@embedpdf/plugin-annotation 3.0.0-next.1 → 3.0.0-next.11

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 (43) hide show
  1. package/dist/authoring-BhtyfsMx.d.cts +37 -0
  2. package/dist/authoring-R4ezdnXd.d.ts +37 -0
  3. package/dist/authoring.cjs +16 -0
  4. package/dist/authoring.d.cts +2 -0
  5. package/dist/authoring.d.ts +2 -0
  6. package/dist/authoring.js +3 -0
  7. package/dist/{capability-hb2AU0f6.cjs → capability-Csb9WMm-.cjs} +816 -482
  8. package/dist/capability-Csb9WMm-.cjs.map +1 -0
  9. package/dist/{capability-fghl0JmE.js → capability-DBsr2D-L.js} +772 -420
  10. package/dist/capability-DBsr2D-L.js.map +1 -0
  11. package/dist/contract/host.cjs +3 -0
  12. package/dist/contract/host.d.cts +2 -0
  13. package/dist/contract/host.d.ts +2 -0
  14. package/dist/contract/host.js +2 -0
  15. package/dist/contract.cjs +8 -0
  16. package/dist/contract.cjs.map +1 -0
  17. package/dist/contract.d.cts +10 -0
  18. package/dist/contract.d.ts +10 -0
  19. package/dist/contract.js +8 -0
  20. package/dist/contract.js.map +1 -0
  21. package/dist/index.cjs +104 -104
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +5 -47
  24. package/dist/index.d.ts +5 -47
  25. package/dist/index.js +96 -96
  26. package/dist/index.js.map +1 -1
  27. package/dist/internal.cjs +4 -2
  28. package/dist/internal.d.cts +2 -1
  29. package/dist/internal.d.ts +2 -1
  30. package/dist/internal.js +3 -1
  31. package/dist/seam-6pJeKOOJ.cjs +296 -0
  32. package/dist/seam-6pJeKOOJ.cjs.map +1 -0
  33. package/dist/seam-C4L_7rDt.js +225 -0
  34. package/dist/seam-C4L_7rDt.js.map +1 -0
  35. package/dist/types-CwytT-TI.js +13 -0
  36. package/dist/types-CwytT-TI.js.map +1 -0
  37. package/dist/types-DimcLIic.cjs +17 -0
  38. package/dist/types-DimcLIic.cjs.map +1 -0
  39. package/dist/{types-Da6JRmhw.d.ts → types-eLTpocXz.d.cts} +232 -25
  40. package/dist/{types-BhWgqgbX.d.cts → types-otwv-Cdl.d.ts} +232 -25
  41. package/package.json +21 -7
  42. package/dist/capability-fghl0JmE.js.map +0 -1
  43. package/dist/capability-hb2AU0f6.cjs.map +0 -1
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- import { C as PromptSourceSpec, D as ToolAuthoringKind, E as StampSourceSpec, O as ToolDefaultsFor, S as InkAuthoringOptions, T as SelectionAuthoring, _ as ToolGhost, a as AnnotationState, b as DEFAULT_TOOLS, c as ChromeSettings, d as FilePromptRequest, f as LinkNavItem, g as TextItem, h as StampToolInput, i as AnnotationHostCapability, l as ChromeSettingsPatch, m as SelectionProps, n as AnnotationCapability, p as SelectionFlags, r as AnnotationConfig, s as Behavior, t as AnnotationAction, u as FilePickerProvider, v as AnnotationToolDef, w as ResolvedTool, x as GhostPolicy, y as AnnotationToolInput } from "./types-BhWgqgbX.cjs";
2
- import { CapabilityToken } from "@embedpdf/core";
3
- import { AnnotationDTO, AnnotationDraft, AnnotationPatch, AnnotationRef, PdfLinkTarget, PdfRect, WidgetAppearance } from "@embedpdf/engine-core/runtime";
4
- import { Annot, AnnotationFlags, AnnotationProps, AnnotationPropsPatch, AnnotationPropsPatch as AnnotationPropsPatch$1, BlendMode, Border, ClickCreate, ClickPlacement, Geom, LineEnding, LineEndings, MIN_DRAG, PropKey, PropKey as PropKey$1, PropSpec, Rect, SnapSettings, Style, TextAlign, propsFor, resolveClickPlacement } from "@embedpdf/core-annotation";
1
+ import { a as toCreateDraft, c as styleFromDTO, i as fromDTO, l as widgetAppearanceFromProps, o as toPatch, s as refKey } from "./authoring-BhtyfsMx.cjs";
2
+ import { A as StampSourceSpec, C as AnnotationToolInput, D as PromptSourceSpec, E as InkAuthoringOptions, M as ToolDefaultsFor, O as ResolvedTool, S as AnnotationToolDef, T as GhostPolicy, _ as SelectionProps, a as AnnotationHydration, b as ThreadDeleteResult, c as Behavior, d as CommentPermissions, f as CommentsApi, g as SelectionFlags, h as LinkNavItem, i as AnnotationHostCapability, j as ToolAuthoringKind, k as SelectionAuthoring, l as ChromeSettings, m as FilePromptRequest, n as AnnotationCapability, o as AnnotationState, p as FilePickerProvider, r as AnnotationConfig, t as AnnotationAction, u as ChromeSettingsPatch, v as StampToolInput, w as DEFAULT_TOOLS, x as ToolGhost, y as TextItem } from "./types-eLTpocXz.cjs";
3
+ import { AnnotationDTO, AnnotationFlags, AnnotationProps, AnnotationPropsPatch, AnnotationRef, AnnotationSubtype, AnnotationToken, BlendMode, Border, ClickCreate, Color, CommentThread, CommentThreadReview, LineEnding, LineEndings, PropKey, PropSpec, ReviewStatus, SnapSettings, TextAlign } from "./contract.cjs";
4
+ import { ClickPlacement, MIN_DRAG, propsFor, resolveClickPlacement } from "@embedpdf/core-annotation";
5
5
  //#region src/annotation.plugin.d.ts
