@embedpdf/react 3.0.0-next.3 → 3.0.0-next.5

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