@inkbar/core 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"file":"signatures-DF2VmNVa.mjs","names":["uuidv7","uuidv7","uuidv7"],"sources":["../src/model/errors.ts","../src/model/events.ts","../src/model/geometry.ts","../src/model/readable.ts","../src/model/selection.ts","../src/pdfjs/load.ts","../src/model/annotations/defaults.ts","../src/model/pdf-date.ts","../src/model/annotations/pdf-names.ts","../src/model/annotations/callout.ts","../src/model/annotations/types.ts","../src/model/annotations/embedded.ts","../src/model/env.ts","../src/model/annotations/history.ts","../src/model/annotations/json.ts","../src/model/annotations/store.ts","../src/model/page-cache.ts","../src/model/pages.ts","../src/model/source.ts","../src/model/text.ts","../src/model/document.ts","../src/model/annotations/edit.ts","../src/model/annotations/style-map.ts","../src/model/annotations/tool-style.ts","../src/model/annotations/suggestions.ts","../src/model/annotations/threads.ts","../src/model/annotations/shape-geometry.ts","../src/model/recognise.ts","../src/model/signatures.ts"],"sourcesContent":["export type InkErrorCode =\n | 'PasswordRequired'\n | 'InvalidPdf'\n | 'SourceFetchFailed'\n | 'AssetConfigMissing'\n | 'AssetLoadFailed'\n | 'EngineUnavailable'\n | 'ControlledMutationIgnored'\n | 'DocumentDestroyed'\n | 'PageOutOfRange'\n\nexport class InkError extends Error {\n override readonly name = 'InkError'\n readonly code: InkErrorCode\n readonly details: Readonly<Record<string, unknown>>\n\n constructor(\n code: InkErrorCode,\n message: string,\n details: Record<string, unknown> = {},\n cause?: unknown\n ) {\n super(message, cause === undefined ? undefined : { cause })\n this.code = code\n this.details = details\n }\n}\n\nexport function isInkError(value: unknown): value is InkError {\n return (\n value instanceof InkError ||\n (typeof value === 'object' &&\n value !== null &&\n (value as { name?: unknown }).name === 'InkError')\n )\n}\n","export type Listener<T> = (payload: T) => void\n\nexport class Emitter<Events extends Record<string, unknown>> {\n private listeners = new Map<keyof Events, Set<Listener<never>>>()\n\n on<K extends keyof Events>(event: K, fn: Listener<Events[K]>): () => void {\n let set = this.listeners.get(event)\n if (!set) {\n set = new Set()\n this.listeners.set(event, set)\n }\n set.add(fn)\n return () => {\n set?.delete(fn)\n }\n }\n\n emit<K extends keyof Events>(event: K, payload: Events[K]): void {\n const set = this.listeners.get(event)\n if (!set) return\n for (const fn of [...set]) (fn as Listener<Events[K]>)(payload)\n }\n\n clear(): void {\n this.listeners.clear()\n }\n}\n","/**\n * All geometry in this module is PDF default user space: points, origin at the\n * lower-left of the page, before /Rotate. Pixel conversions live in dom/transform.ts.\n */\nexport interface Point {\n x: number\n y: number\n}\n\n/** Axis-aligned box. `x`,`y` is the lower-left corner. */\nexport interface Rect {\n x: number\n y: number\n width: number\n height: number\n}\n\n/** Four corners in PDF.js's normalised QuadPoints order: upper-left, upper-right, lower-left, lower-right. */\nexport interface Quad {\n p1: Point\n p2: Point\n p3: Point\n p4: Point\n}\n\n/** PDF transformation matrix [a b c d e f]: x' = a·x + c·y + e, y' = b·x + d·y + f. */\nexport type Matrix = readonly [number, number, number, number, number, number]\n\nexport function approxEqual(a: number, b: number, eps = 0.01): boolean {\n return Math.abs(a - b) <= eps\n}\n\nexport function rectFromPoints(a: Point, b: Point): Rect {\n const x = Math.min(a.x, b.x)\n const y = Math.min(a.y, b.y)\n return { x, y, width: Math.abs(a.x - b.x), height: Math.abs(a.y - b.y) }\n}\n\nexport function rectFromQuad(q: Quad): Rect {\n const xs = [q.p1.x, q.p2.x, q.p3.x, q.p4.x]\n const ys = [q.p1.y, q.p2.y, q.p3.y, q.p4.y]\n const x = Math.min(...xs)\n const y = Math.min(...ys)\n return { x, y, width: Math.max(...xs) - x, height: Math.max(...ys) - y }\n}\n\nexport function quadFromRect(r: Rect): Quad {\n const top = r.y + r.height\n const right = r.x + r.width\n return {\n p1: { x: r.x, y: top },\n p2: { x: right, y: top },\n p3: { x: r.x, y: r.y },\n p4: { x: right, y: r.y },\n }\n}\n\nexport function unionRects(rects: readonly Rect[]): Rect {\n if (rects.length === 0) throw new RangeError('unionRects needs at least one rect')\n let x1 = Infinity\n let y1 = Infinity\n let x2 = -Infinity\n let y2 = -Infinity\n for (const r of rects) {\n x1 = Math.min(x1, r.x)\n y1 = Math.min(y1, r.y)\n x2 = Math.max(x2, r.x + r.width)\n y2 = Math.max(y2, r.y + r.height)\n }\n return { x: x1, y: y1, width: x2 - x1, height: y2 - y1 }\n}\n\nexport function rectsIntersect(a: Rect, b: Rect): boolean {\n return (\n a.x < b.x + b.width &&\n b.x < a.x + a.width &&\n a.y < b.y + b.height &&\n b.y < a.y + a.height\n )\n}\n\nexport function rectContainsPoint(r: Rect, p: Point): boolean {\n return p.x >= r.x && p.x <= r.x + r.width && p.y >= r.y && p.y <= r.y + r.height\n}\n\nexport function translateRect(r: Rect, dx: number, dy: number): Rect {\n return { x: r.x + dx, y: r.y + dy, width: r.width, height: r.height }\n}\n\nexport function translateQuad(q: Quad, dx: number, dy: number): Quad {\n const t = (p: Point): Point => ({ x: p.x + dx, y: p.y + dy })\n return { p1: t(q.p1), p2: t(q.p2), p3: t(q.p3), p4: t(q.p4) }\n}\n\nexport function applyMatrix(m: Matrix, p: Point): Point {\n return { x: m[0] * p.x + m[2] * p.y + m[4], y: m[1] * p.x + m[3] * p.y + m[5] }\n}\n\nexport function invertMatrix(m: Matrix): Matrix {\n const det = m[0] * m[3] - m[1] * m[2]\n if (det === 0) throw new RangeError('matrix is not invertible')\n return [\n m[3] / det,\n -m[1] / det,\n -m[2] / det,\n m[0] / det,\n (m[2] * m[5] - m[3] * m[4]) / det,\n (m[1] * m[4] - m[0] * m[5]) / det,\n ]\n}\n\n/** Returns the matrix that applies `a` first, then `b`. */\nexport function multiplyMatrix(a: Matrix, b: Matrix): Matrix {\n return [\n a[0] * b[0] + a[1] * b[2],\n a[0] * b[1] + a[1] * b[3],\n a[2] * b[0] + a[3] * b[2],\n a[2] * b[1] + a[3] * b[3],\n a[4] * b[0] + a[5] * b[2] + b[4],\n a[4] * b[1] + a[5] * b[3] + b[5],\n ]\n}\n\nexport function pointsFromFlat(flat: ArrayLike<number>): Point[] {\n const out: Point[] = []\n for (let i = 0; i + 1 < flat.length; i += 2) out.push({ x: flat[i]!, y: flat[i + 1]! })\n return out\n}\n\n/** Eight numbers per quad, in PDF.js's normalised order. Trailing partial quads are dropped. */\nexport function quadsFromFlat(flat: ArrayLike<number>): Quad[] {\n const pts = pointsFromFlat(flat)\n const out: Quad[] = []\n for (let i = 0; i + 3 < pts.length; i += 4) {\n out.push({ p1: pts[i]!, p2: pts[i + 1]!, p3: pts[i + 2]!, p4: pts[i + 3]! })\n }\n return out\n}\n","export interface Readable<T> {\n get(): T\n subscribe(fn: (value: T) => void): () => void\n}\n\nexport interface Writable<T> extends Readable<T> {\n set(this: void, value: T): void\n /** Safe to call detached (`const { update } = store`). */\n update(this: void, fn: (value: T) => T): void\n}\n\nexport function writable<T>(initial: T): Writable<T> {\n let value = initial\n const subs = new Set<(v: T) => void>()\n // Not `this.set`: `update` must work detached, e.g. `const { update } = store`.\n const set = (next: T): void => {\n if (Object.is(next, value)) return\n value = next\n for (const fn of [...subs]) fn(value)\n }\n return {\n get: () => value,\n set,\n update(fn) {\n set(fn(value))\n },\n subscribe(fn) {\n subs.add(fn)\n return () => {\n subs.delete(fn)\n }\n },\n }\n}\n\n/**\n * A readable computed from `source`. It subscribes to the source only while it has\n * subscribers of its own, so an unobserved derived value holds no reference to the source.\n */\nexport function derived<T, U>(source: Readable<T>, fn: (value: T) => U): Readable<U> {\n const subs = new Set<(v: U) => void>()\n let cached: U\n let stopSource: (() => void) | undefined\n\n const onSource = (v: T): void => {\n const next = fn(v)\n if (Object.is(next, cached)) return\n cached = next\n for (const sub of [...subs]) sub(next)\n }\n\n return {\n get: () => (stopSource ? cached : fn(source.get())),\n subscribe(sub) {\n if (!stopSource) {\n cached = fn(source.get())\n stopSource = source.subscribe(onSource)\n }\n subs.add(sub)\n return () => {\n if (!subs.delete(sub) || subs.size > 0) return\n stopSource?.()\n stopSource = undefined\n }\n },\n }\n}\n\nexport function readonly<T>(w: Writable<T>): Readable<T> {\n return { get: () => w.get(), subscribe: (fn) => w.subscribe(fn) }\n}\n","import { quadFromRect, type Quad, type Rect } from './geometry'\n\nconst union = (a: Rect, b: Rect): Rect => {\n const x = Math.min(a.x, b.x)\n const y = Math.min(a.y, b.y)\n return {\n x,\n y,\n width: Math.max(a.x + a.width, b.x + b.width) - x,\n height: Math.max(a.y + a.height, b.y + b.height) - y,\n }\n}\n\nconst centreY = (r: Rect): number => r.y + r.height / 2\n\nfunction median(values: number[]): number {\n const sorted = [...values].sort((a, b) => a - b)\n const mid = sorted.length >> 1\n return sorted.length % 2 ? sorted[mid]! : (sorted[mid - 1]! + sorted[mid]!) / 2\n}\n\n/**\n * Merges glyph boxes that share a line into one quad per run, ordered top to bottom (by\n * vertical centre) then left to right. Boxes whose vertical centres are within `tolerance`\n * points count as the same line; boxes with no area are dropped. Within a line, a horizontal\n * gap wider than `gap` points (default 1.5 × the line's median box height) starts a new run,\n * so text selected across a column gutter yields one quad per column. Pure user-space maths.\n */\nexport function mergeLineRects(\n rects: readonly Rect[],\n tolerance = 2,\n gap?: number\n): Quad[] {\n const lines: { bounds: Rect; boxes: Rect[] }[] = []\n for (const r of rects) {\n if (!(r.width > 0 && r.height > 0)) continue\n const line = lines.find((l) => Math.abs(centreY(l.bounds) - centreY(r)) <= tolerance)\n if (!line) {\n lines.push({ bounds: { ...r }, boxes: [r] })\n continue\n }\n line.bounds = union(line.bounds, r)\n line.boxes.push(r)\n }\n const runs: Rect[] = []\n for (const line of lines) {\n const maxGap = gap ?? 1.5 * median(line.boxes.map((b) => b.height))\n const boxes = [...line.boxes].sort((a, b) => a.x - b.x)\n let run = { ...boxes[0]! }\n for (const b of boxes.slice(1)) {\n if (b.x - (run.x + run.width) > maxGap) {\n runs.push(run)\n run = { ...b }\n } else {\n run = union(run, b)\n }\n }\n runs.push(run)\n }\n runs.sort((a, b) => centreY(b) - centreY(a) || a.x - b.x)\n return runs.map(quadFromRect)\n}\n","import { InkError } from '../model/errors'\n\nimport type { PdfAssets, PdfjsDocument, PdfjsLoadingTask, PdfjsModule } from './types'\n\nconst REQUIRED: ReadonlyArray<keyof PdfAssets> = [\n 'worker',\n 'cMaps',\n 'standardFonts',\n 'wasm',\n]\n\nexport function assertAssets(value: unknown): asserts value is PdfAssets {\n const record = (typeof value === 'object' && value !== null ? value : {}) as Record<\n string,\n unknown\n >\n const missing = REQUIRED.filter(\n (k) => typeof record[k] !== 'string' || record[k] === ''\n )\n if (value === undefined || value === null || missing.length > 0) {\n throw new InkError(\n 'AssetConfigMissing',\n 'openDocument needs an `assets` option naming the PDF.js worker, cMaps, standardFonts and wasm locations. ' +\n 'Vite users: add the @inkbar/core/vite plugin and pass `assets` from \"virtual:inkbar-assets\".',\n { missing: value == null ? [...REQUIRED] : missing }\n )\n }\n}\n\nlet modulePromise: Promise<PdfjsModule> | undefined\nlet configuredWorker: string | undefined\n\n/**\n * Loads PDF.js once. `#pdfjs` resolves to the legacy build in Node and the\n * modern build everywhere else (see package.json \"imports\").\n */\nexport async function loadPdfjs(assets: PdfAssets): Promise<PdfjsModule> {\n assertAssets(assets)\n modulePromise ??= import('#pdfjs').catch((cause: unknown) => {\n modulePromise = undefined\n throw new InkError(\n 'AssetLoadFailed',\n 'PDF.js could not be imported',\n { url: assets.worker },\n cause\n )\n }) as Promise<PdfjsModule>\n const pdfjs = await modulePromise\n if (configuredWorker === undefined) {\n pdfjs.GlobalWorkerOptions.workerSrc = assets.worker\n configuredWorker = assets.worker\n } else if (configuredWorker !== assets.worker) {\n throw new InkError(\n 'AssetConfigMissing',\n 'PDF.js worker URL cannot change after the first document is opened',\n { configured: configuredWorker, requested: assets.worker }\n )\n }\n return pdfjs\n}\n\nexport interface OpenProxyOptions {\n assets: PdfAssets\n password?: string | undefined\n /** PDF.js log level (0 errors, 1 warnings, 5 infos). Left to PDF.js when omitted. */\n verbosity?: number | undefined\n}\n\nexport async function openProxy(\n pdfjs: PdfjsModule,\n bytes: Uint8Array,\n options: OpenProxyOptions\n): Promise<{ task: PdfjsLoadingTask; proxy: PdfjsDocument }> {\n const { assets, password, verbosity } = options\n const task = pdfjs.getDocument({\n data: bytes,\n ...(password !== undefined ? { password } : {}),\n ...(verbosity !== undefined ? { verbosity } : {}),\n cMapUrl: assets.cMaps,\n cMapPacked: true,\n standardFontDataUrl: assets.standardFonts,\n wasmUrl: assets.wasm,\n ...(assets.icc !== undefined ? { iccUrl: assets.icc } : {}),\n })\n try {\n const proxy = await task.promise\n return { task, proxy }\n } catch (cause: unknown) {\n try {\n await task.destroy()\n } catch {\n // The caller already receives the mapped load error below; a failure\n // while tearing down the half-open task adds nothing actionable.\n }\n throw mapLoadError(cause, { assets, passwordSupplied: password !== undefined })\n }\n}\n\n/** `PasswordResponses` values from PDF.js (`NEED_PASSWORD = 1`, `INCORRECT_PASSWORD = 2`). */\nconst INCORRECT_PASSWORD = 2\n\n/**\n * PDF.js raises these from `task.promise` when the worker script cannot be\n * imported (in browsers after its real Worker fails and the fake-worker\n * fallback also fails to import `workerSrc`).\n */\nconst WORKER_FAILURE =\n /Setting up fake worker failed|No \"GlobalWorkerOptions\\.workerSrc\" specified/i\n\n/**\n * Only the worker is mapped here. CMap, standard-font and wasm failures are\n * PDF.js warnings with fallbacks that never reject the open promise, so they\n * cannot be detected at open time.\n *\n * PDF.js 6 exports only some exception classes (`PasswordException`,\n * `InvalidPDFException`, `ResponseException`, `AbortException`), and errors\n * that cross the worker boundary are rebuilt by name, so match on `name`.\n * Inputs here are always in-memory bytes, so there is no fetch to fail:\n * every non-password failure means the bytes are not a usable PDF.\n */\nexport function mapLoadError(\n cause: unknown,\n context: { assets: PdfAssets; passwordSupplied?: boolean }\n): InkError {\n const { assets, passwordSupplied = false } = context\n const name = (cause as { name?: unknown } | null)?.name\n const rawMessage = (cause as { message?: unknown } | null)?.message\n const message =\n typeof rawMessage === 'string' && rawMessage !== ''\n ? rawMessage\n : 'Unknown PDF.js error'\n if (WORKER_FAILURE.test(message)) {\n return new InkError(\n 'AssetLoadFailed',\n 'The PDF.js worker could not be loaded. Check the `assets.worker` URL.',\n { url: assets.worker },\n cause\n )\n }\n if (name === 'PasswordException') {\n const wrong = (cause as { code?: unknown }).code === INCORRECT_PASSWORD\n return new InkError(\n 'PasswordRequired',\n wrong\n ? 'The password is incorrect'\n : 'This document is encrypted and needs a password',\n { passwordSupplied, incorrect: wrong },\n cause\n )\n }\n // InvalidPDFException, FormatError, UnknownErrorException, MissingPDFException,\n // UnexpectedResponseException, ResponseException and anything unrecognised.\n return new InkError(\n 'InvalidPdf',\n message,\n {\n pdfjsErrorName: typeof name === 'string' ? name : undefined,\n pdfjsMessage: message,\n },\n cause\n )\n}\n","import type { AnnotationType, ConfidenceBucket } from './types'\n\nexport interface AnnotationDefaults {\n color(type: AnnotationType): string\n /** Fill colour for redactions. */\n fill(): string\n opacity(type: AnnotationType): number\n /** Outline colour for a suggested redaction, by confidence bucket. */\n suggestion(bucket: ConfidenceBucket): string\n}\n\nconst COLORS: Record<AnnotationType, string> = {\n highlight: '#F2C230',\n underline: '#2B5A9E',\n strikeout: '#C0392B',\n squiggly: '#1F7A4D',\n text: '#F2C230',\n // Free text: the text colour (`defaultStyle.color`). A box's fill has no default.\n freetext: '#151820',\n square: '#C0392B',\n circle: '#C0392B',\n line: '#151820',\n polyline: '#151820',\n polygon: '#151820',\n ink: '#151820',\n // A stamp draws its image; the colour is only what XFDF requires every annotation to carry.\n stamp: '#151820',\n // The loupe's rim.\n loupe: '#151820',\n // The dimming colour.\n mask: '#000000',\n redact: '#C0392B',\n}\n\n/**\n * Suggested-redaction colours, strengthening with confidence: amber for low, orange for\n * medium, the redaction red for high.\n */\nconst SUGGESTION_COLORS: Record<ConfidenceBucket, string> = {\n low: '#D4A017',\n medium: '#E67E22',\n high: '#C0392B',\n}\n\nexport const staticDefaults: AnnotationDefaults = {\n color: (type) => COLORS[type],\n fill: () => '#000000',\n opacity: (type) => (type === 'highlight' ? 0.4 : 1),\n suggestion: (bucket) => SUGGESTION_COLORS[bucket],\n}\n\nconst VARIABLES: Record<AnnotationType, string> = {\n highlight: '--ink-highlight',\n underline: '--ink-underline',\n strikeout: '--ink-strikeout',\n squiggly: '--ink-squiggly',\n text: '--ink-note',\n freetext: '--ink-free-text',\n square: '--ink-shape',\n circle: '--ink-shape',\n line: '--ink-shape',\n polyline: '--ink-shape',\n polygon: '--ink-shape',\n ink: '--ink-ink',\n stamp: '--ink-ink',\n loupe: '--ink-shape',\n mask: '--ink-mask',\n redact: '--ink-redact',\n}\n\n/** Resolves default colours from CSS custom properties on `el`, falling back to `staticDefaults`. */\nexport function cssVariableDefaults(el: Element): AnnotationDefaults {\n const read = (name: string): string | undefined => {\n const view = el.ownerDocument.defaultView\n if (!view) return undefined\n return normalizeColor(view.getComputedStyle(el).getPropertyValue(name))\n }\n return {\n color: (type) => read(VARIABLES[type]) ?? staticDefaults.color(type),\n fill: () => read('--ink-redact-fill') ?? staticDefaults.fill(),\n opacity: (type) => staticDefaults.opacity(type),\n suggestion: (bucket) =>\n read(`--ink-suggestion-${bucket}`) ?? staticDefaults.suggestion(bucket),\n }\n}\n\n/** Accepts `#rgb`, `#rrggbb`, `rgb(r, g, b)` and `rgb(r g b)`; returns `#RRGGBB` or undefined. */\nexport function normalizeColor(value: string): string | undefined {\n const v = value.trim()\n const short = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(v)\n if (short) {\n const [, r = '', g = '', b = ''] = short\n return `#${r}${r}${g}${g}${b}${b}`.toUpperCase()\n }\n if (/^#[0-9a-f]{6}$/i.test(v)) return v.toUpperCase()\n const rgb = /^rgba?\\(\\s*(\\d{1,3})[\\s,]+(\\d{1,3})[\\s,]+(\\d{1,3})/i.exec(v)\n if (rgb) {\n const hex = [rgb[1], rgb[2], rgb[3]]\n .map((n) => Math.min(255, Number(n)).toString(16).padStart(2, '0'))\n .join('')\n return `#${hex}`.toUpperCase()\n }\n return undefined\n}\n","/** Parses a PDF date string (`D:YYYYMMDDHHmmSSOHH'mm'`) into ISO 8601. Returns `fallback` on anything unparseable. */\nexport function parsePdfDate(value: string | null | undefined, fallback: string): string {\n if (!value) return fallback\n const m =\n /^(?:D:)?(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(Z|[+-]\\d{2}(?:'\\d{2}')?)?/.exec(\n value.trim()\n )\n if (!m) return fallback\n const [, y, mo = '01', d = '01', h = '00', mi = '00', s = '00', zone] = m\n let offsetMinutes = 0\n if (zone && zone !== 'Z') {\n const sign = zone.startsWith('-') ? -1 : 1\n const zh = Number(zone.slice(1, 3))\n const zm = Number(zone.slice(4, 6) || 0)\n offsetMinutes = sign * (zh * 60 + zm)\n }\n const utc =\n Date.UTC(Number(y), Number(mo) - 1, Number(d), Number(h), Number(mi), Number(s)) -\n offsetMinutes * 60_000\n if (Number.isNaN(utc)) return fallback\n return new Date(utc).toISOString()\n}\n","import { z } from 'zod'\n\n/**\n * A PDF name: a non-empty run of regular characters, so no whitespace and none of the\n * delimiters `( ) < > [ ] { } / %`.\n */\nexport const PDF_NAME = /^[^\\s()<>[\\]{}/%]+$/\n\n/**\n * A set of PDF names Inkbar knows that stays open: any other valid PDF name loads, is kept and\n * is written back unchanged. The output type keeps autocomplete for the known values.\n */\nexport function pdfNameSet<const K extends readonly [string, ...string[]]>(known: K) {\n return z\n .union([z.enum(known), z.string().regex(PDF_NAME, 'expected a PDF name')])\n .describe(\n `One of ${known.join(', ')}. Any other PDF name is allowed and kept unchanged.`\n ) as z.ZodType<K[number] | (string & {}), K[number] | (string & {})>\n}\n\n/** Line ending styles (PDF `/LE`). */\nexport const LINE_ENDINGS = [\n 'None',\n 'Square',\n 'Circle',\n 'Diamond',\n 'OpenArrow',\n 'ClosedArrow',\n 'Butt',\n 'ROpenArrow',\n 'RClosedArrow',\n 'Slash',\n] as const\n\n/** Note icons (PDF `/Name` on a text annotation). */\nexport const NOTE_ICONS = [\n 'Comment',\n 'Note',\n 'Help',\n 'Insert',\n 'Key',\n 'NewParagraph',\n 'Paragraph',\n] as const\n\n/** Annotation intents (PDF `/IT`). */\nexport const INTENTS = [\n 'FreeText',\n 'FreeTextCallout',\n 'FreeTextTypeWriter',\n 'LineArrow',\n 'LineDimension',\n 'PolygonCloud',\n 'PolygonDimension',\n 'PolyLineDimension',\n] as const\n\n/** True when `v` is one of the values in `list`. */\nexport function isKnown<K extends readonly string[]>(list: K, v: string): v is K[number] {\n return (list as readonly string[]).includes(v)\n}\n","// Free-text callouts as PDF and XFDF store them: `rect` holds box and leader line together,\n// `fringe` insets it to the text box, `callout` runs from the tip to the box and `head` is the\n// ending at the tip.\nimport { z } from 'zod'\n\nimport { isKnown, LINE_ENDINGS } from './pdf-names'\n\nimport type { Annotation, FreeTextAnnotation, LineEnding } from './types'\nimport type { Point, Rect } from '../geometry'\n\n/**\n * The insets from a free text's `rect` to its text box, in points (PDF `/RD`, XFDF `fringe`,\n * both in this order).\n */\nexport const FringeSchema = z.object({\n left: z.number().nonnegative(),\n top: z.number().nonnegative(),\n right: z.number().nonnegative(),\n bottom: z.number().nonnegative(),\n})\n\nexport type Fringe = z.infer<typeof FringeSchema>\n\n/** An ending's length, and its full width, as a multiple of the stroke width. */\nconst ENDING_SCALE = 3\n\n/**\n * A free text's text box: `rect` inset by `fringe`, or `rect` itself without one. Insets wider\n * or taller than `rect` leave a box of width or height 0 at the inset origin.\n */\nexport function freeTextBox(a: Pick<FreeTextAnnotation, 'rect' | 'fringe'>): Rect {\n const { rect, fringe } = a\n if (!fringe) return rect\n return {\n x: rect.x + fringe.left,\n y: rect.y + fringe.bottom,\n width: Math.max(0, rect.width - fringe.left - fringe.right),\n height: Math.max(0, rect.height - fringe.top - fringe.bottom),\n }\n}\n\n/**\n * True for a free-text callout drawn the standard way: a box with a leader line through\n * `callout`. A callout with `cornerRadius` is Inkbar's speech bubble instead.\n */\nexport function isStandardCallout(\n a: Annotation\n): a is FreeTextAnnotation & { callout: Point[] } {\n return (\n a.type === 'freetext' &&\n a.intent === 'FreeTextCallout' &&\n a.callout !== undefined &&\n a.callout.length >= 2 &&\n a.cornerRadius === undefined\n )\n}\n\n/**\n * The leader line's stroke: the border colour, else the text colour, and the border width, with\n * 1 pt when the box has no border.\n */\nexport function calloutStroke(a: FreeTextAnnotation): { color: string; width: number } {\n return {\n color: a.borderColor ?? a.defaultStyle.color,\n width: a.width > 0 ? a.width : 1,\n }\n}\n\n/**\n * The `rect` and `fringe` that hold the text box `box` and a leader line through `callout`\n * stroked `width` points wide: every point is padded by half the stroke, and by the ending's\n * size as well when `head` is one Inkbar draws.\n */\nexport function withCalloutBounds(\n box: Rect,\n callout: readonly Point[],\n width: number,\n head: LineEnding | undefined\n): { rect: Rect; fringe: Fringe } {\n const drawn = head !== undefined && head !== 'None' && isKnown(LINE_ENDINGS, head)\n const pad = width / 2 + (drawn ? ENDING_SCALE * Math.max(width, 1) : 0)\n const xs = [box.x, box.x + box.width, ...callout.map((p) => p.x)]\n const ys = [box.y, box.y + box.height, ...callout.map((p) => p.y)]\n const left = Math.min(...xs) - pad\n const bottom = Math.min(...ys) - pad\n const right = Math.max(...xs) + pad\n const top = Math.max(...ys) + pad\n return {\n rect: { x: left, y: bottom, width: right - left, height: top - bottom },\n fringe: {\n left: box.x - left,\n top: top - (box.y + box.height),\n right: right - (box.x + box.width),\n bottom: box.y - bottom,\n },\n }\n}\n","import { z } from 'zod'\n\nimport { FringeSchema } from './callout'\nimport { INTENTS, LINE_ENDINGS, NOTE_ICONS, pdfNameSet } from './pdf-names'\n\nexport const ANNOTATION_FORMAT = 'inkbar/annotations'\nexport const ANNOTATION_VERSION = 1\n\nconst Hex = z.string().regex(/^#[0-9a-fA-F]{6}$/, 'expected #RRGGBB')\n\nexport const PointSchema = z.object({ x: z.number(), y: z.number() })\nexport const RectSchema = z.object({\n x: z.number(),\n y: z.number(),\n width: z.number().nonnegative(),\n height: z.number().nonnegative(),\n})\nexport const QuadSchema = z.object({\n p1: PointSchema,\n p2: PointSchema,\n p3: PointSchema,\n p4: PointSchema,\n})\n\nconst Base = z.object({\n /** Client id, UUIDv7, assigned at creation and never reassigned. Embedded annotations use `pdf:<ref>`. */\n id: z.string().min(1),\n /** 0-based page index. */\n page: z.number().int().nonnegative(),\n /** Bounding box in PDF user space. */\n rect: RectSchema,\n /** Resolved #RRGGBB. Written into the PDF later, so it is always concrete. */\n color: Hex,\n opacity: z.number().min(0).max(1),\n author: z.string().optional(),\n contents: z.string().optional(),\n /** Id of the parent note; replies form threads. */\n inReplyTo: z.string().optional(),\n /** ISO 8601 date-time. */\n createdAt: z.iso.datetime({ offset: true }),\n /** ISO 8601 date-time. */\n modifiedAt: z.iso.datetime({ offset: true }),\n /** Created in this session, or imported from the file. Viewer state, never exported. */\n source: z.enum(['session', 'pdf']),\n /** Embedded annotations are locked until the engine can rewrite the file. Viewer state, never exported. */\n locked: z.boolean().optional(),\n /** Short label for what the mark is (XFDF `subject`). */\n subject: z.string().optional(),\n /** What the mark is for, e.g. a callout or an arrow (XFDF `intent`, a PDF name). */\n intent: pdfNameSet(INTENTS).optional(),\n /** Host data. Preserved, never interpreted. */\n custom: z.record(z.string(), z.unknown()).optional(),\n})\n\nexport const TextMarkupSchema = Base.extend({\n type: z.enum(['highlight', 'underline', 'strikeout', 'squiggly']),\n quads: z.array(QuadSchema).min(1),\n})\n\n/** A note's icon (XFDF `icon`): a PDF name, so a name Inkbar does not know is kept. */\nexport const NoteIconSchema = pdfNameSet(NOTE_ICONS)\n\nexport const NoteSchema = Base.extend({\n type: z.literal('text'),\n icon: NoteIconSchema.default('Note'),\n})\n\n/** A line ending (XFDF `head`/`tail`): a PDF name, so a name Inkbar does not know is kept. */\nexport const LineEndingSchema = pdfNameSet(LINE_ENDINGS)\n\n/** Dash pattern in points, on then off, repeating. Absent means solid. */\nconst DashesSchema = z.array(z.number().nonnegative()).min(1).optional()\n\n/**\n * A key a type refuses outright rather than dropping like other unknown keys: one an older\n * shape used (so its value is not silently lost), or one that means nothing on the type (so a\n * later version is free to give it a meaning).\n */\nconst Refused = z.never().optional()\n\n/**\n * A free-text box's text style, keyed by the CSS property names XFDF writes in its\n * `defaultstyle` string. The older `align` is refused; other unknown keys are dropped.\n */\nexport const FreeTextStyleSchema = z.object({\n fontFamily: z.string().min(1).default('Helvetica'),\n /** Points. */\n fontSize: z.number().positive().default(12),\n /** The text colour. */\n color: Hex,\n textAlign: z.enum(['left', 'center', 'right', 'justify']).default('left'),\n fontWeight: z.literal('bold').optional(),\n fontStyle: z.literal('italic').optional(),\n textDecoration: z.literal('underline').optional(),\n align: Refused,\n})\n\n/**\n * Free text, as XFDF has it: `color` is the box's fill and the text style lives in\n * `defaultStyle`. A box in the older shape (top-level `fontFamily`, `fontSize`, `align`) is\n * refused rather than silently losing its style; other unknown keys are dropped.\n */\nexport const FreeTextSchema = Base.extend({\n type: z.literal('freetext'),\n /** The text shown on the page. */\n contents: z.string(),\n /** The box's fill (XFDF `color`). Absent means no fill. */\n color: Hex.optional(),\n /** The border's colour. An extension, not XFDF. */\n borderColor: Hex.optional(),\n /** The border's width in points; 0 draws no border. */\n width: z.number().nonnegative().default(0),\n dashes: DashesSchema,\n /** Points. An extension, not XFDF. */\n cornerRadius: z.number().nonnegative().optional(),\n defaultStyle: FreeTextStyleSchema,\n /**\n * The insets from `rect` to the text box, in points (XFDF `fringe`, PDF `/RD`). Absent means\n * the box is `rect`.\n */\n fringe: FringeSchema.optional(),\n /** A callout's leader line: the tip, an optional bend, and where it meets the box (PDF `/CL`). */\n callout: z.array(PointSchema).min(2).max(3).optional(),\n /** The line ending at a callout's tip (XFDF `head`, PDF `/LE`). Absent means `None`. */\n head: LineEndingSchema.optional(),\n fontFamily: Refused,\n fontSize: Refused,\n align: Refused,\n})\n\nconst ShapeFields = {\n width: z.number().nonnegative().default(1),\n dashes: DashesSchema,\n interiorColor: Hex.optional(),\n}\n\nexport const SquareSchema = Base.extend({\n type: z.literal('square'),\n ...ShapeFields,\n /** The corner radius in points. An extension, not XFDF. */\n cornerRadius: z.number().nonnegative().optional(),\n})\n\nexport const CircleSchema = Base.extend({\n type: z.literal('circle'),\n ...ShapeFields,\n cornerRadius: Refused,\n})\n\nexport const ShapeSchema = z.discriminatedUnion('type', [SquareSchema, CircleSchema])\n\nexport const LineSchema = Base.extend({\n type: z.literal('line'),\n start: PointSchema,\n end: PointSchema,\n width: z.number().nonnegative().default(1),\n dashes: DashesSchema,\n head: LineEndingSchema.optional(),\n tail: LineEndingSchema.optional(),\n})\n\nconst PolyFields = {\n vertices: z.array(PointSchema).min(2),\n width: z.number().nonnegative().default(1),\n dashes: DashesSchema,\n interiorColor: Hex.optional(),\n}\n\nexport const PolylineSchema = Base.extend({\n type: z.literal('polyline'),\n ...PolyFields,\n /** The ending at the first vertex. */\n head: LineEndingSchema.optional(),\n /** The ending at the last vertex. */\n tail: LineEndingSchema.optional(),\n})\n\nexport const PolygonSchema = Base.extend({\n type: z.literal('polygon'),\n ...PolyFields,\n head: Refused,\n tail: Refused,\n})\n\nexport const PolySchema = z.discriminatedUnion('type', [PolylineSchema, PolygonSchema])\n\nconst InkShape = Base.extend({\n type: z.literal('ink'),\n inklist: z.array(z.array(PointSchema).min(1)).min(1),\n /** Pen pressure per sample, 0 to 1, shaped like `inklist`. Absent for mouse input. */\n pressure: z.array(z.array(z.number().min(0).max(1))).optional(),\n width: z.number().nonnegative().default(2),\n /** Kept so imported dashed ink round-trips. Inkbar draws ink solid. */\n dashes: DashesSchema,\n})\n\n/** Pressure must have one value per point of each stroke. */\nfunction checkPressure(\n a: { inklist: unknown[][]; pressure?: unknown[][] | undefined },\n ctx: z.core.$RefinementCtx\n): void {\n if (!a.pressure) return\n const ok =\n a.pressure.length === a.inklist.length &&\n a.pressure.every((p, i) => p.length === a.inklist[i]?.length)\n if (!ok)\n ctx.addIssue({\n code: 'custom',\n path: ['pressure'],\n message: 'pressure must have the same shape as inklist',\n })\n}\n\nexport const InkSchema = InkShape.superRefine(checkPressure)\n\n/** A PNG or JPEG image as a base64 `data:` URL, as XFDF carries a stamp's `<imagedata>`. */\nexport const IMAGE_DATA_URL = /^data:image\\/(png|jpeg);base64,/\n\n/**\n * An image on the page (XFDF `stamp`), drawn to fill `rect`. Image and typed signatures are\n * stamps with `subject: 'Signature'`.\n */\nexport const StampSchema = Base.extend({\n type: z.literal('stamp'),\n /** A PNG or JPEG `data:` URL (XFDF `imagedata`). */\n imagedata: z.string().regex(IMAGE_DATA_URL, 'expected a PNG or JPEG data URL'),\n /**\n * Quarter turns, in degrees anticlockwise, the image is turned within `rect` (XFDF\n * `rotation`). Absent means upright in user space.\n */\n rotation: z\n .union([z.literal(0), z.literal(90), z.literal(180), z.literal(270)])\n .optional(),\n})\n\n/**\n * A loupe (an extension, not XFDF): a circle inscribed in `rect` that shows the page content\n * under its own centre, magnified. `color` and `width` draw its rim.\n */\nexport const LoupeSchema = Base.extend({\n type: z.literal('loupe'),\n /** How many times larger the content under the centre is drawn. Above 1. */\n magnification: z.number().gt(1).default(2),\n /** The rim's width in points. */\n width: z.number().nonnegative().default(2),\n})\n\n/**\n * A mask (an extension, not XFDF): dims everything on the page outside `shape` drawn in\n * `rect`, an ellipse inscribed in it or the rectangle itself. `color` is the dimming colour\n * (black by default) and `dim` how strongly it covers. One per page: adding a second replaces\n * the first.\n */\nexport const MaskSchema = Base.extend({\n type: z.literal('mask'),\n shape: z.enum(['rect', 'ellipse']),\n /** Opacity of the dimming, 0 (none) to 1 (opaque). */\n dim: z.number().min(0).max(1).default(0.5),\n})\n\nexport const SuggestionSchema = z.object({\n jobId: z.string().optional(),\n confidence: z.number().min(0).max(1),\n reason: z.string().optional(),\n explanation: z.string().optional(),\n recommendation: z.enum(['redact', 'review', 'keep']).optional(),\n})\n\nexport const RedactSchema = Base.extend({\n type: z.literal('redact'),\n /** Present when the mark came from text; absent for an area mark. */\n quads: z.array(QuadSchema).min(1).optional(),\n origin: z.enum(['user', 'suggested']).default('user'),\n suggestion: SuggestionSchema.optional(),\n overlayText: z.string().optional(),\n /** Colour the redaction will be filled with when applied. */\n interiorColor: Hex,\n})\n\nexport const AnnotationSchema = z.discriminatedUnion('type', [\n TextMarkupSchema,\n NoteSchema,\n FreeTextSchema,\n SquareSchema,\n CircleSchema,\n LineSchema,\n PolylineSchema,\n PolygonSchema,\n InkSchema,\n StampSchema,\n LoupeSchema,\n MaskSchema,\n RedactSchema,\n])\n\n/** The viewer's own state on an annotation, left out of exports. */\nconst VIEWER_STATE = { source: true, locked: true } as const\n\n/** One exported annotation: the stored annotation without its viewer state. */\nexport const ExportedAnnotationSchema = z.discriminatedUnion('type', [\n TextMarkupSchema.omit(VIEWER_STATE),\n NoteSchema.omit(VIEWER_STATE),\n FreeTextSchema.omit(VIEWER_STATE),\n SquareSchema.omit(VIEWER_STATE),\n CircleSchema.omit(VIEWER_STATE),\n LineSchema.omit(VIEWER_STATE),\n PolylineSchema.omit(VIEWER_STATE),\n PolygonSchema.omit(VIEWER_STATE),\n InkShape.omit(VIEWER_STATE).superRefine(checkPressure),\n StampSchema.omit(VIEWER_STATE),\n LoupeSchema.omit(VIEWER_STATE),\n MaskSchema.omit(VIEWER_STATE),\n RedactSchema.omit(VIEWER_STATE),\n])\n\nexport type Annotation = z.infer<typeof AnnotationSchema>\nexport type ExportedAnnotation = z.infer<typeof ExportedAnnotationSchema>\nexport type AnnotationType = Annotation['type']\nexport type AnnotationOfType<T extends AnnotationType> = Extract<Annotation, { type: T }>\nexport type TextMarkupAnnotation = z.infer<typeof TextMarkupSchema>\nexport type NoteAnnotation = z.infer<typeof NoteSchema>\nexport type FreeTextAnnotation = z.infer<typeof FreeTextSchema>\nexport type FreeTextStyle = z.infer<typeof FreeTextStyleSchema>\nexport type ShapeAnnotation = z.infer<typeof ShapeSchema>\nexport type LineAnnotation = z.infer<typeof LineSchema>\nexport type PolyAnnotation = z.infer<typeof PolySchema>\nexport type InkAnnotation = z.infer<typeof InkSchema>\nexport type StampAnnotation = z.infer<typeof StampSchema>\nexport type LoupeAnnotation = z.infer<typeof LoupeSchema>\nexport type MaskAnnotation = z.infer<typeof MaskSchema>\nexport type RedactAnnotation = z.infer<typeof RedactSchema>\nexport type Suggestion = z.infer<typeof SuggestionSchema>\nexport type LineEnding = z.infer<typeof LineEndingSchema>\n/**\n * What `update` takes: any of a type's fields. A free-text `defaultStyle` may be partial; it\n * merges into the current one.\n */\nexport type AnnotationPatch = Annotation extends infer A\n ? A extends FreeTextAnnotation\n ? Omit<Partial<A>, 'defaultStyle'> & { defaultStyle?: Partial<FreeTextStyle> }\n : Partial<A>\n : never\n// Point, Rect and Quad types come from ../geometry; the zod schemas above match them structurally.\n\n/** Keys the store fills in; callers never supply them (except an optional `id`). */\ntype Generated = 'id' | 'createdAt' | 'modifiedAt' | 'source' | 'locked'\n/** Keys the store derives or defaults when absent. */\ntype Defaulted = 'rect' | 'color' | 'opacity'\n\n/** Builds the caller-facing shape of one member from its zod input type. */\ntype InputOf<I> = I extends unknown\n ? Omit<I, Generated | Defaulted> &\n Partial<Pick<I, Extract<Defaulted, keyof I>>> & { id?: string }\n : never\n\ntype FreeTextInput = z.input<typeof FreeTextSchema>\n/** Free text may leave out `defaultStyle`, or any of its keys: the store fills the text colour. */\ntype FreeTextCallerInput = Omit<InputOf<FreeTextInput>, 'defaultStyle'> & {\n defaultStyle?: Partial<z.input<typeof FreeTextStyleSchema>>\n}\n\ntype RedactInput = z.input<typeof RedactSchema>\ntype RedactBase = Omit<InputOf<RedactInput>, 'interiorColor' | 'rect' | 'quads'> & {\n interiorColor?: string\n}\ntype RedactCallerInput =\n | (RedactBase & { rect: RedactInput['rect']; quads?: RedactInput['quads'] })\n | (RedactBase & {\n rect?: RedactInput['rect']\n quads: NonNullable<RedactInput['quads']>\n })\n\n/**\n * What callers pass to `add`. Built from zod input types, so fields with defaults or\n * optional fields may be omitted. A redaction needs `rect` or `quads` (the store\n * derives the other), and `interiorColor` defaults to the store's redaction colour. Free text\n * may leave out `defaultStyle`; its text colour defaults to the store's free-text colour.\n */\nexport type AnnotationInput =\n | InputOf<\n | z.input<typeof TextMarkupSchema>\n | z.input<typeof NoteSchema>\n | z.input<typeof ShapeSchema>\n | z.input<typeof LineSchema>\n | z.input<typeof PolySchema>\n | z.input<typeof InkSchema>\n >\n | (InputOf<z.input<typeof StampSchema>> & { rect: z.input<typeof StampSchema>['rect'] })\n | (InputOf<z.input<typeof LoupeSchema>> & { rect: z.input<typeof LoupeSchema>['rect'] })\n | (InputOf<z.input<typeof MaskSchema>> & { rect: z.input<typeof MaskSchema>['rect'] })\n | FreeTextCallerInput\n | RedactCallerInput\n\nexport const AnnotationDocumentSchema = z.object({\n format: z.literal(ANNOTATION_FORMAT),\n version: z.literal(ANNOTATION_VERSION),\n documentKey: z.string().optional(),\n /** Validated item by item on import so unknown types can be preserved. */\n annotations: z.array(z.unknown()),\n})\n\n/**\n * An item whose `type` this version does not know, written by a newer Inkbar. It is kept as-is\n * so it survives an import and export round trip, and it is valid only under the schema\n * version that produced it.\n */\nexport type ForeignAnnotation = { type: string; id: string; page: number } & Record<\n string,\n unknown\n>\n\nexport interface AnnotationDocument {\n format: typeof ANNOTATION_FORMAT\n version: typeof ANNOTATION_VERSION\n documentKey?: string\n annotations: Array<ExportedAnnotation | ForeignAnnotation>\n}\n\nexport type ConfidenceBucket = 'low' | 'medium' | 'high'\n\nexport function confidenceBucket(confidence: number): ConfidenceBucket {\n if (confidence < 0.5) return 'low'\n if (confidence < 0.8) return 'medium'\n return 'high'\n}\n","import {\n pointsFromFlat,\n quadsFromFlat,\n rectFromPoints,\n type Point,\n type Quad,\n type Rect,\n} from '../geometry'\nimport { parsePdfDate } from '../pdf-date'\n\nimport { staticDefaults } from './defaults'\nimport { PDF_NAME } from './pdf-names'\nimport { AnnotationSchema, type Annotation } from './types'\n\nimport type { PdfjsAnnotationData } from '../../pdfjs/types'\n\nexport const SUPPORTED_SUBTYPES: ReadonlySet<string> = new Set([\n 'Highlight',\n 'Underline',\n 'StrikeOut',\n 'Squiggly',\n 'Text',\n 'FreeText',\n 'Square',\n 'Circle',\n 'Line',\n 'Polygon',\n 'PolyLine',\n 'Ink',\n 'Redact',\n])\n\nexport interface EmbeddedSummary {\n subtype: string\n count: number\n supported: boolean\n}\n\nexport function pdfColorToHex(\n c: ArrayLike<number> | null | undefined,\n fallback: string\n): string {\n if (!c || c.length < 3) return fallback\n const hex = [c[0]!, c[1]!, c[2]!]\n .map((n) => Math.round(n).toString(16).padStart(2, '0'))\n .join('')\n return `#${hex}`.toUpperCase()\n}\n\n/** PDF.js hands back `rect` already in user space, but not always ordered; normalise with min/max. */\nfunction rectFromPdf(r: ArrayLike<number>): Rect {\n return rectFromPoints({ x: r[0]!, y: r[1]! }, { x: r[2]!, y: r[3]! })\n}\n\n/** A PDF name exactly as PDF.js gives it (names are case-sensitive), or undefined if invalid. */\nfunction pdfName(raw: string | undefined): string | undefined {\n return raw !== undefined && PDF_NAME.test(raw) ? raw : undefined\n}\n\n/** `head` and `tail` from a Line's or PolyLine's `/LE`, left out when both are `None`. */\nfunction lineEndingsOf(\n raw: readonly string[] | undefined\n): { head: string; tail: string } | Record<string, never> {\n // PDF.js already turns a name it does not know into `None`.\n const endings = raw?.map((e) => pdfName(e) ?? 'None')\n return endings && endings.length === 2 && endings.some((e) => e !== 'None')\n ? { head: endings[0]!, tail: endings[1]! }\n : {}\n}\n\n/**\n * Imported ids are `pdf:<page>:<pdfjsId>` (page is 0-based, pdfjsId is the annotation's object\n * reference such as `12R`). They are stable across opens of the same file, and `inReplyTo`\n * uses the same scheme so threads resolve.\n */\nexport function importedId(page: number, pdfjsId: string): string {\n return `pdf:${page}:${pdfjsId}`\n}\n\nexport function importEmbeddedPage(\n page: number,\n raw: PdfjsAnnotationData[],\n importedAt: string\n): { annotations: Annotation[]; counts: Record<string, number> } {\n const counts: Record<string, number> = {}\n const annotations: Annotation[] = []\n for (const data of raw) {\n counts[data.subtype] = (counts[data.subtype] ?? 0) + 1\n if (!SUPPORTED_SUBTYPES.has(data.subtype) || data.hidden || data.noView) continue\n const converted = convert(page, data, importedAt)\n if (converted) annotations.push(converted)\n }\n return { annotations, counts }\n}\n\nexport function summarise(perPage: Record<string, number>[]): EmbeddedSummary[] {\n const totals = new Map<string, number>()\n for (const counts of perPage) {\n for (const [k, v] of Object.entries(counts)) totals.set(k, (totals.get(k) ?? 0) + v)\n }\n return [...totals.entries()]\n .map(([subtype, count]) => ({\n subtype,\n count,\n supported: SUPPORTED_SUBTYPES.has(subtype),\n }))\n .sort((a, b) => (a.subtype < b.subtype ? -1 : a.subtype > b.subtype ? 1 : 0))\n}\n\nfunction convert(\n page: number,\n d: PdfjsAnnotationData,\n importedAt: string\n): Annotation | undefined {\n const created = parsePdfDate(\n d.creationDate,\n parsePdfDate(d.modificationDate, importedAt)\n )\n const author = d.titleObj?.str\n const contents = d.contentsObj?.str\n const stroke = d.borderStyle?.width ?? 1\n const quads: Quad[] = d.quadPoints ? quadsFromFlat(d.quadPoints) : []\n const optional = (v: unknown) => v !== undefined && v !== ''\n const withColor = (type: Annotation['type'], source = d.color) =>\n pdfColorToHex(source, staticDefaults.color(type))\n const intent = pdfName(d.it)\n const base = (type: Annotation['type'], color = withColor(type)) => ({\n id: importedId(page, d.id),\n page,\n rect: rectFromPdf(d.rect),\n color,\n opacity: d.opacity ?? 1,\n ...(optional(author) ? { author } : {}),\n ...(optional(contents) ? { contents } : {}),\n ...(d.inReplyTo ? { inReplyTo: importedId(page, d.inReplyTo) } : {}),\n ...(intent !== undefined ? { intent } : {}),\n createdAt: created,\n modifiedAt: parsePdfDate(d.modificationDate, created),\n source: 'pdf' as const,\n locked: true,\n })\n const fillOf = (c: ArrayLike<number> | null | undefined) =>\n c && c.length >= 3 ? { interiorColor: pdfColorToHex(c, '#FFFFFF') } : {}\n\n let candidate: Record<string, unknown>\n switch (d.subtype) {\n case 'Highlight':\n case 'Underline':\n case 'StrikeOut':\n case 'Squiggly': {\n if (quads.length === 0) return undefined\n const type =\n d.subtype === 'StrikeOut' ? 'strikeout' : (d.subtype.toLowerCase() as 'highlight')\n candidate = { ...base(type), type, quads }\n break\n }\n case 'Text': {\n // PDF.js reports `NoIcon` for any note with an appearance stream, hiding its `/Name`.\n // Leave the icon out then, as when there is no `/Name`, so the default `Note` applies.\n const icon = d.name === 'NoIcon' ? undefined : pdfName(d.name)\n candidate = {\n ...base('text'),\n type: 'text',\n ...(icon !== undefined ? { icon } : {}),\n }\n break\n }\n case 'FreeText': {\n // XFDF and PDF agree: `/C` is the box's fill, `/DA` the text's colour and size.\n const da = d.defaultAppearanceData\n const { color: _stroke, ...rest } = base('freetext')\n candidate = {\n ...rest,\n ...(d.color && d.color.length >= 3\n ? { color: pdfColorToHex(d.color, '#FFFFFF') }\n : {}),\n type: 'freetext',\n contents: contents ?? '',\n width: d.borderStyle?.width ?? 0,\n defaultStyle: {\n color: pdfColorToHex(\n da?.fontColor as ArrayLike<number> | undefined,\n staticDefaults.color('freetext')\n ),\n ...(da && da.fontSize > 0 ? { fontSize: da.fontSize } : {}),\n },\n }\n break\n }\n case 'Square':\n case 'Circle': {\n const type = d.subtype.toLowerCase() as 'square' | 'circle'\n candidate = { ...base(type), type, width: stroke, ...fillOf(d.interiorColor) }\n break\n }\n case 'Line': {\n const l = d.lineCoordinates ?? [d.rect[0], d.rect[1], d.rect[2], d.rect[3]]\n candidate = {\n ...base('line'),\n type: 'line',\n start: { x: l[0], y: l[1] },\n end: { x: l[2], y: l[3] },\n width: stroke,\n ...lineEndingsOf(d.lineEndings),\n }\n break\n }\n case 'Polygon':\n case 'PolyLine': {\n const type = d.subtype === 'Polygon' ? 'polygon' : 'polyline'\n const vertices = d.vertices ? pointsFromFlat(d.vertices) : []\n if (vertices.length < 2) return undefined\n candidate = {\n ...base(type),\n type,\n vertices,\n width: stroke,\n ...fillOf(d.interiorColor),\n ...(type === 'polyline' ? lineEndingsOf(d.lineEndings) : {}),\n }\n break\n }\n case 'Ink': {\n const inklist: Point[][] = (d.inkLists ?? [])\n .map((p) => pointsFromFlat(p))\n .filter((p) => p.length > 0)\n if (inklist.length === 0) return undefined\n candidate = { ...base('ink'), type: 'ink', inklist, width: stroke }\n break\n }\n case 'Redact':\n // PDF.js 6.4 exposes neither QuadPoints nor /OverlayText for Redact, so only quads\n // that happen to be present are used, and `overlaidText` (the text beneath) is ignored.\n candidate = {\n ...base('redact'),\n type: 'redact',\n origin: 'user',\n interiorColor: pdfColorToHex(d.interiorColor, staticDefaults.fill()),\n ...(quads.length > 0 ? { quads } : {}),\n }\n break\n default:\n return undefined\n }\n const parsed = AnnotationSchema.safeParse(candidate)\n return parsed.success ? parsed.data : undefined\n}\n","/** True only when the build or runtime says production; browsers without `process` count as dev. */\nexport function isProduction(): boolean {\n try {\n return process.env.NODE_ENV === 'production'\n } catch {\n return false\n }\n}\n","import { isProduction } from '../env'\nimport { readonly, writable, type Readable } from '../readable'\n\nimport type { AnnotationChange, AnnotationStore } from './store'\nimport type { Annotation } from './types'\n\nexport interface History {\n readonly canUndo: Readable<boolean>\n readonly canRedo: Readable<boolean>\n undo(): void\n redo(): void\n clear(): void\n /**\n * Runs `fn` and records everything it changes as one undo entry. Change events still fire once\n * per annotation. Nested calls join the outer batch. `fn` must be synchronous; changes after an\n * `await` are not part of the batch; a dev build warns when `fn` returns a promise. A throwing\n * `fn` still records what it changed, then rethrows. A batch whose list ends where it began\n * (the same annotations, by identity, in the same order) records nothing and keeps redo.\n * Calling `undo()` or `redo()` inside `fn` is not supported. On a controlled or destroyed\n * history this only runs `fn`, and a history destroyed inside `fn` records nothing.\n */\n batch(fn: () => void): void\n /** Unsubscribes from the store and empties both stacks; undo and redo become no-ops. */\n destroy(): void\n}\n\ninterface Entry {\n before: readonly Annotation[]\n after: readonly Annotation[]\n}\n\n/**\n * Snapshot-based undo and redo over an uncontrolled store.\n *\n * In controlled mode the host owns the list, so history is the host's concern (the Vue layer\n * offers `useHistory`). There `createHistory` returns an inert History: `canUndo` and `canRedo`\n * stay false, `undo` and `redo` do nothing, and nothing is recorded.\n */\nexport function createHistory(\n store: AnnotationStore,\n opts: { limit?: number } = {}\n): History {\n const canUndo = writable(false)\n const canRedo = writable(false)\n\n if (store.mode === 'controlled') {\n return {\n canUndo: readonly(canUndo),\n canRedo: readonly(canRedo),\n undo() {},\n redo() {},\n clear() {},\n batch(fn) {\n fn()\n },\n destroy() {},\n }\n }\n\n const limit = opts.limit ?? 200\n const undoStack: Entry[] = []\n const redoStack: Entry[] = []\n let previous = store.list.get()\n let replaying = false\n /** Open batch depth; while above zero, changes update `previous` but push no entry. */\n let depth = 0\n /** The list when the outermost batch opened (or was restarted by a replace). */\n let batchStart: readonly Annotation[] | null = null\n\n const sync = () => {\n canUndo.set(undoStack.length > 0)\n canRedo.set(redoStack.length > 0)\n }\n\n let destroyed = false\n const unsubscribe = store.on('change', (change: AnnotationChange) => {\n const current = store.list.get()\n // Our own replays (and any other history replace) never become entries.\n if (replaying || (change.kind === 'replace' && change.reason === 'history')) {\n previous = current\n return\n }\n if (change.kind === 'replace') {\n undoStack.length = 0\n redoStack.length = 0\n previous = current\n if (depth > 0) batchStart = current\n sync()\n return\n }\n if (depth > 0) {\n previous = current\n return\n }\n undoStack.push({ before: previous, after: current })\n if (undoStack.length > limit) undoStack.shift()\n redoStack.length = 0\n previous = current\n sync()\n })\n\n const apply = (list: readonly Annotation[]) => {\n replaying = true\n try {\n store.replaceAll([...list], 'history')\n } finally {\n replaying = false\n }\n }\n\n return {\n canUndo: readonly(canUndo),\n canRedo: readonly(canRedo),\n undo() {\n const entry = undoStack.pop()\n if (destroyed || !entry) return\n redoStack.push(entry)\n apply(entry.before)\n sync()\n },\n redo() {\n const entry = redoStack.pop()\n if (destroyed || !entry) return\n undoStack.push(entry)\n apply(entry.after)\n sync()\n },\n batch(fn) {\n if (destroyed) {\n fn()\n return\n }\n if (depth++ === 0) batchStart = store.list.get()\n try {\n const result: unknown = fn()\n if (\n result !== null &&\n typeof result === 'object' &&\n typeof (result as { then?: unknown }).then === 'function' &&\n !isProduction()\n ) {\n console.warn(\n '[inkbar] history.batch(fn): fn returned a promise. Changes after its first await are not part of the batch.'\n )\n }\n } finally {\n // A history destroyed inside `fn` records nothing more.\n if (--depth === 0 && !destroyed) {\n const before = batchStart\n batchStart = null\n const after = store.list.get()\n // A list that ends where it began, the same annotations in the same order, is no step.\n if (before && !sameAnnotations(before, after)) {\n undoStack.push({ before, after })\n if (undoStack.length > limit) undoStack.shift()\n redoStack.length = 0\n sync()\n }\n }\n }\n },\n destroy() {\n destroyed = true\n batchStart = null\n unsubscribe()\n undoStack.length = 0\n redoStack.length = 0\n sync()\n },\n clear() {\n undoStack.length = 0\n redoStack.length = 0\n previous = store.list.get()\n sync()\n },\n }\n}\n\n/** The same annotation objects in the same order. */\nfunction sameAnnotations(a: readonly Annotation[], b: readonly Annotation[]): boolean {\n return a === b || (a.length === b.length && a.every((x, i) => x === b[i]))\n}\n","import { isProduction } from '../env'\n\nimport {\n ANNOTATION_FORMAT,\n ANNOTATION_VERSION,\n AnnotationDocumentSchema,\n ExportedAnnotationSchema,\n type Annotation,\n type AnnotationDocument,\n type ExportedAnnotation,\n type ForeignAnnotation,\n} from './types'\n\nimport type { AnnotationStore } from './store'\n\nexport interface ImportResult {\n imported: number\n /**\n * Items whose `type` this version does not know (they still need a string `id` and a numeric\n * `page`). Keep them and pass them back to exportAnnotations.\n */\n unknown: ForeignAnnotation[]\n errors: { index: number; issues: string[] }[]\n}\n\nexport interface ImportOptions {\n /** `replace` drops every session annotation first; `merge` overwrites by id and keeps the rest. */\n mode: 'replace' | 'merge'\n}\n\nconst KNOWN_TYPES: ReadonlySet<string> = new Set(\n ExportedAnnotationSchema.options.flatMap(\n (o) => [...o.shape.type._zod.values] as string[]\n )\n)\n\n/**\n * Session annotations plus any preserved foreign items. Embedded (`source: 'pdf'`) ones stay in\n * the file. `source` and `locked` are viewer state and are left out.\n *\n * The result is a JSON copy (`JSON.parse(JSON.stringify(...))`), the same data a serialised\n * export would carry: editing it never touches the store, and values JSON cannot hold, such as\n * functions or `undefined` inside `custom`, are left out exactly as `JSON.stringify` would.\n *\n * Without foreign items the result validates against this version's `schema.json`. With them it\n * validates only against the newer schema that produced them, since this version's schema\n * describes only the types it knows.\n */\nexport function exportAnnotations(\n store: AnnotationStore,\n preserved: readonly ForeignAnnotation[] = [],\n documentKey?: string\n): AnnotationDocument {\n const session: ExportedAnnotation[] = store.list\n .get()\n .filter((a) => a.source === 'session')\n .map(({ source: _source, locked: _locked, ...rest }) => rest)\n return {\n format: ANNOTATION_FORMAT,\n version: ANNOTATION_VERSION,\n ...(documentKey === undefined ? {} : { documentKey }),\n annotations: JSON.parse(JSON.stringify([...session, ...preserved])) as Array<\n ExportedAnnotation | ForeignAnnotation\n >,\n }\n}\n\n/** @internal A validated import that has not touched the store yet. */\nexport interface ImportPlan {\n result: ImportResult\n /** Every id the payload brings in, known or foreign. */\n ids: ReadonlySet<string>\n /** Applies the plan to the store (one `replaceAll(..., 'import')`). */\n apply(): void\n}\n\n/**\n * Validates the envelope (throws a TypeError when it is not an inkbar/annotations v1 document),\n * then each item on its own. Embedded annotations are never touched; imported items become\n * session annotations.\n */\nexport function importAnnotations(\n store: AnnotationStore,\n data: AnnotationDocument | string,\n opts: ImportOptions\n): ImportResult {\n const plan = planImport(store, data, opts)\n plan.apply()\n return plan.result\n}\n\n/**\n * @internal Validation half of `importAnnotations`, so the document can record foreign items\n * before the store publishes the change.\n *\n * Ids are unique across the payload: the first item with an id claims it, and later ones (known\n * or foreign) are reported in `errors`, even when the first was itself rejected. An id that\n * matches an embedded annotation is rejected for known and foreign items alike. In `merge` mode an incoming item replaces whatever session\n * annotation has its id, whether the incoming item is known or foreign.\n */\nexport function planImport(\n store: AnnotationStore,\n data: AnnotationDocument | string,\n opts: ImportOptions\n): ImportPlan {\n const raw: unknown = typeof data === 'string' ? JSON.parse(data) : data\n const envelope = AnnotationDocumentSchema.safeParse(raw)\n if (!envelope.success) {\n throw new TypeError(\n `Expected an ${ANNOTATION_FORMAT} v${ANNOTATION_VERSION} document: ${envelope.error.issues\n .map((i) => `${i.path.join('.') || '(root)'}: ${i.message}`)\n .join('; ')}`\n )\n }\n const embeddedIds = new Set(\n store.list\n .get()\n .filter((a) => a.source === 'pdf')\n .map((a) => a.id)\n )\n const result: ImportResult = { imported: 0, unknown: [], errors: [] }\n const incoming: Annotation[] = []\n /** id -> index of the first item that used it, whether that item was accepted or not. */\n const seen = new Map<string, number>()\n /** Ids the import actually brings in. */\n const accepted = new Set<string>()\n /**\n * Reserves `id` for the item at `index`. Later items with the same id are duplicates even\n * when this one is rejected for reusing an embedded id.\n */\n const claim = (id: string, index: number): boolean => {\n const first = seen.get(id)\n if (first !== undefined) {\n result.errors.push({\n index,\n issues: [`id: duplicate id \"${id}\", already used by item ${first}`],\n })\n return false\n }\n seen.set(id, index)\n if (embeddedIds.has(id)) {\n result.errors.push({\n index,\n issues: [\n 'id: matches an annotation embedded in the PDF, which import never replaces',\n ],\n })\n return false\n }\n accepted.add(id)\n return true\n }\n\n envelope.data.annotations.forEach((item, index) => {\n const type = (item as { type?: unknown } | null)?.type\n if (typeof type === 'string' && !KNOWN_TYPES.has(type)) {\n if (!isForeign(item)) {\n result.errors.push({\n index,\n issues: [\n `type: unknown type \"${type}\" needs a string id and a numeric page to be preserved`,\n ],\n })\n } else if (claim(item.id, index)) {\n result.unknown.push(item)\n }\n return\n }\n // Unknown keys, including `source` and `locked`, are dropped here.\n const parsed = ExportedAnnotationSchema.safeParse(item)\n if (!parsed.success) {\n result.errors.push({\n index,\n issues: parsed.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`),\n })\n return\n }\n if (!claim(parsed.data.id, index)) return\n incoming.push({ ...parsed.data, source: 'session' })\n result.imported++\n })\n\n if (result.unknown.length > 0 && !isProduction()) {\n const types = [...new Set(result.unknown.map((u) => u.type))]\n console.warn(\n `[inkbar] importAnnotations kept ${result.unknown.length} annotation(s) of unknown type ` +\n `(${types.join(', ')}). They are not shown, and exportAnnotations writes them back out.`\n )\n }\n\n const ids: ReadonlySet<string> = accepted\n return {\n result,\n ids,\n apply() {\n const current = store.list.get()\n const embedded = current.filter((a) => a.source === 'pdf')\n if (opts.mode === 'replace') {\n store.replaceAll([...embedded, ...incoming], 'import')\n return\n }\n const byId = new Map(\n current\n .filter((a) => a.source === 'session' && !ids.has(a.id))\n .map((a) => [a.id, a])\n )\n for (const a of incoming) byId.set(a.id, a)\n store.replaceAll([...embedded, ...byId.values()], 'import')\n },\n }\n}\n\nfunction isForeign(item: unknown): item is ForeignAnnotation {\n if (typeof item !== 'object' || item === null || Array.isArray(item)) return false\n const { type, id, page } = item as Record<string, unknown>\n return typeof type === 'string' && typeof id === 'string' && typeof page === 'number'\n}\n","import { v7 as uuidv7 } from 'uuid'\n\nimport { isProduction } from '../env'\nimport { Emitter } from '../events'\nimport { rectFromQuad, unionRects, type Point, type Rect } from '../geometry'\nimport { readonly, writable, type Readable } from '../readable'\n\nimport {\n AnnotationSchema,\n confidenceBucket,\n type Annotation,\n type AnnotationInput,\n type AnnotationPatch,\n} from './types'\n\nimport type { AnnotationDefaults } from './defaults'\n\nexport type AnnotationChange =\n | { kind: 'add'; annotation: Annotation }\n | { kind: 'update'; id: string; before: Annotation; after: Annotation }\n | {\n kind: 'remove'\n /** The annotation `remove` was called with. */\n annotation: Annotation\n /** Everything that went: `annotation` first, then the replies removed with it. */\n removed: Annotation[]\n }\n | { kind: 'replace'; reason: 'import' | 'sync' | 'history' }\n\nexport type StoreMode =\n | { mode: 'uncontrolled'; initial?: Annotation[] }\n | {\n mode: 'controlled'\n initial: Annotation[]\n onChange: (next: Annotation[], change: AnnotationChange) => void\n }\n\nexport interface AnnotationStore {\n readonly mode: 'uncontrolled' | 'controlled'\n readonly list: Readable<readonly Annotation[]>\n readonly selection: Readable<readonly string[]>\n /** The colour, fill and opacity defaults new annotations get. */\n readonly defaults: AnnotationDefaults\n get(id: string): Annotation | undefined\n byPage(page: number): Annotation[]\n /**\n * Returns the completed annotation. In controlled mode it is proposed to the host, not\n * applied. Throws an `Error` naming the id when it is already in the list, whether it came\n * from `input.id` or the store's `id` generator.\n */\n add(input: AnnotationInput): Annotation\n /**\n * `id`, `type`, `createdAt` and `source` cannot be patched, nor can `locked` on an embedded\n * (`source: 'pdf'`) annotation: those keys are ignored. `modifiedAt` is always bumped. A\n * locked annotation refuses any patch to its geometry, `page` or `contents`.\n */\n update(id: string, patch: AnnotationPatch): Annotation | undefined\n remove(id: string): boolean\n select(ids: string[]): void\n /**\n * Uncontrolled: embedded annotations survive (the list may edit them like `update` would, but\n * cannot drop or add them). Controlled: proposes the list minus embedded items to `onChange`.\n */\n replaceAll(list: Annotation[], reason: 'import' | 'sync' | 'history'): void\n /**\n * Controlled mode only: the host pushes its current list. Embedded (`source: 'pdf'`) items\n * belong to the store, so they stay in `list` whatever the host sends; host items that reuse\n * an embedded id are dropped.\n */\n setControlledValue(list: Annotation[]): void\n /**\n * @internal Replaces the annotations embedded in the file (`source: 'pdf'`). Applied\n * directly in both modes and never passed to `onChange`; the document calls it once on open.\n */\n _setEmbedded(list: readonly Annotation[]): void\n /**\n * @internal Like `get`, but in controlled mode it also sees changes proposed to the host and\n * not applied yet: the list `update` and `remove` build on.\n */\n _getProposed(id: string): Annotation | undefined\n completeInput(input: AnnotationInput): Annotation\n on(event: 'change', fn: (change: AnnotationChange) => void): () => void\n destroy(): void\n}\n\nexport interface StoreOptions {\n mode: StoreMode\n defaults: AnnotationDefaults\n now?: () => string\n id?: () => string\n}\n\n/** Keys a locked annotation refuses to change. */\nconst LOCKED_KEYS = new Set([\n 'page',\n 'rect',\n 'quads',\n 'inklist',\n 'start',\n 'end',\n 'vertices',\n 'callout',\n 'contents',\n 'imagedata',\n 'rotation',\n])\n\nfunction keepKey(target: Record<string, unknown>, from: Annotation, key: string): void {\n if (Object.prototype.hasOwnProperty.call(from, key))\n target[key] = (from as Record<string, unknown>)[key]\n else delete target[key]\n}\n\n/** `proposed` as a replacement for embedded `current`, with what the file owns kept from `current`. */\nfunction guardEmbedded(current: Annotation, proposed: Annotation): Annotation {\n if (proposed === current) return current\n if (proposed.type !== current.type) return current\n const candidate: Record<string, unknown> = {\n ...proposed,\n id: current.id,\n createdAt: current.createdAt,\n source: 'pdf',\n }\n keepKey(candidate, current, 'locked')\n if (current.locked) for (const key of LOCKED_KEYS) keepKey(candidate, current, key)\n const parsed = AnnotationSchema.safeParse(candidate)\n return parsed.success ? parsed.data : current\n}\n\nexport function deriveRect(input: AnnotationInput): Rect {\n switch (input.type) {\n case 'highlight':\n case 'underline':\n case 'strikeout':\n case 'squiggly':\n return unionRects(input.quads.map(rectFromQuad))\n case 'redact':\n if (input.quads) return unionRects(input.quads.map(rectFromQuad))\n break\n case 'ink': {\n const pad = (input.width ?? 2) / 2\n const r = bounds(input.inklist.flat())\n return {\n x: r.x - pad,\n y: r.y - pad,\n width: r.width + pad * 2,\n height: r.height + pad * 2,\n }\n }\n case 'line':\n return bounds([input.start, input.end])\n case 'polyline':\n case 'polygon':\n return bounds(input.vertices)\n default:\n break\n }\n if (input.rect) return input.rect\n throw new TypeError(`rect is required for ${input.type}`)\n}\n\nfunction bounds(pts: readonly Point[]): Rect {\n const xs = pts.map((p) => p.x)\n const ys = pts.map((p) => p.y)\n const x = Math.min(...xs)\n const y = Math.min(...ys)\n return { x, y, width: Math.max(...xs) - x, height: Math.max(...ys) - y }\n}\n\n/** `o` without its `undefined` values. */\nfunction withoutUndefined(o: object): Record<string, unknown> {\n return Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined))\n}\n\n/**\n * A `defaultStyle` patch merges one level deep into the current one, so changing the weight\n * keeps the font and size. An `undefined` value removes its key.\n */\nfunction mergedStyle(\n before: Annotation,\n patch: AnnotationPatch\n): { defaultStyle?: Record<string, unknown> } {\n const next = (patch as { defaultStyle?: unknown }).defaultStyle\n if (before.type !== 'freetext' || next === undefined || next === null) return {}\n return { defaultStyle: withoutUndefined({ ...before.defaultStyle, ...next }) }\n}\n\n/** Pending-map key; only annotation changes are tracked, and the prefix keeps ids apart from any other slot. */\nfunction changeKey(change: Exclude<AnnotationChange, { kind: 'replace' }>): string {\n return `annotation:${change.kind === 'update' ? change.id : change.annotation.id}`\n}\n\n/** Structural equality for plain JSON values, ignoring `modifiedAt` at the top level. */\nfunction sameIgnoringModifiedAt(a: Annotation, b: Annotation): boolean {\n const { modifiedAt: _a, ...restA } = a\n const { modifiedAt: _b, ...restB } = b\n return deepEqual(restA, restB)\n}\n\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true\n if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null)\n return false\n if (Array.isArray(a) !== Array.isArray(b)) return false\n const ka = Object.keys(a)\n const kb = Object.keys(b)\n if (ka.length !== kb.length) return false\n return ka.every(\n (k) =>\n Object.prototype.hasOwnProperty.call(b, k) &&\n deepEqual((a as Record<string, unknown>)[k], (b as Record<string, unknown>)[k])\n )\n}\n\nfunction isApplied(change: AnnotationChange, current: readonly Annotation[]): boolean {\n switch (change.kind) {\n case 'add':\n return current.some((a) => a.id === change.annotation.id)\n case 'remove':\n return !current.some((a) => a.id === change.annotation.id)\n case 'update': {\n const mine = current.find((a) => a.id === change.id)\n if (!mine) return false\n // A host or server may re-stamp modifiedAt, so fall back to a structural match.\n return mine === change.after || sameIgnoringModifiedAt(mine, change.after)\n }\n case 'replace':\n return true\n }\n}\n\ninterface Pending {\n id: string\n change: AnnotationChange\n timer: ReturnType<typeof setTimeout>\n}\n\nexport function createAnnotationStore(opts: StoreOptions): AnnotationStore {\n const now = opts.now ?? (() => new Date().toISOString())\n const nextId = opts.id ?? (() => uuidv7())\n const list = writable<readonly Annotation[]>([...(opts.mode.initial ?? [])])\n const selection = writable<readonly string[]>([])\n const emitter = new Emitter<{ change: AnnotationChange }>()\n const controlled = opts.mode.mode === 'controlled' ? opts.mode : undefined\n const pending = new Map<string, Pending>()\n /**\n * Controlled mode: the list as the store last proposed it, embedded items included. Later\n * proposals build on it, so several mutations in a row (one highlight per page, a bulk\n * remove, add then select) all reach the host. It resets to the applied list when the host\n * pushes a value or a pending change's check fires without one.\n */\n let proposed: readonly Annotation[] | undefined\n let destroyed = false\n\n /** What mutations build on: the pending proposal in controlled mode, else the list. */\n const basis = (): readonly Annotation[] => proposed ?? list.get()\n const findIn = (items: readonly Annotation[], id: string): Annotation | undefined =>\n items.find((a) => a.id === id)\n\n function completeInput(input: AnnotationInput): Annotation {\n const ts = now()\n const candidate: Record<string, unknown> = {\n ...input,\n id: input.id ?? nextId(),\n rect: input.rect ?? deriveRect(input),\n color: input.color ?? opts.defaults.color(input.type),\n opacity: input.opacity ?? opts.defaults.opacity(input.type),\n createdAt: ts,\n modifiedAt: ts,\n source: 'session',\n }\n if (input.type === 'freetext') {\n // A box's `color` is its fill, which has no default: the default colour is the text's.\n if (input.color === undefined) delete candidate.color\n candidate.defaultStyle = {\n color: opts.defaults.color('freetext'),\n ...withoutUndefined(input.defaultStyle ?? {}),\n }\n }\n if (input.type === 'redact') {\n if (input.interiorColor === undefined)\n candidate.interiorColor = opts.defaults.fill()\n if (input.origin === 'suggested' && input.suggestion && input.color === undefined) {\n candidate.color = opts.defaults.suggestion(\n confidenceBucket(input.suggestion.confidence)\n )\n }\n }\n return AnnotationSchema.parse(candidate)\n }\n\n function clearPending(key: string): void {\n const entry = pending.get(key)\n if (!entry) return\n clearTimeout(entry.timer)\n pending.delete(key)\n }\n\n function warnIfIgnored(key: string): void {\n const entry = pending.get(key)\n if (!entry) return\n pending.delete(key)\n // Later proposals may still be pending; they keep building on the proposed list.\n if (pending.size === 0) proposed = undefined\n if (isApplied(entry.change, list.get()) || isProduction()) return\n console.warn(\n `[inkbar] ControlledMutationIgnored: the host did not apply a ${entry.change.kind} for ` +\n `annotation ${entry.id}. In controlled mode, pass the list from onChange back into the store.`\n )\n }\n\n function commit(next: readonly Annotation[], change: AnnotationChange): void {\n if (controlled) {\n if (change.kind !== 'replace') {\n const key = changeKey(change)\n clearPending(key)\n // Two macrotasks. Vue applies the change in a microtask; React may apply it after its\n // scheduler's macrotask plus an effect, so one macrotask warns a host that did apply it.\n const entry: Pending = {\n id: change.kind === 'update' ? change.id : change.annotation.id,\n change,\n timer: setTimeout(() => {\n entry.timer = setTimeout(() => {\n warnIfIgnored(key)\n }, 0)\n }, 0),\n }\n pending.set(key, entry)\n }\n proposed =\n change.kind === 'replace'\n ? [\n ...list.get().filter((a) => a.source === 'pdf'),\n ...next.filter((a) => a.source !== 'pdf'),\n ]\n : next\n // Embedded items are the store's, never the host's.\n controlled.onChange(\n next.filter((a) => a.source !== 'pdf'),\n change\n )\n return\n }\n list.set(next)\n emitter.emit('change', change)\n }\n\n /**\n * Uncontrolled `replaceAll` cannot drop or forge embedded annotations: every current embedded\n * item stays (taking the list's version of it, guarded like `update`, when the list has one),\n * and items claiming `source: 'pdf'` that the store does not hold are dropped. History\n * snapshots contain the embedded items, so undo and redo of their edits still work.\n */\n function withEmbedded(proposed: readonly Annotation[]): Annotation[] {\n const current = new Map(\n list\n .get()\n .filter((a) => a.source === 'pdf')\n .map((a) => [a.id, a])\n )\n const seen = new Set<string>()\n const out: Annotation[] = []\n for (const a of proposed) {\n const mine = current.get(a.id)\n if (mine) {\n if (!seen.has(a.id)) out.push(guardEmbedded(mine, a))\n seen.add(a.id)\n } else if (a.source !== 'pdf') {\n out.push(a)\n }\n }\n return [...[...current.values()].filter((a) => !seen.has(a.id)), ...out]\n }\n\n function pruneSelection(next: readonly Annotation[]): void {\n const known = new Set(next.map((a) => a.id))\n const current = selection.get()\n if (current.every((id) => known.has(id))) return\n selection.set(current.filter((id) => known.has(id)))\n }\n\n const store: AnnotationStore = {\n mode: opts.mode.mode,\n list: readonly(list),\n selection: readonly(selection),\n defaults: opts.defaults,\n get: (id) => list.get().find((a) => a.id === id),\n _getProposed: (id) => findIn(basis(), id),\n byPage: (page) => list.get().filter((a) => a.page === page),\n completeInput,\n add(input) {\n const a = completeInput(input)\n // Covers ids from the input and from the `id` option's generator alike.\n if (findIn(basis(), a.id))\n throw new Error(`An annotation with id ${a.id} already exists`)\n if (destroyed) return a\n // One mask per page: a new one replaces the page's session mask in the same change, so\n // the history step and the host's `onChange` see the swap once.\n const replaced =\n a.type === 'mask'\n ? basis().filter(\n (x) => x.type === 'mask' && x.page === a.page && x.source !== 'pdf'\n )\n : []\n const gone = new Set(replaced.map((x) => x.id))\n for (const x of replaced) clearPending(changeKey({ kind: 'add', annotation: x }))\n commit([...basis().filter((x) => !gone.has(x.id)), a], {\n kind: 'add',\n annotation: a,\n })\n if (!controlled && gone.size > 0) pruneSelection(list.get())\n return a\n },\n update(id, patch) {\n const before = findIn(basis(), id)\n if (destroyed || !before) return undefined\n if (before.locked && Object.keys(patch).some((k) => LOCKED_KEYS.has(k)))\n return undefined\n const candidate: Record<string, unknown> = {\n ...before,\n ...patch,\n ...mergedStyle(before, patch),\n id: before.id,\n type: before.type,\n createdAt: before.createdAt,\n source: before.source,\n modifiedAt: now(),\n }\n // An embedded annotation's lock belongs to the file: a `locked` key in the patch is ignored.\n if (before.source === 'pdf') keepKey(candidate, before, 'locked')\n const after = AnnotationSchema.parse(candidate)\n const swap = (items: readonly Annotation[]): Annotation[] =>\n items.map((a) => (a.id === id ? after : a))\n const next = swap(basis())\n const change: AnnotationChange = { kind: 'update', id, before, after }\n if (controlled && before.source === 'pdf') {\n // The host never holds embedded items, so their edits apply here.\n list.set(swap(list.get()))\n if (proposed) proposed = next\n emitter.emit('change', change)\n } else {\n commit(next, change)\n }\n return after\n },\n remove(id) {\n const items = basis()\n const target = findIn(items, id)\n if (destroyed || !target || target.locked) return false\n const doomed = new Set<string>([id])\n let grew = true\n while (grew) {\n grew = false\n for (const a of items) {\n if (a.inReplyTo !== undefined && doomed.has(a.inReplyTo) && !doomed.has(a.id)) {\n doomed.add(a.id)\n grew = true\n }\n }\n }\n const next = items.filter((a) => !doomed.has(a.id))\n const removed = [target, ...items.filter((a) => a.id !== id && doomed.has(a.id))]\n commit(next, { kind: 'remove', annotation: target, removed })\n if (!controlled) pruneSelection(next)\n return true\n },\n select(ids) {\n const known = new Set(basis().map((a) => a.id))\n selection.set(ids.filter((id) => known.has(id)))\n },\n replaceAll(list, reason) {\n if (destroyed) return\n const next = controlled ? [...list] : withEmbedded(list)\n commit(next, { kind: 'replace', reason })\n if (!controlled) pruneSelection(next)\n },\n setControlledValue(value) {\n if (!controlled)\n throw new TypeError('setControlledValue is only valid in controlled mode')\n if (destroyed) return\n const embedded = list.get().filter((a) => a.source === 'pdf')\n const embeddedIds = new Set(embedded.map((a) => a.id))\n const next = [...embedded, ...value.filter((a) => !embeddedIds.has(a.id))]\n list.set(next)\n proposed = undefined\n for (const [key, entry] of [...pending]) {\n if (isApplied(entry.change, next)) clearPending(key)\n }\n pruneSelection(next)\n emitter.emit('change', { kind: 'replace', reason: 'sync' })\n },\n _setEmbedded(items) {\n if (destroyed) return\n const ids = new Set(items.map((a) => a.id))\n const next = [\n ...items,\n ...list.get().filter((a) => a.source !== 'pdf' && !ids.has(a.id)),\n ]\n proposed = undefined\n list.set(next)\n pruneSelection(next)\n emitter.emit('change', { kind: 'replace', reason: 'import' })\n },\n on: (event, fn) => emitter.on(event, fn),\n destroy() {\n destroyed = true\n proposed = undefined\n for (const key of [...pending.keys()]) clearPending(key)\n emitter.clear()\n },\n }\n return store\n}\n","/**\n * Internal (not exported from the package): one in-flight or settled lookup per page index.\n * A lookup that rejects is evicted, so the next request for that page asks again instead of\n * replaying the failure for the rest of the session.\n */\nexport interface PageCache<T> {\n get(index: number): Promise<T>\n clear(): void\n}\n\nexport function createPageCache<T>(fetch: (index: number) => Promise<T>): PageCache<T> {\n const cache = new Map<number, Promise<T>>()\n return {\n get(index) {\n const cached = cache.get(index)\n if (cached) return cached\n const fetched = fetch(index)\n cache.set(index, fetched)\n fetched.catch(() => {\n if (cache.get(index) === fetched) cache.delete(index)\n })\n return fetched\n },\n clear: () => cache.clear(),\n }\n}\n","import type { Rect } from './geometry'\nimport type { PdfjsPage } from '../pdfjs/types'\n\nexport type PageRotation = 0 | 90 | 180 | 270\n\nexport interface PageInfo {\n index: number\n /** CropBox ∩ MediaBox in user space before /Rotate, as PDF.js reports `page.view`. */\n box: Rect\n /** The page's own /Rotate. View rotation applied by the viewer is separate. */\n rotate: PageRotation\n userUnit: number\n /** Unrotated box width in points. */\n width: number\n /** Unrotated box height in points. */\n height: number\n}\n\nexport function pageInfoFromProxy(page: PdfjsPage, index: number): PageInfo {\n const [x1, y1, x2, y2] = page.view as [number, number, number, number]\n const box: Rect = {\n x: Math.min(x1, x2),\n y: Math.min(y1, y2),\n width: Math.abs(x2 - x1),\n height: Math.abs(y2 - y1),\n }\n return {\n index,\n box,\n rotate: normaliseRotation(page.rotate),\n userUnit: page.userUnit > 0 ? page.userUnit : 1,\n width: box.width,\n height: box.height,\n }\n}\n\n/** PDF.js already rejects /Rotate values that are not multiples of 90; this also folds negatives. */\nfunction normaliseRotation(rotate: number): PageRotation {\n const r = (((Math.round(rotate / 90) * 90) % 360) + 360) % 360\n return r as PageRotation\n}\n","import { v7 as uuidv7 } from 'uuid'\n\nimport { InkError } from './errors'\n\nexport type DocumentSource =\n | ArrayBuffer\n | Uint8Array\n | Blob\n | string\n | { url: string; key: string }\n | { data: ArrayBuffer | Uint8Array; key: string }\n\nexport interface ResolvedSource {\n /** Identity of the document. Hosts reuse it to avoid reloads when a signed URL changes. */\n key: string\n bytes(): Promise<Uint8Array>\n}\n\nexport function resolveSource(\n src: DocumentSource,\n fetchImpl: typeof fetch = globalThis.fetch\n): ResolvedSource {\n if (typeof src === 'string')\n return { key: src, bytes: () => fetchBytes(src, fetchImpl) }\n if (src instanceof ArrayBuffer || src instanceof Uint8Array) {\n const data = toBytes(src)\n return { key: `bytes:${uuidv7()}`, bytes: () => Promise.resolve(data.slice()) }\n }\n if ('url' in src) {\n const { url } = src\n return { key: src.key, bytes: () => fetchBytes(url, fetchImpl) }\n }\n if ('data' in src) {\n const data = toBytes(src.data)\n return { key: src.key, bytes: () => Promise.resolve(data.slice()) }\n }\n const blob = src\n return {\n key: `bytes:${uuidv7()}`,\n bytes: async () => new Uint8Array(await blob.arrayBuffer()),\n }\n}\n\n/**\n * A view over the host's bytes. `bytes()` hands PDF.js a copy each time: PDF.js transfers the\n * buffer it is given to its worker, which would empty the host's array and break a reopen\n * (a password retry, for one).\n */\nfunction toBytes(data: ArrayBuffer | Uint8Array): Uint8Array {\n return data instanceof Uint8Array ? data : new Uint8Array(data)\n}\n\nasync function fetchBytes(url: string, fetchImpl: typeof fetch): Promise<Uint8Array> {\n if (typeof fetchImpl !== 'function') {\n throw new InkError(\n 'SourceFetchFailed',\n 'No fetch implementation available for URL sources',\n {\n url,\n }\n )\n }\n let res: Response\n try {\n res = await fetchImpl(url, { credentials: 'same-origin' })\n } catch (cause) {\n throw new InkError('SourceFetchFailed', `Could not fetch ${url}`, { url }, cause)\n }\n if (!res.ok) {\n throw new InkError(\n 'SourceFetchFailed',\n `Fetching ${url} returned HTTP ${res.status}`,\n {\n url,\n status: res.status,\n }\n )\n }\n try {\n return new Uint8Array(await res.arrayBuffer())\n } catch (cause) {\n throw new InkError(\n 'SourceFetchFailed',\n `Reading the body of ${url} failed`,\n { url },\n cause\n )\n }\n}\n","import { rectFromQuad, type Point, type Quad, type Rect } from './geometry'\n\nimport type { PdfjsTextContent, PdfjsTextItem } from '../pdfjs/types'\n\nexport interface TextItem {\n str: string\n dir: 'ltr' | 'rtl' | 'ttb'\n fontName: string\n fontSize: number\n hasEOL: boolean\n /** Glyph-run box in user space, following the run's rotation. */\n quad: Quad\n /** Axis-aligned bounds of `quad`. */\n rect: Rect\n}\n\nexport interface TextContent {\n page: number\n items: TextItem[]\n}\n\n/** Fractions of the font size used when PDF.js has no usable metrics for the font. */\nconst FALLBACK_ASCENT = 0.75\nconst FALLBACK_DESCENT = 0.25\n\n/**\n * Converts `getTextContent()` output to user-space boxes.\n *\n * For an item with transform [a, b, c, d, e, f] (already in user space):\n * - (e, f) is the start of the run on the baseline;\n * - u = (a, b) / |(a, b)| is the baseline direction, along which the run advances `width`;\n * - v = (c, d) / |(c, d)| is the glyph-up direction, and `fontSize` = |(c, d)|;\n * - the box spans from `descent * fontSize` below the baseline to `ascent * fontSize` above it,\n * using the font's ascent/descent from `styles` when PDF.js provides them, else 0.75 / 0.25.\n *\n * So p3 = (e, f) - v * descent * fontSize, p4 = p3 + u * width, p1 = p3 + v * (ascent + descent) * fontSize,\n * p2 = p4 + (p1 - p3). `rect` is the axis-aligned bounding box of the quad.\n */\nexport function textContentFromPdfjs(page: number, tc: PdfjsTextContent): TextContent {\n const items: TextItem[] = []\n for (const raw of tc.items) {\n if (!('str' in raw)) continue\n const item: PdfjsTextItem = raw\n const [a, b, c, d, e, f] = item.transform as [\n number,\n number,\n number,\n number,\n number,\n number,\n ]\n const baseLen = Math.hypot(a, b)\n const fontSize = Math.hypot(c, d)\n const u: Point = baseLen === 0 ? { x: 1, y: 0 } : { x: a / baseLen, y: b / baseLen }\n const v: Point =\n fontSize === 0 ? { x: -u.y, y: u.x } : { x: c / fontSize, y: d / fontSize }\n const { ascent, descent } = metrics(tc.styles[item.fontName])\n const below = descent * fontSize\n const total = (ascent + descent) * fontSize\n const w = item.width\n const p3 = { x: e - v.x * below, y: f - v.y * below }\n const p4 = { x: p3.x + u.x * w, y: p3.y + u.y * w }\n const p1 = { x: p3.x + v.x * total, y: p3.y + v.y * total }\n const p2 = { x: p4.x + v.x * total, y: p4.y + v.y * total }\n const quad: Quad = { p1, p2, p3, p4 }\n items.push({\n str: item.str,\n dir: isDir(item.dir) ? item.dir : 'ltr',\n fontName: item.fontName,\n fontSize,\n hasEOL: item.hasEOL,\n quad,\n rect: rectFromQuad(quad),\n })\n }\n return { page, items }\n}\n\nfunction metrics(style: PdfjsTextContent['styles'][string] | undefined): {\n ascent: number\n descent: number\n} {\n // Vertical fonts report metrics for horizontal layout, so they get the fallback box too.\n if (!style || style.vertical)\n return { ascent: FALLBACK_ASCENT, descent: FALLBACK_DESCENT }\n const ascent = style.ascent\n const descent = Math.abs(style.descent)\n if (!(ascent > 0) || !Number.isFinite(descent) || ascent + descent <= 0) {\n return { ascent: FALLBACK_ASCENT, descent: FALLBACK_DESCENT }\n }\n return { ascent, descent }\n}\n\nfunction isDir(dir: string): dir is TextItem['dir'] {\n return dir === 'ltr' || dir === 'rtl' || dir === 'ttb'\n}\n","import { assertAssets, loadPdfjs, openProxy } from '../pdfjs/load'\n\nimport { staticDefaults, type AnnotationDefaults } from './annotations/defaults'\nimport {\n importEmbeddedPage,\n summarise,\n type EmbeddedSummary,\n} from './annotations/embedded'\nimport { createHistory, type History } from './annotations/history'\nimport {\n exportAnnotations,\n planImport,\n type ImportOptions,\n type ImportResult,\n} from './annotations/json'\nimport {\n createAnnotationStore,\n type AnnotationStore,\n type StoreMode,\n} from './annotations/store'\nimport { InkError, isInkError } from './errors'\nimport { createPageCache, type PageCache } from './page-cache'\nimport { pageInfoFromProxy, type PageInfo } from './pages'\nimport { readonly, writable, type Readable } from './readable'\nimport { resolveSource, type DocumentSource } from './source'\nimport { textContentFromPdfjs, type TextContent } from './text'\n\nimport type { AnnotationDocument, ForeignAnnotation } from './annotations/types'\nimport type {\n PdfAssets,\n PdfjsAnnotationData,\n PdfjsDocument,\n PdfjsModule,\n PdfjsPage,\n} from '../pdfjs/types'\n\nexport type DocumentStatus =\n { state: 'loading' } | { state: 'ready' } | { state: 'error'; error: InkError }\n\n/** A document's status plus `idle`, for a host with no document open. */\nexport type InkStatus = DocumentStatus | { state: 'idle' }\n\nexport interface DocumentInfo {\n title?: string | undefined\n author?: string | undefined\n pageCount: number\n isEncrypted: boolean\n}\n\nexport interface OpenOptions {\n assets: PdfAssets\n password?: string | undefined\n fetch?: typeof fetch | undefined\n /**\n * Defaults to uncontrolled. In controlled mode the host owns only session annotations:\n * embedded (`source: 'pdf'`) ones live in the store, are never passed to `onChange`, and stay\n * in `list` whatever the host pushes back.\n */\n annotations?: StoreMode | undefined\n /** Colour defaults. Pass `cssVariableDefaults(element)` from the DOM layer to read theme variables. */\n defaults?: AnnotationDefaults | undefined\n /**\n * Undo history, on by default. `false` disables it. In controlled mode history is always\n * inert: the host owns the list, so it owns undo too.\n */\n history?: boolean | { limit?: number | undefined } | undefined\n /** PDF.js verbosity level; 0 = errors only. Defaults to PDF.js's own level. */\n verbosity?: number | undefined\n}\n\nexport interface InkDocument {\n readonly key: string\n readonly status: Readable<DocumentStatus>\n /** Resolves when status is ready; rejects with the InkError when it is error. */\n readonly ready: Promise<void>\n readonly pages: readonly PageInfo[]\n readonly info: DocumentInfo\n text(page: number): Promise<TextContent>\n /**\n * Annotations embedded in the file arrive here as `source: 'pdf'`, `locked: true` before\n * `ready` resolves. They stay in `list` in both modes and cannot be removed; in controlled\n * mode they never reach `onChange`.\n */\n readonly annotations: AnnotationStore\n /** What the file contained, by PDF subtype, including subtypes Inkbar does not show. */\n readonly embedded: readonly EmbeddedSummary[]\n readonly history: History\n /** Session annotations only, plus unknown-type items kept from earlier imports. */\n exportAnnotations(format: 'json'): AnnotationDocument\n /** Defaults to `{ mode: 'replace' }`. Embedded annotations are never touched. */\n importAnnotations(data: AnnotationDocument | string, opts?: ImportOptions): ImportResult\n /** Writes the document with its annotations. Needs @inkbar/engine; rejects with EngineUnavailable otherwise. */\n save(): Promise<Uint8Array>\n destroy(): void\n /** @internal PDF.js handles for the DOM layer. Not part of the public contract. */\n readonly _pdfjs: {\n module: PdfjsModule\n proxy: PdfjsDocument\n getPage(index: number): Promise<PdfjsPage>\n }\n}\n\ninterface PdfjsInfoDict {\n Title?: unknown\n Author?: unknown\n EncryptFilterName?: unknown\n}\n\n/**\n * Opens a document. Resolves once loading has finished, whether it succeeded or not:\n * check `status` or await `ready`, which rejects with the InkError. Only a missing\n * `assets` option (a programmer error) makes this promise itself reject.\n */\nexport async function openDocument(\n source: DocumentSource,\n options: OpenOptions\n): Promise<InkDocument> {\n assertAssets(options?.assets)\n const resolved = resolveSource(source, options.fetch)\n const status = writable<DocumentStatus>({ state: 'loading' })\n const pages: PageInfo[] = []\n const info: DocumentInfo = { pageCount: 0, isEncrypted: false }\n let pageCache: PageCache<PdfjsPage> | undefined\n let destroyed = false\n let handles: InkDocument['_pdfjs'] | undefined\n let destroyTask: (() => Promise<void>) | undefined\n\n const store = createAnnotationStore({\n mode: options.annotations ?? { mode: 'uncontrolled' },\n defaults: options.defaults ?? staticDefaults,\n })\n const embedded: EmbeddedSummary[] = []\n let preserved: ForeignAnnotation[] = []\n\n const destroyedError = (): InkError =>\n new InkError('DocumentDestroyed', 'The document has been destroyed')\n\n const load = (async () => {\n const pdfjs = await loadPdfjs(options.assets)\n const bytes = await resolved.bytes()\n const { task, proxy } = await openProxy(pdfjs, bytes, {\n assets: options.assets,\n password: options.password,\n verbosity: options.verbosity,\n })\n destroyTask = () => task.destroy()\n const cache = createPageCache((index) => proxy.getPage(index + 1))\n pageCache = cache\n const getPage = (index: number): Promise<PdfjsPage> => {\n if (destroyed) return Promise.reject(destroyedError())\n if (!Number.isInteger(index) || index < 0 || index >= proxy.numPages) {\n return Promise.reject(\n new InkError('PageOutOfRange', `Page ${index} does not exist`, {\n index,\n pageCount: proxy.numPages,\n })\n )\n }\n // A failed lookup is not cached: the next mount of the page asks PDF.js again.\n return cache.get(index)\n }\n handles = { module: pdfjs, proxy, getPage }\n const meta = await proxy.getMetadata().catch(() => {\n // Metadata is optional: PDF.js throws on malformed Info dictionaries or XMP, and\n // title/author are nice-to-have. The document itself has opened, so carry on without it.\n return undefined\n })\n const docInfo = (meta?.info ?? {}) as PdfjsInfoDict\n const title = nonEmptyString(docInfo.Title)\n const author = nonEmptyString(docInfo.Author)\n if (title !== undefined) info.title = title\n if (author !== undefined) info.author = author\n info.pageCount = proxy.numPages\n info.isEncrypted =\n docInfo.EncryptFilterName !== null && docInfo.EncryptFilterName !== undefined\n for (let i = 0; i < proxy.numPages; i++)\n pages.push(pageInfoFromProxy(await getPage(i), i))\n\n const importedAt = new Date().toISOString()\n const perPage = await mapInOrder(proxy.numPages, EMBEDDED_CONCURRENCY, async (i) => {\n const page = await getPage(i)\n const raw: PdfjsAnnotationData[] = await page.getAnnotations().catch(() => {\n // A page whose annotations PDF.js cannot parse still renders; it just has none to show.\n return []\n })\n return importEmbeddedPage(i, raw, importedAt)\n })\n embedded.push(...summarise(perPage.map((r) => r.counts)))\n const fromFile = perPage.flatMap((r) => r.annotations)\n if (fromFile.length > 0) store._setEmbedded(fromFile)\n })()\n\n const ready = load.then(\n () => {\n status.set({ state: 'ready' })\n },\n (cause: unknown) => {\n const error = isInkError(cause)\n ? cause\n : new InkError('InvalidPdf', errorMessage(cause), {}, cause)\n if (error.code === 'PasswordRequired') info.isEncrypted = true\n status.set({ state: 'error', error })\n throw error\n }\n )\n // Keep the rejection observed so hosts that only watch `status` get no unhandled-rejection warning.\n await ready.catch(() => undefined)\n\n // Created after the embedded import, so loading the file is not an undoable step.\n const historyOption = options.history ?? true\n const historyLimit =\n historyOption === false ? 0 : historyOption === true ? undefined : historyOption.limit\n const history = createHistory(\n store,\n historyLimit === undefined ? {} : { limit: historyLimit }\n )\n\n const doc: InkDocument = {\n key: resolved.key,\n status: readonly(status),\n ready,\n pages,\n info,\n async text(page) {\n if (destroyed) throw destroyedError()\n if (!handles) throw statusError(status.get())\n const p = await handles.getPage(page)\n return textContentFromPdfjs(page, await p.getTextContent())\n },\n annotations: store,\n embedded,\n history,\n exportAnnotations(format) {\n if (format !== 'json')\n throw new TypeError(`Unsupported export format ${String(format)}`)\n return exportAnnotations(store, preserved, resolved.key)\n },\n importAnnotations(data, opts = { mode: 'replace' }) {\n const plan = planImport(store, data, opts)\n // Staged before the store publishes, so a change listener that exports sees it.\n preserved =\n opts.mode === 'replace'\n ? plan.result.unknown\n : [...preserved.filter((u) => !plan.ids.has(u.id)), ...plan.result.unknown]\n plan.apply()\n return plan.result\n },\n save() {\n return Promise.reject(\n new InkError(\n 'EngineUnavailable',\n 'Saving needs @inkbar/engine, which is not registered. Use exportAnnotations(\"json\") to keep annotations without writing the PDF.'\n )\n )\n },\n destroy() {\n if (destroyed) return\n destroyed = true\n history.destroy()\n store.destroy()\n pageCache?.clear()\n if (destroyTask) {\n teardown(destroyTask)\n }\n },\n get _pdfjs() {\n if (!handles) throw statusError(status.get())\n return handles\n },\n }\n return doc\n}\n\nconst EMBEDDED_CONCURRENCY = 8\n\n/** Runs `task(0..count-1)` with at most `limit` in flight; results come back in index order. */\nasync function mapInOrder<T>(\n count: number,\n limit: number,\n task: (index: number) => Promise<T>\n): Promise<T[]> {\n const results = new Array<T>(count)\n let next = 0\n const worker = async (): Promise<void> => {\n while (next < count) {\n const i = next++\n results[i] = await task(i)\n }\n }\n await Promise.all(Array.from({ length: Math.min(limit, count) }, worker))\n return results\n}\n\nfunction teardown(destroyTask: () => Promise<void>): void {\n destroyTask().catch(() => {\n // Teardown is best effort: the document is already marked destroyed and every later call\n // rejects with DocumentDestroyed, so a worker that fails to shut down cleanly changes nothing\n // the host can act on.\n })\n}\n\nfunction statusError(s: DocumentStatus): InkError {\n return s.state === 'error'\n ? s.error\n : new InkError('InvalidPdf', 'The document has not finished loading')\n}\n\nfunction nonEmptyString(value: unknown): string | undefined {\n return typeof value === 'string' && value !== '' ? value : undefined\n}\n\nfunction errorMessage(cause: unknown): string {\n if (cause instanceof Error) return cause.message\n return String(cause)\n}\n","// Geometry edits in user space, shared by the pointer (select tool) and keyboard (overlay)\n// paths so both produce the same patch for the same change.\nimport { translateQuad, translateRect, type Point, type Rect } from '../geometry'\n\nimport {\n calloutStroke,\n freeTextBox,\n isStandardCallout,\n withCalloutBounds,\n} from './callout'\n\nimport type {\n Annotation,\n FreeTextAnnotation,\n LineAnnotation,\n TextMarkupAnnotation,\n} from './types'\n\n/** Smallest width or height a resize leaves, user-space points. */\nexport const MIN_SIZE = 1\n\nconst shift = (p: Point, dx: number, dy: number): Point => ({ x: p.x + dx, y: p.y + dy })\n\n/** The geometry patch that translates `a` by (dx, dy) in user space. */\nexport function translated(a: Annotation, dx: number, dy: number): Partial<Annotation> {\n const patch: Record<string, unknown> = { rect: translateRect(a.rect, dx, dy) }\n if ('quads' in a && a.quads) patch.quads = a.quads.map((q) => translateQuad(q, dx, dy))\n if ('callout' in a && a.callout) patch.callout = a.callout.map((p) => shift(p, dx, dy))\n switch (a.type) {\n case 'line':\n patch.start = shift(a.start, dx, dy)\n patch.end = shift(a.end, dx, dy)\n break\n case 'polyline':\n case 'polygon':\n patch.vertices = a.vertices.map((p) => shift(p, dx, dy))\n break\n case 'ink':\n patch.inklist = a.inklist.map((path) => path.map((p) => shift(p, dx, dy)))\n break\n default:\n }\n return patch\n}\n\n/**\n * True when `rect` is the annotation's whole shape, so resizing means changing `rect`: area\n * redactions, free text, squares, circles, stamps, loupes and masks. Text-derived marks (quads), note icons and\n * point-based shapes are not.\n */\nexport function hasRectGeometry(a: Annotation): boolean {\n switch (a.type) {\n case 'redact':\n return a.quads === undefined || a.quads.length === 0\n case 'freetext':\n case 'square':\n case 'circle':\n case 'stamp':\n case 'loupe':\n case 'mask':\n return true\n default:\n return false\n }\n}\n\n/**\n * Grows (positive) or shrinks (negative) a rect by `dw` and `dh` points, keeping its top-left\n * corner (user space: left edge and top edge, `y + height`) where it is. Neither side goes\n * below `MIN_SIZE`. With `keepAspect`, the side that changes leads and the other follows it in\n * proportion (the width when both change).\n */\nexport function resizedRect(r: Rect, dw: number, dh: number, keepAspect = false): Rect {\n let width = Math.max(MIN_SIZE, r.width + dw)\n let height = Math.max(MIN_SIZE, r.height + dh)\n if (keepAspect && r.width > 0 && r.height > 0) {\n const aspect = r.width / r.height\n if (dw !== 0) height = width / aspect\n else width = height * aspect\n // Neither side below MIN_SIZE, still in proportion.\n const grow = Math.max(MIN_SIZE / width, MIN_SIZE / height, 1)\n width *= grow\n height *= grow\n }\n const top = r.y + r.height\n return { x: r.x, y: top - height, width, height }\n}\n\n/**\n * True for highlight, underline, strikeout and squiggly: marks on text, which a drag passes\n * through to text selection and a click selects.\n */\nexport function isTextMarkup(a: Pick<Annotation, 'type'>): a is TextMarkupAnnotation {\n return (\n a.type === 'highlight' ||\n a.type === 'underline' ||\n a.type === 'strikeout' ||\n a.type === 'squiggly'\n )\n}\n\n/**\n * True for the point-based shapes a corner handle resizes by scaling their points: polylines,\n * polygons and ink. With `hasRectGeometry`, the annotations that get corner handles.\n */\nexport function scalesPoints(a: Annotation): boolean {\n return a.type === 'polyline' || a.type === 'polygon' || a.type === 'ink'\n}\n\n/** True when a corner handle resizes `a`: rect-shaped types and point-based shapes. */\nexport function hasCornerHandles(a: Annotation): boolean {\n return hasRectGeometry(a) || scalesPoints(a)\n}\n\n/**\n * The geometry patch that maps `a` from the box `from` onto the box `to`, both in user space:\n * `rect`, every point field (quads, ink paths, vertices, line ends, callout) and a free text's\n * `fringe` scale with the boxes. Stroke widths and font sizes stay as they are.\n */\nexport function scaled(a: Annotation, from: Rect, to: Rect): Partial<Annotation> {\n const sx = from.width === 0 ? 1 : to.width / from.width\n const sy = from.height === 0 ? 1 : to.height / from.height\n const map = (p: Point): Point => ({\n x: to.x + (p.x - from.x) * sx,\n y: to.y + (p.y - from.y) * sy,\n })\n const sameBox = (r: Rect): boolean =>\n r.x === from.x && r.y === from.y && r.width === from.width && r.height === from.height\n const patch: Record<string, unknown> = {\n // The common case, a rect that is the box, maps exactly rather than through the scale.\n rect: sameBox(a.rect)\n ? { ...to }\n : {\n ...map(a.rect),\n width: a.rect.width * sx,\n height: a.rect.height * sy,\n },\n }\n if ('quads' in a && a.quads)\n patch.quads = a.quads.map((q) => ({\n p1: map(q.p1),\n p2: map(q.p2),\n p3: map(q.p3),\n p4: map(q.p4),\n }))\n if ('callout' in a && a.callout) patch.callout = a.callout.map(map)\n // The text box inside a free text's rect scales with it.\n if (a.type === 'freetext' && a.fringe)\n patch.fringe = {\n left: a.fringe.left * sx,\n top: a.fringe.top * sy,\n right: a.fringe.right * sx,\n bottom: a.fringe.bottom * sy,\n }\n switch (a.type) {\n case 'line':\n patch.start = map(a.start)\n patch.end = map(a.end)\n break\n case 'polyline':\n case 'polygon':\n patch.vertices = a.vertices.map(map)\n break\n case 'ink':\n patch.inklist = a.inklist.map((path) => path.map(map))\n break\n default:\n }\n return patch\n}\n\n/**\n * The patch that moves one end of a line to `to` and refits `rect` to the new ends, padded by\n * half the stroke width on every side.\n */\nexport function movedEndpoint(\n a: LineAnnotation,\n which: 'start' | 'end',\n to: Point\n): Partial<LineAnnotation> {\n const start = which === 'start' ? to : a.start\n const end = which === 'end' ? to : a.end\n const pad = a.width / 2\n const x = Math.min(start.x, end.x)\n const y = Math.min(start.y, end.y)\n return {\n [which]: { ...to },\n rect: {\n x: x - pad,\n y: y - pad,\n width: Math.abs(end.x - start.x) + pad * 2,\n height: Math.abs(end.y - start.y) + pad * 2,\n },\n }\n}\n\n/**\n * True for annotations whose resize keeps their aspect ratio without `Shift`: stamps, loupes,\n * masks and signatures (ink with subject `Signature`).\n */\nexport function keepsAspect(a: Annotation): boolean {\n if (a.type === 'stamp' || a.type === 'loupe' || a.type === 'mask') return true\n return a.type === 'ink' && a.subject === 'Signature'\n}\n\n/**\n * True for a speech bubble: a standard free-text callout (`intent: 'FreeTextCallout'`, `rect`,\n * `fringe`, `callout`) with Inkbar's `cornerRadius`. Inkbar draws it as one rounded outline with\n * a wedge from where `callout`'s last point meets the box to the tip, `callout[0]`.\n */\nexport function isBubble(\n a: Annotation\n): a is FreeTextAnnotation & { callout: [Point, Point, ...Point[]] } {\n return (\n a.type === 'freetext' &&\n a.intent === 'FreeTextCallout' &&\n a.cornerRadius !== undefined &&\n a.callout !== undefined &&\n a.callout.length >= 2\n )\n}\n\n/** True for a free text with a callout to edit: a speech bubble or a standard callout. */\nexport function hasCallout(\n a: Annotation\n): a is FreeTextAnnotation & { callout: [Point, Point, ...Point[]] } {\n return isBubble(a) || isStandardCallout(a)\n}\n\n/**\n * The patch that puts a free text's text box at `box`, refitting `rect` and `fringe` around\n * it. A callout's points become `callout` (its own by default) and `rect` holds them too; any\n * other box keeps its fringe, or has `rect` equal to the box without one.\n */\nexport function withBox(\n a: FreeTextAnnotation,\n box: Rect,\n callout: readonly Point[] | undefined = a.callout\n): Partial<FreeTextAnnotation> {\n if (hasCallout(a) && callout)\n return {\n ...withCalloutBounds(box, callout, calloutStroke(a).width, a.head),\n callout: callout.map((p) => ({ ...p })),\n }\n const f = a.fringe\n if (!f) return { rect: { ...box } }\n return {\n rect: {\n x: box.x - f.left,\n y: box.y - f.bottom,\n width: box.width + f.left + f.right,\n height: box.height + f.bottom + f.top,\n },\n }\n}\n\n/** Half a speech bubble's wedge where it leaves the box, points. */\nexport const WEDGE_HALF = 8\n\ntype Edge = 'left' | 'right' | 'bottom' | 'top'\nconst EDGES: readonly Edge[] = ['left', 'right', 'bottom', 'top']\n\n/**\n * The edge of `box` nearest `p`. `bubblePath` (dom/overlay-render.ts) picks the wedge's edge by\n * the same rule in CSS px; change both together.\n */\nfunction nearestEdge(p: Point, box: Rect): Edge {\n const gaps: Record<Edge, number> = {\n left: Math.abs(p.x - box.x),\n right: Math.abs(p.x - (box.x + box.width)),\n bottom: Math.abs(p.y - box.y),\n top: Math.abs(p.y - (box.y + box.height)),\n }\n return EDGES.reduce((best, e) => (gaps[e] < gaps[best] ? e : best))\n}\n\n/** The side of `box` that `p` lies furthest beyond. */\nfunction edgeBeyond(p: Point, box: Rect): Edge {\n const beyond: Record<Edge, number> = {\n left: box.x - p.x,\n right: p.x - (box.x + box.width),\n bottom: box.y - p.y,\n top: p.y - (box.y + box.height),\n }\n return EDGES.reduce((best, e) => (beyond[e] > beyond[best] ? e : best))\n}\n\n/**\n * `p` carried from the box `from` onto the box `to`: it keeps its fraction along the box edge\n * nearest it and its distance off that edge.\n */\nexport function onMovedEdge(p: Point, from: Rect, to: Rect): Point {\n const edge = nearestEdge(p, from)\n const along = (\n v: number,\n start: number,\n size: number,\n next: number,\n nextSize: number\n ) => next + (size === 0 ? nextSize / 2 : ((v - start) / size) * nextSize)\n if (edge === 'left' || edge === 'right') {\n const x = edge === 'left' ? from.x : from.x + from.width\n const nx = edge === 'left' ? to.x : to.x + to.width\n return { x: nx + p.x - x, y: along(p.y, from.y, from.height, to.y, to.height) }\n }\n const y = edge === 'bottom' ? from.y : from.y + from.height\n const ny = edge === 'bottom' ? to.y : to.y + to.height\n return { x: along(p.x, from.x, from.width, to.x, to.width), y: ny + p.y - y }\n}\n\n/**\n * `p` placed on `box`'s `edge` at its own position along it, kept `margin` points clear of the\n * corners (at most half the edge).\n */\nfunction ontoEdge(p: Point, box: Rect, edge: Edge, margin: number): Point {\n const clamp = (v: number, start: number, size: number) => {\n const m = Math.min(margin, size / 2)\n return Math.min(Math.max(v, start + m), start + size - m)\n }\n if (edge === 'left' || edge === 'right')\n return {\n x: edge === 'left' ? box.x : box.x + box.width,\n y: clamp(p.y, box.y, box.height),\n }\n return {\n x: clamp(p.x, box.x, box.width),\n y: edge === 'bottom' ? box.y : box.y + box.height,\n }\n}\n\n/**\n * The patch that resizes a free text's text box to `to`. A callout's tip and bend stay where\n * they are and its last point moves with the box edge it sits on (`onMovedEdge`).\n */\nexport function resizedBox(a: FreeTextAnnotation, to: Rect): Partial<FreeTextAnnotation> {\n if (!hasCallout(a)) return withBox(a, to)\n const from = freeTextBox(a)\n const last = a.callout.length - 1\n return withBox(\n a,\n to,\n a.callout.map((p, i) => (i === last ? onMovedEdge(p, from, to) : p))\n )\n}\n\n/**\n * The patch that moves a callout's tip to `to`, leaving its text box where it is. A callout\n * without a bend (every bubble) moves its edge point to the side the tip now lies furthest\n * beyond, at its own position along that side and clear of the corners, so the line or wedge\n * never crosses the box; on the same side it stays put. A bend and its edge point stay.\n */\nexport function movedTip(\n a: FreeTextAnnotation & { callout: readonly Point[] },\n to: Point\n): Partial<FreeTextAnnotation> {\n const box = freeTextBox(a)\n if (a.callout.length !== 2) return withBox(a, box, [to, ...a.callout.slice(1)])\n const edge = a.callout[1]!\n const side = edgeBeyond(to, box)\n const margin = (a.cornerRadius ?? 0) + WEDGE_HALF\n return withBox(a, box, [\n to,\n nearestEdge(edge, box) === side ? edge : ontoEdge(edge, box, side, margin),\n ])\n}\n","// Maps the style controls' names (`border`, `fill`, `width`…) to each annotation type's\n// fields and back. Pure: no store, no DOM. A prop maps only where the type has the field, so a\n// patch for a mixed selection lands on each annotation as far as it can.\nimport type { StyleGroup, StyleProps } from './tool-style'\nimport type { Annotation, AnnotationPatch, AnnotationType } from './types'\n\ntype StyleKey = keyof StyleProps\n\n/** For each type, the control-level props it supports and the field each writes. */\nconst FIELDS: Readonly<\n Record<AnnotationType, Readonly<Partial<Record<StyleKey, string>>>>\n> = {\n square: {\n border: 'color',\n fill: 'interiorColor',\n opacity: 'opacity',\n width: 'width',\n dashes: 'dashes',\n },\n circle: {\n border: 'color',\n fill: 'interiorColor',\n opacity: 'opacity',\n width: 'width',\n dashes: 'dashes',\n },\n polygon: {\n border: 'color',\n fill: 'interiorColor',\n opacity: 'opacity',\n width: 'width',\n dashes: 'dashes',\n },\n polyline: {\n border: 'color',\n opacity: 'opacity',\n width: 'width',\n dashes: 'dashes',\n head: 'head',\n tail: 'tail',\n },\n line: {\n border: 'color',\n opacity: 'opacity',\n width: 'width',\n dashes: 'dashes',\n head: 'head',\n tail: 'tail',\n },\n // Ink is drawn solid, so it has no dashes.\n ink: { border: 'color', opacity: 'opacity', width: 'width' },\n highlight: { border: 'color', opacity: 'opacity' },\n underline: { border: 'color', opacity: 'opacity' },\n strikeout: { border: 'color', opacity: 'opacity' },\n squiggly: { border: 'color', opacity: 'opacity' },\n redact: { border: 'color', opacity: 'opacity' },\n // XFDF: a box's `color` is its fill; the text style lives in `defaultStyle`.\n freetext: {\n border: 'borderColor',\n fill: 'color',\n textColor: 'defaultStyle.color',\n opacity: 'opacity',\n width: 'width',\n dashes: 'dashes',\n fontFamily: 'defaultStyle.fontFamily',\n fontSize: 'defaultStyle.fontSize',\n fontWeight: 'defaultStyle.fontWeight',\n fontStyle: 'defaultStyle.fontStyle',\n textDecoration: 'defaultStyle.textDecoration',\n textAlign: 'defaultStyle.textAlign',\n },\n // The rim is the outline; the inside is the magnified page, so there is no fill, and the\n // rim is drawn solid.\n loupe: { border: 'color', opacity: 'opacity', width: 'width' },\n // A mask dims the page outside a shape: nothing for the style controls to change.\n mask: {},\n text: {},\n // An image, signatures among them: the style controls have nothing to change on it.\n stamp: {},\n}\n\nconst GROUPS: Readonly<Record<AnnotationType, StyleGroup | undefined>> = {\n square: 'shape',\n circle: 'shape',\n line: 'shape',\n polyline: 'shape',\n polygon: 'shape',\n loupe: 'shape',\n ink: 'ink',\n freetext: 'text',\n highlight: 'markup',\n underline: 'markup',\n strikeout: 'markup',\n squiggly: 'markup',\n redact: 'redact',\n text: undefined,\n stamp: undefined,\n mask: undefined,\n}\n\nconst SUPPORTED = new Map<AnnotationType, ReadonlySet<StyleKey>>(\n (Object.keys(FIELDS) as AnnotationType[]).map((type) => [\n type,\n new Set(Object.keys(FIELDS[type]) as StyleKey[]),\n ])\n)\n\n/**\n * The props a speech bubble (`intent: 'FreeTextCallout'`) takes from the `shape` group: its\n * outline, fill and opacity, as the shape tool creates it. Its text props stay in `text`.\n */\nconst BUBBLE_SHAPE_PROPS: ReadonlySet<StyleKey> = new Set([\n 'border',\n 'fill',\n 'opacity',\n 'width',\n 'dashes',\n])\n\n/**\n * The style group an annotation's type belongs to; notes belong to none. With `key`, the group\n * that owns that prop on `a`: a speech bubble's outline and fill are `shape`'s, its text `text`'s.\n */\nexport function styleGroupOf(\n a: Pick<Annotation, 'type'> & { intent?: string | undefined },\n key?: StyleKey\n): StyleGroup | undefined {\n if (\n key !== undefined &&\n a.type === 'freetext' &&\n a.intent === 'FreeTextCallout' &&\n BUBBLE_SHAPE_PROPS.has(key)\n )\n return 'shape'\n return GROUPS[a.type]\n}\n\n/** Every group that owns some prop on `a`: two for a speech bubble, else at most one. */\nexport function styleGroupsOf(\n a: Pick<Annotation, 'type'> & { intent?: string | undefined }\n): StyleGroup[] {\n const out = new Set<StyleGroup>()\n const own = GROUPS[a.type]\n if (own) out.add(own)\n for (const key of supportedProps(a.type)) {\n const g = styleGroupOf(a, key)\n if (g) out.add(g)\n }\n return [...out]\n}\n\n/** The types in `group`, from the same table `styleGroupOf` reads. */\nexport function typesInGroup(group: StyleGroup): AnnotationType[] {\n return (Object.keys(GROUPS) as AnnotationType[]).filter((t) => GROUPS[t] === group)\n}\n\n/** The style group a type belongs to. */\nexport function styleGroupOfType(type: AnnotationType): StyleGroup | undefined {\n return GROUPS[type]\n}\n\n/** The control-level props `type` supports. */\nexport function supportedProps(type: AnnotationType): ReadonlySet<StyleKey> {\n return SUPPORTED.get(type) ?? new Set()\n}\n\n/**\n * The control values a field leaves out: `normal` weight and style, no decoration. The field\n * is absent rather than holding them, as XFDF writes only what differs.\n */\nconst UNSET: Readonly<Partial<Record<StyleKey, unknown>>> = {\n fontWeight: 'normal',\n fontStyle: 'normal',\n textDecoration: 'none',\n}\n\n/** The prefix of a field nested in `defaultStyle` (free text). */\nconst STYLE = 'defaultStyle.'\n\n/**\n * The field patch `patch` means on `type`. Props the type lacks are dropped. A `null` fill\n * becomes `interiorColor: undefined` (`color` on free text), which removes the fill when the\n * store applies it; so does `normal` weight or style and no decoration. Free-text text props go\n * into a partial `defaultStyle`, which the store merges into the current one.\n */\nexport function toFields(type: AnnotationType, patch: StyleProps): AnnotationPatch {\n const fields = FIELDS[type]\n const out: Record<string, unknown> = {}\n for (const key of Object.keys(patch) as StyleKey[]) {\n const field = fields[key]\n if (field === undefined) continue\n const raw = patch[key]\n const value = raw === null || raw === UNSET[key] ? undefined : raw\n if (field.startsWith(STYLE)) {\n const style = (out.defaultStyle ??= {}) as Record<string, unknown>\n style[field.slice(STYLE.length)] = value\n } else {\n out[field] = value\n }\n }\n return out\n}\n\n/** The control-level props an annotation shows, for the props its type supports. */\nexport function fromAnnotation(a: Annotation): StyleProps {\n const fields = FIELDS[a.type]\n const record = a as unknown as Record<string, unknown>\n const style = (record.defaultStyle ?? {}) as Record<string, unknown>\n const out: Record<string, unknown> = {}\n for (const key of Object.keys(fields) as StyleKey[]) {\n const field = fields[key] as string\n const value = field.startsWith(STYLE)\n ? style[field.slice(STYLE.length)]\n : record[field]\n if (value !== undefined) out[key] = value\n else if (key === 'fill' || key === 'dashes') out[key] = null\n else if (key === 'head' || key === 'tail') out[key] = 'None'\n else if (UNSET[key] !== undefined) out[key] = UNSET[key]\n }\n return out\n}\n","// The current style per style group, shared by the tools that create into a group and the\n// style controls. Within a group the style is shared: recolouring a line also colours the next\n// rectangle. Groups start empty, so until a control sets a prop each type keeps its theme\n// default (the store's `completeInput` fills it).\n//\n// `set` writes through the store, so in controlled mode every change is proposed to the host's\n// `onChange` and nothing is applied before the host applies it.\nimport { writable, type Readable, type Writable } from '../readable'\n\nimport { freeTextBox } from './callout'\nimport { hasCallout, withBox } from './edit'\nimport {\n fromAnnotation,\n styleGroupOf,\n styleGroupsOf,\n supportedProps,\n toFields,\n typesInGroup,\n} from './style-map'\n\nimport type { AnnotationStore } from './store'\nimport type {\n Annotation,\n AnnotationInput,\n AnnotationPatch,\n FreeTextAnnotation,\n LineEnding,\n} from './types'\n\nexport type StyleGroup = 'shape' | 'ink' | 'text' | 'markup' | 'redact'\n\nexport const STYLE_GROUPS: readonly StyleGroup[] = [\n 'shape',\n 'ink',\n 'text',\n 'markup',\n 'redact',\n]\n\n/** Style as the controls name it; `style-map` turns it into each type's fields. */\nexport interface StyleProps {\n /** #RRGGBB */\n border?: string\n /** `null` means no fill. */\n fill?: string | null\n textColor?: string\n opacity?: number\n width?: number\n /** `null` means solid. */\n dashes?: number[] | null\n head?: LineEnding\n tail?: LineEnding\n fontFamily?: string\n fontSize?: number\n fontWeight?: 'normal' | 'bold'\n fontStyle?: 'normal' | 'italic'\n textDecoration?: 'none' | 'underline'\n textAlign?: 'left' | 'center' | 'right' | 'justify'\n}\n\nexport type StyleKey = keyof StyleProps\n\n/** What the controls show: one value per prop, or `'mixed'` when a selection disagrees. */\nexport type CurrentStyle = { [K in StyleKey]?: StyleProps[K] | 'mixed' }\n\nexport interface ToolStyle {\n get(group: StyleGroup): Readonly<StyleProps>\n readable(group: StyleGroup): Readable<Readonly<StyleProps>>\n /**\n * Values the controls show. Under a select tool, the selection's. Under a creation tool, the\n * selection's when it is non-empty and wholly in the tool's group, else the group's own: a\n * leftover selection from another tool does not take over the controls. `'mixed'` per prop\n * when selected values differ.\n */\n readonly current: Readable<CurrentStyle>\n /**\n * Which props the active tool or the selection supports; controls disable the rest. Under a\n * creation tool, the group's props, plus the selection's when it is wholly in the group.\n */\n readonly supported: Readable<ReadonlySet<StyleKey>>\n /**\n * Updates the active tool's group, or under a select tool (no active group) the group that\n * owns each prop on each selected annotation (a speech bubble's outline is `shape`'s, its\n * text `text`'s). With `apply` it also updates every selected, unlocked annotation that has\n * the props, in one history step. `apply` defaults to true under a select tool, and to\n * whether the selection is wholly in the group otherwise. `group` names the group explicitly.\n */\n set(patch: StyleProps, opts?: { group?: StyleGroup; apply?: boolean }): void\n /** Fills an AnnotationInput's unset style fields from the group (input wins). */\n resolve<T extends AnnotationInput>(group: StyleGroup, input: T): T\n /**\n * The style as a control for one group sees it, whatever the active tool: the selection's\n * when every selected annotation is in `group`, else the group's own. Same identity per group.\n */\n scoped(group: StyleGroup): ScopedToolStyle\n}\n\n/** A view of the tool style for one group, as `ToolStyle.scoped` gives it. */\nexport interface ScopedToolStyle {\n readonly group: StyleGroup\n readonly current: Readable<CurrentStyle>\n readonly supported: Readable<ReadonlySet<StyleKey>>\n /** Updates the group, and the selection too when every selected annotation is in it. */\n set(patch: StyleProps): void\n}\n\nexport interface ToolStyleDeps {\n store: AnnotationStore\n history: { batch(fn: () => void): void }\n /** The active tool's style group; `undefined` for select tools. */\n activeGroup: () => StyleGroup | undefined\n /** Fires when the active tool changes, so `current` and `supported` follow it. */\n active?: Readable<unknown>\n}\n\n/** Every prop some type in `group` supports. */\nfunction groupProps(group: StyleGroup): ReadonlySet<StyleKey> {\n const out = new Set<StyleKey>()\n for (const type of typesInGroup(group))\n for (const key of supportedProps(type)) out.add(key)\n return out\n}\n\nfunction sameValue(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true\n if (Array.isArray(a) && Array.isArray(b))\n return a.length === b.length && a.every((v, i) => Object.is(v, b[i]))\n return false\n}\n\nfunction sameRecord(a: Record<string, unknown>, b: Record<string, unknown>): boolean {\n const ka = Object.keys(a)\n if (ka.length !== Object.keys(b).length) return false\n return ka.every((k) => k in b && sameValue(a[k], b[k]))\n}\n\nfunction sameSet<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): boolean {\n return a.size === b.size && [...a].every((v) => b.has(v))\n}\n\n/**\n * A readable recomputed from `fn` whenever any source fires, subscribed to its sources only\n * while it has subscribers. Equal results (by `eq`) are not re-emitted and keep their identity.\n */\nfunction computed<T>(\n sources: readonly Readable<unknown>[],\n fn: () => T,\n eq: (a: T, b: T) => boolean\n): Readable<T> {\n const subs = new Set<(v: T) => void>()\n let cached: { value: T } | undefined\n let stops: (() => void)[] | undefined\n /** Recomputes, keeping the previous value's identity when equal. True when it changed. */\n const recompute = (): boolean => {\n const next = fn()\n if (cached && eq(next, cached.value)) return false\n cached = { value: next }\n return true\n }\n const refresh = (): void => {\n if (!recompute() || !cached) return\n const value = cached.value\n for (const sub of [...subs]) sub(value)\n }\n return {\n // Stable identity for equal values even unobserved: React's useSyncExternalStore reads\n // the snapshot before it subscribes and loops on a fresh object.\n get: () => {\n if (!stops) recompute()\n return (cached as { value: T }).value\n },\n subscribe(sub) {\n if (!stops) {\n recompute()\n stops = sources.map((s) => s.subscribe(refresh))\n }\n subs.add(sub)\n return () => {\n if (!subs.delete(sub) || subs.size > 0) return\n for (const stop of stops ?? []) stop()\n stops = undefined\n }\n },\n }\n}\n\nexport function createToolStyle(deps: ToolStyleDeps): ToolStyle {\n const { store, history, activeGroup } = deps\n const groups = new Map<StyleGroup, Writable<Readonly<StyleProps>>>(\n STYLE_GROUPS.map((g) => [g, writable<Readonly<StyleProps>>({})])\n )\n const groupStore = (g: StyleGroup): Writable<Readonly<StyleProps>> => {\n const w = groups.get(g)\n if (!w) throw new RangeError(`Unknown style group ${String(g)}`)\n return w\n }\n\n /** The selected annotations, including changes proposed to a controlled host. */\n const selected = (): Annotation[] =>\n store.selection\n .get()\n .map((id) => store._getProposed(id) ?? store.get(id))\n .filter((a): a is Annotation => a !== undefined)\n\n const sources: Readable<unknown>[] = [\n store.list,\n store.selection,\n ...groups.values(),\n ...(deps.active ? [deps.active] : []),\n ]\n\n /** One value per prop over `items`, `'mixed'` where they differ. */\n const styleOf = (items: readonly Annotation[]): CurrentStyle => {\n const out: Record<string, unknown> = {}\n for (const a of items) {\n const props = fromAnnotation(a) as Record<string, unknown>\n for (const [key, value] of Object.entries(props)) {\n if (!(key in out)) out[key] = value\n else if (out[key] !== 'mixed' && !sameValue(out[key], value)) out[key] = 'mixed'\n }\n }\n return out\n }\n\n const propsOf = (items: readonly Annotation[]): ReadonlySet<StyleKey> => {\n const out = new Set<StyleKey>()\n for (const a of items) for (const key of supportedProps(a.type)) out.add(key)\n return out\n }\n\n /** The selection, when it is non-empty and wholly in `group`. */\n const selectedIn = (group: StyleGroup): Annotation[] | null => {\n const items = selected()\n return items.length > 0 && items.every((a) => styleGroupsOf(a).includes(group))\n ? items\n : null\n }\n\n const current = computed<CurrentStyle>(\n sources,\n () => {\n const g = activeGroup()\n if (!g) return styleOf(selected())\n const items = selectedIn(g)\n return items ? styleOf(items) : { ...groupStore(g).get() }\n },\n (a, b) => sameRecord(a, b)\n )\n\n const supported = computed<ReadonlySet<StyleKey>>(\n sources,\n () => {\n const g = activeGroup()\n if (!g) return propsOf(selected())\n const items = selectedIn(g)\n return items ? new Set([...groupProps(g), ...propsOf(items)]) : groupProps(g)\n },\n sameSet\n )\n\n const scopes = new Map<StyleGroup, ScopedToolStyle>()\n function scoped(group: StyleGroup): ScopedToolStyle {\n const known = scopes.get(group)\n if (known) return known\n groupStore(group)\n const scope: ScopedToolStyle = {\n group,\n current: computed<CurrentStyle>(\n sources,\n () => {\n const items = selectedIn(group)\n return items ? styleOf(items) : { ...groupStore(group).get() }\n },\n (a, b) => sameRecord(a, b)\n ),\n supported: computed<ReadonlySet<StyleKey>>(\n sources,\n () => {\n const items = selectedIn(group)\n return items ? propsOf(items) : groupProps(group)\n },\n sameSet\n ),\n set: (patch) => set(patch, { group, apply: selectedIn(group) !== null }),\n }\n scopes.set(group, scope)\n return scope\n }\n\n function set(\n patch: StyleProps,\n opts: { group?: StyleGroup; apply?: boolean } = {}\n ): void {\n const items = selected()\n const active = opts.group ?? activeGroup()\n const keys = (Object.keys(patch) as StyleKey[]).filter((k) => patch[k] !== undefined)\n // The keys each group takes: all of them for the active group, else each prop goes to the\n // group that owns it on each selected annotation.\n const targets = new Map<StyleGroup, Set<StyleKey>>()\n if (active) targets.set(active, new Set(keys))\n else\n for (const a of items)\n for (const key of keys) {\n if (!supportedProps(a.type).has(key)) continue\n const g = styleGroupOf(a, key)\n if (!g) continue\n const own = targets.get(g) ?? new Set<StyleKey>()\n own.add(key)\n targets.set(g, own)\n }\n for (const [g, own] of targets) {\n const allowed = groupProps(g)\n const next: Record<string, unknown> = { ...groupStore(g).get() }\n let changed = false\n for (const key of own) {\n if (!allowed.has(key)) continue\n next[key] = patch[key]\n changed = true\n }\n if (changed) groupStore(g).set(next)\n }\n if (!(opts.apply ?? (active === undefined || selectedIn(active) !== null))) return\n const edits = items\n .filter((a) => !a.locked)\n .map((a) => ({ id: a.id, fields: refit(a, toFields(a.type, patch)) }))\n .filter((e) => Object.keys(e.fields).length > 0)\n if (edits.length === 0) return\n history.batch(() => {\n for (const e of edits) store.update(e.id, e.fields)\n })\n }\n\n /**\n * `fields` with a callout's `rect` and `fringe` refit when they change its border width, so\n * the bounds keep covering the leader, its ending and the outline.\n */\n function refit(a: Annotation, fields: AnnotationPatch): AnnotationPatch {\n if (!('width' in fields) || !hasCallout(a)) return fields\n const next = { ...a, ...fields } as FreeTextAnnotation\n return { ...fields, ...withBox(next, freeTextBox(a)) } as AnnotationPatch\n }\n\n /** `value`'s keys that hold something. */\n const defined = (value: unknown): Record<string, unknown> =>\n Object.fromEntries(\n Object.entries((value ?? {}) as Record<string, unknown>).filter(\n ([, v]) => v !== undefined\n )\n )\n\n function resolve<T extends AnnotationInput>(group: StyleGroup, input: T): T {\n const fields = toFields(input.type, groupStore(group).get()) as Record<\n string,\n unknown\n >\n const out: Record<string, unknown> = { ...input }\n for (const [key, value] of Object.entries(fields)) {\n if (key === 'defaultStyle') {\n // Nested text style: the group's keys fill those the input leaves unset (or undefined).\n out[key] = { ...defined(value), ...defined(out[key]) }\n } else if (value !== undefined && out[key] === undefined) out[key] = value\n }\n return out as T\n }\n\n return {\n get: (g) => groupStore(g).get(),\n readable: (g) => {\n const w = groupStore(g)\n return { get: () => w.get(), subscribe: (fn) => w.subscribe(fn) }\n },\n current,\n supported,\n set,\n resolve,\n scoped,\n }\n}\n","import type { AnnotationStore } from './store'\nimport type { Annotation } from './types'\n\n/**\n * Keeps a suggested redaction as the user's own: `origin` becomes `'user'` and the colour\n * goes from the confidence colour to the store's default redaction colour, so an accepted\n * mark looks like any other. The suggestion details stay on it. Returns the updated\n * annotation, or undefined (changing nothing) when `id` is not a suggested redaction or is\n * locked.\n */\nexport function acceptSuggestion(\n store: AnnotationStore,\n id: string\n): Annotation | undefined {\n // Pending-aware: a controlled host may not have echoed the suggestion back yet.\n const a = store._getProposed(id)\n if (a?.type !== 'redact' || a.origin !== 'suggested' || a.locked) return undefined\n return store.update(id, { origin: 'user', color: store.defaults.color('redact') })\n}\n","import { isTextMarkup } from './edit'\n\nimport type { Annotation, NoteAnnotation, TextMarkupAnnotation } from './types'\n\n/** What a thread can hang from: a note, or text markup whose `contents` is its comment. */\nexport type ThreadRoot = NoteAnnotation | TextMarkupAnnotation\n\nexport function isThreadRoot(a: Annotation): a is ThreadRoot {\n return a.type === 'text' || isTextMarkup(a)\n}\n\n/**\n * True for a reply: an annotation whose `inReplyTo` names a thread root (a note or text markup)\n * in `list`. Replies show in the thread popover only, never on the page.\n */\nexport function isReply(a: Annotation, list: readonly Annotation[]): boolean {\n if (a.inReplyTo === undefined) return false\n const parent = list.find((x) => x.id === a.inReplyTo)\n return parent !== undefined && isThreadRoot(parent)\n}\n\n/** `list` less its replies (see `isReply`), in the same order. */\nexport function withoutReplies(list: readonly Annotation[]): Annotation[] {\n const roots = new Set(list.filter(isThreadRoot).map((a) => a.id))\n return list.filter((a) => a.inReplyTo === undefined || !roots.has(a.inReplyTo))\n}\n\n/** Direct replies to `id`, in creation order. */\nexport function repliesTo(list: readonly Annotation[], id: string): Annotation[] {\n return list\n .filter((a) => a.inReplyTo === id)\n .sort((a, b) => a.createdAt.localeCompare(b.createdAt))\n}\n\n/**\n * The top of a thread: follows `inReplyTo` up through notes, stopping at text markup (which\n * roots a thread of its own), a missing parent, a parent that cannot root a thread, or a\n * cycle. Null when `start` is neither a note nor text markup.\n */\nexport function threadRoot(\n list: readonly Annotation[],\n start: Annotation\n): ThreadRoot | null {\n if (!isThreadRoot(start)) return null\n const seen = new Set([start.id])\n let current: ThreadRoot = start\n while (current.type === 'text' && current.inReplyTo) {\n const id: string = current.inReplyTo\n const parent = list.find((a) => a.id === id)\n if (!parent || !isThreadRoot(parent) || seen.has(parent.id)) break\n seen.add(parent.id)\n current = parent\n }\n return current\n}\n\n/** The root, then every reply below it, depth first, each level in creation order. */\nexport function threadOf(list: readonly Annotation[], root: ThreadRoot): Annotation[] {\n const out: Annotation[] = [root]\n const seen = new Set([root.id])\n const visit = (id: string): void => {\n for (const r of repliesTo(list, id)) {\n if (seen.has(r.id)) continue\n seen.add(r.id)\n out.push(r)\n visit(r.id)\n }\n }\n visit(root.id)\n return out\n}\n\n/**\n * An unlocked root note with no text and no replies: nothing a reader would miss. Always\n * false for text markup, which is worth keeping without a comment.\n */\nexport function isAbandonedNote(a: Annotation, list: readonly Annotation[]): boolean {\n if (a.type !== 'text' || a.locked || a.inReplyTo || a.contents?.trim()) return false\n return repliesTo(list, a.id).length === 0\n}\n","// Pure geometry for the shape tool: vertices for stars and polygons, Shift constraints and the\n// annotation each kind creates. Everything is PDF user space, points, origin bottom-left.\nimport { withCalloutBounds } from './callout'\n\nimport type { Point, Rect } from '../geometry'\nimport type { PageRotation } from '../pages'\nimport type { AnnotationInput } from './types'\n\n/** Every kind the shape menu can offer. Kinds without a creator yet are not in `SHAPE_KINDS`. */\nexport type ShapeKind =\n | 'line'\n | 'arrow'\n | 'rectangle'\n | 'roundedRectangle'\n | 'ellipse'\n | 'bubble'\n | 'star'\n | 'polygon'\n | 'loupe'\n | 'mask'\n | 'ovalMask'\n\nexport interface ShapeOptions {\n kind: ShapeKind\n /** Points of a star. */\n points: number\n /** Sides of a polygon. */\n sides: number\n}\n\n/** The kinds the shape menu offers today, in menu order. Later kinds extend this. */\nexport const SHAPE_KINDS: readonly ShapeKind[] = [\n 'line',\n 'arrow',\n 'rectangle',\n 'roundedRectangle',\n 'ellipse',\n 'bubble',\n 'star',\n 'polygon',\n 'loupe',\n 'mask',\n 'ovalMask',\n]\n\nexport const DEFAULT_SHAPE_OPTIONS: Readonly<ShapeOptions> = {\n kind: 'rectangle',\n points: 5,\n sides: 6,\n}\n\nconst POINTER_ONLY: ReadonlySet<ShapeKind> = new Set(['loupe', 'mask', 'ovalMask'])\n\n/**\n * True for kinds only a pointer creates: the loupe and the mask. `Enter` with the shape tool\n * does not place them.\n */\nexport function isPointerOnlyKind(kind: ShapeKind): boolean {\n return POINTER_ONLY.has(kind)\n}\n\n/** Magnification of a new loupe. */\nexport const DEFAULT_LOUPE_MAGNIFICATION = 2\n\n/** How strongly a new mask dims the page. */\nexport const DEFAULT_MASK_DIM = 0.5\n\n/** Side of the shape a click or Enter places, in points. */\nexport const DEFAULT_SHAPE_SIZE = 72\n/** Corner radius of a new rounded rectangle, in points. */\nexport const DEFAULT_CORNER_RADIUS = 8\n\n/** How far below and left of its anchor a new speech bubble's tail tip sits, in points. */\nconst BUBBLE_TAIL = 24\n/** A new speech bubble's outline width, in points, before the style group's applies. */\nconst BUBBLE_WIDTH = 1\n\nconst clean = (n: number): number => n + 0\n\n/** The box between two corners. */\nfunction rectOf(a: Point, b: Point): Rect {\n return {\n x: Math.min(a.x, b.x),\n y: Math.min(a.y, b.y),\n width: Math.abs(b.x - a.x),\n height: Math.abs(b.y - a.y),\n }\n}\n\n/** Vertices round the ellipse inscribed in `rect`, the first at the top centre, clockwise on the page. */\nfunction ring(rect: Rect, count: number, radius: (index: number) => number): Point[] {\n const cx = rect.x + rect.width / 2\n const cy = rect.y + rect.height / 2\n return Array.from({ length: count }, (_, i) => {\n const angle = (i * 2 * Math.PI) / count\n const r = radius(i)\n return {\n x: clean(cx + (rect.width / 2) * r * Math.sin(angle)),\n y: clean(cy + (rect.height / 2) * r * Math.cos(angle)),\n }\n })\n}\n\n/** A star's `2 * points` vertices, outer and inner alternating, the first at the top centre. */\nexport function starVertices(rect: Rect, points: number, innerRatio = 0.5): Point[] {\n const n = Math.max(2, Math.round(points))\n return ring(rect, n * 2, (i) => (i % 2 === 0 ? 1 : innerRatio))\n}\n\n/** A regular polygon's vertices on the inscribed ellipse, the first at the top centre. */\nexport function polygonVertices(rect: Rect, sides: number): Point[] {\n return ring(rect, Math.max(3, Math.round(sides)), () => 1)\n}\n\nconst LINE_KINDS: ReadonlySet<ShapeKind> = new Set(['line', 'arrow'])\n\n/** True for kinds drawn between two endpoints rather than inside a box. */\nexport function isLineKind(kind: ShapeKind): boolean {\n return LINE_KINDS.has(kind)\n}\n\nconst H = Math.SQRT1_2\n/** Unit steps every 45 degrees, counter-clockwise from +x (y up). */\nconst EIGHT_WAYS: readonly Point[] = [\n { x: 1, y: 0 },\n { x: H, y: H },\n { x: 0, y: 1 },\n { x: -H, y: H },\n { x: -1, y: 0 },\n { x: -H, y: -H },\n { x: 0, y: -1 },\n { x: H, y: -H },\n]\n\n/**\n * Where the drag ends with Shift held: a square or circle for box kinds, the nearest 45 degree\n * angle for lines.\n */\nexport function constrain(kind: ShapeKind, start: Point, end: Point): Point {\n const dx = end.x - start.x\n const dy = end.y - start.y\n if (isLineKind(kind)) {\n const step = Math.round(Math.atan2(dy, dx) / (Math.PI / 4))\n const u = EIGHT_WAYS[((step % 8) + 8) % 8]!\n const length = dx * u.x + dy * u.y\n return { x: clean(start.x + length * u.x), y: clean(start.y + length * u.y) }\n }\n const size = Math.max(Math.abs(dx), Math.abs(dy))\n return {\n x: clean(start.x + (dx < 0 ? -size : size)),\n y: clean(start.y + (dy < 0 ? -size : size)),\n }\n}\n\n/**\n * The two drag corners of the default-size shape centred on `at`. A line or arrow runs left to\n * right on the page as the file displays it: along user space turned anticlockwise by the\n * page's /Rotate `rotation`, which undoes the page's clockwise turn, as a signature is placed.\n */\nexport function defaultEnds(\n kind: ShapeKind,\n at: Point,\n rotation: PageRotation = 0\n): [Point, Point] {\n const half = DEFAULT_SHAPE_SIZE / 2\n if (!isLineKind(kind))\n return [\n { x: at.x - half, y: at.y - half },\n { x: at.x + half, y: at.y + half },\n ]\n const rad = (rotation * Math.PI) / 180\n const dx = Math.round(Math.cos(rad)) * half\n const dy = Math.round(Math.sin(rad)) * half\n return [\n { x: clean(at.x - dx), y: clean(at.y - dy) },\n { x: clean(at.x + dx), y: clean(at.y + dy) },\n ]\n}\n\n/** The annotation a shape kind creates between two points, or `undefined` for a kind without a creator yet. */\nexport function shapeInput(\n kind: ShapeKind,\n page: number,\n start: Point,\n end: Point,\n opts: ShapeOptions\n): AnnotationInput | undefined {\n const rect = rectOf(start, end)\n switch (kind) {\n case 'line':\n return { type: 'line', page, start, end, head: 'None', tail: 'None' }\n case 'arrow':\n return { type: 'line', page, start, end, tail: 'OpenArrow', intent: 'LineArrow' }\n case 'rectangle':\n return { type: 'square', page, rect }\n case 'roundedRectangle':\n return { type: 'square', page, rect, cornerRadius: DEFAULT_CORNER_RADIUS }\n case 'ellipse':\n return { type: 'circle', page, rect }\n case 'bubble': {\n // A standard callout around the dragged box: the edge point is the box's bottom-left\n // quarter point, and the tail runs from it to the tip below and left.\n const edge = { x: clean(rect.x + rect.width / 4), y: clean(rect.y) }\n const tip = { x: clean(edge.x - BUBBLE_TAIL), y: clean(edge.y - BUBBLE_TAIL) }\n const callout = [tip, edge]\n return {\n type: 'freetext',\n page,\n contents: '',\n intent: 'FreeTextCallout',\n cornerRadius: DEFAULT_CORNER_RADIUS,\n width: BUBBLE_WIDTH,\n ...withCalloutBounds(rect, callout, BUBBLE_WIDTH, undefined),\n callout,\n }\n }\n case 'star':\n return { type: 'polygon', page, vertices: starVertices(rect, opts.points) }\n case 'polygon':\n return { type: 'polygon', page, vertices: polygonVertices(rect, opts.sides) }\n case 'loupe':\n // Always a circle: the square on the drag's longer side, as Shift would make it.\n return {\n type: 'loupe',\n page,\n rect: rectOf(start, constrain(kind, start, end)),\n magnification: DEFAULT_LOUPE_MAGNIFICATION,\n }\n case 'mask':\n case 'ovalMask':\n return {\n type: 'mask',\n page,\n rect,\n shape: kind === 'mask' ? 'rect' : 'ellipse',\n dim: DEFAULT_MASK_DIM,\n }\n default:\n return undefined\n }\n}\n","// Recognises a single freehand stroke as a standard shape, by geometric fitting. Pure: no DOM.\n//\n// The stroke is resampled to evenly spaced points (a fiftieth of its box's diagonal apart, so\n// every test is scale-free). Corners of a closed stroke are where the path turns sharply over a\n// few samples, and corners whose neighbours run straight through them are dropped. Then each\n// kind is fitted and scored from 0 to 1, and the best fit wins:\n//\n// - line: how far the path strays from the chord between its ends;\n// - arrow: a straight shaft, then a short head at one end that folds back towards it;\n// - closed strokes (the ends meet, an overshoot trimmed) that wind once round their centre:\n// - ellipse: how far points stray from the ellipse inscribed in the stroke's box;\n// - rectangle: four corners, sides alternating horizontal and vertical;\n// - polygon: three to eight corners joined by straight sides that do not cross;\n// - star: an outline whose corners alternate far from and near the centre, or a pentagram\n// (five straight strokes that wind twice).\n//\n// A stroke that fails every gate (open and bent, winding more or less than once, sides that\n// cross, a corner count no kind has) gets no candidate, so a scrawl or a scribble comes back\n// undefined or scored low.\nimport { starVertices } from './annotations/shape-geometry'\n\nimport type { Point, Rect } from './geometry'\n\nexport type Recognised =\n | { kind: 'line'; start: Point; end: Point }\n | { kind: 'arrow'; start: Point; end: Point }\n | { kind: 'rectangle'; rect: Rect }\n | { kind: 'ellipse'; rect: Rect }\n /** A triangle or other closed polygon, its vertices where the stroke's corners are. */\n | { kind: 'polygon'; vertices: Point[] }\n /** A regular star, outer and inner vertices alternating, the first tip at the top. */\n | { kind: 'star'; vertices: Point[] }\n\n/** The score a fit needs before a stroke is tidied into its shape. */\nexport const RECOGNISE_THRESHOLD = 0.8\n\n/** Samples either side of a point that its turn is measured over. */\nconst W = 3\n/** Turns, over `2 * W` samples, that make a corner: outward, and back against the loop. */\nconst CONVEX_TURN = (40 * Math.PI) / 180\nconst CONCAVE_TURN = (15 * Math.PI) / 180\n/** Resampled points along the box diagonal. */\nconst DENSITY = 50\n/** A run of path is straight when its chord is at least this share of its length. */\nconst STRAIGHT = 0.95\n/** Corners whose neighbours this straight run through them (a turn under about 23 degrees) go. */\nconst MERGE_STRAIGHT = 0.98\n/** The ends of a closed stroke are within this share of the box diagonal. */\nconst CLOSE_GAP = 0.25\n/** Weights of a line's largest and mean straying from its chord, over its length. */\nconst LINE_MAX = 2\nconst LINE_MEAN = 2\n/** Weight of a polygon side's mean straying from its chord, over its length. */\nconst SIDE_MEAN = 3\n\ninterface Fit {\n shape: Recognised\n score: number\n}\n\nconst dist = (a: Point, b: Point): number => Math.hypot(a.x - b.x, a.y - b.y)\nconst clamp01 = (n: number): number => Math.min(Math.max(n, 0), 1)\nconst round = (n: number): number => Math.round(n * 100) / 100 + 0\nconst pt = (p: Point): Point => ({ x: round(p.x), y: round(p.y) })\n\nfunction boxOf(points: readonly Point[]): Rect {\n let minX = Infinity\n let minY = Infinity\n let maxX = -Infinity\n let maxY = -Infinity\n for (const p of points) {\n minX = Math.min(minX, p.x)\n minY = Math.min(minY, p.y)\n maxX = Math.max(maxX, p.x)\n maxY = Math.max(maxY, p.y)\n }\n return { x: minX, y: minY, width: maxX - minX, height: maxY - minY }\n}\n\nconst diagonal = (r: Rect): number => Math.hypot(r.width, r.height)\n\nfunction lengthOf(points: readonly Point[]): number {\n let total = 0\n for (let i = 1; i < points.length; i++) total += dist(points[i - 1]!, points[i]!)\n return total\n}\n\n/** Points every `spacing` along the path, the first and last included. */\nfunction resample(points: readonly Point[], spacing: number): Point[] {\n const out: Point[] = [points[0]!]\n let carried = 0\n let prev = points[0]!\n for (let i = 1; i < points.length; i++) {\n const next = points[i]!\n let d = dist(prev, next)\n while (carried + d >= spacing) {\n const t = (spacing - carried) / d\n const q = { x: prev.x + t * (next.x - prev.x), y: prev.y + t * (next.y - prev.y) }\n out.push(q)\n prev = q\n d = dist(prev, next)\n carried = 0\n }\n carried += d\n prev = next\n }\n const last = points[points.length - 1]!\n if (dist(out[out.length - 1]!, last) > spacing / 2) out.push(last)\n else out[out.length - 1] = last\n return out\n}\n\n/** Distance from `p` to the segment `a`–`b`. */\nfunction toSegment(p: Point, a: Point, b: Point): number {\n const dx = b.x - a.x\n const dy = b.y - a.y\n const len2 = dx * dx + dy * dy\n const t = len2 === 0 ? 0 : clamp01(((p.x - a.x) * dx + (p.y - a.y) * dy) / len2)\n return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy))\n}\n\n/** Path lengths from the first point: `cum[i]` is the length up to point `i`. */\nfunction cumulative(points: readonly Point[]): number[] {\n const cum = [0]\n for (let i = 1; i < points.length; i++)\n cum.push(cum[i - 1]! + dist(points[i - 1]!, points[i]!))\n return cum\n}\n\n/**\n * Corner indices of the loop `r` (its last point joins its first), in order round it. A corner\n * is where the path turns sharply over a few samples: outward by more than `CONVEX_TURN`, or\n * back against the loop's own direction (a star's inner corner) by more than `CONCAVE_TURN`.\n */\nfunction cornersOf(r: readonly Point[]): number[] {\n const n = r.length\n if (n < 2 * W + 2) return []\n const at = (i: number): Point => r[((i % n) + n) % n]!\n const direction = Math.sign(winding(r, centroid(r))) || 1\n const turns = r.map((p, i) => {\n const a = at(i - W)\n const b = at(i + W)\n const turn = Math.atan2(b.y - p.y, b.x - p.x) - Math.atan2(p.y - a.y, p.x - a.x)\n return (\n direction *\n (turn > Math.PI ? turn - 2 * Math.PI : turn < -Math.PI ? turn + 2 * Math.PI : turn)\n )\n })\n /** 1 for an outward corner, -1 for an inward one, 0 for none. */\n const kind = (i: number): number =>\n turns[i]! > CONVEX_TURN ? 1 : turns[i]! < -CONCAVE_TURN ? -1 : 0\n // Each run of sharp turns one way is one corner, at its sharpest. Start where no run is.\n const start = turns.findIndex((_, i) => kind(i) === 0)\n if (start < 0) return []\n const corners: number[] = []\n let best: number | undefined\n for (let k = 0; k <= n; k++) {\n const i = (start + k) % n\n const c = k < n ? kind(i) : 0\n if (best !== undefined && c !== kind(best)) {\n corners.push(best)\n best = undefined\n }\n if (c !== 0 && (best === undefined || Math.abs(turns[i]!) > Math.abs(turns[best]!)))\n best = i\n }\n corners.sort((a, b) => a - b)\n // A jog where the stroke's ends meet can split one corner into two close together: keep the\n // sharper.\n for (let k = 0; corners.length > 1 && k < corners.length;) {\n const next = (k + 1) % corners.length\n if ((corners[next]! - corners[k]! + n) % n > 2 * W) k++\n else\n corners.splice(\n Math.abs(turns[corners[k]!]!) < Math.abs(turns[corners[next]!]!) ? k : next,\n 1\n )\n }\n return mergeStraight(r, corners)\n}\n\n/** Drops corners whose neighbours run straight through them, the straightest first. */\nfunction mergeStraight(r: readonly Point[], corners: number[]): number[] {\n const cum = cumulative(r)\n const total = cum[cum.length - 1]! + dist(r[r.length - 1]!, r[0]!)\n const arc = (a: number, b: number): number =>\n b > a ? cum[b]! - cum[a]! : total - cum[a]! + cum[b]!\n const out = [...corners]\n while (out.length > 3) {\n let drop = -1\n let straightest = MERGE_STRAIGHT\n for (let k = 0; k < out.length; k++) {\n const p = out[(k - 1 + out.length) % out.length]!\n const q = out[(k + 1) % out.length]!\n const a = arc(p, q)\n const ratio = a === 0 ? 1 : dist(r[p]!, r[q]!) / a\n if (ratio > straightest) {\n straightest = ratio\n drop = k\n }\n }\n if (drop < 0) break\n out.splice(drop, 1)\n }\n return out\n}\n\n/** Times the path winds round `c`, signed. */\nfunction winding(points: readonly Point[], c: Point): number {\n let total = 0\n for (let i = 0; i < points.length; i++) {\n const a = points[i]!\n const b = points[(i + 1) % points.length]!\n let d = Math.atan2(b.y - c.y, b.x - c.x) - Math.atan2(a.y - c.y, a.x - c.x)\n if (d > Math.PI) d -= 2 * Math.PI\n if (d < -Math.PI) d += 2 * Math.PI\n total += d\n }\n return total / (2 * Math.PI)\n}\n\n/** Largest and mean distance of `points` from the line through `a` and `b`, over `|ab|`. */\nfunction deviation(\n points: readonly Point[],\n a: Point,\n b: Point\n): { max: number; mean: number } {\n const len = dist(a, b)\n if (len === 0 || points.length === 0) return { max: Infinity, mean: Infinity }\n let max = 0\n let sum = 0\n for (const p of points) {\n const d = Math.abs((b.x - a.x) * (a.y - p.y) - (a.x - p.x) * (b.y - a.y)) / len\n max = Math.max(max, d)\n sum += d\n }\n return { max: max / len, mean: sum / points.length / len }\n}\n\n/** How straight a run from `a` to `b` is: 1 on the chord, falling as the path strays from it. */\nfunction straightness(points: readonly Point[], a: Point, b: Point): number {\n const dev = deviation(points, a, b)\n const bend = 1 - dist(a, b) / lengthOf(points)\n return clamp01(1 - LINE_MAX * dev.max - LINE_MEAN * dev.mean - 2 * bend)\n}\n\nfunction fitLine(r: readonly Point[]): Fit | undefined {\n const a = r[0]!\n const b = r[r.length - 1]!\n if (dist(a, b) / lengthOf(r) < 0.8) return undefined\n return {\n shape: { kind: 'line', start: pt(a), end: pt(b) },\n score: straightness(r, a, b),\n }\n}\n\n/** An arrow whose head is drawn at the end of `r`: a straight shaft, then a short fold back. */\nfunction fitArrow(r: readonly Point[]): Fit | undefined {\n // The tip is where the path first gets (nearly) as far from its start as it ever does: a\n // head with two barbs comes back to the tip, and the second visit may reach a little further.\n const from = r.map((p) => dist(p, r[0]!))\n const far = Math.max(...from)\n let tipAt = from.findIndex((d) => d >= 0.97 * far)\n while (tipAt + 1 < r.length && from[tipAt + 1]! > from[tipAt]!) tipAt++\n const shaft = r.slice(0, tipAt + 1)\n const head = r.slice(tipAt + 1)\n const tail = r[0]!\n const tip = r[tipAt]!\n const shaftLength = lengthOf(shaft)\n const headLength = lengthOf([tip, ...head])\n const total = shaftLength + headLength\n if (shaftLength < 0.6 * total || headLength < 0.06 * shaftLength) return undefined\n const along = { x: (tip.x - tail.x) / shaftLength, y: (tip.y - tail.y) / shaftLength }\n const chord = dist(tail, tip)\n if (chord / shaftLength < STRAIGHT) return undefined\n // The head stays near the tip, folds back from it, and leaves the shaft's line.\n let off = 0\n for (const p of head) {\n if (dist(p, tip) > 0.4 * chord) return undefined\n if ((p.x - tip.x) * along.x + (p.y - tip.y) * along.y > 0.08 * chord) return undefined\n off = Math.max(off, Math.abs((p.x - tip.x) * along.y - (p.y - tip.y) * along.x))\n }\n if (off < 0.04 * chord) return undefined\n return {\n shape: { kind: 'arrow', start: pt(tail), end: pt(tip) },\n score: straightness(shaft, tail, tip),\n }\n}\n\n/**\n * The stroke as a loop, evenly spaced all the way round (the gap between its ends bridged), an\n * overshoot past its start trimmed; undefined when the stroke is open.\n */\nfunction loopOf(r: readonly Point[], size: number, spacing: number): Point[] | undefined {\n const n = r.length\n if (n < 8) return undefined\n // The end may run past the start: close the loop where it comes nearest the start.\n let end = n - 1\n for (let i = Math.floor(n / 2); i < n; i++)\n if (dist(r[i]!, r[0]!) < dist(r[end]!, r[0]!)) end = i\n if (dist(r[end]!, r[0]!) > CLOSE_GAP * size || n - 1 - end > 0.25 * n) return undefined\n const loop = resample([...r.slice(0, end + 1), r[0]!], spacing)\n loop.pop()\n return loop\n}\n\nfunction fitEllipse(loop: readonly Point[], box: Rect): Fit | undefined {\n const rx = box.width / 2\n const ry = box.height / 2\n if (rx === 0 || ry === 0) return undefined\n const cx = box.x + rx\n const cy = box.y + ry\n let sum = 0\n for (const p of loop) sum += Math.abs(Math.hypot((p.x - cx) / rx, (p.y - cy) / ry) - 1)\n const mean = sum / loop.length\n return {\n shape: {\n kind: 'ellipse',\n rect: {\n x: round(box.x),\n y: round(box.y),\n width: round(box.width),\n height: round(box.height),\n },\n },\n score: clamp01(1 - 3 * mean),\n }\n}\n\n/** How closely the loop follows the polygon through `vertices`: 1 on it, falling with distance. */\nfunction polygonFit(\n loop: readonly Point[],\n vertices: readonly Point[],\n size: number\n): number {\n let sum = 0\n for (const p of loop) {\n let best = Infinity\n for (let i = 0; i < vertices.length; i++)\n best = Math.min(\n best,\n toSegment(p, vertices[i]!, vertices[(i + 1) % vertices.length]!)\n )\n sum += best\n }\n return clamp01(1 - (12 * sum) / loop.length / size)\n}\n\n/** Within `tolerance` radians of horizontal (0) or vertical (1); else -1. */\nfunction axisOf(a: Point, b: Point, tolerance: number): { axis: number; off: number } {\n const angle = Math.abs(Math.atan2(b.y - a.y, b.x - a.x)) % Math.PI\n const fromH = Math.min(angle, Math.PI - angle)\n const fromV = Math.abs(angle - Math.PI / 2)\n if (fromH <= tolerance) return { axis: 0, off: fromH }\n if (fromV <= tolerance) return { axis: 1, off: fromV }\n return { axis: -1, off: Math.PI / 4 }\n}\n\nfunction fitRectangle(vertices: readonly Point[], fit: number): Fit | undefined {\n if (vertices.length !== 4) return undefined\n const tolerance = (20 * Math.PI) / 180\n let worst = 0\n for (let i = 0; i < 4; i++) {\n const side = axisOf(vertices[i]!, vertices[(i + 1) % 4]!, tolerance)\n if (\n side.axis < 0 ||\n side.axis !== (axisOf(vertices[0]!, vertices[1]!, tolerance).axis + i) % 2\n )\n return undefined\n worst = Math.max(worst, side.off)\n }\n const xs = vertices.map((v) => v.x).sort((a, b) => a - b)\n const ys = vertices.map((v) => v.y).sort((a, b) => a - b)\n const left = (xs[0]! + xs[1]!) / 2\n const right = (xs[2]! + xs[3]!) / 2\n const bottom = (ys[0]! + ys[1]!) / 2\n const top = (ys[2]! + ys[3]!) / 2\n return {\n shape: {\n kind: 'rectangle',\n rect: {\n x: round(left),\n y: round(bottom),\n width: round(right - left),\n height: round(top - bottom),\n },\n },\n score: clamp01(fit - worst / tolerance / 10),\n }\n}\n\n/** The shape tool's star of `points` tips round `c`, tips at `radius`, the first at the top. */\nfunction regularStar(c: Point, points: number, radius: number): Point[] {\n const box = { x: c.x - radius, y: c.y - radius, width: 2 * radius, height: 2 * radius }\n return starVertices(box, points).map(pt)\n}\n\nconst centroid = (points: readonly Point[]): Point => ({\n x: points.reduce((s, p) => s + p.x, 0) / points.length,\n y: points.reduce((s, p) => s + p.y, 0) / points.length,\n})\n\n/** An outline star: an even number of corners alternating far from and near the centre. */\nfunction fitStar(vertices: readonly Point[], fit: number): Fit | undefined {\n const k = vertices.length\n if (k % 2 !== 0 || k < 8 || k > 16) return undefined\n const c = centroid(vertices)\n const radii = vertices.map((v) => dist(v, c))\n const even = radii.filter((_, i) => i % 2 === 0)\n const odd = radii.filter((_, i) => i % 2 === 1)\n const [outer, inner] = Math.min(...even) > Math.max(...odd) ? [even, odd] : [odd, even]\n if (Math.min(...outer) <= Math.max(...inner)) return undefined\n const mean = (xs: number[]): number => xs.reduce((s, x) => s + x, 0) / xs.length\n const ratio = mean(inner) / mean(outer)\n if (ratio > 0.75) return undefined\n // Tips spread unevenly from the centre make a sloppier star.\n const spread = (Math.max(...outer) - Math.min(...outer)) / mean(outer)\n return {\n shape: { kind: 'star', vertices: regularStar(c, k / 2, mean(outer)) },\n score: clamp01(fit - Math.max(0, spread - 0.2)),\n }\n}\n\n/** A pentagram: five straight strokes that wind twice round the centre. */\nfunction fitPentagram(\n vertices: readonly Point[],\n loop: readonly Point[],\n size: number\n): Fit | undefined {\n if (vertices.length !== 5) return undefined\n const c = centroid(vertices)\n const turns = Math.abs(winding(loop, c))\n if (turns < 1.6 || turns > 2.4) return undefined\n const radii = vertices.map((v) => dist(v, c))\n const mean = radii.reduce((s, x) => s + x, 0) / radii.length\n const spread = (Math.max(...radii) - Math.min(...radii)) / mean\n return {\n shape: { kind: 'star', vertices: regularStar(c, 5, mean) },\n score: clamp01(polygonFit(loop, vertices, size) - Math.max(0, spread - 0.2)),\n }\n}\n\n/** True when two sides of the polygon through `v` cross. */\nfunction crosses(v: readonly Point[]): boolean {\n const k = v.length\n const side = (a: Point, b: Point, c: Point): number =>\n Math.sign((b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x))\n for (let i = 0; i < k; i++)\n for (let j = i + 2; j < k; j++) {\n if (i === 0 && j === k - 1) continue\n const [a, b, c, d] = [v[i]!, v[(i + 1) % k]!, v[j]!, v[(j + 1) % k]!]\n if (side(a, b, c) * side(a, b, d) < 0 && side(c, d, a) * side(c, d, b) < 0)\n return true\n }\n return false\n}\n\n/** How straight the loop runs between consecutive corners: the worst side's score. */\nfunction sidesFit(loop: readonly Point[], corners: readonly number[]): number {\n let worst = 1\n for (let k = 0; k < corners.length; k++) {\n const from = corners[k]!\n const to = corners[(k + 1) % corners.length]!\n const side =\n to > from\n ? loop.slice(from, to + 1)\n : [...loop.slice(from), ...loop.slice(0, to + 1)]\n const a = side[0]!\n const b = side[side.length - 1]!\n const bend = 1 - dist(a, b) / lengthOf(side)\n worst = Math.min(\n worst,\n clamp01(1 - SIDE_MEAN * deviation(side, a, b).mean - 2 * bend)\n )\n }\n return worst\n}\n\nfunction fitClosed(loop: readonly Point[], size: number): Fit[] {\n const box = boxOf(loop)\n const fits: Fit[] = []\n const corners = cornersOf(loop)\n const vertices = corners.map((i) => loop[i]!)\n const pentagram = fitPentagram(vertices, loop, size)\n if (pentagram) fits.push(pentagram)\n // Every other closed kind winds once round its middle.\n const turns = Math.abs(\n winding(loop, { x: box.x + box.width / 2, y: box.y + box.height / 2 })\n )\n if (turns < 0.8 || turns > 1.25) return fits\n const ellipse = fitEllipse(loop, box)\n if (ellipse) fits.push(ellipse)\n if (vertices.length < 3 || crosses(vertices)) return fits\n const fit = polygonFit(loop, vertices, size)\n const rectangle = fitRectangle(vertices, fit)\n if (rectangle) fits.push(rectangle)\n else if (vertices.length <= 8)\n fits.push({\n shape: { kind: 'polygon', vertices: vertices.map(pt) },\n score: Math.min(fit, sidesFit(loop, corners)),\n })\n const star = fitStar(vertices, fit)\n if (star) fits.push(star)\n return fits\n}\n\n/**\n * The standard shape a single freehand stroke (user space points, in drawing order) is closest\n * to, and how well it fits, from 0 to 1. Tidy the stroke only when the score reaches\n * `RECOGNISE_THRESHOLD`. Undefined when no shape fits at all.\n */\nexport function recogniseStroke(\n points: readonly Point[]\n): { shape: Recognised; score: number } | undefined {\n const clean = points.filter(\n (p, i) =>\n Number.isFinite(p.x) &&\n Number.isFinite(p.y) &&\n (i === 0 || p.x !== points[i - 1]!.x || p.y !== points[i - 1]!.y)\n )\n if (clean.length < 2) return undefined\n const size = diagonal(boxOf(clean))\n if (size === 0) return undefined\n // A long path in a small box (a scribble) would resample to thousands of points: cap them.\n const spacing = Math.max(size / DENSITY, lengthOf(clean) / 1000)\n const r = resample(clean, spacing)\n if (r.length < 2) return undefined\n const fits: Fit[] = []\n const line = fitLine(r)\n if (line) fits.push(line)\n const loop = loopOf(r, size, spacing)\n if (loop) fits.push(...fitClosed(loop, size))\n else {\n for (const f of [fitArrow(r), fitArrow([...r].reverse())]) if (f) fits.push(f)\n }\n let best: Fit | undefined\n for (const f of fits) if (!best || f.score > best.score) best = f\n return best && { shape: best.shape, score: round(best.score) }\n}\n","// Signature templates and where they live. A template is a signature drawn or typed once and\n// placed many times: ink strokes in a unit box, or an image. The host owns storage through a\n// `SignatureStore`; core ships a memory store and a localStorage one as conveniences.\n//\n// These are visual signatures, a mark on the page. Nothing here signs the file.\nimport { v7 as uuidv7 } from 'uuid'\nimport { z } from 'zod'\n\nimport { IMAGE_DATA_URL, PointSchema } from './annotations/types'\nimport { readonly, writable, type Readable } from './readable'\n\nimport type { AnnotationInput } from './annotations/types'\nimport type { Point, Rect } from './geometry'\n\n/**\n * A saved signature. Ink points lie in a unit box (0 to 1 on both axes, y growing upwards)\n * that `aspect` (width over height) stretches back to shape. An image keeps its own pixels.\n */\nexport type SignatureTemplate =\n | { id: string; kind: 'ink'; inklist: Point[][]; pressure?: number[][]; aspect: number }\n | { id: string; kind: 'image'; imagedata: string; aspect: number }\n\n/** Where templates live. The host's: a server, the browser, or memory. */\nexport interface SignatureStore {\n list(): Promise<SignatureTemplate[]>\n /** Adds the template, or replaces the one with its id. */\n save(t: SignatureTemplate): Promise<void>\n remove(id: string): Promise<void>\n}\n\n/** Options for the `signature` tool: the template a click places. */\nexport interface SignatureOptions {\n templateId?: string\n}\n\n/** How wide a placed signature is, in points. */\nexport const DEFAULT_SIGNATURE_WIDTH = 150\n\n/** A placed ink signature's stroke width, in points. */\nexport const SIGNATURE_INK_WIDTH = 2\n\nconst Aspect = z.number().positive().finite()\nconst TemplateSchema = z\n .discriminatedUnion('kind', [\n z.object({\n id: z.string().min(1),\n kind: z.literal('ink'),\n inklist: z.array(z.array(PointSchema).min(1)).min(1),\n pressure: z.array(z.array(z.number().min(0).max(1))).optional(),\n aspect: Aspect,\n }),\n z.object({\n id: z.string().min(1),\n kind: z.literal('image'),\n imagedata: z.string().regex(IMAGE_DATA_URL),\n aspect: Aspect,\n }),\n ])\n .refine(\n // Pressure must have one value per point of each stroke, or placing the template would\n // produce ink the store refuses.\n (t) =>\n t.kind !== 'ink' ||\n !t.pressure ||\n (t.pressure.length === t.inklist.length &&\n t.pressure.every((p, i) => p.length === t.inklist[i]?.length)),\n { message: 'pressure must have the same shape as inklist', path: ['pressure'] }\n )\n\n/** The items that are valid templates; the rest are skipped. */\nfunction validTemplates(items: readonly unknown[]): SignatureTemplate[] {\n return items.flatMap((item) => {\n const t = TemplateSchema.safeParse(item)\n return t.success ? [t.data as SignatureTemplate] : []\n })\n}\n\nconst copy = (t: SignatureTemplate): SignatureTemplate =>\n JSON.parse(JSON.stringify(t)) as SignatureTemplate\n\nfunction upsert(\n list: readonly SignatureTemplate[],\n t: SignatureTemplate\n): SignatureTemplate[] {\n const i = list.findIndex((x) => x.id === t.id)\n return i < 0 ? [...list, copy(t)] : list.map((x, j) => (j === i ? copy(t) : x))\n}\n\n/** Templates in memory, gone on reload. The default when a host passes no store. */\nexport function createMemorySignatureStore(\n initial: SignatureTemplate[] = []\n): SignatureStore {\n let items = initial.map(copy)\n return {\n list: () => Promise.resolve(items.map(copy)),\n save(t) {\n items = upsert(items, t)\n return Promise.resolve()\n },\n remove(id) {\n items = items.filter((x) => x.id !== id)\n return Promise.resolve()\n },\n }\n}\n\n/**\n * Templates in `localStorage` under `key`, as a JSON array. Where storage is blocked (it refuses\n * even a tiny test write, as in some private windows) the templates stay in memory for the\n * page's life, so signing still works. Where storage works, or is full but holds a saved list,\n * and has no room for a change, the change is undone and `save` or `remove` rejects, so the host can say so. Stored entries it\n * cannot read, such as a later version's templates, are left out of `list` and kept on write.\n */\nexport function createLocalSignatureStore(key: string): SignatureStore {\n /** Usable storage, or undefined when it is missing or blocked. */\n const storage = ((): Storage | undefined => {\n try {\n const s = globalThis.localStorage ?? undefined\n if (!s) return undefined\n const probe = `${key}:probe`\n try {\n s.setItem(probe, '1')\n s.removeItem(probe)\n } catch {\n // A full store refuses the probe too, but still holds the list: keep it, so the list\n // shows and saves reject. One that holds nothing of ours is treated as blocked.\n return s.getItem(key) === null ? undefined : s\n }\n return s\n } catch {\n return undefined\n }\n })()\n /** What storage holds: the templates, and the entries that are not (kept, never shown). */\n interface Stored {\n items: SignatureTemplate[]\n /** Entries this version cannot read, such as a newer version's: written back unchanged. */\n unread: unknown[]\n }\n /** The stored list; undefined when storage cannot be read. */\n const read = (): Stored | undefined => {\n if (!storage) return undefined\n try {\n const raw = storage.getItem(key)\n if (raw === null) return { items: [], unread: [] }\n const parsed: unknown = JSON.parse(raw)\n if (!Array.isArray(parsed)) return { items: [], unread: [] }\n const items = validTemplates(parsed)\n return { items, unread: parsed.filter((x) => validTemplates([x]).length === 0) }\n } catch (e) {\n // Unreadable JSON is an empty list; a storage that throws is no storage.\n return e instanceof SyntaxError ? { items: [], unread: [] } : undefined\n }\n }\n let { items, unread } = read() ?? { items: [], unread: [] }\n /** Picks up what another tab wrote. */\n const sync = (): void => {\n const stored = read()\n if (stored) ({ items, unread } = stored)\n }\n /** The id of an entry that may not be a template, if it has one. */\n const idOf = (x: unknown): unknown =>\n typeof x === 'object' && x !== null ? (x as { id?: unknown }).id : undefined\n /**\n * Writes `next`, then adopts it; leaves everything as it was when storage refuses. Entries\n * it cannot read go back after the templates, less any whose id a template now has.\n */\n const commit = (next: SignatureTemplate[]): Promise<void> => {\n const ids = new Set<unknown>(next.map((t) => t.id))\n const kept = unread.filter((x) => idOf(x) === undefined || !ids.has(idOf(x)))\n if (storage) {\n try {\n storage.setItem(key, JSON.stringify([...next, ...kept]))\n } catch (cause) {\n return Promise.reject(\n new Error('The signature could not be saved: browser storage is full', {\n cause,\n })\n )\n }\n }\n items = next\n unread = kept\n return Promise.resolve()\n }\n return {\n list() {\n sync()\n return Promise.resolve(items.map(copy))\n },\n save(t) {\n sync()\n return commit(upsert(items, t))\n },\n remove(id) {\n sync()\n return commit(items.filter((x) => x.id !== id))\n },\n }\n}\n\n/**\n * Fits strokes into a unit box, for an ink template. Points come in any y-up space; they go\n * out between 0 and 1 on both axes, and `aspect` is the box's width over its height. A flat\n * side is given 1% of the long side (a dot, a square), so the aspect stays finite, and the\n * strokes are centred across it.\n */\nexport function normaliseInk(inklist: Point[][]): { inklist: Point[][]; aspect: number } {\n const all = inklist.flat()\n const xs = all.map((p) => p.x)\n const ys = all.map((p) => p.y)\n const minX = Math.min(...xs)\n const minY = Math.min(...ys)\n const w = Math.max(...xs) - minX\n const h = Math.max(...ys) - minY\n const long = Math.max(w, h)\n const boxW = long === 0 ? 1 : Math.max(w, long * 0.01)\n const boxH = long === 0 ? 1 : Math.max(h, long * 0.01)\n const map = (p: Point): Point => ({\n x: (p.x - minX + (boxW - w) / 2) / boxW,\n y: (p.y - minY + (boxH - h) / 2) / boxH,\n })\n return { inklist: inklist.map((path) => path.map(map)), aspect: boxW / boxH }\n}\n\n/**\n * An ink template from strokes in any y-up space, with a new id. Throws a RangeError for no\n * strokes, an empty stroke, or pressure that does not have one value per point.\n */\nexport function createInkTemplate(\n inklist: Point[][],\n pressure?: number[][]\n): SignatureTemplate {\n if (inklist.length === 0 || inklist.some((path) => path.length === 0))\n throw new RangeError('A signature needs at least one stroke, and no empty strokes')\n if (\n pressure &&\n (pressure.length !== inklist.length ||\n pressure.some((p, i) => p.length !== inklist[i]!.length))\n )\n throw new RangeError('pressure must have the same shape as inklist')\n const fitted = normaliseInk(inklist)\n return {\n id: uuidv7(),\n kind: 'ink',\n inklist: fitted.inklist,\n ...(pressure ? { pressure: pressure.map((p) => [...p]) } : {}),\n aspect: fitted.aspect,\n }\n}\n\n/** An image template, with a new id. Throws a TypeError unless `imagedata` is a PNG or JPEG data URL. */\nexport function createImageTemplate(\n imagedata: string,\n aspect: number\n): SignatureTemplate {\n if (!IMAGE_DATA_URL.test(imagedata))\n throw new TypeError('A signature image must be a PNG or JPEG data URL')\n if (!(aspect > 0 && Number.isFinite(aspect)))\n throw new RangeError(`aspect must be positive, got ${aspect}`)\n return { id: uuidv7(), kind: 'image', imagedata, aspect }\n}\n\n/**\n * The annotation that places `t` on `page`, `width` points wide on screen and centred on\n * `centre` (user space). `rotation` is the page's /Rotate (clockwise): the signature is turned\n * back by as much, so it reads upright on the page as the file displays it. A viewer's view\n * rotation is left out; it turns the signature with the page like any annotation. Ink becomes `ink` with `subject: 'Signature'`, its strokes inset by half their\n * width; an image becomes a `stamp` with `subject: 'Signature'`.\n */\nexport function placeSignature(\n t: SignatureTemplate,\n page: number,\n centre: Point,\n width: number = DEFAULT_SIGNATURE_WIDTH,\n rotation: 0 | 90 | 180 | 270 = 0\n): AnnotationInput {\n const height = width / t.aspect\n const sideways = rotation === 90 || rotation === 270\n const rw = sideways ? height : width\n const rh = sideways ? width : height\n const rect: Rect = { x: centre.x - rw / 2, y: centre.y - rh / 2, width: rw, height: rh }\n if (t.kind === 'image')\n return {\n type: 'stamp',\n page,\n subject: 'Signature',\n imagedata: t.imagedata,\n rect,\n ...(rotation === 0 ? {} : { rotation }),\n }\n const pad = SIGNATURE_INK_WIDTH / 2\n const innerW = Math.max(width - pad * 2, 0)\n const innerH = Math.max(height - pad * 2, 0)\n const rad = (rotation * Math.PI) / 180\n const cos = Math.round(Math.cos(rad))\n const sin = Math.round(Math.sin(rad))\n const place = (p: Point): Point => {\n const u = (p.x - 0.5) * innerW\n const v = (p.y - 0.5) * innerH\n // Anticlockwise in user space (y up) undoes the page's clockwise turn on screen.\n return { x: centre.x + u * cos - v * sin, y: centre.y + u * sin + v * cos }\n }\n return {\n type: 'ink',\n page,\n subject: 'Signature',\n inklist: t.inklist.map((path) => path.map(place)),\n ...(t.pressure ? { pressure: t.pressure.map((p) => [...p]) } : {}),\n width: SIGNATURE_INK_WIDTH,\n rect,\n }\n}\n\n/**\n * A store's templates kept at hand, so the `signature` tool places one without waiting and the\n * signature menus share one list. Every change goes through the store first.\n */\nexport interface SignatureLibrary {\n readonly store: SignatureStore\n /** The templates as of the last load; empty until the first `refresh`. */\n readonly templates: Readable<readonly SignatureTemplate[]>\n get(id: string): SignatureTemplate | undefined\n /** Reloads from the store. A store that fails to list leaves the last list. */\n refresh(): Promise<void>\n /** Saves through the store, then reloads. Rejects when the store does. */\n save(t: SignatureTemplate): Promise<void>\n /**\n * Removes through the store, then reloads. Rejects when the store does, and then sets\n * `removeError` for the menus to show.\n */\n remove(id: string): Promise<void>\n /** Why the last removal failed; cleared by the next one, or by `clearRemoveError`. */\n readonly removeError: Readable<string | undefined>\n clearRemoveError(): void\n}\n\nexport function createSignatureLibrary(store: SignatureStore): SignatureLibrary {\n const templates = writable<readonly SignatureTemplate[]>([])\n const removeError = writable<string | undefined>(undefined)\n /**\n * The newest load that succeeded writes, so a slow one cannot undo a later save, and a later\n * one that fails does not throw away a slow success.\n */\n let loads = 0\n let applied = 0\n const refresh = async (): Promise<void> => {\n const n = ++loads\n try {\n // A host store may hand back anything: an invalid template would fail when placed.\n const list = validTemplates(await store.list())\n if (n > applied) {\n applied = n\n templates.set(list)\n }\n } catch {\n // The store is unavailable: keep what was there.\n }\n }\n return {\n store,\n templates: readonly(templates),\n get: (id) => templates.get().find((t) => t.id === id),\n refresh,\n async save(t) {\n await store.save(t)\n await refresh()\n },\n async remove(id) {\n removeError.set(undefined)\n try {\n await store.remove(id)\n } catch (e) {\n removeError.set('The signature could not be removed. Try again.')\n throw e\n }\n await refresh()\n },\n removeError: readonly(removeError),\n clearRemoveError: () => removeError.set(undefined),\n }\n}\n"],"mappings":";;;AAWA,IAAa,WAAb,cAA8B,MAAM;CAClC,OAAyB;CACzB;CACA;CAEA,YACE,MACA,SACA,UAAmC,CAAC,GACpC,OACA;EACA,MAAM,SAAS,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,MAAM,CAAC;EAC1D,KAAK,OAAO;EACZ,KAAK,UAAU;CACjB;AACF;AAEA,SAAgB,WAAW,OAAmC;CAC5D,OACE,iBAAiB,YAChB,OAAO,UAAU,YAChB,UAAU,QACT,MAA6B,SAAS;AAE7C;;;ACjCA,IAAa,UAAb,MAA6D;CAC3D,4BAAoB,IAAI,IAAwC;CAEhE,GAA2B,OAAU,IAAqC;EACxE,IAAI,MAAM,KAAK,UAAU,IAAI,KAAK;EAClC,IAAI,CAAC,KAAK;GACR,sBAAM,IAAI,IAAI;GACd,KAAK,UAAU,IAAI,OAAO,GAAG;EAC/B;EACA,IAAI,IAAI,EAAE;EACV,aAAa;GACX,KAAK,OAAO,EAAE;EAChB;CACF;CAEA,KAA6B,OAAU,SAA0B;EAC/D,MAAM,MAAM,KAAK,UAAU,IAAI,KAAK;EACpC,IAAI,CAAC,KAAK;EACV,KAAK,MAAM,MAAM,CAAC,GAAG,GAAG,GAAG,GAA4B,OAAO;CAChE;CAEA,QAAc;EACZ,KAAK,UAAU,MAAM;CACvB;AACF;;;ACEA,SAAgB,YAAY,GAAW,GAAW,MAAM,KAAe;CACrE,OAAO,KAAK,IAAI,IAAI,CAAC,KAAK;AAC5B;AAEA,SAAgB,eAAe,GAAU,GAAgB;CAGvD,OAAO;EAAE,GAFC,KAAK,IAAI,EAAE,GAAG,EAAE,CAEjB;EAAG,GADF,KAAK,IAAI,EAAE,GAAG,EAAE,CACd;EAAG,OAAO,KAAK,IAA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