@tscircuit/pcb-viewer 1.11.428 → 1.11.429

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.js CHANGED
@@ -10315,46 +10315,74 @@ var getPadComponent = (pad, elements) => {
10315
10315
 
10316
10316
  // node_modules/circuit-json-to-connectivity-map/dist/index.js
10317
10317
  import { doesLineIntersectLine } from "@tscircuit/math-utils";
10318
+ function findNetworkRoot(networkRoot) {
10319
+ let canonicalRoot = networkRoot;
10320
+ while (canonicalRoot.parent !== null) canonicalRoot = canonicalRoot.parent;
10321
+ let currentRoot = networkRoot;
10322
+ while (currentRoot.parent !== null && currentRoot.parent !== canonicalRoot) {
10323
+ const parentRoot = currentRoot.parent;
10324
+ currentRoot.parent = canonicalRoot;
10325
+ currentRoot = parentRoot;
10326
+ }
10327
+ return canonicalRoot;
10328
+ }
10329
+ function createNetworkRoot(nodeId, ctx) {
10330
+ const member = { nodeId, nextMember: null };
10331
+ const networkRoot = {
10332
+ parent: null,
10333
+ networkId: `connectivity_net${ctx.nextNetworkNumber++}`,
10334
+ firstMember: member,
10335
+ lastMember: member
10336
+ };
10337
+ ctx.rootByNodeId.set(nodeId, networkRoot);
10338
+ return networkRoot;
10339
+ }
10340
+ function getOrCreateNetworkRoot(nodeId, ctx) {
10341
+ const networkRoot = ctx.rootByNodeId.get(nodeId);
10342
+ return networkRoot === void 0 ? createNetworkRoot(nodeId, ctx) : findNetworkRoot(networkRoot);
10343
+ }
10344
+ function mergeNetworkRoots({
10345
+ targetRoot,
10346
+ sourceRoot
10347
+ }) {
10348
+ targetRoot.lastMember.nextMember = sourceRoot.firstMember;
10349
+ targetRoot.lastMember = sourceRoot.lastMember;
10350
+ sourceRoot.parent = targetRoot;
10351
+ }
10352
+ function getNetworkNodeIds(networkRoot) {
10353
+ const nodeIds = [];
10354
+ let member = networkRoot.firstMember;
10355
+ while (member !== null) {
10356
+ nodeIds.push(member.nodeId);
10357
+ member = member.nextMember;
10358
+ }
10359
+ return nodeIds;
10360
+ }
10318
10361
  function findConnectedNetworks(connections) {
10319
- const networks = /* @__PURE__ */ new Map();
10320
- let netCounter = 0;
10321
- function getOrCreateNetwork(nodeId) {
10322
- for (const [, network] of networks) {
10323
- if (network.has(nodeId)) {
10324
- return network;
10325
- }
10326
- }
10327
- const newNetwork = /* @__PURE__ */ new Set();
10328
- networks.set(`connectivity_net${netCounter++}`, newNetwork);
10329
- return newNetwork;
10330
- }
10362
+ const ctx = {
10363
+ rootByNodeId: /* @__PURE__ */ new Map(),
10364
+ nextNetworkNumber: 0
10365
+ };
10331
10366
  for (const connection of connections) {
10332
- let network = null;
10367
+ let targetRoot = null;
10333
10368
  for (const nodeId of connection) {
10334
- if (!network) {
10335
- network = getOrCreateNetwork(nodeId);
10336
- } else if (!network.has(nodeId)) {
10337
- const existingNetwork = getOrCreateNetwork(nodeId);
10338
- if (existingNetwork !== network) {
10339
- for (const node of existingNetwork) {
10340
- network.add(node);
10341
- }
10342
- networks.delete(
10343
- Array.from(networks.entries()).find(
10344
- ([, net]) => net === existingNetwork
10345
- )[0]
10346
- );
10347
- }
10369
+ const sourceRoot = getOrCreateNetworkRoot(nodeId, ctx);
10370
+ if (targetRoot === null) {
10371
+ targetRoot = sourceRoot;
10372
+ continue;
10373
+ }
10374
+ targetRoot = findNetworkRoot(targetRoot);
10375
+ if (sourceRoot !== targetRoot) {
10376
+ mergeNetworkRoots({ targetRoot, sourceRoot });
10348
10377
  }
10349
- network.add(nodeId);
10350
10378
  }
10351
10379
  }
10352
- return Object.fromEntries(
10353
- Array.from(networks.entries()).map(([netId, connectedNodes]) => [
10354
- netId,
10355
- Array.from(connectedNodes)
10356
- ])
10357
- );
10380
+ const networks = {};
10381
+ for (const networkRoot of ctx.rootByNodeId.values()) {
10382
+ if (networkRoot.parent !== null) continue;
10383
+ networks[networkRoot.networkId] = getNetworkNodeIds(networkRoot);
10384
+ }
10385
+ return networks;
10358
10386
  }
10359
10387
  var ConnectivityMap = class {
10360
10388
  netMap;
@@ -10470,13 +10498,17 @@ var getFullConnectivityMapFromCircuitJson = (circuitJson) => {
10470
10498
  (rp) => rp?.start_pcb_port_id
10471
10499
  )?.start_pcb_port_id;
10472
10500
  const endId = route.find((rp) => rp?.end_pcb_port_id)?.end_pcb_port_id;
10473
- if (startId && pcb_trace_id && endId) {
10474
- connections.push([startId, pcb_trace_id, endId]);
10501
+ if (startId && pcb_trace_id) {
10502
+ connections.push([startId, pcb_trace_id]);
10503
+ }
10504
+ if (pcb_trace_id && endId) {
10505
+ connections.push([pcb_trace_id, endId]);
10475
10506
  }
10476
10507
  }
10477
10508
  } else if (element.type === "pcb_via") {
10478
10509
  const { pcb_via_id, pcb_trace_id, source_trace_id, source_net_id } = element;
10479
10510
  const connectedIds = [
10511
+ ...element.pcb_port_ids ?? [],
10480
10512
  pcb_trace_id,
10481
10513
  source_trace_id,
10482
10514
  source_net_id
@@ -18652,7 +18684,7 @@ import { css as css3 } from "@emotion/css";
18652
18684
  // package.json
18653
18685
  var package_default = {
18654
18686
  name: "@tscircuit/pcb-viewer",
18655
- version: "1.11.427",
18687
+ version: "1.11.428",
18656
18688
  main: "dist/index.js",
18657
18689
  type: "module",
18658
18690
  repository: {
@@ -18695,6 +18727,7 @@ var package_default = {
18695
18727
  "@types/react": "19",
18696
18728
  "@types/react-dom": "~19.1.0",
18697
18729
  "@webgpu/types": "^0.1.72",
18730
+ "circuit-json-to-connectivity-map": "^0.0.35",
18698
18731
  esbuild: "^0.25.2",
18699
18732
  "format-si-unit": "^0.0.12",
18700
18733
  next: "^14.1.4",