@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 { loadLocalEngine } from "../embedpdf/engine.jsx";
|
|
2
|
+
import { RenderLayer } from "../embedpdf/render.jsx";
|
|
3
|
+
import { DocumentGate, KernelProvider, bindKernel, createBrowserKernel, useKernel } from "../embedpdf/runtime.jsx";
|
|
4
|
+
import { SearchLayer } from "../embedpdf/search.jsx";
|
|
5
|
+
import { Stage, useStage, useStageState } from "../embedpdf/stage.jsx";
|
|
6
|
+
import "@stylexjs/stylex";
|
|
7
|
+
import { Show, createEffect, createMemo, createSignal, onSettled } from "solid-js";
|
|
8
|
+
import { Button } from "@zsherman/kit/button";
|
|
9
|
+
import { EmptyState, EmptyStateActions, EmptyStateDescription, EmptyStateIcon, EmptyStateTitle } from "@zsherman/kit/empty-state";
|
|
10
|
+
import { Field, FieldError, Input } from "@zsherman/kit/field";
|
|
11
|
+
import { Lock } from "@zsherman/kit/icons";
|
|
12
|
+
import { Loader } from "@zsherman/kit/loader";
|
|
13
|
+
import { createCapabilityToken, shallowEqual } from "@embedpdf/core";
|
|
14
|
+
import { renderPlugin } from "@embedpdf/plugin-render";
|
|
15
|
+
import { SearchToken, searchPlugin, searchState } from "@embedpdf/plugin-search";
|
|
16
|
+
import { StageToken, stagePlugin, stageState } from "@embedpdf/plugin-stage";
|
|
17
|
+
// src/pdf-renderer/pdf-renderer.tsx
|
|
18
|
+
const english = {
|
|
19
|
+
lockedTitle: "This PDF is protected",
|
|
20
|
+
lockedDescription: "Enter its password to open it.",
|
|
21
|
+
password: "Password",
|
|
22
|
+
unlock: "Open",
|
|
23
|
+
wrongPassword: "That password didn't open it. Try again.",
|
|
24
|
+
page: (page) => `Page ${page}`
|
|
25
|
+
};
|
|
26
|
+
/** The page views fill their frame (the Stage sets its own `position`, so this goes in `style`). */
|
|
27
|
+
const fill = {
|
|
28
|
+
position: "absolute",
|
|
29
|
+
inset: "0"
|
|
30
|
+
};
|
|
31
|
+
const ThumbsToken = createCapabilityToken("stage-thumbs");
|
|
32
|
+
const isPdf = (file) => file.extension === "pdf" || file.type === "application/pdf";
|
|
33
|
+
/**
|
|
34
|
+
* Shows PDFs in `FileViewer`: pages that render sharp at any zoom, search with highlights, page
|
|
35
|
+
* thumbnails, rotation, print and a password prompt for protected files.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* <FileViewer file={file} renderers={[pdfRenderer()]} />
|
|
39
|
+
*/
|
|
40
|
+
function pdfRenderer(options = {}) {
|
|
41
|
+
const label = (key) => options.labels?.[key] ?? english[key];
|
|
42
|
+
return {
|
|
43
|
+
name: "pdf",
|
|
44
|
+
accepts: options.accepts ?? isPdf,
|
|
45
|
+
render: (file) => createPdfView(file, options.engine ?? loadLocalEngine, label)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function createPdfView(file, loadEngine, label) {
|
|
49
|
+
const [binding, setBinding] = createSignal(null);
|
|
50
|
+
const [failure, setFailure] = createSignal(null);
|
|
51
|
+
onSettled(() => {
|
|
52
|
+
let alive = true;
|
|
53
|
+
let opened;
|
|
54
|
+
loadEngine().then(async (engine) => {
|
|
55
|
+
if (!alive) return;
|
|
56
|
+
const kernel = createBrowserKernel(engine, [
|
|
57
|
+
stagePlugin(),
|
|
58
|
+
stagePlugin({
|
|
59
|
+
id: "stage-thumbs",
|
|
60
|
+
token: ThumbsToken,
|
|
61
|
+
interaction: false,
|
|
62
|
+
zoomGestures: false,
|
|
63
|
+
zoom: { pageWidth: 112 },
|
|
64
|
+
gap: { px: 16 },
|
|
65
|
+
padding: 16,
|
|
66
|
+
pageFrame: { bottom: 22 }
|
|
67
|
+
}),
|
|
68
|
+
renderPlugin(),
|
|
69
|
+
searchPlugin()
|
|
70
|
+
]);
|
|
71
|
+
opened = bindKernel(kernel);
|
|
72
|
+
await kernel.start();
|
|
73
|
+
if (!alive) return;
|
|
74
|
+
kernel.documents.openAll([{
|
|
75
|
+
name: file.name,
|
|
76
|
+
source: async () => ({
|
|
77
|
+
kind: "bytes",
|
|
78
|
+
id: "file",
|
|
79
|
+
bytes: await file.bytes()
|
|
80
|
+
})
|
|
81
|
+
}]);
|
|
82
|
+
setBinding(opened);
|
|
83
|
+
}).catch((error) => {
|
|
84
|
+
if (alive) setFailure({ error });
|
|
85
|
+
});
|
|
86
|
+
return () => {
|
|
87
|
+
alive = false;
|
|
88
|
+
opened?.unbind();
|
|
89
|
+
opened?.kernel.destroy();
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
/** A value read from the kernel, `fallback` until it has started. */
|
|
93
|
+
const read = (pick, fallback) => createMemo(() => {
|
|
94
|
+
const current = binding();
|
|
95
|
+
if (!current) return fallback;
|
|
96
|
+
current.version();
|
|
97
|
+
return pick(current.kernel);
|
|
98
|
+
}, { equals: shallowEqual });
|
|
99
|
+
const stageOf = (kernel) => kernel.tryCapability(StageToken);
|
|
100
|
+
const searchOf = (kernel) => kernel.tryCapability(SearchToken);
|
|
101
|
+
const view = read((kernel) => {
|
|
102
|
+
const stage = stageOf(kernel);
|
|
103
|
+
return stage ? stageState.read(stage) : stageState.empty;
|
|
104
|
+
}, stageState.empty);
|
|
105
|
+
const found = read((kernel) => {
|
|
106
|
+
const search = searchOf(kernel);
|
|
107
|
+
return search ? searchState.read(search) : searchState.empty;
|
|
108
|
+
}, searchState.empty);
|
|
109
|
+
const withStage = (act) => {
|
|
110
|
+
const current = binding();
|
|
111
|
+
const stage = current && stageOf(current.kernel);
|
|
112
|
+
if (stage) act(stage);
|
|
113
|
+
};
|
|
114
|
+
const withSearch = (act) => {
|
|
115
|
+
const current = binding();
|
|
116
|
+
const search = current && searchOf(current.kernel);
|
|
117
|
+
if (search) act(search);
|
|
118
|
+
};
|
|
119
|
+
const fit = () => {
|
|
120
|
+
const mode = view().zoomMode;
|
|
121
|
+
return mode === "fit-width" ? "width" : mode === "fit-page" ? "page" : null;
|
|
122
|
+
};
|
|
123
|
+
const inKernel = (children) => <Show when={binding()} keyed>
|
|
124
|
+
{(current) => <KernelProvider binding={current}>{children(current)}</KernelProvider>}
|
|
125
|
+
</Show>;
|
|
126
|
+
return {
|
|
127
|
+
content: () => <>
|
|
128
|
+
<Failure failure={failure()} />
|
|
129
|
+
<Show when={binding()} fallback={<Busy />}>
|
|
130
|
+
{inKernel(() => <DocumentGate fallback={<Busy />} locked={(document) => <Unlock id={document.id} label={label} />} error={(document) => <Failure failure={{ error: new Error(document.error?.message ?? "The PDF couldn't be opened.") }} />}>
|
|
131
|
+
<Stage aria-label={file.name} class={{ className: "x10l6tqk x10a8y8t x1a2a7pz x1ss01z5 x2ssjo2 xf530zi x1eucdj2 x1j96xhd x1l7gnak" }.className} style={fill}>
|
|
132
|
+
{() => <>
|
|
133
|
+
<RenderLayer />
|
|
134
|
+
<SearchLayer />
|
|
135
|
+
</>}
|
|
136
|
+
</Stage>
|
|
137
|
+
</DocumentGate>)}
|
|
138
|
+
</Show>
|
|
139
|
+
</>,
|
|
140
|
+
pages: {
|
|
141
|
+
index: () => view().currentPageIndex,
|
|
142
|
+
count: () => view().pageCount,
|
|
143
|
+
goTo: (index) => withStage((stage) => stage.goToPage(index))
|
|
144
|
+
},
|
|
145
|
+
zoom: {
|
|
146
|
+
level: () => view().zoomLevel,
|
|
147
|
+
fit,
|
|
148
|
+
zoomIn: () => withStage((stage) => stage.zoomIn()),
|
|
149
|
+
zoomOut: () => withStage((stage) => stage.zoomOut()),
|
|
150
|
+
setLevel: (level) => withStage((stage) => stage.zoomTo(level)),
|
|
151
|
+
setFit: (next) => withStage((stage) => next === "width" ? stage.fitWidth() : stage.fitPage())
|
|
152
|
+
},
|
|
153
|
+
rotate: () => withStage((stage) => stage.rotateViewBy(90)),
|
|
154
|
+
search: {
|
|
155
|
+
run: (text) => withSearch((search) => {
|
|
156
|
+
if (text) search.search({ text }).catch(() => {});
|
|
157
|
+
else search.clear();
|
|
158
|
+
}),
|
|
159
|
+
next: () => withSearch((search) => void search.nextHit()),
|
|
160
|
+
previous: () => withSearch((search) => void search.previousHit()),
|
|
161
|
+
count: () => found().hitCount,
|
|
162
|
+
active: () => found().activeHitIndex,
|
|
163
|
+
pending: () => found().status === "searching"
|
|
164
|
+
},
|
|
165
|
+
print: () => {
|
|
166
|
+
const current = binding();
|
|
167
|
+
if (current) current.kernel.documents.print().catch(() => {});
|
|
168
|
+
},
|
|
169
|
+
thumbnails: () => inKernel(() => <DocumentGate>
|
|
170
|
+
<Thumbnails label={label} />
|
|
171
|
+
</DocumentGate>)
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/** Throws the failure, if there is one, to the viewer's error boundary. */
|
|
175
|
+
function Failure(props) {
|
|
176
|
+
const thrown = createMemo(() => {
|
|
177
|
+
const failure = props.failure;
|
|
178
|
+
if (failure) throw failure.error;
|
|
179
|
+
return null;
|
|
180
|
+
});
|
|
181
|
+
return <>{thrown()}</>;
|
|
182
|
+
}
|
|
183
|
+
function Busy() {
|
|
184
|
+
return <div class={{ className: "x10l6tqk x10a8y8t xrvj5dj x1ku5rj1 x1ezasi3" }.className}>
|
|
185
|
+
<Loader />
|
|
186
|
+
</div>;
|
|
187
|
+
}
|
|
188
|
+
function Unlock(props) {
|
|
189
|
+
const [password, setPassword] = createSignal("");
|
|
190
|
+
const [wrong, setWrong] = createSignal(false);
|
|
191
|
+
const kernel = useKernel();
|
|
192
|
+
const submit = async (event) => {
|
|
193
|
+
event.preventDefault();
|
|
194
|
+
setWrong(false);
|
|
195
|
+
try {
|
|
196
|
+
await kernel().documents.unlock(props.id, { password: password() });
|
|
197
|
+
} catch {
|
|
198
|
+
setWrong(true);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
return <div class={{ className: "x10l6tqk x10a8y8t xrvj5dj x1ku5rj1 x1ezasi3" }.className}>
|
|
202
|
+
<EmptyState>
|
|
203
|
+
<EmptyStateIcon icon={Lock} />
|
|
204
|
+
<EmptyStateTitle>{props.label("lockedTitle")}</EmptyStateTitle>
|
|
205
|
+
<EmptyStateDescription>{props.label("lockedDescription")}</EmptyStateDescription>
|
|
206
|
+
<EmptyStateActions>
|
|
207
|
+
<form class={{ className: "x78zum5 xdt5ytf x8rwxmg x1n24ytg" }.className} onSubmit={submit}>
|
|
208
|
+
<Field invalid={wrong()}>
|
|
209
|
+
<Input type="password" autofocus aria-label={props.label("password")} placeholder={props.label("password")} value={password()} onInput={(event) => setPassword(event.currentTarget.value)} />
|
|
210
|
+
<FieldError match>{props.label("wrongPassword")}</FieldError>
|
|
211
|
+
</Field>
|
|
212
|
+
<Button type="submit" variant="primary">
|
|
213
|
+
{props.label("unlock")}
|
|
214
|
+
</Button>
|
|
215
|
+
</form>
|
|
216
|
+
</EmptyStateActions>
|
|
217
|
+
</EmptyState>
|
|
218
|
+
</div>;
|
|
219
|
+
}
|
|
220
|
+
function Thumbnails(props) {
|
|
221
|
+
const main = useStage();
|
|
222
|
+
const thumbs = useStage(ThumbsToken);
|
|
223
|
+
const current = useStageState((state) => state.currentPageIndex);
|
|
224
|
+
createEffect(current, (index) => thumbs.reveal(index));
|
|
225
|
+
const number = (index) => new Intl.NumberFormat().format(index + 1);
|
|
226
|
+
return <Stage token={ThumbsToken} keyboard={false} style={fill} pageChrome={(page) => <span class={{ className: "x10l6tqk x17y0mx6 x1ey2m1c xmll18r x8r4c90 x2b8uid x13rcfk xb5fjo1 xe2mk2a xss6m8b" }.className} aria-hidden="true">
|
|
227
|
+
{number(page.pageIndex)}
|
|
228
|
+
</span>}>
|
|
229
|
+
{(page) => <button type="button" class={{ className: "x10l6tqk x10a8y8t x1717udv x1ghz6dp xc342km xjbqb8w x1ypdohk x1b6xorz x1k57tk5 x784prv xs8lkzz xaatb59 x1uczgqu xewgccq x1mhjs59 x1ewu8gn" }.className} aria-label={props.label("page")(number(page.pageIndex))} aria-current={page.pageIndex === current() ? "page" : void 0} onClick={() => main.goToPage(page.ref)}>
|
|
230
|
+
<RenderLayer thumbnail />
|
|
231
|
+
</button>}
|
|
232
|
+
</Stage>;
|
|
233
|
+
}
|
|
234
|
+
export { pdfRenderer };
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@layer sui.reset,ui-sdk,sui.base;@layer sui.components{@layer priority1{.xf530zi{--epdf-page-shadow:0 1px 3px #0000001f,0 0 0 1px #0000000a}.x1l7gnak{--epdf-search-blend-mode:multiply}.x1eucdj2{--epdf-search-highlight:color-mix(in oklab,var(--sui-warning) 38%,transparent)}.x1j96xhd{--epdf-search-highlight-active:color-mix(in oklab,var(--sui-accent) 45%,transparent)}}@layer priority2{.x10a8y8t{inset:0}.x1ghz6dp{margin:0}.x1717udv{padding:0}.x1ezasi3{padding:var(--sui-space-6)}}@layer priority3{.x1b6xorz{border-radius:var(--sui-radius-sm)}.xc342km{border-width:0}.x8rwxmg{gap:var(--sui-space-2)}.x17y0mx6{inset-inline:0}.x1a2a7pz{outline:none}.x1ku5rj1{place-items:center}.x1ss01z5:focus-visible{outline:2px solid var(--sui-focus)}}@layer priority4{.xjbqb8w{background-color:#0000}.xe2mk2a{color:var(--sui-text-muted)}.x1ypdohk{cursor:pointer}.x78zum5{display:flex}.xrvj5dj{display:grid}.xdt5ytf{flex-direction:column}.x13rcfk{font-family:var(--sui-font-sans)}.xb5fjo1{font-size:var(--sui-text-xs)}.xss6m8b{font-variant-numeric:tabular-nums}.x8r4c90{line-height:1.25rem}.x1uczgqu{outline-color:#0000}.x2ssjo2{outline-offset:-2px}.x1ewu8gn{outline-offset:3px}.xaatb59{outline-style:solid}.x1k57tk5{outline-width:0}.x10l6tqk{position:absolute}.x2b8uid{text-align:center}.x1mhjs59:focus-visible{outline-color:var(--sui-focus)}.x784prv:focus-visible{outline-width:2px}}@layer priority5{.x1ey2m1c{bottom:0}.xmll18r{height:1.25rem}.x1n24ytg{width:min(18rem,100%)}}@layer priority6{.xewgccq[aria-current=page]{outline-color:var(--sui-accent)}.xs8lkzz[aria-current=page]{outline-width:2px}}}@layer sui.theme;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Engine } from "@embedpdf/core";
|
|
2
|
+
/**
|
|
3
|
+
* EmbedPDF's local engine (PDFium compiled to WebAssembly, in a worker), imported the first time it's
|
|
4
|
+
* asked for and shared by every viewer on the page; a failed import is tried again next time. Browser
|
|
5
|
+
* only: call it once mounted (`onSettled`), never during a server render.
|
|
6
|
+
*/
|
|
7
|
+
export declare function loadLocalEngine(): Promise<Engine>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { loadLocalEngine } from "./engine.js";
|
|
2
|
+
export { bindKernel, createBrowserKernel, DocumentGate, DocumentScope, KernelProvider, PageProvider, resolveCapability, useCapability, useCapabilityValue, useDeclared, useDocument, useDocumentId, useDocumentScope, useKernel, useKernelValue, useOptionalCapability, useOptionalSelector, usePage, usePageList, useSelector, useViewerSettings, Viewer, } from "./runtime.js";
|
|
3
|
+
export type { DocumentGateProps, KernelBinding, PageContextValue, TokenInput, ViewerProps } from "./runtime.js";
|
|
4
|
+
export { Stage, useStage, useStageState } from "./stage.js";
|
|
5
|
+
export type { StageProps, StageTokenProp } from "./stage.js";
|
|
6
|
+
export { RenderLayer } from "./render.js";
|
|
7
|
+
export type { RenderLayerProps } from "./render.js";
|
|
8
|
+
export { SearchLayer, useSearch, useSearchHits, useSearchState } from "./search.js";
|
|
9
|
+
export { stagePlugin, StageToken, stageState } from "@embedpdf/plugin-stage";
|
|
10
|
+
export type { StageCapability, StagePluginOptions, StageState, VisiblePage } from "@embedpdf/plugin-stage";
|
|
11
|
+
export { renderPlugin } from "@embedpdf/plugin-render";
|
|
12
|
+
export { searchPlugin, SearchToken } from "@embedpdf/plugin-search";
|
|
13
|
+
export type { SearchCapability, SearchHit, SearchState } from "@embedpdf/plugin-search";
|
|
14
|
+
export { createCapabilityToken } from "@embedpdf/core";
|
|
15
|
+
export type { AnyPlugin, Engine, InitialDocument, Kernel, OpenInput } from "@embedpdf/core";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface RenderLayerProps {
|
|
2
|
+
annotations?: boolean;
|
|
3
|
+
formFields?: boolean;
|
|
4
|
+
/** Mount the tile plane (default true). */
|
|
5
|
+
tiles?: boolean;
|
|
6
|
+
/** Draw the page's thumbnail: one small picture, no tiles. */
|
|
7
|
+
thumbnail?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function RenderLayer(props: RenderLayerProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Solid binding for EmbedPDF's kernel, ported from `@embedpdf/react`'s runtime (Apache-2.0;
|
|
3
|
+
* UPSTREAM.md). The kernel has one change stream (`kernel.subscribe`) and plain reads: Solid binds
|
|
4
|
+
* it with one version signal per kernel, and every read is a memo over it that keeps its value
|
|
5
|
+
* while the answer compares equal, so nothing downstream re-runs for an unchanged answer.
|
|
6
|
+
*/
|
|
7
|
+
import type { JSX } from "@solidjs/web";
|
|
8
|
+
import { type Accessor } from "solid-js";
|
|
9
|
+
import type { AnyPlugin, CapabilityToken, DocumentInfo, Engine, FailedDocumentInfo, InitialDocument, Kernel, LockedDocumentInfo, PageInfo, ViewerPageSettings, ViewerSettings } from "@embedpdf/core";
|
|
10
|
+
import type { PageTransform } from "@embedpdf/core-geometry";
|
|
11
|
+
import type { PageViewDemand } from "@embedpdf/plugin-render/contract";
|
|
12
|
+
import type { PageContext } from "@embedpdf/web";
|
|
13
|
+
/** A kernel and the signal its changes bump: what every hook below reads through. */
|
|
14
|
+
export interface KernelBinding {
|
|
15
|
+
kernel: Kernel;
|
|
16
|
+
/** Bumped on every kernel change. */
|
|
17
|
+
version: Accessor<number>;
|
|
18
|
+
/** Stops following the kernel's changes (call before `kernel.destroy()`). */
|
|
19
|
+
unbind: () => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Follow a kernel's changes with a signal. The kernel can report a change from inside a plugin
|
|
23
|
+
* call made anywhere (an effect, a memo's plugin read), so the signal opts in to writes under an
|
|
24
|
+
* owner: the one narrow place that needs it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function bindKernel(kernel: Kernel): KernelBinding;
|
|
27
|
+
/** A kernel for the browser: its clock, printer, text measurer and `fetch`. */
|
|
28
|
+
export declare function createBrowserKernel(engine: Engine, plugins: AnyPlugin[]): Kernel;
|
|
29
|
+
/** Gives a subtree a kernel someone else created and owns (a renderer that loads its engine first). */
|
|
30
|
+
export declare function KernelProvider(props: {
|
|
31
|
+
binding: KernelBinding;
|
|
32
|
+
children?: JSX.Element;
|
|
33
|
+
}): JSX.Element;
|
|
34
|
+
/** A token, or an accessor of one (a prop that names the lens). */
|
|
35
|
+
export type TokenInput<C> = CapabilityToken<C> | (() => CapabilityToken<C>);
|
|
36
|
+
/** The kernel in context, as an accessor: read it in a handler, a memo or JSX. */
|
|
37
|
+
export declare function useKernel(): Accessor<Kernel>;
|
|
38
|
+
/** A value derived from the kernel, as a memo that changes only when the answer does. */
|
|
39
|
+
export declare function useKernelValue<R>(select: (kernel: Kernel) => R, isEqual?: (left: R, right: R) => boolean): Accessor<R>;
|
|
40
|
+
/** The document the nearest `DocumentScope` names, or null to follow the active document. */
|
|
41
|
+
export declare function useDocumentScope(): Accessor<string | null>;
|
|
42
|
+
/** The document this subtree talks to: the nearest `DocumentScope`'s, else the active one. */
|
|
43
|
+
export declare function useDocumentId(): Accessor<string | null>;
|
|
44
|
+
/** Binds a subtree to one document (side-by-side views, tabs). */
|
|
45
|
+
export declare function DocumentScope(props: {
|
|
46
|
+
id: string;
|
|
47
|
+
children: JSX.Element;
|
|
48
|
+
}): JSX.Element;
|
|
49
|
+
/** The capability, or null while it can't resolve. */
|
|
50
|
+
export declare function useOptionalCapability<C>(token: TokenInput<C>): Accessor<C | null>;
|
|
51
|
+
/** The capability now, or its stand-in while there is no ready document (a call then refuses). */
|
|
52
|
+
export declare function resolveCapability<C>(kernel: Kernel, token: CapabilityToken<C>, scoped?: string | null): C;
|
|
53
|
+
/** The capability as an accessor, for effects that bind to it. */
|
|
54
|
+
export declare function useCapabilityValue<C>(token: TokenInput<C>): Accessor<C>;
|
|
55
|
+
/**
|
|
56
|
+
* A plugin's API as one object that never changes, for handlers and effects: `stage.zoomIn()`.
|
|
57
|
+
* Each call resolves the capability at call time, so a handler always reaches the current
|
|
58
|
+
* document. A method named get/list/is/has/can… is a read: called in JSX or a memo, it follows
|
|
59
|
+
* the kernel. Every other method is only called.
|
|
60
|
+
*/
|
|
61
|
+
export declare function useCapability<C extends object>(token: TokenInput<C>): C;
|
|
62
|
+
/** A selector over a capability: throws while it can't resolve (inside a `DocumentGate` it can). */
|
|
63
|
+
export declare function useSelector<C, R>(token: TokenInput<C>, select: (capability: C) => R, isEqual?: (left: R, right: R) => boolean): Accessor<R>;
|
|
64
|
+
/** `useSelector` that reads `fallback` while the capability can't resolve. */
|
|
65
|
+
export declare function useOptionalSelector<C, R>(token: TokenInput<C>, select: (capability: C) => R, fallback: R, isEqual?: (left: R, right: R) => boolean): Accessor<R>;
|
|
66
|
+
/** A capability's state declaration as an accessor (its `empty` state without a document). */
|
|
67
|
+
export declare function useDeclared<C, State extends object, Selected>(token: CapabilityToken<C>, read: (capability: C) => State, empty: State, select?: (state: State) => Selected): Accessor<Selected>;
|
|
68
|
+
/** The document this subtree talks to: `id`, `name`, `status`, `pageCount`, why it's locked or failed. */
|
|
69
|
+
export declare function useDocument(): Accessor<DocumentInfo>;
|
|
70
|
+
/** The document's pages, in order; the same array until one is added, moved or rotated. */
|
|
71
|
+
export declare function usePageList(): Accessor<readonly PageInfo[]>;
|
|
72
|
+
/** The viewer's own settings (accent, page look), or the part `select` picks. */
|
|
73
|
+
export declare function useViewerSettings<Selected>(select: (settings: ViewerSettings) => Selected): Accessor<Selected>;
|
|
74
|
+
export interface DocumentGateProps {
|
|
75
|
+
/** Shown while there is no document, or it's still opening. */
|
|
76
|
+
fallback?: JSX.Element;
|
|
77
|
+
/** Shown while the document waits for its password; `fallback` without it. */
|
|
78
|
+
locked?: (document: LockedDocumentInfo) => JSX.Element;
|
|
79
|
+
/** Shown when the document couldn't be opened; `fallback` without it. */
|
|
80
|
+
error?: (document: FailedDocumentInfo) => JSX.Element;
|
|
81
|
+
children?: JSX.Element;
|
|
82
|
+
}
|
|
83
|
+
/** Renders its children only once this subtree's document is open. */
|
|
84
|
+
export declare function DocumentGate(props: DocumentGateProps): JSX.Element;
|
|
85
|
+
export interface ViewerProps {
|
|
86
|
+
/** The engine (`localEngine()` from `@embedpdf/engine`). Borrowed: the viewer never destroys it. */
|
|
87
|
+
engine: Engine;
|
|
88
|
+
/** The plugins (`stagePlugin()`, `renderPlugin()`, `searchPlugin()`, …). Read once. */
|
|
89
|
+
plugins: AnyPlugin[];
|
|
90
|
+
/** Documents to open once the kernel has started. Read once. */
|
|
91
|
+
initialDocuments?: InitialDocument[];
|
|
92
|
+
/** Shown until the kernel has started. */
|
|
93
|
+
fallback?: JSX.Element;
|
|
94
|
+
/** Shown when the kernel fails to start. */
|
|
95
|
+
renderError?: (error: unknown) => JSX.Element;
|
|
96
|
+
/** Called with the kernel once it has started, before the initial documents open. */
|
|
97
|
+
onReady?: (kernel: Kernel) => void;
|
|
98
|
+
/** The color every part without a color of its own follows; `--epdf-accent` wins over it. */
|
|
99
|
+
accent?: string;
|
|
100
|
+
/** How pages look: `background` before the picture arrives, and the `shadow` under each page. */
|
|
101
|
+
page?: Partial<ViewerPageSettings>;
|
|
102
|
+
children?: JSX.Element;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Owns one kernel for its lifetime: created and started once mounted (in the browser only),
|
|
106
|
+
* destroyed with the component. `engine`, `plugins` and `initialDocuments` are read then, once.
|
|
107
|
+
*/
|
|
108
|
+
export declare function Viewer(props: ViewerProps): JSX.Element;
|
|
109
|
+
/** The page every layer draws through: one stable object whose members read the current page. */
|
|
110
|
+
export type PageContextValue = PageContext<PageTransform, PageViewDemand>;
|
|
111
|
+
export declare const PageProvider: import("solid-js").Context<PageContextValue>;
|
|
112
|
+
/** The page a layer is drawn on, inside a `Stage` page. */
|
|
113
|
+
export declare function usePage(): PageContextValue;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import type { SearchCapability, SearchHit, SearchState } from "@embedpdf/plugin-search";
|
|
3
|
+
import type { PageRef } from "@embedpdf/core";
|
|
4
|
+
export declare function useSearch(): SearchCapability;
|
|
5
|
+
export declare function useSearchState<Selected = SearchState>(select?: (state: SearchState) => Selected): import("solid-js").Accessor<Selected>;
|
|
6
|
+
export declare function useSearchHits(page?: () => PageRef | number | undefined): import("solid-js").Accessor<readonly SearchHit[]>;
|
|
7
|
+
export declare function SearchLayer(props: {
|
|
8
|
+
onHitClick?: (hit: SearchHit) => void;
|
|
9
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import type { StageCapability, StageState } from "@embedpdf/plugin-stage";
|
|
3
|
+
import type { CapabilityToken } from "@embedpdf/core";
|
|
4
|
+
import { type PageContextValue, type TokenInput } from "./runtime.js";
|
|
5
|
+
export type StageTokenProp = CapabilityToken<StageCapability>;
|
|
6
|
+
export interface StageProps {
|
|
7
|
+
/** Page-space content for each visible page (RenderLayer, SearchLayer, …). */
|
|
8
|
+
children: (page: PageContextValue) => JSX.Element;
|
|
9
|
+
/** Box-space chrome for each page (a page number in the reserved frame). */
|
|
10
|
+
pageChrome?: (page: PageContextValue) => JSX.Element;
|
|
11
|
+
/** Viewport-space UI above the pages. */
|
|
12
|
+
overlay?: JSX.Element;
|
|
13
|
+
/** The lens to drive: default the nearest scope, else the main StageToken. */
|
|
14
|
+
token?: StageTokenProp;
|
|
15
|
+
/**
|
|
16
|
+
* Take keyboard focus and move with the keys: the arrows scroll, Page Up and Page Down (Space,
|
|
17
|
+
* Shift+Space) move a screen, Home and End go to the first and last page. Off for a thumbnail rail.
|
|
18
|
+
* @defaultValue true
|
|
19
|
+
*/
|
|
20
|
+
keyboard?: boolean;
|
|
21
|
+
/** The view's name for assistive technology (the document's name). */
|
|
22
|
+
"aria-label"?: string;
|
|
23
|
+
class?: string;
|
|
24
|
+
style?: JSX.CSSProperties;
|
|
25
|
+
}
|
|
26
|
+
export declare function Stage(props: StageProps): JSX.Element;
|
|
27
|
+
/** The Stage's API: zoom, navigation, reveal. */
|
|
28
|
+
export declare function useStage(token?: StageTokenProp): StageCapability;
|
|
29
|
+
/** The view's state (zoom, current page, page count…), or the part `select` picks. */
|
|
30
|
+
export declare function useStageState<Selected = StageState>(select?: (state: StageState) => Selected, token?: StageTokenProp): import("solid-js").Accessor<Selected>;
|
|
31
|
+
export type { TokenInput };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { FileRenderer, FileSource } from "@zsherman/kit/file-viewer";
|
|
2
|
+
import { type Engine } from "@embedpdf/core";
|
|
3
|
+
/** The renderer's own words, for what the viewer doesn't say (a locked PDF, a thumbnail's name). */
|
|
4
|
+
export interface PdfLabels {
|
|
5
|
+
lockedTitle: string;
|
|
6
|
+
lockedDescription: string;
|
|
7
|
+
password: string;
|
|
8
|
+
unlock: string;
|
|
9
|
+
wrongPassword: string;
|
|
10
|
+
/** A thumbnail's name, with its page number formatted (`"Page 3"`). */
|
|
11
|
+
page: (page: string) => string;
|
|
12
|
+
}
|
|
13
|
+
export interface PdfRendererOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The engine that reads PDFs. Left out, EmbedPDF's local engine (PDFium compiled to
|
|
16
|
+
* WebAssembly, in a worker): imported the first time a PDF opens and shared by every viewer.
|
|
17
|
+
*/
|
|
18
|
+
engine?: () => Promise<Engine>;
|
|
19
|
+
/** Which files this renderer shows. Left out: `.pdf` files and `application/pdf`. */
|
|
20
|
+
accepts?: (file: FileSource) => boolean;
|
|
21
|
+
/** Words for the password prompt and the thumbnails. */
|
|
22
|
+
labels?: Partial<PdfLabels>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Shows PDFs in `FileViewer`: pages that render sharp at any zoom, search with highlights, page
|
|
26
|
+
* thumbnails, rotation, print and a password prompt for protected files.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* <FileViewer file={file} renderers={[pdfRenderer()]} />
|
|
30
|
+
*/
|
|
31
|
+
export declare function pdfRenderer(options?: PdfRendererOptions): FileRenderer;
|
package/docs/api.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"embedpdf": {
|
|
3
|
+
"components": {
|
|
4
|
+
"DocumentGate": {
|
|
5
|
+
"props": [],
|
|
6
|
+
"dataAttributes": [],
|
|
7
|
+
"cssVariables": [],
|
|
8
|
+
"state": []
|
|
9
|
+
},
|
|
10
|
+
"DocumentScope": {
|
|
11
|
+
"props": [],
|
|
12
|
+
"dataAttributes": [],
|
|
13
|
+
"cssVariables": [],
|
|
14
|
+
"state": []
|
|
15
|
+
},
|
|
16
|
+
"KernelProvider": {
|
|
17
|
+
"props": [],
|
|
18
|
+
"dataAttributes": [],
|
|
19
|
+
"cssVariables": [],
|
|
20
|
+
"state": []
|
|
21
|
+
},
|
|
22
|
+
"PageProvider": {
|
|
23
|
+
"props": [],
|
|
24
|
+
"dataAttributes": [],
|
|
25
|
+
"cssVariables": [],
|
|
26
|
+
"state": []
|
|
27
|
+
},
|
|
28
|
+
"Viewer": {
|
|
29
|
+
"props": [],
|
|
30
|
+
"dataAttributes": [],
|
|
31
|
+
"cssVariables": [],
|
|
32
|
+
"state": []
|
|
33
|
+
},
|
|
34
|
+
"Stage": {
|
|
35
|
+
"props": [],
|
|
36
|
+
"dataAttributes": [],
|
|
37
|
+
"cssVariables": [],
|
|
38
|
+
"state": []
|
|
39
|
+
},
|
|
40
|
+
"RenderLayer": {
|
|
41
|
+
"props": [],
|
|
42
|
+
"dataAttributes": [],
|
|
43
|
+
"cssVariables": [],
|
|
44
|
+
"state": []
|
|
45
|
+
},
|
|
46
|
+
"SearchLayer": {
|
|
47
|
+
"props": [],
|
|
48
|
+
"dataAttributes": [],
|
|
49
|
+
"cssVariables": [],
|
|
50
|
+
"state": []
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|