@tscircuit/circuit-json-util 0.0.103 → 0.0.104

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/README.md CHANGED
@@ -50,6 +50,7 @@ It reduces the amount of code to retrieve or join elements from circuit json, it
50
50
  | `getElementRenderLayers` | [`lib/get-element-render-layers.ts`](./lib/get-element-render-layers.ts) | Returns schematic/PCB render layers used for an element. |
51
51
  | `computeClearanceBetweenElements` | [`lib/compute-clearance-between-elements.ts`](./lib/compute-clearance-between-elements.ts) | Computes the minimum edge-to-edge clearance between two circuit elements using geometric decomposition. |
52
52
  | `computeGapBetweenCopper` | [`lib/compute-gap-between-copper.ts`](./lib/compute-gap-between-copper.ts) | Computes the minimum copper-to-copper gap between two circuit elements by decomposing them into primitive shapes. |
53
+ | `analyzePcbPin1Location` | [`lib/analyze-pcb-pin1-location.ts`](./lib/analyze-pcb-pin1-location.ts) | Infers a semantic pin 1 location from PCB pad geometry and numeric port hints. |
53
54
  | `categorizeErrorOrWarning` | [`lib/categorize-error-or-warning.ts`](./lib/categorize-error-or-warning.ts) | Categorizes DRC error/warning types into `"netlist"`, `"pin_specification"`, `"placement"`, `"routing"`, or `"unknown"`. |
54
55
 
55
56
  ## Standard Usage
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as circuit_json from 'circuit-json';
2
- import { AnyCircuitElementInput, AnyCircuitElement, InsertionDirection, PcbBoard, SchematicComponent, SchematicNetLabel, SchematicTrace, SourceGroup, SourceComponentBase, PcbRenderLayer } from 'circuit-json';
2
+ import { AnyCircuitElementInput, AnyCircuitElement, InsertionDirection, PcbBoard, SchematicComponent, SchematicNetLabel, SchematicTrace, SourceGroup, SourceComponentBase, PcbRenderLayer, PcbPin1Location } from 'circuit-json';
3
3
  import * as zod from 'zod';
4
4
  import { Matrix } from 'transformation-matrix';
5
5
  import * as parsel from 'parsel-js';
@@ -1140,6 +1140,8 @@ declare const transformSchematicElement: (elm: AnyCircuitElement, matrix: Matrix
1140
1140
  y: number;
1141
1141
  } | undefined;
1142
1142
  insertion_direction?: "from_left" | "from_right" | "from_top" | "from_bottom" | "from_above" | "from_below" | undefined;
