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