@tscircuit/core 0.0.1481 → 0.0.1483

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 +64 -12
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -9709,19 +9709,63 @@ function Port_tryRenderGroupPcbPort(port) {
9709
9709
  }
9710
9710
 
9711
9711
  // lib/utils/schematic/getSourcePortNetLabelText.ts
9712
+ var compareNamesAlphanumerically = (firstName, secondName) => firstName.localeCompare(secondName, void 0, {
9713
+ numeric: true,
9714
+ sensitivity: "base"
9715
+ });
9716
+ var getSourcePortOwnerName = (db, sourcePort) => {
9717
+ const sourceComponent = sourcePort.source_component_id ? db.source_component.get(sourcePort.source_component_id) : void 0;
9718
+ const sourceGroup = !sourceComponent ? db.source_group.list().find((group) => group.subcircuit_id === sourcePort.subcircuit_id) : void 0;
9719
+ return sourceComponent?.name ?? sourceGroup?.name;
9720
+ };
9712
9721
  var getSourcePortNetLabelText = (db, sourcePortId) => {
9713
9722
  const sourcePort = db.source_port.get(sourcePortId);
9714
9723
  if (!sourcePort?.name) return void 0;
9715
- const sourceComponent = sourcePort.source_component_id ? db.source_component.get(sourcePort.source_component_id) : void 0;
9716
- const sourceGroup = !sourceComponent ? db.source_group.list().find((group) => group.subcircuit_id === sourcePort.subcircuit_id) : void 0;
9717
- const ownerName = sourceComponent?.name ?? sourceGroup?.name;
9724
+ const ownerName = getSourcePortOwnerName(db, sourcePort);
9718
9725
  if (!ownerName) return void 0;
9719
9726
  return `${ownerName}_${sourcePort.name}`;
9720
9727
  };
9721
9728
  var getNetNameFromSourcePorts = (db, sourcePortIds) => {
9722
- const portNames = sourcePortIds.map((sourcePortId) => getSourcePortNetLabelText(db, sourcePortId)).filter((name) => Boolean(name));
9723
- if (portNames.length === 0) return void 0;
9724
- return [...new Set(portNames)].join("/");
9729
+ const sourcePorts = sourcePortIds.map((sourcePortId) => db.source_port.get(sourcePortId)).filter((sourcePort) => Boolean(sourcePort));
9730
+ if (sourcePorts.length === 0) return void 0;
9731
+ const pinCountByComponentId = /* @__PURE__ */ new Map();
9732
+ for (const sourcePort of db.source_port.list()) {
9733
+ if (!sourcePort.source_component_id) continue;
9734
+ pinCountByComponentId.set(
9735
+ sourcePort.source_component_id,
9736
+ (pinCountByComponentId.get(sourcePort.source_component_id) ?? 0) + 1
9737
+ );
9738
+ }
9739
+ const candidates = sourcePorts.map((sourcePort) => {
9740
+ const ownerName = getSourcePortOwnerName(db, sourcePort);
9741
+ if (!ownerName || !sourcePort.name) return null;
9742
+ return {
9743
+ sourcePort,
9744
+ ownerName,
9745
+ label: `${ownerName}_${sourcePort.name}`,
9746
+ ownerPinCount: sourcePort.source_component_id ? pinCountByComponentId.get(sourcePort.source_component_id) ?? 0 : 0
9747
+ };
9748
+ }).filter(
9749
+ (candidate) => Boolean(candidate)
9750
+ );
9751
+ candidates.sort((firstCandidate, secondCandidate) => {
9752
+ const pinCountDifference = secondCandidate.ownerPinCount - firstCandidate.ownerPinCount;
9753
+ if (pinCountDifference !== 0) return pinCountDifference;
9754
+ const ownerNameDifference = compareNamesAlphanumerically(
9755
+ firstCandidate.ownerName,
9756
+ secondCandidate.ownerName
9757
+ );
9758
+ if (ownerNameDifference !== 0) return ownerNameDifference;
9759
+ const firstPinNumber = firstCandidate.sourcePort.pin_number ?? Number.POSITIVE_INFINITY;
9760
+ const secondPinNumber = secondCandidate.sourcePort.pin_number ?? Number.POSITIVE_INFINITY;
9761
+ const pinNumberDifference = firstPinNumber - secondPinNumber;
9762
+ if (pinNumberDifference !== 0) return pinNumberDifference;
9763
+ return compareNamesAlphanumerically(
9764
+ firstCandidate.sourcePort.name,
9765
+ secondCandidate.sourcePort.name
9766
+ );
9767
+ });
9768
+ return candidates[0]?.label;
9725
9769
  };
