@embedpdf/plugin-annotation 3.0.0-next.2 → 3.0.0-next.20

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.
Files changed (42) hide show
  1. package/README.md +129 -0
  2. package/dist/authoring.cjs +26 -0
  3. package/dist/authoring.d.cts +2 -0
  4. package/dist/authoring.d.ts +2 -0
  5. package/dist/authoring.js +2 -0
  6. package/dist/contract/host.cjs +19 -0
  7. package/dist/contract/host.d.cts +3 -0
  8. package/dist/contract/host.d.ts +3 -0
  9. package/dist/contract/host.js +3 -0
  10. package/dist/contract-CPzpRG3h.cjs +692 -0
  11. package/dist/contract-CPzpRG3h.cjs.map +1 -0
  12. package/dist/contract-Cm0cfAzG.d.cts +1152 -0
  13. package/dist/contract-QAvnfm2b.d.ts +1152 -0
  14. package/dist/contract-b2e_LZvu.js +651 -0
  15. package/dist/contract-b2e_LZvu.js.map +1 -0
  16. package/dist/contract.cjs +13 -0
  17. package/dist/contract.d.cts +2 -0
  18. package/dist/contract.d.ts +2 -0
  19. package/dist/contract.js +2 -0
  20. package/dist/host-contract-BDwyBNrs.d.cts +331 -0
  21. package/dist/host-contract-BUub1Un-.d.ts +331 -0
  22. package/dist/host-contract-CxrQPcPj.js +52 -0
  23. package/dist/host-contract-CxrQPcPj.js.map +1 -0
  24. package/dist/host-contract-DY9jFPPF.cjs +87 -0
  25. package/dist/host-contract-DY9jFPPF.cjs.map +1 -0
  26. package/dist/index.cjs +5296 -389
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +13 -59
  29. package/dist/index.d.ts +13 -59
  30. package/dist/index.js +5255 -375
  31. package/dist/index.js.map +1 -1
  32. package/package.json +24 -11
  33. package/dist/capability-fghl0JmE.js +0 -2680
  34. package/dist/capability-fghl0JmE.js.map +0 -1
  35. package/dist/capability-hb2AU0f6.cjs +0 -2739
  36. package/dist/capability-hb2AU0f6.cjs.map +0 -1
  37. package/dist/internal.cjs +0 -5
  38. package/dist/internal.d.cts +0 -13
  39. package/dist/internal.d.ts +0 -13
  40. package/dist/internal.js +0 -2
  41. package/dist/types-BhWgqgbX.d.cts +0 -879
  42. package/dist/types-Da6JRmhw.d.ts +0 -879
