@tscircuit/circuit-json-util 0.0.101 → 0.0.103

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
@@ -884,9 +884,9 @@ var insertionDirectionToVec = (direction) => {
884
884
  return { x: -1, y: 0 };
885
885
  case "from_right":
886
886
  return { x: 1, y: 0 };
887
- case "from_front":
887
+ case "from_top":
888
888
  return { x: 0, y: 1 };
889
- case "from_back":
889
+ case "from_bottom":
890
890
  return { x: 0, y: -1 };
891
891
  }
892
892
  };
@@ -896,11 +896,15 @@ var vecToInsertionDirection = ({
896
896
  }) => {
897
897
  if (x > 0) return "from_right";
898
898
  if (x < 0) return "from_left";
899
- if (y > 0) return "from_front";
900
- return "from_back";
899
+ if (y > 0) return "from_top";
900
+ return "from_bottom";
901
901
  };
902
902
  var transformInsertionDirection = (direction, opts) => {
903
- if (!direction || direction === "from_above") return direction;
903
+ if (!direction) return direction;
904
+ if (direction === "from_above" || direction === "from_below") {
905
+ if (!opts.isFlipped) return direction;
906
+ return direction === "from_above" ? "from_below" : "from_above";
907
+ }
904
908
  let { x, y } = insertionDirectionToVec(direction);
905
909
  let quarterTurns = Math.round(opts.rotationDegrees / 90);
906
910
  while (quarterTurns > 0) {
@@ -976,7 +980,7 @@ var transformPCBElement = (elm, matrix) => {
976
980
  const flipPadWidthHeight = Math.abs(getQuarterTurns(tsr.rotation.angle)) % 2 === 1;
977
981
  const rotationDegrees = tsr.rotation.angle / Math.PI * 180;
978
982
  const isFlipped = tsr.scale.sy < 0;
979
- if (elm.type === "pcb_plated_hole" || elm.type === "pcb_hole" || elm.type === "pcb_via" || elm.type === "pcb_smtpad" || elm.type === "pcb_port") {
983
+ if (elm.type === "pcb_plated_hole" || elm.type === "pcb_hole" || elm.type === "pcb_via" || elm.type === "pcb_smtpad" || elm.type === "pcb_solder_paste" || elm.type === "pcb_port") {
980
984
  const { x, y } = applyToPoint(matrix, {
981
985
  x: Number(elm.x),
982
986
  y: Number(elm.y)
@@ -996,10 +1000,14 @@ var transformPCBElement = (elm, matrix) => {
996
1000
  elm.center = applyToPoint(matrix, elm.center);
997
1001
  } else if (elm.type === "pcb_silkscreen_text" || elm.type === "pcb_fabrication_note_text" || elm.type === "pcb_note_text") {
998
1002
  elm.anchor_position = applyToPoint(matrix, elm.anchor_position);
1003
+ } else if (elm.type === "pcb_copper_text") {
1004
+ if (elm.anchor_position) {
1005
+ elm.anchor_position = applyToPoint(matrix, elm.anchor_position);
1006
+ }
999
1007
  } else if (elm.type === "pcb_courtyard_rect") {
1000
1008
  elm.center = applyToPoint(matrix, elm.center);
1001
1009
  elm.ccw_rotation = ((elm.ccw_rotation ?? 0) + rotationDegrees) % 360;
1002
- } else if (elm.type === "pcb_silkscreen_circle" || elm.type === "pcb_silkscreen_rect" || elm.type === "pcb_note_rect" || elm.type === "pcb_courtyard_circle") {
1010
+ } else if (elm.type === "pcb_silkscreen_circle" || elm.type === "pcb_silkscreen_rect" || elm.type === "pcb_silkscreen_pill" || elm.type === "pcb_silkscreen_oval" || elm.type === "pcb_note_rect" || elm.type === "pcb_courtyard_circle") {
1003
1011
  elm.center = applyToPoint(matrix, elm.center);
1004
1012
  } else if (elm.type === "pcb_component") {
1005
1013
  elm.center = applyToPoint(matrix, elm.center);
@@ -1036,7 +1044,19 @@ var transformPCBElement = (elm, matrix) => {
1036
1044
  p.y = tp.y;
1037
1045
  return p;
1038
1046
  });
1039
- } else if (elm.type === "pcb_silkscreen_path" || elm.type === "pcb_trace" || elm.type === "pcb_fabrication_note_path" || elm.type === "pcb_note_path") {
1047
+ } else if (elm.type === "pcb_trace") {
1048
+ elm.route = elm.route.map((rp) => {
1049
+ if (!("x" in rp)) {
1050
+ rp.start = applyToPoint(matrix, rp.start);
1051
+ rp.end = applyToPoint(matrix, rp.end);
1052
+ return rp;
1053
+ }
1054
+ const tp = applyToPoint(matrix, rp);
1055
+ rp.x = tp.x;
1056
+ rp.y = tp.y;
1057
+ return rp;
1058
+ });
1059
+ } else if (elm.type === "pcb_silkscreen_path" || elm.type === "pcb_trace_hint" || elm.type === "pcb_fabrication_note_path" || elm.type === "pcb_note_path") {
1040
1060
  elm.route = elm.route.map((rp) => {
1041
1061
  const tp = applyToPoint(matrix, rp);
1042
1062
  rp.x = tp.x;
@@ -1069,7 +1089,7 @@ var transformPCBElements = (elms, matrix) => {
1069
1089
  let transformedElms = elms.map((elm) => transformPCBElement(elm, matrix));
1070
1090
  if (flipPadWidthHeight) {
1071
1091
  transformedElms = transformedElms.map((elm) => {
1072
- if (elm.type === "pcb_smtpad" && (elm.shape === "rect" || elm.shape === "pill")) {
1092
+ if ((elm.type === "pcb_smtpad" || elm.type === "pcb_solder_paste") && (elm.shape === "rect" || elm.shape === "pill")) {
1073
1093
  ;
1074
1094
  [elm.width, elm.height] = [elm.height, elm.width];
1075
1095
  }
@@ -1438,10 +1458,13 @@ var getBoundsOfPcbElements = (elements) => {
1438
1458
  }
1439
1459
  } else if (elm.type === "pcb_trace") {
1440
1460
  for (const point of elm.route) {
1441
- minX = Math.min(minX, point.x);
1442
- minY = Math.min(minY, point.y);
1443
- maxX = Math.max(maxX, point.x);
1444
- maxY = Math.max(maxY, point.y);
1461
+ const positions = "x" in point ? [point] : [point.start, point.end];
1462
+ for (const { x, y } of positions) {
1463
+ minX = Math.min(minX, x);
1464
+ minY = Math.min(minY, y);
1465
+ maxX = Math.max(maxX, x);
1466
+ maxY = Math.max(maxY, y);
1467
+ }
1445
1468
  }
1446
1469
  } else if (elm.type === "pcb_courtyard_outline") {
1447
1470
  for (const point of elm.outline) {