circuit-to-svg 0.0.157 → 0.0.159

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
@@ -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
- "pcb_trace",
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
- let svgObjects = circuitJson.sort(
1543
- (a, b) => (OBJECT_ORDER.indexOf(b.type) ?? 9999) - (OBJECT_ORDER.indexOf(a.type) ?? 9999)
1544
- ).flatMap((elm) => createSvgObjects({ elm, circuitJson, ctx }));
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) {
@@ -4048,6 +4079,33 @@ var createSvgSchText = ({
4048
4079
  top_right: "hanging",
4049
4080
  center_left: "middle"
4050
4081
  };
4082
+ const lines = elm.text.split("\n");
4083
+ const children = lines.length === 1 ? [
4084
+ {
4085
+ type: "text",
4086
+ value: elm.text,
4087
+ name: elm.schematic_text_id,
4088
+ attributes: {},
4089
+ children: []
4090
+ }
4091
+ ] : lines.map((line, idx) => ({
4092
+ type: "element",
4093
+ name: "tspan",
4094
+ value: "",
4095
+ attributes: {
4096
+ x: center.x.toString(),
4097
+ ...idx > 0 ? { dy: "1em" } : {}
4098
+ },
4099
+ children: [
4100
+ {
4101
+ type: "text",
4102
+ value: line,
4103
+ name: idx === 0 ? elm.schematic_text_id : "",
4104
+ attributes: {},
4105
+ children: []
4106
+ }
4107
+ ]
4108
+ }));
4051
4109
  return {
4052
4110
  type: "element",
4053
4111
  name: "text",
@@ -4062,15 +4120,7 @@ var createSvgSchText = ({
4062
4120
  "font-size": `${getSchScreenFontSize(transform, "reference_designator", elm.font_size)}px`,
4063
4121
  transform: `rotate(${elm.rotation}, ${center.x}, ${center.y})`
4064
4122
  },
4065
- children: [
4066
- {
4067
- type: "text",
4068
- value: elm.text,
4069
- name: elm.schematic_text_id,
4070
- attributes: {},
4071
- children: []
4072
- }
4073
- ]
4123
+ children
4074
4124
  };
4075
4125
  };
4076
4126