@embedpdf/react 3.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/LICENSE +192 -0
  2. package/dist/AnnotationListSnapshot-W0RCsyDE-dWna4TTJ.d.cts +2593 -0
  3. package/dist/AnnotationListSnapshot-W0RCsyDE-dWna4TTJ.d.ts +2593 -0
  4. package/dist/annotation-B6jwfTCh.d.cts +173 -0
  5. package/dist/annotation-Ct6dFtzJ.cjs +913 -0
  6. package/dist/annotation-Ct6dFtzJ.cjs.map +1 -0
  7. package/dist/annotation-DjGWJljY.js +829 -0
  8. package/dist/annotation-DjGWJljY.js.map +1 -0
  9. package/dist/annotation-menu.cjs +115 -0
  10. package/dist/annotation-menu.cjs.map +1 -0
  11. package/dist/annotation-menu.d.cts +7 -0
  12. package/dist/annotation-menu.d.ts +7 -0
  13. package/dist/annotation-menu.js +99 -0
  14. package/dist/annotation-menu.js.map +1 -0
  15. package/dist/annotation-nUMefyjw.d.ts +173 -0
  16. package/dist/annotation.cjs +25 -0
  17. package/dist/annotation.d.cts +3 -0
  18. package/dist/annotation.d.ts +3 -0
  19. package/dist/annotation.js +4 -0
  20. package/dist/commands.cjs +59 -0
  21. package/dist/commands.cjs.map +1 -0
  22. package/dist/commands.d.cts +20 -0
  23. package/dist/commands.d.ts +20 -0
  24. package/dist/commands.js +47 -0
  25. package/dist/commands.js.map +1 -0
  26. package/dist/form.cjs +560 -0
  27. package/dist/form.cjs.map +1 -0
  28. package/dist/form.d.cts +52 -0
  29. package/dist/form.d.ts +52 -0
  30. package/dist/form.js +545 -0
  31. package/dist/form.js.map +1 -0
  32. package/dist/i18n.cjs +52 -0
  33. package/dist/i18n.cjs.map +1 -0
  34. package/dist/i18n.d.cts +30 -0
  35. package/dist/i18n.d.ts +30 -0
  36. package/dist/i18n.js +42 -0
  37. package/dist/i18n.js.map +1 -0
  38. package/dist/index.cjs +240 -0
  39. package/dist/index.d.cts +37 -0
  40. package/dist/index.d.ts +37 -0
  41. package/dist/index.js +37 -0
  42. package/dist/interaction.cjs +152 -0
  43. package/dist/interaction.cjs.map +1 -0
  44. package/dist/interaction.d.cts +46 -0
  45. package/dist/interaction.d.ts +46 -0
  46. package/dist/interaction.js +139 -0
  47. package/dist/interaction.js.map +1 -0
  48. package/dist/link.cjs +108 -0
  49. package/dist/link.cjs.map +1 -0
  50. package/dist/link.d.cts +16 -0
  51. package/dist/link.d.ts +16 -0
  52. package/dist/link.js +98 -0
  53. package/dist/link.js.map +1 -0
  54. package/dist/metadata.cjs +25 -0
  55. package/dist/metadata.cjs.map +1 -0
  56. package/dist/metadata.d.cts +11 -0
  57. package/dist/metadata.d.ts +11 -0
  58. package/dist/metadata.js +16 -0
  59. package/dist/metadata.js.map +1 -0
  60. package/dist/page-edit.cjs +20 -0
  61. package/dist/page-edit.cjs.map +1 -0
  62. package/dist/page-edit.d.cts +7 -0
  63. package/dist/page-edit.d.ts +7 -0
  64. package/dist/page-edit.js +11 -0
  65. package/dist/page-edit.js.map +1 -0
  66. package/dist/page-view.cjs +107 -0
  67. package/dist/page-view.cjs.map +1 -0
  68. package/dist/page-view.d.cts +23 -0
  69. package/dist/page-view.d.ts +23 -0
  70. package/dist/page-view.js +95 -0
  71. package/dist/page-view.js.map +1 -0
  72. package/dist/redaction.cjs +35 -0
  73. package/dist/redaction.cjs.map +1 -0
  74. package/dist/redaction.d.cts +14 -0
  75. package/dist/redaction.d.ts +14 -0
  76. package/dist/redaction.js +25 -0
  77. package/dist/redaction.js.map +1 -0
  78. package/dist/render.cjs +142 -0
  79. package/dist/render.cjs.map +1 -0
  80. package/dist/render.d.cts +32 -0
  81. package/dist/render.d.ts +32 -0
  82. package/dist/render.js +131 -0
  83. package/dist/render.js.map +1 -0
  84. package/dist/rolldown-runtime-DDXJien1.cjs +50 -0
  85. package/dist/runtime-CMxIuF2O.d.cts +195 -0
  86. package/dist/runtime-DV98q7I0.d.ts +195 -0
  87. package/dist/runtime.cjs +314 -0
  88. package/dist/runtime.cjs.map +1 -0
  89. package/dist/runtime.d.cts +3 -0
  90. package/dist/runtime.d.ts +3 -0
  91. package/dist/runtime.js +287 -0
  92. package/dist/runtime.js.map +1 -0
  93. package/dist/scrollbar.cjs +241 -0
  94. package/dist/scrollbar.cjs.map +1 -0
  95. package/dist/scrollbar.d.cts +42 -0
  96. package/dist/scrollbar.d.ts +42 -0
  97. package/dist/scrollbar.js +213 -0
  98. package/dist/scrollbar.js.map +1 -0
  99. package/dist/search.cjs +70 -0
  100. package/dist/search.cjs.map +1 -0
  101. package/dist/search.d.cts +35 -0
  102. package/dist/search.d.ts +35 -0
  103. package/dist/search.js +58 -0
  104. package/dist/search.js.map +1 -0
  105. package/dist/selection.cjs +60 -0
  106. package/dist/selection.cjs.map +1 -0
  107. package/dist/selection.d.cts +12 -0
  108. package/dist/selection.d.ts +12 -0
  109. package/dist/selection.js +49 -0
  110. package/dist/selection.js.map +1 -0
  111. package/dist/shell.cjs +57 -0
  112. package/dist/shell.cjs.map +1 -0
  113. package/dist/shell.d.cts +27 -0
  114. package/dist/shell.d.ts +27 -0
  115. package/dist/shell.js +46 -0
  116. package/dist/shell.js.map +1 -0
  117. package/dist/stage.cjs +343 -0
  118. package/dist/stage.cjs.map +1 -0
  119. package/dist/stage.d.cts +104 -0
  120. package/dist/stage.d.ts +104 -0
  121. package/dist/stage.js +327 -0
  122. package/dist/stage.js.map +1 -0
  123. package/dist/stamp.cjs +76 -0
  124. package/dist/stamp.cjs.map +1 -0
  125. package/dist/stamp.d.cts +28 -0
  126. package/dist/stamp.d.ts +28 -0
  127. package/dist/stamp.js +63 -0
  128. package/dist/stamp.js.map +1 -0
  129. package/dist/toolbar.cjs +515 -0
  130. package/dist/toolbar.cjs.map +1 -0
  131. package/dist/toolbar.d.cts +100 -0
  132. package/dist/toolbar.d.ts +100 -0
  133. package/dist/toolbar.js +505 -0
  134. package/dist/toolbar.js.map +1 -0
  135. package/dist/views.cjs +35 -0
  136. package/dist/views.cjs.map +1 -0
  137. package/dist/views.d.cts +21 -0
  138. package/dist/views.d.ts +21 -0
  139. package/dist/views.js +26 -0
  140. package/dist/views.js.map +1 -0
  141. package/package.json +158 -0
