@tscircuit/core 0.0.771 → 0.0.773

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
@@ -380,6 +380,14 @@ declare abstract class PrimitiveComponent<ZodProps extends ZodType = any> extend
380
380
  */
381
381
  _computePcbGlobalTransformBeforeLayout(): Matrix;
382
382
  getPrimitiveContainer(): PrimitiveComponent | null;
383
+ /**
384
+ * Walk up the component hierarchy to find the nearest NormalComponent ancestor.
385
+ * This is useful for primitive components that need access to component IDs
386
+ * (pcb_component_id, schematic_component_id, source_component_id) from their
387
+ * parent NormalComponent, even when there are intermediate primitive containers
388
+ * like Symbol in the hierarchy.
389
+ */
390
+ getParentNormalComponent(): any | null;
383
391
  /**
384
392
  * Compute the PCB bounds of this component the circuit json elements
385
393
  * associated with it.
@@ -888,18 +896,27 @@ declare const portProps: z.ZodObject<{
888
896
  aliases: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
889
897
  layer: z.ZodOptional<z.ZodString>;
890
898
  layers: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
899
+ schX: z.ZodOptional<z.ZodNumber>;
900
+ schY: z.ZodOptional<z.ZodNumber>;
901
+ direction: z.ZodOptional<z.ZodEnum<["up", "down", "left", "right"]>>;
891
902
  }, "strip", z.ZodTypeAny, {
892
903
  name?: string | undefined;
893
904
  layer?: string | undefined;
894
905
  layers?: string[] | undefined;
895
906
  pinNumber?: number | undefined;
896
907
  aliases?: string[] | undefined;
908
+ schX?: number | undefined;
909
+ schY?: number | undefined;
910
+ direction?: "left" | "right" | "up" | "down" | undefined;
897
911
  }, {
898
912
  name?: string | undefined;
899
913
  layer?: string | undefined;
900
914
  layers?: string[] | undefined;
901
915
  pinNumber?: number | undefined;
902
916
  aliases?: string[] | undefined;
917
+ schX?: number | undefined;
918
+ schY?: number | undefined;
919
+ direction?: "left" | "right" | "up" | "down" | undefined;
903
920
  }>;
904
921
  declare class Port extends PrimitiveComponent<typeof portProps> {
905
922
  source_port_id: string | null;
@@ -917,18 +934,27 @@ declare class Port extends PrimitiveComponent<typeof portProps> {
917
934
  aliases: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
918
935
  layer: z.ZodOptional<z.ZodString>;
919
936
  layers: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
937
+ schX: z.ZodOptional<z.ZodNumber>;
938
+ schY: z.ZodOptional<z.ZodNumber>;
939
+ direction: z.ZodOptional<z.ZodEnum<["up", "down", "left", "right"]>>;
920
940
  }, "strip", z.ZodTypeAny, {
921
941
  name?: string | undefined;
922
942
  layer?: string | undefined;
923
943
  layers?: string[] | undefined;
924
944
  pinNumber?: number | undefined;
925
945
  aliases?: string[] | undefined;
946
+ schX?: number | undefined;
947
+ schY?: number | undefined;
948
+ direction?: "left" | "right" | "up" | "down" | undefined;
926
949
  }, {
927
950
  name?: string | undefined;
928
951
  layer?: string | undefined;
929
952
  layers?: string[] | undefined;
930
953
  pinNumber?: number | undefined;
931
954
  aliases?: string[] | undefined;
955
+ schX?: number | undefined;
956
+ schY?: number | undefined;
957
+ direction?: "left" | "right" | "up" | "down" | undefined;
932
958
  }>;
933
959
  };
934
960
  constructor(props: z.input<typeof portProps>, opts?: {
@@ -14562,6 +14588,8 @@ declare const voltageSourceProps: z.ZodObject<{
14562
14588
  pcbRotation?: number | undefined;
14563
14589
  layer?: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | undefined;
14564
14590
  phase?: number | undefined;
14591
+ schX?: number | undefined;
14592
+ schY?: number | undefined;
14565
14593
  pcbX?: number | undefined;
14566
14594
  voltage?: number | undefined;
14567
14595
  frequency?: number | undefined;
@@ -14579,8 +14607,6 @@ declare const voltageSourceProps: z.ZodObject<{
14579
14607
  schMarginLeft?: number | undefined;
14580
14608
  schMarginX?: number | undefined;
14581
14609
  schMarginY?: number | undefined;
14582
- schX?: number | undefined;
14583
- schY?: number | undefined;
14584
14610
  schRotation?: number | undefined;
14585
14611
  schRelative?: boolean | undefined;
14586
14612
  pcbRelative?: boolean | undefined;
@@ -14742,6 +14768,8 @@ declare const voltageSourceProps: z.ZodObject<{
14742
14768
  name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
14743
14769
  } | undefined;
14744
14770
  phase?: string | number | undefined;
14771
+ schX?: string | number | undefined;
14772
+ schY?: string | number | undefined;
14745
14773
  pcbX?: string | number | undefined;
14746
14774
  voltage?: string | number | undefined;
14747
14775
  frequency?: string | number | undefined;
@@ -14759,8 +14787,6 @@ declare const voltageSourceProps: z.ZodObject<{
14759
14787
  schMarginLeft?: string | number | undefined;
14760
14788
  schMarginX?: string | number | undefined;
14761
14789
  schMarginY?: string | number | undefined;
14762
- schX?: string | number | undefined;
14763
- schY?: string | number | undefined;
14764
14790
  schRotation?: string | number | undefined;
14765
14791
  schRelative?: boolean | undefined;
14766
14792
  pcbRelative?: boolean | undefined;
@@ -15563,6 +15589,8 @@ declare class VoltageSource extends NormalComponent<typeof voltageSourceProps, "
15563
15589
  pcbRotation?: number | undefined;
15564
15590
  layer?: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | undefined;
15565
15591
  phase?: number | undefined;
15592
+ schX?: number | undefined;
15593
+ schY?: number | undefined;
15566
15594
  pcbX?: number | undefined;
15567
15595
  voltage?: number | undefined;
15568
15596
  frequency?: number | undefined;
@@ -15580,8 +15608,6 @@ declare class VoltageSource extends NormalComponent<typeof voltageSourceProps, "
15580
15608
  schMarginLeft?: number | undefined;
15581
15609
  schMarginX?: number | undefined;
15582
15610
  schMarginY?: number | undefined;
15583
- schX?: number | undefined;
15584
- schY?: number | undefined;
15585
15611
  schRotation?: number | undefined;
15586
15612
  schRelative?: boolean | undefined;
15587
15613
  pcbRelative?: boolean | undefined;
@@ -15743,6 +15769,8 @@ declare class VoltageSource extends NormalComponent<typeof voltageSourceProps, "
15743
15769
  name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
15744
15770
  } | undefined;
15745
15771
  phase?: string | number | undefined;
15772
+ schX?: string | number | undefined;
15773
+ schY?: string | number | undefined;
15746
15774
  pcbX?: string | number | undefined;
15747
15775
  voltage?: string | number | undefined;
15748
15776
  frequency?: string | number | undefined;
@@ -15760,8 +15788,6 @@ declare class VoltageSource extends NormalComponent<typeof voltageSourceProps, "
15760
15788
  schMarginLeft?: string | number | undefined;
15761
15789
  schMarginX?: string | number | undefined;
15762
15790
  schMarginY?: string | number | undefined;
15763
- schX?: string | number | undefined;
15764
- schY?: string | number | undefined;
15765
15791
  schRotation?: string | number | undefined;
15766
15792
  schRelative?: boolean | undefined;
15767
15793
  pcbRelative?: boolean | undefined;
package/dist/index.js CHANGED
@@ -777,6 +777,23 @@ var PrimitiveComponent2 = class extends Renderable {
777
777
  if (this.isPrimitiveContainer) return this;
778
778
  return this.parent?.getPrimitiveContainer?.() ?? null;
779
779
  }
780
+ /**
781
+ * Walk up the component hierarchy to find the nearest NormalComponent ancestor.
782
+ * This is useful for primitive components that need access to component IDs
783
+ * (pcb_component_id, schematic_component_id, source_component_id) from their
784
+ * parent NormalComponent, even when there are intermediate primitive containers
785
+ * like Symbol in the hierarchy.
786
+ */
787
+ getParentNormalComponent() {
788
+ let current = this.parent;
789
+ while (current) {
790
+ if (current.isPrimitiveContainer && current.doInitialPcbComponentRender) {
791
+ return current;
792
+ }
793
+ current = current.parent;
794
+ }
795
+ return null;
796
+ }
780
797
  /**
781
798
  * Compute the PCB bounds of this component the circuit json elements
782
799
  * associated with it.
@@ -1084,7 +1101,8 @@ var PrimitiveComponent2 = class extends Renderable {
1084
1101
  if (!this.isSubcircuit) return;
1085
1102
  const ports = this.selectAll("port");
1086
1103
  for (const port of ports) {
1087
- const parentAliases = port.parent?.getNameAndAliases();
1104
+ const parentComponent = port.getParentNormalComponent?.() ?? port.parent;
1105
+ const parentAliases = parentComponent?.getNameAndAliases();
1088
1106
  const portAliases = port.getNameAndAliases();
1089
1107
  if (!parentAliases) continue;
1090
1108
  for (const parentAlias of parentAliases) {
@@ -3314,7 +3332,10 @@ var portProps = z6.object({
3314
3332
  pinNumber: z6.number().optional(),
3315
3333
  aliases: z6.array(z6.string()).optional(),
3316
3334
  layer: z6.string().optional(),
3317
- layers: z6.array(z6.string()).optional()
3335
+ layers: z6.array(z6.string()).optional(),
3336
+ schX: z6.number().optional(),
3337
+ schY: z6.number().optional(),
3338
+ direction: z6.enum(["up", "down", "left", "right"]).optional()
3318
3339
  });
3319
3340
  var Port = class extends PrimitiveComponent2 {
3320
3341
  source_port_id = null;
@@ -3409,7 +3430,12 @@ var Port = class extends PrimitiveComponent2 {
3409
3430
  * are rendered properly.
3410
3431
  */
