@bonniepdf/previewer 0.0.0-stage → 2026.11.21

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or exemplary damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright © 2026 CodeFocus Limited
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,234 @@
1
- # Temporary Holding Version
1
+ # BonniePDF Previewer
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/@bonniepdf/previewer?label=%40bonniepdf%2Fpreviewer&color=2196F3&style=flat-square&logo=npm)](https://www.npmjs.com/package/@bonniepdf/previewer)
4
+ [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg?style=flat-square)](https://github.com/bonniepdf/BonniePDF-Previewer/blob/master/LICENSE)
5
+
6
+ [Documentation](https://www.bonniepdf.dev/docs/typescript/previewer) · [Accessibility inspector](https://www.bonniepdf.dev/docs/typescript/previewer-accessibility-view) · [Live examples](https://www.bonniepdf.dev/examples/industry-templates) · [BonniePDF for TypeScript](https://github.com/bonniepdf/BonniePDF-TypeScript) · [BonniePDF for .NET](https://github.com/bonniepdf/BonniePDF-NET) · [@bonniepdf/core on npm](https://www.npmjs.com/package/@bonniepdf/core) · [npm](https://www.npmjs.com/package/@bonniepdf/previewer)
7
+
8
+ Show BonniePDF documents in a web page before anyone downloads them. `@bonniepdf/previewer` is a framework-agnostic document viewer: a paginated, zoomable preview with a thumbnail rail, page navigation, fullscreen, a Download PDF button and an optional accessibility inspector. It ships as a `<bonnie-pdf-previewer>` web component inside a Shadow DOM, so host-page CSS cannot reach it.
9
+
10
+ The previewer is what runs on every page of the [live example gallery](https://www.bonniepdf.dev/examples), and inside the BonniePDF editor extensions.
11
+
12
+ It displays the vector SVG pages that BonniePDF itself produces. It is not a general-purpose PDF viewer: it does not open arbitrary PDF files, and it carries no PDF parser, canvas rasteriser or WASM rendering engine.
13
+
14
+ ## Why the previewer
15
+
16
+ - **Crisp at every zoom.** BonniePDF exports each page as vector SVG with glyphs placed by real font advance widths, so text and charts stay sharp at any zoom.
17
+ - **No rendering engine on the page.** No pdf.js, no pdfium, no WASM download. The pages are SVG the browser already knows how to draw.
18
+ - **Fully isolated.** Shadow DOM keeps host styles out and the document's embedded fonts in, and several viewers on one page never collide.
19
+ - **Lazy PDF.** Pages render straight away; the PDF bytes are only generated when someone clicks Download.
20
+ - **Accessibility preflight built in.** The inspector shows the document's tagged structure, PDF/UA-1 findings and WCAG contrast checks, and highlights each element on the page.
21
+ - **Works with either runtime.** Pass a TypeScript `Document`, or the JSON export from a .NET server or a web worker.
22
+ - **Any framework.** Use the custom element, or mount it into any element or shadow root with `createPreviewer()`.
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ npm install @bonniepdf/previewer @bonniepdf/core
28
+ ```
29
+
30
+ pnpm, Bun and Yarn work too. The package ships ESM and CommonJS entry points and has no runtime dependencies.
31
+
32
+ `@bonniepdf/core` is an optional peer dependency. You need it to preview a document you build in the browser; you do not need it to show an export generated somewhere else (see [Documents generated elsewhere](#documents-generated-elsewhere)).
33
+
34
+ ## Quick start
35
+
36
+ Register the element, place it on the page, and load a document:
37
+
38
+ ```html
39
+ <bonnie-pdf-previewer style="height: 80vh" label="Quarterly report"></bonnie-pdf-previewer>
40
+ ```
41
+
42
+ ```typescript
43
+ import { BonniePdfPreviewerElement } from '@bonniepdf/previewer/element'; // registers <bonnie-pdf-previewer>
44
+ import { Document } from '@bonniepdf/core';
45
+
46
+ const doc = new Document();
47
+ // ...build the document...
48
+
49
+ const viewer = document.querySelector<BonniePdfPreviewerElement>('bonnie-pdf-previewer')!;
50
+ await viewer.load(doc);
51
+ ```
52
+
53
+ `load(doc)` does the rest:
54
+
55
+ - renders the pages, capturing the layout snapshot only when an inspector plugin needs it;
56
+ - generates the PDF only if the user clicks Download, naming it from the document's title (`Quarterly Report` becomes `quarterly-report.pdf`);
57
+ - shows a loading state while it works, and an error state if rendering fails;
58
+ - lets a newer `load()` replace one still in progress, so rapid re-renders never show a stale document.
59
+
60
+ `load()` also accepts a promise of a document, and is safe to call before the element is connected: the load runs when it mounts. A second argument overrides the filename or supplies the PDF, for example `viewer.load(doc, { downloadFilename: 'q3.pdf' })`.
61
+
62
+ A failed load rejects its promise and dispatches a `bpp-load-error` event from the element. A document already on screen stays visible under an error banner.
63
+
64
+ ## Using it from any framework
65
+
66
+ The main entry point is side-effect free. `createPreviewer()` mounts the viewer into any element or `ShadowRoot` and returns a handle:
67
+
68
+ ```typescript
69
+ import { createPreviewer } from '@bonniepdf/previewer';
70
+
71
+ const handle = createPreviewer(container, {
72
+ fitMode: 'fit-width',
73
+ selectionColor: '#16a34a',
74
+ });
75
+
76
+ await handle.load(doc);
77
+
78
+ // When the component unmounts:
79
+ handle.dispose();
80
+ ```
81
+
82
+ The custom element is a thin wrapper that calls this factory with its own shadow root. To register it under a different tag name, call `defineBonniePdfPreviewer('my-pdf-viewer')` from the main entry instead of importing `@bonniepdf/previewer/element`.
83
+
84
+ ## Documents generated elsewhere
85
+
86
+ A `Document` is a live object in one JavaScript runtime. When the document is generated somewhere else, pass its **export** instead: the result of `generateSvgDocumentAsync()`, or the same data as JSON. The previewer reads page sizes from each page's `<svg>`, injects the font CSS once, and hands the layout snapshot and compliance report to its inspector.
87
+
88
+ From an ASP.NET Core server, using BonniePDF for .NET:
89
+
90
+ ```csharp
91
+ app.MapGet("/preview", () => Results.Content(
92
+ BuildReport().GenerateSvgDocument(new SvgPageExportOptions { CaptureLayout = true }).ToJson(),
93
+ "application/json"));
94
+ ```
95
+
96
+ ```typescript
97
+ await viewer.load(await (await fetch('/preview')).json(), {
98
+ pdf: () => fetch('/report.pdf').then((r) => r.blob()), // optional: enables Download
99
+ });
100
+ ```
101
+
102
+ From a web worker, to keep a large document off the main thread:
103
+
104
+ ```typescript
105
+ // worker.ts
106
+ const svgExport = await doc.generateSvgDocumentAsync({ captureLayout: true });
107
+ postMessage({ svgExport, pdf: await doc.generateBytesAsync() });
108
+
109
+ // page
110
+ worker.onmessage = ({ data }) => viewer.load(data.svgExport, { pdf: data.pdf });
111
+ ```
112
+
113
+ An export carries no document to generate a PDF from, so Download appears only when you pass `pdf`: a URL, a `Blob`, bytes, or a function returning one of those, called on the first click. When the previewer turns a `Blob` or bytes into an object URL, it owns that URL and revokes it on the next load or on `dispose()`. URLs you pass in remain yours.
114
+
115
+ ## Accessibility inspector
116
+
117
+ The `complianceView()` plugin adds an inspector panel for PDF/UA and accessibility preflight. Because BonniePDF generated the document, the inspector knows each element's semantics from authoring: its structure role, whether it is tagged or an artifact, its alternative text and its heading level.
118
+
119
+ ```typescript
120
+ import { complianceView, createPreviewer } from '@bonniepdf/previewer';
121
+
122
+ const handle = createPreviewer(container, { plugins: [complianceView()] });
123
+ await handle.load(doc);
124
+ ```
125
+
126
+ Or, on the element:
127
+
128
+ ```html
129
+ <bonnie-pdf-previewer compliance-view style="height: 80vh"></bonnie-pdf-previewer>
130
+ ```
131
+
132
+ The panel provides:
133
+
134
+ - **A layout tree** following the WAI-ARIA tree pattern: one tab stop, arrow-key navigation, `←` and `→` to collapse and expand, `*` to expand all. It opens fully by default; `defaultExpandDepth` limits the initial depth, and branches containing errors still expand.
135
+ - **Role badges** such as `H1`, `Figure` and `TH`. A filled badge marks tagged content, a dashed badge marks an artifact, and separate icons distinguish errors, warnings and informational findings.
136
+ - **A summary** with the PDF/UA-1 verdict and issue counts, a filter for elements with issues, and a switch for WCAG contrast checks.
137
+ - **An Issues tab** grouping findings by severity, each with its element, page and a Go to element button.
138
+ - **Two-way selection.** Click a row to highlight its rectangles on the page, or click the page to select the deepest matching node. The SVG itself is never modified; highlights draw on a separate overlay.
139
+ - **A detail pane** with the finding's message, ISO clause and a fix hint.
140
+
141
+ This catches problems external validators often miss. An image without alternative text exports as an artifact; a validator sees a valid untagged artifact, while a screen reader silently skips it. The inspector flags it as an error that needs `altText` or an explicit decorative marking.
142
+
143
+ The inspector reads the layout snapshot and compliance report from `@bonniepdf/core`. With the plugin registered, `load(doc)` captures them automatically. An export carries them when it was generated with `captureLayout: true`.
144
+
145
+ ### WCAG contrast checks
146
+
147
+ PDF/UA-1 sets no numeric contrast requirement: ISO 14289-1 §7.1 only forbids conveying information by contrast or colour alone. Core's contrast findings cite WCAG 2.2 success criterion 1.4.3 instead, and because colourful documents can produce many of them, they can be switched off:
148
+
149
+ - **In the viewer:** the Include WCAG contrast checks switch in the panel, with its initial state set by `complianceView({ showWcagChecks: false })` or `wcag-checks="false"`. Turning it off removes contrast findings from the tree, counts, badges, detail pane and page markers. WCAG findings never affect the PDF/UA-1 verdict.
150
+ - **In the library:** `evaluateCompliance(snapshot, { includeWcag: false })` in TypeScript, or `CompliancePreflight.Evaluate` in .NET, stops the rules running at all.
151
+
152
+ The inspector is an advisory preflight. It does not certify PDF/A or PDF/UA conformance; use an external validator where certification is required.
153
+
154
+ ### Writing a plugin
155
+
156
+ A plugin implements `PreviewerPlugin` (`setup`, `load`, `sync`, `teardown`). The host gives it `overlayFor(pageIndex)` (a `pointer-events: none` layer over a page), `addSidePanel`, `addToolbarItem`, `scale()` and `scrollToPage()`. `addSidePanel` registers a tab in the shared inspector region; pass `defaultOpen` and an `onVisibilityChange(visible)` callback to manage overlays, and use `setBadge(text, tone)` for tab counts. [`src/compliance-view.ts`](src/compliance-view.ts) is a complete example.
157
+
158
+ ## Element reference
159
+
160
+ Attributes are read when the element connects to the page.
161
+
162
+ | Attribute | Effect |
163
+ | ------------------------- | -------------------------------------------------------------------------------------------- |
164
+ | `label` | Accessible name for the viewer region. Defaults to `PDF preview`. |
165
+ | `fit-mode` | `fit-page` (default) or `fit-width`. |
166
+ | `show-thumbnails` | Shows the thumbnail rail on first render. Hidden by default; `"false"` keeps it hidden. |
167
+ | `show-inspector` | Opens (`"true"`) or collapses (`"false"`) the inspector region on first render. |
168
+ | `compliance-view` | Adds the accessibility inspector. |
169
+ | `wcag-checks` | `"false"` starts the inspector with WCAG contrast findings hidden. |
170
+ | `download-filename` | Filename for Download, overriding the one derived from the document title. |
171
+ | `selection-color` | Any CSS colour for selection highlights. Defaults to the system `Highlight` colour. |
172
+ | `footer` | Renders a footer bar with text on the left and conformance pills such as `PDF/A-2a` and `PDF/UA-1`, or `PDF/A-4f` and `PDF/UA-2` for PDF 2.0, on the right. |
173
+ | `footer-label` | Footer text. Defaults to `Generated by @bonniepdf/previewer`. |
174
+ | `preference-key` | Persists thumbnail and inspector visibility and the chosen zoom in `localStorage` under this key. |
175
+ | `hide-border` | Removes the outer border and corner radius. |
176
+ | `style-scrollbars` | `"true"` applies the previewer's own scrollbar styling. |
177
+ | `show-page-nav`, `show-zoom`, `show-fullscreen`, `show-download`, `show-thumbnails-toggle` | `"false"` hides that toolbar group. All are shown by default. |
178
+
179
+ `preference-key` state is read synchronously before the viewer builds, so returning visitors never see panels flash through their defaults. Viewers sharing a key share their preferences.
180
+
181
+ | Method or event | Description |
182
+ | ------------------------------------------------ | ------------------------------------------------------------------------------------------- |
183
+ | `load(source, options?)` | Shows a `Document`, an export, or a promise of either. Resolves once it is shown. |
184
+ | `selectSnapshotNode(nodeId)` | Selects and reveals a layout node. Returns `false` when no such node exists. |
185
+ | `clear()` | Clears the pages and returns to the loading state. |
186
+ | `dispose()` | On a `createPreviewer()` handle: disconnects every observer and listener. The element does this itself when removed. |
187
+ | `bpp-load-error` event | A load failed. `event.detail.error` holds the error. |
188
+ | `bonniepdf-node-select` event | The inspector selected a node. `event.detail` holds `nodeId`, `sourceId`, `sourceNavigation` and `origin` (`page`, `tree` or `finding`). |
189
+
190
+ Both events bubble and cross the shadow boundary. `createPreviewer()` accepts the same settings as options (`fitMode`, `showThumbnails`, `showInspector`, `toolbar`, `footer`, `title`, `downloadFilename`, `hideBorder`, `styleScrollbars`, `selectionColor`, `initialZoom`, `onViewStateChange` and `plugins`); the exported TypeScript types document each one.
191
+
192
+ ### Fullscreen
193
+
194
+ Entering fullscreen switches the document to Fit Page, locks page scrolling and releases any reserved scrollbar gutter. Leaving fullscreen restores the previous zoom, unless the user changed it while in fullscreen, and restores the host's styles.
195
+
196
+ ## Theming
197
+
198
+ Colours resolve the previewer's own `--bpdf-*` custom properties first, then the CongruentUI `--cui-*` tokens the BonniePDF websites use, then a built-in light theme. Custom properties cross the shadow boundary, so a host that sets either family gets a previewer that follows its light and dark modes. The pages themselves stay white, because they are paper.
199
+
200
+ | Property | Controls |
201
+ | ------------------------------------------------ | -------------------------------- |
202
+ | `--bpdf-bg`, `--bpdf-bg-alt`, `--bpdf-bg-soft` | Chrome backgrounds |
203
+ | `--bpdf-text-1`, `--bpdf-text-2`, `--bpdf-text-3`| Primary, secondary and muted text|
204
+ | `--bpdf-brand-2`, `--bpdf-brand-soft` | Accent and accent tint |
205
+ | `--bpdf-divider` | Borders and separators |
206
+ | `--bpdf-radius` | Corner radius |
207
+ | `--bpdf-font-family` | Chrome font (pages use their own)|
208
+ | `--bpdf-selection` | Selection highlight |
209
+ | `--bpdf-error`, `--bpdf-warning`, `--bpdf-info`, `--bpdf-success` | Inspector severity colours |
210
+
211
+ There is no theme attribute and no JavaScript theming API; custom properties are the whole interface.
212
+
213
+ ## Performance
214
+
215
+ - **Windowed rendering.** Only pages and thumbnails near the viewport are mounted; the rest are lightweight placeholders.
216
+ - **Lazy PDF.** The full PDF is generated only when Download is clicked.
217
+ - **Layout capture on demand.** `load(doc)` asks for the layout snapshot only when an inspector plugin is registered.
218
+ - **Deterministic teardown.** `dispose()` and removing the element disconnect every observer and listener.
219
+
220
+ ## Deprecated API
221
+
222
+ `load(svgStringsToPages(pages), { fontFaceCss, snapshot, report, pdfUrl, pdfProvider })` still works as before but is deprecated and will be removed in the next major version; pass the document or its export instead. The `structureView()` plugin and `structure-view` attribute are aliases for the accessibility inspector.
223
+
224
+ ## Licence
225
+
226
+ `@bonniepdf/previewer` is licensed under the [Apache License 2.0](https://github.com/bonniepdf/BonniePDF-Previewer/blob/master/LICENSE).
227
+
228
+ The previewer is free to use with any BonniePDF licence tier. `@bonniepdf/core`, which generates the documents it shows, is licensed separately under the BonniePDF Community License 1.0 or a commercial licence; see the [licensing overview](https://www.bonniepdf.dev/pricing).
229
+
230
+ ## Contributing
231
+
232
+ Issues and pull requests are welcome. For anything beyond a small fix, please open an issue first: the element's attributes, events and `load()` signature are a public API, so the approach is worth agreeing before the work. See [CONTRIBUTING.md](CONTRIBUTING.md) for the sign-off requirement and how to build and test, and [SECURITY.md](SECURITY.md) to report a vulnerability.
233
+
234
+ © 2026 CodeFocus Limited