@tscircuit/core 0.0.1403 → 0.0.1405

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
@@ -319,6 +319,14 @@ type ReactSubtree = {
319
319
  component: NormalComponent;
320
320
  };
321
321
 
322
+ type VerticalPortSideConfiguration = {
323
+ direction?: "top-to-bottom" | "bottom-to-top";
324
+ pins: number[];
325
+ };
326
+ type HorizontalPortSideConfiguration = {
327
+ direction?: "left-to-right" | "right-to-left";
328
+ pins: number[];
329
+ };
322
330
  type SchematicBoxPortPositionWithMetadata = {
323
331
  trueIndex: number;
324
332
  pinNumber: number;
@@ -327,6 +335,26 @@ type SchematicBoxPortPositionWithMetadata = {
327
335
  x: number;
328
336
  y: number;
329
337
  };
338
+ type ExplicitPinMappingArrangement = {
339
+ leftSide?: VerticalPortSideConfiguration;
340
+ rightSide?: VerticalPortSideConfiguration;
341
+ topSide?: HorizontalPortSideConfiguration;
342
+ bottomSide?: HorizontalPortSideConfiguration;
343
+ };
344
+ /** @deprecated prefer SidePinCounts */
345
+ interface SideSizes {
346
+ leftSize?: number;
347
+ rightSize?: number;
348
+ topSize?: number;
349
+ bottomSize?: number;
350
+ }
351
+ interface SidePinCounts {
352
+ leftPinCount?: number;
353
+ rightPinCount?: number;
354
+ topPinCount?: number;
355
+ bottomPinCount?: number;
356
+ }
357
+ type PortArrangement = SideSizes | SidePinCounts | ExplicitPinMappingArrangement;
330
358
  interface SchematicBoxDimensions {
331
359
  pinCount: number;
332
360
  getPortPositionByPinNumber(pinNumber: number): SchematicBoxPortPositionWithMetadata | null;
@@ -2310,6 +2338,7 @@ declare class NormalComponent<ZodProps extends z.ZodType = any, PortNames extend
2310
2338
  * Extract pin labels from ports using existing Port logic
2311
2339
  */
2312
2340
  _getPinLabelsFromPorts(): Record<string, string>;
2341
+ _getImplicitSparseSchematicPortArrangement(pinCount: number): PortArrangement | undefined;
2313
2342
  _getSchematicBoxDimensions(): SchematicBoxDimensions | null;
2314
2343
  getFootprinterString(): string | null;
2315
2344
  doInitialCadModelRender(): void;
@@ -53092,10 +53121,10 @@ declare class Led extends NormalComponent<typeof ledProps, PolarizedPassivePorts
53092
53121
  _getSchematicSymbolDisplayValue(): string | undefined;
53093
53122
  getFootprinterString(): string | null;
53094
53123
  doInitialSourceRender(): void;
53095
- pos: Port;
53096
- anode: Port;
53097
- neg: Port;
53098
- cathode: Port;
53124
+ get pos(): Port;
53125
+ get anode(): Port;
53126
+ get neg(): Port;
53127
+ get cathode(): Port;
53099
53128
  }
53100
53129
 
53101
53130
  declare class PowerSource extends NormalComponent<typeof powerSourceProps, PolarizedPassivePorts> {
package/dist/index.js CHANGED
@@ -10980,7 +10980,6 @@ var createComponentsFromCircuitJson = ({
10980
10980
  };
10981
10981
 
10982
10982
  // lib/utils/filterPinLabels.ts
10983
- import { chipProps } from "@tscircuit/props";
10984
10983
  function filterPinLabels(pinLabels) {
10985
10984
  if (!pinLabels)
10986
10985
  return {
@@ -11010,18 +11009,8 @@ function filterPinLabels(pinLabels) {
11010
11009
  invalidPinLabelsMessages
11011
11010
  };
11012
11011
  }
11013
- function isValidPinLabel(pin, label) {
11014
- try {
11015
- const testProps = {
11016
- name: "test",
11017
- footprint: "test",
11018
- pinLabels: { [pin]: label }
11019
- };
11020
- const result = chipProps.safeParse(testProps);
11021
- return result.success;
11022
- } catch (error) {
11023
- return false;
11024
- }
11012
+ function isValidPinLabel(_pin, label) {
11013
+ return /^[A-Za-z0-9_]+$/.test(label);
11025
11014
  }
11026
11015
 
11027
11016
  // lib/utils/get-bounds-of-pcb-components.ts
@@ -11229,7 +11218,7 @@ var getAllDimensionsForSchematicBox = (params) => {
11229
11218
  currentDistanceFromEdge += pinStyle.topMargin;
11230
11219
  }
11231
11220
  orderedTruePorts.push({
11232
- trueIndex: truePinIndex,
11221
+ trueIndex: pinNumber - 1,
11233
11222
  pinNumber,
11234
11223
  side: "left",
11235
11224
  distanceFromOrthogonalEdge: currentDistanceFromEdge
@@ -11257,7 +11246,7 @@ var getAllDimensionsForSchematicBox = (params) => {
11257
11246
  currentDistanceFromEdge += pinStyle.leftMargin;
11258
11247
  }
11259
11248
  orderedTruePorts.push({
11260
- trueIndex: truePinIndex,
11249
+ trueIndex: pinNumber - 1,
11261
11250
  pinNumber,
11262
11251
  side: "bottom",
11263
11252
  distanceFromOrthogonalEdge: currentDistanceFromEdge
@@ -11285,7 +11274,7 @@ var getAllDimensionsForSchematicBox = (params) => {
11285
11274
  currentDistanceFromEdge += pinStyle.bottomMargin;
11286
11275
  }
11287
11276
  orderedTruePorts.push({
11288
- trueIndex: truePinIndex,
11277
+ trueIndex: pinNumber - 1,
11289
11278
  pinNumber,
11290
11279
  side: "right",
11291
11280
  distanceFromOrthogonalEdge: currentDistanceFromEdge
@@ -11313,7 +11302,7 @@ var getAllDimensionsForSchematicBox = (params) => {
11313
11302
  currentDistanceFromEdge += pinStyle.rightMargin;
11314
11303
  }
11315
11304
  orderedTruePorts.push({
11316
- trueIndex: truePinIndex,
11305
+ trueIndex: pinNumber - 1,
11317
11306
  pinNumber,
11318
11307
  side: "top",
11319
11308
  distanceFromOrthogonalEdge: currentDistanceFromEdge
@@ -13237,7 +13226,9 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
13237
13226
  for (const symPort of sym.ports) {
13238
13227
  const pinNumber = getPinNumberFromLabels(symPort.labels);
13239
13228
  if (!pinNumber) continue;
13240
- const existingPort = portsToCreate.find(
13229
+ const existingPort = this._getAllPortsFromChildren().find(
13230
+ (p) => p._parsedProps.pinNumber === Number(pinNumber)
13231
+ ) ?? portsToCreate.find(
13241
13232
  (p) => p._parsedProps.pinNumber === Number(pinNumber)
13242
13233
  );
13243
13234
  if (existingPort) {
@@ -13290,6 +13281,9 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
13290
13281
  const requiredPinCount = opts.pinCount ?? this._getPrimaryPinCount() ?? 0;
13291
13282
  for (let pn = 1; pn <= requiredPinCount; pn++) {
13292
13283
  if (portsToCreate.find((p) => p._parsedProps.pinNumber === pn)) continue;
13284
+ if (!schPortArrangement && pinLabelsFromProps && !Array.isArray(propsPinLabels) && !pinLabelsFromProps[`pin${pn}`]) {
13285
+ continue;
13286
+ }
13293
13287
  if (!schPortArrangement) {
13294
13288
  portsToCreate.push(
13295
13289
  new Port({
@@ -14148,6 +14142,24 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
14148
14142
  }
14149
14143
  return pinLabels;
14150
14144
  }
14145
+ _getImplicitSparseSchematicPortArrangement(pinCount) {
14146
+ const pinNumbers = Array.from(
14147
+ new Set(
14148
+ this._getAllPortsFromChildren().filter((port) => port._isPrimaryPort).map((port) => port._parsedProps.pinNumber).filter((pinNumber) => pinNumber !== void 0)
14149
+ )
14150
+ ).sort((a, b) => a - b);
14151
+ if (pinNumbers.length !== pinCount) return void 0;
14152
+ const hasSparsePinNumbers = pinNumbers.some(
14153
+ (pinNumber, index) => pinNumber !== index + 1
14154
+ );
14155
+ if (!hasSparsePinNumbers) return void 0;
14156
+ const rightSize = Math.floor(pinCount / 2);
14157
+ const leftSize = pinCount - rightSize;
14158
+ return {
14159
+ leftSide: { pins: pinNumbers.slice(0, leftSize) },
14160
+ rightSide: { pins: pinNumbers.slice(leftSize) }
14161
+ };
14162
+ }
14151
14163
  _getSchematicBoxDimensions() {
14152
14164
  if (this.getSchematicSymbol()) return null;
14153
14165
  if (!this.config.shouldRenderAsSchematicBox && !this._parsedProps?.showAsSchematicBox) {
@@ -14161,6 +14173,7 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
14161
14173
  ...pinLabelsFromPorts,
14162
14174
  ...props.pinLabels
14163
14175
  };
14176
+ const schPortArrangement = this._getSchematicPortArrangement() ?? this._getImplicitSparseSchematicPortArrangement(pinCount);
14164
14177
  const dimensions = getAllDimensionsForSchematicBox({
14165
14178
  schWidth: props.schWidth,
14166
14179
  schHeight: props.schHeight,
@@ -14170,7 +14183,7 @@ var NormalComponent3 = class extends PrimitiveComponent2 {
14170
14183
  allPinLabels
14171
14184
  ),
14172
14185
  pinCount,
14173
- schPortArrangement: this._getSchematicPortArrangement(),
14186
+ schPortArrangement,
14174
14187
  pinLabels: allPinLabels
14175
14188
  });
14176
14189
  return dimensions;
@@ -14856,7 +14869,7 @@ function inflateSourceCapacitor(sourceElm, inflatorContext) {
14856
14869
  }
14857
14870
 
14858
14871
  // lib/components/normal-components/Chip.ts
14859
- import { chipProps as chipProps2 } from "@tscircuit/props";
14872
+ import { chipProps } from "@tscircuit/props";
14860
14873
  import { pcb_component_invalid_layer_error as pcb_component_invalid_layer_error2 } from "circuit-json";
14861
14874
  var Chip = class extends NormalComponent3 {
14862
14875
  schematicBoxDimensions = null;
@@ -14866,7 +14879,7 @@ var Chip = class extends NormalComponent3 {
14866
14879
  get config() {
14867
14880
  return {
14868
14881
  componentName: "Chip",
14869
- zodProps: chipProps2,
14882
+ zodProps: chipProps,
14870
14883
  shouldRenderAsSchematicBox: true
14871
14884
  };
14872
14885
  }
@@ -24378,10 +24391,18 @@ var Led = class extends NormalComponent3 {
24378
24391
  };
24379
24392
  }
24380
24393
  initPorts() {
24394
+ const hasFootprintChild = this.children.some(
24395
+ (child) => child.componentName === "Footprint"
24396
+ );
24397
+ const footprint = this.resolveFootprint();
24398
+ const hasPinLabels = Boolean(this._resolvePinLabels());
24399
+ const shouldAddDefaultAliases = !hasPinLabels && !hasFootprintChild && (!footprint || isFootprinterString(footprint));
24381
24400
  super.initPorts({
24401
+ pinCount: 2,
24402
+ ignoreSymbolPorts: !hasPinLabels && !shouldAddDefaultAliases,
24382
24403
  additionalAliases: {
24383
- pin1: ["anode", "pos", "left"],
24384
- pin2: ["cathode", "neg", "right"]
24404
+ pin1: shouldAddDefaultAliases ? ["anode", "pos", "left"] : [],
24405
+ pin2: shouldAddDefaultAliases ? ["cathode", "neg", "right"] : []
24385
24406
  }
24386
24407
  });
24387
24408
  }
@@ -24411,10 +24432,18 @@ var Led = class extends NormalComponent3 {
24411
24432
  });
24412
24433
  this.source_component_id = source_component.source_component_id;
24413
24434
  }
24414
- pos = this.portMap.pin1;
24415
- anode = this.portMap.pin1;
24416
- neg = this.portMap.pin2;
24417
- cathode = this.portMap.pin2;
24435
+ get pos() {
24436
+ return this.portMap.pos;
24437
+ }
24438
+ get anode() {
24439
+ return this.portMap.anode;
24440
+ }
24441
+ get neg() {
24442
+ return this.portMap.neg;
24443
+ }
24444
+ get cathode() {
24445
+ return this.portMap.cathode;
24446
+ }
24418
24447
  };
24419
24448
 
24420
24449
  // lib/components/primitive-components/Group/Subcircuit/inflators/inflateSourceLed.ts
@@ -25300,7 +25329,7 @@ import { identity as identity5 } from "transformation-matrix";
25300
25329
  var package_default = {
25301
25330
  name: "@tscircuit/core",
25302
25331
  type: "module",
25303
- version: "0.0.1402",
25332
+ version: "0.0.1404",
25304
25333
  types: "dist/index.d.ts",
25305
25334
  main: "dist/index.js",
25306
25335
  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.1403",
4
+ "version": "0.0.1405",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",