@takumi-rs/core 1.8.6 → 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 +329 -0
- package/dist/export.d.mts +329 -0
- package/dist/export.mjs +152 -153
- package/index.d.ts +106 -33
- package/package.json +32 -22
- package/dist/export.d.ts +0 -32
package/index.d.ts
CHANGED
|
@@ -40,19 +40,13 @@ export type Keyframes = KeyframesMap | KeyframesRuleList;
|
|
|
40
40
|
/** The main renderer for Takumi image rendering engine (Node.js version). */
|
|
41
41
|
export declare class Renderer {
|
|
42
42
|
/** 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
|
|
43
|
+
constructor()
|
|
44
|
+
/** Register font into the renderer, returning the families produced. */
|
|
45
|
+
registerFont(fonts: Font, signal?: AbortSignal): Promise<RegisteredFamily[]>
|
|
54
46
|
/** Renders a node tree into an image buffer asynchronously. */
|
|
55
47
|
render(source: Node, options?: RenderOptions, signal?: AbortSignal): Promise<Buffer>
|
|
48
|
+
/** Renders a node tree into an SVG document string asynchronously. */
|
|
49
|
+
renderSvg(source: Node, options?: SvgRenderOptions, signal?: AbortSignal): Promise<string>
|
|
56
50
|
/** Measures a node tree and returns layout information asynchronously. */
|
|
57
51
|
measure(source: Node, options?: RenderOptions, signal?: AbortSignal): Promise<MeasuredNode>
|
|
58
52
|
/** Renders a sequential scene animation into a buffer asynchronously. */
|
|
@@ -85,19 +79,6 @@ export interface AnimationSceneSource {
|
|
|
85
79
|
durationMs: number
|
|
86
80
|
}
|
|
87
81
|
|
|
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
82
|
export type DitheringAlgorithm = 'none'|
|
|
102
83
|
'ordered-bayer'|
|
|
103
84
|
'floyd-steinberg';
|
|
@@ -112,10 +93,18 @@ export interface EncodeFramesOptions {
|
|
|
112
93
|
height: number
|
|
113
94
|
/** The output animation format (WebP, APNG, or GIF). */
|
|
114
95
|
format?: AnimationOutputFormat
|
|
115
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* The quality of lossy WebP (0-100). Ignored for APNG and GIF, and when
|
|
98
|
+
* `lossless` is set.
|
|
99
|
+
*/
|
|
116
100
|
quality?: number
|
|
117
|
-
/**
|
|
118
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Encode WebP losslessly. Defaults to lossless when neither `quality` nor
|
|
103
|
+
* `lossless` is given. Ignored for APNG and GIF.
|
|
104
|
+
*/
|
|
105
|
+
lossless?: boolean
|
|
106
|
+
/** Images keyed by `src`, each carrying raw bytes. */
|
|
107
|
+
images?: Array<ImageSource>
|
|
119
108
|
/** CSS stylesheets to apply before rendering. */
|
|
120
109
|
stylesheets?: Array<string>
|
|
121
110
|
/**
|
|
@@ -123,14 +112,27 @@ export interface EncodeFramesOptions {
|
|
|
123
112
|
* @default 1.0
|
|
124
113
|
*/
|
|
125
114
|
devicePixelRatio?: number
|
|
115
|
+
/**
|
|
116
|
+
* Per-render font stack: ordered family names used as the fallback chain.
|
|
117
|
+
* Defaults to all registered families in registration order.
|
|
118
|
+
*/
|
|
119
|
+
fontFamilies?: Array<string>
|
|
126
120
|
}
|
|
127
121
|
|
|
122
|
+
/** Cache policy for a decoded image. Defaults to `"auto"`. */
|
|
123
|
+
export type ImageCacheMode = /** Cache the decoded image for reuse (evictable). */
|
|
124
|
+
'auto'|
|
|
125
|
+
/** Skip the decoded-image cache. */
|
|
126
|
+
'none';
|
|
127
|
+
|
|
128
128
|
/** An image source with its URL and raw data. */
|
|
129
129
|
export interface ImageSource {
|
|
130
130
|
/** The source URL of the image. */
|
|
131
131
|
src: string
|
|
132
132
|
/** The raw image data (Uint8Array or ArrayBuffer). */
|
|
133
133
|
data: Uint8Array | ArrayBuffer
|
|
134
|
+
/** Cache policy for the decoded image. Defaults to `"auto"`. */
|
|
135
|
+
cache?: ImageCacheMode
|
|
134
136
|
}
|
|
135
137
|
|
|
136
138
|
/** Represents a node that has been measured, including its layout information. */
|
|
@@ -173,6 +175,26 @@ export type OutputFormat = /** WebP format. */
|
|
|
173
175
|
/** Raw pixels format. */
|
|
174
176
|
'raw';
|
|
175
177
|
|
|
178
|
+
/** A single face within a `RegisteredFamily`. */
|
|
179
|
+
export interface RegisteredFace {
|
|
180
|
+
/** Weight class, typically `1`–`1000`. */
|
|
181
|
+
weight: number
|
|
182
|
+
/** CSS `font-style` value (`normal`, `italic`, or `oblique [<angle>deg]`). */
|
|
183
|
+
style: string
|
|
184
|
+
/** Width as a percentage of normal (e.g. `100`). */
|
|
185
|
+
width: number
|
|
186
|
+
/** Index of the face within its source collection. */
|
|
187
|
+
index: number
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** A font family produced by `registerFont`, with the faces it contains. */
|
|
191
|
+
export interface RegisteredFamily {
|
|
192
|
+
/** Family name as stored by the font system (normalized; reflects any override). */
|
|
193
|
+
name: string
|
|
194
|
+
/** Faces registered under this family. */
|
|
195
|
+
faces: Array<RegisteredFace>
|
|
196
|
+
}
|
|
197
|
+
|
|
176
198
|
/** Options for rendering a sequential scene animation. */
|
|
177
199
|
export interface RenderAnimationOptions {
|
|
178
200
|
/** The scenes to render sequentially. */
|
|
@@ -185,12 +207,20 @@ export interface RenderAnimationOptions {
|
|
|
185
207
|
height: number
|
|
186
208
|
/** The output animation format (WebP, APNG, or GIF). */
|
|
187
209
|
format?: AnimationOutputFormat
|
|
188
|
-
/**
|
|
210
|
+
/**
|
|
211
|
+
* The quality of lossy WebP (0-100). Ignored for APNG and GIF, and when
|
|
212
|
+
* `lossless` is set.
|
|
213
|
+
*/
|
|
189
214
|
quality?: number
|
|
215
|
+
/**
|
|
216
|
+
* Encode WebP losslessly. Defaults to lossless when neither `quality` nor
|
|
217
|
+
* `lossless` is given. Ignored for APNG and GIF.
|
|
218
|
+
*/
|
|
219
|
+
lossless?: boolean
|
|
190
220
|
/** Frames per second for timeline sampling. */
|
|
191
221
|
fps: number
|
|
192
|
-
/**
|
|
193
|
-
|
|
222
|
+
/** Images keyed by `src`, each carrying raw bytes. */
|
|
223
|
+
images?: Array<ImageSource>
|
|
194
224
|
/** CSS stylesheets to apply before rendering. */
|
|
195
225
|
stylesheets?: Array<string>
|
|
196
226
|
/**
|
|
@@ -198,6 +228,11 @@ export interface RenderAnimationOptions {
|
|
|
198
228
|
* @default 1.0
|
|
199
229
|
*/
|
|
200
230
|
devicePixelRatio?: number
|
|
231
|
+
/**
|
|
232
|
+
* Per-render font stack: ordered family names used as the fallback chain.
|
|
233
|
+
* Defaults to all registered families in registration order.
|
|
234
|
+
*/
|
|
235
|
+
fontFamilies?: Array<string>
|
|
201
236
|
}
|
|
202
237
|
|
|
203
238
|
/** Options for rendering an image. */
|
|
@@ -208,12 +243,20 @@ export interface RenderOptions {
|
|
|
208
243
|
height?: number
|
|
209
244
|
/** The format of the image. */
|
|
210
245
|
format?: OutputFormat
|
|
211
|
-
/**
|
|
246
|
+
/**
|
|
247
|
+
* The quality of lossy formats (0-100). For JPEG; for WebP it selects lossy
|
|
248
|
+
* encoding unless `lossless` is set.
|
|
249
|
+
*/
|
|
212
250
|
quality?: number
|
|
251
|
+
/**
|
|
252
|
+
* Encode WebP losslessly. Defaults to lossless when neither `quality` nor
|
|
253
|
+
* `lossless` is given.
|
|
254
|
+
*/
|
|
255
|
+
lossless?: boolean
|
|
213
256
|
/** Whether to draw debug borders. */
|
|
214
257
|
drawDebugBorder?: boolean
|
|
215
|
-
/**
|
|
216
|
-
|
|
258
|
+
/** Images keyed by `src`, each carrying raw bytes. */
|
|
259
|
+
images?: Array<ImageSource>
|
|
217
260
|
/** CSS stylesheets to apply before rendering. */
|
|
218
261
|
stylesheets?: Array<string>
|
|
219
262
|
/** Structured keyframes to register alongside stylesheets. */
|
|
@@ -227,4 +270,34 @@ export interface RenderOptions {
|
|
|
227
270
|
timeMs?: number
|
|
228
271
|
/** The output dithering algorithm. */
|
|
229
272
|
dithering?: DitheringAlgorithm
|
|
273
|
+
/**
|
|
274
|
+
* Per-render font stack: ordered family names used as the fallback chain.
|
|
275
|
+
* Defaults to all registered families in registration order.
|
|
276
|
+
*/
|
|
277
|
+
fontFamilies?: Array<string>
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Options for rendering a node tree to an SVG document. SVG is a vector
|
|
282
|
+
* format, so the raster-only knobs (`format`, `quality`, `lossless`,
|
|
283
|
+
* `dithering`, `drawDebugBorder`, `devicePixelRatio`) do not apply.
|
|
284
|
+
*/
|
|
285
|
+
export interface SvgRenderOptions {
|
|
286
|
+
/** The width of the viewport. If not provided, it is derived from content. */
|
|
287
|
+
width?: number
|
|
288
|
+
/** The height of the viewport. If not provided, it is derived from content. */
|
|
289
|
+
height?: number
|
|
290
|
+
/** Images keyed by `src`, each carrying raw bytes. */
|
|
291
|
+
images?: Array<ImageSource>
|
|
292
|
+
/** CSS stylesheets to apply before rendering. */
|
|
293
|
+
stylesheets?: Array<string>
|
|
294
|
+
/** Structured keyframes to register alongside stylesheets. */
|
|
295
|
+
keyframes?: Keyframes
|
|
296
|
+
/** The animation timeline time in milliseconds. */
|
|
297
|
+
timeMs?: number
|
|
298
|
+
/**
|
|
299
|
+
* Per-render font stack: ordered family names used as the fallback chain.
|
|
300
|
+
* Defaults to all registered families in registration order.
|
|
301
|
+
*/
|
|
302
|
+
fontFamilies?: Array<string>
|
|
230
303
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takumi-rs/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
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",
|
|
@@ -36,16 +36,25 @@
|
|
|
36
36
|
"sideEffects": false,
|
|
37
37
|
"main": "./dist/export.cjs",
|
|
38
38
|
"module": "./dist/export.mjs",
|
|
39
|
-
"types": "./dist/export.d.
|
|
39
|
+
"types": "./dist/export.d.mts",
|
|
40
40
|
"exports": {
|
|
41
41
|
".": {
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
"workerd": {
|
|
43
|
+
"types": "./dist/export.d.mts",
|
|
44
|
+
"default": "./not-available.js"
|
|
45
|
+
},
|
|
46
|
+
"browser": {
|
|
47
|
+
"types": "./dist/export.d.mts",
|
|
48
|
+
"default": "./not-available.js"
|
|
49
|
+
},
|
|
50
|
+
"import": {
|
|
51
|
+
"types": "./dist/export.d.mts",
|
|
52
|
+
"default": "./dist/export.mjs"
|
|
53
|
+
},
|
|
54
|
+
"require": {
|
|
55
|
+
"types": "./dist/export.d.cts",
|
|
56
|
+
"default": "./dist/export.cjs"
|
|
57
|
+
}
|
|
49
58
|
}
|
|
50
59
|
},
|
|
51
60
|
"publishConfig": {
|
|
@@ -54,16 +63,17 @@
|
|
|
54
63
|
},
|
|
55
64
|
"scripts": {
|
|
56
65
|
"build": "napi build --release --no-const-enum --platform --esm --strip",
|
|
57
|
-
"build:js": "tsdown &&
|
|
66
|
+
"build:js": "tsdown && bun scripts/patch-dist-loader.ts",
|
|
58
67
|
"prepublishOnly": "jq '.dependencies[\"@takumi-rs/helpers\"] = .version' package.json > tmp.json && mv tmp.json package.json && bun artifacts && napi prepublish -t npm --no-gh-release",
|
|
59
68
|
"artifacts": "napi create-npm-dirs && napi artifacts && napi version",
|
|
60
|
-
"bench": "bun tests/bench/index.tsx"
|
|
69
|
+
"bench": "bun tests/bench/index.tsx",
|
|
70
|
+
"publish-lint": "attw --pack . && publint --strict ."
|
|
61
71
|
},
|
|
62
72
|
"dependencies": {
|
|
63
|
-
"@takumi-rs/helpers": "
|
|
73
|
+
"@takumi-rs/helpers": "2.0.0-beta.0"
|
|
64
74
|
},
|
|
65
75
|
"devDependencies": {
|
|
66
|
-
"@napi-rs/cli": "3.7.
|
|
76
|
+
"@napi-rs/cli": "3.7.2",
|
|
67
77
|
"@types/bun": "catalog:",
|
|
68
78
|
"@types/react": "catalog:",
|
|
69
79
|
"@types/react-dom": "catalog:",
|
|
@@ -93,13 +103,13 @@
|
|
|
93
103
|
"node": ">= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0 < 16 || >= 16.0.0"
|
|
94
104
|
},
|
|
95
105
|
"optionalDependencies": {
|
|
96
|
-
"@takumi-rs/core-darwin-x64": "
|
|
97
|
-
"@takumi-rs/core-darwin-arm64": "
|
|
98
|
-
"@takumi-rs/core-linux-arm64-gnu": "
|
|
99
|
-
"@takumi-rs/core-linux-arm64-musl": "
|
|
100
|
-
"@takumi-rs/core-win32-arm64-msvc": "
|
|
101
|
-
"@takumi-rs/core-linux-x64-gnu": "
|
|
102
|
-
"@takumi-rs/core-linux-x64-musl": "
|
|
103
|
-
"@takumi-rs/core-win32-x64-msvc": "
|
|
106
|
+
"@takumi-rs/core-darwin-x64": "2.0.0-beta.0",
|
|
107
|
+
"@takumi-rs/core-darwin-arm64": "2.0.0-beta.0",
|
|
108
|
+
"@takumi-rs/core-linux-arm64-gnu": "2.0.0-beta.0",
|
|
109
|
+
"@takumi-rs/core-linux-arm64-musl": "2.0.0-beta.0",
|
|
110
|
+
"@takumi-rs/core-win32-arm64-msvc": "2.0.0-beta.0",
|
|
111
|
+
"@takumi-rs/core-linux-x64-gnu": "2.0.0-beta.0",
|
|
112
|
+
"@takumi-rs/core-linux-x64-musl": "2.0.0-beta.0",
|
|
113
|
+
"@takumi-rs/core-win32-x64-msvc": "2.0.0-beta.0"
|
|
104
114
|
}
|
|
105
115
|
}
|
package/dist/export.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { Font, FontDetails, ImageSource } from "../index";
|
|
2
|
-
export type * from "../index";
|
|
3
|
-
import { Renderer as NativeRenderer } from "../index";
|
|
4
|
-
export { extractResourceUrls } from "@takumi-rs/helpers";
|
|
5
|
-
export type ImageSourceLoader = Omit<ImageSource, "data"> & {
|
|
6
|
-
data: ImageSource["data"] | (() => Promise<ImageSource["data"]> | ImageSource["data"]);
|
|
7
|
-
};
|
|
8
|
-
export type FontLoader = Font | (Omit<FontDetails, "data"> & {
|
|
9
|
-
key?: string;
|
|
10
|
-
data: FontDetails["data"] | (() => Promise<FontDetails["data"]> | FontDetails["data"]);
|
|
11
|
-
});
|
|
12
|
-
export type ImageSourceLoaderSync = Omit<ImageSource, "data"> & {
|
|
13
|
-
data: ImageSource["data"] | (() => ImageSource["data"]);
|
|
14
|
-
};
|
|
15
|
-
export type FontLoaderSync = Font | (Omit<FontDetails, "data"> & {
|
|
16
|
-
key?: string;
|
|
17
|
-
data: FontDetails["data"] | (() => FontDetails["data"]);
|
|
18
|
-
});
|
|
19
|
-
export declare class Renderer extends NativeRenderer {
|
|
20
|
-
private fontsMark;
|
|
21
|
-
private fontBuffersMark;
|
|
22
|
-
private persistentImageSrcMark;
|
|
23
|
-
private pendingPersistentImages;
|
|
24
|
-
putPersistentImage(source: ImageSourceLoader, signal?: AbortSignal): Promise<void>;
|
|
25
|
-
loadFonts(fonts: FontLoader[], signal?: AbortSignal): Promise<number>;
|
|
26
|
-
loadFont(data: FontLoader, signal?: AbortSignal): Promise<number>;
|
|
27
|
-
loadFontSync(font: FontLoaderSync): void;
|
|
28
|
-
clearImageStore(): void;
|
|
29
|
-
private checkAndMarkFont;
|
|
30
|
-
private isNewFont;
|
|
31
|
-
private isNewPersistentImage;
|
|
32
|
-
}
|