@tscircuit/runframe 0.0.2985 → 0.0.2986

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.
@@ -5610,11 +5610,11 @@ svg { font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif; }
5610
5610
  .simulation-line { fill: none; stroke-width: 2.5; }
5611
5611
  .simulation-point { stroke-width: 0; }
5612
5612
  .chart-title { fill: rgba(0, 0, 0, 0.85); font-size: 18px; font-weight: 600; }
5613
- `;return tE("style",{},[vR(g)])}function w1I(g,A){const I=g[A];if(typeof I=="string")return I}function bco(g,A,I,e){const o=[4,8],B=o.map(s=>co(s)).join(" "),Q=o.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=co(I(d.timeMs)),u=co(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})`,[c1I(s.graph)]:ktg(s.graph)};s.graph.source_component_id&&(c["data-source-component-id"]=s.graph.source_component_id);const h=w1I(s.graph,"source_probe_id");h&&(c["data-source-probe-id"]=h);const l=w1I(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=co(I(d.timeMs)),w=co(e(d.displayValue));return tE("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=co(a*Q);E.push(tE("path",{...r.pathAttributes,"stroke-dasharray":B,"stroke-dashoffset":c}))}const n=i.flatMap(s=>s.pointElements);return tE("g",{class:"data-series"},[...E,...n])}function Hco(g,A){return g?.name?tE("text",{class:"chart-title",x:co(A/2),y:co(Ul.top-40),"text-anchor":"middle"},[vR(g.name)]):null}var u1I=16;function vco(g,A,I,e){const t=e.map((o,B)=>tE("tspan",{x:"20",dy:B===0?"0":String(u1I)},[vR(o)]));return tE("g",{class:"legend-item",transform:`translate(${co(A)} ${co(I)})`},[tE("line",{class:"legend-line",x1:"0",y1:"0",x2:"16",y2:"0",stroke:g.color}),tE("text",{class:"legend-label",x:"20",y:"0","dominant-baseline":"middle"},t)])}var qco=15;function Tco(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 o=A[t]??"",B=`${e}_${o}`;B.length>qco?(I.push(e),e=o):e=B}return e&&I.push(e),I}var Zco=24;function Oco(g,A){let I=Ul.top;const e=g.map(t=>{const o=A-Ul.right+10,B=Tco(t.label),C=vco(t,o,I,B),Q=B.length*u1I;return I+=Math.max(Q,Zco),C});return tE("g",{class:"legend"},e)}var q5=118,eGA=94,fZ=18;function G1I(g,A){const I=Math.floor((A+fZ)/(q5+fZ)),e=Math.max(1,Math.min(I,g)),t=Math.max(1,Math.ceil(g/e)),o=e*q5+(e-1)*fZ,B=t*eGA+(t-1)*fZ;return{columns:e,rows:t,x:Math.max(0,(A-o)/2),height:B}}var tGA=20,Stg=8,Wco=14;function Vco(g,A,I){const e=G1I(g.length,A),t=[];for(const[o,B]of g.entries()){const C=o%e.columns,Q=Math.floor(o/e.columns);t.push(jco(B,o,e.x+C*(q5+fZ),I+mtg+Q*(eGA+fZ)))}return tE("g",{class:"scope-legend"},t)}function jco(g,A,I,e){const t=g.scopeTraceDisplay,o=Gk(g.graph)?"A":"V",B=t&&beA(t)?Mtg(t.valuePerDiv,o):`1 ${o}`,C=Mtg(t?.center??0,o),Q=fco(t?.offsetDivs??0),i=`Ch${A+1}`,n=[g.label===i?void 0:g.label,`${B}/div`,Q,C].filter(r=>!!r),s=n.length>1?(eGA-tGA-Stg*2-Wco)/(n.length-1):0;return tE("g",{class:"scope-channel",transform:`translate(${co(I)} ${co(e)})`,[c1I(g.graph)]:ktg(g.graph)},[tE("rect",{class:"scope-channel-card",x:"0",y:"0",width:co(q5),height:co(eGA),rx:"6",ry:"6"}),tE("rect",{x:"0",y:"0",width:co(q5),height:co(tGA),rx:"6",ry:"6",fill:g.color}),tE("rect",{x:"0",y:co(tGA-6),width:co(q5),height:"6",fill:g.color}),tE("text",{class:"scope-channel-header-text",x:co(q5/2),y:"14","text-anchor":"middle"},[vR(i)]),...n.map((r,a)=>tE("text",{class:"scope-channel-detail",x:co(Stg),y:co(tGA+Stg+a*s),"dominant-baseline":"hanging"},[vR(r)]))])}function zco(g){const A=Math.ceil(g/2),I=Math.floor(g/2);return{left:m1I(A),right:m1I(I)}}function m1I(g){if(g<=1)return 0;const A=10+(g-1)*ptg+6+pco+kco;return Math.max(0,A-Ul.left)}function p1I(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 k1I(g){return g?.type==="simulation_experiment"}function Xco(g){return g?.type==="simulation_voltage_probe"}function $co(g){return g?.type==="simulation_current_probe"}function Aho(g){return g?.type==="simulation_oscilloscope_trace"}function gho(g,A){const I=eho(g),e=h1I(g),t=Math.min(I.length,e.length),o=[],B=Iho(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)||o.push({timeMs:Q,rawValue:i,displayValue:B(i)})}return o}function Iho(g){if(!beA(g))return t=>t;const A=g.center??0,I=g.offsetDivs??0,e=g.valuePerDiv;return t=>I+(t-A)/e}function eho(g){const A=h1I(g);if(Array.isArray(g.timestamps_ms)&&g.timestamps_ms.length===A.length)return g.timestamps_ms.map(o=>Number(o));const I=A.length;if(I===0)return[];const e=[];for(let o=0;o<I;o++)e.push(g.start_time_ms+g.time_per_step*o);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 oGA(g,A){const I=g[A];if(typeof I=="string")return I}function tho(g,A,I,e){const t=Gk(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 o=oGA(g,"source_probe_name");if(o)return`${t}(${o})`;if(g.source_component_id){const B=e.get(g.source_component_id);if(B)return`${t}(${B})`}return g.name?g.name:g.source_component_id?`Probe ${g.source_component_id}`:ktg(g)}function oho(g,A,I,e,t,o){if(Gk(g)){const Q=e.get(g.simulation_transient_current_graph_id);if(Q)return Q;const i=oGA(g,"source_probe_id")??(A?.type==="simulation_current_probe"?A.simulation_current_probe_id:void 0);return i?o.get(i):void 0}const B=I.get(g.simulation_transient_voltage_graph_id);if(B)return B;const C=oGA(g,"source_probe_id")??(A?.type==="simulation_voltage_probe"?A.simulation_voltage_probe_id:void 0);return C?t.get(C):void 0}function Bho(g,A,I,e,t){const o=oGA(g,"source_probe_id");if(o){const B=Gk(g)?I.get(o):A.get(o);if(B)return B}if(g.source_component_id)return Gk(g)?t.get(g.source_component_id):e.get(g.source_component_id)}function Cho(g,A){if(A)return{displayName:A.display_name,color:A.color,center:A.display_center_value,offsetDivs:A.display_center_offset_divs,valuePerDiv:Gk(g)?A.amps_per_div:A.volts_per_div}}function Qho(g,A){const I=Array.isArray(Mh.simulation_palette)?Mh.simulation_palette:Array.isArray(Mh.palette)?Mh.palette:[],e=A.filter(Xco),t=A.filter($co),o=A.filter(Aho),B=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 o)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&&B.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=Bho(D,E,n,s,r),w=oho(D,y,a,c,h,l),u=Cho(D,w),G=gho(D,u),m=iho(I,d),p=Eho(D,y,Gk(D)?i:C),k=D.color??u?.color??p??m,S=tho(D,y,u,Gk(D)?Q:B);return{graph:D,points:G,color:k,label:S,scopeTraceDisplay:u,usesScopeTraceDisplay:beA(u)}}).filter(D=>D.points.length>0)}function iho(g,A){return g.length===0?r1I:g[A%g.length]??r1I}function Eho(g,A,I){if(A?.color)return A.color;if(g.source_component_id)return I.get(g.source_component_id)}function M1I({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:o="magnitude",width:B=Gco,height:C=mco,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=>k1I(O)&&O.simulation_experiment_id===A),a=g.filter(O=>p1I(O)&&O.simulation_experiment_id===A&&(!s||s.has(a1I(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=uco({results:a,acSweepView:o,experiment:r}),h=c.graphs;if(h.length===0)throw new Error(`No simulation analysis results found for simulation_experiment_id "${A}"`);const l=Qho(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=nho(d):c.xAxisTitle==="Time (ms)"?y=Fco({values:d,graphs:h,experiment:r}):y=gGA(d);const w=gGA(D.map(O=>O.displayValue),!0),u=l.some(O=>O.usesScopeTraceDisplay),G=u?zco(l.length):{left:0,right:0},m=B+G.left+G.right,p=u?G1I(l.length,m):null,k=p?C+mtg+p.height+mtg:C,S=Math.max(1,B-Ul.left-Ul.right),R=Math.max(1,C-Ul.top-Ul.bottom),x=Ul.left+G.left,N=y1I(y.domainMin,y.domainMax,x,x+S),J=y1I(w.domainMin,w.domainMax,Ul.top+R,Ul.top),K=Sco(A),_=quA(g),H=TuA,T=Hco(r,m),j=[_co(),Pco(m,k),Kco(K,x,S,R),Yco(x,S,R),Lco({timeAxis:y,valueAxis:w,scaleX:N,scaleY:J,plotLeft:x,plotWidth:S,plotHeight:R}),bco(l,K,N,J),xco({timeAxis:y,valueAxis:w,graphs:l,scaleX:N,scaleY:J,plotLeft:x,plotWidth:S,plotHeight:R,yAxisTitle:c.yAxisTitle??Mco(l),xAxisTitle:c.xAxisTitle,usesScopeTraceDisplay:u}),u?Vco(l,m,C):Oco(l,m),...T?[T]:[]],W=tE("svg",{xmlns:"http://www.w3.org/2000/svg",width:m.toString(),height:k.toString(),style:`background-color: ${Mh.schematic.background}`,viewBox:`0 0 ${co(m)} ${co(k)}`,"data-simulation-experiment-id":A,...r?.name&&{"data-simulation-experiment-name":r.name},..._&&{"data-software-used-string":_},...Q&&{"data-circuit-to-svg-version":H}},j);return KuA(W)}var nho=g=>{const A=gGA(g);return{...A,tickLabelOverrides:new Map(A.ticks.map(I=>[I,co(10**I)]))}},sho=1200,aho=1200,S1I=.55;function rho({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:o,width:B=sho,height:C=aho,schematicHeightRatio:Q=S1I,schematicOptions:i,includeVersion:E,graphAboveSchematic:n=!1,showErrorsInTextOverlay:s}){const r=g.filter(J=>!k1I(J)&&!p1I(J)),a=hho(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=E1I(r,{...i,width:B,height:d,includeVersion:!1,showErrorsInTextOverlay:s}),u=M1I({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:o,width:B,height:y,includeVersion:!1}),G=vNI(QX(w)),m=vNI(QX(u)),p=cho(m)??{width:B,height:y},k=p.width>0?B*(p.height/p.width):y,S=d+k,R=[];n?(R.push(WuA(m,0,0,B,k)),R.push(WuA(G,0,k,B,d))):(R.push(WuA(G,0,0,B,d)),R.push(WuA(m,0,d,B,k)));const x=quA(r),N={name:"svg",type:"element",value:"",attributes:{xmlns:"http://www.w3.org/2000/svg",width:z2(B),height:z2(S),viewBox:`0 0 ${z2(B)} ${z2(S)}`,"data-simulation-experiment-id":A,...x&&{"data-software-used-string":x},...E&&{"data-circuit-to-svg-version":TuA}},children:R};return KuA(N)}function cho(g){const A=g.attributes?.viewBox;if(typeof A!="string")return null;const I=A.trim().split(/[\s,]+/).map(o=>Number.parseFloat(o));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 hho(g){return Number.isFinite(g)?g<=0?0:g>=1?1:g:S1I}var f1I=({initialTransform:g,initialTouch1:A,initialTouch2:I,finalTouch1:e,finalTouch2:t})=>{if(!e||!t)return g;const o={x:(A.x+I.x)/2,y:(A.y+I.y)/2},B={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=B.x-o.x,n=B.y-o.y;return pc(Bi(E,n),Bi(o.x,o.y),Lu(i,i),Bi(-o.x,-o.y),g)},HeA=(g={})=>{const A=X.useRef(null),[I,e]=X.useState(0),t=g.canvasElm??A.current,[o,B]=X.useState(g.initialTransform??R4()),[C,Q]=X.useState(0),[i,E]=X.useReducer(d=>d+1,0),n=X.useCallback(d=>{g.onSetTransform&&g.onSetTransform(d),g.transform||B(d)},[g.onSetTransform,B]),s=X.useCallback(d=>{n(d),E()},[n]),r=g.transform??o,a=X.useCallback(()=>{e(Date.now())},[]),c=X.useRef("none"),h=X.useRef(null),l=X.useRef(null);X.useEffect(()=>{const d=g.canvasElm??A.current;if(d&&!t){Q(C+1);return}if(!d){const _=setTimeout(()=>{Q(C+1)},100);return()=>clearTimeout(_)}let y=g.transform??o,w={x:0,y:0},u={x:0,y:0},G=!1;const m=_=>({x:_.pageX-d.getBoundingClientRect().left-window.scrollX,y:_.pageY-d.getBoundingClientRect().top-window.scrollY});function p(_){g.enabled!==!1&&(g.shouldDrag&&!g.shouldDrag(_)||(w=m(_),!(Date.now()-I<100)&&(G=!0,_.preventDefault())))}function k(_){if(!G||g.enabled===!1||g.shouldDrag&&!g.shouldDrag(_))return;u=m(_);const H=pc(Bi(u.x-w.x,u.y-w.y),y);n(H),y=H,G=!1}function S(_){if(m(_),!G||g.enabled===!1||g.shouldDrag&&!g.shouldDrag(_))return;u=m(_);const H=pc(Bi(u.x-w.x,u.y-w.y),y);n(H)}function R(_){if(g.enabled===!1||g.shouldDrag&&!g.shouldDrag(_))return;const H=m(_),T=pc(Bi(H.x,H.y),Lu(1-_.deltaY/1e3,1-_.deltaY/1e3),Bi(-H.x,-H.y),y);n(T),y=T,_.preventDefault()}function x(_){if(!G||g.shouldDrag&&!g.shouldDrag(_))return;if(d){const T=d.getBoundingClientRect();if(_.clientX>=T.left+10&&_.clientX<=T.right-10&&_.clientY>=T.top+10&&_.clientY<=T.bottom-10)return}G=!1,u=m(_);const H=pc(Bi(u.x-w.x,u.y-w.y),y);n(H),y=H}function N(_){if(_.preventDefault(),g.enabled!==!1){if(_.touches.length===1){c.current="drag";const H=_.touches[0];h.current={initialTransform:y,initialTouch:{x:H.clientX,y:H.clientY}}}else if(_.touches.length===2){c.current="pinch";const H=_.touches[0],T=_.touches[1];l.current={initialTransform:y,initialTouch1:{x:H.clientX,y:H.clientY},initialTouch2:{x:T.clientX,y:T.clientY},finalTouch1:null,finalTouch2:null}}}}function J(_){if(_.preventDefault(),g.enabled!==!1){if(c.current==="drag"&&_.touches.length===1&&h.current){const H=_.touches[0],T={x:H.clientX,y:H.clientY},j=T.x-h.current.initialTouch.x,W=T.y-h.current.initialTouch.y,O=pc(Bi(j,W),h.current.initialTransform);n(O)}else if(c.current==="pinch"&&_.touches.length===2&&l.current){const H=_.touches[0],T=_.touches[1];l.current.finalTouch1={x:H.clientX,y:H.clientY},l.current.finalTouch2={x:T.clientX,y:T.clientY};const j=f1I(l.current);n(j)}}}function K(_){_.preventDefault();const H=_.changedTouches[0];if(c.current==="drag"&&h.current&&H){const T={x:H.clientX,y:H.clientY},j=T.x-h.current.initialTouch.x,W=T.y-h.current.initialTouch.y,O=pc(Bi(j,W),h.current.initialTransform);n(O),y=O}else if(c.current==="pinch"&&l.current){const T=f1I(l.current);n(T),y=T}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",K,{passive:!1}),d.addEventListener("touchcancel",K,{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",K),d.removeEventListener("touchcancel",K)}},[t,C,i,I,g.enabled,g.shouldDrag]);const D=X.useCallback(d=>KI(r,d),[r]);return{ref:A,transform:r,applyTransformToPoint:D,setTransform:s,cancelDrag:a}},R1I=HeA;function ftg(g){const A=sM(g),I=new Map;for(const B of A.schematic_component.list())B.source_component_id&&I.set(B.source_component_id,B.schematic_component_id);const e=new Map;for(const B of A.source_trace.list()){const C=B.subcircuit_connectivity_map_key;if(C)for(const Q of B.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 B of A.schematic_net_label.list()){if(!B.source_net_id)continue;const C=A.source_net.get(B.source_net_id)?.subcircuit_connectivity_map_key??B.source_net_id;t.set(B.schematic_net_label_id,C)}const o=new Map;for(const B of A.schematic_text.list()){if(!B.source_trace_id)continue;const C=A.source_trace.get(B.source_trace_id)?.subcircuit_connectivity_map_key;C&&o.set(B.schematic_text_id,C)}return{componentIdToKeys:e,netLabelIdToKey:t,textIdToKey:o}}var BGA=(g,A)=>Math.hypot(g.x-A.x,g.y-A.y),N1I=(g,A,I)=>{const e=I.x-A.x,t=I.y-A.y,o=e*e+t*t,B=o?Math.max(0,Math.min(1,((g.x-A.x)*e+(g.y-A.y)*t)/o)):0;return BGA(g,{x:A.x+B*e,y:A.y+B*t})},T5=(g,A,I)=>Math.abs(BGA(A,g)+BGA(g,I)-BGA(A,I))<1e-5;function lho(g,A){const I=ftg(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(o=>o.type==="schematic_trace"&&o.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(o=>o.type==="source_trace").find(o=>o.source_trace_id===t.source_trace_id)?.subcircuit_connectivity_map_key:void 0)}function Dho(g,A){const I=ftg(g),e=g.filter(n=>n.type==="source_trace"),t=g.filter(n=>n.type==="schematic_trace"),o=g.filter(n=>n.type==="schematic_sheet"),B=o[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??B,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??B,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??B,a=C.filter(c=>c.sheet===s&&c.sourceTraceId===n.source_trace_id).sort((c,h)=>N1I(n.position,c.a,c.b)-N1I(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&&(T5(r.a,a.a,a.b)||T5(r.b,a.a,a.b)||T5(a.a,r.a,r.b)||T5(a.b,r.a,r.b)||[...r.junctions??[],...a.junctions??[]].some(c=>T5(c,r.a,r.b)&&T5(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??B)===r.sheet&&n.some(d=>d.portIds?.includes(D.schematic_port_id)||T5(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=o.findIndex(D=>D.schematic_sheet_id===r.sheet);return{kind:"net",label:`${o[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 dho={async load(){const g=await lno("@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}},nS={contextMenu:110,styleAnalysis:120,viewMenu:55,viewMenuIcon:48,clickToInteractOverlay:100,schematicComponentDetailsTooltip:105,schematicComponentHoverOutline:47,schematicPortHoverOutline:48,schematicSearch:101},yho=({circuitJson:g,onClose:A})=>{const[I,e]=X.useState({status:"loading"});return X.useEffect(()=>{let t=!1;e({status:"loading"});const o=window.setTimeout(async()=>{try{const{createSchematicPlacementIssueArtifacts:B}=await dho.load();if(t)return;const C=B(g);t||e({status:"complete",artifacts:C})}catch(B){t||e({status:"error",message:B instanceof Error?B.message:String(B)})}},0);return()=>{t=!0,window.clearTimeout(o)}},[g]),q.jsx(SuA,{open:!0,onOpenChange:t=>!t&&A(),children:q.jsxs(fuA,{children:[q.jsx(meA,{style:{position:"fixed",inset:0,background:"#0008",zIndex:nS.styleAnalysis}}),q.jsxs(keA,{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:nS.styleAnalysis},children:[q.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:16},children:[q.jsx(RuA,{style:{margin:0,fontSize:22},children:"Style Analysis"}),q.jsx(gtg,{style:{cursor:"pointer",padding:"6px 12px"},children:"Close"})]}),q.jsx(NuA,{style:{color:"#525252"},children:"Placement and style issues across all schematic sheets. Each image highlights one issue with its description below."}),I.status==="loading"&&q.jsx("p",{role:"status",children:"Running style analysis…"}),I.status==="error"&&q.jsxs("p",{role:"alert",children:["Style analysis failed: ",I.message]}),I.status==="complete"&&q.jsxs(q.Fragment,{children:[q.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=>q.jsxs("section",{style:{marginTop:24,border:"1px solid #ddd",borderRadius:8,overflow:"hidden",background:"white"},children:[q.jsxs("h3",{style:{margin:16,fontSize:16},children:[t.issueIndex+1,"."," ",t.issue.lineItemType.replace(/([a-z])([A-Z])/g,"$1 $2"),t.schematicSheetId&&q.jsxs("small",{style:{display:"block",marginTop:4,color:"#525252"},children:["Sheet: ",t.schematicSheetId]})]}),q.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"},x1I=(g,A)=>{if(typeof window>"u")return A;try{const I=localStorage.getItem(g);return I!==null?JSON.parse(I):A}catch{return A}},F1I=(g,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(g,JSON.stringify(A))}catch{}},who=g=>{if(typeof window>"u")return null;try{return localStorage.getItem(g)}catch{return null}},uho=(g,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(g,A)}catch{}},U1I=["#8B0000","#2F4F4F","#191970","#006400","#FF4500","#800080","#2E8B57","#B8860B","#C71585","#008B8B"],Gho=g=>{const{svgDivRef:A,circuitJson:I,circuitJsonKey:e,showGroups:t}=g;X.useEffect(()=>{if(A.current&&A.current.querySelectorAll(".schematic-group-overlay").forEach(C=>C.remove()),!A.current||!t||!I||I.length===0)return;const o=setTimeout(()=>{if(!A.current)return;const B=A.current.querySelector("svg");if(!B)return;B.querySelectorAll(".schematic-group-overlay").forEach(Q=>Q.remove());try{const Q=sM(I).source_group?.list().filter(D=>!D.is_subcircuit)||[],i=sM(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=sM(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:U1I[y%U1I.length],depthLevel:G,hasChildren:m,sourceGroupId:d.source_group_id})}})}const c=B.viewBox.baseVal,h=B.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=mho(D.components,B);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,K=N*(1-J),_=Math.max(1,K*.2),H=D.name,T=document.createElementNS("http://www.w3.org/2000/svg","text");T.setAttribute("font-size",K.toString()),T.setAttribute("font-family","Arial, sans-serif"),T.textContent=H,B.appendChild(T);const j=T.getBBox();B.removeChild(T);const W=j.width+_*2,O=K+_*2,gA=d.minX-u,tA=d.minY-u-O,IA=document.createElementNS("http://www.w3.org/2000/svg","rect");IA.setAttribute("class","schematic-group-overlay"),IA.setAttribute("x",gA.toString()),IA.setAttribute("y",(tA-O).toString()),IA.setAttribute("width",W.toString()),IA.setAttribute("height",O.toString()),IA.setAttribute("fill","transparent"),IA.setAttribute("rx","0"),IA.setAttribute("ry","0");const QA=document.createElementNS("http://www.w3.org/2000/svg","text");QA.setAttribute("class","schematic-group-overlay"),QA.setAttribute("x",(gA+_).toString()),QA.setAttribute("y",(tA+O-_).toString()),QA.setAttribute("fill",D.color),QA.setAttribute("font-size",K.toString()),QA.setAttribute("font-family","Arial, sans-serif"),QA.setAttribute("font-weight",D.depthLevel===0?"600":"500"),QA.setAttribute("stroke",D.color),QA.setAttribute("stroke-width",Math.max(.2,K*.02).toString()),QA.textContent=H,B.appendChild(x),B.appendChild(IA),B.appendChild(QA)})}catch(Q){console.error("Error creating group overlays:",Q)}},10);return()=>clearTimeout(o)},[A,e,t])};function mho(g,A){let I=1/0,e=1/0,t=-1/0,o=-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),o=Math.max(o,i.y+i.height)}}return I===1/0?null:{minX:I,minY:e,maxX:t,maxY:o}}var Rtg="sch-net-faded",J1I="g.trace[data-subcircuit-connectivity-map-key], g.trace-overlays[data-subcircuit-connectivity-map-key]",Ntg="[data-schematic-net-label-id], [data-schematic-text-id]",pho=({svgDivRef:g,circuitJson:A,circuitJsonKey:I,enabled:e})=>{X.useEffect(()=>{const t=g.current;if(!e||!t)return;const{componentIdToKeys:o,netLabelIdToKey:B,textIdToKey:C}=ftg(A);let Q=[];const i=new Map;let E=null;const n=()=>{for(const{el:l}of Q)l.classList.remove(Rtg);Q=[],i.clear(),E=null;const h=t.querySelector("svg");if(h){for(const l of Array.from(h.querySelectorAll(J1I))){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:o.get(D)??new Set})}for(const l of Array.from(h.querySelectorAll(Ntg))){const D=B.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(Rtg,h!==null&&!D.has(h))}},r=h=>{const l=h.target;if(!(l instanceof Element)){s(null);return}const D=l.closest(`${J1I}, ${Ntg}`);if(D&&i.has(D)){s(i.get(D));return}for(const[d,y]of i){if(!d.matches(Ntg))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(Rtg)}},[g,I,e])},xtg="http://www.w3.org/2000/svg",kho=({svgDivRef:g,svgContent:A,circuitJsonKey:I})=>{const e=X.useRef(new Set);X.useLayoutEffect(()=>{e.current.clear()},[I]),X.useLayoutEffect(()=>{const t=[];for(const o of g.current?.querySelectorAll(".schematic-warning")??[]){const B=o.getAttribute("data-warning-id"),C=o.querySelector('[data-warning-reference="callout"]');if(!B||!C)continue;const Q=Array.from(o.children),i=Q.map(d=>d.style.display),E=o.getAttribute("role"),n=o.getAttribute("aria-label")??"Warning",s=document.createElementNS(xtg,"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(xtg,"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(xtg,"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),o.append(s),o.setAttribute("role","button"),o.setAttribute("tabindex","0"),o.style.cursor="pointer",o.style.outline="none";const c=()=>{const d=e.current.has(B);Q.forEach((y,w)=>{y.style.display=d?"none":i[w]}),s.style.display=d?"":"none",o.setAttribute("aria-expanded",String(!d)),o.setAttribute("aria-label",`${d?"Expand":"Minimize"} warning: ${n}`)},h=d=>{d.preventDefault(),d.stopPropagation(),e.current.has(B)?e.current.delete(B):e.current.add(B),c()},l=d=>{(d.key==="Enter"||d.key===" ")&&(d.repeat?d.preventDefault():h(d))},D=d=>d.stopPropagation();o.addEventListener("click",h),o.addEventListener("keydown",l),o.addEventListener("mousedown",D),o.addEventListener("touchstart",D),c(),t.push(()=>{o.removeEventListener("click",h),o.removeEventListener("keydown",l),o.removeEventListener("mousedown",D),o.removeEventListener("touchstart",D),s.remove(),Q.forEach((d,y)=>{d.style.display=i[y]}),E?o.setAttribute("role",E):o.removeAttribute("role"),o.setAttribute("aria-label",n),o.removeAttribute("aria-expanded"),o.removeAttribute("tabindex"),o.style.removeProperty("cursor"),o.style.removeProperty("outline")})}return()=>t.forEach(o=>o())},[g,A,I])},Ftg=g=>String(g??"").toLocaleLowerCase(),veA=(g,A)=>{const I=Ftg(g);return I===A?0:I.startsWith(A)?1:I.includes(A)?2:Number.POSITIVE_INFINITY},Mho=g=>{if(g)return String(g).replace(/^simple_/,"").replaceAll("_"," ").replace(/\b\w/g,A=>A.toLocaleUpperCase())},Sho=(g,A,I)=>{let t=Mho(g?.ftype);g?.ftype==="simple_chip"&&g.manufacturer_part_number&&(t=g.manufacturer_part_number);const o=[];g?.display_name===I&&g.name!==I&&o.push(g.name);let B=g?.display_value;if(!B&&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"){B=Q;break}}}if(B??(B=A.symbol_display_value),t&&o.push(t),B&&o.push(B),!t&&!B&&g?.manufacturer_part_number&&o.push(g.manufacturer_part_number),o.length!==0)return o.join(" · ")},fho=g=>g.type==="source_component"&&"source_component_id"in g,Rho=g=>g.type==="source_port",Nho=g=>g.type==="source_trace",xho=g=>g.type==="schematic_component",Fho=g=>g.type==="schematic_port",Uho=g=>g.type==="schematic_net_label",Jho=g=>g.type==="schematic_sheet",Utg=({schematicSheets:g,schematicSheetId:A})=>{if(!(g.length<=1||!A))return g.find(I=>I.schematic_sheet_id===A)?.name},Pho=(g,A)=>{const I=Ftg(A).trim();if(!I)return[];const e=new Map(g.filter(fho).map(E=>[E.source_component_id,E])),t=new Map(g.filter(Rho).map(E=>[E.source_port_id,E])),o=g.filter(Fho),B=g.filter(Nho),C=g.filter(Jho),Q=[],i=new Map;for(const E of g.filter(xho)){const n=E.source_component_id?e.get(E.source_component_id):void 0,s=n?.display_name??n?.name??"Component",r=Math.min(veA(n?.name,I),veA(n?.display_name,I),veA(n?.manufacturer_part_number,I));if(Number.isFinite(r)){const a={label:s,detail:Sho(n,E,s),kind:"component",schematicSheetId:E.schematic_sheet_id,schematicSheetName:Utg({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(Uho)){if(!Ftg(E.text).includes(I))continue;const n=new Set;for(const d of B.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=o.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:Utg({schematicSheets:C,schematicSheetId:E.schematic_sheet_id}),target:{type:"schematic_net_label",id:E.schematic_net_label_id}};Q.push(D),i.set(D,veA(E.text,I))}for(const E of g){if(E.type!=="schematic_text"||!E.source_trace_id)continue;const n=veA(E.text,I);if(!Number.isFinite(n))continue;const s={label:E.text,kind:"net",schematicSheetId:E.schematic_sheet_id,schematicSheetName:Utg({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))},Kho=({containerRect:g,targetRect:A,visibleProjection:I,minimumScale:e})=>{const t=I.a||1,o={x:A.left+A.width/2-g.left,y:A.top+A.height/2-g.top},B={x:(o.x-I.e)/t,y:(o.y-I.f)/t},C=Math.max(t,e);return{a:C,b:0,c:0,d:C,e:g.width/2-B.x*C,f:g.height/2-B.y*C}},Lho=1.8,P1I=350,Yho=({controller:g,circuitJson:A,circuitJsonKey:I,svgDivRef:e,containerRef:t,activeSheetId:o,hasMultipleSheets:B,handleSelectSheet:C,svgString:Q,svgToScreenProjection:i,setSvgToScreenProjection:E,setIsInteractionEnabled:n})=>{const[s,r]=X.useState(""),[a,c]=X.useState(null),h=X.useRef(null),l=X.useMemo(()=>Pho(A,s),[A,I,s]),D=X.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(K=>K.getAttribute(k)===G.target.id);if(!S)return!1;let R=S.getBoundingClientRect();if(G.focusPoint){const K=S.closest("svg"),_=K?.getAttribute("data-real-to-screen-transform"),H=K?.getScreenCTM?.();if(_&&H){const T=OI(H,OI(JRI(_),G.focusPoint));R={left:T.x-1,top:T.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=JRI(J),m.style.transition="none",m.style.transform=J,m.offsetWidth}catch{}return m.style.transition=`transform ${P1I}ms ease-in-out`,m.offsetWidth,E(Kho({containerRect:x,targetRect:R,visibleProjection:N,minimumScale:Lho})),h.current=setTimeout(()=>{m.style.transition=""},P1I),m.querySelectorAll(".schematic-search-match").forEach(K=>K.classList.remove("schematic-search-match")),m.querySelectorAll(`[${k}]`).forEach(K=>{K.getAttribute(k)===G.target.id&&K.classList.add("schematic-search-match")}),!0},[t,E,e,i]),d=X.useCallback(G=>{if(n(!0),G.schematicSheetId&&G.schematicSheetId!==o&&B){C(G.schematicSheetId),c(G);return}D(G)},[o,D,C,B,n]),y=X.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 X.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&&B&&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,B,C,n]),X.useEffect(()=>{if(!a||!Q||B&&a.schematicSheetId&&a.schematicSheetId!==o)return;const G=requestAnimationFrame(()=>{D(a)&&(c(null),w?.schematicComponentId===a.target.id&&u?.(w))});return()=>cancelAnimationFrame(G)},[D,w,u,a,Q,B,o]),X.useEffect(()=>{s||e.current?.querySelectorAll(".schematic-search-match").forEach(G=>G.classList.remove("schematic-search-match"))},[s,e]),X.useEffect(()=>()=>{h.current&&clearTimeout(h.current)},[]),{searchQuery:s,setSearchQuery:r,searchResults:l,handleSearchResultSelect:d,handleCancelSearch:y}};mE("schematic-viewer");var _ho=()=>{mE.enable("schematic-viewer*")},K1I=g=>{const[A,I]=X.useState(0),[e,t]=X.useState(0);return X.useEffect(()=>{if(!g.current)return;const o=()=>{const C=g.current?.getBoundingClientRect();I(C?.width||0),t(C?.height||0)};o();const B=new ResizeObserver(o);return B.observe(g.current),window.addEventListener("resize",o),()=>{B.disconnect(),window.removeEventListener("resize",o)}},[]),{containerWidth:A,containerHeight:e}},bho=600,CGA=10,Hho=({containerRef:g})=>{const[A,I]=X.useState(null),[e,t]=X.useState(!1),[o,B]=X.useState({x:0,y:0}),C=X.useRef(null),Q=X.useRef(null),i=X.useRef(null),E=X.useRef(0),n=X.useCallback(()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null)},[]),s=X.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)>CGA||Math.abs(l.clientY-D.y)>CGA;Q.current=null,!d&&(I(l.target instanceof Element?l.target:null),B({x:l.clientX,y:l.clientY}),t(!0))},[]),r=X.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();B({x:w.left+w.width/2,y:w.top+w.height/2}),t(!0),E.current=Date.now()+1e3,Q.current=null},bho)},[n,g]),a=X.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)>CGA||Math.abs(d.clientY-D.y)>CGA)&&(Q.current=null,n())},[n]),c=X.useCallback(()=>{n(),Q.current=null},[n]),h=X.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 X.useEffect(()=>{if(e)return document.addEventListener("mousedown",h),document.addEventListener("touchstart",h),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("touchstart",h)}},[h,e]),X.useEffect(()=>n,[n]),{menuVisible:e,menuTarget:A,menuPos:o,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}}},vho=(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(([B,C])=>{if(!C)return!1;const Q=t[`${B}_ids`];return t[`${B}_id`]===C||Array.isArray(Q)&&Q.includes(C)||t.schematic_element_type===B&&t.schematic_element_id===C})}),qho=new Set(["type","source_component_id","source_group_id","subcircuit_id","display_name","ftype","are_pins_interchangeable","supplier_part_numbers"]),L1I=["name","resistance","capacitance","inductance","frequency","voltage","current","max_voltage_rating","max_current_rating","power_rating","manufacturer_part_number"],Tho={jlcpcb:g=>`https://jlcpcb.com/partdetail/${encodeURIComponent(g)}`,lcsc:g=>`https://www.lcsc.com/product-detail/${encodeURIComponent(g)}.html`},Zho=g=>{const A=g.trim(),I=/^c?(\d+)$/i.exec(A);return I?`C${I[1]}`:A},Y1I=g=>{const A=L1I.indexOf(g);return A===-1?L1I.length:A},Oho=(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)},Who=g=>Object.entries(g).filter(([A,I])=>qho.has(A)||A.startsWith("display_")&&A.slice(8)in g?!1:I!=null&&I!=="").sort(([A],[I])=>Y1I(A)-Y1I(I)||A.localeCompare(I)).map(([A,I])=>({key:A,label:A,value:Oho(g,A,I)})),Vho=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(o=>!!(typeof o=="string"&&o.trim())).map(Zho))];return t.length?[{key:`supplier_part_numbers.${I}`,label:I,links:t.map(o=>({partNumber:o,href:Tho[I](o)}))}]:[]}):[]},jho=(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),o=g.find(Q=>Q.type==="cad_component"&&Q.source_component_id===e.source_component_id&&(!t||Q.pcb_component_id===t.pcb_component_id)),B=t?.footprinter_string??o?.footprinter_string,C=t?zho(g,t.pcb_component_id):null;return{schematicComponent:I,sourceComponent:e,pcbComponent:t,footprinterString:B,footprintPreviewCircuitJson:C?.circuitJson,footprintPreviewViewBox:C?.viewBox,warnings:vho(g,I,t)}},QGA=2,zho=(g,A)=>{const I=g.find(o=>o.type==="pcb_component"&&o.pcb_component_id===A);if(!I)return null;const e=_RI(I);if(!e)return null;const t={minX:e.minX-QGA,minY:e.minY-QGA,maxX:e.maxX+QGA,maxY:e.maxY+QGA};return{circuitJson:fno(g,t),viewBox:t}},Xho=(g,A)=>{const I=iro(g,{width:320,height:240,viewport:A,backgroundColor:"#f8fafc",includeVersion:!1});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(I)}`},_1I=(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 o=A.find(i=>i.type==="schematic_text"&&i.schematic_text_id===e),B=A.find(i=>i.type==="schematic_port"&&!!t&&(i.schematic_port_id===t||i.source_port_id===t)),C=I??(o?.type==="schematic_text"?o.schematic_component_id:void 0)??(B?.type==="schematic_port"?B.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},$ho=(g,A)=>{const I=_1I(g,A);if(!I)return;const e=A.find(o=>o.type==="source_component"&&o.source_component_id===I.source_component_id),t=A.find(o=>o.type==="pcb_component"&&o.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}},Jtg=X.createContext(null),A0o=5,g0o=(g,A)=>!g&&!A?!0:!g||!A?!1:g.minX===A.minX&&g.maxX===A.maxX&&g.minY===A.minY&&g.maxY===A.maxY,I0o=({children:g})=>X.useContext(Jtg)?q.jsx(q.Fragment,{children:g}):q.jsx(e0o,{children:g}),e0o=({children:g})=>{const A=X.useRef({pointer:null,boundingBoxes:new Map,hoveringIds:new Set,subscribers:new Set,mouseDownPosition:null}),I=X.useCallback(()=>{for(const E of A.current.subscribers)E()},[]),e=X.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=X.useCallback((E,n)=>{A.current.boundingBoxes.set(E,n),e()},[e]),o=X.useCallback((E,n)=>{const s=A.current.boundingBoxes.get(E);s&&g0o(s.bounds,n.bounds)&&s.onClick===n.onClick||(A.current.boundingBoxes.set(E,n),e())},[e]),B=X.useCallback(E=>{A.current.boundingBoxes.delete(E)&&e()},[e]),C=X.useCallback(E=>(A.current.subscribers.add(E),()=>{A.current.subscribers.delete(E)}),[]),Q=X.useCallback(E=>A.current.hoveringIds.has(E),[]);X.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))>A0o){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=X.useMemo(()=>({registerBoundingBox:t,updateBoundingBox:o,unregisterBoundingBox:B,subscribe:C,isHovering:Q}),[t,o,B,C,Q]);return q.jsx(Jtg.Provider,{value:i,children:g})},NZ=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},t0o=g=>{const A=NZ(g);if(A!==null)return A;if(typeof g!="string")return null;try{const I=JSON.parse(g);if(Array.isArray(I))return NZ(I[0]?.price)}catch{return g.split(",").map(e=>{const[t,o]=e.split(":");return{quantity:NZ(t?.split("-")[0]),price:NZ(o)}}).filter(e=>e.quantity!==null&&e.price!==null).sort((e,t)=>e.quantity-t.quantity)[0]?.price??null}return null},o0o=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 o=t.components.find(B=>B&&String(B.lcsc).replace(/^c/i,"")===g.replace(/^c/i,""));return o?{price:NZ(o.price1)??t0o(o.price),stock:NZ(o.stock)}:null},B0o=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"})},C0o=({partNumber:g,platformConfig:A})=>{const[I,e]=X.useState(null),[t,o]=X.useState(!0),B=A?.partsEngine,C=A?.platformFetch;return X.useEffect(()=>{const Q=new AbortController;let i=!0;o(!0),e(null);const E=setTimeout(()=>{Q.abort(),i&&o(!1)},1e4);return Promise.resolve().then(async()=>B?.fetchPartAvailability?await B.fetchPartAvailability({supplierName:"jlcpcb",supplierPartNumber:g,signal:Q.signal,platformFetch:C})??null:o0o(g,Q.signal,C)).then(n=>{i&&e(n)}).catch(()=>{}).finally(()=>{clearTimeout(E),i&&o(!1)}),()=>{i=!1,clearTimeout(E),Q.abort()}},[g,B,C]),q.jsx("span",{role:"status","aria-label":`${g} price and stock`,"aria-busy":t,style:{display:"block",color:"#64748b",marginTop:"2px"},children:t?q.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[q.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:q.jsx("circle",{cx:"6",cy:"6",r:"4",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeDasharray:"18 8",children:q.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 6 6",to:"360 6 6",dur:"1s",repeatCount:"indefinite"})})}),"Loading price and stock…"]}):q.jsxs(q.Fragment,{children:[q.jsx("span",{style:{display:"block"},children:B0o(I)}),q.jsx("span",{style:{display:"block"},children:I?.stock!=null?`${I.stock.toLocaleString("en-US")} in stock`:"Stock unavailable"})]})})},Ptg={color:"#64748b",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45},Q0o=({platformConfig:g,sourceComponent:A,warnings:I=[],footprinterString:e,footprintPreviewCircuitJson:t,footprintPreviewViewBox:o,left:B,top:C,width:Q,maxHeight:i})=>{const E=X.useMemo(()=>Who(A),[A]),n=X.useMemo(()=>Vho(A),[A]),s=X.useMemo(()=>t?.length&&o?Xho(t,o):void 0,[t,o]);return q.jsxs("dialog",{open:!0,"aria-label":`${A.name} component details`,"data-schematic-component-details-tooltip":!0,style:{position:"absolute",left:B,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:nS.schematicComponentDetailsTooltip},onMouseDown:r=>r.stopPropagation(),onClick:r=>r.stopPropagation(),onWheel:r=>r.stopPropagation(),children:[q.jsxs("dl",{style:{display:"grid",gridTemplateColumns:"minmax(110px, 0.8fr) minmax(0, 1.2fr)",gap:"6px 12px",margin:0,padding:"8px"},children:[E.map(r=>q.jsxs("div",{style:{display:"contents"},children:[q.jsx("dt",{style:Ptg,children:r.label}),q.jsx("dd",{style:{minWidth:0,margin:0,color:"#1e293b",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45,overflowWrap:"anywhere"},children:r.value})]},r.key)),n.map(r=>q.jsxs("div",{style:{display:"contents"},children:[q.jsx("dt",{style:Ptg,children:r.label}),q.jsx("dd",{style:{minWidth:0,margin:0,fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45,overflowWrap:"anywhere"},children:r.links.map((a,c)=>q.jsxs("span",{style:r.label==="jlcpcb"?{display:"block",marginTop:c>0?6:0}:void 0,children:[r.label!=="jlcpcb"&&c>0&&", ",q.jsx("a",{href:a.href,target:"_blank",rel:"noreferrer noopener",style:{color:"#2563eb",textDecoration:"underline"},children:a.partNumber}),r.label==="jlcpcb"&&q.jsx(C0o,{partNumber:a.partNumber,platformConfig:g},`${A.source_component_id}-${a.partNumber}`)]},a.href))})]},r.key)),e&&q.jsxs("div",{style:{display:"contents"},children:[q.jsx("dt",{style:Ptg,children:"footprint"}),q.jsx("dd",{style:{minWidth:0,margin:0,color:"#1e293b",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45,overflowWrap:"anywhere"},children:JSON.stringify(e)})]})]}),I.length>0&&q.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:[q.jsxs("strong",{children:["Warnings (",I.length,")"]}),q.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:"18px"},children:I.map((r,a)=>q.jsx("li",{children:r.message},`${r.type}-${a}`))})]}),s&&q.jsx("div",{style:{padding:"0 4px 4px"},children:q.jsx("div",{style:{height:"210px",overflow:"hidden",border:"1px solid #e2e8f0",borderRadius:"2px",background:"#f8fafc"},children:q.jsx("img",{src:s,alt:`${A.name}${e?` ${e}`:""} PCB footprint`,loading:"lazy",referrerPolicy:"no-referrer",style:{display:"block",width:"100%",height:"100%",objectFit:"contain"}})})})]})},b1I=g=>{const A=X.useContext(Jtg);if(!A)throw new Error("useMouseEventsOverBoundingBox must be used within a MouseTracker");const I=X.useId(),e=X.useRef(g);e.current=g;const t=X.useMemo(()=>B=>{e.current.onClick?.(B)},[]);return X.useEffect(()=>(A.registerBoundingBox(I,{bounds:e.current.bounds,onClick:e.current.onClick?t:void 0}),()=>{A.unregisterBoundingBox(I)}),[A,t,I]),X.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:X.useSyncExternalStore(A.subscribe,()=>A.isHovering(I),()=>!1)}},i0o=(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,E0o=({componentId:g,svgDivRef:A,containerRef:I,onComponentClick:e,onHoverChange:t,showOutline:o,circuitJsonKey:B})=>{const[C,Q]=X.useState(null),i=X.useRef(null),E=X.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=>i0o(u,w)?u:w)},[g,I,A]),n=X.useCallback(()=>{i.current===null&&(i.current=window.requestAnimationFrame(E))},[E]);X.useEffect(()=>{n()},[n,B]),X.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=X.useCallback(h=>{e&&e(g,h)},[g,e]),r=C?.bounds??null,{hovering:a}=b1I({bounds:r,onClick:e?s:void 0});if(X.useEffect(()=>{t&&t(g,a)},[a,g,t]),!C||!a||!o)return null;const c=C.rect;return q.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:nS.schematicComponentHoverOutline}})},n0o=(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,s0o=({portId:g,portLabel:A,svgDivRef:I,containerRef:e,onPortClick:t,onHoverChange:o,showOutline:B,circuitJsonKey:C})=>{const[Q,i]=X.useState(null),E=X.useRef(null),n=X.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=>n0o(m,G)?m:G)},[g,e,I]),s=X.useCallback(()=>{E.current===null&&(E.current=window.requestAnimationFrame(n))},[n]);X.useEffect(()=>{s()},[s,C]),X.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=X.useCallback(l=>{t&&t(g,l)},[g,t]),a=Q?.bounds??null,{hovering:c}=b1I({bounds:a,onClick:t?r:void 0});if(X.useEffect(()=>{o&&o(g,c)},[c,g,o]),!Q||!B)return null;const h=Q.rect;return q.jsxs(q.Fragment,{children:[q.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:nS.schematicPortHoverOutline,transition:"border-color 0.15s, background-color 0.15s"}}),c&&A&&q.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:nS.schematicPortHoverOutline+1},children:A})]})},qeA=({children:g,size:A,strokeWidth:I})=>q.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}),H1I=g=>q.jsxs(qeA,{...g,children:[q.jsx("circle",{cx:"11",cy:"11",r:"8"}),q.jsx("path",{d:"m21 21-4.34-4.34"})]}),a0o=g=>q.jsxs(qeA,{...g,children:[q.jsx("path",{d:"M18 6 6 18"}),q.jsx("path",{d:"m6 6 12 12"})]}),r0o=g=>q.jsxs(qeA,{...g,children:[q.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),q.jsx("rect",{x:"8",y:"8",width:"8",height:"8",rx:"1"}),q.jsx("path",{d:"M7 2v2M12 2v2M17 2v2M7 20v2M12 20v2M17 20v2M2 7h2M2 12h2M2 17h2M20 7h2M20 12h2M20 17h2"})]}),c0o=g=>q.jsxs(qeA,{...g,children:[q.jsx("path",{d:"M15 6a9 9 0 0 0-9 9V3"}),q.jsx("circle",{cx:"18",cy:"6",r:"3"}),q.jsx("circle",{cx:"6",cy:"18",r:"3"})]}),h0o=g=>q.jsxs(qeA,{...g,children:[q.jsx("path",{d:"M20 4v7a4 4 0 0 1-4 4H4"}),q.jsx("path",{d:"m9 10-5 5 5 5"})]}),l0o=({text:g,query:A})=>{const I=A.trim().toLocaleLowerCase();if(!I)return g;const e=g.toLocaleLowerCase(),t=[];let o=0,B=e.indexOf(I);for(;B!==-1;)B>o&&t.push(g.slice(o,B)),t.push(q.jsx("strong",{style:{fontWeight:700},children:g.slice(B,B+I.length)},`${B}-${o}`)),o=B+I.length,B=e.indexOf(I,o);return o<g.length&&t.push(g.slice(o)),t.length>0?t:g},D0o=()=>typeof navigator>"u"?"Ctrl F":/mac/i.test(navigator.platform)?"⌘ F":"Ctrl F",d0o=({query:g,onQueryChange:A,onCancel:I,results:e,onSelect:t,viewerContainerRef:o})=>{const[B,C]=X.useState(!1),[Q,i]=X.useState(null),[E,n]=X.useState(null),s=X.useRef(null),r=X.useRef(null),a=D0o();X.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]),X.useEffect(()=>{Q&&r.current?.querySelector(`[data-search-result-id="${Q}"]`)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[Q]),X.useEffect(()=>{const p=S=>{if(S.key==="Escape"&&B){S.preventDefault(),S.stopPropagation(),S.stopImmediatePropagation(),I(),C(!1),s.current?.blur();return}S.code!=="KeyF"&&S.key.toLocaleLowerCase()!=="f"||!S.metaKey&&!S.ctrlKey||o.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}))}},[B,I,o]);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:q.jsxs("section",{children:[q.jsx("div",{style:{padding:"6px 12px 3px",backgroundColor:"#f7f7f8",color:"#777777",fontSize:"11px",fontWeight:600,letterSpacing:"0.02em",textTransform:"lowercase"},children: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=q.jsx(c0o,{size:15,strokeWidth:1.8});S.kind==="component"&&(J=q.jsx(r0o,{size:15,strokeWidth:1.8}));const K=()=>{s.current?.blur(),i(S.target.id),t(S)};return q.jsxs("button",{type:"button","data-search-result-id":S.target.id,onPointerUp:_=>{_.button===0&&K()},onClick:_=>{_.detail===0&&K()},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:[q.jsx("span",{style:{width:"26px",height:"26px",flexShrink:0,display:"grid",placeItems:"center",border:"1px solid #e5e5e5",borderRadius:"6px",backgroundColor:"#f7f7f7",color:"#666666"},children:J}),q.jsxs("span",{style:{minWidth:0,flex:1},children:[q.jsx("span",{style:{display:"block",overflow:"hidden",fontSize:"13px",fontWeight:400,lineHeight:1.25,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:q.jsx(l0o,{text:S.label,query:g})}),S.detail&&q.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&&q.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&&q.jsx("span",{title:"Press Enter to open",style:{flexShrink:0,color:"#666666",fontSize:"17px",lineHeight:1},children:q.jsx(h0o,{size:14,strokeWidth:1.8})})]},S.target.id)})]});return q.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:nS.schematicSearch,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif'},children:B?q.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:[q.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",height:"32px",boxSizing:"border-box",padding:"0 12px",borderBottom:u},children:[q.jsx(H1I,{size:15,strokeWidth:2}),q.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?q.jsx("span",{style:{flexShrink:0,color:"#888888",fontSize:"12px",whiteSpace:"nowrap"},children:w}):q.jsx("kbd",{style:{flexShrink:0,padding:"2px 5px",border:"1px solid #dddddd",borderRadius:"4px",backgroundColor:"#f7f7f7",color:"#777777",fontFamily:"inherit",fontSize:"10px",lineHeight:1.2},children:a}),B&&q.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:q.jsx(a0o,{size:16,strokeWidth:2})})]}),g&&q.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?q.jsx("div",{style:{padding:"12px",color:"#777777",fontSize:"13px"},children:"No matching components or nets"}):q.jsxs(q.Fragment,{children:[m("components",l),m("nets",D)]})})]}):q.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:q.jsx(H1I,{size:16,strokeWidth:2})})})},Ktg='system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',y0o={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:Ktg,outline:"none",zIndex:nS.viewMenu},w0o={display:"flex",alignItems:"center",gap:8,padding:"7px 10px 7px 8px",borderRadius:6,cursor:"pointer",outline:"none",userSelect:"none",color:"#111111",fontSize:13,fontFamily:Ktg},u0o={width:16,height:16,flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center",color:"#111111"},v1I={overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},G0o=`
5613
+ `;return tE("style",{},[vR(g)])}function w1I(g,A){const I=g[A];if(typeof I=="string")return I}function bco(g,A,I,e){const o=[4,8],B=o.map(s=>co(s)).join(" "),Q=o.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=co(I(d.timeMs)),u=co(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})`,[c1I(s.graph)]:ktg(s.graph)};s.graph.source_component_id&&(c["data-source-component-id"]=s.graph.source_component_id);const h=w1I(s.graph,"source_probe_id");h&&(c["data-source-probe-id"]=h);const l=w1I(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=co(I(d.timeMs)),w=co(e(d.displayValue));return tE("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=co(a*Q);E.push(tE("path",{...r.pathAttributes,"stroke-dasharray":B,"stroke-dashoffset":c}))}const n=i.flatMap(s=>s.pointElements);return tE("g",{class:"data-series"},[...E,...n])}function Hco(g,A){return g?.name?tE("text",{class:"chart-title",x:co(A/2),y:co(Ul.top-40),"text-anchor":"middle"},[vR(g.name)]):null}var u1I=16;function vco(g,A,I,e){const t=e.map((o,B)=>tE("tspan",{x:"20",dy:B===0?"0":String(u1I)},[vR(o)]));return tE("g",{class:"legend-item",transform:`translate(${co(A)} ${co(I)})`},[tE("line",{class:"legend-line",x1:"0",y1:"0",x2:"16",y2:"0",stroke:g.color}),tE("text",{class:"legend-label",x:"20",y:"0","dominant-baseline":"middle"},t)])}var qco=15;function Tco(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 o=A[t]??"",B=`${e}_${o}`;B.length>qco?(I.push(e),e=o):e=B}return e&&I.push(e),I}var Zco=24;function Oco(g,A){let I=Ul.top;const e=g.map(t=>{const o=A-Ul.right+10,B=Tco(t.label),C=vco(t,o,I,B),Q=B.length*u1I;return I+=Math.max(Q,Zco),C});return tE("g",{class:"legend"},e)}var q5=118,eGA=94,fZ=18;function G1I(g,A){const I=Math.floor((A+fZ)/(q5+fZ)),e=Math.max(1,Math.min(I,g)),t=Math.max(1,Math.ceil(g/e)),o=e*q5+(e-1)*fZ,B=t*eGA+(t-1)*fZ;return{columns:e,rows:t,x:Math.max(0,(A-o)/2),height:B}}var tGA=20,Stg=8,Wco=14;function Vco(g,A,I){const e=G1I(g.length,A),t=[];for(const[o,B]of g.entries()){const C=o%e.columns,Q=Math.floor(o/e.columns);t.push(jco(B,o,e.x+C*(q5+fZ),I+mtg+Q*(eGA+fZ)))}return tE("g",{class:"scope-legend"},t)}function jco(g,A,I,e){const t=g.scopeTraceDisplay,o=Gk(g.graph)?"A":"V",B=t&&beA(t)?Mtg(t.valuePerDiv,o):`1 ${o}`,C=Mtg(t?.center??0,o),Q=fco(t?.offsetDivs??0),i=`Ch${A+1}`,n=[g.label===i?void 0:g.label,`${B}/div`,Q,C].filter(r=>!!r),s=n.length>1?(eGA-tGA-Stg*2-Wco)/(n.length-1):0;return tE("g",{class:"scope-channel",transform:`translate(${co(I)} ${co(e)})`,[c1I(g.graph)]:ktg(g.graph)},[tE("rect",{class:"scope-channel-card",x:"0",y:"0",width:co(q5),height:co(eGA),rx:"6",ry:"6"}),tE("rect",{x:"0",y:"0",width:co(q5),height:co(tGA),rx:"6",ry:"6",fill:g.color}),tE("rect",{x:"0",y:co(tGA-6),width:co(q5),height:"6",fill:g.color}),tE("text",{class:"scope-channel-header-text",x:co(q5/2),y:"14","text-anchor":"middle"},[vR(i)]),...n.map((r,a)=>tE("text",{class:"scope-channel-detail",x:co(Stg),y:co(tGA+Stg+a*s),"dominant-baseline":"hanging"},[vR(r)]))])}function zco(g){const A=Math.ceil(g/2),I=Math.floor(g/2);return{left:m1I(A),right:m1I(I)}}function m1I(g){if(g<=1)return 0;const A=10+(g-1)*ptg+6+pco+kco;return Math.max(0,A-Ul.left)}function p1I(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 k1I(g){return g?.type==="simulation_experiment"}function Xco(g){return g?.type==="simulation_voltage_probe"}function $co(g){return g?.type==="simulation_current_probe"}function Aho(g){return g?.type==="simulation_oscilloscope_trace"}function gho(g,A){const I=eho(g),e=h1I(g),t=Math.min(I.length,e.length),o=[],B=Iho(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)||o.push({timeMs:Q,rawValue:i,displayValue:B(i)})}return o}function Iho(g){if(!beA(g))return t=>t;const A=g.center??0,I=g.offsetDivs??0,e=g.valuePerDiv;return t=>I+(t-A)/e}function eho(g){const A=h1I(g);if(Array.isArray(g.timestamps_ms)&&g.timestamps_ms.length===A.length)return g.timestamps_ms.map(o=>Number(o));const I=A.length;if(I===0)return[];const e=[];for(let o=0;o<I;o++)e.push(g.start_time_ms+g.time_per_step*o);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 oGA(g,A){const I=g[A];if(typeof I=="string")return I}function tho(g,A,I,e){const t=Gk(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 o=oGA(g,"source_probe_name");if(o)return`${t}(${o})`;if(g.source_component_id){const B=e.get(g.source_component_id);if(B)return`${t}(${B})`}return g.name?g.name:g.source_component_id?`Probe ${g.source_component_id}`:ktg(g)}function oho(g,A,I,e,t,o){if(Gk(g)){const Q=e.get(g.simulation_transient_current_graph_id);if(Q)return Q;const i=oGA(g,"source_probe_id")??(A?.type==="simulation_current_probe"?A.simulation_current_probe_id:void 0);return i?o.get(i):void 0}const B=I.get(g.simulation_transient_voltage_graph_id);if(B)return B;const C=oGA(g,"source_probe_id")??(A?.type==="simulation_voltage_probe"?A.simulation_voltage_probe_id:void 0);return C?t.get(C):void 0}function Bho(g,A,I,e,t){const o=oGA(g,"source_probe_id");if(o){const B=Gk(g)?I.get(o):A.get(o);if(B)return B}if(g.source_component_id)return Gk(g)?t.get(g.source_component_id):e.get(g.source_component_id)}function Cho(g,A){if(A)return{displayName:A.display_name,color:A.color,center:A.display_center_value,offsetDivs:A.display_center_offset_divs,valuePerDiv:Gk(g)?A.amps_per_div:A.volts_per_div}}function Qho(g,A){const I=Array.isArray(Mh.simulation_palette)?Mh.simulation_palette:Array.isArray(Mh.palette)?Mh.palette:[],e=A.filter(Xco),t=A.filter($co),o=A.filter(Aho),B=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 o)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&&B.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=Bho(D,E,n,s,r),w=oho(D,y,a,c,h,l),u=Cho(D,w),G=gho(D,u),m=iho(I,d),p=Eho(D,y,Gk(D)?i:C),k=D.color??u?.color??p??m,S=tho(D,y,u,Gk(D)?Q:B);return{graph:D,points:G,color:k,label:S,scopeTraceDisplay:u,usesScopeTraceDisplay:beA(u)}}).filter(D=>D.points.length>0)}function iho(g,A){return g.length===0?r1I:g[A%g.length]??r1I}function Eho(g,A,I){if(A?.color)return A.color;if(g.source_component_id)return I.get(g.source_component_id)}function M1I({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:o="magnitude",width:B=Gco,height:C=mco,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=>k1I(O)&&O.simulation_experiment_id===A),a=g.filter(O=>p1I(O)&&O.simulation_experiment_id===A&&(!s||s.has(a1I(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=uco({results:a,acSweepView:o,experiment:r}),h=c.graphs;if(h.length===0)throw new Error(`No simulation analysis results found for simulation_experiment_id "${A}"`);const l=Qho(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=nho(d):c.xAxisTitle==="Time (ms)"?y=Fco({values:d,graphs:h,experiment:r}):y=gGA(d);const w=gGA(D.map(O=>O.displayValue),!0),u=l.some(O=>O.usesScopeTraceDisplay),G=u?zco(l.length):{left:0,right:0},m=B+G.left+G.right,p=u?G1I(l.length,m):null,k=p?C+mtg+p.height+mtg:C,S=Math.max(1,B-Ul.left-Ul.right),R=Math.max(1,C-Ul.top-Ul.bottom),x=Ul.left+G.left,N=y1I(y.domainMin,y.domainMax,x,x+S),J=y1I(w.domainMin,w.domainMax,Ul.top+R,Ul.top),K=Sco(A),_=quA(g),H=TuA,T=Hco(r,m),j=[_co(),Pco(m,k),Kco(K,x,S,R),Yco(x,S,R),Lco({timeAxis:y,valueAxis:w,scaleX:N,scaleY:J,plotLeft:x,plotWidth:S,plotHeight:R}),bco(l,K,N,J),xco({timeAxis:y,valueAxis:w,graphs:l,scaleX:N,scaleY:J,plotLeft:x,plotWidth:S,plotHeight:R,yAxisTitle:c.yAxisTitle??Mco(l),xAxisTitle:c.xAxisTitle,usesScopeTraceDisplay:u}),u?Vco(l,m,C):Oco(l,m),...T?[T]:[]],W=tE("svg",{xmlns:"http://www.w3.org/2000/svg",width:m.toString(),height:k.toString(),style:`background-color: ${Mh.schematic.background}`,viewBox:`0 0 ${co(m)} ${co(k)}`,"data-simulation-experiment-id":A,...r?.name&&{"data-simulation-experiment-name":r.name},..._&&{"data-software-used-string":_},...Q&&{"data-circuit-to-svg-version":H}},j);return KuA(W)}var nho=g=>{const A=gGA(g);return{...A,tickLabelOverrides:new Map(A.ticks.map(I=>[I,co(10**I)]))}},sho=1200,aho=1200,S1I=.55;function rho({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:o,width:B=sho,height:C=aho,schematicHeightRatio:Q=S1I,schematicOptions:i,includeVersion:E,graphAboveSchematic:n=!1,showErrorsInTextOverlay:s}){const r=g.filter(J=>!k1I(J)&&!p1I(J)),a=hho(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=E1I(r,{...i,width:B,height:d,includeVersion:!1,showErrorsInTextOverlay:s}),u=M1I({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:o,width:B,height:y,includeVersion:!1}),G=vNI(QX(w)),m=vNI(QX(u)),p=cho(m)??{width:B,height:y},k=p.width>0?B*(p.height/p.width):y,S=d+k,R=[];n?(R.push(WuA(m,0,0,B,k)),R.push(WuA(G,0,k,B,d))):(R.push(WuA(G,0,0,B,d)),R.push(WuA(m,0,d,B,k)));const x=quA(r),N={name:"svg",type:"element",value:"",attributes:{xmlns:"http://www.w3.org/2000/svg",width:z2(B),height:z2(S),viewBox:`0 0 ${z2(B)} ${z2(S)}`,"data-simulation-experiment-id":A,...x&&{"data-software-used-string":x},...E&&{"data-circuit-to-svg-version":TuA}},children:R};return KuA(N)}function cho(g){const A=g.attributes?.viewBox;if(typeof A!="string")return null;const I=A.trim().split(/[\s,]+/).map(o=>Number.parseFloat(o));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 hho(g){return Number.isFinite(g)?g<=0?0:g>=1?1:g:S1I}var f1I=({initialTransform:g,initialTouch1:A,initialTouch2:I,finalTouch1:e,finalTouch2:t})=>{if(!e||!t)return g;const o={x:(A.x+I.x)/2,y:(A.y+I.y)/2},B={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=B.x-o.x,n=B.y-o.y;return pc(Bi(E,n),Bi(o.x,o.y),Lu(i,i),Bi(-o.x,-o.y),g)},HeA=(g={})=>{const A=X.useRef(null),[I,e]=X.useState(0),t=g.canvasElm??A.current,[o,B]=X.useState(g.initialTransform??R4()),[C,Q]=X.useState(0),[i,E]=X.useReducer(d=>d+1,0),n=X.useCallback(d=>{g.onSetTransform&&g.onSetTransform(d),g.transform||B(d)},[g.onSetTransform,B]),s=X.useCallback(d=>{n(d),E()},[n]),r=g.transform??o,a=X.useCallback(()=>{e(Date.now())},[]),c=X.useRef("none"),h=X.useRef(null),l=X.useRef(null);X.useEffect(()=>{const d=g.canvasElm??A.current;if(d&&!t){Q(C+1);return}if(!d){const _=setTimeout(()=>{Q(C+1)},100);return()=>clearTimeout(_)}let y=g.transform??o,w={x:0,y:0},u={x:0,y:0},G=!1;const m=_=>({x:_.pageX-d.getBoundingClientRect().left-window.scrollX,y:_.pageY-d.getBoundingClientRect().top-window.scrollY});function p(_){g.enabled!==!1&&(g.shouldDrag&&!g.shouldDrag(_)||(w=m(_),!(Date.now()-I<100)&&(G=!0,_.preventDefault())))}function k(_){if(!G||g.enabled===!1||g.shouldDrag&&!g.shouldDrag(_))return;u=m(_);const H=pc(Bi(u.x-w.x,u.y-w.y),y);n(H),y=H,G=!1}function S(_){if(m(_),!G||g.enabled===!1||g.shouldDrag&&!g.shouldDrag(_))return;u=m(_);const H=pc(Bi(u.x-w.x,u.y-w.y),y);n(H)}function R(_){if(g.enabled===!1||g.shouldDrag&&!g.shouldDrag(_))return;const H=m(_),T=pc(Bi(H.x,H.y),Lu(1-_.deltaY/1e3,1-_.deltaY/1e3),Bi(-H.x,-H.y),y);n(T),y=T,_.preventDefault()}function x(_){if(!G||g.shouldDrag&&!g.shouldDrag(_))return;if(d){const T=d.getBoundingClientRect();if(_.clientX>=T.left+10&&_.clientX<=T.right-10&&_.clientY>=T.top+10&&_.clientY<=T.bottom-10)return}G=!1,u=m(_);const H=pc(Bi(u.x-w.x,u.y-w.y),y);n(H),y=H}function N(_){if(_.preventDefault(),g.enabled!==!1){if(_.touches.length===1){c.current="drag";const H=_.touches[0];h.current={initialTransform:y,initialTouch:{x:H.clientX,y:H.clientY}}}else if(_.touches.length===2){c.current="pinch";const H=_.touches[0],T=_.touches[1];l.current={initialTransform:y,initialTouch1:{x:H.clientX,y:H.clientY},initialTouch2:{x:T.clientX,y:T.clientY},finalTouch1:null,finalTouch2:null}}}}function J(_){if(_.preventDefault(),g.enabled!==!1){if(c.current==="drag"&&_.touches.length===1&&h.current){const H=_.touches[0],T={x:H.clientX,y:H.clientY},j=T.x-h.current.initialTouch.x,W=T.y-h.current.initialTouch.y,O=pc(Bi(j,W),h.current.initialTransform);n(O)}else if(c.current==="pinch"&&_.touches.length===2&&l.current){const H=_.touches[0],T=_.touches[1];l.current.finalTouch1={x:H.clientX,y:H.clientY},l.current.finalTouch2={x:T.clientX,y:T.clientY};const j=f1I(l.current);n(j)}}}function K(_){_.preventDefault();const H=_.changedTouches[0];if(c.current==="drag"&&h.current&&H){const T={x:H.clientX,y:H.clientY},j=T.x-h.current.initialTouch.x,W=T.y-h.current.initialTouch.y,O=pc(Bi(j,W),h.current.initialTransform);n(O),y=O}else if(c.current==="pinch"&&l.current){const T=f1I(l.current);n(T),y=T}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",K,{passive:!1}),d.addEventListener("touchcancel",K,{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",K),d.removeEventListener("touchcancel",K)}},[t,C,i,I,g.enabled,g.shouldDrag]);const D=X.useCallback(d=>KI(r,d),[r]);return{ref:A,transform:r,applyTransformToPoint:D,setTransform:s,cancelDrag:a}},R1I=HeA;function ftg(g){const A=sM(g),I=new Map;for(const B of A.schematic_component.list())B.source_component_id&&I.set(B.source_component_id,B.schematic_component_id);const e=new Map;for(const B of A.source_trace.list()){const C=B.subcircuit_connectivity_map_key;if(C)for(const Q of B.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 B of A.schematic_net_label.list()){if(!B.source_net_id)continue;const C=A.source_net.get(B.source_net_id)?.subcircuit_connectivity_map_key??B.source_net_id;t.set(B.schematic_net_label_id,C)}const o=new Map;for(const B of A.schematic_text.list()){if(!B.source_trace_id)continue;const C=A.source_trace.get(B.source_trace_id)?.subcircuit_connectivity_map_key;C&&o.set(B.schematic_text_id,C)}return{componentIdToKeys:e,netLabelIdToKey:t,textIdToKey:o}}var BGA=(g,A)=>Math.hypot(g.x-A.x,g.y-A.y),N1I=(g,A,I)=>{const e=I.x-A.x,t=I.y-A.y,o=e*e+t*t,B=o?Math.max(0,Math.min(1,((g.x-A.x)*e+(g.y-A.y)*t)/o)):0;return BGA(g,{x:A.x+B*e,y:A.y+B*t})},T5=(g,A,I)=>Math.abs(BGA(A,g)+BGA(g,I)-BGA(A,I))<1e-5;function lho(g,A){const I=ftg(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(o=>o.type==="schematic_trace"&&o.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(o=>o.type==="source_trace").find(o=>o.source_trace_id===t.source_trace_id)?.subcircuit_connectivity_map_key:void 0)}function Dho(g,A){const I=ftg(g),e=g.filter(n=>n.type==="source_trace"),t=g.filter(n=>n.type==="schematic_trace"),o=g.filter(n=>n.type==="schematic_sheet"),B=o[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??B,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??B,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??B,a=C.filter(c=>c.sheet===s&&c.sourceTraceId===n.source_trace_id).sort((c,h)=>N1I(n.position,c.a,c.b)-N1I(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&&(T5(r.a,a.a,a.b)||T5(r.b,a.a,a.b)||T5(a.a,r.a,r.b)||T5(a.b,r.a,r.b)||[...r.junctions??[],...a.junctions??[]].some(c=>T5(c,r.a,r.b)&&T5(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??B)===r.sheet&&n.some(d=>d.portIds?.includes(D.schematic_port_id)||T5(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=o.findIndex(D=>D.schematic_sheet_id===r.sheet);return{kind:"net",label:`${o[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 dho={async load(){const g=await lno("@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}},nS={contextMenu:110,styleAnalysis:120,viewMenu:110,viewMenuIcon:48,clickToInteractOverlay:100,schematicComponentDetailsTooltip:105,schematicComponentHoverOutline:47,schematicPortHoverOutline:48,schematicSearch:101},yho=({circuitJson:g,onClose:A})=>{const[I,e]=X.useState({status:"loading"});return X.useEffect(()=>{let t=!1;e({status:"loading"});const o=window.setTimeout(async()=>{try{const{createSchematicPlacementIssueArtifacts:B}=await dho.load();if(t)return;const C=B(g);t||e({status:"complete",artifacts:C})}catch(B){t||e({status:"error",message:B instanceof Error?B.message:String(B)})}},0);return()=>{t=!0,window.clearTimeout(o)}},[g]),q.jsx(SuA,{open:!0,onOpenChange:t=>!t&&A(),children:q.jsxs(fuA,{children:[q.jsx(meA,{style:{position:"fixed",inset:0,background:"#0008",zIndex:nS.styleAnalysis}}),q.jsxs(keA,{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:nS.styleAnalysis},children:[q.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:16},children:[q.jsx(RuA,{style:{margin:0,fontSize:22},children:"Style Analysis"}),q.jsx(gtg,{style:{cursor:"pointer",padding:"6px 12px"},children:"Close"})]}),q.jsx(NuA,{style:{color:"#525252"},children:"Placement and style issues across all schematic sheets. Each image highlights one issue with its description below."}),I.status==="loading"&&q.jsx("p",{role:"status",children:"Running style analysis…"}),I.status==="error"&&q.jsxs("p",{role:"alert",children:["Style analysis failed: ",I.message]}),I.status==="complete"&&q.jsxs(q.Fragment,{children:[q.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=>q.jsxs("section",{style:{marginTop:24,border:"1px solid #ddd",borderRadius:8,overflow:"hidden",background:"white"},children:[q.jsxs("h3",{style:{margin:16,fontSize:16},children:[t.issueIndex+1,"."," ",t.issue.lineItemType.replace(/([a-z])([A-Z])/g,"$1 $2"),t.schematicSheetId&&q.jsxs("small",{style:{display:"block",marginTop:4,color:"#525252"},children:["Sheet: ",t.schematicSheetId]})]}),q.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"},x1I=(g,A)=>{if(typeof window>"u")return A;try{const I=localStorage.getItem(g);return I!==null?JSON.parse(I):A}catch{return A}},F1I=(g,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(g,JSON.stringify(A))}catch{}},who=g=>{if(typeof window>"u")return null;try{return localStorage.getItem(g)}catch{return null}},uho=(g,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(g,A)}catch{}},U1I=["#8B0000","#2F4F4F","#191970","#006400","#FF4500","#800080","#2E8B57","#B8860B","#C71585","#008B8B"],Gho=g=>{const{svgDivRef:A,circuitJson:I,circuitJsonKey:e,showGroups:t}=g;X.useEffect(()=>{if(A.current&&A.current.querySelectorAll(".schematic-group-overlay").forEach(C=>C.remove()),!A.current||!t||!I||I.length===0)return;const o=setTimeout(()=>{if(!A.current)return;const B=A.current.querySelector("svg");if(!B)return;B.querySelectorAll(".schematic-group-overlay").forEach(Q=>Q.remove());try{const Q=sM(I).source_group?.list().filter(D=>!D.is_subcircuit)||[],i=sM(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=sM(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:U1I[y%U1I.length],depthLevel:G,hasChildren:m,sourceGroupId:d.source_group_id})}})}const c=B.viewBox.baseVal,h=B.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=mho(D.components,B);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,K=N*(1-J),_=Math.max(1,K*.2),H=D.name,T=document.createElementNS("http://www.w3.org/2000/svg","text");T.setAttribute("font-size",K.toString()),T.setAttribute("font-family","Arial, sans-serif"),T.textContent=H,B.appendChild(T);const j=T.getBBox();B.removeChild(T);const W=j.width+_*2,O=K+_*2,gA=d.minX-u,tA=d.minY-u-O,IA=document.createElementNS("http://www.w3.org/2000/svg","rect");IA.setAttribute("class","schematic-group-overlay"),IA.setAttribute("x",gA.toString()),IA.setAttribute("y",(tA-O).toString()),IA.setAttribute("width",W.toString()),IA.setAttribute("height",O.toString()),IA.setAttribute("fill","transparent"),IA.setAttribute("rx","0"),IA.setAttribute("ry","0");const QA=document.createElementNS("http://www.w3.org/2000/svg","text");QA.setAttribute("class","schematic-group-overlay"),QA.setAttribute("x",(gA+_).toString()),QA.setAttribute("y",(tA+O-_).toString()),QA.setAttribute("fill",D.color),QA.setAttribute("font-size",K.toString()),QA.setAttribute("font-family","Arial, sans-serif"),QA.setAttribute("font-weight",D.depthLevel===0?"600":"500"),QA.setAttribute("stroke",D.color),QA.setAttribute("stroke-width",Math.max(.2,K*.02).toString()),QA.textContent=H,B.appendChild(x),B.appendChild(IA),B.appendChild(QA)})}catch(Q){console.error("Error creating group overlays:",Q)}},10);return()=>clearTimeout(o)},[A,e,t])};function mho(g,A){let I=1/0,e=1/0,t=-1/0,o=-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),o=Math.max(o,i.y+i.height)}}return I===1/0?null:{minX:I,minY:e,maxX:t,maxY:o}}var Rtg="sch-net-faded",J1I="g.trace[data-subcircuit-connectivity-map-key], g.trace-overlays[data-subcircuit-connectivity-map-key]",Ntg="[data-schematic-net-label-id], [data-schematic-text-id]",pho=({svgDivRef:g,circuitJson:A,circuitJsonKey:I,enabled:e})=>{X.useEffect(()=>{const t=g.current;if(!e||!t)return;const{componentIdToKeys:o,netLabelIdToKey:B,textIdToKey:C}=ftg(A);let Q=[];const i=new Map;let E=null;const n=()=>{for(const{el:l}of Q)l.classList.remove(Rtg);Q=[],i.clear(),E=null;const h=t.querySelector("svg");if(h){for(const l of Array.from(h.querySelectorAll(J1I))){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:o.get(D)??new Set})}for(const l of Array.from(h.querySelectorAll(Ntg))){const D=B.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(Rtg,h!==null&&!D.has(h))}},r=h=>{const l=h.target;if(!(l instanceof Element)){s(null);return}const D=l.closest(`${J1I}, ${Ntg}`);if(D&&i.has(D)){s(i.get(D));return}for(const[d,y]of i){if(!d.matches(Ntg))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(Rtg)}},[g,I,e])},xtg="http://www.w3.org/2000/svg",kho=({svgDivRef:g,svgContent:A,circuitJsonKey:I})=>{const e=X.useRef(new Set);X.useLayoutEffect(()=>{e.current.clear()},[I]),X.useLayoutEffect(()=>{const t=[];for(const o of g.current?.querySelectorAll(".schematic-warning")??[]){const B=o.getAttribute("data-warning-id"),C=o.querySelector('[data-warning-reference="callout"]');if(!B||!C)continue;const Q=Array.from(o.children),i=Q.map(d=>d.style.display),E=o.getAttribute("role"),n=o.getAttribute("aria-label")??"Warning",s=document.createElementNS(xtg,"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(xtg,"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(xtg,"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),o.append(s),o.setAttribute("role","button"),o.setAttribute("tabindex","0"),o.style.cursor="pointer",o.style.outline="none";const c=()=>{const d=e.current.has(B);Q.forEach((y,w)=>{y.style.display=d?"none":i[w]}),s.style.display=d?"":"none",o.setAttribute("aria-expanded",String(!d)),o.setAttribute("aria-label",`${d?"Expand":"Minimize"} warning: ${n}`)},h=d=>{d.preventDefault(),d.stopPropagation(),e.current.has(B)?e.current.delete(B):e.current.add(B),c()},l=d=>{(d.key==="Enter"||d.key===" ")&&(d.repeat?d.preventDefault():h(d))},D=d=>d.stopPropagation();o.addEventListener("click",h),o.addEventListener("keydown",l),o.addEventListener("mousedown",D),o.addEventListener("touchstart",D),c(),t.push(()=>{o.removeEventListener("click",h),o.removeEventListener("keydown",l),o.removeEventListener("mousedown",D),o.removeEventListener("touchstart",D),s.remove(),Q.forEach((d,y)=>{d.style.display=i[y]}),E?o.setAttribute("role",E):o.removeAttribute("role"),o.setAttribute("aria-label",n),o.removeAttribute("aria-expanded"),o.removeAttribute("tabindex"),o.style.removeProperty("cursor"),o.style.removeProperty("outline")})}return()=>t.forEach(o=>o())},[g,A,I])},Ftg=g=>String(g??"").toLocaleLowerCase(),veA=(g,A)=>{const I=Ftg(g);return I===A?0:I.startsWith(A)?1:I.includes(A)?2:Number.POSITIVE_INFINITY},Mho=g=>{if(g)return String(g).replace(/^simple_/,"").replaceAll("_"," ").replace(/\b\w/g,A=>A.toLocaleUpperCase())},Sho=(g,A,I)=>{let t=Mho(g?.ftype);g?.ftype==="simple_chip"&&g.manufacturer_part_number&&(t=g.manufacturer_part_number);const o=[];g?.display_name===I&&g.name!==I&&o.push(g.name);let B=g?.display_value;if(!B&&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"){B=Q;break}}}if(B??(B=A.symbol_display_value),t&&o.push(t),B&&o.push(B),!t&&!B&&g?.manufacturer_part_number&&o.push(g.manufacturer_part_number),o.length!==0)return o.join(" · ")},fho=g=>g.type==="source_component"&&"source_component_id"in g,Rho=g=>g.type==="source_port",Nho=g=>g.type==="source_trace",xho=g=>g.type==="schematic_component",Fho=g=>g.type==="schematic_port",Uho=g=>g.type==="schematic_net_label",Jho=g=>g.type==="schematic_sheet",Utg=({schematicSheets:g,schematicSheetId:A})=>{if(!(g.length<=1||!A))return g.find(I=>I.schematic_sheet_id===A)?.name},Pho=(g,A)=>{const I=Ftg(A).trim();if(!I)return[];const e=new Map(g.filter(fho).map(E=>[E.source_component_id,E])),t=new Map(g.filter(Rho).map(E=>[E.source_port_id,E])),o=g.filter(Fho),B=g.filter(Nho),C=g.filter(Jho),Q=[],i=new Map;for(const E of g.filter(xho)){const n=E.source_component_id?e.get(E.source_component_id):void 0,s=n?.display_name??n?.name??"Component",r=Math.min(veA(n?.name,I),veA(n?.display_name,I),veA(n?.manufacturer_part_number,I));if(Number.isFinite(r)){const a={label:s,detail:Sho(n,E,s),kind:"component",schematicSheetId:E.schematic_sheet_id,schematicSheetName:Utg({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(Uho)){if(!Ftg(E.text).includes(I))continue;const n=new Set;for(const d of B.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=o.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:Utg({schematicSheets:C,schematicSheetId:E.schematic_sheet_id}),target:{type:"schematic_net_label",id:E.schematic_net_label_id}};Q.push(D),i.set(D,veA(E.text,I))}for(const E of g){if(E.type!=="schematic_text"||!E.source_trace_id)continue;const n=veA(E.text,I);if(!Number.isFinite(n))continue;const s={label:E.text,kind:"net",schematicSheetId:E.schematic_sheet_id,schematicSheetName:Utg({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))},Kho=({containerRect:g,targetRect:A,visibleProjection:I,minimumScale:e})=>{const t=I.a||1,o={x:A.left+A.width/2-g.left,y:A.top+A.height/2-g.top},B={x:(o.x-I.e)/t,y:(o.y-I.f)/t},C=Math.max(t,e);return{a:C,b:0,c:0,d:C,e:g.width/2-B.x*C,f:g.height/2-B.y*C}},Lho=1.8,P1I=350,Yho=({controller:g,circuitJson:A,circuitJsonKey:I,svgDivRef:e,containerRef:t,activeSheetId:o,hasMultipleSheets:B,handleSelectSheet:C,svgString:Q,svgToScreenProjection:i,setSvgToScreenProjection:E,setIsInteractionEnabled:n})=>{const[s,r]=X.useState(""),[a,c]=X.useState(null),h=X.useRef(null),l=X.useMemo(()=>Pho(A,s),[A,I,s]),D=X.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(K=>K.getAttribute(k)===G.target.id);if(!S)return!1;let R=S.getBoundingClientRect();if(G.focusPoint){const K=S.closest("svg"),_=K?.getAttribute("data-real-to-screen-transform"),H=K?.getScreenCTM?.();if(_&&H){const T=OI(H,OI(JRI(_),G.focusPoint));R={left:T.x-1,top:T.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=JRI(J),m.style.transition="none",m.style.transform=J,m.offsetWidth}catch{}return m.style.transition=`transform ${P1I}ms ease-in-out`,m.offsetWidth,E(Kho({containerRect:x,targetRect:R,visibleProjection:N,minimumScale:Lho})),h.current=setTimeout(()=>{m.style.transition=""},P1I),m.querySelectorAll(".schematic-search-match").forEach(K=>K.classList.remove("schematic-search-match")),m.querySelectorAll(`[${k}]`).forEach(K=>{K.getAttribute(k)===G.target.id&&K.classList.add("schematic-search-match")}),!0},[t,E,e,i]),d=X.useCallback(G=>{if(n(!0),G.schematicSheetId&&G.schematicSheetId!==o&&B){C(G.schematicSheetId),c(G);return}D(G)},[o,D,C,B,n]),y=X.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 X.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&&B&&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,B,C,n]),X.useEffect(()=>{if(!a||!Q||B&&a.schematicSheetId&&a.schematicSheetId!==o)return;const G=requestAnimationFrame(()=>{D(a)&&(c(null),w?.schematicComponentId===a.target.id&&u?.(w))});return()=>cancelAnimationFrame(G)},[D,w,u,a,Q,B,o]),X.useEffect(()=>{s||e.current?.querySelectorAll(".schematic-search-match").forEach(G=>G.classList.remove("schematic-search-match"))},[s,e]),X.useEffect(()=>()=>{h.current&&clearTimeout(h.current)},[]),{searchQuery:s,setSearchQuery:r,searchResults:l,handleSearchResultSelect:d,handleCancelSearch:y}};mE("schematic-viewer");var _ho=()=>{mE.enable("schematic-viewer*")},K1I=g=>{const[A,I]=X.useState(0),[e,t]=X.useState(0);return X.useEffect(()=>{if(!g.current)return;const o=()=>{const C=g.current?.getBoundingClientRect();I(C?.width||0),t(C?.height||0)};o();const B=new ResizeObserver(o);return B.observe(g.current),window.addEventListener("resize",o),()=>{B.disconnect(),window.removeEventListener("resize",o)}},[]),{containerWidth:A,containerHeight:e}},bho=600,CGA=10,Hho=({containerRef:g})=>{const[A,I]=X.useState(null),[e,t]=X.useState(!1),[o,B]=X.useState({x:0,y:0}),C=X.useRef(null),Q=X.useRef(null),i=X.useRef(null),E=X.useRef(0),n=X.useCallback(()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null)},[]),s=X.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)>CGA||Math.abs(l.clientY-D.y)>CGA;Q.current=null,!d&&(I(l.target instanceof Element?l.target:null),B({x:l.clientX,y:l.clientY}),t(!0))},[]),r=X.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();B({x:w.left+w.width/2,y:w.top+w.height/2}),t(!0),E.current=Date.now()+1e3,Q.current=null},bho)},[n,g]),a=X.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)>CGA||Math.abs(d.clientY-D.y)>CGA)&&(Q.current=null,n())},[n]),c=X.useCallback(()=>{n(),Q.current=null},[n]),h=X.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 X.useEffect(()=>{if(e)return document.addEventListener("mousedown",h),document.addEventListener("touchstart",h),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("touchstart",h)}},[h,e]),X.useEffect(()=>n,[n]),{menuVisible:e,menuTarget:A,menuPos:o,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}}},vho=(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(([B,C])=>{if(!C)return!1;const Q=t[`${B}_ids`];return t[`${B}_id`]===C||Array.isArray(Q)&&Q.includes(C)||t.schematic_element_type===B&&t.schematic_element_id===C})}),qho=new Set(["type","source_component_id","source_group_id","subcircuit_id","display_name","ftype","are_pins_interchangeable","supplier_part_numbers"]),L1I=["name","resistance","capacitance","inductance","frequency","voltage","current","max_voltage_rating","max_current_rating","power_rating","manufacturer_part_number"],Tho={jlcpcb:g=>`https://jlcpcb.com/partdetail/${encodeURIComponent(g)}`,lcsc:g=>`https://www.lcsc.com/product-detail/${encodeURIComponent(g)}.html`},Zho=g=>{const A=g.trim(),I=/^c?(\d+)$/i.exec(A);return I?`C${I[1]}`:A},Y1I=g=>{const A=L1I.indexOf(g);return A===-1?L1I.length:A},Oho=(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)},Who=g=>Object.entries(g).filter(([A,I])=>qho.has(A)||A.startsWith("display_")&&A.slice(8)in g?!1:I!=null&&I!=="").sort(([A],[I])=>Y1I(A)-Y1I(I)||A.localeCompare(I)).map(([A,I])=>({key:A,label:A,value:Oho(g,A,I)})),Vho=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(o=>!!(typeof o=="string"&&o.trim())).map(Zho))];return t.length?[{key:`supplier_part_numbers.${I}`,label:I,links:t.map(o=>({partNumber:o,href:Tho[I](o)}))}]:[]}):[]},jho=(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),o=g.find(Q=>Q.type==="cad_component"&&Q.source_component_id===e.source_component_id&&(!t||Q.pcb_component_id===t.pcb_component_id)),B=t?.footprinter_string??o?.footprinter_string,C=t?zho(g,t.pcb_component_id):null;return{schematicComponent:I,sourceComponent:e,pcbComponent:t,footprinterString:B,footprintPreviewCircuitJson:C?.circuitJson,footprintPreviewViewBox:C?.viewBox,warnings:vho(g,I,t)}},QGA=2,zho=(g,A)=>{const I=g.find(o=>o.type==="pcb_component"&&o.pcb_component_id===A);if(!I)return null;const e=_RI(I);if(!e)return null;const t={minX:e.minX-QGA,minY:e.minY-QGA,maxX:e.maxX+QGA,maxY:e.maxY+QGA};return{circuitJson:fno(g,t),viewBox:t}},Xho=(g,A)=>{const I=iro(g,{width:320,height:240,viewport:A,backgroundColor:"#f8fafc",includeVersion:!1});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(I)}`},_1I=(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 o=A.find(i=>i.type==="schematic_text"&&i.schematic_text_id===e),B=A.find(i=>i.type==="schematic_port"&&!!t&&(i.schematic_port_id===t||i.source_port_id===t)),C=I??(o?.type==="schematic_text"?o.schematic_component_id:void 0)??(B?.type==="schematic_port"?B.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},$ho=(g,A)=>{const I=_1I(g,A);if(!I)return;const e=A.find(o=>o.type==="source_component"&&o.source_component_id===I.source_component_id),t=A.find(o=>o.type==="pcb_component"&&o.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}},Jtg=X.createContext(null),A0o=5,g0o=(g,A)=>!g&&!A?!0:!g||!A?!1:g.minX===A.minX&&g.maxX===A.maxX&&g.minY===A.minY&&g.maxY===A.maxY,I0o=({children:g})=>X.useContext(Jtg)?q.jsx(q.Fragment,{children:g}):q.jsx(e0o,{children:g}),e0o=({children:g})=>{const A=X.useRef({pointer:null,boundingBoxes:new Map,hoveringIds:new Set,subscribers:new Set,mouseDownPosition:null}),I=X.useCallback(()=>{for(const E of A.current.subscribers)E()},[]),e=X.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=X.useCallback((E,n)=>{A.current.boundingBoxes.set(E,n),e()},[e]),o=X.useCallback((E,n)=>{const s=A.current.boundingBoxes.get(E);s&&g0o(s.bounds,n.bounds)&&s.onClick===n.onClick||(A.current.boundingBoxes.set(E,n),e())},[e]),B=X.useCallback(E=>{A.current.boundingBoxes.delete(E)&&e()},[e]),C=X.useCallback(E=>(A.current.subscribers.add(E),()=>{A.current.subscribers.delete(E)}),[]),Q=X.useCallback(E=>A.current.hoveringIds.has(E),[]);X.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))>A0o){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=X.useMemo(()=>({registerBoundingBox:t,updateBoundingBox:o,unregisterBoundingBox:B,subscribe:C,isHovering:Q}),[t,o,B,C,Q]);return q.jsx(Jtg.Provider,{value:i,children:g})},NZ=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},t0o=g=>{const A=NZ(g);if(A!==null)return A;if(typeof g!="string")return null;try{const I=JSON.parse(g);if(Array.isArray(I))return NZ(I[0]?.price)}catch{return g.split(",").map(e=>{const[t,o]=e.split(":");return{quantity:NZ(t?.split("-")[0]),price:NZ(o)}}).filter(e=>e.quantity!==null&&e.price!==null).sort((e,t)=>e.quantity-t.quantity)[0]?.price??null}return null},o0o=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 o=t.components.find(B=>B&&String(B.lcsc).replace(/^c/i,"")===g.replace(/^c/i,""));return o?{price:NZ(o.price1)??t0o(o.price),stock:NZ(o.stock)}:null},B0o=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"})},C0o=({partNumber:g,platformConfig:A})=>{const[I,e]=X.useState(null),[t,o]=X.useState(!0),B=A?.partsEngine,C=A?.platformFetch;return X.useEffect(()=>{const Q=new AbortController;let i=!0;o(!0),e(null);const E=setTimeout(()=>{Q.abort(),i&&o(!1)},1e4);return Promise.resolve().then(async()=>B?.fetchPartAvailability?await B.fetchPartAvailability({supplierName:"jlcpcb",supplierPartNumber:g,signal:Q.signal,platformFetch:C})??null:o0o(g,Q.signal,C)).then(n=>{i&&e(n)}).catch(()=>{}).finally(()=>{clearTimeout(E),i&&o(!1)}),()=>{i=!1,clearTimeout(E),Q.abort()}},[g,B,C]),q.jsx("span",{role:"status","aria-label":`${g} price and stock`,"aria-busy":t,style:{display:"block",color:"#64748b",marginTop:"2px"},children:t?q.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[q.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:q.jsx("circle",{cx:"6",cy:"6",r:"4",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeDasharray:"18 8",children:q.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 6 6",to:"360 6 6",dur:"1s",repeatCount:"indefinite"})})}),"Loading price and stock…"]}):q.jsxs(q.Fragment,{children:[q.jsx("span",{style:{display:"block"},children:B0o(I)}),q.jsx("span",{style:{display:"block"},children:I?.stock!=null?`${I.stock.toLocaleString("en-US")} in stock`:"Stock unavailable"})]})})},Ptg={color:"#64748b",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45},Q0o=({platformConfig:g,sourceComponent:A,warnings:I=[],footprinterString:e,footprintPreviewCircuitJson:t,footprintPreviewViewBox:o,left:B,top:C,width:Q,maxHeight:i})=>{const E=X.useMemo(()=>Who(A),[A]),n=X.useMemo(()=>Vho(A),[A]),s=X.useMemo(()=>t?.length&&o?Xho(t,o):void 0,[t,o]);return q.jsxs("dialog",{open:!0,"aria-label":`${A.name} component details`,"data-schematic-component-details-tooltip":!0,style:{position:"absolute",left:B,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:nS.schematicComponentDetailsTooltip},onMouseDown:r=>r.stopPropagation(),onClick:r=>r.stopPropagation(),onWheel:r=>r.stopPropagation(),children:[q.jsxs("dl",{style:{display:"grid",gridTemplateColumns:"minmax(110px, 0.8fr) minmax(0, 1.2fr)",gap:"6px 12px",margin:0,padding:"8px"},children:[E.map(r=>q.jsxs("div",{style:{display:"contents"},children:[q.jsx("dt",{style:Ptg,children:r.label}),q.jsx("dd",{style:{minWidth:0,margin:0,color:"#1e293b",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45,overflowWrap:"anywhere"},children:r.value})]},r.key)),n.map(r=>q.jsxs("div",{style:{display:"contents"},children:[q.jsx("dt",{style:Ptg,children:r.label}),q.jsx("dd",{style:{minWidth:0,margin:0,fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45,overflowWrap:"anywhere"},children:r.links.map((a,c)=>q.jsxs("span",{style:r.label==="jlcpcb"?{display:"block",marginTop:c>0?6:0}:void 0,children:[r.label!=="jlcpcb"&&c>0&&", ",q.jsx("a",{href:a.href,target:"_blank",rel:"noreferrer noopener",style:{color:"#2563eb",textDecoration:"underline"},children:a.partNumber}),r.label==="jlcpcb"&&q.jsx(C0o,{partNumber:a.partNumber,platformConfig:g},`${A.source_component_id}-${a.partNumber}`)]},a.href))})]},r.key)),e&&q.jsxs("div",{style:{display:"contents"},children:[q.jsx("dt",{style:Ptg,children:"footprint"}),q.jsx("dd",{style:{minWidth:0,margin:0,color:"#1e293b",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:1.45,overflowWrap:"anywhere"},children:JSON.stringify(e)})]})]}),I.length>0&&q.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:[q.jsxs("strong",{children:["Warnings (",I.length,")"]}),q.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:"18px"},children:I.map((r,a)=>q.jsx("li",{children:r.message},`${r.type}-${a}`))})]}),s&&q.jsx("div",{style:{padding:"0 4px 4px"},children:q.jsx("div",{style:{height:"210px",overflow:"hidden",border:"1px solid #e2e8f0",borderRadius:"2px",background:"#f8fafc"},children:q.jsx("img",{src:s,alt:`${A.name}${e?` ${e}`:""} PCB footprint`,loading:"lazy",referrerPolicy:"no-referrer",style:{display:"block",width:"100%",height:"100%",objectFit:"contain"}})})})]})},b1I=g=>{const A=X.useContext(Jtg);if(!A)throw new Error("useMouseEventsOverBoundingBox must be used within a MouseTracker");const I=X.useId(),e=X.useRef(g);e.current=g;const t=X.useMemo(()=>B=>{e.current.onClick?.(B)},[]);return X.useEffect(()=>(A.registerBoundingBox(I,{bounds:e.current.bounds,onClick:e.current.onClick?t:void 0}),()=>{A.unregisterBoundingBox(I)}),[A,t,I]),X.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:X.useSyncExternalStore(A.subscribe,()=>A.isHovering(I),()=>!1)}},i0o=(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,E0o=({componentId:g,svgDivRef:A,containerRef:I,onComponentClick:e,onHoverChange:t,showOutline:o,circuitJsonKey:B})=>{const[C,Q]=X.useState(null),i=X.useRef(null),E=X.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=>i0o(u,w)?u:w)},[g,I,A]),n=X.useCallback(()=>{i.current===null&&(i.current=window.requestAnimationFrame(E))},[E]);X.useEffect(()=>{n()},[n,B]),X.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=X.useCallback(h=>{e&&e(g,h)},[g,e]),r=C?.bounds??null,{hovering:a}=b1I({bounds:r,onClick:e?s:void 0});if(X.useEffect(()=>{t&&t(g,a)},[a,g,t]),!C||!a||!o)return null;const c=C.rect;return q.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:nS.schematicComponentHoverOutline}})},n0o=(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,s0o=({portId:g,portLabel:A,svgDivRef:I,containerRef:e,onPortClick:t,onHoverChange:o,showOutline:B,circuitJsonKey:C})=>{const[Q,i]=X.useState(null),E=X.useRef(null),n=X.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=>n0o(m,G)?m:G)},[g,e,I]),s=X.useCallback(()=>{E.current===null&&(E.current=window.requestAnimationFrame(n))},[n]);X.useEffect(()=>{s()},[s,C]),X.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=X.useCallback(l=>{t&&t(g,l)},[g,t]),a=Q?.bounds??null,{hovering:c}=b1I({bounds:a,onClick:t?r:void 0});if(X.useEffect(()=>{o&&o(g,c)},[c,g,o]),!Q||!B)return null;const h=Q.rect;return q.jsxs(q.Fragment,{children:[q.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:nS.schematicPortHoverOutline,transition:"border-color 0.15s, background-color 0.15s"}}),c&&A&&q.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:nS.schematicPortHoverOutline+1},children:A})]})},qeA=({children:g,size:A,strokeWidth:I})=>q.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}),H1I=g=>q.jsxs(qeA,{...g,children:[q.jsx("circle",{cx:"11",cy:"11",r:"8"}),q.jsx("path",{d:"m21 21-4.34-4.34"})]}),a0o=g=>q.jsxs(qeA,{...g,children:[q.jsx("path",{d:"M18 6 6 18"}),q.jsx("path",{d:"m6 6 12 12"})]}),r0o=g=>q.jsxs(qeA,{...g,children:[q.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),q.jsx("rect",{x:"8",y:"8",width:"8",height:"8",rx:"1"}),q.jsx("path",{d:"M7 2v2M12 2v2M17 2v2M7 20v2M12 20v2M17 20v2M2 7h2M2 12h2M2 17h2M20 7h2M20 12h2M20 17h2"})]}),c0o=g=>q.jsxs(qeA,{...g,children:[q.jsx("path",{d:"M15 6a9 9 0 0 0-9 9V3"}),q.jsx("circle",{cx:"18",cy:"6",r:"3"}),q.jsx("circle",{cx:"6",cy:"18",r:"3"})]}),h0o=g=>q.jsxs(qeA,{...g,children:[q.jsx("path",{d:"M20 4v7a4 4 0 0 1-4 4H4"}),q.jsx("path",{d:"m9 10-5 5 5 5"})]}),l0o=({text:g,query:A})=>{const I=A.trim().toLocaleLowerCase();if(!I)return g;const e=g.toLocaleLowerCase(),t=[];let o=0,B=e.indexOf(I);for(;B!==-1;)B>o&&t.push(g.slice(o,B)),t.push(q.jsx("strong",{style:{fontWeight:700},children:g.slice(B,B+I.length)},`${B}-${o}`)),o=B+I.length,B=e.indexOf(I,o);return o<g.length&&t.push(g.slice(o)),t.length>0?t:g},D0o=()=>typeof navigator>"u"?"Ctrl F":/mac/i.test(navigator.platform)?"⌘ F":"Ctrl F",d0o=({query:g,onQueryChange:A,onCancel:I,results:e,onSelect:t,viewerContainerRef:o})=>{const[B,C]=X.useState(!1),[Q,i]=X.useState(null),[E,n]=X.useState(null),s=X.useRef(null),r=X.useRef(null),a=D0o();X.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]),X.useEffect(()=>{Q&&r.current?.querySelector(`[data-search-result-id="${Q}"]`)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[Q]),X.useEffect(()=>{const p=S=>{if(S.key==="Escape"&&B){S.preventDefault(),S.stopPropagation(),S.stopImmediatePropagation(),I(),C(!1),s.current?.blur();return}S.code!=="KeyF"&&S.key.toLocaleLowerCase()!=="f"||!S.metaKey&&!S.ctrlKey||o.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}))}},[B,I,o]);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:q.jsxs("section",{children:[q.jsx("div",{style:{padding:"6px 12px 3px",backgroundColor:"#f7f7f8",color:"#777777",fontSize:"11px",fontWeight:600,letterSpacing:"0.02em",textTransform:"lowercase"},children: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=q.jsx(c0o,{size:15,strokeWidth:1.8});S.kind==="component"&&(J=q.jsx(r0o,{size:15,strokeWidth:1.8}));const K=()=>{s.current?.blur(),i(S.target.id),t(S)};return q.jsxs("button",{type:"button","data-search-result-id":S.target.id,onPointerUp:_=>{_.button===0&&K()},onClick:_=>{_.detail===0&&K()},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:[q.jsx("span",{style:{width:"26px",height:"26px",flexShrink:0,display:"grid",placeItems:"center",border:"1px solid #e5e5e5",borderRadius:"6px",backgroundColor:"#f7f7f7",color:"#666666"},children:J}),q.jsxs("span",{style:{minWidth:0,flex:1},children:[q.jsx("span",{style:{display:"block",overflow:"hidden",fontSize:"13px",fontWeight:400,lineHeight:1.25,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:q.jsx(l0o,{text:S.label,query:g})}),S.detail&&q.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&&q.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&&q.jsx("span",{title:"Press Enter to open",style:{flexShrink:0,color:"#666666",fontSize:"17px",lineHeight:1},children:q.jsx(h0o,{size:14,strokeWidth:1.8})})]},S.target.id)})]});return q.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:nS.schematicSearch,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif'},children:B?q.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:[q.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",height:"32px",boxSizing:"border-box",padding:"0 12px",borderBottom:u},children:[q.jsx(H1I,{size:15,strokeWidth:2}),q.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?q.jsx("span",{style:{flexShrink:0,color:"#888888",fontSize:"12px",whiteSpace:"nowrap"},children:w}):q.jsx("kbd",{style:{flexShrink:0,padding:"2px 5px",border:"1px solid #dddddd",borderRadius:"4px",backgroundColor:"#f7f7f7",color:"#777777",fontFamily:"inherit",fontSize:"10px",lineHeight:1.2},children:a}),B&&q.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:q.jsx(a0o,{size:16,strokeWidth:2})})]}),g&&q.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?q.jsx("div",{style:{padding:"12px",color:"#777777",fontSize:"13px"},children:"No matching components or nets"}):q.jsxs(q.Fragment,{children:[m("components",l),m("nets",D)]})})]}):q.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:q.jsx(H1I,{size:16,strokeWidth:2})})})},Ktg='system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',y0o={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:Ktg,outline:"none",zIndex:nS.viewMenu},w0o={display:"flex",alignItems:"center",gap:8,padding:"7px 10px 7px 8px",borderRadius:6,cursor:"pointer",outline:"none",userSelect:"none",color:"#111111",fontSize:13,fontFamily:Ktg},u0o={width:16,height:16,flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center",color:"#111111"},v1I={overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},G0o=`
5614
5614
  .sv-sheet-item[data-highlighted], .sv-sheet-item:hover { background-color: #f1f3f5; }
5615
5615
  .sv-sheet-chevron { transition: transform 0.2s ease; }
5616
5616
  [data-state="open"] > .sv-sheet-chevron { transform: rotate(180deg); }
5617
- `,m0o=()=>q.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:q.jsx("path",{d:"M20 6 9 17l-5-5"})}),p0o=({className:g})=>q.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:q.jsx("path",{d:"m6 9 6 6 6-6"})}),k0o=({sheets:g,selectedSheetId:A,onSelectSheet:I})=>{const[e,t]=X.useState(!1);if(g.length<=1)return null;const B=g.find(C=>C.schematic_sheet_id===A)?.name??"Select sheet";return q.jsxs(q.Fragment,{children:[q.jsx("style",{children:G0o}),q.jsxs(GuA,{open:e,onOpenChange:t,modal:!1,children:[q.jsx(muA,{asChild:!0,children:q.jsxs("button",{type:"button",title:B,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:Ktg},children:[q.jsx("span",{style:{color:"#888888",flexShrink:0},children:"Sheet:"}),q.jsx("span",{style:{...v1I,minWidth:0},children:B}),q.jsx(p0o,{className:"sv-sheet-chevron"})]})}),q.jsx(hZ,{children:q.jsx(yeA,{style:y0o,side:"bottom",align:"start",sideOffset:8,collisionPadding:10,children:g.map(C=>{const Q=C.schematic_sheet_id===A;return q.jsxs(Hx,{className:"sv-sheet-item",style:w0o,title:C.name,onSelect:i=>i.preventDefault(),onPointerUp:()=>{I(C.schematic_sheet_id),t(!1)},children:[q.jsx("span",{style:u0o,children:Q&&q.jsx(m0o,{})}),q.jsx("span",{style:{...v1I,minWidth:0},children:C.name})]},C.schematic_sheet_id)})})})]})]})},M0o=({count:g,showWarnings:A,onToggle:I})=>{const e=`${A?"Hide":"Show"} ${g} ${g===1?"warning":"warnings"}`;return q.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:[q.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:[q.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"}),q.jsx("path",{d:"M12 9v4m0 4h.01"})]}),q.jsx("span",{children:g})]})},S0o={version:"2.0.103"},Ltg='system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',q1I={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:Ltg,outline:"none",zIndex:nS.contextMenu},v3={display:"flex",alignItems:"center",gap:8,padding:"6px 8px",borderRadius:6,cursor:"default",outline:"none",userSelect:"none",color:"#fafafa",fontSize:14,fontWeight:400,fontFamily:Ltg},xZ={width:16,height:16,flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center",color:"#fafafa"},T1I={height:1,backgroundColor:"#ffffff1a",margin:"4px 0"},f0o=`
5617
+ `,m0o=()=>q.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:q.jsx("path",{d:"M20 6 9 17l-5-5"})}),p0o=({className:g})=>q.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:q.jsx("path",{d:"m6 9 6 6 6-6"})}),k0o=({sheets:g,selectedSheetId:A,onSelectSheet:I})=>{const[e,t]=X.useState(!1);if(g.length<=1)return null;const B=g.find(C=>C.schematic_sheet_id===A)?.name??"Select sheet";return q.jsxs(q.Fragment,{children:[q.jsx("style",{children:G0o}),q.jsxs(GuA,{open:e,onOpenChange:t,modal:!1,children:[q.jsx(muA,{asChild:!0,children:q.jsxs("button",{type:"button",title:B,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:Ktg},children:[q.jsx("span",{style:{color:"#888888",flexShrink:0},children:"Sheet:"}),q.jsx("span",{style:{...v1I,minWidth:0},children:B}),q.jsx(p0o,{className:"sv-sheet-chevron"})]})}),q.jsx(hZ,{children:q.jsx(yeA,{style:y0o,side:"bottom",align:"start",sideOffset:8,collisionPadding:10,children:g.map(C=>{const Q=C.schematic_sheet_id===A;return q.jsxs(Hx,{className:"sv-sheet-item",style:w0o,title:C.name,onSelect:i=>i.preventDefault(),onPointerUp:()=>{I(C.schematic_sheet_id),t(!1)},children:[q.jsx("span",{style:u0o,children:Q&&q.jsx(m0o,{})}),q.jsx("span",{style:{...v1I,minWidth:0},children:C.name})]},C.schematic_sheet_id)})})})]})]})},M0o=({count:g,showWarnings:A,onToggle:I})=>{const e=`${A?"Hide":"Show"} ${g} ${g===1?"warning":"warnings"}`;return q.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:[q.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:[q.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"}),q.jsx("path",{d:"M12 9v4m0 4h.01"})]}),q.jsx("span",{children:g})]})},S0o={version:"2.0.104"},Ltg='system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',q1I={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:Ltg,outline:"none",zIndex:nS.contextMenu},v3={display:"flex",alignItems:"center",gap:8,padding:"6px 8px",borderRadius:6,cursor:"default",outline:"none",userSelect:"none",color:"#fafafa",fontSize:14,fontWeight:400,fontFamily:Ltg},xZ={width:16,height:16,flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center",color:"#fafafa"},T1I={height:1,backgroundColor:"#ffffff1a",margin:"4px 0"},f0o=`
5618
5618
  .sv-vm-item[data-highlighted]:not([data-disabled]),
5619
5619
  .sv-vm-item:hover:not([data-disabled]) { background-color: #404040; }
5620
5620
  .sv-vm-item[data-disabled] { opacity: 0.45; cursor: not-allowed; }
@@ -5674,7 +5674,7 @@ test("${i} should solve problem correctly", () => {
5674
5674
  // Add more specific assertions based on expected output
5675
5675
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5676
5676
  })
5677
- `,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 q.jsxs("div",{className:`relative ${A}`,ref:t,children:[q.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&&q.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:B,children:"Download page.tsx"}),q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:C,children:"Download test.ts"})]})]})},CxI=g=>g.activeSubSolver?[g,...CxI(g.activeSubSolver)]:[g],sDo=({solver:g})=>{const A=CxI(g);return q.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((I,e)=>q.jsxs("div",{className:"flex items-center",children:[e>0&&q.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),q.jsx(nDo,{solver:I})]},I.getSolverName()))})},aDo=({solver:g,triggerRender:A,animationSpeed:I=25,renderer:e,onRendererChange:t,onAnimationSpeedChange:o,onDownloadVisualization:B,onSolverStarted:C,onSolverCompleted:Q})=>{const[i,E]=X.useReducer(m=>!m,!1),n=X.useRef(void 0),s=X.useRef(null),r="solver-debugger-last-iteration",[a,c]=X.useState(null),h=X.useRef(null),l=X.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 X.useEffect(()=>()=>{d()},[]),X.useEffect(()=>{(g.solved||g.failed)&&i&&(d(),E())},[g.solved,g.failed,i]),X.useEffect(()=>{i&&(d(),D())},[I,i]),X.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)}},[]),q.jsxs("div",{className:"space-y-2 p-2 border-b",children:[q.jsx("div",{className:"flex items-center",children:q.jsxs("div",{className:"flex items-center gap-2",ref:h,children:[q.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[q.jsxs("div",{className:"relative",children:[q.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"&&q.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=>q.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&&q.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},m))})]}),q.jsxs("div",{className:"relative",children:[q.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"&&q.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:q.jsx("button",{type:"button",onClick:()=>{B(),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),q.jsxs("div",{className:"relative",children:[q.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"&&q.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=>q.jsxs("button",{type:"button",onClick:()=>{o(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,q.jsx("span",{className:"ml-auto text-xs text-slate-500",children:m.description}),I===m.value&&q.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},m.value))})]})]}),q.jsx(sDo,{solver:g})]})}),q.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[q.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"}),q.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"}),q.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"}),q.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"}),q.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",g.iterations]}),g.timeToSolve!==void 0&&q.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(g.timeToSolve/1e3).toFixed(3),"s"]}),g.solved&&q.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),g.failed&&q.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),g.error&&q.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",g.error]})]})},rDo=g=>g!==null&&"pipelineDef"in g&&Array.isArray(g.pipelineDef),cDo=(g,A,I)=>{const e=g.currentPipelineStageIndex;return A<e?"Completed":A===e&&g.activeSubSolver?g.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},hDo=(g,A)=>{const e=g.pipelineDef[A].solverName,t=cDo(g,A),o=g[e],B=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&&B!==null?Q=r-B:B!==null&&(Q=C-B)}else t==="In Progress"&&B!==null&&(Q=C-B);const i=g.timeSpentOnStage?.[e]??0;let E=0;t==="Completed"?E=1:t==="In Progress"&&o&&(E=o.progress??0);const n=o?.stats??null;return{index:A,name:e,status:t,firstIteration:B,iterations:Q,progress:E,timeSpent:i,stats:n&&Object.keys(n).length>0?n:null,solverInstance:o??null}},lDo=({status:g})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return q.jsx("span",{className:`font-medium ${A[g]}`,children:g})},DDo=({progress:g})=>{if(g===0)return null;const A=Math.round(g*100);return q.jsxs("div",{className:"flex items-center gap-2",children:[q.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:q.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),q.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},QxI=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)},dDo=g=>Object.entries(g).map(([A,I])=>`${A}: ${QxI(I)}`).join(", "),yDo=({stats:g})=>{if(!g||Object.keys(g).length===0)return q.jsx("span",{children:"-"});const A=Object.entries(g),I=dDo(g);return q.jsxs("details",{className:"cursor-pointer",children:[q.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:I}),q.jsx("div",{className:"mt-1 text-xs",children:A.map(([e,t])=>q.jsxs("div",{children:[e,": ",QxI(t)]},e))})]})},Ztg=g=>{if(g===null||typeof g!="object")return g;if(Array.isArray(g))return g.map(Ztg);const A={};for(const[I,e]of Object.entries(g))I.startsWith("_")||(A[I]=Ztg(e));return A},wDo=(g,A)=>{try{if(typeof g.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const I=Ztg(g.getConstructorParams()),e=new Blob([JSON.stringify(I,null,2)],{type:"application/json"}),t=URL.createObjectURL(e),o=document.createElement("a");o.href=t,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(t)}catch(I){alert(`Error downloading input for ${A}: ${I instanceof Error?I.message:String(I)}`)}},uDo=({expanded:g})=>q.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:q.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})}),ixI=g=>{let A=g;for(;A.activeSubSolver;)A=A.activeSubSolver;return A},ExI=({solver:g,onStepUntilPhase:A,onDownloadInput:I,isNested:e=!1,indentLevel:t=0,triggerRender:o})=>{const[B,C]=X.useState(new Set),Q=g.pipelineDef.map((h,l)=>hDo(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):wDo(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)););o?.()}},a=()=>{if(!g.solved&&!g.failed){const h=ixI(g);for(;!g.solved&&!g.failed&&(g.step(),ixI(g)===h););o?.()}},c=t*24;return q.jsxs("div",{className:e?"":"border-t border-gray-200",children:[!e&&q.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[q.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),q.jsxs("div",{className:"flex gap-2",children:[q.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"}),q.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"})]})]}),q.jsx("div",{className:"overflow-x-auto",children:q.jsxs("table",{className:"w-full text-sm",children:[!e&&q.jsx("thead",{children:q.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),q.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",q.jsx("sub",{children:"0"})]}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),q.jsx("tbody",{children:Q.map(h=>{const l=rDo(h.solverInstance),D=B.has(h.name);return q.jsxs(sC.Fragment,{children:[q.jsxs("tr",{className:`border-b border-gray-100 ${h.status==="In Progress"?"bg-yellow-50":""}`,children:[q.jsx("td",{className:"px-4 py-2",children:q.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:c},children:[l?q.jsx("button",{onClick:()=>i(h.name),className:"text-gray-500 hover:text-gray-700",title:D?"Collapse":"Expand",children:q.jsx(uDo,{expanded:D})}):q.jsx("span",{className:"w-4"}),q.jsx("span",{className:"text-gray-400 w-6",children:String(h.index+1).padStart(2,"0")}),q.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:q.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:q.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),q.jsx("span",{className:"font-medium text-gray-900",children:h.name})]})}),q.jsx("td",{className:"px-4 py-2",children:q.jsx(lDo,{status:h.status})}),q.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:h.firstIteration!==null?h.firstIteration:""}),q.jsx("td",{className:"px-4 py-2 text-gray-600",children:h.iterations}),q.jsx("td",{className:"px-4 py-2",children:q.jsx(DDo,{progress:h.progress})}),q.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(h.timeSpent)}),q.jsx("td",{className:"px-4 py-2 text-gray-500",children:q.jsx(yDo,{stats:h.stats})}),q.jsx("td",{className:"px-4 py-2",children:h.solverInstance?q.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:[q.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:q.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),q.jsx("span",{children:"Input"})]}):null})]}),l&&D&&q.jsx("tr",{children:q.jsx("td",{colSpan:8,className:"p-0",children:q.jsx(ExI,{solver:h.solverInstance,onStepUntilPhase:A,onDownloadInput:I,isNested:!0,indentLevel:t+1,triggerRender:o})})})]},h.name)})})]})})]})};function GDo({graphics:g}){const A=g.points??[],I=g.lines??[],e=g.rects??[],t=g.circles??[],o=g.texts??[];let B=Number.POSITIVE_INFINITY,C=Number.POSITIVE_INFINITY,Q=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;const E=(h,l)=>{typeof h=="number"&&(h<B&&(B=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 o)E(h.x,h.y);(!isFinite(B)||!isFinite(C)||!isFinite(Q)||!isFinite(i))&&(B=-20,C=-20,Q=20,i=20);const n=10,s=B-n,r=C-n,a=Math.max(1,Q-B+2*n),c=Math.max(1,i-C+2*n);return q.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)=>q.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)=>q.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)=>q.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)=>q.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${l}`)),o.map((h,l)=>q.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${l}`))]})}var mDo=class extends sC.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}},pDo=({solver:g,createSolver:A,animationSpeed:I=25,onSolverStarted:e,onSolverCompleted:t})=>{const[o,B]=X.useReducer(D=>D+1,0),[C]=X.useState(()=>{if(A)return A();if(!g)throw new Error("GenericSolverDebugger requires solver or createSolver");return g}),[Q,i]=X.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[E,n]=X.useState(I),s=X.useMemo(()=>{try{return C.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(D){return console.error("Visualization error:",D),{points:[],lines:[],rects:[],circles:[]}}},[C,o]),r=X.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);X.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)}},[]),X.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();B()}},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 q.jsxs("div",{children:[q.jsx(aDo,{solver:C,triggerRender:B,animationSpeed:E,renderer:Q,onRendererChange:l,onAnimationSpeedChange:n,onDownloadVisualization:h,onSolverStarted:e,onSolverCompleted:t}),r?q.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):q.jsx(mDo,{fallback:q.jsx(GDo,{graphics:s}),children:Q==="canvas"?q.jsx(EDo,{graphics:s}):q.jsx(CDo,{graphics:s})}),a&&q.jsx(ExI,{solver:C,onStepUntilPhase:c,triggerRender:B})]})};const kDo=()=>{X.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)},[])},MDo=1e3,mk=(g,A)=>{const{fileName:I,mimeType:e="text/plain"}=A,t=g instanceof Blob?g:new Blob([g],{type:e}),o=URL.createObjectURL(t),B=document.createElement("a");B.href=o,B.download=I,B.target="_blank",B.rel="noopener noreferrer",B.style.display="none",document.body.appendChild(B),B.click(),document.body.removeChild(B),setTimeout(()=>{URL.revokeObjectURL(o)},MDo)},Otg=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"},SDo=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]},qx="https://github.com/tscircuit/tscircuit-autorouter/issues/new",nxI="https://github.com/tscircuit/copper-pour-solver/issues/new",sxI="https://github.com/tscircuit/calculate-packing/issues/new",fDo="https://github.com/tscircuit/matchpack/issues/new",axI="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",RDo={PackSolver2:sxI,LayoutPipelineSolver:fDo,AutoroutingPipelineSolver:qx,AssignableAutoroutingPipeline2:qx,AssignableAutoroutingPipeline3:qx,AutoroutingPipeline1_OriginalUnravel:qx,AutoroutingPipelineSolver3_HgPortPointPathing:qx,AutoroutingPipelineSolver4:qx,AutoroutingPipelineSolver5:qx,AutoroutingPipelineSolver7_MultiGraph:qx,AutoroutingPipelineSolver8:qx,CopperPourPipelineSolver:nxI,SchematicTracePipelineSolver:axI},NDo=g=>g.toLowerCase().includes("pack")?$2I:g.toLowerCase().includes("rout")?gfI:fCo,rxI=g=>{const A=RDo[g];if(A)return A;const I=g.toLowerCase();return I.includes("autorout")?qx:I.includes("schematic")&&I.includes("trace")?axI:I.includes("copperpour")?nxI:I.includes("pack")?sxI:null},xDo=g=>`${Otg(`${g.componentName}-${g.solverName}`)}-solver-input.json`,cxI=g=>{mk(JSON.stringify(g.solverParams,null,2),{fileName:xDo(g),mimeType:"application/json"})},FDo=({solverEvent:g})=>{const A=rxI(g.solverName);return q.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[q.jsxs(Ei,{type:"button",variant:"outline",size:"sm",onClick:()=>cxI(g),children:[q.jsx(neA,{className:"rf-w-4 rf-h-4"}),"Download"]}),A?q.jsx(Ei,{asChild:!0,variant:"outline",size:"sm",children:q.jsxs("a",{href:A,target:"_blank",rel:"noopener noreferrer",children:[q.jsx(qwA,{className:"rf-w-4 rf-h-4"}),"Report"]})}):q.jsxs(Ei,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[q.jsx(qwA,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},UDo=({solverEvent:g})=>{const A=rxI(g.solverName);return A?q.jsx(Ei,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:q.jsx("a",{href:A,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:q.jsx(qwA,{className:"rf-w-4 rf-h-4"})})}):q.jsx(Ei,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:q.jsx(qwA,{className:"rf-w-4 rf-h-4"})})},JDo=({solverEvents:g=[]})=>{const[A,I]=X.useState(null);kDo();const e=X.useMemo(()=>{const C=new Map;for(const Q of g){const i=`${Q.componentName}-${Q.solverName}`;C.set(i,Q)}return C},[g]),t=X.useMemo(()=>Array.from(e.keys()),[e]),o=A?e.get(A):null,B=X.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const C=H5A[o.solverName];if(!C)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(H5A).join(", ")}`,classFound:!1};try{return{instance:new C(...SDo(o)),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}}},[o]);return g.length===0?q.jsx("div",{className:"rf-p-4",children:q.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:q.jsxs("div",{className:"rf-p-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),q.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):q.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[q.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[q.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[t.length," ",t.length===1?"Solver":"Solvers"]}),t.map(C=>{const Q=e.get(C),i=A===C;return q.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=NDo(Q.solverName);return q.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[q.jsx(E,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),q.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[q.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:Q.componentName}),q.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:Q.solverName})]})]})})()},C)})]}),q.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?B.instance?q.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[q.jsx(FDo,{solverEvent:o}),q.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:q.jsx(oS,{fallback:q.jsx("div",{className:"rf-p-4",children:q.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),q.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:q.jsx(pDo,{solver:B.instance})})})]}):q.jsxs("div",{className:"rf-p-4",children:[q.jsxs("div",{className:"rf-mb-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),q.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),B.error&&q.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${B.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:q.jsx("p",{className:`rf-text-sm ${B.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:B.error})}),q.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[q.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[q.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),q.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[q.jsx(UDo,{solverEvent:o}),q.jsx(Ei,{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:()=>cxI(o),children:q.jsx(neA,{className:"rf-w-4 rf-h-4"})})]})]}),q.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:q.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):q.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:q.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},PDo=["subcircuit_id","componentDisplayName","phaseName","routingPhaseIndex","phaseOrdinal","phaseCount","phaseStageIndex","phaseStageCount","connectionCount","obstacleCount","previousTraceCount","isReroutePhase","autorouterName","autorouterVersion","solverName","effort","cacheStatus"],KDo=["phaseOrdinal","routingPhaseIndex","phaseName","phaseStageIndex"];function LDo(g,A){let I=-1,e=-1;for(let t=g.length-1;t>=0;t--){const o=g[t];if(o.status!=="running"||o.subcircuit_id!==A.subcircuit_id||o.componentDisplayName!==A.componentDisplayName)continue;let B=0,C=!1;for(const Q of KDo)if(!(o[Q]===void 0||A[Q]===void 0)){if(o[Q]!==A[Q]){C=!0;break}B++}!C&&B>e&&(I=t,e=B)}return I}function YDo(g,A){const I=Object.fromEntries(PDo.filter(B=>A[B]!==void 0).map(B=>[B,A[B]])),e=A.simpleRouteJson?structuredClone(A.simpleRouteJson):void 0,t=A.type==="autorouting:start"?-1:LDo(g,A),o={...t===-1?{id:`autorouting_phase_${g.length+1}`}:g[t],...I,status:A.type==="autorouting:start"?"running":A.type==="autorouting:end"?"complete":"error",...A.type==="autorouting:start"?{startSimpleRouteJson:e}:A.type==="autorouting:end"?{endSimpleRouteJson:e}:{errorSimpleRouteJson:e,error:A.error?{...A.error}:void 0}};return t===-1?[...g,o]:g.map((B,C)=>C===t?o:B)}const _Do=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),bDo=new Set(["tscircuit","default","auto","auto_local"]);function HDo(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 vDo(g){const A=g.autorouterName?.trim(),I=A?.replace(/-/g,"_"),e=I&&_Do.get(I);if(e)return e;if(I&&!bDo.has(I))return A;const t=g.solverName?.trim();if(t)return HDo(t);const o=g.autorouterVersion?.trim();if(o){const B=o.match(/^beta[_-]pipeline(\d+)$/);return B?`Pipeline${B[1]}`:o==="latest"?"default":o}return A?"default":"Unknown"}const Wtg="#fbbf24";function qDo(g){const A=g.endSimpleRouteJson?.traces??[],I=new Set(A.flatMap(t=>[t.pcb_trace_id,t.__replaces_pcb_trace_id].filter(o=>o!==void 0)));return[...(g.startSimpleRouteJson?.traces??[]).filter(t=>!I.has(t.pcb_trace_id)),...A]}function hxI(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 TDo(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 lxI(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,...TDo(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),o=[];let B=0;for(const[C,Q]of t)C>=B&&o.push(I.slice(B,C+1)),B=Math.max(B,Q);return B<I.length&&o.push(I.slice(B)),o}function ZDo(g){const A=[],I=[],e=g.endSimpleRouteJson;if(!e)return{lines:A,circles:I};const t=new Set(hxI(g));for(const o of e.traces??[])if(t.has(o.pcb_trace_id))for(const B of lxI(o,e)){let C;for(const Q of B){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:Wtg,layer:i}),Q.route_type==="via"&&I.push({center:{x:Q.x,y:Q.y},radius:Q.outer_diameter/2,stroke:Wtg,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 ODo(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 WDo=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function VDo(g,A,I){const e=I==="input"?A.startSimpleRouteJson??A.errorSimpleRouteJson:A.endSimpleRouteJson,t=g.filter(i=>!WDo.has(i.type)&&!i.type.endsWith("_error")&&!i.type.endsWith("_warning"));if(!e)return t;const o=I==="input"?e.traces??[]:qDo(A),B=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 o){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=lxI(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}_${ODo(a)}`,subcircuit_id:A.subcircuit_id??void 0,source_trace_id:B.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 Vtg=(g,A)=>g.phaseName||`Phase ${g.phaseOrdinal??A+1}`,DxI=g=>g.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||g.componentDisplayName||g.subcircuit_id||"Board",dxI=g=>g.startSimpleRouteJson??g.endSimpleRouteJson??g.errorSimpleRouteJson,jDo={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},zDo=({circuitJson:g,phases:A=[],isRunning:I=!1})=>{const[e,t]=X.useState(null),[o,B]=X.useState("output"),[C,Q]=X.useState(!0),[i,E]=X.useState(!1),n=X.useRef(null),[s,r]=X.useState(480),a=e?A.findIndex(N=>N.id===e.id&&dxI(N)===dxI(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=o==="output"&&!D?"input":o==="input"&&!y?"output":o,u=w==="input"?d:h?.endSimpleRouteJson,G=X.useMemo(()=>!h||!u?null:VDo(g??[],h,w),[g,h,u,w]),m=X.useMemo(()=>h&&w==="output"&&C?ZDo(h):{lines:[],circles:[]},[h,w,C]);if(X.useLayoutEffect(()=>{const N=n.current;if(!N)return;const J=()=>r(Math.max(360,N.clientHeight));J();const K=new ResizeObserver(J);return K.observe(N),()=>K.disconnect()},[!!h]),!h)return q.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:[q.jsx(gfI,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),q.jsx("h3",{className:"rf-text-base rf-font-medium",children:I?"Waiting for autorouting":"No autorouting captures"}),q.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=Vtg(h,c),k=h.status==="running"&&I,S=!D,R=d?.connections.length,x=G?.filter(N=>N.type==="pcb_trace").length??0;return q.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:[q.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:[q.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:[q.jsx("span",{children:"Routing phases"}),q.jsx("span",{children:A.length})]}),q.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 K=hxI(N).length,_=N.endSimpleRouteJson?`${K} ${K===1?"trace":"traces"} routed`:N.status==="error"?"Failed":N.status==="running"&&I?"Routing…":"No output";return q.jsxs("button",{type:"button","aria-pressed":J===c,title:`${DxI(N)} · ${_}`,onClick:()=>t(N),className:to("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:[q.jsx("span",{className:to("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}),q.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[q.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[q.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:Vtg(N,J),children:Vtg(N,J)}),N.status==="complete"?q.jsx(yJ,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):N.status==="error"?q.jsx(aeg,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):I?q.jsx(BS,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),q.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[vDo(N)," · ",_]})]})]},N.id)})})]}),q.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[q.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:[q.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[p,q.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[c+1," of ",A.length]})]}),I&&q.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"}),q.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(N=>q.jsx("button",{type:"button","aria-pressed":w===N,disabled:N==="input"?!y:!D,onClick:()=>B(N),className:to("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))})]}),q.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:[q.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[q.jsx("input",{type:"checkbox",checked:C,disabled:w!=="output",onChange:N=>Q(N.target.checked),className:"rf-accent-blue-600"}),q.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:Wtg}}),"Highlight changes (all layers)"]}),q.jsxs("span",{children:[w==="input"?"Before this phase":"After this phase"," ","· ",x," traces"]})]}),S&&q.jsx("div",{className:to("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."}),q.jsx("div",{ref:n,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:G?q.jsx(Eeg,{circuitJson:G,height:s,allowEditing:!1,clickToInteractEnabled:!1,initialState:jDo,debugGraphics:m}):q.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),q.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:[q.jsxs("span",{children:[R===void 0?"Input unavailable":`${R} input connections`,` · ${DxI(h)}`]}),q.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[q.jsxs("button",{type:"button",disabled:!u,onClick:()=>mk(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:[q.jsx(neA,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),q.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>E(!i),className:"rf-flex rf-items-center rf-gap-1",children:[q.jsx(K5,{className:to("rf-h-3 rf-w-3",i&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),i&&q.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."})]})]})},yxI=({errorMessage:g,errorStack:A,circuitJsonErrors:I})=>{X.useEffect(()=>{if(ZU("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&g){const e=new Error(g);A&&(e.stack=A);try{Pq.captureException(e)}catch{}}},[g,A]),X.useEffect(()=>{if(ZU("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{Pq.captureException(t,{error_type:e.type})}catch{}}},[I])},wxI=g=>{X.useEffect(()=>{try{Aht(g)}catch{}},[g.source,g.component,g.isWebEmbedded,g.activeTab])},uxI="0.0.2984",XDo={version:uxI},sGA=YVg()(_Vg(g=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{g({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),$Do=g=>{const[A,I]=X.useState([]),[e,t]=X.useState(null),[o,B]=X.useState(""),[C,Q]=oq("eval-version-selection",null),i=sGA(r=>r.setLastRunEvalVersion),E=sGA(r=>r.lastRunEvalVersion);return X.useEffect(()=>{g&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(r=>r.json()).then(r=>{if(Array.isArray(r?.versions)){let a=[...r.versions];r.tags?.latest&&(t(r.tags.latest),a=a.filter(c=>c!==r.tags.latest)),I(a)}}).catch(()=>{})},[g]),X.useEffect(()=>{g&&(C?(window.TSCIRCUIT_LATEST_EVAL_VERSION=C,i(C)):e&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=e,i(e)))},[g,C,e]),{versions:X.useMemo(()=>A.filter(r=>r.includes(o)).slice(0,50),[A,o]),latestVersion:e,lastRunEvalVersion:E,search:o,setSearch:B,selectVersion:r=>{Q(r),B("")}}},Ado=({snippetNames:g,onSelect:A,onCancel:I,isOpen:e})=>{const[t,o]=X.useState(""),[B,C]=X.useState("");if(!e)return null;const Q=g.filter(n=>n.toLowerCase().includes(B.toLowerCase())),i=B&&!g.includes(B),E=n=>{n.key==="Enter"&&(Q.length===1?o(Q[0]):i&&o(B))};return q.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:q.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[q.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),q.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:B,onChange:n=>C(n.target.value),onKeyDown:E}),q.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[Q.map(n=>q.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${t===n?"bg-blue-50":""}`,onClick:()=>o(n),children:n},n)),i&&q.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${t===B?"bg-blue-50":""}`,onClick:()=>o(B),children:['Create new "',B,'"']})]}),q.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[q.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:I,children:"Cancel"}),q.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>t&&A(t),disabled:!t,children:t===B?`Create "${t}"`:`Save to ${t}`})]})]})})},gdo=g=>{const A=X.useRef(null),I=Fc(e=>e.recentEvents);X.useEffect(()=>{if(I.length===0)return;const e=I[0];e.event_id!==A.current&&(g(e),A.current=e.event_id)},[I,g])};var Ido=Object.defineProperty,fJ=(g,A)=>Ido(g,"name",{value:A,configurable:!0}),edo="AlertDialog",[tdo,CAB]=$p(edo,[SRI]),RJ=SRI(),odo=fJ(g=>{const{__scopeAlertDialog:A,...I}=g,e=RJ(A);return q.jsx(SuA,{...e,...I,modal:!0})},"AlertDialog");X.forwardRef(fJ(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=RJ(e);return q.jsx(Ano,{...o,...t,ref:I})},"AlertDialogTrigger"));var Bdo=fJ(g=>{const{__scopeAlertDialog:A,...I}=g,e=RJ(A);return q.jsx(fuA,{...e,...I})},"AlertDialogPortal"),GxI=X.forwardRef(fJ(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=RJ(e);return q.jsx(meA,{...o,...t,ref:I})},"AlertDialogOverlay")),Cdo="AlertDialogContent",[Qdo,ido]=tdo(Cdo),mxI=X.forwardRef(fJ(function(A,I){const{__scopeAlertDialog:e,children:t,...o}=A,B=RJ(e),C=X.useRef(null),Q=wi(I,C),i=X.useRef(null);return q.jsx(Qdo,{scope:e,cancelRef:i,children:q.jsx(keA,{role:"alertdialog",...B,...o,ref:Q,onOpenAutoFocus:Mo(o.onOpenAutoFocus,E=>{E.preventDefault(),i.current?.focus({preventScroll:!0})}),onPointerDownOutside:E=>E.preventDefault(),onInteractOutside:E=>E.preventDefault(),children:t})})},"AlertDialogContent")),pxI=X.forwardRef(fJ(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=RJ(e);return q.jsx(RuA,{...o,...t,ref:I})},"AlertDialogTitle")),kxI=X.forwardRef(fJ(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=RJ(e);return q.jsx(NuA,{...o,...t,ref:I})},"AlertDialogDescription")),MxI=X.forwardRef(fJ(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=RJ(e);return q.jsx(gtg,{...o,...t,ref:I})},"AlertDialogAction")),Edo="AlertDialogCancel",SxI=X.forwardRef(fJ(function(A,I){const{__scopeAlertDialog:e,...t}=A,{cancelRef:o}=ido(Edo,e),B=RJ(e),C=wi(I,o);return q.jsx(gtg,{...B,...t,ref:C})},"AlertDialogCancel"));const fxI=odo,ndo=Bdo,RxI=X.forwardRef(({className:g,...A},I)=>q.jsx(GxI,{className:to("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",g),...A,ref:I}));RxI.displayName=GxI.displayName;const jtg=X.forwardRef(({className:g,...A},I)=>q.jsxs(ndo,{children:[q.jsx(RxI,{}),q.jsx(mxI,{ref:I,className:to("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",g),...A})]}));jtg.displayName=mxI.displayName;const ztg=({className:g,...A})=>q.jsx("div",{className:to("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",g),...A});ztg.displayName="AlertDialogHeader";const Xtg=({className:g,...A})=>q.jsx("div",{className:to("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",g),...A});Xtg.displayName="AlertDialogFooter";const $tg=X.forwardRef(({className:g,...A},I)=>q.jsx(pxI,{ref:I,className:to("rf-text-lg rf-font-semibold",g),...A}));$tg.displayName=pxI.displayName;const Aog=X.forwardRef(({className:g,...A},I)=>q.jsx(kxI,{ref:I,className:to("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",g),...A}));Aog.displayName=kxI.displayName;const sdo=X.forwardRef(({className:g,...A},I)=>q.jsx(MxI,{ref:I,className:to(oZ(),g),...A}));sdo.displayName=MxI.displayName;const gog=X.forwardRef(({className:g,...A},I)=>q.jsx(SxI,{ref:I,className:to(oZ({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",g),...A}));gog.displayName=SxI.displayName;var ado=Object.defineProperty,NJ=(g,A)=>ado(g,"name",{value:A,configurable:!0}),Iog="Checkbox",[rdo,QAB]=$p(Iog),[cdo,eog]=rdo(Iog);function NxI(g){const{__scopeCheckbox:A,checked:I,children:e,defaultChecked:t,disabled:o,form:B,name:C,onCheckedChange:Q,required:i,value:E="on",internal_do_not_use_render:n}=g,[s,r]=ER({prop:I,defaultProp:t??!1,onChange:Q,caller:Iog}),[a,c]=X.useState(null),[h,l]=X.useState(null),[D,d]=X.useState(null),y=a?!!B||!!a.closest("form"):!0,w={checked:s,disabled:o,setChecked:r,control:a,setControl:c,name:C,form:B,value:E,userClick:D,onUserClick:d,required:i,defaultChecked:$2(t)?!1:t,isFormControl:y,bubbleInput:h,setBubbleInput:l};return q.jsx(cdo,{scope:A,...w,children:FxI(n)?n(w):e})}NJ(NxI,"CheckboxProvider");var hdo="CheckboxTrigger",ldo=X.forwardRef(NJ(function({__scopeCheckbox:A,onKeyDown:I,onClick:e,...t},o){const{control:B,value:C,disabled:Q,checked:i,required:E,setControl:n,setChecked:s,onUserClick:r,isFormControl:a,bubbleInput:c}=eog(hdo,A),h=wi(o,n),l=X.useRef(i);return X.useEffect(()=>{const D=B?.form;if(D){const d=NJ(()=>s(l.current),"reset");return D.addEventListener("reset",d),()=>D.removeEventListener("reset",d)}},[B,s]),q.jsx(dQ.button,{type:"button",role:"checkbox","aria-checked":$2(i)?"mixed":i,"aria-required":E,"data-state":tog(i),"data-disabled":Q?"":void 0,disabled:Q,value:C,...t,ref:h,onKeyDown:Mo(I,D=>{D.key==="Enter"&&D.preventDefault()}),onClick:Mo(e,D=>{const d=D.isPropagationStopped();r({requestedChecked:$2(i)?!0:!i,hasConsumerStoppedPropagation:d}),s(y=>$2(y)?!0:!y),c&&a&&(d||D.stopPropagation())})})},"CheckboxTrigger")),xxI=X.forwardRef(NJ(function(A,I){const{__scopeCheckbox:e,name:t,checked:o,defaultChecked:B,required:C,disabled:Q,value:i,onCheckedChange:E,form:n,...s}=A;return q.jsx(NxI,{__scopeCheckbox:e,checked:o,defaultChecked:B,disabled:Q,required:C,onCheckedChange:E,name:t,form:n,value:i,internal_do_not_use_render:({isFormControl:r})=>q.jsxs(q.Fragment,{children:[q.jsx(ldo,{...s,ref:I,__scopeCheckbox:e}),r&&q.jsx(wdo,{__scopeCheckbox:e})]})})},"Checkbox")),Ddo="CheckboxIndicator",ddo=X.forwardRef(NJ(function(A,I){const{__scopeCheckbox:e,forceMount:t,...o}=A,B=eog(Ddo,e);return q.jsx(LM,{present:t||$2(B.checked)||B.checked===!0,children:q.jsx(dQ.span,{"data-state":tog(B.checked),"data-disabled":B.disabled?"":void 0,...o,ref:I,style:{pointerEvents:"none",...A.style}})})},"CheckboxIndicator")),ydo="CheckboxBubbleInput",wdo=X.forwardRef(NJ(function({__scopeCheckbox:A,onClick:I,...e},t){const{control:o,userClick:B,checked:C,defaultChecked:Q,required:i,disabled:E,name:n,value:s,form:r,bubbleInput:a,setBubbleInput:c}=eog(ydo,A),h=wi(t,c),l=Peg(o),D=X.useRef(!1),d=X.useRef(C),y=X.useRef(B),w=X.useRef(null);X.useEffect(()=>{const G=a;if(!G)return;const m=window.HTMLInputElement.prototype,k=Object.getOwnPropertyDescriptor(m,"checked").set;if(!k)return;const S=d.current!==C;d.current=C;const R=B!==null&&B!==y.current;if(y.current=B,R)w.current=S?null:B,S&&(G.indeterminate=$2(C),k.call(G,$2(C)?!1:C)),G.dispatchEvent(new Event("click",{bubbles:!B.hasConsumerStoppedPropagation}));else if(S){const x=w.current;w.current=null;const N=x?.requestedChecked===C;D.current=!0,G.indeterminate=$2(C),k.call(G,$2(C)?!1:C),G.dispatchEvent(new Event("click",{bubbles:!(N&&x.hasConsumerStoppedPropagation)})),D.current=!1}},[a,C,B]);const u=X.useRef($2(C)?!1:C);return q.jsx(dQ.input,{type:"checkbox","aria-hidden":!0,defaultChecked:Q??u.current,required:i,disabled:E,name:n,value:s,form:r,...e,tabIndex:-1,ref:h,onClick:Mo(I,G=>{D.current&&G.stopPropagation()}),style:{...e.style,...l,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})},"CheckboxBubbleInput"));function FxI(g){return typeof g=="function"}NJ(FxI,"isFunction");function $2(g){return g==="indeterminate"}NJ($2,"isIndeterminate");function tog(g){return $2(g)?"indeterminate":g?"checked":"unchecked"}NJ(tog,"getState");const WeA=X.forwardRef(({className:g,...A},I)=>q.jsx(xxI,{ref:I,className:to("rf-peer rf-h-4 rf-w-4 rf-shrink-0 rf-rounded-sm rf-border rf-border-zinc-200 rf-border-zinc-900 rf-shadow focus-visible:rf-outline-none focus-visible:rf-ring-1 focus-visible:rf-ring-zinc-950 disabled:rf-cursor-not-allowed disabled:rf-opacity-50 data-[state=checked]:rf-bg-zinc-900 data-[state=checked]:rf-text-zinc-50 dark:rf-border-zinc-800 dark:rf-border-zinc-50 dark:focus-visible:rf-ring-zinc-300 dark:data-[state=checked]:rf-bg-zinc-50 dark:data-[state=checked]:rf-text-zinc-900",g),...A,children:q.jsx(ddo,{className:to("rf-flex rf-items-center rf-justify-center rf-text-current"),children:q.jsx(yJ,{className:"rf-h-4 rf-w-4"})})}));WeA.displayName=xxI.displayName;const Z5=SuA,udo=fuA,UxI=X.forwardRef(({className:g,...A},I)=>q.jsx(meA,{className:to("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",g),...A,ref:I}));UxI.displayName=meA.displayName;const q3=X.forwardRef(({className:g,children:A,showOverlay:I=!0,...e},t)=>q.jsxs(udo,{children:[q.jsx(UxI,{className:to(I?"":"rf-hidden")}),q.jsx(keA,{ref:t,className:to("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",g),...e,children:A})]}));q3.displayName=keA.displayName;const T3=({className:g,...A})=>q.jsx("div",{className:to("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",g),...A});T3.displayName="DialogHeader";const FZ=({className:g,...A})=>q.jsx("div",{className:to("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",g),...A});FZ.displayName="DialogFooter";const Z3=X.forwardRef(({className:g,...A},I)=>q.jsx(RuA,{ref:I,className:to("rf-text-lg rf-font-semibold",g),...A}));Z3.displayName=RuA.displayName;const O5=X.forwardRef(({className:g,...A},I)=>q.jsx(NuA,{ref:I,className:to("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",g),...A}));O5.displayName=NuA.displayName;const aGA={"tscircuit.com":{label:"tscircuit.com",placeholder:"Search tscircuit packages...",emptyMessage:"No packages found"},jlcpcb:{label:"JLCPCB Parts",placeholder:"Search JLCPCB parts (e.g. C14663)...",emptyMessage:"No parts found"},kicad:{label:"KiCad Footprints",placeholder:"Search KiCad footprints...",emptyMessage:"No footprints found"}},Gdo="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let oog=null;const Bog=async()=>(oog||(oog=import(Gdo)),oog),mdo=g=>(A,I)=>{const e=new Headers(I?.headers),t={};return e.forEach((o,B)=>{t[B]=o}),fetch(`${g?.apiBase??Dm}/proxy`,{...I,headers:{...t,"X-Target-Url":A.toString(),"X-Sender-Origin":t.origin??"","X-Sender-Host":t.host??"https://easyeda.com","X-Sender-Referer":t.referer??"","X-Sender-User-Agent":t["user-agent"]??"","X-Sender-Cookie":t.cookie??"",authority:t.authority??"","content-type":t["content-type"]??"",...g?.headers}})},pdo=async(g,A=10)=>{const I=encodeURIComponent(g),e=await fetch(`https://jlcsearch.tscircuit.com/api/search?limit=${A}&q=${I}`);if(!e.ok)throw new Error(`JLCPCB API error: ${e.status}`);return(await e.json()).components??[]},kdo=g=>({lcscId:g.lcsc,manufacturer:g.mfr,description:g.description,partNumber:`C${g.lcsc}`,package:g.package,price:g.price,stock:g.stock,isBasic:g.is_basic}),JxI=async(g,A)=>{const{fetchEasyEDAComponent:I}=await Bog();return I(g,{fetch:mdo(A),includeModelMetadata:A?.includeModelMetadata})},Mdo=async(g,A)=>{const{convertRawEasyToTsx:I}=await Bog(),e=await JxI(g,A);return I({rawEasy:e})},Sdo=async(g,A)=>{const{EasyEdaJsonSchema:I,convertEasyEdaJsonToCircuitJson:e}=await Bog(),t=await JxI(g,{...A,includeModelMetadata:!1}),o=I.parse(t);return e(o,{shouldRecenter:!0,showDesignator:!0,useModelCdn:!1})};function O3(g){return Array.isArray?Array.isArray(g):KxI(g)==="[object Array]"}function fdo(g){if(typeof g=="string")return g;if(typeof g=="bigint")return g.toString();const A=g+"";return A=="0"&&1/g==-1/0?"-0":A}function Cog(g){return g==null?"":fdo(g)}function BG(g){return typeof g=="string"}function rGA(g){return typeof g=="number"}function Rdo(g){return g===!0||g===!1||Ndo(g)&&KxI(g)=="[object Boolean]"}function PxI(g){return typeof g=="object"}function Ndo(g){return PxI(g)&&g!==null}function aS(g){return g!=null}function cGA(g){return!g.trim().length}function KxI(g){return g==null?g===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(g)}const xdo="Incorrect 'index' type",Qog="Invalid doc index: must be a non-negative integer within the bounds of the docs array",Fdo=g=>`Invalid value for key ${g}`,Udo=g=>`Pattern length exceeds max of ${g}.`,Jdo=g=>`Missing ${g} property in key`,Pdo=g=>`Property 'weight' in key '${g}' must be a positive integer`,Kdo="Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.",LxI=Object.prototype.hasOwnProperty;var Ldo=class{constructor(g){this._keys=[],this._keyMap={};let A=0;g.forEach(I=>{const e=YxI(I);this._keys.push(e),this._keyMap[e.id]=e,A+=e.weight}),this._keys.forEach(I=>{I.weight/=A})}get(g){return this._keyMap[g]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function YxI(g){let A=null,I=null,e=null,t=1,o=null;if(BG(g)||O3(g))e=g,A=_xI(g),I=hGA(g);else{if(!LxI.call(g,"name"))throw new Error(Jdo("name"));const B=g.name;if(e=B,LxI.call(g,"weight")&&g.weight!==void 0&&(t=g.weight,t<=0))throw new Error(Pdo(hGA(B)));A=_xI(B),I=hGA(B),o=g.getFn??null}return{path:A,id:I,weight:t,src:e,getFn:o}}function _xI(g){return O3(g)?g:g.split(".")}function hGA(g){return O3(g)?g.join("."):g}function Ydo(g,A){const I=[];let e=!1;const t=(o,B,C,Q)=>{if(aS(o))if(!B[C])I.push(Q!==void 0?{v:o,i:Q}:o);else{const i=o[B[C]];if(!aS(i))return;if(C===B.length-1&&(BG(i)||rGA(i)||Rdo(i)||typeof i=="bigint"))I.push(Q!==void 0?{v:Cog(i),i:Q}:Cog(i));else if(O3(i)){e=!0;for(let E=0,n=i.length;E<n;E+=1)t(i[E],B,C+1,E)}else B.length&&t(i,B,C+1,Q)}};return t(g,BG(A)?A.split("."):A,0),e?I:I[0]}const rQ=Object.freeze({...{isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(g,A)=>g.score===A.score?g.idx<A.idx?-1:1:g.score<A.score?-1:1},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,useTokenSearch:!1,tokenize:void 0,tokenMatch:"any",getFn:Ydo,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}});function _do(g){return g>=9&&g<=13||g===32||g===160}function bdo(g=1,A=3){const I=new Map,e=Math.pow(10,A);return{get(t){let o=0,B=!1;for(let Q=0;Q<t.length;Q++)_do(t.charCodeAt(Q))?B=!1:B||(o++,B=!0);if(o===0&&(o=1),I.has(o))return I.get(o);const C=Math.round(e/Math.pow(o,.5*g))/e;return I.set(o,C),C},clear(){I.clear()}}}var iog=class{constructor({getFn:g=rQ.getFn,fieldNormWeight:A=rQ.fieldNormWeight}={}){this.norm=bdo(A,3),this.getFn=g,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(g=[]){this.docs=g}setIndexRecords(g=[]){this.records=g}setKeys(g=[]){this.keys=g,this._keysMap={},g.forEach((A,I)=>{this._keysMap[A.id]=I})}create(){if(this.isCreated||!this.docs.length)return;this.isCreated=!0;const g=this.docs.length;this.records=new Array(g);let A=0;if(BG(this.docs[0]))for(let I=0;I<g;I++){const e=this._createStringRecord(this.docs[I],I);e&&(this.records[A++]=e)}else for(let I=0;I<g;I++)this.records[A++]=this._createObjectRecord(this.docs[I],I);this.records.length=A,this.norm.clear()}add(g,A){if(!Number.isInteger(A)||A<0)throw new Error(Qog);if(BG(g)){const e=this._createStringRecord(g,A);return e&&this.records.push(e),e}const I=this._createObjectRecord(g,A);return this.records.push(I),I}removeAt(g){if(!Number.isInteger(g)||g<0)throw new Error(Qog);for(let A=0,I=this.records.length;A<I;A+=1)if(this.records[A].i===g){this.records.splice(A,1);break}for(let A=0,I=this.records.length;A<I;A+=1)this.records[A].i>g&&(this.records[A].i-=1)}removeAll(g){const A=new Set;for(const e of g)Number.isInteger(e)&&e>=0&&A.add(e);if(A.size===0)return;this.records=this.records.filter(e=>!A.has(e.i));const I=Array.from(A).sort((e,t)=>e-t);for(const e of this.records){let t=0,o=I.length;for(;t<o;){const B=t+o>>>1;I[B]<e.i?t=B+1:o=B}e.i-=t}}getValueForItemAtKeyId(g,A){return g[this._keysMap[A]]}size(){return this.records.length}_createStringRecord(g,A){return!aS(g)||cGA(g)?null:{v:g,i:A,n:this.norm.get(g)}}_createObjectRecord(g,A){const I={i:A,$:{}};for(let e=0,t=this.keys.length;e<t;e++){const o=this.keys[e],B=o.getFn?o.getFn(g):this.getFn(g,o.path);if(aS(B)){if(O3(B)){const C=[];for(let Q=0,i=B.length;Q<i;Q+=1){const E=B[Q];if(aS(E)){if(BG(E)){if(!cGA(E)){const n={v:E,i:Q,n:this.norm.get(E)};C.push(n)}}else if(aS(E.v)){const n=BG(E.v)?E.v:Cog(E.v);if(!cGA(n)){const s={v:n,i:E.i,n:this.norm.get(n)};C.push(s)}}}}I.$[e]=C}else if(BG(B)&&!cGA(B)){const C={v:B,n:this.norm.get(B)};I.$[e]=C}}}return I}toJSON(){return{keys:this.keys.map(({getFn:g,...A})=>A),records:this.records}}};function bxI(g,A,{getFn:I=rQ.getFn,fieldNormWeight:e=rQ.fieldNormWeight}={}){const t=new iog({getFn:I,fieldNormWeight:e});return t.setKeys(g.map(YxI)),t.setSources(A),t.create(),t}function Hdo(g,{getFn:A=rQ.getFn,fieldNormWeight:I=rQ.fieldNormWeight}={}){const{keys:e,records:t}=g,o=new iog({getFn:A,fieldNormWeight:I});return o.setKeys(e),o.setIndexRecords(t),o}function vdo(g=[],A=rQ.minMatchCharLength){const I=[];let e=-1,t=-1,o=0;for(let B=g.length;o<B;o+=1){const C=g[o];C&&e===-1?e=o:!C&&e!==-1&&(t=o-1,t-e+1>=A&&I.push([e,t]),e=-1)}return g[o-1]&&o-e>=A&&I.push([e,o-1]),I}function qdo(g,A,I,{location:e=rQ.location,distance:t=rQ.distance,threshold:o=rQ.threshold,findAllMatches:B=rQ.findAllMatches,minMatchCharLength:C=rQ.minMatchCharLength,includeMatches:Q=rQ.includeMatches,ignoreLocation:i=rQ.ignoreLocation}={}){if(A.length>32)throw new Error(Udo(32));const E=A.length,n=g.length,s=Math.max(0,Math.min(e,n));let r=o,a=s;const c=(p,k)=>{const S=p/E;if(i)return S;const R=Math.abs(s-k);return t?S+R/t:R?1:S},h=C>1||Q,l=h?Array(n):[];let D;for(;(D=g.indexOf(A,a))>-1;){const p=c(0,D);if(r=Math.min(p,r),a=D+E,h){let k=0;for(;k<E;)l[D+k]=1,k+=1}}a=-1;let d=[],y=1,w=0,u=E+n;const G=1<<E-1;for(let p=0;p<E;p+=1){let k=0,S=u;for(;k<S;)c(p,s+S)<=r?k=S:u=S,S=Math.floor((u-k)/2+k);u=S;let R=Math.max(1,s-S+1);const x=B?n:Math.min(s+S,n)+E,N=Array(x+2);N[x+1]=(1<<p)-1;for(let J=x;J>=R;J-=1){const K=J-1,_=I[g[K]];if(N[J]=(N[J+1]<<1|1)&_,p&&(N[J]|=(d[J+1]|d[J])<<1|1|d[J+1]),N[J]&G&&(y=c(p,K),y<=r)){if(r=y,a=K,w=p,a<=s)break;R=Math.max(1,2*s-a)}}if(c(p+1,s)>r)break;d=N}if(h&&a>=0){const p=Math.min(n-1,a+E-1+w);for(let k=a;k<=p;k+=1)I[g[k]]&&(l[k]=1)}const m={isMatch:a>=0,score:Math.max(.001,y)};if(h){const p=vdo(l,C);p.length?Q&&(m.indices=p):m.isMatch=!1}return m}function Tdo(g){const A={};for(let I=0,e=g.length;I<e;I+=1){const t=g.charAt(I);A[t]=(A[t]||0)|1<<e-I-1}return A}function Eog(g){if(g.length<=1)return g;g.sort((I,e)=>I[0]-e[0]||I[1]-e[1]);const A=[g[0]];for(let I=1,e=g.length;I<e;I+=1){const t=A[A.length-1],o=g[I];o[0]<=t[1]+1?t[1]=Math.max(t[1],o[1]):A.push(o)}return A}const HxI={ł:"l",Ł:"L",đ:"d",Đ:"D",ø:"o",Ø:"O",ħ:"h",Ħ:"H",ŧ:"t",Ŧ:"T",ı:"i",ß:"ss"},Zdo=new RegExp("["+Object.keys(HxI).join("")+"]","g"),VeA=typeof String.prototype.normalize=="function"?g=>g.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"").replace(Zdo,A=>HxI[A]):g=>g;var nog=class{constructor(g,{location:A=rQ.location,threshold:I=rQ.threshold,distance:e=rQ.distance,includeMatches:t=rQ.includeMatches,findAllMatches:o=rQ.findAllMatches,minMatchCharLength:B=rQ.minMatchCharLength,isCaseSensitive:C=rQ.isCaseSensitive,ignoreDiacritics:Q=rQ.ignoreDiacritics,ignoreLocation:i=rQ.ignoreLocation}={}){if(this.options={location:A,threshold:I,distance:e,includeMatches:t,findAllMatches:o,minMatchCharLength:B,isCaseSensitive:C,ignoreDiacritics:Q,ignoreLocation:i},g=C?g:g.toLowerCase(),g=Q?VeA(g):g,this.pattern=g,this.chunks=[],!this.pattern.length)return;const E=(s,r)=>{this.chunks.push({pattern:s,alphabet:Tdo(s),startIndex:r})},n=this.pattern.length;if(n>32){let s=0;const r=n%32,a=n-r;for(;s<a;)E(this.pattern.substr(s,32),s),s+=32;if(r){const c=n-32;E(this.pattern.substr(c),c)}}else E(this.pattern,0)}searchIn(g){const{isCaseSensitive:A,ignoreDiacritics:I,includeMatches:e}=this.options;if(g=A?g:g.toLowerCase(),g=I?VeA(g):g,this.pattern===g){if(g.length<this.options.minMatchCharLength)return{isMatch:!1,score:1};const a={isMatch:!0,score:0};return e&&(a.indices=[[0,g.length-1]]),a}const{location:t,distance:o,threshold:B,findAllMatches:C,minMatchCharLength:Q,ignoreLocation:i}=this.options,E=[];let n=0,s=!1;this.chunks.forEach(({pattern:a,alphabet:c,startIndex:h})=>{const{isMatch:l,score:D,indices:d}=qdo(g,a,c,{location:t+h,distance:o,threshold:B,findAllMatches:C,minMatchCharLength:Q,includeMatches:e,ignoreLocation:i});l&&(s=!0),n+=D,l&&d&&E.push(...d)});const r={isMatch:s,score:s?n/this.chunks.length:1};return s&&e&&(r.indices=Eog(E)),r}};const Odo=new Set(["fuzzy","include"]);function Wdo(g){return g.startsWith("inverse")}const sog=[{type:"exact",multiRegex:/^="(.*)"$/,singleRegex:/^=(.*)$/,create:g=>({type:"exact",search(A){const I=A===g;return{isMatch:I,score:I?0:1,indices:[0,g.length-1]}}})},{type:"include",multiRegex:/^'"(.*)"$/,singleRegex:/^'(.*)$/,create:g=>({type:"include",search(A){let I=0,e;const t=[],o=g.length;for(;(e=A.indexOf(g,I))>-1;)I=e+o,t.push([e,I-1]);const B=!!t.length;return{isMatch:B,score:B?0:1,indices:t}}})},{type:"prefix-exact",multiRegex:/^\^"(.*)"$/,singleRegex:/^\^(.*)$/,create:g=>({type:"prefix-exact",search(A){const I=A.startsWith(g);return{isMatch:I,score:I?0:1,indices:[0,g.length-1]}}})},{type:"inverse-prefix-exact",multiRegex:/^!\^"(.*)"$/,singleRegex:/^!\^(.*)$/,create:g=>({type:"inverse-prefix-exact",search(A){const I=!A.startsWith(g);return{isMatch:I,score:I?0:1,indices:[0,A.length-1]}}})},{type:"inverse-suffix-exact",multiRegex:/^!"(.*)"\$$/,singleRegex:/^!(.*)\$$/,create:g=>({type:"inverse-suffix-exact",search(A){const I=!A.endsWith(g);return{isMatch:I,score:I?0:1,indices:[0,A.length-1]}}})},{type:"suffix-exact",multiRegex:/^"(.*)"\$$/,singleRegex:/^(.*)\$$/,create:g=>({type:"suffix-exact",search(A){const I=A.endsWith(g);return{isMatch:I,score:I?0:1,indices:[A.length-g.length,A.length-1]}}})},{type:"inverse-exact",multiRegex:/^!"(.*)"$/,singleRegex:/^!(.*)$/,create:g=>({type:"inverse-exact",search(A){const I=A.indexOf(g)===-1;return{isMatch:I,score:I?0:1,indices:[0,A.length-1]}}})},{type:"fuzzy",multiRegex:/^"(.*)"$/,singleRegex:/^(.*)$/,create:(g,A={})=>{const I=new nog(g,{location:A.location??rQ.location,threshold:A.threshold??rQ.threshold,distance:A.distance??rQ.distance,includeMatches:A.includeMatches??rQ.includeMatches,findAllMatches:A.findAllMatches??rQ.findAllMatches,minMatchCharLength:A.minMatchCharLength??rQ.minMatchCharLength,isCaseSensitive:A.isCaseSensitive??rQ.isCaseSensitive,ignoreDiacritics:A.ignoreDiacritics??rQ.ignoreDiacritics,ignoreLocation:A.ignoreLocation??rQ.ignoreLocation});return{type:"fuzzy",search(e){return I.searchIn(e)}}}}],vxI=sog.length,Vdo="\0",jdo="|";function zdo(g){const A=[],I=g.length;let e=0;for(;e<I;){for(;e<I&&g[e]===" ";)e++;if(e>=I)break;let t=e;for(;t<I&&g[t]!==" "&&g[t]!=='"';)t++;if(t<I&&g[t]==='"'){for(t++;t<I;){if(g[t]==='"'){const o=t+1;if(o>=I||g[o]===" "){t++;break}if(g[o]==="$"&&(o+1>=I||g[o+1]===" ")){t+=2;break}}t++}A.push(g.substring(e,t)),e=t}else{for(;t<I&&g[t]!==" ";)t++;A.push(g.substring(e,t)),e=t}}return A}function qxI(g,A){const I=g.match(A);return I?I[1]:null}function Xdo(g,A={}){return g.replace(/\\\|/g,Vdo).split(jdo).map(I=>{const e=zdo(I.replace(/\u0000/g,"|").trim()).filter(o=>o&&!!o.trim()),t=[];for(let o=0,B=e.length;o<B;o+=1){const C=e[o];let Q=!1,i=-1;for(;!Q&&++i<vxI;){const E=sog[i],n=qxI(C,E.multiRegex);n&&(t.push(E.create(n,A)),Q=!0)}if(!Q)for(i=-1;++i<vxI;){const E=sog[i],n=qxI(C,E.singleRegex);if(n){t.push(E.create(n,A));break}}}return t})}var $do=class{constructor(g,{isCaseSensitive:A=rQ.isCaseSensitive,ignoreDiacritics:I=rQ.ignoreDiacritics,includeMatches:e=rQ.includeMatches,minMatchCharLength:t=rQ.minMatchCharLength,ignoreLocation:o=rQ.ignoreLocation,findAllMatches:B=rQ.findAllMatches,location:C=rQ.location,threshold:Q=rQ.threshold,distance:i=rQ.distance}={}){this.query=null,this.options={isCaseSensitive:A,ignoreDiacritics:I,includeMatches:e,minMatchCharLength:t,findAllMatches:B,ignoreLocation:o,location:C,threshold:Q,distance:i},g=A?g:g.toLowerCase(),g=I?VeA(g):g,this.pattern=g,this.query=Xdo(this.pattern,this.options)}static condition(g,A){return A.useExtendedSearch}searchIn(g){const A=this.query;if(!A)return{isMatch:!1,score:1};const{includeMatches:I,isCaseSensitive:e,ignoreDiacritics:t}=this.options;g=e?g:g.toLowerCase(),g=t?VeA(g):g;let o=0;const B=[];let C=0,Q=!1;for(let i=0,E=A.length;i<E;i+=1){const n=A[i];B.length=0,o=0,Q=!1;for(let s=0,r=n.length;s<r;s+=1){const a=n[s],{isMatch:c,indices:h,score:l}=a.search(g);if(c)o+=1,C+=l,Wdo(a.type)&&(Q=!0),I&&(Odo.has(a.type)?B.push(...h):B.push(h));else{C=0,o=0,B.length=0,Q=!1;break}}if(o){const s={isMatch:!0,score:C/o};return Q&&(s.hasInverse=!0),I&&(s.indices=Eog(B)),s}}return{isMatch:!1,score:1}}};const aog=[];function rog(...g){aog.push(...g)}function lGA(g,A){for(let I=0,e=aog.length;I<e;I+=1){const t=aog[I];if(t.condition(g,A))return new t(g,A)}return new nog(g,A)}const DGA={AND:"$and",OR:"$or"},cog={PATH:"$path",PATTERN:"$val"},hog=g=>!!(g[DGA.AND]||g[DGA.OR]),Ayo=g=>!!g[cog.PATH],gyo=g=>!O3(g)&&PxI(g)&&!hog(g),TxI=g=>({[DGA.AND]:Object.keys(g).map(A=>({[A]:g[A]}))});function ZxI(g,A,{auto:I=!0}={}){const e=t=>{if(BG(t)){const Q={keyId:null,pattern:t};return I&&(Q.searcher=lGA(t,A)),Q}const o=Object.keys(t),B=Ayo(t);if(!B&&o.length>1&&!hog(t))return e(TxI(t));if(gyo(t)){const Q=B?t[cog.PATH]:o[0],i=B?t[cog.PATTERN]:t[Q];if(!BG(i))throw new Error(Fdo(Q));const E={keyId:hGA(Q),pattern:i};return I&&(E.searcher=lGA(i,A)),E}const C={children:[],operator:o[0]};return o.forEach(Q=>{const i=t[Q];O3(i)&&i.forEach(E=>{C.children.push(e(E))})}),C};return hog(g)||(g=TxI(g)),e(g)}function log(g,{ignoreFieldNorm:A=rQ.ignoreFieldNorm}){let I=1;return g.forEach(({key:e,norm:t,score:o})=>{const B=e?e.weight:null;I*=Math.pow(o===0&&B?Number.EPSILON:o,(B||1)*(A?1:t))}),I}function Iyo(g,{ignoreFieldNorm:A=rQ.ignoreFieldNorm}){g.forEach(I=>{I.score=log(I.matches,{ignoreFieldNorm:A})})}var eyo=class{constructor(g,A){this.limit=g,this.heap=[],this.comparator=A}get size(){return this.heap.length}insert(g){this.size<this.limit?(this.heap.push(g),this._bubbleUp(this.size-1)):this.comparator(g,this.heap[0])<0&&(this.heap[0]=g,this._sinkDown(0))}extractSorted(){return this.heap.sort(this.comparator)}_bubbleUp(g){const A=this.heap;for(;g>0;){const I=g-1>>1;if(this.comparator(A[g],A[I])<=0)break;const e=A[g];A[g]=A[I],A[I]=e,g=I}}_sinkDown(g){const A=this.heap,I=A.length;let e=g;do{g=e;const t=2*g+1,o=2*g+2;if(t<I&&this.comparator(A[t],A[e])>0&&(e=t),o<I&&this.comparator(A[o],A[e])>0&&(e=o),e!==g){const B=A[g];A[g]=A[e],A[e]=B}}while(e!==g)}};function tyo(g){const A=[];return g.matches.forEach(I=>{if(!aS(I.indices)||!I.indices.length)return;const e={indices:I.indices,value:I.value};I.key&&(e.key=I.key.id),I.idx>-1&&(e.refIndex=I.idx),A.push(e)}),A}function oyo(g,A,{includeMatches:I=rQ.includeMatches,includeScore:e=rQ.includeScore}={}){return g.map(t=>{const{idx:o}=t,B={item:A[o],refIndex:o};return I&&(B.matches=tyo(t)),e&&(B.score=t.score),B})}const Byo=/[\p{L}\p{M}\p{N}_]+/gu,OxI=new WeakSet;function Cyo(g){OxI.has(g)||(OxI.add(g),console.warn(`[Fuse] tokenize regex ${g} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`))}function Qyo(g){if(typeof g=="function"){let A=!1;return I=>{const e=g(I);if(!A&&(A=!0,!Array.isArray(e)||e.some(t=>typeof t!="string")))throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(e)?"array containing non-strings":typeof e}.`);return e}}return g instanceof RegExp?(g.global||Cyo(g),A=>A.match(g)||[]):A=>A.match(Byo)||[]}function Dog({isCaseSensitive:g=!1,ignoreDiacritics:A=!1,tokenize:I}={}){const e=Qyo(I);return{tokenize(t){return g||(t=t.toLowerCase()),A&&(t=VeA(t)),e(t)}}}var iyo=class{static condition(g,A){return A.useTokenSearch}constructor(g,A){this.options=A,this.analyzer=Dog({isCaseSensitive:A.isCaseSensitive,ignoreDiacritics:A.ignoreDiacritics,tokenize:A.tokenize});const I=this.analyzer.tokenize(g),{df:e,fieldCount:t}=A._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(const o of I){this.termSearchers.push(new nog(o,{location:A.location,threshold:A.threshold,distance:A.distance,includeMatches:A.includeMatches,findAllMatches:A.findAllMatches,minMatchCharLength:A.minMatchCharLength,isCaseSensitive:A.isCaseSensitive,ignoreDiacritics:A.ignoreDiacritics,ignoreLocation:!0}));const B=e.get(o)||0,C=Math.log(1+(t-B+.5)/(B+.5));this.idfWeights.push(C)}this.combineAll=A.tokenMatch==="all",this.numTerms=this.termSearchers.length,this.useMask=this.numTerms<=31}searchIn(g){if(!this.termSearchers.length)return{isMatch:!1,score:1};const A=[];let I=0,e=0,t=0,o=0;const B=this.combineAll&&!this.useMask?new Set:null;for(let i=0;i<this.termSearchers.length;i++){const E=this.termSearchers[i].searchIn(g),n=this.idfWeights[i];e+=n,E.isMatch&&(t++,I+=n*(1-E.score),E.indices&&A.push(...E.indices),this.combineAll&&(this.useMask?o|=1<<i:B.add(i)))}if(t===0)return{isMatch:!1,score:1};const C=e>0?1-I/e:0,Q={isMatch:!0,score:Math.max(.001,C)};return this.options.includeMatches&&A.length&&(Q.indices=Eog(A)),this.combineAll&&(this.useMask?Q.matchedMask=o:Q.matchedTerms=B,Q.termCount=this.numTerms),Q}};function dog(g,A,I,e){const t=e.tokenize(A);if(!t.length)return;g.fieldCount++,g.docFieldCount.set(I,(g.docFieldCount.get(I)||0)+1);const o=new Set(t);let B=g.docTermFieldHits.get(I);B||(B=new Map,g.docTermFieldHits.set(I,B));for(const C of o)B.set(C,(B.get(C)||0)+1),g.df.set(C,(g.df.get(C)||0)+1)}function WxI(g,A,I,e){const{i:t,v:o,$:B}=A;if(o!==void 0){dog(g,o,t,e);return}if(B)for(let C=0;C<I;C++){const Q=B[C];if(Q)if(Array.isArray(Q))for(const i of Q)dog(g,i.v,t,e);else dog(g,Q.v,t,e)}}function Eyo(g,A,I){const e={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(const t of g)WxI(e,t,A,I);return e}function nyo(g,A,I,e){WxI(g,A,I,e)}function syo(g,A){const I=g.docFieldCount.get(A);if(I===void 0)return;g.fieldCount-=I,g.docFieldCount.delete(A);const e=g.docTermFieldHits.get(A);if(e){for(const[t,o]of e){const B=(g.df.get(t)||0)-o;B<=0?g.df.delete(t):g.df.set(t,B)}g.docTermFieldHits.delete(A)}}function VxI(g,A){if(A.length===0)return;const I=Array.from(new Set(A)).sort((C,Q)=>C-Q);for(const C of I)syo(g,C);const e=C=>{let Q=0,i=I.length;for(;Q<i;){const E=Q+i>>>1;I[E]<C?Q=E+1:i=E}return C-Q},t=I[0],o=new Map;for(const[C,Q]of g.docFieldCount)o.set(C>t?e(C):C,Q);g.docFieldCount=o;const B=new Map;for(const[C,Q]of g.docTermFieldHits)B.set(C>t?e(C):C,Q);g.docTermFieldHits=B}var W3=class{constructor(g,A,I){this.options={...rQ,...A},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new Ldo(this.options.keys),this._docs=g,this._myIndex=null,this._invertedIndex=null,this.setCollection(g,I),this._lastQuery=null,this._lastSearcher=null}_getSearcher(g){if(this._lastQuery===g)return this._lastSearcher;const A=lGA(g,this._invertedIndex?{...this.options,_invertedIndex:this._invertedIndex}:this.options);return this._lastQuery=g,this._lastSearcher=A,A}setCollection(g,A){if(this._docs=g,A&&!(A instanceof iog))throw new Error(xdo);if(this._myIndex=A||bxI(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){const I=Dog({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=Eyo(this._myIndex.records,this._myIndex.keys.length,I)}this._invalidateSearcherCache()}add(g){if(!aS(g))return;this._docs.push(g);const A=this._myIndex.add(g,this._docs.length-1);if(this._invertedIndex&&A){const I=Dog({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});nyo(this._invertedIndex,A,this._myIndex.keys.length,I)}this._invalidateSearcherCache()}remove(g=()=>!1){const A=[],I=[];for(let e=0,t=this._docs.length;e<t;e+=1)g(this._docs[e],e)&&(A.push(this._docs[e]),I.push(e));if(I.length){this._invertedIndex&&VxI(this._invertedIndex,I);const e=new Set(I);this._docs=this._docs.filter((t,o)=>!e.has(o)),this._myIndex.removeAll(I),this._invalidateSearcherCache()}return A}removeAt(g){if(!Number.isInteger(g)||g<0||g>=this._docs.length)throw new Error(Qog);this._invertedIndex&&VxI(this._invertedIndex,[g]);const A=this._docs.splice(g,1)[0];return this._myIndex.removeAt(g),this._invalidateSearcherCache(),A}_invalidateSearcherCache(){this._lastQuery=null,this._lastSearcher=null}getIndex(){return this._myIndex}_normalizedKeys(){return this._myIndex.keys.map(g=>this._keyStore.get(g.id)||g)}search(g,A){const{limit:I=-1}=A||{},{includeMatches:e,includeScore:t,shouldSort:o,sortFn:B,ignoreFieldNorm:C}=this.options;if(BG(g)&&!g.trim()){let s=this._docs.map((r,a)=>({item:r,refIndex:a}));return rGA(I)&&I>-1&&(s=s.slice(0,I)),s}const Q=o&&rGA(I)&&I>0&&BG(g),i=B,E=(s,r)=>i(s,r)||s.idx-r.idx;let n;if(Q){const s=new eyo(I,E);BG(this._docs[0])?this._searchStringList(g,{heap:s,ignoreFieldNorm:C}):this._searchObjectList(g,{heap:s,ignoreFieldNorm:C}),n=s.extractSorted()}else n=BG(g)?BG(this._docs[0])?this._searchStringList(g):this._searchObjectList(g):this._searchLogical(g),Iyo(n,{ignoreFieldNorm:C}),o&&n.sort(BG(g)?E:i),rGA(I)&&I>-1&&(n=n.slice(0,I));return oyo(n,this._docs,{includeMatches:e,includeScore:t})}_searchStringList(g,{heap:A,ignoreFieldNorm:I}={}){const e=this._getSearcher(g),t=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:o}=this._myIndex,B=A?null:[];return o.forEach(({v:C,i:Q,n:i})=>{if(!aS(C))return;const E=e.searchIn(C);if(E.isMatch){const n={score:E.score,value:C,norm:i,indices:E.indices};t&&(n.matchedMask=E.matchedMask,n.matchedTerms=E.matchedTerms,n.termCount=E.termCount);const s=[n];if(!t||this._coversAllTokens(s)){const r={item:C,idx:Q,matches:s};A?(r.score=log(r.matches,{ignoreFieldNorm:I}),A.insert(r)):B.push(r)}}}),B}_searchLogical(g){const A=ZxI(g,this.options),I=this._normalizedKeys(),e=(C,Q,i)=>{if(!("children"in C)){const{keyId:r,searcher:a}=C;let c;return r===null?(c=[],I.forEach((h,l)=>{c.push(...this._findMatches({key:h,value:Q[l],searcher:a}))})):c=this._findMatches({key:this._keyStore.get(r),value:this._myIndex.getValueForItemAtKeyId(Q,r),searcher:a}),c&&c.length?[{idx:i,item:Q,matches:c}]:[]}const{children:E,operator:n}=C,s=[];for(let r=0,a=E.length;r<a;r+=1){const c=E[r],h=e(c,Q,i);if(h.length)s.push(...h);else if(n===DGA.AND)return[]}return s},t=this._myIndex.records,o=new Map,B=[];return t.forEach(({$:C,i:Q})=>{if(aS(C)){const i=e(A,C,Q);i.length&&(o.has(Q)||(o.set(Q,{idx:Q,item:C,matches:[]}),B.push(o.get(Q))),i.forEach(({matches:E})=>{o.get(Q).matches.push(...E)}))}}),B}_searchObjectList(g,{heap:A,ignoreFieldNorm:I}={}){const e=this._getSearcher(g),t=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:o}=this._myIndex,B=this._normalizedKeys(),C=A?null:[];return o.forEach(({$:Q,i})=>{if(!aS(Q))return;const E=[];let n=!1,s=!1;if(B.forEach((r,a)=>{const c=this._findMatches({key:r,value:Q[a],searcher:e});c.length?(E.push(...c),c[0].hasInverse&&(s=!0)):n=!0}),!(s&&n)&&E.length&&(!t||this._coversAllTokens(E))){const r={idx:i,item:Q,matches:E};A?(r.score=log(r.matches,{ignoreFieldNorm:I}),A.insert(r)):C.push(r)}}),C}_findMatches({key:g,value:A,searcher:I}){if(!aS(A))return[];const e=[];if(O3(A))A.forEach(({v:t,i:o,n:B})=>{if(!aS(t))return;const C=I.searchIn(t);if(C.isMatch){const Q={score:C.score,key:g,value:t,idx:o,norm:B,indices:C.indices,hasInverse:C.hasInverse};C.termCount!==void 0&&(Q.matchedMask=C.matchedMask,Q.matchedTerms=C.matchedTerms,Q.termCount=C.termCount),e.push(Q)}});else{const{v:t,n:o}=A,B=I.searchIn(t);if(B.isMatch){const C={score:B.score,key:g,value:t,norm:o,indices:B.indices,hasInverse:B.hasInverse};B.termCount!==void 0&&(C.matchedMask=B.matchedMask,C.matchedTerms=B.matchedTerms,C.termCount=B.termCount),e.push(C)}}return e}_coversAllTokens(g){const A=g.length?g[0].termCount:void 0;if(A===void 0)return!0;if(A<=31){let e=0;for(let t=0;t<g.length;t++)e|=g[t].matchedMask||0;return e===2**A-1}const I=new Set;for(let e=0;e<g.length;e++){const t=g[e].matchedTerms;if(t)for(const o of t)I.add(o)}return I.size===A}};W3.version="7.5.0",W3.createIndex=bxI,W3.parseIndex=Hdo,W3.config=rQ,W3.match=function(g,A,I){if(I&&I.useTokenSearch)throw new Error(Kdo);return lGA(g,{...rQ,...I}).searchIn(A)},W3.parseQuery=ZxI,rog($do),rog(iyo),W3.use=function(...g){g.forEach(A=>rog(A))};var ayo=W3;const ryo="https://kicad-mod-cache.tscircuit.com";let yog=null,jeA=null,wog=null;const cyo=async()=>yog||jeA||(jeA=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(g=>g.json()).then(g=>(yog=g,jeA=null,g)),jeA),hyo=async(g,A=20)=>{const I=await cyo();return wog||(wog=new ayo(I)),wog.search(g).slice(0,A).map(e=>e.item)},lyo=g=>{const A=g.replace(".pretty/","/").replace(".kicad_mod",""),I=`kicad:${A}`;return{path:g,qualifiedName:I,description:A}},Dyo=g=>g.replace(/^\/+/,"").split("/").map(A=>encodeURIComponent(A)).join("/"),dyo=async g=>{const A=await fetch(`${ryo}/${Dyo(g)}`);if(!A.ok)throw new Error(`KiCad footprint fetch failed: ${A.status}`);const I=await A.text(),{KicadFootprintToCircuitJsonConverter:e}=await sS("kicad-to-circuit-json"),t=new e;return t.addFile(g.split("/").pop()??"selected-footprint.kicad_mod",I),t.runUntilFinished(),t.getOutput()},jxI=g=>g?.source==="jlcpcb"||g?.source==="kicad",yyo=async(g,A)=>{if(g.source==="jlcpcb")return Sdo(g.component.partNumber,A?.jlcpcb);if(g.source==="kicad")return dyo(g.footprint.path);throw new Error("Footprint preview is not available for this source")},wyo=({query:g,placeholder:A,isSearching:I,onQueryChange:e,onSubmit:t})=>{const o=X.useCallback(B=>{B.key==="Enter"&&(B.preventDefault(),t())},[t]);return q.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[q.jsxs("div",{className:"rf-relative rf-flex-grow",children:[q.jsx(reg,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),q.jsx(_tg,{placeholder:A,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:g,onChange:B=>e(B.target.value),onKeyDown:o})]}),q.jsx(Ei,{onClick:t,disabled:I||g.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:I?q.jsx(BS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):q.jsxs(q.Fragment,{children:[q.jsx(reg,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),q.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},uyo=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),Gyo=g=>uyo.format(g),zxI=g=>{switch(g.source){case"tscircuit.com":{const A=g.package;return`tscircuit-${A.package_id??`${A.org_owner_tscircuit_handle??"unknown"}-${A.unscoped_name??A.name??"package"}`}`}case"jlcpcb":return`jlc-${g.component.lcscId}`;case"kicad":return`kicad-${g.footprint.path}`;default:return"unknown"}},myo=g=>{switch(g.source){case"tscircuit.com":return g.package.unscoped_name;case"jlcpcb":return g.component.isDirectLookup?g.component.partNumber:g.component.manufacturer;case"kicad":return g.footprint.qualifiedName}},pyo=g=>{switch(g.source){case"tscircuit.com":return g.package.description||(g.package.org_owner_tscircuit_handle?`Component by ${g.package.org_owner_tscircuit_handle}`:void 0);case"jlcpcb":return g.component.description;case"kicad":return g.footprint.description}},kyo=g=>{switch(g.source){case"tscircuit.com":return g.package.name;case"jlcpcb":return g.component.isDirectLookup?void 0:g.component.partNumber;case"kicad":return}},Myo=({results:g,selected:A,onSelect:I,onShowDetails:e})=>{const t=A?zxI(A):null;return q.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:g.map(o=>{const B=zxI(o),C=t===B,Q=myo(o),i=pyo(o),E=kyo(o),n=o.source==="jlcpcb"?o.component.stock:null,s=o.source==="jlcpcb"?o.component.price:null,r=o.source==="jlcpcb"?o.component.isBasic:null,a=o.source==="jlcpcb"?o.component.isDirectLookup:!1;return q.jsxs("div",{className:`rf-p-3 rf-flex rf-flex-col sm:rf-grid sm:rf-grid-cols-[minmax(0,1fr)_auto] rf-items-start sm:rf-items-center rf-cursor-pointer hover:rf-bg-zinc-100 rf-gap-2 rf-overflow-hidden ${C?"rf-bg-zinc-100":""}`,onClick:()=>I(o),children:[q.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[q.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[q.jsxs("div",{className:"rf-font-medium rf-text-sm rf-truncate rf-flex-1 rf-min-w-0 rf-flex rf-items-center rf-gap-1.5",children:[Q,o.source==="jlcpcb"&&r!=null&&q.jsx("span",{className:`rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 ${r?"rf-bg-green-100 rf-text-green-700":"rf-bg-orange-100 rf-text-orange-700"}`,children:r?"Basic":"Extended"}),a&&q.jsx("span",{className:"rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 rf-bg-blue-100 rf-text-blue-700",children:"Direct lookup"}),o.source==="tscircuit.com"&&o.package.is_private&&q.jsx(TCo,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),o.source==="jlcpcb"&&n!=null?q.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[n.toLocaleString()," in stock"]}):null]}),q.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[E?q.jsx("span",{className:"rf-mr-2",children:E}):null,i]})]}),q.jsxs("div",{children:[o.source==="tscircuit.com"&&e?q.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:q.jsx(Ei,{variant:"outline",size:"sm",className:"rf-text-xs rf-w-full sm:rf-w-auto",onClick:c=>{c.stopPropagation(),e(o)},children:"See Details"})}):o.source==="jlcpcb"&&n!=null?q.jsxs("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0",children:[n.toLocaleString()," in stock"]}):null,s!=null&&q.jsx("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 rf-text-right",children:Gyo(s)})]})]},B)})})},Syo=({circuitJson:g,error:A,isLoading:I,height:e})=>q.jsx("section",{className:"rf-flex rf-min-w-0 rf-items-center rf-justify-center",style:{height:e},children:I?q.jsxs("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-gap-2 rf-bg-zinc-950 rf-text-sm rf-text-zinc-300",style:{height:e},children:[q.jsx(BS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),"Loading preview..."]}):A?q.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-p-4",style:{height:e},children:q.jsxs("div",{className:"rf-flex rf-max-w-[320px] rf-items-start rf-gap-2 rf-text-sm rf-text-zinc-300",children:[q.jsx(aeg,{className:"rf-mt-0.5 rf-h-4 rf-w-4 rf-flex-shrink-0"}),q.jsx("span",{children:A})]})}):g?q.jsx("div",{className:"rf-w-full rf-min-w-0 rf-overflow-hidden",children:q.jsx(Eeg,{circuitJson:g,height:e,allowEditing:!1,clickToInteractEnabled:!1,focusOnHover:!1,disablePcbGroups:!0})}):q.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-text-sm rf-text-zinc-300",style:{height:e},children:"No preview"})}),XxI={importComponentDialog:101,importComponentDetailsDialog:102},fyo=({packageResult:g,isOpen:A,onOpenChange:I,isLoading:e,details:t,previewTab:o,onPreviewTabChange:B,isSubmitting:C,onImport:Q})=>{const i=g?.package??null,E=i?.latest_pcb_preview_image_url,n=i?.latest_sch_preview_image_url,s=i?.latest_cad_preview_image_url,r=i?.unscoped_name?.split("/").pop()??i?.unscoped_name,a=i?.org_owner_tscircuit_handle??void 0,c=a?`https://tscircuit.com/${a}`:void 0,h=a&&r?`https://tscircuit.com/${a}/${r}`:void 0;return q.jsx(Z5,{open:A,onOpenChange:I,children:q.jsxs(q3,{showOverlay:!1,style:{width:"calc(100vw - 2rem)",zIndex:XxI.importComponentDetailsDialog},className:"rf-max-w-5xl no-scrollbar !rf-overflow-y-auto rf-max-h-[90vh] rf-overflow-hidden rf-flex rf-flex-col rf-rounded-sm",children:[q.jsx(T3,{className:"rf-pb-4 rf-border-b",children:q.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:q.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[q.jsx(Z3,{className:"rf-text-xl rf-font-semibold rf-truncate",children:r}),q.jsx(O5,{children:i?.description})]})})}),q.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[a?q.jsxs("div",{children:[q.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),q.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:c?q.jsx("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:a}):a})]}):null,(s||E||n)&&q.jsx(q.Fragment,{children:q.jsxs("div",{children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),q.jsxs(ZHA,{value:o,onValueChange:l=>B(l),children:[q.jsxs(llA,{className:"rf-inline-flex rf-h-9 rf-items-center rf-justify-center rf-rounded-lg rf-bg-zinc-100 rf-p-1 rf-text-zinc-500 dark:rf-bg-zinc-800 dark:rf-text-zinc-400",children:[E&&q.jsx(gx,{value:"pcb",children:"PCB"}),n&&q.jsx(gx,{value:"schematic",children:"Schematic"}),s&&q.jsx(gx,{value:"3d",children:"3D"})]}),q.jsxs("div",{className:"rf-mt-4",children:[q.jsx(xw,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:E?q.jsx("img",{src:E,alt:`${r??"package"} PCB preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),q.jsx(xw,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:n?q.jsx("img",{src:n,alt:`${r??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),q.jsx(xw,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:s?q.jsx("img",{src:s,alt:`${r??"package"} 3D preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null})]})]})]})}),t?.ai_description?q.jsxs("section",{children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),q.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:q.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:t.ai_description})})]}):null,t?.ai_usage_instructions?q.jsxs("section",{children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),q.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:q.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:t.ai_usage_instructions})})]}):null,e?q.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[q.jsx(BS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),q.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),q.jsxs(FZ,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[q.jsx("div",{className:"rf-flex-1",children:h?q.jsxs(Ei,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(h,"_blank"),children:[q.jsx(LCo,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),q.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[q.jsx(Ei,{variant:"outline",onClick:()=>I(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),q.jsx(Ei,{onClick:Q,disabled:C,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:C?q.jsx(BS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},Ryo=()=>{const[g,A]=X.useState(null),[I,e]=X.useState(!1),t=X.useCallback(async(B,C)=>{e(!0);try{const Q=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${B}/${C}`)}`);if(!Q.ok)throw new Error(`Failed to load package details: ${Q.status}`);const i=await Q.json();A(i.package??null)}catch(Q){console.error("Failed to fetch package details",Q),A(null)}finally{e(!1)}},[]),o=X.useCallback(()=>{A(null),e(!1)},[]);return{details:g,isLoading:I,fetchDetails:t,reset:o}},Nyo=(g,A)=>{const[I,e]=X.useState({circuitJson:null,error:null,isLoading:!1});return X.useEffect(()=>{if(!g||!jxI(g)){e({circuitJson:null,error:null,isLoading:!1});return}let t=!1;return e({circuitJson:null,error:null,isLoading:!0}),yyo(g,A).then(o=>{t||e({circuitJson:o,error:null,isLoading:!1})}).catch(o=>{t||e({circuitJson:null,error:o instanceof Error?o.message:"Failed to load footprint preview",isLoading:!1})}),()=>{t=!0}},[g,A]),I},xyo=async(g,A)=>{const I={"Content-Type":"application/json"};A&&(I.Authorization=`Bearer ${A}`);const e=await fetch("https://registry-api.tscircuit.com/packages/search",{method:"POST",headers:I,body:JSON.stringify({query:g})});if(!e.ok)throw new Error(`tscircuit registry error: ${e.status}`);return(await e.json()).packages??[]},Fyo=({sessionToken:g})=>{const[A,I]=X.useState([]),[e,t]=X.useState(!1),[o,B]=X.useState(null),[C,Q]=X.useState(!1),i=X.useCallback(async n=>{const s=n.trim();if(!s)return[];t(!0),B(null);try{const a=(await xyo(s,g)).map(c=>({source:"tscircuit.com",package:c}));return I(a),a}catch(r){return console.error("Error searching tscircuit packages",r),I([]),B(r instanceof Error?r.message:"Failed to search tscircuit packages"),[]}finally{t(!1),Q(!0)}},[g]),E=X.useCallback(()=>{I([]),t(!1),B(null),Q(!1)},[]);return{results:A,isSearching:e,error:o,hasSearched:C,search:i,reset:E}},Uyo=g=>{const A=/^C(\d+)$/i.exec(g.trim());if(!A)return null;const I=Number(A[1]);if(!Number.isSafeInteger(I))return null;const e=`C${A[1]}`;return{source:"jlcpcb",component:{lcscId:I,manufacturer:e,partNumber:e,description:"Import directly from EasyEDA; stock and availability are unknown",package:"",isDirectLookup:!0}}},$xI=(g,A)=>{const I=Uyo(g);return I?A.some(t=>t.component.partNumber.toUpperCase()===I.component.partNumber)?A:[I,...A]:A},Jyo=g=>{const A=g.trim();return/^C\d+/i.test(A)?A.replace(/^C/i,""):A},Pyo=()=>{const[g,A]=X.useState([]),[I,e]=X.useState(!1),[t,o]=X.useState(null),[B,C]=X.useState(!1),Q=X.useCallback(async E=>{const n=Jyo(E);if(!n)return[];e(!0),o(null);try{const s=await pdo(n,10),r=$xI(E,s.map(a=>({source:"jlcpcb",component:kdo(a)})));return A(r),r}catch(s){console.error("Error searching JLCPCB components",s);const r=$xI(E,[]);return A(r),o(r.length>0?null:s instanceof Error?s.message:"Failed to search JLCPCB components"),r}finally{e(!1),C(!0)}},[]),i=X.useCallback(()=>{A([]),e(!1),o(null),C(!1)},[]);return{results:g,isSearching:I,error:t,hasSearched:B,search:Q,reset:i}},Kyo=()=>{const[g,A]=X.useState([]),[I,e]=X.useState(!1),[t,o]=X.useState(null),[B,C]=X.useState(!1),Q=X.useCallback(async E=>{const n=E.trim();if(!n)return[];e(!0),o(null);try{const r=(await hyo(n,20)).map(a=>({source:"kicad",footprint:lyo(a)}));return A(r),r}catch(s){return console.error("Error searching KiCad footprints",s),A([]),o(s instanceof Error?s.message:"Failed to search KiCad footprints"),[]}finally{e(!1),C(!0)}},[]),i=X.useCallback(()=>{A([]),e(!1),o(null),C(!1)},[]);return{results:g,isSearching:I,error:t,hasSearched:B,search:Q,reset:i}},Lyo=({onTscircuitPackageSelected:g,onJlcpcbComponentTsxLoaded:A,onKicadStringSelected:I})=>{const e=[];return g&&e.push("tscircuit.com"),A&&e.push("jlcpcb"),I&&e.push("kicad"),e},Yyo=({isOpen:g,onClose:A,jlcpcbProxyRequestHeaders:I,onKicadStringSelected:e,onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:o,jlcpcbProxyApiBase:B,tscircuitSessionToken:C})=>{TeA();const Q=X.useMemo(()=>Lyo({onKicadStringSelected:e,onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:o}),[e,t,o]),i=Q.length>0,E=Q.length===1,[n,s]=X.useState(Q[0]??"tscircuit.com"),[r,a]=X.useState(""),[c,h]=X.useState(null),{results:l,isSearching:D,error:d,hasSearched:y,search:w,reset:u}=Fyo({sessionToken:C}),{results:G,isSearching:m,error:p,hasSearched:k,search:S,reset:R}=Pyo(),{results:x,isSearching:N,error:J,hasSearched:K,search:_,reset:H}=Kyo(),{details:T,isLoading:j,fetchDetails:W,reset:O}=Ryo(),[gA,tA]=X.useState(null),[IA,QA]=X.useState(!1),[nA,DA]=X.useState("pcb"),[CA,hA]=X.useState(null),[sA,cA]=X.useState(!1),SA=X.useMemo(()=>({jlcpcb:{headers:I,apiBase:B}}),[B,I]),{circuitJson:xA,error:aA,isLoading:FA}=Nyo(c,SA),NA=jxI(c);X.useEffect(()=>{hA(null)},[c]);const RA=X.useCallback(()=>{u(),R(),H(),h(null)},[R,H,u]);X.useEffect(()=>{g||(RA(),a(""),QA(!1),tA(null),hA(null))},[g,RA]),X.useEffect(()=>{a(""),h(null),n==="tscircuit.com"?u():n==="jlcpcb"?R():n==="kicad"&&H()},[n,R,H,u]);const JA=kA=>{h(kA),tA(kA),DA("pcb"),QA(!0),O();const OA=kA.package.org_owner_tscircuit_handle,$A=kA.package.unscoped_name;if(OA&&$A){const tg=$A.split("/").pop()??$A;W(OA,tg)}},PA=async()=>{r.trim()&&(h(null),n==="tscircuit.com"?await w(r):n==="jlcpcb"?await S(r):n==="kicad"&&await _(r))},pA=async kA=>{try{if(hA(null),cA(!0),kA.source==="kicad"){if(!e)throw new Error("KiCad handler not provided");await e({result:kA,footprint:kA.footprint.qualifiedName})}else if(kA.source==="jlcpcb"){if(!o)throw new Error("JLCPCB handler not provided");const OA=await Mdo(kA.component.partNumber,{headers:I,apiBase:B});await o({result:kA,tsx:OA})}else if(kA.source==="tscircuit.com"){if(!t)throw new Error("tscircuit package handler not provided");const OA=kA.package.org_owner_tscircuit_handle,$A=kA.package.unscoped_name;if(!OA||!$A)throw new Error("Missing package metadata");const tg=$A.split("/").pop()??$A,dg=`@tsci/${OA}.${tg}`;await t({result:kA,fullPackageName:dg})}return!0}catch(OA){return console.error("Failed to import component",OA),hA(OA instanceof Error?OA.message:"Failed to import component"),!1}finally{cA(!1)}};let YA=[],dA=!1,HA=null,WA=!1;n==="tscircuit.com"?(YA=l,dA=D,HA=d,WA=y):n==="jlcpcb"?(YA=G,dA=m,HA=p,WA=k):n==="kicad"&&(YA=x,dA=N,HA=J,WA=K);const Qg=async()=>{if(!c)return;await pA(c)&&(A(),RA(),a(""))},_A=kA=>{kA||A()},GA=kA=>{QA(kA),kA||tA(null)};return q.jsxs(Z5,{open:g,onOpenChange:_A,children:[q.jsxs(q3,{style:{width:"calc(100vw - 2rem)",maxWidth:NA?"min(1120px, calc(100vw - 2rem))":"min(672px, calc(100vw - 2rem))",zIndex:XxI.importComponentDialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[q.jsxs(T3,{children:[q.jsxs(Z3,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",E?aGA[n].label:""," ","Component"]}),q.jsx(O5,{className:"rf-text-sm",children:i?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),i?q.jsxs(ZHA,{value:n,onValueChange:kA=>s(kA),className:"rf-min-w-0 rf-w-full",children:[!E&&q.jsx(llA,{className:"rf-flex rf-w-full rf-gap-2",children:Q.map(kA=>q.jsx(gx,{value:kA,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:aGA[kA].label},kA))}),q.jsxs("div",{className:"rf-min-w-0",style:NA?{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(360px, 0.95fr)",gap:"1.5rem",alignItems:"start"}:void 0,children:[q.jsxs("div",{className:"rf-min-w-0",children:[q.jsx(wyo,{query:r,placeholder:aGA[n].placeholder,isSearching:dA,onQueryChange:a,onSubmit:PA}),q.jsx("div",{className:"no-scrollbar rf-mt-4 rf-flex-1 rf-min-h-[200px] !rf-max-h-[40vh] !rf-overflow-y-auto rf-overflow-x-hidden rf-border rf-rounded-md rf-min-w-0",children:dA?q.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[q.jsx(BS,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),q.jsx("p",{children:"Searching..."})]}):YA.length>0?q.jsx(Myo,{results:YA,selected:c,onSelect:h,onShowDetails:n==="tscircuit.com"?JA:void 0}):q.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:HA?`Error: ${HA}`:WA?aGA[n].emptyMessage:"Enter a search term to find components"})})]}),NA?q.jsx("div",{className:"rf-mt-4",children:q.jsx(Syo,{circuitJson:xA,error:aA,isLoading:FA,height:325})}):null]})]}):null,CA?q.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:CA}):null,q.jsxs(FZ,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[q.jsx(Ei,{variant:"outline",onClick:A,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),q.jsx(Ei,{onClick:Qg,disabled:!c||sA,className:"rf-order-1 sm:rf-order-2",children:sA?q.jsx(BS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),q.jsx(fyo,{packageResult:gA,isOpen:IA,onOpenChange:GA,isLoading:j,details:T,previewTab:nA,onPreviewTabChange:kA=>DA(kA),isSubmitting:sA,onImport:()=>{gA&&pA(gA).then(kA=>{kA&&(QA(!1),A(),RA(),a(""))})}})]})},_yo=g=>{const A=g.match(/export const (\w+) =/);if(!A)throw new Error("Could not determine component name from TSX contents");return A[1]},AFI=g=>{const A=Fc(B=>B.pushEvent),I=Fc(B=>B.upsertFile),e=async({result:B,fullPackageName:C})=>{const i=B.package.unscoped_name??B.package.name;await JC.promise(A({event_type:"INSTALL_PACKAGE",full_package_name:C}),{loading:`Requesting install for "${i}"`,success:`Install requested for "${i}"`,error:E=>`Failed to request install: ${E instanceof Error?E.message:String(E)}`})},t=async({footprint:B})=>{await JC.promise(navigator.clipboard.writeText(B),{loading:`Copying "${B}"`,success:`Copied "${B}" to clipboard`,error:C=>`Failed to copy footprint: ${C instanceof Error?C.message:String(C)}`})},o=async({result:B,tsx:C})=>{const i=`imports/${_yo(C)}.tsx`;await JC.promise(I(i,C),{loading:`Importing ${B.component.partNumber}`,success:`Imported to "${i}"`,error:E=>`Failed to import component: ${E instanceof Error?E.message:String(E)}`})};return q.jsx(Yyo,{...g,onTscircuitPackageSelected:e,onKicadStringSelected:t,onJlcpcbComponentTsxLoaded:o})};AFI.displayName="ImportComponentDialogForCli";const byo=async({circuitJson:g,projectName:A})=>{const{convertCircuitJsonToAltiumZip:I}=await Promise.resolve().then(()=>B_o),e=await I(g,A);return new Blob([new Uint8Array(e)],{type:"application/zip"})},Hyo=async({circuitJson:g,projectName:A})=>{await JC.promise((async()=>{const I=await byo({circuitJson:g,projectName:A});mk(I,{fileName:`${A}_altium_project.zip`})})(),{loading:"Generating Altium project...",success:"Altium project ZIP ready",error:I=>`Failed to generate Altium project: ${I instanceof Error?I.message:String(I)}`})};var uog={exports:{}},gFI;function vyo(){return gFI||(gFI=1,(function(g,A){var I={env:{},version:""};(function(e){g.exports=e()})(function(){return(function e(t,o,B){function C(E,n){if(!o[E]){if(!t[E]){var s=typeof LF=="function"&&LF;if(!n&&s)return s(E,!0);if(Q)return Q(E,!0);var r=new Error("Cannot find module '"+E+"'");throw r.code="MODULE_NOT_FOUND",r}var a=o[E]={exports:{}};t[E][0].call(a.exports,function(c){var h=t[E][1][c];return C(h||c)},a,a.exports,e,t,o,B)}return o[E].exports}for(var Q=typeof LF=="function"&&LF,i=0;i<B.length;i++)C(B[i]);return C})({1:[function(e,t,o){var B=e("./utils"),C=e("./support"),Q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";o.encode=function(i){for(var E,n,s,r,a,c,h,l=[],D=0,d=i.length,y=d,w=B.getTypeOf(i)!=="string";D<i.length;)y=d-D,s=w?(E=i[D++],n=D<d?i[D++]:0,D<d?i[D++]:0):(E=i.charCodeAt(D++),n=D<d?i.charCodeAt(D++):0,D<d?i.charCodeAt(D++):0),r=E>>2,a=(3&E)<<4|n>>4,c=1<y?(15&n)<<2|s>>6:64,h=2<y?63&s:64,l.push(Q.charAt(r)+Q.charAt(a)+Q.charAt(c)+Q.charAt(h));return l.join("")},o.decode=function(i){var E,n,s,r,a,c,h=0,l=0,D="data:";if(i.substr(0,D.length)===D)throw new Error("Invalid base64 input, it looks like a data url.");var d,y=3*(i=i.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(i.charAt(i.length-1)===Q.charAt(64)&&y--,i.charAt(i.length-2)===Q.charAt(64)&&y--,y%1!=0)throw new Error("Invalid base64 input, bad content length.");for(d=C.uint8array?new Uint8Array(0|y):new Array(0|y);h<i.length;)E=Q.indexOf(i.charAt(h++))<<2|(r=Q.indexOf(i.charAt(h++)))>>4,n=(15&r)<<4|(a=Q.indexOf(i.charAt(h++)))>>2,s=(3&a)<<6|(c=Q.indexOf(i.charAt(h++))),d[l++]=E,a!==64&&(d[l++]=n),c!==64&&(d[l++]=s);return d}},{"./support":30,"./utils":32}],2:[function(e,t,o){var B=e("./external"),C=e("./stream/DataWorker"),Q=e("./stream/Crc32Probe"),i=e("./stream/DataLengthProbe");function E(n,s,r,a,c){this.compressedSize=n,this.uncompressedSize=s,this.crc32=r,this.compression=a,this.compressedContent=c}E.prototype={getContentWorker:function(){var n=new C(B.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new i("data_length")),s=this;return n.on("end",function(){if(this.streamInfo.data_length!==s.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),n},getCompressedWorker:function(){return new C(B.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},E.createWorkerFrom=function(n,s,r){return n.pipe(new Q).pipe(new i("uncompressedSize")).pipe(s.compressWorker(r)).pipe(new i("compressedSize")).withStreamInfo("compression",s)},t.exports=E},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(e,t,o){var B=e("./stream/GenericWorker");o.STORE={magic:"\0\0",compressWorker:function(){return new B("STORE compression")},uncompressWorker:function(){return new B("STORE decompression")}},o.DEFLATE=e("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(e,t,o){var B=e("./utils"),C=(function(){for(var Q,i=[],E=0;E<256;E++){Q=E;for(var n=0;n<8;n++)Q=1&Q?3988292384^Q>>>1:Q>>>1;i[E]=Q}return i})();t.exports=function(Q,i){return Q!==void 0&&Q.length?B.getTypeOf(Q)!=="string"?(function(E,n,s,r){var a=C,c=r+s;E^=-1;for(var h=r;h<c;h++)E=E>>>8^a[255&(E^n[h])];return-1^E})(0|i,Q,Q.length,0):(function(E,n,s,r){var a=C,c=r+s;E^=-1;for(var h=r;h<c;h++)E=E>>>8^a[255&(E^n.charCodeAt(h))];return-1^E})(0|i,Q,Q.length,0):0}},{"./utils":32}],5:[function(e,t,o){o.base64=!1,o.binary=!1,o.dir=!1,o.createFolders=!0,o.date=null,o.compression=null,o.compressionOptions=null,o.comment=null,o.unixPermissions=null,o.dosPermissions=null},{}],6:[function(e,t,o){var B=null;B=typeof Promise<"u"?Promise:e("lie"),t.exports={Promise:B}},{lie:37}],7:[function(e,t,o){var B=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",C=e("pako"),Q=e("./utils"),i=e("./stream/GenericWorker"),E=B?"uint8array":"array";function n(s,r){i.call(this,"FlateWorker/"+s),this._pako=null,this._pakoAction=s,this._pakoOptions=r,this.meta={}}o.magic="\b\0",Q.inherits(n,i),n.prototype.processChunk=function(s){this.meta=s.meta,this._pako===null&&this._createPako(),this._pako.push(Q.transformTo(E,s.data),!1)},n.prototype.flush=function(){i.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},n.prototype.cleanUp=function(){i.prototype.cleanUp.call(this),this._pako=null},n.prototype._createPako=function(){this._pako=new C[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var s=this;this._pako.onData=function(r){s.push({data:r,meta:s.meta})}},o.compressWorker=function(s){return new n("Deflate",s)},o.uncompressWorker=function(){return new n("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(e,t,o){function B(a,c){var h,l="";for(h=0;h<c;h++)l+=String.fromCharCode(255&a),a>>>=8;return l}function C(a,c,h,l,D,d){var y,w,u=a.file,G=a.compression,m=d!==E.utf8encode,p=Q.transformTo("string",d(u.name)),k=Q.transformTo("string",E.utf8encode(u.name)),S=u.comment,R=Q.transformTo("string",d(S)),x=Q.transformTo("string",E.utf8encode(S)),N=k.length!==u.name.length,J=x.length!==S.length,K="",_="",H="",T=u.dir,j=u.date,W={crc32:0,compressedSize:0,uncompressedSize:0};c&&!h||(W.crc32=a.crc32,W.compressedSize=a.compressedSize,W.uncompressedSize=a.uncompressedSize);var O=0;c&&(O|=8),m||!N&&!J||(O|=2048);var gA=0,tA=0;T&&(gA|=16),D==="UNIX"?(tA=798,gA|=(function(QA,nA){var DA=QA;return QA||(DA=nA?16893:33204),(65535&DA)<<16})(u.unixPermissions,T)):(tA=20,gA|=(function(QA){return 63&(QA||0)})(u.dosPermissions)),y=j.getUTCHours(),y<<=6,y|=j.getUTCMinutes(),y<<=5,y|=j.getUTCSeconds()/2,w=j.getUTCFullYear()-1980,w<<=4,w|=j.getUTCMonth()+1,w<<=5,w|=j.getUTCDate(),N&&(_=B(1,1)+B(n(p),4)+k,K+="up"+B(_.length,2)+_),J&&(H=B(1,1)+B(n(R),4)+x,K+="uc"+B(H.length,2)+H);var IA="";return IA+=`
5677
+ `,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 q.jsxs("div",{className:`relative ${A}`,ref:t,children:[q.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&&q.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:B,children:"Download page.tsx"}),q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:C,children:"Download test.ts"})]})]})},CxI=g=>g.activeSubSolver?[g,...CxI(g.activeSubSolver)]:[g],sDo=({solver:g})=>{const A=CxI(g);return q.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((I,e)=>q.jsxs("div",{className:"flex items-center",children:[e>0&&q.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),q.jsx(nDo,{solver:I})]},I.getSolverName()))})},aDo=({solver:g,triggerRender:A,animationSpeed:I=25,renderer:e,onRendererChange:t,onAnimationSpeedChange:o,onDownloadVisualization:B,onSolverStarted:C,onSolverCompleted:Q})=>{const[i,E]=X.useReducer(m=>!m,!1),n=X.useRef(void 0),s=X.useRef(null),r="solver-debugger-last-iteration",[a,c]=X.useState(null),h=X.useRef(null),l=X.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 X.useEffect(()=>()=>{d()},[]),X.useEffect(()=>{(g.solved||g.failed)&&i&&(d(),E())},[g.solved,g.failed,i]),X.useEffect(()=>{i&&(d(),D())},[I,i]),X.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)}},[]),q.jsxs("div",{className:"space-y-2 p-2 border-b",children:[q.jsx("div",{className:"flex items-center",children:q.jsxs("div",{className:"flex items-center gap-2",ref:h,children:[q.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[q.jsxs("div",{className:"relative",children:[q.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"&&q.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=>q.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&&q.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},m))})]}),q.jsxs("div",{className:"relative",children:[q.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"&&q.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:q.jsx("button",{type:"button",onClick:()=>{B(),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),q.jsxs("div",{className:"relative",children:[q.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"&&q.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=>q.jsxs("button",{type:"button",onClick:()=>{o(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,q.jsx("span",{className:"ml-auto text-xs text-slate-500",children:m.description}),I===m.value&&q.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},m.value))})]})]}),q.jsx(sDo,{solver:g})]})}),q.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[q.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"}),q.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"}),q.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"}),q.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"}),q.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",g.iterations]}),g.timeToSolve!==void 0&&q.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(g.timeToSolve/1e3).toFixed(3),"s"]}),g.solved&&q.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),g.failed&&q.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),g.error&&q.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",g.error]})]})},rDo=g=>g!==null&&"pipelineDef"in g&&Array.isArray(g.pipelineDef),cDo=(g,A,I)=>{const e=g.currentPipelineStageIndex;return A<e?"Completed":A===e&&g.activeSubSolver?g.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},hDo=(g,A)=>{const e=g.pipelineDef[A].solverName,t=cDo(g,A),o=g[e],B=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&&B!==null?Q=r-B:B!==null&&(Q=C-B)}else t==="In Progress"&&B!==null&&(Q=C-B);const i=g.timeSpentOnStage?.[e]??0;let E=0;t==="Completed"?E=1:t==="In Progress"&&o&&(E=o.progress??0);const n=o?.stats??null;return{index:A,name:e,status:t,firstIteration:B,iterations:Q,progress:E,timeSpent:i,stats:n&&Object.keys(n).length>0?n:null,solverInstance:o??null}},lDo=({status:g})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return q.jsx("span",{className:`font-medium ${A[g]}`,children:g})},DDo=({progress:g})=>{if(g===0)return null;const A=Math.round(g*100);return q.jsxs("div",{className:"flex items-center gap-2",children:[q.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:q.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),q.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},QxI=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)},dDo=g=>Object.entries(g).map(([A,I])=>`${A}: ${QxI(I)}`).join(", "),yDo=({stats:g})=>{if(!g||Object.keys(g).length===0)return q.jsx("span",{children:"-"});const A=Object.entries(g),I=dDo(g);return q.jsxs("details",{className:"cursor-pointer",children:[q.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:I}),q.jsx("div",{className:"mt-1 text-xs",children:A.map(([e,t])=>q.jsxs("div",{children:[e,": ",QxI(t)]},e))})]})},Ztg=g=>{if(g===null||typeof g!="object")return g;if(Array.isArray(g))return g.map(Ztg);const A={};for(const[I,e]of Object.entries(g))I.startsWith("_")||(A[I]=Ztg(e));return A},wDo=(g,A)=>{try{if(typeof g.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const I=Ztg(g.getConstructorParams()),e=new Blob([JSON.stringify(I,null,2)],{type:"application/json"}),t=URL.createObjectURL(e),o=document.createElement("a");o.href=t,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(t)}catch(I){alert(`Error downloading input for ${A}: ${I instanceof Error?I.message:String(I)}`)}},uDo=({expanded:g})=>q.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:q.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})}),ixI=g=>{let A=g;for(;A.activeSubSolver;)A=A.activeSubSolver;return A},ExI=({solver:g,onStepUntilPhase:A,onDownloadInput:I,isNested:e=!1,indentLevel:t=0,triggerRender:o})=>{const[B,C]=X.useState(new Set),Q=g.pipelineDef.map((h,l)=>hDo(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):wDo(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)););o?.()}},a=()=>{if(!g.solved&&!g.failed){const h=ixI(g);for(;!g.solved&&!g.failed&&(g.step(),ixI(g)===h););o?.()}},c=t*24;return q.jsxs("div",{className:e?"":"border-t border-gray-200",children:[!e&&q.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[q.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),q.jsxs("div",{className:"flex gap-2",children:[q.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"}),q.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"})]})]}),q.jsx("div",{className:"overflow-x-auto",children:q.jsxs("table",{className:"w-full text-sm",children:[!e&&q.jsx("thead",{children:q.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),q.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",q.jsx("sub",{children:"0"})]}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),q.jsx("tbody",{children:Q.map(h=>{const l=rDo(h.solverInstance),D=B.has(h.name);return q.jsxs(sC.Fragment,{children:[q.jsxs("tr",{className:`border-b border-gray-100 ${h.status==="In Progress"?"bg-yellow-50":""}`,children:[q.jsx("td",{className:"px-4 py-2",children:q.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:c},children:[l?q.jsx("button",{onClick:()=>i(h.name),className:"text-gray-500 hover:text-gray-700",title:D?"Collapse":"Expand",children:q.jsx(uDo,{expanded:D})}):q.jsx("span",{className:"w-4"}),q.jsx("span",{className:"text-gray-400 w-6",children:String(h.index+1).padStart(2,"0")}),q.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:q.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:q.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),q.jsx("span",{className:"font-medium text-gray-900",children:h.name})]})}),q.jsx("td",{className:"px-4 py-2",children:q.jsx(lDo,{status:h.status})}),q.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:h.firstIteration!==null?h.firstIteration:""}),q.jsx("td",{className:"px-4 py-2 text-gray-600",children:h.iterations}),q.jsx("td",{className:"px-4 py-2",children:q.jsx(DDo,{progress:h.progress})}),q.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(h.timeSpent)}),q.jsx("td",{className:"px-4 py-2 text-gray-500",children:q.jsx(yDo,{stats:h.stats})}),q.jsx("td",{className:"px-4 py-2",children:h.solverInstance?q.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:[q.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:q.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),q.jsx("span",{children:"Input"})]}):null})]}),l&&D&&q.jsx("tr",{children:q.jsx("td",{colSpan:8,className:"p-0",children:q.jsx(ExI,{solver:h.solverInstance,onStepUntilPhase:A,onDownloadInput:I,isNested:!0,indentLevel:t+1,triggerRender:o})})})]},h.name)})})]})})]})};function GDo({graphics:g}){const A=g.points??[],I=g.lines??[],e=g.rects??[],t=g.circles??[],o=g.texts??[];let B=Number.POSITIVE_INFINITY,C=Number.POSITIVE_INFINITY,Q=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;const E=(h,l)=>{typeof h=="number"&&(h<B&&(B=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 o)E(h.x,h.y);(!isFinite(B)||!isFinite(C)||!isFinite(Q)||!isFinite(i))&&(B=-20,C=-20,Q=20,i=20);const n=10,s=B-n,r=C-n,a=Math.max(1,Q-B+2*n),c=Math.max(1,i-C+2*n);return q.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)=>q.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)=>q.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)=>q.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)=>q.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${l}`)),o.map((h,l)=>q.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${l}`))]})}var mDo=class extends sC.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}},pDo=({solver:g,createSolver:A,animationSpeed:I=25,onSolverStarted:e,onSolverCompleted:t})=>{const[o,B]=X.useReducer(D=>D+1,0),[C]=X.useState(()=>{if(A)return A();if(!g)throw new Error("GenericSolverDebugger requires solver or createSolver");return g}),[Q,i]=X.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[E,n]=X.useState(I),s=X.useMemo(()=>{try{return C.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(D){return console.error("Visualization error:",D),{points:[],lines:[],rects:[],circles:[]}}},[C,o]),r=X.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);X.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)}},[]),X.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();B()}},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 q.jsxs("div",{children:[q.jsx(aDo,{solver:C,triggerRender:B,animationSpeed:E,renderer:Q,onRendererChange:l,onAnimationSpeedChange:n,onDownloadVisualization:h,onSolverStarted:e,onSolverCompleted:t}),r?q.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):q.jsx(mDo,{fallback:q.jsx(GDo,{graphics:s}),children:Q==="canvas"?q.jsx(EDo,{graphics:s}):q.jsx(CDo,{graphics:s})}),a&&q.jsx(ExI,{solver:C,onStepUntilPhase:c,triggerRender:B})]})};const kDo=()=>{X.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)},[])},MDo=1e3,mk=(g,A)=>{const{fileName:I,mimeType:e="text/plain"}=A,t=g instanceof Blob?g:new Blob([g],{type:e}),o=URL.createObjectURL(t),B=document.createElement("a");B.href=o,B.download=I,B.target="_blank",B.rel="noopener noreferrer",B.style.display="none",document.body.appendChild(B),B.click(),document.body.removeChild(B),setTimeout(()=>{URL.revokeObjectURL(o)},MDo)},Otg=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"},SDo=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]},qx="https://github.com/tscircuit/tscircuit-autorouter/issues/new",nxI="https://github.com/tscircuit/copper-pour-solver/issues/new",sxI="https://github.com/tscircuit/calculate-packing/issues/new",fDo="https://github.com/tscircuit/matchpack/issues/new",axI="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",RDo={PackSolver2:sxI,LayoutPipelineSolver:fDo,AutoroutingPipelineSolver:qx,AssignableAutoroutingPipeline2:qx,AssignableAutoroutingPipeline3:qx,AutoroutingPipeline1_OriginalUnravel:qx,AutoroutingPipelineSolver3_HgPortPointPathing:qx,AutoroutingPipelineSolver4:qx,AutoroutingPipelineSolver5:qx,AutoroutingPipelineSolver7_MultiGraph:qx,AutoroutingPipelineSolver8:qx,CopperPourPipelineSolver:nxI,SchematicTracePipelineSolver:axI},NDo=g=>g.toLowerCase().includes("pack")?$2I:g.toLowerCase().includes("rout")?gfI:fCo,rxI=g=>{const A=RDo[g];if(A)return A;const I=g.toLowerCase();return I.includes("autorout")?qx:I.includes("schematic")&&I.includes("trace")?axI:I.includes("copperpour")?nxI:I.includes("pack")?sxI:null},xDo=g=>`${Otg(`${g.componentName}-${g.solverName}`)}-solver-input.json`,cxI=g=>{mk(JSON.stringify(g.solverParams,null,2),{fileName:xDo(g),mimeType:"application/json"})},FDo=({solverEvent:g})=>{const A=rxI(g.solverName);return q.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[q.jsxs(Ei,{type:"button",variant:"outline",size:"sm",onClick:()=>cxI(g),children:[q.jsx(neA,{className:"rf-w-4 rf-h-4"}),"Download"]}),A?q.jsx(Ei,{asChild:!0,variant:"outline",size:"sm",children:q.jsxs("a",{href:A,target:"_blank",rel:"noopener noreferrer",children:[q.jsx(qwA,{className:"rf-w-4 rf-h-4"}),"Report"]})}):q.jsxs(Ei,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[q.jsx(qwA,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},UDo=({solverEvent:g})=>{const A=rxI(g.solverName);return A?q.jsx(Ei,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:q.jsx("a",{href:A,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:q.jsx(qwA,{className:"rf-w-4 rf-h-4"})})}):q.jsx(Ei,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:q.jsx(qwA,{className:"rf-w-4 rf-h-4"})})},JDo=({solverEvents:g=[]})=>{const[A,I]=X.useState(null);kDo();const e=X.useMemo(()=>{const C=new Map;for(const Q of g){const i=`${Q.componentName}-${Q.solverName}`;C.set(i,Q)}return C},[g]),t=X.useMemo(()=>Array.from(e.keys()),[e]),o=A?e.get(A):null,B=X.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const C=H5A[o.solverName];if(!C)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(H5A).join(", ")}`,classFound:!1};try{return{instance:new C(...SDo(o)),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}}},[o]);return g.length===0?q.jsx("div",{className:"rf-p-4",children:q.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:q.jsxs("div",{className:"rf-p-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),q.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):q.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[q.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[q.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[t.length," ",t.length===1?"Solver":"Solvers"]}),t.map(C=>{const Q=e.get(C),i=A===C;return q.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=NDo(Q.solverName);return q.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[q.jsx(E,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),q.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[q.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:Q.componentName}),q.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:Q.solverName})]})]})})()},C)})]}),q.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?B.instance?q.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[q.jsx(FDo,{solverEvent:o}),q.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:q.jsx(oS,{fallback:q.jsx("div",{className:"rf-p-4",children:q.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),q.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:q.jsx(pDo,{solver:B.instance})})})]}):q.jsxs("div",{className:"rf-p-4",children:[q.jsxs("div",{className:"rf-mb-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),q.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),B.error&&q.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${B.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:q.jsx("p",{className:`rf-text-sm ${B.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:B.error})}),q.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[q.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[q.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),q.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[q.jsx(UDo,{solverEvent:o}),q.jsx(Ei,{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:()=>cxI(o),children:q.jsx(neA,{className:"rf-w-4 rf-h-4"})})]})]}),q.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:q.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):q.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:q.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},PDo=["subcircuit_id","componentDisplayName","phaseName","routingPhaseIndex","phaseOrdinal","phaseCount","phaseStageIndex","phaseStageCount","connectionCount","obstacleCount","previousTraceCount","isReroutePhase","autorouterName","autorouterVersion","solverName","effort","cacheStatus"],KDo=["phaseOrdinal","routingPhaseIndex","phaseName","phaseStageIndex"];function LDo(g,A){let I=-1,e=-1;for(let t=g.length-1;t>=0;t--){const o=g[t];if(o.status!=="running"||o.subcircuit_id!==A.subcircuit_id||o.componentDisplayName!==A.componentDisplayName)continue;let B=0,C=!1;for(const Q of KDo)if(!(o[Q]===void 0||A[Q]===void 0)){if(o[Q]!==A[Q]){C=!0;break}B++}!C&&B>e&&(I=t,e=B)}return I}function YDo(g,A){const I=Object.fromEntries(PDo.filter(B=>A[B]!==void 0).map(B=>[B,A[B]])),e=A.simpleRouteJson?structuredClone(A.simpleRouteJson):void 0,t=A.type==="autorouting:start"?-1:LDo(g,A),o={...t===-1?{id:`autorouting_phase_${g.length+1}`}:g[t],...I,status:A.type==="autorouting:start"?"running":A.type==="autorouting:end"?"complete":"error",...A.type==="autorouting:start"?{startSimpleRouteJson:e}:A.type==="autorouting:end"?{endSimpleRouteJson:e}:{errorSimpleRouteJson:e,error:A.error?{...A.error}:void 0}};return t===-1?[...g,o]:g.map((B,C)=>C===t?o:B)}const _Do=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),bDo=new Set(["tscircuit","default","auto","auto_local"]);function HDo(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 vDo(g){const A=g.autorouterName?.trim(),I=A?.replace(/-/g,"_"),e=I&&_Do.get(I);if(e)return e;if(I&&!bDo.has(I))return A;const t=g.solverName?.trim();if(t)return HDo(t);const o=g.autorouterVersion?.trim();if(o){const B=o.match(/^beta[_-]pipeline(\d+)$/);return B?`Pipeline${B[1]}`:o==="latest"?"default":o}return A?"default":"Unknown"}const Wtg="#fbbf24";function qDo(g){const A=g.endSimpleRouteJson?.traces??[],I=new Set(A.flatMap(t=>[t.pcb_trace_id,t.__replaces_pcb_trace_id].filter(o=>o!==void 0)));return[...(g.startSimpleRouteJson?.traces??[]).filter(t=>!I.has(t.pcb_trace_id)),...A]}function hxI(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 TDo(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 lxI(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,...TDo(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),o=[];let B=0;for(const[C,Q]of t)C>=B&&o.push(I.slice(B,C+1)),B=Math.max(B,Q);return B<I.length&&o.push(I.slice(B)),o}function ZDo(g){const A=[],I=[],e=g.endSimpleRouteJson;if(!e)return{lines:A,circles:I};const t=new Set(hxI(g));for(const o of e.traces??[])if(t.has(o.pcb_trace_id))for(const B of lxI(o,e)){let C;for(const Q of B){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:Wtg,layer:i}),Q.route_type==="via"&&I.push({center:{x:Q.x,y:Q.y},radius:Q.outer_diameter/2,stroke:Wtg,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 ODo(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 WDo=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function VDo(g,A,I){const e=I==="input"?A.startSimpleRouteJson??A.errorSimpleRouteJson:A.endSimpleRouteJson,t=g.filter(i=>!WDo.has(i.type)&&!i.type.endsWith("_error")&&!i.type.endsWith("_warning"));if(!e)return t;const o=I==="input"?e.traces??[]:qDo(A),B=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 o){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=lxI(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}_${ODo(a)}`,subcircuit_id:A.subcircuit_id??void 0,source_trace_id:B.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 Vtg=(g,A)=>g.phaseName||`Phase ${g.phaseOrdinal??A+1}`,DxI=g=>g.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||g.componentDisplayName||g.subcircuit_id||"Board",dxI=g=>g.startSimpleRouteJson??g.endSimpleRouteJson??g.errorSimpleRouteJson,jDo={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},zDo=({circuitJson:g,phases:A=[],isRunning:I=!1})=>{const[e,t]=X.useState(null),[o,B]=X.useState("output"),[C,Q]=X.useState(!0),[i,E]=X.useState(!1),n=X.useRef(null),[s,r]=X.useState(480),a=e?A.findIndex(N=>N.id===e.id&&dxI(N)===dxI(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=o==="output"&&!D?"input":o==="input"&&!y?"output":o,u=w==="input"?d:h?.endSimpleRouteJson,G=X.useMemo(()=>!h||!u?null:VDo(g??[],h,w),[g,h,u,w]),m=X.useMemo(()=>h&&w==="output"&&C?ZDo(h):{lines:[],circles:[]},[h,w,C]);if(X.useLayoutEffect(()=>{const N=n.current;if(!N)return;const J=()=>r(Math.max(360,N.clientHeight));J();const K=new ResizeObserver(J);return K.observe(N),()=>K.disconnect()},[!!h]),!h)return q.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:[q.jsx(gfI,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),q.jsx("h3",{className:"rf-text-base rf-font-medium",children:I?"Waiting for autorouting":"No autorouting captures"}),q.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=Vtg(h,c),k=h.status==="running"&&I,S=!D,R=d?.connections.length,x=G?.filter(N=>N.type==="pcb_trace").length??0;return q.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:[q.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:[q.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:[q.jsx("span",{children:"Routing phases"}),q.jsx("span",{children:A.length})]}),q.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 K=hxI(N).length,_=N.endSimpleRouteJson?`${K} ${K===1?"trace":"traces"} routed`:N.status==="error"?"Failed":N.status==="running"&&I?"Routing…":"No output";return q.jsxs("button",{type:"button","aria-pressed":J===c,title:`${DxI(N)} · ${_}`,onClick:()=>t(N),className:to("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:[q.jsx("span",{className:to("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}),q.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[q.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[q.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:Vtg(N,J),children:Vtg(N,J)}),N.status==="complete"?q.jsx(yJ,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):N.status==="error"?q.jsx(aeg,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):I?q.jsx(BS,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),q.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[vDo(N)," · ",_]})]})]},N.id)})})]}),q.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[q.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:[q.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[p,q.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[c+1," of ",A.length]})]}),I&&q.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"}),q.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(N=>q.jsx("button",{type:"button","aria-pressed":w===N,disabled:N==="input"?!y:!D,onClick:()=>B(N),className:to("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))})]}),q.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:[q.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[q.jsx("input",{type:"checkbox",checked:C,disabled:w!=="output",onChange:N=>Q(N.target.checked),className:"rf-accent-blue-600"}),q.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:Wtg}}),"Highlight changes (all layers)"]}),q.jsxs("span",{children:[w==="input"?"Before this phase":"After this phase"," ","· ",x," traces"]})]}),S&&q.jsx("div",{className:to("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."}),q.jsx("div",{ref:n,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:G?q.jsx(Eeg,{circuitJson:G,height:s,allowEditing:!1,clickToInteractEnabled:!1,initialState:jDo,debugGraphics:m}):q.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),q.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:[q.jsxs("span",{children:[R===void 0?"Input unavailable":`${R} input connections`,` · ${DxI(h)}`]}),q.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[q.jsxs("button",{type:"button",disabled:!u,onClick:()=>mk(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:[q.jsx(neA,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),q.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>E(!i),className:"rf-flex rf-items-center rf-gap-1",children:[q.jsx(K5,{className:to("rf-h-3 rf-w-3",i&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),i&&q.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."})]})]})},yxI=({errorMessage:g,errorStack:A,circuitJsonErrors:I})=>{X.useEffect(()=>{if(ZU("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&g){const e=new Error(g);A&&(e.stack=A);try{Pq.captureException(e)}catch{}}},[g,A]),X.useEffect(()=>{if(ZU("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{Pq.captureException(t,{error_type:e.type})}catch{}}},[I])},wxI=g=>{X.useEffect(()=>{try{Aht(g)}catch{}},[g.source,g.component,g.isWebEmbedded,g.activeTab])},uxI="0.0.2985",XDo={version:uxI},sGA=YVg()(_Vg(g=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{g({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),$Do=g=>{const[A,I]=X.useState([]),[e,t]=X.useState(null),[o,B]=X.useState(""),[C,Q]=oq("eval-version-selection",null),i=sGA(r=>r.setLastRunEvalVersion),E=sGA(r=>r.lastRunEvalVersion);return X.useEffect(()=>{g&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(r=>r.json()).then(r=>{if(Array.isArray(r?.versions)){let a=[...r.versions];r.tags?.latest&&(t(r.tags.latest),a=a.filter(c=>c!==r.tags.latest)),I(a)}}).catch(()=>{})},[g]),X.useEffect(()=>{g&&(C?(window.TSCIRCUIT_LATEST_EVAL_VERSION=C,i(C)):e&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=e,i(e)))},[g,C,e]),{versions:X.useMemo(()=>A.filter(r=>r.includes(o)).slice(0,50),[A,o]),latestVersion:e,lastRunEvalVersion:E,search:o,setSearch:B,selectVersion:r=>{Q(r),B("")}}},Ado=({snippetNames:g,onSelect:A,onCancel:I,isOpen:e})=>{const[t,o]=X.useState(""),[B,C]=X.useState("");if(!e)return null;const Q=g.filter(n=>n.toLowerCase().includes(B.toLowerCase())),i=B&&!g.includes(B),E=n=>{n.key==="Enter"&&(Q.length===1?o(Q[0]):i&&o(B))};return q.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:q.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[q.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),q.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:B,onChange:n=>C(n.target.value),onKeyDown:E}),q.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[Q.map(n=>q.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${t===n?"bg-blue-50":""}`,onClick:()=>o(n),children:n},n)),i&&q.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${t===B?"bg-blue-50":""}`,onClick:()=>o(B),children:['Create new "',B,'"']})]}),q.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[q.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:I,children:"Cancel"}),q.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>t&&A(t),disabled:!t,children:t===B?`Create "${t}"`:`Save to ${t}`})]})]})})},gdo=g=>{const A=X.useRef(null),I=Fc(e=>e.recentEvents);X.useEffect(()=>{if(I.length===0)return;const e=I[0];e.event_id!==A.current&&(g(e),A.current=e.event_id)},[I,g])};var Ido=Object.defineProperty,fJ=(g,A)=>Ido(g,"name",{value:A,configurable:!0}),edo="AlertDialog",[tdo,CAB]=$p(edo,[SRI]),RJ=SRI(),odo=fJ(g=>{const{__scopeAlertDialog:A,...I}=g,e=RJ(A);return q.jsx(SuA,{...e,...I,modal:!0})},"AlertDialog");X.forwardRef(fJ(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=RJ(e);return q.jsx(Ano,{...o,...t,ref:I})},"AlertDialogTrigger"));var Bdo=fJ(g=>{const{__scopeAlertDialog:A,...I}=g,e=RJ(A);return q.jsx(fuA,{...e,...I})},"AlertDialogPortal"),GxI=X.forwardRef(fJ(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=RJ(e);return q.jsx(meA,{...o,...t,ref:I})},"AlertDialogOverlay")),Cdo="AlertDialogContent",[Qdo,ido]=tdo(Cdo),mxI=X.forwardRef(fJ(function(A,I){const{__scopeAlertDialog:e,children:t,...o}=A,B=RJ(e),C=X.useRef(null),Q=wi(I,C),i=X.useRef(null);return q.jsx(Qdo,{scope:e,cancelRef:i,children:q.jsx(keA,{role:"alertdialog",...B,...o,ref:Q,onOpenAutoFocus:Mo(o.onOpenAutoFocus,E=>{E.preventDefault(),i.current?.focus({preventScroll:!0})}),onPointerDownOutside:E=>E.preventDefault(),onInteractOutside:E=>E.preventDefault(),children:t})})},"AlertDialogContent")),pxI=X.forwardRef(fJ(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=RJ(e);return q.jsx(RuA,{...o,...t,ref:I})},"AlertDialogTitle")),kxI=X.forwardRef(fJ(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=RJ(e);return q.jsx(NuA,{...o,...t,ref:I})},"AlertDialogDescription")),MxI=X.forwardRef(fJ(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=RJ(e);return q.jsx(gtg,{...o,...t,ref:I})},"AlertDialogAction")),Edo="AlertDialogCancel",SxI=X.forwardRef(fJ(function(A,I){const{__scopeAlertDialog:e,...t}=A,{cancelRef:o}=ido(Edo,e),B=RJ(e),C=wi(I,o);return q.jsx(gtg,{...B,...t,ref:C})},"AlertDialogCancel"));const fxI=odo,ndo=Bdo,RxI=X.forwardRef(({className:g,...A},I)=>q.jsx(GxI,{className:to("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",g),...A,ref:I}));RxI.displayName=GxI.displayName;const jtg=X.forwardRef(({className:g,...A},I)=>q.jsxs(ndo,{children:[q.jsx(RxI,{}),q.jsx(mxI,{ref:I,className:to("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",g),...A})]}));jtg.displayName=mxI.displayName;const ztg=({className:g,...A})=>q.jsx("div",{className:to("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",g),...A});ztg.displayName="AlertDialogHeader";const Xtg=({className:g,...A})=>q.jsx("div",{className:to("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",g),...A});Xtg.displayName="AlertDialogFooter";const $tg=X.forwardRef(({className:g,...A},I)=>q.jsx(pxI,{ref:I,className:to("rf-text-lg rf-font-semibold",g),...A}));$tg.displayName=pxI.displayName;const Aog=X.forwardRef(({className:g,...A},I)=>q.jsx(kxI,{ref:I,className:to("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",g),...A}));Aog.displayName=kxI.displayName;const sdo=X.forwardRef(({className:g,...A},I)=>q.jsx(MxI,{ref:I,className:to(oZ(),g),...A}));sdo.displayName=MxI.displayName;const gog=X.forwardRef(({className:g,...A},I)=>q.jsx(SxI,{ref:I,className:to(oZ({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",g),...A}));gog.displayName=SxI.displayName;var ado=Object.defineProperty,NJ=(g,A)=>ado(g,"name",{value:A,configurable:!0}),Iog="Checkbox",[rdo,QAB]=$p(Iog),[cdo,eog]=rdo(Iog);function NxI(g){const{__scopeCheckbox:A,checked:I,children:e,defaultChecked:t,disabled:o,form:B,name:C,onCheckedChange:Q,required:i,value:E="on",internal_do_not_use_render:n}=g,[s,r]=ER({prop:I,defaultProp:t??!1,onChange:Q,caller:Iog}),[a,c]=X.useState(null),[h,l]=X.useState(null),[D,d]=X.useState(null),y=a?!!B||!!a.closest("form"):!0,w={checked:s,disabled:o,setChecked:r,control:a,setControl:c,name:C,form:B,value:E,userClick:D,onUserClick:d,required:i,defaultChecked:$2(t)?!1:t,isFormControl:y,bubbleInput:h,setBubbleInput:l};return q.jsx(cdo,{scope:A,...w,children:FxI(n)?n(w):e})}NJ(NxI,"CheckboxProvider");var hdo="CheckboxTrigger",ldo=X.forwardRef(NJ(function({__scopeCheckbox:A,onKeyDown:I,onClick:e,...t},o){const{control:B,value:C,disabled:Q,checked:i,required:E,setControl:n,setChecked:s,onUserClick:r,isFormControl:a,bubbleInput:c}=eog(hdo,A),h=wi(o,n),l=X.useRef(i);return X.useEffect(()=>{const D=B?.form;if(D){const d=NJ(()=>s(l.current),"reset");return D.addEventListener("reset",d),()=>D.removeEventListener("reset",d)}},[B,s]),q.jsx(dQ.button,{type:"button",role:"checkbox","aria-checked":$2(i)?"mixed":i,"aria-required":E,"data-state":tog(i),"data-disabled":Q?"":void 0,disabled:Q,value:C,...t,ref:h,onKeyDown:Mo(I,D=>{D.key==="Enter"&&D.preventDefault()}),onClick:Mo(e,D=>{const d=D.isPropagationStopped();r({requestedChecked:$2(i)?!0:!i,hasConsumerStoppedPropagation:d}),s(y=>$2(y)?!0:!y),c&&a&&(d||D.stopPropagation())})})},"CheckboxTrigger")),xxI=X.forwardRef(NJ(function(A,I){const{__scopeCheckbox:e,name:t,checked:o,defaultChecked:B,required:C,disabled:Q,value:i,onCheckedChange:E,form:n,...s}=A;return q.jsx(NxI,{__scopeCheckbox:e,checked:o,defaultChecked:B,disabled:Q,required:C,onCheckedChange:E,name:t,form:n,value:i,internal_do_not_use_render:({isFormControl:r})=>q.jsxs(q.Fragment,{children:[q.jsx(ldo,{...s,ref:I,__scopeCheckbox:e}),r&&q.jsx(wdo,{__scopeCheckbox:e})]})})},"Checkbox")),Ddo="CheckboxIndicator",ddo=X.forwardRef(NJ(function(A,I){const{__scopeCheckbox:e,forceMount:t,...o}=A,B=eog(Ddo,e);return q.jsx(LM,{present:t||$2(B.checked)||B.checked===!0,children:q.jsx(dQ.span,{"data-state":tog(B.checked),"data-disabled":B.disabled?"":void 0,...o,ref:I,style:{pointerEvents:"none",...A.style}})})},"CheckboxIndicator")),ydo="CheckboxBubbleInput",wdo=X.forwardRef(NJ(function({__scopeCheckbox:A,onClick:I,...e},t){const{control:o,userClick:B,checked:C,defaultChecked:Q,required:i,disabled:E,name:n,value:s,form:r,bubbleInput:a,setBubbleInput:c}=eog(ydo,A),h=wi(t,c),l=Peg(o),D=X.useRef(!1),d=X.useRef(C),y=X.useRef(B),w=X.useRef(null);X.useEffect(()=>{const G=a;if(!G)return;const m=window.HTMLInputElement.prototype,k=Object.getOwnPropertyDescriptor(m,"checked").set;if(!k)return;const S=d.current!==C;d.current=C;const R=B!==null&&B!==y.current;if(y.current=B,R)w.current=S?null:B,S&&(G.indeterminate=$2(C),k.call(G,$2(C)?!1:C)),G.dispatchEvent(new Event("click",{bubbles:!B.hasConsumerStoppedPropagation}));else if(S){const x=w.current;w.current=null;const N=x?.requestedChecked===C;D.current=!0,G.indeterminate=$2(C),k.call(G,$2(C)?!1:C),G.dispatchEvent(new Event("click",{bubbles:!(N&&x.hasConsumerStoppedPropagation)})),D.current=!1}},[a,C,B]);const u=X.useRef($2(C)?!1:C);return q.jsx(dQ.input,{type:"checkbox","aria-hidden":!0,defaultChecked:Q??u.current,required:i,disabled:E,name:n,value:s,form:r,...e,tabIndex:-1,ref:h,onClick:Mo(I,G=>{D.current&&G.stopPropagation()}),style:{...e.style,...l,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})},"CheckboxBubbleInput"));function FxI(g){return typeof g=="function"}NJ(FxI,"isFunction");function $2(g){return g==="indeterminate"}NJ($2,"isIndeterminate");function tog(g){return $2(g)?"indeterminate":g?"checked":"unchecked"}NJ(tog,"getState");const WeA=X.forwardRef(({className:g,...A},I)=>q.jsx(xxI,{ref:I,className:to("rf-peer rf-h-4 rf-w-4 rf-shrink-0 rf-rounded-sm rf-border rf-border-zinc-200 rf-border-zinc-900 rf-shadow focus-visible:rf-outline-none focus-visible:rf-ring-1 focus-visible:rf-ring-zinc-950 disabled:rf-cursor-not-allowed disabled:rf-opacity-50 data-[state=checked]:rf-bg-zinc-900 data-[state=checked]:rf-text-zinc-50 dark:rf-border-zinc-800 dark:rf-border-zinc-50 dark:focus-visible:rf-ring-zinc-300 dark:data-[state=checked]:rf-bg-zinc-50 dark:data-[state=checked]:rf-text-zinc-900",g),...A,children:q.jsx(ddo,{className:to("rf-flex rf-items-center rf-justify-center rf-text-current"),children:q.jsx(yJ,{className:"rf-h-4 rf-w-4"})})}));WeA.displayName=xxI.displayName;const Z5=SuA,udo=fuA,UxI=X.forwardRef(({className:g,...A},I)=>q.jsx(meA,{className:to("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",g),...A,ref:I}));UxI.displayName=meA.displayName;const q3=X.forwardRef(({className:g,children:A,showOverlay:I=!0,...e},t)=>q.jsxs(udo,{children:[q.jsx(UxI,{className:to(I?"":"rf-hidden")}),q.jsx(keA,{ref:t,className:to("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",g),...e,children:A})]}));q3.displayName=keA.displayName;const T3=({className:g,...A})=>q.jsx("div",{className:to("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",g),...A});T3.displayName="DialogHeader";const FZ=({className:g,...A})=>q.jsx("div",{className:to("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",g),...A});FZ.displayName="DialogFooter";const Z3=X.forwardRef(({className:g,...A},I)=>q.jsx(RuA,{ref:I,className:to("rf-text-lg rf-font-semibold",g),...A}));Z3.displayName=RuA.displayName;const O5=X.forwardRef(({className:g,...A},I)=>q.jsx(NuA,{ref:I,className:to("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",g),...A}));O5.displayName=NuA.displayName;const aGA={"tscircuit.com":{label:"tscircuit.com",placeholder:"Search tscircuit packages...",emptyMessage:"No packages found"},jlcpcb:{label:"JLCPCB Parts",placeholder:"Search JLCPCB parts (e.g. C14663)...",emptyMessage:"No parts found"},kicad:{label:"KiCad Footprints",placeholder:"Search KiCad footprints...",emptyMessage:"No footprints found"}},Gdo="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let oog=null;const Bog=async()=>(oog||(oog=import(Gdo)),oog),mdo=g=>(A,I)=>{const e=new Headers(I?.headers),t={};return e.forEach((o,B)=>{t[B]=o}),fetch(`${g?.apiBase??Dm}/proxy`,{...I,headers:{...t,"X-Target-Url":A.toString(),"X-Sender-Origin":t.origin??"","X-Sender-Host":t.host??"https://easyeda.com","X-Sender-Referer":t.referer??"","X-Sender-User-Agent":t["user-agent"]??"","X-Sender-Cookie":t.cookie??"",authority:t.authority??"","content-type":t["content-type"]??"",...g?.headers}})},pdo=async(g,A=10)=>{const I=encodeURIComponent(g),e=await fetch(`https://jlcsearch.tscircuit.com/api/search?limit=${A}&q=${I}`);if(!e.ok)throw new Error(`JLCPCB API error: ${e.status}`);return(await e.json()).components??[]},kdo=g=>({lcscId:g.lcsc,manufacturer:g.mfr,description:g.description,partNumber:`C${g.lcsc}`,package:g.package,price:g.price,stock:g.stock,isBasic:g.is_basic}),JxI=async(g,A)=>{const{fetchEasyEDAComponent:I}=await Bog();return I(g,{fetch:mdo(A),includeModelMetadata:A?.includeModelMetadata})},Mdo=async(g,A)=>{const{convertRawEasyToTsx:I}=await Bog(),e=await JxI(g,A);return I({rawEasy:e})},Sdo=async(g,A)=>{const{EasyEdaJsonSchema:I,convertEasyEdaJsonToCircuitJson:e}=await Bog(),t=await JxI(g,{...A,includeModelMetadata:!1}),o=I.parse(t);return e(o,{shouldRecenter:!0,showDesignator:!0,useModelCdn:!1})};function O3(g){return Array.isArray?Array.isArray(g):KxI(g)==="[object Array]"}function fdo(g){if(typeof g=="string")return g;if(typeof g=="bigint")return g.toString();const A=g+"";return A=="0"&&1/g==-1/0?"-0":A}function Cog(g){return g==null?"":fdo(g)}function BG(g){return typeof g=="string"}function rGA(g){return typeof g=="number"}function Rdo(g){return g===!0||g===!1||Ndo(g)&&KxI(g)=="[object Boolean]"}function PxI(g){return typeof g=="object"}function Ndo(g){return PxI(g)&&g!==null}function aS(g){return g!=null}function cGA(g){return!g.trim().length}function KxI(g){return g==null?g===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(g)}const xdo="Incorrect 'index' type",Qog="Invalid doc index: must be a non-negative integer within the bounds of the docs array",Fdo=g=>`Invalid value for key ${g}`,Udo=g=>`Pattern length exceeds max of ${g}.`,Jdo=g=>`Missing ${g} property in key`,Pdo=g=>`Property 'weight' in key '${g}' must be a positive integer`,Kdo="Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.",LxI=Object.prototype.hasOwnProperty;var Ldo=class{constructor(g){this._keys=[],this._keyMap={};let A=0;g.forEach(I=>{const e=YxI(I);this._keys.push(e),this._keyMap[e.id]=e,A+=e.weight}),this._keys.forEach(I=>{I.weight/=A})}get(g){return this._keyMap[g]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function YxI(g){let A=null,I=null,e=null,t=1,o=null;if(BG(g)||O3(g))e=g,A=_xI(g),I=hGA(g);else{if(!LxI.call(g,"name"))throw new Error(Jdo("name"));const B=g.name;if(e=B,LxI.call(g,"weight")&&g.weight!==void 0&&(t=g.weight,t<=0))throw new Error(Pdo(hGA(B)));A=_xI(B),I=hGA(B),o=g.getFn??null}return{path:A,id:I,weight:t,src:e,getFn:o}}function _xI(g){return O3(g)?g:g.split(".")}function hGA(g){return O3(g)?g.join("."):g}function Ydo(g,A){const I=[];let e=!1;const t=(o,B,C,Q)=>{if(aS(o))if(!B[C])I.push(Q!==void 0?{v:o,i:Q}:o);else{const i=o[B[C]];if(!aS(i))return;if(C===B.length-1&&(BG(i)||rGA(i)||Rdo(i)||typeof i=="bigint"))I.push(Q!==void 0?{v:Cog(i),i:Q}:Cog(i));else if(O3(i)){e=!0;for(let E=0,n=i.length;E<n;E+=1)t(i[E],B,C+1,E)}else B.length&&t(i,B,C+1,Q)}};return t(g,BG(A)?A.split("."):A,0),e?I:I[0]}const rQ=Object.freeze({...{isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(g,A)=>g.score===A.score?g.idx<A.idx?-1:1:g.score<A.score?-1:1},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,useTokenSearch:!1,tokenize:void 0,tokenMatch:"any",getFn:Ydo,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}});function _do(g){return g>=9&&g<=13||g===32||g===160}function bdo(g=1,A=3){const I=new Map,e=Math.pow(10,A);return{get(t){let o=0,B=!1;for(let Q=0;Q<t.length;Q++)_do(t.charCodeAt(Q))?B=!1:B||(o++,B=!0);if(o===0&&(o=1),I.has(o))return I.get(o);const C=Math.round(e/Math.pow(o,.5*g))/e;return I.set(o,C),C},clear(){I.clear()}}}var iog=class{constructor({getFn:g=rQ.getFn,fieldNormWeight:A=rQ.fieldNormWeight}={}){this.norm=bdo(A,3),this.getFn=g,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(g=[]){this.docs=g}setIndexRecords(g=[]){this.records=g}setKeys(g=[]){this.keys=g,this._keysMap={},g.forEach((A,I)=>{this._keysMap[A.id]=I})}create(){if(this.isCreated||!this.docs.length)return;this.isCreated=!0;const g=this.docs.length;this.records=new Array(g);let A=0;if(BG(this.docs[0]))for(let I=0;I<g;I++){const e=this._createStringRecord(this.docs[I],I);e&&(this.records[A++]=e)}else for(let I=0;I<g;I++)this.records[A++]=this._createObjectRecord(this.docs[I],I);this.records.length=A,this.norm.clear()}add(g,A){if(!Number.isInteger(A)||A<0)throw new Error(Qog);if(BG(g)){const e=this._createStringRecord(g,A);return e&&this.records.push(e),e}const I=this._createObjectRecord(g,A);return this.records.push(I),I}removeAt(g){if(!Number.isInteger(g)||g<0)throw new Error(Qog);for(let A=0,I=this.records.length;A<I;A+=1)if(this.records[A].i===g){this.records.splice(A,1);break}for(let A=0,I=this.records.length;A<I;A+=1)this.records[A].i>g&&(this.records[A].i-=1)}removeAll(g){const A=new Set;for(const e of g)Number.isInteger(e)&&e>=0&&A.add(e);if(A.size===0)return;this.records=this.records.filter(e=>!A.has(e.i));const I=Array.from(A).sort((e,t)=>e-t);for(const e of this.records){let t=0,o=I.length;for(;t<o;){const B=t+o>>>1;I[B]<e.i?t=B+1:o=B}e.i-=t}}getValueForItemAtKeyId(g,A){return g[this._keysMap[A]]}size(){return this.records.length}_createStringRecord(g,A){return!aS(g)||cGA(g)?null:{v:g,i:A,n:this.norm.get(g)}}_createObjectRecord(g,A){const I={i:A,$:{}};for(let e=0,t=this.keys.length;e<t;e++){const o=this.keys[e],B=o.getFn?o.getFn(g):this.getFn(g,o.path);if(aS(B)){if(O3(B)){const C=[];for(let Q=0,i=B.length;Q<i;Q+=1){const E=B[Q];if(aS(E)){if(BG(E)){if(!cGA(E)){const n={v:E,i:Q,n:this.norm.get(E)};C.push(n)}}else if(aS(E.v)){const n=BG(E.v)?E.v:Cog(E.v);if(!cGA(n)){const s={v:n,i:E.i,n:this.norm.get(n)};C.push(s)}}}}I.$[e]=C}else if(BG(B)&&!cGA(B)){const C={v:B,n:this.norm.get(B)};I.$[e]=C}}}return I}toJSON(){return{keys:this.keys.map(({getFn:g,...A})=>A),records:this.records}}};function bxI(g,A,{getFn:I=rQ.getFn,fieldNormWeight:e=rQ.fieldNormWeight}={}){const t=new iog({getFn:I,fieldNormWeight:e});return t.setKeys(g.map(YxI)),t.setSources(A),t.create(),t}function Hdo(g,{getFn:A=rQ.getFn,fieldNormWeight:I=rQ.fieldNormWeight}={}){const{keys:e,records:t}=g,o=new iog({getFn:A,fieldNormWeight:I});return o.setKeys(e),o.setIndexRecords(t),o}function vdo(g=[],A=rQ.minMatchCharLength){const I=[];let e=-1,t=-1,o=0;for(let B=g.length;o<B;o+=1){const C=g[o];C&&e===-1?e=o:!C&&e!==-1&&(t=o-1,t-e+1>=A&&I.push([e,t]),e=-1)}return g[o-1]&&o-e>=A&&I.push([e,o-1]),I}function qdo(g,A,I,{location:e=rQ.location,distance:t=rQ.distance,threshold:o=rQ.threshold,findAllMatches:B=rQ.findAllMatches,minMatchCharLength:C=rQ.minMatchCharLength,includeMatches:Q=rQ.includeMatches,ignoreLocation:i=rQ.ignoreLocation}={}){if(A.length>32)throw new Error(Udo(32));const E=A.length,n=g.length,s=Math.max(0,Math.min(e,n));let r=o,a=s;const c=(p,k)=>{const S=p/E;if(i)return S;const R=Math.abs(s-k);return t?S+R/t:R?1:S},h=C>1||Q,l=h?Array(n):[];let D;for(;(D=g.indexOf(A,a))>-1;){const p=c(0,D);if(r=Math.min(p,r),a=D+E,h){let k=0;for(;k<E;)l[D+k]=1,k+=1}}a=-1;let d=[],y=1,w=0,u=E+n;const G=1<<E-1;for(let p=0;p<E;p+=1){let k=0,S=u;for(;k<S;)c(p,s+S)<=r?k=S:u=S,S=Math.floor((u-k)/2+k);u=S;let R=Math.max(1,s-S+1);const x=B?n:Math.min(s+S,n)+E,N=Array(x+2);N[x+1]=(1<<p)-1;for(let J=x;J>=R;J-=1){const K=J-1,_=I[g[K]];if(N[J]=(N[J+1]<<1|1)&_,p&&(N[J]|=(d[J+1]|d[J])<<1|1|d[J+1]),N[J]&G&&(y=c(p,K),y<=r)){if(r=y,a=K,w=p,a<=s)break;R=Math.max(1,2*s-a)}}if(c(p+1,s)>r)break;d=N}if(h&&a>=0){const p=Math.min(n-1,a+E-1+w);for(let k=a;k<=p;k+=1)I[g[k]]&&(l[k]=1)}const m={isMatch:a>=0,score:Math.max(.001,y)};if(h){const p=vdo(l,C);p.length?Q&&(m.indices=p):m.isMatch=!1}return m}function Tdo(g){const A={};for(let I=0,e=g.length;I<e;I+=1){const t=g.charAt(I);A[t]=(A[t]||0)|1<<e-I-1}return A}function Eog(g){if(g.length<=1)return g;g.sort((I,e)=>I[0]-e[0]||I[1]-e[1]);const A=[g[0]];for(let I=1,e=g.length;I<e;I+=1){const t=A[A.length-1],o=g[I];o[0]<=t[1]+1?t[1]=Math.max(t[1],o[1]):A.push(o)}return A}const HxI={ł:"l",Ł:"L",đ:"d",Đ:"D",ø:"o",Ø:"O",ħ:"h",Ħ:"H",ŧ:"t",Ŧ:"T",ı:"i",ß:"ss"},Zdo=new RegExp("["+Object.keys(HxI).join("")+"]","g"),VeA=typeof String.prototype.normalize=="function"?g=>g.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"").replace(Zdo,A=>HxI[A]):g=>g;var nog=class{constructor(g,{location:A=rQ.location,threshold:I=rQ.threshold,distance:e=rQ.distance,includeMatches:t=rQ.includeMatches,findAllMatches:o=rQ.findAllMatches,minMatchCharLength:B=rQ.minMatchCharLength,isCaseSensitive:C=rQ.isCaseSensitive,ignoreDiacritics:Q=rQ.ignoreDiacritics,ignoreLocation:i=rQ.ignoreLocation}={}){if(this.options={location:A,threshold:I,distance:e,includeMatches:t,findAllMatches:o,minMatchCharLength:B,isCaseSensitive:C,ignoreDiacritics:Q,ignoreLocation:i},g=C?g:g.toLowerCase(),g=Q?VeA(g):g,this.pattern=g,this.chunks=[],!this.pattern.length)return;const E=(s,r)=>{this.chunks.push({pattern:s,alphabet:Tdo(s),startIndex:r})},n=this.pattern.length;if(n>32){let s=0;const r=n%32,a=n-r;for(;s<a;)E(this.pattern.substr(s,32),s),s+=32;if(r){const c=n-32;E(this.pattern.substr(c),c)}}else E(this.pattern,0)}searchIn(g){const{isCaseSensitive:A,ignoreDiacritics:I,includeMatches:e}=this.options;if(g=A?g:g.toLowerCase(),g=I?VeA(g):g,this.pattern===g){if(g.length<this.options.minMatchCharLength)return{isMatch:!1,score:1};const a={isMatch:!0,score:0};return e&&(a.indices=[[0,g.length-1]]),a}const{location:t,distance:o,threshold:B,findAllMatches:C,minMatchCharLength:Q,ignoreLocation:i}=this.options,E=[];let n=0,s=!1;this.chunks.forEach(({pattern:a,alphabet:c,startIndex:h})=>{const{isMatch:l,score:D,indices:d}=qdo(g,a,c,{location:t+h,distance:o,threshold:B,findAllMatches:C,minMatchCharLength:Q,includeMatches:e,ignoreLocation:i});l&&(s=!0),n+=D,l&&d&&E.push(...d)});const r={isMatch:s,score:s?n/this.chunks.length:1};return s&&e&&(r.indices=Eog(E)),r}};const Odo=new Set(["fuzzy","include"]);function Wdo(g){return g.startsWith("inverse")}const sog=[{type:"exact",multiRegex:/^="(.*)"$/,singleRegex:/^=(.*)$/,create:g=>({type:"exact",search(A){const I=A===g;return{isMatch:I,score:I?0:1,indices:[0,g.length-1]}}})},{type:"include",multiRegex:/^'"(.*)"$/,singleRegex:/^'(.*)$/,create:g=>({type:"include",search(A){let I=0,e;const t=[],o=g.length;for(;(e=A.indexOf(g,I))>-1;)I=e+o,t.push([e,I-1]);const B=!!t.length;return{isMatch:B,score:B?0:1,indices:t}}})},{type:"prefix-exact",multiRegex:/^\^"(.*)"$/,singleRegex:/^\^(.*)$/,create:g=>({type:"prefix-exact",search(A){const I=A.startsWith(g);return{isMatch:I,score:I?0:1,indices:[0,g.length-1]}}})},{type:"inverse-prefix-exact",multiRegex:/^!\^"(.*)"$/,singleRegex:/^!\^(.*)$/,create:g=>({type:"inverse-prefix-exact",search(A){const I=!A.startsWith(g);return{isMatch:I,score:I?0:1,indices:[0,A.length-1]}}})},{type:"inverse-suffix-exact",multiRegex:/^!"(.*)"\$$/,singleRegex:/^!(.*)\$$/,create:g=>({type:"inverse-suffix-exact",search(A){const I=!A.endsWith(g);return{isMatch:I,score:I?0:1,indices:[0,A.length-1]}}})},{type:"suffix-exact",multiRegex:/^"(.*)"\$$/,singleRegex:/^(.*)\$$/,create:g=>({type:"suffix-exact",search(A){const I=A.endsWith(g);return{isMatch:I,score:I?0:1,indices:[A.length-g.length,A.length-1]}}})},{type:"inverse-exact",multiRegex:/^!"(.*)"$/,singleRegex:/^!(.*)$/,create:g=>({type:"inverse-exact",search(A){const I=A.indexOf(g)===-1;return{isMatch:I,score:I?0:1,indices:[0,A.length-1]}}})},{type:"fuzzy",multiRegex:/^"(.*)"$/,singleRegex:/^(.*)$/,create:(g,A={})=>{const I=new nog(g,{location:A.location??rQ.location,threshold:A.threshold??rQ.threshold,distance:A.distance??rQ.distance,includeMatches:A.includeMatches??rQ.includeMatches,findAllMatches:A.findAllMatches??rQ.findAllMatches,minMatchCharLength:A.minMatchCharLength??rQ.minMatchCharLength,isCaseSensitive:A.isCaseSensitive??rQ.isCaseSensitive,ignoreDiacritics:A.ignoreDiacritics??rQ.ignoreDiacritics,ignoreLocation:A.ignoreLocation??rQ.ignoreLocation});return{type:"fuzzy",search(e){return I.searchIn(e)}}}}],vxI=sog.length,Vdo="\0",jdo="|";function zdo(g){const A=[],I=g.length;let e=0;for(;e<I;){for(;e<I&&g[e]===" ";)e++;if(e>=I)break;let t=e;for(;t<I&&g[t]!==" "&&g[t]!=='"';)t++;if(t<I&&g[t]==='"'){for(t++;t<I;){if(g[t]==='"'){const o=t+1;if(o>=I||g[o]===" "){t++;break}if(g[o]==="$"&&(o+1>=I||g[o+1]===" ")){t+=2;break}}t++}A.push(g.substring(e,t)),e=t}else{for(;t<I&&g[t]!==" ";)t++;A.push(g.substring(e,t)),e=t}}return A}function qxI(g,A){const I=g.match(A);return I?I[1]:null}function Xdo(g,A={}){return g.replace(/\\\|/g,Vdo).split(jdo).map(I=>{const e=zdo(I.replace(/\u0000/g,"|").trim()).filter(o=>o&&!!o.trim()),t=[];for(let o=0,B=e.length;o<B;o+=1){const C=e[o];let Q=!1,i=-1;for(;!Q&&++i<vxI;){const E=sog[i],n=qxI(C,E.multiRegex);n&&(t.push(E.create(n,A)),Q=!0)}if(!Q)for(i=-1;++i<vxI;){const E=sog[i],n=qxI(C,E.singleRegex);if(n){t.push(E.create(n,A));break}}}return t})}var $do=class{constructor(g,{isCaseSensitive:A=rQ.isCaseSensitive,ignoreDiacritics:I=rQ.ignoreDiacritics,includeMatches:e=rQ.includeMatches,minMatchCharLength:t=rQ.minMatchCharLength,ignoreLocation:o=rQ.ignoreLocation,findAllMatches:B=rQ.findAllMatches,location:C=rQ.location,threshold:Q=rQ.threshold,distance:i=rQ.distance}={}){this.query=null,this.options={isCaseSensitive:A,ignoreDiacritics:I,includeMatches:e,minMatchCharLength:t,findAllMatches:B,ignoreLocation:o,location:C,threshold:Q,distance:i},g=A?g:g.toLowerCase(),g=I?VeA(g):g,this.pattern=g,this.query=Xdo(this.pattern,this.options)}static condition(g,A){return A.useExtendedSearch}searchIn(g){const A=this.query;if(!A)return{isMatch:!1,score:1};const{includeMatches:I,isCaseSensitive:e,ignoreDiacritics:t}=this.options;g=e?g:g.toLowerCase(),g=t?VeA(g):g;let o=0;const B=[];let C=0,Q=!1;for(let i=0,E=A.length;i<E;i+=1){const n=A[i];B.length=0,o=0,Q=!1;for(let s=0,r=n.length;s<r;s+=1){const a=n[s],{isMatch:c,indices:h,score:l}=a.search(g);if(c)o+=1,C+=l,Wdo(a.type)&&(Q=!0),I&&(Odo.has(a.type)?B.push(...h):B.push(h));else{C=0,o=0,B.length=0,Q=!1;break}}if(o){const s={isMatch:!0,score:C/o};return Q&&(s.hasInverse=!0),I&&(s.indices=Eog(B)),s}}return{isMatch:!1,score:1}}};const aog=[];function rog(...g){aog.push(...g)}function lGA(g,A){for(let I=0,e=aog.length;I<e;I+=1){const t=aog[I];if(t.condition(g,A))return new t(g,A)}return new nog(g,A)}const DGA={AND:"$and",OR:"$or"},cog={PATH:"$path",PATTERN:"$val"},hog=g=>!!(g[DGA.AND]||g[DGA.OR]),Ayo=g=>!!g[cog.PATH],gyo=g=>!O3(g)&&PxI(g)&&!hog(g),TxI=g=>({[DGA.AND]:Object.keys(g).map(A=>({[A]:g[A]}))});function ZxI(g,A,{auto:I=!0}={}){const e=t=>{if(BG(t)){const Q={keyId:null,pattern:t};return I&&(Q.searcher=lGA(t,A)),Q}const o=Object.keys(t),B=Ayo(t);if(!B&&o.length>1&&!hog(t))return e(TxI(t));if(gyo(t)){const Q=B?t[cog.PATH]:o[0],i=B?t[cog.PATTERN]:t[Q];if(!BG(i))throw new Error(Fdo(Q));const E={keyId:hGA(Q),pattern:i};return I&&(E.searcher=lGA(i,A)),E}const C={children:[],operator:o[0]};return o.forEach(Q=>{const i=t[Q];O3(i)&&i.forEach(E=>{C.children.push(e(E))})}),C};return hog(g)||(g=TxI(g)),e(g)}function log(g,{ignoreFieldNorm:A=rQ.ignoreFieldNorm}){let I=1;return g.forEach(({key:e,norm:t,score:o})=>{const B=e?e.weight:null;I*=Math.pow(o===0&&B?Number.EPSILON:o,(B||1)*(A?1:t))}),I}function Iyo(g,{ignoreFieldNorm:A=rQ.ignoreFieldNorm}){g.forEach(I=>{I.score=log(I.matches,{ignoreFieldNorm:A})})}var eyo=class{constructor(g,A){this.limit=g,this.heap=[],this.comparator=A}get size(){return this.heap.length}insert(g){this.size<this.limit?(this.heap.push(g),this._bubbleUp(this.size-1)):this.comparator(g,this.heap[0])<0&&(this.heap[0]=g,this._sinkDown(0))}extractSorted(){return this.heap.sort(this.comparator)}_bubbleUp(g){const A=this.heap;for(;g>0;){const I=g-1>>1;if(this.comparator(A[g],A[I])<=0)break;const e=A[g];A[g]=A[I],A[I]=e,g=I}}_sinkDown(g){const A=this.heap,I=A.length;let e=g;do{g=e;const t=2*g+1,o=2*g+2;if(t<I&&this.comparator(A[t],A[e])>0&&(e=t),o<I&&this.comparator(A[o],A[e])>0&&(e=o),e!==g){const B=A[g];A[g]=A[e],A[e]=B}}while(e!==g)}};function tyo(g){const A=[];return g.matches.forEach(I=>{if(!aS(I.indices)||!I.indices.length)return;const e={indices:I.indices,value:I.value};I.key&&(e.key=I.key.id),I.idx>-1&&(e.refIndex=I.idx),A.push(e)}),A}function oyo(g,A,{includeMatches:I=rQ.includeMatches,includeScore:e=rQ.includeScore}={}){return g.map(t=>{const{idx:o}=t,B={item:A[o],refIndex:o};return I&&(B.matches=tyo(t)),e&&(B.score=t.score),B})}const Byo=/[\p{L}\p{M}\p{N}_]+/gu,OxI=new WeakSet;function Cyo(g){OxI.has(g)||(OxI.add(g),console.warn(`[Fuse] tokenize regex ${g} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`))}function Qyo(g){if(typeof g=="function"){let A=!1;return I=>{const e=g(I);if(!A&&(A=!0,!Array.isArray(e)||e.some(t=>typeof t!="string")))throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(e)?"array containing non-strings":typeof e}.`);return e}}return g instanceof RegExp?(g.global||Cyo(g),A=>A.match(g)||[]):A=>A.match(Byo)||[]}function Dog({isCaseSensitive:g=!1,ignoreDiacritics:A=!1,tokenize:I}={}){const e=Qyo(I);return{tokenize(t){return g||(t=t.toLowerCase()),A&&(t=VeA(t)),e(t)}}}var iyo=class{static condition(g,A){return A.useTokenSearch}constructor(g,A){this.options=A,this.analyzer=Dog({isCaseSensitive:A.isCaseSensitive,ignoreDiacritics:A.ignoreDiacritics,tokenize:A.tokenize});const I=this.analyzer.tokenize(g),{df:e,fieldCount:t}=A._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(const o of I){this.termSearchers.push(new nog(o,{location:A.location,threshold:A.threshold,distance:A.distance,includeMatches:A.includeMatches,findAllMatches:A.findAllMatches,minMatchCharLength:A.minMatchCharLength,isCaseSensitive:A.isCaseSensitive,ignoreDiacritics:A.ignoreDiacritics,ignoreLocation:!0}));const B=e.get(o)||0,C=Math.log(1+(t-B+.5)/(B+.5));this.idfWeights.push(C)}this.combineAll=A.tokenMatch==="all",this.numTerms=this.termSearchers.length,this.useMask=this.numTerms<=31}searchIn(g){if(!this.termSearchers.length)return{isMatch:!1,score:1};const A=[];let I=0,e=0,t=0,o=0;const B=this.combineAll&&!this.useMask?new Set:null;for(let i=0;i<this.termSearchers.length;i++){const E=this.termSearchers[i].searchIn(g),n=this.idfWeights[i];e+=n,E.isMatch&&(t++,I+=n*(1-E.score),E.indices&&A.push(...E.indices),this.combineAll&&(this.useMask?o|=1<<i:B.add(i)))}if(t===0)return{isMatch:!1,score:1};const C=e>0?1-I/e:0,Q={isMatch:!0,score:Math.max(.001,C)};return this.options.includeMatches&&A.length&&(Q.indices=Eog(A)),this.combineAll&&(this.useMask?Q.matchedMask=o:Q.matchedTerms=B,Q.termCount=this.numTerms),Q}};function dog(g,A,I,e){const t=e.tokenize(A);if(!t.length)return;g.fieldCount++,g.docFieldCount.set(I,(g.docFieldCount.get(I)||0)+1);const o=new Set(t);let B=g.docTermFieldHits.get(I);B||(B=new Map,g.docTermFieldHits.set(I,B));for(const C of o)B.set(C,(B.get(C)||0)+1),g.df.set(C,(g.df.get(C)||0)+1)}function WxI(g,A,I,e){const{i:t,v:o,$:B}=A;if(o!==void 0){dog(g,o,t,e);return}if(B)for(let C=0;C<I;C++){const Q=B[C];if(Q)if(Array.isArray(Q))for(const i of Q)dog(g,i.v,t,e);else dog(g,Q.v,t,e)}}function Eyo(g,A,I){const e={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(const t of g)WxI(e,t,A,I);return e}function nyo(g,A,I,e){WxI(g,A,I,e)}function syo(g,A){const I=g.docFieldCount.get(A);if(I===void 0)return;g.fieldCount-=I,g.docFieldCount.delete(A);const e=g.docTermFieldHits.get(A);if(e){for(const[t,o]of e){const B=(g.df.get(t)||0)-o;B<=0?g.df.delete(t):g.df.set(t,B)}g.docTermFieldHits.delete(A)}}function VxI(g,A){if(A.length===0)return;const I=Array.from(new Set(A)).sort((C,Q)=>C-Q);for(const C of I)syo(g,C);const e=C=>{let Q=0,i=I.length;for(;Q<i;){const E=Q+i>>>1;I[E]<C?Q=E+1:i=E}return C-Q},t=I[0],o=new Map;for(const[C,Q]of g.docFieldCount)o.set(C>t?e(C):C,Q);g.docFieldCount=o;const B=new Map;for(const[C,Q]of g.docTermFieldHits)B.set(C>t?e(C):C,Q);g.docTermFieldHits=B}var W3=class{constructor(g,A,I){this.options={...rQ,...A},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new Ldo(this.options.keys),this._docs=g,this._myIndex=null,this._invertedIndex=null,this.setCollection(g,I),this._lastQuery=null,this._lastSearcher=null}_getSearcher(g){if(this._lastQuery===g)return this._lastSearcher;const A=lGA(g,this._invertedIndex?{...this.options,_invertedIndex:this._invertedIndex}:this.options);return this._lastQuery=g,this._lastSearcher=A,A}setCollection(g,A){if(this._docs=g,A&&!(A instanceof iog))throw new Error(xdo);if(this._myIndex=A||bxI(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){const I=Dog({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=Eyo(this._myIndex.records,this._myIndex.keys.length,I)}this._invalidateSearcherCache()}add(g){if(!aS(g))return;this._docs.push(g);const A=this._myIndex.add(g,this._docs.length-1);if(this._invertedIndex&&A){const I=Dog({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});nyo(this._invertedIndex,A,this._myIndex.keys.length,I)}this._invalidateSearcherCache()}remove(g=()=>!1){const A=[],I=[];for(let e=0,t=this._docs.length;e<t;e+=1)g(this._docs[e],e)&&(A.push(this._docs[e]),I.push(e));if(I.length){this._invertedIndex&&VxI(this._invertedIndex,I);const e=new Set(I);this._docs=this._docs.filter((t,o)=>!e.has(o)),this._myIndex.removeAll(I),this._invalidateSearcherCache()}return A}removeAt(g){if(!Number.isInteger(g)||g<0||g>=this._docs.length)throw new Error(Qog);this._invertedIndex&&VxI(this._invertedIndex,[g]);const A=this._docs.splice(g,1)[0];return this._myIndex.removeAt(g),this._invalidateSearcherCache(),A}_invalidateSearcherCache(){this._lastQuery=null,this._lastSearcher=null}getIndex(){return this._myIndex}_normalizedKeys(){return this._myIndex.keys.map(g=>this._keyStore.get(g.id)||g)}search(g,A){const{limit:I=-1}=A||{},{includeMatches:e,includeScore:t,shouldSort:o,sortFn:B,ignoreFieldNorm:C}=this.options;if(BG(g)&&!g.trim()){let s=this._docs.map((r,a)=>({item:r,refIndex:a}));return rGA(I)&&I>-1&&(s=s.slice(0,I)),s}const Q=o&&rGA(I)&&I>0&&BG(g),i=B,E=(s,r)=>i(s,r)||s.idx-r.idx;let n;if(Q){const s=new eyo(I,E);BG(this._docs[0])?this._searchStringList(g,{heap:s,ignoreFieldNorm:C}):this._searchObjectList(g,{heap:s,ignoreFieldNorm:C}),n=s.extractSorted()}else n=BG(g)?BG(this._docs[0])?this._searchStringList(g):this._searchObjectList(g):this._searchLogical(g),Iyo(n,{ignoreFieldNorm:C}),o&&n.sort(BG(g)?E:i),rGA(I)&&I>-1&&(n=n.slice(0,I));return oyo(n,this._docs,{includeMatches:e,includeScore:t})}_searchStringList(g,{heap:A,ignoreFieldNorm:I}={}){const e=this._getSearcher(g),t=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:o}=this._myIndex,B=A?null:[];return o.forEach(({v:C,i:Q,n:i})=>{if(!aS(C))return;const E=e.searchIn(C);if(E.isMatch){const n={score:E.score,value:C,norm:i,indices:E.indices};t&&(n.matchedMask=E.matchedMask,n.matchedTerms=E.matchedTerms,n.termCount=E.termCount);const s=[n];if(!t||this._coversAllTokens(s)){const r={item:C,idx:Q,matches:s};A?(r.score=log(r.matches,{ignoreFieldNorm:I}),A.insert(r)):B.push(r)}}}),B}_searchLogical(g){const A=ZxI(g,this.options),I=this._normalizedKeys(),e=(C,Q,i)=>{if(!("children"in C)){const{keyId:r,searcher:a}=C;let c;return r===null?(c=[],I.forEach((h,l)=>{c.push(...this._findMatches({key:h,value:Q[l],searcher:a}))})):c=this._findMatches({key:this._keyStore.get(r),value:this._myIndex.getValueForItemAtKeyId(Q,r),searcher:a}),c&&c.length?[{idx:i,item:Q,matches:c}]:[]}const{children:E,operator:n}=C,s=[];for(let r=0,a=E.length;r<a;r+=1){const c=E[r],h=e(c,Q,i);if(h.length)s.push(...h);else if(n===DGA.AND)return[]}return s},t=this._myIndex.records,o=new Map,B=[];return t.forEach(({$:C,i:Q})=>{if(aS(C)){const i=e(A,C,Q);i.length&&(o.has(Q)||(o.set(Q,{idx:Q,item:C,matches:[]}),B.push(o.get(Q))),i.forEach(({matches:E})=>{o.get(Q).matches.push(...E)}))}}),B}_searchObjectList(g,{heap:A,ignoreFieldNorm:I}={}){const e=this._getSearcher(g),t=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:o}=this._myIndex,B=this._normalizedKeys(),C=A?null:[];return o.forEach(({$:Q,i})=>{if(!aS(Q))return;const E=[];let n=!1,s=!1;if(B.forEach((r,a)=>{const c=this._findMatches({key:r,value:Q[a],searcher:e});c.length?(E.push(...c),c[0].hasInverse&&(s=!0)):n=!0}),!(s&&n)&&E.length&&(!t||this._coversAllTokens(E))){const r={idx:i,item:Q,matches:E};A?(r.score=log(r.matches,{ignoreFieldNorm:I}),A.insert(r)):C.push(r)}}),C}_findMatches({key:g,value:A,searcher:I}){if(!aS(A))return[];const e=[];if(O3(A))A.forEach(({v:t,i:o,n:B})=>{if(!aS(t))return;const C=I.searchIn(t);if(C.isMatch){const Q={score:C.score,key:g,value:t,idx:o,norm:B,indices:C.indices,hasInverse:C.hasInverse};C.termCount!==void 0&&(Q.matchedMask=C.matchedMask,Q.matchedTerms=C.matchedTerms,Q.termCount=C.termCount),e.push(Q)}});else{const{v:t,n:o}=A,B=I.searchIn(t);if(B.isMatch){const C={score:B.score,key:g,value:t,norm:o,indices:B.indices,hasInverse:B.hasInverse};B.termCount!==void 0&&(C.matchedMask=B.matchedMask,C.matchedTerms=B.matchedTerms,C.termCount=B.termCount),e.push(C)}}return e}_coversAllTokens(g){const A=g.length?g[0].termCount:void 0;if(A===void 0)return!0;if(A<=31){let e=0;for(let t=0;t<g.length;t++)e|=g[t].matchedMask||0;return e===2**A-1}const I=new Set;for(let e=0;e<g.length;e++){const t=g[e].matchedTerms;if(t)for(const o of t)I.add(o)}return I.size===A}};W3.version="7.5.0",W3.createIndex=bxI,W3.parseIndex=Hdo,W3.config=rQ,W3.match=function(g,A,I){if(I&&I.useTokenSearch)throw new Error(Kdo);return lGA(g,{...rQ,...I}).searchIn(A)},W3.parseQuery=ZxI,rog($do),rog(iyo),W3.use=function(...g){g.forEach(A=>rog(A))};var ayo=W3;const ryo="https://kicad-mod-cache.tscircuit.com";let yog=null,jeA=null,wog=null;const cyo=async()=>yog||jeA||(jeA=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(g=>g.json()).then(g=>(yog=g,jeA=null,g)),jeA),hyo=async(g,A=20)=>{const I=await cyo();return wog||(wog=new ayo(I)),wog.search(g).slice(0,A).map(e=>e.item)},lyo=g=>{const A=g.replace(".pretty/","/").replace(".kicad_mod",""),I=`kicad:${A}`;return{path:g,qualifiedName:I,description:A}},Dyo=g=>g.replace(/^\/+/,"").split("/").map(A=>encodeURIComponent(A)).join("/"),dyo=async g=>{const A=await fetch(`${ryo}/${Dyo(g)}`);if(!A.ok)throw new Error(`KiCad footprint fetch failed: ${A.status}`);const I=await A.text(),{KicadFootprintToCircuitJsonConverter:e}=await sS("kicad-to-circuit-json"),t=new e;return t.addFile(g.split("/").pop()??"selected-footprint.kicad_mod",I),t.runUntilFinished(),t.getOutput()},jxI=g=>g?.source==="jlcpcb"||g?.source==="kicad",yyo=async(g,A)=>{if(g.source==="jlcpcb")return Sdo(g.component.partNumber,A?.jlcpcb);if(g.source==="kicad")return dyo(g.footprint.path);throw new Error("Footprint preview is not available for this source")},wyo=({query:g,placeholder:A,isSearching:I,onQueryChange:e,onSubmit:t})=>{const o=X.useCallback(B=>{B.key==="Enter"&&(B.preventDefault(),t())},[t]);return q.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[q.jsxs("div",{className:"rf-relative rf-flex-grow",children:[q.jsx(reg,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),q.jsx(_tg,{placeholder:A,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:g,onChange:B=>e(B.target.value),onKeyDown:o})]}),q.jsx(Ei,{onClick:t,disabled:I||g.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:I?q.jsx(BS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):q.jsxs(q.Fragment,{children:[q.jsx(reg,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),q.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},uyo=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),Gyo=g=>uyo.format(g),zxI=g=>{switch(g.source){case"tscircuit.com":{const A=g.package;return`tscircuit-${A.package_id??`${A.org_owner_tscircuit_handle??"unknown"}-${A.unscoped_name??A.name??"package"}`}`}case"jlcpcb":return`jlc-${g.component.lcscId}`;case"kicad":return`kicad-${g.footprint.path}`;default:return"unknown"}},myo=g=>{switch(g.source){case"tscircuit.com":return g.package.unscoped_name;case"jlcpcb":return g.component.isDirectLookup?g.component.partNumber:g.component.manufacturer;case"kicad":return g.footprint.qualifiedName}},pyo=g=>{switch(g.source){case"tscircuit.com":return g.package.description||(g.package.org_owner_tscircuit_handle?`Component by ${g.package.org_owner_tscircuit_handle}`:void 0);case"jlcpcb":return g.component.description;case"kicad":return g.footprint.description}},kyo=g=>{switch(g.source){case"tscircuit.com":return g.package.name;case"jlcpcb":return g.component.isDirectLookup?void 0:g.component.partNumber;case"kicad":return}},Myo=({results:g,selected:A,onSelect:I,onShowDetails:e})=>{const t=A?zxI(A):null;return q.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:g.map(o=>{const B=zxI(o),C=t===B,Q=myo(o),i=pyo(o),E=kyo(o),n=o.source==="jlcpcb"?o.component.stock:null,s=o.source==="jlcpcb"?o.component.price:null,r=o.source==="jlcpcb"?o.component.isBasic:null,a=o.source==="jlcpcb"?o.component.isDirectLookup:!1;return q.jsxs("div",{className:`rf-p-3 rf-flex rf-flex-col sm:rf-grid sm:rf-grid-cols-[minmax(0,1fr)_auto] rf-items-start sm:rf-items-center rf-cursor-pointer hover:rf-bg-zinc-100 rf-gap-2 rf-overflow-hidden ${C?"rf-bg-zinc-100":""}`,onClick:()=>I(o),children:[q.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[q.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[q.jsxs("div",{className:"rf-font-medium rf-text-sm rf-truncate rf-flex-1 rf-min-w-0 rf-flex rf-items-center rf-gap-1.5",children:[Q,o.source==="jlcpcb"&&r!=null&&q.jsx("span",{className:`rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 ${r?"rf-bg-green-100 rf-text-green-700":"rf-bg-orange-100 rf-text-orange-700"}`,children:r?"Basic":"Extended"}),a&&q.jsx("span",{className:"rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 rf-bg-blue-100 rf-text-blue-700",children:"Direct lookup"}),o.source==="tscircuit.com"&&o.package.is_private&&q.jsx(TCo,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),o.source==="jlcpcb"&&n!=null?q.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[n.toLocaleString()," in stock"]}):null]}),q.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[E?q.jsx("span",{className:"rf-mr-2",children:E}):null,i]})]}),q.jsxs("div",{children:[o.source==="tscircuit.com"&&e?q.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:q.jsx(Ei,{variant:"outline",size:"sm",className:"rf-text-xs rf-w-full sm:rf-w-auto",onClick:c=>{c.stopPropagation(),e(o)},children:"See Details"})}):o.source==="jlcpcb"&&n!=null?q.jsxs("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0",children:[n.toLocaleString()," in stock"]}):null,s!=null&&q.jsx("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 rf-text-right",children:Gyo(s)})]})]},B)})})},Syo=({circuitJson:g,error:A,isLoading:I,height:e})=>q.jsx("section",{className:"rf-flex rf-min-w-0 rf-items-center rf-justify-center",style:{height:e},children:I?q.jsxs("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-gap-2 rf-bg-zinc-950 rf-text-sm rf-text-zinc-300",style:{height:e},children:[q.jsx(BS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),"Loading preview..."]}):A?q.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-p-4",style:{height:e},children:q.jsxs("div",{className:"rf-flex rf-max-w-[320px] rf-items-start rf-gap-2 rf-text-sm rf-text-zinc-300",children:[q.jsx(aeg,{className:"rf-mt-0.5 rf-h-4 rf-w-4 rf-flex-shrink-0"}),q.jsx("span",{children:A})]})}):g?q.jsx("div",{className:"rf-w-full rf-min-w-0 rf-overflow-hidden",children:q.jsx(Eeg,{circuitJson:g,height:e,allowEditing:!1,clickToInteractEnabled:!1,focusOnHover:!1,disablePcbGroups:!0})}):q.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-text-sm rf-text-zinc-300",style:{height:e},children:"No preview"})}),XxI={importComponentDialog:101,importComponentDetailsDialog:102},fyo=({packageResult:g,isOpen:A,onOpenChange:I,isLoading:e,details:t,previewTab:o,onPreviewTabChange:B,isSubmitting:C,onImport:Q})=>{const i=g?.package??null,E=i?.latest_pcb_preview_image_url,n=i?.latest_sch_preview_image_url,s=i?.latest_cad_preview_image_url,r=i?.unscoped_name?.split("/").pop()??i?.unscoped_name,a=i?.org_owner_tscircuit_handle??void 0,c=a?`https://tscircuit.com/${a}`:void 0,h=a&&r?`https://tscircuit.com/${a}/${r}`:void 0;return q.jsx(Z5,{open:A,onOpenChange:I,children:q.jsxs(q3,{showOverlay:!1,style:{width:"calc(100vw - 2rem)",zIndex:XxI.importComponentDetailsDialog},className:"rf-max-w-5xl no-scrollbar !rf-overflow-y-auto rf-max-h-[90vh] rf-overflow-hidden rf-flex rf-flex-col rf-rounded-sm",children:[q.jsx(T3,{className:"rf-pb-4 rf-border-b",children:q.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:q.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[q.jsx(Z3,{className:"rf-text-xl rf-font-semibold rf-truncate",children:r}),q.jsx(O5,{children:i?.description})]})})}),q.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[a?q.jsxs("div",{children:[q.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),q.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:c?q.jsx("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:a}):a})]}):null,(s||E||n)&&q.jsx(q.Fragment,{children:q.jsxs("div",{children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),q.jsxs(ZHA,{value:o,onValueChange:l=>B(l),children:[q.jsxs(llA,{className:"rf-inline-flex rf-h-9 rf-items-center rf-justify-center rf-rounded-lg rf-bg-zinc-100 rf-p-1 rf-text-zinc-500 dark:rf-bg-zinc-800 dark:rf-text-zinc-400",children:[E&&q.jsx(gx,{value:"pcb",children:"PCB"}),n&&q.jsx(gx,{value:"schematic",children:"Schematic"}),s&&q.jsx(gx,{value:"3d",children:"3D"})]}),q.jsxs("div",{className:"rf-mt-4",children:[q.jsx(xw,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:E?q.jsx("img",{src:E,alt:`${r??"package"} PCB preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),q.jsx(xw,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:n?q.jsx("img",{src:n,alt:`${r??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),q.jsx(xw,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:s?q.jsx("img",{src:s,alt:`${r??"package"} 3D preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null})]})]})]})}),t?.ai_description?q.jsxs("section",{children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),q.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:q.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:t.ai_description})})]}):null,t?.ai_usage_instructions?q.jsxs("section",{children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),q.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:q.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:t.ai_usage_instructions})})]}):null,e?q.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[q.jsx(BS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),q.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),q.jsxs(FZ,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[q.jsx("div",{className:"rf-flex-1",children:h?q.jsxs(Ei,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(h,"_blank"),children:[q.jsx(LCo,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),q.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[q.jsx(Ei,{variant:"outline",onClick:()=>I(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),q.jsx(Ei,{onClick:Q,disabled:C,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:C?q.jsx(BS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},Ryo=()=>{const[g,A]=X.useState(null),[I,e]=X.useState(!1),t=X.useCallback(async(B,C)=>{e(!0);try{const Q=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${B}/${C}`)}`);if(!Q.ok)throw new Error(`Failed to load package details: ${Q.status}`);const i=await Q.json();A(i.package??null)}catch(Q){console.error("Failed to fetch package details",Q),A(null)}finally{e(!1)}},[]),o=X.useCallback(()=>{A(null),e(!1)},[]);return{details:g,isLoading:I,fetchDetails:t,reset:o}},Nyo=(g,A)=>{const[I,e]=X.useState({circuitJson:null,error:null,isLoading:!1});return X.useEffect(()=>{if(!g||!jxI(g)){e({circuitJson:null,error:null,isLoading:!1});return}let t=!1;return e({circuitJson:null,error:null,isLoading:!0}),yyo(g,A).then(o=>{t||e({circuitJson:o,error:null,isLoading:!1})}).catch(o=>{t||e({circuitJson:null,error:o instanceof Error?o.message:"Failed to load footprint preview",isLoading:!1})}),()=>{t=!0}},[g,A]),I},xyo=async(g,A)=>{const I={"Content-Type":"application/json"};A&&(I.Authorization=`Bearer ${A}`);const e=await fetch("https://registry-api.tscircuit.com/packages/search",{method:"POST",headers:I,body:JSON.stringify({query:g})});if(!e.ok)throw new Error(`tscircuit registry error: ${e.status}`);return(await e.json()).packages??[]},Fyo=({sessionToken:g})=>{const[A,I]=X.useState([]),[e,t]=X.useState(!1),[o,B]=X.useState(null),[C,Q]=X.useState(!1),i=X.useCallback(async n=>{const s=n.trim();if(!s)return[];t(!0),B(null);try{const a=(await xyo(s,g)).map(c=>({source:"tscircuit.com",package:c}));return I(a),a}catch(r){return console.error("Error searching tscircuit packages",r),I([]),B(r instanceof Error?r.message:"Failed to search tscircuit packages"),[]}finally{t(!1),Q(!0)}},[g]),E=X.useCallback(()=>{I([]),t(!1),B(null),Q(!1)},[]);return{results:A,isSearching:e,error:o,hasSearched:C,search:i,reset:E}},Uyo=g=>{const A=/^C(\d+)$/i.exec(g.trim());if(!A)return null;const I=Number(A[1]);if(!Number.isSafeInteger(I))return null;const e=`C${A[1]}`;return{source:"jlcpcb",component:{lcscId:I,manufacturer:e,partNumber:e,description:"Import directly from EasyEDA; stock and availability are unknown",package:"",isDirectLookup:!0}}},$xI=(g,A)=>{const I=Uyo(g);return I?A.some(t=>t.component.partNumber.toUpperCase()===I.component.partNumber)?A:[I,...A]:A},Jyo=g=>{const A=g.trim();return/^C\d+/i.test(A)?A.replace(/^C/i,""):A},Pyo=()=>{const[g,A]=X.useState([]),[I,e]=X.useState(!1),[t,o]=X.useState(null),[B,C]=X.useState(!1),Q=X.useCallback(async E=>{const n=Jyo(E);if(!n)return[];e(!0),o(null);try{const s=await pdo(n,10),r=$xI(E,s.map(a=>({source:"jlcpcb",component:kdo(a)})));return A(r),r}catch(s){console.error("Error searching JLCPCB components",s);const r=$xI(E,[]);return A(r),o(r.length>0?null:s instanceof Error?s.message:"Failed to search JLCPCB components"),r}finally{e(!1),C(!0)}},[]),i=X.useCallback(()=>{A([]),e(!1),o(null),C(!1)},[]);return{results:g,isSearching:I,error:t,hasSearched:B,search:Q,reset:i}},Kyo=()=>{const[g,A]=X.useState([]),[I,e]=X.useState(!1),[t,o]=X.useState(null),[B,C]=X.useState(!1),Q=X.useCallback(async E=>{const n=E.trim();if(!n)return[];e(!0),o(null);try{const r=(await hyo(n,20)).map(a=>({source:"kicad",footprint:lyo(a)}));return A(r),r}catch(s){return console.error("Error searching KiCad footprints",s),A([]),o(s instanceof Error?s.message:"Failed to search KiCad footprints"),[]}finally{e(!1),C(!0)}},[]),i=X.useCallback(()=>{A([]),e(!1),o(null),C(!1)},[]);return{results:g,isSearching:I,error:t,hasSearched:B,search:Q,reset:i}},Lyo=({onTscircuitPackageSelected:g,onJlcpcbComponentTsxLoaded:A,onKicadStringSelected:I})=>{const e=[];return g&&e.push("tscircuit.com"),A&&e.push("jlcpcb"),I&&e.push("kicad"),e},Yyo=({isOpen:g,onClose:A,jlcpcbProxyRequestHeaders:I,onKicadStringSelected:e,onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:o,jlcpcbProxyApiBase:B,tscircuitSessionToken:C})=>{TeA();const Q=X.useMemo(()=>Lyo({onKicadStringSelected:e,onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:o}),[e,t,o]),i=Q.length>0,E=Q.length===1,[n,s]=X.useState(Q[0]??"tscircuit.com"),[r,a]=X.useState(""),[c,h]=X.useState(null),{results:l,isSearching:D,error:d,hasSearched:y,search:w,reset:u}=Fyo({sessionToken:C}),{results:G,isSearching:m,error:p,hasSearched:k,search:S,reset:R}=Pyo(),{results:x,isSearching:N,error:J,hasSearched:K,search:_,reset:H}=Kyo(),{details:T,isLoading:j,fetchDetails:W,reset:O}=Ryo(),[gA,tA]=X.useState(null),[IA,QA]=X.useState(!1),[nA,DA]=X.useState("pcb"),[CA,hA]=X.useState(null),[sA,cA]=X.useState(!1),SA=X.useMemo(()=>({jlcpcb:{headers:I,apiBase:B}}),[B,I]),{circuitJson:xA,error:aA,isLoading:FA}=Nyo(c,SA),NA=jxI(c);X.useEffect(()=>{hA(null)},[c]);const RA=X.useCallback(()=>{u(),R(),H(),h(null)},[R,H,u]);X.useEffect(()=>{g||(RA(),a(""),QA(!1),tA(null),hA(null))},[g,RA]),X.useEffect(()=>{a(""),h(null),n==="tscircuit.com"?u():n==="jlcpcb"?R():n==="kicad"&&H()},[n,R,H,u]);const JA=kA=>{h(kA),tA(kA),DA("pcb"),QA(!0),O();const OA=kA.package.org_owner_tscircuit_handle,$A=kA.package.unscoped_name;if(OA&&$A){const tg=$A.split("/").pop()??$A;W(OA,tg)}},PA=async()=>{r.trim()&&(h(null),n==="tscircuit.com"?await w(r):n==="jlcpcb"?await S(r):n==="kicad"&&await _(r))},pA=async kA=>{try{if(hA(null),cA(!0),kA.source==="kicad"){if(!e)throw new Error("KiCad handler not provided");await e({result:kA,footprint:kA.footprint.qualifiedName})}else if(kA.source==="jlcpcb"){if(!o)throw new Error("JLCPCB handler not provided");const OA=await Mdo(kA.component.partNumber,{headers:I,apiBase:B});await o({result:kA,tsx:OA})}else if(kA.source==="tscircuit.com"){if(!t)throw new Error("tscircuit package handler not provided");const OA=kA.package.org_owner_tscircuit_handle,$A=kA.package.unscoped_name;if(!OA||!$A)throw new Error("Missing package metadata");const tg=$A.split("/").pop()??$A,dg=`@tsci/${OA}.${tg}`;await t({result:kA,fullPackageName:dg})}return!0}catch(OA){return console.error("Failed to import component",OA),hA(OA instanceof Error?OA.message:"Failed to import component"),!1}finally{cA(!1)}};let YA=[],dA=!1,HA=null,WA=!1;n==="tscircuit.com"?(YA=l,dA=D,HA=d,WA=y):n==="jlcpcb"?(YA=G,dA=m,HA=p,WA=k):n==="kicad"&&(YA=x,dA=N,HA=J,WA=K);const Qg=async()=>{if(!c)return;await pA(c)&&(A(),RA(),a(""))},_A=kA=>{kA||A()},GA=kA=>{QA(kA),kA||tA(null)};return q.jsxs(Z5,{open:g,onOpenChange:_A,children:[q.jsxs(q3,{style:{width:"calc(100vw - 2rem)",maxWidth:NA?"min(1120px, calc(100vw - 2rem))":"min(672px, calc(100vw - 2rem))",zIndex:XxI.importComponentDialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[q.jsxs(T3,{children:[q.jsxs(Z3,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",E?aGA[n].label:""," ","Component"]}),q.jsx(O5,{className:"rf-text-sm",children:i?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),i?q.jsxs(ZHA,{value:n,onValueChange:kA=>s(kA),className:"rf-min-w-0 rf-w-full",children:[!E&&q.jsx(llA,{className:"rf-flex rf-w-full rf-gap-2",children:Q.map(kA=>q.jsx(gx,{value:kA,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:aGA[kA].label},kA))}),q.jsxs("div",{className:"rf-min-w-0",style:NA?{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(360px, 0.95fr)",gap:"1.5rem",alignItems:"start"}:void 0,children:[q.jsxs("div",{className:"rf-min-w-0",children:[q.jsx(wyo,{query:r,placeholder:aGA[n].placeholder,isSearching:dA,onQueryChange:a,onSubmit:PA}),q.jsx("div",{className:"no-scrollbar rf-mt-4 rf-flex-1 rf-min-h-[200px] !rf-max-h-[40vh] !rf-overflow-y-auto rf-overflow-x-hidden rf-border rf-rounded-md rf-min-w-0",children:dA?q.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[q.jsx(BS,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),q.jsx("p",{children:"Searching..."})]}):YA.length>0?q.jsx(Myo,{results:YA,selected:c,onSelect:h,onShowDetails:n==="tscircuit.com"?JA:void 0}):q.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:HA?`Error: ${HA}`:WA?aGA[n].emptyMessage:"Enter a search term to find components"})})]}),NA?q.jsx("div",{className:"rf-mt-4",children:q.jsx(Syo,{circuitJson:xA,error:aA,isLoading:FA,height:325})}):null]})]}):null,CA?q.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:CA}):null,q.jsxs(FZ,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[q.jsx(Ei,{variant:"outline",onClick:A,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),q.jsx(Ei,{onClick:Qg,disabled:!c||sA,className:"rf-order-1 sm:rf-order-2",children:sA?q.jsx(BS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),q.jsx(fyo,{packageResult:gA,isOpen:IA,onOpenChange:GA,isLoading:j,details:T,previewTab:nA,onPreviewTabChange:kA=>DA(kA),isSubmitting:sA,onImport:()=>{gA&&pA(gA).then(kA=>{kA&&(QA(!1),A(),RA(),a(""))})}})]})},_yo=g=>{const A=g.match(/export const (\w+) =/);if(!A)throw new Error("Could not determine component name from TSX contents");return A[1]},AFI=g=>{const A=Fc(B=>B.pushEvent),I=Fc(B=>B.upsertFile),e=async({result:B,fullPackageName:C})=>{const i=B.package.unscoped_name??B.package.name;await JC.promise(A({event_type:"INSTALL_PACKAGE",full_package_name:C}),{loading:`Requesting install for "${i}"`,success:`Install requested for "${i}"`,error:E=>`Failed to request install: ${E instanceof Error?E.message:String(E)}`})},t=async({footprint:B})=>{await JC.promise(navigator.clipboard.writeText(B),{loading:`Copying "${B}"`,success:`Copied "${B}" to clipboard`,error:C=>`Failed to copy footprint: ${C instanceof Error?C.message:String(C)}`})},o=async({result:B,tsx:C})=>{const i=`imports/${_yo(C)}.tsx`;await JC.promise(I(i,C),{loading:`Importing ${B.component.partNumber}`,success:`Imported to "${i}"`,error:E=>`Failed to import component: ${E instanceof Error?E.message:String(E)}`})};return q.jsx(Yyo,{...g,onTscircuitPackageSelected:e,onKicadStringSelected:t,onJlcpcbComponentTsxLoaded:o})};AFI.displayName="ImportComponentDialogForCli";const byo=async({circuitJson:g,projectName:A})=>{const{convertCircuitJsonToAltiumZip:I}=await Promise.resolve().then(()=>B_o),e=await I(g,A);return new Blob([new Uint8Array(e)],{type:"application/zip"})},Hyo=async({circuitJson:g,projectName:A})=>{await JC.promise((async()=>{const I=await byo({circuitJson:g,projectName:A});mk(I,{fileName:`${A}_altium_project.zip`})})(),{loading:"Generating Altium project...",success:"Altium project ZIP ready",error:I=>`Failed to generate Altium project: ${I instanceof Error?I.message:String(I)}`})};var uog={exports:{}},gFI;function vyo(){return gFI||(gFI=1,(function(g,A){var I={env:{},version:""};(function(e){g.exports=e()})(function(){return(function e(t,o,B){function C(E,n){if(!o[E]){if(!t[E]){var s=typeof LF=="function"&&LF;if(!n&&s)return s(E,!0);if(Q)return Q(E,!0);var r=new Error("Cannot find module '"+E+"'");throw r.code="MODULE_NOT_FOUND",r}var a=o[E]={exports:{}};t[E][0].call(a.exports,function(c){var h=t[E][1][c];return C(h||c)},a,a.exports,e,t,o,B)}return o[E].exports}for(var Q=typeof LF=="function"&&LF,i=0;i<B.length;i++)C(B[i]);return C})({1:[function(e,t,o){var B=e("./utils"),C=e("./support"),Q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";o.encode=function(i){for(var E,n,s,r,a,c,h,l=[],D=0,d=i.length,y=d,w=B.getTypeOf(i)!=="string";D<i.length;)y=d-D,s=w?(E=i[D++],n=D<d?i[D++]:0,D<d?i[D++]:0):(E=i.charCodeAt(D++),n=D<d?i.charCodeAt(D++):0,D<d?i.charCodeAt(D++):0),r=E>>2,a=(3&E)<<4|n>>4,c=1<y?(15&n)<<2|s>>6:64,h=2<y?63&s:64,l.push(Q.charAt(r)+Q.charAt(a)+Q.charAt(c)+Q.charAt(h));return l.join("")},o.decode=function(i){var E,n,s,r,a,c,h=0,l=0,D="data:";if(i.substr(0,D.length)===D)throw new Error("Invalid base64 input, it looks like a data url.");var d,y=3*(i=i.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(i.charAt(i.length-1)===Q.charAt(64)&&y--,i.charAt(i.length-2)===Q.charAt(64)&&y--,y%1!=0)throw new Error("Invalid base64 input, bad content length.");for(d=C.uint8array?new Uint8Array(0|y):new Array(0|y);h<i.length;)E=Q.indexOf(i.charAt(h++))<<2|(r=Q.indexOf(i.charAt(h++)))>>4,n=(15&r)<<4|(a=Q.indexOf(i.charAt(h++)))>>2,s=(3&a)<<6|(c=Q.indexOf(i.charAt(h++))),d[l++]=E,a!==64&&(d[l++]=n),c!==64&&(d[l++]=s);return d}},{"./support":30,"./utils":32}],2:[function(e,t,o){var B=e("./external"),C=e("./stream/DataWorker"),Q=e("./stream/Crc32Probe"),i=e("./stream/DataLengthProbe");function E(n,s,r,a,c){this.compressedSize=n,this.uncompressedSize=s,this.crc32=r,this.compression=a,this.compressedContent=c}E.prototype={getContentWorker:function(){var n=new C(B.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new i("data_length")),s=this;return n.on("end",function(){if(this.streamInfo.data_length!==s.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),n},getCompressedWorker:function(){return new C(B.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},E.createWorkerFrom=function(n,s,r){return n.pipe(new Q).pipe(new i("uncompressedSize")).pipe(s.compressWorker(r)).pipe(new i("compressedSize")).withStreamInfo("compression",s)},t.exports=E},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(e,t,o){var B=e("./stream/GenericWorker");o.STORE={magic:"\0\0",compressWorker:function(){return new B("STORE compression")},uncompressWorker:function(){return new B("STORE decompression")}},o.DEFLATE=e("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(e,t,o){var B=e("./utils"),C=(function(){for(var Q,i=[],E=0;E<256;E++){Q=E;for(var n=0;n<8;n++)Q=1&Q?3988292384^Q>>>1:Q>>>1;i[E]=Q}return i})();t.exports=function(Q,i){return Q!==void 0&&Q.length?B.getTypeOf(Q)!=="string"?(function(E,n,s,r){var a=C,c=r+s;E^=-1;for(var h=r;h<c;h++)E=E>>>8^a[255&(E^n[h])];return-1^E})(0|i,Q,Q.length,0):(function(E,n,s,r){var a=C,c=r+s;E^=-1;for(var h=r;h<c;h++)E=E>>>8^a[255&(E^n.charCodeAt(h))];return-1^E})(0|i,Q,Q.length,0):0}},{"./utils":32}],5:[function(e,t,o){o.base64=!1,o.binary=!1,o.dir=!1,o.createFolders=!0,o.date=null,o.compression=null,o.compressionOptions=null,o.comment=null,o.unixPermissions=null,o.dosPermissions=null},{}],6:[function(e,t,o){var B=null;B=typeof Promise<"u"?Promise:e("lie"),t.exports={Promise:B}},{lie:37}],7:[function(e,t,o){var B=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",C=e("pako"),Q=e("./utils"),i=e("./stream/GenericWorker"),E=B?"uint8array":"array";function n(s,r){i.call(this,"FlateWorker/"+s),this._pako=null,this._pakoAction=s,this._pakoOptions=r,this.meta={}}o.magic="\b\0",Q.inherits(n,i),n.prototype.processChunk=function(s){this.meta=s.meta,this._pako===null&&this._createPako(),this._pako.push(Q.transformTo(E,s.data),!1)},n.prototype.flush=function(){i.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},n.prototype.cleanUp=function(){i.prototype.cleanUp.call(this),this._pako=null},n.prototype._createPako=function(){this._pako=new C[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var s=this;this._pako.onData=function(r){s.push({data:r,meta:s.meta})}},o.compressWorker=function(s){return new n("Deflate",s)},o.uncompressWorker=function(){return new n("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(e,t,o){function B(a,c){var h,l="";for(h=0;h<c;h++)l+=String.fromCharCode(255&a),a>>>=8;return l}function C(a,c,h,l,D,d){var y,w,u=a.file,G=a.compression,m=d!==E.utf8encode,p=Q.transformTo("string",d(u.name)),k=Q.transformTo("string",E.utf8encode(u.name)),S=u.comment,R=Q.transformTo("string",d(S)),x=Q.transformTo("string",E.utf8encode(S)),N=k.length!==u.name.length,J=x.length!==S.length,K="",_="",H="",T=u.dir,j=u.date,W={crc32:0,compressedSize:0,uncompressedSize:0};c&&!h||(W.crc32=a.crc32,W.compressedSize=a.compressedSize,W.uncompressedSize=a.uncompressedSize);var O=0;c&&(O|=8),m||!N&&!J||(O|=2048);var gA=0,tA=0;T&&(gA|=16),D==="UNIX"?(tA=798,gA|=(function(QA,nA){var DA=QA;return QA||(DA=nA?16893:33204),(65535&DA)<<16})(u.unixPermissions,T)):(tA=20,gA|=(function(QA){return 63&(QA||0)})(u.dosPermissions)),y=j.getUTCHours(),y<<=6,y|=j.getUTCMinutes(),y<<=5,y|=j.getUTCSeconds()/2,w=j.getUTCFullYear()-1980,w<<=4,w|=j.getUTCMonth()+1,w<<=5,w|=j.getUTCDate(),N&&(_=B(1,1)+B(n(p),4)+k,K+="up"+B(_.length,2)+_),J&&(H=B(1,1)+B(n(R),4)+x,K+="uc"+B(H.length,2)+H);var IA="";return IA+=`
5678
5678
  \0`,IA+=B(O,2),IA+=G.magic,IA+=B(y,2),IA+=B(w,2),IA+=B(W.crc32,4),IA+=B(W.compressedSize,4),IA+=B(W.uncompressedSize,4),IA+=B(p.length,2),IA+=B(K.length,2),{fileRecord:s.LOCAL_FILE_HEADER+IA+p+K,dirRecord:s.CENTRAL_FILE_HEADER+B(tA,2)+IA+B(R.length,2)+"\0\0\0\0"+B(gA,4)+B(l,4)+p+K+R}}var Q=e("../utils"),i=e("../stream/GenericWorker"),E=e("../utf8"),n=e("../crc32"),s=e("../signature");function r(a,c,h,l){i.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=c,this.zipPlatform=h,this.encodeFileName=l,this.streamFiles=a,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}Q.inherits(r,i),r.prototype.push=function(a){var c=a.meta.percent||0,h=this.entriesCount,l=this._sources.length;this.accumulate?this.contentBuffer.push(a):(this.bytesWritten+=a.data.length,i.prototype.push.call(this,{data:a.data,meta:{currentFile:this.currentFile,percent:h?(c+100*(h-l-1))/h:100}}))},r.prototype.openedSource=function(a){this.currentSourceOffset=this.bytesWritten,this.currentFile=a.file.name;var c=this.streamFiles&&!a.file.dir;if(c){var h=C(a,c,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:h.fileRecord,meta:{percent:0}})}else this.accumulate=!0},r.prototype.closedSource=function(a){this.accumulate=!1;var c=this.streamFiles&&!a.file.dir,h=C(a,c,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(h.dirRecord),c)this.push({data:(function(l){return s.DATA_DESCRIPTOR+B(l.crc32,4)+B(l.compressedSize,4)+B(l.uncompressedSize,4)})(a),meta:{percent:100}});else for(this.push({data:h.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},r.prototype.flush=function(){for(var a=this.bytesWritten,c=0;c<this.dirRecords.length;c++)this.push({data:this.dirRecords[c],meta:{percent:100}});var h=this.bytesWritten-a,l=(function(D,d,y,w,u){var G=Q.transformTo("string",u(w));return s.CENTRAL_DIRECTORY_END+"\0\0\0\0"+B(D,2)+B(D,2)+B(d,4)+B(y,4)+B(G.length,2)+G})(this.dirRecords.length,h,a,this.zipComment,this.encodeFileName);this.push({data:l,meta:{percent:100}})},r.prototype.prepareNextSource=function(){this.previous=this._sources.shift(),this.openedSource(this.previous.streamInfo),this.isPaused?this.previous.pause():this.previous.resume()},r.prototype.registerPrevious=function(a){this._sources.push(a);var c=this;return a.on("data",function(h){c.processChunk(h)}),a.on("end",function(){c.closedSource(c.previous.streamInfo),c._sources.length?c.prepareNextSource():c.end()}),a.on("error",function(h){c.error(h)}),this},r.prototype.resume=function(){return!!i.prototype.resume.call(this)&&(!this.previous&&this._sources.length?(this.prepareNextSource(),!0):this.previous||this._sources.length||this.generatedError?void 0:(this.end(),!0))},r.prototype.error=function(a){var c=this._sources;if(!i.prototype.error.call(this,a))return!1;for(var h=0;h<c.length;h++)try{c[h].error(a)}catch{}return!0},r.prototype.lock=function(){i.prototype.lock.call(this);for(var a=this._sources,c=0;c<a.length;c++)a[c].lock()},t.exports=r},{"../crc32":4,"../signature":23,"../stream/GenericWorker":28,"../utf8":31,"../utils":32}],9:[function(e,t,o){var B=e("../compressions"),C=e("./ZipFileWorker");o.generateWorker=function(Q,i,E){var n=new C(i.streamFiles,E,i.platform,i.encodeFileName),s=0;try{Q.forEach(function(r,a){s++;var c=(function(d,y){var w=d||y,u=B[w];if(!u)throw new Error(w+" is not a valid compression method !");return u})(a.options.compression,i.compression),h=a.options.compressionOptions||i.compressionOptions||{},l=a.dir,D=a.date;a._compressWorker(c,h).withStreamInfo("file",{name:r,dir:l,date:D,comment:a.comment||"",unixPermissions:a.unixPermissions,dosPermissions:a.dosPermissions}).pipe(n)}),n.entriesCount=s}catch(r){n.error(r)}return n}},{"../compressions":3,"./ZipFileWorker":8}],10:[function(e,t,o){function B(){if(!(this instanceof B))return new B;if(arguments.length)throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");this.files=Object.create(null),this.comment=null,this.root="",this.clone=function(){var C=new B;for(var Q in this)typeof this[Q]!="function"&&(C[Q]=this[Q]);return C}}(B.prototype=e("./object")).loadAsync=e("./load"),B.support=e("./support"),B.defaults=e("./defaults"),B.version="3.10.2",B.loadAsync=function(C,Q){return new B().loadAsync(C,Q)},B.external=e("./external"),t.exports=B},{"./defaults":5,"./external":6,"./load":11,"./object":15,"./support":30}],11:[function(e,t,o){var B=e("./utils"),C=e("./external"),Q=e("./utf8"),i=e("./zipEntries"),E=e("./stream/Crc32Probe"),n=e("./nodejsUtils");function s(r){return new C.Promise(function(a,c){var h=r.decompressed.getContentWorker().pipe(new E);h.on("error",function(l){c(l)}).on("end",function(){h.streamInfo.crc32!==r.decompressed.crc32?c(new Error("Corrupted zip : CRC32 mismatch")):a()}).resume()})}t.exports=function(r,a){var c=this;return a=B.extend(a||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:Q.utf8decode}),n.isNode&&n.isStream(r)?C.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):B.prepareContent("the loaded zip file",r,!0,a.optimizedBinaryString,a.base64).then(function(h){var l=new i(a);return l.load(h),l}).then(function(h){var l=[C.Promise.resolve(h)],D=h.files;if(a.checkCRC32)for(var d=0;d<D.length;d++)l.push(s(D[d]));return C.Promise.all(l)}).then(function(h){for(var l=h.shift(),D=l.files,d=0;d<D.length;d++){var y=D[d],w=y.fileNameStr,u=B.resolve(y.fileNameStr);c.file(u,y.decompressed,{binary:!0,optimizedBinaryString:!0,date:y.date,dir:y.dir,comment:y.fileCommentStr.length?y.fileCommentStr:null,unixPermissions:y.unixPermissions,dosPermissions:y.dosPermissions,createFolders:a.createFolders}),y.dir||(c.file(u).unsafeOriginalName=w)}return l.zipComment.length&&(c.comment=l.zipComment),c})}},{"./external":6,"./nodejsUtils":14,"./stream/Crc32Probe":25,"./utf8":31,"./utils":32,"./zipEntries":33}],12:[function(e,t,o){var B=e("../utils"),C=e("../stream/GenericWorker");function Q(i,E){C.call(this,"Nodejs stream input adapter for "+i),this._upstreamEnded=!1,this._bindStream(E)}B.inherits(Q,C),Q.prototype._bindStream=function(i){var E=this;(this._stream=i).pause(),i.on("data",function(n){E.push({data:n,meta:{percent:0}})}).on("error",function(n){E.isPaused?this.generatedError=n:E.error(n)}).on("end",function(){E.isPaused?E._upstreamEnded=!0:E.end()})},Q.prototype.pause=function(){return!!C.prototype.pause.call(this)&&(this._stream.pause(),!0)},Q.prototype.resume=function(){return!!C.prototype.resume.call(this)&&(this._upstreamEnded?this.end():this._stream.resume(),!0)},t.exports=Q},{"../stream/GenericWorker":28,"../utils":32}],13:[function(e,t,o){var B=e("readable-stream").Readable;function C(Q,i,E){B.call(this,i),this._helper=Q;var n=this;Q.on("data",function(s,r){n.push(s)||n._helper.pause(),E&&E(r)}).on("error",function(s){n.emit("error",s)}).on("end",function(){n.push(null)})}e("../utils").inherits(C,B),C.prototype._read=function(){this._helper.resume()},t.exports=C},{"../utils":32,"readable-stream":16}],14:[function(e,t,o){t.exports={isNode:typeof Buffer<"u",newBufferFrom:function(B,C){if(Buffer.from&&Buffer.from!==Uint8Array.from)return Buffer.from(B,C);if(typeof B=="number")throw new Error('The "data" argument must not be a number');return new Buffer(B,C)},allocBuffer:function(B){if(Buffer.alloc)return Buffer.alloc(B);var C=new Buffer(B);return C.fill(0),C},isBuffer:function(B){return Buffer.isBuffer(B)},isStream:function(B){return B&&typeof B.on=="function"&&typeof B.pause=="function"&&typeof B.resume=="function"}}},{}],15:[function(e,t,o){function B(u,G,m){var p,k=Q.getTypeOf(G),S=Q.extend(m||{},n);S.date=S.date||new Date,S.compression!==null&&(S.compression=S.compression.toUpperCase()),typeof S.unixPermissions=="string"&&(S.unixPermissions=parseInt(S.unixPermissions,8)),S.unixPermissions&&16384&S.unixPermissions&&(S.dir=!0),S.dosPermissions&&16&S.dosPermissions&&(S.dir=!0),S.dir&&(u=D(u)),S.createFolders&&(p=l(u))&&d.call(this,p,!0);var R=k==="string"&&S.binary===!1&&S.base64===!1;m&&m.binary!==void 0||(S.binary=!R),(G instanceof s&&G.uncompressedSize===0||S.dir||!G||G.length===0)&&(S.base64=!1,S.binary=!0,G="",S.compression="STORE",k="string");var x=null;x=G instanceof s||G instanceof i?G:c.isNode&&c.isStream(G)?new h(u,G):Q.prepareContent(u,G,S.binary,S.optimizedBinaryString,S.base64);var N=new r(u,x,S);this.files[u]=N}var C=e("./utf8"),Q=e("./utils"),i=e("./stream/GenericWorker"),E=e("./stream/StreamHelper"),n=e("./defaults"),s=e("./compressedObject"),r=e("./zipObject"),a=e("./generate"),c=e("./nodejsUtils"),h=e("./nodejs/NodejsStreamInputAdapter"),l=function(u){u.slice(-1)==="/"&&(u=u.substring(0,u.length-1));var G=u.lastIndexOf("/");return 0<G?u.substring(0,G):""},D=function(u){return u.slice(-1)!=="/"&&(u+="/"),u},d=function(u,G){return G=G!==void 0?G:n.createFolders,u=D(u),this.files[u]||B.call(this,u,null,{dir:!0,createFolders:G}),this.files[u]};function y(u){return Object.prototype.toString.call(u)==="[object RegExp]"}var w={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(u){var G,m,p;for(G in this.files)p=this.files[G],(m=G.slice(this.root.length,G.length))&&G.slice(0,this.root.length)===this.root&&u(m,p)},filter:function(u){var G=[];return this.forEach(function(m,p){u(m,p)&&G.push(p)}),G},file:function(u,G,m){if(arguments.length!==1)return u=this.root+u,B.call(this,u,G,m),this;if(y(u)){var p=u;return this.filter(function(S,R){return!R.dir&&p.test(S)})}var k=this.files[this.root+u];return k&&!k.dir?k:null},folder:function(u){if(!u)return this;if(y(u))return this.filter(function(k,S){return S.dir&&u.test(k)});var G=this.root+u,m=d.call(this,G),p=this.clone();return p.root=m.name,p},remove:function(u){u=this.root+u;var G=this.files[u];if(G||(u.slice(-1)!=="/"&&(u+="/"),G=this.files[u]),G&&!G.dir)delete this.files[u];else for(var m=this.filter(function(k,S){return S.name.slice(0,u.length)===u}),p=0;p<m.length;p++)delete this.files[m[p].name];return this},generate:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},generateInternalStream:function(u){var G,m={};try{if((m=Q.extend(u||{},{streamFiles:!1,compression:"STORE",compressionOptions:null,type:"",platform:"DOS",comment:null,mimeType:"application/zip",encodeFileName:C.utf8encode})).type=m.type.toLowerCase(),m.compression=m.compression.toUpperCase(),m.type==="binarystring"&&(m.type="string"),!m.type)throw new Error("No output type specified.");Q.checkSupport(m.type),m.platform!=="darwin"&&m.platform!=="freebsd"&&m.platform!=="linux"&&m.platform!=="sunos"||(m.platform="UNIX"),m.platform==="win32"&&(m.platform="DOS");var p=m.comment||this.comment||"";G=a.generateWorker(this,m,p)}catch(k){(G=new i("error")).error(k)}return new E(G,m.type||"string",m.mimeType)},generateAsync:function(u,G){return this.generateInternalStream(u).accumulate(G)},generateNodeStream:function(u,G){return(u=u||{}).type||(u.type="nodebuffer"),this.generateInternalStream(u).toNodejsStream(G)}};t.exports=w},{"./compressedObject":2,"./defaults":5,"./generate":9,"./nodejs/NodejsStreamInputAdapter":12,"./nodejsUtils":14,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31,"./utils":32,"./zipObject":35}],16:[function(e,t,o){t.exports=e("stream")},{stream:void 0}],17:[function(e,t,o){var B=e("./DataReader");function C(Q){B.call(this,Q);for(var i=0;i<this.data.length;i++)Q[i]=255&Q[i]}e("../utils").inherits(C,B),C.prototype.byteAt=function(Q){return this.data[this.zero+Q]},C.prototype.lastIndexOfSignature=function(Q){for(var i=Q.charCodeAt(0),E=Q.charCodeAt(1),n=Q.charCodeAt(2),s=Q.charCodeAt(3),r=this.length-4;0<=r;--r)if(this.data[r]===i&&this.data[r+1]===E&&this.data[r+2]===n&&this.data[r+3]===s)return r-this.zero;return-1},C.prototype.readAndCheckSignature=function(Q){var i=Q.charCodeAt(0),E=Q.charCodeAt(1),n=Q.charCodeAt(2),s=Q.charCodeAt(3),r=this.readData(4);return i===r[0]&&E===r[1]&&n===r[2]&&s===r[3]},C.prototype.readData=function(Q){if(this.checkOffset(Q),Q===0)return[];var i=this.data.slice(this.zero+this.index,this.zero+this.index+Q);return this.index+=Q,i},t.exports=C},{"../utils":32,"./DataReader":18}],18:[function(e,t,o){var B=e("../utils");function C(Q){this.data=Q,this.length=Q.length,this.index=0,this.zero=0}C.prototype={checkOffset:function(Q){this.checkIndex(this.index+Q)},checkIndex:function(Q){if(this.length<this.zero+Q||Q<0)throw new Error("End of data reached (data length = "+this.length+", asked index = "+Q+"). Corrupted zip ?")},setIndex:function(Q){this.checkIndex(Q),this.index=Q},skip:function(Q){this.setIndex(this.index+Q)},byteAt:function(){},readInt:function(Q){var i,E=0;for(this.checkOffset(Q),i=this.index+Q-1;i>=this.index;i--)E=(E<<8)+this.byteAt(i);return this.index+=Q,E},readString:function(Q){return B.transformTo("string",this.readData(Q))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var Q=this.readInt(4);return new Date(Date.UTC(1980+(Q>>25&127),(Q>>21&15)-1,Q>>16&31,Q>>11&31,Q>>5&63,(31&Q)<<1))}},t.exports=C},{"../utils":32}],19:[function(e,t,o){var B=e("./Uint8ArrayReader");function C(Q){B.call(this,Q)}e("../utils").inherits(C,B),C.prototype.readData=function(Q){this.checkOffset(Q);var i=this.data.slice(this.zero+this.index,this.zero+this.index+Q);return this.index+=Q,i},t.exports=C},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(e,t,o){var B=e("./DataReader");function C(Q){B.call(this,Q)}e("../utils").inherits(C,B),C.prototype.byteAt=function(Q){return this.data.charCodeAt(this.zero+Q)},C.prototype.lastIndexOfSignature=function(Q){return this.data.lastIndexOf(Q)-this.zero},C.prototype.readAndCheckSignature=function(Q){return Q===this.readData(4)},C.prototype.readData=function(Q){this.checkOffset(Q);var i=this.data.slice(this.zero+this.index,this.zero+this.index+Q);return this.index+=Q,i},t.exports=C},{"../utils":32,"./DataReader":18}],21:[function(e,t,o){var B=e("./ArrayReader");function C(Q){B.call(this,Q)}e("../utils").inherits(C,B),C.prototype.readData=function(Q){if(this.checkOffset(Q),Q===0)return new Uint8Array(0);var i=this.data.subarray(this.zero+this.index,this.zero+this.index+Q);return this.index+=Q,i},t.exports=C},{"../utils":32,"./ArrayReader":17}],22:[function(e,t,o){var B=e("../utils"),C=e("../support"),Q=e("./ArrayReader"),i=e("./StringReader"),E=e("./NodeBufferReader"),n=e("./Uint8ArrayReader");t.exports=function(s){var r=B.getTypeOf(s);return B.checkSupport(r),r!=="string"||C.uint8array?r==="nodebuffer"?new E(s):C.uint8array?new n(B.transformTo("uint8array",s)):new Q(B.transformTo("array",s)):new i(s)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(e,t,o){o.LOCAL_FILE_HEADER="PK",o.CENTRAL_FILE_HEADER="PK",o.CENTRAL_DIRECTORY_END="PK",o.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK\x07",o.ZIP64_CENTRAL_DIRECTORY_END="PK",o.DATA_DESCRIPTOR="PK\x07\b"},{}],24:[function(e,t,o){var B=e("./GenericWorker"),C=e("../utils");function Q(i){B.call(this,"ConvertWorker to "+i),this.destType=i}C.inherits(Q,B),Q.prototype.processChunk=function(i){this.push({data:C.transformTo(this.destType,i.data),meta:i.meta})},t.exports=Q},{"../utils":32,"./GenericWorker":28}],25:[function(e,t,o){var B=e("./GenericWorker"),C=e("../crc32");function Q(){B.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}e("../utils").inherits(Q,B),Q.prototype.processChunk=function(i){this.streamInfo.crc32=C(i.data,this.streamInfo.crc32||0),this.push(i)},t.exports=Q},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(e,t,o){var B=e("../utils"),C=e("./GenericWorker");function Q(i){C.call(this,"DataLengthProbe for "+i),this.propName=i,this.withStreamInfo(i,0)}B.inherits(Q,C),Q.prototype.processChunk=function(i){if(i){var E=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=E+i.data.length}C.prototype.processChunk.call(this,i)},t.exports=Q},{"../utils":32,"./GenericWorker":28}],27:[function(e,t,o){var B=e("../utils"),C=e("./GenericWorker");function Q(i){C.call(this,"DataWorker");var E=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,i.then(function(n){E.dataIsReady=!0,E.data=n,E.max=n&&n.length||0,E.type=B.getTypeOf(n),E.isPaused||E._tickAndRepeat()},function(n){E.error(n)})}B.inherits(Q,C),Q.prototype.cleanUp=function(){C.prototype.cleanUp.call(this),this.data=null},Q.prototype.resume=function(){return!!C.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,B.delay(this._tickAndRepeat,[],this)),!0)},Q.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(B.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},Q.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var i=null,E=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":i=this.data.substring(this.index,E);break;case"uint8array":i=this.data.subarray(this.index,E);break;case"array":case"nodebuffer":i=this.data.slice(this.index,E)}return this.index=E,this.push({data:i,meta:{percent:this.max?this.index/this.max*100:0}})},t.exports=Q},{"../utils":32,"./GenericWorker":28}],28:[function(e,t,o){function B(C){this.name=C||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}B.prototype={push:function(C){this.emit("data",C)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(C){this.emit("error",C)}return!0},error:function(C){return!this.isFinished&&(this.isPaused?this.generatedError=C:(this.isFinished=!0,this.emit("error",C),this.previous&&this.previous.error(C),this.cleanUp()),!0)},on:function(C,Q){return this._listeners[C].push(Q),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(C,Q){if(this._listeners[C])for(var i=0;i<this._listeners[C].length;i++)this._listeners[C][i].call(this,Q)},pipe:function(C){return C.registerPrevious(this)},registerPrevious:function(C){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.streamInfo=C.streamInfo,this.mergeStreamInfo(),this.previous=C;var Q=this;return C.on("data",function(i){Q.processChunk(i)}),C.on("end",function(){Q.end()}),C.on("error",function(i){Q.error(i)}),this},pause:function(){return!this.isPaused&&!this.isFinished&&(this.isPaused=!0,this.previous&&this.previous.pause(),!0)},resume:function(){if(!this.isPaused||this.isFinished)return!1;var C=this.isPaused=!1;return this.generatedError&&(this.error(this.generatedError),C=!0),this.previous&&this.previous.resume(),!C},flush:function(){},processChunk:function(C){this.push(C)},withStreamInfo:function(C,Q){return this.extraStreamInfo[C]=Q,this.mergeStreamInfo(),this},mergeStreamInfo:function(){for(var C in this.extraStreamInfo)Object.prototype.hasOwnProperty.call(this.extraStreamInfo,C)&&(this.streamInfo[C]=this.extraStreamInfo[C])},lock:function(){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.isLocked=!0,this.previous&&this.previous.lock()},toString:function(){var C="Worker "+this.name;return this.previous?this.previous+" -> "+C:C}},t.exports=B},{}],29:[function(e,t,o){var B=e("../utils"),C=e("./ConvertWorker"),Q=e("./GenericWorker"),i=e("../base64"),E=e("../support"),n=e("../external"),s=null;if(E.nodestream)try{s=e("../nodejs/NodejsStreamOutputAdapter")}catch{}function r(c,h){return new n.Promise(function(l,D){var d=[],y=c._internalType,w=c._outputType,u=c._mimeType;c.on("data",function(G,m){d.push(G),h&&h(m)}).on("error",function(G){d=[],D(G)}).on("end",function(){try{var G=(function(m,p,k){switch(m){case"blob":return B.newBlob(B.transformTo("arraybuffer",p),k);case"base64":return i.encode(p);default:return B.transformTo(m,p)}})(w,(function(m,p){var k,S=0,R=null,x=0;for(k=0;k<p.length;k++)x+=p[k].length;switch(m){case"string":return p.join("");case"array":return Array.prototype.concat.apply([],p);case"uint8array":for(R=new Uint8Array(x),k=0;k<p.length;k++)R.set(p[k],S),S+=p[k].length;return R;case"nodebuffer":return Buffer.concat(p);default:throw new Error("concat : unsupported type '"+m+"'")}})(y,d),u);l(G)}catch(m){D(m)}d=[]}).resume()})}function a(c,h,l){var D=h;switch(h){case"blob":case"arraybuffer":D="uint8array";break;case"base64":D="string"}try{this._internalType=D,this._outputType=h,this._mimeType=l,B.checkSupport(D),this._worker=c.pipe(new C(D)),c.lock()}catch(d){this._worker=new Q("error"),this._worker.error(d)}}a.prototype={accumulate:function(c){return r(this,c)},on:function(c,h){var l=this;return c==="data"?this._worker.on(c,function(D){h.call(l,D.data,D.meta)}):this._worker.on(c,function(){B.delay(h,arguments,l)}),this},resume:function(){return B.delay(this._worker.resume,[],this._worker),this},pause:function(){return this._worker.pause(),this},toNodejsStream:function(c){if(B.checkSupport("nodestream"),this._outputType!=="nodebuffer")throw new Error(this._outputType+" is not supported by this method");return new s(this,{objectMode:this._outputType!=="nodebuffer"},c)}},t.exports=a},{"../base64":1,"../external":6,"../nodejs/NodejsStreamOutputAdapter":13,"../support":30,"../utils":32,"./ConvertWorker":24,"./GenericWorker":28}],30:[function(e,t,o){if(o.base64=!0,o.array=!0,o.string=!0,o.arraybuffer=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u",o.nodebuffer=typeof Buffer<"u",o.uint8array=typeof Uint8Array<"u",typeof ArrayBuffer>"u")o.blob=!1;else{var B=new ArrayBuffer(0);try{o.blob=new Blob([B],{type:"application/zip"}).size===0}catch{try{var C=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);C.append(B),o.blob=C.getBlob("application/zip").size===0}catch{o.blob=!1}}}try{o.nodestream=!!e("readable-stream").Readable}catch{o.nodestream=!1}},{"readable-stream":16}],31:[function(e,t,o){for(var B=e("./utils"),C=e("./support"),Q=e("./nodejsUtils"),i=e("./stream/GenericWorker"),E=new Array(256),n=0;n<256;n++)E[n]=252<=n?6:248<=n?5:240<=n?4:224<=n?3:192<=n?2:1;E[254]=E[254]=1;function s(){i.call(this,"utf-8 decode"),this.leftOver=null}function r(){i.call(this,"utf-8 encode")}o.utf8encode=function(a){return C.nodebuffer?Q.newBufferFrom(a,"utf-8"):(function(c){var h,l,D,d,y,w=c.length,u=0;for(d=0;d<w;d++)(64512&(l=c.charCodeAt(d)))==55296&&d+1<w&&(64512&(D=c.charCodeAt(d+1)))==56320&&(l=65536+(l-55296<<10)+(D-56320),d++),u+=l<128?1:l<2048?2:l<65536?3:4;for(h=C.uint8array?new Uint8Array(u):new Array(u),d=y=0;y<u;d++)(64512&(l=c.charCodeAt(d)))==55296&&d+1<w&&(64512&(D=c.charCodeAt(d+1)))==56320&&(l=65536+(l-55296<<10)+(D-56320),d++),l<128?h[y++]=l:(l<2048?h[y++]=192|l>>>6:(l<65536?h[y++]=224|l>>>12:(h[y++]=240|l>>>18,h[y++]=128|l>>>12&63),h[y++]=128|l>>>6&63),h[y++]=128|63&l);return h})(a)},o.utf8decode=function(a){return C.nodebuffer?B.transformTo("nodebuffer",a).toString("utf-8"):(function(c){var h,l,D,d,y=c.length,w=new Array(2*y);for(h=l=0;h<y;)if((D=c[h++])<128)w[l++]=D;else if(4<(d=E[D]))w[l++]=65533,h+=d-1;else{for(D&=d===2?31:d===3?15:7;1<d&&h<y;)D=D<<6|63&c[h++],d--;1<d?w[l++]=65533:D<65536?w[l++]=D:(D-=65536,w[l++]=55296|D>>10&1023,w[l++]=56320|1023&D)}return w.length!==l&&(w.subarray?w=w.subarray(0,l):w.length=l),B.applyFromCharCode(w)})(a=B.transformTo(C.uint8array?"uint8array":"array",a))},B.inherits(s,i),s.prototype.processChunk=function(a){var c=B.transformTo(C.uint8array?"uint8array":"array",a.data);if(this.leftOver&&this.leftOver.length){if(C.uint8array){var h=c;(c=new Uint8Array(h.length+this.leftOver.length)).set(this.leftOver,0),c.set(h,this.leftOver.length)}else c=this.leftOver.concat(c);this.leftOver=null}var l=(function(d,y){var w;for((y=y||d.length)>d.length&&(y=d.length),w=y-1;0<=w&&(192&d[w])==128;)w--;return w<0||w===0?y:w+E[d[w]]>y?w:y})(c),D=c;l!==c.length&&(C.uint8array?(D=c.subarray(0,l),this.leftOver=c.subarray(l,c.length)):(D=c.slice(0,l),this.leftOver=c.slice(l,c.length))),this.push({data:o.utf8decode(D),meta:a.meta})},s.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:o.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},o.Utf8DecodeWorker=s,B.inherits(r,i),r.prototype.processChunk=function(a){this.push({data:o.utf8encode(a.data),meta:a.meta})},o.Utf8EncodeWorker=r},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(e,t,o){var B=e("./support"),C=e("./base64"),Q=e("./nodejsUtils"),i=e("./external");function E(h){return h}function n(h,l){for(var D=0;D<h.length;++D)l[D]=255&h.charCodeAt(D);return l}e("setimmediate"),o.newBlob=function(h,l){o.checkSupport("blob");try{return new Blob([h],{type:l})}catch{try{var D=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);return D.append(h),D.getBlob(l)}catch{throw new Error("Bug : can't construct the Blob.")}}};var s={stringifyByChunk:function(h,l,D){var d=[],y=0,w=h.length;if(w<=D)return String.fromCharCode.apply(null,h);for(;y<w;)l==="array"||l==="nodebuffer"?d.push(String.fromCharCode.apply(null,h.slice(y,Math.min(y+D,w)))):d.push(String.fromCharCode.apply(null,h.subarray(y,Math.min(y+D,w)))),y+=D;return d.join("")},stringifyByChar:function(h){for(var l="",D=0;D<h.length;D++)l+=String.fromCharCode(h[D]);return l},applyCanBeUsed:{uint8array:(function(){try{return B.uint8array&&String.fromCharCode.apply(null,new Uint8Array(1)).length===1}catch{return!1}})(),nodebuffer:(function(){try{return B.nodebuffer&&String.fromCharCode.apply(null,Q.allocBuffer(1)).length===1}catch{return!1}})()}};function r(h){var l=65536,D=o.getTypeOf(h),d=!0;if(D==="uint8array"?d=s.applyCanBeUsed.uint8array:D==="nodebuffer"&&(d=s.applyCanBeUsed.nodebuffer),d)for(;1<l;)try{return s.stringifyByChunk(h,D,l)}catch{l=Math.floor(l/2)}return s.stringifyByChar(h)}function a(h,l){for(var D=0;D<h.length;D++)l[D]=h[D];return l}o.applyFromCharCode=r;var c={};c.string={string:E,array:function(h){return n(h,new Array(h.length))},arraybuffer:function(h){return c.string.uint8array(h).buffer},uint8array:function(h){return n(h,new Uint8Array(h.length))},nodebuffer:function(h){return n(h,Q.allocBuffer(h.length))}},c.array={string:r,array:E,arraybuffer:function(h){return new Uint8Array(h).buffer},uint8array:function(h){return new Uint8Array(h)},nodebuffer:function(h){return Q.newBufferFrom(h)}},c.arraybuffer={string:function(h){return r(new Uint8Array(h))},array:function(h){return a(new Uint8Array(h),new Array(h.byteLength))},arraybuffer:E,uint8array:function(h){return new Uint8Array(h)},nodebuffer:function(h){return Q.newBufferFrom(new Uint8Array(h))}},c.uint8array={string:r,array:function(h){return a(h,new Array(h.length))},arraybuffer:function(h){return h.buffer},uint8array:E,nodebuffer:function(h){return Q.newBufferFrom(h)}},c.nodebuffer={string:r,array:function(h){return a(h,new Array(h.length))},arraybuffer:function(h){return c.nodebuffer.uint8array(h).buffer},uint8array:function(h){return a(h,new Uint8Array(h.length))},nodebuffer:E},o.transformTo=function(h,l){if(l=l||"",!h)return l;o.checkSupport(h);var D=o.getTypeOf(l);return c[D][h](l)},o.resolve=function(h){for(var l=h.split("/"),D=[],d=0;d<l.length;d++){var y=l[d];y==="."||y===""&&d!==0&&d!==l.length-1||(y===".."?D.pop():D.push(y))}return D.join("/")},o.getTypeOf=function(h){if(typeof h=="string")return"string";var l=Object.prototype.toString.call(h);return l==="[object Array]"?"array":B.nodebuffer&&Q.isBuffer(h)?"nodebuffer":B.uint8array&&l==="[object Uint8Array]"?"uint8array":B.arraybuffer&&l==="[object ArrayBuffer]"?"arraybuffer":void 0},o.checkSupport=function(h){if(!B[h.toLowerCase()])throw new Error(h+" is not supported by this platform")},o.MAX_VALUE_16BITS=65535,o.MAX_VALUE_32BITS=-1,o.pretty=function(h){var l,D,d="";for(D=0;D<(h||"").length;D++)d+="\\x"+((l=h.charCodeAt(D))<16?"0":"")+l.toString(16).toUpperCase();return d},o.delay=function(h,l,D){setImmediate(function(){h.apply(D||null,l||[])})},o.inherits=function(h,l){function D(){}D.prototype=l.prototype,h.prototype=new D},o.extend=function(){var h,l,D={};for(h=0;h<arguments.length;h++)for(l in arguments[h])Object.prototype.hasOwnProperty.call(arguments[h],l)&&D[l]===void 0&&(D[l]=arguments[h][l]);return D},o.prepareContent=function(h,l,D,d,y){return i.Promise.resolve(l).then(function(w){return B.blob&&(w instanceof Blob||["[object File]","[object Blob]"].indexOf(Object.prototype.toString.call(w))!==-1)?Blob.prototype.arrayBuffer!==void 0?w.arrayBuffer():typeof FileReader<"u"?new i.Promise(function(u,G){var m=new FileReader;m.onload=function(p){u(p.target.result)},m.onerror=function(p){G(p.target.error)},m.readAsArrayBuffer(w)}):i.Promise.reject(new Error(h+" is a Blob, but we have no way of reading it.")):w}).then(function(w){var u=o.getTypeOf(w);return u?(u==="arraybuffer"?w=o.transformTo("uint8array",w):u==="string"&&(y?w=C.decode(w):D&&d!==!0&&(w=(function(G){return n(G,B.uint8array?new Uint8Array(G.length):new Array(G.length))})(w))),w):i.Promise.reject(new Error("Can't read the data of '"+h+"'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"))})}},{"./base64":1,"./external":6,"./nodejsUtils":14,"./support":30,setimmediate:54}],33:[function(e,t,o){var B=e("./reader/readerFor"),C=e("./utils"),Q=e("./signature"),i=e("./zipEntry"),E=e("./support");function n(s){this.files=[],this.loadOptions=s}n.prototype={checkSignature:function(s){if(!this.reader.readAndCheckSignature(s)){this.reader.index-=4;var r=this.reader.readString(4);throw new Error("Corrupted zip or bug: unexpected signature ("+C.pretty(r)+", expected "+C.pretty(s)+")")}},isSignature:function(s,r){var a=this.reader.index;this.reader.setIndex(s);var c=this.reader.readString(4)===r;return this.reader.setIndex(a),c},readBlockEndOfCentral:function(){this.diskNumber=this.reader.readInt(2),this.diskWithCentralDirStart=this.reader.readInt(2),this.centralDirRecordsOnThisDisk=this.reader.readInt(2),this.centralDirRecords=this.reader.readInt(2),this.centralDirSize=this.reader.readInt(4),this.centralDirOffset=this.reader.readInt(4),this.zipCommentLength=this.reader.readInt(2);var s=this.reader.readData(this.zipCommentLength),r=E.uint8array?"uint8array":"array",a=C.transformTo(r,s);this.zipComment=this.loadOptions.decodeFileName(a)},readBlockZip64EndOfCentral:function(){this.zip64EndOfCentralSize=this.reader.readInt(8),this.reader.skip(4),this.diskNumber=this.reader.readInt(4),this.diskWithCentralDirStart=this.reader.readInt(4),this.centralDirRecordsOnThisDisk=this.reader.readInt(8),this.centralDirRecords=this.reader.readInt(8),this.centralDirSize=this.reader.readInt(8),this.centralDirOffset=this.reader.readInt(8),this.zip64ExtensibleData={};for(var s,r,a,c=this.zip64EndOfCentralSize-44;0<c;)s=this.reader.readInt(2),r=this.reader.readInt(4),a=this.reader.readData(r),this.zip64ExtensibleData[s]={id:s,length:r,value:a}},readBlockZip64EndOfCentralLocator:function(){if(this.diskWithZip64CentralDirStart=this.reader.readInt(4),this.relativeOffsetEndOfZip64CentralDir=this.reader.readInt(8),this.disksCount=this.reader.readInt(4),1<this.disksCount)throw new Error("Multi-volumes zip are not supported")},readLocalFiles:function(){var s,r;for(s=0;s<this.files.length;s++)r=this.files[s],this.reader.setIndex(r.localHeaderOffset),this.checkSignature(Q.LOCAL_FILE_HEADER),r.readLocalPart(this.reader),r.handleUTF8(),r.processAttributes()},readCentralDir:function(){var s;for(this.reader.setIndex(this.centralDirOffset);this.reader.readAndCheckSignature(Q.CENTRAL_FILE_HEADER);)(s=new i({zip64:this.zip64},this.loadOptions)).readCentralPart(this.reader),this.files.push(s);if(this.centralDirRecords!==this.files.length&&this.centralDirRecords!==0&&this.files.length===0)throw new Error("Corrupted zip or bug: expected "+this.centralDirRecords+" records in central dir, got "+this.files.length)},readEndOfCentral:function(){var s=this.reader.lastIndexOfSignature(Q.CENTRAL_DIRECTORY_END);if(s<0)throw this.isSignature(0,Q.LOCAL_FILE_HEADER)?new Error("Corrupted zip: can't find end of central directory"):new Error("Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html");this.reader.setIndex(s);var r=s;if(this.checkSignature(Q.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===C.MAX_VALUE_16BITS||this.diskWithCentralDirStart===C.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===C.MAX_VALUE_16BITS||this.centralDirRecords===C.MAX_VALUE_16BITS||this.centralDirSize===C.MAX_VALUE_32BITS||this.centralDirOffset===C.MAX_VALUE_32BITS){if(this.zip64=!0,(s=this.reader.lastIndexOfSignature(Q.ZIP64_CENTRAL_DIRECTORY_LOCATOR))<0)throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");if(this.reader.setIndex(s),this.checkSignature(Q.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),!this.isSignature(this.relativeOffsetEndOfZip64CentralDir,Q.ZIP64_CENTRAL_DIRECTORY_END)&&(this.relativeOffsetEndOfZip64CentralDir=this.reader.lastIndexOfSignature(Q.ZIP64_CENTRAL_DIRECTORY_END),this.relativeOffsetEndOfZip64CentralDir<0))throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(Q.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}var a=this.centralDirOffset+this.centralDirSize;this.zip64&&(a+=20,a+=12+this.zip64EndOfCentralSize);var c=r-a;if(0<c)this.isSignature(r,Q.CENTRAL_FILE_HEADER)||(this.reader.zero=c);else if(c<0)throw new Error("Corrupted zip: missing "+Math.abs(c)+" bytes.")},prepareReader:function(s){this.reader=B(s)},load:function(s){this.prepareReader(s),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},t.exports=n},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utils":32,"./zipEntry":34}],34:[function(e,t,o){var B=e("./reader/readerFor"),C=e("./utils"),Q=e("./compressedObject"),i=e("./crc32"),E=e("./utf8"),n=e("./compressions"),s=e("./support");function r(a,c){this.options=a,this.loadOptions=c}r.prototype={isEncrypted:function(){return(1&this.bitFlag)==1},useUTF8:function(){return(2048&this.bitFlag)==2048},readLocalPart:function(a){var c,h;if(a.skip(22),this.fileNameLength=a.readInt(2),h=a.readInt(2),this.fileName=a.readData(this.fileNameLength),a.skip(h),this.compressedSize===-1||this.uncompressedSize===-1)throw new Error("Bug or corrupted zip : didn't get enough information from the central directory (compressedSize === -1 || uncompressedSize === -1)");if((c=(function(l){for(var D in n)if(Object.prototype.hasOwnProperty.call(n,D)&&n[D].magic===l)return n[D];return null})(this.compressionMethod))===null)throw new Error("Corrupted zip : compression "+C.pretty(this.compressionMethod)+" unknown (inner file : "+C.transformTo("string",this.fileName)+")");this.decompressed=new Q(this.compressedSize,this.uncompressedSize,this.crc32,c,a.readData(this.compressedSize))},readCentralPart:function(a){this.versionMadeBy=a.readInt(2),a.skip(2),this.bitFlag=a.readInt(2),this.compressionMethod=a.readString(2),this.date=a.readDate(),this.crc32=a.readInt(4),this.compressedSize=a.readInt(4),this.uncompressedSize=a.readInt(4);var c=a.readInt(2);if(this.extraFieldsLength=a.readInt(2),this.fileCommentLength=a.readInt(2),this.diskNumberStart=a.readInt(2),this.internalFileAttributes=a.readInt(2),this.externalFileAttributes=a.readInt(4),this.localHeaderOffset=a.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");a.skip(c),this.readExtraFields(a),this.parseZIP64ExtraField(a),this.fileComment=a.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var a=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),a==0&&(this.dosPermissions=63&this.externalFileAttributes),a==3&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||this.fileNameStr.slice(-1)!=="/"||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var a=B(this.extraFields[1].value);this.uncompressedSize===C.MAX_VALUE_32BITS&&(this.uncompressedSize=a.readInt(8)),this.compressedSize===C.MAX_VALUE_32BITS&&(this.compressedSize=a.readInt(8)),this.localHeaderOffset===C.MAX_VALUE_32BITS&&(this.localHeaderOffset=a.readInt(8)),this.diskNumberStart===C.MAX_VALUE_32BITS&&(this.diskNumberStart=a.readInt(4))}},readExtraFields:function(a){var c,h,l,D=a.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});a.index+4<D;)c=a.readInt(2),h=a.readInt(2),l=a.readData(h),this.extraFields[c]={id:c,length:h,value:l};a.setIndex(D)},handleUTF8:function(){var a=s.uint8array?"uint8array":"array";if(this.useUTF8())this.fileNameStr=E.utf8decode(this.fileName),this.fileCommentStr=E.utf8decode(this.fileComment);else{var c=this.findExtraFieldUnicodePath();if(c!==null)this.fileNameStr=c;else{var h=C.transformTo(a,this.fileName);this.fileNameStr=this.loadOptions.decodeFileName(h)}var l=this.findExtraFieldUnicodeComment();if(l!==null)this.fileCommentStr=l;else{var D=C.transformTo(a,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(D)}}},findExtraFieldUnicodePath:function(){var a=this.extraFields[28789];if(a){var c=B(a.value);return c.readInt(1)!==1||i(this.fileName)!==c.readInt(4)?null:E.utf8decode(c.readData(a.length-5))}return null},findExtraFieldUnicodeComment:function(){var a=this.extraFields[25461];if(a){var c=B(a.value);return c.readInt(1)!==1||i(this.fileComment)!==c.readInt(4)?null:E.utf8decode(c.readData(a.length-5))}return null}},t.exports=r},{"./compressedObject":2,"./compressions":3,"./crc32":4,"./reader/readerFor":22,"./support":30,"./utf8":31,"./utils":32}],35:[function(e,t,o){function B(c,h,l){this.name=c,this.dir=l.dir,this.date=l.date,this.comment=l.comment,this.unixPermissions=l.unixPermissions,this.dosPermissions=l.dosPermissions,this._data=h,this._dataBinary=l.binary,this.options={compression:l.compression,compressionOptions:l.compressionOptions}}var C=e("./stream/StreamHelper"),Q=e("./stream/DataWorker"),i=e("./utf8"),E=e("./compressedObject"),n=e("./stream/GenericWorker");B.prototype={internalStream:function(c){var h=null,l="string";try{if(!c)throw new Error("No output type specified.");var D=(l=c.toLowerCase())==="string"||l==="text";l!=="binarystring"&&l!=="text"||(l="string"),h=this._decompressWorker();var d=!this._dataBinary;d&&!D&&(h=h.pipe(new i.Utf8EncodeWorker)),!d&&D&&(h=h.pipe(new i.Utf8DecodeWorker))}catch(y){(h=new n("error")).error(y)}return new C(h,l,"")},async:function(c,h){return this.internalStream(c).accumulate(h)},nodeStream:function(c,h){return this.internalStream(c||"nodebuffer").toNodejsStream(h)},_compressWorker:function(c,h){if(this._data instanceof E&&this._data.compression.magic===c.magic)return this._data.getCompressedWorker();var l=this._decompressWorker();return this._dataBinary||(l=l.pipe(new i.Utf8EncodeWorker)),E.createWorkerFrom(l,c,h)},_decompressWorker:function(){return this._data instanceof E?this._data.getContentWorker():this._data instanceof n?this._data:new Q(this._data)}};for(var s=["asText","asBinary","asNodeBuffer","asUint8Array","asArrayBuffer"],r=function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},a=0;a<s.length;a++)B.prototype[s[a]]=r;t.exports=B},{"./compressedObject":2,"./stream/DataWorker":27,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31}],36:[function(e,t,o){(function(B){var C,Q,i=B.MutationObserver||B.WebKitMutationObserver;if(i){var E=0,n=new i(c),s=B.document.createTextNode("");n.observe(s,{characterData:!0}),C=function(){s.data=E=++E%2}}else if(B.setImmediate||B.MessageChannel===void 0)C="document"in B&&"onreadystatechange"in B.document.createElement("script")?function(){var h=B.document.createElement("script");h.onreadystatechange=function(){c(),h.onreadystatechange=null,h.parentNode.removeChild(h),h=null},B.document.documentElement.appendChild(h)}:function(){setTimeout(c,0)};else{var r=new B.MessageChannel;r.port1.onmessage=c,C=function(){r.port2.postMessage(0)}}var a=[];function c(){var h,l;Q=!0;for(var D=a.length;D;){for(l=a,a=[],h=-1;++h<D;)l[h]();D=a.length}Q=!1}t.exports=function(h){a.push(h)!==1||Q||C()}}).call(this,typeof OL<"u"?OL:typeof self<"u"?self:typeof window<"u"?window:{})},{}],37:[function(e,t,o){var B=e("immediate");function C(){}var Q={},i=["REJECTED"],E=["FULFILLED"],n=["PENDING"];function s(D){if(typeof D!="function")throw new TypeError("resolver must be a function");this.state=n,this.queue=[],this.outcome=void 0,D!==C&&h(this,D)}function r(D,d,y){this.promise=D,typeof d=="function"&&(this.onFulfilled=d,this.callFulfilled=this.otherCallFulfilled),typeof y=="function"&&(this.onRejected=y,this.callRejected=this.otherCallRejected)}function a(D,d,y){B(function(){var w;try{w=d(y)}catch(u){return Q.reject(D,u)}w===D?Q.reject(D,new TypeError("Cannot resolve promise with itself")):Q.resolve(D,w)})}function c(D){var d=D&&D.then;if(D&&(typeof D=="object"||typeof D=="function")&&typeof d=="function")return function(){d.apply(D,arguments)}}function h(D,d){var y=!1;function w(m){y||(y=!0,Q.reject(D,m))}function u(m){y||(y=!0,Q.resolve(D,m))}var G=l(function(){d(u,w)});G.status==="error"&&w(G.value)}function l(D,d){var y={};try{y.value=D(d),y.status="success"}catch(w){y.status="error",y.value=w}return y}(t.exports=s).prototype.finally=function(D){if(typeof D!="function")return this;var d=this.constructor;return this.then(function(y){return d.resolve(D()).then(function(){return y})},function(y){return d.resolve(D()).then(function(){throw y})})},s.prototype.catch=function(D){return this.then(null,D)},s.prototype.then=function(D,d){if(typeof D!="function"&&this.state===E||typeof d!="function"&&this.state===i)return this;var y=new this.constructor(C);return this.state!==n?a(y,this.state===E?D:d,this.outcome):this.queue.push(new r(y,D,d)),y},r.prototype.callFulfilled=function(D){Q.resolve(this.promise,D)},r.prototype.otherCallFulfilled=function(D){a(this.promise,this.onFulfilled,D)},r.prototype.callRejected=function(D){Q.reject(this.promise,D)},r.prototype.otherCallRejected=function(D){a(this.promise,this.onRejected,D)},Q.resolve=function(D,d){var y=l(c,d);if(y.status==="error")return Q.reject(D,y.value);var w=y.value;if(w)h(D,w);else{D.state=E,D.outcome=d;for(var u=-1,G=D.queue.length;++u<G;)D.queue[u].callFulfilled(d)}return D},Q.reject=function(D,d){D.state=i,D.outcome=d;for(var y=-1,w=D.queue.length;++y<w;)D.queue[y].callRejected(d);return D},s.resolve=function(D){return D instanceof this?D:Q.resolve(new this(C),D)},s.reject=function(D){var d=new this(C);return Q.reject(d,D)},s.all=function(D){var d=this;if(Object.prototype.toString.call(D)!=="[object Array]")return this.reject(new TypeError("must be an array"));var y=D.length,w=!1;if(!y)return this.resolve([]);for(var u=new Array(y),G=0,m=-1,p=new this(C);++m<y;)k(D[m],m);return p;function k(S,R){d.resolve(S).then(function(x){u[R]=x,++G!==y||w||(w=!0,Q.resolve(p,u))},function(x){w||(w=!0,Q.reject(p,x))})}},s.race=function(D){var d=this;if(Object.prototype.toString.call(D)!=="[object Array]")return this.reject(new TypeError("must be an array"));var y=D.length,w=!1;if(!y)return this.resolve([]);for(var u=-1,G=new this(C);++u<y;)m=D[u],d.resolve(m).then(function(p){w||(w=!0,Q.resolve(G,p))},function(p){w||(w=!0,Q.reject(G,p))});var m;return G}},{immediate:36}],38:[function(e,t,o){var B={};(0,e("./lib/utils/common").assign)(B,e("./lib/deflate"),e("./lib/inflate"),e("./lib/zlib/constants")),t.exports=B},{"./lib/deflate":39,"./lib/inflate":40,"./lib/utils/common":41,"./lib/zlib/constants":44}],39:[function(e,t,o){var B=e("./zlib/deflate"),C=e("./utils/common"),Q=e("./utils/strings"),i=e("./zlib/messages"),E=e("./zlib/zstream"),n=Object.prototype.toString,s=0,r=-1,a=0,c=8;function h(D){if(!(this instanceof h))return new h(D);this.options=C.assign({level:r,method:c,chunkSize:16384,windowBits:15,memLevel:8,strategy:a,to:""},D||{});var d=this.options;d.raw&&0<d.windowBits?d.windowBits=-d.windowBits:d.gzip&&0<d.windowBits&&d.windowBits<16&&(d.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new E,this.strm.avail_out=0;var y=B.deflateInit2(this.strm,d.level,d.method,d.windowBits,d.memLevel,d.strategy);if(y!==s)throw new Error(i[y]);if(d.header&&B.deflateSetHeader(this.strm,d.header),d.dictionary){var w;if(w=typeof d.dictionary=="string"?Q.string2buf(d.dictionary):n.call(d.dictionary)==="[object ArrayBuffer]"?new Uint8Array(d.dictionary):d.dictionary,(y=B.deflateSetDictionary(this.strm,w))!==s)throw new Error(i[y]);this._dict_set=!0}}function l(D,d){var y=new h(d);if(y.push(D,!0),y.err)throw y.msg||i[y.err];return y.result}h.prototype.push=function(D,d){var y,w,u=this.strm,G=this.options.chunkSize;if(this.ended)return!1;w=d===~~d?d:d===!0?4:0,typeof D=="string"?u.input=Q.string2buf(D):n.call(D)==="[object ArrayBuffer]"?u.input=new Uint8Array(D):u.input=D,u.next_in=0,u.avail_in=u.input.length;do{if(u.avail_out===0&&(u.output=new C.Buf8(G),u.next_out=0,u.avail_out=G),(y=B.deflate(u,w))!==1&&y!==s)return this.onEnd(y),!(this.ended=!0);u.avail_out!==0&&(u.avail_in!==0||w!==4&&w!==2)||(this.options.to==="string"?this.onData(Q.buf2binstring(C.shrinkBuf(u.output,u.next_out))):this.onData(C.shrinkBuf(u.output,u.next_out)))}while((0<u.avail_in||u.avail_out===0)&&y!==1);return w===4?(y=B.deflateEnd(this.strm),this.onEnd(y),this.ended=!0,y===s):w!==2||(this.onEnd(s),!(u.avail_out=0))},h.prototype.onData=function(D){this.chunks.push(D)},h.prototype.onEnd=function(D){D===s&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=C.flattenChunks(this.chunks)),this.chunks=[],this.err=D,this.msg=this.strm.msg},o.Deflate=h,o.deflate=l,o.deflateRaw=function(D,d){return(d=d||{}).raw=!0,l(D,d)},o.gzip=function(D,d){return(d=d||{}).gzip=!0,l(D,d)}},{"./utils/common":41,"./utils/strings":42,"./zlib/deflate":46,"./zlib/messages":51,"./zlib/zstream":53}],40:[function(e,t,o){var B=e("./zlib/inflate"),C=e("./utils/common"),Q=e("./utils/strings"),i=e("./zlib/constants"),E=e("./zlib/messages"),n=e("./zlib/zstream"),s=e("./zlib/gzheader"),r=Object.prototype.toString;function a(h){if(!(this instanceof a))return new a(h);this.options=C.assign({chunkSize:16384,windowBits:0,to:""},h||{});var l=this.options;l.raw&&0<=l.windowBits&&l.windowBits<16&&(l.windowBits=-l.windowBits,l.windowBits===0&&(l.windowBits=-15)),!(0<=l.windowBits&&l.windowBits<16)||h&&h.windowBits||(l.windowBits+=32),15<l.windowBits&&l.windowBits<48&&(15&l.windowBits)==0&&(l.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new n,this.strm.avail_out=0;var D=B.inflateInit2(this.strm,l.windowBits);if(D!==i.Z_OK)throw new Error(E[D]);this.header=new s,B.inflateGetHeader(this.strm,this.header)}function c(h,l){var D=new a(l);if(D.push(h,!0),D.err)throw D.msg||E[D.err];return D.result}a.prototype.push=function(h,l){var D,d,y,w,u,G,m=this.strm,p=this.options.chunkSize,k=this.options.dictionary,S=!1;if(this.ended)return!1;d=l===~~l?l:l===!0?i.Z_FINISH:i.Z_NO_FLUSH,typeof h=="string"?m.input=Q.binstring2buf(h):r.call(h)==="[object ArrayBuffer]"?m.input=new Uint8Array(h):m.input=h,m.next_in=0,m.avail_in=m.input.length;do{if(m.avail_out===0&&(m.output=new C.Buf8(p),m.next_out=0,m.avail_out=p),(D=B.inflate(m,i.Z_NO_FLUSH))===i.Z_NEED_DICT&&k&&(G=typeof k=="string"?Q.string2buf(k):r.call(k)==="[object ArrayBuffer]"?new Uint8Array(k):k,D=B.inflateSetDictionary(this.strm,G)),D===i.Z_BUF_ERROR&&S===!0&&(D=i.Z_OK,S=!1),D!==i.Z_STREAM_END&&D!==i.Z_OK)return this.onEnd(D),!(this.ended=!0);m.next_out&&(m.avail_out!==0&&D!==i.Z_STREAM_END&&(m.avail_in!==0||d!==i.Z_FINISH&&d!==i.Z_SYNC_FLUSH)||(this.options.to==="string"?(y=Q.utf8border(m.output,m.next_out),w=m.next_out-y,u=Q.buf2string(m.output,y),m.next_out=w,m.avail_out=p-w,w&&C.arraySet(m.output,m.output,y,w,0),this.onData(u)):this.onData(C.shrinkBuf(m.output,m.next_out)))),m.avail_in===0&&m.avail_out===0&&(S=!0)}while((0<m.avail_in||m.avail_out===0)&&D!==i.Z_STREAM_END);return D===i.Z_STREAM_END&&(d=i.Z_FINISH),d===i.Z_FINISH?(D=B.inflateEnd(this.strm),this.onEnd(D),this.ended=!0,D===i.Z_OK):d!==i.Z_SYNC_FLUSH||(this.onEnd(i.Z_OK),!(m.avail_out=0))},a.prototype.onData=function(h){this.chunks.push(h)},a.prototype.onEnd=function(h){h===i.Z_OK&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=C.flattenChunks(this.chunks)),this.chunks=[],this.err=h,this.msg=this.strm.msg},o.Inflate=a,o.inflate=c,o.inflateRaw=function(h,l){return(l=l||{}).raw=!0,c(h,l)},o.ungzip=c},{"./utils/common":41,"./utils/strings":42,"./zlib/constants":44,"./zlib/gzheader":47,"./zlib/inflate":49,"./zlib/messages":51,"./zlib/zstream":53}],41:[function(e,t,o){var B=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Int32Array<"u";o.assign=function(i){for(var E=Array.prototype.slice.call(arguments,1);E.length;){var n=E.shift();if(n){if(typeof n!="object")throw new TypeError(n+"must be non-object");for(var s in n)n.hasOwnProperty(s)&&(i[s]=n[s])}}return i},o.shrinkBuf=function(i,E){return i.length===E?i:i.subarray?i.subarray(0,E):(i.length=E,i)};var C={arraySet:function(i,E,n,s,r){if(E.subarray&&i.subarray)i.set(E.subarray(n,n+s),r);else for(var a=0;a<s;a++)i[r+a]=E[n+a]},flattenChunks:function(i){var E,n,s,r,a,c;for(E=s=0,n=i.length;E<n;E++)s+=i[E].length;for(c=new Uint8Array(s),E=r=0,n=i.length;E<n;E++)a=i[E],c.set(a,r),r+=a.length;return c}},Q={arraySet:function(i,E,n,s,r){for(var a=0;a<s;a++)i[r+a]=E[n+a]},flattenChunks:function(i){return[].concat.apply([],i)}};o.setTyped=function(i){i?(o.Buf8=Uint8Array,o.Buf16=Uint16Array,o.Buf32=Int32Array,o.assign(o,C)):(o.Buf8=Array,o.Buf16=Array,o.Buf32=Array,o.assign(o,Q))},o.setTyped(B)},{}],42:[function(e,t,o){var B=e("./common"),C=!0,Q=!0;try{String.fromCharCode.apply(null,[0])}catch{C=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{Q=!1}for(var i=new B.Buf8(256),E=0;E<256;E++)i[E]=252<=E?6:248<=E?5:240<=E?4:224<=E?3:192<=E?2:1;function n(s,r){if(r<65537&&(s.subarray&&Q||!s.subarray&&C))return String.fromCharCode.apply(null,B.shrinkBuf(s,r));for(var a="",c=0;c<r;c++)a+=String.fromCharCode(s[c]);return a}i[254]=i[254]=1,o.string2buf=function(s){var r,a,c,h,l,D=s.length,d=0;for(h=0;h<D;h++)(64512&(a=s.charCodeAt(h)))==55296&&h+1<D&&(64512&(c=s.charCodeAt(h+1)))==56320&&(a=65536+(a-55296<<10)+(c-56320),h++),d+=a<128?1:a<2048?2:a<65536?3:4;for(r=new B.Buf8(d),h=l=0;l<d;h++)(64512&(a=s.charCodeAt(h)))==55296&&h+1<D&&(64512&(c=s.charCodeAt(h+1)))==56320&&(a=65536+(a-55296<<10)+(c-56320),h++),a<128?r[l++]=a:(a<2048?r[l++]=192|a>>>6:(a<65536?r[l++]=224|a>>>12:(r[l++]=240|a>>>18,r[l++]=128|a>>>12&63),r[l++]=128|a>>>6&63),r[l++]=128|63&a);return r},o.buf2binstring=function(s){return n(s,s.length)},o.binstring2buf=function(s){for(var r=new B.Buf8(s.length),a=0,c=r.length;a<c;a++)r[a]=s.charCodeAt(a);return r},o.buf2string=function(s,r){var a,c,h,l,D=r||s.length,d=new Array(2*D);for(a=c=0;a<D;)if((h=s[a++])<128)d[c++]=h;else if(4<(l=i[h]))d[c++]=65533,a+=l-1;else{for(h&=l===2?31:l===3?15:7;1<l&&a<D;)h=h<<6|63&s[a++],l--;1<l?d[c++]=65533:h<65536?d[c++]=h:(h-=65536,d[c++]=55296|h>>10&1023,d[c++]=56320|1023&h)}return n(d,c)},o.utf8border=function(s,r){var a;for((r=r||s.length)>s.length&&(r=s.length),a=r-1;0<=a&&(192&s[a])==128;)a--;return a<0||a===0?r:a+i[s[a]]>r?a:r}},{"./common":41}],43:[function(e,t,o){t.exports=function(B,C,Q,i){for(var E=65535&B|0,n=B>>>16&65535|0,s=0;Q!==0;){for(Q-=s=2e3<Q?2e3:Q;n=n+(E=E+C[i++]|0)|0,--s;);E%=65521,n%=65521}return E|n<<16|0}},{}],44:[function(e,t,o){t.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],45:[function(e,t,o){var B=(function(){for(var C,Q=[],i=0;i<256;i++){C=i;for(var E=0;E<8;E++)C=1&C?3988292384^C>>>1:C>>>1;Q[i]=C}return Q})();t.exports=function(C,Q,i,E){var n=B,s=E+i;C^=-1;for(var r=E;r<s;r++)C=C>>>8^n[255&(C^Q[r])];return-1^C}},{}],46:[function(e,t,o){var B,C=e("../utils/common"),Q=e("./trees"),i=e("./adler32"),E=e("./crc32"),n=e("./messages"),s=0,r=4,a=0,c=-2,h=-1,l=4,D=2,d=8,y=9,w=286,u=30,G=19,m=2*w+1,p=15,k=3,S=258,R=S+k+1,x=42,N=113,J=1,K=2,_=3,H=4;function T(aA,FA){return aA.msg=n[FA],FA}function j(aA){return(aA<<1)-(4<aA?9:0)}function W(aA){for(var FA=aA.length;0<=--FA;)aA[FA]=0}function O(aA){var FA=aA.state,NA=FA.pending;NA>aA.avail_out&&(NA=aA.avail_out),NA!==0&&(C.arraySet(aA.output,FA.pending_buf,FA.pending_out,NA,aA.next_out),aA.next_out+=NA,FA.pending_out+=NA,aA.total_out+=NA,aA.avail_out-=NA,FA.pending-=NA,FA.pending===0&&(FA.pending_out=0))}function gA(aA,FA){Q._tr_flush_block(aA,0<=aA.block_start?aA.block_start:-1,aA.strstart-aA.block_start,FA),aA.block_start=aA.strstart,O(aA.strm)}function tA(aA,FA){aA.pending_buf[aA.pending++]=FA}function IA(aA,FA){aA.pending_buf[aA.pending++]=FA>>>8&255,aA.pending_buf[aA.pending++]=255&FA}function QA(aA,FA){var NA,RA,JA=aA.max_chain_length,PA=aA.strstart,pA=aA.prev_length,YA=aA.nice_match,dA=aA.strstart>aA.w_size-R?aA.strstart-(aA.w_size-R):0,HA=aA.window,WA=aA.w_mask,Qg=aA.prev,_A=aA.strstart+S,GA=HA[PA+pA-1],kA=HA[PA+pA];aA.prev_length>=aA.good_match&&(JA>>=2),YA>aA.lookahead&&(YA=aA.lookahead);do if(HA[(NA=FA)+pA]===kA&&HA[NA+pA-1]===GA&&HA[NA]===HA[PA]&&HA[++NA]===HA[PA+1]){PA+=2,NA++;do;while(HA[++PA]===HA[++NA]&&HA[++PA]===HA[++NA]&&HA[++PA]===HA[++NA]&&HA[++PA]===HA[++NA]&&HA[++PA]===HA[++NA]&&HA[++PA]===HA[++NA]&&HA[++PA]===HA[++NA]&&HA[++PA]===HA[++NA]&&PA<_A);if(RA=S-(_A-PA),PA=_A-S,pA<RA){if(aA.match_start=FA,YA<=(pA=RA))break;GA=HA[PA+pA-1],kA=HA[PA+pA]}}while((FA=Qg[FA&WA])>dA&&--JA!=0);return pA<=aA.lookahead?pA:aA.lookahead}function nA(aA){var FA,NA,RA,JA,PA,pA,YA,dA,HA,WA,Qg=aA.w_size;do{if(JA=aA.window_size-aA.lookahead-aA.strstart,aA.strstart>=Qg+(Qg-R)){for(C.arraySet(aA.window,aA.window,Qg,Qg,0),aA.match_start-=Qg,aA.strstart-=Qg,aA.block_start-=Qg,FA=NA=aA.hash_size;RA=aA.head[--FA],aA.head[FA]=Qg<=RA?RA-Qg:0,--NA;);for(FA=NA=Qg;RA=aA.prev[--FA],aA.prev[FA]=Qg<=RA?RA-Qg:0,--NA;);JA+=Qg}if(aA.strm.avail_in===0)break;if(pA=aA.strm,YA=aA.window,dA=aA.strstart+aA.lookahead,HA=JA,WA=void 0,WA=pA.avail_in,HA<WA&&(WA=HA),NA=WA===0?0:(pA.avail_in-=WA,C.arraySet(YA,pA.input,pA.next_in,WA,dA),pA.state.wrap===1?pA.adler=i(pA.adler,YA,WA,dA):pA.state.wrap===2&&(pA.adler=E(pA.adler,YA,WA,dA)),pA.next_in+=WA,pA.total_in+=WA,WA),aA.lookahead+=NA,aA.lookahead+aA.insert>=k)for(PA=aA.strstart-aA.insert,aA.ins_h=aA.window[PA],aA.ins_h=(aA.ins_h<<aA.hash_shift^aA.window[PA+1])&aA.hash_mask;aA.insert&&(aA.ins_h=(aA.ins_h<<aA.hash_shift^aA.window[PA+k-1])&aA.hash_mask,aA.prev[PA&aA.w_mask]=aA.head[aA.ins_h],aA.head[aA.ins_h]=PA,PA++,aA.insert--,!(aA.lookahead+aA.insert<k)););}while(aA.lookahead<R&&aA.strm.avail_in!==0)}function DA(aA,FA){for(var NA,RA;;){if(aA.lookahead<R){if(nA(aA),aA.lookahead<R&&FA===s)return J;if(aA.lookahead===0)break}if(NA=0,aA.lookahead>=k&&(aA.ins_h=(aA.ins_h<<aA.hash_shift^aA.window[aA.strstart+k-1])&aA.hash_mask,NA=aA.prev[aA.strstart&aA.w_mask]=aA.head[aA.ins_h],aA.head[aA.ins_h]=aA.strstart),NA!==0&&aA.strstart-NA<=aA.w_size-R&&(aA.match_length=QA(aA,NA)),aA.match_length>=k)if(RA=Q._tr_tally(aA,aA.strstart-aA.match_start,aA.match_length-k),aA.lookahead-=aA.match_length,aA.match_length<=aA.max_lazy_match&&aA.lookahead>=k){for(aA.match_length--;aA.strstart++,aA.ins_h=(aA.ins_h<<aA.hash_shift^aA.window[aA.strstart+k-1])&aA.hash_mask,NA=aA.prev[aA.strstart&aA.w_mask]=aA.head[aA.ins_h],aA.head[aA.ins_h]=aA.strstart,--aA.match_length!=0;);aA.strstart++}else aA.strstart+=aA.match_length,aA.match_length=0,aA.ins_h=aA.window[aA.strstart],aA.ins_h=(aA.ins_h<<aA.hash_shift^aA.window[aA.strstart+1])&aA.hash_mask;else RA=Q._tr_tally(aA,0,aA.window[aA.strstart]),aA.lookahead--,aA.strstart++;if(RA&&(gA(aA,!1),aA.strm.avail_out===0))return J}return aA.insert=aA.strstart<k-1?aA.strstart:k-1,FA===r?(gA(aA,!0),aA.strm.avail_out===0?_:H):aA.last_lit&&(gA(aA,!1),aA.strm.avail_out===0)?J:K}function CA(aA,FA){for(var NA,RA,JA;;){if(aA.lookahead<R){if(nA(aA),aA.lookahead<R&&FA===s)return J;if(aA.lookahead===0)break}if(NA=0,aA.lookahead>=k&&(aA.ins_h=(aA.ins_h<<aA.hash_shift^aA.window[aA.strstart+k-1])&aA.hash_mask,NA=aA.prev[aA.strstart&aA.w_mask]=aA.head[aA.ins_h],aA.head[aA.ins_h]=aA.strstart),aA.prev_length=aA.match_length,aA.prev_match=aA.match_start,aA.match_length=k-1,NA!==0&&aA.prev_length<aA.max_lazy_match&&aA.strstart-NA<=aA.w_size-R&&(aA.match_length=QA(aA,NA),aA.match_length<=5&&(aA.strategy===1||aA.match_length===k&&4096<aA.strstart-aA.match_start)&&(aA.match_length=k-1)),aA.prev_length>=k&&aA.match_length<=aA.prev_length){for(JA=aA.strstart+aA.lookahead-k,RA=Q._tr_tally(aA,aA.strstart-1-aA.prev_match,aA.prev_length-k),aA.lookahead-=aA.prev_length-1,aA.prev_length-=2;++aA.strstart<=JA&&(aA.ins_h=(aA.ins_h<<aA.hash_shift^aA.window[aA.strstart+k-1])&aA.hash_mask,NA=aA.prev[aA.strstart&aA.w_mask]=aA.head[aA.ins_h],aA.head[aA.ins_h]=aA.strstart),--aA.prev_length!=0;);if(aA.match_available=0,aA.match_length=k-1,aA.strstart++,RA&&(gA(aA,!1),aA.strm.avail_out===0))return J}else if(aA.match_available){if((RA=Q._tr_tally(aA,0,aA.window[aA.strstart-1]))&&gA(aA,!1),aA.strstart++,aA.lookahead--,aA.strm.avail_out===0)return J}else aA.match_available=1,aA.strstart++,aA.lookahead--}return aA.match_available&&(RA=Q._tr_tally(aA,0,aA.window[aA.strstart-1]),aA.match_available=0),aA.insert=aA.strstart<k-1?aA.strstart:k-1,FA===r?(gA(aA,!0),aA.strm.avail_out===0?_:H):aA.last_lit&&(gA(aA,!1),aA.strm.avail_out===0)?J:K}function hA(aA,FA,NA,RA,JA){this.good_length=aA,this.max_lazy=FA,this.nice_length=NA,this.max_chain=RA,this.func=JA}function sA(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=d,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new C.Buf16(2*m),this.dyn_dtree=new C.Buf16(2*(2*u+1)),this.bl_tree=new C.Buf16(2*(2*G+1)),W(this.dyn_ltree),W(this.dyn_dtree),W(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new C.Buf16(p+1),this.heap=new C.Buf16(2*w+1),W(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new C.Buf16(2*w+1),W(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function cA(aA){var FA;return aA&&aA.state?(aA.total_in=aA.total_out=0,aA.data_type=D,(FA=aA.state).pending=0,FA.pending_out=0,FA.wrap<0&&(FA.wrap=-FA.wrap),FA.status=FA.wrap?x:N,aA.adler=FA.wrap===2?0:1,FA.last_flush=s,Q._tr_init(FA),a):T(aA,c)}function SA(aA){var FA=cA(aA);return FA===a&&(function(NA){NA.window_size=2*NA.w_size,W(NA.head),NA.max_lazy_match=B[NA.level].max_lazy,NA.good_match=B[NA.level].good_length,NA.nice_match=B[NA.level].nice_length,NA.max_chain_length=B[NA.level].max_chain,NA.strstart=0,NA.block_start=0,NA.lookahead=0,NA.insert=0,NA.match_length=NA.prev_length=k-1,NA.match_available=0,NA.ins_h=0})(aA.state),FA}function xA(aA,FA,NA,RA,JA,PA){if(!aA)return c;var pA=1;if(FA===h&&(FA=6),RA<0?(pA=0,RA=-RA):15<RA&&(pA=2,RA-=16),JA<1||y<JA||NA!==d||RA<8||15<RA||FA<0||9<FA||PA<0||l<PA)return T(aA,c);RA===8&&(RA=9);var YA=new sA;return(aA.state=YA).strm=aA,YA.wrap=pA,YA.gzhead=null,YA.w_bits=RA,YA.w_size=1<<YA.w_bits,YA.w_mask=YA.w_size-1,YA.hash_bits=JA+7,YA.hash_size=1<<YA.hash_bits,YA.hash_mask=YA.hash_size-1,YA.hash_shift=~~((YA.hash_bits+k-1)/k),YA.window=new C.Buf8(2*YA.w_size),YA.head=new C.Buf16(YA.hash_size),YA.prev=new C.Buf16(YA.w_size),YA.lit_bufsize=1<<JA+6,YA.pending_buf_size=4*YA.lit_bufsize,YA.pending_buf=new C.Buf8(YA.pending_buf_size),YA.d_buf=1*YA.lit_bufsize,YA.l_buf=3*YA.lit_bufsize,YA.level=FA,YA.strategy=PA,YA.method=NA,SA(aA)}B=[new hA(0,0,0,0,function(aA,FA){var NA=65535;for(NA>aA.pending_buf_size-5&&(NA=aA.pending_buf_size-5);;){if(aA.lookahead<=1){if(nA(aA),aA.lookahead===0&&FA===s)return J;if(aA.lookahead===0)break}aA.strstart+=aA.lookahead,aA.lookahead=0;var RA=aA.block_start+NA;if((aA.strstart===0||aA.strstart>=RA)&&(aA.lookahead=aA.strstart-RA,aA.strstart=RA,gA(aA,!1),aA.strm.avail_out===0)||aA.strstart-aA.block_start>=aA.w_size-R&&(gA(aA,!1),aA.strm.avail_out===0))return J}return aA.insert=0,FA===r?(gA(aA,!0),aA.strm.avail_out===0?_:H):(aA.strstart>aA.block_start&&(gA(aA,!1),aA.strm.avail_out),J)}),new hA(4,4,8,4,DA),new hA(4,5,16,8,DA),new hA(4,6,32,32,DA),new hA(4,4,16,16,CA),new hA(8,16,32,32,CA),new hA(8,16,128,128,CA),new hA(8,32,128,256,CA),new hA(32,128,258,1024,CA),new hA(32,258,258,4096,CA)],o.deflateInit=function(aA,FA){return xA(aA,FA,d,15,8,0)},o.deflateInit2=xA,o.deflateReset=SA,o.deflateResetKeep=cA,o.deflateSetHeader=function(aA,FA){return aA&&aA.state?aA.state.wrap!==2?c:(aA.state.gzhead=FA,a):c},o.deflate=function(aA,FA){var NA,RA,JA,PA;if(!aA||!aA.state||5<FA||FA<0)return aA?T(aA,c):c;if(RA=aA.state,!aA.output||!aA.input&&aA.avail_in!==0||RA.status===666&&FA!==r)return T(aA,aA.avail_out===0?-5:c);if(RA.strm=aA,NA=RA.last_flush,RA.last_flush=FA,RA.status===x)if(RA.wrap===2)aA.adler=0,tA(RA,31),tA(RA,139),tA(RA,8),RA.gzhead?(tA(RA,(RA.gzhead.text?1:0)+(RA.gzhead.hcrc?2:0)+(RA.gzhead.extra?4:0)+(RA.gzhead.name?8:0)+(RA.gzhead.comment?16:0)),tA(RA,255&RA.gzhead.time),tA(RA,RA.gzhead.time>>8&255),tA(RA,RA.gzhead.time>>16&255),tA(RA,RA.gzhead.time>>24&255),tA(RA,RA.level===9?2:2<=RA.strategy||RA.level<2?4:0),tA(RA,255&RA.gzhead.os),RA.gzhead.extra&&RA.gzhead.extra.length&&(tA(RA,255&RA.gzhead.extra.length),tA(RA,RA.gzhead.extra.length>>8&255)),RA.gzhead.hcrc&&(aA.adler=E(aA.adler,RA.pending_buf,RA.pending,0)),RA.gzindex=0,RA.status=69):(tA(RA,0),tA(RA,0),tA(RA,0),tA(RA,0),tA(RA,0),tA(RA,RA.level===9?2:2<=RA.strategy||RA.level<2?4:0),tA(RA,3),RA.status=N);else{var pA=d+(RA.w_bits-8<<4)<<8;pA|=(2<=RA.strategy||RA.level<2?0:RA.level<6?1:RA.level===6?2:3)<<6,RA.strstart!==0&&(pA|=32),pA+=31-pA%31,RA.status=N,IA(RA,pA),RA.strstart!==0&&(IA(RA,aA.adler>>>16),IA(RA,65535&aA.adler)),aA.adler=1}if(RA.status===69)if(RA.gzhead.extra){for(JA=RA.pending;RA.gzindex<(65535&RA.gzhead.extra.length)&&(RA.pending!==RA.pending_buf_size||(RA.gzhead.hcrc&&RA.pending>JA&&(aA.adler=E(aA.adler,RA.pending_buf,RA.pending-JA,JA)),O(aA),JA=RA.pending,RA.pending!==RA.pending_buf_size));)tA(RA,255&RA.gzhead.extra[RA.gzindex]),RA.gzindex++;RA.gzhead.hcrc&&RA.pending>JA&&(aA.adler=E(aA.adler,RA.pending_buf,RA.pending-JA,JA)),RA.gzindex===RA.gzhead.extra.length&&(RA.gzindex=0,RA.status=73)}else RA.status=73;if(RA.status===73)if(RA.gzhead.name){JA=RA.pending;do{if(RA.pending===RA.pending_buf_size&&(RA.gzhead.hcrc&&RA.pending>JA&&(aA.adler=E(aA.adler,RA.pending_buf,RA.pending-JA,JA)),O(aA),JA=RA.pending,RA.pending===RA.pending_buf_size)){PA=1;break}PA=RA.gzindex<RA.gzhead.name.length?255&RA.gzhead.name.charCodeAt(RA.gzindex++):0,tA(RA,PA)}while(PA!==0);RA.gzhead.hcrc&&RA.pending>JA&&(aA.adler=E(aA.adler,RA.pending_buf,RA.pending-JA,JA)),PA===0&&(RA.gzindex=0,RA.status=91)}else RA.status=91;if(RA.status===91)if(RA.gzhead.comment){JA=RA.pending;do{if(RA.pending===RA.pending_buf_size&&(RA.gzhead.hcrc&&RA.pending>JA&&(aA.adler=E(aA.adler,RA.pending_buf,RA.pending-JA,JA)),O(aA),JA=RA.pending,RA.pending===RA.pending_buf_size)){PA=1;break}PA=RA.gzindex<RA.gzhead.comment.length?255&RA.gzhead.comment.charCodeAt(RA.gzindex++):0,tA(RA,PA)}while(PA!==0);RA.gzhead.hcrc&&RA.pending>JA&&(aA.adler=E(aA.adler,RA.pending_buf,RA.pending-JA,JA)),PA===0&&(RA.status=103)}else RA.status=103;if(RA.status===103&&(RA.gzhead.hcrc?(RA.pending+2>RA.pending_buf_size&&O(aA),RA.pending+2<=RA.pending_buf_size&&(tA(RA,255&aA.adler),tA(RA,aA.adler>>8&255),aA.adler=0,RA.status=N)):RA.status=N),RA.pending!==0){if(O(aA),aA.avail_out===0)return RA.last_flush=-1,a}else if(aA.avail_in===0&&j(FA)<=j(NA)&&FA!==r)return T(aA,-5);if(RA.status===666&&aA.avail_in!==0)return T(aA,-5);if(aA.avail_in!==0||RA.lookahead!==0||FA!==s&&RA.status!==666){var YA=RA.strategy===2?(function(dA,HA){for(var WA;;){if(dA.lookahead===0&&(nA(dA),dA.lookahead===0)){if(HA===s)return J;break}if(dA.match_length=0,WA=Q._tr_tally(dA,0,dA.window[dA.strstart]),dA.lookahead--,dA.strstart++,WA&&(gA(dA,!1),dA.strm.avail_out===0))return J}return dA.insert=0,HA===r?(gA(dA,!0),dA.strm.avail_out===0?_:H):dA.last_lit&&(gA(dA,!1),dA.strm.avail_out===0)?J:K})(RA,FA):RA.strategy===3?(function(dA,HA){for(var WA,Qg,_A,GA,kA=dA.window;;){if(dA.lookahead<=S){if(nA(dA),dA.lookahead<=S&&HA===s)return J;if(dA.lookahead===0)break}if(dA.match_length=0,dA.lookahead>=k&&0<dA.strstart&&(Qg=kA[_A=dA.strstart-1])===kA[++_A]&&Qg===kA[++_A]&&Qg===kA[++_A]){GA=dA.strstart+S;do;while(Qg===kA[++_A]&&Qg===kA[++_A]&&Qg===kA[++_A]&&Qg===kA[++_A]&&Qg===kA[++_A]&&Qg===kA[++_A]&&Qg===kA[++_A]&&Qg===kA[++_A]&&_A<GA);dA.match_length=S-(GA-_A),dA.match_length>dA.lookahead&&(dA.match_length=dA.lookahead)}if(dA.match_length>=k?(WA=Q._tr_tally(dA,1,dA.match_length-k),dA.lookahead-=dA.match_length,dA.strstart+=dA.match_length,dA.match_length=0):(WA=Q._tr_tally(dA,0,dA.window[dA.strstart]),dA.lookahead--,dA.strstart++),WA&&(gA(dA,!1),dA.strm.avail_out===0))return J}return dA.insert=0,HA===r?(gA(dA,!0),dA.strm.avail_out===0?_:H):dA.last_lit&&(gA(dA,!1),dA.strm.avail_out===0)?J:K})(RA,FA):B[RA.level].func(RA,FA);if(YA!==_&&YA!==H||(RA.status=666),YA===J||YA===_)return aA.avail_out===0&&(RA.last_flush=-1),a;if(YA===K&&(FA===1?Q._tr_align(RA):FA!==5&&(Q._tr_stored_block(RA,0,0,!1),FA===3&&(W(RA.head),RA.lookahead===0&&(RA.strstart=0,RA.block_start=0,RA.insert=0))),O(aA),aA.avail_out===0))return RA.last_flush=-1,a}return FA!==r?a:RA.wrap<=0?1:(RA.wrap===2?(tA(RA,255&aA.adler),tA(RA,aA.adler>>8&255),tA(RA,aA.adler>>16&255),tA(RA,aA.adler>>24&255),tA(RA,255&aA.total_in),tA(RA,aA.total_in>>8&255),tA(RA,aA.total_in>>16&255),tA(RA,aA.total_in>>24&255)):(IA(RA,aA.adler>>>16),IA(RA,65535&aA.adler)),O(aA),0<RA.wrap&&(RA.wrap=-RA.wrap),RA.pending!==0?a:1)},o.deflateEnd=function(aA){var FA;return aA&&aA.state?(FA=aA.state.status)!==x&&FA!==69&&FA!==73&&FA!==91&&FA!==103&&FA!==N&&FA!==666?T(aA,c):(aA.state=null,FA===N?T(aA,-3):a):c},o.deflateSetDictionary=function(aA,FA){var NA,RA,JA,PA,pA,YA,dA,HA,WA=FA.length;if(!aA||!aA.state||(PA=(NA=aA.state).wrap)===2||PA===1&&NA.status!==x||NA.lookahead)return c;for(PA===1&&(aA.adler=i(aA.adler,FA,WA,0)),NA.wrap=0,WA>=NA.w_size&&(PA===0&&(W(NA.head),NA.strstart=0,NA.block_start=0,NA.insert=0),HA=new C.Buf8(NA.w_size),C.arraySet(HA,FA,WA-NA.w_size,NA.w_size,0),FA=HA,WA=NA.w_size),pA=aA.avail_in,YA=aA.next_in,dA=aA.input,aA.avail_in=WA,aA.next_in=0,aA.input=FA,nA(NA);NA.lookahead>=k;){for(RA=NA.strstart,JA=NA.lookahead-(k-1);NA.ins_h=(NA.ins_h<<NA.hash_shift^NA.window[RA+k-1])&NA.hash_mask,NA.prev[RA&NA.w_mask]=NA.head[NA.ins_h],NA.head[NA.ins_h]=RA,RA++,--JA;);NA.strstart=RA,NA.lookahead=k-1,nA(NA)}return NA.strstart+=NA.lookahead,NA.block_start=NA.strstart,NA.insert=NA.lookahead,NA.lookahead=0,NA.match_length=NA.prev_length=k-1,NA.match_available=0,aA.next_in=YA,aA.input=dA,aA.avail_in=pA,NA.wrap=PA,a},o.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./messages":51,"./trees":52}],47:[function(e,t,o){t.exports=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}},{}],48:[function(e,t,o){t.exports=function(B,C){var Q,i,E,n,s,r,a,c,h,l,D,d,y,w,u,G,m,p,k,S,R,x,N,J,K;Q=B.state,i=B.next_in,J=B.input,E=i+(B.avail_in-5),n=B.next_out,K=B.output,s=n-(C-B.avail_out),r=n+(B.avail_out-257),a=Q.dmax,c=Q.wsize,h=Q.whave,l=Q.wnext,D=Q.window,d=Q.hold,y=Q.bits,w=Q.lencode,u=Q.distcode,G=(1<<Q.lenbits)-1,m=(1<<Q.distbits)-1;A:do{y<15&&(d+=J[i++]<<y,y+=8,d+=J[i++]<<y,y+=8),p=w[d&G];g:for(;;){if(d>>>=k=p>>>24,y-=k,(k=p>>>16&255)===0)K[n++]=65535&p;else{if(!(16&k)){if((64&k)==0){p=w[(65535&p)+(d&(1<<k)-1)];continue g}if(32&k){Q.mode=12;break A}B.msg="invalid literal/length code",Q.mode=30;break A}S=65535&p,(k&=15)&&(y<k&&(d+=J[i++]<<y,y+=8),S+=d&(1<<k)-1,d>>>=k,y-=k),y<15&&(d+=J[i++]<<y,y+=8,d+=J[i++]<<y,y+=8),p=u[d&m];I:for(;;){if(d>>>=k=p>>>24,y-=k,!(16&(k=p>>>16&255))){if((64&k)==0){p=u[(65535&p)+(d&(1<<k)-1)];continue I}B.msg="invalid distance code",Q.mode=30;break A}if(R=65535&p,y<(k&=15)&&(d+=J[i++]<<y,(y+=8)<k&&(d+=J[i++]<<y,y+=8)),a<(R+=d&(1<<k)-1)){B.msg="invalid distance too far back",Q.mode=30;break A}if(d>>>=k,y-=k,(k=n-s)<R){if(h<(k=R-k)&&Q.sane){B.msg="invalid distance too far back",Q.mode=30;break A}if(N=D,(x=0)===l){if(x+=c-k,k<S){for(S-=k;K[n++]=D[x++],--k;);x=n-R,N=K}}else if(l<k){if(x+=c+l-k,(k-=l)<S){for(S-=k;K[n++]=D[x++],--k;);if(x=0,l<S){for(S-=k=l;K[n++]=D[x++],--k;);x=n-R,N=K}}}else if(x+=l-k,k<S){for(S-=k;K[n++]=D[x++],--k;);x=n-R,N=K}for(;2<S;)K[n++]=N[x++],K[n++]=N[x++],K[n++]=N[x++],S-=3;S&&(K[n++]=N[x++],1<S&&(K[n++]=N[x++]))}else{for(x=n-R;K[n++]=K[x++],K[n++]=K[x++],K[n++]=K[x++],2<(S-=3););S&&(K[n++]=K[x++],1<S&&(K[n++]=K[x++]))}break}}break}}while(i<E&&n<r);i-=S=y>>3,d&=(1<<(y-=S<<3))-1,B.next_in=i,B.next_out=n,B.avail_in=i<E?E-i+5:5-(i-E),B.avail_out=n<r?r-n+257:257-(n-r),Q.hold=d,Q.bits=y}},{}],49:[function(e,t,o){var B=e("../utils/common"),C=e("./adler32"),Q=e("./crc32"),i=e("./inffast"),E=e("./inftrees"),n=1,s=2,r=0,a=-2,c=1,h=852,l=592;function D(x){return(x>>>24&255)+(x>>>8&65280)+((65280&x)<<8)+((255&x)<<24)}function d(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new B.Buf16(320),this.work=new B.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function y(x){var N;return x&&x.state?(N=x.state,x.total_in=x.total_out=N.total=0,x.msg="",N.wrap&&(x.adler=1&N.wrap),N.mode=c,N.last=0,N.havedict=0,N.dmax=32768,N.head=null,N.hold=0,N.bits=0,N.lencode=N.lendyn=new B.Buf32(h),N.distcode=N.distdyn=new B.Buf32(l),N.sane=1,N.back=-1,r):a}function w(x){var N;return x&&x.state?((N=x.state).wsize=0,N.whave=0,N.wnext=0,y(x)):a}function u(x,N){var J,K;return x&&x.state?(K=x.state,N<0?(J=0,N=-N):(J=1+(N>>4),N<48&&(N&=15)),N&&(N<8||15<N)?a:(K.window!==null&&K.wbits!==N&&(K.window=null),K.wrap=J,K.wbits=N,w(x))):a}function G(x,N){var J,K;return x?(K=new d,(x.state=K).window=null,(J=u(x,N))!==r&&(x.state=null),J):a}var m,p,k=!0;function S(x){if(k){var N;for(m=new B.Buf32(512),p=new B.Buf32(32),N=0;N<144;)x.lens[N++]=8;for(;N<256;)x.lens[N++]=9;for(;N<280;)x.lens[N++]=7;for(;N<288;)x.lens[N++]=8;for(E(n,x.lens,0,288,m,0,x.work,{bits:9}),N=0;N<32;)x.lens[N++]=5;E(s,x.lens,0,32,p,0,x.work,{bits:5}),k=!1}x.lencode=m,x.lenbits=9,x.distcode=p,x.distbits=5}function R(x,N,J,K){var _,H=x.state;return H.window===null&&(H.wsize=1<<H.wbits,H.wnext=0,H.whave=0,H.window=new B.Buf8(H.wsize)),K>=H.wsize?(B.arraySet(H.window,N,J-H.wsize,H.wsize,0),H.wnext=0,H.whave=H.wsize):(K<(_=H.wsize-H.wnext)&&(_=K),B.arraySet(H.window,N,J-K,_,H.wnext),(K-=_)?(B.arraySet(H.window,N,J-K,K,0),H.wnext=K,H.whave=H.wsize):(H.wnext+=_,H.wnext===H.wsize&&(H.wnext=0),H.whave<H.wsize&&(H.whave+=_))),0}o.inflateReset=w,o.inflateReset2=u,o.inflateResetKeep=y,o.inflateInit=function(x){return G(x,15)},o.inflateInit2=G,o.inflate=function(x,N){var J,K,_,H,T,j,W,O,gA,tA,IA,QA,nA,DA,CA,hA,sA,cA,SA,xA,aA,FA,NA,RA,JA=0,PA=new B.Buf8(4),pA=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!x||!x.state||!x.output||!x.input&&x.avail_in!==0)return a;(J=x.state).mode===12&&(J.mode=13),T=x.next_out,_=x.output,W=x.avail_out,H=x.next_in,K=x.input,j=x.avail_in,O=J.hold,gA=J.bits,tA=j,IA=W,FA=r;A:for(;;)switch(J.mode){case c:if(J.wrap===0){J.mode=13;break}for(;gA<16;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}if(2&J.wrap&&O===35615){PA[J.check=0]=255&O,PA[1]=O>>>8&255,J.check=Q(J.check,PA,2,0),gA=O=0,J.mode=2;break}if(J.flags=0,J.head&&(J.head.done=!1),!(1&J.wrap)||(((255&O)<<8)+(O>>8))%31){x.msg="incorrect header check",J.mode=30;break}if((15&O)!=8){x.msg="unknown compression method",J.mode=30;break}if(gA-=4,aA=8+(15&(O>>>=4)),J.wbits===0)J.wbits=aA;else if(aA>J.wbits){x.msg="invalid window size",J.mode=30;break}J.dmax=1<<aA,x.adler=J.check=1,J.mode=512&O?10:12,gA=O=0;break;case 2:for(;gA<16;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}if(J.flags=O,(255&J.flags)!=8){x.msg="unknown compression method",J.mode=30;break}if(57344&J.flags){x.msg="unknown header flags set",J.mode=30;break}J.head&&(J.head.text=O>>8&1),512&J.flags&&(PA[0]=255&O,PA[1]=O>>>8&255,J.check=Q(J.check,PA,2,0)),gA=O=0,J.mode=3;case 3:for(;gA<32;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}J.head&&(J.head.time=O),512&J.flags&&(PA[0]=255&O,PA[1]=O>>>8&255,PA[2]=O>>>16&255,PA[3]=O>>>24&255,J.check=Q(J.check,PA,4,0)),gA=O=0,J.mode=4;case 4:for(;gA<16;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}J.head&&(J.head.xflags=255&O,J.head.os=O>>8),512&J.flags&&(PA[0]=255&O,PA[1]=O>>>8&255,J.check=Q(J.check,PA,2,0)),gA=O=0,J.mode=5;case 5:if(1024&J.flags){for(;gA<16;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}J.length=O,J.head&&(J.head.extra_len=O),512&J.flags&&(PA[0]=255&O,PA[1]=O>>>8&255,J.check=Q(J.check,PA,2,0)),gA=O=0}else J.head&&(J.head.extra=null);J.mode=6;case 6:if(1024&J.flags&&(j<(QA=J.length)&&(QA=j),QA&&(J.head&&(aA=J.head.extra_len-J.length,J.head.extra||(J.head.extra=new Array(J.head.extra_len)),B.arraySet(J.head.extra,K,H,QA,aA)),512&J.flags&&(J.check=Q(J.check,K,QA,H)),j-=QA,H+=QA,J.length-=QA),J.length))break A;J.length=0,J.mode=7;case 7:if(2048&J.flags){if(j===0)break A;for(QA=0;aA=K[H+QA++],J.head&&aA&&J.length<65536&&(J.head.name+=String.fromCharCode(aA)),aA&&QA<j;);if(512&J.flags&&(J.check=Q(J.check,K,QA,H)),j-=QA,H+=QA,aA)break A}else J.head&&(J.head.name=null);J.length=0,J.mode=8;case 8:if(4096&J.flags){if(j===0)break A;for(QA=0;aA=K[H+QA++],J.head&&aA&&J.length<65536&&(J.head.comment+=String.fromCharCode(aA)),aA&&QA<j;);if(512&J.flags&&(J.check=Q(J.check,K,QA,H)),j-=QA,H+=QA,aA)break A}else J.head&&(J.head.comment=null);J.mode=9;case 9:if(512&J.flags){for(;gA<16;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}if(O!==(65535&J.check)){x.msg="header crc mismatch",J.mode=30;break}gA=O=0}J.head&&(J.head.hcrc=J.flags>>9&1,J.head.done=!0),x.adler=J.check=0,J.mode=12;break;case 10:for(;gA<32;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}x.adler=J.check=D(O),gA=O=0,J.mode=11;case 11:if(J.havedict===0)return x.next_out=T,x.avail_out=W,x.next_in=H,x.avail_in=j,J.hold=O,J.bits=gA,2;x.adler=J.check=1,J.mode=12;case 12:if(N===5||N===6)break A;case 13:if(J.last){O>>>=7&gA,gA-=7&gA,J.mode=27;break}for(;gA<3;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}switch(J.last=1&O,gA-=1,3&(O>>>=1)){case 0:J.mode=14;break;case 1:if(S(J),J.mode=20,N!==6)break;O>>>=2,gA-=2;break A;case 2:J.mode=17;break;case 3:x.msg="invalid block type",J.mode=30}O>>>=2,gA-=2;break;case 14:for(O>>>=7&gA,gA-=7&gA;gA<32;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}if((65535&O)!=(O>>>16^65535)){x.msg="invalid stored block lengths",J.mode=30;break}if(J.length=65535&O,gA=O=0,J.mode=15,N===6)break A;case 15:J.mode=16;case 16:if(QA=J.length){if(j<QA&&(QA=j),W<QA&&(QA=W),QA===0)break A;B.arraySet(_,K,H,QA,T),j-=QA,H+=QA,W-=QA,T+=QA,J.length-=QA;break}J.mode=12;break;case 17:for(;gA<14;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}if(J.nlen=257+(31&O),O>>>=5,gA-=5,J.ndist=1+(31&O),O>>>=5,gA-=5,J.ncode=4+(15&O),O>>>=4,gA-=4,286<J.nlen||30<J.ndist){x.msg="too many length or distance symbols",J.mode=30;break}J.have=0,J.mode=18;case 18:for(;J.have<J.ncode;){for(;gA<3;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}J.lens[pA[J.have++]]=7&O,O>>>=3,gA-=3}for(;J.have<19;)J.lens[pA[J.have++]]=0;if(J.lencode=J.lendyn,J.lenbits=7,NA={bits:J.lenbits},FA=E(0,J.lens,0,19,J.lencode,0,J.work,NA),J.lenbits=NA.bits,FA){x.msg="invalid code lengths set",J.mode=30;break}J.have=0,J.mode=19;case 19:for(;J.have<J.nlen+J.ndist;){for(;hA=(JA=J.lencode[O&(1<<J.lenbits)-1])>>>16&255,sA=65535&JA,!((CA=JA>>>24)<=gA);){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}if(sA<16)O>>>=CA,gA-=CA,J.lens[J.have++]=sA;else{if(sA===16){for(RA=CA+2;gA<RA;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}if(O>>>=CA,gA-=CA,J.have===0){x.msg="invalid bit length repeat",J.mode=30;break}aA=J.lens[J.have-1],QA=3+(3&O),O>>>=2,gA-=2}else if(sA===17){for(RA=CA+3;gA<RA;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}gA-=CA,aA=0,QA=3+(7&(O>>>=CA)),O>>>=3,gA-=3}else{for(RA=CA+7;gA<RA;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}gA-=CA,aA=0,QA=11+(127&(O>>>=CA)),O>>>=7,gA-=7}if(J.have+QA>J.nlen+J.ndist){x.msg="invalid bit length repeat",J.mode=30;break}for(;QA--;)J.lens[J.have++]=aA}}if(J.mode===30)break;if(J.lens[256]===0){x.msg="invalid code -- missing end-of-block",J.mode=30;break}if(J.lenbits=9,NA={bits:J.lenbits},FA=E(n,J.lens,0,J.nlen,J.lencode,0,J.work,NA),J.lenbits=NA.bits,FA){x.msg="invalid literal/lengths set",J.mode=30;break}if(J.distbits=6,J.distcode=J.distdyn,NA={bits:J.distbits},FA=E(s,J.lens,J.nlen,J.ndist,J.distcode,0,J.work,NA),J.distbits=NA.bits,FA){x.msg="invalid distances set",J.mode=30;break}if(J.mode=20,N===6)break A;case 20:J.mode=21;case 21:if(6<=j&&258<=W){x.next_out=T,x.avail_out=W,x.next_in=H,x.avail_in=j,J.hold=O,J.bits=gA,i(x,IA),T=x.next_out,_=x.output,W=x.avail_out,H=x.next_in,K=x.input,j=x.avail_in,O=J.hold,gA=J.bits,J.mode===12&&(J.back=-1);break}for(J.back=0;hA=(JA=J.lencode[O&(1<<J.lenbits)-1])>>>16&255,sA=65535&JA,!((CA=JA>>>24)<=gA);){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}if(hA&&(240&hA)==0){for(cA=CA,SA=hA,xA=sA;hA=(JA=J.lencode[xA+((O&(1<<cA+SA)-1)>>cA)])>>>16&255,sA=65535&JA,!(cA+(CA=JA>>>24)<=gA);){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}O>>>=cA,gA-=cA,J.back+=cA}if(O>>>=CA,gA-=CA,J.back+=CA,J.length=sA,hA===0){J.mode=26;break}if(32&hA){J.back=-1,J.mode=12;break}if(64&hA){x.msg="invalid literal/length code",J.mode=30;break}J.extra=15&hA,J.mode=22;case 22:if(J.extra){for(RA=J.extra;gA<RA;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}J.length+=O&(1<<J.extra)-1,O>>>=J.extra,gA-=J.extra,J.back+=J.extra}J.was=J.length,J.mode=23;case 23:for(;hA=(JA=J.distcode[O&(1<<J.distbits)-1])>>>16&255,sA=65535&JA,!((CA=JA>>>24)<=gA);){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}if((240&hA)==0){for(cA=CA,SA=hA,xA=sA;hA=(JA=J.distcode[xA+((O&(1<<cA+SA)-1)>>cA)])>>>16&255,sA=65535&JA,!(cA+(CA=JA>>>24)<=gA);){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}O>>>=cA,gA-=cA,J.back+=cA}if(O>>>=CA,gA-=CA,J.back+=CA,64&hA){x.msg="invalid distance code",J.mode=30;break}J.offset=sA,J.extra=15&hA,J.mode=24;case 24:if(J.extra){for(RA=J.extra;gA<RA;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}J.offset+=O&(1<<J.extra)-1,O>>>=J.extra,gA-=J.extra,J.back+=J.extra}if(J.offset>J.dmax){x.msg="invalid distance too far back",J.mode=30;break}J.mode=25;case 25:if(W===0)break A;if(QA=IA-W,J.offset>QA){if((QA=J.offset-QA)>J.whave&&J.sane){x.msg="invalid distance too far back",J.mode=30;break}nA=QA>J.wnext?(QA-=J.wnext,J.wsize-QA):J.wnext-QA,QA>J.length&&(QA=J.length),DA=J.window}else DA=_,nA=T-J.offset,QA=J.length;for(W<QA&&(QA=W),W-=QA,J.length-=QA;_[T++]=DA[nA++],--QA;);J.length===0&&(J.mode=21);break;case 26:if(W===0)break A;_[T++]=J.length,W--,J.mode=21;break;case 27:if(J.wrap){for(;gA<32;){if(j===0)break A;j--,O|=K[H++]<<gA,gA+=8}if(IA-=W,x.total_out+=IA,J.total+=IA,IA&&(x.adler=J.check=J.flags?Q(J.check,_,IA,T-IA):C(J.check,_,IA,T-IA)),IA=W,(J.flags?O:D(O))!==J.check){x.msg="incorrect data check",J.mode=30;break}gA=O=0}J.mode=28;case 28:if(J.wrap&&J.flags){for(;gA<32;){if(j===0)break A;j--,O+=K[H++]<<gA,gA+=8}if(O!==(4294967295&J.total)){x.msg="incorrect length check",J.mode=30;break}gA=O=0}J.mode=29;case 29:FA=1;break A;case 30:FA=-3;break A;case 31:return-4;default:return a}return x.next_out=T,x.avail_out=W,x.next_in=H,x.avail_in=j,J.hold=O,J.bits=gA,(J.wsize||IA!==x.avail_out&&J.mode<30&&(J.mode<27||N!==4))&&R(x,x.output,x.next_out,IA-x.avail_out)?(J.mode=31,-4):(tA-=x.avail_in,IA-=x.avail_out,x.total_in+=tA,x.total_out+=IA,J.total+=IA,J.wrap&&IA&&(x.adler=J.check=J.flags?Q(J.check,_,IA,x.next_out-IA):C(J.check,_,IA,x.next_out-IA)),x.data_type=J.bits+(J.last?64:0)+(J.mode===12?128:0)+(J.mode===20||J.mode===15?256:0),(tA==0&&IA===0||N===4)&&FA===r&&(FA=-5),FA)},o.inflateEnd=function(x){if(!x||!x.state)return a;var N=x.state;return N.window&&(N.window=null),x.state=null,r},o.inflateGetHeader=function(x,N){var J;return x&&x.state?(2&(J=x.state).wrap)==0?a:((J.head=N).done=!1,r):a},o.inflateSetDictionary=function(x,N){var J,K=N.length;return x&&x.state?(J=x.state).wrap!==0&&J.mode!==11?a:J.mode===11&&C(1,N,K,0)!==J.check?-3:R(x,N,K,K)?(J.mode=31,-4):(J.havedict=1,r):a},o.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./inffast":48,"./inftrees":50}],50:[function(e,t,o){var B=e("../utils/common"),C=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],Q=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],i=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],E=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];t.exports=function(n,s,r,a,c,h,l,D){var d,y,w,u,G,m,p,k,S,R=D.bits,x=0,N=0,J=0,K=0,_=0,H=0,T=0,j=0,W=0,O=0,gA=null,tA=0,IA=new B.Buf16(16),QA=new B.Buf16(16),nA=null,DA=0;for(x=0;x<=15;x++)IA[x]=0;for(N=0;N<a;N++)IA[s[r+N]]++;for(_=R,K=15;1<=K&&IA[K]===0;K--);if(K<_&&(_=K),K===0)return c[h++]=20971520,c[h++]=20971520,D.bits=1,0;for(J=1;J<K&&IA[J]===0;J++);for(_<J&&(_=J),x=j=1;x<=15;x++)if(j<<=1,(j-=IA[x])<0)return-1;if(0<j&&(n===0||K!==1))return-1;for(QA[1]=0,x=1;x<15;x++)QA[x+1]=QA[x]+IA[x];for(N=0;N<a;N++)s[r+N]!==0&&(l[QA[s[r+N]]++]=N);if(m=n===0?(gA=nA=l,19):n===1?(gA=C,tA-=257,nA=Q,DA-=257,256):(gA=i,nA=E,-1),x=J,G=h,T=N=O=0,w=-1,u=(W=1<<(H=_))-1,n===1&&852<W||n===2&&592<W)return 1;for(;;){for(p=x-T,S=l[N]<m?(k=0,l[N]):l[N]>m?(k=nA[DA+l[N]],gA[tA+l[N]]):(k=96,0),d=1<<x-T,J=y=1<<H;c[G+(O>>T)+(y-=d)]=p<<24|k<<16|S|0,y!==0;);for(d=1<<x-1;O&d;)d>>=1;if(d!==0?(O&=d-1,O+=d):O=0,N++,--IA[x]==0){if(x===K)break;x=s[r+l[N]]}if(_<x&&(O&u)!==w){for(T===0&&(T=_),G+=J,j=1<<(H=x-T);H+T<K&&!((j-=IA[H+T])<=0);)H++,j<<=1;if(W+=1<<H,n===1&&852<W||n===2&&592<W)return 1;c[w=O&u]=_<<24|H<<16|G-h|0}}return O!==0&&(c[G+O]=x-T<<24|64<<16|0),D.bits=_,0}},{"../utils/common":41}],51:[function(e,t,o){t.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],52:[function(e,t,o){var B=e("../utils/common"),C=0,Q=1;function i(JA){for(var PA=JA.length;0<=--PA;)JA[PA]=0}var E=0,n=29,s=256,r=s+1+n,a=30,c=19,h=2*r+1,l=15,D=16,d=7,y=256,w=16,u=17,G=18,m=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],p=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],k=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],S=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],R=new Array(2*(r+2));i(R);var x=new Array(2*a);i(x);var N=new Array(512);i(N);var J=new Array(256);i(J);var K=new Array(n);i(K);var _,H,T,j=new Array(a);function W(JA,PA,pA,YA,dA){this.static_tree=JA,this.extra_bits=PA,this.extra_base=pA,this.elems=YA,this.max_length=dA,this.has_stree=JA&&JA.length}function O(JA,PA){this.dyn_tree=JA,this.max_code=0,this.stat_desc=PA}function gA(JA){return JA<256?N[JA]:N[256+(JA>>>7)]}function tA(JA,PA){JA.pending_buf[JA.pending++]=255&PA,JA.pending_buf[JA.pending++]=PA>>>8&255}function IA(JA,PA,pA){JA.bi_valid>D-pA?(JA.bi_buf|=PA<<JA.bi_valid&65535,tA(JA,JA.bi_buf),JA.bi_buf=PA>>D-JA.bi_valid,JA.bi_valid+=pA-D):(JA.bi_buf|=PA<<JA.bi_valid&65535,JA.bi_valid+=pA)}function QA(JA,PA,pA){IA(JA,pA[2*PA],pA[2*PA+1])}function nA(JA,PA){for(var pA=0;pA|=1&JA,JA>>>=1,pA<<=1,0<--PA;);return pA>>>1}function DA(JA,PA,pA){var YA,dA,HA=new Array(l+1),WA=0;for(YA=1;YA<=l;YA++)HA[YA]=WA=WA+pA[YA-1]<<1;for(dA=0;dA<=PA;dA++){var Qg=JA[2*dA+1];Qg!==0&&(JA[2*dA]=nA(HA[Qg]++,Qg))}}function CA(JA){var PA;for(PA=0;PA<r;PA++)JA.dyn_ltree[2*PA]=0;for(PA=0;PA<a;PA++)JA.dyn_dtree[2*PA]=0;for(PA=0;PA<c;PA++)JA.bl_tree[2*PA]=0;JA.dyn_ltree[2*y]=1,JA.opt_len=JA.static_len=0,JA.last_lit=JA.matches=0}function hA(JA){8<JA.bi_valid?tA(JA,JA.bi_buf):0<JA.bi_valid&&(JA.pending_buf[JA.pending++]=JA.bi_buf),JA.bi_buf=0,JA.bi_valid=0}function sA(JA,PA,pA,YA){var dA=2*PA,HA=2*pA;return JA[dA]<JA[HA]||JA[dA]===JA[HA]&&YA[PA]<=YA[pA]}function cA(JA,PA,pA){for(var YA=JA.heap[pA],dA=pA<<1;dA<=JA.heap_len&&(dA<JA.heap_len&&sA(PA,JA.heap[dA+1],JA.heap[dA],JA.depth)&&dA++,!sA(PA,YA,JA.heap[dA],JA.depth));)JA.heap[pA]=JA.heap[dA],pA=dA,dA<<=1;JA.heap[pA]=YA}function SA(JA,PA,pA){var YA,dA,HA,WA,Qg=0;if(JA.last_lit!==0)for(;YA=JA.pending_buf[JA.d_buf+2*Qg]<<8|JA.pending_buf[JA.d_buf+2*Qg+1],dA=JA.pending_buf[JA.l_buf+Qg],Qg++,YA===0?QA(JA,dA,PA):(QA(JA,(HA=J[dA])+s+1,PA),(WA=m[HA])!==0&&IA(JA,dA-=K[HA],WA),QA(JA,HA=gA(--YA),pA),(WA=p[HA])!==0&&IA(JA,YA-=j[HA],WA)),Qg<JA.last_lit;);QA(JA,y,PA)}function xA(JA,PA){var pA,YA,dA,HA=PA.dyn_tree,WA=PA.stat_desc.static_tree,Qg=PA.stat_desc.has_stree,_A=PA.stat_desc.elems,GA=-1;for(JA.heap_len=0,JA.heap_max=h,pA=0;pA<_A;pA++)HA[2*pA]!==0?(JA.heap[++JA.heap_len]=GA=pA,JA.depth[pA]=0):HA[2*pA+1]=0;for(;JA.heap_len<2;)HA[2*(dA=JA.heap[++JA.heap_len]=GA<2?++GA:0)]=1,JA.depth[dA]=0,JA.opt_len--,Qg&&(JA.static_len-=WA[2*dA+1]);for(PA.max_code=GA,pA=JA.heap_len>>1;1<=pA;pA--)cA(JA,HA,pA);for(dA=_A;pA=JA.heap[1],JA.heap[1]=JA.heap[JA.heap_len--],cA(JA,HA,1),YA=JA.heap[1],JA.heap[--JA.heap_max]=pA,JA.heap[--JA.heap_max]=YA,HA[2*dA]=HA[2*pA]+HA[2*YA],JA.depth[dA]=(JA.depth[pA]>=JA.depth[YA]?JA.depth[pA]:JA.depth[YA])+1,HA[2*pA+1]=HA[2*YA+1]=dA,JA.heap[1]=dA++,cA(JA,HA,1),2<=JA.heap_len;);JA.heap[--JA.heap_max]=JA.heap[1],(function(kA,OA){var $A,tg,dg,Sg,Bg,Yg,QI=OA.dyn_tree,uA=OA.max_code,ng=OA.stat_desc.static_tree,Mg=OA.stat_desc.has_stree,Ug=OA.stat_desc.extra_bits,mg=OA.stat_desc.extra_base,Rg=OA.stat_desc.max_length,Kg=0;for(Sg=0;Sg<=l;Sg++)kA.bl_count[Sg]=0;for(QI[2*kA.heap[kA.heap_max]+1]=0,$A=kA.heap_max+1;$A<h;$A++)Rg<(Sg=QI[2*QI[2*(tg=kA.heap[$A])+1]+1]+1)&&(Sg=Rg,Kg++),QI[2*tg+1]=Sg,uA<tg||(kA.bl_count[Sg]++,Bg=0,mg<=tg&&(Bg=Ug[tg-mg]),Yg=QI[2*tg],kA.opt_len+=Yg*(Sg+Bg),Mg&&(kA.static_len+=Yg*(ng[2*tg+1]+Bg)));if(Kg!==0){do{for(Sg=Rg-1;kA.bl_count[Sg]===0;)Sg--;kA.bl_count[Sg]--,kA.bl_count[Sg+1]+=2,kA.bl_count[Rg]--,Kg-=2}while(0<Kg);for(Sg=Rg;Sg!==0;Sg--)for(tg=kA.bl_count[Sg];tg!==0;)uA<(dg=kA.heap[--$A])||(QI[2*dg+1]!==Sg&&(kA.opt_len+=(Sg-QI[2*dg+1])*QI[2*dg],QI[2*dg+1]=Sg),tg--)}})(JA,PA),DA(HA,GA,JA.bl_count)}function aA(JA,PA,pA){var YA,dA,HA=-1,WA=PA[1],Qg=0,_A=7,GA=4;for(WA===0&&(_A=138,GA=3),PA[2*(pA+1)+1]=65535,YA=0;YA<=pA;YA++)dA=WA,WA=PA[2*(YA+1)+1],++Qg<_A&&dA===WA||(Qg<GA?JA.bl_tree[2*dA]+=Qg:dA!==0?(dA!==HA&&JA.bl_tree[2*dA]++,JA.bl_tree[2*w]++):Qg<=10?JA.bl_tree[2*u]++:JA.bl_tree[2*G]++,HA=dA,GA=(Qg=0)===WA?(_A=138,3):dA===WA?(_A=6,3):(_A=7,4))}function FA(JA,PA,pA){var YA,dA,HA=-1,WA=PA[1],Qg=0,_A=7,GA=4;for(WA===0&&(_A=138,GA=3),YA=0;YA<=pA;YA++)if(dA=WA,WA=PA[2*(YA+1)+1],!(++Qg<_A&&dA===WA)){if(Qg<GA)for(;QA(JA,dA,JA.bl_tree),--Qg!=0;);else dA!==0?(dA!==HA&&(QA(JA,dA,JA.bl_tree),Qg--),QA(JA,w,JA.bl_tree),IA(JA,Qg-3,2)):Qg<=10?(QA(JA,u,JA.bl_tree),IA(JA,Qg-3,3)):(QA(JA,G,JA.bl_tree),IA(JA,Qg-11,7));HA=dA,GA=(Qg=0)===WA?(_A=138,3):dA===WA?(_A=6,3):(_A=7,4)}}i(j);var NA=!1;function RA(JA,PA,pA,YA){IA(JA,(E<<1)+(YA?1:0),3),(function(dA,HA,WA,Qg){hA(dA),tA(dA,WA),tA(dA,~WA),B.arraySet(dA.pending_buf,dA.window,HA,WA,dA.pending),dA.pending+=WA})(JA,PA,pA)}o._tr_init=function(JA){NA||((function(){var PA,pA,YA,dA,HA,WA=new Array(l+1);for(dA=YA=0;dA<n-1;dA++)for(K[dA]=YA,PA=0;PA<1<<m[dA];PA++)J[YA++]=dA;for(J[YA-1]=dA,dA=HA=0;dA<16;dA++)for(j[dA]=HA,PA=0;PA<1<<p[dA];PA++)N[HA++]=dA;for(HA>>=7;dA<a;dA++)for(j[dA]=HA<<7,PA=0;PA<1<<p[dA]-7;PA++)N[256+HA++]=dA;for(pA=0;pA<=l;pA++)WA[pA]=0;for(PA=0;PA<=143;)R[2*PA+1]=8,PA++,WA[8]++;for(;PA<=255;)R[2*PA+1]=9,PA++,WA[9]++;for(;PA<=279;)R[2*PA+1]=7,PA++,WA[7]++;for(;PA<=287;)R[2*PA+1]=8,PA++,WA[8]++;for(DA(R,r+1,WA),PA=0;PA<a;PA++)x[2*PA+1]=5,x[2*PA]=nA(PA,5);_=new W(R,m,s+1,r,l),H=new W(x,p,0,a,l),T=new W(new Array(0),k,0,c,d)})(),NA=!0),JA.l_desc=new O(JA.dyn_ltree,_),JA.d_desc=new O(JA.dyn_dtree,H),JA.bl_desc=new O(JA.bl_tree,T),JA.bi_buf=0,JA.bi_valid=0,CA(JA)},o._tr_stored_block=RA,o._tr_flush_block=function(JA,PA,pA,YA){var dA,HA,WA=0;0<JA.level?(JA.strm.data_type===2&&(JA.strm.data_type=(function(Qg){var _A,GA=4093624447;for(_A=0;_A<=31;_A++,GA>>>=1)if(1&GA&&Qg.dyn_ltree[2*_A]!==0)return C;if(Qg.dyn_ltree[18]!==0||Qg.dyn_ltree[20]!==0||Qg.dyn_ltree[26]!==0)return Q;for(_A=32;_A<s;_A++)if(Qg.dyn_ltree[2*_A]!==0)return Q;return C})(JA)),xA(JA,JA.l_desc),xA(JA,JA.d_desc),WA=(function(Qg){var _A;for(aA(Qg,Qg.dyn_ltree,Qg.l_desc.max_code),aA(Qg,Qg.dyn_dtree,Qg.d_desc.max_code),xA(Qg,Qg.bl_desc),_A=c-1;3<=_A&&Qg.bl_tree[2*S[_A]+1]===0;_A--);return Qg.opt_len+=3*(_A+1)+5+5+4,_A})(JA),dA=JA.opt_len+3+7>>>3,(HA=JA.static_len+3+7>>>3)<=dA&&(dA=HA)):dA=HA=pA+5,pA+4<=dA&&PA!==-1?RA(JA,PA,pA,YA):JA.strategy===4||HA===dA?(IA(JA,2+(YA?1:0),3),SA(JA,R,x)):(IA(JA,4+(YA?1:0),3),(function(Qg,_A,GA,kA){var OA;for(IA(Qg,_A-257,5),IA(Qg,GA-1,5),IA(Qg,kA-4,4),OA=0;OA<kA;OA++)IA(Qg,Qg.bl_tree[2*S[OA]+1],3);FA(Qg,Qg.dyn_ltree,_A-1),FA(Qg,Qg.dyn_dtree,GA-1)})(JA,JA.l_desc.max_code+1,JA.d_desc.max_code+1,WA+1),SA(JA,JA.dyn_ltree,JA.dyn_dtree)),CA(JA),YA&&hA(JA)},o._tr_tally=function(JA,PA,pA){return JA.pending_buf[JA.d_buf+2*JA.last_lit]=PA>>>8&255,JA.pending_buf[JA.d_buf+2*JA.last_lit+1]=255&PA,JA.pending_buf[JA.l_buf+JA.last_lit]=255&pA,JA.last_lit++,PA===0?JA.dyn_ltree[2*pA]++:(JA.matches++,PA--,JA.dyn_ltree[2*(J[pA]+s+1)]++,JA.dyn_dtree[2*gA(PA)]++),JA.last_lit===JA.lit_bufsize-1},o._tr_align=function(JA){IA(JA,2,3),QA(JA,y,R),(function(PA){PA.bi_valid===16?(tA(PA,PA.bi_buf),PA.bi_buf=0,PA.bi_valid=0):8<=PA.bi_valid&&(PA.pending_buf[PA.pending++]=255&PA.bi_buf,PA.bi_buf>>=8,PA.bi_valid-=8)})(JA)}},{"../utils/common":41}],53:[function(e,t,o){t.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(e,t,o){(function(B){(function(C,Q){if(!C.setImmediate){var i,E,n,s,r=1,a={},c=!1,h=C.document,l=Object.getPrototypeOf&&Object.getPrototypeOf(C);l=l&&l.setTimeout?l:C,i={}.toString.call(C.process)==="[object process]"?function(w){I.nextTick(function(){d(w)})}:(function(){if(C.postMessage&&!C.importScripts){var w=!0,u=C.onmessage;return C.onmessage=function(){w=!1},C.postMessage("","*"),C.onmessage=u,w}})()?(s="setImmediate$"+Math.random()+"$",C.addEventListener?C.addEventListener("message",y,!1):C.attachEvent("onmessage",y),function(w){C.postMessage(s+w,"*")}):C.MessageChannel?((n=new MessageChannel).port1.onmessage=function(w){d(w.data)},function(w){n.port2.postMessage(w)}):h&&"onreadystatechange"in h.createElement("script")?(E=h.documentElement,function(w){var u=h.createElement("script");u.onreadystatechange=function(){d(w),u.onreadystatechange=null,E.removeChild(u),u=null},E.appendChild(u)}):function(w){setTimeout(d,0,w)},l.setImmediate=function(w){typeof w!="function"&&(w=new Function(""+w));for(var u=new Array(arguments.length-1),G=0;G<u.length;G++)u[G]=arguments[G+1];var m={callback:w,args:u};return a[r]=m,i(r),r++},l.clearImmediate=D}function D(w){delete a[w]}function d(w){if(c)setTimeout(d,0,w);else{var u=a[w];if(u){c=!0;try{(function(G){var m=G.callback,p=G.args;switch(p.length){case 0:m();break;case 1:m(p[0]);break;case 2:m(p[0],p[1]);break;case 3:m(p[0],p[1],p[2]);break;default:m.apply(Q,p)}})(u)}finally{D(w),c=!1}}}}function y(w){w.source===C&&typeof w.data=="string"&&w.data.indexOf(s)===0&&d(+w.data.slice(s.length))}})(typeof self>"u"?B===void 0?this:B:self)}).call(this,typeof OL<"u"?OL:typeof self<"u"?self:typeof window<"u"?window:{})},{}]},{},[10])(10)})})(uog)),uog.exports}var qyo=vyo();const zeA=Mp(qyo),Tyo=async()=>await Promise.resolve().then(()=>Cvo),Zyo=async({circuitJson:g,projectName:A})=>{try{const{circuitJsonToStep:I}=await Tyo(),e=await I(g,{exportMode:"assembly"}),t=new zeA;for(const[o,B]of Object.entries(e))t.file(o,B);mk(await t.generateAsync({type:"blob"}),{fileName:`${A}-assembly.zip`})}catch(I){JC.error(`Failed to export assembly STEP: ${I instanceof Error?I.message:String(I)}`)}},Oyo=async({circuitJson:g,projectName:A})=>{await JC.promise((async()=>{const I=new zeA,[e,{convertCircuitJsonToBomRows:t,convertBomRowsToCsv:o},{convertCircuitJsonToPickAndPlaceCsv:B}]=await Promise.all([sS("circuit-json-to-gerber"),sS("circuit-json-to-bom-csv"),sS("circuit-json-to-pnp-csv")]),C=g.filter(r=>!("error_type"in r)&&!("warning_type"in r)),Q=e.convertCircuitJsonToGerberFiles(C,{flip_y_axis:!1});for(const[r,a]of Object.entries(Q))I.file(`gerber/${r}`,a);const i=await t({circuitJson:g}),E=await o(i);I.file("bom.csv",E);const n=await B(g,{supplier:"jlcpcb"});I.file("pick_and_place.csv",n);const s=await I.generateAsync({type:"blob"});mk(s,{fileName:`${A}_fabrication_files.zip`})})(),{loading:"Generating fabrication files...",success:"Fabrication ZIP ready",error:I=>`Failed to generate fabrication files: ${I instanceof Error?I.message:String(I)}`})},Wyo=async g=>{const{createFdmComponentBox:A,renderFdmComponentBoxPng:I}=await sS("circuit-json-to-fdm-component-box"),[e,t]=await Promise.all([A(g),I(g,{},{width:960,height:640})]);return{...e,previewPng:t}},Vyo=async g=>{const{createFdmComponentBox:A}=await sS("circuit-json-to-fdm-component-box");return A(g)},IFI=({generatedBox:g,projectName:A})=>{const I=Uint8Array.from(g.threeMf);mk(new Blob([I.buffer],{type:"model/3mf"}),{fileName:`${Otg(A)}-component-box.3mf`})},jyo=async({circuitJson:g,projectName:A})=>{await JC.promise((async()=>{const I=await Vyo(g);IFI({generatedBox:I,projectName:A})})(),{loading:"Generating component box...",success:"Component box 3MF ready",error:I=>`Failed to generate component box: ${I instanceof Error?I.message:String(I)}`})},zyo=async({circuitJson:g,projectName:A})=>{let I;try{const{convertCircuitJsonToGltf:e}=await sS("circuit-json-to-gltf");console.log("convertCircuitJsonToGltf",e);const t=await e(g,{format:"glb",boardTextureResolution:1024});if(!t||!(t instanceof ArrayBuffer))throw new Error("Invalid GLB data returned from converter");I=new Blob([t],{type:"model/gltf-binary"})}catch(e){console.error("GLB Export Error:",e);return}mk(I,{fileName:`${A}.glb`})},Xyo=async({circuitJson:g,libraryName:A})=>{const{CircuitJsonToKicadLibraryConverter:I}=await sS("circuit-json-to-kicad"),e=new I(g,{libraryName:A,footprintLibraryName:A});e.runUntilFinished();const t=e.getOutput(),o=new zeA;o.file(`${A}.kicad_sym`,t.kicadSymString);for(const B of t.footprints){const C=o.folder(`${A}.pretty`);C&&C.file(`${B.footprintName}.kicad_mod`,`${B.kicadModString}
5679
5679
  `)}if(t.model3dSourcePaths.length>0){const B=o.folder(`${A}.3dshapes`);if(B)for(const C of t.model3dSourcePaths)try{const Q=C.split("/").pop()||C,i=await fetch(C);if(i.ok){const E=await i.arrayBuffer();B.file(Q,E)}}catch{}}return o.file("fp-lib-table",t.fpLibTableString),o.file("sym-lib-table",t.symLibTableString),o},$yo=async({circuitJson:g,projectName:A})=>{await JC.promise((async()=>{const e=await(await Xyo({circuitJson:g,libraryName:A})).generateAsync({type:"blob"});mk(e,{fileName:`${A}_kicad_library.zip`})})(),{loading:"Generating KiCad library...",success:"KiCad library ZIP ready",error:I=>`Failed to generate KiCad library: ${I instanceof Error?I.message:String(I)}`})},Awo=async({circuitJson:g,projectName:A})=>{const{CircuitJsonToKicadPcbConverter:I,CircuitJsonToKicadSchConverter:e,CircuitJsonToKicadProConverter:t,resolveAndLoadKicad3dModelFiles:o}=await sS("circuit-json-to-kicad"),B=new e(g);B.runUntilFinished();const C=B.getOutputString(),Q=new I(g,{includeBuiltin3dModels:!0,projectName:A});Q.runUntilFinished();const i=Q.getOutputString(),E=new t(g,{projectName:A,schematicFilename:`${A}.kicad_sch`,pcbFilename:`${A}.kicad_pcb`});E.runUntilFinished();const n=E.getOutputString(),s=new zeA;return s.file(`${A}.kicad_sch`,C),s.file(`${A}.kicad_pcb`,i),s.file(`${A}.kicad_pro`,n),await o({projectName:A,model3dSourcePaths:Q.getModel3dSourcePaths(),fetch,onModelFile:({outputPath:r,content:a})=>{s.file(r,a)},onError:({sourcePath:r})=>{console.warn(`Failed to load 3D model from ${r}`)}}),s},gwo=async({circuitJson:g,projectName:A})=>{await JC.promise((async()=>{const e=await(await Awo({circuitJson:g,projectName:A})).generateAsync({type:"blob"});mk(e,{fileName:`${A}_kicad_project.zip`})})(),{loading:"Generating KiCad project...",success:"KiCad project ZIP ready",error:I=>`Failed to generate KiCad project: ${I instanceof Error?I.message:String(I)}`})},eFI=async({circuitJson:g,projectName:A,options:I={}})=>{try{const{convertCircuitJsonToLbrn:e}=await sS("circuit-json-to-lbrn"),o=(await e(g,{includeSilkscreen:I.includeSilkscreen??!1,includeOxidationCleaningLayer:I.includeOxidationCleaningLayer??!0})).toXml(),B=new Blob([o],{type:"application/lbrn"});mk(B,{fileName:`${A}.lbrn2`})}catch(e){const t=e instanceof Error?e.message:"Unknown error";JC.error(`Failed to export to LBRN format: ${t}`)}},Iwo=async({circuitJson:g,projectName:A})=>{const{convertCircuitJsonToPinoutSvg:I}=await sS("circuit-to-svg"),e=I(g);mk(e,{fileName:`${A}-pinout.svg`,mimeType:"image/svg+xml"})},ewo=async({circuitJson:g,projectName:A})=>{const{circuitJsonToStep:I}=await sS("circuit-json-to-step"),e=g.find(i=>i.type==="pcb_board"),t=e&&"width"in e?e.width:void 0,o=e&&"height"in e?e.height:void 0,B=e&&"thickness"in e?e.thickness:void 0;if(t===void 0||o===void 0||B===void 0){JC.error("Board dimensions not found. Please add a pcb_board with width, height, and thickness to your circuit.");return}let C;try{C=await I(g,{boardWidth:t,boardHeight:o,boardThickness:B,productName:A,includeComponents:!0,includeExternalMeshes:!0})}catch(i){const E=i instanceof Error?i.message:"Unknown error";JC.error(`Failed to convert circuit to STEP format: ${E}`);return}const Q=new Blob([C],{type:"application/step"});try{mk(Q,{fileName:`${A}.step`})}catch(i){const E=i instanceof Error?i.message:"Unknown error";JC.error(`Failed to download STEP file: ${E}`)}},two=[{extension:"json",name:"Circuit JSON"},{extension:"json",name:"Simple Route JSON"},{extension:"zip",name:"Fabrication Files"},{extension:"zip",name:"KiCad Project"},{extension:"zip",name:"Altium Project"},{extension:"zip",name:"KiCad Library"},{extension:"glb",name:"GLB (Binary GLTF)"},{extension:"svg",name:"Pinout SVG"},{extension:"step",name:"STEP"},{extension:"zip",name:"Assembly STEP"},{extension:"lbrn2",name:"LightBurn"}],owo=async({exportName:g,circuitJson:A,simpleRouteJson:I,projectName:e})=>{const t=Otg(e);if(g==="Fabrication Files"){await Oyo({circuitJson:A,projectName:t});return}if(g==="KiCad Project"){await gwo({circuitJson:A,projectName:t});return}if(g==="Altium Project"){await Hyo({circuitJson:A,projectName:t});return}if(g==="KiCad Library"){await $yo({circuitJson:A,projectName:t});return}if(g==="Circuit JSON"){mk(JSON.stringify(A,null,2),{fileName:`${t}.circuit.json`,mimeType:"application/json"});return}if(g==="Simple Route JSON"){if(!I)throw new Error("No Simple Route JSON available to export");mk(JSON.stringify(I,null,2),{fileName:`${t}.simple-route.json`,mimeType:"application/json"});return}if(g==="GLB (Binary GLTF)"){await zyo({circuitJson:A,projectName:t});return}if(g==="Pinout SVG"){Iwo({circuitJson:A,projectName:t});return}if(g==="STEP"){await ewo({circuitJson:A,projectName:t});return}if(g==="Assembly STEP"){await Zyo({circuitJson:A,projectName:t});return}if(g==="Component Box (3MF)"){await jyo({circuitJson:A,projectName:t});return}if(g==="LightBurn"){await eFI({circuitJson:A,projectName:t});return}throw new Error(`Unsupported export type: "${g}"`)},Bwo=({packageName:g,onSelectReview:A})=>{const I=Fc(n=>n.fsMap),e=Fc(n=>n.circuitJson),[t,o]=X.useState([]),[B,C]=X.useState(!1),[Q,i]=X.useState(!1);X.useEffect(()=>{!g||!hlA()||(C(!0),wAA.get("ai_reviews/list",{searchParams:{package_name:g}}).json().then(n=>o(n.ai_reviews)).catch(n=>{console.error("Failed to load AI reviews",n),JC.error("Failed to load AI reviews")}).finally(()=>C(!1)))},[g]);const E=async()=>{if(!e){JC.error("Need Circuit JSON to Request AI Review");return}if(!hlA()){JC.error("Missing registry token");return}i(!0);try{const{ai_review:n}=await wAA.post("ai_reviews/create",{json:{package_name:g??"unknown",fs_map:Object.fromEntries(I),circuit_json:e}}).json();o(s=>[n,...s]),A(n),JC.success("AI review requested")}catch(n){console.error("Failed to create AI review",n),JC.error("Failed to request AI review")}finally{i(!1)}};return q.jsxs(q.Fragment,{children:[q.jsxs(T3,{children:[q.jsx(Z3,{children:"AI Review"}),q.jsx(O5,{children:"Select an AI review or request a new one."})]}),q.jsx("div",{className:"rf-flex rf-gap-4 rf-mt-4",children:q.jsx("div",{className:"rf-w-48 rf-h-64 rf-overflow-y-auto rf-border rf-rounded rf-p-2 rf-flex-shrink-0",children:B?q.jsx("div",{className:"rf-text-sm",children:"Loading..."}):t.length>0?t.map(n=>q.jsx("div",{className:"rf-text-sm rf-p-2 rf-cursor-pointer rf-rounded hover:rf-bg-zinc-100",onClick:()=>A(n),children:new Date(n.created_at||"").toLocaleString()},n.ai_review_id)):q.jsx("div",{className:"rf-text-sm rf-text-muted-foreground",children:"No AI reviews found."})})}),q.jsx(FZ,{className:"rf-mt-4",children:q.jsx(Ei,{onClick:E,disabled:Q,children:Q?"Requesting...":"Review my Board"})})]})};function Gog(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var W5=Gog();function tFI(g){W5=g}var XeA={exec:()=>null};function Zs(g,A=""){let I=typeof g=="string"?g:g.source;const e={replace:(t,o)=>{let B=typeof o=="string"?o:o.source;return B=B.replace(Um.caret,"$1"),I=I.replace(t,B),e},getRegex:()=>new RegExp(I,A)};return e}var Um={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:g=>new RegExp(`^( {0,3}${g})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:g=>new RegExp(`^ {0,${Math.min(3,g-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:g=>new RegExp(`^ {0,${Math.min(3,g-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:g=>new RegExp(`^ {0,${Math.min(3,g-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:g=>new RegExp(`^ {0,${Math.min(3,g-1)}}#`),htmlBeginRegex:g=>new RegExp(`^ {0,${Math.min(3,g-1)}}<(?:[a-z].*>|!--)`,"i")},Cwo=/^(?:[ \t]*(?:\n|$))+/,Qwo=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,iwo=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,$eA=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Ewo=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,mog=/(?:[*+-]|\d{1,9}[.)])/,oFI=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,BFI=Zs(oFI).replace(/bull/g,mog).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),nwo=Zs(oFI).replace(/bull/g,mog).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),pog=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,swo=/^[^\n]+/,kog=/(?!\s*\])(?:\\.|[^\[\]\\])+/,awo=Zs(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",kog).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),rwo=Zs(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,mog).getRegex(),dGA="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",Mog=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,cwo=Zs("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",Mog).replace("tag",dGA).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),CFI=Zs(pog).replace("hr",$eA).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",dGA).getRegex(),hwo=Zs(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",CFI).getRegex(),Sog={blockquote:hwo,code:Qwo,def:awo,fences:iwo,heading:Ewo,hr:$eA,html:cwo,lheading:BFI,list:rwo,newline:Cwo,paragraph:CFI,table:XeA,text:swo},QFI=Zs("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",$eA).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",dGA).getRegex(),lwo={...Sog,lheading:nwo,table:QFI,paragraph:Zs(pog).replace("hr",$eA).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",QFI).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",dGA).getRegex()},Dwo={...Sog,html:Zs(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Mog).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:XeA,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Zs(pog).replace("hr",$eA).replace("heading",` *#{1,6} *[^
5680
5680
  ]`).replace("lheading",BFI).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},dwo=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,ywo=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,iFI=/^( {2,}|\\)\n(?!\s*$)/,wwo=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,yGA=/[\p{P}\p{S}]/u,fog=/[\s\p{P}\p{S}]/u,EFI=/[^\s\p{P}\p{S}]/u,uwo=Zs(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,fog).getRegex(),nFI=/(?!~)[\p{P}\p{S}]/u,Gwo=/(?!~)[\s\p{P}\p{S}]/u,mwo=/(?:[^\s\p{P}\p{S}]|~)/u,pwo=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,sFI=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,kwo=Zs(sFI,"u").replace(/punct/g,yGA).getRegex(),Mwo=Zs(sFI,"u").replace(/punct/g,nFI).getRegex(),aFI="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Swo=Zs(aFI,"gu").replace(/notPunctSpace/g,EFI).replace(/punctSpace/g,fog).replace(/punct/g,yGA).getRegex(),fwo=Zs(aFI,"gu").replace(/notPunctSpace/g,mwo).replace(/punctSpace/g,Gwo).replace(/punct/g,nFI).getRegex(),Rwo=Zs("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,EFI).replace(/punctSpace/g,fog).replace(/punct/g,yGA).getRegex(),Nwo=Zs(/\\(punct)/,"gu").replace(/punct/g,yGA).getRegex(),xwo=Zs(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Fwo=Zs(Mog).replace("(?:-->|$)","-->").getRegex(),Uwo=Zs("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",Fwo).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),wGA=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,Jwo=Zs(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",wGA).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),rFI=Zs(/^!?\[(label)\]\[(ref)\]/).replace("label",wGA).replace("ref",kog).getRegex(),cFI=Zs(/^!?\[(ref)\](?:\[\])?/).replace("ref",kog).getRegex(),Pwo=Zs("reflink|nolink(?!\\()","g").replace("reflink",rFI).replace("nolink",cFI).getRegex(),Rog={_backpedal:XeA,anyPunctuation:Nwo,autolink:xwo,blockSkip:pwo,br:iFI,code:ywo,del:XeA,emStrongLDelim:kwo,emStrongRDelimAst:Swo,emStrongRDelimUnd:Rwo,escape:dwo,link:Jwo,nolink:cFI,punctuation:uwo,reflink:rFI,reflinkSearch:Pwo,tag:Uwo,text:wwo,url:XeA},Kwo={...Rog,link:Zs(/^!?\[(label)\]\((.*?)\)/).replace("label",wGA).getRegex(),reflink:Zs(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",wGA).getRegex()},Nog={...Rog,emStrongRDelimAst:fwo,emStrongLDelim:Mwo,url:Zs(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},Lwo={...Nog,br:Zs(iFI).replace("{2,}","*").getRegex(),text:Zs(Nog.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},uGA={normal:Sog,gfm:lwo,pedantic:Dwo},AtA={normal:Rog,gfm:Nog,breaks:Lwo,pedantic:Kwo},Ywo={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},hFI=g=>Ywo[g];function Tx(g,A){if(A){if(Um.escapeTest.test(g))return g.replace(Um.escapeReplace,hFI)}else if(Um.escapeTestNoEncode.test(g))return g.replace(Um.escapeReplaceNoEncode,hFI);return g}function lFI(g){try{g=encodeURI(g).replace(Um.percentDecode,"%")}catch{return null}return g}function DFI(g,A){const I=g.replace(Um.findPipe,(o,B,C)=>{let Q=!1,i=B;for(;--i>=0&&C[i]==="\\";)Q=!Q;return Q?"|":" |"}),e=I.split(Um.splitPipe);let t=0;if(e[0].trim()||e.shift(),e.length>0&&!e.at(-1)?.trim()&&e.pop(),A)if(e.length>A)e.splice(A);else for(;e.length<A;)e.push("");for(;t<e.length;t++)e[t]=e[t].trim().replace(Um.slashPipe,"|");return e}function gtA(g,A,I){const e=g.length;if(e===0)return"";let t=0;for(;t<e&&g.charAt(e-t-1)===A;)t++;return g.slice(0,e-t)}function _wo(g,A){if(g.indexOf(A[1])===-1)return-1;let I=0;for(let e=0;e<g.length;e++)if(g[e]==="\\")e++;else if(g[e]===A[0])I++;else if(g[e]===A[1]&&(I--,I<0))return e;return I>0?-2:-1}function dFI(g,A,I,e,t){const o=A.href,B=A.title||null,C=g[1].replace(t.other.outputLinkReplace,"$1");e.state.inLink=!0;const Q={type:g[0].charAt(0)==="!"?"image":"link",raw:I,href:o,title:B,text:C,tokens:e.inlineTokens(C)};return e.state.inLink=!1,Q}function bwo(g,A,I){const e=g.match(I.other.indentCodeCompensation);if(e===null)return A;const t=e[1];return A.split(`