@takumi-rs/core 1.0.0-beta.12 → 1.0.0-beta.14
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/export.d.ts +220 -1
- package/export.mjs +7 -3
- package/package.json +11 -11
package/export.d.ts
CHANGED
|
@@ -1 +1,220 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Node } from "@takumi-rs/helpers";
|
|
2
|
+
|
|
3
|
+
export type { ContainerNode, ImageNode, NodeMetadata, TextNode } from "@takumi-rs/helpers";
|
|
4
|
+
|
|
5
|
+
export type { Node };
|
|
6
|
+
|
|
7
|
+
export interface FontDetails {
|
|
8
|
+
/**
|
|
9
|
+
* The name of the font. If not provided, the name in the font file will be used.
|
|
10
|
+
*/
|
|
11
|
+
name?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The font data.
|
|
14
|
+
*/
|
|
15
|
+
data: Uint8Array | ArrayBuffer;
|
|
16
|
+
/**
|
|
17
|
+
* The weight of the font. If not provided, the weight in the font file will be used.
|
|
18
|
+
*/
|
|
19
|
+
weight?: number;
|
|
20
|
+
/**
|
|
21
|
+
* The style of the font. If not provided, the style in the font file will be used.
|
|
22
|
+
*/
|
|
23
|
+
style?: "normal" | "italic" | "oblique" | `oblique ${number}deg` | (string & {});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type Font = FontDetails | Uint8Array | ArrayBuffer;
|
|
27
|
+
|
|
28
|
+
export type Keyframes = Record<string, Record<string, Record<string, unknown>>>;
|
|
29
|
+
/** The main renderer for Takumi image rendering engine (Node.js version). */
|
|
30
|
+
export declare class Renderer {
|
|
31
|
+
/** Creates a new Renderer instance. */
|
|
32
|
+
constructor(options?: ConstructRendererOptions | undefined | null)
|
|
33
|
+
/** Puts a persistent image into the renderer's internal store asynchronously. */
|
|
34
|
+
putPersistentImage(source: ImageSource, signal?: AbortSignal): Promise<void>
|
|
35
|
+
/** Loads a font synchronously. */
|
|
36
|
+
loadFontSync(font: Font): void
|
|
37
|
+
/** Loads a font into the renderer asynchronously. */
|
|
38
|
+
loadFont(data: Font, signal?: AbortSignal): Promise<number>
|
|
39
|
+
/** Loads multiple fonts into the renderer asynchronously. */
|
|
40
|
+
loadFonts(fonts: Font[], signal?: AbortSignal): Promise<number>
|
|
41
|
+
/** Clears the renderer's internal image store. */
|
|
42
|
+
clearImageStore(): void
|
|
43
|
+
/** Renders a node tree into an image buffer asynchronously. */
|
|
44
|
+
render(source: Node, options?: RenderOptions, signal?: AbortSignal): Promise<Buffer>
|
|
45
|
+
/** Measures a node tree and returns layout information asynchronously. */
|
|
46
|
+
measure(source: Node, options?: RenderOptions, signal?: AbortSignal): Promise<MeasuredNode>
|
|
47
|
+
/** Renders a sequential scene animation into a buffer asynchronously. */
|
|
48
|
+
renderAnimation(options: RenderAnimationOptions, signal?: AbortSignal): Promise<Buffer>
|
|
49
|
+
/** Encodes a precomputed frame sequence into an animated image buffer asynchronously. */
|
|
50
|
+
encodeFrames(source: AnimationFrameSource[], options: EncodeFramesOptions, signal?: AbortSignal): Promise<Buffer>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Represents a single frame in a precomputed animation sequence. */
|
|
54
|
+
export interface AnimationFrameSource {
|
|
55
|
+
/** The node tree to render for this frame. */
|
|
56
|
+
node: Node
|
|
57
|
+
/** The duration of this frame in milliseconds. */
|
|
58
|
+
durationMs: number
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Output format for animated images. */
|
|
62
|
+
export type AnimationOutputFormat = /** Animated WebP format. */
|
|
63
|
+
'webp'|
|
|
64
|
+
/** Animated PNG format. */
|
|
65
|
+
'apng'|
|
|
66
|
+
/** Animated GIF format. */
|
|
67
|
+
'gif';
|
|
68
|
+
|
|
69
|
+
/** Represents a single scene in a sequential animation timeline. */
|
|
70
|
+
export interface AnimationSceneSource {
|
|
71
|
+
/** The node tree to render for this scene. */
|
|
72
|
+
node: Node
|
|
73
|
+
/** The duration of this scene in milliseconds. */
|
|
74
|
+
durationMs: number
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Options for constructing a Renderer instance. */
|
|
78
|
+
export interface ConstructRendererOptions {
|
|
79
|
+
/** The images that needs to be preloaded into the renderer. */
|
|
80
|
+
persistentImages?: Array<ImageSource>
|
|
81
|
+
/** The fonts being used. */
|
|
82
|
+
fonts?: Font[] | undefined
|
|
83
|
+
/**
|
|
84
|
+
* Whether to load the default fonts.
|
|
85
|
+
* If `fonts` are provided, this will be `false` by default.
|
|
86
|
+
*/
|
|
87
|
+
loadDefaultFonts?: boolean
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type DitheringAlgorithm = 'none'|
|
|
91
|
+
'ordered-bayer'|
|
|
92
|
+
'floyd-steinberg';
|
|
93
|
+
|
|
94
|
+
/** Options for encoding a precomputed frame sequence. */
|
|
95
|
+
export interface EncodeFramesOptions {
|
|
96
|
+
/** Whether to draw debug borders around layout elements. */
|
|
97
|
+
drawDebugBorder?: boolean
|
|
98
|
+
/** The width of each frame in pixels. */
|
|
99
|
+
width: number
|
|
100
|
+
/** The height of each frame in pixels. */
|
|
101
|
+
height: number
|
|
102
|
+
/** The output animation format (WebP, APNG, or GIF). */
|
|
103
|
+
format?: AnimationOutputFormat
|
|
104
|
+
/** The quality of WebP format (0-100). Ignored for APNG and GIF. */
|
|
105
|
+
quality?: number
|
|
106
|
+
/** The fetched resources to use. */
|
|
107
|
+
fetchedResources?: Array<ImageSource>
|
|
108
|
+
/** CSS stylesheets to apply before rendering. */
|
|
109
|
+
stylesheets?: Array<string>
|
|
110
|
+
/**
|
|
111
|
+
* The device pixel ratio.
|
|
112
|
+
* @default 1.0
|
|
113
|
+
*/
|
|
114
|
+
devicePixelRatio?: number
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Collects the fetch task urls from the node. */
|
|
118
|
+
export declare function extractResourceUrls(node: Node): Array<string>
|
|
119
|
+
|
|
120
|
+
/** An image source with its URL and raw data. */
|
|
121
|
+
export interface ImageSource {
|
|
122
|
+
/** The source URL of the image. */
|
|
123
|
+
src: string
|
|
124
|
+
/** The raw image data (Uint8Array or ArrayBuffer). */
|
|
125
|
+
data: Uint8Array | ArrayBuffer
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Represents a node that has been measured, including its layout information. */
|
|
129
|
+
export interface MeasuredNode {
|
|
130
|
+
/** The measured width of the node. */
|
|
131
|
+
width: number
|
|
132
|
+
/** The measured height of the node. */
|
|
133
|
+
height: number
|
|
134
|
+
/** The transformation matrix of the node. */
|
|
135
|
+
transform: [number, number, number, number, number, number]
|
|
136
|
+
/** The children of the node. */
|
|
137
|
+
children: Array<MeasuredNode>
|
|
138
|
+
/** The text runs within the node. */
|
|
139
|
+
runs: Array<MeasuredTextRun>
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Represents a single run of text in a measured node. */
|
|
143
|
+
export interface MeasuredTextRun {
|
|
144
|
+
/** The text content of the run. */
|
|
145
|
+
text: string
|
|
146
|
+
/** The inline x-coordinate of the run. */
|
|
147
|
+
x: number
|
|
148
|
+
/** The inline y-coordinate of the run. */
|
|
149
|
+
y: number
|
|
150
|
+
/** The width of the run. */
|
|
151
|
+
width: number
|
|
152
|
+
/** The height of the run. */
|
|
153
|
+
height: number
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Output format for static images. */
|
|
157
|
+
export type OutputFormat = /** WebP format. */
|
|
158
|
+
'webp'|
|
|
159
|
+
/** PNG format. */
|
|
160
|
+
'png'|
|
|
161
|
+
/** JPEG format. */
|
|
162
|
+
'jpeg'|
|
|
163
|
+
/** Raw pixels format. */
|
|
164
|
+
'raw';
|
|
165
|
+
|
|
166
|
+
/** Options for rendering a sequential scene animation. */
|
|
167
|
+
export interface RenderAnimationOptions {
|
|
168
|
+
/** The scenes to render sequentially. */
|
|
169
|
+
scenes: Array<AnimationSceneSource>
|
|
170
|
+
/** Whether to draw debug borders around layout elements. */
|
|
171
|
+
drawDebugBorder?: boolean
|
|
172
|
+
/** The width of each frame in pixels. */
|
|
173
|
+
width: number
|
|
174
|
+
/** The height of each frame in pixels. */
|
|
175
|
+
height: number
|
|
176
|
+
/** The output animation format (WebP, APNG, or GIF). */
|
|
177
|
+
format?: AnimationOutputFormat
|
|
178
|
+
/** The quality of WebP format (0-100). Ignored for APNG and GIF. */
|
|
179
|
+
quality?: number
|
|
180
|
+
/** Frames per second for timeline sampling. */
|
|
181
|
+
fps: number
|
|
182
|
+
/** The fetched resources to use. */
|
|
183
|
+
fetchedResources?: Array<ImageSource>
|
|
184
|
+
/** CSS stylesheets to apply before rendering. */
|
|
185
|
+
stylesheets?: Array<string>
|
|
186
|
+
/**
|
|
187
|
+
* The device pixel ratio.
|
|
188
|
+
* @default 1.0
|
|
189
|
+
*/
|
|
190
|
+
devicePixelRatio?: number
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Options for rendering an image. */
|
|
194
|
+
export interface RenderOptions {
|
|
195
|
+
/** The width of the image. If not provided, the width will be automatically calculated based on the content. */
|
|
196
|
+
width?: number
|
|
197
|
+
/** The height of the image. If not provided, the height will be automatically calculated based on the content. */
|
|
198
|
+
height?: number
|
|
199
|
+
/** The format of the image. */
|
|
200
|
+
format?: OutputFormat
|
|
201
|
+
/** The quality of JPEG format (0-100). */
|
|
202
|
+
quality?: number
|
|
203
|
+
/** Whether to draw debug borders. */
|
|
204
|
+
drawDebugBorder?: boolean
|
|
205
|
+
/** The fetched resources to use. */
|
|
206
|
+
fetchedResources?: Array<ImageSource>
|
|
207
|
+
/** CSS stylesheets to apply before rendering. */
|
|
208
|
+
stylesheets?: Array<string>
|
|
209
|
+
/** Structured keyframes to register alongside stylesheets. */
|
|
210
|
+
keyframes?: { name: string; keyframes: { offsets: number[]; declarations: Record<string, unknown> }[] }[] | Keyframes
|
|
211
|
+
/**
|
|
212
|
+
* The device pixel ratio.
|
|
213
|
+
* @default 1.0
|
|
214
|
+
*/
|
|
215
|
+
devicePixelRatio?: number
|
|
216
|
+
/** The animation timeline time in milliseconds. */
|
|
217
|
+
timeMs?: number
|
|
218
|
+
/** The output dithering algorithm. */
|
|
219
|
+
dithering?: DitheringAlgorithm
|
|
220
|
+
}
|
package/export.mjs
CHANGED
|
@@ -62,9 +62,13 @@ function loadNativeModule() {
|
|
|
62
62
|
const nativeModule = loadNativeModule();
|
|
63
63
|
|
|
64
64
|
if (!nativeModule) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
if (process.env.NEXT_RUNTIME === "nodejs") {
|
|
66
|
+
throw new Error(
|
|
67
|
+
"Native module is not being included in the bundle, add `outputFileTracingIncludes` to your Next.js configuration with `node_modules/@takumi-rs/core-*/*`.",
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
throw new Error("Unable to load native module, make sure your bundler has included it.");
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
const { Renderer, extractResourceUrls } = nativeModule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takumi-rs/core",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.14",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"css",
|
|
6
6
|
"image",
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "napi build --release --no-const-enum --platform --esm --strip",
|
|
43
|
-
"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",
|
|
43
|
+
"prepublishOnly": "jq '.dependencies[\"@takumi-rs/helpers\"] = .version' package.json > tmp.json && mv tmp.json package.json && bun artifacts && cp artifacts/bindings-x86_64-unknown-linux-gnu/index.d.ts export.d.ts && napi prepublish -t npm --no-gh-release",
|
|
44
44
|
"artifacts": "napi create-npm-dirs && napi artifacts && napi version",
|
|
45
45
|
"bench": "bun tests/bench/index.tsx"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@takumi-rs/helpers": "1.0.0-beta.
|
|
48
|
+
"@takumi-rs/helpers": "1.0.0-beta.14"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@napi-rs/cli": "3.5.1",
|
|
@@ -75,13 +75,13 @@
|
|
|
75
75
|
"node": ">= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0 < 16 || >= 16.0.0"
|
|
76
76
|
},
|
|
77
77
|
"optionalDependencies": {
|
|
78
|
-
"@takumi-rs/core-darwin-x64": "1.0.0-beta.
|
|
79
|
-
"@takumi-rs/core-darwin-arm64": "1.0.0-beta.
|
|
80
|
-
"@takumi-rs/core-linux-arm64-gnu": "1.0.0-beta.
|
|
81
|
-
"@takumi-rs/core-linux-arm64-musl": "1.0.0-beta.
|
|
82
|
-
"@takumi-rs/core-win32-arm64-msvc": "1.0.0-beta.
|
|
83
|
-
"@takumi-rs/core-linux-x64-gnu": "1.0.0-beta.
|
|
84
|
-
"@takumi-rs/core-linux-x64-musl": "1.0.0-beta.
|
|
85
|
-
"@takumi-rs/core-win32-x64-msvc": "1.0.0-beta.
|
|
78
|
+
"@takumi-rs/core-darwin-x64": "1.0.0-beta.14",
|
|
79
|
+
"@takumi-rs/core-darwin-arm64": "1.0.0-beta.14",
|
|
80
|
+
"@takumi-rs/core-linux-arm64-gnu": "1.0.0-beta.14",
|
|
81
|
+
"@takumi-rs/core-linux-arm64-musl": "1.0.0-beta.14",
|
|
82
|
+
"@takumi-rs/core-win32-arm64-msvc": "1.0.0-beta.14",
|
|
83
|
+
"@takumi-rs/core-linux-x64-gnu": "1.0.0-beta.14",
|
|
84
|
+
"@takumi-rs/core-linux-x64-musl": "1.0.0-beta.14",
|
|
85
|
+
"@takumi-rs/core-win32-x64-msvc": "1.0.0-beta.14"
|
|
86
86
|
}
|
|
87
87
|
}
|