@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/page-view.cjs
CHANGED
|
@@ -1,125 +1,132 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_rolldown_runtime = require("./rolldown-runtime-DDXJien1.cjs");
|
|
3
|
-
const require_runtime = require("./runtime.cjs");
|
|
3
|
+
const require_runtime = require("./runtime-BfnpyfY0.cjs");
|
|
4
4
|
const require_anchored = require("./anchored.cjs");
|
|
5
|
+
const require_interaction = require("./interaction.cjs");
|
|
5
6
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
+
let _embedpdf_core = require("@embedpdf/core");
|
|
8
|
+
let _embedpdf_web = require("@embedpdf/web");
|
|
6
9
|
let react = require("react");
|
|
7
10
|
react = require_rolldown_runtime.__toESM(react, 1);
|
|
8
|
-
let
|
|
11
|
+
let _embedpdf_plugin_interaction_contract_host = require("@embedpdf/plugin-interaction/contract/host");
|
|
9
12
|
let _embedpdf_core_geometry = require("@embedpdf/core-geometry");
|
|
10
13
|
//#region src/page-view.tsx
|
|
11
14
|
/**
|
|
12
|
-
* <PageView> — a single page surface with
|
|
15
|
+
* <PageView> — a single page surface with no Stage.
|
|
13
16
|
*
|
|
14
17
|
* Same layers + rotation + chrome frame as a `<Stage>` page, but no
|
|
15
|
-
* camera/scroll/zoom and, crucially,
|
|
18
|
+
* camera/scroll/zoom and, crucially, no dependency on `@embedpdf/plugin-stage`.
|
|
16
19
|
* It builds its own `PageTransform` from a target content width and shares the
|
|
17
20
|
* exact `PageContext` seam, so every layer (RenderLayer, AnnotationLayer, …)
|
|
18
21
|
* works here identically — and it provides the measured `ViewProjector`, so
|
|
19
22
|
* anchored UI (`<AnnotationMenu>`, `<SelectionMenu>`) works here too, portalled
|
|
20
|
-
* and clipping-immune.
|
|
23
|
+
* and clipping-immune. With the interaction plugin registered it is also the
|
|
24
|
+
* page's pointer surface, so tools (text selection, annotation editing) work in
|
|
25
|
+
* it as they do on a Stage page.
|
|
21
26
|
*/
|
|
22
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* The page's pointer surface, when the interaction plugin is registered. It sits
|
|
29
|
+
* below the layers, like the Stage's own listener: a press on a layer that lets
|
|
30
|
+
* the pointer through (the picture, the selection highlight) reaches the tools,
|
|
31
|
+
* and a control that takes its own presses (a link, a form field) keeps them.
|
|
32
|
+
*/
|
|
33
|
+
function PointerSurface() {
|
|
34
|
+
return require_runtime.useOptionalCapability(_embedpdf_plugin_interaction_contract_host.InteractionToken) ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_interaction.PagePointerSource, {}) : null;
|
|
35
|
+
}
|
|
36
|
+
/** A single page surface with no Stage — same layers + rotation + chrome frame,
|
|
23
37
|
* no camera/scroll/zoom. */
|
|
24
|
-
function PageView({ page, documentId, width = 240, pageFrame
|
|
25
|
-
const
|
|
26
|
-
const
|
|
38
|
+
function PageView({ page: wanted, documentId, fallback = null, width = 240, pageFrame: framePatch, children, pageChrome, className, style }) {
|
|
39
|
+
const wantedRef = typeof wanted === "number" ? null : wanted;
|
|
40
|
+
const wantedIndex = typeof wanted === "number" ? wanted : null;
|
|
41
|
+
const { top = 0, right = 0, bottom = 0, left = 0 } = framePatch ?? _embedpdf_core_geometry.NO_FRAME;
|
|
42
|
+
const pageFrame = (0, react.useMemo)(() => ({
|
|
43
|
+
top,
|
|
44
|
+
right,
|
|
45
|
+
bottom,
|
|
46
|
+
left
|
|
47
|
+
}), [
|
|
48
|
+
top,
|
|
49
|
+
right,
|
|
50
|
+
bottom,
|
|
51
|
+
left
|
|
52
|
+
]);
|
|
53
|
+
const inScope = require_runtime.useDocumentId();
|
|
27
54
|
const ref = (0, react.useRef)(null);
|
|
28
|
-
const docId = documentId ??
|
|
29
|
-
const
|
|
30
|
-
const base =
|
|
31
|
-
|
|
32
|
-
|
|
55
|
+
const docId = documentId ?? inScope;
|
|
56
|
+
const wantedPageObjectNumber = wantedRef?.objectNumber ?? null;
|
|
57
|
+
const base = require_runtime.useKernelValue((kernel) => {
|
|
58
|
+
if (!docId) return null;
|
|
59
|
+
const pages = kernel.documents.listPages(docId);
|
|
60
|
+
return (wantedPageObjectNumber !== null ? pages.find((pageInfo) => pageInfo.ref.objectNumber === wantedPageObjectNumber) : pages[wantedIndex ?? 0]) ?? null;
|
|
61
|
+
});
|
|
62
|
+
const page = base?.index ?? wantedIndex ?? 0;
|
|
63
|
+
const pageObjectNumber = base?.ref.objectNumber ?? wantedPageObjectNumber ?? page + 1;
|
|
64
|
+
const pageRef = (0, react.useMemo)(() => (0, _embedpdf_core.toPageRef)(pageObjectNumber), [pageObjectNumber]);
|
|
33
65
|
const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
|
|
34
|
-
const transform = (0, react.useMemo)(() => (0, _embedpdf_core_geometry.pageTransform)(
|
|
35
|
-
pageSize: base ? {
|
|
36
|
-
width: base.size.width,
|
|
37
|
-
height: base.size.height
|
|
38
|
-
} : {
|
|
39
|
-
width: 1,
|
|
40
|
-
height: 1
|
|
41
|
-
},
|
|
42
|
-
rotation,
|
|
43
|
-
scale: base ? width / base.size.width : 1,
|
|
44
|
-
baseScale: 96 / 72 * (base?.userUnit ?? 1),
|
|
45
|
-
dpr
|
|
46
|
-
}), [
|
|
66
|
+
const transform = (0, react.useMemo)(() => (0, _embedpdf_core_geometry.pageTransform)((0, _embedpdf_web.pageViewTransformInput)(base, width, dpr)), [
|
|
47
67
|
base?.size.width,
|
|
48
68
|
base?.size.height,
|
|
49
69
|
base?.userUnit,
|
|
50
|
-
rotation,
|
|
70
|
+
base?.rotation,
|
|
51
71
|
width,
|
|
52
72
|
dpr
|
|
53
73
|
]);
|
|
54
74
|
const viewId = (0, react.useId)();
|
|
55
|
-
const ctx = (0, react.useMemo)(() =>
|
|
75
|
+
const ctx = (0, react.useMemo)(() => (0, _embedpdf_web.makePageContext)(docId ?? "", `page-view:${viewId}`, pageRef, page, pageFrame, transform, () => ref.current.getBoundingClientRect()), [
|
|
56
76
|
docId,
|
|
57
|
-
|
|
77
|
+
pageRef,
|
|
58
78
|
page,
|
|
59
79
|
pageFrame,
|
|
60
80
|
transform,
|
|
61
81
|
viewId
|
|
62
82
|
]);
|
|
63
|
-
const projector = (0, react.useMemo)(() => (
|
|
64
|
-
space: "client",
|
|
65
|
-
toScreen: (p, rect) => p === ctx.pon && ref.current ? ctx.toClientRect(rect) : null,
|
|
66
|
-
toScreenPoint: (p, at) => p === ctx.pon && ref.current ? ctx.toClientPoint(at) : null,
|
|
67
|
-
viewEnv: (p) => p === ctx.pon ? {
|
|
68
|
-
scale: ctx.transform.viewScale,
|
|
69
|
-
rotation: ctx.transform.rotation,
|
|
70
|
-
zoom: ctx.transform.zoom
|
|
71
|
-
} : null
|
|
72
|
-
}), [ctx]);
|
|
83
|
+
const projector = (0, react.useMemo)(() => (0, _embedpdf_web.clientPageProjector)(ctx, () => ref.current !== null), [ctx]);
|
|
73
84
|
const projectorBinding = (0, react.useMemo)(() => ({
|
|
74
85
|
projector,
|
|
75
86
|
revision: ctx,
|
|
76
87
|
subscribe: _embedpdf_web.observeClientGeometry
|
|
77
88
|
}), [projector, ctx]);
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
const contentLeft = pageFrame.left + (t.viewWidth - t.contentWidth) / 2;
|
|
83
|
-
const contentTop = pageFrame.top + (t.viewHeight - t.contentHeight) / 2;
|
|
89
|
+
const shownPages = (0, react.useMemo)(() => /* @__PURE__ */ new Set([ctx.ref.objectNumber]), [ctx.ref.objectNumber]);
|
|
90
|
+
const look = require_runtime.useViewerSettings((settings) => settings.page);
|
|
91
|
+
if (!docId || !base) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: fallback });
|
|
92
|
+
const layout = (0, _embedpdf_web.pageSurfaceLayout)(transform, pageFrame);
|
|
84
93
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_runtime.DocumentScope, {
|
|
85
94
|
id: docId,
|
|
86
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_anchored.
|
|
87
|
-
value:
|
|
88
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
width: t.viewWidth,
|
|
103
|
-
height: t.viewHeight,
|
|
104
|
-
boxShadow: "var(--epdf-page-shadow, 0 6px 18px rgba(0,0,0,.18))"
|
|
105
|
-
} }),
|
|
106
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
107
|
-
ref,
|
|
108
|
-
style: {
|
|
95
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_anchored.ShownPagesProvider, {
|
|
96
|
+
value: shownPages,
|
|
97
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_anchored.ProjectorProvider, {
|
|
98
|
+
value: projectorBinding,
|
|
99
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
100
|
+
className,
|
|
101
|
+
style: {
|
|
102
|
+
position: "relative",
|
|
103
|
+
width: layout.outer.width,
|
|
104
|
+
height: layout.outer.height,
|
|
105
|
+
...style
|
|
106
|
+
},
|
|
107
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_runtime.PageProvider, {
|
|
108
|
+
value: ctx,
|
|
109
|
+
children: [
|
|
110
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: {
|
|
109
111
|
position: "absolute",
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
112
|
+
...layout.shadow,
|
|
113
|
+
boxShadow: (0, _embedpdf_web.paint)("page-shadow", look.shadow)
|
|
114
|
+
} }),
|
|
115
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
116
|
+
ref,
|
|
117
|
+
style: {
|
|
118
|
+
position: "absolute",
|
|
119
|
+
...layout.content,
|
|
120
|
+
background: (0, _embedpdf_web.paint)("page-background", look.background),
|
|
121
|
+
transform: layout.turn ?? void 0,
|
|
122
|
+
userSelect: "none",
|
|
123
|
+
WebkitUserSelect: "none"
|
|
124
|
+
},
|
|
125
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(PointerSurface, {}), children]
|
|
126
|
+
}),
|
|
127
|
+
pageChrome
|
|
128
|
+
]
|
|
129
|
+
})
|
|
123
130
|
})
|
|
124
131
|
})
|
|
125
132
|
})
|
package/dist/page-view.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-view.cjs","names":["NO_FRAME","useKernel","useActiveDocumentId","makePageContext","observeClientGeometry","DocumentScope","ProjectorProvider","PageProvider"],"sources":["../src/page-view.tsx"],"sourcesContent":["/**\n * <PageView> — a single page surface with NO Stage.\n *\n * Same layers + rotation + chrome frame as a `<Stage>` page, but no\n * camera/scroll/zoom and, crucially, NO dependency on `@embedpdf/plugin-stage`.\n * It builds its own `PageTransform` from a target content width and shares the\n * exact `PageContext` seam, so every layer (RenderLayer, AnnotationLayer, …)\n * works here identically — and it provides the measured `ViewProjector`, so\n * anchored UI (`<AnnotationMenu>`, `<SelectionMenu>`) works here too, portalled\n * and clipping-immune.\n */\nimport * as React from 'react';\nimport { useId, useMemo, useRef } from 'react';\nimport { NO_FRAME, pageTransform, type PageFrame } from '@embedpdf/core-geometry';\nimport { observeClientGeometry } from '@embedpdf/web';\nimport { ProjectorProvider, type ProjectorBinding, type ViewProjector } from './anchored';\nimport {\n DocumentScope,\n makePageContext,\n PageProvider,\n useActiveDocumentId,\n useKernel,\n} from './runtime';\n\nexport interface PageViewProps {\n page: number;\n /** Which document to show. Defaults to the active document. */\n documentId?: string;\n /** Target width for the page CONTENT; the display box is the rotated footprint. */\n width?: number;\n /** Reserved chrome bands around the page (screen px) — same model as `<Stage>`. */\n pageFrame?: PageFrame;\n /** Page-space content (rotates with the page). */\n children: React.ReactNode;\n /** Box-space chrome (label, border, …) — never rotated. Mirrors `<Stage pageChrome>`. */\n pageChrome?: React.ReactNode;\n style?: React.CSSProperties;\n}\n\n/** A single page surface with NO Stage — same layers + rotation + chrome frame,\n * no camera/scroll/zoom. */\nexport function PageView({\n page,\n documentId,\n width = 240,\n pageFrame = NO_FRAME,\n children,\n pageChrome,\n style,\n}: PageViewProps) {\n const kernel = useKernel();\n const active = useActiveDocumentId();\n const ref = useRef<HTMLDivElement>(null);\n const docId = documentId ?? active;\n const meta = docId ? kernel.getState().core.documents[docId] : undefined;\n const base = meta?.pages[page];\n const pon = base?.pageObjectNumber ?? page + 1;\n const rotation = base?.rotation ?? 0;\n const dpr = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;\n // Standalone (no Stage/camera): build the page's transform from the target\n // content `width` directly. `scale` is view px per point = width / pageWidthPts.\n const transform = useMemo(\n () =>\n pageTransform({\n pageSize: base\n ? { width: base.size.width, height: base.size.height }\n : { width: 1, height: 1 },\n rotation,\n scale: base ? width / base.size.width : 1,\n // Physical 100% on the web: 1pt = 96/72 CSS px, times the page's\n // /UserUnit — so `transform.zoom` is meaningful even without a Stage\n // (a thumbnail-sized PageView reads as zoomed out, as it should).\n baseScale: (96 / 72) * (base?.userUnit ?? 1),\n dpr,\n }),\n [base?.size.width, base?.size.height, base?.userUnit, rotation, width, dpr],\n );\n // This instance's VIEW identity: two PageViews of the same page (a compare\n // strip) must plan rasters independently, like two stage lenses do.\n const viewId = useId();\n const ctx = useMemo(\n () =>\n makePageContext(\n docId ?? '',\n `page-view:${viewId}`,\n pon,\n page,\n pageFrame,\n transform,\n () => ref.current!.getBoundingClientRect(),\n ),\n [docId, pon, page, pageFrame, transform, viewId],\n );\n // The PageView's ViewProjector: no camera, so anchored UI positions by\n // MEASURING the DOM (client space → portal + position:fixed, immune to\n // ancestor overflow clipping). `toScreen` answers null until the page\n // element has committed — <Anchored> forces one post-commit pass to pick\n // it up. The binding's revision covers state-driven changes (a new\n // transform/page); `observeClientGeometry` covers the genuinely\n // browser-driven ones (document scroll, window resize) that no state\n // change announces.\n const projector = useMemo<ViewProjector>(\n () => ({\n space: 'client',\n toScreen: (p, rect) => (p === ctx.pon && ref.current ? ctx.toClientRect(rect) : null),\n toScreenPoint: (p, at) => (p === ctx.pon && ref.current ? ctx.toClientPoint(at) : null),\n viewEnv: (p) =>\n p === ctx.pon\n ? {\n scale: ctx.transform.viewScale,\n rotation: ctx.transform.rotation,\n zoom: ctx.transform.zoom,\n }\n : null,\n }),\n [ctx],\n );\n const projectorBinding = useMemo<ProjectorBinding>(\n () => ({ projector, revision: ctx, subscribe: observeClientGeometry }),\n [projector, ctx],\n );\n if (!docId || !meta || !base) return null;\n const t = transform;\n const outerW = t.viewWidth + pageFrame.left + pageFrame.right;\n const outerH = t.viewHeight + pageFrame.top + pageFrame.bottom;\n const contentLeft = pageFrame.left + (t.viewWidth - t.contentWidth) / 2;\n const contentTop = pageFrame.top + (t.viewHeight - t.contentHeight) / 2;\n return (\n <DocumentScope id={docId}>\n <ProjectorProvider value={projectorBinding}>\n <div style={{ position: 'relative', width: outerW, height: outerH, ...style }}>\n <PageProvider value={ctx}>\n {/* drop shadow ONLY — transparent, axis-aligned, can't leak behind the bitmap */}\n <div\n style={{\n position: 'absolute',\n left: pageFrame.left,\n top: pageFrame.top,\n width: t.viewWidth,\n height: t.viewHeight,\n boxShadow: 'var(--epdf-page-shadow, 0 6px 18px rgba(0,0,0,.18))',\n }}\n />\n {/* white backing + content as ONE box; rotation 0 carries no transform */}\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 userSelect: 'none',\n WebkitUserSelect: 'none',\n }}\n >\n {children}\n </div>\n {pageChrome}\n </PageProvider>\n </div>\n </ProjectorProvider>\n </DocumentScope>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,SAAS,EACvB,MACA,YACA,QAAQ,KACR,YAAYA,wBAAAA,UACZ,UACA,YACA,SACgB;CAChB,MAAM,SAASC,gBAAAA,UAAU;CACzB,MAAM,SAASC,gBAAAA,oBAAoB;CACnC,MAAM,OAAA,GAAA,MAAA,OAAA,CAA6B,IAAI;CACvC,MAAM,QAAQ,cAAc;CAC5B,MAAM,OAAO,QAAQ,OAAO,SAAS,CAAC,CAAC,KAAK,UAAU,SAAS,KAAA;CAC/D,MAAM,OAAO,MAAM,MAAM;CACzB,MAAM,MAAM,MAAM,oBAAoB,OAAO;CAC7C,MAAM,WAAW,MAAM,YAAY;CACnC,MAAM,MAAM,OAAO,WAAW,cAAc,OAAO,oBAAoB,IAAI;CAG3E,MAAM,aAAA,GAAA,MAAA,QAAA,QAAA,GAAA,wBAAA,cAAA,CAEY;EACZ,UAAU,OACN;GAAE,OAAO,KAAK,KAAK;GAAO,QAAQ,KAAK,KAAK;EAAO,IACnD;GAAE,OAAO;GAAG,QAAQ;EAAE;EAC1B;EACA,OAAO,OAAO,QAAQ,KAAK,KAAK,QAAQ;EAIxC,WAAY,KAAK,MAAO,MAAM,YAAY;EAC1C;CACF,CAAC,GACH;EAAC,MAAM,KAAK;EAAO,MAAM,KA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,UAAU;KAAY,OAAO;KAAQ,QAAQ;KAAQ,GAAG;IAAM;IAC1E,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAACC,gBAAAA,cAAD;KAAc,OAAO;KAArB,UAAA;MAEE,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD,EACE,OAAO;OACL,UAAU;OACV,MAAM,UAAU;OAChB,KAAK,UAAU;OACf,OAAO,EAAE;OACT,QAAQ,EAAE;OACV,WAAW;MACb,EACD,CAAA;MAED,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;OACO;OACL,OAAO;QACL,UAAU;QACV,MAAM;QACN,KAAK;QACL,OAAO,EAAE;QACT,QAAQ,EAAE;QACV,YAAY;QACZ,WAAW,WAAW,UAAU,SAAS,QAAQ,KAAA;QACjD,YAAY;QACZ,kBAAkB;OACpB;OAEC;MACE,CAAA;MACJ;KACW;;GACX,CAAA;EACc,CAAA;CACN,CAAA;AAEnB"}
|
|
1
|
+
{"version":3,"file":"page-view.cjs","names":["useOptionalCapability","InteractionHostToken","PagePointerSource","NO_FRAME","useDocumentId","useKernelValue","observeClientGeometry","useViewerSettings","DocumentScope","ShownPagesProvider","ProjectorProvider","PageProvider"],"sources":["../src/page-view.tsx"],"sourcesContent":["/**\n * <PageView> — a single page surface with no Stage.\n *\n * Same layers + rotation + chrome frame as a `<Stage>` page, but no\n * camera/scroll/zoom and, crucially, no dependency on `@embedpdf/plugin-stage`.\n * It builds its own `PageTransform` from a target content width and shares the\n * exact `PageContext` seam, so every layer (RenderLayer, AnnotationLayer, …)\n * works here identically — and it provides the measured `ViewProjector`, so\n * anchored UI (`<AnnotationMenu>`, `<SelectionMenu>`) works here too, portalled\n * and clipping-immune. With the interaction plugin registered it is also the\n * page's pointer surface, so tools (text selection, annotation editing) work in\n * it as they do on a Stage page.\n */\nimport * as React from 'react';\nimport { useId, useMemo, useRef } from 'react';\nimport { toPageRef } from '@embedpdf/core';\nimport type { PageRef } from '@embedpdf/core';\nimport { NO_FRAME, pageTransform, type PageFrame } from '@embedpdf/core-geometry';\nimport {\n clientPageProjector,\n makePageContext,\n observeClientGeometry,\n pageSurfaceLayout,\n pageViewTransformInput,\n paint,\n} from '@embedpdf/web';\nimport { InteractionToken as InteractionHostToken } from '@embedpdf/plugin-interaction/contract/host';\nimport {\n ProjectorProvider,\n ShownPagesProvider,\n type ProjectorBinding,\n type ShownPages,\n type ViewProjector,\n} from './anchored';\nimport { PagePointerSource } from './interaction';\nimport {\n DocumentScope,\n PageProvider,\n useDocumentId,\n useKernelValue,\n useOptionalCapability,\n useViewerSettings,\n} from './runtime';\n\n/**\n * The page's pointer surface, when the interaction plugin is registered. It sits\n * below the layers, like the Stage's own listener: a press on a layer that lets\n * the pointer through (the picture, the selection highlight) reaches the tools,\n * and a control that takes its own presses (a link, a form field) keeps them.\n */\nfunction PointerSurface() {\n const interaction = useOptionalCapability(InteractionHostToken);\n return interaction ? <PagePointerSource /> : null;\n}\n\nexport interface PageViewProps {\n /** The page: its `ref`, which follows it when pages move, or its index, from 0. */\n page: PageRef | number;\n /** Which document to show. Defaults to the one a `<DocumentScope>` names, else the active one. */\n documentId?: string;\n /** Shown while the document or the page is not available yet (default: nothing). */\n fallback?: React.ReactNode;\n /** The width of the page, in pixels; the display box is the rotated footprint. Default 240. */\n width?: number;\n /** Space reserved around the page for your own labels, in pixels per side; the sides left out are 0. */\n pageFrame?: Partial<PageFrame>;\n /** Page-space content (rotates with the page). */\n children: React.ReactNode;\n /** Box-space chrome (label, border, …) — never rotated. Mirrors `<Stage pageChrome>`. */\n pageChrome?: React.ReactNode;\n /** On the outer box. */\n className?: string;\n /** On the outer box. */\n style?: React.CSSProperties;\n}\n\n/** A single page surface with no Stage — same layers + rotation + chrome frame,\n * no camera/scroll/zoom. */\nexport function PageView({\n page: wanted,\n documentId,\n fallback = null,\n width = 240,\n pageFrame: framePatch,\n children,\n pageChrome,\n className,\n style,\n}: PageViewProps) {\n const wantedRef = typeof wanted === 'number' ? null : wanted;\n const wantedIndex = typeof wanted === 'number' ? wanted : null;\n // The sides left out reserve nothing; memoized by value so the context stays stable.\n const { top = 0, right = 0, bottom = 0, left = 0 } = framePatch ?? NO_FRAME;\n const pageFrame = useMemo<PageFrame>(\n () => ({ top, right, bottom, left }),\n [top, right, bottom, left],\n );\n const inScope = useDocumentId();\n const ref = useRef<HTMLDivElement>(null);\n const docId = documentId ?? inScope;\n // The page-registry entry, subscribed: a rotate or a reorder re-renders\n // this surface like it re-renders a Stage page. Entries are reference-\n // stable per page in the registry, so identity is the right equality.\n const wantedPageObjectNumber = wantedRef?.objectNumber ?? null;\n const base = useKernelValue((kernel) => {\n if (!docId) return null;\n const pages = kernel.documents.listPages(docId);\n const found =\n wantedPageObjectNumber !== null\n ? pages.find((pageInfo) => pageInfo.ref.objectNumber === wantedPageObjectNumber)\n : pages[wantedIndex ?? 0];\n return found ?? null;\n });\n const page = base?.index ?? wantedIndex ?? 0;\n // The page's address is the kernel's (`PageLayout.ref`); a placeholder\n // (object number = 1-based index) only until the layout is known — the\n // surface renders the fallback before that anyway. Memoized by the number so\n // the context's `ref` stays identity-stable across re-renders (layers key\n // effects on it).\n const pageObjectNumber = base?.ref.objectNumber ?? wantedPageObjectNumber ?? page + 1;\n const pageRef = useMemo(() => toPageRef(pageObjectNumber), [pageObjectNumber]);\n const dpr = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;\n // Standalone (no Stage/camera): build the page's transform from the target\n // content `width` directly. Memoized by value: a new registry entry for an\n // unchanged page keeps the transform.\n const transform = useMemo(\n () => pageTransform(pageViewTransformInput(base, width, dpr)),\n // eslint-disable-next-line react-hooks/exhaustive-deps -- `base` by the values it gives\n [base?.size.width, base?.size.height, base?.userUnit, base?.rotation, width, dpr],\n );\n // This instance's view identity: two PageViews of the same page (a compare\n // strip) must plan rasters independently, like two stage lenses do.\n const viewId = useId();\n const ctx = useMemo(\n () =>\n makePageContext(docId ?? '', `page-view:${viewId}`, pageRef, page, pageFrame, transform, () =>\n ref.current!.getBoundingClientRect(),\n ),\n [docId, pageRef, page, pageFrame, transform, viewId],\n );\n // The PageView's ViewProjector: no camera, so anchored UI positions by\n // measuring the DOM (client space → portal + position:fixed, immune to\n // ancestor overflow clipping). `toScreen` answers null until the page\n // element has committed — <Anchored> forces one post-commit pass to pick\n // it up. The binding's revision covers state-driven changes (a new\n // transform/page); `observeClientGeometry` covers the genuinely\n // browser-driven ones (document scroll, window resize) that no state\n // change announces.\n const projector = useMemo<ViewProjector>(\n () => clientPageProjector(ctx, () => ref.current !== null),\n [ctx],\n );\n const projectorBinding = useMemo<ProjectorBinding>(\n () => ({ projector, revision: ctx, subscribe: observeClientGeometry }),\n [projector, ctx],\n );\n // A PageView shows its one page.\n const shownPages = useMemo<ShownPages>(\n () => new Set([ctx.ref.objectNumber]),\n [ctx.ref.objectNumber],\n );\n // The viewer's `page` settings; `--epdf-page-*` CSS variables win over them.\n const look = useViewerSettings((settings) => settings.page);\n if (!docId || !base) return <>{fallback}</>;\n // The outer box (page and frame), the shadow at the footprint, and the turned content box.\n const layout = pageSurfaceLayout(transform, pageFrame);\n return (\n <DocumentScope id={docId}>\n <ShownPagesProvider value={shownPages}>\n <ProjectorProvider value={projectorBinding}>\n <div\n className={className}\n style={{\n position: 'relative',\n width: layout.outer.width,\n height: layout.outer.height,\n ...style,\n }}\n >\n <PageProvider value={ctx}>\n {/* drop shadow ONLY — transparent, axis-aligned, can't leak behind the bitmap */}\n <div\n style={{\n position: 'absolute',\n ...layout.shadow,\n boxShadow: paint('page-shadow', look.shadow),\n }}\n />\n {/* white backing + content as ONE box; rotation 0 carries no transform */}\n <div\n ref={ref}\n style={{\n position: 'absolute',\n ...layout.content,\n background: paint('page-background', look.background),\n transform: layout.turn ?? undefined,\n userSelect: 'none',\n WebkitUserSelect: 'none',\n }}\n >\n <PointerSurface />\n {children}\n </div>\n {pageChrome}\n </PageProvider>\n </div>\n </ProjectorProvider>\n </ShownPagesProvider>\n </DocumentScope>\n );\n}\n"],"mappings":";;;;;;;;;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CAAC,OAAD;KACa;KACX,OAAO;MACL,UAAU;MACV,OAAO,OAAO,MAAM;MACpB,QAAQ,OAAO,MAAM;MACrB,GAAG;KACL;KAEA,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAACC,gBAAAA,cAAD;MAAc,OAAO;MAArB,UAAA;OAEE,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD,EACE,OAAO;QACL,UAAU;QACV,GAAG,OAAO;QACV,YAAA,GAAA,cAAA,MAAA,CAAiB,eAAe,KAAK,MAAM;OAC7C,EACD,CAAA;OAED,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;QACO;QACL,OAAO;SACL,UAAU;SACV,GAAG,OAAO;SACV,aAAA,GAAA,cAAA,MAAA,CAAkB,mBAAmB,KAAK,UAAU;SACpD,WAAW,OAAO,QAAQ,KAAA;SAC1B,YAAY;SACZ,kBAAkB;QACpB;QATF,UAAA,CAWE,iBAAA,GAAA,kBAAA,IAAA,CAAC,gBAAD,CAAiB,CAAA,GAChB,QACE;;OACJ;MACW;;IACX,CAAA;GACY,CAAA;EACD,CAAA;CACP,CAAA;AAEnB"}
|
package/dist/page-view.d.cts
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
|
+
import { PageRef } from "@embedpdf/core";
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
import { PageFrame } from "@embedpdf/core-geometry";
|
|
3
4
|
//#region src/page-view.d.ts
|
|
4
5
|
interface PageViewProps {
|
|
5
|
-
page:
|
|
6
|
-
|
|
6
|
+
/** The page: its `ref`, which follows it when pages move, or its index, from 0. */
|
|
7
|
+
page: PageRef | number;
|
|
8
|
+
/** Which document to show. Defaults to the one a `<DocumentScope>` names, else the active one. */
|
|
7
9
|
documentId?: string;
|
|
8
|
-
/**
|
|
10
|
+
/** Shown while the document or the page is not available yet (default: nothing). */
|
|
11
|
+
fallback?: React.ReactNode;
|
|
12
|
+
/** The width of the page, in pixels; the display box is the rotated footprint. Default 240. */
|
|
9
13
|
width?: number;
|
|
10
|
-
/**
|
|
11
|
-
pageFrame?: PageFrame
|
|
14
|
+
/** Space reserved around the page for your own labels, in pixels per side; the sides left out are 0. */
|
|
15
|
+
pageFrame?: Partial<PageFrame>;
|
|
12
16
|
/** Page-space content (rotates with the page). */
|
|
13
17
|
children: React.ReactNode;
|
|
14
18
|
/** Box-space chrome (label, border, …) — never rotated. Mirrors `<Stage pageChrome>`. */
|
|
15
19
|
pageChrome?: React.ReactNode;
|
|
20
|
+
/** On the outer box. */
|
|
21
|
+
className?: string;
|
|
22
|
+
/** On the outer box. */
|
|
16
23
|
style?: React.CSSProperties;
|
|
17
24
|
}
|
|
18
|
-
/** A single page surface with
|
|
25
|
+
/** A single page surface with no Stage — same layers + rotation + chrome frame,
|
|
19
26
|
* no camera/scroll/zoom. */
|
|
20
|
-
declare function PageView({ page, documentId, width, pageFrame, children, pageChrome, style }: PageViewProps): import("react/jsx-runtime").JSX.Element
|
|
27
|
+
declare function PageView({ page: wanted, documentId, fallback, width, pageFrame: framePatch, children, pageChrome, className, style }: PageViewProps): import("react/jsx-runtime").JSX.Element;
|
|
21
28
|
//#endregion
|
|
22
29
|
export { PageView, PageViewProps };
|
|
23
30
|
//# sourceMappingURL=page-view.d.cts.map
|
package/dist/page-view.d.ts
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PageRef } from "@embedpdf/core";
|
|
2
|
+
import * as React$1 from "react";
|
|
2
3
|
import { PageFrame } from "@embedpdf/core-geometry";
|
|
3
4
|
//#region src/page-view.d.ts
|
|
4
5
|
interface PageViewProps {
|
|
5
|
-
page:
|
|
6
|
-
|
|
6
|
+
/** The page: its `ref`, which follows it when pages move, or its index, from 0. */
|
|
7
|
+
page: PageRef | number;
|
|
8
|
+
/** Which document to show. Defaults to the one a `<DocumentScope>` names, else the active one. */
|
|
7
9
|
documentId?: string;
|
|
8
|
-
/**
|
|
10
|
+
/** Shown while the document or the page is not available yet (default: nothing). */
|
|
11
|
+
fallback?: React$1.ReactNode;
|
|
12
|
+
/** The width of the page, in pixels; the display box is the rotated footprint. Default 240. */
|
|
9
13
|
width?: number;
|
|
10
|
-
/**
|
|
11
|
-
pageFrame?: PageFrame
|
|
14
|
+
/** Space reserved around the page for your own labels, in pixels per side; the sides left out are 0. */
|
|
15
|
+
pageFrame?: Partial<PageFrame>;
|
|
12
16
|
/** Page-space content (rotates with the page). */
|
|
13
|
-
children: React.ReactNode;
|
|
17
|
+
children: React$1.ReactNode;
|
|
14
18
|
/** Box-space chrome (label, border, …) — never rotated. Mirrors `<Stage pageChrome>`. */
|
|
15
|
-
pageChrome?: React.ReactNode;
|
|
16
|
-
|
|
19
|
+
pageChrome?: React$1.ReactNode;
|
|
20
|
+
/** On the outer box. */
|
|
21
|
+
className?: string;
|
|
22
|
+
/** On the outer box. */
|
|
23
|
+
style?: React$1.CSSProperties;
|
|
17
24
|
}
|
|
18
|
-
/** A single page surface with
|
|
25
|
+
/** A single page surface with no Stage — same layers + rotation + chrome frame,
|
|
19
26
|
* no camera/scroll/zoom. */
|
|
20
|
-
declare function PageView({ page, documentId, width, pageFrame, children, pageChrome, style }: PageViewProps): import("react/jsx-runtime").JSX.Element
|
|
27
|
+
declare function PageView({ page: wanted, documentId, fallback, width, pageFrame: framePatch, children, pageChrome, className, style }: PageViewProps): import("react/jsx-runtime").JSX.Element;
|
|
21
28
|
//#endregion
|
|
22
29
|
export { PageView, PageViewProps };
|
|
23
30
|
//# sourceMappingURL=page-view.d.ts.map
|
package/dist/page-view.js
CHANGED
|
@@ -1,111 +1,116 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ProjectorProvider } from "./anchored.js";
|
|
3
|
-
import {
|
|
1
|
+
import { D as useViewerSettings, S as useOptionalCapability, a as PageProvider, h as useDocumentId, n as DocumentScope, x as useKernelValue } from "./runtime-tD5iJU83.js";
|
|
2
|
+
import { ProjectorProvider, ShownPagesProvider } from "./anchored.js";
|
|
3
|
+
import { PagePointerSource } from "./interaction.js";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { toPageRef } from "@embedpdf/core";
|
|
6
|
+
import { clientPageProjector, makePageContext, observeClientGeometry, pageSurfaceLayout, pageViewTransformInput, paint } from "@embedpdf/web";
|
|
4
7
|
import { useId, useMemo, useRef } from "react";
|
|
5
|
-
import {
|
|
8
|
+
import { InteractionToken } from "@embedpdf/plugin-interaction/contract/host";
|
|
6
9
|
import { NO_FRAME, pageTransform } from "@embedpdf/core-geometry";
|
|
7
10
|
//#region src/page-view.tsx
|
|
8
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* The page's pointer surface, when the interaction plugin is registered. It sits
|
|
13
|
+
* below the layers, like the Stage's own listener: a press on a layer that lets
|
|
14
|
+
* the pointer through (the picture, the selection highlight) reaches the tools,
|
|
15
|
+
* and a control that takes its own presses (a link, a form field) keeps them.
|
|
16
|
+
*/
|
|
17
|
+
function PointerSurface() {
|
|
18
|
+
return useOptionalCapability(InteractionToken) ? /* @__PURE__ */ jsx(PagePointerSource, {}) : null;
|
|
19
|
+
}
|
|
20
|
+
/** A single page surface with no Stage — same layers + rotation + chrome frame,
|
|
9
21
|
* no camera/scroll/zoom. */
|
|
10
|
-
function PageView({ page, documentId, width = 240, pageFrame
|
|
11
|
-
const
|
|
12
|
-
const
|
|
22
|
+
function PageView({ page: wanted, documentId, fallback = null, width = 240, pageFrame: framePatch, children, pageChrome, className, style }) {
|
|
23
|
+
const wantedRef = typeof wanted === "number" ? null : wanted;
|
|
24
|
+
const wantedIndex = typeof wanted === "number" ? wanted : null;
|
|
25
|
+
const { top = 0, right = 0, bottom = 0, left = 0 } = framePatch ?? NO_FRAME;
|
|
26
|
+
const pageFrame = useMemo(() => ({
|
|
27
|
+
top,
|
|
28
|
+
right,
|
|
29
|
+
bottom,
|
|
30
|
+
left
|
|
31
|
+
}), [
|
|
32
|
+
top,
|
|
33
|
+
right,
|
|
34
|
+
bottom,
|
|
35
|
+
left
|
|
36
|
+
]);
|
|
37
|
+
const inScope = useDocumentId();
|
|
13
38
|
const ref = useRef(null);
|
|
14
|
-
const docId = documentId ??
|
|
15
|
-
const
|
|
16
|
-
const base =
|
|
17
|
-
|
|
18
|
-
|
|
39
|
+
const docId = documentId ?? inScope;
|
|
40
|
+
const wantedPageObjectNumber = wantedRef?.objectNumber ?? null;
|
|
41
|
+
const base = useKernelValue((kernel) => {
|
|
42
|
+
if (!docId) return null;
|
|
43
|
+
const pages = kernel.documents.listPages(docId);
|
|
44
|
+
return (wantedPageObjectNumber !== null ? pages.find((pageInfo) => pageInfo.ref.objectNumber === wantedPageObjectNumber) : pages[wantedIndex ?? 0]) ?? null;
|
|
45
|
+
});
|
|
46
|
+
const page = base?.index ?? wantedIndex ?? 0;
|
|
47
|
+
const pageObjectNumber = base?.ref.objectNumber ?? wantedPageObjectNumber ?? page + 1;
|
|
48
|
+
const pageRef = useMemo(() => toPageRef(pageObjectNumber), [pageObjectNumber]);
|
|
19
49
|
const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
|
|
20
|
-
const transform = useMemo(() => pageTransform(
|
|
21
|
-
pageSize: base ? {
|
|
22
|
-
width: base.size.width,
|
|
23
|
-
height: base.size.height
|
|
24
|
-
} : {
|
|
25
|
-
width: 1,
|
|
26
|
-
height: 1
|
|
27
|
-
},
|
|
28
|
-
rotation,
|
|
29
|
-
scale: base ? width / base.size.width : 1,
|
|
30
|
-
baseScale: 96 / 72 * (base?.userUnit ?? 1),
|
|
31
|
-
dpr
|
|
32
|
-
}), [
|
|
50
|
+
const transform = useMemo(() => pageTransform(pageViewTransformInput(base, width, dpr)), [
|
|
33
51
|
base?.size.width,
|
|
34
52
|
base?.size.height,
|
|
35
53
|
base?.userUnit,
|
|
36
|
-
rotation,
|
|
54
|
+
base?.rotation,
|
|
37
55
|
width,
|
|
38
56
|
dpr
|
|
39
57
|
]);
|
|
40
58
|
const viewId = useId();
|
|
41
|
-
const ctx = useMemo(() => makePageContext(docId ?? "", `page-view:${viewId}`,
|
|
59
|
+
const ctx = useMemo(() => makePageContext(docId ?? "", `page-view:${viewId}`, pageRef, page, pageFrame, transform, () => ref.current.getBoundingClientRect()), [
|
|
42
60
|
docId,
|
|
43
|
-
|
|
61
|
+
pageRef,
|
|
44
62
|
page,
|
|
45
63
|
pageFrame,
|
|
46
64
|
transform,
|
|
47
65
|
viewId
|
|
48
66
|
]);
|
|
49
|
-
const projector = useMemo(() => (
|
|
50
|
-
space: "client",
|
|
51
|
-
toScreen: (p, rect) => p === ctx.pon && ref.current ? ctx.toClientRect(rect) : null,
|
|
52
|
-
toScreenPoint: (p, at) => p === ctx.pon && ref.current ? ctx.toClientPoint(at) : null,
|
|
53
|
-
viewEnv: (p) => p === ctx.pon ? {
|
|
54
|
-
scale: ctx.transform.viewScale,
|
|
55
|
-
rotation: ctx.transform.rotation,
|
|
56
|
-
zoom: ctx.transform.zoom
|
|
57
|
-
} : null
|
|
58
|
-
}), [ctx]);
|
|
67
|
+
const projector = useMemo(() => clientPageProjector(ctx, () => ref.current !== null), [ctx]);
|
|
59
68
|
const projectorBinding = useMemo(() => ({
|
|
60
69
|
projector,
|
|
61
70
|
revision: ctx,
|
|
62
71
|
subscribe: observeClientGeometry
|
|
63
72
|
}), [projector, ctx]);
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
const contentLeft = pageFrame.left + (t.viewWidth - t.contentWidth) / 2;
|
|
69
|
-
const contentTop = pageFrame.top + (t.viewHeight - t.contentHeight) / 2;
|
|
73
|
+
const shownPages = useMemo(() => /* @__PURE__ */ new Set([ctx.ref.objectNumber]), [ctx.ref.objectNumber]);
|
|
74
|
+
const look = useViewerSettings((settings) => settings.page);
|
|
75
|
+
if (!docId || !base) return /* @__PURE__ */ jsx(Fragment, { children: fallback });
|
|
76
|
+
const layout = pageSurfaceLayout(transform, pageFrame);
|
|
70
77
|
return /* @__PURE__ */ jsx(DocumentScope, {
|
|
71
78
|
id: docId,
|
|
72
|
-
children: /* @__PURE__ */ jsx(
|
|
73
|
-
value:
|
|
74
|
-
children: /* @__PURE__ */ jsx(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
width: t.viewWidth,
|
|
89
|
-
height: t.viewHeight,
|
|
90
|
-
boxShadow: "var(--epdf-page-shadow, 0 6px 18px rgba(0,0,0,.18))"
|
|
91
|
-
} }),
|
|
92
|
-
/* @__PURE__ */ jsx("div", {
|
|
93
|
-
ref,
|
|
94
|
-
style: {
|
|
79
|
+
children: /* @__PURE__ */ jsx(ShownPagesProvider, {
|
|
80
|
+
value: shownPages,
|
|
81
|
+
children: /* @__PURE__ */ jsx(ProjectorProvider, {
|
|
82
|
+
value: projectorBinding,
|
|
83
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
84
|
+
className,
|
|
85
|
+
style: {
|
|
86
|
+
position: "relative",
|
|
87
|
+
width: layout.outer.width,
|
|
88
|
+
height: layout.outer.height,
|
|
89
|
+
...style
|
|
90
|
+
},
|
|
91
|
+
children: /* @__PURE__ */ jsxs(PageProvider, {
|
|
92
|
+
value: ctx,
|
|
93
|
+
children: [
|
|
94
|
+
/* @__PURE__ */ jsx("div", { style: {
|
|
95
95
|
position: "absolute",
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
96
|
+
...layout.shadow,
|
|
97
|
+
boxShadow: paint("page-shadow", look.shadow)
|
|
98
|
+
} }),
|
|
99
|
+
/* @__PURE__ */ jsxs("div", {
|
|
100
|
+
ref,
|
|
101
|
+
style: {
|
|
102
|
+
position: "absolute",
|
|
103
|
+
...layout.content,
|
|
104
|
+
background: paint("page-background", look.background),
|
|
105
|
+
transform: layout.turn ?? void 0,
|
|
106
|
+
userSelect: "none",
|
|
107
|
+
WebkitUserSelect: "none"
|
|
108
|
+
},
|
|
109
|
+
children: [/* @__PURE__ */ jsx(PointerSurface, {}), children]
|
|
110
|
+
}),
|
|
111
|
+
pageChrome
|
|
112
|
+
]
|
|
113
|
+
})
|
|
109
114
|
})
|
|
110
115
|
})
|
|
111
116
|
})
|
package/dist/page-view.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-view.js","names":[],"sources":["../src/page-view.tsx"],"sourcesContent":["/**\n * <PageView> — a single page surface with NO Stage.\n *\n * Same layers + rotation + chrome frame as a `<Stage>` page, but no\n * camera/scroll/zoom and, crucially, NO dependency on `@embedpdf/plugin-stage`.\n * It builds its own `PageTransform` from a target content width and shares the\n * exact `PageContext` seam, so every layer (RenderLayer, AnnotationLayer, …)\n * works here identically — and it provides the measured `ViewProjector`, so\n * anchored UI (`<AnnotationMenu>`, `<SelectionMenu>`) works here too, portalled\n * and clipping-immune.\n */\nimport * as React from 'react';\nimport { useId, useMemo, useRef } from 'react';\nimport { NO_FRAME, pageTransform, type PageFrame } from '@embedpdf/core-geometry';\nimport { observeClientGeometry } from '@embedpdf/web';\nimport { ProjectorProvider, type ProjectorBinding, type ViewProjector } from './anchored';\nimport {\n DocumentScope,\n makePageContext,\n PageProvider,\n useActiveDocumentId,\n useKernel,\n} from './runtime';\n\nexport interface PageViewProps {\n page: number;\n /** Which document to show. Defaults to the active document. */\n documentId?: string;\n /** Target width for the page CONTENT; the display box is the rotated footprint. */\n width?: number;\n /** Reserved chrome bands around the page (screen px) — same model as `<Stage>`. */\n pageFrame?: PageFrame;\n /** Page-space content (rotates with the page). */\n children: React.ReactNode;\n /** Box-space chrome (label, border, …) — never rotated. Mirrors `<Stage pageChrome>`. */\n pageChrome?: React.ReactNode;\n style?: React.CSSProperties;\n}\n\n/** A single page surface with NO Stage — same layers + rotation + chrome frame,\n * no camera/scroll/zoom. */\nexport function PageView({\n page,\n documentId,\n width = 240,\n pageFrame = NO_FRAME,\n children,\n pageChrome,\n style,\n}: PageViewProps) {\n const kernel = useKernel();\n const active = useActiveDocumentId();\n const ref = useRef<HTMLDivElement>(null);\n const docId = documentId ?? active;\n const meta = docId ? kernel.getState().core.documents[docId] : undefined;\n const base = meta?.pages[page];\n const pon = base?.pageObjectNumber ?? page + 1;\n const rotation = base?.rotation ?? 0;\n const dpr = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;\n // Standalone (no Stage/camera): build the page's transform from the target\n // content `width` directly. `scale` is view px per point = width / pageWidthPts.\n const transform = useMemo(\n () =>\n pageTransform({\n pageSize: base\n ? { width: base.size.width, height: base.size.height }\n : { width: 1, height: 1 },\n rotation,\n scale: base ? width / base.size.width : 1,\n // Physical 100% on the web: 1pt = 96/72 CSS px, times the page's\n // /UserUnit — so `transform.zoom` is meaningful even without a Stage\n // (a thumbnail-sized PageView reads as zoomed out, as it should).\n baseScale: (96 / 72) * (base?.userUnit ?? 1),\n dpr,\n }),\n [base?.size.width, base?.size.height, base?.userUnit, rotation, width, dpr],\n );\n // This instance's VIEW identity: two PageViews of the same page (a compare\n // strip) must plan rasters independently, like two stage lenses do.\n const viewId = useId();\n const ctx = useMemo(\n () =>\n makePageContext(\n docId ?? '',\n `page-view:${viewId}`,\n pon,\n page,\n pageFrame,\n transform,\n () => ref.current!.getBoundingClientRect(),\n ),\n [docId, pon, page, pageFrame, transform, viewId],\n );\n // The PageView's ViewProjector: no camera, so anchored UI positions by\n // MEASURING the DOM (client space → portal + position:fixed, immune to\n // ancestor overflow clipping). `toScreen` answers null until the page\n // element has committed — <Anchored> forces one post-commit pass to pick\n // it up. The binding's revision covers state-driven changes (a new\n // transform/page); `observeClientGeometry` covers the genuinely\n // browser-driven ones (document scroll, window resize) that no state\n // change announces.\n const projector = useMemo<ViewProjector>(\n () => ({\n space: 'client',\n toScreen: (p, rect) => (p === ctx.pon && ref.current ? ctx.toClientRect(rect) : null),\n toScreenPoint: (p, at) => (p === ctx.pon && ref.current ? ctx.toClientPoint(at) : null),\n viewEnv: (p) =>\n p === ctx.pon\n ? {\n scale: ctx.transform.viewScale,\n rotation: ctx.transform.rotation,\n zoom: ctx.transform.zoom,\n }\n : null,\n }),\n [ctx],\n );\n const projectorBinding = useMemo<ProjectorBinding>(\n () => ({ projector, revision: ctx, subscribe: observeClientGeometry }),\n [projector, ctx],\n );\n if (!docId || !meta || !base) return null;\n const t = transform;\n const outerW = t.viewWidth + pageFrame.left + pageFrame.right;\n const outerH = t.viewHeight + pageFrame.top + pageFrame.bottom;\n const contentLeft = pageFrame.left + (t.viewWidth - t.contentWidth) / 2;\n const contentTop = pageFrame.top + (t.viewHeight - t.contentHeight) / 2;\n return (\n <DocumentScope id={docId}>\n <ProjectorProvider value={projectorBinding}>\n <div style={{ position: 'relative', width: outerW, height: outerH, ...style }}>\n <PageProvider value={ctx}>\n {/* drop shadow ONLY — transparent, axis-aligned, can't leak behind the bitmap */}\n <div\n style={{\n position: 'absolute',\n left: pageFrame.left,\n top: pageFrame.top,\n width: t.viewWidth,\n height: t.viewHeight,\n boxShadow: 'var(--epdf-page-shadow, 0 6px 18px rgba(0,0,0,.18))',\n }}\n />\n {/* white backing + content as ONE box; rotation 0 carries no transform */}\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 userSelect: 'none',\n WebkitUserSelect: 'none',\n }}\n >\n {children}\n </div>\n {pageChrome}\n </PageProvider>\n </div>\n </ProjectorProvider>\n </DocumentScope>\n );\n}\n"],"mappings":";;;;;;;;;AAyCA,SAAgB,SAAS,EACvB,MACA,YACA,QAAQ,KACR,YAAY,UACZ,UACA,YACA,SACgB;CAChB,MAAM,SAAS,UAAU;CACzB,MAAM,SAAS,oBAAoB;CACnC,MAAM,M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CAAC,QAAQ,CAAC,MAAM,OAAO;CACrC,MAAM,IAAI;CACV,MAAM,SAAS,EAAE,YAAY,UAAU,OAAO,UAAU;CACxD,MAAM,SAAS,EAAE,aAAa,UAAU,MAAM,UAAU;CACxD,MAAM,cAAc,UAAU,QAAQ,EAAE,YAAY,EAAE,gBAAgB;CACtE,MAAM,aAAa,UAAU,OAAO,EAAE,aAAa,EAAE,iBAAiB;CACtE,OACE,oBAAC,eAAD;EAAe,IAAI;EACjB,UAAA,oBAAC,mBAAD;GAAmB,OAAO;GAC1B,UAAA,oBAAC,OAAD;IAAK,OAAO;KAAE,UAAU;KAAY,OAAO;KAAQ,QAAQ;KAAQ,GAAG;IAAM;IAC1E,UAAA,qBAAC,cAAD;KAAc,OAAO;KAArB,UAAA;MAEE,oBAAC,OAAD,EACE,OAAO;OACL,UAAU;OACV,MAAM,UAAU;OAChB,KAAK,UAAU;OACf,OAAO,EAAE;OACT,QAAQ,EAAE;OACV,WAAW;MACb,EACD,CAAA;MAED,oBAAC,OAAD;OACO;OACL,OAAO;QACL,UAAU;QACV,MAAM;QACN,KAAK;QACL,OAAO,EAAE;QACT,QAAQ,EAAE;QACV,YAAY;QACZ,WAAW,WAAW,UAAU,SAAS,QAAQ,KAAA;QACjD,YAAY;QACZ,kBAAkB;OACpB;OAEC;MACE,CAAA;MACJ;KACW;;GACX,CAAA;EACc,CAAA;CACN,CAAA;AAEnB"}
|
|
1
|
+
{"version":3,"file":"page-view.js","names":["InteractionHostToken"],"sources":["../src/page-view.tsx"],"sourcesContent":["/**\n * <PageView> — a single page surface with no Stage.\n *\n * Same layers + rotation + chrome frame as a `<Stage>` page, but no\n * camera/scroll/zoom and, crucially, no dependency on `@embedpdf/plugin-stage`.\n * It builds its own `PageTransform` from a target content width and shares the\n * exact `PageContext` seam, so every layer (RenderLayer, AnnotationLayer, …)\n * works here identically — and it provides the measured `ViewProjector`, so\n * anchored UI (`<AnnotationMenu>`, `<SelectionMenu>`) works here too, portalled\n * and clipping-immune. With the interaction plugin registered it is also the\n * page's pointer surface, so tools (text selection, annotation editing) work in\n * it as they do on a Stage page.\n */\nimport * as React from 'react';\nimport { useId, useMemo, useRef } from 'react';\nimport { toPageRef } from '@embedpdf/core';\nimport type { PageRef } from '@embedpdf/core';\nimport { NO_FRAME, pageTransform, type PageFrame } from '@embedpdf/core-geometry';\nimport {\n clientPageProjector,\n makePageContext,\n observeClientGeometry,\n pageSurfaceLayout,\n pageViewTransformInput,\n paint,\n} from '@embedpdf/web';\nimport { InteractionToken as InteractionHostToken } from '@embedpdf/plugin-interaction/contract/host';\nimport {\n ProjectorProvider,\n ShownPagesProvider,\n type ProjectorBinding,\n type ShownPages,\n type ViewProjector,\n} from './anchored';\nimport { PagePointerSource } from './interaction';\nimport {\n DocumentScope,\n PageProvider,\n useDocumentId,\n useKernelValue,\n useOptionalCapability,\n useViewerSettings,\n} from './runtime';\n\n/**\n * The page's pointer surface, when the interaction plugin is registered. It sits\n * below the layers, like the Stage's own listener: a press on a layer that lets\n * the pointer through (the picture, the selection highlight) reaches the tools,\n * and a control that takes its own presses (a link, a form field) keeps them.\n */\nfunction PointerSurface() {\n const interaction = useOptionalCapability(InteractionHostToken);\n return interaction ? <PagePointerSource /> : null;\n}\n\nexport interface PageViewProps {\n /** The page: its `ref`, which follows it when pages move, or its index, from 0. */\n page: PageRef | number;\n /** Which document to show. Defaults to the one a `<DocumentScope>` names, else the active one. */\n documentId?: string;\n /** Shown while the document or the page is not available yet (default: nothing). */\n fallback?: React.ReactNode;\n /** The width of the page, in pixels; the display box is the rotated footprint. Default 240. */\n width?: number;\n /** Space reserved around the page for your own labels, in pixels per side; the sides left out are 0. */\n pageFrame?: Partial<PageFrame>;\n /** Page-space content (rotates with the page). */\n children: React.ReactNode;\n /** Box-space chrome (label, border, …) — never rotated. Mirrors `<Stage pageChrome>`. */\n pageChrome?: React.ReactNode;\n /** On the outer box. */\n className?: string;\n /** On the outer box. */\n style?: React.CSSProperties;\n}\n\n/** A single page surface with no Stage — same layers + rotation + chrome frame,\n * no camera/scroll/zoom. */\nexport function PageView({\n page: wanted,\n documentId,\n fallback = null,\n width = 240,\n pageFrame: framePatch,\n children,\n pageChrome,\n className,\n style,\n}: PageViewProps) {\n const wantedRef = typeof wanted === 'number' ? null : wanted;\n const wantedIndex = typeof wanted === 'number' ? wanted : null;\n // The sides left out reserve nothing; memoized by value so the context stays stable.\n const { top = 0, right = 0, bottom = 0, left = 0 } = framePatch ?? NO_FRAME;\n const pageFrame = useMemo<PageFrame>(\n () => ({ top, right, bottom, left }),\n [top, right, bottom, left],\n );\n const inScope = useDocumentId();\n const ref = useRef<HTMLDivElement>(null);\n const docId = documentId ?? inScope;\n // The page-registry entry, subscribed: a rotate or a reorder re-renders\n // this surface like it re-renders a Stage page. Entries are reference-\n // stable per page in the registry, so identity is the right equality.\n const wantedPageObjectNumber = wantedRef?.objectNumber ?? null;\n const base = useKernelValue((kernel) => {\n if (!docId) return null;\n const pages = kernel.documents.listPages(docId);\n const found =\n wantedPageObjectNumber !== null\n ? pages.find((pageInfo) => pageInfo.ref.objectNumber === wantedPageObjectNumber)\n : pages[wantedIndex ?? 0];\n return found ?? null;\n });\n const page = base?.index ?? wantedIndex ?? 0;\n // The page's address is the kernel's (`PageLayout.ref`); a placeholder\n // (object number = 1-based index) only until the layout is known — the\n // surface renders the fallback before that anyway. Memoized by the number so\n // the context's `ref` stays identity-stable across re-renders (layers key\n // effects on it).\n const pageObjectNumber = base?.ref.objectNumber ?? wantedPageObjectNumber ?? page + 1;\n const pageRef = useMemo(() => toPageRef(pageObjectNumber), [pageObjectNumber]);\n const dpr = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;\n // Standalone (no Stage/camera): build the page's transform from the target\n // content `width` directly. Memoized by value: a new registry entry for an\n // unchanged page keeps the transform.\n const transform = useMemo(\n () => pageTransform(pageViewTransformInput(base, width, dpr)),\n // eslint-disable-next-line react-hooks/exhaustive-deps -- `base` by the values it gives\n [base?.size.width, base?.size.height, base?.userUnit, base?.rotation, width, dpr],\n );\n // This instance's view identity: two PageViews of the same page (a compare\n // strip) must plan rasters independently, like two stage lenses do.\n const viewId = useId();\n const ctx = useMemo(\n () =>\n makePageContext(docId ?? '', `page-view:${viewId}`, pageRef, page, pageFrame, transform, () =>\n ref.current!.getBoundingClientRect(),\n ),\n [docId, pageRef, page, pageFrame, transform, viewId],\n );\n // The PageView's ViewProjector: no camera, so anchored UI positions by\n // measuring the DOM (client space → portal + position:fixed, immune to\n // ancestor overflow clipping). `toScreen` answers null until the page\n // element has committed — <Anchored> forces one post-commit pass to pick\n // it up. The binding's revision covers state-driven changes (a new\n // transform/page); `observeClientGeometry` covers the genuinely\n // browser-driven ones (document scroll, window resize) that no state\n // change announces.\n const projector = useMemo<ViewProjector>(\n () => clientPageProjector(ctx, () => ref.current !== null),\n [ctx],\n );\n const projectorBinding = useMemo<ProjectorBinding>(\n () => ({ projector, revision: ctx, subscribe: observeClientGeometry }),\n [projector, ctx],\n );\n // A PageView shows its one page.\n const shownPages = useMemo<ShownPages>(\n () => new Set([ctx.ref.objectNumber]),\n [ctx.ref.objectNumber],\n );\n // The viewer's `page` settings; `--epdf-page-*` CSS variables win over them.\n const look = useViewerSettings((settings) => settings.page);\n if (!docId || !base) return <>{fallback}</>;\n // The outer box (page and frame), the shadow at the footprint, and the turned content box.\n const layout = pageSurfaceLayout(transform, pageFrame);\n return (\n <DocumentScope id={docId}>\n <ShownPagesProvider value={shownPages}>\n <ProjectorProvider value={projectorBinding}>\n <div\n className={className}\n style={{\n position: 'relative',\n width: layout.outer.width,\n height: layout.outer.height,\n ...style,\n }}\n >\n <PageProvider value={ctx}>\n {/* drop shadow ONLY — transparent, axis-aligned, can't leak behind the bitmap */}\n <div\n style={{\n position: 'absolute',\n ...layout.shadow,\n boxShadow: paint('page-shadow', look.shadow),\n }}\n />\n {/* white backing + content as ONE box; rotation 0 carries no transform */}\n <div\n ref={ref}\n style={{\n position: 'absolute',\n ...layout.content,\n background: paint('page-background', look.background),\n transform: layout.turn ?? undefined,\n userSelect: 'none',\n WebkitUserSelect: 'none',\n }}\n >\n <PointerSurface />\n {children}\n </div>\n {pageChrome}\n </PageProvider>\n </div>\n </ProjectorProvider>\n </ShownPagesProvider>\n </DocumentScope>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkDA,SAAS,iBAAiB;CAExB,OADoB,sBAAsBA,gBACzB,IAAI,oBAAC,mBAAD,CAAoB,CAAA,IAAI;AAC/C;;;AAyBA,SAAgB,SAAS,EACvB,MAAM,QACN,YACA,WAAW,MACX,QAAQ,KACR,WAAW,YACX,UACA,YACA,WACA,SACgB;CAChB,MAAM,YAAY,OAAO,WAAW,WAAW,OAAO;CACtD,MAAM,cAAc,OAAO,WAAW,WAAW,SAAS;CAE1D,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,MAAM,cAAc;CACnE,MAAM,YAAY,eACT;EAAE;EAAK;EAAO;EAAQ;CAAK,IAClC;EAAC;EAAK;EAAO;EAAQ;CAAI,CAC3B;CACA,MAAM,UAAU,cAAc;CAC9B,MAAM,MAAM,OAAuB,IAAI;CACvC,MAAM,QAAQ,cAAc;CAI5B,MAAM,yBAAyB,WAAW,gBAAgB;CAC1D,MAAM,OAAO,gBAAgB,WAAW;EACtC,IAAI,CAAC,OAAO,OAAO;EACnB,MAAM,QAAQ,OAAO,UAAU,UAAU,KAAK;EAK9C,QAHE,2BAA2B,OACvB,MAAM,MAAM,aAAa,SAAS,IAAI,iBAAiB,sBAAsB,IAC7E,MAAM,eAAe,OACX;CAClB,CAAC;CACD,MAAM,OAAO,MAAM,SAAS,eAAe;CAM3C,MAAM,mBAAmB,MAAM,IAAI,gBAAgB,0BAA0B,OAAO;CACpF,MAAM,UAAU,cAAc,UAAU,gBAAgB,GAAG,CAAC,gBAAgB,CAAC;CAC7E,MAAM,MAAM,OAAO,WAAW,cAAc,OAAO,oBAAoB,IAAI;CAI3E,MAAM,YAAY,cACV,cAAc,uBAAu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