@tscircuit/core 0.0.298 → 0.0.299

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.
Files changed (2) hide show
  1. package/dist/index.js +200 -214
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4266,25 +4266,6 @@ var mergeRoutes = (routes) => {
4266
4266
  return merged;
4267
4267
  };
4268
4268
 
4269
- // lib/components/primitive-components/Trace/compute-trace-length.ts
4270
- function getTraceLength(route) {
4271
- let totalLength = 0;
4272
- for (let i = 0; i < route.length; i++) {
4273
- const point = route[i];
4274
- if (point.route_type === "wire") {
4275
- const nextPoint = route[i + 1];
4276
- if (nextPoint) {
4277
- const dx = nextPoint.x - point.x;
4278
- const dy = nextPoint.y - point.y;
4279
- totalLength += Math.sqrt(dx * dx + dy * dy);
4280
- }
4281
- } else if (point.route_type === "via") {
4282
- totalLength += 1.6;
4283
- }
4284
- }
4285
- return totalLength;
4286
- }
4287
-
4288
4269
  // lib/utils/getClosest.ts
4289
4270
  var getDistance = (a, b) => {
4290
4271
  const aPos = "_getGlobalPcbPositionBeforeLayout" in a ? a._getGlobalPcbPositionBeforeLayout() : a;
@@ -4306,6 +4287,21 @@ function getClosest(point, candidates) {
4306
4287
  return closest;
4307
4288
  }
4308
4289
 
4290
+ // lib/utils/schematic/countComplexElements.ts
4291
+ var countComplexElements = (junctions, edges) => {
4292
+ let count = 0;
4293
+ count += junctions.length ?? 0;
4294
+ count += edges.filter((edge) => edge.is_crossing).length;
4295
+ for (let i = 1; i < edges.length; i++) {
4296
+ const prev = edges[i - 1];
4297
+ const curr = edges[i];
4298
+ const prevVertical = Math.abs(prev.from.x - prev.to.x) < 0.01;
4299
+ const currVertical = Math.abs(curr.from.x - curr.to.x) < 0.01;
4300
+ if (prevVertical !== currVertical) count++;
4301
+ }
4302
+ return count;
4303
+ };
4304
+
4309
4305
  // lib/utils/schematic/getEnteringEdgeFromDirection.ts
4310
4306
  var getEnteringEdgeFromDirection = (direction) => {
4311
4307
  return {
@@ -4380,6 +4376,94 @@ function tryNow(fn) {
4380
4376
  // lib/components/primitive-components/Trace/Trace.ts
4381
4377
  import "zod";
4382
4378
 
4379
+ // lib/components/primitive-components/Trace/compute-trace-length.ts
4380
+ function getTraceLength(route) {
4381
+ let totalLength = 0;
4382
+ for (let i = 0; i < route.length; i++) {
4383
+ const point = route[i];
4384
+ if (point.route_type === "wire") {
4385
+ const nextPoint = route[i + 1];
4386
+ if (nextPoint) {
4387
+ const dx = nextPoint.x - point.x;
4388
+ const dy = nextPoint.y - point.y;
4389
+ totalLength += Math.sqrt(dx * dx + dy * dy);
4390
+ }
4391
+ } else if (point.route_type === "via") {
4392
+ totalLength += 1.6;
4393
+ }
4394
+ }
4395
+ return totalLength;
4396
+ }
4397
+
4398
+ // lib/components/primitive-components/Trace/create-downward-net-label-ground-symbol.ts
4399
+ var calculateOffsets = (port) => {
4400
+ const schBoxOffset = {
4401
+ left: { x: -0.5, y: 0 },
4402
+ up: { x: 0.5, y: 0.5 },
4403
+ right: { x: 0.5, y: 0 },
4404
+ down: { x: 0, y: -0.5 }
4405
+ }[port.facingDirection];
4406
+ const schBoxVertOffset = port.parent?.config.shouldRenderAsSchematicBox ? 3 : 1;
4407
+ const schBoxHorzOffset = port.parent?.config.shouldRenderAsSchematicBox && (port.facingDirection === "left" || port.facingDirection === "right") ? 3 : 1;
4408
+ const horzPortDirection = schBoxOffset.x;
4409
+ const vertPortDirectionOffset = schBoxOffset.y;
4410
+ const handleUp = port.facingDirection === "up" ? 0.5 : 0;
4411
+ return {
4412
+ schBoxVertOffset,
4413
+ schBoxHorzOffset,
4414
+ horzPortDirection,
4415
+ vertPortDirectionOffset,
4416
+ handleUp
4417
+ };
4418
+ };
4419
+ var createDownwardNetLabelGroundSymbol = ({
4420
+ port,
4421
+ anchorPos,
4422
+ schDisplayLabel,
4423
+ source_trace_id
4424
+ }, { db }) => {
4425
+ const offsets = calculateOffsets(port);
4426
+ db.schematic_net_label.insert({
4427
+ anchor_side: "top",
4428
+ center: {
4429
+ x: anchorPos.x + offsets.horzPortDirection * offsets.schBoxHorzOffset,
4430
+ y: anchorPos.y + offsets.vertPortDirectionOffset * offsets.schBoxVertOffset
4431
+ },
4432
+ source_net_id: port.source_port_id,
4433
+ text: schDisplayLabel,
4434
+ anchor_position: {
4435
+ x: anchorPos.x + offsets.horzPortDirection * offsets.schBoxHorzOffset,
4436
+ y: anchorPos.y + offsets.vertPortDirectionOffset * offsets.schBoxVertOffset
4437
+ },
4438
+ symbol_name: "ground_horz"
4439
+ });
4440
+ db.schematic_trace.insert({
4441
+ edges: [
4442
+ {
4443
+ from: { x: anchorPos.x, y: anchorPos.y },
4444
+ to: {
4445
+ x: anchorPos.x,
4446
+ y: anchorPos.y + offsets.handleUp * offsets.schBoxVertOffset
4447
+ }
4448
+ },
4449
+ {
4450
+ from: { x: anchorPos.x, y: anchorPos.y },
4451
+ to: {
4452
+ x: anchorPos.x + offsets.horzPortDirection * offsets.schBoxHorzOffset,
4453
+ y: anchorPos.y + offsets.vertPortDirectionOffset * offsets.schBoxVertOffset
4454
+ }
4455
+ }
4456
+ ],
4457
+ junctions: [
4458
+ {
4459
+ x: anchorPos.x + offsets.horzPortDirection * offsets.schBoxHorzOffset,
4460
+ y: anchorPos.y + offsets.vertPortDirectionOffset * offsets.schBoxVertOffset
4461
+ }
4462
+ ],
4463
+ source_trace_id
4464
+ });
4465
+ };
4466
+
4383
4467
  // lib/components/primitive-components/Trace/create-schematic-trace-crossing-segments.ts
4384
4468
  import { distance as distance2, doesLineIntersectLine } from "@tscircuit/math-utils";
4385
4469
 
@@ -4552,175 +4636,6 @@ var createSchematicTraceJunctions = ({
4552
4636
  return [];
4553
4637
  };
4554
4638
 
4555
- // lib/components/primitive-components/Trace/push-edges-of-schematic-trace-to-prevent-overlap.ts
4556
- import { doesLineIntersectLine as doesLineIntersectLine2 } from "@tscircuit/math-utils";
4557
- var pushEdgesOfSchematicTraceToPreventOverlap = ({
4558
- edges,
4559
- db,
4560
- source_trace_id
4561
- }) => {
4562
- const mySourceTrace = db.source_trace.get(source_trace_id);
4563
- const otherEdges = getOtherSchematicTraces({
4564
- db,
4565
- source_trace_id,
4566
- differentNetOnly: true
4567
- }).flatMap((t) => t.edges);
4568
- const edgeOrientation = (edge) => {
4569
- const { from, to } = edge;
4570
- return from.x === to.x ? "vertical" : "horizontal";
4571
- };
4572
- for (const mySegment of edges) {
4573
- const mySegmentOrientation = edgeOrientation(mySegment);
4574
- const findOverlappingParallelSegment = () => otherEdges.find(
4575
- (otherEdge) => edgeOrientation(otherEdge) === mySegmentOrientation && doesLineIntersectLine2(
4576
- [mySegment.from, mySegment.to],
4577
- [otherEdge.from, otherEdge.to],
4578
- {
4579
- lineThickness: 0.05
4580
- }
4581
- )
4582
- );
4583
- let overlappingParallelSegmentFromOtherTrace = findOverlappingParallelSegment();
4584
- while (overlappingParallelSegmentFromOtherTrace) {
4585
- if (mySegmentOrientation === "horizontal") {
4586
- mySegment.from.y += 0.1;
4587
- mySegment.to.y += 0.1;
4588
- } else {
4589
- mySegment.from.x += 0.1;
4590
- mySegment.to.x += 0.1;
4591
- }
4592
- overlappingParallelSegmentFromOtherTrace = findOverlappingParallelSegment();
4593
- }
4594
- }
4595
- };
4596
-
4597
- // lib/utils/schematic/countComplexElements.ts
4598
- var countComplexElements = (junctions, edges) => {
4599
- let count = 0;
4600
- count += junctions.length ?? 0;
4601
- count += edges.filter((edge) => edge.is_crossing).length;
4602
- for (let i = 1; i < edges.length; i++) {
4603
- const prev = edges[i - 1];
4604
- const curr = edges[i];
4605
- const prevVertical = Math.abs(prev.from.x - prev.to.x) < 0.01;
4606
- const currVertical = Math.abs(curr.from.x - curr.to.x) < 0.01;
4607
- if (prevVertical !== currVertical) count++;
4608
- }
4609
- return count;
4610
- };
4611
-
4612
- // lib/components/primitive-components/Trace/create-downward-net-label-ground-symbol.ts
4613
- var calculateOffsets = (port) => {
4614
- const schBoxOffset = {
4615
- left: { x: -0.5, y: 0 },
4616
- up: { x: 0.5, y: 0.5 },
4617
- right: { x: 0.5, y: 0 },
4618
- down: { x: 0, y: -0.5 }
4619
- }[port.facingDirection];
4620
- const schBoxVertOffset = port.parent?.config.shouldRenderAsSchematicBox ? 3 : 1;
4621
- const schBoxHorzOffset = port.parent?.config.shouldRenderAsSchematicBox && (port.facingDirection === "left" || port.facingDirection === "right") ? 3 : 1;
4622
- const horzPortDirection = schBoxOffset.x;
4623
- const vertPortDirectionOffset = schBoxOffset.y;
4624
- const handleUp = port.facingDirection === "up" ? 0.5 : 0;
4625
- return {
4626
- schBoxVertOffset,
4627
- schBoxHorzOffset,
4628
- horzPortDirection,
4629
- vertPortDirectionOffset,
4630
- handleUp
4631
- };
4632
- };
4633
- var createDownwardNetLabelGroundSymbol = ({
4634
- fromPort,
4635
- toPort,
4636
- fromAnchorPos,
4637
- toAnchorPos,
4638
- schDisplayLabel,
4639
- source_trace_id
4640
- }, { db }) => {
4641
- const fromOffsets = calculateOffsets(fromPort);
4642
- db.schematic_net_label.insert({
4643
- anchor_side: "top",
4644
- center: {
4645
- x: fromAnchorPos.x + fromOffsets.horzPortDirection * fromOffsets.schBoxHorzOffset,
4646
- y: fromAnchorPos.y + fromOffsets.vertPortDirectionOffset * fromOffsets.schBoxVertOffset
4647
- },
4648
- source_net_id: fromPort.source_port_id,
4649
- text: schDisplayLabel,
4650
- anchor_position: {
4651
- x: fromAnchorPos.x + fromOffsets.horzPortDirection * fromOffsets.schBoxHorzOffset,
4652
- y: fromAnchorPos.y + fromOffsets.vertPortDirectionOffset * fromOffsets.schBoxVertOffset
4653
- },
4654
- symbol_name: "ground_horz"
4655
- });
4656
- db.schematic_trace.insert({
4657
- edges: [
4658
- {
4659
- from: { x: fromAnchorPos.x, y: fromAnchorPos.y },
4660
- to: {
4661
- x: fromAnchorPos.x,
4662
- y: fromAnchorPos.y + fromOffsets.handleUp * fromOffsets.schBoxVertOffset
4663
- }
4664
- },
4665
- {
4666
- from: { x: fromAnchorPos.x, y: fromAnchorPos.y },
4667
- to: {
4668
- x: fromAnchorPos.x + fromOffsets.horzPortDirection * fromOffsets.schBoxHorzOffset,
4669
- y: fromAnchorPos.y + fromOffsets.vertPortDirectionOffset * fromOffsets.schBoxVertOffset
4670
- }
4671
- }
4672
- ],
4673
- junctions: [
4674
- {
4675
- x: fromAnchorPos.x + fromOffsets.horzPortDirection * fromOffsets.schBoxHorzOffset,
4676
- y: fromAnchorPos.y + fromOffsets.vertPortDirectionOffset * fromOffsets.schBoxVertOffset
4677
- }
4678
- ],
4679
- source_trace_id
4680
- });
4681
- const toOffsets = calculateOffsets(toPort);
4682
- db.schematic_net_label.insert({
4683
- anchor_side: "top",
4684
- center: {
4685
- x: toAnchorPos.x + toOffsets.horzPortDirection * toOffsets.schBoxHorzOffset,
4686
- y: toAnchorPos.y + toOffsets.vertPortDirectionOffset * toOffsets.schBoxVertOffset
4687
- },
4688
- source_net_id: toPort.source_port_id,
4689
- text: schDisplayLabel,
4690
- anchor_position: {
4691
- x: toAnchorPos.x + toOffsets.horzPortDirection * toOffsets.schBoxHorzOffset,
4692
- y: toAnchorPos.y + toOffsets.vertPortDirectionOffset * toOffsets.schBoxVertOffset
4693
- },
4694
- symbol_name: "ground_horz"
4695
- });
4696
- const toHandleUp = toPort.facingDirection === "up" ? 0.5 : 0;
4697
- db.schematic_trace.insert({
4698
- edges: [
4699
- {
4700
- from: { x: toAnchorPos.x, y: toAnchorPos.y },
4701
- to: {
4702
- x: toAnchorPos.x,
4703
- y: toAnchorPos.y + toHandleUp * toOffsets.schBoxVertOffset
4704
- }
4705
- },
4706
- {
4707
- from: { x: toAnchorPos.x, y: toAnchorPos.y },
4708
- to: {
4709
- x: toAnchorPos.x + toOffsets.horzPortDirection * toOffsets.schBoxHorzOffset,
4710
- y: toAnchorPos.y + toOffsets.vertPortDirectionOffset * toOffsets.schBoxVertOffset
4711
- }
4712
- }
4713
- ],
4714
- junctions: [
4715
- {
4716
- x: toAnchorPos.x + toOffsets.horzPortDirection * toOffsets.schBoxHorzOffset,
4717
- y: toAnchorPos.y + toOffsets.vertPortDirectionOffset * toOffsets.schBoxVertOffset
4718
- }
4719
- ],
4720
- source_trace_id
4721
- });
4722
- };
4723
-
4724
4639
  // lib/components/primitive-components/Trace/get-max-length-from-conn ected-capacitors.ts
4725
4640
  var getMaxLengthFromConnectedCapacitors = (ports, { db }) => {
4726
4641
  const capacitorMaxLengths = ports.map((port) => {
@@ -4738,20 +4653,6 @@ var getMaxLengthFromConnectedCapacitors = (ports, { db }) => {
4738
4653
  return Math.min(...capacitorMaxLengths);
4739
4654
  };
4740
4655
 
4741
- // lib/components/primitive-components/Trace/get-trace-display-name.ts
4742
- function getTraceDisplayName({
4743
- ports,
4744
- nets
4745
- }) {
4746
- if (ports.length >= 2) {
4747
- return `${ports[0]?.selector} to ${ports[1]?.selector}`;
4748
- }
4749
- if (ports.length === 1 && nets.length === 1) {
4750
- return `${ports[0]?.selector} to net.${nets[0]._parsedProps.name}`;
4751
- }
4752
- return void 0;
4753
- }
4754
-
4755
4656
  // lib/components/primitive-components/Trace/get-obstacles-for-trace.ts
4756
4657
  import { getUnitVectorFromDirection } from "@tscircuit/math-utils";
4757
4658
  var getSchematicObstaclesForTrace = (trace) => {
@@ -4818,6 +4719,62 @@ var getSchematicObstaclesForTrace = (trace) => {
4818
4719
  return obstacles;
4819
4720
  };
4820
4721
 
4722
+ // lib/components/primitive-components/Trace/get-trace-display-name.ts
4723
+ function getTraceDisplayName({
4724
+ ports,
4725
+ nets
4726
+ }) {
4727
+ if (ports.length >= 2) {
4728
+ return `${ports[0]?.selector} to ${ports[1]?.selector}`;
4729
+ }
4730
+ if (ports.length === 1 && nets.length === 1) {
4731
+ return `${ports[0]?.selector} to net.${nets[0]._parsedProps.name}`;
4732
+ }
4733
+ return void 0;
4734
+ }
4735
+
4736
+ // lib/components/primitive-components/Trace/push-edges-of-schematic-trace-to-prevent-overlap.ts
4737
+ import { doesLineIntersectLine as doesLineIntersectLine2 } from "@tscircuit/math-utils";
4738
+ var pushEdgesOfSchematicTraceToPreventOverlap = ({
4739
+ edges,
4740
+ db,
4741
+ source_trace_id
4742
+ }) => {
4743
+ const mySourceTrace = db.source_trace.get(source_trace_id);
4744
+ const otherEdges = getOtherSchematicTraces({
4745
+ db,
4746
+ source_trace_id,
4747
+ differentNetOnly: true
4748
+ }).flatMap((t) => t.edges);
4749
+ const edgeOrientation = (edge) => {
4750
+ const { from, to } = edge;
4751
+ return from.x === to.x ? "vertical" : "horizontal";
4752
+ };
4753
+ for (const mySegment of edges) {
4754
+ const mySegmentOrientation = edgeOrientation(mySegment);
4755
+ const findOverlappingParallelSegment = () => otherEdges.find(
4756
+ (otherEdge) => edgeOrientation(otherEdge) === mySegmentOrientation && doesLineIntersectLine2(
4757
+ [mySegment.from, mySegment.to],
4758
+ [otherEdge.from, otherEdge.to],
4759
+ {
4760
+ lineThickness: 0.05
4761
+ }
4762
+ )
4763
+ );
4764
+ let overlappingParallelSegmentFromOtherTrace = findOverlappingParallelSegment();
4765
+ while (overlappingParallelSegmentFromOtherTrace) {
4766
+ if (mySegmentOrientation === "horizontal") {
4767
+ mySegment.from.y += 0.1;
4768
+ mySegment.to.y += 0.1;
4769
+ } else {
4770
+ mySegment.from.x += 0.1;
4771
+ mySegment.to.x += 0.1;
4772
+ }
4773
+ overlappingParallelSegmentFromOtherTrace = findOverlappingParallelSegment();
4774
+ }
4775
+ }
4776
+ };
4777
+
4821
4778
  // lib/components/primitive-components/Trace/Trace.ts
4822
4779
  var portToObjective = (port) => {
4823
4780
  const portPosition = port._getGlobalPcbPositionAfterLayout();
@@ -5301,18 +5258,47 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
5301
5258
  if (existingToNetLabel && existingToNetLabel?.text !== netLabelText) {
5302
5259
  existingToNetLabel.text = `${netLabelText} / ${existingToNetLabel.text}`;
5303
5260
  }
5304
- if (!existingFromNetLabel && !existingToNetLabel && (netLabelText?.toLocaleLowerCase().includes("gnd") || netLabelText?.toLocaleLowerCase().includes("ground"))) {
5305
- createDownwardNetLabelGroundSymbol(
5306
- {
5307
- fromPort,
5308
- toPort,
5309
- fromAnchorPos,
5310
- toAnchorPos,
5311
- schDisplayLabel: this.props.schDisplayLabel,
5312
- source_trace_id: this.source_trace_id
5313
- },
5314
- { db }
5315
- );
5261
+ if (netLabelText?.toLocaleLowerCase().includes("gnd") || netLabelText?.toLocaleLowerCase().includes("ground")) {
5262
+ if (!existingFromNetLabel && !existingToNetLabel) {
5263
+ createDownwardNetLabelGroundSymbol(
5264
+ {
5265
+ port: fromPort,
5266
+ anchorPos: fromAnchorPos,
5267
+ schDisplayLabel: this.props.schDisplayLabel,
5268
+ source_trace_id: this.source_trace_id
5269
+ },
5270
+ { db }
5271
+ );
5272
+ createDownwardNetLabelGroundSymbol(
5273
+ {
5274
+ port: toPort,
5275
+ anchorPos: toAnchorPos,
5276
+ schDisplayLabel: this.props.schDisplayLabel,
5277
+ source_trace_id: this.source_trace_id
5278
+ },
5279
+ { db }
5280
+ );
5281
+ } else if (!existingFromNetLabel) {
5282
+ createDownwardNetLabelGroundSymbol(
5283
+ {
5284
+ port: fromPort,
5285
+ anchorPos: fromAnchorPos,
5286
+ schDisplayLabel: this.props.schDisplayLabel,
5287
+ source_trace_id: this.source_trace_id
5288
+ },
5289
+ { db }
5290
+ );
5291
+ } else if (!existingToNetLabel) {
5292
+ createDownwardNetLabelGroundSymbol(
5293
+ {
5294
+ port: toPort,
5295
+ anchorPos: toAnchorPos,
5296
+ schDisplayLabel: this.props.schDisplayLabel,
5297
+ source_trace_id: this.source_trace_id
5298
+ },
5299
+ { db }
5300
+ );
5301
+ }
5316
5302
  return;
5317
5303
  }
5318
5304
  if (!existingToNetLabel) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.298",
4
+ "version": "0.0.299",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",