@zumer/snapdom 2.24.7 → 2.24.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zumer/snapdom",
3
- "version": "2.24.7",
3
+ "version": "2.24.10",
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",
@@ -83,7 +83,11 @@
83
83
  "bugs": {
84
84
  "url": "https://github.com/zumerlab/snapdom/issues"
85
85
  },
86
- "homepage": "https://zumerlab.github.io/snapdom/",
86
+ "homepage": "https://snapdom.dev/",
87
+ "funding": {
88
+ "type": "github",
89
+ "url": "https://github.com/sponsors/tinchox5"
90
+ },
87
91
  "devDependencies": {
88
92
  "@eslint/js": "^9.36.0",
89
93
  "@vitest/browser": "^3.1.2",
@@ -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
- /** Cloned root (detached), available after `beforeClone`/`afterClone`. */
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., `pdf` → `result.toPdf()` as well as `result['pdf']()`). */
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?(context: CaptureContext): void | Promise<void>;
311
+ beforeExport?(
312
+ context: CaptureContext,
313
+ payload: { format: string; options: any }
314
+ ): void | Promise<void>;
292
315
  /**
293
- * Runs after EACH export; returning a value will be chained to the next plugin
294
- * (transform pipeline). If undefined is returned, the prior result is preserved.
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?(context: CaptureContext, result: any): any | Promise<any>;
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 helpers (toPdf()) and as index access (result['pdf']()).
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: (...) => ... } also enables result.toPdf(...)
391
- * - As index access: result["pdf"](...)
419
+ * - As helpers: a plugin returning { pdf: (...) => ... } enables result.toPdf(...)
420
+ * - By name: result.to('pdf', options)
392
421
  *
393
- * Since keys are not known ahead of time, we allow index access.
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
  }