9726
9770
 
9727
9771
  // lib/components/primitive-components/Port/internalCircuitPortMapping.ts
@@ -21760,8 +21804,12 @@ var getNetNameFromPorts = (ports) => {
21760
21804
  }
21761
21805
  }
21762
21806
  }
21763
- const netName = ports.map((p) => p._getNetLabelText()).join("/");
21764
- return { name: netName, wasAssignedDisplayLabel: false };
21807
+ const db = ports.find((port) => port.root)?.root?.db;
21808
+ const sourcePortIds = ports.map((port) => port.source_port_id).filter((sourcePortId) => Boolean(sourcePortId));
21809
+ const netName = db ? getNetNameFromSourcePorts(db, sourcePortIds) : ports.map((port) => port._getNetLabelText()).filter((name) => Boolean(name)).sort(
21810
+ (a, b) => a.localeCompare(b, void 0, { numeric: true, sensitivity: "base" })
21811
+ )[0];
21812
+ return { name: netName ?? "", wasAssignedDisplayLabel: false };
21765
21813
  };
21766
21814
 
21767
21815
  // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/getNetLabelTextBounds.ts
@@ -22043,9 +22091,13 @@ var insertNetLabelsForPortsMissingTrace = ({
22043
22091
  if (wasAssignedDisplayLabel) {
22044
22092
  assignedPortNetLabelText = resolvedPortNetLabelText;
22045
22093
  }
22046
- const implicitPortLabelText = connectedSourcePortIdsForKey.map((sourcePortId) => getSourcePortNetLabelText(db, sourcePortId)).filter((label) => Boolean(label)).join("/");
22094
+ const fallbackPortNetLabelText = wasAssignedDisplayLabel ? void 0 : resolvedPortNetLabelText || void 0;
22095
+ const implicitPortLabelText = getNetNameFromSourcePorts(
22096
+ db,
22097
+ connectedSourcePortIdsForKey
22098
+ );
22047
22099
  const directCrossSubcircuitConnectionLabelText = getDirectCrossSubcircuitConnectionLabelText(db, srcPortId);
22048
- const text = sourceNet?.name || sourceNet?.source_net_id || assignedPortNetLabelText || directCrossSubcircuitConnectionLabelText || implicitPortLabelText || connKey;
22100
+ const text = sourceNet?.name || sourceNet?.source_net_id || assignedPortNetLabelText || directCrossSubcircuitConnectionLabelText || fallbackPortNetLabelText || implicitPortLabelText || connKey;
22049
22101
  const isCollapsedBoxPort = schComponent?.is_box_with_pins && sourcePort && !sourcePort.source_component_id;
22050
22102
  const hasExternalTrace = db.source_trace.list().some(
22051
22103
  (trace) => trace.connected_source_port_ids.includes(srcPortId) && trace.subcircuit_id !== sourcePort?.subcircuit_id
@@ -23077,7 +23129,7 @@ function Group_getRoutingPhasePlans(group) {
23077
23129
  var package_default = {
23078
23130
  name: "@tscircuit/core",
23079
23131
  type: "module",
23080
- version: "0.0.1480",
23132
+ version: "0.0.1482",
23081
23133
  types: "dist/index.d.ts",
23082
23134
  main: "dist/index.js",
23083
23135
  module: "dist/index.js",
@@ -23110,7 +23162,7 @@ var package_default = {
23110
23162
  "@resvg/resvg-js": "^2.6.2",
23111
23163
  "@tscircuit/alphabet": "0.0.25",
23112
23164
  "@tscircuit/breakout-point-solver": "github:tscircuit/breakout-point-solver#bac9629",
23113
- "@tscircuit/capacity-autorouter": "^0.0.696",
23165
+ "@tscircuit/capacity-autorouter": "^0.0.710",
23114
23166
  "@tscircuit/checks": "0.0.145",
23115
23167
  "@tscircuit/circuit-json-util": "^0.0.97",
23116
23168
  "@tscircuit/common": "^0.0.20",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.1481",
4
+ "version": "0.0.1483",
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",