6
6
  /**
7
7
  * The annotation plugin. Document-scoped; requires the interaction hub and
@@ -10,39 +10,6 @@ import { Annot, AnnotationFlags, AnnotationProps, AnnotationPropsPatch, Annotati
10
10
  */
11
11
  declare const annotationPlugin: (config?: AnnotationConfig) => import("@embedpdf/core").PluginDef<AnnotationState, AnnotationAction, AnnotationHostCapability>;
12
12
  //#endregion
13
- //#region src/repository/seam.d.ts
14
- declare function refKey(ref: AnnotationRef): string;
15
- /** Engine DTO → content-space `Style` (CSS colours, `Border` union). Exported so
16
- * selection-aware UIs can read display values straight off a {@link AnnotationDTO}
17
- * without re-deriving the colour/border mapping. */
18
- declare function styleFromDTO(dto: AnnotationDTO): Style;
19
- /**
20
- * The flat props vocabulary (CSS colours, house keys) → the engine's widget
21
- * appearance for `doc.forms` authoring — the SAME mapping the widget patch
22
- * lowering uses, exported as a boundary utility so the form plugin can style
23
- * `placeField` from a tool's `currentDefaults` without growing a second CSS
24
- * parser. Absent keys stay absent (the engine writes nothing for them).
25
- */
26
- declare function widgetAppearanceFromProps(props: AnnotationPropsPatch$1): WidgetAppearance;
27
- //#endregion
28
- //#region src/repository/index.d.ts
29
- /**
30
- * Engine DTO → content-space Annot. `source` decides how it renders: `'baked'`
31
- * shows the engine's appearance raster (a page load, or a remote edit — trust
32
- * the authored AP); `'vector'` renders live from geom/style (we authored or
33
- * changed it). `apBox` is the raster's content-space box, used while baked.
34
- */
35
- declare function fromDTO(dto: AnnotationDTO, crop: PdfRect, source?: 'baked' | 'vector'): Annot;
36
- /** Content Annot → the FULL engine patch: the kind's geometry group plus every
37
- * prop it declares editable. The reference statement — scoped emission and
38
- * drafts both build on it. */
39
- declare function toPatch(a: Annot, crop: PdfRect): AnnotationPatch | null;
40
- /** Content Annot → engine create draft: the full statement plus the kind's
41
- * create-only extras, with the model's `/F` emitted verbatim, once, for every
42
- * kind (a fresh draw carries DRAWN_FLAGS plus any tool seed). `null` for the
43
- * kinds whose creates travel their own path (stamps, widgets, icon place). */
44
- declare function toCreateDraft(a: Annot, crop: PdfRect): AnnotationDraft | null;
45
- //#endregion
46
13
  //#region src/reducer.d.ts
47
14
  /**
48
15
  * Out-of-the-box selection chrome — a sensible document-annotation feel. Every
@@ -52,14 +19,5 @@ declare function toCreateDraft(a: Annot, crop: PdfRect): AnnotationDraft | null;
52
19
  */
53
20
  declare const DEFAULT_CHROME: ChromeSettings;
54
21
  //#endregion
