@tscircuit/runframe 0.0.2985 → 0.0.2987
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.
|
@@ -5606,11 +5606,11 @@ svg { font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif; }
|
|
|
5606
5606
|
.simulation-line { fill: none; stroke-width: 2.5; }
|
|
5607
5607
|
.simulation-point { stroke-width: 0; }
|
|
5608
5608
|
.chart-title { fill: rgba(0, 0, 0, 0.85); font-size: 18px; font-weight: 600; }
|
|
5609
|
-
`;return gE("style",{},[xR(g)])}function eNI(g,A){const I=g[A];if(typeof I=="string")return I}function IaB(g,A,I,e){const B=[4,8],o=B.map(s=>rB(s)).join(" "),Q=B.reduce((s,r)=>s+r,0)/3,i=[];g.forEach((s,r)=>{if(s.points.length===0)return;const a=[];s.points.forEach((d,y)=>{const w=rB(I(d.timeMs)),u=rB(e(d.displayValue));a.push(`${y===0?"M":"L"} ${w} ${u}`)});const c={class:"simulation-line",d:a.join(" "),stroke:s.color,"clip-path":`url(#${A})`,[zRI(s.graph)]:xeg(s.graph)};s.graph.source_component_id&&(c["data-source-component-id"]=s.graph.source_component_id);const h=eNI(s.graph,"source_probe_id");h&&(c["data-source-probe-id"]=h);const l=eNI(s.graph,"source_probe_name");l&&(c["data-source-probe-name"]=l),s.graph.subcircuit_connectivity_map_key&&(c["data-subcircuit-connectivity-map-key"]=s.graph.subcircuit_connectivity_map_key);const D=s.points.map(d=>{const y=rB(I(d.timeMs)),w=rB(e(d.displayValue));return gE("circle",{class:"simulation-point",cx:y,cy:w,r:"2.5",fill:s.color,"clip-path":`url(#${A})`})});i.push({entry:s,graphIndex:r,pathAttributes:c,pointElements:D})});const E=[];for(let s=0;s<3;s++)for(const r of i){const a=(r.graphIndex+s)%3,c=rB(a*Q);E.push(gE("path",{...r.pathAttributes,"stroke-dasharray":o,"stroke-dashoffset":c}))}const n=i.flatMap(s=>s.pointElements);return gE("g",{class:"data-series"},[...E,...n])}function eaB(g,A){return g?.name?gE("text",{class:"chart-title",x:rB(A/2),y:rB(Fl.top-40),"text-anchor":"middle"},[xR(g.name)]):null}var tNI=16;function taB(g,A,I,e){const t=e.map((B,o)=>gE("tspan",{x:"20",dy:o===0?"0":String(tNI)},[xR(B)]));return gE("g",{class:"legend-item",transform:`translate(${rB(A)} ${rB(I)})`},[gE("line",{class:"legend-line",x1:"0",y1:"0",x2:"16",y2:"0",stroke:g.color}),gE("text",{class:"legend-label",x:"20",y:"0","dominant-baseline":"middle"},t)])}var BaB=15;function oaB(g){const A=g.split("_");if(A.length<=1)return[g];const I=[];let e=A[0]??"";for(let t=1;t<A.length;t++){const B=A[t]??"",o=`${e}_${B}`;o.length>BaB?(I.push(e),e=B):e=o}return e&&I.push(e),I}var CaB=24;function QaB(g,A){let I=Fl.top;const e=g.map(t=>{const B=A-Fl.right+10,o=oaB(t.label),C=taB(t,B,I,o),Q=o.length*tNI;return I+=Math.max(Q,CaB),C});return gE("g",{class:"legend"},e)}var f5=118,DuA=94,aZ=18;function BNI(g,A){const I=Math.floor((A+aZ)/(f5+aZ)),e=Math.max(1,Math.min(I,g)),t=Math.max(1,Math.ceil(g/e)),B=e*f5+(e-1)*aZ,o=t*DuA+(t-1)*aZ;return{columns:e,rows:t,x:Math.max(0,(A-B)/2),height:o}}var duA=20,Jeg=8,iaB=14;function EaB(g,A,I){const e=BNI(g.length,A),t=[];for(const[B,o]of g.entries()){const C=B%e.columns,Q=Math.floor(B/e.columns);t.push(naB(o,B,e.x+C*(f5+aZ),I+Neg+Q*(DuA+aZ)))}return gE("g",{class:"scope-legend"},t)}function naB(g,A,I,e){const t=g.scopeTraceDisplay,B=lk(g.graph)?"A":"V",o=t&&heA(t)?Ueg(t.valuePerDiv,B):`1 ${B}`,C=Ueg(t?.center??0,B),Q=qsB(t?.offsetDivs??0),i=`Ch${A+1}`,n=[g.label===i?void 0:g.label,`${o}/div`,Q,C].filter(r=>!!r),s=n.length>1?(DuA-duA-Jeg*2-iaB)/(n.length-1):0;return gE("g",{class:"scope-channel",transform:`translate(${rB(I)} ${rB(e)})`,[zRI(g.graph)]:xeg(g.graph)},[gE("rect",{class:"scope-channel-card",x:"0",y:"0",width:rB(f5),height:rB(DuA),rx:"6",ry:"6"}),gE("rect",{x:"0",y:"0",width:rB(f5),height:rB(duA),rx:"6",ry:"6",fill:g.color}),gE("rect",{x:"0",y:rB(duA-6),width:rB(f5),height:"6",fill:g.color}),gE("text",{class:"scope-channel-header-text",x:rB(f5/2),y:"14","text-anchor":"middle"},[xR(i)]),...n.map((r,a)=>gE("text",{class:"scope-channel-detail",x:rB(Jeg),y:rB(duA+Jeg+a*s),"dominant-baseline":"hanging"},[xR(r)]))])}function saB(g){const A=Math.ceil(g/2),I=Math.floor(g/2);return{left:oNI(A),right:oNI(I)}}function oNI(g){if(g<=1)return 0;const A=10+(g-1)*Feg+6+_sB+bsB;return Math.max(0,A-Fl.left)}function CNI(g){return g.type==="simulation_transient_voltage_graph"||g.type==="simulation_transient_current_graph"||g.type==="simulation_dc_operating_point_voltage"||g.type==="simulation_dc_operating_point_current"||g.type==="simulation_dc_sweep_voltage_graph"||g.type==="simulation_dc_sweep_current_graph"||g.type==="simulation_ac_sweep_voltage_graph"||g.type==="simulation_ac_sweep_current_graph"}function QNI(g){return g?.type==="simulation_experiment"}function aaB(g){return g?.type==="simulation_voltage_probe"}function raB(g){return g?.type==="simulation_current_probe"}function caB(g){return g?.type==="simulation_oscilloscope_trace"}function haB(g,A){const I=DaB(g),e=XRI(g),t=Math.min(I.length,e.length),B=[],o=laB(A);for(let C=0;C<t;C++){const Q=Number(I[C]??Number.NaN),i=Number(e[C]??Number.NaN);!Number.isFinite(Q)||!Number.isFinite(i)||B.push({timeMs:Q,rawValue:i,displayValue:o(i)})}return B}function laB(g){if(!heA(g))return t=>t;const A=g.center??0,I=g.offsetDivs??0,e=g.valuePerDiv;return t=>I+(t-A)/e}function DaB(g){const A=XRI(g);if(Array.isArray(g.timestamps_ms)&&g.timestamps_ms.length===A.length)return g.timestamps_ms.map(B=>Number(B));const I=A.length;if(I===0)return[];const e=[];for(let B=0;B<I;B++)e.push(g.start_time_ms+g.time_per_step*B);const t=e.length>0?e[e.length-1]:void 0;return t!==void 0&&Number.isFinite(g.end_time_ms)&&Number.isFinite(t)&&Math.abs(t-g.end_time_ms)>g.time_per_step/2&&e.push(g.end_time_ms),e}function yuA(g,A){const I=g[A];if(typeof I=="string")return I}function daB(g,A,I,e){const t=lk(g)?"I":"V";if(I?.displayName)return I.displayName;if(g.simulation_parameter_sweep_coordinate&&g.name)return g.name;if(A?.name)return`${t}(${A.name})`;const B=yuA(g,"source_probe_name");if(B)return`${t}(${B})`;if(g.source_component_id){const o=e.get(g.source_component_id);if(o)return`${t}(${o})`}return g.name?g.name:g.source_component_id?`Probe ${g.source_component_id}`:xeg(g)}function yaB(g,A,I,e,t,B){if(lk(g)){const Q=e.get(g.simulation_transient_current_graph_id);if(Q)return Q;const i=yuA(g,"source_probe_id")??(A?.type==="simulation_current_probe"?A.simulation_current_probe_id:void 0);return i?B.get(i):void 0}const o=I.get(g.simulation_transient_voltage_graph_id);if(o)return o;const C=yuA(g,"source_probe_id")??(A?.type==="simulation_voltage_probe"?A.simulation_voltage_probe_id:void 0);return C?t.get(C):void 0}function waB(g,A,I,e,t){const B=yuA(g,"source_probe_id");if(B){const o=lk(g)?I.get(B):A.get(B);if(o)return o}if(g.source_component_id)return lk(g)?t.get(g.source_component_id):e.get(g.source_component_id)}function uaB(g,A){if(A)return{displayName:A.display_name,color:A.color,center:A.display_center_value,offsetDivs:A.display_center_offset_divs,valuePerDiv:lk(g)?A.amps_per_div:A.volts_per_div}}function GaB(g,A){const I=Array.isArray(kh.simulation_palette)?kh.simulation_palette:Array.isArray(kh.palette)?kh.palette:[],e=A.filter(aaB),t=A.filter(raB),B=A.filter(caB),o=new Map,C=new Map,Q=new Map,i=new Map,E=new Map,n=new Map,s=new Map,r=new Map,a=new Map,c=new Map,h=new Map,l=new Map;for(const D of B)D.simulation_transient_voltage_graph_id&&a.set(D.simulation_transient_voltage_graph_id,D),D.simulation_transient_current_graph_id&&c.set(D.simulation_transient_current_graph_id,D),D.simulation_voltage_probe_id&&h.set(D.simulation_voltage_probe_id,D),D.simulation_current_probe_id&&l.set(D.simulation_current_probe_id,D);for(const D of e)E.set(D.simulation_voltage_probe_id,D),D.name&&D.source_component_id&&o.set(D.source_component_id,D.name),D.color&&D.source_component_id&&C.set(D.source_component_id,D.color),D.source_component_id&&s.set(D.source_component_id,D);for(const D of t)n.set(D.simulation_current_probe_id,D),D.name&&D.source_component_id&&Q.set(D.source_component_id,D.name),D.color&&D.source_component_id&&i.set(D.source_component_id,D.color),D.source_component_id&&r.set(D.source_component_id,D);return g.map((D,d)=>{const y=waB(D,E,n,s,r),w=yaB(D,y,a,c,h,l),u=uaB(D,w),G=haB(D,u),m=maB(I,d),p=paB(D,y,lk(D)?i:C),k=D.color??u?.color??p??m,S=daB(D,y,u,lk(D)?Q:o);return{graph:D,points:G,color:k,label:S,scopeTraceDisplay:u,usesScopeTraceDisplay:heA(u)}}).filter(D=>D.points.length>0)}function maB(g,A){return g.length===0?jRI:g[A%g.length]??jRI}function paB(g,A,I){if(A?.color)return A.color;if(g.source_component_id)return I.get(g.source_component_id)}function iNI({circuitJson:g,simulation_experiment_id:A,simulation_transient_current_graph_ids:I,simulation_transient_voltage_graph_ids:e,simulation_result_ids:t,ac_sweep_view:B="magnitude",width:o=LsB,height:C=YsB,includeVersion:Q}){const i=e?new Set(e):null,E=I?new Set(I):null,n=!!(i||E),s=t?new Set(t):null,r=g.find(O=>QNI(O)&&O.simulation_experiment_id===A),a=g.filter(O=>CNI(O)&&O.simulation_experiment_id===A&&(!s||s.has(VRI(O)))&&(!n||O.type==="simulation_transient_voltage_graph"&&(i?.has(O.simulation_transient_voltage_graph_id)??!1)||O.type==="simulation_transient_current_graph"&&(E?.has(O.simulation_transient_current_graph_id)??!1))),c=PsB({results:a,acSweepView:B,experiment:r}),h=c.graphs;if(h.length===0)throw new Error(`No simulation analysis results found for simulation_experiment_id "${A}"`);const l=GaB(h,g),D=l.flatMap(O=>O.points);if(D.length===0)throw new Error(`Simulation results for simulation_experiment_id "${A}" do not contain any datapoints`);const d=D.map(O=>O.timeMs);let y;c.usesLogarithmicXValues?y=kaB(d):c.xAxisTitle==="Time (ms)"?y=WsB({values:d,graphs:h,experiment:r}):y=huA(d);const w=huA(D.map(O=>O.displayValue),!0),u=l.some(O=>O.usesScopeTraceDisplay),G=u?saB(l.length):{left:0,right:0},m=o+G.left+G.right,p=u?BNI(l.length,m):null,k=p?C+Neg+p.height+Neg:C,S=Math.max(1,o-Fl.left-Fl.right),R=Math.max(1,C-Fl.top-Fl.bottom),x=Fl.left+G.left,N=INI(y.domainMin,y.domainMax,x,x+S),J=INI(w.domainMin,w.domainMax,Fl.top+R,Fl.top),L=vsB(A),b=BuA(g),H=ouA,q=eaB(r,m),j=[gaB(),zsB(m,k),XsB(L,x,S,R),AaB(x,S,R),$sB({timeAxis:y,valueAxis:w,scaleX:N,scaleY:J,plotLeft:x,plotWidth:S,plotHeight:R}),IaB(l,L,N,J),OsB({timeAxis:y,valueAxis:w,graphs:l,scaleX:N,scaleY:J,plotLeft:x,plotWidth:S,plotHeight:R,yAxisTitle:c.yAxisTitle??HsB(l),xAxisTitle:c.xAxisTitle,usesScopeTraceDisplay:u}),u?EaB(l,m,C):QaB(l,m),...q?[q]:[]],Z=gE("svg",{xmlns:"http://www.w3.org/2000/svg",width:m.toString(),height:k.toString(),style:`background-color: ${kh.schematic.background}`,viewBox:`0 0 ${rB(m)} ${rB(k)}`,"data-simulation-experiment-id":A,...r?.name&&{"data-simulation-experiment-name":r.name},...b&&{"data-software-used-string":b},...Q&&{"data-circuit-to-svg-version":H}},j);return XwA(Z)}var kaB=g=>{const A=huA(g);return{...A,tickLabelOverrides:new Map(A.ticks.map(I=>[I,rB(10**I)]))}},MaB=1200,SaB=1200,ENI=.55;function faB({circuitJson:g,simulation_experiment_id:A,simulation_transient_current_graph_ids:I,simulation_transient_voltage_graph_ids:e,simulation_result_ids:t,ac_sweep_view:B,width:o=MaB,height:C=SaB,schematicHeightRatio:Q=ENI,schematicOptions:i,includeVersion:E,graphAboveSchematic:n=!1,showErrorsInTextOverlay:s}){const r=g.filter(J=>!QNI(J)&&!CNI(J)),a=NaB(Q),c=Math.max(1,C*a),h=Math.max(1,C-c),l=c+h,D=l===0?1:C/l,d=c*D,y=h*D,w=ZRI(r,{...i,width:o,height:d,includeVersion:!1,showErrorsInTextOverlay:s}),u=iNI({circuitJson:g,simulation_experiment_id:A,simulation_transient_current_graph_ids:I,simulation_transient_voltage_graph_ids:e,simulation_result_ids:t,ac_sweep_view:B,width:o,height:y,includeVersion:!1}),G=pRI(LW(w)),m=pRI(LW(u)),p=RaB(m)??{width:o,height:y},k=p.width>0?o*(p.height/p.width):y,S=d+k,R=[];n?(R.push(iuA(m,0,0,o,k)),R.push(iuA(G,0,k,o,d))):(R.push(iuA(G,0,0,o,d)),R.push(iuA(m,0,d,o,k)));const x=BuA(r),N={name:"svg",type:"element",value:"",attributes:{xmlns:"http://www.w3.org/2000/svg",width:b2(o),height:b2(S),viewBox:`0 0 ${b2(o)} ${b2(S)}`,"data-simulation-experiment-id":A,...x&&{"data-software-used-string":x},...E&&{"data-circuit-to-svg-version":ouA}},children:R};return XwA(N)}function RaB(g){const A=g.attributes?.viewBox;if(typeof A!="string")return null;const I=A.trim().split(/[\s,]+/).map(B=>Number.parseFloat(B));if(I.length!==4)return null;const e=I.at(2),t=I.at(3);return!Number.isFinite(e)||!Number.isFinite(t)||e===void 0||t===void 0||e<=0||t<=0?null:{width:e,height:t}}function NaB(g){return Number.isFinite(g)?g<=0?0:g>=1?1:g:ENI}var nNI=({initialTransform:g,initialTouch1:A,initialTouch2:I,finalTouch1:e,finalTouch2:t})=>{if(!e||!t)return g;const B={x:(A.x+I.x)/2,y:(A.y+I.y)/2},o={x:(e.x+t.x)/2,y:(e.y+t.y)/2},C=Math.hypot(I.x-A.x,I.y-A.y),Q=Math.hypot(t.x-e.x,t.y-e.y),i=C===0?1:Q/C,E=o.x-B.x,n=o.y-B.y;return Sc(Bi(E,n),Bi(B.x,B.y),Lu(i,i),Bi(-B.x,-B.y),g)},leA=(g={})=>{const A=gA.useRef(null),[I,e]=gA.useState(0),t=g.canvasElm??A.current,[B,o]=gA.useState(g.initialTransform??R4()),[C,Q]=gA.useState(0),[i,E]=gA.useReducer(d=>d+1,0),n=gA.useCallback(d=>{g.onSetTransform&&g.onSetTransform(d),g.transform||o(d)},[g.onSetTransform,o]),s=gA.useCallback(d=>{n(d),E()},[n]),r=g.transform??B,a=gA.useCallback(()=>{e(Date.now())},[]),c=gA.useRef("none"),h=gA.useRef(null),l=gA.useRef(null);gA.useEffect(()=>{const d=g.canvasElm??A.current;if(d&&!t){Q(C+1);return}if(!d){const b=setTimeout(()=>{Q(C+1)},100);return()=>clearTimeout(b)}let y=g.transform??B,w={x:0,y:0},u={x:0,y:0},G=!1;const m=b=>({x:b.pageX-d.getBoundingClientRect().left-window.scrollX,y:b.pageY-d.getBoundingClientRect().top-window.scrollY});function p(b){g.enabled!==!1&&(g.shouldDrag&&!g.shouldDrag(b)||(w=m(b),!(Date.now()-I<100)&&(G=!0,b.preventDefault())))}function k(b){if(!G||g.enabled===!1||g.shouldDrag&&!g.shouldDrag(b))return;u=m(b);const H=Sc(Bi(u.x-w.x,u.y-w.y),y);n(H),y=H,G=!1}function S(b){if(m(b),!G||g.enabled===!1||g.shouldDrag&&!g.shouldDrag(b))return;u=m(b);const H=Sc(Bi(u.x-w.x,u.y-w.y),y);n(H)}function R(b){if(g.enabled===!1||g.shouldDrag&&!g.shouldDrag(b))return;const H=m(b),q=Sc(Bi(H.x,H.y),Lu(1-b.deltaY/1e3,1-b.deltaY/1e3),Bi(-H.x,-H.y),y);n(q),y=q,b.preventDefault()}function x(b){if(!G||g.shouldDrag&&!g.shouldDrag(b))return;if(d){const q=d.getBoundingClientRect();if(b.clientX>=q.left+10&&b.clientX<=q.right-10&&b.clientY>=q.top+10&&b.clientY<=q.bottom-10)return}G=!1,u=m(b);const H=Sc(Bi(u.x-w.x,u.y-w.y),y);n(H),y=H}function N(b){if(b.preventDefault(),g.enabled!==!1){if(b.touches.length===1){c.current="drag";const H=b.touches[0];h.current={initialTransform:y,initialTouch:{x:H.clientX,y:H.clientY}}}else if(b.touches.length===2){c.current="pinch";const H=b.touches[0],q=b.touches[1];l.current={initialTransform:y,initialTouch1:{x:H.clientX,y:H.clientY},initialTouch2:{x:q.clientX,y:q.clientY},finalTouch1:null,finalTouch2:null}}}}function J(b){if(b.preventDefault(),g.enabled!==!1){if(c.current==="drag"&&b.touches.length===1&&h.current){const H=b.touches[0],q={x:H.clientX,y:H.clientY},j=q.x-h.current.initialTouch.x,Z=q.y-h.current.initialTouch.y,O=Sc(Bi(j,Z),h.current.initialTransform);n(O)}else if(c.current==="pinch"&&b.touches.length===2&&l.current){const H=b.touches[0],q=b.touches[1];l.current.finalTouch1={x:H.clientX,y:H.clientY},l.current.finalTouch2={x:q.clientX,y:q.clientY};const j=nNI(l.current);n(j)}}}function L(b){b.preventDefault();const H=b.changedTouches[0];if(c.current==="drag"&&h.current&&H){const q={x:H.clientX,y:H.clientY},j=q.x-h.current.initialTouch.x,Z=q.y-h.current.initialTouch.y,O=Sc(Bi(j,Z),h.current.initialTransform);n(O),y=O}else if(c.current==="pinch"&&l.current){const q=nNI(l.current);n(q),y=q}c.current="none",h.current=null,l.current=null}return d.addEventListener("mousedown",p),d.addEventListener("mouseup",k),window.addEventListener("mousemove",S),d.addEventListener("mouseout",x),d.addEventListener("wheel",R),d.addEventListener("touchstart",N,{passive:!1}),d.addEventListener("touchmove",J,{passive:!1}),d.addEventListener("touchend",L,{passive:!1}),d.addEventListener("touchcancel",L,{passive:!1}),()=>{d.removeEventListener("mousedown",p),d.removeEventListener("mouseup",k),window.removeEventListener("mousemove",S),d.removeEventListener("mouseout",x),d.removeEventListener("wheel",R),d.removeEventListener("touchstart",N),d.removeEventListener("touchmove",J),d.removeEventListener("touchend",L),d.removeEventListener("touchcancel",L)}},[t,C,i,I,g.enabled,g.shouldDrag]);const D=gA.useCallback(d=>PI(r,d),[r]);return{ref:A,transform:r,applyTransformToPoint:D,setTransform:s,cancelDrag:a}},sNI=leA;function Keg(g){const A=yM(g),I=new Map;for(const o of A.schematic_component.list())o.source_component_id&&I.set(o.source_component_id,o.schematic_component_id);const e=new Map;for(const o of A.source_trace.list()){const C=o.subcircuit_connectivity_map_key;if(C)for(const Q of o.connected_source_port_ids??[]){const i=I.get(A.source_port.get(Q)?.source_component_id??"");i&&(e.has(i)||e.set(i,new Set),e.get(i).add(C))}}const t=new Map;for(const o of A.schematic_net_label.list()){if(!o.source_net_id)continue;const C=A.source_net.get(o.source_net_id)?.subcircuit_connectivity_map_key??o.source_net_id;t.set(o.schematic_net_label_id,C)}const B=new Map;for(const o of A.schematic_text.list()){if(!o.source_trace_id)continue;const C=A.source_trace.get(o.source_trace_id)?.subcircuit_connectivity_map_key;C&&B.set(o.schematic_text_id,C)}return{componentIdToKeys:e,netLabelIdToKey:t,textIdToKey:B}}var wuA=(g,A)=>Math.hypot(g.x-A.x,g.y-A.y),aNI=(g,A,I)=>{const e=I.x-A.x,t=I.y-A.y,B=e*e+t*t,o=B?Math.max(0,Math.min(1,((g.x-A.x)*e+(g.y-A.y)*t)/B)):0;return wuA(g,{x:A.x+o*e,y:A.y+o*t})},R5=(g,A,I)=>Math.abs(wuA(A,g)+wuA(g,I)-wuA(A,I))<1e-5;function FaB(g,A){const I=Keg(A),e=g?.closest("[data-subcircuit-connectivity-map-key], [data-schematic-net-label-id], [data-schematic-text-id], [data-schematic-trace-id]");if(!e)return;const t=A.find(B=>B.type==="schematic_trace"&&B.schematic_trace_id===e.getAttribute("data-schematic-trace-id"));return e.getAttribute("data-subcircuit-connectivity-map-key")||I.netLabelIdToKey.get(e.getAttribute("data-schematic-net-label-id"))||I.textIdToKey.get(e.getAttribute("data-schematic-text-id"))||(t?.type==="schematic_trace"?t.subcircuit_connectivity_map_key||A.filter(B=>B.type==="source_trace").find(B=>B.source_trace_id===t.source_trace_id)?.subcircuit_connectivity_map_key:void 0)}function xaB(g,A){const I=Keg(g),e=g.filter(n=>n.type==="source_trace"),t=g.filter(n=>n.type==="schematic_trace"),B=g.filter(n=>n.type==="schematic_sheet"),o=B[0]?.schematic_sheet_id,C=[];for(const n of t)if((n.subcircuit_connectivity_map_key??e.find(r=>r.source_trace_id===n.source_trace_id)?.subcircuit_connectivity_map_key)===A)for(const r of n.edges)C.push({a:r.from,b:r.to,sheet:n.schematic_sheet_id??o,target:{type:"schematic_trace",id:n.schematic_trace_id},sourceTraceId:n.source_trace_id,portIds:[r.from_schematic_port_id,r.to_schematic_port_id].filter(a=>!!a),junctions:n.junctions});for(const n of g)if(n.type==="schematic_net_label"&&I.netLabelIdToKey.get(n.schematic_net_label_id)===A){const s=n.anchor_position??n.center;C.push({a:s,b:s,sheet:n.schematic_sheet_id??o,target:{type:"schematic_net_label",id:n.schematic_net_label_id},name:n.text})}for(const n of g){if(n.type!=="schematic_text"||I.textIdToKey.get(n.schematic_text_id)!==A)continue;const s=n.schematic_sheet_id??o,a=C.filter(c=>c.sheet===s&&c.sourceTraceId===n.source_trace_id).sort((c,h)=>aNI(n.position,c.a,c.b)-aNI(n.position,h.a,h.b))[0]?.a??n.position;C.push({a,b:a,sheet:s,target:{type:"schematic_text",id:n.schematic_text_id},name:n.text})}const Q=C.map((n,s)=>s),i=n=>Q[n]===n?n:Q[n]=i(Q[n]);for(let n=0;n<C.length;n++)for(let s=0;s<n;s++){const r=C[n],a=C[s];r.sheet===a.sheet&&(R5(r.a,a.a,a.b)||R5(r.b,a.a,a.b)||R5(a.a,r.a,r.b)||R5(a.b,r.a,r.b)||[...r.junctions??[],...a.junctions??[]].some(c=>R5(c,r.a,r.b)&&R5(c,a.a,a.b)))&&(Q[i(n)]=i(s))}const E=new Map;return C.forEach((n,s)=>E.set(i(s),[...E.get(i(s))??[],n])),[...E.values()].map((n,s)=>{const r=n.find(D=>D.target.type!=="schematic_trace")??n[0],c=g.filter(D=>D.type==="schematic_port").filter(D=>(D.schematic_sheet_id??o)===r.sheet&&n.some(d=>d.portIds?.includes(D.schematic_port_id)||R5(D.center,d.a,d.b))).map(D=>{const d=g.find(w=>w.type==="source_port"&&w.source_port_id===D.source_port_id);if(d?.type!=="source_port")return;const y=g.find(w=>w.type==="source_component"&&w.source_component_id===d.source_component_id);return y?.type==="source_component"?`${y.name}.${d.name??`pin${d.pin_number}`}`:void 0}).filter(D=>!!D).sort(),h=B.findIndex(D=>D.schematic_sheet_id===r.sheet);return{kind:"net",label:`${B[h]?.name??`Sheet ${Math.max(0,h)+1}`}: ${c[0]??r.name??`Location ${s+1}`}`,schematicSheetId:r.sheet,target:r.target,focusPoint:{x:(r.a.x+r.b.x)/2,y:(r.a.y+r.b.y)/2}}})}var UaB={async load(){const g=await FQB("@tscircuit/circuit-json-schematic-placement-analysis");if(typeof g.createSchematicPlacementIssueArtifacts!="function")throw new Error("The style analyzer module does not export its analysis function.");return g}},gS={contextMenu:110,styleAnalysis:120,viewMenu:55,viewMenuIcon:48,clickToInteractOverlay:100,schematicComponentDetailsTooltip:105,schematicComponentHoverOutline:47,schematicPortHoverOutline:48,schematicSearch:101},JaB=({circuitJson:g,onClose:A})=>{const[I,e]=gA.useState({status:"loading"});return gA.useEffect(()=>{let t=!1;e({status:"loading"});const B=window.setTimeout(async()=>{try{const{createSchematicPlacementIssueArtifacts:o}=await UaB.load();if(t)return;const C=o(g);t||e({status:"complete",artifacts:C})}catch(o){t||e({status:"error",message:o instanceof Error?o.message:String(o)})}},0);return()=>{t=!0,window.clearTimeout(B)}},[g]),W.jsx(Beg,{open:!0,onOpenChange:t=>!t&&A(),children:W.jsxs(oeg,{children:[W.jsx(vwA,{style:{position:"fixed",inset:0,background:"#0008",zIndex:gS.styleAnalysis}}),W.jsxs(qwA,{style:{position:"fixed",top:"5vh",left:"50%",transform:"translateX(-50%)",width:"min(1000px, 94vw)",maxHeight:"90vh",overflowY:"auto",boxSizing:"border-box",padding:24,borderRadius:12,background:"#fafafa",color:"#171717",fontFamily:"system-ui, sans-serif",boxShadow:"0 20px 60px #0005",zIndex:gS.styleAnalysis},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:16},children:[W.jsx(TwA,{style:{margin:0,fontSize:22},children:"Style Analysis"}),W.jsx(Qeg,{style:{cursor:"pointer",padding:"6px 12px"},children:"Close"})]}),W.jsx(ZwA,{style:{color:"#525252"},children:"Placement and style issues across all schematic sheets. Each image highlights one issue with its description below."}),I.status==="loading"&&W.jsx("p",{role:"status",children:"Running style analysis…"}),I.status==="error"&&W.jsxs("p",{role:"alert",children:["Style analysis failed: ",I.message]}),I.status==="complete"&&W.jsxs(W.Fragment,{children:[W.jsx("p",{role:"status",children:I.artifacts.length===0?"No style issues found.":`${I.artifacts.length} style ${I.artifacts.length===1?"issue":"issues"} found.`}),I.artifacts.map(t=>W.jsxs("section",{style:{marginTop:24,border:"1px solid #ddd",borderRadius:8,overflow:"hidden",background:"white"},children:[W.jsxs("h3",{style:{margin:16,fontSize:16},children:[t.issueIndex+1,"."," ",t.issue.lineItemType.replace(/([a-z])([A-Z])/g,"$1 $2"),t.schematicSheetId&&W.jsxs("small",{style:{display:"block",marginTop:4,color:"#525252"},children:["Sheet: ",t.schematicSheetId]})]}),W.jsx("img",{src:`data:image/svg+xml;charset=utf-8,${encodeURIComponent(t.content)}`,alt:t.descriptionXml,loading:"lazy",style:{display:"block",width:"100%",height:"auto"}})]},t.issueIndex))]})]})]})})},rZ={IS_SHOWING_SCHEMATIC_GROUPS:"schematic_viewer_show_groups",IS_SHOWING_SCHEMATIC_PORTS:"schematic_viewer_show_ports",SELECTED_SCHEMATIC_SHEET:"schematic_viewer_selected_sheet"},rNI=(g,A)=>{if(typeof window>"u")return A;try{const I=localStorage.getItem(g);return I!==null?JSON.parse(I):A}catch{return A}},cNI=(g,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(g,JSON.stringify(A))}catch{}},KaB=g=>{if(typeof window>"u")return null;try{return localStorage.getItem(g)}catch{return null}},PaB=(g,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(g,A)}catch{}},hNI=["#8B0000","#2F4F4F","#191970","#006400","#FF4500","#800080","#2E8B57","#B8860B","#C71585","#008B8B"],LaB=g=>{const{svgDivRef:A,circuitJson:I,circuitJsonKey:e,showGroups:t}=g;gA.useEffect(()=>{if(A.current&&A.current.querySelectorAll(".schematic-group-overlay").forEach(C=>C.remove()),!A.current||!t||!I||I.length===0)return;const B=setTimeout(()=>{if(!A.current)return;const o=A.current.querySelector("svg");if(!o)return;o.querySelectorAll(".schematic-group-overlay").forEach(Q=>Q.remove());try{const Q=yM(I).source_group?.list().filter(D=>!D.is_subcircuit)||[],i=yM(I).schematic_component?.list()||[],E=new Map;Q.forEach(D=>{const d=D;if(d.parent_source_group_id){const y=E.get(d.parent_source_group_id)||[];y.push(D.source_group_id),E.set(d.parent_source_group_id,y)}});const n=D=>{const d=[],y=E.get(D)||[];for(const w of y)d.push(w),d.push(...n(w));return d},s=D=>{const d=Q.find(y=>y.source_group_id===D);return d?.parent_source_group_id?1+s(d.parent_source_group_id):0},r=Q.length>0&&Q.some(D=>D.name&&D.name.trim()!=="");let a=[];if(r){const D=new Map;for(const d of i){const y=yM(I).source_component.get(d.source_component_id);y?.source_group_id&&(D.has(y.source_group_id)||D.set(y.source_group_id,[]),D.get(y.source_group_id).push(d))}Q.forEach((d,y)=>{let w=D.get(d.source_group_id)||[];const u=n(d.source_group_id);for(const G of u){const m=D.get(G)||[];w=[...w,...m]}if(w.length>0){const G=s(d.source_group_id),m=n(d.source_group_id).length>0;if(d.name?.startsWith("unnamed_board"))return;a.push({id:d.source_group_id,name:d.name||`Group ${y+1}`,components:w,color:hNI[y%hNI.length],depthLevel:G,hasChildren:m,sourceGroupId:d.source_group_id})}})}const c=o.viewBox.baseVal,h=o.getBoundingClientRect(),l=Math.min(h.width/c.width,h.height/c.height)||1;a.sort((D,d)=>D.depthLevel-d.depthLevel),a.forEach(D=>{if(D.components.length===0)return;const d=YaB(D.components,o);if(!d)return;const y=Math.max(8,Math.min(25,15/Math.max(l,.3))),w=D.hasChildren?y*.6:0,u=y+w,G=Math.max(1,2/Math.max(l,.5)),m=D.depthLevel===0?G:G*.7,p=Math.max(4,8/Math.max(l,.5)),k=D.hasChildren?1.3:1,S=p*k,R=S*.5,x=document.createElementNS("http://www.w3.org/2000/svg","rect");x.setAttribute("class","schematic-group-overlay"),x.setAttribute("x",(d.minX-u).toString()),x.setAttribute("y",(d.minY-u).toString()),x.setAttribute("width",(d.maxX-d.minX+u*2).toString()),x.setAttribute("height",(d.maxY-d.minY+u*2).toString()),x.setAttribute("fill","none"),x.setAttribute("stroke",D.color),x.setAttribute("stroke-width",m.toString()),x.setAttribute("stroke-dasharray",`${S},${R}`),x.setAttribute("opacity","0.8"),x.setAttribute("rx","0"),x.setAttribute("ry","0");const N=Math.max(6,Math.min(20,14/Math.max(l,.2))),J=D.depthLevel===0||D.depthLevel===1?0:D.depthLevel*.2,L=N*(1-J),b=Math.max(1,L*.2),H=D.name,q=document.createElementNS("http://www.w3.org/2000/svg","text");q.setAttribute("font-size",L.toString()),q.setAttribute("font-family","Arial, sans-serif"),q.textContent=H,o.appendChild(q);const j=q.getBBox();o.removeChild(q);const Z=j.width+b*2,O=L+b*2,AA=d.minX-u,tA=d.minY-u-O,eA=document.createElementNS("http://www.w3.org/2000/svg","rect");eA.setAttribute("class","schematic-group-overlay"),eA.setAttribute("x",AA.toString()),eA.setAttribute("y",(tA-O).toString()),eA.setAttribute("width",Z.toString()),eA.setAttribute("height",O.toString()),eA.setAttribute("fill","transparent"),eA.setAttribute("rx","0"),eA.setAttribute("ry","0");const iA=document.createElementNS("http://www.w3.org/2000/svg","text");iA.setAttribute("class","schematic-group-overlay"),iA.setAttribute("x",(AA+b).toString()),iA.setAttribute("y",(tA+O-b).toString()),iA.setAttribute("fill",D.color),iA.setAttribute("font-size",L.toString()),iA.setAttribute("font-family","Arial, sans-serif"),iA.setAttribute("font-weight",D.depthLevel===0?"600":"500"),iA.setAttribute("stroke",D.color),iA.setAttribute("stroke-width",Math.max(.2,L*.02).toString()),iA.textContent=H,o.appendChild(x),o.appendChild(eA),o.appendChild(iA)})}catch(Q){console.error("Error creating group overlays:",Q)}},10);return()=>clearTimeout(B)},[A,e,t])};function YaB(g,A){let I=1/0,e=1/0,t=-1/0,B=-1/0;for(const C of g){let Q=A.querySelector(`g[data-schematic-component-id="${C.schematic_component_id}"]`);if(Q||(Q=A.querySelector(`[data-schematic-component-id="${C.schematic_component_id}"]`)),Q){const i=Q.getBBox();I=Math.min(I,i.x),e=Math.min(e,i.y),t=Math.max(t,i.x+i.width),B=Math.max(B,i.y+i.height)}}return I===1/0?null:{minX:I,minY:e,maxX:t,maxY:B}}var Peg="sch-net-faded",lNI="g.trace[data-subcircuit-connectivity-map-key], g.trace-overlays[data-subcircuit-connectivity-map-key]",Leg="[data-schematic-net-label-id], [data-schematic-text-id]",_aB=({svgDivRef:g,circuitJson:A,circuitJsonKey:I,enabled:e})=>{gA.useEffect(()=>{const t=g.current;if(!e||!t)return;const{componentIdToKeys:B,netLabelIdToKey:o,textIdToKey:C}=Keg(A);let Q=[];const i=new Map;let E=null;const n=()=>{for(const{el:l}of Q)l.classList.remove(Peg);Q=[],i.clear(),E=null;const h=t.querySelector("svg");if(h){for(const l of Array.from(h.querySelectorAll(lNI))){const D=l.getAttribute("data-subcircuit-connectivity-map-key"),d=new Set;D&&(d.add(D),i.set(l,D)),Q.push({el:l,keys:d})}for(const l of Array.from(h.querySelectorAll("g[data-schematic-component-id]"))){const D=l.getAttribute("data-schematic-component-id");Q.push({el:l,keys:B.get(D)??new Set})}for(const l of Array.from(h.querySelectorAll(Leg))){const D=o.get(l.getAttribute("data-schematic-net-label-id"))??C.get(l.getAttribute("data-schematic-text-id")),d=new Set;D&&(d.add(D),i.set(l,D)),Q.push({el:l,keys:d})}}},s=h=>{if(h!==E){E=h;for(const{el:l,keys:D}of Q)l.classList.toggle(Peg,h!==null&&!D.has(h))}},r=h=>{const l=h.target;if(!(l instanceof Element)){s(null);return}const D=l.closest(`${lNI}, ${Leg}`);if(D&&i.has(D)){s(i.get(D));return}for(const[d,y]of i){if(!d.matches(Leg))continue;const w=d.getBoundingClientRect();if(h.clientX>=w.left-6&&h.clientX<=w.right+6&&h.clientY>=w.top-6&&h.clientY<=w.bottom+6){s(y);return}}s(null)},a=()=>s(null);n(),t.addEventListener("mousemove",r),t.addEventListener("mouseleave",a);const c=new MutationObserver(n);return c.observe(t,{childList:!0}),()=>{c.disconnect(),t.removeEventListener("mousemove",r),t.removeEventListener("mouseleave",a);for(const{el:h}of Q)h.classList.remove(Peg)}},[g,I,e])},Yeg="http://www.w3.org/2000/svg",baB=({svgDivRef:g,svgContent:A,circuitJsonKey:I})=>{const e=gA.useRef(new Set);gA.useLayoutEffect(()=>{e.current.clear()},[I]),gA.useLayoutEffect(()=>{const t=[];for(const B of g.current?.querySelectorAll(".schematic-warning")??[]){const o=B.getAttribute("data-warning-id"),C=B.querySelector('[data-warning-reference="callout"]');if(!o||!C)continue;const Q=Array.from(B.children),i=Q.map(d=>d.style.display),E=B.getAttribute("role"),n=B.getAttribute("aria-label")??"Warning",s=document.createElementNS(Yeg,"g");s.setAttribute("data-warning-icon",""),s.setAttribute("aria-hidden","true"),s.setAttribute("transform",`translate(${C.getAttribute("x")} ${C.getAttribute("y")})`);const r=document.createElementNS(Yeg,"rect");r.setAttribute("width","24"),r.setAttribute("height","24"),r.setAttribute("fill",C.getAttribute("fill")??"#fffaeb"),r.setAttribute("stroke",C.getAttribute("stroke")??"#d99a00"),r.setAttribute("stroke-width","1");const a=document.createElementNS(Yeg,"text");a.setAttribute("x","12"),a.setAttribute("y","12"),a.setAttribute("dominant-baseline","central"),a.setAttribute("text-anchor","middle"),a.setAttribute("font-size","16"),a.setAttribute("font-family","sans-serif"),a.setAttribute("font-weight","bold"),a.setAttribute("fill","#5c4300"),a.textContent="!",s.append(r,a),B.append(s),B.setAttribute("role","button"),B.setAttribute("tabindex","0"),B.style.cursor="pointer",B.style.outline="none";const c=()=>{const d=e.current.has(o);Q.forEach((y,w)=>{y.style.display=d?"none":i[w]}),s.style.display=d?"":"none",B.setAttribute("aria-expanded",String(!d)),B.setAttribute("aria-label",`${d?"Expand":"Minimize"} warning: ${n}`)},h=d=>{d.preventDefault(),d.stopPropagation(),e.current.has(o)?e.current.delete(o):e.current.add(o),c()},l=d=>{(d.key==="Enter"||d.key===" ")&&(d.repeat?d.preventDefault():h(d))},D=d=>d.stopPropagation();B.addEventListener("click",h),B.addEventListener("keydown",l),B.addEventListener("mousedown",D),B.addEventListener("touchstart",D),c(),t.push(()=>{B.removeEventListener("click",h),B.removeEventListener("keydown",l),B.removeEventListener("mousedown",D),B.removeEventListener("touchstart",D),s.remove(),Q.forEach((d,y)=>{d.style.display=i[y]}),E?B.setAttribute("role",E):B.removeAttribute("role"),B.setAttribute("aria-label",n),B.removeAttribute("aria-expanded"),B.removeAttribute("tabindex"),B.style.removeProperty("cursor"),B.style.removeProperty("outline")})}return()=>t.forEach(B=>B())},[g,A,I])},_eg=g=>String(g??"").toLocaleLowerCase(),DeA=(g,A)=>{const I=_eg(g);return I===A?0:I.startsWith(A)?1:I.includes(A)?2:Number.POSITIVE_INFINITY},HaB=g=>{if(g)return String(g).replace(/^simple_/,"").replaceAll("_"," ").replace(/\b\w/g,A=>A.toLocaleUpperCase())},vaB=(g,A,I)=>{let t=HaB(g?.ftype);g?.ftype==="simple_chip"&&g.manufacturer_part_number&&(t=g.manufacturer_part_number);const B=[];g?.display_name===I&&g.name!==I&&B.push(g.name);let o=g?.display_value;if(!o&&g){for(const C of["display_resistance","display_capacitance","display_inductance","display_frequency","symbol_display_value"])if(C in g){const Q=g[C];if(typeof Q=="string"){o=Q;break}}}if(o??(o=A.symbol_display_value),t&&B.push(t),o&&B.push(o),!t&&!o&&g?.manufacturer_part_number&&B.push(g.manufacturer_part_number),B.length!==0)return B.join(" · ")},qaB=g=>g.type==="source_component"&&"source_component_id"in g,TaB=g=>g.type==="source_port",ZaB=g=>g.type==="source_trace",OaB=g=>g.type==="schematic_component",WaB=g=>g.type==="schematic_port",VaB=g=>g.type==="schematic_net_label",jaB=g=>g.type==="schematic_sheet",beg=({schematicSheets:g,schematicSheetId:A})=>{if(!(g.length<=1||!A))return g.find(I=>I.schematic_sheet_id===A)?.name},zaB=(g,A)=>{const I=_eg(A).trim();if(!I)return[];const e=new Map(g.filter(qaB).map(E=>[E.source_component_id,E])),t=new Map(g.filter(TaB).map(E=>[E.source_port_id,E])),B=g.filter(WaB),o=g.filter(ZaB),C=g.filter(jaB),Q=[],i=new Map;for(const E of g.filter(OaB)){const n=E.source_component_id?e.get(E.source_component_id):void 0,s=n?.display_name??n?.name??"Component",r=Math.min(DeA(n?.name,I),DeA(n?.display_name,I),DeA(n?.manufacturer_part_number,I));if(Number.isFinite(r)){const a={label:s,detail:vaB(n,E,s),kind:"component",schematicSheetId:E.schematic_sheet_id,schematicSheetName:beg({schematicSheets:C,schematicSheetId:E.schematic_sheet_id}),target:{type:"schematic_component",id:E.schematic_component_id}};Q.push(a),i.set(a,r)}}for(const E of g.filter(VaB)){if(!_eg(E.text).includes(I))continue;const n=new Set;for(const d of o.filter(y=>y.connected_source_net_ids.includes(E.source_net_id)))for(const y of d.connected_source_port_ids)n.add(y);const s=E.anchor_position??E.center,r=B.filter(d=>n.has(d.source_port_id)&&(!E.schematic_sheet_id||!d.schematic_sheet_id||d.schematic_sheet_id===E.schematic_sheet_id)).map(d=>({port:d,distance:Math.hypot(d.center.x-s.x,d.center.y-s.y)})).filter(({distance:d})=>d<=1).sort((d,y)=>d.distance-y.distance)[0]?.port,a=r?t.get(r.source_port_id):void 0,c=a?.source_component_id?e.get(a.source_component_id):void 0,h=a?.name??(a?.pin_number!==void 0?`pin${a.pin_number}`:r?.display_pin_label),l=c?.name&&h?`Connected to ${c.name}.${h}`:void 0,D={label:E.text,detail:l,kind:"net",schematicSheetId:E.schematic_sheet_id,schematicSheetName:beg({schematicSheets:C,schematicSheetId:E.schematic_sheet_id}),target:{type:"schematic_net_label",id:E.schematic_net_label_id}};Q.push(D),i.set(D,DeA(E.text,I))}for(const E of g){if(E.type!=="schematic_text"||!E.source_trace_id)continue;const n=DeA(E.text,I);if(!Number.isFinite(n))continue;const s={label:E.text,kind:"net",schematicSheetId:E.schematic_sheet_id,schematicSheetName:beg({schematicSheets:C,schematicSheetId:E.schematic_sheet_id}),target:{type:"schematic_text",id:E.schematic_text_id}};Q.push(s),i.set(s,n)}return Q.sort((E,n)=>(i.get(E)??Number.POSITIVE_INFINITY)-(i.get(n)??Number.POSITIVE_INFINITY)||E.label.localeCompare(n.label))},XaB=({containerRect:g,targetRect:A,visibleProjection:I,minimumScale:e})=>{const t=I.a||1,B={x:A.left+A.width/2-g.left,y:A.top+A.height/2-g.top},o={x:(B.x-I.e)/t,y:(B.y-I.f)/t},C=Math.max(t,e);return{a:C,b:0,c:0,d:C,e:g.width/2-o.x*C,f:g.height/2-o.y*C}},$aB=1.8,DNI=350,ArB=({controller:g,circuitJson:A,circuitJsonKey:I,svgDivRef:e,containerRef:t,activeSheetId:B,hasMultipleSheets:o,handleSelectSheet:C,svgString:Q,svgToScreenProjection:i,setSvgToScreenProjection:E,setIsInteractionEnabled:n})=>{const[s,r]=gA.useState(""),[a,c]=gA.useState(null),h=gA.useRef(null),l=gA.useMemo(()=>zaB(A,s),[A,I,s]),D=gA.useCallback(G=>{const m=e.current,p=t.current;if(!m||!p)return!1;const k=`data-${G.target.type.replaceAll("_","-")}-id`,S=Array.from(m.querySelectorAll(`[${k}]`)).find(L=>L.getAttribute(k)===G.target.id);if(!S)return!1;let R=S.getBoundingClientRect();if(G.focusPoint){const L=S.closest("svg"),b=L?.getAttribute("data-real-to-screen-transform"),H=L?.getScreenCTM?.();if(b&&H){const q=OI(H,OI(lfI(b),G.focusPoint));R={left:q.x-1,top:q.y-1,width:2,height:2}}}const x=p.getBoundingClientRect();if(!x.width||!x.height||!R.width&&!R.height)return!1;h.current&&clearTimeout(h.current);let N=i;const J=getComputedStyle(m).transform;if(J&&J!=="none")try{N=lfI(J),m.style.transition="none",m.style.transform=J,m.offsetWidth}catch{}return m.style.transition=`transform ${DNI}ms ease-in-out`,m.offsetWidth,E(XaB({containerRect:x,targetRect:R,visibleProjection:N,minimumScale:$aB})),h.current=setTimeout(()=>{m.style.transition=""},DNI),m.querySelectorAll(".schematic-search-match").forEach(L=>L.classList.remove("schematic-search-match")),m.querySelectorAll(`[${k}]`).forEach(L=>{L.getAttribute(k)===G.target.id&&L.classList.add("schematic-search-match")}),!0},[t,E,e,i]),d=gA.useCallback(G=>{if(n(!0),G.schematicSheetId&&G.schematicSheetId!==B&&o){C(G.schematicSheetId),c(G);return}D(G)},[B,D,C,o,n]),y=gA.useCallback(()=>{r(""),c(null),h.current&&(clearTimeout(h.current),h.current=null),e.current&&(e.current.style.transition="",e.current.querySelectorAll(".schematic-search-match").forEach(G=>G.classList.remove("schematic-search-match")))},[e]),w=g?.focusRequest,u=g?.onFocusRequestHandled;return gA.useEffect(()=>{if(!w)return;const G=A.find(m=>m.type==="schematic_component"&&m.schematic_component_id===w.schematicComponentId);if(G?.type!=="schematic_component"){c(null),u?.(w);return}n(!0),G.schematic_sheet_id&&o&&C(G.schematic_sheet_id),c({kind:"component",label:G.schematic_component_id,schematicSheetId:G.schematic_sheet_id,target:{type:"schematic_component",id:G.schematic_component_id}})},[w,u,A,I,o,C,n]),gA.useEffect(()=>{if(!a||!Q||o&&a.schematicSheetId&&a.schematicSheetId!==B)return;const G=requestAnimationFrame(()=>{D(a)&&(c(null),w?.schematicComponentId===a.target.id&&u?.(w))});return()=>cancelAnimationFrame(G)},[D,w,u,a,Q,o,B]),gA.useEffect(()=>{s||e.current?.querySelectorAll(".schematic-search-match").forEach(G=>G.classList.remove("schematic-search-match"))},[s,e]),gA.useEffect(()=>()=>{h.current&&clearTimeout(h.current)},[]),{searchQuery:s,setSearchQuery:r,searchResults:l,handleSearchResultSelect:d,handleCancelSearch:y}};ds("schematic-viewer");var grB=()=>{ds.enable("schematic-viewer*")},dNI=g=>{const[A,I]=gA.useState(0),[e,t]=gA.useState(0);return gA.useEffect(()=>{if(!g.current)return;const B=()=>{const C=g.current?.getBoundingClientRect();I(C?.width||0),t(C?.height||0)};B();const o=new ResizeObserver(B);return o.observe(g.current),window.addEventListener("resize",B),()=>{o.disconnect(),window.removeEventListener("resize",B)}},[]),{containerWidth:A,containerHeight:e}},IrB=600,uuA=10,erB=({containerRef:g})=>{const[A,I]=gA.useState(null),[e,t]=gA.useState(!1),[B,o]=gA.useState({x:0,y:0}),C=gA.useRef(null),Q=gA.useRef(null),i=gA.useRef(null),E=gA.useRef(0),n=gA.useCallback(()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null)},[]),s=gA.useCallback(l=>{if(l.preventDefault(),Date.now()<E.current)return;const D=Q.current;if(!D)return;const d=Math.abs(l.clientX-D.x)>uuA||Math.abs(l.clientY-D.y)>uuA;Q.current=null,!d&&(I(l.target instanceof Element?l.target:null),o({x:l.clientX,y:l.clientY}),t(!0))},[]),r=gA.useCallback(l=>{if(n(),l.touches.length!==1){Q.current=null;return}const D=l.touches[0];if(!D)return;const d=l.target instanceof Element?l.target:null;Q.current={x:D.clientX,y:D.clientY},i.current=window.setTimeout(()=>{const y=g.current;if(!y||!Q.current)return;I(d);const w=y.getBoundingClientRect();o({x:w.left+w.width/2,y:w.top+w.height/2}),t(!0),E.current=Date.now()+1e3,Q.current=null},IrB)},[n,g]),a=gA.useCallback(l=>{const D=Q.current;if(!D||l.touches.length!==1)return;const d=l.touches[0];(!d||Math.abs(d.clientX-D.x)>uuA||Math.abs(d.clientY-D.y)>uuA)&&(Q.current=null,n())},[n]),c=gA.useCallback(()=>{n(),Q.current=null},[n]),h=gA.useCallback(l=>{const D=l.target;C.current?.contains(D)||D.closest?.("[data-radix-popper-content-wrapper], [data-radix-dropdown-menu-content]")||t(!1)},[]);return gA.useEffect(()=>{if(e)return document.addEventListener("mousedown",h),document.addEventListener("touchstart",h),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("touchstart",h)}},[h,e]),gA.useEffect(()=>n,[n]),{menuVisible:e,menuTarget:A,menuPos:B,menuRef:C,setMenuVisible:t,contextMenuEventHandlers:{onMouseDown:l=>{Q.current=l.button===2||l.button===0&&l.ctrlKey?{x:l.clientX,y:l.clientY}:null},onContextMenu:s,onTouchStart:r,onTouchMove:a,onTouchEnd:c,onTouchCancel:c}}},trB=(g,A,I)=>g.filter(e=>{if(!e.type.endsWith("_warning"))return!1;const t=e;return[["source_component",A.source_component_id],["schematic_component",A.schematic_component_id],["pcb_component",I?.pcb_component_id]].some(([o,C])=>{if(!C)return!1;const Q=t[`${o}_ids`];return t[`${o}_id`]===C||Array.isArray(Q)&&Q.includes(C)||t.schematic_element_type===o&&t.schematic_element_id===C})}),BrB=new Set(["type","source_component_id","source_group_id","subcircuit_id","display_name","ftype","are_pins_interchangeable","supplier_part_numbers"]),yNI=["name","resistance","capacitance","inductance","frequency","voltage","current","max_voltage_rating","max_current_rating","power_rating","manufacturer_part_number"],orB={jlcpcb:g=>`https://jlcpcb.com/partdetail/${encodeURIComponent(g)}`,lcsc:g=>`https://www.lcsc.com/product-detail/${encodeURIComponent(g)}.html`},CrB=g=>{const A=g.trim(),I=/^c?(\d+)$/i.exec(A);return I?`C${I[1]}`:A},wNI=g=>{const A=yNI.indexOf(g);return A===-1?yNI.length:A},QrB=(g,A,I)=>{if(A==="name")return String(I);const e=g[`display_${A}`];if(typeof e=="string"&&e.trim()){const t=A==="resistance"?e.replace(/Ω$/,""):e;return JSON.stringify(t)}return JSON.stringify(I)??String(I)},irB=g=>Object.entries(g).filter(([A,I])=>BrB.has(A)||A.startsWith("display_")&&A.slice(8)in g?!1:I!=null&&I!=="").sort(([A],[I])=>wNI(A)-wNI(I)||A.localeCompare(I)).map(([A,I])=>({key:A,label:A,value:QrB(g,A,I)})),ErB=g=>{const A=g.supplier_part_numbers;return A?["jlcpcb","lcsc"].flatMap(I=>{const e=A[I];if(!Array.isArray(e))return[];const t=[...new Set(e.filter(B=>!!(typeof B=="string"&&B.trim())).map(CrB))];return t.length?[{key:`supplier_part_numbers.${I}`,label:I,links:t.map(B=>({partNumber:B,href:orB[I](B)}))}]:[]}):[]},nrB=(g,A)=>{const I=g.find(Q=>Q.type==="schematic_component"&&Q.schematic_component_id===A);if(!I)return null;const e=g.find(Q=>Q.type==="source_component"&&Q.source_component_id===I.source_component_id);if(!e)return null;const t=g.find(Q=>Q.type==="pcb_component"&&Q.source_component_id===e.source_component_id),B=g.find(Q=>Q.type==="cad_component"&&Q.source_component_id===e.source_component_id&&(!t||Q.pcb_component_id===t.pcb_component_id)),o=t?.footprinter_string??B?.footprinter_string,C=t?srB(g,t.pcb_component_id):null;return{schematicComponent:I,sourceComponent:e,pcbComponent:t,footprinterString:o,footprintPreviewCircuitJson:C?.circuitJson,footprintPreviewViewBox:C?.viewBox,warnings:trB(g,I,t)}},GuA=2,srB=(g,A)=>{const I=g.find(B=>B.type==="pcb_component"&&B.pcb_component_id===A);if(!I)return null;const e=ufI(I);if(!e)return null;const t={minX:e.minX-GuA,minY:e.minY-GuA,maxX:e.maxX+GuA,maxY:e.maxY+GuA};return{circuitJson:qQB(g,t),viewBox:t}},arB=(g,A)=>{const I=mnB(g,{width:320,height:240,viewport:A,backgroundColor:"#f8fafc",includeVersion:!1});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(I)}`},uNI=(g,A)=>{const I=g?.closest("[data-schematic-component-id]")?.getAttribute("data-schematic-component-id"),e=g?.closest("[data-schematic-text-id]")?.getAttribute("data-schematic-text-id"),t=g?.closest("[data-schematic-port-id]")?.getAttribute("data-schematic-port-id");if(!I&&!e&&!t)return;const B=A.find(i=>i.type==="schematic_text"&&i.schematic_text_id===e),o=A.find(i=>i.type==="schematic_port"&&!!t&&(i.schematic_port_id===t||i.source_port_id===t)),C=I??(B?.type==="schematic_text"?B.schematic_component_id:void 0)??(o?.type==="schematic_port"?o.schematic_component_id:void 0);if(!C)return;const Q=A.find(i=>i.type==="schematic_component"&&i.schematic_component_id===C);if(Q?.type==="schematic_component")return Q},rrB=(g,A)=>{const I=uNI(g,A);if(!I)return;const e=A.find(B=>B.type==="source_component"&&B.source_component_id===I.source_component_id),t=A.find(B=>B.type==="pcb_component"&&B.source_component_id===I.source_component_id);if(!(e?.type!=="source_component"||t?.type!=="pcb_component"))return{source_component_id:e.source_component_id,schematic_component_id:I.schematic_component_id,pcb_component_id:t.pcb_component_id,refdes:e.name}},Heg=gA.createContext(null),crB=5,hrB=(g,A)=>!g&&!A?!0:!g||!A?!1:g.minX===A.minX&&g.maxX===A.maxX&&g.minY===A.minY&&g.maxY===A.maxY,lrB=({children:g})=>gA.useContext(Heg)?W.jsx(W.Fragment,{children:g}):W.jsx(DrB,{children:g}),DrB=({children:g})=>{const A=gA.useRef({pointer:null,boundingBoxes:new Map,hoveringIds:new Set,subscribers:new Set,mouseDownPosition:null}),I=gA.useCallback(()=>{for(const E of A.current.subscribers)E()},[]),e=gA.useCallback(()=>{const E=A.current.pointer,n=new Set;if(E)for(const[r,a]of A.current.boundingBoxes){const c=a.bounds;c&&E.x>=c.minX&&E.x<=c.maxX&&E.y>=c.minY&&E.y<=c.maxY&&n.add(r)}const s=A.current.hoveringIds;n.size===s.size&&[...n].every(r=>s.has(r))||(A.current.hoveringIds=n,I())},[I]),t=gA.useCallback((E,n)=>{A.current.boundingBoxes.set(E,n),e()},[e]),B=gA.useCallback((E,n)=>{const s=A.current.boundingBoxes.get(E);s&&hrB(s.bounds,n.bounds)&&s.onClick===n.onClick||(A.current.boundingBoxes.set(E,n),e())},[e]),o=gA.useCallback(E=>{A.current.boundingBoxes.delete(E)&&e()},[e]),C=gA.useCallback(E=>(A.current.subscribers.add(E),()=>{A.current.subscribers.delete(E)}),[]),Q=gA.useCallback(E=>A.current.hoveringIds.has(E),[]);gA.useEffect(()=>{const E=a=>{const{clientX:c,clientY:h}=a,l=A.current.pointer;l&&l.x===c&&l.y===h||(A.current.pointer={x:c,y:h},e())},n=()=>{A.current.pointer!==null&&(A.current.pointer=null,A.current.mouseDownPosition=null,e())},s=a=>{A.current.mouseDownPosition={x:a.clientX,y:a.clientY}},r=a=>{const{clientX:c,clientY:h}=a,l=A.current.mouseDownPosition;if(l&&Math.sqrt(Math.pow(c-l.x,2)+Math.pow(h-l.y,2))>crB){A.current.mouseDownPosition=null;return}A.current.mouseDownPosition=null;for(const D of A.current.boundingBoxes.values()){const d=D.bounds;d&&c>=d.minX&&c<=d.maxX&&h>=d.minY&&h<=d.maxY&&D.onClick?.(a)}};return window.addEventListener("pointermove",E,{passive:!0}),window.addEventListener("pointerdown",E,{passive:!0}),window.addEventListener("pointerup",E,{passive:!0}),window.addEventListener("pointerleave",n),window.addEventListener("pointercancel",n),window.addEventListener("blur",n),window.addEventListener("mousedown",s,{passive:!0}),window.addEventListener("click",r,{passive:!0}),()=>{window.removeEventListener("pointermove",E),window.removeEventListener("pointerdown",E),window.removeEventListener("pointerup",E),window.removeEventListener("pointerleave",n),window.removeEventListener("pointercancel",n),window.removeEventListener("blur",n),window.removeEventListener("mousedown",s),window.removeEventListener("click",r)}},[e]);const i=gA.useMemo(()=>({registerBoundingBox:t,updateBoundingBox:B,unregisterBoundingBox:o,subscribe:C,isHovering:Q}),[t,B,o,C,Q]);return W.jsx(Heg.Provider,{value:i,children:g})},cZ=g=>{if(typeof g!="number"&&typeof g!="string"||typeof g=="string"&&!g.trim())return null;const A=Number(g);return Number.isFinite(A)&&A>=0?A:null},drB=g=>{const A=cZ(g);if(A!==null)return A;if(typeof g!="string")return null;try{const I=JSON.parse(g);if(Array.isArray(I))return cZ(I[0]?.price)}catch{return g.split(",").map(e=>{const[t,B]=e.split(":");return{quantity:cZ(t?.split("-")[0]),price:cZ(B)}}).filter(e=>e.quantity!==null&&e.price!==null).sort((e,t)=>e.quantity-t.quantity)[0]?.price??null}return null},yrB=async(g,A,I=fetch)=>{const e=await I(`https://jlcsearch.tscircuit.com/api/search?q=${encodeURIComponent(g)}&limit=1`,{signal:A,cache:"no-store"});if(!e.ok)throw new Error("JLC part lookup failed");const t=await e.json();if(!Array.isArray(t?.components))return null;const B=t.components.find(o=>o&&String(o.lcsc).replace(/^c/i,"")===g.replace(/^c/i,""));return B?{price:cZ(B.price1)??drB(B.price),stock:cZ(B.stock)}:null},wrB=g=>{if(g?.price==null)return"Price unavailable";const A={minimumFractionDigits:2,maximumFractionDigits:6};return g.currency===null?g.price.toLocaleString("en-US",A):g.price.toLocaleString("en-US",{...A,style:"currency",currency:g.currency??"USD"})},urB=({partNumber:g,platformConfig:A})=>{const[I,e]=gA.useState(null),[t,B]=gA.useState(!0),o=A?.partsEngine,C=A?.platformFetch;return gA.useEffect(()=>{const Q=new AbortController;let i=!0;B(!0),e(null);const E=setTimeout(()=>{Q.abort(),i&&B(!1)},1e4);return Promise.resolve().then(async()=>o?.fetchPartAvailability?await o.fetchPartAvailability({supplierName:"jlcpcb",supplierPartNumber:g,signal:Q.signal,platformFetch:C})??null:yrB(g,Q.signal,C)).then(n=>{i&&e(n)}).catch(()=>{}).finally(()=>{clearTimeout(E),i&&B(!1)}),()=>{i=!1,clearTimeout(E),Q.abort()}},[g,o,C]),W.jsx("span",{role:"status","aria-label":`${g} price and stock`,"aria-busy":t,style:{display:"block",color:"#64748b",marginTop:"2px"},children:t?W.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[W.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:W.jsx("circle",{cx:"6",cy:"6",r:"4",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeDasharray:"18 8",children:W.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 6 6",to:"360 6 6",dur:"1s",repeatCount:"indefinite"})})}),"Loading price and stock…"]}):W.jsxs(W.Fragment,{children:[W.jsx("span",{style:{display:"block"},children:wrB(I)}),W.jsx("span",{style:{display:"block"},children:I?.stock!=null?`${I.stock.toLocaleString("en-US")} in stock`:"Stock unavailable"})]})})},veg={color:"#64748b",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45},GrB=({platformConfig:g,sourceComponent:A,warnings:I=[],footprinterString:e,footprintPreviewCircuitJson:t,footprintPreviewViewBox:B,left:o,top:C,width:Q,maxHeight:i})=>{const E=gA.useMemo(()=>irB(A),[A]),n=gA.useMemo(()=>ErB(A),[A]),s=gA.useMemo(()=>t?.length&&B?arB(t,B):void 0,[t,B]);return W.jsxs("dialog",{open:!0,"aria-label":`${A.name} component details`,"data-schematic-component-details-tooltip":!0,style:{position:"absolute",left:o,right:"auto",top:C,bottom:"auto",width:Q,maxHeight:i,margin:0,padding:0,overflowY:"auto",overscrollBehavior:"contain",cursor:"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:gS.schematicComponentDetailsTooltip},onMouseDown:r=>r.stopPropagation(),onClick:r=>r.stopPropagation(),onWheel:r=>r.stopPropagation(),children:[W.jsxs("dl",{style:{display:"grid",gridTemplateColumns:"minmax(110px, 0.8fr) minmax(0, 1.2fr)",gap:"6px 12px",margin:0,padding:"8px"},children:[E.map(r=>W.jsxs("div",{style:{display:"contents"},children:[W.jsx("dt",{style:veg,children:r.label}),W.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:r.value})]},r.key)),n.map(r=>W.jsxs("div",{style:{display:"contents"},children:[W.jsx("dt",{style:veg,children:r.label}),W.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:r.links.map((a,c)=>W.jsxs("span",{style:r.label==="jlcpcb"?{display:"block",marginTop:c>0?6:0}:void 0,children:[r.label!=="jlcpcb"&&c>0&&", ",W.jsx("a",{href:a.href,target:"_blank",rel:"noreferrer noopener",style:{color:"#2563eb",textDecoration:"underline"},children:a.partNumber}),r.label==="jlcpcb"&&W.jsx(urB,{partNumber:a.partNumber,platformConfig:g},`${A.source_component_id}-${a.partNumber}`)]},a.href))})]},r.key)),e&&W.jsxs("div",{style:{display:"contents"},children:[W.jsx("dt",{style:veg,children:"footprint"}),W.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)})]})]}),I.length>0&&W.jsxs("section",{"aria-label":"Component warnings",style:{margin:"0 8px 8px",padding:"8px",border:"1px solid #fcd34d",borderRadius:"4px",backgroundColor:"#fffbeb",color:"#92400e",fontSize:"12px",lineHeight:1.45,overflowWrap:"anywhere"},children:[W.jsxs("strong",{children:["Warnings (",I.length,")"]}),W.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:"18px"},children:I.map((r,a)=>W.jsx("li",{children:r.message},`${r.type}-${a}`))})]}),s&&W.jsx("div",{style:{padding:"0 4px 4px"},children:W.jsx("div",{style:{height:"210px",overflow:"hidden",border:"1px solid #e2e8f0",borderRadius:"2px",background:"#f8fafc"},children:W.jsx("img",{src:s,alt:`${A.name}${e?` ${e}`:""} PCB footprint`,loading:"lazy",referrerPolicy:"no-referrer",style:{display:"block",width:"100%",height:"100%",objectFit:"contain"}})})})]})},GNI=g=>{const A=gA.useContext(Heg);if(!A)throw new Error("useMouseEventsOverBoundingBox must be used within a MouseTracker");const I=gA.useId(),e=gA.useRef(g);e.current=g;const t=gA.useMemo(()=>o=>{e.current.onClick?.(o)},[]);return gA.useEffect(()=>(A.registerBoundingBox(I,{bounds:e.current.bounds,onClick:e.current.onClick?t:void 0}),()=>{A.unregisterBoundingBox(I)}),[A,t,I]),gA.useEffect(()=>{A.updateBoundingBox(I,{bounds:e.current.bounds,onClick:e.current.onClick?t:void 0})},[A,t,I,g.bounds?.minX,g.bounds?.maxX,g.bounds?.minY,g.bounds?.maxY,g.onClick]),{hovering:gA.useSyncExternalStore(A.subscribe,()=>A.isHovering(I),()=>!1)}},mrB=(g,A)=>!g&&!A?!0:!g||!A?!1:Math.abs(g.bounds.minX-A.bounds.minX)<.5&&Math.abs(g.bounds.maxX-A.bounds.maxX)<.5&&Math.abs(g.bounds.minY-A.bounds.minY)<.5&&Math.abs(g.bounds.maxY-A.bounds.maxY)<.5&&Math.abs(g.rect.left-A.rect.left)<.5&&Math.abs(g.rect.top-A.rect.top)<.5&&Math.abs(g.rect.width-A.rect.width)<.5&&Math.abs(g.rect.height-A.rect.height)<.5,prB=({componentId:g,svgDivRef:A,containerRef:I,onComponentClick:e,onHoverChange:t,showOutline:B,circuitJsonKey:o})=>{const[C,Q]=gA.useState(null),i=gA.useRef(null),E=gA.useCallback(()=>{i.current=null;const h=A.current,l=I.current;if(!h||!l){Q(u=>u&&null);return}const D=h.querySelector(`[data-schematic-component-id="${g}"]`);if(!D){Q(u=>u&&null);return}const d=D.getBoundingClientRect(),y=l.getBoundingClientRect(),w={bounds:{minX:d.left,maxX:d.right,minY:d.top,maxY:d.bottom},rect:{left:d.left-y.left,top:d.top-y.top,width:d.width,height:d.height}};Q(u=>mrB(u,w)?u:w)},[g,I,A]),n=gA.useCallback(()=>{i.current===null&&(i.current=window.requestAnimationFrame(E))},[E]);gA.useEffect(()=>{n()},[n,o]),gA.useEffect(()=>{n();const h=A.current,l=I.current;if(!h||!l)return;const D=typeof ResizeObserver<"u"?new ResizeObserver(()=>{n()}):null;D?.observe(l),D?.observe(h);const d=typeof MutationObserver<"u"?new MutationObserver(()=>{n()}):null;return d?.observe(h,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",n,!0),window.addEventListener("resize",n),()=>{D?.disconnect(),d?.disconnect(),window.removeEventListener("scroll",n,!0),window.removeEventListener("resize",n),i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)}},[n,A,I]);const s=gA.useCallback(h=>{e&&e(g,h)},[g,e]),r=C?.bounds??null,{hovering:a}=GNI({bounds:r,onClick:e?s:void 0});if(gA.useEffect(()=>{t&&t(g,a)},[a,g,t]),!C||!a||!B)return null;const c=C.rect;return W.jsx("div",{style:{position:"absolute",left:c.left,top:c.top,width:c.width,height:c.height,border:"1.5px solid rgba(51, 153, 255, 0.9)",pointerEvents:"none",zIndex:gS.schematicComponentHoverOutline}})},krB=(g,A)=>!g&&!A?!0:!g||!A?!1:Math.abs(g.bounds.minX-A.bounds.minX)<.5&&Math.abs(g.bounds.maxX-A.bounds.maxX)<.5&&Math.abs(g.bounds.minY-A.bounds.minY)<.5&&Math.abs(g.bounds.maxY-A.bounds.maxY)<.5&&Math.abs(g.rect.left-A.rect.left)<.5&&Math.abs(g.rect.top-A.rect.top)<.5&&Math.abs(g.rect.width-A.rect.width)<.5&&Math.abs(g.rect.height-A.rect.height)<.5,MrB=({portId:g,portLabel:A,svgDivRef:I,containerRef:e,onPortClick:t,onHoverChange:B,showOutline:o,circuitJsonKey:C})=>{const[Q,i]=gA.useState(null),E=gA.useRef(null),n=gA.useCallback(()=>{E.current=null;const l=I.current,D=e.current;if(!l||!D){i(m=>m&&null);return}const d=l.querySelector(`[data-schematic-port-id="${g}"]`);if(!d){i(m=>m&&null);return}const y=d.getBoundingClientRect(),w=D.getBoundingClientRect(),u=4,G={bounds:{minX:y.left-u,maxX:y.right+u,minY:y.top-u,maxY:y.bottom+u},rect:{left:y.left-w.left-u,top:y.top-w.top-u,width:y.width+u*2,height:y.height+u*2}};i(m=>krB(m,G)?m:G)},[g,e,I]),s=gA.useCallback(()=>{E.current===null&&(E.current=window.requestAnimationFrame(n))},[n]);gA.useEffect(()=>{s()},[s,C]),gA.useEffect(()=>{s();const l=I.current,D=e.current;if(!l||!D)return;const d=typeof ResizeObserver<"u"?new ResizeObserver(()=>{s()}):null;d?.observe(D),d?.observe(l);const y=typeof MutationObserver<"u"?new MutationObserver(()=>{s()}):null;return y?.observe(l,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",s,!0),window.addEventListener("resize",s),()=>{d?.disconnect(),y?.disconnect(),window.removeEventListener("scroll",s,!0),window.removeEventListener("resize",s),E.current!==null&&(cancelAnimationFrame(E.current),E.current=null)}},[s,I,e]);const r=gA.useCallback(l=>{t&&t(g,l)},[g,t]),a=Q?.bounds??null,{hovering:c}=GNI({bounds:a,onClick:t?r:void 0});if(gA.useEffect(()=>{B&&B(g,c)},[c,g,B]),!Q||!o)return null;const h=Q.rect;return W.jsxs(W.Fragment,{children:[W.jsx("div",{style:{position:"absolute",left:h.left,top:h.top,width:h.width,height:h.height,border:c?"1.5px solid rgba(255, 153, 51, 0.9)":"1.5px solid rgba(255, 153, 51, 0.3)",backgroundColor:c?"rgba(255, 153, 51, 0.15)":"rgba(255, 153, 51, 0.05)",borderRadius:"50%",pointerEvents:"none",zIndex:gS.schematicPortHoverOutline,transition:"border-color 0.15s, background-color 0.15s"}}),c&&A&&W.jsx("div",{style:{position:"absolute",left:h.left+h.width/2,top:h.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:gS.schematicPortHoverOutline+1},children:A})]})},deA=({children:g,size:A,strokeWidth:I})=>W.jsx("svg",{width:A,height:A,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:I,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:g}),mNI=g=>W.jsxs(deA,{...g,children:[W.jsx("circle",{cx:"11",cy:"11",r:"8"}),W.jsx("path",{d:"m21 21-4.34-4.34"})]}),SrB=g=>W.jsxs(deA,{...g,children:[W.jsx("path",{d:"M18 6 6 18"}),W.jsx("path",{d:"m6 6 12 12"})]}),frB=g=>W.jsxs(deA,{...g,children:[W.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),W.jsx("rect",{x:"8",y:"8",width:"8",height:"8",rx:"1"}),W.jsx("path",{d:"M7 2v2M12 2v2M17 2v2M7 20v2M12 20v2M17 20v2M2 7h2M2 12h2M2 17h2M20 7h2M20 12h2M20 17h2"})]}),RrB=g=>W.jsxs(deA,{...g,children:[W.jsx("path",{d:"M15 6a9 9 0 0 0-9 9V3"}),W.jsx("circle",{cx:"18",cy:"6",r:"3"}),W.jsx("circle",{cx:"6",cy:"18",r:"3"})]}),NrB=g=>W.jsxs(deA,{...g,children:[W.jsx("path",{d:"M20 4v7a4 4 0 0 1-4 4H4"}),W.jsx("path",{d:"m9 10-5 5 5 5"})]}),FrB=({text:g,query:A})=>{const I=A.trim().toLocaleLowerCase();if(!I)return g;const e=g.toLocaleLowerCase(),t=[];let B=0,o=e.indexOf(I);for(;o!==-1;)o>B&&t.push(g.slice(B,o)),t.push(W.jsx("strong",{style:{fontWeight:700},children:g.slice(o,o+I.length)},`${o}-${B}`)),B=o+I.length,o=e.indexOf(I,B);return B<g.length&&t.push(g.slice(B)),t.length>0?t:g},xrB=()=>typeof navigator>"u"?"Ctrl F":/mac/i.test(navigator.platform)?"⌘ F":"Ctrl F",UrB=({query:g,onQueryChange:A,onCancel:I,results:e,onSelect:t,viewerContainerRef:B})=>{const[o,C]=gA.useState(!1),[Q,i]=gA.useState(null),[E,n]=gA.useState(null),s=gA.useRef(null),r=gA.useRef(null),a=xrB();gA.useEffect(()=>{i(p=>e.some(k=>k.target.id===p)?p:e.find(k=>k.kind==="component")?.target.id??e[0]?.target.id??null)},[e]),gA.useEffect(()=>{Q&&r.current?.querySelector(`[data-search-result-id="${Q}"]`)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[Q]),gA.useEffect(()=>{const p=S=>{if(S.key==="Escape"&&o){S.preventDefault(),S.stopPropagation(),S.stopImmediatePropagation(),I(),C(!1),s.current?.blur();return}S.code!=="KeyF"&&S.key.toLocaleLowerCase()!=="f"||!S.metaKey&&!S.ctrlKey||B.current?.matches(":hover")&&(S.preventDefault(),S.stopPropagation(),S.stopImmediatePropagation(),C(!0),requestAnimationFrame(()=>{s.current?.focus(),s.current?.select()}))},k=[window];try{window.parent!==window&&window.parent.document&&k.push(window.parent)}catch{}return k.forEach(S=>S.addEventListener("keydown",p,{capture:!0})),()=>{k.forEach(S=>S.removeEventListener("keydown",p,{capture:!0}))}},[o,I,B]);const c=()=>{I(),C(!1),s.current?.blur()},h=p=>{C(!0),p&&requestAnimationFrame(()=>s.current?.focus())},l=e.filter(p=>p.kind==="component"),D=e.filter(p=>p.kind==="net"),d=[...l,...D],y=d.find(p=>p.target.id===Q)??d[0],w=e.length===1?"1 result":`${e.length} results`;let u="none";g&&(u="1px solid #e8e8e8");const G=p=>{if(!(p.key==="Enter"&&p.target instanceof Element&&p.target.closest('[aria-label="Clear search"]'))){if(p.key==="Escape"){p.preventDefault(),c();return}if(d.length>0&&(p.key==="ArrowDown"||p.key==="ArrowUp")){p.preventDefault();let k=-1;p.key==="ArrowDown"&&(k=1),i(S=>{const R=d.findIndex(J=>J.target.id===S);let x=R;R===-1&&(x=0,k===1&&(x=-1));const N=(x+k+d.length)%d.length;return d[N]?.target.id??null});return}p.key==="Enter"&&y&&(p.preventDefault(),t(y))}},m=(p,k)=>k.length===0?null:W.jsxs("section",{children:[W.jsx("div",{style:{padding:"6px 12px 3px",backgroundColor:"#f7f7f8",color:"#777777",fontSize:"11px",fontWeight:600,letterSpacing:"0.02em",textTransform:"lowercase"},children:p}),k.map(S=>{const R=S.target.id===y?.target.id,x=S.target.id===E;let N="#ffffff";(x||R)&&(N="#f1f3f5");let J=W.jsx(RrB,{size:15,strokeWidth:1.8});S.kind==="component"&&(J=W.jsx(frB,{size:15,strokeWidth:1.8}));const L=()=>{s.current?.blur(),i(S.target.id),t(S)};return W.jsxs("button",{type:"button","data-search-result-id":S.target.id,onPointerUp:b=>{b.button===0&&L()},onClick:b=>{b.detail===0&&L()},onMouseEnter:()=>n(S.target.id),onMouseLeave:()=>n(null),style:{width:"100%",display:"flex",alignItems:"center",gap:"9px",padding:"7px 12px",border:"none",background:N,color:"#222222",cursor:"pointer",textAlign:"left"},children:[W.jsx("span",{style:{width:"26px",height:"26px",flexShrink:0,display:"grid",placeItems:"center",border:"1px solid #e5e5e5",borderRadius:"6px",backgroundColor:"#f7f7f7",color:"#666666"},children:J}),W.jsxs("span",{style:{minWidth:0,flex:1},children:[W.jsx("span",{style:{display:"block",overflow:"hidden",fontSize:"13px",fontWeight:400,lineHeight:1.25,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:W.jsx(FrB,{text:S.label,query:g})}),S.detail&&W.jsx("span",{style:{display:"block",overflow:"hidden",marginTop:"2px",color:"#777777",fontSize:"11px",lineHeight:1.2,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:S.detail}),S.schematicSheetName&&W.jsxs("span",{style:{display:"block",overflow:"hidden",marginTop:"2px",color:"#777777",fontSize:"11px",lineHeight:1.2,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Sheet: ",S.schematicSheetName]})]}),R&&W.jsx("span",{title:"Press Enter to open",style:{flexShrink:0,color:"#666666",fontSize:"17px",lineHeight:1},children:W.jsx(NrB,{size:14,strokeWidth:1.8})})]},S.target.id)})]});return W.jsx("div",{"data-schematic-search":!0,onPointerDown:p=>p.stopPropagation(),onMouseDown:p=>p.stopPropagation(),onTouchStart:p=>p.stopPropagation(),onTouchEnd:p=>p.stopPropagation(),style:{position:"relative",zIndex:gS.schematicSearch,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif'},children:o?W.jsxs("div",{onKeyDown:G,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:[W.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",height:"32px",boxSizing:"border-box",padding:"0 12px",borderBottom:u},children:[W.jsx(mNI,{size:15,strokeWidth:2}),W.jsx("input",{ref:s,value:g,"aria-label":"Search components and nets",placeholder:"Search...",onPointerUp:p=>p.currentTarget.focus(),onChange:p=>A(p.target.value),style:{minWidth:0,flex:1,border:"none",outline:"none",fontSize:"13px",color:"#222222",background:"transparent"}}),g&&e.length>0?W.jsx("span",{style:{flexShrink:0,color:"#888888",fontSize:"12px",whiteSpace:"nowrap"},children:w}):W.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:a}),o&&W.jsx("button",{type:"button","aria-label":"Clear search",onPointerUp:p=>{p.button===0&&c()},onClick:p=>{p.detail===0&&c()},style:{border:"none",background:"transparent",color:"#777777",cursor:"pointer",width:"20px",height:"20px",display:"grid",placeItems:"center",padding:0,lineHeight:1},children:W.jsx(SrB,{size:16,strokeWidth:2})})]}),g&&W.jsx("div",{ref:r,style:{maxHeight:"240px",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",scrollBehavior:"smooth",touchAction:"pan-y",WebkitOverflowScrolling:"touch"},onWheel:p=>p.stopPropagation(),onTouchMove:p=>p.stopPropagation(),children:e.length===0?W.jsx("div",{style:{padding:"12px",color:"#777777",fontSize:"13px"},children:"No matching components or nets"}):W.jsxs(W.Fragment,{children:[m("components",l),m("nets",D)]})})]}):W.jsx("button",{type:"button",title:"Search schematic","aria-label":"Search schematic",onPointerDown:p=>{p.stopPropagation(),p.pointerType!=="mouse"&&h(!1)},onPointerUp:p=>{p.pointerType==="mouse"&&p.button===0&&h(!0)},onClick:p=>{p.detail===0&&h(!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:W.jsx(mNI,{size:16,strokeWidth:2})})})},qeg='system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',JrB={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:qeg,outline:"none",zIndex:gS.viewMenu},KrB={display:"flex",alignItems:"center",gap:8,padding:"7px 10px 7px 8px",borderRadius:6,cursor:"pointer",outline:"none",userSelect:"none",color:"#111111",fontSize:13,fontFamily:qeg},PrB={width:16,height:16,flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center",color:"#111111"},pNI={overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},LrB=`
|
|
5609
|
+
`;return gE("style",{},[xR(g)])}function eNI(g,A){const I=g[A];if(typeof I=="string")return I}function IaB(g,A,I,e){const B=[4,8],o=B.map(s=>rB(s)).join(" "),Q=B.reduce((s,r)=>s+r,0)/3,i=[];g.forEach((s,r)=>{if(s.points.length===0)return;const a=[];s.points.forEach((d,y)=>{const w=rB(I(d.timeMs)),u=rB(e(d.displayValue));a.push(`${y===0?"M":"L"} ${w} ${u}`)});const c={class:"simulation-line",d:a.join(" "),stroke:s.color,"clip-path":`url(#${A})`,[zRI(s.graph)]:xeg(s.graph)};s.graph.source_component_id&&(c["data-source-component-id"]=s.graph.source_component_id);const h=eNI(s.graph,"source_probe_id");h&&(c["data-source-probe-id"]=h);const l=eNI(s.graph,"source_probe_name");l&&(c["data-source-probe-name"]=l),s.graph.subcircuit_connectivity_map_key&&(c["data-subcircuit-connectivity-map-key"]=s.graph.subcircuit_connectivity_map_key);const D=s.points.map(d=>{const y=rB(I(d.timeMs)),w=rB(e(d.displayValue));return gE("circle",{class:"simulation-point",cx:y,cy:w,r:"2.5",fill:s.color,"clip-path":`url(#${A})`})});i.push({entry:s,graphIndex:r,pathAttributes:c,pointElements:D})});const E=[];for(let s=0;s<3;s++)for(const r of i){const a=(r.graphIndex+s)%3,c=rB(a*Q);E.push(gE("path",{...r.pathAttributes,"stroke-dasharray":o,"stroke-dashoffset":c}))}const n=i.flatMap(s=>s.pointElements);return gE("g",{class:"data-series"},[...E,...n])}function eaB(g,A){return g?.name?gE("text",{class:"chart-title",x:rB(A/2),y:rB(Fl.top-40),"text-anchor":"middle"},[xR(g.name)]):null}var tNI=16;function taB(g,A,I,e){const t=e.map((B,o)=>gE("tspan",{x:"20",dy:o===0?"0":String(tNI)},[xR(B)]));return gE("g",{class:"legend-item",transform:`translate(${rB(A)} ${rB(I)})`},[gE("line",{class:"legend-line",x1:"0",y1:"0",x2:"16",y2:"0",stroke:g.color}),gE("text",{class:"legend-label",x:"20",y:"0","dominant-baseline":"middle"},t)])}var BaB=15;function oaB(g){const A=g.split("_");if(A.length<=1)return[g];const I=[];let e=A[0]??"";for(let t=1;t<A.length;t++){const B=A[t]??"",o=`${e}_${B}`;o.length>BaB?(I.push(e),e=B):e=o}return e&&I.push(e),I}var CaB=24;function QaB(g,A){let I=Fl.top;const e=g.map(t=>{const B=A-Fl.right+10,o=oaB(t.label),C=taB(t,B,I,o),Q=o.length*tNI;return I+=Math.max(Q,CaB),C});return gE("g",{class:"legend"},e)}var f5=118,DuA=94,aZ=18;function BNI(g,A){const I=Math.floor((A+aZ)/(f5+aZ)),e=Math.max(1,Math.min(I,g)),t=Math.max(1,Math.ceil(g/e)),B=e*f5+(e-1)*aZ,o=t*DuA+(t-1)*aZ;return{columns:e,rows:t,x:Math.max(0,(A-B)/2),height:o}}var duA=20,Jeg=8,iaB=14;function EaB(g,A,I){const e=BNI(g.length,A),t=[];for(const[B,o]of g.entries()){const C=B%e.columns,Q=Math.floor(B/e.columns);t.push(naB(o,B,e.x+C*(f5+aZ),I+Neg+Q*(DuA+aZ)))}return gE("g",{class:"scope-legend"},t)}function naB(g,A,I,e){const t=g.scopeTraceDisplay,B=lk(g.graph)?"A":"V",o=t&&heA(t)?Ueg(t.valuePerDiv,B):`1 ${B}`,C=Ueg(t?.center??0,B),Q=qsB(t?.offsetDivs??0),i=`Ch${A+1}`,n=[g.label===i?void 0:g.label,`${o}/div`,Q,C].filter(r=>!!r),s=n.length>1?(DuA-duA-Jeg*2-iaB)/(n.length-1):0;return gE("g",{class:"scope-channel",transform:`translate(${rB(I)} ${rB(e)})`,[zRI(g.graph)]:xeg(g.graph)},[gE("rect",{class:"scope-channel-card",x:"0",y:"0",width:rB(f5),height:rB(DuA),rx:"6",ry:"6"}),gE("rect",{x:"0",y:"0",width:rB(f5),height:rB(duA),rx:"6",ry:"6",fill:g.color}),gE("rect",{x:"0",y:rB(duA-6),width:rB(f5),height:"6",fill:g.color}),gE("text",{class:"scope-channel-header-text",x:rB(f5/2),y:"14","text-anchor":"middle"},[xR(i)]),...n.map((r,a)=>gE("text",{class:"scope-channel-detail",x:rB(Jeg),y:rB(duA+Jeg+a*s),"dominant-baseline":"hanging"},[xR(r)]))])}function saB(g){const A=Math.ceil(g/2),I=Math.floor(g/2);return{left:oNI(A),right:oNI(I)}}function oNI(g){if(g<=1)return 0;const A=10+(g-1)*Feg+6+_sB+bsB;return Math.max(0,A-Fl.left)}function CNI(g){return g.type==="simulation_transient_voltage_graph"||g.type==="simulation_transient_current_graph"||g.type==="simulation_dc_operating_point_voltage"||g.type==="simulation_dc_operating_point_current"||g.type==="simulation_dc_sweep_voltage_graph"||g.type==="simulation_dc_sweep_current_graph"||g.type==="simulation_ac_sweep_voltage_graph"||g.type==="simulation_ac_sweep_current_graph"}function QNI(g){return g?.type==="simulation_experiment"}function aaB(g){return g?.type==="simulation_voltage_probe"}function raB(g){return g?.type==="simulation_current_probe"}function caB(g){return g?.type==="simulation_oscilloscope_trace"}function haB(g,A){const I=DaB(g),e=XRI(g),t=Math.min(I.length,e.length),B=[],o=laB(A);for(let C=0;C<t;C++){const Q=Number(I[C]??Number.NaN),i=Number(e[C]??Number.NaN);!Number.isFinite(Q)||!Number.isFinite(i)||B.push({timeMs:Q,rawValue:i,displayValue:o(i)})}return B}function laB(g){if(!heA(g))return t=>t;const A=g.center??0,I=g.offsetDivs??0,e=g.valuePerDiv;return t=>I+(t-A)/e}function DaB(g){const A=XRI(g);if(Array.isArray(g.timestamps_ms)&&g.timestamps_ms.length===A.length)return g.timestamps_ms.map(B=>Number(B));const I=A.length;if(I===0)return[];const e=[];for(let B=0;B<I;B++)e.push(g.start_time_ms+g.time_per_step*B);const t=e.length>0?e[e.length-1]:void 0;return t!==void 0&&Number.isFinite(g.end_time_ms)&&Number.isFinite(t)&&Math.abs(t-g.end_time_ms)>g.time_per_step/2&&e.push(g.end_time_ms),e}function yuA(g,A){const I=g[A];if(typeof I=="string")return I}function daB(g,A,I,e){const t=lk(g)?"I":"V";if(I?.displayName)return I.displayName;if(g.simulation_parameter_sweep_coordinate&&g.name)return g.name;if(A?.name)return`${t}(${A.name})`;const B=yuA(g,"source_probe_name");if(B)return`${t}(${B})`;if(g.source_component_id){const o=e.get(g.source_component_id);if(o)return`${t}(${o})`}return g.name?g.name:g.source_component_id?`Probe ${g.source_component_id}`:xeg(g)}function yaB(g,A,I,e,t,B){if(lk(g)){const Q=e.get(g.simulation_transient_current_graph_id);if(Q)return Q;const i=yuA(g,"source_probe_id")??(A?.type==="simulation_current_probe"?A.simulation_current_probe_id:void 0);return i?B.get(i):void 0}const o=I.get(g.simulation_transient_voltage_graph_id);if(o)return o;const C=yuA(g,"source_probe_id")??(A?.type==="simulation_voltage_probe"?A.simulation_voltage_probe_id:void 0);return C?t.get(C):void 0}function waB(g,A,I,e,t){const B=yuA(g,"source_probe_id");if(B){const o=lk(g)?I.get(B):A.get(B);if(o)return o}if(g.source_component_id)return lk(g)?t.get(g.source_component_id):e.get(g.source_component_id)}function uaB(g,A){if(A)return{displayName:A.display_name,color:A.color,center:A.display_center_value,offsetDivs:A.display_center_offset_divs,valuePerDiv:lk(g)?A.amps_per_div:A.volts_per_div}}function GaB(g,A){const I=Array.isArray(kh.simulation_palette)?kh.simulation_palette:Array.isArray(kh.palette)?kh.palette:[],e=A.filter(aaB),t=A.filter(raB),B=A.filter(caB),o=new Map,C=new Map,Q=new Map,i=new Map,E=new Map,n=new Map,s=new Map,r=new Map,a=new Map,c=new Map,h=new Map,l=new Map;for(const D of B)D.simulation_transient_voltage_graph_id&&a.set(D.simulation_transient_voltage_graph_id,D),D.simulation_transient_current_graph_id&&c.set(D.simulation_transient_current_graph_id,D),D.simulation_voltage_probe_id&&h.set(D.simulation_voltage_probe_id,D),D.simulation_current_probe_id&&l.set(D.simulation_current_probe_id,D);for(const D of e)E.set(D.simulation_voltage_probe_id,D),D.name&&D.source_component_id&&o.set(D.source_component_id,D.name),D.color&&D.source_component_id&&C.set(D.source_component_id,D.color),D.source_component_id&&s.set(D.source_component_id,D);for(const D of t)n.set(D.simulation_current_probe_id,D),D.name&&D.source_component_id&&Q.set(D.source_component_id,D.name),D.color&&D.source_component_id&&i.set(D.source_component_id,D.color),D.source_component_id&&r.set(D.source_component_id,D);return g.map((D,d)=>{const y=waB(D,E,n,s,r),w=yaB(D,y,a,c,h,l),u=uaB(D,w),G=haB(D,u),m=maB(I,d),p=paB(D,y,lk(D)?i:C),k=D.color??u?.color??p??m,S=daB(D,y,u,lk(D)?Q:o);return{graph:D,points:G,color:k,label:S,scopeTraceDisplay:u,usesScopeTraceDisplay:heA(u)}}).filter(D=>D.points.length>0)}function maB(g,A){return g.length===0?jRI:g[A%g.length]??jRI}function paB(g,A,I){if(A?.color)return A.color;if(g.source_component_id)return I.get(g.source_component_id)}function iNI({circuitJson:g,simulation_experiment_id:A,simulation_transient_current_graph_ids:I,simulation_transient_voltage_graph_ids:e,simulation_result_ids:t,ac_sweep_view:B="magnitude",width:o=LsB,height:C=YsB,includeVersion:Q}){const i=e?new Set(e):null,E=I?new Set(I):null,n=!!(i||E),s=t?new Set(t):null,r=g.find(O=>QNI(O)&&O.simulation_experiment_id===A),a=g.filter(O=>CNI(O)&&O.simulation_experiment_id===A&&(!s||s.has(VRI(O)))&&(!n||O.type==="simulation_transient_voltage_graph"&&(i?.has(O.simulation_transient_voltage_graph_id)??!1)||O.type==="simulation_transient_current_graph"&&(E?.has(O.simulation_transient_current_graph_id)??!1))),c=PsB({results:a,acSweepView:B,experiment:r}),h=c.graphs;if(h.length===0)throw new Error(`No simulation analysis results found for simulation_experiment_id "${A}"`);const l=GaB(h,g),D=l.flatMap(O=>O.points);if(D.length===0)throw new Error(`Simulation results for simulation_experiment_id "${A}" do not contain any datapoints`);const d=D.map(O=>O.timeMs);let y;c.usesLogarithmicXValues?y=kaB(d):c.xAxisTitle==="Time (ms)"?y=WsB({values:d,graphs:h,experiment:r}):y=huA(d);const w=huA(D.map(O=>O.displayValue),!0),u=l.some(O=>O.usesScopeTraceDisplay),G=u?saB(l.length):{left:0,right:0},m=o+G.left+G.right,p=u?BNI(l.length,m):null,k=p?C+Neg+p.height+Neg:C,S=Math.max(1,o-Fl.left-Fl.right),R=Math.max(1,C-Fl.top-Fl.bottom),x=Fl.left+G.left,N=INI(y.domainMin,y.domainMax,x,x+S),J=INI(w.domainMin,w.domainMax,Fl.top+R,Fl.top),L=vsB(A),b=BuA(g),H=ouA,q=eaB(r,m),j=[gaB(),zsB(m,k),XsB(L,x,S,R),AaB(x,S,R),$sB({timeAxis:y,valueAxis:w,scaleX:N,scaleY:J,plotLeft:x,plotWidth:S,plotHeight:R}),IaB(l,L,N,J),OsB({timeAxis:y,valueAxis:w,graphs:l,scaleX:N,scaleY:J,plotLeft:x,plotWidth:S,plotHeight:R,yAxisTitle:c.yAxisTitle??HsB(l),xAxisTitle:c.xAxisTitle,usesScopeTraceDisplay:u}),u?EaB(l,m,C):QaB(l,m),...q?[q]:[]],Z=gE("svg",{xmlns:"http://www.w3.org/2000/svg",width:m.toString(),height:k.toString(),style:`background-color: ${kh.schematic.background}`,viewBox:`0 0 ${rB(m)} ${rB(k)}`,"data-simulation-experiment-id":A,...r?.name&&{"data-simulation-experiment-name":r.name},...b&&{"data-software-used-string":b},...Q&&{"data-circuit-to-svg-version":H}},j);return XwA(Z)}var kaB=g=>{const A=huA(g);return{...A,tickLabelOverrides:new Map(A.ticks.map(I=>[I,rB(10**I)]))}},MaB=1200,SaB=1200,ENI=.55;function faB({circuitJson:g,simulation_experiment_id:A,simulation_transient_current_graph_ids:I,simulation_transient_voltage_graph_ids:e,simulation_result_ids:t,ac_sweep_view:B,width:o=MaB,height:C=SaB,schematicHeightRatio:Q=ENI,schematicOptions:i,includeVersion:E,graphAboveSchematic:n=!1,showErrorsInTextOverlay:s}){const r=g.filter(J=>!QNI(J)&&!CNI(J)),a=NaB(Q),c=Math.max(1,C*a),h=Math.max(1,C-c),l=c+h,D=l===0?1:C/l,d=c*D,y=h*D,w=ZRI(r,{...i,width:o,height:d,includeVersion:!1,showErrorsInTextOverlay:s}),u=iNI({circuitJson:g,simulation_experiment_id:A,simulation_transient_current_graph_ids:I,simulation_transient_voltage_graph_ids:e,simulation_result_ids:t,ac_sweep_view:B,width:o,height:y,includeVersion:!1}),G=pRI(LW(w)),m=pRI(LW(u)),p=RaB(m)??{width:o,height:y},k=p.width>0?o*(p.height/p.width):y,S=d+k,R=[];n?(R.push(iuA(m,0,0,o,k)),R.push(iuA(G,0,k,o,d))):(R.push(iuA(G,0,0,o,d)),R.push(iuA(m,0,d,o,k)));const x=BuA(r),N={name:"svg",type:"element",value:"",attributes:{xmlns:"http://www.w3.org/2000/svg",width:b2(o),height:b2(S),viewBox:`0 0 ${b2(o)} ${b2(S)}`,"data-simulation-experiment-id":A,...x&&{"data-software-used-string":x},...E&&{"data-circuit-to-svg-version":ouA}},children:R};return XwA(N)}function RaB(g){const A=g.attributes?.viewBox;if(typeof A!="string")return null;const I=A.trim().split(/[\s,]+/).map(B=>Number.parseFloat(B));if(I.length!==4)return null;const e=I.at(2),t=I.at(3);return!Number.isFinite(e)||!Number.isFinite(t)||e===void 0||t===void 0||e<=0||t<=0?null:{width:e,height:t}}function NaB(g){return Number.isFinite(g)?g<=0?0:g>=1?1:g:ENI}var nNI=({initialTransform:g,initialTouch1:A,initialTouch2:I,finalTouch1:e,finalTouch2:t})=>{if(!e||!t)return g;const B={x:(A.x+I.x)/2,y:(A.y+I.y)/2},o={x:(e.x+t.x)/2,y:(e.y+t.y)/2},C=Math.hypot(I.x-A.x,I.y-A.y),Q=Math.hypot(t.x-e.x,t.y-e.y),i=C===0?1:Q/C,E=o.x-B.x,n=o.y-B.y;return Sc(Bi(E,n),Bi(B.x,B.y),Lu(i,i),Bi(-B.x,-B.y),g)},leA=(g={})=>{const A=gA.useRef(null),[I,e]=gA.useState(0),t=g.canvasElm??A.current,[B,o]=gA.useState(g.initialTransform??R4()),[C,Q]=gA.useState(0),[i,E]=gA.useReducer(d=>d+1,0),n=gA.useCallback(d=>{g.onSetTransform&&g.onSetTransform(d),g.transform||o(d)},[g.onSetTransform,o]),s=gA.useCallback(d=>{n(d),E()},[n]),r=g.transform??B,a=gA.useCallback(()=>{e(Date.now())},[]),c=gA.useRef("none"),h=gA.useRef(null),l=gA.useRef(null);gA.useEffect(()=>{const d=g.canvasElm??A.current;if(d&&!t){Q(C+1);return}if(!d){const b=setTimeout(()=>{Q(C+1)},100);return()=>clearTimeout(b)}let y=g.transform??B,w={x:0,y:0},u={x:0,y:0},G=!1;const m=b=>({x:b.pageX-d.getBoundingClientRect().left-window.scrollX,y:b.pageY-d.getBoundingClientRect().top-window.scrollY});function p(b){g.enabled!==!1&&(g.shouldDrag&&!g.shouldDrag(b)||(w=m(b),!(Date.now()-I<100)&&(G=!0,b.preventDefault())))}function k(b){if(!G||g.enabled===!1||g.shouldDrag&&!g.shouldDrag(b))return;u=m(b);const H=Sc(Bi(u.x-w.x,u.y-w.y),y);n(H),y=H,G=!1}function S(b){if(m(b),!G||g.enabled===!1||g.shouldDrag&&!g.shouldDrag(b))return;u=m(b);const H=Sc(Bi(u.x-w.x,u.y-w.y),y);n(H)}function R(b){if(g.enabled===!1||g.shouldDrag&&!g.shouldDrag(b))return;const H=m(b),q=Sc(Bi(H.x,H.y),Lu(1-b.deltaY/1e3,1-b.deltaY/1e3),Bi(-H.x,-H.y),y);n(q),y=q,b.preventDefault()}function x(b){if(!G||g.shouldDrag&&!g.shouldDrag(b))return;if(d){const q=d.getBoundingClientRect();if(b.clientX>=q.left+10&&b.clientX<=q.right-10&&b.clientY>=q.top+10&&b.clientY<=q.bottom-10)return}G=!1,u=m(b);const H=Sc(Bi(u.x-w.x,u.y-w.y),y);n(H),y=H}function N(b){if(b.preventDefault(),g.enabled!==!1){if(b.touches.length===1){c.current="drag";const H=b.touches[0];h.current={initialTransform:y,initialTouch:{x:H.clientX,y:H.clientY}}}else if(b.touches.length===2){c.current="pinch";const H=b.touches[0],q=b.touches[1];l.current={initialTransform:y,initialTouch1:{x:H.clientX,y:H.clientY},initialTouch2:{x:q.clientX,y:q.clientY},finalTouch1:null,finalTouch2:null}}}}function J(b){if(b.preventDefault(),g.enabled!==!1){if(c.current==="drag"&&b.touches.length===1&&h.current){const H=b.touches[0],q={x:H.clientX,y:H.clientY},j=q.x-h.current.initialTouch.x,Z=q.y-h.current.initialTouch.y,O=Sc(Bi(j,Z),h.current.initialTransform);n(O)}else if(c.current==="pinch"&&b.touches.length===2&&l.current){const H=b.touches[0],q=b.touches[1];l.current.finalTouch1={x:H.clientX,y:H.clientY},l.current.finalTouch2={x:q.clientX,y:q.clientY};const j=nNI(l.current);n(j)}}}function L(b){b.preventDefault();const H=b.changedTouches[0];if(c.current==="drag"&&h.current&&H){const q={x:H.clientX,y:H.clientY},j=q.x-h.current.initialTouch.x,Z=q.y-h.current.initialTouch.y,O=Sc(Bi(j,Z),h.current.initialTransform);n(O),y=O}else if(c.current==="pinch"&&l.current){const q=nNI(l.current);n(q),y=q}c.current="none",h.current=null,l.current=null}return d.addEventListener("mousedown",p),d.addEventListener("mouseup",k),window.addEventListener("mousemove",S),d.addEventListener("mouseout",x),d.addEventListener("wheel",R),d.addEventListener("touchstart",N,{passive:!1}),d.addEventListener("touchmove",J,{passive:!1}),d.addEventListener("touchend",L,{passive:!1}),d.addEventListener("touchcancel",L,{passive:!1}),()=>{d.removeEventListener("mousedown",p),d.removeEventListener("mouseup",k),window.removeEventListener("mousemove",S),d.removeEventListener("mouseout",x),d.removeEventListener("wheel",R),d.removeEventListener("touchstart",N),d.removeEventListener("touchmove",J),d.removeEventListener("touchend",L),d.removeEventListener("touchcancel",L)}},[t,C,i,I,g.enabled,g.shouldDrag]);const D=gA.useCallback(d=>PI(r,d),[r]);return{ref:A,transform:r,applyTransformToPoint:D,setTransform:s,cancelDrag:a}},sNI=leA;function Keg(g){const A=yM(g),I=new Map;for(const o of A.schematic_component.list())o.source_component_id&&I.set(o.source_component_id,o.schematic_component_id);const e=new Map;for(const o of A.source_trace.list()){const C=o.subcircuit_connectivity_map_key;if(C)for(const Q of o.connected_source_port_ids??[]){const i=I.get(A.source_port.get(Q)?.source_component_id??"");i&&(e.has(i)||e.set(i,new Set),e.get(i).add(C))}}const t=new Map;for(const o of A.schematic_net_label.list()){if(!o.source_net_id)continue;const C=A.source_net.get(o.source_net_id)?.subcircuit_connectivity_map_key??o.source_net_id;t.set(o.schematic_net_label_id,C)}const B=new Map;for(const o of A.schematic_text.list()){if(!o.source_trace_id)continue;const C=A.source_trace.get(o.source_trace_id)?.subcircuit_connectivity_map_key;C&&B.set(o.schematic_text_id,C)}return{componentIdToKeys:e,netLabelIdToKey:t,textIdToKey:B}}var wuA=(g,A)=>Math.hypot(g.x-A.x,g.y-A.y),aNI=(g,A,I)=>{const e=I.x-A.x,t=I.y-A.y,B=e*e+t*t,o=B?Math.max(0,Math.min(1,((g.x-A.x)*e+(g.y-A.y)*t)/B)):0;return wuA(g,{x:A.x+o*e,y:A.y+o*t})},R5=(g,A,I)=>Math.abs(wuA(A,g)+wuA(g,I)-wuA(A,I))<1e-5;function FaB(g,A){const I=Keg(A),e=g?.closest("[data-subcircuit-connectivity-map-key], [data-schematic-net-label-id], [data-schematic-text-id], [data-schematic-trace-id]");if(!e)return;const t=A.find(B=>B.type==="schematic_trace"&&B.schematic_trace_id===e.getAttribute("data-schematic-trace-id"));return e.getAttribute("data-subcircuit-connectivity-map-key")||I.netLabelIdToKey.get(e.getAttribute("data-schematic-net-label-id"))||I.textIdToKey.get(e.getAttribute("data-schematic-text-id"))||(t?.type==="schematic_trace"?t.subcircuit_connectivity_map_key||A.filter(B=>B.type==="source_trace").find(B=>B.source_trace_id===t.source_trace_id)?.subcircuit_connectivity_map_key:void 0)}function xaB(g,A){const I=Keg(g),e=g.filter(n=>n.type==="source_trace"),t=g.filter(n=>n.type==="schematic_trace"),B=g.filter(n=>n.type==="schematic_sheet"),o=B[0]?.schematic_sheet_id,C=[];for(const n of t)if((n.subcircuit_connectivity_map_key??e.find(r=>r.source_trace_id===n.source_trace_id)?.subcircuit_connectivity_map_key)===A)for(const r of n.edges)C.push({a:r.from,b:r.to,sheet:n.schematic_sheet_id??o,target:{type:"schematic_trace",id:n.schematic_trace_id},sourceTraceId:n.source_trace_id,portIds:[r.from_schematic_port_id,r.to_schematic_port_id].filter(a=>!!a),junctions:n.junctions});for(const n of g)if(n.type==="schematic_net_label"&&I.netLabelIdToKey.get(n.schematic_net_label_id)===A){const s=n.anchor_position??n.center;C.push({a:s,b:s,sheet:n.schematic_sheet_id??o,target:{type:"schematic_net_label",id:n.schematic_net_label_id},name:n.text})}for(const n of g){if(n.type!=="schematic_text"||I.textIdToKey.get(n.schematic_text_id)!==A)continue;const s=n.schematic_sheet_id??o,a=C.filter(c=>c.sheet===s&&c.sourceTraceId===n.source_trace_id).sort((c,h)=>aNI(n.position,c.a,c.b)-aNI(n.position,h.a,h.b))[0]?.a??n.position;C.push({a,b:a,sheet:s,target:{type:"schematic_text",id:n.schematic_text_id},name:n.text})}const Q=C.map((n,s)=>s),i=n=>Q[n]===n?n:Q[n]=i(Q[n]);for(let n=0;n<C.length;n++)for(let s=0;s<n;s++){const r=C[n],a=C[s];r.sheet===a.sheet&&(R5(r.a,a.a,a.b)||R5(r.b,a.a,a.b)||R5(a.a,r.a,r.b)||R5(a.b,r.a,r.b)||[...r.junctions??[],...a.junctions??[]].some(c=>R5(c,r.a,r.b)&&R5(c,a.a,a.b)))&&(Q[i(n)]=i(s))}const E=new Map;return C.forEach((n,s)=>E.set(i(s),[...E.get(i(s))??[],n])),[...E.values()].map((n,s)=>{const r=n.find(D=>D.target.type!=="schematic_trace")??n[0],c=g.filter(D=>D.type==="schematic_port").filter(D=>(D.schematic_sheet_id??o)===r.sheet&&n.some(d=>d.portIds?.includes(D.schematic_port_id)||R5(D.center,d.a,d.b))).map(D=>{const d=g.find(w=>w.type==="source_port"&&w.source_port_id===D.source_port_id);if(d?.type!=="source_port")return;const y=g.find(w=>w.type==="source_component"&&w.source_component_id===d.source_component_id);return y?.type==="source_component"?`${y.name}.${d.name??`pin${d.pin_number}`}`:void 0}).filter(D=>!!D).sort(),h=B.findIndex(D=>D.schematic_sheet_id===r.sheet);return{kind:"net",label:`${B[h]?.name??`Sheet ${Math.max(0,h)+1}`}: ${c[0]??r.name??`Location ${s+1}`}`,schematicSheetId:r.sheet,target:r.target,focusPoint:{x:(r.a.x+r.b.x)/2,y:(r.a.y+r.b.y)/2}}})}var UaB={async load(){const g=await FQB("@tscircuit/circuit-json-schematic-placement-analysis");if(typeof g.createSchematicPlacementIssueArtifacts!="function")throw new Error("The style analyzer module does not export its analysis function.");return g}},gS={contextMenu:110,styleAnalysis:120,viewMenu:110,viewMenuIcon:48,clickToInteractOverlay:100,schematicComponentDetailsTooltip:105,schematicComponentHoverOutline:47,schematicPortHoverOutline:48,schematicSearch:101},JaB=({circuitJson:g,onClose:A})=>{const[I,e]=gA.useState({status:"loading"});return gA.useEffect(()=>{let t=!1;e({status:"loading"});const B=window.setTimeout(async()=>{try{const{createSchematicPlacementIssueArtifacts:o}=await UaB.load();if(t)return;const C=o(g);t||e({status:"complete",artifacts:C})}catch(o){t||e({status:"error",message:o instanceof Error?o.message:String(o)})}},0);return()=>{t=!0,window.clearTimeout(B)}},[g]),W.jsx(Beg,{open:!0,onOpenChange:t=>!t&&A(),children:W.jsxs(oeg,{children:[W.jsx(vwA,{style:{position:"fixed",inset:0,background:"#0008",zIndex:gS.styleAnalysis}}),W.jsxs(qwA,{style:{position:"fixed",top:"5vh",left:"50%",transform:"translateX(-50%)",width:"min(1000px, 94vw)",maxHeight:"90vh",overflowY:"auto",boxSizing:"border-box",padding:24,borderRadius:12,background:"#fafafa",color:"#171717",fontFamily:"system-ui, sans-serif",boxShadow:"0 20px 60px #0005",zIndex:gS.styleAnalysis},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:16},children:[W.jsx(TwA,{style:{margin:0,fontSize:22},children:"Style Analysis"}),W.jsx(Qeg,{style:{cursor:"pointer",padding:"6px 12px"},children:"Close"})]}),W.jsx(ZwA,{style:{color:"#525252"},children:"Placement and style issues across all schematic sheets. Each image highlights one issue with its description below."}),I.status==="loading"&&W.jsx("p",{role:"status",children:"Running style analysis…"}),I.status==="error"&&W.jsxs("p",{role:"alert",children:["Style analysis failed: ",I.message]}),I.status==="complete"&&W.jsxs(W.Fragment,{children:[W.jsx("p",{role:"status",children:I.artifacts.length===0?"No style issues found.":`${I.artifacts.length} style ${I.artifacts.length===1?"issue":"issues"} found.`}),I.artifacts.map(t=>W.jsxs("section",{style:{marginTop:24,border:"1px solid #ddd",borderRadius:8,overflow:"hidden",background:"white"},children:[W.jsxs("h3",{style:{margin:16,fontSize:16},children:[t.issueIndex+1,"."," ",t.issue.lineItemType.replace(/([a-z])([A-Z])/g,"$1 $2"),t.schematicSheetId&&W.jsxs("small",{style:{display:"block",marginTop:4,color:"#525252"},children:["Sheet: ",t.schematicSheetId]})]}),W.jsx("img",{src:`data:image/svg+xml;charset=utf-8,${encodeURIComponent(t.content)}`,alt:t.descriptionXml,loading:"lazy",style:{display:"block",width:"100%",height:"auto"}})]},t.issueIndex))]})]})]})})},rZ={IS_SHOWING_SCHEMATIC_GROUPS:"schematic_viewer_show_groups",IS_SHOWING_SCHEMATIC_PORTS:"schematic_viewer_show_ports",SELECTED_SCHEMATIC_SHEET:"schematic_viewer_selected_sheet"},rNI=(g,A)=>{if(typeof window>"u")return A;try{const I=localStorage.getItem(g);return I!==null?JSON.parse(I):A}catch{return A}},cNI=(g,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(g,JSON.stringify(A))}catch{}},KaB=g=>{if(typeof window>"u")return null;try{return localStorage.getItem(g)}catch{return null}},PaB=(g,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(g,A)}catch{}},hNI=["#8B0000","#2F4F4F","#191970","#006400","#FF4500","#800080","#2E8B57","#B8860B","#C71585","#008B8B"],LaB=g=>{const{svgDivRef:A,circuitJson:I,circuitJsonKey:e,showGroups:t}=g;gA.useEffect(()=>{if(A.current&&A.current.querySelectorAll(".schematic-group-overlay").forEach(C=>C.remove()),!A.current||!t||!I||I.length===0)return;const B=setTimeout(()=>{if(!A.current)return;const o=A.current.querySelector("svg");if(!o)return;o.querySelectorAll(".schematic-group-overlay").forEach(Q=>Q.remove());try{const Q=yM(I).source_group?.list().filter(D=>!D.is_subcircuit)||[],i=yM(I).schematic_component?.list()||[],E=new Map;Q.forEach(D=>{const d=D;if(d.parent_source_group_id){const y=E.get(d.parent_source_group_id)||[];y.push(D.source_group_id),E.set(d.parent_source_group_id,y)}});const n=D=>{const d=[],y=E.get(D)||[];for(const w of y)d.push(w),d.push(...n(w));return d},s=D=>{const d=Q.find(y=>y.source_group_id===D);return d?.parent_source_group_id?1+s(d.parent_source_group_id):0},r=Q.length>0&&Q.some(D=>D.name&&D.name.trim()!=="");let a=[];if(r){const D=new Map;for(const d of i){const y=yM(I).source_component.get(d.source_component_id);y?.source_group_id&&(D.has(y.source_group_id)||D.set(y.source_group_id,[]),D.get(y.source_group_id).push(d))}Q.forEach((d,y)=>{let w=D.get(d.source_group_id)||[];const u=n(d.source_group_id);for(const G of u){const m=D.get(G)||[];w=[...w,...m]}if(w.length>0){const G=s(d.source_group_id),m=n(d.source_group_id).length>0;if(d.name?.startsWith("unnamed_board"))return;a.push({id:d.source_group_id,name:d.name||`Group ${y+1}`,components:w,color:hNI[y%hNI.length],depthLevel:G,hasChildren:m,sourceGroupId:d.source_group_id})}})}const c=o.viewBox.baseVal,h=o.getBoundingClientRect(),l=Math.min(h.width/c.width,h.height/c.height)||1;a.sort((D,d)=>D.depthLevel-d.depthLevel),a.forEach(D=>{if(D.components.length===0)return;const d=YaB(D.components,o);if(!d)return;const y=Math.max(8,Math.min(25,15/Math.max(l,.3))),w=D.hasChildren?y*.6:0,u=y+w,G=Math.max(1,2/Math.max(l,.5)),m=D.depthLevel===0?G:G*.7,p=Math.max(4,8/Math.max(l,.5)),k=D.hasChildren?1.3:1,S=p*k,R=S*.5,x=document.createElementNS("http://www.w3.org/2000/svg","rect");x.setAttribute("class","schematic-group-overlay"),x.setAttribute("x",(d.minX-u).toString()),x.setAttribute("y",(d.minY-u).toString()),x.setAttribute("width",(d.maxX-d.minX+u*2).toString()),x.setAttribute("height",(d.maxY-d.minY+u*2).toString()),x.setAttribute("fill","none"),x.setAttribute("stroke",D.color),x.setAttribute("stroke-width",m.toString()),x.setAttribute("stroke-dasharray",`${S},${R}`),x.setAttribute("opacity","0.8"),x.setAttribute("rx","0"),x.setAttribute("ry","0");const N=Math.max(6,Math.min(20,14/Math.max(l,.2))),J=D.depthLevel===0||D.depthLevel===1?0:D.depthLevel*.2,L=N*(1-J),b=Math.max(1,L*.2),H=D.name,q=document.createElementNS("http://www.w3.org/2000/svg","text");q.setAttribute("font-size",L.toString()),q.setAttribute("font-family","Arial, sans-serif"),q.textContent=H,o.appendChild(q);const j=q.getBBox();o.removeChild(q);const Z=j.width+b*2,O=L+b*2,AA=d.minX-u,tA=d.minY-u-O,eA=document.createElementNS("http://www.w3.org/2000/svg","rect");eA.setAttribute("class","schematic-group-overlay"),eA.setAttribute("x",AA.toString()),eA.setAttribute("y",(tA-O).toString()),eA.setAttribute("width",Z.toString()),eA.setAttribute("height",O.toString()),eA.setAttribute("fill","transparent"),eA.setAttribute("rx","0"),eA.setAttribute("ry","0");const iA=document.createElementNS("http://www.w3.org/2000/svg","text");iA.setAttribute("class","schematic-group-overlay"),iA.setAttribute("x",(AA+b).toString()),iA.setAttribute("y",(tA+O-b).toString()),iA.setAttribute("fill",D.color),iA.setAttribute("font-size",L.toString()),iA.setAttribute("font-family","Arial, sans-serif"),iA.setAttribute("font-weight",D.depthLevel===0?"600":"500"),iA.setAttribute("stroke",D.color),iA.setAttribute("stroke-width",Math.max(.2,L*.02).toString()),iA.textContent=H,o.appendChild(x),o.appendChild(eA),o.appendChild(iA)})}catch(Q){console.error("Error creating group overlays:",Q)}},10);return()=>clearTimeout(B)},[A,e,t])};function YaB(g,A){let I=1/0,e=1/0,t=-1/0,B=-1/0;for(const C of g){let Q=A.querySelector(`g[data-schematic-component-id="${C.schematic_component_id}"]`);if(Q||(Q=A.querySelector(`[data-schematic-component-id="${C.schematic_component_id}"]`)),Q){const i=Q.getBBox();I=Math.min(I,i.x),e=Math.min(e,i.y),t=Math.max(t,i.x+i.width),B=Math.max(B,i.y+i.height)}}return I===1/0?null:{minX:I,minY:e,maxX:t,maxY:B}}var Peg="sch-net-faded",lNI="g.trace[data-subcircuit-connectivity-map-key], g.trace-overlays[data-subcircuit-connectivity-map-key]",Leg="[data-schematic-net-label-id], [data-schematic-text-id]",_aB=({svgDivRef:g,circuitJson:A,circuitJsonKey:I,enabled:e})=>{gA.useEffect(()=>{const t=g.current;if(!e||!t)return;const{componentIdToKeys:B,netLabelIdToKey:o,textIdToKey:C}=Keg(A);let Q=[];const i=new Map;let E=null;const n=()=>{for(const{el:l}of Q)l.classList.remove(Peg);Q=[],i.clear(),E=null;const h=t.querySelector("svg");if(h){for(const l of Array.from(h.querySelectorAll(lNI))){const D=l.getAttribute("data-subcircuit-connectivity-map-key"),d=new Set;D&&(d.add(D),i.set(l,D)),Q.push({el:l,keys:d})}for(const l of Array.from(h.querySelectorAll("g[data-schematic-component-id]"))){const D=l.getAttribute("data-schematic-component-id");Q.push({el:l,keys:B.get(D)??new Set})}for(const l of Array.from(h.querySelectorAll(Leg))){const D=o.get(l.getAttribute("data-schematic-net-label-id"))??C.get(l.getAttribute("data-schematic-text-id")),d=new Set;D&&(d.add(D),i.set(l,D)),Q.push({el:l,keys:d})}}},s=h=>{if(h!==E){E=h;for(const{el:l,keys:D}of Q)l.classList.toggle(Peg,h!==null&&!D.has(h))}},r=h=>{const l=h.target;if(!(l instanceof Element)){s(null);return}const D=l.closest(`${lNI}, ${Leg}`);if(D&&i.has(D)){s(i.get(D));return}for(const[d,y]of i){if(!d.matches(Leg))continue;const w=d.getBoundingClientRect();if(h.clientX>=w.left-6&&h.clientX<=w.right+6&&h.clientY>=w.top-6&&h.clientY<=w.bottom+6){s(y);return}}s(null)},a=()=>s(null);n(),t.addEventListener("mousemove",r),t.addEventListener("mouseleave",a);const c=new MutationObserver(n);return c.observe(t,{childList:!0}),()=>{c.disconnect(),t.removeEventListener("mousemove",r),t.removeEventListener("mouseleave",a);for(const{el:h}of Q)h.classList.remove(Peg)}},[g,I,e])},Yeg="http://www.w3.org/2000/svg",baB=({svgDivRef:g,svgContent:A,circuitJsonKey:I})=>{const e=gA.useRef(new Set);gA.useLayoutEffect(()=>{e.current.clear()},[I]),gA.useLayoutEffect(()=>{const t=[];for(const B of g.current?.querySelectorAll(".schematic-warning")??[]){const o=B.getAttribute("data-warning-id"),C=B.querySelector('[data-warning-reference="callout"]');if(!o||!C)continue;const Q=Array.from(B.children),i=Q.map(d=>d.style.display),E=B.getAttribute("role"),n=B.getAttribute("aria-label")??"Warning",s=document.createElementNS(Yeg,"g");s.setAttribute("data-warning-icon",""),s.setAttribute("aria-hidden","true"),s.setAttribute("transform",`translate(${C.getAttribute("x")} ${C.getAttribute("y")})`);const r=document.createElementNS(Yeg,"rect");r.setAttribute("width","24"),r.setAttribute("height","24"),r.setAttribute("fill",C.getAttribute("fill")??"#fffaeb"),r.setAttribute("stroke",C.getAttribute("stroke")??"#d99a00"),r.setAttribute("stroke-width","1");const a=document.createElementNS(Yeg,"text");a.setAttribute("x","12"),a.setAttribute("y","12"),a.setAttribute("dominant-baseline","central"),a.setAttribute("text-anchor","middle"),a.setAttribute("font-size","16"),a.setAttribute("font-family","sans-serif"),a.setAttribute("font-weight","bold"),a.setAttribute("fill","#5c4300"),a.textContent="!",s.append(r,a),B.append(s),B.setAttribute("role","button"),B.setAttribute("tabindex","0"),B.style.cursor="pointer",B.style.outline="none";const c=()=>{const d=e.current.has(o);Q.forEach((y,w)=>{y.style.display=d?"none":i[w]}),s.style.display=d?"":"none",B.setAttribute("aria-expanded",String(!d)),B.setAttribute("aria-label",`${d?"Expand":"Minimize"} warning: ${n}`)},h=d=>{d.preventDefault(),d.stopPropagation(),e.current.has(o)?e.current.delete(o):e.current.add(o),c()},l=d=>{(d.key==="Enter"||d.key===" ")&&(d.repeat?d.preventDefault():h(d))},D=d=>d.stopPropagation();B.addEventListener("click",h),B.addEventListener("keydown",l),B.addEventListener("mousedown",D),B.addEventListener("touchstart",D),c(),t.push(()=>{B.removeEventListener("click",h),B.removeEventListener("keydown",l),B.removeEventListener("mousedown",D),B.removeEventListener("touchstart",D),s.remove(),Q.forEach((d,y)=>{d.style.display=i[y]}),E?B.setAttribute("role",E):B.removeAttribute("role"),B.setAttribute("aria-label",n),B.removeAttribute("aria-expanded"),B.removeAttribute("tabindex"),B.style.removeProperty("cursor"),B.style.removeProperty("outline")})}return()=>t.forEach(B=>B())},[g,A,I])},_eg=g=>String(g??"").toLocaleLowerCase(),DeA=(g,A)=>{const I=_eg(g);return I===A?0:I.startsWith(A)?1:I.includes(A)?2:Number.POSITIVE_INFINITY},HaB=g=>{if(g)return String(g).replace(/^simple_/,"").replaceAll("_"," ").replace(/\b\w/g,A=>A.toLocaleUpperCase())},vaB=(g,A,I)=>{let t=HaB(g?.ftype);g?.ftype==="simple_chip"&&g.manufacturer_part_number&&(t=g.manufacturer_part_number);const B=[];g?.display_name===I&&g.name!==I&&B.push(g.name);let o=g?.display_value;if(!o&&g){for(const C of["display_resistance","display_capacitance","display_inductance","display_frequency","symbol_display_value"])if(C in g){const Q=g[C];if(typeof Q=="string"){o=Q;break}}}if(o??(o=A.symbol_display_value),t&&B.push(t),o&&B.push(o),!t&&!o&&g?.manufacturer_part_number&&B.push(g.manufacturer_part_number),B.length!==0)return B.join(" · ")},qaB=g=>g.type==="source_component"&&"source_component_id"in g,TaB=g=>g.type==="source_port",ZaB=g=>g.type==="source_trace",OaB=g=>g.type==="schematic_component",WaB=g=>g.type==="schematic_port",VaB=g=>g.type==="schematic_net_label",jaB=g=>g.type==="schematic_sheet",beg=({schematicSheets:g,schematicSheetId:A})=>{if(!(g.length<=1||!A))return g.find(I=>I.schematic_sheet_id===A)?.name},zaB=(g,A)=>{const I=_eg(A).trim();if(!I)return[];const e=new Map(g.filter(qaB).map(E=>[E.source_component_id,E])),t=new Map(g.filter(TaB).map(E=>[E.source_port_id,E])),B=g.filter(WaB),o=g.filter(ZaB),C=g.filter(jaB),Q=[],i=new Map;for(const E of g.filter(OaB)){const n=E.source_component_id?e.get(E.source_component_id):void 0,s=n?.display_name??n?.name??"Component",r=Math.min(DeA(n?.name,I),DeA(n?.display_name,I),DeA(n?.manufacturer_part_number,I));if(Number.isFinite(r)){const a={label:s,detail:vaB(n,E,s),kind:"component",schematicSheetId:E.schematic_sheet_id,schematicSheetName:beg({schematicSheets:C,schematicSheetId:E.schematic_sheet_id}),target:{type:"schematic_component",id:E.schematic_component_id}};Q.push(a),i.set(a,r)}}for(const E of g.filter(VaB)){if(!_eg(E.text).includes(I))continue;const n=new Set;for(const d of o.filter(y=>y.connected_source_net_ids.includes(E.source_net_id)))for(const y of d.connected_source_port_ids)n.add(y);const s=E.anchor_position??E.center,r=B.filter(d=>n.has(d.source_port_id)&&(!E.schematic_sheet_id||!d.schematic_sheet_id||d.schematic_sheet_id===E.schematic_sheet_id)).map(d=>({port:d,distance:Math.hypot(d.center.x-s.x,d.center.y-s.y)})).filter(({distance:d})=>d<=1).sort((d,y)=>d.distance-y.distance)[0]?.port,a=r?t.get(r.source_port_id):void 0,c=a?.source_component_id?e.get(a.source_component_id):void 0,h=a?.name??(a?.pin_number!==void 0?`pin${a.pin_number}`:r?.display_pin_label),l=c?.name&&h?`Connected to ${c.name}.${h}`:void 0,D={label:E.text,detail:l,kind:"net",schematicSheetId:E.schematic_sheet_id,schematicSheetName:beg({schematicSheets:C,schematicSheetId:E.schematic_sheet_id}),target:{type:"schematic_net_label",id:E.schematic_net_label_id}};Q.push(D),i.set(D,DeA(E.text,I))}for(const E of g){if(E.type!=="schematic_text"||!E.source_trace_id)continue;const n=DeA(E.text,I);if(!Number.isFinite(n))continue;const s={label:E.text,kind:"net",schematicSheetId:E.schematic_sheet_id,schematicSheetName:beg({schematicSheets:C,schematicSheetId:E.schematic_sheet_id}),target:{type:"schematic_text",id:E.schematic_text_id}};Q.push(s),i.set(s,n)}return Q.sort((E,n)=>(i.get(E)??Number.POSITIVE_INFINITY)-(i.get(n)??Number.POSITIVE_INFINITY)||E.label.localeCompare(n.label))},XaB=({containerRect:g,targetRect:A,visibleProjection:I,minimumScale:e})=>{const t=I.a||1,B={x:A.left+A.width/2-g.left,y:A.top+A.height/2-g.top},o={x:(B.x-I.e)/t,y:(B.y-I.f)/t},C=Math.max(t,e);return{a:C,b:0,c:0,d:C,e:g.width/2-o.x*C,f:g.height/2-o.y*C}},$aB=1.8,DNI=350,ArB=({controller:g,circuitJson:A,circuitJsonKey:I,svgDivRef:e,containerRef:t,activeSheetId:B,hasMultipleSheets:o,handleSelectSheet:C,svgString:Q,svgToScreenProjection:i,setSvgToScreenProjection:E,setIsInteractionEnabled:n})=>{const[s,r]=gA.useState(""),[a,c]=gA.useState(null),h=gA.useRef(null),l=gA.useMemo(()=>zaB(A,s),[A,I,s]),D=gA.useCallback(G=>{const m=e.current,p=t.current;if(!m||!p)return!1;const k=`data-${G.target.type.replaceAll("_","-")}-id`,S=Array.from(m.querySelectorAll(`[${k}]`)).find(L=>L.getAttribute(k)===G.target.id);if(!S)return!1;let R=S.getBoundingClientRect();if(G.focusPoint){const L=S.closest("svg"),b=L?.getAttribute("data-real-to-screen-transform"),H=L?.getScreenCTM?.();if(b&&H){const q=OI(H,OI(lfI(b),G.focusPoint));R={left:q.x-1,top:q.y-1,width:2,height:2}}}const x=p.getBoundingClientRect();if(!x.width||!x.height||!R.width&&!R.height)return!1;h.current&&clearTimeout(h.current);let N=i;const J=getComputedStyle(m).transform;if(J&&J!=="none")try{N=lfI(J),m.style.transition="none",m.style.transform=J,m.offsetWidth}catch{}return m.style.transition=`transform ${DNI}ms ease-in-out`,m.offsetWidth,E(XaB({containerRect:x,targetRect:R,visibleProjection:N,minimumScale:$aB})),h.current=setTimeout(()=>{m.style.transition=""},DNI),m.querySelectorAll(".schematic-search-match").forEach(L=>L.classList.remove("schematic-search-match")),m.querySelectorAll(`[${k}]`).forEach(L=>{L.getAttribute(k)===G.target.id&&L.classList.add("schematic-search-match")}),!0},[t,E,e,i]),d=gA.useCallback(G=>{if(n(!0),G.schematicSheetId&&G.schematicSheetId!==B&&o){C(G.schematicSheetId),c(G);return}D(G)},[B,D,C,o,n]),y=gA.useCallback(()=>{r(""),c(null),h.current&&(clearTimeout(h.current),h.current=null),e.current&&(e.current.style.transition="",e.current.querySelectorAll(".schematic-search-match").forEach(G=>G.classList.remove("schematic-search-match")))},[e]),w=g?.focusRequest,u=g?.onFocusRequestHandled;return gA.useEffect(()=>{if(!w)return;const G=A.find(m=>m.type==="schematic_component"&&m.schematic_component_id===w.schematicComponentId);if(G?.type!=="schematic_component"){c(null),u?.(w);return}n(!0),G.schematic_sheet_id&&o&&C(G.schematic_sheet_id),c({kind:"component",label:G.schematic_component_id,schematicSheetId:G.schematic_sheet_id,target:{type:"schematic_component",id:G.schematic_component_id}})},[w,u,A,I,o,C,n]),gA.useEffect(()=>{if(!a||!Q||o&&a.schematicSheetId&&a.schematicSheetId!==B)return;const G=requestAnimationFrame(()=>{D(a)&&(c(null),w?.schematicComponentId===a.target.id&&u?.(w))});return()=>cancelAnimationFrame(G)},[D,w,u,a,Q,o,B]),gA.useEffect(()=>{s||e.current?.querySelectorAll(".schematic-search-match").forEach(G=>G.classList.remove("schematic-search-match"))},[s,e]),gA.useEffect(()=>()=>{h.current&&clearTimeout(h.current)},[]),{searchQuery:s,setSearchQuery:r,searchResults:l,handleSearchResultSelect:d,handleCancelSearch:y}};ds("schematic-viewer");var grB=()=>{ds.enable("schematic-viewer*")},dNI=g=>{const[A,I]=gA.useState(0),[e,t]=gA.useState(0);return gA.useEffect(()=>{if(!g.current)return;const B=()=>{const C=g.current?.getBoundingClientRect();I(C?.width||0),t(C?.height||0)};B();const o=new ResizeObserver(B);return o.observe(g.current),window.addEventListener("resize",B),()=>{o.disconnect(),window.removeEventListener("resize",B)}},[]),{containerWidth:A,containerHeight:e}},IrB=600,uuA=10,erB=({containerRef:g})=>{const[A,I]=gA.useState(null),[e,t]=gA.useState(!1),[B,o]=gA.useState({x:0,y:0}),C=gA.useRef(null),Q=gA.useRef(null),i=gA.useRef(null),E=gA.useRef(0),n=gA.useCallback(()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null)},[]),s=gA.useCallback(l=>{if(l.preventDefault(),Date.now()<E.current)return;const D=Q.current;if(!D)return;const d=Math.abs(l.clientX-D.x)>uuA||Math.abs(l.clientY-D.y)>uuA;Q.current=null,!d&&(I(l.target instanceof Element?l.target:null),o({x:l.clientX,y:l.clientY}),t(!0))},[]),r=gA.useCallback(l=>{if(n(),l.touches.length!==1){Q.current=null;return}const D=l.touches[0];if(!D)return;const d=l.target instanceof Element?l.target:null;Q.current={x:D.clientX,y:D.clientY},i.current=window.setTimeout(()=>{const y=g.current;if(!y||!Q.current)return;I(d);const w=y.getBoundingClientRect();o({x:w.left+w.width/2,y:w.top+w.height/2}),t(!0),E.current=Date.now()+1e3,Q.current=null},IrB)},[n,g]),a=gA.useCallback(l=>{const D=Q.current;if(!D||l.touches.length!==1)return;const d=l.touches[0];(!d||Math.abs(d.clientX-D.x)>uuA||Math.abs(d.clientY-D.y)>uuA)&&(Q.current=null,n())},[n]),c=gA.useCallback(()=>{n(),Q.current=null},[n]),h=gA.useCallback(l=>{const D=l.target;C.current?.contains(D)||D.closest?.("[data-radix-popper-content-wrapper], [data-radix-dropdown-menu-content]")||t(!1)},[]);return gA.useEffect(()=>{if(e)return document.addEventListener("mousedown",h),document.addEventListener("touchstart",h),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("touchstart",h)}},[h,e]),gA.useEffect(()=>n,[n]),{menuVisible:e,menuTarget:A,menuPos:B,menuRef:C,setMenuVisible:t,contextMenuEventHandlers:{onMouseDown:l=>{Q.current=l.button===2||l.button===0&&l.ctrlKey?{x:l.clientX,y:l.clientY}:null},onContextMenu:s,onTouchStart:r,onTouchMove:a,onTouchEnd:c,onTouchCancel:c}}},trB=(g,A,I)=>g.filter(e=>{if(!e.type.endsWith("_warning"))return!1;const t=e;return[["source_component",A.source_component_id],["schematic_component",A.schematic_component_id],["pcb_component",I?.pcb_component_id]].some(([o,C])=>{if(!C)return!1;const Q=t[`${o}_ids`];return t[`${o}_id`]===C||Array.isArray(Q)&&Q.includes(C)||t.schematic_element_type===o&&t.schematic_element_id===C})}),BrB=new Set(["type","source_component_id","source_group_id","subcircuit_id","display_name","ftype","are_pins_interchangeable","supplier_part_numbers"]),yNI=["name","resistance","capacitance","inductance","frequency","voltage","current","max_voltage_rating","max_current_rating","power_rating","manufacturer_part_number"],orB={jlcpcb:g=>`https://jlcpcb.com/partdetail/${encodeURIComponent(g)}`,lcsc:g=>`https://www.lcsc.com/product-detail/${encodeURIComponent(g)}.html`},CrB=g=>{const A=g.trim(),I=/^c?(\d+)$/i.exec(A);return I?`C${I[1]}`:A},wNI=g=>{const A=yNI.indexOf(g);return A===-1?yNI.length:A},QrB=(g,A,I)=>{if(A==="name")return String(I);const e=g[`display_${A}`];if(typeof e=="string"&&e.trim()){const t=A==="resistance"?e.replace(/Ω$/,""):e;return JSON.stringify(t)}return JSON.stringify(I)??String(I)},irB=g=>Object.entries(g).filter(([A,I])=>BrB.has(A)||A.startsWith("display_")&&A.slice(8)in g?!1:I!=null&&I!=="").sort(([A],[I])=>wNI(A)-wNI(I)||A.localeCompare(I)).map(([A,I])=>({key:A,label:A,value:QrB(g,A,I)})),ErB=g=>{const A=g.supplier_part_numbers;return A?["jlcpcb","lcsc"].flatMap(I=>{const e=A[I];if(!Array.isArray(e))return[];const t=[...new Set(e.filter(B=>!!(typeof B=="string"&&B.trim())).map(CrB))];return t.length?[{key:`supplier_part_numbers.${I}`,label:I,links:t.map(B=>({partNumber:B,href:orB[I](B)}))}]:[]}):[]},nrB=(g,A)=>{const I=g.find(Q=>Q.type==="schematic_component"&&Q.schematic_component_id===A);if(!I)return null;const e=g.find(Q=>Q.type==="source_component"&&Q.source_component_id===I.source_component_id);if(!e)return null;const t=g.find(Q=>Q.type==="pcb_component"&&Q.source_component_id===e.source_component_id),B=g.find(Q=>Q.type==="cad_component"&&Q.source_component_id===e.source_component_id&&(!t||Q.pcb_component_id===t.pcb_component_id)),o=t?.footprinter_string??B?.footprinter_string,C=t?srB(g,t.pcb_component_id):null;return{schematicComponent:I,sourceComponent:e,pcbComponent:t,footprinterString:o,footprintPreviewCircuitJson:C?.circuitJson,footprintPreviewViewBox:C?.viewBox,warnings:trB(g,I,t)}},GuA=2,srB=(g,A)=>{const I=g.find(B=>B.type==="pcb_component"&&B.pcb_component_id===A);if(!I)return null;const e=ufI(I);if(!e)return null;const t={minX:e.minX-GuA,minY:e.minY-GuA,maxX:e.maxX+GuA,maxY:e.maxY+GuA};return{circuitJson:qQB(g,t),viewBox:t}},arB=(g,A)=>{const I=mnB(g,{width:320,height:240,viewport:A,backgroundColor:"#f8fafc",includeVersion:!1});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(I)}`},uNI=(g,A)=>{const I=g?.closest("[data-schematic-component-id]")?.getAttribute("data-schematic-component-id"),e=g?.closest("[data-schematic-text-id]")?.getAttribute("data-schematic-text-id"),t=g?.closest("[data-schematic-port-id]")?.getAttribute("data-schematic-port-id");if(!I&&!e&&!t)return;const B=A.find(i=>i.type==="schematic_text"&&i.schematic_text_id===e),o=A.find(i=>i.type==="schematic_port"&&!!t&&(i.schematic_port_id===t||i.source_port_id===t)),C=I??(B?.type==="schematic_text"?B.schematic_component_id:void 0)??(o?.type==="schematic_port"?o.schematic_component_id:void 0);if(!C)return;const Q=A.find(i=>i.type==="schematic_component"&&i.schematic_component_id===C);if(Q?.type==="schematic_component")return Q},rrB=(g,A)=>{const I=uNI(g,A);if(!I)return;const e=A.find(B=>B.type==="source_component"&&B.source_component_id===I.source_component_id),t=A.find(B=>B.type==="pcb_component"&&B.source_component_id===I.source_component_id);if(!(e?.type!=="source_component"||t?.type!=="pcb_component"))return{source_component_id:e.source_component_id,schematic_component_id:I.schematic_component_id,pcb_component_id:t.pcb_component_id,refdes:e.name}},Heg=gA.createContext(null),crB=5,hrB=(g,A)=>!g&&!A?!0:!g||!A?!1:g.minX===A.minX&&g.maxX===A.maxX&&g.minY===A.minY&&g.maxY===A.maxY,lrB=({children:g})=>gA.useContext(Heg)?W.jsx(W.Fragment,{children:g}):W.jsx(DrB,{children:g}),DrB=({children:g})=>{const A=gA.useRef({pointer:null,boundingBoxes:new Map,hoveringIds:new Set,subscribers:new Set,mouseDownPosition:null}),I=gA.useCallback(()=>{for(const E of A.current.subscribers)E()},[]),e=gA.useCallback(()=>{const E=A.current.pointer,n=new Set;if(E)for(const[r,a]of A.current.boundingBoxes){const c=a.bounds;c&&E.x>=c.minX&&E.x<=c.maxX&&E.y>=c.minY&&E.y<=c.maxY&&n.add(r)}const s=A.current.hoveringIds;n.size===s.size&&[...n].every(r=>s.has(r))||(A.current.hoveringIds=n,I())},[I]),t=gA.useCallback((E,n)=>{A.current.boundingBoxes.set(E,n),e()},[e]),B=gA.useCallback((E,n)=>{const s=A.current.boundingBoxes.get(E);s&&hrB(s.bounds,n.bounds)&&s.onClick===n.onClick||(A.current.boundingBoxes.set(E,n),e())},[e]),o=gA.useCallback(E=>{A.current.boundingBoxes.delete(E)&&e()},[e]),C=gA.useCallback(E=>(A.current.subscribers.add(E),()=>{A.current.subscribers.delete(E)}),[]),Q=gA.useCallback(E=>A.current.hoveringIds.has(E),[]);gA.useEffect(()=>{const E=a=>{const{clientX:c,clientY:h}=a,l=A.current.pointer;l&&l.x===c&&l.y===h||(A.current.pointer={x:c,y:h},e())},n=()=>{A.current.pointer!==null&&(A.current.pointer=null,A.current.mouseDownPosition=null,e())},s=a=>{A.current.mouseDownPosition={x:a.clientX,y:a.clientY}},r=a=>{const{clientX:c,clientY:h}=a,l=A.current.mouseDownPosition;if(l&&Math.sqrt(Math.pow(c-l.x,2)+Math.pow(h-l.y,2))>crB){A.current.mouseDownPosition=null;return}A.current.mouseDownPosition=null;for(const D of A.current.boundingBoxes.values()){const d=D.bounds;d&&c>=d.minX&&c<=d.maxX&&h>=d.minY&&h<=d.maxY&&D.onClick?.(a)}};return window.addEventListener("pointermove",E,{passive:!0}),window.addEventListener("pointerdown",E,{passive:!0}),window.addEventListener("pointerup",E,{passive:!0}),window.addEventListener("pointerleave",n),window.addEventListener("pointercancel",n),window.addEventListener("blur",n),window.addEventListener("mousedown",s,{passive:!0}),window.addEventListener("click",r,{passive:!0}),()=>{window.removeEventListener("pointermove",E),window.removeEventListener("pointerdown",E),window.removeEventListener("pointerup",E),window.removeEventListener("pointerleave",n),window.removeEventListener("pointercancel",n),window.removeEventListener("blur",n),window.removeEventListener("mousedown",s),window.removeEventListener("click",r)}},[e]);const i=gA.useMemo(()=>({registerBoundingBox:t,updateBoundingBox:B,unregisterBoundingBox:o,subscribe:C,isHovering:Q}),[t,B,o,C,Q]);return W.jsx(Heg.Provider,{value:i,children:g})},cZ=g=>{if(typeof g!="number"&&typeof g!="string"||typeof g=="string"&&!g.trim())return null;const A=Number(g);return Number.isFinite(A)&&A>=0?A:null},drB=g=>{const A=cZ(g);if(A!==null)return A;if(typeof g!="string")return null;try{const I=JSON.parse(g);if(Array.isArray(I))return cZ(I[0]?.price)}catch{return g.split(",").map(e=>{const[t,B]=e.split(":");return{quantity:cZ(t?.split("-")[0]),price:cZ(B)}}).filter(e=>e.quantity!==null&&e.price!==null).sort((e,t)=>e.quantity-t.quantity)[0]?.price??null}return null},yrB=async(g,A,I=fetch)=>{const e=await I(`https://jlcsearch.tscircuit.com/api/search?q=${encodeURIComponent(g)}&limit=1`,{signal:A,cache:"no-store"});if(!e.ok)throw new Error("JLC part lookup failed");const t=await e.json();if(!Array.isArray(t?.components))return null;const B=t.components.find(o=>o&&String(o.lcsc).replace(/^c/i,"")===g.replace(/^c/i,""));return B?{price:cZ(B.price1)??drB(B.price),stock:cZ(B.stock)}:null},wrB=g=>{if(g?.price==null)return"Price unavailable";const A={minimumFractionDigits:2,maximumFractionDigits:6};return g.currency===null?g.price.toLocaleString("en-US",A):g.price.toLocaleString("en-US",{...A,style:"currency",currency:g.currency??"USD"})},urB=({partNumber:g,platformConfig:A})=>{const[I,e]=gA.useState(null),[t,B]=gA.useState(!0),o=A?.partsEngine,C=A?.platformFetch;return gA.useEffect(()=>{const Q=new AbortController;let i=!0;B(!0),e(null);const E=setTimeout(()=>{Q.abort(),i&&B(!1)},1e4);return Promise.resolve().then(async()=>o?.fetchPartAvailability?await o.fetchPartAvailability({supplierName:"jlcpcb",supplierPartNumber:g,signal:Q.signal,platformFetch:C})??null:yrB(g,Q.signal,C)).then(n=>{i&&e(n)}).catch(()=>{}).finally(()=>{clearTimeout(E),i&&B(!1)}),()=>{i=!1,clearTimeout(E),Q.abort()}},[g,o,C]),W.jsx("span",{role:"status","aria-label":`${g} price and stock`,"aria-busy":t,style:{display:"block",color:"#64748b",marginTop:"2px"},children:t?W.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[W.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:W.jsx("circle",{cx:"6",cy:"6",r:"4",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeDasharray:"18 8",children:W.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 6 6",to:"360 6 6",dur:"1s",repeatCount:"indefinite"})})}),"Loading price and stock…"]}):W.jsxs(W.Fragment,{children:[W.jsx("span",{style:{display:"block"},children:wrB(I)}),W.jsx("span",{style:{display:"block"},children:I?.stock!=null?`${I.stock.toLocaleString("en-US")} in stock`:"Stock unavailable"})]})})},veg={color:"#64748b",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45},GrB=({platformConfig:g,sourceComponent:A,warnings:I=[],footprinterString:e,footprintPreviewCircuitJson:t,footprintPreviewViewBox:B,left:o,top:C,width:Q,maxHeight:i})=>{const E=gA.useMemo(()=>irB(A),[A]),n=gA.useMemo(()=>ErB(A),[A]),s=gA.useMemo(()=>t?.length&&B?arB(t,B):void 0,[t,B]);return W.jsxs("dialog",{open:!0,"aria-label":`${A.name} component details`,"data-schematic-component-details-tooltip":!0,style:{position:"absolute",left:o,right:"auto",top:C,bottom:"auto",width:Q,maxHeight:i,margin:0,padding:0,overflowY:"auto",overscrollBehavior:"contain",cursor:"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:gS.schematicComponentDetailsTooltip},onMouseDown:r=>r.stopPropagation(),onClick:r=>r.stopPropagation(),onWheel:r=>r.stopPropagation(),children:[W.jsxs("dl",{style:{display:"grid",gridTemplateColumns:"minmax(110px, 0.8fr) minmax(0, 1.2fr)",gap:"6px 12px",margin:0,padding:"8px"},children:[E.map(r=>W.jsxs("div",{style:{display:"contents"},children:[W.jsx("dt",{style:veg,children:r.label}),W.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:r.value})]},r.key)),n.map(r=>W.jsxs("div",{style:{display:"contents"},children:[W.jsx("dt",{style:veg,children:r.label}),W.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:r.links.map((a,c)=>W.jsxs("span",{style:r.label==="jlcpcb"?{display:"block",marginTop:c>0?6:0}:void 0,children:[r.label!=="jlcpcb"&&c>0&&", ",W.jsx("a",{href:a.href,target:"_blank",rel:"noreferrer noopener",style:{color:"#2563eb",textDecoration:"underline"},children:a.partNumber}),r.label==="jlcpcb"&&W.jsx(urB,{partNumber:a.partNumber,platformConfig:g},`${A.source_component_id}-${a.partNumber}`)]},a.href))})]},r.key)),e&&W.jsxs("div",{style:{display:"contents"},children:[W.jsx("dt",{style:veg,children:"footprint"}),W.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)})]})]}),I.length>0&&W.jsxs("section",{"aria-label":"Component warnings",style:{margin:"0 8px 8px",padding:"8px",border:"1px solid #fcd34d",borderRadius:"4px",backgroundColor:"#fffbeb",color:"#92400e",fontSize:"12px",lineHeight:1.45,overflowWrap:"anywhere"},children:[W.jsxs("strong",{children:["Warnings (",I.length,")"]}),W.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:"18px"},children:I.map((r,a)=>W.jsx("li",{children:r.message},`${r.type}-${a}`))})]}),s&&W.jsx("div",{style:{padding:"0 4px 4px"},children:W.jsx("div",{style:{height:"210px",overflow:"hidden",border:"1px solid #e2e8f0",borderRadius:"2px",background:"#f8fafc"},children:W.jsx("img",{src:s,alt:`${A.name}${e?` ${e}`:""} PCB footprint`,loading:"lazy",referrerPolicy:"no-referrer",style:{display:"block",width:"100%",height:"100%",objectFit:"contain"}})})})]})},GNI=g=>{const A=gA.useContext(Heg);if(!A)throw new Error("useMouseEventsOverBoundingBox must be used within a MouseTracker");const I=gA.useId(),e=gA.useRef(g);e.current=g;const t=gA.useMemo(()=>o=>{e.current.onClick?.(o)},[]);return gA.useEffect(()=>(A.registerBoundingBox(I,{bounds:e.current.bounds,onClick:e.current.onClick?t:void 0}),()=>{A.unregisterBoundingBox(I)}),[A,t,I]),gA.useEffect(()=>{A.updateBoundingBox(I,{bounds:e.current.bounds,onClick:e.current.onClick?t:void 0})},[A,t,I,g.bounds?.minX,g.bounds?.maxX,g.bounds?.minY,g.bounds?.maxY,g.onClick]),{hovering:gA.useSyncExternalStore(A.subscribe,()=>A.isHovering(I),()=>!1)}},mrB=(g,A)=>!g&&!A?!0:!g||!A?!1:Math.abs(g.bounds.minX-A.bounds.minX)<.5&&Math.abs(g.bounds.maxX-A.bounds.maxX)<.5&&Math.abs(g.bounds.minY-A.bounds.minY)<.5&&Math.abs(g.bounds.maxY-A.bounds.maxY)<.5&&Math.abs(g.rect.left-A.rect.left)<.5&&Math.abs(g.rect.top-A.rect.top)<.5&&Math.abs(g.rect.width-A.rect.width)<.5&&Math.abs(g.rect.height-A.rect.height)<.5,prB=({componentId:g,svgDivRef:A,containerRef:I,onComponentClick:e,onHoverChange:t,showOutline:B,circuitJsonKey:o})=>{const[C,Q]=gA.useState(null),i=gA.useRef(null),E=gA.useCallback(()=>{i.current=null;const h=A.current,l=I.current;if(!h||!l){Q(u=>u&&null);return}const D=h.querySelector(`[data-schematic-component-id="${g}"]`);if(!D){Q(u=>u&&null);return}const d=D.getBoundingClientRect(),y=l.getBoundingClientRect(),w={bounds:{minX:d.left,maxX:d.right,minY:d.top,maxY:d.bottom},rect:{left:d.left-y.left,top:d.top-y.top,width:d.width,height:d.height}};Q(u=>mrB(u,w)?u:w)},[g,I,A]),n=gA.useCallback(()=>{i.current===null&&(i.current=window.requestAnimationFrame(E))},[E]);gA.useEffect(()=>{n()},[n,o]),gA.useEffect(()=>{n();const h=A.current,l=I.current;if(!h||!l)return;const D=typeof ResizeObserver<"u"?new ResizeObserver(()=>{n()}):null;D?.observe(l),D?.observe(h);const d=typeof MutationObserver<"u"?new MutationObserver(()=>{n()}):null;return d?.observe(h,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",n,!0),window.addEventListener("resize",n),()=>{D?.disconnect(),d?.disconnect(),window.removeEventListener("scroll",n,!0),window.removeEventListener("resize",n),i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)}},[n,A,I]);const s=gA.useCallback(h=>{e&&e(g,h)},[g,e]),r=C?.bounds??null,{hovering:a}=GNI({bounds:r,onClick:e?s:void 0});if(gA.useEffect(()=>{t&&t(g,a)},[a,g,t]),!C||!a||!B)return null;const c=C.rect;return W.jsx("div",{style:{position:"absolute",left:c.left,top:c.top,width:c.width,height:c.height,border:"1.5px solid rgba(51, 153, 255, 0.9)",pointerEvents:"none",zIndex:gS.schematicComponentHoverOutline}})},krB=(g,A)=>!g&&!A?!0:!g||!A?!1:Math.abs(g.bounds.minX-A.bounds.minX)<.5&&Math.abs(g.bounds.maxX-A.bounds.maxX)<.5&&Math.abs(g.bounds.minY-A.bounds.minY)<.5&&Math.abs(g.bounds.maxY-A.bounds.maxY)<.5&&Math.abs(g.rect.left-A.rect.left)<.5&&Math.abs(g.rect.top-A.rect.top)<.5&&Math.abs(g.rect.width-A.rect.width)<.5&&Math.abs(g.rect.height-A.rect.height)<.5,MrB=({portId:g,portLabel:A,svgDivRef:I,containerRef:e,onPortClick:t,onHoverChange:B,showOutline:o,circuitJsonKey:C})=>{const[Q,i]=gA.useState(null),E=gA.useRef(null),n=gA.useCallback(()=>{E.current=null;const l=I.current,D=e.current;if(!l||!D){i(m=>m&&null);return}const d=l.querySelector(`[data-schematic-port-id="${g}"]`);if(!d){i(m=>m&&null);return}const y=d.getBoundingClientRect(),w=D.getBoundingClientRect(),u=4,G={bounds:{minX:y.left-u,maxX:y.right+u,minY:y.top-u,maxY:y.bottom+u},rect:{left:y.left-w.left-u,top:y.top-w.top-u,width:y.width+u*2,height:y.height+u*2}};i(m=>krB(m,G)?m:G)},[g,e,I]),s=gA.useCallback(()=>{E.current===null&&(E.current=window.requestAnimationFrame(n))},[n]);gA.useEffect(()=>{s()},[s,C]),gA.useEffect(()=>{s();const l=I.current,D=e.current;if(!l||!D)return;const d=typeof ResizeObserver<"u"?new ResizeObserver(()=>{s()}):null;d?.observe(D),d?.observe(l);const y=typeof MutationObserver<"u"?new MutationObserver(()=>{s()}):null;return y?.observe(l,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",s,!0),window.addEventListener("resize",s),()=>{d?.disconnect(),y?.disconnect(),window.removeEventListener("scroll",s,!0),window.removeEventListener("resize",s),E.current!==null&&(cancelAnimationFrame(E.current),E.current=null)}},[s,I,e]);const r=gA.useCallback(l=>{t&&t(g,l)},[g,t]),a=Q?.bounds??null,{hovering:c}=GNI({bounds:a,onClick:t?r:void 0});if(gA.useEffect(()=>{B&&B(g,c)},[c,g,B]),!Q||!o)return null;const h=Q.rect;return W.jsxs(W.Fragment,{children:[W.jsx("div",{style:{position:"absolute",left:h.left,top:h.top,width:h.width,height:h.height,border:c?"1.5px solid rgba(255, 153, 51, 0.9)":"1.5px solid rgba(255, 153, 51, 0.3)",backgroundColor:c?"rgba(255, 153, 51, 0.15)":"rgba(255, 153, 51, 0.05)",borderRadius:"50%",pointerEvents:"none",zIndex:gS.schematicPortHoverOutline,transition:"border-color 0.15s, background-color 0.15s"}}),c&&A&&W.jsx("div",{style:{position:"absolute",left:h.left+h.width/2,top:h.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:gS.schematicPortHoverOutline+1},children:A})]})},deA=({children:g,size:A,strokeWidth:I})=>W.jsx("svg",{width:A,height:A,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:I,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:g}),mNI=g=>W.jsxs(deA,{...g,children:[W.jsx("circle",{cx:"11",cy:"11",r:"8"}),W.jsx("path",{d:"m21 21-4.34-4.34"})]}),SrB=g=>W.jsxs(deA,{...g,children:[W.jsx("path",{d:"M18 6 6 18"}),W.jsx("path",{d:"m6 6 12 12"})]}),frB=g=>W.jsxs(deA,{...g,children:[W.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),W.jsx("rect",{x:"8",y:"8",width:"8",height:"8",rx:"1"}),W.jsx("path",{d:"M7 2v2M12 2v2M17 2v2M7 20v2M12 20v2M17 20v2M2 7h2M2 12h2M2 17h2M20 7h2M20 12h2M20 17h2"})]}),RrB=g=>W.jsxs(deA,{...g,children:[W.jsx("path",{d:"M15 6a9 9 0 0 0-9 9V3"}),W.jsx("circle",{cx:"18",cy:"6",r:"3"}),W.jsx("circle",{cx:"6",cy:"18",r:"3"})]}),NrB=g=>W.jsxs(deA,{...g,children:[W.jsx("path",{d:"M20 4v7a4 4 0 0 1-4 4H4"}),W.jsx("path",{d:"m9 10-5 5 5 5"})]}),FrB=({text:g,query:A})=>{const I=A.trim().toLocaleLowerCase();if(!I)return g;const e=g.toLocaleLowerCase(),t=[];let B=0,o=e.indexOf(I);for(;o!==-1;)o>B&&t.push(g.slice(B,o)),t.push(W.jsx("strong",{style:{fontWeight:700},children:g.slice(o,o+I.length)},`${o}-${B}`)),B=o+I.length,o=e.indexOf(I,B);return B<g.length&&t.push(g.slice(B)),t.length>0?t:g},xrB=()=>typeof navigator>"u"?"Ctrl F":/mac/i.test(navigator.platform)?"⌘ F":"Ctrl F",UrB=({query:g,onQueryChange:A,onCancel:I,results:e,onSelect:t,viewerContainerRef:B})=>{const[o,C]=gA.useState(!1),[Q,i]=gA.useState(null),[E,n]=gA.useState(null),s=gA.useRef(null),r=gA.useRef(null),a=xrB();gA.useEffect(()=>{i(p=>e.some(k=>k.target.id===p)?p:e.find(k=>k.kind==="component")?.target.id??e[0]?.target.id??null)},[e]),gA.useEffect(()=>{Q&&r.current?.querySelector(`[data-search-result-id="${Q}"]`)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[Q]),gA.useEffect(()=>{const p=S=>{if(S.key==="Escape"&&o){S.preventDefault(),S.stopPropagation(),S.stopImmediatePropagation(),I(),C(!1),s.current?.blur();return}S.code!=="KeyF"&&S.key.toLocaleLowerCase()!=="f"||!S.metaKey&&!S.ctrlKey||B.current?.matches(":hover")&&(S.preventDefault(),S.stopPropagation(),S.stopImmediatePropagation(),C(!0),requestAnimationFrame(()=>{s.current?.focus(),s.current?.select()}))},k=[window];try{window.parent!==window&&window.parent.document&&k.push(window.parent)}catch{}return k.forEach(S=>S.addEventListener("keydown",p,{capture:!0})),()=>{k.forEach(S=>S.removeEventListener("keydown",p,{capture:!0}))}},[o,I,B]);const c=()=>{I(),C(!1),s.current?.blur()},h=p=>{C(!0),p&&requestAnimationFrame(()=>s.current?.focus())},l=e.filter(p=>p.kind==="component"),D=e.filter(p=>p.kind==="net"),d=[...l,...D],y=d.find(p=>p.target.id===Q)??d[0],w=e.length===1?"1 result":`${e.length} results`;let u="none";g&&(u="1px solid #e8e8e8");const G=p=>{if(!(p.key==="Enter"&&p.target instanceof Element&&p.target.closest('[aria-label="Clear search"]'))){if(p.key==="Escape"){p.preventDefault(),c();return}if(d.length>0&&(p.key==="ArrowDown"||p.key==="ArrowUp")){p.preventDefault();let k=-1;p.key==="ArrowDown"&&(k=1),i(S=>{const R=d.findIndex(J=>J.target.id===S);let x=R;R===-1&&(x=0,k===1&&(x=-1));const N=(x+k+d.length)%d.length;return d[N]?.target.id??null});return}p.key==="Enter"&&y&&(p.preventDefault(),t(y))}},m=(p,k)=>k.length===0?null:W.jsxs("section",{children:[W.jsx("div",{style:{padding:"6px 12px 3px",backgroundColor:"#f7f7f8",color:"#777777",fontSize:"11px",fontWeight:600,letterSpacing:"0.02em",textTransform:"lowercase"},children:p}),k.map(S=>{const R=S.target.id===y?.target.id,x=S.target.id===E;let N="#ffffff";(x||R)&&(N="#f1f3f5");let J=W.jsx(RrB,{size:15,strokeWidth:1.8});S.kind==="component"&&(J=W.jsx(frB,{size:15,strokeWidth:1.8}));const L=()=>{s.current?.blur(),i(S.target.id),t(S)};return W.jsxs("button",{type:"button","data-search-result-id":S.target.id,onPointerUp:b=>{b.button===0&&L()},onClick:b=>{b.detail===0&&L()},onMouseEnter:()=>n(S.target.id),onMouseLeave:()=>n(null),style:{width:"100%",display:"flex",alignItems:"center",gap:"9px",padding:"7px 12px",border:"none",background:N,color:"#222222",cursor:"pointer",textAlign:"left"},children:[W.jsx("span",{style:{width:"26px",height:"26px",flexShrink:0,display:"grid",placeItems:"center",border:"1px solid #e5e5e5",borderRadius:"6px",backgroundColor:"#f7f7f7",color:"#666666"},children:J}),W.jsxs("span",{style:{minWidth:0,flex:1},children:[W.jsx("span",{style:{display:"block",overflow:"hidden",fontSize:"13px",fontWeight:400,lineHeight:1.25,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:W.jsx(FrB,{text:S.label,query:g})}),S.detail&&W.jsx("span",{style:{display:"block",overflow:"hidden",marginTop:"2px",color:"#777777",fontSize:"11px",lineHeight:1.2,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:S.detail}),S.schematicSheetName&&W.jsxs("span",{style:{display:"block",overflow:"hidden",marginTop:"2px",color:"#777777",fontSize:"11px",lineHeight:1.2,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Sheet: ",S.schematicSheetName]})]}),R&&W.jsx("span",{title:"Press Enter to open",style:{flexShrink:0,color:"#666666",fontSize:"17px",lineHeight:1},children:W.jsx(NrB,{size:14,strokeWidth:1.8})})]},S.target.id)})]});return W.jsx("div",{"data-schematic-search":!0,onPointerDown:p=>p.stopPropagation(),onMouseDown:p=>p.stopPropagation(),onTouchStart:p=>p.stopPropagation(),onTouchEnd:p=>p.stopPropagation(),style:{position:"relative",zIndex:gS.schematicSearch,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif'},children:o?W.jsxs("div",{onKeyDown:G,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:[W.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",height:"32px",boxSizing:"border-box",padding:"0 12px",borderBottom:u},children:[W.jsx(mNI,{size:15,strokeWidth:2}),W.jsx("input",{ref:s,value:g,"aria-label":"Search components and nets",placeholder:"Search...",onPointerUp:p=>p.currentTarget.focus(),onChange:p=>A(p.target.value),style:{minWidth:0,flex:1,border:"none",outline:"none",fontSize:"13px",color:"#222222",background:"transparent"}}),g&&e.length>0?W.jsx("span",{style:{flexShrink:0,color:"#888888",fontSize:"12px",whiteSpace:"nowrap"},children:w}):W.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:a}),o&&W.jsx("button",{type:"button","aria-label":"Clear search",onPointerUp:p=>{p.button===0&&c()},onClick:p=>{p.detail===0&&c()},style:{border:"none",background:"transparent",color:"#777777",cursor:"pointer",width:"20px",height:"20px",display:"grid",placeItems:"center",padding:0,lineHeight:1},children:W.jsx(SrB,{size:16,strokeWidth:2})})]}),g&&W.jsx("div",{ref:r,style:{maxHeight:"240px",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",scrollBehavior:"smooth",touchAction:"pan-y",WebkitOverflowScrolling:"touch"},onWheel:p=>p.stopPropagation(),onTouchMove:p=>p.stopPropagation(),children:e.length===0?W.jsx("div",{style:{padding:"12px",color:"#777777",fontSize:"13px"},children:"No matching components or nets"}):W.jsxs(W.Fragment,{children:[m("components",l),m("nets",D)]})})]}):W.jsx("button",{type:"button",title:"Search schematic","aria-label":"Search schematic",onPointerDown:p=>{p.stopPropagation(),p.pointerType!=="mouse"&&h(!1)},onPointerUp:p=>{p.pointerType==="mouse"&&p.button===0&&h(!0)},onClick:p=>{p.detail===0&&h(!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:W.jsx(mNI,{size:16,strokeWidth:2})})})},qeg='system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',JrB={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:qeg,outline:"none",zIndex:gS.viewMenu},KrB={display:"flex",alignItems:"center",gap:8,padding:"7px 10px 7px 8px",borderRadius:6,cursor:"pointer",outline:"none",userSelect:"none",color:"#111111",fontSize:13,fontFamily:qeg},PrB={width:16,height:16,flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center",color:"#111111"},pNI={overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},LrB=`
|
|
5610
5610
|
.sv-sheet-item[data-highlighted], .sv-sheet-item:hover { background-color: #f1f3f5; }
|
|
5611
5611
|
.sv-sheet-chevron { transition: transform 0.2s ease; }
|
|
5612
5612
|
[data-state="open"] > .sv-sheet-chevron { transform: rotate(180deg); }
|
|
5613
|
-
`,YrB=()=>W.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:W.jsx("path",{d:"M20 6 9 17l-5-5"})}),_rB=({className:g})=>W.jsx("svg",{className:g,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:W.jsx("path",{d:"m6 9 6 6 6-6"})}),brB=({sheets:g,selectedSheetId:A,onSelectSheet:I})=>{const[e,t]=gA.useState(!1);if(g.length<=1)return null;const o=g.find(C=>C.schematic_sheet_id===A)?.name??"Select sheet";return W.jsxs(W.Fragment,{children:[W.jsx("style",{children:LrB}),W.jsxs(LwA,{open:e,onOpenChange:t,modal:!1,children:[W.jsx(YwA,{asChild:!0,children:W.jsxs("button",{type:"button",title:o,onPointerDown:C=>C.stopPropagation(),style:{display:"flex",alignItems:"center",gap:"6px",maxWidth:"220px",height:"32px",boxSizing:"border-box",padding:"0 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:qeg},children:[W.jsx("span",{style:{color:"#888888",flexShrink:0},children:"Sheet:"}),W.jsx("span",{style:{...pNI,minWidth:0},children:o}),W.jsx(_rB,{className:"sv-sheet-chevron"})]})}),W.jsx(AZ,{children:W.jsx(zIA,{style:JrB,side:"bottom",align:"start",sideOffset:8,collisionPadding:10,children:g.map(C=>{const Q=C.schematic_sheet_id===A;return W.jsxs(UF,{className:"sv-sheet-item",style:KrB,title:C.name,onSelect:i=>i.preventDefault(),onPointerUp:()=>{I(C.schematic_sheet_id),t(!1)},children:[W.jsx("span",{style:PrB,children:Q&&W.jsx(YrB,{})}),W.jsx("span",{style:{...pNI,minWidth:0},children:C.name})]},C.schematic_sheet_id)})})})]})]})},HrB=({count:g,showWarnings:A,onToggle:I})=>{const e=`${A?"Hide":"Show"} ${g} ${g===1?"warning":"warnings"}`;return W.jsxs("button",{type:"button","data-schematic-warnings":!0,title:e,"aria-label":e,"aria-pressed":A,onClick:I,onPointerDown:t=>t.stopPropagation(),onMouseDown:t=>t.stopPropagation(),onTouchStart:t=>t.stopPropagation(),onTouchEnd:t=>t.stopPropagation(),style:{height:"32px",display:"flex",alignItems:"center",gap:"4px",padding:"0 8px",border:"none",borderRadius:"4px",backgroundColor:A?"#fff3cd":"#ffffff",color:"#946200",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',fontSize:"12px",fontWeight:600},children:[W.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[W.jsx("path",{d:"M10.3 3.9 1.8 18.1A2 2 0 0 0 3.5 21h17a2 2 0 0 0 1.7-2.9L13.7 3.9a2 2 0 0 0-3.4 0Z"}),W.jsx("path",{d:"M12 9v4m0 4h.01"})]}),W.jsx("span",{children:g})]})},vrB={version:"2.0.
|
|
5613
|
+
`,YrB=()=>W.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:W.jsx("path",{d:"M20 6 9 17l-5-5"})}),_rB=({className:g})=>W.jsx("svg",{className:g,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:W.jsx("path",{d:"m6 9 6 6 6-6"})}),brB=({sheets:g,selectedSheetId:A,onSelectSheet:I})=>{const[e,t]=gA.useState(!1);if(g.length<=1)return null;const o=g.find(C=>C.schematic_sheet_id===A)?.name??"Select sheet";return W.jsxs(W.Fragment,{children:[W.jsx("style",{children:LrB}),W.jsxs(LwA,{open:e,onOpenChange:t,modal:!1,children:[W.jsx(YwA,{asChild:!0,children:W.jsxs("button",{type:"button",title:o,onPointerDown:C=>C.stopPropagation(),style:{display:"flex",alignItems:"center",gap:"6px",maxWidth:"220px",height:"32px",boxSizing:"border-box",padding:"0 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:qeg},children:[W.jsx("span",{style:{color:"#888888",flexShrink:0},children:"Sheet:"}),W.jsx("span",{style:{...pNI,minWidth:0},children:o}),W.jsx(_rB,{className:"sv-sheet-chevron"})]})}),W.jsx(AZ,{children:W.jsx(zIA,{style:JrB,side:"bottom",align:"start",sideOffset:8,collisionPadding:10,children:g.map(C=>{const Q=C.schematic_sheet_id===A;return W.jsxs(UF,{className:"sv-sheet-item",style:KrB,title:C.name,onSelect:i=>i.preventDefault(),onPointerUp:()=>{I(C.schematic_sheet_id),t(!1)},children:[W.jsx("span",{style:PrB,children:Q&&W.jsx(YrB,{})}),W.jsx("span",{style:{...pNI,minWidth:0},children:C.name})]},C.schematic_sheet_id)})})})]})]})},HrB=({count:g,showWarnings:A,onToggle:I})=>{const e=`${A?"Hide":"Show"} ${g} ${g===1?"warning":"warnings"}`;return W.jsxs("button",{type:"button","data-schematic-warnings":!0,title:e,"aria-label":e,"aria-pressed":A,onClick:I,onPointerDown:t=>t.stopPropagation(),onMouseDown:t=>t.stopPropagation(),onTouchStart:t=>t.stopPropagation(),onTouchEnd:t=>t.stopPropagation(),style:{height:"32px",display:"flex",alignItems:"center",gap:"4px",padding:"0 8px",border:"none",borderRadius:"4px",backgroundColor:A?"#fff3cd":"#ffffff",color:"#946200",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',fontSize:"12px",fontWeight:600},children:[W.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[W.jsx("path",{d:"M10.3 3.9 1.8 18.1A2 2 0 0 0 3.5 21h17a2 2 0 0 0 1.7-2.9L13.7 3.9a2 2 0 0 0-3.4 0Z"}),W.jsx("path",{d:"M12 9v4m0 4h.01"})]}),W.jsx("span",{children:g})]})},vrB={version:"2.0.104"},Teg='system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',kNI={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:Teg,outline:"none",zIndex:gS.contextMenu},F3={display:"flex",alignItems:"center",gap:8,padding:"6px 8px",borderRadius:6,cursor:"default",outline:"none",userSelect:"none",color:"#fafafa",fontSize:14,fontWeight:400,fontFamily:Teg},hZ={width:16,height:16,flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center",color:"#fafafa"},MNI={height:1,backgroundColor:"#ffffff1a",margin:"4px 0"},qrB=`
|
|
5614
5614
|
.sv-vm-item[data-highlighted]:not([data-disabled]),
|
|
5615
5615
|
.sv-vm-item:hover:not([data-disabled]) { background-color: #404040; }
|
|
5616
5616
|
.sv-vm-item[data-disabled] { opacity: 0.45; cursor: not-allowed; }
|
|
@@ -5670,7 +5670,7 @@ test("${i} should solve problem correctly", () => {
|
|
|
5670
5670
|
// Add more specific assertions based on expected output
|
|
5671
5671
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5672
5672
|
})
|
|
5673
|
-
`,n=new Blob([E],{type:"text/plain"}),s=URL.createObjectURL(n),r=document.createElement("a");r.href=s,r.download=`${i}.test.ts`,r.click(),URL.revokeObjectURL(s)}catch(Q){alert(`Error generating test.ts for ${g.getSolverName()}: ${Q instanceof Error?Q.message:String(Q)}`)}e(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:t,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>e(!I),title:`Download options for ${g.getSolverName()}`,children:g.getSolverName()}),I&&W.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:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:B,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:C,children:"Download test.ts"})]})]})},qNI=g=>g.activeSubSolver?[g,...qNI(g.activeSubSolver)]:[g],MhB=({solver:g})=>{const A=qNI(g);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((I,e)=>W.jsxs("div",{className:"flex items-center",children:[e>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(khB,{solver:I})]},I.getSolverName()))})},ShB=({solver:g,triggerRender:A,animationSpeed:I=25,renderer:e,onRendererChange:t,onAnimationSpeedChange:B,onDownloadVisualization:o,onSolverStarted:C,onSolverCompleted:Q})=>{const[i,E]=gA.useReducer(m=>!m,!1),n=gA.useRef(void 0),s=gA.useRef(null),r="solver-debugger-last-iteration",[a,c]=gA.useState(null),h=gA.useRef(null),l=gA.useMemo(()=>[{label:"Slow",value:250,description:"250ms"},{label:"Normal",value:100,description:"100ms"},{label:"Fast",value:10,description:"10ms"},{label:"Fast (2x)",value:5,description:"5ms"},{label:"Fast (10x)",value:1,description:"1ms"},{label:"Fast 20x",value:.5,description:"2 steps / 1ms"},{label:"Fast 100x",value:.1,description:"10 steps / 1ms"}],[]),D=()=>{const m=Math.max(1,I),p=I<1?Math.round(1/I):1;n.current=setInterval(()=>{if(g.solved||g.failed){n.current&&(clearInterval(n.current),n.current=void 0),E(),A(),Q&&g.solved&&Q(g);return}for(let k=0;k<p&&!(g.solved||g.failed);k++)g.step();A()},m)},d=()=>{n.current&&(clearInterval(n.current),n.current=void 0)},y=()=>{!g.solved&&!g.failed&&(g.step(),A())},w=()=>{!g.solved&&!g.failed&&(C&&C(g),g.solve(),A(),Q&&Q(g))},u=()=>{i?(d(),E()):(E(),D())},G=()=>{if(g.solved||g.failed||i)return;s.current===null&&typeof window<"u"&&(s.current=window.localStorage.getItem(r));const m=window.prompt("Step until which iteration?",s.current??`${g.iterations}`);if(m===null)return;s.current=m,typeof window<"u"&&window.localStorage.setItem(r,m);const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;g.iterations<p&&!g.solved&&!g.failed;)g.step();A(),g.solved&&Q&&Q(g)};return gA.useEffect(()=>()=>{d()},[]),gA.useEffect(()=>{(g.solved||g.failed)&&i&&(d(),E())},[g.solved,g.failed,i]),gA.useEffect(()=>{i&&(d(),D())},[I,i]),gA.useEffect(()=>{if(typeof document>"u")return;const m=p=>{h.current&&!h.current.contains(p.target)&&c(null)};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[]),W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsxs("div",{className:"flex items-center gap-2",ref:h,children:[W.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="renderer"?null:"renderer"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="renderer"?"open":"closed",children:"Renderer"}),a==="renderer"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[10rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:["vector","canvas"].map(m=>W.jsxs("button",{type:"button",onClick:()=>{t(m),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m==="vector"?"Vector":"Canvas",e===m&&W.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},m))})]}),W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="debug"?null:"debug"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="debug"?"open":"closed",children:"Debug"}),a==="debug"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:W.jsx("button",{type:"button",onClick:()=>{o(),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="animation"?null:"animation"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="animation"?"open":"closed",children:"Animation"}),a==="animation"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:l.map(m=>W.jsxs("button",{type:"button",onClick:()=>{B(m.value),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m.label,W.jsx("span",{className:"ml-auto text-xs text-slate-500",children:m.description}),I===m.value&&W.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},m.value))})]})]}),W.jsx(MhB,{solver:g})]})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:y,disabled:g.solved||g.failed||i,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:w,disabled:g.solved||g.failed||i,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:u,disabled:g.solved||g.failed,className:`px-3 py-1 rounded text-white text-sm ${i?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:i?"Stop":"Animate"}),W.jsx("button",{onClick:G,disabled:g.solved||g.failed||i,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"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",g.iterations]}),g.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(g.timeToSolve/1e3).toFixed(3),"s"]}),g.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),g.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),g.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",g.error]})]})},fhB=g=>g!==null&&"pipelineDef"in g&&Array.isArray(g.pipelineDef),RhB=(g,A,I)=>{const e=g.currentPipelineStageIndex;return A<e?"Completed":A===e&&g.activeSubSolver?g.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},NhB=(g,A)=>{const e=g.pipelineDef[A].solverName,t=RhB(g,A),B=g[e],o=g.firstIterationOfStage?.[e]??(A===g.currentPipelineStageIndex?g.iterations:null),C=g.iterations;let Q=0;if(t==="Completed"){const s=g.pipelineDef[A+1],r=s?g.firstIterationOfStage?.[s.solverName]:void 0;r!==void 0&&o!==null?Q=r-o:o!==null&&(Q=C-o)}else t==="In Progress"&&o!==null&&(Q=C-o);const i=g.timeSpentOnStage?.[e]??0;let E=0;t==="Completed"?E=1:t==="In Progress"&&B&&(E=B.progress??0);const n=B?.stats??null;return{index:A,name:e,status:t,firstIteration:o,iterations:Q,progress:E,timeSpent:i,stats:n&&Object.keys(n).length>0?n:null,solverInstance:B??null}},FhB=({status:g})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[g]}`,children:g})},xhB=({progress:g})=>{if(g===0)return null;const A=Math.round(g*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},TNI=g=>{if(typeof g=="string")return g;if(typeof g=="number"||typeof g=="boolean"||typeof g=="bigint"||g==null)return String(g);if(typeof g=="object")try{return JSON.stringify(g)}catch{return String(g)}return String(g)},UhB=g=>Object.entries(g).map(([A,I])=>`${A}: ${TNI(I)}`).join(", "),JhB=({stats:g})=>{if(!g||Object.keys(g).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(g),I=UhB(g);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:I}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([e,t])=>W.jsxs("div",{children:[e,": ",TNI(t)]},e))})]})},Atg=g=>{if(g===null||typeof g!="object")return g;if(Array.isArray(g))return g.map(Atg);const A={};for(const[I,e]of Object.entries(g))I.startsWith("_")||(A[I]=Atg(e));return A},KhB=(g,A)=>{try{if(typeof g.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const I=Atg(g.getConstructorParams()),e=new Blob([JSON.stringify(I,null,2)],{type:"application/json"}),t=URL.createObjectURL(e),B=document.createElement("a");B.href=t,B.download=`${A}_input.json`,B.click(),URL.revokeObjectURL(t)}catch(I){alert(`Error downloading input for ${A}: ${I instanceof Error?I.message:String(I)}`)}},PhB=({expanded:g})=>W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:`w-4 h-4 transition-transform duration-200 ${g?"rotate-90":""}`,children:W.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"})}),ZNI=g=>{let A=g;for(;A.activeSubSolver;)A=A.activeSubSolver;return A},ONI=({solver:g,onStepUntilPhase:A,onDownloadInput:I,isNested:e=!1,indentLevel:t=0,triggerRender:B})=>{const[o,C]=gA.useState(new Set),Q=g.pipelineDef.map((h,l)=>NhB(g,l)),i=h=>{C(l=>{const D=new Set(l);return D.has(h)?D.delete(h):D.add(h),D})},E=h=>{A?.(h)},n=h=>{h.solverInstance&&(I?I(h.solverInstance,h.name):KhB(h.solverInstance,h.name))},s=h=>`${(h/1e3).toFixed(2)}s`,r=()=>{if(!g.solved&&!g.failed){const h=g.activeSubSolver;for(;!g.solved&&!g.failed&&(g.step(),!(g.activeSubSolver&&g.activeSubSolver!==h)););B?.()}},a=()=>{if(!g.solved&&!g.failed){const h=ZNI(g);for(;!g.solved&&!g.failed&&(g.step(),ZNI(g)===h););B?.()}},c=t*24;return W.jsxs("div",{className:e?"":"border-t border-gray-200",children:[!e&&W.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),W.jsxs("div",{className:"flex gap-2",children:[W.jsx("button",{onClick:a,disabled:g.solved||g.failed,className:"bg-indigo-500 hover:bg-indigo-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Solver"}),W.jsx("button",{onClick:r,disabled:g.solved||g.failed,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Stage"})]})]}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[!e&&W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:Q.map(h=>{const l=fhB(h.solverInstance),D=o.has(h.name);return W.jsxs(nC.Fragment,{children:[W.jsxs("tr",{className:`border-b border-gray-100 ${h.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:c},children:[l?W.jsx("button",{onClick:()=>i(h.name),className:"text-gray-500 hover:text-gray-700",title:D?"Collapse":"Expand",children:W.jsx(PhB,{expanded:D})}):W.jsx("span",{className:"w-4"}),W.jsx("span",{className:"text-gray-400 w-6",children:String(h.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>E(h.name),disabled:h.status==="Completed"||g.solved||g.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${h.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.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"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:h.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(FhB,{status:h.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:h.firstIteration!==null?h.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:h.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(xhB,{progress:h.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(h.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(JhB,{stats:h.stats})}),W.jsx("td",{className:"px-4 py-2",children:h.solverInstance?W.jsxs("button",{onClick:()=>n(h),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${h.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.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"})}),W.jsx("span",{children:"Input"})]}):null})]}),l&&D&&W.jsx("tr",{children:W.jsx("td",{colSpan:8,className:"p-0",children:W.jsx(ONI,{solver:h.solverInstance,onStepUntilPhase:A,onDownloadInput:I,isNested:!0,indentLevel:t+1,triggerRender:B})})})]},h.name)})})]})})]})};function LhB({graphics:g}){const A=g.points??[],I=g.lines??[],e=g.rects??[],t=g.circles??[],B=g.texts??[];let o=Number.POSITIVE_INFINITY,C=Number.POSITIVE_INFINITY,Q=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;const E=(h,l)=>{typeof h=="number"&&(h<o&&(o=h),h>Q&&(Q=h)),typeof l=="number"&&(l<C&&(C=l),l>i&&(i=l))};for(const h of A)E(h.x,h.y);for(const h of I){const l=h.points??[];for(const D of l)E(D.x,D.y)}for(const h of e){const l=h.x??0,D=h.y??0,d=h.width??0,y=h.height??0;E(l,D),E(l+d,D+y)}for(const h of t){const l=h.x??0,D=h.y??0,d=h.radius??1;E(l-d,D-d),E(l+d,D+d)}for(const h of B)E(h.x,h.y);(!isFinite(o)||!isFinite(C)||!isFinite(Q)||!isFinite(i))&&(o=-20,C=-20,Q=20,i=20);const n=10,s=o-n,r=C-n,a=Math.max(1,Q-o+2*n),c=Math.max(1,i-C+2*n);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${s} ${r} ${a} ${c}`,role:"img","aria-label":"Graphics fallback",children:[e.map((h,l)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${l}`)),I.map((h,l)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(D=>`${D.x??0},${D.y??0}`).join(" ")},`line-${l}`)),t.map((h,l)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${l}`)),A.map((h,l)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${l}`)),B.map((h,l)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${l}`))]})}var YhB=class extends nC.Component{constructor(g){super(g),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(g){console.error("InteractiveGraphics render error:",g)}render(){return this.state.hasError?this.props.fallback:this.props.children}},_hB=({solver:g,createSolver:A,animationSpeed:I=25,onSolverStarted:e,onSolverCompleted:t})=>{const[B,o]=gA.useReducer(D=>D+1,0),[C]=gA.useState(()=>{if(A)return A();if(!g)throw new Error("GenericSolverDebugger requires solver or createSolver");return g}),[Q,i]=gA.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[E,n]=gA.useState(I),s=gA.useMemo(()=>{try{return C.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(D){return console.error("Visualization error:",D),{points:[],lines:[],rects:[],circles:[]}}},[C,B]),r=gA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);gA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const D=document.createElement("script");D.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(D)}},[]),gA.useEffect(()=>{n(I)},[I]);const a=C.pipelineDef!==void 0,c=D=>{const d=C;if(!C.solved&&!C.failed){for(;!C.solved&&!C.failed&&d.currentPipelineStageIndex<=d.pipelineDef.findIndex(y=>y.solverName===D);)C.step();o()}},h=()=>{const D=JSON.stringify(s,null,2),d=new Blob([D],{type:"application/json"}),y=URL.createObjectURL(d),w=document.createElement("a");w.download="visualization.json",w.href=y,document.body.appendChild(w),w.click(),document.body.removeChild(w),URL.revokeObjectURL(y)},l=D=>{i(D),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",D)};return W.jsxs("div",{children:[W.jsx(ShB,{solver:C,triggerRender:o,animationSpeed:E,renderer:Q,onRendererChange:l,onAnimationSpeedChange:n,onDownloadVisualization:h,onSolverStarted:e,onSolverCompleted:t}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(YhB,{fallback:W.jsx(LhB,{graphics:s}),children:Q==="canvas"?W.jsx(phB,{graphics:s}):W.jsx(uhB,{graphics:s})}),a&&W.jsx(ONI,{solver:C,onStepUntilPhase:c,triggerRender:o})]})};const bhB=()=>{gA.useEffect(()=>{const g="tailwind-cdn-script";if(document.getElementById(g)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const I=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),I)return;const e=document.createElement("script");e.id=g,e.src="https://cdn.tailwindcss.com",document.head.appendChild(e)},[])},HhB=1e3,Dk=(g,A)=>{const{fileName:I,mimeType:e="text/plain"}=A,t=g instanceof Blob?g:new Blob([g],{type:e}),B=URL.createObjectURL(t),o=document.createElement("a");o.href=B,o.download=I,o.target="_blank",o.rel="noopener noreferrer",o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(()=>{URL.revokeObjectURL(B)},HhB)},gtg=g=>{let A=g.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(A)&&(A=`_${A}`),A=A.slice(0,200),A||"untitled"},vhB=g=>{const A=g.solverConstructorArgs??[g.solverParams];if(g.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||A.length!==1)return A;const[{input:I,options:e}]=A;return[I,e]},KF="https://github.com/tscircuit/tscircuit-autorouter/issues/new",WNI="https://github.com/tscircuit/copper-pour-solver/issues/new",VNI="https://github.com/tscircuit/calculate-packing/issues/new",qhB="https://github.com/tscircuit/matchpack/issues/new",jNI="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",ThB={PackSolver2:VNI,LayoutPipelineSolver:qhB,AutoroutingPipelineSolver:KF,AssignableAutoroutingPipeline2:KF,AssignableAutoroutingPipeline3:KF,AutoroutingPipeline1_OriginalUnravel:KF,AutoroutingPipelineSolver3_HgPortPointPathing:KF,AutoroutingPipelineSolver4:KF,AutoroutingPipelineSolver5:KF,AutoroutingPipelineSolver7_MultiGraph:KF,AutoroutingPipelineSolver8:KF,CopperPourPipelineSolver:WNI,SchematicTracePipelineSolver:jNI},ZhB=g=>g.toLowerCase().includes("pack")?oBB:g.toLowerCase().includes("rout")?KSI:XtB,zNI=g=>{const A=ThB[g];if(A)return A;const I=g.toLowerCase();return I.includes("autorout")?KF:I.includes("schematic")&&I.includes("trace")?jNI:I.includes("copperpour")?WNI:I.includes("pack")?VNI:null},OhB=g=>`${gtg(`${g.componentName}-${g.solverName}`)}-solver-input.json`,XNI=g=>{Dk(JSON.stringify(g.solverParams,null,2),{fileName:OhB(g),mimeType:"application/json"})},WhB=({solverEvent:g})=>{const A=zNI(g.solverName);return W.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:[W.jsxs(zE,{type:"button",variant:"outline",size:"sm",onClick:()=>XNI(g),children:[W.jsx(qIA,{className:"rf-w-4 rf-h-4"}),"Download"]}),A?W.jsx(zE,{asChild:!0,variant:"outline",size:"sm",children:W.jsxs("a",{href:A,target:"_blank",rel:"noopener noreferrer",children:[W.jsx(iwA,{className:"rf-w-4 rf-h-4"}),"Report"]})}):W.jsxs(zE,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[W.jsx(iwA,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},VhB=({solverEvent:g})=>{const A=zNI(g.solverName);return A?W.jsx(zE,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:W.jsx("a",{href:A,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:W.jsx(iwA,{className:"rf-w-4 rf-h-4"})})}):W.jsx(zE,{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:W.jsx(iwA,{className:"rf-w-4 rf-h-4"})})},jhB=({solverEvents:g=[]})=>{const[A,I]=gA.useState(null);bhB();const e=gA.useMemo(()=>{const C=new Map;for(const Q of g){const i=`${Q.componentName}-${Q.solverName}`;C.set(i,Q)}return C},[g]),t=gA.useMemo(()=>Array.from(e.keys()),[e]),B=A?e.get(A):null,o=gA.useMemo(()=>{if(!B)return{instance:null,error:null,classFound:!1};const C=d6A[B.solverName];if(!C)return{instance:null,error:`Solver class "${B.solverName}" not found in SOLVERS registry. Available: ${Object.keys(d6A).join(", ")}`,classFound:!1};try{return{instance:new C(...vhB(B)),error:null,classFound:!0}}catch(Q){const i=Q instanceof Error?Q.message:String(Q);return console.error("Failed to reconstruct solver:",Q),{instance:null,error:`Failed to instantiate solver: ${i}`,classFound:!0}}},[B]);return g.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.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."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.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:[t.length," ",t.length===1?"Solver":"Solvers"]}),t.map(C=>{const Q=e.get(C),i=A===C;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${i?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>I(C),children:(()=>{const E=ZhB(Q.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(E,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:Q.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:Q.solverName})]})]})})()},C)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:B?o.instance?W.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[W.jsx(WhB,{solverEvent:B}),W.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:W.jsx(SR,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",B.solverName]})]})}),children:W.jsx(_hB,{solver:o.instance})})})]}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:B.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",B.componentName]})]}),o.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${o.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${o.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:o.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.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:[W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(VhB,{solverEvent:B}),W.jsx(zE,{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:()=>XNI(B),children:W.jsx(qIA,{className:"rf-w-4 rf-h-4"})})]})]}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(B.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},zhB=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),XhB=new Set(["tscircuit","default","auto","auto_local"]);function $hB(g){if(g==="FanoutSolver")return"Fanout";if(g==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const A=g.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(A)return`Pipeline${A[1]}`;const I=g.match(/^AssignableAutoroutingPipeline(\d+)$/);return I?`Assignable${I[1]}`:g}function A0B(g){const A=g.autorouterName?.trim(),I=A?.replace(/-/g,"_"),e=I&&zhB.get(I);if(e)return e;if(I&&!XhB.has(I))return A;const t=g.solverName?.trim();if(t)return $hB(t);const B=g.autorouterVersion?.trim();if(B){const o=B.match(/^beta[_-]pipeline(\d+)$/);return o?`Pipeline${o[1]}`:B==="latest"?"default":B}return A?"default":"Unknown"}const Itg="#fbbf24";function g0B(g){const A=g.endSimpleRouteJson?.traces??[],I=new Set(A.flatMap(t=>[t.pcb_trace_id,t.__replaces_pcb_trace_id].filter(B=>B!==void 0)));return[...(g.startSimpleRouteJson?.traces??[]).filter(t=>!I.has(t.pcb_trace_id)),...A]}function $NI(g){const A=new Map((g.startSimpleRouteJson?.traces??[]).map(I=>[I.pcb_trace_id,I]));return(g.endSimpleRouteJson?.traces??[]).filter(I=>{const e=A.get(I.pcb_trace_id);return!e||!!I.__replaces_pcb_trace_id&&I.__replaces_pcb_trace_id!==e.__replaces_pcb_trace_id||JSON.stringify(e.route)!==JSON.stringify(I.route)}).map(I=>I.pcb_trace_id)}function I0B(g,A){return{outer_diameter:g.via_diameter??A.minViaPadDiameter??A.min_via_pad_diameter??A.minViaDiameter??.6,hole_diameter:g.via_hole_diameter??A.minViaHoleDiameter??A.min_via_hole_diameter??.3}}function A1I(g,A){const I=[];for(const C of g.route)C.route_type==="wire"?I.push({...C,layer:C.layer}):C.route_type==="via"?I.push({route_type:"via",x:C.x,y:C.y,from_layer:C.from_layer,to_layer:C.to_layer,...I0B(C,A)}):C.route_type==="through_obstacle"&&I.push({route_type:"through_pad",start:{...C.start},end:{...C.end},width:C.width,start_layer:C.from_layer,end_layer:C.to_layer,pcb_smtpad_id:C.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:C.circuitJsonMetadata?.pcb_plated_hole_id});const e=C=>{let Q=-1,i=Number.POSITIVE_INFINITY;return I.forEach((E,n)=>{if(E.route_type!=="wire")return;const s=Math.hypot(E.x-C.x,E.y-C.y);s<i&&(i=s,Q=n)}),Q},t=g.route.filter(C=>C.route_type==="jumper").map(C=>[e(C.start),e(C.end)].sort((Q,i)=>Q-i)).filter(([C,Q])=>C>=0&&Q>C).sort(([C],[Q])=>C-Q),B=[];let o=0;for(const[C,Q]of t)C>=o&&B.push(I.slice(o,C+1)),o=Math.max(o,Q);return o<I.length&&B.push(I.slice(o)),B}function e0B(g){const A=[],I=[],e=g.endSimpleRouteJson;if(!e)return{lines:A,circles:I};const t=new Set($NI(g));for(const B of e.traces??[])if(t.has(B.pcb_trace_id))for(const o of A1I(B,e)){let C;for(const Q of o){if(Q.route_type==="through_pad"){C={...Q.end,layer:Q.end_layer,width:Q.width};continue}const i=Q.route_type==="wire"?Q.layer:Q.from_layer;C&&C.layer===i&&(C.x!==Q.x||C.y!==Q.y)&&A.push({points:[{x:C.x,y:C.y},{x:Q.x,y:Q.y}],strokeWidth:Q.route_type==="wire"?Q.width:C.width,strokeColor:Itg,layer:i}),Q.route_type==="via"&&I.push({center:{x:Q.x,y:Q.y},radius:Q.outer_diameter/2,stroke:Itg,fill:"transparent"}),C={x:Q.x,y:Q.y,layer:Q.route_type==="wire"?Q.layer:Q.to_layer,width:Q.route_type==="wire"?Q.width:C?.width??e.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:A,circles:I}}function t0B(g){const A=JSON.stringify(g);let I=2166136261;for(let e=0;e<A.length;e++)I=Math.imul(I^A.charCodeAt(e),16777619);return(I>>>0).toString(36)}const B0B=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function o0B(g,A,I){const e=I==="input"?A.startSimpleRouteJson??A.errorSimpleRouteJson:A.endSimpleRouteJson,t=g.filter(i=>!B0B.has(i.type)&&!i.type.endsWith("_error")&&!i.type.endsWith("_warning"));if(!e)return t;const B=I==="input"?e.traces??[]:g0B(A),o=new Set(g.filter(i=>i.type==="source_trace").map(i=>i.source_trace_id)),C=["top",...Array.from({length:Math.max(0,e.layerCount-2)},(i,E)=>`inner${E+1}`),...e.layerCount>1?["bottom"]:[]],Q=[];for(const i of B){const n=e.connections.find(r=>r.name===i.connection_name||r.source_trace_id===i.connection_name)?.source_trace_id??i.connection_name??"",s=A1I(i,e);for(const[r,a]of s.entries()){const c={type:"pcb_trace",pcb_trace_id:`${A.id}_${I}_${i.pcb_trace_id}_${r}_${t0B(a)}`,subcircuit_id:A.subcircuit_id??void 0,source_trace_id:o.has(n)?n:void 0,route:a};Q.push(c);for(const[h,l]of a.entries()){if(l.route_type!=="via")continue;const D=C.indexOf(l.from_layer),d=C.indexOf(l.to_layer),y={type:"pcb_via",pcb_via_id:`${c.pcb_trace_id}_via_${h}`,pcb_trace_id:c.pcb_trace_id,subcircuit_id:A.subcircuit_id??void 0,x:l.x,y:l.y,outer_diameter:l.outer_diameter,hole_diameter:l.hole_diameter,layers:D>=0&&d>=0?C.slice(Math.min(D,d),Math.max(D,d)+1):[l.from_layer,l.to_layer]};Q.push(y)}}}return[...t,...Q]}const etg=(g,A)=>g.phaseName||`Phase ${g.phaseOrdinal??A+1}`,g1I=g=>g.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||g.componentDisplayName||g.subcircuit_id||"Board",I1I=g=>g.startSimpleRouteJson??g.endSimpleRouteJson??g.errorSimpleRouteJson,C0B={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},Q0B=({circuitJson:g,phases:A=[],isRunning:I=!1})=>{const[e,t]=gA.useState(null),[B,o]=gA.useState("output"),[C,Q]=gA.useState(!0),[i,E]=gA.useState(!1),n=gA.useRef(null),[s,r]=gA.useState(480),a=e?A.findIndex(N=>N.id===e.id&&I1I(N)===I1I(e)):-1,c=a<0?A.length-1:a,h=A[c],l=a<0,D=!!h?.endSimpleRouteJson,d=h?.startSimpleRouteJson??h?.errorSimpleRouteJson,y=!!d,w=B==="output"&&!D?"input":B==="input"&&!y?"output":B,u=w==="input"?d:h?.endSimpleRouteJson,G=gA.useMemo(()=>!h||!u?null:o0B(g??[],h,w),[g,h,u,w]),m=gA.useMemo(()=>h&&w==="output"&&C?e0B(h):{lines:[],circles:[]},[h,w,C]);if(gA.useLayoutEffect(()=>{const N=n.current;if(!N)return;const J=()=>r(Math.max(360,N.clientHeight));J();const L=new ResizeObserver(J);return L.observe(N),()=>L.disconnect()},[!!h]),!h)return W.jsxs("div",{className:"rf-flex rf-min-h-[400px] rf-flex-col rf-items-center rf-justify-center rf-gap-3 rf-p-8 rf-text-center",children:[W.jsx(KSI,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),W.jsx("h3",{className:"rf-text-base rf-font-medium",children:I?"Waiting for autorouting":"No autorouting captures"}),W.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:I?"Phases appear as the circuit routes. Each capture includes its input and output on the PCB.":"Run a circuit with autorouting enabled to inspect its phases. A circuit JSON file alone does not include routing history."})]});const p=etg(h,c),k=h.status==="running"&&I,S=!D,R=d?.connections.length,x=G?.filter(N=>N.type==="pcb_trace").length??0;return W.jsxs("div",{className:"rf-flex rf-h-full rf-min-h-[620px] rf-flex-col rf-bg-white md:rf-flex-row","data-testid":"autorouting-explorer",children:[W.jsxs("aside",{className:"rf-flex rf-shrink-0 rf-flex-col rf-border-b rf-border-gray-200 md:rf-w-52 md:rf-border-b-0 md:rf-border-r","aria-label":"Routing phases",children:[W.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-px-3 rf-py-2 rf-text-xs rf-text-gray-500",children:[W.jsx("span",{children:"Routing phases"}),W.jsx("span",{children:A.length})]}),W.jsx("div",{className:"rf-flex rf-gap-1 rf-overflow-x-auto rf-px-1.5 rf-pb-1.5 md:rf-flex-col md:rf-overflow-x-hidden md:rf-overflow-y-auto",children:A.map((N,J)=>{const L=$NI(N).length,b=N.endSimpleRouteJson?`${L} ${L===1?"trace":"traces"} routed`:N.status==="error"?"Failed":N.status==="running"&&I?"Routing…":"No output";return W.jsxs("button",{type:"button","aria-pressed":J===c,title:`${g1I(N)} · ${b}`,onClick:()=>t(N),className:no("rf-flex rf-min-w-[192px] rf-items-start rf-gap-2 rf-rounded-md rf-border rf-px-2 rf-py-2 rf-text-left md:rf-min-w-0",J===c?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[W.jsx("span",{className:no("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",J===c?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:J+1}),W.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[W.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx("span",{className:"rf-min-w-0 rf-flex-1 rf-truncate rf-text-xs rf-font-medium rf-leading-5 rf-text-gray-800",title:etg(N,J),children:etg(N,J)}),N.status==="complete"?W.jsx(vIA,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):N.status==="error"?W.jsx(nIg,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):I?W.jsx(_2,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),W.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[A0B(N)," · ",b]})]})]},N.id)})})]}),W.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-gap-3 rf-border-b rf-border-gray-200 rf-px-4 rf-py-3",children:[W.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[p,W.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[c+1," of ",A.length]})]}),I&&W.jsx("button",{type:"button",onClick:()=>t(null),disabled:l,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:l?"Following latest":"Follow latest"}),W.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(N=>W.jsx("button",{type:"button","aria-pressed":w===N,disabled:N==="input"?!y:!D,onClick:()=>o(N),className:no("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",w===N?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:N==="input"?"Input":"Output"},N))})]}),W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-px-4 rf-py-2 rf-text-xs rf-text-gray-600",children:[W.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx("input",{type:"checkbox",checked:C,disabled:w!=="output",onChange:N=>Q(N.target.checked),className:"rf-accent-blue-600"}),W.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:Itg}}),"Highlight changes (all layers)"]}),W.jsxs("span",{children:[w==="input"?"Before this phase":"After this phase"," ","· ",x," traces"]})]}),S&&W.jsx("div",{className:no("rf-border-y rf-px-4 rf-py-2 rf-text-xs",h.status==="error"?"rf-border-red-100 rf-bg-red-50 rf-text-red-700":"rf-border-blue-100 rf-bg-blue-50 rf-text-blue-700"),role:"status",children:h.status==="error"?`Routing failed: ${h.error?.message||"No output was captured."}`:k?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),W.jsx("div",{ref:n,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:G?W.jsx(QIg,{circuitJson:G,height:s,allowEditing:!1,clickToInteractEnabled:!1,initialState:C0B,debugGraphics:m}):W.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-border-t rf-border-gray-200 rf-px-4 rf-py-3 rf-text-xs rf-text-gray-500",children:[W.jsxs("span",{children:[R===void 0?"Input unavailable":`${R} input connections`,` · ${g1I(h)}`]}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[W.jsxs("button",{type:"button",disabled:!u,onClick:()=>Dk(JSON.stringify(u,null,2),{fileName:`${h.id}-${w}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[W.jsx(qIA,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),W.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>E(!i),className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(v7,{className:no("rf-h-3 rf-w-3",i&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),i&&W.jsx("pre",{className:"rf-m-0 rf-max-h-64 rf-overflow-auto rf-border-t rf-border-gray-200 rf-bg-gray-50 rf-p-4 rf-text-xs","aria-label":`${p} ${w} SRJ`,children:u?JSON.stringify(u,null,2):"No snapshot captured."})]})]})},e1I=({errorMessage:g,errorStack:A,circuitJsonErrors:I})=>{gA.useEffect(()=>{if(wx("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&g){const e=new Error(g);A&&(e.stack=A);try{n9.captureException(e)}catch{}}},[g,A]),gA.useEffect(()=>{if(wx("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&I&&I.length>0)for(const e of I){const t=new Error(e.message||"Circuit JSON Error");e.stack&&(t.stack=e.stack);try{n9.captureException(t,{error_type:e.type})}catch{}}},[I])},i0B=g=>{gA.useEffect(()=>{try{iVI(g)}catch{}},[g.source,g.component,g.isWebEmbedded,g.activeTab])},t1I="0.0.2984",E0B={version:t1I},ttg={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Btg=new Map,MuA=g=>{const A=Btg.get(g);return A?Object.fromEntries(Object.entries(A.stores).map(([I,e])=>[I,e.getState()])):{}},n0B=(g,A,I)=>{if(g===void 0)return{type:"untracked",connection:A.connect(I)};const e=Btg.get(I.name);if(e)return{type:"tracked",store:g,...e};const t={connection:A.connect(I),stores:{}};return Btg.set(I.name,t),{type:"tracked",store:g,...t}},B1I=(g,A={})=>(I,e,t)=>{const{enabled:B,anonymousActionType:o,store:C,...Q}=A;let i;try{i=(B??(ttg?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!i)return(ttg?"production":void 0)!=="production"&&B&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),g(I,e,t);const{connection:E,...n}=n0B(C,i,Q);let s=!0;t.setState=(c,h,l)=>{const D=I(c,h);if(!s)return D;const d=l===void 0?{type:o||"anonymous"}:typeof l=="string"?{type:l}:l;return C===void 0?(E?.send(d,e()),D):(E?.send({...d,type:`${C}/${d.type}`},{...MuA(Q.name),[C]:t.getState()}),D)};const r=(...c)=>{const h=s;s=!1,I(...c),s=h},a=g(t.setState,e,t);if(n.type==="untracked"?E?.init(a):(n.stores[n.store]=t,E?.init(Object.fromEntries(Object.entries(n.stores).map(([c,h])=>[c,c===n.store?a:h.getState()])))),t.dispatchFromDevtools&&typeof t.dispatch=="function"){let c=!1;const h=t.dispatch;t.dispatch=(...l)=>{(ttg?"production":void 0)!=="production"&&l[0].type==="__setState"&&!c&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),c=!0),h(...l)}}return E.subscribe(c=>{var h;switch(c.type){case"ACTION":if(typeof c.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return otg(c.payload,l=>{if(l.type==="__setState"){if(C===void 0){r(l.state);return}Object.keys(l.state).length!==1&&console.error(`
|
|
5673
|
+
`,n=new Blob([E],{type:"text/plain"}),s=URL.createObjectURL(n),r=document.createElement("a");r.href=s,r.download=`${i}.test.ts`,r.click(),URL.revokeObjectURL(s)}catch(Q){alert(`Error generating test.ts for ${g.getSolverName()}: ${Q instanceof Error?Q.message:String(Q)}`)}e(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:t,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>e(!I),title:`Download options for ${g.getSolverName()}`,children:g.getSolverName()}),I&&W.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:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:B,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:C,children:"Download test.ts"})]})]})},qNI=g=>g.activeSubSolver?[g,...qNI(g.activeSubSolver)]:[g],MhB=({solver:g})=>{const A=qNI(g);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((I,e)=>W.jsxs("div",{className:"flex items-center",children:[e>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(khB,{solver:I})]},I.getSolverName()))})},ShB=({solver:g,triggerRender:A,animationSpeed:I=25,renderer:e,onRendererChange:t,onAnimationSpeedChange:B,onDownloadVisualization:o,onSolverStarted:C,onSolverCompleted:Q})=>{const[i,E]=gA.useReducer(m=>!m,!1),n=gA.useRef(void 0),s=gA.useRef(null),r="solver-debugger-last-iteration",[a,c]=gA.useState(null),h=gA.useRef(null),l=gA.useMemo(()=>[{label:"Slow",value:250,description:"250ms"},{label:"Normal",value:100,description:"100ms"},{label:"Fast",value:10,description:"10ms"},{label:"Fast (2x)",value:5,description:"5ms"},{label:"Fast (10x)",value:1,description:"1ms"},{label:"Fast 20x",value:.5,description:"2 steps / 1ms"},{label:"Fast 100x",value:.1,description:"10 steps / 1ms"}],[]),D=()=>{const m=Math.max(1,I),p=I<1?Math.round(1/I):1;n.current=setInterval(()=>{if(g.solved||g.failed){n.current&&(clearInterval(n.current),n.current=void 0),E(),A(),Q&&g.solved&&Q(g);return}for(let k=0;k<p&&!(g.solved||g.failed);k++)g.step();A()},m)},d=()=>{n.current&&(clearInterval(n.current),n.current=void 0)},y=()=>{!g.solved&&!g.failed&&(g.step(),A())},w=()=>{!g.solved&&!g.failed&&(C&&C(g),g.solve(),A(),Q&&Q(g))},u=()=>{i?(d(),E()):(E(),D())},G=()=>{if(g.solved||g.failed||i)return;s.current===null&&typeof window<"u"&&(s.current=window.localStorage.getItem(r));const m=window.prompt("Step until which iteration?",s.current??`${g.iterations}`);if(m===null)return;s.current=m,typeof window<"u"&&window.localStorage.setItem(r,m);const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;g.iterations<p&&!g.solved&&!g.failed;)g.step();A(),g.solved&&Q&&Q(g)};return gA.useEffect(()=>()=>{d()},[]),gA.useEffect(()=>{(g.solved||g.failed)&&i&&(d(),E())},[g.solved,g.failed,i]),gA.useEffect(()=>{i&&(d(),D())},[I,i]),gA.useEffect(()=>{if(typeof document>"u")return;const m=p=>{h.current&&!h.current.contains(p.target)&&c(null)};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[]),W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsxs("div",{className:"flex items-center gap-2",ref:h,children:[W.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="renderer"?null:"renderer"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="renderer"?"open":"closed",children:"Renderer"}),a==="renderer"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[10rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:["vector","canvas"].map(m=>W.jsxs("button",{type:"button",onClick:()=>{t(m),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m==="vector"?"Vector":"Canvas",e===m&&W.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},m))})]}),W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="debug"?null:"debug"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="debug"?"open":"closed",children:"Debug"}),a==="debug"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:W.jsx("button",{type:"button",onClick:()=>{o(),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="animation"?null:"animation"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="animation"?"open":"closed",children:"Animation"}),a==="animation"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:l.map(m=>W.jsxs("button",{type:"button",onClick:()=>{B(m.value),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m.label,W.jsx("span",{className:"ml-auto text-xs text-slate-500",children:m.description}),I===m.value&&W.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},m.value))})]})]}),W.jsx(MhB,{solver:g})]})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:y,disabled:g.solved||g.failed||i,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:w,disabled:g.solved||g.failed||i,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:u,disabled:g.solved||g.failed,className:`px-3 py-1 rounded text-white text-sm ${i?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:i?"Stop":"Animate"}),W.jsx("button",{onClick:G,disabled:g.solved||g.failed||i,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"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",g.iterations]}),g.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(g.timeToSolve/1e3).toFixed(3),"s"]}),g.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),g.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),g.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",g.error]})]})},fhB=g=>g!==null&&"pipelineDef"in g&&Array.isArray(g.pipelineDef),RhB=(g,A,I)=>{const e=g.currentPipelineStageIndex;return A<e?"Completed":A===e&&g.activeSubSolver?g.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},NhB=(g,A)=>{const e=g.pipelineDef[A].solverName,t=RhB(g,A),B=g[e],o=g.firstIterationOfStage?.[e]??(A===g.currentPipelineStageIndex?g.iterations:null),C=g.iterations;let Q=0;if(t==="Completed"){const s=g.pipelineDef[A+1],r=s?g.firstIterationOfStage?.[s.solverName]:void 0;r!==void 0&&o!==null?Q=r-o:o!==null&&(Q=C-o)}else t==="In Progress"&&o!==null&&(Q=C-o);const i=g.timeSpentOnStage?.[e]??0;let E=0;t==="Completed"?E=1:t==="In Progress"&&B&&(E=B.progress??0);const n=B?.stats??null;return{index:A,name:e,status:t,firstIteration:o,iterations:Q,progress:E,timeSpent:i,stats:n&&Object.keys(n).length>0?n:null,solverInstance:B??null}},FhB=({status:g})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[g]}`,children:g})},xhB=({progress:g})=>{if(g===0)return null;const A=Math.round(g*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},TNI=g=>{if(typeof g=="string")return g;if(typeof g=="number"||typeof g=="boolean"||typeof g=="bigint"||g==null)return String(g);if(typeof g=="object")try{return JSON.stringify(g)}catch{return String(g)}return String(g)},UhB=g=>Object.entries(g).map(([A,I])=>`${A}: ${TNI(I)}`).join(", "),JhB=({stats:g})=>{if(!g||Object.keys(g).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(g),I=UhB(g);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:I}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([e,t])=>W.jsxs("div",{children:[e,": ",TNI(t)]},e))})]})},Atg=g=>{if(g===null||typeof g!="object")return g;if(Array.isArray(g))return g.map(Atg);const A={};for(const[I,e]of Object.entries(g))I.startsWith("_")||(A[I]=Atg(e));return A},KhB=(g,A)=>{try{if(typeof g.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const I=Atg(g.getConstructorParams()),e=new Blob([JSON.stringify(I,null,2)],{type:"application/json"}),t=URL.createObjectURL(e),B=document.createElement("a");B.href=t,B.download=`${A}_input.json`,B.click(),URL.revokeObjectURL(t)}catch(I){alert(`Error downloading input for ${A}: ${I instanceof Error?I.message:String(I)}`)}},PhB=({expanded:g})=>W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:`w-4 h-4 transition-transform duration-200 ${g?"rotate-90":""}`,children:W.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"})}),ZNI=g=>{let A=g;for(;A.activeSubSolver;)A=A.activeSubSolver;return A},ONI=({solver:g,onStepUntilPhase:A,onDownloadInput:I,isNested:e=!1,indentLevel:t=0,triggerRender:B})=>{const[o,C]=gA.useState(new Set),Q=g.pipelineDef.map((h,l)=>NhB(g,l)),i=h=>{C(l=>{const D=new Set(l);return D.has(h)?D.delete(h):D.add(h),D})},E=h=>{A?.(h)},n=h=>{h.solverInstance&&(I?I(h.solverInstance,h.name):KhB(h.solverInstance,h.name))},s=h=>`${(h/1e3).toFixed(2)}s`,r=()=>{if(!g.solved&&!g.failed){const h=g.activeSubSolver;for(;!g.solved&&!g.failed&&(g.step(),!(g.activeSubSolver&&g.activeSubSolver!==h)););B?.()}},a=()=>{if(!g.solved&&!g.failed){const h=ZNI(g);for(;!g.solved&&!g.failed&&(g.step(),ZNI(g)===h););B?.()}},c=t*24;return W.jsxs("div",{className:e?"":"border-t border-gray-200",children:[!e&&W.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),W.jsxs("div",{className:"flex gap-2",children:[W.jsx("button",{onClick:a,disabled:g.solved||g.failed,className:"bg-indigo-500 hover:bg-indigo-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Solver"}),W.jsx("button",{onClick:r,disabled:g.solved||g.failed,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Stage"})]})]}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[!e&&W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:Q.map(h=>{const l=fhB(h.solverInstance),D=o.has(h.name);return W.jsxs(nC.Fragment,{children:[W.jsxs("tr",{className:`border-b border-gray-100 ${h.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:c},children:[l?W.jsx("button",{onClick:()=>i(h.name),className:"text-gray-500 hover:text-gray-700",title:D?"Collapse":"Expand",children:W.jsx(PhB,{expanded:D})}):W.jsx("span",{className:"w-4"}),W.jsx("span",{className:"text-gray-400 w-6",children:String(h.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>E(h.name),disabled:h.status==="Completed"||g.solved||g.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${h.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.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"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:h.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(FhB,{status:h.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:h.firstIteration!==null?h.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:h.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(xhB,{progress:h.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(h.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(JhB,{stats:h.stats})}),W.jsx("td",{className:"px-4 py-2",children:h.solverInstance?W.jsxs("button",{onClick:()=>n(h),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${h.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.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"})}),W.jsx("span",{children:"Input"})]}):null})]}),l&&D&&W.jsx("tr",{children:W.jsx("td",{colSpan:8,className:"p-0",children:W.jsx(ONI,{solver:h.solverInstance,onStepUntilPhase:A,onDownloadInput:I,isNested:!0,indentLevel:t+1,triggerRender:B})})})]},h.name)})})]})})]})};function LhB({graphics:g}){const A=g.points??[],I=g.lines??[],e=g.rects??[],t=g.circles??[],B=g.texts??[];let o=Number.POSITIVE_INFINITY,C=Number.POSITIVE_INFINITY,Q=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;const E=(h,l)=>{typeof h=="number"&&(h<o&&(o=h),h>Q&&(Q=h)),typeof l=="number"&&(l<C&&(C=l),l>i&&(i=l))};for(const h of A)E(h.x,h.y);for(const h of I){const l=h.points??[];for(const D of l)E(D.x,D.y)}for(const h of e){const l=h.x??0,D=h.y??0,d=h.width??0,y=h.height??0;E(l,D),E(l+d,D+y)}for(const h of t){const l=h.x??0,D=h.y??0,d=h.radius??1;E(l-d,D-d),E(l+d,D+d)}for(const h of B)E(h.x,h.y);(!isFinite(o)||!isFinite(C)||!isFinite(Q)||!isFinite(i))&&(o=-20,C=-20,Q=20,i=20);const n=10,s=o-n,r=C-n,a=Math.max(1,Q-o+2*n),c=Math.max(1,i-C+2*n);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${s} ${r} ${a} ${c}`,role:"img","aria-label":"Graphics fallback",children:[e.map((h,l)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${l}`)),I.map((h,l)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(D=>`${D.x??0},${D.y??0}`).join(" ")},`line-${l}`)),t.map((h,l)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${l}`)),A.map((h,l)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${l}`)),B.map((h,l)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${l}`))]})}var YhB=class extends nC.Component{constructor(g){super(g),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(g){console.error("InteractiveGraphics render error:",g)}render(){return this.state.hasError?this.props.fallback:this.props.children}},_hB=({solver:g,createSolver:A,animationSpeed:I=25,onSolverStarted:e,onSolverCompleted:t})=>{const[B,o]=gA.useReducer(D=>D+1,0),[C]=gA.useState(()=>{if(A)return A();if(!g)throw new Error("GenericSolverDebugger requires solver or createSolver");return g}),[Q,i]=gA.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[E,n]=gA.useState(I),s=gA.useMemo(()=>{try{return C.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(D){return console.error("Visualization error:",D),{points:[],lines:[],rects:[],circles:[]}}},[C,B]),r=gA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);gA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const D=document.createElement("script");D.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(D)}},[]),gA.useEffect(()=>{n(I)},[I]);const a=C.pipelineDef!==void 0,c=D=>{const d=C;if(!C.solved&&!C.failed){for(;!C.solved&&!C.failed&&d.currentPipelineStageIndex<=d.pipelineDef.findIndex(y=>y.solverName===D);)C.step();o()}},h=()=>{const D=JSON.stringify(s,null,2),d=new Blob([D],{type:"application/json"}),y=URL.createObjectURL(d),w=document.createElement("a");w.download="visualization.json",w.href=y,document.body.appendChild(w),w.click(),document.body.removeChild(w),URL.revokeObjectURL(y)},l=D=>{i(D),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",D)};return W.jsxs("div",{children:[W.jsx(ShB,{solver:C,triggerRender:o,animationSpeed:E,renderer:Q,onRendererChange:l,onAnimationSpeedChange:n,onDownloadVisualization:h,onSolverStarted:e,onSolverCompleted:t}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(YhB,{fallback:W.jsx(LhB,{graphics:s}),children:Q==="canvas"?W.jsx(phB,{graphics:s}):W.jsx(uhB,{graphics:s})}),a&&W.jsx(ONI,{solver:C,onStepUntilPhase:c,triggerRender:o})]})};const bhB=()=>{gA.useEffect(()=>{const g="tailwind-cdn-script";if(document.getElementById(g)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const I=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),I)return;const e=document.createElement("script");e.id=g,e.src="https://cdn.tailwindcss.com",document.head.appendChild(e)},[])},HhB=1e3,Dk=(g,A)=>{const{fileName:I,mimeType:e="text/plain"}=A,t=g instanceof Blob?g:new Blob([g],{type:e}),B=URL.createObjectURL(t),o=document.createElement("a");o.href=B,o.download=I,o.target="_blank",o.rel="noopener noreferrer",o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(()=>{URL.revokeObjectURL(B)},HhB)},gtg=g=>{let A=g.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(A)&&(A=`_${A}`),A=A.slice(0,200),A||"untitled"},vhB=g=>{const A=g.solverConstructorArgs??[g.solverParams];if(g.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||A.length!==1)return A;const[{input:I,options:e}]=A;return[I,e]},KF="https://github.com/tscircuit/tscircuit-autorouter/issues/new",WNI="https://github.com/tscircuit/copper-pour-solver/issues/new",VNI="https://github.com/tscircuit/calculate-packing/issues/new",qhB="https://github.com/tscircuit/matchpack/issues/new",jNI="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",ThB={PackSolver2:VNI,LayoutPipelineSolver:qhB,AutoroutingPipelineSolver:KF,AssignableAutoroutingPipeline2:KF,AssignableAutoroutingPipeline3:KF,AutoroutingPipeline1_OriginalUnravel:KF,AutoroutingPipelineSolver3_HgPortPointPathing:KF,AutoroutingPipelineSolver4:KF,AutoroutingPipelineSolver5:KF,AutoroutingPipelineSolver7_MultiGraph:KF,AutoroutingPipelineSolver8:KF,CopperPourPipelineSolver:WNI,SchematicTracePipelineSolver:jNI},ZhB=g=>g.toLowerCase().includes("pack")?oBB:g.toLowerCase().includes("rout")?KSI:XtB,zNI=g=>{const A=ThB[g];if(A)return A;const I=g.toLowerCase();return I.includes("autorout")?KF:I.includes("schematic")&&I.includes("trace")?jNI:I.includes("copperpour")?WNI:I.includes("pack")?VNI:null},OhB=g=>`${gtg(`${g.componentName}-${g.solverName}`)}-solver-input.json`,XNI=g=>{Dk(JSON.stringify(g.solverParams,null,2),{fileName:OhB(g),mimeType:"application/json"})},WhB=({solverEvent:g})=>{const A=zNI(g.solverName);return W.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:[W.jsxs(zE,{type:"button",variant:"outline",size:"sm",onClick:()=>XNI(g),children:[W.jsx(qIA,{className:"rf-w-4 rf-h-4"}),"Download"]}),A?W.jsx(zE,{asChild:!0,variant:"outline",size:"sm",children:W.jsxs("a",{href:A,target:"_blank",rel:"noopener noreferrer",children:[W.jsx(iwA,{className:"rf-w-4 rf-h-4"}),"Report"]})}):W.jsxs(zE,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[W.jsx(iwA,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},VhB=({solverEvent:g})=>{const A=zNI(g.solverName);return A?W.jsx(zE,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:W.jsx("a",{href:A,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:W.jsx(iwA,{className:"rf-w-4 rf-h-4"})})}):W.jsx(zE,{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:W.jsx(iwA,{className:"rf-w-4 rf-h-4"})})},jhB=({solverEvents:g=[]})=>{const[A,I]=gA.useState(null);bhB();const e=gA.useMemo(()=>{const C=new Map;for(const Q of g){const i=`${Q.componentName}-${Q.solverName}`;C.set(i,Q)}return C},[g]),t=gA.useMemo(()=>Array.from(e.keys()),[e]),B=A?e.get(A):null,o=gA.useMemo(()=>{if(!B)return{instance:null,error:null,classFound:!1};const C=d6A[B.solverName];if(!C)return{instance:null,error:`Solver class "${B.solverName}" not found in SOLVERS registry. Available: ${Object.keys(d6A).join(", ")}`,classFound:!1};try{return{instance:new C(...vhB(B)),error:null,classFound:!0}}catch(Q){const i=Q instanceof Error?Q.message:String(Q);return console.error("Failed to reconstruct solver:",Q),{instance:null,error:`Failed to instantiate solver: ${i}`,classFound:!0}}},[B]);return g.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.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."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.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:[t.length," ",t.length===1?"Solver":"Solvers"]}),t.map(C=>{const Q=e.get(C),i=A===C;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${i?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>I(C),children:(()=>{const E=ZhB(Q.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(E,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:Q.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:Q.solverName})]})]})})()},C)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:B?o.instance?W.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[W.jsx(WhB,{solverEvent:B}),W.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:W.jsx(SR,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",B.solverName]})]})}),children:W.jsx(_hB,{solver:o.instance})})})]}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:B.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",B.componentName]})]}),o.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${o.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${o.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:o.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.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:[W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(VhB,{solverEvent:B}),W.jsx(zE,{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:()=>XNI(B),children:W.jsx(qIA,{className:"rf-w-4 rf-h-4"})})]})]}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(B.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},zhB=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),XhB=new Set(["tscircuit","default","auto","auto_local"]);function $hB(g){if(g==="FanoutSolver")return"Fanout";if(g==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const A=g.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(A)return`Pipeline${A[1]}`;const I=g.match(/^AssignableAutoroutingPipeline(\d+)$/);return I?`Assignable${I[1]}`:g}function A0B(g){const A=g.autorouterName?.trim(),I=A?.replace(/-/g,"_"),e=I&&zhB.get(I);if(e)return e;if(I&&!XhB.has(I))return A;const t=g.solverName?.trim();if(t)return $hB(t);const B=g.autorouterVersion?.trim();if(B){const o=B.match(/^beta[_-]pipeline(\d+)$/);return o?`Pipeline${o[1]}`:B==="latest"?"default":B}return A?"default":"Unknown"}const Itg="#fbbf24";function g0B(g){const A=g.endSimpleRouteJson?.traces??[],I=new Set(A.flatMap(t=>[t.pcb_trace_id,t.__replaces_pcb_trace_id].filter(B=>B!==void 0)));return[...(g.startSimpleRouteJson?.traces??[]).filter(t=>!I.has(t.pcb_trace_id)),...A]}function $NI(g){const A=new Map((g.startSimpleRouteJson?.traces??[]).map(I=>[I.pcb_trace_id,I]));return(g.endSimpleRouteJson?.traces??[]).filter(I=>{const e=A.get(I.pcb_trace_id);return!e||!!I.__replaces_pcb_trace_id&&I.__replaces_pcb_trace_id!==e.__replaces_pcb_trace_id||JSON.stringify(e.route)!==JSON.stringify(I.route)}).map(I=>I.pcb_trace_id)}function I0B(g,A){return{outer_diameter:g.via_diameter??A.minViaPadDiameter??A.min_via_pad_diameter??A.minViaDiameter??.6,hole_diameter:g.via_hole_diameter??A.minViaHoleDiameter??A.min_via_hole_diameter??.3}}function A1I(g,A){const I=[];for(const C of g.route)C.route_type==="wire"?I.push({...C,layer:C.layer}):C.route_type==="via"?I.push({route_type:"via",x:C.x,y:C.y,from_layer:C.from_layer,to_layer:C.to_layer,...I0B(C,A)}):C.route_type==="through_obstacle"&&I.push({route_type:"through_pad",start:{...C.start},end:{...C.end},width:C.width,start_layer:C.from_layer,end_layer:C.to_layer,pcb_smtpad_id:C.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:C.circuitJsonMetadata?.pcb_plated_hole_id});const e=C=>{let Q=-1,i=Number.POSITIVE_INFINITY;return I.forEach((E,n)=>{if(E.route_type!=="wire")return;const s=Math.hypot(E.x-C.x,E.y-C.y);s<i&&(i=s,Q=n)}),Q},t=g.route.filter(C=>C.route_type==="jumper").map(C=>[e(C.start),e(C.end)].sort((Q,i)=>Q-i)).filter(([C,Q])=>C>=0&&Q>C).sort(([C],[Q])=>C-Q),B=[];let o=0;for(const[C,Q]of t)C>=o&&B.push(I.slice(o,C+1)),o=Math.max(o,Q);return o<I.length&&B.push(I.slice(o)),B}function e0B(g){const A=[],I=[],e=g.endSimpleRouteJson;if(!e)return{lines:A,circles:I};const t=new Set($NI(g));for(const B of e.traces??[])if(t.has(B.pcb_trace_id))for(const o of A1I(B,e)){let C;for(const Q of o){if(Q.route_type==="through_pad"){C={...Q.end,layer:Q.end_layer,width:Q.width};continue}const i=Q.route_type==="wire"?Q.layer:Q.from_layer;C&&C.layer===i&&(C.x!==Q.x||C.y!==Q.y)&&A.push({points:[{x:C.x,y:C.y},{x:Q.x,y:Q.y}],strokeWidth:Q.route_type==="wire"?Q.width:C.width,strokeColor:Itg,layer:i}),Q.route_type==="via"&&I.push({center:{x:Q.x,y:Q.y},radius:Q.outer_diameter/2,stroke:Itg,fill:"transparent"}),C={x:Q.x,y:Q.y,layer:Q.route_type==="wire"?Q.layer:Q.to_layer,width:Q.route_type==="wire"?Q.width:C?.width??e.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:A,circles:I}}function t0B(g){const A=JSON.stringify(g);let I=2166136261;for(let e=0;e<A.length;e++)I=Math.imul(I^A.charCodeAt(e),16777619);return(I>>>0).toString(36)}const B0B=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function o0B(g,A,I){const e=I==="input"?A.startSimpleRouteJson??A.errorSimpleRouteJson:A.endSimpleRouteJson,t=g.filter(i=>!B0B.has(i.type)&&!i.type.endsWith("_error")&&!i.type.endsWith("_warning"));if(!e)return t;const B=I==="input"?e.traces??[]:g0B(A),o=new Set(g.filter(i=>i.type==="source_trace").map(i=>i.source_trace_id)),C=["top",...Array.from({length:Math.max(0,e.layerCount-2)},(i,E)=>`inner${E+1}`),...e.layerCount>1?["bottom"]:[]],Q=[];for(const i of B){const n=e.connections.find(r=>r.name===i.connection_name||r.source_trace_id===i.connection_name)?.source_trace_id??i.connection_name??"",s=A1I(i,e);for(const[r,a]of s.entries()){const c={type:"pcb_trace",pcb_trace_id:`${A.id}_${I}_${i.pcb_trace_id}_${r}_${t0B(a)}`,subcircuit_id:A.subcircuit_id??void 0,source_trace_id:o.has(n)?n:void 0,route:a};Q.push(c);for(const[h,l]of a.entries()){if(l.route_type!=="via")continue;const D=C.indexOf(l.from_layer),d=C.indexOf(l.to_layer),y={type:"pcb_via",pcb_via_id:`${c.pcb_trace_id}_via_${h}`,pcb_trace_id:c.pcb_trace_id,subcircuit_id:A.subcircuit_id??void 0,x:l.x,y:l.y,outer_diameter:l.outer_diameter,hole_diameter:l.hole_diameter,layers:D>=0&&d>=0?C.slice(Math.min(D,d),Math.max(D,d)+1):[l.from_layer,l.to_layer]};Q.push(y)}}}return[...t,...Q]}const etg=(g,A)=>g.phaseName||`Phase ${g.phaseOrdinal??A+1}`,g1I=g=>g.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||g.componentDisplayName||g.subcircuit_id||"Board",I1I=g=>g.startSimpleRouteJson??g.endSimpleRouteJson??g.errorSimpleRouteJson,C0B={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},Q0B=({circuitJson:g,phases:A=[],isRunning:I=!1})=>{const[e,t]=gA.useState(null),[B,o]=gA.useState("output"),[C,Q]=gA.useState(!0),[i,E]=gA.useState(!1),n=gA.useRef(null),[s,r]=gA.useState(480),a=e?A.findIndex(N=>N.id===e.id&&I1I(N)===I1I(e)):-1,c=a<0?A.length-1:a,h=A[c],l=a<0,D=!!h?.endSimpleRouteJson,d=h?.startSimpleRouteJson??h?.errorSimpleRouteJson,y=!!d,w=B==="output"&&!D?"input":B==="input"&&!y?"output":B,u=w==="input"?d:h?.endSimpleRouteJson,G=gA.useMemo(()=>!h||!u?null:o0B(g??[],h,w),[g,h,u,w]),m=gA.useMemo(()=>h&&w==="output"&&C?e0B(h):{lines:[],circles:[]},[h,w,C]);if(gA.useLayoutEffect(()=>{const N=n.current;if(!N)return;const J=()=>r(Math.max(360,N.clientHeight));J();const L=new ResizeObserver(J);return L.observe(N),()=>L.disconnect()},[!!h]),!h)return W.jsxs("div",{className:"rf-flex rf-min-h-[400px] rf-flex-col rf-items-center rf-justify-center rf-gap-3 rf-p-8 rf-text-center",children:[W.jsx(KSI,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),W.jsx("h3",{className:"rf-text-base rf-font-medium",children:I?"Waiting for autorouting":"No autorouting captures"}),W.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:I?"Phases appear as the circuit routes. Each capture includes its input and output on the PCB.":"Run a circuit with autorouting enabled to inspect its phases. A circuit JSON file alone does not include routing history."})]});const p=etg(h,c),k=h.status==="running"&&I,S=!D,R=d?.connections.length,x=G?.filter(N=>N.type==="pcb_trace").length??0;return W.jsxs("div",{className:"rf-flex rf-h-full rf-min-h-[620px] rf-flex-col rf-bg-white md:rf-flex-row","data-testid":"autorouting-explorer",children:[W.jsxs("aside",{className:"rf-flex rf-shrink-0 rf-flex-col rf-border-b rf-border-gray-200 md:rf-w-52 md:rf-border-b-0 md:rf-border-r","aria-label":"Routing phases",children:[W.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-px-3 rf-py-2 rf-text-xs rf-text-gray-500",children:[W.jsx("span",{children:"Routing phases"}),W.jsx("span",{children:A.length})]}),W.jsx("div",{className:"rf-flex rf-gap-1 rf-overflow-x-auto rf-px-1.5 rf-pb-1.5 md:rf-flex-col md:rf-overflow-x-hidden md:rf-overflow-y-auto",children:A.map((N,J)=>{const L=$NI(N).length,b=N.endSimpleRouteJson?`${L} ${L===1?"trace":"traces"} routed`:N.status==="error"?"Failed":N.status==="running"&&I?"Routing…":"No output";return W.jsxs("button",{type:"button","aria-pressed":J===c,title:`${g1I(N)} · ${b}`,onClick:()=>t(N),className:no("rf-flex rf-min-w-[192px] rf-items-start rf-gap-2 rf-rounded-md rf-border rf-px-2 rf-py-2 rf-text-left md:rf-min-w-0",J===c?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[W.jsx("span",{className:no("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",J===c?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:J+1}),W.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[W.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx("span",{className:"rf-min-w-0 rf-flex-1 rf-truncate rf-text-xs rf-font-medium rf-leading-5 rf-text-gray-800",title:etg(N,J),children:etg(N,J)}),N.status==="complete"?W.jsx(vIA,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):N.status==="error"?W.jsx(nIg,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):I?W.jsx(_2,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),W.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[A0B(N)," · ",b]})]})]},N.id)})})]}),W.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-gap-3 rf-border-b rf-border-gray-200 rf-px-4 rf-py-3",children:[W.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[p,W.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[c+1," of ",A.length]})]}),I&&W.jsx("button",{type:"button",onClick:()=>t(null),disabled:l,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:l?"Following latest":"Follow latest"}),W.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(N=>W.jsx("button",{type:"button","aria-pressed":w===N,disabled:N==="input"?!y:!D,onClick:()=>o(N),className:no("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",w===N?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:N==="input"?"Input":"Output"},N))})]}),W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-px-4 rf-py-2 rf-text-xs rf-text-gray-600",children:[W.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx("input",{type:"checkbox",checked:C,disabled:w!=="output",onChange:N=>Q(N.target.checked),className:"rf-accent-blue-600"}),W.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:Itg}}),"Highlight changes (all layers)"]}),W.jsxs("span",{children:[w==="input"?"Before this phase":"After this phase"," ","· ",x," traces"]})]}),S&&W.jsx("div",{className:no("rf-border-y rf-px-4 rf-py-2 rf-text-xs",h.status==="error"?"rf-border-red-100 rf-bg-red-50 rf-text-red-700":"rf-border-blue-100 rf-bg-blue-50 rf-text-blue-700"),role:"status",children:h.status==="error"?`Routing failed: ${h.error?.message||"No output was captured."}`:k?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),W.jsx("div",{ref:n,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:G?W.jsx(QIg,{circuitJson:G,height:s,allowEditing:!1,clickToInteractEnabled:!1,initialState:C0B,debugGraphics:m}):W.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-border-t rf-border-gray-200 rf-px-4 rf-py-3 rf-text-xs rf-text-gray-500",children:[W.jsxs("span",{children:[R===void 0?"Input unavailable":`${R} input connections`,` · ${g1I(h)}`]}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[W.jsxs("button",{type:"button",disabled:!u,onClick:()=>Dk(JSON.stringify(u,null,2),{fileName:`${h.id}-${w}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[W.jsx(qIA,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),W.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>E(!i),className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(v7,{className:no("rf-h-3 rf-w-3",i&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),i&&W.jsx("pre",{className:"rf-m-0 rf-max-h-64 rf-overflow-auto rf-border-t rf-border-gray-200 rf-bg-gray-50 rf-p-4 rf-text-xs","aria-label":`${p} ${w} SRJ`,children:u?JSON.stringify(u,null,2):"No snapshot captured."})]})]})},e1I=({errorMessage:g,errorStack:A,circuitJsonErrors:I})=>{gA.useEffect(()=>{if(wx("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&g){const e=new Error(g);A&&(e.stack=A);try{n9.captureException(e)}catch{}}},[g,A]),gA.useEffect(()=>{if(wx("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&I&&I.length>0)for(const e of I){const t=new Error(e.message||"Circuit JSON Error");e.stack&&(t.stack=e.stack);try{n9.captureException(t,{error_type:e.type})}catch{}}},[I])},i0B=g=>{gA.useEffect(()=>{try{iVI(g)}catch{}},[g.source,g.component,g.isWebEmbedded,g.activeTab])},t1I="0.0.2986",E0B={version:t1I},ttg={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Btg=new Map,MuA=g=>{const A=Btg.get(g);return A?Object.fromEntries(Object.entries(A.stores).map(([I,e])=>[I,e.getState()])):{}},n0B=(g,A,I)=>{if(g===void 0)return{type:"untracked",connection:A.connect(I)};const e=Btg.get(I.name);if(e)return{type:"tracked",store:g,...e};const t={connection:A.connect(I),stores:{}};return Btg.set(I.name,t),{type:"tracked",store:g,...t}},B1I=(g,A={})=>(I,e,t)=>{const{enabled:B,anonymousActionType:o,store:C,...Q}=A;let i;try{i=(B??(ttg?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!i)return(ttg?"production":void 0)!=="production"&&B&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),g(I,e,t);const{connection:E,...n}=n0B(C,i,Q);let s=!0;t.setState=(c,h,l)=>{const D=I(c,h);if(!s)return D;const d=l===void 0?{type:o||"anonymous"}:typeof l=="string"?{type:l}:l;return C===void 0?(E?.send(d,e()),D):(E?.send({...d,type:`${C}/${d.type}`},{...MuA(Q.name),[C]:t.getState()}),D)};const r=(...c)=>{const h=s;s=!1,I(...c),s=h},a=g(t.setState,e,t);if(n.type==="untracked"?E?.init(a):(n.stores[n.store]=t,E?.init(Object.fromEntries(Object.entries(n.stores).map(([c,h])=>[c,c===n.store?a:h.getState()])))),t.dispatchFromDevtools&&typeof t.dispatch=="function"){let c=!1;const h=t.dispatch;t.dispatch=(...l)=>{(ttg?"production":void 0)!=="production"&&l[0].type==="__setState"&&!c&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),c=!0),h(...l)}}return E.subscribe(c=>{var h;switch(c.type){case"ACTION":if(typeof c.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return otg(c.payload,l=>{if(l.type==="__setState"){if(C===void 0){r(l.state);return}Object.keys(l.state).length!==1&&console.error(`
|
|
5674
5674
|
[zustand devtools middleware] Unsupported __setState action format.
|
|
5675
5675
|
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
5676
5676
|
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|