@tscircuit/runframe 0.0.528 → 0.0.529

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.
@@ -640,7 +640,7 @@ Check the render method of %s.`,Zt(Kt)||"Unknown"));var Ce=Pf(G,$);Ce.payload={e
640
640
  fieldset[disabled]:not(fieldset[disabled] legend:first-of-type *)
641
641
  )`,enabled:":not(:disabled)",checked:":is(:is(input[type=radio], input[type=checkbox])[checked], option:selected)",required:":is(input, select, textarea)[required]",optional:":is(input, select, textarea):not([required])",selected:"option:is([selected], select:not([multiple]):not(:has(> option[selected])) > :first-of-type)",checkbox:"[type=checkbox]",file:"[type=file]",password:"[type=password]",radio:"[type=radio]",reset:"[type=reset]",image:"[type=image]",submit:"[type=submit]",parent:":not(:empty)",header:":is(h1, h2, h3, h4, h5, h6)",button:":is(button, input[type=button])",input:":is(input, textarea, select, button)",text:"input:is(:not([type!='']), [type=text])"},q0e={};function Kst(r,e){return r===ng.falseFunc?ng.falseFunc:t=>e.isTag(t)&&r(t)}function Z0e(r,e){const t=e.getSiblings(r);if(t.length<=1)return[];const n=t.indexOf(r);return n<0||n===t.length-1?[]:t.slice(n+1).filter(e.isTag)}function CV(r){return{xmlMode:!!r.xmlMode,lowerCaseAttributeNames:!!r.lowerCaseAttributeNames,lowerCaseTags:!!r.lowerCaseTags,quirksMode:!!r.quirksMode,cacheResults:!!r.cacheResults,pseudos:r.pseudos,adapter:r.adapter,equals:r.equals}}const _V=(r,e,t,n,i)=>{const o=i(e,CV(t),n);return o===ng.trueFunc?r:o===ng.falseFunc?ng.falseFunc:a=>o(a)&&r(a)},EV={is:_V,matches:_V,where:_V,not(r,e,t,n,i){const o=i(e,CV(t),n);return o===ng.falseFunc?r:o===ng.trueFunc?ng.falseFunc:a=>!o(a)&&r(a)},has(r,e,t,n,i){const{adapter:o}=t,a=CV(t);a.relativeSelector=!0;const s=e.some(u=>u.some(yV))?[q0e]:void 0,l=i(e,a,s);if(l===ng.falseFunc)return ng.falseFunc;const c=Kst(l,o);if(s&&l!==ng.trueFunc){const{shouldTestNextSiblings:u=!1}=l;return A=>{if(!r(A))return!1;s[0]=A;const d=o.getChildren(A),f=u?[...d,...Z0e(A,o)]:d;return o.existsOne(c,f)}}return u=>r(u)&&o.existsOne(c,o.getChildren(u))}};function jst(r,e,t,n,i){var o;const{name:a,data:s}=e;if(Array.isArray(s)){if(!(a in EV))throw new Error(`Unknown pseudo-class :${a}(${s})`);return EV[a](r,s,t,n,i)}const l=(o=t.pseudos)===null||o===void 0?void 0:o[a],c=typeof l=="string"?l:Vst[a];if(typeof c=="string"){if(s!=null)throw new Error(`Pseudo ${a} doesn't have any arguments`);const u=z0e(c);return EV.is(r,u,t,n,i)}if(typeof l=="function")return W0e(l,a,s,1),u=>l(u,s)&&r(u);if(a in vV)return vV[a](r,s,t,n);if(a in J0e){const u=J0e[a];return W0e(u,a,s,2),A=>u(A,t,s)&&r(A)}throw new Error(`Unknown pseudo-class :${a}`)}function xV(r,e){const t=e.getParent(r);return t&&e.isTag(t)?t:null}function Jst(r,e,t,n,i){const{adapter:o,equals:a}=t;switch(e.type){case Hf.PseudoElement:throw new Error("Pseudo-elements are not supported by css-select");case Hf.ColumnCombinator:throw new Error("Column combinators are not yet supported by css-select");case Hf.Attribute:{if(e.namespace!=null)throw new Error("Namespaced attributes are not yet supported by css-select");return(!t.xmlMode||t.lowerCaseAttributeNames)&&(e.name=e.name.toLowerCase()),Gst[e.action](r,e,t)}case Hf.Pseudo:return jst(r,e,t,n,i);case Hf.Tag:{if(e.namespace!=null)throw new Error("Namespaced tag names are not yet supported by css-select");let{name:s}=e;return(!t.xmlMode||t.lowerCaseTags)&&(s=s.toLowerCase()),function(c){return o.getName(c)===s&&r(c)}}case Hf.Descendant:{if(t.cacheResults===!1||typeof WeakSet>"u")return function(c){let u=c;for(;u=xV(u,o);)if(r(u))return!0;return!1};const s=new WeakSet;return function(c){let u=c;for(;u=xV(u,o);)if(!s.has(u)){if(o.isTag(u)&&r(u))return!0;s.add(u)}return!1}}case"_flexibleDescendant":return function(l){let c=l;do if(r(c))return!0;while(c=xV(c,o));return!1};case Hf.Parent:return function(l){return o.getChildren(l).some(c=>o.isTag(c)&&r(c))};case Hf.Child:return function(l){const c=o.getParent(l);return c!=null&&o.isTag(c)&&r(c)};case Hf.Sibling:return function(l){const c=o.getSiblings(l);for(let u=0;u<c.length;u++){const A=c[u];if(a(l,A))break;if(o.isTag(A)&&r(A))return!0}return!1};case Hf.Adjacent:return o.prevElementSibling?function(l){const c=o.prevElementSibling(l);return c!=null&&r(c)}:function(l){const c=o.getSiblings(l);let u;for(let A=0;A<c.length;A++){const d=c[A];if(a(l,d))break;o.isTag(d)&&(u=d)}return!!u&&r(u)};case Hf.Universal:{if(e.namespace!=null&&e.namespace!=="*")throw new Error("Namespaced universal selectors are not yet supported by css-select");return r}}}function Wst(r,e,t){const n=typeof r=="string"?z0e(r):r;return $0e(n,e,t)}function X0e(r){return r.type===Hf.Pseudo&&(r.name==="scope"||Array.isArray(r.data)&&r.data.some(e=>e.some(X0e)))}const qst={type:Hf.Descendant},Zst={type:"_flexibleDescendant"},Xst={type:Hf.Pseudo,name:"scope",data:null};function $st(r,{adapter:e},t){const n=!!(t!=null&&t.every(i=>{const o=e.isTag(i)&&e.getParent(i);return i===q0e||o&&e.isTag(o)}));for(const i of r){if(!(i.length>0&&yV(i[0])&&i[0].type!==Hf.Descendant))if(n&&!i.some(X0e))i.unshift(qst);else continue;i.unshift(Xst)}}function $0e(r,e,t){var n;r.forEach(Ust),t=(n=e.context)!==null&&n!==void 0?n:t;const i=Array.isArray(t),o=t&&(Array.isArray(t)?t:[t]);if(e.relativeSelector!==!1)$st(r,e,o);else if(r.some(l=>l.length>0&&yV(l[0])))throw new Error("Relative selectors are not allowed when the `relativeSelector` option is disabled");let a=!1;const s=r.map(l=>{if(l.length>=2){const[c,u]=l;c.type!==Hf.Pseudo||c.name!=="scope"||(i&&u.type===Hf.Descendant?l[1]=Zst:(u.type===Hf.Adjacent||u.type===Hf.Sibling)&&(a=!0))}return elt(l,e,o)}).reduce(tlt,ng.falseFunc);return s.shouldTestNextSiblings=a,s}function elt(r,e,t){var n;return r.reduce((i,o)=>i===ng.falseFunc?ng.falseFunc:Jst(i,o,e,t,$0e),(n=e.rootFunc)!==null&&n!==void 0?n:ng.trueFunc)}function tlt(r,e){return e===ng.falseFunc||r===ng.trueFunc?r:r===ng.falseFunc||e===ng.trueFunc?e:function(n){return r(n)||e(n)}}const eme=(r,e)=>r===e,nlt={adapter:F0e,equals:eme};function rlt(r){var e,t,n,i;const o=r??nlt;return(e=o.adapter)!==null&&e!==void 0||(o.adapter=F0e),(t=o.equals)!==null&&t!==void 0||(o.equals=(i=(n=o.adapter)===null||n===void 0?void 0:n.equals)!==null&&i!==void 0?i:eme),o}function tme(r){return function(t,n,i){const o=rlt(i);typeof t!="function"&&(t=Wst(t,o,n));const a=ilt(n,o.adapter,t.shouldTestNextSiblings);return r(t,a,o)}}function ilt(r,e,t=!1){return t&&(r=olt(r,e)),Array.isArray(r)?e.removeSubsets(r):e.getChildren(r)}function olt(r,e){const t=Array.isArray(r)?r.slice(0):[r],n=t.length;for(let i=0;i<n;i++){const o=Z0e(t[i],e);t.push(...o)}return t}const yM=tme((r,e,t)=>r===ng.falseFunc||!e||e.length===0?[]:t.adapter.findAll(r,e)),YS=tme((r,e,t)=>r===ng.falseFunc||!e||e.length===0?null:t.adapter.findOne(r,e));var bV=(r,e={})=>{let t=r._internal_store;if(!t){t={counts:{}},r._internal_store=t;for(const i of r){const o=i.type,a=i[`${o}_id`];if(!a)continue;const s=Number.parseInt(a.split("_").pop());Number.isNaN(s)||(t.counts[o]=Math.max(t.counts[o]??0,s))}}return new Proxy({},{get:(i,o)=>o==="toArray"?()=>r:{get:a=>r.find(s=>s.type===o&&s[`${o}_id`]===a),getUsing:a=>{const s=Object.keys(a);if(s.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const l=s[0],c=l.replace("_id",""),u=r.find(A=>A.type===c&&A[l]===a[l]);return u?r.find(A=>A.type===o&&A[`${o}_id`]===u[`${o}_id`]):null},getWhere:a=>{const s=Object.keys(a);return r.find(l=>l.type===o&&s.every(c=>l[c]===a[c]))},list:a=>{const s=a?Object.keys(a):[];return r.filter(l=>l.type===o&&s.every(c=>l[c]===a[c]))},insert:a=>{var c;(c=t.counts)[o]??(c[o]=-1),t.counts[o]++;const s=t.counts[o],l={type:o,[`${o}_id`]:`${o}_${s}`,...a};return e.validateInserts&&(XT[o]??cR).parse(l),r.push(l),l},delete:a=>{const s=r.find(l=>l[`${o}_id`]===a);s&&r.splice(r.indexOf(s),1)},update:(a,s)=>{const l=r.find(c=>c.type===o&&c[`${o}_id`]===a);if(l)return Object.assign(l,s),l},select:a=>{if(o==="source_component")return r.find(s=>s.type==="source_component"&&s.name===a.replace(/\./g,""));if(o==="pcb_port"||o==="source_port"||o==="schematic_port"){const[s,l]=a.replace(/\./g,"").split(/[\s\>]+/),c=r.find(A=>A.type==="source_component"&&A.name===s);if(!c)return null;const u=r.find(A=>A.type==="source_port"&&A.source_component_id===c.source_component_id&&(A.name===l||(A.port_hints??[]).includes(l)));if(!u)return null;if(o==="source_port")return u;if(o==="pcb_port")return r.find(A=>A.type==="pcb_port"&&A.source_port_id===u.source_port_id);if(o==="schematic_port")return r.find(A=>A.type==="schematic_port"&&A.source_port_id===u.source_port_id)}}}})};bV.unparsed=bV;var dm=bV,cQ={exports:{}},alt=cQ.exports,nme;function slt(){return nme||(nme=1,(function(){var r,e,t,n,i,o;typeof performance<"u"&&performance!==null&&performance.now?cQ.exports=function(){return performance.now()}:typeof process<"u"&&process!==null&&process.hrtime?(cQ.exports=function(){return(r()-i)/1e6},e=process.hrtime,r=function(){var a;return a=e(),a[0]*1e9+a[1]},n=r(),o=process.uptime()*1e9,i=n-o):Date.now?(cQ.exports=function(){return Date.now()-t},t=Date.now()):(cQ.exports=function(){return new Date().getTime()-t},t=new Date().getTime())}).call(alt)),cQ.exports}slt();function llt([r,e],[t,n],{lineThickness:i=0}={}){return i===0?rme(r,e,t,n):clt(r,e,t,n)<=i}function rme(r,e,t,n){const i=z8(r,e,t),o=z8(r,e,n),a=z8(t,n,r),s=z8(t,n,e);return!!(i!==o&&a!==s||i===0&&H8(r,t,e)||o===0&&H8(r,n,e)||a===0&&H8(t,r,n)||s===0&&H8(t,e,n))}function z8(r,e,t){const n=(e.y-r.y)*(t.x-e.x)-(e.x-r.x)*(t.y-e.y);return n===0?0:n>0?1:2}function H8(r,e,t){return e.x<=Math.max(r.x,t.x)&&e.x>=Math.min(r.x,t.x)&&e.y<=Math.max(r.y,t.y)&&e.y>=Math.min(r.y,t.y)}function clt(r,e,t,n){if(r.x===e.x&&r.y===e.y)return vM(r,t,n);if(t.x===n.x&&t.y===n.y)return vM(t,r,e);if(rme(r,e,t,n))return 0;const i=[vM(r,t,n),vM(e,t,n),vM(t,r,e),vM(n,r,e)];return Math.min(...i)}function vM(r,e,t){const n=(t.x-e.x)**2+(t.y-e.y)**2;if(n===0)return ime(r,e);let i=((r.x-e.x)*(t.x-e.x)+(r.y-e.y)*(t.y-e.y))/n;i=Math.max(0,Math.min(1,i));const o={x:e.x+i*(t.x-e.x),y:e.y+i*(t.y-e.y)};return ime(r,o)}function ime(r,e){const t=r.x-e.x,n=r.y-e.y;return Math.sqrt(t*t+n*n)}function ome(r){const e=new Map;let t=0;function n(i){for(const[,a]of e)if(a.has(i))return a;const o=new Set;return e.set(`connectivity_net${t++}`,o),o}for(const i of r){let o=null;for(const a of i){if(!o)o=n(a);else if(!o.has(a)){const s=n(a);if(s!==o){for(const l of s)o.add(l);e.delete(Array.from(e.entries()).find(([,l])=>l===s)[0])}}o.add(a)}}return Object.fromEntries(Array.from(e.entries()).map(([i,o])=>[i,Array.from(o)]))}var uQ=class{constructor(e){Le(this,"netMap");Le(this,"idToNetMap");this.netMap=e,this.idToNetMap={};for(const[t,n]of Object.entries(e))for(const i of n)this.idToNetMap[i]=t}addConnections(e){for(const t of e){const n=new Set;for(const o of t){const a=this.idToNetMap[o];a&&n.add(a)}let i;if(n.size===0)i=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[i]=[];else if(n.size===1)i=n.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{i=n.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const o of n)if(o!==i){this.netMap[i].push(...this.netMap[o]),this.netMap[o]=this.netMap[i];for(const a of this.netMap[i])this.idToNetMap[a]=i}}for(const o of t)this.netMap[i].includes(o)||this.netMap[i].push(o),this.idToNetMap[o]=i}}getIdsConnectedToNet(e){return this.netMap[e]||[]}getNetConnectedToId(e){return this.idToNetMap[e]}areIdsConnected(e,t){if(e===t)return!0;const n=this.getNetConnectedToId(e);if(!n)return!1;const i=this.getNetConnectedToId(t);return i?n===i||i===e||i===e:!1}areAllIdsConnected(e){const t=this.getNetConnectedToId(e[0]);for(const n of e){const i=this.getNetConnectedToId(n);if(i===void 0||i!==t)return!1}return!0}},AB=r=>{var n,i;const e=[];for(const o of r)if(o.type==="source_trace")e.push([o.source_trace_id,...o.connected_source_port_ids??[],...o.connected_source_net_ids??[]].filter(Boolean));else if(o.type==="pcb_port"){const{pcb_port_id:a,source_port_id:s}=o;s&&a&&e.push([s,a])}else if(o.type==="pcb_smtpad"){const{pcb_smtpad_id:a,pcb_port_id:s}=o;s&&a&&e.push([a,s])}else if(o.type==="pcb_plated_hole"){const{pcb_plated_hole_id:a,pcb_port_id:s}=o;s&&a&&e.push([a,s])}else if(o.type==="pcb_trace"){const{pcb_trace_id:a,source_trace_id:s}=o,l=Array.isArray(o.route)?o.route.filter(c=>c&&c.route_type==="wire"):[];if(s&&a&&e.push([a,s]),Array.isArray(l)){const c=(n=l.find(A=>A&&A.start_pcb_port_id))==null?void 0:n.start_pcb_port_id,u=(i=l.find(A=>A&&A.end_pcb_port_id))==null?void 0:i.end_pcb_port_id;c&&a&&u&&e.push([c,a,u])}}else if(o.type==="pcb_via"){const{pcb_via_id:a,pcb_trace_id:s}=o;s&&a&&e.push([a,s])}else if(o.type==="source_component"&&o.internally_connected_source_port_ids)for(const a of o.internally_connected_source_port_ids)e.push(a);const t=ome(e);return new uQ(t)},ame=class{constructor(r){Le(this,"circuitJson");Le(this,"traceIdToElm");Le(this,"portIdToElm");Le(this,"connMap");this.circuitJson=r||[],this.traceIdToElm=new Map,this.portIdToElm=new Map,r?(this._buildTraceMap(),this._buildPortMap(),this.connMap=this._buildTraceConnectivityMap()):this.connMap=new uQ({})}_buildPortMap(){for(const r of this.circuitJson)r.type==="pcb_port"&&this.portIdToElm.set(r.pcb_port_id,r)}_buildTraceMap(){for(const r of this.circuitJson)r.type==="pcb_trace"&&this.traceIdToElm.set(r.pcb_trace_id,r)}_buildTraceConnectivityMap(){const r=[],e=Array.from(this.traceIdToElm.keys());for(let t=0;t<e.length;t++)for(let n=t+1;n<e.length;n++){const i=this.traceIdToElm.get(e[t]),o=this.traceIdToElm.get(e[n]);this._arePcbTracesConnected(i,o)&&r.push([e[t],e[n]])}for(const t of this.portIdToElm.values())for(const n of this.traceIdToElm.values())for(const i of n.route)i.route_type==="wire"&&(i.start_pcb_port_id===t.pcb_port_id?r.push([t.pcb_port_id,n.pcb_trace_id]):i.end_pcb_port_id===t.pcb_port_id&&r.push([n.pcb_trace_id,t.pcb_port_id]));return new uQ(ome(r))}addTrace(r){this.traceIdToElm.set(r.pcb_trace_id,r);const e=[];for(const t of r.route)t.route_type==="wire"&&(t.start_pcb_port_id&&e.push([t.start_pcb_port_id,r.pcb_trace_id]),t.end_pcb_port_id&&e.push([t.end_pcb_port_id,r.pcb_trace_id]));this.connMap.addConnections(e)}_arePcbTracesConnected(r,e){for(let t=0;t<r.route.length-1;t++){const n=r.route[t],i=r.route[t+1];if(n.route_type==="wire"&&i.route_type==="wire")for(let o=0;o<e.route.length-1;o++){const a=e.route[o],s=e.route[o+1];if(a.route_type!=="wire"||s.route_type!=="wire")continue;if(llt([n,i],[a,s],{lineThickness:(n.width+a.width)/2}))return!0}}return!1}areTracesConnected(r,e){return this.connMap.areIdsConnected(r,e)}getAllTracesConnectedToTrace(r){const e=this.connMap.getNetConnectedToId(r);return e?this.connMap.getIdsConnectedToNet(e).filter(t=>this.traceIdToElm.has(t)).map(t=>this.traceIdToElm.get(t)):[]}getAllTracesConnectedToPort(r){const e=this.connMap.getNetConnectedToId(r);return e?this.connMap.getIdsConnectedToNet(e).filter(t=>this.traceIdToElm.has(t)).map(t=>this.traceIdToElm.get(t)):[]}};function sme(r){const e=r.width/2,t=r.height/2;return{minX:r.center.x-e,maxX:r.center.x+e,minY:r.center.y-t,maxY:r.center.y+t}}function ult(r,e){const t=sme(r),n=sme(e),i=Math.max(t.minX-n.maxX,n.minX-t.maxX,0),o=Math.max(t.minY-n.maxY,n.minY-t.maxY,0),a={x:0,y:0},s={x:0,y:0};return i===0&&o===0?{distance:0,pointA:r.center,pointB:e.center}:(a.x=$2(r.center.x,n.minX,n.maxX),a.y=$2(r.center.y,n.minY,n.maxY),s.x=$2(e.center.x,t.minX,t.maxX),s.y=$2(e.center.y,t.minY,t.maxY),{distance:Math.hypot(a.x-s.x,a.y-s.y),pointA:a,pointB:s})}function $2(r,e,t){return Math.max(e,Math.min(t,r))}function Alt(r,e){let t=Number.POSITIVE_INFINITY,n={x:0,y:0},i={x:0,y:0};for(const o of r)for(const a of e){const{distance:s,pointA:l,pointB:c}=ult(o,a);s<t&&(t=s,n=l,i=c)}return{pointA:n,pointB:i,distance:t}}var AQ=(r,e)=>Math.abs(r.x-e.x)+Math.abs(r.y-e.y),lme=(r,e)=>{const t=e.x-r.x,n=e.y-r.y;return Math.abs(t)>Math.abs(n)?{dx:Math.sign(t),dy:0}:{dx:0,dy:Math.sign(n)}},cme=(r,e,t)=>Math.abs(r.x-e.x)*Math.abs(t.dx)+Math.abs(r.y-e.y)*Math.abs(t.dy),ume=(r,e=.1)=>`${Math.round(r.x/e)},${Math.round(r.y/e)}`,Ame=(r,e)=>Math.abs(r-e)<1e-4,dme=(r,e,{viaDiameter:t=.5}={})=>{const n=[];for(let i=0;i<r.length-1;i++){const[o,a]=[r[i],r[i+1]],s=i-1>=0?r[i-1]:null,l=Ame(o.y,a.y),c=Ame(o.x,a.x);if(!l&&!c)throw new Error(`getObstaclesFromTrace currently only supports horizontal and vertical traces (not diagonals) Conflicting trace: ${e}, start: (${o.x}, ${o.y}), end: (${a.x}, ${a.y})`);const u={type:"rect",layers:[o.layer],center:{x:(o.x+a.x)/2,y:(o.y+a.y)/2},width:l?Math.abs(o.x-a.x):.1,height:c?Math.abs(o.y-a.y):.1,connectedTo:[e]};if(n.push(u),s&&s.layer===o.layer&&o.layer!==a.layer){const A={type:"rect",layers:[o.layer,a.layer],center:{x:o.x,y:o.y},connectedTo:[e],width:t,height:t};n.push(A)}}return n},fme=class{constructor(r){Le(this,"obstacles");Le(this,"GRID_STEP",.1);this.obstacles=r.map(e=>({...e,left:e.center.x-e.width/2,right:e.center.x+e.width/2,top:e.center.y+e.height/2,bottom:e.center.y-e.height/2}))}getObstacleAt(r,e,t){t??(t=this.GRID_STEP);for(const n of this.obstacles){const i=n.width/2+t,o=n.height/2+t;if(r>=n.center.x-i&&r<=n.center.x+i&&e>=n.center.y-o&&e<=n.center.y+o)return n}return null}isObstacleAt(r,e,t){return this.getObstacleAt(r,e,t)!==null}getDirectionDistancesToNearestObstacle(r,e){const{GRID_STEP:t}=this,n={left:1/0,top:1/0,bottom:1/0,right:1/0};for(const i of this.obstacles)if(i.type==="rect"){const o=i.center.x-i.width/2-t,a=i.center.x+i.width/2+t,s=i.center.y+i.height/2+t,l=i.center.y-i.height/2-t;e>=l&&e<=s&&r>o&&(n.left=Math.min(n.left,r-a)),e>=l&&e<=s&&r<a&&(n.right=Math.min(n.right,o-r)),r>=o&&r<=a&&e<s&&(n.top=Math.min(n.top,l-e)),r>=o&&r<=a&&e>l&&(n.bottom=Math.min(n.bottom,e-s))}return n}getOrthoDirectionCollisionInfo(r,e,{margin:t=0}={}){const{x:n,y:i}=r,{dx:o,dy:a}=e;let s=1/0,l=null;for(const c of this.obstacles){const u=c.left-t,A=c.right+t,d=c.top+t,f=c.bottom-t;let p=null;o===1&&a===0?i>f&&i<d&&n<c.left&&(p=c.left-n):o===-1&&a===0?i>f&&i<d&&n>c.right&&(p=n-c.right):o===0&&a===1?n>u&&n<A&&i<c.bottom&&(p=c.bottom-i):o===0&&a===-1&&n>u&&n<A&&i>c.top&&(p=i-c.top),p!==null&&p<s&&(s=p,l=c)}return{dx:o,dy:a,wallDistance:s,obstacle:l}}getObstaclesOverlappingRegion(r){const e=[];for(const t of this.obstacles){const{left:n,right:i,top:o,bottom:a}=t;n<=r.maxX&&i>=r.minX&&o<=r.maxY&&a>=r.minY&&e.push(t)}return e}};function dlt(r){if(r.length<4)return r;const e=[{...r[0]}];let t=r[0].layer;for(let n=1;n<r.length;n++){const i={start:r[n-1],end:r[n]},o=r[n].route_type==="via"||r[n-1].route_type==="via";if(r[n].layer!==t||o){e.push({...r[n]}),t=r[n].layer;continue}let a=!1,s=null,l=-1;for(let u=0;u<e.length-1;u++){const A={start:e[u],end:e[u+1]};if(A.start.layer===i.start.layer&&A.start.layer===i.start.layer){const d=flt(A,i);if(d){a=!0,s={...d,layer:t},l=u;break}}}a&&s&&(e.splice(l+1),e.push(s));const c=e[e.length-1];(c.x!==r[n].x||c.y!==r[n].y)&&e.push(r[n])}return e}function flt(r,e){if(r.start.x===r.end.x&&e.start.x===e.end.x||r.start.y===r.end.y&&e.start.y===e.end.y)return null;let t;if(r.start.x===r.end.x){const n=r.start.x,i=e.start.y;t={...r.start,x:n,y:i}}else{const n=e.start.x,i=r.start.y;t={...r.start,x:n,y:i}}return hme(t,r)&&hme(t,e)?t:null}function hme(r,e){return r.x>=Math.min(e.start.x,e.end.x)&&r.x<=Math.max(e.start.x,e.end.x)&&r.y>=Math.min(e.start.y,e.end.y)&&r.y<=Math.max(e.start.y,e.end.y)}function hlt(r){const e=[r[0]];for(let t=1;t<r.length-1;t++){const[n,i,o]=[r[t-1],r[t],r[t+1]];e.push(i),!(i.route_type!=="wire"||n.route_type!=="wire"||o.route_type!=="wire")&&n.layer===i.layer&&i.layer!==o.layer&&e.push({route_type:"via",from_layer:i.layer,to_layer:o.layer,x:i.x,y:i.y})}return e.push(r[r.length-1]),e}u0("autorouter:shortenPathWithShortcuts");function plt(r,e){if(r.length<=2)return r;const t=[r[0]];for(let n=1;n<r.length;n++){const i={start:t[t.length-1],end:r[n]};let o=-1;const a=i.start.x===i.end.x,s=i.start.y===i.end.y;for(let l=n+1;l<r.length;l++){if(l<=o)continue;const c={start:r[l],end:r[l+1]};if(!c.end)continue;const u=c.start.x===c.end.x,A=c.start.y===c.end.y,d=a&&u,f=s&&A;if(f&&d||!(d||f))continue;let C=!1;const v=Math.min(i.start.x,i.end.x),_=Math.max(i.start.x,i.end.x),x=Math.min(c.start.x,c.end.x),b=Math.max(c.start.x,c.end.x),P=Math.min(i.start.y,i.end.y),F=Math.max(i.start.y,i.end.y),U=Math.min(c.start.y,c.end.y),H=Math.max(c.start.y,c.end.y);if(f?C=v<=b&&_>=x:d&&(C=P<=H&&F>=U),!C)continue;const L=[],j=t[t.length-1],O=r[l+2];if(!O)continue;f&&x<_&&O.x===x&&L.push({x,y:i.start.y,layer:i.start.layer}),f&&b>v&&O.x===b&&L.push({x:b,y:i.start.y,layer:i.start.layer}),d&&U<F&&O.y===U&&L.push({x:i.start.x,y:U,layer:i.start.layer}),d&&H>P&&O.y===H&&L.push({x:i.start.x,y:H,layer:i.start.layer});let oe=null;for(const te of L)if(!(e(j,te)||e(O,te))){oe=te;break}if(oe){t.push(oe),n=l+1,o=l+1;break}}o===-1&&t.push(r[n])}return t[t.length-1]!==r[r.length-1]&&t.push(r[r.length-1]),t}var dQ=u0("autorouting-dataset:astar"),pme=class{constructor(r){Le(this,"openSet",[]);Le(this,"closedSet",new Set);Le(this,"debug",!1);Le(this,"debugSolutions");Le(this,"debugMessage",null);Le(this,"debugTraceCount",0);Le(this,"input");Le(this,"obstacles");Le(this,"allObstacles");Le(this,"startNode");Le(this,"goalPoint");Le(this,"GRID_STEP");Le(this,"OBSTACLE_MARGIN");Le(this,"MAX_ITERATIONS");Le(this,"isRemovePathLoopsEnabled");Le(this,"isShortenPathWithShortcutsEnabled");Le(this,"GREEDY_MULTIPLIER",1.1);Le(this,"iterations",-1);this.input=r.input,this.allObstacles=r.input.obstacles,this.startNode=r.startNode,this.goalPoint=r.goalPoint?{l:0,...r.goalPoint}:void 0,this.GRID_STEP=r.GRID_STEP??.1,this.OBSTACLE_MARGIN=r.OBSTACLE_MARGIN??.15,this.MAX_ITERATIONS=r.MAX_ITERATIONS??100,this.debug=r.debug??dQ.enabled,this.isRemovePathLoopsEnabled=r.isRemovePathLoopsEnabled??!1,this.isShortenPathWithShortcutsEnabled=r.isShortenPathWithShortcutsEnabled??!1,this.debug&&(dQ.enabled=!0),dQ.enabled&&(this.debugSolutions={},this.debugMessage="")}getNeighbors(r){return[]}isSameNode(r,e){return AQ(r,e)<this.GRID_STEP}computeG(r,e){return r.g+AQ(r,e)}computeH(r){return AQ(r,this.goalPoint)}getNodeName(r){return ume(r,this.GRID_STEP)}solveOneStep(){this.iterations+=1;const{openSet:r,closedSet:e,GRID_STEP:t,goalPoint:n}=this;r.sort((s,l)=>s.f-l.f);const i=r.shift();if(this.computeH(i)<=t*2)return{solved:!0,current:i,newNeighbors:[]};this.closedSet.add(this.getNodeName(i));let a=[];for(const s of this.getNeighbors(i)){if(e.has(this.getNodeName(s)))continue;const l=this.computeG(i,s),c=this.openSet.find(u=>this.isSameNode(u,s));if(!c||l<c.g){const u=this.computeH(s),A=l+u*this.GREEDY_MULTIPLIER,d={...s,g:l,h:u,f:A,obstacleHit:s.obstacleHit??void 0,manDistFromParent:AQ(i,s),nodesInPath:i.nodesInPath+1,parent:i,enterMarginCost:s.enterMarginCost,travelMarginCostFactor:s.travelMarginCostFactor};r.push(d),a.push(d)}}return dQ.enabled&&(r.sort((s,l)=>s.f-l.f),this.drawDebugSolution({current:i,newNeighbors:a})),{solved:!1,current:i,newNeighbors:a}}getStartNode(r){return{x:r.pointsToConnect[0].x,y:r.pointsToConnect[0].y,manDistFromParent:0,f:0,g:0,h:0,nodesInPath:0,parent:null}}layerToIndex(r){return 0}indexToLayer(r){return"top"}preprocessConnectionBeforeSolving(r){return r}solveConnection(r){if(r.pointsToConnect.length>2)throw new Error("GeneralizedAstarAutorouter doesn't currently support 2+ points in a connection");r=this.preprocessConnectionBeforeSolving(r);const{pointsToConnect:e}=r;for(this.iterations=0,this.closedSet=new Set,this.startNode=this.getStartNode(r),this.goalPoint={...e[e.length-1],l:this.layerToIndex(e[e.length-1].layer)},this.openSet=[this.startNode];this.iterations<this.MAX_ITERATIONS;){const{solved:t,current:n}=this.solveOneStep();if(t){let i=[],o=n;for(;o;){const a=o.l;i.unshift({x:o.x,y:o.y,layer:a!==void 0?this.indexToLayer(a):e[0].layer}),o=o.parent}return dQ.enabled&&(this.debugMessage+=`t${this.debugTraceCount}: ${this.iterations} iterations
642
642
  `),this.isRemovePathLoopsEnabled&&(i=dlt(i)),this.isShortenPathWithShortcutsEnabled&&(i=plt(i,(a,s)=>{if(a.x===s.x&&a.y===s.y)return!1;const l=this.obstacles.getOrthoDirectionCollisionInfo({x:a.x,y:a.y,l:this.layerToIndex(a.layer)??0},{dx:Math.sign(s.x-a.x),dy:Math.sign(s.y-a.y),dl:0},{margin:.05}),c=Math.sqrt((a.x-s.x)**2+(a.y-s.y)**2);return l.wallDistance<c})),{solved:!0,route:i,connectionName:r.name}}if(this.openSet.length===0)break}return dQ.enabled&&(this.debugMessage+=`t${this.debugTraceCount}: ${this.iterations} iterations (failed)
643
- `),{solved:!1,connectionName:r.name}}createObstacleList({dominantLayer:r,connection:e,obstaclesFromTraces:t}){return new fme(this.allObstacles.filter(n=>!n.connectedTo.includes(e.name)).filter(n=>n.layers.includes(r)).concat(t??[]))}postprocessConnectionSolveResult(r,e){return e}solve(){const r=[],e=[];this.debugTraceCount=0;for(const t of this.input.connections){const n=t.pointsToConnect[0].layer??"top";this.debugTraceCount+=1,this.obstacles=this.createObstacleList({dominantLayer:n,connection:t,obstaclesFromTraces:e});let i=this.solveConnection(t);i=this.postprocessConnectionSolveResult(t,i),r.push(i),dQ.enabled&&this.drawDebugTraceObstacles(e),i.solved&&e.push(...dme(i.route.map(o=>({x:o.x,y:o.y,layer:o.layer??n})),t.name))}return r}solveAndMapToTraces(){return this.solve().flatMap(e=>e.solved?[{type:"pcb_trace",pcb_trace_id:`pcb_trace_for_${e.connectionName}`,route:hlt(e.route.map(t=>({route_type:"wire",x:t.x,y:t.y,width:this.input.minTraceWidth,layer:t.layer})))}]:[])}getDebugGroup(){const r=`t${this.debugTraceCount}_iter[${this.iterations-1}]`;return this.iterations<30||this.iterations<100&&this.iterations%10===0||this.iterations<1e3&&this.iterations%100===0||!this.debugSolutions?r:null}drawDebugTraceObstacles(r){const{debugTraceCount:e,debugSolutions:t}=this;for(const n in t)n.startsWith(`t${e}_`)&&t[n].push(...r.map((i,o)=>({type:"pcb_smtpad",pcb_component_id:"",layer:i.layers[0],width:i.width,shape:"rect",x:i.center.x,y:i.center.y,pcb_smtpad_id:`trace_obstacle_${o}`,height:i.height})))}drawDebugSolution({current:r,newNeighbors:e}){const t=this.getDebugGroup();if(!t)return;const{openSet:n,debugTraceCount:i,debugSolutions:o}=this;o[t]??(o[t]=[]);const a=o[t];a.push({type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:`debug_note_${r.x}_${r.y}`,font:"tscircuit2024",font_size:.25,text:"X"+(r.l!==void 0?r.l:""),pcb_component_id:"",layer:"top",anchor_position:{x:r.x,y:r.y},anchor_alignment:"center"});for(let s=0;s<n.length;s++){const l=n[s];a.push({type:"pcb_fabrication_note_path",pcb_component_id:"",pcb_fabrication_note_path_id:`note_path_${l.x}_${l.y}`,layer:"top",route:[[0,.05],[.05,0],[0,-.05],[-.05,0],[0,.05]].map(([c,u])=>({x:l.x+c,y:l.y+u})),stroke_width:.01}),a.push({type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:`debug_note_${l.x}_${l.y}`,font:"tscircuit2024",font_size:.03,text:s.toString(),pcb_component_id:"",layer:"top",anchor_position:{x:l.x,y:l.y},anchor_alignment:"center"})}if(r.parent){const s=[];let l=r;for(;l;)s.unshift(l),l=l.parent;a.push({type:"pcb_fabrication_note_path",pcb_component_id:"",pcb_fabrication_note_path_id:`note_path_${r.x}_${r.y}`,layer:"top",route:s,stroke_width:.01})}}},glt=u0("autorouting-dataset:infinite-grid-ijump-astar:get-distance-to-overcome-obstacle");function BV({node:r,travelDir:e,wallDir:t,obstacle:n,obstacles:i,obstaclesInRow:o=0,OBSTACLE_MARGIN:a=.15,SHOULD_DETECT_CONJOINED_OBSTACLES:s=!1,MAX_CONJOINED_OBSTACLES:l=20}){let c;if(e.dx===0?e.dy>0?c=n.center.y+n.height/2-r.y:c=r.y-(n.center.y-n.height/2):e.dx>0?c=n.center.x+n.width/2-r.x:c=r.x-(n.center.x-n.width/2),c+=a,s&&o<l){const u=i.getObstacleAt(r.x+e.dx*c+t.dx*(t.wallDistance+.001),r.y+e.dy*c+t.dy*(t.wallDistance+.001));if(u===n)return c;if(u&&u.type==="rect"){const A=e.dy===0,d=A?n.height:n.width;if((A?u.height:u.width)>d)return glt("next obstacle on path is bigger, not trying to overcome it"),c;const p=BV({node:{x:r.x+e.dx*c,y:r.y+e.dy*c},travelDir:e,wallDir:t,obstacle:u,obstacles:i,obstaclesInRow:o+1,SHOULD_DETECT_CONJOINED_OBSTACLES:s,MAX_CONJOINED_OBSTACLES:l,OBSTACLE_MARGIN:a});c+=p}}return c}var mlt=class extends pme{constructor(){super(...arguments);Le(this,"MAX_ITERATIONS",200)}getNeighbors(e){const t=this.obstacles,n=this.goalPoint;let i;e.parent?i=lme(e.parent,e):i=lme(e,n);const o=[{dx:0,dy:1},{dx:1,dy:0},{dx:0,dy:-1},{dx:-1,dy:0}].filter(s=>{var l;return s.dx===i.dx*-1&&s.dy===i.dy*-1?!1:!(s.dx===i.dx&&s.dy===i.dy&&((l=e.parent)!=null&&l.obstacleHit))}).map(s=>t.getOrthoDirectionCollisionInfo(e,s,{margin:this.OBSTACLE_MARGIN})).filter(s=>s.wallDistance>=this.OBSTACLE_MARGIN),a=[];for(const s of o){let l=null;e!=null&&e.obstacleHit&&(l=BV({node:e,travelDir:s,wallDir:{...i,wallDistance:this.OBSTACLE_MARGIN},obstacle:e.obstacleHit,obstacles:t,OBSTACLE_MARGIN:this.OBSTACLE_MARGIN,SHOULD_DETECT_CONJOINED_OBSTACLES:!0}));const c=cme(e,n,s),u=(s.dx===0||Math.sign(n.x-e.x)===s.dx)&&(s.dy===0||Math.sign(n.y-e.y)===s.dy);c<s.wallDistance&&c>0&&u?a.push({...s,travelDistance:c}):l!==null&&l<s.wallDistance?a.push({...s,travelDistance:l}):s.wallDistance!==1/0&&a.push({...s,travelDistance:s.wallDistance-this.OBSTACLE_MARGIN})}return a.filter(s=>!t.isObstacleAt(e.x+s.dx*s.travelDistance,e.y+s.dy*s.travelDistance)).map(s=>({x:e.x+s.dx*s.travelDistance,y:e.y+s.dy*s.travelDistance,obstacleHit:s.obstacle}))}};function ylt(r,e=4){const{center:t,width:n,height:i,rotation:o}=r,a=[],s=o*Math.PI/180,l=Math.cos(s),c=Math.sin(s),u=(o%360+360)%360;if(i<=n?u>=45&&u<135||u>=225&&u<315:u>=135&&u<225||u>=315||u<45){const d=n/e;for(let f=0;f<e;f++){const p=(f-e/2+.5)*d,C=-p*l,v=-p*c,_=d*1.1,x=Math.abs(i*l)+Math.abs(d*c);a.push({center:{x:t.x+C,y:t.y+v},width:_,height:x})}}else{const d=i/e;for(let f=0;f<e;f++){const p=(f-e/2+.5)*d,C=-p*c,v=p*l,_=Math.abs(n*l)+Math.abs(d*c),x=d*1.1;a.push({center:{x:t.x+C,y:t.y+v},width:_,height:x})}}return a}var Y8=["top","inner1","inner2","bottom"],SV=(r,e)=>{const t=i=>e?i.concat(i.map(o=>e==null?void 0:e.getNetConnectedToId(o)).filter(Boolean)):i,n=[];for(const i of r)if(i.type==="pcb_smtpad"){if(i.shape==="circle")n.push({type:"oval",layers:[i.layer],center:{x:i.x,y:i.y},width:i.radius*2,height:i.radius*2,connectedTo:t([i.pcb_smtpad_id])});else if(i.shape==="rect")n.push({type:"rect",layers:[i.layer],center:{x:i.x,y:i.y},width:i.width,height:i.height,connectedTo:t([i.pcb_smtpad_id])});else if(i.shape==="rotated_rect"){const o={center:{x:i.x,y:i.y},width:i.width,height:i.height,rotation:i.ccw_rotation},a=ylt(o);for(const s of a)n.push({type:"rect",layers:[i.layer],center:s.center,width:s.width,height:s.height,connectedTo:t([i.pcb_smtpad_id])})}}else if(i.type==="pcb_keepout")i.shape==="circle"?n.push({type:"oval",layers:i.layers,center:{x:i.center.x,y:i.center.y},width:i.radius*2,height:i.radius*2,connectedTo:[]}):i.shape==="rect"&&n.push({type:"rect",layers:i.layers,center:{x:i.center.x,y:i.center.y},width:i.width,height:i.height,connectedTo:[]});else if(i.type==="pcb_hole")i.hole_shape==="oval"?n.push({type:"oval",center:{x:i.x,y:i.y},width:i.hole_width,height:i.hole_height,connectedTo:[]}):i.hole_shape==="square"?n.push({type:"rect",layers:Y8,center:{x:i.x,y:i.y},width:i.hole_diameter,height:i.hole_diameter,connectedTo:[]}):(i.hole_shape==="round"||i.hole_shape==="circle")&&n.push({type:"rect",layers:Y8,center:{x:i.x,y:i.y},width:i.hole_diameter,height:i.hole_diameter,connectedTo:[]});else if(i.type==="pcb_plated_hole")i.shape==="circle"?n.push({type:"oval",layers:Y8,center:{x:i.x,y:i.y},width:i.outer_diameter,height:i.outer_diameter,connectedTo:t([i.pcb_plated_hole_id])}):(i.shape==="oval"||i.shape==="pill")&&n.push({type:"oval",layers:Y8,center:{x:i.x,y:i.y},width:i.outer_width,height:i.outer_height,connectedTo:t([i.pcb_plated_hole_id])});else if(i.type==="pcb_trace"){const o=dme(i.route.map(a=>({x:a.x,y:a.y,layer:"layer"in a?a.layer:a.from_layer})),i.source_trace_id);n.push(...o)}else i.type==="pcb_via"&&n.push({type:"rect",layers:i.layers,center:{x:i.x,y:i.y},connectedTo:[],width:i.outer_diameter,height:i.outer_diameter});return n};function gme(r){const{pcbConnMap:e,goalElementId:t}=r;if(!t.startsWith("pcb_port_"))throw new Error(`Currently alternative goal boxes must have a goal id with prefix "pcb_port_" (got ${t})`);const n=e.getAllTracesConnectedToPort(t);return SV(n).map(i=>({...i,connectedTo:[t]}))}var mme=r=>{let{connection:e,pcbConnMap:t}=r;if(e.pointsToConnect.length!==2)throw new Error(`Connection must have exactly 2 points for alternative goal boxes (got ${e.pointsToConnect.length})`);const[n,i]=e.pointsToConnect;if(!n.pcb_port_id||!i.pcb_port_id)throw new Error(`Connection points must have pcb_port_id for alternative goal box calculation (got ${n.pcb_port_id} and ${i.pcb_port_id})`);const o=gme({goalElementId:n.pcb_port_id,pcbConnMap:t}).concat([{center:n,width:.01,height:.01,connectedTo:[n.pcb_port_id],layers:[n.layer],type:"rect"}]),a=gme({goalElementId:i.pcb_port_id,pcbConnMap:t}).concat([{center:i,width:.01,height:.01,connectedTo:[i.pcb_port_id],layers:[i.layer],type:"rect"}]);if(o.length<=1&&a.length<=1)return{...e,startPoint:n,endPoint:i,goalBoxes:[]};const s=Alt(o,a);let l,c,u;return o.length>=a.length?(l={...i,...s.pointB},c={...n,...s.pointA},u=o):(l={...n,...s.pointA},c={...i,...s.pointB},u=a),{startPoint:l,endPoint:c,goalBoxes:u,name:e.name,pointsToConnect:[l,c]}},vlt=(r,e={})=>{const t={minTraceWidth:.1};t.layerCount=e.layerCount??1,t.obstacles=SV(r,e.connMap),t.connections=[];for(const i of r)if(i.type==="source_trace"){let o={name:i.source_trace_id,pointsToConnect:i.connected_source_port_ids.map(a=>{var l;const s=dm(r).pcb_port.getWhere({source_port_id:a});if(!s)throw new Error(`Could not find pcb_port for source_port_id "${a}"`);return{x:s.x,y:s.y,layer:((l=s.layers)==null?void 0:l[0])??"top",pcb_port_id:s.pcb_port_id}})};if(e.optimizeWithGoalBoxes){const a=new ame(r);o=mme({connection:o,pcbConnMap:a})}t.connections.push(o),Ilt(t.obstacles,o.pointsToConnect,o.name)}const n={minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0};for(const i of t.obstacles)n.minX=Math.min(n.minX,i.center.x-i.width/2),n.maxX=Math.max(n.maxX,i.center.x+i.width/2),n.minY=Math.min(n.minY,i.center.y-i.height/2),n.maxY=Math.max(n.maxY,i.center.y+i.height/2);for(const i of t.connections)for(const o of i.pointsToConnect)n.minX=Math.min(n.minX,o.x),n.maxX=Math.max(n.maxX,o.x),n.minY=Math.min(n.minY,o.y),n.maxY=Math.max(n.maxY,o.y);return t.bounds=n,t},Ilt=(r,e,t)=>{for(const n of e)for(const i of r)Clt(n,i)&&i.connectedTo.push(t)};function Clt(r,e){const t=e.width/2,n=e.height/2;if(e.type==="rect")return r.x>=e.center.x-t&&r.x<=e.center.x+t&&r.y>=e.center.y-n&&r.y<=e.center.y+n;if(e.type==="oval"){const i=(r.x-e.center.x)/t,o=(r.y-e.center.y)/n;return i*i+o*o<=1}return!1}function yme(r,e){const t=e.x>r.x?1:e.x<r.x?-1:0,n=e.y>r.y?1:e.y<r.y?-1:0,i=e.l>r.l?1:e.l<r.l?-1:0;return{dx:t,dy:n,dl:i}}var wV={1:["top"],2:["top","bottom"],4:["top","inner1","inner2","bottom"]},_lt=r=>wV[r];function vme(r,e){const n=wV[r].indexOf(e);if(n===-1)throw new Error(`Invalid layer for getLayerIndex (for layerCount === ${r}): "${e}"`);return n}function Elt(r,e){const n=wV[r][e];if(!n)throw new Error(`Invalid index for indexToLayer (for layerCount === ${r}): "${e}"`);return n}var xlt=class extends fme{constructor(e,t){super([]);Le(this,"obstacles");Le(this,"GRID_STEP",.1);Le(this,"layerCount");this.layerCount=e;const n=_lt(e);this.obstacles=t.flatMap(i=>i.layers.filter(o=>n.includes(o)).map(o=>({...i,left:i.center.x-i.width/2,right:i.center.x+i.width/2,top:i.center.y+i.height/2,bottom:i.center.y-i.height/2,l:vme(e,o)})))}getObstacleAt(e,t,n,i){i??(i=this.GRID_STEP);for(const o of this.obstacles){if(o.l!==n)continue;const a=o.width/2+i,s=o.height/2+i;if(e>=o.center.x-a&&e<=o.center.x+a&&t>=o.center.y-s&&t<=o.center.y+s)return o}return null}isObstacleAt(e,t,n,i){return this.getObstacleAt(e,t,n,i)!==null}getDirectionDistancesToNearestObstacle3d(e,t,n){const{GRID_STEP:i}=this,o={left:1/0,top:1/0,bottom:1/0,right:1/0};for(const a of this.obstacles)if(a.l===n&&a.type==="rect"){const s=a.center.x-a.width/2-i,l=a.center.x+a.width/2+i,c=a.center.y+a.height/2+i,u=a.center.y-a.height/2-i;t>=u&&t<=c&&e>s&&(o.left=Math.min(o.left,e-l)),t>=u&&t<=c&&e<l&&(o.right=Math.min(o.right,s-e)),e>=s&&e<=l&&t<c&&(o.top=Math.min(o.top,u-t)),e>=s&&e<=l&&t>u&&(o.bottom=Math.min(o.bottom,t-c))}return o}getOrthoDirectionCollisionInfo(e,t,{margin:n=0}={}){const{x:i,y:o,l:a}=e,{dx:s,dy:l,dl:c}=t;let u=1/0,A=null;if(c!==0){const d=a+c;return this.isObstacleAt(i,o,d,n)?(u=1,A=this.getObstacleAt(i,o,d,n)):u=1,{dx:s,dy:l,dl:c,wallDistance:u,obstacle:A}}else{for(const d of this.obstacles){if(d.l!==a)continue;const f=d.left-n,p=d.right+n,C=d.top+n,v=d.bottom-n;let _=null;s===1&&l===0?o>v&&o<C&&i<d.left&&(_=d.left-i):s===-1&&l===0?o>v&&o<C&&i>d.right&&(_=i-d.right):s===0&&l===1?i>f&&i<p&&o<d.bottom&&(_=d.bottom-o):s===0&&l===-1&&i>f&&i<p&&o>d.top&&(_=o-d.top),_!==null&&_<u&&(u=_,A=d)}return{dx:s,dy:l,dl:0,wallDistance:u,obstacle:A}}}getObstaclesOverlappingRegion(e){const t=[];for(const n of this.obstacles){if(n.l!==e.l)continue;const{left:i,right:o,top:a,bottom:s}=n;i<=e.maxX&&o>=e.minX&&a>=e.minY&&s<=e.maxY&&t.push(n)}return t}},IM=class extends pme{constructor(e){super(e);Le(this,"MAX_ITERATIONS",500);Le(this,"VIA_COST",4);Le(this,"VIA_DIAMETER",.5);Le(this,"allowLayerChange",!0);Le(this,"layerCount");Le(this,"obstacles");Le(this,"optimizeWithGoalBoxes");Le(this,"connMap");Le(this,"pcbConnMap");Le(this,"GOAL_RUSH_FACTOR",1.1);Le(this,"defaultGoalViaMargin",.5);Le(this,"marginsWithCosts");this.layerCount=e.input.layerCount??2,this.MAX_ITERATIONS=e.MAX_ITERATIONS??this.MAX_ITERATIONS,this.VIA_COST=e.VIA_COST??this.VIA_COST,this.connMap=e.connMap,this.pcbConnMap=e.pcbConnMap??new ame,this.optimizeWithGoalBoxes=e.optimizeWithGoalBoxes??!1,this.obstacles=null,this.marginsWithCosts=e.marginsWithCosts??[{margin:1,enterCost:0,travelCostFactor:1},{margin:this.OBSTACLE_MARGIN,enterCost:10,travelCostFactor:2}]}get largestMargin(){return this.marginsWithCosts[0].margin}preprocessConnectionBeforeSolving(e){return this.optimizeWithGoalBoxes?mme({connection:e,pcbConnMap:this.pcbConnMap}):e}postprocessConnectionSolveResult(e,t){if(!t.solved)return t;if(this.optimizeWithGoalBoxes){const n=t.route.map(i=>({x:i.x,y:i.y,route_type:"wire",layer:i.layer,width:this.input.minTraceWidth}));n[0].start_pcb_port_id=e.pointsToConnect[0].pcb_port_id,n[n.length-1].end_pcb_port_id=e.pointsToConnect[1].pcb_port_id,this.pcbConnMap.addTrace({type:"pcb_trace",pcb_trace_id:`postprocess_trace_${kO(8)}`,route:n})}return t}createObstacleList({dominantLayer:e,connection:t,obstaclesFromTraces:n}){const i=this.connMap?this.connMap.getNetConnectedToId(t.name):t.name;if(!i)throw new Error(`The connection.name "${t.name}" wasn't present in the full connectivity map`);return new xlt(this.layerCount,this.allObstacles.filter(o=>!o.connectedTo.includes(i)).concat(n??[]))}computeG(e,t){let n=e.g+AQ(e,t)*(e.travelMarginCostFactor??1)+(t.enterMarginCost??0);return(t.l??e.l!==-1??-1)&&(n+=this.VIA_COST),n}computeH(e){const t=Math.abs(e.x-this.goalPoint.x),n=Math.abs(e.y-this.goalPoint.y),i=Math.abs(e.l-this.goalPoint.l);return(t+n)**this.GOAL_RUSH_FACTOR+i*this.VIA_COST}getStartNode(e){return{...super.getStartNode(e),l:this.layerToIndex(e.pointsToConnect[0].layer)}}layerToIndex(e){return vme(this.layerCount,e)}indexToLayer(e){return Elt(this.layerCount,e)}getNodeName(e){return`${ume(e,this.GRID_STEP)}-${e.l??0}`}hasSpaceForVia(e,t){return e.every(n=>this.obstacles.getObstaclesOverlappingRegion({minX:t.x-this.VIA_DIAMETER/2-this.OBSTACLE_MARGIN,minY:t.y-this.VIA_DIAMETER/2-this.OBSTACLE_MARGIN,maxX:t.x+this.VIA_DIAMETER/2+this.OBSTACLE_MARGIN,maxY:t.y+this.VIA_DIAMETER/2+this.OBSTACLE_MARGIN,l:n}).length===0)}getNeighborsSurroundingGoal(e){this.obstacles;const t=this.goalPoint,n=[],i=[{dx:1,dy:0,dl:0},{dx:-1,dy:0,dl:0},{dx:0,dy:1,dl:0},{dx:0,dy:-1,dl:0}],o=this.VIA_DIAMETER+this.OBSTACLE_MARGIN+this.defaultGoalViaMargin;for(const a of i){const s={x:e.x+a.dx*o,y:e.y+a.dy*o,l:e.l+a.dl,obstacleHit:null};this.hasSpaceForVia([e.l,t.l],s)&&n.push(s)}return n}getNeighbors(e){const t=this.obstacles,n=this.goalPoint,i=AQ(e,n);if(i<=this.OBSTACLE_MARGIN)return this.getNeighborsSurroundingGoal(e);let o;e.parent?o=yme(e.parent,e):o=yme(e,n);const a=[{dx:0,dy:1,dl:0},{dx:1,dy:0,dl:0},{dx:0,dy:-1,dl:0},{dx:-1,dy:0,dl:0}],s=i>this.VIA_DIAMETER+this.OBSTACLE_MARGIN,l=AQ(e,this.startNode)>this.VIA_DIAMETER+this.OBSTACLE_MARGIN;this.allowLayerChange&&s&&l&&(e.l<this.layerCount-1&&a.push({dx:0,dy:0,dl:1}),e.l>0&&a.push({dx:0,dy:0,dl:-1}));const c=a.filter(A=>{var d;return A.dx===o.dx*-1&&A.dy===o.dy*-1&&A.dl===o.dl*-1?!1:!(A.dx===o.dx&&A.dy===o.dy&&A.dl===o.dl&&((d=e.parent)!=null&&d.obstacleHit))}).map(A=>t.getOrthoDirectionCollisionInfo(e,A,{margin:this.OBSTACLE_MARGIN})).filter(A=>!(A.wallDistance<this.OBSTACLE_MARGIN)),u=[];for(const A of c){const d=A.dx===0&&A.dy===0&&A.dl===1,f=A.dx===0&&A.dy===0&&A.dl===-1;if((d||f)&&![e.l,e.l+A.dl].every(x=>t.getObstaclesOverlappingRegion({minX:e.x-this.VIA_DIAMETER/2-this.OBSTACLE_MARGIN,minY:e.y-this.VIA_DIAMETER/2-this.OBSTACLE_MARGIN,maxX:e.x+this.VIA_DIAMETER/2+this.OBSTACLE_MARGIN,maxY:e.y+this.VIA_DIAMETER/2+this.OBSTACLE_MARGIN,l:x}).length===0))continue;if(d){e.l<this.layerCount-1&&u.push({...A,travelDistance:0,enterMarginCost:0,travelMarginCostFactor:1});continue}if(f){e.l>0&&u.push({...A,travelDistance:0,enterMarginCost:0,travelMarginCostFactor:1});continue}let p=null;e!=null&&e.obstacleHit&&(p=BV({node:e,travelDir:A,wallDir:{...o,wallDistance:this.OBSTACLE_MARGIN},obstacle:e.obstacleHit,obstacles:t,OBSTACLE_MARGIN:this.OBSTACLE_MARGIN,SHOULD_DETECT_CONJOINED_OBSTACLES:!0}));const C=cme(e,n,A),v=(A.dx===0||Math.sign(n.x-e.x)===A.dx)&&(A.dy===0||Math.sign(n.y-e.y)===A.dy);if(C<A.wallDistance&&C>0&&v){const _=e.l===n.l;let x=0;!_&&Math.abs(C-i)<this.GRID_STEP&&(x=this.VIA_DIAMETER+this.OBSTACLE_MARGIN+this.defaultGoalViaMargin),u.push({...A,travelDistance:C-x,enterMarginCost:0,travelMarginCostFactor:1})}else if(p!==null&&p<A.wallDistance){for(const{margin:_,enterCost:x,travelCostFactor:b}of this.marginsWithCosts)p-this.OBSTACLE_MARGIN+_*2<A.wallDistance&&u.push({...A,travelDistance:p-this.OBSTACLE_MARGIN+_,enterMarginCost:x,travelMarginCostFactor:b});if(A.wallDistance===1/0)u.push({...A,travelDistance:C,enterMarginCost:0,travelMarginCostFactor:1});else if(A.wallDistance>this.largestMargin)for(const{margin:_,enterCost:x,travelCostFactor:b}of this.marginsWithCosts)A.wallDistance>this.largestMargin+_&&u.push({...A,travelDistance:A.wallDistance-_,enterMarginCost:x,travelMarginCostFactor:b})}else if(A.wallDistance!==1/0)for(const{margin:_,enterCost:x,travelCostFactor:b}of this.marginsWithCosts)A.wallDistance>_&&u.push({...A,travelDistance:A.wallDistance-_,enterMarginCost:x,travelMarginCostFactor:b})}return u.map(A=>({x:e.x+A.dx*A.travelDistance,y:e.y+A.dy*A.travelDistance,l:e.l+A.dl,obstacleHit:A.obstacle,travelMarginCostFactor:A.travelMarginCostFactor,enterMarginCost:A.enterMarginCost}))}};function QV(r){const e=vlt(r),t=new mlt({input:e});return{solution:t.solveAndMapToTraces(),debugSolutions:t.debugSolutions,debugMessage:t.debugMessage}}var CM=SV,blt=mo(["up","down","left","right"]);mo(["top-to-bottom","left-to-right","bottom-to-top","right-to-left"]);var VS=br(_e().or(sn())),Ime=zt({x:qn,y:qn,z:qn}),Blt=zt({x:dl([sn(),_e()]),y:dl([sn(),_e()]),z:dl([sn(),_e()])}),MV=zt({rotationOffset:sn().or(Blt).optional(),positionOffset:Ime.optional(),size:Ime.optional()}),Slt=MV.extend({stlUrl:_e()}),wlt=MV.extend({objUrl:_e(),mtlUrl:_e().optional()}),Qlt=MV.extend({jscad:jg(GI())}),Mlt=dl([pde(),_e(),Slt,wlt,Qlt]),Dlt=nE(r=>!0),OI=zt({pcbX:qn.optional(),pcbY:qn.optional(),pcbRotation:kC.optional(),layer:mg.optional()}),V8=zt({pcbX:qn.optional(),pcbY:qn.optional(),pcbRotation:kC.optional(),schX:qn.optional(),schY:qn.optional(),schRotation:kC.optional(),layer:mg.optional(),footprint:Dlt.optional()}),Rlt=zt({supplierPartNumbers:jg(AM,br(_e())).optional()}),iE=V8.merge(Rlt).extend({key:GI().optional(),name:_e(),cadModel:Mlt.optional(),children:GI().optional(),symbolName:_e().optional()});qn.or(mo(["2x","3x","4x"]));var K8=zt({pins:br(dl([sn(),_e()])),direction:dl([Nt("top-to-bottom"),Nt("left-to-right"),Nt("bottom-to-top"),Nt("right-to-left")])}),mR=zt({leftSize:sn().optional().describe("@deprecated, use leftPinCount"),topSize:sn().optional().describe("@deprecated, use topPinCount"),rightSize:sn().optional().describe("@deprecated, use rightPinCount"),bottomSize:sn().optional().describe("@deprecated, use bottomPinCount"),leftPinCount:sn().optional(),rightPinCount:sn().optional(),topPinCount:sn().optional(),bottomPinCount:sn().optional(),leftSide:K8.optional(),rightSide:K8.optional(),topSide:K8.optional(),bottomSide:K8.optional()}),Nlt=mR,DV=jg(zt({marginLeft:qn.optional(),marginRight:qn.optional(),marginTop:qn.optional(),marginBottom:qn.optional(),leftMargin:qn.optional(),rightMargin:qn.optional(),topMargin:qn.optional(),bottomMargin:qn.optional()})),RV=zt({x:qn,y:qn}),yR=zt({edit_event_id:_e(),in_progress:Ni().optional(),created_at:sn()}),Tlt=yR.extend({pcb_edit_event_type:Nt("edit_component_location").describe("deprecated"),edit_event_type:Nt("edit_pcb_component_location"),pcb_component_id:_e(),original_center:zt({x:sn(),y:sn()}),new_center:zt({x:sn(),y:sn()})}),Plt=yR.extend({pcb_edit_event_type:Nt("edit_trace_hint").describe("deprecated"),edit_event_type:Nt("edit_pcb_trace_hint").optional(),pcb_port_id:_e(),pcb_trace_hint_id:_e().optional(),route:br(zt({x:sn(),y:sn(),via:Ni().optional()}))}),klt=yR.extend({edit_event_type:Nt("edit_schematic_component_location"),schematic_component_id:_e(),original_center:zt({x:sn(),y:sn()}),new_center:zt({x:sn(),y:sn()})});yR.extend({edit_event_type:Nt("edit_pcb_group_location"),pcb_group_id:_e(),original_center:zt({x:sn(),y:sn()}),new_center:zt({x:sn(),y:sn()})}),yR.extend({edit_event_type:Nt("edit_schematic_group_location"),schematic_group_id:_e(),original_center:zt({x:sn(),y:sn()}),new_center:zt({x:sn(),y:sn()})}),dl([Tlt,Plt,klt]);var Ult=zt({selector:_e(),relative_to:_e().optional().default("group_center").describe("Can be a selector or 'group_center'"),center:Am}),Flt=zt({pcb_port_selector:_e(),offsets:br(nx)}),Llt=zt({selector:_e(),relative_to:_e().optional().default("group_center").describe("Can be a selector or 'group_center'"),center:Am}),Glt=zt({pcb_placements:br(Ult).optional(),manual_trace_hints:br(Flt).optional(),schematic_placements:br(Llt).optional()}),NV=zt({layoutMode:mo(["grid","flex","match-adapt","none"]).optional(),position:mo(["absolute","relative"]).optional(),grid:Ni().optional(),gridCols:sn().or(_e()).optional(),gridRows:sn().or(_e()).optional(),gridTemplateRows:_e().optional(),gridTemplateColumns:_e().optional(),gridTemplate:_e().optional(),gridGap:sn().or(_e()).optional(),flex:Ni().or(_e()).optional(),flexDirection:mo(["row","column"]).optional(),alignItems:mo(["start","center","end","stretch"]).optional(),justifyContent:mo(["start","center","end","stretch"]).optional(),flexRow:Ni().optional(),flexColumn:Ni().optional(),gap:sn().or(_e()).optional(),matchAdapt:Ni().optional()}),Olt=zt({serverUrl:_e().optional(),inputFormat:mo(["simplified","circuit-json"]).optional(),serverMode:mo(["job","solve-endpoint"]).optional(),serverCacheEnabled:Ni().optional(),cache:nE(r=>!0).optional(),groupMode:mo(["sequential-trace","subcircuit"]).optional(),algorithmFn:nE(r=>typeof r=="function"||r===void 0).optional(),local:Ni().optional()}),Cme=dl([Olt,Nt("sequential-trace"),Nt("subcircuit"),Nt("auto"),Nt("auto-local"),Nt("auto-cloud")]),_me=V8.extend({name:_e().optional(),children:GI().optional(),key:GI().optional(),...NV.shape,pcbWidth:In.optional(),pcbHeight:In.optional(),schWidth:In.optional(),schHeight:In.optional(),pcbLayout:NV.optional(),schLayout:NV.optional()}),Eme=nE(r=>"findPart"in r),xme=_me.extend({layout:nE(r=>!0).optional(),manualEdits:Glt.optional(),schAutoLayoutEnabled:Ni().optional(),schTraceAutoLabelEnabled:Ni().optional(),routingDisabled:Ni().optional(),defaultTraceWidth:In.optional(),minTraceWidth:In.optional(),partsEngine:Eme.optional(),pcbRouteCache:nE(r=>!0).optional(),autorouter:Cme.optional()}),zlt=xme.extend({subcircuit:Nt(!0)}),bme=zB("subcircuit",[_me.extend({subcircuit:Nt(!1).optional()}),zlt]),TV=xme.extend({width:qn.optional(),height:qn.optional(),outline:br(RV).optional(),outlineOffsetX:qn.optional(),outlineOffsetY:qn.optional(),material:mo(["fr4","fr1"]).default("fr4")}),Hlt=_e().or(br(_e()).readonly()).or(br(_e())),Ylt=nE().pipe(jg(_e(),Hlt)),Vlt=jg(_e(),_e().or(br(_e()).readonly()).or(br(_e()))),Klt=zt({manufacturerPartNumber:_e().optional(),supplierPartNumber:jg(AM,br(_e())).optional()}),PV=iE.extend({manufacturerPartNumber:_e().optional(),pinLabels:Vlt.optional(),internallyConnectedPins:br(br(_e())).optional(),externallyConnectedPins:br(br(_e())).optional(),schPinArrangement:mR.optional(),schPortArrangement:mR.optional(),pinCompatibleVariants:br(Klt).optional(),schPinStyle:DV.optional(),schPinSpacing:qn.optional(),schWidth:qn.optional(),schHeight:qn.optional(),noSchematicRepresentation:Ni().optional(),connections:Ylt.optional()}),Bme=iE.extend({manufacturerPartNumber:_e().optional(),pinLabels:jg(sn().or(_e()),_e().or(br(_e()))).optional(),schPinStyle:DV.optional(),schPinSpacing:qn.optional(),schWidth:qn.optional(),schHeight:qn.optional(),schDirection:mo(["left","right"]).optional(),schPortArrangement:mR.optional(),pinCount:dl([Nt(2),Nt(3)]).optional(),internallyConnectedPins:br(br(_e())).optional()});iE.extend({manufacturerPartNumber:_e().optional(),pinLabels:jg(sn().or(_e()),_e().or(br(_e()))).optional(),schPinStyle:DV.optional(),schPinSpacing:qn.optional(),schWidth:qn.optional(),schHeight:qn.optional(),schDirection:mo(["left","right"]).optional(),schPortArrangement:mR.optional(),internallyConnectedPins:br(br(_e())).optional(),standard:mo(["usb_c","m2"]).optional()});var jlt=iE.extend({currentRating:dl([sn(),_e()]),voltageRating:dl([sn(),_e()]).optional(),schShowRatings:Ni().optional(),connections:jg(_e(),dl([_e(),br(_e()).readonly(),br(_e())])).optional()}),j8=nE().transform(r=>{if(r!==void 0)return qn.parse(r)}),Sme=dl([OI.omit({pcbRotation:!0,layer:!0}).extend({name:_e().optional(),shape:Nt("circle"),holeDiameter:qn,outerDiameter:qn,portHints:VS.optional()}),OI.omit({pcbRotation:!0,layer:!0}).extend({name:_e().optional(),shape:Nt("oval"),outerWidth:qn,outerHeight:qn,holeWidth:j8,holeHeight:j8,innerWidth:qn.optional().describe("DEPRECATED use holeWidth"),innerHeight:qn.optional().describe("DEPRECATED use holeHeight"),portHints:VS.optional()}),OI.omit({pcbRotation:!0,layer:!0}).extend({name:_e().optional(),shape:Nt("pill"),outerWidth:qn,outerHeight:qn,holeWidth:j8,holeHeight:j8,innerWidth:qn.optional().describe("DEPRECATED use holeWidth"),innerHeight:qn.optional().describe("DEPRECATED use holeHeight"),portHints:VS.optional()}),OI.omit({pcbRotation:!0,layer:!0}).extend({name:_e().optional(),holeDiameter:qn,rectPadWidth:qn,rectPadHeight:qn,holeShape:Nt("circle").optional(),padShape:Nt("rect").optional(),shape:Nt("circular_hole_with_rect_pad").optional(),portHints:VS.optional()}).refine(r=>r.shape==="circular_hole_with_rect_pad"?r.holeDiameter&&r.rectPadWidth&&r.rectPadHeight:!0,{message:"Missing required fields for circular_hole_with_rect_pad"}),OI.omit({pcbRotation:!0,layer:!0}).extend({name:_e().optional(),shape:Nt("pill_hole_with_rect_pad"),holeShape:Nt("pill"),padShape:Nt("rect"),holeWidth:qn,holeHeight:qn,rectPadWidth:qn,rectPadHeight:qn,portHints:VS.optional()})]).refine(r=>("innerWidth"in r&&r.innerWidth!==void 0&&(r.holeWidth??(r.holeWidth=r.innerWidth)),"innerHeight"in r&&r.innerHeight!==void 0&&(r.holeHeight??(r.holeHeight=r.innerHeight)),r)),Jlt=_e().or(br(_e()).readonly()).or(br(_e())),wme=r=>jg(mo(r),Jlt),Wlt=["pin1","pin2","pos","neg"],Qme=iE.extend({resistance:V2,pullupFor:_e().optional(),pullupTo:_e().optional(),pulldownFor:_e().optional(),pulldownTo:_e().optional(),connections:wme(Wlt).optional()}),Mme=iE.extend({maxResistance:V2,pinVariant:mo(["two_pin","three_pin"]).optional()}),Dme=iE.extend({frequency:uM,loadCapacitance:US,pinVariant:mo(["two_pin","four_pin"]).optional()}),Rme=iE.extend({frequency:uM,loadCapacitance:US,pinVariant:mo(["no_ground","ground_pin","two_ground_pins"]).optional()});TV.extend({leftPinCount:sn().optional(),rightPinCount:sn().optional(),topPinCount:sn().optional(),bottomPinCount:sn().optional(),leftPins:br(_e()).optional(),rightPins:br(_e()).optional(),topPins:br(_e()).optional(),bottomPins:br(_e()).optional(),pinPitch:qn.optional(),innerHoles:Ni().optional()});var qlt=["pin1","pin2","pos","neg","anode","cathode"],Nme=iE.extend({capacitance:US,maxVoltageRating:K2.optional(),schShowRatings:Ni().optional().default(!1),polarized:Ni().optional().default(!1),decouplingFor:_e().optional(),decouplingTo:_e().optional(),bypassFor:_e().optional(),bypassTo:_e().optional(),maxDecouplingTraceLength:sn().optional(),connections:wme(qlt).optional()});zt({name:_e()}),zt({name:_e().optional(),pcbOnly:Ni().optional(),schOnly:Ni().optional()});var Zlt=zt({pcb:Nt(!0).optional(),xDist:qn,left:_e(),right:_e(),edgeToEdge:Nt(!0).optional(),centerToCenter:Nt(!0).optional()}),Xlt=zt({pcb:Nt(!0).optional(),yDist:qn,top:_e(),bottom:_e(),edgeToEdge:Nt(!0).optional(),centerToCenter:Nt(!0).optional()}),$lt=zt({pcb:Nt(!0).optional(),sameY:Nt(!0).optional(),for:br(_e())}),ect=zt({pcb:Nt(!0).optional(),sameX:Nt(!0).optional(),for:br(_e())}),Tme=dl([Zlt,Xlt,$lt,ect]),tct=OI.omit({layer:!0,pcbRotation:!0}).extend({name:_e().optional(),shape:Nt("rect"),width:qn,height:qn}),nct=OI.omit({layer:!0,pcbRotation:!0}).extend({name:_e().optional(),shape:Nt("circle"),radius:qn}),rct=OI.omit({layer:!0,pcbRotation:!0}).extend({name:_e().optional(),shape:Nt("polygon"),points:br(RV)}),Pme=zB("shape",[tct,nct,rct]),ict=OI.omit({pcbRotation:!0}).extend({shape:Nt("rect"),width:qn,height:qn,portHints:VS.optional()}),oct=OI.omit({pcbRotation:!0}).extend({shape:Nt("rotated_rect"),width:qn,height:qn,ccwRotation:sn(),portHints:VS.optional()}),act=OI.omit({pcbRotation:!0}).extend({shape:Nt("circle"),radius:qn,portHints:VS.optional()}),sct=OI.omit({pcbRotation:!0}).extend({shape:Nt("pill"),width:qn,height:qn,radius:qn,portHints:VS.optional()}),kme=dl([act,ict,oct,sct]),lct=OI.omit({pcbRotation:!0}).extend({shape:Nt("rect"),width:qn,height:qn}),cct=OI.omit({pcbRotation:!0}).extend({shape:Nt("circle"),radius:qn});dl([cct,lct]);var Ume=OI.omit({pcbRotation:!0}).extend({name:_e().optional(),diameter:qn.optional(),radius:qn.optional()}).transform(r=>({...r,diameter:r.diameter??2*r.radius,radius:r.radius??r.diameter/2})),kV=dl([_e(),nE(r=>!!r.getPortSelector)]),Fme=zt({key:_e().optional(),thickness:qn.optional(),schematicRouteHints:br(RV).optional(),pcbRouteHints:br(nx).optional(),schDisplayLabel:_e().optional(),maxLength:qn.optional()}),Lme=dl([Fme.extend({path:br(kV)}),Fme.extend({from:kV,to:kV})]),Gme=zt({originalLayer:mg.default("top").optional()}),uct=sn().or(_e().endsWith("mAh")).transform(r=>{if(typeof r=="string"){const e=r.replace("mAh",""),t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error("Invalid capacity");return t}return r}).describe("Battery capacity in mAh"),Ome=iE.extend({capacity:uct.optional()}),zme=iE.extend({pinCount:sn(),pitch:qn.optional(),schFacingDirection:mo(["up","down","left","right"]).optional(),gender:mo(["male","female"]).optional().default("male"),showSilkscreenPinLabels:Ni().optional(),doubleRow:Ni().optional(),holeDiameter:qn.optional(),platedDiameter:qn.optional(),pinLabels:br(_e()).optional(),facingDirection:mo(["left","right"]).optional(),schPinArrangement:Nlt.optional()}),Hme=zt({net:_e().optional(),schX:qn.optional(),schY:qn.optional(),schRotation:kC.optional(),anchorSide:mo(["left","up","right","down"]).optional()}),Yme=PV.extend({}),Vme=iE.extend({type:mo(["npn","pnp","bjt","jfet","mosfet"])}),Kme=iE.extend({channelType:mo(["n","p"]),mosfetMode:mo(["enhancement","depletion"])}),jme=iE.extend({inductance:WT}),Act=mo(["anode","cathode","pin1","pin2","pos","neg"]),dct=_e().or(br(_e()).readonly()).or(br(_e())),fct=jg(Act,dct),hct=mo(["standard","schottky","zener","photo","tvs"]),Jme=iE.extend({connections:fct.optional(),variant:hct.optional().default("standard"),standard:Ni().optional(),schottky:Ni().optional(),zener:Ni().optional(),photo:Ni().optional(),tvs:Ni().optional()}).superRefine((r,e)=>{if([r.standard,r.schottky,r.zener,r.photo,r.tvs].filter(Boolean).length>1)return e.addIssue({code:ds.custom,message:"Exactly one diode variant must be enabled",path:[]}),Of}).transform(r=>{const e={...r,standard:!1,schottky:!1,zener:!1,photo:!1,tvs:!1};if(r.standard)e.standard=!0;else if(r.schottky)e.schottky=!0;else if(r.zener)e.zener=!0;else if(r.photo)e.photo=!0;else if(r.tvs)e.tvs=!0;else switch(r.variant){case"standard":e.standard=!0;break;case"schottky":e.schottky=!0;break;case"zener":e.zener=!0;break;case"photo":e.photo=!0;break;case"tvs":e.tvs=!0;break;default:e.standard=!0}return e}),Wme=iE.extend({color:_e().optional(),wavelength:_e().optional()}),qme=iE.extend({type:mo(["spst","spdt","dpst","dpdt"]).optional(),isNormallyClosed:Ni().optional().default(!1),spst:Ni().optional(),spdt:Ni().optional(),dpst:Ni().optional(),dpdt:Ni().optional()}).transform(r=>{const e={...r};switch(e.dpdt?e.type="dpdt":e.spst?e.type="spst":e.spdt?e.type="spdt":e.dpst&&(e.type="dpst"),e.type){case"spdt":e.spdt=!0;break;case"spst":e.spst=!0;break;case"dpst":e.dpst=!0;break;case"dpdt":e.dpdt=!0;break}return e}),Zme=OI.extend({text:_e(),anchorAlignment:mo(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),font:mo(["tscircuit2024"]).optional(),fontSize:In.optional(),color:_e().optional()}),Xme=OI.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({route:br(nx),strokeWidth:In.optional(),color:_e().optional()});zt({layer:_e().optional(),thickness:qn.optional(),route:br(nx)});var $me=V8.extend({fromLayer:mg,toLayer:mg,holeDiameter:qn,outerDiameter:qn}),eye=dl([OI.omit({pcbRotation:!0}).extend({shape:Nt("circle"),radius:qn}),OI.extend({shape:Nt("rect"),width:qn,height:qn})]),tye=iE.extend({voltage:K2}),UV=mo(["top_left","top_center","top_right","center_left","center","center_right","bottom_left","bottom_center","bottom_right"]),nye=zt({schX:qn,schY:qn,width:qn.optional(),height:qn.optional(),overlay:br(_e()).optional(),padding:qn.optional(),paddingLeft:qn.optional(),paddingRight:qn.optional(),paddingTop:qn.optional(),paddingBottom:qn.optional(),title:_e().optional(),titlePosition:UV.default("top_left"),titleColor:_e().optional(),titleFontSize:qn.optional(),titleInside:Ni().default(!1),strokeStyle:mo(["solid","dashed"]).default("solid")}).refine(r=>r.width!==void 0&&r.height!==void 0||Array.isArray(r.overlay)&&r.overlay.length>0,{message:"Must provide either both `width` and `height`, or a non-empty `overlay` array.",path:[]});zt({x1:qn,y1:qn,x2:qn,y2:qn});var pct=mo(["center","left","right","top","bottom"]),rye=zt({schX:qn,schY:qn,text:_e(),fontSize:sn().default(1),anchor:dl([pct.describe("legacy"),UV]).default("center"),color:_e().default("#000000"),schRotation:kC.default(0)});zt({points:br(Am),isFilled:Ni().optional().default(!1),fillColor:mo(["red","blue"]).optional()});var iye=OI.extend({text:_e(),anchorAlignment:UV.default("center"),font:mo(["tscircuit2024"]).optional(),fontSize:In.optional()}),oye=OI.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({route:br(nx),strokeWidth:In.optional()}),aye=OI.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({strokeWidth:qn,x1:qn,y1:qn,x2:qn,y2:qn}),sye=OI.omit({pcbRotation:!0}).extend({isFilled:Ni().optional(),isOutline:Ni().optional(),strokeWidth:qn.optional(),width:qn,height:qn}),lye=OI.omit({pcbRotation:!0}).extend({isFilled:Ni().optional(),isOutline:Ni().optional(),strokeWidth:qn.optional(),radius:qn}),cye=zt({x:qn,y:qn,via:Ni().optional(),toLayer:mg.optional()}),uye=zt({for:_e().optional().describe("Selector for the port you're targeting, not required if you're inside a trace"),order:sn().optional(),offset:nx.or(cye).optional(),offsets:br(nx).or(br(cye)).optional(),traceWidth:sn().optional()});V8.extend({name:_e(),pinNumber:sn().optional(),aliases:br(_e()).optional(),direction:blt});var gct=br(GI()).describe("Circuit JSON"),mct=gde().args(_e()).returns(mde(zt({footprintCircuitJson:br(GI())}))).describe("A function that takes a path and returns Circuit JSON");zt({partsEngine:Eme.optional(),autorouter:Cme.optional(),registryApiUrl:_e().optional(),cloudAutorouterUrl:_e().optional(),localCacheEngine:GI().optional(),pcbDisabled:Ni().optional(),schematicDisabled:Ni().optional(),partsEngineDisabled:Ni().optional(),footprintLibraryMap:jg(_e(),jg(_e(),dl([gct,mct]))).optional()});function _M(){return new FV}class FV{constructor(){Le(this,"index",{});Le(this,"array",[])}size(){return this.array.length}empty(){return this.array.length===0}itemAt(e){return this.array[e]}contains(e){return this.index[e.id()]!==void 0}find(e){const t=this.index[e.id()];return t===void 0?void 0:this.array[t]}setDefault(e,t){const n=this.index[e.id()];if(n===void 0){const i=new J8(e,t());return this.index[e.id()]=this.array.length,this.array.push(i),i}else return this.array[n]}insert(e,t){const n=new J8(e,t),i=this.index[e.id()];return i===void 0?(this.index[e.id()]=this.array.length,this.array.push(n)):this.array[i]=n,n}erase(e){const t=this.index[e.id()];if(t===void 0)return;this.index[e.id()]=void 0;const n=this.array[t],i=this.array.pop();return n!==i&&(this.array[t]=i,this.index[i.first.id()]=t),n}copy(){const e=new FV;for(let t=0;t<this.array.length;t++){const n=this.array[t].copy();e.array[t]=n,e.index[n.first.id()]=t}return e}}class J8{constructor(e,t){Le(this,"first");Le(this,"second");this.first=e,this.second=t}copy(){return new J8(this.first,this.second)}}class vR{constructor(e=""){Le(this,"_name");Le(this,"_value",0);Le(this,"_context",null);Le(this,"_id",yct++);this._name=e}id(){return this._id}name(){return this._name}setName(e){this._name=e}context(){return this._context}setContext(e){this._context=e}value(){return this._value}setValue(e){this._value=e}plus(e){return new Um(this,e)}minus(e){return new Um(this,typeof e=="number"?-e:[-1,e])}multiply(e){return new Um([e,this])}divide(e){return new Um([1/e,this])}toJSON(){return{name:this._name,value:this._value}}toString(){return this._context+"["+this._name+":"+this._value+"]"}}let yct=0;class Um{constructor(){Le(this,"_terms");Le(this,"_constant");let e=vct(arguments);this._terms=e.terms,this._constant=e.constant}terms(){return this._terms}constant(){return this._constant}value(){let e=this._constant;for(let t=0,n=this._terms.size();t<n;t++){let i=this._terms.itemAt(t);e+=i.first.value()*i.second}return e}plus(e){return new Um(this,e)}minus(e){return new Um(this,typeof e=="number"?-e:[-1,e])}multiply(e){return new Um([e,this])}divide(e){return new Um([1/e,this])}isConstant(){return this._terms.size()==0}toString(){let e=this._terms.array.map(function(t){return t.second+"*"+t.first.toString()}).join(" + ");return!this.isConstant()&&this._constant!==0&&(e+=" + "),e+=this._constant,e}}function vct(r){let e=0,t=()=>0,n=_M();for(let i=0,o=r.length;i<o;++i){let a=r[i];if(typeof a=="number")e+=a;else if(a instanceof vR)n.setDefault(a,t).second+=1;else if(a instanceof Um){e+=a.constant();let s=a.terms();for(let l=0,c=s.size();l<c;l++){let u=s.itemAt(l);n.setDefault(u.first,t).second+=u.second}}else if(a instanceof Array){if(a.length!==2)throw new Error("array must have length 2");let s=a[0],l=a[1];if(typeof s!="number")throw new Error("array item 0 must be a number");if(l instanceof vR)n.setDefault(l,t).second+=s;else if(l instanceof Um){e+=l.constant()*s;let c=l.terms();for(let u=0,A=c.size();u<A;u++){let d=c.itemAt(u);n.setDefault(d.first,t).second+=d.second*s}}else throw new Error("array item 1 must be a variable or expression")}else throw new Error("invalid Expression argument: "+a)}return{terms:n,constant:e}}const DB=class DB{static create(e,t,n,i=1){let o=0;return o+=Math.max(0,Math.min(1e3,e*i))*1e6,o+=Math.max(0,Math.min(1e3,t*i))*1e3,o+=Math.max(0,Math.min(1e3,n*i)),o}static clip(e){return Math.max(0,Math.min(DB.required,e))}};Le(DB,"required",DB.create(1e3,1e3,1e3)),Le(DB,"strong",DB.create(1,0,0)),Le(DB,"medium",DB.create(0,1,0)),Le(DB,"weak",DB.create(0,0,1));let uy=DB;var _I;(function(r){r[r.Le=0]="Le",r[r.Ge=1]="Ge",r[r.Eq=2]="Eq"})(_I||(_I={}));class L1{constructor(e,t,n,i=uy.required){Le(this,"_expression");Le(this,"_operator");Le(this,"_strength");Le(this,"_id",Ict++);this._operator=t,this._strength=uy.clip(i),n===void 0&&e instanceof Um?this._expression=e:this._expression=e.minus(n)}id(){return this._id}expression(){return this._expression}op(){return this._operator}strength(){return this._strength}toString(){return this._expression.toString()+" "+["<=",">=","="][this._operator]+" 0 ("+this._strength.toString()+")"}}let Ict=0;class LV{constructor(){Le(this,"maxIterations",1e3);Le(this,"_cnMap",Cct());Le(this,"_rowMap",_ct());Le(this,"_varMap",Ect());Le(this,"_editMap",xct());Le(this,"_infeasibleRows",[]);Le(this,"_objective",new q8);Le(this,"_artificial",null);Le(this,"_idTick",0)}createConstraint(e,t,n,i=uy.required){let o=new L1(e,t,n,i);return this.addConstraint(o),o}addConstraint(e){if(this._cnMap.find(e)!==void 0)throw new Error("duplicate constraint");let n=this._createRow(e),i=n.row,o=n.tag,a=this._chooseSubject(i,o);if(a.type()===fm.Invalid&&i.allDummies())if(W8(i.constant()))a=o.marker;else throw new Error("unsatisfiable constraint");if(a.type()===fm.Invalid){if(!this._addWithArtificialVariable(i))throw new Error("unsatisfiable constraint")}else i.solveFor(a),this._substitute(a,i),this._rowMap.insert(a,i);this._cnMap.insert(e,o),this._optimize(this._objective)}removeConstraint(e){let t=this._cnMap.erase(e);if(t===void 0)throw new Error("unknown constraint");this._removeConstraintEffects(e,t.second);let n=t.second.marker,i=this._rowMap.erase(n);if(i===void 0){let o=this._getMarkerLeavingSymbol(n);if(o.type()===fm.Invalid)throw new Error("failed to find leaving row");i=this._rowMap.erase(o),i.second.solveForEx(o,n),this._substitute(n,i.second)}this._optimize(this._objective)}hasConstraint(e){return this._cnMap.contains(e)}getConstraints(){return this._cnMap.array.map(({first:e})=>e)}addEditVariable(e,t){if(this._editMap.find(e)!==void 0)throw new Error("duplicate edit variable");if(t=uy.clip(t),t===uy.required)throw new Error("bad required strength");let i=new Um(e),o=new L1(i,_I.Eq,void 0,t);this.addConstraint(o);let s={tag:this._cnMap.find(o).second,constraint:o,constant:0};this._editMap.insert(e,s)}removeEditVariable(e){let t=this._editMap.erase(e);if(t===void 0)throw new Error("unknown edit variable");this.removeConstraint(t.second.constraint)}hasEditVariable(e){return this._editMap.contains(e)}suggestValue(e,t){let n=this._editMap.find(e);if(n===void 0)throw new Error("unknown edit variable");let i=this._rowMap,o=n.second,a=t-o.constant;o.constant=t;let s=o.tag.marker,l=i.find(s);if(l!==void 0){l.second.add(-a)<0&&this._infeasibleRows.push(s),this._dualOptimize();return}let c=o.tag.other;if(l=i.find(c),l!==void 0){l.second.add(a)<0&&this._infeasibleRows.push(c),this._dualOptimize();return}for(let u=0,A=i.size();u<A;++u){let d=i.itemAt(u),f=d.second,p=f.coefficientFor(s);p!==0&&f.add(a*p)<0&&d.first.type()!==fm.External&&this._infeasibleRows.push(d.first)}this._dualOptimize()}updateVariables(){let e=this._varMap,t=this._rowMap;for(let n=0,i=e.size();n<i;++n){let o=e.itemAt(n),a=t.find(o.second);a!==void 0?o.first.setValue(a.second.constant()):o.first.setValue(0)}}_getVarSymbol(e){let t=()=>this._makeSymbol(fm.External);return this._varMap.setDefault(e,t).second}_createRow(e){let t=e.expression(),n=new q8(t.constant()),i=t.terms();for(let l=0,c=i.size();l<c;++l){let u=i.itemAt(l);if(!W8(u.second)){let A=this._getVarSymbol(u.first),d=this._rowMap.find(A);d!==void 0?n.insertRow(d.second,u.second):n.insertSymbol(A,u.second)}}let o=this._objective,a=e.strength(),s={marker:ew,other:ew};switch(e.op()){case _I.Le:case _I.Ge:{let l=e.op()===_I.Le?1:-1,c=this._makeSymbol(fm.Slack);if(s.marker=c,n.insertSymbol(c,l),a<uy.required){let u=this._makeSymbol(fm.Error);s.other=u,n.insertSymbol(u,-l),o.insertSymbol(u,a)}break}case _I.Eq:{if(a<uy.required){let l=this._makeSymbol(fm.Error),c=this._makeSymbol(fm.Error);s.marker=l,s.other=c,n.insertSymbol(l,-1),n.insertSymbol(c,1),o.insertSymbol(l,a),o.insertSymbol(c,a)}else{let l=this._makeSymbol(fm.Dummy);s.marker=l,n.insertSymbol(l)}break}}return n.constant()<0&&n.reverseSign(),{row:n,tag:s}}_chooseSubject(e,t){let n=e.cells();for(let o=0,a=n.size();o<a;++o){let s=n.itemAt(o);if(s.first.type()===fm.External)return s.first}let i=t.marker.type();return(i===fm.Slack||i===fm.Error)&&e.coefficientFor(t.marker)<0?t.marker:(i=t.other.type(),(i===fm.Slack||i===fm.Error)&&e.coefficientFor(t.other)<0?t.other:ew)}_addWithArtificialVariable(e){let t=this._makeSymbol(fm.Slack);this._rowMap.insert(t,e.copy()),this._artificial=e.copy(),this._optimize(this._artificial);let n=W8(this._artificial.constant());this._artificial=null;let i=this._rowMap.erase(t);if(i!==void 0){let a=i.second;if(a.isConstant())return n;let s=this._anyPivotableSymbol(a);if(s.type()===fm.Invalid)return!1;a.solveForEx(t,s),this._substitute(s,a),this._rowMap.insert(s,a)}let o=this._rowMap;for(let a=0,s=o.size();a<s;++a)o.itemAt(a).second.removeSymbol(t);return this._objective.removeSymbol(t),n}_substitute(e,t){let n=this._rowMap;for(let i=0,o=n.size();i<o;++i){let a=n.itemAt(i);a.second.substitute(e,t),a.second.constant()<0&&a.first.type()!==fm.External&&this._infeasibleRows.push(a.first)}this._objective.substitute(e,t),this._artificial&&this._artificial.substitute(e,t)}_optimize(e){let t=0;for(;t<this.maxIterations;){let n=this._getEnteringSymbol(e);if(n.type()===fm.Invalid)return;let i=this._getLeavingSymbol(n);if(i.type()===fm.Invalid)throw new Error("the objective is unbounded");let o=this._rowMap.erase(i).second;o.solveForEx(i,n),this._substitute(n,o),this._rowMap.insert(n,o),t++}throw new Error("solver iterations exceeded")}_dualOptimize(){let e=this._rowMap,t=this._infeasibleRows;for(;t.length!==0;){let n=t.pop(),i=e.find(n);if(i!==void 0&&i.second.constant()<0){let o=this._getDualEnteringSymbol(i.second);if(o.type()===fm.Invalid)throw new Error("dual optimize failed");let a=i.second;e.erase(n),a.solveForEx(n,o),this._substitute(o,a),e.insert(o,a)}}}_getEnteringSymbol(e){let t=e.cells();for(let n=0,i=t.size();n<i;++n){let o=t.itemAt(n),a=o.first;if(o.second<0&&a.type()!==fm.Dummy)return a}return ew}_getDualEnteringSymbol(e){let t=Number.MAX_VALUE,n=ew,i=e.cells();for(let o=0,a=i.size();o<a;++o){let s=i.itemAt(o),l=s.first,c=s.second;if(c>0&&l.type()!==fm.Dummy){let A=this._objective.coefficientFor(l)/c;A<t&&(t=A,n=l)}}return n}_getLeavingSymbol(e){let t=Number.MAX_VALUE,n=ew,i=this._rowMap;for(let o=0,a=i.size();o<a;++o){let s=i.itemAt(o),l=s.first;if(l.type()!==fm.External){let c=s.second,u=c.coefficientFor(e);if(u<0){let A=-c.constant()/u;A<t&&(t=A,n=l)}}}return n}_getMarkerLeavingSymbol(e){let t=Number.MAX_VALUE,n=t,i=t,o=ew,a=o,s=o,l=o,c=this._rowMap;for(let u=0,A=c.size();u<A;++u){let d=c.itemAt(u),f=d.second,p=f.coefficientFor(e);if(p===0)continue;let C=d.first;if(C.type()===fm.External)l=C;else if(p<0){let v=-f.constant()/p;v<n&&(n=v,a=C)}else{let v=f.constant()/p;v<i&&(i=v,s=C)}}return a!==o?a:s!==o?s:l}_removeConstraintEffects(e,t){t.marker.type()===fm.Error&&this._removeMarkerEffects(t.marker,e.strength()),t.other.type()===fm.Error&&this._removeMarkerEffects(t.other,e.strength())}_removeMarkerEffects(e,t){let n=this._rowMap.find(e);n!==void 0?this._objective.insertRow(n.second,-t):this._objective.insertSymbol(e,-t)}_anyPivotableSymbol(e){let t=e.cells();for(let n=0,i=t.size();n<i;++n){let o=t.itemAt(n),a=o.first.type();if(a===fm.Slack||a===fm.Error)return o.first}return ew}_makeSymbol(e){return new Aye(e,this._idTick++)}}function W8(r){let e=1e-8;return r<0?-r<e:r<e}function Cct(){return _M()}function _ct(){return _M()}function Ect(){return _M()}function xct(){return _M()}var fm;(function(r){r[r.Invalid=0]="Invalid",r[r.External=1]="External",r[r.Slack=2]="Slack",r[r.Error=3]="Error",r[r.Dummy=4]="Dummy"})(fm||(fm={}));let Aye=class{constructor(e,t){Le(this,"_id");Le(this,"_type");this._id=t,this._type=e}id(){return this._id}type(){return this._type}},ew=new Aye(fm.Invalid,-1);class q8{constructor(e=0){Le(this,"_cellMap",_M());Le(this,"_constant");this._constant=e}cells(){return this._cellMap}constant(){return this._constant}isConstant(){return this._cellMap.empty()}allDummies(){let e=this._cellMap;for(let t=0,n=e.size();t<n;++t)if(e.itemAt(t).first.type()!==fm.Dummy)return!1;return!0}copy(){let e=new q8(this._constant);return e._cellMap=this._cellMap.copy(),e}add(e){return this._constant+=e}insertSymbol(e,t=1){let n=this._cellMap.setDefault(e,()=>0);W8(n.second+=t)&&this._cellMap.erase(e)}insertRow(e,t=1){this._constant+=e._constant*t;let n=e._cellMap;for(let i=0,o=n.size();i<o;++i){let a=n.itemAt(i);this.insertSymbol(a.first,a.second*t)}}removeSymbol(e){this._cellMap.erase(e)}reverseSign(){this._constant=-this._constant;let e=this._cellMap;for(let t=0,n=e.size();t<n;++t){let i=e.itemAt(t);i.second=-i.second}}solveFor(e){let t=this._cellMap,i=-1/t.erase(e).second;this._constant*=i;for(let o=0,a=t.size();o<a;++o)t.itemAt(o).second*=i}solveForEx(e,t){this.insertSymbol(e,-1),this.solveFor(t)}coefficientFor(e){let t=this._cellMap.find(e);return t!==void 0?t.second:0}substitute(e,t){let n=this._cellMap.erase(e);n!==void 0&&this.insertRow(t,n.second)}}function EM([r,e],[t,n],{lineThickness:i=0}={}){return i===0?fQ(r,e,t,n):bct(r,e,t,n)<=i}function fQ(r,e,t,n){const i=Z8(r,e,t),o=Z8(r,e,n),a=Z8(t,n,r),s=Z8(t,n,e);return!!(i!==o&&a!==s||i===0&&X8(r,t,e)||o===0&&X8(r,n,e)||a===0&&X8(t,r,n)||s===0&&X8(t,e,n))}function Z8(r,e,t){const n=(e.y-r.y)*(t.x-e.x)-(e.x-r.x)*(t.y-e.y);return n===0?0:n>0?1:2}function X8(r,e,t){return e.x<=Math.max(r.x,t.x)&&e.x>=Math.min(r.x,t.x)&&e.y<=Math.max(r.y,t.y)&&e.y>=Math.min(r.y,t.y)}function bct(r,e,t,n){if(r.x===e.x&&r.y===e.y)return bE(r,t,n);if(t.x===n.x&&t.y===n.y)return bE(t,r,e);if(fQ(r,e,t,n))return 0;const i=[bE(r,t,n),bE(e,t,n),bE(t,r,e),bE(n,r,e)];return Math.min(...i)}function bE(r,e,t){const n=(t.x-e.x)**2+(t.y-e.y)**2;if(n===0)return xx(r,e);let i=((r.x-e.x)*(t.x-e.x)+(r.y-e.y)*(t.y-e.y))/n;i=Math.max(0,Math.min(1,i));const o={x:e.x+i*(t.x-e.x),y:e.y+i*(t.y-e.y)};return xx(r,o)}function xx(r,e){const t=r.x-e.x,n=r.y-e.y;return Math.sqrt(t*t+n*n)}function Bct(r,e,t,n){if(r.x===e.x&&r.y===e.y)return bE(r,t,n);if(t.x===n.x&&t.y===n.y)return bE(t,r,e);if(fQ(r,e,t,n))return 0;const i=[bE(r,t,n),bE(e,t,n),bE(t,r,e),bE(n,r,e)];return Math.min(...i)}function Sct(r,e,t){const n={x:t.minX,y:t.minY},i={x:t.maxX,y:t.minY},o={x:t.minX,y:t.maxY},a={x:t.maxX,y:t.maxY};if(fQ(r,e,n,i)||fQ(r,e,i,a)||fQ(r,e,a,o)||fQ(r,e,o,n)||r.x>=t.minX&&r.x<=t.maxX&&r.y>=t.minY&&r.y<=t.maxY&&e.x>=t.minX&&e.x<=t.maxX&&e.y>=t.minY&&e.y<=t.maxY)return 0;const s=[bE(n,r,e),bE(i,r,e),bE(o,r,e),bE(a,r,e)];if(r.x>=t.minX&&r.x<=t.maxX&&r.y>=t.minY&&r.y<=t.maxY||e.x>=t.minX&&e.x<=t.maxX&&e.y>=t.minY&&e.y<=t.maxY)return 0;if(r.x<t.minX||r.x>t.maxX||r.y<t.minY||r.y>t.maxY){const l=$2(r.x,t.minX,t.maxX),c=$2(r.y,t.minY,t.maxY);s.push(xx(r,{x:l,y:c}))}if(e.x<t.minX||e.x>t.maxX||e.y<t.minY||e.y>t.maxY){const l=$2(e.x,t.minX,t.maxX),c=$2(e.y,t.minY,t.maxY);s.push(xx(e,{x:l,y:c}))}return Math.min(...s)}function wct(r,e,t){const n={x:t.x,y:t.y};if(r.x===e.x&&r.y===e.y)return Math.max(0,xx(r,n)-t.radius);const i={x:e.x-r.x,y:e.y-r.y},o={x:n.x-r.x,y:n.y-r.y},a=i.x*i.x+i.y*i.y,s=Math.max(0,Math.min(1,(i.x*o.x+i.y*o.y)/a)),l={x:r.x+s*i.x,y:r.y+s*i.y},c=xx(l,n);return Math.max(0,c-t.radius)}var GV=(r,e)=>{const t={x:e.x-r.x,y:e.y-r.y},n=Math.sqrt(t.x**2+t.y**2);return{x:t.x/n,y:t.y/n}},OV=r=>{switch(r){case"up":return{x:0,y:1};case"down":return{x:0,y:-1};case"left":return{x:-1,y:0};case"right":return{x:1,y:0}}},dye=(r,e={})=>{let t=r._internal_store;if(!t){t={counts:{}},r._internal_store=t;for(const i of r){const o=i.type,a=i[`${o}_id`];if(!a)continue;const s=Number.parseInt(a.split("_").pop());Number.isNaN(s)||(t.counts[o]=Math.max(t.counts[o]??0,s))}}return new Proxy({},{get:(i,o)=>o==="toArray"?()=>r:{get:a=>r.find(s=>s.type===o&&s[`${o}_id`]===a),getUsing:a=>{const s=Object.keys(a);if(s.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const l=s[0],c=l.replace("_id",""),u=r.find(A=>A.type===c&&A[l]===a[l]);return u?r.find(A=>A.type===o&&A[`${o}_id`]===u[`${o}_id`]):null},getWhere:a=>{const s=Object.keys(a);return r.find(l=>l.type===o&&s.every(c=>l[c]===a[c]))},list:a=>{const s=a?Object.keys(a):[];return r.filter(l=>l.type===o&&s.every(c=>l[c]===a[c]))},insert:a=>{var c;(c=t.counts)[o]??(c[o]=-1),t.counts[o]++;const s=t.counts[o],l={type:o,[`${o}_id`]:`${o}_${s}`,...a};return e.validateInserts&&(XT[o]??cR).parse(l),r.push(l),l},delete:a=>{const s=r.find(l=>l[`${o}_id`]===a);s&&r.splice(r.indexOf(s),1)},update:(a,s)=>{const l=r.find(c=>c[`${o}_id`]===a);if(l)return Object.assign(l,s),l},select:a=>{if(o==="source_component")return r.find(s=>s.type==="source_component"&&s.name===a.replace(/\./g,""));if(o==="pcb_port"||o==="source_port"||o==="schematic_port"){const[s,l]=a.replace(/\./g,"").split(/[\s\>]+/),c=r.find(A=>A.type==="source_component"&&A.name===s);if(!c)return null;const u=r.find(A=>A.type==="source_port"&&A.source_component_id===c.source_component_id&&(A.name===l||(A.port_hints??[]).includes(l)));if(!u)return null;if(o==="source_port")return u;if(o==="pcb_port")return r.find(A=>A.type==="pcb_port"&&A.source_port_id===u.source_port_id);if(o==="schematic_port")return r.find(A=>A.type==="schematic_port"&&A.source_port_id===u.source_port_id)}}}})};dye.unparsed=dye;var Qct=r=>{if(r==="up")return"right";if(r==="right")return"down";if(r==="down")return"left";if(r==="left")return"up";throw new Error(`Invalid direction: ${r}`)},Mct=r=>{if(r==="up")return"left";if(r==="left")return"down";if(r==="down")return"right";if(r==="right")return"up";throw new Error(`Invalid direction: ${r}`)},Dct=(r,e)=>{for(;e>0;)r=Qct(r),e--;for(;e<0;)r=Mct(r),e++;return r},Rct=(r,e)=>{if(r.type==="schematic_component")r.center=Xr(e,r.center);else if(r.type==="schematic_port")r.center=Xr(e,r.center),r.facing_direction&&(r.facing_direction=Dct(r.facing_direction,-(Math.atan2(e.b,e.a)/Math.PI)*2));else if(r.type==="schematic_text")r.position=Xr(e,r.position);else if(r.type!=="schematic_trace"){if(r.type==="schematic_box"){const{x:t,y:n}=Xr(e,{x:r.x,y:r.y});r.x=t,r.y=n}else if(r.type==="schematic_line"){const{x:t,y:n}=Xr(e,{x:r.x1,y:r.y1}),{x:i,y:o}=Xr(e,{x:r.x2,y:r.y2});r.x1=t,r.y1=n,r.x2=i,r.y2=o}}return r},fye=(r,e)=>{const t=r;for(const n of e.boxes){const i=t.find(a=>a.type==="schematic_component"&&a.schematic_component_id===n.box_id),o=OA(n.x-i.center.x,n.y-i.center.y);for(const a of t)a.schematic_component_id===n.box_id&&Rct(a,o)}return t},hye=r=>{const e=[],t=[],n=[],i={schematic_component:r.filter(o=>o.type==="schematic_component"),schematic_port:r.filter(o=>o.type==="schematic_port"),source_port:r.filter(o=>o.type==="source_port"),schematic_trace:r.filter(o=>o.type==="schematic_trace"),source_trace:r.filter(o=>o.type==="source_trace")};for(const o of i.schematic_component){const a=[],s=o.schematic_component_id;for(const c of i.schematic_port)c.schematic_component_id===o.schematic_component_id&&a.push({port_id:`${s}.${c.schematic_port_id}`,rx:c.center.x-o.center.x,ry:c.center.y-o.center.y});const l={box_id:s,x:o.center.x,y:o.center.y,ports:a};e.push(l)}for(const o of i.source_trace){const[a,s]=o.connected_source_port_ids,l=i.schematic_port.find(f=>f.source_port_id===a),c=i.schematic_port.find(f=>f.source_port_id===s);if(!l||!c)continue;const u=i.schematic_component.find(f=>f.schematic_component_id===l.schematic_component_id),A=i.schematic_component.find(f=>f.schematic_component_id===c.schematic_component_id);if(!u||!A)continue;const d={from:`${u.schematic_component_id}.${l.schematic_port_id}`,to:`${A.schematic_component_id}.${c.schematic_port_id}`};t.push(d)}return{boxes:e,connections:t,nets:n}};function Nct(r){return r.connections.reduce((e,t)=>(e[t.from]=t.to,e[t.to]=t.from,e),{})}function Tct(r,e){for(const t of["left","right"]){const n=r.filter(a=>a.side===t),i=n.map(a=>a.ascending_box_index).filter(a=>!isNaN(a)),o=Math.max(...i);for(const a of n)a.box_id!==e.box_id&&(a.y-=o/2*1.25)}}var Pct=r=>{let e=r[0];for(const t of r)t.ports.length>e.ports.length&&(e=t);return e};function kct(r,e,t,n){for(const i of["left","right"]){const o=r.filter(a=>a.side===i).sort((a,s)=>a.ascending_box_index-s.ascending_box_index);for(let a=0;a<o.length-1;a++){const[s,l]=[o[a],o[a+1]];if(s.ports.length===2&&l.ports.length===2){const[c,u]=s.ports,[A,d]=l.ports,[f,p]=[c,u].map(b=>e[b.port_id]),[C,v]=[A,d].map(b=>e[b.port_id]);let _=null;if((f===C||f===v)&&t.has(f)?_=f:(p===C||p===v)&&t.has(p)&&(_=p),!_)continue;const x=n.nets.find(b=>b.net_id===_);if(!x.is_ground&&!x.is_power)continue;x.is_ground&&o.slice(a+1).forEach(b=>{b.ascending_box_index-=1,b.y-=1}),x.is_power&&o.slice(a+1).forEach(b=>{b.ascending_box_index-=1,b.y-=1})}}}}function Uct(r,e){for(let t=0;t<r;t++){let n=0;for(const i of e)i.ascending_box_index===t&&(n+=1);if(n===0){r-=1;for(const i of e)i.ascending_box_index>t&&(i.ascending_box_index-=1)}}return r}function Fct(r,e,t,n){const i=Math.max(...r.map(o=>o.ascending_box_index).filter(o=>!isNaN(o)));for(const o of["left","right"])for(let a=0;a<=i;a++){const s=r.filter(p=>p.side===o).filter(p=>p.ascending_box_index===a);if(s.length===0)continue;const c=s.map(p=>e.connections.filter(C=>C.from.startsWith(p.box_id+".")||C.to.startsWith(p.box_id+".")).map(C=>C.from.startsWith(p.box_id+".")?C.to:C.from)).map(p=>p.filter(C=>t.has(C))),u=c.reduce((p,C)=>p.filter(v=>C.includes(v)),c[0]),A=u.map(p=>e.nets.find(C=>C.net_id===p)),f=(o==="left"?Math.max:Math.min)(...s.map(p=>p.x));for(const p of A){const C=a+(p!=null&&p.is_ground?-1:1),v=`${p==null?void 0:p.net_id}_${o==="left"?"L":"R"}_${a}`,_=p!=null&&p.is_ground?`${v}.top`:`${v}.bottom`,x={box_id:v,x:f,y:C,side:o,ascending_port_index:0,ascending_box_index:a,width:0,ports:[{port_id:_,rx:0,ry:p!=null&&p.is_ground?.1:-.1}]};r.push(x);for(const b of s){const P=n.filter(F=>F.from.startsWith(b.box_id+".")||F.to.startsWith(b.box_id+"."));for(const F of P)F.from===p.net_id&&(F.from=_),F.to===p.net_id&&(F.to=_)}}for(let p=0;p<s.length;p++){const C=s[p],v=c[p].filter(_=>!u.includes(_));for(const _ of v){const x=e.nets.find(H=>H.net_id===_),b=`${_}_${C.ascending_box_index}_${o==="left"?"L":"R"}_${p}`,P=`${b}.${x.is_ground?"top":"bottom"}`,F={x:C.x,y:C.y+(x.is_ground?-1:1),side:o,ascending_port_index:0,ascending_box_index:C.ascending_box_index,box_id:b,ports:[{port_id:P,rx:0,ry:x.is_ground?.1:-.1}]};r.push(F);const U=n.find(H=>H.from===_&&H.to.startsWith(C.box_id)||H.to===_&&H.from.startsWith(C.box_id));U.from===_&&(U.from=P),U.to===_&&(U.to=P)}}}return i}var pye=(r,e)=>{const t=xE(e*(Math.PI/180));r.ports.forEach(n=>{const i=Xr(t,{x:n.rx,y:n.ry});n.rx=i.x,n.ry=i.y})},gye=r=>{const e=Math.sqrt(r.x**2+r.y**2);return{x:r.x/e,y:r.y/e}},Lct=r=>[0,90,180,270].map(t=>{const n={...r,ports:r.ports.map(i=>({...i}))};return pye(n,t),n.applied_rotation_deg=t,n}),Gct=r=>{const e=r.boxes.sort((t,n)=>t.y-n.y);for(const t of e)if(t.ports.length===2){const n=t.ports.map(a=>{var u;const s=r.connections.filter(A=>A.from===a.port_id||A.to===a.port_id).map(A=>A.from===a.port_id?A.to:A.from);if(s.length===0)return null;const l=e.filter(A=>s.some(d=>d.startsWith(A.box_id+"."))),c=(u=l.flatMap(A=>A.ports))==null?void 0:u.filter(A=>s.includes(A.port_id));for(const A of c){const d=l.find(f=>f.box_id===A.port_id.split(".")[0]);A.x=d.x+A.rx,A.y=d.y+A.ry}return{...a,connected_port:c[0],connected_ports:c}}).filter(Boolean);if(n.length===0)continue;const i=Lct({...t,ports:n});for(const a of i){a.natural_offset_sum_deg=0;for(const s of a.ports)for(const l of s.connected_ports){const c=gye({x:l.x-(a.x+s.rx),y:l.y-(a.y+s.ry)}),u=gye({x:s.rx,y:s.ry}),A=Math.sqrt((c.x-u.x)**2+(c.y-u.y)**2),d=c.x*u.x+c.y*u.y,f=c.x*u.y-c.y*u.x,p=Math.atan2(f,d)*(180/Math.PI);a.natural_offset_sum_deg+=Math.abs(p)/A}}const o=i.reduce((a,s)=>a.natural_offset_sum_deg<s.natural_offset_sum_deg?a:s);pye(t,o.applied_rotation_deg)}return r},mye=r=>{const e=new Set(r.nets.map(l=>l.net_id)),t=Nct(r),n=JSON.parse(JSON.stringify(r.boxes)),i=JSON.parse(JSON.stringify(r.connections));for(const l of n){l.x=0,l.y=0;let c=0,u=0;for(const A of l.ports)A.rx<c?c=A.rx:A.rx>u&&(u=A.rx);l.width=u-c}const o=Pct(n);for(const l of o.ports)l.rx>0?l.side="right":l.rx<0&&(l.side="left");for(const l of n){if(l.box_id===o.box_id)continue;const c=o.ports.filter(d=>i.some(f=>f.from.startsWith(l.box_id)&&f.to===d.port_id||f.to.startsWith(l.box_id)&&f.from===d.port_id));if(c.length===0){l.side="left";continue}let u=0,A=0;for(const d of c)d.rx>0?A+=1:d.rx<0&&(u+=1);u>=A?l.side="left":l.side="right"}for(const l of["left","right"]){const c=o.ports.filter(u=>u.side===l);c.sort((u,A)=>u.ry-A.ry);for(const u of c)u.ascending_port_index=c.indexOf(u)}for(const l of n){if(l.box_id===o.box_id)continue;const c=r.connections.filter(A=>A.from.startsWith(l.box_id+".")||A.to.startsWith(l.box_id+".")).map(A=>A.from.startsWith(l.box_id+".")?A.to:A.from),u=o.ports.filter(A=>c.includes(A.port_id));u.length!==0&&(l.ascending_port_index=Math.min(...u.map(A=>A.ascending_port_index)),l.ascending_box_index=l.ascending_port_index)}let a=Math.max(0,...n.map(l=>l.ascending_box_index).filter(l=>!isNaN(l)));for(const l of n)l.box_id!==o.box_id&&l.ascending_box_index===void 0&&(a+=1,l.ascending_box_index=a);for(const l of["left","right"])Uct(a,n.filter(c=>c.side===l));for(const l of["left","right"]){let c=o.width*.75*(l==="left"?-1:1);for(let u=0;u<=a;u++){const A=n.filter(p=>p.side===l&&p.ascending_box_index===u),d=Math.max(...A.map(p=>p.width)),f=Math.max(.5,d)*(l==="left"?-1:1);c+=f;for(const p of A)p.box_id!==o.box_id&&(p.y=p.ascending_box_index*1.25,p.x=c);c+=f/2}}kct(n,t,e,r),Fct(n,r,e,i),Tct(n,o);const s={...r,connections:i,boxes:n};return Gct(s),s};function tw(r){throw new Error('Could not dynamically require "'+r+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var zV={exports:{}},yye;function Oct(){return yye||(yye=1,function(r,e){(function(t){r.exports=t()})(function(){return function t(n,i,o){function a(c,u){if(!i[c]){if(!n[c]){var A=typeof tw=="function"&&tw;if(!u&&A)return A(c,!0);if(s)return s(c,!0);throw new Error("Cannot find module '"+c+"'")}u=i[c]={exports:{}},n[c][0].call(u.exports,function(d){var f=n[c][1][d];return a(f||d)},u,u.exports,t,n,i,o)}return i[c].exports}for(var s=typeof tw=="function"&&tw,l=0;l<o.length;l++)a(o[l]);return a}({1:[function(t,n,i){(function(o,a,s,l,c,u,A,d,f){var p=t("crypto");function C(U,H){H=x(U,H);var L;return(L=H.algorithm!=="passthrough"?p.createHash(H.algorithm):new F).write===void 0&&(L.write=L.update,L.end=L.update),P(H,L).dispatch(U),L.update||L.end(""),L.digest?L.digest(H.encoding==="buffer"?void 0:H.encoding):(U=L.read(),H.encoding!=="buffer"?U.toString(H.encoding):U)}(i=n.exports=C).sha1=function(U){return C(U)},i.keys=function(U){return C(U,{excludeValues:!0,algorithm:"sha1",encoding:"hex"})},i.MD5=function(U){return C(U,{algorithm:"md5",encoding:"hex"})},i.keysMD5=function(U){return C(U,{algorithm:"md5",encoding:"hex",excludeValues:!0})};var v=p.getHashes?p.getHashes().slice():["sha1","md5"],_=(v.push("passthrough"),["buffer","hex","binary","base64"]);function x(U,H){var L={};if(L.algorithm=(H=H||{}).algorithm||"sha1",L.encoding=H.encoding||"hex",L.excludeValues=!!H.excludeValues,L.algorithm=L.algorithm.toLowerCase(),L.encoding=L.encoding.toLowerCase(),L.ignoreUnknown=H.ignoreUnknown===!0,L.respectType=H.respectType!==!1,L.respectFunctionNames=H.respectFunctionNames!==!1,L.respectFunctionProperties=H.respectFunctionProperties!==!1,L.unorderedArrays=H.unorderedArrays===!0,L.unorderedSets=H.unorderedSets!==!1,L.unorderedObjects=H.unorderedObjects!==!1,L.replacer=H.replacer||void 0,L.excludeKeys=H.excludeKeys||void 0,U===void 0)throw new Error("Object argument required.");for(var j=0;j<v.length;++j)v[j].toLowerCase()===L.algorithm.toLowerCase()&&(L.algorithm=v[j]);if(v.indexOf(L.algorithm)===-1)throw new Error('Algorithm "'+L.algorithm+'" not supported. supported values: '+v.join(", "));if(_.indexOf(L.encoding)===-1&&L.algorithm!=="passthrough")throw new Error('Encoding "'+L.encoding+'" not supported. supported values: '+_.join(", "));return L}function b(U){if(typeof U=="function")return/^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i.exec(Function.prototype.toString.call(U))!=null}function P(U,H,L){L=L||[];function j(O){return H.update?H.update(O,"utf8"):H.write(O,"utf8")}return{dispatch:function(O){return this["_"+((O=U.replacer?U.replacer(O):O)===null?"null":typeof O)](O)},_object:function(O){var oe,te=Object.prototype.toString.call(O),ie=/\[object (.*)\]/i.exec(te);if(ie=(ie=ie?ie[1]:"unknown:["+te+"]").toLowerCase(),0<=(te=L.indexOf(O)))return this.dispatch("[CIRCULAR:"+te+"]");if(L.push(O),s!==void 0&&s.isBuffer&&s.isBuffer(O))return j("buffer:"),j(O);if(ie==="object"||ie==="function"||ie==="asyncfunction")return te=Object.keys(O),U.unorderedObjects&&(te=te.sort()),U.respectType===!1||b(O)||te.splice(0,0,"prototype","__proto__","constructor"),U.excludeKeys&&(te=te.filter(function(pe){return!U.excludeKeys(pe)})),j("object:"+te.length+":"),oe=this,te.forEach(function(pe){oe.dispatch(pe),j(":"),U.excludeValues||oe.dispatch(O[pe]),j(",")});if(!this["_"+ie]){if(U.ignoreUnknown)return j("["+ie+"]");throw new Error('Unknown object type "'+ie+'"')}this["_"+ie](O)},_array:function(O,pe){pe=pe!==void 0?pe:U.unorderedArrays!==!1;var te=this;if(j("array:"+O.length+":"),!pe||O.length<=1)return O.forEach(function(Ae){return te.dispatch(Ae)});var ie=[],pe=O.map(function(Ae){var de=new F,Ie=L.slice();return P(U,de,Ie).dispatch(Ae),ie=ie.concat(Ie.slice(L.length)),de.read().toString()});return L=L.concat(ie),pe.sort(),this._array(pe,!1)},_date:function(O){return j("date:"+O.toJSON())},_symbol:function(O){return j("symbol:"+O.toString())},_error:function(O){return j("error:"+O.toString())},_boolean:function(O){return j("bool:"+O.toString())},_string:function(O){j("string:"+O.length+":"),j(O.toString())},_function:function(O){j("fn:"),b(O)?this.dispatch("[native]"):this.dispatch(O.toString()),U.respectFunctionNames!==!1&&this.dispatch("function-name:"+String(O.name)),U.respectFunctionProperties&&this._object(O)},_number:function(O){return j("number:"+O.toString())},_xml:function(O){return j("xml:"+O.toString())},_null:function(){return j("Null")},_undefined:function(){return j("Undefined")},_regexp:function(O){return j("regex:"+O.toString())},_uint8array:function(O){return j("uint8array:"),this.dispatch(Array.prototype.slice.call(O))},_uint8clampedarray:function(O){return j("uint8clampedarray:"),this.dispatch(Array.prototype.slice.call(O))},_int8array:function(O){return j("int8array:"),this.dispatch(Array.prototype.slice.call(O))},_uint16array:function(O){return j("uint16array:"),this.dispatch(Array.prototype.slice.call(O))},_int16array:function(O){return j("int16array:"),this.dispatch(Array.prototype.slice.call(O))},_uint32array:function(O){return j("uint32array:"),this.dispatch(Array.prototype.slice.call(O))},_int32array:function(O){return j("int32array:"),this.dispatch(Array.prototype.slice.call(O))},_float32array:function(O){return j("float32array:"),this.dispatch(Array.prototype.slice.call(O))},_float64array:function(O){return j("float64array:"),this.dispatch(Array.prototype.slice.call(O))},_arraybuffer:function(O){return j("arraybuffer:"),this.dispatch(new Uint8Array(O))},_url:function(O){return j("url:"+O.toString())},_map:function(O){return j("map:"),O=Array.from(O),this._array(O,U.unorderedSets!==!1)},_set:function(O){return j("set:"),O=Array.from(O),this._array(O,U.unorderedSets!==!1)},_file:function(O){return j("file:"),this.dispatch([O.name,O.size,O.type,O.lastModfied])},_blob:function(){if(U.ignoreUnknown)return j("[blob]");throw Error(`Hashing Blob objects is currently not supported
643
+ `),{solved:!1,connectionName:r.name}}createObstacleList({dominantLayer:r,connection:e,obstaclesFromTraces:t}){return new fme(this.allObstacles.filter(n=>!n.connectedTo.includes(e.name)).filter(n=>n.layers.includes(r)).concat(t??[]))}postprocessConnectionSolveResult(r,e){return e}solve(){const r=[],e=[];this.debugTraceCount=0;for(const t of this.input.connections){const n=t.pointsToConnect[0].layer??"top";this.debugTraceCount+=1,this.obstacles=this.createObstacleList({dominantLayer:n,connection:t,obstaclesFromTraces:e});let i=this.solveConnection(t);i=this.postprocessConnectionSolveResult(t,i),r.push(i),dQ.enabled&&this.drawDebugTraceObstacles(e),i.solved&&e.push(...dme(i.route.map(o=>({x:o.x,y:o.y,layer:o.layer??n})),t.name))}return r}solveAndMapToTraces(){return this.solve().flatMap(e=>e.solved?[{type:"pcb_trace",pcb_trace_id:`pcb_trace_for_${e.connectionName}`,route:hlt(e.route.map(t=>({route_type:"wire",x:t.x,y:t.y,width:this.input.minTraceWidth,layer:t.layer})))}]:[])}getDebugGroup(){const r=`t${this.debugTraceCount}_iter[${this.iterations-1}]`;return this.iterations<30||this.iterations<100&&this.iterations%10===0||this.iterations<1e3&&this.iterations%100===0||!this.debugSolutions?r:null}drawDebugTraceObstacles(r){const{debugTraceCount:e,debugSolutions:t}=this;for(const n in t)n.startsWith(`t${e}_`)&&t[n].push(...r.map((i,o)=>({type:"pcb_smtpad",pcb_component_id:"",layer:i.layers[0],width:i.width,shape:"rect",x:i.center.x,y:i.center.y,pcb_smtpad_id:`trace_obstacle_${o}`,height:i.height})))}drawDebugSolution({current:r,newNeighbors:e}){const t=this.getDebugGroup();if(!t)return;const{openSet:n,debugTraceCount:i,debugSolutions:o}=this;o[t]??(o[t]=[]);const a=o[t];a.push({type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:`debug_note_${r.x}_${r.y}`,font:"tscircuit2024",font_size:.25,text:"X"+(r.l!==void 0?r.l:""),pcb_component_id:"",layer:"top",anchor_position:{x:r.x,y:r.y},anchor_alignment:"center"});for(let s=0;s<n.length;s++){const l=n[s];a.push({type:"pcb_fabrication_note_path",pcb_component_id:"",pcb_fabrication_note_path_id:`note_path_${l.x}_${l.y}`,layer:"top",route:[[0,.05],[.05,0],[0,-.05],[-.05,0],[0,.05]].map(([c,u])=>({x:l.x+c,y:l.y+u})),stroke_width:.01}),a.push({type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:`debug_note_${l.x}_${l.y}`,font:"tscircuit2024",font_size:.03,text:s.toString(),pcb_component_id:"",layer:"top",anchor_position:{x:l.x,y:l.y},anchor_alignment:"center"})}if(r.parent){const s=[];let l=r;for(;l;)s.unshift(l),l=l.parent;a.push({type:"pcb_fabrication_note_path",pcb_component_id:"",pcb_fabrication_note_path_id:`note_path_${r.x}_${r.y}`,layer:"top",route:s,stroke_width:.01})}}},glt=u0("autorouting-dataset:infinite-grid-ijump-astar:get-distance-to-overcome-obstacle");function BV({node:r,travelDir:e,wallDir:t,obstacle:n,obstacles:i,obstaclesInRow:o=0,OBSTACLE_MARGIN:a=.15,SHOULD_DETECT_CONJOINED_OBSTACLES:s=!1,MAX_CONJOINED_OBSTACLES:l=20}){let c;if(e.dx===0?e.dy>0?c=n.center.y+n.height/2-r.y:c=r.y-(n.center.y-n.height/2):e.dx>0?c=n.center.x+n.width/2-r.x:c=r.x-(n.center.x-n.width/2),c+=a,s&&o<l){const u=i.getObstacleAt(r.x+e.dx*c+t.dx*(t.wallDistance+.001),r.y+e.dy*c+t.dy*(t.wallDistance+.001));if(u===n)return c;if(u&&u.type==="rect"){const A=e.dy===0,d=A?n.height:n.width;if((A?u.height:u.width)>d)return glt("next obstacle on path is bigger, not trying to overcome it"),c;const p=BV({node:{x:r.x+e.dx*c,y:r.y+e.dy*c},travelDir:e,wallDir:t,obstacle:u,obstacles:i,obstaclesInRow:o+1,SHOULD_DETECT_CONJOINED_OBSTACLES:s,MAX_CONJOINED_OBSTACLES:l,OBSTACLE_MARGIN:a});c+=p}}return c}var mlt=class extends pme{constructor(){super(...arguments);Le(this,"MAX_ITERATIONS",200)}getNeighbors(e){const t=this.obstacles,n=this.goalPoint;let i;e.parent?i=lme(e.parent,e):i=lme(e,n);const o=[{dx:0,dy:1},{dx:1,dy:0},{dx:0,dy:-1},{dx:-1,dy:0}].filter(s=>{var l;return s.dx===i.dx*-1&&s.dy===i.dy*-1?!1:!(s.dx===i.dx&&s.dy===i.dy&&((l=e.parent)!=null&&l.obstacleHit))}).map(s=>t.getOrthoDirectionCollisionInfo(e,s,{margin:this.OBSTACLE_MARGIN})).filter(s=>s.wallDistance>=this.OBSTACLE_MARGIN),a=[];for(const s of o){let l=null;e!=null&&e.obstacleHit&&(l=BV({node:e,travelDir:s,wallDir:{...i,wallDistance:this.OBSTACLE_MARGIN},obstacle:e.obstacleHit,obstacles:t,OBSTACLE_MARGIN:this.OBSTACLE_MARGIN,SHOULD_DETECT_CONJOINED_OBSTACLES:!0}));const c=cme(e,n,s),u=(s.dx===0||Math.sign(n.x-e.x)===s.dx)&&(s.dy===0||Math.sign(n.y-e.y)===s.dy);c<s.wallDistance&&c>0&&u?a.push({...s,travelDistance:c}):l!==null&&l<s.wallDistance?a.push({...s,travelDistance:l}):s.wallDistance!==1/0&&a.push({...s,travelDistance:s.wallDistance-this.OBSTACLE_MARGIN})}return a.filter(s=>!t.isObstacleAt(e.x+s.dx*s.travelDistance,e.y+s.dy*s.travelDistance)).map(s=>({x:e.x+s.dx*s.travelDistance,y:e.y+s.dy*s.travelDistance,obstacleHit:s.obstacle}))}};function ylt(r,e=4){const{center:t,width:n,height:i,rotation:o}=r,a=[],s=o*Math.PI/180,l=Math.cos(s),c=Math.sin(s),u=(o%360+360)%360;if(i<=n?u>=45&&u<135||u>=225&&u<315:u>=135&&u<225||u>=315||u<45){const d=n/e;for(let f=0;f<e;f++){const p=(f-e/2+.5)*d,C=-p*l,v=-p*c,_=d*1.1,x=Math.abs(i*l)+Math.abs(d*c);a.push({center:{x:t.x+C,y:t.y+v},width:_,height:x})}}else{const d=i/e;for(let f=0;f<e;f++){const p=(f-e/2+.5)*d,C=-p*c,v=p*l,_=Math.abs(n*l)+Math.abs(d*c),x=d*1.1;a.push({center:{x:t.x+C,y:t.y+v},width:_,height:x})}}return a}var Y8=["top","inner1","inner2","bottom"],SV=(r,e)=>{const t=i=>e?i.concat(i.map(o=>e==null?void 0:e.getNetConnectedToId(o)).filter(Boolean)):i,n=[];for(const i of r)if(i.type==="pcb_smtpad"){if(i.shape==="circle")n.push({type:"oval",layers:[i.layer],center:{x:i.x,y:i.y},width:i.radius*2,height:i.radius*2,connectedTo:t([i.pcb_smtpad_id])});else if(i.shape==="rect")n.push({type:"rect",layers:[i.layer],center:{x:i.x,y:i.y},width:i.width,height:i.height,connectedTo:t([i.pcb_smtpad_id])});else if(i.shape==="rotated_rect"){const o={center:{x:i.x,y:i.y},width:i.width,height:i.height,rotation:i.ccw_rotation},a=ylt(o);for(const s of a)n.push({type:"rect",layers:[i.layer],center:s.center,width:s.width,height:s.height,connectedTo:t([i.pcb_smtpad_id])})}}else if(i.type==="pcb_keepout")i.shape==="circle"?n.push({type:"oval",layers:i.layers,center:{x:i.center.x,y:i.center.y},width:i.radius*2,height:i.radius*2,connectedTo:[]}):i.shape==="rect"&&n.push({type:"rect",layers:i.layers,center:{x:i.center.x,y:i.center.y},width:i.width,height:i.height,connectedTo:[]});else if(i.type==="pcb_hole")i.hole_shape==="oval"?n.push({type:"oval",center:{x:i.x,y:i.y},width:i.hole_width,height:i.hole_height,connectedTo:[]}):i.hole_shape==="square"?n.push({type:"rect",layers:Y8,center:{x:i.x,y:i.y},width:i.hole_diameter,height:i.hole_diameter,connectedTo:[]}):(i.hole_shape==="round"||i.hole_shape==="circle")&&n.push({type:"rect",layers:Y8,center:{x:i.x,y:i.y},width:i.hole_diameter,height:i.hole_diameter,connectedTo:[]});else if(i.type==="pcb_plated_hole")i.shape==="circle"?n.push({type:"oval",layers:Y8,center:{x:i.x,y:i.y},width:i.outer_diameter,height:i.outer_diameter,connectedTo:t([i.pcb_plated_hole_id])}):(i.shape==="oval"||i.shape==="pill")&&n.push({type:"oval",layers:Y8,center:{x:i.x,y:i.y},width:i.outer_width,height:i.outer_height,connectedTo:t([i.pcb_plated_hole_id])});else if(i.type==="pcb_trace"){const o=dme(i.route.map(a=>({x:a.x,y:a.y,layer:"layer"in a?a.layer:a.from_layer})),i.source_trace_id);n.push(...o)}else i.type==="pcb_via"&&n.push({type:"rect",layers:i.layers,center:{x:i.x,y:i.y},connectedTo:[],width:i.outer_diameter,height:i.outer_diameter});return n};function gme(r){const{pcbConnMap:e,goalElementId:t}=r;if(!t.startsWith("pcb_port_"))throw new Error(`Currently alternative goal boxes must have a goal id with prefix "pcb_port_" (got ${t})`);const n=e.getAllTracesConnectedToPort(t);return SV(n).map(i=>({...i,connectedTo:[t]}))}var mme=r=>{let{connection:e,pcbConnMap:t}=r;if(e.pointsToConnect.length!==2)throw new Error(`Connection must have exactly 2 points for alternative goal boxes (got ${e.pointsToConnect.length})`);const[n,i]=e.pointsToConnect;if(!n.pcb_port_id||!i.pcb_port_id)throw new Error(`Connection points must have pcb_port_id for alternative goal box calculation (got ${n.pcb_port_id} and ${i.pcb_port_id})`);const o=gme({goalElementId:n.pcb_port_id,pcbConnMap:t}).concat([{center:n,width:.01,height:.01,connectedTo:[n.pcb_port_id],layers:[n.layer],type:"rect"}]),a=gme({goalElementId:i.pcb_port_id,pcbConnMap:t}).concat([{center:i,width:.01,height:.01,connectedTo:[i.pcb_port_id],layers:[i.layer],type:"rect"}]);if(o.length<=1&&a.length<=1)return{...e,startPoint:n,endPoint:i,goalBoxes:[]};const s=Alt(o,a);let l,c,u;return o.length>=a.length?(l={...i,...s.pointB},c={...n,...s.pointA},u=o):(l={...n,...s.pointA},c={...i,...s.pointB},u=a),{startPoint:l,endPoint:c,goalBoxes:u,name:e.name,pointsToConnect:[l,c]}},vlt=(r,e={})=>{const t={minTraceWidth:.1};t.layerCount=e.layerCount??1,t.obstacles=SV(r,e.connMap),t.connections=[];for(const i of r)if(i.type==="source_trace"){let o={name:i.source_trace_id,pointsToConnect:i.connected_source_port_ids.map(a=>{var l;const s=dm(r).pcb_port.getWhere({source_port_id:a});if(!s)throw new Error(`Could not find pcb_port for source_port_id "${a}"`);return{x:s.x,y:s.y,layer:((l=s.layers)==null?void 0:l[0])??"top",pcb_port_id:s.pcb_port_id}})};if(e.optimizeWithGoalBoxes){const a=new ame(r);o=mme({connection:o,pcbConnMap:a})}t.connections.push(o),Ilt(t.obstacles,o.pointsToConnect,o.name)}const n={minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0};for(const i of t.obstacles)n.minX=Math.min(n.minX,i.center.x-i.width/2),n.maxX=Math.max(n.maxX,i.center.x+i.width/2),n.minY=Math.min(n.minY,i.center.y-i.height/2),n.maxY=Math.max(n.maxY,i.center.y+i.height/2);for(const i of t.connections)for(const o of i.pointsToConnect)n.minX=Math.min(n.minX,o.x),n.maxX=Math.max(n.maxX,o.x),n.minY=Math.min(n.minY,o.y),n.maxY=Math.max(n.maxY,o.y);return t.bounds=n,t},Ilt=(r,e,t)=>{for(const n of e)for(const i of r)Clt(n,i)&&i.connectedTo.push(t)};function Clt(r,e){const t=e.width/2,n=e.height/2;if(e.type==="rect")return r.x>=e.center.x-t&&r.x<=e.center.x+t&&r.y>=e.center.y-n&&r.y<=e.center.y+n;if(e.type==="oval"){const i=(r.x-e.center.x)/t,o=(r.y-e.center.y)/n;return i*i+o*o<=1}return!1}function yme(r,e){const t=e.x>r.x?1:e.x<r.x?-1:0,n=e.y>r.y?1:e.y<r.y?-1:0,i=e.l>r.l?1:e.l<r.l?-1:0;return{dx:t,dy:n,dl:i}}var wV={1:["top"],2:["top","bottom"],4:["top","inner1","inner2","bottom"]},_lt=r=>wV[r];function vme(r,e){const n=wV[r].indexOf(e);if(n===-1)throw new Error(`Invalid layer for getLayerIndex (for layerCount === ${r}): "${e}"`);return n}function Elt(r,e){const n=wV[r][e];if(!n)throw new Error(`Invalid index for indexToLayer (for layerCount === ${r}): "${e}"`);return n}var xlt=class extends fme{constructor(e,t){super([]);Le(this,"obstacles");Le(this,"GRID_STEP",.1);Le(this,"layerCount");this.layerCount=e;const n=_lt(e);this.obstacles=t.flatMap(i=>i.layers.filter(o=>n.includes(o)).map(o=>({...i,left:i.center.x-i.width/2,right:i.center.x+i.width/2,top:i.center.y+i.height/2,bottom:i.center.y-i.height/2,l:vme(e,o)})))}getObstacleAt(e,t,n,i){i??(i=this.GRID_STEP);for(const o of this.obstacles){if(o.l!==n)continue;const a=o.width/2+i,s=o.height/2+i;if(e>=o.center.x-a&&e<=o.center.x+a&&t>=o.center.y-s&&t<=o.center.y+s)return o}return null}isObstacleAt(e,t,n,i){return this.getObstacleAt(e,t,n,i)!==null}getDirectionDistancesToNearestObstacle3d(e,t,n){const{GRID_STEP:i}=this,o={left:1/0,top:1/0,bottom:1/0,right:1/0};for(const a of this.obstacles)if(a.l===n&&a.type==="rect"){const s=a.center.x-a.width/2-i,l=a.center.x+a.width/2+i,c=a.center.y+a.height/2+i,u=a.center.y-a.height/2-i;t>=u&&t<=c&&e>s&&(o.left=Math.min(o.left,e-l)),t>=u&&t<=c&&e<l&&(o.right=Math.min(o.right,s-e)),e>=s&&e<=l&&t<c&&(o.top=Math.min(o.top,u-t)),e>=s&&e<=l&&t>u&&(o.bottom=Math.min(o.bottom,t-c))}return o}getOrthoDirectionCollisionInfo(e,t,{margin:n=0}={}){const{x:i,y:o,l:a}=e,{dx:s,dy:l,dl:c}=t;let u=1/0,A=null;if(c!==0){const d=a+c;return this.isObstacleAt(i,o,d,n)?(u=1,A=this.getObstacleAt(i,o,d,n)):u=1,{dx:s,dy:l,dl:c,wallDistance:u,obstacle:A}}else{for(const d of this.obstacles){if(d.l!==a)continue;const f=d.left-n,p=d.right+n,C=d.top+n,v=d.bottom-n;let _=null;s===1&&l===0?o>v&&o<C&&i<d.left&&(_=d.left-i):s===-1&&l===0?o>v&&o<C&&i>d.right&&(_=i-d.right):s===0&&l===1?i>f&&i<p&&o<d.bottom&&(_=d.bottom-o):s===0&&l===-1&&i>f&&i<p&&o>d.top&&(_=o-d.top),_!==null&&_<u&&(u=_,A=d)}return{dx:s,dy:l,dl:0,wallDistance:u,obstacle:A}}}getObstaclesOverlappingRegion(e){const t=[];for(const n of this.obstacles){if(n.l!==e.l)continue;const{left:i,right:o,top:a,bottom:s}=n;i<=e.maxX&&o>=e.minX&&a>=e.minY&&s<=e.maxY&&t.push(n)}return t}},IM=class extends pme{constructor(e){super(e);Le(this,"MAX_ITERATIONS",500);Le(this,"VIA_COST",4);Le(this,"VIA_DIAMETER",.5);Le(this,"allowLayerChange",!0);Le(this,"layerCount");Le(this,"obstacles");Le(this,"optimizeWithGoalBoxes");Le(this,"connMap");Le(this,"pcbConnMap");Le(this,"GOAL_RUSH_FACTOR",1.1);Le(this,"defaultGoalViaMargin",.5);Le(this,"marginsWithCosts");this.layerCount=e.input.layerCount??2,this.MAX_ITERATIONS=e.MAX_ITERATIONS??this.MAX_ITERATIONS,this.VIA_COST=e.VIA_COST??this.VIA_COST,this.connMap=e.connMap,this.pcbConnMap=e.pcbConnMap??new ame,this.optimizeWithGoalBoxes=e.optimizeWithGoalBoxes??!1,this.obstacles=null,this.marginsWithCosts=e.marginsWithCosts??[{margin:1,enterCost:0,travelCostFactor:1},{margin:this.OBSTACLE_MARGIN,enterCost:10,travelCostFactor:2}]}get largestMargin(){return this.marginsWithCosts[0].margin}preprocessConnectionBeforeSolving(e){return this.optimizeWithGoalBoxes?mme({connection:e,pcbConnMap:this.pcbConnMap}):e}postprocessConnectionSolveResult(e,t){if(!t.solved)return t;if(this.optimizeWithGoalBoxes){const n=t.route.map(i=>({x:i.x,y:i.y,route_type:"wire",layer:i.layer,width:this.input.minTraceWidth}));n[0].start_pcb_port_id=e.pointsToConnect[0].pcb_port_id,n[n.length-1].end_pcb_port_id=e.pointsToConnect[1].pcb_port_id,this.pcbConnMap.addTrace({type:"pcb_trace",pcb_trace_id:`postprocess_trace_${kO(8)}`,route:n})}return t}createObstacleList({dominantLayer:e,connection:t,obstaclesFromTraces:n}){const i=this.connMap?this.connMap.getNetConnectedToId(t.name):t.name;if(!i)throw new Error(`The connection.name "${t.name}" wasn't present in the full connectivity map`);return new xlt(this.layerCount,this.allObstacles.filter(o=>!o.connectedTo.includes(i)).concat(n??[]))}computeG(e,t){let n=e.g+AQ(e,t)*(e.travelMarginCostFactor??1)+(t.enterMarginCost??0);return(t.l??e.l!==-1??-1)&&(n+=this.VIA_COST),n}computeH(e){const t=Math.abs(e.x-this.goalPoint.x),n=Math.abs(e.y-this.goalPoint.y),i=Math.abs(e.l-this.goalPoint.l);return(t+n)**this.GOAL_RUSH_FACTOR+i*this.VIA_COST}getStartNode(e){return{...super.getStartNode(e),l:this.layerToIndex(e.pointsToConnect[0].layer)}}layerToIndex(e){return vme(this.layerCount,e)}indexToLayer(e){return Elt(this.layerCount,e)}getNodeName(e){return`${ume(e,this.GRID_STEP)}-${e.l??0}`}hasSpaceForVia(e,t){return e.every(n=>this.obstacles.getObstaclesOverlappingRegion({minX:t.x-this.VIA_DIAMETER/2-this.OBSTACLE_MARGIN,minY:t.y-this.VIA_DIAMETER/2-this.OBSTACLE_MARGIN,maxX:t.x+this.VIA_DIAMETER/2+this.OBSTACLE_MARGIN,maxY:t.y+this.VIA_DIAMETER/2+this.OBSTACLE_MARGIN,l:n}).length===0)}getNeighborsSurroundingGoal(e){this.obstacles;const t=this.goalPoint,n=[],i=[{dx:1,dy:0,dl:0},{dx:-1,dy:0,dl:0},{dx:0,dy:1,dl:0},{dx:0,dy:-1,dl:0}],o=this.VIA_DIAMETER+this.OBSTACLE_MARGIN+this.defaultGoalViaMargin;for(const a of i){const s={x:e.x+a.dx*o,y:e.y+a.dy*o,l:e.l+a.dl,obstacleHit:null};this.hasSpaceForVia([e.l,t.l],s)&&n.push(s)}return n}getNeighbors(e){const t=this.obstacles,n=this.goalPoint,i=AQ(e,n);if(i<=this.OBSTACLE_MARGIN)return this.getNeighborsSurroundingGoal(e);let o;e.parent?o=yme(e.parent,e):o=yme(e,n);const a=[{dx:0,dy:1,dl:0},{dx:1,dy:0,dl:0},{dx:0,dy:-1,dl:0},{dx:-1,dy:0,dl:0}],s=i>this.VIA_DIAMETER+this.OBSTACLE_MARGIN,l=AQ(e,this.startNode)>this.VIA_DIAMETER+this.OBSTACLE_MARGIN;this.allowLayerChange&&s&&l&&(e.l<this.layerCount-1&&a.push({dx:0,dy:0,dl:1}),e.l>0&&a.push({dx:0,dy:0,dl:-1}));const c=a.filter(A=>{var d;return A.dx===o.dx*-1&&A.dy===o.dy*-1&&A.dl===o.dl*-1?!1:!(A.dx===o.dx&&A.dy===o.dy&&A.dl===o.dl&&((d=e.parent)!=null&&d.obstacleHit))}).map(A=>t.getOrthoDirectionCollisionInfo(e,A,{margin:this.OBSTACLE_MARGIN})).filter(A=>!(A.wallDistance<this.OBSTACLE_MARGIN)),u=[];for(const A of c){const d=A.dx===0&&A.dy===0&&A.dl===1,f=A.dx===0&&A.dy===0&&A.dl===-1;if((d||f)&&![e.l,e.l+A.dl].every(x=>t.getObstaclesOverlappingRegion({minX:e.x-this.VIA_DIAMETER/2-this.OBSTACLE_MARGIN,minY:e.y-this.VIA_DIAMETER/2-this.OBSTACLE_MARGIN,maxX:e.x+this.VIA_DIAMETER/2+this.OBSTACLE_MARGIN,maxY:e.y+this.VIA_DIAMETER/2+this.OBSTACLE_MARGIN,l:x}).length===0))continue;if(d){e.l<this.layerCount-1&&u.push({...A,travelDistance:0,enterMarginCost:0,travelMarginCostFactor:1});continue}if(f){e.l>0&&u.push({...A,travelDistance:0,enterMarginCost:0,travelMarginCostFactor:1});continue}let p=null;e!=null&&e.obstacleHit&&(p=BV({node:e,travelDir:A,wallDir:{...o,wallDistance:this.OBSTACLE_MARGIN},obstacle:e.obstacleHit,obstacles:t,OBSTACLE_MARGIN:this.OBSTACLE_MARGIN,SHOULD_DETECT_CONJOINED_OBSTACLES:!0}));const C=cme(e,n,A),v=(A.dx===0||Math.sign(n.x-e.x)===A.dx)&&(A.dy===0||Math.sign(n.y-e.y)===A.dy);if(C<A.wallDistance&&C>0&&v){const _=e.l===n.l;let x=0;!_&&Math.abs(C-i)<this.GRID_STEP&&(x=this.VIA_DIAMETER+this.OBSTACLE_MARGIN+this.defaultGoalViaMargin),u.push({...A,travelDistance:C-x,enterMarginCost:0,travelMarginCostFactor:1})}else if(p!==null&&p<A.wallDistance){for(const{margin:_,enterCost:x,travelCostFactor:b}of this.marginsWithCosts)p-this.OBSTACLE_MARGIN+_*2<A.wallDistance&&u.push({...A,travelDistance:p-this.OBSTACLE_MARGIN+_,enterMarginCost:x,travelMarginCostFactor:b});if(A.wallDistance===1/0)u.push({...A,travelDistance:C,enterMarginCost:0,travelMarginCostFactor:1});else if(A.wallDistance>this.largestMargin)for(const{margin:_,enterCost:x,travelCostFactor:b}of this.marginsWithCosts)A.wallDistance>this.largestMargin+_&&u.push({...A,travelDistance:A.wallDistance-_,enterMarginCost:x,travelMarginCostFactor:b})}else if(A.wallDistance!==1/0)for(const{margin:_,enterCost:x,travelCostFactor:b}of this.marginsWithCosts)A.wallDistance>_&&u.push({...A,travelDistance:A.wallDistance-_,enterMarginCost:x,travelMarginCostFactor:b})}return u.map(A=>({x:e.x+A.dx*A.travelDistance,y:e.y+A.dy*A.travelDistance,l:e.l+A.dl,obstacleHit:A.obstacle,travelMarginCostFactor:A.travelMarginCostFactor,enterMarginCost:A.enterMarginCost}))}};function QV(r){const e=vlt(r),t=new mlt({input:e});return{solution:t.solveAndMapToTraces(),debugSolutions:t.debugSolutions,debugMessage:t.debugMessage}}var CM=SV,blt=mo(["up","down","left","right"]);mo(["top-to-bottom","left-to-right","bottom-to-top","right-to-left"]);var VS=br(_e().or(sn())),Ime=zt({x:qn,y:qn,z:qn}),Blt=zt({x:dl([sn(),_e()]),y:dl([sn(),_e()]),z:dl([sn(),_e()])}),MV=zt({rotationOffset:sn().or(Blt).optional(),positionOffset:Ime.optional(),size:Ime.optional()}),Slt=MV.extend({stlUrl:_e()}),wlt=MV.extend({objUrl:_e(),mtlUrl:_e().optional()}),Qlt=MV.extend({jscad:jg(GI())}),Mlt=dl([pde(),_e(),Slt,wlt,Qlt]),Dlt=nE(r=>!0),OI=zt({pcbX:qn.optional(),pcbY:qn.optional(),pcbRotation:kC.optional(),layer:mg.optional()}),V8=zt({pcbX:qn.optional(),pcbY:qn.optional(),pcbRotation:kC.optional(),schX:qn.optional(),schY:qn.optional(),schRotation:kC.optional(),layer:mg.optional(),footprint:Dlt.optional()}),Rlt=zt({supplierPartNumbers:jg(AM,br(_e())).optional()}),iE=V8.merge(Rlt).extend({key:GI().optional(),name:_e(),cadModel:Mlt.optional(),children:GI().optional(),symbolName:_e().optional(),doNotPlace:Ni().optional()});qn.or(mo(["2x","3x","4x"]));var K8=zt({pins:br(dl([sn(),_e()])),direction:dl([Nt("top-to-bottom"),Nt("left-to-right"),Nt("bottom-to-top"),Nt("right-to-left")])}),mR=zt({leftSize:sn().optional().describe("@deprecated, use leftPinCount"),topSize:sn().optional().describe("@deprecated, use topPinCount"),rightSize:sn().optional().describe("@deprecated, use rightPinCount"),bottomSize:sn().optional().describe("@deprecated, use bottomPinCount"),leftPinCount:sn().optional(),rightPinCount:sn().optional(),topPinCount:sn().optional(),bottomPinCount:sn().optional(),leftSide:K8.optional(),rightSide:K8.optional(),topSide:K8.optional(),bottomSide:K8.optional()}),Nlt=mR,DV=jg(zt({marginLeft:qn.optional(),marginRight:qn.optional(),marginTop:qn.optional(),marginBottom:qn.optional(),leftMargin:qn.optional(),rightMargin:qn.optional(),topMargin:qn.optional(),bottomMargin:qn.optional()})),RV=zt({x:qn,y:qn}),yR=zt({edit_event_id:_e(),in_progress:Ni().optional(),created_at:sn()}),Tlt=yR.extend({pcb_edit_event_type:Nt("edit_component_location").describe("deprecated"),edit_event_type:Nt("edit_pcb_component_location"),pcb_component_id:_e(),original_center:zt({x:sn(),y:sn()}),new_center:zt({x:sn(),y:sn()})}),Plt=yR.extend({pcb_edit_event_type:Nt("edit_trace_hint").describe("deprecated"),edit_event_type:Nt("edit_pcb_trace_hint").optional(),pcb_port_id:_e(),pcb_trace_hint_id:_e().optional(),route:br(zt({x:sn(),y:sn(),via:Ni().optional()}))}),klt=yR.extend({edit_event_type:Nt("edit_schematic_component_location"),schematic_component_id:_e(),original_center:zt({x:sn(),y:sn()}),new_center:zt({x:sn(),y:sn()})});yR.extend({edit_event_type:Nt("edit_pcb_group_location"),pcb_group_id:_e(),original_center:zt({x:sn(),y:sn()}),new_center:zt({x:sn(),y:sn()})}),yR.extend({edit_event_type:Nt("edit_schematic_group_location"),schematic_group_id:_e(),original_center:zt({x:sn(),y:sn()}),new_center:zt({x:sn(),y:sn()})}),dl([Tlt,Plt,klt]);var Ult=zt({selector:_e(),relative_to:_e().optional().default("group_center").describe("Can be a selector or 'group_center'"),center:Am}),Flt=zt({pcb_port_selector:_e(),offsets:br(nx)}),Llt=zt({selector:_e(),relative_to:_e().optional().default("group_center").describe("Can be a selector or 'group_center'"),center:Am}),Glt=zt({pcb_placements:br(Ult).optional(),manual_trace_hints:br(Flt).optional(),schematic_placements:br(Llt).optional()}),NV=zt({layoutMode:mo(["grid","flex","match-adapt","none"]).optional(),position:mo(["absolute","relative"]).optional(),grid:Ni().optional(),gridCols:sn().or(_e()).optional(),gridRows:sn().or(_e()).optional(),gridTemplateRows:_e().optional(),gridTemplateColumns:_e().optional(),gridTemplate:_e().optional(),gridGap:sn().or(_e()).optional(),flex:Ni().or(_e()).optional(),flexDirection:mo(["row","column"]).optional(),alignItems:mo(["start","center","end","stretch"]).optional(),justifyContent:mo(["start","center","end","stretch"]).optional(),flexRow:Ni().optional(),flexColumn:Ni().optional(),gap:sn().or(_e()).optional(),matchAdapt:Ni().optional()}),Olt=zt({serverUrl:_e().optional(),inputFormat:mo(["simplified","circuit-json"]).optional(),serverMode:mo(["job","solve-endpoint"]).optional(),serverCacheEnabled:Ni().optional(),cache:nE(r=>!0).optional(),groupMode:mo(["sequential-trace","subcircuit"]).optional(),algorithmFn:nE(r=>typeof r=="function"||r===void 0).optional(),local:Ni().optional()}),Cme=dl([Olt,Nt("sequential-trace"),Nt("subcircuit"),Nt("auto"),Nt("auto-local"),Nt("auto-cloud")]),_me=V8.extend({name:_e().optional(),children:GI().optional(),key:GI().optional(),...NV.shape,pcbWidth:In.optional(),pcbHeight:In.optional(),schWidth:In.optional(),schHeight:In.optional(),pcbLayout:NV.optional(),schLayout:NV.optional()}),Eme=nE(r=>"findPart"in r),xme=_me.extend({layout:nE(r=>!0).optional(),manualEdits:Glt.optional(),schAutoLayoutEnabled:Ni().optional(),schTraceAutoLabelEnabled:Ni().optional(),routingDisabled:Ni().optional(),defaultTraceWidth:In.optional(),minTraceWidth:In.optional(),partsEngine:Eme.optional(),pcbRouteCache:nE(r=>!0).optional(),autorouter:Cme.optional()}),zlt=xme.extend({subcircuit:Nt(!0)}),bme=zB("subcircuit",[_me.extend({subcircuit:Nt(!1).optional()}),zlt]),TV=xme.extend({width:qn.optional(),height:qn.optional(),outline:br(RV).optional(),outlineOffsetX:qn.optional(),outlineOffsetY:qn.optional(),material:mo(["fr4","fr1"]).default("fr4")}),Hlt=_e().or(br(_e()).readonly()).or(br(_e())),Ylt=nE().pipe(jg(_e(),Hlt)),Vlt=jg(_e(),_e().or(br(_e()).readonly()).or(br(_e()))),Klt=zt({manufacturerPartNumber:_e().optional(),supplierPartNumber:jg(AM,br(_e())).optional()}),PV=iE.extend({manufacturerPartNumber:_e().optional(),pinLabels:Vlt.optional(),internallyConnectedPins:br(br(_e())).optional(),externallyConnectedPins:br(br(_e())).optional(),schPinArrangement:mR.optional(),schPortArrangement:mR.optional(),pinCompatibleVariants:br(Klt).optional(),schPinStyle:DV.optional(),schPinSpacing:qn.optional(),schWidth:qn.optional(),schHeight:qn.optional(),noSchematicRepresentation:Ni().optional(),connections:Ylt.optional()}),Bme=iE.extend({manufacturerPartNumber:_e().optional(),pinLabels:jg(sn().or(_e()),_e().or(br(_e()))).optional(),schPinStyle:DV.optional(),schPinSpacing:qn.optional(),schWidth:qn.optional(),schHeight:qn.optional(),schDirection:mo(["left","right"]).optional(),schPortArrangement:mR.optional(),pinCount:dl([Nt(2),Nt(3)]).optional(),internallyConnectedPins:br(br(_e())).optional()});iE.extend({manufacturerPartNumber:_e().optional(),pinLabels:jg(sn().or(_e()),_e().or(br(_e()))).optional(),schPinStyle:DV.optional(),schPinSpacing:qn.optional(),schWidth:qn.optional(),schHeight:qn.optional(),schDirection:mo(["left","right"]).optional(),schPortArrangement:mR.optional(),internallyConnectedPins:br(br(_e())).optional(),standard:mo(["usb_c","m2"]).optional()});var jlt=iE.extend({currentRating:dl([sn(),_e()]),voltageRating:dl([sn(),_e()]).optional(),schShowRatings:Ni().optional(),connections:jg(_e(),dl([_e(),br(_e()).readonly(),br(_e())])).optional()}),j8=nE().transform(r=>{if(r!==void 0)return qn.parse(r)}),Sme=dl([OI.omit({pcbRotation:!0,layer:!0}).extend({name:_e().optional(),shape:Nt("circle"),holeDiameter:qn,outerDiameter:qn,portHints:VS.optional()}),OI.omit({pcbRotation:!0,layer:!0}).extend({name:_e().optional(),shape:Nt("oval"),outerWidth:qn,outerHeight:qn,holeWidth:j8,holeHeight:j8,innerWidth:qn.optional().describe("DEPRECATED use holeWidth"),innerHeight:qn.optional().describe("DEPRECATED use holeHeight"),portHints:VS.optional()}),OI.omit({pcbRotation:!0,layer:!0}).extend({name:_e().optional(),shape:Nt("pill"),outerWidth:qn,outerHeight:qn,holeWidth:j8,holeHeight:j8,innerWidth:qn.optional().describe("DEPRECATED use holeWidth"),innerHeight:qn.optional().describe("DEPRECATED use holeHeight"),portHints:VS.optional()}),OI.omit({pcbRotation:!0,layer:!0}).extend({name:_e().optional(),holeDiameter:qn,rectPadWidth:qn,rectPadHeight:qn,holeShape:Nt("circle").optional(),padShape:Nt("rect").optional(),shape:Nt("circular_hole_with_rect_pad").optional(),portHints:VS.optional()}).refine(r=>r.shape==="circular_hole_with_rect_pad"?r.holeDiameter&&r.rectPadWidth&&r.rectPadHeight:!0,{message:"Missing required fields for circular_hole_with_rect_pad"}),OI.omit({pcbRotation:!0,layer:!0}).extend({name:_e().optional(),shape:Nt("pill_hole_with_rect_pad"),holeShape:Nt("pill"),padShape:Nt("rect"),holeWidth:qn,holeHeight:qn,rectPadWidth:qn,rectPadHeight:qn,portHints:VS.optional()})]).refine(r=>("innerWidth"in r&&r.innerWidth!==void 0&&(r.holeWidth??(r.holeWidth=r.innerWidth)),"innerHeight"in r&&r.innerHeight!==void 0&&(r.holeHeight??(r.holeHeight=r.innerHeight)),r)),Jlt=_e().or(br(_e()).readonly()).or(br(_e())),wme=r=>jg(mo(r),Jlt),Wlt=["pin1","pin2","pos","neg"],Qme=iE.extend({resistance:V2,pullupFor:_e().optional(),pullupTo:_e().optional(),pulldownFor:_e().optional(),pulldownTo:_e().optional(),connections:wme(Wlt).optional()}),Mme=iE.extend({maxResistance:V2,pinVariant:mo(["two_pin","three_pin"]).optional()}),Dme=iE.extend({frequency:uM,loadCapacitance:US,pinVariant:mo(["two_pin","four_pin"]).optional()}),Rme=iE.extend({frequency:uM,loadCapacitance:US,pinVariant:mo(["no_ground","ground_pin","two_ground_pins"]).optional()});TV.extend({leftPinCount:sn().optional(),rightPinCount:sn().optional(),topPinCount:sn().optional(),bottomPinCount:sn().optional(),leftPins:br(_e()).optional(),rightPins:br(_e()).optional(),topPins:br(_e()).optional(),bottomPins:br(_e()).optional(),pinPitch:qn.optional(),innerHoles:Ni().optional()});var qlt=["pin1","pin2","pos","neg","anode","cathode"],Nme=iE.extend({capacitance:US,maxVoltageRating:K2.optional(),schShowRatings:Ni().optional().default(!1),polarized:Ni().optional().default(!1),decouplingFor:_e().optional(),decouplingTo:_e().optional(),bypassFor:_e().optional(),bypassTo:_e().optional(),maxDecouplingTraceLength:sn().optional(),connections:wme(qlt).optional()});zt({name:_e()}),zt({name:_e().optional(),pcbOnly:Ni().optional(),schOnly:Ni().optional()});var Zlt=zt({pcb:Nt(!0).optional(),xDist:qn,left:_e(),right:_e(),edgeToEdge:Nt(!0).optional(),centerToCenter:Nt(!0).optional()}),Xlt=zt({pcb:Nt(!0).optional(),yDist:qn,top:_e(),bottom:_e(),edgeToEdge:Nt(!0).optional(),centerToCenter:Nt(!0).optional()}),$lt=zt({pcb:Nt(!0).optional(),sameY:Nt(!0).optional(),for:br(_e())}),ect=zt({pcb:Nt(!0).optional(),sameX:Nt(!0).optional(),for:br(_e())}),Tme=dl([Zlt,Xlt,$lt,ect]),tct=OI.omit({layer:!0,pcbRotation:!0}).extend({name:_e().optional(),shape:Nt("rect"),width:qn,height:qn}),nct=OI.omit({layer:!0,pcbRotation:!0}).extend({name:_e().optional(),shape:Nt("circle"),radius:qn}),rct=OI.omit({layer:!0,pcbRotation:!0}).extend({name:_e().optional(),shape:Nt("polygon"),points:br(RV)}),Pme=zB("shape",[tct,nct,rct]),ict=OI.omit({pcbRotation:!0}).extend({shape:Nt("rect"),width:qn,height:qn,portHints:VS.optional()}),oct=OI.omit({pcbRotation:!0}).extend({shape:Nt("rotated_rect"),width:qn,height:qn,ccwRotation:sn(),portHints:VS.optional()}),act=OI.omit({pcbRotation:!0}).extend({shape:Nt("circle"),radius:qn,portHints:VS.optional()}),sct=OI.omit({pcbRotation:!0}).extend({shape:Nt("pill"),width:qn,height:qn,radius:qn,portHints:VS.optional()}),kme=dl([act,ict,oct,sct]),lct=OI.omit({pcbRotation:!0}).extend({shape:Nt("rect"),width:qn,height:qn}),cct=OI.omit({pcbRotation:!0}).extend({shape:Nt("circle"),radius:qn});dl([cct,lct]);var Ume=OI.omit({pcbRotation:!0}).extend({name:_e().optional(),diameter:qn.optional(),radius:qn.optional()}).transform(r=>({...r,diameter:r.diameter??2*r.radius,radius:r.radius??r.diameter/2})),kV=dl([_e(),nE(r=>!!r.getPortSelector)]),Fme=zt({key:_e().optional(),thickness:qn.optional(),schematicRouteHints:br(RV).optional(),pcbRouteHints:br(nx).optional(),schDisplayLabel:_e().optional(),maxLength:qn.optional()}),Lme=dl([Fme.extend({path:br(kV)}),Fme.extend({from:kV,to:kV})]),Gme=zt({originalLayer:mg.default("top").optional()}),uct=sn().or(_e().endsWith("mAh")).transform(r=>{if(typeof r=="string"){const e=r.replace("mAh",""),t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error("Invalid capacity");return t}return r}).describe("Battery capacity in mAh"),Ome=iE.extend({capacity:uct.optional()}),zme=iE.extend({pinCount:sn(),pitch:qn.optional(),schFacingDirection:mo(["up","down","left","right"]).optional(),gender:mo(["male","female"]).optional().default("male"),showSilkscreenPinLabels:Ni().optional(),doubleRow:Ni().optional(),holeDiameter:qn.optional(),platedDiameter:qn.optional(),pinLabels:br(_e()).optional(),facingDirection:mo(["left","right"]).optional(),schPinArrangement:Nlt.optional()}),Hme=zt({net:_e().optional(),schX:qn.optional(),schY:qn.optional(),schRotation:kC.optional(),anchorSide:mo(["left","up","right","down"]).optional()}),Yme=PV.extend({}),Vme=iE.extend({type:mo(["npn","pnp","bjt","jfet","mosfet"])}),Kme=iE.extend({channelType:mo(["n","p"]),mosfetMode:mo(["enhancement","depletion"])}),jme=iE.extend({inductance:WT}),Act=mo(["anode","cathode","pin1","pin2","pos","neg"]),dct=_e().or(br(_e()).readonly()).or(br(_e())),fct=jg(Act,dct),hct=mo(["standard","schottky","zener","photo","tvs"]),Jme=iE.extend({connections:fct.optional(),variant:hct.optional().default("standard"),standard:Ni().optional(),schottky:Ni().optional(),zener:Ni().optional(),photo:Ni().optional(),tvs:Ni().optional()}).superRefine((r,e)=>{if([r.standard,r.schottky,r.zener,r.photo,r.tvs].filter(Boolean).length>1)return e.addIssue({code:ds.custom,message:"Exactly one diode variant must be enabled",path:[]}),Of}).transform(r=>{const e={...r,standard:!1,schottky:!1,zener:!1,photo:!1,tvs:!1};if(r.standard)e.standard=!0;else if(r.schottky)e.schottky=!0;else if(r.zener)e.zener=!0;else if(r.photo)e.photo=!0;else if(r.tvs)e.tvs=!0;else switch(r.variant){case"standard":e.standard=!0;break;case"schottky":e.schottky=!0;break;case"zener":e.zener=!0;break;case"photo":e.photo=!0;break;case"tvs":e.tvs=!0;break;default:e.standard=!0}return e}),Wme=iE.extend({color:_e().optional(),wavelength:_e().optional(),schDisplayValue:_e().optional()}),qme=iE.extend({type:mo(["spst","spdt","dpst","dpdt"]).optional(),isNormallyClosed:Ni().optional().default(!1),spst:Ni().optional(),spdt:Ni().optional(),dpst:Ni().optional(),dpdt:Ni().optional()}).transform(r=>{const e={...r};switch(e.dpdt?e.type="dpdt":e.spst?e.type="spst":e.spdt?e.type="spdt":e.dpst&&(e.type="dpst"),e.type){case"spdt":e.spdt=!0;break;case"spst":e.spst=!0;break;case"dpst":e.dpst=!0;break;case"dpdt":e.dpdt=!0;break}return e}),Zme=OI.extend({text:_e(),anchorAlignment:mo(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),font:mo(["tscircuit2024"]).optional(),fontSize:In.optional(),color:_e().optional()}),Xme=OI.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({route:br(nx),strokeWidth:In.optional(),color:_e().optional()});zt({layer:_e().optional(),thickness:qn.optional(),route:br(nx)});var $me=V8.extend({fromLayer:mg,toLayer:mg,holeDiameter:qn,outerDiameter:qn}),eye=dl([OI.omit({pcbRotation:!0}).extend({shape:Nt("circle"),radius:qn}),OI.extend({shape:Nt("rect"),width:qn,height:qn})]),tye=iE.extend({voltage:K2}),UV=mo(["top_left","top_center","top_right","center_left","center","center_right","bottom_left","bottom_center","bottom_right"]),nye=zt({schX:qn,schY:qn,width:qn.optional(),height:qn.optional(),overlay:br(_e()).optional(),padding:qn.optional(),paddingLeft:qn.optional(),paddingRight:qn.optional(),paddingTop:qn.optional(),paddingBottom:qn.optional(),title:_e().optional(),titlePosition:UV.default("top_left"),titleColor:_e().optional(),titleFontSize:qn.optional(),titleInside:Ni().default(!1),strokeStyle:mo(["solid","dashed"]).default("solid")}).refine(r=>r.width!==void 0&&r.height!==void 0||Array.isArray(r.overlay)&&r.overlay.length>0,{message:"Must provide either both `width` and `height`, or a non-empty `overlay` array."}).refine(r=>!(r.width!==void 0&&r.height!==void 0&&Array.isArray(r.overlay)&&r.overlay.length>0),{message:"Cannot provide both `width`/`height` and `overlay` at the same time."});zt({x1:qn,y1:qn,x2:qn,y2:qn});var pct=mo(["center","left","right","top","bottom"]),rye=zt({schX:qn,schY:qn,text:_e(),fontSize:sn().default(1),anchor:dl([pct.describe("legacy"),UV]).default("center"),color:_e().default("#000000"),schRotation:kC.default(0)});zt({points:br(Am),isFilled:Ni().optional().default(!1),fillColor:mo(["red","blue"]).optional()});var iye=OI.extend({text:_e(),anchorAlignment:UV.default("center"),font:mo(["tscircuit2024"]).optional(),fontSize:In.optional()}),oye=OI.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({route:br(nx),strokeWidth:In.optional()}),aye=OI.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({strokeWidth:qn,x1:qn,y1:qn,x2:qn,y2:qn}),sye=OI.omit({pcbRotation:!0}).extend({filled:Ni().default(!0).optional(),stroke:mo(["dashed","solid","none"]).optional(),strokeWidth:qn.optional(),width:qn,height:qn}),lye=OI.omit({pcbRotation:!0}).extend({isFilled:Ni().optional(),isOutline:Ni().optional(),strokeWidth:qn.optional(),radius:qn}),cye=zt({x:qn,y:qn,via:Ni().optional(),toLayer:mg.optional()}),uye=zt({for:_e().optional().describe("Selector for the port you're targeting, not required if you're inside a trace"),order:sn().optional(),offset:nx.or(cye).optional(),offsets:br(nx).or(br(cye)).optional(),traceWidth:sn().optional()});V8.extend({name:_e(),pinNumber:sn().optional(),aliases:br(_e()).optional(),direction:blt});var gct=br(GI()).describe("Circuit JSON"),mct=gde().args(_e()).returns(mde(zt({footprintCircuitJson:br(GI())}))).describe("A function that takes a path and returns Circuit JSON");zt({partsEngine:Eme.optional(),autorouter:Cme.optional(),registryApiUrl:_e().optional(),cloudAutorouterUrl:_e().optional(),localCacheEngine:GI().optional(),pcbDisabled:Ni().optional(),schematicDisabled:Ni().optional(),partsEngineDisabled:Ni().optional(),footprintLibraryMap:jg(_e(),jg(_e(),dl([gct,mct]))).optional()});function _M(){return new FV}class FV{constructor(){Le(this,"index",{});Le(this,"array",[])}size(){return this.array.length}empty(){return this.array.length===0}itemAt(e){return this.array[e]}contains(e){return this.index[e.id()]!==void 0}find(e){const t=this.index[e.id()];return t===void 0?void 0:this.array[t]}setDefault(e,t){const n=this.index[e.id()];if(n===void 0){const i=new J8(e,t());return this.index[e.id()]=this.array.length,this.array.push(i),i}else return this.array[n]}insert(e,t){const n=new J8(e,t),i=this.index[e.id()];return i===void 0?(this.index[e.id()]=this.array.length,this.array.push(n)):this.array[i]=n,n}erase(e){const t=this.index[e.id()];if(t===void 0)return;this.index[e.id()]=void 0;const n=this.array[t],i=this.array.pop();return n!==i&&(this.array[t]=i,this.index[i.first.id()]=t),n}copy(){const e=new FV;for(let t=0;t<this.array.length;t++){const n=this.array[t].copy();e.array[t]=n,e.index[n.first.id()]=t}return e}}class J8{constructor(e,t){Le(this,"first");Le(this,"second");this.first=e,this.second=t}copy(){return new J8(this.first,this.second)}}class vR{constructor(e=""){Le(this,"_name");Le(this,"_value",0);Le(this,"_context",null);Le(this,"_id",yct++);this._name=e}id(){return this._id}name(){return this._name}setName(e){this._name=e}context(){return this._context}setContext(e){this._context=e}value(){return this._value}setValue(e){this._value=e}plus(e){return new Um(this,e)}minus(e){return new Um(this,typeof e=="number"?-e:[-1,e])}multiply(e){return new Um([e,this])}divide(e){return new Um([1/e,this])}toJSON(){return{name:this._name,value:this._value}}toString(){return this._context+"["+this._name+":"+this._value+"]"}}let yct=0;class Um{constructor(){Le(this,"_terms");Le(this,"_constant");let e=vct(arguments);this._terms=e.terms,this._constant=e.constant}terms(){return this._terms}constant(){return this._constant}value(){let e=this._constant;for(let t=0,n=this._terms.size();t<n;t++){let i=this._terms.itemAt(t);e+=i.first.value()*i.second}return e}plus(e){return new Um(this,e)}minus(e){return new Um(this,typeof e=="number"?-e:[-1,e])}multiply(e){return new Um([e,this])}divide(e){return new Um([1/e,this])}isConstant(){return this._terms.size()==0}toString(){let e=this._terms.array.map(function(t){return t.second+"*"+t.first.toString()}).join(" + ");return!this.isConstant()&&this._constant!==0&&(e+=" + "),e+=this._constant,e}}function vct(r){let e=0,t=()=>0,n=_M();for(let i=0,o=r.length;i<o;++i){let a=r[i];if(typeof a=="number")e+=a;else if(a instanceof vR)n.setDefault(a,t).second+=1;else if(a instanceof Um){e+=a.constant();let s=a.terms();for(let l=0,c=s.size();l<c;l++){let u=s.itemAt(l);n.setDefault(u.first,t).second+=u.second}}else if(a instanceof Array){if(a.length!==2)throw new Error("array must have length 2");let s=a[0],l=a[1];if(typeof s!="number")throw new Error("array item 0 must be a number");if(l instanceof vR)n.setDefault(l,t).second+=s;else if(l instanceof Um){e+=l.constant()*s;let c=l.terms();for(let u=0,A=c.size();u<A;u++){let d=c.itemAt(u);n.setDefault(d.first,t).second+=d.second*s}}else throw new Error("array item 1 must be a variable or expression")}else throw new Error("invalid Expression argument: "+a)}return{terms:n,constant:e}}const DB=class DB{static create(e,t,n,i=1){let o=0;return o+=Math.max(0,Math.min(1e3,e*i))*1e6,o+=Math.max(0,Math.min(1e3,t*i))*1e3,o+=Math.max(0,Math.min(1e3,n*i)),o}static clip(e){return Math.max(0,Math.min(DB.required,e))}};Le(DB,"required",DB.create(1e3,1e3,1e3)),Le(DB,"strong",DB.create(1,0,0)),Le(DB,"medium",DB.create(0,1,0)),Le(DB,"weak",DB.create(0,0,1));let uy=DB;var _I;(function(r){r[r.Le=0]="Le",r[r.Ge=1]="Ge",r[r.Eq=2]="Eq"})(_I||(_I={}));class L1{constructor(e,t,n,i=uy.required){Le(this,"_expression");Le(this,"_operator");Le(this,"_strength");Le(this,"_id",Ict++);this._operator=t,this._strength=uy.clip(i),n===void 0&&e instanceof Um?this._expression=e:this._expression=e.minus(n)}id(){return this._id}expression(){return this._expression}op(){return this._operator}strength(){return this._strength}toString(){return this._expression.toString()+" "+["<=",">=","="][this._operator]+" 0 ("+this._strength.toString()+")"}}let Ict=0;class LV{constructor(){Le(this,"maxIterations",1e3);Le(this,"_cnMap",Cct());Le(this,"_rowMap",_ct());Le(this,"_varMap",Ect());Le(this,"_editMap",xct());Le(this,"_infeasibleRows",[]);Le(this,"_objective",new q8);Le(this,"_artificial",null);Le(this,"_idTick",0)}createConstraint(e,t,n,i=uy.required){let o=new L1(e,t,n,i);return this.addConstraint(o),o}addConstraint(e){if(this._cnMap.find(e)!==void 0)throw new Error("duplicate constraint");let n=this._createRow(e),i=n.row,o=n.tag,a=this._chooseSubject(i,o);if(a.type()===fm.Invalid&&i.allDummies())if(W8(i.constant()))a=o.marker;else throw new Error("unsatisfiable constraint");if(a.type()===fm.Invalid){if(!this._addWithArtificialVariable(i))throw new Error("unsatisfiable constraint")}else i.solveFor(a),this._substitute(a,i),this._rowMap.insert(a,i);this._cnMap.insert(e,o),this._optimize(this._objective)}removeConstraint(e){let t=this._cnMap.erase(e);if(t===void 0)throw new Error("unknown constraint");this._removeConstraintEffects(e,t.second);let n=t.second.marker,i=this._rowMap.erase(n);if(i===void 0){let o=this._getMarkerLeavingSymbol(n);if(o.type()===fm.Invalid)throw new Error("failed to find leaving row");i=this._rowMap.erase(o),i.second.solveForEx(o,n),this._substitute(n,i.second)}this._optimize(this._objective)}hasConstraint(e){return this._cnMap.contains(e)}getConstraints(){return this._cnMap.array.map(({first:e})=>e)}addEditVariable(e,t){if(this._editMap.find(e)!==void 0)throw new Error("duplicate edit variable");if(t=uy.clip(t),t===uy.required)throw new Error("bad required strength");let i=new Um(e),o=new L1(i,_I.Eq,void 0,t);this.addConstraint(o);let s={tag:this._cnMap.find(o).second,constraint:o,constant:0};this._editMap.insert(e,s)}removeEditVariable(e){let t=this._editMap.erase(e);if(t===void 0)throw new Error("unknown edit variable");this.removeConstraint(t.second.constraint)}hasEditVariable(e){return this._editMap.contains(e)}suggestValue(e,t){let n=this._editMap.find(e);if(n===void 0)throw new Error("unknown edit variable");let i=this._rowMap,o=n.second,a=t-o.constant;o.constant=t;let s=o.tag.marker,l=i.find(s);if(l!==void 0){l.second.add(-a)<0&&this._infeasibleRows.push(s),this._dualOptimize();return}let c=o.tag.other;if(l=i.find(c),l!==void 0){l.second.add(a)<0&&this._infeasibleRows.push(c),this._dualOptimize();return}for(let u=0,A=i.size();u<A;++u){let d=i.itemAt(u),f=d.second,p=f.coefficientFor(s);p!==0&&f.add(a*p)<0&&d.first.type()!==fm.External&&this._infeasibleRows.push(d.first)}this._dualOptimize()}updateVariables(){let e=this._varMap,t=this._rowMap;for(let n=0,i=e.size();n<i;++n){let o=e.itemAt(n),a=t.find(o.second);a!==void 0?o.first.setValue(a.second.constant()):o.first.setValue(0)}}_getVarSymbol(e){let t=()=>this._makeSymbol(fm.External);return this._varMap.setDefault(e,t).second}_createRow(e){let t=e.expression(),n=new q8(t.constant()),i=t.terms();for(let l=0,c=i.size();l<c;++l){let u=i.itemAt(l);if(!W8(u.second)){let A=this._getVarSymbol(u.first),d=this._rowMap.find(A);d!==void 0?n.insertRow(d.second,u.second):n.insertSymbol(A,u.second)}}let o=this._objective,a=e.strength(),s={marker:ew,other:ew};switch(e.op()){case _I.Le:case _I.Ge:{let l=e.op()===_I.Le?1:-1,c=this._makeSymbol(fm.Slack);if(s.marker=c,n.insertSymbol(c,l),a<uy.required){let u=this._makeSymbol(fm.Error);s.other=u,n.insertSymbol(u,-l),o.insertSymbol(u,a)}break}case _I.Eq:{if(a<uy.required){let l=this._makeSymbol(fm.Error),c=this._makeSymbol(fm.Error);s.marker=l,s.other=c,n.insertSymbol(l,-1),n.insertSymbol(c,1),o.insertSymbol(l,a),o.insertSymbol(c,a)}else{let l=this._makeSymbol(fm.Dummy);s.marker=l,n.insertSymbol(l)}break}}return n.constant()<0&&n.reverseSign(),{row:n,tag:s}}_chooseSubject(e,t){let n=e.cells();for(let o=0,a=n.size();o<a;++o){let s=n.itemAt(o);if(s.first.type()===fm.External)return s.first}let i=t.marker.type();return(i===fm.Slack||i===fm.Error)&&e.coefficientFor(t.marker)<0?t.marker:(i=t.other.type(),(i===fm.Slack||i===fm.Error)&&e.coefficientFor(t.other)<0?t.other:ew)}_addWithArtificialVariable(e){let t=this._makeSymbol(fm.Slack);this._rowMap.insert(t,e.copy()),this._artificial=e.copy(),this._optimize(this._artificial);let n=W8(this._artificial.constant());this._artificial=null;let i=this._rowMap.erase(t);if(i!==void 0){let a=i.second;if(a.isConstant())return n;let s=this._anyPivotableSymbol(a);if(s.type()===fm.Invalid)return!1;a.solveForEx(t,s),this._substitute(s,a),this._rowMap.insert(s,a)}let o=this._rowMap;for(let a=0,s=o.size();a<s;++a)o.itemAt(a).second.removeSymbol(t);return this._objective.removeSymbol(t),n}_substitute(e,t){let n=this._rowMap;for(let i=0,o=n.size();i<o;++i){let a=n.itemAt(i);a.second.substitute(e,t),a.second.constant()<0&&a.first.type()!==fm.External&&this._infeasibleRows.push(a.first)}this._objective.substitute(e,t),this._artificial&&this._artificial.substitute(e,t)}_optimize(e){let t=0;for(;t<this.maxIterations;){let n=this._getEnteringSymbol(e);if(n.type()===fm.Invalid)return;let i=this._getLeavingSymbol(n);if(i.type()===fm.Invalid)throw new Error("the objective is unbounded");let o=this._rowMap.erase(i).second;o.solveForEx(i,n),this._substitute(n,o),this._rowMap.insert(n,o),t++}throw new Error("solver iterations exceeded")}_dualOptimize(){let e=this._rowMap,t=this._infeasibleRows;for(;t.length!==0;){let n=t.pop(),i=e.find(n);if(i!==void 0&&i.second.constant()<0){let o=this._getDualEnteringSymbol(i.second);if(o.type()===fm.Invalid)throw new Error("dual optimize failed");let a=i.second;e.erase(n),a.solveForEx(n,o),this._substitute(o,a),e.insert(o,a)}}}_getEnteringSymbol(e){let t=e.cells();for(let n=0,i=t.size();n<i;++n){let o=t.itemAt(n),a=o.first;if(o.second<0&&a.type()!==fm.Dummy)return a}return ew}_getDualEnteringSymbol(e){let t=Number.MAX_VALUE,n=ew,i=e.cells();for(let o=0,a=i.size();o<a;++o){let s=i.itemAt(o),l=s.first,c=s.second;if(c>0&&l.type()!==fm.Dummy){let A=this._objective.coefficientFor(l)/c;A<t&&(t=A,n=l)}}return n}_getLeavingSymbol(e){let t=Number.MAX_VALUE,n=ew,i=this._rowMap;for(let o=0,a=i.size();o<a;++o){let s=i.itemAt(o),l=s.first;if(l.type()!==fm.External){let c=s.second,u=c.coefficientFor(e);if(u<0){let A=-c.constant()/u;A<t&&(t=A,n=l)}}}return n}_getMarkerLeavingSymbol(e){let t=Number.MAX_VALUE,n=t,i=t,o=ew,a=o,s=o,l=o,c=this._rowMap;for(let u=0,A=c.size();u<A;++u){let d=c.itemAt(u),f=d.second,p=f.coefficientFor(e);if(p===0)continue;let C=d.first;if(C.type()===fm.External)l=C;else if(p<0){let v=-f.constant()/p;v<n&&(n=v,a=C)}else{let v=f.constant()/p;v<i&&(i=v,s=C)}}return a!==o?a:s!==o?s:l}_removeConstraintEffects(e,t){t.marker.type()===fm.Error&&this._removeMarkerEffects(t.marker,e.strength()),t.other.type()===fm.Error&&this._removeMarkerEffects(t.other,e.strength())}_removeMarkerEffects(e,t){let n=this._rowMap.find(e);n!==void 0?this._objective.insertRow(n.second,-t):this._objective.insertSymbol(e,-t)}_anyPivotableSymbol(e){let t=e.cells();for(let n=0,i=t.size();n<i;++n){let o=t.itemAt(n),a=o.first.type();if(a===fm.Slack||a===fm.Error)return o.first}return ew}_makeSymbol(e){return new Aye(e,this._idTick++)}}function W8(r){let e=1e-8;return r<0?-r<e:r<e}function Cct(){return _M()}function _ct(){return _M()}function Ect(){return _M()}function xct(){return _M()}var fm;(function(r){r[r.Invalid=0]="Invalid",r[r.External=1]="External",r[r.Slack=2]="Slack",r[r.Error=3]="Error",r[r.Dummy=4]="Dummy"})(fm||(fm={}));let Aye=class{constructor(e,t){Le(this,"_id");Le(this,"_type");this._id=t,this._type=e}id(){return this._id}type(){return this._type}},ew=new Aye(fm.Invalid,-1);class q8{constructor(e=0){Le(this,"_cellMap",_M());Le(this,"_constant");this._constant=e}cells(){return this._cellMap}constant(){return this._constant}isConstant(){return this._cellMap.empty()}allDummies(){let e=this._cellMap;for(let t=0,n=e.size();t<n;++t)if(e.itemAt(t).first.type()!==fm.Dummy)return!1;return!0}copy(){let e=new q8(this._constant);return e._cellMap=this._cellMap.copy(),e}add(e){return this._constant+=e}insertSymbol(e,t=1){let n=this._cellMap.setDefault(e,()=>0);W8(n.second+=t)&&this._cellMap.erase(e)}insertRow(e,t=1){this._constant+=e._constant*t;let n=e._cellMap;for(let i=0,o=n.size();i<o;++i){let a=n.itemAt(i);this.insertSymbol(a.first,a.second*t)}}removeSymbol(e){this._cellMap.erase(e)}reverseSign(){this._constant=-this._constant;let e=this._cellMap;for(let t=0,n=e.size();t<n;++t){let i=e.itemAt(t);i.second=-i.second}}solveFor(e){let t=this._cellMap,i=-1/t.erase(e).second;this._constant*=i;for(let o=0,a=t.size();o<a;++o)t.itemAt(o).second*=i}solveForEx(e,t){this.insertSymbol(e,-1),this.solveFor(t)}coefficientFor(e){let t=this._cellMap.find(e);return t!==void 0?t.second:0}substitute(e,t){let n=this._cellMap.erase(e);n!==void 0&&this.insertRow(t,n.second)}}function EM([r,e],[t,n],{lineThickness:i=0}={}){return i===0?fQ(r,e,t,n):bct(r,e,t,n)<=i}function fQ(r,e,t,n){const i=Z8(r,e,t),o=Z8(r,e,n),a=Z8(t,n,r),s=Z8(t,n,e);return!!(i!==o&&a!==s||i===0&&X8(r,t,e)||o===0&&X8(r,n,e)||a===0&&X8(t,r,n)||s===0&&X8(t,e,n))}function Z8(r,e,t){const n=(e.y-r.y)*(t.x-e.x)-(e.x-r.x)*(t.y-e.y);return n===0?0:n>0?1:2}function X8(r,e,t){return e.x<=Math.max(r.x,t.x)&&e.x>=Math.min(r.x,t.x)&&e.y<=Math.max(r.y,t.y)&&e.y>=Math.min(r.y,t.y)}function bct(r,e,t,n){if(r.x===e.x&&r.y===e.y)return bE(r,t,n);if(t.x===n.x&&t.y===n.y)return bE(t,r,e);if(fQ(r,e,t,n))return 0;const i=[bE(r,t,n),bE(e,t,n),bE(t,r,e),bE(n,r,e)];return Math.min(...i)}function bE(r,e,t){const n=(t.x-e.x)**2+(t.y-e.y)**2;if(n===0)return xx(r,e);let i=((r.x-e.x)*(t.x-e.x)+(r.y-e.y)*(t.y-e.y))/n;i=Math.max(0,Math.min(1,i));const o={x:e.x+i*(t.x-e.x),y:e.y+i*(t.y-e.y)};return xx(r,o)}function xx(r,e){const t=r.x-e.x,n=r.y-e.y;return Math.sqrt(t*t+n*n)}function Bct(r,e,t,n){if(r.x===e.x&&r.y===e.y)return bE(r,t,n);if(t.x===n.x&&t.y===n.y)return bE(t,r,e);if(fQ(r,e,t,n))return 0;const i=[bE(r,t,n),bE(e,t,n),bE(t,r,e),bE(n,r,e)];return Math.min(...i)}function Sct(r,e,t){const n={x:t.minX,y:t.minY},i={x:t.maxX,y:t.minY},o={x:t.minX,y:t.maxY},a={x:t.maxX,y:t.maxY};if(fQ(r,e,n,i)||fQ(r,e,i,a)||fQ(r,e,a,o)||fQ(r,e,o,n)||r.x>=t.minX&&r.x<=t.maxX&&r.y>=t.minY&&r.y<=t.maxY&&e.x>=t.minX&&e.x<=t.maxX&&e.y>=t.minY&&e.y<=t.maxY)return 0;const s=[bE(n,r,e),bE(i,r,e),bE(o,r,e),bE(a,r,e)];if(r.x>=t.minX&&r.x<=t.maxX&&r.y>=t.minY&&r.y<=t.maxY||e.x>=t.minX&&e.x<=t.maxX&&e.y>=t.minY&&e.y<=t.maxY)return 0;if(r.x<t.minX||r.x>t.maxX||r.y<t.minY||r.y>t.maxY){const l=$2(r.x,t.minX,t.maxX),c=$2(r.y,t.minY,t.maxY);s.push(xx(r,{x:l,y:c}))}if(e.x<t.minX||e.x>t.maxX||e.y<t.minY||e.y>t.maxY){const l=$2(e.x,t.minX,t.maxX),c=$2(e.y,t.minY,t.maxY);s.push(xx(e,{x:l,y:c}))}return Math.min(...s)}function wct(r,e,t){const n={x:t.x,y:t.y};if(r.x===e.x&&r.y===e.y)return Math.max(0,xx(r,n)-t.radius);const i={x:e.x-r.x,y:e.y-r.y},o={x:n.x-r.x,y:n.y-r.y},a=i.x*i.x+i.y*i.y,s=Math.max(0,Math.min(1,(i.x*o.x+i.y*o.y)/a)),l={x:r.x+s*i.x,y:r.y+s*i.y},c=xx(l,n);return Math.max(0,c-t.radius)}var GV=(r,e)=>{const t={x:e.x-r.x,y:e.y-r.y},n=Math.sqrt(t.x**2+t.y**2);return{x:t.x/n,y:t.y/n}},OV=r=>{switch(r){case"up":return{x:0,y:1};case"down":return{x:0,y:-1};case"left":return{x:-1,y:0};case"right":return{x:1,y:0}}},dye=(r,e={})=>{let t=r._internal_store;if(!t){t={counts:{}},r._internal_store=t;for(const i of r){const o=i.type,a=i[`${o}_id`];if(!a)continue;const s=Number.parseInt(a.split("_").pop());Number.isNaN(s)||(t.counts[o]=Math.max(t.counts[o]??0,s))}}return new Proxy({},{get:(i,o)=>o==="toArray"?()=>r:{get:a=>r.find(s=>s.type===o&&s[`${o}_id`]===a),getUsing:a=>{const s=Object.keys(a);if(s.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const l=s[0],c=l.replace("_id",""),u=r.find(A=>A.type===c&&A[l]===a[l]);return u?r.find(A=>A.type===o&&A[`${o}_id`]===u[`${o}_id`]):null},getWhere:a=>{const s=Object.keys(a);return r.find(l=>l.type===o&&s.every(c=>l[c]===a[c]))},list:a=>{const s=a?Object.keys(a):[];return r.filter(l=>l.type===o&&s.every(c=>l[c]===a[c]))},insert:a=>{var c;(c=t.counts)[o]??(c[o]=-1),t.counts[o]++;const s=t.counts[o],l={type:o,[`${o}_id`]:`${o}_${s}`,...a};return e.validateInserts&&(XT[o]??cR).parse(l),r.push(l),l},delete:a=>{const s=r.find(l=>l[`${o}_id`]===a);s&&r.splice(r.indexOf(s),1)},update:(a,s)=>{const l=r.find(c=>c[`${o}_id`]===a);if(l)return Object.assign(l,s),l},select:a=>{if(o==="source_component")return r.find(s=>s.type==="source_component"&&s.name===a.replace(/\./g,""));if(o==="pcb_port"||o==="source_port"||o==="schematic_port"){const[s,l]=a.replace(/\./g,"").split(/[\s\>]+/),c=r.find(A=>A.type==="source_component"&&A.name===s);if(!c)return null;const u=r.find(A=>A.type==="source_port"&&A.source_component_id===c.source_component_id&&(A.name===l||(A.port_hints??[]).includes(l)));if(!u)return null;if(o==="source_port")return u;if(o==="pcb_port")return r.find(A=>A.type==="pcb_port"&&A.source_port_id===u.source_port_id);if(o==="schematic_port")return r.find(A=>A.type==="schematic_port"&&A.source_port_id===u.source_port_id)}}}})};dye.unparsed=dye;var Qct=r=>{if(r==="up")return"right";if(r==="right")return"down";if(r==="down")return"left";if(r==="left")return"up";throw new Error(`Invalid direction: ${r}`)},Mct=r=>{if(r==="up")return"left";if(r==="left")return"down";if(r==="down")return"right";if(r==="right")return"up";throw new Error(`Invalid direction: ${r}`)},Dct=(r,e)=>{for(;e>0;)r=Qct(r),e--;for(;e<0;)r=Mct(r),e++;return r},Rct=(r,e)=>{if(r.type==="schematic_component")r.center=Xr(e,r.center);else if(r.type==="schematic_port")r.center=Xr(e,r.center),r.facing_direction&&(r.facing_direction=Dct(r.facing_direction,-(Math.atan2(e.b,e.a)/Math.PI)*2));else if(r.type==="schematic_text")r.position=Xr(e,r.position);else if(r.type!=="schematic_trace"){if(r.type==="schematic_box"){const{x:t,y:n}=Xr(e,{x:r.x,y:r.y});r.x=t,r.y=n}else if(r.type==="schematic_line"){const{x:t,y:n}=Xr(e,{x:r.x1,y:r.y1}),{x:i,y:o}=Xr(e,{x:r.x2,y:r.y2});r.x1=t,r.y1=n,r.x2=i,r.y2=o}}return r},fye=(r,e)=>{const t=r;for(const n of e.boxes){const i=t.find(a=>a.type==="schematic_component"&&a.schematic_component_id===n.box_id),o=OA(n.x-i.center.x,n.y-i.center.y);for(const a of t)a.schematic_component_id===n.box_id&&Rct(a,o)}return t},hye=r=>{const e=[],t=[],n=[],i={schematic_component:r.filter(o=>o.type==="schematic_component"),schematic_port:r.filter(o=>o.type==="schematic_port"),source_port:r.filter(o=>o.type==="source_port"),schematic_trace:r.filter(o=>o.type==="schematic_trace"),source_trace:r.filter(o=>o.type==="source_trace")};for(const o of i.schematic_component){const a=[],s=o.schematic_component_id;for(const c of i.schematic_port)c.schematic_component_id===o.schematic_component_id&&a.push({port_id:`${s}.${c.schematic_port_id}`,rx:c.center.x-o.center.x,ry:c.center.y-o.center.y});const l={box_id:s,x:o.center.x,y:o.center.y,ports:a};e.push(l)}for(const o of i.source_trace){const[a,s]=o.connected_source_port_ids,l=i.schematic_port.find(f=>f.source_port_id===a),c=i.schematic_port.find(f=>f.source_port_id===s);if(!l||!c)continue;const u=i.schematic_component.find(f=>f.schematic_component_id===l.schematic_component_id),A=i.schematic_component.find(f=>f.schematic_component_id===c.schematic_component_id);if(!u||!A)continue;const d={from:`${u.schematic_component_id}.${l.schematic_port_id}`,to:`${A.schematic_component_id}.${c.schematic_port_id}`};t.push(d)}return{boxes:e,connections:t,nets:n}};function Nct(r){return r.connections.reduce((e,t)=>(e[t.from]=t.to,e[t.to]=t.from,e),{})}function Tct(r,e){for(const t of["left","right"]){const n=r.filter(a=>a.side===t),i=n.map(a=>a.ascending_box_index).filter(a=>!isNaN(a)),o=Math.max(...i);for(const a of n)a.box_id!==e.box_id&&(a.y-=o/2*1.25)}}var Pct=r=>{let e=r[0];for(const t of r)t.ports.length>e.ports.length&&(e=t);return e};function kct(r,e,t,n){for(const i of["left","right"]){const o=r.filter(a=>a.side===i).sort((a,s)=>a.ascending_box_index-s.ascending_box_index);for(let a=0;a<o.length-1;a++){const[s,l]=[o[a],o[a+1]];if(s.ports.length===2&&l.ports.length===2){const[c,u]=s.ports,[A,d]=l.ports,[f,p]=[c,u].map(b=>e[b.port_id]),[C,v]=[A,d].map(b=>e[b.port_id]);let _=null;if((f===C||f===v)&&t.has(f)?_=f:(p===C||p===v)&&t.has(p)&&(_=p),!_)continue;const x=n.nets.find(b=>b.net_id===_);if(!x.is_ground&&!x.is_power)continue;x.is_ground&&o.slice(a+1).forEach(b=>{b.ascending_box_index-=1,b.y-=1}),x.is_power&&o.slice(a+1).forEach(b=>{b.ascending_box_index-=1,b.y-=1})}}}}function Uct(r,e){for(let t=0;t<r;t++){let n=0;for(const i of e)i.ascending_box_index===t&&(n+=1);if(n===0){r-=1;for(const i of e)i.ascending_box_index>t&&(i.ascending_box_index-=1)}}return r}function Fct(r,e,t,n){const i=Math.max(...r.map(o=>o.ascending_box_index).filter(o=>!isNaN(o)));for(const o of["left","right"])for(let a=0;a<=i;a++){const s=r.filter(p=>p.side===o).filter(p=>p.ascending_box_index===a);if(s.length===0)continue;const c=s.map(p=>e.connections.filter(C=>C.from.startsWith(p.box_id+".")||C.to.startsWith(p.box_id+".")).map(C=>C.from.startsWith(p.box_id+".")?C.to:C.from)).map(p=>p.filter(C=>t.has(C))),u=c.reduce((p,C)=>p.filter(v=>C.includes(v)),c[0]),A=u.map(p=>e.nets.find(C=>C.net_id===p)),f=(o==="left"?Math.max:Math.min)(...s.map(p=>p.x));for(const p of A){const C=a+(p!=null&&p.is_ground?-1:1),v=`${p==null?void 0:p.net_id}_${o==="left"?"L":"R"}_${a}`,_=p!=null&&p.is_ground?`${v}.top`:`${v}.bottom`,x={box_id:v,x:f,y:C,side:o,ascending_port_index:0,ascending_box_index:a,width:0,ports:[{port_id:_,rx:0,ry:p!=null&&p.is_ground?.1:-.1}]};r.push(x);for(const b of s){const P=n.filter(F=>F.from.startsWith(b.box_id+".")||F.to.startsWith(b.box_id+"."));for(const F of P)F.from===p.net_id&&(F.from=_),F.to===p.net_id&&(F.to=_)}}for(let p=0;p<s.length;p++){const C=s[p],v=c[p].filter(_=>!u.includes(_));for(const _ of v){const x=e.nets.find(H=>H.net_id===_),b=`${_}_${C.ascending_box_index}_${o==="left"?"L":"R"}_${p}`,P=`${b}.${x.is_ground?"top":"bottom"}`,F={x:C.x,y:C.y+(x.is_ground?-1:1),side:o,ascending_port_index:0,ascending_box_index:C.ascending_box_index,box_id:b,ports:[{port_id:P,rx:0,ry:x.is_ground?.1:-.1}]};r.push(F);const U=n.find(H=>H.from===_&&H.to.startsWith(C.box_id)||H.to===_&&H.from.startsWith(C.box_id));U.from===_&&(U.from=P),U.to===_&&(U.to=P)}}}return i}var pye=(r,e)=>{const t=xE(e*(Math.PI/180));r.ports.forEach(n=>{const i=Xr(t,{x:n.rx,y:n.ry});n.rx=i.x,n.ry=i.y})},gye=r=>{const e=Math.sqrt(r.x**2+r.y**2);return{x:r.x/e,y:r.y/e}},Lct=r=>[0,90,180,270].map(t=>{const n={...r,ports:r.ports.map(i=>({...i}))};return pye(n,t),n.applied_rotation_deg=t,n}),Gct=r=>{const e=r.boxes.sort((t,n)=>t.y-n.y);for(const t of e)if(t.ports.length===2){const n=t.ports.map(a=>{var u;const s=r.connections.filter(A=>A.from===a.port_id||A.to===a.port_id).map(A=>A.from===a.port_id?A.to:A.from);if(s.length===0)return null;const l=e.filter(A=>s.some(d=>d.startsWith(A.box_id+"."))),c=(u=l.flatMap(A=>A.ports))==null?void 0:u.filter(A=>s.includes(A.port_id));for(const A of c){const d=l.find(f=>f.box_id===A.port_id.split(".")[0]);A.x=d.x+A.rx,A.y=d.y+A.ry}return{...a,connected_port:c[0],connected_ports:c}}).filter(Boolean);if(n.length===0)continue;const i=Lct({...t,ports:n});for(const a of i){a.natural_offset_sum_deg=0;for(const s of a.ports)for(const l of s.connected_ports){const c=gye({x:l.x-(a.x+s.rx),y:l.y-(a.y+s.ry)}),u=gye({x:s.rx,y:s.ry}),A=Math.sqrt((c.x-u.x)**2+(c.y-u.y)**2),d=c.x*u.x+c.y*u.y,f=c.x*u.y-c.y*u.x,p=Math.atan2(f,d)*(180/Math.PI);a.natural_offset_sum_deg+=Math.abs(p)/A}}const o=i.reduce((a,s)=>a.natural_offset_sum_deg<s.natural_offset_sum_deg?a:s);pye(t,o.applied_rotation_deg)}return r},mye=r=>{const e=new Set(r.nets.map(l=>l.net_id)),t=Nct(r),n=JSON.parse(JSON.stringify(r.boxes)),i=JSON.parse(JSON.stringify(r.connections));for(const l of n){l.x=0,l.y=0;let c=0,u=0;for(const A of l.ports)A.rx<c?c=A.rx:A.rx>u&&(u=A.rx);l.width=u-c}const o=Pct(n);for(const l of o.ports)l.rx>0?l.side="right":l.rx<0&&(l.side="left");for(const l of n){if(l.box_id===o.box_id)continue;const c=o.ports.filter(d=>i.some(f=>f.from.startsWith(l.box_id)&&f.to===d.port_id||f.to.startsWith(l.box_id)&&f.from===d.port_id));if(c.length===0){l.side="left";continue}let u=0,A=0;for(const d of c)d.rx>0?A+=1:d.rx<0&&(u+=1);u>=A?l.side="left":l.side="right"}for(const l of["left","right"]){const c=o.ports.filter(u=>u.side===l);c.sort((u,A)=>u.ry-A.ry);for(const u of c)u.ascending_port_index=c.indexOf(u)}for(const l of n){if(l.box_id===o.box_id)continue;const c=r.connections.filter(A=>A.from.startsWith(l.box_id+".")||A.to.startsWith(l.box_id+".")).map(A=>A.from.startsWith(l.box_id+".")?A.to:A.from),u=o.ports.filter(A=>c.includes(A.port_id));u.length!==0&&(l.ascending_port_index=Math.min(...u.map(A=>A.ascending_port_index)),l.ascending_box_index=l.ascending_port_index)}let a=Math.max(0,...n.map(l=>l.ascending_box_index).filter(l=>!isNaN(l)));for(const l of n)l.box_id!==o.box_id&&l.ascending_box_index===void 0&&(a+=1,l.ascending_box_index=a);for(const l of["left","right"])Uct(a,n.filter(c=>c.side===l));for(const l of["left","right"]){let c=o.width*.75*(l==="left"?-1:1);for(let u=0;u<=a;u++){const A=n.filter(p=>p.side===l&&p.ascending_box_index===u),d=Math.max(...A.map(p=>p.width)),f=Math.max(.5,d)*(l==="left"?-1:1);c+=f;for(const p of A)p.box_id!==o.box_id&&(p.y=p.ascending_box_index*1.25,p.x=c);c+=f/2}}kct(n,t,e,r),Fct(n,r,e,i),Tct(n,o);const s={...r,connections:i,boxes:n};return Gct(s),s};function tw(r){throw new Error('Could not dynamically require "'+r+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var zV={exports:{}},yye;function Oct(){return yye||(yye=1,function(r,e){(function(t){r.exports=t()})(function(){return function t(n,i,o){function a(c,u){if(!i[c]){if(!n[c]){var A=typeof tw=="function"&&tw;if(!u&&A)return A(c,!0);if(s)return s(c,!0);throw new Error("Cannot find module '"+c+"'")}u=i[c]={exports:{}},n[c][0].call(u.exports,function(d){var f=n[c][1][d];return a(f||d)},u,u.exports,t,n,i,o)}return i[c].exports}for(var s=typeof tw=="function"&&tw,l=0;l<o.length;l++)a(o[l]);return a}({1:[function(t,n,i){(function(o,a,s,l,c,u,A,d,f){var p=t("crypto");function C(U,H){H=x(U,H);var L;return(L=H.algorithm!=="passthrough"?p.createHash(H.algorithm):new F).write===void 0&&(L.write=L.update,L.end=L.update),P(H,L).dispatch(U),L.update||L.end(""),L.digest?L.digest(H.encoding==="buffer"?void 0:H.encoding):(U=L.read(),H.encoding!=="buffer"?U.toString(H.encoding):U)}(i=n.exports=C).sha1=function(U){return C(U)},i.keys=function(U){return C(U,{excludeValues:!0,algorithm:"sha1",encoding:"hex"})},i.MD5=function(U){return C(U,{algorithm:"md5",encoding:"hex"})},i.keysMD5=function(U){return C(U,{algorithm:"md5",encoding:"hex",excludeValues:!0})};var v=p.getHashes?p.getHashes().slice():["sha1","md5"],_=(v.push("passthrough"),["buffer","hex","binary","base64"]);function x(U,H){var L={};if(L.algorithm=(H=H||{}).algorithm||"sha1",L.encoding=H.encoding||"hex",L.excludeValues=!!H.excludeValues,L.algorithm=L.algorithm.toLowerCase(),L.encoding=L.encoding.toLowerCase(),L.ignoreUnknown=H.ignoreUnknown===!0,L.respectType=H.respectType!==!1,L.respectFunctionNames=H.respectFunctionNames!==!1,L.respectFunctionProperties=H.respectFunctionProperties!==!1,L.unorderedArrays=H.unorderedArrays===!0,L.unorderedSets=H.unorderedSets!==!1,L.unorderedObjects=H.unorderedObjects!==!1,L.replacer=H.replacer||void 0,L.excludeKeys=H.excludeKeys||void 0,U===void 0)throw new Error("Object argument required.");for(var j=0;j<v.length;++j)v[j].toLowerCase()===L.algorithm.toLowerCase()&&(L.algorithm=v[j]);if(v.indexOf(L.algorithm)===-1)throw new Error('Algorithm "'+L.algorithm+'" not supported. supported values: '+v.join(", "));if(_.indexOf(L.encoding)===-1&&L.algorithm!=="passthrough")throw new Error('Encoding "'+L.encoding+'" not supported. supported values: '+_.join(", "));return L}function b(U){if(typeof U=="function")return/^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i.exec(Function.prototype.toString.call(U))!=null}function P(U,H,L){L=L||[];function j(O){return H.update?H.update(O,"utf8"):H.write(O,"utf8")}return{dispatch:function(O){return this["_"+((O=U.replacer?U.replacer(O):O)===null?"null":typeof O)](O)},_object:function(O){var oe,te=Object.prototype.toString.call(O),ie=/\[object (.*)\]/i.exec(te);if(ie=(ie=ie?ie[1]:"unknown:["+te+"]").toLowerCase(),0<=(te=L.indexOf(O)))return this.dispatch("[CIRCULAR:"+te+"]");if(L.push(O),s!==void 0&&s.isBuffer&&s.isBuffer(O))return j("buffer:"),j(O);if(ie==="object"||ie==="function"||ie==="asyncfunction")return te=Object.keys(O),U.unorderedObjects&&(te=te.sort()),U.respectType===!1||b(O)||te.splice(0,0,"prototype","__proto__","constructor"),U.excludeKeys&&(te=te.filter(function(pe){return!U.excludeKeys(pe)})),j("object:"+te.length+":"),oe=this,te.forEach(function(pe){oe.dispatch(pe),j(":"),U.excludeValues||oe.dispatch(O[pe]),j(",")});if(!this["_"+ie]){if(U.ignoreUnknown)return j("["+ie+"]");throw new Error('Unknown object type "'+ie+'"')}this["_"+ie](O)},_array:function(O,pe){pe=pe!==void 0?pe:U.unorderedArrays!==!1;var te=this;if(j("array:"+O.length+":"),!pe||O.length<=1)return O.forEach(function(Ae){return te.dispatch(Ae)});var ie=[],pe=O.map(function(Ae){var de=new F,Ie=L.slice();return P(U,de,Ie).dispatch(Ae),ie=ie.concat(Ie.slice(L.length)),de.read().toString()});return L=L.concat(ie),pe.sort(),this._array(pe,!1)},_date:function(O){return j("date:"+O.toJSON())},_symbol:function(O){return j("symbol:"+O.toString())},_error:function(O){return j("error:"+O.toString())},_boolean:function(O){return j("bool:"+O.toString())},_string:function(O){j("string:"+O.length+":"),j(O.toString())},_function:function(O){j("fn:"),b(O)?this.dispatch("[native]"):this.dispatch(O.toString()),U.respectFunctionNames!==!1&&this.dispatch("function-name:"+String(O.name)),U.respectFunctionProperties&&this._object(O)},_number:function(O){return j("number:"+O.toString())},_xml:function(O){return j("xml:"+O.toString())},_null:function(){return j("Null")},_undefined:function(){return j("Undefined")},_regexp:function(O){return j("regex:"+O.toString())},_uint8array:function(O){return j("uint8array:"),this.dispatch(Array.prototype.slice.call(O))},_uint8clampedarray:function(O){return j("uint8clampedarray:"),this.dispatch(Array.prototype.slice.call(O))},_int8array:function(O){return j("int8array:"),this.dispatch(Array.prototype.slice.call(O))},_uint16array:function(O){return j("uint16array:"),this.dispatch(Array.prototype.slice.call(O))},_int16array:function(O){return j("int16array:"),this.dispatch(Array.prototype.slice.call(O))},_uint32array:function(O){return j("uint32array:"),this.dispatch(Array.prototype.slice.call(O))},_int32array:function(O){return j("int32array:"),this.dispatch(Array.prototype.slice.call(O))},_float32array:function(O){return j("float32array:"),this.dispatch(Array.prototype.slice.call(O))},_float64array:function(O){return j("float64array:"),this.dispatch(Array.prototype.slice.call(O))},_arraybuffer:function(O){return j("arraybuffer:"),this.dispatch(new Uint8Array(O))},_url:function(O){return j("url:"+O.toString())},_map:function(O){return j("map:"),O=Array.from(O),this._array(O,U.unorderedSets!==!1)},_set:function(O){return j("set:"),O=Array.from(O),this._array(O,U.unorderedSets!==!1)},_file:function(O){return j("file:"),this.dispatch([O.name,O.size,O.type,O.lastModfied])},_blob:function(){if(U.ignoreUnknown)return j("[blob]");throw Error(`Hashing Blob objects is currently not supported
644
644
  (see https://github.com/puleos/object-hash/issues/26)
645
645
  Use "options.replacer" or "options.ignoreUnknown"
646
646
  `)},_domwindow:function(){return j("domwindow")},_bigint:function(O){return j("bigint:"+O.toString())},_process:function(){return j("process")},_timer:function(){return j("timer")},_pipe:function(){return j("pipe")},_tcp:function(){return j("tcp")},_udp:function(){return j("udp")},_tty:function(){return j("tty")},_statwatcher:function(){return j("statwatcher")},_securecontext:function(){return j("securecontext")},_connection:function(){return j("connection")},_zlib:function(){return j("zlib")},_context:function(){return j("context")},_nodescript:function(){return j("nodescript")},_httpparser:function(){return j("httpparser")},_dataview:function(){return j("dataview")},_signal:function(){return j("signal")},_fsevent:function(){return j("fsevent")},_tlswrap:function(){return j("tlswrap")}}}function F(){return{buf:"",write:function(U){this.buf+=U},end:function(U){this.buf+=U},read:function(){return this.buf}}}i.writeToStream=function(U,H,L){return L===void 0&&(L=H,H={}),P(H=x(U,H),L).dispatch(U)}}).call(this,t("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},t("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_9a5aa49d.js","/")},{buffer:3,crypto:5,lYpoI2:11}],2:[function(t,n,i){(function(o,a,s,l,c,u,A,d,f){(function(p){var C=typeof Uint8Array<"u"?Uint8Array:Array,v=43,_=47,x=48,b=97,P=65,F=45,U=95;function H(L){return L=L.charCodeAt(0),L===v||L===F?62:L===_||L===U?63:L<x?-1:L<x+10?L-x+26+26:L<P+26?L-P:L<b+26?L-b+26:void 0}p.toByteArray=function(L){var j,O;if(0<L.length%4)throw new Error("Invalid string. Length must be a multiple of 4");var oe=L.length,oe=L.charAt(oe-2)==="="?2:L.charAt(oe-1)==="="?1:0,te=new C(3*L.length/4-oe),ie=0<oe?L.length-4:L.length,pe=0;function Ae(de){te[pe++]=de}for(j=0;j<ie;j+=4,0)Ae((16711680&(O=H(L.charAt(j))<<18|H(L.charAt(j+1))<<12|H(L.charAt(j+2))<<6|H(L.charAt(j+3))))>>16),Ae((65280&O)>>8),Ae(255&O);return oe==2?Ae(255&(O=H(L.charAt(j))<<2|H(L.charAt(j+1))>>4)):oe==1&&(Ae((O=H(L.charAt(j))<<10|H(L.charAt(j+1))<<4|H(L.charAt(j+2))>>2)>>8&255),Ae(255&O)),te},p.fromByteArray=function(L){var j,O,oe,te,ie=L.length%3,pe="";function Ae(de){return"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(de)}for(j=0,oe=L.length-ie;j<oe;j+=3)O=(L[j]<<16)+(L[j+1]<<8)+L[j+2],pe+=Ae((te=O)>>18&63)+Ae(te>>12&63)+Ae(te>>6&63)+Ae(63&te);switch(ie){case 1:pe=(pe+=Ae((O=L[L.length-1])>>2))+Ae(O<<4&63)+"==";break;case 2:pe=(pe=(pe+=Ae((O=(L[L.length-2]<<8)+L[L.length-1])>>10))+Ae(O>>4&63))+Ae(O<<2&63)+"="}return pe}})(i===void 0?this.base64js={}:i)}).call(this,t("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},t("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/base64-js/lib/b64.js","/node_modules/gulp-browserify/node_modules/base64-js/lib")},{buffer:3,lYpoI2:11}],3:[function(t,n,i){(function(o,a,v,l,c,u,A,d,f){var p=t("base64-js"),C=t("ieee754");function v($e,It,Ct){if(!(this instanceof v))return new v($e,It,Ct);var Lt,Xt,Rt,tt,un=typeof $e;if(It==="base64"&&un=="string")for($e=(tt=$e).trim?tt.trim():tt.replace(/^\s+|\s+$/g,"");$e.length%4!=0;)$e+="=";if(un=="number")Lt=ge($e);else if(un=="string")Lt=v.byteLength($e,It);else{if(un!="object")throw new Error("First argument needs to be a number, array or string.");Lt=ge($e.length)}if(v._useTypedArrays?Xt=v._augment(new Uint8Array(Lt)):((Xt=this).length=Lt,Xt._isBuffer=!0),v._useTypedArrays&&typeof $e.byteLength=="number")Xt._set($e);else if(Me(tt=$e)||v.isBuffer(tt)||tt&&typeof tt=="object"&&typeof tt.length=="number")for(Rt=0;Rt<Lt;Rt++)v.isBuffer($e)?Xt[Rt]=$e.readUInt8(Rt):Xt[Rt]=$e[Rt];else if(un=="string")Xt.write($e,0,It);else if(un=="number"&&!v._useTypedArrays&&!Ct)for(Rt=0;Rt<Lt;Rt++)Xt[Rt]=0;return Xt}function _($e,It,Ct,Lt){return v._charsWritten=Ke(function(Xt){for(var Rt=[],tt=0;tt<Xt.length;tt++)Rt.push(255&Xt.charCodeAt(tt));return Rt}(It),$e,Ct,Lt)}function x($e,It,Ct,Lt){return v._charsWritten=Ke(function(Xt){for(var Rt,tt,un=[],Tt=0;Tt<Xt.length;Tt++)tt=Xt.charCodeAt(Tt),Rt=tt>>8,tt=tt%256,un.push(tt),un.push(Rt);return un}(It),$e,Ct,Lt)}function b($e,It,Ct){var Lt="";Ct=Math.min($e.length,Ct);for(var Xt=It;Xt<Ct;Xt++)Lt+=String.fromCharCode($e[Xt]);return Lt}function P($e,It,Ct,Rt){Rt||(Qt(typeof Ct=="boolean","missing or invalid endian"),Qt(It!=null,"missing offset"),Qt(It+1<$e.length,"Trying to read beyond buffer length"));var Xt,Rt=$e.length;if(!(Rt<=It))return Ct?(Xt=$e[It],It+1<Rt&&(Xt|=$e[It+1]<<8)):(Xt=$e[It]<<8,It+1<Rt&&(Xt|=$e[It+1])),Xt}function F($e,It,Ct,Rt){Rt||(Qt(typeof Ct=="boolean","missing or invalid endian"),Qt(It!=null,"missing offset"),Qt(It+3<$e.length,"Trying to read beyond buffer length"));var Xt,Rt=$e.length;if(!(Rt<=It))return Ct?(It+2<Rt&&(Xt=$e[It+2]<<16),It+1<Rt&&(Xt|=$e[It+1]<<8),Xt|=$e[It],It+3<Rt&&(Xt+=$e[It+3]<<24>>>0)):(It+1<Rt&&(Xt=$e[It+1]<<16),It+2<Rt&&(Xt|=$e[It+2]<<8),It+3<Rt&&(Xt|=$e[It+3]),Xt+=$e[It]<<24>>>0),Xt}function U($e,It,Ct,Lt){if(Lt||(Qt(typeof Ct=="boolean","missing or invalid endian"),Qt(It!=null,"missing offset"),Qt(It+1<$e.length,"Trying to read beyond buffer length")),!($e.length<=It))return Lt=P($e,It,Ct,!0),32768&Lt?-1*(65535-Lt+1):Lt}function H($e,It,Ct,Lt){if(Lt||(Qt(typeof Ct=="boolean","missing or invalid endian"),Qt(It!=null,"missing offset"),Qt(It+3<$e.length,"Trying to read beyond buffer length")),!($e.length<=It))return Lt=F($e,It,Ct,!0),2147483648&Lt?-1*(4294967295-Lt+1):Lt}function L($e,It,Ct,Lt){return Lt||(Qt(typeof Ct=="boolean","missing or invalid endian"),Qt(It+3<$e.length,"Trying to read beyond buffer length")),C.read($e,It,Ct,23,4)}function j($e,It,Ct,Lt){return Lt||(Qt(typeof Ct=="boolean","missing or invalid endian"),Qt(It+7<$e.length,"Trying to read beyond buffer length")),C.read($e,It,Ct,52,8)}function O($e,It,Ct,Lt,Xt){if(Xt||(Qt(It!=null,"missing value"),Qt(typeof Lt=="boolean","missing or invalid endian"),Qt(Ct!=null,"missing offset"),Qt(Ct+1<$e.length,"trying to write beyond buffer length"),lt(It,65535)),Xt=$e.length,!(Xt<=Ct))for(var Rt=0,tt=Math.min(Xt-Ct,2);Rt<tt;Rt++)$e[Ct+Rt]=(It&255<<8*(Lt?Rt:1-Rt))>>>8*(Lt?Rt:1-Rt)}function oe($e,It,Ct,Lt,Xt){if(Xt||(Qt(It!=null,"missing value"),Qt(typeof Lt=="boolean","missing or invalid endian"),Qt(Ct!=null,"missing offset"),Qt(Ct+3<$e.length,"trying to write beyond buffer length"),lt(It,4294967295)),Xt=$e.length,!(Xt<=Ct))for(var Rt=0,tt=Math.min(Xt-Ct,4);Rt<tt;Rt++)$e[Ct+Rt]=It>>>8*(Lt?Rt:3-Rt)&255}function te($e,It,Ct,Lt,Xt){Xt||(Qt(It!=null,"missing value"),Qt(typeof Lt=="boolean","missing or invalid endian"),Qt(Ct!=null,"missing offset"),Qt(Ct+1<$e.length,"Trying to write beyond buffer length"),ft(It,32767,-32768)),$e.length<=Ct||O($e,0<=It?It:65535+It+1,Ct,Lt,Xt)}function ie($e,It,Ct,Lt,Xt){Xt||(Qt(It!=null,"missing value"),Qt(typeof Lt=="boolean","missing or invalid endian"),Qt(Ct!=null,"missing offset"),Qt(Ct+3<$e.length,"Trying to write beyond buffer length"),ft(It,2147483647,-2147483648)),$e.length<=Ct||oe($e,0<=It?It:4294967295+It+1,Ct,Lt,Xt)}function pe($e,It,Ct,Lt,Xt){Xt||(Qt(It!=null,"missing value"),Qt(typeof Lt=="boolean","missing or invalid endian"),Qt(Ct!=null,"missing offset"),Qt(Ct+3<$e.length,"Trying to write beyond buffer length"),kt(It,34028234663852886e22,-34028234663852886e22)),$e.length<=Ct||C.write($e,It,Ct,Lt,23,4)}function Ae($e,It,Ct,Lt,Xt){Xt||(Qt(It!=null,"missing value"),Qt(typeof Lt=="boolean","missing or invalid endian"),Qt(Ct!=null,"missing offset"),Qt(Ct+7<$e.length,"Trying to write beyond buffer length"),kt(It,17976931348623157e292,-17976931348623157e292)),$e.length<=Ct||C.write($e,It,Ct,Lt,52,8)}i.Buffer=v,i.SlowBuffer=v,i.INSPECT_MAX_BYTES=50,v.poolSize=8192,v._useTypedArrays=function(){try{var $e=new ArrayBuffer(0),It=new Uint8Array($e);return It.foo=function(){return 42},It.foo()===42&&typeof It.subarray=="function"}catch{return!1}}(),v.isEncoding=function($e){switch(String($e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},v.isBuffer=function($e){return!($e==null||!$e._isBuffer)},v.byteLength=function($e,It){var Ct;switch($e+="",It||"utf8"){case"hex":Ct=$e.length/2;break;case"utf8":case"utf-8":Ct=Re($e).length;break;case"ascii":case"binary":case"raw":Ct=$e.length;break;case"base64":Ct=we($e).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":Ct=2*$e.length;break;default:throw new Error("Unknown encoding")}return Ct},v.concat=function($e,It){if(Qt(Me($e),`Usage: Buffer.concat(list, [totalLength])
@@ -13494,7 +13494,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}return ble}sqt();function R6e(r,e,t,n=
13494
13494
  &:hover {
13495
13495
  background-color: rgba(255, 255, 255, 0.1);
13496
13496
  }
13497
- `,onClick:n=>{n.stopPropagation(),t()},children:[Ve.jsx("input",{type:"checkbox",checked:e}),Ve.jsx("span",{style:{color:"#eee"},children:r})]}),T$t=({children:r,elements:e})=>{const[t,n]=J1(L=>[L.is_mouse_over_container,L.setIsMouseOverContainer]),[i,o]=nt.useState(!1),[a,s]=nt.useState(!1),[l,c]=nt.useState(!1),[u,A]=J1(L=>[L.selected_layer,L.selectLayer]),[d,f,p,C,v,_]=J1(L=>[L.in_move_footprint_mode,L.in_draw_trace_mode,L.is_showing_rats_nest,L.is_showing_multiple_traces_length,L.is_showing_autorouting,L.is_showing_drc_errors]),x=J1(L=>L.setEditMode),b=J1(L=>L.setIsShowingRatsNest),P=J1(L=>L.setIsShowingMultipleTracesLength),F=J1(L=>L.setIsShowingAutorouting),U=J1(L=>L.setIsShowingDrcErrors);Kw("1",()=>A("top")),Kw("2",()=>A("bottom")),Kw("3",()=>A("inner1")),Kw("4",()=>A("inner2")),Kw("5",()=>A("inner3")),Kw("6",()=>A("inner4")),Kw("7",()=>A("inner5")),Kw("8",()=>A("inner6"));const H=(e==null?void 0:e.filter(L=>L.type.includes("error")).length)??0;return Ve.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>{n(!0)},onMouseLeave:L=>{n(!1),s(!1)},children:[r,Ve.jsxs("div",{style:{position:"absolute",bottom:4,right:8,pointerEvents:"none",color:"white",fontSize:11,opacity:t?.5:0,transition:"opacity 1s",transitionDelay:"2s",fontFamily:"sans-serif"},children:["@tscircuit/pcb-viewer@",R$t.version]}),Ve.jsxs("div",{style:{position:"absolute",opacity:t?1:0,top:16,left:16,transition:t?"opacity 100ms linear":"opacity 1s linear",zIndex:gx.toolbarOverlay,color:"red",display:"flex",fontSize:12,height:100,fontFamily:"sans-serif"},children:[Ve.jsxs(wD,{onClick:()=>{s(!a)},onMouseLeave:()=>{a&&s(!1)},children:[Ve.jsxs("div",{children:["layer:"," ",Ve.jsx("span",{style:{marginLeft:2,fontWeight:500,color:SD[u]},children:u})]}),a&&Ve.jsx("div",{style:{marginTop:4,minWidth:120},children:ace.map(L=>L.replace(/-/g,"")).map(L=>Ve.jsx(N$t,{name:L,selected:L===u,onClick:()=>{A(L.replace(/-/,""))}},L))})]}),Ve.jsxs(wD,{style:H>0?{color:"red"}:{},onClick:()=>c(!l),onMouseLeave:()=>c(!1),children:[Ve.jsxs("div",{children:[H," errors"]}),l&&Ve.jsx("div",{style:{display:"grid",gridTemplateColumns:"100px 300px"},children:e==null?void 0:e.filter(L=>L.type.includes("error")).map((L,j)=>Ve.jsxs(nt.Fragment,{children:[Ve.jsx("div",{children:L.error_type}),Ve.jsx("div",{children:L.message})]},j))})]}),Ve.jsx(wD,{style:{},onClick:()=>{x(f?"off":"draw_trace")},children:Ve.jsxs("div",{children:[f?"✖ ":"","Edit Traces"]})}),Ve.jsx(wD,{style:{},onClick:()=>{x(d?"off":"move_footprint")},children:Ve.jsxs("div",{children:[d?"✖ ":"","Move Components"]})}),Ve.jsx(wD,{style:{},onClick:()=>{b(!p)},children:Ve.jsxs("div",{children:[p?"✖ ":"","Rats Nest"]})}),Ve.jsx(wD,{onClick:()=>{o(!i)},children:Ve.jsxs("div",{children:[Ve.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:["View"," ",Ve.jsx("span",{style:{fontSize:"8px",transform:i?"rotate(180deg)":"rotate(0)",transition:"transform 0.1s ease",display:"inline-block"},children:"▼"})]}),i&&Ve.jsxs("div",{style:{marginTop:4,minWidth:120},children:[Ve.jsx(dce,{label:"Show All Trace Lengths",checked:C,onClick:()=>{P(!C)}}),Ve.jsx(dce,{label:"Show Autorouting Animation",checked:v,onClick:()=>{F(!v)}}),Ve.jsx(dce,{label:"Show DRC Errors",checked:_,onClick:()=>{U(!_)}})]})]})})]})]})},P$t=r=>{const{transform:e,elements:t}=r,[n,i]=nt.useMemo(()=>{const c=r.elements.flatMap(A=>KXt(A,r.elements)),u=AB(r.elements);return[c,u]},[r.elements]),[o,a]=nt.useState({drawingObjectIdsWithMouseOver:new Set,primitiveIdsInMousedOverNet:[]}),s=nt.useMemo(()=>YXt({primitivesWithoutInteractionMetadata:n,drawingObjectIdsWithMouseOver:o.drawingObjectIdsWithMouseOver,primitiveIdsInMousedOverNet:o.primitiveIdsInMousedOverNet}),[n,o]),l=nt.useCallback(c=>{var d,f;const u=[];for(const p of c)if(p._element){const C=i.getNetConnectedToId("pcb_port_id"in p._element?(d=p._element)==null?void 0:d.pcb_port_id:"pcb_trace_id"in p._element?(f=p._element)==null?void 0:f.pcb_trace_id:"");u.push(...i.getIdsConnectedToNet(C))}const A=new Set(c.map(p=>p._pcb_drawing_object_id));a({drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:u})},[i]);return Ve.jsx(M$t,{elements:t,transform:e,primitives:n,onMouseHoverOverPrimitives:l,children:Ve.jsx(f$t,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:Ve.jsx(m$t,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:Ve.jsx(A$t,{transform:e,focusOnHover:r.focusOnHover,children:Ve.jsx(T$t,{elements:t,children:Ve.jsx(I$t,{transform:e,elements:t,children:Ve.jsx(D$t,{transform:e,soup:t,children:Ve.jsx(c$t,{transform:e,debugGraphics:r.debugGraphics,children:Ve.jsx(u$t,{transform:e,elements:t,children:Ve.jsx(l$t,{transform:e,primitives:s,width:r.width,height:r.height,grid:r.grid})})})})})})})})})})},k$t=Pc(OA(400,300),F1(40,-40)),U$t=({circuitJson:r,debugGraphics:e,height:t=600,initialState:n,allowEditing:i=!0,editEvents:o,onEditEventsChanged:a,focusOnHover:s=!1,clickToInteractEnabled:l=!1})=>{const[c,u]=nt.useState(!l),[A,d]=uce(),[f,p]=nt.useState(k$t),{ref:C,setTransform:v,cancelDrag:_}=HXt({transform:f,onSetTransform:p,enabled:c});let[x,b]=nt.useState([]);x=o??x;const P=nt.useRef(!1),F=nt.useRef(null),U=`${(r==null?void 0:r.length)||0}_${(r==null?void 0:r.editCount)||0}`,H=()=>{const te=(d==null?void 0:d.width)>0?d:{width:500,height:500},{center:ie,width:pe,height:Ae}=j.some(ge=>ge.type.startsWith("pcb_"))?NXt(j.filter(ge=>ge.type.startsWith("pcb_"))):{center:{x:0,y:0},width:.001,height:.001},de=Math.min((te.width??0)/pe,(te.height??0)/Ae,100)*.75,Ie=Pc(OA((te.width??0)/2,(te.height??0)/2),F1(de,-de,0,0),OA(-ie.x,-ie.y));v(Ie)};nt.useEffect(()=>{d!=null&&d.width&&r&&r.length!==0&&(P.current||(H(),P.current=!0))},[r,d]);const L=nt.useMemo(()=>(r==null?void 0:r.filter(te=>te.type.startsWith("pcb_")||te.type.startsWith("source_")))??[],[U]),j=nt.useMemo(()=>$Jt({circuitJson:L,editEvents:x}),[L,x]),O=te=>{b([...x,te]),a==null||a([...x,te])},oe=te=>{const ie=x.map(pe=>pe.edit_event_id===te.edit_event_id?{...pe,...te}:pe);b(ie),a==null||a(ie)};return Ve.jsxs("div",{ref:C,style:{position:"relative"},children:[Ve.jsx("div",{ref:A,children:Ve.jsxs(PXt,{initialState:n,children:[Ve.jsx(P$t,{transform:f,height:t,width:d.width,allowEditing:i,focusOnHover:s,cancelPanDrag:_,onCreateEditEvent:O,onModifyEditEvent:oe,grid:{spacing:1,view_window:{left:0,right:d.width||500,top:t,bottom:0}},elements:j,debugGraphics:e},d.width),Ve.jsx(UXt,{})]})}),l&&!c&&Ve.jsx("div",{onClick:()=>{u(!0),H()},onTouchStart:te=>{const ie=te.touches[0];F.current={x:ie.clientX,y:ie.clientY}},onTouchEnd:te=>{const ie=te.changedTouches[0],pe=F.current;if(!pe)return;const Ae=Math.abs(ie.clientX-pe.x),de=Math.abs(ie.clientY-pe.y);Ae<10&&de<10&&(te.preventDefault(),u(!0),H()),F.current=null},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:gx.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center",touchAction:"pan-x pan-y pinch-zoom"},children:Ve.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",pointerEvents:"none"},children:typeof window<"u"&&("ontouchstart"in window||navigator.maxTouchPoints>0)?"Touch to Interact":"Click to Interact"})})]})};const F$t=({containerClassName:r,...e})=>{const t=nt.useRef(null),[n,i]=nt.useState(620);return nt.useLayoutEffect(()=>{const o=()=>{if(t.current){const s=t.current.clientHeight,l=window.innerHeight;i(Math.min(Math.max(s,620),l))}};o();const a=new ResizeObserver(o);return t.current&&a.observe(t.current),window.addEventListener("resize",o),()=>{a.disconnect(),window.removeEventListener("resize",o)}},[]),Ve.jsx("div",{ref:t,className:r||"rf-w-full rf-h-full",children:Ve.jsx(U$t,{...e,height:n})})},L$t='*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }/*! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com*/*,:after,:before{border:0 solid #e5e7eb;box-sizing:border-box}:after,:before{--tw-content:""}:host,html{line-height:1.5;-webkit-text-size-adjust:100%;font-family:ui-sans-serif,system-ui,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-tap-highlight-color:transparent}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-size:1em;font-variation-settings:normal}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{color:inherit;font-family:inherit;font-feature-settings:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;letter-spacing:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{color:#9ca3af;opacity:1}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]:where(:not([hidden=until-found])){display:none}:root{--radius:0.5rem}.rf-pointer-events-none{pointer-events:none}.rf-invisible{visibility:hidden}.rf-fixed{position:fixed}.rf-absolute{position:absolute}.rf-relative{position:relative}.rf-inset-0{inset:0}.-rf-left-2{left:-.5rem}.-rf-right-10{right:-2.5rem}.-rf-right-2{right:-.5rem}.-rf-right-4{right:-1rem}.-rf-right-6{right:-1.5rem}.-rf-right-7{right:-1.75rem}.-rf-right-8{right:-2rem}.-rf-right-9{right:-2.25rem}.rf-bottom-full{bottom:100%}.rf-left-0{left:0}.rf-left-1{left:.25rem}.rf-left-1\\/2{left:50%}.rf-left-2{left:.5rem}.rf-left-\\[50\\%\\]{left:50%}.rf-right-0{right:0}.rf-right-4{right:1rem}.rf-right-\\[4px\\]{right:4px}.rf-top-0{top:0}.rf-top-1{top:.25rem}.rf-top-2{top:.5rem}.rf-top-2\\.5{top:.625rem}.rf-top-\\[50\\%\\]{top:50%}.rf-top-\\[6px\\]{top:6px}.rf-z-50{z-index:50}.rf-z-\\[100\\]{z-index:100}.-rf-mx-1,.rf--mx-1{margin-left:-.25rem;margin-right:-.25rem}.rf-mx-1{margin-left:.25rem;margin-right:.25rem}.rf-mx-2{margin-left:.5rem;margin-right:.5rem}.rf-mx-auto{margin-left:auto;margin-right:auto}.rf-my-1{margin-bottom:.25rem;margin-top:.25rem}.rf-my-12{margin-bottom:3rem;margin-top:3rem}.rf-my-4{margin-bottom:1rem;margin-top:1rem}.rf-my-auto{margin-bottom:auto;margin-top:auto}.rf-mb-1{margin-bottom:.25rem}.rf-mb-12{margin-bottom:3rem}.rf-mb-2{margin-bottom:.5rem}.rf-mb-3{margin-bottom:.75rem}.rf-mb-4{margin-bottom:1rem}.rf-mb-6{margin-bottom:1.5rem}.rf-mb-8{margin-bottom:2rem}.rf-ml-1{margin-left:.25rem}.rf-ml-2{margin-left:.5rem}.rf-ml-auto{margin-left:auto}.rf-mr-1{margin-right:.25rem}.rf-mr-2{margin-right:.5rem}.rf-mt-0{margin-top:0}.rf-mt-0\\.5{margin-top:.125rem}.rf-mt-1{margin-top:.25rem}.rf-mt-2{margin-top:.5rem}.rf-mt-3{margin-top:.75rem}.rf-mt-4{margin-top:1rem}.rf-mt-5{margin-top:1.25rem}.rf-mt-auto{margin-top:auto}.rf-block{display:block}.rf-inline{display:inline}.rf-flex{display:flex}.rf-inline-flex{display:inline-flex}.rf-grid{display:grid}.rf-hidden{display:none}.rf-aspect-square{aspect-ratio:1/1}.rf-aspect-video{aspect-ratio:16/9}.rf-size-14{height:3.5rem;width:3.5rem}.rf-size-4{height:1rem;width:1rem}.\\!rf-h-2{height:.5rem!important}.\\!rf-h-2\\.5{height:.625rem!important}.\\!rf-h-3{height:.75rem!important}.\\!rf-h-full{height:100%!important}.rf-h-1{height:.25rem}.rf-h-10{height:2.5rem}.rf-h-12{height:3rem}.rf-h-2{height:.5rem}.rf-h-2\\.5{height:.625rem}.rf-h-3{height:.75rem}.rf-h-3\\.5{height:.875rem}.rf-h-4{height:1rem}.rf-h-5{height:1.25rem}.rf-h-6{height:1.5rem}.rf-h-60{height:15rem}.rf-h-64{height:16rem}.rf-h-8{height:2rem}.rf-h-9{height:2.25rem}.rf-h-\\[620px\\]{height:620px}.rf-h-\\[calc\\(100vh-52px\\)\\]{height:calc(100vh - 52px)}.rf-h-\\[calc\\(100vh-96px\\)\\]{height:calc(100vh - 96px)}.rf-h-\\[var\\(--radix-select-trigger-height\\)\\]{height:var(--radix-select-trigger-height)}.rf-h-fit{height:-moz-fit-content;height:fit-content}.rf-h-full{height:100%}.rf-h-px{height:1px}.\\!rf-max-h-\\[40vh\\]{max-height:40vh!important}.\\!rf-max-h-\\[70\\%\\]{max-height:70%!important}.rf-max-h-32{max-height:8rem}.rf-max-h-96{max-height:24rem}.rf-max-h-\\[500px\\]{max-height:500px}.rf-max-h-\\[90vh\\]{max-height:90vh}.rf-min-h-0{min-height:0}.rf-min-h-\\[200px\\]{min-height:200px}.rf-min-h-\\[620px\\]{min-height:620px}.rf-min-h-\\[calc\\(100vh-240px\\)\\]{min-height:calc(100vh - 240px)}.\\!rf-w-2{width:.5rem!important}.\\!rf-w-2\\.5{width:.625rem!important}.rf-w-1{width:.25rem}.rf-w-1\\/2{width:50%}.rf-w-11{width:2.75rem}.rf-w-11\\/12{width:91.666667%}.rf-w-12{width:3rem}.rf-w-16{width:4rem}.rf-w-2{width:.5rem}.rf-w-2\\.5{width:.625rem}.rf-w-3{width:.75rem}.rf-w-3\\.5{width:.875rem}.rf-w-32{width:8rem}.rf-w-4{width:1rem}.rf-w-5{width:1.25rem}.rf-w-6{width:1.5rem}.rf-w-64{width:16rem}.rf-w-72{width:18rem}.rf-w-8{width:2rem}.rf-w-9{width:2.25rem}.rf-w-96{width:24rem}.rf-w-\\[95\\%\\]{width:95%}.rf-w-fit{width:-moz-fit-content;width:fit-content}.rf-w-full{width:100%}.rf-min-w-10{min-width:2.5rem}.rf-min-w-16{min-width:4rem}.rf-min-w-\\[148px\\]{min-width:148px}.rf-min-w-\\[8rem\\]{min-width:8rem}.rf-min-w-\\[var\\(--radix-select-trigger-width\\)\\]{min-width:var(--radix-select-trigger-width)}.\\!rf-max-w-\\[60vw\\]{max-width:60vw!important}.\\!rf-max-w-\\[660px\\]{max-width:660px!important}.rf-max-w-2xl{max-width:42rem}.rf-max-w-3xl{max-width:48rem}.rf-max-w-5xl{max-width:64rem}.rf-max-w-full{max-width:100%}.rf-max-w-lg{max-width:32rem}.rf-max-w-md{max-width:28rem}.rf-max-w-xl{max-width:36rem}.rf-flex-1{flex:1 1 0%}.rf-flex-shrink-0,.rf-shrink-0{flex-shrink:0}.rf-flex-grow{flex-grow:1}.rf-table-auto{table-layout:auto}.-rf-translate-x-1{--tw-translate-x:-0.25rem}.-rf-translate-x-1,.-rf-translate-x-1\\/2{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.-rf-translate-x-1\\/2{--tw-translate-x:-50%}.-rf-translate-y-1{--tw-translate-y:-0.25rem}.-rf-translate-y-1,.rf--translate-x-1{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rf--translate-x-1{--tw-translate-x:-0.25rem}.rf-translate-x-\\[-50\\%\\]{--tw-translate-x:-50%}.rf-translate-x-\\[-50\\%\\],.rf-translate-y-\\[-50\\%\\]{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rf-translate-y-\\[-50\\%\\]{--tw-translate-y:-50%}.rf-transform{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes rf-pulse{50%{opacity:.5}}.rf-animate-pulse{animation:rf-pulse 2s cubic-bezier(.4,0,.6,1) infinite}@keyframes rf-spin{to{transform:rotate(1turn)}}.rf-animate-spin{animation:rf-spin 1s linear infinite}.rf-cursor-default{cursor:default}.rf-cursor-not-allowed{cursor:not-allowed}.rf-cursor-pointer{cursor:pointer}.rf-select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.rf-grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.rf-grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.rf-flex-row{flex-direction:row}.rf-flex-col{flex-direction:column}.rf-flex-col-reverse{flex-direction:column-reverse}.rf-flex-wrap{flex-wrap:wrap}.rf-place-items-center{place-items:center}.rf-items-start{align-items:flex-start}.rf-items-end{align-items:flex-end}.rf-items-center{align-items:center}.rf-justify-end{justify-content:flex-end}.rf-justify-center{justify-content:center}.rf-justify-between{justify-content:space-between}.rf-gap-0{gap:0}.rf-gap-1{gap:.25rem}.rf-gap-2{gap:.5rem}.rf-gap-3{gap:.75rem}.rf-gap-4{gap:1rem}.rf-gap-5{gap:1.25rem}.rf-gap-6{gap:1.5rem}.rf-gap-8{gap:2rem}.rf-space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-left:calc(.5rem*(1 - var(--tw-space-x-reverse)));margin-right:calc(.5rem*var(--tw-space-x-reverse))}.rf-space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(.5rem*var(--tw-space-y-reverse));margin-top:calc(.5rem*(1 - var(--tw-space-y-reverse)))}.rf-space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(1rem*var(--tw-space-y-reverse));margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)))}.rf-space-y-6>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(1.5rem*var(--tw-space-y-reverse));margin-top:calc(1.5rem*(1 - var(--tw-space-y-reverse)))}.rf-divide-y>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-bottom-width:calc(1px*var(--tw-divide-y-reverse));border-top-width:calc(1px*(1 - var(--tw-divide-y-reverse)))}.rf-overflow-auto{overflow:auto}.rf-overflow-hidden{overflow:hidden}.rf-overflow-visible{overflow:visible}.rf-overflow-x-auto{overflow-x:auto}.\\!rf-overflow-y-auto{overflow-y:auto!important}.rf-overflow-y-auto{overflow-y:auto}.\\!rf-overflow-x-hidden{overflow-x:hidden!important}.rf-overflow-x-hidden{overflow-x:hidden}.rf-overflow-x-clip{overflow-x:clip}.rf-truncate{overflow:hidden;text-overflow:ellipsis}.rf-truncate,.rf-whitespace-nowrap{white-space:nowrap}.rf-whitespace-pre-wrap{white-space:pre-wrap}.rf-break-words{overflow-wrap:break-word}.rf-rounded{border-radius:.25rem}.rf-rounded-2xl{border-radius:1rem}.rf-rounded-full{border-radius:9999px}.rf-rounded-lg{border-radius:var(--radius)}.rf-rounded-md{border-radius:calc(var(--radius) - 2px)}.rf-rounded-sm{border-radius:calc(var(--radius) - 4px)}.rf-rounded-xl{border-radius:.75rem}.rf-border{border-width:1px}.rf-border-b{border-bottom-width:1px}.rf-border-t{border-top-width:1px}.rf-border-blue-200{--tw-border-opacity:1;border-color:rgb(191 219 254/var(--tw-border-opacity,1))}.rf-border-blue-500{--tw-border-opacity:1;border-color:rgb(59 130 246/var(--tw-border-opacity,1))}.rf-border-blue-600{--tw-border-opacity:1;border-color:rgb(37 99 235/var(--tw-border-opacity,1))}.rf-border-gray-200{--tw-border-opacity:1;border-color:rgb(229 231 235/var(--tw-border-opacity,1))}.rf-border-gray-300{--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity,1))}.rf-border-green-200{--tw-border-opacity:1;border-color:rgb(187 247 208/var(--tw-border-opacity,1))}.rf-border-input{border-color:hsl(var(--input))}.rf-border-neutral-200{--tw-border-opacity:1;border-color:rgb(229 229 229/var(--tw-border-opacity,1))}.rf-border-primary{border-color:hsl(var(--primary))}.rf-border-red-200{--tw-border-opacity:1;border-color:rgb(254 202 202/var(--tw-border-opacity,1))}.rf-border-red-500{--tw-border-opacity:1;border-color:rgb(239 68 68/var(--tw-border-opacity,1))}.rf-border-zinc-200{--tw-border-opacity:1;border-color:rgb(228 228 231/var(--tw-border-opacity,1))}.rf-border-zinc-900{--tw-border-opacity:1;border-color:rgb(24 24 27/var(--tw-border-opacity,1))}.rf-bg-background{background-color:hsl(var(--background))}.rf-bg-black{--tw-bg-opacity:1;background-color:rgb(0 0 0/var(--tw-bg-opacity,1))}.rf-bg-black\\/80{background-color:rgba(0,0,0,.8)}.rf-bg-blue-100{--tw-bg-opacity:1;background-color:rgb(219 234 254/var(--tw-bg-opacity,1))}.rf-bg-blue-50{--tw-bg-opacity:1;background-color:rgb(239 246 255/var(--tw-bg-opacity,1))}.rf-bg-blue-500{--tw-bg-opacity:1;background-color:rgb(59 130 246/var(--tw-bg-opacity,1))}.rf-bg-blue-600{--tw-bg-opacity:1;background-color:rgb(37 99 235/var(--tw-bg-opacity,1))}.rf-bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.rf-bg-gray-200{--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity,1))}.rf-bg-gray-300{--tw-bg-opacity:1;background-color:rgb(209 213 219/var(--tw-bg-opacity,1))}.rf-bg-gray-400{--tw-bg-opacity:1;background-color:rgb(156 163 175/var(--tw-bg-opacity,1))}.rf-bg-gray-50{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity,1))}.rf-bg-gray-500{--tw-bg-opacity:1;background-color:rgb(107 114 128/var(--tw-bg-opacity,1))}.rf-bg-gray-700{--tw-bg-opacity:1;background-color:rgb(55 65 81/var(--tw-bg-opacity,1))}.rf-bg-gray-800{--tw-bg-opacity:1;background-color:rgb(31 41 55/var(--tw-bg-opacity,1))}.rf-bg-gray-900{--tw-bg-opacity:1;background-color:rgb(17 24 39/var(--tw-bg-opacity,1))}.rf-bg-green-100{--tw-bg-opacity:1;background-color:rgb(220 252 231/var(--tw-bg-opacity,1))}.rf-bg-green-50{--tw-bg-opacity:1;background-color:rgb(240 253 244/var(--tw-bg-opacity,1))}.rf-bg-muted{background-color:hsl(var(--muted))}.rf-bg-neutral-100{--tw-bg-opacity:1;background-color:rgb(245 245 245/var(--tw-bg-opacity,1))}.rf-bg-neutral-50{--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.rf-bg-neutral-800{--tw-bg-opacity:1;background-color:rgb(38 38 38/var(--tw-bg-opacity,1))}.rf-bg-neutral-900{--tw-bg-opacity:1;background-color:rgb(23 23 23/var(--tw-bg-opacity,1))}.rf-bg-orange-400{--tw-bg-opacity:1;background-color:rgb(251 146 60/var(--tw-bg-opacity,1))}.rf-bg-popover{background-color:hsl(var(--popover))}.rf-bg-red-100{--tw-bg-opacity:1;background-color:rgb(254 226 226/var(--tw-bg-opacity,1))}.rf-bg-red-50{--tw-bg-opacity:1;background-color:rgb(254 242 242/var(--tw-bg-opacity,1))}.rf-bg-red-500{--tw-bg-opacity:1;background-color:rgb(239 68 68/var(--tw-bg-opacity,1))}.rf-bg-red-900{--tw-bg-opacity:1;background-color:rgb(127 29 29/var(--tw-bg-opacity,1))}.rf-bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.rf-bg-yellow-100{--tw-bg-opacity:1;background-color:rgb(254 249 195/var(--tw-bg-opacity,1))}.rf-bg-zinc-100{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.rf-bg-zinc-200{--tw-bg-opacity:1;background-color:rgb(228 228 231/var(--tw-bg-opacity,1))}.rf-bg-zinc-50{--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.rf-bg-zinc-800{--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.rf-bg-zinc-900{--tw-bg-opacity:1;background-color:rgb(24 24 27/var(--tw-bg-opacity,1))}.rf-bg-opacity-50{--tw-bg-opacity:0.5}.rf-fill-current{fill:currentColor}.rf-object-contain{-o-object-fit:contain;object-fit:contain}.\\!rf-p-0{padding:0!important}.rf-p-0{padding:0}.rf-p-1{padding:.25rem}.rf-p-2{padding:.5rem}.rf-p-3{padding:.75rem}.rf-p-4{padding:1rem}.rf-p-5{padding:1.25rem}.rf-p-6{padding:1.5rem}.rf-p-8{padding:2rem}.rf-px-1{padding-left:.25rem;padding-right:.25rem}.rf-px-2{padding-left:.5rem;padding-right:.5rem}.rf-px-3{padding-left:.75rem;padding-right:.75rem}.rf-px-4{padding-left:1rem;padding-right:1rem}.rf-px-6{padding-left:1.5rem;padding-right:1.5rem}.rf-px-8{padding-left:2rem;padding-right:2rem}.rf-py-0{padding-bottom:0;padding-top:0}.rf-py-0\\.5{padding-bottom:.125rem;padding-top:.125rem}.rf-py-1{padding-bottom:.25rem;padding-top:.25rem}.rf-py-1\\.5{padding-bottom:.375rem;padding-top:.375rem}.rf-py-10{padding-bottom:2.5rem;padding-top:2.5rem}.rf-py-12{padding-bottom:3rem;padding-top:3rem}.rf-py-2{padding-bottom:.5rem;padding-top:.5rem}.rf-py-3{padding-bottom:.75rem;padding-top:.75rem}.rf-py-4{padding-bottom:1rem;padding-top:1rem}.rf-py-8{padding-bottom:2rem;padding-top:2rem}.rf-pb-0{padding-bottom:0}.rf-pb-2{padding-bottom:.5rem}.rf-pb-3{padding-bottom:.75rem}.rf-pb-4{padding-bottom:1rem}.rf-pl-2{padding-left:.5rem}.rf-pl-4{padding-left:1rem}.rf-pl-8{padding-left:2rem}.rf-pr-2{padding-right:.5rem}.rf-pt-2{padding-top:.5rem}.rf-pt-4{padding-top:1rem}.rf-text-left{text-align:left}.rf-text-center{text-align:center}.rf-text-right{text-align:right}.rf-font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.rf-text-2xl{font-size:1.5rem;line-height:2rem}.rf-text-3xl{font-size:1.875rem;line-height:2.25rem}.rf-text-\\[8px\\]{font-size:8px}.rf-text-base{font-size:1rem;line-height:1.5rem}.rf-text-lg{font-size:1.125rem;line-height:1.75rem}.rf-text-sm{font-size:.875rem;line-height:1.25rem}.rf-text-xl{font-size:1.25rem;line-height:1.75rem}.rf-text-xs{font-size:.75rem;line-height:1rem}.rf-font-bold{font-weight:700}.rf-font-medium{font-weight:500}.rf-font-semibold{font-weight:600}.rf-capitalize{text-transform:capitalize}.rf-tabular-nums{--tw-numeric-spacing:tabular-nums;font-variant-numeric:var(--tw-ordinal) var(--tw-slashed-zero) var(--tw-numeric-figure) var(--tw-numeric-spacing) var(--tw-numeric-fraction)}.rf-leading-5{line-height:1.25rem}.rf-leading-none{line-height:1}.rf-leading-tight{line-height:1.25}.rf-tracking-widest{letter-spacing:.1em}.rf-text-black{--tw-text-opacity:1;color:rgb(0 0 0/var(--tw-text-opacity,1))}.rf-text-blue-500{--tw-text-opacity:1;color:rgb(59 130 246/var(--tw-text-opacity,1))}.rf-text-blue-600{--tw-text-opacity:1;color:rgb(37 99 235/var(--tw-text-opacity,1))}.rf-text-blue-700{--tw-text-opacity:1;color:rgb(29 78 216/var(--tw-text-opacity,1))}.rf-text-blue-800{--tw-text-opacity:1;color:rgb(30 64 175/var(--tw-text-opacity,1))}.rf-text-blue-900{--tw-text-opacity:1;color:rgb(30 58 138/var(--tw-text-opacity,1))}.rf-text-current{color:currentColor}.rf-text-gray-400{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity,1))}.rf-text-gray-500{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity,1))}.rf-text-gray-600{--tw-text-opacity:1;color:rgb(75 85 99/var(--tw-text-opacity,1))}.rf-text-gray-700{--tw-text-opacity:1;color:rgb(55 65 81/var(--tw-text-opacity,1))}.rf-text-gray-800{--tw-text-opacity:1;color:rgb(31 41 55/var(--tw-text-opacity,1))}.rf-text-gray-900{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity,1))}.rf-text-green-500{--tw-text-opacity:1;color:rgb(34 197 94/var(--tw-text-opacity,1))}.rf-text-green-600{--tw-text-opacity:1;color:rgb(22 163 74/var(--tw-text-opacity,1))}.rf-text-green-700{--tw-text-opacity:1;color:rgb(21 128 61/var(--tw-text-opacity,1))}.rf-text-green-800{--tw-text-opacity:1;color:rgb(22 101 52/var(--tw-text-opacity,1))}.rf-text-green-900{--tw-text-opacity:1;color:rgb(20 83 45/var(--tw-text-opacity,1))}.rf-text-muted-foreground{color:hsl(var(--muted-foreground))}.rf-text-neutral-50{--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.rf-text-neutral-500{--tw-text-opacity:1;color:rgb(115 115 115/var(--tw-text-opacity,1))}.rf-text-neutral-900{--tw-text-opacity:1;color:rgb(23 23 23/var(--tw-text-opacity,1))}.rf-text-neutral-950{--tw-text-opacity:1;color:rgb(10 10 10/var(--tw-text-opacity,1))}.rf-text-popover-foreground{color:hsl(var(--popover-foreground))}.rf-text-red-200{--tw-text-opacity:1;color:rgb(254 202 202/var(--tw-text-opacity,1))}.rf-text-red-300{--tw-text-opacity:1;color:rgb(252 165 165/var(--tw-text-opacity,1))}.rf-text-red-400{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.rf-text-red-500{--tw-text-opacity:1;color:rgb(239 68 68/var(--tw-text-opacity,1))}.rf-text-red-600{--tw-text-opacity:1;color:rgb(220 38 38/var(--tw-text-opacity,1))}.rf-text-red-700{--tw-text-opacity:1;color:rgb(185 28 28/var(--tw-text-opacity,1))}.rf-text-red-800{--tw-text-opacity:1;color:rgb(153 27 27/var(--tw-text-opacity,1))}.rf-text-red-900{--tw-text-opacity:1;color:rgb(127 29 29/var(--tw-text-opacity,1))}.rf-text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.rf-text-yellow-400{--tw-text-opacity:1;color:rgb(250 204 21/var(--tw-text-opacity,1))}.rf-text-yellow-500{--tw-text-opacity:1;color:rgb(234 179 8/var(--tw-text-opacity,1))}.rf-text-yellow-900{--tw-text-opacity:1;color:rgb(113 63 18/var(--tw-text-opacity,1))}.rf-text-zinc-200{--tw-text-opacity:1;color:rgb(228 228 231/var(--tw-text-opacity,1))}.rf-text-zinc-300{--tw-text-opacity:1;color:rgb(212 212 216/var(--tw-text-opacity,1))}.rf-text-zinc-400{--tw-text-opacity:1;color:rgb(161 161 170/var(--tw-text-opacity,1))}.rf-text-zinc-50{--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.rf-text-zinc-500{--tw-text-opacity:1;color:rgb(113 113 122/var(--tw-text-opacity,1))}.rf-text-zinc-900{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.rf-text-zinc-950{--tw-text-opacity:1;color:rgb(9 9 11/var(--tw-text-opacity,1))}.rf-underline{text-decoration-line:underline}.rf-line-through{text-decoration-line:line-through}.rf-underline-offset-4{text-underline-offset:4px}.rf-opacity-0{opacity:0}.rf-opacity-25{opacity:.25}.rf-opacity-30{opacity:.3}.rf-opacity-50{opacity:.5}.rf-opacity-60{opacity:.6}.rf-opacity-75{opacity:.75}.rf-shadow{--tw-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px -1px rgba(0,0,0,.1);--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color)}.rf-shadow,.rf-shadow-lg{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.rf-shadow-lg{--tw-shadow:0 10px 15px -3px rgba(0,0,0,.1),0 4px 6px -4px rgba(0,0,0,.1);--tw-shadow-colored:0 10px 15px -3px var(--tw-shadow-color),0 4px 6px -4px var(--tw-shadow-color)}.rf-shadow-md{--tw-shadow:0 4px 6px -1px rgba(0,0,0,.1),0 2px 4px -2px rgba(0,0,0,.1);--tw-shadow-colored:0 4px 6px -1px var(--tw-shadow-color),0 2px 4px -2px var(--tw-shadow-color)}.rf-shadow-md,.rf-shadow-sm{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.rf-shadow-sm{--tw-shadow:0 1px 2px 0 rgba(0,0,0,.05);--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color)}.rf-outline-none{outline:2px solid transparent;outline-offset:2px}.rf-ring-2{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.rf-ring-blue-500{--tw-ring-opacity:1;--tw-ring-color:rgb(59 130 246/var(--tw-ring-opacity,1))}.rf-ring-primary{--tw-ring-color:hsl(var(--primary))}.rf-ring-offset-background{--tw-ring-offset-color:hsl(var(--background))}.rf-ring-offset-white{--tw-ring-offset-color:#fff}.rf-transition{transition-duration:.15s;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-transition-all{transition-duration:.15s;transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-transition-colors{transition-duration:.15s;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-transition-opacity{transition-duration:.15s;transition-property:opacity;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-duration-200{transition-duration:.2s}.rf-ease-in-out{transition-timing-function:cubic-bezier(.4,0,.2,1)}@keyframes enter{0%{opacity:var(--tw-enter-opacity,1);transform:translate3d(var(--tw-enter-translate-x,0),var(--tw-enter-translate-y,0),0) scale3d(var(--tw-enter-scale,1),var(--tw-enter-scale,1),var(--tw-enter-scale,1)) rotate(var(--tw-enter-rotate,0))}}@keyframes exit{to{opacity:var(--tw-exit-opacity,1);transform:translate3d(var(--tw-exit-translate-x,0),var(--tw-exit-translate-y,0),0) scale3d(var(--tw-exit-scale,1),var(--tw-exit-scale,1),var(--tw-exit-scale,1)) rotate(var(--tw-exit-rotate,0))}}.rf-slide-in-from-left-1{--tw-enter-translate-x:-0.25rem}.rf-slide-out-to-left-1{--tw-exit-translate-x:-0.25rem}.rf-duration-200{animation-duration:.2s}.rf-ease-in-out{animation-timing-function:cubic-bezier(.4,0,.2,1)}.file\\:rf-border-0::file-selector-button{border-width:0}.file\\:rf-bg-transparent::file-selector-button{background-color:transparent}.file\\:rf-text-sm::file-selector-button{font-size:.875rem;line-height:1.25rem}.file\\:rf-font-medium::file-selector-button{font-weight:500}.placeholder\\:rf-text-zinc-500::-moz-placeholder{--tw-text-opacity:1;color:rgb(113 113 122/var(--tw-text-opacity,1))}.placeholder\\:rf-text-zinc-500::placeholder{--tw-text-opacity:1;color:rgb(113 113 122/var(--tw-text-opacity,1))}.hover\\:rf-border-blue-300:hover{--tw-border-opacity:1;border-color:rgb(147 197 253/var(--tw-border-opacity,1))}.hover\\:\\!rf-bg-transparent:hover{background-color:transparent!important}.hover\\:rf-bg-blue-700:hover{--tw-bg-opacity:1;background-color:rgb(29 78 216/var(--tw-bg-opacity,1))}.hover\\:rf-bg-red-500\\/90:hover{background-color:rgba(239,68,68,.9)}.hover\\:rf-bg-zinc-100:hover{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.hover\\:rf-bg-zinc-100\\/80:hover{background-color:hsla(240,5%,96%,.8)}.hover\\:rf-bg-zinc-900\\/90:hover{background-color:rgba(24,24,27,.9)}.hover\\:rf-text-red-400:hover{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.hover\\:rf-text-zinc-900:hover{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.hover\\:rf-underline:hover{text-decoration-line:underline}.focus\\:rf-bg-gray-100:focus{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.focus\\:rf-bg-zinc-100:focus{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.focus\\:rf-text-gray-900:focus{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity,1))}.focus\\:rf-text-zinc-900:focus{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.focus\\:rf-outline-none:focus{outline:2px solid transparent;outline-offset:2px}.focus\\:rf-ring-2:focus{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus\\:rf-ring-ring:focus{--tw-ring-color:hsl(var(--ring))}.focus\\:rf-ring-offset-2:focus{--tw-ring-offset-width:2px}.focus-visible\\:rf-outline-none:focus-visible{outline:2px solid transparent;outline-offset:2px}.focus-visible\\:rf-ring-1:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:rf-ring-2:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:rf-ring-zinc-950:focus-visible{--tw-ring-opacity:1;--tw-ring-color:rgb(9 9 11/var(--tw-ring-opacity,1))}.focus-visible\\:rf-ring-offset-2:focus-visible{--tw-ring-offset-width:2px}.disabled\\:rf-pointer-events-none:disabled{pointer-events:none}.disabled\\:rf-cursor-not-allowed:disabled{cursor:not-allowed}.disabled\\:rf-opacity-50:disabled{opacity:.5}.rf-group\\/bar:hover .group-hover\\/bar\\:rf-opacity-100{opacity:1}.data-\\[disabled\\]\\:rf-pointer-events-none[data-disabled]{pointer-events:none}.data-\\[side\\=bottom\\]\\:rf-translate-y-1[data-side=bottom]{--tw-translate-y:0.25rem}.data-\\[side\\=bottom\\]\\:rf-translate-y-1[data-side=bottom],.data-\\[side\\=left\\]\\:-rf-translate-x-1[data-side=left]{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.data-\\[side\\=left\\]\\:-rf-translate-x-1[data-side=left]{--tw-translate-x:-0.25rem}.data-\\[side\\=right\\]\\:rf-translate-x-1[data-side=right]{--tw-translate-x:0.25rem}.data-\\[side\\=right\\]\\:rf-translate-x-1[data-side=right],.data-\\[side\\=top\\]\\:-rf-translate-y-1[data-side=top]{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.data-\\[side\\=top\\]\\:-rf-translate-y-1[data-side=top]{--tw-translate-y:-0.25rem}.data-\\[state\\=active\\]\\:rf-bg-white[data-state=active]{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.data-\\[state\\=checked\\]\\:rf-bg-zinc-900[data-state=checked]{--tw-bg-opacity:1;background-color:rgb(24 24 27/var(--tw-bg-opacity,1))}.data-\\[state\\=open\\]\\:rf-bg-zinc-100[data-state=open]{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.data-\\[state\\=active\\]\\:rf-text-zinc-950[data-state=active]{--tw-text-opacity:1;color:rgb(9 9 11/var(--tw-text-opacity,1))}.data-\\[state\\=checked\\]\\:rf-text-zinc-50[data-state=checked]{--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.data-\\[disabled\\]\\:rf-opacity-50[data-disabled]{opacity:.5}.data-\\[state\\=active\\]\\:rf-shadow[data-state=active]{--tw-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px -1px rgba(0,0,0,.1);--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.data-\\[state\\=open\\]\\:rf-animate-in[data-state=open]{animation-duration:.15s;animation-name:enter;--tw-enter-opacity:initial;--tw-enter-scale:initial;--tw-enter-rotate:initial;--tw-enter-translate-x:initial;--tw-enter-translate-y:initial}.data-\\[state\\=closed\\]\\:rf-animate-out[data-state=closed]{animation-duration:.15s;animation-name:exit;--tw-exit-opacity:initial;--tw-exit-scale:initial;--tw-exit-rotate:initial;--tw-exit-translate-x:initial;--tw-exit-translate-y:initial}.data-\\[state\\=closed\\]\\:rf-fade-out-0[data-state=closed]{--tw-exit-opacity:0}.data-\\[state\\=open\\]\\:rf-fade-in-0[data-state=open]{--tw-enter-opacity:0}.data-\\[state\\=closed\\]\\:rf-zoom-out-95[data-state=closed]{--tw-exit-scale:.95}.data-\\[state\\=open\\]\\:rf-zoom-in-95[data-state=open]{--tw-enter-scale:.95}.data-\\[side\\=bottom\\]\\:rf-slide-in-from-top-2[data-side=bottom]{--tw-enter-translate-y:-0.5rem}.data-\\[side\\=left\\]\\:rf-slide-in-from-right-2[data-side=left]{--tw-enter-translate-x:0.5rem}.data-\\[side\\=right\\]\\:rf-slide-in-from-left-2[data-side=right]{--tw-enter-translate-x:-0.5rem}.data-\\[side\\=top\\]\\:rf-slide-in-from-bottom-2[data-side=top]{--tw-enter-translate-y:0.5rem}.data-\\[state\\=closed\\]\\:rf-slide-out-to-left-1\\/2[data-state=closed]{--tw-exit-translate-x:-50%}.data-\\[state\\=closed\\]\\:rf-slide-out-to-top-\\[48\\%\\][data-state=closed]{--tw-exit-translate-y:-48%}.data-\\[state\\=open\\]\\:rf-slide-in-from-left-1\\/2[data-state=open]{--tw-enter-translate-x:-50%}.data-\\[state\\=open\\]\\:rf-slide-in-from-top-\\[48\\%\\][data-state=open]{--tw-enter-translate-y:-48%}.dark\\:rf-border-zinc-50:is(.rf-dark *){--tw-border-opacity:1;border-color:rgb(250 250 250/var(--tw-border-opacity,1))}.dark\\:rf-border-zinc-800:is(.rf-dark *){--tw-border-opacity:1;border-color:rgb(39 39 42/var(--tw-border-opacity,1))}.dark\\:rf-bg-red-900:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(127 29 29/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-50:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-800:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-950:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(9 9 11/var(--tw-bg-opacity,1))}.dark\\:rf-text-zinc-400:is(.rf-dark *){--tw-text-opacity:1;color:rgb(161 161 170/var(--tw-text-opacity,1))}.dark\\:rf-text-zinc-50:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:rf-text-zinc-900:is(.rf-dark *){--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.dark\\:rf-placeholder-zinc-400:is(.rf-dark *)::-moz-placeholder{--tw-placeholder-opacity:1;color:rgb(161 161 170/var(--tw-placeholder-opacity,1))}.dark\\:rf-placeholder-zinc-400:is(.rf-dark *)::placeholder{--tw-placeholder-opacity:1;color:rgb(161 161 170/var(--tw-placeholder-opacity,1))}.dark\\:rf-ring-offset-zinc-950:is(.rf-dark *){--tw-ring-offset-color:#09090b}.dark\\:hover\\:rf-bg-red-900\\/90:hover:is(.rf-dark *){background-color:rgba(127,29,29,.9)}.dark\\:hover\\:rf-bg-zinc-50\\/90:hover:is(.rf-dark *){background-color:hsla(0,0%,98%,.9)}.dark\\:hover\\:rf-bg-zinc-800:hover:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:hover\\:rf-bg-zinc-800\\/80:hover:is(.rf-dark *){background-color:rgba(39,39,42,.8)}.dark\\:hover\\:rf-text-zinc-50:hover:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:focus\\:rf-bg-zinc-800:focus:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:focus\\:rf-text-zinc-50:focus:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:focus-visible\\:rf-ring-zinc-300:focus-visible:is(.rf-dark *){--tw-ring-opacity:1;--tw-ring-color:rgb(212 212 216/var(--tw-ring-opacity,1))}.dark\\:data-\\[state\\=active\\]\\:rf-bg-zinc-950[data-state=active]:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(9 9 11/var(--tw-bg-opacity,1))}.dark\\:data-\\[state\\=checked\\]\\:rf-bg-zinc-50[data-state=checked]:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.dark\\:data-\\[state\\=open\\]\\:rf-bg-zinc-800[data-state=open]:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:data-\\[state\\=active\\]\\:rf-text-zinc-50[data-state=active]:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:data-\\[state\\=checked\\]\\:rf-text-zinc-900[data-state=checked]:is(.rf-dark *){--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}@media (min-width:640px){.sm\\:rf-mt-0{margin-top:0}.sm\\:rf-flex-row{flex-direction:row}.sm\\:rf-justify-end{justify-content:flex-end}.sm\\:rf-space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-left:calc(.5rem*(1 - var(--tw-space-x-reverse)));margin-right:calc(.5rem*var(--tw-space-x-reverse))}.sm\\:rf-rounded-lg{border-radius:var(--radius)}.sm\\:rf-text-left{text-align:left}}@media (min-width:768px){.md\\:rf-grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}}.\\[\\&\\>span\\]\\:rf-line-clamp-1>span{display:-webkit-box;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1}.\\[\\&\\>svg\\]\\:rf-size-4>svg{height:1rem;width:1rem}.\\[\\&\\>svg\\]\\:rf-shrink-0>svg{flex-shrink:0}.\\[\\&\\>svg\\]\\:rf-text-red-300>svg{--tw-text-opacity:1;color:rgb(252 165 165/var(--tw-text-opacity,1))}.\\[\\&\\>svg\\]\\:hover\\:rf-text-red-400:hover>svg{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.\\[\\&_svg\\]\\:rf-pointer-events-none svg{pointer-events:none}.\\[\\&_svg\\]\\:rf-size-4 svg{height:1rem;width:1rem}.\\[\\&_svg\\]\\:rf-shrink-0 svg{flex-shrink:0}',G$t=()=>{nt.useEffect(()=>{if(document.querySelector('style[data-styles="tscircuit-runframe"]'))return;const e=document.createElement("style");e.setAttribute("data-styles","tscircuit-runframe"),e.textContent=L$t,document.head.appendChild(e)},[])},K7e=r=>`hsl(${qx.indexOf(r)*137.5%360}, 70%, 50%)`,O$t=({phaseTimings:r})=>{if(!r)return null;const e=Object.values(r).reduce((t,n)=>t+n,0);return Ve.jsxs("div",{className:"rf-space-y-2 rf-w-full rf-px-4",children:[Ve.jsx("div",{className:"rf-relative rf-h-8 rf-flex rf-rounded-sm",children:qx.map(t=>{const n=r[t]||0,i=n/e*100;return Ve.jsx("div",{className:"rf-group/bar rf-relative rf-overflow-visible",style:{width:`${i}%`,backgroundColor:K7e(t)},children:Ve.jsxs("div",{className:"rf-opacity-0 group-hover/bar:rf-opacity-100 rf-transition-opacity rf-absolute rf-bottom-full rf-left-1/2 rf-transform -rf-translate-x-1/2 rf-mb-2 rf-px-2 rf-py-1 rf-text-xs rf-whitespace-nowrap rf-rounded rf-bg-gray-900 rf-text-white rf-pointer-events-none",children:[t,": ",n.toFixed(1),"ms"]})},t)})}),Ve.jsxs("div",{className:"rf-text-xs rf-text-gray-500",children:["Total: ",e.toFixed(2),"ms"]})]})},z$t=({renderLog:r})=>{const[e,t]=nt.useState("chronological");if(!r)return Ve.jsx("div",{className:"rf-p-4 rf-bg-gray-100 rf-rounded-md",children:"No render log, make sure this tab is open when you render (TODO add a rerender button here)"});const n=Object.entries((r==null?void 0:r.phaseTimings)??{});e==="chronological"?n.sort((o,a)=>qx.indexOf(o[0])-qx.indexOf(a[0])):n.sort((o,a)=>a[1]-o[1]);const i=n.reduce((o,[a,s])=>o+s,0);return Ve.jsxs("div",{className:"rf-bg-white",children:[Ve.jsxs("div",{className:"rf-flex rf-justify-between rf-items-center",children:[Ve.jsx("div",{children:"Render Logs"}),Ve.jsxs("div",{className:"rf-mb-4 rf-pr-2 rf-flex rf-text-xs rf-items-center",children:[Ve.jsx("div",{className:"rf-mr-2",children:"Sort by:"}),Ve.jsxs("select",{value:e,onChange:o=>t(o.target.value),className:"rf-px-2 rf-py-1 rf-border rf-rounded rf-text-xs",children:[Ve.jsx("option",{value:"chronological",children:"Phase Order"}),Ve.jsx("option",{value:"longest",children:"Duration"})]})]})]}),Ve.jsx(O$t,{phaseTimings:r.phaseTimings}),Ve.jsxs("table",{className:"rf-w-full rf-text-xs",children:[Ve.jsx("thead",{children:Ve.jsxs("tr",{children:[Ve.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase Order"}),Ve.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase"}),Ve.jsx("th",{className:"rf-text-left rf-p-2",children:"Duration (ms)"})]})}),Ve.jsx("tbody",{children:n.map(([o,a])=>Ve.jsxs("tr",{children:[Ve.jsx("td",{className:"rf-p-2",children:qx.indexOf(o)}),Ve.jsx("td",{className:"rf-p-2",children:o}),Ve.jsx("td",{className:"rf-p-2",children:Ve.jsx("div",{className:"rf-w-8",children:Ve.jsx("div",{className:"rf-h-2 rf-rounded-sm",style:{backgroundColor:K7e(o),width:`${a/i*100}%`}})})}),Ve.jsx("td",{className:"rf-p-2",children:Ve.jsxs("div",{className:"rf-flex w-full",children:[Ve.jsxs("span",{className:"rf-flex-grow",children:[a,"ms"]}),Ve.jsxs("span",{className:"rf-text-gray-500 rf-pr-2",children:[(a/i*100).toFixed(1),"%"]})]})})]},o))})]})]})},H$t="0.0.527",Y$t=["assembly","bom","circuit_json","errors","render_log"],V$t=({code:r,onRunClicked:e=void 0,errorMessage:t,circuitJson:n,autoroutingGraphics:i,showRightHeaderContent:o=!0,showCodeTab:a=!1,codeTabContent:s,showJsonTab:l=!0,showRenderLogTab:c=!0,onActiveTabChange:u,renderLog:A,showImportAndFormatButtons:d=!0,className:f,headerClassName:p,leftHeaderContent:C,readOnly:v,isStreaming:_,autoroutingLog:x,onReportAutoroutingLog:b,isRunningCode:P,hasCodeChangedSinceLastRun:F,onEditEvent:U,editEvents:H,defaultActiveTab:L,autoRotate3dViewerDisabled:j,showSchematicDebugGrid:O=!1,showToggleFullScreen:oe=!0,defaultToFullScreen:te=!1})=>{var Re;G$t();const ie=nt.useMemo(()=>n?n.filter(we=>we&&"error_type"in we||we.type.includes("error")):null,[n]),[pe,Ae]=nt.useState(L??"pcb"),[de,Ie]=nt.useState(te),ge=nt.useCallback(we=>{Ae(we),u==null||u(we)},[u]),Me=()=>{Ie(!de)};nt.useEffect(()=>{t&&ge("errors")},[t]),nt.useEffect(()=>{(pe==="code"||pe==="errors")&&n&&!t&&ge(L??"pcb")},[n]);const Be=nt.useCallback(we=>{window.TSCIRCUIT_3D_OBJECT_REF=we===null?void 0:we},[]);return Ve.jsx("div",{className:Mp("flex flex-col relative rf-overflow-x-hidden",f),children:Ve.jsx("div",{className:Mp("rf-md:sticky rf-md:top-2",de&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-bg-white"),children:Ve.jsxs(OIe,{value:pe,onValueChange:ge,className:"rf-flex-grow rf-flex rf-flex-col",children:[Ve.jsxs("div",{className:Mp("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",p),children:[C,C&&Ve.jsx("div",{className:"rf-flex-grow"}),!C&&P&&Ve.jsx(iD,{className:"rf-w-4 rf-h-4 rf-animate-spin"}),!C&&Ve.jsx("div",{className:"rf-flex-grow"}),A&&A.progress!==1&&Ve.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[A.lastRenderEvent&&Ve.jsx("div",{className:"rf-text-xs rf-text-gray-500",children:((Re=A.lastRenderEvent)==null?void 0:Re.phase)??""}),Ve.jsx("div",{className:"rf-w-4 rf-h-4 rf-bg-blue-500 rf-opacity-50 rf-rounded-full rf-text-white",children:Ve.jsx(iD,{className:"rf-w-4 rf-h-4 rf-animate-spin"})}),Ve.jsxs("div",{className:"rf-text-xs rf-font-bold rf-text-gray-700 rf-tabular-nums",children:[((A.progress??0)*100).toFixed(1),"%"]})]}),o&&Ve.jsxs(cj,{children:[a&&Ve.jsx(uw,{value:"code",children:"Code"}),Ve.jsxs(uw,{value:"pcb",className:"rf-whitespace-nowrap",children:[n&&Ve.jsx("span",{className:Mp("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",F?"rf-bg-gray-500":"rf-bg-blue-500")}),"PCB"]}),Ve.jsxs(uw,{value:"schematic",className:"rf-whitespace-nowrap",children:[n&&Ve.jsx("span",{className:Mp("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",F?"rf-bg-gray-500":"rf-bg-blue-500")}),"Schematic"]}),Ve.jsxs(uw,{value:"cad",children:[n&&Ve.jsx("span",{className:Mp("inline-flex items-center justify-center w-2 h-2 mr-1 text-xs font-bold text-white rounded-full",F?"rf-bg-gray-500":"rf-bg-blue-500")}),"3D"]}),!["pcb","cad","schematic"].includes(pe)&&Ve.jsx(uw,{value:pe,children:GIe(pe)}),Ve.jsxs(Cse,{children:[Ve.jsx(_se,{asChild:!0,children:Ve.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[Ve.jsx(xzt,{className:"rf-w-4 rf-h-4"}),(ie&&ie.length>0||t)&&Ve.jsx("span",{className:"rf-inline-flex rf-absolute rf-top-[6px] rf-right-[4px] rf-items-center rf-justify-center rf-w-1 rf-h-1 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full"})]})}),Ve.jsxs(mG,{className:"rf-*:text-xs",children:[Y$t.map(we=>Ve.jsxs(xB,{onSelect:()=>ge(we),children:[pe!==we&&Ve.jsx(Dke,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),pe===we&&Ve.jsx(Qae,{className:"rf-w-3 rf-h-3"}),Ve.jsx("div",{className:"rf-pr-2",children:GIe(we)}),we==="errors"&&(ie&&ie.length>0||t)&&Ve.jsx("span",{className:"rf-inline-flex rf-items-center rf-justify-center rf-w-3 rf-h-3 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full",children:t?1:ie==null?void 0:ie.length})]},we)),Ve.jsx(xB,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:Ve.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/runframe@",H$t.split(".").map((we,Ke)=>Ke===2?parseInt(we)+1:we).join(".")]})})]})]})]}),oe&&Ve.jsx(UE,{onClick:Me,variant:"ghost",children:de?Ve.jsx(wzt,{size:16}):Ve.jsx(Bzt,{size:16})})]}),a&&Ve.jsx($B,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:Ve.jsx("div",{className:"rf-h-full",children:s})}),Ve.jsx($B,{value:"pcb",children:Ve.jsx("div",{className:Mp("rf-overflow-hidden",de?"rf-h-[calc(100vh-52px)]":"rf-h-[620px]"),children:Ve.jsx(rD,{fallbackRender:({error:we})=>Ve.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ve.jsxs("div",{className:"rf-p-4",children:[Ve.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading PCB viewer"}),Ve.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(we==null?void 0:we.message)||"An unknown error occurred"})]})}),children:n?Ve.jsx(F$t,{focusOnHover:!1,circuitJson:n,debugGraphics:i,containerClassName:Mp("rf-h-full rf-w-full",de?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:we=>{U&&we.forEach(Ke=>U(Ke))}}):Ve.jsx(P9,{onRunClicked:e})})})}),Ve.jsx($B,{value:"assembly",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",de?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(rD,{fallback:Ve.jsx("div",{children:"Error loading Assembly"}),children:n?Ve.jsx($jt,{circuitJson:n,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):Ve.jsx(P9,{onRunClicked:e})})})}),Ve.jsx($B,{value:"schematic",children:Ve.jsx("div",{className:Mp("rf-overflow-auto rf-bg-white",de?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(rD,{fallbackRender:({error:we})=>Ve.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ve.jsxs("div",{className:"rf-p-4",children:[Ve.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Schematic"}),Ve.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(we==null?void 0:we.message)||"An unknown error occurred"})]})}),children:n?Ve.jsx(qjt,{circuitJson:n,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:we=>{U==null||U(we)},debugGrid:O,colorOverrides:{schematic:{background:"transparent"}}}):Ve.jsx(P9,{onRunClicked:e})})})}),Ve.jsx($B,{value:"cad",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",de?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(rD,{FallbackComponent:Azt,children:n?Ve.jsx(czt,{ref:Be,circuitJson:n,autoRotateDisabled:j}):Ve.jsx(P9,{onRunClicked:e})})})}),Ve.jsx($B,{value:"bom",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",de?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(rD,{fallbackRender:({error:we})=>Ve.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ve.jsxs("div",{className:"rf-p-4",children:[Ve.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Bill of Materials"}),Ve.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(we==null?void 0:we.message)||"An unknown error occurred"})]})}),children:n?Ve.jsx(iJt,{circuitJson:n}):Ve.jsx(P9,{onRunClicked:e})})})}),Ve.jsx($B,{value:"circuit_json",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",de?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(rD,{fallback:Ve.jsx("div",{children:"Error loading JSON viewer"}),children:n?Ve.jsx(nJt,{elements:n}):Ve.jsx(P9,{onRunClicked:e})})})}),Ve.jsx($B,{value:"errors",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",de?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:t||ie&&ie.length>0?Ve.jsx(_Kt,{code:r,circuitJsonErrors:ie,errorMessage:t,autoroutingLog:x,onReportAutoroutingLog:b}):Ve.jsx(P9,{onRunClicked:e})})}),c&&Ve.jsx($B,{value:"render_log",children:Ve.jsx(z$t,{renderLog:A})})]})})})};var f7="Dialog",[j7e,J7e]=WS(f7),[K$t,wB]=j7e(f7),W7e=r=>{const{__scopeDialog:e,children:t,open:n,defaultOpen:i,onOpenChange:o,modal:a=!0}=r,s=nt.useRef(null),l=nt.useRef(null),[c,u]=UM({prop:n,defaultProp:i??!1,onChange:o,caller:f7});return Ve.jsx(K$t,{scope:e,triggerRef:s,contentRef:l,contentId:qS(),titleId:qS(),descriptionId:qS(),open:c,onOpenChange:u,onOpenToggle:nt.useCallback(()=>u(A=>!A),[u]),modal:a,children:t})};W7e.displayName=f7;var q7e="DialogTrigger",Z7e=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=wB(q7e,t),o=d1(e,i.triggerRef);return Ve.jsx(Qv.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":pce(i.open),...n,ref:o,onClick:Oh(r.onClick,i.onOpenToggle)})});Z7e.displayName=q7e;var fce="DialogPortal",[j$t,X7e]=j7e(fce,{forceMount:void 0}),$7e=r=>{const{__scopeDialog:e,forceMount:t,children:n,container:i}=r,o=wB(fce,e);return Ve.jsx(j$t,{scope:e,forceMount:t,children:nt.Children.map(n,a=>Ve.jsx(ZB,{present:t||o.open,children:Ve.jsx(ose,{asChild:!0,container:i,children:a})}))})};$7e.displayName=fce;var h7="DialogOverlay",eOe=nt.forwardRef((r,e)=>{const t=X7e(h7,r.__scopeDialog),{forceMount:n=t.forceMount,...i}=r,o=wB(h7,r.__scopeDialog);return o.modal?Ve.jsx(ZB,{present:n||o.open,children:Ve.jsx(W$t,{...i,ref:e})}):null});eOe.displayName=h7;var J$t=kM("DialogOverlay.RemoveScroll"),W$t=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=wB(h7,t);return Ve.jsx(Ase,{as:J$t,allowPinchZoom:!0,shards:[i.contentRef],children:Ve.jsx(Qv.div,{"data-state":pce(i.open),...n,ref:e,style:{pointerEvents:"auto",...n.style}})})}),Y9="DialogContent",tOe=nt.forwardRef((r,e)=>{const t=X7e(Y9,r.__scopeDialog),{forceMount:n=t.forceMount,...i}=r,o=wB(Y9,r.__scopeDialog);return Ve.jsx(ZB,{present:n||o.open,children:o.modal?Ve.jsx(q$t,{...i,ref:e}):Ve.jsx(Z$t,{...i,ref:e})})});tOe.displayName=Y9;var q$t=nt.forwardRef((r,e)=>{const t=wB(Y9,r.__scopeDialog),n=nt.useRef(null),i=d1(e,t.contentRef,n);return nt.useEffect(()=>{const o=n.current;if(o)return kUe(o)},[]),Ve.jsx(nOe,{...r,ref:i,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Oh(r.onCloseAutoFocus,o=>{var a;o.preventDefault(),(a=t.triggerRef.current)==null||a.focus()}),onPointerDownOutside:Oh(r.onPointerDownOutside,o=>{const a=o.detail.originalEvent,s=a.button===0&&a.ctrlKey===!0;(a.button===2||s)&&o.preventDefault()}),onFocusOutside:Oh(r.onFocusOutside,o=>o.preventDefault())})}),Z$t=nt.forwardRef((r,e)=>{const t=wB(Y9,r.__scopeDialog),n=nt.useRef(!1),i=nt.useRef(!1);return Ve.jsx(nOe,{...r,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{var a,s;(a=r.onCloseAutoFocus)==null||a.call(r,o),o.defaultPrevented||(n.current||(s=t.triggerRef.current)==null||s.focus(),o.preventDefault()),n.current=!1,i.current=!1},onInteractOutside:o=>{var l,c;(l=r.onInteractOutside)==null||l.call(r,o),o.defaultPrevented||(n.current=!0,o.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const a=o.target;((c=t.triggerRef.current)==null?void 0:c.contains(a))&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&i.current&&o.preventDefault()}})}),nOe=nt.forwardRef((r,e)=>{const{__scopeDialog:t,trapFocus:n,onOpenAutoFocus:i,onCloseAutoFocus:o,...a}=r,s=wB(Y9,t),l=nt.useRef(null),c=d1(e,l);return Zke(),Ve.jsxs(Ve.Fragment,{children:[Ve.jsx(Yae,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:i,onUnmountAutoFocus:o,children:Ve.jsx(Gae,{role:"dialog",id:s.contentId,"aria-describedby":s.descriptionId,"aria-labelledby":s.titleId,"data-state":pce(s.open),...a,ref:c,onDismiss:()=>s.onOpenChange(!1)})}),Ve.jsxs(Ve.Fragment,{children:[Ve.jsx($$t,{titleId:s.titleId}),Ve.jsx(ten,{contentRef:l,descriptionId:s.descriptionId})]})]})}),hce="DialogTitle",rOe=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=wB(hce,t);return Ve.jsx(Qv.h2,{id:i.titleId,...n,ref:e})});rOe.displayName=hce;var iOe="DialogDescription",oOe=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=wB(iOe,t);return Ve.jsx(Qv.p,{id:i.descriptionId,...n,ref:e})});oOe.displayName=iOe;var aOe="DialogClose",sOe=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=wB(aOe,t);return Ve.jsx(Qv.button,{type:"button",...n,ref:e,onClick:Oh(r.onClick,()=>i.onOpenChange(!1))})});sOe.displayName=aOe;function pce(r){return r?"open":"closed"}var lOe="DialogTitleWarning",[X$t,cOe]=Wpt(lOe,{contentName:Y9,titleName:hce,docsSlug:"dialog"}),$$t=({titleId:r})=>{const e=cOe(lOe),t=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
13497
+ `,onClick:n=>{n.stopPropagation(),t()},children:[Ve.jsx("input",{type:"checkbox",checked:e}),Ve.jsx("span",{style:{color:"#eee"},children:r})]}),T$t=({children:r,elements:e})=>{const[t,n]=J1(L=>[L.is_mouse_over_container,L.setIsMouseOverContainer]),[i,o]=nt.useState(!1),[a,s]=nt.useState(!1),[l,c]=nt.useState(!1),[u,A]=J1(L=>[L.selected_layer,L.selectLayer]),[d,f,p,C,v,_]=J1(L=>[L.in_move_footprint_mode,L.in_draw_trace_mode,L.is_showing_rats_nest,L.is_showing_multiple_traces_length,L.is_showing_autorouting,L.is_showing_drc_errors]),x=J1(L=>L.setEditMode),b=J1(L=>L.setIsShowingRatsNest),P=J1(L=>L.setIsShowingMultipleTracesLength),F=J1(L=>L.setIsShowingAutorouting),U=J1(L=>L.setIsShowingDrcErrors);Kw("1",()=>A("top")),Kw("2",()=>A("bottom")),Kw("3",()=>A("inner1")),Kw("4",()=>A("inner2")),Kw("5",()=>A("inner3")),Kw("6",()=>A("inner4")),Kw("7",()=>A("inner5")),Kw("8",()=>A("inner6"));const H=(e==null?void 0:e.filter(L=>L.type.includes("error")).length)??0;return Ve.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>{n(!0)},onMouseLeave:L=>{n(!1),s(!1)},children:[r,Ve.jsxs("div",{style:{position:"absolute",bottom:4,right:8,pointerEvents:"none",color:"white",fontSize:11,opacity:t?.5:0,transition:"opacity 1s",transitionDelay:"2s",fontFamily:"sans-serif"},children:["@tscircuit/pcb-viewer@",R$t.version]}),Ve.jsxs("div",{style:{position:"absolute",opacity:t?1:0,top:16,left:16,transition:t?"opacity 100ms linear":"opacity 1s linear",zIndex:gx.toolbarOverlay,color:"red",display:"flex",fontSize:12,height:100,fontFamily:"sans-serif"},children:[Ve.jsxs(wD,{onClick:()=>{s(!a)},onMouseLeave:()=>{a&&s(!1)},children:[Ve.jsxs("div",{children:["layer:"," ",Ve.jsx("span",{style:{marginLeft:2,fontWeight:500,color:SD[u]},children:u})]}),a&&Ve.jsx("div",{style:{marginTop:4,minWidth:120},children:ace.map(L=>L.replace(/-/g,"")).map(L=>Ve.jsx(N$t,{name:L,selected:L===u,onClick:()=>{A(L.replace(/-/,""))}},L))})]}),Ve.jsxs(wD,{style:H>0?{color:"red"}:{},onClick:()=>c(!l),onMouseLeave:()=>c(!1),children:[Ve.jsxs("div",{children:[H," errors"]}),l&&Ve.jsx("div",{style:{display:"grid",gridTemplateColumns:"100px 300px"},children:e==null?void 0:e.filter(L=>L.type.includes("error")).map((L,j)=>Ve.jsxs(nt.Fragment,{children:[Ve.jsx("div",{children:L.error_type}),Ve.jsx("div",{children:L.message})]},j))})]}),Ve.jsx(wD,{style:{},onClick:()=>{x(f?"off":"draw_trace")},children:Ve.jsxs("div",{children:[f?"✖ ":"","Edit Traces"]})}),Ve.jsx(wD,{style:{},onClick:()=>{x(d?"off":"move_footprint")},children:Ve.jsxs("div",{children:[d?"✖ ":"","Move Components"]})}),Ve.jsx(wD,{style:{},onClick:()=>{b(!p)},children:Ve.jsxs("div",{children:[p?"✖ ":"","Rats Nest"]})}),Ve.jsx(wD,{onClick:()=>{o(!i)},children:Ve.jsxs("div",{children:[Ve.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:["View"," ",Ve.jsx("span",{style:{fontSize:"8px",transform:i?"rotate(180deg)":"rotate(0)",transition:"transform 0.1s ease",display:"inline-block"},children:"▼"})]}),i&&Ve.jsxs("div",{style:{marginTop:4,minWidth:120},children:[Ve.jsx(dce,{label:"Show All Trace Lengths",checked:C,onClick:()=>{P(!C)}}),Ve.jsx(dce,{label:"Show Autorouting Animation",checked:v,onClick:()=>{F(!v)}}),Ve.jsx(dce,{label:"Show DRC Errors",checked:_,onClick:()=>{U(!_)}})]})]})})]})]})},P$t=r=>{const{transform:e,elements:t}=r,[n,i]=nt.useMemo(()=>{const c=r.elements.flatMap(A=>KXt(A,r.elements)),u=AB(r.elements);return[c,u]},[r.elements]),[o,a]=nt.useState({drawingObjectIdsWithMouseOver:new Set,primitiveIdsInMousedOverNet:[]}),s=nt.useMemo(()=>YXt({primitivesWithoutInteractionMetadata:n,drawingObjectIdsWithMouseOver:o.drawingObjectIdsWithMouseOver,primitiveIdsInMousedOverNet:o.primitiveIdsInMousedOverNet}),[n,o]),l=nt.useCallback(c=>{var d,f;const u=[];for(const p of c)if(p._element){const C=i.getNetConnectedToId("pcb_port_id"in p._element?(d=p._element)==null?void 0:d.pcb_port_id:"pcb_trace_id"in p._element?(f=p._element)==null?void 0:f.pcb_trace_id:"");u.push(...i.getIdsConnectedToNet(C))}const A=new Set(c.map(p=>p._pcb_drawing_object_id));a({drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:u})},[i]);return Ve.jsx(M$t,{elements:t,transform:e,primitives:n,onMouseHoverOverPrimitives:l,children:Ve.jsx(f$t,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:Ve.jsx(m$t,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:Ve.jsx(A$t,{transform:e,focusOnHover:r.focusOnHover,children:Ve.jsx(T$t,{elements:t,children:Ve.jsx(I$t,{transform:e,elements:t,children:Ve.jsx(D$t,{transform:e,soup:t,children:Ve.jsx(c$t,{transform:e,debugGraphics:r.debugGraphics,children:Ve.jsx(u$t,{transform:e,elements:t,children:Ve.jsx(l$t,{transform:e,primitives:s,width:r.width,height:r.height,grid:r.grid})})})})})})})})})})},k$t=Pc(OA(400,300),F1(40,-40)),U$t=({circuitJson:r,debugGraphics:e,height:t=600,initialState:n,allowEditing:i=!0,editEvents:o,onEditEventsChanged:a,focusOnHover:s=!1,clickToInteractEnabled:l=!1})=>{const[c,u]=nt.useState(!l),[A,d]=uce(),[f,p]=nt.useState(k$t),{ref:C,setTransform:v,cancelDrag:_}=HXt({transform:f,onSetTransform:p,enabled:c});let[x,b]=nt.useState([]);x=o??x;const P=nt.useRef(!1),F=nt.useRef(null),U=`${(r==null?void 0:r.length)||0}_${(r==null?void 0:r.editCount)||0}`,H=()=>{const te=(d==null?void 0:d.width)>0?d:{width:500,height:500},{center:ie,width:pe,height:Ae}=j.some(ge=>ge.type.startsWith("pcb_"))?NXt(j.filter(ge=>ge.type.startsWith("pcb_"))):{center:{x:0,y:0},width:.001,height:.001},de=Math.min((te.width??0)/pe,(te.height??0)/Ae,100)*.75,Ie=Pc(OA((te.width??0)/2,(te.height??0)/2),F1(de,-de,0,0),OA(-ie.x,-ie.y));v(Ie)};nt.useEffect(()=>{d!=null&&d.width&&r&&r.length!==0&&(P.current||(H(),P.current=!0))},[r,d]);const L=nt.useMemo(()=>(r==null?void 0:r.filter(te=>te.type.startsWith("pcb_")||te.type.startsWith("source_")))??[],[U]),j=nt.useMemo(()=>$Jt({circuitJson:L,editEvents:x}),[L,x]),O=te=>{b([...x,te]),a==null||a([...x,te])},oe=te=>{const ie=x.map(pe=>pe.edit_event_id===te.edit_event_id?{...pe,...te}:pe);b(ie),a==null||a(ie)};return Ve.jsxs("div",{ref:C,style:{position:"relative"},children:[Ve.jsx("div",{ref:A,children:Ve.jsxs(PXt,{initialState:n,children:[Ve.jsx(P$t,{transform:f,height:t,width:d.width,allowEditing:i,focusOnHover:s,cancelPanDrag:_,onCreateEditEvent:O,onModifyEditEvent:oe,grid:{spacing:1,view_window:{left:0,right:d.width||500,top:t,bottom:0}},elements:j,debugGraphics:e},d.width),Ve.jsx(UXt,{})]})}),l&&!c&&Ve.jsx("div",{onClick:()=>{u(!0),H()},onTouchStart:te=>{const ie=te.touches[0];F.current={x:ie.clientX,y:ie.clientY}},onTouchEnd:te=>{const ie=te.changedTouches[0],pe=F.current;if(!pe)return;const Ae=Math.abs(ie.clientX-pe.x),de=Math.abs(ie.clientY-pe.y);Ae<10&&de<10&&(te.preventDefault(),u(!0),H()),F.current=null},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:gx.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center",touchAction:"pan-x pan-y pinch-zoom"},children:Ve.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",pointerEvents:"none"},children:typeof window<"u"&&("ontouchstart"in window||navigator.maxTouchPoints>0)?"Touch to Interact":"Click to Interact"})})]})};const F$t=({containerClassName:r,...e})=>{const t=nt.useRef(null),[n,i]=nt.useState(620);return nt.useLayoutEffect(()=>{const o=()=>{if(t.current){const s=t.current.clientHeight,l=window.innerHeight;i(Math.min(Math.max(s,620),l))}};o();const a=new ResizeObserver(o);return t.current&&a.observe(t.current),window.addEventListener("resize",o),()=>{a.disconnect(),window.removeEventListener("resize",o)}},[]),Ve.jsx("div",{ref:t,className:r||"rf-w-full rf-h-full",children:Ve.jsx(U$t,{...e,height:n})})},L$t='*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }/*! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com*/*,:after,:before{border:0 solid #e5e7eb;box-sizing:border-box}:after,:before{--tw-content:""}:host,html{line-height:1.5;-webkit-text-size-adjust:100%;font-family:ui-sans-serif,system-ui,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-tap-highlight-color:transparent}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-size:1em;font-variation-settings:normal}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{color:inherit;font-family:inherit;font-feature-settings:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;letter-spacing:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{color:#9ca3af;opacity:1}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]:where(:not([hidden=until-found])){display:none}:root{--radius:0.5rem}.rf-pointer-events-none{pointer-events:none}.rf-invisible{visibility:hidden}.rf-fixed{position:fixed}.rf-absolute{position:absolute}.rf-relative{position:relative}.rf-inset-0{inset:0}.-rf-left-2{left:-.5rem}.-rf-right-10{right:-2.5rem}.-rf-right-2{right:-.5rem}.-rf-right-4{right:-1rem}.-rf-right-6{right:-1.5rem}.-rf-right-7{right:-1.75rem}.-rf-right-8{right:-2rem}.-rf-right-9{right:-2.25rem}.rf-bottom-full{bottom:100%}.rf-left-0{left:0}.rf-left-1{left:.25rem}.rf-left-1\\/2{left:50%}.rf-left-2{left:.5rem}.rf-left-\\[50\\%\\]{left:50%}.rf-right-0{right:0}.rf-right-4{right:1rem}.rf-right-\\[4px\\]{right:4px}.rf-top-0{top:0}.rf-top-1{top:.25rem}.rf-top-2{top:.5rem}.rf-top-2\\.5{top:.625rem}.rf-top-\\[50\\%\\]{top:50%}.rf-top-\\[6px\\]{top:6px}.rf-z-50{z-index:50}.rf-z-\\[100\\]{z-index:100}.-rf-mx-1,.rf--mx-1{margin-left:-.25rem;margin-right:-.25rem}.rf-mx-1{margin-left:.25rem;margin-right:.25rem}.rf-mx-2{margin-left:.5rem;margin-right:.5rem}.rf-mx-auto{margin-left:auto;margin-right:auto}.rf-my-1{margin-bottom:.25rem;margin-top:.25rem}.rf-my-12{margin-bottom:3rem;margin-top:3rem}.rf-my-4{margin-bottom:1rem;margin-top:1rem}.rf-my-auto{margin-bottom:auto;margin-top:auto}.rf-mb-1{margin-bottom:.25rem}.rf-mb-12{margin-bottom:3rem}.rf-mb-2{margin-bottom:.5rem}.rf-mb-3{margin-bottom:.75rem}.rf-mb-4{margin-bottom:1rem}.rf-mb-6{margin-bottom:1.5rem}.rf-mb-8{margin-bottom:2rem}.rf-ml-1{margin-left:.25rem}.rf-ml-2{margin-left:.5rem}.rf-ml-auto{margin-left:auto}.rf-mr-1{margin-right:.25rem}.rf-mr-2{margin-right:.5rem}.rf-mt-0{margin-top:0}.rf-mt-0\\.5{margin-top:.125rem}.rf-mt-1{margin-top:.25rem}.rf-mt-2{margin-top:.5rem}.rf-mt-3{margin-top:.75rem}.rf-mt-4{margin-top:1rem}.rf-mt-5{margin-top:1.25rem}.rf-mt-auto{margin-top:auto}.rf-block{display:block}.rf-inline{display:inline}.rf-flex{display:flex}.rf-inline-flex{display:inline-flex}.rf-grid{display:grid}.rf-hidden{display:none}.rf-aspect-square{aspect-ratio:1/1}.rf-aspect-video{aspect-ratio:16/9}.rf-size-14{height:3.5rem;width:3.5rem}.rf-size-4{height:1rem;width:1rem}.\\!rf-h-2{height:.5rem!important}.\\!rf-h-2\\.5{height:.625rem!important}.\\!rf-h-3{height:.75rem!important}.\\!rf-h-full{height:100%!important}.rf-h-1{height:.25rem}.rf-h-10{height:2.5rem}.rf-h-12{height:3rem}.rf-h-2{height:.5rem}.rf-h-2\\.5{height:.625rem}.rf-h-3{height:.75rem}.rf-h-3\\.5{height:.875rem}.rf-h-4{height:1rem}.rf-h-5{height:1.25rem}.rf-h-6{height:1.5rem}.rf-h-60{height:15rem}.rf-h-64{height:16rem}.rf-h-8{height:2rem}.rf-h-9{height:2.25rem}.rf-h-\\[620px\\]{height:620px}.rf-h-\\[calc\\(100vh-52px\\)\\]{height:calc(100vh - 52px)}.rf-h-\\[calc\\(100vh-96px\\)\\]{height:calc(100vh - 96px)}.rf-h-\\[var\\(--radix-select-trigger-height\\)\\]{height:var(--radix-select-trigger-height)}.rf-h-fit{height:-moz-fit-content;height:fit-content}.rf-h-full{height:100%}.rf-h-px{height:1px}.\\!rf-max-h-\\[40vh\\]{max-height:40vh!important}.\\!rf-max-h-\\[70\\%\\]{max-height:70%!important}.rf-max-h-32{max-height:8rem}.rf-max-h-96{max-height:24rem}.rf-max-h-\\[500px\\]{max-height:500px}.rf-max-h-\\[90vh\\]{max-height:90vh}.rf-min-h-0{min-height:0}.rf-min-h-\\[200px\\]{min-height:200px}.rf-min-h-\\[620px\\]{min-height:620px}.rf-min-h-\\[calc\\(100vh-240px\\)\\]{min-height:calc(100vh - 240px)}.\\!rf-w-2{width:.5rem!important}.\\!rf-w-2\\.5{width:.625rem!important}.rf-w-1{width:.25rem}.rf-w-1\\/2{width:50%}.rf-w-11{width:2.75rem}.rf-w-11\\/12{width:91.666667%}.rf-w-12{width:3rem}.rf-w-16{width:4rem}.rf-w-2{width:.5rem}.rf-w-2\\.5{width:.625rem}.rf-w-3{width:.75rem}.rf-w-3\\.5{width:.875rem}.rf-w-32{width:8rem}.rf-w-4{width:1rem}.rf-w-5{width:1.25rem}.rf-w-6{width:1.5rem}.rf-w-64{width:16rem}.rf-w-72{width:18rem}.rf-w-8{width:2rem}.rf-w-9{width:2.25rem}.rf-w-96{width:24rem}.rf-w-\\[95\\%\\]{width:95%}.rf-w-fit{width:-moz-fit-content;width:fit-content}.rf-w-full{width:100%}.rf-min-w-10{min-width:2.5rem}.rf-min-w-16{min-width:4rem}.rf-min-w-\\[148px\\]{min-width:148px}.rf-min-w-\\[8rem\\]{min-width:8rem}.rf-min-w-\\[var\\(--radix-select-trigger-width\\)\\]{min-width:var(--radix-select-trigger-width)}.\\!rf-max-w-\\[60vw\\]{max-width:60vw!important}.\\!rf-max-w-\\[660px\\]{max-width:660px!important}.rf-max-w-2xl{max-width:42rem}.rf-max-w-3xl{max-width:48rem}.rf-max-w-5xl{max-width:64rem}.rf-max-w-full{max-width:100%}.rf-max-w-lg{max-width:32rem}.rf-max-w-md{max-width:28rem}.rf-max-w-xl{max-width:36rem}.rf-flex-1{flex:1 1 0%}.rf-flex-shrink-0,.rf-shrink-0{flex-shrink:0}.rf-flex-grow{flex-grow:1}.rf-table-auto{table-layout:auto}.-rf-translate-x-1{--tw-translate-x:-0.25rem}.-rf-translate-x-1,.-rf-translate-x-1\\/2{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.-rf-translate-x-1\\/2{--tw-translate-x:-50%}.-rf-translate-y-1{--tw-translate-y:-0.25rem}.-rf-translate-y-1,.rf--translate-x-1{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rf--translate-x-1{--tw-translate-x:-0.25rem}.rf-translate-x-\\[-50\\%\\]{--tw-translate-x:-50%}.rf-translate-x-\\[-50\\%\\],.rf-translate-y-\\[-50\\%\\]{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rf-translate-y-\\[-50\\%\\]{--tw-translate-y:-50%}.rf-transform{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes rf-pulse{50%{opacity:.5}}.rf-animate-pulse{animation:rf-pulse 2s cubic-bezier(.4,0,.6,1) infinite}@keyframes rf-spin{to{transform:rotate(1turn)}}.rf-animate-spin{animation:rf-spin 1s linear infinite}.rf-cursor-default{cursor:default}.rf-cursor-not-allowed{cursor:not-allowed}.rf-cursor-pointer{cursor:pointer}.rf-select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.rf-grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.rf-grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.rf-flex-row{flex-direction:row}.rf-flex-col{flex-direction:column}.rf-flex-col-reverse{flex-direction:column-reverse}.rf-flex-wrap{flex-wrap:wrap}.rf-place-items-center{place-items:center}.rf-items-start{align-items:flex-start}.rf-items-end{align-items:flex-end}.rf-items-center{align-items:center}.rf-justify-end{justify-content:flex-end}.rf-justify-center{justify-content:center}.rf-justify-between{justify-content:space-between}.rf-gap-0{gap:0}.rf-gap-1{gap:.25rem}.rf-gap-2{gap:.5rem}.rf-gap-3{gap:.75rem}.rf-gap-4{gap:1rem}.rf-gap-5{gap:1.25rem}.rf-gap-6{gap:1.5rem}.rf-gap-8{gap:2rem}.rf-space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-left:calc(.5rem*(1 - var(--tw-space-x-reverse)));margin-right:calc(.5rem*var(--tw-space-x-reverse))}.rf-space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(.5rem*var(--tw-space-y-reverse));margin-top:calc(.5rem*(1 - var(--tw-space-y-reverse)))}.rf-space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(1rem*var(--tw-space-y-reverse));margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)))}.rf-space-y-6>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(1.5rem*var(--tw-space-y-reverse));margin-top:calc(1.5rem*(1 - var(--tw-space-y-reverse)))}.rf-divide-y>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-bottom-width:calc(1px*var(--tw-divide-y-reverse));border-top-width:calc(1px*(1 - var(--tw-divide-y-reverse)))}.rf-overflow-auto{overflow:auto}.rf-overflow-hidden{overflow:hidden}.rf-overflow-visible{overflow:visible}.rf-overflow-x-auto{overflow-x:auto}.\\!rf-overflow-y-auto{overflow-y:auto!important}.rf-overflow-y-auto{overflow-y:auto}.\\!rf-overflow-x-hidden{overflow-x:hidden!important}.rf-overflow-x-hidden{overflow-x:hidden}.rf-overflow-x-clip{overflow-x:clip}.rf-truncate{overflow:hidden;text-overflow:ellipsis}.rf-truncate,.rf-whitespace-nowrap{white-space:nowrap}.rf-whitespace-pre-wrap{white-space:pre-wrap}.rf-break-words{overflow-wrap:break-word}.rf-rounded{border-radius:.25rem}.rf-rounded-2xl{border-radius:1rem}.rf-rounded-full{border-radius:9999px}.rf-rounded-lg{border-radius:var(--radius)}.rf-rounded-md{border-radius:calc(var(--radius) - 2px)}.rf-rounded-sm{border-radius:calc(var(--radius) - 4px)}.rf-rounded-xl{border-radius:.75rem}.rf-border{border-width:1px}.rf-border-b{border-bottom-width:1px}.rf-border-t{border-top-width:1px}.rf-border-blue-200{--tw-border-opacity:1;border-color:rgb(191 219 254/var(--tw-border-opacity,1))}.rf-border-blue-500{--tw-border-opacity:1;border-color:rgb(59 130 246/var(--tw-border-opacity,1))}.rf-border-blue-600{--tw-border-opacity:1;border-color:rgb(37 99 235/var(--tw-border-opacity,1))}.rf-border-gray-200{--tw-border-opacity:1;border-color:rgb(229 231 235/var(--tw-border-opacity,1))}.rf-border-gray-300{--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity,1))}.rf-border-green-200{--tw-border-opacity:1;border-color:rgb(187 247 208/var(--tw-border-opacity,1))}.rf-border-input{border-color:hsl(var(--input))}.rf-border-neutral-200{--tw-border-opacity:1;border-color:rgb(229 229 229/var(--tw-border-opacity,1))}.rf-border-primary{border-color:hsl(var(--primary))}.rf-border-red-200{--tw-border-opacity:1;border-color:rgb(254 202 202/var(--tw-border-opacity,1))}.rf-border-red-500{--tw-border-opacity:1;border-color:rgb(239 68 68/var(--tw-border-opacity,1))}.rf-border-zinc-200{--tw-border-opacity:1;border-color:rgb(228 228 231/var(--tw-border-opacity,1))}.rf-border-zinc-900{--tw-border-opacity:1;border-color:rgb(24 24 27/var(--tw-border-opacity,1))}.rf-bg-background{background-color:hsl(var(--background))}.rf-bg-black{--tw-bg-opacity:1;background-color:rgb(0 0 0/var(--tw-bg-opacity,1))}.rf-bg-black\\/80{background-color:rgba(0,0,0,.8)}.rf-bg-blue-100{--tw-bg-opacity:1;background-color:rgb(219 234 254/var(--tw-bg-opacity,1))}.rf-bg-blue-50{--tw-bg-opacity:1;background-color:rgb(239 246 255/var(--tw-bg-opacity,1))}.rf-bg-blue-500{--tw-bg-opacity:1;background-color:rgb(59 130 246/var(--tw-bg-opacity,1))}.rf-bg-blue-600{--tw-bg-opacity:1;background-color:rgb(37 99 235/var(--tw-bg-opacity,1))}.rf-bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.rf-bg-gray-200{--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity,1))}.rf-bg-gray-300{--tw-bg-opacity:1;background-color:rgb(209 213 219/var(--tw-bg-opacity,1))}.rf-bg-gray-400{--tw-bg-opacity:1;background-color:rgb(156 163 175/var(--tw-bg-opacity,1))}.rf-bg-gray-50{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity,1))}.rf-bg-gray-500{--tw-bg-opacity:1;background-color:rgb(107 114 128/var(--tw-bg-opacity,1))}.rf-bg-gray-700{--tw-bg-opacity:1;background-color:rgb(55 65 81/var(--tw-bg-opacity,1))}.rf-bg-gray-800{--tw-bg-opacity:1;background-color:rgb(31 41 55/var(--tw-bg-opacity,1))}.rf-bg-gray-900{--tw-bg-opacity:1;background-color:rgb(17 24 39/var(--tw-bg-opacity,1))}.rf-bg-green-100{--tw-bg-opacity:1;background-color:rgb(220 252 231/var(--tw-bg-opacity,1))}.rf-bg-green-50{--tw-bg-opacity:1;background-color:rgb(240 253 244/var(--tw-bg-opacity,1))}.rf-bg-muted{background-color:hsl(var(--muted))}.rf-bg-neutral-100{--tw-bg-opacity:1;background-color:rgb(245 245 245/var(--tw-bg-opacity,1))}.rf-bg-neutral-50{--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.rf-bg-neutral-800{--tw-bg-opacity:1;background-color:rgb(38 38 38/var(--tw-bg-opacity,1))}.rf-bg-neutral-900{--tw-bg-opacity:1;background-color:rgb(23 23 23/var(--tw-bg-opacity,1))}.rf-bg-orange-400{--tw-bg-opacity:1;background-color:rgb(251 146 60/var(--tw-bg-opacity,1))}.rf-bg-popover{background-color:hsl(var(--popover))}.rf-bg-red-100{--tw-bg-opacity:1;background-color:rgb(254 226 226/var(--tw-bg-opacity,1))}.rf-bg-red-50{--tw-bg-opacity:1;background-color:rgb(254 242 242/var(--tw-bg-opacity,1))}.rf-bg-red-500{--tw-bg-opacity:1;background-color:rgb(239 68 68/var(--tw-bg-opacity,1))}.rf-bg-red-900{--tw-bg-opacity:1;background-color:rgb(127 29 29/var(--tw-bg-opacity,1))}.rf-bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.rf-bg-yellow-100{--tw-bg-opacity:1;background-color:rgb(254 249 195/var(--tw-bg-opacity,1))}.rf-bg-zinc-100{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.rf-bg-zinc-200{--tw-bg-opacity:1;background-color:rgb(228 228 231/var(--tw-bg-opacity,1))}.rf-bg-zinc-50{--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.rf-bg-zinc-800{--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.rf-bg-zinc-900{--tw-bg-opacity:1;background-color:rgb(24 24 27/var(--tw-bg-opacity,1))}.rf-bg-opacity-50{--tw-bg-opacity:0.5}.rf-fill-current{fill:currentColor}.rf-object-contain{-o-object-fit:contain;object-fit:contain}.\\!rf-p-0{padding:0!important}.rf-p-0{padding:0}.rf-p-1{padding:.25rem}.rf-p-2{padding:.5rem}.rf-p-3{padding:.75rem}.rf-p-4{padding:1rem}.rf-p-5{padding:1.25rem}.rf-p-6{padding:1.5rem}.rf-p-8{padding:2rem}.rf-px-1{padding-left:.25rem;padding-right:.25rem}.rf-px-2{padding-left:.5rem;padding-right:.5rem}.rf-px-3{padding-left:.75rem;padding-right:.75rem}.rf-px-4{padding-left:1rem;padding-right:1rem}.rf-px-6{padding-left:1.5rem;padding-right:1.5rem}.rf-px-8{padding-left:2rem;padding-right:2rem}.rf-py-0{padding-bottom:0;padding-top:0}.rf-py-0\\.5{padding-bottom:.125rem;padding-top:.125rem}.rf-py-1{padding-bottom:.25rem;padding-top:.25rem}.rf-py-1\\.5{padding-bottom:.375rem;padding-top:.375rem}.rf-py-10{padding-bottom:2.5rem;padding-top:2.5rem}.rf-py-12{padding-bottom:3rem;padding-top:3rem}.rf-py-2{padding-bottom:.5rem;padding-top:.5rem}.rf-py-3{padding-bottom:.75rem;padding-top:.75rem}.rf-py-4{padding-bottom:1rem;padding-top:1rem}.rf-py-8{padding-bottom:2rem;padding-top:2rem}.rf-pb-0{padding-bottom:0}.rf-pb-2{padding-bottom:.5rem}.rf-pb-3{padding-bottom:.75rem}.rf-pb-4{padding-bottom:1rem}.rf-pl-2{padding-left:.5rem}.rf-pl-4{padding-left:1rem}.rf-pl-8{padding-left:2rem}.rf-pr-2{padding-right:.5rem}.rf-pt-2{padding-top:.5rem}.rf-pt-4{padding-top:1rem}.rf-text-left{text-align:left}.rf-text-center{text-align:center}.rf-text-right{text-align:right}.rf-font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.rf-text-2xl{font-size:1.5rem;line-height:2rem}.rf-text-3xl{font-size:1.875rem;line-height:2.25rem}.rf-text-\\[8px\\]{font-size:8px}.rf-text-base{font-size:1rem;line-height:1.5rem}.rf-text-lg{font-size:1.125rem;line-height:1.75rem}.rf-text-sm{font-size:.875rem;line-height:1.25rem}.rf-text-xl{font-size:1.25rem;line-height:1.75rem}.rf-text-xs{font-size:.75rem;line-height:1rem}.rf-font-bold{font-weight:700}.rf-font-medium{font-weight:500}.rf-font-semibold{font-weight:600}.rf-capitalize{text-transform:capitalize}.rf-tabular-nums{--tw-numeric-spacing:tabular-nums;font-variant-numeric:var(--tw-ordinal) var(--tw-slashed-zero) var(--tw-numeric-figure) var(--tw-numeric-spacing) var(--tw-numeric-fraction)}.rf-leading-5{line-height:1.25rem}.rf-leading-none{line-height:1}.rf-leading-tight{line-height:1.25}.rf-tracking-widest{letter-spacing:.1em}.rf-text-black{--tw-text-opacity:1;color:rgb(0 0 0/var(--tw-text-opacity,1))}.rf-text-blue-500{--tw-text-opacity:1;color:rgb(59 130 246/var(--tw-text-opacity,1))}.rf-text-blue-600{--tw-text-opacity:1;color:rgb(37 99 235/var(--tw-text-opacity,1))}.rf-text-blue-700{--tw-text-opacity:1;color:rgb(29 78 216/var(--tw-text-opacity,1))}.rf-text-blue-800{--tw-text-opacity:1;color:rgb(30 64 175/var(--tw-text-opacity,1))}.rf-text-blue-900{--tw-text-opacity:1;color:rgb(30 58 138/var(--tw-text-opacity,1))}.rf-text-current{color:currentColor}.rf-text-gray-400{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity,1))}.rf-text-gray-500{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity,1))}.rf-text-gray-600{--tw-text-opacity:1;color:rgb(75 85 99/var(--tw-text-opacity,1))}.rf-text-gray-700{--tw-text-opacity:1;color:rgb(55 65 81/var(--tw-text-opacity,1))}.rf-text-gray-800{--tw-text-opacity:1;color:rgb(31 41 55/var(--tw-text-opacity,1))}.rf-text-gray-900{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity,1))}.rf-text-green-500{--tw-text-opacity:1;color:rgb(34 197 94/var(--tw-text-opacity,1))}.rf-text-green-600{--tw-text-opacity:1;color:rgb(22 163 74/var(--tw-text-opacity,1))}.rf-text-green-700{--tw-text-opacity:1;color:rgb(21 128 61/var(--tw-text-opacity,1))}.rf-text-green-800{--tw-text-opacity:1;color:rgb(22 101 52/var(--tw-text-opacity,1))}.rf-text-green-900{--tw-text-opacity:1;color:rgb(20 83 45/var(--tw-text-opacity,1))}.rf-text-muted-foreground{color:hsl(var(--muted-foreground))}.rf-text-neutral-50{--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.rf-text-neutral-500{--tw-text-opacity:1;color:rgb(115 115 115/var(--tw-text-opacity,1))}.rf-text-neutral-900{--tw-text-opacity:1;color:rgb(23 23 23/var(--tw-text-opacity,1))}.rf-text-neutral-950{--tw-text-opacity:1;color:rgb(10 10 10/var(--tw-text-opacity,1))}.rf-text-popover-foreground{color:hsl(var(--popover-foreground))}.rf-text-red-200{--tw-text-opacity:1;color:rgb(254 202 202/var(--tw-text-opacity,1))}.rf-text-red-300{--tw-text-opacity:1;color:rgb(252 165 165/var(--tw-text-opacity,1))}.rf-text-red-400{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.rf-text-red-500{--tw-text-opacity:1;color:rgb(239 68 68/var(--tw-text-opacity,1))}.rf-text-red-600{--tw-text-opacity:1;color:rgb(220 38 38/var(--tw-text-opacity,1))}.rf-text-red-700{--tw-text-opacity:1;color:rgb(185 28 28/var(--tw-text-opacity,1))}.rf-text-red-800{--tw-text-opacity:1;color:rgb(153 27 27/var(--tw-text-opacity,1))}.rf-text-red-900{--tw-text-opacity:1;color:rgb(127 29 29/var(--tw-text-opacity,1))}.rf-text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.rf-text-yellow-400{--tw-text-opacity:1;color:rgb(250 204 21/var(--tw-text-opacity,1))}.rf-text-yellow-500{--tw-text-opacity:1;color:rgb(234 179 8/var(--tw-text-opacity,1))}.rf-text-yellow-900{--tw-text-opacity:1;color:rgb(113 63 18/var(--tw-text-opacity,1))}.rf-text-zinc-200{--tw-text-opacity:1;color:rgb(228 228 231/var(--tw-text-opacity,1))}.rf-text-zinc-300{--tw-text-opacity:1;color:rgb(212 212 216/var(--tw-text-opacity,1))}.rf-text-zinc-400{--tw-text-opacity:1;color:rgb(161 161 170/var(--tw-text-opacity,1))}.rf-text-zinc-50{--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.rf-text-zinc-500{--tw-text-opacity:1;color:rgb(113 113 122/var(--tw-text-opacity,1))}.rf-text-zinc-900{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.rf-text-zinc-950{--tw-text-opacity:1;color:rgb(9 9 11/var(--tw-text-opacity,1))}.rf-underline{text-decoration-line:underline}.rf-line-through{text-decoration-line:line-through}.rf-underline-offset-4{text-underline-offset:4px}.rf-opacity-0{opacity:0}.rf-opacity-25{opacity:.25}.rf-opacity-30{opacity:.3}.rf-opacity-50{opacity:.5}.rf-opacity-60{opacity:.6}.rf-opacity-75{opacity:.75}.rf-shadow{--tw-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px -1px rgba(0,0,0,.1);--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color)}.rf-shadow,.rf-shadow-lg{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.rf-shadow-lg{--tw-shadow:0 10px 15px -3px rgba(0,0,0,.1),0 4px 6px -4px rgba(0,0,0,.1);--tw-shadow-colored:0 10px 15px -3px var(--tw-shadow-color),0 4px 6px -4px var(--tw-shadow-color)}.rf-shadow-md{--tw-shadow:0 4px 6px -1px rgba(0,0,0,.1),0 2px 4px -2px rgba(0,0,0,.1);--tw-shadow-colored:0 4px 6px -1px var(--tw-shadow-color),0 2px 4px -2px var(--tw-shadow-color)}.rf-shadow-md,.rf-shadow-sm{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.rf-shadow-sm{--tw-shadow:0 1px 2px 0 rgba(0,0,0,.05);--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color)}.rf-outline-none{outline:2px solid transparent;outline-offset:2px}.rf-ring-2{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.rf-ring-blue-500{--tw-ring-opacity:1;--tw-ring-color:rgb(59 130 246/var(--tw-ring-opacity,1))}.rf-ring-primary{--tw-ring-color:hsl(var(--primary))}.rf-ring-offset-background{--tw-ring-offset-color:hsl(var(--background))}.rf-ring-offset-white{--tw-ring-offset-color:#fff}.rf-transition{transition-duration:.15s;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-transition-all{transition-duration:.15s;transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-transition-colors{transition-duration:.15s;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-transition-opacity{transition-duration:.15s;transition-property:opacity;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-duration-200{transition-duration:.2s}.rf-ease-in-out{transition-timing-function:cubic-bezier(.4,0,.2,1)}@keyframes enter{0%{opacity:var(--tw-enter-opacity,1);transform:translate3d(var(--tw-enter-translate-x,0),var(--tw-enter-translate-y,0),0) scale3d(var(--tw-enter-scale,1),var(--tw-enter-scale,1),var(--tw-enter-scale,1)) rotate(var(--tw-enter-rotate,0))}}@keyframes exit{to{opacity:var(--tw-exit-opacity,1);transform:translate3d(var(--tw-exit-translate-x,0),var(--tw-exit-translate-y,0),0) scale3d(var(--tw-exit-scale,1),var(--tw-exit-scale,1),var(--tw-exit-scale,1)) rotate(var(--tw-exit-rotate,0))}}.rf-slide-in-from-left-1{--tw-enter-translate-x:-0.25rem}.rf-slide-out-to-left-1{--tw-exit-translate-x:-0.25rem}.rf-duration-200{animation-duration:.2s}.rf-ease-in-out{animation-timing-function:cubic-bezier(.4,0,.2,1)}.file\\:rf-border-0::file-selector-button{border-width:0}.file\\:rf-bg-transparent::file-selector-button{background-color:transparent}.file\\:rf-text-sm::file-selector-button{font-size:.875rem;line-height:1.25rem}.file\\:rf-font-medium::file-selector-button{font-weight:500}.placeholder\\:rf-text-zinc-500::-moz-placeholder{--tw-text-opacity:1;color:rgb(113 113 122/var(--tw-text-opacity,1))}.placeholder\\:rf-text-zinc-500::placeholder{--tw-text-opacity:1;color:rgb(113 113 122/var(--tw-text-opacity,1))}.hover\\:rf-border-blue-300:hover{--tw-border-opacity:1;border-color:rgb(147 197 253/var(--tw-border-opacity,1))}.hover\\:\\!rf-bg-transparent:hover{background-color:transparent!important}.hover\\:rf-bg-blue-700:hover{--tw-bg-opacity:1;background-color:rgb(29 78 216/var(--tw-bg-opacity,1))}.hover\\:rf-bg-red-500\\/90:hover{background-color:rgba(239,68,68,.9)}.hover\\:rf-bg-zinc-100:hover{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.hover\\:rf-bg-zinc-100\\/80:hover{background-color:hsla(240,5%,96%,.8)}.hover\\:rf-bg-zinc-900\\/90:hover{background-color:rgba(24,24,27,.9)}.hover\\:rf-text-red-400:hover{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.hover\\:rf-text-zinc-900:hover{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.hover\\:rf-underline:hover{text-decoration-line:underline}.focus\\:rf-bg-gray-100:focus{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.focus\\:rf-bg-zinc-100:focus{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.focus\\:rf-text-gray-900:focus{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity,1))}.focus\\:rf-text-zinc-900:focus{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.focus\\:rf-outline-none:focus{outline:2px solid transparent;outline-offset:2px}.focus\\:rf-ring-2:focus{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus\\:rf-ring-ring:focus{--tw-ring-color:hsl(var(--ring))}.focus\\:rf-ring-offset-2:focus{--tw-ring-offset-width:2px}.focus-visible\\:rf-outline-none:focus-visible{outline:2px solid transparent;outline-offset:2px}.focus-visible\\:rf-ring-1:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:rf-ring-2:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:rf-ring-zinc-950:focus-visible{--tw-ring-opacity:1;--tw-ring-color:rgb(9 9 11/var(--tw-ring-opacity,1))}.focus-visible\\:rf-ring-offset-2:focus-visible{--tw-ring-offset-width:2px}.disabled\\:rf-pointer-events-none:disabled{pointer-events:none}.disabled\\:rf-cursor-not-allowed:disabled{cursor:not-allowed}.disabled\\:rf-opacity-50:disabled{opacity:.5}.rf-group\\/bar:hover .group-hover\\/bar\\:rf-opacity-100{opacity:1}.data-\\[disabled\\]\\:rf-pointer-events-none[data-disabled]{pointer-events:none}.data-\\[side\\=bottom\\]\\:rf-translate-y-1[data-side=bottom]{--tw-translate-y:0.25rem}.data-\\[side\\=bottom\\]\\:rf-translate-y-1[data-side=bottom],.data-\\[side\\=left\\]\\:-rf-translate-x-1[data-side=left]{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.data-\\[side\\=left\\]\\:-rf-translate-x-1[data-side=left]{--tw-translate-x:-0.25rem}.data-\\[side\\=right\\]\\:rf-translate-x-1[data-side=right]{--tw-translate-x:0.25rem}.data-\\[side\\=right\\]\\:rf-translate-x-1[data-side=right],.data-\\[side\\=top\\]\\:-rf-translate-y-1[data-side=top]{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.data-\\[side\\=top\\]\\:-rf-translate-y-1[data-side=top]{--tw-translate-y:-0.25rem}.data-\\[state\\=active\\]\\:rf-bg-white[data-state=active]{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.data-\\[state\\=checked\\]\\:rf-bg-zinc-900[data-state=checked]{--tw-bg-opacity:1;background-color:rgb(24 24 27/var(--tw-bg-opacity,1))}.data-\\[state\\=open\\]\\:rf-bg-zinc-100[data-state=open]{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.data-\\[state\\=active\\]\\:rf-text-zinc-950[data-state=active]{--tw-text-opacity:1;color:rgb(9 9 11/var(--tw-text-opacity,1))}.data-\\[state\\=checked\\]\\:rf-text-zinc-50[data-state=checked]{--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.data-\\[disabled\\]\\:rf-opacity-50[data-disabled]{opacity:.5}.data-\\[state\\=active\\]\\:rf-shadow[data-state=active]{--tw-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px -1px rgba(0,0,0,.1);--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.data-\\[state\\=open\\]\\:rf-animate-in[data-state=open]{animation-duration:.15s;animation-name:enter;--tw-enter-opacity:initial;--tw-enter-scale:initial;--tw-enter-rotate:initial;--tw-enter-translate-x:initial;--tw-enter-translate-y:initial}.data-\\[state\\=closed\\]\\:rf-animate-out[data-state=closed]{animation-duration:.15s;animation-name:exit;--tw-exit-opacity:initial;--tw-exit-scale:initial;--tw-exit-rotate:initial;--tw-exit-translate-x:initial;--tw-exit-translate-y:initial}.data-\\[state\\=closed\\]\\:rf-fade-out-0[data-state=closed]{--tw-exit-opacity:0}.data-\\[state\\=open\\]\\:rf-fade-in-0[data-state=open]{--tw-enter-opacity:0}.data-\\[state\\=closed\\]\\:rf-zoom-out-95[data-state=closed]{--tw-exit-scale:.95}.data-\\[state\\=open\\]\\:rf-zoom-in-95[data-state=open]{--tw-enter-scale:.95}.data-\\[side\\=bottom\\]\\:rf-slide-in-from-top-2[data-side=bottom]{--tw-enter-translate-y:-0.5rem}.data-\\[side\\=left\\]\\:rf-slide-in-from-right-2[data-side=left]{--tw-enter-translate-x:0.5rem}.data-\\[side\\=right\\]\\:rf-slide-in-from-left-2[data-side=right]{--tw-enter-translate-x:-0.5rem}.data-\\[side\\=top\\]\\:rf-slide-in-from-bottom-2[data-side=top]{--tw-enter-translate-y:0.5rem}.data-\\[state\\=closed\\]\\:rf-slide-out-to-left-1\\/2[data-state=closed]{--tw-exit-translate-x:-50%}.data-\\[state\\=closed\\]\\:rf-slide-out-to-top-\\[48\\%\\][data-state=closed]{--tw-exit-translate-y:-48%}.data-\\[state\\=open\\]\\:rf-slide-in-from-left-1\\/2[data-state=open]{--tw-enter-translate-x:-50%}.data-\\[state\\=open\\]\\:rf-slide-in-from-top-\\[48\\%\\][data-state=open]{--tw-enter-translate-y:-48%}.dark\\:rf-border-zinc-50:is(.rf-dark *){--tw-border-opacity:1;border-color:rgb(250 250 250/var(--tw-border-opacity,1))}.dark\\:rf-border-zinc-800:is(.rf-dark *){--tw-border-opacity:1;border-color:rgb(39 39 42/var(--tw-border-opacity,1))}.dark\\:rf-bg-red-900:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(127 29 29/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-50:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-800:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-950:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(9 9 11/var(--tw-bg-opacity,1))}.dark\\:rf-text-zinc-400:is(.rf-dark *){--tw-text-opacity:1;color:rgb(161 161 170/var(--tw-text-opacity,1))}.dark\\:rf-text-zinc-50:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:rf-text-zinc-900:is(.rf-dark *){--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.dark\\:rf-placeholder-zinc-400:is(.rf-dark *)::-moz-placeholder{--tw-placeholder-opacity:1;color:rgb(161 161 170/var(--tw-placeholder-opacity,1))}.dark\\:rf-placeholder-zinc-400:is(.rf-dark *)::placeholder{--tw-placeholder-opacity:1;color:rgb(161 161 170/var(--tw-placeholder-opacity,1))}.dark\\:rf-ring-offset-zinc-950:is(.rf-dark *){--tw-ring-offset-color:#09090b}.dark\\:hover\\:rf-bg-red-900\\/90:hover:is(.rf-dark *){background-color:rgba(127,29,29,.9)}.dark\\:hover\\:rf-bg-zinc-50\\/90:hover:is(.rf-dark *){background-color:hsla(0,0%,98%,.9)}.dark\\:hover\\:rf-bg-zinc-800:hover:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:hover\\:rf-bg-zinc-800\\/80:hover:is(.rf-dark *){background-color:rgba(39,39,42,.8)}.dark\\:hover\\:rf-text-zinc-50:hover:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:focus\\:rf-bg-zinc-800:focus:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:focus\\:rf-text-zinc-50:focus:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:focus-visible\\:rf-ring-zinc-300:focus-visible:is(.rf-dark *){--tw-ring-opacity:1;--tw-ring-color:rgb(212 212 216/var(--tw-ring-opacity,1))}.dark\\:data-\\[state\\=active\\]\\:rf-bg-zinc-950[data-state=active]:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(9 9 11/var(--tw-bg-opacity,1))}.dark\\:data-\\[state\\=checked\\]\\:rf-bg-zinc-50[data-state=checked]:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.dark\\:data-\\[state\\=open\\]\\:rf-bg-zinc-800[data-state=open]:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:data-\\[state\\=active\\]\\:rf-text-zinc-50[data-state=active]:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:data-\\[state\\=checked\\]\\:rf-text-zinc-900[data-state=checked]:is(.rf-dark *){--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}@media (min-width:640px){.sm\\:rf-mt-0{margin-top:0}.sm\\:rf-flex-row{flex-direction:row}.sm\\:rf-justify-end{justify-content:flex-end}.sm\\:rf-space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-left:calc(.5rem*(1 - var(--tw-space-x-reverse)));margin-right:calc(.5rem*var(--tw-space-x-reverse))}.sm\\:rf-rounded-lg{border-radius:var(--radius)}.sm\\:rf-text-left{text-align:left}}@media (min-width:768px){.md\\:rf-grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}}.\\[\\&\\>span\\]\\:rf-line-clamp-1>span{display:-webkit-box;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1}.\\[\\&\\>svg\\]\\:rf-size-4>svg{height:1rem;width:1rem}.\\[\\&\\>svg\\]\\:rf-shrink-0>svg{flex-shrink:0}.\\[\\&\\>svg\\]\\:rf-text-red-300>svg{--tw-text-opacity:1;color:rgb(252 165 165/var(--tw-text-opacity,1))}.\\[\\&\\>svg\\]\\:hover\\:rf-text-red-400:hover>svg{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.\\[\\&_svg\\]\\:rf-pointer-events-none svg{pointer-events:none}.\\[\\&_svg\\]\\:rf-size-4 svg{height:1rem;width:1rem}.\\[\\&_svg\\]\\:rf-shrink-0 svg{flex-shrink:0}',G$t=()=>{nt.useEffect(()=>{if(document.querySelector('style[data-styles="tscircuit-runframe"]'))return;const e=document.createElement("style");e.setAttribute("data-styles","tscircuit-runframe"),e.textContent=L$t,document.head.appendChild(e)},[])},K7e=r=>`hsl(${qx.indexOf(r)*137.5%360}, 70%, 50%)`,O$t=({phaseTimings:r})=>{if(!r)return null;const e=Object.values(r).reduce((t,n)=>t+n,0);return Ve.jsxs("div",{className:"rf-space-y-2 rf-w-full rf-px-4",children:[Ve.jsx("div",{className:"rf-relative rf-h-8 rf-flex rf-rounded-sm",children:qx.map(t=>{const n=r[t]||0,i=n/e*100;return Ve.jsx("div",{className:"rf-group/bar rf-relative rf-overflow-visible",style:{width:`${i}%`,backgroundColor:K7e(t)},children:Ve.jsxs("div",{className:"rf-opacity-0 group-hover/bar:rf-opacity-100 rf-transition-opacity rf-absolute rf-bottom-full rf-left-1/2 rf-transform -rf-translate-x-1/2 rf-mb-2 rf-px-2 rf-py-1 rf-text-xs rf-whitespace-nowrap rf-rounded rf-bg-gray-900 rf-text-white rf-pointer-events-none",children:[t,": ",n.toFixed(1),"ms"]})},t)})}),Ve.jsxs("div",{className:"rf-text-xs rf-text-gray-500",children:["Total: ",e.toFixed(2),"ms"]})]})},z$t=({renderLog:r})=>{const[e,t]=nt.useState("chronological");if(!r)return Ve.jsx("div",{className:"rf-p-4 rf-bg-gray-100 rf-rounded-md",children:"No render log, make sure this tab is open when you render (TODO add a rerender button here)"});const n=Object.entries((r==null?void 0:r.phaseTimings)??{});e==="chronological"?n.sort((o,a)=>qx.indexOf(o[0])-qx.indexOf(a[0])):n.sort((o,a)=>a[1]-o[1]);const i=n.reduce((o,[a,s])=>o+s,0);return Ve.jsxs("div",{className:"rf-bg-white",children:[Ve.jsxs("div",{className:"rf-flex rf-justify-between rf-items-center",children:[Ve.jsx("div",{children:"Render Logs"}),Ve.jsxs("div",{className:"rf-mb-4 rf-pr-2 rf-flex rf-text-xs rf-items-center",children:[Ve.jsx("div",{className:"rf-mr-2",children:"Sort by:"}),Ve.jsxs("select",{value:e,onChange:o=>t(o.target.value),className:"rf-px-2 rf-py-1 rf-border rf-rounded rf-text-xs",children:[Ve.jsx("option",{value:"chronological",children:"Phase Order"}),Ve.jsx("option",{value:"longest",children:"Duration"})]})]})]}),Ve.jsx(O$t,{phaseTimings:r.phaseTimings}),Ve.jsxs("table",{className:"rf-w-full rf-text-xs",children:[Ve.jsx("thead",{children:Ve.jsxs("tr",{children:[Ve.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase Order"}),Ve.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase"}),Ve.jsx("th",{className:"rf-text-left rf-p-2",children:"Duration (ms)"})]})}),Ve.jsx("tbody",{children:n.map(([o,a])=>Ve.jsxs("tr",{children:[Ve.jsx("td",{className:"rf-p-2",children:qx.indexOf(o)}),Ve.jsx("td",{className:"rf-p-2",children:o}),Ve.jsx("td",{className:"rf-p-2",children:Ve.jsx("div",{className:"rf-w-8",children:Ve.jsx("div",{className:"rf-h-2 rf-rounded-sm",style:{backgroundColor:K7e(o),width:`${a/i*100}%`}})})}),Ve.jsx("td",{className:"rf-p-2",children:Ve.jsxs("div",{className:"rf-flex w-full",children:[Ve.jsxs("span",{className:"rf-flex-grow",children:[a,"ms"]}),Ve.jsxs("span",{className:"rf-text-gray-500 rf-pr-2",children:[(a/i*100).toFixed(1),"%"]})]})})]},o))})]})]})},H$t="0.0.528",Y$t=["assembly","bom","circuit_json","errors","render_log"],V$t=({code:r,onRunClicked:e=void 0,errorMessage:t,circuitJson:n,autoroutingGraphics:i,showRightHeaderContent:o=!0,showCodeTab:a=!1,codeTabContent:s,showJsonTab:l=!0,showRenderLogTab:c=!0,onActiveTabChange:u,renderLog:A,showImportAndFormatButtons:d=!0,className:f,headerClassName:p,leftHeaderContent:C,readOnly:v,isStreaming:_,autoroutingLog:x,onReportAutoroutingLog:b,isRunningCode:P,hasCodeChangedSinceLastRun:F,onEditEvent:U,editEvents:H,defaultActiveTab:L,autoRotate3dViewerDisabled:j,showSchematicDebugGrid:O=!1,showToggleFullScreen:oe=!0,defaultToFullScreen:te=!1})=>{var Re;G$t();const ie=nt.useMemo(()=>n?n.filter(we=>we&&"error_type"in we||we.type.includes("error")):null,[n]),[pe,Ae]=nt.useState(L??"pcb"),[de,Ie]=nt.useState(te),ge=nt.useCallback(we=>{Ae(we),u==null||u(we)},[u]),Me=()=>{Ie(!de)};nt.useEffect(()=>{t&&ge("errors")},[t]),nt.useEffect(()=>{(pe==="code"||pe==="errors")&&n&&!t&&ge(L??"pcb")},[n]);const Be=nt.useCallback(we=>{window.TSCIRCUIT_3D_OBJECT_REF=we===null?void 0:we},[]);return Ve.jsx("div",{className:Mp("flex flex-col relative rf-overflow-x-hidden",f),children:Ve.jsx("div",{className:Mp("rf-md:sticky rf-md:top-2",de&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-bg-white"),children:Ve.jsxs(OIe,{value:pe,onValueChange:ge,className:"rf-flex-grow rf-flex rf-flex-col",children:[Ve.jsxs("div",{className:Mp("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",p),children:[C,C&&Ve.jsx("div",{className:"rf-flex-grow"}),!C&&P&&Ve.jsx(iD,{className:"rf-w-4 rf-h-4 rf-animate-spin"}),!C&&Ve.jsx("div",{className:"rf-flex-grow"}),A&&A.progress!==1&&Ve.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[A.lastRenderEvent&&Ve.jsx("div",{className:"rf-text-xs rf-text-gray-500",children:((Re=A.lastRenderEvent)==null?void 0:Re.phase)??""}),Ve.jsx("div",{className:"rf-w-4 rf-h-4 rf-bg-blue-500 rf-opacity-50 rf-rounded-full rf-text-white",children:Ve.jsx(iD,{className:"rf-w-4 rf-h-4 rf-animate-spin"})}),Ve.jsxs("div",{className:"rf-text-xs rf-font-bold rf-text-gray-700 rf-tabular-nums",children:[((A.progress??0)*100).toFixed(1),"%"]})]}),o&&Ve.jsxs(cj,{children:[a&&Ve.jsx(uw,{value:"code",children:"Code"}),Ve.jsxs(uw,{value:"pcb",className:"rf-whitespace-nowrap",children:[n&&Ve.jsx("span",{className:Mp("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",F?"rf-bg-gray-500":"rf-bg-blue-500")}),"PCB"]}),Ve.jsxs(uw,{value:"schematic",className:"rf-whitespace-nowrap",children:[n&&Ve.jsx("span",{className:Mp("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",F?"rf-bg-gray-500":"rf-bg-blue-500")}),"Schematic"]}),Ve.jsxs(uw,{value:"cad",children:[n&&Ve.jsx("span",{className:Mp("inline-flex items-center justify-center w-2 h-2 mr-1 text-xs font-bold text-white rounded-full",F?"rf-bg-gray-500":"rf-bg-blue-500")}),"3D"]}),!["pcb","cad","schematic"].includes(pe)&&Ve.jsx(uw,{value:pe,children:GIe(pe)}),Ve.jsxs(Cse,{children:[Ve.jsx(_se,{asChild:!0,children:Ve.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[Ve.jsx(xzt,{className:"rf-w-4 rf-h-4"}),(ie&&ie.length>0||t)&&Ve.jsx("span",{className:"rf-inline-flex rf-absolute rf-top-[6px] rf-right-[4px] rf-items-center rf-justify-center rf-w-1 rf-h-1 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full"})]})}),Ve.jsxs(mG,{className:"rf-*:text-xs",children:[Y$t.map(we=>Ve.jsxs(xB,{onSelect:()=>ge(we),children:[pe!==we&&Ve.jsx(Dke,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),pe===we&&Ve.jsx(Qae,{className:"rf-w-3 rf-h-3"}),Ve.jsx("div",{className:"rf-pr-2",children:GIe(we)}),we==="errors"&&(ie&&ie.length>0||t)&&Ve.jsx("span",{className:"rf-inline-flex rf-items-center rf-justify-center rf-w-3 rf-h-3 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full",children:t?1:ie==null?void 0:ie.length})]},we)),Ve.jsx(xB,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:Ve.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/runframe@",H$t.split(".").map((we,Ke)=>Ke===2?parseInt(we)+1:we).join(".")]})})]})]})]}),oe&&Ve.jsx(UE,{onClick:Me,variant:"ghost",children:de?Ve.jsx(wzt,{size:16}):Ve.jsx(Bzt,{size:16})})]}),a&&Ve.jsx($B,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:Ve.jsx("div",{className:"rf-h-full",children:s})}),Ve.jsx($B,{value:"pcb",children:Ve.jsx("div",{className:Mp("rf-overflow-hidden",de?"rf-h-[calc(100vh-52px)]":"rf-h-[620px]"),children:Ve.jsx(rD,{fallbackRender:({error:we})=>Ve.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ve.jsxs("div",{className:"rf-p-4",children:[Ve.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading PCB viewer"}),Ve.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(we==null?void 0:we.message)||"An unknown error occurred"})]})}),children:n?Ve.jsx(F$t,{focusOnHover:!1,circuitJson:n,debugGraphics:i,containerClassName:Mp("rf-h-full rf-w-full",de?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:we=>{U&&we.forEach(Ke=>U(Ke))}}):Ve.jsx(P9,{onRunClicked:e})})})}),Ve.jsx($B,{value:"assembly",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",de?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(rD,{fallback:Ve.jsx("div",{children:"Error loading Assembly"}),children:n?Ve.jsx($jt,{circuitJson:n,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):Ve.jsx(P9,{onRunClicked:e})})})}),Ve.jsx($B,{value:"schematic",children:Ve.jsx("div",{className:Mp("rf-overflow-auto rf-bg-white",de?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(rD,{fallbackRender:({error:we})=>Ve.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ve.jsxs("div",{className:"rf-p-4",children:[Ve.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Schematic"}),Ve.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(we==null?void 0:we.message)||"An unknown error occurred"})]})}),children:n?Ve.jsx(qjt,{circuitJson:n,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:we=>{U==null||U(we)},debugGrid:O,colorOverrides:{schematic:{background:"transparent"}}}):Ve.jsx(P9,{onRunClicked:e})})})}),Ve.jsx($B,{value:"cad",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",de?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(rD,{FallbackComponent:Azt,children:n?Ve.jsx(czt,{ref:Be,circuitJson:n,autoRotateDisabled:j}):Ve.jsx(P9,{onRunClicked:e})})})}),Ve.jsx($B,{value:"bom",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",de?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(rD,{fallbackRender:({error:we})=>Ve.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ve.jsxs("div",{className:"rf-p-4",children:[Ve.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Bill of Materials"}),Ve.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(we==null?void 0:we.message)||"An unknown error occurred"})]})}),children:n?Ve.jsx(iJt,{circuitJson:n}):Ve.jsx(P9,{onRunClicked:e})})})}),Ve.jsx($B,{value:"circuit_json",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",de?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(rD,{fallback:Ve.jsx("div",{children:"Error loading JSON viewer"}),children:n?Ve.jsx(nJt,{elements:n}):Ve.jsx(P9,{onRunClicked:e})})})}),Ve.jsx($B,{value:"errors",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",de?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:t||ie&&ie.length>0?Ve.jsx(_Kt,{code:r,circuitJsonErrors:ie,errorMessage:t,autoroutingLog:x,onReportAutoroutingLog:b}):Ve.jsx(P9,{onRunClicked:e})})}),c&&Ve.jsx($B,{value:"render_log",children:Ve.jsx(z$t,{renderLog:A})})]})})})};var f7="Dialog",[j7e,J7e]=WS(f7),[K$t,wB]=j7e(f7),W7e=r=>{const{__scopeDialog:e,children:t,open:n,defaultOpen:i,onOpenChange:o,modal:a=!0}=r,s=nt.useRef(null),l=nt.useRef(null),[c,u]=UM({prop:n,defaultProp:i??!1,onChange:o,caller:f7});return Ve.jsx(K$t,{scope:e,triggerRef:s,contentRef:l,contentId:qS(),titleId:qS(),descriptionId:qS(),open:c,onOpenChange:u,onOpenToggle:nt.useCallback(()=>u(A=>!A),[u]),modal:a,children:t})};W7e.displayName=f7;var q7e="DialogTrigger",Z7e=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=wB(q7e,t),o=d1(e,i.triggerRef);return Ve.jsx(Qv.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":pce(i.open),...n,ref:o,onClick:Oh(r.onClick,i.onOpenToggle)})});Z7e.displayName=q7e;var fce="DialogPortal",[j$t,X7e]=j7e(fce,{forceMount:void 0}),$7e=r=>{const{__scopeDialog:e,forceMount:t,children:n,container:i}=r,o=wB(fce,e);return Ve.jsx(j$t,{scope:e,forceMount:t,children:nt.Children.map(n,a=>Ve.jsx(ZB,{present:t||o.open,children:Ve.jsx(ose,{asChild:!0,container:i,children:a})}))})};$7e.displayName=fce;var h7="DialogOverlay",eOe=nt.forwardRef((r,e)=>{const t=X7e(h7,r.__scopeDialog),{forceMount:n=t.forceMount,...i}=r,o=wB(h7,r.__scopeDialog);return o.modal?Ve.jsx(ZB,{present:n||o.open,children:Ve.jsx(W$t,{...i,ref:e})}):null});eOe.displayName=h7;var J$t=kM("DialogOverlay.RemoveScroll"),W$t=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=wB(h7,t);return Ve.jsx(Ase,{as:J$t,allowPinchZoom:!0,shards:[i.contentRef],children:Ve.jsx(Qv.div,{"data-state":pce(i.open),...n,ref:e,style:{pointerEvents:"auto",...n.style}})})}),Y9="DialogContent",tOe=nt.forwardRef((r,e)=>{const t=X7e(Y9,r.__scopeDialog),{forceMount:n=t.forceMount,...i}=r,o=wB(Y9,r.__scopeDialog);return Ve.jsx(ZB,{present:n||o.open,children:o.modal?Ve.jsx(q$t,{...i,ref:e}):Ve.jsx(Z$t,{...i,ref:e})})});tOe.displayName=Y9;var q$t=nt.forwardRef((r,e)=>{const t=wB(Y9,r.__scopeDialog),n=nt.useRef(null),i=d1(e,t.contentRef,n);return nt.useEffect(()=>{const o=n.current;if(o)return kUe(o)},[]),Ve.jsx(nOe,{...r,ref:i,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Oh(r.onCloseAutoFocus,o=>{var a;o.preventDefault(),(a=t.triggerRef.current)==null||a.focus()}),onPointerDownOutside:Oh(r.onPointerDownOutside,o=>{const a=o.detail.originalEvent,s=a.button===0&&a.ctrlKey===!0;(a.button===2||s)&&o.preventDefault()}),onFocusOutside:Oh(r.onFocusOutside,o=>o.preventDefault())})}),Z$t=nt.forwardRef((r,e)=>{const t=wB(Y9,r.__scopeDialog),n=nt.useRef(!1),i=nt.useRef(!1);return Ve.jsx(nOe,{...r,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{var a,s;(a=r.onCloseAutoFocus)==null||a.call(r,o),o.defaultPrevented||(n.current||(s=t.triggerRef.current)==null||s.focus(),o.preventDefault()),n.current=!1,i.current=!1},onInteractOutside:o=>{var l,c;(l=r.onInteractOutside)==null||l.call(r,o),o.defaultPrevented||(n.current=!0,o.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const a=o.target;((c=t.triggerRef.current)==null?void 0:c.contains(a))&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&i.current&&o.preventDefault()}})}),nOe=nt.forwardRef((r,e)=>{const{__scopeDialog:t,trapFocus:n,onOpenAutoFocus:i,onCloseAutoFocus:o,...a}=r,s=wB(Y9,t),l=nt.useRef(null),c=d1(e,l);return Zke(),Ve.jsxs(Ve.Fragment,{children:[Ve.jsx(Yae,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:i,onUnmountAutoFocus:o,children:Ve.jsx(Gae,{role:"dialog",id:s.contentId,"aria-describedby":s.descriptionId,"aria-labelledby":s.titleId,"data-state":pce(s.open),...a,ref:c,onDismiss:()=>s.onOpenChange(!1)})}),Ve.jsxs(Ve.Fragment,{children:[Ve.jsx($$t,{titleId:s.titleId}),Ve.jsx(ten,{contentRef:l,descriptionId:s.descriptionId})]})]})}),hce="DialogTitle",rOe=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=wB(hce,t);return Ve.jsx(Qv.h2,{id:i.titleId,...n,ref:e})});rOe.displayName=hce;var iOe="DialogDescription",oOe=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=wB(iOe,t);return Ve.jsx(Qv.p,{id:i.descriptionId,...n,ref:e})});oOe.displayName=iOe;var aOe="DialogClose",sOe=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=wB(aOe,t);return Ve.jsx(Qv.button,{type:"button",...n,ref:e,onClick:Oh(r.onClick,()=>i.onOpenChange(!1))})});sOe.displayName=aOe;function pce(r){return r?"open":"closed"}var lOe="DialogTitleWarning",[X$t,cOe]=Wpt(lOe,{contentName:Y9,titleName:hce,docsSlug:"dialog"}),$$t=({titleId:r})=>{const e=cOe(lOe),t=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
13498
13498
 
13499
13499
  If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
13500
13500