55
- //#region src/index.d.ts
56
- /**
57
- * App-facing annotation token: resolves the public {@link AnnotationCapability}.
58
- * It is the SAME runtime token the plugin provides, narrowed to the public lens —
59
- * the framework-only surface (render projection, pointer gestures, behavior
60
- * registration) is reachable only via `@embedpdf/plugin-annotation/internal`.
61
- */
62
- declare const AnnotationToken: CapabilityToken<AnnotationCapability>;
63
- //#endregion
64
- export { type AnnotationAction, type AnnotationCapability, type AnnotationConfig, type AnnotationFlags, type AnnotationProps, type AnnotationPropsPatch, type AnnotationState, AnnotationToken, type AnnotationToolDef, type AnnotationToolInput, type Behavior, type BlendMode, type Border, type ChromeSettings, type ChromeSettingsPatch, type ClickCreate, type ClickPlacement, DEFAULT_CHROME, DEFAULT_TOOLS, type FilePickerProvider, type FilePromptRequest, type GhostPolicy, type InkAuthoringOptions, type LineEnding, type LineEndings, type LinkNavItem, MIN_DRAG, type PromptSourceSpec, type PropKey, type PropSpec, type ResolvedTool, type SelectionAuthoring, type SelectionFlags, type SelectionProps, type SnapSettings, type StampSourceSpec, type StampToolInput, type TextAlign, type TextItem, type ToolAuthoringKind, type ToolDefaultsFor, type ToolGhost, annotationPlugin, fromDTO, propsFor, refKey, resolveClickPlacement, styleFromDTO, toCreateDraft, toPatch, widgetAppearanceFromProps };
22
+ export { type AnnotationAction, type AnnotationCapability, type AnnotationConfig, type AnnotationDTO, type AnnotationFlags, type AnnotationHydration, type AnnotationProps, type AnnotationPropsPatch, type AnnotationRef, type AnnotationState, type AnnotationSubtype, AnnotationToken, type AnnotationToolDef, type AnnotationToolInput, type Behavior, type BlendMode, type Border, type ChromeSettings, type ChromeSettingsPatch, type ClickCreate, type ClickPlacement, type Color, type CommentPermissions, type CommentThread, type CommentThreadReview, type CommentsApi, DEFAULT_CHROME, DEFAULT_TOOLS, type FilePickerProvider, type FilePromptRequest, type GhostPolicy, type InkAuthoringOptions, type LineEnding, type LineEndings, type LinkNavItem, MIN_DRAG, type PromptSourceSpec, type PropKey, type PropSpec, type ResolvedTool, type ReviewStatus, type SelectionAuthoring, type SelectionFlags, type SelectionProps, type SnapSettings, type StampSourceSpec, type StampToolInput, type TextAlign, type TextItem, type ThreadDeleteResult, type ToolAuthoringKind, type ToolDefaultsFor, type ToolGhost, annotationPlugin, fromDTO, propsFor, refKey, resolveClickPlacement, styleFromDTO, toCreateDraft, toPatch, widgetAppearanceFromProps };
65
23
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { C as PromptSourceSpec, D as ToolAuthoringKind, E as StampSourceSpec, O as ToolDefaultsFor, S as InkAuthoringOptions, T as SelectionAuthoring, _ as ToolGhost, a as AnnotationState, b as DEFAULT_TOOLS, c as ChromeSettings, d as FilePromptRequest, f as LinkNavItem, g as TextItem, h as StampToolInput, i as AnnotationHostCapability, l as ChromeSettingsPatch, m as SelectionProps, n as AnnotationCapability, p as SelectionFlags, r as AnnotationConfig, s as Behavior, t as AnnotationAction, u as FilePickerProvider, v as AnnotationToolDef, w as ResolvedTool, x as GhostPolicy, y as AnnotationToolInput } from "./types-Da6JRmhw.js";
2
- import { CapabilityToken } from "@embedpdf/core";
3
- import { AnnotationDTO, AnnotationDraft, AnnotationPatch, AnnotationRef, PdfLinkTarget, PdfRect, WidgetAppearance } from "@embedpdf/engine-core/runtime";
4
- import { Annot, AnnotationFlags, AnnotationProps, AnnotationPropsPatch, AnnotationPropsPatch as AnnotationPropsPatch$1, BlendMode, Border, ClickCreate, ClickPlacement, Geom, LineEnding, LineEndings, MIN_DRAG, PropKey, PropKey as PropKey$1, PropSpec, Rect, SnapSettings, Style, TextAlign, propsFor, resolveClickPlacement } from "@embedpdf/core-annotation";
1
+ import { a as toCreateDraft, c as styleFromDTO, i as fromDTO, l as widgetAppearanceFromProps, o as toPatch, s as refKey } from "./authoring-R4ezdnXd.js";
2
+ import { A as StampSourceSpec, C as AnnotationToolInput, D as PromptSourceSpec, E as InkAuthoringOptions, M as ToolDefaultsFor, O as ResolvedTool, S as AnnotationToolDef, T as GhostPolicy, _ as SelectionProps, a as AnnotationHydration, b as ThreadDeleteResult, c as Behavior, d as CommentPermissions, f as CommentsApi, g as SelectionFlags, h as LinkNavItem, i as AnnotationHostCapability, j as ToolAuthoringKind, k as SelectionAuthoring, l as ChromeSettings, m as FilePromptRequest, n as AnnotationCapability, o as AnnotationState, p as FilePickerProvider, r as AnnotationConfig, t as AnnotationAction, u as ChromeSettingsPatch, v as StampToolInput, w as DEFAULT_TOOLS, x as ToolGhost, y as TextItem } from "./types-otwv-Cdl.js";
3
+ import { AnnotationDTO, AnnotationFlags, AnnotationProps, AnnotationPropsPatch, AnnotationRef, AnnotationSubtype, AnnotationToken, BlendMode, Border, ClickCreate, Color, CommentThread, CommentThreadReview, LineEnding, LineEndings, PropKey, PropSpec, ReviewStatus, SnapSettings, TextAlign } from "./contract.js";
4
+ import { ClickPlacement, MIN_DRAG, propsFor, resolveClickPlacement } from "@embedpdf/core-annotation";
5
5
  //#region src/annotation.plugin.d.ts