1143
+ pin1_location?: "leftside_top" | "leftside_bottom" | "rightside_top" | "rightside_bottom" | "topside_left" | "topside_right" | "bottomside_left" | "bottomside_right" | undefined;
1144
+ supplier_pin1_location_map?: Partial<Record<"jlcpcb" | "macrofab" | "pcbway" | "digikey" | "mouser" | "lcsc", "leftside_top" | "leftside_bottom" | "rightside_top" | "rightside_bottom" | "topside_left" | "topside_right" | "bottomside_left" | "bottomside_right">> | undefined;
1143
1145
  metadata?: {
1144
1146
  kicad_footprint?: {
1145
1147
  layer?: string | undefined;
@@ -1713,6 +1715,7 @@ declare const transformSchematicElement: (elm: AnyCircuitElement, matrix: Matrix
1713
1715
  soldermask_margin?: number | undefined;
1714
1716
  port_hints?: string[] | undefined;
1715
1717
  pcb_port_id?: string | undefined;
1718
+ solderpaste_margin?: number | undefined;
1716
1719
  } | {
1717
1720
  type: "pcb_smtpad";
1718
1721
  x: number;
@@ -1730,6 +1733,7 @@ declare const transformSchematicElement: (elm: AnyCircuitElement, matrix: Matrix
1730
1733
  port_hints?: string[] | undefined;
1731
1734
  pcb_port_id?: string | undefined;
1732
1735
  rect_border_radius?: number | undefined;
1736
+ solderpaste_margin?: number | undefined;
1733
1737
  corner_radius?: number | undefined;
1734
1738
  soldermask_margin_left?: number | undefined;
1735
1739
  soldermask_margin_top?: number | undefined;
@@ -1753,6 +1757,7 @@ declare const transformSchematicElement: (elm: AnyCircuitElement, matrix: Matrix
1753
1757
  port_hints?: string[] | undefined;
1754
1758
  pcb_port_id?: string | undefined;
1755
1759
  rect_border_radius?: number | undefined;
1760
+ solderpaste_margin?: number | undefined;
1756
1761
  corner_radius?: number | undefined;
1757
1762
  soldermask_margin_left?: number | undefined;
1758
1763
  soldermask_margin_top?: number | undefined;
@@ -1776,6 +1781,7 @@ declare const transformSchematicElement: (elm: AnyCircuitElement, matrix: Matrix
1776
1781
  soldermask_margin?: number | undefined;
1777
1782
  port_hints?: string[] | undefined;
1778
1783
  pcb_port_id?: string | undefined;
1784
+ solderpaste_margin?: number | undefined;
1779
1785
  } | {
1780
1786
  type: "pcb_smtpad";
1781
1787
  x: number;
@@ -1793,6 +1799,7 @@ declare const transformSchematicElement: (elm: AnyCircuitElement, matrix: Matrix
1793
1799
  soldermask_margin?: number | undefined;
1794
1800
  port_hints?: string[] | undefined;
1795
1801
  pcb_port_id?: string | undefined;
1802
+ solderpaste_margin?: number | undefined;
1796
1803
  } | {
1797
1804
  type: "pcb_smtpad";
1798
1805
  layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
@@ -1809,6 +1816,7 @@ declare const transformSchematicElement: (elm: AnyCircuitElement, matrix: Matrix
1809
1816
  soldermask_margin?: number | undefined;
1810
1817
  port_hints?: string[] | undefined;
1811
1818
  pcb_port_id?: string | undefined;
1819
+ solderpaste_margin?: number | undefined;
1812
1820
  } | {
1813
1821
  type: "pcb_solder_paste";
1814
1822
  x: number;
@@ -1927,6 +1935,7 @@ declare const transformSchematicElement: (elm: AnyCircuitElement, matrix: Matrix
1927
1935
  carrier_pcb_board_id?: string | undefined;
1928
1936
  is_subcircuit?: boolean | undefined;
1929
1937
  is_mounted_to_carrier_board?: boolean | undefined;
1938
+ is_via_in_pad_allowed?: boolean | undefined;
1930
1939
  outline?: {
1931
1940
  x: number;
1932
1941
  y: number;
@@ -5923,6 +5932,8 @@ declare const transformSchematicElements: (elms: AnyCircuitElement[], matrix: Ma
5923
5932
  y: number;
5924
5933
  } | undefined;
5925
5934
  insertion_direction?: "from_left" | "from_right" | "from_top" | "from_bottom" | "from_above" | "from_below" | undefined;
5935
+ pin1_location?: "leftside_top" | "leftside_bottom" | "rightside_top" | "rightside_bottom" | "topside_left" | "topside_right" | "bottomside_left" | "bottomside_right" | undefined;
5936
+ supplier_pin1_location_map?: Partial<Record<"jlcpcb" | "macrofab" | "pcbway" | "digikey" | "mouser" | "lcsc", "leftside_top" | "leftside_bottom" | "rightside_top" | "rightside_bottom" | "topside_left" | "topside_right" | "bottomside_left" | "bottomside_right">> | undefined;
5926
5937
  metadata?: {
5927
5938
  kicad_footprint?: {
5928
5939
  layer?: string | undefined;
@@ -6496,6 +6507,7 @@ declare const transformSchematicElements: (elms: AnyCircuitElement[], matrix: Ma
6496
6507
  soldermask_margin?: number | undefined;
6497
6508
  port_hints?: string[] | undefined;
6498
6509
  pcb_port_id?: string | undefined;
6510
+ solderpaste_margin?: number | undefined;
6499
6511
  } | {
6500
6512
  type: "pcb_smtpad";
6501
6513
  x: number;
@@ -6513,6 +6525,7 @@ declare const transformSchematicElements: (elms: AnyCircuitElement[], matrix: Ma
6513
6525
  port_hints?: string[] | undefined;
6514
6526
  pcb_port_id?: string | undefined;
6515
6527
  rect_border_radius?: number | undefined;
6528
+ solderpaste_margin?: number | undefined;
6516
6529
  corner_radius?: number | undefined;
6517
6530
  soldermask_margin_left?: number | undefined;
6518
6531
  soldermask_margin_top?: number | undefined;
@@ -6536,6 +6549,7 @@ declare const transformSchematicElements: (elms: AnyCircuitElement[], matrix: Ma
6536
6549
  port_hints?: string[] | undefined;
6537
6550
  pcb_port_id?: string | undefined;
6538
6551
  rect_border_radius?: number | undefined;
6552
+ solderpaste_margin?: number | undefined;
6539
6553
  corner_radius?: number | undefined;
6540
6554
  soldermask_margin_left?: number | undefined;
6541
6555
  soldermask_margin_top?: number | undefined;
@@ -6559,6 +6573,7 @@ declare const transformSchematicElements: (elms: AnyCircuitElement[], matrix: Ma
6559
6573
  soldermask_margin?: number | undefined;
6560
6574
  port_hints?: string[] | undefined;
6561
6575
  pcb_port_id?: string | undefined;
6576
+ solderpaste_margin?: number | undefined;
6562
6577
  } | {
6563
6578
  type: "pcb_smtpad";
6564
6579
  x: number;
@@ -6576,6 +6591,7 @@ declare const transformSchematicElements: (elms: AnyCircuitElement[], matrix: Ma
6576
6591
  soldermask_margin?: number | undefined;
6577
6592
  port_hints?: string[] | undefined;
6578
6593
  pcb_port_id?: string | undefined;
6594
+ solderpaste_margin?: number | undefined;
6579
6595
  } | {
6580
6596
  type: "pcb_smtpad";
6581
6597
  layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
@@ -6592,6 +6608,7 @@ declare const transformSchematicElements: (elms: AnyCircuitElement[], matrix: Ma
6592
6608
  soldermask_margin?: number | undefined;
6593
6609
  port_hints?: string[] | undefined;
6594
6610
  pcb_port_id?: string | undefined;
6611
+ solderpaste_margin?: number | undefined;
6595
6612
  } | {
6596
6613
  type: "pcb_solder_paste";
6597
6614
  x: number;
@@ -6710,6 +6727,7 @@ declare const transformSchematicElements: (elms: AnyCircuitElement[], matrix: Ma
6710
6727
  carrier_pcb_board_id?: string | undefined;
6711
6728
  is_subcircuit?: boolean | undefined;
6712
6729
  is_mounted_to_carrier_board?: boolean | undefined;
6730
+ is_via_in_pad_allowed?: boolean | undefined;
6713
6731
  outline?: {
6714
6732
  x: number;
6715
6733
  y: number;
@@ -10706,6 +10724,8 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
10706
10724
  y: number;
10707
10725
  } | undefined;
10708
10726
  insertion_direction?: "from_left" | "from_right" | "from_top" | "from_bottom" | "from_above" | "from_below" | undefined;
10727
+ pin1_location?: "leftside_top" | "leftside_bottom" | "rightside_top" | "rightside_bottom" | "topside_left" | "topside_right" | "bottomside_left" | "bottomside_right" | undefined;
10728
+ supplier_pin1_location_map?: Partial<Record<"jlcpcb" | "macrofab" | "pcbway" | "digikey" | "mouser" | "lcsc", "leftside_top" | "leftside_bottom" | "rightside_top" | "rightside_bottom" | "topside_left" | "topside_right" | "bottomside_left" | "bottomside_right">> | undefined;
10709
10729
  metadata?: {
10710
10730
  kicad_footprint?: {
10711
10731
  layer?: string | undefined;
@@ -11279,6 +11299,7 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
11279
11299
  soldermask_margin?: number | undefined;
11280
11300
  port_hints?: string[] | undefined;
11281
11301
  pcb_port_id?: string | undefined;
11302
+ solderpaste_margin?: number | undefined;
11282
11303
  } | {
11283
11304
  type: "pcb_smtpad";
11284
11305
  x: number;
@@ -11296,6 +11317,7 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
11296
11317
  port_hints?: string[] | undefined;
11297
11318
  pcb_port_id?: string | undefined;
11298
11319
  rect_border_radius?: number | undefined;
11320
+ solderpaste_margin?: number | undefined;
11299
11321
  corner_radius?: number | undefined;
11300
11322
  soldermask_margin_left?: number | undefined;
11301
11323
  soldermask_margin_top?: number | undefined;
@@ -11319,6 +11341,7 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
11319
11341
  port_hints?: string[] | undefined;
11320
11342
  pcb_port_id?: string | undefined;
11321
11343
  rect_border_radius?: number | undefined;
11344
+ solderpaste_margin?: number | undefined;
11322
11345
  corner_radius?: number | undefined;
11323
11346
  soldermask_margin_left?: number | undefined;
11324
11347
  soldermask_margin_top?: number | undefined;
@@ -11342,6 +11365,7 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
11342
11365
  soldermask_margin?: number | undefined;
11343
11366
  port_hints?: string[] | undefined;
11344
11367
  pcb_port_id?: string | undefined;
11368
+ solderpaste_margin?: number | undefined;
11345
11369
  } | {
11346
11370
  type: "pcb_smtpad";
11347
11371
  x: number;
@@ -11359,6 +11383,7 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
11359
11383
  soldermask_margin?: number | undefined;
11360
11384
  port_hints?: string[] | undefined;
11361
11385
  pcb_port_id?: string | undefined;
11386
+ solderpaste_margin?: number | undefined;
11362
11387
  } | {
11363
11388
  type: "pcb_smtpad";
11364
11389
  layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
@@ -11375,6 +11400,7 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
11375
11400
  soldermask_margin?: number | undefined;
11376
11401
  port_hints?: string[] | undefined;
11377
11402
  pcb_port_id?: string | undefined;
11403
+ solderpaste_margin?: number | undefined;
11378
11404
  } | {
11379
11405
  type: "pcb_solder_paste";
11380
11406
  x: number;
@@ -11493,6 +11519,7 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
11493
11519
  carrier_pcb_board_id?: string | undefined;
11494
11520
  is_subcircuit?: boolean | undefined;
11495
11521
  is_mounted_to_carrier_board?: boolean | undefined;
11522
+ is_via_in_pad_allowed?: boolean | undefined;
11496
11523
  outline?: {
11497
11524
  x: number;
11498
11525
  y: number;
@@ -15489,6 +15516,8 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
15489
15516
  y: number;
15490
15517
  } | undefined;
15491
15518
  insertion_direction?: "from_left" | "from_right" | "from_top" | "from_bottom" | "from_above" | "from_below" | undefined;
15519
+ pin1_location?: "leftside_top" | "leftside_bottom" | "rightside_top" | "rightside_bottom" | "topside_left" | "topside_right" | "bottomside_left" | "bottomside_right" | undefined;
15520
+ supplier_pin1_location_map?: Partial<Record<"jlcpcb" | "macrofab" | "pcbway" | "digikey" | "mouser" | "lcsc", "leftside_top" | "leftside_bottom" | "rightside_top" | "rightside_bottom" | "topside_left" | "topside_right" | "bottomside_left" | "bottomside_right">> | undefined;
15492
15521
  metadata?: {
15493
15522
  kicad_footprint?: {
15494
15523
  layer?: string | undefined;
@@ -16062,6 +16091,7 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
16062
16091
  soldermask_margin?: number | undefined;
16063
16092
  port_hints?: string[] | undefined;
16064
16093
  pcb_port_id?: string | undefined;
16094
+ solderpaste_margin?: number | undefined;
16065
16095
  } | {
16066
16096
  type: "pcb_smtpad";
16067
16097
  x: number;
@@ -16079,6 +16109,7 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
16079
16109
  port_hints?: string[] | undefined;
16080
16110
  pcb_port_id?: string | undefined;
16081
16111
  rect_border_radius?: number | undefined;
16112
+ solderpaste_margin?: number | undefined;
16082
16113
  corner_radius?: number | undefined;
16083
16114
  soldermask_margin_left?: number | undefined;
16084
16115
  soldermask_margin_top?: number | undefined;
@@ -16102,6 +16133,7 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
16102
16133
  port_hints?: string[] | undefined;
16103
16134
  pcb_port_id?: string | undefined;
16104
16135
  rect_border_radius?: number | undefined;
16136
+ solderpaste_margin?: number | undefined;
16105
16137
  corner_radius?: number | undefined;
16106
16138
  soldermask_margin_left?: number | undefined;
16107
16139
  soldermask_margin_top?: number | undefined;
@@ -16125,6 +16157,7 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
16125
16157
  soldermask_margin?: number | undefined;
16126
16158
  port_hints?: string[] | undefined;
16127
16159
  pcb_port_id?: string | undefined;
16160
+ solderpaste_margin?: number | undefined;
16128
16161
  } | {
16129
16162
  type: "pcb_smtpad";
16130
16163
  x: number;
@@ -16142,6 +16175,7 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
16142
16175
  soldermask_margin?: number | undefined;
16143
16176
  port_hints?: string[] | undefined;
16144
16177
  pcb_port_id?: string | undefined;
16178
+ solderpaste_margin?: number | undefined;
16145
16179
  } | {
16146
16180
  type: "pcb_smtpad";
16147
16181
  layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
@@ -16158,6 +16192,7 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
16158
16192
  soldermask_margin?: number | undefined;
16159
16193
  port_hints?: string[] | undefined;
16160
16194
  pcb_port_id?: string | undefined;
16195
+ solderpaste_margin?: number | undefined;
16161
16196
  } | {
16162
16197
  type: "pcb_solder_paste";
16163
16198
  x: number;
@@ -16276,6 +16311,7 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
16276
16311
  carrier_pcb_board_id?: string | undefined;
16277
16312
  is_subcircuit?: boolean | undefined;
16278
16313
  is_mounted_to_carrier_board?: boolean | undefined;
16314
+ is_via_in_pad_allowed?: boolean | undefined;
16279
16315
  outline?: {
16280
16316
  x: number;
16281
16317
  y: number;
@@ -19373,7 +19409,7 @@ declare const computeGapBetweenCopper: (elm1: AnyCircuitElement, elm2: AnyCircui
19373
19409
 
19374
19410
  declare const computeClearanceBetweenElements: (elm1: AnyCircuitElement, elm2: AnyCircuitElement) => number;
19375
19411
 
19376
- type Point = {
19412
+ type Point$1 = {
19377
19413
  x: number;
19378
19414
  y: number;
19379
19415
  };
@@ -19393,7 +19429,7 @@ type Rect = {
19393
19429
  };
19394
19430
  type Polygon = {
19395
19431
  kind: "polygon";
19396
- points: Point[];
19432
+ points: Point$1[];
19397
19433
  };
19398
19434
  type CopperShape = Circle | Rect | Polygon;
19399
19435
 
@@ -19402,6 +19438,24 @@ declare const distanceBetweenPolygonAndPolygon: (a: Polygon, b: Polygon) => numb
19402
19438
  declare const distanceBetweenCircleAndPolygon: (circle: Circle, polygon: Polygon) => number;
19403
19439
  declare const distanceBetweenShapes: (a: CopperShape, b: CopperShape) => number;
19404
19440
 
19441
+ type Point = {
19442
+ x: number;
19443
+ y: number;
19444
+ };
19445
+ interface PcbPin1LocationElement {
19446
+ type: string;
19447
+ x?: number;
19448
+ y?: number;
19449
+ points?: readonly Point[];
19450
+ port_hints?: readonly unknown[];
19451
+ }
19452
+ /**
19453
+ * Infers the semantic pin 1 location from PCB pad positions and numeric port
19454
+ * hints. Returns null when pin 1 is missing or the geometry cannot distinguish
19455
+ * a rotation from a reflection.
19456
+ */
19457
+ declare const analyzePcbPin1Location: (elements: readonly PcbPin1LocationElement[]) => PcbPin1Location | null;
19458
+
19405
19459
  type DrcCategory = "netlist" | "pin_specification" | "placement" | "routing" | "unknown";
19406
19460
  type DrcLike = {
19407
19461
  type?: string;
@@ -19410,4 +19464,4 @@ type DrcLike = {
19410
19464
  };
19411
19465
  declare const categorizeErrorOrWarning: (value: string | DrcLike) => DrcCategory;
19412
19466
 
19413
- export { type BoardBounds, type CircuitJsonInputUtilObjects, type CircuitJsonOps, type CircuitJsonTreeNode, type CircuitJsonUtilObjects, type CircuitJsonUtilOptions, type DrcCategory, type GetCircuitJsonUtilFn, type GetIndexedCircuitJsonUtilFn, type IndexedCircuitJsonUtilOptions, type SchematicElementBounds, type SchematicElementWithBounds, type Size, type SubtreeOptions, applySelector, applySelectorAST, buildSubtree, categorizeErrorOrWarning, cju, cjuIndexed, computeClearanceBetweenElements, computeGapBetweenCopper, directionToVec, distanceBetweenCircleAndCircle, distanceBetweenCircleAndPolygon, distanceBetweenPolygonAndPolygon, distanceBetweenShapes, findBoundsAndCenter, getBoardBounds, getBoundsOfPcbElements, getCircuitJsonTree, getElementById, getElementId, getElementRenderLayers, getMinimumFlexContainer, getPrimaryId, getReadableNameForElement, getReadableNameForPcbPort, getReadableNameForPcbSmtpad, getReadableNameForPcbTrace, getSchematicElementBounds, getStringFromCircuitJsonTree, oppositeDirection, oppositeSide, repositionPcbComponentTo, repositionPcbGroupTo, repositionSchematicComponentTo, repositionSchematicGroupTo, rotateClockwise, rotateCounterClockwise, rotateDirection, su, transformInsertionDirection, transformPCBElement, transformPCBElements, transformPCBElement as transformPcbElement, transformPCBElements as transformPcbElements, transformSchematicElement, transformSchematicElements, vecToDirection };
19467
+ export { type BoardBounds, type CircuitJsonInputUtilObjects, type CircuitJsonOps, type CircuitJsonTreeNode, type CircuitJsonUtilObjects, type CircuitJsonUtilOptions, type DrcCategory, type GetCircuitJsonUtilFn, type GetIndexedCircuitJsonUtilFn, type IndexedCircuitJsonUtilOptions, type PcbPin1LocationElement, type SchematicElementBounds, type SchematicElementWithBounds, type Size, type SubtreeOptions, analyzePcbPin1Location, applySelector, applySelectorAST, buildSubtree, categorizeErrorOrWarning, cju, cjuIndexed, computeClearanceBetweenElements, computeGapBetweenCopper, directionToVec, distanceBetweenCircleAndCircle, distanceBetweenCircleAndPolygon, distanceBetweenPolygonAndPolygon, distanceBetweenShapes, findBoundsAndCenter, getBoardBounds, getBoundsOfPcbElements, getCircuitJsonTree, getElementById, getElementId, getElementRenderLayers, getMinimumFlexContainer, getPrimaryId, getReadableNameForElement, getReadableNameForPcbPort, getReadableNameForPcbSmtpad, getReadableNameForPcbTrace, getSchematicElementBounds, getStringFromCircuitJsonTree, oppositeDirection, oppositeSide, repositionPcbComponentTo, repositionPcbGroupTo, repositionSchematicComponentTo, repositionSchematicGroupTo, rotateClockwise, rotateCounterClockwise, rotateDirection, su, transformInsertionDirection, transformPCBElement, transformPCBElements, transformPCBElement as transformPcbElement, transformPCBElements as transformPcbElements, transformSchematicElement, transformSchematicElements, vecToDirection };
package/dist/index.js CHANGED
@@ -2586,6 +2586,95 @@ var computeClearanceBetweenElements = (elm1, elm2) => {
2586
2586
  return minimumGap;
2587
2587
  };
2588
2588
 
2589
+ // lib/analyze-pcb-pin1-location.ts
2590
+ var PIN1_LOCATION_PARTS = {
2591
+ leftside_top: { side: "leftside", alignment: "top" },
2592
+ leftside_bottom: { side: "leftside", alignment: "bottom" },
2593
+ rightside_top: { side: "rightside", alignment: "top" },
2594
+ rightside_bottom: { side: "rightside", alignment: "bottom" },
2595
+ topside_left: { side: "topside", alignment: "left" },
2596
+ topside_right: { side: "topside", alignment: "right" },
2597
+ bottomside_left: { side: "bottomside", alignment: "left" },
2598
+ bottomside_right: { side: "bottomside", alignment: "right" }
2599
+ };
2600
+ var PIN1_LOCATIONS = Object.keys(PIN1_LOCATION_PARTS);
2601
+ var getPadCenter = (pad) => {
2602
+ if (typeof pad.x === "number" && typeof pad.y === "number") {
2603
+ return { x: pad.x, y: pad.y };
2604
+ }
2605
+ if (pad.points && pad.points.length > 0) {
2606
+ const xs = pad.points.map((point) => point.x);
2607
+ const ys = pad.points.map((point) => point.y);
2608
+ return {
2609
+ x: (Math.min(...xs) + Math.max(...xs)) / 2,
2610
+ y: (Math.min(...ys) + Math.max(...ys)) / 2
2611
+ };
2612
+ }
2613
+ return null;
2614
+ };
2615
+ var getPinNumber = (pad) => {
2616
+ for (const hint of pad.port_hints ?? []) {
2617
+ const match = String(hint).trim().match(/^(?:pin)?(\d+)$/i);
2618
+ if (match) return Number.parseInt(match[1], 10);
2619
+ }
2620
+ return null;
2621
+ };
2622
+ var pinMatchesLocation = (padCenters, pin1Center, pin1Location) => {
2623
+ const xs = padCenters.map((point) => point.x);
2624
+ const ys = padCenters.map((point) => point.y);
2625
+ const minX = Math.min(...xs);
2626
+ const maxX = Math.max(...xs);
2627
+ const minY = Math.min(...ys);
2628
+ const maxY = Math.max(...ys);
2629
+ const centerX = (minX + maxX) / 2;
2630
+ const centerY = (minY + maxY) / 2;
2631
+ const spanX = maxX - minX;
2632
+ const spanY = maxY - minY;
2633
+ const tolerance = Math.max(spanX, spanY, 1) * 1e-6;
2634
+ const { side, alignment } = PIN1_LOCATION_PARTS[pin1Location];
2635
+ const onRequestedSide = side === "leftside" && Math.abs(pin1Center.x - minX) <= tolerance || side === "rightside" && Math.abs(pin1Center.x - maxX) <= tolerance || side === "topside" && Math.abs(pin1Center.y - maxY) <= tolerance || side === "bottomside" && Math.abs(pin1Center.y - minY) <= tolerance;
2636
+ const atRequestedAlignment = alignment === "left" && (spanX <= tolerance || pin1Center.x < centerX - tolerance) || alignment === "right" && (spanX <= tolerance || pin1Center.x > centerX + tolerance) || alignment === "top" && (spanY <= tolerance || pin1Center.y > centerY + tolerance) || alignment === "bottom" && (spanY <= tolerance || pin1Center.y < centerY - tolerance);
2637
+ return onRequestedSide && atRequestedAlignment;
2638
+ };
2639
+ var analyzePcbPin1Location = (elements) => {
2640
+ const pads = elements.filter(
2641
+ (element) => element.type === "pcb_smtpad" || element.type === "pcb_plated_hole"
2642
+ );
2643
+ const numberedPads = pads.map((pad) => ({
2644
+ center: getPadCenter(pad),
2645
+ pinNumber: getPinNumber(pad)
2646
+ }));
2647
+ const pin1Center = numberedPads.find((pad) => pad.pinNumber === 1)?.center;
2648
+ const padCenters = numberedPads.map((pad) => pad.center).filter((point) => point !== null);
2649
+ if (!pin1Center || padCenters.length === 0) return null;
2650
+ const candidates = PIN1_LOCATIONS.filter(
2651
+ (pin1Location) => pinMatchesLocation(padCenters, pin1Center, pin1Location)
2652
+ );
2653
+ if (candidates.length === 1) return candidates[0];
2654
+ if (candidates.length === 0) return null;
2655
+ let nextNumberedPad;
2656
+ for (const pad of numberedPads) {
2657
+ if (!pad.center || pad.pinNumber === null || pad.pinNumber <= 1) continue;
2658
+ if (!nextNumberedPad || pad.pinNumber < nextNumberedPad.pinNumber) {
2659
+ nextNumberedPad = { center: pad.center, pinNumber: pad.pinNumber };
2660
+ }
2661
+ }
2662
+ if (!nextNumberedPad) return null;
2663
+ const xs = padCenters.map((point) => point.x);
2664
+ const ys = padCenters.map((point) => point.y);
2665
+ const span = Math.max(
2666
+ Math.max(...xs) - Math.min(...xs),
2667
+ Math.max(...ys) - Math.min(...ys),
2668
+ 1
2669
+ );
2670
+ const tolerance = span * 1e-6;
2671
+ const topologyCandidates = candidates.filter((pin1Location) => {
2672
+ const { side } = PIN1_LOCATION_PARTS[pin1Location];
2673
+ return side === "leftside" || side === "rightside" ? Math.abs(nextNumberedPad.center.x - pin1Center.x) <= tolerance : Math.abs(nextNumberedPad.center.y - pin1Center.y) <= tolerance;
2674
+ });
2675
+ return topologyCandidates.length === 1 ? topologyCandidates[0] : null;
2676
+ };
2677
+
2589
2678
  // lib/categorize-error-or-warning.ts
2590
2679
  var NETLIST_TYPES = /* @__PURE__ */ new Set(["source_pin_must_be_connected_error"]);
2591
2680
  var PIN_SPECIFICATION_TYPES = /* @__PURE__ */ new Set([
@@ -2616,6 +2705,7 @@ var categorizeErrorOrWarning = (value) => {
2616
2705
  return "unknown";
2617
2706
  };
2618
2707
  export {
2708
+ analyzePcbPin1Location,
2619
2709
  applySelector,
2620
2710
  applySelectorAST,
2621
2711
  buildSubtree,