@takumi-rs/wasm 2.0.0-rc.11 → 2.0.0-rc.13
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/README.md +45 -3
- package/dist/export.cjs +10 -56
- package/dist/export.d.cts +7 -20
- package/dist/export.d.mts +7 -20
- package/dist/export.mjs +11 -57
- package/package.json +2 -3
- package/pkg/takumi_wasm_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -1,7 +1,49 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://takumi.kane.tw/logo.svg" alt="Takumi" width="64" />
|
|
3
|
+
|
|
1
4
|
# @takumi-rs/wasm
|
|
2
5
|
|
|
3
|
-
WebAssembly bindings for [Takumi](https://github.com/kane50613/takumi), a Rust image rendering engine
|
|
6
|
+
**WebAssembly bindings for [Takumi](https://github.com/kane50613/takumi), a Rust image rendering engine.**
|
|
7
|
+
Render OG cards, banners, and animations on Cloudflare Workers, edge runtimes, and browsers, no headless browser required.
|
|
8
|
+
|
|
9
|
+
[Documentation](https://takumi.kane.tw/docs/) · [Playground](https://takumi.kane.tw/playground)
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @takumi-rs/wasm
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import init, { Renderer } from "@takumi-rs/wasm";
|
|
23
|
+
|
|
24
|
+
await init();
|
|
25
|
+
|
|
26
|
+
const renderer = new Renderer();
|
|
27
|
+
|
|
28
|
+
const png = await renderer.render(
|
|
29
|
+
{
|
|
30
|
+
type: "container",
|
|
31
|
+
children: [{ type: "text", text: "Hello from Takumi" }],
|
|
32
|
+
},
|
|
33
|
+
{ width: 1200, height: 630 },
|
|
34
|
+
);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Call `init()` once to load the WASM binary, then reuse the `Renderer`. Build node trees by hand, or generate them from JSX and HTML with [`@takumi-rs/helpers`](https://npmjs.com/package/@takumi-rs/helpers).
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
- Integration guide: <https://takumi.kane.tw/docs/integration>
|
|
42
|
+
- API reference: <https://takumi.kane.tw/docs/api-reference>
|
|
43
|
+
- Repository: <https://github.com/kane50613/takumi>
|
|
44
|
+
|
|
45
|
+
For Node.js, use the native [@takumi-rs/core](https://npmjs.com/package/@takumi-rs/core) bindings.
|
|
4
46
|
|
|
5
|
-
|
|
47
|
+
## License
|
|
6
48
|
|
|
7
|
-
|
|
49
|
+
MIT or Apache-2.0
|
package/dist/export.cjs
CHANGED
|
@@ -2,7 +2,6 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
let _takumi_rs_helpers = require("@takumi-rs/helpers");
|
|
6
5
|
let _takumi_rs_helpers_renderer = require("@takumi-rs/helpers/renderer");
|
|
7
6
|
//#region pkg/takumi_wasm.js
|
|
8
7
|
/**
|
|
@@ -522,70 +521,25 @@ var Renderer = class {
|
|
|
522
521
|
inner = new Renderer$1();
|
|
523
522
|
fonts = new _takumi_rs_helpers_renderer.FontRegistry((font) => this.inner.registerFont(font));
|
|
524
523
|
async render(node, options) {
|
|
525
|
-
const {
|
|
526
|
-
|
|
527
|
-
const resolved = await this.fonts.resolveResources(fonts && (0, _takumi_rs_helpers.subsetFonts)({
|
|
528
|
-
fonts,
|
|
529
|
-
source: node
|
|
530
|
-
}), images, fontFamilies);
|
|
531
|
-
signal?.throwIfAborted();
|
|
532
|
-
return this.inner.render(node, {
|
|
533
|
-
...rest,
|
|
534
|
-
...resolved
|
|
535
|
-
});
|
|
524
|
+
const { options: opts } = await (0, _takumi_rs_helpers_renderer.prepareRenderInput)(this.fonts, options ?? {}, node);
|
|
525
|
+
return this.inner.render(node, opts);
|
|
536
526
|
}
|
|
537
527
|
async renderAsDataUrl(node, options) {
|
|
538
|
-
const {
|
|
539
|
-
|
|
540
|
-
const resolved = await this.fonts.resolveResources(fonts && (0, _takumi_rs_helpers.subsetFonts)({
|
|
541
|
-
fonts,
|
|
542
|
-
source: node
|
|
543
|
-
}), images, fontFamilies);
|
|
544
|
-
signal?.throwIfAborted();
|
|
545
|
-
return this.inner.renderAsDataUrl(node, {
|
|
546
|
-
...rest,
|
|
547
|
-
...resolved
|
|
548
|
-
});
|
|
528
|
+
const { options: opts } = await (0, _takumi_rs_helpers_renderer.prepareRenderInput)(this.fonts, options ?? {}, node);
|
|
529
|
+
return this.inner.renderAsDataUrl(node, opts);
|
|
549
530
|
}
|
|
550
531
|
async renderSvg(node, options) {
|
|
551
|
-
const {
|
|
552
|
-
|
|
553
|
-
const resolved = await this.fonts.resolveResources(fonts && (0, _takumi_rs_helpers.subsetFonts)({
|
|
554
|
-
fonts,
|
|
555
|
-
source: node
|
|
556
|
-
}), images, fontFamilies);
|
|
557
|
-
signal?.throwIfAborted();
|
|
558
|
-
return this.inner.renderSvg(node, {
|
|
559
|
-
...rest,
|
|
560
|
-
...resolved
|
|
561
|
-
});
|
|
532
|
+
const { options: opts } = await (0, _takumi_rs_helpers_renderer.prepareRenderInput)(this.fonts, options ?? {}, node);
|
|
533
|
+
return this.inner.renderSvg(node, opts);
|
|
562
534
|
}
|
|
563
535
|
async measure(node, options) {
|
|
564
|
-
const {
|
|
565
|
-
|
|
566
|
-
const resolved = await this.fonts.resolveResources(fonts && (0, _takumi_rs_helpers.subsetFonts)({
|
|
567
|
-
fonts,
|
|
568
|
-
source: node
|
|
569
|
-
}), images, fontFamilies);
|
|
570
|
-
signal?.throwIfAborted();
|
|
571
|
-
return this.inner.measure(node, {
|
|
572
|
-
...rest,
|
|
573
|
-
...resolved
|
|
574
|
-
});
|
|
536
|
+
const { options: opts } = await (0, _takumi_rs_helpers_renderer.prepareRenderInput)(this.fonts, options ?? {}, node);
|
|
537
|
+
return this.inner.measure(node, opts);
|
|
575
538
|
}
|
|
576
539
|
async renderAnimation(options) {
|
|
577
|
-
const { fonts, fontFamilies, signal, images, ...rest } = options;
|
|
578
|
-
signal?.throwIfAborted();
|
|
579
540
|
const nodes = options.scenes.map((scene) => scene.node);
|
|
580
|
-
const
|
|
581
|
-
|
|
582
|
-
source: nodes
|
|
583
|
-
}), images, fontFamilies);
|
|
584
|
-
signal?.throwIfAborted();
|
|
585
|
-
return this.inner.renderAnimation({
|
|
586
|
-
...rest,
|
|
587
|
-
...resolved
|
|
588
|
-
});
|
|
541
|
+
const { options: opts } = await (0, _takumi_rs_helpers_renderer.prepareRenderInput)(this.fonts, options, nodes);
|
|
542
|
+
return this.inner.renderAnimation(opts);
|
|
589
543
|
}
|
|
590
544
|
registerFont(font) {
|
|
591
545
|
return this.fonts.register(font);
|
package/dist/export.d.cts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { ContainerNode, ImageNode, Node, Node as Node$1, NodeMetadata, TextNode } from "@takumi-rs/helpers";
|
|
2
|
-
import {
|
|
3
|
-
import { AnimationOutputFormatOptions, AnimationOutputFormatOptions as AnimationOutputFormatOptions$1, FontLoader, FontLoader as FontLoader$1, ImageLoader, ImagesInput, ImagesInput as ImagesInput$1, OutputFormatOptions, OutputFormatOptions as OutputFormatOptions$1 } from "@takumi-rs/helpers/renderer";
|
|
2
|
+
import { AnimationOutputFormatOptions, BackendAnimationOptions, BackendRenderOptions, BackendSvgOptions, FontLoader, FontLoader as FontLoader$1, ImageLoader, ImagesInput, OutputFormatOptions } from "@takumi-rs/helpers/renderer";
|
|
4
3
|
|
|
5
4
|
//#region pkg/takumi_wasm.d.ts
|
|
6
5
|
type ByteBuf = Uint8Array | ArrayBuffer | Buffer;
|
|
7
|
-
type KeyframesMap = Record<string, Record<string,
|
|
6
|
+
type KeyframesMap = Record<string, Record<string, CSSStyleDeclaration>>;
|
|
8
7
|
type KeyframesRuleList = {
|
|
9
8
|
name: string;
|
|
10
9
|
keyframes: {
|
|
11
10
|
offsets: number[];
|
|
12
|
-
declarations: Record<string,
|
|
11
|
+
declarations: Record<string, CSSStyleDeclaration>;
|
|
13
12
|
}[];
|
|
14
13
|
}[];
|
|
15
14
|
type Keyframes = KeyframesMap | KeyframesRuleList;
|
|
@@ -151,7 +150,7 @@ type ImageSource = {
|
|
|
151
150
|
};
|
|
152
151
|
type KeyframeRule = {
|
|
153
152
|
offsets: number[];
|
|
154
|
-
declarations: Record<string,
|
|
153
|
+
declarations: Record<string, CSSStyleDeclaration>;
|
|
155
154
|
};
|
|
156
155
|
type KeyframesRule = {
|
|
157
156
|
name: string;
|
|
@@ -231,21 +230,9 @@ declare function __wbg_init(module_or_path?: {
|
|
|
231
230
|
} | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
232
231
|
//#endregion
|
|
233
232
|
//#region src/export.d.ts
|
|
234
|
-
type RenderOptions =
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
images?: ImagesInput$1;
|
|
238
|
-
};
|
|
239
|
-
type RenderAnimationOptions = Omit<RenderAnimationOptions$1, "images" | "format" | "quality" | "lossless"> & AnimationOutputFormatOptions$1 & {
|
|
240
|
-
fonts?: FontLoader$1[];
|
|
241
|
-
signal?: AbortSignal;
|
|
242
|
-
images?: ImagesInput$1;
|
|
243
|
-
};
|
|
244
|
-
type SvgRenderOptions = Omit<SvgRenderOptions$1, "images"> & {
|
|
245
|
-
fonts?: FontLoader$1[];
|
|
246
|
-
signal?: AbortSignal;
|
|
247
|
-
images?: ImagesInput$1;
|
|
248
|
-
};
|
|
233
|
+
type RenderOptions = BackendRenderOptions<RenderOptions$1>;
|
|
234
|
+
type RenderAnimationOptions = BackendAnimationOptions<RenderAnimationOptions$1>;
|
|
235
|
+
type SvgRenderOptions = BackendSvgOptions<SvgRenderOptions$1>;
|
|
249
236
|
declare class Renderer {
|
|
250
237
|
private inner;
|
|
251
238
|
private fonts;
|
package/dist/export.d.mts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
+
import { AnimationOutputFormatOptions, BackendAnimationOptions, BackendRenderOptions, BackendSvgOptions, FontLoader, FontLoader as FontLoader$1, ImageLoader, ImagesInput, OutputFormatOptions } from "@takumi-rs/helpers/renderer";
|
|
1
2
|
import { ContainerNode, ImageNode, Node, Node as Node$1, NodeMetadata, TextNode } from "@takumi-rs/helpers";
|
|
2
|
-
import { AnimationOutputFormatOptions, AnimationOutputFormatOptions as AnimationOutputFormatOptions$1, FontLoader, FontLoader as FontLoader$1, ImageLoader, ImagesInput, ImagesInput as ImagesInput$1, OutputFormatOptions, OutputFormatOptions as OutputFormatOptions$1 } from "@takumi-rs/helpers/renderer";
|
|
3
|
-
import { Properties } from "csstype";
|
|
4
3
|
|
|
5
4
|
//#region pkg/takumi_wasm.d.ts
|
|
6
5
|
type ByteBuf = Uint8Array | ArrayBuffer | Buffer;
|
|
7
|
-
type KeyframesMap = Record<string, Record<string,
|
|
6
|
+
type KeyframesMap = Record<string, Record<string, CSSStyleDeclaration>>;
|
|
8
7
|
type KeyframesRuleList = {
|
|
9
8
|
name: string;
|
|
10
9
|
keyframes: {
|
|
11
10
|
offsets: number[];
|
|
12
|
-
declarations: Record<string,
|
|
11
|
+
declarations: Record<string, CSSStyleDeclaration>;
|
|
13
12
|
}[];
|
|
14
13
|
}[];
|
|
15
14
|
type Keyframes = KeyframesMap | KeyframesRuleList;
|
|
@@ -151,7 +150,7 @@ type ImageSource = {
|
|
|
151
150
|
};
|
|
152
151
|
type KeyframeRule = {
|
|
153
152
|
offsets: number[];
|
|
154
|
-
declarations: Record<string,
|
|
153
|
+
declarations: Record<string, CSSStyleDeclaration>;
|
|
155
154
|
};
|
|
156
155
|
type KeyframesRule = {
|
|
157
156
|
name: string;
|
|
@@ -231,21 +230,9 @@ declare function __wbg_init(module_or_path?: {
|
|
|
231
230
|
} | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
232
231
|
//#endregion
|
|
233
232
|
//#region src/export.d.ts
|
|
234
|
-
type RenderOptions =
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
images?: ImagesInput$1;
|
|
238
|
-
};
|
|
239
|
-
type RenderAnimationOptions = Omit<RenderAnimationOptions$1, "images" | "format" | "quality" | "lossless"> & AnimationOutputFormatOptions$1 & {
|
|
240
|
-
fonts?: FontLoader$1[];
|
|
241
|
-
signal?: AbortSignal;
|
|
242
|
-
images?: ImagesInput$1;
|
|
243
|
-
};
|
|
244
|
-
type SvgRenderOptions = Omit<SvgRenderOptions$1, "images"> & {
|
|
245
|
-
fonts?: FontLoader$1[];
|
|
246
|
-
signal?: AbortSignal;
|
|
247
|
-
images?: ImagesInput$1;
|
|
248
|
-
};
|
|
233
|
+
type RenderOptions = BackendRenderOptions<RenderOptions$1>;
|
|
234
|
+
type RenderAnimationOptions = BackendAnimationOptions<RenderAnimationOptions$1>;
|
|
235
|
+
type SvgRenderOptions = BackendSvgOptions<SvgRenderOptions$1>;
|
|
249
236
|
declare class Renderer {
|
|
250
237
|
private inner;
|
|
251
238
|
private fonts;
|
package/dist/export.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FontRegistry } from "@takumi-rs/helpers/renderer";
|
|
1
|
+
import { FontRegistry, prepareRenderInput } from "@takumi-rs/helpers/renderer";
|
|
3
2
|
//#region pkg/takumi_wasm.js
|
|
4
3
|
/**
|
|
5
4
|
* The main renderer for Takumi image rendering engine.
|
|
@@ -518,70 +517,25 @@ var Renderer = class {
|
|
|
518
517
|
inner = new Renderer$1();
|
|
519
518
|
fonts = new FontRegistry((font) => this.inner.registerFont(font));
|
|
520
519
|
async render(node, options) {
|
|
521
|
-
const {
|
|
522
|
-
|
|
523
|
-
const resolved = await this.fonts.resolveResources(fonts && subsetFonts({
|
|
524
|
-
fonts,
|
|
525
|
-
source: node
|
|
526
|
-
}), images, fontFamilies);
|
|
527
|
-
signal?.throwIfAborted();
|
|
528
|
-
return this.inner.render(node, {
|
|
529
|
-
...rest,
|
|
530
|
-
...resolved
|
|
531
|
-
});
|
|
520
|
+
const { options: opts } = await prepareRenderInput(this.fonts, options ?? {}, node);
|
|
521
|
+
return this.inner.render(node, opts);
|
|
532
522
|
}
|
|
533
523
|
async renderAsDataUrl(node, options) {
|
|
534
|
-
const {
|
|
535
|
-
|
|
536
|
-
const resolved = await this.fonts.resolveResources(fonts && subsetFonts({
|
|
537
|
-
fonts,
|
|
538
|
-
source: node
|
|
539
|
-
}), images, fontFamilies);
|
|
540
|
-
signal?.throwIfAborted();
|
|
541
|
-
return this.inner.renderAsDataUrl(node, {
|
|
542
|
-
...rest,
|
|
543
|
-
...resolved
|
|
544
|
-
});
|
|
524
|
+
const { options: opts } = await prepareRenderInput(this.fonts, options ?? {}, node);
|
|
525
|
+
return this.inner.renderAsDataUrl(node, opts);
|
|
545
526
|
}
|
|
546
527
|
async renderSvg(node, options) {
|
|
547
|
-
const {
|
|
548
|
-
|
|
549
|
-
const resolved = await this.fonts.resolveResources(fonts && subsetFonts({
|
|
550
|
-
fonts,
|
|
551
|
-
source: node
|
|
552
|
-
}), images, fontFamilies);
|
|
553
|
-
signal?.throwIfAborted();
|
|
554
|
-
return this.inner.renderSvg(node, {
|
|
555
|
-
...rest,
|
|
556
|
-
...resolved
|
|
557
|
-
});
|
|
528
|
+
const { options: opts } = await prepareRenderInput(this.fonts, options ?? {}, node);
|
|
529
|
+
return this.inner.renderSvg(node, opts);
|
|
558
530
|
}
|
|
559
531
|
async measure(node, options) {
|
|
560
|
-
const {
|
|
561
|
-
|
|
562
|
-
const resolved = await this.fonts.resolveResources(fonts && subsetFonts({
|
|
563
|
-
fonts,
|
|
564
|
-
source: node
|
|
565
|
-
}), images, fontFamilies);
|
|
566
|
-
signal?.throwIfAborted();
|
|
567
|
-
return this.inner.measure(node, {
|
|
568
|
-
...rest,
|
|
569
|
-
...resolved
|
|
570
|
-
});
|
|
532
|
+
const { options: opts } = await prepareRenderInput(this.fonts, options ?? {}, node);
|
|
533
|
+
return this.inner.measure(node, opts);
|
|
571
534
|
}
|
|
572
535
|
async renderAnimation(options) {
|
|
573
|
-
const { fonts, fontFamilies, signal, images, ...rest } = options;
|
|
574
|
-
signal?.throwIfAborted();
|
|
575
536
|
const nodes = options.scenes.map((scene) => scene.node);
|
|
576
|
-
const
|
|
577
|
-
|
|
578
|
-
source: nodes
|
|
579
|
-
}), images, fontFamilies);
|
|
580
|
-
signal?.throwIfAborted();
|
|
581
|
-
return this.inner.renderAnimation({
|
|
582
|
-
...rest,
|
|
583
|
-
...resolved
|
|
584
|
-
});
|
|
537
|
+
const { options: opts } = await prepareRenderInput(this.fonts, options, nodes);
|
|
538
|
+
return this.inner.renderAnimation(opts);
|
|
585
539
|
}
|
|
586
540
|
registerFont(font) {
|
|
587
541
|
return this.fonts.register(font);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takumi-rs/wasm",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.13",
|
|
4
4
|
"description": "WebAssembly bindings for Takumi, a Rust image rendering engine.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css",
|
|
@@ -117,8 +117,7 @@
|
|
|
117
117
|
"publish-lint": "attw --pack . && publint --strict ."
|
|
118
118
|
},
|
|
119
119
|
"dependencies": {
|
|
120
|
-
"@takumi-rs/helpers": "2.0.0-rc.
|
|
121
|
-
"csstype": "^3.2.3"
|
|
120
|
+
"@takumi-rs/helpers": "2.0.0-rc.13"
|
|
122
121
|
},
|
|
123
122
|
"devDependencies": {
|
|
124
123
|
"@types/bun": "^1.3.14",
|
package/pkg/takumi_wasm_bg.wasm
CHANGED
|
Binary file
|