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