@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/index.d.ts
CHANGED
|
@@ -24,6 +24,12 @@ export interface FontDetails {
|
|
|
24
24
|
* The style of the font. If not provided, the style in the font file will be used.
|
|
25
25
|
*/
|
|
26
26
|
style?: "normal" | "italic" | "oblique" | `oblique ${number}deg` | (string & {});
|
|
27
|
+
/**
|
|
28
|
+
* Logical family this font is a coverage subset of. Subsets sharing a `subsetOf` are
|
|
29
|
+
* kept as distinct families and `font-family: {subsetOf}` expands to all of them, so each
|
|
30
|
+
* script routes to the subset that covers it. Set by {@link loadGoogleFonts}.
|
|
31
|
+
*/
|
|
32
|
+
subsetOf?: string;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
export type Font = FontDetails | ByteBuf;
|
|
@@ -40,19 +46,13 @@ export type Keyframes = KeyframesMap | KeyframesRuleList;
|
|
|
40
46
|
/** The main renderer for Takumi image rendering engine (Node.js version). */
|
|
41
47
|
export declare class Renderer {
|
|
42
48
|
/** Creates a new Renderer instance. */
|
|
43
|
-
constructor(
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
/** Loads a font synchronously. */
|
|
47
|
-
loadFontSync(font: Font): void
|
|
48
|
-
/** Loads a font into the renderer asynchronously. */
|
|
49
|
-
loadFont(data: Font, signal?: AbortSignal): Promise<number>
|
|
50
|
-
/** Loads multiple fonts into the renderer asynchronously. */
|
|
51
|
-
loadFonts(fonts: Font[], signal?: AbortSignal): Promise<number>
|
|
52
|
-
/** Clears the renderer's internal image store. */
|
|
53
|
-
clearImageStore(): void
|
|
49
|
+
constructor()
|
|
50
|
+
/** Register font into the renderer, returning the families produced. */
|
|
51
|
+
registerFont(fonts: Font, signal?: AbortSignal): Promise<RegisteredFamily[]>
|
|
54
52
|
/** Renders a node tree into an image buffer asynchronously. */
|
|
55
53
|
render(source: Node, options?: RenderOptions, signal?: AbortSignal): Promise<Buffer>
|
|
54
|
+
/** Renders a node tree into an SVG document string asynchronously. */
|
|
55
|
+
renderSvg(source: Node, options?: SvgRenderOptions, signal?: AbortSignal): Promise<string>
|
|
56
56
|
/** Measures a node tree and returns layout information asynchronously. */
|
|
57
57
|
measure(source: Node, options?: RenderOptions, signal?: AbortSignal): Promise<MeasuredNode>
|
|
58
58
|
/** Renders a sequential scene animation into a buffer asynchronously. */
|
|
@@ -85,19 +85,6 @@ export interface AnimationSceneSource {
|
|
|
85
85
|
durationMs: number
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
/** Options for constructing a Renderer instance. */
|
|
89
|
-
export interface ConstructRendererOptions {
|
|
90
|
-
/** The images that needs to be preloaded into the renderer. */
|
|
91
|
-
persistentImages?: Array<ImageSource>
|
|
92
|
-
/** The fonts being used. */
|
|
93
|
-
fonts?: Font[] | undefined
|
|
94
|
-
/**
|
|
95
|
-
* Whether to load the default fonts.
|
|
96
|
-
* If `fonts` are provided, this will be `false` by default.
|
|
97
|
-
*/
|
|
98
|
-
loadDefaultFonts?: boolean
|
|
99
|
-
}
|
|
100
|
-
|
|
101
88
|
export type DitheringAlgorithm = 'none'|
|
|
102
89
|
'ordered-bayer'|
|
|
103
90
|
'floyd-steinberg';
|
|
@@ -112,10 +99,18 @@ export interface EncodeFramesOptions {
|
|
|
112
99
|
height: number
|
|
113
100
|
/** The output animation format (WebP, APNG, or GIF). */
|
|
114
101
|
format?: AnimationOutputFormat
|
|
115
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* The quality of lossy WebP (0-100). Ignored for APNG and GIF, and when
|
|
104
|
+
* `lossless` is set.
|
|
105
|
+
*/
|
|
116
106
|
quality?: number
|
|
117
|
-
/**
|
|
118
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Encode WebP losslessly. Defaults to lossless when neither `quality` nor
|
|
109
|
+
* `lossless` is given. Ignored for APNG and GIF.
|
|
110
|
+
*/
|
|
111
|
+
lossless?: boolean
|
|
112
|
+
/** Images keyed by `src`, each carrying raw bytes. */
|
|
113
|
+
images?: Array<ImageSource>
|
|
119
114
|
/** CSS stylesheets to apply before rendering. */
|
|
120
115
|
stylesheets?: Array<string>
|
|
121
116
|
/**
|
|
@@ -123,14 +118,27 @@ export interface EncodeFramesOptions {
|
|
|
123
118
|
* @default 1.0
|
|
124
119
|
*/
|
|
125
120
|
devicePixelRatio?: number
|
|
121
|
+
/**
|
|
122
|
+
* Per-render font stack: ordered family names used as the fallback chain.
|
|
123
|
+
* Defaults to all registered families in registration order.
|
|
124
|
+
*/
|
|
125
|
+
fontFamilies?: Array<string>
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
/** Cache policy for a decoded image. Defaults to `"auto"`. */
|
|
129
|
+
export type ImageCacheMode = /** Cache the decoded image for reuse (evictable). */
|
|
130
|
+
'auto'|
|
|
131
|
+
/** Skip the decoded-image cache. */
|
|
132
|
+
'none';
|
|
133
|
+
|
|
128
134
|
/** An image source with its URL and raw data. */
|
|
129
135
|
export interface ImageSource {
|
|
130
136
|
/** The source URL of the image. */
|
|
131
137
|
src: string
|
|
132
138
|
/** The raw image data (Uint8Array or ArrayBuffer). */
|
|
133
139
|
data: Uint8Array | ArrayBuffer
|
|
140
|
+
/** Cache policy for the decoded image. Defaults to `"auto"`. */
|
|
141
|
+
cache?: ImageCacheMode
|
|
134
142
|
}
|
|
135
143
|
|
|
136
144
|
/** Represents a node that has been measured, including its layout information. */
|
|
@@ -173,6 +181,26 @@ export type OutputFormat = /** WebP format. */
|
|
|
173
181
|
/** Raw pixels format. */
|
|
174
182
|
'raw';
|
|
175
183
|
|
|
184
|
+
/** A single face within a `RegisteredFamily`. */
|
|
185
|
+
export interface RegisteredFace {
|
|
186
|
+
/** Weight class, typically `1`–`1000`. */
|
|
187
|
+
weight: number
|
|
188
|
+
/** CSS `font-style` value (`normal`, `italic`, or `oblique [<angle>deg]`). */
|
|
189
|
+
style: string
|
|
190
|
+
/** Width as a percentage of normal (e.g. `100`). */
|
|
191
|
+
width: number
|
|
192
|
+
/** Index of the face within its source collection. */
|
|
193
|
+
index: number
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** A font family produced by `registerFont`, with the faces it contains. */
|
|
197
|
+
export interface RegisteredFamily {
|
|
198
|
+
/** Family name as stored by the font system (normalized; reflects any override). */
|
|
199
|
+
name: string
|
|
200
|
+
/** Faces registered under this family. */
|
|
201
|
+
faces: Array<RegisteredFace>
|
|
202
|
+
}
|
|
203
|
+
|
|
176
204
|
/** Options for rendering a sequential scene animation. */
|
|
177
205
|
export interface RenderAnimationOptions {
|
|
178
206
|
/** The scenes to render sequentially. */
|
|
@@ -185,12 +213,20 @@ export interface RenderAnimationOptions {
|
|
|
185
213
|
height: number
|
|
186
214
|
/** The output animation format (WebP, APNG, or GIF). */
|
|
187
215
|
format?: AnimationOutputFormat
|
|
188
|
-
/**
|
|
216
|
+
/**
|
|
217
|
+
* The quality of lossy WebP (0-100). Ignored for APNG and GIF, and when
|
|
218
|
+
* `lossless` is set.
|
|
219
|
+
*/
|
|
189
220
|
quality?: number
|
|
221
|
+
/**
|
|
222
|
+
* Encode WebP losslessly. Defaults to lossless when neither `quality` nor
|
|
223
|
+
* `lossless` is given. Ignored for APNG and GIF.
|
|
224
|
+
*/
|
|
225
|
+
lossless?: boolean
|
|
190
226
|
/** Frames per second for timeline sampling. */
|
|
191
227
|
fps: number
|
|
192
|
-
/**
|
|
193
|
-
|
|
228
|
+
/** Images keyed by `src`, each carrying raw bytes. */
|
|
229
|
+
images?: Array<ImageSource>
|
|
194
230
|
/** CSS stylesheets to apply before rendering. */
|
|
195
231
|
stylesheets?: Array<string>
|
|
196
232
|
/**
|
|
@@ -198,6 +234,11 @@ export interface RenderAnimationOptions {
|
|
|
198
234
|
* @default 1.0
|
|
199
235
|
*/
|
|
200
236
|
devicePixelRatio?: number
|
|
237
|
+
/**
|
|
238
|
+
* Per-render font stack: ordered family names used as the fallback chain.
|
|
239
|
+
* Defaults to all registered families in registration order.
|
|
240
|
+
*/
|
|
241
|
+
fontFamilies?: Array<string>
|
|
201
242
|
}
|
|
202
243
|
|
|
203
244
|
/** Options for rendering an image. */
|
|
@@ -208,12 +249,20 @@ export interface RenderOptions {
|
|
|
208
249
|
height?: number
|
|
209
250
|
/** The format of the image. */
|
|
210
251
|
format?: OutputFormat
|
|
211
|
-
/**
|
|
252
|
+
/**
|
|
253
|
+
* The quality of lossy formats (0-100). For JPEG; for WebP it selects lossy
|
|
254
|
+
* encoding unless `lossless` is set.
|
|
255
|
+
*/
|
|
212
256
|
quality?: number
|
|
257
|
+
/**
|
|
258
|
+
* Encode WebP losslessly. Defaults to lossless when neither `quality` nor
|
|
259
|
+
* `lossless` is given.
|
|
260
|
+
*/
|
|
261
|
+
lossless?: boolean
|
|
213
262
|
/** Whether to draw debug borders. */
|
|
214
263
|
drawDebugBorder?: boolean
|
|
215
|
-
/**
|
|
216
|
-
|
|
264
|
+
/** Images keyed by `src`, each carrying raw bytes. */
|
|
265
|
+
images?: Array<ImageSource>
|
|
217
266
|
/** CSS stylesheets to apply before rendering. */
|
|
218
267
|
stylesheets?: Array<string>
|
|
219
268
|
/** Structured keyframes to register alongside stylesheets. */
|
|
@@ -227,4 +276,34 @@ export interface RenderOptions {
|
|
|
227
276
|
timeMs?: number
|
|
228
277
|
/** The output dithering algorithm. */
|
|
229
278
|
dithering?: DitheringAlgorithm
|
|
279
|
+
/**
|
|
280
|
+
* Per-render font stack: ordered family names used as the fallback chain.
|
|
281
|
+
* Defaults to all registered families in registration order.
|
|
282
|
+
*/
|
|
283
|
+
fontFamilies?: Array<string>
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Options for rendering a node tree to an SVG document. SVG is a vector
|
|
288
|
+
* format, so the raster-only knobs (`format`, `quality`, `lossless`,
|
|
289
|
+
* `dithering`, `drawDebugBorder`, `devicePixelRatio`) do not apply.
|
|
290
|
+
*/
|
|
291
|
+
export interface SvgRenderOptions {
|
|
292
|
+
/** The width of the viewport. If not provided, it is derived from content. */
|
|
293
|
+
width?: number
|
|
294
|
+
/** The height of the viewport. If not provided, it is derived from content. */
|
|
295
|
+
height?: number
|
|
296
|
+
/** Images keyed by `src`, each carrying raw bytes. */
|
|
297
|
+
images?: Array<ImageSource>
|
|
298
|
+
/** CSS stylesheets to apply before rendering. */
|
|
299
|
+
stylesheets?: Array<string>
|
|
300
|
+
/** Structured keyframes to register alongside stylesheets. */
|
|
301
|
+
keyframes?: Keyframes
|
|
302
|
+
/** The animation timeline time in milliseconds. */
|
|
303
|
+
timeMs?: number
|
|
304
|
+
/**
|
|
305
|
+
* Per-render font stack: ordered family names used as the fallback chain.
|
|
306
|
+
* Defaults to all registered families in registration order.
|
|
307
|
+
*/
|
|
308
|
+
fontFamilies?: Array<string>
|
|
230
309
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takumi-rs/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
4
|
"description": "Native Node.js bindings for the Takumi Rust image rendering engine.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
|
27
27
|
"url": "git+https://github.com/kane50613/takumi.git",
|
|
28
|
-
"directory": "takumi-napi
|
|
28
|
+
"directory": "takumi-napi"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
31
|
"dist",
|
|
@@ -70,10 +70,10 @@
|
|
|
70
70
|
"publish-lint": "attw --pack . && publint --strict ."
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@takumi-rs/helpers": "
|
|
73
|
+
"@takumi-rs/helpers": "2.0.0-beta.1"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"@napi-rs/cli": "3.7.
|
|
76
|
+
"@napi-rs/cli": "3.7.2",
|
|
77
77
|
"@types/bun": "catalog:",
|
|
78
78
|
"@types/react": "catalog:",
|
|
79
79
|
"@types/react-dom": "catalog:",
|
|
@@ -103,13 +103,13 @@
|
|
|
103
103
|
"node": ">= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0 < 16 || >= 16.0.0"
|
|
104
104
|
},
|
|
105
105
|
"optionalDependencies": {
|
|
106
|
-
"@takumi-rs/core-darwin-x64": "
|
|
107
|
-
"@takumi-rs/core-darwin-arm64": "
|
|
108
|
-
"@takumi-rs/core-linux-arm64-gnu": "
|
|
109
|
-
"@takumi-rs/core-linux-arm64-musl": "
|
|
110
|
-
"@takumi-rs/core-win32-arm64-msvc": "
|
|
111
|
-
"@takumi-rs/core-linux-x64-gnu": "
|
|
112
|
-
"@takumi-rs/core-linux-x64-musl": "
|
|
113
|
-
"@takumi-rs/core-win32-x64-msvc": "
|
|
106
|
+
"@takumi-rs/core-darwin-x64": "2.0.0-beta.1",
|
|
107
|
+
"@takumi-rs/core-darwin-arm64": "2.0.0-beta.1",
|
|
108
|
+
"@takumi-rs/core-linux-arm64-gnu": "2.0.0-beta.1",
|
|
109
|
+
"@takumi-rs/core-linux-arm64-musl": "2.0.0-beta.1",
|
|
110
|
+
"@takumi-rs/core-win32-arm64-msvc": "2.0.0-beta.1",
|
|
111
|
+
"@takumi-rs/core-linux-x64-gnu": "2.0.0-beta.1",
|
|
112
|
+
"@takumi-rs/core-linux-x64-musl": "2.0.0-beta.1",
|
|
113
|
+
"@takumi-rs/core-win32-x64-msvc": "2.0.0-beta.1"
|
|
114
114
|
}
|
|
115
115
|
}
|