3411
3432
  _hasSchematicPort() {
3412
- const symbol = this.parent?.getSchematicSymbol();
3433
+ const { schX, schY } = this._parsedProps;
3434
+ if (schX !== void 0 && schY !== void 0) {
3435
+ return true;
3436
+ }
3437
+ const parentNormalComponent = this.getParentNormalComponent();
3438
+ const symbol = parentNormalComponent?.getSchematicSymbol();
3413
3439
  if (symbol) {
3414
3440
  if (this.schematicSymbolPortDef) return true;
3415
3441
  const portsInternallyConnectedToThisPort = this._getPortsInternallyConnectedToThisPort();
@@ -3417,7 +3443,7 @@ var Port = class extends PrimitiveComponent2 {
3417
3443
  return true;
3418
3444
  return false;
3419
3445
  }
3420
- const parentBoxDim = this?.parent?._getSchematicBoxDimensions();
3446
+ const parentBoxDim = parentNormalComponent?._getSchematicBoxDimensions();
3421
3447
  if (parentBoxDim && this.props.pinNumber !== void 0) {
3422
3448
  const localPortPosition = parentBoxDim.getPortPositionByPinNumber(
3423
3449
  this.props.pinNumber
@@ -3427,7 +3453,12 @@ var Port = class extends PrimitiveComponent2 {
3427
3453
  return false;
3428
3454
  }
3429
3455
  _getGlobalSchematicPositionBeforeLayout() {
3430
- const symbol = this.parent?.getSchematicSymbol();
3456
+ const { schX, schY } = this._parsedProps;
3457
+ if (schX !== void 0 && schY !== void 0) {
3458
+ return { x: schX, y: schY };
3459
+ }
3460
+ const parentNormalComponent = this.getParentNormalComponent();
3461
+ const symbol = parentNormalComponent?.getSchematicSymbol();
3431
3462
  if (symbol) {
3432
3463
  let schematicSymbolPortDef = this.schematicSymbolPortDef;
3433
3464
  if (!schematicSymbolPortDef) {
@@ -3441,12 +3472,12 @@ var Port = class extends PrimitiveComponent2 {
3441
3472
  }
3442
3473
  }
3443
3474
  const transform = compose3(
3444
- this.parent.computeSchematicGlobalTransform(),
3475
+ parentNormalComponent.computeSchematicGlobalTransform(),
3445
3476
  translate3(-symbol.center.x, -symbol.center.y)
3446
3477
  );
3447
3478
  return applyToPoint5(transform, schematicSymbolPortDef);
3448
3479
  }
3449
- const parentBoxDim = this?.parent?._getSchematicBoxDimensions();
3480
+ const parentBoxDim = parentNormalComponent?._getSchematicBoxDimensions();
3450
3481
  if (parentBoxDim && this.props.pinNumber !== void 0) {
3451
3482
  const localPortPosition = parentBoxDim.getPortPositionByPinNumber(
3452
3483
  this.props.pinNumber
@@ -3457,7 +3488,7 @@ var Port = class extends PrimitiveComponent2 {
3457
3488
  );
3458
3489
  }
3459
3490
  return applyToPoint5(
3460
- this.parent.computeSchematicGlobalTransform(),
3491
+ parentNormalComponent.computeSchematicGlobalTransform(),
3461
3492
  localPortPosition
3462
3493
  );
3463
3494
  }
@@ -3519,7 +3550,8 @@ var Port = class extends PrimitiveComponent2 {
3519
3550
  return this.isMatchingAnyOf(port.getNameAndAliases());
3520
3551
  }
3521
3552
  getPortSelector() {
3522
- return `.${this.parent?.props.name} > port.${this.props.name}`;
3553
+ const parentComponent = this.getParentNormalComponent() ?? this.parent;
3554
+ return `.${parentComponent?.props.name} > port.${this.props.name}`;
3523
3555
  }
3524
3556
  getAvailablePcbLayers() {
3525
3557
  const { layer, layers } = this._parsedProps;
@@ -3543,35 +3575,42 @@ var Port = class extends PrimitiveComponent2 {
3543
3575
  const { db } = this.root;
3544
3576
  const { _parsedProps: props } = this;
3545
3577
  const port_hints = this.getNameAndAliases();
3578
+ const parentNormalComponent = this.getParentNormalComponent();
3579
+ const parentWithSourceId = this.parent?.source_component_id ? this.parent : parentNormalComponent;
3580
+ const source_component_id = parentWithSourceId?.source_component_id ?? null;
3546
3581
  const source_port = db.source_port.insert({
3547
3582
  name: props.name,
3548
3583
  pin_number: props.pinNumber,
3549
3584
  port_hints,
3550
- source_component_id: this.parent?.source_component_id,
3585
+ source_component_id,
3551
3586
  subcircuit_id: this.getSubcircuit()?.subcircuit_id
3552
3587
  });
3553
3588
  this.source_port_id = source_port.source_port_id;
3554
3589
  }
3555
3590
  doInitialSourceParentAttachment() {
3556
3591
  const { db } = this.root;
3557
- if (!this.parent?.source_component_id) {
3592
+ const parentNormalComponent = this.getParentNormalComponent();
3593
+ const parentWithSourceId = this.parent?.source_component_id ? this.parent : parentNormalComponent;
3594
+ if (!parentWithSourceId?.source_component_id) {
3558
3595
  throw new Error(
3559
3596
  `${this.getString()} has no parent source component (parent: ${this.parent?.getString()})`
3560
3597
  );
3561
3598
  }
3562
3599
  db.source_port.update(this.source_port_id, {
3563
- source_component_id: this.parent?.source_component_id,
3600
+ source_component_id: parentWithSourceId.source_component_id,
3564
3601
  subcircuit_id: this.getSubcircuit()?.subcircuit_id
3565
3602
  });
3566
- this.source_component_id = this.parent?.source_component_id;
3603
+ this.source_component_id = parentWithSourceId.source_component_id;
3567
3604
  }
3568
3605
  doInitialPcbPortRender() {
3569
3606
  if (this.root?.pcbDisabled) return;
3570
3607
  const { db } = this.root;
3571
3608
  const { matchedComponents } = this;
3572
- if (!this.parent?.pcb_component_id) {
3609
+ const parentNormalComponent = this.getParentNormalComponent();
3610
+ const parentWithPcbComponentId = this.parent?.pcb_component_id ? this.parent : parentNormalComponent;
3611
+ if (!parentWithPcbComponentId?.pcb_component_id) {
3573
3612
  throw new Error(
3574
- `${this.getString()} has no parent pcb component, cannot render pcb_port (parent: ${this.parent?.getString()})`
3613
+ `${this.getString()} has no parent pcb component, cannot render pcb_port (parent: ${this.parent?.getString()}, parentNormalComponent: ${parentNormalComponent?.getString()})`
3575
3614
  );
3576
3615
  }
3577
3616
  const pcbMatches = matchedComponents.filter((c) => c.isPcbPrimitive);
@@ -3592,7 +3631,7 @@ var Port = class extends PrimitiveComponent2 {
3592
3631
  const subcircuit = this.getSubcircuit();
3593
3632
  const isBoardPinout = this._shouldIncludeInBoardPinout();
3594
3633
  const pcb_port = db.pcb_port.insert({
3595
- pcb_component_id: this.parent?.pcb_component_id,
3634
+ pcb_component_id: parentWithPcbComponentId.pcb_component_id,
3596
3635
  layers: this.getAvailablePcbLayers(),
3597
3636
  subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
3598
3637
  pcb_group_id: this.getGroup()?.pcb_group_id ?? void 0,
@@ -3628,10 +3667,12 @@ var Port = class extends PrimitiveComponent2 {
3628
3667
  }
3629
3668
  }
3630
3669
  if (!matchCenter) return;
3670
+ const parentNormalComponent = this.getParentNormalComponent();
3671
+ const parentWithPcbComponentId = this.parent?.pcb_component_id ? this.parent : parentNormalComponent;
3631
3672
  const subcircuit = this.getSubcircuit();
3632
3673
  const isBoardPinout = this._shouldIncludeInBoardPinout();
3633
3674
  const pcb_port = db.pcb_port.insert({
3634
- pcb_component_id: this.parent?.pcb_component_id,
3675
+ pcb_component_id: parentWithPcbComponentId?.pcb_component_id,
3635
3676
  layers: this.getAvailablePcbLayers(),
3636
3677
  subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
3637
3678
  pcb_group_id: this.getGroup()?.pcb_group_id ?? void 0,
@@ -3645,7 +3686,8 @@ var Port = class extends PrimitiveComponent2 {
3645
3686
  doInitialSchematicPortRender() {
3646
3687
  const { db } = this.root;
3647
3688
  const { _parsedProps: props } = this;
3648
- const container = this.getPrimitiveContainer();
3689
+ const { schX, schY } = props;
3690
+ const container = schX !== void 0 && schY !== void 0 ? this.getParentNormalComponent() : this.getPrimitiveContainer();
3649
3691
  if (!container) return;
3650
3692
  if (!this._hasSchematicPort()) return;
3651
3693
  const containerCenter = container._getGlobalSchematicPositionBeforeLayout();
@@ -3685,7 +3727,8 @@ var Port = class extends PrimitiveComponent2 {
3685
3727
  labelHints.push(portHint);
3686
3728
  }
3687
3729
  let bestDisplayPinLabel = void 0;
3688
- const showPinAliases = this.parent?.props?.showPinAliases;
3730
+ const parentNormalComponent = this.getParentNormalComponent();
3731
+ const showPinAliases = parentNormalComponent?.props?.showPinAliases;
3689
3732
  if (showPinAliases && labelHints.length > 0) {
3690
3733
  bestDisplayPinLabel = labelHints.join("/");
3691
3734
  } else if (labelHints.length > 0) {
@@ -3693,7 +3736,7 @@ var Port = class extends PrimitiveComponent2 {
3693
3736
  }
3694
3737
  const schematicPortInsertProps = {
3695
3738
  type: "schematic_port",
3696
- schematic_component_id: this.parent?.schematic_component_id,
3739
+ schematic_component_id: parentNormalComponent?.schematic_component_id,
3697
3740
  center: portCenter,
3698
3741
  source_port_id: this.source_port_id,
3699
3742
  facing_direction: this.facingDirection,
@@ -7683,7 +7726,6 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
7683
7726
  is_box_with_pins: false
7684
7727
  });
7685
7728
  this.schematic_component_id = schematic_component2.schematic_component_id;
7686
- this.add(symbolElement);
7687
7729
  }
7688
7730
  _doInitialSchematicComponentRenderWithSchematicBoxDimensions() {
7689
7731
  if (this.root?.schematicDisabled) return;
@@ -7902,6 +7944,15 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
7902
7944
  this.add(fpElm);
7903
7945
  }
7904
7946
  }
7947
+ const symElm = this.props.symbol;
7948
+ if (isValidElement(symElm)) {
7949
+ const hasSymbolChild = this.children.some(
7950
+ (c) => c.componentName === "Symbol"
7951
+ );
7952
+ if (!hasSymbolChild) {
7953
+ this.add(symElm);
7954
+ }
7955
+ }
7905
7956
  const cmElm = this.props.cadModel;
7906
7957
  if (isValidElement(cmElm)) {
7907
7958
  this._isCadModelChild = true;
@@ -8035,7 +8086,7 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
8035
8086
  for (const [pinName, target] of Object.entries(props.connections)) {
8036
8087
  const targets = Array.isArray(target) ? target : [target];
8037
8088
  for (const targetPath of targets) {
8038
- propsWithConnections.push(targetPath);
8089
+ propsWithConnections.push(String(targetPath));
8039
8090
  }
8040
8091
  }
8041
8092
  }
@@ -8285,8 +8336,8 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
8285
8336
  for (const targetPath of targets) {
8286
8337
  this.add(
8287
8338
  new Trace3({
8288
- from: `${this.getSubcircuitSelector()} > port.${pinName}`,
8289
- to: targetPath
8339
+ from: `.${this.name} > .${pinName}`,
8340
+ to: String(targetPath)
8290
8341
  })
8291
8342
  );
8292
8343
  }
@@ -16074,7 +16125,7 @@ import { identity as identity6 } from "transformation-matrix";
16074
16125
  var package_default = {
16075
16126
  name: "@tscircuit/core",
16076
16127
  type: "module",
16077
- version: "0.0.770",
16128
+ version: "0.0.772",
16078
16129
  types: "dist/index.d.ts",
16079
16130
  main: "dist/index.js",
16080
16131
  module: "dist/index.js",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.771",
4
+ "version": "0.0.773",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",