@zsherman/pdf 0.0.0-stage → 0.4.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 (38) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +373 -0
  3. package/README.md +13 -2
  4. package/THIRD_PARTY_NOTICES.md +28 -0
  5. package/dist/dom/embedpdf/engine.js +15 -0
  6. package/dist/dom/embedpdf/index.js +10 -0
  7. package/dist/dom/embedpdf/render.js +205 -0
  8. package/dist/dom/embedpdf/runtime.js +299 -0
  9. package/dist/dom/embedpdf/search.js +114 -0
  10. package/dist/dom/embedpdf/stage.js +224 -0
  11. package/dist/dom/index.js +8 -0
  12. package/dist/dom/pdf-renderer/index.js +1 -0
  13. package/dist/dom/pdf-renderer/pdf-renderer.js +346 -0
  14. package/dist/solid/embedpdf/engine.jsx +15 -0
  15. package/dist/solid/embedpdf/index.jsx +10 -0
  16. package/dist/solid/embedpdf/render.jsx +170 -0
  17. package/dist/solid/embedpdf/runtime.jsx +234 -0
  18. package/dist/solid/embedpdf/search.jsx +83 -0
  19. package/dist/solid/embedpdf/stage.jsx +155 -0
  20. package/dist/solid/index.jsx +8 -0
  21. package/dist/solid/pdf-renderer/index.jsx +1 -0
  22. package/dist/solid/pdf-renderer/pdf-renderer.jsx +234 -0
  23. package/dist/styles.css +1 -0
  24. package/dist/types/embedpdf/engine.d.ts +7 -0
  25. package/dist/types/embedpdf/index.d.ts +15 -0
  26. package/dist/types/embedpdf/render.d.ts +9 -0
  27. package/dist/types/embedpdf/runtime.d.ts +113 -0
  28. package/dist/types/embedpdf/search.d.ts +9 -0
  29. package/dist/types/embedpdf/stage.d.ts +31 -0
  30. package/dist/types/index.d.ts +2 -0
  31. package/dist/types/pdf-renderer/index.d.ts +2 -0
  32. package/dist/types/pdf-renderer/pdf-renderer.d.ts +31 -0
  33. package/docs/api.json +54 -0
  34. package/docs/embedpdf.md +171 -0
  35. package/docs/llms.txt +32 -0
  36. package/docs/pdf-renderer.md +123 -0
  37. package/docs/search-index.json +24 -0
  38. package/package.json +66 -4
