circuit-to-svg 0.0.252 → 0.0.253

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
@@ -3339,7 +3339,7 @@ function getSoftwareUsedString(circuitJson) {
3339
3339
  var package_default = {
3340
3340
  name: "circuit-to-svg",
3341
3341
  type: "module",
3342
- version: "0.0.251",
3342
+ version: "0.0.252",
3343
3343
  description: "Convert Circuit JSON to SVG",
3344
3344
  main: "dist/index.js",
3345
3345
  files: [
@@ -3499,15 +3499,20 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
3499
3499
  let minY = Number.POSITIVE_INFINITY;
3500
3500
  let maxX = Number.NEGATIVE_INFINITY;
3501
3501
  let maxY = Number.NEGATIVE_INFINITY;
3502
+ let hasBounds = false;
3502
3503
  let boardMinX = Number.POSITIVE_INFINITY;
3503
3504
  let boardMinY = Number.POSITIVE_INFINITY;
3504
3505
  let boardMaxX = Number.NEGATIVE_INFINITY;
3505
3506
  let boardMaxY = Number.NEGATIVE_INFINITY;
3507
+ let hasBoardBounds = false;
3506
3508
  for (const circuitJsonElm of circuitJson) {
3507
3509
  if (circuitJsonElm.type === "pcb_panel") {
3508
3510
  const panel = circuitJsonElm;
3509
- const width = Number(panel.width);
3510
- const height = Number(panel.height);
3511
+ const width = toNumeric(panel.width);
3512
+ const height = toNumeric(panel.height);
3513
+ if (width === void 0 || height === void 0) {
3514
+ continue;
3515
+ }
3511
3516
  const center = { x: width / 2, y: height / 2 };
3512
3517
  updateBounds(center, width, height);
3513
3518
  updateBoardBounds(center, width, height);
@@ -3534,7 +3539,10 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
3534
3539
  if (pad.shape === "rect" || pad.shape === "rotated_rect" || pad.shape === "pill") {
3535
3540
  updateBounds({ x: pad.x, y: pad.y }, pad.width, pad.height);
3536
3541
  } else if (pad.shape === "circle") {
3537
- updateBounds({ x: pad.x, y: pad.y }, pad.radius * 2, pad.radius * 2);
3542
+ const radius = toNumeric(pad.radius);
3543
+ if (radius !== void 0) {
3544
+ updateBounds({ x: pad.x, y: pad.y }, radius * 2, radius * 2);
3545
+ }
3538
3546
  } else if (pad.shape === "polygon") {
3539
3547
  updateTraceBounds(pad.points);
3540
3548
  }
@@ -3551,7 +3559,10 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
3551
3559
  if (cutout.shape === "rect") {
3552
3560
  updateBounds(cutout.center, cutout.width, cutout.height);
3553
3561
  } else if (cutout.shape === "circle") {
3554
- updateBounds(cutout.center, cutout.radius * 2, cutout.radius * 2);
3562
+ const radius = toNumeric(cutout.radius);
3563
+ if (radius !== void 0) {
3564
+ updateBounds(cutout.center, radius * 2, radius * 2);
3565
+ }
3555
3566
  } else if (cutout.shape === "polygon") {
3556
3567
  updateTraceBounds(cutout.points);
3557
3568
  }
@@ -3711,44 +3722,94 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
3711
3722
  console.error("Error stringifying SVG object:", error);
3712
3723
  throw error;
3713
3724
  }
3725
+ function toNumeric(value) {
3726
+ if (typeof value === "number") {
3727
+ return Number.isFinite(value) ? value : void 0;
3728
+ }
3729
+ if (typeof value === "string") {
3730
+ const parsed = Number.parseFloat(value);
3731
+ return Number.isFinite(parsed) ? parsed : void 0;
3732
+ }
3733
+ return void 0;
3734
+ }
3714
3735
  function updateBounds(center, width, height) {
3715
- const halfWidth = width / 2;
3716
- const halfHeight = height / 2;
3717
- minX = Math.min(minX, center.x - halfWidth);
3718
- minY = Math.min(minY, center.y - halfHeight);
3719
- maxX = Math.max(maxX, center.x + halfWidth);
3720
- maxY = Math.max(maxY, center.y + halfHeight);
3736
+ if (!center) return;
3737
+ const centerX = toNumeric(center.x);
3738
+ const centerY = toNumeric(center.y);
3739
+ if (centerX === void 0 || centerY === void 0) return;
3740
+ const numericWidth = toNumeric(width) ?? 0;
3741
+ const numericHeight = toNumeric(height) ?? 0;
3742
+ const halfWidth = numericWidth / 2;
3743
+ const halfHeight = numericHeight / 2;
3744
+ minX = Math.min(minX, centerX - halfWidth);
3745
+ minY = Math.min(minY, centerY - halfHeight);
3746
+ maxX = Math.max(maxX, centerX + halfWidth);
3747
+ maxY = Math.max(maxY, centerY + halfHeight);
3748
+ hasBounds = true;
3721
3749
  }
3722
3750
  function updateBoardBounds(center, width, height) {
3723
- const halfWidth = width / 2;
3724
- const halfHeight = height / 2;
3725
- boardMinX = Math.min(boardMinX, center.x - halfWidth);
3726
- boardMinY = Math.min(boardMinY, center.y - halfHeight);
3727
- boardMaxX = Math.max(boardMaxX, center.x + halfWidth);
3728
- boardMaxY = Math.max(boardMaxY, center.y + halfHeight);
3751
+ if (!center) return;
3752
+ const centerX = toNumeric(center.x);
3753
+ const centerY = toNumeric(center.y);
3754
+ if (centerX === void 0 || centerY === void 0) return;
3755
+ const numericWidth = toNumeric(width) ?? 0;
3756
+ const numericHeight = toNumeric(height) ?? 0;
3757
+ const halfWidth = numericWidth / 2;
3758
+ const halfHeight = numericHeight / 2;
3759
+ boardMinX = Math.min(boardMinX, centerX - halfWidth);
3760
+ boardMinY = Math.min(boardMinY, centerY - halfHeight);
3761
+ boardMaxX = Math.max(boardMaxX, centerX + halfWidth);
3762
+ boardMaxY = Math.max(boardMaxY, centerY + halfHeight);
3763
+ hasBounds = true;
3764
+ hasBoardBounds = true;
3729
3765
  }
3730
3766
  function updateBoundsToIncludeOutline(outline) {
3767
+ let updated = false;
3731
3768
  for (const point of outline) {
3732
- minX = Math.min(minX, point.x);
3733
- minY = Math.min(minY, point.y);
3734
- maxX = Math.max(maxX, point.x);
3735
- maxY = Math.max(maxY, point.y);
3769
+ const x = toNumeric(point.x);
3770
+ const y = toNumeric(point.y);
3771
+ if (x === void 0 || y === void 0) continue;
3772
+ minX = Math.min(minX, x);
3773
+ minY = Math.min(minY, y);
3774
+ maxX = Math.max(maxX, x);
3775
+ maxY = Math.max(maxY, y);
3776
+ updated = true;
3777
+ }
3778
+ if (updated) {
3779
+ hasBounds = true;
3736
3780
  }
3737
3781
  }
3738
3782
  function updateBoardBoundsToIncludeOutline(outline) {
3783
+ let updated = false;
3739
3784
  for (const point of outline) {
3740
- boardMinX = Math.min(boardMinX, point.x);
3741
- boardMinY = Math.min(boardMinY, point.y);
3742
- boardMaxX = Math.max(boardMaxX, point.x);
3743
- boardMaxY = Math.max(boardMaxY, point.y);
3785
+ const x = toNumeric(point.x);
3786
+ const y = toNumeric(point.y);
3787
+ if (x === void 0 || y === void 0) continue;
3788
+ boardMinX = Math.min(boardMinX, x);
3789
+ boardMinY = Math.min(boardMinY, y);
3790
+ boardMaxX = Math.max(boardMaxX, x);
3791
+ boardMaxY = Math.max(boardMaxY, y);
3792
+ updated = true;
3793
+ }
3794
+ if (updated) {
3795
+ hasBounds = true;
3796
+ hasBoardBounds = true;
3744
3797
  }
3745
3798
  }
3746
3799
  function updateTraceBounds(route) {
3800
+ let updated = false;
3747
3801
  for (const point of route) {
3748
- minX = Math.min(minX, point.x);
3749
- minY = Math.min(minY, point.y);
3750
- maxX = Math.max(maxX, point.x);
3751
- maxY = Math.max(maxY, point.y);
3802
+ const x = toNumeric(point?.x);
3803
+ const y = toNumeric(point?.y);
3804
+ if (x === void 0 || y === void 0) continue;
3805
+ minX = Math.min(minX, x);
3806
+ minY = Math.min(minY, y);
3807
+ maxX = Math.max(maxX, x);
3808
+ maxY = Math.max(maxY, y);
3809
+ updated = true;
3810
+ }
3811
+ if (updated) {
3812
+ hasBounds = true;
3752
3813
  }
3753
3814
  }
3754
3815
  function updateSilkscreenBounds(item) {
@@ -3759,7 +3820,10 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
3759
3820
  } else if (item.type === "pcb_silkscreen_rect") {
3760
3821
  updateBounds(item.center, item.width, item.height);
3761
3822
  } else if (item.type === "pcb_silkscreen_circle") {
3762
- updateBounds(item.center, item.radius * 2, item.radius * 2);
3823
+ const radius = toNumeric(item.radius);
3824
+ if (radius !== void 0) {
3825
+ updateBounds(item.center, radius * 2, radius * 2);
3826
+ }
3763
3827
  } else if (item.type === "pcb_silkscreen_line") {
3764
3828
  updateBounds({ x: item.x1, y: item.y1 }, 0, 0);
3765
3829
  updateBounds({ x: item.x2, y: item.y2 }, 0, 0);
@@ -3768,7 +3832,10 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
3768
3832
  if (cutout.shape === "rect") {
3769
3833
  updateBounds(cutout.center, cutout.width, cutout.height);
3770
3834
  } else if (cutout.shape === "circle") {
3771
- updateBounds(cutout.center, cutout.radius * 2, cutout.radius * 2);
3835
+ const radius = toNumeric(cutout.radius);
3836
+ if (radius !== void 0) {
3837
+ updateBounds(cutout.center, radius * 2, radius * 2);
3838
+ }
3772
3839
  } else if (cutout.shape === "polygon") {
3773
3840
  updateTraceBounds(cutout.points);
3774
3841
  }