@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,171 @@
1
+ # EmbedPDF for Solid
2
+
3
+ <!-- search: embedpdf, pdf headless, pdf hooks, custom pdf viewer, pdfium, pdf pages, pdf stage -->
4
+
5
+ A Solid binding for [EmbedPDF](https://www.embedpdf.com)'s headless viewer, for a PDF view of your own when the FileViewer's isn't the one you want: your own toolbar, two documents side by side, a page strip in a form. EmbedPDF's plugins hold the state and logic; these components draw it. It's a port of `@embedpdf/react`'s layer, with the same names and the same hooks, returning accessors.
6
+
7
+ ```tsx
8
+ import { onSettled, createSignal, Show } from "solid-js";
9
+ import {
10
+ DocumentGate,
11
+ loadLocalEngine,
12
+ RenderLayer,
13
+ renderPlugin,
14
+ SearchLayer,
15
+ searchPlugin,
16
+ Stage,
17
+ stagePlugin,
18
+ useStage,
19
+ useStageState,
20
+ Viewer,
21
+ type Engine,
22
+ } from "@zsherman/pdf/embedpdf";
23
+
24
+ const plugins = [stagePlugin(), renderPlugin(), searchPlugin()];
25
+ const report = async () => ({
26
+ kind: "bytes" as const,
27
+ id: "report",
28
+ bytes: new Uint8Array(await (await fetch("/report.pdf")).arrayBuffer()),
29
+ });
30
+
31
+ function Zoom() {
32
+ const stage = useStage();
33
+ const view = useStageState();
34
+ return (
35
+ <div>
36
+ <button onClick={() => stage.zoomOut()}>−</button>
37
+ {Math.round(view().zoomLevel * 100)}%<button onClick={() => stage.zoomIn()}>+</button>
38
+ Page {view().currentPageIndex + 1} of {view().pageCount}
39
+ </div>
40
+ );
41
+ }
42
+
43
+ export function ReportView() {
44
+ const [engine, setEngine] = createSignal<Engine | null>(null);
45
+ onSettled(() => {
46
+ void loadLocalEngine().then(setEngine);
47
+ });
48
+ return (
49
+ <Show when={engine()}>
50
+ {(ready) => (
51
+ <Viewer engine={ready()} plugins={plugins} initialDocuments={[{ source: report }]}>
52
+ <DocumentGate fallback={<p>Opening…</p>}>
53
+ <Zoom />
54
+ <Stage aria-label="Report" style={{ height: "40rem" }}>
55
+ {() => (
56
+ <>
57
+ <RenderLayer />
58
+ <SearchLayer />
59
+ </>
60
+ )}
61
+ </Stage>
62
+ </DocumentGate>
63
+ </Viewer>
64
+ )}
65
+ </Show>
66
+ );
67
+ }
68
+ ```
69
+
70
+ ## Parts
71
+
72
+ | Part | What it does |
73
+ | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
74
+ | `Viewer` | Owns a kernel: created and started once mounted, destroyed with the component. `engine`, `plugins`, `initialDocuments` (read once), `fallback`, `renderError`, `onReady`, `accent`, `page` |
75
+ | `KernelProvider` | Gives a subtree a kernel you created yourself (`bindKernel(createBrowserKernel(engine, plugins))`), for code that must reach it from outside the view (the PDF renderer does) |
76
+ | `DocumentGate` | Its children only once the document is open; `fallback`, `locked(document)`, `error(document)` |
77
+ | `DocumentScope` | Binds a subtree to one document (`id`), for tabs or side by side |
78
+ | `Stage` | The pages, positioned by the camera, only the visible ones mounted; children is a function of each page. `pageChrome` (per-page bands: a number), `overlay`, `token` (another lens: a thumbnail rail), `keyboard` (default `true`), `aria-label` |
79
+ | `RenderLayer` | A page's picture: one image, and sharper tiles once zoomed past it. `thumbnail` for a small one |
80
+ | `SearchLayer` | The page's search matches; `onHitClick(hit)` makes them clickable |
81
+
82
+ A thumbnail rail is a second Stage on its own lens:
83
+
84
+ ```tsx
85
+ const ThumbsToken = createCapabilityToken<StageCapability>("stage-thumbs");
86
+ const plugins = [
87
+ stagePlugin(),
88
+ stagePlugin({
89
+ id: "stage-thumbs",
90
+ token: ThumbsToken,
91
+ interaction: false,
92
+ zoomGestures: false,
93
+ zoom: { pageWidth: 112 },
94
+ pageFrame: { bottom: 20 },
95
+ }),
96
+ renderPlugin(),
97
+ ];
98
+
99
+ const main = useStage();
100
+ <Stage token={ThumbsToken} keyboard={false} pageChrome={(page) => <span>{page.pageIndex + 1}</span>}>
101
+ {(page) => (
102
+ <button onClick={() => main.goToPage(page.ref)} aria-label={`Page ${page.pageIndex + 1}`}>
103
+ <RenderLayer thumbnail />
104
+ </button>
105
+ )}
106
+ </Stage>;
107
+ ```
108
+
109
+ ## Hooks
110
+
111
+ Every hook reads the document of the nearest `DocumentScope`, else the active one, and returns an accessor that changes only when its answer does.
112
+
113
+ | Hook | Returns |
114
+ | ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
115
+ | `useStage(token?)` | The Stage's API: `zoomIn()`, `zoomTo(level)`, `fitWidth()`, `goToPage(index)`, `rotateViewBy(90)`, `scrollBy({ top })`, … |
116
+ | `useStageState(select?, token?)` | `zoomLevel`, `zoomMode`, `currentPageIndex`, `pageCount`, … |
117
+ | `useSearch()` | `search({ text })`, `nextHit()`, `previousHit()`, `clear()` |
118
+ | `useSearchState(select?)` | `hitCount`, `activeHitIndex`, `status`, `activeHit` |
119
+ | `useSearchHits(page?)` | The matches found so far, or one page's |
120
+ | `useCapability(token)` | Any plugin's API, as one object for handlers. Its `get…`, `list…`, `is…`, `has…`, `can…` methods follow the kernel when read in JSX or a memo |
121
+ | `useKernelValue(select, isEqual?)` | Anything derived from the kernel |
122
+ | `useDocument()`, `usePageList()` | The document's info, its pages |
123
+ | `usePage()` | Inside a Stage page: the page's `ref`, `pageIndex`, `transform` (read in JSX or memos) |
124
+
125
+ The API objects never change, so call them from handlers and effects. Read state through the state hooks, in JSX or memos.
126
+
127
+ ## Gotchas
128
+
129
+ - Create the engine in the browser only: `loadLocalEngine()` in `onSettled`, as above. `Viewer` itself creates its kernel once mounted.
130
+ - `plugins` is read once: define it at module level, not inline in JSX.
131
+ - The rest of EmbedPDF (annotations, forms, selection, redaction) works with these parts' kernel, but its drawing layers aren't ported yet; their plugins' APIs are there.
132
+
133
+ ## API reference: `@zsherman/pdf/embedpdf`
134
+
135
+ <!-- generated:props:embedpdf (node tooling/props-doc.ts; edit the JSDoc in the source, not this table) -->
136
+
137
+ Generated from the types of `@zsherman/pdf/embedpdf`. Each part also takes its element's native and ARIA attributes.
138
+
139
+ #### `DocumentGate`
140
+
141
+ No props beyond the element's attributes.
142
+
143
+ #### `DocumentScope`
144
+
145
+ No props beyond the element's attributes.
146
+
147
+ #### `KernelProvider`
148
+
149
+ No props beyond the element's attributes.
150
+
151
+ #### `PageProvider`
152
+
153
+ No props beyond the element's attributes.
154
+
155
+ #### `Viewer`
156
+
157
+ No props beyond the element's attributes.
158
+
159
+ #### `Stage`
160
+
161
+ No props beyond the element's attributes.
162
+
163
+ #### `RenderLayer`
164
+
165
+ No props beyond the element's attributes.
166
+
167
+ #### `SearchLayer`
168
+
169
+ No props beyond the element's attributes.
170
+
171
+ <!-- /generated:props:embedpdf -->
package/docs/llms.txt ADDED
@@ -0,0 +1,32 @@
1
+ # @zsherman/pdf
2
+
3
+ > PDFs for @zsherman/kit: a renderer that shows PDFs in the kit's FileViewer (pages that stay sharp at any zoom, search with highlights, page thumbnails, rotation, print, a password prompt), and a Solid binding for EmbedPDF's headless viewer (PDFium compiled to WebAssembly, in a worker) for building your own. Themed with the kit's `--sui-*` tokens. Your app does not need a StyleX compiler.
4
+
5
+ Read this file first, then the pages for what you use. These docs ship in the package, so they match the installed version.
6
+
7
+ ## Setup
8
+
9
+ ```sh
10
+ npm install @zsherman/pdf @zsherman/kit solid-js@^2 @solidjs/web@^2
11
+ ```
12
+
13
+ Load both stylesheets once, in the app entry, the kit's first:
14
+
15
+ ```ts
16
+ import "@zsherman/kit/styles.css";
17
+ import "@zsherman/pdf/styles.css";
18
+ ```
19
+
20
+ The engine (`@embedpdf/engine`: about 2.4 MB of WebAssembly and a worker, brotli) is imported the first time a PDF opens, in the browser only: your bundler gives it chunks of their own, and a page that shows no PDF never loads it. A server render shows the loading state. If your server bundle includes the engine anyway (an SSR build that bundles dynamic imports), alias `@embedpdf/engine` to a stub there: [pdf-renderer.md#server-rendering](./pdf-renderer.md#server-rendering).
21
+
22
+ Common tasks:
23
+
24
+ - Show PDFs in the kit's FileViewer: [pdf-renderer.md](./pdf-renderer.md)
25
+ - A protected PDF (password): [pdf-renderer.md#protected-pdfs](./pdf-renderer.md#protected-pdfs)
26
+ - Your own engine (a self-hosted WebAssembly, EmbedPDF's cloud engine): [pdf-renderer.md#the-engine](./pdf-renderer.md#the-engine)
27
+ - Your own PDF viewer from EmbedPDF's parts (pages, layers, hooks): [embedpdf.md](./embedpdf.md)
28
+
29
+ ## Components
30
+
31
+ - `@zsherman/pdf/pdf-renderer` — `pdfRenderer` (a `FileRenderer` for `FileViewer`), `PdfRendererOptions`, `PdfLabels` — [pdf-renderer.md](./pdf-renderer.md)
32
+ - `@zsherman/pdf/embedpdf` — `Viewer`, `KernelProvider`, `DocumentGate`, `Stage`, `RenderLayer`, `SearchLayer`, `useStage`, `useStageState`, `useSearch`, `useSearchState`, `useCapability`, `useKernelValue`, `loadLocalEngine`, the plugins (`stagePlugin`, `renderPlugin`, `searchPlugin`) — [embedpdf.md](./embedpdf.md)
@@ -0,0 +1,123 @@
1
+ # PDF viewer
2
+
3
+ <!-- search: pdf, pdf viewer, pdf preview, pdf reader, document viewer, view pdf, pdf.js, react-pdf, embedpdf, pdfium -->
4
+
5
+ Shows PDFs in the kit's [FileViewer](https://solid-ui.zach-sh.workers.dev/components/file-viewer): pages that render sharp at any zoom, search with highlights, page thumbnails, rotation, print and a password prompt for protected files. Pass `pdfRenderer()` in `renderers`; the viewer's other kinds of file (images, Markdown, CSV, code) keep working beside it.
6
+
7
+ ```tsx
8
+ import { FileViewer } from "@zsherman/kit/file-viewer";
9
+ import { pdfRenderer } from "@zsherman/pdf/pdf-renderer";
10
+
11
+ const renderers = [pdfRenderer()];
12
+
13
+ <FileViewer
14
+ file={{ name: "Annual report 2026.pdf", src: "/files/annual-report.pdf" }}
15
+ renderers={renderers}
16
+ />;
17
+ ```
18
+
19
+ ## Usage guidelines
20
+
21
+ **Pick it for** PDFs people read in your app: invoices, contracts, reports, statements, attachments. The pages are drawn by PDFium (Chrome's PDF engine) in a worker, so they look the same in every browser, including the mobile ones that can't show a PDF inline.
22
+
23
+ **Mind the weight.** The engine is about 2.4 MB of WebAssembly (brotli) plus a 200 KB worker, loaded the first time a PDF opens and then cached by the browser. Pages that never show a PDF never load it. For a link people only download, a plain link is lighter.
24
+
25
+ **Create the renderer once**, at module level or in a memo: a new `pdfRenderer()` in every render is a new renderer, and the viewer starts the file over.
26
+
27
+ ## What it does
28
+
29
+ | Control | How |
30
+ | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
31
+ | Pages | Previous, Next and the page field in the toolbar; the page view scrolls continuously |
32
+ | Zoom | Zoom out and in (25%–400% in steps), the level (pressing it fits the page, then the width), Ctrl/⌘ + wheel or a pinch around the pointer |
33
+ | Rotate | A quarter clockwise, for the whole view |
34
+ | Search | Ctrl/⌘ F or the toolbar's Search: matches highlight on the pages as they're found, Enter and Shift+Enter move between them |
35
+ | Thumbnails | The Pages toggle (`defaultSidebarOpen` opens it at first): the current page is outlined and follows the reader; a thumbnail goes to its page |
36
+ | Print | Prints the document at the printer's resolution |
37
+ | Keyboard | The page view takes focus: the arrows scroll, Page Up and Page Down (Space, Shift+Space) move a screen, Home and End go to the first and last page |
38
+
39
+ Text selection, links inside the PDF, annotations and forms aren't drawn yet: the pages are pictures with search highlights over them.
40
+
41
+ ## Protected PDFs
42
+
43
+ A PDF with a password opens on a prompt (a password field and Open). A wrong password says so and keeps the field. Its words are in `labels`:
44
+
45
+ ```tsx
46
+ pdfRenderer({
47
+ labels: {
48
+ lockedTitle: "Ce PDF est protégé",
49
+ lockedDescription: "Saisissez son mot de passe pour l'ouvrir.",
50
+ password: "Mot de passe",
51
+ unlock: "Ouvrir",
52
+ wrongPassword: "Ce mot de passe ne l'ouvre pas.",
53
+ page: (page) => `Page ${page}`,
54
+ },
55
+ });
56
+ ```
57
+
58
+ `page` names each thumbnail ("Page 3"). The viewer's own words (toolbar, search, errors) are the FileViewer's `labels`.
59
+
60
+ ## The engine
61
+
62
+ Left out, `engine` is EmbedPDF's local engine, imported once for the page and shared by every viewer. Pass your own to configure it (a self-hosted WebAssembly URL, fonts) or to use EmbedPDF's cloud engine:
63
+
64
+ ```tsx
65
+ import { pdfRenderer } from "@zsherman/pdf/pdf-renderer";
66
+
67
+ const renderers = [
68
+ pdfRenderer({
69
+ engine: () => import("@embedpdf/engine").then((m) => m.localEngine({ wasmUrl: "/static/embedpdf.wasm" })),
70
+ }),
71
+ ];
72
+ ```
73
+
74
+ `engine` is called the first time a PDF opens, in the browser. Return the same engine every time (cache the promise) unless you want one per viewer.
75
+
76
+ ## Server rendering
77
+
78
+ The renderer imports the engine with `import()` once a PDF has mounted, so a server render never runs it. Some SSR builds bundle dynamic imports anyway, and the engine's WebAssembly then lands in the server bundle (a Cloudflare Worker refuses an upload that large). Alias the engine to a stub in the server build. With Vite:
79
+
80
+ ```ts
81
+ // vite.config.ts
82
+ function browserOnlyPdfEngine(): Plugin {
83
+ const stub = "\0embedpdf-engine-stub";
84
+ return {
85
+ name: "browser-only-pdf-engine",
86
+ enforce: "pre",
87
+ applyToEnvironment: (environment) => environment.name === "ssr",
88
+ resolveId: (source) => (source === "@embedpdf/engine" ? stub : null),
89
+ load: (id) => (id === stub ? "export function localEngine() { throw new Error('browser only'); }" : null),
90
+ };
91
+ }
92
+ ```
93
+
94
+ ## API reference
95
+
96
+ <!-- generated:props:pdf-renderer (node tooling/props-doc.ts) -->
97
+ <!-- /generated:props:pdf-renderer -->
98
+
99
+ `pdfRenderer(options?: PdfRendererOptions): FileRenderer`
100
+
101
+ | Option | Type | Default | Notes |
102
+ | --------- | ------------------------------- | ---------------------------- | --------------------------------------------------------------------------------------- |
103
+ | `engine` | `() => Promise<Engine>` | EmbedPDF's local engine | Called the first time a PDF opens, in the browser |
104
+ | `accepts` | `(file: FileSource) => boolean` | `.pdf` and `application/pdf` | Which files this renderer shows |
105
+ | `labels` | `Partial<PdfLabels>` | English | `lockedTitle`, `lockedDescription`, `password`, `unlock`, `wrongPassword`, `page(page)` |
106
+
107
+ ### CSS variables
108
+
109
+ The page view sets EmbedPDF's variables from the kit's tokens; override them on an ancestor of the viewer (`.my-viewer [data-renderer=pdf] { … }`).
110
+
111
+ | Variable | Default |
112
+ | -------------------------------- | ---------------------------------------------- |
113
+ | `--epdf-search-highlight` | `--sui-warning` at 38% |
114
+ | `--epdf-search-highlight-active` | `--sui-accent` at 45% |
115
+ | `--epdf-page-shadow` | A hairline and a soft shadow |
116
+ | `--epdf-page-background` | White (pages are paper in either color scheme) |
117
+
118
+ ## Gotchas
119
+
120
+ - The PDF is read whole (`file.bytes()`) before its first page draws; a 50 MB scan takes a moment on a slow connection.
121
+ - `print` opens the browser's print dialog with the pages rendered for print; popup blockers don't affect it.
122
+ - Each viewer starts a kernel and opens the file; closing the viewer (or changing `file`) closes it and frees the worker's memory for it. The engine stays loaded for the next PDF.
123
+ - With `skipLibCheck: false` and `moduleResolution: "node16"`, TypeScript reports one error inside EmbedPDF 3.4.0's own declarations (`@embedpdf/engine-core`, TS2552 "Cannot find name 'infer'"): a bundling bug upstream, not in your code. `skipLibCheck: true` (the default in most templates) or `moduleResolution: "bundler"` avoids it.
@@ -0,0 +1,24 @@
1
+ {"records":[
2
+ {"id":"embedpdf.md","kind":"page","title":"EmbedPDF for Solid","page":"EmbedPDF for Solid","doc":"embedpdf.md","entry":"@zsherman/pdf/embedpdf","keywords":"embedpdf, pdf headless, pdf hooks, custom pdf viewer, pdfium, pdf pages, pdf stage","text":"A Solid binding for EmbedPDF's headless viewer, for a PDF view of your own when the FileViewer's isn't the one you want: your own toolbar, two documents side by side, a page strip in a form. EmbedPDF's plugins hold the state and logic; these components draw it. It's a port of @embedpdf/react's layer, with the same names and the same hooks, returning accessors."},
3
+ {"id":"embedpdf.md#parts","kind":"section","title":"Parts","page":"EmbedPDF for Solid","doc":"embedpdf.md","anchor":"parts","text":"Viewer · Owns a kernel: created and started once mounted, destroyed with the component. engine, plugins, initialDocuments (read once), fallback, renderError, onReady, accent, page KernelProvider · Gives a subtree a kernel you created yourself (bindKernel(createBrowserKernel(engine, plugins))), for code that must reach it from outside the view (the PDF renderer does) DocumentGate · Its children only once the document is open; fallback, locked(document), error(document) DocumentScope · Binds a subtree to one document (id), for tabs or side by side Stage · The pages, positioned by the camera, only the visible ones mounted; children is a function of each page. pageChrome (per-page bands: a number), overlay, token (another lens: a thumbnail rail), keyboard (default true), aria-label RenderLayer · A page's picture: one image, and sharper tiles once zoomed past it. thumbnail for a small one SearchLayer · The page's search matches; onHitClick(hit) makes them clickable A thumbnail rail is a second Stage on its own lens:","code":"ThumbsToken createCapabilityToken StageCapability stage-thumbs plugins stagePlugin token interaction zoomGestures zoom pageWidth pageFrame bottom renderPlugin main useStage Stage keyboard pageChrome page span pageIndex button onClick goToPage ref aria-label Page RenderLayer thumbnail"},
4
+ {"id":"embedpdf.md#hooks","kind":"section","title":"Hooks","page":"EmbedPDF for Solid","doc":"embedpdf.md","anchor":"hooks","text":"Every hook reads the document of the nearest DocumentScope, else the active one, and returns an accessor that changes only when its answer does. useStage(token?) · The Stage's API: zoomIn(), zoomTo(level), fitWidth(), goToPage(index), rotateViewBy(90), scrollBy({ top }), … useStageState(select?, token?) · zoomLevel, zoomMode, currentPageIndex, pageCount, … useSearch() · search({ text }), nextHit(), previousHit(), clear() useSearchState(select?) · hitCount, activeHitIndex, status, activeHit useSearchHits(page?) · The matches found so far, or one page's useCapability(token) · Any plugin's API, as one object for handlers. Its get…, list…, is…, has…, can… methods follow the kernel when read in JSX or a memo useKernelValue(select, isEqual?) · Anything derived from the kernel useDocument(), usePageList() · The document's info, its pages usePage() · Inside a Stage page: the page's ref, pageIndex, transform (read in JSX or memos) The API objects never change, so call them from handlers and effects. Read state through the state hooks, in JSX or memos."},
5
+ {"id":"embedpdf.md#gotchas","kind":"section","title":"Gotchas","page":"EmbedPDF for Solid","doc":"embedpdf.md","anchor":"gotchas","text":"Create the engine in the browser only: loadLocalEngine() in onSettled, as above. Viewer itself creates its kernel once mounted. plugins is read once: define it at module level, not inline in JSX. The rest of EmbedPDF (annotations, forms, selection, redaction) works with these parts' kernel, but its drawing layers aren't ported yet; their plugins' APIs are there."},
6
+ {"id":"embedpdf.md#api-reference-zshermanpdfembedpdf","kind":"section","title":"API reference: @zsherman/pdf/embedpdf","page":"EmbedPDF for Solid","doc":"embedpdf.md","anchor":"api-reference-zshermanpdfembedpdf","text":""},
7
+ {"id":"pdf-renderer.md","kind":"page","title":"PDF viewer","page":"PDF viewer","doc":"pdf-renderer.md","entry":"@zsherman/pdf/pdf-renderer","keywords":"pdf, pdf viewer, pdf preview, pdf reader, document viewer, view pdf, pdf.js, react-pdf, embedpdf, pdfium","text":"Shows PDFs in the kit's FileViewer: pages that render sharp at any zoom, search with highlights, page thumbnails, rotation, print and a password prompt for protected files. Pass pdfRenderer() in renderers; the viewer's other kinds of file (images, Markdown, CSV, code) keep working beside it."},
8
+ {"id":"pdf-renderer.md#usage-guidelines","kind":"section","title":"Usage guidelines","page":"PDF viewer","doc":"pdf-renderer.md","anchor":"usage-guidelines","text":"Pick it for PDFs people read in your app: invoices, contracts, reports, statements, attachments. The pages are drawn by PDFium (Chrome's PDF engine) in a worker, so they look the same in every browser, including the mobile ones that can't show a PDF inline. Mind the weight. The engine is about 2.4 MB of WebAssembly (brotli) plus a 200 KB worker, loaded the first time a PDF opens and then cached by the browser. Pages that never show a PDF never load it. For a link people only download, a plain link is lighter. Create the renderer once, at module level or in a memo: a new pdfRenderer() in every render is a new renderer, and the viewer starts the file over."},
9
+ {"id":"pdf-renderer.md#what-it-does","kind":"section","title":"What it does","page":"PDF viewer","doc":"pdf-renderer.md","anchor":"what-it-does","text":"Pages · Previous, Next and the page field in the toolbar; the page view scrolls continuously Zoom · Zoom out and in (25%–400% in steps), the level (pressing it fits the page, then the width), Ctrl/⌘ + wheel or a pinch around the pointer Rotate · A quarter clockwise, for the whole view Search · Ctrl/⌘ F or the toolbar's Search: matches highlight on the pages as they're found, Enter and Shift+Enter move between them Thumbnails · The Pages toggle (defaultSidebarOpen opens it at first): the current page is outlined and follows the reader; a thumbnail goes to its page Print · Prints the document at the printer's resolution Keyboard · The page view takes focus: the arrows scroll, Page Up and Page Down (Space, Shift+Space) move a screen, Home and End go to the first and last page Text selection, links inside the PDF, annotations and forms aren't drawn yet: the pages are pictures with search highlights over them."},
10
+ {"id":"pdf-renderer.md#protected-pdfs","kind":"section","title":"Protected PDFs","page":"PDF viewer","doc":"pdf-renderer.md","anchor":"protected-pdfs","text":"A PDF with a password opens on a prompt (a password field and Open). A wrong password says so and keeps the field. Its words are in labels: page names each thumbnail (\"Page 3\"). The viewer's own words (toolbar, search, errors) are the FileViewer's labels.","code":"pdfRenderer labels lockedTitle PDF est prot lockedDescription Saisissez son mot passe pour ouvrir password Mot unlock Ouvrir wrongPassword ouvre pas page Page"},
11
+ {"id":"pdf-renderer.md#the-engine","kind":"section","title":"The engine","page":"PDF viewer","doc":"pdf-renderer.md","anchor":"the-engine","text":"Left out, engine is EmbedPDF's local engine, imported once for the page and shared by every viewer. Pass your own to configure it (a self-hosted WebAssembly URL, fonts) or to use EmbedPDF's cloud engine: engine is called the first time a PDF opens, in the browser. Return the same engine every time (cache the promise) unless you want one per viewer.","code":"pdfRenderer zsherman pdf pdf-renderer renderers engine embedpdf then localEngine wasmUrl static wasm"},
12
+ {"id":"pdf-renderer.md#server-rendering","kind":"section","title":"Server rendering","page":"PDF viewer","doc":"pdf-renderer.md","anchor":"server-rendering","text":"The renderer imports the engine with import() once a PDF has mounted, so a server render never runs it. Some SSR builds bundle dynamic imports anyway, and the engine's WebAssembly then lands in the server bundle (a Cloudflare Worker refuses an upload that large). Alias the engine to a stub in the server build. With Vite:","code":"browserOnlyPdfEngine Plugin stub embedpdf-engine-stub name browser-only-pdf-engine enforce pre applyToEnvironment environment ssr resolveId source embedpdf engine load localEngine throw Error browser only"},
13
+ {"id":"pdf-renderer.md#api-reference","kind":"section","title":"API reference","page":"PDF viewer","doc":"pdf-renderer.md","anchor":"api-reference","text":"pdfRenderer(options?: PdfRendererOptions): FileRenderer engine · () => Promise<Engine> · EmbedPDF's local engine · Called the first time a PDF opens, in the browser accepts · (file: FileSource) => boolean ·.pdf and application/pdf · Which files this renderer shows labels · Partial<PdfLabels> · English · lockedTitle, lockedDescription, password, unlock, wrongPassword, page(page)"},
14
+ {"id":"pdf-renderer.md#css-variables","kind":"section","title":"CSS variables","page":"PDF viewer","parent":"API reference","doc":"pdf-renderer.md","anchor":"css-variables","text":"The page view sets EmbedPDF's variables from the kit's tokens; override them on an ancestor of the viewer (.my-viewer [data-renderer=pdf] { … }). --epdf-search-highlight · --sui-warning at 38% --epdf-search-highlight-active · --sui-accent at 45% --epdf-page-shadow · A hairline and a soft shadow --epdf-page-background · White (pages are paper in either color scheme)"},
15
+ {"id":"pdf-renderer.md#gotchas","kind":"section","title":"Gotchas","page":"PDF viewer","doc":"pdf-renderer.md","anchor":"gotchas","text":"The PDF is read whole (file.bytes()) before its first page draws; a 50 MB scan takes a moment on a slow connection. print opens the browser's print dialog with the pages rendered for print; popup blockers don't affect it. Each viewer starts a kernel and opens the file; closing the viewer (or changing file) closes it and frees the worker's memory for it. The engine stays loaded for the next PDF. With skipLibCheck: false and moduleResolution: \"node16\", TypeScript reports one error inside EmbedPDF 3.4.0's own declarations (@embedpdf/engine-core, TS2552 \"Cannot find name 'infer'\"): a bundling bug upstream, not in your code. skipLibCheck: true (the default in most templates) or moduleResolution: \"bundler\" avoids it."},
16
+ {"id":"api:embedpdf/DocumentGate","kind":"part","title":"DocumentGate","page":"EmbedPDF for Solid","doc":"embedpdf.md","anchor":"documentgate","entry":"@zsherman/pdf/embedpdf","text":"DocumentGate from @zsherman/pdf/embedpdf."},
17
+ {"id":"api:embedpdf/DocumentScope","kind":"part","title":"DocumentScope","page":"EmbedPDF for Solid","doc":"embedpdf.md","anchor":"documentscope","entry":"@zsherman/pdf/embedpdf","text":"DocumentScope from @zsherman/pdf/embedpdf."},
18
+ {"id":"api:embedpdf/KernelProvider","kind":"part","title":"KernelProvider","page":"EmbedPDF for Solid","doc":"embedpdf.md","anchor":"kernelprovider","entry":"@zsherman/pdf/embedpdf","text":"KernelProvider from @zsherman/pdf/embedpdf."},
19
+ {"id":"api:embedpdf/PageProvider","kind":"part","title":"PageProvider","page":"EmbedPDF for Solid","doc":"embedpdf.md","anchor":"pageprovider","entry":"@zsherman/pdf/embedpdf","text":"PageProvider from @zsherman/pdf/embedpdf."},
20
+ {"id":"api:embedpdf/Viewer","kind":"part","title":"Viewer","page":"EmbedPDF for Solid","doc":"embedpdf.md","anchor":"viewer","entry":"@zsherman/pdf/embedpdf","text":"Viewer from @zsherman/pdf/embedpdf."},
21
+ {"id":"api:embedpdf/Stage","kind":"part","title":"Stage","page":"EmbedPDF for Solid","doc":"embedpdf.md","anchor":"stage","entry":"@zsherman/pdf/embedpdf","text":"Stage from @zsherman/pdf/embedpdf."},
22
+ {"id":"api:embedpdf/RenderLayer","kind":"part","title":"RenderLayer","page":"EmbedPDF for Solid","doc":"embedpdf.md","anchor":"renderlayer","entry":"@zsherman/pdf/embedpdf","text":"RenderLayer from @zsherman/pdf/embedpdf."},
23
+ {"id":"api:embedpdf/SearchLayer","kind":"part","title":"SearchLayer","page":"EmbedPDF for Solid","doc":"embedpdf.md","anchor":"searchlayer","entry":"@zsherman/pdf/embedpdf","text":"SearchLayer from @zsherman/pdf/embedpdf."}
24
+ ]}
package/package.json CHANGED
@@ -1,6 +1,68 @@
1
1
  {
2
2
  "name": "@zsherman/pdf",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.4.0",
4
+ "description": "PDFs for @zsherman/kit: a renderer that shows PDFs in the kit's FileViewer (pages, zoom, search, thumbnails, print) and a Solid binding for EmbedPDF's headless viewer (PDFium in a worker), themed with the kit's --sui-* tokens.",
5
+ "license": "MPL-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/zsherman/solid-ui.git",
9
+ "directory": "packages/pdf"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "docs",
14
+ "README.md",
15
+ "THIRD_PARTY_NOTICES.md",
16
+ "LICENSE",
17
+ "CHANGELOG.md"
18
+ ],
19
+ "type": "module",
20
+ "sideEffects": [
21
+ "*.css"
22
+ ],
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/types/index.d.ts",
26
+ "solid": "./dist/solid/index.jsx",
27
+ "default": "./dist/dom/index.js"
28
+ },
29
+ "./pdf-renderer": {
30
+ "types": "./dist/types/pdf-renderer/index.d.ts",
31
+ "solid": "./dist/solid/pdf-renderer/index.jsx",
32
+ "default": "./dist/dom/pdf-renderer/index.js"
33
+ },
34
+ "./embedpdf": {
35
+ "types": "./dist/types/embedpdf/index.d.ts",
36
+ "solid": "./dist/solid/embedpdf/index.jsx",
37
+ "default": "./dist/dom/embedpdf/index.js"
38
+ },
39
+ "./styles.css": "./dist/styles.css",
40
+ "./package.json": "./package.json"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "scripts": {
46
+ "build": "rm -rf dist && vp pack && node ../../tooling/compose-package-css.ts . dist/solid/assets/stylex.css dist/dom/assets/stylex.css && node ../../tooling/css-guard.ts dist/styles.css && tsrs -p tsconfig.build.json && node ../../tooling/dts-extensions.ts dist/types",
47
+ "typecheck": "tsrs -p tsconfig.json"
48
+ },
49
+ "dependencies": {
50
+ "@embedpdf/core": "3.4.0",
51
+ "@embedpdf/core-geometry": "3.4.0",
52
+ "@embedpdf/engine": "3.4.0",
53
+ "@embedpdf/plugin-interaction": "3.4.0",
54
+ "@embedpdf/plugin-render": "3.4.0",
55
+ "@embedpdf/plugin-search": "3.4.0",
56
+ "@embedpdf/plugin-stage": "3.4.0",
57
+ "@embedpdf/web": "3.4.0",
58
+ "@stylexjs/stylex": "0.19.2"
59
+ },
60
+ "devDependencies": {
61
+ "@zsherman/kit": "0.4.0"
62
+ },
63
+ "peerDependencies": {
64
+ "@solidjs/web": "^2.0.3",
65
+ "@zsherman/kit": "^0.4.0",
66
+ "solid-js": "^2.0.3"
67
+ }
68
+ }