@@ -0,0 +1,299 @@
1
+ import { createComponent, memo } from "@solidjs/web";
2
+ import { Match, Show, Switch, createContext, createEffect, createMemo, createSignal, onSettled, useContext } from "solid-js";
3
+ import { DocumentsToken, createKernel, documentState, isLocalEngine, shallowEqual, standInFor, viewerSettingsOf } from "@embedpdf/core";
4
+ import { browserClock, browserPrinter, browserTextMeasurer } from "@embedpdf/web";
5
+ // src/embedpdf/runtime.tsx
6
+ /**
7
+ * Follow a kernel's changes with a signal. The kernel can report a change from inside a plugin
8
+ * call made anywhere (an effect, a memo's plugin read), so the signal opts in to writes under an
9
+ * owner: the one narrow place that needs it.
10
+ */
11
+ function bindKernel(kernel) {
12
+ const [version, setVersion] = createSignal(0, {
13
+ ownedWrite: true,
14
+ name: "kernel version"
15
+ });
16
+ return {
17
+ kernel,
18
+ version,
19
+ unbind: kernel.subscribe(() => setVersion((v) => v + 1))
20
+ };
21
+ }
22
+ /** A kernel for the browser: its clock, printer, text measurer and `fetch`. */
23
+ function createBrowserKernel(engine, plugins) {
24
+ return createKernel({
25
+ engine,
26
+ plugins,
27
+ clock: browserClock(),
28
+ printer: browserPrinter(),
29
+ measurer: browserTextMeasurer(),
30
+ fetch: (url, init) => globalThis.fetch(url, init)
31
+ });
32
+ }
33
+ const KernelContext = createContext();
34
+ /** The document a subtree is bound to; null follows the active document. */
35
+ const DocumentScopeContext = createContext(() => null);
36
+ /** Gives a subtree a kernel someone else created and owns (a renderer that loads its engine first). */
37
+ function KernelProvider(props) {
38
+ const binding = () => props.binding;
39
+ return createComponent(KernelContext, {
40
+ value: binding,
41
+ get children() {
42
+ return props.children;
43
+ }
44
+ });
45
+ }
46
+ const tokenOf = (input) => typeof input === "function" ? input() : input;
47
+ /** The kernel in context, as an accessor: read it in a handler, a memo or JSX. */
48
+ function useKernel() {
49
+ const binding = useContext(KernelContext);
50
+ return () => binding().kernel;
51
+ }
52
+ /** A value derived from the kernel, as a memo that changes only when the answer does. */
53
+ function useKernelValue(select, isEqual = Object.is) {
54
+ const binding = useContext(KernelContext);
55
+ return createMemo(() => {
56
+ const { kernel, version } = binding();
57
+ version();
58
+ return select(kernel);
59
+ }, { equals: isEqual });
60
+ }
61
+ /** The document the nearest `DocumentScope` names, or null to follow the active document. */
62
+ function useDocumentScope() {
63
+ return useContext(DocumentScopeContext);
64
+ }
65
+ /** The document this subtree talks to: the nearest `DocumentScope`'s, else the active one. */
66
+ function useDocumentId() {
67
+ const scoped = useDocumentScope();
68
+ return useKernelValue((kernel) => scoped() ?? kernel.documents.getActiveId());
69
+ }
70
+ /** Binds a subtree to one document (side-by-side views, tabs). */
71
+ function DocumentScope(props) {
72
+ const id = () => props.id;
73
+ return createComponent(DocumentScopeContext, {
74
+ value: id,
75
+ get children() {
76
+ return props.children;
77
+ }
78
+ });
79
+ }
80
+ /** The capability, or null while it can't resolve. */
81
+ function useOptionalCapability(token) {
82
+ const scoped = useDocumentScope();
83
+ return useKernelValue((kernel) => kernel.tryCapability(tokenOf(token), scoped() ?? void 0));
84
+ }
85
+ /** The capability now, or its stand-in while there is no ready document (a call then refuses). */
86
+ function resolveCapability(kernel, token, scoped = null) {
87
+ const capability = kernel.tryCapability(token, scoped ?? void 0);
88
+ if (capability) return capability;
89
+ if (kernel.scopeOf(token) === "document") return standInFor(kernel, token);
90
+ return kernel.capability(token);
91
+ }
92
+ /** The capability as an accessor, for effects that bind to it. */
93
+ function useCapabilityValue(token) {
94
+ const scoped = useDocumentScope();
95
+ return useKernelValue((kernel) => resolveCapability(kernel, tokenOf(token), scoped()));
96
+ }
97
+ const READ = /^(get|list|is|has|can)[A-Z]/;
98
+ /**
99
+ * A plugin's API as one object that never changes, for handlers and effects: `stage.zoomIn()`.
100
+ * Each call resolves the capability at call time, so a handler always reaches the current
101
+ * document. A method named get/list/is/has/can… is a read: called in JSX or a memo, it follows
102
+ * the kernel. Every other method is only called.
103
+ */
104
+ function useCapability(token) {
105
+ const binding = useContext(KernelContext);
106
+ const scoped = useDocumentScope();
107
+ return new Proxy({}, { get(_, key) {
108
+ const { kernel, version } = binding();
109
+ const capability = resolveCapability(kernel, tokenOf(token), scoped());
110
+ const value = capability[key];
111
+ if (typeof value !== "function") return value;
112
+ if (typeof key === "string" && READ.test(key)) return (...args) => {
113
+ version();
114
+ return value.apply(capability, args);
115
+ };
116
+ return value.bind(capability);
117
+ } });
118
+ }
119
+ /** A selector over a capability: throws while it can't resolve (inside a `DocumentGate` it can). */
120
+ function useSelector(token, select, isEqual = Object.is) {
121
+ const scoped = useDocumentScope();
122
+ return useKernelValue((kernel) => {
123
+ const resolved = tokenOf(token);
124
+ return select(kernel.tryCapability(resolved, scoped() ?? void 0) ?? kernel.capability(resolved, scoped() ?? void 0));
125
+ }, isEqual);
126
+ }
127
+ /** `useSelector` that reads `fallback` while the capability can't resolve. */
128
+ function useOptionalSelector(token, select, fallback, isEqual = Object.is) {
129
+ const scoped = useDocumentScope();
130
+ return useKernelValue((kernel) => {
131
+ const capability = kernel.tryCapability(tokenOf(token), scoped() ?? void 0);
132
+ if (!capability) return fallback;
133
+ try {
134
+ return select(capability);
135
+ } catch {
136
+ return fallback;
137
+ }
138
+ }, isEqual);
139
+ }
140
+ /** A capability's state declaration as an accessor (its `empty` state without a document). */
141
+ function useDeclared(token, read, empty, select) {
142
+ const scoped = useDocumentScope();
143
+ return useKernelValue((kernel) => {
144
+ const capability = kernel.tryCapability(token, scoped() ?? void 0);
145
+ const state = capability ? read(capability) : empty;
146
+ return select ? select(state) : state;
147
+ }, shallowEqual);
148
+ }
149
+ /** The document this subtree talks to: `id`, `name`, `status`, `pageCount`, why it's locked or failed. */
150
+ function useDocument() {
151
+ return useDeclared(DocumentsToken, documentState.read, documentState.empty);
152
+ }
153
+ const NO_PAGES = Object.freeze([]);
154
+ /** The document's pages, in order; the same array until one is added, moved or rotated. */
155
+ function usePageList() {
156
+ const documentId = useDocumentId();
157
+ return useKernelValue((kernel) => {
158
+ const id = documentId();
159
+ return id ? kernel.documents.listPages(id) : NO_PAGES;
160
+ });
161
+ }
162
+ /** The viewer's own settings (accent, page look), or the part `select` picks. */
163
+ function useViewerSettings(select) {
164
+ return useKernelValue((kernel) => select(kernel.getSettings()), shallowEqual);
165
+ }
166
+ /** Renders its children only once this subtree's document is open. */
167
+ function DocumentGate(props) {
168
+ const document = useDocument();
169
+ const status = createMemo(() => document().status);
170
+ return createComponent(Switch, {
171
+ get fallback() {
172
+ return props.fallback;
173
+ },
174
+ get children() {
175
+ return [
176
+ createComponent(Match, {
177
+ get when() {
178
+ return status() === "ready";
179
+ },
180
+ get children() {
181
+ return props.children;
182
+ }
183
+ }),
184
+ createComponent(Match, {
185
+ get when() {
186
+ return memo(() => {
187
+ return status() === "locked";
188
+ })() && props.locked;
189
+ },
190
+ get children() {
191
+ return props.locked?.(document());
192
+ }
193
+ }),
194
+ createComponent(Match, {
195
+ get when() {
196
+ return memo(() => {
197
+ return status() === "error";
198
+ })() && props.error;
199
+ },
200
+ get children() {
201
+ return props.error?.(document());
202
+ }
203
+ })
204
+ ];
205
+ }
206
+ });
207
+ }
208
+ /**
209
+ * Owns one kernel for its lifetime: created and started once mounted (in the browser only),
210
+ * destroyed with the component. `engine`, `plugins` and `initialDocuments` are read then, once.
211
+ */
212
+ function Viewer(props) {
213
+ const [binding, setBinding] = createSignal(null);
214
+ const [phase, setPhase] = createSignal("booting");
215
+ const [bootError, setBootError] = createSignal(void 0);
216
+ const settings = createMemo(() => viewerSettingsOf({
217
+ accent: props.accent,
218
+ page: props.page
219
+ }), { equals: shallowEqual });
220
+ onSettled(() => {
221
+ let current;
222
+ try {
223
+ current = bindKernel(createBrowserKernel(props.engine, props.plugins));
224
+ } catch (error) {
225
+ setBootError(error);
226
+ setPhase("error");
227
+ return;
228
+ }
229
+ const { kernel } = current;
230
+ kernel.updateSettings(settings());
231
+ if (isLocalEngine(props.engine)) props.engine.warmup();
232
+ const initialDocuments = props.initialDocuments ?? [];
233
+ const onReady = props.onReady;
234
+ let alive = true;
235
+ setBinding(current);
236
+ kernel.start().then(() => {
237
+ if (!alive) return;
238
+ onReady?.(kernel);
239
+ setPhase("ready");
240
+ kernel.documents.openAll(initialDocuments);
241
+ }, (error) => {
242
+ if (!alive) return;
243
+ setBootError(error);
244
+ setPhase("error");
245
+ });
246
+ return () => {
247
+ alive = false;
248
+ current.unbind();
249
+ kernel.destroy();
250
+ };
251
+ });
252
+ createEffect(() => ({
253
+ binding: binding(),
254
+ settings: settings()
255
+ }), ({ binding, settings }) => binding?.kernel.updateSettings(settings));
256
+ return createComponent(Switch, {
257
+ get fallback() {
258
+ return props.fallback;
259
+ },
260
+ get children() {
261
+ return [createComponent(Match, {
262
+ get when() {
263
+ return phase() === "error";
264
+ },
265
+ get children() {
266
+ return props.renderError?.(bootError());
267
+ }
268
+ }), createComponent(Match, {
269
+ get when() {
270
+ return binding();
271
+ },
272
+ keyed: true,
273
+ children: (current) => createComponent(KernelContext, {
274
+ value: () => current,
275
+ get children() {
276
+ return createComponent(Show, {
277
+ get when() {
278
+ return phase() === "ready";
279
+ },
280
+ get fallback() {
281
+ return props.fallback;
282
+ },
283
+ get children() {
284
+ return props.children;
285
+ }
286
+ });
287
+ }
288
+ })
289
+ })];
290
+ }
291
+ });
292
+ }
293
+ const PageContextContext = createContext();
294
+ const PageProvider = PageContextContext;
295
+ /** The page a layer is drawn on, inside a `Stage` page. */
296
+ function usePage() {
297
+ return useContext(PageContextContext);
298
+ }
299
+ export { DocumentGate, DocumentScope, KernelProvider, PageProvider, Viewer, bindKernel, createBrowserKernel, resolveCapability, useCapability, useCapabilityValue, useDeclared, useDocument, useDocumentId, useDocumentScope, useKernel, useKernelValue, useOptionalCapability, useOptionalSelector, usePage, usePageList, useSelector, useViewerSettings };
@@ -0,0 +1,114 @@
1
+ import { useCapability, useDeclared, useDocumentScope, useKernelValue, usePage } from "./runtime.js";
2
+ import { createComponent, effect, getNextElement, insert, memo, runHydrationEvents, setStyleProperty, spread, template } from "@solidjs/web";
3
+ import { For, Show, createMemo } from "solid-js";
4
+ import { SearchToken, searchState } from "@embedpdf/plugin-search";
5
+ import { createClickDetector, paint, searchHighlightsOf } from "@embedpdf/web";
6
+ // src/embedpdf/search.tsx
7
+ /**
8
+ * SearchLayer and the search hooks: a port of `@embedpdf/react/search`. The
9
+ * layer paints the page's matches; search itself is driven from the chrome.
10
+ */
11
+ var _tmpl$ = /* @__PURE__ */ template(`<div style=position:absolute;inset:0;pointer-events:none>`);
12
+ var _tmpl$2 = /* @__PURE__ */ template(`<svg style=position:absolute;inset:0;width:100%;height:100%;overflow:visible><polygon>`);
13
+ var _tmpl$3 = /* @__PURE__ */ template(`<div>`);
14
+ function useSearch() {
15
+ return useCapability(SearchToken);
16
+ }
17
+ function useSearchState(select) {
18
+ return useDeclared(SearchToken, searchState.read, searchState.empty, select);
19
+ }
20
+ const NO_HITS = Object.freeze([]);
21
+ function useSearchHits(page) {
22
+ const scoped = useDocumentScope();
23
+ return useKernelValue((kernel) => {
24
+ const which = page?.();
25
+ return kernel.tryCapability(SearchToken, scoped() ?? void 0)?.listHits(which === void 0 ? void 0 : { page: which }) ?? NO_HITS;
26
+ });
27
+ }
28
+ function SearchLayer(props) {
29
+ const page = usePage();
30
+ const hits = useSearchHits(createMemo(() => page.ref));
31
+ const active = useSearchState((state) => state.activeHit);
32
+ const highlight = useKernelValue((kernel) => kernel.settingsOf(SearchToken).getSettings().highlight);
33
+ const clicks = createClickDetector();
34
+ const pieces = createMemo(() => hits().length === 0 ? [] : searchHighlightsOf(hits(), {
35
+ active: active(),
36
+ page: page.transform,
37
+ color: paint("search-highlight", highlight().color),
38
+ activeColor: paint("search-highlight-active", highlight().activeColor)
39
+ }));
40
+ const blend = () => paint("search-blend-mode", highlight().blendMode);
41
+ const handlers = (hit) => props.onHitClick ? {
42
+ onPointerDown: (event) => clicks.press(event),
43
+ onClick: (event) => {
44
+ if (clicks.isClick(event)) props.onHitClick?.(hit);
45
+ }
46
+ } : {};
47
+ const clickable = () => props.onHitClick ? {
48
+ "pointer-events": "auto",
49
+ cursor: "pointer"
50
+ } : {};
51
+ return memo(() => {
52
+ return memo(() => {
53
+ return pieces().length > 0;
54
+ })() ? (() => {
55
+ var _el$ = getNextElement(_tmpl$);
56
+ insert(_el$, createComponent(For, {
57
+ get each() {
58
+ return pieces();
59
+ },
60
+ keyed: (piece) => piece.key,
61
+ children: (piece) => createComponent(Show, {
62
+ get when() {
63
+ return piece().box;
64
+ },
65
+ get fallback() {
66
+ var _el$2 = getNextElement(_tmpl$2);
67
+ var _el$3 = _el$2.firstChild;
68
+ spread(_el$3, [
69
+ { get points() {
70
+ return piece().points ?? void 0;
71
+ } },
72
+ () => {
73
+ return handlers(piece().hit);
74
+ },
75
+ { get style() {
76
+ return {
77
+ fill: piece().fill,
78
+ ...clickable()
79
+ };
80
+ } }
81
+ ], false);
82
+ effect(() => blend(), (_v$) => {
83
+ setStyleProperty(_el$2, "mix-blend-mode", _v$);
84
+ });
85
+ runHydrationEvents();
86
+ return _el$2;
87
+ },
88
+ children: (box) => (() => {
89
+ var _el$4 = getNextElement(_tmpl$3);
90
+ spread(_el$4, [() => {
91
+ return handlers(piece().hit);
92
+ }, { get style() {
93
+ return {
94
+ position: "absolute",
95
+ left: `${box().left}px`,
96
+ top: `${box().top}px`,
97
+ width: `${box().width}px`,
98
+ height: `${box().height}px`,
99
+ "background-color": piece().fill,
100
+ "mix-blend-mode": blend(),
101
+ "border-radius": "2px",
102
+ ...clickable()
103
+ };
104
+ } }], false);
105
+ runHydrationEvents();
106
+ return _el$4;
107
+ })()
108
+ })
109
+ }));
110
+ return _el$;
111
+ })() : void 0;
112
+ });
113
+ }
114
+ export { SearchLayer, useSearch, useSearchHits, useSearchState };
@@ -0,0 +1,224 @@
1
+ import { PageProvider, useCapability, useCapabilityValue, useDocumentId, useDocumentScope, useKernelValue, useOptionalCapability, useSelector, useViewerSettings } from "./runtime.js";
2
+ import { className, createComponent, delegateEvents, effect, getNextElement, insert, memo, readShallow, ref, runHydrationEvents, scope, setAttribute, style, template } from "@solidjs/web";
3
+ import { For, createContext, createEffect, createMemo, useContext } from "solid-js";
4
+ import { shallowEqual, toPageRef } from "@embedpdf/core";
5
+ import { createScrollHandler, createZoomDragHandler, stageState } from "@embedpdf/plugin-stage";
6
+ import { createStageSurface, makePageContext, pageSurfaceLayout, paint, stagePageDemand } from "@embedpdf/web";
7
+ import { StageToken as StageToken$1 } from "@embedpdf/plugin-stage/contract";
8
+ import { InteractionToken } from "@embedpdf/plugin-interaction/contract/host";
9
+ // src/embedpdf/stage.tsx
10
+ /**
11
+ * The Stage: a port of `@embedpdf/react/stage`. It positions the visible pages
12
+ * by the camera and hands each one to the children, which bring the layers.
13
+ * Layout, gestures and visibility are `@embedpdf/web`'s and the plugin's; this
14
+ * file is only the binding.
15
+ */
16
+ var _tmpl$ = /* @__PURE__ */ template(`<div style=position:absolute>`);
17
+ var _tmpl$2 = /* @__PURE__ */ template(`<div style=position:absolute;isolation:isolate;user-select:none;-webkit-user-select:none>`);
18
+ var _tmpl$3 = /* @__PURE__ */ template(`<div style=position:relative;overflow:hidden;touch-action:none>`);
19
+ const StageTokenContext = createContext(null);
20
+ /** The lens a stage hook binds to: the explicit one, else the nearest Stage, else the main one. */
21
+ function useStageToken(explicit) {
22
+ const scoped = useContext(StageTokenContext);
23
+ return () => explicit?.() ?? scoped ?? StageToken$1;
24
+ }
25
+ const px = (box) => ({
26
+ left: `${box.left}px`,
27
+ top: `${box.top}px`,
28
+ width: `${box.width}px`,
29
+ height: `${box.height}px`
30
+ });
31
+ const sameFrame = (a, b) => a.top === b.top && a.right === b.right && a.bottom === b.bottom && a.left === b.left;
32
+ function PageSurface(props) {
33
+ let content;
34
+ const look = useViewerSettings((settings) => settings.page);
35
+ const layout = createMemo(() => pageSurfaceLayout(props.page.transform, props.frame, {
36
+ x: props.page.screenX,
37
+ y: props.page.screenY
38
+ }));
39
+ const objectNumber = createMemo(() => props.page.ref.objectNumber);
40
+ const pageRef = createMemo(() => toPageRef(objectNumber()));
41
+ const current = createMemo(() => makePageContext(props.documentId, props.stage.getLensId(), pageRef(), props.page.pageIndex, props.frame, props.page.transform, () => content.getBoundingClientRect(), () => stagePageDemand(props.stage, objectNumber(), props.page.transform.deviceWidth)));
42
+ const page = new Proxy({}, { get(_, key) {
43
+ const context = current();
44
+ const value = context[key];
45
+ return typeof value === "function" ? value.bind(context) : value;
46
+ } });
47
+ var _el$ = getNextElement(_tmpl$);
48
+ insert(_el$, createComponent(PageProvider, {
49
+ value: page,
50
+ get children() {
51
+ return [
52
+ (() => {
53
+ var _el$2 = getNextElement(_tmpl$);
54
+ effect(() => ({
55
+ ...px(layout().shadow),
56
+ "box-shadow": paint("page-shadow", look().shadow)
57
+ }), (_v$, _$p) => {
58
+ style(_el$2, _v$, _$p);
59
+ });
60
+ return _el$2;
61
+ })(),
62
+ (() => {
63
+ var _el$3 = getNextElement(_tmpl$2);
64
+ ref(() => {
65
+ return (el) => content = el;
66
+ }, _el$3);
67
+ insert(_el$3, scope(() => {
68
+ return props.render(page);
69
+ }));
70
+ effect(() => ({
71
+ ...px(layout().content),
72
+ background: paint("page-background", look().background),
73
+ transform: layout().turn ?? void 0
74
+ }), (_v$, _$p) => {
75
+ style(_el$3, _v$, _$p);
76
+ });
77
+ return _el$3;
78
+ })(),
79
+ memo(() => {
80
+ return props.chrome?.(page);
81
+ })
82
+ ];
83
+ }
84
+ }));
85
+ effect(() => ({ ...px(layout().outer) }), (_v$, _$p) => {
86
+ style(_el$, _v$, _$p);
87
+ });
88
+ return _el$;
89
+ }
90
+ /** How far an arrow key scrolls, in CSS pixels. */
91
+ const ARROW_STEP = 48;
92
+ function Stage(props) {
93
+ const token = useStageToken(() => props.token);
94
+ const hostToken = () => token();
95
+ const stage = useCapabilityValue(hostToken);
96
+ const ix = useOptionalCapability(InteractionToken);
97
+ const interaction = useSelector(token, (s) => s.getSettings().interaction);
98
+ const panFallback = useSelector(token, (s) => s.getSettings().panFallback);
99
+ const zoomGestures = useSelector(token, (s) => s.getSettings().zoomGestures);
100
+ const useHub = createMemo(() => interaction() && !!ix());
101
+ const cursor = useKernelValue(() => ix()?.getCursor() ?? "default");
102
+ const documentId = useDocumentId();
103
+ const pages = useSelector(token, (s) => s.listVisiblePages());
104
+ const frame = useSelector(token, (s) => s.getSettings().pageFrame, sameFrame);
105
+ let element;
106
+ const onKeyDown = (event) => {
107
+ if (props.keyboard === false || event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;
108
+ if (event.target !== event.currentTarget) return;
109
+ const view = stage();
110
+ const screen = view.getViewportSize().height * .9;
111
+ const move = {
112
+ ArrowDown: () => view.scrollBy({ top: ARROW_STEP }),
113
+ ArrowUp: () => view.scrollBy({ top: -48 }),
114
+ ArrowRight: () => view.scrollBy({ left: ARROW_STEP }),
115
+ ArrowLeft: () => view.scrollBy({ left: -48 }),
116
+ PageDown: () => view.scrollBy({ top: screen }),
117
+ PageUp: () => view.scrollBy({ top: -screen }),
118
+ " ": () => view.scrollBy({ top: event.shiftKey ? -screen : screen }),
119
+ Home: () => view.goToFirstPage(),
120
+ End: () => view.goToLastPage()
121
+ }[event.key];
122
+ if (!move) return;
123
+ event.preventDefault();
124
+ move();
125
+ };
126
+ createEffect(() => ({
127
+ stage: stage(),
128
+ ix: ix(),
129
+ hub: useHub(),
130
+ zoomGestures: zoomGestures(),
131
+ panFallback: panFallback()
132
+ }), ({ stage, ix, hub, zoomGestures, panFallback }) => {
133
+ if (!element) return;
134
+ const detach = createStageSurface(element, stage, {
135
+ hub: hub ? ix : null,
136
+ source: stage.getLensId(),
137
+ zoomGestures
138
+ });
139
+ const source = { source: stage.getLensId() };
140
+ const offScroll = hub && ix ? ix.registerHandler(createScrollHandler(stage, ix, { panFallback }), source) : null;
141
+ const offZoom = hub && ix ? ix.registerHandler(createZoomDragHandler(stage, ix), source) : null;
142
+ return () => {
143
+ offZoom?.();
144
+ offScroll?.();
145
+ detach();
146
+ };
147
+ });
148
+ var _el$4 = getNextElement(_tmpl$3);
149
+ _el$4._$$keydown = onKeyDown;
150
+ ref(() => {
151
+ return (el) => element = el;
152
+ }, _el$4);
153
+ insert(_el$4, createComponent(StageTokenContext, {
154
+ get value() {
155
+ return token();
156
+ },
157
+ get children() {
158
+ return [createComponent(For, {
159
+ get each() {
160
+ return pages();
161
+ },
162
+ keyed: (page) => page.ref.objectNumber,
163
+ children: (page) => createComponent(PageSurface, {
164
+ get documentId() {
165
+ return documentId() ?? "";
166
+ },
167
+ get page() {
168
+ return page();
169
+ },
170
+ get frame() {
171
+ return frame();
172
+ },
173
+ get stage() {
174
+ return stage();
175
+ },
176
+ get render() {
177
+ return props.children;
178
+ },
179
+ get chrome() {
180
+ return props.pageChrome;
181
+ }
182
+ })
183
+ }), memo(() => {
184
+ return props.overlay;
185
+ })];
186
+ }
187
+ }));
188
+ effect(() => {
189
+ return {
190
+ e: readShallow(props.class),
191
+ t: props.keyboard === false ? void 0 : 0,
192
+ a: props.keyboard === false ? void 0 : "document",
193
+ o: props["aria-label"],
194
+ i: {
195
+ cursor: useHub() ? cursor() : void 0,
196
+ ...props.style
197
+ }
198
+ };
199
+ }, ({ e, t, a, o, i }, _p$) => {
200
+ className(_el$4, e, _p$?.e);
201
+ t !== _p$?.t && setAttribute(_el$4, "tabindex", t);
202
+ a !== _p$?.a && setAttribute(_el$4, "role", a);
203
+ o !== _p$?.o && setAttribute(_el$4, "aria-label", o);
204
+ style(_el$4, i, _p$?.i);
205
+ });
206
+ runHydrationEvents();
207
+ return _el$4;
208
+ }
209
+ /** The Stage's API: zoom, navigation, reveal. */
210
+ function useStage(token) {
211
+ return useCapability(useStageToken(() => token));
212
+ }
213
+ /** The view's state (zoom, current page, page count…), or the part `select` picks. */
214
+ function useStageState(select, token) {
215
+ const lens = useStageToken(() => token);
216
+ const scoped = useDocumentScope();
217
+ return useKernelValue((kernel) => {
218
+ const stage = kernel.tryCapability(lens(), scoped() ?? void 0);
219
+ const state = stage ? stageState.read(stage) : stageState.empty;
220
+ return select ? select(state) : state;
221
+ }, shallowEqual);
222
+ }
223
+ delegateEvents(["keydown"]);
224
+ export { Stage, useStage, useStageState };
@@ -0,0 +1,8 @@
1
+ import { loadLocalEngine } from "./embedpdf/engine.js";
2
+ import { DocumentGate, DocumentScope, KernelProvider, PageProvider, Viewer, bindKernel, createBrowserKernel, resolveCapability, useCapability, useCapabilityValue, useDeclared, useDocument, useDocumentId, useDocumentScope, useKernel, useKernelValue, useOptionalCapability, useOptionalSelector, usePage, usePageList, useSelector, useViewerSettings } from "./embedpdf/runtime.js";
3
+ import { RenderLayer } from "./embedpdf/render.js";
4
+ import { SearchLayer, useSearch, useSearchHits, useSearchState } from "./embedpdf/search.js";
5
+ import { Stage, useStage, useStageState } from "./embedpdf/stage.js";
6
+ import { pdfRenderer } from "./pdf-renderer/pdf-renderer.js";
7
+ import { SearchToken, StageToken, createCapabilityToken, renderPlugin, searchPlugin, stagePlugin, stageState } from "./embedpdf/index.js";
8
+ export { DocumentGate, DocumentScope, KernelProvider, PageProvider, RenderLayer, SearchLayer, SearchToken, Stage, StageToken, Viewer, bindKernel, createBrowserKernel, createCapabilityToken, loadLocalEngine, pdfRenderer, renderPlugin, resolveCapability, searchPlugin, stagePlugin, stageState, useCapability, useCapabilityValue, useDeclared, useDocument, useDocumentId, useDocumentScope, useKernel, useKernelValue, useOptionalCapability, useOptionalSelector, usePage, usePageList, useSearch, useSearchHits, useSearchState, useSelector, useStage, useStageState, useViewerSettings };
@@ -0,0 +1 @@
1
+ export { pdfRenderer } from "./pdf-renderer.js";