circuit-to-svg 0.0.258 → 0.0.259
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 +38 -40
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// lib/pcb/convert-circuit-json-to-pcb-svg.ts
|
|
2
|
+
import { distance } from "circuit-json";
|
|
2
3
|
import { stringify } from "svgson";
|
|
3
4
|
import {
|
|
4
5
|
applyToPoint as applyToPoint31,
|
|
@@ -2902,9 +2903,9 @@ var findNearestPointInNet = (sourcePoint, netId, connectivity, circuitJson) => {
|
|
|
2902
2903
|
if (pos) {
|
|
2903
2904
|
const dx = sourcePoint.x - pos.x;
|
|
2904
2905
|
const dy = sourcePoint.y - pos.y;
|
|
2905
|
-
const
|
|
2906
|
-
if (
|
|
2907
|
-
minDistance =
|
|
2906
|
+
const distance3 = Math.sqrt(dx * dx + dy * dy);
|
|
2907
|
+
if (distance3 > 0 && distance3 < minDistance) {
|
|
2908
|
+
minDistance = distance3;
|
|
2908
2909
|
nearestPoint = pos;
|
|
2909
2910
|
}
|
|
2910
2911
|
}
|
|
@@ -3471,7 +3472,7 @@ function getSoftwareUsedString(circuitJson) {
|
|
|
3471
3472
|
var package_default = {
|
|
3472
3473
|
name: "circuit-to-svg",
|
|
3473
3474
|
type: "module",
|
|
3474
|
-
version: "0.0.
|
|
3475
|
+
version: "0.0.258",
|
|
3475
3476
|
description: "Convert Circuit JSON to SVG",
|
|
3476
3477
|
main: "dist/index.js",
|
|
3477
3478
|
files: [
|
|
@@ -3495,12 +3496,12 @@ var package_default = {
|
|
|
3495
3496
|
"bun-match-svg": "^0.0.12",
|
|
3496
3497
|
esbuild: "^0.20.2",
|
|
3497
3498
|
"performance-now": "^2.1.0",
|
|
3498
|
-
"circuit-json": "^0.0.
|
|
3499
|
+
"circuit-json": "^0.0.296",
|
|
3499
3500
|
react: "19.1.0",
|
|
3500
3501
|
"react-cosmos": "7.0.0",
|
|
3501
3502
|
"react-cosmos-plugin-vite": "7.0.0",
|
|
3502
3503
|
"react-dom": "19.1.0",
|
|
3503
|
-
tscircuit: "^0.0.
|
|
3504
|
+
tscircuit: "^0.0.827",
|
|
3504
3505
|
tsup: "^8.0.2",
|
|
3505
3506
|
typescript: "^5.4.5",
|
|
3506
3507
|
"vite-tsconfig-paths": "^5.0.1"
|
|
@@ -3640,14 +3641,13 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
3640
3641
|
for (const circuitJsonElm of circuitJson) {
|
|
3641
3642
|
if (circuitJsonElm.type === "pcb_panel") {
|
|
3642
3643
|
const panel = circuitJsonElm;
|
|
3643
|
-
const width =
|
|
3644
|
-
const height =
|
|
3644
|
+
const width = distance.parse(panel.width);
|
|
3645
|
+
const height = distance.parse(panel.height);
|
|
3645
3646
|
if (width === void 0 || height === void 0) {
|
|
3646
3647
|
continue;
|
|
3647
3648
|
}
|
|
3648
3649
|
const center = { x: width / 2, y: height / 2 };
|
|
3649
3650
|
updateBounds(center, width, height);
|
|
3650
|
-
updateBoardBounds(center, width, height);
|
|
3651
3651
|
} else if (circuitJsonElm.type === "pcb_board") {
|
|
3652
3652
|
if (circuitJsonElm.outline && Array.isArray(circuitJsonElm.outline) && circuitJsonElm.outline.length >= 3) {
|
|
3653
3653
|
updateBoundsToIncludeOutline(circuitJsonElm.outline);
|
|
@@ -3664,20 +3664,20 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
3664
3664
|
circuitJsonElm.height
|
|
3665
3665
|
);
|
|
3666
3666
|
}
|
|
3667
|
-
} else if ("x" in circuitJsonElm && "y" in circuitJsonElm) {
|
|
3668
|
-
updateBounds({ x: circuitJsonElm.x, y: circuitJsonElm.y }, 0, 0);
|
|
3669
3667
|
} else if (circuitJsonElm.type === "pcb_smtpad") {
|
|
3670
3668
|
const pad = circuitJsonElm;
|
|
3671
3669
|
if (pad.shape === "rect" || pad.shape === "rotated_rect" || pad.shape === "pill") {
|
|
3672
3670
|
updateBounds({ x: pad.x, y: pad.y }, pad.width, pad.height);
|
|
3673
3671
|
} else if (pad.shape === "circle") {
|
|
3674
|
-
const radius =
|
|
3672
|
+
const radius = distance.parse(pad.radius);
|
|
3675
3673
|
if (radius !== void 0) {
|
|
3676
3674
|
updateBounds({ x: pad.x, y: pad.y }, radius * 2, radius * 2);
|
|
3677
3675
|
}
|
|
3678
3676
|
} else if (pad.shape === "polygon") {
|
|
3679
3677
|
updateTraceBounds(pad.points);
|
|
3680
3678
|
}
|
|
3679
|
+
} else if ("x" in circuitJsonElm && "y" in circuitJsonElm) {
|
|
3680
|
+
updateBounds({ x: circuitJsonElm.x, y: circuitJsonElm.y }, 0, 0);
|
|
3681
3681
|
} else if ("route" in circuitJsonElm) {
|
|
3682
3682
|
updateTraceBounds(circuitJsonElm.route);
|
|
3683
3683
|
} else if (circuitJsonElm.type === "pcb_note_rect" || circuitJsonElm.type === "pcb_fabrication_note_rect") {
|
|
@@ -3691,7 +3691,7 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
3691
3691
|
if (cutout.shape === "rect") {
|
|
3692
3692
|
updateBounds(cutout.center, cutout.width, cutout.height);
|
|
3693
3693
|
} else if (cutout.shape === "circle") {
|
|
3694
|
-
const radius =
|
|
3694
|
+
const radius = distance.parse(cutout.radius);
|
|
3695
3695
|
if (radius !== void 0) {
|
|
3696
3696
|
updateBounds(cutout.center, radius * 2, radius * 2);
|
|
3697
3697
|
}
|
|
@@ -3854,23 +3854,13 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
3854
3854
|
console.error("Error stringifying SVG object:", error);
|
|
3855
3855
|
throw error;
|
|
3856
3856
|
}
|
|
3857
|
-
function toNumeric(value) {
|
|
3858
|
-
if (typeof value === "number") {
|
|
3859
|
-
return Number.isFinite(value) ? value : void 0;
|
|
3860
|
-
}
|
|
3861
|
-
if (typeof value === "string") {
|
|
3862
|
-
const parsed = Number.parseFloat(value);
|
|
3863
|
-
return Number.isFinite(parsed) ? parsed : void 0;
|
|
3864
|
-
}
|
|
3865
|
-
return void 0;
|
|
3866
|
-
}
|
|
3867
3857
|
function updateBounds(center, width, height) {
|
|
3868
3858
|
if (!center) return;
|
|
3869
|
-
const centerX =
|
|
3870
|
-
const centerY =
|
|
3859
|
+
const centerX = distance.parse(center.x);
|
|
3860
|
+
const centerY = distance.parse(center.y);
|
|
3871
3861
|
if (centerX === void 0 || centerY === void 0) return;
|
|
3872
|
-
const numericWidth =
|
|
3873
|
-
const numericHeight =
|
|
3862
|
+
const numericWidth = distance.parse(width) ?? 0;
|
|
3863
|
+
const numericHeight = distance.parse(height) ?? 0;
|
|
3874
3864
|
const halfWidth = numericWidth / 2;
|
|
3875
3865
|
const halfHeight = numericHeight / 2;
|
|
3876
3866
|
minX = Math.min(minX, centerX - halfWidth);
|
|
@@ -3881,11 +3871,11 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
3881
3871
|
}
|
|
3882
3872
|
function updateBoardBounds(center, width, height) {
|
|
3883
3873
|
if (!center) return;
|
|
3884
|
-
const centerX =
|
|
3885
|
-
const centerY =
|
|
3874
|
+
const centerX = distance.parse(center.x);
|
|
3875
|
+
const centerY = distance.parse(center.y);
|
|
3886
3876
|
if (centerX === void 0 || centerY === void 0) return;
|
|
3887
|
-
const numericWidth =
|
|
3888
|
-
const numericHeight =
|
|
3877
|
+
const numericWidth = distance.parse(width) ?? 0;
|
|
3878
|
+
const numericHeight = distance.parse(height) ?? 0;
|
|
3889
3879
|
const halfWidth = numericWidth / 2;
|
|
3890
3880
|
const halfHeight = numericHeight / 2;
|
|
3891
3881
|
boardMinX = Math.min(boardMinX, centerX - halfWidth);
|
|
@@ -3898,8 +3888,8 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
3898
3888
|
function updateBoundsToIncludeOutline(outline) {
|
|
3899
3889
|
let updated = false;
|
|
3900
3890
|
for (const point of outline) {
|
|
3901
|
-
const x =
|
|
3902
|
-
const y =
|
|
3891
|
+
const x = distance.parse(point.x);
|
|
3892
|
+
const y = distance.parse(point.y);
|
|
3903
3893
|
if (x === void 0 || y === void 0) continue;
|
|
3904
3894
|
minX = Math.min(minX, x);
|
|
3905
3895
|
minY = Math.min(minY, y);
|
|
@@ -3914,8 +3904,8 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
3914
3904
|
function updateBoardBoundsToIncludeOutline(outline) {
|
|
3915
3905
|
let updated = false;
|
|
3916
3906
|
for (const point of outline) {
|
|
3917
|
-
const x =
|
|
3918
|
-
const y =
|
|
3907
|
+
const x = distance.parse(point.x);
|
|
3908
|
+
const y = distance.parse(point.y);
|
|
3919
3909
|
if (x === void 0 || y === void 0) continue;
|
|
3920
3910
|
boardMinX = Math.min(boardMinX, x);
|
|
3921
3911
|
boardMinY = Math.min(boardMinY, y);
|
|
@@ -3931,8 +3921,8 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
3931
3921
|
function updateTraceBounds(route) {
|
|
3932
3922
|
let updated = false;
|
|
3933
3923
|
for (const point of route) {
|
|
3934
|
-
const x =
|
|
3935
|
-
const y =
|
|
3924
|
+
const x = distance.parse(point?.x);
|
|
3925
|
+
const y = distance.parse(point?.y);
|
|
3936
3926
|
if (x === void 0 || y === void 0) continue;
|
|
3937
3927
|
minX = Math.min(minX, x);
|
|
3938
3928
|
minY = Math.min(minY, y);
|
|
@@ -3952,7 +3942,7 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
3952
3942
|
} else if (item.type === "pcb_silkscreen_rect") {
|
|
3953
3943
|
updateBounds(item.center, item.width, item.height);
|
|
3954
3944
|
} else if (item.type === "pcb_silkscreen_circle") {
|
|
3955
|
-
const radius =
|
|
3945
|
+
const radius = distance.parse(item.radius);
|
|
3956
3946
|
if (radius !== void 0) {
|
|
3957
3947
|
updateBounds(item.center, radius * 2, radius * 2);
|
|
3958
3948
|
}
|
|
@@ -3964,7 +3954,7 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
3964
3954
|
if (cutout.shape === "rect") {
|
|
3965
3955
|
updateBounds(cutout.center, cutout.width, cutout.height);
|
|
3966
3956
|
} else if (cutout.shape === "circle") {
|
|
3967
|
-
const radius =
|
|
3957
|
+
const radius = distance.parse(cutout.radius);
|
|
3968
3958
|
if (radius !== void 0) {
|
|
3969
3959
|
updateBounds(cutout.center, radius * 2, radius * 2);
|
|
3970
3960
|
}
|
|
@@ -10558,6 +10548,7 @@ function formatNumber2(value) {
|
|
|
10558
10548
|
}
|
|
10559
10549
|
|
|
10560
10550
|
// lib/pcb/convert-circuit-json-to-solder-paste-mask.ts
|
|
10551
|
+
import { distance as distance2 } from "circuit-json";
|
|
10561
10552
|
import { stringify as stringify7 } from "svgson";
|
|
10562
10553
|
import {
|
|
10563
10554
|
applyToPoint as applyToPoint70,
|
|
@@ -10664,7 +10655,7 @@ function convertCircuitJsonToSolderPasteMask(circuitJson, options) {
|
|
|
10664
10655
|
let maxX = Number.NEGATIVE_INFINITY;
|
|
10665
10656
|
let maxY = Number.NEGATIVE_INFINITY;
|
|
10666
10657
|
const filteredCircuitJson = circuitJson.filter(
|
|
10667
|
-
(elm) => elm.type === "pcb_board" || elm.type === "pcb_solder_paste" && elm.layer === options.layer
|
|
10658
|
+
(elm) => elm.type === "pcb_board" || elm.type === "pcb_panel" || elm.type === "pcb_solder_paste" && elm.layer === options.layer
|
|
10668
10659
|
);
|
|
10669
10660
|
for (const item of filteredCircuitJson) {
|
|
10670
10661
|
if (item.type === "pcb_board") {
|
|
@@ -10673,6 +10664,13 @@ function convertCircuitJsonToSolderPasteMask(circuitJson, options) {
|
|
|
10673
10664
|
} else if ("center" in item && "width" in item && "height" in item) {
|
|
10674
10665
|
updateBounds(item.center, item.width, item.height);
|
|
10675
10666
|
}
|
|
10667
|
+
} else if (item.type === "pcb_panel") {
|
|
10668
|
+
const panel = item;
|
|
10669
|
+
const width = distance2.parse(panel.width);
|
|
10670
|
+
const height = distance2.parse(panel.height);
|
|
10671
|
+
if (width !== void 0 && height !== void 0) {
|
|
10672
|
+
updateBounds({ x: width / 2, y: height / 2 }, width, height);
|
|
10673
|
+
}
|
|
10676
10674
|
} else if (item.type === "pcb_solder_paste" && "x" in item && "y" in item) {
|
|
10677
10675
|
updateBounds({ x: item.x, y: item.y }, 0, 0);
|
|
10678
10676
|
}
|