@tscircuit/core 0.0.1807 → 0.0.1809

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 +270 -69
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -38452,7 +38452,13 @@ var debug8 = Debug10("Group_doInitialSchematicTraceRender");
38452
38452
  var INLINE_NET_LABEL_COLOR = "rgb(132, 0, 0)";
38453
38453
  var VERTICAL_INLINE_NET_LABEL_ROTATION = -90;
38454
38454
  function applyInlineNetLabelPlacements(args) {
38455
- const { group, solver, userNetIdToConnKey, sourceTraceIdByPinPairKey } = args;
38455
+ const {
38456
+ group,
38457
+ solver,
38458
+ userNetIdToConnKey,
38459
+ sourceTraceIdByPinPairKey,
38460
+ crossScopeSourceTraceIdBySchematicPortIdAndNetId
38461
+ } = args;
38456
38462
  const { db } = group.root;
38457
38463
  const inlineNetLabelPlacements = solver.inlineNetLabelSolver?.getOutput().inlineNetLabelPlacements ?? [];
38458
38464
  if (inlineNetLabelPlacements.length === 0) return;
@@ -38461,17 +38467,18 @@ function applyInlineNetLabelPlacements(args) {
38461
38467
  for (const placement of inlineNetLabelPlacements) {
38462
38468
  const schematicPortIds = placement.pinIds.map(asSchematicPortId);
38463
38469
  const placementUserNetId = globalConnMap.getIdsConnectedToNet(placement.globalConnNetId).find((id) => userNetIdToConnKey.has(id));
38464
- const connKey = placementUserNetId ? userNetIdToConnKey.get(placementUserNetId) : void 0;
38465
- const text = connKey ? resolveCanonicalNetLabelText({ subcircuitConnectivityMapKey: connKey }).name : placement.netId ?? placement.globalConnNetId;
38470
+ const crossScopeSourceTraceId = schematicPortIds.length === 1 ? crossScopeSourceTraceIdBySchematicPortIdAndNetId.get(schematicPortIds[0])?.get(placement.netId ?? placement.globalConnNetId) : void 0;
38471
+ const connKey = (crossScopeSourceTraceId ? db.source_trace.get(crossScopeSourceTraceId)?.subcircuit_connectivity_map_key : void 0) ?? (placementUserNetId ? userNetIdToConnKey.get(placementUserNetId) : void 0);
38472
+ const text = placement.netLabelText ?? (connKey ? resolveCanonicalNetLabelText({
38473
+ subcircuitConnectivityMapKey: connKey
38474
+ }).name : placement.netId ?? placement.globalConnNetId);
38466
38475
  if (!text) {
38467
38476
  debug8(
38468
38477
  `skipping inline net label for "${placement.netId}" REASON:no resolvable text`
38469
38478
  );
38470
38479
  continue;
38471
38480
  }
38472
- let sourceTraceId = sourceTraceIdByPinPairKey.get(
38473
- [...schematicPortIds].sort().join("::")
38474
- );
38481
+ let sourceTraceId = crossScopeSourceTraceId ?? sourceTraceIdByPinPairKey.get([...schematicPortIds].sort().join("::"));
38475
38482
  if (!sourceTraceId && connKey) {
38476
38483
  const sourcePortIds = schematicPortIds.flatMap((schematicPortId) => {
38477
38484
  const sourcePortId = db.schematic_port.get(schematicPortId)?.source_port_id;
@@ -38640,7 +38647,7 @@ function applyNetLabelPlacements(args) {
38640
38647
  solver,
38641
38648
  connKeyToSourceNet,
38642
38649
  userNetIdToConnKey,
38643
- crossSubcircuitTraceLabelBySchematicPortId,
38650
+ crossScopeSourceTraceIdBySchematicPortIdAndNetId,
38644
38651
  sourceTraceIdByPortOnlyLabelSchematicPortId,
38645
38652
  connKeysWithExplicitPortNetTraces,
38646
38653
  schematicPortIdsWithPreExistingNetLabels,
@@ -38696,8 +38703,8 @@ function applyNetLabelPlacements(args) {
38696
38703
  for (const placement of dedupedNetLabelPlacements) {
38697
38704
  debug9(`processing placement: ${placement.netId}`);
38698
38705
  const schPortIds = placement.pinIds.map(asSchematicPortId);
38699
- const crossSubcircuitTraceLabel = schPortIds.length === 1 ? crossSubcircuitTraceLabelBySchematicPortId.get(schPortIds[0]) : void 0;
38700
- const placementSourceTraceId = crossSubcircuitTraceLabel?.sourceTraceId ?? (schPortIds.length === 1 ? sourceTraceIdByPortOnlyLabelSchematicPortId.get(schPortIds[0]) : void 0);
38706
+ const crossScopeSourceTraceId = schPortIds.length === 1 ? crossScopeSourceTraceIdBySchematicPortIdAndNetId.get(schPortIds[0])?.get(placement.netId ?? placement.globalConnNetId) : void 0;
38707
+ const placementSourceTraceId = crossScopeSourceTraceId ?? (schPortIds.length === 1 ? sourceTraceIdByPortOnlyLabelSchematicPortId.get(schPortIds[0]) : void 0);
38701
38708
  const placementSourceTrace = placementSourceTraceId ? db.source_trace.get(placementSourceTraceId) : void 0;
38702
38709
  const placementUserNetId = globalConnMap.getIdsConnectedToNet(placement.globalConnNetId).find((id) => userNetIdToConnKey.get(id));
38703
38710
  const placementConnKey = placementSourceTrace?.subcircuit_connectivity_map_key ?? userNetIdToConnKey.get(placementUserNetId);
@@ -38707,15 +38714,16 @@ function applyNetLabelPlacements(args) {
38707
38714
  if (placementConnKey) {
38708
38715
  sourceNet = connKeyToSourceNet.get(placementConnKey);
38709
38716
  }
38710
- const canonicalNetLabel = placementConnKey ? crossSubcircuitTraceLabel ? {
38711
- name: crossSubcircuitTraceLabel.text,
38712
- wasAssignedDisplayLabel: false
38713
- } : resolveCanonicalNetLabelText({
38717
+ const resolvedCanonicalNetLabel = placementConnKey ? resolveCanonicalNetLabelText({
38714
38718
  subcircuitConnectivityMapKey: placementConnKey
38715
38719
  }) : {
38716
38720
  name: placement.netId ?? placement.globalConnNetId,
38717
38721
  wasAssignedDisplayLabel: false
38718
38722
  };
38723
+ const canonicalNetLabel = placement.netLabelText ? {
38724
+ name: placement.netLabelText,
38725
+ wasAssignedDisplayLabel: true
38726
+ } : resolvedCanonicalNetLabel;
38719
38727
  let schematicSheetId = group._resolveSchematicSheetId();
38720
38728
  const schematicPort = db.schematic_port.get(schPortIds[0]);
38721
38729
  if (schematicPort?.schematic_sheet_id) {
@@ -39572,9 +39580,23 @@ import {
39572
39580
  getBoundsCenter as getBoundsCenter2
39573
39581
  } from "@tscircuit/math-utils";
39574
39582
  import "@tscircuit/schematic-trace-solver";
39583
+ import { getSourcePortConnectivityMapFromCircuitJson as getSourcePortConnectivityMapFromCircuitJson2 } from "circuit-json-to-connectivity-map";
39575
39584
 
39576
39585
  // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/applyInlineNetLabelEligibility.ts
39577
39586
  var INLINE_NET_LABEL_FONT_SIZE = 0.12;
39587
+ var markConnectionEligibleForInlineNetLabel = (connection, name) => {
39588
+ connection.anchoredNetLabelWidth ??= Number(
39589
+ getSchematicNetLabelTextWidth({ text: name }).toFixed(2)
39590
+ );
39591
+ connection.allowInlineNetLabel = true;
39592
+ connection.inlineNetLabelHeight = INLINE_NET_LABEL_FONT_SIZE;
39593
+ connection.inlineNetLabelWidth = Number(
39594
+ getSchematicNetLabelTextWidth({
39595
+ text: name,
39596
+ font_size: INLINE_NET_LABEL_FONT_SIZE
39597
+ }).toFixed(2)
39598
+ );
39599
+ };
39578
39600
  var applyInlineNetLabelEligibility = ({
39579
39601
  directConnections,
39580
39602
  netConnections,
@@ -39586,19 +39608,6 @@ var applyInlineNetLabelEligibility = ({
39586
39608
  areSchematicPortsOnDifferentComponents,
39587
39609
  resolveCanonicalNetLabelText
39588
39610
  }) => {
39589
- const markEligible = (connection, name) => {
39590
- connection.anchoredNetLabelWidth ??= Number(
39591
- getSchematicNetLabelTextWidth({ text: name }).toFixed(2)
39592
- );
39593
- connection.allowInlineNetLabel = true;
39594
- connection.inlineNetLabelHeight = INLINE_NET_LABEL_FONT_SIZE;
39595
- connection.inlineNetLabelWidth = Number(
39596
- getSchematicNetLabelTextWidth({
39597
- text: name,
39598
- font_size: INLINE_NET_LABEL_FONT_SIZE
39599
- }).toFixed(2)
39600
- );
39601
- };
39602
39611
  for (const directConnection of directConnections) {
39603
39612
  const { connKey } = directConnection;
39604
39613
  if (!connKey) continue;
@@ -39610,10 +39619,11 @@ var applyInlineNetLabelEligibility = ({
39610
39619
  subcircuitConnectivityMapKey: connKey
39611
39620
  });
39612
39621
  if (!name || !wasAssignedDisplayLabel) continue;
39613
- markEligible(directConnection, name);
39622
+ markConnectionEligibleForInlineNetLabel(directConnection, name);
39614
39623
  }
39615
39624
  for (const netConnection of netConnections) {
39616
39625
  const { schematicPortIds } = netConnection;
39626
+ const { isSameSheetCrossSectionConnection } = netConnection;
39617
39627
  const hasInlineNetLabel = schematicPortIds.some(
39618
39628
  (schematicPortId) => schematicPortIdsWithInlineNetLabels.has(schematicPortId)
39619
39629
  );
@@ -39625,7 +39635,7 @@ var applyInlineNetLabelEligibility = ({
39625
39635
  otherSchematicPortId
39626
39636
  ])
39627
39637
  );
39628
- if (!hasInlineNetLabel && !isSinglePort && !hasPortsOnDifferentComponents) {
39638
+ if (!hasInlineNetLabel && !isSameSheetCrossSectionConnection && !isSinglePort && !hasPortsOnDifferentComponents) {
39629
39639
  continue;
39630
39640
  }
39631
39641
  if (!hasInlineNetLabel && schematicPortIds.some(
@@ -39633,17 +39643,25 @@ var applyInlineNetLabelEligibility = ({
39633
39643
  ))
39634
39644
  continue;
39635
39645
  const { connKey } = netConnection;
39636
- if (!connKey) continue;
39637
- if (!connKeysWithExplicitPortNetTraces.has(connKey)) continue;
39638
- const sourceNet = connKeyToSourceNet.get(connKey);
39639
- if (!hasInlineNetLabel && (sourceNet?.is_power || sourceNet?.is_ground)) {
39646
+ if (!connKey && !isSameSheetCrossSectionConnection) continue;
39647
+ if (connKey && !isSameSheetCrossSectionConnection && !connKeysWithExplicitPortNetTraces.has(connKey))
39648
+ continue;
39649
+ const sourceNet = connKey ? connKeyToSourceNet.get(connKey) : void 0;
39650
+ if (!hasInlineNetLabel && (netConnection.isPowerOrGroundConnection || sourceNet?.is_power || sourceNet?.is_ground)) {
39640
39651
  continue;
39641
39652
  }
39642
- const { name, wasAssignedDisplayLabel } = resolveCanonicalNetLabelText({
39643
- subcircuitConnectivityMapKey: connKey
39644
- });
39653
+ let name = netConnection.netLabelText ?? "";
39654
+ let wasAssignedDisplayLabel = Boolean(name);
39655
+ if (!isSameSheetCrossSectionConnection) {
39656
+ if (!connKey) continue;
39657
+ const resolvedLabel = resolveCanonicalNetLabelText({
39658
+ subcircuitConnectivityMapKey: connKey
39659
+ });
39660
+ name = resolvedLabel.name;
39661
+ wasAssignedDisplayLabel = resolvedLabel.wasAssignedDisplayLabel;
39662
+ }
39645
39663
  if (!name || !hasInlineNetLabel && !wasAssignedDisplayLabel) continue;
39646
- markEligible(netConnection, name);
39664
+ markConnectionEligibleForInlineNetLabel(netConnection, name);
39647
39665
  }
39648
39666
  };
39649
39667
 
@@ -39829,6 +39847,36 @@ var DEFAULT_MAX_MSP_PAIR_DISTANCE = 2.4;
39829
39847
  var SCHEMATIC_RAIL_NET_LABEL_HEIGHT = 0.42;
39830
39848
  function createSchematicTraceSolverInputProblem(group, opts = {}) {
39831
39849
  const { db } = group.root;
39850
+ const sourcePortConnectivityMap = getSourcePortConnectivityMapFromCircuitJson2(
39851
+ db.toArray()
39852
+ );
39853
+ const getStableSourceConnectivityNetId = (connectivityNetId) => {
39854
+ const canonicalSourceId = [
39855
+ ...sourcePortConnectivityMap.getIdsConnectedToNet(connectivityNetId)
39856
+ ].sort()[0];
39857
+ return canonicalSourceId ? `source_connectivity_${canonicalSourceId}` : `source_${connectivityNetId}`;
39858
+ };
39859
+ const getSourceConnectivityNetId = (sourceTrace) => {
39860
+ const connectivityNetId = [
39861
+ ...sourceTrace.connected_source_port_ids,
39862
+ ...sourceTrace.connected_source_net_ids
39863
+ ].map(
39864
+ (sourceId) => sourcePortConnectivityMap.getNetConnectedToId(sourceId)
39865
+ ).find((netId) => Boolean(netId));
39866
+ return connectivityNetId ? getStableSourceConnectivityNetId(connectivityNetId) : sourceTrace.subcircuit_connectivity_map_key ?? sourceTrace.source_trace_id;
39867
+ };
39868
+ const powerOrGroundSourceConnectivityNetIds = /* @__PURE__ */ new Set();
39869
+ for (const sourceNet of db.source_net.list()) {
39870
+ if (!sourceNet.is_power && !sourceNet.is_ground) continue;
39871
+ const connectivityNetId = sourcePortConnectivityMap.getNetConnectedToId(
39872
+ sourceNet.source_net_id
39873
+ );
39874
+ if (connectivityNetId) {
39875
+ powerOrGroundSourceConnectivityNetIds.add(
39876
+ getStableSourceConnectivityNetId(connectivityNetId)
39877
+ );
39878
+ }
39879
+ }
39832
39880
  const connKeyToSourceNet = /* @__PURE__ */ new Map();
39833
39881
  const childGroups = [];
39834
39882
  const componentsToVisit = [...group.children].reverse();
@@ -39877,7 +39925,8 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
39877
39925
  });
39878
39926
  }).filter((textBox) => Boolean(textBox));
39879
39927
  const sectionIdBySchematicComponentId = /* @__PURE__ */ new Map();
39880
- for (const component of group.getDescendants()) {
39928
+ const boardDescendants = group._getBoard()?.getDescendants() ?? [];
39929
+ for (const component of boardDescendants) {
39881
39930
  const schematicComponentId = component.schematic_component_id;
39882
39931
  const sectionId = component.getSchematicSectionName();
39883
39932
  if (schematicComponentId && sectionId) {
@@ -40023,9 +40072,67 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
40023
40072
  }
40024
40073
  }
40025
40074
  const directConnections = [];
40026
- const singlePortTraceNetConnections = [];
40075
+ const boundaryTraceNetConnections = [];
40027
40076
  const connectedPairKeys = /* @__PURE__ */ new Set();
40028
- const crossSubcircuitTraceLabelBySchematicPortId = /* @__PURE__ */ new Map();
40077
+ const crossScopeSourceTraceIdBySchematicPortIdAndNetId = /* @__PURE__ */ new Map();
40078
+ const crossSectionNetConnectionByKey = /* @__PURE__ */ new Map();
40079
+ const setCrossScopeSourceTraceId = ({
40080
+ schematicPortId,
40081
+ netId,
40082
+ sourceTraceId,
40083
+ replaceExisting = false
40084
+ }) => {
40085
+ const sourceTraceIdByNetId = crossScopeSourceTraceIdBySchematicPortIdAndNetId.get(schematicPortId) ?? /* @__PURE__ */ new Map();
40086
+ if (sourceTraceIdByNetId.has(netId) && !replaceExisting) return false;
40087
+ sourceTraceIdByNetId.set(netId, sourceTraceId);
40088
+ crossScopeSourceTraceIdBySchematicPortIdAndNetId.set(
40089
+ schematicPortId,
40090
+ sourceTraceIdByNetId
40091
+ );
40092
+ return true;
40093
+ };
40094
+ const addPortToCrossSectionInlineNetConnection = ({
40095
+ sourceConnectivityNetId,
40096
+ schematicPortId,
40097
+ text,
40098
+ sourceTraceId,
40099
+ connKey,
40100
+ preferInScopeTraceMetadata = false
40101
+ }) => {
40102
+ const netId = sourceConnectivityNetId;
40103
+ setCrossScopeSourceTraceId({
40104
+ schematicPortId,
40105
+ netId,
40106
+ sourceTraceId,
40107
+ replaceExisting: preferInScopeTraceMetadata
40108
+ });
40109
+ if (schematicPortIdsWithExplicitNetLabels.has(schematicPortId)) return;
40110
+ let connection = crossSectionNetConnectionByKey.get(sourceConnectivityNetId);
40111
+ if (!connection) {
40112
+ connection = {
40113
+ netId,
40114
+ netLabelText: text,
40115
+ schematicPortIds: [],
40116
+ netLabelWidth: Number(
40117
+ getSchematicNetLabelTextWidth({ text }).toFixed(2)
40118
+ ),
40119
+ connKey,
40120
+ isSameSheetCrossSectionConnection: true,
40121
+ isPowerOrGroundConnection: powerOrGroundSourceConnectivityNetIds.has(netId)
40122
+ };
40123
+ crossSectionNetConnectionByKey.set(sourceConnectivityNetId, connection);
40124
+ boundaryTraceNetConnections.push(connection);
40125
+ } else if (preferInScopeTraceMetadata) {
40126
+ connection.netLabelText = text;
40127
+ connection.netLabelWidth = Number(
40128
+ getSchematicNetLabelTextWidth({ text }).toFixed(2)
40129
+ );
40130
+ connection.connKey = connKey ?? connection.connKey;
40131
+ }
40132
+ if (!connection.schematicPortIds.includes(schematicPortId)) {
40133
+ connection.schematicPortIds.push(schematicPortId);
40134
+ }
40135
+ };
40029
40136
  const sourceTraceIdsByPortOnlyLabelSchematicPortId = /* @__PURE__ */ new Map();
40030
40137
  const sourceTraceIdByPinPairKey = /* @__PURE__ */ new Map();
40031
40138
  const connKeysWithExplicitPortNetTraces = /* @__PURE__ */ new Set();
@@ -40036,6 +40143,30 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
40036
40143
  );
40037
40144
  }
40038
40145
  }
40146
+ const areSchematicPortsInDifferentSectionsOnSameSheet = (firstSchematicPortId, secondSchematicPortId) => {
40147
+ const firstSchematicPort = db.schematic_port.get(firstSchematicPortId);
40148
+ const secondSchematicPort = db.schematic_port.get(secondSchematicPortId);
40149
+ if (!firstSchematicPort || !secondSchematicPort) return false;
40150
+ const sharesSheet = firstSchematicPort.schematic_sheet_id === secondSchematicPort.schematic_sheet_id;
40151
+ if (!sharesSheet) return false;
40152
+ const firstSectionId = firstSchematicPort.schematic_component_id ? sectionIdBySchematicComponentId.get(
40153
+ firstSchematicPort.schematic_component_id
40154
+ ) : void 0;
40155
+ const secondSectionId = secondSchematicPort.schematic_component_id ? sectionIdBySchematicComponentId.get(
40156
+ secondSchematicPort.schematic_component_id
40157
+ ) : void 0;
40158
+ const crossesSection = firstSectionId !== secondSectionId && (firstSectionId !== void 0 || secondSectionId !== void 0);
40159
+ return crossesSection;
40160
+ };
40161
+ const doesSourcePortCrossSectionOnSameSheet = ({
40162
+ schematicPortId,
40163
+ otherSourcePortId
40164
+ }) => db.schematic_port.list({ source_port_id: otherSourcePortId }).some(
40165
+ (otherSchematicPort) => areSchematicPortsInDifferentSectionsOnSameSheet(
40166
+ schematicPortId,
40167
+ asSchematicPortId(otherSchematicPort.schematic_port_id)
40168
+ )
40169
+ );
40039
40170
  for (const st of tracesInScope) {
40040
40171
  const connected = (st.connected_source_port_ids ?? []).map(
40041
40172
  (sourcePortId) => sourcePortIdToSchPortId.get(asSourcePortId(sourcePortId))
@@ -40055,11 +40186,25 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
40055
40186
  schematicSheetId: opts.schematicSheetId
40056
40187
  })
40057
40188
  );
40189
+ const crossesSchematicSectionOnSameSheet = Boolean(
40190
+ connected.length === 1 && otherSourcePortId && doesSourcePortCrossSectionOnSameSheet({
40191
+ schematicPortId: connected[0],
40192
+ otherSourcePortId
40193
+ })
40194
+ );
40058
40195
  if (connected.length === 1 && st.connected_source_port_ids.length === 2 && crossesSchematicScopeBoundary && st.connected_source_net_ids.length === 0 && st.subcircuit_connectivity_map_key) {
40059
40196
  const schematicPortId = connected[0];
40060
40197
  const sourcePortId = schPortIdToSourcePortId.get(schematicPortId);
40061
40198
  if (sourcePortId) {
40062
40199
  const connKey = st.subcircuit_connectivity_map_key;
40200
+ const sourcePortConnKey = db.source_port.get(sourcePortId)?.subcircuit_connectivity_map_key;
40201
+ const sourceNetInCurrentSubcircuit = db.source_net.list().find(
40202
+ (sourceNet) => sourceNet.subcircuit_id === group.subcircuit_id && sourcePortConnectivityMap.areIdsConnected(
40203
+ sourceNet.source_net_id,
40204
+ sourcePortId
40205
+ )
40206
+ );
40207
+ const sourceNetForLabel = connKeyToSourceNet.get(connKey) ?? (sourcePortConnKey ? connKeyToSourceNet.get(sourcePortConnKey) : void 0) ?? sourceNetInCurrentSubcircuit;
40063
40208
  const connectedSourcePortIdsForKey = Array.from(schematicPortIdsInScope).map((portId) => schPortIdToSourcePortId.get(portId)).filter((sourcePortId2) => {
40064
40209
  if (!sourcePortId2) return false;
40065
40210
  return db.source_port.get(sourcePortId2)?.subcircuit_connectivity_map_key === connKey;
@@ -40071,21 +40216,36 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
40071
40216
  sourcePortIdsInSchematicScope,
40072
40217
  schematicSheetId: opts.schematicSheetId,
40073
40218
  connKey,
40074
- sourceNet: connKeyToSourceNet.get(connKey)
40219
+ sourceNet: sourceNetForLabel
40075
40220
  });
40076
- if (text && !crossSubcircuitTraceLabelBySchematicPortId.has(schematicPortId)) {
40077
- crossSubcircuitTraceLabelBySchematicPortId.set(schematicPortId, {
40078
- text,
40221
+ if (text) {
40222
+ const sourceConnectivityNetId = getSourceConnectivityNetId(st);
40223
+ if (!userNetIdToConnKey.has(sourceConnectivityNetId)) {
40224
+ userNetIdToConnKey.set(sourceConnectivityNetId, connKey);
40225
+ }
40226
+ if (crossesSchematicSectionOnSameSheet) {
40227
+ addPortToCrossSectionInlineNetConnection({
40228
+ sourceConnectivityNetId,
40229
+ schematicPortId,
40230
+ text,
40231
+ sourceTraceId: st.source_trace_id,
40232
+ connKey
40233
+ });
40234
+ } else if (setCrossScopeSourceTraceId({
40235
+ schematicPortId,
40236
+ netId: sourceConnectivityNetId,
40079
40237
  sourceTraceId: st.source_trace_id
40080
- });
40081
- userNetIdToConnKey.set(text, connKey);
40082
- singlePortTraceNetConnections.push({
40083
- netId: text,
40084
- schematicPortIds: [schematicPortId],
40085
- netLabelWidth: Number(
40086
- getSchematicNetLabelTextWidth({ text }).toFixed(2)
40087
- )
40088
- });
40238
+ })) {
40239
+ boundaryTraceNetConnections.push({
40240
+ netId: sourceConnectivityNetId,
40241
+ netLabelText: text,
40242
+ schematicPortIds: [schematicPortId],
40243
+ netLabelWidth: Number(
40244
+ getSchematicNetLabelTextWidth({ text }).toFixed(2)
40245
+ ),
40246
+ connKey
40247
+ });
40248
+ }
40089
40249
  }
40090
40250
  }
40091
40251
  } else if (connected.length >= 2) {
@@ -40123,12 +40283,39 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
40123
40283
  text: renderedNetLabelText
40124
40284
  }).toFixed(2)
40125
40285
  ) : void 0;
40286
+ const crossSectionNetLabelText = renderedNetLabelText;
40126
40287
  for (let i = 0; i < connected.length - 1; i++) {
40127
40288
  const a = connected[i];
40128
40289
  const b = connected[i + 1];
40129
40290
  const pairKey = [a, b].sort().join("::");
40130
40291
  if (connectedPairKeys.has(pairKey)) continue;
40131
40292
  connectedPairKeys.add(pairKey);
40293
+ if (crossSectionNetLabelText && areSchematicPortsInDifferentSectionsOnSameSheet(a, b)) {
40294
+ const sourceConnectivityNetId = getSourceConnectivityNetId(st);
40295
+ if (st.subcircuit_connectivity_map_key) {
40296
+ userNetIdToConnKey.set(
40297
+ sourceConnectivityNetId,
40298
+ st.subcircuit_connectivity_map_key
40299
+ );
40300
+ }
40301
+ addPortToCrossSectionInlineNetConnection({
40302
+ sourceConnectivityNetId,
40303
+ schematicPortId: a,
40304
+ text: crossSectionNetLabelText,
40305
+ sourceTraceId: st.source_trace_id,
40306
+ connKey: st.subcircuit_connectivity_map_key,
40307
+ preferInScopeTraceMetadata: true
40308
+ });
40309
+ addPortToCrossSectionInlineNetConnection({
40310
+ sourceConnectivityNetId,
40311
+ schematicPortId: b,
40312
+ text: crossSectionNetLabelText,
40313
+ sourceTraceId: st.source_trace_id,
40314
+ connKey: st.subcircuit_connectivity_map_key,
40315
+ preferInScopeTraceMetadata: true
40316
+ });
40317
+ continue;
40318
+ }
40132
40319
  sourceTraceIdByPinPairKey.set(pairKey, st.source_trace_id);
40133
40320
  directConnections.push({
40134
40321
  schematicPortIds: [a, b],
@@ -40139,7 +40326,7 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
40139
40326
  }
40140
40327
  }
40141
40328
  }
40142
- const netConnections = [...singlePortTraceNetConnections];
40329
+ const netConnections = [...boundaryTraceNetConnections];
40143
40330
  const connKeyToSchematicPortIds = /* @__PURE__ */ new Map();
40144
40331
  for (const [schId, srcPortId] of schPortIdToSourcePortId) {
40145
40332
  if (schematicPortIdsWithExternallyRoutedRepresentations.has(schId)) continue;
@@ -40224,7 +40411,7 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
40224
40411
  netToAllowedOrientations[net.name] = ["x-", "x+"];
40225
40412
  }
40226
40413
  }
40227
- for (const { netId } of singlePortTraceNetConnections) {
40414
+ for (const { netId } of boundaryTraceNetConnections) {
40228
40415
  netToAllowedOrientations[netId] ??= ["x-", "x+"];
40229
40416
  }
40230
40417
  return netToAllowedOrientations;
@@ -40238,7 +40425,13 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
40238
40425
  })
40239
40426
  ),
40240
40427
  netConnections: netConnections.map(
40241
- ({ schematicPortIds, connKey, ...connection }) => ({
40428
+ ({
40429
+ schematicPortIds,
40430
+ connKey,
40431
+ isSameSheetCrossSectionConnection,
40432
+ isPowerOrGroundConnection,
40433
+ ...connection
40434
+ }) => ({
40242
40435
  ...connection,
40243
40436
  pinIds: schematicPortIds
40244
40437
  })
@@ -40259,7 +40452,7 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
40259
40452
  inputProblem,
40260
40453
  connKeyToSourceNet,
40261
40454
  userNetIdToConnKey,
40262
- crossSubcircuitTraceLabelBySchematicPortId,
40455
+ crossScopeSourceTraceIdBySchematicPortIdAndNetId,
40263
40456
  sourceTraceIdByPortOnlyLabelSchematicPortId,
40264
40457
  connKeysWithExplicitPortNetTraces,
40265
40458
  schematicPortIdsInScope,
@@ -40532,7 +40725,7 @@ var renderSchematicTracesForSheet = ({
40532
40725
  schematicPortIdsWithExternallyRoutedRepresentations,
40533
40726
  schPortIdToSourcePortId,
40534
40727
  userNetIdToConnKey,
40535
- crossSubcircuitTraceLabelBySchematicPortId,
40728
+ crossScopeSourceTraceIdBySchematicPortIdAndNetId,
40536
40729
  sourceTraceIdByPortOnlyLabelSchematicPortId,
40537
40730
  connKeysWithExplicitPortNetTraces,
40538
40731
  netLabelsInScope,
@@ -40587,7 +40780,7 @@ var renderSchematicTracesForSheet = ({
40587
40780
  solver,
40588
40781
  connKeyToSourceNet,
40589
40782
  userNetIdToConnKey,
40590
- crossSubcircuitTraceLabelBySchematicPortId,
40783
+ crossScopeSourceTraceIdBySchematicPortIdAndNetId,
40591
40784
  sourceTraceIdByPortOnlyLabelSchematicPortId,
40592
40785
  connKeysWithExplicitPortNetTraces,
40593
40786
  schematicPortIdsWithPreExistingNetLabels,
@@ -40598,7 +40791,8 @@ var renderSchematicTracesForSheet = ({
40598
40791
  group,
40599
40792
  solver,
40600
40793
  userNetIdToConnKey,
40601
- sourceTraceIdByPinPairKey
40794
+ sourceTraceIdByPinPairKey,
40795
+ crossScopeSourceTraceIdBySchematicPortIdAndNetId
40602
40796
  });
40603
40797
  insertNetLabelsForPortsMissingTrace({
40604
40798
  group,
@@ -41980,7 +42174,7 @@ function Group_getRoutingPhasePlans(group) {
41980
42174
  var package_default = {
41981
42175
  name: "@tscircuit/core",
41982
42176
  type: "module",
41983
- version: "0.0.1806",
42177
+ version: "0.0.1807",
41984
42178
  types: "dist/index.d.ts",
41985
42179
  main: "dist/index.js",
41986
42180
  module: "dist/index.js",
@@ -54170,11 +54364,12 @@ var SchematicSymbol = class extends PrimitiveComponent2 {
54170
54364
  };
54171
54365
 
54172
54366
  // lib/components/primitive-components/SchematicSection.ts
54367
+ import { doBoundsOverlap as doBoundsOverlap3 } from "@tscircuit/math-utils";
54368
+ import { schematicSectionProps } from "@tscircuit/props";
54173
54369
  import {
54174
54370
  calculateCellBoundaries,
54175
54371
  computeBoundsFromCellContents
54176
54372
  } from "calculate-cell-boundaries";
54177
- import { schematicSectionProps } from "@tscircuit/props";
54178
54373
  var SchematicSection = class _SchematicSection extends PrimitiveComponent2 {
54179
54374
  isSchematicPrimitive = true;
54180
54375
  get config() {
@@ -54288,16 +54483,22 @@ var SchematicSection = class _SchematicSection extends PrimitiveComponent2 {
54288
54483
  const vDividers = dividers.filter(
54289
54484
  (l) => Math.abs(l.start.x - l.end.x) < TOL4
54290
54485
  );
54291
- for (const {
54292
- displayName,
54293
- sectionTitleFontSize,
54294
- rawBounds
54295
- } of allSectionsWithBounds) {
54486
+ for (const sectionWithBounds of allSectionsWithBounds) {
54487
+ const { displayName, sectionTitleFontSize, rawBounds, cell } = sectionWithBounds;
54296
54488
  if (!displayName) continue;
54489
+ const overlapsAnotherSection = allSectionsWithBounds.some(
54490
+ (section) => section !== sectionWithBounds && doBoundsOverlap3(section.rawBounds, rawBounds)
54491
+ );
54297
54492
  const dividersAbove = hDividers.map((l) => l.start.y).filter((y) => y > rawBounds.maxY);
54298
54493
  const topBoundary = dividersAbove.length > 0 ? Math.min(...dividersAbove) : outer.maxY;
54299
54494
  const dividersToLeft = vDividers.map((l) => l.start.x).filter((x) => x < rawBounds.minX);
54300
- const leftBoundary = dividersToLeft.length > 0 ? Math.max(...dividersToLeft) : outer.minX;
54495
+ let leftBoundary = outer.minX;
54496
+ if (overlapsAnotherSection) {
54497
+ leftBoundary = cell.minX;
54498
+ }
54499
+ if (dividersToLeft.length > 0) {
54500
+ leftBoundary = Math.max(...dividersToLeft);
54501
+ }
54301
54502
  db.schematic_text.insert({
54302
54503
  anchor: "top_left",
54303
54504
  text: displayName,
@@ -55073,7 +55274,7 @@ var AnalogSweepParameter = class extends PrimitiveComponent2 {
55073
55274
  import { voltageProbeProps } from "@tscircuit/props";
55074
55275
 
55075
55276
  // lib/utils/schematic/selectBestLabelAlignment.ts
55076
- import { doBoundsOverlap as doBoundsOverlap3 } from "@tscircuit/math-utils";
55277
+ import { doBoundsOverlap as doBoundsOverlap4 } from "@tscircuit/math-utils";
55077
55278
  function getLabelBounds(probePosition, labelText, alignment, labelOffset = 0.3) {
55078
55279
  const charWidth = 0.1;
55079
55280
  const labelWidth = Math.max(labelText.length * charWidth, 0.3);
@@ -55144,7 +55345,7 @@ function getElementBounds(elm) {
55144
55345
  return null;
55145
55346
  }
55146
55347
  function getOverlapArea(a, b) {
55147
- if (!doBoundsOverlap3(a, b)) return 0;
55348
+ if (!doBoundsOverlap4(a, b)) return 0;
55148
55349
  const overlapWidth = Math.min(a.maxX, b.maxX) - Math.max(a.minX, b.minX);
55149
55350
  const overlapHeight = Math.min(a.maxY, b.maxY) - Math.max(a.minY, b.minY);
55150
55351
  return overlapWidth * overlapHeight;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.1807",
4
+ "version": "0.0.1809",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",