@embedpdf/react 3.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/LICENSE +192 -0
  2. package/dist/AnnotationListSnapshot-W0RCsyDE-dWna4TTJ.d.cts +2593 -0
  3. package/dist/AnnotationListSnapshot-W0RCsyDE-dWna4TTJ.d.ts +2593 -0
  4. package/dist/annotation-B6jwfTCh.d.cts +173 -0
  5. package/dist/annotation-Ct6dFtzJ.cjs +913 -0
  6. package/dist/annotation-Ct6dFtzJ.cjs.map +1 -0
  7. package/dist/annotation-DjGWJljY.js +829 -0
  8. package/dist/annotation-DjGWJljY.js.map +1 -0
  9. package/dist/annotation-menu.cjs +115 -0
  10. package/dist/annotation-menu.cjs.map +1 -0
  11. package/dist/annotation-menu.d.cts +7 -0
  12. package/dist/annotation-menu.d.ts +7 -0
  13. package/dist/annotation-menu.js +99 -0
  14. package/dist/annotation-menu.js.map +1 -0
  15. package/dist/annotation-nUMefyjw.d.ts +173 -0
  16. package/dist/annotation.cjs +25 -0
  17. package/dist/annotation.d.cts +3 -0
  18. package/dist/annotation.d.ts +3 -0
  19. package/dist/annotation.js +4 -0
  20. package/dist/commands.cjs +59 -0
  21. package/dist/commands.cjs.map +1 -0
  22. package/dist/commands.d.cts +20 -0
  23. package/dist/commands.d.ts +20 -0
  24. package/dist/commands.js +47 -0
  25. package/dist/commands.js.map +1 -0
  26. package/dist/form.cjs +560 -0
  27. package/dist/form.cjs.map +1 -0
  28. package/dist/form.d.cts +52 -0
  29. package/dist/form.d.ts +52 -0
  30. package/dist/form.js +545 -0
  31. package/dist/form.js.map +1 -0
  32. package/dist/i18n.cjs +52 -0
  33. package/dist/i18n.cjs.map +1 -0
  34. package/dist/i18n.d.cts +30 -0
  35. package/dist/i18n.d.ts +30 -0
  36. package/dist/i18n.js +42 -0
  37. package/dist/i18n.js.map +1 -0
  38. package/dist/index.cjs +240 -0
  39. package/dist/index.d.cts +37 -0
  40. package/dist/index.d.ts +37 -0
  41. package/dist/index.js +37 -0
  42. package/dist/interaction.cjs +152 -0
  43. package/dist/interaction.cjs.map +1 -0
  44. package/dist/interaction.d.cts +46 -0
  45. package/dist/interaction.d.ts +46 -0
  46. package/dist/interaction.js +139 -0
  47. package/dist/interaction.js.map +1 -0
  48. package/dist/link.cjs +108 -0
  49. package/dist/link.cjs.map +1 -0
  50. package/dist/link.d.cts +16 -0
  51. package/dist/link.d.ts +16 -0
  52. package/dist/link.js +98 -0
  53. package/dist/link.js.map +1 -0
  54. package/dist/metadata.cjs +25 -0
  55. package/dist/metadata.cjs.map +1 -0
  56. package/dist/metadata.d.cts +11 -0
  57. package/dist/metadata.d.ts +11 -0
  58. package/dist/metadata.js +16 -0
  59. package/dist/metadata.js.map +1 -0
  60. package/dist/page-edit.cjs +20 -0
  61. package/dist/page-edit.cjs.map +1 -0
  62. package/dist/page-edit.d.cts +7 -0
  63. package/dist/page-edit.d.ts +7 -0
  64. package/dist/page-edit.js +11 -0
  65. package/dist/page-edit.js.map +1 -0
  66. package/dist/page-view.cjs +107 -0
  67. package/dist/page-view.cjs.map +1 -0
  68. package/dist/page-view.d.cts +23 -0
  69. package/dist/page-view.d.ts +23 -0
  70. package/dist/page-view.js +95 -0
  71. package/dist/page-view.js.map +1 -0
  72. package/dist/redaction.cjs +35 -0
  73. package/dist/redaction.cjs.map +1 -0
  74. package/dist/redaction.d.cts +14 -0
  75. package/dist/redaction.d.ts +14 -0
  76. package/dist/redaction.js +25 -0
  77. package/dist/redaction.js.map +1 -0
  78. package/dist/render.cjs +142 -0
  79. package/dist/render.cjs.map +1 -0
  80. package/dist/render.d.cts +32 -0
  81. package/dist/render.d.ts +32 -0
  82. package/dist/render.js +131 -0
  83. package/dist/render.js.map +1 -0
  84. package/dist/rolldown-runtime-DDXJien1.cjs +50 -0
  85. package/dist/runtime-CMxIuF2O.d.cts +195 -0
  86. package/dist/runtime-DV98q7I0.d.ts +195 -0
  87. package/dist/runtime.cjs +314 -0
  88. package/dist/runtime.cjs.map +1 -0
  89. package/dist/runtime.d.cts +3 -0
  90. package/dist/runtime.d.ts +3 -0
  91. package/dist/runtime.js +287 -0
  92. package/dist/runtime.js.map +1 -0
  93. package/dist/scrollbar.cjs +241 -0
  94. package/dist/scrollbar.cjs.map +1 -0
  95. package/dist/scrollbar.d.cts +42 -0
  96. package/dist/scrollbar.d.ts +42 -0
  97. package/dist/scrollbar.js +213 -0
  98. package/dist/scrollbar.js.map +1 -0
  99. package/dist/search.cjs +70 -0
  100. package/dist/search.cjs.map +1 -0
  101. package/dist/search.d.cts +35 -0
  102. package/dist/search.d.ts +35 -0
  103. package/dist/search.js +58 -0
  104. package/dist/search.js.map +1 -0
  105. package/dist/selection.cjs +60 -0
  106. package/dist/selection.cjs.map +1 -0
  107. package/dist/selection.d.cts +12 -0
  108. package/dist/selection.d.ts +12 -0
  109. package/dist/selection.js +49 -0
  110. package/dist/selection.js.map +1 -0
  111. package/dist/shell.cjs +57 -0
  112. package/dist/shell.cjs.map +1 -0
  113. package/dist/shell.d.cts +27 -0
  114. package/dist/shell.d.ts +27 -0
  115. package/dist/shell.js +46 -0
  116. package/dist/shell.js.map +1 -0
  117. package/dist/stage.cjs +343 -0
  118. package/dist/stage.cjs.map +1 -0
  119. package/dist/stage.d.cts +104 -0
  120. package/dist/stage.d.ts +104 -0
  121. package/dist/stage.js +327 -0
  122. package/dist/stage.js.map +1 -0
  123. package/dist/stamp.cjs +76 -0
  124. package/dist/stamp.cjs.map +1 -0
  125. package/dist/stamp.d.cts +28 -0
  126. package/dist/stamp.d.ts +28 -0
  127. package/dist/stamp.js +63 -0
  128. package/dist/stamp.js.map +1 -0
  129. package/dist/toolbar.cjs +515 -0
  130. package/dist/toolbar.cjs.map +1 -0
  131. package/dist/toolbar.d.cts +100 -0
  132. package/dist/toolbar.d.ts +100 -0
  133. package/dist/toolbar.js +505 -0
  134. package/dist/toolbar.js.map +1 -0
  135. package/dist/views.cjs +35 -0
  136. package/dist/views.cjs.map +1 -0
  137. package/dist/views.d.cts +21 -0
  138. package/dist/views.d.ts +21 -0
  139. package/dist/views.js +26 -0
  140. package/dist/views.js.map +1 -0
  141. package/package.json +158 -0
