@tscircuit/core 0.0.249 → 0.0.251

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
@@ -444,6 +444,7 @@ declare class Trace extends PrimitiveComponent<typeof traceProps> implements Tra
444
444
  } | undefined;
445
445
  }>, "many">>;
446
446
  schDisplayLabel: z.ZodOptional<z.ZodString>;
447
+ maxLength: z.ZodOptional<z.ZodNumber>;
447
448
  }, {
448
449
  path: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<{
449
450
  getPortSelector: () => string;
@@ -468,6 +469,7 @@ declare class Trace extends PrimitiveComponent<typeof traceProps> implements Tra
468
469
  to_layer?: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | undefined;
469
470
  }[] | undefined;
470
471
  schDisplayLabel?: string | undefined;
472
+ maxLength?: number | undefined;
471
473
  }, {
472
474
  path: (string | {
473
475
  getPortSelector: () => string;
@@ -488,6 +490,7 @@ declare class Trace extends PrimitiveComponent<typeof traceProps> implements Tra
488
490
  } | undefined;
489
491
  }[] | undefined;
490
492
  schDisplayLabel?: string | undefined;
493
+ maxLength?: number | undefined;
491
494
  }>, z.ZodObject<z.objectUtil.extendShape<{
492
495
  key: z.ZodOptional<z.ZodString>;
493
496
  thickness: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>>;
@@ -531,6 +534,7 @@ declare class Trace extends PrimitiveComponent<typeof traceProps> implements Tra
531
534
  } | undefined;
532
535
  }>, "many">>;
533
536
  schDisplayLabel: z.ZodOptional<z.ZodString>;
537
+ maxLength: z.ZodOptional<z.ZodNumber>;
534
538
  }, {
535
539
  from: z.ZodUnion<[z.ZodString, z.ZodType<{
536
540
  getPortSelector: () => string;
@@ -563,6 +567,7 @@ declare class Trace extends PrimitiveComponent<typeof traceProps> implements Tra
563
567
  to_layer?: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | undefined;
564
568
  }[] | undefined;
565
569
  schDisplayLabel?: string | undefined;
570
+ maxLength?: number | undefined;
566
571
  }, {
567
572
  from: string | {
568
573
  getPortSelector: () => string;
@@ -586,6 +591,7 @@ declare class Trace extends PrimitiveComponent<typeof traceProps> implements Tra
586
591
  } | undefined;
587
592
  }[] | undefined;
588
593
  schDisplayLabel?: string | undefined;
594
+ maxLength?: number | undefined;
589
595
  }>]>;
590
596
  componentName: string;
591
597
  };
@@ -638,12 +644,12 @@ declare const portProps: z.ZodObject<{
638
644
  pinNumber: z.ZodOptional<z.ZodNumber>;
639
645
  aliases: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
640
646
  }, "strip", z.ZodTypeAny, {
641
- name?: string | undefined;
642
647
  pinNumber?: number | undefined;
648
+ name?: string | undefined;
643
649
  aliases?: string[] | undefined;
644
650
  }, {
645
- name?: string | undefined;
646
651
  pinNumber?: number | undefined;
652
+ name?: string | undefined;
647
653
  aliases?: string[] | undefined;
648
654
  }>;
649
655
  declare class Port extends PrimitiveComponent<typeof portProps> {
@@ -661,12 +667,12 @@ declare class Port extends PrimitiveComponent<typeof portProps> {
661
667
  pinNumber: z.ZodOptional<z.ZodNumber>;
662
668
  aliases: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
663
669
  }, "strip", z.ZodTypeAny, {
664
- name?: string | undefined;
665
670
  pinNumber?: number | undefined;
671
+ name?: string | undefined;
666
672
  aliases?: string[] | undefined;
667
673
  }, {
668
- name?: string | undefined;
669
674
  pinNumber?: number | undefined;
675
+ name?: string | undefined;
670
676
  aliases?: string[] | undefined;
671
677
  }>;
672
678
  };
