circuit-json-to-gltf 0.0.4 → 0.0.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/README.md +2 -0
- package/dist/index.js +13 -6
- package/dist/svg-to-png-BX4YEHCP.js +29 -0
- package/package.json +1 -1
- package/dist/svg-to-png-browser-2JB6D5DD.js +0 -61
- package/dist/svg-to-png-browser-4BZIU5HP.js +0 -66
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
|
@@ -489,7 +489,6 @@ async function renderBoardLayer(circuitJson, options) {
|
|
|
489
489
|
backgroundColor = "transparent",
|
|
490
490
|
copperColor = "#ffe066",
|
|
491
491
|
silkscreenColor = "#ffffff",
|
|
492
|
-
padColor = "#ffe066",
|
|
493
492
|
drillColor = "rgba(0,0,0,0.5)"
|
|
494
493
|
} = options;
|
|
495
494
|
const svg = convertCircuitJsonToPcbSvg(circuitJson, {
|
|
@@ -520,11 +519,19 @@ async function convertSvgToPng(svgString, resolution, backgroundColor) {
|
|
|
520
519
|
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
521
520
|
return convertSvgToCanvasBrowser(svgString, resolution, backgroundColor);
|
|
522
521
|
} else {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
522
|
+
try {
|
|
523
|
+
const { svgToPngDataUrl } = await import("./svg-to-png-BX4YEHCP.js");
|
|
524
|
+
return await svgToPngDataUrl(svgString, {
|
|
525
|
+
width: resolution,
|
|
526
|
+
background: backgroundColor
|
|
527
|
+
});
|
|
528
|
+
} catch (error) {
|
|
529
|
+
console.warn(
|
|
530
|
+
"Failed to load native svg-to-png, falling back to browser method:",
|
|
531
|
+
error
|
|
532
|
+
);
|
|
533
|
+
return convertSvgToCanvasBrowser(svgString, resolution, backgroundColor);
|
|
534
|
+
}
|
|
528
535
|
}
|
|
529
536
|
}
|
|
530
537
|
async function convertSvgToCanvasBrowser(svgString, resolution, backgroundColor) {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// lib/utils/svg-to-png.ts
|
|
2
|
+
import { Resvg } from "@resvg/resvg-js";
|
|
3
|
+
async function svgToPng(svgString, options = {}) {
|
|
4
|
+
const opts = {
|
|
5
|
+
background: options.background,
|
|
6
|
+
fitTo: options.width ? {
|
|
7
|
+
mode: "width",
|
|
8
|
+
value: options.width
|
|
9
|
+
} : options.height ? {
|
|
10
|
+
mode: "height",
|
|
11
|
+
value: options.height
|
|
12
|
+
} : void 0,
|
|
13
|
+
font: {
|
|
14
|
+
fontFiles: options.fonts || []
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const resvg = new Resvg(svgString, opts);
|
|
18
|
+
const pngData = resvg.render();
|
|
19
|
+
const pngBuffer = pngData.asPng();
|
|
20
|
+
return Buffer.from(pngBuffer);
|
|
21
|
+
}
|
|
22
|
+
async function svgToPngDataUrl(svgString, options = {}) {
|
|
23
|
+
const pngBuffer = await svgToPng(svgString, options);
|
|
24
|
+
return `data:image/png;base64,${pngBuffer.toString("base64")}`;
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
svgToPng,
|
|
28
|
+
svgToPngDataUrl
|
|
29
|
+
};
|
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
|
-
};
|
|
@@ -1,66 +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(
|
|
13
|
-
currentDir,
|
|
14
|
-
"../../node_modules/@resvg/resvg-wasm/index_bg.wasm"
|
|
15
|
-
);
|
|
16
|
-
const wasmBuffer = readFileSync(wasmPath);
|
|
17
|
-
await initWasm(wasmBuffer);
|
|
18
|
-
} else {
|
|
19
|
-
try {
|
|
20
|
-
const wasmUrl = await import("@resvg/resvg-wasm/index_bg.wasm?url");
|
|
21
|
-
await initWasm(fetch(wasmUrl.default));
|
|
22
|
-
} catch {
|
|
23
|
-
await initWasm(
|
|
24
|
-
fetch("https://unpkg.com/@resvg/resvg-wasm@2.6.2/index_bg.wasm")
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
wasmInitialized = true;
|
|
29
|
-
} catch (error) {
|
|
30
|
-
console.error("Failed to initialize WASM:", error);
|
|
31
|
-
throw error;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
async function svgToPng(svgString, options = {}) {
|
|
36
|
-
await ensureWasmInitialized();
|
|
37
|
-
const opts = {
|
|
38
|
-
background: options.background,
|
|
39
|
-
fitTo: options.width ? {
|
|
40
|
-
mode: "width",
|
|
41
|
-
value: options.width
|
|
42
|
-
} : options.height ? {
|
|
43
|
-
mode: "height",
|
|
44
|
-
value: options.height
|
|
45
|
-
} : void 0
|
|
46
|
-
};
|
|
47
|
-
const resvg = new Resvg(svgString, opts);
|
|
48
|
-
const pngData = resvg.render();
|
|
49
|
-
const pngBuffer = pngData.asPng();
|
|
50
|
-
return pngBuffer;
|
|
51
|
-
}
|
|
52
|
-
async function svgToPngDataUrl(svgString, options = {}) {
|
|
53
|
-
const pngBuffer = await svgToPng(svgString, options);
|
|
54
|
-
let binary = "";
|
|
55
|
-
const bytes = new Uint8Array(pngBuffer);
|
|
56
|
-
const len = bytes.byteLength;
|
|
57
|
-
for (let i = 0; i < len; i++) {
|
|
58
|
-
binary += String.fromCharCode(bytes[i]);
|
|
59
|
-
}
|
|
60
|
-
const base64 = btoa(binary);
|
|
61
|
-
return `data:image/png;base64,${base64}`;
|
|
62
|
-
}
|
|
63
|
-
export {
|
|
64
|
-
svgToPng,
|
|
65
|
-
svgToPngDataUrl
|
|
66
|
-
};
|