@embedpdf/react 3.0.0-next.14 → 3.0.0-next.16
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-DcyhF2kU-CiBFOq1z.d.cts +878 -0
- package/dist/AnnotationList-DcyhF2kU-CiBFOq1z.d.ts +878 -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-3UvABfJm.d.cts +305 -0
- package/dist/annotation-BNHQpMKv.cjs +806 -0
- package/dist/annotation-BNHQpMKv.cjs.map +1 -0
- package/dist/annotation-CDI8CFb3.js +684 -0
- package/dist/annotation-CDI8CFb3.js.map +1 -0
- package/dist/annotation-DhEfs0pH.d.ts +305 -0
- package/dist/annotation.cjs +20 -784
- package/dist/annotation.d.cts +2 -2
- package/dist/annotation.d.ts +2 -2
- package/dist/annotation.js +2 -769
- package/dist/attachment.cjs +39 -0
- package/dist/attachment.cjs.map +1 -0
- package/dist/attachment.d.cts +29 -0
- package/dist/attachment.d.ts +29 -0
- package/dist/attachment.js +28 -0
- package/dist/attachment.js.map +1 -0
- 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-BSGvjA5D.js +511 -0
- package/dist/form-BSGvjA5D.js.map +1 -0
- package/dist/form-BgztZyOK.cjs +548 -0
- package/dist/form-BgztZyOK.cjs.map +1 -0
- package/dist/form.cjs +5 -5
- package/dist/form.d.cts +41 -2
- package/dist/form.d.ts +41 -2
- 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 +227 -57
- package/dist/index.d.cts +35 -32
- package/dist/index.d.ts +35 -32
- package/dist/index.js +36 -30
- 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 +36 -11
- package/dist/measurement.cjs.map +1 -1
- package/dist/measurement.d.cts +33 -7
- package/dist/measurement.d.ts +33 -7
- package/dist/measurement.js +35 -14
- package/dist/measurement.js.map +1 -1
- 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/outline.cjs +39 -0
- package/dist/outline.cjs.map +1 -0
- package/dist/outline.d.cts +31 -0
- package/dist/outline.d.ts +31 -0
- package/dist/outline.js +28 -0
- package/dist/outline.js.map +1 -0
- package/dist/page-edit.cjs +15 -3
- package/dist/page-edit.cjs.map +1 -1
- package/dist/page-edit.d.cts +17 -2
- package/dist/page-edit.d.ts +17 -2
- package/dist/page-edit.js +15 -5
- 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-BfnpyfY0.cjs +556 -0
- package/dist/runtime-BfnpyfY0.cjs.map +1 -0
- package/dist/runtime-DBEBlpQV.d.cts +237 -0
- package/dist/runtime-V3MVMb91.d.ts +237 -0
- package/dist/runtime-tD5iJU83.js +399 -0
- package/dist/runtime-tD5iJU83.js.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 +37 -24
- package/dist/search.d.ts +37 -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-B7BG2e8Q.cjs +369 -0
- package/dist/stage-B7BG2e8Q.cjs.map +1 -0
- package/dist/stage-BqfBjDu6.js +302 -0
- package/dist/stage-BqfBjDu6.js.map +1 -0
- package/dist/stage-ByFPD-Fv.d.cts +117 -0
- package/dist/stage-DaboaheR.d.ts +117 -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-CzI2KlZb.js +62 -0
- package/dist/state-CzI2KlZb.js.map +1 -0
- package/dist/state-Dtf8HAue.cjs +73 -0
- package/dist/state-Dtf8HAue.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 +47 -39
- 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-Bdjk0Z3T.d.cts +0 -537
- package/dist/form-CK3mp99m.js +0 -895
- package/dist/form-CK3mp99m.js.map +0 -1
- package/dist/form-CYRYgthn.d.ts +0 -537
- 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/stage.js
CHANGED
|
@@ -1,229 +1,4 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import {
|
|
3
|
-
import { ProjectorProvider } from "./anchored.js";
|
|
4
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
import { useLayoutEffect, useMemo, useRef } from "react";
|
|
6
|
-
import { createStageSurface } from "@embedpdf/web";
|
|
7
|
-
import { StageToken, createScrollHandler, settingsEqual } from "@embedpdf/plugin-stage";
|
|
8
|
-
import { InteractionToken } from "@embedpdf/plugin-interaction/contract";
|
|
1
|
+
import { n as useStageToken, t as StageScope } from "./stage-scope-D7ZeNduT.js";
|
|
2
|
+
import { a as useStageState, i as useStageSettings, n as useStage, o as Scrollbar, r as useStageEvent, s as useScrollMetrics, t as Stage } from "./stage-BqfBjDu6.js";
|
|
9
3
|
export * from "@embedpdf/plugin-stage";
|
|
10
|
-
|
|
11
|
-
function PageSurface({ documentId, page, frame, stage, render, chrome }) {
|
|
12
|
-
const ref = useRef(null);
|
|
13
|
-
const t = page.transform;
|
|
14
|
-
const rotation = page.rotation;
|
|
15
|
-
const outerW = t.viewWidth + frame.left + frame.right;
|
|
16
|
-
const outerH = t.viewHeight + frame.top + frame.bottom;
|
|
17
|
-
const left = page.screenX - frame.left;
|
|
18
|
-
const top = page.screenY - frame.top;
|
|
19
|
-
const contentLeft = frame.left + (t.viewWidth - t.contentWidth) / 2;
|
|
20
|
-
const contentTop = frame.top + (t.viewHeight - t.contentHeight) / 2;
|
|
21
|
-
const ctx = useMemo(() => makePageContext(documentId, stage.lensId(), page.pon, page.pageIndex, frame, t, () => ref.current.getBoundingClientRect(), () => {
|
|
22
|
-
const live = stage.visiblePages().find((p) => p.pon === page.pon);
|
|
23
|
-
return live ? {
|
|
24
|
-
desiredDeviceWidth: live.transform.deviceWidth,
|
|
25
|
-
visibleRect: live.visibleRect
|
|
26
|
-
} : {
|
|
27
|
-
desiredDeviceWidth: t.deviceWidth,
|
|
28
|
-
visibleRect: {
|
|
29
|
-
x: 0,
|
|
30
|
-
y: 0,
|
|
31
|
-
width: 0,
|
|
32
|
-
height: 0
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}), [
|
|
36
|
-
documentId,
|
|
37
|
-
page.pon,
|
|
38
|
-
page.pageIndex,
|
|
39
|
-
frame,
|
|
40
|
-
t,
|
|
41
|
-
stage
|
|
42
|
-
]);
|
|
43
|
-
return /* @__PURE__ */ jsx("div", {
|
|
44
|
-
style: {
|
|
45
|
-
position: "absolute",
|
|
46
|
-
left,
|
|
47
|
-
top,
|
|
48
|
-
width: outerW,
|
|
49
|
-
height: outerH
|
|
50
|
-
},
|
|
51
|
-
children: /* @__PURE__ */ jsxs(PageProvider, {
|
|
52
|
-
value: ctx,
|
|
53
|
-
children: [
|
|
54
|
-
/* @__PURE__ */ jsx("div", { style: {
|
|
55
|
-
position: "absolute",
|
|
56
|
-
left: frame.left,
|
|
57
|
-
top: frame.top,
|
|
58
|
-
width: t.viewWidth,
|
|
59
|
-
height: t.viewHeight,
|
|
60
|
-
boxShadow: "var(--epdf-page-shadow, 0 6px 18px rgba(0,0,0,.18))"
|
|
61
|
-
} }),
|
|
62
|
-
/* @__PURE__ */ jsx("div", {
|
|
63
|
-
ref,
|
|
64
|
-
style: {
|
|
65
|
-
position: "absolute",
|
|
66
|
-
left: contentLeft,
|
|
67
|
-
top: contentTop,
|
|
68
|
-
width: t.contentWidth,
|
|
69
|
-
height: t.contentHeight,
|
|
70
|
-
background: "#fff",
|
|
71
|
-
transform: rotation ? `rotate(${rotation}deg)` : void 0,
|
|
72
|
-
userSelect: "none",
|
|
73
|
-
WebkitUserSelect: "none"
|
|
74
|
-
},
|
|
75
|
-
children: render(ctx)
|
|
76
|
-
}),
|
|
77
|
-
chrome?.(ctx)
|
|
78
|
-
]
|
|
79
|
-
})
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
function Stage({ children, pageChrome, overlay, interaction = true, panFallback = true, zoomGestures = true, token = StageToken, className, style }) {
|
|
83
|
-
const stage = useCapability(token);
|
|
84
|
-
const ix = useOptionalCapability(InteractionToken);
|
|
85
|
-
const useHub = interaction && !!ix;
|
|
86
|
-
const hubCursor = useKernelValue(() => ix?.cursor() ?? "default");
|
|
87
|
-
const ref = useRef(null);
|
|
88
|
-
const docId = useDocumentId();
|
|
89
|
-
const pages = useSelector(token, (c) => c.visiblePages());
|
|
90
|
-
const frame = useSelector(token, (c) => c.pageFrame(), (a, b) => a.top === b.top && a.right === b.right && a.bottom === b.bottom && a.left === b.left);
|
|
91
|
-
const projector = useMemo(() => ({
|
|
92
|
-
space: "overlay",
|
|
93
|
-
toScreen: (pon, rect) => stage.pageRectToScreen(pon, rect),
|
|
94
|
-
toScreenPoint: (pon, at) => {
|
|
95
|
-
const r = stage.pageRectToScreen(pon, {
|
|
96
|
-
x: at.x,
|
|
97
|
-
y: at.y,
|
|
98
|
-
width: 0,
|
|
99
|
-
height: 0
|
|
100
|
-
});
|
|
101
|
-
return r ? {
|
|
102
|
-
x: r.x,
|
|
103
|
-
y: r.y
|
|
104
|
-
} : null;
|
|
105
|
-
},
|
|
106
|
-
viewEnv: (pon) => {
|
|
107
|
-
const t = stage.pageRect(pon)?.transform;
|
|
108
|
-
return t ? {
|
|
109
|
-
scale: t.viewScale,
|
|
110
|
-
rotation: t.rotation,
|
|
111
|
-
zoom: t.zoom
|
|
112
|
-
} : null;
|
|
113
|
-
}
|
|
114
|
-
}), [stage]);
|
|
115
|
-
const projectorBinding = useMemo(() => ({
|
|
116
|
-
projector,
|
|
117
|
-
revision: pages
|
|
118
|
-
}), [projector, pages]);
|
|
119
|
-
useLayoutEffect(() => {
|
|
120
|
-
const el = ref.current;
|
|
121
|
-
const detachSurface = createStageSurface(el, stage, {
|
|
122
|
-
hub: useHub ? ix : null,
|
|
123
|
-
source: stage.lensId(),
|
|
124
|
-
zoomGestures
|
|
125
|
-
});
|
|
126
|
-
const offScroll = useHub && ix ? ix.registerHandler(createScrollHandler(stage, ix, { panFallback }), { source: stage.lensId() }) : null;
|
|
127
|
-
return () => {
|
|
128
|
-
offScroll?.();
|
|
129
|
-
detachSurface();
|
|
130
|
-
};
|
|
131
|
-
}, [
|
|
132
|
-
stage,
|
|
133
|
-
ix,
|
|
134
|
-
useHub,
|
|
135
|
-
zoomGestures,
|
|
136
|
-
panFallback
|
|
137
|
-
]);
|
|
138
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
139
|
-
ref,
|
|
140
|
-
className,
|
|
141
|
-
style: {
|
|
142
|
-
position: "relative",
|
|
143
|
-
overflow: "hidden",
|
|
144
|
-
touchAction: "none",
|
|
145
|
-
...useHub ? { cursor: hubCursor } : null,
|
|
146
|
-
...style
|
|
147
|
-
},
|
|
148
|
-
children: [pages.map((p) => /* @__PURE__ */ jsx(PageSurface, {
|
|
149
|
-
documentId: docId ?? "",
|
|
150
|
-
page: p,
|
|
151
|
-
frame,
|
|
152
|
-
stage,
|
|
153
|
-
render: children,
|
|
154
|
-
chrome: pageChrome
|
|
155
|
-
}, p.pon)), /* @__PURE__ */ jsx(ProjectorProvider, {
|
|
156
|
-
value: projectorBinding,
|
|
157
|
-
children: overlay
|
|
158
|
-
})]
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
function useStage(token = StageToken) {
|
|
162
|
-
return useCapability(token);
|
|
163
|
-
}
|
|
164
|
-
function useZoom(token = StageToken) {
|
|
165
|
-
const s = useCapability(token);
|
|
166
|
-
return {
|
|
167
|
-
zoom: useSelector(token, (c) => c.zoomLevel()),
|
|
168
|
-
/** Active zoom intent: 'automatic' | 'fit-page' | 'fit-width' | 'fit-all' | 'custom'. */
|
|
169
|
-
mode: useSelector(token, (c) => c.zoomMode()),
|
|
170
|
-
zoomIn: s.zoomIn,
|
|
171
|
-
zoomOut: s.zoomOut,
|
|
172
|
-
fitWidth: s.fitWidth,
|
|
173
|
-
fitPage: s.fitPage,
|
|
174
|
-
fitAll: s.fitAll,
|
|
175
|
-
automatic: s.automatic,
|
|
176
|
-
zoomTo: s.zoomTo
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
function usePages(token = StageToken) {
|
|
180
|
-
const s = useCapability(token);
|
|
181
|
-
return {
|
|
182
|
-
currentPage: useSelector(token, (c) => c.currentPage()),
|
|
183
|
-
pageCount: useSelector(token, (c) => c.pageCount()),
|
|
184
|
-
goToPage: s.goToPage,
|
|
185
|
-
next: s.next,
|
|
186
|
-
prev: s.prev,
|
|
187
|
-
reveal: s.reveal
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
function useLayout(token = StageToken) {
|
|
191
|
-
const s = useCapability(token);
|
|
192
|
-
return {
|
|
193
|
-
flow: useSelector(token, (c) => c.flow()),
|
|
194
|
-
layout: useSelector(token, (c) => c.layout()),
|
|
195
|
-
spread: useSelector(token, (c) => c.spread()),
|
|
196
|
-
sizing: useSelector(token, (c) => c.sizing()),
|
|
197
|
-
bounded: useSelector(token, (c) => c.bounded()),
|
|
198
|
-
setFlow: s.setFlow,
|
|
199
|
-
setLayout: s.setLayout,
|
|
200
|
-
setSpread: s.setSpread,
|
|
201
|
-
setSizing: s.setSizing,
|
|
202
|
-
setBounded: s.setBounded
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
/** The document's page list (with PDF labels) + the current item's pages — the
|
|
206
|
-
* data for page thumbnails / worksheet-style page tabs. */
|
|
207
|
-
function usePageList(token = StageToken) {
|
|
208
|
-
return {
|
|
209
|
-
pages: useSelector(token, (c) => c.pages(), (a, b) => a.length === b.length && a.every((p, i) => p.pon === b[i].pon && p.label === b[i].label)),
|
|
210
|
-
currentItemPages: useSelector(token, (c) => c.currentItemPages(), (a, b) => a.length === b.length && a.every((x, i) => x === b[i]))
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* All Stage settings + the batch `update`. This is the seam for "presets are a
|
|
215
|
-
* customer concern": keep your own `Partial<StageSettings>` objects and apply them
|
|
216
|
-
* with `update(preset)` (one anchor-preserving change).
|
|
217
|
-
*/
|
|
218
|
-
function useStageSettings(token = StageToken) {
|
|
219
|
-
const s = useCapability(token);
|
|
220
|
-
return {
|
|
221
|
-
settings: useSelector(token, (c) => c.settings(), settingsEqual),
|
|
222
|
-
update: s.update,
|
|
223
|
-
reset: s.resetView
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
//#endregion
|
|
227
|
-
export { Stage, useLayout, usePageList, usePages, useStage, useStageSettings, useZoom };
|
|
228
|
-
|
|
229
|
-
//# sourceMappingURL=stage.js.map
|
|
4
|
+
export { Scrollbar, Stage, StageScope, useScrollMetrics, useStage, useStageEvent, useStageSettings, useStageState, useStageToken };
|
package/dist/stamp.cjs
CHANGED
|
@@ -1,66 +1,70 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("./rolldown-runtime-DDXJien1.cjs");
|
|
3
|
-
const require_runtime = require("./runtime.cjs");
|
|
4
|
-
|
|
3
|
+
const require_runtime = require("./runtime-BfnpyfY0.cjs");
|
|
4
|
+
const require_state = require("./state-Dtf8HAue.cjs");
|
|
5
5
|
let _embedpdf_web = require("@embedpdf/web");
|
|
6
|
+
let react = require("react");
|
|
6
7
|
let _embedpdf_plugin_stamp = require("@embedpdf/plugin-stamp");
|
|
7
8
|
//#region src/stamp.tsx
|
|
8
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* The stamp capability. Libraries are shared by every document; the placing
|
|
11
|
+
* verbs act on the document this component is in.
|
|
12
|
+
*/
|
|
9
13
|
function useStamp() {
|
|
10
14
|
return require_runtime.useCapability(_embedpdf_plugin_stamp.StampToken);
|
|
11
15
|
}
|
|
16
|
+
/** Subscribe to one stamp event for the mounted lifetime: `useStampEvent((stamp) => stamp.onAssetCreated, handler)`. */
|
|
17
|
+
function useStampEvent(select, handler) {
|
|
18
|
+
require_runtime.useCapabilityEvent(_embedpdf_plugin_stamp.StampToken, select, handler);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The stamps' state for this component's document: the armed stamp (the
|
|
22
|
+
* page's State table, declared once in `stampState`). Takes a selector, and
|
|
23
|
+
* re-renders only when what it returns changes.
|
|
24
|
+
*/
|
|
25
|
+
const useStampState = require_state.stateHook(_embedpdf_plugin_stamp.stampState);
|
|
26
|
+
/** The stamp settings (`assetEngine`, `previewWidth`, `dynamic`), with or without a document. Takes a selector. */
|
|
27
|
+
const useStampSettings = require_state.settingsHook(_embedpdf_plugin_stamp.StampToken);
|
|
12
28
|
/** Libraries, optionally of one kind or several (`{ kind: 'stamps' }`, `{ kind: ['stamps', 'toolbar'] }`). */
|
|
13
|
-
function useStampLibraries(
|
|
14
|
-
const kinds =
|
|
15
|
-
return require_runtime.useSelector(_embedpdf_plugin_stamp.StampToken, (
|
|
29
|
+
function useStampLibraries(filter) {
|
|
30
|
+
const kinds = filter?.kind === void 0 ? void 0 : [].concat(filter.kind).join("\0");
|
|
31
|
+
return require_runtime.useSelector(_embedpdf_plugin_stamp.StampToken, (stamp) => stamp.listLibraries(kinds === void 0 ? void 0 : { kind: kinds.split("\0") }), require_runtime.shallowArray);
|
|
16
32
|
}
|
|
17
|
-
/**
|
|
18
|
-
function useStampAssets(
|
|
19
|
-
|
|
33
|
+
/** The stamps of one library (`{ libraryId }`), of one kind or category, or every stamp. */
|
|
34
|
+
function useStampAssets(filter) {
|
|
35
|
+
const libraryId = filter?.libraryId;
|
|
36
|
+
const kind = filter?.kind;
|
|
37
|
+
const category = filter?.category;
|
|
38
|
+
return require_runtime.useSelector(_embedpdf_plugin_stamp.StampToken, (stamp) => stamp.listAssets({
|
|
39
|
+
libraryId,
|
|
40
|
+
kind,
|
|
41
|
+
category
|
|
42
|
+
}), require_runtime.shallowArray);
|
|
20
43
|
}
|
|
21
44
|
/**
|
|
22
45
|
* Object URL for an asset's cached preview (gallery thumbnails). The plugin
|
|
23
|
-
* holds the preview
|
|
46
|
+
* holds the preview bytes; the URL — a DOM resource — is created here and
|
|
24
47
|
* revoked on unmount/asset change, mirroring `<AnnotationLayer>`'s rule that
|
|
25
48
|
* object-URL lifetime belongs to the framework layer.
|
|
26
49
|
*/
|
|
27
50
|
function useStampAssetPreviewUrl(assetId) {
|
|
28
|
-
const stamp =
|
|
51
|
+
const stamp = useStamp();
|
|
29
52
|
const [url, setUrl] = (0, react.useState)(null);
|
|
30
53
|
(0, react.useEffect)(() => {
|
|
31
|
-
const preview = assetId ? stamp.
|
|
54
|
+
const preview = assetId ? stamp.getAssetPreview(assetId) : null;
|
|
32
55
|
if (!preview) {
|
|
33
56
|
setUrl(null);
|
|
34
57
|
return;
|
|
35
58
|
}
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
const obj = URL.createObjectURL(new Blob([body], { type: preview.mimeType }));
|
|
39
|
-
setUrl(obj);
|
|
59
|
+
const objectUrl = (0, _embedpdf_web.objectUrlOf)(preview);
|
|
60
|
+
setUrl(objectUrl.url);
|
|
40
61
|
return () => {
|
|
41
|
-
|
|
62
|
+
objectUrl.revoke();
|
|
42
63
|
setUrl(null);
|
|
43
64
|
};
|
|
44
65
|
}, [stamp, assetId]);
|
|
45
66
|
return url;
|
|
46
67
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Arm/disarm assets against the nearest `<DocumentScope>` (or the active
|
|
49
|
-
* document) — the one-liner a gallery item's onClick needs.
|
|
50
|
-
*/
|
|
51
|
-
function useArmStampAsset() {
|
|
52
|
-
const stamp = require_runtime.useCapability(_embedpdf_plugin_stamp.StampToken);
|
|
53
|
-
const documentId = require_runtime.useDocumentId();
|
|
54
|
-
return {
|
|
55
|
-
armAsset: (assetId, opts) => {
|
|
56
|
-
if (!documentId) return Promise.reject(/* @__PURE__ */ new Error("[stamp] no document in scope"));
|
|
57
|
-
return stamp.armAsset(documentId, assetId, opts);
|
|
58
|
-
},
|
|
59
|
-
disarm: () => {
|
|
60
|
-
if (documentId) stamp.disarm(documentId);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
68
|
//#endregion
|
|
65
69
|
Object.defineProperty(exports, "indexedDbByteStore", {
|
|
66
70
|
enumerable: true,
|
|
@@ -68,11 +72,13 @@ Object.defineProperty(exports, "indexedDbByteStore", {
|
|
|
68
72
|
return _embedpdf_web.indexedDbByteStore;
|
|
69
73
|
}
|
|
70
74
|
});
|
|
71
|
-
exports.useArmStampAsset = useArmStampAsset;
|
|
72
75
|
exports.useStamp = useStamp;
|
|
73
76
|
exports.useStampAssetPreviewUrl = useStampAssetPreviewUrl;
|
|
74
77
|
exports.useStampAssets = useStampAssets;
|
|
78
|
+
exports.useStampEvent = useStampEvent;
|
|
75
79
|
exports.useStampLibraries = useStampLibraries;
|
|
80
|
+
exports.useStampSettings = useStampSettings;
|
|
81
|
+
exports.useStampState = useStampState;
|
|
76
82
|
Object.keys(_embedpdf_plugin_stamp).forEach(function(k) {
|
|
77
83
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
78
84
|
enumerable: true,
|
package/dist/stamp.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stamp.cjs","names":["useCapability","StampToken","
|
|
1
|
+
{"version":3,"file":"stamp.cjs","names":["useCapability","StampToken","stateHook","stampState","settingsHook","useSelector","shallowArray"],"sources":["../src/stamp.tsx"],"sourcesContent":["/**\n * The React view of @embedpdf/plugin-stamp.\n *\n * Thin by design: the plugin owns the store (libraries/assets) and the binary\n * sidecar (bytes + cached previews); this file only exposes hooks and owns the\n * DOM-side object-URL lifetime for gallery thumbnails. Placement UI needs no\n * component here — arming rides the annotation plugin, whose `<AnnotationLayer>`\n * already renders the hover ghost. `useStamp()` inside a `<DocumentScope>`\n * places on that document; elsewhere on the active one.\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-stamp';\n// The browser store for `persistStampLibraries` / `restoreStampLibraries`\n// (structurally the plugin's `StampLibraryStore`), written once in `@embedpdf/web`.\nexport { indexedDbByteStore } from '@embedpdf/web';\nexport type { ByteStore } from '@embedpdf/web';\nimport { objectUrlOf } from '@embedpdf/web';\nimport { useEffect, useState } from 'react';\nimport {\n StampToken,\n stampState,\n type StampAsset,\n type StampAssetFilter,\n type StampCapability,\n type StampLibrary,\n type StampLibraryFilter,\n} from '@embedpdf/plugin-stamp';\nimport type { EventHook } from '@embedpdf/core';\nimport { shallowArray, useCapability, useCapabilityEvent, useSelector } from './runtime';\nimport { settingsHook, stateHook } from './state';\n\n/**\n * The stamp capability. Libraries are shared by every document; the placing\n * verbs act on the document this component is in.\n */\nexport function useStamp(): StampCapability {\n return useCapability(StampToken);\n}\n\n/** Subscribe to one stamp event for the mounted lifetime: `useStampEvent((stamp) => stamp.onAssetCreated, handler)`. */\nexport function useStampEvent<T>(\n select: (stamp: StampCapability) => EventHook<T>,\n handler: (event: T) => void,\n): void {\n useCapabilityEvent(StampToken, select, handler);\n}\n\n/**\n * The stamps' state for this component's document: the armed stamp (the\n * page's State table, declared once in `stampState`). Takes a selector, and\n * re-renders only when what it returns changes.\n */\nexport const useStampState = stateHook(stampState);\n\n/** The stamp settings (`assetEngine`, `previewWidth`, `dynamic`), with or without a document. Takes a selector. */\nexport const useStampSettings = settingsHook(StampToken);\n\n/** Libraries, optionally of one kind or several (`{ kind: 'stamps' }`, `{ kind: ['stamps', 'toolbar'] }`). */\nexport function useStampLibraries(filter?: StampLibraryFilter): readonly StampLibrary[] {\n // Keyed by value, so an inline filter doesn't read a new list every render.\n const kinds =\n filter?.kind === undefined ? undefined : ([] as string[]).concat(filter.kind).join('\\u0000');\n return useSelector(\n StampToken,\n (stamp) =>\n stamp.listLibraries(kinds === undefined ? undefined : { kind: kinds.split('\\u0000') }),\n shallowArray,\n );\n}\n\n/** The stamps of one library (`{ libraryId }`), of one kind or category, or every stamp. */\nexport function useStampAssets(filter?: StampAssetFilter): readonly StampAsset[] {\n const libraryId = filter?.libraryId;\n const kind = filter?.kind;\n const category = filter?.category;\n return useSelector(\n StampToken,\n (stamp) => stamp.listAssets({ libraryId, kind, category }),\n shallowArray,\n );\n}\n\n/**\n * Object URL for an asset's cached preview (gallery thumbnails). The plugin\n * holds the preview bytes; the URL — a DOM resource — is created here and\n * revoked on unmount/asset change, mirroring `<AnnotationLayer>`'s rule that\n * object-URL lifetime belongs to the framework layer.\n */\nexport function useStampAssetPreviewUrl(assetId: string | null): string | null {\n const stamp = useStamp();\n const [url, setUrl] = useState<string | null>(null);\n useEffect(() => {\n const preview = assetId ? stamp.getAssetPreview(assetId) : null;\n if (!preview) {\n setUrl(null);\n return;\n }\n const objectUrl = objectUrlOf(preview);\n setUrl(objectUrl.url);\n return () => {\n objectUrl.revoke();\n setUrl(null);\n };\n }, [stamp, assetId]);\n return url;\n}\n"],"mappings":";;;;;;;;;;;;AAoCA,SAAgB,WAA4B;CAC1C,OAAOA,gBAAAA,cAAcC,uBAAAA,UAAU;AACjC;;AAGA,SAAgB,cACd,QACA,SACM;CACN,gBAAA,mBAAmBA,uBAAAA,YAAY,QAAQ,OAAO;AAChD;;;;;;AAOA,MAAa,gBAAgBC,cAAAA,UAAUC,uBAAAA,UAAU;;AAGjD,MAAa,mBAAmBC,cAAAA,aAAaH,uBAAAA,UAAU;;AAGvD,SAAgB,kBAAkB,QAAsD;CAEtF,MAAM,QACJ,QAAQ,SAAS,KAAA,IAAY,KAAA,IAAa,CAAC,CAAC,CAAc,OAAO,OAAO,IAAI,CAAC,CAAC,KAAK,IAAQ;CAC7F,OAAOI,gBAAAA,YACLJ,uBAAAA,aACC,UACC,MAAM,cAAc,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,MAAM,MAAM,MAAM,IAAQ,EAAE,CAAC,GACvFK,gBAAAA,YACF;AACF;;AAGA,SAAgB,eAAe,QAAkD;CAC/E,MAAM,YAAY,QAAQ;CAC1B,MAAM,OAAO,QAAQ;CACrB,MAAM,WAAW,QAAQ;CACzB,OAAOD,gBAAAA,YACLJ,uBAAAA,aACC,UAAU,MAAM,WAAW;EAAE;EAAW;EAAM;CAAS,CAAC,GACzDK,gBAAAA,YACF;AACF;;;;;;;AAQA,SAAgB,wBAAwB,SAAuC;CAC7E,MAAM,QAAQ,SAAS;CACvB,MAAM,CAAC,KAAK,WAAA,GAAA,MAAA,SAAA,CAAkC,IAAI;CAClD,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,MAAM,UAAU,UAAU,MAAM,gBAAgB,OAAO,IAAI;EAC3D,IAAI,CAAC,SAAS;GACZ,OAAO,IAAI;GACX;EACF;EACA,MAAM,aAAA,GAAA,cAAA,YAAA,CAAwB,OAAO;EACrC,OAAO,UAAU,GAAG;EACpB,aAAa;GACX,UAAU,OAAO;GACjB,OAAO,IAAI;EACb;CACF,GAAG,CAAC,OAAO,OAAO,CAAC;CACnB,OAAO;AACT"}
|
package/dist/stamp.d.cts
CHANGED
|
@@ -1,30 +1,37 @@
|
|
|
1
|
+
import { n as StateHook, t as SettingsHook } from "./state-0K1I5cM4.cjs";
|
|
2
|
+
import { EventHook } from "@embedpdf/core";
|
|
1
3
|
import { ByteStore, indexedDbByteStore } from "@embedpdf/web";
|
|
2
|
-
import { StampAsset, StampLibrary,
|
|
4
|
+
import { StampAsset, StampAssetFilter, StampCapability, StampLibrary, StampLibraryFilter } from "@embedpdf/plugin-stamp";
|
|
3
5
|
export * from "@embedpdf/plugin-stamp";
|
|
4
6
|
//#region src/stamp.d.ts
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The stamp capability. Libraries are shared by every document; the placing
|
|
9
|
+
* verbs act on the document this component is in.
|
|
10
|
+
*/
|
|
11
|
+
declare function useStamp(): StampCapability;
|
|
12
|
+
/** Subscribe to one stamp event for the mounted lifetime: `useStampEvent((stamp) => stamp.onAssetCreated, handler)`. */
|
|
13
|
+
declare function useStampEvent<T>(select: (stamp: StampCapability) => EventHook<T>, handler: (event: T) => void): void;
|
|
14
|
+
/**
|
|
15
|
+
* The stamps' state for this component's document: the armed stamp (the
|
|
16
|
+
* page's State table, declared once in `stampState`). Takes a selector, and
|
|
17
|
+
* re-renders only when what it returns changes.
|
|
18
|
+
*/
|
|
19
|
+
declare const useStampState: StateHook<{
|
|
20
|
+
armedAsset: StampAsset | null;
|
|
21
|
+
}>;
|
|
22
|
+
/** The stamp settings (`assetEngine`, `previewWidth`, `dynamic`), with or without a document. Takes a selector. */
|
|
23
|
+
declare const useStampSettings: SettingsHook<import("@embedpdf/plugin-stamp").StampSettings>;
|
|
7
24
|
/** Libraries, optionally of one kind or several (`{ kind: 'stamps' }`, `{ kind: ['stamps', 'toolbar'] }`). */
|
|
8
|
-
declare function useStampLibraries(
|
|
9
|
-
/**
|
|
10
|
-
declare function useStampAssets(
|
|
25
|
+
declare function useStampLibraries(filter?: StampLibraryFilter): readonly StampLibrary[];
|
|
26
|
+
/** The stamps of one library (`{ libraryId }`), of one kind or category, or every stamp. */
|
|
27
|
+
declare function useStampAssets(filter?: StampAssetFilter): readonly StampAsset[];
|
|
11
28
|
/**
|
|
12
29
|
* Object URL for an asset's cached preview (gallery thumbnails). The plugin
|
|
13
|
-
* holds the preview
|
|
30
|
+
* holds the preview bytes; the URL — a DOM resource — is created here and
|
|
14
31
|
* revoked on unmount/asset change, mirroring `<AnnotationLayer>`'s rule that
|
|
15
32
|
* object-URL lifetime belongs to the framework layer.
|
|
16
33
|
*/
|
|
17
34
|
declare function useStampAssetPreviewUrl(assetId: string | null): string | null;
|
|
18
|
-
/**
|
|
19
|
-
* Arm/disarm assets against the nearest `<DocumentScope>` (or the active
|
|
20
|
-
* document) — the one-liner a gallery item's onClick needs.
|
|
21
|
-
*/
|
|
22
|
-
declare function useArmStampAsset(): {
|
|
23
|
-
armAsset: (assetId: string, opts?: {
|
|
24
|
-
targetWidth?: number;
|
|
25
|
-
}) => Promise<void>;
|
|
26
|
-
disarm: () => void;
|
|
27
|
-
};
|
|
28
35
|
//#endregion
|
|
29
|
-
export { type ByteStore, indexedDbByteStore,
|
|
36
|
+
export { type ByteStore, indexedDbByteStore, useStamp, useStampAssetPreviewUrl, useStampAssets, useStampEvent, useStampLibraries, useStampSettings, useStampState };
|
|
30
37
|
//# sourceMappingURL=stamp.d.cts.map
|
package/dist/stamp.d.ts
CHANGED
|
@@ -1,30 +1,37 @@
|
|
|
1
|
+
import { n as StateHook, t as SettingsHook } from "./state-0K1I5cM4.js";
|
|
2
|
+
import { EventHook } from "@embedpdf/core";
|
|
1
3
|
import { ByteStore, indexedDbByteStore } from "@embedpdf/web";
|
|
2
|
-
import { StampAsset, StampLibrary,
|
|
4
|
+
import { StampAsset, StampAssetFilter, StampCapability, StampLibrary, StampLibraryFilter } from "@embedpdf/plugin-stamp";
|
|
3
5
|
export * from "@embedpdf/plugin-stamp";
|
|
4
6
|
//#region src/stamp.d.ts
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The stamp capability. Libraries are shared by every document; the placing
|
|
9
|
+
* verbs act on the document this component is in.
|
|
10
|
+
*/
|
|
11
|
+
declare function useStamp(): StampCapability;
|
|
12
|
+
/** Subscribe to one stamp event for the mounted lifetime: `useStampEvent((stamp) => stamp.onAssetCreated, handler)`. */
|
|
13
|
+
declare function useStampEvent<T>(select: (stamp: StampCapability) => EventHook<T>, handler: (event: T) => void): void;
|
|
14
|
+
/**
|
|
15
|
+
* The stamps' state for this component's document: the armed stamp (the
|
|
16
|
+
* page's State table, declared once in `stampState`). Takes a selector, and
|
|
17
|
+
* re-renders only when what it returns changes.
|
|
18
|
+
*/
|
|
19
|
+
declare const useStampState: StateHook<{
|
|
20
|
+
armedAsset: StampAsset | null;
|
|
21
|
+
}>;
|
|
22
|
+
/** The stamp settings (`assetEngine`, `previewWidth`, `dynamic`), with or without a document. Takes a selector. */
|
|
23
|
+
declare const useStampSettings: SettingsHook<import("@embedpdf/plugin-stamp").StampSettings>;
|
|
7
24
|
/** Libraries, optionally of one kind or several (`{ kind: 'stamps' }`, `{ kind: ['stamps', 'toolbar'] }`). */
|
|
8
|
-
declare function useStampLibraries(
|
|
9
|
-
/**
|
|
10
|
-
declare function useStampAssets(
|
|
25
|
+
declare function useStampLibraries(filter?: StampLibraryFilter): readonly StampLibrary[];
|
|
26
|
+
/** The stamps of one library (`{ libraryId }`), of one kind or category, or every stamp. */
|
|
27
|
+
declare function useStampAssets(filter?: StampAssetFilter): readonly StampAsset[];
|
|
11
28
|
/**
|
|
12
29
|
* Object URL for an asset's cached preview (gallery thumbnails). The plugin
|
|
13
|
-
* holds the preview
|
|
30
|
+
* holds the preview bytes; the URL — a DOM resource — is created here and
|
|
14
31
|
* revoked on unmount/asset change, mirroring `<AnnotationLayer>`'s rule that
|
|
15
32
|
* object-URL lifetime belongs to the framework layer.
|
|
16
33
|
*/
|
|
17
34
|
declare function useStampAssetPreviewUrl(assetId: string | null): string | null;
|
|
18
|
-
/**
|
|
19
|
-
* Arm/disarm assets against the nearest `<DocumentScope>` (or the active
|
|
20
|
-
* document) — the one-liner a gallery item's onClick needs.
|
|
21
|
-
*/
|
|
22
|
-
declare function useArmStampAsset(): {
|
|
23
|
-
armAsset: (assetId: string, opts?: {
|
|
24
|
-
targetWidth?: number;
|
|
25
|
-
}) => Promise<void>;
|
|
26
|
-
disarm: () => void;
|
|
27
|
-
};
|
|
28
35
|
//#endregion
|
|
29
|
-
export { type ByteStore, indexedDbByteStore,
|
|
36
|
+
export { type ByteStore, indexedDbByteStore, useStamp, useStampAssetPreviewUrl, useStampAssets, useStampEvent, useStampLibraries, useStampSettings, useStampState };
|
|
30
37
|
//# sourceMappingURL=stamp.d.ts.map
|
package/dist/stamp.js
CHANGED
|
@@ -1,67 +1,70 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import {
|
|
1
|
+
import { E as useSelector, f as useCapability, p as useCapabilityEvent, u as shallowArray } from "./runtime-tD5iJU83.js";
|
|
2
|
+
import { n as stateHook, t as settingsHook } from "./state-CzI2KlZb.js";
|
|
3
|
+
import { indexedDbByteStore, objectUrlOf } from "@embedpdf/web";
|
|
3
4
|
import { useEffect, useState } from "react";
|
|
4
|
-
import {
|
|
5
|
-
import { StampToken } from "@embedpdf/plugin-stamp";
|
|
5
|
+
import { StampToken, stampState } from "@embedpdf/plugin-stamp";
|
|
6
6
|
export * from "@embedpdf/plugin-stamp";
|
|
7
7
|
//#region src/stamp.tsx
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* The stamp capability. Libraries are shared by every document; the placing
|
|
10
|
+
* verbs act on the document this component is in.
|
|
11
|
+
*/
|
|
9
12
|
function useStamp() {
|
|
10
13
|
return useCapability(StampToken);
|
|
11
14
|
}
|
|
15
|
+
/** Subscribe to one stamp event for the mounted lifetime: `useStampEvent((stamp) => stamp.onAssetCreated, handler)`. */
|
|
16
|
+
function useStampEvent(select, handler) {
|
|
17
|
+
useCapabilityEvent(StampToken, select, handler);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The stamps' state for this component's document: the armed stamp (the
|
|
21
|
+
* page's State table, declared once in `stampState`). Takes a selector, and
|
|
22
|
+
* re-renders only when what it returns changes.
|
|
23
|
+
*/
|
|
24
|
+
const useStampState = stateHook(stampState);
|
|
25
|
+
/** The stamp settings (`assetEngine`, `previewWidth`, `dynamic`), with or without a document. Takes a selector. */
|
|
26
|
+
const useStampSettings = settingsHook(StampToken);
|
|
12
27
|
/** Libraries, optionally of one kind or several (`{ kind: 'stamps' }`, `{ kind: ['stamps', 'toolbar'] }`). */
|
|
13
|
-
function useStampLibraries(
|
|
14
|
-
const kinds =
|
|
15
|
-
return useSelector(StampToken, (
|
|
28
|
+
function useStampLibraries(filter) {
|
|
29
|
+
const kinds = filter?.kind === void 0 ? void 0 : [].concat(filter.kind).join("\0");
|
|
30
|
+
return useSelector(StampToken, (stamp) => stamp.listLibraries(kinds === void 0 ? void 0 : { kind: kinds.split("\0") }), shallowArray);
|
|
16
31
|
}
|
|
17
|
-
/**
|
|
18
|
-
function useStampAssets(
|
|
19
|
-
|
|
32
|
+
/** The stamps of one library (`{ libraryId }`), of one kind or category, or every stamp. */
|
|
33
|
+
function useStampAssets(filter) {
|
|
34
|
+
const libraryId = filter?.libraryId;
|
|
35
|
+
const kind = filter?.kind;
|
|
36
|
+
const category = filter?.category;
|
|
37
|
+
return useSelector(StampToken, (stamp) => stamp.listAssets({
|
|
38
|
+
libraryId,
|
|
39
|
+
kind,
|
|
40
|
+
category
|
|
41
|
+
}), shallowArray);
|
|
20
42
|
}
|
|
21
43
|
/**
|
|
22
44
|
* Object URL for an asset's cached preview (gallery thumbnails). The plugin
|
|
23
|
-
* holds the preview
|
|
45
|
+
* holds the preview bytes; the URL — a DOM resource — is created here and
|
|
24
46
|
* revoked on unmount/asset change, mirroring `<AnnotationLayer>`'s rule that
|
|
25
47
|
* object-URL lifetime belongs to the framework layer.
|
|
26
48
|
*/
|
|
27
49
|
function useStampAssetPreviewUrl(assetId) {
|
|
28
|
-
const stamp =
|
|
50
|
+
const stamp = useStamp();
|
|
29
51
|
const [url, setUrl] = useState(null);
|
|
30
52
|
useEffect(() => {
|
|
31
|
-
const preview = assetId ? stamp.
|
|
53
|
+
const preview = assetId ? stamp.getAssetPreview(assetId) : null;
|
|
32
54
|
if (!preview) {
|
|
33
55
|
setUrl(null);
|
|
34
56
|
return;
|
|
35
57
|
}
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
const obj = URL.createObjectURL(new Blob([body], { type: preview.mimeType }));
|
|
39
|
-
setUrl(obj);
|
|
58
|
+
const objectUrl = objectUrlOf(preview);
|
|
59
|
+
setUrl(objectUrl.url);
|
|
40
60
|
return () => {
|
|
41
|
-
|
|
61
|
+
objectUrl.revoke();
|
|
42
62
|
setUrl(null);
|
|
43
63
|
};
|
|
44
64
|
}, [stamp, assetId]);
|
|
45
65
|
return url;
|
|
46
66
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Arm/disarm assets against the nearest `<DocumentScope>` (or the active
|
|
49
|
-
* document) — the one-liner a gallery item's onClick needs.
|
|
50
|
-
*/
|
|
51
|
-
function useArmStampAsset() {
|
|
52
|
-
const stamp = useCapability(StampToken);
|
|
53
|
-
const documentId = useDocumentId();
|
|
54
|
-
return {
|
|
55
|
-
armAsset: (assetId, opts) => {
|
|
56
|
-
if (!documentId) return Promise.reject(/* @__PURE__ */ new Error("[stamp] no document in scope"));
|
|
57
|
-
return stamp.armAsset(documentId, assetId, opts);
|
|
58
|
-
},
|
|
59
|
-
disarm: () => {
|
|
60
|
-
if (documentId) stamp.disarm(documentId);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
67
|
//#endregion
|
|
65
|
-
export { indexedDbByteStore,
|
|
68
|
+
export { indexedDbByteStore, useStamp, useStampAssetPreviewUrl, useStampAssets, useStampEvent, useStampLibraries, useStampSettings, useStampState };
|
|
66
69
|
|
|
67
70
|
//# sourceMappingURL=stamp.js.map
|
package/dist/stamp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stamp.js","names":[],"sources":["../src/stamp.tsx"],"sourcesContent":["/**\n * The React view of @embedpdf/plugin-stamp.\n *\n * Thin by design: the plugin owns the store (libraries/assets) and the binary\n * sidecar (bytes + cached previews); this file only exposes hooks and owns the\n * DOM-side object-URL lifetime for gallery thumbnails. Placement UI needs no\n * component here — arming rides the annotation plugin, whose `<AnnotationLayer>`\n * already renders the hover ghost.\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-stamp';\n// The browser store for `persistStampLibraries` / `restoreStampLibraries`\n// (structurally the plugin's `StampLibraryStore`), written once in `@embedpdf/web`.\nexport { indexedDbByteStore } from '@embedpdf/web';\nexport type { ByteStore } from '@embedpdf/web';\nimport { useEffect, useState } from 'react';\nimport {\n StampToken,\n type StampAsset,\n type StampLibrary,\n type
|
|
1
|
+
{"version":3,"file":"stamp.js","names":[],"sources":["../src/stamp.tsx"],"sourcesContent":["/**\n * The React view of @embedpdf/plugin-stamp.\n *\n * Thin by design: the plugin owns the store (libraries/assets) and the binary\n * sidecar (bytes + cached previews); this file only exposes hooks and owns the\n * DOM-side object-URL lifetime for gallery thumbnails. Placement UI needs no\n * component here — arming rides the annotation plugin, whose `<AnnotationLayer>`\n * already renders the hover ghost. `useStamp()` inside a `<DocumentScope>`\n * places on that document; elsewhere on the active one.\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-stamp';\n// The browser store for `persistStampLibraries` / `restoreStampLibraries`\n// (structurally the plugin's `StampLibraryStore`), written once in `@embedpdf/web`.\nexport { indexedDbByteStore } from '@embedpdf/web';\nexport type { ByteStore } from '@embedpdf/web';\nimport { objectUrlOf } from '@embedpdf/web';\nimport { useEffect, useState } from 'react';\nimport {\n StampToken,\n stampState,\n type StampAsset,\n type StampAssetFilter,\n type StampCapability,\n type StampLibrary,\n type StampLibraryFilter,\n} from '@embedpdf/plugin-stamp';\nimport type { EventHook } from '@embedpdf/core';\nimport { shallowArray, useCapability, useCapabilityEvent, useSelector } from './runtime';\nimport { settingsHook, stateHook } from './state';\n\n/**\n * The stamp capability. Libraries are shared by every document; the placing\n * verbs act on the document this component is in.\n */\nexport function useStamp(): StampCapability {\n return useCapability(StampToken);\n}\n\n/** Subscribe to one stamp event for the mounted lifetime: `useStampEvent((stamp) => stamp.onAssetCreated, handler)`. */\nexport function useStampEvent<T>(\n select: (stamp: StampCapability) => EventHook<T>,\n handler: (event: T) => void,\n): void {\n useCapabilityEvent(StampToken, select, handler);\n}\n\n/**\n * The stamps' state for this component's document: the armed stamp (the\n * page's State table, declared once in `stampState`). Takes a selector, and\n * re-renders only when what it returns changes.\n */\nexport const useStampState = stateHook(stampState);\n\n/** The stamp settings (`assetEngine`, `previewWidth`, `dynamic`), with or without a document. Takes a selector. */\nexport const useStampSettings = settingsHook(StampToken);\n\n/** Libraries, optionally of one kind or several (`{ kind: 'stamps' }`, `{ kind: ['stamps', 'toolbar'] }`). */\nexport function useStampLibraries(filter?: StampLibraryFilter): readonly StampLibrary[] {\n // Keyed by value, so an inline filter doesn't read a new list every render.\n const kinds =\n filter?.kind === undefined ? undefined : ([] as string[]).concat(filter.kind).join('\\u0000');\n return useSelector(\n StampToken,\n (stamp) =>\n stamp.listLibraries(kinds === undefined ? undefined : { kind: kinds.split('\\u0000') }),\n shallowArray,\n );\n}\n\n/** The stamps of one library (`{ libraryId }`), of one kind or category, or every stamp. */\nexport function useStampAssets(filter?: StampAssetFilter): readonly StampAsset[] {\n const libraryId = filter?.libraryId;\n const kind = filter?.kind;\n const category = filter?.category;\n return useSelector(\n StampToken,\n (stamp) => stamp.listAssets({ libraryId, kind, category }),\n shallowArray,\n );\n}\n\n/**\n * Object URL for an asset's cached preview (gallery thumbnails). The plugin\n * holds the preview bytes; the URL — a DOM resource — is created here and\n * revoked on unmount/asset change, mirroring `<AnnotationLayer>`'s rule that\n * object-URL lifetime belongs to the framework layer.\n */\nexport function useStampAssetPreviewUrl(assetId: string | null): string | null {\n const stamp = useStamp();\n const [url, setUrl] = useState<string | null>(null);\n useEffect(() => {\n const preview = assetId ? stamp.getAssetPreview(assetId) : null;\n if (!preview) {\n setUrl(null);\n return;\n }\n const objectUrl = objectUrlOf(preview);\n setUrl(objectUrl.url);\n return () => {\n objectUrl.revoke();\n setUrl(null);\n };\n }, [stamp, assetId]);\n return url;\n}\n"],"mappings":";;;;;;;;;;;AAoCA,SAAgB,WAA4B;CAC1C,OAAO,cAAc,UAAU;AACjC;;AAGA,SAAgB,cACd,QACA,SACM;CACN,mBAAmB,YAAY,QAAQ,OAAO;AAChD;;;;;;AAOA,MAAa,gBAAgB,UAAU,UAAU;;AAGjD,MAAa,mBAAmB,aAAa,UAAU;;AAGvD,SAAgB,kBAAkB,QAAsD;CAEtF,MAAM,QACJ,QAAQ,SAAS,KAAA,IAAY,KAAA,IAAa,CAAC,CAAC,CAAc,OAAO,OAAO,IAAI,CAAC,CAAC,KAAK,IAAQ;CAC7F,OAAO,YACL,aACC,UACC,MAAM,cAAc,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,MAAM,MAAM,MAAM,IAAQ,EAAE,CAAC,GACvF,YACF;AACF;;AAGA,SAAgB,eAAe,QAAkD;CAC/E,MAAM,YAAY,QAAQ;CAC1B,MAAM,OAAO,QAAQ;CACrB,MAAM,WAAW,QAAQ;CACzB,OAAO,YACL,aACC,UAAU,MAAM,WAAW;EAAE;EAAW;EAAM;CAAS,CAAC,GACzD,YACF;AACF;;;;;;;AAQA,SAAgB,wBAAwB,SAAuC;CAC7E,MAAM,QAAQ,SAAS;CACvB,MAAM,CAAC,KAAK,UAAU,SAAwB,IAAI;CAClD,gBAAgB;EACd,MAAM,UAAU,UAAU,MAAM,gBAAgB,OAAO,IAAI;EAC3D,IAAI,CAAC,SAAS;GACZ,OAAO,IAAI;GACX;EACF;EACA,MAAM,YAAY,YAAY,OAAO;EACrC,OAAO,UAAU,GAAG;EACpB,aAAa;GACX,UAAU,OAAO;GACjB,OAAO,IAAI;EACb;CACF,GAAG,CAAC,OAAO,OAAO,CAAC;CACnB,OAAO;AACT"}
|