@zumer/snapdom 2.24.7 → 2.24.12
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 +14 -7
- package/dist/plugins.mjs +1 -1
- package/dist/preCache.mjs +1 -1
- package/dist/snapdom.js +9 -9
- package/dist/snapdom.mjs +9 -9
- package/package.json +11 -5
- package/types/snapdom.d.ts +43 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zumer/snapdom",
|
|
3
|
-
"version": "2.24.
|
|
3
|
+
"version": "2.24.12",
|
|
4
4
|
"description": "Fast, modern alternative to html2canvas — captures HTML elements to images (PNG, JPG, SVG, WebP) with exceptional speed and accuracy.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/snapdom.js",
|
|
@@ -33,11 +33,13 @@
|
|
|
33
33
|
"compile": "node esbuild.config.mjs",
|
|
34
34
|
"lint": "eslint src __tests__ --ext .js",
|
|
35
35
|
"lint:fix": "eslint src __tests__ --ext .js --fix",
|
|
36
|
+
"test:bundle": "npm run compile && node scripts/verify-legacy-bundle.mjs",
|
|
36
37
|
"test:types": "tsc --noEmit",
|
|
37
|
-
"test": "npm run lint:fix && npm run test:types && npx vitest run --browser.headless --reporter=verbose",
|
|
38
|
+
"test": "npm run lint:fix && npm run test:types && npm run test:bundle && npx vitest run --browser.headless --reporter=verbose",
|
|
39
|
+
"test:visual": "npx vitest run __tests__/visual.demos. --browser.headless --reporter=verbose",
|
|
38
40
|
"test:firefox": "BROWSER=firefox npx vitest run --browser.headless --reporter=verbose",
|
|
39
41
|
"test:webkit": "BROWSER=webkit npx vitest run --browser.headless --reporter=verbose",
|
|
40
|
-
"test:full": "npm run lint:fix && npm run test:types && BROWSER=all npx vitest run --browser.headless --reporter=verbose",
|
|
42
|
+
"test:full": "npm run lint:fix && npm run test:types && npm run test:bundle && BROWSER=all npx vitest run --browser.headless --reporter=verbose",
|
|
41
43
|
"report:cross": "node scripts/cross-report.mjs",
|
|
42
44
|
"test:coverage": "npx vitest run --browser.headless --coverage",
|
|
43
45
|
"test:benchmark": "npx vitest bench --browser.headless --watch=false",
|
|
@@ -83,12 +85,16 @@
|
|
|
83
85
|
"bugs": {
|
|
84
86
|
"url": "https://github.com/zumerlab/snapdom/issues"
|
|
85
87
|
},
|
|
86
|
-
"homepage": "https://
|
|
88
|
+
"homepage": "https://snapdom.dev/",
|
|
89
|
+
"funding": {
|
|
90
|
+
"type": "github",
|
|
91
|
+
"url": "https://github.com/sponsors/tinchox5"
|
|
92
|
+
},
|
|
87
93
|
"devDependencies": {
|
|
88
94
|
"@eslint/js": "^9.36.0",
|
|
89
95
|
"@vitest/browser": "^3.1.2",
|
|
90
96
|
"@vitest/coverage-v8": "^3.1.2",
|
|
91
|
-
"@zumer/snapdiff": "^0.
|
|
97
|
+
"@zumer/snapdiff": "^0.3.0",
|
|
92
98
|
"esbuild": "^0.28.1",
|
|
93
99
|
"eslint": "^9.36.0",
|
|
94
100
|
"globals": "^16.4.0",
|
package/types/snapdom.d.ts
CHANGED
|
@@ -227,20 +227,40 @@ export interface SnapdomOptions {
|
|
|
227
227
|
* Capture context (hook state)
|
|
228
228
|
* ========================= */
|
|
229
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Union of the two runtime context shapes. Which fields actually exist depends on the hook:
|
|
232
|
+
*
|
|
233
|
+
* - Clone-phase hooks (beforeSnap, beforeClone, afterClone, beforeRender, afterRender) get the
|
|
234
|
+
* capture state: `element`, `options`, `plugins`, `clone`, `classCSS`, `styleCache`, `nodeMap`,
|
|
235
|
+
* `fontsCSS`, `baseCSS`, `scrollbarCSS`, `svgString`, `dataURL`. Capture options are NOT
|
|
236
|
+
* flattened onto it there: read them from `ctx.options`.
|
|
237
|
+
* - Export-phase hooks (beforeExport, afterExport, defineExports) get a spread of the normalized
|
|
238
|
+
* options plus `element`, `meta`, `export` and (in defineExports) `exports`. There is no
|
|
239
|
+
* `clone` or `nodeMap` at that point: the clone is already serialized.
|
|
240
|
+
*
|
|
241
|
+
* Consequence: data stashed as `ctx.__x` in afterClone is invisible in defineExports. Mirror it
|
|
242
|
+
* on `ctx.options.__x`, which is the object the export context is spread from.
|
|
243
|
+
*/
|
|
230
244
|
export interface CaptureContext extends SnapdomOptions {
|
|
231
|
-
/** Input element being captured. */
|
|
245
|
+
/** Input element being captured. Present in every hook. */
|
|
232
246
|
element: Element;
|
|
233
247
|
|
|
234
|
-
/**
|
|
248
|
+
/** Normalized capture options. Present in clone-phase hooks only (export hooks are spread from it). */
|
|
249
|
+
options?: SnapdomOptions & Record<string, any>;
|
|
250
|
+
|
|
251
|
+
/** Cloned root (detached). Clone-phase hooks only, from `afterClone` onward. */
|
|
235
252
|
clone?: HTMLElement | SVGElement | null;
|
|
236
253
|
|
|
237
|
-
/** Internal style/class caches (opaque to user). */
|
|
254
|
+
/** Internal style/class caches (opaque to user). Clone-phase hooks only. */
|
|
238
255
|
classCSS?: string;
|
|
239
256
|
styleCache?: unknown;
|
|
240
257
|
fontsCSS?: string;
|
|
241
258
|
baseCSS?: string;
|
|
259
|
+
scrollbarCSS?: string;
|
|
260
|
+
/** Clone node → source node map for this capture. Clone-phase hooks only. */
|
|
261
|
+
nodeMap?: Map<Node, Node>;
|
|
242
262
|
|
|
243
|
-
/** Serialized artifacts, available after render. */
|
|
263
|
+
/** Serialized artifacts, available after render. Clone-phase hooks only. */
|
|
244
264
|
svgString?: string;
|
|
245
265
|
dataURL?: string;
|
|
246
266
|
|
|
@@ -269,7 +289,7 @@ export interface CaptureContext extends SnapdomOptions {
|
|
|
269
289
|
|
|
270
290
|
export type Exporter = (ctx: CaptureContext, opts?: any) => Promise<any>;
|
|
271
291
|
|
|
272
|
-
/** Map returned by `defineExports`: keys are exposed on the result (e.g
|
|
292
|
+
/** Map returned by `defineExports`: keys are exposed on the result as a `to<Name>()` helper and through `to(name)` (e.g. `pdf` → `result.toPdf()` and `result.to('pdf')`). */
|
|
273
293
|
export type ExportMap = Record<string, Exporter>;
|
|
274
294
|
|
|
275
295
|
/* =========================
|
|
@@ -288,16 +308,25 @@ export interface SnapdomPlugin {
|
|
|
288
308
|
afterRender?(context: CaptureContext): void | Promise<void>;
|
|
289
309
|
|
|
290
310
|
/** Runs before EACH export. */
|
|
291
|
-
beforeExport?(
|
|
311
|
+
beforeExport?(
|
|
312
|
+
context: CaptureContext,
|
|
313
|
+
payload: { format: string; options: any }
|
|
314
|
+
): void | Promise<void>;
|
|
292
315
|
/**
|
|
293
|
-
* Runs after EACH export
|
|
294
|
-
*
|
|
316
|
+
* Runs after EACH export. Observation only: the value returned here becomes the payload
|
|
317
|
+
* passed to the next plugin's afterExport, but what the caller receives from
|
|
318
|
+
* toPng()/toBlob()/... is always what the exporter produced. To change an output,
|
|
319
|
+
* register your own export with `defineExports`.
|
|
295
320
|
*/
|
|
296
|
-
afterExport?(
|
|
321
|
+
afterExport?(
|
|
322
|
+
context: CaptureContext,
|
|
323
|
+
payload: { format: string; options: any; result: any }
|
|
324
|
+
): any | Promise<any>;
|
|
297
325
|
|
|
298
326
|
/**
|
|
299
327
|
* Provide custom exporters (e.g., { pdf: async (ctx, opts) => Blob }).
|
|
300
|
-
* Keys are exposed on the capture result as
|
|
328
|
+
* Keys are exposed on the capture result as a `to<Name>()` helper (toPdf()) and through
|
|
329
|
+
* `to(name)` (result.to('pdf')). Bare index access (result.pdf()) is NOT generated.
|
|
301
330
|
*/
|
|
302
331
|
defineExports?(context: CaptureContext): ExportMap | Promise<ExportMap>;
|
|
303
332
|
|
|
@@ -387,10 +416,11 @@ export interface CaptureResult {
|
|
|
387
416
|
|
|
388
417
|
/**
|
|
389
418
|
* Custom exporters exposed by plugins:
|
|
390
|
-
* - As helpers: a plugin returning { pdf: (...) => ... }
|
|
391
|
-
* -
|
|
419
|
+
* - As helpers: a plugin returning { pdf: (...) => ... } enables result.toPdf(...)
|
|
420
|
+
* - By name: result.to('pdf', options)
|
|
392
421
|
*
|
|
393
|
-
*
|
|
422
|
+
* The index signature exists because helper names are not known ahead of time; it does
|
|
423
|
+
* not mean result['pdf']() is defined (it is not: only the toX() helper is generated).
|
|
394
424
|
*/
|
|
395
425
|
[key: string]: any;
|
|
396
426
|
}
|