@profpowell/pdf-viewer 0.1.0 → 0.2.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/README.md +125 -4
- package/dist/pdf-viewer.js +2277 -2267
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,6 +1,127 @@
|
|
|
1
|
-
pdf-viewer
|
|
2
|
-
The components use custom events and are frame work agnostic. The component follows the same repository patterns with JSDocs, a doc site, heavy unit and playwright testing and best practices established elsewhere. Actual viewing of PDFs can be performed by dependencies this component coordinates, wraps, and controls. This makes it like code-block and code-playground which very much rely on other things
|
|
1
|
+
# @profpowell/pdf-viewer
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
A standalone `<pdf-viewer>` web component wrapping [PDF.js](https://mozilla.github.io/pdf.js/) with navigation, zoom, search, thumbnails, dark mode, and full design-token theming.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
Status: **alpha** — API may shift before 1.0.
|
|
6
|
+
|
|
7
|
+
- Live demo: https://profpowell.github.io/pdf-viewer/
|
|
8
|
+
- Repo: https://github.com/ProfPowell/pdf-viewer
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @profpowell/pdf-viewer
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or import directly from a CDN (ESM):
|
|
17
|
+
|
|
18
|
+
```html
|
|
19
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@profpowell/pdf-viewer/dist/pdf-viewer.js"></script>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick start
|
|
23
|
+
|
|
24
|
+
```html
|
|
25
|
+
<script type="module">
|
|
26
|
+
import '@profpowell/pdf-viewer'
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<pdf-viewer src="document.pdf"></pdf-viewer>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```html
|
|
33
|
+
<pdf-viewer
|
|
34
|
+
src="report.pdf"
|
|
35
|
+
page="3"
|
|
36
|
+
zoom="fit-width"
|
|
37
|
+
show-thumbnails
|
|
38
|
+
show-search
|
|
39
|
+
></pdf-viewer>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Attributes
|
|
43
|
+
|
|
44
|
+
| Attribute | Type | Default | Description |
|
|
45
|
+
|---|---|---|---|
|
|
46
|
+
| `src` | string | — | URL of the PDF document |
|
|
47
|
+
| `page` | number | `1` | Current page (1-based) |
|
|
48
|
+
| `zoom` | string | `auto` | Number (`"1.5"`) or mode (`"fit-width"`, `"fit-page"`, `"auto"`) |
|
|
49
|
+
| `mode` | `light` \| `dark` | auto | Color scheme; omit to follow page/system preference |
|
|
50
|
+
| `view` | `single` \| `continuous` | `single` | Page layout mode |
|
|
51
|
+
| `show-toolbar` | boolean | `true` | Show the toolbar |
|
|
52
|
+
| `show-thumbnails` | boolean | `false` | Show thumbnail sidebar |
|
|
53
|
+
| `show-search` | boolean | `false` | Show search bar |
|
|
54
|
+
| `no-download` | boolean | `false` | Hide the download button |
|
|
55
|
+
| `no-print` | boolean | `false` | Hide the print button |
|
|
56
|
+
| `title` | string | — | Title displayed in the toolbar |
|
|
57
|
+
| `lazy` | boolean | `false` | Defer loading until the component scrolls into view |
|
|
58
|
+
|
|
59
|
+
## Methods
|
|
60
|
+
|
|
61
|
+
`nextPage()`, `prevPage()`, `goToPage(n)`, `getPageCount()`, `getCurrentPage()`, `zoomIn()`, `zoomOut()`, `setZoom(level)`, `setData(arrayBufferOrFile)`, `openFile()`, `download()`, `print()`, `search(query)`, `clearSearch()`, `toggleFullscreen()`, `toggleThumbnails()`, `toggleSearch()`.
|
|
62
|
+
|
|
63
|
+
See [`pdf-viewer.d.ts`](./pdf-viewer.d.ts) for full type signatures.
|
|
64
|
+
|
|
65
|
+
## Events
|
|
66
|
+
|
|
67
|
+
| Event | Detail |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `pdf-loaded` | `{ url, pageCount, title }` |
|
|
70
|
+
| `pdf-load-error` | `{ url, error }` |
|
|
71
|
+
| `page-change` | `{ page, previousPage, pageCount }` |
|
|
72
|
+
| `zoom-change` | `{ zoom, previousZoom }` |
|
|
73
|
+
| `view-change` | `{ view }` |
|
|
74
|
+
| `file-opened` | `{ name, size }` |
|
|
75
|
+
|
|
76
|
+
## Theming
|
|
77
|
+
|
|
78
|
+
Two layers of CSS custom properties, both optional:
|
|
79
|
+
|
|
80
|
+
**1. Per-instance overrides** — `--pdf-viewer-*` properties take highest priority.
|
|
81
|
+
|
|
82
|
+
```css
|
|
83
|
+
pdf-viewer {
|
|
84
|
+
--pdf-viewer-accent-color: #ff6b00;
|
|
85
|
+
--pdf-viewer-toolbar-bg: #fafafa;
|
|
86
|
+
--pdf-viewer-sidebar-width: 240px;
|
|
87
|
+
--pdf-viewer-highlight: rgba(255, 200, 0, 0.5);
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Available: `--pdf-viewer-bg`, `--pdf-viewer-toolbar-bg`, `--pdf-viewer-border-color`, `--pdf-viewer-text-color`, `--pdf-viewer-text-muted`, `--pdf-viewer-accent-color`, `--pdf-viewer-hover-bg`, `--pdf-viewer-content-bg`, `--pdf-viewer-sidebar-bg`, `--pdf-viewer-sidebar-width`, `--pdf-viewer-toolbar-height`, `--pdf-viewer-font-family`, `--pdf-viewer-font-size`, `--pdf-viewer-shadow`, `--pdf-viewer-highlight`, `--pdf-viewer-highlight-active`.
|
|
92
|
+
|
|
93
|
+
**2. Design-token consumption** — when surrounding CSS defines tokens like `--color-surface`, `--size-xs`, `--font-size-base`, `--radius-s`, `--shadow-m`, `--border-width-thin`, the component picks them up automatically. Each token has a sensible pixel/color fallback so consumers without a token system see no visual change.
|
|
94
|
+
|
|
95
|
+
### Vanilla Breeze compatibility
|
|
96
|
+
|
|
97
|
+
This component is designed to drop into a [Vanilla Breeze](https://github.com/vanilla-breeze) page with **zero extra wiring**. It consumes the standard VB token namespaces:
|
|
98
|
+
|
|
99
|
+
| Surface | VB tokens consumed |
|
|
100
|
+
|---|---|
|
|
101
|
+
| Colors | `--color-surface`, `--color-surface-raised`, `--color-surface-sunken`, `--color-surface-hover`, `--color-border`, `--color-text`, `--color-text-muted`, `--color-interactive`, `--color-error` |
|
|
102
|
+
| Typography | `--font-sans`, `--font-size-2xs`, `--font-size-xs`, `--font-size-sm`, `--font-size-base`, `--font-size-l` |
|
|
103
|
+
| Spacing | `--size-3xs`, `--size-2xs`, `--size-xs`, `--size-s`, `--size-m` |
|
|
104
|
+
| Borders & radii | `--border-width-thin`, `--radius-xs`, `--radius-s`, `--radius-m` |
|
|
105
|
+
| Shadows | `--shadow-s`, `--shadow-m`, `--shadow-l` (heavier in dark mode for contrast) |
|
|
106
|
+
|
|
107
|
+
Theme-pack switching (default ↔ rough ↔ extreme-swiss ↔ extreme-neumorphism) re-skins toolbar, sidebar, search bar, overlays, and chrome borders. The PDF page paper itself stays white in both light and dark mode by PDF/print convention — this is intentional, not a bug.
|
|
108
|
+
|
|
109
|
+
The `--pdf-viewer-*` overrides above always win over VB tokens, so per-instance customization remains available inside a themed page.
|
|
110
|
+
|
|
111
|
+
## Dark mode
|
|
112
|
+
|
|
113
|
+
Dark mode is auto-detected from `prefers-color-scheme`. Force it explicitly with the `mode` attribute:
|
|
114
|
+
|
|
115
|
+
```html
|
|
116
|
+
<pdf-viewer src="doc.pdf" mode="dark"></pdf-viewer>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The component also observes the host page's `data-theme` / `class="dark"` (via `theme-observer`) so it stays in sync with site-wide theme toggles.
|
|
120
|
+
|
|
121
|
+
## Browser support
|
|
122
|
+
|
|
123
|
+
Modern evergreen browsers with ES modules and Custom Elements v1 (Chrome, Firefox, Safari, Edge — recent versions).
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
MIT © [Prof Thomas Powell](https://github.com/ProfPowell)
|