@tscircuit/core 0.0.829 → 0.0.831

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
@@ -913,6 +913,7 @@ declare const portProps: z.ZodObject<{
913
913
  schX: z.ZodOptional<z.ZodNumber>;
914
914
  schY: z.ZodOptional<z.ZodNumber>;
915
915
  direction: z.ZodOptional<z.ZodEnum<["up", "down", "left", "right"]>>;
916
+ connectsTo: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
916
917
  }, "strip", z.ZodTypeAny, {
917
918
  name?: string | undefined;
918
919
  layer?: string | undefined;
@@ -922,6 +923,7 @@ declare const portProps: z.ZodObject<{
922
923
  schX?: number | undefined;
923
924
  schY?: number | undefined;
924
925
  direction?: "left" | "right" | "up" | "down" | undefined;
926
+ connectsTo?: string | string[] | undefined;
925
927
  }, {
926
928
  name?: string | undefined;
927
929
  layer?: string | undefined;
@@ -931,6 +933,7 @@ declare const portProps: z.ZodObject<{
931
933
  schX?: number | undefined;
932
934
  schY?: number | undefined;
933
935
  direction?: "left" | "right" | "up" | "down" | undefined;
936
+ connectsTo?: string | string[] | undefined;
934
937
  }>;
935
938
  declare class Port extends PrimitiveComponent<typeof portProps> {
936
939
  source_port_id: string | null;
@@ -951,6 +954,7 @@ declare class Port extends PrimitiveComponent<typeof portProps> {
951
954
  schX: z.ZodOptional<z.ZodNumber>;
952
955
  schY: z.ZodOptional<z.ZodNumber>;
953
956
  direction: z.ZodOptional<z.ZodEnum<["up", "down", "left", "right"]>>;
957
+ connectsTo: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
954
958
  }, "strip", z.ZodTypeAny, {
955
959
  name?: string | undefined;
956
960
  layer?: string | undefined;
@@ -960,6 +964,7 @@ declare class Port extends PrimitiveComponent<typeof portProps> {
960
964
  schX?: number | undefined;
961
965
  schY?: number | undefined;
962
966
  direction?: "left" | "right" | "up" | "down" | undefined;
967
+ connectsTo?: string | string[] | undefined;
963
968
  }, {
964
969
  name?: string | undefined;
965
970
  layer?: string | undefined;
@@ -969,11 +974,15 @@ declare class Port extends PrimitiveComponent<typeof portProps> {
969
974
  schX?: number | undefined;
970
975
  schY?: number | undefined;
971
976
  direction?: "left" | "right" | "up" | "down" | undefined;
977
+ connectsTo?: string | string[] | undefined;
972
978
  }>;
973
979
  };
974
980
  constructor(props: z.input<typeof portProps>, opts?: {
975
981
  originDescription?: string;
976
982
  });
983
+ isGroupPort(): boolean;
984
+ isComponentPort(): boolean;
985
+ _getConnectedPortsFromConnectsTo(): Port[];
977
986
  _isBoardPinoutFromAttributes(): boolean | undefined;
978
987
  _getGlobalPcbPositionBeforeLayout(): {
979
988
  x: number;
@@ -1040,6 +1049,11 @@ declare class Port extends PrimitiveComponent<typeof portProps> {
1040
1049
  doInitialSourceParentAttachment(): void;
1041
1050
  doInitialPcbPortRender(): void;
1042
1051
  updatePcbPortRender(): void;
1052
+ /**
1053
+ * Get the best display label for this port based on port_hints
1054
+ * Filters out generic patterns and applies showPinAliases logic
1055
+ */
1056
+ _getBestDisplayPinLabel(): string | undefined;
1043
1057
  doInitialSchematicPortRender(): void;
1044
1058
  _getSubcircuitConnectivityKey(): string | undefined;
1045
1059
  _setPositionFromLayout(newCenter: {
@@ -1189,6 +1203,10 @@ declare class NormalComponent<ZodProps extends z.ZodType = any, PortNames extend
1189
1203
  * appear on a schematic box, e.g. for a pin header
1190
1204
  */
1191
1205
  _getSchematicPortArrangement(): SchematicPortArrangement | null;
1206
+ /**
1207
+ * Extract pin labels from ports using existing Port logic
1208
+ */
1209
+ _getPinLabelsFromPorts(): Record<string, string>;
1192
1210
  _getSchematicBoxDimensions(): SchematicBoxDimensions | null;
1193
1211
  getFootprinterString(): string | null;
1194
1212
  doInitialCadModelRender(): void;
package/dist/index.js CHANGED
@@ -3481,7 +3481,8 @@ var portProps = z6.object({
3481
3481
  layers: z6.array(z6.string()).optional(),
3482
3482
  schX: z6.number().optional(),
3483
3483
  schY: z6.number().optional(),
3484
- direction: z6.enum(["up", "down", "left", "right"]).optional()
3484
+ direction: z6.enum(["up", "down", "left", "right"]).optional(),
3485
+ connectsTo: z6.union([z6.string(), z6.array(z6.string())]).optional()
3485
3486
  });
3486
3487
  var Port = class extends PrimitiveComponent2 {
3487
3488
  source_port_id = null;
@@ -3509,6 +3510,28 @@ var Port = class extends PrimitiveComponent2 {
3509
3510
  }
3510
3511
  this.matchedComponents = [];
3511
3512
  }
3513
+ isGroupPort() {
3514
+ return this.parent?.componentName === "Group";
3515
+ }
3516
+ isComponentPort() {
3517
+ return !this.isGroupPort();
3518
+ }
3519
+ _getConnectedPortsFromConnectsTo() {
3520
+ const { _parsedProps: props } = this;
3521
+ const connectsTo = props.connectsTo;
3522
+ if (!connectsTo) return [];
3523
+ const connectedPorts = [];
3524
+ const connectsToArray = Array.isArray(connectsTo) ? connectsTo : [connectsTo];
3525
+ for (const connection of connectsToArray) {
3526
+ const port = this.getSubcircuit().selectOne(connection, {
3527
+ type: "port"
3528
+ });
3529
+ if (port) {
3530
+ connectedPorts.push(port);
3531
+ }
3532
+ }
3533
+ return connectedPorts;
3534
+ }
3512
3535
  _isBoardPinoutFromAttributes() {
3513
3536
  const parent = this.parent;
3514
3537
  if (parent?._parsedProps?.pinAttributes) {
@@ -3737,6 +3760,13 @@ var Port = class extends PrimitiveComponent2 {
3737
3760
  const { db } = this.root;
3738
3761
  const parentNormalComponent = this.getParentNormalComponent();
3739
3762
  const parentWithSourceId = this.parent?.source_component_id ? this.parent : parentNormalComponent;
3763
+ if (this.isGroupPort()) {
3764
+ db.source_port.update(this.source_port_id, {
3765
+ source_component_id: null,
3766
+ subcircuit_id: this.getSubcircuit()?.subcircuit_id
3767
+ });
3768
+ return;
3769
+ }
3740
3770
  if (!parentWithSourceId?.source_component_id) {
3741
3771
  throw new Error(
3742
3772
  `${this.getString()} has no parent source component (parent: ${this.parent?.getString()})`
@@ -3752,6 +3782,30 @@ var Port = class extends PrimitiveComponent2 {
3752
3782
  if (this.root?.pcbDisabled) return;
3753
3783
  const { db } = this.root;
3754
3784
  const { matchedComponents } = this;
3785
+ if (this.isGroupPort()) {
3786
+ const connectedPorts = this._getConnectedPortsFromConnectsTo();
3787
+ if (connectedPorts.length === 0) {
3788
+ return;
3789
+ }
3790
+ const connectedPort = connectedPorts[0];
3791
+ if (!connectedPort.pcb_port_id) {
3792
+ return;
3793
+ }
3794
+ const connectedPcbPort = db.pcb_port.get(connectedPort.pcb_port_id);
3795
+ const matchCenter2 = { x: connectedPcbPort.x, y: connectedPcbPort.y };
3796
+ const subcircuit = this.getSubcircuit();
3797
+ const pcb_port = db.pcb_port.insert({
3798
+ pcb_component_id: void 0,
3799
+ layers: connectedPort.getAvailablePcbLayers(),
3800
+ subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
3801
+ pcb_group_id: this.getGroup()?.pcb_group_id ?? void 0,
3802
+ ...matchCenter2,
3803
+ source_port_id: this.source_port_id,
3804
+ is_board_pinout: false
3805
+ });
3806
+ this.pcb_port_id = pcb_port.pcb_port_id;
3807
+ return;
3808
+ }
3755
3809
  const parentNormalComponent = this.getParentNormalComponent();
3756
3810
  const parentWithPcbComponentId = this.parent?.pcb_component_id ? this.parent : parentNormalComponent;
3757
3811
  if (!parentWithPcbComponentId?.pcb_component_id) {
@@ -3798,6 +3852,26 @@ var Port = class extends PrimitiveComponent2 {
3798
3852
  if (this.root?.pcbDisabled) return;
3799
3853
  const { db } = this.root;
3800
3854
  if (this.pcb_port_id) return;
3855
+ if (this.isGroupPort()) {
3856
+ const connectedPorts = this._getConnectedPortsFromConnectsTo();
3857
+ if (connectedPorts.length === 0) return;
3858
+ const connectedPort = connectedPorts[0];
3859
+ if (!connectedPort.pcb_port_id) return;
3860
+ const connectedPcbPort = db.pcb_port.get(connectedPort.pcb_port_id);
3861
+ const matchCenter2 = { x: connectedPcbPort.x, y: connectedPcbPort.y };
3862
+ const subcircuit2 = this.getSubcircuit();
3863
+ const pcb_port2 = db.pcb_port.insert({
3864
+ pcb_component_id: void 0,
3865
+ layers: connectedPort.getAvailablePcbLayers(),
3866
+ subcircuit_id: subcircuit2?.subcircuit_id ?? void 0,
3867
+ pcb_group_id: this.getGroup()?.pcb_group_id ?? void 0,
3868
+ ...matchCenter2,
3869
+ source_port_id: this.source_port_id,
3870
+ is_board_pinout: false
3871
+ });
3872
+ this.pcb_port_id = pcb_port2.pcb_port_id;
3873
+ return;
3874
+ }
3801
3875
  const pcbMatches = this.matchedComponents.filter((c) => c.isPcbPrimitive);
3802
3876
  if (pcbMatches.length === 0) return;
3803
3877
  let matchCenter = null;
@@ -3829,6 +3903,29 @@ var Port = class extends PrimitiveComponent2 {
3829
3903
  });
3830
3904
  this.pcb_port_id = pcb_port.pcb_port_id;
3831
3905
  }
3906
+ /**
3907
+ * Get the best display label for this port based on port_hints
3908
+ * Filters out generic patterns and applies showPinAliases logic
3909
+ */
3910
+ _getBestDisplayPinLabel() {
3911
+ const { db } = this.root;
3912
+ const sourcePort = db.source_port.get(this.source_port_id);
3913
+ const labelHints = [];
3914
+ for (const portHint of sourcePort?.port_hints ?? []) {
3915
+ if (portHint.match(/^(pin)?\d+$/)) continue;
3916
+ if (portHint.match(/^(left|right)/) && !sourcePort?.name.match(/^(left|right)/))
3917
+ continue;
3918
+ labelHints.push(portHint);
3919
+ }
3920
+ const parentNormalComponent = this.getParentNormalComponent();
3921
+ const showPinAliases = parentNormalComponent?.props?.showPinAliases;
3922
+ if (showPinAliases && labelHints.length > 0) {
3923
+ return labelHints.join("/");
3924
+ } else if (labelHints.length > 0) {
3925
+ return labelHints[0];
3926
+ }
3927
+ return void 0;
3928
+ }
3832
3929
  doInitialSchematicPortRender() {
3833
3930
  const { db } = this.root;
3834
3931
  const { _parsedProps: props } = this;
@@ -3864,22 +3961,8 @@ var Port = class extends PrimitiveComponent2 {
3864
3961
  bottom: "down"
3865
3962
  }[localPortInfo.side];
3866
3963
  }
3867
- const sourcePort = db.source_port.get(this.source_port_id);
3868
- const labelHints = [];
3869
- for (const portHint of sourcePort?.port_hints ?? []) {
3870
- if (portHint.match(/^(pin)?\d+$/)) continue;
3871
- if (portHint.match(/^(left|right)/) && !sourcePort?.name.match(/^(left|right)/))
3872
- continue;
3873
- labelHints.push(portHint);
3874
- }
3875
- let bestDisplayPinLabel = void 0;
3964
+ const bestDisplayPinLabel = this._getBestDisplayPinLabel();
3876
3965
  const parentNormalComponent = this.getParentNormalComponent();
3877
- const showPinAliases = parentNormalComponent?.props?.showPinAliases;
3878
- if (showPinAliases && labelHints.length > 0) {
3879
- bestDisplayPinLabel = labelHints.join("/");
3880
- } else if (labelHints.length > 0) {
3881
- bestDisplayPinLabel = labelHints[0];
3882
- }
3883
3966
  const schematicPortInsertProps = {
3884
3967
  type: "schematic_port",
3885
3968
  schematic_component_id: parentNormalComponent?.schematic_component_id,
@@ -3980,6 +4063,7 @@ var getSizeOfSidesFromPortArrangement = (pa) => {
3980
4063
  };
3981
4064
 
3982
4065
  // lib/utils/schematic/getAllDimensionsForSchematicBox.ts
4066
+ var DEFAULT_SCHEMATIC_BOX_PADDING_MM = 0.4;
3983
4067
  function isExplicitPinMappingArrangement(arrangement) {
3984
4068
  const a = arrangement;
3985
4069
  return a.leftSide !== void 0 || a.rightSide !== void 0 || a.topSide !== void 0 || a.bottomSide !== void 0;
@@ -4157,12 +4241,24 @@ var getAllDimensionsForSchematicBox = (params) => {
4157
4241
  }
4158
4242
  truePinIndex++;
4159
4243
  }
4160
- let schWidth = params.schWidth;
4161
- if (schWidth === void 0) {
4162
- schWidth = Math.max(
4163
- sideLengths.top + params.schPinSpacing * 2,
4164
- sideLengths.bottom + params.schPinSpacing * 2
4244
+ let resolvedSchWidth = params.schWidth;
4245
+ if (resolvedSchWidth === void 0) {
4246
+ resolvedSchWidth = Math.max(
4247
+ sideLengths.top + DEFAULT_SCHEMATIC_BOX_PADDING_MM,
4248
+ sideLengths.bottom + DEFAULT_SCHEMATIC_BOX_PADDING_MM
4165
4249
  );
4250
+ if (params.pinLabels) {
4251
+ const leftRightPins = orderedTruePorts.filter(
4252
+ (p) => p.side === "left" || p.side === "right"
4253
+ );
4254
+ const hasLeftRightLabels = leftRightPins.some(
4255
+ (p) => params.pinLabels?.[`pin${p.pinNumber}`] || params.pinLabels?.[p.pinNumber]
4256
+ );
4257
+ if (hasLeftRightLabels) {
4258
+ const MIN_WIDTH_FOR_SIDE_PINS = 0.5;
4259
+ resolvedSchWidth = Math.max(resolvedSchWidth, MIN_WIDTH_FOR_SIDE_PINS);
4260
+ }
4261
+ }
4166
4262
  const labelWidth = params.pinLabels ? Math.max(
4167
4263
  ...Object.values(params.pinLabels).map(
4168
4264
  (label) => label.length * 0.1
@@ -4170,19 +4266,19 @@ var getAllDimensionsForSchematicBox = (params) => {
4170
4266
  )
4171
4267
  ) : 0;
4172
4268
  const LABEL_PADDING = labelWidth > 0 ? 1.1 : 0;
4173
- schWidth = Math.max(schWidth, labelWidth + LABEL_PADDING);
4269
+ resolvedSchWidth = Math.max(resolvedSchWidth, labelWidth + LABEL_PADDING);
4174
4270
  }
4175
4271
  let schHeight = params.schHeight;
4176
4272
  if (!schHeight) {
4177
4273
  schHeight = Math.max(
4178
- sideLengths.left + params.schPinSpacing * 2,
4179
- sideLengths.right + params.schPinSpacing * 2
4274
+ sideLengths.left + DEFAULT_SCHEMATIC_BOX_PADDING_MM,
4275
+ sideLengths.right + DEFAULT_SCHEMATIC_BOX_PADDING_MM
4180
4276
  );
4181
4277
  }
4182
4278
  const trueEdgePositions = {
4183
4279
  // Top left corner
4184
4280
  left: {
4185
- x: -schWidth / 2 - portDistanceFromEdge,
4281
+ x: -resolvedSchWidth / 2 - portDistanceFromEdge,
4186
4282
  y: sideLengths.left / 2
4187
4283
  },
4188
4284
  // bottom left corner
@@ -4192,7 +4288,7 @@ var getAllDimensionsForSchematicBox = (params) => {
4192
4288
  },
4193
4289
  // bottom right corner
4194
4290
  right: {
4195
- x: schWidth / 2 + portDistanceFromEdge,
4291
+ x: resolvedSchWidth / 2 + portDistanceFromEdge,
4196
4292
  y: -sideLengths.right / 2
4197
4293
  },
4198
4294
  // top right corner
@@ -4228,11 +4324,11 @@ var getAllDimensionsForSchematicBox = (params) => {
4228
4324
  return port;
4229
4325
  },
4230
4326
  getSize() {
4231
- return { width: schWidth, height: schHeight };
4327
+ return { width: resolvedSchWidth, height: schHeight };
4232
4328
  },
4233
4329
  getSizeIncludingPins() {
4234
4330
  return {
4235
- width: schWidth + (sidePinCounts.leftSize || sidePinCounts.rightSize ? 0.4 : 0),
4331
+ width: resolvedSchWidth + (sidePinCounts.leftSize || sidePinCounts.rightSize ? 0.4 : 0),
4236
4332
  height: schHeight + (sidePinCounts.topSize || sidePinCounts.bottomSize ? 0.4 : 0)
4237
4333
  };
4238
4334
  },
@@ -8405,23 +8501,45 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
8405
8501
  _getSchematicPortArrangement() {
8406
8502
  return this._parsedProps.schPinArrangement ?? this._parsedProps.schPortArrangement;
8407
8503
  }
8504
+ /**
8505
+ * Extract pin labels from ports using existing Port logic
8506
+ */
8507
+ _getPinLabelsFromPorts() {
8508
+ const ports = this.selectAll("port");
8509
+ const pinLabels = {};
8510
+ for (const port of ports) {
8511
+ const pinNumber = port.props.pinNumber;
8512
+ if (pinNumber !== void 0) {
8513
+ const bestLabel = port._getBestDisplayPinLabel();
8514
+ if (bestLabel) {
8515
+ pinLabels[`pin${pinNumber}`] = bestLabel;
8516
+ }
8517
+ }
8518
+ }
8519
+ return pinLabels;
8520
+ }
8408
8521
  _getSchematicBoxDimensions() {
8409
8522
  if (this.getSchematicSymbol()) return null;
8410
8523
  if (!this.config.shouldRenderAsSchematicBox) return null;
8411
8524
  const { _parsedProps: props } = this;
8412
8525
  const pinCount = this._getPinCount();
8413
8526
  const pinSpacing = props.schPinSpacing ?? 0.2;
8527
+ const pinLabelsFromPorts = this._getPinLabelsFromPorts();
8528
+ const allPinLabels = {
8529
+ ...pinLabelsFromPorts,
8530
+ ...props.pinLabels
8531
+ };
8414
8532
  const dimensions = getAllDimensionsForSchematicBox({
8415
8533
  schWidth: props.schWidth,
8416
8534
  schHeight: props.schHeight,
8417
8535
  schPinSpacing: pinSpacing,
8418
8536
  numericSchPinStyle: getNumericSchPinStyle(
8419
8537
  props.schPinStyle,
8420
- props.pinLabels
8538
+ allPinLabels
8421
8539
  ),
8422
8540
  pinCount,
8423
8541
  schPortArrangement: this._getSchematicPortArrangement(),
8424
- pinLabels: props.pinLabels
8542
+ pinLabels: allPinLabels
8425
8543
  });
8426
8544
  return dimensions;
8427
8545
  }
@@ -17365,7 +17483,7 @@ import { identity as identity6 } from "transformation-matrix";
17365
17483
  var package_default = {
17366
17484
  name: "@tscircuit/core",
17367
17485
  type: "module",
17368
- version: "0.0.828",
17486
+ version: "0.0.830",
17369
17487
  types: "dist/index.d.ts",
17370
17488
  main: "dist/index.js",
17371
17489
  module: "dist/index.js",
@@ -17420,7 +17538,7 @@ var package_default = {
17420
17538
  "bun-match-svg": "0.0.12",
17421
17539
  "calculate-elbow": "^0.0.12",
17422
17540
  "chokidar-cli": "^3.0.0",
17423
- "circuit-json": "^0.0.291",
17541
+ "circuit-json": "^0.0.295",
17424
17542
  "circuit-json-to-bpc": "^0.0.13",
17425
17543
  "circuit-json-to-connectivity-map": "^0.0.22",
17426
17544
  "circuit-json-to-gltf": "^0.0.31",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.829",
4
+ "version": "0.0.831",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -56,7 +56,7 @@
56
56
  "bun-match-svg": "0.0.12",
57
57
  "calculate-elbow": "^0.0.12",
58
58
  "chokidar-cli": "^3.0.0",
59
- "circuit-json": "^0.0.291",
59
+ "circuit-json": "^0.0.295",
60
60
  "circuit-json-to-bpc": "^0.0.13",
61
61
  "circuit-json-to-connectivity-map": "^0.0.22",
62
62
  "circuit-json-to-gltf": "^0.0.31",