@@ -0,0 +1,195 @@
1
+ import { AnyPlugin, CapabilityToken, Engine, EngineFactory, InitialDocument, Kernel } from "@embedpdf/core";
2
+ import * as React from "react";
3
+ import { PageFrame, PageTransform, Point, Rect } from "@embedpdf/core-geometry";
4
+ import { PageViewDemand } from "@embedpdf/plugin-render";
5
+ //#region src/runtime.d.ts
6
+ declare function useKernel(): Kernel;
7
+ declare const shallowArray: <T>(a: readonly T[], b: readonly T[]) => boolean;
8
+ /** Read a value derived from the kernel, cached by equality (no tearing loop). */
9
+ declare function useKernelValue<R>(select: (k: Kernel) => R, isEqual?: (a: R, b: R) => boolean): R;
10
+ declare function useActiveDocumentId(): string | null;
11
+ /** The document id for this subtree: the nearest <DocumentScope>, else the active doc. */
12
+ declare function useDocumentId(): string | null;
13
+ interface DocumentScopeProps {
14
+ id: string;
15
+ children: React.ReactNode;
16
+ }
17
+ /** Bind a subtree to a specific document (panes, comparison). */
18
+ declare function DocumentScope({ id, children }: DocumentScopeProps): import("react/jsx-runtime").JSX.Element;
19
+ interface DocumentGateProps {
20
+ /** Shown while this subtree has NO document (empty workspace, docs still opening). */
21
+ fallback?: React.ReactNode;
22
+ children: React.ReactNode;
23
+ }
24
+ /**
25
+ * Render children only while this subtree has a READY document — the
26
+ * structural way to say "this UI is defined over a document". An empty
27
+ * workspace is a legitimate, designable state (the Viewer no longer blocks on
28
+ * documents so chrome can render at t≈0): workspace-scoped UI (toolbars,
29
+ * commands, i18n) lives OUTSIDE the gate; document-scoped UI (Stage, panels,
30
+ * page chrome) lives inside it, or reads through `useOptionalSelector`.
31
+ * A `loading`/`locked`/`error` tab renders `fallback` — so the gate's
32
+ * fallback doubles as the per-tab boot state; richer chrome (a password
33
+ * prompt, an error pane) branches on `useDocumentStatus()` beside the gate.
34
+ * Sibling of <DocumentScope>, which picks WHICH document; this one handles
35
+ * WHETHER.
36
+ */
37
+ declare function DocumentGate({ fallback, children }: DocumentGateProps): import("react/jsx-runtime").JSX.Element;
38
+ /** Lifecycle status of this subtree's document (loading/locked/ready/error),
39
+ * or null with no document. The password prompt and error panes key off it. */
40
+ declare function useDocumentStatus(): import("@embedpdf/core").DocStatus | null;
41
+ /**
42
+ * Resolve a capability by token, binding document-scoped ones to this
43
+ * subtree's document. Resolution is a REACTIVE read (`tryCapability` through
44
+ * the kernel's one change stream), not a memoized call — under the
45
+ * request-time lifecycle a document can become resolvable while its id stays
46
+ * the same, so any id-keyed cache goes stale; subscribing makes staleness
47
+ * structurally impossible. Fail-fast: while unresolvable, this re-runs the
48
+ * strict resolver so the kernel's truthful reason (`no capability` / `no
49
+ * document` / `document is loading|locked`) is what throws.
50
+ */
51
+ declare function useCapability<T>(token: CapabilityToken<T>): T;
52
+ /** Like `useCapability`, but null while the token can't resolve (no plugin,
53
+ * no document, or a document that isn't ready yet). */
54
+ declare function useOptionalCapability<T>(token: CapabilityToken<T>): T | null;
55
+ /** Subscribe to a selector over a (document-resolved) capability. */
56
+ declare function useSelector<C, R>(token: CapabilityToken<C>, select: (cap: C) => R, isEqual?: (a: R, b: R) => boolean): R;
57
+ /**
58
+ * Null-safe `useSelector`: `fallback` whenever the token can't resolve — no
59
+ * provider, or a document-scoped token with no document. For chrome that stays
60
+ * mounted across the empty-workspace state (a zoom readout, a mode band).
61
+ * `useSelector` stays strict (fail-fast) for code that KNOWS a document exists
62
+ * — e.g. anything inside a <DocumentGate>.
63
+ *
64
+ * The `select` guard also swallows reads through a capability whose document
65
+ * closed between the store notification and this render — that teardown race
66
+ * resolves to `fallback` for one frame, then re-renders against the new state.
67
+ */
68
+ declare function useOptionalSelector<C, R>(token: CapabilityToken<C>, select: (cap: C) => R, fallback: R, isEqual?: (a: R, b: R) => boolean): R;
69
+ /** The document registry (open/close/active/list), reactive. */
70
+ declare function useDocuments(): {
71
+ docs: import("@embedpdf/core").DocInfo[];
72
+ activeId: string | null;
73
+ open: (input: import("@embedpdf/core").OpenSource, options?: import("@embedpdf/core").OpenDocumentOptions) => Promise<string>;
74
+ unlock: (id: string, input: {
75
+ password: string;
76
+ }) => Promise<void>;
77
+ close: (id: string) => Promise<void>;
78
+ setActive: (id: string) => void;
79
+ move: (id: string, toIndex: number) => void;
80
+ swap: (a: string, b: string) => void;
81
+ download: (id?: string, opts?: {
82
+ mode?: import("@embedpdf/core").PdfSaveMode;
83
+ }) => Promise<Uint8Array>;
84
+ downloadLayer: (id?: string) => Promise<Uint8Array>;
85
+ };
86
+ interface ViewerProps {
87
+ /**
88
+ * The engine, as an instance or a thunk. Engines construct synchronously and
89
+ * boot lazily (`localEngine()` allocates nothing until first use), so
90
+ * ownership follows the SHAPE of what you pass:
91
+ *
92
+ * - An **instance** (`engine={engine}`) is BORROWED: the Viewer uses it and
93
+ * never destroys it, because you acquired it and therefore own it. The
94
+ * common path — a module-scope `const engine = localEngine()` shared
95
+ * across viewers and route changes. The Viewer calls `engine.warmup?.()`
96
+ * on mount so the boot overlaps app initialization.
97
+ * - A **thunk** (`engine={() => localEngine()}`) is VIEWER-OWNED: the
98
+ * Viewer calls it on mount and `destroy()`s the result on unmount. Use it
99
+ * for per-mount isolation (StrictMode/HMR-clean teardown, independent
100
+ * multi-viewer engines).
101
+ *
102
+ * Init-only: captured on first render; later identity changes are ignored (dev warns).
103
+ */
104
+ engine: Engine | EngineFactory;
105
+ /** Init-only: captured on first render; later identity changes are ignored (dev warns). */
106
+ plugins: AnyPlugin[];
107
+ /** Documents to open on startup (with optional tab names). Init-only. */
108
+ initialDocuments?: InitialDocument[];
109
+ fallback?: React.ReactNode;
110
+ /** Rendered when kernel construction or `start()` fails. Without it a boot
111
+ * failure renders nothing — but never a silent forever-fallback. */
112
+ renderError?: (error: unknown) => React.ReactNode;
113
+ children: React.ReactNode;
114
+ }
115
+ /**
116
+ * Owns the kernel as an EFFECT-scoped resource: each effect setup creates and
117
+ * starts exactly one kernel; each cleanup destroys exactly that one. That is
118
+ * the contract StrictMode exercises (two kernels in dev, the first fully
119
+ * destroyed) — the kernel itself is never restarted after destroy.
120
+ *
121
+ * The kernel is published to context the moment it exists — before `start()`
122
+ * resolves — so the `fallback` can use workspace capabilities (i18n copy on a
123
+ * loading screen) exactly as before. The one exception is the very first
124
+ * render, which happens before the effect: it renders nothing. Children mount
125
+ * once `start()` resolves — which never touches the engine, so the shell is
126
+ * alive while WASM compiles or the transport connects. `initialDocuments`
127
+ * open in the BACKGROUND and stream into the registry (`useDocuments()` is
128
+ * reactive); per-document loading UI is the Stage's job, not a root gate.
129
+ *
130
+ * ENGINE OWNERSHIP. When `engine` is a thunk, the Viewer OWNS it: each effect
131
+ * setup constructs one engine (construction is synchronous and inert — boot
132
+ * happens lazily inside the engine) and each cleanup destroys exactly that one
133
+ * — after the kernel, so handles close first. When `engine` is an instance it
134
+ * is BORROWED and never destroyed here; the Viewer only calls `warmup?.()` so
135
+ * the WASM/transport boot overlaps plugin initialization. StrictMode's
136
+ * double-mount therefore constructs two independent thunk engines and tears
137
+ * the first fully down, matching the kernel's own effect-scoped lifecycle.
138
+ * That means dev-only double resource use (two worker spawns, two font
139
+ * fetches, briefly overlapping) — deliberate, because it is exactly the
140
+ * leak-detection contract StrictMode exists to exercise; production mounts
141
+ * once and boots once.
142
+ */
143
+ declare function Viewer({ engine, plugins, initialDocuments, fallback, renderError, children }: ViewerProps): import("react/jsx-runtime").JSX.Element | null;
144
+ declare const EmbedPDF: typeof Viewer;
145
+ /**
146
+ * PageContext — the seam. A layer depends ONLY on this, never on the Stage. So the
147
+ * same layer works inside a virtualized Stage and in a standalone <PageView>.
148
+ */
149
+ interface PageContextValue {
150
+ documentId: string;
151
+ /** Durable page identity (PDF object number) — use for keys / render / annotations. */
152
+ pon: number;
153
+ /** Display index (page N) — use for ordering / human-facing page numbers. */
154
+ pageIndex: number;
155
+ /**
156
+ * Reserved chrome bands around the page (screen px per side). The page-chrome
157
+ * slot renders into the outer box (content + frame); these thicknesses size
158
+ * the bands — a label in the bottom band is `bottom:0; height: frame.bottom`.
159
+ */
160
+ frame: PageFrame;
161
+ /**
162
+ * The single bridge between PDF points, view px, and device px for this page.
163
+ * Layers do ALL coordinate work through it — `pageToContent` to place content-
164
+ * space overlays, `renderScale`/`deviceWidth` to render, `contentWidth` for
165
+ * page-relative sizing. Never re-derive `x * scale` or `* dpr`.
166
+ */
167
+ transform: PageTransform;
168
+ /** Client (screen) point → PDF point — the one platform-bound hit-test. */
169
+ toPagePoint(clientX: number, clientY: number): Point;
170
+ /** PDF/content point → client (screen) px — the exact inverse of `toPagePoint`
171
+ * (rotation applied). Lets viewport-space UI (e.g. a selection menu) anchor to a
172
+ * page point WITHOUT a Stage camera, so it works the same in `<PageView>`. */
173
+ toClientPoint(p: Point): Point;
174
+ /** PDF/content rect → client (screen) px AABB. Rect analog of `toClientPoint`
175
+ * for upright viewport-space UI that frames a selected page region. */
176
+ toClientRect(rect: Rect): Rect;
177
+ /**
178
+ * The page-view DEMAND for raster planning uses dependency inversion:
179
+ * plugin-render defines the shape; the host that CREATED this
180
+ * context fills it — as a PULL. The Stage host's getter closes over the
181
+ * stage capability and reads `VisiblePage.visibleRect` live at call time
182
+ * (visibility is the STAGE's data; adapters never re-derive camera math or
183
+ * cache a copy). Three states, three meanings: a real sub-rect (visible),
184
+ * a ZERO rect (stage host, page currently off-screen — want nothing), and
185
+ * an undefined getter (stage-less `<PageView>` — whole page visible, which
186
+ * a thumbnail-sized demand turns into "never engages" by arithmetic).
187
+ */
188
+ getViewDemand?: () => PageViewDemand;
189
+ }
190
+ declare const PageProvider: React.Provider<PageContextValue | null>;
191
+ declare function usePage(): PageContextValue;
192
+ declare function makePageContext(documentId: string, pon: number, pageIndex: number, frame: PageFrame, transform: PageTransform, getRect: () => DOMRect, getViewDemand?: () => PageViewDemand): PageContextValue;
193
+ //#endregion
194
+ export { useSelector as S, useKernel as _, EmbedPDF as a, useOptionalSelector as b, Viewer as c, shallowArray as d, useActiveDocumentId as f, useDocuments as g, useDocumentStatus as h, DocumentScopeProps as i, ViewerProps as l, useDocumentId as m, DocumentGateProps as n, PageContextValue as o, useCapability as p, DocumentScope as r, PageProvider as s, DocumentGate as t, makePageContext as u, useKernelValue as v, usePage as x, useOptionalCapability as y };
195
+ //# sourceMappingURL=runtime-DV98q7I0.d.ts.map
@@ -0,0 +1,314 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_rolldown_runtime = require("./rolldown-runtime-DDXJien1.cjs");
3
+ let react_jsx_runtime = require("react/jsx-runtime");
4
+ let _embedpdf_core = require("@embedpdf/core");
5
+ let react = require("react");
6
+ react = require_rolldown_runtime.__toESM(react, 1);
7
+ //#region src/runtime.tsx
8
+ const KernelCtx = (0, react.createContext)(null);
9
+ /** The document a subtree is bound to. null => use the active document. */
10
+ const DocumentScopeCtx = (0, react.createContext)(null);
11
+ function useKernel() {
12
+ const k = (0, react.useContext)(KernelCtx);
13
+ if (!k) throw new Error("useKernel must be used within <Viewer>/<EmbedPDF>");
14
+ return k;
15
+ }
16
+ const shallowArray = (a, b) => a === b || a.length === b.length && a.every((x, i) => x === b[i]);
17
+ /** Read a value derived from the kernel, cached by equality (no tearing loop). */
18
+ function useKernelValue(select, isEqual = Object.is) {
19
+ const kernel = useKernel();
20
+ const last = (0, react.useRef)(null);
21
+ const get = () => {
22
+ const next = select(kernel);
23
+ if (last.current && isEqual(last.current.v, next)) return last.current.v;
24
+ last.current = { v: next };
25
+ return next;
26
+ };
27
+ return (0, react.useSyncExternalStore)(kernel.subscribe, get, get);
28
+ }
29
+ function useActiveDocumentId() {
30
+ return useKernelValue((k) => k.documents.activeId());
31
+ }
32
+ /** The document id for this subtree: the nearest <DocumentScope>, else the active doc. */
33
+ function useDocumentId() {
34
+ const scoped = (0, react.useContext)(DocumentScopeCtx);
35
+ const active = useActiveDocumentId();
36
+ return scoped ?? active;
37
+ }
38
+ /** Bind a subtree to a specific document (panes, comparison). */
39
+ function DocumentScope({ id, children }) {
40
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocumentScopeCtx.Provider, {
41
+ value: id,
42
+ children
43
+ });
44
+ }
45
+ /**
46
+ * Render children only while this subtree has a READY document — the
47
+ * structural way to say "this UI is defined over a document". An empty
48
+ * workspace is a legitimate, designable state (the Viewer no longer blocks on
49
+ * documents so chrome can render at t≈0): workspace-scoped UI (toolbars,
50
+ * commands, i18n) lives OUTSIDE the gate; document-scoped UI (Stage, panels,
51
+ * page chrome) lives inside it, or reads through `useOptionalSelector`.
52
+ * A `loading`/`locked`/`error` tab renders `fallback` — so the gate's
53
+ * fallback doubles as the per-tab boot state; richer chrome (a password
54
+ * prompt, an error pane) branches on `useDocumentStatus()` beside the gate.
55
+ * Sibling of <DocumentScope>, which picks WHICH document; this one handles
56
+ * WHETHER.
57
+ */
58
+ function DocumentGate({ fallback = null, children }) {
59
+ const docId = useDocumentId();
60
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: useKernelValue((k) => docId ? k.documents.get(docId)?.status === "ready" : false) ? children : fallback });
61
+ }
62
+ /** Lifecycle status of this subtree's document (loading/locked/ready/error),
63
+ * or null with no document. The password prompt and error panes key off it. */
64
+ function useDocumentStatus() {
65
+ const docId = useDocumentId();
66
+ return useKernelValue((k) => docId ? k.documents.get(docId)?.status ?? null : null);
67
+ }
68
+ /**
69
+ * Resolve a capability by token, binding document-scoped ones to this
70
+ * subtree's document. Resolution is a REACTIVE read (`tryCapability` through
71
+ * the kernel's one change stream), not a memoized call — under the
72
+ * request-time lifecycle a document can become resolvable while its id stays
73
+ * the same, so any id-keyed cache goes stale; subscribing makes staleness
74
+ * structurally impossible. Fail-fast: while unresolvable, this re-runs the
75
+ * strict resolver so the kernel's truthful reason (`no capability` / `no
76
+ * document` / `document is loading|locked`) is what throws.
77
+ */
78
+ function useCapability(token) {
79
+ const kernel = useKernel();
80
+ const scoped = (0, react.useContext)(DocumentScopeCtx);
81
+ return useKernelValue((k) => k.tryCapability(token, scoped ?? void 0)) ?? kernel.capability(token, scoped ?? void 0);
82
+ }
83
+ /** Like `useCapability`, but null while the token can't resolve (no plugin,
84
+ * no document, or a document that isn't ready yet). */
85
+ function useOptionalCapability(token) {
86
+ const scoped = (0, react.useContext)(DocumentScopeCtx);
87
+ return useKernelValue((k) => k.tryCapability(token, scoped ?? void 0));
88
+ }
89
+ /** Subscribe to a selector over a (document-resolved) capability. */
90
+ function useSelector(token, select, isEqual = Object.is) {
91
+ const kernel = useKernel();
92
+ const cap = useCapability(token);
93
+ const last = (0, react.useRef)(null);
94
+ const get = () => {
95
+ const next = select(cap);
96
+ if (last.current && isEqual(last.current.v, next)) return last.current.v;
97
+ last.current = { v: next };
98
+ return next;
99
+ };
100
+ return (0, react.useSyncExternalStore)(kernel.subscribe, get, get);
101
+ }
102
+ /**
103
+ * Null-safe `useSelector`: `fallback` whenever the token can't resolve — no
104
+ * provider, or a document-scoped token with no document. For chrome that stays
105
+ * mounted across the empty-workspace state (a zoom readout, a mode band).
106
+ * `useSelector` stays strict (fail-fast) for code that KNOWS a document exists
107
+ * — e.g. anything inside a <DocumentGate>.
108
+ *
109
+ * The `select` guard also swallows reads through a capability whose document
110
+ * closed between the store notification and this render — that teardown race
111
+ * resolves to `fallback` for one frame, then re-renders against the new state.
112
+ */
113
+ function useOptionalSelector(token, select, fallback, isEqual = Object.is) {
114
+ const kernel = useKernel();
115
+ const cap = useOptionalCapability(token);
116
+ const last = (0, react.useRef)(null);
117
+ const get = () => {
118
+ let next;
119
+ if (cap === null) next = fallback;
120
+ else try {
121
+ next = select(cap);
122
+ } catch {
123
+ next = fallback;
124
+ }
125
+ if (last.current && isEqual(last.current.v, next)) return last.current.v;
126
+ last.current = { v: next };
127
+ return next;
128
+ };
129
+ return (0, react.useSyncExternalStore)(kernel.subscribe, get, get);
130
+ }
131
+ /** The document registry (open/close/active/list), reactive. */
132
+ function useDocuments() {
133
+ const kernel = useKernel();
134
+ return {
135
+ docs: useKernelValue((k) => k.documents.list(), _embedpdf_core.docInfoListEquals),
136
+ activeId: useActiveDocumentId(),
137
+ open: kernel.documents.open,
138
+ unlock: kernel.documents.unlock,
139
+ close: kernel.documents.close,
140
+ setActive: kernel.documents.setActive,
141
+ move: kernel.documents.move,
142
+ swap: kernel.documents.swap,
143
+ download: kernel.documents.download,
144
+ downloadLayer: kernel.documents.downloadLayer
145
+ };
146
+ }
147
+ /**
148
+ * Owns the kernel as an EFFECT-scoped resource: each effect setup creates and
149
+ * starts exactly one kernel; each cleanup destroys exactly that one. That is
150
+ * the contract StrictMode exercises (two kernels in dev, the first fully
151
+ * destroyed) — the kernel itself is never restarted after destroy.
152
+ *
153
+ * The kernel is published to context the moment it exists — before `start()`
154
+ * resolves — so the `fallback` can use workspace capabilities (i18n copy on a
155
+ * loading screen) exactly as before. The one exception is the very first
156
+ * render, which happens before the effect: it renders nothing. Children mount
157
+ * once `start()` resolves — which never touches the engine, so the shell is
158
+ * alive while WASM compiles or the transport connects. `initialDocuments`
159
+ * open in the BACKGROUND and stream into the registry (`useDocuments()` is
160
+ * reactive); per-document loading UI is the Stage's job, not a root gate.
161
+ *
162
+ * ENGINE OWNERSHIP. When `engine` is a thunk, the Viewer OWNS it: each effect
163
+ * setup constructs one engine (construction is synchronous and inert — boot
164
+ * happens lazily inside the engine) and each cleanup destroys exactly that one
165
+ * — after the kernel, so handles close first. When `engine` is an instance it
166
+ * is BORROWED and never destroyed here; the Viewer only calls `warmup?.()` so
167
+ * the WASM/transport boot overlaps plugin initialization. StrictMode's
168
+ * double-mount therefore constructs two independent thunk engines and tears
169
+ * the first fully down, matching the kernel's own effect-scoped lifecycle.
170
+ * That means dev-only double resource use (two worker spawns, two font
171
+ * fetches, briefly overlapping) — deliberate, because it is exactly the
172
+ * leak-detection contract StrictMode exists to exercise; production mounts
173
+ * once and boots once.
174
+ */
175
+ function Viewer({ engine, plugins, initialDocuments, fallback, renderError, children }) {
176
+ const initial = (0, react.useRef)({
177
+ engine,
178
+ plugins,
179
+ initialDocuments
180
+ });
181
+ const warned = (0, react.useRef)(false);
182
+ if (process.env.NODE_ENV !== "production" && !warned.current) {
183
+ if (initial.current.engine !== engine || initial.current.plugins !== plugins) {
184
+ warned.current = true;
185
+ console.warn("[embedpdf] <Viewer> engine/plugins are init-only. A changed identity is ignored — pass stable references (module scope, useState, or useMemo). An inline `plugins={[...]}` array recreates its identity every render.");
186
+ }
187
+ }
188
+ const [boot, setBoot] = (0, react.useState)({
189
+ phase: "booting",
190
+ kernel: null
191
+ });
192
+ (0, react.useEffect)(() => {
193
+ const captured = initial.current;
194
+ const ownsEngine = typeof captured.engine === "function";
195
+ const engine = ownsEngine ? captured.engine() : captured.engine;
196
+ engine.warmup?.();
197
+ let kernel;
198
+ try {
199
+ kernel = (0, _embedpdf_core.createKernel)({
200
+ engine,
201
+ plugins: captured.plugins
202
+ });
203
+ } catch (error) {
204
+ setBoot({
205
+ phase: "error",
206
+ error
207
+ });
208
+ if (ownsEngine) engine.destroy();
209
+ return;
210
+ }
211
+ let alive = true;
212
+ setBoot({
213
+ phase: "booting",
214
+ kernel
215
+ });
216
+ kernel.start().then(() => {
217
+ if (!alive) return;
218
+ setBoot({
219
+ phase: "ready",
220
+ kernel
221
+ });
222
+ kernel.documents.openAll(captured.initialDocuments ?? []);
223
+ }, (error) => {
224
+ if (alive) setBoot({
225
+ phase: "error",
226
+ error
227
+ });
228
+ });
229
+ return () => {
230
+ alive = false;
231
+ kernel.destroy().then(() => {
232
+ if (ownsEngine) engine.destroy();
233
+ });
234
+ };
235
+ }, []);
236
+ if (boot.phase === "error") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: renderError ? renderError(boot.error) : null });
237
+ if (!boot.kernel) return null;
238
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(KernelCtx.Provider, {
239
+ value: boot.kernel,
240
+ children: boot.phase === "ready" ? children : fallback ?? null
241
+ });
242
+ }
243
+ const EmbedPDF = Viewer;
244
+ const PageCtx = (0, react.createContext)(null);
245
+ const PageProvider = PageCtx.Provider;
246
+ function usePage() {
247
+ const c = (0, react.useContext)(PageCtx);
248
+ if (!c) throw new Error("usePage must be used inside <PageView> or a <Stage> page");
249
+ return c;
250
+ }
251
+ function makePageContext(documentId, pon, pageIndex, frame, transform, getRect, getViewDemand) {
252
+ return {
253
+ documentId,
254
+ pon,
255
+ pageIndex,
256
+ frame,
257
+ transform,
258
+ ...getViewDemand ? { getViewDemand } : {},
259
+ toPagePoint: (cx, cy) => {
260
+ const r = getRect();
261
+ return transform.viewToPage({
262
+ x: cx - r.left,
263
+ y: cy - r.top
264
+ });
265
+ },
266
+ toClientPoint: (p) => {
267
+ const r = getRect();
268
+ const v = transform.pageToView(p);
269
+ return {
270
+ x: r.left + v.x,
271
+ y: r.top + v.y
272
+ };
273
+ },
274
+ toClientRect: (rect) => {
275
+ const r = getRect();
276
+ const v = transform.pageToViewRect(rect);
277
+ return {
278
+ x: r.left + v.x,
279
+ y: r.top + v.y,
280
+ width: v.width,
281
+ height: v.height
282
+ };
283
+ }
284
+ };
285
+ }
286
+ //#endregion
287
+ exports.DocumentGate = DocumentGate;
288
+ exports.DocumentScope = DocumentScope;
289
+ exports.EmbedPDF = EmbedPDF;
290
+ exports.PageProvider = PageProvider;
291
+ exports.Viewer = Viewer;
292
+ exports.makePageContext = makePageContext;
293
+ exports.shallowArray = shallowArray;
294
+ exports.useActiveDocumentId = useActiveDocumentId;
295
+ exports.useCapability = useCapability;
296
+ exports.useDocumentId = useDocumentId;
297
+ exports.useDocumentStatus = useDocumentStatus;
298
+ exports.useDocuments = useDocuments;
299
+ exports.useKernel = useKernel;
300
+ exports.useKernelValue = useKernelValue;
301
+ exports.useOptionalCapability = useOptionalCapability;
302
+ exports.useOptionalSelector = useOptionalSelector;
303
+ exports.usePage = usePage;
304
+ exports.useSelector = useSelector;
305
+ Object.keys(_embedpdf_core).forEach(function(k) {
306
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
307
+ enumerable: true,
308
+ get: function() {
309
+ return _embedpdf_core[k];
310
+ }
311
+ });
312
+ });
313
+
314
+ //# sourceMappingURL=runtime.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.cjs","names":["docInfoListEquals"],"sources":["../src/runtime.tsx"],"sourcesContent":["/**\n * @embedpdf/react — the generic binding.\n *\n * Binds the kernel's one change stream to React (useSyncExternalStore), resolves\n * capabilities (document-scoped ones against the active or `<DocumentScope>`-given\n * document), and provides the page coordinate context. Every plugin and layer rides\n * on this — there is no per-plugin framework code.\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/core';\nimport * as React from 'react';\nimport {\n createContext,\n useContext,\n useEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { createKernel, docInfoListEquals } from '@embedpdf/core';\nimport type {\n AnyPlugin,\n CapabilityToken,\n Engine,\n EngineFactory,\n InitialDocument,\n Kernel,\n} from '@embedpdf/core';\n// Pure coordinate math from the geometry base — NOT from stage-core. The\n// PageContext seam stays stage-agnostic (it must also serve standalone PageView).\nimport type { PageFrame, PageTransform, Point, Rect } from '@embedpdf/core-geometry';\nimport type { PageViewDemand } from '@embedpdf/plugin-render';\n\nconst KernelCtx = createContext<Kernel | null>(null);\n/** The document a subtree is bound to. null => use the active document. */\nconst DocumentScopeCtx = createContext<string | null>(null);\n\nexport function useKernel(): Kernel {\n const k = useContext(KernelCtx);\n if (!k) throw new Error('useKernel must be used within <Viewer>/<EmbedPDF>');\n return k;\n}\n\nexport const shallowArray = <T,>(a: readonly T[], b: readonly T[]): boolean =>\n a === b || (a.length === b.length && a.every((x, i) => x === b[i]));\n\n/** Read a value derived from the kernel, cached by equality (no tearing loop). */\nexport function useKernelValue<R>(\n select: (k: Kernel) => R,\n isEqual: (a: R, b: R) => boolean = Object.is,\n): R {\n const kernel = useKernel();\n const last = useRef<{ v: R } | null>(null);\n const get = () => {\n const next = select(kernel);\n if (last.current && isEqual(last.current.v, next)) return last.current.v;\n last.current = { v: next };\n return next;\n };\n return useSyncExternalStore(kernel.subscribe, get, get);\n}\n\nexport function useActiveDocumentId(): string | null {\n return useKernelValue((k) => k.documents.activeId());\n}\n\n/** The document id for this subtree: the nearest <DocumentScope>, else the active doc. */\nexport function useDocumentId(): string | null {\n const scoped = useContext(DocumentScopeCtx);\n const active = useActiveDocumentId();\n return scoped ?? active;\n}\n\nexport interface DocumentScopeProps {\n id: string;\n children: React.ReactNode;\n}\n/** Bind a subtree to a specific document (panes, comparison). */\nexport function DocumentScope({ id, children }: DocumentScopeProps) {\n return <DocumentScopeCtx.Provider value={id}>{children}</DocumentScopeCtx.Provider>;\n}\n\nexport interface DocumentGateProps {\n /** Shown while this subtree has NO document (empty workspace, docs still opening). */\n fallback?: React.ReactNode;\n children: React.ReactNode;\n}\n/**\n * Render children only while this subtree has a READY document — the\n * structural way to say \"this UI is defined over a document\". An empty\n * workspace is a legitimate, designable state (the Viewer no longer blocks on\n * documents so chrome can render at t≈0): workspace-scoped UI (toolbars,\n * commands, i18n) lives OUTSIDE the gate; document-scoped UI (Stage, panels,\n * page chrome) lives inside it, or reads through `useOptionalSelector`.\n * A `loading`/`locked`/`error` tab renders `fallback` — so the gate's\n * fallback doubles as the per-tab boot state; richer chrome (a password\n * prompt, an error pane) branches on `useDocumentStatus()` beside the gate.\n * Sibling of <DocumentScope>, which picks WHICH document; this one handles\n * WHETHER.\n */\nexport function DocumentGate({ fallback = null, children }: DocumentGateProps) {\n const docId = useDocumentId();\n const ready = useKernelValue((k) => (docId ? k.documents.get(docId)?.status === 'ready' : false));\n return <>{ready ? children : fallback}</>;\n}\n\n/** Lifecycle status of this subtree's document (loading/locked/ready/error),\n * or null with no document. The password prompt and error panes key off it. */\nexport function useDocumentStatus() {\n const docId = useDocumentId();\n return useKernelValue((k) => (docId ? (k.documents.get(docId)?.status ?? null) : null));\n}\n\n/**\n * Resolve a capability by token, binding document-scoped ones to this\n * subtree's document. Resolution is a REACTIVE read (`tryCapability` through\n * the kernel's one change stream), not a memoized call — under the\n * request-time lifecycle a document can become resolvable while its id stays\n * the same, so any id-keyed cache goes stale; subscribing makes staleness\n * structurally impossible. Fail-fast: while unresolvable, this re-runs the\n * strict resolver so the kernel's truthful reason (`no capability` / `no\n * document` / `document is loading|locked`) is what throws.\n */\nexport function useCapability<T>(token: CapabilityToken<T>): T {\n const kernel = useKernel();\n const scoped = useContext(DocumentScopeCtx);\n const cap = useKernelValue((k) => k.tryCapability(token, scoped ?? undefined));\n return cap ?? kernel.capability(token, scoped ?? undefined);\n}\n\n/** Like `useCapability`, but null while the token can't resolve (no plugin,\n * no document, or a document that isn't ready yet). */\nexport function useOptionalCapability<T>(token: CapabilityToken<T>): T | null {\n const scoped = useContext(DocumentScopeCtx);\n return useKernelValue((k) => k.tryCapability(token, scoped ?? undefined));\n}\n\n/** Subscribe to a selector over a (document-resolved) capability. */\nexport function useSelector<C, R>(\n token: CapabilityToken<C>,\n select: (cap: C) => R,\n isEqual: (a: R, b: R) => boolean = Object.is,\n): R {\n const kernel = useKernel();\n const cap = useCapability(token);\n const last = useRef<{ v: R } | null>(null);\n const get = () => {\n const next = select(cap);\n if (last.current && isEqual(last.current.v, next)) return last.current.v;\n last.current = { v: next };\n return next;\n };\n return useSyncExternalStore(kernel.subscribe, get, get);\n}\n\n/**\n * Null-safe `useSelector`: `fallback` whenever the token can't resolve — no\n * provider, or a document-scoped token with no document. For chrome that stays\n * mounted across the empty-workspace state (a zoom readout, a mode band).\n * `useSelector` stays strict (fail-fast) for code that KNOWS a document exists\n * — e.g. anything inside a <DocumentGate>.\n *\n * The `select` guard also swallows reads through a capability whose document\n * closed between the store notification and this render — that teardown race\n * resolves to `fallback` for one frame, then re-renders against the new state.\n */\nexport function useOptionalSelector<C, R>(\n token: CapabilityToken<C>,\n select: (cap: C) => R,\n fallback: R,\n isEqual: (a: R, b: R) => boolean = Object.is,\n): R {\n const kernel = useKernel();\n const cap = useOptionalCapability(token);\n const last = useRef<{ v: R } | null>(null);\n const get = () => {\n let next: R;\n if (cap === null) {\n next = fallback;\n } else {\n try {\n next = select(cap);\n } catch {\n next = fallback;\n }\n }\n if (last.current && isEqual(last.current.v, next)) return last.current.v;\n last.current = { v: next };\n return next;\n };\n return useSyncExternalStore(kernel.subscribe, get, get);\n}\n\n/** The document registry (open/close/active/list), reactive. */\nexport function useDocuments() {\n const kernel = useKernel();\n const docs = useKernelValue((k) => k.documents.list(), docInfoListEquals);\n const activeId = useActiveDocumentId();\n return {\n docs,\n activeId,\n open: kernel.documents.open,\n unlock: kernel.documents.unlock,\n close: kernel.documents.close,\n setActive: kernel.documents.setActive,\n move: kernel.documents.move,\n swap: kernel.documents.swap,\n download: kernel.documents.download,\n downloadLayer: kernel.documents.downloadLayer,\n };\n}\n\n// `InitialDocument` is the KERNEL's type (re-exported via `export * from\n// '@embedpdf/core'` above) — one shared shape for every adapter.\n\nexport interface ViewerProps {\n /**\n * The engine, as an instance or a thunk. Engines construct synchronously and\n * boot lazily (`localEngine()` allocates nothing until first use), so\n * ownership follows the SHAPE of what you pass:\n *\n * - An **instance** (`engine={engine}`) is BORROWED: the Viewer uses it and\n * never destroys it, because you acquired it and therefore own it. The\n * common path — a module-scope `const engine = localEngine()` shared\n * across viewers and route changes. The Viewer calls `engine.warmup?.()`\n * on mount so the boot overlaps app initialization.\n * - A **thunk** (`engine={() => localEngine()}`) is VIEWER-OWNED: the\n * Viewer calls it on mount and `destroy()`s the result on unmount. Use it\n * for per-mount isolation (StrictMode/HMR-clean teardown, independent\n * multi-viewer engines).\n *\n * Init-only: captured on first render; later identity changes are ignored (dev warns).\n */\n engine: Engine | EngineFactory;\n /** Init-only: captured on first render; later identity changes are ignored (dev warns). */\n plugins: AnyPlugin[];\n /** Documents to open on startup (with optional tab names). Init-only. */\n initialDocuments?: InitialDocument[];\n fallback?: React.ReactNode;\n /** Rendered when kernel construction or `start()` fails. Without it a boot\n * failure renders nothing — but never a silent forever-fallback. */\n renderError?: (error: unknown) => React.ReactNode;\n children: React.ReactNode;\n}\n\ntype BootState =\n | { phase: 'booting'; kernel: Kernel | null }\n | { phase: 'ready'; kernel: Kernel }\n | { phase: 'error'; error: unknown };\n\n/**\n * Owns the kernel as an EFFECT-scoped resource: each effect setup creates and\n * starts exactly one kernel; each cleanup destroys exactly that one. That is\n * the contract StrictMode exercises (two kernels in dev, the first fully\n * destroyed) — the kernel itself is never restarted after destroy.\n *\n * The kernel is published to context the moment it exists — before `start()`\n * resolves — so the `fallback` can use workspace capabilities (i18n copy on a\n * loading screen) exactly as before. The one exception is the very first\n * render, which happens before the effect: it renders nothing. Children mount\n * once `start()` resolves — which never touches the engine, so the shell is\n * alive while WASM compiles or the transport connects. `initialDocuments`\n * open in the BACKGROUND and stream into the registry (`useDocuments()` is\n * reactive); per-document loading UI is the Stage's job, not a root gate.\n *\n * ENGINE OWNERSHIP. When `engine` is a thunk, the Viewer OWNS it: each effect\n * setup constructs one engine (construction is synchronous and inert — boot\n * happens lazily inside the engine) and each cleanup destroys exactly that one\n * — after the kernel, so handles close first. When `engine` is an instance it\n * is BORROWED and never destroyed here; the Viewer only calls `warmup?.()` so\n * the WASM/transport boot overlaps plugin initialization. StrictMode's\n * double-mount therefore constructs two independent thunk engines and tears\n * the first fully down, matching the kernel's own effect-scoped lifecycle.\n * That means dev-only double resource use (two worker spawns, two font\n * fetches, briefly overlapping) — deliberate, because it is exactly the\n * leak-detection contract StrictMode exists to exercise; production mounts\n * once and boots once.\n */\nexport function Viewer({\n engine,\n plugins,\n initialDocuments,\n fallback,\n renderError,\n children,\n}: ViewerProps) {\n // Init-only inputs: the kernel's lifetime is the component's lifetime, so a\n // changed engine/plugins identity cannot mean \"rebuild the workspace\" —\n // that would silently drop every open document. Capture once, warn in dev.\n const initial = useRef({ engine, plugins, initialDocuments });\n const warned = useRef(false);\n if (process.env.NODE_ENV !== 'production' && !warned.current) {\n if (initial.current.engine !== engine || initial.current.plugins !== plugins) {\n warned.current = true;\n console.warn(\n '[embedpdf] <Viewer> engine/plugins are init-only. A changed identity is ignored — ' +\n 'pass stable references (module scope, useState, or useMemo). ' +\n 'An inline `plugins={[...]}` array recreates its identity every render.',\n );\n }\n }\n\n const [boot, setBoot] = useState<BootState>({ phase: 'booting', kernel: null });\n useEffect(() => {\n const captured = initial.current;\n // A thunk is viewer-owned: call it now, destroy on unmount. An instance is\n // borrowed: use as-is, never destroy. Construction is synchronous and inert\n // either way — the engine boots lazily on first use — so kick `warmup()`\n // to overlap the WASM/transport boot with plugin initialization.\n const ownsEngine = typeof captured.engine === 'function';\n const engine: Engine = ownsEngine\n ? (captured.engine as EngineFactory)()\n : (captured.engine as Engine);\n engine.warmup?.();\n let kernel: Kernel;\n try {\n kernel = createKernel({ engine, plugins: captured.plugins });\n } catch (error) {\n setBoot({ phase: 'error', error }); // plan/graph errors surface, not throw mid-render\n if (ownsEngine) void engine.destroy();\n return;\n }\n let alive = true;\n setBoot({ phase: 'booting', kernel }); // context carries the kernel from this frame on\n kernel.start().then(\n () => {\n if (!alive) return; // unmounted mid-boot — don't open anything\n setBoot({ phase: 'ready', kernel });\n // Kernel-owned boot policy: all tabs appear immediately in array\n // order; the `active` entry (else the first) is selected; failures\n // surface as tab status. See DocumentsCapability.openAll.\n kernel.documents.openAll(captured.initialDocuments ?? []);\n },\n (error) => {\n if (alive) setBoot({ phase: 'error', error });\n },\n );\n return () => {\n alive = false;\n // Kernel first (closes every document handle), THEN the engine we own —\n // ownership follows acquisition. `engine.destroy()` joins an in-flight\n // boot (or no-ops if it never started), so an unmount mid-boot is safe.\n void kernel.destroy().then(() => {\n if (ownsEngine) void engine.destroy();\n });\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n if (boot.phase === 'error') {\n return <>{renderError ? renderError(boot.error) : null}</>;\n }\n if (!boot.kernel) return null; // pre-effect first render only\n return (\n <KernelCtx.Provider value={boot.kernel}>\n {boot.phase === 'ready' ? children : (fallback ?? null)}\n </KernelCtx.Provider>\n );\n}\nexport const EmbedPDF = Viewer;\n\n/**\n * PageContext — the seam. A layer depends ONLY on this, never on the Stage. So the\n * same layer works inside a virtualized Stage and in a standalone <PageView>.\n */\nexport interface PageContextValue {\n documentId: string;\n /** Durable page identity (PDF object number) — use for keys / render / annotations. */\n pon: number;\n /** Display index (page N) — use for ordering / human-facing page numbers. */\n pageIndex: number;\n /**\n * Reserved chrome bands around the page (screen px per side). The page-chrome\n * slot renders into the outer box (content + frame); these thicknesses size\n * the bands — a label in the bottom band is `bottom:0; height: frame.bottom`.\n */\n frame: PageFrame;\n /**\n * The single bridge between PDF points, view px, and device px for this page.\n * Layers do ALL coordinate work through it — `pageToContent` to place content-\n * space overlays, `renderScale`/`deviceWidth` to render, `contentWidth` for\n * page-relative sizing. Never re-derive `x * scale` or `* dpr`.\n */\n transform: PageTransform;\n /** Client (screen) point → PDF point — the one platform-bound hit-test. */\n toPagePoint(clientX: number, clientY: number): Point;\n /** PDF/content point → client (screen) px — the exact inverse of `toPagePoint`\n * (rotation applied). Lets viewport-space UI (e.g. a selection menu) anchor to a\n * page point WITHOUT a Stage camera, so it works the same in `<PageView>`. */\n toClientPoint(p: Point): Point;\n /** PDF/content rect → client (screen) px AABB. Rect analog of `toClientPoint`\n * for upright viewport-space UI that frames a selected page region. */\n toClientRect(rect: Rect): Rect;\n /**\n * The page-view DEMAND for raster planning uses dependency inversion:\n * plugin-render defines the shape; the host that CREATED this\n * context fills it — as a PULL. The Stage host's getter closes over the\n * stage capability and reads `VisiblePage.visibleRect` live at call time\n * (visibility is the STAGE's data; adapters never re-derive camera math or\n * cache a copy). Three states, three meanings: a real sub-rect (visible),\n * a ZERO rect (stage host, page currently off-screen — want nothing), and\n * an undefined getter (stage-less `<PageView>` — whole page visible, which\n * a thumbnail-sized demand turns into \"never engages\" by arithmetic).\n */\n getViewDemand?: () => PageViewDemand;\n}\n\nconst PageCtx = createContext<PageContextValue | null>(null);\nexport const PageProvider = PageCtx.Provider;\n\nexport function usePage(): PageContextValue {\n const c = useContext(PageCtx);\n if (!c) throw new Error('usePage must be used inside <PageView> or a <Stage> page');\n return c;\n}\n\nexport function makePageContext(\n documentId: string,\n pon: number,\n pageIndex: number,\n frame: PageFrame,\n transform: PageTransform,\n getRect: () => DOMRect,\n getViewDemand?: () => PageViewDemand,\n): PageContextValue {\n return {\n documentId,\n pon,\n pageIndex,\n frame,\n transform,\n ...(getViewDemand ? { getViewDemand } : {}),\n toPagePoint: (cx, cy) => {\n // `getRect()` is the rotated content wrapper's axis-aligned bounding box =\n // the page's DISPLAY box on screen. Convert client → box-local view px,\n // then invert rotation + scale via the transform (verified once in geometry,\n // not re-derived per framework adapter).\n const r = getRect();\n return transform.viewToPage({ x: cx - r.left, y: cy - r.top });\n },\n toClientPoint: (p) => {\n // Exact inverse of `toPagePoint`: page/content point → display-box view px\n // (rotation applied by the transform), offset by the same live display-box\n // origin. So the two can never drift, in either <Stage> or <PageView>.\n const r = getRect();\n const v = transform.pageToView(p);\n return { x: r.left + v.x, y: r.top + v.y };\n },\n toClientRect: (rect) => {\n const r = getRect();\n const v = transform.pageToViewRect(rect);\n return { x: r.left + v.x, y: r.top + v.y, width: v.width, height: v.height };\n },\n };\n}\n"],"mappings":";;;;;;;AAkCA,MAAM,aAAA,GAAA,MAAA,cAAA,CAAyC,IAAI;;AAEnD,MAAM,oBAAA,GAAA,MAAA,cAAA,CAAgD,IAAI;AAE1D,SAAgB,YAAoB;CAClC,MAAM,KAAA,GAAA,MAAA,WAAA,CAAe,SAAS;CAC9B,IAAI,CAAC,GAAG,MAAM,IAAI,MAAM,mDAAmD;CAC3E,OAAO;AACT;AAEA,MAAa,gBAAoB,GAAiB,MAChD,MAAM,KAAM,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,GAAG,MAAM,MAAM,EAAE,EAAE;;AAGnE,SAAgB,eACd,QACA,UAAmC,OAAO,IACvC;CACH,MAAM,SAAS,UAAU;CACzB,MAAM,QAAA,GAAA,MA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;GAAE;EAC3C;EACA,eAAe,SAAS;GACtB,MAAM,IAAI,QAAQ;GAClB,MAAM,IAAI,UAAU,eAAe,IAAI;GACvC,OAAO;IAAE,GAAG,EAAE,OAAO,EAAE;IAAG,GAAG,EAAE,MAAM,EAAE;IAAG,OAAO,EAAE;IAAO,QAAQ,EAAE;GAAO;EAC7E;CACF;AACF"}
@@ -0,0 +1,3 @@
1
+ import { S as useSelector, _ as useKernel, a as EmbedPDF, b as useOptionalSelector, c as Viewer, d as shallowArray, f as useActiveDocumentId, g as useDocuments, h as useDocumentStatus, i as DocumentScopeProps, l as ViewerProps, m as useDocumentId, n as DocumentGateProps, o as PageContextValue, p as useCapability, r as DocumentScope, s as PageProvider, t as DocumentGate, u as makePageContext, v as useKernelValue, x as usePage, y as useOptionalCapability } from "./runtime-CMxIuF2O.cjs";
2
+ export * from "@embedpdf/core";
3
+ export { DocumentGate, DocumentGateProps, DocumentScope, DocumentScopeProps, EmbedPDF, PageContextValue, PageProvider, Viewer, ViewerProps, makePageContext, shallowArray, useActiveDocumentId, useCapability, useDocumentId, useDocumentStatus, useDocuments, useKernel, useKernelValue, useOptionalCapability, useOptionalSelector, usePage, useSelector };
@@ -0,0 +1,3 @@
1
+ import { S as useSelector, _ as useKernel, a as EmbedPDF, b as useOptionalSelector, c as Viewer, d as shallowArray, f as useActiveDocumentId, g as useDocuments, h as useDocumentStatus, i as DocumentScopeProps, l as ViewerProps, m as useDocumentId, n as DocumentGateProps, o as PageContextValue, p as useCapability, r as DocumentScope, s as PageProvider, t as DocumentGate, u as makePageContext, v as useKernelValue, x as usePage, y as useOptionalCapability } from "./runtime-DV98q7I0.js";
2
+ export * from "@embedpdf/core";
3
+ export { DocumentGate, DocumentGateProps, DocumentScope, DocumentScopeProps, EmbedPDF, PageContextValue, PageProvider, Viewer, ViewerProps, makePageContext, shallowArray, useActiveDocumentId, useCapability, useDocumentId, useDocumentStatus, useDocuments, useKernel, useKernelValue, useOptionalCapability, useOptionalSelector, usePage, useSelector };