@zumer/snapdom 1.9.10-dev.1 → 1.9.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": "1.9.10-dev.1",
3
+ "version": "1.9.10",
4
4
  "description": "snapDOM captures HTML elements to images with exceptional speed and accuracy.",
5
5
  "main": "dist/snapdom.js",
6
6
  "module": "dist/snapdom.mjs",
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * snapDOM – ultra-fast DOM-to-image capture
3
- * TypeScript definitions
4
- *
3
+ * TypeScript definitions (v1.9.10-dev.2)
4
+ *
5
5
  * Notes:
6
- * - Style compression is always enabled internally (no user option).
6
+ * - Style compression is internal (no public option).
7
7
  * - Icon fonts are always embedded; `embedFonts` controls non-icon fonts only.
8
8
  */
9
9
 
@@ -11,11 +11,12 @@ export type RasterMime = "png" | "jpg" | "jpeg" | "webp";
11
11
  export type BlobType = "svg" | RasterMime;
12
12
 
13
13
  export type IconFontMatcher = string | RegExp;
14
+ export type CachePolicy = "disabled" | "full" | "auto" | "soft";
14
15
 
15
16
  export interface LocalFontDescriptor {
16
- /** CSS font-family name (e.g. "Inter") */
17
+ /** CSS font-family name (e.g. "Inter"). */
17
18
  family: string;
18
- /** URL to the font source (woff2/woff/ttf). Data URLs are allowed. */
19
+ /** URL to the font source (woff2/woff/ttf). Data URLs allowed. */
19
20
  src: string;
20
21
  /** CSS font-weight value (e.g. 400, "bold"). */
21
22
  weight?: string | number;
@@ -27,27 +28,16 @@ export interface LocalFontDescriptor {
27
28
 
28
29
  export interface CaptureOptions {
29
30
  /**
30
- * Skip small idle delays for faster overall capture on some browsers.
31
- * Default: true
32
- */
33
- fast?: boolean;
34
-
35
- /**
36
- * Inline non-icon fonts that are detected as used within the captured subtree.
37
- * Icon fonts are always embedded.
31
+ * Enable additional internal logs.
38
32
  * Default: false
39
33
  */
40
- embedFonts?: boolean;
41
-
42
- /**
43
- * Additional local fonts to be considered during embedding.
44
- */
45
- localFonts?: LocalFontDescriptor[];
34
+ debug?: boolean;
46
35
 
47
36
  /**
48
- * Extra icon font family matchers (by name or regex). Helpful for custom icon sets.
37
+ * Skip small idle delays for faster overall capture.
38
+ * Default: true
49
39
  */
50
- iconFonts?: IconFontMatcher | IconFontMatcher[];
40
+ fast?: boolean;
51
41
 
52
42
  /**
53
43
  * Output scale multiplier. If set, takes precedence over width/height.
@@ -67,10 +57,16 @@ export interface CaptureOptions {
67
57
  /** Target height for the exported image. Ignored if `scale` is provided. */
68
58
  height?: number;
69
59
 
70
- /** Fallback color for JPG/WebP exports (no alpha). Default: "#fff". */
71
- backgroundColor?: string;
60
+ /**
61
+ * Fallback color for lossy raster formats (JPG/WebP have no alpha).
62
+ * Default: "#ffffff" for JPG/JPEG/WebP, `null` otherwise.
63
+ */
64
+ backgroundColor?: string | null;
72
65
 
73
- /** Quality for JPG/WebP (0..1). Default: 1. */
66
+ /**
67
+ * Quality for JPG/WebP (0..1).
68
+ * Default: 0.92
69
+ */
74
70
  quality?: number;
75
71
 
76
72
  /**
@@ -83,24 +79,75 @@ export interface CaptureOptions {
83
79
  type?: BlobType;
84
80
 
85
81
  /**
86
- * CSS selectors for elements to exclude entirely from capture.
87
- * They are removed from the cloned subtree before processing.
82
+ * Preferred export format used by convenience methods / download.
83
+ * Default: "png"
88
84
  */
85
+ format?: "svg" | RasterMime;
86
+
87
+ /** CSS selectors removed from the cloned subtree before processing. */
89
88
  exclude?: string[];
90
89
 
91
90
  /**
92
- * Advanced filter; return false to exclude a node.
93
- * Applied to the cloned subtree during traversal.
91
+ * Advanced node filter; return false to exclude a node during traversal.
92
+ * Applied to the cloned subtree.
94
93
  */
95
94
  filter?: (el: Element) => boolean;
96
95
 
97
96
  /**
98
- * Reset mode for internal caches at the beginning of capture.
99
- * - "soft" (default): clear ephemeral/session caches (computed styles, per-capture maps).
100
- * - "hard": clear all caches including images/resources/fonts/base styles.
101
- * - "none": do not reset anything (fastest, may reuse stale resources).
97
+ * Whether to synthesize placeholders for broken images, etc.
98
+ * Default: true
99
+ */
100
+ placeholders?: boolean;
101
+
102
+ /**
103
+ * Inline non-icon fonts used within the captured subtree.
104
+ * Icon fonts are always embedded.
105
+ * Default: false
106
+ */
107
+ embedFonts?: boolean;
108
+
109
+ /**
110
+ * Additional local fonts to be considered during embedding.
111
+ */
112
+ localFonts?: LocalFontDescriptor[];
113
+
114
+ /**
115
+ * Extra icon font family matchers (by name or regex).
102
116
  */
103
- reset?: "soft" | "hard" | "none";
117
+ iconFonts?: IconFontMatcher | IconFontMatcher[];
118
+
119
+ /**
120
+ * Font family matchers to explicitly exclude from embedding.
121
+ */
122
+ excludeFonts?: IconFontMatcher[];
123
+
124
+ /**
125
+ * Fallback image source when an <img> fails to load.
126
+ * - String: use as-is.
127
+ * - Callback: receives measured width/height and original src, returns a URL string.
128
+ */
129
+ defaultImageUrl?:
130
+ | string
131
+ | ((
132
+ args: {
133
+ width?: number;
134
+ height?: number;
135
+ src?: string;
136
+ element: HTMLImageElement;
137
+ }
138
+ ) => string | Promise<string>);
139
+
140
+ /**
141
+ * Cache policy applied at capture start.
142
+ * Default: "soft"
143
+ */
144
+ cache?: CachePolicy;
145
+
146
+ /**
147
+ * Base filename used by `download`.
148
+ * Default: "snapDOM"
149
+ */
150
+ filename?: string;
104
151
  }
105
152
 
106
153
  export interface BlobOptions {
@@ -109,39 +156,39 @@ export interface BlobOptions {
109
156
  /** JPG/WebP quality (0..1). */
110
157
  quality?: number;
111
158
  /** Background override for lossy formats. */
112
- backgroundColor?: string;
159
+ backgroundColor?: string | null;
113
160
  }
114
161
 
115
162
  export interface DownloadOptions {
116
163
  /** File format. Default: "png". */
117
164
  format?: "svg" | RasterMime;
118
- /** Base filename without extension. Default: "capture". */
165
+ /** Base filename without extension. Default: "snapDOM". */
119
166
  filename?: string;
120
167
  /** Background override for lossy formats. */
121
- backgroundColor?: string;
122
- /** Quality for JPG/WebP (0..1). */
168
+ backgroundColor?: string | null;
169
+ /** JPG/WebP quality (0..1). Default: 0.92. */
123
170
  quality?: number;
124
171
  }
125
172
 
126
173
  export interface CaptureResult {
127
174
  /** SVG data URL representing the captured element. */
128
175
  url: string;
129
- /** Returns the raw SVG markup as string. */
176
+ /** Returns the same SVG data URL string. */
130
177
  toRaw(): string;
131
- /** Creates an HTMLImageElement from the SVG. */
132
- toImg(): Promise<HTMLImageElement>;
133
- /** Renders into a Canvas element (sized appropriately). */
134
- toCanvas(): Promise<HTMLCanvasElement>;
178
+ /** Creates an HTMLImageElement from the SVG (accepts options). */
179
+ toImg(options?: CaptureOptions): Promise<HTMLImageElement>;
180
+ /** Renders into a Canvas element (accepts options). */
181
+ toCanvas(options?: CaptureOptions): Promise<HTMLCanvasElement>;
135
182
  /** Exports to a Blob (SVG/PNG/JPG/WebP). */
136
- toBlob(options?: BlobOptions): Promise<Blob>;
183
+ toBlob(options?: CaptureOptions & BlobOptions): Promise<Blob>;
137
184
  /** Convenience PNG export (returns an <img>). */
138
- toPng(options?: { backgroundColor?: string; quality?: number }): Promise<HTMLImageElement>;
185
+ toPng(options?: CaptureOptions): Promise<HTMLImageElement>;
139
186
  /** Convenience JPG export (returns an <img>). */
140
- toJpg(options?: { backgroundColor?: string; quality?: number }): Promise<HTMLImageElement>;
187
+ toJpg(options?: CaptureOptions): Promise<HTMLImageElement>;
141
188
  /** Convenience WebP export (returns an <img>). */
142
- toWebp(options?: { backgroundColor?: string; quality?: number }): Promise<HTMLImageElement>;
189
+ toWebp(options?: CaptureOptions): Promise<HTMLImageElement>;
143
190
  /** Triggers a file download. */
144
- download(options?: DownloadOptions): Promise<void>;
191
+ download(options?: CaptureOptions & DownloadOptions): Promise<void>;
145
192
  }
146
193
 
147
194
  /**
@@ -163,16 +210,27 @@ export declare namespace snapdom {
163
210
  * Preload resources (images/fonts) to avoid first-capture stalls.
164
211
  */
165
212
  export interface PreCacheOptions {
166
- /** Root element to scan. Default: document.body. */
167
- root?: Element | Document;
168
213
  /** Inline non-icon fonts during preload. Default: true. */
169
214
  embedFonts?: boolean;
170
215
  /** Additional local fonts. */
171
216
  localFonts?: LocalFontDescriptor[];
172
217
  /** Proxy for CORS fallbacks. */
173
218
  useProxy?: string;
219
+ /** Font family matchers to explicitly exclude from embedding. */
220
+ excludeFonts?: IconFontMatcher[];
221
+ /**
222
+ * Cache policy used during precache.
223
+ * Note: for `preCache` the option name in runtime is `cacheOpt`.
224
+ */
225
+ cacheOpt?: CachePolicy;
174
226
  }
175
227
 
176
- export declare function preCache(options?: PreCacheOptions): Promise<void>;
228
+ /**
229
+ * Preload resources rooted at `root` (defaults to `document`).
230
+ */
231
+ export declare function preCache(
232
+ root?: Element | Document,
233
+ options?: PreCacheOptions
234
+ ): Promise<void>;
177
235
 
178
236
  export {};