@tscircuit/runframe 0.0.2514 → 0.0.2516

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.
@@ -2195,7 +2195,7 @@ var usePostHogActivity = (properties) => {
2195
2195
  };
2196
2196
 
2197
2197
  // package.json
2198
- var version = "0.0.2513";
2198
+ var version = "0.0.2515";
2199
2199
  var package_default = {
2200
2200
  name: "@tscircuit/runframe",
2201
2201
  main: "dist/preview.js",
@@ -2256,7 +2256,7 @@ var package_default = {
2256
2256
  "@tscircuit/internal-dynamic-import": "^0.0.15",
2257
2257
  "@tscircuit/pcb-viewer": "1.11.390",
2258
2258
  "@tscircuit/props": "^0.0.612",
2259
- "@tscircuit/schematic-viewer": "^2.0.87",
2259
+ "@tscircuit/schematic-viewer": "^2.0.88",
2260
2260
  "@types/bun": "latest",
2261
2261
  "@types/debug": "^4.1.12",
2262
2262
  "@types/react": "^19.1.10",
@@ -2317,7 +2317,7 @@ var package_default = {
2317
2317
  },
2318
2318
  dependencies: {
2319
2319
  "@tscircuit/core": "^0.0.1705",
2320
- "@tscircuit/eval": "^0.0.1237",
2320
+ "@tscircuit/eval": "^0.0.1238",
2321
2321
  "@tscircuit/solver-utils": "^0.0.7",
2322
2322
  debug: "^4.4.0",
2323
2323
  "format-si-unit": "^0.0.12"
package/dist/preview.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  SchematicViewer,
9
9
  useOrderDialog,
10
10
  useOrderDialogCli
11
- } from "./chunk-XWNRJRCU.js";
11
+ } from "./chunk-WW262BNB.js";
12
12
  export {
13
13
  BomTable,
14
14
  CadViewer,
package/dist/runner.js CHANGED
@@ -40,7 +40,7 @@ import {
40
40
  useRunFrameStore,
41
41
  useRunnerStore,
42
42
  useStyles
43
- } from "./chunk-XWNRJRCU.js";
43
+ } from "./chunk-WW262BNB.js";
44
44
 
45
45
  // lib/components/RunFrame/RunFrame.tsx
46
46
  import { createCircuitWebWorker } from "@tscircuit/eval/worker";
@@ -5614,11 +5614,11 @@ ${N}
5614
5614
  ### Error
5615
5615
  \`\`\`
5616
5616
  ${b.type}: ${H}
5617
- \`\`\``}d(P,R)},children:[q.jsx(E9e,{className:"rf-w-4 rf-h-4"}),"Report Issue"]})]})]})})};function bzo(t,e){return Array.isArray(e)?[t.a*e[0]+t.c*e[1]+t.e,t.b*e[0]+t.d*e[1]+t.f]:{x:t.a*e.x+t.c*e.y+t.e,y:t.b*e.x+t.d*e.y+t.f}}function Dzo(){return{a:1,c:0,e:0,b:0,d:1,f:0}}function c7e(t){return typeof t>"u"}function Ux(t,e=0){return{a:1,c:0,e:t,b:0,d:1,f:e}}function l7e(...t){t=Array.isArray(t[0])?t[0]:t;const e=(n,o)=>({a:n.a*o.a+n.c*o.b,c:n.a*o.c+n.c*o.d,e:n.a*o.e+n.c*o.f+n.e,b:n.b*o.a+n.d*o.b,d:n.b*o.c+n.d*o.d,f:n.b*o.e+n.d*o.f+n.f});switch(t.length){case 0:throw new Error("no matrices provided");case 1:return t[0];case 2:return e(t[0],t[1]);default:{const[n,o,...i]=t,r=e(n,o);return l7e(r,...i)}}}function D8(...t){return l7e(...t)}function lFt(t,e=void 0,n=void 0,o=void 0){c7e(e)&&(e=t);const i={a:t,c:0,e:0,b:0,d:e,f:0};return c7e(n)||c7e(o)?i:l7e([Ux(n,o),i,Ux(-n,-o)])}var gFt=({initialTransform:t,initialTouch1:e,initialTouch2:n,finalTouch1:o,finalTouch2:i})=>{if(!o||!i)return t;const r={x:(e.x+n.x)/2,y:(e.y+n.y)/2},s={x:(o.x+i.x)/2,y:(o.y+i.y)/2},a=Math.hypot(n.x-e.x,n.y-e.y),A=Math.hypot(i.x-o.x,i.y-o.y),c=a===0?1:A/a,l=s.x-r.x,g=s.y-r.y;return D8(Ux(l,g),Ux(r.x,r.y),lFt(c,c),Ux(-r.x,-r.y),t)},Mz=(t={})=>{const e=Z.useRef(null),[n,o]=Z.useState(0),i=t.canvasElm??e.current,[r,s]=Z.useState(t.initialTransform??Dzo()),[a,A]=Z.useState(0),[c,l]=Z.useReducer(f=>f+1,0),g=Z.useCallback(f=>{t.onSetTransform&&t.onSetTransform(f),t.transform||s(f)},[t.onSetTransform,s]),u=Z.useCallback(f=>{g(f),l()},[g]),h=t.transform??r,d=Z.useCallback(()=>{o(Date.now())},[]),_=Z.useRef("none"),m=Z.useRef(null),p=Z.useRef(null);Z.useEffect(()=>{const f=t.canvasElm??e.current;if(f&&!i){A(a+1);return}if(!f){const W=setTimeout(()=>{A(a+1)},100);return()=>clearTimeout(W)}let C=t.transform??r,y={x:0,y:0},E={x:0,y:0},B=!1;const Q=W=>({x:W.pageX-f.getBoundingClientRect().left-window.scrollX,y:W.pageY-f.getBoundingClientRect().top-window.scrollY});function b(W){t.enabled!==!1&&(t.shouldDrag&&!t.shouldDrag(W)||(y=Q(W),!(Date.now()-n<100)&&(B=!0,W.preventDefault())))}function P(W){if(!B||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(W))return;E=Q(W);const j=D8(Ux(E.x-y.x,E.y-y.y),C);g(j),C=j,B=!1}function N(W){if(Q(W),!B||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(W))return;E=Q(W);const j=D8(Ux(E.x-y.x,E.y-y.y),C);g(j)}function R(W){if(t.enabled===!1||t.shouldDrag&&!t.shouldDrag(W))return;const j=Q(W),re=D8(Ux(j.x,j.y),lFt(1-W.deltaY/1e3,1-W.deltaY/1e3),Ux(-j.x,-j.y),C);g(re),C=re,W.preventDefault()}function H(W){if(!B||t.shouldDrag&&!t.shouldDrag(W))return;if(f){const re=f.getBoundingClientRect();if(W.clientX>=re.left+10&&W.clientX<=re.right-10&&W.clientY>=re.top+10&&W.clientY<=re.bottom-10)return}B=!1,E=Q(W);const j=D8(Ux(E.x-y.x,E.y-y.y),C);g(j),C=j}function G(W){if(W.preventDefault(),t.enabled!==!1){if(W.touches.length===1){_.current="drag";const j=W.touches[0];m.current={initialTransform:C,initialTouch:{x:j.clientX,y:j.clientY}}}else if(W.touches.length===2){_.current="pinch";const j=W.touches[0],re=W.touches[1];p.current={initialTransform:C,initialTouch1:{x:j.clientX,y:j.clientY},initialTouch2:{x:re.clientX,y:re.clientY},finalTouch1:null,finalTouch2:null}}}}function O(W){if(W.preventDefault(),t.enabled!==!1){if(_.current==="drag"&&W.touches.length===1&&m.current){const j=W.touches[0],re={x:j.clientX,y:j.clientY},ne=re.x-m.current.initialTouch.x,X=re.y-m.current.initialTouch.y,ee=D8(Ux(ne,X),m.current.initialTransform);g(ee)}else if(_.current==="pinch"&&W.touches.length===2&&p.current){const j=W.touches[0],re=W.touches[1];p.current.finalTouch1={x:j.clientX,y:j.clientY},p.current.finalTouch2={x:re.clientX,y:re.clientY};const ne=gFt(p.current);g(ne)}}}function U(W){W.preventDefault();const j=W.changedTouches[0];if(_.current==="drag"&&m.current&&j){const re={x:j.clientX,y:j.clientY},ne=re.x-m.current.initialTouch.x,X=re.y-m.current.initialTouch.y,ee=D8(Ux(ne,X),m.current.initialTransform);g(ee),C=ee}else if(_.current==="pinch"&&p.current){const re=gFt(p.current);g(re),C=re}_.current="none",m.current=null,p.current=null}return f.addEventListener("mousedown",b),f.addEventListener("mouseup",P),window.addEventListener("mousemove",N),f.addEventListener("mouseout",H),f.addEventListener("wheel",R),f.addEventListener("touchstart",G,{passive:!1}),f.addEventListener("touchmove",O,{passive:!1}),f.addEventListener("touchend",U,{passive:!1}),f.addEventListener("touchcancel",U,{passive:!1}),()=>{f.removeEventListener("mousedown",b),f.removeEventListener("mouseup",P),window.removeEventListener("mousemove",N),f.removeEventListener("mouseout",H),f.removeEventListener("wheel",R),f.removeEventListener("touchstart",G),f.removeEventListener("touchmove",O),f.removeEventListener("touchend",U),f.removeEventListener("touchcancel",U)}},[i,a,c,n,t.enabled,t.shouldDrag]);const I=Z.useCallback(f=>bzo(h,f),[h]);return{ref:e,transform:h,applyTransformToPoint:I,setTransform:u,cancelDrag:d}},Pzo=Mz;function uFt(t,e,n){if(!e||!n)return;let o=t.get(e);o||(o=new Set,t.set(e,o)),o.add(n);let i=t.get(n);i||(i=new Set,t.set(n,i)),i.add(e)}function vzo(t,e){if(!e.subcircuit_id&&!e.source_group_id)return[...t];let n=e;if(e.subcircuit_id){const a=new Set([e.subcircuit_id]),A=new Map,c=new Map;for(const g of t)if(g.type==="source_group"){const u=g.source_group_id,h=g.subcircuit_id;h&&c.set(u,h);const d=g.parent_source_group_id;d&&(A.has(d)||A.set(d,[]),A.get(d).push(u))}let l;for(const[g,u]of c)if(u===e.subcircuit_id){l=g;break}if(l){const g=u=>{const h=A.get(u)||[];for(const d of h){const _=c.get(d);_&&a.add(_),g(d)}};g(l),n={...e,subcircuit_ids:Array.from(a)}}}const o=new Map;for(const a of t){const A=`${a.type}_id`,c=a[A];typeof c=="string"&&o.set(c,a)}const i=new Map;for(const a of t){const A=Object.entries(a);for(const[c,l]of A)if(c!=="parent_source_group_id"){if(c.endsWith("_id")&&typeof l=="string"){const g=o.get(l);uFt(i,a,g)}else if(c.endsWith("_ids")&&Array.isArray(l)){for(const g of l)if(typeof g=="string"){const u=o.get(g);uFt(i,a,u)}}}}const r=[],s=new Set;for(const a of t){let A=!1;(n.subcircuit_id&&"subcircuit_id"in a&&a.subcircuit_id===n.subcircuit_id||n.subcircuit_ids&&"subcircuit_id"in a&&a.subcircuit_id&&n.subcircuit_ids.includes(a.subcircuit_id)||n.source_group_id&&"source_group_id"in a&&a.source_group_id===n.source_group_id||n.source_group_id&&"member_source_group_ids"in a&&Array.isArray(a.member_source_group_ids)&&a.member_source_group_ids.includes(n.source_group_id))&&(A=!0),A&&(r.push(a),s.add(a))}for(;r.length>0;){const a=r.shift(),A=i.get(a);if(A)for(const c of A)s.has(c)||(s.add(c),r.push(c))}return t.filter(a=>s.has(a))}var g7e=((t,e={})=>{const n=t;let o=n._internal_store;if(!o){o={counts:{},editCount:0},n._internal_store=o;for(const r of n){const s=r.type,a=r[`${s}_id`];if(!a)continue;const A=Number.parseInt(a.split("_").pop());Number.isNaN(A)||(o.counts[s]=Math.max(o.counts[s]??0,A))}}const i=new Proxy({},{get:(r,s)=>{if(s==="toArray")return()=>(n.editCount=o.editCount,n);if(s==="editCount")return o.editCount;if(s==="subtree")return A=>g7e(vzo(n,A),e);if(s==="insert")return A=>{const c=A.type;if(!c)throw new Error("insert requires an element with a type");o.counts[c]??=-1,o.counts[c]++;const l=o.counts[c],g={...A,type:c,[`${c}_id`]:`${c}_${l}`};return e.validateInserts&&(Fw[c]??VP).parse(g),n.push(g),o.editCount++,g};if(s==="insertAll")return A=>A.map(c=>i.insert(c));const a=s;return{get:A=>n.find(c=>c.type===a&&c[`${a}_id`]===A),getUsing:A=>{const c=Object.keys(A);if(c.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const l=c[0],g=l.replace("_id",""),u=n.find(h=>h.type===g&&h[l]===A[l]);return u?n.find(h=>h.type===a&&h[`${a}_id`]===u[`${a}_id`]):null},getWhere:A=>{const c=Object.keys(A);return n.find(l=>l.type===a&&c.every(g=>l[g]===A[g]))},list:A=>{const c=A?Object.keys(A):[];return n.filter(l=>l.type===a&&c.every(g=>l[g]===A[g]))},insert:A=>{o.counts[a]??=-1,o.counts[a]++;const c=o.counts[a],l={type:a,[`${a}_id`]:`${a}_${c}`,...A};return e.validateInserts&&(Fw[a]??VP).parse(l),n.push(l),o.editCount++,l},delete:A=>{const c=n.find(l=>l[`${a}_id`]===A);c&&(n.splice(n.indexOf(c),1),o.editCount++)},update:(A,c)=>{const l=n.find(g=>g.type===a&&g[`${a}_id`]===A);return l?(Object.assign(l,c),o.editCount++,l):null},select:A=>{if(a==="source_component")return n.find(c=>c.type==="source_component"&&c.name===A.replace(/\./g,""));if(a==="pcb_port"||a==="source_port"||a==="schematic_port"){const[c,l]=A.replace(/\./g,"").split(/[\s\>]+/),g=n.find(h=>h.type==="source_component"&&h.name===c);if(!g)return null;const u=n.find(h=>h.type==="source_port"&&h.source_component_id===g.source_component_id&&(h.name===l||(h.port_hints??[]).includes(l)));if(!u)return null;if(a==="source_port")return u;if(a==="pcb_port")return n.find(h=>h.type==="pcb_port"&&h.source_port_id===u.source_port_id);if(a==="schematic_port")return n.find(h=>h.type==="schematic_port"&&h.source_port_id===u.source_port_id)}}}}});return i});g7e.unparsed=g7e;function u7e(t){const e=t.type;return`${e}:${t[`${e}_id`]}`}var dFt=((t,e={})=>{let n=t._internal_store_indexed;if(!n){n={counts:{},editCount:0,indexes:{}};for(const s of t){const a=s.type,A=s[`${a}_id`];if(!A)continue;const c=Number.parseInt(A.split("_").pop()||"");Number.isNaN(c)||(n.counts[a]=Math.max(n.counts[a]??0,c))}const i=e.indexConfig||{},r=n.indexes;if(i.byId&&(r.byId=new Map),i.byType&&(r.byType=new Map),i.byRelation&&(r.byRelation=new Map),i.bySubcircuit&&(r.bySubcircuit=new Map),i.byCustomField&&i.byCustomField.length>0){r.byCustomField=new Map;for(const s of i.byCustomField)r.byCustomField.set(s,new Map)}for(const s of t){if(i.byId){const a=u7e(s);r.byId.set(a,s)}if(i.byType){const a=r.byType.get(s.type)||[];a.push(s),r.byType.set(s.type,a)}if(i.byRelation){const a=Object.entries(s);for(const[A,c]of a)if(A.endsWith("_id")&&A!==`${s.type}_id`&&typeof c=="string"){const l=r.byRelation.get(A)||new Map,g=l.get(c)||[];g.push(s),l.set(c,g),r.byRelation.set(A,l)}}if(i.bySubcircuit&&"subcircuit_id"in s){const a=s.subcircuit_id;if(a&&typeof a=="string"){const A=r.bySubcircuit.get(a)||[];A.push(s),r.bySubcircuit.set(a,A)}}if(i.byCustomField&&r.byCustomField){for(const a of i.byCustomField)if(a in s){const A=s[a];if(A!==void 0&&(typeof A=="string"||typeof A=="number")){const c=String(A),l=r.byCustomField.get(a),g=l.get(c)||[];g.push(s),l.set(c,g)}}}}t._internal_store_indexed=n}return new Proxy({},{get:(i,r)=>{if(r==="toArray")return()=>(t.editCount=n.editCount,t);if(r==="editCount")return n.editCount;const s=r;return{get:a=>{const A=e.indexConfig||{};return A.byId&&n.indexes.byId?n.indexes.byId.get(`${s}:${a}`)||null:A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===a)||null:t.find(c=>c.type===s&&c[`${s}_id`]===a)||null},getUsing:a=>{const A=e.indexConfig||{},c=Object.keys(a);if(c.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const l=c[0],g=l.replace("_id","");if(A.byRelation&&n.indexes.byRelation){const h=n.indexes.byRelation.get(l);if(h){const _=(h.get(a[l])||[]).find(p=>p.type===g);if(!_)return null;const m=_[`${s}_id`];return A.byId&&n.indexes.byId?n.indexes.byId.get(`${s}:${m}`)||null:A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(I=>I[`${s}_id`]===m)||null:t.find(p=>p.type===s&&p[`${s}_id`]===m)||null}}const u=t.find(h=>h.type===g&&h[l]===a[l]);return u&&t.find(h=>h.type===s&&h[`${s}_id`]===u[`${s}_id`])||null},getWhere:a=>{const A=e.indexConfig||{},c=Object.keys(a);if(c.length===1&&A.byCustomField&&n.indexes.byCustomField){const l=c[0],g=n.indexes.byCustomField.get(l);if(g){const u=String(a[l]);return(g.get(u)||[]).find(d=>d.type===s)||null}}if("subcircuit_id"in a&&A.bySubcircuit&&n.indexes.bySubcircuit){const l=a.subcircuit_id;return(n.indexes.bySubcircuit.get(l)||[]).find(u=>u.type===s&&c.every(h=>u[h]===a[h]))||null}return A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(g=>c.every(u=>g[u]===a[u]))||null:t.find(l=>l.type===s&&c.every(g=>l[g]===a[g]))||null},list:a=>{const A=e.indexConfig||{},c=a?Object.keys(a):[];if(c.length===0&&A.byType&&n.indexes.byType)return n.indexes.byType.get(s)||[];if(c.length===1&&c[0]==="subcircuit_id"&&A.bySubcircuit&&n.indexes.bySubcircuit){const g=a.subcircuit_id;return(n.indexes.bySubcircuit.get(g)||[]).filter(h=>h.type===s)}let l;return A.byType&&n.indexes.byType?l=n.indexes.byType.get(s)||[]:l=t.filter(g=>g.type===s),c.length>0?l.filter(g=>c.every(u=>g[u]===a[u])):l},insert:a=>{n.counts[s]??=-1,n.counts[s]++;const A=n.counts[s],c={type:s,[`${s}_id`]:`${s}_${A}`,...a};e.validateInserts&&(Fw[s]??VP).parse(c),t.push(c),n.editCount++;const l=e.indexConfig||{};if(l.byId&&n.indexes.byId){const g=u7e(c);n.indexes.byId.set(g,c)}if(l.byType&&n.indexes.byType){const g=n.indexes.byType.get(s)||[];g.push(c),n.indexes.byType.set(s,g)}if(l.byRelation&&n.indexes.byRelation){const g=Object.entries(c);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${c.type}_id`&&typeof h=="string"){const d=n.indexes.byRelation.get(u)||new Map,_=d.get(h)||[];_.push(c),d.set(h,_),n.indexes.byRelation.set(u,d)}}if(l.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in c){const g=c.subcircuit_id;if(g&&typeof g=="string"){const u=n.indexes.bySubcircuit.get(g)||[];u.push(c),n.indexes.bySubcircuit.set(g,u)}}if(l.byCustomField&&n.indexes.byCustomField){for(const g of l.byCustomField)if(g in c){const u=c[g];if(u!==void 0&&(typeof u=="string"||typeof u=="number")){const h=String(u),d=n.indexes.byCustomField.get(g),_=d.get(h)||[];_.push(c),d.set(h,_)}}}return c},delete:a=>{const A=e.indexConfig||{};let c;if(A.byId&&n.indexes.byId?c=n.indexes.byId.get(`${s}:${a}`):A.byType&&n.indexes.byType?c=(n.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===a):c=t.find(g=>g[`${s}_id`]===a),!c)return;const l=t.indexOf(c);if(l>=0&&(t.splice(l,1),n.editCount++),A.byId&&n.indexes.byId){const g=u7e(c);n.indexes.byId.delete(g)}if(A.byType&&n.indexes.byType){const u=(n.indexes.byType.get(s)||[]).filter(h=>h[`${s}_id`]!==a);n.indexes.byType.set(s,u)}if(A.byRelation&&n.indexes.byRelation)for(const[g,u]of n.indexes.byRelation.entries())for(const[h,d]of u.entries()){const _=d.filter(m=>m!==c);_.length===0?u.delete(h):u.set(h,_)}if(A.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in c){const g=c.subcircuit_id;if(g){const h=(n.indexes.bySubcircuit.get(g)||[]).filter(d=>d!==c);h.length===0?n.indexes.bySubcircuit.delete(g):n.indexes.bySubcircuit.set(g,h)}}if(A.byCustomField&&n.indexes.byCustomField)for(const g of n.indexes.byCustomField.values())for(const[u,h]of g.entries()){const d=h.filter(_=>_!==c);d.length===0?g.delete(u):g.set(u,d)}},update:(a,A)=>{const c=e.indexConfig||{};let l;if(c.byId&&n.indexes.byId?l=n.indexes.byId.get(`${s}:${a}`):c.byType&&n.indexes.byType?l=(n.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===a):l=t.find(g=>g.type===s&&g[`${s}_id`]===a),!l)return null;if(c.byRelation&&n.indexes.byRelation){const g=Object.entries(l);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${l.type}_id`&&typeof h=="string"&&u in A&&A[u]!==h){const d=n.indexes.byRelation.get(u);if(d){const m=(d.get(h)||[]).filter(p=>p!==l);m.length===0?d.delete(h):d.set(h,m)}}}if(c.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in l&&"subcircuit_id"in A){const g=l.subcircuit_id,u=A.subcircuit_id;if(g!==u){const d=(n.indexes.bySubcircuit.get(g)||[]).filter(_=>_!==l);d.length===0?n.indexes.bySubcircuit.delete(g):n.indexes.bySubcircuit.set(g,d)}}if(c.byCustomField&&n.indexes.byCustomField){for(const g of c.byCustomField)if(g in l&&g in A&&l[g]!==A[g]){const u=n.indexes.byCustomField.get(g);if(u){const h=String(l[g]),_=(u.get(h)||[]).filter(m=>m!==l);_.length===0?u.delete(h):u.set(h,_)}}}if(Object.assign(l,A),n.editCount++,c.byRelation&&n.indexes.byRelation){const g=Object.entries(l);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${l.type}_id`&&typeof h=="string"&&u in A){const d=n.indexes.byRelation.get(u)||new Map,_=d.get(h)||[];_.includes(l)||(_.push(l),d.set(h,_),n.indexes.byRelation.set(u,d))}}if(c.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in l&&"subcircuit_id"in A){const g=l.subcircuit_id;if(g&&typeof g=="string"){const u=n.indexes.bySubcircuit.get(g)||[];u.includes(l)||(u.push(l),n.indexes.bySubcircuit.set(g,u))}}if(c.byCustomField&&n.indexes.byCustomField){for(const g of c.byCustomField)if(g in l&&g in A){const u=l[g];if(u!==void 0&&(typeof u=="string"||typeof u=="number")){const h=String(u),d=n.indexes.byCustomField.get(g),_=d.get(h)||[];_.includes(l)||(_.push(l),d.set(h,_))}}}return l},select:a=>{if(s==="source_component")return t.find(A=>A.type==="source_component"&&A.name===a.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[A,c]=a.replace(/\./g,"").split(/[\s\>]+/),l=t.find(u=>u.type==="source_component"&&u.name===A);if(!l)return null;const g=t.find(u=>u.type==="source_port"&&u.source_component_id===l.source_component_id&&(u.name===c||(u.port_hints??[]).includes(c)));if(!g)return null;if(s==="source_port")return g;if(s==="pcb_port")return t.find(u=>u.type==="pcb_port"&&u.source_port_id===g.source_port_id)||null;if(s==="schematic_port")return t.find(u=>u.type==="schematic_port"&&u.source_port_id===g.source_port_id)||null}return null}}}})});dFt.unparsed=dFt;var hFt=(t,e)=>({minX:Math.min(t.minX,e.minX),minY:Math.min(t.minY,e.minY),maxX:Math.max(t.maxX,e.maxX),maxY:Math.max(t.maxY,e.maxY)}),wz=(t,e,n)=>{const o=n/2;return{minX:t-o,minY:e-o,maxX:t+o,maxY:e+o}},_Ft=(t,e,n,o,i)=>{const r=n/2,s=o/2,a=i*Math.PI/180,A=Math.cos(a),c=Math.sin(a),l=[{x:-r,y:-s},{x:r,y:-s},{x:r,y:s},{x:-r,y:s}].map(g=>({x:t+g.x*A-g.y*c,y:e+g.x*c+g.y*A}));return{minX:Math.min(...l.map(g=>g.x)),minY:Math.min(...l.map(g=>g.y)),maxX:Math.max(...l.map(g=>g.x)),maxY:Math.max(...l.map(g=>g.y))}},Mzo=(t,e,n,o,i)=>{const r=n/2,s=o/2,a=i*Math.PI/180,A=Math.cos(a),c=Math.sin(a),l=Math.hypot(r*A,s*c),g=Math.hypot(r*c,s*A);return{minX:t-l,minY:e-g,maxX:t+l,maxY:e+g}},wzo=(t,e,n,o,i)=>{const r=Math.min(n,o)/2,s=Math.max(n,o)/2-r,a=i*Math.PI/180,A=n>=o?{x:s,y:0}:{x:0,y:s},c={x:A.x*Math.cos(a)-A.y*Math.sin(a),y:A.x*Math.sin(a)+A.y*Math.cos(a)},l=Math.abs(c.x)+r,g=Math.abs(c.y)+r;return{minX:t-l,minY:e-g,maxX:t+l,maxY:e+g}},wae=t=>t.length===0?null:{minX:Math.min(...t.map(e=>e.x)),minY:Math.min(...t.map(e=>e.y)),maxX:Math.max(...t.map(e=>e.x)),maxY:Math.max(...t.map(e=>e.y))},d7e=t=>Array.isArray(t)?t.flatMap(e=>!e||typeof e!="object"?[]:"x"in e&&"y"in e&&typeof e.x=="number"&&typeof e.y=="number"?[{x:e.x,y:e.y}]:"start"in e&&"end"in e?[e.start,e.end].filter(o=>!!(o&&typeof o=="object"&&"x"in o&&"y"in o&&typeof o.x=="number"&&typeof o.y=="number")):[]):[],mFt=t=>{if(!t.type.startsWith("pcb_"))return null;if(t.type==="pcb_smtpad"&&t.shape==="polygon"&&Array.isArray(t.points))return wae(t.points);if(t.type==="pcb_hole"&&t.hole_shape==="circle")return wz(t.x,t.y,t.hole_diameter);if(t.type==="pcb_plated_hole"){let g;if("outer_diameter"in t&&typeof t.outer_diameter=="number"?g=wz(t.x,t.y,t.outer_diameter):"hole_diameter"in t&&typeof t.hole_diameter=="number"&&(g=wz(t.x,t.y,t.hole_diameter)),(t.shape==="oval"||t.shape==="pill")&&typeof t.outer_width=="number"&&typeof t.outer_height=="number"&&(g=(t.shape==="pill"?wzo:Mzo)(t.x,t.y,t.outer_width,t.outer_height,t.ccw_rotation??0)),"rect_pad_width"in t&&typeof t.rect_pad_width=="number"&&"rect_pad_height"in t&&typeof t.rect_pad_height=="number"){const u=_Ft(t.x,t.y,t.rect_pad_width,t.rect_pad_height,"rect_ccw_rotation"in t?t.rect_ccw_rotation??0:0);g=g?hFt(g,u):u}if("hole_diameter"in t&&typeof t.hole_diameter=="number"){const u=wz(t.x+("hole_offset_x"in t?t.hole_offset_x??0:0),t.y+("hole_offset_y"in t?t.hole_offset_y??0:0),t.hole_diameter);g=g?hFt(g,u):u}if(g)return g}const e=t,n=wae(d7e(e.route));if(n)return n;const o=wae(d7e(e.outline));if(o)return o;const i=wae(d7e(e.points));if(i)return i;let r,s,a,A;"x"in t&&"y"in t&&(r=Number(t.x),s=Number(t.y)),"outer_diameter"in t&&(a=Number(t.outer_diameter),A=Number(t.outer_diameter)),"width"in t&&(a=Number(t.width)),"height"in t&&(A=Number(t.height)),"center"in t&&t.center&&typeof t.center=="object"&&"x"in t.center&&"y"in t.center&&(r=Number(t.center.x),s=Number(t.center.y));let c=0;if("rotation"in t&&typeof t.rotation=="number"&&(c=t.rotation),"ccw_rotation"in t&&typeof t.ccw_rotation=="number"&&(c=t.ccw_rotation),r!==void 0&&s!==void 0)return a!==void 0&&A!==void 0?c?_Ft(r,s,a,A,c):{minX:r-a/2,minY:s-A/2,maxX:r+a/2,maxY:s+A/2}:"radius"in t&&typeof t.radius=="number"?wz(r,s,t.radius*2):{minX:r,minY:s,maxX:r,maxY:s};const l=[e.anchor_position,e.position].filter(g=>!!(g&&typeof g=="object"&&"x"in g&&"y"in g&&typeof g.x=="number"&&typeof g.y=="number")).at(0);return l?{minX:l.x,minY:l.y,maxX:l.x,maxY:l.y}:null},Nzo=(t,e)=>t.filter(n=>{const o=mFt(n);return o?o.minX<=e.maxX&&o.maxX>=e.minX&&o.minY<=e.maxY&&o.maxY>=e.minY:!1}),BF={IS_SHOWING_SCHEMATIC_GROUPS:"schematic_viewer_show_groups",IS_SHOWING_SCHEMATIC_PORTS:"schematic_viewer_show_ports",SELECTED_SCHEMATIC_SHEET:"schematic_viewer_selected_sheet"},pFt=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},IFt=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},Rzo=t=>{if(typeof window>"u")return null;try{return localStorage.getItem(t)}catch{return null}},Tzo=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,e)}catch{}},fFt=["#8B0000","#2F4F4F","#191970","#006400","#FF4500","#800080","#2E8B57","#B8860B","#C71585","#008B8B"],kzo=t=>{const{svgDivRef:e,circuitJson:n,circuitJsonKey:o,showGroups:i}=t;Z.useEffect(()=>{if(e.current&&e.current.querySelectorAll(".schematic-group-overlay").forEach(a=>a.remove()),!e.current||!i||!n||n.length===0)return;const r=setTimeout(()=>{if(!e.current)return;const s=e.current.querySelector("svg");if(!s)return;s.querySelectorAll(".schematic-group-overlay").forEach(A=>A.remove());try{const A=U2(n).source_group?.list().filter(I=>!I.is_subcircuit)||[],c=U2(n).schematic_component?.list()||[],l=new Map;A.forEach(I=>{const f=I;if(f.parent_source_group_id){const C=l.get(f.parent_source_group_id)||[];C.push(I.source_group_id),l.set(f.parent_source_group_id,C)}});const g=I=>{const f=[],C=l.get(I)||[];for(const y of C)f.push(y),f.push(...g(y));return f},u=I=>{const f=A.find(C=>C.source_group_id===I);return f?.parent_source_group_id?1+u(f.parent_source_group_id):0},h=A.length>0&&A.some(I=>I.name&&I.name.trim()!=="");let d=[];if(h){const I=new Map;for(const f of c){const C=U2(n).source_component.get(f.source_component_id);C?.source_group_id&&(I.has(C.source_group_id)||I.set(C.source_group_id,[]),I.get(C.source_group_id).push(f))}A.forEach((f,C)=>{let y=I.get(f.source_group_id)||[];const E=g(f.source_group_id);for(const B of E){const Q=I.get(B)||[];y=[...y,...Q]}if(y.length>0){const B=u(f.source_group_id),Q=g(f.source_group_id).length>0;if(f.name?.startsWith("unnamed_board"))return;d.push({id:f.source_group_id,name:f.name||`Group ${C+1}`,components:y,color:fFt[C%fFt.length],depthLevel:B,hasChildren:Q,sourceGroupId:f.source_group_id})}})}const _=s.viewBox.baseVal,m=s.getBoundingClientRect(),p=Math.min(m.width/_.width,m.height/_.height)||1;d.sort((I,f)=>I.depthLevel-f.depthLevel),d.forEach(I=>{if(I.components.length===0)return;const f=Fzo(I.components,s);if(!f)return;const C=Math.max(8,Math.min(25,15/Math.max(p,.3))),y=I.hasChildren?C*.6:0,E=C+y,B=Math.max(1,2/Math.max(p,.5)),Q=I.depthLevel===0?B:B*.7,b=Math.max(4,8/Math.max(p,.5)),P=I.hasChildren?1.3:1,N=b*P,R=N*.5,H=document.createElementNS("http://www.w3.org/2000/svg","rect");H.setAttribute("class","schematic-group-overlay"),H.setAttribute("x",(f.minX-E).toString()),H.setAttribute("y",(f.minY-E).toString()),H.setAttribute("width",(f.maxX-f.minX+E*2).toString()),H.setAttribute("height",(f.maxY-f.minY+E*2).toString()),H.setAttribute("fill","none"),H.setAttribute("stroke",I.color),H.setAttribute("stroke-width",Q.toString()),H.setAttribute("stroke-dasharray",`${N},${R}`),H.setAttribute("opacity","0.8"),H.setAttribute("rx","0"),H.setAttribute("ry","0");const G=Math.max(6,Math.min(20,14/Math.max(p,.2))),O=I.depthLevel===0||I.depthLevel===1?0:I.depthLevel*.2,U=G*(1-O),W=Math.max(1,U*.2),j=I.name,re=document.createElementNS("http://www.w3.org/2000/svg","text");re.setAttribute("font-size",U.toString()),re.setAttribute("font-family","Arial, sans-serif"),re.textContent=j,s.appendChild(re);const ne=re.getBBox();s.removeChild(re);const X=ne.width+W*2,ee=U+W*2,se=f.minX-E,le=f.minY-E-ee,ge=document.createElementNS("http://www.w3.org/2000/svg","rect");ge.setAttribute("class","schematic-group-overlay"),ge.setAttribute("x",se.toString()),ge.setAttribute("y",(le-ee).toString()),ge.setAttribute("width",X.toString()),ge.setAttribute("height",ee.toString()),ge.setAttribute("fill","transparent"),ge.setAttribute("rx","0"),ge.setAttribute("ry","0");const xe=document.createElementNS("http://www.w3.org/2000/svg","text");xe.setAttribute("class","schematic-group-overlay"),xe.setAttribute("x",(se+W).toString()),xe.setAttribute("y",(le+ee-W).toString()),xe.setAttribute("fill",I.color),xe.setAttribute("font-size",U.toString()),xe.setAttribute("font-family","Arial, sans-serif"),xe.setAttribute("font-weight",I.depthLevel===0?"600":"500"),xe.setAttribute("stroke",I.color),xe.setAttribute("stroke-width",Math.max(.2,U*.02).toString()),xe.textContent=j,s.appendChild(H),s.appendChild(ge),s.appendChild(xe)})}catch(A){console.error("Error creating group overlays:",A)}},10);return()=>clearTimeout(r)},[e,o,i])};function Fzo(t,e){let n=1/0,o=1/0,i=-1/0,r=-1/0;for(const a of t){let A=e.querySelector(`g[data-schematic-component-id="${a.schematic_component_id}"]`);if(A||(A=e.querySelector(`[data-schematic-component-id="${a.schematic_component_id}"]`)),A){const c=A.getBBox();n=Math.min(n,c.x),o=Math.min(o,c.y),i=Math.max(i,c.x+c.width),r=Math.max(r,c.y+c.height)}}return n===1/0?null:{minX:n,minY:o,maxX:i,maxY:r}}var h7e="sch-net-faded",CFt="g.trace[data-subcircuit-connectivity-map-key], g.trace-overlays[data-subcircuit-connectivity-map-key]",yFt="[data-schematic-net-label-id]",Lzo=({svgDivRef:t,circuitJson:e,circuitJsonKey:n,enabled:o})=>{Z.useEffect(()=>{const i=t.current;if(!o||!i)return;const{componentIdToKeys:r,netLabelIdToKey:s}=Hzo(e);let a=[];const A=new Map;let c=null;const l=()=>{for(const{el:m}of a)m.classList.remove(h7e);a=[],A.clear(),c=null;const _=i.querySelector("svg");if(_){for(const m of Array.from(_.querySelectorAll(CFt))){const p=m.getAttribute("data-subcircuit-connectivity-map-key"),I=new Set;p&&(I.add(p),A.set(m,p)),a.push({el:m,keys:I})}for(const m of Array.from(_.querySelectorAll("g[data-schematic-component-id]"))){const p=m.getAttribute("data-schematic-component-id");a.push({el:m,keys:r.get(p)??new Set})}for(const m of Array.from(_.querySelectorAll(yFt))){const p=s.get(m.getAttribute("data-schematic-net-label-id")),I=new Set;p&&(I.add(p),A.set(m,p)),a.push({el:m,keys:I})}}},g=_=>{if(_!==c){c=_;for(const{el:m,keys:p}of a)m.classList.toggle(h7e,_!==null&&!p.has(_))}},u=_=>{const m=_.target;if(!(m instanceof Element)){g(null);return}const p=m.closest(`${CFt}, ${yFt}`);if(!p){g(null);return}g(A.get(p)??null)},h=()=>g(null);l(),i.addEventListener("mouseover",u),i.addEventListener("mouseleave",h);const d=new MutationObserver(l);return d.observe(i,{childList:!0}),()=>{d.disconnect(),i.removeEventListener("mouseover",u),i.removeEventListener("mouseleave",h);for(const{el:_}of a)_.classList.remove(h7e)}},[t,n,o])};function Hzo(t){const e=U2(t),n=new Map;for(const r of e.schematic_component.list())r.source_component_id&&n.set(r.source_component_id,r.schematic_component_id);const o=new Map;for(const r of e.source_trace.list()){const s=r.subcircuit_connectivity_map_key;if(s)for(const a of r.connected_source_port_ids??[]){const A=n.get(e.source_port.get(a)?.source_component_id??"");A&&(o.has(A)||o.set(A,new Set),o.get(A).add(s))}}const i=new Map;for(const r of e.schematic_net_label.list()){if(!r.source_net_id)continue;const s=e.source_net.get(r.source_net_id)?.subcircuit_connectivity_map_key??r.source_net_id;i.set(r.schematic_net_label_id,s)}return{componentIdToKeys:o,netLabelIdToKey:i}}var _7e=t=>String(t??"").toLocaleLowerCase(),Nae=(t,e)=>{const n=_7e(t);return n===e?0:n.startsWith(e)?1:n.includes(e)?2:Number.POSITIVE_INFINITY},Gzo=t=>{if(t)return String(t).replace(/^simple_/,"").replaceAll("_"," ").replace(/\b\w/g,e=>e.toLocaleUpperCase())},Ozo=(t,e,n)=>{const o=Gzo(t?.ftype);let i;t?.display_name!==n&&(i=t?.display_name);let r=t?.display_value;if(!r&&t){for(const s of["display_resistance","display_capacitance","display_inductance","display_frequency","symbol_display_value"])if(s in t){const a=t[s];if(typeof a=="string"){r=a;break}}}return r??(r=e.symbol_display_value),o&&r?`${o} · ${r}`:r??i??t?.manufacturer_part_number??o},Kzo=t=>t.type==="source_component"&&"source_component_id"in t,Uzo=t=>t.type==="source_port",Yzo=t=>t.type==="source_trace",zzo=t=>t.type==="schematic_component",Vzo=t=>t.type==="schematic_port",Jzo=t=>t.type==="schematic_net_label",qzo=t=>t.type==="schematic_sheet",EFt=({schematicSheets:t,schematicSheetId:e})=>{if(!(t.length<=1||!e))return t.find(n=>n.schematic_sheet_id===e)?.name},Wzo=(t,e)=>{const n=_7e(e).trim();if(!n)return[];const o=new Map(t.filter(Kzo).map(l=>[l.source_component_id,l])),i=new Map(t.filter(Uzo).map(l=>[l.source_port_id,l])),r=t.filter(Vzo),s=t.filter(Yzo),a=t.filter(qzo),A=[],c=new Map;for(const l of t.filter(zzo)){const g=l.source_component_id?o.get(l.source_component_id):void 0,u=g?.name??g?.display_name??"Component",h=Math.min(Nae(u,n),Nae(g?.display_name,n),Nae(g?.manufacturer_part_number,n));if(Number.isFinite(h)){const d={label:u,detail:Ozo(g,l,u),kind:"component",schematicSheetId:l.schematic_sheet_id,schematicSheetName:EFt({schematicSheets:a,schematicSheetId:l.schematic_sheet_id}),target:{type:"schematic_component",id:l.schematic_component_id}};A.push(d),c.set(d,h)}}for(const l of t.filter(Jzo)){if(!_7e(l.text).includes(n))continue;const g=new Set;for(const f of s.filter(C=>C.connected_source_net_ids.includes(l.source_net_id)))for(const C of f.connected_source_port_ids)g.add(C);const u=l.anchor_position??l.center,h=r.filter(f=>g.has(f.source_port_id)&&(!l.schematic_sheet_id||!f.schematic_sheet_id||f.schematic_sheet_id===l.schematic_sheet_id)).map(f=>({port:f,distance:Math.hypot(f.center.x-u.x,f.center.y-u.y)})).filter(({distance:f})=>f<=1).sort((f,C)=>f.distance-C.distance)[0]?.port,d=h?i.get(h.source_port_id):void 0,_=d?.source_component_id?o.get(d.source_component_id):void 0,m=d?.name??(d?.pin_number!==void 0?`pin${d.pin_number}`:h?.display_pin_label),p=_?.name&&m?`Connected to ${_.name}.${m}`:void 0,I={label:l.text,detail:p,kind:"net",schematicSheetId:l.schematic_sheet_id,schematicSheetName:EFt({schematicSheets:a,schematicSheetId:l.schematic_sheet_id}),target:{type:"schematic_net_label",id:l.schematic_net_label_id}};A.push(I),c.set(I,Nae(l.text,n))}return A.sort((l,g)=>(c.get(l)??Number.POSITIVE_INFINITY)-(c.get(g)??Number.POSITIVE_INFINITY)||l.label.localeCompare(g.label))},jzo=({containerRect:t,targetRect:e,visibleProjection:n,minimumScale:o})=>{const i=n.a||1,r={x:e.left+e.width/2-t.left,y:e.top+e.height/2-t.top},s={x:(r.x-n.e)/i,y:(r.y-n.f)/i},a=Math.max(i,o);return{a,b:0,c:0,d:a,e:t.width/2-s.x*a,f:t.height/2-s.y*a}},Xzo=1.8,xFt=350,$zo=({circuitJson:t,circuitJsonKey:e,svgDivRef:n,containerRef:o,activeSheetId:i,hasMultipleSheets:r,handleSelectSheet:s,svgString:a,svgToScreenProjection:A,setSvgToScreenProjection:c,setIsInteractionEnabled:l})=>{const[g,u]=Z.useState(""),[h,d]=Z.useState(null),_=Z.useRef(null),m=Z.useMemo(()=>Wzo(t,g),[t,e,g]),p=Z.useCallback(C=>{const y=n.current,E=o.current;if(!y||!E)return!1;let B="data-schematic-net-label-id";C.target.type==="schematic_component"&&(B="data-schematic-component-id");const Q=Array.from(y.querySelectorAll(`[${B}]`)).find(H=>H.getAttribute(B)===C.target.id);if(!Q)return!1;const b=Q.getBoundingClientRect(),P=E.getBoundingClientRect();if(!b.width&&!b.height)return!1;_.current&&clearTimeout(_.current);let N=A;const R=getComputedStyle(y).transform;if(R&&R!=="none")try{N=gH(R),y.style.transition="none",y.style.transform=R,y.offsetWidth}catch{}return y.style.transition=`transform ${xFt}ms ease-in-out`,y.offsetWidth,c(jzo({containerRect:P,targetRect:b,visibleProjection:N,minimumScale:Xzo})),_.current=setTimeout(()=>{y.style.transition=""},xFt),y.querySelectorAll(".schematic-search-match").forEach(H=>H.classList.remove("schematic-search-match")),y.querySelectorAll(`[${B}]`).forEach(H=>{H.getAttribute(B)===C.target.id&&H.classList.add("schematic-search-match")}),!0},[o,c,n,A]),I=Z.useCallback(C=>{if(l(!0),C.schematicSheetId&&C.schematicSheetId!==i&&r){s(C.schematicSheetId),d(C);return}p(C)},[i,p,s,r,l]),f=Z.useCallback(()=>{u(""),d(null),_.current&&(clearTimeout(_.current),_.current=null),n.current&&(n.current.style.transition="",n.current.querySelectorAll(".schematic-search-match").forEach(C=>C.classList.remove("schematic-search-match")))},[n]);return Z.useEffect(()=>{if(!h||!a)return;const C=requestAnimationFrame(()=>{p(h)&&d(null)});return()=>cancelAnimationFrame(C)},[p,h,a]),Z.useEffect(()=>{g||n.current?.querySelectorAll(".schematic-search-match").forEach(C=>C.classList.remove("schematic-search-match"))},[g,n]),Z.useEffect(()=>()=>{_.current&&clearTimeout(_.current)},[]),{searchQuery:g,setSearchQuery:u,searchResults:m,handleSearchResultSelect:I,handleCancelSearch:f}};pl("schematic-viewer");var Zzo=()=>{pl.enable("schematic-viewer*")},BFt=t=>{const[e,n]=Z.useState(0),[o,i]=Z.useState(0);return Z.useEffect(()=>{if(!t.current)return;const r=()=>{const a=t.current?.getBoundingClientRect();n(a?.width||0),i(a?.height||0)};r();const s=new ResizeObserver(r);return s.observe(t.current),window.addEventListener("resize",r),()=>{s.disconnect(),window.removeEventListener("resize",r)}},[]),{containerWidth:e,containerHeight:o}},eVo=600,Rae=10,tVo=({containerRef:t})=>{const[e,n]=Z.useState(!1),[o,i]=Z.useState({x:0,y:0}),r=Z.useRef(null),s=Z.useRef(null),a=Z.useRef(null),A=Z.useRef(0),c=Z.useCallback(()=>{a.current!==null&&(window.clearTimeout(a.current),a.current=null)},[]),l=Z.useCallback(_=>{if(_.preventDefault(),Date.now()<A.current)return;const m=s.current;if(!m)return;const p=Math.abs(_.clientX-m.x)>Rae||Math.abs(_.clientY-m.y)>Rae;s.current=null,!p&&(i({x:_.clientX,y:_.clientY}),n(!0))},[]),g=Z.useCallback(_=>{if(c(),_.touches.length!==1){s.current=null;return}const m=_.touches[0];m&&(s.current={x:m.clientX,y:m.clientY},a.current=window.setTimeout(()=>{const p=t.current;if(!p||!s.current)return;const I=p.getBoundingClientRect();i({x:I.left+I.width/2,y:I.top+I.height/2}),n(!0),A.current=Date.now()+1e3,s.current=null},eVo))},[c,t]),u=Z.useCallback(_=>{const m=s.current;if(!m||_.touches.length!==1)return;const p=_.touches[0];(!p||Math.abs(p.clientX-m.x)>Rae||Math.abs(p.clientY-m.y)>Rae)&&(s.current=null,c())},[c]),h=Z.useCallback(()=>{c(),s.current=null},[c]),d=Z.useCallback(_=>{const m=_.target;r.current?.contains(m)||m.closest?.("[data-radix-popper-content-wrapper], [data-radix-dropdown-menu-content]")||n(!1)},[]);return Z.useEffect(()=>{if(e)return document.addEventListener("mousedown",d),document.addEventListener("touchstart",d),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("touchstart",d)}},[d,e]),Z.useEffect(()=>c,[c]),{menuVisible:e,menuPos:o,menuRef:r,setMenuVisible:n,contextMenuEventHandlers:{onMouseDown:_=>{s.current=_.button===2||_.button===0&&_.ctrlKey?{x:_.clientX,y:_.clientY}:null},onContextMenu:l,onTouchStart:g,onTouchMove:u,onTouchEnd:h,onTouchCancel:h}}},nVo=new Set(["type","source_component_id","source_group_id","subcircuit_id","display_name","ftype","are_pins_interchangeable","supplier_part_numbers"]),QFt=["name","resistance","capacitance","inductance","frequency","voltage","current","max_voltage_rating","max_current_rating","power_rating","manufacturer_part_number"],oVo={jlcpcb:t=>`https://jlcpcb.com/partdetail/${encodeURIComponent(t)}`,lcsc:t=>`https://www.lcsc.com/product-detail/${encodeURIComponent(t)}.html`},iVo=t=>{const e=t.trim(),n=/^c?(\d+)$/i.exec(e);return n?`C${n[1]}`:e},SFt=t=>{const e=QFt.indexOf(t);return e===-1?QFt.length:e},rVo=(t,e,n)=>{if(e==="name")return String(n);const o=t[`display_${e}`];if(typeof o=="string"&&o.trim()){const i=e==="resistance"?o.replace(/Ω$/,""):o;return JSON.stringify(i)}return JSON.stringify(n)??String(n)},sVo=t=>Object.entries(t).filter(([e,n])=>nVo.has(e)||e.startsWith("display_")&&e.slice(8)in t?!1:n!=null&&n!=="").sort(([e],[n])=>SFt(e)-SFt(n)||e.localeCompare(n)).map(([e,n])=>({key:e,label:e,value:rVo(t,e,n)})),aVo=t=>{const e=t.supplier_part_numbers;return e?["jlcpcb","lcsc"].flatMap(n=>{const o=e[n];if(!Array.isArray(o))return[];const i=[...new Set(o.filter(r=>!!(typeof r=="string"&&r.trim())).map(iVo))];return i.length?[{key:`supplier_part_numbers.${n}`,label:n,links:i.map(r=>({partNumber:r,href:oVo[n](r)}))}]:[]}):[]},AVo=(t,e)=>{const n=t.find(A=>A.type==="schematic_component"&&A.schematic_component_id===e);if(!n)return null;const o=t.find(A=>A.type==="source_component"&&A.source_component_id===n.source_component_id);if(!o)return null;const i=t.find(A=>A.type==="pcb_component"&&A.source_component_id===o.source_component_id),r=t.find(A=>A.type==="cad_component"&&A.source_component_id===o.source_component_id&&(!i||A.pcb_component_id===i.pcb_component_id)),s=i?.footprinter_string??r?.footprinter_string,a=i?cVo(t,i.pcb_component_id):null;return{schematicComponent:n,sourceComponent:o,pcbComponent:i,footprinterString:s,footprintPreviewCircuitJson:a?.circuitJson,footprintPreviewViewBox:a?.viewBox}},Tae=2,cVo=(t,e)=>{const n=t.find(r=>r.type==="pcb_component"&&r.pcb_component_id===e);if(!n)return null;const o=mFt(n);if(!o)return null;const i={minX:o.minX-Tae,minY:o.minY-Tae,maxX:o.maxX+Tae,maxY:o.maxY+Tae};return{circuitJson:Nzo(t,i),viewBox:i}},lVo=t=>{let e="";for(let o=0;o<t.length;o+=8192)e+=String.fromCharCode(...t.subarray(o,o+8192));return btoa(e)},gVo=(t,e)=>{const n=lVo(oue(iue(JSON.stringify(t)))),o=new URL("https://svg.tscircuit.com/");return o.searchParams.set("svg_type","pcb"),o.searchParams.set("circuit_json",n),o.searchParams.set("viewbox",[e.minX,e.minY,e.maxX,e.maxY].join(",")),o.searchParams.set("background_color","#f8fafc"),o.toString()},hQ={contextMenu:110,viewMenu:55,viewMenuIcon:48,clickToInteractOverlay:100,schematicComponentDetailsTooltip:105,schematicComponentHoverOutline:47,schematicPortHoverOutline:48,schematicSearch:101},m7e=Z.createContext(null),uVo=5,dVo=(t,e)=>!t&&!e?!0:!t||!e?!1:t.minX===e.minX&&t.maxX===e.maxX&&t.minY===e.minY&&t.maxY===e.maxY,hVo=({children:t})=>Z.useContext(m7e)?q.jsx(q.Fragment,{children:t}):q.jsx(_Vo,{children:t}),_Vo=({children:t})=>{const e=Z.useRef({pointer:null,boundingBoxes:new Map,hoveringIds:new Set,subscribers:new Set,mouseDownPosition:null}),n=Z.useCallback(()=>{for(const l of e.current.subscribers)l()},[]),o=Z.useCallback(()=>{const l=e.current.pointer,g=new Set;if(l)for(const[h,d]of e.current.boundingBoxes){const _=d.bounds;_&&l.x>=_.minX&&l.x<=_.maxX&&l.y>=_.minY&&l.y<=_.maxY&&g.add(h)}const u=e.current.hoveringIds;g.size===u.size&&[...g].every(h=>u.has(h))||(e.current.hoveringIds=g,n())},[n]),i=Z.useCallback((l,g)=>{e.current.boundingBoxes.set(l,g),o()},[o]),r=Z.useCallback((l,g)=>{const u=e.current.boundingBoxes.get(l);u&&dVo(u.bounds,g.bounds)&&u.onClick===g.onClick||(e.current.boundingBoxes.set(l,g),o())},[o]),s=Z.useCallback(l=>{e.current.boundingBoxes.delete(l)&&o()},[o]),a=Z.useCallback(l=>(e.current.subscribers.add(l),()=>{e.current.subscribers.delete(l)}),[]),A=Z.useCallback(l=>e.current.hoveringIds.has(l),[]);Z.useEffect(()=>{const l=d=>{const{clientX:_,clientY:m}=d,p=e.current.pointer;p&&p.x===_&&p.y===m||(e.current.pointer={x:_,y:m},o())},g=()=>{e.current.pointer!==null&&(e.current.pointer=null,e.current.mouseDownPosition=null,o())},u=d=>{e.current.mouseDownPosition={x:d.clientX,y:d.clientY}},h=d=>{const{clientX:_,clientY:m}=d,p=e.current.mouseDownPosition;if(p&&Math.sqrt(Math.pow(_-p.x,2)+Math.pow(m-p.y,2))>uVo){e.current.mouseDownPosition=null;return}e.current.mouseDownPosition=null;for(const I of e.current.boundingBoxes.values()){const f=I.bounds;f&&_>=f.minX&&_<=f.maxX&&m>=f.minY&&m<=f.maxY&&I.onClick?.(d)}};return window.addEventListener("pointermove",l,{passive:!0}),window.addEventListener("pointerdown",l,{passive:!0}),window.addEventListener("pointerup",l,{passive:!0}),window.addEventListener("pointerleave",g),window.addEventListener("pointercancel",g),window.addEventListener("blur",g),window.addEventListener("mousedown",u,{passive:!0}),window.addEventListener("click",h,{passive:!0}),()=>{window.removeEventListener("pointermove",l),window.removeEventListener("pointerdown",l),window.removeEventListener("pointerup",l),window.removeEventListener("pointerleave",g),window.removeEventListener("pointercancel",g),window.removeEventListener("blur",g),window.removeEventListener("mousedown",u),window.removeEventListener("click",h)}},[o]);const c=Z.useMemo(()=>({registerBoundingBox:i,updateBoundingBox:r,unregisterBoundingBox:s,subscribe:a,isHovering:A}),[i,r,s,a,A]);return q.jsx(m7e.Provider,{value:c,children:t})},p7e={color:"#64748b",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45},mVo=({sourceComponent:t,footprinterString:e,footprintPreviewCircuitJson:n,footprintPreviewViewBox:o,left:i,top:r,width:s,maxHeight:a})=>{const A=Z.useMemo(()=>sVo(t),[t]),c=Z.useMemo(()=>aVo(t),[t]),l=Z.useMemo(()=>n?.length&&o?gVo(n,o):void 0,[n,o]);return q.jsxs("dialog",{open:!0,"aria-label":`${t.name} component details`,"data-schematic-component-details-tooltip":!0,style:{position:"absolute",left:i,right:"auto",top:r,bottom:"auto",width:s,maxHeight:a,margin:0,padding:0,overflowY:"auto",boxSizing:"border-box",border:"1px solid #cbd5e1",borderRadius:"4px",backgroundColor:"rgba(255, 255, 255, 0.98)",boxShadow:"0 20px 25px -5px rgba(15, 23, 42, 0.18), 0 8px 10px -6px rgba(15, 23, 42, 0.12)",color:"#0f172a",fontFamily:'Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',pointerEvents:"auto",userSelect:"text",WebkitUserSelect:"text",zIndex:hQ.schematicComponentDetailsTooltip},onMouseDown:g=>g.stopPropagation(),onClick:g=>g.stopPropagation(),children:[q.jsxs("dl",{style:{display:"grid",gridTemplateColumns:"minmax(110px, 0.8fr) minmax(0, 1.2fr)",gap:"6px 12px",margin:0,padding:"8px"},children:[A.map(g=>q.jsxs("div",{style:{display:"contents"},children:[q.jsx("dt",{style:p7e,children:g.label}),q.jsx("dd",{style:{minWidth:0,margin:0,color:"#1e293b",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45,overflowWrap:"anywhere"},children:g.value})]},g.key)),c.map(g=>q.jsxs("div",{style:{display:"contents"},children:[q.jsx("dt",{style:p7e,children:g.label}),q.jsx("dd",{style:{minWidth:0,margin:0,fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45,overflowWrap:"anywhere"},children:g.links.map((u,h)=>q.jsxs("span",{children:[h>0&&", ",q.jsx("a",{href:u.href,target:"_blank",rel:"noreferrer noopener",style:{color:"#2563eb",textDecoration:"underline"},children:u.partNumber})]},u.href))})]},g.key)),e&&q.jsxs("div",{style:{display:"contents"},children:[q.jsx("dt",{style:p7e,children:"footprint"}),q.jsx("dd",{style:{minWidth:0,margin:0,color:"#1e293b",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45,overflowWrap:"anywhere"},children:JSON.stringify(e)})]})]}),l&&q.jsx("div",{style:{padding:"0 4px 4px"},children:q.jsx("div",{style:{height:"210px",overflow:"hidden",border:"1px solid #e2e8f0",borderRadius:"2px",background:"#f8fafc"},children:q.jsx("img",{src:l,alt:`${t.name}${e?` ${e}`:""} PCB footprint`,loading:"lazy",referrerPolicy:"no-referrer",style:{display:"block",width:"100%",height:"100%",objectFit:"contain"}})})})]})},bFt=t=>{const e=Z.useContext(m7e);if(!e)throw new Error("useMouseEventsOverBoundingBox must be used within a MouseTracker");const n=Z.useId(),o=Z.useRef(t);o.current=t;const i=Z.useMemo(()=>s=>{o.current.onClick?.(s)},[]);return Z.useEffect(()=>(e.registerBoundingBox(n,{bounds:o.current.bounds,onClick:o.current.onClick?i:void 0}),()=>{e.unregisterBoundingBox(n)}),[e,i,n]),Z.useEffect(()=>{e.updateBoundingBox(n,{bounds:o.current.bounds,onClick:o.current.onClick?i:void 0})},[e,i,n,t.bounds?.minX,t.bounds?.maxX,t.bounds?.minY,t.bounds?.maxY,t.onClick]),{hovering:Z.useSyncExternalStore(e.subscribe,()=>e.isHovering(n),()=>!1)}},pVo=(t,e)=>!t&&!e?!0:!t||!e?!1:Math.abs(t.bounds.minX-e.bounds.minX)<.5&&Math.abs(t.bounds.maxX-e.bounds.maxX)<.5&&Math.abs(t.bounds.minY-e.bounds.minY)<.5&&Math.abs(t.bounds.maxY-e.bounds.maxY)<.5&&Math.abs(t.rect.left-e.rect.left)<.5&&Math.abs(t.rect.top-e.rect.top)<.5&&Math.abs(t.rect.width-e.rect.width)<.5&&Math.abs(t.rect.height-e.rect.height)<.5,IVo=({componentId:t,svgDivRef:e,containerRef:n,onComponentClick:o,onHoverChange:i,showOutline:r,circuitJsonKey:s})=>{const[a,A]=Z.useState(null),c=Z.useRef(null),l=Z.useCallback(()=>{c.current=null;const m=e.current,p=n.current;if(!m||!p){A(E=>E&&null);return}const I=m.querySelector(`[data-schematic-component-id="${t}"]`);if(!I){A(E=>E&&null);return}const f=I.getBoundingClientRect(),C=p.getBoundingClientRect(),y={bounds:{minX:f.left,maxX:f.right,minY:f.top,maxY:f.bottom},rect:{left:f.left-C.left,top:f.top-C.top,width:f.width,height:f.height}};A(E=>pVo(E,y)?E:y)},[t,n,e]),g=Z.useCallback(()=>{c.current===null&&(c.current=window.requestAnimationFrame(l))},[l]);Z.useEffect(()=>{g()},[g,s]),Z.useEffect(()=>{g();const m=e.current,p=n.current;if(!m||!p)return;const I=typeof ResizeObserver<"u"?new ResizeObserver(()=>{g()}):null;I?.observe(p),I?.observe(m);const f=typeof MutationObserver<"u"?new MutationObserver(()=>{g()}):null;return f?.observe(m,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",g,!0),window.addEventListener("resize",g),()=>{I?.disconnect(),f?.disconnect(),window.removeEventListener("scroll",g,!0),window.removeEventListener("resize",g),c.current!==null&&(cancelAnimationFrame(c.current),c.current=null)}},[g,e,n]);const u=Z.useCallback(m=>{o&&o(t,m)},[t,o]),h=a?.bounds??null,{hovering:d}=bFt({bounds:h,onClick:o?u:void 0});if(Z.useEffect(()=>{i&&i(t,d)},[d,t,i]),!a||!d||!r)return null;const _=a.rect;return q.jsx("div",{style:{position:"absolute",left:_.left,top:_.top,width:_.width,height:_.height,border:"1.5px solid rgba(51, 153, 255, 0.9)",pointerEvents:"none",zIndex:hQ.schematicComponentHoverOutline}})},fVo=(t,e)=>!t&&!e?!0:!t||!e?!1:Math.abs(t.bounds.minX-e.bounds.minX)<.5&&Math.abs(t.bounds.maxX-e.bounds.maxX)<.5&&Math.abs(t.bounds.minY-e.bounds.minY)<.5&&Math.abs(t.bounds.maxY-e.bounds.maxY)<.5&&Math.abs(t.rect.left-e.rect.left)<.5&&Math.abs(t.rect.top-e.rect.top)<.5&&Math.abs(t.rect.width-e.rect.width)<.5&&Math.abs(t.rect.height-e.rect.height)<.5,CVo=({portId:t,portLabel:e,svgDivRef:n,containerRef:o,onPortClick:i,onHoverChange:r,showOutline:s,circuitJsonKey:a})=>{const[A,c]=Z.useState(null),l=Z.useRef(null),g=Z.useCallback(()=>{l.current=null;const p=n.current,I=o.current;if(!p||!I){c(Q=>Q&&null);return}const f=p.querySelector(`[data-schematic-port-id="${t}"]`);if(!f){c(Q=>Q&&null);return}const C=f.getBoundingClientRect(),y=I.getBoundingClientRect(),E=4,B={bounds:{minX:C.left-E,maxX:C.right+E,minY:C.top-E,maxY:C.bottom+E},rect:{left:C.left-y.left-E,top:C.top-y.top-E,width:C.width+E*2,height:C.height+E*2}};c(Q=>fVo(Q,B)?Q:B)},[t,o,n]),u=Z.useCallback(()=>{l.current===null&&(l.current=window.requestAnimationFrame(g))},[g]);Z.useEffect(()=>{u()},[u,a]),Z.useEffect(()=>{u();const p=n.current,I=o.current;if(!p||!I)return;const f=typeof ResizeObserver<"u"?new ResizeObserver(()=>{u()}):null;f?.observe(I),f?.observe(p);const C=typeof MutationObserver<"u"?new MutationObserver(()=>{u()}):null;return C?.observe(p,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{f?.disconnect(),C?.disconnect(),window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u),l.current!==null&&(cancelAnimationFrame(l.current),l.current=null)}},[u,n,o]);const h=Z.useCallback(p=>{i&&i(t,p)},[t,i]),d=A?.bounds??null,{hovering:_}=bFt({bounds:d,onClick:i?h:void 0});if(Z.useEffect(()=>{r&&r(t,_)},[_,t,r]),!A||!s)return null;const m=A.rect;return q.jsxs(q.Fragment,{children:[q.jsx("div",{style:{position:"absolute",left:m.left,top:m.top,width:m.width,height:m.height,border:_?"1.5px solid rgba(255, 153, 51, 0.9)":"1.5px solid rgba(255, 153, 51, 0.3)",backgroundColor:_?"rgba(255, 153, 51, 0.15)":"rgba(255, 153, 51, 0.05)",borderRadius:"50%",pointerEvents:"none",zIndex:hQ.schematicPortHoverOutline,transition:"border-color 0.15s, background-color 0.15s"}}),_&&e&&q.jsx("div",{style:{position:"absolute",left:m.left+m.width/2,top:m.top-24,transform:"translateX(-50%)",backgroundColor:"rgba(0, 0, 0, 0.85)",color:"white",padding:"4px 8px",borderRadius:"4px",fontSize:"12px",fontFamily:"monospace",whiteSpace:"nowrap",pointerEvents:"none",zIndex:hQ.schematicPortHoverOutline+1},children:e})]})},Nz=({children:t,size:e,strokeWidth:n})=>q.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:n,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t}),DFt=t=>q.jsxs(Nz,{...t,children:[q.jsx("circle",{cx:"11",cy:"11",r:"8"}),q.jsx("path",{d:"m21 21-4.34-4.34"})]}),yVo=t=>q.jsxs(Nz,{...t,children:[q.jsx("path",{d:"M18 6 6 18"}),q.jsx("path",{d:"m6 6 12 12"})]}),EVo=t=>q.jsxs(Nz,{...t,children:[q.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),q.jsx("rect",{x:"8",y:"8",width:"8",height:"8",rx:"1"}),q.jsx("path",{d:"M7 2v2M12 2v2M17 2v2M7 20v2M12 20v2M17 20v2M2 7h2M2 12h2M2 17h2M20 7h2M20 12h2M20 17h2"})]}),xVo=t=>q.jsxs(Nz,{...t,children:[q.jsx("path",{d:"M15 6a9 9 0 0 0-9 9V3"}),q.jsx("circle",{cx:"18",cy:"6",r:"3"}),q.jsx("circle",{cx:"6",cy:"18",r:"3"})]}),BVo=t=>q.jsxs(Nz,{...t,children:[q.jsx("path",{d:"M20 4v7a4 4 0 0 1-4 4H4"}),q.jsx("path",{d:"m9 10-5 5 5 5"})]}),QVo=({text:t,query:e})=>{const n=e.trim().toLocaleLowerCase();if(!n)return t;const o=t.toLocaleLowerCase(),i=[];let r=0,s=o.indexOf(n);for(;s!==-1;)s>r&&i.push(t.slice(r,s)),i.push(q.jsx("strong",{style:{fontWeight:700},children:t.slice(s,s+n.length)},`${s}-${r}`)),r=s+n.length,s=o.indexOf(n,r);return r<t.length&&i.push(t.slice(r)),i.length>0?i:t},SVo=()=>typeof navigator>"u"?"Ctrl F":/mac/i.test(navigator.platform)?"⌘ F":"Ctrl F",bVo=({query:t,onQueryChange:e,onCancel:n,results:o,onSelect:i,viewerContainerRef:r})=>{const[s,a]=Z.useState(!1),[A,c]=Z.useState(null),[l,g]=Z.useState(null),u=Z.useRef(null),h=Z.useRef(null),d=SVo();Z.useEffect(()=>{c(b=>o.some(P=>P.target.id===b)?b:o.find(P=>P.kind==="component")?.target.id??o[0]?.target.id??null)},[o]),Z.useEffect(()=>{A&&h.current?.querySelector(`[data-search-result-id="${A}"]`)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[A]),Z.useEffect(()=>{const b=N=>{if(N.key==="Escape"&&s){N.preventDefault(),N.stopPropagation(),N.stopImmediatePropagation(),n(),a(!1),u.current?.blur();return}N.code!=="KeyF"&&N.key.toLocaleLowerCase()!=="f"||!N.metaKey&&!N.ctrlKey||r.current?.matches(":hover")&&(N.preventDefault(),N.stopPropagation(),N.stopImmediatePropagation(),a(!0),requestAnimationFrame(()=>{u.current?.focus(),u.current?.select()}))},P=[window];try{window.parent!==window&&window.parent.document&&P.push(window.parent)}catch{}return P.forEach(N=>N.addEventListener("keydown",b,{capture:!0})),()=>{P.forEach(N=>N.removeEventListener("keydown",b,{capture:!0}))}},[s,n,r]);const _=()=>{n(),a(!1),u.current?.blur()},m=b=>{a(!0),b&&requestAnimationFrame(()=>u.current?.focus())},p=o.filter(b=>b.kind==="component"),I=o.filter(b=>b.kind==="net"),f=[...p,...I],C=f.find(b=>b.target.id===A)??f[0],y=o.length===1?"1 result":`${o.length} results`;let E="none";t&&(E="1px solid #e8e8e8");const B=b=>{if(!(b.key==="Enter"&&b.target instanceof Element&&b.target.closest('[aria-label="Clear search"]'))){if(b.key==="Escape"){b.preventDefault(),_();return}if(f.length>0&&(b.key==="ArrowDown"||b.key==="ArrowUp")){b.preventDefault();let P=-1;b.key==="ArrowDown"&&(P=1),c(N=>{const R=f.findIndex(O=>O.target.id===N);let H=R;R===-1&&(H=0,P===1&&(H=-1));const G=(H+P+f.length)%f.length;return f[G]?.target.id??null});return}b.key==="Enter"&&C&&(b.preventDefault(),i(C))}},Q=(b,P)=>P.length===0?null:q.jsxs("section",{children:[q.jsx("div",{style:{padding:"6px 12px 3px",backgroundColor:"#f7f7f8",color:"#777777",fontSize:"11px",fontWeight:600,letterSpacing:"0.02em",textTransform:"lowercase"},children:b}),P.map(N=>{const R=N.target.id===C?.target.id,H=N.target.id===l;let G="#ffffff";(H||R)&&(G="#f1f3f5");let O=q.jsx(xVo,{size:15,strokeWidth:1.8});N.kind==="component"&&(O=q.jsx(EVo,{size:15,strokeWidth:1.8}));const U=()=>{u.current?.blur(),c(N.target.id),i(N)};return q.jsxs("button",{type:"button","data-search-result-id":N.target.id,onPointerUp:W=>{W.button===0&&U()},onClick:W=>{W.detail===0&&U()},onMouseEnter:()=>g(N.target.id),onMouseLeave:()=>g(null),style:{width:"100%",display:"flex",alignItems:"center",gap:"9px",padding:"7px 12px",border:"none",background:G,color:"#222222",cursor:"pointer",textAlign:"left"},children:[q.jsx("span",{style:{width:"26px",height:"26px",flexShrink:0,display:"grid",placeItems:"center",border:"1px solid #e5e5e5",borderRadius:"6px",backgroundColor:"#f7f7f7",color:"#666666"},children:O}),q.jsxs("span",{style:{minWidth:0,flex:1},children:[q.jsx("span",{style:{display:"block",overflow:"hidden",fontSize:"13px",fontWeight:400,lineHeight:1.25,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:q.jsx(QVo,{text:N.label,query:t})}),N.detail&&q.jsx("span",{style:{display:"block",overflow:"hidden",marginTop:"2px",color:"#777777",fontSize:"11px",lineHeight:1.2,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:N.detail}),N.schematicSheetName&&q.jsxs("span",{style:{display:"block",overflow:"hidden",marginTop:"2px",color:"#777777",fontSize:"11px",lineHeight:1.2,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Sheet: ",N.schematicSheetName]})]}),R&&q.jsx("span",{title:"Press Enter to open",style:{flexShrink:0,color:"#666666",fontSize:"17px",lineHeight:1},children:q.jsx(BVo,{size:14,strokeWidth:1.8})})]},N.target.id)})]});return q.jsx("div",{"data-schematic-search":!0,onPointerDown:b=>b.stopPropagation(),onMouseDown:b=>b.stopPropagation(),onTouchStart:b=>b.stopPropagation(),onTouchEnd:b=>b.stopPropagation(),style:{position:"relative",zIndex:hQ.schematicSearch,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif'},children:s?q.jsxs("div",{onKeyDown:B,style:{width:"min(280px, calc(100vw - 32px))",overflow:"hidden",border:"none",borderRadius:"4px",backgroundColor:"#ffffff",boxShadow:"0 2px 4px rgba(0,0,0,0.1)"},children:[q.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",height:"32px",boxSizing:"border-box",padding:"0 12px",borderBottom:E},children:[q.jsx(DFt,{size:15,strokeWidth:2}),q.jsx("input",{ref:u,value:t,"aria-label":"Search components and nets",placeholder:"Search...",onPointerUp:b=>b.currentTarget.focus(),onChange:b=>e(b.target.value),style:{minWidth:0,flex:1,border:"none",outline:"none",fontSize:"13px",color:"#222222",background:"transparent"}}),t&&o.length>0?q.jsx("span",{style:{flexShrink:0,color:"#888888",fontSize:"12px",whiteSpace:"nowrap"},children:y}):q.jsx("kbd",{style:{flexShrink:0,padding:"2px 5px",border:"1px solid #dddddd",borderRadius:"4px",backgroundColor:"#f7f7f7",color:"#777777",fontFamily:"inherit",fontSize:"10px",lineHeight:1.2},children:d}),s&&q.jsx("button",{type:"button","aria-label":"Clear search",onPointerUp:b=>{b.button===0&&_()},onClick:b=>{b.detail===0&&_()},style:{border:"none",background:"transparent",color:"#777777",cursor:"pointer",width:"20px",height:"20px",display:"grid",placeItems:"center",padding:0,lineHeight:1},children:q.jsx(yVo,{size:16,strokeWidth:2})})]}),t&&q.jsx("div",{ref:h,style:{maxHeight:"240px",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",scrollBehavior:"smooth",touchAction:"pan-y",WebkitOverflowScrolling:"touch"},onWheel:b=>b.stopPropagation(),onTouchMove:b=>b.stopPropagation(),children:o.length===0?q.jsx("div",{style:{padding:"12px",color:"#777777",fontSize:"13px"},children:"No matching components or nets"}):q.jsxs(q.Fragment,{children:[Q("components",p),Q("nets",I)]})})]}):q.jsx("button",{type:"button",title:"Search schematic","aria-label":"Search schematic",onPointerDown:b=>{b.stopPropagation(),b.pointerType!=="mouse"&&m(!1)},onPointerUp:b=>{b.pointerType==="mouse"&&b.button===0&&m(!0)},onClick:b=>{b.detail===0&&m(!0)},style:{width:"32px",height:"32px",display:"grid",placeItems:"center",padding:0,border:"none",borderRadius:"4px",backgroundColor:"#ffffff",color:"#000000",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)"},children:q.jsx(DFt,{size:16,strokeWidth:2})})})},I7e='system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',DVo={backgroundColor:"#ffffff",color:"#111111",borderRadius:8,boxShadow:"0 6px 24px rgba(0,0,0,0.12), 0 1px 3px rgba(0,0,0,0.08)",border:"1px solid #e5e7eb",padding:4,minWidth:200,maxWidth:320,maxHeight:320,overflowY:"auto",fontSize:13,fontFamily:I7e,outline:"none",zIndex:hQ.viewMenu},PVo={display:"flex",alignItems:"center",gap:8,padding:"7px 10px 7px 8px",borderRadius:6,cursor:"pointer",outline:"none",userSelect:"none",color:"#111111",fontSize:13,fontFamily:I7e},vVo={width:16,height:16,flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center",color:"#111111"},PFt={overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},MVo=`
5617
+ \`\`\``}d(P,R)},children:[q.jsx(E9e,{className:"rf-w-4 rf-h-4"}),"Report Issue"]})]})]})})};function bzo(t,e){return Array.isArray(e)?[t.a*e[0]+t.c*e[1]+t.e,t.b*e[0]+t.d*e[1]+t.f]:{x:t.a*e.x+t.c*e.y+t.e,y:t.b*e.x+t.d*e.y+t.f}}function Dzo(){return{a:1,c:0,e:0,b:0,d:1,f:0}}function c7e(t){return typeof t>"u"}function Ux(t,e=0){return{a:1,c:0,e:t,b:0,d:1,f:e}}function l7e(...t){t=Array.isArray(t[0])?t[0]:t;const e=(n,o)=>({a:n.a*o.a+n.c*o.b,c:n.a*o.c+n.c*o.d,e:n.a*o.e+n.c*o.f+n.e,b:n.b*o.a+n.d*o.b,d:n.b*o.c+n.d*o.d,f:n.b*o.e+n.d*o.f+n.f});switch(t.length){case 0:throw new Error("no matrices provided");case 1:return t[0];case 2:return e(t[0],t[1]);default:{const[n,o,...i]=t,r=e(n,o);return l7e(r,...i)}}}function D8(...t){return l7e(...t)}function lFt(t,e=void 0,n=void 0,o=void 0){c7e(e)&&(e=t);const i={a:t,c:0,e:0,b:0,d:e,f:0};return c7e(n)||c7e(o)?i:l7e([Ux(n,o),i,Ux(-n,-o)])}var gFt=({initialTransform:t,initialTouch1:e,initialTouch2:n,finalTouch1:o,finalTouch2:i})=>{if(!o||!i)return t;const r={x:(e.x+n.x)/2,y:(e.y+n.y)/2},s={x:(o.x+i.x)/2,y:(o.y+i.y)/2},a=Math.hypot(n.x-e.x,n.y-e.y),A=Math.hypot(i.x-o.x,i.y-o.y),c=a===0?1:A/a,l=s.x-r.x,g=s.y-r.y;return D8(Ux(l,g),Ux(r.x,r.y),lFt(c,c),Ux(-r.x,-r.y),t)},Mz=(t={})=>{const e=Z.useRef(null),[n,o]=Z.useState(0),i=t.canvasElm??e.current,[r,s]=Z.useState(t.initialTransform??Dzo()),[a,A]=Z.useState(0),[c,l]=Z.useReducer(f=>f+1,0),g=Z.useCallback(f=>{t.onSetTransform&&t.onSetTransform(f),t.transform||s(f)},[t.onSetTransform,s]),u=Z.useCallback(f=>{g(f),l()},[g]),h=t.transform??r,d=Z.useCallback(()=>{o(Date.now())},[]),_=Z.useRef("none"),m=Z.useRef(null),p=Z.useRef(null);Z.useEffect(()=>{const f=t.canvasElm??e.current;if(f&&!i){A(a+1);return}if(!f){const W=setTimeout(()=>{A(a+1)},100);return()=>clearTimeout(W)}let C=t.transform??r,y={x:0,y:0},E={x:0,y:0},B=!1;const Q=W=>({x:W.pageX-f.getBoundingClientRect().left-window.scrollX,y:W.pageY-f.getBoundingClientRect().top-window.scrollY});function b(W){t.enabled!==!1&&(t.shouldDrag&&!t.shouldDrag(W)||(y=Q(W),!(Date.now()-n<100)&&(B=!0,W.preventDefault())))}function P(W){if(!B||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(W))return;E=Q(W);const j=D8(Ux(E.x-y.x,E.y-y.y),C);g(j),C=j,B=!1}function N(W){if(Q(W),!B||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(W))return;E=Q(W);const j=D8(Ux(E.x-y.x,E.y-y.y),C);g(j)}function R(W){if(t.enabled===!1||t.shouldDrag&&!t.shouldDrag(W))return;const j=Q(W),re=D8(Ux(j.x,j.y),lFt(1-W.deltaY/1e3,1-W.deltaY/1e3),Ux(-j.x,-j.y),C);g(re),C=re,W.preventDefault()}function H(W){if(!B||t.shouldDrag&&!t.shouldDrag(W))return;if(f){const re=f.getBoundingClientRect();if(W.clientX>=re.left+10&&W.clientX<=re.right-10&&W.clientY>=re.top+10&&W.clientY<=re.bottom-10)return}B=!1,E=Q(W);const j=D8(Ux(E.x-y.x,E.y-y.y),C);g(j),C=j}function G(W){if(W.preventDefault(),t.enabled!==!1){if(W.touches.length===1){_.current="drag";const j=W.touches[0];m.current={initialTransform:C,initialTouch:{x:j.clientX,y:j.clientY}}}else if(W.touches.length===2){_.current="pinch";const j=W.touches[0],re=W.touches[1];p.current={initialTransform:C,initialTouch1:{x:j.clientX,y:j.clientY},initialTouch2:{x:re.clientX,y:re.clientY},finalTouch1:null,finalTouch2:null}}}}function O(W){if(W.preventDefault(),t.enabled!==!1){if(_.current==="drag"&&W.touches.length===1&&m.current){const j=W.touches[0],re={x:j.clientX,y:j.clientY},ne=re.x-m.current.initialTouch.x,X=re.y-m.current.initialTouch.y,ee=D8(Ux(ne,X),m.current.initialTransform);g(ee)}else if(_.current==="pinch"&&W.touches.length===2&&p.current){const j=W.touches[0],re=W.touches[1];p.current.finalTouch1={x:j.clientX,y:j.clientY},p.current.finalTouch2={x:re.clientX,y:re.clientY};const ne=gFt(p.current);g(ne)}}}function U(W){W.preventDefault();const j=W.changedTouches[0];if(_.current==="drag"&&m.current&&j){const re={x:j.clientX,y:j.clientY},ne=re.x-m.current.initialTouch.x,X=re.y-m.current.initialTouch.y,ee=D8(Ux(ne,X),m.current.initialTransform);g(ee),C=ee}else if(_.current==="pinch"&&p.current){const re=gFt(p.current);g(re),C=re}_.current="none",m.current=null,p.current=null}return f.addEventListener("mousedown",b),f.addEventListener("mouseup",P),window.addEventListener("mousemove",N),f.addEventListener("mouseout",H),f.addEventListener("wheel",R),f.addEventListener("touchstart",G,{passive:!1}),f.addEventListener("touchmove",O,{passive:!1}),f.addEventListener("touchend",U,{passive:!1}),f.addEventListener("touchcancel",U,{passive:!1}),()=>{f.removeEventListener("mousedown",b),f.removeEventListener("mouseup",P),window.removeEventListener("mousemove",N),f.removeEventListener("mouseout",H),f.removeEventListener("wheel",R),f.removeEventListener("touchstart",G),f.removeEventListener("touchmove",O),f.removeEventListener("touchend",U),f.removeEventListener("touchcancel",U)}},[i,a,c,n,t.enabled,t.shouldDrag]);const I=Z.useCallback(f=>bzo(h,f),[h]);return{ref:e,transform:h,applyTransformToPoint:I,setTransform:u,cancelDrag:d}},Pzo=Mz;function uFt(t,e,n){if(!e||!n)return;let o=t.get(e);o||(o=new Set,t.set(e,o)),o.add(n);let i=t.get(n);i||(i=new Set,t.set(n,i)),i.add(e)}function vzo(t,e){if(!e.subcircuit_id&&!e.source_group_id)return[...t];let n=e;if(e.subcircuit_id){const a=new Set([e.subcircuit_id]),A=new Map,c=new Map;for(const g of t)if(g.type==="source_group"){const u=g.source_group_id,h=g.subcircuit_id;h&&c.set(u,h);const d=g.parent_source_group_id;d&&(A.has(d)||A.set(d,[]),A.get(d).push(u))}let l;for(const[g,u]of c)if(u===e.subcircuit_id){l=g;break}if(l){const g=u=>{const h=A.get(u)||[];for(const d of h){const _=c.get(d);_&&a.add(_),g(d)}};g(l),n={...e,subcircuit_ids:Array.from(a)}}}const o=new Map;for(const a of t){const A=`${a.type}_id`,c=a[A];typeof c=="string"&&o.set(c,a)}const i=new Map;for(const a of t){const A=Object.entries(a);for(const[c,l]of A)if(c!=="parent_source_group_id"){if(c.endsWith("_id")&&typeof l=="string"){const g=o.get(l);uFt(i,a,g)}else if(c.endsWith("_ids")&&Array.isArray(l)){for(const g of l)if(typeof g=="string"){const u=o.get(g);uFt(i,a,u)}}}}const r=[],s=new Set;for(const a of t){let A=!1;(n.subcircuit_id&&"subcircuit_id"in a&&a.subcircuit_id===n.subcircuit_id||n.subcircuit_ids&&"subcircuit_id"in a&&a.subcircuit_id&&n.subcircuit_ids.includes(a.subcircuit_id)||n.source_group_id&&"source_group_id"in a&&a.source_group_id===n.source_group_id||n.source_group_id&&"member_source_group_ids"in a&&Array.isArray(a.member_source_group_ids)&&a.member_source_group_ids.includes(n.source_group_id))&&(A=!0),A&&(r.push(a),s.add(a))}for(;r.length>0;){const a=r.shift(),A=i.get(a);if(A)for(const c of A)s.has(c)||(s.add(c),r.push(c))}return t.filter(a=>s.has(a))}var g7e=((t,e={})=>{const n=t;let o=n._internal_store;if(!o){o={counts:{},editCount:0},n._internal_store=o;for(const r of n){const s=r.type,a=r[`${s}_id`];if(!a)continue;const A=Number.parseInt(a.split("_").pop());Number.isNaN(A)||(o.counts[s]=Math.max(o.counts[s]??0,A))}}const i=new Proxy({},{get:(r,s)=>{if(s==="toArray")return()=>(n.editCount=o.editCount,n);if(s==="editCount")return o.editCount;if(s==="subtree")return A=>g7e(vzo(n,A),e);if(s==="insert")return A=>{const c=A.type;if(!c)throw new Error("insert requires an element with a type");o.counts[c]??=-1,o.counts[c]++;const l=o.counts[c],g={...A,type:c,[`${c}_id`]:`${c}_${l}`};return e.validateInserts&&(Fw[c]??VP).parse(g),n.push(g),o.editCount++,g};if(s==="insertAll")return A=>A.map(c=>i.insert(c));const a=s;return{get:A=>n.find(c=>c.type===a&&c[`${a}_id`]===A),getUsing:A=>{const c=Object.keys(A);if(c.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const l=c[0],g=l.replace("_id",""),u=n.find(h=>h.type===g&&h[l]===A[l]);return u?n.find(h=>h.type===a&&h[`${a}_id`]===u[`${a}_id`]):null},getWhere:A=>{const c=Object.keys(A);return n.find(l=>l.type===a&&c.every(g=>l[g]===A[g]))},list:A=>{const c=A?Object.keys(A):[];return n.filter(l=>l.type===a&&c.every(g=>l[g]===A[g]))},insert:A=>{o.counts[a]??=-1,o.counts[a]++;const c=o.counts[a],l={type:a,[`${a}_id`]:`${a}_${c}`,...A};return e.validateInserts&&(Fw[a]??VP).parse(l),n.push(l),o.editCount++,l},delete:A=>{const c=n.find(l=>l[`${a}_id`]===A);c&&(n.splice(n.indexOf(c),1),o.editCount++)},update:(A,c)=>{const l=n.find(g=>g.type===a&&g[`${a}_id`]===A);return l?(Object.assign(l,c),o.editCount++,l):null},select:A=>{if(a==="source_component")return n.find(c=>c.type==="source_component"&&c.name===A.replace(/\./g,""));if(a==="pcb_port"||a==="source_port"||a==="schematic_port"){const[c,l]=A.replace(/\./g,"").split(/[\s\>]+/),g=n.find(h=>h.type==="source_component"&&h.name===c);if(!g)return null;const u=n.find(h=>h.type==="source_port"&&h.source_component_id===g.source_component_id&&(h.name===l||(h.port_hints??[]).includes(l)));if(!u)return null;if(a==="source_port")return u;if(a==="pcb_port")return n.find(h=>h.type==="pcb_port"&&h.source_port_id===u.source_port_id);if(a==="schematic_port")return n.find(h=>h.type==="schematic_port"&&h.source_port_id===u.source_port_id)}}}}});return i});g7e.unparsed=g7e;function u7e(t){const e=t.type;return`${e}:${t[`${e}_id`]}`}var dFt=((t,e={})=>{let n=t._internal_store_indexed;if(!n){n={counts:{},editCount:0,indexes:{}};for(const s of t){const a=s.type,A=s[`${a}_id`];if(!A)continue;const c=Number.parseInt(A.split("_").pop()||"");Number.isNaN(c)||(n.counts[a]=Math.max(n.counts[a]??0,c))}const i=e.indexConfig||{},r=n.indexes;if(i.byId&&(r.byId=new Map),i.byType&&(r.byType=new Map),i.byRelation&&(r.byRelation=new Map),i.bySubcircuit&&(r.bySubcircuit=new Map),i.byCustomField&&i.byCustomField.length>0){r.byCustomField=new Map;for(const s of i.byCustomField)r.byCustomField.set(s,new Map)}for(const s of t){if(i.byId){const a=u7e(s);r.byId.set(a,s)}if(i.byType){const a=r.byType.get(s.type)||[];a.push(s),r.byType.set(s.type,a)}if(i.byRelation){const a=Object.entries(s);for(const[A,c]of a)if(A.endsWith("_id")&&A!==`${s.type}_id`&&typeof c=="string"){const l=r.byRelation.get(A)||new Map,g=l.get(c)||[];g.push(s),l.set(c,g),r.byRelation.set(A,l)}}if(i.bySubcircuit&&"subcircuit_id"in s){const a=s.subcircuit_id;if(a&&typeof a=="string"){const A=r.bySubcircuit.get(a)||[];A.push(s),r.bySubcircuit.set(a,A)}}if(i.byCustomField&&r.byCustomField){for(const a of i.byCustomField)if(a in s){const A=s[a];if(A!==void 0&&(typeof A=="string"||typeof A=="number")){const c=String(A),l=r.byCustomField.get(a),g=l.get(c)||[];g.push(s),l.set(c,g)}}}}t._internal_store_indexed=n}return new Proxy({},{get:(i,r)=>{if(r==="toArray")return()=>(t.editCount=n.editCount,t);if(r==="editCount")return n.editCount;const s=r;return{get:a=>{const A=e.indexConfig||{};return A.byId&&n.indexes.byId?n.indexes.byId.get(`${s}:${a}`)||null:A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===a)||null:t.find(c=>c.type===s&&c[`${s}_id`]===a)||null},getUsing:a=>{const A=e.indexConfig||{},c=Object.keys(a);if(c.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const l=c[0],g=l.replace("_id","");if(A.byRelation&&n.indexes.byRelation){const h=n.indexes.byRelation.get(l);if(h){const _=(h.get(a[l])||[]).find(p=>p.type===g);if(!_)return null;const m=_[`${s}_id`];return A.byId&&n.indexes.byId?n.indexes.byId.get(`${s}:${m}`)||null:A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(I=>I[`${s}_id`]===m)||null:t.find(p=>p.type===s&&p[`${s}_id`]===m)||null}}const u=t.find(h=>h.type===g&&h[l]===a[l]);return u&&t.find(h=>h.type===s&&h[`${s}_id`]===u[`${s}_id`])||null},getWhere:a=>{const A=e.indexConfig||{},c=Object.keys(a);if(c.length===1&&A.byCustomField&&n.indexes.byCustomField){const l=c[0],g=n.indexes.byCustomField.get(l);if(g){const u=String(a[l]);return(g.get(u)||[]).find(d=>d.type===s)||null}}if("subcircuit_id"in a&&A.bySubcircuit&&n.indexes.bySubcircuit){const l=a.subcircuit_id;return(n.indexes.bySubcircuit.get(l)||[]).find(u=>u.type===s&&c.every(h=>u[h]===a[h]))||null}return A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(g=>c.every(u=>g[u]===a[u]))||null:t.find(l=>l.type===s&&c.every(g=>l[g]===a[g]))||null},list:a=>{const A=e.indexConfig||{},c=a?Object.keys(a):[];if(c.length===0&&A.byType&&n.indexes.byType)return n.indexes.byType.get(s)||[];if(c.length===1&&c[0]==="subcircuit_id"&&A.bySubcircuit&&n.indexes.bySubcircuit){const g=a.subcircuit_id;return(n.indexes.bySubcircuit.get(g)||[]).filter(h=>h.type===s)}let l;return A.byType&&n.indexes.byType?l=n.indexes.byType.get(s)||[]:l=t.filter(g=>g.type===s),c.length>0?l.filter(g=>c.every(u=>g[u]===a[u])):l},insert:a=>{n.counts[s]??=-1,n.counts[s]++;const A=n.counts[s],c={type:s,[`${s}_id`]:`${s}_${A}`,...a};e.validateInserts&&(Fw[s]??VP).parse(c),t.push(c),n.editCount++;const l=e.indexConfig||{};if(l.byId&&n.indexes.byId){const g=u7e(c);n.indexes.byId.set(g,c)}if(l.byType&&n.indexes.byType){const g=n.indexes.byType.get(s)||[];g.push(c),n.indexes.byType.set(s,g)}if(l.byRelation&&n.indexes.byRelation){const g=Object.entries(c);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${c.type}_id`&&typeof h=="string"){const d=n.indexes.byRelation.get(u)||new Map,_=d.get(h)||[];_.push(c),d.set(h,_),n.indexes.byRelation.set(u,d)}}if(l.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in c){const g=c.subcircuit_id;if(g&&typeof g=="string"){const u=n.indexes.bySubcircuit.get(g)||[];u.push(c),n.indexes.bySubcircuit.set(g,u)}}if(l.byCustomField&&n.indexes.byCustomField){for(const g of l.byCustomField)if(g in c){const u=c[g];if(u!==void 0&&(typeof u=="string"||typeof u=="number")){const h=String(u),d=n.indexes.byCustomField.get(g),_=d.get(h)||[];_.push(c),d.set(h,_)}}}return c},delete:a=>{const A=e.indexConfig||{};let c;if(A.byId&&n.indexes.byId?c=n.indexes.byId.get(`${s}:${a}`):A.byType&&n.indexes.byType?c=(n.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===a):c=t.find(g=>g[`${s}_id`]===a),!c)return;const l=t.indexOf(c);if(l>=0&&(t.splice(l,1),n.editCount++),A.byId&&n.indexes.byId){const g=u7e(c);n.indexes.byId.delete(g)}if(A.byType&&n.indexes.byType){const u=(n.indexes.byType.get(s)||[]).filter(h=>h[`${s}_id`]!==a);n.indexes.byType.set(s,u)}if(A.byRelation&&n.indexes.byRelation)for(const[g,u]of n.indexes.byRelation.entries())for(const[h,d]of u.entries()){const _=d.filter(m=>m!==c);_.length===0?u.delete(h):u.set(h,_)}if(A.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in c){const g=c.subcircuit_id;if(g){const h=(n.indexes.bySubcircuit.get(g)||[]).filter(d=>d!==c);h.length===0?n.indexes.bySubcircuit.delete(g):n.indexes.bySubcircuit.set(g,h)}}if(A.byCustomField&&n.indexes.byCustomField)for(const g of n.indexes.byCustomField.values())for(const[u,h]of g.entries()){const d=h.filter(_=>_!==c);d.length===0?g.delete(u):g.set(u,d)}},update:(a,A)=>{const c=e.indexConfig||{};let l;if(c.byId&&n.indexes.byId?l=n.indexes.byId.get(`${s}:${a}`):c.byType&&n.indexes.byType?l=(n.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===a):l=t.find(g=>g.type===s&&g[`${s}_id`]===a),!l)return null;if(c.byRelation&&n.indexes.byRelation){const g=Object.entries(l);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${l.type}_id`&&typeof h=="string"&&u in A&&A[u]!==h){const d=n.indexes.byRelation.get(u);if(d){const m=(d.get(h)||[]).filter(p=>p!==l);m.length===0?d.delete(h):d.set(h,m)}}}if(c.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in l&&"subcircuit_id"in A){const g=l.subcircuit_id,u=A.subcircuit_id;if(g!==u){const d=(n.indexes.bySubcircuit.get(g)||[]).filter(_=>_!==l);d.length===0?n.indexes.bySubcircuit.delete(g):n.indexes.bySubcircuit.set(g,d)}}if(c.byCustomField&&n.indexes.byCustomField){for(const g of c.byCustomField)if(g in l&&g in A&&l[g]!==A[g]){const u=n.indexes.byCustomField.get(g);if(u){const h=String(l[g]),_=(u.get(h)||[]).filter(m=>m!==l);_.length===0?u.delete(h):u.set(h,_)}}}if(Object.assign(l,A),n.editCount++,c.byRelation&&n.indexes.byRelation){const g=Object.entries(l);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${l.type}_id`&&typeof h=="string"&&u in A){const d=n.indexes.byRelation.get(u)||new Map,_=d.get(h)||[];_.includes(l)||(_.push(l),d.set(h,_),n.indexes.byRelation.set(u,d))}}if(c.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in l&&"subcircuit_id"in A){const g=l.subcircuit_id;if(g&&typeof g=="string"){const u=n.indexes.bySubcircuit.get(g)||[];u.includes(l)||(u.push(l),n.indexes.bySubcircuit.set(g,u))}}if(c.byCustomField&&n.indexes.byCustomField){for(const g of c.byCustomField)if(g in l&&g in A){const u=l[g];if(u!==void 0&&(typeof u=="string"||typeof u=="number")){const h=String(u),d=n.indexes.byCustomField.get(g),_=d.get(h)||[];_.includes(l)||(_.push(l),d.set(h,_))}}}return l},select:a=>{if(s==="source_component")return t.find(A=>A.type==="source_component"&&A.name===a.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[A,c]=a.replace(/\./g,"").split(/[\s\>]+/),l=t.find(u=>u.type==="source_component"&&u.name===A);if(!l)return null;const g=t.find(u=>u.type==="source_port"&&u.source_component_id===l.source_component_id&&(u.name===c||(u.port_hints??[]).includes(c)));if(!g)return null;if(s==="source_port")return g;if(s==="pcb_port")return t.find(u=>u.type==="pcb_port"&&u.source_port_id===g.source_port_id)||null;if(s==="schematic_port")return t.find(u=>u.type==="schematic_port"&&u.source_port_id===g.source_port_id)||null}return null}}}})});dFt.unparsed=dFt;var hFt=(t,e)=>({minX:Math.min(t.minX,e.minX),minY:Math.min(t.minY,e.minY),maxX:Math.max(t.maxX,e.maxX),maxY:Math.max(t.maxY,e.maxY)}),wz=(t,e,n)=>{const o=n/2;return{minX:t-o,minY:e-o,maxX:t+o,maxY:e+o}},_Ft=(t,e,n,o,i)=>{const r=n/2,s=o/2,a=i*Math.PI/180,A=Math.cos(a),c=Math.sin(a),l=[{x:-r,y:-s},{x:r,y:-s},{x:r,y:s},{x:-r,y:s}].map(g=>({x:t+g.x*A-g.y*c,y:e+g.x*c+g.y*A}));return{minX:Math.min(...l.map(g=>g.x)),minY:Math.min(...l.map(g=>g.y)),maxX:Math.max(...l.map(g=>g.x)),maxY:Math.max(...l.map(g=>g.y))}},Mzo=(t,e,n,o,i)=>{const r=n/2,s=o/2,a=i*Math.PI/180,A=Math.cos(a),c=Math.sin(a),l=Math.hypot(r*A,s*c),g=Math.hypot(r*c,s*A);return{minX:t-l,minY:e-g,maxX:t+l,maxY:e+g}},wzo=(t,e,n,o,i)=>{const r=Math.min(n,o)/2,s=Math.max(n,o)/2-r,a=i*Math.PI/180,A=n>=o?{x:s,y:0}:{x:0,y:s},c={x:A.x*Math.cos(a)-A.y*Math.sin(a),y:A.x*Math.sin(a)+A.y*Math.cos(a)},l=Math.abs(c.x)+r,g=Math.abs(c.y)+r;return{minX:t-l,minY:e-g,maxX:t+l,maxY:e+g}},wae=t=>t.length===0?null:{minX:Math.min(...t.map(e=>e.x)),minY:Math.min(...t.map(e=>e.y)),maxX:Math.max(...t.map(e=>e.x)),maxY:Math.max(...t.map(e=>e.y))},d7e=t=>Array.isArray(t)?t.flatMap(e=>!e||typeof e!="object"?[]:"x"in e&&"y"in e&&typeof e.x=="number"&&typeof e.y=="number"?[{x:e.x,y:e.y}]:"start"in e&&"end"in e?[e.start,e.end].filter(o=>!!(o&&typeof o=="object"&&"x"in o&&"y"in o&&typeof o.x=="number"&&typeof o.y=="number")):[]):[],mFt=t=>{if(!t.type.startsWith("pcb_"))return null;if(t.type==="pcb_smtpad"&&t.shape==="polygon"&&Array.isArray(t.points))return wae(t.points);if(t.type==="pcb_hole"&&t.hole_shape==="circle")return wz(t.x,t.y,t.hole_diameter);if(t.type==="pcb_plated_hole"){let g;if("outer_diameter"in t&&typeof t.outer_diameter=="number"?g=wz(t.x,t.y,t.outer_diameter):"hole_diameter"in t&&typeof t.hole_diameter=="number"&&(g=wz(t.x,t.y,t.hole_diameter)),(t.shape==="oval"||t.shape==="pill")&&typeof t.outer_width=="number"&&typeof t.outer_height=="number"&&(g=(t.shape==="pill"?wzo:Mzo)(t.x,t.y,t.outer_width,t.outer_height,t.ccw_rotation??0)),"rect_pad_width"in t&&typeof t.rect_pad_width=="number"&&"rect_pad_height"in t&&typeof t.rect_pad_height=="number"){const u=_Ft(t.x,t.y,t.rect_pad_width,t.rect_pad_height,"rect_ccw_rotation"in t?t.rect_ccw_rotation??0:0);g=g?hFt(g,u):u}if("hole_diameter"in t&&typeof t.hole_diameter=="number"){const u=wz(t.x+("hole_offset_x"in t?t.hole_offset_x??0:0),t.y+("hole_offset_y"in t?t.hole_offset_y??0:0),t.hole_diameter);g=g?hFt(g,u):u}if(g)return g}const e=t,n=wae(d7e(e.route));if(n)return n;const o=wae(d7e(e.outline));if(o)return o;const i=wae(d7e(e.points));if(i)return i;let r,s,a,A;"x"in t&&"y"in t&&(r=Number(t.x),s=Number(t.y)),"outer_diameter"in t&&(a=Number(t.outer_diameter),A=Number(t.outer_diameter)),"width"in t&&(a=Number(t.width)),"height"in t&&(A=Number(t.height)),"center"in t&&t.center&&typeof t.center=="object"&&"x"in t.center&&"y"in t.center&&(r=Number(t.center.x),s=Number(t.center.y));let c=0;if("rotation"in t&&typeof t.rotation=="number"&&(c=t.rotation),"ccw_rotation"in t&&typeof t.ccw_rotation=="number"&&(c=t.ccw_rotation),r!==void 0&&s!==void 0)return a!==void 0&&A!==void 0?c?_Ft(r,s,a,A,c):{minX:r-a/2,minY:s-A/2,maxX:r+a/2,maxY:s+A/2}:"radius"in t&&typeof t.radius=="number"?wz(r,s,t.radius*2):{minX:r,minY:s,maxX:r,maxY:s};const l=[e.anchor_position,e.position].filter(g=>!!(g&&typeof g=="object"&&"x"in g&&"y"in g&&typeof g.x=="number"&&typeof g.y=="number")).at(0);return l?{minX:l.x,minY:l.y,maxX:l.x,maxY:l.y}:null},Nzo=(t,e)=>t.filter(n=>{const o=mFt(n);return o?o.minX<=e.maxX&&o.maxX>=e.minX&&o.minY<=e.maxY&&o.maxY>=e.minY:!1}),BF={IS_SHOWING_SCHEMATIC_GROUPS:"schematic_viewer_show_groups",IS_SHOWING_SCHEMATIC_PORTS:"schematic_viewer_show_ports",SELECTED_SCHEMATIC_SHEET:"schematic_viewer_selected_sheet"},pFt=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},IFt=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},Rzo=t=>{if(typeof window>"u")return null;try{return localStorage.getItem(t)}catch{return null}},Tzo=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,e)}catch{}},fFt=["#8B0000","#2F4F4F","#191970","#006400","#FF4500","#800080","#2E8B57","#B8860B","#C71585","#008B8B"],kzo=t=>{const{svgDivRef:e,circuitJson:n,circuitJsonKey:o,showGroups:i}=t;Z.useEffect(()=>{if(e.current&&e.current.querySelectorAll(".schematic-group-overlay").forEach(a=>a.remove()),!e.current||!i||!n||n.length===0)return;const r=setTimeout(()=>{if(!e.current)return;const s=e.current.querySelector("svg");if(!s)return;s.querySelectorAll(".schematic-group-overlay").forEach(A=>A.remove());try{const A=U2(n).source_group?.list().filter(I=>!I.is_subcircuit)||[],c=U2(n).schematic_component?.list()||[],l=new Map;A.forEach(I=>{const f=I;if(f.parent_source_group_id){const C=l.get(f.parent_source_group_id)||[];C.push(I.source_group_id),l.set(f.parent_source_group_id,C)}});const g=I=>{const f=[],C=l.get(I)||[];for(const y of C)f.push(y),f.push(...g(y));return f},u=I=>{const f=A.find(C=>C.source_group_id===I);return f?.parent_source_group_id?1+u(f.parent_source_group_id):0},h=A.length>0&&A.some(I=>I.name&&I.name.trim()!=="");let d=[];if(h){const I=new Map;for(const f of c){const C=U2(n).source_component.get(f.source_component_id);C?.source_group_id&&(I.has(C.source_group_id)||I.set(C.source_group_id,[]),I.get(C.source_group_id).push(f))}A.forEach((f,C)=>{let y=I.get(f.source_group_id)||[];const E=g(f.source_group_id);for(const B of E){const Q=I.get(B)||[];y=[...y,...Q]}if(y.length>0){const B=u(f.source_group_id),Q=g(f.source_group_id).length>0;if(f.name?.startsWith("unnamed_board"))return;d.push({id:f.source_group_id,name:f.name||`Group ${C+1}`,components:y,color:fFt[C%fFt.length],depthLevel:B,hasChildren:Q,sourceGroupId:f.source_group_id})}})}const _=s.viewBox.baseVal,m=s.getBoundingClientRect(),p=Math.min(m.width/_.width,m.height/_.height)||1;d.sort((I,f)=>I.depthLevel-f.depthLevel),d.forEach(I=>{if(I.components.length===0)return;const f=Fzo(I.components,s);if(!f)return;const C=Math.max(8,Math.min(25,15/Math.max(p,.3))),y=I.hasChildren?C*.6:0,E=C+y,B=Math.max(1,2/Math.max(p,.5)),Q=I.depthLevel===0?B:B*.7,b=Math.max(4,8/Math.max(p,.5)),P=I.hasChildren?1.3:1,N=b*P,R=N*.5,H=document.createElementNS("http://www.w3.org/2000/svg","rect");H.setAttribute("class","schematic-group-overlay"),H.setAttribute("x",(f.minX-E).toString()),H.setAttribute("y",(f.minY-E).toString()),H.setAttribute("width",(f.maxX-f.minX+E*2).toString()),H.setAttribute("height",(f.maxY-f.minY+E*2).toString()),H.setAttribute("fill","none"),H.setAttribute("stroke",I.color),H.setAttribute("stroke-width",Q.toString()),H.setAttribute("stroke-dasharray",`${N},${R}`),H.setAttribute("opacity","0.8"),H.setAttribute("rx","0"),H.setAttribute("ry","0");const G=Math.max(6,Math.min(20,14/Math.max(p,.2))),O=I.depthLevel===0||I.depthLevel===1?0:I.depthLevel*.2,U=G*(1-O),W=Math.max(1,U*.2),j=I.name,re=document.createElementNS("http://www.w3.org/2000/svg","text");re.setAttribute("font-size",U.toString()),re.setAttribute("font-family","Arial, sans-serif"),re.textContent=j,s.appendChild(re);const ne=re.getBBox();s.removeChild(re);const X=ne.width+W*2,ee=U+W*2,se=f.minX-E,le=f.minY-E-ee,ge=document.createElementNS("http://www.w3.org/2000/svg","rect");ge.setAttribute("class","schematic-group-overlay"),ge.setAttribute("x",se.toString()),ge.setAttribute("y",(le-ee).toString()),ge.setAttribute("width",X.toString()),ge.setAttribute("height",ee.toString()),ge.setAttribute("fill","transparent"),ge.setAttribute("rx","0"),ge.setAttribute("ry","0");const xe=document.createElementNS("http://www.w3.org/2000/svg","text");xe.setAttribute("class","schematic-group-overlay"),xe.setAttribute("x",(se+W).toString()),xe.setAttribute("y",(le+ee-W).toString()),xe.setAttribute("fill",I.color),xe.setAttribute("font-size",U.toString()),xe.setAttribute("font-family","Arial, sans-serif"),xe.setAttribute("font-weight",I.depthLevel===0?"600":"500"),xe.setAttribute("stroke",I.color),xe.setAttribute("stroke-width",Math.max(.2,U*.02).toString()),xe.textContent=j,s.appendChild(H),s.appendChild(ge),s.appendChild(xe)})}catch(A){console.error("Error creating group overlays:",A)}},10);return()=>clearTimeout(r)},[e,o,i])};function Fzo(t,e){let n=1/0,o=1/0,i=-1/0,r=-1/0;for(const a of t){let A=e.querySelector(`g[data-schematic-component-id="${a.schematic_component_id}"]`);if(A||(A=e.querySelector(`[data-schematic-component-id="${a.schematic_component_id}"]`)),A){const c=A.getBBox();n=Math.min(n,c.x),o=Math.min(o,c.y),i=Math.max(i,c.x+c.width),r=Math.max(r,c.y+c.height)}}return n===1/0?null:{minX:n,minY:o,maxX:i,maxY:r}}var h7e="sch-net-faded",CFt="g.trace[data-subcircuit-connectivity-map-key], g.trace-overlays[data-subcircuit-connectivity-map-key]",yFt="[data-schematic-net-label-id]",Lzo=({svgDivRef:t,circuitJson:e,circuitJsonKey:n,enabled:o})=>{Z.useEffect(()=>{const i=t.current;if(!o||!i)return;const{componentIdToKeys:r,netLabelIdToKey:s}=Hzo(e);let a=[];const A=new Map;let c=null;const l=()=>{for(const{el:m}of a)m.classList.remove(h7e);a=[],A.clear(),c=null;const _=i.querySelector("svg");if(_){for(const m of Array.from(_.querySelectorAll(CFt))){const p=m.getAttribute("data-subcircuit-connectivity-map-key"),I=new Set;p&&(I.add(p),A.set(m,p)),a.push({el:m,keys:I})}for(const m of Array.from(_.querySelectorAll("g[data-schematic-component-id]"))){const p=m.getAttribute("data-schematic-component-id");a.push({el:m,keys:r.get(p)??new Set})}for(const m of Array.from(_.querySelectorAll(yFt))){const p=s.get(m.getAttribute("data-schematic-net-label-id")),I=new Set;p&&(I.add(p),A.set(m,p)),a.push({el:m,keys:I})}}},g=_=>{if(_!==c){c=_;for(const{el:m,keys:p}of a)m.classList.toggle(h7e,_!==null&&!p.has(_))}},u=_=>{const m=_.target;if(!(m instanceof Element)){g(null);return}const p=m.closest(`${CFt}, ${yFt}`);if(!p){g(null);return}g(A.get(p)??null)},h=()=>g(null);l(),i.addEventListener("mouseover",u),i.addEventListener("mouseleave",h);const d=new MutationObserver(l);return d.observe(i,{childList:!0}),()=>{d.disconnect(),i.removeEventListener("mouseover",u),i.removeEventListener("mouseleave",h);for(const{el:_}of a)_.classList.remove(h7e)}},[t,n,o])};function Hzo(t){const e=U2(t),n=new Map;for(const r of e.schematic_component.list())r.source_component_id&&n.set(r.source_component_id,r.schematic_component_id);const o=new Map;for(const r of e.source_trace.list()){const s=r.subcircuit_connectivity_map_key;if(s)for(const a of r.connected_source_port_ids??[]){const A=n.get(e.source_port.get(a)?.source_component_id??"");A&&(o.has(A)||o.set(A,new Set),o.get(A).add(s))}}const i=new Map;for(const r of e.schematic_net_label.list()){if(!r.source_net_id)continue;const s=e.source_net.get(r.source_net_id)?.subcircuit_connectivity_map_key??r.source_net_id;i.set(r.schematic_net_label_id,s)}return{componentIdToKeys:o,netLabelIdToKey:i}}var _7e=t=>String(t??"").toLocaleLowerCase(),Nae=(t,e)=>{const n=_7e(t);return n===e?0:n.startsWith(e)?1:n.includes(e)?2:Number.POSITIVE_INFINITY},Gzo=t=>{if(t)return String(t).replace(/^simple_/,"").replaceAll("_"," ").replace(/\b\w/g,e=>e.toLocaleUpperCase())},Ozo=(t,e,n)=>{let i=Gzo(t?.ftype);t?.ftype==="simple_chip"&&t.manufacturer_part_number&&(i=t.manufacturer_part_number);const r=[];t?.display_name===n&&t.name!==n&&r.push(t.name);let s=t?.display_value;if(!s&&t){for(const a of["display_resistance","display_capacitance","display_inductance","display_frequency","symbol_display_value"])if(a in t){const A=t[a];if(typeof A=="string"){s=A;break}}}if(s??(s=e.symbol_display_value),i&&r.push(i),s&&r.push(s),!i&&!s&&t?.manufacturer_part_number&&r.push(t.manufacturer_part_number),r.length!==0)return r.join(" · ")},Kzo=t=>t.type==="source_component"&&"source_component_id"in t,Uzo=t=>t.type==="source_port",Yzo=t=>t.type==="source_trace",zzo=t=>t.type==="schematic_component",Vzo=t=>t.type==="schematic_port",Jzo=t=>t.type==="schematic_net_label",qzo=t=>t.type==="schematic_sheet",EFt=({schematicSheets:t,schematicSheetId:e})=>{if(!(t.length<=1||!e))return t.find(n=>n.schematic_sheet_id===e)?.name},Wzo=(t,e)=>{const n=_7e(e).trim();if(!n)return[];const o=new Map(t.filter(Kzo).map(l=>[l.source_component_id,l])),i=new Map(t.filter(Uzo).map(l=>[l.source_port_id,l])),r=t.filter(Vzo),s=t.filter(Yzo),a=t.filter(qzo),A=[],c=new Map;for(const l of t.filter(zzo)){const g=l.source_component_id?o.get(l.source_component_id):void 0,u=g?.display_name??g?.name??"Component",h=Math.min(Nae(g?.name,n),Nae(g?.display_name,n),Nae(g?.manufacturer_part_number,n));if(Number.isFinite(h)){const d={label:u,detail:Ozo(g,l,u),kind:"component",schematicSheetId:l.schematic_sheet_id,schematicSheetName:EFt({schematicSheets:a,schematicSheetId:l.schematic_sheet_id}),target:{type:"schematic_component",id:l.schematic_component_id}};A.push(d),c.set(d,h)}}for(const l of t.filter(Jzo)){if(!_7e(l.text).includes(n))continue;const g=new Set;for(const f of s.filter(C=>C.connected_source_net_ids.includes(l.source_net_id)))for(const C of f.connected_source_port_ids)g.add(C);const u=l.anchor_position??l.center,h=r.filter(f=>g.has(f.source_port_id)&&(!l.schematic_sheet_id||!f.schematic_sheet_id||f.schematic_sheet_id===l.schematic_sheet_id)).map(f=>({port:f,distance:Math.hypot(f.center.x-u.x,f.center.y-u.y)})).filter(({distance:f})=>f<=1).sort((f,C)=>f.distance-C.distance)[0]?.port,d=h?i.get(h.source_port_id):void 0,_=d?.source_component_id?o.get(d.source_component_id):void 0,m=d?.name??(d?.pin_number!==void 0?`pin${d.pin_number}`:h?.display_pin_label),p=_?.name&&m?`Connected to ${_.name}.${m}`:void 0,I={label:l.text,detail:p,kind:"net",schematicSheetId:l.schematic_sheet_id,schematicSheetName:EFt({schematicSheets:a,schematicSheetId:l.schematic_sheet_id}),target:{type:"schematic_net_label",id:l.schematic_net_label_id}};A.push(I),c.set(I,Nae(l.text,n))}return A.sort((l,g)=>(c.get(l)??Number.POSITIVE_INFINITY)-(c.get(g)??Number.POSITIVE_INFINITY)||l.label.localeCompare(g.label))},jzo=({containerRect:t,targetRect:e,visibleProjection:n,minimumScale:o})=>{const i=n.a||1,r={x:e.left+e.width/2-t.left,y:e.top+e.height/2-t.top},s={x:(r.x-n.e)/i,y:(r.y-n.f)/i},a=Math.max(i,o);return{a,b:0,c:0,d:a,e:t.width/2-s.x*a,f:t.height/2-s.y*a}},Xzo=1.8,xFt=350,$zo=({circuitJson:t,circuitJsonKey:e,svgDivRef:n,containerRef:o,activeSheetId:i,hasMultipleSheets:r,handleSelectSheet:s,svgString:a,svgToScreenProjection:A,setSvgToScreenProjection:c,setIsInteractionEnabled:l})=>{const[g,u]=Z.useState(""),[h,d]=Z.useState(null),_=Z.useRef(null),m=Z.useMemo(()=>Wzo(t,g),[t,e,g]),p=Z.useCallback(C=>{const y=n.current,E=o.current;if(!y||!E)return!1;let B="data-schematic-net-label-id";C.target.type==="schematic_component"&&(B="data-schematic-component-id");const Q=Array.from(y.querySelectorAll(`[${B}]`)).find(H=>H.getAttribute(B)===C.target.id);if(!Q)return!1;const b=Q.getBoundingClientRect(),P=E.getBoundingClientRect();if(!b.width&&!b.height)return!1;_.current&&clearTimeout(_.current);let N=A;const R=getComputedStyle(y).transform;if(R&&R!=="none")try{N=gH(R),y.style.transition="none",y.style.transform=R,y.offsetWidth}catch{}return y.style.transition=`transform ${xFt}ms ease-in-out`,y.offsetWidth,c(jzo({containerRect:P,targetRect:b,visibleProjection:N,minimumScale:Xzo})),_.current=setTimeout(()=>{y.style.transition=""},xFt),y.querySelectorAll(".schematic-search-match").forEach(H=>H.classList.remove("schematic-search-match")),y.querySelectorAll(`[${B}]`).forEach(H=>{H.getAttribute(B)===C.target.id&&H.classList.add("schematic-search-match")}),!0},[o,c,n,A]),I=Z.useCallback(C=>{if(l(!0),C.schematicSheetId&&C.schematicSheetId!==i&&r){s(C.schematicSheetId),d(C);return}p(C)},[i,p,s,r,l]),f=Z.useCallback(()=>{u(""),d(null),_.current&&(clearTimeout(_.current),_.current=null),n.current&&(n.current.style.transition="",n.current.querySelectorAll(".schematic-search-match").forEach(C=>C.classList.remove("schematic-search-match")))},[n]);return Z.useEffect(()=>{if(!h||!a)return;const C=requestAnimationFrame(()=>{p(h)&&d(null)});return()=>cancelAnimationFrame(C)},[p,h,a]),Z.useEffect(()=>{g||n.current?.querySelectorAll(".schematic-search-match").forEach(C=>C.classList.remove("schematic-search-match"))},[g,n]),Z.useEffect(()=>()=>{_.current&&clearTimeout(_.current)},[]),{searchQuery:g,setSearchQuery:u,searchResults:m,handleSearchResultSelect:I,handleCancelSearch:f}};pl("schematic-viewer");var Zzo=()=>{pl.enable("schematic-viewer*")},BFt=t=>{const[e,n]=Z.useState(0),[o,i]=Z.useState(0);return Z.useEffect(()=>{if(!t.current)return;const r=()=>{const a=t.current?.getBoundingClientRect();n(a?.width||0),i(a?.height||0)};r();const s=new ResizeObserver(r);return s.observe(t.current),window.addEventListener("resize",r),()=>{s.disconnect(),window.removeEventListener("resize",r)}},[]),{containerWidth:e,containerHeight:o}},eVo=600,Rae=10,tVo=({containerRef:t})=>{const[e,n]=Z.useState(!1),[o,i]=Z.useState({x:0,y:0}),r=Z.useRef(null),s=Z.useRef(null),a=Z.useRef(null),A=Z.useRef(0),c=Z.useCallback(()=>{a.current!==null&&(window.clearTimeout(a.current),a.current=null)},[]),l=Z.useCallback(_=>{if(_.preventDefault(),Date.now()<A.current)return;const m=s.current;if(!m)return;const p=Math.abs(_.clientX-m.x)>Rae||Math.abs(_.clientY-m.y)>Rae;s.current=null,!p&&(i({x:_.clientX,y:_.clientY}),n(!0))},[]),g=Z.useCallback(_=>{if(c(),_.touches.length!==1){s.current=null;return}const m=_.touches[0];m&&(s.current={x:m.clientX,y:m.clientY},a.current=window.setTimeout(()=>{const p=t.current;if(!p||!s.current)return;const I=p.getBoundingClientRect();i({x:I.left+I.width/2,y:I.top+I.height/2}),n(!0),A.current=Date.now()+1e3,s.current=null},eVo))},[c,t]),u=Z.useCallback(_=>{const m=s.current;if(!m||_.touches.length!==1)return;const p=_.touches[0];(!p||Math.abs(p.clientX-m.x)>Rae||Math.abs(p.clientY-m.y)>Rae)&&(s.current=null,c())},[c]),h=Z.useCallback(()=>{c(),s.current=null},[c]),d=Z.useCallback(_=>{const m=_.target;r.current?.contains(m)||m.closest?.("[data-radix-popper-content-wrapper], [data-radix-dropdown-menu-content]")||n(!1)},[]);return Z.useEffect(()=>{if(e)return document.addEventListener("mousedown",d),document.addEventListener("touchstart",d),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("touchstart",d)}},[d,e]),Z.useEffect(()=>c,[c]),{menuVisible:e,menuPos:o,menuRef:r,setMenuVisible:n,contextMenuEventHandlers:{onMouseDown:_=>{s.current=_.button===2||_.button===0&&_.ctrlKey?{x:_.clientX,y:_.clientY}:null},onContextMenu:l,onTouchStart:g,onTouchMove:u,onTouchEnd:h,onTouchCancel:h}}},nVo=new Set(["type","source_component_id","source_group_id","subcircuit_id","display_name","ftype","are_pins_interchangeable","supplier_part_numbers"]),QFt=["name","resistance","capacitance","inductance","frequency","voltage","current","max_voltage_rating","max_current_rating","power_rating","manufacturer_part_number"],oVo={jlcpcb:t=>`https://jlcpcb.com/partdetail/${encodeURIComponent(t)}`,lcsc:t=>`https://www.lcsc.com/product-detail/${encodeURIComponent(t)}.html`},iVo=t=>{const e=t.trim(),n=/^c?(\d+)$/i.exec(e);return n?`C${n[1]}`:e},SFt=t=>{const e=QFt.indexOf(t);return e===-1?QFt.length:e},rVo=(t,e,n)=>{if(e==="name")return String(n);const o=t[`display_${e}`];if(typeof o=="string"&&o.trim()){const i=e==="resistance"?o.replace(/Ω$/,""):o;return JSON.stringify(i)}return JSON.stringify(n)??String(n)},sVo=t=>Object.entries(t).filter(([e,n])=>nVo.has(e)||e.startsWith("display_")&&e.slice(8)in t?!1:n!=null&&n!=="").sort(([e],[n])=>SFt(e)-SFt(n)||e.localeCompare(n)).map(([e,n])=>({key:e,label:e,value:rVo(t,e,n)})),aVo=t=>{const e=t.supplier_part_numbers;return e?["jlcpcb","lcsc"].flatMap(n=>{const o=e[n];if(!Array.isArray(o))return[];const i=[...new Set(o.filter(r=>!!(typeof r=="string"&&r.trim())).map(iVo))];return i.length?[{key:`supplier_part_numbers.${n}`,label:n,links:i.map(r=>({partNumber:r,href:oVo[n](r)}))}]:[]}):[]},AVo=(t,e)=>{const n=t.find(A=>A.type==="schematic_component"&&A.schematic_component_id===e);if(!n)return null;const o=t.find(A=>A.type==="source_component"&&A.source_component_id===n.source_component_id);if(!o)return null;const i=t.find(A=>A.type==="pcb_component"&&A.source_component_id===o.source_component_id),r=t.find(A=>A.type==="cad_component"&&A.source_component_id===o.source_component_id&&(!i||A.pcb_component_id===i.pcb_component_id)),s=i?.footprinter_string??r?.footprinter_string,a=i?cVo(t,i.pcb_component_id):null;return{schematicComponent:n,sourceComponent:o,pcbComponent:i,footprinterString:s,footprintPreviewCircuitJson:a?.circuitJson,footprintPreviewViewBox:a?.viewBox}},Tae=2,cVo=(t,e)=>{const n=t.find(r=>r.type==="pcb_component"&&r.pcb_component_id===e);if(!n)return null;const o=mFt(n);if(!o)return null;const i={minX:o.minX-Tae,minY:o.minY-Tae,maxX:o.maxX+Tae,maxY:o.maxY+Tae};return{circuitJson:Nzo(t,i),viewBox:i}},lVo=t=>{let e="";for(let o=0;o<t.length;o+=8192)e+=String.fromCharCode(...t.subarray(o,o+8192));return btoa(e)},gVo=(t,e)=>{const n=lVo(oue(iue(JSON.stringify(t)))),o=new URL("https://svg.tscircuit.com/");return o.searchParams.set("svg_type","pcb"),o.searchParams.set("circuit_json",n),o.searchParams.set("viewbox",[e.minX,e.minY,e.maxX,e.maxY].join(",")),o.searchParams.set("background_color","#f8fafc"),o.toString()},hQ={contextMenu:110,viewMenu:55,viewMenuIcon:48,clickToInteractOverlay:100,schematicComponentDetailsTooltip:105,schematicComponentHoverOutline:47,schematicPortHoverOutline:48,schematicSearch:101},m7e=Z.createContext(null),uVo=5,dVo=(t,e)=>!t&&!e?!0:!t||!e?!1:t.minX===e.minX&&t.maxX===e.maxX&&t.minY===e.minY&&t.maxY===e.maxY,hVo=({children:t})=>Z.useContext(m7e)?q.jsx(q.Fragment,{children:t}):q.jsx(_Vo,{children:t}),_Vo=({children:t})=>{const e=Z.useRef({pointer:null,boundingBoxes:new Map,hoveringIds:new Set,subscribers:new Set,mouseDownPosition:null}),n=Z.useCallback(()=>{for(const l of e.current.subscribers)l()},[]),o=Z.useCallback(()=>{const l=e.current.pointer,g=new Set;if(l)for(const[h,d]of e.current.boundingBoxes){const _=d.bounds;_&&l.x>=_.minX&&l.x<=_.maxX&&l.y>=_.minY&&l.y<=_.maxY&&g.add(h)}const u=e.current.hoveringIds;g.size===u.size&&[...g].every(h=>u.has(h))||(e.current.hoveringIds=g,n())},[n]),i=Z.useCallback((l,g)=>{e.current.boundingBoxes.set(l,g),o()},[o]),r=Z.useCallback((l,g)=>{const u=e.current.boundingBoxes.get(l);u&&dVo(u.bounds,g.bounds)&&u.onClick===g.onClick||(e.current.boundingBoxes.set(l,g),o())},[o]),s=Z.useCallback(l=>{e.current.boundingBoxes.delete(l)&&o()},[o]),a=Z.useCallback(l=>(e.current.subscribers.add(l),()=>{e.current.subscribers.delete(l)}),[]),A=Z.useCallback(l=>e.current.hoveringIds.has(l),[]);Z.useEffect(()=>{const l=d=>{const{clientX:_,clientY:m}=d,p=e.current.pointer;p&&p.x===_&&p.y===m||(e.current.pointer={x:_,y:m},o())},g=()=>{e.current.pointer!==null&&(e.current.pointer=null,e.current.mouseDownPosition=null,o())},u=d=>{e.current.mouseDownPosition={x:d.clientX,y:d.clientY}},h=d=>{const{clientX:_,clientY:m}=d,p=e.current.mouseDownPosition;if(p&&Math.sqrt(Math.pow(_-p.x,2)+Math.pow(m-p.y,2))>uVo){e.current.mouseDownPosition=null;return}e.current.mouseDownPosition=null;for(const I of e.current.boundingBoxes.values()){const f=I.bounds;f&&_>=f.minX&&_<=f.maxX&&m>=f.minY&&m<=f.maxY&&I.onClick?.(d)}};return window.addEventListener("pointermove",l,{passive:!0}),window.addEventListener("pointerdown",l,{passive:!0}),window.addEventListener("pointerup",l,{passive:!0}),window.addEventListener("pointerleave",g),window.addEventListener("pointercancel",g),window.addEventListener("blur",g),window.addEventListener("mousedown",u,{passive:!0}),window.addEventListener("click",h,{passive:!0}),()=>{window.removeEventListener("pointermove",l),window.removeEventListener("pointerdown",l),window.removeEventListener("pointerup",l),window.removeEventListener("pointerleave",g),window.removeEventListener("pointercancel",g),window.removeEventListener("blur",g),window.removeEventListener("mousedown",u),window.removeEventListener("click",h)}},[o]);const c=Z.useMemo(()=>({registerBoundingBox:i,updateBoundingBox:r,unregisterBoundingBox:s,subscribe:a,isHovering:A}),[i,r,s,a,A]);return q.jsx(m7e.Provider,{value:c,children:t})},p7e={color:"#64748b",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45},mVo=({sourceComponent:t,footprinterString:e,footprintPreviewCircuitJson:n,footprintPreviewViewBox:o,left:i,top:r,width:s,maxHeight:a})=>{const A=Z.useMemo(()=>sVo(t),[t]),c=Z.useMemo(()=>aVo(t),[t]),l=Z.useMemo(()=>n?.length&&o?gVo(n,o):void 0,[n,o]);return q.jsxs("dialog",{open:!0,"aria-label":`${t.name} component details`,"data-schematic-component-details-tooltip":!0,style:{position:"absolute",left:i,right:"auto",top:r,bottom:"auto",width:s,maxHeight:a,margin:0,padding:0,overflowY:"auto",boxSizing:"border-box",border:"1px solid #cbd5e1",borderRadius:"4px",backgroundColor:"rgba(255, 255, 255, 0.98)",boxShadow:"0 20px 25px -5px rgba(15, 23, 42, 0.18), 0 8px 10px -6px rgba(15, 23, 42, 0.12)",color:"#0f172a",fontFamily:'Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',pointerEvents:"auto",userSelect:"text",WebkitUserSelect:"text",zIndex:hQ.schematicComponentDetailsTooltip},onMouseDown:g=>g.stopPropagation(),onClick:g=>g.stopPropagation(),children:[q.jsxs("dl",{style:{display:"grid",gridTemplateColumns:"minmax(110px, 0.8fr) minmax(0, 1.2fr)",gap:"6px 12px",margin:0,padding:"8px"},children:[A.map(g=>q.jsxs("div",{style:{display:"contents"},children:[q.jsx("dt",{style:p7e,children:g.label}),q.jsx("dd",{style:{minWidth:0,margin:0,color:"#1e293b",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45,overflowWrap:"anywhere"},children:g.value})]},g.key)),c.map(g=>q.jsxs("div",{style:{display:"contents"},children:[q.jsx("dt",{style:p7e,children:g.label}),q.jsx("dd",{style:{minWidth:0,margin:0,fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45,overflowWrap:"anywhere"},children:g.links.map((u,h)=>q.jsxs("span",{children:[h>0&&", ",q.jsx("a",{href:u.href,target:"_blank",rel:"noreferrer noopener",style:{color:"#2563eb",textDecoration:"underline"},children:u.partNumber})]},u.href))})]},g.key)),e&&q.jsxs("div",{style:{display:"contents"},children:[q.jsx("dt",{style:p7e,children:"footprint"}),q.jsx("dd",{style:{minWidth:0,margin:0,color:"#1e293b",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45,overflowWrap:"anywhere"},children:JSON.stringify(e)})]})]}),l&&q.jsx("div",{style:{padding:"0 4px 4px"},children:q.jsx("div",{style:{height:"210px",overflow:"hidden",border:"1px solid #e2e8f0",borderRadius:"2px",background:"#f8fafc"},children:q.jsx("img",{src:l,alt:`${t.name}${e?` ${e}`:""} PCB footprint`,loading:"lazy",referrerPolicy:"no-referrer",style:{display:"block",width:"100%",height:"100%",objectFit:"contain"}})})})]})},bFt=t=>{const e=Z.useContext(m7e);if(!e)throw new Error("useMouseEventsOverBoundingBox must be used within a MouseTracker");const n=Z.useId(),o=Z.useRef(t);o.current=t;const i=Z.useMemo(()=>s=>{o.current.onClick?.(s)},[]);return Z.useEffect(()=>(e.registerBoundingBox(n,{bounds:o.current.bounds,onClick:o.current.onClick?i:void 0}),()=>{e.unregisterBoundingBox(n)}),[e,i,n]),Z.useEffect(()=>{e.updateBoundingBox(n,{bounds:o.current.bounds,onClick:o.current.onClick?i:void 0})},[e,i,n,t.bounds?.minX,t.bounds?.maxX,t.bounds?.minY,t.bounds?.maxY,t.onClick]),{hovering:Z.useSyncExternalStore(e.subscribe,()=>e.isHovering(n),()=>!1)}},pVo=(t,e)=>!t&&!e?!0:!t||!e?!1:Math.abs(t.bounds.minX-e.bounds.minX)<.5&&Math.abs(t.bounds.maxX-e.bounds.maxX)<.5&&Math.abs(t.bounds.minY-e.bounds.minY)<.5&&Math.abs(t.bounds.maxY-e.bounds.maxY)<.5&&Math.abs(t.rect.left-e.rect.left)<.5&&Math.abs(t.rect.top-e.rect.top)<.5&&Math.abs(t.rect.width-e.rect.width)<.5&&Math.abs(t.rect.height-e.rect.height)<.5,IVo=({componentId:t,svgDivRef:e,containerRef:n,onComponentClick:o,onHoverChange:i,showOutline:r,circuitJsonKey:s})=>{const[a,A]=Z.useState(null),c=Z.useRef(null),l=Z.useCallback(()=>{c.current=null;const m=e.current,p=n.current;if(!m||!p){A(E=>E&&null);return}const I=m.querySelector(`[data-schematic-component-id="${t}"]`);if(!I){A(E=>E&&null);return}const f=I.getBoundingClientRect(),C=p.getBoundingClientRect(),y={bounds:{minX:f.left,maxX:f.right,minY:f.top,maxY:f.bottom},rect:{left:f.left-C.left,top:f.top-C.top,width:f.width,height:f.height}};A(E=>pVo(E,y)?E:y)},[t,n,e]),g=Z.useCallback(()=>{c.current===null&&(c.current=window.requestAnimationFrame(l))},[l]);Z.useEffect(()=>{g()},[g,s]),Z.useEffect(()=>{g();const m=e.current,p=n.current;if(!m||!p)return;const I=typeof ResizeObserver<"u"?new ResizeObserver(()=>{g()}):null;I?.observe(p),I?.observe(m);const f=typeof MutationObserver<"u"?new MutationObserver(()=>{g()}):null;return f?.observe(m,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",g,!0),window.addEventListener("resize",g),()=>{I?.disconnect(),f?.disconnect(),window.removeEventListener("scroll",g,!0),window.removeEventListener("resize",g),c.current!==null&&(cancelAnimationFrame(c.current),c.current=null)}},[g,e,n]);const u=Z.useCallback(m=>{o&&o(t,m)},[t,o]),h=a?.bounds??null,{hovering:d}=bFt({bounds:h,onClick:o?u:void 0});if(Z.useEffect(()=>{i&&i(t,d)},[d,t,i]),!a||!d||!r)return null;const _=a.rect;return q.jsx("div",{style:{position:"absolute",left:_.left,top:_.top,width:_.width,height:_.height,border:"1.5px solid rgba(51, 153, 255, 0.9)",pointerEvents:"none",zIndex:hQ.schematicComponentHoverOutline}})},fVo=(t,e)=>!t&&!e?!0:!t||!e?!1:Math.abs(t.bounds.minX-e.bounds.minX)<.5&&Math.abs(t.bounds.maxX-e.bounds.maxX)<.5&&Math.abs(t.bounds.minY-e.bounds.minY)<.5&&Math.abs(t.bounds.maxY-e.bounds.maxY)<.5&&Math.abs(t.rect.left-e.rect.left)<.5&&Math.abs(t.rect.top-e.rect.top)<.5&&Math.abs(t.rect.width-e.rect.width)<.5&&Math.abs(t.rect.height-e.rect.height)<.5,CVo=({portId:t,portLabel:e,svgDivRef:n,containerRef:o,onPortClick:i,onHoverChange:r,showOutline:s,circuitJsonKey:a})=>{const[A,c]=Z.useState(null),l=Z.useRef(null),g=Z.useCallback(()=>{l.current=null;const p=n.current,I=o.current;if(!p||!I){c(Q=>Q&&null);return}const f=p.querySelector(`[data-schematic-port-id="${t}"]`);if(!f){c(Q=>Q&&null);return}const C=f.getBoundingClientRect(),y=I.getBoundingClientRect(),E=4,B={bounds:{minX:C.left-E,maxX:C.right+E,minY:C.top-E,maxY:C.bottom+E},rect:{left:C.left-y.left-E,top:C.top-y.top-E,width:C.width+E*2,height:C.height+E*2}};c(Q=>fVo(Q,B)?Q:B)},[t,o,n]),u=Z.useCallback(()=>{l.current===null&&(l.current=window.requestAnimationFrame(g))},[g]);Z.useEffect(()=>{u()},[u,a]),Z.useEffect(()=>{u();const p=n.current,I=o.current;if(!p||!I)return;const f=typeof ResizeObserver<"u"?new ResizeObserver(()=>{u()}):null;f?.observe(I),f?.observe(p);const C=typeof MutationObserver<"u"?new MutationObserver(()=>{u()}):null;return C?.observe(p,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{f?.disconnect(),C?.disconnect(),window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u),l.current!==null&&(cancelAnimationFrame(l.current),l.current=null)}},[u,n,o]);const h=Z.useCallback(p=>{i&&i(t,p)},[t,i]),d=A?.bounds??null,{hovering:_}=bFt({bounds:d,onClick:i?h:void 0});if(Z.useEffect(()=>{r&&r(t,_)},[_,t,r]),!A||!s)return null;const m=A.rect;return q.jsxs(q.Fragment,{children:[q.jsx("div",{style:{position:"absolute",left:m.left,top:m.top,width:m.width,height:m.height,border:_?"1.5px solid rgba(255, 153, 51, 0.9)":"1.5px solid rgba(255, 153, 51, 0.3)",backgroundColor:_?"rgba(255, 153, 51, 0.15)":"rgba(255, 153, 51, 0.05)",borderRadius:"50%",pointerEvents:"none",zIndex:hQ.schematicPortHoverOutline,transition:"border-color 0.15s, background-color 0.15s"}}),_&&e&&q.jsx("div",{style:{position:"absolute",left:m.left+m.width/2,top:m.top-24,transform:"translateX(-50%)",backgroundColor:"rgba(0, 0, 0, 0.85)",color:"white",padding:"4px 8px",borderRadius:"4px",fontSize:"12px",fontFamily:"monospace",whiteSpace:"nowrap",pointerEvents:"none",zIndex:hQ.schematicPortHoverOutline+1},children:e})]})},Nz=({children:t,size:e,strokeWidth:n})=>q.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:n,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t}),DFt=t=>q.jsxs(Nz,{...t,children:[q.jsx("circle",{cx:"11",cy:"11",r:"8"}),q.jsx("path",{d:"m21 21-4.34-4.34"})]}),yVo=t=>q.jsxs(Nz,{...t,children:[q.jsx("path",{d:"M18 6 6 18"}),q.jsx("path",{d:"m6 6 12 12"})]}),EVo=t=>q.jsxs(Nz,{...t,children:[q.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),q.jsx("rect",{x:"8",y:"8",width:"8",height:"8",rx:"1"}),q.jsx("path",{d:"M7 2v2M12 2v2M17 2v2M7 20v2M12 20v2M17 20v2M2 7h2M2 12h2M2 17h2M20 7h2M20 12h2M20 17h2"})]}),xVo=t=>q.jsxs(Nz,{...t,children:[q.jsx("path",{d:"M15 6a9 9 0 0 0-9 9V3"}),q.jsx("circle",{cx:"18",cy:"6",r:"3"}),q.jsx("circle",{cx:"6",cy:"18",r:"3"})]}),BVo=t=>q.jsxs(Nz,{...t,children:[q.jsx("path",{d:"M20 4v7a4 4 0 0 1-4 4H4"}),q.jsx("path",{d:"m9 10-5 5 5 5"})]}),QVo=({text:t,query:e})=>{const n=e.trim().toLocaleLowerCase();if(!n)return t;const o=t.toLocaleLowerCase(),i=[];let r=0,s=o.indexOf(n);for(;s!==-1;)s>r&&i.push(t.slice(r,s)),i.push(q.jsx("strong",{style:{fontWeight:700},children:t.slice(s,s+n.length)},`${s}-${r}`)),r=s+n.length,s=o.indexOf(n,r);return r<t.length&&i.push(t.slice(r)),i.length>0?i:t},SVo=()=>typeof navigator>"u"?"Ctrl F":/mac/i.test(navigator.platform)?"⌘ F":"Ctrl F",bVo=({query:t,onQueryChange:e,onCancel:n,results:o,onSelect:i,viewerContainerRef:r})=>{const[s,a]=Z.useState(!1),[A,c]=Z.useState(null),[l,g]=Z.useState(null),u=Z.useRef(null),h=Z.useRef(null),d=SVo();Z.useEffect(()=>{c(b=>o.some(P=>P.target.id===b)?b:o.find(P=>P.kind==="component")?.target.id??o[0]?.target.id??null)},[o]),Z.useEffect(()=>{A&&h.current?.querySelector(`[data-search-result-id="${A}"]`)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[A]),Z.useEffect(()=>{const b=N=>{if(N.key==="Escape"&&s){N.preventDefault(),N.stopPropagation(),N.stopImmediatePropagation(),n(),a(!1),u.current?.blur();return}N.code!=="KeyF"&&N.key.toLocaleLowerCase()!=="f"||!N.metaKey&&!N.ctrlKey||r.current?.matches(":hover")&&(N.preventDefault(),N.stopPropagation(),N.stopImmediatePropagation(),a(!0),requestAnimationFrame(()=>{u.current?.focus(),u.current?.select()}))},P=[window];try{window.parent!==window&&window.parent.document&&P.push(window.parent)}catch{}return P.forEach(N=>N.addEventListener("keydown",b,{capture:!0})),()=>{P.forEach(N=>N.removeEventListener("keydown",b,{capture:!0}))}},[s,n,r]);const _=()=>{n(),a(!1),u.current?.blur()},m=b=>{a(!0),b&&requestAnimationFrame(()=>u.current?.focus())},p=o.filter(b=>b.kind==="component"),I=o.filter(b=>b.kind==="net"),f=[...p,...I],C=f.find(b=>b.target.id===A)??f[0],y=o.length===1?"1 result":`${o.length} results`;let E="none";t&&(E="1px solid #e8e8e8");const B=b=>{if(!(b.key==="Enter"&&b.target instanceof Element&&b.target.closest('[aria-label="Clear search"]'))){if(b.key==="Escape"){b.preventDefault(),_();return}if(f.length>0&&(b.key==="ArrowDown"||b.key==="ArrowUp")){b.preventDefault();let P=-1;b.key==="ArrowDown"&&(P=1),c(N=>{const R=f.findIndex(O=>O.target.id===N);let H=R;R===-1&&(H=0,P===1&&(H=-1));const G=(H+P+f.length)%f.length;return f[G]?.target.id??null});return}b.key==="Enter"&&C&&(b.preventDefault(),i(C))}},Q=(b,P)=>P.length===0?null:q.jsxs("section",{children:[q.jsx("div",{style:{padding:"6px 12px 3px",backgroundColor:"#f7f7f8",color:"#777777",fontSize:"11px",fontWeight:600,letterSpacing:"0.02em",textTransform:"lowercase"},children:b}),P.map(N=>{const R=N.target.id===C?.target.id,H=N.target.id===l;let G="#ffffff";(H||R)&&(G="#f1f3f5");let O=q.jsx(xVo,{size:15,strokeWidth:1.8});N.kind==="component"&&(O=q.jsx(EVo,{size:15,strokeWidth:1.8}));const U=()=>{u.current?.blur(),c(N.target.id),i(N)};return q.jsxs("button",{type:"button","data-search-result-id":N.target.id,onPointerUp:W=>{W.button===0&&U()},onClick:W=>{W.detail===0&&U()},onMouseEnter:()=>g(N.target.id),onMouseLeave:()=>g(null),style:{width:"100%",display:"flex",alignItems:"center",gap:"9px",padding:"7px 12px",border:"none",background:G,color:"#222222",cursor:"pointer",textAlign:"left"},children:[q.jsx("span",{style:{width:"26px",height:"26px",flexShrink:0,display:"grid",placeItems:"center",border:"1px solid #e5e5e5",borderRadius:"6px",backgroundColor:"#f7f7f7",color:"#666666"},children:O}),q.jsxs("span",{style:{minWidth:0,flex:1},children:[q.jsx("span",{style:{display:"block",overflow:"hidden",fontSize:"13px",fontWeight:400,lineHeight:1.25,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:q.jsx(QVo,{text:N.label,query:t})}),N.detail&&q.jsx("span",{style:{display:"block",overflow:"hidden",marginTop:"2px",color:"#777777",fontSize:"11px",lineHeight:1.2,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:N.detail}),N.schematicSheetName&&q.jsxs("span",{style:{display:"block",overflow:"hidden",marginTop:"2px",color:"#777777",fontSize:"11px",lineHeight:1.2,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Sheet: ",N.schematicSheetName]})]}),R&&q.jsx("span",{title:"Press Enter to open",style:{flexShrink:0,color:"#666666",fontSize:"17px",lineHeight:1},children:q.jsx(BVo,{size:14,strokeWidth:1.8})})]},N.target.id)})]});return q.jsx("div",{"data-schematic-search":!0,onPointerDown:b=>b.stopPropagation(),onMouseDown:b=>b.stopPropagation(),onTouchStart:b=>b.stopPropagation(),onTouchEnd:b=>b.stopPropagation(),style:{position:"relative",zIndex:hQ.schematicSearch,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif'},children:s?q.jsxs("div",{onKeyDown:B,style:{width:"min(280px, calc(100vw - 32px))",overflow:"hidden",border:"none",borderRadius:"4px",backgroundColor:"#ffffff",boxShadow:"0 2px 4px rgba(0,0,0,0.1)"},children:[q.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",height:"32px",boxSizing:"border-box",padding:"0 12px",borderBottom:E},children:[q.jsx(DFt,{size:15,strokeWidth:2}),q.jsx("input",{ref:u,value:t,"aria-label":"Search components and nets",placeholder:"Search...",onPointerUp:b=>b.currentTarget.focus(),onChange:b=>e(b.target.value),style:{minWidth:0,flex:1,border:"none",outline:"none",fontSize:"13px",color:"#222222",background:"transparent"}}),t&&o.length>0?q.jsx("span",{style:{flexShrink:0,color:"#888888",fontSize:"12px",whiteSpace:"nowrap"},children:y}):q.jsx("kbd",{style:{flexShrink:0,padding:"2px 5px",border:"1px solid #dddddd",borderRadius:"4px",backgroundColor:"#f7f7f7",color:"#777777",fontFamily:"inherit",fontSize:"10px",lineHeight:1.2},children:d}),s&&q.jsx("button",{type:"button","aria-label":"Clear search",onPointerUp:b=>{b.button===0&&_()},onClick:b=>{b.detail===0&&_()},style:{border:"none",background:"transparent",color:"#777777",cursor:"pointer",width:"20px",height:"20px",display:"grid",placeItems:"center",padding:0,lineHeight:1},children:q.jsx(yVo,{size:16,strokeWidth:2})})]}),t&&q.jsx("div",{ref:h,style:{maxHeight:"240px",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",scrollBehavior:"smooth",touchAction:"pan-y",WebkitOverflowScrolling:"touch"},onWheel:b=>b.stopPropagation(),onTouchMove:b=>b.stopPropagation(),children:o.length===0?q.jsx("div",{style:{padding:"12px",color:"#777777",fontSize:"13px"},children:"No matching components or nets"}):q.jsxs(q.Fragment,{children:[Q("components",p),Q("nets",I)]})})]}):q.jsx("button",{type:"button",title:"Search schematic","aria-label":"Search schematic",onPointerDown:b=>{b.stopPropagation(),b.pointerType!=="mouse"&&m(!1)},onPointerUp:b=>{b.pointerType==="mouse"&&b.button===0&&m(!0)},onClick:b=>{b.detail===0&&m(!0)},style:{width:"32px",height:"32px",display:"grid",placeItems:"center",padding:0,border:"none",borderRadius:"4px",backgroundColor:"#ffffff",color:"#000000",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)"},children:q.jsx(DFt,{size:16,strokeWidth:2})})})},I7e='system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',DVo={backgroundColor:"#ffffff",color:"#111111",borderRadius:8,boxShadow:"0 6px 24px rgba(0,0,0,0.12), 0 1px 3px rgba(0,0,0,0.08)",border:"1px solid #e5e7eb",padding:4,minWidth:200,maxWidth:320,maxHeight:320,overflowY:"auto",fontSize:13,fontFamily:I7e,outline:"none",zIndex:hQ.viewMenu},PVo={display:"flex",alignItems:"center",gap:8,padding:"7px 10px 7px 8px",borderRadius:6,cursor:"pointer",outline:"none",userSelect:"none",color:"#111111",fontSize:13,fontFamily:I7e},vVo={width:16,height:16,flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center",color:"#111111"},PFt={overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},MVo=`
5618
5618
  .sv-sheet-item[data-highlighted], .sv-sheet-item:hover { background-color: #f1f3f5; }
5619
5619
  .sv-sheet-chevron { transition: transform 0.2s ease; }
5620
5620
  [data-state="open"] > .sv-sheet-chevron { transform: rotate(180deg); }
5621
- `,wVo=()=>q.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:q.jsx("path",{d:"M20 6 9 17l-5-5"})}),NVo=({className:t})=>q.jsx("svg",{className:t,width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.6,flexShrink:0},"aria-hidden":"true",children:q.jsx("path",{d:"m6 9 6 6 6-6"})}),RVo=({sheets:t,selectedSheetId:e,onSelectSheet:n})=>{const[o,i]=Z.useState(!1);if(t.length<=1)return null;const s=t.find(a=>a.schematic_sheet_id===e)?.name??"Select sheet";return q.jsxs(q.Fragment,{children:[q.jsx("style",{children:MVo}),q.jsxs(Dae,{open:o,onOpenChange:i,modal:!1,children:[q.jsx(Pae,{asChild:!0,children:q.jsxs("button",{type:"button",title:s,onPointerDown:a=>a.stopPropagation(),style:{display:"flex",alignItems:"center",gap:"6px",maxWidth:"220px",padding:"8px 12px",backgroundColor:"#ffffff",color:"#000000",border:"none",outline:"none",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",fontSize:"13px",fontFamily:I7e},children:[q.jsx("span",{style:{color:"#888888",flexShrink:0},children:"Sheet:"}),q.jsx("span",{style:{...PFt,minWidth:0},children:s}),q.jsx(NVo,{className:"sv-sheet-chevron"})]})}),q.jsx(Sz,{children:q.jsx(bz,{style:DVo,side:"bottom",align:"start",sideOffset:8,collisionPadding:10,children:t.map(a=>{const A=a.schematic_sheet_id===e;return q.jsxs(b8,{className:"sv-sheet-item",style:PVo,title:a.name,onSelect:c=>c.preventDefault(),onPointerUp:()=>{n(a.schematic_sheet_id),i(!1)},children:[q.jsx("span",{style:vVo,children:A&&q.jsx(wVo,{})}),q.jsx("span",{style:{...PFt,minWidth:0},children:a.name})]},a.schematic_sheet_id)})})})]})]})},TVo={version:"2.0.86"},f7e='system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',kVo={backgroundColor:"#262626",color:"#fafafa",borderRadius:6,boxShadow:"0px 12px 48px -12px rgba(0, 0, 0, 0.5), 0px 8px 24px -8px rgba(0, 0, 0, 0.3)",border:"1px solid #333333",padding:4,minWidth:208,fontSize:14,fontWeight:400,fontFamily:f7e,outline:"none",zIndex:hQ.contextMenu},C7e={display:"flex",alignItems:"center",gap:8,padding:"6px 8px",borderRadius:6,cursor:"default",outline:"none",userSelect:"none",color:"#fafafa",fontSize:14,fontWeight:400,fontFamily:f7e},y7e={width:16,height:16,flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center",color:"#fafafa"},FVo={height:1,backgroundColor:"#ffffff1a",margin:"4px 0"},LVo=`
5621
+ `,wVo=()=>q.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:q.jsx("path",{d:"M20 6 9 17l-5-5"})}),NVo=({className:t})=>q.jsx("svg",{className:t,width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.6,flexShrink:0},"aria-hidden":"true",children:q.jsx("path",{d:"m6 9 6 6 6-6"})}),RVo=({sheets:t,selectedSheetId:e,onSelectSheet:n})=>{const[o,i]=Z.useState(!1);if(t.length<=1)return null;const s=t.find(a=>a.schematic_sheet_id===e)?.name??"Select sheet";return q.jsxs(q.Fragment,{children:[q.jsx("style",{children:MVo}),q.jsxs(Dae,{open:o,onOpenChange:i,modal:!1,children:[q.jsx(Pae,{asChild:!0,children:q.jsxs("button",{type:"button",title:s,onPointerDown:a=>a.stopPropagation(),style:{display:"flex",alignItems:"center",gap:"6px",maxWidth:"220px",padding:"8px 12px",backgroundColor:"#ffffff",color:"#000000",border:"none",outline:"none",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",fontSize:"13px",fontFamily:I7e},children:[q.jsx("span",{style:{color:"#888888",flexShrink:0},children:"Sheet:"}),q.jsx("span",{style:{...PFt,minWidth:0},children:s}),q.jsx(NVo,{className:"sv-sheet-chevron"})]})}),q.jsx(Sz,{children:q.jsx(bz,{style:DVo,side:"bottom",align:"start",sideOffset:8,collisionPadding:10,children:t.map(a=>{const A=a.schematic_sheet_id===e;return q.jsxs(b8,{className:"sv-sheet-item",style:PVo,title:a.name,onSelect:c=>c.preventDefault(),onPointerUp:()=>{n(a.schematic_sheet_id),i(!1)},children:[q.jsx("span",{style:vVo,children:A&&q.jsx(wVo,{})}),q.jsx("span",{style:{...PFt,minWidth:0},children:a.name})]},a.schematic_sheet_id)})})})]})]})},TVo={version:"2.0.87"},f7e='system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',kVo={backgroundColor:"#262626",color:"#fafafa",borderRadius:6,boxShadow:"0px 12px 48px -12px rgba(0, 0, 0, 0.5), 0px 8px 24px -8px rgba(0, 0, 0, 0.3)",border:"1px solid #333333",padding:4,minWidth:208,fontSize:14,fontWeight:400,fontFamily:f7e,outline:"none",zIndex:hQ.contextMenu},C7e={display:"flex",alignItems:"center",gap:8,padding:"6px 8px",borderRadius:6,cursor:"default",outline:"none",userSelect:"none",color:"#fafafa",fontSize:14,fontWeight:400,fontFamily:f7e},y7e={width:16,height:16,flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center",color:"#fafafa"},FVo={height:1,backgroundColor:"#ffffff1a",margin:"4px 0"},LVo=`
5622
5622
  .sv-vm-item[data-highlighted]:not([data-disabled]),
5623
5623
  .sv-vm-item:hover:not([data-disabled]) { background-color: #404040; }
5624
5624
  .sv-vm-item[data-disabled] { opacity: 0.45; cursor: not-allowed; }
@@ -5728,7 +5728,7 @@ test("${c} should solve problem correctly", () => {
5728
5728
  // Add more specific assertions based on expected output
5729
5729
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5730
5730
  })
5731
- `,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.constructor.name}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return q.jsxs("div",{className:`relative ${e}`,ref:i,children:[q.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&q.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},YUt=t=>t.activeSubSolver?[t,...YUt(t.activeSubSolver)]:[t],Fti=({solver:t})=>{const e=YUt(t);return q.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>q.jsxs("div",{className:"flex items-center",children:[o>0&&q.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),q.jsx(kti,{solver:n})]},n.constructor.name))})},Lti=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=Z.useReducer(_=>!_,!1),a=Z.useRef(void 0),A=()=>{!t.solved&&!t.failed&&(t.step(),e())},c=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},l=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},g=()=>{const _=t;if(_.getCurrentPhase&&!t.solved&&!t.failed){const m=_.getCurrentPhase();for(;_.getCurrentPhase()===m&&!t.solved&&!t.failed;)t.step();e()}},u=()=>{if(t.solved||t.failed||r)return;const _=window.prompt("Step until which iteration?",`${t.iterations}`);if(_===null)return;const m=Number(_);if(!Number.isFinite(m)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<m&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};Z.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),Z.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,d=h?t.getCurrentPhase():null;return q.jsxs("div",{className:"space-y-2 p-2 border-b",children:[q.jsx("div",{className:"flex items-center",children:q.jsx(Fti,{solver:t})}),q.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[q.jsx("button",{onClick:A,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),q.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),q.jsx("button",{onClick:l,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),q.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),h&&q.jsx("button",{onClick:g,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),q.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&q.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),d&&q.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",q.jsx("span",{className:"font-medium",children:d})]}),t.solved&&q.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&q.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&q.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Hti=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},Gti=(t,e)=>{const o=t.pipelineDef[e].solverName,i=Hti(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfPhase?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnPhase?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},Oti=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return q.jsx("span",{className:`font-medium ${e[t]}`,children:t})},Kti=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return q.jsxs("div",{className:"flex items-center gap-2",children:[q.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:q.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),q.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},Uti=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),Yti=({stats:t})=>{if(!t||Object.keys(t).length===0)return q.jsx("span",{children:"-"});const e=Object.entries(t),n=Uti(t);return q.jsxs("details",{className:"cursor-pointer",children:[q.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),q.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>q.jsxs("div",{children:[o,": ",String(i)]},o))})]})},tRe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(tRe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=tRe(o));return e},zti=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=tRe(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},Vti=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,A)=>Gti(t,A)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):zti(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return q.jsxs("div",{className:"border-t border-gray-200",children:[q.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:q.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),q.jsx("div",{className:"overflow-x-auto",children:q.jsxs("table",{className:"w-full text-sm",children:[q.jsx("thead",{children:q.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),q.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",q.jsx("sub",{children:"0"})]}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),q.jsx("tbody",{children:o.map(a=>q.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[q.jsx("td",{className:"px-4 py-2",children:q.jsxs("div",{className:"flex items-center gap-2",children:[q.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),q.jsx("button",{onClick:()=>i(a.name),disabled:a.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${a.name} completes`,children:q.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:q.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),q.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),q.jsx("td",{className:"px-4 py-2",children:q.jsx(Oti,{status:a.status})}),q.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),q.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),q.jsx("td",{className:"px-4 py-2",children:q.jsx(Kti,{progress:a.progress})}),q.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),q.jsx("td",{className:"px-4 py-2 text-gray-500",children:q.jsx(Yti,{stats:a.stats})}),q.jsx("td",{className:"px-4 py-2",children:a.solverInstance?q.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[q.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:q.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),q.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},Jti=class extends $r.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function qti({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(m,p)=>{typeof m=="number"&&(m<s&&(s=m),m>A&&(A=m)),typeof p=="number"&&(p<a&&(a=p),p>c&&(c=p))};for(const m of e)l(m.x,m.y);for(const m of n){const p=m.points??[];for(const I of p)l(I.x,I.y)}for(const m of o){const p=m.x??0,I=m.y??0,f=m.width??0,C=m.height??0;l(p,I),l(p+f,I+C)}for(const m of i){const p=m.x??0,I=m.y??0,f=m.radius??1;l(p-f,I-f),l(p+f,I+f)}for(const m of r)l(m.x,m.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),_=Math.max(1,c-a+2*g);return q.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${_}`,role:"img","aria-label":"Graphics fallback",children:[o.map((m,p)=>q.jsx("rect",{x:m.x??0,y:m.y??0,width:m.width??0,height:m.height??0,fill:"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1},`rect-${p}`)),n.map((m,p)=>q.jsx("polyline",{fill:"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1,points:(m.points??[]).map(I=>`${I.x??0},${I.y??0}`).join(" ")},`line-${p}`)),i.map((m,p)=>q.jsx("circle",{cx:m.x??0,cy:m.y??0,r:m.radius??1.5,fill:m.fillColor??"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1},`circle-${p}`)),e.map((m,p)=>q.jsx("circle",{cx:m.x??0,cy:m.y??0,r:m.radius??1.5,fill:m.color??"black"},`point-${p}`)),r.map((m,p)=>q.jsx("text",{x:m.x??0,y:m.y??0,fontSize:m.fontSize??10,fill:m.color??"black",children:m.text??""},`text-${p}`))]})}var Wti=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=Z.useReducer(l=>l+1,0),s=Z.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(l){return console.error("Visualization error:",l),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=Z.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);Z.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const l=document.createElement("script");l.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(l)}},[]);const A=t.pipelineDef!==void 0,c=l=>{const g=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&g.currentPipelineStepIndex<=g.pipelineDef.findIndex(u=>u.solverName===l);)t.step();r()}};return q.jsxs("div",{children:[q.jsx(Lti,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?q.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):q.jsx(Jti,{fallback:q.jsx(qti,{graphics:s}),children:q.jsx(Tti,{graphics:s})}),A&&q.jsx(Vti,{solver:t,onStepUntilPhase:c})]})};const jti=()=>{Z.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},Xti=1e3,fQ=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},Xti)},nRe=t=>{let e=t.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},$ti=t=>{if(Array.isArray(t.solverConstructorArgs))return t.solverConstructorArgs;const e=t.solverParams;return e!==null&&typeof e=="object"&&"input"in e?[e.input]:[e]},Hb="https://github.com/tscircuit/tscircuit-autorouter/issues/new",zUt="https://github.com/tscircuit/copper-pour-solver/issues/new",VUt="https://github.com/tscircuit/calculate-packing/issues/new",Zti="https://github.com/tscircuit/matchpack/issues/new",JUt="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",eni={PackSolver2:VUt,LayoutPipelineSolver:Zti,AutoroutingPipelineSolver:Hb,AssignableAutoroutingPipeline2:Hb,AssignableAutoroutingPipeline3:Hb,AutoroutingPipeline1_OriginalUnravel:Hb,AutoroutingPipelineSolver3_HgPortPointPathing:Hb,AutoroutingPipelineSolver4:Hb,AutoroutingPipelineSolver5:Hb,AutoroutingPipelineSolver7_MultiGraph:Hb,AutoroutingPipelineSolver8:Hb,CopperPourPipelineSolver:zUt,SchematicTracePipelineSolver:JUt},tni=t=>t.toLowerCase().includes("pack")?zOo:t.toLowerCase().includes("rout")?ZOo:FOo,qUt=t=>{const e=eni[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?Hb:n.includes("schematic")&&n.includes("trace")?JUt:n.includes("copperpour")?zUt:n.includes("pack")?VUt:null},nni=t=>`${nRe(`${t.componentName}-${t.solverName}`)}-solver-input.json`,WUt=t=>{fQ(JSON.stringify(t.solverParams,null,2),{fileName:nni(t),mimeType:"application/json"})},oni=({solverEvent:t})=>{const e=qUt(t.solverName);return q.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[q.jsxs(XA,{type:"button",variant:"outline",size:"sm",onClick:()=>WUt(t),children:[q.jsx(eae,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?q.jsx(XA,{asChild:!0,variant:"outline",size:"sm",children:q.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[q.jsx(Xse,{className:"rf-w-4 rf-h-4"}),"Report"]})}):q.jsxs(XA,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[q.jsx(Xse,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},ini=({solverEvent:t})=>{const e=qUt(t.solverName);return e?q.jsx(XA,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:q.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:q.jsx(Xse,{className:"rf-w-4 rf-h-4"})})}):q.jsx(XA,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:q.jsx(Xse,{className:"rf-w-4 rf-h-4"})})},rni=({solverEvents:t=[]})=>{const[e,n]=Z.useState(null);jti();const o=Z.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=Z.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=Z.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=YSe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(YSe).join(", ")}`,classFound:!1};try{return{instance:new a(...$ti(r)),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?q.jsx("div",{className:"rf-p-4",children:q.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:q.jsxs("div",{className:"rf-p-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),q.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):q.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[q.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[q.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const A=o.get(a),c=e===a;return q.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=tni(A.solverName);return q.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[q.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),q.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[q.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),q.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),q.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?q.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[q.jsx(oni,{solverEvent:r}),q.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:q.jsx(Pb,{fallback:q.jsx("div",{className:"rf-p-4",children:q.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),q.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:q.jsx(Wti,{solver:s.instance})})})]}):q.jsxs("div",{className:"rf-p-4",children:[q.jsxs("div",{className:"rf-mb-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),q.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&q.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:q.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),q.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[q.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[q.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),q.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[q.jsx(ini,{solverEvent:r}),q.jsx(XA,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>WUt(r),children:q.jsx(eae,{className:"rf-w-4 rf-h-4"})})]})]}),q.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:q.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):q.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:q.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},jUt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{Z.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{F9.captureException(o)}catch{}}},[t,e]),Z.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{F9.captureException(i,{error_type:o.type})}catch{}}},[n])},sni=t=>{Z.useEffect(()=>{try{YZt(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},XUt="0.0.2513",ani={version:XUt},oRe={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},iRe=new Map,SAe=t=>{const e=iRe.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},Ani=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=iRe.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return iRe.set(n.name,i),{type:"tracked",store:t,...i}},$Ut=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...A}=e;let c;try{c=(r??(oRe?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return(oRe?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:l,...g}=Ani(a,c,A);let u=!0;i.setState=(_,m,p)=>{const I=n(_,m);if(!u)return I;const f=p===void 0?{type:s||"anonymous"}:typeof p=="string"?{type:p}:p;return a===void 0?(l?.send(f,o()),I):(l?.send({...f,type:`${a}/${f.type}`},{...SAe(A.name),[a]:i.getState()}),I)};const h=(..._)=>{const m=u;u=!1,n(..._),u=m},d=t(i.setState,o,i);if(g.type==="untracked"?l?.init(d):(g.stores[g.store]=i,l?.init(Object.fromEntries(Object.entries(g.stores).map(([_,m])=>[_,_===g.store?d:m.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let _=!1;const m=i.dispatch;i.dispatch=(...p)=>{(oRe?"production":void 0)!=="production"&&p[0].type==="__setState"&&!_&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),_=!0),m(...p)}}return l.subscribe(_=>{var m;switch(_.type){case"ACTION":if(typeof _.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return rRe(_.payload,p=>{if(p.type==="__setState"){if(a===void 0){h(p.state);return}Object.keys(p.state).length!==1&&console.error(`
5731
+ `,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.constructor.name}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return q.jsxs("div",{className:`relative ${e}`,ref:i,children:[q.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&q.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},YUt=t=>t.activeSubSolver?[t,...YUt(t.activeSubSolver)]:[t],Fti=({solver:t})=>{const e=YUt(t);return q.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>q.jsxs("div",{className:"flex items-center",children:[o>0&&q.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),q.jsx(kti,{solver:n})]},n.constructor.name))})},Lti=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=Z.useReducer(_=>!_,!1),a=Z.useRef(void 0),A=()=>{!t.solved&&!t.failed&&(t.step(),e())},c=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},l=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},g=()=>{const _=t;if(_.getCurrentPhase&&!t.solved&&!t.failed){const m=_.getCurrentPhase();for(;_.getCurrentPhase()===m&&!t.solved&&!t.failed;)t.step();e()}},u=()=>{if(t.solved||t.failed||r)return;const _=window.prompt("Step until which iteration?",`${t.iterations}`);if(_===null)return;const m=Number(_);if(!Number.isFinite(m)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<m&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};Z.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),Z.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,d=h?t.getCurrentPhase():null;return q.jsxs("div",{className:"space-y-2 p-2 border-b",children:[q.jsx("div",{className:"flex items-center",children:q.jsx(Fti,{solver:t})}),q.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[q.jsx("button",{onClick:A,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),q.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),q.jsx("button",{onClick:l,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),q.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),h&&q.jsx("button",{onClick:g,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),q.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&q.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),d&&q.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",q.jsx("span",{className:"font-medium",children:d})]}),t.solved&&q.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&q.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&q.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Hti=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},Gti=(t,e)=>{const o=t.pipelineDef[e].solverName,i=Hti(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfPhase?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnPhase?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},Oti=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return q.jsx("span",{className:`font-medium ${e[t]}`,children:t})},Kti=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return q.jsxs("div",{className:"flex items-center gap-2",children:[q.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:q.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),q.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},Uti=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),Yti=({stats:t})=>{if(!t||Object.keys(t).length===0)return q.jsx("span",{children:"-"});const e=Object.entries(t),n=Uti(t);return q.jsxs("details",{className:"cursor-pointer",children:[q.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),q.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>q.jsxs("div",{children:[o,": ",String(i)]},o))})]})},tRe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(tRe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=tRe(o));return e},zti=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=tRe(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},Vti=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,A)=>Gti(t,A)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):zti(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return q.jsxs("div",{className:"border-t border-gray-200",children:[q.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:q.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),q.jsx("div",{className:"overflow-x-auto",children:q.jsxs("table",{className:"w-full text-sm",children:[q.jsx("thead",{children:q.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),q.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",q.jsx("sub",{children:"0"})]}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),q.jsx("tbody",{children:o.map(a=>q.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[q.jsx("td",{className:"px-4 py-2",children:q.jsxs("div",{className:"flex items-center gap-2",children:[q.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),q.jsx("button",{onClick:()=>i(a.name),disabled:a.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${a.name} completes`,children:q.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:q.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),q.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),q.jsx("td",{className:"px-4 py-2",children:q.jsx(Oti,{status:a.status})}),q.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),q.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),q.jsx("td",{className:"px-4 py-2",children:q.jsx(Kti,{progress:a.progress})}),q.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),q.jsx("td",{className:"px-4 py-2 text-gray-500",children:q.jsx(Yti,{stats:a.stats})}),q.jsx("td",{className:"px-4 py-2",children:a.solverInstance?q.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[q.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:q.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),q.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},Jti=class extends $r.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function qti({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(m,p)=>{typeof m=="number"&&(m<s&&(s=m),m>A&&(A=m)),typeof p=="number"&&(p<a&&(a=p),p>c&&(c=p))};for(const m of e)l(m.x,m.y);for(const m of n){const p=m.points??[];for(const I of p)l(I.x,I.y)}for(const m of o){const p=m.x??0,I=m.y??0,f=m.width??0,C=m.height??0;l(p,I),l(p+f,I+C)}for(const m of i){const p=m.x??0,I=m.y??0,f=m.radius??1;l(p-f,I-f),l(p+f,I+f)}for(const m of r)l(m.x,m.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),_=Math.max(1,c-a+2*g);return q.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${_}`,role:"img","aria-label":"Graphics fallback",children:[o.map((m,p)=>q.jsx("rect",{x:m.x??0,y:m.y??0,width:m.width??0,height:m.height??0,fill:"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1},`rect-${p}`)),n.map((m,p)=>q.jsx("polyline",{fill:"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1,points:(m.points??[]).map(I=>`${I.x??0},${I.y??0}`).join(" ")},`line-${p}`)),i.map((m,p)=>q.jsx("circle",{cx:m.x??0,cy:m.y??0,r:m.radius??1.5,fill:m.fillColor??"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1},`circle-${p}`)),e.map((m,p)=>q.jsx("circle",{cx:m.x??0,cy:m.y??0,r:m.radius??1.5,fill:m.color??"black"},`point-${p}`)),r.map((m,p)=>q.jsx("text",{x:m.x??0,y:m.y??0,fontSize:m.fontSize??10,fill:m.color??"black",children:m.text??""},`text-${p}`))]})}var Wti=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=Z.useReducer(l=>l+1,0),s=Z.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(l){return console.error("Visualization error:",l),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=Z.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);Z.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const l=document.createElement("script");l.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(l)}},[]);const A=t.pipelineDef!==void 0,c=l=>{const g=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&g.currentPipelineStepIndex<=g.pipelineDef.findIndex(u=>u.solverName===l);)t.step();r()}};return q.jsxs("div",{children:[q.jsx(Lti,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?q.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):q.jsx(Jti,{fallback:q.jsx(qti,{graphics:s}),children:q.jsx(Tti,{graphics:s})}),A&&q.jsx(Vti,{solver:t,onStepUntilPhase:c})]})};const jti=()=>{Z.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},Xti=1e3,fQ=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},Xti)},nRe=t=>{let e=t.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},$ti=t=>{if(Array.isArray(t.solverConstructorArgs))return t.solverConstructorArgs;const e=t.solverParams;return e!==null&&typeof e=="object"&&"input"in e?[e.input]:[e]},Hb="https://github.com/tscircuit/tscircuit-autorouter/issues/new",zUt="https://github.com/tscircuit/copper-pour-solver/issues/new",VUt="https://github.com/tscircuit/calculate-packing/issues/new",Zti="https://github.com/tscircuit/matchpack/issues/new",JUt="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",eni={PackSolver2:VUt,LayoutPipelineSolver:Zti,AutoroutingPipelineSolver:Hb,AssignableAutoroutingPipeline2:Hb,AssignableAutoroutingPipeline3:Hb,AutoroutingPipeline1_OriginalUnravel:Hb,AutoroutingPipelineSolver3_HgPortPointPathing:Hb,AutoroutingPipelineSolver4:Hb,AutoroutingPipelineSolver5:Hb,AutoroutingPipelineSolver7_MultiGraph:Hb,AutoroutingPipelineSolver8:Hb,CopperPourPipelineSolver:zUt,SchematicTracePipelineSolver:JUt},tni=t=>t.toLowerCase().includes("pack")?zOo:t.toLowerCase().includes("rout")?ZOo:FOo,qUt=t=>{const e=eni[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?Hb:n.includes("schematic")&&n.includes("trace")?JUt:n.includes("copperpour")?zUt:n.includes("pack")?VUt:null},nni=t=>`${nRe(`${t.componentName}-${t.solverName}`)}-solver-input.json`,WUt=t=>{fQ(JSON.stringify(t.solverParams,null,2),{fileName:nni(t),mimeType:"application/json"})},oni=({solverEvent:t})=>{const e=qUt(t.solverName);return q.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[q.jsxs(XA,{type:"button",variant:"outline",size:"sm",onClick:()=>WUt(t),children:[q.jsx(eae,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?q.jsx(XA,{asChild:!0,variant:"outline",size:"sm",children:q.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[q.jsx(Xse,{className:"rf-w-4 rf-h-4"}),"Report"]})}):q.jsxs(XA,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[q.jsx(Xse,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},ini=({solverEvent:t})=>{const e=qUt(t.solverName);return e?q.jsx(XA,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:q.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:q.jsx(Xse,{className:"rf-w-4 rf-h-4"})})}):q.jsx(XA,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:q.jsx(Xse,{className:"rf-w-4 rf-h-4"})})},rni=({solverEvents:t=[]})=>{const[e,n]=Z.useState(null);jti();const o=Z.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=Z.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=Z.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=YSe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(YSe).join(", ")}`,classFound:!1};try{return{instance:new a(...$ti(r)),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?q.jsx("div",{className:"rf-p-4",children:q.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:q.jsxs("div",{className:"rf-p-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),q.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):q.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[q.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[q.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const A=o.get(a),c=e===a;return q.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=tni(A.solverName);return q.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[q.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),q.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[q.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),q.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),q.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?q.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[q.jsx(oni,{solverEvent:r}),q.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:q.jsx(Pb,{fallback:q.jsx("div",{className:"rf-p-4",children:q.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),q.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:q.jsx(Wti,{solver:s.instance})})})]}):q.jsxs("div",{className:"rf-p-4",children:[q.jsxs("div",{className:"rf-mb-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),q.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&q.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:q.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),q.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[q.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[q.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),q.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[q.jsx(ini,{solverEvent:r}),q.jsx(XA,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>WUt(r),children:q.jsx(eae,{className:"rf-w-4 rf-h-4"})})]})]}),q.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:q.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):q.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:q.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},jUt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{Z.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{F9.captureException(o)}catch{}}},[t,e]),Z.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{F9.captureException(i,{error_type:o.type})}catch{}}},[n])},sni=t=>{Z.useEffect(()=>{try{YZt(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},XUt="0.0.2515",ani={version:XUt},oRe={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},iRe=new Map,SAe=t=>{const e=iRe.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},Ani=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=iRe.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return iRe.set(n.name,i),{type:"tracked",store:t,...i}},$Ut=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...A}=e;let c;try{c=(r??(oRe?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return(oRe?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:l,...g}=Ani(a,c,A);let u=!0;i.setState=(_,m,p)=>{const I=n(_,m);if(!u)return I;const f=p===void 0?{type:s||"anonymous"}:typeof p=="string"?{type:p}:p;return a===void 0?(l?.send(f,o()),I):(l?.send({...f,type:`${a}/${f.type}`},{...SAe(A.name),[a]:i.getState()}),I)};const h=(..._)=>{const m=u;u=!1,n(..._),u=m},d=t(i.setState,o,i);if(g.type==="untracked"?l?.init(d):(g.stores[g.store]=i,l?.init(Object.fromEntries(Object.entries(g.stores).map(([_,m])=>[_,_===g.store?d:m.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let _=!1;const m=i.dispatch;i.dispatch=(...p)=>{(oRe?"production":void 0)!=="production"&&p[0].type==="__setState"&&!_&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),_=!0),m(...p)}}return l.subscribe(_=>{var m;switch(_.type){case"ACTION":if(typeof _.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return rRe(_.payload,p=>{if(p.type==="__setState"){if(a===void 0){h(p.state);return}Object.keys(p.state).length!==1&&console.error(`
5732
5732
  [zustand devtools middleware] Unsupported __setState action format.
5733
5733
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5734
5734
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }