@takumi-rs/wasm 2.0.0-beta.4 → 2.0.0-beta.6
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/bundlers/vite.mjs +17 -4
- package/dist/export.cjs +17 -5
- package/dist/export.d.cts +6 -2
- package/dist/export.d.mts +6 -2
- package/dist/export.mjs +17 -5
- package/package.json +2 -2
- package/pkg/takumi_wasm_bg.wasm +0 -0
package/bundlers/vite.mjs
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
import url from "../pkg/takumi_wasm_bg.wasm?url";
|
|
2
2
|
|
|
3
|
+
// `?url` is a browser path; map it to a file for server reads. Vite emits the asset next to the
|
|
4
|
+
// importing server chunk, so resolve relative to import.meta.url, not the framework output dir.
|
|
3
5
|
async function processUrl() {
|
|
4
6
|
if (typeof process !== "undefined" && process.versions?.node != null) {
|
|
5
7
|
const { readFile } = await import("node:fs/promises");
|
|
8
|
+
const path = decodeURIComponent(url.replace(/[?#].*$/, ""));
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
// Dev SSR serves an `/@fs/<abs-path>` URL.
|
|
11
|
+
if (path.startsWith("/@fs/")) {
|
|
12
|
+
return readFile(path.slice("/@fs".length));
|
|
9
13
|
}
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
if (!path.startsWith("/")) {
|
|
16
|
+
return readFile(new URL(path, import.meta.url));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const basename = path.slice(path.lastIndexOf("/") + 1);
|
|
20
|
+
const candidates = [`./${basename}`, `../client${path}`, `../../client${path}`];
|
|
21
|
+
|
|
22
|
+
let lastError;
|
|
23
|
+
for (const candidate of candidates) {
|
|
12
24
|
try {
|
|
13
25
|
return await readFile(new URL(candidate, import.meta.url));
|
|
14
26
|
} catch (error) {
|
|
15
27
|
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
|
|
28
|
+
lastError = error;
|
|
16
29
|
continue;
|
|
17
30
|
}
|
|
18
31
|
|
|
@@ -20,7 +33,7 @@ async function processUrl() {
|
|
|
20
33
|
}
|
|
21
34
|
}
|
|
22
35
|
|
|
23
|
-
throw new Error(`Unable to locate Takumi WASM asset for SSR: ${url}
|
|
36
|
+
throw new Error(`Unable to locate Takumi WASM asset for SSR: ${url}`, { cause: lastError });
|
|
24
37
|
}
|
|
25
38
|
|
|
26
39
|
return fetch(new URL(url, import.meta.url)).then((response) => response.arrayBuffer());
|
package/dist/export.cjs
CHANGED
|
@@ -564,8 +564,20 @@ async function resolveImageLoaders(images) {
|
|
|
564
564
|
})));
|
|
565
565
|
}
|
|
566
566
|
var Renderer = class {
|
|
567
|
-
|
|
567
|
+
fontsByKey = /* @__PURE__ */ new Map();
|
|
568
|
+
fontsByData = /* @__PURE__ */ new WeakMap();
|
|
568
569
|
inner = new Renderer$1();
|
|
570
|
+
getFont(key) {
|
|
571
|
+
return typeof key === "string" ? this.fontsByKey.get(key) : this.fontsByData.get(key);
|
|
572
|
+
}
|
|
573
|
+
setFont(key, family) {
|
|
574
|
+
if (typeof key === "string") this.fontsByKey.set(key, family);
|
|
575
|
+
else this.fontsByData.set(key, family);
|
|
576
|
+
}
|
|
577
|
+
deleteFont(key) {
|
|
578
|
+
if (typeof key === "string") this.fontsByKey.delete(key);
|
|
579
|
+
else this.fontsByData.delete(key);
|
|
580
|
+
}
|
|
569
581
|
async prepareFonts(fonts) {
|
|
570
582
|
if (!fonts) return;
|
|
571
583
|
const families = await Promise.all(fonts.map(this.registerFont.bind(this)));
|
|
@@ -636,7 +648,7 @@ var Renderer = class {
|
|
|
636
648
|
}
|
|
637
649
|
async registerFont(font) {
|
|
638
650
|
const key = createFontKey(font);
|
|
639
|
-
const cached = this.
|
|
651
|
+
const cached = this.getFont(key);
|
|
640
652
|
if (cached) return cached;
|
|
641
653
|
const extracted = extractFontBuffer(font);
|
|
642
654
|
const register = (data) => this.inner.registerFont(isBuffer(font) ? data : {
|
|
@@ -645,14 +657,14 @@ var Renderer = class {
|
|
|
645
657
|
});
|
|
646
658
|
if (isBuffer(extracted)) {
|
|
647
659
|
const binded = register(extracted);
|
|
648
|
-
this.
|
|
660
|
+
this.setFont(key, Promise.resolve(binded));
|
|
649
661
|
return binded;
|
|
650
662
|
}
|
|
651
663
|
const promise = extracted.then(register).catch((error) => {
|
|
652
|
-
this.
|
|
664
|
+
this.deleteFont(key);
|
|
653
665
|
throw error;
|
|
654
666
|
});
|
|
655
|
-
this.
|
|
667
|
+
this.setFont(key, promise);
|
|
656
668
|
return promise;
|
|
657
669
|
}
|
|
658
670
|
};
|
package/dist/export.d.cts
CHANGED
|
@@ -295,8 +295,12 @@ type SvgRenderOptions = Omit<SvgRenderOptions$1, "images"> & {
|
|
|
295
295
|
images?: ImageLoader[];
|
|
296
296
|
};
|
|
297
297
|
declare class Renderer {
|
|
298
|
-
private
|
|
298
|
+
private fontsByKey;
|
|
299
|
+
private fontsByData;
|
|
299
300
|
private inner;
|
|
301
|
+
private getFont;
|
|
302
|
+
private setFont;
|
|
303
|
+
private deleteFont;
|
|
300
304
|
private prepareFonts;
|
|
301
305
|
render(node: Node, options?: RenderOptions): Promise<Uint8Array<ArrayBufferLike>>;
|
|
302
306
|
renderAsDataUrl(node: Node, options?: RenderOptions): Promise<string>;
|
|
@@ -305,7 +309,7 @@ declare class Renderer {
|
|
|
305
309
|
renderAnimation(options: RenderAnimationOptions): Promise<Uint8Array<ArrayBufferLike>>;
|
|
306
310
|
encodeFrames(frames: AnimationFrameSource[], options: EncodeFramesOptions): Promise<Uint8Array<ArrayBufferLike>>;
|
|
307
311
|
free(): void;
|
|
308
|
-
registerFont(font: FontLoader): Promise<
|
|
312
|
+
registerFont(font: FontLoader): Promise<RegisteredFamily[]>;
|
|
309
313
|
}
|
|
310
314
|
//#endregion
|
|
311
315
|
export { AnimationFrameSource, AnimationOutputFormatOptions, AnimationSceneSource, ByteBuf, ContainerNode, EncodeFramesOptions, Font, FontDetails, FontLoader, ImageLoader, ImageNode, ImageSource, 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, extractResourceUrls, initSync };
|
package/dist/export.d.mts
CHANGED
|
@@ -295,8 +295,12 @@ type SvgRenderOptions = Omit<SvgRenderOptions$1, "images"> & {
|
|
|
295
295
|
images?: ImageLoader[];
|
|
296
296
|
};
|
|
297
297
|
declare class Renderer {
|
|
298
|
-
private
|
|
298
|
+
private fontsByKey;
|
|
299
|
+
private fontsByData;
|
|
299
300
|
private inner;
|
|
301
|
+
private getFont;
|
|
302
|
+
private setFont;
|
|
303
|
+
private deleteFont;
|
|
300
304
|
private prepareFonts;
|
|
301
305
|
render(node: Node, options?: RenderOptions): Promise<Uint8Array<ArrayBufferLike>>;
|
|
302
306
|
renderAsDataUrl(node: Node, options?: RenderOptions): Promise<string>;
|
|
@@ -305,7 +309,7 @@ declare class Renderer {
|
|
|
305
309
|
renderAnimation(options: RenderAnimationOptions): Promise<Uint8Array<ArrayBufferLike>>;
|
|
306
310
|
encodeFrames(frames: AnimationFrameSource[], options: EncodeFramesOptions): Promise<Uint8Array<ArrayBufferLike>>;
|
|
307
311
|
free(): void;
|
|
308
|
-
registerFont(font: FontLoader): Promise<
|
|
312
|
+
registerFont(font: FontLoader): Promise<RegisteredFamily[]>;
|
|
309
313
|
}
|
|
310
314
|
//#endregion
|
|
311
315
|
export { AnimationFrameSource, AnimationOutputFormatOptions, AnimationSceneSource, ByteBuf, ContainerNode, EncodeFramesOptions, Font, FontDetails, FontLoader, ImageLoader, ImageNode, ImageSource, 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, extractResourceUrls, initSync };
|
package/dist/export.mjs
CHANGED
|
@@ -560,8 +560,20 @@ async function resolveImageLoaders(images) {
|
|
|
560
560
|
})));
|
|
561
561
|
}
|
|
562
562
|
var Renderer = class {
|
|
563
|
-
|
|
563
|
+
fontsByKey = /* @__PURE__ */ new Map();
|
|
564
|
+
fontsByData = /* @__PURE__ */ new WeakMap();
|
|
564
565
|
inner = new Renderer$1();
|
|
566
|
+
getFont(key) {
|
|
567
|
+
return typeof key === "string" ? this.fontsByKey.get(key) : this.fontsByData.get(key);
|
|
568
|
+
}
|
|
569
|
+
setFont(key, family) {
|
|
570
|
+
if (typeof key === "string") this.fontsByKey.set(key, family);
|
|
571
|
+
else this.fontsByData.set(key, family);
|
|
572
|
+
}
|
|
573
|
+
deleteFont(key) {
|
|
574
|
+
if (typeof key === "string") this.fontsByKey.delete(key);
|
|
575
|
+
else this.fontsByData.delete(key);
|
|
576
|
+
}
|
|
565
577
|
async prepareFonts(fonts) {
|
|
566
578
|
if (!fonts) return;
|
|
567
579
|
const families = await Promise.all(fonts.map(this.registerFont.bind(this)));
|
|
@@ -632,7 +644,7 @@ var Renderer = class {
|
|
|
632
644
|
}
|
|
633
645
|
async registerFont(font) {
|
|
634
646
|
const key = createFontKey(font);
|
|
635
|
-
const cached = this.
|
|
647
|
+
const cached = this.getFont(key);
|
|
636
648
|
if (cached) return cached;
|
|
637
649
|
const extracted = extractFontBuffer(font);
|
|
638
650
|
const register = (data) => this.inner.registerFont(isBuffer(font) ? data : {
|
|
@@ -641,14 +653,14 @@ var Renderer = class {
|
|
|
641
653
|
});
|
|
642
654
|
if (isBuffer(extracted)) {
|
|
643
655
|
const binded = register(extracted);
|
|
644
|
-
this.
|
|
656
|
+
this.setFont(key, Promise.resolve(binded));
|
|
645
657
|
return binded;
|
|
646
658
|
}
|
|
647
659
|
const promise = extracted.then(register).catch((error) => {
|
|
648
|
-
this.
|
|
660
|
+
this.deleteFont(key);
|
|
649
661
|
throw error;
|
|
650
662
|
});
|
|
651
|
-
this.
|
|
663
|
+
this.setFont(key, promise);
|
|
652
664
|
return promise;
|
|
653
665
|
}
|
|
654
666
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takumi-rs/wasm",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.6",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"css",
|
|
6
6
|
"image",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"publish-lint": "attw --pack . && publint --strict ."
|
|
90
90
|
},
|
|
91
91
|
"dependencies": {
|
|
92
|
-
"@takumi-rs/helpers": "
|
|
92
|
+
"@takumi-rs/helpers": "2.0.0-beta.6"
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
95
|
"@types/bun": "catalog:",
|
package/pkg/takumi_wasm_bg.wasm
CHANGED
|
Binary file
|