@tscircuit/core 0.0.1871 → 0.0.1873

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 +91 -91
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -47907,6 +47907,7 @@ var isUserDefinedNetLabelRedundantWithPlacement = (label, solverPlacement) => {
47907
47907
  function applyNetLabelPlacements(args) {
47908
47908
  const {
47909
47909
  group,
47910
+ routedSchematicPortIdBySchematicPortId,
47910
47911
  solver,
47911
47912
  connKeyToSourceNet,
47912
47913
  userNetIdToConnKey,
@@ -47959,7 +47960,7 @@ function applyNetLabelPlacements(args) {
47959
47960
  if (!dbLabel) return null;
47960
47961
  return {
47961
47962
  schematicNetLabel: dbLabel,
47962
- schematicPortIds: label._getConnectedPorts().map((port) => port.schematic_port_id).filter((id) => Boolean(id)),
47963
+ schematicPortIds: label._getConnectedPorts().map((port) => port.schematic_port_id).filter((id) => Boolean(id)).map((id) => routedSchematicPortIdBySchematicPortId.get(id) ?? id),
47963
47964
  shouldUseSchematicTraceSolver: label._parsedProps.schX === void 0 && label._parsedProps.schY === void 0
47964
47965
  };
47965
47966
  }).filter((label) => label !== null);
@@ -48447,21 +48448,6 @@ function computeJunctions(traces, opts = {}) {
48447
48448
  return result;
48448
48449
  }
48449
48450
 
48450
- // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/getPortForSchematicSymbolPort.ts
48451
- var getPortForSchematicSymbolPort = (port) => {
48452
- const { schX, schY } = port._parsedProps;
48453
- if (schX !== void 0 && schY !== void 0) return port;
48454
- if (!port.getParentNormalComponent()?.getSchematicSymbol()) return port;
48455
- const internallyConnectedPorts = port._getPortsInternallyConnectedToThisPort();
48456
- const schematicSymbolPortDef = port.schematicSymbolPortDef ?? internallyConnectedPorts.find(
48457
- (connectedPort) => connectedPort.schematicSymbolPortDef
48458
- )?.schematicSymbolPortDef;
48459
- if (!schematicSymbolPortDef) return port;
48460
- return internallyConnectedPorts.find(
48461
- (connectedPort) => connectedPort.schematicSymbolPortDef === schematicSymbolPortDef
48462
- ) ?? port;
48463
- };
48464
-
48465
48451
  // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/remove-overlapping-same-net-crossing-segments.ts
48466
48452
  var TOL3 = 1e-6;
48467
48453
  function isCollinear(a, b, tol = TOL3) {
@@ -48628,20 +48614,6 @@ function applyTracesFromSolverOutput(args) {
48628
48614
  schematicPortIdsWithPreExistingNetLabels
48629
48615
  } = args;
48630
48616
  const { db } = group.root;
48631
- const schematicPortIdsByRoutedSchematicPortId = /* @__PURE__ */ new Map();
48632
- for (const port of group.selectAll("port")) {
48633
- const routedSchematicPortIdValue = getPortForSchematicSymbolPort(port).schematic_port_id;
48634
- const schematicPortIdValue = port.schematic_port_id;
48635
- if (!routedSchematicPortIdValue || !schematicPortIdValue) continue;
48636
- const routedSchematicPortId = asSchematicPortId(routedSchematicPortIdValue);
48637
- const schematicPortId = asSchematicPortId(schematicPortIdValue);
48638
- const schematicPortIds = schematicPortIdsByRoutedSchematicPortId.get(routedSchematicPortId) ?? [];
48639
- schematicPortIds.push(schematicPortId);
48640
- schematicPortIdsByRoutedSchematicPortId.set(
48641
- routedSchematicPortId,
48642
- schematicPortIds
48643
- );
48644
- }
48645
48617
  const customSymbolPortIds = new Set(
48646
48618
  group.selectAll("port").filter((port) => {
48647
48619
  if (!port._getSymbolAncestor()) return false;
@@ -48727,13 +48699,6 @@ function applyTracesFromSolverOutput(args) {
48727
48699
  db.schematic_port.update(routedSchematicPortId, {
48728
48700
  is_connected: true
48729
48701
  });
48730
- for (const schematicPortId of schematicPortIdsByRoutedSchematicPortId.get(
48731
- routedSchematicPortId
48732
- ) ?? []) {
48733
- db.schematic_port.update(schematicPortId, {
48734
- is_connected: true
48735
- });
48736
- }
48737
48702
  }
48738
48703
  subcircuit_connectivity_map_key = userNetIdToConnKey.get(
48739
48704
  String(solvedTracePath.userNetId)
@@ -48928,6 +48893,40 @@ var applyInlineNetLabelEligibility = ({
48928
48893
  }
48929
48894
  };
48930
48895
 
48896
+ // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/getPortForSchematicSymbolPort.ts
48897
+ var getPortForSchematicSymbolPort = (port) => {
48898
+ const { schX, schY } = port._parsedProps;
48899
+ if (schX !== void 0 && schY !== void 0) return port;
48900
+ if (!port.getParentNormalComponent()?.getSchematicSymbol()) return port;
48901
+ const internallyConnectedPorts = port._getPortsInternallyConnectedToThisPort();
48902
+ const schematicSymbolPortDef = port.schematicSymbolPortDef ?? internallyConnectedPorts.find(
48903
+ (connectedPort) => connectedPort.schematicSymbolPortDef
48904
+ )?.schematicSymbolPortDef;
48905
+ if (!schematicSymbolPortDef) return port;
48906
+ return internallyConnectedPorts.find(
48907
+ (connectedPort) => connectedPort.schematicSymbolPortDef === schematicSymbolPortDef
48908
+ ) ?? port;
48909
+ };
48910
+
48911
+ // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/createRoutedSchematicPortIdMap.ts
48912
+ function createRoutedSchematicPortIdMap(group) {
48913
+ const { db } = group.root;
48914
+ const routedSchematicPortIdBySchematicPortId = /* @__PURE__ */ new Map();
48915
+ for (const port of group.selectAll("port")) {
48916
+ if (!port.schematic_port_id) continue;
48917
+ const schematicPort = db.schematic_port.get(port.schematic_port_id);
48918
+ const terminalPort = getPortForSchematicSymbolPort(port);
48919
+ const terminalSchematicPort = terminalPort.schematic_port_id ? db.schematic_port.get(terminalPort.schematic_port_id) : void 0;
48920
+ if (!schematicPort || !terminalSchematicPort || schematicPort.schematic_component_id !== terminalSchematicPort.schematic_component_id || schematicPort.schematic_sheet_id !== terminalSchematicPort.schematic_sheet_id)
48921
+ continue;
48922
+ routedSchematicPortIdBySchematicPortId.set(
48923
+ asSchematicPortId(schematicPort.schematic_port_id),
48924
+ asSchematicPortId(terminalSchematicPort.schematic_port_id)
48925
+ );
48926
+ }
48927
+ return routedSchematicPortIdBySchematicPortId;
48928
+ }
48929
+
48931
48930
  // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/resolveNetLabelForPortMissingTrace.ts
48932
48931
  var isDirectConnectionEndpointOutsideSchematicScope = ({
48933
48932
  db,
@@ -49110,6 +49109,8 @@ var DEFAULT_MAX_MSP_PAIR_DISTANCE = 2.4;
49110
49109
  var SCHEMATIC_RAIL_NET_LABEL_HEIGHT = 0.42;
49111
49110
  function createSchematicTraceSolverInputProblem(group, opts = {}) {
49112
49111
  const { db } = group.root;
49112
+ const routedSchematicPortIdBySchematicPortId = createRoutedSchematicPortIdMap(group);
49113
+ const resolveRoutedSchematicPortId = (schematicPortId) => routedSchematicPortIdBySchematicPortId.get(schematicPortId) ?? schematicPortId;
49113
49114
  const sourcePortConnectivityMap = getSourcePortConnectivityMapFromCircuitJson2(
49114
49115
  db.toArray()
49115
49116
  );
@@ -49202,8 +49203,13 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
49202
49203
  const schematicPorts = db.schematic_port.list({
49203
49204
  schematic_component_id: schematicComponent.schematic_component_id
49204
49205
  });
49205
- const pins = schematicPorts.map((schematicPort) => {
49206
- const schematicPortId = asSchematicPortId(schematicPort.schematic_port_id);
49206
+ const pins = schematicPorts.filter((schematicPort) => {
49207
+ const id = asSchematicPortId(schematicPort.schematic_port_id);
49208
+ return resolveRoutedSchematicPortId(id) === id;
49209
+ }).map((schematicPort) => {
49210
+ const schematicPortId = asSchematicPortId(
49211
+ schematicPort.schematic_port_id
49212
+ );
49207
49213
  const sourcePort = schematicPort.source_port_id ? db.source_port.get(schematicPort.source_port_id) : void 0;
49208
49214
  return {
49209
49215
  pinId: schematicPortId,
@@ -49272,19 +49278,19 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
49272
49278
  const schematicPortIdsWithExplicitNetLabels = new Set(
49273
49279
  netLabelsInScope.filter((netLabel) => !netLabel._parsedProps.inline).flatMap((netLabel) => netLabel._getConnectedPorts()).map((port) => port.schematic_port_id).filter(
49274
49280
  (schematicPortId) => schematicPortId !== null && schematicPortId !== void 0
49275
- ).map(asSchematicPortId)
49281
+ ).map(asSchematicPortId).map(resolveRoutedSchematicPortId)
49276
49282
  );
49277
49283
  const solverManagedNetLabelSchematicPortIds = new Set(
49278
49284
  netLabelsInScope.filter(
49279
49285
  (netLabel) => netLabel._parsedProps.inline || netLabel._parsedProps.schX === void 0 && netLabel._parsedProps.schY === void 0
49280
49286
  ).flatMap((netLabel) => netLabel._getConnectedPorts()).map((port) => port.schematic_port_id).filter(
49281
49287
  (schematicPortId) => schematicPortId !== null && schematicPortId !== void 0
49282
- ).map(asSchematicPortId)
49288
+ ).map(asSchematicPortId).map(resolveRoutedSchematicPortId)
49283
49289
  );
49284
49290
  const schematicPortIdsWithInlineNetLabels = new Set(
49285
49291
  netLabelsInScope.filter((netLabel) => netLabel._parsedProps.inline).flatMap((netLabel) => netLabel._getConnectedPorts()).map((port) => port.schematic_port_id).filter(
49286
49292
  (schematicPortId) => schematicPortId !== null && schematicPortId !== void 0
49287
- ).map(asSchematicPortId)
49293
+ ).map(asSchematicPortId).map(resolveRoutedSchematicPortId)
49288
49294
  );
49289
49295
  const allowedSubcircuitIds = /* @__PURE__ */ new Set();
49290
49296
  if (group.subcircuit_id) allowedSubcircuitIds.add(group.subcircuit_id);
@@ -49431,10 +49437,14 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
49431
49437
  )
49432
49438
  );
49433
49439
  for (const st of tracesInScope) {
49434
- const connected = (st.connected_source_port_ids ?? []).map(
49435
- (sourcePortId) => sourcePortIdToSchPortId.get(asSourcePortId(sourcePortId))
49436
- ).filter(
49437
- (schematicPortId) => Boolean(schematicPortId) && schematicPortIdsInScope.has(schematicPortId)
49440
+ const connected = Array.from(
49441
+ new Set(
49442
+ (st.connected_source_port_ids ?? []).map(
49443
+ (sourcePortId) => sourcePortIdToSchPortId.get(asSourcePortId(sourcePortId))
49444
+ ).filter(
49445
+ (schematicPortId) => Boolean(schematicPortId) && schematicPortIdsInScope.has(schematicPortId)
49446
+ ).map(resolveRoutedSchematicPortId)
49447
+ )
49438
49448
  );
49439
49449
  const sourcePortIdForSingleConnectedEndpoint = connected.length === 1 ? schPortIdToSourcePortId.get(connected[0]) : void 0;
49440
49450
  const otherSourcePortId = sourcePortIdForSingleConnectedEndpoint ? st.connected_source_port_ids.map(asSourcePortId).find(
@@ -49599,24 +49609,15 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
49599
49609
  if (!connKeyToSchematicPortIds.has(connKey)) {
49600
49610
  connKeyToSchematicPortIds.set(connKey, []);
49601
49611
  }
49602
- connKeyToSchematicPortIds.get(connKey).push(schId);
49612
+ const routedSchematicPortId = resolveRoutedSchematicPortId(schId);
49613
+ const netSchematicPortIds = connKeyToSchematicPortIds.get(connKey);
49614
+ if (!netSchematicPortIds.includes(routedSchematicPortId)) {
49615
+ netSchematicPortIds.push(routedSchematicPortId);
49616
+ }
49603
49617
  }
49604
49618
  for (const [connKey, schematicPortIds] of connKeyToSchematicPortIds) {
49605
49619
  const sourceNet = connKeyToSourceNet.get(connKey);
49606
49620
  if (sourceNet && schematicPortIds.length >= 1) {
49607
- const seenRoutedSchematicPortIds = /* @__PURE__ */ new Set();
49608
- const uniqueSchematicPortIds = schematicPortIds.filter(
49609
- (schematicPortId) => {
49610
- const componentPort = componentPortBySchematicPortId.get(schematicPortId);
49611
- const routedSchematicPortIdValue = componentPort ? getPortForSchematicSymbolPort(componentPort).schematic_port_id : null;
49612
- const routedSchematicPortId = routedSchematicPortIdValue ? asSchematicPortId(routedSchematicPortIdValue) : schematicPortId;
49613
- if (seenRoutedSchematicPortIds.has(routedSchematicPortId)) {
49614
- return false;
49615
- }
49616
- seenRoutedSchematicPortIds.add(routedSchematicPortId);
49617
- return true;
49618
- }
49619
- );
49620
49621
  const userNetId = String(
49621
49622
  sourceNet.name || sourceNet.source_net_id || connKey
49622
49623
  );
@@ -49632,7 +49633,7 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
49632
49633
  }
49633
49634
  netConnections.push({
49634
49635
  netId: userNetId,
49635
- schematicPortIds: uniqueSchematicPortIds,
49636
+ schematicPortIds,
49636
49637
  isGround: sourceNet.is_ground,
49637
49638
  netLabelWidth,
49638
49639
  netLabelHeight,
@@ -49713,6 +49714,7 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
49713
49714
  );
49714
49715
  return {
49715
49716
  inputProblem,
49717
+ routedSchematicPortIdBySchematicPortId,
49716
49718
  connKeyToSourceNet,
49717
49719
  userNetIdToConnKey,
49718
49720
  crossScopeSourceTraceIdBySchematicPortIdAndNetId,
@@ -49727,7 +49729,7 @@ function createSchematicTraceSolverInputProblem(group, opts = {}) {
49727
49729
  }
49728
49730
 
49729
49731
  // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/getSchematicPortIdsWithAssignedNetLabels.ts
49730
- var getSchematicPortIdsWithAssignedNetLabels = (netLabels) => {
49732
+ var getSchematicPortIdsWithAssignedNetLabels = (netLabels, routedSchematicPortIdBySchematicPortId) => {
49731
49733
  const schematicPortIdsWithNetLabels = /* @__PURE__ */ new Set();
49732
49734
  for (const netLabel of netLabels) {
49733
49735
  const { inline, schX, schY } = netLabel._parsedProps;
@@ -49737,7 +49739,9 @@ var getSchematicPortIdsWithAssignedNetLabels = (netLabels) => {
49737
49739
  for (const port of netLabelPorts) {
49738
49740
  if (!port.schematic_port_id) continue;
49739
49741
  schematicPortIdsWithNetLabels.add(
49740
- asSchematicPortId(port.schematic_port_id)
49742
+ routedSchematicPortIdBySchematicPortId.get(
49743
+ asSchematicPortId(port.schematic_port_id)
49744
+ ) ?? asSchematicPortId(port.schematic_port_id)
49741
49745
  );
49742
49746
  }
49743
49747
  }
@@ -49983,6 +49987,7 @@ var renderSchematicTracesForSheet = ({
49983
49987
  }) => {
49984
49988
  const {
49985
49989
  inputProblem,
49990
+ routedSchematicPortIdBySchematicPortId,
49986
49991
  connKeyToSourceNet,
49987
49992
  schematicPortIdsInScope,
49988
49993
  schematicPortIdsWithExternallyRoutedRepresentations,
@@ -49998,7 +50003,10 @@ var renderSchematicTracesForSheet = ({
49998
50003
  netLabels
49999
50004
  });
50000
50005
  if (inputProblem.chips.length === 0) return;
50001
- const schematicPortIdsWithPreExistingNetLabels = getSchematicPortIdsWithAssignedNetLabels(netLabelsInScope);
50006
+ const schematicPortIdsWithPreExistingNetLabels = getSchematicPortIdsWithAssignedNetLabels(
50007
+ netLabelsInScope,
50008
+ routedSchematicPortIdBySchematicPortId
50009
+ );
50002
50010
  const hasRouteableSchematicConnections = inputProblem.directConnections.length > 0 || inputProblem.netConnections.length > 0;
50003
50011
  if (!hasRouteableSchematicConnections) {
50004
50012
  insertNetLabelsForPortsMissingTrace({
@@ -50040,6 +50048,7 @@ var renderSchematicTracesForSheet = ({
50040
50048
  });
50041
50049
  applyNetLabelPlacements({
50042
50050
  group,
50051
+ routedSchematicPortIdBySchematicPortId,
50043
50052
  solver,
50044
50053
  connKeyToSourceNet,
50045
50054
  userNetIdToConnKey,
@@ -50057,6 +50066,15 @@ var renderSchematicTracesForSheet = ({
50057
50066
  sourceTraceIdByPinPairKey,
50058
50067
  crossScopeSourceTraceIdBySchematicPortIdAndNetId
50059
50068
  });
50069
+ const { db } = group.root;
50070
+ for (const [
50071
+ schematicPortId,
50072
+ routedSchematicPortId
50073
+ ] of routedSchematicPortIdBySchematicPortId) {
50074
+ if (db.schematic_port.get(routedSchematicPortId)?.is_connected) {
50075
+ db.schematic_port.update(schematicPortId, { is_connected: true });
50076
+ }
50077
+ }
50060
50078
  insertNetLabelsForPortsMissingTrace({
50061
50079
  group,
50062
50080
  schematicPortIdsInScope,
@@ -51437,7 +51455,7 @@ function Group_getRoutingPhasePlans(group) {
51437
51455
  var package_default = {
51438
51456
  name: "@tscircuit/core",
51439
51457
  type: "module",
51440
- version: "0.0.1870",
51458
+ version: "0.0.1872",
51441
51459
  types: "dist/index.d.ts",
51442
51460
  main: "dist/index.js",
51443
51461
  module: "dist/index.js",
@@ -51492,7 +51510,7 @@ var package_default = {
51492
51510
  "@tscircuit/ngspice-spice-engine": "^0.0.20",
51493
51511
  "@tscircuit/props": "^0.0.646",
51494
51512
  "@tscircuit/schematic-match-adapt": "^0.0.18",
51495
- "@tscircuit/schematic-trace-solver": "^0.0.188",
51513
+ "@tscircuit/schematic-trace-solver": "^0.0.189",
51496
51514
  "@tscircuit/solver-utils": "^0.0.16",
51497
51515
  "@tscircuit/soup-util": "^0.0.41",
51498
51516
  "@tscircuit/via-stitch-solver": "github:tscircuit/via-stitch-solver#75653b6440e75584b052f03595afd34283ae7558",
@@ -54967,32 +54985,14 @@ var PushButton = class extends NormalComponent3 {
54967
54985
  const symPort1 = symbol.ports.find((p) => p.labels.includes("1"));
54968
54986
  const symPort2 = symbol.ports.find((p) => p.labels.includes("2"));
54969
54987
  const ports = this.selectAll("port");
54970
- const pin1Port = ports.find((p) => p.props.pinNumber === 1);
54971
- const pin2Port = ports.find((p) => p.props.pinNumber === 2);
54972
- const pin3Port = ports.find((p) => p.props.pinNumber === 3);
54973
- const pin4Port = ports.find((p) => p.props.pinNumber === 4);
54974
- const { internallyConnectedPins } = this._parsedProps;
54988
+ const pin1Port = ports.find((port) => port.props.pinNumber === 1);
54975
54989
  pin1Port.schematicSymbolPortDef = symPort1;
54976
- if (!internallyConnectedPins || internallyConnectedPins.length === 0) {
54977
- pin2Port.schematicSymbolPortDef = symPort2;
54978
- }
54979
- for (const [pn, port] of [
54980
- [2, pin2Port],
54981
- [3, pin3Port],
54982
- [4, pin4Port]
54983
- ]) {
54984
- const internallyConnectedRow = internallyConnectedPins?.find(
54985
- ([pin1, pin2]) => pin1 === `pin${pn}` || pin2 === `pin${pn}`
54986
- );
54987
- if (!internallyConnectedRow) {
54988
- port.schematicSymbolPortDef = symPort2;
54989
- break;
54990
- }
54991
- const internallyConnectedTo = internallyConnectedRow?.[0] === `pin${pn}` ? internallyConnectedRow[1] : internallyConnectedRow?.[0];
54992
- if (internallyConnectedTo === "pin1") {
54993
- continue;
54994
- }
54995
- port.schematicSymbolPortDef = symPort2;
54990
+ const firstTerminalPorts = new Set(
54991
+ pin1Port._getPortsInternallyConnectedToThisPort()
54992
+ );
54993
+ const secondTerminalPort = ports.filter((port) => port !== pin1Port && !firstTerminalPorts.has(port)).sort((a, b) => (a.props.pinNumber ?? 0) - (b.props.pinNumber ?? 0))[0];
54994
+ if (secondTerminalPort) {
54995
+ secondTerminalPort.schematicSymbolPortDef = symPort2;
54996
54996
  }
54997
54997
  }
54998
54998
  doInitialSourceRender() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.1871",
4
+ "version": "0.0.1873",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -56,7 +56,7 @@
56
56
  "@tscircuit/ngspice-spice-engine": "^0.0.20",
57
57
  "@tscircuit/props": "^0.0.646",
58
58
  "@tscircuit/schematic-match-adapt": "^0.0.18",
59
- "@tscircuit/schematic-trace-solver": "^0.0.188",
59
+ "@tscircuit/schematic-trace-solver": "^0.0.189",
60
60
  "@tscircuit/solver-utils": "^0.0.16",
61
61
  "@tscircuit/soup-util": "^0.0.41",
62
62
  "@tscircuit/via-stitch-solver": "github:tscircuit/via-stitch-solver#75653b6440e75584b052f03595afd34283ae7558",