@tscircuit/core 0.0.1480 → 0.0.1482

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.
Files changed (2) hide show
  1. package/dist/index.js +125 -26
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -5145,6 +5145,14 @@ var Trace_doInitialSchematicTraceRender = (trace) => {
5145
5145
  const hasSheetLocalSchematicPortRepresentation = portsWithPosition.some(
5146
5146
  ({ port, schematic_port_id }) => port.schematic_port_id !== schematic_port_id
5147
5147
  );
5148
+ const connectedSchematicPorts = portsWithPosition.map(({ schematic_port_id }) => db.schematic_port.get(schematic_port_id)).filter((port) => Boolean(port));
5149
+ const [firstSchematicPort, secondSchematicPort] = connectedSchematicPorts;
5150
+ const firstIsInternalAndSecondOverlaps = firstSchematicPort?.is_internal_circuit_port && secondSchematicPort?.is_overlapping_internal_circuit_port;
5151
+ const secondIsInternalAndFirstOverlaps = secondSchematicPort?.is_internal_circuit_port && firstSchematicPort?.is_overlapping_internal_circuit_port;
5152
+ const isInternalCircuitPortMapping = connectedSchematicPorts.length === 2 && (firstIsInternalAndSecondOverlaps || secondIsInternalAndFirstOverlaps);
5153
+ if (isInternalCircuitPortMapping) {
5154
+ return;
5155
+ }
5148
5156
  const portPairKey = portIds.join(",");
5149
5157
  const board = trace.root?._getBoard();
5150
5158
  if (board?._connectedSchematicPortPairs) {
@@ -9716,6 +9724,62 @@ var getNetNameFromSourcePorts = (db, sourcePortIds) => {
9716
9724
  return [...new Set(portNames)].join("/");
9717
9725
  };
9718
9726
 
9727
+ // lib/components/primitive-components/Port/internalCircuitPortMapping.ts
9728
+ var getInternalCircuitAncestor = (port) => {
9729
+ let ancestor = port.parent;
9730
+ while (ancestor) {
9731
+ if (ancestor.componentName === "InternalCircuit") return ancestor;
9732
+ ancestor = ancestor.parent;
9733
+ }
9734
+ return null;
9735
+ };
9736
+ var isInternalCircuitPort = (port) => getInternalCircuitAncestor(port) !== null;
9737
+ var getConnectionTargets2 = (target) => {
9738
+ if (!target) return [];
9739
+ return typeof target === "string" ? [target] : [...target];
9740
+ };
9741
+ var getChipPortsMappedToInternalCircuitPort = (internalCircuitPort) => {
9742
+ const internalCircuit = getInternalCircuitAncestor(internalCircuitPort);
9743
+ const containingChip = internalCircuit?.parent;
9744
+ if (!internalCircuit || !containingChip) return [];
9745
+ const internalComponent = internalCircuitPort.getParentNormalComponent();
9746
+ const connections = internalComponent?._parsedProps?.connections;
9747
+ if (!connections) return [];
9748
+ const mappedChipPorts = [];
9749
+ for (const [portName, target] of Object.entries(connections)) {
9750
+ if (!internalCircuitPort.isMatchingAnyOf([portName])) continue;
9751
+ for (const targetSelector of getConnectionTargets2(target)) {
9752
+ const targetPort = internalCircuitPort.getSubcircuit().selectOne(targetSelector, { type: "port" });
9753
+ if (!targetPort) continue;
9754
+ if (targetPort.getParentNormalComponent() !== containingChip) continue;
9755
+ if (!mappedChipPorts.includes(targetPort)) {
9756
+ mappedChipPorts.push(targetPort);
9757
+ }
9758
+ }
9759
+ }
9760
+ return mappedChipPorts;
9761
+ };
9762
+ var isInternalCircuitPortMappedToChipPort = (port) => getChipPortsMappedToInternalCircuitPort(port).length > 0;
9763
+ var getInternalCircuitPortMappedToChipPort = (chipPort) => {
9764
+ const chipComponent = chipPort.getParentNormalComponent();
9765
+ if (!chipComponent) return null;
9766
+ const internalCircuit = chipComponent.children.find(
9767
+ (child) => child.componentName === "InternalCircuit"
9768
+ );
9769
+ if (!internalCircuit) return null;
9770
+ const mappedInternalCircuitPorts = internalCircuit.getDescendants().filter((component) => component.componentName === "Port").map((component) => component).filter(
9771
+ (internalCircuitPort) => getChipPortsMappedToInternalCircuitPort(internalCircuitPort).includes(
9772
+ chipPort
9773
+ )
9774
+ );
9775
+ if (mappedInternalCircuitPorts.length > 1) {
9776
+ throw new Error(
9777
+ `${chipPort.getString()} is mapped to multiple internal circuit ports: ${mappedInternalCircuitPorts.map((port) => port.getString()).join(", ")}. A chip port can overlap only one internal circuit port.`
9778
+ );
9779
+ }
9780
+ return mappedInternalCircuitPorts[0] ?? null;
9781
+ };
9782
+
9719
9783
  // lib/components/primitive-components/Port/Port.ts
9720
9784
  var Port = class extends PrimitiveComponent2 {
9721
9785
  source_port_id = null;
@@ -9835,6 +9899,10 @@ var Port = class extends PrimitiveComponent2 {
9835
9899
  * are rendered properly.
9836
9900
  */
9837
9901
  _hasSchematicPort() {
9902
+ const mappedInternalPort = getInternalCircuitPortMappedToChipPort(this);
9903
+ if (mappedInternalPort) {
9904
+ return mappedInternalPort._hasSchematicPort();
9905
+ }
9838
9906
  const { schX, schY } = this._parsedProps;
9839
9907
  if (schX !== void 0 && schY !== void 0) {
9840
9908
  return true;
@@ -9858,6 +9926,10 @@ var Port = class extends PrimitiveComponent2 {
9858
9926
  return false;
9859
9927
  }
9860
9928
  _getGlobalSchematicPositionBeforeLayout() {
9929
+ const mappedInternalPort = getInternalCircuitPortMappedToChipPort(this);
9930
+ if (mappedInternalPort) {
9931
+ return mappedInternalPort._getGlobalSchematicPositionBeforeLayout();
9932
+ }
9861
9933
  const { schX, schY } = this._parsedProps;
9862
9934
  if (schX !== void 0 && schY !== void 0) {
9863
9935
  return { x: schX, y: schY };
@@ -10164,16 +10236,21 @@ var Port = class extends PrimitiveComponent2 {
10164
10236
  if (collapsedAncestor && this.parent !== collapsedAncestor) return;
10165
10237
  const { db } = this.root;
10166
10238
  const { _parsedProps: props } = this;
10167
- const { schX, schY } = props;
10168
- const container = schX !== void 0 && schY !== void 0 ? this.getParentNormalComponent() : this.getPrimitiveContainer();
10239
+ const mappedInternalPort = getInternalCircuitPortMappedToChipPort(this);
10240
+ const schematicPlacementPort = mappedInternalPort ?? this;
10241
+ const schematicPlacementProps = schematicPlacementPort._parsedProps;
10242
+ const { schX, schY } = schematicPlacementProps;
10243
+ const container = schX !== void 0 && schY !== void 0 ? schematicPlacementPort.getParentNormalComponent() : schematicPlacementPort.getPrimitiveContainer();
10169
10244
  if (!container) return;
10170
10245
  if (!this._hasSchematicPort()) return;
10171
10246
  const containerCenter = container._getGlobalSchematicPositionBeforeLayout();
10172
- const portCenter = this._getGlobalSchematicPositionBeforeLayout();
10247
+ const portCenter = schematicPlacementPort._getGlobalSchematicPositionBeforeLayout();
10173
10248
  let localPortInfo = null;
10174
10249
  const containerDims = container._getSchematicBoxDimensions();
10175
- if (containerDims && props.pinNumber !== void 0) {
10176
- localPortInfo = containerDims.getPortPositionByPinNumber(props.pinNumber);
10250
+ if (containerDims && schematicPlacementProps.pinNumber !== void 0) {
10251
+ localPortInfo = containerDims.getPortPositionByPinNumber(
10252
+ schematicPlacementProps.pinNumber
10253
+ );
10177
10254
  }
10178
10255
  if (this.getSubcircuit().props._schDebugObjectsEnabled) {
10179
10256
  db.schematic_debug_object.insert({
@@ -10186,11 +10263,11 @@ var Port = class extends PrimitiveComponent2 {
10186
10263
  label: "obstacle"
10187
10264
  });
10188
10265
  }
10189
- const isExplicitCustomSymbolPort = schX !== void 0 && schY !== void 0 && !!this._getSymbolAncestor();
10266
+ const isExplicitCustomSymbolPort = schX !== void 0 && schY !== void 0 && !!schematicPlacementPort._getSymbolAncestor();
10190
10267
  if (!localPortInfo?.side) {
10191
10268
  this.facingDirection = getRelativeDirection(containerCenter, portCenter);
10192
- if (isExplicitCustomSymbolPort && props.direction) {
10193
- this.facingDirection = props.direction;
10269
+ if (isExplicitCustomSymbolPort && schematicPlacementProps.direction) {
10270
+ this.facingDirection = schematicPlacementProps.direction;
10194
10271
  }
10195
10272
  } else {
10196
10273
  this.facingDirection = {
@@ -10201,20 +10278,24 @@ var Port = class extends PrimitiveComponent2 {
10201
10278
  }[localPortInfo.side];
10202
10279
  }
10203
10280
  const bestDisplayPinLabel = this._getBestDisplayPinLabel();
10204
- const parentNormalComponent = this.getParentNormalComponent();
10205
- const sideOfComponent = localPortInfo?.side ?? (props.direction === "up" ? "top" : props.direction === "down" ? "bottom" : props.direction);
10281
+ const parentNormalComponent = schematicPlacementPort.getParentNormalComponent();
10282
+ const sideOfComponent = localPortInfo?.side ?? (schematicPlacementProps.direction === "up" ? "top" : schematicPlacementProps.direction === "down" ? "bottom" : schematicPlacementProps.direction);
10283
+ const isInternalPort = isInternalCircuitPort(this);
10284
+ const isMappedInternalPort = isInternalPort && isInternalCircuitPortMappedToChipPort(this);
10206
10285
  const schematicPortInsertProps = {
10207
10286
  type: "schematic_port",
10208
10287
  schematic_component_id: parentNormalComponent?.schematic_component_id,
10209
10288
  center: portCenter,
10210
10289
  source_port_id: this.source_port_id,
10211
10290
  facing_direction: this.facingDirection,
10212
- distance_from_component_edge: props.schStemLength ?? 0.4,
10291
+ distance_from_component_edge: schematicPlacementProps.schStemLength ?? 0.4,
10213
10292
  side_of_component: sideOfComponent,
10214
10293
  pin_number: props.pinNumber,
10215
10294
  true_ccw_index: localPortInfo?.trueIndex,
10216
10295
  display_pin_label: bestDisplayPinLabel,
10217
- is_connected: false,
10296
+ is_connected: mappedInternalPort !== null || isMappedInternalPort,
10297
+ is_internal_circuit_port: isInternalPort ? true : void 0,
10298
+ is_overlapping_internal_circuit_port: mappedInternalPort !== null ? true : void 0,
10218
10299
  schematic_sheet_id: this._resolveSchematicSheetId()
10219
10300
  };
10220
10301
  for (const attributes of this._getMatchingPinAttributes()) {
@@ -10227,8 +10308,8 @@ var Port = class extends PrimitiveComponent2 {
10227
10308
  }
10228
10309
  const schematic_port = db.schematic_port.insert(schematicPortInsertProps);
10229
10310
  this.schematic_port_id = schematic_port.schematic_port_id;
10230
- if (props.schStemLength !== void 0 && props.schStemLength !== 0) {
10231
- const { schStemLength, direction } = props;
10311
+ if (!mappedInternalPort && schematicPlacementProps.schStemLength !== void 0 && schematicPlacementProps.schStemLength !== 0) {
10312
+ const { schStemLength, direction } = schematicPlacementProps;
10232
10313
  let x2 = portCenter.x;
10233
10314
  let y2 = portCenter.y;
10234
10315
  if (direction === "right") x2 -= schStemLength;
@@ -10252,7 +10333,9 @@ var Port = class extends PrimitiveComponent2 {
10252
10333
  doInitialSchematicSymbolResize() {
10253
10334
  if (this.root?.schematicDisabled) return;
10254
10335
  if (!this.schematic_port_id) return;
10255
- const symbol = this._getSymbolAncestor();
10336
+ const mappedInternalPort = getInternalCircuitPortMappedToChipPort(this);
10337
+ const schematicPlacementPort = mappedInternalPort ?? this;
10338
+ const symbol = schematicPlacementPort._getSymbolAncestor();
10256
10339
  const transform = symbol?.getUserCoordinateToResizedSymbolTransform();
10257
10340
  if (!transform) return;
10258
10341
  const { db } = this.root;
@@ -19738,9 +19821,9 @@ function convertTreeToMatchPackInputProblem(tree, db, group, opts = {}) {
19738
19821
  const component = group.children.find(
19739
19822
  (groupChild) => groupChild.source_component_id === child.sourceComponent?.source_component_id
19740
19823
  );
19741
- const ports = db.schematic_port.list({
19824
+ const portsDefiningLayout = db.schematic_port.list({
19742
19825
  schematic_component_id: schematicComponent.schematic_component_id
19743
- });
19826
+ }).filter((port) => !port.is_overlapping_internal_circuit_port);
19744
19827
  let availableRotations = [
19745
19828
  ...DEFAULT_AVAILABLE_ROTATIONS
19746
19829
  ];
@@ -19760,7 +19843,10 @@ function convertTreeToMatchPackInputProblem(tree, db, group, opts = {}) {
19760
19843
  availableRotations = [0];
19761
19844
  }
19762
19845
  if (availableRotations.length === DEFAULT_AVAILABLE_ROTATIONS.length) {
19763
- const forcedRotation = getPowerGroundForcedRotation(db, ports);
19846
+ const forcedRotation = getPowerGroundForcedRotation(
19847
+ db,
19848
+ portsDefiningLayout
19849
+ );
19764
19850
  if (forcedRotation !== null) availableRotations = [forcedRotation];
19765
19851
  }
19766
19852
  const ccwRotationDegrees = availableRotations.length === 1 ? availableRotations[0] : 0;
@@ -19783,7 +19869,7 @@ function convertTreeToMatchPackInputProblem(tree, db, group, opts = {}) {
19783
19869
  }
19784
19870
  }
19785
19871
  };
19786
- for (const port of ports) {
19872
+ for (const port of portsDefiningLayout) {
19787
19873
  const sourcePort = db.source_port.get(port.source_port_id);
19788
19874
  if (!sourcePort) continue;
19789
19875
  const pinId = `${chipId}.${sourcePort.pin_number || sourcePort.name || port.schematic_port_id}`;
@@ -19832,10 +19918,10 @@ function convertTreeToMatchPackInputProblem(tree, db, group, opts = {}) {
19832
19918
  );
19833
19919
  const groupPins = [];
19834
19920
  for (const comp of groupComponents) {
19835
- const ports = db.schematic_port.list({
19921
+ const portsDefiningLayout = db.schematic_port.list({
19836
19922
  schematic_component_id: comp.schematic_component_id
19837
- });
19838
- for (const port of ports) {
19923
+ }).filter((port) => !port.is_overlapping_internal_circuit_port);
19924
+ for (const port of portsDefiningLayout) {
19839
19925
  const sourcePort = db.source_port.get(port.source_port_id);
19840
19926
  if (!sourcePort) continue;
19841
19927
  const pinId = `${groupId}.${sourcePort.pin_number || sourcePort.name || port.schematic_port_id}`;
@@ -20751,8 +20837,9 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
20751
20837
  });
20752
20838
  for (const schematicPort of schematicPorts) {
20753
20839
  const sourcePort = db.source_port.get(schematicPort.source_port_id);
20840
+ const portSourceComponent = sourcePort?.source_component_id ? db.source_component.get(sourcePort.source_component_id) : void 0;
20754
20841
  const selector = getSchematicPortSelector({
20755
- componentName: sourceComponent?.name ?? schematicComponent.schematic_component_id,
20842
+ componentName: portSourceComponent?.name ?? sourceComponent?.name ?? schematicComponent.schematic_component_id,
20756
20843
  schematicPort,
20757
20844
  sourcePort
20758
20845
  });
@@ -20833,6 +20920,7 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
20833
20920
  }
20834
20921
  const directConnections = [];
20835
20922
  const connectedPairKeys = /* @__PURE__ */ new Set();
20923
+ const internalCircuitPortIdsRepresentedByChipPorts = /* @__PURE__ */ new Set();
20836
20924
  const connKeysWithExplicitPortNetTraces = /* @__PURE__ */ new Set();
20837
20925
  for (const sourceTrace of tracesInScope) {
20838
20926
  if (sourceTrace?.subcircuit_connectivity_map_key && (sourceTrace.connected_source_port_ids?.length ?? 0) > 0 && (sourceTrace.connected_source_net_ids?.length ?? 0) > 0) {
@@ -20860,6 +20948,16 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
20860
20948
  }
20861
20949
  const portA = db.schematic_port.get(a);
20862
20950
  const portB = db.schematic_port.get(b);
20951
+ const portAIsInternalAndPortBOverlaps = portA?.is_internal_circuit_port && portB?.is_overlapping_internal_circuit_port;
20952
+ const portBIsInternalAndPortAOverlaps = portB?.is_internal_circuit_port && portA?.is_overlapping_internal_circuit_port;
20953
+ const isInternalCircuitPortMapping = portAIsInternalAndPortBOverlaps || portBIsInternalAndPortAOverlaps;
20954
+ if (portA && portB && isInternalCircuitPortMapping) {
20955
+ const internalCircuitPort = portA.is_internal_circuit_port ? portA : portB;
20956
+ internalCircuitPortIdsRepresentedByChipPorts.add(
20957
+ internalCircuitPort.schematic_port_id
20958
+ );
20959
+ continue;
20960
+ }
20863
20961
  let portDistance = 0;
20864
20962
  if (portA && portB) {
20865
20963
  portDistance = Math.sqrt(
@@ -20894,6 +20992,7 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
20894
20992
  }
20895
20993
  const connKeyToPinIds = /* @__PURE__ */ new Map();
20896
20994
  for (const [schId, srcPortId] of schPortIdToSourcePortId) {
20995
+ if (internalCircuitPortIdsRepresentedByChipPorts.has(schId)) continue;
20897
20996
  const sp = db.source_port.get(srcPortId);
20898
20997
  if (!sp?.subcircuit_connectivity_map_key) continue;
20899
20998
  const connKey = sp.subcircuit_connectivity_map_key;
@@ -22978,7 +23077,7 @@ function Group_getRoutingPhasePlans(group) {
22978
23077
  var package_default = {
22979
23078
  name: "@tscircuit/core",
22980
23079
  type: "module",
22981
- version: "0.0.1479",
23080
+ version: "0.0.1481",
22982
23081
  types: "dist/index.d.ts",
22983
23082
  main: "dist/index.js",
22984
23083
  module: "dist/index.js",
@@ -23011,7 +23110,7 @@ var package_default = {
23011
23110
  "@resvg/resvg-js": "^2.6.2",
23012
23111
  "@tscircuit/alphabet": "0.0.25",
23013
23112
  "@tscircuit/breakout-point-solver": "github:tscircuit/breakout-point-solver#bac9629",
23014
- "@tscircuit/capacity-autorouter": "^0.0.696",
23113
+ "@tscircuit/capacity-autorouter": "^0.0.710",
23015
23114
  "@tscircuit/checks": "0.0.145",
23016
23115
  "@tscircuit/circuit-json-util": "^0.0.97",
23017
23116
  "@tscircuit/common": "^0.0.20",
@@ -23042,7 +23141,7 @@ var package_default = {
23042
23141
  "bun-match-svg": "0.0.12",
23043
23142
  "calculate-elbow": "^0.0.12",
23044
23143
  "chokidar-cli": "^3.0.0",
23045
- "circuit-json": "^0.0.450",
23144
+ "circuit-json": "^0.0.451",
23046
23145
  "circuit-json-to-bpc": "^0.0.13",
23047
23146
  "circuit-json-to-connectivity-map": "^0.0.23",
23048
23147
  "circuit-json-to-gltf": "^0.0.107",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.1480",
4
+ "version": "0.0.1482",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -34,7 +34,7 @@
34
34
  "@resvg/resvg-js": "^2.6.2",
35
35
  "@tscircuit/alphabet": "0.0.25",
36
36
  "@tscircuit/breakout-point-solver": "github:tscircuit/breakout-point-solver#bac9629",
37
- "@tscircuit/capacity-autorouter": "^0.0.696",
37
+ "@tscircuit/capacity-autorouter": "^0.0.710",
38
38
  "@tscircuit/checks": "0.0.145",
39
39
  "@tscircuit/circuit-json-util": "^0.0.97",
40
40
  "@tscircuit/common": "^0.0.20",
@@ -65,7 +65,7 @@
65
65
  "bun-match-svg": "0.0.12",
66
66
  "calculate-elbow": "^0.0.12",
67
67
  "chokidar-cli": "^3.0.0",
68
- "circuit-json": "^0.0.450",
68
+ "circuit-json": "^0.0.451",
69
69
  "circuit-json-to-bpc": "^0.0.13",
70
70
  "circuit-json-to-connectivity-map": "^0.0.23",
71
71
  "circuit-json-to-gltf": "^0.0.107",