@tscircuit/core 0.0.651 → 0.0.653

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
@@ -459,7 +459,7 @@ declare abstract class PrimitiveComponent<ZodProps extends ZodType = any> extend
459
459
  doInitialAssignNameToUnnamedComponents(): void;
460
460
  doInitialOptimizeSelectorCache(): void;
461
461
  _cachedSelectAllQueries: Map<string, PrimitiveComponent[]>;
462
- selectAll(selectorRaw: string): PrimitiveComponent[];
462
+ selectAll<T extends PrimitiveComponent = PrimitiveComponent>(selectorRaw: string): T[];
463
463
  _cachedSelectOneQueries: Map<string, PrimitiveComponent | null>;
464
464
  selectOne<T = PrimitiveComponent>(selectorRaw: string, options?: {
465
465
  type?: string;
@@ -956,11 +956,18 @@ declare class Port extends PrimitiveComponent<typeof portProps> {
956
956
  doInitialSourceParentAttachment(): void;
957
957
  doInitialPcbPortRender(): void;
958
958
  doInitialSchematicPortRender(): void;
959
+ _getSubcircuitConnectivityKey(): string | undefined;
959
960
  _setPositionFromLayout(newCenter: {
960
961
  x: number;
961
962
  y: number;
962
963
  }): void;
963
964
  _hasMatchedPcbPrimitive(): boolean;
965
+ /**
966
+ * Return the text that should be used for the net label for this port if a
967
+ * trace can't be drawn. This net label text usually doesn't appear at this
968
+ * port, but appears at the port it connects to.
969
+ */
970
+ _getNetLabelText(): string | undefined;
964
971
  }
965
972
 
966
973
  interface INormalComponent {
package/dist/index.js CHANGED
@@ -1033,12 +1033,14 @@ var PrimitiveComponent2 = class extends Renderable {
1033
1033
  _cachedSelectAllQueries = /* @__PURE__ */ new Map();
1034
1034
  selectAll(selectorRaw) {
1035
1035
  if (this._cachedSelectAllQueries.has(selectorRaw)) {
1036
- return this._cachedSelectAllQueries.get(
1037
- selectorRaw
1038
- );
1036
+ return this._cachedSelectAllQueries.get(selectorRaw);
1039
1037
  }
1040
1038
  const selector = preprocessSelector(selectorRaw);
1041
- const result = selectAll(selector, this, cssSelectOptionsInsideSubcircuit);
1039
+ const result = selectAll(
1040
+ selector,
1041
+ this,
1042
+ cssSelectOptionsInsideSubcircuit
1043
+ );
1042
1044
  if (result.length > 0) {
1043
1045
  this._cachedSelectAllQueries.set(selectorRaw, result);
1044
1046
  return result;
@@ -3305,6 +3307,9 @@ var Port = class extends PrimitiveComponent2 {
3305
3307
  });
3306
3308
  this.schematic_port_id = schematic_port.schematic_port_id;
3307
3309
  }
3310
+ _getSubcircuitConnectivityKey() {
3311
+ return this.root?.db.source_port.get(this.source_port_id)?.subcircuit_connectivity_map_key;
3312
+ }
3308
3313
  _setPositionFromLayout(newCenter) {
3309
3314
  const { db } = this.root;
3310
3315
  if (!this.pcb_port_id) return;
@@ -3316,6 +3321,14 @@ var Port = class extends PrimitiveComponent2 {
3316
3321
  _hasMatchedPcbPrimitive() {
3317
3322
  return this.matchedComponents.some((c) => c.isPcbPrimitive);
3318
3323
  }
3324
+ /**
3325
+ * Return the text that should be used for the net label for this port if a
3326
+ * trace can't be drawn. This net label text usually doesn't appear at this
3327
+ * port, but appears at the port it connects to.
3328
+ */
3329
+ _getNetLabelText() {
3330
+ return `${this.parent?.props.name}_${this.props.name}`;
3331
+ }
3319
3332
  };
3320
3333
 
3321
3334
  // lib/utils/getPortFromHints.ts
@@ -10041,6 +10054,12 @@ var oppositeSide = (input) => {
10041
10054
  }
10042
10055
  };
10043
10056
 
10057
+ // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/getNetNameFromPorts.ts
10058
+ var getNetNameFromPorts = (ports) => {
10059
+ const netName = ports.map((p) => p._getNetLabelText()).join("/");
10060
+ return netName;
10061
+ };
10062
+
10044
10063
  // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/applyNetLabelPlacements.ts
10045
10064
  function applyNetLabelPlacements(args) {
10046
10065
  const {
@@ -10050,7 +10069,10 @@ function applyNetLabelPlacements(args) {
10050
10069
  allScks,
10051
10070
  allSourceAndSchematicPortIdsInScope,
10052
10071
  schPortIdToSourcePortId,
10053
- userNetIdToSck
10072
+ userNetIdToSck,
10073
+ pinIdToSchematicPortId,
10074
+ schematicPortIdsWithPreExistingNetLabels,
10075
+ schematicPortIdsWithRoutedTraces
10054
10076
  } = args;
10055
10077
  const { db } = group.root;
10056
10078
  const netLabelPlacements = solver.netLabelPlacementSolver?.netLabelPlacements ?? [];
@@ -10062,18 +10084,38 @@ function applyNetLabelPlacements(args) {
10062
10084
  const orientation = placement.orientation;
10063
10085
  const anchor_side = oppositeSide(orientation);
10064
10086
  const sourceNet = placementSck ? sckToSourceNet.get(placementSck) : void 0;
10065
- if (!sourceNet) {
10087
+ const schPortIds = placement.pinIds.map(
10088
+ (pinId) => pinIdToSchematicPortId.get(pinId)
10089
+ );
10090
+ if (schPortIds.some(
10091
+ (schPortId) => schematicPortIdsWithPreExistingNetLabels.has(schPortId)
10092
+ )) {
10066
10093
  continue;
10067
10094
  }
10068
- const text = sourceNet.name;
10069
- const hasExistingLabelForNet = db.schematic_net_label.list().some((nl) => {
10070
- if (sourceNet?.source_net_id && nl.source_net_id) {
10071
- return nl.source_net_id === sourceNet.source_net_id;
10072
- }
10073
- return nl.text === text;
10074
- });
10075
- if (hasExistingLabelForNet) continue;
10076
- const center = placement.center ?? computeSchematicNetLabelCenter({
10095
+ if (sourceNet) {
10096
+ const text2 = sourceNet.name;
10097
+ const center2 = computeSchematicNetLabelCenter({
10098
+ anchor_position,
10099
+ anchor_side,
10100
+ text: text2
10101
+ });
10102
+ db.schematic_net_label.insert({
10103
+ text: text2,
10104
+ anchor_position,
10105
+ center: center2,
10106
+ anchor_side,
10107
+ ...sourceNet?.source_net_id ? { source_net_id: sourceNet.source_net_id } : {}
10108
+ });
10109
+ return;
10110
+ }
10111
+ if (schPortIds.some(
10112
+ (schPortId) => schematicPortIdsWithRoutedTraces.has(schPortId)
10113
+ )) {
10114
+ continue;
10115
+ }
10116
+ const ports = group.selectAll("port").filter((p) => p._getSubcircuitConnectivityKey() === placementSck);
10117
+ const text = getNetNameFromPorts(ports);
10118
+ const center = computeSchematicNetLabelCenter({
10077
10119
  anchor_position,
10078
10120
  anchor_side,
10079
10121
  text
@@ -10082,51 +10124,22 @@ function applyNetLabelPlacements(args) {
10082
10124
  text,
10083
10125
  anchor_position,
10084
10126
  center,
10085
- anchor_side,
10086
- ...sourceNet?.source_net_id ? { source_net_id: sourceNet.source_net_id } : {}
10127
+ anchor_side
10087
10128
  });
10088
10129
  }
10089
10130
  }
10090
10131
 
10091
10132
  // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/insertNetLabelsForTracesExcludedFromRouting.ts
10092
10133
  import "@tscircuit/schematic-trace-solver";
10093
- function insertNetLabelsForTracesExcludedFromRouting(args) {
10094
- const { group, displayLabelTraces } = args;
10095
- const { db } = group.root;
10096
- for (const trace of displayLabelTraces) {
10097
- const label = trace._parsedProps?.schDisplayLabel;
10098
- if (!label) continue;
10099
- try {
10100
- const res = trace._findConnectedPorts?.();
10101
- if (!res?.allPortsFound || !res.ports || res.ports.length < 1) continue;
10102
- const ports = res.ports.slice(0, 2);
10103
- for (const port of ports) {
10104
- const anchor_position = port._getGlobalSchematicPositionAfterLayout();
10105
- const side = getEnteringEdgeFromDirection(port.facingDirection || "right") || "right";
10106
- const center = computeSchematicNetLabelCenter({
10107
- anchor_position,
10108
- anchor_side: side,
10109
- text: label
10110
- });
10111
- db.schematic_net_label.insert({
10112
- text: label,
10113
- anchor_position,
10114
- center,
10115
- anchor_side: side,
10116
- ...trace.source_trace_id ? { source_trace_id: trace.source_trace_id } : {}
10117
- });
10118
- }
10119
- } catch {
10120
- }
10121
- }
10122
- }
10123
10134
 
10124
10135
  // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/insertNetLabelsForPortsMissingTrace.ts
10125
10136
  var insertNetLabelsForPortsMissingTrace = ({
10126
10137
  allSourceAndSchematicPortIdsInScope,
10127
10138
  group,
10128
10139
  schPortIdToSourcePortId,
10129
- sckToSourceNet: connKeyToNet
10140
+ sckToSourceNet: connKeyToNet,
10141
+ pinIdToSchematicPortId,
10142
+ schematicPortIdsWithPreExistingNetLabels
10130
10143
  }) => {
10131
10144
  const { db } = group.root;
10132
10145
  for (const schOrSrcPortId of Array.from(
@@ -10144,13 +10157,6 @@ var insertNetLabelsForPortsMissingTrace = ({
10144
10157
  if (!sourceNet) {
10145
10158
  continue;
10146
10159
  }
10147
- const hasLabelForNet = db.schematic_net_label.list().some((nl) => {
10148
- if (sourceNet.source_net_id && nl.source_net_id) {
10149
- return nl.source_net_id === sourceNet.source_net_id;
10150
- }
10151
- return nl.text === (sourceNet.name || key);
10152
- });
10153
- if (hasLabelForNet) continue;
10154
10160
  const existingAtPort = db.schematic_net_label.list().some((nl) => {
10155
10161
  const samePos = Math.abs(nl.anchor_position.x - sp.center.x) < 1e-6 && Math.abs(nl.anchor_position.y - sp.center.y) < 1e-6;
10156
10162
  if (!samePos) return false;
@@ -10177,6 +10183,38 @@ var insertNetLabelsForPortsMissingTrace = ({
10177
10183
  }
10178
10184
  };
10179
10185
 
10186
+ // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/getSchematicPortIdsWithAssignedNetLabels.ts
10187
+ var getSchematicPortIdsWithAssignedNetLabels = (group) => {
10188
+ const schematicPortIdsWithNetLabels = /* @__PURE__ */ new Set();
10189
+ const netLabels = group.selectAll("netlabel");
10190
+ for (const netLabel of netLabels) {
10191
+ const netLabelPorts = netLabel._getConnectedPorts();
10192
+ for (const port of netLabelPorts) {
10193
+ if (!port.schematic_port_id) continue;
10194
+ schematicPortIdsWithNetLabels.add(port.schematic_port_id);
10195
+ }
10196
+ }
10197
+ return schematicPortIdsWithNetLabels;
10198
+ };
10199
+
10200
+ // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/getSchematicPortIdsWithRoutedTraces.ts
10201
+ var getSchematicPortIdsWithRoutedTraces = ({
10202
+ solver,
10203
+ pinIdToSchematicPortId
10204
+ }) => {
10205
+ const solvedTraces = solver.schematicTraceLinesSolver.solvedTracePaths;
10206
+ const schematicPortIdsWithRoutedTraces = /* @__PURE__ */ new Set();
10207
+ for (const solvedTrace of solvedTraces) {
10208
+ for (const pinId of solvedTrace.pinIds) {
10209
+ const schPortId = pinIdToSchematicPortId.get(pinId);
10210
+ if (schPortId) {
10211
+ schematicPortIdsWithRoutedTraces.add(schPortId);
10212
+ }
10213
+ }
10214
+ }
10215
+ return schematicPortIdsWithRoutedTraces;
10216
+ };
10217
+
10180
10218
  // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/Group_doInitialSchematicTraceRender.ts
10181
10219
  var debug7 = Debug8("Group_doInitialSchematicTraceRender");
10182
10220
  var Group_doInitialSchematicTraceRender = (group) => {
@@ -10194,6 +10232,7 @@ var Group_doInitialSchematicTraceRender = (group) => {
10194
10232
  allScks,
10195
10233
  userNetIdToSck
10196
10234
  } = createSchematicTraceSolverInputProblem(group);
10235
+ const schematicPortIdsWithPreExistingNetLabels = getSchematicPortIdsWithAssignedNetLabels(group);
10197
10236
  if (debug7.enabled) {
10198
10237
  globalThis.debugOutputs?.add(
10199
10238
  "group-trace-render-input-problem",
@@ -10202,6 +10241,10 @@ var Group_doInitialSchematicTraceRender = (group) => {
10202
10241
  }
10203
10242
  const solver = new SchematicTracePipelineSolver4(inputProblem);
10204
10243
  solver.solve();
10244
+ const schematicPortIdsWithRoutedTraces = getSchematicPortIdsWithRoutedTraces({
10245
+ solver,
10246
+ pinIdToSchematicPortId
10247
+ });
10205
10248
  applyTracesFromSolverOutput({
10206
10249
  group,
10207
10250
  solver,
@@ -10214,19 +10257,19 @@ var Group_doInitialSchematicTraceRender = (group) => {
10214
10257
  sckToSourceNet,
10215
10258
  allSourceAndSchematicPortIdsInScope,
10216
10259
  schPortIdToSourcePortId,
10260
+ pinIdToSchematicPortId,
10217
10261
  allScks,
10218
- userNetIdToSck
10262
+ userNetIdToSck,
10263
+ schematicPortIdsWithPreExistingNetLabels,
10264
+ schematicPortIdsWithRoutedTraces
10219
10265
  });
10220
10266
  insertNetLabelsForPortsMissingTrace({
10221
10267
  group,
10222
10268
  allSourceAndSchematicPortIdsInScope,
10223
10269
  schPortIdToSourcePortId,
10224
- sckToSourceNet
10225
- });
10226
- insertNetLabelsForTracesExcludedFromRouting({
10227
- group,
10228
- solver,
10229
- displayLabelTraces
10270
+ sckToSourceNet,
10271
+ pinIdToSchematicPortId,
10272
+ schematicPortIdsWithPreExistingNetLabels
10230
10273
  });
10231
10274
  };
10232
10275
 
@@ -13669,7 +13712,7 @@ import { identity as identity5 } from "transformation-matrix";
13669
13712
  var package_default = {
13670
13713
  name: "@tscircuit/core",
13671
13714
  type: "module",
13672
- version: "0.0.650",
13715
+ version: "0.0.652",
13673
13716
  types: "dist/index.d.ts",
13674
13717
  main: "dist/index.js",
13675
13718
  module: "dist/index.js",
@@ -13711,7 +13754,7 @@ var package_default = {
13711
13754
  "@tscircuit/props": "^0.0.287",
13712
13755
  "@tscircuit/schematic-autolayout": "^0.0.6",
13713
13756
  "@tscircuit/schematic-match-adapt": "^0.0.16",
13714
- "@tscircuit/schematic-trace-solver": "^0.0.12",
13757
+ "@tscircuit/schematic-trace-solver": "^0.0.17",
13715
13758
  "@tscircuit/simple-3d-svg": "^0.0.38",
13716
13759
  "@types/bun": "^1.2.16",
13717
13760
  "@types/debug": "^4.1.12",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.651",
4
+ "version": "0.0.653",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -43,7 +43,7 @@
43
43
  "@tscircuit/props": "^0.0.287",
44
44
  "@tscircuit/schematic-autolayout": "^0.0.6",
45
45
  "@tscircuit/schematic-match-adapt": "^0.0.16",
46
- "@tscircuit/schematic-trace-solver": "^0.0.12",
46
+ "@tscircuit/schematic-trace-solver": "^0.0.17",
47
47
  "@tscircuit/simple-3d-svg": "^0.0.38",
48
48
  "@types/bun": "^1.2.16",
49
49
  "@types/debug": "^4.1.12",