@zumer/snapdom 1.9.9 → 1.9.10-dev.1
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 +123 -84
- package/dist/snapdom.js +1542 -811
- package/dist/snapdom.min.js +5 -3
- package/dist/snapdom.min.mjs +5 -3
- package/dist/snapdom.mjs +1517 -767
- package/package.json +1 -1
- package/types/snapdom.d.ts +171 -60
package/package.json
CHANGED
package/types/snapdom.d.ts
CHANGED
|
@@ -1,67 +1,178 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
/**
|
|
2
|
+
* snapDOM – ultra-fast DOM-to-image capture
|
|
3
|
+
* TypeScript definitions
|
|
4
|
+
*
|
|
5
|
+
* Notes:
|
|
6
|
+
* - Style compression is always enabled internally (no user option).
|
|
7
|
+
* - Icon fonts are always embedded; `embedFonts` controls non-icon fonts only.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type RasterMime = "png" | "jpg" | "jpeg" | "webp";
|
|
11
|
+
export type BlobType = "svg" | RasterMime;
|
|
12
|
+
|
|
13
|
+
export type IconFontMatcher = string | RegExp;
|
|
14
|
+
|
|
15
|
+
export interface LocalFontDescriptor {
|
|
16
|
+
/** CSS font-family name (e.g. "Inter") */
|
|
17
|
+
family: string;
|
|
18
|
+
/** URL to the font source (woff2/woff/ttf). Data URLs are allowed. */
|
|
19
|
+
src: string;
|
|
20
|
+
/** CSS font-weight value (e.g. 400, "bold"). */
|
|
21
|
+
weight?: string | number;
|
|
22
|
+
/** CSS font-style value (e.g. "normal", "italic"). */
|
|
23
|
+
style?: string;
|
|
24
|
+
/** CSS font-stretch as percentage (e.g. 100 for normal). */
|
|
25
|
+
stretchPct?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface CaptureOptions {
|
|
29
|
+
/**
|
|
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.
|
|
38
|
+
* Default: false
|
|
39
|
+
*/
|
|
40
|
+
embedFonts?: boolean;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Additional local fonts to be considered during embedding.
|
|
44
|
+
*/
|
|
45
|
+
localFonts?: LocalFontDescriptor[];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Extra icon font family matchers (by name or regex). Helpful for custom icon sets.
|
|
49
|
+
*/
|
|
50
|
+
iconFonts?: IconFontMatcher | IconFontMatcher[];
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Output scale multiplier. If set, takes precedence over width/height.
|
|
54
|
+
* Default: 1
|
|
55
|
+
*/
|
|
56
|
+
scale?: number;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Device pixel ratio to use for raster exports.
|
|
60
|
+
* Default: `window.devicePixelRatio` at capture time.
|
|
61
|
+
*/
|
|
62
|
+
dpr?: number;
|
|
63
|
+
|
|
64
|
+
/** Target width for the exported image. Ignored if `scale` is provided. */
|
|
65
|
+
width?: number;
|
|
66
|
+
|
|
67
|
+
/** Target height for the exported image. Ignored if `scale` is provided. */
|
|
68
|
+
height?: number;
|
|
69
|
+
|
|
70
|
+
/** Fallback color for JPG/WebP exports (no alpha). Default: "#fff". */
|
|
71
|
+
backgroundColor?: string;
|
|
72
|
+
|
|
73
|
+
/** Quality for JPG/WebP (0..1). Default: 1. */
|
|
74
|
+
quality?: number;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Proxy base URL used as a fallback for CORS-restricted images/fonts.
|
|
78
|
+
* Example: "https://corsproxy.io/?url="
|
|
79
|
+
*/
|
|
80
|
+
useProxy?: string;
|
|
81
|
+
|
|
82
|
+
/** Preferred Blob type for `toBlob`. Default: "svg". */
|
|
83
|
+
type?: BlobType;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* CSS selectors for elements to exclude entirely from capture.
|
|
87
|
+
* They are removed from the cloned subtree before processing.
|
|
88
|
+
*/
|
|
89
|
+
exclude?: string[];
|
|
34
90
|
|
|
35
91
|
/**
|
|
36
|
-
*
|
|
92
|
+
* Advanced filter; return false to exclude a node.
|
|
93
|
+
* Applied to the cloned subtree during traversal.
|
|
37
94
|
*/
|
|
38
|
-
|
|
39
|
-
element: HTMLElement,
|
|
40
|
-
options?: SnapOptions
|
|
41
|
-
): Promise<SnapResult>;
|
|
42
|
-
|
|
43
|
-
export namespace snapdom {
|
|
44
|
-
function capture(element: HTMLElement, options?: SnapOptions): Promise<SnapResult>;
|
|
45
|
-
function toRaw(element: HTMLElement, options?: SnapOptions): Promise<string>;
|
|
46
|
-
function toImg(element: HTMLElement, options?: SnapOptions): Promise<HTMLImageElement>;
|
|
47
|
-
function toCanvas(element: HTMLElement, options?: SnapOptions): Promise<HTMLCanvasElement>;
|
|
48
|
-
function toBlob(element: HTMLElement, options?: SnapOptions): Promise<Blob>;
|
|
49
|
-
function toPng(element: HTMLElement, options?: SnapOptions): Promise<HTMLImageElement>;
|
|
50
|
-
function toJpg(element: HTMLElement, options?: SnapOptions): Promise<HTMLImageElement>;
|
|
51
|
-
function toWebp(element: HTMLElement, options?: SnapOptions): Promise<HTMLImageElement>;
|
|
52
|
-
function download(element: HTMLElement, options?: SnapOptions): Promise<void>;
|
|
53
|
-
}
|
|
95
|
+
filter?: (el: Element) => boolean;
|
|
54
96
|
|
|
55
97
|
/**
|
|
56
|
-
*
|
|
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).
|
|
57
102
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
103
|
+
reset?: "soft" | "hard" | "none";
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface BlobOptions {
|
|
107
|
+
/** Blob type to export. Default: "svg". */
|
|
108
|
+
type?: BlobType;
|
|
109
|
+
/** JPG/WebP quality (0..1). */
|
|
110
|
+
quality?: number;
|
|
111
|
+
/** Background override for lossy formats. */
|
|
112
|
+
backgroundColor?: string;
|
|
67
113
|
}
|
|
114
|
+
|
|
115
|
+
export interface DownloadOptions {
|
|
116
|
+
/** File format. Default: "png". */
|
|
117
|
+
format?: "svg" | RasterMime;
|
|
118
|
+
/** Base filename without extension. Default: "capture". */
|
|
119
|
+
filename?: string;
|
|
120
|
+
/** Background override for lossy formats. */
|
|
121
|
+
backgroundColor?: string;
|
|
122
|
+
/** Quality for JPG/WebP (0..1). */
|
|
123
|
+
quality?: number;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface CaptureResult {
|
|
127
|
+
/** SVG data URL representing the captured element. */
|
|
128
|
+
url: string;
|
|
129
|
+
/** Returns the raw SVG markup as string. */
|
|
130
|
+
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>;
|
|
135
|
+
/** Exports to a Blob (SVG/PNG/JPG/WebP). */
|
|
136
|
+
toBlob(options?: BlobOptions): Promise<Blob>;
|
|
137
|
+
/** Convenience PNG export (returns an <img>). */
|
|
138
|
+
toPng(options?: { backgroundColor?: string; quality?: number }): Promise<HTMLImageElement>;
|
|
139
|
+
/** Convenience JPG export (returns an <img>). */
|
|
140
|
+
toJpg(options?: { backgroundColor?: string; quality?: number }): Promise<HTMLImageElement>;
|
|
141
|
+
/** Convenience WebP export (returns an <img>). */
|
|
142
|
+
toWebp(options?: { backgroundColor?: string; quality?: number }): Promise<HTMLImageElement>;
|
|
143
|
+
/** Triggers a file download. */
|
|
144
|
+
download(options?: DownloadOptions): Promise<void>;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Capture an element and return reusable export helpers.
|
|
149
|
+
*/
|
|
150
|
+
export declare function snapdom(el: Element, options?: CaptureOptions): Promise<CaptureResult>;
|
|
151
|
+
|
|
152
|
+
export declare namespace snapdom {
|
|
153
|
+
function toImg(el: Element, options?: CaptureOptions): Promise<HTMLImageElement>;
|
|
154
|
+
function toCanvas(el: Element, options?: CaptureOptions): Promise<HTMLCanvasElement>;
|
|
155
|
+
function toBlob(el: Element, options?: CaptureOptions & BlobOptions): Promise<Blob>;
|
|
156
|
+
function toPng(el: Element, options?: CaptureOptions): Promise<HTMLImageElement>;
|
|
157
|
+
function toJpg(el: Element, options?: CaptureOptions): Promise<HTMLImageElement>;
|
|
158
|
+
function toWebp(el: Element, options?: CaptureOptions): Promise<HTMLImageElement>;
|
|
159
|
+
function download(el: Element, options?: CaptureOptions & DownloadOptions): Promise<void>;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Preload resources (images/fonts) to avoid first-capture stalls.
|
|
164
|
+
*/
|
|
165
|
+
export interface PreCacheOptions {
|
|
166
|
+
/** Root element to scan. Default: document.body. */
|
|
167
|
+
root?: Element | Document;
|
|
168
|
+
/** Inline non-icon fonts during preload. Default: true. */
|
|
169
|
+
embedFonts?: boolean;
|
|
170
|
+
/** Additional local fonts. */
|
|
171
|
+
localFonts?: LocalFontDescriptor[];
|
|
172
|
+
/** Proxy for CORS fallbacks. */
|
|
173
|
+
useProxy?: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export declare function preCache(options?: PreCacheOptions): Promise<void>;
|
|
177
|
+
|
|
178
|
+
export {};
|