@tscircuit/cli 0.1.2225 → 0.1.2226

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/cli/main.js CHANGED
@@ -38413,7 +38413,7 @@ function compose14(...matrices) {
38413
38413
  function isUndefined2(val) {
38414
38414
  return typeof val === "undefined";
38415
38415
  }
38416
- function rotate13(angle, cx2, cy2) {
38416
+ function rotate14(angle, cx2, cy2) {
38417
38417
  const cosAngle = cos(angle);
38418
38418
  const sinAngle = sin(angle);
38419
38419
  const rotationMatrix = {
@@ -38434,7 +38434,7 @@ function rotate13(angle, cx2, cy2) {
38434
38434
  ]);
38435
38435
  }
38436
38436
  function rotateDEG(angle, cx2 = undefined, cy2 = undefined) {
38437
- return rotate13(angle * PI / 180, cx2, cy2);
38437
+ return rotate14(angle * PI / 180, cx2, cy2);
38438
38438
  }
38439
38439
  function scale8(sx2, sy2 = undefined, cx2 = undefined, cy2 = undefined) {
38440
38440
  if (isUndefined2(sy2))
@@ -44668,7 +44668,7 @@ function createSvgObjectsFromPcbFabricationNoteText2(pcbFabNoteText, ctx) {
44668
44668
  dominantBaseline = "text-after-edge";
44669
44669
  break;
44670
44670
  }
44671
- const textTransform = compose14(translate13(transformedX, transformedY), rotate13(Math.PI / 180));
44671
+ const textTransform = compose14(translate13(transformedX, transformedY), rotate14(Math.PI / 180));
44672
44672
  const svgObject = {
44673
44673
  name: "text",
44674
44674
  type: "element",
@@ -46497,7 +46497,7 @@ function createSvgObjectsFromPcbSilkscreenText2(pcbSilkscreenText, ctx) {
46497
46497
  const rectW = width + padLeft + padRight;
46498
46498
  const rectH = height + padTop + padBottom;
46499
46499
  const strokeWidth = scaledFontSize * 0.15;
46500
- const knockoutTransform = toString(compose14(translate13(transformedX, transformedY), rotate13(-ccw_rotation * Math.PI / 180), ...applyMirror ? [scale8(-1, 1)] : [], scale8(scaleFactor, scaleFactor)));
46500
+ const knockoutTransform = toString(compose14(translate13(transformedX, transformedY), rotate14(-ccw_rotation * Math.PI / 180), ...applyMirror ? [scale8(-1, 1)] : [], scale8(scaleFactor, scaleFactor)));
46501
46501
  const maskId = `silkscreen-knockout-mask-${pcbSilkscreenText.pcb_silkscreen_text_id}-${silkscreenMaskIdCounter2++}`;
46502
46502
  return [
46503
46503
  {
@@ -46610,7 +46610,7 @@ function createSvgObjectsFromPcbSilkscreenText2(pcbSilkscreenText, ctx) {
46610
46610
  dominantBaseline = "central";
46611
46611
  break;
46612
46612
  }
46613
- const textTransform = compose14(translate13(transformedX, transformedY), rotate13(-ccw_rotation * Math.PI / 180), ...layer === "bottom" ? [scale8(-1, 1)] : []);
46613
+ const textTransform = compose14(translate13(transformedX, transformedY), rotate14(-ccw_rotation * Math.PI / 180), ...layer === "bottom" ? [scale8(-1, 1)] : []);
46614
46614
  const lines = text.split(`
46615
46615
  `);
46616
46616
  const children = lines.length === 1 ? [
@@ -46852,7 +46852,7 @@ function createSvgObjectsFromPcbCopperText2(pcbCopperText, ctx) {
46852
46852
  const rectW = width2 + padX * 2;
46853
46853
  const rectH = height2 + padY * 2;
46854
46854
  const strokeWidth2 = scaledFontSize2 * 0.15;
46855
- const knockoutTransform = toString(compose14(translate13(ax, ay), rotate13(-ccw_rotation * Math.PI / 180), ...applyMirror ? [scale8(-1, 1)] : [], scale8(scaleFactor, scaleFactor)));
46855
+ const knockoutTransform = toString(compose14(translate13(ax, ay), rotate14(-ccw_rotation * Math.PI / 180), ...applyMirror ? [scale8(-1, 1)] : [], scale8(scaleFactor, scaleFactor)));
46856
46856
  const maskId = `knockout-mask-${pcbCopperText.pcb_copper_text_id}-${maskIdCounter2++}`;
46857
46857
  return [
46858
46858
  {
@@ -46954,7 +46954,7 @@ function createSvgObjectsFromPcbCopperText2(pcbCopperText, ctx) {
46954
46954
  offsetY = -height / 2;
46955
46955
  break;
46956
46956
  }
46957
- const textTransform = toString(compose14(translate13(ax, ay), rotate13(-ccw_rotation * Math.PI / 180), ...applyMirror ? [scale8(-1, 1)] : [], translate13(offsetX, offsetY), scale8(scaleFactor, scaleFactor)));
46957
+ const textTransform = toString(compose14(translate13(ax, ay), rotate14(-ccw_rotation * Math.PI / 180), ...applyMirror ? [scale8(-1, 1)] : [], translate13(offsetX, offsetY), scale8(scaleFactor, scaleFactor)));
46958
46958
  const strokeWidth = scaledFontSize * 0.15;
46959
46959
  return [
46960
46960
  {
@@ -49025,7 +49025,7 @@ function createSvgObjectsFromPcbCutout2(cutout, ctx) {
49025
49025
  width: scaledWidth.toString(),
49026
49026
  height: scaledHeight.toString(),
49027
49027
  fill: colorMap2.drill,
49028
- transform: toString(compose14(translate13(cx, cy), rotate13(svgRotation * Math.PI / 180))),
49028
+ transform: toString(compose14(translate13(cx, cy), rotate14(svgRotation * Math.PI / 180))),
49029
49029
  "data-type": "pcb_cutout",
49030
49030
  "data-pcb-layer": "drill"
49031
49031
  };
@@ -49376,7 +49376,7 @@ function createSvgObjectsFromPcbCopperPour2(pour, ctx) {
49376
49376
  y: (-scaledHeight / 2).toString(),
49377
49377
  width: scaledWidth.toString(),
49378
49378
  height: scaledHeight.toString(),
49379
- transform: toString(compose14(translate13(cx, cy), rotate13(svgRotation * Math.PI / 180)))
49379
+ transform: toString(compose14(translate13(cx, cy), rotate14(svgRotation * Math.PI / 180)))
49380
49380
  };
49381
49381
  const copperRect = {
49382
49382
  name: "rect",
@@ -55754,7 +55754,7 @@ var import_debug3, svgAlphabet, lineAlphabet3, debug3, debugPcb2, debugSch2, DEF
55754
55754
  y: schNetLabel.center.y - realTextGrowthVec.y * fullWidthFsr * fontSizeMm / 2
55755
55755
  };
55756
55756
  const pathRotation = 0;
55757
- const rotationMatrix = rotate13(pathRotation / 180 * Math.PI);
55757
+ const rotationMatrix = rotate14(pathRotation / 180 * Math.PI);
55758
55758
  const symbolBounds = {
55759
55759
  minX: Math.min(...symbol.primitives.flatMap((p) => p.type === "path" ? p.points.map((pt) => pt.x) : [])),
55760
55760
  maxX: Math.max(...symbol.primitives.flatMap((p) => p.type === "path" ? p.points.map((pt) => pt.x) : [])),
@@ -55940,7 +55940,7 @@ var import_debug3, svgAlphabet, lineAlphabet3, debug3, debugPcb2, debugSch2, DEF
55940
55940
  x: ARROW_POINT_WIDTH_FSR,
55941
55941
  y: -0.6
55942
55942
  }
55943
- ].map((fontRelativePoint) => applyToPoint49(compose14(realToScreenTransform, translate13(realAnchorPosition.x, realAnchorPosition.y), scale8(fontSizeMm), rotate13(pathRotation / 180 * Math.PI)), fontRelativePoint));
55943
+ ].map((fontRelativePoint) => applyToPoint49(compose14(realToScreenTransform, translate13(realAnchorPosition.x, realAnchorPosition.y), scale8(fontSizeMm), rotate14(pathRotation / 180 * Math.PI)), fontRelativePoint));
55944
55944
  const pathD = `
55945
55945
  M ${screenOutlinePoints[0].x},${screenOutlinePoints[0].y}
55946
55946
  L ${screenOutlinePoints[1].x},${screenOutlinePoints[1].y}
@@ -57847,7 +57847,7 @@ import {
57847
57847
  applyToPoint as applyToPoint79,
57848
57848
  compose as compose15,
57849
57849
  identity as identity9,
57850
- rotate as rotate14,
57850
+ rotate as rotate15,
57851
57851
  translate as translate14
57852
57852
  } from "transformation-matrix";
57853
57853
  import { getBoundFromCenteredRect as getBoundFromCenteredRect2 } from "@tscircuit/math-utils";
@@ -58738,7 +58738,7 @@ var import_polygon_clipping2, import_fast_json_stable_stringify, import_polygon_
58738
58738
  20,1,$1+$1,$8,$9,$2,$3,0*
58739
58739
  `.trim()
58740
58740
  }).add("comment", { comment: "APERTURE MACROS END" }).build());
58741
- }, SILKSCREEN_SHAPE_TYPES, isSilkscreenShape = (element) => SILKSCREEN_SHAPE_TYPES.includes(element.type), DEFAULT_STROKE_WIDTH3 = 0.1, ELLIPSE_SEGMENTS = 48, CORNER_SEGMENTS = 12, rotationAboutCenter = (center, ccwDegrees) => ccwDegrees ? compose15(translate14(center.x, center.y), rotate14(ccwDegrees * Math.PI / 180), translate14(-center.x, -center.y)) : identity9(), ellipseRoute = (center, radiusX, radiusY, ccwDegrees = 0) => {
58741
+ }, SILKSCREEN_SHAPE_TYPES, isSilkscreenShape = (element) => SILKSCREEN_SHAPE_TYPES.includes(element.type), DEFAULT_STROKE_WIDTH3 = 0.1, ELLIPSE_SEGMENTS = 48, CORNER_SEGMENTS = 12, rotationAboutCenter = (center, ccwDegrees) => ccwDegrees ? compose15(translate14(center.x, center.y), rotate15(ccwDegrees * Math.PI / 180), translate14(-center.x, -center.y)) : identity9(), ellipseRoute = (center, radiusX, radiusY, ccwDegrees = 0) => {
58742
58742
  const matrix = rotationAboutCenter(center, ccwDegrees);
58743
58743
  return Array.from({ length: ELLIPSE_SEGMENTS + 1 }, (_, i) => {
58744
58744
  const angle = i / ELLIPSE_SEGMENTS * Math.PI * 2;
@@ -75164,7 +75164,7 @@ import { applyToPoint as applyToPoint103 } from "transformation-matrix";
75164
75164
  import { applyToPoint as applyToPoint113 } from "transformation-matrix";
75165
75165
  import { applyToPoint as applyToPoint123 } from "transformation-matrix";
75166
75166
  import { applyToPoint as applyToPoint163 } from "transformation-matrix";
75167
- import { applyToPoint as applyToPoint133, compose as compose17, rotate as rotate15, translate as translate15 } from "transformation-matrix";
75167
+ import { applyToPoint as applyToPoint133, compose as compose17, rotate as rotate16, translate as translate15 } from "transformation-matrix";
75168
75168
  import { applyToPoint as applyToPoint143, compose as compose24, rotate as rotate24, translate as translate24 } from "transformation-matrix";
75169
75169
  import { applyToPoint as applyToPoint153 } from "transformation-matrix";
75170
75170
  import { applyToPoint as applyToPoint173 } from "transformation-matrix";
@@ -76491,7 +76491,7 @@ function drawPillPath(params2) {
76491
76491
  ccwRotationDegrees = 0
76492
76492
  } = params2;
76493
76493
  const ccwRotationRadians = ccwRotationDegrees * Math.PI / 180;
76494
- const realToPxTransform = compose17(translate15(centerX, centerY), rotate15(-ccwRotationRadians));
76494
+ const realToPxTransform = compose17(translate15(centerX, centerY), rotate16(-ccwRotationRadians));
76495
76495
  if (width > height) {
76496
76496
  const semicircleRadius = height / 2;
76497
76497
  const semicircleCenterOffset = (width - height) / 2;
@@ -147027,7 +147027,7 @@ var init_create_circuit_to_altium_pcb_point_transform = __esm(() => {
147027
147027
  });
147028
147028
 
147029
147029
  // node_modules/circuit-json-to-altium/lib/create-pcb-component-body-records.ts
147030
- import { applyToPoint as applyToPoint99, compose as compose19, rotate as rotate16, translate as translate18 } from "transformation-matrix";
147030
+ import { applyToPoint as applyToPoint99, compose as compose19, rotate as rotate17, translate as translate18 } from "transformation-matrix";
147031
147031
  function createPcbComponentBodyRecords({
147032
147032
  circuitJson,
147033
147033
  circuitToAltiumPcbPoint,
@@ -147100,7 +147100,7 @@ function createBodyOutline({
147100
147100
  rotationDegrees,
147101
147101
  size
147102
147102
  }) {
147103
- const localToCircuit = compose19(translate18(position.x, position.y), rotate16(rotationDegrees * Math.PI / 180));
147103
+ const localToCircuit = compose19(translate18(position.x, position.y), rotate17(rotationDegrees * Math.PI / 180));
147104
147104
  const halfWidthMm = size.x / 2;
147105
147105
  const halfHeightMm = size.y / 2;
147106
147106
  const localOutline = [
@@ -147142,7 +147142,7 @@ var init_create_pcb_component_body_records = __esm(() => {
147142
147142
  import {
147143
147143
  pcb_copper_pour
147144
147144
  } from "circuit-json";
147145
- import { applyToPoint as applyToPoint100, compose as compose20, rotate as rotate17, translate as translate19 } from "transformation-matrix";
147145
+ import { applyToPoint as applyToPoint100, compose as compose20, rotate as rotate18, translate as translate19 } from "transformation-matrix";
147146
147146
  function createPcbCopperPourRecords({
147147
147147
  circuitJson,
147148
147148
  circuitToAltiumPcbPoint,
@@ -147264,7 +147264,7 @@ function getCopperPourRings(copperPour) {
147264
147264
  };
147265
147265
  }
147266
147266
  function getRotatedRectPoints2(copperPour) {
147267
- const centerToCircuit = compose20(translate19(copperPour.center.x, copperPour.center.y), rotate17((copperPour.rotation ?? 0) * Math.PI / 180));
147267
+ const centerToCircuit = compose20(translate19(copperPour.center.x, copperPour.center.y), rotate18((copperPour.rotation ?? 0) * Math.PI / 180));
147268
147268
  const halfWidth = copperPour.width / 2;
147269
147269
  const halfHeight = copperPour.height / 2;
147270
147270
  return [
@@ -147427,7 +147427,7 @@ var init_create_pcb_copper_pour_records = __esm(() => {
147427
147427
  });
147428
147428
 
147429
147429
  // node_modules/circuit-json-to-altium/lib/create-pcb-annotation-primitives.ts
147430
- import { applyToPoint as applyToPoint101, compose as compose21, rotate as rotate18, translate as translate20 } from "transformation-matrix";
147430
+ import { applyToPoint as applyToPoint101, compose as compose21, rotate as rotate19, translate as translate20 } from "transformation-matrix";
147431
147431
  function createAltiumTrackRecords({
147432
147432
  altiumComponentIndex,
147433
147433
  circuitPoints,
@@ -147565,7 +147565,7 @@ function createRoundedRectPoints({
147565
147565
  { x: halfWidthMm, y: halfHeightMm },
147566
147566
  { x: -halfWidthMm, y: halfHeightMm }
147567
147567
  ] : createRoundedCornerPoints({ halfHeightMm, halfWidthMm, radiusMm });
147568
- const localToCircuit = compose21(translate20(center.x, center.y), rotate18(rotationDegrees * Math.PI / 180));
147568
+ const localToCircuit = compose21(translate20(center.x, center.y), rotate19(rotationDegrees * Math.PI / 180));
147569
147569
  return localPoints.map((point) => applyToPoint101(localToCircuit, point));
147570
147570
  }
147571
147571
  function createRoundedCornerPoints({
@@ -150875,7 +150875,7 @@ var init_create_altium_schematic_text_record_fields = __esm(() => {
150875
150875
  });
150876
150876
 
150877
150877
  // node_modules/circuit-json-to-altium/lib/is-schematic-symbol-primitive.ts
150878
- function isSchematicSymbolPrimitive(element) {
150878
+ function isSchematicSymbolPrimitive2(element) {
150879
150879
  return SCHEMATIC_SYMBOL_PRIMITIVE_TYPES.has(element.type ?? "") || element.type === "schematic_text" && typeof element.schematic_symbol_id === "string" && element.schematic_symbol_id.length > 0;
150880
150880
  }
150881
150881
  var SCHEMATIC_SYMBOL_PRIMITIVE_TYPES;
@@ -151095,7 +151095,7 @@ function createRectRecordFields2({
151095
151095
  ];
151096
151096
  }
151097
151097
  function createAltiumSchematicSymbolPrimitiveRecordFields(input) {
151098
- if (!isSchematicSymbolPrimitive(input.graphic))
151098
+ if (!isSchematicSymbolPrimitive2(input.graphic))
151099
151099
  return;
151100
151100
  if (input.graphic.type === "schematic_text") {
151101
151101
  return createAltiumSchematicTextRecordFields({
@@ -151379,7 +151379,7 @@ function getSchematicTransform(schematicElements, sheetSettings) {
151379
151379
  const center = asPoint(element.center);
151380
151380
  if (center)
151381
151381
  circuitPoints.push(center);
151382
- if (isSchematicSymbolPrimitive(element) && (asString(element.schematic_symbol_id) || asString(element.schematic_component_id))) {
151382
+ if (isSchematicSymbolPrimitive2(element) && (asString(element.schematic_symbol_id) || asString(element.schematic_component_id))) {
151383
151383
  appendSchematicSymbolPrimitivePoints({
151384
151384
  element,
151385
151385
  points: circuitPoints
@@ -151481,7 +151481,7 @@ function createSchematicSymbolPrimitiveMaps(schematicElements) {
151481
151481
  byComponentId: new Map,
151482
151482
  bySymbolId: new Map
151483
151483
  };
151484
- for (const primitive of schematicElements.filter(isSchematicSymbolPrimitive)) {
151484
+ for (const primitive of schematicElements.filter(isSchematicSymbolPrimitive2)) {
151485
151485
  appendElementToIdMap({
151486
151486
  element: primitive,
151487
151487
  id: asString(primitive.schematic_component_id),
@@ -151764,7 +151764,7 @@ function createSchematicDocument({
151764
151764
  schematicPort
151765
151765
  ]);
151766
151766
  }
151767
- for (const schematicText of schematicElements.filter((element) => element.type === "schematic_text" && !isSchematicSymbolPrimitive(element))) {
151767
+ for (const schematicText of schematicElements.filter((element) => element.type === "schematic_text" && !isSchematicSymbolPrimitive2(element))) {
151768
151768
  appendElementToIdMap({
151769
151769
  element: schematicText,
151770
151770
  id: asString(schematicText.schematic_component_id),
@@ -154298,7 +154298,7 @@ var import_perfect_cli = __toESM3(require_dist3(), 1);
154298
154298
  // lib/getVersion.ts
154299
154299
  import { createRequire as createRequire2 } from "node:module";
154300
154300
  // package.json
154301
- var version = "0.1.2224";
154301
+ var version = "0.1.2225";
154302
154302
  var package_default = {
154303
154303
  name: "@tscircuit/cli",
154304
154304
  version,
@@ -154350,7 +154350,7 @@ var package_default = {
154350
154350
  "circuit-json-to-fdm-component-box": "^0.0.2",
154351
154351
  "circuit-json-to-footprinter": "^0.0.58",
154352
154352
  "circuit-json-to-gerber": "^0.0.105",
154353
- "circuit-json-to-kicad": "0.0.212",
154353
+ "circuit-json-to-kicad": "0.0.230",
154354
154354
  "circuit-json-to-pnp-csv": "^0.0.18",
154355
154355
  "circuit-json-to-readable-netlist": "^0.0.15",
154356
154356
  "circuit-json-to-spice": "^0.0.45",
@@ -159407,7 +159407,7 @@ import {
159407
159407
  import { Paper, Uuid as Uuid4 } from "kicadts";
159408
159408
  import { KicadPcb as KicadPcb2 } from "kicadts";
159409
159409
  import { cju as cju2 } from "@tscircuit/circuit-json-util";
159410
- import { compose as compose6, translate as translate6, scale as scale4 } from "transformation-matrix";
159410
+ import { compose as compose7, translate as translate7, scale as scale5 } from "transformation-matrix";
159411
159411
 
159412
159412
  // node_modules/earcut/src/earcut.js
159413
159413
  var steiners = new Set;
@@ -159981,7 +159981,7 @@ import {
159981
159981
  Setup
159982
159982
  } from "kicadts";
159983
159983
  import { PcbNet } from "kicadts";
159984
- import { Footprint as Footprint3, FootprintModel as FootprintModel4 } from "kicadts";
159984
+ import { Footprint as Footprint3, FootprintModel as FootprintModel4, FootprintAttr as FootprintAttr3 } from "kicadts";
159985
159985
  import {
159986
159986
  parseKicadSexpr,
159987
159987
  KicadPcb,
@@ -159993,7 +159993,7 @@ import {
159993
159993
  TextEffects as TextEffects8,
159994
159994
  TextEffectsFont as TextEffectsFont8
159995
159995
  } from "kicadts";
159996
- import { applyToPoint as applyToPoint22 } from "transformation-matrix";
159996
+ import { applyToPoint as applyToPoint23 } from "transformation-matrix";
159997
159997
  import {
159998
159998
  Property as Property2,
159999
159999
  TextEffects as TextEffects9,
@@ -160022,8 +160022,16 @@ import { applyToPoint as applyToPoint15, rotate as rotate4, identity as identity
160022
160022
  import { TextEffectsJustify as TextEffectsJustify5 } from "kicadts";
160023
160023
  import { FpLine, Stroke as Stroke11 } from "kicadts";
160024
160024
  import { applyToPoint as applyToPoint16, identity as identity3, rotate as rotate5 } from "transformation-matrix";
160025
+ import { FpPoly as FpPoly2, Stroke as Stroke12 } from "kicadts";
160026
+ import {
160027
+ applyToPoint as applyToPoint17,
160028
+ compose as compose5,
160029
+ rotate as rotate6,
160030
+ scale as scale3,
160031
+ translate as translate5
160032
+ } from "transformation-matrix";
160025
160033
  import { FpText as FpText3, TextEffects as TextEffects11, TextEffectsFont as TextEffectsFont11 } from "kicadts";
160026
- import { applyToPoint as applyToPoint17, rotate as rotate6, identity as identity4 } from "transformation-matrix";
160034
+ import { applyToPoint as applyToPoint18, rotate as rotate7, identity as identity4 } from "transformation-matrix";
160027
160035
  import { FootprintModel as FootprintModel3 } from "kicadts";
160028
160036
  import {
160029
160037
  FootprintPad,
@@ -160035,24 +160043,24 @@ import {
160035
160043
  PadNet
160036
160044
  } from "kicadts";
160037
160045
  import {
160038
- applyToPoint as applyToPoint18,
160039
- compose as compose5,
160040
- translate as translate5,
160041
- scale as scale3,
160042
- rotate as rotate7
160046
+ applyToPoint as applyToPoint19,
160047
+ compose as compose6,
160048
+ translate as translate6,
160049
+ scale as scale4,
160050
+ rotate as rotate8
160043
160051
  } from "transformation-matrix";
160044
160052
  import { FootprintPad as FootprintPad2, PadDrill, PadNet as PadNet2 } from "kicadts";
160045
- import { applyToPoint as applyToPoint19, rotate as rotate8, identity as identity5 } from "transformation-matrix";
160053
+ import { applyToPoint as applyToPoint20, rotate as rotate9, identity as identity5 } from "transformation-matrix";
160046
160054
  import { FootprintPad as FootprintPad3, PadDrill as PadDrill2 } from "kicadts";
160047
- import { applyToPoint as applyToPoint20, rotate as rotate9, identity as identity6 } from "transformation-matrix";
160048
- import { FpLine as FpLine2, Stroke as Stroke12 } from "kicadts";
160049
- import { applyToPoint as applyToPoint21, identity as identity7, rotate as rotate10 } from "transformation-matrix";
160055
+ import { applyToPoint as applyToPoint21, rotate as rotate10, identity as identity6 } from "transformation-matrix";
160056
+ import { FpLine as FpLine2, Stroke as Stroke13 } from "kicadts";
160057
+ import { applyToPoint as applyToPoint22, identity as identity7, rotate as rotate11 } from "transformation-matrix";
160050
160058
  import { Segment, SegmentNet } from "kicadts";
160051
- import { applyToPoint as applyToPoint23 } from "transformation-matrix";
160052
- import { Via, ViaNet } from "kicadts";
160053
160059
  import { applyToPoint as applyToPoint24 } from "transformation-matrix";
160054
- import { Footprint as Footprint4 } from "kicadts";
160060
+ import { Via, ViaNet } from "kicadts";
160055
160061
  import { applyToPoint as applyToPoint25 } from "transformation-matrix";
160062
+ import { Footprint as Footprint4 } from "kicadts";
160063
+ import { applyToPoint as applyToPoint26 } from "transformation-matrix";
160056
160064
  import { GrLine } from "kicadts";
160057
160065
  import {
160058
160066
  At as At3,
@@ -160061,10 +160069,10 @@ import {
160061
160069
  TextEffectsFont as TextEffectsFont12,
160062
160070
  TextEffectsJustify as TextEffectsJustify6
160063
160071
  } from "kicadts";
160064
- import { applyToPoint as applyToPoint26 } from "transformation-matrix";
160065
- import { applyToPoint as applyToPoint28, rotate as rotate11 } from "transformation-matrix";
160066
- import { GrText as GrText2, TextEffects as TextEffects13, TextEffectsFont as TextEffectsFont13, At as At4 } from "kicadts";
160067
160072
  import { applyToPoint as applyToPoint27 } from "transformation-matrix";
160073
+ import { applyToPoint as applyToPoint29, rotate as rotate12 } from "transformation-matrix";
160074
+ import { GrText as GrText2, TextEffects as TextEffects13, TextEffectsFont as TextEffectsFont13, At as At4 } from "kicadts";
160075
+ import { applyToPoint as applyToPoint28 } from "transformation-matrix";
160068
160076
  import { cju as cju3 } from "@tscircuit/circuit-json-util";
160069
160077
  import { cju as cju4 } from "@tscircuit/circuit-json-util";
160070
160078
  import { parseKicadSexpr as parseKicadSexpr2, KicadSch as KicadSch2 } from "kicadts";
@@ -160538,8 +160546,22 @@ function getReferenceDesignator(sourceComponent) {
160538
160546
  const prefix = getReferencePrefixForComponent(sourceComponent);
160539
160547
  return `${prefix}?`;
160540
160548
  }
160549
+ var legacySymbolNameByOrientedSymbolName = {
160550
+ n_channel_e_mosfet_transistor_gate_left_drain_top: "n_channel_e_mosfet_transistor_horz",
160551
+ n_channel_e_mosfet_transistor_gate_top_drain_right: "n_channel_e_mosfet_transistor_vert",
160552
+ n_channel_d_mosfet_transistor_gate_left_drain_top: "n_channel_d_mosfet_transistor_horz",
160553
+ n_channel_d_mosfet_transistor_gate_top_drain_right: "n_channel_d_mosfet_transistor_vert",
160554
+ p_channel_e_mosfet_transistor_gate_left_drain_top: "p_channel_e_mosfet_transistor_horz",
160555
+ p_channel_e_mosfet_transistor_gate_top_drain_right: "p_channel_e_mosfet_transistor_vert",
160556
+ p_channel_d_mosfet_transistor_gate_left_drain_top: "p_channel_d_mosfet_transistor_horz",
160557
+ p_channel_d_mosfet_transistor_gate_top_drain_right: "p_channel_d_mosfet_transistor_vert"
160558
+ };
160559
+ var getSchematicSymbolData = (symbolName) => {
160560
+ const resolvedSymbolName = legacySymbolNameByOrientedSymbolName[symbolName] ?? symbolName;
160561
+ return symbols[resolvedSymbolName];
160562
+ };
160541
160563
  function isBuiltinSymbol(symbolName) {
160542
- return symbolName in symbols;
160564
+ return symbolName in symbols2;
160543
160565
  }
160544
160566
  function sanitizeLibraryIdentifierPart(value) {
160545
160567
  return value.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "") || "connector";
@@ -160575,20 +160597,37 @@ function getLibraryId(sourceComp, schematicComp, cadComponent, schematicSymbolNa
160575
160597
  function getComponentLevelLibraryId(sourceComp, schematicComp, cadComponent) {
160576
160598
  return `${getLibraryId(sourceComp, schematicComp, cadComponent)}_${sanitizeLibraryIdentifierPart(schematicComp.schematic_component_id)}`;
160577
160599
  }
160578
- var legacySymbolNameByOrientedSymbolName = {
160579
- n_channel_e_mosfet_transistor_gate_left_drain_top: "n_channel_e_mosfet_transistor_horz",
160580
- n_channel_e_mosfet_transistor_gate_top_drain_right: "n_channel_e_mosfet_transistor_vert",
160581
- n_channel_d_mosfet_transistor_gate_left_drain_top: "n_channel_d_mosfet_transistor_horz",
160582
- n_channel_d_mosfet_transistor_gate_top_drain_right: "n_channel_d_mosfet_transistor_vert",
160583
- p_channel_e_mosfet_transistor_gate_left_drain_top: "p_channel_e_mosfet_transistor_horz",
160584
- p_channel_e_mosfet_transistor_gate_top_drain_right: "p_channel_e_mosfet_transistor_vert",
160585
- p_channel_d_mosfet_transistor_gate_left_drain_top: "p_channel_d_mosfet_transistor_horz",
160586
- p_channel_d_mosfet_transistor_gate_top_drain_right: "p_channel_d_mosfet_transistor_vert"
160587
- };
160588
- var getSchematicSymbolData = (symbolName) => {
160589
- const resolvedSymbolName = legacySymbolNameByOrientedSymbolName[symbolName] ?? symbolName;
160590
- return symbols2[resolvedSymbolName];
160591
- };
160600
+ function isSchematicSymbolPrimitive(element) {
160601
+ return element.type === "schematic_arc" || element.type === "schematic_circle" || element.type === "schematic_line" || element.type === "schematic_path" || element.type === "schematic_rect";
160602
+ }
160603
+ function findLinkedSchematicSymbolId(circuitJson, schematicComponentId) {
160604
+ return circuitJson.find((element) => isSchematicSymbolPrimitive(element) && element.schematic_component_id === schematicComponentId && Boolean(element.schematic_symbol_id))?.schematic_symbol_id;
160605
+ }
160606
+ function resolveSchematicComponentSymbol({
160607
+ circuitJson,
160608
+ schematicComponent,
160609
+ sourceComponent,
160610
+ cadComponents
160611
+ }) {
160612
+ const cadComponent = cadComponents.find((candidate) => candidate.source_component_id === sourceComponent.source_component_id);
160613
+ const linkedSchematicSymbolId = findLinkedSchematicSymbolId(circuitJson, schematicComponent.schematic_component_id);
160614
+ const schematicSymbolId = schematicComponent.schematic_symbol_id || linkedSchematicSymbolId;
160615
+ const schematicSymbol = schematicSymbolId ? circuitJson.find((element) => element.type === "schematic_symbol" && element.schematic_symbol_id === schematicSymbolId) : undefined;
160616
+ const schematicSymbolName = schematicSymbolId ? schematicSymbol?.name ?? getKicadCompatibleCustomSymbolName(sourceComponent, cadComponent, schematicSymbolId) : undefined;
160617
+ const usesComponentLevelSymbolPrimitives = hasComponentLevelSymbolPrimitives(circuitJson, schematicComponent);
160618
+ const libraryId = usesComponentLevelSymbolPrimitives ? getComponentLevelLibraryId(sourceComponent, schematicComponent, cadComponent) : getLibraryId(sourceComponent, schematicComponent, cadComponent, schematicSymbolName);
160619
+ const isChip = sourceComponent.ftype === "simple_chip" || sourceComponent.ftype === "simple_pin_header" || sourceComponent.ftype === "simple_connector";
160620
+ return {
160621
+ cadComponent,
160622
+ schematicSymbol,
160623
+ schematicSymbolId,
160624
+ schematicSymbolName,
160625
+ hasLinkedSymbolPrimitives: Boolean(linkedSchematicSymbolId),
160626
+ usesComponentLevelSymbolPrimitives,
160627
+ libraryId,
160628
+ isChip
160629
+ };
160630
+ }
160592
160631
  var normalizePositiveDegrees = (degrees) => (degrees % 360 + 360) % 360;
160593
160632
  var getDirectedSweepDegrees = ({
160594
160633
  startAngleDegrees,
@@ -160784,7 +160823,7 @@ function buildSymbolDataFromSchematicPrimitives(params2) {
160784
160823
  function createArcFromPrimitive({
160785
160824
  primitive,
160786
160825
  transform,
160787
- scale: scale5
160826
+ scale: scale6
160788
160827
  }) {
160789
160828
  const start = applyToPoint(transform, primitive.start);
160790
160829
  const mid = applyToPoint(transform, primitive.mid);
@@ -160797,7 +160836,7 @@ function createArcFromPrimitive({
160797
160836
  "stroke",
160798
160837
  [
160799
160838
  "width",
160800
- primitive.strokeWidth == null ? 0.254 : primitive.strokeWidth * scale5
160839
+ primitive.strokeWidth == null ? 0.254 : primitive.strokeWidth * scale6
160801
160840
  ],
160802
160841
  ["type", primitive.isDashed ? "dash" : "default"]
160803
160842
  ],
@@ -160851,7 +160890,7 @@ function createSymbolFillSexprPrimitives({
160851
160890
  function createCircleFromPrimitive({
160852
160891
  primitive,
160853
160892
  transform,
160854
- scale: scale5
160893
+ scale: scale6
160855
160894
  }) {
160856
160895
  const scaledPos = applyToPoint2(transform, {
160857
160896
  x: primitive.x,
@@ -160859,12 +160898,12 @@ function createCircleFromPrimitive({
160859
160898
  });
160860
160899
  return SymbolCircle.fromSexprPrimitives([
160861
160900
  ["center", scaledPos.x, scaledPos.y],
160862
- ["radius", primitive.radius * scale5],
160901
+ ["radius", primitive.radius * scale6],
160863
160902
  [
160864
160903
  "stroke",
160865
160904
  [
160866
160905
  "width",
160867
- primitive.strokeWidth == null ? 0.254 : primitive.strokeWidth * scale5
160906
+ primitive.strokeWidth == null ? 0.254 : primitive.strokeWidth * scale6
160868
160907
  ],
160869
160908
  ["type", "default"]
160870
160909
  ],
@@ -160886,7 +160925,7 @@ function createPolylineFromPoints({
160886
160925
  fallbackFillType,
160887
160926
  strokeWidth,
160888
160927
  isDashed,
160889
- scale: scale5
160928
+ scale: scale6
160890
160929
  }) {
160891
160930
  const polyline = new SymbolPolyline;
160892
160931
  const xyPoints = points.map((p) => {
@@ -160896,7 +160935,7 @@ function createPolylineFromPoints({
160896
160935
  const pts = new Pts(xyPoints);
160897
160936
  polyline.points = pts;
160898
160937
  const stroke = new Stroke2;
160899
- stroke.width = strokeWidth == null ? 0.254 : strokeWidth * scale5;
160938
+ stroke.width = strokeWidth == null ? 0.254 : strokeWidth * scale6;
160900
160939
  stroke.type = isDashed ? "dash" : "default";
160901
160940
  polyline.stroke = stroke;
160902
160941
  const fill = SymbolPolylineFill.fromSexprPrimitives(createSymbolFillSexprPrimitives({
@@ -160910,7 +160949,7 @@ function createPolylineFromPoints({
160910
160949
  function createRectangleFromPrimitive({
160911
160950
  primitive,
160912
160951
  transform,
160913
- scale: scale5
160952
+ scale: scale6
160914
160953
  }) {
160915
160954
  const start = applyToPoint4(transform, primitive.start);
160916
160955
  const end = applyToPoint4(transform, primitive.end);
@@ -160921,7 +160960,7 @@ function createRectangleFromPrimitive({
160921
160960
  "stroke",
160922
160961
  [
160923
160962
  "width",
160924
- primitive.strokeWidth == null ? 0.254 : primitive.strokeWidth * scale5
160963
+ primitive.strokeWidth == null ? 0.254 : primitive.strokeWidth * scale6
160925
160964
  ],
160926
160965
  ["type", primitive.isDashed ? "dash" : "default"]
160927
160966
  ],
@@ -160937,13 +160976,13 @@ function createRectangleFromPrimitive({
160937
160976
  function createTextFromPrimitive({
160938
160977
  schText,
160939
160978
  transform,
160940
- scale: scale5
160979
+ scale: scale6
160941
160980
  }) {
160942
160981
  const symbolText = new SymbolText;
160943
160982
  const scaledPos = applyToPoint5(transform, { x: schText.x, y: schText.y });
160944
160983
  symbolText.value = schText.text;
160945
160984
  symbolText.at = [scaledPos.x, scaledPos.y, 0];
160946
- const scaledFontSize = schText.fontSize * scale5;
160985
+ const scaledFontSize = schText.fontSize * scale6;
160947
160986
  const font = new TextEffectsFont2;
160948
160987
  font.size = { height: scaledFontSize, width: scaledFontSize };
160949
160988
  symbolText.effects = new TextEffects2({ font });
@@ -161196,12 +161235,81 @@ function calculatePinPosition({
161196
161235
  }
161197
161236
  return { x, y, angle };
161198
161237
  }
161238
+ function getPortSide(x, y) {
161239
+ if (Math.abs(x) > Math.abs(y))
161240
+ return x < 0 ? "left" : "right";
161241
+ return y < 0 ? "down" : "up";
161242
+ }
161243
+ function hasDuplicatePositions(values) {
161244
+ const sorted = [...values].sort((a, b) => a - b);
161245
+ return sorted.some((value, index) => {
161246
+ const previous = sorted[index - 1];
161247
+ return previous !== undefined && Math.abs(value - previous) < 0.000001;
161248
+ });
161249
+ }
161250
+ function getCircuitPinNumbers({
161251
+ symbolData,
161252
+ schematicComponent,
161253
+ schematicPorts,
161254
+ sourcePorts
161255
+ }) {
161256
+ const matches = /* @__PURE__ */ new Map;
161257
+ if (!schematicComponent)
161258
+ return matches;
161259
+ const sourcePortsById = new Map(sourcePorts.map((port) => [port.source_port_id, port]));
161260
+ const symbolCenter = symbolData.center ?? { x: 0, y: 0 };
161261
+ const componentPorts = schematicPorts.filter((port) => port.schematic_component_id === schematicComponent.schematic_component_id);
161262
+ for (const side of ["left", "right", "up", "down"]) {
161263
+ const symbolPorts = symbolData.ports.map((port, index) => ({
161264
+ index,
161265
+ x: (port.x ?? 0) - symbolCenter.x,
161266
+ y: (port.y ?? 0) - symbolCenter.y
161267
+ })).filter((port) => getPortSide(port.x, port.y) === side);
161268
+ const circuitPorts = componentPorts.map((port) => ({
161269
+ port,
161270
+ x: port.center.x - schematicComponent.center.x,
161271
+ y: port.center.y - schematicComponent.center.y
161272
+ })).filter(({ port, x, y }) => (port.facing_direction ?? getPortSide(x, y)) === side);
161273
+ if (symbolPorts.length === 0 || symbolPorts.length !== circuitPorts.length) {
161274
+ continue;
161275
+ }
161276
+ const coordinate = (port) => side === "left" || side === "right" ? port.y : port.x;
161277
+ if (hasDuplicatePositions(symbolPorts.map(coordinate)) || hasDuplicatePositions(circuitPorts.map(coordinate))) {
161278
+ continue;
161279
+ }
161280
+ symbolPorts.sort((a, b) => coordinate(a) - coordinate(b));
161281
+ circuitPorts.sort((a, b) => coordinate(a) - coordinate(b));
161282
+ for (let index = 0;index < symbolPorts.length; index++) {
161283
+ const symbolPort = symbolPorts[index];
161284
+ const circuitPort = circuitPorts[index];
161285
+ if (!symbolPort || !circuitPort)
161286
+ continue;
161287
+ const pinNumber = circuitPort.port.pin_number ?? (circuitPort.port.source_port_id ? sourcePortsById.get(circuitPort.port.source_port_id)?.pin_number : undefined);
161288
+ if (pinNumber !== undefined && pinNumber !== null) {
161289
+ matches.set(symbolPort.index, String(pinNumber));
161290
+ }
161291
+ }
161292
+ }
161293
+ return matches;
161294
+ }
161295
+ function validateInferredPinNumbers(symbolData, inferredPinNumbers) {
161296
+ const missingPinIndices = symbolData.ports.map((port, index) => port.pinNumber == null ? index : undefined).filter((index) => index !== undefined);
161297
+ if (missingPinIndices.length === 0 || missingPinIndices.some((index) => !inferredPinNumbers.has(index))) {
161298
+ return /* @__PURE__ */ new Map;
161299
+ }
161300
+ const resolvedPinNumbers = symbolData.ports.map((port, index) => port.pinNumber?.toString() ?? inferredPinNumbers.get(index));
161301
+ if (resolvedPinNumbers.some((pinNumber) => pinNumber === undefined) || new Set(resolvedPinNumbers).size !== resolvedPinNumbers.length) {
161302
+ return /* @__PURE__ */ new Map;
161303
+ }
161304
+ return inferredPinNumbers;
161305
+ }
161199
161306
  function createPinSubsymbol({
161200
161307
  libId,
161201
161308
  symbolData,
161202
161309
  isChip,
161203
161310
  schematicComponent,
161204
161311
  schematicPorts,
161312
+ sourcePorts,
161205
161313
  c2kMatSchScale
161206
161314
  }) {
161207
161315
  const pinSymbol = new SchematicSymbol3({
@@ -161209,8 +161317,14 @@ function createPinSubsymbol({
161209
161317
  });
161210
161318
  const CHIP_PIN_LENGTH = 6;
161211
161319
  const CUSTOM_SYMBOL_PIN_LENGTH = 0.01;
161212
- for (let i = 0;i < (symbolData.ports?.length || 0); i++) {
161213
- const port = symbolData.ports[i];
161320
+ const inferredPinNumbers = isChip ? /* @__PURE__ */ new Map : getCircuitPinNumbers({
161321
+ symbolData,
161322
+ schematicComponent,
161323
+ schematicPorts,
161324
+ sourcePorts
161325
+ });
161326
+ const circuitPinNumbers = validateInferredPinNumbers(symbolData, inferredPinNumbers);
161327
+ for (const [i, port] of symbolData.ports.entries()) {
161214
161328
  const pin = new SymbolPin;
161215
161329
  pin.pinElectricalType = "passive";
161216
161330
  pin.pinGraphicStyle = "line";
@@ -161234,7 +161348,7 @@ function createPinSubsymbol({
161234
161348
  const numFont = new TextEffectsFont4;
161235
161349
  numFont.size = { height: 1.27, width: 1.27 };
161236
161350
  const numEffects = new TextEffects4({ font: numFont });
161237
- const pinNum = port.pinNumber?.toString() || `${i + 1}`;
161351
+ const pinNum = port.pinNumber?.toString() ?? circuitPinNumbers.get(i) ?? `${i + 1}`;
161238
161352
  pin._sxNumber = new SymbolPinNumber({
161239
161353
  value: pinNum,
161240
161354
  effects: numEffects
@@ -161286,19 +161400,23 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
161286
161400
  const sourceComp = schematicComponent.source_component_id ? db.source_component.get(schematicComponent.source_component_id) : null;
161287
161401
  if (!sourceComp)
161288
161402
  return null;
161289
- const cadComponent = db.cad_component?.list()?.find((cad) => cad.source_component_id === sourceComp.source_component_id);
161290
- let schematicSymbolId = schematicComponent.schematic_symbol_id;
161291
- if (!schematicSymbolId) {
161292
- const linkedPrimitive = this.ctx.circuitJson.find((el) => (el.type === "schematic_line" || el.type === "schematic_circle" || el.type === "schematic_arc" || el.type === "schematic_path" || el.type === "schematic_rect") && el.schematic_component_id === schematicComponent.schematic_component_id && el.schematic_symbol_id);
161293
- if (linkedPrimitive) {
161294
- schematicSymbolId = linkedPrimitive.schematic_symbol_id;
161295
- }
161296
- }
161403
+ const symbolContext = resolveSchematicComponentSymbol({
161404
+ circuitJson: this.ctx.circuitJson,
161405
+ schematicComponent,
161406
+ sourceComponent: sourceComp,
161407
+ cadComponents: db.cad_component?.list?.() ?? []
161408
+ });
161409
+ const {
161410
+ cadComponent,
161411
+ schematicSymbolId,
161412
+ usesComponentLevelSymbolPrimitives,
161413
+ libraryId,
161414
+ isChip
161415
+ } = symbolContext;
161297
161416
  if (schematicSymbolId) {
161298
- return this.createLibrarySymbolFromSchematicSymbol(schematicComponent, sourceComp, cadComponent, schematicSymbolId);
161417
+ return this.createLibrarySymbolFromSchematicSymbol(schematicComponent, sourceComp, symbolContext);
161299
161418
  }
161300
- const hasInnerSymbolPrimitives = hasComponentLevelSymbolPrimitives(this.ctx.circuitJson, schematicComponent);
161301
- if (hasInnerSymbolPrimitives) {
161419
+ if (usesComponentLevelSymbolPrimitives) {
161302
161420
  const innerSymbolData = buildSymbolDataFromSchematicPrimitives({
161303
161421
  circuitJson: this.ctx.circuitJson,
161304
161422
  schematicComponentId: schematicComponent.schematic_component_id,
@@ -161314,14 +161432,13 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
161314
161432
  ...innerSymbolData,
161315
161433
  texts: []
161316
161434
  };
161317
- const libId2 = getComponentLevelLibraryId(sourceComp, schematicComponent, cadComponent);
161318
161435
  const footprintName2 = getKicadCompatibleComponentName(sourceComp, cadComponent);
161319
161436
  let footprintRef = "";
161320
161437
  if (footprintName2) {
161321
161438
  footprintRef = `tscircuit:${footprintName2}`;
161322
161439
  }
161323
161440
  return this.createLibrarySymbol({
161324
- libId: libId2,
161441
+ libId: libraryId,
161325
161442
  symbolData: symbolData2,
161326
161443
  isChip: false,
161327
161444
  hidePinNames: true,
@@ -161341,11 +161458,9 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
161341
161458
  const symbolData = this.getSymbolData(symbolName, schematicComponent);
161342
161459
  if (!symbolData)
161343
161460
  return null;
161344
- const libId = getLibraryId(sourceComp, schematicComponent, cadComponent);
161345
- const isChip = sourceComp.ftype === "simple_chip" || sourceComp.ftype === "simple_pin_header" || sourceComp.ftype === "simple_connector";
161346
161461
  const footprintName = getKicadCompatibleComponentName(sourceComp, cadComponent);
161347
161462
  return this.createLibrarySymbol({
161348
- libId,
161463
+ libId: libraryId,
161349
161464
  symbolData,
161350
161465
  isChip,
161351
161466
  schematicComponent,
@@ -161357,23 +161472,15 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
161357
161472
  symbolScale: this.ctx.kicadSchematicScaleFactor
161358
161473
  });
161359
161474
  }
161360
- createLibrarySymbolFromSchematicSymbol(schematicComponent, sourceComp, cadComponent, schematicSymbolId) {
161361
- const { db } = this.ctx;
161362
- const schematicSymbol = this.ctx.circuitJson.find((el) => el.type === "schematic_symbol" && el.schematic_symbol_id === schematicSymbolId);
161363
- if (!schematicSymbol) {
161475
+ createLibrarySymbolFromSchematicSymbol(schematicComponent, sourceComp, symbolContext) {
161476
+ const { cadComponent, schematicSymbol, schematicSymbolId, libraryId } = symbolContext;
161477
+ if (!schematicSymbol || !schematicSymbolId) {
161364
161478
  return null;
161365
161479
  }
161366
- let symbolName;
161367
- if (schematicSymbol.name) {
161368
- symbolName = schematicSymbol.name;
161369
- } else {
161370
- symbolName = getKicadCompatibleCustomSymbolName(sourceComp, cadComponent, schematicSymbolId);
161371
- }
161372
- const libId = `Custom:${symbolName}`;
161373
- if (this.processedSymbolNames.has(libId)) {
161480
+ if (this.processedSymbolNames.has(libraryId)) {
161374
161481
  return null;
161375
161482
  }
161376
- this.processedSymbolNames.add(libId);
161483
+ this.processedSymbolNames.add(libraryId);
161377
161484
  const symbolData = buildSymbolDataFromSchematicPrimitives({
161378
161485
  circuitJson: this.ctx.circuitJson,
161379
161486
  schematicSymbolId,
@@ -161384,7 +161491,7 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
161384
161491
  });
161385
161492
  const footprintName = getKicadCompatibleComponentName(sourceComp, cadComponent);
161386
161493
  return this.createLibrarySymbol({
161387
- libId,
161494
+ libId: libraryId,
161388
161495
  symbolData,
161389
161496
  isChip: false,
161390
161497
  schematicComponent,
@@ -161475,6 +161582,7 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
161475
161582
  isChip,
161476
161583
  schematicComponent,
161477
161584
  schematicPorts: this.ctx.db.schematic_port.list(),
161585
+ sourcePorts: this.ctx.db.source_port.list(),
161478
161586
  c2kMatSchScale: symbolScale
161479
161587
  });
161480
161588
  symbol.subSymbols.push(pinSymbol);
@@ -161941,6 +162049,19 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
161941
162049
  const sourceComponent = schematicComponent.source_component_id ? db.source_component.get(schematicComponent.source_component_id) : null;
161942
162050
  if (!sourceComponent)
161943
162051
  continue;
162052
+ const symbolContext = resolveSchematicComponentSymbol({
162053
+ circuitJson: this.ctx.circuitJson,
162054
+ schematicComponent,
162055
+ sourceComponent,
162056
+ cadComponents: db.cad_component?.list?.() ?? []
162057
+ });
162058
+ const {
162059
+ schematicSymbol,
162060
+ schematicSymbolId,
162061
+ hasLinkedSymbolPrimitives,
162062
+ usesComponentLevelSymbolPrimitives,
162063
+ libraryId
162064
+ } = symbolContext;
161944
162065
  if (!this.ctx.c2kMatSch)
161945
162066
  continue;
161946
162067
  const { x, y } = applyToPoint9(this.ctx.c2kMatSch, {
@@ -161958,42 +162079,18 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
161958
162079
  uuid,
161959
162080
  fieldsAutoplaced: false
161960
162081
  });
161961
- const cadComponent = db.cad_component?.list()?.find((cad) => cad.source_component_id === sourceComponent.source_component_id);
161962
- let schematicSymbolName;
161963
- let schematicSymbolId = schematicComponent.schematic_symbol_id;
161964
- if (!schematicSymbolId) {
161965
- const linkedPrimitive = this.ctx.circuitJson.find((el) => (el.type === "schematic_line" || el.type === "schematic_circle" || el.type === "schematic_arc" || el.type === "schematic_path" || el.type === "schematic_rect") && el.schematic_component_id === schematicComponent.schematic_component_id && el.schematic_symbol_id);
161966
- if (linkedPrimitive) {
161967
- schematicSymbolId = linkedPrimitive.schematic_symbol_id;
161968
- }
161969
- }
161970
- if (schematicSymbolId) {
161971
- const schematicSymbol = this.ctx.circuitJson.find((el) => el.type === "schematic_symbol" && el.schematic_symbol_id === schematicSymbolId);
161972
- if (schematicSymbol?.name) {
161973
- schematicSymbolName = schematicSymbol.name;
161974
- } else {
161975
- schematicSymbolName = getKicadCompatibleCustomSymbolName(sourceComponent, cadComponent, schematicSymbolId);
161976
- }
161977
- }
161978
- const usesComponentLevelSymbolPrimitives = hasComponentLevelSymbolPrimitives(this.ctx.circuitJson, schematicComponent);
161979
- const libId = usesComponentLevelSymbolPrimitives ? getComponentLevelLibraryId(sourceComponent, schematicComponent, cadComponent) : getLibraryId(sourceComponent, schematicComponent, cadComponent, schematicSymbolName);
161980
- const symLibId = new SymbolLibId2(libId);
162082
+ const symLibId = new SymbolLibId2(libraryId);
161981
162083
  symbol._sxLibId = symLibId;
161982
162084
  const { reference, value, description } = this.getComponentMetadata(sourceComponent);
161983
162085
  const hasManufacturerValueForValuePlacement = (sourceComponent.ftype === "simple_chip" || sourceComponent.ftype === "simple_connector") && Boolean(sourceComponent.manufacturer_part_number);
161984
162086
  const { refTextPos, valTextPos, refJustify, valJustify } = this.getTextPositions({
161985
162087
  schematicComponent,
161986
162088
  placeValueAtNamePosition: hasManufacturerValueForValuePlacement,
162089
+ isCustomSymbol: hasLinkedSymbolPrimitives,
161987
162090
  reference,
161988
162091
  value
161989
162092
  });
161990
- let symbolMetadata;
161991
- if (schematicSymbolId) {
161992
- const schSymEl = this.ctx.circuitJson.find((el) => el.type === "schematic_symbol" && el.schematic_symbol_id === schematicSymbolId);
161993
- if (schSymEl && schSymEl.type === "schematic_symbol") {
161994
- symbolMetadata = schSymEl.metadata?.kicad_symbol;
161995
- }
161996
- }
162093
+ const symbolMetadata = schematicSymbol?.metadata?.kicad_symbol;
161997
162094
  const refMeta = symbolMetadata?.properties?.Reference;
161998
162095
  const hideGeneratedCustomReference = Boolean(schematicSymbolId) || usesComponentLevelSymbolPrimitives;
161999
162096
  const referenceProperty = new SymbolProperty3({
@@ -162139,6 +162236,7 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
162139
162236
  getTextPositions({
162140
162237
  schematicComponent,
162141
162238
  placeValueAtNamePosition,
162239
+ isCustomSymbol,
162142
162240
  reference,
162143
162241
  value
162144
162242
  }) {
@@ -162154,7 +162252,6 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
162154
162252
  const componentHeightMm = Math.abs(bodyEdge.y - symbolKicadPos.y) * 2;
162155
162253
  const referenceAboveBodyY = symbolKicadPos.y - componentHeightMm / 2 - 3;
162156
162254
  const valueBelowBodyY = symbolKicadPos.y + componentHeightMm / 2 + 3;
162157
- const isCustomSymbol = this.isCustomSymbolComponent(schematicComponent);
162158
162255
  if (isCustomSymbol) {
162159
162256
  const customHeightMm = (schematicComponent.size?.height || 1) * this.ctx.kicadSchematicScaleFactor;
162160
162257
  const refTextPos2 = {
@@ -162254,12 +162351,6 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
162254
162351
  justify: getTextJustificationFromAnchor(text.anchor)
162255
162352
  };
162256
162353
  }
162257
- isCustomSymbolComponent(schematicComponent) {
162258
- const componentId = schematicComponent.schematic_component_id;
162259
- if (!componentId)
162260
- return false;
162261
- return this.ctx.circuitJson.some((el) => (el.type === "schematic_line" || el.type === "schematic_circle" || el.type === "schematic_arc" || el.type === "schematic_path" || el.type === "schematic_rect") && el.schematic_component_id === componentId && el.schematic_symbol_id);
162262
- }
162263
162354
  getComponentMetadata(sourceComp) {
162264
162355
  const name = sourceComp.name || "?";
162265
162356
  const reference = getReferenceDesignator(sourceComp);
@@ -163075,7 +163166,7 @@ var InitializePcbStage = class extends ConverterStage {
163075
163166
  paper.size = "A4";
163076
163167
  kicadPcb.paper = paper;
163077
163168
  const general = new PcbGeneral;
163078
- general.thickness = 1.6;
163169
+ general.thickness = pcbBoard?.thickness ?? 1.6;
163079
163170
  kicadPcb.general = general;
163080
163171
  const setup = new Setup;
163081
163172
  setup.padToMaskClearance = 0;
@@ -163465,6 +163556,17 @@ function applyMetadataToFootprint({
163465
163556
  effects: createTextEffects2(),
163466
163557
  hidden: true
163467
163558
  }));
163559
+ if (componentProperty.manufacturerPartNumber) {
163560
+ newProperties.push(new Property2({
163561
+ key: "MPN",
163562
+ value: componentProperty.manufacturerPartNumber,
163563
+ position: [0, 0, 0],
163564
+ layer: "F.Fab",
163565
+ uuid: generateDeterministicUuid(`${componentProperty.reference}-property-MPN`),
163566
+ effects: createTextEffects2(),
163567
+ hidden: true
163568
+ }));
163569
+ }
163468
163570
  footprint.properties = newProperties;
163469
163571
  if (metadata?.attributes) {
163470
163572
  if (!footprint.attr) {
@@ -163526,12 +163628,14 @@ function getkicadComponentProperty(sourceComp) {
163526
163628
  const name = sourceComp.name || "?";
163527
163629
  const reference = getReferenceDesignator(sourceComp);
163528
163630
  const supplierPartNumber = getJlcpcbSupplierPartNumber(sourceComp);
163631
+ const manufacturerPartNumber = sourceComp.manufacturer_part_number;
163529
163632
  if (sourceComp.ftype === "simple_resistor") {
163530
163633
  const resistor = sourceComp;
163531
163634
  return {
163532
163635
  reference,
163533
163636
  kicadComponentValue: resistor.display_resistance || "R",
163534
- supplierPartNumber
163637
+ supplierPartNumber,
163638
+ manufacturerPartNumber
163535
163639
  };
163536
163640
  }
163537
163641
  if (sourceComp.ftype === "simple_capacitor") {
@@ -163539,7 +163643,8 @@ function getkicadComponentProperty(sourceComp) {
163539
163643
  return {
163540
163644
  reference,
163541
163645
  kicadComponentValue: capacitor.display_capacitance || "C",
163542
- supplierPartNumber
163646
+ supplierPartNumber,
163647
+ manufacturerPartNumber
163543
163648
  };
163544
163649
  }
163545
163650
  if (sourceComp.ftype === "simple_inductor") {
@@ -163547,35 +163652,40 @@ function getkicadComponentProperty(sourceComp) {
163547
163652
  return {
163548
163653
  reference,
163549
163654
  kicadComponentValue: inductor.display_inductance || "L",
163550
- supplierPartNumber
163655
+ supplierPartNumber,
163656
+ manufacturerPartNumber
163551
163657
  };
163552
163658
  }
163553
163659
  if (sourceComp.ftype === "simple_diode") {
163554
163660
  return {
163555
163661
  reference,
163556
163662
  kicadComponentValue: "D",
163557
- supplierPartNumber
163663
+ supplierPartNumber,
163664
+ manufacturerPartNumber
163558
163665
  };
163559
163666
  }
163560
163667
  if (sourceComp.ftype === "simple_chip") {
163561
163668
  return {
163562
163669
  reference,
163563
163670
  kicadComponentValue: sourceComp?.manufacturer_part_number,
163564
- supplierPartNumber
163671
+ supplierPartNumber,
163672
+ manufacturerPartNumber
163565
163673
  };
163566
163674
  }
163567
163675
  if (sourceComp.ftype === "simple_led") {
163568
163676
  return {
163569
163677
  reference,
163570
163678
  kicadComponentValue: sourceComp.manufacturer_part_number || "LED",
163571
- supplierPartNumber
163679
+ supplierPartNumber,
163680
+ manufacturerPartNumber
163572
163681
  };
163573
163682
  }
163574
163683
  if (sourceComp.ftype === "simple_switch") {
163575
163684
  return {
163576
163685
  reference,
163577
163686
  kicadComponentValue: sourceComp.manufacturer_part_number || "SW",
163578
- supplierPartNumber
163687
+ supplierPartNumber,
163688
+ manufacturerPartNumber
163579
163689
  };
163580
163690
  }
163581
163691
  if (sourceComp.ftype === "simple_potentiometer") {
@@ -163583,13 +163693,15 @@ function getkicadComponentProperty(sourceComp) {
163583
163693
  return {
163584
163694
  reference,
163585
163695
  kicadComponentValue: potentiometer.display_max_resistance || "POT",
163586
- supplierPartNumber
163696
+ supplierPartNumber,
163697
+ manufacturerPartNumber
163587
163698
  };
163588
163699
  }
163589
163700
  return {
163590
163701
  reference,
163591
163702
  kicadComponentValue: name,
163592
- supplierPartNumber
163703
+ supplierPartNumber,
163704
+ manufacturerPartNumber
163593
163705
  };
163594
163706
  }
163595
163707
  function convertSilkscreenCircles(silkscreenCircles, { componentCenter, componentRotation = 0 }) {
@@ -163822,6 +163934,7 @@ function createFpTextFromCircuitJson({
163822
163934
  bottom: "B.SilkS"
163823
163935
  };
163824
163936
  const kicadLayer = layerMap[textElement.layer] || textElement.layer || "F.SilkS";
163937
+ const kicadLayerNames = textElement.is_knockout ? [kicadLayer, "knockout"] : kicadLayer;
163825
163938
  const font = new TextEffectsFont10;
163826
163939
  font.size = {
163827
163940
  width: textElement.font_size || 1,
@@ -163846,7 +163959,7 @@ function createFpTextFromCircuitJson({
163846
163959
  y: relativePosition.y,
163847
163960
  angle: rotation
163848
163961
  },
163849
- layer: kicadLayer,
163962
+ layer: kicadLayerNames,
163850
163963
  effects: textEffects
163851
163964
  });
163852
163965
  }
@@ -163912,14 +164025,68 @@ function convertSilkscreenPaths(silkscreenPaths, { componentCenter, componentRot
163912
164025
  }
163913
164026
  return fpLines;
163914
164027
  }
164028
+ var getRectanglePoints = (rect) => {
164029
+ const halfWidth = rect.width / 2;
164030
+ const halfHeight = rect.height / 2;
164031
+ const radius = Math.min(Math.max(rect.corner_radius ?? 0, 0), halfWidth, halfHeight);
164032
+ if (radius === 0) {
164033
+ return [
164034
+ { x: -halfWidth, y: -halfHeight },
164035
+ { x: halfWidth, y: -halfHeight },
164036
+ { x: halfWidth, y: halfHeight },
164037
+ { x: -halfWidth, y: halfHeight }
164038
+ ];
164039
+ }
164040
+ const corners = [
164041
+ { x: halfWidth - radius, y: halfHeight - radius, start: 0 },
164042
+ { x: -halfWidth + radius, y: halfHeight - radius, start: 90 },
164043
+ { x: -halfWidth + radius, y: -halfHeight + radius, start: 180 },
164044
+ { x: halfWidth - radius, y: -halfHeight + radius, start: 270 }
164045
+ ];
164046
+ return corners.flatMap((corner) => Array.from({ length: 9 }, (_, index) => {
164047
+ const angle = (corner.start + index * 90 / 8) * Math.PI / 180;
164048
+ return {
164049
+ x: corner.x + radius * Math.cos(angle),
164050
+ y: corner.y + radius * Math.sin(angle)
164051
+ };
164052
+ }));
164053
+ };
164054
+ function convertSilkscreenRects({
164055
+ silkscreenRects,
164056
+ componentCenter,
164057
+ componentRotation = 0
164058
+ }) {
164059
+ const toLocal = compose5(rotate6(componentRotation * Math.PI / 180), scale3(1, -1), translate5(-componentCenter.x, -componentCenter.y));
164060
+ return silkscreenRects.flatMap((rect) => {
164061
+ const hasStroke = rect.has_stroke ?? rect.stroke_width > 0;
164062
+ if (!hasStroke && !rect.is_filled)
164063
+ return [];
164064
+ const fromRectCenter = compose5(translate5(rect.center.x, rect.center.y), rotate6((rect.ccw_rotation ?? 0) * Math.PI / 180));
164065
+ const points = getRectanglePoints(rect).map((point) => applyToPoint17(toLocal, applyToPoint17(fromRectCenter, point)));
164066
+ const stroke = hasStroke ? new Stroke12 : undefined;
164067
+ if (stroke) {
164068
+ stroke.width = rect.stroke_width;
164069
+ stroke.type = rect.is_stroke_dashed ? "dash" : "default";
164070
+ }
164071
+ return [
164072
+ new FpPoly2({
164073
+ points,
164074
+ layer: rect.layer === "bottom" ? "B.SilkS" : "F.SilkS",
164075
+ stroke,
164076
+ fill: rect.is_filled ?? false,
164077
+ uuid: generateDeterministicUuid(rect.pcb_silkscreen_rect_id)
164078
+ })
164079
+ ];
164080
+ });
164081
+ }
163915
164082
  function convertNoteTexts(params2) {
163916
164083
  const { noteTexts, componentCenter, componentRotation } = params2;
163917
164084
  const fpTexts = [];
163918
164085
  for (const textElement of noteTexts) {
163919
164086
  const relX = textElement.anchor_position.x - componentCenter.x;
163920
164087
  const relY = -(textElement.anchor_position.y - componentCenter.y);
163921
- const rotationMatrix = componentRotation !== 0 ? rotate6(componentRotation * Math.PI / 180) : identity4();
163922
- const rotatedPos = applyToPoint17(rotationMatrix, { x: relX, y: relY });
164088
+ const rotationMatrix = componentRotation !== 0 ? rotate7(componentRotation * Math.PI / 180) : identity4();
164089
+ const rotatedPos = applyToPoint18(rotationMatrix, { x: relX, y: relY });
163923
164090
  const fontSize = textElement.font_size || 1;
163924
164091
  const font = new TextEffectsFont11;
163925
164092
  font.size = { width: fontSize, height: fontSize };
@@ -164033,8 +164200,8 @@ function create3DModelsFromCadComponent(cadComponent, componentCenter, options)
164033
164200
  model.offset = transform.offset;
164034
164201
  model.rotate = transform.rotation;
164035
164202
  if (cadComponent.model_unit_to_mm_scale_factor) {
164036
- const scale5 = cadComponent.model_unit_to_mm_scale_factor;
164037
- model.scale = { x: scale5, y: scale5, z: scale5 };
164203
+ const scale6 = cadComponent.model_unit_to_mm_scale_factor;
164204
+ model.scale = { x: scale6, y: scale6, z: scale6 };
164038
164205
  }
164039
164206
  models.push(model);
164040
164207
  return models;
@@ -164059,8 +164226,8 @@ function createSmdPadFromCircuitJson({
164059
164226
  } else {
164060
164227
  throw new Error("Pad must have either x/y coordinates or points array");
164061
164228
  }
164062
- const cj2kicadMatrix = compose5(componentRotation !== 0 ? rotate7(componentRotation * Math.PI / 180) : { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }, scale3(1, -1), translate5(-componentCenter.x, -componentCenter.y));
164063
- const rotatedPos = applyToPoint18(cj2kicadMatrix, {
164229
+ const cj2kicadMatrix = compose6(componentRotation !== 0 ? rotate8(componentRotation * Math.PI / 180) : { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }, scale4(1, -1), translate6(-componentCenter.x, -componentCenter.y));
164230
+ const rotatedPos = applyToPoint19(cj2kicadMatrix, {
164064
164231
  x: padX,
164065
164232
  y: padY
164066
164233
  });
@@ -164083,9 +164250,9 @@ function createSmdPadFromCircuitJson({
164083
164250
  ];
164084
164251
  } else if (pcbPad.shape === "polygon" && "points" in pcbPad) {
164085
164252
  const points = pcbPad.points;
164086
- const pointTransformMatrix = compose5(scale3(1, -1), translate5(-padX, -padY));
164253
+ const pointTransformMatrix = compose6(scale4(1, -1), translate6(-padX, -padY));
164087
164254
  const relativePoints = points.map((p) => {
164088
- const transformed = applyToPoint18(pointTransformMatrix, { x: p.x, y: p.y });
164255
+ const transformed = applyToPoint19(pointTransformMatrix, { x: p.x, y: p.y });
164089
164256
  return new Xy7(transformed.x, transformed.y);
164090
164257
  });
164091
164258
  const grPoly = new PadPrimitiveGrPoly;
@@ -164197,8 +164364,8 @@ function createThruHolePadFromCircuitJson({
164197
164364
  }
164198
164365
  const relativeX = platedHole.x - componentCenter.x;
164199
164366
  const relativeY = -(platedHole.y - componentCenter.y);
164200
- const rotationMatrix = componentRotation !== 0 ? rotate8(componentRotation * Math.PI / 180) : identity5();
164201
- const rotatedPos = applyToPoint19(rotationMatrix, {
164367
+ const rotationMatrix = componentRotation !== 0 ? rotate9(componentRotation * Math.PI / 180) : identity5();
164368
+ const rotatedPos = applyToPoint20(rotationMatrix, {
164202
164369
  x: relativeX,
164203
164370
  y: relativeY
164204
164371
  });
@@ -164214,7 +164381,7 @@ function createThruHolePadFromCircuitJson({
164214
164381
  y: platedHole.hole_offset_y ?? 0
164215
164382
  };
164216
164383
  if (rawOffset.x !== 0 || rawOffset.y !== 0) {
164217
- const rotatedOffset = applyToPoint19(rotationMatrix, {
164384
+ const rotatedOffset = applyToPoint20(rotationMatrix, {
164218
164385
  x: -rawOffset.x,
164219
164386
  y: rawOffset.y
164220
164387
  });
@@ -164329,8 +164496,8 @@ function createNpthPadFromCircuitJson({
164329
164496
  }
164330
164497
  const relativeX = pcbHole.x - componentCenter.x;
164331
164498
  const relativeY = -(pcbHole.y - componentCenter.y);
164332
- const rotationMatrix = componentRotation !== 0 ? rotate9(componentRotation * Math.PI / 180) : identity6();
164333
- const rotatedPos = applyToPoint20(rotationMatrix, {
164499
+ const rotationMatrix = componentRotation !== 0 ? rotate10(componentRotation * Math.PI / 180) : identity6();
164500
+ const rotatedPos = applyToPoint21(rotationMatrix, {
164334
164501
  x: relativeX,
164335
164502
  y: relativeY
164336
164503
  });
@@ -164404,7 +164571,7 @@ function convertFabricationNotePaths(fabricationNotePaths, {
164404
164571
  componentRotation = 0
164405
164572
  }) {
164406
164573
  const fpLines = [];
164407
- const rotationMatrix = componentRotation !== 0 ? rotate10(componentRotation * Math.PI / 180) : identity7();
164574
+ const rotationMatrix = componentRotation !== 0 ? rotate11(componentRotation * Math.PI / 180) : identity7();
164408
164575
  for (const fabricationNotePath of fabricationNotePaths) {
164409
164576
  if (fabricationNotePath.route.length < 2)
164410
164577
  continue;
@@ -164414,15 +164581,15 @@ function convertFabricationNotePaths(fabricationNotePaths, {
164414
164581
  const endPoint = fabricationNotePath.route[index + 1];
164415
164582
  if (!startPoint || !endPoint)
164416
164583
  continue;
164417
- const startRelative = applyToPoint21(rotationMatrix, {
164584
+ const startRelative = applyToPoint22(rotationMatrix, {
164418
164585
  x: startPoint.x - componentCenter.x,
164419
164586
  y: -(startPoint.y - componentCenter.y)
164420
164587
  });
164421
- const endRelative = applyToPoint21(rotationMatrix, {
164588
+ const endRelative = applyToPoint22(rotationMatrix, {
164422
164589
  x: endPoint.x - componentCenter.x,
164423
164590
  y: -(endPoint.y - componentCenter.y)
164424
164591
  });
164425
- const stroke = new Stroke12;
164592
+ const stroke = new Stroke13;
164426
164593
  stroke.width = fabricationNotePath.stroke_width || 0.1;
164427
164594
  stroke.type = "default";
164428
164595
  fpLines.push(new FpLine2({
@@ -164439,6 +164606,7 @@ var AddFootprintsStage = class extends ConverterStage {
164439
164606
  componentsProcessed = 0;
164440
164607
  pcbComponents = [];
164441
164608
  includeBuiltin3dModels;
164609
+ sourcePortNetKeys = /* @__PURE__ */ Object.create(null);
164442
164610
  getNetInfoForPcbPort(pcbPortId) {
164443
164611
  if (!pcbPortId)
164444
164612
  return;
@@ -164451,10 +164619,23 @@ var AddFootprintsStage = class extends ConverterStage {
164451
164619
  const sourcePort = this.ctx.db.source_port?.get(sourcePortId);
164452
164620
  if (!sourcePort)
164453
164621
  return;
164454
- const connectivityKey = sourcePort.subcircuit_connectivity_map_key;
164455
- if (!connectivityKey)
164456
- return;
164457
- return this.ctx.pcbNetMap?.get(connectivityKey);
164622
+ const keys = [
164623
+ ...this.sourcePortNetKeys[sourcePortId] ?? [],
164624
+ sourcePort.subcircuit_connectivity_map_key
164625
+ ];
164626
+ const nets = [];
164627
+ for (const key of keys) {
164628
+ const net = key ? this.ctx.pcbNetMap?.get(key) : undefined;
164629
+ if (net && !nets.some((existing) => existing.id === net.id)) {
164630
+ nets.push(net);
164631
+ }
164632
+ }
164633
+ if (nets.length > 1) {
164634
+ const component = sourcePort.source_component_id ? this.ctx.db.source_component.get(sourcePort.source_component_id) : undefined;
164635
+ const reference = component?.name || sourcePort.source_component_id || pcbPort.pcb_component_id;
164636
+ throw new Error(`Cannot export ${reference} pad ${sourcePort.pin_number ?? sourcePort.name}: multiple KiCad nets (${nets.map((net) => net.name).join(", ")})`);
164637
+ }
164638
+ return nets[0];
164458
164639
  }
164459
164640
  getCadComponentForPcbComponent(pcbComponentId) {
164460
164641
  const cadComponents = this.ctx.db.cad_component?.list() || [];
@@ -164464,6 +164645,19 @@ var AddFootprintsStage = class extends ConverterStage {
164464
164645
  super(input, ctx);
164465
164646
  this.pcbComponents = this.ctx.db.pcb_component.list();
164466
164647
  this.includeBuiltin3dModels = options?.includeBuiltin3dModels ?? false;
164648
+ for (const trace of ctx.db.source_trace.list()) {
164649
+ const keys = [
164650
+ trace.subcircuit_connectivity_map_key,
164651
+ ...(trace.connected_source_net_ids ?? []).map((id) => {
164652
+ const net = ctx.db.source_net.get(id);
164653
+ return net?.subcircuit_connectivity_map_key || net?.source_net_id;
164654
+ })
164655
+ ].filter((key) => Boolean(key));
164656
+ for (const portId of trace.connected_source_port_ids ?? []) {
164657
+ this.sourcePortNetKeys[portId] ??= [];
164658
+ this.sourcePortNetKeys[portId].push(...keys);
164659
+ }
164660
+ }
164467
164661
  }
164468
164662
  _step() {
164469
164663
  const { kicadPcb, c2kMatPcb } = this.ctx;
@@ -164481,7 +164675,7 @@ var AddFootprintsStage = class extends ConverterStage {
164481
164675
  const sourceComponent = component.source_component_id ? this.ctx.db.source_component.get(component.source_component_id) : null;
164482
164676
  const cadComponent = this.getCadComponentForPcbComponent(component.pcb_component_id);
164483
164677
  const footprintName = sourceComponent ? getKicadCompatibleComponentName(sourceComponent, cadComponent) : "Unknown";
164484
- const transformedPos = applyToPoint22(c2kMatPcb, {
164678
+ const transformedPos = applyToPoint23(c2kMatPcb, {
164485
164679
  x: component.center.x,
164486
164680
  y: component.center.y
164487
164681
  });
@@ -164572,6 +164766,12 @@ var AddFootprintsStage = class extends ConverterStage {
164572
164766
  componentCenter: component.center,
164573
164767
  componentRotation: component.rotation || 0
164574
164768
  });
164769
+ const pcbSilkscreenRects = this.ctx.db.pcb_silkscreen_rect?.list().filter((rect) => rect.pcb_component_id === component.pcb_component_id) || [];
164770
+ fpPolys.push(...convertSilkscreenRects({
164771
+ silkscreenRects: pcbSilkscreenRects,
164772
+ componentCenter: component.center,
164773
+ componentRotation: component.rotation || 0
164774
+ }));
164575
164775
  if (fpPolys.length > 0) {
164576
164776
  footprint.fpPolys = fpPolys;
164577
164777
  }
@@ -164628,6 +164828,10 @@ var AddFootprintsStage = class extends ConverterStage {
164628
164828
  componentProperty: kicadComponentProperty
164629
164829
  });
164630
164830
  }
164831
+ if (component.do_not_place) {
164832
+ footprint.attr ??= new FootprintAttr3;
164833
+ footprint.attr.dnp = true;
164834
+ }
164631
164835
  const footprints = kicadPcb.footprints;
164632
164836
  footprints.push(footprint);
164633
164837
  kicadPcb.footprints = footprints;
@@ -164701,8 +164905,8 @@ var AddTracesStage = class extends ConverterStage {
164701
164905
  if (!startPosition || !endPosition) {
164702
164906
  throw new Error(`Unable to convert pcb_trace route segment ${trace.pcb_trace_id ?? this.tracesProcessed}:${i} to KiCad segment`);
164703
164907
  }
164704
- const transformedStart = applyToPoint23(c2kMatPcb, startPosition);
164705
- const transformedEnd = applyToPoint23(c2kMatPcb, endPosition);
164908
+ const transformedStart = applyToPoint24(c2kMatPcb, startPosition);
164909
+ const transformedEnd = applyToPoint24(c2kMatPcb, endPosition);
164706
164910
  if (transformedStart.x === transformedEnd.x && transformedStart.y === transformedEnd.y) {
164707
164911
  continue;
164708
164912
  }
@@ -164716,8 +164920,8 @@ var AddTracesStage = class extends ConverterStage {
164716
164920
  if (!connectivityKey && sourceTrace.connected_source_net_ids?.length) {
164717
164921
  for (const sourceNetId of sourceTrace.connected_source_net_ids) {
164718
164922
  const sourceNet = this.ctx.db.source_net?.get(sourceNetId);
164719
- if (sourceNet?.subcircuit_connectivity_map_key) {
164720
- connectivityKey = sourceNet.subcircuit_connectivity_map_key;
164923
+ if (sourceNet) {
164924
+ connectivityKey = sourceNet.subcircuit_connectivity_map_key || sourceNet.source_net_id;
164721
164925
  break;
164722
164926
  }
164723
164927
  }
@@ -164726,8 +164930,8 @@ var AddTracesStage = class extends ConverterStage {
164726
164930
  }
164727
164931
  if (!connectivityKey && typeof trace.connection_name === "string") {
164728
164932
  const sourceNet = this.ctx.db.source_net?.get(trace.connection_name);
164729
- if (sourceNet?.subcircuit_connectivity_map_key) {
164730
- connectivityKey = sourceNet.subcircuit_connectivity_map_key;
164933
+ if (sourceNet) {
164934
+ connectivityKey = sourceNet.subcircuit_connectivity_map_key || sourceNet.source_net_id;
164731
164935
  }
164732
164936
  }
164733
164937
  if (connectivityKey) {
@@ -164826,13 +165030,19 @@ var AddViasStage = class extends ConverterStage {
164826
165030
  this.finished = true;
164827
165031
  return;
164828
165032
  }
164829
- const transformedPos = applyToPoint24(c2kMatPcb, {
165033
+ const transformedPos = applyToPoint25(c2kMatPcb, {
164830
165034
  x: via.x,
164831
165035
  y: via.y
164832
165036
  });
164833
165037
  let netInfo;
164834
165038
  if (pcbNetMap) {
164835
165039
  let connectivityKey = via.subcircuit_connectivity_map_key;
165040
+ if (!connectivityKey && via.source_net_id) {
165041
+ const sourceNet = this.ctx.db.source_net?.get(via.source_net_id);
165042
+ if (sourceNet) {
165043
+ connectivityKey = sourceNet.subcircuit_connectivity_map_key || sourceNet.source_net_id;
165044
+ }
165045
+ }
164836
165046
  if (!connectivityKey && via.pcb_trace_id) {
164837
165047
  const pcbTrace = this.ctx.db.pcb_trace?.get(via.pcb_trace_id);
164838
165048
  if (pcbTrace) {
@@ -164848,8 +165058,8 @@ var AddViasStage = class extends ConverterStage {
164848
165058
  if (!connectivityKey && sourceTrace.connected_source_net_ids?.length) {
164849
165059
  for (const sourceNetId of sourceTrace.connected_source_net_ids) {
164850
165060
  const sourceNet = this.ctx.db.source_net?.get(sourceNetId);
164851
- if (sourceNet?.subcircuit_connectivity_map_key) {
164852
- connectivityKey = sourceNet.subcircuit_connectivity_map_key;
165061
+ if (sourceNet) {
165062
+ connectivityKey = sourceNet.subcircuit_connectivity_map_key || sourceNet.source_net_id;
164853
165063
  break;
164854
165064
  }
164855
165065
  }
@@ -164857,8 +165067,8 @@ var AddViasStage = class extends ConverterStage {
164857
165067
  }
164858
165068
  if (!connectivityKey) {
164859
165069
  const sourceNet = this.ctx.db.source_net?.get(pcbTrace.source_trace_id);
164860
- if (sourceNet?.subcircuit_connectivity_map_key) {
164861
- connectivityKey = sourceNet.subcircuit_connectivity_map_key;
165070
+ if (sourceNet) {
165071
+ connectivityKey = sourceNet.subcircuit_connectivity_map_key || sourceNet.source_net_id;
164862
165072
  }
164863
165073
  }
164864
165074
  }
@@ -164866,8 +165076,8 @@ var AddViasStage = class extends ConverterStage {
164866
165076
  }
164867
165077
  if (!connectivityKey && via.connection_name) {
164868
165078
  const sourceNet = this.ctx.db.source_net?.get(via.connection_name);
164869
- if (sourceNet?.subcircuit_connectivity_map_key) {
164870
- connectivityKey = sourceNet.subcircuit_connectivity_map_key;
165079
+ if (sourceNet) {
165080
+ connectivityKey = sourceNet.subcircuit_connectivity_map_key || sourceNet.source_net_id;
164871
165081
  }
164872
165082
  }
164873
165083
  if (connectivityKey) {
@@ -164922,7 +165132,7 @@ var AddStandalonePcbElements = class extends ConverterStage {
164922
165132
  const pcbPad = elm;
164923
165133
  const padCenter = this.getPcbSmtPadCenter(pcbPad);
164924
165134
  const footprintSeed = `standalone_smtpad:${pcbPad.pcb_smtpad_id}:${padCenter.x},${padCenter.y}`;
164925
- const kicadPos = applyToPoint25(c2kMatPcb, padCenter);
165135
+ const kicadPos = applyToPoint26(c2kMatPcb, padCenter);
164926
165136
  const footprint = new Footprint4({
164927
165137
  libraryLink: this.getSmtPadLibraryLink(pcbPad),
164928
165138
  layer: "F.Cu",
@@ -164944,7 +165154,7 @@ var AddStandalonePcbElements = class extends ConverterStage {
164944
165154
  } else if (elm.type === "pcb_hole") {
164945
165155
  const hole = elm;
164946
165156
  const footprintSeed = `standalone_hole:${hole.pcb_hole_id}:${hole.x},${hole.y}`;
164947
- const kicadPos = applyToPoint25(c2kMatPcb, { x: hole.x, y: hole.y });
165157
+ const kicadPos = applyToPoint26(c2kMatPcb, { x: hole.x, y: hole.y });
164948
165158
  const libraryLink = this.getHoleLibraryLink(hole);
164949
165159
  const footprint = new Footprint4({
164950
165160
  libraryLink,
@@ -164967,7 +165177,7 @@ var AddStandalonePcbElements = class extends ConverterStage {
164967
165177
  } else if (elm.type === "pcb_plated_hole") {
164968
165178
  const hole = elm;
164969
165179
  const footprintSeed = `standalone_plated_hole:${hole.pcb_plated_hole_id}:${hole.x},${hole.y}`;
164970
- const kicadPos = applyToPoint25(c2kMatPcb, { x: hole.x, y: hole.y });
165180
+ const kicadPos = applyToPoint26(c2kMatPcb, { x: hole.x, y: hole.y });
164971
165181
  const libraryLink = this.getPlatedHoleLibraryLink(hole);
164972
165182
  const footprint = new Footprint4({
164973
165183
  libraryLink,
@@ -165064,7 +165274,7 @@ function createFabricationNoteTextFromCircuitJson({
165064
165274
  if (!textElement.text || !textElement.anchor_position) {
165065
165275
  return null;
165066
165276
  }
165067
- const transformedPos = applyToPoint26(c2kMatPcb, {
165277
+ const transformedPos = applyToPoint27(c2kMatPcb, {
165068
165278
  x: textElement.anchor_position.x,
165069
165279
  y: textElement.anchor_position.y
165070
165280
  });
@@ -165122,7 +165332,7 @@ function createGrTextFromCircuitJson({
165122
165332
  if (!textElement.text || !textElement.anchor_position) {
165123
165333
  return null;
165124
165334
  }
165125
- const transformedPos = applyToPoint27(c2kMatPcb, {
165335
+ const transformedPos = applyToPoint28(c2kMatPcb, {
165126
165336
  x: textElement.anchor_position.x,
165127
165337
  y: textElement.anchor_position.y
165128
165338
  });
@@ -165131,12 +165341,14 @@ function createGrTextFromCircuitJson({
165131
165341
  bottom: "B.SilkS"
165132
165342
  };
165133
165343
  const kicadLayer = layerMap[textElement.layer] || textElement.layer || "F.SilkS";
165344
+ const kicadLayerNames = textElement.is_knockout ? [kicadLayer, "knockout"] : kicadLayer;
165134
165345
  const font = new TextEffectsFont13;
165346
+ const fontSize = textElement.font_size || 1;
165135
165347
  font.size = {
165136
- width: textElement.font_size || 1,
165137
- height: textElement.font_size || 1
165348
+ width: fontSize,
165349
+ height: fontSize
165138
165350
  };
165139
- font.thickness = 0.15;
165351
+ font.thickness = fontSize > 1 ? Math.min(0.3, fontSize * 0.2) : 0.15;
165140
165352
  const textEffects = new TextEffects13({ font });
165141
165353
  const justify = createPcbTextJustify({
165142
165354
  anchorAlignment: textElement.anchor_alignment,
@@ -165150,7 +165362,7 @@ function createGrTextFromCircuitJson({
165150
165362
  const position = new At4([transformedPos.x, transformedPos.y, rotation]);
165151
165363
  const grText = new GrText2({
165152
165364
  text: textElement.text,
165153
- layer: kicadLayer,
165365
+ layer: kicadLayerNames,
165154
165366
  effects: textEffects,
165155
165367
  uuid: generateDeterministicUuid(textElement.pcb_silkscreen_text_id ?? textElement.text)
165156
165368
  });
@@ -165171,7 +165383,7 @@ var normalizeOutlineCorners = (corners) => {
165171
165383
  }
165172
165384
  return dedupedCorners;
165173
165385
  };
165174
- var EDGE_CUTS_WIDTH = 0.1;
165386
+ var DEFAULT_EDGE_CUTS_WIDTH = 0.1;
165175
165387
  var appendGraphicLine = (kicadPcb, grLine) => {
165176
165388
  const graphicLines = kicadPcb.graphicLines;
165177
165389
  graphicLines.push(grLine);
@@ -165180,7 +165392,7 @@ var appendGraphicLine = (kicadPcb, grLine) => {
165180
165392
  var rotatePointAroundOrigin = (point, rotationDegrees = 0) => {
165181
165393
  if (!rotationDegrees)
165182
165394
  return point;
165183
- return applyToPoint28(rotate11(rotationDegrees * Math.PI / 180), point);
165395
+ return applyToPoint29(rotate12(rotationDegrees * Math.PI / 180), point);
165184
165396
  };
165185
165397
  var getRectCutoutCorners = (cutout) => {
165186
165398
  const halfWidth = cutout.width / 2;
@@ -165202,6 +165414,7 @@ var getRectCutoutCorners = (cutout) => {
165202
165414
  var AddGraphicsStage = class extends ConverterStage {
165203
165415
  _step() {
165204
165416
  const { kicadPcb, c2kMatPcb } = this.ctx;
165417
+ const edgeCutsWidth = this.ctx.edgeCutsWidth ?? DEFAULT_EDGE_CUTS_WIDTH;
165205
165418
  if (!kicadPcb) {
165206
165419
  throw new Error("KicadPcb instance not initialized in context");
165207
165420
  }
@@ -165217,11 +165430,11 @@ var AddGraphicsStage = class extends ConverterStage {
165217
165430
  const endPoint = path.route[i + 1];
165218
165431
  if (!startPoint || !endPoint)
165219
165432
  continue;
165220
- const transformedStart = applyToPoint28(c2kMatPcb, {
165433
+ const transformedStart = applyToPoint29(c2kMatPcb, {
165221
165434
  x: startPoint.x,
165222
165435
  y: startPoint.y
165223
165436
  });
165224
- const transformedEnd = applyToPoint28(c2kMatPcb, {
165437
+ const transformedEnd = applyToPoint29(c2kMatPcb, {
165225
165438
  x: endPoint.x,
165226
165439
  y: endPoint.y
165227
165440
  });
@@ -165301,7 +165514,7 @@ var AddGraphicsStage = class extends ConverterStage {
165301
165514
  }
165302
165515
  for (const poly of boardGeom) {
165303
165516
  for (const ring of poly) {
165304
- const transformedRing = ring.map((point) => applyToPoint28(c2kMatPcb, { x: point[0], y: point[1] }));
165517
+ const transformedRing = ring.map((point) => applyToPoint29(c2kMatPcb, { x: point[0], y: point[1] }));
165305
165518
  for (let i = 0;i < transformedRing.length; i++) {
165306
165519
  const start = transformedRing[i];
165307
165520
  const end = transformedRing[(i + 1) % transformedRing.length];
@@ -165313,7 +165526,7 @@ var AddGraphicsStage = class extends ConverterStage {
165313
165526
  start: { x: start.x, y: start.y },
165314
165527
  end: { x: end.x, y: end.y },
165315
165528
  layer: "Edge.Cuts",
165316
- width: EDGE_CUTS_WIDTH
165529
+ width: edgeCutsWidth
165317
165530
  });
165318
165531
  appendGraphicLine(kicadPcb, edgeLine);
165319
165532
  }
@@ -165330,13 +165543,13 @@ var AddGraphicsStage = class extends ConverterStage {
165330
165543
  const endPoint = cutout.route[i + 1];
165331
165544
  if (!startPoint || !endPoint)
165332
165545
  continue;
165333
- const transformedStart = applyToPoint28(c2kMatPcb, startPoint);
165334
- const transformedEnd = applyToPoint28(c2kMatPcb, endPoint);
165546
+ const transformedStart = applyToPoint29(c2kMatPcb, startPoint);
165547
+ const transformedEnd = applyToPoint29(c2kMatPcb, endPoint);
165335
165548
  appendGraphicLine(kicadPcb, new GrLine({
165336
165549
  start: transformedStart,
165337
165550
  end: transformedEnd,
165338
165551
  layer: "Edge.Cuts",
165339
- width: EDGE_CUTS_WIDTH
165552
+ width: edgeCutsWidth
165340
165553
  }));
165341
165554
  }
165342
165555
  }
@@ -165366,8 +165579,9 @@ var CircuitJsonToKicadPcbConverter = class {
165366
165579
  generator: "circuit-json-to-kicad",
165367
165580
  generatorVersion: "0.0.1"
165368
165581
  }),
165369
- c2kMatPcb: compose6(translate6(KICAD_PCB_CENTER_X, KICAD_PCB_CENTER_Y), scale4(CIRCUIT_JSON_TO_MM_SCALE, -CIRCUIT_JSON_TO_MM_SCALE)),
165582
+ c2kMatPcb: compose7(translate7(KICAD_PCB_CENTER_X, KICAD_PCB_CENTER_Y), scale5(CIRCUIT_JSON_TO_MM_SCALE, -CIRCUIT_JSON_TO_MM_SCALE)),
165370
165583
  projectName: options?.projectName,
165584
+ edgeCutsWidth: options?.edgeCutsWidth,
165371
165585
  pcbModel3dSourcePaths: []
165372
165586
  };
165373
165587
  this.pipeline = [
@@ -168276,11 +168490,11 @@ import base64Font from "@tscircuit/alphabet/base64font";
168276
168490
  import"circuit-json";
168277
168491
  import {
168278
168492
  applyToPoint as applyToPoint47,
168279
- compose as compose7,
168493
+ compose as compose72,
168280
168494
  scale as scale32,
168281
- translate as translate7
168495
+ translate as translate72
168282
168496
  } from "transformation-matrix";
168283
- import { applyToPoint as applyToPoint29 } from "transformation-matrix";
168497
+ import { applyToPoint as applyToPoint30 } from "transformation-matrix";
168284
168498
  import { applyToPoint as applyToPoint210 } from "transformation-matrix";
168285
168499
  import { applyToPoint as applyToPoint32 } from "transformation-matrix";
168286
168500
  import { applyToPoint as applyToPoint42 } from "transformation-matrix";
@@ -168288,7 +168502,7 @@ import { applyToPoint as applyToPoint52 } from "transformation-matrix";
168288
168502
  import { applyToPoint as applyToPoint62 } from "transformation-matrix";
168289
168503
  import Debug2 from "debug";
168290
168504
  import { toString as matrixToString } from "transformation-matrix";
168291
- import { applyToPoint as applyToPoint72, compose as compose8, rotate as rotate12, translate as translate8 } from "transformation-matrix";
168505
+ import { applyToPoint as applyToPoint72, compose as compose8, rotate as rotate13, translate as translate8 } from "transformation-matrix";
168292
168506
  import { applyToPoint as applyToPoint82 } from "transformation-matrix";
168293
168507
  import { applyToPoint as applyToPoint92 } from "transformation-matrix";
168294
168508
  import { applyToPoint as applyToPoint102 } from "transformation-matrix";
@@ -168304,7 +168518,7 @@ import {
168304
168518
  compose as compose22,
168305
168519
  rotate as rotate22,
168306
168520
  translate as translate22,
168307
- scale as scale5,
168521
+ scale as scale6,
168308
168522
  toString as matrixToString2
168309
168523
  } from "transformation-matrix";
168310
168524
  import { lineAlphabet } from "@tscircuit/alphabet";
@@ -168339,7 +168553,7 @@ import {
168339
168553
  } from "circuit-json";
168340
168554
  import { applyToPoint as applyToPoint292 } from "transformation-matrix";
168341
168555
  import {
168342
- applyToPoint as applyToPoint30,
168556
+ applyToPoint as applyToPoint302,
168343
168557
  compose as compose42,
168344
168558
  rotate as rotate42,
168345
168559
  toString as matrixToString6,
@@ -168435,7 +168649,7 @@ import {
168435
168649
  applyToPoint as applyToPoint66,
168436
168650
  compose as compose11,
168437
168651
  rotate as rotate62,
168438
- scale as scale6,
168652
+ scale as scale62,
168439
168653
  translate as translate11
168440
168654
  } from "transformation-matrix";
168441
168655
  import { symbols as symbols22 } from "schematic-symbols";
@@ -168698,7 +168912,7 @@ function createSvgObjectsFromPcbTraceError(pcbTraceError, circuitJson, ctx) {
168698
168912
  return createSvgObjectsForViaTraceError(pcbTraceError, via, ctx);
168699
168913
  }
168700
168914
  if (pcbTraceError.center) {
168701
- const screenCenter = applyToPoint29(transform, {
168915
+ const screenCenter = applyToPoint30(transform, {
168702
168916
  x: pcbTraceError.center.x,
168703
168917
  y: pcbTraceError.center.y
168704
168918
  });
@@ -168743,11 +168957,11 @@ function createSvgObjectsFromPcbTraceError(pcbTraceError, circuitJson, ctx) {
168743
168957
  } else
168744
168958
  return [];
168745
168959
  }
168746
- const screenPort1 = applyToPoint29(transform, {
168960
+ const screenPort1 = applyToPoint30(transform, {
168747
168961
  x: port1.x,
168748
168962
  y: port1.y
168749
168963
  });
168750
- const screenPort2 = applyToPoint29(transform, {
168964
+ const screenPort2 = applyToPoint30(transform, {
168751
168965
  x: port2.x,
168752
168966
  y: port2.y
168753
168967
  });
@@ -168831,11 +169045,11 @@ function createSvgObjectsFromPcbTraceError(pcbTraceError, circuitJson, ctx) {
168831
169045
  function createSvgObjectsForViaTraceError(pcbTraceError, via, ctx) {
168832
169046
  const { transform } = ctx;
168833
169047
  if (pcbTraceError.center && via) {
168834
- const screenCenter = applyToPoint29(transform, {
169048
+ const screenCenter = applyToPoint30(transform, {
168835
169049
  x: pcbTraceError.center.x,
168836
169050
  y: pcbTraceError.center.y
168837
169051
  });
168838
- const screenVia = applyToPoint29(transform, {
169052
+ const screenVia = applyToPoint30(transform, {
168839
169053
  x: via.x,
168840
169054
  y: via.y
168841
169055
  });
@@ -169542,7 +169756,7 @@ function createSvgObjectsFromPcbFabricationNoteText(pcbFabNoteText, ctx) {
169542
169756
  ]);
169543
169757
  const transformedFontSize = font_size * Math.abs(transform.a);
169544
169758
  const { textAnchor, dominantBaseline } = getSvgTextAnchorAlignment(anchor_alignment);
169545
- const textTransform = compose8(translate8(transformedX, transformedY), rotate12(-ccw_rotation * Math.PI / 180));
169759
+ const textTransform = compose8(translate8(transformedX, transformedY), rotate13(-ccw_rotation * Math.PI / 180));
169546
169760
  const svgObject = {
169547
169761
  name: "text",
169548
169762
  type: "element",
@@ -171909,7 +172123,7 @@ function createSvgObjectsFromPcbSilkscreenText(pcbSilkscreenText, ctx) {
171909
172123
  children: maskCutoutChildren
171910
172124
  }
171911
172125
  ] : maskCutoutChildren;
171912
- const knockoutTransform = matrixToString2(compose22(translate22(transformedX, transformedY), rotate22(-ccw_rotation * Math.PI / 180), ...applyMirror ? [scale5(-1, 1)] : [], scale5(scaleFactor, scaleFactor)));
172126
+ const knockoutTransform = matrixToString2(compose22(translate22(transformedX, transformedY), rotate22(-ccw_rotation * Math.PI / 180), ...applyMirror ? [scale6(-1, 1)] : [], scale6(scaleFactor, scaleFactor)));
171913
172127
  const maskId = `silkscreen-knockout-mask-${pcbSilkscreenText.pcb_silkscreen_text_id}-${silkscreenMaskIdCounter++}`;
171914
172128
  return [
171915
172129
  {
@@ -171992,7 +172206,7 @@ function createSvgObjectsFromPcbSilkscreenText(pcbSilkscreenText, ctx) {
171992
172206
  dominantBaseline = "central";
171993
172207
  break;
171994
172208
  }
171995
- const textTransform = compose22(translate22(transformedX, transformedY), rotate22(-ccw_rotation * Math.PI / 180), ...applyMirror ? [scale5(-1, 1)] : []);
172209
+ const textTransform = compose22(translate22(transformedX, transformedY), rotate22(-ccw_rotation * Math.PI / 180), ...applyMirror ? [scale6(-1, 1)] : []);
171996
172210
  const lines = text.split(`
171997
172211
  `);
171998
172212
  const children = lines.length === 1 ? [
@@ -173132,7 +173346,7 @@ function createSvgObjectsFromPcbVia(hole, ctx) {
173132
173346
  }
173133
173347
  function getCopperPourShape(pour, transform) {
173134
173348
  if (pour.shape === "rect") {
173135
- const [cx, cy] = applyToPoint30(transform, [pour.center.x, pour.center.y]);
173349
+ const [cx, cy] = applyToPoint302(transform, [pour.center.x, pour.center.y]);
173136
173350
  const scaledWidth = pour.width * Math.abs(transform.a);
173137
173351
  const scaledHeight = pour.height * Math.abs(transform.d);
173138
173352
  const svgRotation = -(pour.rotation ?? 0);
@@ -173150,7 +173364,7 @@ function getCopperPourShape(pour, transform) {
173150
173364
  if (pour.shape === "polygon") {
173151
173365
  if (!pour.points || pour.points.length === 0)
173152
173366
  return null;
173153
- const pointsString = pour.points.map((p) => applyToPoint30(transform, [p.x, p.y])).map((p) => `${p[0]},${p[1]}`).join(" ");
173367
+ const pointsString = pour.points.map((p) => applyToPoint302(transform, [p.x, p.y])).map((p) => `${p[0]},${p[1]}`).join(" ");
173154
173368
  return {
173155
173369
  elementType: "polygon",
173156
173370
  shapeAttributes: { points: pointsString }
@@ -177510,7 +177724,7 @@ function convertCircuitJsonToPcbSvg2(circuitJson, options) {
177510
177724
  const scaleFactor = Math.min(scaleX, scaleY);
177511
177725
  const offsetX = (svgWidth - circuitWidth * scaleFactor) / 2;
177512
177726
  const offsetY = (svgHeight - circuitHeight * scaleFactor) / 2;
177513
- const transform = compose7(translate7(offsetX - boundsMinX * scaleFactor + padding * scaleFactor, svgHeight - offsetY + boundsMinY * scaleFactor - padding * scaleFactor), scale32(scaleFactor, -scaleFactor));
177727
+ const transform = compose72(translate72(offsetX - boundsMinX * scaleFactor + padding * scaleFactor, svgHeight - offsetY + boundsMinY * scaleFactor - padding * scaleFactor), scale32(scaleFactor, -scaleFactor));
177514
177728
  const viewportScale = Math.min(svgWidth, svgHeight);
177515
177729
  const debugStrokeWidth = Math.max(1, Math.min(2, viewportScale * 0.002));
177516
177730
  const debugFontSize = Math.max(10, Math.min(18, viewportScale * 0.02));
@@ -309610,14 +309824,14 @@ var PrimitiveComponent2 = class extends Renderable {
309610
309824
  computePcbPropsTransform() {
309611
309825
  const rotation42 = this._getPcbRotationBeforeLayout() ?? 0;
309612
309826
  const { pcbX, pcbY } = this.getResolvedPcbPositionProp();
309613
- const matrix2 = compose14(translate13(pcbX, pcbY), rotate13(rotation42 * Math.PI / 180));
309827
+ const matrix2 = compose14(translate13(pcbX, pcbY), rotate14(rotation42 * Math.PI / 180));
309614
309828
  return matrix2;
309615
309829
  }
309616
309830
  _computePcbGlobalTransformBeforeLayout() {
309617
309831
  const manualPlacement = this.getSubcircuit()._getPcbManualPlacementForComponent(this);
309618
309832
  if (manualPlacement && this.props.pcbX === undefined && this.props.pcbY === undefined) {
309619
309833
  const rotation42 = this._getPcbRotationBeforeLayout() ?? 0;
309620
- return compose14(this.parent?._computePcbGlobalTransformBeforeLayout() ?? identity8(), compose14(translate13(manualPlacement.x, manualPlacement.y), rotate13(rotation42 * Math.PI / 180)));
309834
+ return compose14(this.parent?._computePcbGlobalTransformBeforeLayout() ?? identity8(), compose14(translate13(manualPlacement.x, manualPlacement.y), rotate14(rotation42 * Math.PI / 180)));
309621
309835
  }
309622
309836
  if (this.isPcbPrimitive) {
309623
309837
  const primitiveContainer = this.getPrimitiveContainer();
@@ -318977,7 +319191,7 @@ var extractPcbPrimitivesFromCircuitJson = ({
318977
319191
  }) => {
318978
319192
  const componentCenter = pcbComponent.center || { x: 0, y: 0 };
318979
319193
  const componentRotation = pcbComponent.rotation || 0;
318980
- const absoluteToComponentRelativeTransform = inverse(compose14(translate13(componentCenter.x, componentCenter.y), rotate13(componentRotation * Math.PI / 180)));
319194
+ const absoluteToComponentRelativeTransform = inverse(compose14(translate13(componentCenter.x, componentCenter.y), rotate14(componentRotation * Math.PI / 180)));
318981
319195
  const relativeElements = db2.toArray().filter((elm) => ("pcb_component_id" in elm) && elm.pcb_component_id === pcbComponent.pcb_component_id);
318982
319196
  const clonedRelativeElements = structuredClone(relativeElements);
318983
319197
  transformPCBElements(clonedRelativeElements, absoluteToComponentRelativeTransform);
@@ -321005,7 +321219,7 @@ var applyPackOutput = (group, packOutput, clusterMap) => {
321005
321219
  if (!member)
321006
321220
  continue;
321007
321221
  const originalCenter2 = member.center;
321008
- const transformMatrix2 = compose14(group._computePcbGlobalTransformBeforeLayout(), translate13(center2.x + rotatedRel.x, center2.y + rotatedRel.y), rotate13(angleRad), translate13(-originalCenter2.x, -originalCenter2.y));
321222
+ const transformMatrix2 = compose14(group._computePcbGlobalTransformBeforeLayout(), translate13(center2.x + rotatedRel.x, center2.y + rotatedRel.y), rotate14(angleRad), translate13(-originalCenter2.x, -originalCenter2.y));
321009
321223
  const related = db2.toArray().filter((elm) => ("pcb_component_id" in elm) && elm.pcb_component_id === memberId);
321010
321224
  transformPCBElements(related, transformMatrix2);
321011
321225
  updateCadRotation({
@@ -321030,7 +321244,7 @@ var applyPackOutput = (group, packOutput, clusterMap) => {
321030
321244
  }
321031
321245
  const originalCenter2 = pcbComponent.center;
321032
321246
  const rotationDegrees2 = ccwRotationDegrees ?? ccwRotationOffset ?? 0;
321033
- const transformMatrix2 = compose14(group._computePcbGlobalTransformBeforeLayout(), translate13(center2.x, center2.y), rotate13(rotationDegrees2 * Math.PI / 180), translate13(-originalCenter2.x, -originalCenter2.y));
321247
+ const transformMatrix2 = compose14(group._computePcbGlobalTransformBeforeLayout(), translate13(center2.x, center2.y), rotate14(rotationDegrees2 * Math.PI / 180), translate13(-originalCenter2.x, -originalCenter2.y));
321034
321248
  const related = db2.toArray().filter((elm) => ("pcb_component_id" in elm) && elm.pcb_component_id === componentId);
321035
321249
  transformPCBElements(related, transformMatrix2);
321036
321250
  updateCadRotation({
@@ -321046,7 +321260,7 @@ var applyPackOutput = (group, packOutput, clusterMap) => {
321046
321260
  continue;
321047
321261
  const originalCenter = pcbGroup.center;
321048
321262
  const rotationDegrees = ccwRotationDegrees ?? ccwRotationOffset ?? 0;
321049
- const transformMatrix = compose14(group._computePcbGlobalTransformBeforeLayout(), translate13(center2.x, center2.y), rotate13(rotationDegrees * Math.PI / 180), translate13(-originalCenter.x, -originalCenter.y));
321263
+ const transformMatrix = compose14(group._computePcbGlobalTransformBeforeLayout(), translate13(center2.x, center2.y), rotate14(rotationDegrees * Math.PI / 180), translate13(-originalCenter.x, -originalCenter.y));
321050
321264
  const relatedElements = db2.toArray().filter((elm) => {
321051
321265
  if ("source_group_id" in elm && elm.source_group_id) {
321052
321266
  if (elm.source_group_id === componentId) {