circuit-json-to-gltf 0.0.4 → 0.0.5
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
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Converts circuit JSON to 3D GLTF files. Used for exporting circuits as 3D models.
|
|
4
4
|
|
|
5
|
+
[Online Playground](https://circuit-json-to-gltf.vercel.app/renderer.html?fixtureId=%7B%22path%22%3A%22CircuitToGltfDemo.fixture.tsx%22%7D&locked=true)
|
|
6
|
+
|
|
5
7
|
<img width="2424" height="1854" alt="image" src="https://github.com/user-attachments/assets/4ad8b607-e496-449c-88a3-8875b16c0a53" />
|
|
6
8
|
|
|
7
9
|
## Features
|
package/dist/index.js
CHANGED
|
@@ -520,7 +520,7 @@ async function convertSvgToPng(svgString, resolution, backgroundColor) {
|
|
|
520
520
|
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
521
521
|
return convertSvgToCanvasBrowser(svgString, resolution, backgroundColor);
|
|
522
522
|
} else {
|
|
523
|
-
const { svgToPngDataUrl } = await import("./svg-to-png-browser-
|
|
523
|
+
const { svgToPngDataUrl } = await import("./svg-to-png-browser-ZI5PXAWS.js");
|
|
524
524
|
return await svgToPngDataUrl(svgString, {
|
|
525
525
|
width: resolution,
|
|
526
526
|
background: backgroundColor
|
|
@@ -6,13 +6,7 @@ async function ensureWasmInitialized() {
|
|
|
6
6
|
try {
|
|
7
7
|
if (typeof process !== "undefined" && process.versions?.node) {
|
|
8
8
|
const { readFileSync } = await import("fs");
|
|
9
|
-
const
|
|
10
|
-
const { dirname, join } = await import("path");
|
|
11
|
-
const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
12
|
-
const wasmPath = join(
|
|
13
|
-
currentDir,
|
|
14
|
-
"../../node_modules/@resvg/resvg-wasm/index_bg.wasm"
|
|
15
|
-
);
|
|
9
|
+
const wasmPath = await import("@resvg/resvg-wasm/index_bg.wasm");
|
|
16
10
|
const wasmBuffer = readFileSync(wasmPath);
|
|
17
11
|
await initWasm(wasmBuffer);
|
|
18
12
|
} else {
|
package/package.json
CHANGED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// lib/utils/svg-to-png-browser.ts
|
|
2
|
-
import { Resvg, initWasm } from "@resvg/resvg-wasm";
|
|
3
|
-
var wasmInitialized = false;
|
|
4
|
-
async function ensureWasmInitialized() {
|
|
5
|
-
if (!wasmInitialized) {
|
|
6
|
-
try {
|
|
7
|
-
if (typeof process !== "undefined" && process.versions?.node) {
|
|
8
|
-
const { readFileSync } = await import("fs");
|
|
9
|
-
const { fileURLToPath } = await import("url");
|
|
10
|
-
const { dirname, join } = await import("path");
|
|
11
|
-
const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
12
|
-
const wasmPath = join(currentDir, "../../node_modules/@resvg/resvg-wasm/index_bg.wasm");
|
|
13
|
-
const wasmBuffer = readFileSync(wasmPath);
|
|
14
|
-
await initWasm(wasmBuffer);
|
|
15
|
-
} else {
|
|
16
|
-
try {
|
|
17
|
-
const wasmUrl = await import("@resvg/resvg-wasm/index_bg.wasm?url");
|
|
18
|
-
await initWasm(fetch(wasmUrl.default));
|
|
19
|
-
} catch {
|
|
20
|
-
await initWasm(fetch("https://unpkg.com/@resvg/resvg-wasm@2.6.2/index_bg.wasm"));
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
wasmInitialized = true;
|
|
24
|
-
} catch (error) {
|
|
25
|
-
console.error("Failed to initialize WASM:", error);
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async function svgToPng(svgString, options = {}) {
|
|
31
|
-
await ensureWasmInitialized();
|
|
32
|
-
const opts = {
|
|
33
|
-
background: options.background,
|
|
34
|
-
fitTo: options.width ? {
|
|
35
|
-
mode: "width",
|
|
36
|
-
value: options.width
|
|
37
|
-
} : options.height ? {
|
|
38
|
-
mode: "height",
|
|
39
|
-
value: options.height
|
|
40
|
-
} : void 0
|
|
41
|
-
};
|
|
42
|
-
const resvg = new Resvg(svgString, opts);
|
|
43
|
-
const pngData = resvg.render();
|
|
44
|
-
const pngBuffer = pngData.asPng();
|
|
45
|
-
return pngBuffer;
|
|
46
|
-
}
|
|
47
|
-
async function svgToPngDataUrl(svgString, options = {}) {
|
|
48
|
-
const pngBuffer = await svgToPng(svgString, options);
|
|
49
|
-
let binary = "";
|
|
50
|
-
const bytes = new Uint8Array(pngBuffer);
|
|
51
|
-
const len = bytes.byteLength;
|
|
52
|
-
for (let i = 0; i < len; i++) {
|
|
53
|
-
binary += String.fromCharCode(bytes[i]);
|
|
54
|
-
}
|
|
55
|
-
const base64 = btoa(binary);
|
|
56
|
-
return `data:image/png;base64,${base64}`;
|
|
57
|
-
}
|
|
58
|
-
export {
|
|
59
|
-
svgToPng,
|
|
60
|
-
svgToPngDataUrl
|
|
61
|
-
};
|