Comment mode shipped the crop and the note, so an agent got a picture of the problem and had to grep for the element it showed. Each element comment now also names its CSS selector, its markup, and the computed styles that decide layout, which is what the agent needs to land in the right file. The target line stays prose — it is what the user pointed at — and the DOM detail rides labelled lines beneath it. Area pins have no element, so they still get only the crop and the note. Markup is redacted in the guest before it crosses to the host: password and hidden input values, and any attribute reading as a key/token/secret, are replaced with [redacted] on a clone, so a page's secrets never reach the composer or the model. It is clipped to a 600-char budget so one comment cannot paste a whole section. AnnotateIdentity was a hand-copy of CompactIdentity that had already drifted; it is now an alias, so the guest, the pin, and the packer cannot disagree about the shape again.
101 lines
2.6 KiB
TypeScript
101 lines
2.6 KiB
TypeScript
import type { CompactIdentity } from './identity'
|
|
|
|
/**
|
|
* Numbered pin stack for comment mode. Saving a pin only appends — it never
|
|
* sends a turn. Numbers are assigned 1..N in add order and stay put if a pin
|
|
* is removed, so Comment 3 in the composer still matches marker 3 on the page.
|
|
*/
|
|
|
|
export type AnnotatePinKind = 'area' | 'element'
|
|
|
|
export interface AnnotateRect {
|
|
height: number
|
|
width: number
|
|
x: number
|
|
y: number
|
|
}
|
|
|
|
/** What a pin knows about its element. One shape, owned by `identity`. */
|
|
export type AnnotateIdentity = CompactIdentity
|
|
|
|
export interface AnnotatePin {
|
|
id: string
|
|
identity?: AnnotateIdentity
|
|
imageDataUrl: string
|
|
kind: AnnotatePinKind
|
|
note: string
|
|
number: number
|
|
pageTitle: string
|
|
pageUrl: string
|
|
rect: AnnotateRect
|
|
}
|
|
|
|
export interface AnnotateStack {
|
|
nextNumber: number
|
|
pins: AnnotatePin[]
|
|
}
|
|
|
|
export type AnnotatePinDraft = Omit<AnnotatePin, 'id' | 'number'> & { id?: string }
|
|
|
|
export function emptyAnnotateStack(): AnnotateStack {
|
|
return { nextNumber: 1, pins: [] }
|
|
}
|
|
|
|
export function addAnnotatePin(stack: AnnotateStack, draft: AnnotatePinDraft): AnnotateStack {
|
|
const pin: AnnotatePin = {
|
|
...draft,
|
|
id: draft.id || `annotate-${stack.nextNumber}`,
|
|
number: stack.nextNumber
|
|
}
|
|
|
|
return {
|
|
nextNumber: stack.nextNumber + 1,
|
|
pins: [...stack.pins, pin]
|
|
}
|
|
}
|
|
|
|
export function updateAnnotatePinNote(stack: AnnotateStack, id: string, note: string): AnnotateStack {
|
|
return {
|
|
...stack,
|
|
pins: stack.pins.map(pin => (pin.id === id ? { ...pin, note } : pin))
|
|
}
|
|
}
|
|
|
|
export function removeAnnotatePin(stack: AnnotateStack, id: string): AnnotateStack {
|
|
return {
|
|
...stack,
|
|
pins: stack.pins.filter(pin => pin.id !== id)
|
|
}
|
|
}
|
|
|
|
export function clearAnnotateStack(stack: AnnotateStack): AnnotateStack {
|
|
void stack
|
|
|
|
return emptyAnnotateStack()
|
|
}
|
|
|
|
/** Clear a flushed batch while keeping comment numbers unique in this page session. */
|
|
export function clearAnnotatePins(stack: AnnotateStack): AnnotateStack {
|
|
return { ...stack, pins: [] }
|
|
}
|
|
|
|
export interface AnnotateSession {
|
|
/** In-progress pick that has a crop but no saved note yet. */
|
|
draft: AnnotatePinDraft | null
|
|
mode: boolean
|
|
overlayLive: boolean
|
|
stack: AnnotateStack
|
|
}
|
|
|
|
export function emptyAnnotateSession(): AnnotateSession {
|
|
return { draft: null, mode: false, overlayLive: false, stack: emptyAnnotateStack() }
|
|
}
|
|
|
|
export function beginAnnotateMode(session: AnnotateSession): AnnotateSession {
|
|
return { ...session, mode: true, overlayLive: true }
|
|
}
|
|
|
|
export function endAnnotateMode(session: AnnotateSession): AnnotateSession {
|
|
return { ...session, draft: null, mode: false, overlayLive: false }
|
|
}
|