6
6
  /**
7
7
  * The annotation plugin. Document-scoped; requires the interaction hub and
@@ -10,39 +10,6 @@ import { Annot, AnnotationFlags, AnnotationProps, AnnotationPropsPatch, Annotati
10
10
  */
11
11
  declare const annotationPlugin: (config?: AnnotationConfig) => import("@embedpdf/core").PluginDef<AnnotationState, AnnotationAction, AnnotationHostCapability>;
12
12
  //#endregion
13
- //#region src/repository/seam.d.ts
14
- declare function refKey(ref: AnnotationRef): string;
15
- /** Engine DTO → content-space `Style` (CSS colours, `Border` union). Exported so
16
- * selection-aware UIs can read display values straight off a {@link AnnotationDTO}
17
- * without re-deriving the colour/border mapping. */
18
- declare function styleFromDTO(dto: AnnotationDTO): Style;
19
- /**
20
- * The flat props vocabulary (CSS colours, house keys) → the engine's widget
21
- * appearance for `doc.forms` authoring — the SAME mapping the widget patch
22
- * lowering uses, exported as a boundary utility so the form plugin can style
23
- * `placeField` from a tool's `currentDefaults` without growing a second CSS
24
- * parser. Absent keys stay absent (the engine writes nothing for them).
25
- */
26
- declare function widgetAppearanceFromProps(props: AnnotationPropsPatch$1): WidgetAppearance;
27
- //#endregion
28
- //#region src/repository/index.d.ts
29
- /**
30
- * Engine DTO → content-space Annot. `source` decides how it renders: `'baked'`
31
- * shows the engine's appearance raster (a page load, or a remote edit — trust
32
- * the authored AP); `'vector'` renders live from geom/style (we authored or
33
- * changed it). `apBox` is the raster's content-space box, used while baked.
34
- */
35
- declare function fromDTO(dto: AnnotationDTO, crop: PdfRect, source?: 'baked' | 'vector'): Annot;
36
- /** Content Annot → the FULL engine patch: the kind's geometry group plus every
37
- * prop it declares editable. The reference statement — scoped emission and
38
- * drafts both build on it. */
39
- declare function toPatch(a: Annot, crop: PdfRect): AnnotationPatch | null;
40
- /** Content Annot → engine create draft: the full statement plus the kind's
41
- * create-only extras, with the model's `/F` emitted verbatim, once, for every
42
- * kind (a fresh draw carries DRAWN_FLAGS plus any tool seed). `null` for the
43
- * kinds whose creates travel their own path (stamps, widgets, icon place). */
44
- declare function toCreateDraft(a: Annot, crop: PdfRect): AnnotationDraft | null;
45
- //#endregion
46
13
  //#region src/reducer.d.ts
47
14
  /**
48
15
  * Out-of-the-box selection chrome — a sensible document-annotation feel. Every
@@ -52,14 +19,5 @@ declare function toCreateDraft(a: Annot, crop: PdfRect): AnnotationDraft | null;
52
19
  */
53
20
  declare const DEFAULT_CHROME: ChromeSettings;
54
21
  //#endregion
