@embedpdf/react 3.0.0-next.13 → 3.0.0-next.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AnnotationList-CkijRHet-HEFNUIZe.d.cts +877 -0
- package/dist/AnnotationList-CkijRHet-HEFNUIZe.d.ts +877 -0
- package/dist/actions.cjs +25 -5
- package/dist/actions.cjs.map +1 -1
- package/dist/actions.d.cts +18 -5
- package/dist/actions.d.ts +18 -5
- package/dist/actions.js +22 -6
- package/dist/actions.js.map +1 -1
- package/dist/anchored-DeX95xSd.d.ts +85 -0
- package/dist/anchored-DzN3JywS.d.cts +85 -0
- package/dist/anchored.cjs +71 -28
- package/dist/anchored.cjs.map +1 -1
- package/dist/anchored.d.cts +2 -45
- package/dist/anchored.d.ts +2 -45
- package/dist/anchored.js +56 -19
- package/dist/anchored.js.map +1 -1
- package/dist/annotation-B48UT2ln.d.ts +302 -0
- package/dist/annotation-C1ttM8Wj.js +708 -0
- package/dist/annotation-C1ttM8Wj.js.map +1 -0
- package/dist/annotation-C9dVwo9b.d.cts +302 -0
- package/dist/annotation-Dex5EBda.cjs +830 -0
- package/dist/annotation-Dex5EBda.cjs.map +1 -0
- package/dist/annotation.cjs +20 -783
- package/dist/annotation.d.cts +2 -2
- package/dist/annotation.d.ts +2 -2
- package/dist/annotation.js +2 -768
- package/dist/commands.cjs +68 -28
- package/dist/commands.cjs.map +1 -1
- package/dist/commands.d.cts +37 -10
- package/dist/commands.d.ts +37 -10
- package/dist/commands.js +68 -31
- package/dist/commands.js.map +1 -1
- package/dist/form-55izw0jS.js +511 -0
- package/dist/form-55izw0jS.js.map +1 -0
- package/dist/form-BNqQfGGH.cjs +548 -0
- package/dist/form-BNqQfGGH.cjs.map +1 -0
- package/dist/form.cjs +5 -5
- package/dist/form.d.cts +32 -25
- package/dist/form.d.ts +32 -25
- package/dist/form.js +2 -3
- package/dist/history.cjs +38 -0
- package/dist/history.cjs.map +1 -0
- package/dist/history.d.cts +27 -0
- package/dist/history.d.ts +27 -0
- package/dist/history.js +27 -0
- package/dist/history.js.map +1 -0
- package/dist/i18n.cjs +26 -30
- package/dist/i18n.cjs.map +1 -1
- package/dist/i18n.d.cts +24 -21
- package/dist/i18n.d.ts +24 -21
- package/dist/i18n.js +24 -31
- package/dist/i18n.js.map +1 -1
- package/dist/index.cjs +213 -57
- package/dist/index.d.cts +32 -31
- package/dist/index.d.ts +32 -31
- package/dist/index.js +33 -29
- package/dist/inert-CmBEbKCn.cjs +19 -0
- package/dist/inert-CmBEbKCn.cjs.map +1 -0
- package/dist/inert-D8fkennb.js +14 -0
- package/dist/inert-D8fkennb.js.map +1 -0
- package/dist/interaction.cjs +48 -102
- package/dist/interaction.cjs.map +1 -1
- package/dist/interaction.d.cts +23 -32
- package/dist/interaction.d.ts +23 -32
- package/dist/interaction.js +33 -102
- package/dist/interaction.js.map +1 -1
- package/dist/link.cjs +65 -104
- package/dist/link.cjs.map +1 -1
- package/dist/link.d.cts +21 -16
- package/dist/link.d.ts +22 -17
- package/dist/link.js +67 -107
- package/dist/link.js.map +1 -1
- package/dist/measurement.cjs +56 -0
- package/dist/measurement.cjs.map +1 -0
- package/dist/measurement.d.cts +38 -0
- package/dist/measurement.d.ts +38 -0
- package/dist/measurement.js +42 -0
- package/dist/measurement.js.map +1 -0
- package/dist/metadata.cjs +20 -7
- package/dist/metadata.cjs.map +1 -1
- package/dist/metadata.d.cts +22 -7
- package/dist/metadata.d.ts +22 -7
- package/dist/metadata.js +20 -10
- package/dist/metadata.js.map +1 -1
- package/dist/page-edit.cjs +7 -3
- package/dist/page-edit.cjs.map +1 -1
- package/dist/page-edit.d.cts +6 -2
- package/dist/page-edit.d.ts +6 -2
- package/dist/page-edit.js +7 -4
- package/dist/page-edit.js.map +1 -1
- package/dist/page-layers-Bkaaz8Zf.js +26 -0
- package/dist/page-layers-Bkaaz8Zf.js.map +1 -0
- package/dist/page-layers-BloZDoOV.cjs +37 -0
- package/dist/page-layers-BloZDoOV.cjs.map +1 -0
- package/dist/page-view.cjs +89 -82
- package/dist/page-view.cjs.map +1 -1
- package/dist/page-view.d.cts +14 -7
- package/dist/page-view.d.ts +18 -11
- package/dist/page-view.js +86 -81
- package/dist/page-view.js.map +1 -1
- package/dist/redaction.cjs +30 -15
- package/dist/redaction.cjs.map +1 -1
- package/dist/redaction.d.cts +27 -9
- package/dist/redaction.d.ts +27 -9
- package/dist/redaction.js +29 -18
- package/dist/redaction.js.map +1 -1
- package/dist/render.cjs +71 -46
- package/dist/render.cjs.map +1 -1
- package/dist/render.d.cts +17 -5
- package/dist/render.d.ts +17 -5
- package/dist/render.js +70 -49
- package/dist/render.js.map +1 -1
- package/dist/runtime-B6xcPsEb.js +398 -0
- package/dist/runtime-B6xcPsEb.js.map +1 -0
- package/dist/runtime-DBEBlpQV.d.cts +237 -0
- package/dist/runtime-V3MVMb91.d.ts +237 -0
- package/dist/runtime-fzpGv78v.cjs +555 -0
- package/dist/runtime-fzpGv78v.cjs.map +1 -0
- package/dist/runtime.cjs +45 -324
- package/dist/runtime.d.cts +2 -2
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.js +2 -306
- package/dist/search.cjs +81 -50
- package/dist/search.cjs.map +1 -1
- package/dist/search.d.cts +36 -24
- package/dist/search.d.ts +36 -24
- package/dist/search.js +81 -53
- package/dist/search.js.map +1 -1
- package/dist/selection.cjs +105 -108
- package/dist/selection.cjs.map +1 -1
- package/dist/selection.d.cts +54 -26
- package/dist/selection.d.ts +56 -28
- package/dist/selection.js +103 -110
- package/dist/selection.js.map +1 -1
- package/dist/shell.cjs +36 -21
- package/dist/shell.cjs.map +1 -1
- package/dist/shell.d.cts +32 -17
- package/dist/shell.d.ts +32 -17
- package/dist/shell.js +36 -24
- package/dist/shell.js.map +1 -1
- package/dist/signature.cjs +29 -48
- package/dist/signature.cjs.map +1 -1
- package/dist/signature.d.cts +26 -26
- package/dist/signature.d.ts +26 -26
- package/dist/signature.js +30 -48
- package/dist/signature.js.map +1 -1
- package/dist/stage-BIG6aeVd.cjs +369 -0
- package/dist/stage-BIG6aeVd.cjs.map +1 -0
- package/dist/stage-ByFPD-Fv.d.cts +117 -0
- package/dist/stage-DaboaheR.d.ts +117 -0
- package/dist/stage-DoVekb83.js +302 -0
- package/dist/stage-DoVekb83.js.map +1 -0
- package/dist/stage-scope-CQgCuf1w.cjs +46 -0
- package/dist/stage-scope-CQgCuf1w.cjs.map +1 -0
- package/dist/stage-scope-D7ZeNduT.js +23 -0
- package/dist/stage-scope-D7ZeNduT.js.map +1 -0
- package/dist/stage.cjs +12 -235
- package/dist/stage.d.cts +2 -116
- package/dist/stage.d.ts +2 -116
- package/dist/stage.js +3 -228
- package/dist/stamp.cjs +41 -35
- package/dist/stamp.cjs.map +1 -1
- package/dist/stamp.d.cts +25 -18
- package/dist/stamp.d.ts +25 -18
- package/dist/stamp.js +40 -37
- package/dist/stamp.js.map +1 -1
- package/dist/state-0K1I5cM4.d.cts +29 -0
- package/dist/state-0K1I5cM4.d.ts +29 -0
- package/dist/state-CbgxhwLA.js +62 -0
- package/dist/state-CbgxhwLA.js.map +1 -0
- package/dist/state-CsfZy_Eq.cjs +73 -0
- package/dist/state-CsfZy_Eq.cjs.map +1 -0
- package/dist/svg-shapes-Dm1yTR1b.js +40 -0
- package/dist/svg-shapes-Dm1yTR1b.js.map +1 -0
- package/dist/svg-shapes-zo0GNkc9.cjs +53 -0
- package/dist/svg-shapes-zo0GNkc9.cjs.map +1 -0
- package/dist/toolbar.cjs +297 -295
- package/dist/toolbar.cjs.map +1 -1
- package/dist/toolbar.d.cts +58 -68
- package/dist/toolbar.d.ts +67 -77
- package/dist/toolbar.js +271 -293
- package/dist/toolbar.js.map +1 -1
- package/dist/view-manager.cjs +34 -0
- package/dist/view-manager.cjs.map +1 -0
- package/dist/view-manager.d.cts +21 -0
- package/dist/view-manager.d.ts +21 -0
- package/dist/view-manager.js +23 -0
- package/dist/view-manager.js.map +1 -0
- package/package.json +41 -38
- package/dist/AnnotationListSnapshot-D3mFut1e-C_GMpK25.d.cts +0 -546
- package/dist/AnnotationListSnapshot-D3mFut1e-C_GMpK25.d.ts +0 -546
- package/dist/annotation-BCED_p9H.d.cts +0 -160
- package/dist/annotation-anchors-CetwM1g7.js +0 -15
- package/dist/annotation-anchors-CetwM1g7.js.map +0 -1
- package/dist/annotation-anchors-DuYRBJLl.cjs +0 -26
- package/dist/annotation-anchors-DuYRBJLl.cjs.map +0 -1
- package/dist/annotation-hooks-BB5ZhPpf.cjs +0 -16
- package/dist/annotation-hooks-BB5ZhPpf.cjs.map +0 -1
- package/dist/annotation-hooks-Df8EmzDO.js +0 -11
- package/dist/annotation-hooks-Df8EmzDO.js.map +0 -1
- package/dist/annotation-k38KDlIZ.d.ts +0 -160
- package/dist/annotation-menu.cjs +0 -64
- package/dist/annotation-menu.cjs.map +0 -1
- package/dist/annotation-menu.d.cts +0 -33
- package/dist/annotation-menu.d.ts +0 -33
- package/dist/annotation-menu.js +0 -48
- package/dist/annotation-menu.js.map +0 -1
- package/dist/annotation.cjs.map +0 -1
- package/dist/annotation.js.map +0 -1
- package/dist/form-BVumS7up.cjs +0 -926
- package/dist/form-BVumS7up.cjs.map +0 -1
- package/dist/form-CK3mp99m.js +0 -895
- package/dist/form-CK3mp99m.js.map +0 -1
- package/dist/rolldown-runtime-BBjsoOtd.js +0 -27
- package/dist/runtime-DE76hlnl.d.ts +0 -216
- package/dist/runtime-umHA_xHt.d.cts +0 -216
- package/dist/runtime.cjs.map +0 -1
- package/dist/runtime.js.map +0 -1
- package/dist/scrollbar.cjs +0 -241
- package/dist/scrollbar.cjs.map +0 -1
- package/dist/scrollbar.d.cts +0 -42
- package/dist/scrollbar.d.ts +0 -42
- package/dist/scrollbar.js +0 -213
- package/dist/scrollbar.js.map +0 -1
- package/dist/stage.cjs.map +0 -1
- package/dist/stage.js.map +0 -1
- package/dist/views.cjs +0 -35
- package/dist/views.cjs.map +0 -1
- package/dist/views.d.cts +0 -21
- package/dist/views.d.ts +0 -21
- package/dist/views.js +0 -27
- package/dist/views.js.map +0 -1
package/dist/runtime.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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 EventHook,\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/contract';\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/**\n * Subscribe to a capability's {@link EventHook} for the mounted lifetime —\n * `useCapabilityEvent(ActionsToken, (c) => c.onAction, handler)`. Events\n * carry occurrences, never state (a late subscriber that needs the current\n * value uses `useSelector`). The handler rides a ref, so a fresh closure per\n * render never resubscribes. Null-safe: no plugin/document → no subscription.\n */\nexport function useCapabilityEvent<C, T>(\n token: CapabilityToken<C>,\n select: (cap: C) => EventHook<T>,\n handler: (event: T) => void,\n): void {\n const cap = useOptionalCapability(token);\n const handlerRef = useRef(handler);\n handlerRef.current = handler;\n const selectRef = useRef(select);\n selectRef.current = select;\n useEffect(() => {\n if (!cap) return;\n return selectRef.current(cap)((event) => handlerRef.current(event));\n }, [cap]);\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 — `toPixels` 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 → the viewer's coordinates (content point) — the\n * one platform-bound hit-test. */\n toContentPoint(clientX: number, clientY: number): Point;\n /** Content point → client (screen) px — the exact inverse of `toContentPoint`\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 /** 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 * The hosting VIEW's identity — the stage lens id (`stage.lensId()`) or a\n * per-instance PageView id. IDENTITY, not an option: per-view raster\n * planning (tiles) keys its state by this, so two views showing the SAME\n * page never fight over one plan (a thumbnail rail's never-engaging demand\n * must not disturb the main view's tiles). Every page context host must\n * say which view it is.\n */\n view: string;\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 view: 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 view,\n pon,\n pageIndex,\n frame,\n transform,\n ...(getViewDemand ? { getViewDemand } : {}),\n toContentPoint: (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.viewToContent({ x: cx - r.left, y: cy - r.top });\n },\n toClientPoint: (p) => {\n // Exact inverse of `toContentPoint`: 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.contentToView(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.contentToViewRect(rect);\n return { x: r.left + v.x, y: r.top + v.y, width: v.width, height: v.height };\n },\n };\n}\n"],"mappings":";;;;;;;AAmCA,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,MAAA,OAAA,CAA+B,IAAI;CACzC,MAAM,YAAY;EAChB,MAAM,OAAO,OAAO,MAAM;EAC1B,IAAI,KAAK,WAAW,QAAQ,KAAK,QAAQ,GAAG,IAAI,GAAG,OAAO,KAAK,QAAQ;EACvE,KAAK,UAAU,EAAE,GAAG,KAAK;EACzB,OAAO;CACT;CACA,QAAA,GAAA,MAAA,qBAAA,CAA4B,OAAO,WAAW,KAAK,GAAG;AACxD;AAEA,SAAgB,sBAAqC;CACnD,OAAO,gBAAgB,MAAM,EAAE,UAAU,SAAS,CAAC;AACrD;;AAGA,SAAgB,gBAA+B;CAC7C,MAAM,UAAA,GAAA,MAAA,WAAA,CAAoB,gBAAgB;CAC1C,MAAM,SAAS,oBAAoB;CACnC,OAAO,UAAU;AACnB;;AAOA,SAAgB,cAAc,EAAE,IAAI,YAAgC;CAClE,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,iBAAiB,UAAlB;EAA2B,OAAO;EAAK;CAAoC,CAAA;AACpF;;;;;;;;;;;;;;AAoBA,SAAg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@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","names":[],"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 EventHook,\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/contract';\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/**\n * Subscribe to a capability's {@link EventHook} for the mounted lifetime —\n * `useCapabilityEvent(ActionsToken, (c) => c.onAction, handler)`. Events\n * carry occurrences, never state (a late subscriber that needs the current\n * value uses `useSelector`). The handler rides a ref, so a fresh closure per\n * render never resubscribes. Null-safe: no plugin/document → no subscription.\n */\nexport function useCapabilityEvent<C, T>(\n token: CapabilityToken<C>,\n select: (cap: C) => EventHook<T>,\n handler: (event: T) => void,\n): void {\n const cap = useOptionalCapability(token);\n const handlerRef = useRef(handler);\n handlerRef.current = handler;\n const selectRef = useRef(select);\n selectRef.current = select;\n useEffect(() => {\n if (!cap) return;\n return selectRef.current(cap)((event) => handlerRef.current(event));\n }, [cap]);\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 — `toPixels` 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 → the viewer's coordinates (content point) — the\n * one platform-bound hit-test. */\n toContentPoint(clientX: number, clientY: number): Point;\n /** Content point → client (screen) px — the exact inverse of `toContentPoint`\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 /** 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 * The hosting VIEW's identity — the stage lens id (`stage.lensId()`) or a\n * per-instance PageView id. IDENTITY, not an option: per-view raster\n * planning (tiles) keys its state by this, so two views showing the SAME\n * page never fight over one plan (a thumbnail rail's never-engaging demand\n * must not disturb the main view's tiles). Every page context host must\n * say which view it is.\n */\n view: string;\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 view: 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 view,\n pon,\n pageIndex,\n frame,\n transform,\n ...(getViewDemand ? { getViewDemand } : {}),\n toContentPoint: (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.viewToContent({ x: cx - r.left, y: cy - r.top });\n },\n toClientPoint: (p) => {\n // Exact inverse of `toContentPoint`: 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.contentToView(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.contentToViewRect(rect);\n return { x: r.left + v.x, y: r.top +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;EACA;EACA,GAAI,gBAAgB,EAAE,cAAc,IAAI,CAAC;EACzC,iBAAiB,IAAI,OAAO;GAK1B,MAAM,IAAI,QAAQ;GAClB,OAAO,UAAU,cAAc;IAAE,GAAG,KAAK,EAAE;IAAM,GAAG,KAAK,EAAE;GAAI,CAAC;EAClE;EACA,gBAAgB,MAAM;GAIpB,MAAM,IAAI,QAAQ;GAClB,MAAM,IAAI,UAAU,cAAc,CAAC;GACnC,OAAO;IAAE,GAAG,EAAE,OAAO,EAAE;IAAG,GAAG,EAAE,MAAM,EAAE;GAAE;EAC3C;EACA,eAAe,SAAS;GACtB,MAAM,IAAI,QAAQ;GAClB,MAAM,IAAI,UAAU,kBAAkB,IAAI;GAC1C,OAAO;IAAE,GAAG,EAAE,OAAO,EAAE;IAAG,GAAG,EAAE,MAAM,EAAE;IAAG,OAAO,EAAE;IAAO,QAAQ,EAAE;GAAO;EAC7E;CACF;AACF"}
|
package/dist/scrollbar.cjs
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_rolldown_runtime = require("./rolldown-runtime-DDXJien1.cjs");
|
|
3
|
-
const require_runtime = require("./runtime.cjs");
|
|
4
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
-
let react = require("react");
|
|
6
|
-
react = require_rolldown_runtime.__toESM(react, 1);
|
|
7
|
-
let _embedpdf_plugin_stage_contract = require("@embedpdf/plugin-stage/contract");
|
|
8
|
-
//#region src/scrollbar.tsx
|
|
9
|
-
/**
|
|
10
|
-
* Headless scrollbar for a Stage lens — a pure view of `stage.scrollMetrics()`.
|
|
11
|
-
*
|
|
12
|
-
* The Stage exposes the native scroller contract (scrollTop/scrollHeight/
|
|
13
|
-
* clientHeight, in screen px — see plugin-stage's README); this component turns
|
|
14
|
-
* it into a native-feeling bar: thumb drag with pointer capture and a preserved
|
|
15
|
-
* grab point, track paging with press-and-hold repeat that stops at the
|
|
16
|
-
* pointer, a minimum thumb length on long documents, and macOS-style overlay
|
|
17
|
-
* auto-hide. On an UNBOUNDED stage the metrics already carry the Figma
|
|
18
|
-
* semantics (the range is the union of content and view), so the same bar
|
|
19
|
-
* shrinks toward the edge as you pan away and rides you back — the mapping is
|
|
20
|
-
* FROZEN for the duration of a thumb drag so the thumb never chases itself
|
|
21
|
-
* while the union re-collapses.
|
|
22
|
-
*
|
|
23
|
-
* Headless styling contract: geometry and behavior live here; looks live in
|
|
24
|
-
* your CSS. Style via `className`/`thumbClassName` (or the style props) against
|
|
25
|
-
* [data-embedpdf-scrollbar][data-axis="y"][data-state="visible|hidden"]
|
|
26
|
-
* [data-embedpdf-scrollbar][data-dragging]
|
|
27
|
-
* [data-embedpdf-scrollbar-thumb]
|
|
28
|
-
* The defaults are deliberately minimal: a transparent track pinned to the
|
|
29
|
-
* viewport edge and a `var(--epdf-scrollbar-thumb, …)` pill, so the bar works
|
|
30
|
-
* unstyled and disappears into any theme. Build something else entirely
|
|
31
|
-
* (minimap, progress ring) from `useScrollMetrics()` + `stage.scrollTo()`.
|
|
32
|
-
*/
|
|
33
|
-
/** Live scroll metrics for a stage lens (reference-stable; see
|
|
34
|
-
* `StageCapability.scrollMetrics`). The raw material for custom scroll UI. */
|
|
35
|
-
function useScrollMetrics(token = _embedpdf_plugin_stage_contract.StageToken) {
|
|
36
|
-
return require_runtime.useSelector(token, (c) => c.scrollMetrics());
|
|
37
|
-
}
|
|
38
|
-
const clamp01 = (v) => Math.min(1, Math.max(0, v));
|
|
39
|
-
/** Best-effort pointer capture: an already-released pointer (pen/touch races,
|
|
40
|
-
* synthetic events in tests) throws NotFoundError — the press must still work,
|
|
41
|
-
* just without capture (moves keep arriving while the pointer stays on us). */
|
|
42
|
-
const capturePointer = (el, pointerId) => {
|
|
43
|
-
try {
|
|
44
|
-
el.setPointerCapture(pointerId);
|
|
45
|
-
} catch {}
|
|
46
|
-
};
|
|
47
|
-
/** Thumb geometry from metrics + a measured track. One formula for render,
|
|
48
|
-
* drag capture, and paging — they can never disagree. */
|
|
49
|
-
const geometry = (m, vertical, trackPx, minThumbSize) => {
|
|
50
|
-
const client = vertical ? m.clientHeight : m.clientWidth;
|
|
51
|
-
const total = vertical ? m.scrollHeight : m.scrollWidth;
|
|
52
|
-
const offset = vertical ? m.scrollTop : m.scrollLeft;
|
|
53
|
-
const maxOffset = Math.max(0, total - client);
|
|
54
|
-
const thumbLen = Math.min(trackPx, Math.max(minThumbSize, total > 0 ? client / total * trackPx : 0));
|
|
55
|
-
const travel = Math.max(0, trackPx - thumbLen);
|
|
56
|
-
return {
|
|
57
|
-
client,
|
|
58
|
-
offset,
|
|
59
|
-
maxOffset,
|
|
60
|
-
thumbLen,
|
|
61
|
-
travel,
|
|
62
|
-
thumbPos: maxOffset > 0 ? offset / maxOffset * travel : 0
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
function Scrollbar({ axis, token = _embedpdf_plugin_stage_contract.StageToken, autoHide = 1200, minThumbSize = 24, trackPress = "page", className, style, thumbClassName, thumbStyle }) {
|
|
66
|
-
const stage = require_runtime.useCapability(token);
|
|
67
|
-
const m = useScrollMetrics(token);
|
|
68
|
-
const vertical = axis === "y";
|
|
69
|
-
const scrollable = vertical ? m.scrollableY : m.scrollableX;
|
|
70
|
-
const trackRef = (0, react.useRef)(null);
|
|
71
|
-
const [trackPx, setTrackPx] = (0, react.useState)(0);
|
|
72
|
-
const [dragging, setDragging] = (0, react.useState)(false);
|
|
73
|
-
const [hovered, setHovered] = (0, react.useState)(false);
|
|
74
|
-
const [active, setActive] = (0, react.useState)(true);
|
|
75
|
-
const g = geometry(m, vertical, trackPx, minThumbSize);
|
|
76
|
-
const hideAfter = autoHide === false ? 0 : autoHide;
|
|
77
|
-
(0, react.useEffect)(() => {
|
|
78
|
-
if (!hideAfter) return;
|
|
79
|
-
setActive(true);
|
|
80
|
-
const t = setTimeout(() => setActive(false), hideAfter);
|
|
81
|
-
return () => clearTimeout(t);
|
|
82
|
-
}, [m, hideAfter]);
|
|
83
|
-
const shown = !hideAfter || active || hovered || dragging;
|
|
84
|
-
(0, react.useEffect)(() => {
|
|
85
|
-
const el = trackRef.current;
|
|
86
|
-
if (!el) return;
|
|
87
|
-
const measure = () => setTrackPx(vertical ? el.clientHeight : el.clientWidth);
|
|
88
|
-
const ro = new ResizeObserver(measure);
|
|
89
|
-
ro.observe(el);
|
|
90
|
-
measure();
|
|
91
|
-
return () => ro.disconnect();
|
|
92
|
-
}, [vertical, scrollable]);
|
|
93
|
-
const dragRef = (0, react.useRef)(null);
|
|
94
|
-
const pageRef = (0, react.useRef)(null);
|
|
95
|
-
const lastPtr = (0, react.useRef)(0);
|
|
96
|
-
const ptrPos = (e) => {
|
|
97
|
-
const r = trackRef.current.getBoundingClientRect();
|
|
98
|
-
return vertical ? e.clientY - r.top : e.clientX - r.left;
|
|
99
|
-
};
|
|
100
|
-
/** Fresh geometry for paging steps — read from the capability, never a stale render. */
|
|
101
|
-
const liveGeometry = () => geometry(stage.scrollMetrics(), vertical, trackPx, minThumbSize);
|
|
102
|
-
const stopPaging = () => {
|
|
103
|
-
if (pageRef.current) {
|
|
104
|
-
clearTimeout(pageRef.current.timer);
|
|
105
|
-
clearInterval(pageRef.current.timer);
|
|
106
|
-
pageRef.current = null;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
const endDrag = () => {
|
|
110
|
-
dragRef.current = null;
|
|
111
|
-
stopPaging();
|
|
112
|
-
setDragging(false);
|
|
113
|
-
};
|
|
114
|
-
const beginDrag = (grab, applied) => {
|
|
115
|
-
dragRef.current = {
|
|
116
|
-
grab,
|
|
117
|
-
applied,
|
|
118
|
-
max: g.maxOffset,
|
|
119
|
-
travel: g.travel
|
|
120
|
-
};
|
|
121
|
-
setDragging(true);
|
|
122
|
-
};
|
|
123
|
-
const onThumbDown = (e) => {
|
|
124
|
-
if (e.button !== 0) return;
|
|
125
|
-
e.preventDefault();
|
|
126
|
-
e.stopPropagation();
|
|
127
|
-
capturePointer(e.target, e.pointerId);
|
|
128
|
-
beginDrag(ptrPos(e) - g.thumbPos, g.offset);
|
|
129
|
-
};
|
|
130
|
-
const onTrackDown = (e) => {
|
|
131
|
-
if (e.button !== 0 || e.target !== e.currentTarget) return;
|
|
132
|
-
e.preventDefault();
|
|
133
|
-
capturePointer(e.currentTarget, e.pointerId);
|
|
134
|
-
const p = lastPtr.current = ptrPos(e);
|
|
135
|
-
if (trackPress === "jump") {
|
|
136
|
-
const want = g.travel > 0 ? clamp01((p - g.thumbLen / 2) / g.travel) * g.maxOffset : 0;
|
|
137
|
-
stage.scrollTo(vertical ? { top: want } : { left: want });
|
|
138
|
-
beginDrag(g.thumbLen / 2, want);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
const dir = p < g.thumbPos ? -1 : 1;
|
|
142
|
-
const step = () => {
|
|
143
|
-
const live = liveGeometry();
|
|
144
|
-
if (dir === 1 ? lastPtr.current <= live.thumbPos + live.thumbLen : lastPtr.current >= live.thumbPos) return stopPaging();
|
|
145
|
-
stage.scrollBy(vertical ? { top: dir * live.client * .9 } : { left: dir * live.client * .9 });
|
|
146
|
-
};
|
|
147
|
-
step();
|
|
148
|
-
const timer = window.setTimeout(() => {
|
|
149
|
-
if (!pageRef.current) return;
|
|
150
|
-
pageRef.current.timer = window.setInterval(step, 80);
|
|
151
|
-
}, 350);
|
|
152
|
-
pageRef.current = {
|
|
153
|
-
dir,
|
|
154
|
-
timer
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
const onMove = (e) => {
|
|
158
|
-
const d = dragRef.current;
|
|
159
|
-
if (d) {
|
|
160
|
-
if (d.travel <= 0) return;
|
|
161
|
-
const want = clamp01((ptrPos(e) - d.grab) / d.travel) * d.max;
|
|
162
|
-
const delta = want - d.applied;
|
|
163
|
-
if (delta) {
|
|
164
|
-
stage.panBy(vertical ? 0 : -delta, vertical ? -delta : 0);
|
|
165
|
-
d.applied = want;
|
|
166
|
-
}
|
|
167
|
-
} else if (pageRef.current) lastPtr.current = ptrPos(e);
|
|
168
|
-
};
|
|
169
|
-
(0, react.useEffect)(() => endDrag, []);
|
|
170
|
-
if (!scrollable) return null;
|
|
171
|
-
const trackDefaults = vertical ? {
|
|
172
|
-
position: "absolute",
|
|
173
|
-
top: 0,
|
|
174
|
-
right: 0,
|
|
175
|
-
bottom: 0,
|
|
176
|
-
width: 12
|
|
177
|
-
} : {
|
|
178
|
-
position: "absolute",
|
|
179
|
-
left: 0,
|
|
180
|
-
right: 0,
|
|
181
|
-
bottom: 0,
|
|
182
|
-
height: 12
|
|
183
|
-
};
|
|
184
|
-
const thumbDefaults = vertical ? {
|
|
185
|
-
position: "absolute",
|
|
186
|
-
left: 2,
|
|
187
|
-
right: 2,
|
|
188
|
-
top: g.thumbPos,
|
|
189
|
-
height: g.thumbLen
|
|
190
|
-
} : {
|
|
191
|
-
position: "absolute",
|
|
192
|
-
top: 2,
|
|
193
|
-
bottom: 2,
|
|
194
|
-
left: g.thumbPos,
|
|
195
|
-
width: g.thumbLen
|
|
196
|
-
};
|
|
197
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
198
|
-
ref: trackRef,
|
|
199
|
-
role: "scrollbar",
|
|
200
|
-
"aria-orientation": vertical ? "vertical" : "horizontal",
|
|
201
|
-
"aria-valuemin": 0,
|
|
202
|
-
"aria-valuemax": Math.round(g.maxOffset),
|
|
203
|
-
"aria-valuenow": Math.round(g.offset),
|
|
204
|
-
"data-embedpdf-scrollbar": "",
|
|
205
|
-
"data-axis": axis,
|
|
206
|
-
"data-state": shown ? "visible" : "hidden",
|
|
207
|
-
"data-dragging": dragging ? "" : void 0,
|
|
208
|
-
className,
|
|
209
|
-
style: {
|
|
210
|
-
...trackDefaults,
|
|
211
|
-
touchAction: "none",
|
|
212
|
-
userSelect: "none",
|
|
213
|
-
opacity: shown ? 1 : 0,
|
|
214
|
-
transition: "opacity 200ms",
|
|
215
|
-
pointerEvents: shown ? "auto" : "none",
|
|
216
|
-
...style
|
|
217
|
-
},
|
|
218
|
-
onPointerDown: onTrackDown,
|
|
219
|
-
onPointerMove: onMove,
|
|
220
|
-
onPointerUp: endDrag,
|
|
221
|
-
onPointerCancel: endDrag,
|
|
222
|
-
onPointerEnter: () => setHovered(true),
|
|
223
|
-
onPointerLeave: () => setHovered(false),
|
|
224
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
225
|
-
"data-embedpdf-scrollbar-thumb": "",
|
|
226
|
-
className: thumbClassName,
|
|
227
|
-
style: {
|
|
228
|
-
...thumbDefaults,
|
|
229
|
-
borderRadius: 6,
|
|
230
|
-
background: "var(--epdf-scrollbar-thumb, rgba(0, 0, 0, 0.4))",
|
|
231
|
-
...thumbStyle
|
|
232
|
-
},
|
|
233
|
-
onPointerDown: onThumbDown
|
|
234
|
-
})
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
//#endregion
|
|
238
|
-
exports.Scrollbar = Scrollbar;
|
|
239
|
-
exports.useScrollMetrics = useScrollMetrics;
|
|
240
|
-
|
|
241
|
-
//# sourceMappingURL=scrollbar.cjs.map
|
package/dist/scrollbar.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scrollbar.cjs","names":["StageToken","useSelector","useCapability"],"sources":["../src/scrollbar.tsx"],"sourcesContent":["/**\n * Headless scrollbar for a Stage lens — a pure view of `stage.scrollMetrics()`.\n *\n * The Stage exposes the native scroller contract (scrollTop/scrollHeight/\n * clientHeight, in screen px — see plugin-stage's README); this component turns\n * it into a native-feeling bar: thumb drag with pointer capture and a preserved\n * grab point, track paging with press-and-hold repeat that stops at the\n * pointer, a minimum thumb length on long documents, and macOS-style overlay\n * auto-hide. On an UNBOUNDED stage the metrics already carry the Figma\n * semantics (the range is the union of content and view), so the same bar\n * shrinks toward the edge as you pan away and rides you back — the mapping is\n * FROZEN for the duration of a thumb drag so the thumb never chases itself\n * while the union re-collapses.\n *\n * Headless styling contract: geometry and behavior live here; looks live in\n * your CSS. Style via `className`/`thumbClassName` (or the style props) against\n * [data-embedpdf-scrollbar][data-axis=\"y\"][data-state=\"visible|hidden\"]\n * [data-embedpdf-scrollbar][data-dragging]\n * [data-embedpdf-scrollbar-thumb]\n * The defaults are deliberately minimal: a transparent track pinned to the\n * viewport edge and a `var(--epdf-scrollbar-thumb, …)` pill, so the bar works\n * unstyled and disappears into any theme. Build something else entirely\n * (minimap, progress ring) from `useScrollMetrics()` + `stage.scrollTo()`.\n */\n\nimport * as React from 'react';\nimport { useEffect, useRef, useState } from 'react';\nimport { StageToken } from '@embedpdf/plugin-stage/contract';\nimport type { ScrollMetrics, StageCapability } from '@embedpdf/plugin-stage/contract';\nimport type { CapabilityToken } from '@embedpdf/core';\nimport { useCapability, useSelector } from './runtime';\n\nexport type ScrollbarAxis = 'x' | 'y';\n\n/** Live scroll metrics for a stage lens (reference-stable; see\n * `StageCapability.scrollMetrics`). The raw material for custom scroll UI. */\nexport function useScrollMetrics(\n token: CapabilityToken<StageCapability> = StageToken,\n): ScrollMetrics {\n return useSelector(token, (c) => c.scrollMetrics());\n}\n\nexport interface ScrollbarProps {\n axis: ScrollbarAxis;\n /** The stage lens to scroll (default: the main StageToken). */\n token?: CapabilityToken<StageCapability>;\n /**\n * Overlay auto-hide: fade `autoHide` ms after the camera stops moving\n * (drags and hover pin it visible; a hidden bar ignores the pointer, like\n * macOS). `false` = always visible. Visibility is published as\n * `data-state=\"visible|hidden\"` — the default style fades opacity; replace\n * it in CSS for any other treatment. Default 1200.\n */\n autoHide?: number | false;\n /** Minimum thumb length in px — native bars never vanish on long documents.\n * Position stays proportional via the standard travel remap. Default 24. */\n minThumbSize?: number;\n /**\n * Pressing the track: 'page' steps by 90% of a viewport toward the pointer,\n * repeats while held, and stops when the thumb reaches the pointer (the\n * native default); 'jump' centers the thumb at the pointer and hands off to\n * a drag (the macOS option-click / Figma feel). Default 'page'.\n */\n trackPress?: 'page' | 'jump';\n /** Track class/style. The default style pins the bar to the right (y) or\n * bottom (x) edge of the nearest positioned ancestor — the Stage container\n * when rendered in its `overlay`; override to place it anywhere else. */\n className?: string;\n style?: React.CSSProperties;\n thumbClassName?: string;\n thumbStyle?: React.CSSProperties;\n}\n\nconst clamp01 = (v: number) => Math.min(1, Math.max(0, v));\n\n/** Best-effort pointer capture: an already-released pointer (pen/touch races,\n * synthetic events in tests) throws NotFoundError — the press must still work,\n * just without capture (moves keep arriving while the pointer stays on us). */\nconst capturePointer = (el: Element, pointerId: number) => {\n try {\n el.setPointerCapture(pointerId);\n } catch {\n /* uncaptured is fine */\n }\n};\n\n/** Thumb geometry from metrics + a measured track. One formula for render,\n * drag capture, and paging — they can never disagree. */\nconst geometry = (m: ScrollMetrics, vertical: boolean, trackPx: number, minThumbSize: number) => {\n const client = vertical ? m.clientHeight : m.clientWidth;\n const total = vertical ? m.scrollHeight : m.scrollWidth;\n const offset = vertical ? m.scrollTop : m.scrollLeft;\n const maxOffset = Math.max(0, total - client);\n const thumbLen = Math.min(\n trackPx,\n Math.max(minThumbSize, total > 0 ? (client / total) * trackPx : 0),\n );\n const travel = Math.max(0, trackPx - thumbLen);\n const thumbPos = maxOffset > 0 ? (offset / maxOffset) * travel : 0;\n return { client, offset, maxOffset, thumbLen, travel, thumbPos };\n};\n\nexport function Scrollbar({\n axis,\n token = StageToken,\n autoHide = 1200,\n minThumbSize = 24,\n trackPress = 'page',\n className,\n style,\n thumbClassName,\n thumbStyle,\n}: ScrollbarProps) {\n const stage = useCapability(token);\n const m = useScrollMetrics(token);\n const vertical = axis === 'y';\n const scrollable = vertical ? m.scrollableY : m.scrollableX;\n\n const trackRef = useRef<HTMLDivElement>(null);\n const [trackPx, setTrackPx] = useState(0);\n const [dragging, setDragging] = useState(false);\n const [hovered, setHovered] = useState(false);\n const [active, setActive] = useState(true); // camera moved recently\n\n const g = geometry(m, vertical, trackPx, minThumbSize);\n\n // ── overlay auto-hide: any metrics change re-arms the fade timer ──────────\n const hideAfter = autoHide === false ? 0 : autoHide;\n useEffect(() => {\n if (!hideAfter) return;\n setActive(true);\n const t = setTimeout(() => setActive(false), hideAfter);\n return () => clearTimeout(t);\n }, [m, hideAfter]);\n const shown = !hideAfter || active || hovered || dragging;\n\n // ── track measurement (px mapping needs real geometry) ────────────────────\n useEffect(() => {\n const el = trackRef.current;\n if (!el) return;\n const measure = () => setTrackPx(vertical ? el.clientHeight : el.clientWidth);\n const ro = new ResizeObserver(measure);\n ro.observe(el);\n measure();\n return () => ro.disconnect();\n }, [vertical, scrollable]);\n\n // ── interactions. Drag state is FROZEN at pointer-down (grab point, travel,\n // max offset) and applied as relative pans — absolute-feeling in bounded\n // mode (the range is static there) and stable in unbounded mode, where\n // the live union would otherwise shift under the pointer mid-drag. ──────\n const dragRef = useRef<{ grab: number; applied: number; max: number; travel: number } | null>(\n null,\n );\n const pageRef = useRef<{ dir: 1 | -1; timer: number } | null>(null);\n const lastPtr = useRef(0);\n\n const ptrPos = (e: React.PointerEvent) => {\n const r = trackRef.current!.getBoundingClientRect();\n return vertical ? e.clientY - r.top : e.clientX - r.left;\n };\n /** Fresh geometry for paging steps — read from the capability, never a stale render. */\n const liveGeometry = () => geometry(stage.scrollMetrics(), vertical, trackPx, minThumbSize);\n\n const stopPaging = () => {\n if (pageRef.current) {\n clearTimeout(pageRef.current.timer);\n clearInterval(pageRef.current.timer);\n pageRef.current = null;\n }\n };\n const endDrag = () => {\n dragRef.current = null;\n stopPaging();\n setDragging(false);\n };\n\n const beginDrag = (grab: number, applied: number) => {\n dragRef.current = { grab, applied, max: g.maxOffset, travel: g.travel };\n setDragging(true);\n };\n\n const onThumbDown = (e: React.PointerEvent) => {\n if (e.button !== 0) return;\n e.preventDefault();\n e.stopPropagation();\n capturePointer(e.target as Element, e.pointerId);\n beginDrag(ptrPos(e) - g.thumbPos, g.offset);\n };\n\n const onTrackDown = (e: React.PointerEvent) => {\n if (e.button !== 0 || e.target !== e.currentTarget) return; // thumb handles its own\n e.preventDefault();\n capturePointer(e.currentTarget as Element, e.pointerId);\n const p = (lastPtr.current = ptrPos(e));\n\n if (trackPress === 'jump') {\n // land the thumb centered at the pointer, then it's an ordinary drag\n const want = g.travel > 0 ? clamp01((p - g.thumbLen / 2) / g.travel) * g.maxOffset : 0;\n stage.scrollTo(vertical ? { top: want } : { left: want });\n beginDrag(g.thumbLen / 2, want);\n return;\n }\n\n // 'page': step toward the pointer, repeat while held, stop at the pointer\n const dir: 1 | -1 = p < g.thumbPos ? -1 : 1;\n const step = () => {\n const live = liveGeometry();\n const reached =\n dir === 1\n ? lastPtr.current <= live.thumbPos + live.thumbLen\n : lastPtr.current >= live.thumbPos;\n if (reached) return stopPaging();\n stage.scrollBy(\n vertical ? { top: dir * live.client * 0.9 } : { left: dir * live.client * 0.9 },\n );\n };\n step();\n // native cadence: a beat before the repeat kicks in, then a steady march\n const timer = window.setTimeout(() => {\n if (!pageRef.current) return;\n pageRef.current.timer = window.setInterval(step, 80);\n }, 350);\n pageRef.current = { dir, timer };\n };\n\n // Pointer capture retargets to the pressed element and bubbles here — one\n // move/up pair serves thumb drags, jump-drags, and paging alike.\n const onMove = (e: React.PointerEvent) => {\n const d = dragRef.current;\n if (d) {\n if (d.travel <= 0) return;\n const want = clamp01((ptrPos(e) - d.grab) / d.travel) * d.max;\n const delta = want - d.applied;\n if (delta) {\n stage.panBy(vertical ? 0 : -delta, vertical ? -delta : 0);\n d.applied = want;\n }\n } else if (pageRef.current) {\n lastPtr.current = ptrPos(e);\n }\n };\n\n useEffect(() => endDrag, []); // unmount: no orphaned repeat timers\n\n if (!scrollable) return null;\n\n const trackDefaults: React.CSSProperties = vertical\n ? { position: 'absolute', top: 0, right: 0, bottom: 0, width: 12 }\n : { position: 'absolute', left: 0, right: 0, bottom: 0, height: 12 };\n const thumbDefaults: React.CSSProperties = vertical\n ? { position: 'absolute', left: 2, right: 2, top: g.thumbPos, height: g.thumbLen }\n : { position: 'absolute', top: 2, bottom: 2, left: g.thumbPos, width: g.thumbLen };\n\n return (\n <div\n ref={trackRef}\n role=\"scrollbar\"\n aria-orientation={vertical ? 'vertical' : 'horizontal'}\n aria-valuemin={0}\n aria-valuemax={Math.round(g.maxOffset)}\n aria-valuenow={Math.round(g.offset)}\n data-embedpdf-scrollbar=\"\"\n data-axis={axis}\n data-state={shown ? 'visible' : 'hidden'}\n data-dragging={dragging ? '' : undefined}\n className={className}\n style={{\n ...trackDefaults,\n touchAction: 'none',\n userSelect: 'none',\n opacity: shown ? 1 : 0,\n transition: 'opacity 200ms',\n // a hidden overlay bar must not eat the clicks under it\n pointerEvents: shown ? 'auto' : 'none',\n ...style,\n }}\n onPointerDown={onTrackDown}\n onPointerMove={onMove}\n onPointerUp={endDrag}\n onPointerCancel={endDrag}\n onPointerEnter={() => setHovered(true)}\n onPointerLeave={() => setHovered(false)}\n >\n <div\n data-embedpdf-scrollbar-thumb=\"\"\n className={thumbClassName}\n style={{\n ...thumbDefaults,\n borderRadius: 6,\n background: 'var(--epdf-scrollbar-thumb, rgba(0, 0, 0, 0.4))',\n ...thumbStyle,\n }}\n onPointerDown={onThumbDown}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,iBACd,QAA0CA,gCAAAA,YAC3B;CACf,OAAOC,gBAAAA,YAAY,QAAQ,MAAM,EAAE,cAAc,CAAC;AACpD;AAiCA,MAAM,WAAW,MAAc,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,CAAC,CAAC;;;;AAKzD,MAAM,kBAAkB,IAAa,cAAsB;CACzD,IAAI;EACF,GAAG,kBAAkB,SAAS;CAChC,QAAQ,CAER;AACF;;;AAIA,MAAM,YAAY,GAAkB,UAAmB,SAAiB,iBAAyB;CAC/F,MAAM,SAAS,WAAW,EAAE,eAAe,EAAE;CAC7C,MAAM,QAAQ,WAAW,EAAE,eAAe,EAAE;CAC5C,MAAM,SAAS,WAAW,EAAE,YAAY,EAAE;CAC1C,MAAM,YAAY,KAAK,IAAI,GAAG,QA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AY,KAAK;EAAG,OAAO;EAAG,QAAQ;EAAG,OAAO;CAAG,IAC/D;EAAE,UAAU;EAAY,MAAM;EAAG,OAAO;EAAG,QAAQ;EAAG,QAAQ;CAAG;CACrE,MAAM,gBAAqC,WACvC;EAAE,UAAU;EAAY,MAAM;EAAG,OAAO;EAAG,KAAK,EAAE;EAAU,QAAQ,EAAE;CAAS,IAC/E;EAAE,UAAU;EAAY,KAAK;EAAG,QAAQ;EAAG,MAAM,EAAE;EAAU,OAAO,EAAE;CAAS;CAEnF,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EACE,KAAK;EACL,MAAK;EACL,oBAAkB,WAAW,aAAa;EAC1C,iBAAe;EACf,iBAAe,KAAK,MAAM,EAAE,SAAS;EACrC,iBAAe,KAAK,MAAM,EAAE,MAAM;EAClC,2BAAwB;EACxB,aAAW;EACX,cAAY,QAAQ,YAAY;EAChC,iBAAe,WAAW,KAAK,KAAA;EACpB;EACX,OAAO;GACL,GAAG;GACH,aAAa;GACb,YAAY;GACZ,SAAS,QAAQ,IAAI;GACrB,YAAY;GAEZ,eAAe,QAAQ,SAAS;GAChC,GAAG;EACL;EACA,eAAe;EACf,eAAe;EACf,aAAa;EACb,iBAAiB;EACjB,sBAAsB,WAAW,IAAI;EACrC,sBAAsB,WAAW,KAAK;EAEtC,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;GACE,iCAA8B;GAC9B,WAAW;GACX,OAAO;IACL,GAAG;IACH,cAAc;IACd,YAAY;IACZ,GAAG;GACL;GACA,eAAe;EAChB,CAAA;CACE,CAAA;AAET"}
|
package/dist/scrollbar.d.cts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { CapabilityToken } from "@embedpdf/core";
|
|
3
|
-
import { ScrollMetrics, StageCapability } from "@embedpdf/plugin-stage/contract";
|
|
4
|
-
//#region src/scrollbar.d.ts
|
|
5
|
-
type ScrollbarAxis = 'x' | 'y';
|
|
6
|
-
/** Live scroll metrics for a stage lens (reference-stable; see
|
|
7
|
-
* `StageCapability.scrollMetrics`). The raw material for custom scroll UI. */
|
|
8
|
-
declare function useScrollMetrics(token?: CapabilityToken<StageCapability>): ScrollMetrics;
|
|
9
|
-
interface ScrollbarProps {
|
|
10
|
-
axis: ScrollbarAxis;
|
|
11
|
-
/** The stage lens to scroll (default: the main StageToken). */
|
|
12
|
-
token?: CapabilityToken<StageCapability>;
|
|
13
|
-
/**
|
|
14
|
-
* Overlay auto-hide: fade `autoHide` ms after the camera stops moving
|
|
15
|
-
* (drags and hover pin it visible; a hidden bar ignores the pointer, like
|
|
16
|
-
* macOS). `false` = always visible. Visibility is published as
|
|
17
|
-
* `data-state="visible|hidden"` — the default style fades opacity; replace
|
|
18
|
-
* it in CSS for any other treatment. Default 1200.
|
|
19
|
-
*/
|
|
20
|
-
autoHide?: number | false;
|
|
21
|
-
/** Minimum thumb length in px — native bars never vanish on long documents.
|
|
22
|
-
* Position stays proportional via the standard travel remap. Default 24. */
|
|
23
|
-
minThumbSize?: number;
|
|
24
|
-
/**
|
|
25
|
-
* Pressing the track: 'page' steps by 90% of a viewport toward the pointer,
|
|
26
|
-
* repeats while held, and stops when the thumb reaches the pointer (the
|
|
27
|
-
* native default); 'jump' centers the thumb at the pointer and hands off to
|
|
28
|
-
* a drag (the macOS option-click / Figma feel). Default 'page'.
|
|
29
|
-
*/
|
|
30
|
-
trackPress?: 'page' | 'jump';
|
|
31
|
-
/** Track class/style. The default style pins the bar to the right (y) or
|
|
32
|
-
* bottom (x) edge of the nearest positioned ancestor — the Stage container
|
|
33
|
-
* when rendered in its `overlay`; override to place it anywhere else. */
|
|
34
|
-
className?: string;
|
|
35
|
-
style?: React.CSSProperties;
|
|
36
|
-
thumbClassName?: string;
|
|
37
|
-
thumbStyle?: React.CSSProperties;
|
|
38
|
-
}
|
|
39
|
-
declare function Scrollbar({ axis, token, autoHide, minThumbSize, trackPress, className, style, thumbClassName, thumbStyle }: ScrollbarProps): import("react/jsx-runtime").JSX.Element | null;
|
|
40
|
-
//#endregion
|
|
41
|
-
export { Scrollbar, ScrollbarAxis, ScrollbarProps, useScrollMetrics };
|
|
42
|
-
//# sourceMappingURL=scrollbar.d.cts.map
|
package/dist/scrollbar.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { CapabilityToken } from "@embedpdf/core";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { ScrollMetrics, StageCapability } from "@embedpdf/plugin-stage/contract";
|
|
4
|
-
//#region src/scrollbar.d.ts
|
|
5
|
-
type ScrollbarAxis = 'x' | 'y';
|
|
6
|
-
/** Live scroll metrics for a stage lens (reference-stable; see
|
|
7
|
-
* `StageCapability.scrollMetrics`). The raw material for custom scroll UI. */
|
|
8
|
-
declare function useScrollMetrics(token?: CapabilityToken<StageCapability>): ScrollMetrics;
|
|
9
|
-
interface ScrollbarProps {
|
|
10
|
-
axis: ScrollbarAxis;
|
|
11
|
-
/** The stage lens to scroll (default: the main StageToken). */
|
|
12
|
-
token?: CapabilityToken<StageCapability>;
|
|
13
|
-
/**
|
|
14
|
-
* Overlay auto-hide: fade `autoHide` ms after the camera stops moving
|
|
15
|
-
* (drags and hover pin it visible; a hidden bar ignores the pointer, like
|
|
16
|
-
* macOS). `false` = always visible. Visibility is published as
|
|
17
|
-
* `data-state="visible|hidden"` — the default style fades opacity; replace
|
|
18
|
-
* it in CSS for any other treatment. Default 1200.
|
|
19
|
-
*/
|
|
20
|
-
autoHide?: number | false;
|
|
21
|
-
/** Minimum thumb length in px — native bars never vanish on long documents.
|
|
22
|
-
* Position stays proportional via the standard travel remap. Default 24. */
|
|
23
|
-
minThumbSize?: number;
|
|
24
|
-
/**
|
|
25
|
-
* Pressing the track: 'page' steps by 90% of a viewport toward the pointer,
|
|
26
|
-
* repeats while held, and stops when the thumb reaches the pointer (the
|
|
27
|
-
* native default); 'jump' centers the thumb at the pointer and hands off to
|
|
28
|
-
* a drag (the macOS option-click / Figma feel). Default 'page'.
|
|
29
|
-
*/
|
|
30
|
-
trackPress?: 'page' | 'jump';
|
|
31
|
-
/** Track class/style. The default style pins the bar to the right (y) or
|
|
32
|
-
* bottom (x) edge of the nearest positioned ancestor — the Stage container
|
|
33
|
-
* when rendered in its `overlay`; override to place it anywhere else. */
|
|
34
|
-
className?: string;
|
|
35
|
-
style?: React.CSSProperties;
|
|
36
|
-
thumbClassName?: string;
|
|
37
|
-
thumbStyle?: React.CSSProperties;
|
|
38
|
-
}
|
|
39
|
-
declare function Scrollbar({ axis, token, autoHide, minThumbSize, trackPress, className, style, thumbClassName, thumbStyle }: ScrollbarProps): import("react/jsx-runtime").JSX.Element | null;
|
|
40
|
-
//#endregion
|
|
41
|
-
export { Scrollbar, ScrollbarAxis, ScrollbarProps, useScrollMetrics };
|
|
42
|
-
//# sourceMappingURL=scrollbar.d.ts.map
|