circuit-to-svg 0.0.156 → 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.d.ts +3 -1
- package/dist/index.js +70 -14
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -250,4 +250,6 @@ interface Options {
|
|
|
250
250
|
}
|
|
251
251
|
declare function convertCircuitJsonToSolderPasteMask(circuitJson: AnyCircuitElement[], options: Options): string;
|
|
252
252
|
|
|
253
|
-
|
|
253
|
+
declare function getSoftwareUsedString(circuitJson: AnyCircuitElement[]): string | undefined;
|
|
254
|
+
|
|
255
|
+
export { type ColorMap, type ColorOverrides, type PcbColorMap, type PcbColorOverrides, type PcbContext, circuitJsonToPcbSvg, circuitJsonToSchematicSvg, convertCircuitJsonToAssemblySvg, convertCircuitJsonToPcbSvg, convertCircuitJsonToSchematicSvg, convertCircuitJsonToSolderPasteMask, getSoftwareUsedString };
|
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
|
];
|
|
@@ -1410,6 +1415,14 @@ function createSvgObjectsFromPcbComponent(component, ctx) {
|
|
|
1410
1415
|
];
|
|
1411
1416
|
}
|
|
1412
1417
|
|
|
1418
|
+
// lib/utils/get-software-used-string.ts
|
|
1419
|
+
function getSoftwareUsedString(circuitJson) {
|
|
1420
|
+
const metadata = circuitJson.find(
|
|
1421
|
+
(e) => e.type === "project_software_metadata" || e.type === "source_project_metadata"
|
|
1422
|
+
);
|
|
1423
|
+
return metadata?.software_used_string;
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1413
1426
|
// lib/pcb/convert-circuit-json-to-pcb-svg.ts
|
|
1414
1427
|
var OBJECT_ORDER = [
|
|
1415
1428
|
"pcb_trace_error",
|
|
@@ -1420,8 +1433,9 @@ var OBJECT_ORDER = [
|
|
|
1420
1433
|
"pcb_silkscreen_path",
|
|
1421
1434
|
"pcb_via",
|
|
1422
1435
|
"pcb_cutout",
|
|
1423
|
-
|
|
1436
|
+
// Draw traces before SMT pads so pads appear on top
|
|
1424
1437
|
"pcb_smtpad",
|
|
1438
|
+
"pcb_trace",
|
|
1425
1439
|
"pcb_component",
|
|
1426
1440
|
"pcb_board"
|
|
1427
1441
|
];
|
|
@@ -1531,9 +1545,34 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
1531
1545
|
drawPaddingOutsideBoard,
|
|
1532
1546
|
colorMap: colorMap2
|
|
1533
1547
|
};
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
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 }));
|
|
1537
1576
|
let strokeWidth = String(0.05 * scaleFactor);
|
|
1538
1577
|
for (const element of circuitJson) {
|
|
1539
1578
|
if ("stroke_width" in element) {
|
|
@@ -1582,13 +1621,17 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
1582
1621
|
);
|
|
1583
1622
|
}
|
|
1584
1623
|
children.push(...svgObjects);
|
|
1624
|
+
const softwareUsedString = getSoftwareUsedString(circuitJson);
|
|
1585
1625
|
const svgObject = {
|
|
1586
1626
|
name: "svg",
|
|
1587
1627
|
type: "element",
|
|
1588
1628
|
attributes: {
|
|
1589
1629
|
xmlns: "http://www.w3.org/2000/svg",
|
|
1590
1630
|
width: svgWidth.toString(),
|
|
1591
|
-
height: svgHeight.toString()
|
|
1631
|
+
height: svgHeight.toString(),
|
|
1632
|
+
...softwareUsedString && {
|
|
1633
|
+
"data-software-used-string": softwareUsedString
|
|
1634
|
+
}
|
|
1592
1635
|
},
|
|
1593
1636
|
value: "",
|
|
1594
1637
|
children: children.filter((child) => child !== null)
|
|
@@ -2019,13 +2062,17 @@ function convertCircuitJsonToAssemblySvg(soup, options) {
|
|
|
2019
2062
|
const svgObjects = soup.sort(
|
|
2020
2063
|
(a, b) => (OBJECT_ORDER2.indexOf(b.type) ?? 9999) - (OBJECT_ORDER2.indexOf(a.type) ?? 9999)
|
|
2021
2064
|
).flatMap((item) => createSvgObjects2(item, transform, soup));
|
|
2065
|
+
const softwareUsedString = getSoftwareUsedString(soup);
|
|
2022
2066
|
const svgObject = {
|
|
2023
2067
|
name: "svg",
|
|
2024
2068
|
type: "element",
|
|
2025
2069
|
attributes: {
|
|
2026
2070
|
xmlns: "http://www.w3.org/2000/svg",
|
|
2027
2071
|
width: svgWidth.toString(),
|
|
2028
|
-
height: svgHeight.toString()
|
|
2072
|
+
height: svgHeight.toString(),
|
|
2073
|
+
...softwareUsedString && {
|
|
2074
|
+
"data-software-used-string": softwareUsedString
|
|
2075
|
+
}
|
|
2029
2076
|
},
|
|
2030
2077
|
value: "",
|
|
2031
2078
|
children: [
|
|
@@ -5047,6 +5094,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
5047
5094
|
})
|
|
5048
5095
|
);
|
|
5049
5096
|
}
|
|
5097
|
+
const softwareUsedString = getSoftwareUsedString(circuitJson);
|
|
5050
5098
|
const svgObject = {
|
|
5051
5099
|
name: "svg",
|
|
5052
5100
|
type: "element",
|
|
@@ -5055,7 +5103,10 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
5055
5103
|
width: svgWidth.toString(),
|
|
5056
5104
|
height: svgHeight.toString(),
|
|
5057
5105
|
style: `background-color: ${colorMap2.schematic.background}`,
|
|
5058
|
-
"data-real-to-screen-transform": toSVG(transform)
|
|
5106
|
+
"data-real-to-screen-transform": toSVG(transform),
|
|
5107
|
+
...softwareUsedString && {
|
|
5108
|
+
"data-software-used-string": softwareUsedString
|
|
5109
|
+
}
|
|
5059
5110
|
},
|
|
5060
5111
|
children: [
|
|
5061
5112
|
// Add styles
|
|
@@ -5241,13 +5292,17 @@ function convertCircuitJsonToSolderPasteMask(circuitJson, options) {
|
|
|
5241
5292
|
const svgObjects = filteredCircuitJson.sort(
|
|
5242
5293
|
(a, b) => (OBJECT_ORDER3.indexOf(b.type) ?? 9999) - (OBJECT_ORDER3.indexOf(a.type) ?? 9999)
|
|
5243
5294
|
).flatMap((item) => createSvgObjects3({ elm: item, ctx }));
|
|
5295
|
+
const softwareUsedString = getSoftwareUsedString(circuitJson);
|
|
5244
5296
|
const svgObject = {
|
|
5245
5297
|
name: "svg",
|
|
5246
5298
|
type: "element",
|
|
5247
5299
|
attributes: {
|
|
5248
5300
|
xmlns: "http://www.w3.org/2000/svg",
|
|
5249
5301
|
width: svgWidth.toString(),
|
|
5250
|
-
height: svgHeight.toString()
|
|
5302
|
+
height: svgHeight.toString(),
|
|
5303
|
+
...softwareUsedString && {
|
|
5304
|
+
"data-software-used-string": softwareUsedString
|
|
5305
|
+
}
|
|
5251
5306
|
},
|
|
5252
5307
|
value: "",
|
|
5253
5308
|
children: [
|
|
@@ -5341,6 +5396,7 @@ export {
|
|
|
5341
5396
|
convertCircuitJsonToAssemblySvg,
|
|
5342
5397
|
convertCircuitJsonToPcbSvg,
|
|
5343
5398
|
convertCircuitJsonToSchematicSvg,
|
|
5344
|
-
convertCircuitJsonToSolderPasteMask
|
|
5399
|
+
convertCircuitJsonToSolderPasteMask,
|
|
5400
|
+
getSoftwareUsedString
|
|
5345
5401
|
};
|
|
5346
5402
|
//# sourceMappingURL=index.js.map
|