55
- //#region src/index.d.ts
56
- /**
57
- * App-facing annotation token: resolves the public {@link AnnotationCapability}.
58
- * It is the SAME runtime token the plugin provides, narrowed to the public lens —
59
- * the framework-only surface (render projection, pointer gestures, behavior
60
- * registration) is reachable only via `@embedpdf/plugin-annotation/internal`.
61
- */
62
- declare const AnnotationToken: CapabilityToken<AnnotationCapability>;
63
- //#endregion
64
- export { type AnnotationAction, type AnnotationCapability, type AnnotationConfig, type AnnotationFlags, type AnnotationProps, type AnnotationPropsPatch, type AnnotationState, AnnotationToken, type AnnotationToolDef, type AnnotationToolInput, type Behavior, type BlendMode, type Border, type ChromeSettings, type ChromeSettingsPatch, type ClickCreate, type ClickPlacement, DEFAULT_CHROME, DEFAULT_TOOLS, type FilePickerProvider, type FilePromptRequest, type GhostPolicy, type InkAuthoringOptions, type LineEnding, type LineEndings, type LinkNavItem, MIN_DRAG, type PromptSourceSpec, type PropKey, type PropSpec, type ResolvedTool, type SelectionAuthoring, type SelectionFlags, type SelectionProps, type SnapSettings, type StampSourceSpec, type StampToolInput, type TextAlign, type TextItem, type ToolAuthoringKind, type ToolDefaultsFor, type ToolGhost, annotationPlugin, fromDTO, propsFor, refKey, resolveClickPlacement, styleFromDTO, toCreateDraft, toPatch, widgetAppearanceFromProps };
22
+ export { type AnnotationAction, type AnnotationCapability, type AnnotationConfig, type AnnotationDTO, type AnnotationFlags, type AnnotationHydration, type AnnotationProps, type AnnotationPropsPatch, type AnnotationRef, type AnnotationState, type AnnotationSubtype, AnnotationToken, type AnnotationToolDef, type AnnotationToolInput, type Behavior, type BlendMode, type Border, type ChromeSettings, type ChromeSettingsPatch, type ClickCreate, type ClickPlacement, type Color, type CommentPermissions, type CommentThread, type CommentThreadReview, type CommentsApi, DEFAULT_CHROME, DEFAULT_TOOLS, type FilePickerProvider, type FilePromptRequest, type GhostPolicy, type InkAuthoringOptions, type LineEnding, type LineEndings, type LinkNavItem, MIN_DRAG, type PromptSourceSpec, type PropKey, type PropSpec, type ResolvedTool, type ReviewStatus, type SelectionAuthoring, type SelectionFlags, type SelectionProps, type SnapSettings, type StampSourceSpec, type StampToolInput, type TextAlign, type TextItem, type ThreadDeleteResult, type ToolAuthoringKind, type ToolDefaultsFor, type ToolGhost, annotationPlugin, fromDTO, propsFor, refKey, resolveClickPlacement, styleFromDTO, toCreateDraft, toPatch, widgetAppearanceFromProps };
65
23
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,14 +1,20 @@
1
- import { a as toCreateDraft, c as styleFromDTO, i as fromDTO, l as widgetAppearanceFromProps, n as DEFAULT_TOOLS, o as toPatch, s as refKey, t as createAnnotationCapability, u as AnnotationToken$1 } from "./capability-fghl0JmE.js";
1
+ import { d as refKey, h as widgetAppearanceFromProps, p as styleFromDTO } from "./seam-C4L_7rDt.js";
2
+ import { a as fromDTO, i as isTouchDirect, n as DEFAULT_TOOLS, o as toCreateDraft, s as toPatch, t as createAnnotationCapability } from "./capability-DBsr2D-L.js";
3
+ import { t as AnnotationToken$1 } from "./types-CwytT-TI.js";
4
+ import { AnnotationToken } from "./contract.js";
5
+ import "./authoring.js";
2
6
  import { definePlugin } from "@embedpdf/core";
3
- import { InteractionToken } from "@embedpdf/plugin-interaction";
4
- import { SelectionToken } from "@embedpdf/plugin-selection";
7
+ import { ActionsToken } from "@embedpdf/plugin-actions/contract";
8
+ import { ActionsToken as ActionsToken$1 } from "@embedpdf/plugin-actions/contract/host";
9
+ import { InteractionToken } from "@embedpdf/plugin-interaction/contract";
10
+ import { SelectionToken } from "@embedpdf/plugin-selection/contract/host";
5
11
  import { encodeStableIdKey } from "@embedpdf/engine-core/runtime";
6
- import { MIN_DRAG, initialModel, propsFor, propsFor as propsFor$1, resolveClickPlacement, update } from "@embedpdf/core-annotation";
12
+ import { MIN_DRAG, initialModel, propsFor, resolveClickPlacement, update } from "@embedpdf/core-annotation";
7
13
  //#region src/effects.ts
