circuit-to-svg 0.0.157 → 0.0.158
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 +40 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -938,7 +938,8 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
|
|
|
938
938
|
y: (-height / 2).toString(),
|
|
939
939
|
width: width.toString(),
|
|
940
940
|
height: height.toString(),
|
|
941
|
-
transform: `translate(${x} ${y}) rotate(${-pad.ccw_rotation})
|
|
941
|
+
transform: `translate(${x} ${y}) rotate(${-pad.ccw_rotation})`,
|
|
942
|
+
"data-layer": pad.layer
|
|
942
943
|
}
|
|
943
944
|
}
|
|
944
945
|
];
|
|
@@ -953,7 +954,8 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
|
|
|
953
954
|
x: (x - width / 2).toString(),
|
|
954
955
|
y: (y - height / 2).toString(),
|
|
955
956
|
width: width.toString(),
|
|
956
|
-
height: height.toString()
|
|
957
|
+
height: height.toString(),
|
|
958
|
+
"data-layer": pad.layer
|
|
957
959
|
}
|
|
958
960
|
}
|
|
959
961
|
];
|
|
@@ -975,7 +977,8 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
|
|
|
975
977
|
width: width.toString(),
|
|
976
978
|
height: height.toString(),
|
|
977
979
|
rx: radius.toString(),
|
|
978
|
-
ry: radius.toString()
|
|
980
|
+
ry: radius.toString(),
|
|
981
|
+
"data-layer": pad.layer
|
|
979
982
|
}
|
|
980
983
|
}
|
|
981
984
|
];
|
|
@@ -992,7 +995,8 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
|
|
|
992
995
|
fill: layerNameToColor(pad.layer, colorMap2),
|
|
993
996
|
cx: x.toString(),
|
|
994
997
|
cy: y.toString(),
|
|
995
|
-
r: radius.toString()
|
|
998
|
+
r: radius.toString(),
|
|
999
|
+
"data-layer": pad.layer
|
|
996
1000
|
}
|
|
997
1001
|
}
|
|
998
1002
|
];
|
|
@@ -1008,7 +1012,8 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
|
|
|
1008
1012
|
attributes: {
|
|
1009
1013
|
class: "pcb-pad",
|
|
1010
1014
|
fill: layerNameToColor(pad.layer),
|
|
1011
|
-
points
|
|
1015
|
+
points,
|
|
1016
|
+
"data-layer": pad.layer
|
|
1012
1017
|
}
|
|
1013
1018
|
}
|
|
1014
1019
|
];
|
|
@@ -1428,8 +1433,9 @@ var OBJECT_ORDER = [
|
|
|
1428
1433
|
"pcb_silkscreen_path",
|
|
1429
1434
|
"pcb_via",
|
|
1430
1435
|
"pcb_cutout",
|
|
1431
|
-
|
|
1436
|
+
// Draw traces before SMT pads so pads appear on top
|
|
1432
1437
|
"pcb_smtpad",
|
|
1438
|
+
"pcb_trace",
|
|
1433
1439
|
"pcb_component",
|
|
1434
1440
|
"pcb_board"
|
|
1435
1441
|
];
|
|
@@ -1539,9 +1545,34 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
1539
1545
|
drawPaddingOutsideBoard,
|
|
1540
1546
|
colorMap: colorMap2
|
|
1541
1547
|
};
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1548
|
+
function getLayer(elm) {
|
|
1549
|
+
if (elm.type === "pcb_smtpad") {
|
|
1550
|
+
return elm.layer === "top" || elm.layer === "bottom" ? elm.layer : void 0;
|
|
1551
|
+
}
|
|
1552
|
+
if (elm.type === "pcb_trace") {
|
|
1553
|
+
for (const seg of elm.route ?? []) {
|
|
1554
|
+
const candidate = "layer" in seg && seg.layer || "from_layer" in seg && seg.from_layer || "to_layer" in seg && seg.to_layer || void 0;
|
|
1555
|
+
if (candidate === "top" || candidate === "bottom") {
|
|
1556
|
+
return candidate;
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
return void 0;
|
|
1561
|
+
}
|
|
1562
|
+
function isCopper(elm) {
|
|
1563
|
+
return elm.type === "pcb_trace" || elm.type === "pcb_smtpad";
|
|
1564
|
+
}
|
|
1565
|
+
let svgObjects = circuitJson.sort((a, b) => {
|
|
1566
|
+
const layerA = getLayer(a);
|
|
1567
|
+
const layerB = getLayer(b);
|
|
1568
|
+
if (isCopper(a) && isCopper(b) && layerA !== layerB) {
|
|
1569
|
+
if (layerA === "top") return 1;
|
|
1570
|
+
if (layerB === "top") return -1;
|
|
1571
|
+
if (layerA === "bottom") return -1;
|
|
1572
|
+
if (layerB === "bottom") return 1;
|
|
1573
|
+
}
|
|
1574
|
+
return (OBJECT_ORDER.indexOf(b.type) ?? 9999) - (OBJECT_ORDER.indexOf(a.type) ?? 9999);
|
|
1575
|
+
}).flatMap((elm) => createSvgObjects({ elm, circuitJson, ctx }));
|
|
1545
1576
|
let strokeWidth = String(0.05 * scaleFactor);
|
|
1546
1577
|
for (const element of circuitJson) {
|
|
1547
1578
|
if ("stroke_width" in element) {
|