@@ -1549,6 +1555,7 @@ declare class Capacitor extends NormalComponent<typeof capacitorProps, PassivePo
1549
1555
  decouplingTo: zod.ZodOptional<zod.ZodString>;
1550
1556
  bypassFor: zod.ZodOptional<zod.ZodString>;
1551
1557
  bypassTo: zod.ZodOptional<zod.ZodString>;
1558
+ maxDecouplingTraceLength: zod.ZodOptional<zod.ZodNumber>;
1552
1559
  }>, "strip", zod.ZodTypeAny, {
1553
1560
  name: string;
1554
1561
  capacitance: number;
@@ -1622,6 +1629,7 @@ declare class Capacitor extends NormalComponent<typeof capacitorProps, PassivePo
1622
1629
  decouplingTo?: string | undefined;
1623
1630
  bypassFor?: string | undefined;
1624
1631
  bypassTo?: string | undefined;
1632
+ maxDecouplingTraceLength?: number | undefined;
1625
1633
  }, {
1626
1634
  name: string;
1627
1635
  capacitance: string | number;
@@ -1697,6 +1705,7 @@ declare class Capacitor extends NormalComponent<typeof capacitorProps, PassivePo
1697
1705
  decouplingTo?: string | undefined;
1698
1706
  bypassFor?: string | undefined;
1699
1707
  bypassTo?: string | undefined;
1708
+ maxDecouplingTraceLength?: number | undefined;
1700
1709
  }>;
1701
1710
  sourceFtype: "simple_capacitor";
1702
1711
  };