8
14
  function registerAnnotationEffects(ctx) {
9
15
  const doc = ctx.doc;
10
16
  if (!doc) return;
11
- const cropOf = (pon) => ctx.document()?.pages.find((p) => p.pageObjectNumber === pon)?.boxes.crop ?? null;
17
+ const host = () => ctx.get(AnnotationToken$1);
12
18
  const apply = (msg) => {
13
19
  const [next] = update(ctx.getState().model, msg);
14
20
  ctx.dispatch({
@@ -16,39 +22,6 @@ function registerAnnotationEffects(ctx) {
16
22
  model: next
17
23
  });
18
24
  };
19
- const upsert = (dtos, bumpAp) => {
20
- const bump = [];
21
- const keep = [];
22
- for (const dto of dtos) {
23
- const crop = cropOf(dto.pageObjectNumber);
24
- if (!crop) continue;
25
- const a = fromDTO(dto, crop, "baked");
26
- if (a.subtype === "link" && a.data?.subtype === "link" && a.data.replyType === "group") {
27
- const parentId = a.data.inReplyTo ? refKey(a.data.inReplyTo) : null;
28
- const parent = parentId ? ctx.getState().model.byId[parentId] : null;
29
- if (parent && parent.subtype !== "link" && propsFor$1(parent.subtype).some((s) => s.key === "link") && a.ref) {
30
- const refs = parent.linkRefs ?? [];
31
- const known = refs.some((r) => refKey(r) === a.id);
32
- keep.push({
33
- ...parent,
34
- link: a.data.target,
35
- linkRefs: known ? refs : [...refs, a.ref]
36
- });
37
- continue;
38
- }
39
- }
40
- (bumpAp ? bump : keep).push(a);
41
- }
42
- if (bump.length) apply({
43
- t: "upsert",
44
- annots: bump,
45
- bumpAp: true
46
- });
47
- if (keep.length) apply({
48
- t: "upsert",
49
- annots: keep
50
- });
51
- };
52
25
  const unsubscribe = doc.events.subscribe((event) => {
53
26
  if (event.type === "form.valueChanged" || event.type === "form.effectsApplied") {
54
27
  apply({
@@ -62,52 +35,43 @@ function registerAnnotationEffects(ctx) {
62
35
  }
63
36
  if (event.type === "redaction.applied") {
64
37
  const affected = new Set(event.results.filter((r) => r.status === "applied").map((r) => r.pageObjectNumber));
65
- if (affected.size) {
66
- const host = ctx.get(AnnotationToken$1);
67
- for (const pon of affected) host.reloadPage(pon);
68
- }
38
+ if (affected.size) for (const pon of affected) host().reloadPage(pon);
39
+ return;
40
+ }
41
+ if (event.type === "stream.desynced") {
42
+ host().rehydrate();
43
+ return;
44
+ }
45
+ if (event.type === "pages.deleted") {
46
+ const gone = new Set(event.pageObjectNumbers);
47
+ const m = ctx.getState().model;
48
+ const ids = m.order.filter((id) => {
49
+ const a = m.byId[id];
50
+ return a !== void 0 && gone.has(a.pon);
51
+ });
52
+ if (ids.length) apply({
53
+ t: "remove",
54
+ ids
55
+ });
56
+ return;
57
+ }
58
+ if (event.type === "pages.inserted") {
59
+ for (const pon of event.insertedPageObjectNumbers) host().reloadPage(pon);
69
60
  return;
70
61
  }
71
62
  if (!("origin" in event) || event.origin.kind !== "remote") return;
72
63
  switch (event.type) {
73
64
  case "annotation.created":
74
- upsert([event.created], true);
75
- break;
76
65
  case "annotation.updated":
77
- upsert([event.updated], event.appearance.changed);
78
- break;
79
66
  case "annotation.moved":
80
- upsert(event.moved, false);
81
- break;
82
67
  case "annotation.deleted":
83
- if (event.deleted) {
84
- const key = encodeStableIdKey(event.deleted);
85
- const m = ctx.getState().model;
86
- if (m.byId[key]) apply({
87
- t: "remove",
88
- ids: [key]
89
- });
90
- else for (const id of m.order) {
91
- const a = m.byId[id];
92
- const refs = a?.linkRefs;
93
- if (!a || !refs?.length || !refs.some((r) => refKey(r) === key)) continue;
94
- const remaining = refs.filter((r) => refKey(r) !== key);
95
- apply({
96
- t: "upsert",
97
- annots: [{
98
- ...a,
99
- linkRefs: remaining,
100
- ...remaining.length ? {} : { link: null }
101
- }]
102
- });
103
- break;
104
- }
105
- }
68
+ host().deliverRemoteAnnotationEvent(event);
106
69
  break;
107
70
  default: break;
108
71
  }
109
72
  });
110
73
  ctx.cleanup(unsubscribe);
74
+ host().ensureHydrated();
111
75
  }
112
76
  //#endregion
113
77
  //#region src/handler.ts
@@ -183,22 +147,25 @@ function createEditHandler(anno, interaction) {
183
147
  id: "annotation-edit",
184
148
  priority: 100,
185
149
  enabledFor: (t) => t.enables.has("annotation-edit"),
150
+ claimsTouch: (s) => !!s.page && anno.claimsTouchAt(s.page.pon, s.page.point, s.page.scale, s.page.rotation, s.page.zoom),
186
151
  onDown: (s) => {
187
152
  if (!s.page) return false;
153
+ const touch = s.pointerType === "touch";
188
154
  const wasEditing = anno.currentEditing() != null;
189
155
  if (wasEditing) anno.endTextEdit();
190
- if (anno.hitKind(s.page.pon, s.page.point, s.page.scale, s.page.rotation, s.page.zoom) === "empty") {
156
+ if (anno.hitKind(s.page.pon, s.page.point, s.page.scale, s.page.rotation, s.page.zoom, touch) === "empty") {
191
157
  if (!s.modifiers.shift) anno.deselect();
192
158
  return wasEditing;
193
159
  }
194
160
  if ((s.clickCount ?? 1) >= 2) {
195
- anno.beginTextEditAt(s.page.pon, s.page.point, s.page.scale, s.page.rotation, s.page.zoom);
196
- return true;
161
+ if (anno.beginTextEditAt(s.page.pon, s.page.point, s.page.scale, s.page.rotation, s.page.zoom)) return true;
197
162
  }
198
- anno.editPointer("down", s.page.pon, s.page.point, s.modifiers.shift, s.page.scale, s.page.rotation, s.page.zoom);
163
+ anno.editPointer("down", s.page.pon, s.page.point, s.modifiers.shift, s.page.scale, s.page.rotation, s.page.zoom, touch);
199
164
  origin = {
200
165
  pon: s.page.pon,
201
- point: s.page.point
166
+ point: s.page.point,
167
+ downPoint: s.page.point,
168
+ touch
202
169
  };
203
170
  return true;
204
171
  },
@@ -207,13 +174,20 @@ function createEditHandler(anno, interaction) {
207
174
  const point = pointOn(s, origin.pon);
208
175
  if (!point) return;
209
176
  origin.point = point;
210
- anno.editPointer("move", origin.pon, point, s.modifiers.shift, s.page?.scale, s.page?.rotation, s.page?.zoom);
177
+ anno.editPointer("move", origin.pon, point, s.modifiers.shift, s.page?.scale, s.page?.rotation, s.page?.zoom, origin.touch);
211
178
  },
212
179
  onUp: (s) => {
213
180
  if (!origin) return;
214
- anno.editPointer("up", origin.pon, pointOn(s, origin.pon) ?? origin.point, false);
181
+ anno.editPointer("up", origin.pon, pointOn(s, origin.pon) ?? origin.point, false, void 0, void 0, void 0, origin.touch);
215
182
  origin = null;
216
183
  },
184
+ onCancel: () => {
185
+ if (!origin) return;
186
+ const { pon, downPoint, touch } = origin;
187
+ origin = null;
188
+ anno.editPointer("move", pon, downPoint, false, void 0, void 0, void 0, touch);
189
+ anno.editPointer("up", pon, downPoint, false, void 0, void 0, void 0, touch);
190
+ },
217
191
  onHover: (s) => {
218
192
  interaction.setCursor("annotation", s.page ? anno.cursorAt(s.page.pon, s.page.point, s.page.scale, s.page.rotation, s.page.zoom) : null, 20);
219
193
  anno.hoverAt(s.page ? {
@@ -280,6 +254,12 @@ function createMarqueeHandler(anno) {
280
254
  anchor = null;
281
255
  last = null;
282
256
  dragging = false;
257
+ },
258
+ onCancel: () => {
259
+ anchor = null;
260
+ last = null;
261
+ dragging = false;
262
+ anno.cancelCreationDraft();
283
263
  }
284
264
  };
285
265
  }
@@ -358,6 +338,16 @@ function createDrawHandler(anno, interaction) {
358
338
  }
359
339
  origin = null;
360
340
  },
341
+ onCancel: () => {
342
+ if (pendingInk) {
343
+ clearTimeout(pendingInk.timer);
344
+ pendingInk = null;
345
+ }
346
+ drawingPoly = false;
347
+ drawingCallout = false;
348
+ origin = null;
349
+ anno.cancelCreationDraft();
350
+ },
361
351
  onHover: (s) => {
362
352
  const tool = toolId();
363
353
  const st = subtypeOf(tool);
@@ -381,9 +371,9 @@ function wireMarkup(annotation, selection, interaction) {
381
371
  const previewSubtype = authoring?.kind === "markup" ? tool.subtype : authoring?.kind === "text-edit" && authoring.operation === "replace" ? "strikeout" : null;
382
372
  selection.setHighlightVisible(previewSubtype == null);
383
373
  if (previewSubtype && tool && selection.hasSelection()) {
384
- const rectsByPage = {};
385
- for (const page of selection.snapshot().pages) rectsByPage[page.pon] = page.rects;
386
- annotation.previewMarkup(previewSubtype, rectsByPage, tool.preset);
374
+ const quadsByPage = {};
375
+ for (const page of selection.snapshot().pages) quadsByPage[page.pon] = page.segments.map((s) => s.quad);
376
+ annotation.previewMarkup(previewSubtype, quadsByPage, tool.preset);
387
377
  } else annotation.clearMarkupPreview();
388
378
  };
389
379
  selection.onChange(sync);
@@ -394,19 +384,30 @@ function wireMarkup(annotation, selection, interaction) {
394
384
  if (!tool || !authoring) return;
395
385
  const snapshot = selection.snapshot();
396
386
  if (authoring.kind === "text-edit" && authoring.operation === "insert") {
397
- if (snapshot.end) annotation.createCaret(snapshot.end.pon, snapshot.end.rect);
387
+ if (snapshot.end) annotation.createCaret(snapshot.end.pon, {
388
+ glyphQuad: snapshot.end.glyphQuad,
389
+ advance: snapshot.end.advance
390
+ });
398
391
  selection.clear();
399
392
  return;
400
393
  }
401
394
  if (authoring.kind === "text-edit" && authoring.operation === "replace") {
402
395
  for (const page of snapshot.pages) {
403
- const endRect = page.rects[page.rects.length - 1];
404
- if (endRect) annotation.createReplaceText(page.pon, page.rects, endRect, tool.preset);
396
+ const last = page.segments[page.segments.length - 1];
397
+ if (!last) continue;
398
+ const anchor = snapshot.end && snapshot.end.pon === page.pon ? {
399
+ glyphQuad: snapshot.end.glyphQuad,
400
+ advance: snapshot.end.advance
401
+ } : {
402
+ glyphQuad: last.quad,
403
+ advance: last.advance
404
+ };
405
+ annotation.createReplaceText(page.pon, page.segments.map((s) => s.quad), anchor, tool.preset);
405
406
  }
406
407
  selection.clear();
407
408
  return;
408
409
  }
409
- for (const page of snapshot.pages) annotation.createMarkup(tool.subtype, page.pon, page.rects, tool.preset);
410
+ for (const page of snapshot.pages) annotation.createMarkup(tool.subtype, page.pon, page.segments.map((s) => s.quad), tool.preset);
410
411
  selection.clear();
411
412
  });
412
413
  }
@@ -480,6 +481,7 @@ const initialAnnotationState = (config = {}) => ({
480
481
  ...config.snap
481
482
  }
482
483
  },
484
+ hydration: { status: "loading" },
483
485
  chrome: mergeChrome(DEFAULT_CHROME, config.chrome ?? {}),
484
486
  toolGhost: null,
485
487
  stampArmEpoch: 0
@@ -490,6 +492,10 @@ const annotationReducer = (state, action) => {
490
492
  ...state,
491
493
  model: action.model
492
494
  };
495
+ case "SET_HYDRATION": return {
496
+ ...state,
497
+ hydration: action.hydration
498
+ };
493
499
  case "SET_CHROME": return {
494
500
  ...state,
495
501
  chrome: mergeChrome(state.chrome, action.patch)
@@ -518,7 +524,7 @@ const annotationPlugin = (config = {}) => definePlugin({
518
524
  token: AnnotationToken$1,
519
525
  scope: "document",
520
526
  requires: [InteractionToken],
521
- optional: [SelectionToken],
527
+ optional: [SelectionToken, ActionsToken],
522
528
  initialState: () => initialAnnotationState(config),
523
529
  reduce: annotationReducer,
524
530
  capability: (ctx) => createAnnotationCapability(ctx, config),
@@ -527,12 +533,15 @@ const annotationPlugin = (config = {}) => definePlugin({
527
533
  const interaction = ctx.get(InteractionToken);
528
534
  const annotation = ctx.get(AnnotationToken$1);
529
535
  const selection = ctx.tryGet(SelectionToken);
536
+ const actions = ctx.tryGet(ActionsToken$1);
537
+ if (actions) ctx.cleanup(actions.registerAnnotCommitSink((entries) => annotation.commitScriptEffects(entries)));
530
538
  for (const tool of annotation.tools()) {
531
539
  if (tool.enables.has("text-select") && !selection) continue;
532
540
  interaction.registerTool({
533
541
  id: tool.id,
534
542
  cursor: tool.cursor,
535
- enables: tool.enables
543
+ enables: tool.enables,
544
+ touchDirect: isTouchDirect(tool.enables)
536
545
  });
537
546
  if (tool.defaults) annotation.setDefaults(tool.preset, tool.defaults);
538
547
  }
@@ -551,15 +560,6 @@ const annotationPlugin = (config = {}) => definePlugin({
551
560
  }
552
561
  });
553
562
  //#endregion
554
- //#region src/index.ts
555
- /**
556
- * App-facing annotation token: resolves the public {@link AnnotationCapability}.
557
- * It is the SAME runtime token the plugin provides, narrowed to the public lens —
558
- * the framework-only surface (render projection, pointer gestures, behavior
559
- * registration) is reachable only via `@embedpdf/plugin-annotation/internal`.
560
- */
561
- const AnnotationToken = AnnotationToken$1;
562
- //#endregion
563
563
  export { AnnotationToken, DEFAULT_CHROME, DEFAULT_TOOLS, MIN_DRAG, annotationPlugin, fromDTO, propsFor, refKey, resolveClickPlacement, styleFromDTO, toCreateDraft, toPatch, widgetAppearanceFromProps };
564
564
 
565
565
  //# sourceMappingURL=index.js.map