@takumi-rs/wasm 1.0.0-beta.2 → 1.0.0-beta.20

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 CHANGED
@@ -4,4 +4,4 @@ Takumi is a **image rendering engine** written in Rust and this package provides
4
4
 
5
5
  Please refer to the [WebAssembly (In Browser)](https://takumi.kane.tw/docs/integrations/wasm-web) page in our official documentation for more details.
6
6
 
7
- If you are looking for Node.js bindings, take a look at the [@takumi-rs/core](https://npmjs.com/package/@takumi-rs/core) package.
7
+ If you are looking for Node.js bindings, take a look at the [@takumi-rs/core](https://npmjs.com/package/@takumi-rs/core) package.
package/bundlers/node.mjs CHANGED
@@ -1,13 +1,7 @@
1
1
  import { readFileSync } from "node:fs";
2
- import { dirname, join } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
2
  import { initSync } from "../pkg/takumi_wasm";
5
3
 
6
- const __filename = fileURLToPath(import.meta.url);
7
- const __dirname = dirname(__filename);
8
-
9
- const wasmPath = join(__dirname, "../pkg/takumi_wasm_bg.wasm");
10
- const wasmBytes = readFileSync(wasmPath);
4
+ const wasmBytes = readFileSync(new URL("../pkg/takumi_wasm_bg.wasm", import.meta.url));
11
5
 
12
6
  initSync({ module: wasmBytes });
13
7
 
@@ -0,0 +1,3 @@
1
+ declare const module: string;
2
+
3
+ export default module;
@@ -0,0 +1,29 @@
1
+ import url from "../pkg/takumi_wasm_bg.wasm?url";
2
+
3
+ async function processUrl() {
4
+ if (typeof process !== "undefined" && process.versions?.node != null) {
5
+ const { readFile } = await import("node:fs/promises");
6
+
7
+ if (!url.startsWith("/")) {
8
+ return readFile(new URL(url, import.meta.url));
9
+ }
10
+
11
+ for (const candidate of [`../client${url}`, `../../client${url}`]) {
12
+ try {
13
+ return await readFile(new URL(candidate, import.meta.url));
14
+ } catch (error) {
15
+ if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
16
+ continue;
17
+ }
18
+
19
+ throw error;
20
+ }
21
+ }
22
+
23
+ throw new Error(`Unable to locate Takumi WASM asset for SSR: ${url}`);
24
+ }
25
+
26
+ return fetch(new URL(url, import.meta.url)).then((response) => response.arrayBuffer());
27
+ }
28
+
29
+ export default processUrl();
@@ -0,0 +1,3 @@
1
+ import module from "../pkg/takumi_wasm_bg.wasm";
2
+
3
+ export default module;
package/package.json CHANGED
@@ -1,43 +1,30 @@
1
1
  {
2
2
  "name": "@takumi-rs/wasm",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.20",
4
4
  "keywords": [
5
- "image",
6
- "rendering",
7
5
  "css",
8
- "react",
6
+ "image",
9
7
  "jsx",
8
+ "react",
9
+ "rendering",
10
10
  "webassembly"
11
11
  ],
12
- "scripts": {
13
- "build": "wasm-pack build --no-pack --release --out-dir pkg --target web && bun run scripts/merge-dts.ts && bun build pkg/takumi_wasm.js --define import.meta.url=undefined --format cjs --outfile pkg/takumi_wasm.cjs",
14
- "build:debug": "wasm-pack build --no-pack --dev --out-dir pkg --target web && bun run scripts/merge-dts.ts && bun build pkg/takumi_wasm.js --define import.meta.url=undefined --format cjs --outfile pkg/takumi_wasm.cjs",
15
- "prepublishOnly": "jq '.dependencies[\"@takumi-rs/helpers\"] = .version' package.json > tmp.json && mv tmp.json package.json"
16
- },
12
+ "license": "(MIT OR Apache-2.0)",
17
13
  "author": {
18
- "email": "me@kane.tw",
19
14
  "name": "Kane Wang",
15
+ "email": "me@kane.tw",
20
16
  "url": "https://kane.tw"
21
17
  },
22
18
  "repository": {
23
19
  "url": "git+https://github.com/kane50613/takumi.git"
24
20
  },
25
- "dependencies": {
26
- "@takumi-rs/helpers": "1.0.0-beta.2"
27
- },
28
- "readme": "README.md",
29
- "license": "(MIT OR Apache-2.0)",
30
- "devDependencies": {
31
- "@types/bun": "catalog:",
32
- "typescript": "catalog:"
33
- },
21
+ "files": [
22
+ "README.md",
23
+ "pkg/takumi*",
24
+ "bundlers/*"
25
+ ],
34
26
  "exports": {
35
27
  ".": {
36
- "node": {
37
- "types": "./bundlers/node.d.ts",
38
- "import": "./bundlers/node.mjs",
39
- "require": "./bundlers/node.cjs"
40
- },
41
28
  "types": "./pkg/takumi_wasm.d.ts",
42
29
  "import": "./pkg/takumi_wasm.js",
43
30
  "require": "./pkg/takumi_wasm.cjs",
@@ -54,18 +41,38 @@
54
41
  "import": "./bundlers/node.mjs",
55
42
  "require": "./bundlers/node.cjs"
56
43
  },
44
+ "./auto": {
45
+ "types": "./pkg/takumi_wasm.d.ts",
46
+ "workerd": "./bundlers/workerd.js",
47
+ "unwasm": "./bundlers/next.mjs",
48
+ "module": "./bundlers/vite.mjs",
49
+ "node": "./bundlers/node.mjs",
50
+ "default": "./bundlers/vite.mjs"
51
+ },
57
52
  "./takumi_wasm_bg.wasm": {
58
53
  "types": "./pkg/takumi_wasm_bg.wasm.d.ts",
59
54
  "default": "./pkg/takumi_wasm_bg.wasm"
60
55
  },
61
56
  "./next": {
62
57
  "types": "./bundlers/next.d.ts",
63
- "default": "./bundlers/next.js"
58
+ "default": "./bundlers/next.mjs"
59
+ },
60
+ "./vite": {
61
+ "types": "./bundlers/vite.d.ts",
62
+ "default": "./bundlers/vite.mjs"
64
63
  }
65
64
  },
66
- "files": [
67
- "README.md",
68
- "pkg/takumi*",
69
- "bundlers/*"
70
- ]
65
+ "scripts": {
66
+ "build": "wasm-pack build --no-pack --release --out-dir pkg --target web && bun run scripts/merge-dts.ts && bun build pkg/takumi_wasm.js --define import.meta.url=undefined --format cjs --outfile pkg/takumi_wasm.cjs",
67
+ "build:debug": "wasm-pack build --no-pack --dev --out-dir pkg --target web && bun run scripts/merge-dts.ts && bun build pkg/takumi_wasm.js --define import.meta.url=undefined --format cjs --outfile pkg/takumi_wasm.cjs",
68
+ "prepublishOnly": "jq '.dependencies[\"@takumi-rs/helpers\"] = .version' package.json > tmp.json && mv tmp.json package.json"
69
+ },
70
+ "dependencies": {
71
+ "@takumi-rs/helpers": "1.0.0-beta.20"
72
+ },
73
+ "devDependencies": {
74
+ "@types/bun": "catalog:",
75
+ "typescript": "catalog:"
76
+ },
77
+ "readme": "README.md"
71
78
  }
@@ -1,12 +1,6 @@
1
1
  import type { Node } from "@takumi-rs/helpers";
2
2
 
3
- export {
4
- ContainerNode,
5
- ImageNode,
6
- Node,
7
- NodeMetadata,
8
- TextNode,
9
- } from "@takumi-rs/helpers";
3
+ export { ContainerNode, ImageNode, Node, NodeMetadata, TextNode } from "@takumi-rs/helpers";
10
4
 
11
5
  export type ByteBuf = Uint8Array | ArrayBuffer | Buffer;
12
6
 
@@ -119,7 +113,7 @@ export type FontDetails = {
119
113
  name?: string;
120
114
  data: ByteBuf;
121
115
  weight?: number;
122
- style?: "normal" | "italic" | "oblique";
116
+ style?: "normal" | "italic" | "oblique" | `oblique ${number}deg` | (string & {});
123
117
  };
124
118
 
125
119
  export type ImageSource = {
@@ -148,6 +142,11 @@ export type ConstructRendererOptions = {
148
142
  * The fonts being used.
149
143
  */
150
144
  fonts?: Font[];
145
+ /**
146
+ * Whether to load the default fonts.
147
+ * If `fonts` are provided, this will be `false` by default.
148
+ */
149
+ loadDefaultFonts?: boolean;
151
150
  };
152
151
 
153
152
  export type MeasuredTextRun = {
Binary file
File without changes