package/dist/index.js CHANGED
@@ -410,11 +410,47 @@ var createInstanceFromReactElement = (reactElm) => {
410
410
  // lib/soup/underscorifyPinStyles.ts
411
411
  import "circuit-json";
412
412
  import "zod";
413
- var underscorifyPinStyles = (pinStyles) => {
413
+
414
+ // lib/utils/schematic/parsePinNumberFromLabelsOrThrow.ts
415
+ var parsePinNumberFromLabelsOrThrow = (pinNumberOrLabel, pinLabels) => {
416
+ if (typeof pinNumberOrLabel === "number") {
417
+ return pinNumberOrLabel;
418
+ }
419
+ if (pinNumberOrLabel.startsWith("pin")) {
420
+ const pinNumber = Number(pinNumberOrLabel.slice(3));
421
+ return pinNumber;
422
+ }
423
+ if (!pinLabels) {
424
+ throw new Error(
425
+ `No pin labels provided and pin number or label is not a number: "${pinNumberOrLabel}"`
426
+ );
427
+ }
428
+ for (const pinNumberKey in pinLabels) {
429
+ const aliases = Array.isArray(pinLabels[pinNumberKey]) ? pinLabels[pinNumberKey] : [pinLabels[pinNumberKey]];
430
+ if (aliases.includes(pinNumberOrLabel)) {
431
+ return Number(pinNumberKey.replace("pin", ""));
432
+ }
433
+ }
434
+ throw new Error(
435
+ `No pin labels provided and pin number or label is not a number: "${pinNumberOrLabel}"`
436
+ );
437
+ };
438
+
439
+ // lib/soup/underscorifyPinStyles.ts
440
+ var underscorifyPinStyles = (pinStyles, pinLabels) => {
414
441
  if (!pinStyles) return void 0;
415
442
  const underscorePinStyles = {};
416
- for (const [pinName, pinStyle] of Object.entries(pinStyles)) {
417
- underscorePinStyles[pinName] = {
443
+ const mergedStyles = {};
444
+ for (const [pinNameOrLabel, pinStyle] of Object.entries(pinStyles)) {
445
+ const pinNumber = parsePinNumberFromLabelsOrThrow(pinNameOrLabel, pinLabels);
446
+ mergedStyles[pinNumber] = {
447
+ ...mergedStyles[pinNumber],
448
+ ...pinStyle
449
+ };
450
+ }
451
+ for (const [pinNumber, pinStyle] of Object.entries(mergedStyles)) {
452
+ const pinKey = `pin${pinNumber}`;
453
+ underscorePinStyles[pinKey] = {
418
454
  bottom_margin: pinStyle.bottomMargin,
419
455
  left_margin: pinStyle.leftMargin,
420
456
  right_margin: pinStyle.rightMargin,
@@ -2130,31 +2166,6 @@ var getSizeOfSidesFromPortArrangement = (pa) => {
2130
2166
  return { leftSize, rightSize, topSize, bottomSize };
2131
2167
  };
2132
2168
 
2133
- // lib/utils/schematic/parsePinNumberFromLabelsOrThrow.ts
2134
- var parsePinNumberFromLabelsOrThrow = (pinNumberOrLabel, pinLabels) => {
2135
- if (typeof pinNumberOrLabel === "number") {
2136
- return pinNumberOrLabel;
2137
- }
2138
- if (pinNumberOrLabel.startsWith("pin")) {
2139
- const pinNumber = Number(pinNumberOrLabel.slice(3));
2140
- return pinNumber;
2141
- }
2142
- if (!pinLabels) {
2143
- throw new Error(
2144
- `No pin labels provided and pin number or label is not a number: "${pinNumberOrLabel}"`
2145
- );
2146
- }
2147
- for (const pinNumberKey in pinLabels) {
2148
- const aliases = Array.isArray(pinLabels[pinNumberKey]) ? pinLabels[pinNumberKey] : [pinLabels[pinNumberKey]];
2149
- if (aliases.includes(pinNumberOrLabel)) {
2150
- return Number(pinNumberKey.replace("pin", ""));
2151
- }
2152
- }
2153
- throw new Error(
2154
- `No pin labels provided and pin number or label is not a number: "${pinNumberOrLabel}"`
2155
- );
2156
- };
2157
-
2158
2169
  // lib/utils/schematic/getAllDimensionsForSchematicBox.ts
2159
2170
  function isExplicitPinMappingArrangement(arrangement) {
2160
2171
  return arrangement.leftSide !== void 0;
@@ -2227,7 +2238,7 @@ var getAllDimensionsForSchematicBox = (params) => {
2227
2238
  sideIndex,
2228
2239
  truePinIndex
2229
2240
  });
2230
- const pinStyle = params.schPinStyle?.[`pin${pinNumber}`] ?? params.schPinStyle?.[pinNumber];
2241
+ const pinStyle = params.numericSchPinStyle?.[`pin${pinNumber}`] ?? params.numericSchPinStyle?.[pinNumber];
2231
2242
  if (pinStyle?.topMargin) {
2232
2243
  currentDistanceFromEdge += pinStyle.topMargin;
2233
2244
  }
@@ -2255,7 +2266,7 @@ var getAllDimensionsForSchematicBox = (params) => {
2255
2266
  sideIndex,
2256
2267
  truePinIndex
2257
2268
  });
2258
- const pinStyle = params.schPinStyle?.[`pin${pinNumber}`] ?? params.schPinStyle?.[pinNumber];
2269
+ const pinStyle = params.numericSchPinStyle?.[`pin${pinNumber}`] ?? params.numericSchPinStyle?.[pinNumber];
2259
2270
  if (pinStyle?.leftMargin) {
2260
2271
  currentDistanceFromEdge += pinStyle.leftMargin;
2261
2272
  }
@@ -2283,7 +2294,7 @@ var getAllDimensionsForSchematicBox = (params) => {
2283
2294
  sideIndex,
2284
2295
  truePinIndex
2285
2296
  });
2286
- const pinStyle = params.schPinStyle?.[`pin${pinNumber}`] ?? params.schPinStyle?.[pinNumber];
2297
+ const pinStyle = params.numericSchPinStyle?.[`pin${pinNumber}`] ?? params.numericSchPinStyle?.[pinNumber];
2287
2298
  if (pinStyle?.bottomMargin) {
2288
2299
  currentDistanceFromEdge += pinStyle.bottomMargin;
2289
2300
  }
@@ -2311,7 +2322,7 @@ var getAllDimensionsForSchematicBox = (params) => {
2311
2322
  sideIndex,
2312
2323
  truePinIndex
2313
2324
  });
2314
- const pinStyle = params.schPinStyle?.[`pin${pinNumber}`] ?? params.schPinStyle?.[pinNumber];
2325
+ const pinStyle = params.numericSchPinStyle?.[`pin${pinNumber}`] ?? params.numericSchPinStyle?.[pinNumber];
2315
2326
  if (pinStyle?.rightMargin) {
2316
2327
  currentDistanceFromEdge += pinStyle.rightMargin;
2317
2328
  }
@@ -2627,6 +2638,20 @@ var Footprint = class extends PrimitiveComponent {
2627
2638
  }
2628
2639
  };
2629
2640
 
2641
+ // lib/utils/schematic/getNumericSchPinStyle.ts
2642
+ var getNumericSchPinStyle = (pinStyles, pinLabels) => {
2643
+ if (!pinStyles) return void 0;
2644
+ const numericPinStyles = {};
2645
+ for (const [pinNameOrLabel, pinStyle] of Object.entries(pinStyles)) {
2646
+ const pinNumber = parsePinNumberFromLabelsOrThrow(pinNameOrLabel, pinLabels);
2647
+ numericPinStyles[`pin${pinNumber}`] = {
2648
+ ...numericPinStyles[`pin${pinNumber}`],
2649
+ ...pinStyle
2650
+ };
2651
+ }
2652
+ return numericPinStyles;
2653
+ };
2654
+
2630
2655
  // lib/components/base-components/NormalComponent.ts
2631
2656
  var debug2 = Debug3("tscircuit:core");
2632
2657
  var rotation3 = z5.object({
@@ -2926,7 +2951,7 @@ var NormalComponent = class extends PrimitiveComponent {
2926
2951
  ),
2927
2952
  pin_spacing: props.schPinSpacing ?? 0.2,
2928
2953
  // @ts-ignore soup needs to support distance for pin_styles
2929
- pin_styles: underscorifyPinStyles(props.schPinStyle),
2954
+ pin_styles: underscorifyPinStyles(props.schPinStyle, props.pinLabels),
2930
2955
  port_labels: primaryPortLabels,
2931
2956
  source_component_id: this.source_component_id
2932
2957
  });
@@ -3217,7 +3242,10 @@ var NormalComponent = class extends PrimitiveComponent {
3217
3242
  schWidth: props.schWidth,
3218
3243
  schHeight: props.schHeight,
3219
3244
  schPinSpacing: pinSpacing,
3220
- schPinStyle: props.schPinStyle,
3245
+ numericSchPinStyle: getNumericSchPinStyle(
3246
+ props.schPinStyle,
3247
+ props.pinLabels
3248
+ ),
3221
3249
  pinCount,
3222
3250
  schPortArrangement: this._getSchematicPortArrangement(),
3223
3251
  pinLabels: props.pinLabels
@@ -3917,6 +3945,25 @@ var mergeRoutes = (routes) => {
3917
3945
  return merged;
3918
3946
  };
3919
3947
 
3948
+ // lib/components/primitive-components/Trace/compute-trace-length.ts
3949
+ function getTraceLength(route) {
3950
+ let totalLength = 0;
3951
+ for (let i = 0; i < route.length; i++) {
3952
+ const point = route[i];
3953
+ if (point.route_type === "wire") {
3954
+ const nextPoint = route[i + 1];
3955
+ if (nextPoint) {
3956
+ const dx = nextPoint.x - point.x;
3957
+ const dy = nextPoint.y - point.y;
3958
+ totalLength += Math.sqrt(dx * dx + dy * dy);
3959
+ }
3960
+ } else if (point.route_type === "via") {
3961
+ totalLength += 1.6;
3962
+ }
3963
+ }
3964
+ return totalLength;
3965
+ }
3966
+
3920
3967
  // lib/utils/getClosest.ts
3921
3968
  var getDistance = (a, b) => {
3922
3969
  const aPos = "_getGlobalPcbPositionBeforeLayout" in a ? a._getGlobalPcbPositionBeforeLayout() : a;
@@ -4327,6 +4374,23 @@ var createDownwardNetLabelGroundSymbol = ({
4327
4374
  });
4328
4375
  };
4329
4376
 
4377
+ // lib/components/primitive-components/Trace/get-max-length-from-conn ected-capacitors.ts
4378
+ var getMaxLengthFromConnectedCapacitors = (ports, { db }) => {
4379
+ const capacitorMaxLengths = ports.map((port) => {
4380
+ const sourcePort = db.source_port.get(port.source_port_id);
4381
+ if (!sourcePort?.source_component_id) return null;
4382
+ const sourceComponent = db.source_component.get(
4383
+ sourcePort.source_component_id
4384
+ );
4385
+ if (sourceComponent?.ftype === "simple_capacitor") {
4386
+ return sourceComponent.max_decoupling_trace_length;
4387
+ }
4388
+ return null;
4389
+ }).filter((length) => length !== null);
4390
+ if (capacitorMaxLengths.length === 0) return void 0;
4391
+ return Math.min(...capacitorMaxLengths);
4392
+ };
4393
+
4330
4394
  // lib/components/primitive-components/Trace/Trace.ts
4331
4395
  var portToObjective = (port) => {
4332
4396
  const portPosition = port._getGlobalPcbPositionAfterLayout();
@@ -4472,7 +4536,11 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
4472
4536
  const nets = this._findConnectedNets().nets;
4473
4537
  const trace = db.source_trace.insert({
4474
4538
  connected_source_port_ids: ports.map((p) => p.port.source_port_id),
4475
- connected_source_net_ids: nets.map((n) => n.source_net_id)
4539
+ connected_source_net_ids: nets.map((n) => n.source_net_id),
4540
+ max_length: getMaxLengthFromConnectedCapacitors(
4541
+ ports.map((p) => p.port),
4542
+ { db }
4543
+ ) ?? props.maxLength
4476
4544
  });
4477
4545
  this.source_trace_id = trace.source_trace_id;
4478
4546
  }
@@ -4722,9 +4790,11 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
4722
4790
  routes.push(trace.route);
4723
4791
  }
4724
4792
  const mergedRoute = mergeRoutes(routes);
4793
+ const traceLength = getTraceLength(mergedRoute);
4725
4794
  const pcb_trace = db.pcb_trace.insert({
4726
4795
  route: mergedRoute,
4727
- source_trace_id: this.source_trace_id
4796
+ source_trace_id: this.source_trace_id,
4797
+ trace_length: traceLength
4728
4798
  });
4729
4799
  this._portsRoutedOnPcb = ports;
4730
4800
  this.pcb_trace_id = pcb_trace.pcb_trace_id;
@@ -5064,6 +5134,7 @@ var Capacitor = class extends NormalComponent {
5064
5134
  manufacturer_part_number: props.manufacturerPartNumber ?? props.mfn,
5065
5135
  supplier_part_numbers: props.supplierPartNumbers,
5066
5136
  capacitance: props.capacitance,
5137
+ max_decoupling_trace_length: props.maxDecouplingTraceLength,
5067
5138
  display_capacitance: this._getSchematicSymbolDisplayValue()
5068
5139
  });
5069
5140
  this.source_component_id = source_component.source_component_id;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.249",
4
+ "version": "0.0.251",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -43,10 +43,10 @@
43
43
  "@tscircuit/footprinter": "^0.0.95",
44
44
  "@tscircuit/infgrid-ijump-astar": "^0.0.26",
45
45
  "@tscircuit/math-utils": "^0.0.5",
46
- "@tscircuit/props": "^0.0.123",
46
+ "@tscircuit/props": "^0.0.124",
47
47
  "@tscircuit/schematic-autolayout": "^0.0.6",
48
48
  "@tscircuit/soup-util": "^0.0.41",
49
- "circuit-json": "^0.0.124",
49
+ "circuit-json": "^0.0.126",
50
50
  "circuit-json-to-connectivity-map": "^0.0.17",
51
51
  "format-si-unit": "^0.0.2",
52
52
  "nanoid": "^5.0.7",