@embedpdf/svelte-pdf-viewer 2.0.0 → 2.0.1
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 +141 -47
- package/dist/PDFViewer.svelte +20 -15
- package/dist/PDFViewer.svelte.d.ts +14 -7
- package/dist/PDFViewer.svelte.d.ts.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,8 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://www.embedpdf.com/svelte-pdf-viewer">
|
|
3
|
+
<img alt="EmbedPDF logo" src="https://www.embedpdf.com/logo-192.png" height="96">
|
|
4
|
+
</a>
|
|
2
5
|
|
|
3
|
-
Svelte
|
|
6
|
+
<h1>Svelte PDF Viewer</h1>
|
|
7
|
+
<p>The easiest way to embed PDF files in your Svelte application with a complete, ready‑to‑use interface.</p>
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
<a href="https://www.embedpdf.com/svelte-pdf-viewer"><img alt="Documentation" src="https://img.shields.io/badge/View%20Docs-0af?style=for-the-badge&labelColor=000000"></a>
|
|
10
|
+
<a href="https://app.embedpdf.com/"><img alt="Live Demo" src="https://img.shields.io/badge/Try%20Live%20Demo-ff1493.svg?style=for-the-badge&labelColor=000000"></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@embedpdf/svelte-pdf-viewer"><img alt="NPM Version" src="https://img.shields.io/npm/v/@embedpdf/svelte-pdf-viewer?style=for-the-badge&labelColor=000000&color=blue"></a>
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 📚 Documentation
|
|
18
|
+
|
|
19
|
+
The full walkthrough, advanced examples, and API reference live in our docs site:
|
|
20
|
+
|
|
21
|
+
👉 **[https://www.embedpdf.com/svelte-pdf-viewer](https://www.embedpdf.com/svelte-pdf-viewer)**
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 🚀 Introduction
|
|
26
|
+
|
|
27
|
+
The `@embedpdf/svelte-pdf-viewer` package provides a complete, production-ready PDF viewing experience for Svelte applications.
|
|
28
|
+
|
|
29
|
+
It is designed to be the fastest way to get a high-quality PDF viewer into your app. You don't need to build toolbars, handle layout logic, or worry about CSS—it just works.
|
|
30
|
+
|
|
31
|
+
### Key Features
|
|
32
|
+
|
|
33
|
+
- **Ready-to-use UI** — Includes a polished toolbar, sidebar, and thumbnails.
|
|
34
|
+
- **Responsive** — Adapts seamlessly to mobile and desktop screens.
|
|
35
|
+
- **Themable** — Built-in light/dark modes and support for custom brand colors.
|
|
36
|
+
- **Configurable** — Easily disable features you don't need (e.g., printing or downloading).
|
|
37
|
+
- **TypeScript** — Fully typed for a great developer experience.
|
|
38
|
+
- **Svelte 4 & 5** — Works with both Svelte 4 and Svelte 5 projects.
|
|
39
|
+
- **SvelteKit Ready** — Works seamlessly with SSR.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 📦 Installation
|
|
6
44
|
|
|
7
45
|
```bash
|
|
8
46
|
npm install @embedpdf/svelte-pdf-viewer
|
|
@@ -12,75 +50,131 @@ pnpm add @embedpdf/svelte-pdf-viewer
|
|
|
12
50
|
yarn add @embedpdf/svelte-pdf-viewer
|
|
13
51
|
```
|
|
14
52
|
|
|
15
|
-
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 🛠 Basic Usage
|
|
56
|
+
|
|
57
|
+
Import the `PDFViewer` component and render it with a PDF source.
|
|
16
58
|
|
|
17
59
|
```svelte
|
|
18
60
|
<script>
|
|
19
61
|
import { PDFViewer } from '@embedpdf/svelte-pdf-viewer';
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<div style="height: 100vh;">
|
|
65
|
+
<PDFViewer
|
|
66
|
+
config={{
|
|
67
|
+
src: 'https://snippet.embedpdf.com/ebook.pdf',
|
|
68
|
+
theme: { preference: 'light' },
|
|
69
|
+
}}
|
|
70
|
+
/>
|
|
71
|
+
</div>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
That's it! You now have a fully functional PDF viewer.
|
|
75
|
+
|
|
76
|
+
### SvelteKit Usage
|
|
77
|
+
|
|
78
|
+
The component works seamlessly with SvelteKit. Since it uses browser APIs (Canvas, WebAssembly), it should be used in a browser context. The component handles this internally, but you can also lazy load it if needed.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## 🎨 Customization
|
|
83
|
+
|
|
84
|
+
### Theme
|
|
85
|
+
|
|
86
|
+
The viewer includes a robust theming system. You can set the preference to `'light'`, `'dark'`, or `'system'`, and even override specific colors to match your brand.
|
|
20
87
|
|
|
21
|
-
|
|
88
|
+
```svelte
|
|
89
|
+
<PDFViewer
|
|
90
|
+
config={{
|
|
22
91
|
src: '/document.pdf',
|
|
23
|
-
theme: {
|
|
24
|
-
|
|
92
|
+
theme: {
|
|
93
|
+
preference: 'system',
|
|
94
|
+
light: {
|
|
95
|
+
accent: {
|
|
96
|
+
primary: '#ff3e00', // Custom brand color (Orange)
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
}}
|
|
101
|
+
/>
|
|
102
|
+
```
|
|
25
103
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
</script>
|
|
104
|
+
### Disabling Features
|
|
105
|
+
|
|
106
|
+
Easily customize the UI by disabling features you don't need via the `disabledCategories` option:
|
|
30
107
|
|
|
31
|
-
|
|
108
|
+
```svelte
|
|
109
|
+
<PDFViewer
|
|
110
|
+
config={{
|
|
111
|
+
src: '/document.pdf',
|
|
112
|
+
disabledCategories: ['annotation', 'print', 'export'],
|
|
113
|
+
}}
|
|
114
|
+
/>
|
|
32
115
|
```
|
|
33
116
|
|
|
34
|
-
|
|
117
|
+
Available categories include: `zoom`, `annotation`, `redaction`, `document`, `page`, `panel`, `tools`, `selection`, and `history`.
|
|
35
118
|
|
|
36
|
-
|
|
37
|
-
| -------- | ----------------- | ---------------------------------------- |
|
|
38
|
-
| `config` | `PDFViewerConfig` | Full configuration object for the viewer |
|
|
39
|
-
| `class` | `string` | CSS class name for the container |
|
|
40
|
-
| `style` | `string` | Inline styles for the container |
|
|
119
|
+
---
|
|
41
120
|
|
|
42
|
-
|
|
121
|
+
## ⚙️ Configuration Options
|
|
43
122
|
|
|
44
|
-
|
|
45
|
-
- `theme` - Theme configuration
|
|
46
|
-
- `zoom` - Zoom configuration
|
|
47
|
-
- `scroll` - Scroll configuration
|
|
48
|
-
- `annotations` - Annotation configuration
|
|
49
|
-
- And more...
|
|
123
|
+
The `config` prop accepts the following top-level options:
|
|
50
124
|
|
|
51
|
-
|
|
125
|
+
| Option | Type | Description |
|
|
126
|
+
| :------------------- | :---------------------------------- | :--------------------------------------------- |
|
|
127
|
+
| `src` | `string` | URL or path to the PDF document. |
|
|
128
|
+
| `theme` | `object` | Theme configuration (preference, overrides). |
|
|
129
|
+
| `tabBar` | `'always' \| 'multiple' \| 'never'` | Control visibility of the document tab bar. |
|
|
130
|
+
| `disabledCategories` | `string[]` | Hide specific UI features by category. |
|
|
131
|
+
| `i18n` | `object` | Configure locales and translations. |
|
|
132
|
+
| `annotations` | `object` | Configure annotation defaults (author, tools). |
|
|
133
|
+
| `zoom` | `object` | Configure default zoom levels and limits. |
|
|
134
|
+
| `scroll` | `object` | Configure scroll direction and logic. |
|
|
52
135
|
|
|
53
|
-
|
|
54
|
-
| ------- | ------------------- | -------------------------------- |
|
|
55
|
-
| `init` | `EmbedPdfContainer` | Fired when viewer is initialized |
|
|
56
|
-
| `ready` | `PluginRegistry` | Fired when registry is ready |
|
|
136
|
+
---
|
|
57
137
|
|
|
58
|
-
##
|
|
138
|
+
## 🔌 Callbacks & Registry
|
|
59
139
|
|
|
60
|
-
Use
|
|
140
|
+
Use callback props to access the viewer instance and plugin registry.
|
|
61
141
|
|
|
62
142
|
```svelte
|
|
63
143
|
<script>
|
|
64
144
|
import { PDFViewer } from '@embedpdf/svelte-pdf-viewer';
|
|
65
145
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
async function handleClick() {
|
|
70
|
-
const reg = await registry;
|
|
71
|
-
// Use registry to access plugins
|
|
146
|
+
function onready(registry) {
|
|
147
|
+
const engine = registry.getEngine();
|
|
148
|
+
console.log('Engine ready:', engine);
|
|
72
149
|
}
|
|
73
150
|
</script>
|
|
74
151
|
|
|
75
|
-
<PDFViewer
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
152
|
+
<PDFViewer config={{ src: '/doc.pdf' }} {onready} />
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Available Callbacks
|
|
156
|
+
|
|
157
|
+
| Callback | Payload | Description |
|
|
158
|
+
| :-------- | :------------------ | :---------------------------------------------- |
|
|
159
|
+
| `oninit` | `EmbedPdfContainer` | Fired when the viewer container is initialized. |
|
|
160
|
+
| `onready` | `PluginRegistry` | Fired when the plugin registry is ready. |
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## 🧩 Headless Mode
|
|
165
|
+
|
|
166
|
+
Need complete control over the UI? Building a custom design system?
|
|
167
|
+
|
|
168
|
+
Check out our **Headless Components** which provide stores and logic without the UI:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
npm install @embedpdf/core @embedpdf/plugin-zoom ...
|
|
82
172
|
```
|
|
83
173
|
|
|
84
|
-
|
|
174
|
+
Read the [Headless Documentation](https://www.embedpdf.com/docs/svelte/headless/introduction) for more details.
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## 📄 License
|
|
85
179
|
|
|
86
|
-
MIT
|
|
180
|
+
EmbedPDF is [MIT licensed](https://github.com/embedpdf/embed-pdf-viewer/blob/main/LICENSE). Commercial use is welcome—just keep the copyright headers intact.
|
package/dist/PDFViewer.svelte
CHANGED
|
@@ -6,22 +6,29 @@
|
|
|
6
6
|
type PluginRegistry,
|
|
7
7
|
} from '@embedpdf/snippet';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
interface Props {
|
|
10
|
+
/** Full configuration for the PDF viewer */
|
|
11
|
+
config?: PDFViewerConfig;
|
|
12
|
+
/** CSS class for the container element */
|
|
13
|
+
class?: string;
|
|
14
|
+
/** Inline styles for the container element */
|
|
15
|
+
style?: string;
|
|
16
|
+
/** Callback when the viewer container is initialized */
|
|
17
|
+
oninit?: (container: EmbedPdfContainer) => void;
|
|
18
|
+
/** Callback when the plugin registry is ready */
|
|
19
|
+
onready?: (registry: PluginRegistry) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let { config = {}, class: className = '', style = '', oninit, onready }: Props = $props();
|
|
23
|
+
|
|
24
|
+
let container: EmbedPdfContainer | null = null;
|
|
25
|
+
let containerEl: HTMLDivElement;
|
|
16
26
|
const dispatch = createEventDispatcher<{
|
|
17
27
|
init: EmbedPdfContainer;
|
|
18
28
|
ready: PluginRegistry;
|
|
19
29
|
}>();
|
|
20
30
|
|
|
21
|
-
let containerEl: HTMLDivElement;
|
|
22
|
-
|
|
23
31
|
onMount(() => {
|
|
24
|
-
// Initialize the viewer with the config prop
|
|
25
32
|
const viewer = EmbedPDF.init({
|
|
26
33
|
type: 'container',
|
|
27
34
|
target: containerEl,
|
|
@@ -30,24 +37,22 @@
|
|
|
30
37
|
|
|
31
38
|
if (viewer) {
|
|
32
39
|
container = viewer;
|
|
33
|
-
|
|
40
|
+
oninit?.(viewer);
|
|
34
41
|
dispatch('init', viewer);
|
|
35
42
|
|
|
36
|
-
// Dispatch ready when registry is available
|
|
37
43
|
viewer.registry.then((reg) => {
|
|
44
|
+
onready?.(reg);
|
|
38
45
|
dispatch('ready', reg);
|
|
39
46
|
});
|
|
40
47
|
}
|
|
41
48
|
});
|
|
42
49
|
|
|
43
50
|
onDestroy(() => {
|
|
44
|
-
// Cleanup: remove the viewer element
|
|
45
51
|
if (container && containerEl) {
|
|
46
52
|
containerEl.innerHTML = '';
|
|
47
53
|
container = null;
|
|
48
|
-
registry = null;
|
|
49
54
|
}
|
|
50
55
|
});
|
|
51
56
|
</script>
|
|
52
57
|
|
|
53
|
-
<div bind:this={containerEl} class={
|
|
58
|
+
<div bind:this={containerEl} class={className} {style}></div>
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { type EmbedPdfContainer, type PDFViewerConfig, type PluginRegistry } from '@embedpdf/snippet';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** Full configuration for the PDF viewer */
|
|
4
|
+
config?: PDFViewerConfig;
|
|
5
|
+
/** CSS class for the container element */
|
|
6
|
+
class?: string;
|
|
7
|
+
/** Inline styles for the container element */
|
|
8
|
+
style?: string;
|
|
9
|
+
/** Callback when the viewer container is initialized */
|
|
10
|
+
oninit?: (container: EmbedPdfContainer) => void;
|
|
11
|
+
/** Callback when the plugin registry is ready */
|
|
12
|
+
onready?: (registry: PluginRegistry) => void;
|
|
13
|
+
}
|
|
2
14
|
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
3
15
|
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
16
|
$$bindings?: Bindings;
|
|
@@ -12,17 +24,12 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
|
|
|
12
24
|
};
|
|
13
25
|
z_$$bindings?: Bindings;
|
|
14
26
|
}
|
|
15
|
-
declare const PDFViewer: $$__sveltets_2_IsomorphicComponent<{
|
|
16
|
-
[x: string]: any;
|
|
17
|
-
config?: PDFViewerConfig | undefined;
|
|
18
|
-
container?: (EmbedPdfContainer | null) | undefined;
|
|
19
|
-
registry?: (Promise<PluginRegistry> | null) | undefined;
|
|
20
|
-
}, {
|
|
27
|
+
declare const PDFViewer: $$__sveltets_2_IsomorphicComponent<Props, {
|
|
21
28
|
init: CustomEvent<EmbedPdfContainer>;
|
|
22
29
|
ready: CustomEvent<PluginRegistry>;
|
|
23
30
|
} & {
|
|
24
31
|
[evt: string]: CustomEvent<any>;
|
|
25
|
-
}, {}, {},
|
|
32
|
+
}, {}, {}, "">;
|
|
26
33
|
type PDFViewer = InstanceType<typeof PDFViewer>;
|
|
27
34
|
export default PDFViewer;
|
|
28
35
|
//# sourceMappingURL=PDFViewer.svelte.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PDFViewer.svelte.d.ts","sourceRoot":"","sources":["../src/PDFViewer.svelte.ts"],"names":[],"mappings":"AAIA,OAAiB,EACb,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"PDFViewer.svelte.d.ts","sourceRoot":"","sources":["../src/PDFViewer.svelte.ts"],"names":[],"mappings":"AAIA,OAAiB,EACb,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAG3B,UAAU,KAAK;IACb,4CAA4C;IAC5C,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAChD,iDAAiD;IACjD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;CAC9C;AAiDH,UAAU,kCAAkC,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,OAAO,GAAG,EAAE,EAAE,QAAQ,GAAG,MAAM;IACpM,KAAK,OAAO,EAAE,OAAO,QAAQ,EAAE,2BAA2B,CAAC,KAAK,CAAC,GAAG,OAAO,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,QAAQ,CAAA;KAAE,GAAG,OAAO,CAAC;IACjK,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAG;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,KAAK,CAAA;KAAC,GAAG,OAAO,GAAG;QAAE,IAAI,CAAC,EAAE,GAAG,CAAC;QAAC,GAAG,CAAC,EAAE,GAAG,CAAA;KAAE,CAAC;IAC9G,YAAY,CAAC,EAAE,QAAQ,CAAC;CAC3B;AAKD,QAAA,MAAM,SAAS;;;;;cAA+E,CAAC;AAC7E,KAAK,SAAS,GAAG,YAAY,CAAC,OAAO,SAAS,CAAC,CAAC;AAClD,eAAe,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/svelte-pdf-viewer",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Svelte component for embedding PDF documents",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
8
|
+
"homepage": "https://www.embedpdf.com/svelte-pdf-viewer",
|
|
8
9
|
"svelte": "./dist/index.js",
|
|
9
10
|
"types": "./dist/index.d.ts",
|
|
10
11
|
"exports": {
|
|
@@ -19,11 +20,11 @@
|
|
|
19
20
|
"README.md"
|
|
20
21
|
],
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"@embedpdf/snippet": "2.0.
|
|
23
|
+
"@embedpdf/snippet": "2.0.1"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@sveltejs/package": "^2.3.0",
|
|
26
|
-
"rimraf": "^
|
|
27
|
+
"rimraf": "^6.1.2",
|
|
27
28
|
"svelte": "^5.0.0",
|
|
28
29
|
"typescript": "^5.1.6"
|
|
29
30
|
},
|