@tscircuit/eval 0.0.514 → 0.0.515
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blob-url.js +1 -1
- package/dist/webworker/entrypoint.js +1 -1
- package/package.json +3 -2
|
@@ -156,7 +156,7 @@ svg { font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif; }
|
|
|
156
156
|
:is(button, input, select, textarea, optgroup, option)[disabled],
|
|
157
157
|
optgroup[disabled] > option,
|
|
158
158
|
fieldset[disabled]:not(fieldset[disabled] legend:first-of-type *)
|
|
159
|
-
)`,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])"};var Cs=Vt(td(),1);var Z5={};function K5(n,e){return n===Cs.default.falseFunc?Cs.default.falseFunc:t=>e.isTag(t)&&n(t)}function J5(n,e){let t=e.getSiblings(n);if(t.length<=1)return[];let i=t.indexOf(n);return i<0||i===t.length-1?[]:t.slice(i+1).filter(e.isTag)}function q5(n){return{xmlMode:!!n.xmlMode,lowerCaseAttributeNames:!!n.lowerCaseAttributeNames,lowerCaseTags:!!n.lowerCaseTags,quirksMode:!!n.quirksMode,cacheResults:!!n.cacheResults,pseudos:n.pseudos,adapter:n.adapter,equals:n.equals}}var H5=(n,e,t,i,r)=>{let s=r(e,q5(t),i);return s===Cs.default.trueFunc?n:s===Cs.default.falseFunc?Cs.default.falseFunc:o=>s(o)&&n(o)},uw={is:H5,matches:H5,where:H5,not(n,e,t,i,r){let s=r(e,q5(t),i);return s===Cs.default.falseFunc?n:s===Cs.default.trueFunc?Cs.default.falseFunc:o=>!s(o)&&n(o)},has(n,e,t,i,r){let{adapter:s}=t,o=q5(t);o.relativeSelector=!0;let a=e.some(u=>u.some(Pg))?[Z5]:void 0,c=r(e,o,a);if(c===Cs.default.falseFunc)return Cs.default.falseFunc;let l=K5(c,s);if(a&&c!==Cs.default.trueFunc){let{shouldTestNextSiblings:u=!1}=c;return p=>{if(!n(p))return!1;a[0]=p;let d=s.getChildren(p),_=u?[...d,...J5(p,s)]:d;return s.existsOne(l,_)}}return u=>n(u)&&s.existsOne(l,s.getChildren(u))}};function XG(n,e,t,i,r){var s;let{name:o,data:a}=e;if(Array.isArray(a)){if(!(o in uw))throw new Error(`Unknown pseudo-class :${o}(${a})`);return uw[o](n,a,t,i,r)}let c=(s=t.pseudos)===null||s===void 0?void 0:s[o],l=typeof c=="string"?c:W5[o];if(typeof l=="string"){if(a!=null)throw new Error(`Pseudo ${o} doesn't have any arguments`);let u=Sg(l);return uw.is(n,u,t,i,r)}if(typeof c=="function")return G5(c,o,a,1),u=>c(u,a)&&n(u);if(o in Tg)return Tg[o](n,a,t,i);if(o in lw){let u=lw[o];return G5(u,o,a,2),p=>u(p,t,a)&&n(p)}throw new Error(`Unknown pseudo-class :${o}`)}function Q5(n,e){let t=e.getParent(n);return t&&e.isTag(t)?t:null}function UG(n,e,t,i,r){let{adapter:s,equals:o}=t;switch(e.type){case fe.PseudoElement:throw new Error("Pseudo-elements are not supported by css-select");case fe.ColumnCombinator:throw new Error("Column combinators are not yet supported by css-select");case fe.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()),DG[e.action](n,e,t)}case fe.Pseudo:return XG(n,e,t,i,r);case fe.Tag:{if(e.namespace!=null)throw new Error("Namespaced tag names are not yet supported by css-select");let{name:a}=e;return(!t.xmlMode||t.lowerCaseTags)&&(a=a.toLowerCase()),function(l){return s.getName(l)===a&&n(l)}}case fe.Descendant:{if(t.cacheResults===!1||typeof WeakSet>"u")return function(l){let u=l;for(;u=Q5(u,s);)if(n(u))return!0;return!1};let a=new WeakSet;return function(l){let u=l;for(;u=Q5(u,s);)if(!a.has(u)){if(s.isTag(u)&&n(u))return!0;a.add(u)}return!1}}case"_flexibleDescendant":return function(c){let l=c;do if(n(l))return!0;while(l=Q5(l,s));return!1};case fe.Parent:return function(c){return s.getChildren(c).some(l=>s.isTag(l)&&n(l))};case fe.Child:return function(c){let l=s.getParent(c);return l!=null&&s.isTag(l)&&n(l)};case fe.Sibling:return function(c){let l=s.getSiblings(c);for(let u=0;u<l.length;u++){let p=l[u];if(o(c,p))break;if(s.isTag(p)&&n(p))return!0}return!1};case fe.Adjacent:return s.prevElementSibling?function(c){let l=s.prevElementSibling(c);return l!=null&&n(l)}:function(c){let l=s.getSiblings(c),u;for(let p=0;p<l.length;p++){let d=l[p];if(o(c,d))break;s.isTag(d)&&(u=d)}return!!u&&n(u)};case fe.Universal:{if(e.namespace!=null&&e.namespace!=="*")throw new Error("Namespaced universal selectors are not yet supported by css-select");return n}}}function VG(n,e,t){let i=pw(n,e,t);return K5(i,e.adapter)}function pw(n,e,t){let i=typeof n=="string"?Sg(n):n;return hw(i,e,t)}function GG(n){return n.type===fe.Pseudo&&(n.name==="scope"||Array.isArray(n.data)&&n.data.some(e=>e.some(GG)))}var d3t={type:fe.Descendant},f3t={type:"_flexibleDescendant"},m3t={type:fe.Pseudo,name:"scope",data:null};function _3t(n,{adapter:e},t){let i=!!t?.every(r=>{let s=e.isTag(r)&&e.getParent(r);return r===Z5||s&&e.isTag(s)});for(let r of n){if(!(r.length>0&&Pg(r[0])&&r[0].type!==fe.Descendant))if(i&&!r.some(GG))r.unshift(d3t);else continue;r.unshift(m3t)}}function hw(n,e,t){var i;n.forEach(X5),t=(i=e.context)!==null&&i!==void 0?i:t;let r=Array.isArray(t),s=t&&(Array.isArray(t)?t:[t]);if(e.relativeSelector!==!1)_3t(n,e,s);else if(n.some(c=>c.length>0&&Pg(c[0])))throw new Error("Relative selectors are not allowed when the `relativeSelector` option is disabled");let o=!1,a=n.map(c=>{if(c.length>=2){let[l,u]=c;l.type!==fe.Pseudo||l.name!=="scope"||(r&&u.type===fe.Descendant?c[1]=f3t:(u.type===fe.Adjacent||u.type===fe.Sibling)&&(o=!0))}return y3t(c,e,s)}).reduce(g3t,Ra.default.falseFunc);return a.shouldTestNextSiblings=o,a}function y3t(n,e,t){var i;return n.reduce((r,s)=>r===Ra.default.falseFunc?Ra.default.falseFunc:UG(r,s,e,t,hw),(i=e.rootFunc)!==null&&i!==void 0?i:Ra.default.trueFunc)}function g3t(n,e){return e===Ra.default.falseFunc||n===Ra.default.trueFunc?n:n===Ra.default.falseFunc||e===Ra.default.trueFunc?e:function(i){return n(i)||e(i)}}var WG=(n,e)=>n===e,x3t={adapter:aw,equals:WG};function HG(n){var e,t,i,r;let s=n??x3t;return(e=s.adapter)!==null&&e!==void 0||(s.adapter=aw),(t=s.equals)!==null&&t!==void 0||(s.equals=(r=(i=s.adapter)===null||i===void 0?void 0:i.equals)!==null&&r!==void 0?r:WG),s}function e4(n){return function(t,i,r){let s=HG(i);return n(t,s,r)}}var vee=e4(VG),wee=e4(pw),See=e4(hw);function qG(n){return function(t,i,r){let s=HG(r);typeof t!="function"&&(t=pw(t,s,i));let o=b3t(i,s.adapter,t.shouldTestNextSiblings);return n(t,o,s)}}function b3t(n,e,t=!1){return t&&(n=v3t(n,e)),Array.isArray(n)?e.removeSubsets(n):e.getChildren(n)}function v3t(n,e){let t=Array.isArray(n)?n.slice(0):[n],i=t.length;for(let r=0;r<i;r++){let s=J5(t[r],e);t.push(...s)}return t}var n4=qG((n,e,t)=>n===t4.default.falseFunc||!e||e.length===0?[]:t.adapter.findAll(n,e)),dw=qG((n,e,t)=>n===t4.default.falseFunc||!e||e.length===0?null:t.adapter.findOne(n,e));Q();wt();Q();var EW=Vt(In(),1);wt();var IW=Vt(In(),1),AW=Vt(In(),1);wt();si();l4();var u4=(n,e={})=>{let t=n._internal_store;if(!t){t={counts:{}},n._internal_store=t;for(let r of n){let s=r.type,o=r[`${s}_id`];if(!o)continue;let a=Number.parseInt(o.split("_").pop());Number.isNaN(a)||(t.counts[s]=Math.max(t.counts[s]??0,a))}}return new Proxy({},{get:(r,s)=>s==="toArray"?()=>n:{get:o=>n.find(a=>a.type===s&&a[`${s}_id`]===o),getUsing:o=>{let a=Object.keys(o);if(a.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");let c=a[0],l=c.replace("_id",""),u=n.find(p=>p.type===l&&p[c]===o[c]);return u?n.find(p=>p.type===s&&p[`${s}_id`]===u[`${s}_id`]):null},getWhere:o=>{let a=Object.keys(o);return n.find(c=>c.type===s&&a.every(l=>c[l]===o[l]))},list:o=>{let a=o?Object.keys(o):[];return n.filter(c=>c.type===s&&a.every(l=>c[l]===o[l]))},insert:o=>{var l;(l=t.counts)[s]??(l[s]=-1),t.counts[s]++;let a=t.counts[s],c={type:s,[`${s}_id`]:`${s}_${a}`,...o};return e.validateInserts&&(Wh[s]??Gh).parse(c),n.push(c),c},delete:o=>{let a=n.find(c=>c[`${s}_id`]===o);a&&n.splice(n.indexOf(a),1)},update:(o,a)=>{let c=n.find(l=>l[`${s}_id`]===o);if(c)return Object.assign(c,a),c},select:o=>{if(s==="source_component")return n.find(a=>a.type==="source_component"&&a.name===o.replace(/\./g,""));if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){let[a,c]=o.replace(/\./g,"").split(/[\s\>]+/),l=n.find(p=>p.type==="source_component"&&p.name===a);if(!l)return null;let u=n.find(p=>p.type==="source_port"&&p.source_component_id===l.source_component_id&&(p.name===c||(p.port_hints??[]).includes(c)));if(!u)return null;if(s==="source_port")return u;if(s==="pcb_port")return n.find(p=>p.type==="pcb_port"&&p.source_port_id===u.source_port_id);if(s==="schematic_port")return n.find(p=>p.type==="schematic_port"&&p.source_port_id===u.source_port_id)}}}})};u4.unparsed=u4;var lW=u4;var Tie=Vt(pW(),1);ir();function so(n){let e=n.width/2,t=n.height/2;return{minX:n.center.x-e,maxX:n.center.x+e,minY:n.center.y-t,maxY:n.center.y+t}}function Ng(n,e){let t=so(n),i=so(e),r=Math.max(t.minX-i.maxX,i.minX-t.maxX,0),s=Math.max(t.minY-i.maxY,i.minY-t.maxY,0),o={x:0,y:0},a={x:0,y:0};return r===0&&s===0?{distance:0,pointA:n.center,pointB:e.center}:(o.x=Wn(n.center.x,i.minX,i.maxX),o.y=Wn(n.center.y,i.minY,i.maxY),a.x=Wn(e.center.x,t.minX,t.maxX),a.y=Wn(e.center.y,t.minY,t.maxY),{distance:Math.hypot(o.x-a.x,o.y-a.y),pointA:o,pointB:a})}function Fo(n,e){return Ng(n,e)}function m4(n,e){let t=so(n),i=so(e),r=Math.max(t.minX-i.maxX,i.minX-t.maxX,0),s=Math.max(t.minY-i.maxY,i.minY-t.maxY,0);return Math.hypot(r,s)}function Wn(n,e,t){return Math.max(e,Math.min(t,n))}function Ag(n,e){let t=Number.POSITIVE_INFINITY,i={x:0,y:0},r={x:0,y:0};for(let s of n)for(let o of e){let{distance:a,pointA:c,pointB:l}=Ng(s,o);a<t&&(t=a,i=c,r=l)}return{pointA:i,pointB:r,distance:t}}ir();ir();var gW="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var xW=(n=21)=>{let e="",t=crypto.getRandomValues(new Uint8Array(n|=0));for(;n--;)e+=gW[t[n]&63];return e};ir();var ad=(n,e)=>Math.abs(n.x-e.x)+Math.abs(n.y-e.y),bW=(n,e)=>{let t=e.x-n.x,i=e.y-n.y;return Math.abs(t)>Math.abs(i)?{dx:Math.sign(t),dy:0}:{dx:0,dy:Math.sign(i)}},kW=(n,e,t)=>Math.abs(n.x-e.x)*Math.abs(t.dx)+Math.abs(n.y-e.y)*Math.abs(t.dy),TW=(n,e=.1)=>`${Math.round(n.x/e)},${Math.round(n.y/e)}`,vW=(n,e)=>Math.abs(n-e)<1e-4,MW=(n,e,{viaDiameter:t=.5}={})=>{let i=[];for(let r=0;r<n.length-1;r++){let[s,o]=[n[r],n[r+1]],a=r-1>=0?n[r-1]:null,c=vW(s.y,o.y),l=vW(s.x,o.x);if(!c&&!l)throw new Error(`getObstaclesFromTrace currently only supports horizontal and vertical traces (not diagonals) Conflicting trace: ${e}, start: (${s.x}, ${s.y}), end: (${o.x}, ${o.y})`);let u={type:"rect",layers:[s.layer],center:{x:(s.x+o.x)/2,y:(s.y+o.y)/2},width:c?Math.abs(s.x-o.x):.1,height:l?Math.abs(s.y-o.y):.1,connectedTo:[e]};if(i.push(u),a&&a.layer===s.layer&&s.layer!==o.layer){let p={type:"rect",layers:[s.layer,o.layer],center:{x:s.x,y:s.y},connectedTo:[e],width:t,height:t};i.push(p)}}return i},CW=class{constructor(n){f(this,"obstacles");f(this,"GRID_STEP",.1);this.obstacles=n.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(n,e,t){t??(t=this.GRID_STEP);for(let i of this.obstacles){let r=i.width/2+t,s=i.height/2+t;if(n>=i.center.x-r&&n<=i.center.x+r&&e>=i.center.y-s&&e<=i.center.y+s)return i}return null}isObstacleAt(n,e,t){return this.getObstacleAt(n,e,t)!==null}getDirectionDistancesToNearestObstacle(n,e){let{GRID_STEP:t}=this,i={left:1/0,top:1/0,bottom:1/0,right:1/0};for(let r of this.obstacles)if(r.type==="rect"){let s=r.center.x-r.width/2-t,o=r.center.x+r.width/2+t,a=r.center.y+r.height/2+t,c=r.center.y-r.height/2-t;e>=c&&e<=a&&n>s&&(i.left=Math.min(i.left,n-o)),e>=c&&e<=a&&n<o&&(i.right=Math.min(i.right,s-n)),n>=s&&n<=o&&e<a&&(i.top=Math.min(i.top,c-e)),n>=s&&n<=o&&e>c&&(i.bottom=Math.min(i.bottom,e-a))}return i}getOrthoDirectionCollisionInfo(n,e,{margin:t=0}={}){let{x:i,y:r}=n,{dx:s,dy:o}=e,a=1/0,c=null;for(let l of this.obstacles){let u=l.left-t,p=l.right+t,d=l.top+t,_=l.bottom-t,g=null;s===1&&o===0?r>_&&r<d&&i<l.left&&(g=l.left-i):s===-1&&o===0?r>_&&r<d&&i>l.right&&(g=i-l.right):s===0&&o===1?i>u&&i<p&&r<l.bottom&&(g=l.bottom-r):s===0&&o===-1&&i>u&&i<p&&r>l.top&&(g=r-l.top),g!==null&&g<a&&(a=g,c=l)}return{dx:s,dy:o,wallDistance:a,obstacle:c}}getObstaclesOverlappingRegion(n){let e=[];for(let t of this.obstacles){let{left:i,right:r,top:s,bottom:o}=t;i<=n.maxX&&r>=n.minX&&s<=n.maxY&&o>=n.minY&&e.push(t)}return e}};function E3t(n){if(n.length<4)return n;let e=[{...n[0]}],t=n[0].layer;for(let i=1;i<n.length;i++){let r={start:n[i-1],end:n[i]},s=n[i].route_type==="via"||n[i-1].route_type==="via";if(n[i].layer!==t||s){e.push({...n[i]}),t=n[i].layer;continue}let o=!1,a=null,c=-1;for(let u=0;u<e.length-1;u++){let p={start:e[u],end:e[u+1]};if(p.start.layer===r.start.layer&&p.start.layer===r.start.layer){let d=M3t(p,r);if(d){o=!0,a={...d,layer:t},c=u;break}}}o&&a&&(e.splice(c+1),e.push(a));let l=e[e.length-1];(l.x!==n[i].x||l.y!==n[i].y)&&e.push(n[i])}return e}function M3t(n,e){if(n.start.x===n.end.x&&e.start.x===e.end.x||n.start.y===n.end.y&&e.start.y===e.end.y)return null;let t;if(n.start.x===n.end.x){let i=n.start.x,r=e.start.y;t={...n.start,x:i,y:r}}else{let i=e.start.x,r=n.start.y;t={...n.start,x:i,y:r}}return wW(t,n)&&wW(t,e)?t:null}function wW(n,e){return n.x>=Math.min(e.start.x,e.end.x)&&n.x<=Math.max(e.start.x,e.end.x)&&n.y>=Math.min(e.start.y,e.end.y)&&n.y<=Math.max(e.start.y,e.end.y)}function C3t(n){let e=[n[0]];for(let t=1;t<n.length-1;t++){let[i,r,s]=[n[t-1],n[t],n[t+1]];e.push(r),!(r.route_type!=="wire"||i.route_type!=="wire"||s.route_type!=="wire")&&i.layer===r.layer&&r.layer!==s.layer&&e.push({route_type:"via",from_layer:r.layer,to_layer:s.layer,x:r.x,y:r.y})}return e.push(n[n.length-1]),e}var Pie=(0,IW.default)("autorouter:shortenPathWithShortcuts");function I3t(n,e){if(n.length<=2)return n;let t=[n[0]];for(let i=1;i<n.length;i++){let r={start:t[t.length-1],end:n[i]},s=-1,o=r.start.x===r.end.x,a=r.start.y===r.end.y;for(let c=i+1;c<n.length;c++){if(c<=s)continue;let l={start:n[c],end:n[c+1]};if(!l.end)continue;let u=l.start.x===l.end.x,p=l.start.y===l.end.y,d=o&&u,_=a&&p;if(_&&d||!(d||_))continue;let x=!1,v=Math.min(r.start.x,r.end.x),S=Math.max(r.start.x,r.end.x),P=Math.min(l.start.x,l.end.x),T=Math.max(l.start.x,l.end.x),k=Math.min(r.start.y,r.end.y),N=Math.max(r.start.y,r.end.y),E=Math.min(l.start.y,l.end.y),C=Math.max(l.start.y,l.end.y);if(_?x=v<=T&&S>=P:d&&(x=k<=C&&N>=E),!x)continue;let M=[],A=t[t.length-1],R=n[c+2];if(!R)continue;_&&P<S&&R.x===P&&M.push({x:P,y:r.start.y,layer:r.start.layer}),_&&T>v&&R.x===T&&M.push({x:T,y:r.start.y,layer:r.start.layer}),d&&E<N&&R.y===E&&M.push({x:r.start.x,y:E,layer:r.start.layer}),d&&C>k&&R.y===C&&M.push({x:r.start.x,y:C,layer:r.start.layer});let B=null;for(let j of M)if(!(e(A,j)||e(R,j))){B=j;break}if(B){t.push(B),i=c+1,s=c+1;break}}s===-1&&t.push(n[i])}return t[t.length-1]!==n[n.length-1]&&t.push(n[n.length-1]),t}var od=(0,EW.default)("autorouting-dataset:astar"),NW=class{constructor(n){f(this,"openSet",[]);f(this,"closedSet",new Set);f(this,"debug",!1);f(this,"debugSolutions");f(this,"debugMessage",null);f(this,"debugTraceCount",0);f(this,"input");f(this,"obstacles");f(this,"allObstacles");f(this,"startNode");f(this,"goalPoint");f(this,"GRID_STEP");f(this,"OBSTACLE_MARGIN");f(this,"MAX_ITERATIONS");f(this,"isRemovePathLoopsEnabled");f(this,"isShortenPathWithShortcutsEnabled");f(this,"GREEDY_MULTIPLIER",1.1);f(this,"iterations",-1);this.input=n.input,this.allObstacles=n.input.obstacles,this.startNode=n.startNode,this.goalPoint=n.goalPoint?{l:0,...n.goalPoint}:void 0,this.GRID_STEP=n.GRID_STEP??.1,this.OBSTACLE_MARGIN=n.OBSTACLE_MARGIN??.15,this.MAX_ITERATIONS=n.MAX_ITERATIONS??100,this.debug=n.debug??od.enabled,this.isRemovePathLoopsEnabled=n.isRemovePathLoopsEnabled??!1,this.isShortenPathWithShortcutsEnabled=n.isShortenPathWithShortcutsEnabled??!1,this.debug&&(od.enabled=!0),od.enabled&&(this.debugSolutions={},this.debugMessage="")}getNeighbors(n){return[]}isSameNode(n,e){return ad(n,e)<this.GRID_STEP}computeG(n,e){return n.g+ad(n,e)}computeH(n){return ad(n,this.goalPoint)}getNodeName(n){return TW(n,this.GRID_STEP)}solveOneStep(){this.iterations+=1;let{openSet:n,closedSet:e,GRID_STEP:t,goalPoint:i}=this;n.sort((a,c)=>a.f-c.f);let r=n.shift();if(this.computeH(r)<=t*2)return{solved:!0,current:r,newNeighbors:[]};this.closedSet.add(this.getNodeName(r));let o=[];for(let a of this.getNeighbors(r)){if(e.has(this.getNodeName(a)))continue;let c=this.computeG(r,a),l=this.openSet.find(u=>this.isSameNode(u,a));if(!l||c<l.g){let u=this.computeH(a),p=c+u*this.GREEDY_MULTIPLIER,d={...a,g:c,h:u,f:p,obstacleHit:a.obstacleHit??void 0,manDistFromParent:ad(r,a),nodesInPath:r.nodesInPath+1,parent:r,enterMarginCost:a.enterMarginCost,travelMarginCostFactor:a.travelMarginCostFactor};n.push(d),o.push(d)}}return od.enabled&&(n.sort((a,c)=>a.f-c.f),this.drawDebugSolution({current:r,newNeighbors:o})),{solved:!1,current:r,newNeighbors:o}}getStartNode(n){return{x:n.pointsToConnect[0].x,y:n.pointsToConnect[0].y,manDistFromParent:0,f:0,g:0,h:0,nodesInPath:0,parent:null}}layerToIndex(n){return 0}indexToLayer(n){return"top"}preprocessConnectionBeforeSolving(n){return n}solveConnection(n){if(n.pointsToConnect.length>2)throw new Error("GeneralizedAstarAutorouter doesn't currently support 2+ points in a connection");n=this.preprocessConnectionBeforeSolving(n);let{pointsToConnect:e}=n;for(this.iterations=0,this.closedSet=new Set,this.startNode=this.getStartNode(n),this.goalPoint={...e[e.length-1],l:this.layerToIndex(e[e.length-1].layer)},this.openSet=[this.startNode];this.iterations<this.MAX_ITERATIONS;){let{solved:t,current:i}=this.solveOneStep();if(t){let r=[],s=i;for(;s;){let o=s.l;r.unshift({x:s.x,y:s.y,layer:o!==void 0?this.indexToLayer(o):e[0].layer}),s=s.parent}return od.enabled&&(this.debugMessage+=`t${this.debugTraceCount}: ${this.iterations} iterations
|
|
159
|
+
)`,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])"};var Cs=Vt(td(),1);var Z5={};function K5(n,e){return n===Cs.default.falseFunc?Cs.default.falseFunc:t=>e.isTag(t)&&n(t)}function J5(n,e){let t=e.getSiblings(n);if(t.length<=1)return[];let i=t.indexOf(n);return i<0||i===t.length-1?[]:t.slice(i+1).filter(e.isTag)}function q5(n){return{xmlMode:!!n.xmlMode,lowerCaseAttributeNames:!!n.lowerCaseAttributeNames,lowerCaseTags:!!n.lowerCaseTags,quirksMode:!!n.quirksMode,cacheResults:!!n.cacheResults,pseudos:n.pseudos,adapter:n.adapter,equals:n.equals}}var H5=(n,e,t,i,r)=>{let s=r(e,q5(t),i);return s===Cs.default.trueFunc?n:s===Cs.default.falseFunc?Cs.default.falseFunc:o=>s(o)&&n(o)},uw={is:H5,matches:H5,where:H5,not(n,e,t,i,r){let s=r(e,q5(t),i);return s===Cs.default.falseFunc?n:s===Cs.default.trueFunc?Cs.default.falseFunc:o=>!s(o)&&n(o)},has(n,e,t,i,r){let{adapter:s}=t,o=q5(t);o.relativeSelector=!0;let a=e.some(u=>u.some(Pg))?[Z5]:void 0,c=r(e,o,a);if(c===Cs.default.falseFunc)return Cs.default.falseFunc;let l=K5(c,s);if(a&&c!==Cs.default.trueFunc){let{shouldTestNextSiblings:u=!1}=c;return p=>{if(!n(p))return!1;a[0]=p;let d=s.getChildren(p),_=u?[...d,...J5(p,s)]:d;return s.existsOne(l,_)}}return u=>n(u)&&s.existsOne(l,s.getChildren(u))}};function XG(n,e,t,i,r){var s;let{name:o,data:a}=e;if(Array.isArray(a)){if(!(o in uw))throw new Error(`Unknown pseudo-class :${o}(${a})`);return uw[o](n,a,t,i,r)}let c=(s=t.pseudos)===null||s===void 0?void 0:s[o],l=typeof c=="string"?c:W5[o];if(typeof l=="string"){if(a!=null)throw new Error(`Pseudo ${o} doesn't have any arguments`);let u=Sg(l);return uw.is(n,u,t,i,r)}if(typeof c=="function")return G5(c,o,a,1),u=>c(u,a)&&n(u);if(o in Tg)return Tg[o](n,a,t,i);if(o in lw){let u=lw[o];return G5(u,o,a,2),p=>u(p,t,a)&&n(p)}throw new Error(`Unknown pseudo-class :${o}`)}function Q5(n,e){let t=e.getParent(n);return t&&e.isTag(t)?t:null}function UG(n,e,t,i,r){let{adapter:s,equals:o}=t;switch(e.type){case fe.PseudoElement:throw new Error("Pseudo-elements are not supported by css-select");case fe.ColumnCombinator:throw new Error("Column combinators are not yet supported by css-select");case fe.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()),DG[e.action](n,e,t)}case fe.Pseudo:return XG(n,e,t,i,r);case fe.Tag:{if(e.namespace!=null)throw new Error("Namespaced tag names are not yet supported by css-select");let{name:a}=e;return(!t.xmlMode||t.lowerCaseTags)&&(a=a.toLowerCase()),function(l){return s.getName(l)===a&&n(l)}}case fe.Descendant:{if(t.cacheResults===!1||typeof WeakSet>"u")return function(l){let u=l;for(;u=Q5(u,s);)if(n(u))return!0;return!1};let a=new WeakSet;return function(l){let u=l;for(;u=Q5(u,s);)if(!a.has(u)){if(s.isTag(u)&&n(u))return!0;a.add(u)}return!1}}case"_flexibleDescendant":return function(c){let l=c;do if(n(l))return!0;while(l=Q5(l,s));return!1};case fe.Parent:return function(c){return s.getChildren(c).some(l=>s.isTag(l)&&n(l))};case fe.Child:return function(c){let l=s.getParent(c);return l!=null&&s.isTag(l)&&n(l)};case fe.Sibling:return function(c){let l=s.getSiblings(c);for(let u=0;u<l.length;u++){let p=l[u];if(o(c,p))break;if(s.isTag(p)&&n(p))return!0}return!1};case fe.Adjacent:return s.prevElementSibling?function(c){let l=s.prevElementSibling(c);return l!=null&&n(l)}:function(c){let l=s.getSiblings(c),u;for(let p=0;p<l.length;p++){let d=l[p];if(o(c,d))break;s.isTag(d)&&(u=d)}return!!u&&n(u)};case fe.Universal:{if(e.namespace!=null&&e.namespace!=="*")throw new Error("Namespaced universal selectors are not yet supported by css-select");return n}}}function VG(n,e,t){let i=pw(n,e,t);return K5(i,e.adapter)}function pw(n,e,t){let i=typeof n=="string"?Sg(n):n;return hw(i,e,t)}function GG(n){return n.type===fe.Pseudo&&(n.name==="scope"||Array.isArray(n.data)&&n.data.some(e=>e.some(GG)))}var d3t={type:fe.Descendant},f3t={type:"_flexibleDescendant"},m3t={type:fe.Pseudo,name:"scope",data:null};function _3t(n,{adapter:e},t){let i=!!t?.every(r=>{let s=e.isTag(r)&&e.getParent(r);return r===Z5||s&&e.isTag(s)});for(let r of n){if(!(r.length>0&&Pg(r[0])&&r[0].type!==fe.Descendant))if(i&&!r.some(GG))r.unshift(d3t);else continue;r.unshift(m3t)}}function hw(n,e,t){var i;n.forEach(X5),t=(i=e.context)!==null&&i!==void 0?i:t;let r=Array.isArray(t),s=t&&(Array.isArray(t)?t:[t]);if(e.relativeSelector!==!1)_3t(n,e,s);else if(n.some(c=>c.length>0&&Pg(c[0])))throw new Error("Relative selectors are not allowed when the `relativeSelector` option is disabled");let o=!1,a=n.map(c=>{if(c.length>=2){let[l,u]=c;l.type!==fe.Pseudo||l.name!=="scope"||(r&&u.type===fe.Descendant?c[1]=f3t:(u.type===fe.Adjacent||u.type===fe.Sibling)&&(o=!0))}return y3t(c,e,s)}).reduce(g3t,Ra.default.falseFunc);return a.shouldTestNextSiblings=o,a}function y3t(n,e,t){var i;return n.reduce((r,s)=>r===Ra.default.falseFunc?Ra.default.falseFunc:UG(r,s,e,t,hw),(i=e.rootFunc)!==null&&i!==void 0?i:Ra.default.trueFunc)}function g3t(n,e){return e===Ra.default.falseFunc||n===Ra.default.trueFunc?n:n===Ra.default.falseFunc||e===Ra.default.trueFunc?e:function(i){return n(i)||e(i)}}var WG=(n,e)=>n===e,x3t={adapter:aw,equals:WG};function HG(n){var e,t,i,r;let s=n??x3t;return(e=s.adapter)!==null&&e!==void 0||(s.adapter=aw),(t=s.equals)!==null&&t!==void 0||(s.equals=(r=(i=s.adapter)===null||i===void 0?void 0:i.equals)!==null&&r!==void 0?r:WG),s}function e4(n){return function(t,i,r){let s=HG(i);return n(t,s,r)}}var vee=e4(VG),wee=e4(pw),See=e4(hw);function qG(n){return function(t,i,r){let s=HG(r);typeof t!="function"&&(t=pw(t,s,i));let o=b3t(i,s.adapter,t.shouldTestNextSiblings);return n(t,o,s)}}function b3t(n,e,t=!1){return t&&(n=v3t(n,e)),Array.isArray(n)?e.removeSubsets(n):e.getChildren(n)}function v3t(n,e){let t=Array.isArray(n)?n.slice(0):[n],i=t.length;for(let r=0;r<i;r++){let s=J5(t[r],e);t.push(...s)}return t}var n4=qG((n,e,t)=>n===t4.default.falseFunc||!e||e.length===0?[]:t.adapter.findAll(n,e)),dw=qG((n,e,t)=>n===t4.default.falseFunc||!e||e.length===0?null:t.adapter.findOne(n,e));Q();wt();Q();var EW=Vt(In(),1);wt();var IW=Vt(In(),1),AW=Vt(In(),1);wt();si();l4();var u4=(n,e={})=>{let t=n._internal_store;if(!t){t={counts:{}},n._internal_store=t;for(let r of n){let s=r.type,o=r[`${s}_id`];if(!o)continue;let a=Number.parseInt(o.split("_").pop());Number.isNaN(a)||(t.counts[s]=Math.max(t.counts[s]??0,a))}}return new Proxy({},{get:(r,s)=>s==="toArray"?()=>n:{get:o=>n.find(a=>a.type===s&&a[`${s}_id`]===o),getUsing:o=>{let a=Object.keys(o);if(a.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");let c=a[0],l=c.replace("_id",""),u=n.find(p=>p.type===l&&p[c]===o[c]);return u?n.find(p=>p.type===s&&p[`${s}_id`]===u[`${s}_id`]):null},getWhere:o=>{let a=Object.keys(o);return n.find(c=>c.type===s&&a.every(l=>c[l]===o[l]))},list:o=>{let a=o?Object.keys(o):[];return n.filter(c=>c.type===s&&a.every(l=>c[l]===o[l]))},insert:o=>{var l;(l=t.counts)[s]??(l[s]=-1),t.counts[s]++;let a=t.counts[s],c={type:s,[`${s}_id`]:`${s}_${a}`,...o};return e.validateInserts&&(Wh[s]??Gh).parse(c),n.push(c),c},delete:o=>{let a=n.find(c=>c[`${s}_id`]===o);a&&n.splice(n.indexOf(a),1)},update:(o,a)=>{let c=n.find(l=>l.type===s&&l[`${s}_id`]===o);if(c)return Object.assign(c,a),c},select:o=>{if(s==="source_component")return n.find(a=>a.type==="source_component"&&a.name===o.replace(/\./g,""));if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){let[a,c]=o.replace(/\./g,"").split(/[\s\>]+/),l=n.find(p=>p.type==="source_component"&&p.name===a);if(!l)return null;let u=n.find(p=>p.type==="source_port"&&p.source_component_id===l.source_component_id&&(p.name===c||(p.port_hints??[]).includes(c)));if(!u)return null;if(s==="source_port")return u;if(s==="pcb_port")return n.find(p=>p.type==="pcb_port"&&p.source_port_id===u.source_port_id);if(s==="schematic_port")return n.find(p=>p.type==="schematic_port"&&p.source_port_id===u.source_port_id)}}}})};u4.unparsed=u4;var lW=u4;var Tie=Vt(pW(),1);ir();function so(n){let e=n.width/2,t=n.height/2;return{minX:n.center.x-e,maxX:n.center.x+e,minY:n.center.y-t,maxY:n.center.y+t}}function Ng(n,e){let t=so(n),i=so(e),r=Math.max(t.minX-i.maxX,i.minX-t.maxX,0),s=Math.max(t.minY-i.maxY,i.minY-t.maxY,0),o={x:0,y:0},a={x:0,y:0};return r===0&&s===0?{distance:0,pointA:n.center,pointB:e.center}:(o.x=Wn(n.center.x,i.minX,i.maxX),o.y=Wn(n.center.y,i.minY,i.maxY),a.x=Wn(e.center.x,t.minX,t.maxX),a.y=Wn(e.center.y,t.minY,t.maxY),{distance:Math.hypot(o.x-a.x,o.y-a.y),pointA:o,pointB:a})}function Fo(n,e){return Ng(n,e)}function m4(n,e){let t=so(n),i=so(e),r=Math.max(t.minX-i.maxX,i.minX-t.maxX,0),s=Math.max(t.minY-i.maxY,i.minY-t.maxY,0);return Math.hypot(r,s)}function Wn(n,e,t){return Math.max(e,Math.min(t,n))}function Ag(n,e){let t=Number.POSITIVE_INFINITY,i={x:0,y:0},r={x:0,y:0};for(let s of n)for(let o of e){let{distance:a,pointA:c,pointB:l}=Ng(s,o);a<t&&(t=a,i=c,r=l)}return{pointA:i,pointB:r,distance:t}}ir();ir();var gW="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var xW=(n=21)=>{let e="",t=crypto.getRandomValues(new Uint8Array(n|=0));for(;n--;)e+=gW[t[n]&63];return e};ir();var ad=(n,e)=>Math.abs(n.x-e.x)+Math.abs(n.y-e.y),bW=(n,e)=>{let t=e.x-n.x,i=e.y-n.y;return Math.abs(t)>Math.abs(i)?{dx:Math.sign(t),dy:0}:{dx:0,dy:Math.sign(i)}},kW=(n,e,t)=>Math.abs(n.x-e.x)*Math.abs(t.dx)+Math.abs(n.y-e.y)*Math.abs(t.dy),TW=(n,e=.1)=>`${Math.round(n.x/e)},${Math.round(n.y/e)}`,vW=(n,e)=>Math.abs(n-e)<1e-4,MW=(n,e,{viaDiameter:t=.5}={})=>{let i=[];for(let r=0;r<n.length-1;r++){let[s,o]=[n[r],n[r+1]],a=r-1>=0?n[r-1]:null,c=vW(s.y,o.y),l=vW(s.x,o.x);if(!c&&!l)throw new Error(`getObstaclesFromTrace currently only supports horizontal and vertical traces (not diagonals) Conflicting trace: ${e}, start: (${s.x}, ${s.y}), end: (${o.x}, ${o.y})`);let u={type:"rect",layers:[s.layer],center:{x:(s.x+o.x)/2,y:(s.y+o.y)/2},width:c?Math.abs(s.x-o.x):.1,height:l?Math.abs(s.y-o.y):.1,connectedTo:[e]};if(i.push(u),a&&a.layer===s.layer&&s.layer!==o.layer){let p={type:"rect",layers:[s.layer,o.layer],center:{x:s.x,y:s.y},connectedTo:[e],width:t,height:t};i.push(p)}}return i},CW=class{constructor(n){f(this,"obstacles");f(this,"GRID_STEP",.1);this.obstacles=n.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(n,e,t){t??(t=this.GRID_STEP);for(let i of this.obstacles){let r=i.width/2+t,s=i.height/2+t;if(n>=i.center.x-r&&n<=i.center.x+r&&e>=i.center.y-s&&e<=i.center.y+s)return i}return null}isObstacleAt(n,e,t){return this.getObstacleAt(n,e,t)!==null}getDirectionDistancesToNearestObstacle(n,e){let{GRID_STEP:t}=this,i={left:1/0,top:1/0,bottom:1/0,right:1/0};for(let r of this.obstacles)if(r.type==="rect"){let s=r.center.x-r.width/2-t,o=r.center.x+r.width/2+t,a=r.center.y+r.height/2+t,c=r.center.y-r.height/2-t;e>=c&&e<=a&&n>s&&(i.left=Math.min(i.left,n-o)),e>=c&&e<=a&&n<o&&(i.right=Math.min(i.right,s-n)),n>=s&&n<=o&&e<a&&(i.top=Math.min(i.top,c-e)),n>=s&&n<=o&&e>c&&(i.bottom=Math.min(i.bottom,e-a))}return i}getOrthoDirectionCollisionInfo(n,e,{margin:t=0}={}){let{x:i,y:r}=n,{dx:s,dy:o}=e,a=1/0,c=null;for(let l of this.obstacles){let u=l.left-t,p=l.right+t,d=l.top+t,_=l.bottom-t,g=null;s===1&&o===0?r>_&&r<d&&i<l.left&&(g=l.left-i):s===-1&&o===0?r>_&&r<d&&i>l.right&&(g=i-l.right):s===0&&o===1?i>u&&i<p&&r<l.bottom&&(g=l.bottom-r):s===0&&o===-1&&i>u&&i<p&&r>l.top&&(g=r-l.top),g!==null&&g<a&&(a=g,c=l)}return{dx:s,dy:o,wallDistance:a,obstacle:c}}getObstaclesOverlappingRegion(n){let e=[];for(let t of this.obstacles){let{left:i,right:r,top:s,bottom:o}=t;i<=n.maxX&&r>=n.minX&&s<=n.maxY&&o>=n.minY&&e.push(t)}return e}};function E3t(n){if(n.length<4)return n;let e=[{...n[0]}],t=n[0].layer;for(let i=1;i<n.length;i++){let r={start:n[i-1],end:n[i]},s=n[i].route_type==="via"||n[i-1].route_type==="via";if(n[i].layer!==t||s){e.push({...n[i]}),t=n[i].layer;continue}let o=!1,a=null,c=-1;for(let u=0;u<e.length-1;u++){let p={start:e[u],end:e[u+1]};if(p.start.layer===r.start.layer&&p.start.layer===r.start.layer){let d=M3t(p,r);if(d){o=!0,a={...d,layer:t},c=u;break}}}o&&a&&(e.splice(c+1),e.push(a));let l=e[e.length-1];(l.x!==n[i].x||l.y!==n[i].y)&&e.push(n[i])}return e}function M3t(n,e){if(n.start.x===n.end.x&&e.start.x===e.end.x||n.start.y===n.end.y&&e.start.y===e.end.y)return null;let t;if(n.start.x===n.end.x){let i=n.start.x,r=e.start.y;t={...n.start,x:i,y:r}}else{let i=e.start.x,r=n.start.y;t={...n.start,x:i,y:r}}return wW(t,n)&&wW(t,e)?t:null}function wW(n,e){return n.x>=Math.min(e.start.x,e.end.x)&&n.x<=Math.max(e.start.x,e.end.x)&&n.y>=Math.min(e.start.y,e.end.y)&&n.y<=Math.max(e.start.y,e.end.y)}function C3t(n){let e=[n[0]];for(let t=1;t<n.length-1;t++){let[i,r,s]=[n[t-1],n[t],n[t+1]];e.push(r),!(r.route_type!=="wire"||i.route_type!=="wire"||s.route_type!=="wire")&&i.layer===r.layer&&r.layer!==s.layer&&e.push({route_type:"via",from_layer:r.layer,to_layer:s.layer,x:r.x,y:r.y})}return e.push(n[n.length-1]),e}var Pie=(0,IW.default)("autorouter:shortenPathWithShortcuts");function I3t(n,e){if(n.length<=2)return n;let t=[n[0]];for(let i=1;i<n.length;i++){let r={start:t[t.length-1],end:n[i]},s=-1,o=r.start.x===r.end.x,a=r.start.y===r.end.y;for(let c=i+1;c<n.length;c++){if(c<=s)continue;let l={start:n[c],end:n[c+1]};if(!l.end)continue;let u=l.start.x===l.end.x,p=l.start.y===l.end.y,d=o&&u,_=a&&p;if(_&&d||!(d||_))continue;let x=!1,v=Math.min(r.start.x,r.end.x),S=Math.max(r.start.x,r.end.x),P=Math.min(l.start.x,l.end.x),T=Math.max(l.start.x,l.end.x),k=Math.min(r.start.y,r.end.y),N=Math.max(r.start.y,r.end.y),E=Math.min(l.start.y,l.end.y),C=Math.max(l.start.y,l.end.y);if(_?x=v<=T&&S>=P:d&&(x=k<=C&&N>=E),!x)continue;let M=[],A=t[t.length-1],R=n[c+2];if(!R)continue;_&&P<S&&R.x===P&&M.push({x:P,y:r.start.y,layer:r.start.layer}),_&&T>v&&R.x===T&&M.push({x:T,y:r.start.y,layer:r.start.layer}),d&&E<N&&R.y===E&&M.push({x:r.start.x,y:E,layer:r.start.layer}),d&&C>k&&R.y===C&&M.push({x:r.start.x,y:C,layer:r.start.layer});let B=null;for(let j of M)if(!(e(A,j)||e(R,j))){B=j;break}if(B){t.push(B),i=c+1,s=c+1;break}}s===-1&&t.push(n[i])}return t[t.length-1]!==n[n.length-1]&&t.push(n[n.length-1]),t}var od=(0,EW.default)("autorouting-dataset:astar"),NW=class{constructor(n){f(this,"openSet",[]);f(this,"closedSet",new Set);f(this,"debug",!1);f(this,"debugSolutions");f(this,"debugMessage",null);f(this,"debugTraceCount",0);f(this,"input");f(this,"obstacles");f(this,"allObstacles");f(this,"startNode");f(this,"goalPoint");f(this,"GRID_STEP");f(this,"OBSTACLE_MARGIN");f(this,"MAX_ITERATIONS");f(this,"isRemovePathLoopsEnabled");f(this,"isShortenPathWithShortcutsEnabled");f(this,"GREEDY_MULTIPLIER",1.1);f(this,"iterations",-1);this.input=n.input,this.allObstacles=n.input.obstacles,this.startNode=n.startNode,this.goalPoint=n.goalPoint?{l:0,...n.goalPoint}:void 0,this.GRID_STEP=n.GRID_STEP??.1,this.OBSTACLE_MARGIN=n.OBSTACLE_MARGIN??.15,this.MAX_ITERATIONS=n.MAX_ITERATIONS??100,this.debug=n.debug??od.enabled,this.isRemovePathLoopsEnabled=n.isRemovePathLoopsEnabled??!1,this.isShortenPathWithShortcutsEnabled=n.isShortenPathWithShortcutsEnabled??!1,this.debug&&(od.enabled=!0),od.enabled&&(this.debugSolutions={},this.debugMessage="")}getNeighbors(n){return[]}isSameNode(n,e){return ad(n,e)<this.GRID_STEP}computeG(n,e){return n.g+ad(n,e)}computeH(n){return ad(n,this.goalPoint)}getNodeName(n){return TW(n,this.GRID_STEP)}solveOneStep(){this.iterations+=1;let{openSet:n,closedSet:e,GRID_STEP:t,goalPoint:i}=this;n.sort((a,c)=>a.f-c.f);let r=n.shift();if(this.computeH(r)<=t*2)return{solved:!0,current:r,newNeighbors:[]};this.closedSet.add(this.getNodeName(r));let o=[];for(let a of this.getNeighbors(r)){if(e.has(this.getNodeName(a)))continue;let c=this.computeG(r,a),l=this.openSet.find(u=>this.isSameNode(u,a));if(!l||c<l.g){let u=this.computeH(a),p=c+u*this.GREEDY_MULTIPLIER,d={...a,g:c,h:u,f:p,obstacleHit:a.obstacleHit??void 0,manDistFromParent:ad(r,a),nodesInPath:r.nodesInPath+1,parent:r,enterMarginCost:a.enterMarginCost,travelMarginCostFactor:a.travelMarginCostFactor};n.push(d),o.push(d)}}return od.enabled&&(n.sort((a,c)=>a.f-c.f),this.drawDebugSolution({current:r,newNeighbors:o})),{solved:!1,current:r,newNeighbors:o}}getStartNode(n){return{x:n.pointsToConnect[0].x,y:n.pointsToConnect[0].y,manDistFromParent:0,f:0,g:0,h:0,nodesInPath:0,parent:null}}layerToIndex(n){return 0}indexToLayer(n){return"top"}preprocessConnectionBeforeSolving(n){return n}solveConnection(n){if(n.pointsToConnect.length>2)throw new Error("GeneralizedAstarAutorouter doesn't currently support 2+ points in a connection");n=this.preprocessConnectionBeforeSolving(n);let{pointsToConnect:e}=n;for(this.iterations=0,this.closedSet=new Set,this.startNode=this.getStartNode(n),this.goalPoint={...e[e.length-1],l:this.layerToIndex(e[e.length-1].layer)},this.openSet=[this.startNode];this.iterations<this.MAX_ITERATIONS;){let{solved:t,current:i}=this.solveOneStep();if(t){let r=[],s=i;for(;s;){let o=s.l;r.unshift({x:s.x,y:s.y,layer:o!==void 0?this.indexToLayer(o):e[0].layer}),s=s.parent}return od.enabled&&(this.debugMessage+=`t${this.debugTraceCount}: ${this.iterations} iterations
|
|
160
160
|
`),this.isRemovePathLoopsEnabled&&(r=E3t(r)),this.isShortenPathWithShortcutsEnabled&&(r=I3t(r,(o,a)=>{if(o.x===a.x&&o.y===a.y)return!1;let c=this.obstacles.getOrthoDirectionCollisionInfo({x:o.x,y:o.y,l:this.layerToIndex(o.layer)??0},{dx:Math.sign(a.x-o.x),dy:Math.sign(a.y-o.y),dl:0},{margin:.05}),l=Math.sqrt((o.x-a.x)**2+(o.y-a.y)**2);return c.wallDistance<l})),{solved:!0,route:r,connectionName:n.name}}if(this.openSet.length===0)break}return od.enabled&&(this.debugMessage+=`t${this.debugTraceCount}: ${this.iterations} iterations (failed)
|
|
161
161
|
`),{solved:!1,connectionName:n.name}}createObstacleList({dominantLayer:n,connection:e,obstaclesFromTraces:t}){return new CW(this.allObstacles.filter(i=>!i.connectedTo.includes(e.name)).filter(i=>i.layers.includes(n)).concat(t??[]))}postprocessConnectionSolveResult(n,e){return e}solve(){let n=[],e=[];this.debugTraceCount=0;for(let t of this.input.connections){let i=t.pointsToConnect[0].layer??"top";this.debugTraceCount+=1,this.obstacles=this.createObstacleList({dominantLayer:i,connection:t,obstaclesFromTraces:e});let r=this.solveConnection(t);r=this.postprocessConnectionSolveResult(t,r),n.push(r),od.enabled&&this.drawDebugTraceObstacles(e),r.solved&&e.push(...MW(r.route.map(s=>({x:s.x,y:s.y,layer:s.layer??i})),t.name))}return n}solveAndMapToTraces(){return this.solve().flatMap(e=>e.solved?[{type:"pcb_trace",pcb_trace_id:`pcb_trace_for_${e.connectionName}`,route:C3t(e.route.map(t=>({route_type:"wire",x:t.x,y:t.y,width:this.input.minTraceWidth,layer:t.layer})))}]:[])}getDebugGroup(){let n=`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?n:null}drawDebugTraceObstacles(n){let{debugTraceCount:e,debugSolutions:t}=this;for(let i in t)i.startsWith(`t${e}_`)&&t[i].push(...n.map((r,s)=>({type:"pcb_smtpad",pcb_component_id:"",layer:r.layers[0],width:r.width,shape:"rect",x:r.center.x,y:r.center.y,pcb_smtpad_id:`trace_obstacle_${s}`,height:r.height})))}drawDebugSolution({current:n,newNeighbors:e}){let t=this.getDebugGroup();if(!t)return;let{openSet:i,debugTraceCount:r,debugSolutions:s}=this;s[t]??(s[t]=[]);let o=s[t];o.push({type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:`debug_note_${n.x}_${n.y}`,font:"tscircuit2024",font_size:.25,text:"X"+(n.l!==void 0?n.l:""),pcb_component_id:"",layer:"top",anchor_position:{x:n.x,y:n.y},anchor_alignment:"center"});for(let a=0;a<i.length;a++){let c=i[a];o.push({type:"pcb_fabrication_note_path",pcb_component_id:"",pcb_fabrication_note_path_id:`note_path_${c.x}_${c.y}`,layer:"top",route:[[0,.05],[.05,0],[0,-.05],[-.05,0],[0,.05]].map(([l,u])=>({x:c.x+l,y:c.y+u})),stroke_width:.01}),o.push({type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:`debug_note_${c.x}_${c.y}`,font:"tscircuit2024",font_size:.03,text:a.toString(),pcb_component_id:"",layer:"top",anchor_position:{x:c.x,y:c.y},anchor_alignment:"center"})}if(n.parent){let a=[],c=n;for(;c;)a.unshift(c),c=c.parent;o.push({type:"pcb_fabrication_note_path",pcb_component_id:"",pcb_fabrication_note_path_id:`note_path_${n.x}_${n.y}`,layer:"top",route:a,stroke_width:.01})}}},N3t=(0,AW.default)("autorouting-dataset:infinite-grid-ijump-astar:get-distance-to-overcome-obstacle");function _4({node:n,travelDir:e,wallDir:t,obstacle:i,obstacles:r,obstaclesInRow:s=0,OBSTACLE_MARGIN:o=.15,SHOULD_DETECT_CONJOINED_OBSTACLES:a=!1,MAX_CONJOINED_OBSTACLES:c=20}){let l;if(e.dx===0?e.dy>0?l=i.center.y+i.height/2-n.y:l=n.y-(i.center.y-i.height/2):e.dx>0?l=i.center.x+i.width/2-n.x:l=n.x-(i.center.x-i.width/2),l+=o,a&&s<c){let u=r.getObstacleAt(n.x+e.dx*l+t.dx*(t.wallDistance+.001),n.y+e.dy*l+t.dy*(t.wallDistance+.001));if(u===i)return l;if(u&&u.type==="rect"){let p=e.dy===0,d=p?i.height:i.width;if((p?u.height:u.width)>d)return N3t("next obstacle on path is bigger, not trying to overcome it"),l;let g=_4({node:{x:n.x+e.dx*l,y:n.y+e.dy*l},travelDir:e,wallDir:t,obstacle:u,obstacles:r,obstaclesInRow:s+1,SHOULD_DETECT_CONJOINED_OBSTACLES:a,MAX_CONJOINED_OBSTACLES:c,OBSTACLE_MARGIN:o});l+=g}}return l}var A3t=class extends NW{constructor(){super(...arguments);f(this,"MAX_ITERATIONS",200)}getNeighbors(e){let t=this.obstacles,i=this.goalPoint,r;e.parent?r=bW(e.parent,e):r=bW(e,i);let s=[{dx:0,dy:1},{dx:1,dy:0},{dx:0,dy:-1},{dx:-1,dy:0}].filter(a=>a.dx===r.dx*-1&&a.dy===r.dy*-1?!1:!(a.dx===r.dx&&a.dy===r.dy&&e.parent?.obstacleHit)).map(a=>t.getOrthoDirectionCollisionInfo(e,a,{margin:this.OBSTACLE_MARGIN})).filter(a=>a.wallDistance>=this.OBSTACLE_MARGIN),o=[];for(let a of s){let c=null;e?.obstacleHit&&(c=_4({node:e,travelDir:a,wallDir:{...r,wallDistance:this.OBSTACLE_MARGIN},obstacle:e.obstacleHit,obstacles:t,OBSTACLE_MARGIN:this.OBSTACLE_MARGIN,SHOULD_DETECT_CONJOINED_OBSTACLES:!0}));let l=kW(e,i,a),u=(a.dx===0||Math.sign(i.x-e.x)===a.dx)&&(a.dy===0||Math.sign(i.y-e.y)===a.dy);l<a.wallDistance&&l>0&&u?o.push({...a,travelDistance:l}):c!==null&&c<a.wallDistance?o.push({...a,travelDistance:c}):a.wallDistance!==1/0&&o.push({...a,travelDistance:a.wallDistance-this.OBSTACLE_MARGIN})}return o.filter(a=>!t.isObstacleAt(e.x+a.dx*a.travelDistance,e.y+a.dy*a.travelDistance)).map(a=>({x:e.x+a.dx*a.travelDistance,y:e.y+a.dy*a.travelDistance,obstacleHit:a.obstacle}))}};function R3t(n,e=4){let{center:t,width:i,height:r,rotation:s}=n,o=[],a=s*Math.PI/180,c=Math.cos(a),l=Math.sin(a),u=(s%360+360)%360;if(r<=i?u>=45&&u<135||u>=225&&u<315:u>=135&&u<225||u>=315||u<45){let d=i/e;for(let _=0;_<e;_++){let g=(_-e/2+.5)*d,x=-g*c,v=-g*l,S=d*1.1,P=Math.abs(r*c)+Math.abs(d*l);o.push({center:{x:t.x+x,y:t.y+v},width:S,height:P})}}else{let d=r/e;for(let _=0;_<e;_++){let g=(_-e/2+.5)*d,x=-g*l,v=g*c,S=Math.abs(i*c)+Math.abs(d*l),P=d*1.1;o.push({center:{x:t.x+x,y:t.y+v},width:S,height:P})}}return o}var xw=["top","inner1","inner2","bottom"],RW=(n,e)=>{let t=r=>e?r.concat(r.map(s=>e?.getNetConnectedToId(s)).filter(Boolean)):r,i=[];for(let r of n)if(r.type==="pcb_smtpad"){if(r.shape==="circle")i.push({type:"oval",layers:[r.layer],center:{x:r.x,y:r.y},width:r.radius*2,height:r.radius*2,connectedTo:t([r.pcb_smtpad_id])});else if(r.shape==="rect")i.push({type:"rect",layers:[r.layer],center:{x:r.x,y:r.y},width:r.width,height:r.height,connectedTo:t([r.pcb_smtpad_id])});else if(r.shape==="rotated_rect"){let s={center:{x:r.x,y:r.y},width:r.width,height:r.height,rotation:r.ccw_rotation},o=R3t(s);for(let a of o)i.push({type:"rect",layers:[r.layer],center:a.center,width:a.width,height:a.height,connectedTo:t([r.pcb_smtpad_id])})}}else if(r.type==="pcb_keepout")r.shape==="circle"?i.push({type:"oval",layers:r.layers,center:{x:r.center.x,y:r.center.y},width:r.radius*2,height:r.radius*2,connectedTo:[]}):r.shape==="rect"&&i.push({type:"rect",layers:r.layers,center:{x:r.center.x,y:r.center.y},width:r.width,height:r.height,connectedTo:[]});else if(r.type==="pcb_hole")r.hole_shape==="oval"?i.push({type:"oval",center:{x:r.x,y:r.y},width:r.hole_width,height:r.hole_height,connectedTo:[]}):r.hole_shape==="square"?i.push({type:"rect",layers:xw,center:{x:r.x,y:r.y},width:r.hole_diameter,height:r.hole_diameter,connectedTo:[]}):(r.hole_shape==="round"||r.hole_shape==="circle")&&i.push({type:"rect",layers:xw,center:{x:r.x,y:r.y},width:r.hole_diameter,height:r.hole_diameter,connectedTo:[]});else if(r.type==="pcb_plated_hole")r.shape==="circle"?i.push({type:"oval",layers:xw,center:{x:r.x,y:r.y},width:r.outer_diameter,height:r.outer_diameter,connectedTo:t([r.pcb_plated_hole_id])}):(r.shape==="oval"||r.shape==="pill")&&i.push({type:"oval",layers:xw,center:{x:r.x,y:r.y},width:r.outer_width,height:r.outer_height,connectedTo:t([r.pcb_plated_hole_id])});else if(r.type==="pcb_trace"){let s=MW(r.route.map(o=>({x:o.x,y:o.y,layer:"layer"in o?o.layer:o.from_layer})),r.source_trace_id);i.push(...s)}else r.type==="pcb_via"&&i.push({type:"rect",layers:r.layers,center:{x:r.x,y:r.y},connectedTo:[],width:r.outer_diameter,height:r.outer_diameter});return i};function SW(n){let{pcbConnMap:e,goalElementId:t}=n;if(!t.startsWith("pcb_port_"))throw new Error(`Currently alternative goal boxes must have a goal id with prefix "pcb_port_" (got ${t})`);let i=e.getAllTracesConnectedToPort(t);return RW(i).map(r=>({...r,connectedTo:[t]}))}var OW=n=>{let{connection:e,pcbConnMap:t}=n;if(e.pointsToConnect.length!==2)throw new Error(`Connection must have exactly 2 points for alternative goal boxes (got ${e.pointsToConnect.length})`);let[i,r]=e.pointsToConnect;if(!i.pcb_port_id||!r.pcb_port_id)throw new Error(`Connection points must have pcb_port_id for alternative goal box calculation (got ${i.pcb_port_id} and ${r.pcb_port_id})`);let s=SW({goalElementId:i.pcb_port_id,pcbConnMap:t}).concat([{center:i,width:.01,height:.01,connectedTo:[i.pcb_port_id],layers:[i.layer],type:"rect"}]),o=SW({goalElementId:r.pcb_port_id,pcbConnMap:t}).concat([{center:r,width:.01,height:.01,connectedTo:[r.pcb_port_id],layers:[r.layer],type:"rect"}]);if(s.length<=1&&o.length<=1)return{...e,startPoint:i,endPoint:r,goalBoxes:[]};let a=Ag(s,o),c,l,u;return s.length>=o.length?(c={...r,...a.pointB},l={...i,...a.pointA},u=s):(c={...i,...a.pointA},l={...r,...a.pointB},u=o),{startPoint:c,endPoint:l,goalBoxes:u,name:e.name,pointsToConnect:[c,l]}},O3t=(n,e={})=>{let t={minTraceWidth:.1};t.layerCount=e.layerCount??1,t.obstacles=RW(n,e.connMap),t.connections=[];for(let r of n)if(r.type==="source_trace"){let s={name:r.source_trace_id,pointsToConnect:r.connected_source_port_ids.map(o=>{let a=lW(n).pcb_port.getWhere({source_port_id:o});if(!a)throw new Error(`Could not find pcb_port for source_port_id "${o}"`);return{x:a.x,y:a.y,layer:a.layers?.[0]??"top",pcb_port_id:a.pcb_port_id}})};if(e.optimizeWithGoalBoxes){let o=new gw(n);s=OW({connection:s,pcbConnMap:o})}t.connections.push(s),L3t(t.obstacles,s.pointsToConnect,s.name)}let i={minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0};for(let r of t.obstacles)i.minX=Math.min(i.minX,r.center.x-r.width/2),i.maxX=Math.max(i.maxX,r.center.x+r.width/2),i.minY=Math.min(i.minY,r.center.y-r.height/2),i.maxY=Math.max(i.maxY,r.center.y+r.height/2);for(let r of t.connections)for(let s of r.pointsToConnect)i.minX=Math.min(i.minX,s.x),i.maxX=Math.max(i.maxX,s.x),i.minY=Math.min(i.minY,s.y),i.maxY=Math.max(i.maxY,s.y);return t.bounds=i,t},L3t=(n,e,t)=>{for(let i of e)for(let r of n)F3t(i,r)&&r.connectedTo.push(t)};function F3t(n,e){let t=e.width/2,i=e.height/2;if(e.type==="rect")return n.x>=e.center.x-t&&n.x<=e.center.x+t&&n.y>=e.center.y-i&&n.y<=e.center.y+i;if(e.type==="oval"){let r=(n.x-e.center.x)/t,s=(n.y-e.center.y)/i;return r*r+s*s<=1}return!1}function PW(n,e){let t=e.x>n.x?1:e.x<n.x?-1:0,i=e.y>n.y?1:e.y<n.y?-1:0,r=e.l>n.l?1:e.l<n.l?-1:0;return{dx:t,dy:i,dl:r}}var y4={1:["top"],2:["top","bottom"],4:["top","inner1","inner2","bottom"]},$3t=n=>y4[n];function LW(n,e){let i=y4[n].indexOf(e);if(i===-1)throw new Error(`Invalid layer for getLayerIndex (for layerCount === ${n}): "${e}"`);return i}function z3t(n,e){let i=y4[n][e];if(!i)throw new Error(`Invalid index for indexToLayer (for layerCount === ${n}): "${e}"`);return i}var D3t=class extends CW{constructor(e,t){super([]);f(this,"obstacles");f(this,"GRID_STEP",.1);f(this,"layerCount");this.layerCount=e;let i=$3t(e);this.obstacles=t.flatMap(r=>r.layers.filter(s=>i.includes(s)).map(s=>({...r,left:r.center.x-r.width/2,right:r.center.x+r.width/2,top:r.center.y+r.height/2,bottom:r.center.y-r.height/2,l:LW(e,s)})))}getObstacleAt(e,t,i,r){r??(r=this.GRID_STEP);for(let s of this.obstacles){if(s.l!==i)continue;let o=s.width/2+r,a=s.height/2+r;if(e>=s.center.x-o&&e<=s.center.x+o&&t>=s.center.y-a&&t<=s.center.y+a)return s}return null}isObstacleAt(e,t,i,r){return this.getObstacleAt(e,t,i,r)!==null}getDirectionDistancesToNearestObstacle3d(e,t,i){let{GRID_STEP:r}=this,s={left:1/0,top:1/0,bottom:1/0,right:1/0};for(let o of this.obstacles)if(o.l===i&&o.type==="rect"){let a=o.center.x-o.width/2-r,c=o.center.x+o.width/2+r,l=o.center.y+o.height/2+r,u=o.center.y-o.height/2-r;t>=u&&t<=l&&e>a&&(s.left=Math.min(s.left,e-c)),t>=u&&t<=l&&e<c&&(s.right=Math.min(s.right,a-e)),e>=a&&e<=c&&t<l&&(s.top=Math.min(s.top,u-t)),e>=a&&e<=c&&t>u&&(s.bottom=Math.min(s.bottom,t-l))}return s}getOrthoDirectionCollisionInfo(e,t,{margin:i=0}={}){let{x:r,y:s,l:o}=e,{dx:a,dy:c,dl:l}=t,u=1/0,p=null;if(l!==0){let d=o+l;return this.isObstacleAt(r,s,d,i)?(u=1,p=this.getObstacleAt(r,s,d,i)):u=1,{dx:a,dy:c,dl:l,wallDistance:u,obstacle:p}}else{for(let d of this.obstacles){if(d.l!==o)continue;let _=d.left-i,g=d.right+i,x=d.top+i,v=d.bottom-i,S=null;a===1&&c===0?s>v&&s<x&&r<d.left&&(S=d.left-r):a===-1&&c===0?s>v&&s<x&&r>d.right&&(S=r-d.right):a===0&&c===1?r>_&&r<g&&s<d.bottom&&(S=d.bottom-s):a===0&&c===-1&&r>_&&r<g&&s>d.top&&(S=s-d.top),S!==null&&S<u&&(u=S,p=d)}return{dx:a,dy:c,dl:0,wallDistance:u,obstacle:p}}}getObstaclesOverlappingRegion(e){let t=[];for(let i of this.obstacles){if(i.l!==e.l)continue;let{left:r,right:s,top:o,bottom:a}=i;r<=e.maxX&&s>=e.minX&&o>=e.minY&&a<=e.maxY&&t.push(i)}return t}},bw=class extends NW{constructor(e){super(e);f(this,"MAX_ITERATIONS",500);f(this,"VIA_COST",4);f(this,"VIA_DIAMETER",.5);f(this,"allowLayerChange",!0);f(this,"layerCount");f(this,"obstacles");f(this,"optimizeWithGoalBoxes");f(this,"connMap");f(this,"pcbConnMap");f(this,"GOAL_RUSH_FACTOR",1.1);f(this,"defaultGoalViaMargin",.5);f(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 gw,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?OW({connection:e,pcbConnMap:this.pcbConnMap}):e}postprocessConnectionSolveResult(e,t){if(!t.solved)return t;if(this.optimizeWithGoalBoxes){let i=t.route.map(r=>({x:r.x,y:r.y,route_type:"wire",layer:r.layer,width:this.input.minTraceWidth}));i[0].start_pcb_port_id=e.pointsToConnect[0].pcb_port_id,i[i.length-1].end_pcb_port_id=e.pointsToConnect[1].pcb_port_id,this.pcbConnMap.addTrace({type:"pcb_trace",pcb_trace_id:`postprocess_trace_${xW(8)}`,route:i})}return t}createObstacleList({dominantLayer:e,connection:t,obstaclesFromTraces:i}){let r=this.connMap?this.connMap.getNetConnectedToId(t.name):t.name;if(!r)throw new Error(`The connection.name "${t.name}" wasn't present in the full connectivity map`);return new D3t(this.layerCount,this.allObstacles.filter(s=>!s.connectedTo.includes(r)).concat(i??[]))}computeG(e,t){let i=e.g+ad(e,t)*(e.travelMarginCostFactor??1)+(t.enterMarginCost??0);return(t.l??e.l!==-1??-1)&&(i+=this.VIA_COST),i}computeH(e){let t=Math.abs(e.x-this.goalPoint.x),i=Math.abs(e.y-this.goalPoint.y),r=Math.abs(e.l-this.goalPoint.l);return(t+i)**this.GOAL_RUSH_FACTOR+r*this.VIA_COST}getStartNode(e){return{...super.getStartNode(e),l:this.layerToIndex(e.pointsToConnect[0].layer)}}layerToIndex(e){return LW(this.layerCount,e)}indexToLayer(e){return z3t(this.layerCount,e)}getNodeName(e){return`${TW(e,this.GRID_STEP)}-${e.l??0}`}hasSpaceForVia(e,t){return e.every(i=>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:i}).length===0)}getNeighborsSurroundingGoal(e){let t=this.obstacles,i=this.goalPoint,r=[],s=[{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(let a of s){let c={x:e.x+a.dx*o,y:e.y+a.dy*o,l:e.l+a.dl,obstacleHit:null};this.hasSpaceForVia([e.l,i.l],c)&&r.push(c)}return r}getNeighbors(e){let t=this.obstacles,i=this.goalPoint,r=ad(e,i);if(r<=this.OBSTACLE_MARGIN)return this.getNeighborsSurroundingGoal(e);let s;e.parent?s=PW(e.parent,e):s=PW(e,i);let o=[{dx:0,dy:1,dl:0},{dx:1,dy:0,dl:0},{dx:0,dy:-1,dl:0},{dx:-1,dy:0,dl:0}],a=r>this.VIA_DIAMETER+this.OBSTACLE_MARGIN,c=ad(e,this.startNode)>this.VIA_DIAMETER+this.OBSTACLE_MARGIN;this.allowLayerChange&&a&&c&&(e.l<this.layerCount-1&&o.push({dx:0,dy:0,dl:1}),e.l>0&&o.push({dx:0,dy:0,dl:-1}));let l=o.filter(p=>p.dx===s.dx*-1&&p.dy===s.dy*-1&&p.dl===s.dl*-1?!1:!(p.dx===s.dx&&p.dy===s.dy&&p.dl===s.dl&&e.parent?.obstacleHit)).map(p=>t.getOrthoDirectionCollisionInfo(e,p,{margin:this.OBSTACLE_MARGIN})).filter(p=>!(p.wallDistance<this.OBSTACLE_MARGIN)),u=[];for(let p of l){let d=p.dx===0&&p.dy===0&&p.dl===1,_=p.dx===0&&p.dy===0&&p.dl===-1;if((d||_)&&![e.l,e.l+p.dl].every(P=>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:P}).length===0))continue;if(d){e.l<this.layerCount-1&&u.push({...p,travelDistance:0,enterMarginCost:0,travelMarginCostFactor:1});continue}if(_){e.l>0&&u.push({...p,travelDistance:0,enterMarginCost:0,travelMarginCostFactor:1});continue}let g=null;e?.obstacleHit&&(g=_4({node:e,travelDir:p,wallDir:{...s,wallDistance:this.OBSTACLE_MARGIN},obstacle:e.obstacleHit,obstacles:t,OBSTACLE_MARGIN:this.OBSTACLE_MARGIN,SHOULD_DETECT_CONJOINED_OBSTACLES:!0}));let x=kW(e,i,p),v=(p.dx===0||Math.sign(i.x-e.x)===p.dx)&&(p.dy===0||Math.sign(i.y-e.y)===p.dy);if(x<p.wallDistance&&x>0&&v){let S=e.l===i.l,P=0;!S&&Math.abs(x-r)<this.GRID_STEP&&(P=this.VIA_DIAMETER+this.OBSTACLE_MARGIN+this.defaultGoalViaMargin),u.push({...p,travelDistance:x-P,enterMarginCost:0,travelMarginCostFactor:1})}else if(g!==null&&g<p.wallDistance){for(let{margin:S,enterCost:P,travelCostFactor:T}of this.marginsWithCosts)g-this.OBSTACLE_MARGIN+S*2<p.wallDistance&&u.push({...p,travelDistance:g-this.OBSTACLE_MARGIN+S,enterMarginCost:P,travelMarginCostFactor:T});if(p.wallDistance===1/0)u.push({...p,travelDistance:x,enterMarginCost:0,travelMarginCostFactor:1});else if(p.wallDistance>this.largestMargin)for(let{margin:S,enterCost:P,travelCostFactor:T}of this.marginsWithCosts)p.wallDistance>this.largestMargin+S&&u.push({...p,travelDistance:p.wallDistance-S,enterMarginCost:P,travelMarginCostFactor:T})}else if(p.wallDistance!==1/0)for(let{margin:S,enterCost:P,travelCostFactor:T}of this.marginsWithCosts)p.wallDistance>S&&u.push({...p,travelDistance:p.wallDistance-S,enterMarginCost:P,travelMarginCostFactor:T})}return u.map(p=>({x:e.x+p.dx*p.travelDistance,y:e.y+p.dy*p.travelDistance,l:e.l+p.dl,obstacleHit:p.obstacle,travelMarginCostFactor:p.travelMarginCostFactor,enterMarginCost:p.enterMarginCost}))}};function FW(n){let e=O3t(n),t=new A3t({input:e});return{solution:t.solveAndMapToTraces(),debugSolutions:t.debugSolutions,debugMessage:t.debugMessage}}Q();Q();wt();wt();Q();Q();Q();wt();Q();Q();wt();Q();wt();Q();Q();Q();Q();wt();Q();Q();wt();Q();Q();wt();Q();Q();wt();Q();Q();Q();Q();Q();Q();Q();Q();Q();Q();wt();Q();wt();Q();wt();Q();Q();wt();wt();Q();wt();Q();Q();wt();Q();Q();Q();wt();Q();wt();Q();wt();Q();wt();Q();wt();Q();wt();Q();wt();Q();Q();Q();Q();Q();Q();Q();Q();wt();Q();wt();Q();Q();wt();Q();wt();Q();Q();Q();wt();Q();wt();wt();Q();Q();Q();wt();Q();Q();Q();wt();Q();wt();Q();wt();Q();wt();Q();wt();Q();wt();Q();wt();Q();wt();Q();Q();wt();Q();wt();Q();wt();Q();Q();wt();wt();Q();Q();wt();wt();Q();Q();wt();Q();wt();Q();wt();Q();wt();Q();wt();Q();wt();Q();Q();wt();Q();wt();Q();wt();Q();wt();Q();wt();Q();wt();Q();wt();Q();wt();wt();Q();wt();Q();wt();Q();Q();wt();Q();wt();Q();wt();Q();wt();Q();wt();Q();Q();var Ct=n=>{};Ct("extra props b");Ct("missing props b");Ct(!0);Ct("property a has mismatched types");var j3t=h.enum(["up","down","left","right"]),Yie=h.enum(["top-to-bottom","left-to-right","bottom-to-top","right-to-left"]);Ct(!0);Ct(!0);var oo=h.array(h.string().or(h.number()));Ct(!0);var B3t=h.string().regex(/^calc\(.*\)$/),pe=V,$i=B3t.or(V),Sw=h.object({x:V,y:V,z:V}),Y3t=h.object({x:h.union([h.number(),h.string()]),y:h.union([h.number(),h.string()]),z:h.union([h.number(),h.string()])}),Hc=h.object({rotationOffset:h.number().or(Y3t).optional(),positionOffset:Sw.optional(),size:Sw.optional(),modelUnitToMmScale:pe.optional(),zOffsetFromSurface:pe.optional()});Ct(!0);var X3t=Hc.extend({stlUrl:h.string()}),U3t=Hc.extend({objUrl:h.string(),mtlUrl:h.string().optional()}),V3t=Hc.extend({gltfUrl:h.string()}),G3t=Hc.extend({glbUrl:h.string()}),W3t=Hc.extend({stepUrl:h.string()}),H3t=Hc.extend({wrlUrl:h.string()}),q3t=Hc.extend({jscad:h.record(h.any())}),UW=h.union([h.null(),h.string(),h.custom(n=>n&&typeof n=="object"&&"type"in n&&"props"in n),X3t,U3t,V3t,G3t,W3t,H3t,q3t]);Ct(!0);var Z3t=h.custom(n=>!0),b4=h.object({silkscreenFontSize:V.optional(),viaPadDiameter:V.optional(),viaHoleDiameter:V.optional(),silkscreenTextPosition:h.union([h.enum(["centered","outside","none"]),h.object({offsetX:h.number(),offsetY:h.number()})]).optional(),silkscreenTextVisibility:h.enum(["hidden","visible","inherit"]).optional()});Ct(!0);var K3t=h.object({defaultPassiveSize:h.union([h.enum(["xs","sm","md"]),V]).optional(),defaultCapacitorOrientation:h.enum(["vertical","none"]).optional()});Ct(!0);var J3t=h.custom(n=>!0),Be=h.object({pcbX:$i.optional(),pcbY:$i.optional(),pcbLeftEdgeX:$i.optional(),pcbRightEdgeX:$i.optional(),pcbTopEdgeY:$i.optional(),pcbBottomEdgeY:$i.optional(),pcbOffsetX:V.optional(),pcbOffsetY:V.optional(),pcbRotation:tn.optional(),pcbPositionAnchor:h.string().optional(),pcbPositionMode:h.enum(["relative_to_group_anchor","auto","relative_to_board_anchor","relative_to_component_anchor"]).optional(),layer:he.optional(),pcbMarginTop:V.optional(),pcbMarginRight:V.optional(),pcbMarginBottom:V.optional(),pcbMarginLeft:V.optional(),pcbMarginX:V.optional(),pcbMarginY:V.optional(),pcbStyle:b4.optional(),pcbRelative:h.boolean().optional(),relative:h.boolean().optional()});Ct(!0);var Pw=h.object({pcbX:$i.optional(),pcbY:$i.optional(),pcbLeftEdgeX:$i.optional(),pcbRightEdgeX:$i.optional(),pcbTopEdgeY:$i.optional(),pcbBottomEdgeY:$i.optional(),pcbOffsetX:V.optional(),pcbOffsetY:V.optional(),pcbRotation:tn.optional(),pcbPositionAnchor:h.string().optional(),pcbPositionMode:h.enum(["relative_to_group_anchor","auto","relative_to_board_anchor","relative_to_component_anchor"]).optional(),pcbMarginTop:V.optional(),pcbMarginRight:V.optional(),pcbMarginBottom:V.optional(),pcbMarginLeft:V.optional(),pcbMarginX:V.optional(),pcbMarginY:V.optional(),pcbStyle:b4.optional(),schMarginTop:V.optional(),schMarginRight:V.optional(),schMarginBottom:V.optional(),schMarginLeft:V.optional(),schMarginX:V.optional(),schMarginY:V.optional(),schX:V.optional(),schY:V.optional(),schRotation:tn.optional(),layer:he.optional(),footprint:Z3t.optional(),symbol:J3t.optional(),schStyle:K3t.optional(),relative:h.boolean().optional(),schRelative:h.boolean().optional(),pcbRelative:h.boolean().optional()});Ct(!0);var Q3t=h.object({supplierPartNumbers:h.record(Lm,h.array(h.string())).optional()});Ct(!0);var tMt=h.object({providesPower:h.boolean().optional(),requiresPower:h.boolean().optional(),providesGround:h.boolean().optional(),requiresGround:h.boolean().optional(),providesVoltage:h.union([h.string(),h.number()]).optional(),requiresVoltage:h.union([h.string(),h.number()]).optional(),doNotConnect:h.boolean().optional(),includeInBoardPinout:h.boolean().optional(),highlightColor:h.string().optional(),mustBeConnected:h.boolean().optional()});Ct(!0);var oi=Pw.merge(Q3t).extend({key:h.any().optional(),name:h.string(),cadModel:UW.optional(),children:h.any().optional(),symbolName:h.string().optional(),doNotPlace:h.boolean().optional(),obstructsWithinBounds:h.boolean().optional().describe("Does this component take up all the space within its bounds on a layer. This is generally true except for when separated pin headers are being represented by a single component (in which case, chips can be placed between the pin headers) or for tall modules where chips fit underneath"),showAsTranslucentModel:h.boolean().optional().describe("Whether to show this component's CAD model as translucent in the 3D viewer."),pinAttributes:h.record(h.string(),tMt).optional()});Ct(!0);var v4=["pin1","left","pin2","right"],kw=["pin1","left","anode","pos","pin2","right","cathode","neg"],rre=V.or(h.enum(["2x","3x","4x"]));var qc=h.enum(["vertical","horizontal","pos_top","pos_bottom","pos_left","pos_right","neg_top","neg_bottom","neg_left","neg_right"]).describe("horizontal means pins go 1->2 rightward and vertical means pins go 1->2 downward (generally, positive on top)");Ct(!0);var vw=h.object({pins:h.array(h.union([h.number(),h.string()])),direction:h.union([h.literal("top-to-bottom"),h.literal("left-to-right"),h.literal("bottom-to-top"),h.literal("right-to-left")])}),Og=h.object({leftSize:h.number().optional().describe("@deprecated, use leftPinCount"),topSize:h.number().optional().describe("@deprecated, use topPinCount"),rightSize:h.number().optional().describe("@deprecated, use rightPinCount"),bottomSize:h.number().optional().describe("@deprecated, use bottomPinCount"),leftPinCount:h.number().optional(),rightPinCount:h.number().optional(),topPinCount:h.number().optional(),bottomPinCount:h.number().optional(),leftSide:vw.optional(),rightSide:vw.optional(),topSide:vw.optional(),bottomSide:vw.optional()}),w4=Og;Ct(!0);var Lg=h.record(h.object({marginLeft:V.optional(),marginRight:V.optional(),marginTop:V.optional(),marginBottom:V.optional(),leftMargin:V.optional(),rightMargin:V.optional(),topMargin:V.optional(),bottomMargin:V.optional()}));Ct(!0);var Ns=h.string().regex(/^[A-Za-z0-9_]+$/),VW=V.or(h.enum(["xs","sm","default","md"])).describe("distance between pin1 and pin2 of the schematic symbol"),r_=h.enum(["top_left","top_center","top_right","center_left","center","center_right","bottom_left","bottom_center","bottom_right"]),$o=h.object({x:V,y:V}),Fg=h.object({edit_event_id:h.string(),in_progress:h.boolean().optional(),created_at:h.number()});Ct(!0);var eMt=Fg.extend({pcb_edit_event_type:h.literal("edit_component_location").describe("deprecated"),edit_event_type:h.literal("edit_pcb_component_location"),pcb_component_id:h.string(),original_center:h.object({x:h.number(),y:h.number()}),new_center:h.object({x:h.number(),y:h.number()})});Ct(!0);var nMt=Fg.extend({pcb_edit_event_type:h.literal("edit_trace_hint").describe("deprecated"),edit_event_type:h.literal("edit_pcb_trace_hint").optional(),pcb_port_id:h.string(),pcb_trace_hint_id:h.string().optional(),route:h.array(h.object({x:h.number(),y:h.number(),via:h.boolean().optional()}))});Ct(!0);var iMt=Fg.extend({edit_event_type:h.literal("edit_schematic_component_location"),schematic_component_id:h.string(),original_center:h.object({x:h.number(),y:h.number()}),new_center:h.object({x:h.number(),y:h.number()})});Ct(!0);var Sre=Fg.extend({edit_event_type:h.literal("edit_pcb_group_location"),pcb_group_id:h.string(),original_center:h.object({x:h.number(),y:h.number()}),new_center:h.object({x:h.number(),y:h.number()})});Ct(!0);var kre=Fg.extend({edit_event_type:h.literal("edit_schematic_group_location"),schematic_group_id:h.string(),original_center:h.object({x:h.number(),y:h.number()}),new_center:h.object({x:h.number(),y:h.number()})});Ct(!0);var Ere=h.union([eMt,nMt,iMt]);Ct(!0);var rMt=h.object({selector:h.string(),relative_to:h.string().optional().default("group_center").describe("Can be a selector or 'group_center'"),center:Zt});Ct(!0);var sMt=h.object({pcb_port_selector:h.string(),offsets:h.array(tr)});Ct(!0);var oMt=h.object({selector:h.string(),relative_to:h.string().optional().default("group_center").describe("Can be a selector or 'group_center'"),center:Zt});Ct(!0);var aMt=h.object({pcb_placements:h.array(rMt).optional(),manual_trace_hints:h.array(sMt).optional(),schematic_placements:h.array(oMt).optional()});Ct(!0);var s_=h.string().or(h.array(h.string()).readonly()).or(h.array(h.string())),cd=n=>h.record(h.enum(n),s_),Rg=h.object({layoutMode:h.enum(["grid","flex","match-adapt","relative","none"]).optional(),position:h.enum(["absolute","relative"]).optional(),grid:h.boolean().optional(),gridCols:h.number().or(h.string()).optional(),gridRows:h.number().or(h.string()).optional(),gridTemplateRows:h.string().optional(),gridTemplateColumns:h.string().optional(),gridTemplate:h.string().optional(),gridGap:h.number().or(h.string()).optional(),gridRowGap:h.number().or(h.string()).optional(),gridColumnGap:h.number().or(h.string()).optional(),flex:h.boolean().or(h.string()).optional(),flexDirection:h.enum(["row","column"]).optional(),alignItems:h.enum(["start","center","end","stretch"]).optional(),justifyContent:h.enum(["start","center","end","stretch","space-between","space-around","space-evenly"]).optional(),flexRow:h.boolean().optional(),flexColumn:h.boolean().optional(),gap:h.number().or(h.string()).optional(),pack:h.boolean().optional().describe("Pack the contents of this group using a packing strategy"),packOrderStrategy:h.enum(["largest_to_smallest","first_to_last","highest_to_lowest_pin_count"]).optional(),packPlacementStrategy:h.enum(["shortest_connection_along_outline"]).optional(),padding:D.optional(),paddingLeft:D.optional(),paddingRight:D.optional(),paddingTop:D.optional(),paddingBottom:D.optional(),paddingX:D.optional(),paddingY:D.optional(),width:D.optional(),height:D.optional(),matchAdapt:h.boolean().optional(),matchAdaptTemplate:h.any().optional()});Ct(!0);var $W=h.object({strokeWidth:D.optional(),dashed:h.boolean().optional(),solid:h.boolean().optional()}),cMt=h.custom(n=>typeof n=="string"),lMt=h.object({serverUrl:h.string().optional(),inputFormat:h.enum(["simplified","circuit-json"]).optional(),serverMode:h.enum(["job","solve-endpoint"]).optional(),serverCacheEnabled:h.boolean().optional(),cache:h.custom(n=>!0).optional(),traceClearance:D.optional(),groupMode:h.enum(["sequential_trace","subcircuit","sequential-trace"]).optional(),algorithmFn:h.custom(n=>typeof n=="function"||n===void 0).optional(),preset:h.enum(["sequential_trace","subcircuit","auto","auto_local","auto_cloud","freerouting","laser_prefab","sequential-trace","auto-local","auto-cloud"]).optional(),local:h.boolean().optional()}),uMt=h.union([h.literal("sequential_trace"),h.literal("subcircuit"),h.literal("auto"),h.literal("auto_local"),h.literal("auto_cloud"),h.literal("freerouting"),h.literal("laser_prefab"),h.literal("sequential-trace"),h.literal("auto-local"),h.literal("auto-cloud")]),pMt=h.string(),GW=h.union([lMt,uMt,pMt]),S4=Pw.extend({name:h.string().optional(),children:h.any().optional(),schTitle:h.string().optional(),key:h.any().optional(),showAsSchematicBox:h.boolean().optional(),connections:h.record(h.string(),s_.optional()).optional(),schPinArrangement:w4.optional(),schPinSpacing:D.optional(),schPinStyle:Lg.optional(),...Rg.shape,grid:Rg.shape.grid.describe("@deprecated use pcbGrid"),flex:Rg.shape.flex.describe("@deprecated use pcbFlex"),pcbGrid:h.boolean().optional(),pcbGridCols:h.number().or(h.string()).optional(),pcbGridRows:h.number().or(h.string()).optional(),pcbGridTemplateRows:h.string().optional(),pcbGridTemplateColumns:h.string().optional(),pcbGridTemplate:h.string().optional(),pcbGridGap:h.number().or(h.string()).optional(),pcbGridRowGap:h.number().or(h.string()).optional(),pcbGridColumnGap:h.number().or(h.string()).optional(),pcbFlex:h.boolean().or(h.string()).optional(),pcbFlexGap:h.number().or(h.string()).optional(),pcbFlexDirection:h.enum(["row","column"]).optional(),pcbAlignItems:h.enum(["start","center","end","stretch"]).optional(),pcbJustifyContent:h.enum(["start","center","end","stretch","space-between","space-around","space-evenly"]).optional(),pcbFlexRow:h.boolean().optional(),pcbFlexColumn:h.boolean().optional(),pcbGap:h.number().or(h.string()).optional(),pcbPack:h.boolean().optional(),pcbPackGap:h.number().or(h.string()).optional(),schGrid:h.boolean().optional(),schGridCols:h.number().or(h.string()).optional(),schGridRows:h.number().or(h.string()).optional(),schGridTemplateRows:h.string().optional(),schGridTemplateColumns:h.string().optional(),schGridTemplate:h.string().optional(),schGridGap:h.number().or(h.string()).optional(),schGridRowGap:h.number().or(h.string()).optional(),schGridColumnGap:h.number().or(h.string()).optional(),schFlex:h.boolean().or(h.string()).optional(),schFlexGap:h.number().or(h.string()).optional(),schFlexDirection:h.enum(["row","column"]).optional(),schAlignItems:h.enum(["start","center","end","stretch"]).optional(),schJustifyContent:h.enum(["start","center","end","stretch","space-between","space-around","space-evenly"]).optional(),schFlexRow:h.boolean().optional(),schFlexColumn:h.boolean().optional(),schGap:h.number().or(h.string()).optional(),schPack:h.boolean().optional(),schMatchAdapt:h.boolean().optional(),pcbWidth:D.optional(),pcbHeight:D.optional(),minTraceWidth:D.optional(),schWidth:D.optional(),schHeight:D.optional(),pcbLayout:Rg.optional(),schLayout:Rg.optional(),cellBorder:$W.nullable().optional(),border:$W.nullable().optional(),schPadding:D.optional(),schPaddingLeft:D.optional(),schPaddingRight:D.optional(),schPaddingTop:D.optional(),schPaddingBottom:D.optional(),pcbPadding:D.optional(),pcbPaddingLeft:D.optional(),pcbPaddingRight:D.optional(),pcbPaddingTop:D.optional(),pcbPaddingBottom:D.optional(),pcbPositionAnchor:cMt.optional()}),WW=h.custom(n=>"findPart"in n),P4=S4.extend({manualEdits:aMt.optional(),schAutoLayoutEnabled:h.boolean().optional(),schTraceAutoLabelEnabled:h.boolean().optional(),schMaxTraceDistance:V.optional(),routingDisabled:h.boolean().optional(),defaultTraceWidth:D.optional(),minTraceWidth:D.optional(),partsEngine:WW.optional(),pcbRouteCache:h.custom(n=>!0).optional(),autorouter:GW.optional(),square:h.boolean().optional(),emptyArea:h.string().optional(),filledArea:h.string().optional(),width:V.optional(),height:V.optional(),outline:h.array($o).optional(),outlineOffsetX:V.optional(),outlineOffsetY:V.optional(),circuitJson:h.array(h.any()).optional()}),hMt=P4.extend({subcircuit:h.literal(!0)}),HW=h.discriminatedUnion("subcircuit",[S4.extend({subcircuit:h.literal(!1).optional()}),hMt]);Ct(!0);Ct(!0);Ct(!0);Ct(!0);var i_=h.custom(n=>typeof n=="string"),k4=P4.omit({connections:!0}).extend({material:h.enum(["fr4","fr1"]).default("fr4"),layers:h.union([h.literal(1),h.literal(2),h.literal(4),h.literal(6),h.literal(8)]).default(2),borderRadius:pe.optional(),thickness:pe.optional(),boardAnchorPosition:$o.optional(),boardAnchorAlignment:r_.optional(),title:h.string().optional(),solderMaskColor:i_.optional(),topSolderMaskColor:i_.optional(),bottomSolderMaskColor:i_.optional(),silkscreenColor:i_.optional(),topSilkscreenColor:i_.optional(),bottomSilkscreenColor:i_.optional(),doubleSidedAssembly:h.boolean().optional().default(!1),schematicDisabled:h.boolean().optional()});Ct(!0);var qW=S4.omit({width:!0,height:!0,children:!0}).extend({width:pe,height:pe,children:h.any().optional(),noSolderMask:h.boolean().optional(),panelizationMethod:h.enum(["tab-routing","none"]).optional(),boardGap:pe.optional(),tabWidth:pe.optional(),tabLength:pe.optional(),mouseBites:h.boolean().optional()});Ct(!0);var zre=P4.extend({padding:V.optional(),paddingLeft:V.optional(),paddingRight:V.optional(),paddingTop:V.optional(),paddingBottom:V.optional()});Ct(!0);var dMt=h.string().or(h.array(h.string()).readonly()).or(h.array(h.string())),fMt=h.custom().pipe(h.record(h.string(),dMt)),mMt=h.record(Ns,Ns.or(h.array(Ns).readonly()).or(h.array(Ns)));Ct(!0);var _Mt=h.object({manufacturerPartNumber:h.string().optional(),supplierPartNumber:h.record(Lm,h.array(h.string())).optional()}),o_=oi.extend({manufacturerPartNumber:h.string().optional(),pinLabels:mMt.optional(),showPinAliases:h.boolean().optional(),pcbPinLabels:h.record(h.string(),h.string()).optional(),internallyConnectedPins:h.array(h.array(h.union([h.string(),h.number()]))).optional(),externallyConnectedPins:h.array(h.array(h.string())).optional(),schPinArrangement:Og.optional(),schPortArrangement:Og.optional(),pinCompatibleVariants:h.array(_Mt).optional(),schPinStyle:Lg.optional(),schPinSpacing:V.optional(),schWidth:V.optional(),schHeight:V.optional(),noSchematicRepresentation:h.boolean().optional(),connections:fMt.optional()});Ct(!0);var ZW=o_;Ct(!0);var T4=oi.extend({manufacturerPartNumber:h.string().optional(),pinLabels:h.record(h.number().or(Ns),Ns.or(h.array(Ns))).optional(),schPinStyle:Lg.optional(),schPinSpacing:V.optional(),schWidth:V.optional(),schHeight:V.optional(),schDirection:h.enum(["left","right"]).optional(),schPinArrangement:w4.optional(),schPortArrangement:Og.optional(),pcbPinLabels:h.record(h.string(),h.string()).optional(),pinCount:h.union([h.literal(2),h.literal(3)]).optional(),internallyConnectedPins:h.array(h.array(h.union([h.string(),h.number()]))).optional(),connections:h.custom().pipe(h.record(h.string(),s_)).optional()});Ct(!0);var KW=T4.extend({bridgedPins:h.array(h.array(h.string())).optional(),bridged:h.boolean().optional()});Ct(!0);var Gre=oi.extend({manufacturerPartNumber:h.string().optional(),pinLabels:h.record(h.number().or(Ns),Ns.or(h.array(Ns))).optional(),schPinStyle:Lg.optional(),schPinSpacing:V.optional(),schWidth:V.optional(),schHeight:V.optional(),schDirection:h.enum(["left","right"]).optional(),schPortArrangement:Og.optional(),internallyConnectedPins:h.array(h.array(h.union([h.string(),h.number()]))).optional(),standard:h.enum(["usb_c","m2"]).optional()});Ct(!0);var JW=oi.extend({standard:h.enum(["TSC0001_36P_XALT_2025_11","0805","0603","1206"]).optional()});Ct(!0);var QW=oi.extend({currentRating:h.union([h.number(),h.string()]),voltageRating:h.union([h.number(),h.string()]).optional(),schShowRatings:h.boolean().optional(),schOrientation:qc.optional(),connections:h.record(h.string(),h.union([h.string(),h.array(h.string()).readonly(),h.array(h.string())])).optional()}),ww=h.custom().transform(n=>{if(n!==void 0)return V.parse(n)}),tH=h.discriminatedUnion("shape",[Be.omit({pcbRotation:!0,layer:!0}).extend({name:h.string().optional(),connectsTo:h.string().or(h.array(h.string())).optional(),shape:h.literal("circle"),holeDiameter:V,outerDiameter:V,padDiameter:V.optional().describe("Diameter of the copper pad"),portHints:oo.optional(),solderMaskMargin:V.optional(),coveredWithSolderMask:h.boolean().optional()}),Be.omit({layer:!0}).extend({name:h.string().optional(),connectsTo:h.string().or(h.array(h.string())).optional(),shape:h.literal("oval"),outerWidth:V,outerHeight:V,holeWidth:ww,holeHeight:ww,innerWidth:V.optional().describe("DEPRECATED use holeWidth"),innerHeight:V.optional().describe("DEPRECATED use holeHeight"),portHints:oo.optional(),solderMaskMargin:V.optional(),coveredWithSolderMask:h.boolean().optional()}),Be.omit({layer:!0}).extend({name:h.string().optional(),connectsTo:h.string().or(h.array(h.string())).optional(),shape:h.literal("pill"),rectPad:h.boolean().optional(),outerWidth:V,outerHeight:V,holeWidth:ww,holeHeight:ww,innerWidth:V.optional().describe("DEPRECATED use holeWidth"),innerHeight:V.optional().describe("DEPRECATED use holeHeight"),portHints:oo.optional(),holeOffsetX:V.optional(),holeOffsetY:V.optional(),solderMaskMargin:V.optional(),coveredWithSolderMask:h.boolean().optional()}),Be.omit({pcbRotation:!0,layer:!0}).extend({name:h.string().optional(),connectsTo:h.string().or(h.array(h.string())).optional(),shape:h.literal("circular_hole_with_rect_pad"),holeDiameter:V,rectPadWidth:V,rectPadHeight:V,rectBorderRadius:V.optional(),holeShape:h.literal("circle").optional(),padShape:h.literal("rect").optional(),portHints:oo.optional(),holeOffsetX:V.optional(),holeOffsetY:V.optional(),solderMaskMargin:V.optional(),coveredWithSolderMask:h.boolean().optional()}),Be.omit({pcbRotation:!0,layer:!0}).extend({name:h.string().optional(),connectsTo:h.string().or(h.array(h.string())).optional(),shape:h.literal("pill_hole_with_rect_pad"),holeShape:h.literal("pill"),padShape:h.literal("rect"),holeWidth:V,holeHeight:V,rectPadWidth:V,rectPadHeight:V,portHints:oo.optional(),holeOffsetX:V.optional(),holeOffsetY:V.optional(),solderMaskMargin:V.optional(),coveredWithSolderMask:h.boolean().optional()}),Be.omit({pcbRotation:!0,layer:!0}).extend({name:h.string().optional(),connectsTo:h.string().or(h.array(h.string())).optional(),shape:h.literal("hole_with_polygon_pad"),holeShape:h.enum(["circle","oval","pill","rotated_pill"]),holeDiameter:V.optional(),holeWidth:V.optional(),holeHeight:V.optional(),padOutline:h.array($o),holeOffsetX:V,holeOffsetY:V,portHints:oo.optional(),solderMaskMargin:V.optional(),coveredWithSolderMask:h.boolean().optional()})]).refine(n=>("innerWidth"in n&&n.innerWidth!==void 0&&(n.holeWidth??(n.holeWidth=n.innerWidth)),"innerHeight"in n&&n.innerHeight!==void 0&&(n.holeHeight??(n.holeHeight=n.innerHeight)),n));Ct(!0);var yMt=["pin1","pin2","pos","neg"],eH=oi.extend({resistance:Yc,pullupFor:h.string().optional(),pullupTo:h.string().optional(),pulldownFor:h.string().optional(),pulldownTo:h.string().optional(),schOrientation:qc.optional(),schSize:VW.optional(),connections:cd(yMt).optional()}),nH=v4;Ct(!0);var iH=oi.extend({maxResistance:Yc,pinVariant:h.enum(["two_pin","three_pin"]).optional()});Ct(!0);var gMt=v4,rH=oi.extend({frequency:zr,loadCapacitance:ka,manufacturerPartNumber:h.string().optional(),mpn:h.string().optional(),pinVariant:h.enum(["two_pin","four_pin"]).optional(),schOrientation:qc.optional(),connections:cd(gMt).optional()});Ct(!0);var sH=oi.extend({frequency:zr,loadCapacitance:ka,pinVariant:h.enum(["no_ground","ground_pin","two_ground_pins"]).optional()});Ct(!0);var ase=k4.extend({leftPinCount:h.number().optional(),rightPinCount:h.number().optional(),topPinCount:h.number().optional(),bottomPinCount:h.number().optional(),leftPins:h.array(h.string()).optional(),rightPins:h.array(h.string()).optional(),topPins:h.array(h.string()).optional(),bottomPins:h.array(h.string()).optional(),pinPitch:V.optional(),innerHoles:h.boolean().optional()});Ct(!0);var xMt=["pin1","pin2","pos","neg","anode","cathode"],oH=oi.extend({capacitance:ka,maxVoltageRating:pr.optional(),schShowRatings:h.boolean().optional().default(!1),polarized:h.boolean().optional().default(!1),decouplingFor:h.string().optional(),decouplingTo:h.string().optional(),bypassFor:h.string().optional(),bypassTo:h.string().optional(),maxDecouplingTraceLength:h.number().optional(),schOrientation:qc.optional(),schSize:VW.optional(),connections:cd(xMt).optional()}),aH=kw;Ct(!0);var pse=h.object({name:h.string(),connectsTo:h.string().or(h.array(h.string())).optional(),highlightColor:h.string().optional(),isPowerNet:h.boolean().optional(),isGroundNet:h.boolean().optional()});Ct(!0);var dse=h.object({name:h.string().optional(),pcbOnly:h.boolean().optional(),schOnly:h.boolean().optional()});Ct(!0);var bMt=h.object({pcb:h.literal(!0).optional(),xDist:pe,left:h.string(),right:h.string(),edgeToEdge:h.literal(!0).optional(),centerToCenter:h.literal(!0).optional()});Ct(!0);var vMt=h.object({pcb:h.literal(!0).optional(),yDist:pe,top:h.string(),bottom:h.string(),edgeToEdge:h.literal(!0).optional(),centerToCenter:h.literal(!0).optional()});Ct(!0);var wMt=h.object({pcb:h.literal(!0).optional(),sameY:h.literal(!0).optional(),for:h.array(h.string())});Ct(!0);var SMt=h.object({pcb:h.literal(!0).optional(),sameX:h.literal(!0).optional(),for:h.array(h.string())});Ct(!0);var cH=h.union([bMt,vMt,wMt,SMt]);Ct(!0);var PMt=Be.omit({layer:!0,pcbRotation:!0}).extend({name:h.string().optional(),shape:h.literal("rect"),width:pe,height:pe});Ct(!0);var kMt=Be.omit({layer:!0,pcbRotation:!0}).extend({name:h.string().optional(),shape:h.literal("circle"),radius:pe});Ct(!0);var TMt=Be.omit({layer:!0,pcbRotation:!0}).extend({name:h.string().optional(),shape:h.literal("polygon"),points:h.array($o)});Ct(!0);var lH=h.discriminatedUnion("shape",[PMt,kMt,TMt]),EMt=Be.omit({pcbRotation:!0}).extend({name:h.string().optional(),shape:h.literal("rect"),width:pe,height:pe,rectBorderRadius:pe.optional(),cornerRadius:pe.optional(),portHints:oo.optional(),coveredWithSolderMask:h.boolean().optional(),solderMaskMargin:pe.optional()});Ct(!0);var MMt=Be.omit({pcbRotation:!0}).extend({name:h.string().optional(),shape:h.literal("rotated_rect"),width:pe,height:pe,ccwRotation:h.number(),cornerRadius:pe.optional(),portHints:oo.optional(),coveredWithSolderMask:h.boolean().optional(),solderMaskMargin:pe.optional()});Ct(!0);var CMt=Be.omit({pcbRotation:!0}).extend({name:h.string().optional(),shape:h.literal("circle"),radius:pe,portHints:oo.optional(),coveredWithSolderMask:h.boolean().optional(),solderMaskMargin:pe.optional()});Ct(!0);var IMt=Be.omit({pcbRotation:!0}).extend({name:h.string().optional(),shape:h.literal("pill"),width:pe,height:pe,radius:pe,portHints:oo.optional(),coveredWithSolderMask:h.boolean().optional(),solderMaskMargin:pe.optional()});Ct(!0);var NMt=Be.omit({pcbRotation:!0}).extend({name:h.string().optional(),shape:h.literal("polygon"),points:h.array($o),portHints:oo.optional(),coveredWithSolderMask:h.boolean().optional(),solderMaskMargin:pe.optional()});Ct(!0);var uH=h.discriminatedUnion("shape",[CMt,EMt,MMt,IMt,NMt]);Ct(!0);var AMt=Be.omit({pcbRotation:!0}).extend({shape:h.literal("rect"),width:pe,height:pe});Ct(!0);var RMt=Be.omit({pcbRotation:!0}).extend({shape:h.literal("circle"),radius:pe});Ct(!0);var gse=h.union([RMt,AMt]);Ct(!0);var OMt=Be.extend({name:h.string().optional(),shape:h.literal("circle").optional(),diameter:pe.optional(),radius:pe.optional(),solderMaskMargin:pe.optional(),coveredWithSolderMask:h.boolean().optional()}).transform(n=>({...n,diameter:n.diameter??2*n.radius,radius:n.radius??n.diameter/2})),LMt=Be.extend({name:h.string().optional(),shape:h.literal("pill"),width:pe,height:pe,solderMaskMargin:pe.optional(),coveredWithSolderMask:h.boolean().optional()}),FMt=Be.extend({name:h.string().optional(),shape:h.literal("rect"),width:pe,height:pe,solderMaskMargin:pe.optional(),coveredWithSolderMask:h.boolean().optional()}),pH=h.union([OMt,LMt,FMt]);Ct(!0);var g4=h.union([h.string(),h.custom(n=>!!n.getPortSelector)]),zW=h.object({key:h.string().optional(),thickness:V.optional(),width:V.optional().describe("Alias for trace thickness"),schematicRouteHints:h.array($o).optional(),pcbRouteHints:h.array(tr).optional(),pcbPathRelativeTo:h.string().optional(),pcbPath:h.array(h.union([$o,h.string()])).optional(),pcbStraightLine:h.boolean().optional().describe("Draw a straight pcb trace between the connected points"),schDisplayLabel:h.string().optional(),schStroke:h.string().optional(),highlightColor:h.string().optional(),maxLength:V.optional()}),hH=h.union([zW.extend({path:h.array(g4)}),zW.extend({from:g4,to:g4})]),dH=h.object({children:h.any().optional(),originalLayer:he.default("top").optional(),circuitJson:h.array(h.any()).optional()});Ct(!0);var fH=h.object({originalFacingDirection:h.enum(["up","down","left","right"]).default("right").optional()});Ct(!0);var $Mt=h.number().or(h.string().endsWith("mAh")).transform(n=>{if(typeof n=="string"){let e=n.replace("mAh",""),t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error("Invalid capacity");return t}return n}).describe("Battery capacity in mAh"),mH=oi.extend({capacity:$Mt.optional(),voltage:pr.optional(),standard:h.enum(["AA","AAA","9V","CR2032","18650","C"]).optional(),schOrientation:qc.optional()});Ct(!0);var zMt=h.enum(["vertical","horizontal"]).describe("vertical means pins go 1->2 downward and horizontal means pins go 1->2 rightward");Ct(!0);var _H=oi.extend({pinCount:h.number(),pitch:V.optional(),schFacingDirection:h.enum(["up","down","left","right"]).optional(),gender:h.enum(["male","female","unpopulated"]).optional().default("male"),showSilkscreenPinLabels:h.boolean().optional(),pcbPinLabels:h.record(h.string(),h.string()).optional(),doubleRow:h.boolean().optional(),rightAngle:h.boolean().optional(),pcbOrientation:zMt.optional(),holeDiameter:V.optional(),platedDiameter:V.optional(),pinLabels:h.record(h.string(),Ns).or(h.array(Ns)).optional(),connections:h.custom().pipe(h.record(h.string(),s_)).optional(),facingDirection:h.enum(["left","right"]).optional(),schPinArrangement:w4.optional(),schPinStyle:Lg.optional(),schPinSpacing:V.optional(),schWidth:V.optional(),schHeight:V.optional()});Ct(!0);var Ase=h.object({net:h.string().optional(),connection:h.string().optional(),schX:pe.optional(),schY:pe.optional(),schRotation:tn.optional(),anchorSide:h.enum(["left","top","right","bottom"]).optional()});Ct(!0);var yH=h.object({net:h.string().optional(),connection:h.string().optional(),connectsTo:h.string().or(h.array(h.string())).optional(),schX:pe.optional(),schY:pe.optional(),schRotation:tn.optional(),anchorSide:h.enum(["left","top","right","bottom"]).optional()});Ct(!0);var gH=o_.extend({});Ct(!0);Ct(!0);var DMt=h.custom(n=>typeof n=="string"),xH=h.object({simulationType:h.literal("spice_transient_analysis").default("spice_transient_analysis"),duration:hr.optional(),timePerStep:hr.optional(),spiceEngine:DMt.optional()});Ct(!0);var jMt=["pin1","pin2","pin3","emitter","collector","base","gate","source","drain"],bH=oi.extend({type:h.enum(["npn","pnp","bjt","jfet","mosfet","igbt"]),connections:cd(jMt).optional()});Ct(!0);var vH=oi.extend({channelType:h.enum(["n","p"]),mosfetMode:h.enum(["enhancement","depletion"])});Ct(!0);var BMt=v4,wH=oi.extend({inductance:Kx,maxCurrentRating:h.union([h.string(),h.number()]).optional(),schOrientation:qc.optional(),connections:cd(BMt).optional()});Ct(!0);var YMt=h.enum(["anode","cathode","pin1","pin2","pos","neg"]),XMt=h.string().or(h.array(h.string()).readonly()).or(h.array(h.string())),UMt=h.record(YMt,XMt),VMt=h.enum(["standard","schottky","zener","avalanche","photo","tvs"]),SH=oi.extend({connections:UMt.optional(),variant:VMt.optional().default("standard"),standard:h.boolean().optional(),schottky:h.boolean().optional(),zener:h.boolean().optional(),avalanche:h.boolean().optional(),photo:h.boolean().optional(),tvs:h.boolean().optional(),schOrientation:qc.optional()}).superRefine((n,e)=>{if([n.standard,n.schottky,n.zener,n.avalanche,n.photo,n.tvs].filter(Boolean).length>1)return e.addIssue({code:h.ZodIssueCode.custom,message:"Exactly one diode variant must be enabled",path:[]}),h.INVALID}).transform(n=>{let e={...n,standard:!1,schottky:!1,zener:!1,avalanche:!1,photo:!1,tvs:!1};if(n.standard)e.standard=!0;else if(n.schottky)e.schottky=!0;else if(n.zener)e.zener=!0;else if(n.photo)e.photo=!0;else if(n.tvs)e.tvs=!0;else switch(n.variant){case"standard":e.standard=!0;break;case"schottky":e.schottky=!0;break;case"zener":e.zener=!0;break;case"avalanche":e.avalanche=!0;break;case"photo":e.photo=!0;break;case"tvs":e.tvs=!0;break;default:e.standard=!0}return e}),PH=kw;Ct(!0);var kH=oi.extend({color:h.string().optional(),wavelength:h.string().optional(),schDisplayValue:h.string().optional(),schOrientation:qc.optional(),connections:cd(kw).optional(),laser:h.boolean().optional()}),TH=kw,EH=oi.extend({type:h.enum(["spst","spdt","dpst","dpdt"]).optional(),isNormallyClosed:h.boolean().optional().default(!1),spst:h.boolean().optional(),spdt:h.boolean().optional(),dpst:h.boolean().optional(),dpdt:h.boolean().optional(),simSwitchFrequency:zr.optional(),simCloseAt:hr.optional(),simOpenAt:hr.optional(),simStartClosed:h.boolean().optional(),simStartOpen:h.boolean().optional(),connections:h.custom().pipe(h.record(h.string(),s_)).optional()}).transform(n=>{let e={...n};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});Ct(!0);var MH=Be.extend({text:h.string(),anchorAlignment:h.enum(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),font:h.enum(["tscircuit2024"]).optional(),fontSize:D.optional(),color:h.string().optional()});Ct(!0);var CH=Be.omit({pcbRotation:!0}).extend({width:V,height:V,strokeWidth:V.optional(),isFilled:h.boolean().optional(),hasStroke:h.boolean().optional(),isStrokeDashed:h.boolean().optional(),color:h.string().optional(),cornerRadius:V.optional()}),IH=Be.omit({pcbLeftEdgeX:!0,pcbRightEdgeX:!0,pcbTopEdgeY:!0,pcbBottomEdgeY:!0,pcbX:!0,pcbY:!0,pcbOffsetX:!0,pcbOffsetY:!0,pcbRotation:!0}).extend({route:h.array(tr),strokeWidth:D.optional(),color:h.string().optional()}),DW=h.union([h.string(),$o]),NH=Be.omit({pcbLeftEdgeX:!0,pcbRightEdgeX:!0,pcbTopEdgeY:!0,pcbBottomEdgeY:!0,pcbX:!0,pcbY:!0,pcbOffsetX:!0,pcbOffsetY:!0,pcbRotation:!0}).extend({from:DW,to:DW,text:h.string().optional(),offset:V.optional(),font:h.enum(["tscircuit2024"]).optional(),fontSize:D.optional(),color:h.string().optional(),arrowSize:V.optional(),units:h.enum(["in","mm"]).optional(),outerEdgeToEdge:h.literal(!0).optional(),centerToCenter:h.literal(!0).optional(),innerEdgeToEdge:h.literal(!0).optional()});Ct(!0);var eoe=h.object({layer:h.string().optional(),thickness:V.optional(),route:h.array(tr)}),AH=Pw.extend({name:h.string().optional(),fromLayer:he,toLayer:he,holeDiameter:V.optional(),outerDiameter:V.optional(),connectsTo:h.string().or(h.array(h.string())).optional(),netIsAssignable:h.boolean().optional()});Ct(!0);var GMt=h.object({pin1:s_}).strict(),RH=oi.extend({connections:GMt.optional(),footprintVariant:h.enum(["pad","through_hole"]).optional(),padShape:h.enum(["rect","circle"]).optional().default("circle"),padDiameter:V.optional(),holeDiameter:V.optional(),width:V.optional(),height:V.optional()}).refine(n=>n.footprintVariant!=="through_hole"||n.holeDiameter!==void 0,{message:"holeDiameter is required for through_hole testpoints"});Ct(!0);var OH=Be.omit({pcbRotation:!0,layer:!0}).extend({connection:h.string()});Ct(!0);var LH=h.union([Be.omit({pcbRotation:!0}).extend({shape:h.literal("circle"),radius:V}),Be.extend({shape:h.literal("rect"),width:V,height:V})]),poe=Be.omit({pcbRotation:!0}).extend({width:V,height:V,strokeWidth:V.optional(),isFilled:h.boolean().optional(),hasStroke:h.boolean().optional(),isStrokeDashed:h.boolean().optional(),color:h.string().optional()}),foe=Be.omit({pcbLeftEdgeX:!0,pcbRightEdgeX:!0,pcbTopEdgeY:!0,pcbBottomEdgeY:!0,pcbX:!0,pcbY:!0,pcbOffsetX:!0,pcbOffsetY:!0,pcbRotation:!0}).extend({outline:h.array($o),strokeWidth:D.optional(),isClosed:h.boolean().optional(),isStrokeDashed:h.boolean().optional(),color:h.string().optional()}),FH=h.object({name:h.string().optional(),layer:he,connectsTo:h.string(),padMargin:pe.optional(),traceMargin:pe.optional(),clearance:pe.optional(),boardEdgeMargin:pe.optional(),cutoutMargin:pe.optional(),coveredWithSolderMask:h.boolean().optional().default(!0)});Ct(!0);var $H=h.object({originalLayer:he.default("top").optional(),children:h.any().optional()});Ct(!0);var WMt=h.object({pcbX:$i.optional(),pcbY:$i.optional(),pcbLeftEdgeX:$i.optional(),pcbRightEdgeX:$i.optional(),pcbTopEdgeY:$i.optional(),pcbBottomEdgeY:$i.optional(),pcbOffsetX:pe.optional(),pcbOffsetY:pe.optional(),pcbZ:pe.optional()}),HMt=Hc.extend({modelUrl:h.string(),stepUrl:h.string().optional()}),qMt=HMt.merge(WMt);Ct(!0);var zH=h.union([h.null(),h.string(),qMt]),DH=oi.extend({voltage:pr}),ZMt=["pin1","pin2","pos","neg"],KMt=h.union([h.string(),h.number()]).transform(n=>typeof n=="string"?n.endsWith("%")?parseFloat(n.slice(0,-1))/100:parseFloat(n):n).pipe(h.number().min(0,"Duty cycle must be non-negative").max(1,"Duty cycle cannot be greater than 100%")),jH=oi.extend({voltage:pr.optional(),frequency:zr.optional(),peakToPeakVoltage:pr.optional(),waveShape:h.enum(["sinewave","square","triangle","sawtooth"]).optional(),phase:tn.optional(),dutyCycle:KMt.optional(),connections:cd(ZMt).optional()});Ct(!0);var BH=oi.omit({name:!0}).extend({name:h.string().optional(),connectsTo:h.string(),referenceTo:h.string().optional(),color:h.string().optional()});Ct(!0);var YH=h.object({center:Zt,radius:V,startAngleDegrees:tn,endAngleDegrees:tn,direction:h.enum(["clockwise","counterclockwise"]).default("counterclockwise"),strokeWidth:V.optional(),color:h.string().optional(),isDashed:h.boolean().optional().default(!1)}),XH=h.object({schX:V.optional(),schY:V.optional(),width:V.optional(),height:V.optional(),overlay:h.array(h.string()).optional(),padding:V.optional(),paddingLeft:V.optional(),paddingRight:V.optional(),paddingTop:V.optional(),paddingBottom:V.optional(),title:h.string().optional(),titleAlignment:r_.default("top_left"),titleColor:h.string().optional(),titleFontSize:V.optional(),titleInside:h.boolean().default(!1),strokeStyle:h.enum(["solid","dashed"]).default("solid")}).refine(n=>n.width!==void 0&&n.height!==void 0||Array.isArray(n.overlay)&&n.overlay.length>0,{message:"Must provide either both `width` and `height`, or a non-empty `overlay` array."}).refine(n=>!(n.width!==void 0&&n.height!==void 0&&Array.isArray(n.overlay)&&n.overlay.length>0),{message:"Cannot provide both `width`/`height` and `overlay` at the same time."}),UH=h.object({center:Zt,radius:V,strokeWidth:V.optional(),color:h.string().optional(),isFilled:h.boolean().optional().default(!1),fillColor:h.string().optional(),isDashed:h.boolean().optional().default(!1)}),VH=h.object({schX:V.optional(),schY:V.optional(),width:V,height:V,rotation:tn.default(0),strokeWidth:V.optional(),color:h.string().optional(),isFilled:h.boolean().optional().default(!1),fillColor:h.string().optional(),isDashed:h.boolean().optional().default(!1),cornerRadius:V.optional()}),GH=h.object({x1:V,y1:V,x2:V,y2:V,strokeWidth:V.optional(),color:h.string().optional(),isDashed:h.boolean().optional().default(!1)}),JMt=h.enum(["center","left","right","top","bottom"]),WH=h.object({schX:V.optional(),schY:V.optional(),text:h.string(),fontSize:h.number().default(1),anchor:h.union([JMt.describe("legacy"),r_]).default("center"),color:h.string().default("#000000"),schRotation:tn.default(0)}),Doe=h.object({points:h.array(Zt),isFilled:h.boolean().optional().default(!1),fillColor:h.enum(["red","blue"]).optional()}),HH=h.object({schX:V.optional(),schY:V.optional(),children:h.any().optional(),cellPadding:V.optional(),borderWidth:V.optional(),anchor:r_.optional(),fontSize:V.optional()});Ct(!0);var qH=h.object({children:h.any().optional(),height:V.optional()});Ct(!0);var ZH=h.object({children:h.string().optional(),horizontalAlign:h.enum(["left","center","right"]).optional(),verticalAlign:h.enum(["top","middle","bottom"]).optional(),fontSize:V.optional(),rowSpan:h.number().optional(),colSpan:h.number().optional(),width:V.optional(),text:h.string().optional()});Ct(!0);var Hoe=Be.extend({text:h.string(),anchorAlignment:r_.default("center"),font:h.enum(["tscircuit2024"]).optional(),fontSize:D.optional(),layers:h.array(he).optional()}),KH=Be.extend({text:h.string(),anchorAlignment:r_.default("center"),font:h.enum(["tscircuit2024"]).optional(),fontSize:D.optional(),isKnockout:h.boolean().optional(),knockoutPadding:D.optional(),knockoutPaddingLeft:D.optional(),knockoutPaddingRight:D.optional(),knockoutPaddingTop:D.optional(),knockoutPaddingBottom:D.optional(),layers:h.array(he).optional()}),JH=Be.omit({pcbLeftEdgeX:!0,pcbRightEdgeX:!0,pcbTopEdgeY:!0,pcbBottomEdgeY:!0,pcbX:!0,pcbY:!0,pcbOffsetX:!0,pcbOffsetY:!0,pcbRotation:!0}).extend({route:h.array(tr),strokeWidth:D.optional()}),QH=Be.omit({pcbX:!0,pcbY:!0,pcbOffsetX:!0,pcbOffsetY:!0,pcbRotation:!0}).extend({strokeWidth:V,x1:V,y1:V,x2:V,y2:V}),tq=Be.omit({pcbRotation:!0}).extend({filled:h.boolean().default(!0).optional(),stroke:h.enum(["dashed","solid","none"]).optional(),strokeWidth:V.optional(),width:V,height:V,cornerRadius:V.optional()}),eq=Be.omit({pcbRotation:!0}).extend({isFilled:h.boolean().optional(),isOutline:h.boolean().optional(),strokeWidth:V.optional(),radius:V}),jW=h.object({x:V,y:V,via:h.boolean().optional(),toLayer:he.optional()}),nq=h.object({for:h.string().optional().describe("Selector for the port you're targeting, not required if you're inside a trace"),order:h.number().optional(),offset:tr.or(jW).optional(),offsets:h.array(tr).or(h.array(jW)).optional(),traceWidth:h.number().optional()}),aae=Pw.extend({name:h.string(),pinNumber:h.number().optional(),aliases:h.array(h.string()).optional(),direction:j3t,connectsTo:h.string().or(h.array(h.string())).optional()}),iq=Be.extend({text:h.string(),anchorAlignment:h.enum(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),font:h.enum(["tscircuit2024"]).optional(),fontSize:D.optional(),color:h.string().optional()});Ct(!0);var rq=Be.omit({pcbRotation:!0}).extend({width:V,height:V,strokeWidth:V.optional(),isFilled:h.boolean().optional(),hasStroke:h.boolean().optional(),isStrokeDashed:h.boolean().optional(),color:h.string().optional(),cornerRadius:V.optional()});Ct(!0);var sq=Be.omit({pcbLeftEdgeX:!0,pcbRightEdgeX:!0,pcbTopEdgeY:!0,pcbBottomEdgeY:!0,pcbX:!0,pcbY:!0,pcbOffsetX:!0,pcbOffsetY:!0,pcbRotation:!0}).extend({route:h.array(tr),strokeWidth:D.optional(),color:h.string().optional()});Ct(!0);var oq=Be.omit({pcbLeftEdgeX:!0,pcbRightEdgeX:!0,pcbTopEdgeY:!0,pcbBottomEdgeY:!0,pcbX:!0,pcbY:!0,pcbOffsetX:!0,pcbOffsetY:!0,pcbRotation:!0}).extend({x1:V,y1:V,x2:V,y2:V,strokeWidth:V.optional(),color:h.string().optional(),isDashed:h.boolean().optional()});Ct(!0);var BW=h.union([h.string(),$o]),aq=Be.omit({pcbLeftEdgeX:!0,pcbRightEdgeX:!0,pcbTopEdgeY:!0,pcbBottomEdgeY:!0,pcbX:!0,pcbY:!0,pcbOffsetX:!0,pcbOffsetY:!0,pcbRotation:!0}).extend({from:BW,to:BW,text:h.string().optional(),offset:V.optional(),font:h.enum(["tscircuit2024"]).optional(),fontSize:D.optional(),color:h.string().optional(),arrowSize:V.optional(),units:h.enum(["in","mm"]).optional(),outerEdgeToEdge:h.literal(!0).optional(),centerToCenter:h.literal(!0).optional(),innerEdgeToEdge:h.literal(!0).optional()});Ct(!0);var cq=h.array(h.any()).describe("Circuit JSON"),x4=h.object({footprintCircuitJson:h.array(h.any()),cadModel:UW.optional()}),YW=h.function().args(h.string()).returns(h.promise(x4)).or(h.function().args(h.string(),h.object({resolvedPcbStyle:b4.optional()}).optional()).returns(h.promise(x4))).describe("A function that takes a path and returns Circuit JSON"),QMt=h.object({loadFromUrl:h.function().args(h.string()).returns(h.promise(x4)).describe("A function that takes a footprint file URL and returns Circuit JSON")}),tCt=h.object({engineVersionString:h.string().optional(),simulationResultCircuitJson:cq}),eCt=h.object({simulate:h.function().args(h.string()).returns(h.promise(tCt)).describe("A function that takes a SPICE string and returns a simulation result")}),nCt=h.custom(n=>typeof n=="string"),XW=h.object({run:h.function().args().returns(h.promise(h.unknown())).describe("Run the autorouter"),getOutputSimpleRouteJson:h.function().args().returns(h.promise(h.any())).describe("Get the resulting SimpleRouteJson")}),iCt=h.object({createAutorouter:h.function().args(h.any(),h.any().optional()).returns(h.union([XW,h.promise(XW)])).describe("Create an autorouter instance")}),rCt=h.object({partsEngine:WW.optional(),autorouter:GW.optional(),autorouterMap:h.record(h.string(),iCt).optional(),registryApiUrl:h.string().optional(),cloudAutorouterUrl:h.string().optional(),projectName:h.string().optional(),projectBaseUrl:h.string().optional(),version:h.string().optional(),url:h.string().optional(),printBoardInformationToSilkscreen:h.boolean().optional(),includeBoardFiles:h.array(h.string()).describe('The board files to automatically build with "tsci build", defaults to ["**/*.circuit.tsx"]. Can be an array of files or globs').optional(),snapshotsDir:h.string().describe('The directory where snapshots are stored for "tsci snapshot", defaults to "tests/__snapshots__"').optional(),defaultSpiceEngine:nCt.optional(),localCacheEngine:h.any().optional(),pcbDisabled:h.boolean().optional(),schematicDisabled:h.boolean().optional(),partsEngineDisabled:h.boolean().optional(),spiceEngineMap:h.record(h.string(),eCt).optional(),footprintLibraryMap:h.record(h.string(),h.union([YW,h.record(h.string(),h.union([cq,YW]))])).optional(),footprintFileParserMap:h.record(h.string(),QMt).optional(),resolveProjectStaticFileImportUrl:h.function().args(h.string()).returns(h.promise(h.string())).describe("A function that returns a string URL for static files for the project").optional()});Ct(!0);var sCt=rCt,xae=sCt.pick({projectName:!0,projectBaseUrl:!0,version:!0,url:!0,printBoardInformationToSilkscreen:!0,includeBoardFiles:!0,snapshotsDir:!0,defaultSpiceEngine:!0});Ct(!0);wt();Q();wt();wt();wt();Ia();Q();var Wa=Vt(Js(),1);Ia();Q();function Zc(){return new E4}var E4=class n{constructor(){f(this,"index",{});f(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){let t=this.index[e.id()];return t===void 0?void 0:this.array[t]}setDefault(e,t){let i=this.index[e.id()];if(i===void 0){let r=new Tw(e,t());return this.index[e.id()]=this.array.length,this.array.push(r),r}else return this.array[i]}insert(e,t){let i=new Tw(e,t),r=this.index[e.id()];return r===void 0?(this.index[e.id()]=this.array.length,this.array.push(i)):this.array[r]=i,i}erase(e){let t=this.index[e.id()];if(t===void 0)return;this.index[e.id()]=void 0;let i=this.array[t],r=this.array.pop();return i!==r&&(this.array[t]=r,this.index[r.first.id()]=t),i}copy(){let e=new n;for(let t=0;t<this.array.length;t++){let i=this.array[t].copy();e.array[t]=i,e.index[i.first.id()]=t}return e}},Tw=class n{constructor(e,t){f(this,"first");f(this,"second");this.first=e,this.second=t}copy(){return new n(this.first,this.second)}};var Oa=class{constructor(e=""){f(this,"_name");f(this,"_value",0);f(this,"_context",null);f(this,"_id",oCt++);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 Dn(this,e)}minus(e){return new Dn(this,typeof e=="number"?-e:[-1,e])}multiply(e){return new Dn([e,this])}divide(e){return new Dn([1/e,this])}toJSON(){return{name:this._name,value:this._value}}toString(){return this._context+"["+this._name+":"+this._value+"]"}},oCt=0;var Dn=class n{constructor(){f(this,"_terms");f(this,"_constant");let e=aCt(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,i=this._terms.size();t<i;t++){let r=this._terms.itemAt(t);e+=r.first.value()*r.second}return e}plus(e){return new n(this,e)}minus(e){return new n(this,typeof e=="number"?-e:[-1,e])}multiply(e){return new n([e,this])}divide(e){return new n([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 aCt(n){let e=0,t=()=>0,i=Zc();for(let r=0,s=n.length;r<s;++r){let o=n[r];if(typeof o=="number")e+=o;else if(o instanceof Oa)i.setDefault(o,t).second+=1;else if(o instanceof Dn){e+=o.constant();let a=o.terms();for(let c=0,l=a.size();c<l;c++){let u=a.itemAt(c);i.setDefault(u.first,t).second+=u.second}}else if(o instanceof Array){if(o.length!==2)throw new Error("array must have length 2");let a=o[0],c=o[1];if(typeof a!="number")throw new Error("array item 0 must be a number");if(c instanceof Oa)i.setDefault(c,t).second+=a;else if(c instanceof Dn){e+=c.constant()*a;let l=c.terms();for(let u=0,p=l.size();u<p;u++){let d=l.itemAt(u);i.setDefault(d.first,t).second+=d.second*a}}else throw new Error("array item 1 must be a variable or expression")}else throw new Error("invalid Expression argument: "+o)}return{terms:i,constant:e}}var ao=class ao{static create(e,t,i,r=1){let s=0;return s+=Math.max(0,Math.min(1e3,e*r))*1e6,s+=Math.max(0,Math.min(1e3,t*r))*1e3,s+=Math.max(0,Math.min(1e3,i*r)),s}static clip(e){return Math.max(0,Math.min(ao.required,e))}};f(ao,"required",ao.create(1e3,1e3,1e3)),f(ao,"strong",ao.create(1,0,0)),f(ao,"medium",ao.create(0,1,0)),f(ao,"weak",ao.create(0,0,1));var On=ao;var ai;(function(n){n[n.Le=0]="Le",n[n.Ge=1]="Ge",n[n.Eq=2]="Eq"})(ai||(ai={}));var ki=class{constructor(e,t,i,r=On.required){f(this,"_expression");f(this,"_operator");f(this,"_strength");f(this,"_id",cCt++);this._operator=t,this._strength=On.clip(r),i===void 0&&e instanceof Dn?this._expression=e:this._expression=e.minus(i)}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()+")"}},cCt=0;var a_=class{constructor(){f(this,"maxIterations",1e3);f(this,"_cnMap",lCt());f(this,"_rowMap",uCt());f(this,"_varMap",pCt());f(this,"_editMap",hCt());f(this,"_infeasibleRows",[]);f(this,"_objective",new Cw);f(this,"_artificial",null);f(this,"_idTick",0)}createConstraint(e,t,i,r=On.required){let s=new ki(e,t,i,r);return this.addConstraint(s),s}addConstraint(e){if(this._cnMap.find(e)!==void 0)throw new Error("duplicate constraint");let i=this._createRow(e),r=i.row,s=i.tag,o=this._chooseSubject(r,s);if(o.type()===rn.Invalid&&r.allDummies())if(Ew(r.constant()))o=s.marker;else throw new Error("unsatisfiable constraint");if(o.type()===rn.Invalid){if(!this._addWithArtificialVariable(r))throw new Error("unsatisfiable constraint")}else r.solveFor(o),this._substitute(o,r),this._rowMap.insert(o,r);this._cnMap.insert(e,s),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 i=t.second.marker,r=this._rowMap.erase(i);if(r===void 0){let s=this._getMarkerLeavingSymbol(i);if(s.type()===rn.Invalid)throw new Error("failed to find leaving row");r=this._rowMap.erase(s),r.second.solveForEx(s,i),this._substitute(i,r.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=On.clip(t),t===On.required)throw new Error("bad required strength");let r=new Dn(e),s=new ki(r,ai.Eq,void 0,t);this.addConstraint(s);let a={tag:this._cnMap.find(s).second,constraint:s,constant:0};this._editMap.insert(e,a)}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 i=this._editMap.find(e);if(i===void 0)throw new Error("unknown edit variable");let r=this._rowMap,s=i.second,o=t-s.constant;s.constant=t;let a=s.tag.marker,c=r.find(a);if(c!==void 0){c.second.add(-o)<0&&this._infeasibleRows.push(a),this._dualOptimize();return}let l=s.tag.other;if(c=r.find(l),c!==void 0){c.second.add(o)<0&&this._infeasibleRows.push(l),this._dualOptimize();return}for(let u=0,p=r.size();u<p;++u){let d=r.itemAt(u),_=d.second,g=_.coefficientFor(a);g!==0&&_.add(o*g)<0&&d.first.type()!==rn.External&&this._infeasibleRows.push(d.first)}this._dualOptimize()}updateVariables(){let e=this._varMap,t=this._rowMap;for(let i=0,r=e.size();i<r;++i){let s=e.itemAt(i),o=t.find(s.second);o!==void 0?s.first.setValue(o.second.constant()):s.first.setValue(0)}}_getVarSymbol(e){let t=()=>this._makeSymbol(rn.External);return this._varMap.setDefault(e,t).second}_createRow(e){let t=e.expression(),i=new Cw(t.constant()),r=t.terms();for(let c=0,l=r.size();c<l;++c){let u=r.itemAt(c);if(!Ew(u.second)){let p=this._getVarSymbol(u.first),d=this._rowMap.find(p);d!==void 0?i.insertRow(d.second,u.second):i.insertSymbol(p,u.second)}}let s=this._objective,o=e.strength(),a={marker:Kc,other:Kc};switch(e.op()){case ai.Le:case ai.Ge:{let c=e.op()===ai.Le?1:-1,l=this._makeSymbol(rn.Slack);if(a.marker=l,i.insertSymbol(l,c),o<On.required){let u=this._makeSymbol(rn.Error);a.other=u,i.insertSymbol(u,-c),s.insertSymbol(u,o)}break}case ai.Eq:{if(o<On.required){let c=this._makeSymbol(rn.Error),l=this._makeSymbol(rn.Error);a.marker=c,a.other=l,i.insertSymbol(c,-1),i.insertSymbol(l,1),s.insertSymbol(c,o),s.insertSymbol(l,o)}else{let c=this._makeSymbol(rn.Dummy);a.marker=c,i.insertSymbol(c)}break}}return i.constant()<0&&i.reverseSign(),{row:i,tag:a}}_chooseSubject(e,t){let i=e.cells();for(let s=0,o=i.size();s<o;++s){let a=i.itemAt(s);if(a.first.type()===rn.External)return a.first}let r=t.marker.type();return(r===rn.Slack||r===rn.Error)&&e.coefficientFor(t.marker)<0?t.marker:(r=t.other.type(),(r===rn.Slack||r===rn.Error)&&e.coefficientFor(t.other)<0?t.other:Kc)}_addWithArtificialVariable(e){let t=this._makeSymbol(rn.Slack);this._rowMap.insert(t,e.copy()),this._artificial=e.copy(),this._optimize(this._artificial);let i=Ew(this._artificial.constant());this._artificial=null;let r=this._rowMap.erase(t);if(r!==void 0){let o=r.second;if(o.isConstant())return i;let a=this._anyPivotableSymbol(o);if(a.type()===rn.Invalid)return!1;o.solveForEx(t,a),this._substitute(a,o),this._rowMap.insert(a,o)}let s=this._rowMap;for(let o=0,a=s.size();o<a;++o)s.itemAt(o).second.removeSymbol(t);return this._objective.removeSymbol(t),i}_substitute(e,t){let i=this._rowMap;for(let r=0,s=i.size();r<s;++r){let o=i.itemAt(r);o.second.substitute(e,t),o.second.constant()<0&&o.first.type()!==rn.External&&this._infeasibleRows.push(o.first)}this._objective.substitute(e,t),this._artificial&&this._artificial.substitute(e,t)}_optimize(e){let t=0;for(;t<this.maxIterations;){let i=this._getEnteringSymbol(e);if(i.type()===rn.Invalid)return;let r=this._getLeavingSymbol(i);if(r.type()===rn.Invalid)throw new Error("the objective is unbounded");let s=this._rowMap.erase(r).second;s.solveForEx(r,i),this._substitute(i,s),this._rowMap.insert(i,s),t++}throw new Error("solver iterations exceeded")}_dualOptimize(){let e=this._rowMap,t=this._infeasibleRows;for(;t.length!==0;){let i=t.pop(),r=e.find(i);if(r!==void 0&&r.second.constant()<0){let s=this._getDualEnteringSymbol(r.second);if(s.type()===rn.Invalid)throw new Error("dual optimize failed");let o=r.second;e.erase(i),o.solveForEx(i,s),this._substitute(s,o),e.insert(s,o)}}}_getEnteringSymbol(e){let t=e.cells();for(let i=0,r=t.size();i<r;++i){let s=t.itemAt(i),o=s.first;if(s.second<0&&o.type()!==rn.Dummy)return o}return Kc}_getDualEnteringSymbol(e){let t=Number.MAX_VALUE,i=Kc,r=e.cells();for(let s=0,o=r.size();s<o;++s){let a=r.itemAt(s),c=a.first,l=a.second;if(l>0&&c.type()!==rn.Dummy){let p=this._objective.coefficientFor(c)/l;p<t&&(t=p,i=c)}}return i}_getLeavingSymbol(e){let t=Number.MAX_VALUE,i=Kc,r=this._rowMap;for(let s=0,o=r.size();s<o;++s){let a=r.itemAt(s),c=a.first;if(c.type()!==rn.External){let l=a.second,u=l.coefficientFor(e);if(u<0){let p=-l.constant()/u;p<t&&(t=p,i=c)}}}return i}_getMarkerLeavingSymbol(e){let t=Number.MAX_VALUE,i=t,r=t,s=Kc,o=s,a=s,c=s,l=this._rowMap;for(let u=0,p=l.size();u<p;++u){let d=l.itemAt(u),_=d.second,g=_.coefficientFor(e);if(g===0)continue;let x=d.first;if(x.type()===rn.External)c=x;else if(g<0){let v=-_.constant()/g;v<i&&(i=v,o=x)}else{let v=_.constant()/g;v<r&&(r=v,a=x)}}return o!==s?o:a!==s?a:c}_removeConstraintEffects(e,t){t.marker.type()===rn.Error&&this._removeMarkerEffects(t.marker,e.strength()),t.other.type()===rn.Error&&this._removeMarkerEffects(t.other,e.strength())}_removeMarkerEffects(e,t){let i=this._rowMap.find(e);i!==void 0?this._objective.insertRow(i.second,-t):this._objective.insertSymbol(e,-t)}_anyPivotableSymbol(e){let t=e.cells();for(let i=0,r=t.size();i<r;++i){let s=t.itemAt(i),o=s.first.type();if(o===rn.Slack||o===rn.Error)return s.first}return Kc}_makeSymbol(e){return new Mw(e,this._idTick++)}};function Ew(n){let e=1e-8;return n<0?-n<e:n<e}function lCt(){return Zc()}function uCt(){return Zc()}function pCt(){return Zc()}function hCt(){return Zc()}var rn;(function(n){n[n.Invalid=0]="Invalid",n[n.External=1]="External",n[n.Slack=2]="Slack",n[n.Error=3]="Error",n[n.Dummy=4]="Dummy"})(rn||(rn={}));var Mw=class{constructor(e,t){f(this,"_id");f(this,"_type");this._id=t,this._type=e}id(){return this._id}type(){return this._type}},Kc=new Mw(rn.Invalid,-1),Cw=class n{constructor(e=0){f(this,"_cellMap",Zc());f(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,i=e.size();t<i;++t)if(e.itemAt(t).first.type()!==rn.Dummy)return!1;return!0}copy(){let e=new n(this._constant);return e._cellMap=this._cellMap.copy(),e}add(e){return this._constant+=e}insertSymbol(e,t=1){let i=this._cellMap.setDefault(e,()=>0);Ew(i.second+=t)&&this._cellMap.erase(e)}insertRow(e,t=1){this._constant+=e._constant*t;let i=e._cellMap;for(let r=0,s=i.size();r<s;++r){let o=i.itemAt(r);this.insertSymbol(o.first,o.second*t)}}removeSymbol(e){this._cellMap.erase(e)}reverseSign(){this._constant=-this._constant;let e=this._cellMap;for(let t=0,i=e.size();t<i;++t){let r=e.itemAt(t);r.second=-r.second}}solveFor(e){let t=this._cellMap,r=-1/t.erase(e).second;this._constant*=r;for(let s=0,o=t.size();s<o;++s)t.itemAt(s).second*=r}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 i=this._cellMap.erase(e);i!==void 0&&this.insertRow(t,i.second)}};var Mnt=Vt(In(),1);Q();wt();wt();ir();var A4={};$c(A4,{areBoundsCompletelyInsidePolygon:()=>N4,areBoundsOverlappingPolygon:()=>I4,boundsAreaOverlap:()=>vq,boundsDistance:()=>wq,boundsIntersection:()=>Sq,clamp:()=>Wn,computeDistanceBetweenBoxes:()=>Fo,computeGapBetweenBoxes:()=>m4,computeManhattanDistanceBetweenBoxes:()=>Ng,distSq:()=>fq,distance:()=>zi,doBoundsOverlap:()=>Jc,doSegmentsIntersect:()=>Ti,doesLineIntersectLine:()=>La,doesSegmentIntersectRect:()=>M4,findNearestPointsBetweenBoxSets:()=>Ag,getBoundingBox:()=>so,getBoundsFromPoints:()=>co,getSegmentIntersection:()=>pd,getUnitVectorFromDirection:()=>Ow,getUnitVectorFromPointAToB:()=>Rw,grid:()=>Pq,isPointInsidePolygon:()=>Aw,isRectCompletelyInsidePolygon:()=>xq,isRectOverlappingPolygon:()=>gq,midpoint:()=>dq,normalizeDegrees:()=>hd,onSegment:()=>ud,orientation:()=>ld,pointToBoundsDistance:()=>hq,pointToBoxDistance:()=>pq,pointToSegmentClosestPoint:()=>uq,pointToSegmentDistance:()=>gi,range:()=>bq,segmentToBoundsMinDistance:()=>$g,segmentToBoxMinDistance:()=>Iw,segmentToCircleMinDistance:()=>Nw,segmentToSegmentMinDistance:()=>c_});function La([n,e],[t,i],{lineThickness:r=0}={}){return r===0?Ti(n,e,t,i):dCt(n,e,t,i)<=r}function Ti(n,e,t,i){let r=ld(n,e,t),s=ld(n,e,i),o=ld(t,i,n),a=ld(t,i,e);return!!(r!==s&&o!==a||r===0&&ud(n,t,e)||s===0&&ud(n,i,e)||o===0&&ud(t,n,i)||a===0&&ud(t,e,i))}function ld(n,e,t){let i=(e.y-n.y)*(t.x-e.x)-(e.x-n.x)*(t.y-e.y);return i===0?0:i>0?1:2}function ud(n,e,t){return e.x<=Math.max(n.x,t.x)&&e.x>=Math.min(n.x,t.x)&&e.y<=Math.max(n.y,t.y)&&e.y>=Math.min(n.y,t.y)}function dCt(n,e,t,i){if(n.x===e.x&&n.y===e.y)return gi(n,t,i);if(t.x===i.x&&t.y===i.y)return gi(t,n,e);if(Ti(n,e,t,i))return 0;let r=[gi(n,t,i),gi(e,t,i),gi(t,n,e),gi(i,n,e)];return Math.min(...r)}function gi(n,e,t){let i=(t.x-e.x)**2+(t.y-e.y)**2;if(i===0)return zi(n,e);let r=((n.x-e.x)*(t.x-e.x)+(n.y-e.y)*(t.y-e.y))/i;r=Math.max(0,Math.min(1,r));let s={x:e.x+r*(t.x-e.x),y:e.y+r*(t.y-e.y)};return zi(n,s)}function zi(n,e){let t=n.x-e.x,i=n.y-e.y;return Math.sqrt(t*t+i*i)}function pd(n,e,t,i){let r=e.x-n.x,s=e.y-n.y,o=i.x-t.x,a=i.y-t.y,c=n.x-t.x,l=n.y-t.y,u=r*a-s*o;if(Math.abs(u)<1e-10)return null;let p=(l*o-c*a)/u,d=(r*l-s*c)/u,_=1e-9;if(p>=-_&&p<=1+_&&d>=-_&&d<=1+_){let g=n.x+p*r,x=n.y+p*s;return{x:g,y:x}}return null}function M4(n,e,t){let i=c=>c.x>=t.minX&&c.x<=t.maxX&&c.y>=t.minY&&c.y<=t.maxY;if(i(n)||i(e))return!0;let r={x:t.minX,y:t.minY},s={x:t.maxX,y:t.minY},o={x:t.minX,y:t.maxY},a={x:t.maxX,y:t.maxY};return Ti(n,e,r,s)||Ti(n,e,s,a)||Ti(n,e,a,o)||Ti(n,e,o,r)}function c_(n,e,t,i){if(n.x===e.x&&n.y===e.y)return gi(n,t,i);if(t.x===i.x&&t.y===i.y)return gi(t,n,e);if(Ti(n,e,t,i))return 0;let r=[gi(n,t,i),gi(e,t,i),gi(t,n,e),gi(i,n,e)];return Math.min(...r)}function $g(n,e,t){let i={x:t.minX,y:t.minY},r={x:t.maxX,y:t.minY},s={x:t.minX,y:t.maxY},o={x:t.maxX,y:t.maxY};if(Ti(n,e,i,r)||Ti(n,e,r,o)||Ti(n,e,o,s)||Ti(n,e,s,i)||n.x>=t.minX&&n.x<=t.maxX&&n.y>=t.minY&&n.y<=t.maxY&&e.x>=t.minX&&e.x<=t.maxX&&e.y>=t.minY&&e.y<=t.maxY)return 0;let a=[gi(i,n,e),gi(r,n,e),gi(s,n,e),gi(o,n,e)];if(n.x>=t.minX&&n.x<=t.maxX&&n.y>=t.minY&&n.y<=t.maxY||e.x>=t.minX&&e.x<=t.maxX&&e.y>=t.minY&&e.y<=t.maxY)return 0;if(n.x<t.minX||n.x>t.maxX||n.y<t.minY||n.y>t.maxY){let c=Wn(n.x,t.minX,t.maxX),l=Wn(n.y,t.minY,t.maxY);a.push(zi(n,{x:c,y:l}))}if(e.x<t.minX||e.x>t.maxX||e.y<t.minY||e.y>t.maxY){let c=Wn(e.x,t.minX,t.maxX),l=Wn(e.y,t.minY,t.maxY);a.push(zi(e,{x:c,y:l}))}return Math.min(...a)}function Iw(n,e,t){let i=t.width/2,r=t.height/2,s={minX:t.center.x-i,maxX:t.center.x+i,minY:t.center.y-r,maxY:t.center.y+r};return $g(n,e,s)}function Nw(n,e,t){let i={x:t.x,y:t.y};if(n.x===e.x&&n.y===e.y)return Math.max(0,zi(n,i)-t.radius);let r={x:e.x-n.x,y:e.y-n.y},s={x:i.x-n.x,y:i.y-n.y},o=r.x*r.x+r.y*r.y,a=Math.max(0,Math.min(1,(r.x*s.x+r.y*s.y)/o)),c={x:n.x+a*r.x,y:n.y+a*r.y},l=zi(c,i);return Math.max(0,l-t.radius)}function uq(n,e,t){let i=t.x-e.x,r=t.y-e.y,s=i*i+r*r;if(s===0)return{x:e.x,y:e.y};let o=((n.x-e.x)*i+(n.y-e.y)*r)/s;return o=Math.max(0,Math.min(1,o)),{x:e.x+o*i,y:e.y+o*r}}function hd(n){return(n%360+360)%360}function pq(n,e){let t=e.width/2,i=e.height/2,r=e.center.x-t,s=e.center.x+t,o=e.center.y-i,a=e.center.y+i;if(n.x>=r&&n.x<=s&&n.y>=o&&n.y<=a)return 0;let c=Wn(n.x,r,s),l=Wn(n.y,o,a);return zi(n,{x:c,y:l})}function hq(n,e){if(n.x>=e.minX&&n.x<=e.maxX&&n.y>=e.minY&&n.y<=e.maxY)return 0;let t=Wn(n.x,e.minX,e.maxX),i=Wn(n.y,e.minY,e.maxY);return zi(n,{x:t,y:i})}function dq(n,e){return{x:(n.x+e.x)/2,y:(n.y+e.y)/2}}function fq(n,e){let t=n.x-e.x,i=n.y-e.y;return t*t+i*i}var mq=n=>{if("minX"in n)return n;let e=n.width/2,t=n.height/2;return{minX:n.center.x-e,minY:n.center.y-t,maxX:n.center.x+e,maxY:n.center.y+t}},C4=n=>[{x:n.minX,y:n.minY},{x:n.maxX,y:n.minY},{x:n.maxX,y:n.maxY},{x:n.minX,y:n.maxY}],_q=n=>{let e=[];for(let t=0;t<n.length;t++){let i=n[t],r=n[(t+1)%n.length];e.push([i,r])}return e},fCt=(n,e,t)=>{let i=(n.y-e.y)*(t.x-e.x)-(n.x-e.x)*(t.y-e.y);if(Math.abs(i)>1e-9)return!1;let r=(n.x-e.x)*(t.x-e.x)+(n.y-e.y)*(t.y-e.y);if(r<0)return!1;let s=(t.x-e.x)**2+(t.y-e.y)**2;return!(r>s)},mCt=(n,e)=>n.x>=e.minX&&n.x<=e.maxX&&n.y>=e.minY&&n.y<=e.maxY,Aw=(n,e)=>{if(e.length<3)return!1;let t=_q(e);for(let[r,s]of t)if(fCt(n,r,s))return!0;let i=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){let o=e[r].x,a=e[r].y,c=e[s].x,l=e[s].y;a>n.y!=l>n.y&&n.x<(c-o)*(n.y-a)/(l-a)+o&&(i=!i)}return i},yq=(n,e)=>{let t=C4(n),i=[[t[0],t[1]],[t[1],t[2]],[t[2],t[3]],[t[3],t[0]]],r=_q(e);for(let[s,o]of r)for(let[a,c]of i)if(Ti(s,o,a,c))return!0;return!1},I4=(n,e)=>e.length<3?!1:e.some(i=>mCt(i,n))||C4(n).some(i=>Aw(i,e))?!0:yq(n,e),N4=(n,e)=>e.length<3||!C4(n).every(i=>Aw(i,e))?!1:!yq(n,e),gq=(n,e)=>I4(mq(n),e),xq=(n,e)=>N4(mq(n),e);function bq(n,e,t=1){if(t===0)throw new Error("step cannot be 0");let i,r;e===void 0?(i=0,r=n):(i=n,r=e);let s=[];if(t>0)for(let o=i;o<r;o+=t)s.push(o);else for(let o=i;o>r;o+=t)s.push(o);return s}var vq=(n,e)=>{let t=Math.max(0,Math.min(n.maxX,e.maxX)-Math.max(n.minX,e.minX)),i=Math.max(0,Math.min(n.maxY,e.maxY)-Math.max(n.minY,e.minY));return t*i};var wq=(n,e)=>{let t=n.maxX<e.minX?e.minX-n.maxX:e.maxX<n.minX?n.minX-e.maxX:0,i=n.maxY<e.minY?e.minY-n.maxY:e.maxY<n.minY?n.minY-e.maxY:0;return Math.sqrt(t*t+i*i)};var Sq=(n,e)=>{let t=Math.max(n.minX,e.minX),i=Math.max(n.minY,e.minY),r=Math.min(n.maxX,e.maxX),s=Math.min(n.maxY,e.maxY);return t>r||i>s?null:{minX:t,minY:i,maxX:r,maxY:s}};var Jc=(n,e)=>!(n.maxX<e.minX||e.maxX<n.minX||n.maxY<e.minY||e.maxY<n.minY);var co=n=>{if(n.length===0)return null;let e=n[0].x,t=n[0].y,i=n[0].x,r=n[0].y;for(let s=1;s<n.length;s++){let o=n[s];o.x<e&&(e=o.x),o.y<t&&(t=o.y),o.x>i&&(i=o.x),o.y>r&&(r=o.y)}return{minX:e,minY:t,maxX:i,maxY:r}};var Rw=(n,e)=>{let t={x:e.x-n.x,y:e.y-n.y},i=Math.sqrt(t.x**2+t.y**2);return{x:t.x/i,y:t.y/i}},Ow=n=>{switch(n){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}}};function Pq({rows:n,cols:e,xSpacing:t,ySpacing:i,width:r,height:s,offsetX:o=0,offsetY:a=0,yDirection:c="cartesian",centered:l=!0}){let u=t??1,p=i??1,d=r??e*u,_=s??n*p,g=l?-d/2:0,x=l?-_/2:0,v=r?r/e:u,S=s?s/n:p,P=[];for(let T=0;T<n;T++)for(let k=0;k<e;k++){let N=T*e+k,E=o+g+k*v+v/2,C=a+T*S+S/2,M=c==="cartesian"?a+x+(n-1-T)*S+S/2:a+x+T*S+S/2;P.push({index:N,center:{x:E,y:M},topLeft:{x:E-v/2,y:M+S/2},bottomRight:{x:E+v/2,y:M-S/2},row:T,col:k})}return P}wt();zg();var kq={name:"@tscircuit/capacity-autorouter",main:"./dist/index.js",version:"0.0.140",type:"module",files:["dist"],scripts:{start:"cosmos",build:"tsup ./lib/index.ts --minify terser --external @tscircuit/core --external circuit-to-svg --format esm --dts --sourcemap",bench:"bun test tests/spatial-index-bench.test.ts",format:"biome format --write .","format:check":"biome format .","vercel-build":"cosmos-export","repomix:lib":"repomix --ignore 'testing/**,**/TwoRouteHighDensitySolver/**,**/RouteStitchingSolver/**,solvers/CapacitySegmentPointOptimizer/CapacitySegmentPointOptimizer.ts' lib","bug-report":"bun run scripts/download-bug-report.ts","bug-report-with-test":"bun run scripts/create-bug-report-test.ts"},devDependencies:{"@biomejs/biome":"^1.9.4","@radix-ui/react-icons":"^1.3.2","@radix-ui/react-menubar":"^1.1.14","@react-hook/resize-observer":"^2.0.2","@resvg/resvg-js":"^2.6.2","@tscircuit/checks":"^0.0.75","@tscircuit/circuit-json-util":"^0.0.46","@tscircuit/core":"^0.0.337","@tscircuit/math-utils":"^0.0.27","@types/bun":"^1.2.23","@types/fast-json-stable-stringify":"^2.1.2","@types/object-hash":"^3.0.6","@types/rbush":"^4.0.0","@types/react":"^19.0.8","@types/react-dom":"^19.0.3","@vercel/node":"^5.1.7","@vitejs/plugin-react":"^4.3.4","circuit-json-to-connectivity-map":"^0.0.19","circuit-to-svg":"^0.0.220",clsx:"^2.1.1",flatbush:"^4.4.0","graphics-debug":"^0.0.44","looks-same":"9",rbush:"^4.0.1",react:"18","react-cosmos":"^6.2.3","react-cosmos-plugin-vite":"^6.2.0","react-dom":"18","react-konva":"18",recharts:"^2.15.1","tailwind-merge":"^3.2.0",terser:"^5.43.1",tsup:"^8.3.6",typescript:"^5.9.3","use-mouse-matrix-transform":"^1.3.0",vite:"^6.0.11","vite-tsconfig-paths":"^5.1.4"},dependencies:{"fast-json-stable-stringify":"^2.1.0","object-hash":"^3.0.0"}};wt();ir();Ae();var b9=Vt(Js(),1);wt();var Lnt=Vt(In(),1);var lN={};$c(lN,{AssignableViaAutoroutingPipelineSolver:()=>o5t,AutoroutingPipelineSolver:()=>HZ,CapacityMeshSolver:()=>t5t,InMemoryCache:()=>IZ,LocalStorageCache:()=>NZ,calculateOptimalCapacityDepth:()=>sN,convertSrjToGraphicsObject:()=>Kg,getGlobalInMemoryCache:()=>x_,getGlobalLocalStorageCache:()=>AZ,getTunedTotalCapacity1:()=>uo,setupGlobalCaches:()=>Zg});var CZ=Vt(zw(),1),YZ=Vt(zw(),1),VZ=Vt(zw(),1);var yd=(...n)=>{let e={points:[],lines:[],circles:[],rects:[]};return n.forEach((t,i)=>{t&&(t.lines&&(e.lines=[...e.lines||[],...t.lines.map(r=>({...r,step:i}))]),t.points&&(e.points=[...e.points||[],...t.points.map(r=>({...r,step:i}))]),t.circles&&(e.circles=[...e.circles||[],...t.circles.map(r=>({...r,step:i}))]),t.rects&&(e.rects=[...e.rects||[],...t.rects.map(r=>({...r,step:i}))]))}),e},cn=class{constructor(){f(this,"MAX_ITERATIONS",1e3);f(this,"solved",!1);f(this,"failed",!1);f(this,"iterations",0);f(this,"progress",0);f(this,"error",null);f(this,"activeSubSolver");f(this,"failedSubSolvers");f(this,"timeToSolve");f(this,"stats",{});f(this,"cacheHit");f(this,"cacheKey");f(this,"cacheToSolveSpaceTransform")}step(){if(!this.solved&&!this.failed){this.iterations++;try{this._step()}catch(n){throw this.error=`${this.constructor.name} error: ${n}`,console.error(this.error),this.failed=!0,n}!this.solved&&this.iterations>this.MAX_ITERATIONS&&this.tryFinalAcceptance(),!this.solved&&this.iterations>this.MAX_ITERATIONS&&(this.error=`${this.constructor.name} ran out of iterations`,console.error(this.error),this.failed=!0),"computeProgress"in this&&(this.progress=this.computeProgress())}}_step(){}getConstructorParams(){throw new Error("getConstructorParams not implemented")}solve(){let n=Date.now();for(;!this.solved&&!this.failed;)this.step();let e=Date.now();this.timeToSolve=e-n}visualize(){return{lines:[],points:[],rects:[],circles:[]}}tryFinalAcceptance(){}preview(){return{lines:[],points:[],rects:[],circles:[]}}};function Dq(n){let e=n.width/2,t=n.height/2;return{minX:n.center.x-e,maxX:n.center.x+e,minY:n.center.y-t,maxY:n.center.y+t}}function nl(n,e,t){return Math.max(e,Math.min(t,n))}function Di(n,e,t,i){let r=Dw(n,e,t),s=Dw(n,e,i),o=Dw(t,i,n),a=Dw(t,i,e);return r!==s&&o!==a||!(r!==0||!jw(n,t,e))||!(s!==0||!jw(n,i,e))||!(o!==0||!jw(t,n,i))||!(a!==0||!jw(t,e,i))}function Dw(n,e,t){let i=(e.y-n.y)*(t.x-e.x)-(e.x-n.x)*(t.y-e.y);return i===0?0:i>0?1:2}function jw(n,e,t){return e.x<=Math.max(n.x,t.x)&&e.x>=Math.min(n.x,t.x)&&e.y<=Math.max(n.y,t.y)&&e.y>=Math.min(n.y,t.y)}function _r(n,e,t){let i=(t.x-e.x)**2+(t.y-e.y)**2;if(i===0)return Qt(n,e);let r=((n.x-e.x)*(t.x-e.x)+(n.y-e.y)*(t.y-e.y))/i;return r=Math.max(0,Math.min(1,r)),Qt(n,{x:e.x+r*(t.x-e.x),y:e.y+r*(t.y-e.y)})}function Qt(n,e){let t=n.x-e.x,i=n.y-e.y;return Math.sqrt(t*t+i*i)}function hZ(n,e,t,i){let r=e.x-n.x,s=e.y-n.y,o=i.x-t.x,a=i.y-t.y,c=n.x-t.x,l=n.y-t.y,u=r*a-s*o;if(Math.abs(u)<1e-10)return null;let p=(l*o-c*a)/u,d=(r*l-s*c)/u,_=1e-9;return p>=-1e-9&&p<=1+_&&d>=-1e-9&&d<=1+_?{x:n.x+p*r,y:n.y+p*s}:null}function jq(n,e){return{x:(n.x+e.x)/2,y:(n.y+e.y)/2}}var dZ=n=>{if("minX"in n)return n;let e=n.width/2,t=n.height/2;return{minX:n.center.x-e,minY:n.center.y-t,maxX:n.center.x+e,maxY:n.center.y+t}},rN=n=>[{x:n.minX,y:n.minY},{x:n.maxX,y:n.minY},{x:n.maxX,y:n.maxY},{x:n.minX,y:n.maxY}],fZ=n=>{let e=[];for(let t=0;t<n.length;t++){let i=n[t],r=n[(t+1)%n.length];e.push([i,r])}return e},MCt=(n,e,t)=>{let i=(n.y-e.y)*(t.x-e.x)-(n.x-e.x)*(t.y-e.y);if(Math.abs(i)>1e-9)return!1;let r=(n.x-e.x)*(t.x-e.x)+(n.y-e.y)*(t.y-e.y);return r<0?!1:!(r>(t.x-e.x)**2+(t.y-e.y)**2)},mZ=(n,e)=>{if(e.length<3)return!1;let t=fZ(e);for(let[r,s]of t)if(MCt(n,r,s))return!0;let i=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){let o=e[r].x,a=e[r].y,c=e[s].x,l=e[s].y;a>n.y!=l>n.y&&n.x<(c-o)*(n.y-a)/(l-a)+o&&(i=!i)}return i},_Z=(n,e)=>{let t=rN(n),i=[[t[0],t[1]],[t[1],t[2]],[t[2],t[3]],[t[3],t[0]]],r=fZ(e);for(let[s,o]of r)for(let[a,c]of i)if(Di(s,o,a,c))return!0;return!1},W4=(n,e)=>((t,i)=>!(i.length<3)&&(!!i.some(r=>((s,o)=>s.x>=o.minX&&s.x<=o.maxX&&s.y>=o.minY&&s.y<=o.maxY)(r,t))||!!rN(t).some(r=>mZ(r,i))||_Z(t,i)))(dZ(n),e),yZ=(n,e)=>((t,i)=>!(i.length<3)&&!!rN(t).every(r=>mZ(r,i))&&!_Z(t,i))(dZ(n),e);function H4(n,e,t,i){if(n.x===e.x&&n.y===e.y)return _r(n,t,i);if(t.x===i.x&&t.y===i.y)return _r(t,n,e);if(Di(n,e,t,i))return 0;let r=[_r(n,t,i),_r(e,t,i),_r(t,n,e),_r(i,n,e)];return Math.min(...r)}function gZ(n,e,t){let i=t.width/2,r=t.height/2;return(function(s,o,a){let c={x:a.minX,y:a.minY},l={x:a.maxX,y:a.minY},u={x:a.minX,y:a.maxY},p={x:a.maxX,y:a.maxY};if(Di(s,o,c,l)||Di(s,o,l,p)||Di(s,o,p,u)||Di(s,o,u,c)||s.x>=a.minX&&s.x<=a.maxX&&s.y>=a.minY&&s.y<=a.maxY&&o.x>=a.minX&&o.x<=a.maxX&&o.y>=a.minY&&o.y<=a.maxY)return 0;let d=[_r(c,s,o),_r(l,s,o),_r(u,s,o),_r(p,s,o)];if(s.x>=a.minX&&s.x<=a.maxX&&s.y>=a.minY&&s.y<=a.maxY||o.x>=a.minX&&o.x<=a.maxX&&o.y>=a.minY&&o.y<=a.maxY)return 0;if(s.x<a.minX||s.x>a.maxX||s.y<a.minY||s.y>a.maxY){let _=nl(s.x,a.minX,a.maxX),g=nl(s.y,a.minY,a.maxY);d.push(Qt(s,{x:_,y:g}))}if(o.x<a.minX||o.x>a.maxX||o.y<a.minY||o.y>a.maxY){let _=nl(o.x,a.minX,a.maxX),g=nl(o.y,a.minY,a.maxY);d.push(Qt(o,{x:_,y:g}))}return Math.min(...d)})(n,e,{minX:t.center.x-i,maxX:t.center.x+i,minY:t.center.y-r,maxY:t.center.y+r})}function f_(n,e,t){let i=t.x-e.x,r=t.y-e.y,s=i*i+r*r;if(s===0)return{x:e.x,y:e.y};let o=((n.x-e.x)*i+(n.y-e.y)*r)/s;return o=Math.max(0,Math.min(1,o)),{x:e.x+o*i,y:e.y+o*r}}function Xr(){return Xr=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var i in t)({}).hasOwnProperty.call(t,i)&&(n[i]=t[i])}return n},Xr.apply(null,arguments)}function eS(n,e){return(eS=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,i){return t.__proto__=i,t})(n,e)}function xZ(n){return(xZ=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(n)}function bZ(){try{var n=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(bZ=function(){return!!n})()}function q4(n){var e=typeof Map=="function"?new Map:void 0;return q4=function(t){if(t===null||!(function(r){try{return Function.toString.call(r).indexOf("[native code]")!==-1}catch{return typeof r=="function"}})(t))return t;if(typeof t!="function")throw new TypeError("Super expression must either be null or a function");if(e!==void 0){if(e.has(t))return e.get(t);e.set(t,i)}function i(){return(function(r,s,o){if(bZ())return Reflect.construct.apply(null,arguments);var a=[null];a.push.apply(a,s);var c=new(r.bind.apply(r,a));return o&&eS(c,o.prototype),c})(t,arguments,xZ(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),eS(i,t)},q4(n)}var Yr=(function(n){var e,t;function i(r){var s;if(1)s=n.call(this,"An error occurred. See https://github.com/styled-components/polished/blob/main/src/internalHelpers/errors.md#"+r+" for more information.")||this;else for(var o,a,c;c<o;c++);return(function(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l})(s)}return t=n,(e=i).prototype=Object.create(t.prototype),e.prototype.constructor=e,eS(e,t),i})(q4(Error));function Bq(n,e){return n.substr(-e.length)===e}var CCt=/^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/;function Yq(n){return typeof n!="string"?n:n.match(CCt)?parseFloat(n):n}var Xq=function(n){return function(e,t){t===void 0&&(t="16px");var i=e,r=t;if(typeof e=="string"){if(!Bq(e,"px"))throw new Yr(69,n,e);i=Yq(e)}if(typeof t=="string"){if(!Bq(t,"px"))throw new Yr(70,n,t);r=Yq(t)}if(typeof i=="string")throw new Yr(71,e,n);if(typeof r=="string")throw new Yr(72,t,n);return""+i/r+n}};Xq("em"),Xq("rem");function F4(n){return Math.round(255*n)}function ICt(n,e,t){return F4(n)+","+F4(e)+","+F4(t)}function Wg(n,e,t,i){if(i===void 0&&(i=ICt),e===0)return i(t,t,t);var r=(n%360+360)%360/60,s=(1-Math.abs(2*t-1))*e,o=s*(1-Math.abs(r%2-1)),a=0,c=0,l=0;r>=0&&r<1?(a=s,c=o):r>=1&&r<2?(a=o,c=s):r>=2&&r<3?(c=s,l=o):r>=3&&r<4?(c=o,l=s):r>=4&&r<5?(a=o,l=s):r>=5&&r<6&&(a=s,l=o);var u=t-s/2;return i(a+u,c+u,l+u)}var Uq={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"00ffff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"0000ff",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"00ffff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"ff00ff",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"639",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},NCt=/^#[a-fA-F0-9]{6}$/,ACt=/^#[a-fA-F0-9]{8}$/,RCt=/^#[a-fA-F0-9]{3}$/,OCt=/^#[a-fA-F0-9]{4}$/,$4=/^rgb\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*\)$/i,LCt=/^rgb(?:a)?\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i,FCt=/^hsl\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*\)$/i,$Ct=/^hsl(?:a)?\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i;function m_(n){if(typeof n!="string")throw new Yr(3);var e=(function(d){if(typeof d!="string")return d;var _=d.toLowerCase();return Uq[_]?"#"+Uq[_]:d})(n);if(e.match(NCt))return{red:parseInt(""+e[1]+e[2],16),green:parseInt(""+e[3]+e[4],16),blue:parseInt(""+e[5]+e[6],16)};if(e.match(ACt)){var t=parseFloat((parseInt(""+e[7]+e[8],16)/255).toFixed(2));return{red:parseInt(""+e[1]+e[2],16),green:parseInt(""+e[3]+e[4],16),blue:parseInt(""+e[5]+e[6],16),alpha:t}}if(e.match(RCt))return{red:parseInt(""+e[1]+e[1],16),green:parseInt(""+e[2]+e[2],16),blue:parseInt(""+e[3]+e[3],16)};if(e.match(OCt)){var i=parseFloat((parseInt(""+e[4]+e[4],16)/255).toFixed(2));return{red:parseInt(""+e[1]+e[1],16),green:parseInt(""+e[2]+e[2],16),blue:parseInt(""+e[3]+e[3],16),alpha:i}}var r=$4.exec(e);if(r)return{red:parseInt(""+r[1],10),green:parseInt(""+r[2],10),blue:parseInt(""+r[3],10)};var s=LCt.exec(e.substring(0,50));if(s)return{red:parseInt(""+s[1],10),green:parseInt(""+s[2],10),blue:parseInt(""+s[3],10),alpha:parseFloat(""+s[4])>1?parseFloat(""+s[4])/100:parseFloat(""+s[4])};var o=FCt.exec(e);if(o){var a="rgb("+Wg(parseInt(""+o[1],10),parseInt(""+o[2],10)/100,parseInt(""+o[3],10)/100)+")",c=$4.exec(a);if(!c)throw new Yr(4,e,a);return{red:parseInt(""+c[1],10),green:parseInt(""+c[2],10),blue:parseInt(""+c[3],10)}}var l=$Ct.exec(e.substring(0,50));if(l){var u="rgb("+Wg(parseInt(""+l[1],10),parseInt(""+l[2],10)/100,parseInt(""+l[3],10)/100)+")",p=$4.exec(u);if(!p)throw new Yr(4,e,u);return{red:parseInt(""+p[1],10),green:parseInt(""+p[2],10),blue:parseInt(""+p[3],10),alpha:parseFloat(""+l[4])>1?parseFloat(""+l[4])/100:parseFloat(""+l[4])}}throw new Yr(5)}function il(n){return(function(e){var t,i=e.red/255,r=e.green/255,s=e.blue/255,o=Math.max(i,r,s),a=Math.min(i,r,s),c=(o+a)/2;if(o===a)return e.alpha!==void 0?{hue:0,saturation:0,lightness:c,alpha:e.alpha}:{hue:0,saturation:0,lightness:c};var l=o-a,u=c>.5?l/(2-o-a):l/(o+a);switch(o){case i:t=(r-s)/l+(r<s?6:0);break;case r:t=(s-i)/l+2;break;default:t=(i-r)/l+4}return t*=60,e.alpha!==void 0?{hue:t,saturation:u,lightness:c,alpha:e.alpha}:{hue:t,saturation:u,lightness:c}})(m_(n))}var Z4=function(n){return n.length===7&&n[1]===n[2]&&n[3]===n[4]&&n[5]===n[6]?"#"+n[1]+n[3]+n[5]:n};function md(n){var e=n.toString(16);return e.length===1?"0"+e:e}function z4(n){return md(Math.round(255*n))}function zCt(n,e,t){return Z4("#"+z4(n)+z4(e)+z4(t))}function Bw(n,e,t){return Wg(n,e,t,zCt)}function K4(n,e,t){if(typeof n=="number"&&typeof e=="number"&&typeof t=="number")return Z4("#"+md(n)+md(e)+md(t));if(typeof n=="object"&&e===void 0&&t===void 0)return Z4("#"+md(n.red)+md(n.green)+md(n.blue));throw new Yr(6)}function lS(n,e,t,i){if(typeof n=="string"&&typeof e=="number"){var r=m_(n);return"rgba("+r.red+","+r.green+","+r.blue+","+e+")"}if(typeof n=="number"&&typeof e=="number"&&typeof t=="number"&&typeof i=="number")return i>=1?K4(n,e,t):"rgba("+n+","+e+","+t+","+i+")";if(typeof n=="object"&&e===void 0&&t===void 0&&i===void 0)return n.alpha>=1?K4(n.red,n.green,n.blue):"rgba("+n.red+","+n.green+","+n.blue+","+n.alpha+")";throw new Yr(7)}function rl(n){if(typeof n!="object")throw new Yr(8);if((function(e){return typeof e.red=="number"&&typeof e.green=="number"&&typeof e.blue=="number"&&typeof e.alpha=="number"})(n))return lS(n);if((function(e){return typeof e.red=="number"&&typeof e.green=="number"&&typeof e.blue=="number"&&(typeof e.alpha!="number"||e.alpha===void 0)})(n))return K4(n);if((function(e){return typeof e.hue=="number"&&typeof e.saturation=="number"&&typeof e.lightness=="number"&&typeof e.alpha=="number"})(n))return(function(e,t,i,r){if(typeof e=="number"&&typeof t=="number"&&typeof i=="number"&&typeof r=="number")return r>=1?Bw(e,t,i):"rgba("+Wg(e,t,i)+","+r+")";if(typeof e=="object"&&t===void 0&&i===void 0&&r===void 0)return e.alpha>=1?Bw(e.hue,e.saturation,e.lightness):"rgba("+Wg(e.hue,e.saturation,e.lightness)+","+e.alpha+")";throw new Yr(2)})(n);if((function(e){return typeof e.hue=="number"&&typeof e.saturation=="number"&&typeof e.lightness=="number"&&(typeof e.alpha!="number"||e.alpha===void 0)})(n))return(function(e,t,i){if(typeof e=="number"&&typeof t=="number"&&typeof i=="number")return Bw(e,t,i);if(typeof e=="object"&&t===void 0&&i===void 0)return Bw(e.hue,e.saturation,e.lightness);throw new Yr(1)})(n);throw new Yr(8)}function vZ(n,e,t){return function(){var i=t.concat(Array.prototype.slice.call(arguments));return i.length>=e?n.apply(this,i):vZ(n,e,i)}}function as(n){return vZ(n,n.length,[])}as(function(n,e){if(e==="transparent")return e;var t=il(e);return rl(Xr({},t,{hue:t.hue+parseFloat(n)}))});function g_(n,e,t){return Math.max(n,Math.min(e,t))}as(function(n,e){if(e==="transparent")return e;var t=il(e);return rl(Xr({},t,{lightness:g_(0,1,t.lightness-parseFloat(n))}))});as(function(n,e){if(e==="transparent")return e;var t=il(e);return rl(Xr({},t,{saturation:g_(0,1,t.saturation-parseFloat(n))}))});as(function(n,e){if(e==="transparent")return e;var t=il(e);return rl(Xr({},t,{lightness:g_(0,1,t.lightness+parseFloat(n))}))});var wZ=as(function(n,e,t){if(e==="transparent")return t;if(t==="transparent")return e;if(n===0)return t;var i=m_(e),r=Xr({},i,{alpha:typeof i.alpha=="number"?i.alpha:1}),s=m_(t),o=Xr({},s,{alpha:typeof s.alpha=="number"?s.alpha:1}),a=r.alpha-o.alpha,c=2*parseFloat(n)-1,l=((c*a===-1?c:c+a)/(1+c*a)+1)/2,u=1-l;return lS({red:Math.floor(r.red*l+o.red*u),green:Math.floor(r.green*l+o.green*u),blue:Math.floor(r.blue*l+o.blue*u),alpha:r.alpha*parseFloat(n)+o.alpha*(1-parseFloat(n))})});as(function(n,e){if(e==="transparent")return e;var t=m_(e);return lS(Xr({},t,{alpha:g_(0,1,(100*(typeof t.alpha=="number"?t.alpha:1)+100*parseFloat(n))/100)}))});as(function(n,e){if(e==="transparent")return e;var t=il(e);return rl(Xr({},t,{saturation:g_(0,1,t.saturation+parseFloat(n))}))});as(function(n,e){return e==="transparent"?e:rl(Xr({},il(e),{hue:parseFloat(n)}))});as(function(n,e){return e==="transparent"?e:rl(Xr({},il(e),{lightness:parseFloat(n)}))});as(function(n,e){return e==="transparent"?e:rl(Xr({},il(e),{saturation:parseFloat(n)}))});as(function(n,e){return e==="transparent"?e:wZ(parseFloat(n),"rgb(0, 0, 0)",e)});as(function(n,e){return e==="transparent"?e:wZ(parseFloat(n),"rgb(255, 255, 255)",e)});var DCt=as(function(n,e){if(e==="transparent")return e;var t=m_(e);return lS(Xr({},t,{alpha:g_(0,1,+(100*(typeof t.alpha=="number"?t.alpha:1)-100*parseFloat(n)).toFixed(2)/100)}))}),Vq=["blue","orange","purple","cyan","magenta","yellowgreen","darkgoldenrod","deeppink"],Hg=(n,e)=>{let t={};for(let i=0;i<n.connections.length;i++){let r=n.connections[i],s=e?.getNetConnectedToId(r.name);s&&!t[s]&&(t[s]=`hsl(${300*i/n.connections.length}, 100%, 50%)`),t[r.name]=(s?t[s]:null)??`hsl(${340*i/n.connections.length}, 100%, 50%)`}return t},Jn=(n,e)=>{try{return DCt(e,n)}catch(t){return console.error(t),n}},gd=(n,e)=>n==="top"?0:n==="bottom"?e-1:parseInt(n.slice(5)),uo=(n,e=1)=>{let t=(("width"in n?n.width:n)/.5/2)**1.1*e;return n.availableZ?.length===1&&t>1?1:t},sN=(n,e=.5,t=16)=>{let i=0,r=n;for(;i<t&&!(uo({width:r})<=e);)r/=2,i++;return Math.max(1,i)};function SZ(n,e,t=0,i=n.length-1,r=jCt){for(;i>t;){if(i-t>600){let c=i-t+1,l=e-t+1,u=Math.log(c),p=.5*Math.exp(2*u/3),d=.5*Math.sqrt(u*p*(c-p)/c)*(l-c/2<0?-1:1);SZ(n,e,Math.max(t,Math.floor(e-l*p/c+d)),Math.min(i,Math.floor(e+(c-l)*p/c+d)),r)}let s=n[e],o=t,a=i;for(jg(n,t,e),r(n[i],s)>0&&jg(n,t,i);o<a;){for(jg(n,o,a),o++,a--;r(n[o],s)<0;)o++;for(;r(n[a],s)>0;)a--}r(n[t],s)===0?jg(n,t,a):(a++,jg(n,a,i)),a<=e&&(t=a+1),e<=a&&(i=a-1)}}function jg(n,e,t){let i=n[e];n[e]=n[t],n[t]=i}function jCt(n,e){return n<e?-1:n>e?1:0}var BCt=class{constructor(n=9){this._maxEntries=Math.max(4,n),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(){return this._all(this.data,[])}search(n){let e=this.data,t=[];if(!Xw(n,e))return t;let i=this.toBBox,r=[];for(;e;){for(let s=0;s<e.children.length;s++){let o=e.children[s],a=e.leaf?i(o):o;Xw(n,a)&&(e.leaf?t.push(o):j4(n,a)?this._all(o,t):r.push(o))}e=r.pop()}return t}collides(n){let e=this.data;if(!Xw(n,e))return!1;let t=[];for(;e;){for(let i=0;i<e.children.length;i++){let r=e.children[i],s=e.leaf?this.toBBox(r):r;if(Xw(n,s)){if(e.leaf||j4(n,s))return!0;t.push(r)}}e=t.pop()}return!1}load(n){if(!n||!n.length)return this;if(n.length<this._minEntries){for(let t=0;t<n.length;t++)this.insert(n[t]);return this}let e=this._build(n.slice(),0,n.length-1,0);if(this.data.children.length)if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){let t=this.data;this.data=e,e=t}this._insert(e,this.data.height-e.height-1,!0)}else this.data=e;return this}insert(n){return n&&this._insert(n,this.data.height-1),this}clear(){return this.data=h_([]),this}remove(n,e){if(!n)return this;let t=this.data,i=this.toBBox(n),r=[],s=[],o,a,c;for(;t||r.length;){if(t||(t=r.pop(),a=r[r.length-1],o=s.pop(),c=!0),t.leaf){let l=YCt(n,t.children,e);if(l!==-1)return t.children.splice(l,1),r.push(t),this._condense(r),this}c||t.leaf||!j4(t,i)?a?(o++,t=a.children[o],c=!1):t=null:(r.push(t),s.push(o),o=0,a=t,t=t.children[0])}return this}toBBox(n){return n}compareMinX(n,e){return n.minX-e.minX}compareMinY(n,e){return n.minY-e.minY}toJSON(){return this.data}fromJSON(n){return this.data=n,this}_all(n,e){let t=[];for(;n;)n.leaf?e.push(...n.children):t.push(...n.children),n=t.pop();return e}_build(n,e,t,i){let r=t-e+1,s,o=this._maxEntries;if(r<=o)return s=h_(n.slice(e,t+1)),p_(s,this.toBBox),s;i||(i=Math.ceil(Math.log(r)/Math.log(o)),o=Math.ceil(r/Math.pow(o,i-1))),s=h_([]),s.leaf=!1,s.height=i;let a=Math.ceil(r/o),c=a*Math.ceil(Math.sqrt(o));Gq(n,e,t,c,this.compareMinX);for(let l=e;l<=t;l+=c){let u=Math.min(l+c-1,t);Gq(n,l,u,a,this.compareMinY);for(let p=l;p<=u;p+=a){let d=Math.min(p+a-1,u);s.children.push(this._build(n,p,d,i-1))}}return p_(s,this.toBBox),s}_chooseSubtree(n,e,t,i){for(;i.push(e),!e.leaf&&i.length-1!==t;){let r,s=1/0,o=1/0;for(let a=0;a<e.children.length;a++){let c=e.children[a],l=D4(c),u=VCt(n,c)-l;u<o?(o=u,s=l<s?l:s,r=c):u===o&&l<s&&(s=l,r=c)}e=r||e.children[0]}return e}_insert(n,e,t){let i=t?n:this.toBBox(n),r=[],s=this._chooseSubtree(i,this.data,e,r);for(s.children.push(n),Yg(s,i);e>=0&&r[e].children.length>this._maxEntries;)this._split(r,e),e--;this._adjustParentBBoxes(i,r,e)}_split(n,e){let t=n[e],i=t.children.length,r=this._minEntries;this._chooseSplitAxis(t,r,i);let s=this._chooseSplitIndex(t,r,i),o=h_(t.children.splice(s,t.children.length-s));o.height=t.height,o.leaf=t.leaf,p_(t,this.toBBox),p_(o,this.toBBox),e?n[e-1].children.push(o):this._splitRoot(t,o)}_splitRoot(n,e){this.data=h_([n,e]),this.data.height=n.height+1,this.data.leaf=!1,p_(this.data,this.toBBox)}_chooseSplitIndex(n,e,t){let i,r=1/0,s=1/0;for(let o=e;o<=t-e;o++){let a=Bg(n,0,o,this.toBBox),c=Bg(n,o,t,this.toBBox),l=GCt(a,c),u=D4(a)+D4(c);l<r?(r=l,i=o,s=u<s?u:s):l===r&&u<s&&(s=u,i=o)}return i||t-e}_chooseSplitAxis(n,e,t){let i=n.leaf?this.compareMinX:XCt,r=n.leaf?this.compareMinY:UCt;this._allDistMargin(n,e,t,i)<this._allDistMargin(n,e,t,r)&&n.children.sort(i)}_allDistMargin(n,e,t,i){n.children.sort(i);let r=this.toBBox,s=Bg(n,0,e,r),o=Bg(n,t-e,t,r),a=Yw(s)+Yw(o);for(let c=e;c<t-e;c++){let l=n.children[c];Yg(s,n.leaf?r(l):l),a+=Yw(s)}for(let c=t-e-1;c>=e;c--){let l=n.children[c];Yg(o,n.leaf?r(l):l),a+=Yw(o)}return a}_adjustParentBBoxes(n,e,t){for(let i=t;i>=0;i--)Yg(e[i],n)}_condense(n){for(let e,t=n.length-1;t>=0;t--)n[t].children.length===0?t>0?(e=n[t-1].children,e.splice(e.indexOf(n[t]),1)):this.clear():p_(n[t],this.toBBox)}};function YCt(n,e,t){if(!t)return e.indexOf(n);for(let i=0;i<e.length;i++)if(t(n,e[i]))return i;return-1}function p_(n,e){Bg(n,0,n.children.length,e,n)}function Bg(n,e,t,i,r){r||(r=h_(null)),r.minX=1/0,r.minY=1/0,r.maxX=-1/0,r.maxY=-1/0;for(let s=e;s<t;s++){let o=n.children[s];Yg(r,n.leaf?i(o):o)}return r}function Yg(n,e){return n.minX=Math.min(n.minX,e.minX),n.minY=Math.min(n.minY,e.minY),n.maxX=Math.max(n.maxX,e.maxX),n.maxY=Math.max(n.maxY,e.maxY),n}function XCt(n,e){return n.minX-e.minX}function UCt(n,e){return n.minY-e.minY}function D4(n){return(n.maxX-n.minX)*(n.maxY-n.minY)}function Yw(n){return n.maxX-n.minX+(n.maxY-n.minY)}function VCt(n,e){return(Math.max(e.maxX,n.maxX)-Math.min(e.minX,n.minX))*(Math.max(e.maxY,n.maxY)-Math.min(e.minY,n.minY))}function GCt(n,e){let t=Math.max(n.minX,e.minX),i=Math.max(n.minY,e.minY),r=Math.min(n.maxX,e.maxX),s=Math.min(n.maxY,e.maxY);return Math.max(0,r-t)*Math.max(0,s-i)}function j4(n,e){return n.minX<=e.minX&&n.minY<=e.minY&&e.maxX<=n.maxX&&e.maxY<=n.maxY}function Xw(n,e){return e.minX<=n.maxX&&e.minY<=n.maxY&&e.maxX>=n.minX&&e.maxY>=n.minY}function h_(n){return{children:n,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Gq(n,e,t,i,r){let s=[e,t];for(;s.length;){if((t=s.pop())-(e=s.pop())<=i)continue;let o=e+Math.ceil((t-e)/i/2)*i;SZ(n,o,e,t,r),s.push(e,o,o,t)}}var Wq=class{constructor(n=9){f(this,"tree");this.tree=new BCt(n)}insert(n,e,t,i,r){this.tree.insert({minX:e,minY:t,maxX:i,maxY:r,data:n})}bulkLoad(n){let e=n.map(({item:t,minX:i,minY:r,maxX:s,maxY:o})=>({minX:i,minY:r,maxX:s,maxY:o,data:t}));this.tree.load(e)}search(n,e,t,i){return this.tree.search({minX:n,minY:e,maxX:t,maxY:i}).map(r=>r.data)}clear(){this.tree.clear()}},WCt=class{constructor(){this.ids=[],this.values=[],this.length=0}clear(){this.length=0}push(n,e){let t=this.length++;for(;t>0;){let i=t-1>>1,r=this.values[i];if(e>=r)break;this.ids[t]=this.ids[i],this.values[t]=r,t=i}this.ids[t]=n,this.values[t]=e}pop(){if(this.length===0)return;let n=this.ids,e=this.values,t=n[0],i=--this.length;if(i>0){let r=n[i],s=e[i],o=0,a=i>>1;for(;o<a;){let c=1+(o<<1),l=c+1,u=c+(+(l<i)&+(e[l]<e[c]));if(e[u]>=s)break;n[o]=n[u],e[o]=e[u],o=u}n[o]=r,e[o]=s}return t}peek(){return this.length>0?this.ids[0]:void 0}peekValue(){return this.length>0?this.values[0]:void 0}shrink(){this.ids.length=this.values.length=this.length}},Hq=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],qq=class PZ{static from(e,t=0){if(t%8!=0)throw new Error("byteOffset must be 8-byte aligned.");if(!e||e.byteLength===void 0||e.buffer)throw new Error("Data must be an instance of ArrayBuffer or SharedArrayBuffer.");let[i,r]=new Uint8Array(e,t+0,2);if(i!==251)throw new Error("Data does not appear to be in a Flatbush format.");let s=r>>4;if(s!==3)throw new Error(`Got v${s} data when expected v3.`);let o=Hq[15&r];if(!o)throw new Error("Unrecognized array type.");let[a]=new Uint16Array(e,t+2,1),[c]=new Uint32Array(e,t+4,1);return new PZ(c,a,o,void 0,e,t)}constructor(e,t=16,i=Float64Array,r=ArrayBuffer,s,o=0){if(e===void 0)throw new Error("Missing required argument: numItems.");if(isNaN(e)||e<=0)throw new Error(`Unexpected numItems value: ${e}.`);this.numItems=+e,this.nodeSize=Math.min(Math.max(+t,2),65535),this.byteOffset=o;let a=e,c=a;this._levelBounds=[4*a];do a=Math.ceil(a/this.nodeSize),c+=a,this._levelBounds.push(4*c);while(a!==1);this.ArrayType=i,this.IndexArrayType=c<16384?Uint16Array:Uint32Array;let l=Hq.indexOf(i),u=4*c*i.BYTES_PER_ELEMENT;if(l<0)throw new Error(`Unexpected typed array class: ${i}.`);if(s)this.data=s,this._boxes=new i(s,o+8,4*c),this._indices=new this.IndexArrayType(s,o+8+u,c),this._pos=4*c,this.minX=this._boxes[this._pos-4],this.minY=this._boxes[this._pos-3],this.maxX=this._boxes[this._pos-2],this.maxY=this._boxes[this._pos-1];else{let p=this.data=new r(8+u+c*this.IndexArrayType.BYTES_PER_ELEMENT);this._boxes=new i(p,8,4*c),this._indices=new this.IndexArrayType(p,8+u,c),this._pos=0,this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,new Uint8Array(p,0,2).set([251,48+l]),new Uint16Array(p,2,1)[0]=t,new Uint32Array(p,4,1)[0]=e}this._queue=new WCt}add(e,t,i=e,r=t){let s=this._pos>>2,o=this._boxes;return this._indices[s]=s,o[this._pos++]=e,o[this._pos++]=t,o[this._pos++]=i,o[this._pos++]=r,e<this.minX&&(this.minX=e),t<this.minY&&(this.minY=t),i>this.maxX&&(this.maxX=i),r>this.maxY&&(this.maxY=r),s}finish(){if(this._pos>>2!==this.numItems)throw new Error(`Added ${this._pos>>2} items when expected ${this.numItems}.`);let e=this._boxes;if(this.numItems<=this.nodeSize)return e[this._pos++]=this.minX,e[this._pos++]=this.minY,e[this._pos++]=this.maxX,void(e[this._pos++]=this.maxY);let t=this.maxX-this.minX||1,i=this.maxY-this.minY||1,r=new Uint32Array(this.numItems);for(let s=0,o=0;s<this.numItems;s++){let a=e[o++],c=e[o++],l=e[o++],u=e[o++],p=Math.floor(65535*((a+l)/2-this.minX)/t),d=Math.floor(65535*((c+u)/2-this.minY)/i);r[s]=qCt(p,d)}J4(r,e,this._indices,0,this.numItems-1,this.nodeSize);for(let s=0,o=0;s<this._levelBounds.length-1;s++){let a=this._levelBounds[s];for(;o<a;){let c=o,l=e[o++],u=e[o++],p=e[o++],d=e[o++];for(let _=1;_<this.nodeSize&&o<a;_++)l=Math.min(l,e[o++]),u=Math.min(u,e[o++]),p=Math.max(p,e[o++]),d=Math.max(d,e[o++]);this._indices[this._pos>>2]=c,e[this._pos++]=l,e[this._pos++]=u,e[this._pos++]=p,e[this._pos++]=d}}}search(e,t,i,r,s){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let o=this._boxes.length-4,a=[],c=[];for(;o!==void 0;){let l=Math.min(o+4*this.nodeSize,Zq(o,this._levelBounds));for(let u=o;u<l;u+=4){let p=this._boxes[u];if(i<p)continue;let d=this._boxes[u+1];if(r<d)continue;let _=this._boxes[u+2];if(e>_)continue;let g=this._boxes[u+3];if(t>g)continue;let x=0|this._indices[u>>2];o>=4*this.numItems?a.push(x):(s===void 0||s(x,p,d,_,g))&&c.push(x)}o=a.pop()}return c}neighbors(e,t,i=1/0,r=1/0,s){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let o=this._boxes.length-4,a=this._queue,c=[],l=r*r;t:for(;o!==void 0;){let u=Math.min(o+4*this.nodeSize,Zq(o,this._levelBounds));for(let p=o;p<u;p+=4){let d=0|this._indices[p>>2],_=this._boxes[p],g=this._boxes[p+1],x=this._boxes[p+2],v=this._boxes[p+3],S=e<_?_-e:e>x?e-x:0,P=t<g?g-t:t>v?t-v:0,T=S*S+P*P;T>l||(o>=4*this.numItems?a.push(d<<1,T):(s===void 0||s(d))&&a.push(1+(d<<1),T))}for(;a.length&&1&a.peek();)if(a.peekValue()>l||(c.push(a.pop()>>1),c.length===i))break t;o=a.length?a.pop()>>1:void 0}return a.clear(),c}};function Zq(n,e){let t=0,i=e.length-1;for(;t<i;){let r=t+i>>1;e[r]>n?i=r:t=r+1}return e[t]}function J4(n,e,t,i,r,s){if(Math.floor(i/s)>=Math.floor(r/s))return;let o=n[i],a=n[i+r>>1],c=n[r],l=c,u=Math.max(o,a);c>u?l=u:u===o?l=Math.max(a,c):u===a&&(l=Math.max(o,c));let p=i-1,d=r+1;for(;;){do p++;while(n[p]<l);do d--;while(n[d]>l);if(p>=d)break;HCt(n,e,t,p,d)}J4(n,e,t,i,d,s),J4(n,e,t,d+1,r,s)}function HCt(n,e,t,i,r){let s=n[i];n[i]=n[r],n[r]=s;let o=4*i,a=4*r,c=e[o],l=e[o+1],u=e[o+2],p=e[o+3];e[o]=e[a],e[o+1]=e[a+1],e[o+2]=e[a+2],e[o+3]=e[a+3],e[a]=c,e[a+1]=l,e[a+2]=u,e[a+3]=p;let d=t[i];t[i]=t[r],t[r]=d}function qCt(n,e){let t=n^e,i=65535^t,r=65535^(n|e),s=n&(65535^e),o=t|i>>1,a=t>>1^t,c=r>>1^i&s>>1^r,l=t&r>>1^s>>1^s;t=o,i=a,r=c,s=l,o=t&t>>2^i&i>>2,a=t&i>>2^i&(t^i)>>2,c^=t&r>>2^i&s>>2,l^=i&r>>2^(t^i)&s>>2,t=o,i=a,r=c,s=l,o=t&t>>4^i&i>>4,a=t&i>>4^i&(t^i)>>4,c^=t&r>>4^i&s>>4,l^=i&r>>4^(t^i)&s>>4,t=o,i=a,r=c,s=l,c^=t&r>>8^i&s>>8,l^=i&r>>8^(t^i)&s>>8,t=c^c>>1,i=l^l>>1;let u=n^e,p=i|65535^(u|t);return u=16711935&(u|u<<8),u=252645135&(u|u<<4),u=858993459&(u|u<<2),u=1431655765&(u|u<<1),p=16711935&(p|p<<8),p=252645135&(p|p<<4),p=858993459&(p|p<<2),p=1431655765&(p|p<<1),(p<<1|u)>>>0}var ZCt=class{constructor(n){f(this,"index");f(this,"items",[]);f(this,"currentIndex",0);f(this,"capacity");this.capacity=Math.max(1,n),this.index=new qq(this.capacity)}insert(n,e,t,i,r){if(this.currentIndex>=this.index.numItems)throw new Error("Exceeded initial capacity");this.items[this.currentIndex]=n,this.index.add(e,t,i,r),this.currentIndex++}finish(){this.index.finish()}search(n,e,t,i){return this.index.search(n,e,t,i).map(r=>this.items[r]||null).filter(Boolean)}clear(){this.items=[],this.currentIndex=0,this.index=new qq(this.capacity)}},kZ=class{constructor(n="native",e=[]){f(this,"idx");f(this,"storage",[]);n==="flatbush"?e.length===0?(this.idx=new Wq,n="rbush"):this.idx=new ZCt(e.length):this.idx=n==="rbush"?new Wq:new class{constructor(){f(this,"shi",new KCt(e))}insert(t){}search(t,i,r,s){let o=(t+r)/2,a=(i+s)/2,c=r-t,l=s-i;return this.shi.getNodesInArea(o,a,c,l)}clear(){}},e.forEach(t=>this.insert(t)),n==="flatbush"&&e.length>0&&this.idx.finish?.()}insert(n){this.storage.push(n),this.idx.insert(n,n.center.x-n.width/2,n.center.y-n.height/2,n.center.x+n.width/2,n.center.y+n.height/2)}search(n){return this.idx.search(n.minX,n.minY,n.maxX,n.maxY)}searchArea(n,e,t,i){return this.search({minX:n-t/2,minY:e-i/2,maxX:n+t/2,maxY:e+i/2})}},KCt=class{constructor(n){f(this,"buckets");f(this,"CELL_SIZE",.4);this.obstacles=n,this.buckets=new Map;for(let e=0;e<n.length;e++){let t=n[e],i=t.center.x-t.width/2,r=t.center.y-t.height/2,s=t.center.x+t.width/2,o=t.center.y+t.height/2;for(let a=i;a<=s;a+=this.CELL_SIZE)for(let c=r;c<=o;c+=this.CELL_SIZE){let l=this.getBucketKey(a,c),u=this.buckets.get(l);u?u.push([t,e]):this.buckets.set(l,[[t,e]])}}}getBucketKey(n,e){return`${Math.floor(n/this.CELL_SIZE)}x${Math.floor(e/this.CELL_SIZE)}`}getNodesInArea(n,e,t,i){let r=[],s=new Set,o=e-i/2,a=n+t/2,c=e+i/2;for(let l=n-t/2;l<=a;l+=this.CELL_SIZE)for(let u=o;u<=c;u+=this.CELL_SIZE){let p=this.getBucketKey(l,u),d=this.buckets.get(p)||[];for(let _ of d)s.has(_[1])||(s.add(_[1]),r.push(_[0]))}return r}},JCt=class{constructor(n){f(this,"buckets");f(this,"CELL_SIZE",5);this.targets=n,this.buckets=new Map;for(let e=0;e<n.length;e++){let t=n[e],i=Math.floor(t.bounds.minX/this.CELL_SIZE)*this.CELL_SIZE,r=Math.floor(t.bounds.minY/this.CELL_SIZE)*this.CELL_SIZE,s=t.bounds.maxX,o=t.bounds.maxY;for(let a=i;a<=s;a+=this.CELL_SIZE)for(let c=r;c<=o;c+=this.CELL_SIZE){let l=this.getBucketKey(a,c),u=this.buckets.get(l);u?u.push([t,e]):this.buckets.set(l,[[t,e]])}}}getBucketKey(n,e){return`${Math.floor(n/this.CELL_SIZE)}x${Math.floor(e/this.CELL_SIZE)}`}getTargetsInArea(n,e,t,i){let r=[],s=new Set,o=Math.floor((n-t/2)/this.CELL_SIZE)*this.CELL_SIZE,a=Math.floor((e-i/2)/this.CELL_SIZE)*this.CELL_SIZE,c=n+t/2,l=e+i/2;for(let u=o;u<=c;u+=this.CELL_SIZE)for(let p=a;p<=l;p+=this.CELL_SIZE){let d=this.getBucketKey(u,p),_=this.buckets.get(d)||[];for(let g of _)s.has(g[1])||(s.add(g[1]),r.push(g[0]))}return r}},QCt=class extends cn{constructor(e,t={}){super();f(this,"unfinishedNodes");f(this,"finishedNodes");f(this,"nodeToXYOverlappingObstaclesMap");f(this,"layerCount");f(this,"outlinePolygon");f(this,"MAX_DEPTH",4);f(this,"targets");f(this,"targetTree");f(this,"obstacleTree");f(this,"_nextNodeCounter",0);this.srj=e,this.opts=t,this.MAX_DEPTH=t?.capacityDepth??this.MAX_DEPTH,this.MAX_ITERATIONS=1e5,this.layerCount=e.layerCount??2,this.outlinePolygon=e.outline&&e.outline.length>=3?e.outline:void 0;for(let o of e.obstacles)if(!o.zLayers){let a=[];for(let c of o.layers)a.push(gd(c,e.layerCount));o.zLayers=a}let i={x:(e.bounds.minX+e.bounds.maxX)/2,y:(e.bounds.minY+e.bounds.maxY)/2},r={width:e.bounds.maxX-e.bounds.minX,height:e.bounds.maxY-e.bounds.minY},s=Math.max(r.width,r.height);this.unfinishedNodes=[{capacityMeshNodeId:this.getNextNodeId(),center:i,width:s,height:s,layer:"top",availableZ:Array.from({length:this.layerCount},(o,a)=>a),_depth:0,_containsTarget:!0,_containsObstacle:!0,_completelyInsideObstacle:!1}],this.finishedNodes=[],this.nodeToXYOverlappingObstaclesMap=new Map,this.obstacleTree=new kZ("flatbush",this.srj.obstacles),this.targets=this.computeTargets(),this.targetTree=new JCt(this.targets)}computeTargets(){let e=[];for(let t of this.srj.connections)for(let i of t.pointsToConnect){let r=this.obstacleTree.searchArea(i.x,i.y,.01,.01).filter(a=>a.zLayers.some(c=>c===gd(i.layer,this.layerCount))),s={minX:i.x-.005,minY:i.y-.005,maxX:i.x+.005,maxY:i.y+.005};r.length>0&&(s={minX:Math.min(...r.map(a=>a.center.x-a.width/2)),minY:Math.min(...r.map(a=>a.center.y-a.height/2)),maxX:Math.max(...r.map(a=>a.center.x+a.width/2)),maxY:Math.max(...r.map(a=>a.center.y+a.height/2))});let o={...i,connectionName:t.name,availableZ:[gd(i.layer,this.layerCount)],bounds:s};e.push(o)}return e}getNodeBounds(e){let t=e.width/2,i=e.height/2;return{minX:e.center.x-t,maxX:e.center.x+t,minY:e.center.y-i,maxY:e.center.y+i}}getNodeRect(e){return{center:{x:e.center.x,y:e.center.y},width:e.width,height:e.height}}getNextNodeId(){return"cn"+this._nextNodeCounter++}getCapacityFromDepth(e){return(this.MAX_DEPTH-e+1)**2}getTargetIfNodeContainsTarget(e){let t=e.width>4*this.targetTree.CELL_SIZE?this.targets:this.targetTree.getTargetsInArea(e.center.x,e.center.y,e.width,e.height);for(let i of t)if(i.bounds.minX<=e.center.x+e.width/2&&i.bounds.maxX>=e.center.x-e.width/2&&i.bounds.minY<=e.center.y+e.height/2&&i.bounds.maxY>=e.center.y-e.height/2&&i.availableZ.some(r=>e.availableZ.includes(r)))return i;return null}getXYOverlappingObstacles(e){let t=this.nodeToXYOverlappingObstaclesMap.get(e.capacityMeshNodeId);if(t)return t;let i=[],r=this.getNodeBounds(e),s=r.minX,o=r.maxX,a=r.minY,c=r.maxY,l=e._parent?this.getXYOverlappingObstacles(e._parent):this.srj.obstacles;for(let u of l){let p=u.center.x-u.width/2,d=u.center.x+u.width/2,_=u.center.y-u.height/2,g=u.center.y+u.height/2;(o>=p&&s<=d&&c>=_&&a<=g||s>=p&&o<=d&&a>=_&&c<=g||p>=s&&d<=o&&_>=a&&g<=c)&&i.push(u)}return this.nodeToXYOverlappingObstaclesMap.set(e.capacityMeshNodeId,i),i}getXYZOverlappingObstacles(e){let t=this.getXYOverlappingObstacles(e),i=[];for(let r of t)e.availableZ.some(s=>r.zLayers.includes(s))&&i.push(r);return i}doesNodeOverlapObstacle(e){if(this.getXYZOverlappingObstacles(e).length>0)return!0;let t=this.getNodeBounds(e);if(this.outlinePolygon){let i=this.getNodeRect(e);if(!yZ(i,this.outlinePolygon))return!0}return t.minX<this.srj.bounds.minX||t.maxX>this.srj.bounds.maxX||t.minY<this.srj.bounds.minY||t.maxY>this.srj.bounds.maxY}isNodeCompletelyInsideObstacle(e){let t=this.getXYZOverlappingObstacles(e),i=this.getNodeBounds(e);if(this.outlinePolygon){let r=this.getNodeRect(e);if(!W4(r,this.outlinePolygon))return!0}for(let r of t){let s=r.center.x-r.width/2,o=r.center.x+r.width/2,a=r.center.y-r.height/2,c=r.center.y+r.height/2;if(i.minX>=s&&i.maxX<=o&&i.minY>=a&&i.maxY<=c)return!0}return!1}getChildNodes(e){if(e._depth===this.MAX_DEPTH)return[];let t=[],i={width:e.width/2,height:e.height/2},r=[{x:e.center.x-i.width/2,y:e.center.y-i.height/2},{x:e.center.x+i.width/2,y:e.center.y-i.height/2},{x:e.center.x-i.width/2,y:e.center.y+i.height/2},{x:e.center.x+i.width/2,y:e.center.y+i.height/2}];for(let s of r){let o={capacityMeshNodeId:this.getNextNodeId(),center:s,width:i.width,height:i.height,layer:e.layer,availableZ:e.availableZ,_depth:(e._depth??0)+1,_parent:e};o._containsObstacle=this.doesNodeOverlapObstacle(o);let a=this.getTargetIfNodeContainsTarget(o);a&&(o._targetConnectionName=a.connectionName,o.availableZ=a.availableZ,o._containsTarget=!0),o._containsObstacle&&(o._completelyInsideObstacle=this.isNodeCompletelyInsideObstacle(o)),o._completelyInsideObstacle&&!o._containsTarget||t.push(o)}return t}shouldNodeBeXYSubdivided(e){return!(e._depth>=this.MAX_DEPTH)&&(!!e._containsTarget||!(!e._containsObstacle||e._completelyInsideObstacle))}_step(){let e=this.unfinishedNodes.pop();if(!e)return void(this.solved=!0);let t=this.getChildNodes(e),i=[],r=[];for(let s of t){let o=this.shouldNodeBeXYSubdivided(s);o?r.push(s):o||s._containsObstacle?!o&&s._containsTarget&&i.push(s):i.push(s)}this.unfinishedNodes.push(...r),this.finishedNodes.push(...i)}visualize(){let e={lines:[],points:[],rects:[],circles:[],coordinateSystem:"cartesian",title:"Capacity Mesh Visualization"};if(this.outlinePolygon&&this.outlinePolygon.length>=2){let i=this.outlinePolygon.map(r=>({x:r.x,y:r.y}));i.push({...i[0]}),e.lines.push({points:i,strokeColor:"rgba(0, 136, 255, 0.95)",label:"outline"});for(let r of this.outlinePolygon)e.points.push({x:r.x,y:r.y,color:"rgba(0, 136, 255, 0.95)"})}for(let i of this.srj.obstacles)e.rects.push({center:i.center,width:i.width,height:i.height,fill:i.zLayers?.length===1&&i.zLayers?.includes(1)?"rgba(0,0,255,0.3)":"rgba(255,0,0,0.3)",stroke:"red",label:["obstacle",`z: ${i.zLayers.join(",")}`].join(`
|
|
162
162
|
`)});let t=[...this.finishedNodes,...this.unfinishedNodes];for(let i of t){let r=Math.min(...i.availableZ),s=this.unfinishedNodes.length>0&&i===this.unfinishedNodes[this.unfinishedNodes.length-1];e.rects.push({center:{x:i.center.x+r*i.width*.05,y:i.center.y-r*i.width*.05},width:Math.max(i.width-2,.8*i.width),height:Math.max(i.height-2,.8*i.height),fill:i._containsObstacle?"rgba(255,0,0,0.1)":{"0,1":"rgba(0,0,0,0.1)",0:"rgba(0,200,200, 0.1)",1:"rgba(0,0,200, 0.1)"}[i.availableZ.join(",")]??"rgba(0,200,200,0.1)",stroke:s?"rgba(255,165,0,0.5)":void 0,label:[i.capacityMeshNodeId,`availableZ: ${i.availableZ.join(",")}`,`target? ${i._containsTarget??!1}`,`obs? ${i._containsObstacle??!1}`,`${i.width.toFixed(2)}x${i.height.toFixed(2)}`,`capacity: ${uo(i).toFixed(2)}`].join(`
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/eval",
|
|
3
3
|
"main": "dist/lib/index.js",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.515",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -123,7 +123,8 @@
|
|
|
123
123
|
"tsup": "^8.2.4",
|
|
124
124
|
"tslib": "^2.8.1",
|
|
125
125
|
"@tscircuit/common": "^0.0.20",
|
|
126
|
-
"@tscircuit/copper-pour-solver": "^0.0.14"
|
|
126
|
+
"@tscircuit/copper-pour-solver": "^0.0.14",
|
|
127
|
+
"zod": "^3.25.67"
|
|
127
128
|
},
|
|
128
129
|
"peerDependencies": {
|
|
129
130
|
"typescript": "^5.0.0",
|