@takumi-rs/core 1.8.7 → 2.0.0-beta.0
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/dist/export.cjs +153 -154
- package/dist/export.d.cts +174 -73
- package/dist/export.d.mts +174 -73
- package/dist/export.mjs +152 -153
- package/index.d.ts +106 -33
- package/package.json +12 -12
package/dist/export.d.cts
CHANGED
|
@@ -31,29 +31,6 @@ type KeyframesRuleList = {
|
|
|
31
31
|
}[];
|
|
32
32
|
}[];
|
|
33
33
|
type Keyframes = KeyframesMap | KeyframesRuleList;
|
|
34
|
-
/** The main renderer for Takumi image rendering engine (Node.js version). */
|
|
35
|
-
declare class Renderer$1 {
|
|
36
|
-
/** Creates a new Renderer instance. */
|
|
37
|
-
constructor(options?: ConstructRendererOptions | undefined | null);
|
|
38
|
-
/** Puts a persistent image into the renderer's internal store asynchronously. */
|
|
39
|
-
putPersistentImage(source: ImageSource, signal?: AbortSignal): Promise<void>;
|
|
40
|
-
/** Loads a font synchronously. */
|
|
41
|
-
loadFontSync(font: Font): void;
|
|
42
|
-
/** Loads a font into the renderer asynchronously. */
|
|
43
|
-
loadFont(data: Font, signal?: AbortSignal): Promise<number>;
|
|
44
|
-
/** Loads multiple fonts into the renderer asynchronously. */
|
|
45
|
-
loadFonts(fonts: Font[], signal?: AbortSignal): Promise<number>;
|
|
46
|
-
/** Clears the renderer's internal image store. */
|
|
47
|
-
clearImageStore(): void;
|
|
48
|
-
/** Renders a node tree into an image buffer asynchronously. */
|
|
49
|
-
render(source: Node, options?: RenderOptions, signal?: AbortSignal): Promise<Buffer>;
|
|
50
|
-
/** Measures a node tree and returns layout information asynchronously. */
|
|
51
|
-
measure(source: Node, options?: RenderOptions, signal?: AbortSignal): Promise<MeasuredNode>;
|
|
52
|
-
/** Renders a sequential scene animation into a buffer asynchronously. */
|
|
53
|
-
renderAnimation(options: RenderAnimationOptions, signal?: AbortSignal): Promise<Buffer>;
|
|
54
|
-
/** Encodes a precomputed frame sequence into an animated image buffer asynchronously. */
|
|
55
|
-
encodeFrames(source: AnimationFrameSource[], options: EncodeFramesOptions, signal?: AbortSignal): Promise<Buffer>;
|
|
56
|
-
}
|
|
57
34
|
/** Represents a single frame in a precomputed animation sequence. */
|
|
58
35
|
interface AnimationFrameSource {
|
|
59
36
|
/** The node tree to render for this frame. */
|
|
@@ -70,21 +47,9 @@ interface AnimationSceneSource {
|
|
|
70
47
|
/** The duration of this scene in milliseconds. */
|
|
71
48
|
durationMs: number;
|
|
72
49
|
}
|
|
73
|
-
/** Options for constructing a Renderer instance. */
|
|
74
|
-
interface ConstructRendererOptions {
|
|
75
|
-
/** The images that needs to be preloaded into the renderer. */
|
|
76
|
-
persistentImages?: Array<ImageSource>;
|
|
77
|
-
/** The fonts being used. */
|
|
78
|
-
fonts?: Font[] | undefined;
|
|
79
|
-
/**
|
|
80
|
-
* Whether to load the default fonts.
|
|
81
|
-
* If `fonts` are provided, this will be `false` by default.
|
|
82
|
-
*/
|
|
83
|
-
loadDefaultFonts?: boolean;
|
|
84
|
-
}
|
|
85
50
|
type DitheringAlgorithm = 'none' | 'ordered-bayer' | 'floyd-steinberg';
|
|
86
51
|
/** Options for encoding a precomputed frame sequence. */
|
|
87
|
-
interface EncodeFramesOptions {
|
|
52
|
+
interface EncodeFramesOptions$1 {
|
|
88
53
|
/** Whether to draw debug borders around layout elements. */
|
|
89
54
|
drawDebugBorder?: boolean;
|
|
90
55
|
/** The width of each frame in pixels. */
|
|
@@ -93,10 +58,18 @@ interface EncodeFramesOptions {
|
|
|
93
58
|
height: number;
|
|
94
59
|
/** The output animation format (WebP, APNG, or GIF). */
|
|
95
60
|
format?: AnimationOutputFormat;
|
|
96
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* The quality of lossy WebP (0-100). Ignored for APNG and GIF, and when
|
|
63
|
+
* `lossless` is set.
|
|
64
|
+
*/
|
|
97
65
|
quality?: number;
|
|
98
|
-
/**
|
|
99
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Encode WebP losslessly. Defaults to lossless when neither `quality` nor
|
|
68
|
+
* `lossless` is given. Ignored for APNG and GIF.
|
|
69
|
+
*/
|
|
70
|
+
lossless?: boolean;
|
|
71
|
+
/** Images keyed by `src`, each carrying raw bytes. */
|
|
72
|
+
images?: Array<ImageSource>;
|
|
100
73
|
/** CSS stylesheets to apply before rendering. */
|
|
101
74
|
stylesheets?: Array<string>;
|
|
102
75
|
/**
|
|
@@ -104,13 +77,22 @@ interface EncodeFramesOptions {
|
|
|
104
77
|
* @default 1.0
|
|
105
78
|
*/
|
|
106
79
|
devicePixelRatio?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Per-render font stack: ordered family names used as the fallback chain.
|
|
82
|
+
* Defaults to all registered families in registration order.
|
|
83
|
+
*/
|
|
84
|
+
fontFamilies?: Array<string>;
|
|
107
85
|
}
|
|
86
|
+
/** Cache policy for a decoded image. Defaults to `"auto"`. */
|
|
87
|
+
type ImageCacheMode = /** Cache the decoded image for reuse (evictable). */'auto' | /** Skip the decoded-image cache. */'none';
|
|
108
88
|
/** An image source with its URL and raw data. */
|
|
109
89
|
interface ImageSource {
|
|
110
90
|
/** The source URL of the image. */
|
|
111
91
|
src: string;
|
|
112
92
|
/** The raw image data (Uint8Array or ArrayBuffer). */
|
|
113
93
|
data: Uint8Array | ArrayBuffer;
|
|
94
|
+
/** Cache policy for the decoded image. Defaults to `"auto"`. */
|
|
95
|
+
cache?: ImageCacheMode;
|
|
114
96
|
}
|
|
115
97
|
/** Represents a node that has been measured, including its layout information. */
|
|
116
98
|
interface MeasuredNode {
|
|
@@ -140,8 +122,26 @@ interface MeasuredTextRun {
|
|
|
140
122
|
}
|
|
141
123
|
/** Output format for static images. */
|
|
142
124
|
type OutputFormat = /** WebP format. */'webp' | /** PNG format. */'png' | /** JPEG format. */'jpeg' | /** ICO format. */'ico' | /** Raw pixels format. */'raw';
|
|
125
|
+
/** A single face within a `RegisteredFamily`. */
|
|
126
|
+
interface RegisteredFace {
|
|
127
|
+
/** Weight class, typically `1`–`1000`. */
|
|
128
|
+
weight: number;
|
|
129
|
+
/** CSS `font-style` value (`normal`, `italic`, or `oblique [<angle>deg]`). */
|
|
130
|
+
style: string;
|
|
131
|
+
/** Width as a percentage of normal (e.g. `100`). */
|
|
132
|
+
width: number;
|
|
133
|
+
/** Index of the face within its source collection. */
|
|
134
|
+
index: number;
|
|
135
|
+
}
|
|
136
|
+
/** A font family produced by `registerFont`, with the faces it contains. */
|
|
137
|
+
interface RegisteredFamily {
|
|
138
|
+
/** Family name as stored by the font system (normalized; reflects any override). */
|
|
139
|
+
name: string;
|
|
140
|
+
/** Faces registered under this family. */
|
|
141
|
+
faces: Array<RegisteredFace>;
|
|
142
|
+
}
|
|
143
143
|
/** Options for rendering a sequential scene animation. */
|
|
144
|
-
interface RenderAnimationOptions {
|
|
144
|
+
interface RenderAnimationOptions$1 {
|
|
145
145
|
/** The scenes to render sequentially. */
|
|
146
146
|
scenes: Array<AnimationSceneSource>;
|
|
147
147
|
/** Whether to draw debug borders around layout elements. */
|
|
@@ -152,12 +152,20 @@ interface RenderAnimationOptions {
|
|
|
152
152
|
height: number;
|
|
153
153
|
/** The output animation format (WebP, APNG, or GIF). */
|
|
154
154
|
format?: AnimationOutputFormat;
|
|
155
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* The quality of lossy WebP (0-100). Ignored for APNG and GIF, and when
|
|
157
|
+
* `lossless` is set.
|
|
158
|
+
*/
|
|
156
159
|
quality?: number;
|
|
160
|
+
/**
|
|
161
|
+
* Encode WebP losslessly. Defaults to lossless when neither `quality` nor
|
|
162
|
+
* `lossless` is given. Ignored for APNG and GIF.
|
|
163
|
+
*/
|
|
164
|
+
lossless?: boolean;
|
|
157
165
|
/** Frames per second for timeline sampling. */
|
|
158
166
|
fps: number;
|
|
159
|
-
/**
|
|
160
|
-
|
|
167
|
+
/** Images keyed by `src`, each carrying raw bytes. */
|
|
168
|
+
images?: Array<ImageSource>;
|
|
161
169
|
/** CSS stylesheets to apply before rendering. */
|
|
162
170
|
stylesheets?: Array<string>;
|
|
163
171
|
/**
|
|
@@ -165,21 +173,34 @@ interface RenderAnimationOptions {
|
|
|
165
173
|
* @default 1.0
|
|
166
174
|
*/
|
|
167
175
|
devicePixelRatio?: number;
|
|
176
|
+
/**
|
|
177
|
+
* Per-render font stack: ordered family names used as the fallback chain.
|
|
178
|
+
* Defaults to all registered families in registration order.
|
|
179
|
+
*/
|
|
180
|
+
fontFamilies?: Array<string>;
|
|
168
181
|
}
|
|
169
182
|
/** Options for rendering an image. */
|
|
170
|
-
interface RenderOptions {
|
|
183
|
+
interface RenderOptions$1 {
|
|
171
184
|
/** The width of the image. If not provided, the width will be automatically calculated based on the content. */
|
|
172
185
|
width?: number;
|
|
173
186
|
/** The height of the image. If not provided, the height will be automatically calculated based on the content. */
|
|
174
187
|
height?: number;
|
|
175
188
|
/** The format of the image. */
|
|
176
189
|
format?: OutputFormat;
|
|
177
|
-
/**
|
|
190
|
+
/**
|
|
191
|
+
* The quality of lossy formats (0-100). For JPEG; for WebP it selects lossy
|
|
192
|
+
* encoding unless `lossless` is set.
|
|
193
|
+
*/
|
|
178
194
|
quality?: number;
|
|
195
|
+
/**
|
|
196
|
+
* Encode WebP losslessly. Defaults to lossless when neither `quality` nor
|
|
197
|
+
* `lossless` is given.
|
|
198
|
+
*/
|
|
199
|
+
lossless?: boolean;
|
|
179
200
|
/** Whether to draw debug borders. */
|
|
180
201
|
drawDebugBorder?: boolean;
|
|
181
|
-
/**
|
|
182
|
-
|
|
202
|
+
/** Images keyed by `src`, each carrying raw bytes. */
|
|
203
|
+
images?: Array<ImageSource>;
|
|
183
204
|
/** CSS stylesheets to apply before rendering. */
|
|
184
205
|
stylesheets?: Array<string>;
|
|
185
206
|
/** Structured keyframes to register alongside stylesheets. */
|
|
@@ -193,36 +214,116 @@ interface RenderOptions {
|
|
|
193
214
|
timeMs?: number;
|
|
194
215
|
/** The output dithering algorithm. */
|
|
195
216
|
dithering?: DitheringAlgorithm;
|
|
217
|
+
/**
|
|
218
|
+
* Per-render font stack: ordered family names used as the fallback chain.
|
|
219
|
+
* Defaults to all registered families in registration order.
|
|
220
|
+
*/
|
|
221
|
+
fontFamilies?: Array<string>;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Options for rendering a node tree to an SVG document. SVG is a vector
|
|
225
|
+
* format, so the raster-only knobs (`format`, `quality`, `lossless`,
|
|
226
|
+
* `dithering`, `drawDebugBorder`, `devicePixelRatio`) do not apply.
|
|
227
|
+
*/
|
|
228
|
+
interface SvgRenderOptions$1 {
|
|
229
|
+
/** The width of the viewport. If not provided, it is derived from content. */
|
|
230
|
+
width?: number;
|
|
231
|
+
/** The height of the viewport. If not provided, it is derived from content. */
|
|
232
|
+
height?: number;
|
|
233
|
+
/** Images keyed by `src`, each carrying raw bytes. */
|
|
234
|
+
images?: Array<ImageSource>;
|
|
235
|
+
/** CSS stylesheets to apply before rendering. */
|
|
236
|
+
stylesheets?: Array<string>;
|
|
237
|
+
/** Structured keyframes to register alongside stylesheets. */
|
|
238
|
+
keyframes?: Keyframes;
|
|
239
|
+
/** The animation timeline time in milliseconds. */
|
|
240
|
+
timeMs?: number;
|
|
241
|
+
/**
|
|
242
|
+
* Per-render font stack: ordered family names used as the fallback chain.
|
|
243
|
+
* Defaults to all registered families in registration order.
|
|
244
|
+
*/
|
|
245
|
+
fontFamilies?: Array<string>;
|
|
196
246
|
}
|
|
197
247
|
//#endregion
|
|
198
248
|
//#region src/export.d.ts
|
|
199
|
-
type ImageSourceLoader = Omit<ImageSource, "data"> & {
|
|
200
|
-
data: ImageSource["data"] | (() => Promise<ImageSource["data"]> | ImageSource["data"]);
|
|
201
|
-
};
|
|
202
249
|
type FontLoader = Font | (Omit<FontDetails, "data"> & {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
250
|
+
data: () => Promise<FontDetails["data"]> | FontDetails["data"];
|
|
251
|
+
} & ({
|
|
252
|
+
key: string;
|
|
253
|
+
} | {
|
|
254
|
+
name: string;
|
|
255
|
+
}));
|
|
256
|
+
type ImageLoaderData = ImageSource["data"];
|
|
257
|
+
type ImageLoader = Omit<ImageSource, "data"> & {
|
|
258
|
+
data: ImageLoaderData | (() => ImageLoaderData | Promise<ImageLoaderData>);
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Output format. Format-specific options live on the variant that supports them,
|
|
262
|
+
* so `quality` cannot be paired with PNG/ICO/raw, and `lossless` is WebP-only.
|
|
263
|
+
* For WebP, `lossless` takes precedence over `quality`; omitting both encodes
|
|
264
|
+
* losslessly.
|
|
265
|
+
*/
|
|
266
|
+
type OutputFormatOptions = {
|
|
267
|
+
format?: "png";
|
|
268
|
+
} | {
|
|
269
|
+
format: "jpeg";
|
|
270
|
+
quality?: number;
|
|
271
|
+
} | {
|
|
272
|
+
format: "webp";
|
|
273
|
+
quality?: number;
|
|
274
|
+
lossless?: boolean;
|
|
275
|
+
} | {
|
|
276
|
+
format: "ico";
|
|
277
|
+
} | {
|
|
278
|
+
format: "raw";
|
|
279
|
+
};
|
|
280
|
+
type RenderOptions = Omit<RenderOptions$1, "images" | "format" | "quality" | "lossless"> & OutputFormatOptions & {
|
|
281
|
+
fonts?: FontLoader[];
|
|
282
|
+
signal?: AbortSignal;
|
|
283
|
+
images?: ImageLoader[];
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* Animation output format. `quality` and `lossless` are WebP-only; for WebP,
|
|
287
|
+
* `lossless` takes precedence over `quality`, and omitting both encodes
|
|
288
|
+
* losslessly.
|
|
289
|
+
*/
|
|
290
|
+
type AnimationOutputFormatOptions = {
|
|
291
|
+
format?: "webp";
|
|
292
|
+
quality?: number;
|
|
293
|
+
lossless?: boolean;
|
|
294
|
+
} | {
|
|
295
|
+
format: "apng";
|
|
296
|
+
} | {
|
|
297
|
+
format: "gif";
|
|
298
|
+
};
|
|
299
|
+
type RenderAnimationOptions = Omit<RenderAnimationOptions$1, "images" | "format" | "quality" | "lossless"> & AnimationOutputFormatOptions & {
|
|
300
|
+
fonts?: FontLoader[];
|
|
301
|
+
signal?: AbortSignal;
|
|
302
|
+
images?: ImageLoader[];
|
|
303
|
+
};
|
|
304
|
+
type EncodeFramesOptions = Omit<EncodeFramesOptions$1, "images" | "format" | "quality" | "lossless"> & AnimationOutputFormatOptions & {
|
|
305
|
+
fonts?: FontLoader[];
|
|
306
|
+
signal?: AbortSignal;
|
|
307
|
+
images?: ImageLoader[];
|
|
308
|
+
};
|
|
309
|
+
type SvgRenderOptions = Omit<SvgRenderOptions$1, "images"> & {
|
|
310
|
+
fonts?: FontLoader[];
|
|
311
|
+
signal?: AbortSignal;
|
|
312
|
+
images?: ImageLoader[];
|
|
208
313
|
};
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
private
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
clearImageStore(): void;
|
|
223
|
-
private checkAndMarkFont;
|
|
224
|
-
private isNewFont;
|
|
225
|
-
private isNewPersistentImage;
|
|
314
|
+
declare class Renderer {
|
|
315
|
+
private fontMapping;
|
|
316
|
+
private inner;
|
|
317
|
+
private prepareFonts;
|
|
318
|
+
/** Registers `fonts` and resolves lazy `images`, yielding the `images`/`fontFamilies`
|
|
319
|
+
* the napi binding expects. Explicit `fontFamilies` wins over the registered set. */
|
|
320
|
+
private resolveResources;
|
|
321
|
+
render(node: Node, options?: RenderOptions): Promise<Buffer>;
|
|
322
|
+
renderSvg(node: Node, options?: SvgRenderOptions): Promise<string>;
|
|
323
|
+
measure(node: Node, options?: RenderOptions): Promise<MeasuredNode>;
|
|
324
|
+
renderAnimation(options: RenderAnimationOptions): Promise<Buffer>;
|
|
325
|
+
encodeFrames(frames: AnimationFrameSource[], options: EncodeFramesOptions): Promise<Buffer>;
|
|
326
|
+
registerFont(font: FontLoader): Promise<any>;
|
|
226
327
|
}
|
|
227
328
|
//#endregion
|
|
228
|
-
export { type AnimationFrameSource, type AnimationOutputFormat, type AnimationSceneSource, type ByteBuf, type
|
|
329
|
+
export { type AnimationFrameSource, type AnimationOutputFormat, AnimationOutputFormatOptions, type AnimationSceneSource, type ByteBuf, type ContainerNode, type DitheringAlgorithm, EncodeFramesOptions, type Font, type FontDetails, FontLoader, type ImageCacheMode, ImageLoader, type ImageNode, type ImageSource, type Keyframes, type KeyframesMap, type KeyframesRuleList, type MeasuredNode, type MeasuredTextRun, type Node, type NodeMetadata, type OutputFormat, OutputFormatOptions, type RegisteredFace, type RegisteredFamily, RenderAnimationOptions, RenderOptions, Renderer, SvgRenderOptions, type TextNode, extractResourceUrls };
|
package/dist/export.d.mts
CHANGED
|
@@ -31,29 +31,6 @@ type KeyframesRuleList = {
|
|
|
31
31
|
}[];
|
|
32
32
|
}[];
|
|
33
33
|
type Keyframes = KeyframesMap | KeyframesRuleList;
|
|
34
|
-
/** The main renderer for Takumi image rendering engine (Node.js version). */
|
|
35
|
-
declare class Renderer$1 {
|
|
36
|
-
/** Creates a new Renderer instance. */
|
|
37
|
-
constructor(options?: ConstructRendererOptions | undefined | null);
|
|
38
|
-
/** Puts a persistent image into the renderer's internal store asynchronously. */
|
|
39
|
-
putPersistentImage(source: ImageSource, signal?: AbortSignal): Promise<void>;
|
|
40
|
-
/** Loads a font synchronously. */
|
|
41
|
-
loadFontSync(font: Font): void;
|
|
42
|
-
/** Loads a font into the renderer asynchronously. */
|
|
43
|
-
loadFont(data: Font, signal?: AbortSignal): Promise<number>;
|
|
44
|
-
/** Loads multiple fonts into the renderer asynchronously. */
|
|
45
|
-
loadFonts(fonts: Font[], signal?: AbortSignal): Promise<number>;
|
|
46
|
-
/** Clears the renderer's internal image store. */
|
|
47
|
-
clearImageStore(): void;
|
|
48
|
-
/** Renders a node tree into an image buffer asynchronously. */
|
|
49
|
-
render(source: Node, options?: RenderOptions, signal?: AbortSignal): Promise<Buffer>;
|
|
50
|
-
/** Measures a node tree and returns layout information asynchronously. */
|
|
51
|
-
measure(source: Node, options?: RenderOptions, signal?: AbortSignal): Promise<MeasuredNode>;
|
|
52
|
-
/** Renders a sequential scene animation into a buffer asynchronously. */
|
|
53
|
-
renderAnimation(options: RenderAnimationOptions, signal?: AbortSignal): Promise<Buffer>;
|
|
54
|
-
/** Encodes a precomputed frame sequence into an animated image buffer asynchronously. */
|
|
55
|
-
encodeFrames(source: AnimationFrameSource[], options: EncodeFramesOptions, signal?: AbortSignal): Promise<Buffer>;
|
|
56
|
-
}
|
|
57
34
|
/** Represents a single frame in a precomputed animation sequence. */
|
|
58
35
|
interface AnimationFrameSource {
|
|
59
36
|
/** The node tree to render for this frame. */
|
|
@@ -70,21 +47,9 @@ interface AnimationSceneSource {
|
|
|
70
47
|
/** The duration of this scene in milliseconds. */
|
|
71
48
|
durationMs: number;
|
|
72
49
|
}
|
|
73
|
-
/** Options for constructing a Renderer instance. */
|
|
74
|
-
interface ConstructRendererOptions {
|
|
75
|
-
/** The images that needs to be preloaded into the renderer. */
|
|
76
|
-
persistentImages?: Array<ImageSource>;
|
|
77
|
-
/** The fonts being used. */
|
|
78
|
-
fonts?: Font[] | undefined;
|
|
79
|
-
/**
|
|
80
|
-
* Whether to load the default fonts.
|
|
81
|
-
* If `fonts` are provided, this will be `false` by default.
|
|
82
|
-
*/
|
|
83
|
-
loadDefaultFonts?: boolean;
|
|
84
|
-
}
|
|
85
50
|
type DitheringAlgorithm = 'none' | 'ordered-bayer' | 'floyd-steinberg';
|
|
86
51
|
/** Options for encoding a precomputed frame sequence. */
|
|
87
|
-
interface EncodeFramesOptions {
|
|
52
|
+
interface EncodeFramesOptions$1 {
|
|
88
53
|
/** Whether to draw debug borders around layout elements. */
|
|
89
54
|
drawDebugBorder?: boolean;
|
|
90
55
|
/** The width of each frame in pixels. */
|
|
@@ -93,10 +58,18 @@ interface EncodeFramesOptions {
|
|
|
93
58
|
height: number;
|
|
94
59
|
/** The output animation format (WebP, APNG, or GIF). */
|
|
95
60
|
format?: AnimationOutputFormat;
|
|
96
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* The quality of lossy WebP (0-100). Ignored for APNG and GIF, and when
|
|
63
|
+
* `lossless` is set.
|
|
64
|
+
*/
|
|
97
65
|
quality?: number;
|
|
98
|
-
/**
|
|
99
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Encode WebP losslessly. Defaults to lossless when neither `quality` nor
|
|
68
|
+
* `lossless` is given. Ignored for APNG and GIF.
|
|
69
|
+
*/
|
|
70
|
+
lossless?: boolean;
|
|
71
|
+
/** Images keyed by `src`, each carrying raw bytes. */
|
|
72
|
+
images?: Array<ImageSource>;
|
|
100
73
|
/** CSS stylesheets to apply before rendering. */
|
|
101
74
|
stylesheets?: Array<string>;
|
|
102
75
|
/**
|
|
@@ -104,13 +77,22 @@ interface EncodeFramesOptions {
|
|
|
104
77
|
* @default 1.0
|
|
105
78
|
*/
|
|
106
79
|
devicePixelRatio?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Per-render font stack: ordered family names used as the fallback chain.
|
|
82
|
+
* Defaults to all registered families in registration order.
|
|
83
|
+
*/
|
|
84
|
+
fontFamilies?: Array<string>;
|
|
107
85
|
}
|
|
86
|
+
/** Cache policy for a decoded image. Defaults to `"auto"`. */
|
|
87
|
+
type ImageCacheMode = /** Cache the decoded image for reuse (evictable). */'auto' | /** Skip the decoded-image cache. */'none';
|
|
108
88
|
/** An image source with its URL and raw data. */
|
|
109
89
|
interface ImageSource {
|
|
110
90
|
/** The source URL of the image. */
|
|
111
91
|
src: string;
|
|
112
92
|
/** The raw image data (Uint8Array or ArrayBuffer). */
|
|
113
93
|
data: Uint8Array | ArrayBuffer;
|
|
94
|
+
/** Cache policy for the decoded image. Defaults to `"auto"`. */
|
|
95
|
+
cache?: ImageCacheMode;
|
|
114
96
|
}
|
|
115
97
|
/** Represents a node that has been measured, including its layout information. */
|
|
116
98
|
interface MeasuredNode {
|
|
@@ -140,8 +122,26 @@ interface MeasuredTextRun {
|
|
|
140
122
|
}
|
|
141
123
|
/** Output format for static images. */
|
|
142
124
|
type OutputFormat = /** WebP format. */'webp' | /** PNG format. */'png' | /** JPEG format. */'jpeg' | /** ICO format. */'ico' | /** Raw pixels format. */'raw';
|
|
125
|
+
/** A single face within a `RegisteredFamily`. */
|
|
126
|
+
interface RegisteredFace {
|
|
127
|
+
/** Weight class, typically `1`–`1000`. */
|
|
128
|
+
weight: number;
|
|
129
|
+
/** CSS `font-style` value (`normal`, `italic`, or `oblique [<angle>deg]`). */
|
|
130
|
+
style: string;
|
|
131
|
+
/** Width as a percentage of normal (e.g. `100`). */
|
|
132
|
+
width: number;
|
|
133
|
+
/** Index of the face within its source collection. */
|
|
134
|
+
index: number;
|
|
135
|
+
}
|
|
136
|
+
/** A font family produced by `registerFont`, with the faces it contains. */
|
|
137
|
+
interface RegisteredFamily {
|
|
138
|
+
/** Family name as stored by the font system (normalized; reflects any override). */
|
|
139
|
+
name: string;
|
|
140
|
+
/** Faces registered under this family. */
|
|
141
|
+
faces: Array<RegisteredFace>;
|
|
142
|
+
}
|
|
143
143
|
/** Options for rendering a sequential scene animation. */
|
|
144
|
-
interface RenderAnimationOptions {
|
|
144
|
+
interface RenderAnimationOptions$1 {
|
|
145
145
|
/** The scenes to render sequentially. */
|
|
146
146
|
scenes: Array<AnimationSceneSource>;
|
|
147
147
|
/** Whether to draw debug borders around layout elements. */
|
|
@@ -152,12 +152,20 @@ interface RenderAnimationOptions {
|
|
|
152
152
|
height: number;
|
|
153
153
|
/** The output animation format (WebP, APNG, or GIF). */
|
|
154
154
|
format?: AnimationOutputFormat;
|
|
155
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* The quality of lossy WebP (0-100). Ignored for APNG and GIF, and when
|
|
157
|
+
* `lossless` is set.
|
|
158
|
+
*/
|
|
156
159
|
quality?: number;
|
|
160
|
+
/**
|
|
161
|
+
* Encode WebP losslessly. Defaults to lossless when neither `quality` nor
|
|
162
|
+
* `lossless` is given. Ignored for APNG and GIF.
|
|
163
|
+
*/
|
|
164
|
+
lossless?: boolean;
|
|
157
165
|
/** Frames per second for timeline sampling. */
|
|
158
166
|
fps: number;
|
|
159
|
-
/**
|
|
160
|
-
|
|
167
|
+
/** Images keyed by `src`, each carrying raw bytes. */
|
|
168
|
+
images?: Array<ImageSource>;
|
|
161
169
|
/** CSS stylesheets to apply before rendering. */
|
|
162
170
|
stylesheets?: Array<string>;
|
|
163
171
|
/**
|
|
@@ -165,21 +173,34 @@ interface RenderAnimationOptions {
|
|
|
165
173
|
* @default 1.0
|
|
166
174
|
*/
|
|
167
175
|
devicePixelRatio?: number;
|
|
176
|
+
/**
|
|
177
|
+
* Per-render font stack: ordered family names used as the fallback chain.
|
|
178
|
+
* Defaults to all registered families in registration order.
|
|
179
|
+
*/
|
|
180
|
+
fontFamilies?: Array<string>;
|
|
168
181
|
}
|
|
169
182
|
/** Options for rendering an image. */
|
|
170
|
-
interface RenderOptions {
|
|
183
|
+
interface RenderOptions$1 {
|
|
171
184
|
/** The width of the image. If not provided, the width will be automatically calculated based on the content. */
|
|
172
185
|
width?: number;
|
|
173
186
|
/** The height of the image. If not provided, the height will be automatically calculated based on the content. */
|
|
174
187
|
height?: number;
|
|
175
188
|
/** The format of the image. */
|
|
176
189
|
format?: OutputFormat;
|
|
177
|
-
/**
|
|
190
|
+
/**
|
|
191
|
+
* The quality of lossy formats (0-100). For JPEG; for WebP it selects lossy
|
|
192
|
+
* encoding unless `lossless` is set.
|
|
193
|
+
*/
|
|
178
194
|
quality?: number;
|
|
195
|
+
/**
|
|
196
|
+
* Encode WebP losslessly. Defaults to lossless when neither `quality` nor
|
|
197
|
+
* `lossless` is given.
|
|
198
|
+
*/
|
|
199
|
+
lossless?: boolean;
|
|
179
200
|
/** Whether to draw debug borders. */
|
|
180
201
|
drawDebugBorder?: boolean;
|
|
181
|
-
/**
|
|
182
|
-
|
|
202
|
+
/** Images keyed by `src`, each carrying raw bytes. */
|
|
203
|
+
images?: Array<ImageSource>;
|
|
183
204
|
/** CSS stylesheets to apply before rendering. */
|
|
184
205
|
stylesheets?: Array<string>;
|
|
185
206
|
/** Structured keyframes to register alongside stylesheets. */
|
|
@@ -193,36 +214,116 @@ interface RenderOptions {
|
|
|
193
214
|
timeMs?: number;
|
|
194
215
|
/** The output dithering algorithm. */
|
|
195
216
|
dithering?: DitheringAlgorithm;
|
|
217
|
+
/**
|
|
218
|
+
* Per-render font stack: ordered family names used as the fallback chain.
|
|
219
|
+
* Defaults to all registered families in registration order.
|
|
220
|
+
*/
|
|
221
|
+
fontFamilies?: Array<string>;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Options for rendering a node tree to an SVG document. SVG is a vector
|
|
225
|
+
* format, so the raster-only knobs (`format`, `quality`, `lossless`,
|
|
226
|
+
* `dithering`, `drawDebugBorder`, `devicePixelRatio`) do not apply.
|
|
227
|
+
*/
|
|
228
|
+
interface SvgRenderOptions$1 {
|
|
229
|
+
/** The width of the viewport. If not provided, it is derived from content. */
|
|
230
|
+
width?: number;
|
|
231
|
+
/** The height of the viewport. If not provided, it is derived from content. */
|
|
232
|
+
height?: number;
|
|
233
|
+
/** Images keyed by `src`, each carrying raw bytes. */
|
|
234
|
+
images?: Array<ImageSource>;
|
|
235
|
+
/** CSS stylesheets to apply before rendering. */
|
|
236
|
+
stylesheets?: Array<string>;
|
|
237
|
+
/** Structured keyframes to register alongside stylesheets. */
|
|
238
|
+
keyframes?: Keyframes;
|
|
239
|
+
/** The animation timeline time in milliseconds. */
|
|
240
|
+
timeMs?: number;
|
|
241
|
+
/**
|
|
242
|
+
* Per-render font stack: ordered family names used as the fallback chain.
|
|
243
|
+
* Defaults to all registered families in registration order.
|
|
244
|
+
*/
|
|
245
|
+
fontFamilies?: Array<string>;
|
|
196
246
|
}
|
|
197
247
|
//#endregion
|
|
198
248
|
//#region src/export.d.ts
|
|
199
|
-
type ImageSourceLoader = Omit<ImageSource, "data"> & {
|
|
200
|
-
data: ImageSource["data"] | (() => Promise<ImageSource["data"]> | ImageSource["data"]);
|
|
201
|
-
};
|
|
202
249
|
type FontLoader = Font | (Omit<FontDetails, "data"> & {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
250
|
+
data: () => Promise<FontDetails["data"]> | FontDetails["data"];
|
|
251
|
+
} & ({
|
|
252
|
+
key: string;
|
|
253
|
+
} | {
|
|
254
|
+
name: string;
|
|
255
|
+
}));
|
|
256
|
+
type ImageLoaderData = ImageSource["data"];
|
|
257
|
+
type ImageLoader = Omit<ImageSource, "data"> & {
|
|
258
|
+
data: ImageLoaderData | (() => ImageLoaderData | Promise<ImageLoaderData>);
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Output format. Format-specific options live on the variant that supports them,
|
|
262
|
+
* so `quality` cannot be paired with PNG/ICO/raw, and `lossless` is WebP-only.
|
|
263
|
+
* For WebP, `lossless` takes precedence over `quality`; omitting both encodes
|
|
264
|
+
* losslessly.
|
|
265
|
+
*/
|
|
266
|
+
type OutputFormatOptions = {
|
|
267
|
+
format?: "png";
|
|
268
|
+
} | {
|
|
269
|
+
format: "jpeg";
|
|
270
|
+
quality?: number;
|
|
271
|
+
} | {
|
|
272
|
+
format: "webp";
|
|
273
|
+
quality?: number;
|
|
274
|
+
lossless?: boolean;
|
|
275
|
+
} | {
|
|
276
|
+
format: "ico";
|
|
277
|
+
} | {
|
|
278
|
+
format: "raw";
|
|
279
|
+
};
|
|
280
|
+
type RenderOptions = Omit<RenderOptions$1, "images" | "format" | "quality" | "lossless"> & OutputFormatOptions & {
|
|
281
|
+
fonts?: FontLoader[];
|
|
282
|
+
signal?: AbortSignal;
|
|
283
|
+
images?: ImageLoader[];
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* Animation output format. `quality` and `lossless` are WebP-only; for WebP,
|
|
287
|
+
* `lossless` takes precedence over `quality`, and omitting both encodes
|
|
288
|
+
* losslessly.
|
|
289
|
+
*/
|
|
290
|
+
type AnimationOutputFormatOptions = {
|
|
291
|
+
format?: "webp";
|
|
292
|
+
quality?: number;
|
|
293
|
+
lossless?: boolean;
|
|
294
|
+
} | {
|
|
295
|
+
format: "apng";
|
|
296
|
+
} | {
|
|
297
|
+
format: "gif";
|
|
298
|
+
};
|
|
299
|
+
type RenderAnimationOptions = Omit<RenderAnimationOptions$1, "images" | "format" | "quality" | "lossless"> & AnimationOutputFormatOptions & {
|
|
300
|
+
fonts?: FontLoader[];
|
|
301
|
+
signal?: AbortSignal;
|
|
302
|
+
images?: ImageLoader[];
|
|
303
|
+
};
|
|
304
|
+
type EncodeFramesOptions = Omit<EncodeFramesOptions$1, "images" | "format" | "quality" | "lossless"> & AnimationOutputFormatOptions & {
|
|
305
|
+
fonts?: FontLoader[];
|
|
306
|
+
signal?: AbortSignal;
|
|
307
|
+
images?: ImageLoader[];
|
|
308
|
+
};
|
|
309
|
+
type SvgRenderOptions = Omit<SvgRenderOptions$1, "images"> & {
|
|
310
|
+
fonts?: FontLoader[];
|
|
311
|
+
signal?: AbortSignal;
|
|
312
|
+
images?: ImageLoader[];
|
|
208
313
|
};
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
private
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
clearImageStore(): void;
|
|
223
|
-
private checkAndMarkFont;
|
|
224
|
-
private isNewFont;
|
|
225
|
-
private isNewPersistentImage;
|
|
314
|
+
declare class Renderer {
|
|
315
|
+
private fontMapping;
|
|
316
|
+
private inner;
|
|
317
|
+
private prepareFonts;
|
|
318
|
+
/** Registers `fonts` and resolves lazy `images`, yielding the `images`/`fontFamilies`
|
|
319
|
+
* the napi binding expects. Explicit `fontFamilies` wins over the registered set. */
|
|
320
|
+
private resolveResources;
|
|
321
|
+
render(node: Node, options?: RenderOptions): Promise<Buffer>;
|
|
322
|
+
renderSvg(node: Node, options?: SvgRenderOptions): Promise<string>;
|
|
323
|
+
measure(node: Node, options?: RenderOptions): Promise<MeasuredNode>;
|
|
324
|
+
renderAnimation(options: RenderAnimationOptions): Promise<Buffer>;
|
|
325
|
+
encodeFrames(frames: AnimationFrameSource[], options: EncodeFramesOptions): Promise<Buffer>;
|
|
326
|
+
registerFont(font: FontLoader): Promise<any>;
|
|
226
327
|
}
|
|
227
328
|
//#endregion
|
|
228
|
-
export { type AnimationFrameSource, type AnimationOutputFormat, type AnimationSceneSource, type ByteBuf, type
|
|
329
|
+
export { type AnimationFrameSource, type AnimationOutputFormat, AnimationOutputFormatOptions, type AnimationSceneSource, type ByteBuf, type ContainerNode, type DitheringAlgorithm, EncodeFramesOptions, type Font, type FontDetails, FontLoader, type ImageCacheMode, ImageLoader, type ImageNode, type ImageSource, type Keyframes, type KeyframesMap, type KeyframesRuleList, type MeasuredNode, type MeasuredTextRun, type Node, type NodeMetadata, type OutputFormat, OutputFormatOptions, type RegisteredFace, type RegisteredFamily, RenderAnimationOptions, RenderOptions, Renderer, SvgRenderOptions, type TextNode, extractResourceUrls };
|