@tscircuit/core 0.0.225 → 0.0.227
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 +2 -0
- package/dist/index.js +72 -14
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -89,6 +89,7 @@ declare class Circuit {
|
|
|
89
89
|
root: Circuit | null;
|
|
90
90
|
isRoot: boolean;
|
|
91
91
|
schematicDisabled: boolean;
|
|
92
|
+
pcbDisabled: boolean;
|
|
92
93
|
_hasRenderedAtleastOnce: boolean;
|
|
93
94
|
constructor();
|
|
94
95
|
add(componentOrElm: PrimitiveComponent | ReactElement): void;
|
|
@@ -614,6 +615,7 @@ declare class Trace extends PrimitiveComponent<typeof traceProps> implements Tra
|
|
|
614
615
|
doInitialSourceTraceRender(): void;
|
|
615
616
|
doInitialPcbTraceRender(): void;
|
|
616
617
|
_doInitialSchematicTraceRenderWithDisplayLabel(): void;
|
|
618
|
+
private _isPassiveToChipConnection;
|
|
617
619
|
doInitialSchematicTraceRender(): void;
|
|
618
620
|
}
|
|
619
621
|
|
package/dist/index.js
CHANGED
|
@@ -1117,6 +1117,7 @@ var Net = class extends PrimitiveComponent {
|
|
|
1117
1117
|
* routing phase for autorouters that don't care about connecting nets.
|
|
1118
1118
|
*/
|
|
1119
1119
|
doInitialPcbRouteNetIslands() {
|
|
1120
|
+
if (this.root?.pcbDisabled) return;
|
|
1120
1121
|
const { db } = this.root;
|
|
1121
1122
|
const { _parsedProps: props } = this;
|
|
1122
1123
|
const traces = this._getAllDirectlyConnectedTraces().filter(
|
|
@@ -1263,6 +1264,7 @@ var SmtPad = class extends PrimitiveComponent {
|
|
|
1263
1264
|
}
|
|
1264
1265
|
}
|
|
1265
1266
|
doInitialPcbPrimitiveRender() {
|
|
1267
|
+
if (this.root?.pcbDisabled) return;
|
|
1266
1268
|
const { db } = this.root;
|
|
1267
1269
|
const { _parsedProps: props } = this;
|
|
1268
1270
|
if (!props.portHints) return;
|
|
@@ -1342,6 +1344,7 @@ var SmtPad = class extends PrimitiveComponent {
|
|
|
1342
1344
|
}
|
|
1343
1345
|
}
|
|
1344
1346
|
doInitialPcbPortAttachment() {
|
|
1347
|
+
if (this.root?.pcbDisabled) return;
|
|
1345
1348
|
const { db } = this.root;
|
|
1346
1349
|
db.pcb_smtpad.update(this.pcb_smtpad_id, {
|
|
1347
1350
|
pcb_port_id: this.matchedPort?.pcb_port_id
|
|
@@ -1427,6 +1430,7 @@ var SilkscreenPath = class extends PrimitiveComponent {
|
|
|
1427
1430
|
};
|
|
1428
1431
|
}
|
|
1429
1432
|
doInitialPcbPrimitiveRender() {
|
|
1433
|
+
if (this.root?.pcbDisabled) return;
|
|
1430
1434
|
const { db } = this.root;
|
|
1431
1435
|
const { _parsedProps: props } = this;
|
|
1432
1436
|
const layer = props.layer ?? "top";
|
|
@@ -1523,6 +1527,7 @@ var PlatedHole = class extends PrimitiveComponent {
|
|
|
1523
1527
|
}
|
|
1524
1528
|
}
|
|
1525
1529
|
doInitialPcbPrimitiveRender() {
|
|
1530
|
+
if (this.root?.pcbDisabled) return;
|
|
1526
1531
|
const { db } = this.root;
|
|
1527
1532
|
const { _parsedProps: props } = this;
|
|
1528
1533
|
const position = this._getGlobalPcbPositionBeforeLayout();
|
|
@@ -1560,6 +1565,7 @@ var PlatedHole = class extends PrimitiveComponent {
|
|
|
1560
1565
|
}
|
|
1561
1566
|
}
|
|
1562
1567
|
doInitialPcbPortAttachment() {
|
|
1568
|
+
if (this.root?.pcbDisabled) return;
|
|
1563
1569
|
const { db } = this.root;
|
|
1564
1570
|
db.pcb_plated_hole.update(this.pcb_plated_hole_id, {
|
|
1565
1571
|
pcb_port_id: this.matchedPort?.pcb_port_id
|
|
@@ -1580,6 +1586,7 @@ var Keepout = class extends PrimitiveComponent {
|
|
|
1580
1586
|
};
|
|
1581
1587
|
}
|
|
1582
1588
|
doInitialPcbPrimitiveRender() {
|
|
1589
|
+
if (this.root?.pcbDisabled) return;
|
|
1583
1590
|
const { db } = this.root;
|
|
1584
1591
|
const { _parsedProps: props } = this;
|
|
1585
1592
|
const position = this._getGlobalPcbPositionBeforeLayout();
|
|
@@ -1633,6 +1640,7 @@ var Hole = class extends PrimitiveComponent {
|
|
|
1633
1640
|
return { width: props.diameter, height: props.diameter };
|
|
1634
1641
|
}
|
|
1635
1642
|
doInitialPcbPrimitiveRender() {
|
|
1643
|
+
if (this.root?.pcbDisabled) return;
|
|
1636
1644
|
const { db } = this.root;
|
|
1637
1645
|
const { _parsedProps: props } = this;
|
|
1638
1646
|
const position = this._getGlobalPcbPositionBeforeLayout();
|
|
@@ -1961,6 +1969,7 @@ var Port = class extends PrimitiveComponent {
|
|
|
1961
1969
|
this.source_component_id = this.parent?.source_component_id;
|
|
1962
1970
|
}
|
|
1963
1971
|
doInitialPcbPortRender() {
|
|
1972
|
+
if (this.root?.pcbDisabled) return;
|
|
1964
1973
|
const { db } = this.root;
|
|
1965
1974
|
const { matchedComponents } = this;
|
|
1966
1975
|
if (!this.parent?.pcb_component_id) {
|
|
@@ -2405,6 +2414,7 @@ var Footprint = class extends PrimitiveComponent {
|
|
|
2405
2414
|
* to any constraints that are defined.
|
|
2406
2415
|
*/
|
|
2407
2416
|
doInitialPcbFootprintLayout() {
|
|
2417
|
+
if (this.root?.pcbDisabled) return;
|
|
2408
2418
|
const constraints = this.children.filter(
|
|
2409
2419
|
(child) => child.componentName === "Constraint"
|
|
2410
2420
|
);
|
|
@@ -2926,6 +2936,7 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
2926
2936
|
this.schematic_component_id = schematic_component2.schematic_component_id;
|
|
2927
2937
|
}
|
|
2928
2938
|
doInitialPcbComponentRender() {
|
|
2939
|
+
if (this.root?.pcbDisabled) return;
|
|
2929
2940
|
const { db } = this.root;
|
|
2930
2941
|
const { _parsedProps: props } = this;
|
|
2931
2942
|
const pcb_component = db.pcb_component.insert({
|
|
@@ -2952,6 +2963,7 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
2952
2963
|
* the width/height of the component
|
|
2953
2964
|
*/
|
|
2954
2965
|
doInitialPcbComponentSizeCalculation() {
|
|
2966
|
+
if (this.root?.pcbDisabled) return;
|
|
2955
2967
|
if (!this.pcb_component_id) return;
|
|
2956
2968
|
const { db } = this.root;
|
|
2957
2969
|
const { _parsedProps: props } = this;
|
|
@@ -3331,6 +3343,7 @@ var TraceHint = class extends PrimitiveComponent {
|
|
|
3331
3343
|
);
|
|
3332
3344
|
}
|
|
3333
3345
|
doInitialPcbTraceHintRender() {
|
|
3346
|
+
if (this.root?.pcbDisabled) return;
|
|
3334
3347
|
const { db } = this.root;
|
|
3335
3348
|
const { _parsedProps: props } = this;
|
|
3336
3349
|
db.pcb_trace_hint.insert({
|
|
@@ -3464,6 +3477,7 @@ var Group = class extends NormalComponent {
|
|
|
3464
3477
|
}
|
|
3465
3478
|
}
|
|
3466
3479
|
doInitialPcbTraceRender() {
|
|
3480
|
+
if (this.root?.pcbDisabled) return;
|
|
3467
3481
|
if (this._shouldUseTraceByTraceRouting()) return;
|
|
3468
3482
|
const serverUrl = this.props.autorouter?.serverUrl ?? "https://registry-api.tscircuit.com";
|
|
3469
3483
|
const serverMode = this.props.autorouter?.serverMode ?? "job";
|
|
@@ -3651,6 +3665,7 @@ var Board = class extends Group {
|
|
|
3651
3665
|
return ["top", "bottom", "inner1", "inner2"];
|
|
3652
3666
|
}
|
|
3653
3667
|
doInitialPcbComponentRender() {
|
|
3668
|
+
if (this.root?.pcbDisabled) return;
|
|
3654
3669
|
const { db } = this.root;
|
|
3655
3670
|
const { _parsedProps: props } = this;
|
|
3656
3671
|
if (!props.width || !props.height) {
|
|
@@ -4152,6 +4167,21 @@ var pushEdgesOfSchematicTraceToPreventOverlap = ({
|
|
|
4152
4167
|
}
|
|
4153
4168
|
};
|
|
4154
4169
|
|
|
4170
|
+
// lib/utils/schematic/countComplexElements.ts
|
|
4171
|
+
var countComplexElements = (junctions, edges) => {
|
|
4172
|
+
let count = 0;
|
|
4173
|
+
count += junctions.length ?? 0;
|
|
4174
|
+
count += edges.filter((edge) => edge.is_crossing).length;
|
|
4175
|
+
for (let i = 1; i < edges.length; i++) {
|
|
4176
|
+
const prev = edges[i - 1];
|
|
4177
|
+
const curr = edges[i];
|
|
4178
|
+
const prevVertical = Math.abs(prev.from.x - prev.to.x) < 0.01;
|
|
4179
|
+
const currVertical = Math.abs(curr.from.x - curr.to.x) < 0.01;
|
|
4180
|
+
if (prevVertical !== currVertical) count++;
|
|
4181
|
+
}
|
|
4182
|
+
return count;
|
|
4183
|
+
};
|
|
4184
|
+
|
|
4155
4185
|
// lib/components/primitive-components/Trace/Trace.ts
|
|
4156
4186
|
var portToObjective = (port) => {
|
|
4157
4187
|
const portPosition = port._getGlobalPcbPositionAfterLayout();
|
|
@@ -4302,6 +4332,7 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
|
|
|
4302
4332
|
this.source_trace_id = trace.source_trace_id;
|
|
4303
4333
|
}
|
|
4304
4334
|
doInitialPcbTraceRender() {
|
|
4335
|
+
if (this.root?.pcbDisabled) return;
|
|
4305
4336
|
const { db } = this.root;
|
|
4306
4337
|
const { _parsedProps: props, parent } = this;
|
|
4307
4338
|
const subcircuit = this.getSubcircuit();
|
|
@@ -4577,7 +4608,7 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
|
|
|
4577
4608
|
const portsWithPosition = connectedPorts.map(({ port }) => ({
|
|
4578
4609
|
port,
|
|
4579
4610
|
position: port._getGlobalSchematicPositionAfterLayout(),
|
|
4580
|
-
schematic_port_id: port.schematic_port_id
|
|
4611
|
+
schematic_port_id: port.schematic_port_id,
|
|
4581
4612
|
facingDirection: port.facingDirection
|
|
4582
4613
|
}));
|
|
4583
4614
|
if (portsWithPosition.length < 2) {
|
|
@@ -4614,26 +4645,40 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
|
|
|
4614
4645
|
}
|
|
4615
4646
|
const existingFromNetLabel = db.schematic_net_label.list().find((label) => label.source_net_id === fromPort.source_port_id);
|
|
4616
4647
|
const existingToNetLabel = db.schematic_net_label.list().find((label) => label.source_net_id === toPort.source_port_id);
|
|
4617
|
-
if (
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4648
|
+
if (this.props.schDisplayLabel) {
|
|
4649
|
+
if (existingFromNetLabel && existingFromNetLabel.text !== this.props.schDisplayLabel || existingToNetLabel && existingToNetLabel?.text !== this.props.schDisplayLabel) {
|
|
4650
|
+
throw new Error(
|
|
4651
|
+
`Cannot create net label for port ${existingFromNetLabel ? fromPortName : toPortName} because it already has a net label with text "${existingFromNetLabel ? existingFromNetLabel.text : existingToNetLabel?.text}".`
|
|
4652
|
+
);
|
|
4653
|
+
}
|
|
4621
4654
|
}
|
|
4655
|
+
const [firstPort, secondPort] = connectedPorts.map(({ port }) => port);
|
|
4656
|
+
const isFirstPortSchematicBox = firstPort.parent?.config.shouldRenderAsSchematicBox;
|
|
4657
|
+
const pinFullName = isFirstPortSchematicBox ? `${firstPort?.parent?.props.name}_${firstPort?.props.name}` : `${secondPort?.parent?.props.name}_${secondPort?.props.name}`;
|
|
4622
4658
|
db.schematic_net_label.insert({
|
|
4623
|
-
text: this.props.schDisplayLabel,
|
|
4659
|
+
text: this.props.schDisplayLabel ?? pinFullName,
|
|
4624
4660
|
source_net_id: fromPort.source_port_id,
|
|
4625
4661
|
anchor_position: fromAnchorPos,
|
|
4626
4662
|
center: fromAnchorPos,
|
|
4627
4663
|
anchor_side: getEnteringEdgeFromDirection(fromPort.facingDirection) ?? "bottom"
|
|
4628
4664
|
});
|
|
4629
4665
|
db.schematic_net_label.insert({
|
|
4630
|
-
text: this.props.schDisplayLabel,
|
|
4666
|
+
text: this.props.schDisplayLabel ?? pinFullName,
|
|
4631
4667
|
source_net_id: toPort.source_port_id,
|
|
4632
4668
|
anchor_position: toAnchorPos,
|
|
4633
4669
|
center: toAnchorPos,
|
|
4634
4670
|
anchor_side: getEnteringEdgeFromDirection(toPort.facingDirection) ?? "bottom"
|
|
4635
4671
|
});
|
|
4636
4672
|
}
|
|
4673
|
+
_isPassiveToChipConnection() {
|
|
4674
|
+
const { allPortsFound, ports } = this._findConnectedPorts();
|
|
4675
|
+
if (!allPortsFound || ports.length !== 2) return false;
|
|
4676
|
+
const [port1, port2] = ports;
|
|
4677
|
+
if (!port1?.parent || !port2?.parent) return false;
|
|
4678
|
+
const isPort1Chip = port1.parent.config.shouldRenderAsSchematicBox;
|
|
4679
|
+
const isPort2Chip = port2.parent.config.shouldRenderAsSchematicBox;
|
|
4680
|
+
return isPort1Chip && !isPort2Chip || !isPort1Chip && isPort2Chip;
|
|
4681
|
+
}
|
|
4637
4682
|
doInitialSchematicTraceRender() {
|
|
4638
4683
|
if (this.root?.schematicDisabled) return;
|
|
4639
4684
|
const { db } = this.root;
|
|
@@ -4677,7 +4722,6 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
|
|
|
4677
4722
|
type: "rect",
|
|
4678
4723
|
layers: ["top"],
|
|
4679
4724
|
center: elm.position,
|
|
4680
|
-
// Approximate text bounds based on text length
|
|
4681
4725
|
width: (elm.text?.length ?? 0) * 0.1,
|
|
4682
4726
|
height: 0.2,
|
|
4683
4727
|
connectedTo: []
|
|
@@ -4775,12 +4819,17 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
|
|
|
4775
4819
|
if (!this.source_trace_id) {
|
|
4776
4820
|
throw new Error("Missing source_trace_id for schematic trace insertion.");
|
|
4777
4821
|
}
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4822
|
+
if (countComplexElements(junctions, edges) >= 5 && this._isPassiveToChipConnection()) {
|
|
4823
|
+
this._doInitialSchematicTraceRenderWithDisplayLabel();
|
|
4824
|
+
db.schematic_trace.delete(this.schematic_trace_id);
|
|
4825
|
+
} else {
|
|
4826
|
+
const trace = db.schematic_trace.insert({
|
|
4827
|
+
source_trace_id: this.source_trace_id,
|
|
4828
|
+
edges,
|
|
4829
|
+
junctions
|
|
4830
|
+
});
|
|
4831
|
+
this.schematic_trace_id = trace.schematic_trace_id;
|
|
4832
|
+
}
|
|
4784
4833
|
}
|
|
4785
4834
|
};
|
|
4786
4835
|
|
|
@@ -4867,6 +4916,7 @@ var Chip = class extends NormalComponent {
|
|
|
4867
4916
|
this.source_component_id = source_component.source_component_id;
|
|
4868
4917
|
}
|
|
4869
4918
|
doInitialPcbComponentRender() {
|
|
4919
|
+
if (this.root?.pcbDisabled) return;
|
|
4870
4920
|
const { db } = this.root;
|
|
4871
4921
|
const { _parsedProps: props } = this;
|
|
4872
4922
|
const pcb_component = db.pcb_component.insert({
|
|
@@ -4933,6 +4983,7 @@ var Jumper = class extends NormalComponent {
|
|
|
4933
4983
|
this.source_component_id = source_component.source_component_id;
|
|
4934
4984
|
}
|
|
4935
4985
|
doInitialPcbComponentRender() {
|
|
4986
|
+
if (this.root?.pcbDisabled) return;
|
|
4936
4987
|
const { db } = this.root;
|
|
4937
4988
|
const { _parsedProps: props } = this;
|
|
4938
4989
|
const pcb_component = db.pcb_component.insert({
|
|
@@ -5134,6 +5185,7 @@ var FabricationNotePath = class extends PrimitiveComponent {
|
|
|
5134
5185
|
};
|
|
5135
5186
|
}
|
|
5136
5187
|
doInitialPcbPrimitiveRender() {
|
|
5188
|
+
if (this.root?.pcbDisabled) return;
|
|
5137
5189
|
const { db } = this.root;
|
|
5138
5190
|
const { _parsedProps: props } = this;
|
|
5139
5191
|
const layer = props.layer ?? "top";
|
|
@@ -5174,6 +5226,7 @@ var FabricationNoteText = class extends PrimitiveComponent {
|
|
|
5174
5226
|
};
|
|
5175
5227
|
}
|
|
5176
5228
|
doInitialPcbPrimitiveRender() {
|
|
5229
|
+
if (this.root?.pcbDisabled) return;
|
|
5177
5230
|
const { db } = this.root;
|
|
5178
5231
|
const { _parsedProps: props } = this;
|
|
5179
5232
|
const container = this.getPrimitiveContainer();
|
|
@@ -5242,6 +5295,7 @@ var SilkscreenCircle = class extends PrimitiveComponent {
|
|
|
5242
5295
|
};
|
|
5243
5296
|
}
|
|
5244
5297
|
doInitialPcbPrimitiveRender() {
|
|
5298
|
+
if (this.root?.pcbDisabled) return;
|
|
5245
5299
|
const { db } = this.root;
|
|
5246
5300
|
const { _parsedProps: props } = this;
|
|
5247
5301
|
const layer = props.layer ?? "top";
|
|
@@ -5275,6 +5329,7 @@ var SilkscreenRect = class extends PrimitiveComponent {
|
|
|
5275
5329
|
};
|
|
5276
5330
|
}
|
|
5277
5331
|
doInitialPcbPrimitiveRender() {
|
|
5332
|
+
if (this.root?.pcbDisabled) return;
|
|
5278
5333
|
const { db } = this.root;
|
|
5279
5334
|
const { _parsedProps: props } = this;
|
|
5280
5335
|
const layer = props.layer ?? "top";
|
|
@@ -5308,6 +5363,7 @@ var SilkscreenText = class extends PrimitiveComponent {
|
|
|
5308
5363
|
};
|
|
5309
5364
|
}
|
|
5310
5365
|
doInitialPcbPrimitiveRender() {
|
|
5366
|
+
if (this.root?.pcbDisabled) return;
|
|
5311
5367
|
const { db } = this.root;
|
|
5312
5368
|
const { _parsedProps: props } = this;
|
|
5313
5369
|
const container = this.getPrimitiveContainer();
|
|
@@ -5379,6 +5435,7 @@ var Via = class extends PrimitiveComponent {
|
|
|
5379
5435
|
});
|
|
5380
5436
|
}
|
|
5381
5437
|
doInitialPcbPrimitiveRender() {
|
|
5438
|
+
if (this.root?.pcbDisabled) return;
|
|
5382
5439
|
const { db } = this.root;
|
|
5383
5440
|
const { _parsedProps: props } = this;
|
|
5384
5441
|
const position = this._getGlobalPcbPositionBeforeLayout();
|
|
@@ -5631,6 +5688,7 @@ var Circuit = class {
|
|
|
5631
5688
|
root = null;
|
|
5632
5689
|
isRoot = true;
|
|
5633
5690
|
schematicDisabled = false;
|
|
5691
|
+
pcbDisabled = false;
|
|
5634
5692
|
_hasRenderedAtleastOnce = false;
|
|
5635
5693
|
constructor() {
|
|
5636
5694
|
this.children = [];
|