@embedpdf/react 3.0.0-next.13 → 3.0.0-next.15
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.
- package/dist/AnnotationList-CkijRHet-HEFNUIZe.d.cts +877 -0
- package/dist/AnnotationList-CkijRHet-HEFNUIZe.d.ts +877 -0
- package/dist/actions.cjs +25 -5
- package/dist/actions.cjs.map +1 -1
- package/dist/actions.d.cts +18 -5
- package/dist/actions.d.ts +18 -5
- package/dist/actions.js +22 -6
- package/dist/actions.js.map +1 -1
- package/dist/anchored-DeX95xSd.d.ts +85 -0
- package/dist/anchored-DzN3JywS.d.cts +85 -0
- package/dist/anchored.cjs +71 -28
- package/dist/anchored.cjs.map +1 -1
- package/dist/anchored.d.cts +2 -45
- package/dist/anchored.d.ts +2 -45
- package/dist/anchored.js +56 -19
- package/dist/anchored.js.map +1 -1
- package/dist/annotation-B48UT2ln.d.ts +302 -0
- package/dist/annotation-C1ttM8Wj.js +708 -0
- package/dist/annotation-C1ttM8Wj.js.map +1 -0
- package/dist/annotation-C9dVwo9b.d.cts +302 -0
- package/dist/annotation-Dex5EBda.cjs +830 -0
- package/dist/annotation-Dex5EBda.cjs.map +1 -0
- package/dist/annotation.cjs +20 -783
- package/dist/annotation.d.cts +2 -2
- package/dist/annotation.d.ts +2 -2
- package/dist/annotation.js +2 -768
- package/dist/commands.cjs +68 -28
- package/dist/commands.cjs.map +1 -1
- package/dist/commands.d.cts +37 -10
- package/dist/commands.d.ts +37 -10
- package/dist/commands.js +68 -31
- package/dist/commands.js.map +1 -1
- package/dist/form-55izw0jS.js +511 -0
- package/dist/form-55izw0jS.js.map +1 -0
- package/dist/form-BNqQfGGH.cjs +548 -0
- package/dist/form-BNqQfGGH.cjs.map +1 -0
- package/dist/form.cjs +5 -5
- package/dist/form.d.cts +32 -25
- package/dist/form.d.ts +32 -25
- package/dist/form.js +2 -3
- package/dist/history.cjs +38 -0
- package/dist/history.cjs.map +1 -0
- package/dist/history.d.cts +27 -0
- package/dist/history.d.ts +27 -0
- package/dist/history.js +27 -0
- package/dist/history.js.map +1 -0
- package/dist/i18n.cjs +26 -30
- package/dist/i18n.cjs.map +1 -1
- package/dist/i18n.d.cts +24 -21
- package/dist/i18n.d.ts +24 -21
- package/dist/i18n.js +24 -31
- package/dist/i18n.js.map +1 -1
- package/dist/index.cjs +213 -57
- package/dist/index.d.cts +32 -31
- package/dist/index.d.ts +32 -31
- package/dist/index.js +33 -29
- package/dist/inert-CmBEbKCn.cjs +19 -0
- package/dist/inert-CmBEbKCn.cjs.map +1 -0
- package/dist/inert-D8fkennb.js +14 -0
- package/dist/inert-D8fkennb.js.map +1 -0
- package/dist/interaction.cjs +48 -102
- package/dist/interaction.cjs.map +1 -1
- package/dist/interaction.d.cts +23 -32
- package/dist/interaction.d.ts +23 -32
- package/dist/interaction.js +33 -102
- package/dist/interaction.js.map +1 -1
- package/dist/link.cjs +65 -104
- package/dist/link.cjs.map +1 -1
- package/dist/link.d.cts +21 -16
- package/dist/link.d.ts +22 -17
- package/dist/link.js +67 -107
- package/dist/link.js.map +1 -1
- package/dist/measurement.cjs +56 -0
- package/dist/measurement.cjs.map +1 -0
- package/dist/measurement.d.cts +38 -0
- package/dist/measurement.d.ts +38 -0
- package/dist/measurement.js +42 -0
- package/dist/measurement.js.map +1 -0
- package/dist/metadata.cjs +20 -7
- package/dist/metadata.cjs.map +1 -1
- package/dist/metadata.d.cts +22 -7
- package/dist/metadata.d.ts +22 -7
- package/dist/metadata.js +20 -10
- package/dist/metadata.js.map +1 -1
- package/dist/page-edit.cjs +7 -3
- package/dist/page-edit.cjs.map +1 -1
- package/dist/page-edit.d.cts +6 -2
- package/dist/page-edit.d.ts +6 -2
- package/dist/page-edit.js +7 -4
- package/dist/page-edit.js.map +1 -1
- package/dist/page-layers-Bkaaz8Zf.js +26 -0
- package/dist/page-layers-Bkaaz8Zf.js.map +1 -0
- package/dist/page-layers-BloZDoOV.cjs +37 -0
- package/dist/page-layers-BloZDoOV.cjs.map +1 -0
- package/dist/page-view.cjs +89 -82
- package/dist/page-view.cjs.map +1 -1
- package/dist/page-view.d.cts +14 -7
- package/dist/page-view.d.ts +18 -11
- package/dist/page-view.js +86 -81
- package/dist/page-view.js.map +1 -1
- package/dist/redaction.cjs +30 -15
- package/dist/redaction.cjs.map +1 -1
- package/dist/redaction.d.cts +27 -9
- package/dist/redaction.d.ts +27 -9
- package/dist/redaction.js +29 -18
- package/dist/redaction.js.map +1 -1
- package/dist/render.cjs +71 -46
- package/dist/render.cjs.map +1 -1
- package/dist/render.d.cts +17 -5
- package/dist/render.d.ts +17 -5
- package/dist/render.js +70 -49
- package/dist/render.js.map +1 -1
- package/dist/runtime-B6xcPsEb.js +398 -0
- package/dist/runtime-B6xcPsEb.js.map +1 -0
- package/dist/runtime-DBEBlpQV.d.cts +237 -0
- package/dist/runtime-V3MVMb91.d.ts +237 -0
- package/dist/runtime-fzpGv78v.cjs +555 -0
- package/dist/runtime-fzpGv78v.cjs.map +1 -0
- package/dist/runtime.cjs +45 -324
- package/dist/runtime.d.cts +2 -2
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.js +2 -306
- package/dist/search.cjs +81 -50
- package/dist/search.cjs.map +1 -1
- package/dist/search.d.cts +36 -24
- package/dist/search.d.ts +36 -24
- package/dist/search.js +81 -53
- package/dist/search.js.map +1 -1
- package/dist/selection.cjs +105 -108
- package/dist/selection.cjs.map +1 -1
- package/dist/selection.d.cts +54 -26
- package/dist/selection.d.ts +56 -28
- package/dist/selection.js +103 -110
- package/dist/selection.js.map +1 -1
- package/dist/shell.cjs +36 -21
- package/dist/shell.cjs.map +1 -1
- package/dist/shell.d.cts +32 -17
- package/dist/shell.d.ts +32 -17
- package/dist/shell.js +36 -24
- package/dist/shell.js.map +1 -1
- package/dist/signature.cjs +29 -48
- package/dist/signature.cjs.map +1 -1
- package/dist/signature.d.cts +26 -26
- package/dist/signature.d.ts +26 -26
- package/dist/signature.js +30 -48
- package/dist/signature.js.map +1 -1
- package/dist/stage-BIG6aeVd.cjs +369 -0
- package/dist/stage-BIG6aeVd.cjs.map +1 -0
- package/dist/stage-ByFPD-Fv.d.cts +117 -0
- package/dist/stage-DaboaheR.d.ts +117 -0
- package/dist/stage-DoVekb83.js +302 -0
- package/dist/stage-DoVekb83.js.map +1 -0
- package/dist/stage-scope-CQgCuf1w.cjs +46 -0
- package/dist/stage-scope-CQgCuf1w.cjs.map +1 -0
- package/dist/stage-scope-D7ZeNduT.js +23 -0
- package/dist/stage-scope-D7ZeNduT.js.map +1 -0
- package/dist/stage.cjs +12 -235
- package/dist/stage.d.cts +2 -116
- package/dist/stage.d.ts +2 -116
- package/dist/stage.js +3 -228
- package/dist/stamp.cjs +41 -35
- package/dist/stamp.cjs.map +1 -1
- package/dist/stamp.d.cts +25 -18
- package/dist/stamp.d.ts +25 -18
- package/dist/stamp.js +40 -37
- package/dist/stamp.js.map +1 -1
- package/dist/state-0K1I5cM4.d.cts +29 -0
- package/dist/state-0K1I5cM4.d.ts +29 -0
- package/dist/state-CbgxhwLA.js +62 -0
- package/dist/state-CbgxhwLA.js.map +1 -0
- package/dist/state-CsfZy_Eq.cjs +73 -0
- package/dist/state-CsfZy_Eq.cjs.map +1 -0
- package/dist/svg-shapes-Dm1yTR1b.js +40 -0
- package/dist/svg-shapes-Dm1yTR1b.js.map +1 -0
- package/dist/svg-shapes-zo0GNkc9.cjs +53 -0
- package/dist/svg-shapes-zo0GNkc9.cjs.map +1 -0
- package/dist/toolbar.cjs +297 -295
- package/dist/toolbar.cjs.map +1 -1
- package/dist/toolbar.d.cts +58 -68
- package/dist/toolbar.d.ts +67 -77
- package/dist/toolbar.js +271 -293
- package/dist/toolbar.js.map +1 -1
- package/dist/view-manager.cjs +34 -0
- package/dist/view-manager.cjs.map +1 -0
- package/dist/view-manager.d.cts +21 -0
- package/dist/view-manager.d.ts +21 -0
- package/dist/view-manager.js +23 -0
- package/dist/view-manager.js.map +1 -0
- package/package.json +41 -38
- package/dist/AnnotationListSnapshot-D3mFut1e-C_GMpK25.d.cts +0 -546
- package/dist/AnnotationListSnapshot-D3mFut1e-C_GMpK25.d.ts +0 -546
- package/dist/annotation-BCED_p9H.d.cts +0 -160
- package/dist/annotation-anchors-CetwM1g7.js +0 -15
- package/dist/annotation-anchors-CetwM1g7.js.map +0 -1
- package/dist/annotation-anchors-DuYRBJLl.cjs +0 -26
- package/dist/annotation-anchors-DuYRBJLl.cjs.map +0 -1
- package/dist/annotation-hooks-BB5ZhPpf.cjs +0 -16
- package/dist/annotation-hooks-BB5ZhPpf.cjs.map +0 -1
- package/dist/annotation-hooks-Df8EmzDO.js +0 -11
- package/dist/annotation-hooks-Df8EmzDO.js.map +0 -1
- package/dist/annotation-k38KDlIZ.d.ts +0 -160
- package/dist/annotation-menu.cjs +0 -64
- package/dist/annotation-menu.cjs.map +0 -1
- package/dist/annotation-menu.d.cts +0 -33
- package/dist/annotation-menu.d.ts +0 -33
- package/dist/annotation-menu.js +0 -48
- package/dist/annotation-menu.js.map +0 -1
- package/dist/annotation.cjs.map +0 -1
- package/dist/annotation.js.map +0 -1
- package/dist/form-BVumS7up.cjs +0 -926
- package/dist/form-BVumS7up.cjs.map +0 -1
- package/dist/form-CK3mp99m.js +0 -895
- package/dist/form-CK3mp99m.js.map +0 -1
- package/dist/rolldown-runtime-BBjsoOtd.js +0 -27
- package/dist/runtime-DE76hlnl.d.ts +0 -216
- package/dist/runtime-umHA_xHt.d.cts +0 -216
- package/dist/runtime.cjs.map +0 -1
- package/dist/runtime.js.map +0 -1
- package/dist/scrollbar.cjs +0 -241
- package/dist/scrollbar.cjs.map +0 -1
- package/dist/scrollbar.d.cts +0 -42
- package/dist/scrollbar.d.ts +0 -42
- package/dist/scrollbar.js +0 -213
- package/dist/scrollbar.js.map +0 -1
- package/dist/stage.cjs.map +0 -1
- package/dist/stage.js.map +0 -1
- package/dist/views.cjs +0 -35
- package/dist/views.cjs.map +0 -1
- package/dist/views.d.cts +0 -21
- package/dist/views.d.ts +0 -21
- package/dist/views.js +0 -27
- package/dist/views.js.map +0 -1
package/dist/annotation.cjs
CHANGED
|
@@ -1,785 +1,24 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
const bucket = ghost?.kind === "image" ? (0, _embedpdf_plugin_annotation.previewBucket)(ghost.box.width * page.transform.renderScale) : 0;
|
|
169
|
-
(0, react.useEffect)(() => {
|
|
170
|
-
if (!bucket) {
|
|
171
|
-
setUrl(null);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
let cancelled = false;
|
|
175
|
-
let obj = null;
|
|
176
|
-
anno.armedStampPreview(bucket).then((preview) => {
|
|
177
|
-
if (cancelled || !preview) return;
|
|
178
|
-
const body = new ArrayBuffer(preview.bytes.byteLength);
|
|
179
|
-
new Uint8Array(body).set(preview.bytes);
|
|
180
|
-
const blob = new Blob([body], preview.mimeType ? { type: preview.mimeType } : {});
|
|
181
|
-
obj = URL.createObjectURL(blob);
|
|
182
|
-
setUrl(obj);
|
|
183
|
-
});
|
|
184
|
-
return () => {
|
|
185
|
-
cancelled = true;
|
|
186
|
-
if (obj) URL.revokeObjectURL(obj);
|
|
187
|
-
};
|
|
188
|
-
}, [
|
|
189
|
-
anno,
|
|
190
|
-
epoch,
|
|
191
|
-
bucket
|
|
192
|
-
]);
|
|
193
|
-
if (!ghost || ghost.kind !== "image" || !url) return null;
|
|
194
|
-
const b = boxOf(ghost.box, page);
|
|
195
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
|
|
196
|
-
src: url,
|
|
197
|
-
alt: "",
|
|
198
|
-
draggable: false,
|
|
199
|
-
style: {
|
|
200
|
-
position: "absolute",
|
|
201
|
-
left: b.left,
|
|
202
|
-
top: b.top,
|
|
203
|
-
width: b.width,
|
|
204
|
-
height: b.height,
|
|
205
|
-
maxWidth: "none",
|
|
206
|
-
maxHeight: "none",
|
|
207
|
-
pointerEvents: "none",
|
|
208
|
-
opacity: .5,
|
|
209
|
-
...ghost.rot ? {
|
|
210
|
-
transform: `rotate(${ghost.rot}deg)`,
|
|
211
|
-
transformOrigin: "center"
|
|
212
|
-
} : {}
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
function Chrome({ page }) {
|
|
217
|
-
const scale = page.transform.viewScale;
|
|
218
|
-
const rotation = page.transform.rotation;
|
|
219
|
-
const zoom = page.transform.zoom;
|
|
220
|
-
const nodes = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.chrome(page.pon, scale, rotation, zoom), require_runtime.shallowArray);
|
|
221
|
-
const cs = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.chromeSettings());
|
|
222
|
-
const outlineStroke = cs.outline.color ?? cs.accent;
|
|
223
|
-
const handleStroke = cs.handles.stroke ?? cs.accent;
|
|
224
|
-
const knobStroke = cs.knob.stroke ?? cs.accent;
|
|
225
|
-
const outlineDash = cs.outline.style === "dashed" ? "4 3" : void 0;
|
|
226
|
-
const chip = nodes.find((n) => n.kind === "angle-chip");
|
|
227
|
-
const chipAt = chip ? page.transform.toPixels(chip.at) : null;
|
|
228
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
229
|
-
style: {
|
|
230
|
-
position: "absolute",
|
|
231
|
-
inset: 0,
|
|
232
|
-
overflow: "visible",
|
|
233
|
-
pointerEvents: "none"
|
|
234
|
-
},
|
|
235
|
-
children: nodes.map((n, i) => {
|
|
236
|
-
if (n.kind === "angle-chip") return null;
|
|
237
|
-
if (n.kind === "handle") {
|
|
238
|
-
const p = page.transform.toPixels(n.at);
|
|
239
|
-
const hs = cs.handles.size;
|
|
240
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
|
|
241
|
-
x: p.x - hs / 2,
|
|
242
|
-
y: p.y - hs / 2,
|
|
243
|
-
width: hs,
|
|
244
|
-
height: hs,
|
|
245
|
-
fill: cs.handles.fill,
|
|
246
|
-
stroke: handleStroke,
|
|
247
|
-
strokeWidth: 1.5,
|
|
248
|
-
...n.rot ? { transform: `rotate(${n.rot} ${p.x} ${p.y})` } : {}
|
|
249
|
-
}, i);
|
|
250
|
-
}
|
|
251
|
-
if (n.kind === "guide") {
|
|
252
|
-
const a = page.transform.toPixels(n.axis === "x" ? {
|
|
253
|
-
x: n.at,
|
|
254
|
-
y: n.lo
|
|
255
|
-
} : {
|
|
256
|
-
x: n.lo,
|
|
257
|
-
y: n.at
|
|
258
|
-
});
|
|
259
|
-
const b = page.transform.toPixels(n.axis === "x" ? {
|
|
260
|
-
x: n.at,
|
|
261
|
-
y: n.hi
|
|
262
|
-
} : {
|
|
263
|
-
x: n.hi,
|
|
264
|
-
y: n.at
|
|
265
|
-
});
|
|
266
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
267
|
-
x1: a.x,
|
|
268
|
-
y1: a.y,
|
|
269
|
-
x2: b.x,
|
|
270
|
-
y2: b.y,
|
|
271
|
-
stroke: "#e91e63",
|
|
272
|
-
strokeWidth: 1.5,
|
|
273
|
-
shapeRendering: "crispEdges"
|
|
274
|
-
}, i);
|
|
275
|
-
}
|
|
276
|
-
if (n.kind === "obb") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("polygon", {
|
|
277
|
-
points: n.corners.map((c) => {
|
|
278
|
-
const p = page.transform.toPixels(c);
|
|
279
|
-
return `${p.x},${p.y}`;
|
|
280
|
-
}).join(" "),
|
|
281
|
-
fill: "none",
|
|
282
|
-
stroke: outlineStroke,
|
|
283
|
-
strokeWidth: cs.outline.width,
|
|
284
|
-
strokeDasharray: outlineDash
|
|
285
|
-
}, i);
|
|
286
|
-
if (n.kind === "rotate-guides") {
|
|
287
|
-
const guideDash = cs.guides.style === "dashed" ? "4 3" : void 0;
|
|
288
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("g", { children: n.lines.map((l, j) => {
|
|
289
|
-
const a = page.transform.toPixels(l.a);
|
|
290
|
-
const b = page.transform.toPixels(l.b);
|
|
291
|
-
const axis = l.role === "axis";
|
|
292
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
293
|
-
x1: a.x,
|
|
294
|
-
y1: a.y,
|
|
295
|
-
x2: b.x,
|
|
296
|
-
y2: b.y,
|
|
297
|
-
stroke: axis ? cs.guides.axisColor ?? cs.accent : cs.guides.indicatorColor ?? cs.accent,
|
|
298
|
-
opacity: axis ? cs.guides.axisOpacity : cs.guides.indicatorOpacity,
|
|
299
|
-
strokeWidth: cs.guides.width,
|
|
300
|
-
strokeDasharray: guideDash
|
|
301
|
-
}, j);
|
|
302
|
-
}) }, i);
|
|
303
|
-
}
|
|
304
|
-
if (n.kind === "rotate-knob") {
|
|
305
|
-
const at = page.transform.toPixels(n.at);
|
|
306
|
-
const from = page.transform.toPixels(n.from);
|
|
307
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", { children: [cs.knob.stalk && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
308
|
-
x1: from.x,
|
|
309
|
-
y1: from.y,
|
|
310
|
-
x2: at.x,
|
|
311
|
-
y2: at.y,
|
|
312
|
-
stroke: knobStroke,
|
|
313
|
-
strokeWidth: 1
|
|
314
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
315
|
-
cx: at.x,
|
|
316
|
-
cy: at.y,
|
|
317
|
-
r: cs.knob.size / 2,
|
|
318
|
-
fill: cs.knob.fill,
|
|
319
|
-
stroke: knobStroke,
|
|
320
|
-
strokeWidth: 1.5
|
|
321
|
-
})] }, i);
|
|
322
|
-
}
|
|
323
|
-
const b = boxOf(n.rect, page);
|
|
324
|
-
if (n.kind === "marquee") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
|
|
325
|
-
x: b.left,
|
|
326
|
-
y: b.top,
|
|
327
|
-
width: b.width,
|
|
328
|
-
height: b.height,
|
|
329
|
-
fill: rgba(cs.accent, .08),
|
|
330
|
-
stroke: cs.accent,
|
|
331
|
-
strokeWidth: 1,
|
|
332
|
-
strokeDasharray: "4 3"
|
|
333
|
-
}, i);
|
|
334
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
|
|
335
|
-
x: b.left,
|
|
336
|
-
y: b.top,
|
|
337
|
-
width: b.width,
|
|
338
|
-
height: b.height,
|
|
339
|
-
fill: "none",
|
|
340
|
-
stroke: outlineStroke,
|
|
341
|
-
strokeWidth: cs.outline.width,
|
|
342
|
-
strokeDasharray: outlineDash
|
|
343
|
-
}, i);
|
|
344
|
-
})
|
|
345
|
-
}), chip && chipAt && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
346
|
-
style: {
|
|
347
|
-
position: "absolute",
|
|
348
|
-
left: chipAt.x + 16,
|
|
349
|
-
top: chipAt.y - 28,
|
|
350
|
-
background: "rgba(0,0,0,0.8)",
|
|
351
|
-
color: "#fff",
|
|
352
|
-
padding: "2px 6px",
|
|
353
|
-
borderRadius: 4,
|
|
354
|
-
fontSize: 12,
|
|
355
|
-
fontFamily: "monospace",
|
|
356
|
-
pointerEvents: "none",
|
|
357
|
-
whiteSpace: "nowrap",
|
|
358
|
-
zIndex: 1
|
|
359
|
-
},
|
|
360
|
-
children: [chip.angle, "°"]
|
|
361
|
-
})] });
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* A free-text annotation: the SAME styled element for viewing and editing —
|
|
365
|
-
* `contentEditable` just toggles, so the text never jumps. The plugin handed us
|
|
366
|
-
* a ready-to-spread body style (`item.css`) and the rich paragraphs
|
|
367
|
-
* (`item.richText`); the shared `attachRichTextEditor` binding renders them
|
|
368
|
-
* as inline-styled spans, serialises typing back, maps the selection to flat
|
|
369
|
-
* offsets and keeps the caret through a restyle; the browser owns layout,
|
|
370
|
-
* caret, IME and clipboard; the plugin owns the text truth, the range
|
|
371
|
-
* routing and the debounced engine write. This component is the ENTIRE
|
|
372
|
-
* per-framework surface for text editing — React's part is the glue below.
|
|
373
|
-
*/
|
|
374
|
-
function FreeText({ item, page }) {
|
|
375
|
-
const anno = require_runtime.useCapability(_embedpdf_plugin_annotation_internal.AnnotationToken);
|
|
376
|
-
const ref = react.useRef(null);
|
|
377
|
-
const box = boxOf(item.box, page);
|
|
378
|
-
const scale = item.box.width > 0 ? box.width / item.box.width : 1;
|
|
379
|
-
const binding = react.useRef(null);
|
|
380
|
-
const latest = react.useRef({
|
|
381
|
-
item,
|
|
382
|
-
scale
|
|
383
|
-
});
|
|
384
|
-
latest.current = {
|
|
385
|
-
item,
|
|
386
|
-
scale
|
|
387
|
-
};
|
|
388
|
-
(0, react.useEffect)(() => {
|
|
389
|
-
const el = ref.current;
|
|
390
|
-
if (!el) return;
|
|
391
|
-
const b = (0, _embedpdf_web.attachRichTextEditor)(el, {
|
|
392
|
-
onInput: (doc) => {
|
|
393
|
-
const it = latest.current.item;
|
|
394
|
-
if (it.ref) anno.setRichText(it.ref, doc);
|
|
395
|
-
},
|
|
396
|
-
onSelectionChange: (range) => {
|
|
397
|
-
const it = latest.current.item;
|
|
398
|
-
if (it.ref) anno.setTextSelection(it.ref, range);
|
|
399
|
-
},
|
|
400
|
-
onCommand: (command) => anno.toggleTextFormat(command),
|
|
401
|
-
cssFontFamily: (family) => anno.cssFontFamily(family)
|
|
402
|
-
}, {
|
|
403
|
-
document: latest.current.item.richText,
|
|
404
|
-
scale: latest.current.scale
|
|
405
|
-
});
|
|
406
|
-
binding.current = b;
|
|
407
|
-
return () => {
|
|
408
|
-
b.detach();
|
|
409
|
-
binding.current = null;
|
|
410
|
-
};
|
|
411
|
-
}, [anno]);
|
|
412
|
-
(0, react.useEffect)(() => {
|
|
413
|
-
binding.current?.update({
|
|
414
|
-
document: item.richText,
|
|
415
|
-
scale
|
|
416
|
-
});
|
|
417
|
-
}, [item, scale]);
|
|
418
|
-
const pad = item.css.padding * scale;
|
|
419
|
-
const plate = {
|
|
420
|
-
left: box.left + pad,
|
|
421
|
-
top: box.top + pad,
|
|
422
|
-
width: Math.max(0, box.width - 2 * pad),
|
|
423
|
-
height: Math.max(0, box.height - 2 * pad)
|
|
424
|
-
};
|
|
425
|
-
(0, react.useEffect)(() => {
|
|
426
|
-
if (item.editing) {
|
|
427
|
-
const el = ref.current;
|
|
428
|
-
if (!el) return;
|
|
429
|
-
el.focus();
|
|
430
|
-
el.scrollTop = 0;
|
|
431
|
-
}
|
|
432
|
-
}, [item.editing]);
|
|
433
|
-
(0, react.useEffect)(() => {
|
|
434
|
-
const el = ref.current;
|
|
435
|
-
if (!el) return;
|
|
436
|
-
const stop = (e) => e.stopPropagation();
|
|
437
|
-
el.addEventListener("pointerdown", stop);
|
|
438
|
-
return () => el.removeEventListener("pointerdown", stop);
|
|
439
|
-
}, []);
|
|
440
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
441
|
-
ref,
|
|
442
|
-
contentEditable: item.editing,
|
|
443
|
-
suppressContentEditableWarning: true,
|
|
444
|
-
onBlur: (e) => {
|
|
445
|
-
if (e.relatedTarget == null && ref.current?.isConnected && anno.currentEditing() === item.id) ref.current.focus();
|
|
446
|
-
},
|
|
447
|
-
style: {
|
|
448
|
-
position: "absolute",
|
|
449
|
-
left: plate.left,
|
|
450
|
-
top: plate.top,
|
|
451
|
-
width: plate.width,
|
|
452
|
-
height: plate.height,
|
|
453
|
-
fontFamily: item.css.fontFamily,
|
|
454
|
-
fontSize: item.css.fontSize * scale,
|
|
455
|
-
color: item.css.color,
|
|
456
|
-
fontWeight: item.css.fontWeight,
|
|
457
|
-
fontStyle: item.css.fontStyle,
|
|
458
|
-
textDecoration: item.css.textDecoration,
|
|
459
|
-
textAlign: item.css.align,
|
|
460
|
-
boxSizing: "border-box",
|
|
461
|
-
background: "transparent",
|
|
462
|
-
whiteSpace: "pre-wrap",
|
|
463
|
-
overflowWrap: "break-word",
|
|
464
|
-
overflowY: item.editing ? "auto" : "hidden",
|
|
465
|
-
overflowX: "hidden",
|
|
466
|
-
outline: item.editing ? "1px solid #3858e9" : "none",
|
|
467
|
-
cursor: item.editing ? "text" : "default",
|
|
468
|
-
...item.rot ? {
|
|
469
|
-
transform: `rotate(${item.rot}deg)`,
|
|
470
|
-
transformOrigin: "center"
|
|
471
|
-
} : {},
|
|
472
|
-
pointerEvents: item.editing ? "auto" : "none"
|
|
473
|
-
}
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Auto-registered behaviors for `interactive` renderer entries — refcounted
|
|
478
|
-
* per (capability, entry) because the layer mounts once PER PAGE: the first
|
|
479
|
-
* page registers, the last unregisters. Entry identity is the key, hence the
|
|
480
|
-
* "define entries outside render" rule on {@link AnnotationRenderer}.
|
|
481
|
-
*/
|
|
482
|
-
const autoBehaviors = /* @__PURE__ */ new WeakMap();
|
|
483
|
-
let autoBehaviorSeq = 0;
|
|
484
|
-
function useAutoBehaviors(anno, renderers) {
|
|
485
|
-
(0, react.useEffect)(() => {
|
|
486
|
-
if (!renderers) return;
|
|
487
|
-
const released = [];
|
|
488
|
-
for (const r of renderers) {
|
|
489
|
-
if (!("for" in r) || !r.interactive) continue;
|
|
490
|
-
let perCap = autoBehaviors.get(anno);
|
|
491
|
-
if (!perCap) autoBehaviors.set(anno, perCap = /* @__PURE__ */ new Map());
|
|
492
|
-
let rec = perCap.get(r);
|
|
493
|
-
if (!rec) {
|
|
494
|
-
const id = r.id ?? `renderer:${++autoBehaviorSeq}`;
|
|
495
|
-
const engaged = typeof r.interactive === "function" ? r.interactive : () => true;
|
|
496
|
-
rec = {
|
|
497
|
-
id,
|
|
498
|
-
count: 0,
|
|
499
|
-
unregister: anno.registerBehavior({
|
|
500
|
-
id,
|
|
501
|
-
matches: r.for,
|
|
502
|
-
engaged
|
|
503
|
-
})
|
|
504
|
-
};
|
|
505
|
-
perCap.set(r, rec);
|
|
506
|
-
}
|
|
507
|
-
rec.count++;
|
|
508
|
-
const owned = rec;
|
|
509
|
-
released.push(() => {
|
|
510
|
-
owned.count--;
|
|
511
|
-
if (owned.count === 0) {
|
|
512
|
-
owned.unregister();
|
|
513
|
-
autoBehaviors.get(anno)?.delete(r);
|
|
514
|
-
}
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
|
-
return () => released.forEach((f) => f());
|
|
518
|
-
}, [anno, renderers]);
|
|
519
|
-
}
|
|
520
|
-
/** The behavior id a renderer entry answers for (plugin-owned or auto-registered). */
|
|
521
|
-
function rendererBehaviorId(anno, r) {
|
|
522
|
-
if ("behavior" in r) return r.behavior;
|
|
523
|
-
return autoBehaviors.get(anno)?.get(r)?.id ?? null;
|
|
524
|
-
}
|
|
525
|
-
/** React 18 spells the `inert` attribute as a string spread; it hard-disables
|
|
526
|
-
* pointer AND focus for the whole subtree — the mechanical guarantee that a
|
|
527
|
-
* non-interactive renderer entry (a skin) can never steal input. */
|
|
528
|
-
const INERT = { inert: "" };
|
|
529
|
-
function AnnotationLayer({ renderers } = {}) {
|
|
530
|
-
const page = require_runtime.usePage();
|
|
531
|
-
const anno = require_runtime.useCapability(_embedpdf_plugin_annotation_internal.AnnotationToken);
|
|
532
|
-
const viewZoom = page.transform.zoom;
|
|
533
|
-
const viewRotation = page.transform.rotation;
|
|
534
|
-
const items = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.pageItems(page.pon, {
|
|
535
|
-
zoom: viewZoom,
|
|
536
|
-
rotation: viewRotation
|
|
537
|
-
}), require_runtime.shallowArray);
|
|
538
|
-
const texts = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.textItems(page.pon, {
|
|
539
|
-
zoom: viewZoom,
|
|
540
|
-
rotation: viewRotation
|
|
541
|
-
}), require_runtime.shallowArray);
|
|
542
|
-
const [urls, setUrls] = (0, react.useState)({});
|
|
543
|
-
useAutoBehaviors(anno, renderers);
|
|
544
|
-
(0, react.useEffect)(() => {
|
|
545
|
-
anno.ensurePage(page.pon);
|
|
546
|
-
}, [anno, page.pon]);
|
|
547
|
-
const bakedKey = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.appearanceEpoch(page.pon));
|
|
548
|
-
const bakeScale = require_runtime.useSelector(_embedpdf_plugin_annotation_internal.AnnotationToken, (c) => c.bakeScale(page.transform.renderScale));
|
|
549
|
-
(0, react.useEffect)(() => {
|
|
550
|
-
const controller = new AbortController();
|
|
551
|
-
const revokers = [];
|
|
552
|
-
(async () => {
|
|
553
|
-
try {
|
|
554
|
-
const imgs = await anno.appearances(page.pon, bakeScale, controller.signal);
|
|
555
|
-
const map = {};
|
|
556
|
-
for (const ap of imgs) {
|
|
557
|
-
const box = anno.toContentBox(page.pon, ap.rect);
|
|
558
|
-
if (!box) continue;
|
|
559
|
-
const obj = await ap.image.objectUrl(controller.signal);
|
|
560
|
-
if (controller.signal.aborted) {
|
|
561
|
-
obj.revoke();
|
|
562
|
-
return;
|
|
563
|
-
}
|
|
564
|
-
revokers.push(obj.revoke);
|
|
565
|
-
map[(0, _embedpdf_plugin_annotation.refKey)(ap.ref)] = {
|
|
566
|
-
url: obj.url,
|
|
567
|
-
box
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
if (!controller.signal.aborted) setUrls(map);
|
|
571
|
-
} catch {}
|
|
572
|
-
})();
|
|
573
|
-
return () => {
|
|
574
|
-
controller.abort();
|
|
575
|
-
revokers.forEach((r) => r());
|
|
576
|
-
};
|
|
577
|
-
}, [
|
|
578
|
-
anno,
|
|
579
|
-
page.pon,
|
|
580
|
-
bakeScale,
|
|
581
|
-
bakedKey
|
|
582
|
-
]);
|
|
583
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
584
|
-
style: {
|
|
585
|
-
position: "absolute",
|
|
586
|
-
inset: 0,
|
|
587
|
-
pointerEvents: "none"
|
|
588
|
-
},
|
|
589
|
-
children: [
|
|
590
|
-
items.map((item) => {
|
|
591
|
-
const baked = urls[item.id];
|
|
592
|
-
const native = item.source === "baked" ? baked ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BakedImage, {
|
|
593
|
-
box: item.apBox ?? baked.box,
|
|
594
|
-
url: baked.url,
|
|
595
|
-
page,
|
|
596
|
-
blend: item.blend,
|
|
597
|
-
rot: item.apRot
|
|
598
|
-
}) : null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Shape, {
|
|
599
|
-
item,
|
|
600
|
-
page
|
|
601
|
-
});
|
|
602
|
-
const behavior = anno.behaviorFor({
|
|
603
|
-
subtype: item.subtype,
|
|
604
|
-
ref: item.ref
|
|
605
|
-
});
|
|
606
|
-
let out;
|
|
607
|
-
if (behavior) {
|
|
608
|
-
const entry = renderers?.find((r) => rendererBehaviorId(anno, r) === behavior.id);
|
|
609
|
-
if (entry) {
|
|
610
|
-
const Owner = entry.component;
|
|
611
|
-
out = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Owner, {
|
|
612
|
-
item,
|
|
613
|
-
page,
|
|
614
|
-
appearance: baked ?? null,
|
|
615
|
-
native,
|
|
616
|
-
interactive: true
|
|
617
|
-
});
|
|
618
|
-
} else out = null;
|
|
619
|
-
} else {
|
|
620
|
-
const entry = renderers?.find((r) => "for" in r && r.for({
|
|
621
|
-
subtype: item.subtype,
|
|
622
|
-
ref: item.ref
|
|
623
|
-
}));
|
|
624
|
-
if (entry) {
|
|
625
|
-
const Skin = entry.component;
|
|
626
|
-
out = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
627
|
-
...INERT,
|
|
628
|
-
style: { pointerEvents: "none" },
|
|
629
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Skin, {
|
|
630
|
-
item,
|
|
631
|
-
page,
|
|
632
|
-
appearance: baked ?? null,
|
|
633
|
-
native,
|
|
634
|
-
interactive: false
|
|
635
|
-
})
|
|
636
|
-
});
|
|
637
|
-
} else out = native;
|
|
638
|
-
}
|
|
639
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: out }, item.id);
|
|
640
|
-
}),
|
|
641
|
-
texts.map((t) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FreeText, {
|
|
642
|
-
item: t,
|
|
643
|
-
page
|
|
644
|
-
}, t.id)),
|
|
645
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolGhostImage, { page }),
|
|
646
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chrome, { page })
|
|
647
|
-
]
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
|
-
* The default file-picker provider: the built-in file dialog (from
|
|
652
|
-
* `@embedpdf/web`), honouring the tool's `accept` filter. This is the ADAPTER
|
|
653
|
-
* fulfilling the plugin's DOM-free port — the dialog lives here, in the
|
|
654
|
-
* framework layer, never in the plugin. A picked `File` carries its own name
|
|
655
|
-
* and mime, so it goes straight through as the engine's file source.
|
|
656
|
-
*/
|
|
657
|
-
const filePickerProvider = async (req) => {
|
|
658
|
-
const file = await (0, _embedpdf_web.pickFile)({ accept: req.accept ?? "*/*" });
|
|
659
|
-
return file ? { data: file } : null;
|
|
660
|
-
};
|
|
661
|
-
/**
|
|
662
|
-
* Install the file-picker provider for the active document — the ONE port
|
|
663
|
-
* behind every click-then-pick tool (a stamp `'prompt'` source, the file-
|
|
664
|
-
* attachment tool). Call ONCE at a document-scoped spot (not inside
|
|
665
|
-
* `<AnnotationLayer>`, which is per page). Defaults to
|
|
666
|
-
* {@link filePickerProvider}, so a bare `useFilePickerProvider()` makes all of
|
|
667
|
-
* them work out of the box; pass a custom provider (asset library, cloud
|
|
668
|
-
* drive — switch on `req.subtype` / `req.toolId`) or `null` to make
|
|
669
|
-
* click-then-pick tools inert. Cleared on unmount.
|
|
670
|
-
*/
|
|
671
|
-
function useFilePickerProvider(provider = filePickerProvider) {
|
|
672
|
-
const anno = require_runtime.useOptionalCapability(_embedpdf_plugin_annotation.AnnotationToken);
|
|
673
|
-
(0, react.useEffect)(() => {
|
|
674
|
-
if (!anno) return;
|
|
675
|
-
anno.setFilePickerProvider(provider);
|
|
676
|
-
return () => anno.setFilePickerProvider(null);
|
|
677
|
-
}, [anno, provider]);
|
|
678
|
-
}
|
|
679
|
-
function useAnnotation() {
|
|
680
|
-
return require_runtime.useCapability(_embedpdf_plugin_annotation.AnnotationToken);
|
|
681
|
-
}
|
|
682
|
-
function useAnnotationSelection() {
|
|
683
|
-
return require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.selection(), require_runtime.shallowArray);
|
|
684
|
-
}
|
|
685
|
-
/** Structural equality for a resolved props bag — keeps the subscription from
|
|
686
|
-
* re-rendering on unrelated dispatches, since `currentDefaults` returns a fresh
|
|
687
|
-
* object each call. Small flat objects; JSON compare is exact and cheap here. */
|
|
688
|
-
const sameProps = (a, b) => a === b || JSON.stringify(a) === JSON.stringify(b);
|
|
689
|
-
/**
|
|
690
|
-
* A tool's RESOLVED defaults (base + per-tool override) as a full flat props
|
|
691
|
-
* bag, subscribed so a `setDefaults` re-renders the consumer. Use this — not the
|
|
692
|
-
* imperative `useAnnotation().currentDefaults(id)` — to drive default-editing
|
|
693
|
-
* controls, so they reflect changes live. Pair with `propsForTool(id)` for the
|
|
694
|
-
* specs to render.
|
|
695
|
-
*/
|
|
696
|
-
function useAnnotationDefaults(toolId) {
|
|
697
|
-
return require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.currentDefaults(toolId), sameProps);
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* The selection's editable properties — ordered specs shared by every selected
|
|
701
|
-
* kind, current values, and which keys are mixed. THE hook a property sidebar
|
|
702
|
-
* renders from; write back with `useAnnotation().updateSelection({ [key]: v })`.
|
|
703
|
-
* Reference-stable between model changes (the capability memoizes by model
|
|
704
|
-
* identity), so the default equality is enough.
|
|
705
|
-
*/
|
|
706
|
-
function useSelectionProps() {
|
|
707
|
-
return require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.getSelectionProps());
|
|
708
|
-
}
|
|
709
|
-
/**
|
|
710
|
-
* The selection's `/F` annotation flags — per-flag `true`/`false`, `null` where
|
|
711
|
-
* the selected annotations disagree (render an indeterminate control), `null`
|
|
712
|
-
* overall when nothing is selected. Write back with
|
|
713
|
-
* `useAnnotation().updateSelectionFlags({ locked: true })`. Reference-stable
|
|
714
|
-
* between model changes, like {@link useSelectionProps}.
|
|
715
|
-
*/
|
|
716
|
-
function useSelectionFlags() {
|
|
717
|
-
return require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.getSelectionFlags());
|
|
718
|
-
}
|
|
719
|
-
/** Pure join behind {@link useCommentThreads} — exported for tests. */
|
|
720
|
-
function enrichCommentThreads(threads, pages) {
|
|
721
|
-
const byPon = new Map(pages.map((p) => [p.pageObjectNumber, p]));
|
|
722
|
-
return threads.map((t) => {
|
|
723
|
-
const page = byPon.get(t.pageObjectNumber);
|
|
724
|
-
return {
|
|
725
|
-
...t,
|
|
726
|
-
pageIndex: page ? page.index : -1,
|
|
727
|
-
pageLabel: page ? page.label ?? String(page.index + 1) : "?",
|
|
728
|
-
contentRect: page ? (0, _embedpdf_core_annotation.pdfToContentRect)(t.root.rect, page.boxes.crop) : null
|
|
729
|
-
};
|
|
730
|
-
});
|
|
731
|
-
}
|
|
732
|
-
/** The comments surface (verbs + `permissionsFor`) — imperative; pair with
|
|
733
|
-
* {@link useCommentThreads} for the subscribed view. */
|
|
734
|
-
function useComments() {
|
|
735
|
-
return require_runtime.useCapability(_embedpdf_plugin_annotation.AnnotationToken).comments;
|
|
736
|
-
}
|
|
737
|
-
const EMPTY_PAGES = [];
|
|
738
|
-
/**
|
|
739
|
-
* Every comment thread in the document, display-ordered (page position →
|
|
740
|
-
* top of page → creation date) and enriched with `pageIndex`/`pageLabel`.
|
|
741
|
-
* Subscribed to BOTH stores: annotation writes (own, remote, hydration)
|
|
742
|
-
* recompute the threads; page moves/deletes re-run the join. Reference-
|
|
743
|
-
* stable between changes — safe to memo child renders on the array.
|
|
744
|
-
*/
|
|
745
|
-
function useCommentThreads() {
|
|
746
|
-
const docId = require_runtime.useDocumentId();
|
|
747
|
-
const threads = require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.comments.threads());
|
|
748
|
-
const pages = require_runtime.useKernelValue((k) => docId ? k.getState().core.documents[docId]?.pages ?? EMPTY_PAGES : EMPTY_PAGES);
|
|
749
|
-
return react.useMemo(() => enrichCommentThreads(threads, pages), [threads, pages]);
|
|
750
|
-
}
|
|
751
|
-
/** The enriched thread containing ANY member ref (root, reply, grouped part,
|
|
752
|
-
* state annotation), or null. */
|
|
753
|
-
function useCommentThread(ref) {
|
|
754
|
-
const views = useCommentThreads();
|
|
755
|
-
const api = useComments();
|
|
756
|
-
if (ref == null) return null;
|
|
757
|
-
const t = api.thread(ref);
|
|
758
|
-
if (!t) return null;
|
|
759
|
-
return views.find((v) => (0, _embedpdf_plugin_annotation.refKey)(v.root.ref) === (0, _embedpdf_plugin_annotation.refKey)(t.root.ref)) ?? null;
|
|
760
|
-
}
|
|
761
|
-
/** Whole-document hydration status — the comments sidebar's honest loading
|
|
762
|
-
* state (`loading` until `listRawAll` lands, then `complete`/`error`). */
|
|
763
|
-
function useCommentsHydration() {
|
|
764
|
-
return require_runtime.useSelector(_embedpdf_plugin_annotation.AnnotationToken, (c) => c.comments.hydration());
|
|
765
|
-
}
|
|
766
|
-
//#endregion
|
|
767
|
-
exports.AnnotationLayer = AnnotationLayer;
|
|
768
|
-
exports.enrichCommentThreads = enrichCommentThreads;
|
|
769
|
-
exports.filePickerProvider = filePickerProvider;
|
|
770
|
-
exports.sameAnchor = require_annotation_anchors.sameAnchor;
|
|
771
|
-
exports.sameCreationDraftAnchor = require_annotation_anchors.sameCreationDraftAnchor;
|
|
772
|
-
exports.useAnnotation = useAnnotation;
|
|
773
|
-
exports.useAnnotationDefaults = useAnnotationDefaults;
|
|
774
|
-
exports.useAnnotationSelected = require_annotation_hooks.useAnnotationSelected;
|
|
775
|
-
exports.useAnnotationSelection = useAnnotationSelection;
|
|
776
|
-
exports.useCommentThread = useCommentThread;
|
|
777
|
-
exports.useCommentThreads = useCommentThreads;
|
|
778
|
-
exports.useComments = useComments;
|
|
779
|
-
exports.useCommentsHydration = useCommentsHydration;
|
|
780
|
-
exports.useFilePickerProvider = useFilePickerProvider;
|
|
781
|
-
exports.useSelectionFlags = useSelectionFlags;
|
|
782
|
-
exports.useSelectionProps = useSelectionProps;
|
|
2
|
+
const require_annotation = require("./annotation-Dex5EBda.cjs");
|
|
3
|
+
exports.AnnotationDraftMenu = require_annotation.AnnotationDraftMenu;
|
|
4
|
+
exports.AnnotationLayer = require_annotation.AnnotationLayer;
|
|
5
|
+
exports.AnnotationMenu = require_annotation.AnnotationMenu;
|
|
6
|
+
exports.AnnotationRotationBadge = require_annotation.AnnotationRotationBadge;
|
|
7
|
+
exports.filePickerProvider = require_annotation.filePickerProvider;
|
|
8
|
+
exports.useAnnotation = require_annotation.useAnnotation;
|
|
9
|
+
exports.useAnnotationAnchor = require_annotation.useAnnotationAnchor;
|
|
10
|
+
exports.useAnnotationDefaults = require_annotation.useAnnotationDefaults;
|
|
11
|
+
exports.useAnnotationEvent = require_annotation.useAnnotationEvent;
|
|
12
|
+
exports.useAnnotationList = require_annotation.useAnnotationList;
|
|
13
|
+
exports.useAnnotationProperties = require_annotation.useAnnotationProperties;
|
|
14
|
+
exports.useAnnotationSettings = require_annotation.useAnnotationSettings;
|
|
15
|
+
exports.useAnnotationState = require_annotation.useAnnotationState;
|
|
16
|
+
exports.useCommentThread = require_annotation.useCommentThread;
|
|
17
|
+
exports.useCommentThreads = require_annotation.useCommentThreads;
|
|
18
|
+
exports.useComments = require_annotation.useComments;
|
|
19
|
+
exports.useFilePickerProvider = require_annotation.useFilePickerProvider;
|
|
20
|
+
exports.useRichTextEditor = require_annotation.useRichTextEditor;
|
|
21
|
+
var _embedpdf_plugin_annotation = require("@embedpdf/plugin-annotation");
|
|
783
22
|
Object.keys(_embedpdf_plugin_annotation).forEach(function(k) {
|
|
784
23
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
785
24
|
enumerable: true,
|
|
@@ -788,5 +27,3 @@ Object.keys(_embedpdf_plugin_annotation).forEach(function(k) {
|
|
|
788
27
|
}
|
|
789
28
|
});
|
|
790
29
|
});
|
|
791
|
-
|
|
792
|
-
//# sourceMappingURL=annotation.cjs.map
|