@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/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(options?: ConstructRendererOptions | undefined | null)
44
- /** Puts a persistent image into the renderer's internal store asynchronously. */
45
- putPersistentImage(source: ImageSource, signal?: AbortSignal): Promise<void>
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
- /** The quality of WebP format (0-100). Ignored for APNG and GIF. */
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
- /** The fetched resources to use. */
118
- fetchedResources?: Array<ImageSource>
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
- /** The quality of WebP format (0-100). Ignored for APNG and GIF. */
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
- /** The fetched resources to use. */
193
- fetchedResources?: Array<ImageSource>
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
- /** The quality of JPEG format (0-100). */
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
- /** The fetched resources to use. */
216
- fetchedResources?: Array<ImageSource>
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": "1.8.7",
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-core"
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": "1.8.7"
73
+ "@takumi-rs/helpers": "2.0.0-beta.0"
74
74
  },
75
75
  "devDependencies": {
76
- "@napi-rs/cli": "3.7.0",
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": "1.8.7",
107
- "@takumi-rs/core-darwin-arm64": "1.8.7",
108
- "@takumi-rs/core-linux-arm64-gnu": "1.8.7",
109
- "@takumi-rs/core-linux-arm64-musl": "1.8.7",
110
- "@takumi-rs/core-win32-arm64-msvc": "1.8.7",
111
- "@takumi-rs/core-linux-x64-gnu": "1.8.7",
112
- "@takumi-rs/core-linux-x64-musl": "1.8.7",
113
- "@takumi-rs/core-win32-x64-msvc": "1.8.7"
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"
114
114
  }
115
115
  }