@@ -0,0 +1,913 @@
1
+ const require_rolldown_runtime = require("./rolldown-runtime-DDXJien1.cjs");
2
+ const require_runtime = require("./runtime.cjs");
3
+ let react_jsx_runtime = require("react/jsx-runtime");
4
+ let react = require("react");
5
+ react = require_rolldown_runtime.__toESM(react, 1);
6
+ let _embedpdf_web = require("@embedpdf/web");
7
+ let _embedpdf_plugin_annotation = require("@embedpdf/plugin-annotation");
8
+ let react_dom = require("react-dom");
9
+ let _embedpdf_plugin_annotation_internal = require("@embedpdf/plugin-annotation/internal");
10
+ let _embedpdf_core_annotation = require("@embedpdf/core-annotation");
11
+ //#region src/internal/annotation-menu-position.ts
12
+ /**
13
+ * Place an upright menu around `box` (screen px). `knob` is the rotate handle's
14
+ * screen point, when the selection has one: the menu extends ONLY the edge it
15
+ * sits on, and ONLY when the knob protrudes past that edge — so it clears the
16
+ * handle without ever shifting off-centre on the other axis. When the knob is on
17
+ * another side (e.g. a 90deg shape, knob at mid-height for a `top` menu) the edge
18
+ * is untouched and the menu stays centred on `box`.
19
+ */
20
+ function positionMenuAroundRect(box, placement, gap, knob) {
21
+ const cx = box.x + box.width / 2;
22
+ const cy = box.y + box.height / 2;
23
+ switch (placement) {
24
+ case "bottom": return {
25
+ left: cx,
26
+ top: Math.max(box.y + box.height, knob ? knob.y : -Infinity) + gap,
27
+ transform: "translate(-50%, 0)"
28
+ };
29
+ case "left": return {
30
+ left: Math.min(box.x, knob ? knob.x : Infinity) - gap,
31
+ top: cy,
32
+ transform: "translate(-100%, -50%)"
33
+ };
34
+ case "right": return {
35
+ left: Math.max(box.x + box.width, knob ? knob.x : -Infinity) + gap,
36
+ top: cy,
37
+ transform: "translate(0, -50%)"
38
+ };
39
+ default: return {
40
+ left: cx,
41
+ top: Math.min(box.y, knob ? knob.y : Infinity) - gap,
42
+ transform: "translate(-50%, -100%)"
43
+ };
44
+ }
45
+ }
46
+ //#endregion
47
+ //#region src/annotation.tsx
48
+ /** `#rrggbb` → `rgba(...)` — the marquee's translucent fill derives from the
49
+ * accent, so one `setChrome({ accent })` restyles every piece of chrome. */
50
+ const rgba = (hex, alpha) => {
51
+ const m = /^#?([0-9a-f]{6})$/i.exec(hex);
52
+ if (!m) return hex;
53
+ const n = parseInt(m[1], 16);
54
+ return `rgba(${n >> 16 & 255},${n >> 8 & 255},${n & 255},${alpha})`;
55
+ };
56
+ /** Content rect → a view-px box (the page wrapper's own coordinate space). */
57
+ function boxOf(r, page) {
58
+ const tl = page.transform.pageToContent({
59
+ x: r.x,
60
+ y: r.y
61
+ });
62
+ const br = page.transform.pageToContent({
63
+ x: r.x + r.width,
64
+ y: r.y + r.height
65
+ });
66
+ return {
67
+ left: tl.x,
68
+ top: tl.y,
69
+ width: br.x - tl.x,
70
+ height: br.y - tl.y
71
+ };
72
+ }
73
+ /** Map a core `Paint` to SVG presentation attributes — the whole framework-facing
74
+ * surface. Everything else about appearance is decided in the core's `scene`. */
75
+ function paintAttrs(p) {
76
+ return {
77
+ fill: p.fill ?? "none",
78
+ stroke: p.stroke ?? "none",
79
+ strokeWidth: p.width,
80
+ opacity: p.opacity,
81
+ strokeLinejoin: p.join ?? "miter",
82
+ strokeMiterlimit: _embedpdf_core_annotation.MITER_LIMIT,
83
+ strokeLinecap: p.cap,
84
+ strokeDasharray: p.dash ? p.dash.join(" ") : void 0,
85
+ ...p.blend ? { style: { mixBlendMode: p.blend } } : {}
86
+ };
87
+ }
88
+ /**
89
+ * The dumb painter. The pure core computed `item.box` and the painted `scene`; we
90
+ * size the <svg> to the box with a content-space `viewBox` and map each SceneNode
91
+ * to one element, applying its `paint`. No per-kind logic, no bounds math — so
92
+ * shapes, cloudy borders and every text-markup type all render here, and a Vue /
93
+ * Svelte painter is the same ~10-line loop.
94
+ */
95
+ function Shape({ item, page }) {
96
+ if (item.box.width <= 0 || item.box.height <= 0) return null;
97
+ const { left, top, width, height } = boxOf(item.box, page);
98
+ const vb = `${item.box.x} ${item.box.y} ${item.box.width} ${item.box.height}`;
99
+ const rot = item.geom.t === "rect" ? item.rot ?? 0 : 0;
100
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
101
+ viewBox: vb,
102
+ style: {
103
+ position: "absolute",
104
+ left,
105
+ top,
106
+ width,
107
+ height,
108
+ overflow: "visible",
109
+ pointerEvents: "none",
110
+ ...rot ? {
111
+ transform: `rotate(${rot}deg)`,
112
+ transformOrigin: "center"
113
+ } : {}
114
+ },
115
+ children: sceneNodes(item)
116
+ });
117
+ }
118
+ /** Map a core scene to SVG children. */
119
+ function sceneNodes(item) {
120
+ return (0, _embedpdf_core_annotation.scene)(item).map((n, i) => {
121
+ const a = paintAttrs(n.paint);
122
+ if (n.kind === "rect") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
123
+ x: n.rect.x,
124
+ y: n.rect.y,
125
+ width: n.rect.width,
126
+ height: n.rect.height,
127
+ ...a
128
+ }, i);
129
+ if (n.kind === "ellipse") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ellipse", {
130
+ cx: n.rect.x + n.rect.width / 2,
131
+ cy: n.rect.y + n.rect.height / 2,
132
+ rx: n.rect.width / 2,
133
+ ry: n.rect.height / 2,
134
+ ...a
135
+ }, i);
136
+ if (n.kind === "line") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
137
+ x1: n.a.x,
138
+ y1: n.a.y,
139
+ x2: n.b.x,
140
+ y2: n.b.y,
141
+ ...a
142
+ }, i);
143
+ if (n.kind === "path") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
144
+ d: n.d,
145
+ ...a
146
+ }, i);
147
+ if (n.kind === "text") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("text", {
148
+ x: n.at.x,
149
+ y: n.at.y,
150
+ fontSize: n.fontSize,
151
+ ...n.fontFamily ? { fontFamily: n.fontFamily } : {},
152
+ ...a,
153
+ children: n.text
154
+ }, i);
155
+ const pts = n.points.map((p) => `${p.x},${p.y}`).join(" ");
156
+ return n.closed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("polygon", {
157
+ points: pts,
158
+ ...a
159
+ }, i) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("polyline", {
160
+ points: pts,
161
+ ...a
162
+ }, i);
163
+ });
164
+ }
165
+ function BakedImage({ box, url, page, blend, rot }) {
166
+ const b = boxOf(box, page);
167
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
168
+ src: url,
169
+ alt: "",
170
+ draggable: false,
171
+ style: {
172
+ position: "absolute",
173
+ left: b.left,
174
+ top: b.top,
175
+ width: b.width,
176
+ height: b.height,
177
+ maxWidth: "none",
178
+ maxHeight: "none",
179
+ pointerEvents: "none",
180
+ mixBlendMode: blend,
181
+ ...rot ? {
182
+ transform: `rotate(${rot}deg)`,
183
+ transformOrigin: "center"
184
+ } : {}
185
+ }
186
+ });
187
+ }
188
+ /**
189
+ * The armed stamp's IMAGE footprint ghost: a translucent render of the payload
190
+ * drawn in the EXACT box a click would place it (the plugin computes it with
191
+ * the same fit + clamp as placement). Vector footprint ghosts never reach this
192
+ * component — they ride `pageItems` like every draft preview. The preview
193
+ * bytes live in the capability closure; this layer owns only the object-URL
194
+ * lifetime, keyed on the arm epoch — a new arm swaps the image, a disarm (or
195
+ * tool change) drops it.
196
+ */
197
+ function ToolGhostImage({ page }) {
198
+ const anno = require_runtime.useCapability(_embedpdf_plugin_annotation_internal.AnnotationToken);
199
+ const ghost = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.toolGhost(page.pon));
200
+ const epoch = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.stampArmEpoch());
201
+ const [url, setUrl] = (0, react.useState)(null);
202
+ (0, react.useEffect)(() => {
203
+ const preview = anno.armedStampPreview();
204
+ if (!preview) {
205
+ setUrl(null);
206
+ return;
207
+ }
208
+ const body = new ArrayBuffer(preview.bytes.byteLength);
209
+ new Uint8Array(body).set(preview.bytes);
210
+ const blob = new Blob([body], preview.mimeType ? { type: preview.mimeType } : {});
211
+ const obj = URL.createObjectURL(blob);
212
+ setUrl(obj);
213
+ return () => {
214
+ URL.revokeObjectURL(obj);
215
+ setUrl(null);
216
+ };
217
+ }, [anno, epoch]);
218
+ if (!ghost || ghost.kind !== "image" || !url) return null;
219
+ const b = boxOf(ghost.box, page);
220
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
221
+ src: url,
222
+ alt: "",
223
+ draggable: false,
224
+ style: {
225
+ position: "absolute",
226
+ left: b.left,
227
+ top: b.top,
228
+ width: b.width,
229
+ height: b.height,
230
+ maxWidth: "none",
231
+ maxHeight: "none",
232
+ pointerEvents: "none",
233
+ opacity: .5,
234
+ ...ghost.rot ? {
235
+ transform: `rotate(${ghost.rot}deg)`,
236
+ transformOrigin: "center"
237
+ } : {}
238
+ }
239
+ });
240
+ }
241
+ function Chrome({ page }) {
242
+ const scale = page.transform.viewScale;
243
+ const rotation = page.transform.rotation;
244
+ const zoom = page.transform.zoom;
245
+ const nodes = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.chrome(page.pon, scale, rotation, zoom), require_runtime.shallowArray);
246
+ const cs = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.chromeSettings());
247
+ const outlineStroke = cs.outline.color ?? cs.accent;
248
+ const handleStroke = cs.handles.stroke ?? cs.accent;
249
+ const knobStroke = cs.knob.stroke ?? cs.accent;
250
+ const outlineDash = cs.outline.style === "dashed" ? "4 3" : void 0;
251
+ const chip = nodes.find((n) => n.kind === "angle-chip");
252
+ const chipAt = chip ? page.transform.pageToContent(chip.at) : null;
253
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
254
+ style: {
255
+ position: "absolute",
256
+ inset: 0,
257
+ overflow: "visible",
258
+ pointerEvents: "none"
259
+ },
260
+ children: nodes.map((n, i) => {
261
+ if (n.kind === "angle-chip") return null;
262
+ if (n.kind === "handle") {
263
+ const p = page.transform.pageToContent(n.at);
264
+ const hs = cs.handles.size;
265
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
266
+ x: p.x - hs / 2,
267
+ y: p.y - hs / 2,
268
+ width: hs,
269
+ height: hs,
270
+ fill: cs.handles.fill,
271
+ stroke: handleStroke,
272
+ strokeWidth: 1.5,
273
+ ...n.rot ? { transform: `rotate(${n.rot} ${p.x} ${p.y})` } : {}
274
+ }, i);
275
+ }
276
+ if (n.kind === "guide") {
277
+ const a = page.transform.pageToContent(n.axis === "x" ? {
278
+ x: n.at,
279
+ y: n.lo
280
+ } : {
281
+ x: n.lo,
282
+ y: n.at
283
+ });
284
+ const b = page.transform.pageToContent(n.axis === "x" ? {
285
+ x: n.at,
286
+ y: n.hi
287
+ } : {
288
+ x: n.hi,
289
+ y: n.at
290
+ });
291
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
292
+ x1: a.x,
293
+ y1: a.y,
294
+ x2: b.x,
295
+ y2: b.y,
296
+ stroke: "#e91e63",
297
+ strokeWidth: 1.5,
298
+ shapeRendering: "crispEdges"
299
+ }, i);
300
+ }
301
+ if (n.kind === "obb") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("polygon", {
302
+ points: n.corners.map((c) => {
303
+ const p = page.transform.pageToContent(c);
304
+ return `${p.x},${p.y}`;
305
+ }).join(" "),
306
+ fill: "none",
307
+ stroke: outlineStroke,
308
+ strokeWidth: cs.outline.width,
309
+ strokeDasharray: outlineDash
310
+ }, i);
311
+ if (n.kind === "rotate-guides") {
312
+ const guideDash = cs.guides.style === "dashed" ? "4 3" : void 0;
313
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("g", { children: n.lines.map((l, j) => {
314
+ const a = page.transform.pageToContent(l.a);
315
+ const b = page.transform.pageToContent(l.b);
316
+ const axis = l.role === "axis";
317
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
318
+ x1: a.x,
319
+ y1: a.y,
320
+ x2: b.x,
321
+ y2: b.y,
322
+ stroke: axis ? cs.guides.axisColor ?? cs.accent : cs.guides.indicatorColor ?? cs.accent,
323
+ opacity: axis ? cs.guides.axisOpacity : cs.guides.indicatorOpacity,
324
+ strokeWidth: cs.guides.width,
325
+ strokeDasharray: guideDash
326
+ }, j);
327
+ }) }, i);
328
+ }
329
+ if (n.kind === "rotate-knob") {
330
+ const at = page.transform.pageToContent(n.at);
331
+ const from = page.transform.pageToContent(n.from);
332
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", { children: [cs.knob.stalk && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
333
+ x1: from.x,
334
+ y1: from.y,
335
+ x2: at.x,
336
+ y2: at.y,
337
+ stroke: knobStroke,
338
+ strokeWidth: 1
339
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
340
+ cx: at.x,
341
+ cy: at.y,
342
+ r: cs.knob.size / 2,
343
+ fill: cs.knob.fill,
344
+ stroke: knobStroke,
345
+ strokeWidth: 1.5
346
+ })] }, i);
347
+ }
348
+ const b = boxOf(n.rect, page);
349
+ if (n.kind === "marquee") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
350
+ x: b.left,
351
+ y: b.top,
352
+ width: b.width,
353
+ height: b.height,
354
+ fill: rgba(cs.accent, .08),
355
+ stroke: cs.accent,
356
+ strokeWidth: 1,
357
+ strokeDasharray: "4 3"
358
+ }, i);
359
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
360
+ x: b.left,
361
+ y: b.top,
362
+ width: b.width,
363
+ height: b.height,
364
+ fill: "none",
365
+ stroke: outlineStroke,
366
+ strokeWidth: cs.outline.width,
367
+ strokeDasharray: outlineDash
368
+ }, i);
369
+ })
370
+ }), chip && chipAt && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
371
+ style: {
372
+ position: "absolute",
373
+ left: chipAt.x + 16,
374
+ top: chipAt.y - 28,
375
+ background: "rgba(0,0,0,0.8)",
376
+ color: "#fff",
377
+ padding: "2px 6px",
378
+ borderRadius: 4,
379
+ fontSize: 12,
380
+ fontFamily: "monospace",
381
+ pointerEvents: "none",
382
+ whiteSpace: "nowrap",
383
+ zIndex: 1
384
+ },
385
+ children: [chip.angle, "°"]
386
+ })] });
387
+ }
388
+ /**
389
+ * A free-text annotation: the SAME styled element for viewing and editing —
390
+ * `contentEditable` just toggles, so the text never jumps. The plugin handed us a
391
+ * ready-to-spread style (`item.css`); the browser owns layout, caret, selection,
392
+ * IME and clipboard; the plugin owns the text truth + the debounced engine write.
393
+ * This component is the ENTIRE per-framework surface for text editing.
394
+ */
395
+ function FreeText({ item, page }) {
396
+ const anno = require_runtime.useCapability(_embedpdf_plugin_annotation_internal.AnnotationToken);
397
+ const ref = react.useRef(null);
398
+ const box = boxOf(item.box, page);
399
+ const scale = item.box.width > 0 ? box.width / item.box.width : 1;
400
+ (0, react.useEffect)(() => {
401
+ const el = ref.current;
402
+ if (el && document.activeElement !== el && el.innerText !== item.contents) el.innerText = item.contents;
403
+ }, [item.contents, item.editing]);
404
+ (0, react.useEffect)(() => {
405
+ if (item.editing) ref.current?.focus();
406
+ }, [item.editing]);
407
+ (0, react.useEffect)(() => {
408
+ const el = ref.current;
409
+ if (!el) return;
410
+ const stop = (e) => e.stopPropagation();
411
+ el.addEventListener("pointerdown", stop);
412
+ return () => el.removeEventListener("pointerdown", stop);
413
+ }, []);
414
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
415
+ ref,
416
+ contentEditable: item.editing,
417
+ suppressContentEditableWarning: true,
418
+ onInput: () => item.ref && anno.setContents(item.ref, ref.current.innerText),
419
+ onBlur: (e) => {
420
+ if (e.relatedTarget == null && ref.current?.isConnected && anno.currentEditing() === item.id) ref.current.focus();
421
+ },
422
+ onPaste: (e) => {
423
+ e.preventDefault();
424
+ document.execCommand("insertText", false, e.clipboardData.getData("text/plain"));
425
+ },
426
+ style: {
427
+ position: "absolute",
428
+ left: box.left,
429
+ top: box.top,
430
+ width: box.width,
431
+ height: box.height,
432
+ fontFamily: item.css.fontFamily,
433
+ fontSize: item.css.fontSize * scale,
434
+ lineHeight: `${item.css.lineHeight * scale}px`,
435
+ color: item.css.color,
436
+ textAlign: item.css.align,
437
+ padding: item.css.padding * scale,
438
+ boxSizing: "border-box",
439
+ background: item.css.background ?? "transparent",
440
+ whiteSpace: "pre-wrap",
441
+ overflowWrap: "break-word",
442
+ overflowY: item.editing ? "auto" : "hidden",
443
+ overflowX: "hidden",
444
+ outline: item.editing ? "1px solid #3858e9" : "none",
445
+ cursor: item.editing ? "text" : "default",
446
+ ...item.rot ? {
447
+ transform: `rotate(${item.rot}deg)`,
448
+ transformOrigin: "center"
449
+ } : {},
450
+ pointerEvents: item.editing ? "auto" : "none"
451
+ }
452
+ });
453
+ }
454
+ /**
455
+ * Auto-registered behaviors for `interactive` renderer entries — refcounted
456
+ * per (capability, entry) because the layer mounts once PER PAGE: the first
457
+ * page registers, the last unregisters. Entry identity is the key, hence the
458
+ * "define entries outside render" rule on {@link AnnotationRenderer}.
459
+ */
460
+ const autoBehaviors = /* @__PURE__ */ new WeakMap();
461
+ let autoBehaviorSeq = 0;
462
+ function useAutoBehaviors(anno, renderers) {
463
+ (0, react.useEffect)(() => {
464
+ if (!renderers) return;
465
+ const released = [];
466
+ for (const r of renderers) {
467
+ if (!("for" in r) || !r.interactive) continue;
468
+ let perCap = autoBehaviors.get(anno);
469
+ if (!perCap) autoBehaviors.set(anno, perCap = /* @__PURE__ */ new Map());
470
+ let rec = perCap.get(r);
471
+ if (!rec) {
472
+ const id = r.id ?? `renderer:${++autoBehaviorSeq}`;
473
+ const engaged = typeof r.interactive === "function" ? r.interactive : () => true;
474
+ rec = {
475
+ id,
476
+ count: 0,
477
+ unregister: anno.registerBehavior({
478
+ id,
479
+ matches: r.for,
480
+ engaged
481
+ })
482
+ };
483
+ perCap.set(r, rec);
484
+ }
485
+ rec.count++;
486
+ const owned = rec;
487
+ released.push(() => {
488
+ owned.count--;
489
+ if (owned.count === 0) {
490
+ owned.unregister();
491
+ autoBehaviors.get(anno)?.delete(r);
492
+ }
493
+ });
494
+ }
495
+ return () => released.forEach((f) => f());
496
+ }, [anno, renderers]);
497
+ }
498
+ /** The behavior id a renderer entry answers for (plugin-owned or auto-registered). */
499
+ function rendererBehaviorId(anno, r) {
500
+ if ("behavior" in r) return r.behavior;
501
+ return autoBehaviors.get(anno)?.get(r)?.id ?? null;
502
+ }
503
+ /** React 18 spells the `inert` attribute as a string spread; it hard-disables
504
+ * pointer AND focus for the whole subtree — the mechanical guarantee that a
505
+ * non-interactive renderer entry (a skin) can never steal input. */
506
+ const INERT = { inert: "" };
507
+ function AnnotationLayer({ renderers } = {}) {
508
+ const page = require_runtime.usePage();
509
+ const anno = require_runtime.useCapability(_embedpdf_plugin_annotation_internal.AnnotationToken);
510
+ const viewZoom = page.transform.zoom;
511
+ const viewRotation = page.transform.rotation;
512
+ const items = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.pageItems(page.pon, {
513
+ zoom: viewZoom,
514
+ rotation: viewRotation
515
+ }), require_runtime.shallowArray);
516
+ const texts = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.textItems(page.pon, {
517
+ zoom: viewZoom,
518
+ rotation: viewRotation
519
+ }), require_runtime.shallowArray);
520
+ const [urls, setUrls] = (0, react.useState)({});
521
+ useAutoBehaviors(anno, renderers);
522
+ (0, react.useEffect)(() => {
523
+ anno.ensurePage(page.pon);
524
+ }, [anno, page.pon]);
525
+ const bakedKey = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.appearanceEpoch(page.pon));
526
+ const bakeScale = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.bakeScale(page.transform.renderScale));
527
+ (0, react.useEffect)(() => {
528
+ const controller = new AbortController();
529
+ const revokers = [];
530
+ (async () => {
531
+ try {
532
+ const imgs = await anno.appearances(page.pon, bakeScale, controller.signal);
533
+ const map = {};
534
+ for (const ap of imgs) {
535
+ const box = anno.toContentBox(page.pon, ap.rect);
536
+ if (!box) continue;
537
+ const obj = await ap.image.objectUrl(controller.signal);
538
+ if (controller.signal.aborted) {
539
+ obj.revoke();
540
+ return;
541
+ }
542
+ revokers.push(obj.revoke);
543
+ map[(0, _embedpdf_plugin_annotation.refKey)(ap.ref)] = {
544
+ url: obj.url,
545
+ box
546
+ };
547
+ }
548
+ if (!controller.signal.aborted) setUrls(map);
549
+ } catch {}
550
+ })();
551
+ return () => {
552
+ controller.abort();
553
+ revokers.forEach((r) => r());
554
+ };
555
+ }, [
556
+ anno,
557
+ page.pon,
558
+ bakeScale,
559
+ bakedKey
560
+ ]);
561
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
562
+ style: {
563
+ position: "absolute",
564
+ inset: 0,
565
+ pointerEvents: "none"
566
+ },
567
+ children: [
568
+ items.map((item) => {
569
+ const baked = urls[item.id];
570
+ const native = item.source === "baked" ? baked ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BakedImage, {
571
+ box: item.apBox ?? baked.box,
572
+ url: baked.url,
573
+ page,
574
+ blend: item.blend,
575
+ rot: item.apRot
576
+ }) : null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Shape, {
577
+ item,
578
+ page
579
+ });
580
+ const behavior = anno.behaviorFor({
581
+ subtype: item.subtype,
582
+ ref: item.ref
583
+ });
584
+ let out;
585
+ if (behavior) {
586
+ const entry = renderers?.find((r) => rendererBehaviorId(anno, r) === behavior.id);
587
+ if (entry) {
588
+ const Owner = entry.component;
589
+ out = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Owner, {
590
+ item,
591
+ page,
592
+ appearance: baked ?? null,
593
+ native,
594
+ interactive: true
595
+ });
596
+ } else out = null;
597
+ } else {
598
+ const entry = renderers?.find((r) => "for" in r && r.for({
599
+ subtype: item.subtype,
600
+ ref: item.ref
601
+ }));
602
+ if (entry) {
603
+ const Skin = entry.component;
604
+ out = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
605
+ ...INERT,
606
+ style: { pointerEvents: "none" },
607
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Skin, {
608
+ item,
609
+ page,
610
+ appearance: baked ?? null,
611
+ native,
612
+ interactive: false
613
+ })
614
+ });
615
+ } else out = native;
616
+ }
617
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: out }, item.id);
618
+ }),
619
+ texts.map((t) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FreeText, {
620
+ item: t,
621
+ page
622
+ }, t.id)),
623
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolGhostImage, { page }),
624
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chrome, { page })
625
+ ]
626
+ });
627
+ }
628
+ /**
629
+ * The default file-picker provider: the built-in file dialog (from
630
+ * `@embedpdf/web`), honouring the tool's `accept` filter. This is the ADAPTER
631
+ * fulfilling the plugin's DOM-free port — the dialog lives here, in the
632
+ * framework layer, never in the plugin. A picked `File` carries its own name
633
+ * and mime, so it goes straight through as the engine's file source.
634
+ */
635
+ const filePickerProvider = async (req) => {
636
+ const file = await (0, _embedpdf_web.pickFile)({ accept: req.accept ?? "*/*" });
637
+ return file ? { data: file } : null;
638
+ };
639
+ /**
640
+ * Install the file-picker provider for the active document — the ONE port
641
+ * behind every click-then-pick tool (a stamp `'prompt'` source, the file-
642
+ * attachment tool). Call ONCE at a document-scoped spot (not inside
643
+ * `<AnnotationLayer>`, which is per page). Defaults to
644
+ * {@link filePickerProvider}, so a bare `useFilePickerProvider()` makes all of
645
+ * them work out of the box; pass a custom provider (asset library, cloud
646
+ * drive — switch on `req.subtype` / `req.toolId`) or `null` to make
647
+ * click-then-pick tools inert. Cleared on unmount.
648
+ */
649
+ function useFilePickerProvider(provider = filePickerProvider) {
650
+ const anno = require_runtime.useOptionalCapability(_embedpdf_plugin_annotation.AnnotationToken);
651
+ (0, react.useEffect)(() => {
652
+ if (!anno) return;
653
+ anno.setFilePickerProvider(provider);
654
+ return () => anno.setFilePickerProvider(null);
655
+ }, [anno, provider]);
656
+ }
657
+ function useAnnotation() {
658
+ return require_runtime.useCapability(_embedpdf_plugin_annotation.AnnotationToken);
659
+ }
660
+ function useAnnotationSelection() {
661
+ return require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.selection(), require_runtime.shallowArray);
662
+ }
663
+ /** The selected annotations as engine DTOs — for selection-aware toolbars/sidebars. */
664
+ function useAnnotationSelected() {
665
+ return require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.getSelected(), require_runtime.shallowArray);
666
+ }
667
+ /** Structural equality for a resolved props bag — keeps the subscription from
668
+ * re-rendering on unrelated dispatches, since `currentDefaults` returns a fresh
669
+ * object each call. Small flat objects; JSON compare is exact and cheap here. */
670
+ const sameProps = (a, b) => a === b || JSON.stringify(a) === JSON.stringify(b);
671
+ /**
672
+ * A tool's RESOLVED defaults (base + per-tool override) as a full flat props
673
+ * bag, subscribed so a `setDefaults` re-renders the consumer. Use this — not the
674
+ * imperative `useAnnotation().currentDefaults(id)` — to drive default-editing
675
+ * controls, so they reflect changes live. Pair with `propsForTool(id)` for the
676
+ * specs to render.
677
+ */
678
+ function useAnnotationDefaults(toolId) {
679
+ return require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.currentDefaults(toolId), sameProps);
680
+ }
681
+ /**
682
+ * The selection's editable properties — ordered specs shared by every selected
683
+ * kind, current values, and which keys are mixed. THE hook a property sidebar
684
+ * renders from; write back with `useAnnotation().updateSelection({ [key]: v })`.
685
+ * Reference-stable between model changes (the capability memoizes by model
686
+ * identity), so the default equality is enough.
687
+ */
688
+ function useSelectionProps() {
689
+ return require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.getSelectionProps());
690
+ }
691
+ /**
692
+ * The selection's `/F` annotation flags — per-flag `true`/`false`, `null` where
693
+ * the selected annotations disagree (render an indeterminate control), `null`
694
+ * overall when nothing is selected. Write back with
695
+ * `useAnnotation().updateSelectionFlags({ locked: true })`. Reference-stable
696
+ * between model changes, like {@link useSelectionProps}.
697
+ */
698
+ function useSelectionFlags() {
699
+ return require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.getSelectionFlags());
700
+ }
701
+ /** Structural equality for the selection anchor — keeps the menu from re-rendering
702
+ * on unrelated dispatches (the capability returns a fresh object each call). */
703
+ function sameAnchor(a, b) {
704
+ if (a === b) return true;
705
+ if (!a || !b) return false;
706
+ return a.pon === b.pon && a.bounds.x === b.bounds.x && a.bounds.y === b.bounds.y && a.bounds.width === b.bounds.width && a.bounds.height === b.bounds.height && a.knob?.x === b.knob?.x && a.knob?.y === b.knob?.y;
707
+ }
708
+ function sameCreationDraftAnchor(a, b) {
709
+ if (a === b) return true;
710
+ if (!a || !b) return false;
711
+ return a.kind === b.kind && a.subtype === b.subtype && a.pon === b.pon && a.pointCount === b.pointCount && a.minPoints === b.minPoints && a.canFinish === b.canFinish && a.bounds.x === b.bounds.x && a.bounds.y === b.bounds.y && a.bounds.width === b.bounds.width && a.bounds.height === b.bounds.height;
712
+ }
713
+ /**
714
+ * The Stage-FREE selection menu, for `<PageView>` (no camera). It transforms a
715
+ * selected content rect to client px via `page.toClientRect`, then renders an
716
+ * UPRIGHT menu through a portal to
717
+ * `document.body` (so it never rotates with the page nor clips at a container
718
+ * edge). Re-measures on scroll/resize. For `<Stage>`, prefer `<AnnotationMenu>`
719
+ * from `@embedpdf/react/annotation-menu` (camera-driven, more responsive).
720
+ */
721
+ function PageAnnotationMenu({ children, gap = 8, placement = "top" }) {
722
+ const page = require_runtime.usePage();
723
+ const anno = require_runtime.useCapability(_embedpdf_plugin_annotation_internal.AnnotationToken);
724
+ const anchor = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.selectionAnchor(page.transform.viewScale, page.transform.rotation, page.transform.zoom), sameAnchor);
725
+ const selected = useAnnotationSelected();
726
+ const [pos, setPos] = (0, react.useState)(null);
727
+ const here = !!anchor && anchor.pon === page.pon;
728
+ (0, react.useLayoutEffect)(() => {
729
+ if (!here || !anchor) {
730
+ setPos(null);
731
+ return;
732
+ }
733
+ const measure = () => {
734
+ const knob = anchor.knob ? page.toClientPoint(anchor.knob) : null;
735
+ setPos(positionMenuAroundRect(page.toClientRect(anchor.bounds), placement, gap, knob));
736
+ };
737
+ measure();
738
+ window.addEventListener("scroll", measure, true);
739
+ window.addEventListener("resize", measure);
740
+ return () => {
741
+ window.removeEventListener("scroll", measure, true);
742
+ window.removeEventListener("resize", measure);
743
+ };
744
+ }, [
745
+ here,
746
+ anchor,
747
+ page,
748
+ gap,
749
+ placement
750
+ ]);
751
+ if (!pos) return null;
752
+ return (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
753
+ style: {
754
+ position: "fixed",
755
+ left: pos.left,
756
+ top: pos.top,
757
+ transform: pos.transform,
758
+ pointerEvents: "auto"
759
+ },
760
+ children: children({
761
+ selected,
762
+ deleteSelection: anno.deleteSelection,
763
+ deselect: anno.deselect,
764
+ updateSelection: anno.updateSelection,
765
+ rotate90: anno.rotateSelection90,
766
+ resetRotation: anno.resetSelectionRotation,
767
+ group: anno.group,
768
+ ungroup: anno.ungroup,
769
+ canGroup: anno.canGroup(),
770
+ canUngroup: anno.canUngroup()
771
+ })
772
+ }), document.body);
773
+ }
774
+ function PageAnnotationDraftMenu({ children, gap = 8, placement = "top" }) {
775
+ const page = require_runtime.usePage();
776
+ const anno = require_runtime.useCapability(_embedpdf_plugin_annotation_internal.AnnotationToken);
777
+ const anchor = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.creationDraftAnchor(), sameCreationDraftAnchor);
778
+ const [pos, setPos] = (0, react.useState)(null);
779
+ const ref = react.useRef(null);
780
+ const here = !!anchor && anchor.pon === page.pon;
781
+ (0, react.useEffect)(() => {
782
+ const el = ref.current;
783
+ if (!el) return;
784
+ const stop = (e) => e.stopPropagation();
785
+ el.addEventListener("pointerdown", stop);
786
+ return () => el.removeEventListener("pointerdown", stop);
787
+ });
788
+ (0, react.useLayoutEffect)(() => {
789
+ if (!here || !anchor) {
790
+ setPos(null);
791
+ return;
792
+ }
793
+ const measure = () => {
794
+ setPos(positionMenuAroundRect(page.toClientRect(anchor.bounds), placement, gap));
795
+ };
796
+ measure();
797
+ window.addEventListener("scroll", measure, true);
798
+ window.addEventListener("resize", measure);
799
+ return () => {
800
+ window.removeEventListener("scroll", measure, true);
801
+ window.removeEventListener("resize", measure);
802
+ };
803
+ }, [
804
+ here,
805
+ anchor,
806
+ page,
807
+ gap,
808
+ placement
809
+ ]);
810
+ if (!anchor || !pos) return null;
811
+ return (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
812
+ ref,
813
+ style: {
814
+ position: "fixed",
815
+ left: pos.left,
816
+ top: pos.top,
817
+ transform: pos.transform,
818
+ pointerEvents: "auto"
819
+ },
820
+ children: children({
821
+ ...anchor,
822
+ finish: anno.finishCreationDraft,
823
+ cancel: anno.cancelCreationDraft
824
+ })
825
+ }), document.body);
826
+ }
827
+ //#endregion
828
+ Object.defineProperty(exports, "AnnotationLayer", {
829
+ enumerable: true,
830
+ get: function() {
831
+ return AnnotationLayer;
832
+ }
833
+ });
834
+ Object.defineProperty(exports, "PageAnnotationDraftMenu", {
835
+ enumerable: true,
836
+ get: function() {
837
+ return PageAnnotationDraftMenu;
838
+ }
839
+ });
840
+ Object.defineProperty(exports, "PageAnnotationMenu", {
841
+ enumerable: true,
842
+ get: function() {
843
+ return PageAnnotationMenu;
844
+ }
845
+ });
846
+ Object.defineProperty(exports, "filePickerProvider", {
847
+ enumerable: true,
848
+ get: function() {
849
+ return filePickerProvider;
850
+ }
851
+ });
852
+ Object.defineProperty(exports, "positionMenuAroundRect", {
853
+ enumerable: true,
854
+ get: function() {
855
+ return positionMenuAroundRect;
856
+ }
857
+ });
858
+ Object.defineProperty(exports, "sameAnchor", {
859
+ enumerable: true,
860
+ get: function() {
861
+ return sameAnchor;
862
+ }
863
+ });
864
+ Object.defineProperty(exports, "sameCreationDraftAnchor", {
865
+ enumerable: true,
866
+ get: function() {
867
+ return sameCreationDraftAnchor;
868
+ }
869
+ });
870
+ Object.defineProperty(exports, "useAnnotation", {
871
+ enumerable: true,
872
+ get: function() {
873
+ return useAnnotation;
874
+ }
875
+ });
876
+ Object.defineProperty(exports, "useAnnotationDefaults", {
877
+ enumerable: true,
878
+ get: function() {
879
+ return useAnnotationDefaults;
880
+ }
881
+ });
882
+ Object.defineProperty(exports, "useAnnotationSelected", {
883
+ enumerable: true,
884
+ get: function() {
885
+ return useAnnotationSelected;
886
+ }
887
+ });
888
+ Object.defineProperty(exports, "useAnnotationSelection", {
889
+ enumerable: true,
890
+ get: function() {
891
+ return useAnnotationSelection;
892
+ }
893
+ });
894
+ Object.defineProperty(exports, "useFilePickerProvider", {
895
+ enumerable: true,
896
+ get: function() {
897
+ return useFilePickerProvider;
898
+ }
899
+ });
900
+ Object.defineProperty(exports, "useSelectionFlags", {
901
+ enumerable: true,
902
+ get: function() {
903
+ return useSelectionFlags;
904
+ }
905
+ });
906
+ Object.defineProperty(exports, "useSelectionProps", {
907
+ enumerable: true,
908
+ get: function() {
909
+ return useSelectionProps;
910
+ }
911
+ });
912
+
913
+ //# sourceMappingURL=annotation-Ct6dFtzJ.cjs.map