@tscircuit/core 0.0.829 → 0.0.830

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
@@ -1040,6 +1040,11 @@ declare class Port extends PrimitiveComponent<typeof portProps> {
1040
1040
  doInitialSourceParentAttachment(): void;
1041
1041
  doInitialPcbPortRender(): void;
1042
1042
  updatePcbPortRender(): void;
1043
+ /**
1044
+ * Get the best display label for this port based on port_hints
1045
+ * Filters out generic patterns and applies showPinAliases logic
1046
+ */
1047
+ _getBestDisplayPinLabel(): string | undefined;
1043
1048
  doInitialSchematicPortRender(): void;
1044
1049
  _getSubcircuitConnectivityKey(): string | undefined;
1045
1050
  _setPositionFromLayout(newCenter: {
@@ -1189,6 +1194,10 @@ declare class NormalComponent<ZodProps extends z.ZodType = any, PortNames extend
1189
1194
  * appear on a schematic box, e.g. for a pin header
1190
1195
  */
1191
1196
  _getSchematicPortArrangement(): SchematicPortArrangement | null;
1197
+ /**
1198
+ * Extract pin labels from ports using existing Port logic
1199
+ */
1200
+ _getPinLabelsFromPorts(): Record<string, string>;
1192
1201
  _getSchematicBoxDimensions(): SchematicBoxDimensions | null;
1193
1202
  getFootprinterString(): string | null;
1194
1203
  doInitialCadModelRender(): void;
package/dist/index.js CHANGED
@@ -3829,6 +3829,29 @@ var Port = class extends PrimitiveComponent2 {
3829
3829
  });
3830
3830
  this.pcb_port_id = pcb_port.pcb_port_id;
3831
3831
  }
3832
+ /**
3833
+ * Get the best display label for this port based on port_hints
3834
+ * Filters out generic patterns and applies showPinAliases logic
3835
+ */
3836
+ _getBestDisplayPinLabel() {
3837
+ const { db } = this.root;
3838
+ const sourcePort = db.source_port.get(this.source_port_id);
3839
+ const labelHints = [];
3840
+ for (const portHint of sourcePort?.port_hints ?? []) {
3841
+ if (portHint.match(/^(pin)?\d+$/)) continue;
3842
+ if (portHint.match(/^(left|right)/) && !sourcePort?.name.match(/^(left|right)/))
3843
+ continue;
3844
+ labelHints.push(portHint);
3845
+ }
3846
+ const parentNormalComponent = this.getParentNormalComponent();
3847
+ const showPinAliases = parentNormalComponent?.props?.showPinAliases;
3848
+ if (showPinAliases && labelHints.length > 0) {
3849
+ return labelHints.join("/");
3850
+ } else if (labelHints.length > 0) {
3851
+ return labelHints[0];
3852
+ }
3853
+ return void 0;
3854
+ }
3832
3855
  doInitialSchematicPortRender() {
3833
3856
  const { db } = this.root;
3834
3857
  const { _parsedProps: props } = this;
@@ -3864,22 +3887,8 @@ var Port = class extends PrimitiveComponent2 {
3864
3887
  bottom: "down"
3865
3888
  }[localPortInfo.side];
3866
3889
  }
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;
3890
+ const bestDisplayPinLabel = this._getBestDisplayPinLabel();
3876
3891
  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
3892
  const schematicPortInsertProps = {
3884
3893
  type: "schematic_port",
3885
3894
  schematic_component_id: parentNormalComponent?.schematic_component_id,
@@ -3980,6 +3989,7 @@ var getSizeOfSidesFromPortArrangement = (pa) => {
3980
3989
  };
3981
3990
 
3982
3991
  // lib/utils/schematic/getAllDimensionsForSchematicBox.ts
3992
+ var DEFAULT_SCHEMATIC_BOX_PADDING_MM = 0.4;
3983
3993
  function isExplicitPinMappingArrangement(arrangement) {
3984
3994
  const a = arrangement;
3985
3995
  return a.leftSide !== void 0 || a.rightSide !== void 0 || a.topSide !== void 0 || a.bottomSide !== void 0;
@@ -4157,12 +4167,24 @@ var getAllDimensionsForSchematicBox = (params) => {
4157
4167
  }
4158
4168
  truePinIndex++;
4159
4169
  }
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
4170
+ let resolvedSchWidth = params.schWidth;
4171
+ if (resolvedSchWidth === void 0) {
4172
+ resolvedSchWidth = Math.max(
4173
+ sideLengths.top + DEFAULT_SCHEMATIC_BOX_PADDING_MM,
4174
+ sideLengths.bottom + DEFAULT_SCHEMATIC_BOX_PADDING_MM
4165
4175
  );
4176
+ if (params.pinLabels) {
4177
+ const leftRightPins = orderedTruePorts.filter(
4178
+ (p) => p.side === "left" || p.side === "right"
4179
+ );
4180
+ const hasLeftRightLabels = leftRightPins.some(
4181
+ (p) => params.pinLabels?.[`pin${p.pinNumber}`] || params.pinLabels?.[p.pinNumber]
4182
+ );
4183
+ if (hasLeftRightLabels) {
4184
+ const MIN_WIDTH_FOR_SIDE_PINS = 0.5;
4185
+ resolvedSchWidth = Math.max(resolvedSchWidth, MIN_WIDTH_FOR_SIDE_PINS);
4186
+ }
4187
+ }
4166
4188
  const labelWidth = params.pinLabels ? Math.max(
4167
4189
  ...Object.values(params.pinLabels).map(
4168
4190
  (label) => label.length * 0.1
@@ -4170,19 +4192,19 @@ var getAllDimensionsForSchematicBox = (params) => {
4170
4192
  )
4171
4193
  ) : 0;
4172
4194
  const LABEL_PADDING = labelWidth > 0 ? 1.1 : 0;
4173
- schWidth = Math.max(schWidth, labelWidth + LABEL_PADDING);
4195
+ resolvedSchWidth = Math.max(resolvedSchWidth, labelWidth + LABEL_PADDING);
4174
4196
  }
4175
4197
  let schHeight = params.schHeight;
4176
4198
  if (!schHeight) {
4177
4199
  schHeight = Math.max(
4178
- sideLengths.left + params.schPinSpacing * 2,
4179
- sideLengths.right + params.schPinSpacing * 2
4200
+ sideLengths.left + DEFAULT_SCHEMATIC_BOX_PADDING_MM,
4201
+ sideLengths.right + DEFAULT_SCHEMATIC_BOX_PADDING_MM
4180
4202
  );
4181
4203
  }
4182
4204
  const trueEdgePositions = {
4183
4205
  // Top left corner
4184
4206
  left: {
4185
- x: -schWidth / 2 - portDistanceFromEdge,
4207
+ x: -resolvedSchWidth / 2 - portDistanceFromEdge,
4186
4208
  y: sideLengths.left / 2
4187
4209
  },
4188
4210
  // bottom left corner
@@ -4192,7 +4214,7 @@ var getAllDimensionsForSchematicBox = (params) => {
4192
4214
  },
4193
4215
  // bottom right corner
4194
4216
  right: {
4195
- x: schWidth / 2 + portDistanceFromEdge,
4217
+ x: resolvedSchWidth / 2 + portDistanceFromEdge,
4196
4218
  y: -sideLengths.right / 2
4197
4219
  },
4198
4220
  // top right corner
@@ -4228,11 +4250,11 @@ var getAllDimensionsForSchematicBox = (params) => {
4228
4250
  return port;
4229
4251
  },
4230
4252
  getSize() {
4231
- return { width: schWidth, height: schHeight };
4253
+ return { width: resolvedSchWidth, height: schHeight };
4232
4254
  },
4233
4255
  getSizeIncludingPins() {
4234
4256
  return {
4235
- width: schWidth + (sidePinCounts.leftSize || sidePinCounts.rightSize ? 0.4 : 0),
4257
+ width: resolvedSchWidth + (sidePinCounts.leftSize || sidePinCounts.rightSize ? 0.4 : 0),
4236
4258
  height: schHeight + (sidePinCounts.topSize || sidePinCounts.bottomSize ? 0.4 : 0)
4237
4259
  };
4238
4260
  },
@@ -8405,23 +8427,45 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
8405
8427
  _getSchematicPortArrangement() {
8406
8428
  return this._parsedProps.schPinArrangement ?? this._parsedProps.schPortArrangement;
8407
8429
  }
8430
+ /**
8431
+ * Extract pin labels from ports using existing Port logic
8432
+ */
8433
+ _getPinLabelsFromPorts() {
8434
+ const ports = this.selectAll("port");
8435
+ const pinLabels = {};
8436
+ for (const port of ports) {
8437
+ const pinNumber = port.props.pinNumber;
8438
+ if (pinNumber !== void 0) {
8439
+ const bestLabel = port._getBestDisplayPinLabel();
8440
+ if (bestLabel) {
8441
+ pinLabels[`pin${pinNumber}`] = bestLabel;
8442
+ }
8443
+ }
8444
+ }
8445
+ return pinLabels;
8446
+ }
8408
8447
  _getSchematicBoxDimensions() {
8409
8448
  if (this.getSchematicSymbol()) return null;
8410
8449
  if (!this.config.shouldRenderAsSchematicBox) return null;
8411
8450
  const { _parsedProps: props } = this;
8412
8451
  const pinCount = this._getPinCount();
8413
8452
  const pinSpacing = props.schPinSpacing ?? 0.2;
8453
+ const pinLabelsFromPorts = this._getPinLabelsFromPorts();
8454
+ const allPinLabels = {
8455
+ ...pinLabelsFromPorts,
8456
+ ...props.pinLabels
8457
+ };
8414
8458
  const dimensions = getAllDimensionsForSchematicBox({
8415
8459
  schWidth: props.schWidth,
8416
8460
  schHeight: props.schHeight,
8417
8461
  schPinSpacing: pinSpacing,
8418
8462
  numericSchPinStyle: getNumericSchPinStyle(
8419
8463
  props.schPinStyle,
8420
- props.pinLabels
8464
+ allPinLabels
8421
8465
  ),
8422
8466
  pinCount,
8423
8467
  schPortArrangement: this._getSchematicPortArrangement(),
8424
- pinLabels: props.pinLabels
8468
+ pinLabels: allPinLabels
8425
8469
  });
8426
8470
  return dimensions;
8427
8471
  }
@@ -17365,7 +17409,7 @@ import { identity as identity6 } from "transformation-matrix";
17365
17409
  var package_default = {
17366
17410
  name: "@tscircuit/core",
17367
17411
  type: "module",
17368
- version: "0.0.828",
17412
+ version: "0.0.829",
17369
17413
  types: "dist/index.d.ts",
17370
17414
  main: "dist/index.js",
17371
17415
  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.829",
4
+ "version": "0.0.830",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",