circuit-json-to-gltf 0.0.5 → 0.0.7

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/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
- const { svgToPngDataUrl } = await import("./svg-to-png-browser-ZI5PXAWS.js");
524
- return await svgToPngDataUrl(svgString, {
525
- width: resolution,
526
- background: backgroundColor
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) {
@@ -1763,7 +1770,15 @@ var GLTFBuilder = class {
1763
1770
  }
1764
1771
  }
1765
1772
  createGLB(gltf, bufferData) {
1766
- const jsonString = JSON.stringify(gltf);
1773
+ const gltfWithBuffer = {
1774
+ ...gltf,
1775
+ buffers: [
1776
+ {
1777
+ byteLength: bufferData.byteLength
1778
+ }
1779
+ ]
1780
+ };
1781
+ const jsonString = JSON.stringify(gltfWithBuffer);
1767
1782
  const jsonData = new TextEncoder().encode(jsonString);
1768
1783
  const jsonPadding = (4 - jsonData.length % 4) % 4;
1769
1784
  const jsonLength = jsonData.length + jsonPadding;
@@ -1777,8 +1792,11 @@ var GLTFBuilder = class {
1777
1792
  view.setUint32(8, totalSize, true);
1778
1793
  view.setUint32(12, jsonLength, true);
1779
1794
  view.setUint32(16, 1313821514, true);
1780
- const jsonArray = new Uint8Array(glb, 20, jsonData.length);
1795
+ const jsonArray = new Uint8Array(glb, 20, jsonLength);
1781
1796
  jsonArray.set(jsonData);
1797
+ for (let i = jsonData.length; i < jsonLength; i++) {
1798
+ jsonArray[i] = 32;
1799
+ }
1782
1800
  const binChunkOffset = 20 + jsonLength;
1783
1801
  view.setUint32(binChunkOffset, binLength, true);
1784
1802
  view.setUint32(binChunkOffset + 4, 5130562, true);
@@ -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
@@ -2,7 +2,7 @@
2
2
  "name": "circuit-json-to-gltf",
3
3
  "main": "dist/index.js",
4
4
  "type": "module",
5
- "version": "0.0.5",
5
+ "version": "0.0.7",
6
6
  "scripts": {
7
7
  "test": "bun test tests/",
8
8
  "format": "biome format --write .",
@@ -1,60 +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 wasmPath = await import("@resvg/resvg-wasm/index_bg.wasm");
10
- const wasmBuffer = readFileSync(wasmPath);
11
- await initWasm(wasmBuffer);
12
- } else {
13
- try {
14
- const wasmUrl = await import("@resvg/resvg-wasm/index_bg.wasm?url");
15
- await initWasm(fetch(wasmUrl.default));
16
- } catch {
17
- await initWasm(
18
- fetch("https://unpkg.com/@resvg/resvg-wasm@2.6.2/index_bg.wasm")
19
- );
20
- }
21
- }
22
- wasmInitialized = true;
23
- } catch (error) {
24
- console.error("Failed to initialize WASM:", error);
25
- throw error;
26
- }
27
- }
28
- }
29
- async function svgToPng(svgString, options = {}) {
30
- await ensureWasmInitialized();
31
- const opts = {
32
- background: options.background,
33
- fitTo: options.width ? {
34
- mode: "width",
35
- value: options.width
36
- } : options.height ? {
37
- mode: "height",
38
- value: options.height
39
- } : void 0
40
- };
41
- const resvg = new Resvg(svgString, opts);
42
- const pngData = resvg.render();
43
- const pngBuffer = pngData.asPng();
44
- return pngBuffer;
45
- }
46
- async function svgToPngDataUrl(svgString, options = {}) {
47
- const pngBuffer = await svgToPng(svgString, options);
48
- let binary = "";
49
- const bytes = new Uint8Array(pngBuffer);
50
- const len = bytes.byteLength;
51
- for (let i = 0; i < len; i++) {
52
- binary += String.fromCharCode(bytes[i]);
53
- }
54
- const base64 = btoa(binary);
55
- return `data:image/png;base64,${base64}`;
56
- }
57
- export {
58
- svgToPng,
59
- svgToPngDataUrl
60
- };