@tscircuit/core 0.0.40 → 0.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -41,7 +41,7 @@ declare class Circuit {
41
41
  */
42
42
  declare const Project: typeof Circuit;
43
43
 
44
- declare const orderedRenderPhases: readonly ["ReactSubtreesRender", "InitializePortsFromChildren", "CreateNetsFromProps", "CreateTracesFromProps", "SourceRender", "SourceParentAttachment", "PortDiscovery", "PortMatching", "SourceTraceRender", "SchematicComponentRender", "SchematicLayout", "SchematicPortRender", "SchematicTraceRender", "PcbComponentRender", "PcbPrimitiveRender", "PcbFootprintLayout", "PcbPortRender", "PcbParentAttachment", "PcbLayout", "PcbTraceRender", "PcbRouteNetIslands", "PcbComponentSizeCalculation", "CadModelRender"];
44
+ declare const orderedRenderPhases: readonly ["ReactSubtreesRender", "InitializePortsFromChildren", "CreateNetsFromProps", "CreateTracesFromProps", "SourceRender", "SourceParentAttachment", "PortDiscovery", "PortMatching", "SourceTraceRender", "SchematicComponentRender", "SchematicLayout", "SchematicPortRender", "SchematicTraceRender", "PcbComponentRender", "PcbPrimitiveRender", "PcbFootprintLayout", "PcbPortRender", "PcbPortAttachment", "PcbLayout", "PcbTraceRender", "PcbRouteNetIslands", "PcbComponentSizeCalculation", "CadModelRender"];
45
45
  type RenderPhase = (typeof orderedRenderPhases)[number];
46
46
  type RenderPhaseFn<K extends RenderPhase = RenderPhase> = `doInitial${K}` | `update${K}` | `remove${K}`;
47
47
  type RenderPhaseStates = Record<RenderPhase, {
@@ -141,10 +141,10 @@ declare abstract class PrimitiveComponent<ZodProps extends ZodType = any> extend
141
141
  _computePcbGlobalTransformBeforeLayout(): Matrix;
142
142
  getPrimitiveContainer(): PrimitiveComponent | null;
143
143
  /**
144
- * Compute the bounds of this component the circuit json elements associated
145
- * with it.
144
+ * Compute the PCB bounds of this component the circuit json elements
145
+ * associated with it.
146
146
  */
147
- _getCircuitJsonBounds(): {
147
+ _getPcbCircuitJsonBounds(): {
148
148
  center: {
149
149
  x: number;
150
150
  y: number;
@@ -161,7 +161,7 @@ declare abstract class PrimitiveComponent<ZodProps extends ZodType = any> extend
161
161
  /**
162
162
  * Set the position of this component from the layout solver. This method
163
163
  * should operate using CircuitJson associated with this component, like
164
- * _getCircuitJsonBounds it can be called multiple times as different
164
+ * _getPcbCircuitJsonBounds it can be called multiple times as different
165
165
  * parents apply layout to their children.
166
166
  */
167
167
  _setPositionFromLayout(newCenter: {
@@ -512,6 +512,24 @@ declare class Port extends PrimitiveComponent<typeof portProps> {
512
512
  x: number;
513
513
  y: number;
514
514
  };
515
+ _getPcbCircuitJsonBounds(): {
516
+ center: {
517
+ x: number;
518
+ y: number;
519
+ };
520
+ bounds: {
521
+ left: number;
522
+ top: number;
523
+ right: number;
524
+ bottom: number;
525
+ };
526
+ width: number;
527
+ height: number;
528
+ };
529
+ _getGlobalPcbPositionAfterLayout(): {
530
+ x: number;
531
+ y: number;
532
+ };
515
533
  _getGlobalSchematicPositionBeforeLayout(): {
516
534
  x: number;
517
535
  y: number;
@@ -770,7 +788,8 @@ declare class SmtPad extends PrimitiveComponent<typeof smtPadProps> {
770
788
  };
771
789
  doInitialPortMatching(): void;
772
790
  doInitialPcbPrimitiveRender(): void;
773
- _getCircuitJsonBounds(): {
791
+ doInitialPcbPortAttachment(): void;
792
+ _getPcbCircuitJsonBounds(): {
774
793
  center: {
775
794
  x: number;
776
795
  y: number;
@@ -3819,7 +3838,7 @@ declare class PlatedHole extends PrimitiveComponent<typeof platedHoleProps> {
3819
3838
  width: number;
3820
3839
  height: number;
3821
3840
  };
3822
- _getCircuitJsonBounds(): {
3841
+ _getPcbCircuitJsonBounds(): {
3823
3842
  center: {
3824
3843
  x: number;
3825
3844
  y: number;
@@ -3839,6 +3858,7 @@ declare class PlatedHole extends PrimitiveComponent<typeof platedHoleProps> {
3839
3858
  }): void;
3840
3859
  doInitialPortMatching(): void;
3841
3860
  doInitialPcbPrimitiveRender(): void;
3861
+ doInitialPcbPortAttachment(): void;
3842
3862
  }
3843
3863
 
3844
3864
  declare const edgeSpecifiers: readonly ["leftedge", "rightedge", "topedge", "bottomedge", "center"];
@@ -3985,7 +4005,7 @@ declare class Hole extends PrimitiveComponent<typeof holeProps> {
3985
4005
  height: number;
3986
4006
  };
3987
4007
  doInitialPcbPrimitiveRender(): void;
3988
- _getCircuitJsonBounds(): {
4008
+ _getPcbCircuitJsonBounds(): {
3989
4009
  center: {
3990
4010
  x: number;
3991
4011
  y: number;
package/dist/index.js CHANGED
@@ -56,7 +56,7 @@ var orderedRenderPhases = [
56
56
  "PcbPrimitiveRender",
57
57
  "PcbFootprintLayout",
58
58
  "PcbPortRender",
59
- "PcbParentAttachment",
59
+ "PcbPortAttachment",
60
60
  "PcbLayout",
61
61
  "PcbTraceRender",
62
62
  "PcbRouteNetIslands",
@@ -274,10 +274,10 @@ var PrimitiveComponent = class extends Renderable {
274
274
  return this.parent?.getPrimitiveContainer?.() ?? null;
275
275
  }
276
276
  /**
277
- * Compute the bounds of this component the circuit json elements associated
278
- * with it.
277
+ * Compute the PCB bounds of this component the circuit json elements
278
+ * associated with it.
279
279
  */
280
- _getCircuitJsonBounds() {
280
+ _getPcbCircuitJsonBounds() {
281
281
  return {
282
282
  center: { x: 0, y: 0 },
283
283
  bounds: { left: 0, top: 0, right: 0, bottom: 0 },
@@ -288,7 +288,7 @@ var PrimitiveComponent = class extends Renderable {
288
288
  /**
289
289
  * Set the position of this component from the layout solver. This method
290
290
  * should operate using CircuitJson associated with this component, like
291
- * _getCircuitJsonBounds it can be called multiple times as different
291
+ * _getPcbCircuitJsonBounds it can be called multiple times as different
292
292
  * parents apply layout to their children.
293
293
  */
294
294
  _setPositionFromLayout(newCenter) {
@@ -529,7 +529,7 @@ var Footprint = class extends PrimitiveComponent {
529
529
  selector,
530
530
  componentSelector,
531
531
  edge,
532
- bounds: component._getCircuitJsonBounds()
532
+ bounds: component._getPcbCircuitJsonBounds()
533
533
  }));
534
534
  if (involvedComponents.some((c) => c.edge)) {
535
535
  throw new Error(
@@ -745,6 +745,22 @@ var Port = class extends PrimitiveComponent {
745
745
  }
746
746
  return matchedPcbElm?._getGlobalPcbPositionBeforeLayout() ?? { x: 0, y: 0 };
747
747
  }
748
+ _getPcbCircuitJsonBounds() {
749
+ if (!this.pcb_port_id) {
750
+ return super._getPcbCircuitJsonBounds();
751
+ }
752
+ const { db } = this.root;
753
+ const pcb_port = db.pcb_port.get(this.pcb_port_id);
754
+ return {
755
+ center: { x: pcb_port.x, y: pcb_port.y },
756
+ bounds: { left: 0, top: 0, right: 0, bottom: 0 },
757
+ width: 0,
758
+ height: 0
759
+ };
760
+ }
761
+ _getGlobalPcbPositionAfterLayout() {
762
+ return this._getPcbCircuitJsonBounds().center;
763
+ }
748
764
  _getGlobalSchematicPositionBeforeLayout() {
749
765
  if (!this.schematicSymbolPortDef) {
750
766
  return applyToPoint2(this.parent.computeSchematicGlobalTransform(), {
@@ -845,11 +861,11 @@ var Port = class extends PrimitiveComponent {
845
861
  );
846
862
  }
847
863
  const pcbMatch = pcbMatches[0];
848
- if ("_getCircuitJsonBounds" in pcbMatch) {
864
+ if ("_getPcbCircuitJsonBounds" in pcbMatch) {
849
865
  const pcb_port = db.pcb_port.insert({
850
866
  pcb_component_id: this.parent?.pcb_component_id,
851
867
  layers: ["top"],
852
- ...pcbMatch._getCircuitJsonBounds().center,
868
+ ...pcbMatch._getPcbCircuitJsonBounds().center,
853
869
  source_port_id: this.source_port_id
854
870
  });
855
871
  this.pcb_port_id = pcb_port.pcb_port_id;
@@ -1112,6 +1128,7 @@ var SmtPad = class extends PrimitiveComponent {
1112
1128
  pcb_smtpad = db.pcb_smtpad.insert({
1113
1129
  pcb_component_id: this.parent?.pcb_component_id,
1114
1130
  pcb_port_id: this.matchedPort?.pcb_port_id,
1131
+ // port likely isn't matched
1115
1132
  layer: props.layer ?? "top",
1116
1133
  shape: "circle",
1117
1134
  // @ts-ignore: no idea why this is triggering
@@ -1124,6 +1141,7 @@ var SmtPad = class extends PrimitiveComponent {
1124
1141
  pcb_smtpad = db.pcb_smtpad.insert({
1125
1142
  pcb_component_id: this.parent?.pcb_component_id,
1126
1143
  pcb_port_id: this.matchedPort?.pcb_port_id,
1144
+ // port likely isn't matched
1127
1145
  layer: props.layer ?? "top",
1128
1146
  shape: "rect",
1129
1147
  ...isRotated90 ? { width: props.height, height: props.width } : { width: props.width, height: props.height },
@@ -1136,7 +1154,13 @@ var SmtPad = class extends PrimitiveComponent {
1136
1154
  this.pcb_smtpad_id = pcb_smtpad.pcb_smtpad_id;
1137
1155
  }
1138
1156
  }
1139
- _getCircuitJsonBounds() {
1157
+ doInitialPcbPortAttachment() {
1158
+ const { db } = this.root;
1159
+ db.pcb_smtpad.update(this.pcb_smtpad_id, {
1160
+ pcb_port_id: this.matchedPort?.pcb_port_id
1161
+ });
1162
+ }
1163
+ _getPcbCircuitJsonBounds() {
1140
1164
  const { db } = this.root;
1141
1165
  const smtpad = db.pcb_smtpad.get(this.pcb_smtpad_id);
1142
1166
  if (smtpad.shape === "rect") {
@@ -1242,7 +1266,7 @@ var PlatedHole = class extends PrimitiveComponent {
1242
1266
  `getPcbSize for shape "${props.shape}" not implemented for ${this.componentName}`
1243
1267
  );
1244
1268
  }
1245
- _getCircuitJsonBounds() {
1269
+ _getPcbCircuitJsonBounds() {
1246
1270
  const { db } = this.root;
1247
1271
  const platedHole = db.pcb_plated_hole.get(this.pcb_plated_hole_id);
1248
1272
  const size = this.getPcbSize();
@@ -1301,6 +1325,12 @@ var PlatedHole = class extends PrimitiveComponent {
1301
1325
  this.pcb_plated_hole_id = pcb_plated_hole.pcb_plated_hole_id;
1302
1326
  }
1303
1327
  }
1328
+ doInitialPcbPortAttachment() {
1329
+ const { db } = this.root;
1330
+ db.pcb_plated_hole.update(this.pcb_plated_hole_id, {
1331
+ pcb_port_id: this.matchedPort?.pcb_port_id
1332
+ });
1333
+ }
1304
1334
  };
1305
1335
 
1306
1336
  // lib/utils/createComponentsFromSoup.ts
@@ -2039,7 +2069,7 @@ function getClosest(point, candidates) {
2039
2069
  // lib/components/primitive-components/Trace.ts
2040
2070
  import "zod";
2041
2071
  var portToObjective = (port) => {
2042
- const portPosition = port._getGlobalPcbPositionBeforeLayout();
2072
+ const portPosition = port._getGlobalPcbPositionAfterLayout();
2043
2073
  return {
2044
2074
  ...portPosition,
2045
2075
  layers: port.getAvailablePcbLayers()
@@ -3094,7 +3124,7 @@ var Hole = class extends PrimitiveComponent {
3094
3124
  });
3095
3125
  this.pcb_hole_id = inserted_hole.pcb_hole_id;
3096
3126
  }
3097
- _getCircuitJsonBounds() {
3127
+ _getPcbCircuitJsonBounds() {
3098
3128
  const { db } = this.root;
3099
3129
  const hole = db.pcb_hole.get(this.pcb_hole_id);
3100
3130
  const size = this.getPcbSize();
@@ -166,10 +166,10 @@ export abstract class PrimitiveComponent<
166
166
  }
167
167
 
168
168
  /**
169
- * Compute the bounds of this component the circuit json elements associated
170
- * with it.
169
+ * Compute the PCB bounds of this component the circuit json elements
170
+ * associated with it.
171
171
  */
172
- _getCircuitJsonBounds(): {
172
+ _getPcbCircuitJsonBounds(): {
173
173
  center: { x: number; y: number }
174
174
  bounds: { left: number; top: number; right: number; bottom: number }
175
175
  width: number
@@ -186,7 +186,7 @@ export abstract class PrimitiveComponent<
186
186
  /**
187
187
  * Set the position of this component from the layout solver. This method
188
188
  * should operate using CircuitJson associated with this component, like
189
- * _getCircuitJsonBounds it can be called multiple times as different
189
+ * _getPcbCircuitJsonBounds it can be called multiple times as different
190
190
  * parents apply layout to their children.
191
191
  */
192
192
  _setPositionFromLayout(newCenter: { x: number; y: number }) {
@@ -19,7 +19,7 @@ export const orderedRenderPhases = [
19
19
  "PcbPrimitiveRender",
20
20
  "PcbFootprintLayout",
21
21
  "PcbPortRender",
22
- "PcbParentAttachment",
22
+ "PcbPortAttachment",
23
23
  "PcbLayout",
24
24
  "PcbTraceRender",
25
25
  "PcbRouteNetIslands",
@@ -28,7 +28,7 @@ export class Footprint extends PrimitiveComponent<typeof footprintProps> {
28
28
  selector,
29
29
  componentSelector,
30
30
  edge,
31
- bounds: component._getCircuitJsonBounds(),
31
+ bounds: component._getPcbCircuitJsonBounds(),
32
32
  }))
33
33
 
34
34
  if (involvedComponents.some((c) => c.edge)) {
@@ -32,7 +32,7 @@ export class Hole extends PrimitiveComponent<typeof holeProps> {
32
32
  this.pcb_hole_id = inserted_hole.pcb_hole_id!
33
33
  }
34
34
 
35
- _getCircuitJsonBounds(): {
35
+ _getPcbCircuitJsonBounds(): {
36
36
  center: { x: number; y: number }
37
37
  bounds: { left: number; top: number; right: number; bottom: number }
38
38
  width: number
@@ -27,7 +27,7 @@ export class PlatedHole extends PrimitiveComponent<typeof platedHoleProps> {
27
27
  )
28
28
  }
29
29
 
30
- _getCircuitJsonBounds(): {
30
+ _getPcbCircuitJsonBounds(): {
31
31
  center: { x: number; y: number }
32
32
  bounds: { left: number; top: number; right: number; bottom: number }
33
33
  width: number
@@ -98,4 +98,11 @@ export class PlatedHole extends PrimitiveComponent<typeof platedHoleProps> {
98
98
  this.pcb_plated_hole_id = pcb_plated_hole.pcb_plated_hole_id
99
99
  }
100
100
  }
101
+
102
+ doInitialPcbPortAttachment(): void {
103
+ const { db } = this.root!
104
+ db.pcb_plated_hole.update(this.pcb_plated_hole_id!, {
105
+ pcb_port_id: this.matchedPort?.pcb_port_id!,
106
+ })
107
+ }
101
108
  }
@@ -44,6 +44,24 @@ export class Port extends PrimitiveComponent<typeof portProps> {
44
44
  return matchedPcbElm?._getGlobalPcbPositionBeforeLayout() ?? { x: 0, y: 0 }
45
45
  }
46
46
 
47
+ _getPcbCircuitJsonBounds() {
48
+ if (!this.pcb_port_id) {
49
+ return super._getPcbCircuitJsonBounds()
50
+ }
51
+ const { db } = this.root!
52
+ const pcb_port = db.pcb_port.get(this.pcb_port_id)!
53
+ return {
54
+ center: { x: pcb_port.x, y: pcb_port.y },
55
+ bounds: { left: 0, top: 0, right: 0, bottom: 0 },
56
+ width: 0,
57
+ height: 0,
58
+ }
59
+ }
60
+
61
+ _getGlobalPcbPositionAfterLayout(): { x: number; y: number } {
62
+ return this._getPcbCircuitJsonBounds().center
63
+ }
64
+
47
65
  _getGlobalSchematicPositionBeforeLayout(): { x: number; y: number } {
48
66
  if (!this.schematicSymbolPortDef) {
49
67
  return applyToPoint(this.parent!.computeSchematicGlobalTransform(), {
@@ -168,12 +186,12 @@ export class Port extends PrimitiveComponent<typeof portProps> {
168
186
 
169
187
  const pcbMatch: any = pcbMatches[0]
170
188
 
171
- if ("_getCircuitJsonBounds" in pcbMatch) {
189
+ if ("_getPcbCircuitJsonBounds" in pcbMatch) {
172
190
  const pcb_port = db.pcb_port.insert({
173
191
  pcb_component_id: this.parent?.pcb_component_id!,
174
192
  layers: ["top"],
175
193
 
176
- ...pcbMatch._getCircuitJsonBounds().center,
194
+ ...pcbMatch._getPcbCircuitJsonBounds().center,
177
195
 
178
196
  source_port_id: this.source_port_id!,
179
197
  })
@@ -63,7 +63,7 @@ export class SmtPad extends PrimitiveComponent<typeof smtPadProps> {
63
63
  if (props.shape === "circle") {
64
64
  pcb_smtpad = db.pcb_smtpad.insert({
65
65
  pcb_component_id: this.parent?.pcb_component_id!,
66
- pcb_port_id: this.matchedPort?.pcb_port_id!,
66
+ pcb_port_id: this.matchedPort?.pcb_port_id!, // port likely isn't matched
67
67
  layer: props.layer ?? "top",
68
68
  shape: "circle",
69
69
 
@@ -78,7 +78,7 @@ export class SmtPad extends PrimitiveComponent<typeof smtPadProps> {
78
78
  } else if (props.shape === "rect") {
79
79
  pcb_smtpad = db.pcb_smtpad.insert({
80
80
  pcb_component_id: this.parent?.pcb_component_id!,
81
- pcb_port_id: this.matchedPort?.pcb_port_id!,
81
+ pcb_port_id: this.matchedPort?.pcb_port_id!, // port likely isn't matched
82
82
  layer: props.layer ?? "top",
83
83
  shape: "rect",
84
84
 
@@ -97,7 +97,14 @@ export class SmtPad extends PrimitiveComponent<typeof smtPadProps> {
97
97
  }
98
98
  }
99
99
 
100
- _getCircuitJsonBounds(): {
100
+ doInitialPcbPortAttachment(): void {
101
+ const { db } = this.root!
102
+ db.pcb_smtpad.update(this.pcb_smtpad_id!, {
103
+ pcb_port_id: this.matchedPort?.pcb_port_id!,
104
+ })
105
+ }
106
+
107
+ _getPcbCircuitJsonBounds(): {
101
108
  center: { x: number; y: number }
102
109
  bounds: { left: number; top: number; right: number; bottom: number }
103
110
  width: number
@@ -38,7 +38,7 @@ type PcbRouteObjective =
38
38
  | { layers: string[]; x: number; y: number; via?: boolean }
39
39
 
40
40
  const portToObjective = (port: Port): PcbRouteObjective => {
41
- const portPosition = port._getGlobalPcbPositionBeforeLayout()
41
+ const portPosition = port._getGlobalPcbPositionAfterLayout()
42
42
  return {
43
43
  ...portPosition,
44
44
  layers: port.getAvailablePcbLayers(),
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tscircuit/core",
3
3
  "module": "index.ts",
4
4
  "type": "module",
5
- "version": "0.0.40",
5
+ "version": "0.0.42",
6
6
  "types": "dist/index.d.ts",
7
7
  "main": "dist/index.js",
8
8
  "files": [