@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/scrollbar.js
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import { useCapability, useSelector } from "./runtime.js";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useRef, useState } from "react";
|
|
4
|
-
import { StageToken } from "@embedpdf/plugin-stage/contract";
|
|
5
|
-
//#region src/scrollbar.tsx
|
|
6
|
-
/** Live scroll metrics for a stage lens (reference-stable; see
|
|
7
|
-
* `StageCapability.scrollMetrics`). The raw material for custom scroll UI. */
|
|
8
|
-
function useScrollMetrics(token = StageToken) {
|
|
9
|
-
return useSelector(token, (c) => c.scrollMetrics());
|
|
10
|
-
}
|
|
11
|
-
const clamp01 = (v) => Math.min(1, Math.max(0, v));
|
|
12
|
-
/** Best-effort pointer capture: an already-released pointer (pen/touch races,
|
|
13
|
-
* synthetic events in tests) throws NotFoundError — the press must still work,
|
|
14
|
-
* just without capture (moves keep arriving while the pointer stays on us). */
|
|
15
|
-
const capturePointer = (el, pointerId) => {
|
|
16
|
-
try {
|
|
17
|
-
el.setPointerCapture(pointerId);
|
|
18
|
-
} catch {}
|
|
19
|
-
};
|
|
20
|
-
/** Thumb geometry from metrics + a measured track. One formula for render,
|
|
21
|
-
* drag capture, and paging — they can never disagree. */
|
|
22
|
-
const geometry = (m, vertical, trackPx, minThumbSize) => {
|
|
23
|
-
const client = vertical ? m.clientHeight : m.clientWidth;
|
|
24
|
-
const total = vertical ? m.scrollHeight : m.scrollWidth;
|
|
25
|
-
const offset = vertical ? m.scrollTop : m.scrollLeft;
|
|
26
|
-
const maxOffset = Math.max(0, total - client);
|
|
27
|
-
const thumbLen = Math.min(trackPx, Math.max(minThumbSize, total > 0 ? client / total * trackPx : 0));
|
|
28
|
-
const travel = Math.max(0, trackPx - thumbLen);
|
|
29
|
-
return {
|
|
30
|
-
client,
|
|
31
|
-
offset,
|
|
32
|
-
maxOffset,
|
|
33
|
-
thumbLen,
|
|
34
|
-
travel,
|
|
35
|
-
thumbPos: maxOffset > 0 ? offset / maxOffset * travel : 0
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
function Scrollbar({ axis, token = StageToken, autoHide = 1200, minThumbSize = 24, trackPress = "page", className, style, thumbClassName, thumbStyle }) {
|
|
39
|
-
const stage = useCapability(token);
|
|
40
|
-
const m = useScrollMetrics(token);
|
|
41
|
-
const vertical = axis === "y";
|
|
42
|
-
const scrollable = vertical ? m.scrollableY : m.scrollableX;
|
|
43
|
-
const trackRef = useRef(null);
|
|
44
|
-
const [trackPx, setTrackPx] = useState(0);
|
|
45
|
-
const [dragging, setDragging] = useState(false);
|
|
46
|
-
const [hovered, setHovered] = useState(false);
|
|
47
|
-
const [active, setActive] = useState(true);
|
|
48
|
-
const g = geometry(m, vertical, trackPx, minThumbSize);
|
|
49
|
-
const hideAfter = autoHide === false ? 0 : autoHide;
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
if (!hideAfter) return;
|
|
52
|
-
setActive(true);
|
|
53
|
-
const t = setTimeout(() => setActive(false), hideAfter);
|
|
54
|
-
return () => clearTimeout(t);
|
|
55
|
-
}, [m, hideAfter]);
|
|
56
|
-
const shown = !hideAfter || active || hovered || dragging;
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
const el = trackRef.current;
|
|
59
|
-
if (!el) return;
|
|
60
|
-
const measure = () => setTrackPx(vertical ? el.clientHeight : el.clientWidth);
|
|
61
|
-
const ro = new ResizeObserver(measure);
|
|
62
|
-
ro.observe(el);
|
|
63
|
-
measure();
|
|
64
|
-
return () => ro.disconnect();
|
|
65
|
-
}, [vertical, scrollable]);
|
|
66
|
-
const dragRef = useRef(null);
|
|
67
|
-
const pageRef = useRef(null);
|
|
68
|
-
const lastPtr = useRef(0);
|
|
69
|
-
const ptrPos = (e) => {
|
|
70
|
-
const r = trackRef.current.getBoundingClientRect();
|
|
71
|
-
return vertical ? e.clientY - r.top : e.clientX - r.left;
|
|
72
|
-
};
|
|
73
|
-
/** Fresh geometry for paging steps — read from the capability, never a stale render. */
|
|
74
|
-
const liveGeometry = () => geometry(stage.scrollMetrics(), vertical, trackPx, minThumbSize);
|
|
75
|
-
const stopPaging = () => {
|
|
76
|
-
if (pageRef.current) {
|
|
77
|
-
clearTimeout(pageRef.current.timer);
|
|
78
|
-
clearInterval(pageRef.current.timer);
|
|
79
|
-
pageRef.current = null;
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
const endDrag = () => {
|
|
83
|
-
dragRef.current = null;
|
|
84
|
-
stopPaging();
|
|
85
|
-
setDragging(false);
|
|
86
|
-
};
|
|
87
|
-
const beginDrag = (grab, applied) => {
|
|
88
|
-
dragRef.current = {
|
|
89
|
-
grab,
|
|
90
|
-
applied,
|
|
91
|
-
max: g.maxOffset,
|
|
92
|
-
travel: g.travel
|
|
93
|
-
};
|
|
94
|
-
setDragging(true);
|
|
95
|
-
};
|
|
96
|
-
const onThumbDown = (e) => {
|
|
97
|
-
if (e.button !== 0) return;
|
|
98
|
-
e.preventDefault();
|
|
99
|
-
e.stopPropagation();
|
|
100
|
-
capturePointer(e.target, e.pointerId);
|
|
101
|
-
beginDrag(ptrPos(e) - g.thumbPos, g.offset);
|
|
102
|
-
};
|
|
103
|
-
const onTrackDown = (e) => {
|
|
104
|
-
if (e.button !== 0 || e.target !== e.currentTarget) return;
|
|
105
|
-
e.preventDefault();
|
|
106
|
-
capturePointer(e.currentTarget, e.pointerId);
|
|
107
|
-
const p = lastPtr.current = ptrPos(e);
|
|
108
|
-
if (trackPress === "jump") {
|
|
109
|
-
const want = g.travel > 0 ? clamp01((p - g.thumbLen / 2) / g.travel) * g.maxOffset : 0;
|
|
110
|
-
stage.scrollTo(vertical ? { top: want } : { left: want });
|
|
111
|
-
beginDrag(g.thumbLen / 2, want);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const dir = p < g.thumbPos ? -1 : 1;
|
|
115
|
-
const step = () => {
|
|
116
|
-
const live = liveGeometry();
|
|
117
|
-
if (dir === 1 ? lastPtr.current <= live.thumbPos + live.thumbLen : lastPtr.current >= live.thumbPos) return stopPaging();
|
|
118
|
-
stage.scrollBy(vertical ? { top: dir * live.client * .9 } : { left: dir * live.client * .9 });
|
|
119
|
-
};
|
|
120
|
-
step();
|
|
121
|
-
const timer = window.setTimeout(() => {
|
|
122
|
-
if (!pageRef.current) return;
|
|
123
|
-
pageRef.current.timer = window.setInterval(step, 80);
|
|
124
|
-
}, 350);
|
|
125
|
-
pageRef.current = {
|
|
126
|
-
dir,
|
|
127
|
-
timer
|
|
128
|
-
};
|
|
129
|
-
};
|
|
130
|
-
const onMove = (e) => {
|
|
131
|
-
const d = dragRef.current;
|
|
132
|
-
if (d) {
|
|
133
|
-
if (d.travel <= 0) return;
|
|
134
|
-
const want = clamp01((ptrPos(e) - d.grab) / d.travel) * d.max;
|
|
135
|
-
const delta = want - d.applied;
|
|
136
|
-
if (delta) {
|
|
137
|
-
stage.panBy(vertical ? 0 : -delta, vertical ? -delta : 0);
|
|
138
|
-
d.applied = want;
|
|
139
|
-
}
|
|
140
|
-
} else if (pageRef.current) lastPtr.current = ptrPos(e);
|
|
141
|
-
};
|
|
142
|
-
useEffect(() => endDrag, []);
|
|
143
|
-
if (!scrollable) return null;
|
|
144
|
-
const trackDefaults = vertical ? {
|
|
145
|
-
position: "absolute",
|
|
146
|
-
top: 0,
|
|
147
|
-
right: 0,
|
|
148
|
-
bottom: 0,
|
|
149
|
-
width: 12
|
|
150
|
-
} : {
|
|
151
|
-
position: "absolute",
|
|
152
|
-
left: 0,
|
|
153
|
-
right: 0,
|
|
154
|
-
bottom: 0,
|
|
155
|
-
height: 12
|
|
156
|
-
};
|
|
157
|
-
const thumbDefaults = vertical ? {
|
|
158
|
-
position: "absolute",
|
|
159
|
-
left: 2,
|
|
160
|
-
right: 2,
|
|
161
|
-
top: g.thumbPos,
|
|
162
|
-
height: g.thumbLen
|
|
163
|
-
} : {
|
|
164
|
-
position: "absolute",
|
|
165
|
-
top: 2,
|
|
166
|
-
bottom: 2,
|
|
167
|
-
left: g.thumbPos,
|
|
168
|
-
width: g.thumbLen
|
|
169
|
-
};
|
|
170
|
-
return /* @__PURE__ */ jsx("div", {
|
|
171
|
-
ref: trackRef,
|
|
172
|
-
role: "scrollbar",
|
|
173
|
-
"aria-orientation": vertical ? "vertical" : "horizontal",
|
|
174
|
-
"aria-valuemin": 0,
|
|
175
|
-
"aria-valuemax": Math.round(g.maxOffset),
|
|
176
|
-
"aria-valuenow": Math.round(g.offset),
|
|
177
|
-
"data-embedpdf-scrollbar": "",
|
|
178
|
-
"data-axis": axis,
|
|
179
|
-
"data-state": shown ? "visible" : "hidden",
|
|
180
|
-
"data-dragging": dragging ? "" : void 0,
|
|
181
|
-
className,
|
|
182
|
-
style: {
|
|
183
|
-
...trackDefaults,
|
|
184
|
-
touchAction: "none",
|
|
185
|
-
userSelect: "none",
|
|
186
|
-
opacity: shown ? 1 : 0,
|
|
187
|
-
transition: "opacity 200ms",
|
|
188
|
-
pointerEvents: shown ? "auto" : "none",
|
|
189
|
-
...style
|
|
190
|
-
},
|
|
191
|
-
onPointerDown: onTrackDown,
|
|
192
|
-
onPointerMove: onMove,
|
|
193
|
-
onPointerUp: endDrag,
|
|
194
|
-
onPointerCancel: endDrag,
|
|
195
|
-
onPointerEnter: () => setHovered(true),
|
|
196
|
-
onPointerLeave: () => setHovered(false),
|
|
197
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
198
|
-
"data-embedpdf-scrollbar-thumb": "",
|
|
199
|
-
className: thumbClassName,
|
|
200
|
-
style: {
|
|
201
|
-
...thumbDefaults,
|
|
202
|
-
borderRadius: 6,
|
|
203
|
-
background: "var(--epdf-scrollbar-thumb, rgba(0, 0, 0, 0.4))",
|
|
204
|
-
...thumbStyle
|
|
205
|
-
},
|
|
206
|
-
onPointerDown: onThumbDown
|
|
207
|
-
})
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
//#endregion
|
|
211
|
-
export { Scrollbar, useScrollMetrics };
|
|
212
|
-
|
|
213
|
-
//# sourceMappingURL=scrollbar.js.map
|
package/dist/scrollbar.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scrollbar.js","names":[],"sources":["../src/scrollbar.tsx"],"sourcesContent":["/**\n * Headless scrollbar for a Stage lens — a pure view of `stage.scrollMetrics()`.\n *\n * The Stage exposes the native scroller contract (scrollTop/scrollHeight/\n * clientHeight, in screen px — see plugin-stage's README); this component turns\n * it into a native-feeling bar: thumb drag with pointer capture and a preserved\n * grab point, track paging with press-and-hold repeat that stops at the\n * pointer, a minimum thumb length on long documents, and macOS-style overlay\n * auto-hide. On an UNBOUNDED stage the metrics already carry the Figma\n * semantics (the range is the union of content and view), so the same bar\n * shrinks toward the edge as you pan away and rides you back — the mapping is\n * FROZEN for the duration of a thumb drag so the thumb never chases itself\n * while the union re-collapses.\n *\n * Headless styling contract: geometry and behavior live here; looks live in\n * your CSS. Style via `className`/`thumbClassName` (or the style props) against\n * [data-embedpdf-scrollbar][data-axis=\"y\"][data-state=\"visible|hidden\"]\n * [data-embedpdf-scrollbar][data-dragging]\n * [data-embedpdf-scrollbar-thumb]\n * The defaults are deliberately minimal: a transparent track pinned to the\n * viewport edge and a `var(--epdf-scrollbar-thumb, …)` pill, so the bar works\n * unstyled and disappears into any theme. Build something else entirely\n * (minimap, progress ring) from `useScrollMetrics()` + `stage.scrollTo()`.\n */\n\nimport * as React from 'react';\nimport { useEffect, useRef, useState } from 'react';\nimport { StageToken } from '@embedpdf/plugin-stage/contract';\nimport type { ScrollMetrics, StageCapability } from '@embedpdf/plugin-stage/contract';\nimport type { CapabilityToken } from '@embedpdf/core';\nimport { useCapability, useSelector } from './runtime';\n\nexport type ScrollbarAxis = 'x' | 'y';\n\n/** Live scroll metrics for a stage lens (reference-stable; see\n * `StageCapability.scrollMetrics`). The raw material for custom scroll UI. */\nexport function useScrollMetrics(\n token: CapabilityToken<StageCapability> = StageToken,\n): ScrollMetrics {\n return useSelector(token, (c) => c.scrollMetrics());\n}\n\nexport interface ScrollbarProps {\n axis: ScrollbarAxis;\n /** The stage lens to scroll (default: the main StageToken). */\n token?: CapabilityToken<StageCapability>;\n /**\n * Overlay auto-hide: fade `autoHide` ms after the camera stops moving\n * (drags and hover pin it visible; a hidden bar ignores the pointer, like\n * macOS). `false` = always visible. Visibility is published as\n * `data-state=\"visible|hidden\"` — the default style fades opacity; replace\n * it in CSS for any other treatment. Default 1200.\n */\n autoHide?: number | false;\n /** Minimum thumb length in px — native bars never vanish on long documents.\n * Position stays proportional via the standard travel remap. Default 24. */\n minThumbSize?: number;\n /**\n * Pressing the track: 'page' steps by 90% of a viewport toward the pointer,\n * repeats while held, and stops when the thumb reaches the pointer (the\n * native default); 'jump' centers the thumb at the pointer and hands off to\n * a drag (the macOS option-click / Figma feel). Default 'page'.\n */\n trackPress?: 'page' | 'jump';\n /** Track class/style. The default style pins the bar to the right (y) or\n * bottom (x) edge of the nearest positioned ancestor — the Stage container\n * when rendered in its `overlay`; override to place it anywhere else. */\n className?: string;\n style?: React.CSSProperties;\n thumbClassName?: string;\n thumbStyle?: React.CSSProperties;\n}\n\nconst clamp01 = (v: number) => Math.min(1, Math.max(0, v));\n\n/** Best-effort pointer capture: an already-released pointer (pen/touch races,\n * synthetic events in tests) throws NotFoundError — the press must still work,\n * just without capture (moves keep arriving while the pointer stays on us). */\nconst capturePointer = (el: Element, pointerId: number) => {\n try {\n el.setPointerCapture(pointerId);\n } catch {\n /* uncaptured is fine */\n }\n};\n\n/** Thumb geometry from metrics + a measured track. One formula for render,\n * drag capture, and paging — they can never disagree. */\nconst geometry = (m: ScrollMetrics, vertical: boolean, trackPx: number, minThumbSize: number) => {\n const client = vertical ? m.clientHeight : m.clientWidth;\n const total = vertical ? m.scrollHeight : m.scrollWidth;\n const offset = vertical ? m.scrollTop : m.scrollLeft;\n const maxOffset = Math.max(0, total - client);\n const thumbLen = Math.min(\n trackPx,\n Math.max(minThumbSize, total > 0 ? (client / total) * trackPx : 0),\n );\n const travel = Math.max(0, trackPx - thumbLen);\n const thumbPos = maxOffset > 0 ? (offset / maxOffset) * travel : 0;\n return { client, offset, maxOffset, thumbLen, travel, thumbPos };\n};\n\nexport function Scrollbar({\n axis,\n token = StageToken,\n autoHide = 1200,\n minThumbSize = 24,\n trackPress = 'page',\n className,\n style,\n thumbClassName,\n thumbStyle,\n}: ScrollbarProps) {\n const stage = useCapability(token);\n const m = useScrollMetrics(token);\n const vertical = axis === 'y';\n const scrollable = vertical ? m.scrollableY : m.scrollableX;\n\n const trackRef = useRef<HTMLDivElement>(null);\n const [trackPx, setTrackPx] = useState(0);\n const [dragging, setDragging] = useState(false);\n const [hovered, setHovered] = useState(false);\n const [active, setActive] = useState(true); // camera moved recently\n\n const g = geometry(m, vertical, trackPx, minThumbSize);\n\n // ── overlay auto-hide: any metrics change re-arms the fade timer ──────────\n const hideAfter = autoHide === false ? 0 : autoHide;\n useEffect(() => {\n if (!hideAfter) return;\n setActive(true);\n const t = setTimeout(() => setActive(false), hideAfter);\n return () => clearTimeout(t);\n }, [m, hideAfter]);\n const shown = !hideAfter || active || hovered || dragging;\n\n // ── track measurement (px mapping needs real geometry) ────────────────────\n useEffect(() => {\n const el = trackRef.current;\n if (!el) return;\n const measure = () => setTrackPx(vertical ? el.clientHeight : el.clientWidth);\n const ro = new ResizeObserver(measure);\n ro.observe(el);\n measure();\n return () => ro.disconnect();\n }, [vertical, scrollable]);\n\n // ── interactions. Drag state is FROZEN at pointer-down (grab point, travel,\n // max offset) and applied as relative pans — absolute-feeling in bounded\n // mode (the range is static there) and stable in unbounded mode, where\n // the live union would otherwise shift under the pointer mid-drag. ──────\n const dragRef = useRef<{ grab: number; applied: number; max: number; travel: number } | null>(\n null,\n );\n const pageRef = useRef<{ dir: 1 | -1; timer: number } | null>(null);\n const lastPtr = useRef(0);\n\n const ptrPos = (e: React.PointerEvent) => {\n const r = trackRef.current!.getBoundingClientRect();\n return vertical ? e.clientY - r.top : e.clientX - r.left;\n };\n /** Fresh geometry for paging steps — read from the capability, never a stale render. */\n const liveGeometry = () => geometry(stage.scrollMetrics(), vertical, trackPx, minThumbSize);\n\n const stopPaging = () => {\n if (pageRef.current) {\n clearTimeout(pageRef.current.timer);\n clearInterval(pageRef.current.timer);\n pageRef.current = null;\n }\n };\n const endDrag = () => {\n dragRef.current = null;\n stopPaging();\n setDragging(false);\n };\n\n const beginDrag = (grab: number, applied: number) => {\n dragRef.current = { grab, applied, max: g.maxOffset, travel: g.travel };\n setDragging(true);\n };\n\n const onThumbDown = (e: React.PointerEvent) => {\n if (e.button !== 0) return;\n e.preventDefault();\n e.stopPropagation();\n capturePointer(e.target as Element, e.pointerId);\n beginDrag(ptrPos(e) - g.thumbPos, g.offset);\n };\n\n const onTrackDown = (e: React.PointerEvent) => {\n if (e.button !== 0 || e.target !== e.currentTarget) return; // thumb handles its own\n e.preventDefault();\n capturePointer(e.currentTarget as Element, e.pointerId);\n const p = (lastPtr.current = ptrPos(e));\n\n if (trackPress === 'jump') {\n // land the thumb centered at the pointer, then it's an ordinary drag\n const want = g.travel > 0 ? clamp01((p - g.thumbLen / 2) / g.travel) * g.maxOffset : 0;\n stage.scrollTo(vertical ? { top: want } : { left: want });\n beginDrag(g.thumbLen / 2, want);\n return;\n }\n\n // 'page': step toward the pointer, repeat while held, stop at the pointer\n const dir: 1 | -1 = p < g.thumbPos ? -1 : 1;\n const step = () => {\n const live = liveGeometry();\n const reached =\n dir === 1\n ? lastPtr.current <= live.thumbPos + live.thumbLen\n : lastPtr.current >= live.thumbPos;\n if (reached) return stopPaging();\n stage.scrollBy(\n vertical ? { top: dir * live.client * 0.9 } : { left: dir * live.client * 0.9 },\n );\n };\n step();\n // native cadence: a beat before the repeat kicks in, then a steady march\n const timer = window.setTimeout(() => {\n if (!pageRef.current) return;\n pageRef.current.timer = window.setInterval(step, 80);\n }, 350);\n pageRef.current = { dir, timer };\n };\n\n // Pointer capture retargets to the pressed element and bubbles here — one\n // move/up pair serves thumb drags, jump-drags, and paging alike.\n const onMove = (e: React.PointerEvent) => {\n const d = dragRef.current;\n if (d) {\n if (d.travel <= 0) return;\n const want = clamp01((ptrPos(e) - d.grab) / d.travel) * d.max;\n const delta = want - d.applied;\n if (delta) {\n stage.panBy(vertical ? 0 : -delta, vertical ? -delta : 0);\n d.applied = want;\n }\n } else if (pageRef.current) {\n lastPtr.current = ptrPos(e);\n }\n };\n\n useEffect(() => endDrag, []); // unmount: no orphaned repeat timers\n\n if (!scrollable) return null;\n\n const trackDefaults: React.CSSProperties = vertical\n ? { position: 'absolute', top: 0, right: 0, bottom: 0, width: 12 }\n : { position: 'absolute', left: 0, right: 0, bottom: 0, height: 12 };\n const thumbDefaults: React.CSSProperties = vertical\n ? { position: 'absolute', left: 2, right: 2, top: g.thumbPos, height: g.thumbLen }\n : { position: 'absolute', top: 2, bottom: 2, left: g.thumbPos, width: g.thumbLen };\n\n return (\n <div\n ref={trackRef}\n role=\"scrollbar\"\n aria-orientation={vertical ? 'vertical' : 'horizontal'}\n aria-valuemin={0}\n aria-valuemax={Math.round(g.maxOffset)}\n aria-valuenow={Math.round(g.offset)}\n data-embedpdf-scrollbar=\"\"\n data-axis={axis}\n data-state={shown ? 'visible' : 'hidden'}\n data-dragging={dragging ? '' : undefined}\n className={className}\n style={{\n ...trackDefaults,\n touchAction: 'none',\n userSelect: 'none',\n opacity: shown ? 1 : 0,\n transition: 'opacity 200ms',\n // a hidden overlay bar must not eat the clicks under it\n pointerEvents: shown ? 'auto' : 'none',\n ...style,\n }}\n onPointerDown={onTrackDown}\n onPointerMove={onMove}\n onPointerUp={endDrag}\n onPointerCancel={endDrag}\n onPointerEnter={() => setHovered(true)}\n onPointerLeave={() => setHovered(false)}\n >\n <div\n data-embedpdf-scrollbar-thumb=\"\"\n className={thumbClassName}\n style={{\n ...thumbDefaults,\n borderRadius: 6,\n background: 'var(--epdf-scrollbar-thumb, rgba(0, 0, 0, 0.4))',\n ...thumbStyle,\n }}\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AAA;AAET"}
|
package/dist/stage.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stage.cjs","names":["makePageContext","PageProvider","StageToken","useCapability","useOptionalCapability","InteractionToken","useKernelValue","useDocumentId","useSelector","ProjectorProvider","settingsEqual"],"sources":["../src/stage.tsx"],"sourcesContent":["/**\n * Stage / RenderLayer + facade hooks.\n *\n * <Stage> virtualizes and positions page surfaces by the camera, and hands each\n * one to YOUR render prop — you bring the layers. (The standalone, Stage-free\n * single-page surface lives in `./page-view` so it never pulls the stage plugin.)\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-stage';\nimport * as React from 'react';\nimport { useLayoutEffect, useMemo, useRef } from 'react';\nimport { StageToken, createScrollHandler, settingsEqual } from '@embedpdf/plugin-stage';\nimport type { StageCapability, VisiblePage } from '@embedpdf/plugin-stage';\nimport type { CapabilityToken } from '@embedpdf/core';\n\n/** Which stage lens to bind to. Defaults to the main StageToken — pass a custom\n * token to drive an additional lens (e.g. a wrapped thumbnail sidebar). */\nexport type StageTokenProp = CapabilityToken<StageCapability>;\nimport type { PageFrame } from '@embedpdf/core-geometry';\nimport { InteractionToken } from '@embedpdf/plugin-interaction/contract';\nimport { createStageSurface } from '@embedpdf/web';\nimport { ProjectorProvider, type ProjectorBinding, type ViewProjector } from './anchored';\nimport {\n makePageContext,\n PageProvider,\n useCapability,\n useDocumentId,\n useKernelValue,\n useOptionalCapability,\n useSelector,\n} from './runtime';\nimport type { PageContextValue } from './runtime';\n\nfunction PageSurface({\n documentId,\n page,\n frame,\n stage,\n render,\n chrome,\n}: {\n documentId: string;\n page: VisiblePage;\n /** Reserved chrome bands around the page (screen px); the layout reserved the\n * matching space, so the outer box tiles into it. */\n frame: PageFrame;\n /** The stage capability — the demand getter reads visibility LIVE off it. */\n stage: StageCapability;\n render: (page: PageContextValue) => React.ReactNode;\n chrome?: (page: PageContextValue) => React.ReactNode;\n}) {\n const ref = useRef<HTMLDivElement>(null);\n const t = page.transform;\n const rotation = page.rotation;\n // All geometry comes from the transform: the DISPLAY footprint (viewWidth/Height,\n // already w↔h-swapped + device-snapped) and the UN-rotated content box\n // (contentWidth/Height). The shell never re-derives `* zoom` / `* dpr` / snapping.\n const outerW = t.viewWidth + frame.left + frame.right;\n const outerH = t.viewHeight + frame.top + frame.bottom;\n // page.screenX/screenY are the device-snapped footprint top-left; the outer box\n // sits one frame further out so the content keeps its scene position.\n const left = page.screenX - frame.left;\n const top = page.screenY - frame.top;\n // Center the (possibly rotated) content box on the display box and rotate about\n // its center — NO translate(), so rotation 0 carries no transform and pixel-snaps\n // like the axis-aligned shadow behind it (no hairline seam).\n const contentLeft = frame.left + (t.viewWidth - t.contentWidth) / 2;\n const contentTop = frame.top + (t.viewHeight - t.contentHeight) / 2;\n // The page-view DEMAND is a PULL: the getter closes over\n // stable references (capability + pon) and reads the stage's live state at\n // call time — visibility is the STAGE's data (`VisiblePage.visibleRect`),\n // not something an adapter re-derives or caches. Absent from the visible\n // set = zero rect (\"want nothing\"), distinct from PageView's undefined\n // getter (\"whole page\").\n const ctx = useMemo(\n () =>\n makePageContext(\n documentId,\n // the hosting lens — per-view raster planning keys tile state by it,\n // so a thumbnail rail and the main view never fight over one plan\n stage.lensId(),\n page.pon,\n page.pageIndex,\n frame,\n t,\n () => ref.current!.getBoundingClientRect(),\n () => {\n const live = stage.visiblePages().find((p) => p.pon === page.pon);\n return live\n ? { desiredDeviceWidth: live.transform.deviceWidth, visibleRect: live.visibleRect }\n : {\n desiredDeviceWidth: t.deviceWidth,\n visibleRect: { x: 0, y: 0, width: 0, height: 0 },\n };\n },\n ),\n [documentId, page.pon, page.pageIndex, frame, t, stage],\n );\n return (\n <div style={{ position: 'absolute', left, top, width: outerW, height: outerH }}>\n <PageProvider value={ctx}>\n {/* drop shadow ONLY — axis-aligned at the content box (inset by the frame),\n transparent fill so it can never peek out behind the bitmap, and it\n stays put under rotation. */}\n <div\n style={{\n position: 'absolute',\n left: frame.left,\n top: frame.top,\n width: t.viewWidth,\n height: t.viewHeight,\n // themeable: override via the CSS variable (app stylesheet), no props\n boxShadow: 'var(--epdf-page-shadow, 0 6px 18px rgba(0,0,0,.18))',\n }}\n />\n {/* the page: white backing + bitmap as ONE rasterized box, so there is no\n seam between them and nothing white larger than the bitmap to leak.\n The ONLY thing rotation turns; markers/annotations ride it in content\n coordinates. Rotation 0 carries no transform → pixel-snaps cleanly. */}\n <div\n ref={ref}\n style={{\n position: 'absolute',\n left: contentLeft,\n top: contentTop,\n width: t.contentWidth,\n height: t.contentHeight,\n background: '#fff',\n transform: rotation ? `rotate(${rotation}deg)` : undefined,\n // We render our own selection highlights — suppress native text/image\n // selection (and the double-click image grab) on the whole page subtree.\n userSelect: 'none',\n WebkitUserSelect: 'none',\n }}\n >\n {render(ctx)}\n </div>\n {/* box-space chrome — labels, selection border, per-page buttons — fills\n the outer box, NEVER rotates. Bands are plain regions: a label is\n `bottom:0; height: frame.bottom`, a button row `top:0; height: frame.top`. */}\n {chrome?.(ctx)}\n </PageProvider>\n </div>\n );\n}\n\nexport interface StageProps {\n /**\n * PAGE-SPACE content for each visible page (RenderLayer, annotations,\n * markers). Rendered inside the page's content frame, so it ROTATES with the\n * page's display rotation — coordinates are plain PDF points.\n */\n children: (page: PageContextValue) => React.ReactNode;\n /**\n * BOX-SPACE chrome for each visible page (page-number label, selection\n * border, a per-page rotate/delete button). Rendered into the OUTER box\n * (content + reserved `pageFrame`), so it does NOT rotate and the reserved\n * bands are plain regions (`bottom:0; height: page.frame.bottom`). The three\n * coordinate spaces: `children` (page content), `pageChrome` (page box +\n * frame), `overlay` (viewport).\n */\n pageChrome?: (page: PageContextValue) => React.ReactNode;\n /** Viewport-space UI (menus, controls) rendered above the pages. */\n overlay?: React.ReactNode;\n /**\n * Route this Stage's pointer events to the interaction hub (page-resolved via\n * `pageAt`) — AND register this lens's tool-gated pan-scroll handler with it\n * (lens-scoped, so multiple stages on one document never pan each other).\n * Pan is then the `pan` tool's job and dragging in `pointer` mode selects\n * text (incl. across pages).\n *\n * Default TRUE: registering `interactionPlugin()` is the one opt-in — tools\n * just work; without the hub this is inert and the stage falls back to\n * built-in drag-to-pan, so a hub-less setup costs nothing. Set `false` on\n * SECONDARY lenses (a thumbnail rail) that should stay click-to-navigate\n * instead of feeding the document's tools.\n */\n interaction?: boolean;\n /**\n * With {@link interaction}: let drags over page GAPS pan regardless of the\n * active tool (and show a grab cursor there) — the gutter always pans; there\n * is nothing to draw/select outside a page. Default true.\n */\n panFallback?: boolean;\n /**\n * Ambient ZOOM gestures on this stage: ctrl/cmd+wheel and trackpad pinch\n * (Safari gesture events included). Default true. Turn OFF for follower\n * lenses with a fixed magnification — a thumbnail rail should scroll under\n * cmd+wheel, not zoom — so a zoom-wheel falls through to ordinary wheel\n * pan, and pinches are still swallowed (they never page-zoom the browser).\n */\n zoomGestures?: boolean;\n /** The stage lens to drive (default: the main StageToken). */\n token?: StageTokenProp;\n className?: string;\n style?: React.CSSProperties;\n}\n\nexport function Stage({\n children,\n pageChrome,\n overlay,\n interaction = true,\n panFallback = true,\n zoomGestures = true,\n token = StageToken,\n className,\n style,\n}: StageProps) {\n const stage = useCapability(token);\n const ix = useOptionalCapability(InteractionToken);\n const useHub = interaction && !!ix;\n // The hub's resolved cursor (text/grab/…), applied to the viewport when driving.\n const hubCursor = useKernelValue(() => ix?.cursor() ?? 'default');\n const ref = useRef<HTMLDivElement>(null);\n const docId = useDocumentId();\n // visiblePages already folds in the camera (each page carries its device-snapped\n // screenX/screenY + transform), so panning re-emits the list — no separate\n // camera subscription needed for positioning.\n const pages = useSelector(token, (c) => c.visiblePages()); // memoized -> stable ref\n // Reserved chrome bands (screen px), uniform across pages — the frame the\n // outer box reserves and `pageChrome` paints into.\n const frame = useSelector(\n token,\n (c) => c.pageFrame(),\n (a, b) => a.top === b.top && a.right === b.right && a.bottom === b.bottom && a.left === b.left,\n );\n\n // The Stage's ViewProjector: anchored UI (menus, popovers) positions through\n // the CAMERA — pure state, no DOM reads, no portal, and NO subscription:\n // `pages` (visiblePages) is the binding's revision, so a camera change\n // re-renders the pages AND every anchored consumer in the SAME React\n // commit — surface and overlay can never paint a frame apart.\n const projector = useMemo<ViewProjector>(\n () => ({\n space: 'overlay',\n toScreen: (pon, rect) => stage.pageRectToScreen(pon, rect),\n toScreenPoint: (pon, at) => {\n const r = stage.pageRectToScreen(pon, { x: at.x, y: at.y, width: 0, height: 0 });\n return r ? { x: r.x, y: r.y } : null;\n },\n viewEnv: (pon) => {\n const t = stage.pageRect(pon)?.transform;\n return t ? { scale: t.viewScale, rotation: t.rotation, zoom: t.zoom } : null;\n },\n }),\n [stage],\n );\n const projectorBinding = useMemo<ProjectorBinding>(\n () => ({ projector, revision: pages }),\n [projector, pages],\n );\n\n useLayoutEffect(() => {\n const el = ref.current!;\n // The WHOLE browser binding — viewport/DPR reporting, sample normalization,\n // gesture controller — is the shared @embedpdf/web surface, so every\n // framework adapter has one feel. This component keeps only React glue.\n const detachSurface = createStageSurface(el, stage, {\n hub: useHub ? ix : null,\n source: stage.lensId(),\n zoomGestures,\n });\n // Interaction opt-in lives WITH the sample source: the same knob that\n // forwards this lens's samples also registers its pan-scroll handler,\n // lens-scoped — two stages on one document can never pan each other.\n const offScroll =\n useHub && ix\n ? ix.registerHandler(createScrollHandler(stage, ix, { panFallback }), {\n source: stage.lensId(),\n })\n : null;\n\n return () => {\n offScroll?.();\n detachSurface();\n };\n }, [stage, ix, useHub, zoomGestures, panFallback]);\n\n return (\n <div\n ref={ref}\n className={className}\n style={{\n position: 'relative',\n overflow: 'hidden',\n touchAction: 'none',\n ...(useHub ? { cursor: hubCursor } : null),\n ...style,\n }}\n >\n {pages.map((p) => (\n <PageSurface\n key={p.pon} // durable page identity — survives move/delete (matches Angular's `track p.pon`)\n documentId={docId ?? ''}\n page={p}\n frame={frame}\n stage={stage}\n render={children}\n chrome={pageChrome}\n />\n ))}\n {/* Anchored UI mounts in the overlay: absolute coords here are the\n projector's overlay space (the stage container). */}\n <ProjectorProvider value={projectorBinding}>{overlay}</ProjectorProvider>\n </div>\n );\n}\n\n// ── Facade hooks — thin sugar over the capability + generic binding ───────────\nexport function useStage(token: StageTokenProp = StageToken) {\n return useCapability(token);\n}\nexport function useZoom(token: StageTokenProp = StageToken) {\n const s = useCapability(token);\n const zoom = useSelector(token, (c) => c.zoomLevel());\n const mode = useSelector(token, (c) => c.zoomMode());\n return {\n zoom,\n /** Active zoom intent: 'automatic' | 'fit-page' | 'fit-width' | 'fit-all' | 'custom'. */\n mode,\n zoomIn: s.zoomIn,\n zoomOut: s.zoomOut,\n fitWidth: s.fitWidth,\n fitPage: s.fitPage,\n fitAll: s.fitAll,\n automatic: s.automatic,\n zoomTo: s.zoomTo,\n };\n}\nexport function usePages(token: StageTokenProp = StageToken) {\n const s = useCapability(token);\n const currentPage = useSelector(token, (c) => c.currentPage());\n const pageCount = useSelector(token, (c) => c.pageCount());\n return {\n currentPage,\n pageCount,\n goToPage: s.goToPage,\n next: s.next,\n prev: s.prev,\n reveal: s.reveal,\n };\n}\nexport function useLayout(token: StageTokenProp = StageToken) {\n const s = useCapability(token);\n const flow = useSelector(token, (c) => c.flow());\n const layout = useSelector(token, (c) => c.layout());\n const spread = useSelector(token, (c) => c.spread());\n const sizing = useSelector(token, (c) => c.sizing());\n const bounded = useSelector(token, (c) => c.bounded());\n return {\n flow,\n layout,\n spread,\n sizing,\n bounded,\n setFlow: s.setFlow,\n setLayout: s.setLayout,\n setSpread: s.setSpread,\n setSizing: s.setSizing,\n setBounded: s.setBounded,\n };\n}\n\n/** The document's page list (with PDF labels) + the current item's pages — the\n * data for page thumbnails / worksheet-style page tabs. */\nexport function usePageList(token: StageTokenProp = StageToken) {\n const pages = useSelector(\n token,\n (c) => c.pages(),\n (a, b) =>\n a.length === b.length && a.every((p, i) => p.pon === b[i].pon && p.label === b[i].label),\n );\n const current = useSelector(\n token,\n (c) => c.currentItemPages(),\n (a, b) => a.length === b.length && a.every((x, i) => x === b[i]),\n );\n return { pages, currentItemPages: current };\n}\n\n/**\n * All Stage settings + the batch `update`. This is the seam for \"presets are a\n * customer concern\": keep your own `Partial<StageSettings>` objects and apply them\n * with `update(preset)` (one anchor-preserving change).\n */\nexport function useStageSettings(token: StageTokenProp = StageToken) {\n const s = useCapability(token);\n // settingsEqual derives from the plugin's settings registry — a new setting is\n // covered here automatically, without this package spelling out the shape.\n const settings = useSelector(token, (c) => c.settings(), settingsEqual);\n return { settings, update: s.update, reset: s.resetView };\n}\n"],"mappings":";;;;;;;;;;;AAkCA,SAAS,YAAY,EACnB,YACA,MACA,OACA,OACA,QACA,UAWC;CACD,MAAM,OAAA,GAAA,MAAA,OAAA,CAA6B,IAAI;CACvC,MAAM,IAAI,KAAK;CACf,MAAM,WAAW,KAAK;CAItB,MAAM,SAAS,EAAE,YAAY,MAAM,OAAO,MAAM;CAChD,MAAM,SAAS,EAAE,aAAa,MAAM,MAAM,MAAM;CAGhD,MAAM,OAAO,KAAK,UAAU,MAAM;CAClC,MAAM,MAAM,KAAK,UAAU,MAAM;CAIjC,MAAM,cAAc,MAAM,QAAQ,EAAE,YAAY,EAAE,gBAAgB;CAClE,MAAM,aAAa,MAAM,OAAO,EAAE,aAAa,EAAE,iBAAiB;CAOlE,MAAM,OAAA,GAAA,MAAA,QAAA,OAEFA,gBAAAA,gBACE,YAGA,MAAM,OAAO,GACb,KAAK,KACL,KAAK,WACL,OACA,SACM,IAAI,QAAS,sBAAsB,SACnC;EACJ,MAAM,OAAO,MAAM,aAAa,CAAC,CAAC,MAAM,MAAM,EAAE,QAAQ,KAAK,GAAG;EAChE,OAAO,OACH;GAAE,oBAAoB,KAAK,UAAU;GAAa,aAAa,KAAK;EAAY,IAChF;GACE,oBAAoB,EAAE;GACtB,aAAa;IAAE,GAAG;IAAG,GAAG;IAAG,OAAO;IAAG,QAAQ;GAAE;EACjD;CACN,CACF,GACF;EAAC;EAAY,KAAK;EAAK,KAAK;EAAW;EAAO;EAAG;CAAK,CACxD;CACA,OACE,i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EAAE,OAAO,CAM3C;EACL,QANaA,gBAAAA,YAAY,QAAQ,MAAM,EAAE,OAAO,CAM3C;EACL,SANcA,gBAAAA,YAAY,QAAQ,MAAM,EAAE,QAAQ,CAM5C;EACN,SAAS,EAAE;EACX,WAAW,EAAE;EACb,WAAW,EAAE;EACb,WAAW,EAAE;EACb,YAAY,EAAE;CAChB;AACF;;;AAIA,SAAgB,YAAY,QAAwBN,uBAAAA,YAAY;CAY9D,OAAO;EAAE,OAXKM,gBAAAA,YACZ,QACC,MAAM,EAAE,MAAM,IACd,GAAG,MACF,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,GAAG,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC,KAAK,CAO9E;EAAG,kBALAA,gBAAAA,YACd,QACC,MAAM,EAAE,iBAAiB,IACzB,GAAG,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,GAAG,MAAM,MAAM,EAAE,EAAE,CAEzB;CAAE;AAC5C;;;;;;AAOA,SAAgB,iBAAiB,QAAwBN,uBAAAA,YAAY;CACnE,MAAM,IAAIC,gBAAAA,cAAc,KAAK;CAI7B,OAAO;EAAE,UADQK,gBAAAA,YAAY,QAAQ,MAAM,EAAE,SAAS,GAAGE,uBAAAA,aACzC;EAAG,QAAQ,EAAE;EAAQ,OAAO,EAAE;CAAU;AAC1D"}
|
package/dist/stage.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stage.js","names":[],"sources":["../src/stage.tsx"],"sourcesContent":["/**\n * Stage / RenderLayer + facade hooks.\n *\n * <Stage> virtualizes and positions page surfaces by the camera, and hands each\n * one to YOUR render prop — you bring the layers. (The standalone, Stage-free\n * single-page surface lives in `./page-view` so it never pulls the stage plugin.)\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-stage';\nimport * as React from 'react';\nimport { useLayoutEffect, useMemo, useRef } from 'react';\nimport { StageToken, createScrollHandler, settingsEqual } from '@embedpdf/plugin-stage';\nimport type { StageCapability, VisiblePage } from '@embedpdf/plugin-stage';\nimport type { CapabilityToken } from '@embedpdf/core';\n\n/** Which stage lens to bind to. Defaults to the main StageToken — pass a custom\n * token to drive an additional lens (e.g. a wrapped thumbnail sidebar). */\nexport type StageTokenProp = CapabilityToken<StageCapability>;\nimport type { PageFrame } from '@embedpdf/core-geometry';\nimport { InteractionToken } from '@embedpdf/plugin-interaction/contract';\nimport { createStageSurface } from '@embedpdf/web';\nimport { ProjectorProvider, type ProjectorBinding, type ViewProjector } from './anchored';\nimport {\n makePageContext,\n PageProvider,\n useCapability,\n useDocumentId,\n useKernelValue,\n useOptionalCapability,\n useSelector,\n} from './runtime';\nimport type { PageContextValue } from './runtime';\n\nfunction PageSurface({\n documentId,\n page,\n frame,\n stage,\n render,\n chrome,\n}: {\n documentId: string;\n page: VisiblePage;\n /** Reserved chrome bands around the page (screen px); the layout reserved the\n * matching space, so the outer box tiles into it. */\n frame: PageFrame;\n /** The stage capability — the demand getter reads visibility LIVE off it. */\n stage: StageCapability;\n render: (page: PageContextValue) => React.ReactNode;\n chrome?: (page: PageContextValue) => React.ReactNode;\n}) {\n const ref = useRef<HTMLDivElement>(null);\n const t = page.transform;\n const rotation = page.rotation;\n // All geometry comes from the transform: the DISPLAY footprint (viewWidth/Height,\n // already w↔h-swapped + device-snapped) and the UN-rotated content box\n // (contentWidth/Height). The shell never re-derives `* zoom` / `* dpr` / snapping.\n const outerW = t.viewWidth + frame.left + frame.right;\n const outerH = t.viewHeight + frame.top + frame.bottom;\n // page.screenX/screenY are the device-snapped footprint top-left; the outer box\n // sits one frame further out so the content keeps its scene position.\n const left = page.screenX - frame.left;\n const top = page.screenY - frame.top;\n // Center the (possibly rotated) content box on the display box and rotate about\n // its center — NO translate(), so rotation 0 carries no transform and pixel-snaps\n // like the axis-aligned shadow behind it (no hairline seam).\n const contentLeft = frame.left + (t.viewWidth - t.contentWidth) / 2;\n const contentTop = frame.top + (t.viewHeight - t.contentHeight) / 2;\n // The page-view DEMAND is a PULL: the getter closes over\n // stable references (capability + pon) and reads the stage's live state at\n // call time — visibility is the STAGE's data (`VisiblePage.visibleRect`),\n // not something an adapter re-derives or caches. Absent from the visible\n // set = zero rect (\"want nothing\"), distinct from PageView's undefined\n // getter (\"whole page\").\n const ctx = useMemo(\n () =>\n makePageContext(\n documentId,\n // the hosting lens — per-view raster planning keys tile state by it,\n // so a thumbnail rail and the main view never fight over one plan\n stage.lensId(),\n page.pon,\n page.pageIndex,\n frame,\n t,\n () => ref.current!.getBoundingClientRect(),\n () => {\n const live = stage.visiblePages().find((p) => p.pon === page.pon);\n return live\n ? { desiredDeviceWidth: live.transform.deviceWidth, visibleRect: live.visibleRect }\n : {\n desiredDeviceWidth: t.deviceWidth,\n visibleRect: { x: 0, y: 0, width: 0, height: 0 },\n };\n },\n ),\n [documentId, page.pon, page.pageIndex, frame, t, stage],\n );\n return (\n <div style={{ position: 'absolute', left, top, width: outerW, height: outerH }}>\n <PageProvider value={ctx}>\n {/* drop shadow ONLY — axis-aligned at the content box (inset by the frame),\n transparent fill so it can never peek out behind the bitmap, and it\n stays put under rotation. */}\n <div\n style={{\n position: 'absolute',\n left: frame.left,\n top: frame.top,\n width: t.viewWidth,\n height: t.viewHeight,\n // themeable: override via the CSS variable (app stylesheet), no props\n boxShadow: 'var(--epdf-page-shadow, 0 6px 18px rgba(0,0,0,.18))',\n }}\n />\n {/* the page: white backing + bitmap as ONE rasterized box, so there is no\n seam between them and nothing white larger than the bitmap to leak.\n The ONLY thing rotation turns; markers/annotations ride it in content\n coordinates. Rotation 0 carries no transform → pixel-snaps cleanly. */}\n <div\n ref={ref}\n style={{\n position: 'absolute',\n left: contentLeft,\n top: contentTop,\n width: t.contentWidth,\n height: t.contentHeight,\n background: '#fff',\n transform: rotation ? `rotate(${rotation}deg)` : undefined,\n // We render our own selection highlights — suppress native text/image\n // selection (and the double-click image grab) on the whole page subtree.\n userSelect: 'none',\n WebkitUserSelect: 'none',\n }}\n >\n {render(ctx)}\n </div>\n {/* box-space chrome — labels, selection border, per-page buttons — fills\n the outer box, NEVER rotates. Bands are plain regions: a label is\n `bottom:0; height: frame.bottom`, a button row `top:0; height: frame.top`. */}\n {chrome?.(ctx)}\n </PageProvider>\n </div>\n );\n}\n\nexport interface StageProps {\n /**\n * PAGE-SPACE content for each visible page (RenderLayer, annotations,\n * markers). Rendered inside the page's content frame, so it ROTATES with the\n * page's display rotation — coordinates are plain PDF points.\n */\n children: (page: PageContextValue) => React.ReactNode;\n /**\n * BOX-SPACE chrome for each visible page (page-number label, selection\n * border, a per-page rotate/delete button). Rendered into the OUTER box\n * (content + reserved `pageFrame`), so it does NOT rotate and the reserved\n * bands are plain regions (`bottom:0; height: page.frame.bottom`). The three\n * coordinate spaces: `children` (page content), `pageChrome` (page box +\n * frame), `overlay` (viewport).\n */\n pageChrome?: (page: PageContextValue) => React.ReactNode;\n /** Viewport-space UI (menus, controls) rendered above the pages. */\n overlay?: React.ReactNode;\n /**\n * Route this Stage's pointer events to the interaction hub (page-resolved via\n * `pageAt`) — AND register this lens's tool-gated pan-scroll handler with it\n * (lens-scoped, so multiple stages on one document never pan each other).\n * Pan is then the `pan` tool's job and dragging in `pointer` mode selects\n * text (incl. across pages).\n *\n * Default TRUE: registering `interactionPlugin()` is the one opt-in — tools\n * just work; without the hub this is inert and the stage falls back to\n * built-in drag-to-pan, so a hub-less setup costs nothing. Set `false` on\n * SECONDARY lenses (a thumbnail rail) that should stay click-to-navigate\n * instead of feeding the document's tools.\n */\n interaction?: boolean;\n /**\n * With {@link interaction}: let drags over page GAPS pan regardless of the\n * active tool (and show a grab cursor there) — the gutter always pans; there\n * is nothing to draw/select outside a page. Default true.\n */\n panFallback?: boolean;\n /**\n * Ambient ZOOM gestures on this stage: ctrl/cmd+wheel and trackpad pinch\n * (Safari gesture events included). Default true. Turn OFF for follower\n * lenses with a fixed magnification — a thumbnail rail should scroll under\n * cmd+wheel, not zoom — so a zoom-wheel falls through to ordinary wheel\n * pan, and pinches are still swallowed (they never page-zoom the browser).\n */\n zoomGestures?: boolean;\n /** The stage lens to drive (default: the main StageToken). */\n token?: StageTokenProp;\n className?: string;\n style?: React.CSSProperties;\n}\n\nexport function Stage({\n children,\n pageChrome,\n overlay,\n interaction = true,\n panFallback = true,\n zoomGestures = true,\n token = StageToken,\n className,\n style,\n}: StageProps) {\n const stage = useCapability(token);\n const ix = useOptionalCapability(InteractionToken);\n const useHub = interaction && !!ix;\n // The hub's resolved cursor (text/grab/…), applied to the viewport when driving.\n const hubCursor = useKernelValue(() => ix?.cursor() ?? 'default');\n const ref = useRef<HTMLDivElement>(null);\n const docId = useDocumentId();\n // visiblePages already folds in the camera (each page carries its device-snapped\n // screenX/screenY + transform), so panning re-emits the list — no separate\n // camera subscription needed for positioning.\n const pages = useSelector(token, (c) => c.visiblePages()); // memoized -> stable ref\n // Reserved chrome bands (screen px), uniform across pages — the frame the\n // outer box reserves and `pageChrome` paints into.\n const frame = useSelector(\n token,\n (c) => c.pageFrame(),\n (a, b) => a.top === b.top && a.right === b.right && a.bottom === b.bottom && a.left === b.left,\n );\n\n // The Stage's ViewProjector: anchored UI (menus, popovers) positions through\n // the CAMERA — pure state, no DOM reads, no portal, and NO subscription:\n // `pages` (visiblePages) is the binding's revision, so a camera change\n // re-renders the pages AND every anchored consumer in the SAME React\n // commit — surface and overlay can never paint a frame apart.\n const projector = useMemo<ViewProjector>(\n () => ({\n space: 'overlay',\n toScreen: (pon, rect) => stage.pageRectToScreen(pon, rect),\n toScreenPoint: (pon, at) => {\n const r = stage.pageRectToScreen(pon, { x: at.x, y: at.y, width: 0, height: 0 });\n return r ? { x: r.x, y: r.y } : null;\n },\n viewEnv: (pon) => {\n const t = stage.pageRect(pon)?.transform;\n return t ? { scale: t.viewScale, rotation: t.rotation, zoom: t.zoom } : null;\n },\n }),\n [stage],\n );\n const projectorBinding = useMemo<ProjectorBinding>(\n () => ({ projector, revision: pages }),\n [projector, pages],\n );\n\n useLayoutEffect(() => {\n const el = ref.current!;\n // The WHOLE browser binding — viewport/DPR reporting, sample normalization,\n // gesture controller — is the shared @embedpdf/web surface, so every\n // framework adapter has one feel. This component keeps only React glue.\n const detachSurface = createStageSurface(el, stage, {\n hub: useHub ? ix : null,\n source: stage.lensId(),\n zoomGestures,\n });\n // Interaction opt-in lives WITH the sample source: the same knob that\n // forwards this lens's samples also registers its pan-scroll handler,\n // lens-scoped — two stages on one document can never pan each other.\n const offScroll =\n useHub && ix\n ? ix.registerHandler(createScrollHandler(stage, ix, { panFallback }), {\n source: stage.lensId(),\n })\n : null;\n\n return () => {\n offScroll?.();\n detachSurface();\n };\n }, [stage, ix, useHub, zoomGestures, panFallback]);\n\n return (\n <div\n ref={ref}\n className={className}\n style={{\n position: 'relative',\n overflow: 'hidden',\n touchAction: 'none',\n ...(useHub ? { cursor: hubCursor } : null),\n ...style,\n }}\n >\n {pages.map((p) => (\n <PageSurface\n key={p.pon} // durable page identity — survives move/delete (matches Angular's `track p.pon`)\n documentId={docId ?? ''}\n page={p}\n frame={frame}\n stage={stage}\n render={children}\n chrome={pageChrome}\n />\n ))}\n {/* Anchored UI mounts in the overlay: absolute coords here are the\n projector's overlay space (the stage container). */}\n <ProjectorProvider value={projectorBinding}>{overlay}</ProjectorProvider>\n </div>\n );\n}\n\n// ── Facade hooks — thin sugar over the capability + generic binding ───────────\nexport function useStage(token: StageTokenProp = StageToken) {\n return useCapability(token);\n}\nexport function useZoom(token: StageTokenProp = StageToken) {\n const s = useCapability(token);\n const zoom = useSelector(token, (c) => c.zoomLevel());\n const mode = useSelector(token, (c) => c.zoomMode());\n return {\n zoom,\n /** Active zoom intent: 'automatic' | 'fit-page' | 'fit-width' | 'fit-all' | 'custom'. */\n mode,\n zoomIn: s.zoomIn,\n zoomOut: s.zoomOut,\n fitWidth: s.fitWidth,\n fitPage: s.fitPage,\n fitAll: s.fitAll,\n automatic: s.automatic,\n zoomTo: s.zoomTo,\n };\n}\nexport function usePages(token: StageTokenProp = StageToken) {\n const s = useCapability(token);\n const currentPage = useSelector(token, (c) => c.currentPage());\n const pageCount = useSelector(token, (c) => c.pageCount());\n return {\n currentPage,\n pageCount,\n goToPage: s.goToPage,\n next: s.next,\n prev: s.prev,\n reveal: s.reveal,\n };\n}\nexport function useLayout(token: StageTokenProp = StageToken) {\n const s = useCapability(token);\n const flow = useSelector(token, (c) => c.flow());\n const layout = useSelector(token, (c) => c.layout());\n const spread = useSelector(token, (c) => c.spread());\n const sizing = useSelector(token, (c) => c.sizing());\n const bounded = useSelector(token, (c) => c.bounded());\n return {\n flow,\n layout,\n spread,\n sizing,\n bounded,\n setFlow: s.setFlow,\n setLayout: s.setLayout,\n setSpread: s.setSpread,\n setSizing: s.setSizing,\n setBounded: s.setBounded,\n };\n}\n\n/** The document's page list (with PDF labels) + the current item's pages — the\n * data for page thumbnails / worksheet-style page tabs. */\nexport function usePageList(token: StageTokenProp = StageToken) {\n const pages = useSelector(\n token,\n (c) => c.pages(),\n (a, b) =>\n a.length === b.length && a.every((p, i) => p.pon === b[i].pon && p.label === b[i].label),\n );\n const current = useSelector(\n token,\n (c) => c.currentItemPages(),\n (a, b) => a.length === b.length && a.every((x, i) => x === b[i]),\n );\n return { pages, currentItemPages: current };\n}\n\n/**\n * All Stage settings + the batch `update`. This is the seam for \"presets are a\n * customer concern\": keep your own `Partial<StageSettings>` objects and apply them\n * with `update(preset)` (one anchor-preserving change).\n */\nexport function useStageSettings(token: StageTokenProp = StageToken) {\n const s = useCapability(token);\n // settingsEqual derives from the plugin's settings registry — a new setting is\n // covered here automatically, without this package spelling out the shape.\n const settings = useSelector(token, (c) => c.settings(), settingsEqual);\n return { settings, update: s.update, reset: s.resetView };\n}\n"],"mappings":";;;;;;;;;;AAkCA,SAAS,YAAY,EACnB,YACA,MACA,OACA,OACA,QACA,UAWC;CACD,MAAM,MAAM,OAAuB,IAAI;CACvC,MAAM,IAAI,KAAK;CACf,MAAM,WAAW,KAAK;CAItB,MA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A,SAAgB,UAAU,QAAwB,YAAY;CAC5D,MAAM,IAAI,cAAc,KAAK;CAM7B,OAAO;EACL,MANW,YAAY,QAAQ,MAAM,EAAE,KAAK,CAMzC;EACH,QANa,YAAY,QAAQ,MAAM,EAAE,OAAO,CAM3C;EACL,QANa,YAAY,QAAQ,MAAM,EAAE,OAAO,CAM3C;EACL,QANa,YAAY,QAAQ,MAAM,EAAE,OAAO,CAM3C;EACL,SANc,YAAY,QAAQ,MAAM,EAAE,QAAQ,CAM5C;EACN,SAAS,EAAE;EACX,WAAW,EAAE;EACb,WAAW,EAAE;EACb,WAAW,EAAE;EACb,YAAY,EAAE;CAChB;AACF;;;AAIA,SAAgB,YAAY,QAAwB,YAAY;CAY9D,OAAO;EAAE,OAXK,YACZ,QACC,MAAM,EAAE,MAAM,IACd,GAAG,MACF,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,GAAG,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC,KAAK,CAO9E;EAAG,kBALA,YACd,QACC,MAAM,EAAE,iBAAiB,IACzB,GAAG,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,GAAG,MAAM,MAAM,EAAE,EAAE,CAEzB;CAAE;AAC5C;;;;;;AAOA,SAAgB,iBAAiB,QAAwB,YAAY;CACnE,MAAM,IAAI,cAAc,KAAK;CAI7B,OAAO;EAAE,UADQ,YAAY,QAAQ,MAAM,EAAE,SAAS,GAAG,aACzC;EAAG,QAAQ,EAAE;EAAQ,OAAO,EAAE;CAAU;AAC1D"}
|
package/dist/views.cjs
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("./rolldown-runtime-DDXJien1.cjs");
|
|
3
|
-
const require_runtime = require("./runtime.cjs");
|
|
4
|
-
let _embedpdf_plugin_view_manager = require("@embedpdf/plugin-view-manager");
|
|
5
|
-
//#region src/views.ts
|
|
6
|
-
const sameView = (a, b) => a.id === b.id && a.activeDocumentId === b.activeDocumentId && a.documentIds.length === b.documentIds.length && a.documentIds.every((d, i) => d === b.documentIds[i]);
|
|
7
|
-
function useViews() {
|
|
8
|
-
const vm = require_runtime.useKernel().capability(_embedpdf_plugin_view_manager.ViewManagerToken);
|
|
9
|
-
return {
|
|
10
|
-
views: require_runtime.useKernelValue(() => vm.list(), (a, b) => a.length === b.length && a.every((v, i) => sameView(v, b[i]))),
|
|
11
|
-
focusedViewId: require_runtime.useKernelValue(() => vm.focusedViewId()),
|
|
12
|
-
documentView: vm.documentView,
|
|
13
|
-
createView: vm.createView,
|
|
14
|
-
removeView: vm.removeView,
|
|
15
|
-
moveView: vm.moveView,
|
|
16
|
-
setFocused: vm.setFocused,
|
|
17
|
-
setActiveDocument: vm.setActiveDocument,
|
|
18
|
-
addDocument: vm.addDocument,
|
|
19
|
-
removeDocument: vm.removeDocument,
|
|
20
|
-
moveDocumentWithin: vm.moveDocumentWithin,
|
|
21
|
-
moveDocumentBetween: vm.moveDocumentBetween
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
exports.useViews = useViews;
|
|
26
|
-
Object.keys(_embedpdf_plugin_view_manager).forEach(function(k) {
|
|
27
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function() {
|
|
30
|
-
return _embedpdf_plugin_view_manager[k];
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
//# sourceMappingURL=views.cjs.map
|
package/dist/views.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"views.cjs","names":["useKernel","ViewManagerToken","useKernelValue"],"sources":["../src/views.ts"],"sourcesContent":["/**\n * useViews — the React view of @embedpdf/plugin-view-manager.\n *\n * Reactive pane list + intents. The adapter stays headless: it gives you the\n * views; YOU lay them out (split, grid, stacked), render each pane's tab strip\n * over `view.documentIds`, and wrap the body in a <DocumentScope id={activeId}>\n * so its Stage binds to that pane's active document.\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-view-manager';\nimport { ViewManagerToken } from '@embedpdf/plugin-view-manager';\nimport type { ViewInfo } from '@embedpdf/plugin-view-manager';\nimport { useKernel, useKernelValue } from './runtime';\n\nexport interface UseViews {\n views: ViewInfo[];\n focusedViewId: string | null;\n documentView: (documentId: string) => string | null;\n createView: () => string;\n removeView: (id: string) => void;\n moveView: (id: string, toIndex: number) => void;\n setFocused: (id: string) => void;\n setActiveDocument: (viewId: string, documentId: string | null) => void;\n addDocument: (viewId: string, documentId: string, index?: number) => void;\n removeDocument: (viewId: string, documentId: string) => void;\n moveDocumentWithin: (viewId: string, documentId: string, toIndex: number) => void;\n moveDocumentBetween: (\n fromViewId: string,\n toViewId: string,\n documentId: string,\n toIndex?: number,\n ) => void;\n}\n\nconst sameView = (a: ViewInfo, b: ViewInfo): boolean =>\n a.id === b.id &&\n a.activeDocumentId === b.activeDocumentId &&\n a.documentIds.length === b.documentIds.length &&\n a.documentIds.every((d, i) => d === b.documentIds[i]);\n\nexport function useViews(): UseViews {\n const kernel = useKernel();\n const vm = kernel.capability(ViewManagerToken);\n const views = useKernelValue(\n () => vm.list(),\n (a, b) => a.length === b.length && a.every((v, i) => sameView(v, b[i])),\n );\n const focusedViewId = useKernelValue(() => vm.focusedViewId());\n return {\n views,\n focusedViewId,\n documentView: vm.documentView,\n createView: vm.createView,\n removeView: vm.removeView,\n moveView: vm.moveView,\n setFocused: vm.setFocused,\n setActiveDocument: vm.setActiveDocument,\n addDocument: vm.addDocument,\n removeDocument: vm.removeDocument,\n moveDocumentWithin: vm.moveDocumentWithin,\n moveDocumentBetween: vm.moveDocumentBetween,\n };\n}\n"],"mappings":";;;;;AAmCA,MAAM,YAAY,GAAa,MAC7B,EAAE,OAAO,EAAE,MACX,EAAE,qBAAqB,EAAE,oBACzB,EAAE,YAAY,WAAW,EAAE,YAAY,UACvC,EAAE,YAAY,OAAO,GAAG,MAAM,MAAM,EAAE,YAAY,EAAE;AAEtD,SAAgB,WAAqB;CAEnC,MAAM,KADSA,gBAAAA,UACC,CAAC,CAAC,WAAWC,8BAAAA,gBAAgB;CAM7C,OAAO;EACL,OANYC,gBAAAA,qBACN,GAAG,KAAK,IACb,GAAG,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,GAAG,MAAM,SAAS,GAAG,EAAE,EAAE,CAAC,CAIlE;EACJ,eAHoBA,gBAAAA,qBAAqB,GAAG,cAAc,CAG9C;EACZ,cAAc,GAAG;EACjB,YAAY,GAAG;EACf,YAAY,GAAG;EACf,UAAU,GAAG;EACb,YAAY,GAAG;EACf,mBAAmB,GAAG;EACtB,aAAa,GAAG;EAChB,gBAAgB,GAAG;EACnB,oBAAoB,GAAG;EACvB,qBAAqB,GAAG;CAC1B;AACF"}
|
package/dist/views.d.cts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ViewInfo } from "@embedpdf/plugin-view-manager";
|
|
2
|
-
export * from "@embedpdf/plugin-view-manager";
|
|
3
|
-
//#region src/views.d.ts
|
|
4
|
-
interface UseViews {
|
|
5
|
-
views: ViewInfo[];
|
|
6
|
-
focusedViewId: string | null;
|
|
7
|
-
documentView: (documentId: string) => string | null;
|
|
8
|
-
createView: () => string;
|
|
9
|
-
removeView: (id: string) => void;
|
|
10
|
-
moveView: (id: string, toIndex: number) => void;
|
|
11
|
-
setFocused: (id: string) => void;
|
|
12
|
-
setActiveDocument: (viewId: string, documentId: string | null) => void;
|
|
13
|
-
addDocument: (viewId: string, documentId: string, index?: number) => void;
|
|
14
|
-
removeDocument: (viewId: string, documentId: string) => void;
|
|
15
|
-
moveDocumentWithin: (viewId: string, documentId: string, toIndex: number) => void;
|
|
16
|
-
moveDocumentBetween: (fromViewId: string, toViewId: string, documentId: string, toIndex?: number) => void;
|
|
17
|
-
}
|
|
18
|
-
declare function useViews(): UseViews;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { UseViews, useViews };
|
|
21
|
-
//# sourceMappingURL=views.d.cts.map
|
package/dist/views.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ViewInfo } from "@embedpdf/plugin-view-manager";
|
|
2
|
-
export * from "@embedpdf/plugin-view-manager";
|
|
3
|
-
//#region src/views.d.ts
|
|
4
|
-
interface UseViews {
|
|
5
|
-
views: ViewInfo[];
|
|
6
|
-
focusedViewId: string | null;
|
|
7
|
-
documentView: (documentId: string) => string | null;
|
|
8
|
-
createView: () => string;
|
|
9
|
-
removeView: (id: string) => void;
|
|
10
|
-
moveView: (id: string, toIndex: number) => void;
|
|
11
|
-
setFocused: (id: string) => void;
|
|
12
|
-
setActiveDocument: (viewId: string, documentId: string | null) => void;
|
|
13
|
-
addDocument: (viewId: string, documentId: string, index?: number) => void;
|
|
14
|
-
removeDocument: (viewId: string, documentId: string) => void;
|
|
15
|
-
moveDocumentWithin: (viewId: string, documentId: string, toIndex: number) => void;
|
|
16
|
-
moveDocumentBetween: (fromViewId: string, toViewId: string, documentId: string, toIndex?: number) => void;
|
|
17
|
-
}
|
|
18
|
-
declare function useViews(): UseViews;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { UseViews, useViews };
|
|
21
|
-
//# sourceMappingURL=views.d.ts.map
|
package/dist/views.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import "./rolldown-runtime-BBjsoOtd.js";
|
|
2
|
-
import { useKernel, useKernelValue } from "./runtime.js";
|
|
3
|
-
import { ViewManagerToken } from "@embedpdf/plugin-view-manager";
|
|
4
|
-
export * from "@embedpdf/plugin-view-manager";
|
|
5
|
-
//#region src/views.ts
|
|
6
|
-
const sameView = (a, b) => a.id === b.id && a.activeDocumentId === b.activeDocumentId && a.documentIds.length === b.documentIds.length && a.documentIds.every((d, i) => d === b.documentIds[i]);
|
|
7
|
-
function useViews() {
|
|
8
|
-
const vm = useKernel().capability(ViewManagerToken);
|
|
9
|
-
return {
|
|
10
|
-
views: useKernelValue(() => vm.list(), (a, b) => a.length === b.length && a.every((v, i) => sameView(v, b[i]))),
|
|
11
|
-
focusedViewId: useKernelValue(() => vm.focusedViewId()),
|
|
12
|
-
documentView: vm.documentView,
|
|
13
|
-
createView: vm.createView,
|
|
14
|
-
removeView: vm.removeView,
|
|
15
|
-
moveView: vm.moveView,
|
|
16
|
-
setFocused: vm.setFocused,
|
|
17
|
-
setActiveDocument: vm.setActiveDocument,
|
|
18
|
-
addDocument: vm.addDocument,
|
|
19
|
-
removeDocument: vm.removeDocument,
|
|
20
|
-
moveDocumentWithin: vm.moveDocumentWithin,
|
|
21
|
-
moveDocumentBetween: vm.moveDocumentBetween
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
export { useViews };
|
|
26
|
-
|
|
27
|
-
//# sourceMappingURL=views.js.map
|
package/dist/views.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"views.js","names":[],"sources":["../src/views.ts"],"sourcesContent":["/**\n * useViews — the React view of @embedpdf/plugin-view-manager.\n *\n * Reactive pane list + intents. The adapter stays headless: it gives you the\n * views; YOU lay them out (split, grid, stacked), render each pane's tab strip\n * over `view.documentIds`, and wrap the body in a <DocumentScope id={activeId}>\n * so its Stage binds to that pane's active document.\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-view-manager';\nimport { ViewManagerToken } from '@embedpdf/plugin-view-manager';\nimport type { ViewInfo } from '@embedpdf/plugin-view-manager';\nimport { useKernel, useKernelValue } from './runtime';\n\nexport interface UseViews {\n views: ViewInfo[];\n focusedViewId: string | null;\n documentView: (documentId: string) => string | null;\n createView: () => string;\n removeView: (id: string) => void;\n moveView: (id: string, toIndex: number) => void;\n setFocused: (id: string) => void;\n setActiveDocument: (viewId: string, documentId: string | null) => void;\n addDocument: (viewId: string, documentId: string, index?: number) => void;\n removeDocument: (viewId: string, documentId: string) => void;\n moveDocumentWithin: (viewId: string, documentId: string, toIndex: number) => void;\n moveDocumentBetween: (\n fromViewId: string,\n toViewId: string,\n documentId: string,\n toIndex?: number,\n ) => void;\n}\n\nconst sameView = (a: ViewInfo, b: ViewInfo): boolean =>\n a.id === b.id &&\n a.activeDocumentId === b.activeDocumentId &&\n a.documentIds.length === b.documentIds.length &&\n a.documentIds.every((d, i) => d === b.documentIds[i]);\n\nexport function useViews(): UseViews {\n const kernel = useKernel();\n const vm = kernel.capability(ViewManagerToken);\n const views = useKernelValue(\n () => vm.list(),\n (a, b) => a.length === b.length && a.every((v, i) => sameView(v, b[i])),\n );\n const focusedViewId = useKernelValue(() => vm.focusedViewId());\n return {\n views,\n focusedViewId,\n documentView: vm.documentView,\n createView: vm.createView,\n removeView: vm.removeView,\n moveView: vm.moveView,\n setFocused: vm.setFocused,\n setActiveDocument: vm.setActiveDocument,\n addDocument: vm.addDocument,\n removeDocument: vm.removeDocument,\n moveDocumentWithin: vm.moveDocumentWithin,\n moveDocumentBetween: vm.moveDocumentBetween,\n };\n}\n"],"mappings":";;;;;AAmCA,MAAM,YAAY,GAAa,MAC7B,EAAE,OAAO,EAAE,MACX,EAAE,qBAAqB,EAAE,oBACzB,EAAE,YAAY,WAAW,EAAE,YAAY,UACvC,EAAE,YAAY,OAAO,GAAG,MAAM,MAAM,EAAE,YAAY,EAAE;AAEtD,SAAgB,WAAqB;CAEnC,MAAM,KADS,UACC,CAAC,CAAC,WAAW,gBAAgB;CAM7C,OAAO;EACL,OANY,qBACN,GAAG,KAAK,IACb,GAAG,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,GAAG,MAAM,SAAS,GAAG,EAAE,EAAE,CAAC,CAIlE;EACJ,eAHoB,qBAAqB,GAAG,cAAc,CAG9C;EACZ,cAAc,GAAG;EACjB,YAAY,GAAG;EACf,YAAY,GAAG;EACf,UAAU,GAAG;EACb,YAAY,GAAG;EACf,mBAAmB,GAAG;EACtB,aAAa,GAAG;EAChB,gBAAgB,GAAG;EACnB,oBAAoB,GAAG;EACvB,qBAAqB,GAAG;CAC1B;AACF"}
|