@tscircuit/core 0.0.1292 → 0.0.1294

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 +216 -105
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -13689,7 +13689,7 @@ import {
13689
13689
  import {
13690
13690
  distance as distance10
13691
13691
  } from "circuit-json";
13692
- import Debug13 from "debug";
13692
+ import Debug14 from "debug";
13693
13693
 
13694
13694
  // lib/utils/autorouting/CapacityMeshAutorouter.ts
13695
13695
  import "@tscircuit/capacity-autorouter";
@@ -16868,19 +16868,21 @@ function convertTreeToMatchPackInputProblem(tree, db, group) {
16868
16868
  decouplingCapsGap: 0.4,
16869
16869
  partitionGap: 1.2
16870
16870
  };
16871
+ const groupOffset = group._getGlobalSchematicPositionBeforeLayout();
16871
16872
  debug6(
16872
16873
  `[${group.name}] Processing ${tree.childNodes.length} child nodes for input problem`
16873
16874
  );
16874
16875
  tree.childNodes.forEach((child, index) => {
16875
- if (isTreeChildExplicitlyPositioned(child, group)) {
16876
+ const explicitlyPositioned = isTreeChildExplicitlyPositioned(child, group);
16877
+ if (explicitlyPositioned) {
16876
16878
  debug6(
16877
- `[${group.name}] Skipping explicitly positioned child ${index} from matchpack`
16879
+ `[${group.name}] Child ${index} explicitly positioned, including as fixed chip`
16880
+ );
16881
+ } else {
16882
+ debug6(
16883
+ `[${group.name}] Processing child ${index}: nodeType=${child.nodeType}`
16878
16884
  );
16879
- return;
16880
16885
  }
16881
- debug6(
16882
- `[${group.name}] Processing child ${index}: nodeType=${child.nodeType}`
16883
- );
16884
16886
  if (child.nodeType === "component") {
16885
16887
  debug6(`[${group.name}] - Component: ${child.sourceComponent?.name}`);
16886
16888
  } else if (child.nodeType === "group") {
@@ -16928,7 +16930,13 @@ function convertTreeToMatchPackInputProblem(tree, db, group) {
16928
16930
  x: (schematicComponent.size?.width || 1) + marginLeft + marginRight,
16929
16931
  y: (schematicComponent.size?.height || 1) + marginTop + marginBottom
16930
16932
  },
16931
- availableRotations
16933
+ availableRotations,
16934
+ ...explicitlyPositioned && {
16935
+ fixedPosition: {
16936
+ x: schematicComponent.center.x - groupOffset.x,
16937
+ y: schematicComponent.center.y - groupOffset.y
16938
+ }
16939
+ }
16932
16940
  };
16933
16941
  const ports = db.schematic_port.list({
16934
16942
  schematic_component_id: schematicComponent.schematic_component_id
@@ -17276,6 +17284,13 @@ function applySchematicMatchPackLayoutToTree(group, tree) {
17276
17284
  y: placement.y + groupOffset.y
17277
17285
  };
17278
17286
  if (treeNode.nodeType === "component" && treeNode.sourceComponent) {
17287
+ const groupChild = group.children.find(
17288
+ (c) => c.source_component_id === treeNode.sourceComponent?.source_component_id
17289
+ );
17290
+ if (groupChild?._parsedProps?.schX !== void 0 || groupChild?._parsedProps?.schY !== void 0) {
17291
+ debug6(`Skipping position update for fixed chip ${chipId}`);
17292
+ continue;
17293
+ }
17279
17294
  const schematicComponent = db.schematic_component.getWhere({
17280
17295
  source_component_id: treeNode.sourceComponent.source_component_id
17281
17296
  });
@@ -17434,6 +17449,7 @@ function Group_doInitialSchematicLayoutMatchPack(group) {
17434
17449
 
17435
17450
  // lib/components/primitive-components/Group/Group_doInitialSchematicLayoutSections.ts
17436
17451
  import { getCircuitJsonTree as getCircuitJsonTree3 } from "@tscircuit/circuit-json-util";
17452
+ import Debug9 from "debug";
17437
17453
 
17438
17454
  // lib/components/primitive-components/Group/computeSchematicSectionLayoutUsingRows.ts
17439
17455
  var SECTION_GAP = 1;
@@ -17489,6 +17505,7 @@ function computeSchematicSectionLayoutUsingRows({
17489
17505
  }
17490
17506
 
17491
17507
  // lib/components/primitive-components/Group/Group_doInitialSchematicLayoutSections.ts
17508
+ var debug7 = Debug9("Group_doInitialSchematicLayoutSections");
17492
17509
  function Group_doInitialSchematicLayoutSections(group) {
17493
17510
  const { db } = group.root;
17494
17511
  const sectionNamesUsedByChildren = /* @__PURE__ */ new Set();
@@ -17555,6 +17572,14 @@ function Group_doInitialSchematicLayoutSections(group) {
17555
17572
  });
17556
17573
  }
17557
17574
  if (sectionNameToBoundsWithChildren.size <= 1) return;
17575
+ const anchoredSections = /* @__PURE__ */ new Set();
17576
+ for (const child of group.children) {
17577
+ if (!child.source_component_id) continue;
17578
+ const props = child._parsedProps;
17579
+ if (props?.schX !== void 0 || props?.schY !== void 0) {
17580
+ anchoredSections.add(child.getSchematicSectionName());
17581
+ }
17582
+ }
17558
17583
  const groupSchPositionBeforeLayout = group._getGlobalSchematicPositionBeforeLayout();
17559
17584
  const sectionPlacements = computeSchematicSectionLayoutUsingRows({
17560
17585
  sectionBlocks: Array.from(sectionNameToBoundsWithChildren.values()).map(
@@ -17568,6 +17593,12 @@ function Group_doInitialSchematicLayoutSections(group) {
17568
17593
  for (const [sectionName, placement] of sectionPlacements) {
17569
17594
  const boundsWithChildren = sectionNameToBoundsWithChildren.get(sectionName);
17570
17595
  if (!boundsWithChildren) continue;
17596
+ if (anchoredSections.has(sectionName)) {
17597
+ debug7(
17598
+ `[${group.name}] Section "${sectionName}" anchored by manual position, skipping shift`
17599
+ );
17600
+ continue;
17601
+ }
17571
17602
  const delta = {
17572
17603
  x: placement.x - boundsWithChildren.center.x,
17573
17604
  y: placement.y - boundsWithChildren.center.y
@@ -17719,7 +17750,7 @@ var Group_doInitialSchematicBoxComponentRender = (group) => {
17719
17750
 
17720
17751
  // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/Group_doInitialSchematicTraceRender.ts
17721
17752
  import { SchematicTracePipelineSolver as SchematicTracePipelineSolver3 } from "@tscircuit/schematic-trace-solver";
17722
- import Debug11 from "debug";
17753
+ import Debug12 from "debug";
17723
17754
 
17724
17755
  // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/createSchematicTraceSolverInputProblem.ts
17725
17756
  import "@tscircuit/schematic-trace-solver";
@@ -18269,8 +18300,8 @@ function computeJunctions(traces, opts = {}) {
18269
18300
  }
18270
18301
 
18271
18302
  // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/applyTracesFromSolverOutput.ts
18272
- import Debug9 from "debug";
18273
- var debug7 = Debug9("Group_doInitialSchematicTraceRender");
18303
+ import Debug10 from "debug";
18304
+ var debug8 = Debug10("Group_doInitialSchematicTraceRender");
18274
18305
  function applyTracesFromSolverOutput(args) {
18275
18306
  const {
18276
18307
  group,
@@ -18282,7 +18313,7 @@ function applyTracesFromSolverOutput(args) {
18282
18313
  const { db } = group.root;
18283
18314
  const traces = solver.netLabelTraceCollisionSolver?.getOutput().traces ?? solver.traceCleanupSolver?.getOutput().traces ?? solver.traceLabelOverlapAvoidanceSolver?.getOutput().traces ?? solver.schematicTraceLinesSolver?.solvedTracePaths;
18284
18315
  const pendingTraces = [];
18285
- debug7(`Traces inside SchematicTraceSolver output: ${(traces ?? []).length}`);
18316
+ debug8(`Traces inside SchematicTraceSolver output: ${(traces ?? []).length}`);
18286
18317
  for (const solvedTracePath of traces ?? []) {
18287
18318
  const uniquePinIds = Array.from(new Set(solvedTracePath.pinIds ?? []));
18288
18319
  const solvedTraceSchematicPortIds = uniquePinIds.map((pinId) => pinIdToSchematicPortId.get(pinId)).filter((id) => Boolean(id));
@@ -18290,14 +18321,14 @@ function applyTracesFromSolverOutput(args) {
18290
18321
  (id) => schematicPortIdsWithPreExistingNetLabels.has(id)
18291
18322
  );
18292
18323
  if (isNetLabelStubTrace) {
18293
- debug7(
18324
+ debug8(
18294
18325
  `Skipping solver netlabel stub trace ${solvedTracePath?.mspPairId} because schematic port already has a netlabel`
18295
18326
  );
18296
18327
  continue;
18297
18328
  }
18298
18329
  const points = solvedTracePath?.tracePath;
18299
18330
  if (!Array.isArray(points) || points.length < 2) {
18300
- debug7(
18331
+ debug8(
18301
18332
  `Skipping trace ${solvedTracePath?.pinIds.join(",")} because it has less than 2 points`
18302
18333
  );
18303
18334
  continue;
@@ -18335,7 +18366,7 @@ function applyTracesFromSolverOutput(args) {
18335
18366
  subcircuit_connectivity_map_key
18336
18367
  });
18337
18368
  }
18338
- debug7(
18369
+ debug8(
18339
18370
  `Applying ${pendingTraces.length} traces from SchematicTraceSolver output`
18340
18371
  );
18341
18372
  const withCrossings = computeCrossings(
@@ -18398,8 +18429,8 @@ var getNetNameFromPorts = (ports) => {
18398
18429
  };
18399
18430
 
18400
18431
  // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/applyNetLabelPlacements.ts
18401
- import Debug10 from "debug";
18402
- var debug8 = Debug10("Group_doInitialSchematicTraceRender");
18432
+ import Debug11 from "debug";
18433
+ var debug9 = Debug11("Group_doInitialSchematicTraceRender");
18403
18434
  function applyNetLabelPlacements(args) {
18404
18435
  const {
18405
18436
  group,
@@ -18413,16 +18444,41 @@ function applyNetLabelPlacements(args) {
18413
18444
  } = args;
18414
18445
  const { db } = group.root;
18415
18446
  const netLabelPlacements = solver.netLabelTraceCollisionSolver?.getOutput().netLabelPlacements ?? solver.netLabelPlacementSolver?.netLabelPlacements ?? solver.traceLabelOverlapAvoidanceSolver?.getOutput().netLabelPlacements ?? [];
18416
- const netLabelPlacementCountByGlobalNetId = /* @__PURE__ */ new Map();
18447
+ const dedupedNetLabelPlacements = [];
18448
+ const netLabelPlacementKeys = /* @__PURE__ */ new Set();
18417
18449
  for (const placement of netLabelPlacements) {
18450
+ const pinIds = [...placement.pinIds ?? []].sort();
18451
+ const key = `${placement.globalConnNetId}|${pinIds.join("::")}|${placement.netId ?? ""}`;
18452
+ if (netLabelPlacementKeys.has(key)) {
18453
+ debug9(
18454
+ `skipping duplicate placement for "${placement.netId}" REASON:identical net label placement`
18455
+ );
18456
+ continue;
18457
+ }
18458
+ netLabelPlacementKeys.add(key);
18459
+ dedupedNetLabelPlacements.push(placement);
18460
+ }
18461
+ const netLabelPlacementCountByGlobalNetId = /* @__PURE__ */ new Map();
18462
+ const routedPairKeysByGlobalNetId = /* @__PURE__ */ new Map();
18463
+ const globalNetIdsWithPortOnlyPlacements = /* @__PURE__ */ new Set();
18464
+ for (const placement of dedupedNetLabelPlacements) {
18418
18465
  netLabelPlacementCountByGlobalNetId.set(
18419
18466
  placement.globalConnNetId,
18420
18467
  (netLabelPlacementCountByGlobalNetId.get(placement.globalConnNetId) ?? 0) + 1
18421
18468
  );
18469
+ if ((placement.pinIds?.length ?? 0) > 1) {
18470
+ if (!routedPairKeysByGlobalNetId.has(placement.globalConnNetId)) {
18471
+ routedPairKeysByGlobalNetId.set(placement.globalConnNetId, /* @__PURE__ */ new Set());
18472
+ }
18473
+ routedPairKeysByGlobalNetId.get(placement.globalConnNetId).add(placement.pinIds.slice().sort().join("::"));
18474
+ }
18475
+ if ((placement.pinIds?.length ?? 0) <= 1) {
18476
+ globalNetIdsWithPortOnlyPlacements.add(placement.globalConnNetId);
18477
+ }
18422
18478
  }
18423
18479
  const globalConnMap = solver.mspConnectionPairSolver.globalConnMap;
18424
- for (const placement of netLabelPlacements) {
18425
- debug8(`processing placement: ${placement.netId}`);
18480
+ for (const placement of dedupedNetLabelPlacements) {
18481
+ debug9(`processing placement: ${placement.netId}`);
18426
18482
  const placementUserNetId = globalConnMap.getIdsConnectedToNet(placement.globalConnNetId).find((id) => userNetIdToConnKey.get(id));
18427
18483
  const placementConnKey = userNetIdToConnKey.get(placementUserNetId);
18428
18484
  const anchor_position = placement.anchorPoint;
@@ -18438,7 +18494,7 @@ function applyNetLabelPlacements(args) {
18438
18494
  if (schPortIds.some(
18439
18495
  (schPortId) => schematicPortIdsWithPreExistingNetLabels.has(schPortId)
18440
18496
  )) {
18441
- debug8(
18497
+ debug9(
18442
18498
  `skipping net label placement for "${placement.netId}" REASON:schematic port has pre-existing net label`
18443
18499
  );
18444
18500
  continue;
@@ -18454,7 +18510,7 @@ function applyNetLabelPlacements(args) {
18454
18510
  const hasSingleLabelPlacement = (netLabelPlacementCountByGlobalNetId.get(placement.globalConnNetId) ?? 0) <= 1;
18455
18511
  const shouldSkipImplicitSignalNetLabel = !hasExplicitPortNetTrace && !isPowerOrGroundNet && hasRoutedTraceForPlacementPort && hasSingleLabelPlacement;
18456
18512
  if (shouldSkipImplicitSignalNetLabel) {
18457
- debug8(
18513
+ debug9(
18458
18514
  `skipping net label placement for "${placement.netId}" REASON:schematic port has routed trace`
18459
18515
  );
18460
18516
  continue;
@@ -18477,10 +18533,12 @@ function applyNetLabelPlacements(args) {
18477
18533
  }
18478
18534
  const ports = group.selectAll("port").filter((p) => p._getSubcircuitConnectivityKey() === placementConnKey);
18479
18535
  const { name: text, wasAssignedDisplayLabel } = getNetNameFromPorts(ports);
18480
- if (!wasAssignedDisplayLabel && (netLabelPlacementCountByGlobalNetId.get(placement.globalConnNetId) ?? 0) <= 1 && schPortIds.some(
18536
+ const isRoutedPairPlacement = (placement.pinIds?.length ?? 0) > 1;
18537
+ const shouldKeepRoutedPairLabel = isRoutedPairPlacement && (globalNetIdsWithPortOnlyPlacements.has(placement.globalConnNetId) || (routedPairKeysByGlobalNetId.get(placement.globalConnNetId)?.size ?? 0) > 1);
18538
+ if (!wasAssignedDisplayLabel && !shouldKeepRoutedPairLabel && schPortIds.some(
18481
18539
  (schPortId) => schematicPortIdsWithRoutedTraces.has(schPortId)
18482
18540
  )) {
18483
- debug8(
18541
+ debug9(
18484
18542
  `skipping net label placement for "${placement.netId}" REASON:schematic port has routed traces and no display label`
18485
18543
  );
18486
18544
  continue;
@@ -18504,6 +18562,26 @@ function applyNetLabelPlacements(args) {
18504
18562
  // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/insertNetLabelsForPortsMissingTrace.ts
18505
18563
  var NEAR_EXISTING_NET_LABEL_DISTANCE = 0.5;
18506
18564
  var SAME_ANCHOR_POSITION_DISTANCE = 0.1;
18565
+ var doesSchematicNetLabelRepresentCurrentSourceConnection = (args) => {
18566
+ const { nl, connKey, sourceNet, text } = args;
18567
+ if (sourceNet?.source_net_id && nl.source_net_id) {
18568
+ return nl.source_net_id === sourceNet.source_net_id;
18569
+ }
18570
+ if (nl.source_net_id) {
18571
+ return nl.source_net_id === connKey;
18572
+ }
18573
+ return nl.text === text;
18574
+ };
18575
+ var getSourcePortNetLabelText = (db, sourcePortId) => {
18576
+ const sourcePort = db.source_port.get(sourcePortId);
18577
+ if (!sourcePort) return void 0;
18578
+ let sourceComponent;
18579
+ if (sourcePort.source_component_id) {
18580
+ sourceComponent = db.source_component.get(sourcePort.source_component_id);
18581
+ }
18582
+ if (!sourceComponent?.name || !sourcePort.name) return void 0;
18583
+ return `${sourceComponent.name}_${sourcePort.name}`;
18584
+ };
18507
18585
  var insertNetLabelsForPortsMissingTrace = ({
18508
18586
  allSourceAndSchematicPortIdsInScope,
18509
18587
  group,
@@ -18523,10 +18601,14 @@ var insertNetLabelsForPortsMissingTrace = ({
18523
18601
  const connKey = sourcePort?.subcircuit_connectivity_map_key;
18524
18602
  if (!connKey) continue;
18525
18603
  const sourceNet = connKeyToSourceNet.get(connKey);
18526
- if (!sourceNet) {
18527
- continue;
18528
- }
18529
- const text = sourceNet.name || sourceNet.source_net_id || connKey;
18604
+ const connectedSourcePortIdsForKey = Array.from(
18605
+ allSourceAndSchematicPortIdsInScope
18606
+ ).map((portId) => schPortIdToSourcePortId.get(portId)).filter((sourcePortId) => {
18607
+ if (!sourcePortId) return false;
18608
+ return db.source_port.get(sourcePortId)?.subcircuit_connectivity_map_key === connKey;
18609
+ });
18610
+ const implicitPortLabelText = connectedSourcePortIdsForKey.map((sourcePortId) => getSourcePortNetLabelText(db, sourcePortId)).filter((label) => Boolean(label)).join("/");
18611
+ const text = sourceNet?.name || sourceNet?.source_net_id || implicitPortLabelText || connKey;
18530
18612
  const connectedPortCountForKey = Array.from(
18531
18613
  allSourceAndSchematicPortIdsInScope
18532
18614
  ).filter((portId) => {
@@ -18534,13 +18616,12 @@ var insertNetLabelsForPortsMissingTrace = ({
18534
18616
  if (!sourcePortId) return false;
18535
18617
  return db.source_port.get(sourcePortId)?.subcircuit_connectivity_map_key === connKey;
18536
18618
  }).length;
18537
- const isGndNet = sourceNet.is_ground;
18538
- const isPowerNet = !isGndNet && sourceNet.is_power;
18539
- const usePowerSymbolSide = connectedPortCountForKey > 1;
18619
+ const isGndNet = sourceNet?.is_ground ?? false;
18620
+ const isPowerNet = !isGndNet && (sourceNet?.is_power ?? false);
18540
18621
  let side;
18541
- if (usePowerSymbolSide && isGndNet) {
18622
+ if (isGndNet) {
18542
18623
  side = "top";
18543
- } else if (usePowerSymbolSide && isPowerNet) {
18624
+ } else if (isPowerNet) {
18544
18625
  side = "bottom";
18545
18626
  } else {
18546
18627
  side = getEnteringEdgeFromDirection(
@@ -18552,32 +18633,40 @@ var insertNetLabelsForPortsMissingTrace = ({
18552
18633
  anchor_side: side,
18553
18634
  text
18554
18635
  });
18555
- const sameNetLabel = db.schematic_net_label.list().find((nl) => {
18556
- if (sourceNet.source_net_id && nl.source_net_id) {
18557
- return nl.source_net_id === sourceNet.source_net_id;
18558
- }
18559
- return nl.text === (sourceNet.name || connKey);
18560
- });
18561
- if (sameNetLabel && connectedPortCountForKey <= 1) {
18562
- db.schematic_net_label.update(sameNetLabel.schematic_net_label_id, {
18563
- text,
18564
- anchor_position: schPort.center,
18565
- center,
18566
- anchor_side: side
18636
+ const existingNetLabelForCurrentSourceConnection = db.schematic_net_label.list().find((nl) => {
18637
+ return doesSchematicNetLabelRepresentCurrentSourceConnection({
18638
+ nl,
18639
+ connKey,
18640
+ sourceNet,
18641
+ text
18567
18642
  });
18568
- continue;
18569
- }
18570
- if (sameNetLabel) {
18571
- const dx = sameNetLabel.anchor_position.x - schPort.center.x;
18572
- const dy = sameNetLabel.anchor_position.y - schPort.center.y;
18573
- const labelIsNearPort = dx * dx + dy * dy < NEAR_EXISTING_NET_LABEL_DISTANCE * NEAR_EXISTING_NET_LABEL_DISTANCE;
18574
- if (labelIsNearPort && sourceNet.is_ground) {
18575
- db.schematic_net_label.update(sameNetLabel.schematic_net_label_id, {
18643
+ });
18644
+ if (existingNetLabelForCurrentSourceConnection && connectedPortCountForKey <= 1) {
18645
+ db.schematic_net_label.update(
18646
+ existingNetLabelForCurrentSourceConnection.schematic_net_label_id,
18647
+ {
18576
18648
  text,
18577
18649
  anchor_position: schPort.center,
18578
18650
  center,
18579
18651
  anchor_side: side
18580
- });
18652
+ }
18653
+ );
18654
+ continue;
18655
+ }
18656
+ if (existingNetLabelForCurrentSourceConnection) {
18657
+ const dx = existingNetLabelForCurrentSourceConnection.anchor_position.x - schPort.center.x;
18658
+ const dy = existingNetLabelForCurrentSourceConnection.anchor_position.y - schPort.center.y;
18659
+ const labelIsNearPort = dx * dx + dy * dy < NEAR_EXISTING_NET_LABEL_DISTANCE * NEAR_EXISTING_NET_LABEL_DISTANCE;
18660
+ if (labelIsNearPort && isGndNet) {
18661
+ db.schematic_net_label.update(
18662
+ existingNetLabelForCurrentSourceConnection.schematic_net_label_id,
18663
+ {
18664
+ text,
18665
+ anchor_position: schPort.center,
18666
+ center,
18667
+ anchor_side: side
18668
+ }
18669
+ );
18581
18670
  continue;
18582
18671
  }
18583
18672
  const existingAtPort = db.schematic_net_label.list().some((nl) => {
@@ -18586,16 +18675,41 @@ var insertNetLabelsForPortsMissingTrace = ({
18586
18675
  if (dx2 * dx2 + dy2 * dy2 >= SAME_ANCHOR_POSITION_DISTANCE * SAME_ANCHOR_POSITION_DISTANCE) {
18587
18676
  return false;
18588
18677
  }
18589
- if (sourceNet.source_net_id && nl.source_net_id) {
18590
- return nl.source_net_id === sourceNet.source_net_id;
18591
- }
18592
- return nl.text === (sourceNet.name || connKey);
18678
+ return doesSchematicNetLabelRepresentCurrentSourceConnection({
18679
+ nl,
18680
+ connKey,
18681
+ sourceNet,
18682
+ text
18683
+ });
18593
18684
  });
18594
18685
  if (existingAtPort) continue;
18595
18686
  }
18687
+ if (!sourceNet) {
18688
+ for (const nl of db.schematic_net_label.list()) {
18689
+ if (nl.source_net_id !== connKey) continue;
18690
+ const isAttachedToConnectedPort = connectedSourcePortIdsForKey.some(
18691
+ (sourcePortId) => {
18692
+ const schPortId = Array.from(
18693
+ schPortIdToSourcePortId.entries()
18694
+ ).find(([, id]) => id === sourcePortId)?.[0];
18695
+ let connectedSchPort;
18696
+ if (schPortId) {
18697
+ connectedSchPort = db.schematic_port.get(schPortId);
18698
+ }
18699
+ if (!connectedSchPort?.center || !nl.anchor_position) return false;
18700
+ const dx = nl.anchor_position.x - connectedSchPort.center.x;
18701
+ const dy = nl.anchor_position.y - connectedSchPort.center.y;
18702
+ return dx * dx + dy * dy < SAME_ANCHOR_POSITION_DISTANCE * SAME_ANCHOR_POSITION_DISTANCE;
18703
+ }
18704
+ );
18705
+ if (!isAttachedToConnectedPort) {
18706
+ db.schematic_net_label.delete(nl.schematic_net_label_id);
18707
+ }
18708
+ }
18709
+ }
18596
18710
  const netLabel = {
18597
18711
  text,
18598
- source_net_id: sourceNet.source_net_id,
18712
+ source_net_id: sourceNet?.source_net_id ?? connKey,
18599
18713
  anchor_position: schPort.center,
18600
18714
  center,
18601
18715
  anchor_side: side
@@ -18640,7 +18754,7 @@ var getSchematicPortIdsWithRoutedTraces = ({
18640
18754
  };
18641
18755
 
18642
18756
  // lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/Group_doInitialSchematicTraceRender.ts
18643
- var debug9 = Debug11("Group_doInitialSchematicTraceRender");
18757
+ var debug10 = Debug12("Group_doInitialSchematicTraceRender");
18644
18758
  var Group_doInitialSchematicTraceRender = (group) => {
18645
18759
  if (!group.root?._featureMspSchematicTraceRouting) return;
18646
18760
  if (!group.isSubcircuit) return;
@@ -18666,7 +18780,7 @@ var Group_doInitialSchematicTraceRender = (group) => {
18666
18780
  });
18667
18781
  return;
18668
18782
  }
18669
- if (debug9.enabled) {
18783
+ if (debug10.enabled) {
18670
18784
  group.root?.emit("debug:logOutput", {
18671
18785
  type: "debug:logOutput",
18672
18786
  name: "group-trace-render-input-problem",
@@ -18706,7 +18820,7 @@ var Group_doInitialSchematicTraceRender = (group) => {
18706
18820
 
18707
18821
  // lib/components/primitive-components/Group/Group_doInitialSimulationSpiceEngineRender.ts
18708
18822
  import { circuitJsonToSpice } from "circuit-json-to-spice";
18709
- import Debug12 from "debug";
18823
+ import Debug13 from "debug";
18710
18824
 
18711
18825
  // lib/spice/get-spicey-engine.ts
18712
18826
  import { simulate, spiceyTranToVGraphs } from "spicey";
@@ -18779,7 +18893,7 @@ function getTransientVoltageGraphNamesFromSpiceNetlist(spiceNetlist) {
18779
18893
  }
18780
18894
 
18781
18895
  // lib/components/primitive-components/Group/Group_doInitialSimulationSpiceEngineRender.ts
18782
- var debug10 = Debug12("tscircuit:core:Group_doInitialSimulationSpiceEngineRender");
18896
+ var debug11 = Debug13("tscircuit:core:Group_doInitialSimulationSpiceEngineRender");
18783
18897
  function Group_doInitialSimulationSpiceEngineRender(group) {
18784
18898
  if (!group.isSubcircuit) return;
18785
18899
  const { root } = group;
@@ -18798,10 +18912,10 @@ function Group_doInitialSimulationSpiceEngineRender(group) {
18798
18912
  try {
18799
18913
  spiceNetlist = circuitJsonToSpice(circuitJson);
18800
18914
  spiceString = spiceNetlist.toSpiceString();
18801
- debug10(`Generated SPICE string:
18915
+ debug11(`Generated SPICE string:
18802
18916
  ${spiceString}`);
18803
18917
  } catch (error) {
18804
- debug10(`Failed to convert circuit JSON to SPICE: ${error}`);
18918
+ debug11(`Failed to convert circuit JSON to SPICE: ${error}`);
18805
18919
  return;
18806
18920
  }
18807
18921
  const graphNameToProbe = /* @__PURE__ */ new Map();
@@ -18826,7 +18940,7 @@ ${spiceString}`);
18826
18940
  }
18827
18941
  }
18828
18942
  } else {
18829
- debug10(
18943
+ debug11(
18830
18944
  `Skipping probe-to-graph order mapping because counts differ: probes=${orderedSimulationProbes.length} graphNames=${graphNamesFromNetlist.length}`
18831
18945
  );
18832
18946
  }
@@ -18841,19 +18955,19 @@ ${spiceString}`);
18841
18955
  );
18842
18956
  }
18843
18957
  const effectId = `spice-simulation-${engineName}-${analogSim.source_component_id}`;
18844
- debug10(
18958
+ debug11(
18845
18959
  `Queueing simulation for spice engine: ${engineName} (id: ${effectId})`
18846
18960
  );
18847
18961
  group._queueAsyncEffect(effectId, async () => {
18848
18962
  try {
18849
- debug10(`Running simulation with engine: ${engineName}`);
18963
+ debug11(`Running simulation with engine: ${engineName}`);
18850
18964
  const result = await spiceEngine.simulate(spiceString);
18851
- debug10(
18965
+ debug11(
18852
18966
  `Simulation completed, received ${result.simulationResultCircuitJson.length} elements`
18853
18967
  );
18854
18968
  const simulationExperiment = root.db.simulation_experiment.list()[0];
18855
18969
  if (!simulationExperiment) {
18856
- debug10("No simulation experiment found, skipping result insertion");
18970
+ debug11("No simulation experiment found, skipping result insertion");
18857
18971
  return;
18858
18972
  }
18859
18973
  for (const element of result.simulationResultCircuitJson) {
@@ -18866,9 +18980,9 @@ ${spiceString}`);
18866
18980
  if (elementType && root.db[elementType]) {
18867
18981
  ;
18868
18982
  root.db[elementType].insert(element);
18869
- debug10(`Inserted ${elementType} into database`);
18983
+ debug11(`Inserted ${elementType} into database`);
18870
18984
  } else {
18871
- debug10(
18985
+ debug11(
18872
18986
  `Warning: Unknown element type ${elementType}, adding to raw db`
18873
18987
  );
18874
18988
  root.db._addElement(element);
@@ -18876,7 +18990,7 @@ ${spiceString}`);
18876
18990
  }
18877
18991
  group._markDirty("SimulationSpiceEngineRender");
18878
18992
  } catch (error) {
18879
- debug10(`Simulation failed for engine ${engineName}: ${error}`);
18993
+ debug11(`Simulation failed for engine ${engineName}: ${error}`);
18880
18994
  const simulationExperiment = root.db.simulation_experiment.list()[0];
18881
18995
  root.db.simulation_unknown_experiment_error.insert({
18882
18996
  simulation_experiment_id: simulationExperiment?.simulation_experiment_id,
@@ -20343,7 +20457,7 @@ var Group5 = class extends NormalComponent3 {
20343
20457
  return Group_getRoutingPhasePlans(this);
20344
20458
  }
20345
20459
  _hasTracesToRoute() {
20346
- const debug11 = Debug13("tscircuit:core:_hasTracesToRoute");
20460
+ const debug12 = Debug14("tscircuit:core:_hasTracesToRoute");
20347
20461
  const routingPhasePlans = this._getRoutingPhasePlans();
20348
20462
  let traceCount = 0;
20349
20463
  let hasReroutePhaseWithRegion = false;
@@ -20353,11 +20467,11 @@ var Group5 = class extends NormalComponent3 {
20353
20467
  routingPhasePlan.reroute && routingPhasePlan.region
20354
20468
  );
20355
20469
  }
20356
- debug11(`[${this.getString()}] has ${traceCount} traces to route`);
20470
+ debug12(`[${this.getString()}] has ${traceCount} traces to route`);
20357
20471
  if (traceCount > 0) return true;
20358
20472
  if (hasReroutePhaseWithRegion) {
20359
20473
  const existingTraceCount = getExistingPcbTracesForReroute(this).length;
20360
- debug11(
20474
+ debug12(
20361
20475
  `[${this.getString()}] has ${existingTraceCount} existing pcb traces available for reroute`
20362
20476
  );
20363
20477
  return existingTraceCount > 0;
@@ -20366,13 +20480,13 @@ var Group5 = class extends NormalComponent3 {
20366
20480
  }
20367
20481
  async _runEffectMakeHttpAutoroutingRequest() {
20368
20482
  const { db } = this.root;
20369
- const debug11 = Debug13("tscircuit:core:_runEffectMakeHttpAutoroutingRequest");
20483
+ const debug12 = Debug14("tscircuit:core:_runEffectMakeHttpAutoroutingRequest");
20370
20484
  const props = this._parsedProps;
20371
20485
  const autorouterConfig = this._getAutorouterConfig();
20372
20486
  const serverUrl = autorouterConfig.serverUrl;
20373
20487
  const serverMode = autorouterConfig.serverMode;
20374
20488
  const fetchWithDebug = (url, options) => {
20375
- debug11("fetching", url);
20489
+ debug12("fetching", url);
20376
20490
  if (options.headers) {
20377
20491
  options.headers["Tscircuit-Core-Version"] = this.root?.getCoreVersion();
20378
20492
  }
@@ -20490,8 +20604,8 @@ var Group5 = class extends NormalComponent3 {
20490
20604
  async _runLocalAutorouting() {
20491
20605
  const { db } = this.root;
20492
20606
  const props = this._parsedProps;
20493
- const debug11 = Debug13("tscircuit:core:_runLocalAutorouting");
20494
- debug11(`[${this.getString()}] starting local autorouting`);
20607
+ const debug12 = Debug14("tscircuit:core:_runLocalAutorouting");
20608
+ debug12(`[${this.getString()}] starting local autorouting`);
20495
20609
  const autorouterConfig = this._getAutorouterConfig();
20496
20610
  const isLaserPrefabPreset = this._isLaserPrefabAutorouter(autorouterConfig);
20497
20611
  const isAutoJumperPreset = this._isAutoJumperAutorouter(autorouterConfig);
@@ -20591,14 +20705,14 @@ var Group5 = class extends NormalComponent3 {
20591
20705
  simpleRouteJson.availableJumperTypes = phaseAutorouterConfig.availableJumperTypes;
20592
20706
  }
20593
20707
  }
20594
- if (debug11.enabled) {
20708
+ if (debug12.enabled) {
20595
20709
  ;
20596
20710
  global.debugOutputArray?.push({
20597
20711
  name: `simpleroutejson-${this.props.name}.json`,
20598
20712
  obj: simpleRouteJson
20599
20713
  });
20600
20714
  }
20601
- if (debug11.enabled) {
20715
+ if (debug12.enabled) {
20602
20716
  const graphicsObject = convertSrjToGraphicsObject(
20603
20717
  simpleRouteJson
20604
20718
  );
@@ -20637,11 +20751,11 @@ var Group5 = class extends NormalComponent3 {
20637
20751
  const routingPromise = new Promise(
20638
20752
  (resolve, reject) => {
20639
20753
  autorouter.on("complete", (event) => {
20640
- debug11(`[${this.getString()}] local autorouting complete`);
20754
+ debug12(`[${this.getString()}] local autorouting complete`);
20641
20755
  resolve(event.traces);
20642
20756
  });
20643
20757
  autorouter.on("error", (event) => {
20644
- debug11(
20758
+ debug12(
20645
20759
  `[${this.getString()}] local autorouting error: ${event.error.message}`
20646
20760
  );
20647
20761
  reject(event.error);
@@ -20755,7 +20869,7 @@ var Group5 = class extends NormalComponent3 {
20755
20869
  }
20756
20870
  }
20757
20871
  doInitialPcbTraceRender() {
20758
- const debug11 = Debug13("tscircuit:core:doInitialPcbTraceRender");
20872
+ const debug12 = Debug14("tscircuit:core:doInitialPcbTraceRender");
20759
20873
  if (!this.isSubcircuit) return;
20760
20874
  if (this.root?.pcbDisabled) return;
20761
20875
  if (this.root?.pcbRoutingDisabled || this.getInheritedProperty("routingDisabled"))
@@ -20763,12 +20877,12 @@ var Group5 = class extends NormalComponent3 {
20763
20877
  if (this._isInflatedFromCircuitJson) return;
20764
20878
  if (this._shouldUseTraceByTraceRouting()) return;
20765
20879
  if (!this._areChildSubcircuitsRouted()) {
20766
- debug11(
20880
+ debug12(
20767
20881
  `[${this.getString()}] child subcircuits are not routed, skipping async autorouting until subcircuits routed`
20768
20882
  );
20769
20883
  return;
20770
20884
  }
20771
- debug11(
20885
+ debug12(
20772
20886
  `[${this.getString()}] no child subcircuits to wait for, initiating async routing`
20773
20887
  );
20774
20888
  if (!this._hasTracesToRoute()) return;
@@ -20779,13 +20893,13 @@ var Group5 = class extends NormalComponent3 {
20779
20893
  Group_doInitialSchematicTraceRender(this);
20780
20894
  }
20781
20895
  updatePcbTraceRender() {
20782
- const debug11 = Debug13("tscircuit:core:updatePcbTraceRender");
20783
- debug11(`[${this.getString()}] updating...`);
20896
+ const debug12 = Debug14("tscircuit:core:updatePcbTraceRender");
20897
+ debug12(`[${this.getString()}] updating...`);
20784
20898
  if (!this.isSubcircuit) return;
20785
20899
  if (this._isInflatedFromCircuitJson) return;
20786
20900
  if (this._shouldRouteAsync() && this._hasTracesToRoute() && !this._hasStartedAsyncAutorouting) {
20787
20901
  if (this._areChildSubcircuitsRouted()) {
20788
- debug11(
20902
+ debug12(
20789
20903
  `[${this.getString()}] child subcircuits are now routed, starting async autorouting`
20790
20904
  );
20791
20905
  this._startAsyncAutorouting();
@@ -20796,14 +20910,14 @@ var Group5 = class extends NormalComponent3 {
20796
20910
  if (this._shouldUseTraceByTraceRouting()) return;
20797
20911
  const { db } = this.root;
20798
20912
  if (this._asyncAutoroutingResult.output_simple_route_json) {
20799
- debug11(
20913
+ debug12(
20800
20914
  `[${this.getString()}] updating PCB traces from simple route json (${this._asyncAutoroutingResult.output_simple_route_json.traces?.length} traces)`
20801
20915
  );
20802
20916
  this._updatePcbTraceRenderFromSimpleRouteJson();
20803
20917
  return;
20804
20918
  }
20805
20919
  if (this._asyncAutoroutingResult.output_pcb_traces) {
20806
- debug11(
20920
+ debug12(
20807
20921
  `[${this.getString()}] updating PCB traces from ${this._asyncAutoroutingResult.output_pcb_traces.length} traces`
20808
20922
  );
20809
20923
  this._updatePcbTraceRenderFromPcbTraces();
@@ -20984,10 +21098,7 @@ var Group5 = class extends NormalComponent3 {
20984
21098
  const hasAnySectionName = this.children.some(
20985
21099
  (c) => c.source_component_id !== null && c._parsedProps?.schSectionName !== void 0
20986
21100
  );
20987
- const hasAnyExplicitPosition = this.children.some(
20988
- (c) => c.source_component_id !== null && (c._parsedProps?.schX !== void 0 || c._parsedProps?.schY !== void 0)
20989
- );
20990
- const hasSections = hasAnySectionName && !hasAnyExplicitPosition;
21101
+ const hasSections = hasAnySectionName;
20991
21102
  if (hasSections) {
20992
21103
  this._doInitialSchematicLayoutSections();
20993
21104
  this._insertSchematicBorder();
@@ -22229,7 +22340,7 @@ var DrcCheck = class extends PrimitiveComponent2 {
22229
22340
 
22230
22341
  // lib/IsolatedCircuit.ts
22231
22342
  import { su as su5 } from "@tscircuit/circuit-json-util";
22232
- import Debug14 from "debug";
22343
+ import Debug15 from "debug";
22233
22344
  import { isValidElement as isValidElement2 } from "react";
22234
22345
  import { identity as identity5 } from "transformation-matrix";
22235
22346
 
@@ -22237,7 +22348,7 @@ import { identity as identity5 } from "transformation-matrix";
22237
22348
  var package_default = {
22238
22349
  name: "@tscircuit/core",
22239
22350
  type: "module",
22240
- version: "0.0.1291",
22351
+ version: "0.0.1293",
22241
22352
  types: "dist/index.d.ts",
22242
22353
  main: "dist/index.js",
22243
22354
  module: "dist/index.js",
@@ -22281,12 +22392,12 @@ var package_default = {
22281
22392
  "@tscircuit/jlcpcb-manufacturing-specs": "git+https://github.com/tscircuit/jlcpcb-manufacturing-specs#e08af159db01a37db007e33f0a7268d0e4a279a5",
22282
22393
  "@tscircuit/krt-wasm": "^0.1.1",
22283
22394
  "@tscircuit/log-soup": "^1.0.2",
22284
- "@tscircuit/matchpack": "^0.0.16",
22395
+ "@tscircuit/matchpack": "",
22285
22396
  "@tscircuit/math-utils": "^0.0.36",
22286
22397
  "@tscircuit/miniflex": "^0.0.4",
22287
22398
  "@tscircuit/ngspice-spice-engine": "^0.0.8",
22288
22399
  "@tscircuit/props": "^0.0.542",
22289
- "@tscircuit/schematic-match-adapt": "^0.0.16",
22400
+ "@tscircuit/schematic-match-adapt": "^0.0.18",
22290
22401
  "@tscircuit/schematic-trace-solver": "^0.0.60",
22291
22402
  "@tscircuit/solver-utils": "^0.0.3",
22292
22403
  "@tscircuit/soup-util": "^0.0.41",
@@ -22597,11 +22708,11 @@ var IsolatedCircuit = class {
22597
22708
  (l) => l !== listener
22598
22709
  );
22599
22710
  }
22600
- enableDebug(debug11) {
22601
- if (typeof debug11 === "string") {
22602
- Debug14.enable(debug11);
22603
- } else if (debug11 === null || debug11 === false) {
22604
- Debug14.disable();
22711
+ enableDebug(debug12) {
22712
+ if (typeof debug12 === "string") {
22713
+ Debug15.enable(debug12);
22714
+ } else if (debug12 === null || debug12 === false) {
22715
+ Debug15.disable();
22605
22716
  }
22606
22717
  }
22607
22718
  getClientOrigin() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.1292",
4
+ "version": "0.0.1294",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -45,12 +45,12 @@
45
45
  "@tscircuit/jlcpcb-manufacturing-specs": "git+https://github.com/tscircuit/jlcpcb-manufacturing-specs#e08af159db01a37db007e33f0a7268d0e4a279a5",
46
46
  "@tscircuit/krt-wasm": "^0.1.1",
47
47
  "@tscircuit/log-soup": "^1.0.2",
48
- "@tscircuit/matchpack": "^0.0.16",
48
+ "@tscircuit/matchpack": "",
49
49
  "@tscircuit/math-utils": "^0.0.36",
50
50
  "@tscircuit/miniflex": "^0.0.4",
51
51
  "@tscircuit/ngspice-spice-engine": "^0.0.8",
52
52
  "@tscircuit/props": "^0.0.542",
53
- "@tscircuit/schematic-match-adapt": "^0.0.16",
53
+ "@tscircuit/schematic-match-adapt": "^0.0.18",
54
54
  "@tscircuit/schematic-trace-solver": "^0.0.60",
55
55
  "@tscircuit/solver-utils": "^0.0.3",
56
56
  "@tscircuit/soup-util": "^0.0.41",