@embedpdf/react 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 (132) hide show
  1. package/dist/AnnotationListSnapshot-C1U3XUxP-6kGwNoxy.d.cts +546 -0
  2. package/dist/AnnotationListSnapshot-C1U3XUxP-6kGwNoxy.d.ts +546 -0
  3. package/dist/actions.cjs +42 -0
  4. package/dist/actions.cjs.map +1 -0
  5. package/dist/actions.d.cts +18 -0
  6. package/dist/actions.d.ts +18 -0
  7. package/dist/actions.js +34 -0
  8. package/dist/actions.js.map +1 -0
  9. package/dist/anchored.cjs +89 -0
  10. package/dist/anchored.cjs.map +1 -0
  11. package/dist/anchored.d.cts +45 -0
  12. package/dist/anchored.d.ts +45 -0
  13. package/dist/anchored.js +60 -0
  14. package/dist/anchored.js.map +1 -0
  15. package/dist/{annotation-B6jwfTCh.d.cts → annotation-BCED_p9H.d.cts} +56 -69
  16. package/dist/annotation-anchors-CetwM1g7.js +15 -0
  17. package/dist/annotation-anchors-CetwM1g7.js.map +1 -0
  18. package/dist/annotation-anchors-DuYRBJLl.cjs +26 -0
  19. package/dist/annotation-anchors-DuYRBJLl.cjs.map +1 -0
  20. package/dist/annotation-hooks-BB5ZhPpf.cjs +16 -0
  21. package/dist/annotation-hooks-BB5ZhPpf.cjs.map +1 -0
  22. package/dist/annotation-hooks-Df8EmzDO.js +11 -0
  23. package/dist/annotation-hooks-Df8EmzDO.js.map +1 -0
  24. package/dist/{annotation-nUMefyjw.d.ts → annotation-k38KDlIZ.d.ts} +57 -70
  25. package/dist/annotation-menu.cjs +37 -88
  26. package/dist/annotation-menu.cjs.map +1 -1
  27. package/dist/annotation-menu.d.cts +28 -2
  28. package/dist/annotation-menu.d.ts +28 -2
  29. package/dist/annotation-menu.js +28 -79
  30. package/dist/annotation-menu.js.map +1 -1
  31. package/dist/annotation.cjs +738 -16
  32. package/dist/annotation.cjs.map +1 -0
  33. package/dist/annotation.d.cts +2 -2
  34. package/dist/annotation.d.ts +2 -2
  35. package/dist/annotation.js +723 -3
  36. package/dist/annotation.js.map +1 -0
  37. package/dist/commands.js +1 -0
  38. package/dist/commands.js.map +1 -1
  39. package/dist/form-BwrLFpKN.js +805 -0
  40. package/dist/form-BwrLFpKN.js.map +1 -0
  41. package/dist/form-D-ZSfGmB.cjs +836 -0
  42. package/dist/form-D-ZSfGmB.cjs.map +1 -0
  43. package/dist/form.cjs +8 -551
  44. package/dist/form.d.cts +4 -21
  45. package/dist/form.d.ts +4 -21
  46. package/dist/form.js +3 -544
  47. package/dist/index.cjs +49 -16
  48. package/dist/index.d.cts +17 -10
  49. package/dist/index.d.ts +17 -10
  50. package/dist/index.js +14 -9
  51. package/dist/interaction.cjs +17 -4
  52. package/dist/interaction.cjs.map +1 -1
  53. package/dist/interaction.d.cts +2 -2
  54. package/dist/interaction.d.ts +2 -2
  55. package/dist/interaction.js +7 -5
  56. package/dist/interaction.js.map +1 -1
  57. package/dist/link.cjs +70 -7
  58. package/dist/link.cjs.map +1 -1
  59. package/dist/link.d.cts +12 -3
  60. package/dist/link.d.ts +12 -3
  61. package/dist/link.js +73 -10
  62. package/dist/link.js.map +1 -1
  63. package/dist/metadata.js +1 -0
  64. package/dist/metadata.js.map +1 -1
  65. package/dist/page-edit.js +1 -0
  66. package/dist/page-edit.js.map +1 -1
  67. package/dist/page-view.cjs +62 -38
  68. package/dist/page-view.cjs.map +1 -1
  69. package/dist/page-view.js +59 -37
  70. package/dist/page-view.js.map +1 -1
  71. package/dist/redaction.js +1 -0
  72. package/dist/redaction.js.map +1 -1
  73. package/dist/render.cjs +67 -50
  74. package/dist/render.cjs.map +1 -1
  75. package/dist/render.d.cts +6 -19
  76. package/dist/render.d.ts +6 -19
  77. package/dist/render.js +71 -52
  78. package/dist/render.js.map +1 -1
  79. package/dist/rolldown-runtime-BBjsoOtd.js +27 -0
  80. package/dist/{runtime-CMxIuF2O.d.cts → runtime-DE76hlnl.d.ts} +32 -11
  81. package/dist/{runtime-DV98q7I0.d.ts → runtime-umHA_xHt.d.cts} +32 -11
  82. package/dist/runtime.cjs +25 -5
  83. package/dist/runtime.cjs.map +1 -1
  84. package/dist/runtime.d.cts +2 -2
  85. package/dist/runtime.d.ts +2 -2
  86. package/dist/runtime.js +26 -6
  87. package/dist/runtime.js.map +1 -1
  88. package/dist/scrollbar.cjs +3 -3
  89. package/dist/scrollbar.cjs.map +1 -1
  90. package/dist/scrollbar.d.cts +1 -1
  91. package/dist/scrollbar.d.ts +1 -1
  92. package/dist/scrollbar.js +1 -1
  93. package/dist/scrollbar.js.map +1 -1
  94. package/dist/search.cjs +36 -19
  95. package/dist/search.cjs.map +1 -1
  96. package/dist/search.d.cts +1 -1
  97. package/dist/search.d.ts +1 -1
  98. package/dist/search.js +36 -19
  99. package/dist/search.js.map +1 -1
  100. package/dist/selection.cjs +217 -22
  101. package/dist/selection.cjs.map +1 -1
  102. package/dist/selection.d.cts +60 -2
  103. package/dist/selection.d.ts +60 -2
  104. package/dist/selection.js +214 -27
  105. package/dist/selection.js.map +1 -1
  106. package/dist/shell.js +1 -0
  107. package/dist/shell.js.map +1 -1
  108. package/dist/stage.cjs +49 -148
  109. package/dist/stage.cjs.map +1 -1
  110. package/dist/stage.d.cts +18 -5
  111. package/dist/stage.d.ts +18 -5
  112. package/dist/stage.js +51 -149
  113. package/dist/stage.js.map +1 -1
  114. package/dist/stamp.js +1 -0
  115. package/dist/stamp.js.map +1 -1
  116. package/dist/toolbar.cjs +4 -4
  117. package/dist/toolbar.cjs.map +1 -1
  118. package/dist/toolbar.d.cts +1 -1
  119. package/dist/toolbar.d.ts +1 -1
  120. package/dist/toolbar.js +2 -1
  121. package/dist/toolbar.js.map +1 -1
  122. package/dist/views.js +1 -0
  123. package/dist/views.js.map +1 -1
  124. package/package.json +33 -26
  125. package/dist/AnnotationListSnapshot-W0RCsyDE-dWna4TTJ.d.cts +0 -2593
  126. package/dist/AnnotationListSnapshot-W0RCsyDE-dWna4TTJ.d.ts +0 -2593
  127. package/dist/annotation-Ct6dFtzJ.cjs +0 -913
  128. package/dist/annotation-Ct6dFtzJ.cjs.map +0 -1
  129. package/dist/annotation-DjGWJljY.js +0 -829
  130. package/dist/annotation-DjGWJljY.js.map +0 -1
  131. package/dist/form.cjs.map +0 -1
  132. package/dist/form.js.map +0 -1
