@zumer/snapdom-pdf 1.0.0 → 1.0.2
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 +39 -0
- package/README.md +208 -9
- package/index.d.ts +14 -5
- package/package.json +4 -4
- package/src/furniture.js +7 -3
- package/src/index.js +215 -38
- package/src/mega/README.md +1 -1
- package/src/mega/fonts.js +118 -11
- package/src/page-image.js +147 -0
- package/src/text-layer.js +105 -9
- package/src/writer/brotli-dictionary.js +676 -0
- package/src/writer/brotli.js +589 -0
- package/src/writer/font.js +12 -5
- package/src/writer/index.js +5 -5
- package/src/writer/woff2.js +455 -0
- package/REFERENCE.md +0 -520
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# PDF changes
|
|
2
2
|
|
|
3
|
+
## 1.0.2
|
|
4
|
+
|
|
5
|
+
> 24 November 2026
|
|
6
|
+
|
|
7
|
+
**Features**
|
|
8
|
+
|
|
9
|
+
- **pdf:** WOFF2 fonts embed, and text is painted only from a file that holds its glyphs [`9644f96`](https://github.com/zumerlab/snapdom/commit/9644f969972bd942d2a767ccc70876adc916b00c)
|
|
10
|
+
- **pdf:** a word painted as glyphs is in the file once [`88c831e`](https://github.com/zumerlab/snapdom/commit/88c831e4c0d07acb5a37749b15ff7fa88a2e100d)
|
|
11
|
+
- **pdf:** text is painted as real glyphs by default [`9c525aa`](https://github.com/zumerlab/snapdom/commit/9c525aacdefb31320542b208df6aa1891ee5e2ec)
|
|
12
|
+
|
|
13
|
+
**Refactoring**
|
|
14
|
+
|
|
15
|
+
- the vector engine writes no PDF; the PDF plugin owns all of it [`acaff7d`](https://github.com/zumerlab/snapdom/commit/acaff7d76e12661a67ae8e1214b71c69f753bcc1)
|
|
16
|
+
- one engine per product; the PDF plugin does not use the vector engine [`de4f795`](https://github.com/zumerlab/snapdom/commit/de4f79529174793e2800cd3517b40769d9be59d0)
|
|
17
|
+
|
|
18
|
+
**Chores**
|
|
19
|
+
|
|
20
|
+
- **pdf,vector:** require SnapDOM 3.8.3 [`548afe4`](https://github.com/zumerlab/snapdom/commit/548afe42db29c19ce6c2a1eeddd84f6c86aa1117)
|
|
21
|
+
- release each package from its workspace instead of sixteen root aliases [`37f6b34`](https://github.com/zumerlab/snapdom/commit/37f6b341e842f6480786b663a3bc1123de393659)
|
|
22
|
+
|
|
23
|
+
## 1.0.1
|
|
24
|
+
|
|
25
|
+
> 9 November 2026
|
|
26
|
+
|
|
27
|
+
**Fixes**
|
|
28
|
+
|
|
29
|
+
- **pdf:** place the text layer correctly on hidpi screens [`05d87aa`](https://github.com/zumerlab/snapdom/commit/05d87aa81de0e03dd7c76e782626b629851b81ee)
|
|
30
|
+
- **pdf:** rasterize a capture enlarged to the paper at its printed size [`20add63`](https://github.com/zumerlab/snapdom/commit/20add63a27d31da61da1911001e1461ba4b7b99d)
|
|
31
|
+
|
|
32
|
+
**Refactoring**
|
|
33
|
+
|
|
34
|
+
- **pdf:** drop two locals nothing reads [`f49f5c1`](https://github.com/zumerlab/snapdom/commit/f49f5c1c050b83687d5a79365fca9ab4d280e4f4)
|
|
35
|
+
|
|
36
|
+
**Docs**
|
|
37
|
+
|
|
38
|
+
- **pdf:** rewrite the reference in plain words, capture the demo at dpr 2 [`b79e178`](https://github.com/zumerlab/snapdom/commit/b79e178f3f5fcd8b23c224ade730df830cf34d4a)
|
|
39
|
+
- **pdf:** fold the reference into the README [`e9f3a4f`](https://github.com/zumerlab/snapdom/commit/e9f3a4f8e0cde00e3a1bdab5f9ade5d06229346c)
|
|
40
|
+
- **site:** point the demos and docs at the published packages [`c57b2b3`](https://github.com/zumerlab/snapdom/commit/c57b2b38f3b57fc51e0cb7f64f8207ddad9421ef)
|
|
41
|
+
|
|
3
42
|
## 1.0.0
|
|
4
43
|
|
|
5
44
|
> 9 November 2026
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@zumer/snapdom-pdf)
|
|
4
4
|
[](https://www.npmjs.com/package/@zumer/snapdom)
|
|
5
5
|
|
|
6
|
-
PDF export for [SnapDOM](https://snapdom.dev/): `pdf()` adds `toPdf()` to a capture
|
|
6
|
+
PDF export for [SnapDOM](https://snapdom.dev/): `pdf()` adds `toPdf()` to a capture and turns it into a real PDF, with the capture's appearance, selectable and searchable text, links, bookmarks, pages, repeated table headers and fillable fields. Headers, footers, metadata, tagging and encryption are export options. Everything runs in the browser and nothing is uploaded. MIT licensed. Landing page and live demo: [snapdom.dev/plugins/pdf](https://snapdom.dev/plugins/pdf/).
|
|
7
7
|
|
|
8
8
|
## Install
|
|
9
9
|
|
|
@@ -11,20 +11,219 @@ PDF export for [SnapDOM](https://snapdom.dev/): `pdf()` adds `toPdf()` to a capt
|
|
|
11
11
|
npm install @zumer/snapdom@latest @zumer/snapdom-pdf@latest
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
It needs SnapDOM 3.8.3 or newer within 3.x. Up to SnapDOM plugins 4.x the same exporter shipped as `@zumer/snapdom-plugins/pdf`; only the import changes.
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Without a bundler, map both packages in an import map and serve the whole `@zumer/snapdom-pdf` folder, because its `index.js` imports files from `src/`.
|
|
17
|
+
|
|
18
|
+
```html
|
|
19
|
+
<script type="importmap">
|
|
20
|
+
{
|
|
21
|
+
"imports": {
|
|
22
|
+
"@zumer/snapdom": "/vendor/snapdom.mjs",
|
|
23
|
+
"@zumer/snapdom-pdf": "/vendor/snapdom-pdf/index.js"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
</script>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick start
|
|
17
30
|
|
|
18
31
|
```js
|
|
19
|
-
import { snapdom } from '@zumer/snapdom'
|
|
20
|
-
import { pdf } from '@zumer/snapdom-pdf'
|
|
32
|
+
import { snapdom } from '@zumer/snapdom'
|
|
33
|
+
import { pdf } from '@zumer/snapdom-pdf'
|
|
21
34
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
await
|
|
35
|
+
snapdom.plugins(pdf())
|
|
36
|
+
|
|
37
|
+
const shot = await snapdom(document.querySelector('#report'))
|
|
38
|
+
const blob = await shot.toPdf({ page: 'a4', download: 'report.pdf' })
|
|
25
39
|
```
|
|
26
40
|
|
|
27
|
-
|
|
41
|
+
Register the plugin before you capture. A capture made without it has no `toPdf()`. To use it on one capture only, pass it there: `snapdom(el, { plugins: [pdf()] })`.
|
|
42
|
+
|
|
43
|
+
`toPdf()` returns a PDF `Blob`. `download` also saves the file. `shot.to('pdf', options)` does the same as `toPdf(options)`. The types are in [index.d.ts](index.d.ts).
|
|
44
|
+
|
|
45
|
+
## Options on pdf()
|
|
46
|
+
|
|
47
|
+
Five options decide what the plugin reads from the page while SnapDOM captures it, so they go on `pdf()` and not on `toPdf()`.
|
|
48
|
+
|
|
49
|
+
| Option | Default | What it does |
|
|
50
|
+
|---|---|---|
|
|
51
|
+
| `formValues` | `true` | Include the values typed in inputs and the selected option. Passwords become bullets. |
|
|
52
|
+
| `shadow` | `true` | Read text inside open shadow roots. |
|
|
53
|
+
| `breakAvoid` | `true` | Measure blocks so page breaks avoid cutting them. |
|
|
54
|
+
| `outline` | `true` | Turn headings into bookmarks. A selector string picks other elements; `false` turns it off. |
|
|
55
|
+
| `forms` | `true` | Measure form controls so the PDF can have fillable fields. |
|
|
56
|
+
|
|
57
|
+
Every other option works in either place. On `pdf()` it becomes the default for every export; in `toPdf()` it applies to that export and wins.
|
|
58
|
+
|
|
59
|
+
## Pages
|
|
60
|
+
|
|
61
|
+
| Option | Default | What it does |
|
|
62
|
+
|---|---|---|
|
|
63
|
+
| `page` | `'fit'` | `'fit'` makes one page the size of the capture. Paper sizes: `'a3'` to `'a6'`, `'b4'`, `'b5'`, `'letter'`, `'legal'`, `'tabloid'`, `'executive'`, or `[width, height]` in points. |
|
|
64
|
+
| `orientation` | `'portrait'` | `'portrait'` or `'landscape'`. |
|
|
65
|
+
| `margin` | `24` | Margin on every side, in points. |
|
|
66
|
+
| `repeatHeaders` | `true` | Repeat a table's `<thead>` on each page the table continues to. |
|
|
67
|
+
|
|
68
|
+
Page breaks avoid table rows, list items, figures, quotes, images and anything with `break-inside: avoid`. CSS page breaks are respected. A block taller than a page still has to split.
|
|
69
|
+
|
|
70
|
+
## Image and file size
|
|
71
|
+
|
|
72
|
+
What you see in the PDF is an image of the capture, with invisible text on top so it can be selected and searched.
|
|
73
|
+
|
|
74
|
+
| Option | Default | What it does |
|
|
75
|
+
|---|---|---|
|
|
76
|
+
| `image` | `true` | Draw the captured image. `false` makes a PDF with text only. |
|
|
77
|
+
| `codec` | `'auto'` | Try JPEG and lossless and keep the smaller file, per image. `'jpeg'` or `'flate'` forces one. |
|
|
78
|
+
| `quality` | `0.92` | JPEG quality. It only matters when JPEG wins, which on normal pages is rare. |
|
|
79
|
+
| `backgroundColor` | none | Fill transparent areas with a colour. Usually makes the file smaller. |
|
|
80
|
+
|
|
81
|
+
Sharpness and size come from the capture: `snapdom(el, { scale, dpr })`. Both multiply the image's pixels and leave the page layout alone. The image keeps that many pixels per CSS pixel at the size it is printed. A capture enlarged to fill the paper is drawn at the enlarged size, so it stays as sharp as on screen. `dpr` defaults to the screen of the machine that exports, so set it, for example to `2`, to get the same file everywhere.
|
|
82
|
+
|
|
83
|
+
## Text and links
|
|
84
|
+
|
|
85
|
+
| Option | Default | What it does |
|
|
86
|
+
|---|---|---|
|
|
87
|
+
| `text` | `true` | Add the invisible text layer, so the text can be selected, searched and copied. |
|
|
88
|
+
| `links` | `true` | Make links clickable. Same-page anchors jump inside the PDF. |
|
|
89
|
+
| `debugText` | `false` | Paint the text layer red, to check where it sits. |
|
|
90
|
+
|
|
91
|
+
Links work for `http:`, `https:`, `mailto:` and `tel:`. Any other link is left out with a warning.
|
|
92
|
+
|
|
93
|
+
> Covering something with a box or a blur hides the pixels, not the text: it can still be selected in the PDF. To keep data out, remove or replace it before the capture.
|
|
94
|
+
|
|
95
|
+
## Fonts and sharp text
|
|
96
|
+
|
|
97
|
+
| Option | Default | What it does |
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| `embedFonts` | `true` | Embed the page's web fonts, only the letters the document uses. `'full'` embeds whole fonts; `false` none. |
|
|
100
|
+
| `vectorText` | `true` | Draw the text as real letters instead of pixels: sharp at any zoom and a lighter file. `false` keeps all the text in the image. |
|
|
101
|
+
|
|
102
|
+
The PDF can only embed fonts the capture carries, so capture with `snapdom(el, { embedFonts: true })`. Web fonts in TTF, OTF, WOFF and WOFF2 embed. System fonts have no file to embed. Copying text works the same with or without embedded fonts.
|
|
103
|
+
|
|
104
|
+
Text is drawn as real letters wherever the page's own font file can draw it, which needs embedded fonts. The rest stays as image, so the page always looks as it does on screen. These stay as image:
|
|
105
|
+
|
|
106
|
+
- right-to-left and complex scripts;
|
|
107
|
+
- a variable font at a weight other than the one its file was saved in;
|
|
108
|
+
- bold or italic the browser fakes because the page loaded no file for it;
|
|
109
|
+
- translucent or outlined text;
|
|
110
|
+
- small caps, tabular or old-style figures and other `font-feature-settings`;
|
|
111
|
+
- a word the browser hyphenated, and a word with a letter the font lacks;
|
|
112
|
+
- any text in a system font: the browser does not hand over its file.
|
|
113
|
+
|
|
114
|
+
The letters that are drawn leave the page image, so each one is in the file once: the PDF gets lighter and the text has no soft edge around it. Underlines, shadows and backgrounds stay in the image. A text that cannot be taken out of the image, such as the value of a form control, is not drawn and stays as image. This needs a `@zumer/snapdom` newer than 3.8.2; with an older one the letters are drawn over the image.
|
|
115
|
+
|
|
116
|
+
With `image: false` it gives a very small text-only PDF, without borders, backgrounds or pictures.
|
|
117
|
+
|
|
118
|
+
## Bookmarks and accessibility
|
|
119
|
+
|
|
120
|
+
| Option | Default | What it does |
|
|
121
|
+
|---|---|---|
|
|
122
|
+
| `outline` | `true` | Bookmarks from headings. Set it on `pdf()`. |
|
|
123
|
+
| `tagged` | `true` | Tag headings, paragraphs, lists, tables and figures for screen readers. |
|
|
124
|
+
| `lang` | from the page | Document language, for example `'en'` or `'es-MX'`. |
|
|
125
|
+
|
|
126
|
+
The PDF is marked accessible (PDF/UA-1) only when it qualifies: every font embedded, a language, a `meta.title`, alt text on every image and `fields: false`. There is no option to force it. When something is missing, the report says what.
|
|
127
|
+
|
|
128
|
+
## Fillable forms
|
|
129
|
+
|
|
130
|
+
| Option | Default | What it does |
|
|
131
|
+
|---|---|---|
|
|
132
|
+
| `fields` | `true` | Turn form controls into fields you can fill in the PDF. `false` keeps their values as plain text. |
|
|
133
|
+
|
|
134
|
+
Text inputs, textareas, checkboxes, radio buttons and selects become fields with their name, value and label. Read-only, disabled, required and maxlength carry over. Password fields are written empty. Buttons, sliders, colour pickers and file inputs stay as image. The PDF never contains scripts or submit actions.
|
|
135
|
+
|
|
136
|
+
## Header, footer and page numbers
|
|
137
|
+
|
|
138
|
+
| Option | Default | What it does |
|
|
139
|
+
|---|---|---|
|
|
140
|
+
| `header` | none | Text, a function, `{ left, center, right, size, font, color, rule, gap }` or an element. |
|
|
141
|
+
| `footer` | none | The same, at the bottom. |
|
|
142
|
+
| `pageNumbers` | `false` | `true` writes "1 / 4". `{ format, align, size, font, color }` changes it. |
|
|
143
|
+
|
|
144
|
+
```js
|
|
145
|
+
await shot.toPdf({
|
|
146
|
+
page: 'a4',
|
|
147
|
+
header: { left: 'North Studio', right: 'Delivery report' },
|
|
148
|
+
pageNumbers: { format: (page, pages) => `Page ${page} of ${pages}` },
|
|
149
|
+
})
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
These need a paper size and do nothing on `page: 'fit'`. Text is real PDF text. An element is captured as an image, so its text cannot be selected.
|
|
153
|
+
|
|
154
|
+
## Cover, contents, back page and watermark
|
|
155
|
+
|
|
156
|
+
| Option | Default | What it does |
|
|
157
|
+
|---|---|---|
|
|
158
|
+
| `cover` | none | An element captured as the first page. |
|
|
159
|
+
| `toc` | none | A table of contents from the headings. `true`, a title, or `{ title, levels, size, font, indent, dots, label, color, leaderColor }`. |
|
|
160
|
+
| `back` | none | An element captured as the last page. |
|
|
161
|
+
| `watermark` | none | Text or an element over every page. `{ text, opacity, angle, size, font, color }` or `{ element, opacity, angle, fit }`. |
|
|
162
|
+
|
|
163
|
+
Cover, contents and back page need a paper size. The watermark also works on `page: 'fit'`.
|
|
164
|
+
|
|
165
|
+
## Metadata
|
|
166
|
+
|
|
167
|
+
| Option | Default | What it does |
|
|
168
|
+
|---|---|---|
|
|
169
|
+
| `meta` | none | `{ title, author, subject, keywords, creator, created, modified }`. Viewers show the title instead of the file name. |
|
|
170
|
+
|
|
171
|
+
Dates are written only when you pass them. Pass `new Date()` when you want today. The same page exported twice gives the same file, byte for byte.
|
|
172
|
+
|
|
173
|
+
## Password
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
await shot.toPdf({
|
|
177
|
+
page: 'a4',
|
|
178
|
+
encrypt: { userPassword: 'ada-1815', ownerPassword: 'owner-key' },
|
|
179
|
+
})
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
`encrypt` protects the file with AES-256. `userPassword` is required. `ownerPassword` defaults to it. `permissions` takes `print`, `modify`, `copy`, `annotate`, `fillForms`, `assemble` and `printHighRes`, all `true` by default.
|
|
183
|
+
|
|
184
|
+
Only the password protects the file. Permissions are requests that a viewer may ignore. Encryption needs https or localhost, and an encrypted export is different every time.
|
|
185
|
+
|
|
186
|
+
## Output
|
|
187
|
+
|
|
188
|
+
| Option | Default | What it does |
|
|
189
|
+
|---|---|---|
|
|
190
|
+
| `download` | `false` | A file name, or `true` for `snapdom.pdf`. The Blob is still returned. |
|
|
191
|
+
| `deflate` | `true` | Compress the PDF's internal streams. |
|
|
192
|
+
|
|
193
|
+
## Progress, cancel and report
|
|
194
|
+
|
|
195
|
+
| Option | Default | What it does |
|
|
196
|
+
|---|---|---|
|
|
197
|
+
| `onProgress` | none | Called with `{ phase, done, total }` as pages are made. `total` is `null` until the page count is known. |
|
|
198
|
+
| `signal` | none | An `AbortSignal`. Aborting stops the export with an `AbortError`. |
|
|
199
|
+
| `onReport` | none | Called once the PDF is done, with what happened: pages, size, fields, fonts and warnings. |
|
|
200
|
+
|
|
201
|
+
```js
|
|
202
|
+
await shot.toPdf({
|
|
203
|
+
page: 'a4',
|
|
204
|
+
onProgress: ({ done, total }) => bar.update(done, total),
|
|
205
|
+
signal: controller.signal,
|
|
206
|
+
onReport: (report) => console.log(report.pages, report.warnings),
|
|
207
|
+
})
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Each warning in the report has a `code`, such as `link-unresolved` or `text-clipped`, so a test can check for them without reading messages.
|
|
211
|
+
|
|
212
|
+
## When something looks wrong
|
|
213
|
+
|
|
214
|
+
The plugin warns in the console with a `[snapdom-pdf]` prefix: a block split across pages, a link without a target, text cut off. The same warnings arrive in the report.
|
|
215
|
+
|
|
216
|
+
A grey box where an image should be means the capture could not read that image. It shows up in the capture's `result.warnings` as `image-fallback`. [Export a PDF with cross-origin images](https://snapdom.dev/how-to/pdf-cross-origin-images/) explains the fix.
|
|
217
|
+
|
|
218
|
+
If the PDF does not match the page, [open an issue](https://github.com/zumerlab/snapdom/issues) with a small example and we will fix it.
|
|
219
|
+
|
|
220
|
+
## Limits
|
|
221
|
+
|
|
222
|
+
- Text in a system font is an image, so a deep zoom shows the capture's resolution. Text in a web font is drawn as letters.
|
|
223
|
+
- Closed shadow roots cannot be read.
|
|
224
|
+
- Date inputs are written in ISO format, not as the browser shows them.
|
|
225
|
+
- An element used as header, footer or watermark has no selectable text. A repeated table header has no links.
|
|
226
|
+
- The full test suite runs in Chromium. Firefox and WebKit are checked for the main features.
|
|
28
227
|
|
|
29
228
|
## Migrating from `pdf-image`
|
|
30
229
|
|
package/index.d.ts
CHANGED
|
@@ -180,7 +180,7 @@ export interface PdfReport {
|
|
|
180
180
|
* configurable; the `ua-withheld` warning names the blockers when false.
|
|
181
181
|
*/
|
|
182
182
|
pdfua: boolean
|
|
183
|
-
/** Text runs
|
|
183
|
+
/** Text runs painted as real glyphs. 0 when `vectorText` is off or no font could paint any. */
|
|
184
184
|
vectorText: number
|
|
185
185
|
}
|
|
186
186
|
|
|
@@ -222,10 +222,19 @@ export interface PdfExportOptions {
|
|
|
222
222
|
/**
|
|
223
223
|
* Paint eligible text as real vector glyphs from the embedded fonts instead
|
|
224
224
|
* of leaving it invisible over the raster, crisp at any zoom. Only faithful
|
|
225
|
-
* where no shaping intervenes (left-to-right runs in an embedded face)
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
225
|
+
* where no shaping intervenes (left-to-right runs in an embedded face) and
|
|
226
|
+
* the font file holds the design the page drew, so these stay on the raster:
|
|
227
|
+
* RTL and uncovered runs, a variable font off the weight its file was saved
|
|
228
|
+
* in, a bold or italic the browser faked, translucent or outlined text, small
|
|
229
|
+
* caps and other glyph substitutions, a word the browser hyphenated.
|
|
230
|
+
*
|
|
231
|
+
* With `image: true` a painted word is drawn once: the page image is
|
|
232
|
+
* rasterized without its glyph fill (underline, shadow and background stay),
|
|
233
|
+
* which is where most of the file's weight goes. A paintable run that cannot
|
|
234
|
+
* be taken out of the image — a form control's value — is then left as image.
|
|
235
|
+
* Needs a core with `ctx.exports.editSvg`; on an older one the glyphs
|
|
236
|
+
* overpaint the raster. Pair with `image: false` for a tiny, fully-vector
|
|
237
|
+
* text PDF. Default true; `false` leaves every glyph in the page image.
|
|
229
238
|
*/
|
|
230
239
|
vectorText?: boolean
|
|
231
240
|
cover?: Element | null
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zumer/snapdom-pdf",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "PDF export for SnapDOM: searchable, paginated documents with selectable text, links and optional form fields",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"bump:dry": "npx @zumerbox/bump -d",
|
|
8
|
-
"bump": "npx @zumerbox/bump && npx @zumerbox/changelog"
|
|
8
|
+
"bump": "npx @zumerbox/bump && npx @zumerbox/changelog",
|
|
9
|
+
"release": "git add package.json CHANGELOG.md ../../package-lock.json && git commit -m \"Bumped pdf version\" && git push"
|
|
9
10
|
},
|
|
10
11
|
"exports": {
|
|
11
12
|
".": "./index.js"
|
|
@@ -16,7 +17,6 @@
|
|
|
16
17
|
"index.d.ts",
|
|
17
18
|
"src/",
|
|
18
19
|
"README.md",
|
|
19
|
-
"REFERENCE.md",
|
|
20
20
|
"CHANGELOG.md"
|
|
21
21
|
],
|
|
22
22
|
"keywords": [
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"url": "https://github.com/sponsors/tinchox5"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@zumer/snapdom": "^3.
|
|
45
|
+
"@zumer/snapdom": "^3.8.3"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@zumer/snapdom": "file:../.."
|
package/src/furniture.js
CHANGED
|
@@ -42,7 +42,7 @@ export function bandHeight(el, availW) {
|
|
|
42
42
|
*
|
|
43
43
|
* @param {Element} el
|
|
44
44
|
* @param {{scale: number, dpr: number, quality: number,
|
|
45
|
-
* backgroundColor: string|null, availW: number}} opts
|
|
45
|
+
* backgroundColor: string|null, availW: number, fitW?: number}} opts
|
|
46
46
|
*/
|
|
47
47
|
export async function captureBand(el, options, encodeImage) {
|
|
48
48
|
const img = await captureElement(el, options, encodeImage)
|
|
@@ -59,11 +59,15 @@ export async function captureBand(el, options, encodeImage) {
|
|
|
59
59
|
* @returns {Promise<object>} what `addStream` needs, plus `aspect` (height/width).
|
|
60
60
|
*/
|
|
61
61
|
export async function captureElement(el, {
|
|
62
|
-
scale, dpr, quality, backgroundColor, codec, captureOptions = {}, image = true,
|
|
62
|
+
scale, dpr, quality, backgroundColor, codec, captureOptions = {}, image = true, fitW = 0,
|
|
63
63
|
}, encodeImage) {
|
|
64
64
|
if (!el || el.nodeType !== 1) throw new TypeError('captureElement: expected an Element')
|
|
65
65
|
if (image && typeof encodeImage !== 'function') throw new TypeError('captureElement: encodeImage must be a function')
|
|
66
|
-
|
|
66
|
+
// `fitW` is the width in points the image is drawn at. Wider than the element's own
|
|
67
|
+
// box (CSS px x 0.75), the raster is enlarged to it the way the body's is (`magnify`
|
|
68
|
+
// in index.js), so a band or a cover is no softer than the page under it.
|
|
69
|
+
const boxW = fitW > 0 ? el.getBoundingClientRect().width * 0.75 : 0
|
|
70
|
+
const rasterScale = positive(scale, 1) * (boxW > 0 ? Math.max(1, fitW / boxW) : 1)
|
|
67
71
|
const rasterDpr = positive(dpr, 1)
|
|
68
72
|
const source = {
|
|
69
73
|
baseURL: String(el.ownerDocument?.baseURI || document.baseURI),
|