circuit-json-to-gltf 0.0.53 → 0.0.57

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
@@ -14117,6 +14117,11 @@ async function loadGLB(url, transform) {
14117
14117
  return glbCache.get(cacheKey);
14118
14118
  }
14119
14119
  const response = await fetch(url);
14120
+ if (!response.ok) {
14121
+ throw new Error(
14122
+ `Failed to fetch GLB: ${response.status} ${response.statusText}`
14123
+ );
14124
+ }
14120
14125
  const buffer = await response.arrayBuffer();
14121
14126
  const mesh = parseGLB(buffer, transform);
14122
14127
  glbCache.set(cacheKey, mesh);
@@ -14273,20 +14278,7 @@ function extractTrianglesFromGLTF(gltf, binaryBuffer) {
14273
14278
  let indices;
14274
14279
  if (primitive.indices !== void 0) {
14275
14280
  const indexAccessor = gltf.accessors[primitive.indices];
14276
- const indexData = getAccessorData(
14277
- indexAccessor,
14278
- gltf.bufferViews,
14279
- binaryBuffer
14280
- );
14281
- indices = indexAccessor.componentType === 5123 ? new Uint16Array(
14282
- indexData.buffer,
14283
- indexData.byteOffset,
14284
- indexData.length
14285
- ) : new Uint32Array(
14286
- indexData.buffer,
14287
- indexData.byteOffset,
14288
- indexData.length
14289
- );
14281
+ indices = getAccessorData(indexAccessor, gltf.bufferViews, binaryBuffer);
14290
14282
  }
14291
14283
  const vertexCount = positions.length / 3;
14292
14284
  if (indices) {
@@ -14678,7 +14670,7 @@ async function renderBoardLayer(circuitJson, options) {
14678
14670
  }
14679
14671
  async function convertSvgToPng(svgString, resolution, backgroundColor) {
14680
14672
  if (typeof window !== "undefined" && typeof document !== "undefined") {
14681
- const { svgToPngDataUrl } = await import("./svg-to-png-browser-VH734VGT.js");
14673
+ const { svgToPngDataUrl } = await import("./svg-to-png-browser-MXUWCXAZ.js");
14682
14674
  return await svgToPngDataUrl(svgString, {
14683
14675
  width: resolution,
14684
14676
  background: backgroundColor
@@ -14725,20 +14717,18 @@ async function convertSvgToCanvasBrowser(svgString, resolution, backgroundColor)
14725
14717
  });
14726
14718
  }
14727
14719
  async function renderBoardTextures(circuitJson, resolution = 1024) {
14728
- const [top, bottom] = await Promise.all([
14729
- renderBoardLayer(circuitJson, {
14730
- layer: "top",
14731
- resolution,
14732
- backgroundColor: "#0F3812"
14733
- // Green PCB background
14734
- }),
14735
- renderBoardLayer(circuitJson, {
14736
- layer: "bottom",
14737
- resolution,
14738
- backgroundColor: "#0F3812"
14739
- // Darker green for bottom layer
14740
- })
14741
- ]);
14720
+ const top = await renderBoardLayer(circuitJson, {
14721
+ layer: "top",
14722
+ resolution,
14723
+ backgroundColor: "#0F3812"
14724
+ // Green PCB background
14725
+ });
14726
+ const bottom = await renderBoardLayer(circuitJson, {
14727
+ layer: "bottom",
14728
+ resolution,
14729
+ backgroundColor: "#0F3812"
14730
+ // Darker green for bottom layer
14731
+ });
14742
14732
  return { top, bottom };
14743
14733
  }
14744
14734
 
@@ -15187,7 +15177,11 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
15187
15177
  } else if (model_obj_url) {
15188
15178
  box.mesh = await loadOBJ(model_obj_url, defaultTransform);
15189
15179
  } else if (model_glb_url) {
15190
- box.mesh = await loadGLB(model_glb_url, defaultTransform);
15180
+ try {
15181
+ box.mesh = await loadGLB(model_glb_url, defaultTransform);
15182
+ } catch (err) {
15183
+ console.error(`Failed to load GLB from ${model_glb_url}:`, err);
15184
+ }
15191
15185
  } else if (model_gltf_url) {
15192
15186
  box.mesh = await loadGLTF(model_gltf_url, defaultTransform);
15193
15187
  } else if (hasFootprinterModel && cad.footprinter_string) {
@@ -15914,7 +15908,8 @@ var GLTFBuilder = class {
15914
15908
  },
15915
15909
  alphaMode: "BLEND"
15916
15910
  });
15917
- for (const box of scene3D.boxes) {
15911
+ for (let i = 0; i < scene3D.boxes.length; i++) {
15912
+ const box = scene3D.boxes[i];
15918
15913
  await this.addBox(box, defaultMaterialIndex);
15919
15914
  }
15920
15915
  }
@@ -15998,9 +15993,8 @@ var GLTFBuilder = class {
15998
15993
  }
15999
15994
  const primitives = [];
16000
15995
  for (const { meshData, materialIndex } of meshDataArray) {
16001
- const transformedMeshData = convertMeshToGLTFOrientation(
16002
- transformMesh(meshData, box.center, box.rotation)
16003
- );
15996
+ const translatedMesh = transformMesh(meshData, box.center, box.rotation);
15997
+ const transformedMeshData = convertMeshToGLTFOrientation(translatedMesh);
16004
15998
  const positionAccessorIndex = this.addAccessor(
16005
15999
  transformedMeshData.positions,
16006
16000
  "VEC3",
@@ -6,14 +6,18 @@ import {
6
6
  } from "./chunk-QGM4M3NI.js";
7
7
 
8
8
  // lib/utils/svg-to-png-browser.ts
9
- import { Resvg, initWasm } from "@resvg/resvg-wasm";
10
9
  var wasmInitialized = false;
10
+ var Resvg;
11
+ var initWasm;
11
12
  async function ensureWasmInitialized() {
12
13
  if (!wasmInitialized) {
13
14
  try {
14
15
  if (typeof process !== "undefined" && process.versions?.node) {
15
16
  const { readFileSync } = await import("fs");
16
17
  const { dirname, join } = await import("path");
18
+ const resvgModule = await import("@resvg/resvg-wasm");
19
+ Resvg = resvgModule.Resvg;
20
+ initWasm = resvgModule.initWasm;
17
21
  try {
18
22
  const packagePath = __require.resolve("@resvg/resvg-wasm/package.json");
19
23
  const wasmPath = join(dirname(packagePath), "index_bg.wasm");
@@ -33,12 +37,28 @@ async function ensureWasmInitialized() {
33
37
  }
34
38
  } else {
35
39
  try {
40
+ const resvgModule = await import("@resvg/resvg-wasm");
41
+ Resvg = resvgModule.Resvg;
42
+ initWasm = resvgModule.initWasm;
36
43
  const wasmUrl = await import("@resvg/resvg-wasm/index_bg.wasm?url");
37
44
  await initWasm(fetch(wasmUrl.default));
38
45
  } catch {
39
- await initWasm(
40
- fetch("https://unpkg.com/@resvg/resvg-wasm@2.6.2/index_bg.wasm")
41
- );
46
+ try {
47
+ const cdnUrl = "https://cdn.jsdelivr.net/npm/@resvg/resvg-wasm@2.6.2/+esm";
48
+ const resvgModule = await import(
49
+ /* @vite-ignore */
50
+ cdnUrl
51
+ );
52
+ Resvg = resvgModule.Resvg;
53
+ initWasm = resvgModule.initWasm;
54
+ await initWasm(
55
+ fetch("https://unpkg.com/@resvg/resvg-wasm@2.6.2/index_bg.wasm")
56
+ );
57
+ } catch (cdnError) {
58
+ throw new Error(
59
+ `Failed to load resvg-wasm from CDN: ${cdnError.message}`
60
+ );
61
+ }
42
62
  }
43
63
  }
44
64
  wasmInitialized = true;
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.53",
5
+ "version": "0.0.57",
6
6
  "scripts": {
7
7
  "test": "bun test tests/",
8
8
  "format": "biome format --write .",