@@ -1,20 +1,740 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- require("./runtime.cjs");
3
- const require_annotation = require("./annotation-Ct6dFtzJ.cjs");
4
- exports.AnnotationLayer = require_annotation.AnnotationLayer;
5
- exports.PageAnnotationDraftMenu = require_annotation.PageAnnotationDraftMenu;
6
- exports.PageAnnotationMenu = require_annotation.PageAnnotationMenu;
7
- exports.filePickerProvider = require_annotation.filePickerProvider;
8
- exports.sameAnchor = require_annotation.sameAnchor;
9
- exports.sameCreationDraftAnchor = require_annotation.sameCreationDraftAnchor;
10
- exports.useAnnotation = require_annotation.useAnnotation;
11
- exports.useAnnotationDefaults = require_annotation.useAnnotationDefaults;
12
- exports.useAnnotationSelected = require_annotation.useAnnotationSelected;
13
- exports.useAnnotationSelection = require_annotation.useAnnotationSelection;
14
- exports.useFilePickerProvider = require_annotation.useFilePickerProvider;
15
- exports.useSelectionFlags = require_annotation.useSelectionFlags;
16
- exports.useSelectionProps = require_annotation.useSelectionProps;
17
- var _embedpdf_plugin_annotation = require("@embedpdf/plugin-annotation");
2
+ const require_rolldown_runtime = require("./rolldown-runtime-DDXJien1.cjs");
3
+ const require_runtime = require("./runtime.cjs");
4
+ const require_annotation_anchors = require("./annotation-anchors-DuYRBJLl.cjs");
5
+ const require_annotation_hooks = require("./annotation-hooks-BB5ZhPpf.cjs");
6
+ let react_jsx_runtime = require("react/jsx-runtime");
7
+ let react = require("react");
8
+ react = require_rolldown_runtime.__toESM(react, 1);
9
+ let _embedpdf_web = require("@embedpdf/web");
10
+ let _embedpdf_plugin_annotation = require("@embedpdf/plugin-annotation");
11
+ let _embedpdf_plugin_annotation_internal = require("@embedpdf/plugin-annotation/internal");
12
+ let _embedpdf_core_annotation = require("@embedpdf/core-annotation");
13
+ //#region src/annotation.tsx
14
+ /** `#rrggbb` → `rgba(...)` — the marquee's translucent fill derives from the
15
+ * accent, so one `setChrome({ accent })` restyles every piece of chrome. */
16
+ const rgba = (hex, alpha) => {
17
+ const m = /^#?([0-9a-f]{6})$/i.exec(hex);
18
+ if (!m) return hex;
19
+ const n = parseInt(m[1], 16);
20
+ return `rgba(${n >> 16 & 255},${n >> 8 & 255},${n & 255},${alpha})`;
21
+ };
22
+ /** Content rect → a view-px box (the page wrapper's own coordinate space). */
23
+ function boxOf(r, page) {
24
+ const tl = page.transform.toPixels({
25
+ x: r.x,
26
+ y: r.y
27
+ });
28
+ const br = page.transform.toPixels({
29
+ x: r.x + r.width,
30
+ y: r.y + r.height
31
+ });
32
+ return {
33
+ left: tl.x,
34
+ top: tl.y,
35
+ width: br.x - tl.x,
36
+ height: br.y - tl.y
37
+ };
38
+ }
39
+ /** Map a core `Paint` to SVG presentation attributes — the whole framework-facing
40
+ * surface. Everything else about appearance is decided in the core's `scene`. */
41
+ function paintAttrs(p) {
42
+ return {
43
+ fill: p.fill ?? "none",
44
+ stroke: p.stroke ?? "none",
45
+ strokeWidth: p.width,
46
+ opacity: p.opacity,
47
+ strokeLinejoin: p.join ?? "miter",
48
+ strokeMiterlimit: _embedpdf_core_annotation.MITER_LIMIT,
49
+ strokeLinecap: p.cap,
50
+ strokeDasharray: p.dash ? p.dash.join(" ") : void 0,
51
+ ...p.blend ? { style: { mixBlendMode: p.blend } } : {}
52
+ };
53
+ }
54
+ /**
55
+ * The dumb painter. The pure core computed `item.box` and the painted `scene`; we
56
+ * size the <svg> to the box with a content-space `viewBox` and map each SceneNode
57
+ * to one element, applying its `paint`. No per-kind logic, no bounds math — so
58
+ * shapes, cloudy borders and every text-markup type all render here, and a Vue /
59
+ * Svelte painter is the same ~10-line loop.
60
+ */
61
+ function Shape({ item, page }) {
62
+ if (item.box.width <= 0 || item.box.height <= 0) return null;
63
+ const { left, top, width, height } = boxOf(item.box, page);
64
+ const vb = `${item.box.x} ${item.box.y} ${item.box.width} ${item.box.height}`;
65
+ const rot = item.geom.t === "rect" || item.geom.t === "caret" ? item.rot ?? 0 : 0;
66
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
67
+ viewBox: vb,
68
+ style: {
69
+ position: "absolute",
70
+ left,
71
+ top,
72
+ width,
73
+ height,
74
+ overflow: "visible",
75
+ pointerEvents: "none",
76
+ ...rot ? {
77
+ transform: `rotate(${rot}deg)`,
78
+ transformOrigin: "center"
79
+ } : {}
80
+ },
81
+ children: sceneNodes(item)
82
+ });
83
+ }
84
+ /** Map a core scene to SVG children. */
85
+ function sceneNodes(item) {
86
+ return (0, _embedpdf_core_annotation.scene)(item).map((n, i) => {
87
+ const a = paintAttrs(n.paint);
88
+ if (n.kind === "rect") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
89
+ x: n.rect.x,
90
+ y: n.rect.y,
91
+ width: n.rect.width,
92
+ height: n.rect.height,
93
+ ...a
94
+ }, i);
95
+ if (n.kind === "ellipse") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ellipse", {
96
+ cx: n.rect.x + n.rect.width / 2,
97
+ cy: n.rect.y + n.rect.height / 2,
98
+ rx: n.rect.width / 2,
99
+ ry: n.rect.height / 2,
100
+ ...a
101
+ }, i);
102
+ if (n.kind === "line") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
103
+ x1: n.a.x,
104
+ y1: n.a.y,
105
+ x2: n.b.x,
106
+ y2: n.b.y,
107
+ ...a
108
+ }, i);
109
+ if (n.kind === "path") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
110
+ d: n.d,
111
+ ...a
112
+ }, i);
113
+ if (n.kind === "text") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("text", {
114
+ x: n.at.x,
115
+ y: n.at.y,
116
+ fontSize: n.fontSize,
117
+ ...n.fontFamily ? { fontFamily: n.fontFamily } : {},
118
+ ...a,
119
+ children: n.text
120
+ }, i);
121
+ const pts = n.points.map((p) => `${p.x},${p.y}`).join(" ");
122
+ return n.closed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("polygon", {
123
+ points: pts,
124
+ ...a
125
+ }, i) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("polyline", {
126
+ points: pts,
127
+ ...a
128
+ }, i);
129
+ });
130
+ }
131
+ function BakedImage({ box, url, page, blend, rot }) {
132
+ const b = boxOf(box, page);
133
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
134
+ src: url,
135
+ alt: "",
136
+ draggable: false,
137
+ style: {
138
+ position: "absolute",
139
+ left: b.left,
140
+ top: b.top,
141
+ width: b.width,
142
+ height: b.height,
143
+ maxWidth: "none",
144
+ maxHeight: "none",
145
+ pointerEvents: "none",
146
+ mixBlendMode: blend,
147
+ ...rot ? {
148
+ transform: `rotate(${rot}deg)`,
149
+ transformOrigin: "center"
150
+ } : {}
151
+ }
152
+ });
153
+ }
154
+ /**
155
+ * The armed stamp's IMAGE footprint ghost: a translucent render of the payload
156
+ * drawn in the EXACT box a click would place it (the plugin computes it with
157
+ * the same fit + clamp as placement). Vector footprint ghosts never reach this
158
+ * component — they ride `pageItems` like every draft preview. The preview
159
+ * bytes live in the capability closure; this layer owns only the object-URL
160
+ * lifetime, keyed on the arm epoch — a new arm swaps the image, a disarm (or
161
+ * tool change) drops it.
162
+ */
163
+ function ToolGhostImage({ page }) {
164
+ const anno = require_runtime.useCapability(_embedpdf_plugin_annotation_internal.AnnotationToken);
165
+ const ghost = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.toolGhost(page.pon));
166
+ const epoch = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.stampArmEpoch());
167
+ const [url, setUrl] = (0, react.useState)(null);
168
+ (0, react.useEffect)(() => {
169
+ const preview = anno.armedStampPreview();
170
+ if (!preview) {
171
+ setUrl(null);
172
+ return;
173
+ }
174
+ const body = new ArrayBuffer(preview.bytes.byteLength);
175
+ new Uint8Array(body).set(preview.bytes);
176
+ const blob = new Blob([body], preview.mimeType ? { type: preview.mimeType } : {});
177
+ const obj = URL.createObjectURL(blob);
178
+ setUrl(obj);
179
+ return () => {
180
+ URL.revokeObjectURL(obj);
181
+ setUrl(null);
182
+ };
183
+ }, [anno, epoch]);
184
+ if (!ghost || ghost.kind !== "image" || !url) return null;
185
+ const b = boxOf(ghost.box, page);
186
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
187
+ src: url,
188
+ alt: "",
189
+ draggable: false,
190
+ style: {
191
+ position: "absolute",
192
+ left: b.left,
193
+ top: b.top,
194
+ width: b.width,
195
+ height: b.height,
196
+ maxWidth: "none",
197
+ maxHeight: "none",
198
+ pointerEvents: "none",
199
+ opacity: .5,
200
+ ...ghost.rot ? {
201
+ transform: `rotate(${ghost.rot}deg)`,
202
+ transformOrigin: "center"
203
+ } : {}
204
+ }
205
+ });
206
+ }
207
+ function Chrome({ page }) {
208
+ const scale = page.transform.viewScale;
209
+ const rotation = page.transform.rotation;
210
+ const zoom = page.transform.zoom;
211
+ const nodes = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.chrome(page.pon, scale, rotation, zoom), require_runtime.shallowArray);
212
+ const cs = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.chromeSettings());
213
+ const outlineStroke = cs.outline.color ?? cs.accent;
214
+ const handleStroke = cs.handles.stroke ?? cs.accent;
215
+ const knobStroke = cs.knob.stroke ?? cs.accent;
216
+ const outlineDash = cs.outline.style === "dashed" ? "4 3" : void 0;
217
+ const chip = nodes.find((n) => n.kind === "angle-chip");
218
+ const chipAt = chip ? page.transform.toPixels(chip.at) : null;
219
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
220
+ style: {
221
+ position: "absolute",
222
+ inset: 0,
223
+ overflow: "visible",
224
+ pointerEvents: "none"
225
+ },
226
+ children: nodes.map((n, i) => {
227
+ if (n.kind === "angle-chip") return null;
228
+ if (n.kind === "handle") {
229
+ const p = page.transform.toPixels(n.at);
230
+ const hs = cs.handles.size;
231
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
232
+ x: p.x - hs / 2,
233
+ y: p.y - hs / 2,
234
+ width: hs,
235
+ height: hs,
236
+ fill: cs.handles.fill,
237
+ stroke: handleStroke,
238
+ strokeWidth: 1.5,
239
+ ...n.rot ? { transform: `rotate(${n.rot} ${p.x} ${p.y})` } : {}
240
+ }, i);
241
+ }
242
+ if (n.kind === "guide") {
243
+ const a = page.transform.toPixels(n.axis === "x" ? {
244
+ x: n.at,
245
+ y: n.lo
246
+ } : {
247
+ x: n.lo,
248
+ y: n.at
249
+ });
250
+ const b = page.transform.toPixels(n.axis === "x" ? {
251
+ x: n.at,
252
+ y: n.hi
253
+ } : {
254
+ x: n.hi,
255
+ y: n.at
256
+ });
257
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
258
+ x1: a.x,
259
+ y1: a.y,
260
+ x2: b.x,
261
+ y2: b.y,
262
+ stroke: "#e91e63",
263
+ strokeWidth: 1.5,
264
+ shapeRendering: "crispEdges"
265
+ }, i);
266
+ }
267
+ if (n.kind === "obb") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("polygon", {
268
+ points: n.corners.map((c) => {
269
+ const p = page.transform.toPixels(c);
270
+ return `${p.x},${p.y}`;
271
+ }).join(" "),
272
+ fill: "none",
273
+ stroke: outlineStroke,
274
+ strokeWidth: cs.outline.width,
275
+ strokeDasharray: outlineDash
276
+ }, i);
277
+ if (n.kind === "rotate-guides") {
278
+ const guideDash = cs.guides.style === "dashed" ? "4 3" : void 0;
279
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("g", { children: n.lines.map((l, j) => {
280
+ const a = page.transform.toPixels(l.a);
281
+ const b = page.transform.toPixels(l.b);
282
+ const axis = l.role === "axis";
283
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
284
+ x1: a.x,
285
+ y1: a.y,
286
+ x2: b.x,
287
+ y2: b.y,
288
+ stroke: axis ? cs.guides.axisColor ?? cs.accent : cs.guides.indicatorColor ?? cs.accent,
289
+ opacity: axis ? cs.guides.axisOpacity : cs.guides.indicatorOpacity,
290
+ strokeWidth: cs.guides.width,
291
+ strokeDasharray: guideDash
292
+ }, j);
293
+ }) }, i);
294
+ }
295
+ if (n.kind === "rotate-knob") {
296
+ const at = page.transform.toPixels(n.at);
297
+ const from = page.transform.toPixels(n.from);
298
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", { children: [cs.knob.stalk && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
299
+ x1: from.x,
300
+ y1: from.y,
301
+ x2: at.x,
302
+ y2: at.y,
303
+ stroke: knobStroke,
304
+ strokeWidth: 1
305
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
306
+ cx: at.x,
307
+ cy: at.y,
308
+ r: cs.knob.size / 2,
309
+ fill: cs.knob.fill,
310
+ stroke: knobStroke,
311
+ strokeWidth: 1.5
312
+ })] }, i);
313
+ }
314
+ const b = boxOf(n.rect, page);
315
+ if (n.kind === "marquee") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
316
+ x: b.left,
317
+ y: b.top,
318
+ width: b.width,
319
+ height: b.height,
320
+ fill: rgba(cs.accent, .08),
321
+ stroke: cs.accent,
322
+ strokeWidth: 1,
323
+ strokeDasharray: "4 3"
324
+ }, i);
325
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
326
+ x: b.left,
327
+ y: b.top,
328
+ width: b.width,
329
+ height: b.height,
330
+ fill: "none",
331
+ stroke: outlineStroke,
332
+ strokeWidth: cs.outline.width,
333
+ strokeDasharray: outlineDash
334
+ }, i);
335
+ })
336
+ }), chip && chipAt && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
337
+ style: {
338
+ position: "absolute",
339
+ left: chipAt.x + 16,
340
+ top: chipAt.y - 28,
341
+ background: "rgba(0,0,0,0.8)",
342
+ color: "#fff",
343
+ padding: "2px 6px",
344
+ borderRadius: 4,
345
+ fontSize: 12,
346
+ fontFamily: "monospace",
347
+ pointerEvents: "none",
348
+ whiteSpace: "nowrap",
349
+ zIndex: 1
350
+ },
351
+ children: [chip.angle, "°"]
352
+ })] });
353
+ }
354
+ /**
355
+ * A free-text annotation: the SAME styled element for viewing and editing —
356
+ * `contentEditable` just toggles, so the text never jumps. The plugin handed us a
357
+ * ready-to-spread style (`item.css`); the browser owns layout, caret, selection,
358
+ * IME and clipboard; the plugin owns the text truth + the debounced engine write.
359
+ * This component is the ENTIRE per-framework surface for text editing.
360
+ */
361
+ function FreeText({ item, page }) {
362
+ const anno = require_runtime.useCapability(_embedpdf_plugin_annotation_internal.AnnotationToken);
363
+ const ref = react.useRef(null);
364
+ const box = boxOf(item.box, page);
365
+ const scale = item.box.width > 0 ? box.width / item.box.width : 1;
366
+ const pad = item.css.padding * scale;
367
+ const plate = {
368
+ left: box.left + pad,
369
+ top: box.top + pad,
370
+ width: Math.max(0, box.width - 2 * pad),
371
+ height: Math.max(0, box.height - 2 * pad)
372
+ };
373
+ (0, react.useEffect)(() => {
374
+ const el = ref.current;
375
+ if (el && document.activeElement !== el && el.innerText !== item.contents) el.innerText = item.contents;
376
+ }, [item.contents, item.editing]);
377
+ (0, react.useEffect)(() => {
378
+ if (item.editing) {
379
+ const el = ref.current;
380
+ if (!el) return;
381
+ el.focus();
382
+ el.scrollTop = 0;
383
+ }
384
+ }, [item.editing]);
385
+ (0, react.useEffect)(() => {
386
+ const el = ref.current;
387
+ if (!el) return;
388
+ const stop = (e) => e.stopPropagation();
389
+ el.addEventListener("pointerdown", stop);
390
+ return () => el.removeEventListener("pointerdown", stop);
391
+ }, []);
392
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
393
+ ref,
394
+ contentEditable: item.editing,
395
+ suppressContentEditableWarning: true,
396
+ onInput: () => item.ref && anno.setContents(item.ref, ref.current.innerText),
397
+ onBlur: (e) => {
398
+ if (e.relatedTarget == null && ref.current?.isConnected && anno.currentEditing() === item.id) ref.current.focus();
399
+ },
400
+ onPaste: (e) => {
401
+ e.preventDefault();
402
+ document.execCommand("insertText", false, e.clipboardData.getData("text/plain"));
403
+ },
404
+ style: {
405
+ position: "absolute",
406
+ left: plate.left,
407
+ top: plate.top,
408
+ width: plate.width,
409
+ height: plate.height,
410
+ fontFamily: item.css.fontFamily,
411
+ fontSize: item.css.fontSize * scale,
412
+ lineHeight: `${item.css.lineHeight * scale}px`,
413
+ color: item.css.color,
414
+ textAlign: item.css.align,
415
+ boxSizing: "border-box",
416
+ background: item.css.background ?? "transparent",
417
+ whiteSpace: "pre-wrap",
418
+ overflowWrap: "break-word",
419
+ overflowY: item.editing ? "auto" : "hidden",
420
+ overflowX: "hidden",
421
+ outline: item.editing ? "1px solid #3858e9" : "none",
422
+ cursor: item.editing ? "text" : "default",
423
+ ...item.rot ? {
424
+ transform: `rotate(${item.rot}deg)`,
425
+ transformOrigin: "center"
426
+ } : {},
427
+ pointerEvents: item.editing ? "auto" : "none"
428
+ }
429
+ });
430
+ }
431
+ /**
432
+ * Auto-registered behaviors for `interactive` renderer entries — refcounted
433
+ * per (capability, entry) because the layer mounts once PER PAGE: the first
434
+ * page registers, the last unregisters. Entry identity is the key, hence the
435
+ * "define entries outside render" rule on {@link AnnotationRenderer}.
436
+ */
437
+ const autoBehaviors = /* @__PURE__ */ new WeakMap();
438
+ let autoBehaviorSeq = 0;
439
+ function useAutoBehaviors(anno, renderers) {
440
+ (0, react.useEffect)(() => {
441
+ if (!renderers) return;
442
+ const released = [];
443
+ for (const r of renderers) {
444
+ if (!("for" in r) || !r.interactive) continue;
445
+ let perCap = autoBehaviors.get(anno);
446
+ if (!perCap) autoBehaviors.set(anno, perCap = /* @__PURE__ */ new Map());
447
+ let rec = perCap.get(r);
448
+ if (!rec) {
449
+ const id = r.id ?? `renderer:${++autoBehaviorSeq}`;
450
+ const engaged = typeof r.interactive === "function" ? r.interactive : () => true;
451
+ rec = {
452
+ id,
453
+ count: 0,
454
+ unregister: anno.registerBehavior({
455
+ id,
456
+ matches: r.for,
457
+ engaged
458
+ })
459
+ };
460
+ perCap.set(r, rec);
461
+ }
462
+ rec.count++;
463
+ const owned = rec;
464
+ released.push(() => {
465
+ owned.count--;
466
+ if (owned.count === 0) {
467
+ owned.unregister();
468
+ autoBehaviors.get(anno)?.delete(r);
469
+ }
470
+ });
471
+ }
472
+ return () => released.forEach((f) => f());
473
+ }, [anno, renderers]);
474
+ }
475
+ /** The behavior id a renderer entry answers for (plugin-owned or auto-registered). */
476
+ function rendererBehaviorId(anno, r) {
477
+ if ("behavior" in r) return r.behavior;
478
+ return autoBehaviors.get(anno)?.get(r)?.id ?? null;
479
+ }
480
+ /** React 18 spells the `inert` attribute as a string spread; it hard-disables
481
+ * pointer AND focus for the whole subtree — the mechanical guarantee that a
482
+ * non-interactive renderer entry (a skin) can never steal input. */
483
+ const INERT = { inert: "" };
484
+ function AnnotationLayer({ renderers } = {}) {
485
+ const page = require_runtime.usePage();
486
+ const anno = require_runtime.useCapability(_embedpdf_plugin_annotation_internal.AnnotationToken);
487
+ const viewZoom = page.transform.zoom;
488
+ const viewRotation = page.transform.rotation;
489
+ const items = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.pageItems(page.pon, {
490
+ zoom: viewZoom,
491
+ rotation: viewRotation
492
+ }), require_runtime.shallowArray);
493
+ const texts = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.textItems(page.pon, {
494
+ zoom: viewZoom,
495
+ rotation: viewRotation
496
+ }), require_runtime.shallowArray);
497
+ const [urls, setUrls] = (0, react.useState)({});
498
+ useAutoBehaviors(anno, renderers);
499
+ (0, react.useEffect)(() => {
500
+ anno.ensurePage(page.pon);
501
+ }, [anno, page.pon]);
502
+ const bakedKey = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.appearanceEpoch(page.pon));
503
+ const bakeScale = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.bakeScale(page.transform.renderScale));
504
+ (0, react.useEffect)(() => {
505
+ const controller = new AbortController();
506
+ const revokers = [];
507
+ (async () => {
508
+ try {
509
+ const imgs = await anno.appearances(page.pon, bakeScale, controller.signal);
510
+ const map = {};
511
+ for (const ap of imgs) {
512
+ const box = anno.toContentBox(page.pon, ap.rect);
513
+ if (!box) continue;
514
+ const obj = await ap.image.objectUrl(controller.signal);
515
+ if (controller.signal.aborted) {
516
+ obj.revoke();
517
+ return;
518
+ }
519
+ revokers.push(obj.revoke);
520
+ map[(0, _embedpdf_plugin_annotation.refKey)(ap.ref)] = {
521
+ url: obj.url,
522
+ box
523
+ };
524
+ }
525
+ if (!controller.signal.aborted) setUrls(map);
526
+ } catch {}
527
+ })();
528
+ return () => {
529
+ controller.abort();
530
+ revokers.forEach((r) => r());
531
+ };
532
+ }, [
533
+ anno,
534
+ page.pon,
535
+ bakeScale,
536
+ bakedKey
537
+ ]);
538
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
539
+ style: {
540
+ position: "absolute",
541
+ inset: 0,
542
+ pointerEvents: "none"
543
+ },
544
+ children: [
545
+ items.map((item) => {
546
+ const baked = urls[item.id];
547
+ const native = item.source === "baked" ? baked ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BakedImage, {
548
+ box: item.apBox ?? baked.box,
549
+ url: baked.url,
550
+ page,
551
+ blend: item.blend,
552
+ rot: item.apRot
553
+ }) : null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Shape, {
554
+ item,
555
+ page
556
+ });
557
+ const behavior = anno.behaviorFor({
558
+ subtype: item.subtype,
559
+ ref: item.ref
560
+ });
561
+ let out;
562
+ if (behavior) {
563
+ const entry = renderers?.find((r) => rendererBehaviorId(anno, r) === behavior.id);
564
+ if (entry) {
565
+ const Owner = entry.component;
566
+ out = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Owner, {
567
+ item,
568
+ page,
569
+ appearance: baked ?? null,
570
+ native,
571
+ interactive: true
572
+ });
573
+ } else out = null;
574
+ } else {
575
+ const entry = renderers?.find((r) => "for" in r && r.for({
576
+ subtype: item.subtype,
577
+ ref: item.ref
578
+ }));
579
+ if (entry) {
580
+ const Skin = entry.component;
581
+ out = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
582
+ ...INERT,
583
+ style: { pointerEvents: "none" },
584
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Skin, {
585
+ item,
586
+ page,
587
+ appearance: baked ?? null,
588
+ native,
589
+ interactive: false
590
+ })
591
+ });
592
+ } else out = native;
593
+ }
594
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: out }, item.id);
595
+ }),
596
+ texts.map((t) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FreeText, {
597
+ item: t,
598
+ page
599
+ }, t.id)),
600
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolGhostImage, { page }),
601
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chrome, { page })
602
+ ]
603
+ });
604
+ }
605
+ /**
606
+ * The default file-picker provider: the built-in file dialog (from
607
+ * `@embedpdf/web`), honouring the tool's `accept` filter. This is the ADAPTER
608
+ * fulfilling the plugin's DOM-free port — the dialog lives here, in the
609
+ * framework layer, never in the plugin. A picked `File` carries its own name
610
+ * and mime, so it goes straight through as the engine's file source.
611
+ */
612
+ const filePickerProvider = async (req) => {
613
+ const file = await (0, _embedpdf_web.pickFile)({ accept: req.accept ?? "*/*" });
614
+ return file ? { data: file } : null;
615
+ };
616
+ /**
617
+ * Install the file-picker provider for the active document — the ONE port
618
+ * behind every click-then-pick tool (a stamp `'prompt'` source, the file-
619
+ * attachment tool). Call ONCE at a document-scoped spot (not inside
620
+ * `<AnnotationLayer>`, which is per page). Defaults to
621
+ * {@link filePickerProvider}, so a bare `useFilePickerProvider()` makes all of
622
+ * them work out of the box; pass a custom provider (asset library, cloud
623
+ * drive — switch on `req.subtype` / `req.toolId`) or `null` to make
624
+ * click-then-pick tools inert. Cleared on unmount.
625
+ */
626
+ function useFilePickerProvider(provider = filePickerProvider) {
627
+ const anno = require_runtime.useOptionalCapability(_embedpdf_plugin_annotation.AnnotationToken);
628
+ (0, react.useEffect)(() => {
629
+ if (!anno) return;
630
+ anno.setFilePickerProvider(provider);
631
+ return () => anno.setFilePickerProvider(null);
632
+ }, [anno, provider]);
633
+ }
634
+ function useAnnotation() {
635
+ return require_runtime.useCapability(_embedpdf_plugin_annotation.AnnotationToken);
636
+ }
637
+ function useAnnotationSelection() {
638
+ return require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.selection(), require_runtime.shallowArray);
639
+ }
640
+ /** Structural equality for a resolved props bag — keeps the subscription from
641
+ * re-rendering on unrelated dispatches, since `currentDefaults` returns a fresh
642
+ * object each call. Small flat objects; JSON compare is exact and cheap here. */
643
+ const sameProps = (a, b) => a === b || JSON.stringify(a) === JSON.stringify(b);
644
+ /**
645
+ * A tool's RESOLVED defaults (base + per-tool override) as a full flat props
646
+ * bag, subscribed so a `setDefaults` re-renders the consumer. Use this — not the
647
+ * imperative `useAnnotation().currentDefaults(id)` — to drive default-editing
648
+ * controls, so they reflect changes live. Pair with `propsForTool(id)` for the
649
+ * specs to render.
650
+ */
651
+ function useAnnotationDefaults(toolId) {
652
+ return require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.currentDefaults(toolId), sameProps);
653
+ }
654
+ /**
655
+ * The selection's editable properties — ordered specs shared by every selected
656
+ * kind, current values, and which keys are mixed. THE hook a property sidebar
657
+ * renders from; write back with `useAnnotation().updateSelection({ [key]: v })`.
658
+ * Reference-stable between model changes (the capability memoizes by model
659
+ * identity), so the default equality is enough.
660
+ */
661
+ function useSelectionProps() {
662
+ return require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.getSelectionProps());
663
+ }
664
+ /**
665
+ * The selection's `/F` annotation flags — per-flag `true`/`false`, `null` where
666
+ * the selected annotations disagree (render an indeterminate control), `null`
667
+ * overall when nothing is selected. Write back with
668
+ * `useAnnotation().updateSelectionFlags({ locked: true })`. Reference-stable
669
+ * between model changes, like {@link useSelectionProps}.
670
+ */
671
+ function useSelectionFlags() {
672
+ return require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.getSelectionFlags());
673
+ }
674
+ /** Pure join behind {@link useCommentThreads} — exported for tests. */
675
+ function enrichCommentThreads(threads, pages) {
676
+ const byPon = new Map(pages.map((p) => [p.pageObjectNumber, p]));
677
+ return threads.map((t) => {
678
+ const page = byPon.get(t.pageObjectNumber);
679
+ return {
680
+ ...t,
681
+ pageIndex: page ? page.index : -1,
682
+ pageLabel: page ? page.label ?? String(page.index + 1) : "?",
683
+ contentRect: page ? (0, _embedpdf_core_annotation.pdfToContentRect)(t.root.rect, page.boxes.crop) : null
684
+ };
685
+ });
686
+ }
687
+ /** The comments surface (verbs + `permissionsFor`) — imperative; pair with
688
+ * {@link useCommentThreads} for the subscribed view. */
689
+ function useComments() {
690
+ return require_runtime.useCapability(_embedpdf_plugin_annotation.AnnotationToken).comments;
691
+ }
692
+ const EMPTY_PAGES = [];
693
+ /**
694
+ * Every comment thread in the document, display-ordered (page position →
695
+ * top of page → creation date) and enriched with `pageIndex`/`pageLabel`.
696
+ * Subscribed to BOTH stores: annotation writes (own, remote, hydration)
697
+ * recompute the threads; page moves/deletes re-run the join. Reference-
698
+ * stable between changes — safe to memo child renders on the array.
699
+ */
700
+ function useCommentThreads() {
701
+ const docId = require_runtime.useDocumentId();
702
+ const threads = require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.comments.threads());
703
+ const pages = require_runtime.useKernelValue((k) => docId ? k.getState().core.documents[docId]?.pages ?? EMPTY_PAGES : EMPTY_PAGES);
704
+ return react.useMemo(() => enrichCommentThreads(threads, pages), [threads, pages]);
705
+ }
706
+ /** The enriched thread containing ANY member ref (root, reply, grouped part,
707
+ * state annotation), or null. */
708
+ function useCommentThread(ref) {
709
+ const views = useCommentThreads();
710
+ const api = useComments();
711
+ if (ref == null) return null;
712
+ const t = api.thread(ref);
713
+ if (!t) return null;
714
+ return views.find((v) => (0, _embedpdf_plugin_annotation.refKey)(v.root.ref) === (0, _embedpdf_plugin_annotation.refKey)(t.root.ref)) ?? null;
715
+ }
716
+ /** Whole-document hydration status — the comments sidebar's honest loading
717
+ * state (`loading` until `listRawAll` lands, then `complete`/`error`). */
718
+ function useCommentsHydration() {
719
+ return require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.comments.hydration());
720
+ }
721
+ //#endregion
722
+ exports.AnnotationLayer = AnnotationLayer;
723
+ exports.enrichCommentThreads = enrichCommentThreads;
724
+ exports.filePickerProvider = filePickerProvider;
725
+ exports.sameAnchor = require_annotation_anchors.sameAnchor;
726
+ exports.sameCreationDraftAnchor = require_annotation_anchors.sameCreationDraftAnchor;
727
+ exports.useAnnotation = useAnnotation;
728
+ exports.useAnnotationDefaults = useAnnotationDefaults;
729
+ exports.useAnnotationSelected = require_annotation_hooks.useAnnotationSelected;
730
+ exports.useAnnotationSelection = useAnnotationSelection;
731
+ exports.useCommentThread = useCommentThread;
732
+ exports.useCommentThreads = useCommentThreads;
733
+ exports.useComments = useComments;
734
+ exports.useCommentsHydration = useCommentsHydration;
735
+ exports.useFilePickerProvider = useFilePickerProvider;
736
+ exports.useSelectionFlags = useSelectionFlags;
737
+ exports.useSelectionProps = useSelectionProps;
18
738
  Object.keys(_embedpdf_plugin_annotation).forEach(function(k) {
19
739
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
20
740
  enumerable: true,
@@ -23,3 +743,5 @@ Object.keys(_embedpdf_plugin_annotation).forEach(function(k) {
23
743
  }
24
744
  });
25
745
  });
746
+
747
+ //# sourceMappingURL=annotation.cjs.map