@tscircuit/circuit-json-util 0.0.76 → 0.0.78

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
@@ -19,9 +19,53 @@ function connect(map, a, b) {
19
19
  }
20
20
  function buildSubtree(soup, opts) {
21
21
  if (!opts.subcircuit_id && !opts.source_group_id) return [...soup];
22
+ let effectiveOpts = opts;
23
+ if (opts.subcircuit_id) {
24
+ const subcircuitIds = /* @__PURE__ */ new Set([opts.subcircuit_id]);
25
+ const groupChildren = /* @__PURE__ */ new Map();
26
+ const groupSubcircuit = /* @__PURE__ */ new Map();
27
+ for (const elm of soup) {
28
+ if (elm.type === "source_group") {
29
+ const groupId = elm.source_group_id;
30
+ const subcircuitId = elm.subcircuit_id;
31
+ if (subcircuitId) {
32
+ groupSubcircuit.set(groupId, subcircuitId);
33
+ }
34
+ const parentId = elm.parent_source_group_id;
35
+ if (parentId) {
36
+ if (!groupChildren.has(parentId)) {
37
+ groupChildren.set(parentId, []);
38
+ }
39
+ groupChildren.get(parentId).push(groupId);
40
+ }
41
+ }
42
+ }
43
+ let rootGroupId;
44
+ for (const [groupId, subcircuitId] of groupSubcircuit) {
45
+ if (subcircuitId === opts.subcircuit_id) {
46
+ rootGroupId = groupId;
47
+ break;
48
+ }
49
+ }
50
+ if (rootGroupId) {
51
+ const collectChildSubcircuits = (groupId) => {
52
+ const children = groupChildren.get(groupId) || [];
53
+ for (const childId of children) {
54
+ const childSubcircuit = groupSubcircuit.get(childId);
55
+ if (childSubcircuit) {
56
+ subcircuitIds.add(childSubcircuit);
57
+ }
58
+ collectChildSubcircuits(childId);
59
+ }
60
+ };
61
+ collectChildSubcircuits(rootGroupId);
62
+ effectiveOpts = { ...opts, subcircuit_ids: Array.from(subcircuitIds) };
63
+ }
64
+ }
22
65
  const idMap = /* @__PURE__ */ new Map();
23
66
  for (const elm of soup) {
24
- const idVal = elm[`${elm.type}_id`];
67
+ const idKey = `${elm.type}_id`;
68
+ const idVal = elm[idKey];
25
69
  if (typeof idVal === "string") {
26
70
  idMap.set(idVal, elm);
27
71
  }
@@ -47,9 +91,17 @@ function buildSubtree(soup, opts) {
47
91
  const queue = [];
48
92
  const included = /* @__PURE__ */ new Set();
49
93
  for (const elm of soup) {
50
- if (opts.subcircuit_id && elm.subcircuit_id === opts.subcircuit_id || opts.source_group_id && (elm.source_group_id === opts.source_group_id || Array.isArray(elm.member_source_group_ids) && elm.member_source_group_ids.includes(
51
- opts.source_group_id
52
- ))) {
94
+ let shouldInclude = false;
95
+ if (effectiveOpts.subcircuit_id && "subcircuit_id" in elm && elm.subcircuit_id === effectiveOpts.subcircuit_id) {
96
+ shouldInclude = true;
97
+ } else if (effectiveOpts.subcircuit_ids && "subcircuit_id" in elm && elm.subcircuit_id && effectiveOpts.subcircuit_ids.includes(elm.subcircuit_id)) {
98
+ shouldInclude = true;
99
+ } else if (effectiveOpts.source_group_id && "source_group_id" in elm && elm.source_group_id === effectiveOpts.source_group_id) {
100
+ shouldInclude = true;
101
+ } else if (effectiveOpts.source_group_id && "member_source_group_ids" in elm && Array.isArray(elm.member_source_group_ids) && elm.member_source_group_ids.includes(effectiveOpts.source_group_id)) {
102
+ shouldInclude = true;
103
+ }
104
+ if (shouldInclude) {
53
105
  queue.push(elm);
54
106
  included.add(elm);
55
107
  }
@@ -1757,6 +1809,10 @@ function getElementRenderLayers(element) {
1757
1809
  const layer = element.layer;
1758
1810
  return [`${layer}_fabrication_note`];
1759
1811
  }
1812
+ if (element.type === "pcb_courtyard_circle" || element.type === "pcb_courtyard_polygon" || element.type === "pcb_courtyard_rect" || element.type === "pcb_courtyard_outline") {
1813
+ const layer = element.layer;
1814
+ return [`${layer}_courtyard`];
1815
+ }
1760
1816
  return [];
1761
1817
  }
1762
1818
  export {