10f2a20966
Click or drag on the preview page to pin a numbered comment. Saving a pin only adds it to the stack. Add comments drops the crops and a short prompt into the composer and never sends the turn. Capture takes the visible page then crops in bitmap space, because Electron's rect crop on guest webviews is empty on Windows and shifted on high-DPI.
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { annotateFlushPrompt, dataUrlToFile, packageAnnotateStack } from './pack'
|
|
import type { AnnotatePin } from './stack'
|
|
|
|
export interface AnnotateFlushPorts {
|
|
attachImage: (blob: Blob) => void | Promise<void>
|
|
insertText: (text: string) => void
|
|
send?: () => void
|
|
}
|
|
|
|
export interface AnnotateFlushResult {
|
|
count: number
|
|
prompt: string
|
|
sent: false
|
|
}
|
|
|
|
/**
|
|
* Attach every pin to the composer as a numbered crop plus the packed prompt.
|
|
* Saving / flushing never submits a turn — `send` is accepted so tests can
|
|
* prove it stays untouched.
|
|
*/
|
|
export async function flushAnnotateStack(
|
|
pins: readonly AnnotatePin[],
|
|
ports: AnnotateFlushPorts,
|
|
pageUrl?: string
|
|
): Promise<AnnotateFlushResult> {
|
|
const items = packageAnnotateStack(pins)
|
|
|
|
for (const item of items) {
|
|
if (item.imageDataUrl) {
|
|
await ports.attachImage(dataUrlToFile(item.imageDataUrl, `Comment_${item.number}.png`))
|
|
}
|
|
}
|
|
|
|
const prompt = annotateFlushPrompt(items, pageUrl)
|
|
|
|
if (prompt.trim()) {
|
|
ports.insertText(prompt)
|
|
}
|
|
|
|
return { count: items.length, prompt, sent: false }
|
|
}
|