takumi-js 2.12.0 → 2.13.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/backend/node.cjs +1 -1
- package/dist/backend/wasm.cjs +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +1 -1
- package/dist/{render-BIupnPO8.d.cts → render-9RT7wd29.d.mts} +16 -6
- package/dist/{render-CPSfpCxT.mjs → render-BPTOJWUk.mjs} +31 -16
- package/dist/{render-f5o4nsy9.cjs → render-C7kRwHMk.cjs} +32 -17
- package/dist/{render-CSv0fCuQ.d.mts → render-DDQRhVd1.d.cts} +16 -6
- package/dist/response.cjs +1 -1
- package/dist/response.d.cts +1 -1
- package/dist/response.d.mts +1 -1
- package/dist/response.mjs +1 -1
- package/dist/{rolldown-runtime-DakpK96I.cjs → rolldown-runtime-C0BPl7ul.cjs} +1 -1
- package/dist/wasm/no-init.cjs +1 -1
- package/dist/{wasm-init-H65IoN11.cjs → wasm-init-Dl-su2Ub.cjs} +1 -1
- package/dist/{wasm-node-CaSIdQS-.cjs → wasm-node-BB44t5QI.cjs} +2 -2
- package/dist/wasm.cjs +1 -1
- package/package.json +5 -5
package/dist/backend/node.cjs
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const loadNative = () => import("@takumi-rs/core").catch((cause) => {
|
|
4
4
|
throw new Error("Failed to load the native @takumi-rs/core backend. On a runtime without the native addon, pass a `module` (a WASM binary) to render with the WASM backend instead.", { cause });
|
|
5
5
|
});
|
|
6
|
-
const loadWasm = (module) => Promise.resolve().then(() => require("../wasm-node-
|
|
6
|
+
const loadWasm = (module) => Promise.resolve().then(() => require("../wasm-node-BB44t5QI.cjs")).then((backend) => backend.loadBackend(module));
|
|
7
7
|
const loadBackend = (module) => typeof process !== "undefined" && process.versions?.webcontainer ? loadWasm(module) : loadNative(module);
|
|
8
8
|
//#endregion
|
|
9
9
|
exports.loadBackend = loadBackend;
|
package/dist/backend/wasm.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_rolldown_runtime = require("../rolldown-runtime-
|
|
3
|
-
const require_wasm_init = require("../wasm-init-
|
|
2
|
+
const require_rolldown_runtime = require("../rolldown-runtime-C0BPl7ul.cjs");
|
|
3
|
+
const require_wasm_init = require("../wasm-init-Dl-su2Ub.cjs");
|
|
4
4
|
let _takumi_rs_wasm_auto = require("@takumi-rs/wasm/auto");
|
|
5
5
|
_takumi_rs_wasm_auto = require_rolldown_runtime.__toESM(_takumi_rs_wasm_auto, 1);
|
|
6
6
|
//#region src/backend/wasm.ts
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_render = require("./render-
|
|
2
|
+
const require_render = require("./render-C7kRwHMk.cjs");
|
|
3
3
|
exports.render = require_render.render;
|
|
4
4
|
exports.renderAnimation = require_render.renderAnimation;
|
|
5
5
|
exports.renderSvg = require_render.renderSvg;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as RenderOptions, c as renderAnimation, i as RenderInput, l as renderSvg, n as ImagesInput, o as RenderSvgOptions, r as RenderAnimationOptions, s as render, t as AnimationScene } from "./render-
|
|
1
|
+
import { a as RenderOptions, c as renderAnimation, i as RenderInput, l as renderSvg, n as ImagesInput, o as RenderSvgOptions, r as RenderAnimationOptions, s as render, t as AnimationScene } from "./render-DDQRhVd1.cjs";
|
|
2
2
|
import { AnimationOutputFormat, DitheringAlgorithm, Font, FontDetails, FontLoader, ImageSource, Keyframes, KeyframesMap, KeyframesRuleList, MeasuredNode, MeasuredTextRun, OutputFormat } from "@takumi-rs/core";
|
|
3
|
-
import { ContainerNode, FetchOptions, ImageNode, Node, NodeAttributes, NodeMetadata, ReactElementLike, RgbaImage, TextNode } from "@takumi-rs/helpers";
|
|
3
|
+
import { AnimationRule, ContainerNode, CssInput, Declarations, FetchOptions, ImageNode, LayerRule, MediaRule, Node, NodeAttributes, NodeMetadata, ReactElementLike, RgbaImage, StyleRule, SupportsRule, TextNode } from "@takumi-rs/helpers";
|
|
4
4
|
//#region src/glyph-cache.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Sets the byte budget shared by the resolved-glyph and glyph-mask caches; `0` stops
|
|
@@ -24,4 +24,4 @@ declare module "react" {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
//#endregion
|
|
27
|
-
export { type AnimationOutputFormat, type AnimationScene, type ContainerNode, type DitheringAlgorithm, type FetchOptions, type Font, type FontDetails, type FontLoader, type ImageNode, type ImageSource, type ImagesInput, type Keyframes, type KeyframesMap, type KeyframesRuleList, type MeasuredNode, type MeasuredTextRun, type Node, type NodeAttributes, type NodeMetadata, type OutputFormat, type ReactElementLike, type RenderAnimationOptions, type RenderInput, type RenderOptions, type RenderSvgOptions, type RgbaImage, type TextNode, render, renderAnimation, renderSvg, setGlyphCacheMaxBytes };
|
|
27
|
+
export { type AnimationOutputFormat, type AnimationRule, type AnimationScene, type ContainerNode, type CssInput, type Declarations, type DitheringAlgorithm, type FetchOptions, type Font, type FontDetails, type FontLoader, type ImageNode, type ImageSource, type ImagesInput, type Keyframes, type KeyframesMap, type KeyframesRuleList, type LayerRule, type MeasuredNode, type MeasuredTextRun, type MediaRule, type Node, type NodeAttributes, type NodeMetadata, type OutputFormat, type ReactElementLike, type RenderAnimationOptions, type RenderInput, type RenderOptions, type RenderSvgOptions, type RgbaImage, type StyleRule, type SupportsRule, type TextNode, render, renderAnimation, renderSvg, setGlyphCacheMaxBytes };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as RenderOptions, c as renderAnimation, i as RenderInput, l as renderSvg, n as ImagesInput, o as RenderSvgOptions, r as RenderAnimationOptions, s as render, t as AnimationScene } from "./render-
|
|
2
|
-
import { ContainerNode, FetchOptions, ImageNode, Node, NodeAttributes, NodeMetadata, ReactElementLike, RgbaImage, TextNode } from "@takumi-rs/helpers";
|
|
1
|
+
import { a as RenderOptions, c as renderAnimation, i as RenderInput, l as renderSvg, n as ImagesInput, o as RenderSvgOptions, r as RenderAnimationOptions, s as render, t as AnimationScene } from "./render-9RT7wd29.mjs";
|
|
2
|
+
import { AnimationRule, ContainerNode, CssInput, Declarations, FetchOptions, ImageNode, LayerRule, MediaRule, Node, NodeAttributes, NodeMetadata, ReactElementLike, RgbaImage, StyleRule, SupportsRule, TextNode } from "@takumi-rs/helpers";
|
|
3
3
|
import { AnimationOutputFormat, DitheringAlgorithm, Font, FontDetails, FontLoader, ImageSource, Keyframes, KeyframesMap, KeyframesRuleList, MeasuredNode, MeasuredTextRun, OutputFormat } from "@takumi-rs/core";
|
|
4
4
|
//#region src/glyph-cache.d.ts
|
|
5
5
|
/**
|
|
@@ -24,4 +24,4 @@ declare module "react" {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
//#endregion
|
|
27
|
-
export { type AnimationOutputFormat, type AnimationScene, type ContainerNode, type DitheringAlgorithm, type FetchOptions, type Font, type FontDetails, type FontLoader, type ImageNode, type ImageSource, type ImagesInput, type Keyframes, type KeyframesMap, type KeyframesRuleList, type MeasuredNode, type MeasuredTextRun, type Node, type NodeAttributes, type NodeMetadata, type OutputFormat, type ReactElementLike, type RenderAnimationOptions, type RenderInput, type RenderOptions, type RenderSvgOptions, type RgbaImage, type TextNode, render, renderAnimation, renderSvg, setGlyphCacheMaxBytes };
|
|
27
|
+
export { type AnimationOutputFormat, type AnimationRule, type AnimationScene, type ContainerNode, type CssInput, type Declarations, type DitheringAlgorithm, type FetchOptions, type Font, type FontDetails, type FontLoader, type ImageNode, type ImageSource, type ImagesInput, type Keyframes, type KeyframesMap, type KeyframesRuleList, type LayerRule, type MeasuredNode, type MeasuredTextRun, type MediaRule, type Node, type NodeAttributes, type NodeMetadata, type OutputFormat, type ReactElementLike, type RenderAnimationOptions, type RenderInput, type RenderOptions, type RenderSvgOptions, type RgbaImage, type StyleRule, type SupportsRule, type TextNode, render, renderAnimation, renderSvg, setGlyphCacheMaxBytes };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as setGlyphCacheMaxBytes, n as renderAnimation, r as renderSvg, t as render } from "./render-
|
|
1
|
+
import { i as setGlyphCacheMaxBytes, n as renderAnimation, r as renderSvg, t as render } from "./render-BPTOJWUk.mjs";
|
|
2
2
|
export { render, renderAnimation, renderSvg, setGlyphCacheMaxBytes };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as napi from "@takumi-rs/core";
|
|
2
|
-
import * as wasm from "@takumi-rs/wasm";
|
|
3
1
|
import { EmojiType } from "@takumi-rs/helpers/emoji";
|
|
4
|
-
import { FetchOptions, ImageFetchCache, Node, ReactElementLike } from "@takumi-rs/helpers";
|
|
2
|
+
import { CssInput, FetchOptions, ImageFetchCache, Node, ReactElementLike } from "@takumi-rs/helpers";
|
|
5
3
|
import { FromJsxOptions } from "@takumi-rs/helpers/jsx";
|
|
4
|
+
import * as napi from "@takumi-rs/core";
|
|
5
|
+
import * as wasm from "@takumi-rs/wasm";
|
|
6
6
|
import { ReactNode } from "react";
|
|
7
7
|
//#region src/render.d.ts
|
|
8
8
|
type Renderer = napi.Renderer | wasm.Renderer;
|
|
@@ -50,9 +50,19 @@ type Managed<TInner> = (TInner & SharedRenderExtras) | (TInner & Omit<SharedRend
|
|
|
50
50
|
* tagged union survives instead of collapsing into one flat member.
|
|
51
51
|
*/
|
|
52
52
|
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
53
|
-
|
|
54
|
-
type
|
|
55
|
-
|
|
53
|
+
/** The wrapper-level CSS inputs, replacing the backends' `stylesheets` field. */
|
|
54
|
+
type CssOptions = {
|
|
55
|
+
/** CSS to apply before rendering, one string or a list cascading in order. */
|
|
56
|
+
css?: CssInput | readonly CssInput[];
|
|
57
|
+
/**
|
|
58
|
+
* CSS stylesheets to apply before rendering.
|
|
59
|
+
* @deprecated Use `css` instead. Will be removed in v3.
|
|
60
|
+
*/
|
|
61
|
+
stylesheets?: string[];
|
|
62
|
+
};
|
|
63
|
+
type InnerRenderOptions = DistributiveOmit<napi.RenderOptions | wasm.RenderOptions, "images" | "css"> & CssOptions;
|
|
64
|
+
type InnerSvgRenderOptions = DistributiveOmit<napi.SvgRenderOptions | wasm.SvgRenderOptions, "images" | "css"> & CssOptions;
|
|
65
|
+
type InnerRenderAnimationOptions = DistributiveOmit<napi.RenderAnimationOptions | wasm.RenderAnimationOptions, "images" | "css"> & CssOptions;
|
|
56
66
|
type RenderOptions = Managed<InnerRenderOptions>;
|
|
57
67
|
type RenderSvgOptions = Managed<InnerSvgRenderOptions>;
|
|
58
68
|
/** A single animation scene whose content is any renderable input. */
|
|
@@ -57,7 +57,7 @@ function isTakumiNode(element) {
|
|
|
57
57
|
async function transformElement(element, options) {
|
|
58
58
|
if (isTakumiNode(element)) return {
|
|
59
59
|
node: element,
|
|
60
|
-
|
|
60
|
+
css: []
|
|
61
61
|
};
|
|
62
62
|
if (typeof element === "string") return fromHtml(element);
|
|
63
63
|
return fromJsx(element, options?.jsx);
|
|
@@ -70,11 +70,11 @@ async function resolveRenderer(options) {
|
|
|
70
70
|
}
|
|
71
71
|
/** Transforms an input into a node tree and extracts its emojis. */
|
|
72
72
|
async function resolveContent(element, options) {
|
|
73
|
-
const { node: originalNode,
|
|
73
|
+
const { node: originalNode, css } = await transformElement(element, options);
|
|
74
74
|
const emojiType = options?.emoji ?? "twemoji";
|
|
75
75
|
return {
|
|
76
76
|
node: emojiType !== "from-font" ? extractEmojis(originalNode, emojiType) : originalNode,
|
|
77
|
-
|
|
77
|
+
css
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
/** Resolves the render's `images` option into concrete entries via {@link prepareImages}. */
|
|
@@ -96,8 +96,20 @@ async function collectImages(node, options) {
|
|
|
96
96
|
cache: ("cache" in image ? image.cache : void 0) ?? cache
|
|
97
97
|
})) : prepared;
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
let warnedStylesheets = false;
|
|
100
|
+
function warnStylesheetsDeprecated() {
|
|
101
|
+
if (warnedStylesheets) return;
|
|
102
|
+
warnedStylesheets = true;
|
|
103
|
+
console.warn("takumi: the `stylesheets` option is deprecated, use `css` instead.");
|
|
104
|
+
}
|
|
105
|
+
/** Narrows the `css` option, which takes one entry or a list of them. */
|
|
106
|
+
function isCssList(css) {
|
|
107
|
+
return Array.isArray(css);
|
|
108
|
+
}
|
|
109
|
+
function mergeCss(options, extra) {
|
|
110
|
+
if (options?.css !== void 0 && options?.stylesheets !== void 0) throw new Error("pass either `css` or `stylesheets`, not both");
|
|
111
|
+
if (options?.stylesheets !== void 0) warnStylesheetsDeprecated();
|
|
112
|
+
return [...options?.css !== void 0 ? isCssList(options.css) ? options.css : [options.css] : options?.stylesheets ?? [], ...extra];
|
|
101
113
|
}
|
|
102
114
|
/**
|
|
103
115
|
* Renders a React element, HTML string, or Takumi node tree into an image.
|
|
@@ -122,13 +134,14 @@ function mergeStylesheets(options, extra) {
|
|
|
122
134
|
async function render(element, options) {
|
|
123
135
|
options?.signal?.throwIfAborted();
|
|
124
136
|
const renderer = await resolveRenderer(options);
|
|
125
|
-
const { node,
|
|
137
|
+
const { node, css: extractedCss } = await resolveContent(element, options);
|
|
126
138
|
const images = await collectImages(node, options);
|
|
127
139
|
options?.signal?.throwIfAborted();
|
|
140
|
+
const { css: _, stylesheets: _alias, ...forward } = options ?? {};
|
|
128
141
|
return renderer.render(node, {
|
|
129
|
-
...
|
|
142
|
+
...forward,
|
|
130
143
|
images,
|
|
131
|
-
|
|
144
|
+
css: mergeCss(options, extractedCss)
|
|
132
145
|
});
|
|
133
146
|
}
|
|
134
147
|
/**
|
|
@@ -154,13 +167,14 @@ async function render(element, options) {
|
|
|
154
167
|
async function renderSvg(element, options) {
|
|
155
168
|
options?.signal?.throwIfAborted();
|
|
156
169
|
const renderer = await resolveRenderer(options);
|
|
157
|
-
const { node,
|
|
170
|
+
const { node, css: extractedCss } = await resolveContent(element, options);
|
|
158
171
|
const images = await collectImages(node, options);
|
|
159
172
|
options?.signal?.throwIfAborted();
|
|
173
|
+
const { css: _, stylesheets: _alias, ...forward } = options ?? {};
|
|
160
174
|
return renderer.renderSvg(node, {
|
|
161
|
-
...
|
|
175
|
+
...forward,
|
|
162
176
|
images,
|
|
163
|
-
|
|
177
|
+
css: mergeCss(options, extractedCss)
|
|
164
178
|
});
|
|
165
179
|
}
|
|
166
180
|
/**
|
|
@@ -189,26 +203,27 @@ async function renderSvg(element, options) {
|
|
|
189
203
|
*/
|
|
190
204
|
async function renderAnimation(options) {
|
|
191
205
|
options.signal?.throwIfAborted();
|
|
206
|
+
const { css: _, stylesheets: _alias, ...forward } = options;
|
|
192
207
|
const renderer = await resolveRenderer(options);
|
|
193
208
|
const scenes = await Promise.all(options.scenes.map(async (scene) => {
|
|
194
|
-
const { node,
|
|
209
|
+
const { node, css } = await resolveContent(scene.node, options);
|
|
195
210
|
return {
|
|
196
211
|
node,
|
|
197
212
|
durationMs: scene.durationMs,
|
|
198
|
-
|
|
213
|
+
css
|
|
199
214
|
};
|
|
200
215
|
}));
|
|
201
216
|
const images = await collectImages(scenes.map((scene) => scene.node), options);
|
|
202
|
-
const
|
|
217
|
+
const css = mergeCss(options, scenes.flatMap((scene) => scene.css));
|
|
203
218
|
options.signal?.throwIfAborted();
|
|
204
219
|
return renderer.renderAnimation({
|
|
205
|
-
...
|
|
220
|
+
...forward,
|
|
206
221
|
scenes: scenes.map(({ node, durationMs }) => ({
|
|
207
222
|
node,
|
|
208
223
|
durationMs
|
|
209
224
|
})),
|
|
210
225
|
images,
|
|
211
|
-
|
|
226
|
+
css
|
|
212
227
|
});
|
|
213
228
|
}
|
|
214
229
|
//#endregion
|
|
@@ -38,7 +38,7 @@ let importPromise = null;
|
|
|
38
38
|
* Node target that can't load the native addon. A failed load clears the cache.
|
|
39
39
|
*/
|
|
40
40
|
function getImports(module) {
|
|
41
|
-
importPromise ??= (module === void 0 ? (0, _backend.loadBackend)() : Promise.resolve().then(() => require("./wasm-init-
|
|
41
|
+
importPromise ??= (module === void 0 ? (0, _backend.loadBackend)() : Promise.resolve().then(() => require("./wasm-init-Dl-su2Ub.cjs")).then((n) => n.wasm_init_exports).then(({ initWasm }) => initWasm(module))).then((backend) => {
|
|
42
42
|
applyGlyphCacheMaxBytes(backend);
|
|
43
43
|
return backend;
|
|
44
44
|
}).catch((error) => {
|
|
@@ -57,7 +57,7 @@ function isTakumiNode(element) {
|
|
|
57
57
|
async function transformElement(element, options) {
|
|
58
58
|
if (isTakumiNode(element)) return {
|
|
59
59
|
node: element,
|
|
60
|
-
|
|
60
|
+
css: []
|
|
61
61
|
};
|
|
62
62
|
if (typeof element === "string") return (0, _takumi_rs_helpers_html.fromHtml)(element);
|
|
63
63
|
return (0, _takumi_rs_helpers_jsx.fromJsx)(element, options?.jsx);
|
|
@@ -70,11 +70,11 @@ async function resolveRenderer(options) {
|
|
|
70
70
|
}
|
|
71
71
|
/** Transforms an input into a node tree and extracts its emojis. */
|
|
72
72
|
async function resolveContent(element, options) {
|
|
73
|
-
const { node: originalNode,
|
|
73
|
+
const { node: originalNode, css } = await transformElement(element, options);
|
|
74
74
|
const emojiType = options?.emoji ?? "twemoji";
|
|
75
75
|
return {
|
|
76
76
|
node: emojiType !== "from-font" ? (0, _takumi_rs_helpers_emoji.extractEmojis)(originalNode, emojiType) : originalNode,
|
|
77
|
-
|
|
77
|
+
css
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
/** Resolves the render's `images` option into concrete entries via {@link prepareImages}. */
|
|
@@ -96,8 +96,20 @@ async function collectImages(node, options) {
|
|
|
96
96
|
cache: ("cache" in image ? image.cache : void 0) ?? cache
|
|
97
97
|
})) : prepared;
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
let warnedStylesheets = false;
|
|
100
|
+
function warnStylesheetsDeprecated() {
|
|
101
|
+
if (warnedStylesheets) return;
|
|
102
|
+
warnedStylesheets = true;
|
|
103
|
+
console.warn("takumi: the `stylesheets` option is deprecated, use `css` instead.");
|
|
104
|
+
}
|
|
105
|
+
/** Narrows the `css` option, which takes one entry or a list of them. */
|
|
106
|
+
function isCssList(css) {
|
|
107
|
+
return Array.isArray(css);
|
|
108
|
+
}
|
|
109
|
+
function mergeCss(options, extra) {
|
|
110
|
+
if (options?.css !== void 0 && options?.stylesheets !== void 0) throw new Error("pass either `css` or `stylesheets`, not both");
|
|
111
|
+
if (options?.stylesheets !== void 0) warnStylesheetsDeprecated();
|
|
112
|
+
return [...options?.css !== void 0 ? isCssList(options.css) ? options.css : [options.css] : options?.stylesheets ?? [], ...extra];
|
|
101
113
|
}
|
|
102
114
|
/**
|
|
103
115
|
* Renders a React element, HTML string, or Takumi node tree into an image.
|
|
@@ -122,13 +134,14 @@ function mergeStylesheets(options, extra) {
|
|
|
122
134
|
async function render(element, options) {
|
|
123
135
|
options?.signal?.throwIfAborted();
|
|
124
136
|
const renderer = await resolveRenderer(options);
|
|
125
|
-
const { node,
|
|
137
|
+
const { node, css: extractedCss } = await resolveContent(element, options);
|
|
126
138
|
const images = await collectImages(node, options);
|
|
127
139
|
options?.signal?.throwIfAborted();
|
|
140
|
+
const { css: _, stylesheets: _alias, ...forward } = options ?? {};
|
|
128
141
|
return renderer.render(node, {
|
|
129
|
-
...
|
|
142
|
+
...forward,
|
|
130
143
|
images,
|
|
131
|
-
|
|
144
|
+
css: mergeCss(options, extractedCss)
|
|
132
145
|
});
|
|
133
146
|
}
|
|
134
147
|
/**
|
|
@@ -154,13 +167,14 @@ async function render(element, options) {
|
|
|
154
167
|
async function renderSvg(element, options) {
|
|
155
168
|
options?.signal?.throwIfAborted();
|
|
156
169
|
const renderer = await resolveRenderer(options);
|
|
157
|
-
const { node,
|
|
170
|
+
const { node, css: extractedCss } = await resolveContent(element, options);
|
|
158
171
|
const images = await collectImages(node, options);
|
|
159
172
|
options?.signal?.throwIfAborted();
|
|
173
|
+
const { css: _, stylesheets: _alias, ...forward } = options ?? {};
|
|
160
174
|
return renderer.renderSvg(node, {
|
|
161
|
-
...
|
|
175
|
+
...forward,
|
|
162
176
|
images,
|
|
163
|
-
|
|
177
|
+
css: mergeCss(options, extractedCss)
|
|
164
178
|
});
|
|
165
179
|
}
|
|
166
180
|
/**
|
|
@@ -189,26 +203,27 @@ async function renderSvg(element, options) {
|
|
|
189
203
|
*/
|
|
190
204
|
async function renderAnimation(options) {
|
|
191
205
|
options.signal?.throwIfAborted();
|
|
206
|
+
const { css: _, stylesheets: _alias, ...forward } = options;
|
|
192
207
|
const renderer = await resolveRenderer(options);
|
|
193
208
|
const scenes = await Promise.all(options.scenes.map(async (scene) => {
|
|
194
|
-
const { node,
|
|
209
|
+
const { node, css } = await resolveContent(scene.node, options);
|
|
195
210
|
return {
|
|
196
211
|
node,
|
|
197
212
|
durationMs: scene.durationMs,
|
|
198
|
-
|
|
213
|
+
css
|
|
199
214
|
};
|
|
200
215
|
}));
|
|
201
216
|
const images = await collectImages(scenes.map((scene) => scene.node), options);
|
|
202
|
-
const
|
|
217
|
+
const css = mergeCss(options, scenes.flatMap((scene) => scene.css));
|
|
203
218
|
options.signal?.throwIfAborted();
|
|
204
219
|
return renderer.renderAnimation({
|
|
205
|
-
...
|
|
220
|
+
...forward,
|
|
206
221
|
scenes: scenes.map(({ node, durationMs }) => ({
|
|
207
222
|
node,
|
|
208
223
|
durationMs
|
|
209
224
|
})),
|
|
210
225
|
images,
|
|
211
|
-
|
|
226
|
+
css
|
|
212
227
|
});
|
|
213
228
|
}
|
|
214
229
|
//#endregion
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { EmojiType } from "@takumi-rs/helpers/emoji";
|
|
2
|
-
import { FetchOptions, ImageFetchCache, Node, ReactElementLike } from "@takumi-rs/helpers";
|
|
3
|
-
import { FromJsxOptions } from "@takumi-rs/helpers/jsx";
|
|
4
1
|
import * as napi from "@takumi-rs/core";
|
|
5
2
|
import * as wasm from "@takumi-rs/wasm";
|
|
3
|
+
import { EmojiType } from "@takumi-rs/helpers/emoji";
|
|
4
|
+
import { CssInput, FetchOptions, ImageFetchCache, Node, ReactElementLike } from "@takumi-rs/helpers";
|
|
5
|
+
import { FromJsxOptions } from "@takumi-rs/helpers/jsx";
|
|
6
6
|
import { ReactNode } from "react";
|
|
7
7
|
//#region src/render.d.ts
|
|
8
8
|
type Renderer = napi.Renderer | wasm.Renderer;
|
|
@@ -50,9 +50,19 @@ type Managed<TInner> = (TInner & SharedRenderExtras) | (TInner & Omit<SharedRend
|
|
|
50
50
|
* tagged union survives instead of collapsing into one flat member.
|
|
51
51
|
*/
|
|
52
52
|
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
53
|
-
|
|
54
|
-
type
|
|
55
|
-
|
|
53
|
+
/** The wrapper-level CSS inputs, replacing the backends' `stylesheets` field. */
|
|
54
|
+
type CssOptions = {
|
|
55
|
+
/** CSS to apply before rendering, one string or a list cascading in order. */
|
|
56
|
+
css?: CssInput | readonly CssInput[];
|
|
57
|
+
/**
|
|
58
|
+
* CSS stylesheets to apply before rendering.
|
|
59
|
+
* @deprecated Use `css` instead. Will be removed in v3.
|
|
60
|
+
*/
|
|
61
|
+
stylesheets?: string[];
|
|
62
|
+
};
|
|
63
|
+
type InnerRenderOptions = DistributiveOmit<napi.RenderOptions | wasm.RenderOptions, "images" | "css"> & CssOptions;
|
|
64
|
+
type InnerSvgRenderOptions = DistributiveOmit<napi.SvgRenderOptions | wasm.SvgRenderOptions, "images" | "css"> & CssOptions;
|
|
65
|
+
type InnerRenderAnimationOptions = DistributiveOmit<napi.RenderAnimationOptions | wasm.RenderAnimationOptions, "images" | "css"> & CssOptions;
|
|
56
66
|
type RenderOptions = Managed<InnerRenderOptions>;
|
|
57
67
|
type RenderSvgOptions = Managed<InnerSvgRenderOptions>;
|
|
58
68
|
/** A single animation scene whose content is any renderable input. */
|
package/dist/response.cjs
CHANGED
|
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_render = require("./render-
|
|
5
|
+
const require_render = require("./render-C7kRwHMk.cjs");
|
|
6
6
|
//#region src/response/index.ts
|
|
7
7
|
const contentTypeMap = {
|
|
8
8
|
png: "image/png",
|
package/dist/response.d.cts
CHANGED
package/dist/response.d.mts
CHANGED
package/dist/response.mjs
CHANGED
|
@@ -24,7 +24,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
}
|
|
25
25
|
return to;
|
|
26
26
|
};
|
|
27
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
27
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
28
28
|
value: mod,
|
|
29
29
|
enumerable: true
|
|
30
30
|
}) : target, mod));
|
package/dist/wasm/no-init.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_rolldown_runtime = require("../rolldown-runtime-
|
|
2
|
+
const require_rolldown_runtime = require("../rolldown-runtime-C0BPl7ul.cjs");
|
|
3
3
|
let _takumi_rs_wasm = require("@takumi-rs/wasm");
|
|
4
4
|
_takumi_rs_wasm = require_rolldown_runtime.__toESM(_takumi_rs_wasm, 1);
|
|
5
5
|
Object.defineProperty(exports, "init", {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_rolldown_runtime = require("./rolldown-runtime-
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
2
2
|
let _takumi_rs_wasm = require("@takumi-rs/wasm");
|
|
3
3
|
_takumi_rs_wasm = require_rolldown_runtime.__toESM(_takumi_rs_wasm, 1);
|
|
4
4
|
//#region src/backend/wasm-init.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_rolldown_runtime = require("./rolldown-runtime-
|
|
2
|
-
const require_wasm_init = require("./wasm-init-
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
2
|
+
const require_wasm_init = require("./wasm-init-Dl-su2Ub.cjs");
|
|
3
3
|
let _takumi_rs_wasm_node = require("@takumi-rs/wasm/node");
|
|
4
4
|
_takumi_rs_wasm_node = require_rolldown_runtime.__toESM(_takumi_rs_wasm_node, 1);
|
|
5
5
|
//#region src/backend/wasm-node.ts
|
package/dist/wasm.cjs
CHANGED
|
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_rolldown_runtime = require("./rolldown-runtime-
|
|
5
|
+
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
6
6
|
let _takumi_rs_wasm_auto = require("@takumi-rs/wasm/auto");
|
|
7
7
|
_takumi_rs_wasm_auto = require_rolldown_runtime.__toESM(_takumi_rs_wasm_auto, 1);
|
|
8
8
|
let _takumi_rs_wasm = require("@takumi-rs/wasm");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "takumi-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13.0",
|
|
4
4
|
"description": "Render OG images from JSX, HTML, and CSS. No headless browser.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"animated-webp",
|
|
@@ -238,12 +238,12 @@
|
|
|
238
238
|
"publish-lint": "attw --pack . && publint --strict ."
|
|
239
239
|
},
|
|
240
240
|
"dependencies": {
|
|
241
|
-
"@takumi-rs/core": "2.
|
|
242
|
-
"@takumi-rs/helpers": "2.
|
|
243
|
-
"@takumi-rs/wasm": "2.
|
|
241
|
+
"@takumi-rs/core": "2.13.0",
|
|
242
|
+
"@takumi-rs/helpers": "2.13.0",
|
|
243
|
+
"@takumi-rs/wasm": "2.13.0"
|
|
244
244
|
},
|
|
245
245
|
"devDependencies": {
|
|
246
|
-
"@types/bun": "^1.
|
|
246
|
+
"@types/bun": "^1.4.0",
|
|
247
247
|
"@types/react": "19.2.18",
|
|
248
248
|
"react": "^19.2.8",
|
|
249
249
|
"tsdown": "0.22.14",
|