@@ -0,0 +1,1152 @@
1
+ import { BatchResult, DeepPartial, EventHook, EventOrigin, OperationOptions, PluginErrorInfo, ResourceStatus, SettingsApi, Unsubscribe } from "@embedpdf/core";
2
+ import { MountableFontProgram } from "@embedpdf/plugin-fonts/contract";
3
+ import { AnnotationTransfer } from "@embedpdf/engine-core/public";
4
+ import { Annotation, Annotation as Annotation$1, AnnotationBundle, AnnotationBundle as AnnotationBundle$1, AnnotationDraft, AnnotationDraft as AnnotationDraft$1, AnnotationImportDrop, AnnotationImportDrop as AnnotationImportDrop$1, AnnotationImportOptions, AnnotationImportOptions as AnnotationImportOptions$1, AnnotationPatch, AnnotationPatch as AnnotationPatch$1, AnnotationPosition, AnnotationPosition as AnnotationPosition$1, AnnotationRef, AnnotationRef as AnnotationRef$1, AnnotationResourceRole, AnnotationResourceRole as AnnotationResourceRole$1, AnnotationResources, AnnotationResources as AnnotationResources$1, AnnotationSubtype, AnnotationSubtype as AnnotationSubtype$1, AttachmentContent, AttachmentFileSource, AttachmentFileSource as AttachmentFileSource$1, BinarySource, Color, CommentThread, CommentThread as CommentThread$1, CommentThreadReview, PageRef, PdfActionTree, PdfLinkTarget, PdfLinkTarget as PdfLinkTarget$1, ReviewStatus, RichTextBody, RichTextParagraph, WidgetAppearance } from "@embedpdf/engine-core/runtime";
5
+ import { AnnotationFlags, AnnotationFlags as AnnotationFlags$1, AnnotationOption, AnnotationProperty, AnnotationProperty as AnnotationProperty$1, BlendMode, ClickCreate, ClickCreate as ClickCreate$1, CreationDraftAnchor, EditableKind, EditableKinds, EditableKinds as EditableKinds$1, FieldValues, FieldValues as FieldValues$1, FlagKey, HandleRole, InkStraightenOptions, KindName, LineEnding, LineEndings, MeasurementIntent, Rect, RichTextRange, RotationAnchor, SnapSettings, SnapSettings as SnapSettings$1, TextAlign, ViewEnv } from "@embedpdf/core-annotation";
6
+ import "@embedpdf/plugin-interaction/contract";
7
+ import { Point as Point$1 } from "@embedpdf/core-geometry";
8
+ //#region src/rich-text.d.ts
9
+ type TextFormat = 'bold' | 'italic' | 'underline';
10
+ /** The editor's selection inside one free-text annotation: flat offsets over
11
+ * the plain projection (paragraphs joined by `\r`). */
12
+ interface TextSelection extends RichTextRange {
13
+ id: string;
14
+ }
15
+ /** The face a run or a body names. */
16
+ interface Face {
17
+ family: string;
18
+ weight?: number;
19
+ italic?: boolean;
20
+ }
21
+ //#endregion
22
+ //#region src/tools/definitions.d.ts
23
+ /**
24
+ * How a stamp-family tool resolves the image bytes it places — pure data, so a
25
+ * tool table stays JSON-serializable (config can come from a file, a DB, or the
26
+ * server). Evaluated at click time, so the user picks the spot first, then the
27
+ * source:
28
+ * - `{ kind: 'bytes' }` — fixed bytes: a company rubber-stamp.
29
+ * - `{ kind: 'prompt' }` — ask the environment for bytes. The plugin does not
30
+ * know how (a file dialog is DOM); the file-picker port (`FilePickerProvider`),
31
+ * installed by the framework adapter, fulfils it. Resolve `null` there to cancel.
32
+ */
33
+ type StampSourceSpec = {
34
+ kind: 'bytes';
35
+ source: BinarySource;
36
+ } | PromptSourceSpec;
37
+ /**
38
+ * The ask-the-environment resolution, shared by every click-then-pick tool
39
+ * (a stamp's `'prompt'` source, the file-attachment tool). `accept` is the
40
+ * file-dialog filter the picker request carries — a UX hint only, the engine
41
+ * sniffs/validates the bytes for real. Unset = any file.
42
+ */
43
+ interface PromptSourceSpec {
44
+ kind: 'prompt';
45
+ accept?: string;
46
+ }
47
+ /**
48
+ * The tool `stamps.arm` activates — and the only tool an armed payload survives
49
+ * onto (plus the legacy `annotation-stamp` tag, honoured for embedder configs
50
+ * written before the tags were unified). Placement consults the armed payload
51
+ * before the active tool's own `source` spec, so a payload must not outlive
52
+ * its tool onto a sibling stamp preset: an `image` preset's click has to open
53
+ * its own picker, not silently place whatever the stamp panel last armed.
54
+ */
55
+ declare const ARMED_STAMP_TOOL_ID = "stamp";
56
+ /** Declarative result of committing a text selection while a tool is active. */
57
+ type SelectionAuthoring = {
58
+ kind: 'markup';
59
+ } | {
60
+ kind: 'text-edit';
61
+ operation: 'insert' | 'replace';
62
+ };
63
+ /**
64
+ * The tool's ghost: a see-through copy of what a click would place, following
65
+ * the pointer, drawn with the tool's current defaults exactly where and as
66
+ * the click will make it. `true` shows it half see-through, `{ opacity }`
67
+ * as opaque as you say (0–1; `--epdf-ghost-opacity` wins over it from CSS),
68
+ * `false` hides it. It shows only where a click creates: a tool whose click
69
+ * makes nothing (ink, a polygon, `clickCreate: false`) has none, and it hides
70
+ * over an annotation or text, where the click does something else.
71
+ * The cursor says which tool is active; the ghost says where the click lands.
72
+ */
73
+ type GhostPolicy = boolean | {
74
+ opacity: number;
75
+ };
76
+ /** A resolved ghost: how opaque it paints, or `false` for none. */
77
+ type ResolvedGhost = false | {
78
+ opacity: number;
79
+ };
80
+ /** Time/geometry policy for freehand ink authoring. */
81
+ interface InkAuthoringOptions {
82
+ /** Group strokes made within this interval into one `/InkList`; 0 commits immediately. */
83
+ groupStrokesMs?: number;
84
+ /** Optional pure straight-line recognition applied to each completed stroke. */
85
+ straighten?: InkStraightenOptions;
86
+ }
87
+ /**
88
+ * The fields no tool's defaults may set: where the annotation goes (that comes
89
+ * from the drawing), its identity and relationships, and what the engine
90
+ * stamps or keeps by itself.
91
+ */
92
+ declare const NOT_DEFAULTS: readonly ["ref", "page", "index", "hasAppearance", "appearanceState", "nm", "rect", "box", "linePoints", "vertices", "inkList", "quadPoints", "calloutLine", "captionCenter", "measure", "reply", "popup", "parent", "groupId", "author", "createdAt", "modifiedAt", "userId", "createdBy", "modifiedBy", "importedBy", "actions"];
93
+ type NotDefault = (typeof NOT_DEFAULTS)[number];
94
+ /**
95
+ * The fields each known authoring kind's defaults may set: any field a create
96
+ * from the tool takes besides where it goes, flags and `contents` included.
97
+ * A key outside it stops the app at startup, naming the tool and the field.
98
+ */
99
+ declare const TOOL_DEFAULT_FIELDS: {
100
+ readonly square: readonly string[];
101
+ readonly circle: readonly string[];
102
+ readonly line: readonly string[];
103
+ readonly polygon: readonly string[];
104
+ readonly polyline: readonly string[];
105
+ readonly ink: readonly string[];
106
+ readonly 'free-text': readonly string[];
107
+ readonly 'free-text-callout': readonly string[];
108
+ readonly highlight: readonly string[];
109
+ readonly underline: readonly string[];
110
+ readonly strikeout: readonly string[];
111
+ readonly squiggly: readonly string[];
112
+ readonly caret: readonly string[];
113
+ readonly redact: readonly string[];
114
+ readonly stamp: readonly string[];
115
+ readonly link: readonly string[];
116
+ readonly text: readonly string[];
117
+ readonly 'file-attachment': readonly string[];
118
+ readonly 'widget-text': readonly ["color", "interiorColor", "strokeWidth", "borderStyle", "fontFamily", "fontSize", "fontColor", "textAlign"];
119
+ readonly 'widget-choice': readonly ["color", "interiorColor", "strokeWidth", "borderStyle", "fontFamily", "fontSize", "fontColor", "textAlign"];
120
+ readonly 'widget-button': readonly ["color", "interiorColor", "strokeWidth", "borderStyle", "fontFamily", "fontSize", "fontColor", "textAlign"];
121
+ readonly 'widget-toggle': readonly ["color", "interiorColor", "strokeWidth", "borderStyle"];
122
+ readonly 'widget-radio': readonly ["color", "interiorColor", "strokeWidth", "borderStyle"];
123
+ readonly 'widget-box': readonly ["color", "interiorColor", "strokeWidth", "borderStyle"];
124
+ };
125
+ type ToolAuthoringKind = keyof typeof TOOL_DEFAULT_FIELDS;
126
+ /** The draft a kind's creates are: a callout is a free text; a form tool's kind is a widget's appearance. */
127
+ type ToolDraftOf<K extends ToolAuthoringKind> = K extends `widget-${string}` ? Partial<Pick<WidgetAppearance, (typeof TOOL_DEFAULT_FIELDS)[K][number] & keyof WidgetAppearance>> : Omit<Partial<Extract<AnnotationDraft, {
128
+ subtype: K extends 'free-text-callout' ? 'free-text' : K;
129
+ }>>, NotDefault | 'subtype' | 'richText'>;
130
+ /** A tool's rich text is its body: the formatting what it types starts with. */
131
+ type ToolRichText = {
132
+ richText?: {
133
+ body: Partial<RichTextBody>;
134
+ };
135
+ };
136
+ /**
137
+ * The defaults a tool of kind `K` takes: any field of what it draws, flags
138
+ * included, except where it goes (`box`, `rect`, points), which the drawing
139
+ * gives.
140
+ */
141
+ type ToolDefaultsFor<K extends ToolAuthoringKind> = ToolDraftOf<K> & (K extends 'free-text' | 'free-text-callout' ? ToolRichText : unknown);
142
+ /**
143
+ * A tool definition — the public config vocabulary. Every field except `id` is
144
+ * optional: the common cases are "configure a built-in" (`{ id, defaults }`) and
145
+ * "add a preset" (`{ id, extends, defaults }`).
146
+ */
147
+ interface AnnotationToolDef<K extends ToolAuthoringKind = ToolAuthoringKind> {
148
+ /** Stable tool id — the value passed to `activateTool` and the `defaults` key. */
149
+ id: string;
150
+ /** Inherit `subtype` / `fieldsKind` / `cursor` / `enables` / `source` /
151
+ * `selection` / `intent` / `ink` / `meta`
152
+ * from an existing tool id (a built-in or another entry). Own fields win. */
153
+ extends?: string;
154
+ /** The routing kind this tool authors — the core's client kind (the geometry
155
+ * it draws + the props key). Usually the PDF subtype, but not always:
156
+ * `free-text-callout` routes the callout gesture onto a free-text
157
+ * annotation, and `widget-text`/`widget-choice`/`widget-toggle`/`widget-radio` are client
158
+ * views of the one PDF `widget` subtype (a form tool's commit goes through
159
+ * `doc.forms`, never this plugin — see the form plugin's tool table).
160
+ * Defaults to the inherited kind, or the id when neither is given. */
161
+ subtype?: KindName;
162
+ /** The kind whose editable fields a style panel shows for this tool.
163
+ * Defaults to `subtype`. */
164
+ fieldsKind?: string;
165
+ /** Advanced: the `defaults` key this tool reads/writes. Defaults to the id, and
166
+ * that is almost always right — override it only to alias a shared defaults bag
167
+ * (the built-in insert-caret tool points its preset at the `caret` key). */
168
+ preset?: string;
169
+ /** The engine fields what the tool draws takes, besides its shape: a draft
170
+ * without its shape, merged over any inherited defaults (each value whole).
171
+ * The engine's defaults fill in what they leave out. */
172
+ defaults?: ToolDefaultsFor<K>;
173
+ /**
174
+ * `/F` annotation flags seeded on everything this tool creates, merged over
175
+ * the drawn default (`print` set — Acrobat parity) and any inherited seed.
176
+ * A note tool passes `{ noZoom: true, noRotate: true }` so its icons stay
177
+ * screen-sized and upright (the spec's rule for Text annotations).
178
+ */
179
+ flags?: Partial<AnnotationFlags>;
180
+ /** The pointer cursor while this tool is active. Defaults inherited / `crosshair`. */
181
+ cursor?: string;
182
+ /** Interaction capability tags this tool enables (which handlers wake up). */
183
+ enables?: string[];
184
+ /**
185
+ * How the click-to-place payload resolves. Stamps take the full spec
186
+ * ({@link StampSourceSpec}: fixed bytes or prompt); file attachments are
187
+ * prompt-only ({@link PromptSourceSpec} — the file always comes from the
188
+ * environment). Other kinds carry no payload.
189
+ */
190
+ source?: K extends 'stamp' ? StampSourceSpec : K extends 'file-attachment' ? PromptSourceSpec : never;
191
+ /** What a committed text selection authors. Omit for pointer/click tools. */
192
+ selection?: SelectionAuthoring;
193
+ /** Ink-only stroke grouping and straightening policy. */
194
+ ink?: K extends 'ink' ? InkAuthoringOptions : never;
195
+ /**
196
+ * Place annotations upright: counter-rotate what this tool creates against the
197
+ * page's total display rotation (document /Rotate + any stage view rotation),
198
+ * so it reads horizontally exactly as the author saw it — Adobe's behaviour
199
+ * for stamps and text on rotated pages. WYSIWYG at authoring time: the
200
+ * rotation is baked into the annotation, so a save keeps what the author saw
201
+ * (other viewers apply only /Rotate — document that when view rotation is in
202
+ * play). A drawing without a reading direction bakes no turn: a clicked
203
+ * square or circle swaps its sides instead, so it shows its `clickCreate`
204
+ * size as the author sees the page, and a clicked line points the way its
205
+ * `clickCreate` says there; a drag, and a callout's leader, follow the
206
+ * pointer. Default: on for the built-in `stamp`, `free-text`, `note`,
207
+ * `attachment`, `square`, `circle` and `line` tools, off elsewhere.
208
+ */
209
+ upright?: boolean;
210
+ /**
211
+ * What a bare click creates ({@link ClickCreate}): a default-size shape
212
+ * centred on the point, a default-length line centred on it, free text's
213
+ * type-here box hanging from it — page-clamped, in PDF pt. `false` =
214
+ * drag-only. Defaults: on for the built-in square/circle/line/free-text,
215
+ * off elsewhere.
216
+ */
217
+ clickCreate?: ClickCreate | false;
218
+ /**
219
+ * The tool's ghost ({@link GhostPolicy}). Defaults: inherited, else off;
220
+ * on for the built-in click-to-place tools (stamp, note, attachment).
221
+ */
222
+ ghost?: GhostPolicy;
223
+ /**
224
+ * What happens after this tool creates an annotation: select it, keep the
225
+ * tool, start typing in a text box. Wins over the `afterCreate` setting for
226
+ * every tool; what it leaves out comes from there.
227
+ */
228
+ afterCreate?: Partial<AfterCreateSettings>;
229
+ /** Your own data, such as a label and an icon for a toolbar that builds itself
230
+ * from the tool table. The plugin keeps it and never reads it. */
231
+ meta?: Record<string, unknown>;
232
+ }
233
+ interface BuiltinToolKindMap {
234
+ square: 'square';
235
+ circle: 'circle';
236
+ line: 'line';
237
+ distance: 'line';
238
+ perimeter: 'polyline';
239
+ area: 'polygon';
240
+ calibrate: 'line';
241
+ polygon: 'polygon';
242
+ polyline: 'polyline';
243
+ ink: 'ink';
244
+ 'ink-highlight': 'ink';
245
+ 'free-text': 'free-text';
246
+ 'free-text-callout': 'free-text-callout';
247
+ highlight: 'highlight';
248
+ underline: 'underline';
249
+ strikeout: 'strikeout';
250
+ squiggly: 'squiggly';
251
+ 'insert-text': 'caret';
252
+ 'replace-text': 'strikeout';
253
+ redact: 'redact';
254
+ stamp: 'stamp';
255
+ note: 'text';
256
+ attachment: 'file-attachment';
257
+ link: 'link';
258
+ }
259
+ type DirectToolDef = { [K in ToolAuthoringKind]: Omit<AnnotationToolDef<K>, 'subtype'> & {
260
+ subtype: K;
261
+ }; }[ToolAuthoringKind];
262
+ type BuiltinToolOverride = { [I in keyof BuiltinToolKindMap]: Omit<AnnotationToolDef<BuiltinToolKindMap[I]>, 'id' | 'extends' | 'subtype'> & {
263
+ id: I;
264
+ extends?: undefined;
265
+ subtype?: undefined;
266
+ }; }[keyof BuiltinToolKindMap];
267
+ type ExtendedBuiltinToolDef = { [I in keyof BuiltinToolKindMap]: Omit<AnnotationToolDef<BuiltinToolKindMap[I]>, 'extends' | 'subtype'> & {
268
+ extends: I;
269
+ subtype?: undefined;
270
+ }; }[keyof BuiltinToolKindMap];
271
+ /** Public tool input: known overrides, known-base presets, or an explicit subtype. */
272
+ type AnnotationToolInput = DirectToolDef | BuiltinToolOverride | ExtendedBuiltinToolDef;
273
+ /** A fully-resolved tool — what the plugin, handlers, and registration loop read. */
274
+ interface ResolvedTool {
275
+ id: string;
276
+ /** Routing token for the draw core + the created annotation's PDF subtype. */
277
+ subtype: KindName;
278
+ /** The `defaults` key (always the tool id) — keeps same-subtype tools apart. */
279
+ preset: string;
280
+ /** The kind whose properties the style panel shows (`propertiesOf(kindNamed(…))`). */
281
+ fieldsKind: string;
282
+ cursor: string;
283
+ enables: ReadonlySet<string>;
284
+ defaults?: FieldValues;
285
+ /** `/F` seed for created annotations (see {@link AnnotationToolDef.flags}). */
286
+ flags?: Partial<AnnotationFlags>;
287
+ source?: StampSourceSpec;
288
+ selection?: SelectionAuthoring;
289
+ ink?: InkAuthoringOptions;
290
+ /** Counter-rotate creations against the page's display rotation (see
291
+ * {@link AnnotationToolDef.upright}). */
292
+ upright: boolean;
293
+ /** What a bare click creates, or `false` for drag-only. */
294
+ clickCreate: ClickCreate | false;
295
+ /** The tool's ghost ({@link GhostPolicy}): how opaque it paints, or `false` for none. */
296
+ ghost: ResolvedGhost;
297
+ /** Its own `afterCreate` (see {@link AnnotationToolDef.afterCreate}), over the setting. */
298
+ afterCreate?: Partial<AfterCreateSettings>;
299
+ /** A line gesture is captured, not created ({@link CAPTURE_TOOLS}). */
300
+ capture: boolean;
301
+ meta?: Record<string, unknown>;
302
+ }
303
+ /**
304
+ * The built-in tools, as data (shapes + lines + ink
305
+ * + free text in the draw channel, text markup + caret behind text selection, and
306
+ * the click-to-place stamp). Order is display-neutral; the toolbar owns layout.
307
+ */
308
+ declare const DEFAULT_TOOLS: AnnotationToolInput[];
309
+ //#endregion
310
+ //#region src/token.d.ts
311
+ declare const AnnotationToken: import("@embedpdf/core").CapabilityToken<AnnotationCapability>;
312
+ //#endregion
313
+ //#region src/state.d.ts
314
+ /** Whether the annotations are read, and the ones selected, under the pointer and being typed in. */
315
+ interface AnnotationState {
316
+ /** `loading` until the document's annotations are in, then `ready`; `forbidden` or `error` when they can't load. */
317
+ readonly status: ResourceStatus;
318
+ /** The selected annotations, as the user sees them. */
319
+ readonly selected: readonly Annotation[];
320
+ /** The annotation under the pointer, or `null`. */
321
+ readonly hovered: Annotation | null;
322
+ /** The text box being typed in, or `null`. */
323
+ readonly editing: Annotation | null;
324
+ }
325
+ declare const annotationState: import("@embedpdf/core").StateDeclaration<AnnotationCapability, AnnotationState>;
326
+ //#endregion
327
+ //#region src/contract.d.ts
328
+ /** `'solid'` or `'dashed'` (4 pixels on, 3 off). */
329
+ type LineStyle = 'solid' | 'dashed';
330
+ /**
331
+ * How a selection looks: its outline, its handles and rotation handle, the
332
+ * lines shown while snapping and turning, the box dragged to select, a text
333
+ * box's outline while typing, and the angle while turning. Every size is in
334
+ * screen pixels, so it looks the same at every zoom. A color left `null`
335
+ * follows the part named in its doc, and in the end `accent`; every color,
336
+ * width and dash can also come from a CSS variable (`--epdf-annotation-*`),
337
+ * which wins over the setting.
338
+ */
339
+ interface ChromeSettings {
340
+ /** The color of every part below that has none of its own; `null` follows the viewer's accent. */
341
+ readonly accent: string | null;
342
+ /** The box around the selection. */
343
+ readonly outline: {
344
+ /** `null` follows `accent`. */
345
+ readonly color: string | null;
346
+ readonly style: LineStyle;
347
+ /** Line width, px. */
348
+ readonly width: number;
349
+ };
350
+ /** The resize and point handles. */
351
+ readonly handles: {
352
+ readonly shape: 'square' | 'circle';
353
+ /** What you see, px. */
354
+ readonly size: number;
355
+ /** What you can grab, px: keep it at 24 or more for touch. */
356
+ readonly hitSize: number;
357
+ readonly fill: string;
358
+ /** `null` follows `accent`. */
359
+ readonly stroke: string | null;
360
+ };
361
+ /** The round handle that turns the selection, on a short line (its stalk) above it. */
362
+ readonly rotationHandle: {
363
+ /** `false`: no rotation handle; the selection turns only from code. */
364
+ readonly enabled: boolean;
365
+ /** Its diameter, px. */
366
+ readonly size: number;
367
+ /** What you can grab, px. */
368
+ readonly hitSize: number;
369
+ /** How far it sits from the selection's edge, px. */
370
+ readonly offset: number;
371
+ /** `false` hides the line from the edge to it. */
372
+ readonly stalk: boolean;
373
+ /** `null` follows `handles.fill`. */
374
+ readonly fill: string | null;
375
+ /** `null` follows `handles.stroke`. */
376
+ readonly stroke: string | null;
377
+ };
378
+ /** The lines shown while snapping (alignment) and while turning (rotation). */
379
+ readonly guides: {
380
+ /** `false`: no rotation guides while turning. */
381
+ readonly enabled: boolean;
382
+ /** What a move snaps to. */
383
+ readonly color: string;
384
+ /** The reference cross and the angle line while turning; `null` follows `accent`. */
385
+ readonly rotationColor: string | null;
386
+ readonly style: LineStyle;
387
+ /** Line width of both kinds, px. */
388
+ readonly width: number;
389
+ };
390
+ /** The box you drag to select several annotations. */
391
+ readonly marquee: {
392
+ /** `null`: `accent` at 8%. */
393
+ readonly fill: string | null;
394
+ /** `null` follows `accent`. */
395
+ readonly stroke: string | null;
396
+ };
397
+ /** The outline of a text box while you type in it; `null` follows `accent`. */
398
+ readonly textOutline: string | null;
399
+ /** The angle shown next to the pointer while you turn a selection. */
400
+ readonly readout: {
401
+ readonly enabled: boolean;
402
+ readonly background: string;
403
+ readonly color: string;
404
+ };
405
+ }
406
+ /**
407
+ * A tool's defaults: the fields its next annotation starts with, its own over
408
+ * the engine's. Which fields there are depends on the tool's kind; the style
409
+ * fields most tools have are typed, the rest read as `unknown`.
410
+ */
411
+ interface ToolDefaults {
412
+ readonly color?: string;
413
+ readonly interiorColor?: string | null;
414
+ readonly opacity?: number;
415
+ readonly strokeWidth?: number;
416
+ readonly fontFamily?: string;
417
+ readonly fontSize?: number;
418
+ readonly fontColor?: string;
419
+ readonly textAlign?: 'left' | 'center' | 'right';
420
+ readonly icon?: string;
421
+ readonly contents?: string | null;
422
+ readonly [field: string]: unknown;
423
+ }
424
+ /** What happens after a tool creates an annotation. A tool's own `afterCreate` wins over this. */
425
+ interface AfterCreateSettings {
426
+ /** Select the new annotation. */
427
+ readonly select: boolean;
428
+ /** `'stay'` keeps the tool active; `'default'` goes back to the default tool, usually `pointer`. */
429
+ readonly tool: 'stay' | 'default';
430
+ /** For text boxes: start typing in the new box right away. */
431
+ readonly editText: boolean;
432
+ }
433
+ /**
434
+ * The annotation settings: what `annotationPlugin(config)` registers over
435
+ * {@link ANNOTATION_DEFAULTS}. `snap`, `chrome`, `afterCreate` and `editable`
436
+ * change for every open document with `updateSettings()`; `tools` is read
437
+ * when a document opens (add a tool to an open one with `tools.register()`).
438
+ */
439
+ interface AnnotationSettings {
440
+ /**
441
+ * Change the built-in tools or add your own. An entry with a built-in's id
442
+ * changes it (`{ id: 'ink', defaults: { strokeWidth: 6 } }`), a new id adds
443
+ * a tool, and `extends` starts from another tool.
444
+ */
445
+ readonly tools: readonly AnnotationToolInput[];
446
+ readonly afterCreate: AfterCreateSettings;
447
+ readonly chrome: ChromeSettings;
448
+ /** Snapping to other annotations and the page while moving, and to angles while turning. */
449
+ readonly snap: SnapSettings;
450
+ /**
451
+ * Which annotations people may change by hand: `true`, every one; `false`,
452
+ * none; or a list of the kinds they may, by subtype (`'highlight'`), a
453
+ * measurement by its intent (`'line-dimension'`). One left out can still be
454
+ * selected, read and commented on, but not moved, resized, turned,
455
+ * restyled, typed in or deleted. Only the interface: your code still
456
+ * changes it, and `canUpdate()` and `canDelete()` don't change.
457
+ */
458
+ readonly editable: EditableKinds;
459
+ }
460
+ /** What the annotation settings are when the app registers none. */
461
+ declare const ANNOTATION_DEFAULTS: AnnotationSettings;
462
+ /** What `annotationPlugin(config)` takes: any of the settings, merged over the defaults. */
463
+ type AnnotationConfig = DeepPartial<AnnotationSettings>;
464
+ /**
465
+ * The armed stamp's ghost: its image, see-through, in the box a click at the
466
+ * pointer would place it in (page space). Every other tool's ghost paints
467
+ * with the page's items (`source: 'ghost'`).
468
+ */
469
+ interface ImageGhost {
470
+ page: PageRef;
471
+ /** The box the stamp's placement would use, before its turn. */
472
+ box: Rect;
473
+ /** The tool's upright turn at this hover (degrees clockwise). */
474
+ rot: number;
475
+ /** How opaque it paints (0–1); `--epdf-ghost-opacity` wins over it. */
476
+ opacity: number;
477
+ }
478
+ /**
479
+ * One clickable link area on a page (page space): a standalone link
480
+ * annotation, or one segment of a parent's attached link. See
481
+ * {@link AnnotationHostCapability.listLinkItems}.
482
+ */
483
+ interface LinkNavItem {
484
+ /** Stable per-page key: the annot id, `#n`-suffixed for attached segments. */
485
+ id: string;
486
+ /** The clickable area in page space. */
487
+ bounds: Rect;
488
+ target: PdfLinkTarget;
489
+ /**
490
+ * True for a link child riding an editable annotation (an `/RT /Group`
491
+ * subordinate): a property of its parent while authoring, a nav behavior
492
+ * only while reading. The nav layer stands its anchors down for attached
493
+ * items whenever the active tool enables `annotation-edit`, so the parent
494
+ * stays selectable/movable; standalone document links navigate regardless.
495
+ */
496
+ attached: boolean;
497
+ /** The full payload-carrying `/A` tree, when one exists: the action
498
+ * engine's dispatch input. `target` remains its root projection. */
499
+ activate?: PdfActionTree;
500
+ /** The annotation ref, carried for ActionSource context. */
501
+ ref?: AnnotationRef;
502
+ /** Which `/AA` hover trees this link carries: the nav layer's pump flags
503
+ * (tree-less hover must cost zero dispatches). Links are behavior-inert
504
+ * to the annotation plane's hover feed while navigable, so their
505
+ * cursorEnter/cursorExit can only fire from the LinkLayer anchors. */
506
+ hoverEvents?: {
507
+ enter: boolean;
508
+ exit: boolean;
509
+ };
510
+ }
511
+ /**
512
+ * A plugin (forms, links) or an interactive renderer marks some annotations as
513
+ * interactive: while engaged, they render their own DOM, take the pointer and
514
+ * are not geometry-editable. Not engaged, they are edited like any other.
515
+ */
516
+ interface Behavior {
517
+ id: string;
518
+ /** Whether this behavior is about the annotation at all. */
519
+ matches(annotation: Annotation): boolean;
520
+ /** Whether it owns the annotation now (read live: the active tool, the app's mode). */
521
+ engaged(annotation: Annotation): boolean;
522
+ }
523
+ /**
524
+ * What a style panel shows: the {@link AnnotationProperty}s in display order,
525
+ * their current `values` by key, and which differ across the selection
526
+ * (`mixed`, shown as "mixed").
527
+ *
528
+ * For the selection, the properties are the ones every selected kind has (a
529
+ * mixed selection shows the shared ones, in the first kind's order), and the
530
+ * values the first member's; empty `properties` means nothing is selected. For
531
+ * a tool, they are its kind's, with its defaults over the engine's. The
532
+ * border's value is three keys (`borderStyle`, `dashArray`,
533
+ * `cloudyIntensity`); a text's font, size, colour and alignment read as the
534
+ * text shows (a free text's `fontColor` follows its `color` when it has none).
535
+ */
536
+ interface AnnotationProperties {
537
+ readonly properties: readonly AnnotationProperty[];
538
+ readonly values: FieldValues;
539
+ readonly mixed: readonly string[];
540
+ }
541
+ /**
542
+ * A free-text annotation projected for the framework: the box (page space,
543
+ * live gesture applied) + the plain text + an `editing` flag + a ready-to-spread
544
+ * CSS style. The framework renders one editable element from this and nothing
545
+ * more: all the mapping (fonts, colours, alignment) is done here, once. The
546
+ * element paints the text only: the box's fill and border are the vector
547
+ * scene's (`listPageItems`), the same for a plain box and a callout, so the
548
+ * live view matches the baked appearance.
549
+ */
550
+ interface TextItem {
551
+ id: string;
552
+ ref: AnnotationRef | null;
553
+ box: Rect;
554
+ contents: string;
555
+ /** The rich paragraphs the editor renders and edits (run deltas over the
556
+ * body, which `css` carries). `contents` is their plain projection. */
557
+ richText: {
558
+ paragraphs: RichTextParagraph[];
559
+ };
560
+ /** The face of its text without one of its own: the body's. */
561
+ face: {
562
+ family: string;
563
+ weight: number;
564
+ italic: boolean;
565
+ };
566
+ /**
567
+ * The font programs its text is drawn in (`css.fontFamily` and the runs'
568
+ * families name them): mount them where the box is drawn
569
+ * (`createFontMounts` in `@embedpdf/web`). Empty without the fonts plugin.
570
+ */
571
+ programs: readonly MountableFontProgram[];
572
+ editing: boolean;
573
+ /** Applied rotation (deg, CW). `box` is the unrotated text box; the framework
574
+ * rotates the editable element about its centre by this. 0/undefined = none. */
575
+ rot?: number;
576
+ css: {
577
+ fontFamily: string;
578
+ /** Content units (the framework multiplies by the page scale). The line
579
+ * height is not here: the editor binding states the engine's line model
580
+ * per face on the element itself (`@embedpdf/web`, `lineModelFor`). */
581
+ fontSize: number;
582
+ color: string;
583
+ /** The body's formatting (runs override it as inline spans). */
584
+ fontWeight: number;
585
+ fontStyle: 'normal' | 'italic';
586
+ textDecoration: 'none' | 'underline';
587
+ align: 'left' | 'center' | 'right';
588
+ padding: number;
589
+ };
590
+ }
591
+ /** What `comments.deleteThread()` did: everything went, or nothing did and `failed` says why. */
592
+ interface ThreadDeleteResult {
593
+ deleted: AnnotationRef[];
594
+ failed: Array<{
595
+ ref: AnnotationRef;
596
+ error: unknown;
597
+ }>;
598
+ }
599
+ /** The public shape of a tool: a named preset over a kind. */
600
+ interface AnnotationTool {
601
+ readonly id: string;
602
+ readonly subtype: KindName;
603
+ /** The defaults key this tool reads and writes. */
604
+ readonly preset: string;
605
+ readonly cursor: string;
606
+ readonly enables: readonly string[];
607
+ readonly defaults?: FieldValues;
608
+ /** The tool's ghost, what a click would place following the pointer: how opaque it paints, or `false`. */
609
+ readonly ghost: ResolvedGhost;
610
+ /** Your own data from the tool's definition, such as a label and an icon. */
611
+ readonly meta?: Readonly<Record<string, unknown>>;
612
+ }
613
+ /** A polygon or polyline being drawn: where it is, how many points it has, and whether it can end. */
614
+ type CreationDraft = CreationDraftAnchor;
615
+ /** A turn in progress: its page, the pointer there, and the angle so far (degrees clockwise). */
616
+ type AnnotationRotationAnchor = RotationAnchor;
617
+ /** Where a menu attaches to the selection: its page and the box around it (page space). */
618
+ interface AnnotationSelectionAnchor {
619
+ readonly page: PageRef;
620
+ readonly bounds: Rect;
621
+ /** The rotation handle's middle, so a menu can stay clear of it; absent without one. */
622
+ readonly rotationHandle?: Point$1;
623
+ }
624
+ /** Where UI attaches to one annotation: its page and the box around what it shows (page space). */
625
+ interface AnnotationAnchor {
626
+ readonly page: PageRef;
627
+ readonly bounds: Rect;
628
+ /**
629
+ * For an annotation that keeps its size or stays upright on screen (a note):
630
+ * the box in a given view, where `bounds` is the box at 100%. `<Anchored>`
631
+ * calls it, so the anchor doesn't change while people zoom. Absent for
632
+ * every other annotation.
633
+ */
634
+ readonly boundsIn?: (view: ViewEnv) => Rect | null;
635
+ }
636
+ /** An annotation was added: the engine's record, whoever added it. */
637
+ interface AnnotationCreatedEvent {
638
+ readonly annotation: Annotation;
639
+ readonly origin: EventOrigin;
640
+ }
641
+ /** An annotation was changed: the engine's record after the change. */
642
+ interface AnnotationUpdatedEvent {
643
+ readonly annotation: Annotation;
644
+ readonly origin: EventOrigin;
645
+ }
646
+ /** Annotations were deleted: one, and what went with it (its popup, replies and review states). */
647
+ interface AnnotationDeletedEvent {
648
+ /** Everything that went, the annotation first. */
649
+ readonly refs: readonly AnnotationRef[];
650
+ readonly page: PageRef;
651
+ readonly origin: EventOrigin;
652
+ }
653
+ /** The drawing order on a page changed: `order` is the page's annotations, bottom to top. */
654
+ interface AnnotationReorderedEvent {
655
+ readonly page: PageRef;
656
+ readonly order: readonly AnnotationRef[];
657
+ readonly origin: EventOrigin;
658
+ }
659
+ /** Annotations were read again (a document opening, a page re-read): not a list of creates. */
660
+ interface AnnotationResyncedEvent {
661
+ readonly pages: readonly PageRef[] | 'all';
662
+ }
663
+ /**
664
+ * The engine refused a change the user made (a revoked grant, a lock set
665
+ * elsewhere). The change is already gone from the view, which shows the
666
+ * engine's record again; this says why, so a UI can tell the user.
667
+ */
668
+ interface AnnotationWriteFailedEvent {
669
+ /** The existing annotations the refused write carried; empty for a refused create. */
670
+ readonly refs: readonly AnnotationRef[];
671
+ readonly error: PluginErrorInfo;
672
+ }
673
+ /** The selection changed. */
674
+ interface AnnotationSelectionChangedEvent {
675
+ readonly refs: readonly AnnotationRef[];
676
+ readonly previousRefs: readonly AnnotationRef[];
677
+ }
678
+ /** A polygon or polyline started, got a point, or ended. */
679
+ interface AnnotationDraftChangedEvent {
680
+ readonly draft: CreationDraft | null;
681
+ }
682
+ /** Typing in a text box started (`ref`) or ended (`null`). */
683
+ interface AnnotationEditingChangedEvent {
684
+ readonly ref: AnnotationRef | null;
685
+ }
686
+ /** The pointer moved onto an annotation (`ref`), or off it (`null`). */
687
+ interface AnnotationHoverChangedEvent {
688
+ readonly ref: AnnotationRef | null;
689
+ }
690
+ /** A tool's defaults changed, from your UI or your code. */
691
+ interface ToolDefaultsChangedEvent {
692
+ readonly toolId: string;
693
+ /** The tool's defaults now, as `tools.getDefaults(toolId)` returns them. */
694
+ readonly defaults: ToolDefaults;
695
+ }
696
+ /** A thread changed through this viewer. */
697
+ interface CommentThreadChangedEvent {
698
+ readonly rootRef: AnnotationRef;
699
+ readonly change: 'reply' | 'text' | 'status' | 'marked' | 'deleted';
700
+ }
701
+ /** Which annotations `list()` returns: every field narrows. */
702
+ interface AnnotationFilter {
703
+ /** Only these pages, as refs or indexes. */
704
+ readonly pages?: readonly (PageRef | number)[];
705
+ readonly subtype?: AnnotationSubtype;
706
+ }
707
+ /** What `import()` did: the new annotations, where each bundle ref went, and what was left out. */
708
+ interface AnnotationImportResult {
709
+ /** The new annotations, in bundle order. */
710
+ readonly annotations: readonly Annotation[];
711
+ /** Each imported annotation's ref in the bundle, and its new ref here. */
712
+ readonly refMap: ReadonlyArray<{
713
+ readonly from: AnnotationRef;
714
+ readonly to: AnnotationRef;
715
+ }>;
716
+ /** What was left out, and why, in bundle order. */
717
+ readonly dropped: readonly AnnotationImportDrop[];
718
+ }
719
+ /** Which annotations `export()` takes. */
720
+ interface AnnotationExportSelection {
721
+ /** These annotations, with what they point at and their replies. */
722
+ readonly refs?: readonly AnnotationRef[];
723
+ /** Every annotation on these pages, as refs or indexes. */
724
+ readonly pages?: readonly (PageRef | number)[];
725
+ }
726
+ /** The selection: what is selected, and the verbs that change it as one. */
727
+ interface AnnotationSelectionApi {
728
+ /** Select these annotations; an annotation in a group brings its group. */
729
+ set(refs: readonly AnnotationRef[]): void;
730
+ /** Add these annotations to the selection, with their groups. */
731
+ add(refs: readonly AnnotationRef[]): void;
732
+ /** Select everything that can be selected, on one page or in the whole document. */
733
+ selectAll(page?: PageRef | number): void;
734
+ /**
735
+ * Select everything a box on a page touches of what it paints (its lines,
736
+ * or the inside of a filled shape), with the rest of each one's group, as
737
+ * dragging on empty space does. Throws `not-found` for a page that isn't
738
+ * in the document.
739
+ */
740
+ selectInRect(page: PageRef | number, rect: Rect): void;
741
+ /** Clear the selection. */
742
+ clear(): void;
743
+ /** The selected annotations, as the user sees them. */
744
+ list(): readonly Annotation[];
745
+ /**
746
+ * Change the selected annotations: each takes the fields its kind has, and
747
+ * skips the rest. A function changes each relative to itself. While words
748
+ * are selected in a text box being typed in, its font, size, colour and
749
+ * formats change those words. Resolves once the engine wrote every change,
750
+ * with what it refused in `failed`.
751
+ */
752
+ update(changes: AnnotationPatch | ((annotation: Annotation) => AnnotationPatch), options?: OperationOptions): Promise<BatchResult<AnnotationRef, AnnotationRef>>;
753
+ /** Link the selected annotations to a page or a website, or remove their links with `null`. */
754
+ updateLink(target: PdfLinkTarget | null, options?: OperationOptions): Promise<BatchResult<AnnotationRef, AnnotationRef>>;
755
+ /** What a style panel shows for the selection. The same object while nothing changes. */
756
+ getProperties(): AnnotationProperties;
757
+ /** Delete every selected annotation. */
758
+ delete(options?: OperationOptions): Promise<BatchResult<AnnotationRef, AnnotationRef>>;
759
+ /** Turn the selection a quarter turn: `90` clockwise, `-90` the other way. */
760
+ rotateBy(degrees: 90 | -90, options?: OperationOptions): Promise<void>;
761
+ /** Turn the selection upright again. */
762
+ resetRotation(options?: OperationOptions): Promise<void>;
763
+ /** Make the selected annotations one group, saved the way Acrobat saves it. */
764
+ group(options?: OperationOptions): Promise<void>;
765
+ /** Split the selected groups up again. */
766
+ ungroup(options?: OperationOptions): Promise<void>;
767
+ /** Whether the selection can be grouped: two or more on one page, each changeable. */
768
+ canGroup(): boolean;
769
+ /** Whether the selection holds a group that can be split. */
770
+ canUngroup(): boolean;
771
+ /**
772
+ * Where a menu attaches: the selection's page and the box around it, or
773
+ * `null` with nothing selected, or while a gesture moves, resizes or turns it.
774
+ */
775
+ getAnchor(): AnnotationSelectionAnchor | null;
776
+ /** While the selection is being turned: the pointer's point and the angle so far, or `null`. */
777
+ getRotationAnchor(): AnnotationRotationAnchor | null;
778
+ }
779
+ /** A polygon or polyline being drawn, a click per point. */
780
+ interface AnnotationDraftApi {
781
+ /** The shape being drawn, or `null`. */
782
+ get(): CreationDraft | null;
783
+ /** End the shape and create it, as a double-click does. Resolves `null` when there was none to make. */
784
+ finish(options?: OperationOptions): Promise<{
785
+ annotation: Annotation;
786
+ } | null>;
787
+ /** Drop the shape being drawn. */
788
+ cancel(): void;
789
+ }
790
+ /** Typing in a text box. */
791
+ interface AnnotationTextApi {
792
+ /** Start typing in a text box, as a double-click does. */
793
+ begin(ref: AnnotationRef): void;
794
+ /** Stop typing, and save what was typed. */
795
+ end(options?: OperationOptions): Promise<void>;
796
+ /** The text box being typed in, or `null`. */
797
+ getEditing(): Annotation | null;
798
+ /** Bold, italic or underline on or off: for the selected words, or the whole of each selected box. */
799
+ toggleFormat(format: TextFormat, options?: OperationOptions): Promise<void>;
800
+ }
801
+ /** The tools: what a click or a drag creates, with which defaults. */
802
+ interface AnnotationToolsApi {
803
+ /** Every tool, the built-in ones and yours. */
804
+ list(): readonly AnnotationTool[];
805
+ /** One tool, or `null`. */
806
+ get(id: string): AnnotationTool | null;
807
+ /** Add a tool while the app runs, or replace the one with the same id. Returns a function that removes it. */
808
+ register(tool: AnnotationToolInput): Unsubscribe;
809
+ /** The fields a tool's next annotation starts with: its defaults over the engine's. The same object until they change. */
810
+ getDefaults(id: string): ToolDefaults;
811
+ /**
812
+ * Change a tool's defaults for the drawings that follow: each value whole,
813
+ * as in a patch. They stay in this viewer. Fires `onDefaultsChanged`.
814
+ */
815
+ updateDefaults(id: string, changes: FieldValues): void;
816
+ /** What a style panel for the tool shows, the same shape as `selection.getProperties()`. */
817
+ getProperties(id: string): AnnotationProperties;
818
+ /** A tool's defaults changed. */
819
+ readonly onDefaultsChanged: EventHook<ToolDefaultsChangedEvent>;
820
+ }
821
+ /** A stamp's bytes, to arm for a click or to place from code. */
822
+ interface StampInput {
823
+ /** PNG, JPEG, or one-page PDF bytes (`Blob | Uint8Array | BinaryPayload`). */
824
+ source: BinarySource;
825
+ /** Placed width in PDF points (height follows the picture). Default: the picture's own width. */
826
+ targetWidth?: number;
827
+ /** The placed annotation's `/Name`: the stamp identifier (standard or custom). */
828
+ name?: string;
829
+ /** The placed annotation's `/Subj`. */
830
+ subject?: string;
831
+ /**
832
+ * The hover ghost's image. Either fixed bytes (PNG/JPEG) or, for vector
833
+ * sources, which are only right at one size on screen, a
834
+ * {@link StampPreviewProvider} the ghost asks for a render at the device
835
+ * pixel width it shows at. Raster sources default to themselves; without
836
+ * one a PDF source shows no ghost.
837
+ */
838
+ preview?: BinarySource | StampPreviewProvider;
839
+ /**
840
+ * The source's own size in PDF points. Raster sources are measured from
841
+ * their header, but PDF bytes carry no size a sniff can read: a caller that
842
+ * knows it (a stamp library does) passes it here so placement keeps the
843
+ * picture's aspect.
844
+ */
845
+ intrinsicSize?: {
846
+ width: number;
847
+ height: number;
848
+ };
849
+ }
850
+ /** Where `stamps.place()` puts a stamp, without a click. */
851
+ interface StampPlacement {
852
+ /** The page, as a ref or an index. */
853
+ page: PageRef | number;
854
+ /** Where its middle goes, in page space. The size comes from the picture. */
855
+ center: Point$1;
856
+ /** Placed width in PDF points; default the picture's own (or the stamp's `targetWidth`). */
857
+ targetWidth?: number;
858
+ /** Its turn, degrees clockwise. Default 0. */
859
+ rotation?: number;
860
+ /** Select it, as placing it with a click would. Default false: code never changes the selection. */
861
+ select?: boolean;
862
+ }
863
+ /** Stamps placed from bytes: armed for the next click, or placed from code. */
864
+ interface AnnotationStampsApi {
865
+ /**
866
+ * Arm a stamp's bytes so the next click places them, as the `stamp` tool
867
+ * does after picking a file. Rejects `invalid-input` for bytes that aren't
868
+ * PNG, JPEG or a one-page PDF.
869
+ */
870
+ arm(stamp: StampInput, options?: OperationOptions): Promise<void>;
871
+ /** Disarm the stamp. */
872
+ disarm(): void;
873
+ /** Whether a stamp is armed. */
874
+ isArmed(): boolean;
875
+ /**
876
+ * Place a stamp's bytes with its middle on `center`, sized by its picture
877
+ * and kept on the page, as a click would. Resolves `{ annotation }`.
878
+ * Rejects `permission-denied` without `annotations:create`, `not-found` for
879
+ * a page that isn't in the document, `invalid-input` for bytes that aren't
880
+ * a picture.
881
+ */
882
+ place(stamp: StampInput, placement: StampPlacement, options?: OperationOptions): Promise<{
883
+ annotation: Annotation;
884
+ }>;
885
+ }
886
+ /** Links attached to annotations (a link child), or a link annotation's own target. */
887
+ interface AnnotationLinksApi {
888
+ /** Where an annotation links to, or `null`. */
889
+ get(ref: AnnotationRef): PdfLinkTarget | null;
890
+ /** Link an annotation to a page or a website. */
891
+ set(ref: AnnotationRef, target: PdfLinkTarget, options?: OperationOptions): Promise<void>;
892
+ /** Remove an annotation's link. */
893
+ clear(ref: AnnotationRef, options?: OperationOptions): Promise<void>;
894
+ }
895
+ /**
896
+ * Comments and replies: threads over the annotations. Every verb is a plain
897
+ * annotation create, change or delete, so other people's changes, this
898
+ * viewer's and reloads all show in `listThreads()`.
899
+ */
900
+ interface CommentsApi {
901
+ /** Every thread, in reading order: by page, then from the top of the page. */
902
+ listThreads(): readonly CommentThread[];
903
+ /** The thread a comment is in (its first comment, a reply or a review state), or `null`. */
904
+ getThread(ref: AnnotationRef): CommentThread | null;
905
+ /**
906
+ * Reply to the thread's first comment, whichever comment you pass.
907
+ * Resolves `{ annotation }`. Rejects `permission-denied` without
908
+ * `annotations:create`.
909
+ */
910
+ reply(ref: AnnotationRef, text: string, options?: OperationOptions): Promise<{
911
+ annotation: Annotation;
912
+ }>;
913
+ /** Change a comment's text. Rejects `permission-denied` when `canSetText(ref)` is false. */
914
+ setText(ref: AnnotationRef, text: string, options?: OperationOptions): Promise<void>;
915
+ /** Set the user's review state on a thread, such as `'accepted'`. */
916
+ setStatus(ref: AnnotationRef, state: string, options?: OperationOptions): Promise<void>;
917
+ /** Check a thread off for the user, or clear the check mark. */
918
+ setMarked(ref: AnnotationRef, marked: boolean, options?: OperationOptions): Promise<void>;
919
+ /** Delete a comment with its replies; the first comment of a thread deletes the thread. */
920
+ delete(ref: AnnotationRef, options?: OperationOptions): Promise<void>;
921
+ /** Delete a whole thread, all of it or none. */
922
+ deleteThread(ref: AnnotationRef, options?: OperationOptions): Promise<ThreadDeleteResult>;
923
+ /** Whether the user may reply to this thread (`annotations:create`). */
924
+ canReply(ref: AnnotationRef): boolean;
925
+ /** Whether the user may change this comment's text (`annotations:update`, and not `lockedContents`). */
926
+ canSetText(ref: AnnotationRef): boolean;
927
+ /** Whether the user may set a review state on this thread (`annotations:create`). */
928
+ canSetStatus(ref: AnnotationRef): boolean;
929
+ /** Whether the user may check this thread off (`annotations:create`). */
930
+ canSetMarked(ref: AnnotationRef): boolean;
931
+ /**
932
+ * Whether the user may delete this comment with its replies (`annotations:delete`): the
933
+ * comment unlocked, and every reply too.
934
+ */
935
+ canDelete(ref: AnnotationRef): boolean;
936
+ /** Whether the user may delete this thread: `canDelete()` of its first comment. */
937
+ canDeleteThread(ref: AnnotationRef): boolean;
938
+ /** A thread changed through this viewer: a reply, a text, a review state, a check mark or a delete. */
939
+ readonly onThreadChanged: EventHook<CommentThreadChangedEvent>;
940
+ }
941
+ /**
942
+ * The annotation API: the documented, stable surface for application code.
943
+ * Resolve it with the token re-exported from the package root
944
+ * (`@embedpdf/plugin-annotation`). Framework-only plumbing lives on
945
+ * {@link AnnotationHostCapability} in `@embedpdf/plugin-annotation/contract/host`.
946
+ */
947
+ interface AnnotationCapability extends SettingsApi<AnnotationSettings> {
948
+ /**
949
+ * The annotation as the user sees it: the engine's record with any change
950
+ * the user made applied, as the engine will apply it. A new annotation shows
951
+ * before the engine confirms it, under the `nm` ref it was created with.
952
+ */
953
+ get(ref: AnnotationRef): Annotation | null;
954
+ /** Every annotation in drawing order, or the ones on some pages or of one kind. */
955
+ list(filter?: AnnotationFilter): readonly Annotation[];
956
+ /**
957
+ * The topmost annotation at a point on a page, or `null`. A selected
958
+ * annotation's handles count as the annotation. A page that isn't in the
959
+ * document has none.
960
+ */
961
+ getAt(page: PageRef | number, point: Point$1): Annotation | null;
962
+ /** Whether a change the user made to it waits for the engine. */
963
+ isPending(ref: AnnotationRef): boolean;
964
+ /** `loading` until the document's annotations are in, then `ready`; `forbidden` or `error` when they can't load. */
965
+ getStatus(): ResourceStatus;
966
+ /** The annotation under the pointer, or `null`. */
967
+ getHovered(): Annotation | null;
968
+ /** Read every annotation from the engine again. */
969
+ refresh(options?: OperationOptions): Promise<void>;
970
+ /**
971
+ * Create an annotation from its kind and fields: what they leave out takes
972
+ * the `tool`'s defaults when one is named, then the engine's. Bytes travel
973
+ * beside them (a stamp's `appearance`, a file attachment's `file`). It
974
+ * shows at once; resolves `{ annotation }` with the engine's record.
975
+ * `select` selects it, as drawing it would; without it, code never changes
976
+ * the selection. A read of another annotation makes the same one again (a
977
+ * copy): its own fields are written, and where it is comes from `page`.
978
+ * Rejects `permission-denied` without `annotations:create`, `not-found` for
979
+ * a page that isn't in the document or an unknown `tool`, `invalid-input`
980
+ * for a kind the engine doesn't know or a value a write can't make (another
981
+ * app's beveled border).
982
+ */
983
+ create(page: PageRef | number, draft: AnnotationDraft | Annotation, resources?: AnnotationResources, options?: OperationOptions & {
984
+ tool?: string;
985
+ select?: boolean;
986
+ }): Promise<{
987
+ annotation: Annotation;
988
+ }>;
989
+ /**
990
+ * What a text tool makes of the selected text, one annotation per page: a
991
+ * highlight, underline, strikeout or squiggly line, an insertion caret, a
992
+ * replacement or a redaction mark. Resolves `{ annotations }` (empty
993
+ * without a text selection). The text selection is cleared afterwards
994
+ * unless `clear` is `false`. Rejects `permission-denied` without
995
+ * `annotations:create`, `not-found` for a tool that makes nothing of
996
+ * selected text.
997
+ */
998
+ createFromSelection(tool: string, options?: OperationOptions & {
999
+ clear?: boolean;
1000
+ }): Promise<{
1001
+ annotations: readonly Annotation[];
1002
+ }>;
1003
+ /**
1004
+ * Change the fields the patch names, as given: the engine works out what
1005
+ * follows (a free text's body from its font, a measurement's label from its
1006
+ * points, a drawn kind's shape from a new `rect`). New bytes replace what
1007
+ * they are for. It shows at once; resolves `{ annotation }` with the
1008
+ * engine's record. Rejects `not-found` for an annotation that isn't here.
1009
+ */
1010
+ update(ref: AnnotationRef, patch: AnnotationPatch, resources?: AnnotationResources, options?: OperationOptions): Promise<{
1011
+ annotation: Annotation;
1012
+ }>;
1013
+ /** Delete an annotation, with its popup and its replies. Fires `onDeleted`. */
1014
+ delete(ref: AnnotationRef, options?: OperationOptions): Promise<void>;
1015
+ /**
1016
+ * Change the drawing order on one page: the annotations go together, in
1017
+ * the order given, right after or before a neighbour annotation of the page
1018
+ * (`{ after: ref }`, `{ before: ref }`), or to the bottom (`'start'`) or the
1019
+ * top (`'end'`). Shows at once; fires `onReordered`. Rejects `invalid-input`
1020
+ * for refs on different pages and `not-found` for a neighbour that isn't
1021
+ * there. Widgets paint above every annotation and are ordered by the form.
1022
+ */
1023
+ reorder(refs: readonly AnnotationRef[], position: AnnotationPosition, options?: OperationOptions): Promise<void>;
1024
+ /**
1025
+ * Take annotations out as a bundle, with the bytes they carry (a stamp's
1026
+ * drawing, an attached file): every annotation, a selection of them (with
1027
+ * what they point at and their replies), or some pages'. Waits for pending
1028
+ * changes first. Rejects `permission-denied` without `doc.download`.
1029
+ */
1030
+ export(selection?: AnnotationExportSelection, options?: OperationOptions): Promise<AnnotationBundle>;
1031
+ /**
1032
+ * Put a bundle's annotations into this document, as one change: they show
1033
+ * once it's done. Resolves `{ annotations, refMap, dropped }`. Rejects
1034
+ * `permission-denied` without `annotations:create` (and, for the default
1035
+ * `attribution: 'restore'`, `doc.annotate.import`).
1036
+ */
1037
+ import(bundle: AnnotationBundle, options?: AnnotationImportOptions & OperationOptions): Promise<AnnotationImportResult>;
1038
+ /**
1039
+ * Download a stamp's drawing (`'appearance'`) or an attachment's file
1040
+ * (`'file'`): the bytes `create()` takes to make it again. Rejects
1041
+ * `permission-denied` without `doc.download`, `not-found` for an annotation
1042
+ * that isn't here, `invalid-input` for a role its kind doesn't have.
1043
+ */
1044
+ downloadResource(ref: AnnotationRef, role: AnnotationResourceRole, options?: OperationOptions): Promise<Uint8Array>;
1045
+ readonly links: AnnotationLinksApi;
1046
+ readonly selection: AnnotationSelectionApi;
1047
+ readonly draft: AnnotationDraftApi;
1048
+ readonly text: AnnotationTextApi;
1049
+ readonly tools: AnnotationToolsApi;
1050
+ readonly stamps: AnnotationStampsApi;
1051
+ readonly comments: CommentsApi;
1052
+ /**
1053
+ * Set the function that gives the `stamp` and `attachment` tools their
1054
+ * file, `null` to make them do nothing. Returns a function that removes it.
1055
+ */
1056
+ setFilePickerProvider(provider: FilePickerProvider | null): Unsubscribe;
1057
+ /** Whether the user may see annotations (`doc.annotate.read`). */
1058
+ canRead(): boolean;
1059
+ /** Whether the user may create annotations (`annotations:create`). */
1060
+ canCreate(): boolean;
1061
+ /** Whether the user may change this annotation: its permission and its own `locked` flag. */
1062
+ canUpdate(ref: AnnotationRef): boolean;
1063
+ /**
1064
+ * Whether the user may delete this annotation, and with it its replies, review states and
1065
+ * popups: the permission for each of them and their `locked` flags.
1066
+ */
1067
+ canDelete(ref: AnnotationRef): boolean;
1068
+ /**
1069
+ * Whether the `editable` setting lets people change this annotation by
1070
+ * hand; `false` for one the document doesn't have. Whether a change would
1071
+ * succeed is `canUpdate()` and `canDelete()`.
1072
+ */
1073
+ isEditable(ref: AnnotationRef): boolean;
1074
+ /** Stop a drag, or a polygon in progress. */
1075
+ cancel(): void;
1076
+ /** An annotation was added, once the engine saved it. */
1077
+ readonly onCreated: EventHook<AnnotationCreatedEvent>;
1078
+ /** An annotation was changed, once the engine saved it. */
1079
+ readonly onUpdated: EventHook<AnnotationUpdatedEvent>;
1080
+ /** Annotations were deleted: one, plus its popup and replies. */
1081
+ readonly onDeleted: EventHook<AnnotationDeletedEvent>;
1082
+ /** The drawing order on a page changed. */
1083
+ readonly onReordered: EventHook<AnnotationReorderedEvent>;
1084
+ /** Annotations were read again, as after loading a document. */
1085
+ readonly onResynced: EventHook<AnnotationResyncedEvent>;
1086
+ /** The engine refused a change the user made; the view already shows the engine's record again. */
1087
+ readonly onWriteFailed: EventHook<AnnotationWriteFailedEvent>;
1088
+ /** The selection changed. */
1089
+ readonly onSelectionChanged: EventHook<AnnotationSelectionChangedEvent>;
1090
+ /** A polygon or polyline is being drawn, or ended. */
1091
+ readonly onDraftChanged: EventHook<AnnotationDraftChangedEvent>;
1092
+ /** Typing in a text box started or ended. */
1093
+ readonly onEditingChanged: EventHook<AnnotationEditingChangedEvent>;
1094
+ /** The pointer moved onto an annotation, or off it. */
1095
+ readonly onHoverChanged: EventHook<AnnotationHoverChangedEvent>;
1096
+ }
1097
+ type MarkupSubtype = 'highlight' | 'underline' | 'strikeout' | 'squiggly';
1098
+ /** The armed stamp: its placement size and identity. */
1099
+ interface ArmedStampInfo {
1100
+ /** Placement size in PDF points. */
1101
+ readonly width: number;
1102
+ readonly height: number;
1103
+ readonly name?: string;
1104
+ readonly subject?: string;
1105
+ }
1106
+ /** The armed stamp's paintable preview, for the render layer's ghost `<img>`. */
1107
+ interface ArmedStampPreview {
1108
+ bytes: Uint8Array;
1109
+ mimeType?: string;
1110
+ }
1111
+ /**
1112
+ * Resolution-aware ghost preview: "give me this stamp at `devicePixelWidth`
1113
+ * pixels wide". The annotation plugin buckets the request (see
1114
+ * `previewBucket`) and caches per bucket for the arm's lifetime, so a zoom
1115
+ * gesture never renders per frame and one render serves a zoom range. A stamp
1116
+ * library renders its page lazily through its asset engine; a raster returns
1117
+ * itself (it cannot get sharper than its pixels).
1118
+ */
1119
+ type StampPreviewProvider = (devicePixelWidth: number) => Promise<ArmedStampPreview | null>;
1120
+ /**
1121
+ * What the {@link FilePickerProvider} is asked for: which tool clicked (id +
1122
+ * the kind it creates), the tool's `accept` filter, and the page-space point
1123
+ * the click landed on: enough to route per tool (asset library for stamps,
1124
+ * cloud drive for attachments) or position a picker near the click. Plain
1125
+ * data: the request crosses the plugin↔adapter boundary as a message.
1126
+ */
1127
+ interface FilePromptRequest {
1128
+ toolId: string;
1129
+ /** The kind the placement creates: the routing key for per-tool pickers. */
1130
+ subtype: KindName;
1131
+ /** The tool's file-dialog filter hint (from the tool def). UX only:
1132
+ * the engine sniffs and validates the bytes. */
1133
+ accept?: string;
1134
+ page: PageRef;
1135
+ /** The page-space point the placement is centred on. */
1136
+ point: Point$1;
1137
+ }
1138
+ /**
1139
+ * The one environment port behind every click-then-pick tool (the stamp
1140
+ * `'prompt'` source and the file-attachment tool, whose file is picked after
1141
+ * the spot): given a click, produce the file to place, `null` to cancel. The
1142
+ * plugin declares this contract but never implements it: a file dialog is a
1143
+ * DOM concern, so the framework adapter installs the implementation via
1144
+ * {@link AnnotationCapability.setFilePickerProvider}. The return shape is the
1145
+ * engine's file vocabulary: a stamp takes only `data`; an attachment embeds
1146
+ * the whole thing. A picked `File` carries its own name and type; a provider
1147
+ * returning raw bytes for an attachment must supply `name` itself.
1148
+ */
1149
+ type FilePickerProvider = (request: FilePromptRequest) => Promise<AttachmentFileSource | null>;
1150
+ //#endregion
1151
+ export { Color as $, AnnotationResources$1 as A, AnnotationState as At, AnnotationTool as B, ResolvedGhost as Bt, AnnotationPatch$1 as C, StampPlacement as Ct, AnnotationRef$1 as D, ThreadDeleteResult as Dt, AnnotationProperty$1 as E, TextItem as Et, AnnotationSelectionChangedEvent as F, AnnotationToolInput as Ft, ArmedStampInfo as G, ToolDefaultsFor as Gt, AnnotationTransfer as H, SelectionAuthoring as Ht, AnnotationSettings as I, DEFAULT_TOOLS as It, AttachmentFileSource$1 as J, TextSelection as Jt, ArmedStampPreview as K, Face as Kt, AnnotationStampsApi as L, GhostPolicy as Lt, AnnotationRotationAnchor as M, AnnotationToken as Mt, AnnotationSelectionAnchor as N, ARMED_STAMP_TOOL_ID as Nt, AnnotationReorderedEvent as O, ToolDefaults as Ot, AnnotationSelectionApi as P, AnnotationToolDef as Pt, ClickCreate$1 as Q, AnnotationSubtype$1 as R, InkAuthoringOptions as Rt, AnnotationOption as S, StampInput as St, AnnotationProperties as T, TextAlign as Tt, AnnotationUpdatedEvent as U, StampSourceSpec as Ut, AnnotationToolsApi as V, ResolvedTool as Vt, AnnotationWriteFailedEvent as W, ToolAuthoringKind as Wt, BlendMode as X, Behavior as Y, ChromeSettings as Z, AnnotationHoverChangedEvent as _, MarkupSubtype as _t, AnnotationBundle$1 as a, EditableKind as at, AnnotationImportResult as b, ReviewStatus as bt, AnnotationCreatedEvent as c, FilePickerProvider as ct, AnnotationDraftApi as d, HandleRole as dt, CommentThread$1 as et, AnnotationDraftChangedEvent as f, ImageGhost as ft, AnnotationFlags$1 as g, LinkNavItem as gt, AnnotationFilter as h, LineStyle as ht, AnnotationAnchor as i, CreationDraft as it, AnnotationResyncedEvent as j, annotationState as jt, AnnotationResourceRole$1 as k, ToolDefaultsChangedEvent as kt, AnnotationDeletedEvent as l, FilePromptRequest as lt, AnnotationExportSelection as m, LineEndings as mt, AfterCreateSettings as n, CommentThreadReview as nt, AnnotationCapability as o, EditableKinds$1 as ot, AnnotationEditingChangedEvent as p, LineEnding as pt, AttachmentContent as q, TextFormat as qt, Annotation$1 as r, CommentsApi as rt, AnnotationConfig as s, FieldValues$1 as st, ANNOTATION_DEFAULTS as t, CommentThreadChangedEvent as tt, AnnotationDraft$1 as u, FlagKey as ut, AnnotationImportDrop$1 as v, MeasurementIntent as vt, AnnotationPosition$1 as w, StampPreviewProvider as wt, AnnotationLinksApi as x, SnapSettings$1 as xt, AnnotationImportOptions$1 as y, PdfLinkTarget$1 as yt, AnnotationTextApi as z, PromptSourceSpec as zt };
1152
+ //# sourceMappingURL=contract-QAvnfm2b.d.ts.map