@zumer/snapdom 1.9.10-dev.2 → 1.9.11
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 +64 -40
- package/dist/snapdom.js +58 -32
- package/dist/snapdom.min.js +3 -3
- package/dist/snapdom.min.mjs +4 -4
- package/dist/snapdom.mjs +58 -32
- package/package.json +1 -1
- package/types/snapdom.d.ts +100 -56
package/types/snapdom.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* snapDOM – ultra-fast DOM-to-image capture
|
|
3
|
-
* TypeScript definitions
|
|
3
|
+
* TypeScript definitions (v1.9.10-dev.2)
|
|
4
4
|
*
|
|
5
5
|
* Notes:
|
|
6
|
-
* - Style compression is
|
|
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
|
|
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
|
-
*
|
|
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
|
-
|
|
34
|
+
debug?: boolean;
|
|
41
35
|
|
|
42
36
|
/**
|
|
43
|
-
*
|
|
44
|
-
|
|
45
|
-
localFonts?: LocalFontDescriptor[];
|
|
46
|
-
|
|
47
|
-
/**
|
|
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
|
-
|
|
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
|
-
/**
|
|
71
|
-
|
|
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
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Quality for JPG/WebP (0..1).
|
|
68
|
+
* Default: 0.92
|
|
69
|
+
*/
|
|
74
70
|
quality?: number;
|
|
75
71
|
|
|
76
72
|
/**
|
|
@@ -83,24 +79,47 @@ export interface CaptureOptions {
|
|
|
83
79
|
type?: BlobType;
|
|
84
80
|
|
|
85
81
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
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
|
|
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
|
-
*
|
|
99
|
-
*
|
|
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
|
|
102
99
|
*/
|
|
103
|
-
|
|
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).
|
|
116
|
+
*/
|
|
117
|
+
iconFonts?: IconFontMatcher | IconFontMatcher[];
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Font family matchers to explicitly exclude from embedding.
|
|
121
|
+
*/
|
|
122
|
+
excludeFonts?: IconFontMatcher[];
|
|
104
123
|
|
|
105
124
|
/**
|
|
106
125
|
* Fallback image source when an <img> fails to load.
|
|
@@ -108,13 +127,27 @@ export interface CaptureOptions {
|
|
|
108
127
|
* - Callback: receives measured width/height and original src, returns a URL string.
|
|
109
128
|
*/
|
|
110
129
|
defaultImageUrl?:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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;
|
|
118
151
|
}
|
|
119
152
|
|
|
120
153
|
export interface BlobOptions {
|
|
@@ -123,39 +156,39 @@ export interface BlobOptions {
|
|
|
123
156
|
/** JPG/WebP quality (0..1). */
|
|
124
157
|
quality?: number;
|
|
125
158
|
/** Background override for lossy formats. */
|
|
126
|
-
backgroundColor?: string;
|
|
159
|
+
backgroundColor?: string | null;
|
|
127
160
|
}
|
|
128
161
|
|
|
129
162
|
export interface DownloadOptions {
|
|
130
163
|
/** File format. Default: "png". */
|
|
131
164
|
format?: "svg" | RasterMime;
|
|
132
|
-
/** Base filename without extension. Default: "
|
|
165
|
+
/** Base filename without extension. Default: "snapDOM". */
|
|
133
166
|
filename?: string;
|
|
134
167
|
/** Background override for lossy formats. */
|
|
135
|
-
backgroundColor?: string;
|
|
136
|
-
/**
|
|
168
|
+
backgroundColor?: string | null;
|
|
169
|
+
/** JPG/WebP quality (0..1). Default: 0.92. */
|
|
137
170
|
quality?: number;
|
|
138
171
|
}
|
|
139
172
|
|
|
140
173
|
export interface CaptureResult {
|
|
141
174
|
/** SVG data URL representing the captured element. */
|
|
142
175
|
url: string;
|
|
143
|
-
/** Returns the
|
|
176
|
+
/** Returns the same SVG data URL string. */
|
|
144
177
|
toRaw(): string;
|
|
145
|
-
/** Creates an HTMLImageElement from the SVG. */
|
|
146
|
-
toImg(): Promise<HTMLImageElement>;
|
|
147
|
-
/** Renders into a Canvas element (
|
|
148
|
-
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>;
|
|
149
182
|
/** Exports to a Blob (SVG/PNG/JPG/WebP). */
|
|
150
|
-
toBlob(options?: BlobOptions): Promise<Blob>;
|
|
183
|
+
toBlob(options?: CaptureOptions & BlobOptions): Promise<Blob>;
|
|
151
184
|
/** Convenience PNG export (returns an <img>). */
|
|
152
|
-
toPng(options?:
|
|
185
|
+
toPng(options?: CaptureOptions): Promise<HTMLImageElement>;
|
|
153
186
|
/** Convenience JPG export (returns an <img>). */
|
|
154
|
-
toJpg(options?:
|
|
187
|
+
toJpg(options?: CaptureOptions): Promise<HTMLImageElement>;
|
|
155
188
|
/** Convenience WebP export (returns an <img>). */
|
|
156
|
-
toWebp(options?:
|
|
189
|
+
toWebp(options?: CaptureOptions): Promise<HTMLImageElement>;
|
|
157
190
|
/** Triggers a file download. */
|
|
158
|
-
download(options?: DownloadOptions): Promise<void>;
|
|
191
|
+
download(options?: CaptureOptions & DownloadOptions): Promise<void>;
|
|
159
192
|
}
|
|
160
193
|
|
|
161
194
|
/**
|
|
@@ -177,16 +210,27 @@ export declare namespace snapdom {
|
|
|
177
210
|
* Preload resources (images/fonts) to avoid first-capture stalls.
|
|
178
211
|
*/
|
|
179
212
|
export interface PreCacheOptions {
|
|
180
|
-
/** Root element to scan. Default: document.body. */
|
|
181
|
-
root?: Element | Document;
|
|
182
213
|
/** Inline non-icon fonts during preload. Default: true. */
|
|
183
214
|
embedFonts?: boolean;
|
|
184
215
|
/** Additional local fonts. */
|
|
185
216
|
localFonts?: LocalFontDescriptor[];
|
|
186
217
|
/** Proxy for CORS fallbacks. */
|
|
187
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;
|
|
188
226
|
}
|
|
189
227
|
|
|
190
|
-
|
|
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>;
|
|
191
235
|
|
|
192
236
|
export {};
|