@takumi-rs/wasm 2.0.0-rc.2 → 2.0.0-rc.4
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 +19 -24
- package/dist/export.d.cts +12 -10
- package/dist/export.d.mts +12 -10
- package/dist/export.mjs +21 -25
- package/package.json +1 -1
- package/pkg/takumi_wasm_bg.wasm +0 -0
package/dist/export.cjs
CHANGED
|
@@ -518,12 +518,13 @@ async function __wbg_init(module_or_path) {
|
|
|
518
518
|
//#endregion
|
|
519
519
|
//#region src/export.ts
|
|
520
520
|
async function resolveImageLoaders(images) {
|
|
521
|
+
const { sources = [], cache } = Array.isArray(images) ? { sources: images } : images;
|
|
521
522
|
const bySrc = /* @__PURE__ */ new Map();
|
|
522
|
-
for (const image of
|
|
523
|
-
return Promise.all([...bySrc.values()].map(async ({ src, data, cache }) => ({
|
|
523
|
+
for (const image of sources) bySrc.set(image.src, image);
|
|
524
|
+
return Promise.all([...bySrc.values()].map(async ({ src, data, cache: own }) => ({
|
|
524
525
|
src,
|
|
525
526
|
data: typeof data === "function" ? await data() : data,
|
|
526
|
-
cache
|
|
527
|
+
cache: own ?? cache
|
|
527
528
|
})));
|
|
528
529
|
}
|
|
529
530
|
var Renderer = class {
|
|
@@ -547,11 +548,10 @@ var Renderer = class {
|
|
|
547
548
|
return [...new Set(families.flat().map((f) => f.name))];
|
|
548
549
|
}
|
|
549
550
|
async render(node, options) {
|
|
550
|
-
const { fonts, fontFamilies, images,
|
|
551
|
-
const registeredFamilies = await this.prepareFonts((0, _takumi_rs_helpers.
|
|
551
|
+
const { fonts, fontFamilies, images, ...rest } = options ?? {};
|
|
552
|
+
const registeredFamilies = await this.prepareFonts(fonts && (0, _takumi_rs_helpers.subsetFonts)({
|
|
552
553
|
fonts,
|
|
553
|
-
source: node
|
|
554
|
-
subset
|
|
554
|
+
source: node
|
|
555
555
|
}));
|
|
556
556
|
const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
|
|
557
557
|
return this.inner.render(node, {
|
|
@@ -561,11 +561,10 @@ var Renderer = class {
|
|
|
561
561
|
});
|
|
562
562
|
}
|
|
563
563
|
async renderAsDataUrl(node, options) {
|
|
564
|
-
const { fonts, fontFamilies, images,
|
|
565
|
-
const registeredFamilies = await this.prepareFonts((0, _takumi_rs_helpers.
|
|
564
|
+
const { fonts, fontFamilies, images, ...rest } = options ?? {};
|
|
565
|
+
const registeredFamilies = await this.prepareFonts(fonts && (0, _takumi_rs_helpers.subsetFonts)({
|
|
566
566
|
fonts,
|
|
567
|
-
source: node
|
|
568
|
-
subset
|
|
567
|
+
source: node
|
|
569
568
|
}));
|
|
570
569
|
const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
|
|
571
570
|
return this.inner.renderAsDataUrl(node, {
|
|
@@ -575,11 +574,10 @@ var Renderer = class {
|
|
|
575
574
|
});
|
|
576
575
|
}
|
|
577
576
|
async renderSvg(node, options) {
|
|
578
|
-
const { fonts, fontFamilies, images,
|
|
579
|
-
const registeredFamilies = await this.prepareFonts((0, _takumi_rs_helpers.
|
|
577
|
+
const { fonts, fontFamilies, images, ...rest } = options ?? {};
|
|
578
|
+
const registeredFamilies = await this.prepareFonts(fonts && (0, _takumi_rs_helpers.subsetFonts)({
|
|
580
579
|
fonts,
|
|
581
|
-
source: node
|
|
582
|
-
subset
|
|
580
|
+
source: node
|
|
583
581
|
}));
|
|
584
582
|
const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
|
|
585
583
|
return this.inner.renderSvg(node, {
|
|
@@ -589,11 +587,10 @@ var Renderer = class {
|
|
|
589
587
|
});
|
|
590
588
|
}
|
|
591
589
|
async measure(node, options) {
|
|
592
|
-
const { fonts, fontFamilies, images,
|
|
593
|
-
const registeredFamilies = await this.prepareFonts((0, _takumi_rs_helpers.
|
|
590
|
+
const { fonts, fontFamilies, images, ...rest } = options ?? {};
|
|
591
|
+
const registeredFamilies = await this.prepareFonts(fonts && (0, _takumi_rs_helpers.subsetFonts)({
|
|
594
592
|
fonts,
|
|
595
|
-
source: node
|
|
596
|
-
subset
|
|
593
|
+
source: node
|
|
597
594
|
}));
|
|
598
595
|
const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
|
|
599
596
|
return this.inner.measure(node, {
|
|
@@ -603,12 +600,11 @@ var Renderer = class {
|
|
|
603
600
|
});
|
|
604
601
|
}
|
|
605
602
|
async renderAnimation(options) {
|
|
606
|
-
const { fonts, fontFamilies, images,
|
|
603
|
+
const { fonts, fontFamilies, images, ...rest } = options;
|
|
607
604
|
const nodes = options.scenes.map((scene) => scene.node);
|
|
608
|
-
const registeredFamilies = await this.prepareFonts((0, _takumi_rs_helpers.
|
|
605
|
+
const registeredFamilies = await this.prepareFonts(fonts && (0, _takumi_rs_helpers.subsetFonts)({
|
|
609
606
|
fonts,
|
|
610
|
-
source: nodes
|
|
611
|
-
subset
|
|
607
|
+
source: nodes
|
|
612
608
|
}));
|
|
613
609
|
const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
|
|
614
610
|
return this.inner.renderAnimation({
|
|
@@ -660,5 +656,4 @@ function isBuffer(data) {
|
|
|
660
656
|
//#endregion
|
|
661
657
|
exports.Renderer = Renderer;
|
|
662
658
|
exports.default = __wbg_init;
|
|
663
|
-
exports.extractResourceUrls = _takumi_rs_helpers.extractResourceUrls;
|
|
664
659
|
exports.initSync = initSync;
|
package/dist/export.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContainerNode, ImageNode, Node, Node as Node$1, NodeMetadata, TextNode
|
|
1
|
+
import { ContainerNode, ImageNode, Node, Node as Node$1, NodeMetadata, TextNode } from "@takumi-rs/helpers";
|
|
2
2
|
import { Properties } from "csstype";
|
|
3
3
|
|
|
4
4
|
//#region pkg/takumi_wasm.d.ts
|
|
@@ -72,7 +72,7 @@ type RenderOptions$1 = {
|
|
|
72
72
|
*/
|
|
73
73
|
type SvgRenderOptions$1 = Omit<RenderOptions$1, "format" | "quality" | "drawDebugBorder" | "devicePixelRatio" | "dithering">;
|
|
74
74
|
type RenderAnimationOptions$1 = {
|
|
75
|
-
scenes:
|
|
75
|
+
scenes: AnimationScene[];
|
|
76
76
|
width: number;
|
|
77
77
|
height: number;
|
|
78
78
|
format?: "webp" | "apng" | "gif";
|
|
@@ -155,7 +155,7 @@ type MeasuredNode = {
|
|
|
155
155
|
children: MeasuredNode[];
|
|
156
156
|
runs: MeasuredTextRun[];
|
|
157
157
|
};
|
|
158
|
-
type
|
|
158
|
+
type AnimationScene = {
|
|
159
159
|
node: Node$1;
|
|
160
160
|
durationMs: number;
|
|
161
161
|
};
|
|
@@ -220,6 +220,11 @@ type ImageLoaderData = ImageSource["data"];
|
|
|
220
220
|
type ImageLoader = Omit<ImageSource, "data"> & {
|
|
221
221
|
data: ImageLoaderData | (() => ImageLoaderData | Promise<ImageLoaderData>);
|
|
222
222
|
};
|
|
223
|
+
/** Images for a render: pre-fetched entries, or a group with a decode-cache default. */
|
|
224
|
+
type ImagesInput = ImageLoader[] | {
|
|
225
|
+
/** Pre-fetched entries, same as the array form. */sources?: ImageLoader[]; /** Decode-cache default for every image this render; a source's own `cache` wins. */
|
|
226
|
+
cache?: NonNullable<ImageLoader["cache"]>;
|
|
227
|
+
};
|
|
223
228
|
/**
|
|
224
229
|
* Output format. Format-specific options live on the variant that supports them,
|
|
225
230
|
* so `quality` cannot be paired with a lossless format. On wasm, WebP is always
|
|
@@ -239,8 +244,7 @@ type OutputFormatOptions = {
|
|
|
239
244
|
};
|
|
240
245
|
type RenderOptions = Omit<RenderOptions$1, "images" | "format" | "quality"> & OutputFormatOptions & {
|
|
241
246
|
fonts?: FontLoader[];
|
|
242
|
-
images?:
|
|
243
|
-
subset?: boolean;
|
|
247
|
+
images?: ImagesInput;
|
|
244
248
|
};
|
|
245
249
|
/**
|
|
246
250
|
* Animation output format. On wasm, WebP animation is always lossless (lossy
|
|
@@ -255,13 +259,11 @@ type AnimationOutputFormatOptions = {
|
|
|
255
259
|
};
|
|
256
260
|
type RenderAnimationOptions = Omit<RenderAnimationOptions$1, "images" | "format"> & AnimationOutputFormatOptions & {
|
|
257
261
|
fonts?: FontLoader[];
|
|
258
|
-
images?:
|
|
259
|
-
subset?: boolean;
|
|
262
|
+
images?: ImagesInput;
|
|
260
263
|
};
|
|
261
264
|
type SvgRenderOptions = Omit<SvgRenderOptions$1, "images"> & {
|
|
262
265
|
fonts?: FontLoader[];
|
|
263
|
-
images?:
|
|
264
|
-
subset?: boolean;
|
|
266
|
+
images?: ImagesInput;
|
|
265
267
|
};
|
|
266
268
|
declare class Renderer {
|
|
267
269
|
private fontsByKey;
|
|
@@ -280,4 +282,4 @@ declare class Renderer {
|
|
|
280
282
|
registerFont(font: FontLoader): Promise<RegisteredFamily[]>;
|
|
281
283
|
}
|
|
282
284
|
//#endregion
|
|
283
|
-
export { AnimationOutputFormatOptions,
|
|
285
|
+
export { AnimationOutputFormatOptions, AnimationScene, ByteBuf, ContainerNode, Font, FontDetails, FontLoader, ImageLoader, ImageNode, ImageSource, ImagesInput, InitInput, InitOutput, KeyframeRule, Keyframes, KeyframesMap, KeyframesRule, KeyframesRuleList, MeasuredNode, MeasuredTextRun, type Node, NodeMetadata, OutputFormatOptions, RegisteredFace, RegisteredFamily, RenderAnimationOptions, RenderOptions, Renderer, SvgRenderOptions, SyncInitInput, TextNode, __wbg_init as default, initSync };
|
package/dist/export.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContainerNode, ImageNode, Node, Node as Node$1, NodeMetadata, TextNode
|
|
1
|
+
import { ContainerNode, ImageNode, Node, Node as Node$1, NodeMetadata, TextNode } from "@takumi-rs/helpers";
|
|
2
2
|
import { Properties } from "csstype";
|
|
3
3
|
|
|
4
4
|
//#region pkg/takumi_wasm.d.ts
|
|
@@ -72,7 +72,7 @@ type RenderOptions$1 = {
|
|
|
72
72
|
*/
|
|
73
73
|
type SvgRenderOptions$1 = Omit<RenderOptions$1, "format" | "quality" | "drawDebugBorder" | "devicePixelRatio" | "dithering">;
|
|
74
74
|
type RenderAnimationOptions$1 = {
|
|
75
|
-
scenes:
|
|
75
|
+
scenes: AnimationScene[];
|
|
76
76
|
width: number;
|
|
77
77
|
height: number;
|
|
78
78
|
format?: "webp" | "apng" | "gif";
|
|
@@ -155,7 +155,7 @@ type MeasuredNode = {
|
|
|
155
155
|
children: MeasuredNode[];
|
|
156
156
|
runs: MeasuredTextRun[];
|
|
157
157
|
};
|
|
158
|
-
type
|
|
158
|
+
type AnimationScene = {
|
|
159
159
|
node: Node$1;
|
|
160
160
|
durationMs: number;
|
|
161
161
|
};
|
|
@@ -220,6 +220,11 @@ type ImageLoaderData = ImageSource["data"];
|
|
|
220
220
|
type ImageLoader = Omit<ImageSource, "data"> & {
|
|
221
221
|
data: ImageLoaderData | (() => ImageLoaderData | Promise<ImageLoaderData>);
|
|
222
222
|
};
|
|
223
|
+
/** Images for a render: pre-fetched entries, or a group with a decode-cache default. */
|
|
224
|
+
type ImagesInput = ImageLoader[] | {
|
|
225
|
+
/** Pre-fetched entries, same as the array form. */sources?: ImageLoader[]; /** Decode-cache default for every image this render; a source's own `cache` wins. */
|
|
226
|
+
cache?: NonNullable<ImageLoader["cache"]>;
|
|
227
|
+
};
|
|
223
228
|
/**
|
|
224
229
|
* Output format. Format-specific options live on the variant that supports them,
|
|
225
230
|
* so `quality` cannot be paired with a lossless format. On wasm, WebP is always
|
|
@@ -239,8 +244,7 @@ type OutputFormatOptions = {
|
|
|
239
244
|
};
|
|
240
245
|
type RenderOptions = Omit<RenderOptions$1, "images" | "format" | "quality"> & OutputFormatOptions & {
|
|
241
246
|
fonts?: FontLoader[];
|
|
242
|
-
images?:
|
|
243
|
-
subset?: boolean;
|
|
247
|
+
images?: ImagesInput;
|
|
244
248
|
};
|
|
245
249
|
/**
|
|
246
250
|
* Animation output format. On wasm, WebP animation is always lossless (lossy
|
|
@@ -255,13 +259,11 @@ type AnimationOutputFormatOptions = {
|
|
|
255
259
|
};
|
|
256
260
|
type RenderAnimationOptions = Omit<RenderAnimationOptions$1, "images" | "format"> & AnimationOutputFormatOptions & {
|
|
257
261
|
fonts?: FontLoader[];
|
|
258
|
-
images?:
|
|
259
|
-
subset?: boolean;
|
|
262
|
+
images?: ImagesInput;
|
|
260
263
|
};
|
|
261
264
|
type SvgRenderOptions = Omit<SvgRenderOptions$1, "images"> & {
|
|
262
265
|
fonts?: FontLoader[];
|
|
263
|
-
images?:
|
|
264
|
-
subset?: boolean;
|
|
266
|
+
images?: ImagesInput;
|
|
265
267
|
};
|
|
266
268
|
declare class Renderer {
|
|
267
269
|
private fontsByKey;
|
|
@@ -280,4 +282,4 @@ declare class Renderer {
|
|
|
280
282
|
registerFont(font: FontLoader): Promise<RegisteredFamily[]>;
|
|
281
283
|
}
|
|
282
284
|
//#endregion
|
|
283
|
-
export { AnimationOutputFormatOptions,
|
|
285
|
+
export { AnimationOutputFormatOptions, AnimationScene, ByteBuf, ContainerNode, Font, FontDetails, FontLoader, ImageLoader, ImageNode, ImageSource, ImagesInput, InitInput, InitOutput, KeyframeRule, Keyframes, KeyframesMap, KeyframesRule, KeyframesRuleList, MeasuredNode, MeasuredTextRun, type Node, NodeMetadata, OutputFormatOptions, RegisteredFace, RegisteredFamily, RenderAnimationOptions, RenderOptions, Renderer, SvgRenderOptions, SyncInitInput, TextNode, __wbg_init as default, initSync };
|
package/dist/export.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fontFromUrl, subsetFonts } from "@takumi-rs/helpers";
|
|
2
2
|
//#region pkg/takumi_wasm.js
|
|
3
3
|
/**
|
|
4
4
|
* The main renderer for Takumi image rendering engine.
|
|
@@ -514,12 +514,13 @@ async function __wbg_init(module_or_path) {
|
|
|
514
514
|
//#endregion
|
|
515
515
|
//#region src/export.ts
|
|
516
516
|
async function resolveImageLoaders(images) {
|
|
517
|
+
const { sources = [], cache } = Array.isArray(images) ? { sources: images } : images;
|
|
517
518
|
const bySrc = /* @__PURE__ */ new Map();
|
|
518
|
-
for (const image of
|
|
519
|
-
return Promise.all([...bySrc.values()].map(async ({ src, data, cache }) => ({
|
|
519
|
+
for (const image of sources) bySrc.set(image.src, image);
|
|
520
|
+
return Promise.all([...bySrc.values()].map(async ({ src, data, cache: own }) => ({
|
|
520
521
|
src,
|
|
521
522
|
data: typeof data === "function" ? await data() : data,
|
|
522
|
-
cache
|
|
523
|
+
cache: own ?? cache
|
|
523
524
|
})));
|
|
524
525
|
}
|
|
525
526
|
var Renderer = class {
|
|
@@ -543,11 +544,10 @@ var Renderer = class {
|
|
|
543
544
|
return [...new Set(families.flat().map((f) => f.name))];
|
|
544
545
|
}
|
|
545
546
|
async render(node, options) {
|
|
546
|
-
const { fonts, fontFamilies, images,
|
|
547
|
-
const registeredFamilies = await this.prepareFonts(
|
|
547
|
+
const { fonts, fontFamilies, images, ...rest } = options ?? {};
|
|
548
|
+
const registeredFamilies = await this.prepareFonts(fonts && subsetFonts({
|
|
548
549
|
fonts,
|
|
549
|
-
source: node
|
|
550
|
-
subset
|
|
550
|
+
source: node
|
|
551
551
|
}));
|
|
552
552
|
const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
|
|
553
553
|
return this.inner.render(node, {
|
|
@@ -557,11 +557,10 @@ var Renderer = class {
|
|
|
557
557
|
});
|
|
558
558
|
}
|
|
559
559
|
async renderAsDataUrl(node, options) {
|
|
560
|
-
const { fonts, fontFamilies, images,
|
|
561
|
-
const registeredFamilies = await this.prepareFonts(
|
|
560
|
+
const { fonts, fontFamilies, images, ...rest } = options ?? {};
|
|
561
|
+
const registeredFamilies = await this.prepareFonts(fonts && subsetFonts({
|
|
562
562
|
fonts,
|
|
563
|
-
source: node
|
|
564
|
-
subset
|
|
563
|
+
source: node
|
|
565
564
|
}));
|
|
566
565
|
const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
|
|
567
566
|
return this.inner.renderAsDataUrl(node, {
|
|
@@ -571,11 +570,10 @@ var Renderer = class {
|
|
|
571
570
|
});
|
|
572
571
|
}
|
|
573
572
|
async renderSvg(node, options) {
|
|
574
|
-
const { fonts, fontFamilies, images,
|
|
575
|
-
const registeredFamilies = await this.prepareFonts(
|
|
573
|
+
const { fonts, fontFamilies, images, ...rest } = options ?? {};
|
|
574
|
+
const registeredFamilies = await this.prepareFonts(fonts && subsetFonts({
|
|
576
575
|
fonts,
|
|
577
|
-
source: node
|
|
578
|
-
subset
|
|
576
|
+
source: node
|
|
579
577
|
}));
|
|
580
578
|
const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
|
|
581
579
|
return this.inner.renderSvg(node, {
|
|
@@ -585,11 +583,10 @@ var Renderer = class {
|
|
|
585
583
|
});
|
|
586
584
|
}
|
|
587
585
|
async measure(node, options) {
|
|
588
|
-
const { fonts, fontFamilies, images,
|
|
589
|
-
const registeredFamilies = await this.prepareFonts(
|
|
586
|
+
const { fonts, fontFamilies, images, ...rest } = options ?? {};
|
|
587
|
+
const registeredFamilies = await this.prepareFonts(fonts && subsetFonts({
|
|
590
588
|
fonts,
|
|
591
|
-
source: node
|
|
592
|
-
subset
|
|
589
|
+
source: node
|
|
593
590
|
}));
|
|
594
591
|
const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
|
|
595
592
|
return this.inner.measure(node, {
|
|
@@ -599,12 +596,11 @@ var Renderer = class {
|
|
|
599
596
|
});
|
|
600
597
|
}
|
|
601
598
|
async renderAnimation(options) {
|
|
602
|
-
const { fonts, fontFamilies, images,
|
|
599
|
+
const { fonts, fontFamilies, images, ...rest } = options;
|
|
603
600
|
const nodes = options.scenes.map((scene) => scene.node);
|
|
604
|
-
const registeredFamilies = await this.prepareFonts(
|
|
601
|
+
const registeredFamilies = await this.prepareFonts(fonts && subsetFonts({
|
|
605
602
|
fonts,
|
|
606
|
-
source: nodes
|
|
607
|
-
subset
|
|
603
|
+
source: nodes
|
|
608
604
|
}));
|
|
609
605
|
const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
|
|
610
606
|
return this.inner.renderAnimation({
|
|
@@ -654,4 +650,4 @@ function isBuffer(data) {
|
|
|
654
650
|
return data instanceof Uint8Array || data instanceof ArrayBuffer || typeof Buffer !== "undefined" && Buffer.isBuffer(data);
|
|
655
651
|
}
|
|
656
652
|
//#endregion
|
|
657
|
-
export { Renderer, __wbg_init as default,
|
|
653
|
+
export { Renderer, __wbg_init as default, initSync };
|
package/package.json
CHANGED
package/pkg/takumi_wasm_bg.wasm
CHANGED
|
Binary file
|