@tscircuit/eval 0.0.310 → 0.0.311

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.
@@ -3499,6 +3499,4 @@ declare const createCircuitWebWorker: (configuration: Partial<WebWorkerConfigura
3499
3499
 
3500
3500
  declare const getPossibleEntrypointComponentPaths: (fsMap: Record<string, string>) => string[];
3501
3501
 
3502
- declare const getPlatformConfig: () => PlatformConfig;
3503
-
3504
- export { CircuitRunner, type CircuitWebWorker, type WebWorkerConfiguration, createCircuitWebWorker, getImportsFromCode, getPlatformConfig, getPossibleEntrypointComponentPaths, runTscircuitCode, runTscircuitModule };
3502
+ export { CircuitRunner, type CircuitWebWorker, type WebWorkerConfiguration, createCircuitWebWorker, getImportsFromCode, getPossibleEntrypointComponentPaths, runTscircuitCode, runTscircuitModule };
package/dist/lib/index.js CHANGED
@@ -1155,7 +1155,6 @@ export {
1155
1155
  CircuitRunner,
1156
1156
  createCircuitWebWorker,
1157
1157
  getImportsFromCode,
1158
- getPlatformConfig,
1159
1158
  getPossibleEntrypointComponentPaths,
1160
1159
  runTscircuitCode,
1161
1160
  runTscircuitModule
@@ -948,7 +948,7 @@ Using plugins:`),be.forEach(function(je){rbt(je,Q,ge)}),I||console.log("\nUsing
948
948
  :is(button, input, select, textarea, optgroup, option)[disabled],
949
949
  optgroup[disabled] > option,
950
950
  fieldset[disabled]:not(fieldset[disabled] legend:first-of-type *)
951
- )`,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 Ku=qr(Jf(),1);var JX={};function ZX(n,e){return n===Ku.default.falseFunc?Ku.default.falseFunc:a=>e.isTag(a)&&n(a)}function QX(n,e){let a=e.getSiblings(n);if(a.length<=1)return[];let s=a.indexOf(n);return s<0||s===a.length-1?[]:a.slice(s+1).filter(e.isTag)}function KX(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 WX=(n,e,a,s,l)=>{let p=l(e,KX(a),s);return p===Ku.default.trueFunc?n:p===Ku.default.falseFunc?Ku.default.falseFunc:x=>p(x)&&n(x)},VR={is:WX,matches:WX,where:WX,not(n,e,a,s,l){let p=l(e,KX(a),s);return p===Ku.default.falseFunc?n:p===Ku.default.trueFunc?Ku.default.falseFunc:x=>!p(x)&&n(x)},has(n,e,a,s,l){let{adapter:p}=a,x=KX(a);x.relativeSelector=!0;let f=e.some(b=>b.some(Rb))?[JX]:void 0,m=l(e,x,f);if(m===Ku.default.falseFunc)return Ku.default.falseFunc;let D=ZX(m,p);if(f&&m!==Ku.default.trueFunc){let{shouldTestNextSiblings:b=!1}=m;return E=>{if(!n(E))return!1;f[0]=E;let A=p.getChildren(E),B=b?[...A,...QX(E,p)]:A;return p.existsOne(D,B)}}return b=>n(b)&&p.existsOne(D,p.getChildren(b))}};function L8e(n,e,a,s,l){var p;let{name:x,data:f}=e;if(Array.isArray(f)){if(!(x in VR))throw new Error(`Unknown pseudo-class :${x}(${f})`);return VR[x](n,f,a,s,l)}let m=(p=a.pseudos)===null||p===void 0?void 0:p[x],D=typeof m=="string"?m:HX[x];if(typeof D=="string"){if(f!=null)throw new Error(`Pseudo ${x} doesn't have any arguments`);let b=Ab(D);return VR.is(n,b,a,s,l)}if(typeof m=="function")return YX(m,x,f,1),b=>m(b,f)&&n(b);if(x in Bb)return Bb[x](n,f,a,s);if(x in UR){let b=UR[x];return YX(b,x,f,2),E=>b(E,a,f)&&n(E)}throw new Error(`Unknown pseudo-class :${x}`)}function eY(n,e){let a=e.getParent(n);return a&&e.isTag(a)?a:null}function $8e(n,e,a,s,l){let{adapter:p,equals:x}=a;switch(e.type){case Kr.PseudoElement:throw new Error("Pseudo-elements are not supported by css-select");case Kr.ColumnCombinator:throw new Error("Column combinators are not yet supported by css-select");case Kr.Attribute:{if(e.namespace!=null)throw new Error("Namespaced attributes are not yet supported by css-select");return(!a.xmlMode||a.lowerCaseAttributeNames)&&(e.name=e.name.toLowerCase()),k8e[e.action](n,e,a)}case Kr.Pseudo:return L8e(n,e,a,s,l);case Kr.Tag:{if(e.namespace!=null)throw new Error("Namespaced tag names are not yet supported by css-select");let{name:f}=e;return(!a.xmlMode||a.lowerCaseTags)&&(f=f.toLowerCase()),function(D){return p.getName(D)===f&&n(D)}}case Kr.Descendant:{if(a.cacheResults===!1||typeof WeakSet>"u")return function(D){let b=D;for(;b=eY(b,p);)if(n(b))return!0;return!1};let f=new WeakSet;return function(D){let b=D;for(;b=eY(b,p);)if(!f.has(b)){if(p.isTag(b)&&n(b))return!0;f.add(b)}return!1}}case"_flexibleDescendant":return function(m){let D=m;do if(n(D))return!0;while(D=eY(D,p));return!1};case Kr.Parent:return function(m){return p.getChildren(m).some(D=>p.isTag(D)&&n(D))};case Kr.Child:return function(m){let D=p.getParent(m);return D!=null&&p.isTag(D)&&n(D)};case Kr.Sibling:return function(m){let D=p.getSiblings(m);for(let b=0;b<D.length;b++){let E=D[b];if(x(m,E))break;if(p.isTag(E)&&n(E))return!0}return!1};case Kr.Adjacent:return p.prevElementSibling?function(m){let D=p.prevElementSibling(m);return D!=null&&n(D)}:function(m){let D=p.getSiblings(m),b;for(let E=0;E<D.length;E++){let A=D[E];if(x(m,A))break;p.isTag(A)&&(b=A)}return!!b&&n(b)};case Kr.Universal:{if(e.namespace!=null&&e.namespace!=="*")throw new Error("Namespaced universal selectors are not yet supported by css-select");return n}}}function z8e(n,e,a){let s=GR(n,e,a);return ZX(s,e.adapter)}function GR(n,e,a){let s=typeof n=="string"?Ab(n):n;return XR(s,e,a)}function q8e(n){return n.type===Kr.Pseudo&&(n.name==="scope"||Array.isArray(n.data)&&n.data.some(e=>e.some(q8e)))}var kIt={type:Kr.Descendant},NIt={type:"_flexibleDescendant"},MIt={type:Kr.Pseudo,name:"scope",data:null};function OIt(n,{adapter:e},a){let s=!!a?.every(l=>{let p=e.isTag(l)&&e.getParent(l);return l===JX||p&&e.isTag(p)});for(let l of n){if(!(l.length>0&&Rb(l[0])&&l[0].type!==Kr.Descendant))if(s&&!l.some(q8e))l.unshift(kIt);else continue;l.unshift(MIt)}}function XR(n,e,a){var s;n.forEach(VX),a=(s=e.context)!==null&&s!==void 0?s:a;let l=Array.isArray(a),p=a&&(Array.isArray(a)?a:[a]);if(e.relativeSelector!==!1)OIt(n,e,p);else if(n.some(m=>m.length>0&&Rb(m[0])))throw new Error("Relative selectors are not allowed when the `relativeSelector` option is disabled");let x=!1,f=n.map(m=>{if(m.length>=2){let[D,b]=m;D.type!==Kr.Pseudo||D.name!=="scope"||(l&&b.type===Kr.Descendant?m[1]=NIt:(b.type===Kr.Adjacent||b.type===Kr.Sibling)&&(x=!0))}return LIt(m,e,p)}).reduce($It,Jl.default.falseFunc);return f.shouldTestNextSiblings=x,f}function LIt(n,e,a){var s;return n.reduce((l,p)=>l===Jl.default.falseFunc?Jl.default.falseFunc:$8e(l,p,e,a,XR),(s=e.rootFunc)!==null&&s!==void 0?s:Jl.default.trueFunc)}function $It(n,e){return e===Jl.default.falseFunc||n===Jl.default.trueFunc?n:n===Jl.default.falseFunc||e===Jl.default.trueFunc?e:function(s){return n(s)||e(s)}}var U8e=(n,e)=>n===e,zIt={adapter:zR,equals:U8e};function V8e(n){var e,a,s,l;let p=n??zIt;return(e=p.adapter)!==null&&e!==void 0||(p.adapter=zR),(a=p.equals)!==null&&a!==void 0||(p.equals=(l=(s=p.adapter)===null||s===void 0?void 0:s.equals)!==null&&l!==void 0?l:U8e),p}function rY(n){return function(a,s,l){let p=V8e(s);return n(a,p,l)}}var xrr=rY(z8e),frr=rY(GR),hrr=rY(XR);function G8e(n){return function(a,s,l){let p=V8e(l);typeof a!="function"&&(a=GR(a,p,s));let x=qIt(s,p.adapter,a.shouldTestNextSiblings);return n(a,x,p)}}function qIt(n,e,a=!1){return a&&(n=UIt(n,e)),Array.isArray(n)?e.removeSubsets(n):e.getChildren(n)}function UIt(n,e){let a=Array.isArray(n)?n.slice(0):[n],s=a.length;for(let l=0;l<s;l++){let p=QX(a[l],e);a.push(...p)}return a}var nY=G8e((n,e,a)=>n===tY.default.falseFunc||!e||e.length===0?[]:a.adapter.findAll(n,e)),YR=G8e((n,e,a)=>n===tY.default.falseFunc||!e||e.length===0?null:a.adapter.findOne(n,e));Xe();Yt();Xe();var E_e=qr(As(),1);Yt();var __e=qr(As(),1),R_e=qr(As(),1);Yt();Zl();lY();var dY=(n,e={})=>{let a=n._internal_store;if(!a){a={counts:{}},n._internal_store=a;for(let l of n){let p=l.type,x=l[`${p}_id`];if(!x)continue;let f=Number.parseInt(x.split("_").pop());Number.isNaN(f)||(a.counts[p]=Math.max(a.counts[p]??0,f))}}return new Proxy({},{get:(l,p)=>p==="toArray"?()=>n:{get:x=>n.find(f=>f.type===p&&f[`${p}_id`]===x),getUsing:x=>{let f=Object.keys(x);if(f.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");let m=f[0],D=m.replace("_id",""),b=n.find(E=>E.type===D&&E[m]===x[m]);return b?n.find(E=>E.type===p&&E[`${p}_id`]===b[`${p}_id`]):null},getWhere:x=>{let f=Object.keys(x);return n.find(m=>m.type===p&&f.every(D=>m[D]===x[D]))},list:x=>{let f=x?Object.keys(x):[];return n.filter(m=>m.type===p&&f.every(D=>m[D]===x[D]))},insert:x=>{var D;(D=a.counts)[p]??(D[p]=-1),a.counts[p]++;let f=a.counts[p],m={type:p,[`${p}_id`]:`${p}_${f}`,...x};return e.validateInserts&&(Vf[p]??Uf).parse(m),n.push(m),m},delete:x=>{let f=n.find(m=>m[`${p}_id`]===x);f&&n.splice(n.indexOf(f),1)},update:(x,f)=>{let m=n.find(D=>D[`${p}_id`]===x);if(m)return Object.assign(m,f),m},select:x=>{if(p==="source_component")return n.find(f=>f.type==="source_component"&&f.name===x.replace(/\./g,""));if(p==="pcb_port"||p==="source_port"||p==="schematic_port"){let[f,m]=x.replace(/\./g,"").split(/[\s\>]+/),D=n.find(E=>E.type==="source_component"&&E.name===f);if(!D)return null;let b=n.find(E=>E.type==="source_port"&&E.source_component_id===D.source_component_id&&(E.name===m||(E.port_hints??[]).includes(m)));if(!b)return null;if(p==="source_port")return b;if(p==="pcb_port")return n.find(E=>E.type==="pcb_port"&&E.source_port_id===b.source_port_id);if(p==="schematic_port")return n.find(E=>E.type==="schematic_port"&&E.source_port_id===b.source_port_id)}}}})};dY.unparsed=dY;var a_e=dY;var Car=qr(i_e(),1);Zo();function Ql(n){let e=n.width/2,a=n.height/2;return{minX:n.center.x-e,maxX:n.center.x+e,minY:n.center.y-a,maxY:n.center.y+a}}function tg(n,e){let a=Ql(n),s=Ql(e),l=Math.max(a.minX-s.maxX,s.minX-a.maxX,0),p=Math.max(a.minY-s.maxY,s.minY-a.maxY,0),x={x:0,y:0},f={x:0,y:0};return l===0&&p===0?{distance:0,pointA:n.center,pointB:e.center}:(x.x=hs(n.center.x,s.minX,s.maxX),x.y=hs(n.center.y,s.minY,s.maxY),f.x=hs(e.center.x,a.minX,a.maxX),f.y=hs(e.center.y,a.minY,a.maxY),{distance:Math.hypot(x.x-f.x,x.y-f.y),pointA:x,pointB:f})}function hs(n,e,a){return Math.max(e,Math.min(a,n))}function Nb(n,e){let a=Number.POSITIVE_INFINITY,s={x:0,y:0},l={x:0,y:0};for(let p of n)for(let x of e){let{distance:f,pointA:m,pointB:D}=tg(p,x);f<a&&(a=f,s=m,l=D)}return{pointA:s,pointB:l,distance:a}}Zo();Zo();var x_e="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var f_e=(n=21)=>{let e="",a=crypto.getRandomValues(new Uint8Array(n|=0));for(;n--;)e+=x_e[a[n]&63];return e};Zo();var n1=(n,e)=>Math.abs(n.x-e.x)+Math.abs(n.y-e.y),h_e=(n,e)=>{let a=e.x-n.x,s=e.y-n.y;return Math.abs(a)>Math.abs(s)?{dx:Math.sign(a),dy:0}:{dx:0,dy:Math.sign(s)}},b_e=(n,e,a)=>Math.abs(n.x-e.x)*Math.abs(a.dx)+Math.abs(n.y-e.y)*Math.abs(a.dy),F_e=(n,e=.1)=>`${Math.round(n.x/e)},${Math.round(n.y/e)}`,m_e=(n,e)=>Math.abs(n-e)<1e-4,v_e=(n,e,{viaDiameter:a=.5}={})=>{let s=[];for(let l=0;l<n.length-1;l++){let[p,x]=[n[l],n[l+1]],f=l-1>=0?n[l-1]:null,m=m_e(p.y,x.y),D=m_e(p.x,x.x);if(!m&&!D)throw new Error(`getObstaclesFromTrace currently only supports horizontal and vertical traces (not diagonals) Conflicting trace: ${e}, start: (${p.x}, ${p.y}), end: (${x.x}, ${x.y})`);let b={type:"rect",layers:[p.layer],center:{x:(p.x+x.x)/2,y:(p.y+x.y)/2},width:m?Math.abs(p.x-x.x):.1,height:D?Math.abs(p.y-x.y):.1,connectedTo:[e]};if(s.push(b),f&&f.layer===p.layer&&p.layer!==x.layer){let E={type:"rect",layers:[p.layer,x.layer],center:{x:p.x,y:p.y},connectedTo:[e],width:a,height:a};s.push(E)}}return s},C_e=class{constructor(n){q(this,"obstacles");q(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,a){a??(a=this.GRID_STEP);for(let s of this.obstacles){let l=s.width/2+a,p=s.height/2+a;if(n>=s.center.x-l&&n<=s.center.x+l&&e>=s.center.y-p&&e<=s.center.y+p)return s}return null}isObstacleAt(n,e,a){return this.getObstacleAt(n,e,a)!==null}getDirectionDistancesToNearestObstacle(n,e){let{GRID_STEP:a}=this,s={left:1/0,top:1/0,bottom:1/0,right:1/0};for(let l of this.obstacles)if(l.type==="rect"){let p=l.center.x-l.width/2-a,x=l.center.x+l.width/2+a,f=l.center.y+l.height/2+a,m=l.center.y-l.height/2-a;e>=m&&e<=f&&n>p&&(s.left=Math.min(s.left,n-x)),e>=m&&e<=f&&n<x&&(s.right=Math.min(s.right,p-n)),n>=p&&n<=x&&e<f&&(s.top=Math.min(s.top,m-e)),n>=p&&n<=x&&e>m&&(s.bottom=Math.min(s.bottom,e-f))}return s}getOrthoDirectionCollisionInfo(n,e,{margin:a=0}={}){let{x:s,y:l}=n,{dx:p,dy:x}=e,f=1/0,m=null;for(let D of this.obstacles){let b=D.left-a,E=D.right+a,A=D.top+a,B=D.bottom-a,w=null;p===1&&x===0?l>B&&l<A&&s<D.left&&(w=D.left-s):p===-1&&x===0?l>B&&l<A&&s>D.right&&(w=s-D.right):p===0&&x===1?s>b&&s<E&&l<D.bottom&&(w=D.bottom-l):p===0&&x===-1&&s>b&&s<E&&l>D.top&&(w=l-D.top),w!==null&&w<f&&(f=w,m=D)}return{dx:p,dy:x,wallDistance:f,obstacle:m}}getObstaclesOverlappingRegion(n){let e=[];for(let a of this.obstacles){let{left:s,right:l,top:p,bottom:x}=a;s<=n.maxX&&l>=n.minX&&p<=n.maxY&&x>=n.minY&&e.push(a)}return e}};function XIt(n){if(n.length<4)return n;let e=[{...n[0]}],a=n[0].layer;for(let s=1;s<n.length;s++){let l={start:n[s-1],end:n[s]},p=n[s].route_type==="via"||n[s-1].route_type==="via";if(n[s].layer!==a||p){e.push({...n[s]}),a=n[s].layer;continue}let x=!1,f=null,m=-1;for(let b=0;b<e.length-1;b++){let E={start:e[b],end:e[b+1]};if(E.start.layer===l.start.layer&&E.start.layer===l.start.layer){let A=YIt(E,l);if(A){x=!0,f={...A,layer:a},m=b;break}}}x&&f&&(e.splice(m+1),e.push(f));let D=e[e.length-1];(D.x!==n[s].x||D.y!==n[s].y)&&e.push(n[s])}return e}function YIt(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 a;if(n.start.x===n.end.x){let s=n.start.x,l=e.start.y;a={...n.start,x:s,y:l}}else{let s=e.start.x,l=n.start.y;a={...n.start,x:s,y:l}}return g_e(a,n)&&g_e(a,e)?a:null}function g_e(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 HIt(n){let e=[n[0]];for(let a=1;a<n.length-1;a++){let[s,l,p]=[n[a-1],n[a],n[a+1]];e.push(l),!(l.route_type!=="wire"||s.route_type!=="wire"||p.route_type!=="wire")&&s.layer===l.layer&&l.layer!==p.layer&&e.push({route_type:"via",from_layer:l.layer,to_layer:p.layer,x:l.x,y:l.y})}return e.push(n[n.length-1]),e}var Far=(0,__e.default)("autorouter:shortenPathWithShortcuts");function WIt(n,e){if(n.length<=2)return n;let a=[n[0]];for(let s=1;s<n.length;s++){let l={start:a[a.length-1],end:n[s]},p=-1,x=l.start.x===l.end.x,f=l.start.y===l.end.y;for(let m=s+1;m<n.length;m++){if(m<=p)continue;let D={start:n[m],end:n[m+1]};if(!D.end)continue;let b=D.start.x===D.end.x,E=D.start.y===D.end.y,A=x&&b,B=f&&E;if(B&&A||!(A||B))continue;let P=!1,k=Math.min(l.start.x,l.end.x),O=Math.max(l.start.x,l.end.x),$=Math.min(D.start.x,D.end.x),ee=Math.max(D.start.x,D.end.x),X=Math.min(l.start.y,l.end.y),te=Math.max(l.start.y,l.end.y),L=Math.min(D.start.y,D.end.y),J=Math.max(D.start.y,D.end.y);if(B?P=k<=ee&&O>=$:A&&(P=X<=J&&te>=L),!P)continue;let U=[],W=a[a.length-1],Z=n[m+2];if(!Z)continue;B&&$<O&&Z.x===$&&U.push({x:$,y:l.start.y,layer:l.start.layer}),B&&ee>k&&Z.x===ee&&U.push({x:ee,y:l.start.y,layer:l.start.layer}),A&&L<te&&Z.y===L&&U.push({x:l.start.x,y:L,layer:l.start.layer}),A&&J>X&&Z.y===J&&U.push({x:l.start.x,y:J,layer:l.start.layer});let de=null;for(let oe of U)if(!(e(W,oe)||e(Z,oe))){de=oe;break}if(de){a.push(de),s=m+1,p=m+1;break}}p===-1&&a.push(n[s])}return a[a.length-1]!==n[n.length-1]&&a.push(n[n.length-1]),a}var r1=(0,E_e.default)("autorouting-dataset:astar"),A_e=class{constructor(n){q(this,"openSet",[]);q(this,"closedSet",new Set);q(this,"debug",!1);q(this,"debugSolutions");q(this,"debugMessage",null);q(this,"debugTraceCount",0);q(this,"input");q(this,"obstacles");q(this,"allObstacles");q(this,"startNode");q(this,"goalPoint");q(this,"GRID_STEP");q(this,"OBSTACLE_MARGIN");q(this,"MAX_ITERATIONS");q(this,"isRemovePathLoopsEnabled");q(this,"isShortenPathWithShortcutsEnabled");q(this,"GREEDY_MULTIPLIER",1.1);q(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??r1.enabled,this.isRemovePathLoopsEnabled=n.isRemovePathLoopsEnabled??!1,this.isShortenPathWithShortcutsEnabled=n.isShortenPathWithShortcutsEnabled??!1,this.debug&&(r1.enabled=!0),r1.enabled&&(this.debugSolutions={},this.debugMessage="")}getNeighbors(n){return[]}isSameNode(n,e){return n1(n,e)<this.GRID_STEP}computeG(n,e){return n.g+n1(n,e)}computeH(n){return n1(n,this.goalPoint)}getNodeName(n){return F_e(n,this.GRID_STEP)}solveOneStep(){this.iterations+=1;let{openSet:n,closedSet:e,GRID_STEP:a,goalPoint:s}=this;n.sort((f,m)=>f.f-m.f);let l=n.shift();if(this.computeH(l)<=a*2)return{solved:!0,current:l,newNeighbors:[]};this.closedSet.add(this.getNodeName(l));let x=[];for(let f of this.getNeighbors(l)){if(e.has(this.getNodeName(f)))continue;let m=this.computeG(l,f),D=this.openSet.find(b=>this.isSameNode(b,f));if(!D||m<D.g){let b=this.computeH(f),E=m+b*this.GREEDY_MULTIPLIER,A={...f,g:m,h:b,f:E,obstacleHit:f.obstacleHit??void 0,manDistFromParent:n1(l,f),nodesInPath:l.nodesInPath+1,parent:l,enterMarginCost:f.enterMarginCost,travelMarginCostFactor:f.travelMarginCostFactor};n.push(A),x.push(A)}}return r1.enabled&&(n.sort((f,m)=>f.f-m.f),this.drawDebugSolution({current:l,newNeighbors:x})),{solved:!1,current:l,newNeighbors:x}}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:a,current:s}=this.solveOneStep();if(a){let l=[],p=s;for(;p;){let x=p.l;l.unshift({x:p.x,y:p.y,layer:x!==void 0?this.indexToLayer(x):e[0].layer}),p=p.parent}return r1.enabled&&(this.debugMessage+=`t${this.debugTraceCount}: ${this.iterations} iterations
951
+ )`,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 Ku=qr(Jf(),1);var JX={};function ZX(n,e){return n===Ku.default.falseFunc?Ku.default.falseFunc:a=>e.isTag(a)&&n(a)}function QX(n,e){let a=e.getSiblings(n);if(a.length<=1)return[];let s=a.indexOf(n);return s<0||s===a.length-1?[]:a.slice(s+1).filter(e.isTag)}function KX(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 WX=(n,e,a,s,l)=>{let p=l(e,KX(a),s);return p===Ku.default.trueFunc?n:p===Ku.default.falseFunc?Ku.default.falseFunc:x=>p(x)&&n(x)},VR={is:WX,matches:WX,where:WX,not(n,e,a,s,l){let p=l(e,KX(a),s);return p===Ku.default.falseFunc?n:p===Ku.default.trueFunc?Ku.default.falseFunc:x=>!p(x)&&n(x)},has(n,e,a,s,l){let{adapter:p}=a,x=KX(a);x.relativeSelector=!0;let f=e.some(b=>b.some(Rb))?[JX]:void 0,m=l(e,x,f);if(m===Ku.default.falseFunc)return Ku.default.falseFunc;let D=ZX(m,p);if(f&&m!==Ku.default.trueFunc){let{shouldTestNextSiblings:b=!1}=m;return E=>{if(!n(E))return!1;f[0]=E;let A=p.getChildren(E),B=b?[...A,...QX(E,p)]:A;return p.existsOne(D,B)}}return b=>n(b)&&p.existsOne(D,p.getChildren(b))}};function L8e(n,e,a,s,l){var p;let{name:x,data:f}=e;if(Array.isArray(f)){if(!(x in VR))throw new Error(`Unknown pseudo-class :${x}(${f})`);return VR[x](n,f,a,s,l)}let m=(p=a.pseudos)===null||p===void 0?void 0:p[x],D=typeof m=="string"?m:HX[x];if(typeof D=="string"){if(f!=null)throw new Error(`Pseudo ${x} doesn't have any arguments`);let b=Ab(D);return VR.is(n,b,a,s,l)}if(typeof m=="function")return YX(m,x,f,1),b=>m(b,f)&&n(b);if(x in Bb)return Bb[x](n,f,a,s);if(x in UR){let b=UR[x];return YX(b,x,f,2),E=>b(E,a,f)&&n(E)}throw new Error(`Unknown pseudo-class :${x}`)}function eY(n,e){let a=e.getParent(n);return a&&e.isTag(a)?a:null}function $8e(n,e,a,s,l){let{adapter:p,equals:x}=a;switch(e.type){case Kr.PseudoElement:throw new Error("Pseudo-elements are not supported by css-select");case Kr.ColumnCombinator:throw new Error("Column combinators are not yet supported by css-select");case Kr.Attribute:{if(e.namespace!=null)throw new Error("Namespaced attributes are not yet supported by css-select");return(!a.xmlMode||a.lowerCaseAttributeNames)&&(e.name=e.name.toLowerCase()),k8e[e.action](n,e,a)}case Kr.Pseudo:return L8e(n,e,a,s,l);case Kr.Tag:{if(e.namespace!=null)throw new Error("Namespaced tag names are not yet supported by css-select");let{name:f}=e;return(!a.xmlMode||a.lowerCaseTags)&&(f=f.toLowerCase()),function(D){return p.getName(D)===f&&n(D)}}case Kr.Descendant:{if(a.cacheResults===!1||typeof WeakSet>"u")return function(D){let b=D;for(;b=eY(b,p);)if(n(b))return!0;return!1};let f=new WeakSet;return function(D){let b=D;for(;b=eY(b,p);)if(!f.has(b)){if(p.isTag(b)&&n(b))return!0;f.add(b)}return!1}}case"_flexibleDescendant":return function(m){let D=m;do if(n(D))return!0;while(D=eY(D,p));return!1};case Kr.Parent:return function(m){return p.getChildren(m).some(D=>p.isTag(D)&&n(D))};case Kr.Child:return function(m){let D=p.getParent(m);return D!=null&&p.isTag(D)&&n(D)};case Kr.Sibling:return function(m){let D=p.getSiblings(m);for(let b=0;b<D.length;b++){let E=D[b];if(x(m,E))break;if(p.isTag(E)&&n(E))return!0}return!1};case Kr.Adjacent:return p.prevElementSibling?function(m){let D=p.prevElementSibling(m);return D!=null&&n(D)}:function(m){let D=p.getSiblings(m),b;for(let E=0;E<D.length;E++){let A=D[E];if(x(m,A))break;p.isTag(A)&&(b=A)}return!!b&&n(b)};case Kr.Universal:{if(e.namespace!=null&&e.namespace!=="*")throw new Error("Namespaced universal selectors are not yet supported by css-select");return n}}}function z8e(n,e,a){let s=GR(n,e,a);return ZX(s,e.adapter)}function GR(n,e,a){let s=typeof n=="string"?Ab(n):n;return XR(s,e,a)}function q8e(n){return n.type===Kr.Pseudo&&(n.name==="scope"||Array.isArray(n.data)&&n.data.some(e=>e.some(q8e)))}var kIt={type:Kr.Descendant},NIt={type:"_flexibleDescendant"},MIt={type:Kr.Pseudo,name:"scope",data:null};function OIt(n,{adapter:e},a){let s=!!a?.every(l=>{let p=e.isTag(l)&&e.getParent(l);return l===JX||p&&e.isTag(p)});for(let l of n){if(!(l.length>0&&Rb(l[0])&&l[0].type!==Kr.Descendant))if(s&&!l.some(q8e))l.unshift(kIt);else continue;l.unshift(MIt)}}function XR(n,e,a){var s;n.forEach(VX),a=(s=e.context)!==null&&s!==void 0?s:a;let l=Array.isArray(a),p=a&&(Array.isArray(a)?a:[a]);if(e.relativeSelector!==!1)OIt(n,e,p);else if(n.some(m=>m.length>0&&Rb(m[0])))throw new Error("Relative selectors are not allowed when the `relativeSelector` option is disabled");let x=!1,f=n.map(m=>{if(m.length>=2){let[D,b]=m;D.type!==Kr.Pseudo||D.name!=="scope"||(l&&b.type===Kr.Descendant?m[1]=NIt:(b.type===Kr.Adjacent||b.type===Kr.Sibling)&&(x=!0))}return LIt(m,e,p)}).reduce($It,Jl.default.falseFunc);return f.shouldTestNextSiblings=x,f}function LIt(n,e,a){var s;return n.reduce((l,p)=>l===Jl.default.falseFunc?Jl.default.falseFunc:$8e(l,p,e,a,XR),(s=e.rootFunc)!==null&&s!==void 0?s:Jl.default.trueFunc)}function $It(n,e){return e===Jl.default.falseFunc||n===Jl.default.trueFunc?n:n===Jl.default.falseFunc||e===Jl.default.trueFunc?e:function(s){return n(s)||e(s)}}var U8e=(n,e)=>n===e,zIt={adapter:zR,equals:U8e};function V8e(n){var e,a,s,l;let p=n??zIt;return(e=p.adapter)!==null&&e!==void 0||(p.adapter=zR),(a=p.equals)!==null&&a!==void 0||(p.equals=(l=(s=p.adapter)===null||s===void 0?void 0:s.equals)!==null&&l!==void 0?l:U8e),p}function rY(n){return function(a,s,l){let p=V8e(s);return n(a,p,l)}}var xrr=rY(z8e),frr=rY(GR),hrr=rY(XR);function G8e(n){return function(a,s,l){let p=V8e(l);typeof a!="function"&&(a=GR(a,p,s));let x=qIt(s,p.adapter,a.shouldTestNextSiblings);return n(a,x,p)}}function qIt(n,e,a=!1){return a&&(n=UIt(n,e)),Array.isArray(n)?e.removeSubsets(n):e.getChildren(n)}function UIt(n,e){let a=Array.isArray(n)?n.slice(0):[n],s=a.length;for(let l=0;l<s;l++){let p=QX(a[l],e);a.push(...p)}return a}var nY=G8e((n,e,a)=>n===tY.default.falseFunc||!e||e.length===0?[]:a.adapter.findAll(n,e)),YR=G8e((n,e,a)=>n===tY.default.falseFunc||!e||e.length===0?null:a.adapter.findOne(n,e));Xe();Yt();Xe();var E_e=qr(As(),1);Yt();var __e=qr(As(),1),R_e=qr(As(),1);Yt();Zl();lY();var dY=(n,e={})=>{let a=n._internal_store;if(!a){a={counts:{}},n._internal_store=a;for(let l of n){let p=l.type,x=l[`${p}_id`];if(!x)continue;let f=Number.parseInt(x.split("_").pop());Number.isNaN(f)||(a.counts[p]=Math.max(a.counts[p]??0,f))}}return new Proxy({},{get:(l,p)=>p==="toArray"?()=>n:{get:x=>n.find(f=>f.type===p&&f[`${p}_id`]===x),getUsing:x=>{let f=Object.keys(x);if(f.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");let m=f[0],D=m.replace("_id",""),b=n.find(E=>E.type===D&&E[m]===x[m]);return b?n.find(E=>E.type===p&&E[`${p}_id`]===b[`${p}_id`]):null},getWhere:x=>{let f=Object.keys(x);return n.find(m=>m.type===p&&f.every(D=>m[D]===x[D]))},list:x=>{let f=x?Object.keys(x):[];return n.filter(m=>m.type===p&&f.every(D=>m[D]===x[D]))},insert:x=>{var D;(D=a.counts)[p]??(D[p]=-1),a.counts[p]++;let f=a.counts[p],m={type:p,[`${p}_id`]:`${p}_${f}`,...x};return e.validateInserts&&(Vf[p]??Uf).parse(m),n.push(m),m},delete:x=>{let f=n.find(m=>m[`${p}_id`]===x);f&&n.splice(n.indexOf(f),1)},update:(x,f)=>{let m=n.find(D=>D.type===p&&D[`${p}_id`]===x);if(m)return Object.assign(m,f),m},select:x=>{if(p==="source_component")return n.find(f=>f.type==="source_component"&&f.name===x.replace(/\./g,""));if(p==="pcb_port"||p==="source_port"||p==="schematic_port"){let[f,m]=x.replace(/\./g,"").split(/[\s\>]+/),D=n.find(E=>E.type==="source_component"&&E.name===f);if(!D)return null;let b=n.find(E=>E.type==="source_port"&&E.source_component_id===D.source_component_id&&(E.name===m||(E.port_hints??[]).includes(m)));if(!b)return null;if(p==="source_port")return b;if(p==="pcb_port")return n.find(E=>E.type==="pcb_port"&&E.source_port_id===b.source_port_id);if(p==="schematic_port")return n.find(E=>E.type==="schematic_port"&&E.source_port_id===b.source_port_id)}}}})};dY.unparsed=dY;var a_e=dY;var Car=qr(i_e(),1);Zo();function Ql(n){let e=n.width/2,a=n.height/2;return{minX:n.center.x-e,maxX:n.center.x+e,minY:n.center.y-a,maxY:n.center.y+a}}function tg(n,e){let a=Ql(n),s=Ql(e),l=Math.max(a.minX-s.maxX,s.minX-a.maxX,0),p=Math.max(a.minY-s.maxY,s.minY-a.maxY,0),x={x:0,y:0},f={x:0,y:0};return l===0&&p===0?{distance:0,pointA:n.center,pointB:e.center}:(x.x=hs(n.center.x,s.minX,s.maxX),x.y=hs(n.center.y,s.minY,s.maxY),f.x=hs(e.center.x,a.minX,a.maxX),f.y=hs(e.center.y,a.minY,a.maxY),{distance:Math.hypot(x.x-f.x,x.y-f.y),pointA:x,pointB:f})}function hs(n,e,a){return Math.max(e,Math.min(a,n))}function Nb(n,e){let a=Number.POSITIVE_INFINITY,s={x:0,y:0},l={x:0,y:0};for(let p of n)for(let x of e){let{distance:f,pointA:m,pointB:D}=tg(p,x);f<a&&(a=f,s=m,l=D)}return{pointA:s,pointB:l,distance:a}}Zo();Zo();var x_e="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var f_e=(n=21)=>{let e="",a=crypto.getRandomValues(new Uint8Array(n|=0));for(;n--;)e+=x_e[a[n]&63];return e};Zo();var n1=(n,e)=>Math.abs(n.x-e.x)+Math.abs(n.y-e.y),h_e=(n,e)=>{let a=e.x-n.x,s=e.y-n.y;return Math.abs(a)>Math.abs(s)?{dx:Math.sign(a),dy:0}:{dx:0,dy:Math.sign(s)}},b_e=(n,e,a)=>Math.abs(n.x-e.x)*Math.abs(a.dx)+Math.abs(n.y-e.y)*Math.abs(a.dy),F_e=(n,e=.1)=>`${Math.round(n.x/e)},${Math.round(n.y/e)}`,m_e=(n,e)=>Math.abs(n-e)<1e-4,v_e=(n,e,{viaDiameter:a=.5}={})=>{let s=[];for(let l=0;l<n.length-1;l++){let[p,x]=[n[l],n[l+1]],f=l-1>=0?n[l-1]:null,m=m_e(p.y,x.y),D=m_e(p.x,x.x);if(!m&&!D)throw new Error(`getObstaclesFromTrace currently only supports horizontal and vertical traces (not diagonals) Conflicting trace: ${e}, start: (${p.x}, ${p.y}), end: (${x.x}, ${x.y})`);let b={type:"rect",layers:[p.layer],center:{x:(p.x+x.x)/2,y:(p.y+x.y)/2},width:m?Math.abs(p.x-x.x):.1,height:D?Math.abs(p.y-x.y):.1,connectedTo:[e]};if(s.push(b),f&&f.layer===p.layer&&p.layer!==x.layer){let E={type:"rect",layers:[p.layer,x.layer],center:{x:p.x,y:p.y},connectedTo:[e],width:a,height:a};s.push(E)}}return s},C_e=class{constructor(n){q(this,"obstacles");q(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,a){a??(a=this.GRID_STEP);for(let s of this.obstacles){let l=s.width/2+a,p=s.height/2+a;if(n>=s.center.x-l&&n<=s.center.x+l&&e>=s.center.y-p&&e<=s.center.y+p)return s}return null}isObstacleAt(n,e,a){return this.getObstacleAt(n,e,a)!==null}getDirectionDistancesToNearestObstacle(n,e){let{GRID_STEP:a}=this,s={left:1/0,top:1/0,bottom:1/0,right:1/0};for(let l of this.obstacles)if(l.type==="rect"){let p=l.center.x-l.width/2-a,x=l.center.x+l.width/2+a,f=l.center.y+l.height/2+a,m=l.center.y-l.height/2-a;e>=m&&e<=f&&n>p&&(s.left=Math.min(s.left,n-x)),e>=m&&e<=f&&n<x&&(s.right=Math.min(s.right,p-n)),n>=p&&n<=x&&e<f&&(s.top=Math.min(s.top,m-e)),n>=p&&n<=x&&e>m&&(s.bottom=Math.min(s.bottom,e-f))}return s}getOrthoDirectionCollisionInfo(n,e,{margin:a=0}={}){let{x:s,y:l}=n,{dx:p,dy:x}=e,f=1/0,m=null;for(let D of this.obstacles){let b=D.left-a,E=D.right+a,A=D.top+a,B=D.bottom-a,w=null;p===1&&x===0?l>B&&l<A&&s<D.left&&(w=D.left-s):p===-1&&x===0?l>B&&l<A&&s>D.right&&(w=s-D.right):p===0&&x===1?s>b&&s<E&&l<D.bottom&&(w=D.bottom-l):p===0&&x===-1&&s>b&&s<E&&l>D.top&&(w=l-D.top),w!==null&&w<f&&(f=w,m=D)}return{dx:p,dy:x,wallDistance:f,obstacle:m}}getObstaclesOverlappingRegion(n){let e=[];for(let a of this.obstacles){let{left:s,right:l,top:p,bottom:x}=a;s<=n.maxX&&l>=n.minX&&p<=n.maxY&&x>=n.minY&&e.push(a)}return e}};function XIt(n){if(n.length<4)return n;let e=[{...n[0]}],a=n[0].layer;for(let s=1;s<n.length;s++){let l={start:n[s-1],end:n[s]},p=n[s].route_type==="via"||n[s-1].route_type==="via";if(n[s].layer!==a||p){e.push({...n[s]}),a=n[s].layer;continue}let x=!1,f=null,m=-1;for(let b=0;b<e.length-1;b++){let E={start:e[b],end:e[b+1]};if(E.start.layer===l.start.layer&&E.start.layer===l.start.layer){let A=YIt(E,l);if(A){x=!0,f={...A,layer:a},m=b;break}}}x&&f&&(e.splice(m+1),e.push(f));let D=e[e.length-1];(D.x!==n[s].x||D.y!==n[s].y)&&e.push(n[s])}return e}function YIt(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 a;if(n.start.x===n.end.x){let s=n.start.x,l=e.start.y;a={...n.start,x:s,y:l}}else{let s=e.start.x,l=n.start.y;a={...n.start,x:s,y:l}}return g_e(a,n)&&g_e(a,e)?a:null}function g_e(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 HIt(n){let e=[n[0]];for(let a=1;a<n.length-1;a++){let[s,l,p]=[n[a-1],n[a],n[a+1]];e.push(l),!(l.route_type!=="wire"||s.route_type!=="wire"||p.route_type!=="wire")&&s.layer===l.layer&&l.layer!==p.layer&&e.push({route_type:"via",from_layer:l.layer,to_layer:p.layer,x:l.x,y:l.y})}return e.push(n[n.length-1]),e}var Far=(0,__e.default)("autorouter:shortenPathWithShortcuts");function WIt(n,e){if(n.length<=2)return n;let a=[n[0]];for(let s=1;s<n.length;s++){let l={start:a[a.length-1],end:n[s]},p=-1,x=l.start.x===l.end.x,f=l.start.y===l.end.y;for(let m=s+1;m<n.length;m++){if(m<=p)continue;let D={start:n[m],end:n[m+1]};if(!D.end)continue;let b=D.start.x===D.end.x,E=D.start.y===D.end.y,A=x&&b,B=f&&E;if(B&&A||!(A||B))continue;let P=!1,k=Math.min(l.start.x,l.end.x),O=Math.max(l.start.x,l.end.x),$=Math.min(D.start.x,D.end.x),ee=Math.max(D.start.x,D.end.x),X=Math.min(l.start.y,l.end.y),te=Math.max(l.start.y,l.end.y),L=Math.min(D.start.y,D.end.y),J=Math.max(D.start.y,D.end.y);if(B?P=k<=ee&&O>=$:A&&(P=X<=J&&te>=L),!P)continue;let U=[],W=a[a.length-1],Z=n[m+2];if(!Z)continue;B&&$<O&&Z.x===$&&U.push({x:$,y:l.start.y,layer:l.start.layer}),B&&ee>k&&Z.x===ee&&U.push({x:ee,y:l.start.y,layer:l.start.layer}),A&&L<te&&Z.y===L&&U.push({x:l.start.x,y:L,layer:l.start.layer}),A&&J>X&&Z.y===J&&U.push({x:l.start.x,y:J,layer:l.start.layer});let de=null;for(let oe of U)if(!(e(W,oe)||e(Z,oe))){de=oe;break}if(de){a.push(de),s=m+1,p=m+1;break}}p===-1&&a.push(n[s])}return a[a.length-1]!==n[n.length-1]&&a.push(n[n.length-1]),a}var r1=(0,E_e.default)("autorouting-dataset:astar"),A_e=class{constructor(n){q(this,"openSet",[]);q(this,"closedSet",new Set);q(this,"debug",!1);q(this,"debugSolutions");q(this,"debugMessage",null);q(this,"debugTraceCount",0);q(this,"input");q(this,"obstacles");q(this,"allObstacles");q(this,"startNode");q(this,"goalPoint");q(this,"GRID_STEP");q(this,"OBSTACLE_MARGIN");q(this,"MAX_ITERATIONS");q(this,"isRemovePathLoopsEnabled");q(this,"isShortenPathWithShortcutsEnabled");q(this,"GREEDY_MULTIPLIER",1.1);q(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??r1.enabled,this.isRemovePathLoopsEnabled=n.isRemovePathLoopsEnabled??!1,this.isShortenPathWithShortcutsEnabled=n.isShortenPathWithShortcutsEnabled??!1,this.debug&&(r1.enabled=!0),r1.enabled&&(this.debugSolutions={},this.debugMessage="")}getNeighbors(n){return[]}isSameNode(n,e){return n1(n,e)<this.GRID_STEP}computeG(n,e){return n.g+n1(n,e)}computeH(n){return n1(n,this.goalPoint)}getNodeName(n){return F_e(n,this.GRID_STEP)}solveOneStep(){this.iterations+=1;let{openSet:n,closedSet:e,GRID_STEP:a,goalPoint:s}=this;n.sort((f,m)=>f.f-m.f);let l=n.shift();if(this.computeH(l)<=a*2)return{solved:!0,current:l,newNeighbors:[]};this.closedSet.add(this.getNodeName(l));let x=[];for(let f of this.getNeighbors(l)){if(e.has(this.getNodeName(f)))continue;let m=this.computeG(l,f),D=this.openSet.find(b=>this.isSameNode(b,f));if(!D||m<D.g){let b=this.computeH(f),E=m+b*this.GREEDY_MULTIPLIER,A={...f,g:m,h:b,f:E,obstacleHit:f.obstacleHit??void 0,manDistFromParent:n1(l,f),nodesInPath:l.nodesInPath+1,parent:l,enterMarginCost:f.enterMarginCost,travelMarginCostFactor:f.travelMarginCostFactor};n.push(A),x.push(A)}}return r1.enabled&&(n.sort((f,m)=>f.f-m.f),this.drawDebugSolution({current:l,newNeighbors:x})),{solved:!1,current:l,newNeighbors:x}}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:a,current:s}=this.solveOneStep();if(a){let l=[],p=s;for(;p;){let x=p.l;l.unshift({x:p.x,y:p.y,layer:x!==void 0?this.indexToLayer(x):e[0].layer}),p=p.parent}return r1.enabled&&(this.debugMessage+=`t${this.debugTraceCount}: ${this.iterations} iterations
952
952
  `),this.isRemovePathLoopsEnabled&&(l=XIt(l)),this.isShortenPathWithShortcutsEnabled&&(l=WIt(l,(x,f)=>{if(x.x===f.x&&x.y===f.y)return!1;let m=this.obstacles.getOrthoDirectionCollisionInfo({x:x.x,y:x.y,l:this.layerToIndex(x.layer)??0},{dx:Math.sign(f.x-x.x),dy:Math.sign(f.y-x.y),dl:0},{margin:.05}),D=Math.sqrt((x.x-f.x)**2+(x.y-f.y)**2);return m.wallDistance<D})),{solved:!0,route:l,connectionName:n.name}}if(this.openSet.length===0)break}return r1.enabled&&(this.debugMessage+=`t${this.debugTraceCount}: ${this.iterations} iterations (failed)
953
953
  `),{solved:!1,connectionName:n.name}}createObstacleList({dominantLayer:n,connection:e,obstaclesFromTraces:a}){return new C_e(this.allObstacles.filter(s=>!s.connectedTo.includes(e.name)).filter(s=>s.layers.includes(n)).concat(a??[]))}postprocessConnectionSolveResult(n,e){return e}solve(){let n=[],e=[];this.debugTraceCount=0;for(let a of this.input.connections){let s=a.pointsToConnect[0].layer??"top";this.debugTraceCount+=1,this.obstacles=this.createObstacleList({dominantLayer:s,connection:a,obstaclesFromTraces:e});let l=this.solveConnection(a);l=this.postprocessConnectionSolveResult(a,l),n.push(l),r1.enabled&&this.drawDebugTraceObstacles(e),l.solved&&e.push(...v_e(l.route.map(p=>({x:p.x,y:p.y,layer:p.layer??s})),a.name))}return n}solveAndMapToTraces(){return this.solve().flatMap(e=>e.solved?[{type:"pcb_trace",pcb_trace_id:`pcb_trace_for_${e.connectionName}`,route:HIt(e.route.map(a=>({route_type:"wire",x:a.x,y:a.y,width:this.input.minTraceWidth,layer:a.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:a}=this;for(let s in a)s.startsWith(`t${e}_`)&&a[s].push(...n.map((l,p)=>({type:"pcb_smtpad",pcb_component_id:"",layer:l.layers[0],width:l.width,shape:"rect",x:l.center.x,y:l.center.y,pcb_smtpad_id:`trace_obstacle_${p}`,height:l.height})))}drawDebugSolution({current:n,newNeighbors:e}){let a=this.getDebugGroup();if(!a)return;let{openSet:s,debugTraceCount:l,debugSolutions:p}=this;p[a]??(p[a]=[]);let x=p[a];x.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 f=0;f<s.length;f++){let m=s[f];x.push({type:"pcb_fabrication_note_path",pcb_component_id:"",pcb_fabrication_note_path_id:`note_path_${m.x}_${m.y}`,layer:"top",route:[[0,.05],[.05,0],[0,-.05],[-.05,0],[0,.05]].map(([D,b])=>({x:m.x+D,y:m.y+b})),stroke_width:.01}),x.push({type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:`debug_note_${m.x}_${m.y}`,font:"tscircuit2024",font_size:.03,text:f.toString(),pcb_component_id:"",layer:"top",anchor_position:{x:m.x,y:m.y},anchor_alignment:"center"})}if(n.parent){let f=[],m=n;for(;m;)f.unshift(m),m=m.parent;x.push({type:"pcb_fabrication_note_path",pcb_component_id:"",pcb_fabrication_note_path_id:`note_path_${n.x}_${n.y}`,layer:"top",route:f,stroke_width:.01})}}},KIt=(0,R_e.default)("autorouting-dataset:infinite-grid-ijump-astar:get-distance-to-overcome-obstacle");function hY({node:n,travelDir:e,wallDir:a,obstacle:s,obstacles:l,obstaclesInRow:p=0,OBSTACLE_MARGIN:x=.15,SHOULD_DETECT_CONJOINED_OBSTACLES:f=!1,MAX_CONJOINED_OBSTACLES:m=20}){let D;if(e.dx===0?e.dy>0?D=s.center.y+s.height/2-n.y:D=n.y-(s.center.y-s.height/2):e.dx>0?D=s.center.x+s.width/2-n.x:D=n.x-(s.center.x-s.width/2),D+=x,f&&p<m){let b=l.getObstacleAt(n.x+e.dx*D+a.dx*(a.wallDistance+.001),n.y+e.dy*D+a.dy*(a.wallDistance+.001));if(b===s)return D;if(b&&b.type==="rect"){let E=e.dy===0,A=E?s.height:s.width;if((E?b.height:b.width)>A)return KIt("next obstacle on path is bigger, not trying to overcome it"),D;let w=hY({node:{x:n.x+e.dx*D,y:n.y+e.dy*D},travelDir:e,wallDir:a,obstacle:b,obstacles:l,obstaclesInRow:p+1,SHOULD_DETECT_CONJOINED_OBSTACLES:f,MAX_CONJOINED_OBSTACLES:m,OBSTACLE_MARGIN:x});D+=w}}return D}var JIt=class extends A_e{constructor(){super(...arguments);q(this,"MAX_ITERATIONS",200)}getNeighbors(e){let a=this.obstacles,s=this.goalPoint,l;e.parent?l=h_e(e.parent,e):l=h_e(e,s);let p=[{dx:0,dy:1},{dx:1,dy:0},{dx:0,dy:-1},{dx:-1,dy:0}].filter(f=>f.dx===l.dx*-1&&f.dy===l.dy*-1?!1:!(f.dx===l.dx&&f.dy===l.dy&&e.parent?.obstacleHit)).map(f=>a.getOrthoDirectionCollisionInfo(e,f,{margin:this.OBSTACLE_MARGIN})).filter(f=>f.wallDistance>=this.OBSTACLE_MARGIN),x=[];for(let f of p){let m=null;e?.obstacleHit&&(m=hY({node:e,travelDir:f,wallDir:{...l,wallDistance:this.OBSTACLE_MARGIN},obstacle:e.obstacleHit,obstacles:a,OBSTACLE_MARGIN:this.OBSTACLE_MARGIN,SHOULD_DETECT_CONJOINED_OBSTACLES:!0}));let D=b_e(e,s,f),b=(f.dx===0||Math.sign(s.x-e.x)===f.dx)&&(f.dy===0||Math.sign(s.y-e.y)===f.dy);D<f.wallDistance&&D>0&&b?x.push({...f,travelDistance:D}):m!==null&&m<f.wallDistance?x.push({...f,travelDistance:m}):f.wallDistance!==1/0&&x.push({...f,travelDistance:f.wallDistance-this.OBSTACLE_MARGIN})}return x.filter(f=>!a.isObstacleAt(e.x+f.dx*f.travelDistance,e.y+f.dy*f.travelDistance)).map(f=>({x:e.x+f.dx*f.travelDistance,y:e.y+f.dy*f.travelDistance,obstacleHit:f.obstacle}))}};function ZIt(n,e=4){let{center:a,width:s,height:l,rotation:p}=n,x=[],f=p*Math.PI/180,m=Math.cos(f),D=Math.sin(f),b=(p%360+360)%360;if(l<=s?b>=45&&b<135||b>=225&&b<315:b>=135&&b<225||b>=315||b<45){let A=s/e;for(let B=0;B<e;B++){let w=(B-e/2+.5)*A,P=-w*m,k=-w*D,O=A*1.1,$=Math.abs(l*m)+Math.abs(A*D);x.push({center:{x:a.x+P,y:a.y+k},width:O,height:$})}}else{let A=l/e;for(let B=0;B<e;B++){let w=(B-e/2+.5)*A,P=-w*D,k=w*m,O=Math.abs(s*m)+Math.abs(A*D),$=A*1.1;x.push({center:{x:a.x+P,y:a.y+k},width:O,height:$})}}return x}var ZR=["top","inner1","inner2","bottom"],S_e=(n,e)=>{let a=l=>e?l.concat(l.map(p=>e?.getNetConnectedToId(p)).filter(Boolean)):l,s=[];for(let l of n)if(l.type==="pcb_smtpad"){if(l.shape==="circle")s.push({type:"oval",layers:[l.layer],center:{x:l.x,y:l.y},width:l.radius*2,height:l.radius*2,connectedTo:a([l.pcb_smtpad_id])});else if(l.shape==="rect")s.push({type:"rect",layers:[l.layer],center:{x:l.x,y:l.y},width:l.width,height:l.height,connectedTo:a([l.pcb_smtpad_id])});else if(l.shape==="rotated_rect"){let p={center:{x:l.x,y:l.y},width:l.width,height:l.height,rotation:l.ccw_rotation},x=ZIt(p);for(let f of x)s.push({type:"rect",layers:[l.layer],center:f.center,width:f.width,height:f.height,connectedTo:a([l.pcb_smtpad_id])})}}else if(l.type==="pcb_keepout")l.shape==="circle"?s.push({type:"oval",layers:l.layers,center:{x:l.center.x,y:l.center.y},width:l.radius*2,height:l.radius*2,connectedTo:[]}):l.shape==="rect"&&s.push({type:"rect",layers:l.layers,center:{x:l.center.x,y:l.center.y},width:l.width,height:l.height,connectedTo:[]});else if(l.type==="pcb_hole")l.hole_shape==="oval"?s.push({type:"oval",center:{x:l.x,y:l.y},width:l.hole_width,height:l.hole_height,connectedTo:[]}):l.hole_shape==="square"?s.push({type:"rect",layers:ZR,center:{x:l.x,y:l.y},width:l.hole_diameter,height:l.hole_diameter,connectedTo:[]}):(l.hole_shape==="round"||l.hole_shape==="circle")&&s.push({type:"rect",layers:ZR,center:{x:l.x,y:l.y},width:l.hole_diameter,height:l.hole_diameter,connectedTo:[]});else if(l.type==="pcb_plated_hole")l.shape==="circle"?s.push({type:"oval",layers:ZR,center:{x:l.x,y:l.y},width:l.outer_diameter,height:l.outer_diameter,connectedTo:a([l.pcb_plated_hole_id])}):(l.shape==="oval"||l.shape==="pill")&&s.push({type:"oval",layers:ZR,center:{x:l.x,y:l.y},width:l.outer_width,height:l.outer_height,connectedTo:a([l.pcb_plated_hole_id])});else if(l.type==="pcb_trace"){let p=v_e(l.route.map(x=>({x:x.x,y:x.y,layer:"layer"in x?x.layer:x.from_layer})),l.source_trace_id);s.push(...p)}else l.type==="pcb_via"&&s.push({type:"rect",layers:l.layers,center:{x:l.x,y:l.y},connectedTo:[],width:l.outer_diameter,height:l.outer_diameter});return s};function D_e(n){let{pcbConnMap:e,goalElementId:a}=n;if(!a.startsWith("pcb_port_"))throw new Error(`Currently alternative goal boxes must have a goal id with prefix "pcb_port_" (got ${a})`);let s=e.getAllTracesConnectedToPort(a);return S_e(s).map(l=>({...l,connectedTo:[a]}))}var B_e=n=>{let{connection:e,pcbConnMap:a}=n;if(e.pointsToConnect.length!==2)throw new Error(`Connection must have exactly 2 points for alternative goal boxes (got ${e.pointsToConnect.length})`);let[s,l]=e.pointsToConnect;if(!s.pcb_port_id||!l.pcb_port_id)throw new Error(`Connection points must have pcb_port_id for alternative goal box calculation (got ${s.pcb_port_id} and ${l.pcb_port_id})`);let p=D_e({goalElementId:s.pcb_port_id,pcbConnMap:a}).concat([{center:s,width:.01,height:.01,connectedTo:[s.pcb_port_id],layers:[s.layer],type:"rect"}]),x=D_e({goalElementId:l.pcb_port_id,pcbConnMap:a}).concat([{center:l,width:.01,height:.01,connectedTo:[l.pcb_port_id],layers:[l.layer],type:"rect"}]);if(p.length<=1&&x.length<=1)return{...e,startPoint:s,endPoint:l,goalBoxes:[]};let f=Nb(p,x),m,D,b;return p.length>=x.length?(m={...l,...f.pointB},D={...s,...f.pointA},b=p):(m={...s,...f.pointA},D={...l,...f.pointB},b=x),{startPoint:m,endPoint:D,goalBoxes:b,name:e.name,pointsToConnect:[m,D]}},QIt=(n,e={})=>{let a={minTraceWidth:.1};a.layerCount=e.layerCount??1,a.obstacles=S_e(n,e.connMap),a.connections=[];for(let l of n)if(l.type==="source_trace"){let p={name:l.source_trace_id,pointsToConnect:l.connected_source_port_ids.map(x=>{let f=a_e(n).pcb_port.getWhere({source_port_id:x});if(!f)throw new Error(`Could not find pcb_port for source_port_id "${x}"`);return{x:f.x,y:f.y,layer:f.layers?.[0]??"top",pcb_port_id:f.pcb_port_id}})};if(e.optimizeWithGoalBoxes){let x=new JR(n);p=B_e({connection:p,pcbConnMap:x})}a.connections.push(p),ejt(a.obstacles,p.pointsToConnect,p.name)}let s={minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0};for(let l of a.obstacles)s.minX=Math.min(s.minX,l.center.x-l.width/2),s.maxX=Math.max(s.maxX,l.center.x+l.width/2),s.minY=Math.min(s.minY,l.center.y-l.height/2),s.maxY=Math.max(s.maxY,l.center.y+l.height/2);for(let l of a.connections)for(let p of l.pointsToConnect)s.minX=Math.min(s.minX,p.x),s.maxX=Math.max(s.maxX,p.x),s.minY=Math.min(s.minY,p.y),s.maxY=Math.max(s.maxY,p.y);return a.bounds=s,a},ejt=(n,e,a)=>{for(let s of e)for(let l of n)tjt(s,l)&&l.connectedTo.push(a)};function tjt(n,e){let a=e.width/2,s=e.height/2;if(e.type==="rect")return n.x>=e.center.x-a&&n.x<=e.center.x+a&&n.y>=e.center.y-s&&n.y<=e.center.y+s;if(e.type==="oval"){let l=(n.x-e.center.x)/a,p=(n.y-e.center.y)/s;return l*l+p*p<=1}return!1}function y_e(n,e){let a=e.x>n.x?1:e.x<n.x?-1:0,s=e.y>n.y?1:e.y<n.y?-1:0,l=e.l>n.l?1:e.l<n.l?-1:0;return{dx:a,dy:s,dl:l}}var mY={1:["top"],2:["top","bottom"],4:["top","inner1","inner2","bottom"]},rjt=n=>mY[n];function w_e(n,e){let s=mY[n].indexOf(e);if(s===-1)throw new Error(`Invalid layer for getLayerIndex (for layerCount === ${n}): "${e}"`);return s}function njt(n,e){let s=mY[n][e];if(!s)throw new Error(`Invalid index for indexToLayer (for layerCount === ${n}): "${e}"`);return s}var ajt=class extends C_e{constructor(e,a){super([]);q(this,"obstacles");q(this,"GRID_STEP",.1);q(this,"layerCount");this.layerCount=e;let s=rjt(e);this.obstacles=a.flatMap(l=>l.layers.filter(p=>s.includes(p)).map(p=>({...l,left:l.center.x-l.width/2,right:l.center.x+l.width/2,top:l.center.y+l.height/2,bottom:l.center.y-l.height/2,l:w_e(e,p)})))}getObstacleAt(e,a,s,l){l??(l=this.GRID_STEP);for(let p of this.obstacles){if(p.l!==s)continue;let x=p.width/2+l,f=p.height/2+l;if(e>=p.center.x-x&&e<=p.center.x+x&&a>=p.center.y-f&&a<=p.center.y+f)return p}return null}isObstacleAt(e,a,s,l){return this.getObstacleAt(e,a,s,l)!==null}getDirectionDistancesToNearestObstacle3d(e,a,s){let{GRID_STEP:l}=this,p={left:1/0,top:1/0,bottom:1/0,right:1/0};for(let x of this.obstacles)if(x.l===s&&x.type==="rect"){let f=x.center.x-x.width/2-l,m=x.center.x+x.width/2+l,D=x.center.y+x.height/2+l,b=x.center.y-x.height/2-l;a>=b&&a<=D&&e>f&&(p.left=Math.min(p.left,e-m)),a>=b&&a<=D&&e<m&&(p.right=Math.min(p.right,f-e)),e>=f&&e<=m&&a<D&&(p.top=Math.min(p.top,b-a)),e>=f&&e<=m&&a>b&&(p.bottom=Math.min(p.bottom,a-D))}return p}getOrthoDirectionCollisionInfo(e,a,{margin:s=0}={}){let{x:l,y:p,l:x}=e,{dx:f,dy:m,dl:D}=a,b=1/0,E=null;if(D!==0){let A=x+D;return this.isObstacleAt(l,p,A,s)?(b=1,E=this.getObstacleAt(l,p,A,s)):b=1,{dx:f,dy:m,dl:D,wallDistance:b,obstacle:E}}else{for(let A of this.obstacles){if(A.l!==x)continue;let B=A.left-s,w=A.right+s,P=A.top+s,k=A.bottom-s,O=null;f===1&&m===0?p>k&&p<P&&l<A.left&&(O=A.left-l):f===-1&&m===0?p>k&&p<P&&l>A.right&&(O=l-A.right):f===0&&m===1?l>B&&l<w&&p<A.bottom&&(O=A.bottom-p):f===0&&m===-1&&l>B&&l<w&&p>A.top&&(O=p-A.top),O!==null&&O<b&&(b=O,E=A)}return{dx:f,dy:m,dl:0,wallDistance:b,obstacle:E}}}getObstaclesOverlappingRegion(e){let a=[];for(let s of this.obstacles){if(s.l!==e.l)continue;let{left:l,right:p,top:x,bottom:f}=s;l<=e.maxX&&p>=e.minX&&x>=e.minY&&f<=e.maxY&&a.push(s)}return a}},QR=class extends A_e{constructor(e){super(e);q(this,"MAX_ITERATIONS",500);q(this,"VIA_COST",4);q(this,"VIA_DIAMETER",.5);q(this,"allowLayerChange",!0);q(this,"layerCount");q(this,"obstacles");q(this,"optimizeWithGoalBoxes");q(this,"connMap");q(this,"pcbConnMap");q(this,"GOAL_RUSH_FACTOR",1.1);q(this,"defaultGoalViaMargin",.5);q(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 JR,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?B_e({connection:e,pcbConnMap:this.pcbConnMap}):e}postprocessConnectionSolveResult(e,a){if(!a.solved)return a;if(this.optimizeWithGoalBoxes){let s=a.route.map(l=>({x:l.x,y:l.y,route_type:"wire",layer:l.layer,width:this.input.minTraceWidth}));s[0].start_pcb_port_id=e.pointsToConnect[0].pcb_port_id,s[s.length-1].end_pcb_port_id=e.pointsToConnect[1].pcb_port_id,this.pcbConnMap.addTrace({type:"pcb_trace",pcb_trace_id:`postprocess_trace_${f_e(8)}`,route:s})}return a}createObstacleList({dominantLayer:e,connection:a,obstaclesFromTraces:s}){let l=this.connMap?this.connMap.getNetConnectedToId(a.name):a.name;if(!l)throw new Error(`The connection.name "${a.name}" wasn't present in the full connectivity map`);return new ajt(this.layerCount,this.allObstacles.filter(p=>!p.connectedTo.includes(l)).concat(s??[]))}computeG(e,a){let s=e.g+n1(e,a)*(e.travelMarginCostFactor??1)+(a.enterMarginCost??0);return(a.l??e.l!==-1??-1)&&(s+=this.VIA_COST),s}computeH(e){let a=Math.abs(e.x-this.goalPoint.x),s=Math.abs(e.y-this.goalPoint.y),l=Math.abs(e.l-this.goalPoint.l);return(a+s)**this.GOAL_RUSH_FACTOR+l*this.VIA_COST}getStartNode(e){return{...super.getStartNode(e),l:this.layerToIndex(e.pointsToConnect[0].layer)}}layerToIndex(e){return w_e(this.layerCount,e)}indexToLayer(e){return njt(this.layerCount,e)}getNodeName(e){return`${F_e(e,this.GRID_STEP)}-${e.l??0}`}hasSpaceForVia(e,a){return e.every(s=>this.obstacles.getObstaclesOverlappingRegion({minX:a.x-this.VIA_DIAMETER/2-this.OBSTACLE_MARGIN,minY:a.y-this.VIA_DIAMETER/2-this.OBSTACLE_MARGIN,maxX:a.x+this.VIA_DIAMETER/2+this.OBSTACLE_MARGIN,maxY:a.y+this.VIA_DIAMETER/2+this.OBSTACLE_MARGIN,l:s}).length===0)}getNeighborsSurroundingGoal(e){let a=this.obstacles,s=this.goalPoint,l=[],p=[{dx:1,dy:0,dl:0},{dx:-1,dy:0,dl:0},{dx:0,dy:1,dl:0},{dx:0,dy:-1,dl:0}],x=this.VIA_DIAMETER+this.OBSTACLE_MARGIN+this.defaultGoalViaMargin;for(let f of p){let m={x:e.x+f.dx*x,y:e.y+f.dy*x,l:e.l+f.dl,obstacleHit:null};this.hasSpaceForVia([e.l,s.l],m)&&l.push(m)}return l}getNeighbors(e){let a=this.obstacles,s=this.goalPoint,l=n1(e,s);if(l<=this.OBSTACLE_MARGIN)return this.getNeighborsSurroundingGoal(e);let p;e.parent?p=y_e(e.parent,e):p=y_e(e,s);let x=[{dx:0,dy:1,dl:0},{dx:1,dy:0,dl:0},{dx:0,dy:-1,dl:0},{dx:-1,dy:0,dl:0}],f=l>this.VIA_DIAMETER+this.OBSTACLE_MARGIN,m=n1(e,this.startNode)>this.VIA_DIAMETER+this.OBSTACLE_MARGIN;this.allowLayerChange&&f&&m&&(e.l<this.layerCount-1&&x.push({dx:0,dy:0,dl:1}),e.l>0&&x.push({dx:0,dy:0,dl:-1}));let D=x.filter(E=>E.dx===p.dx*-1&&E.dy===p.dy*-1&&E.dl===p.dl*-1?!1:!(E.dx===p.dx&&E.dy===p.dy&&E.dl===p.dl&&e.parent?.obstacleHit)).map(E=>a.getOrthoDirectionCollisionInfo(e,E,{margin:this.OBSTACLE_MARGIN})).filter(E=>!(E.wallDistance<this.OBSTACLE_MARGIN)),b=[];for(let E of D){let A=E.dx===0&&E.dy===0&&E.dl===1,B=E.dx===0&&E.dy===0&&E.dl===-1;if((A||B)&&![e.l,e.l+E.dl].every($=>a.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:$}).length===0))continue;if(A){e.l<this.layerCount-1&&b.push({...E,travelDistance:0,enterMarginCost:0,travelMarginCostFactor:1});continue}if(B){e.l>0&&b.push({...E,travelDistance:0,enterMarginCost:0,travelMarginCostFactor:1});continue}let w=null;e?.obstacleHit&&(w=hY({node:e,travelDir:E,wallDir:{...p,wallDistance:this.OBSTACLE_MARGIN},obstacle:e.obstacleHit,obstacles:a,OBSTACLE_MARGIN:this.OBSTACLE_MARGIN,SHOULD_DETECT_CONJOINED_OBSTACLES:!0}));let P=b_e(e,s,E),k=(E.dx===0||Math.sign(s.x-e.x)===E.dx)&&(E.dy===0||Math.sign(s.y-e.y)===E.dy);if(P<E.wallDistance&&P>0&&k){let O=e.l===s.l,$=0;!O&&Math.abs(P-l)<this.GRID_STEP&&($=this.VIA_DIAMETER+this.OBSTACLE_MARGIN+this.defaultGoalViaMargin),b.push({...E,travelDistance:P-$,enterMarginCost:0,travelMarginCostFactor:1})}else if(w!==null&&w<E.wallDistance){for(let{margin:O,enterCost:$,travelCostFactor:ee}of this.marginsWithCosts)w-this.OBSTACLE_MARGIN+O*2<E.wallDistance&&b.push({...E,travelDistance:w-this.OBSTACLE_MARGIN+O,enterMarginCost:$,travelMarginCostFactor:ee});if(E.wallDistance===1/0)b.push({...E,travelDistance:P,enterMarginCost:0,travelMarginCostFactor:1});else if(E.wallDistance>this.largestMargin)for(let{margin:O,enterCost:$,travelCostFactor:ee}of this.marginsWithCosts)E.wallDistance>this.largestMargin+O&&b.push({...E,travelDistance:E.wallDistance-O,enterMarginCost:$,travelMarginCostFactor:ee})}else if(E.wallDistance!==1/0)for(let{margin:O,enterCost:$,travelCostFactor:ee}of this.marginsWithCosts)E.wallDistance>O&&b.push({...E,travelDistance:E.wallDistance-O,enterMarginCost:$,travelMarginCostFactor:ee})}return b.map(E=>({x:e.x+E.dx*E.travelDistance,y:e.y+E.dy*E.travelDistance,l:e.l+E.dl,obstacleHit:E.obstacle,travelMarginCostFactor:E.travelMarginCostFactor,enterMarginCost:E.enterMarginCost}))}};function T_e(n){let e=QIt(n),a=new JIt({input:e});return{solution:a.solveAndMapToTraces(),debugSolutions:a.debugSolutions,debugMessage:a.debugMessage}}Xe();Xe();Yt();Xe();Xe();Yt();Xe();Xe();Xe();Xe();Xe();Yt();Xe();Xe();Yt();Xe();Yt();Yt();Xe();Xe();Xe();Xe();Xe();Xe();Xe();Xe();Xe();Xe();Xe();Yt();Xe();Yt();Xe();Yt();Yt();Yt();Xe();Yt();Xe();Xe();Xe();Yt();Xe();Xe();Yt();Xe();Yt();Xe();Yt();Xe();Yt();Xe();Yt();Xe();Yt();Xe();Yt();Xe();Xe();Xe();Xe();Xe();Xe();Xe();Xe();Yt();Xe();Yt();Xe();Xe();Yt();Xe();Yt();Xe();Xe();Xe();Yt();Xe();Yt();Xe();Xe();Yt();Xe();Xe();Xe();Xe();Yt();Xe();Yt();Xe();Yt();Xe();Yt();Xe();Yt();Xe();Xe();Yt();Xe();Xe();Yt();Yt();Xe();Yt();Xe();Xe();Yt();Xe();Yt();Xe();Xe();Yt();Xe();Yt();Xe();Yt();Xe();Yt();Xe();Yt();Xe();Yt();Xe();Yt();Yt();Xe();Yt();Xe();Yt();Xe();Xe();Xe();var lr=n=>{};lr("extra props b");lr("missing props b");lr(!0);lr("property a has mismatched types");var sjt=C.enum(["up","down","left","right"]),$ar=C.enum(["top-to-bottom","left-to-right","bottom-to-top","right-to-left"]);lr(!0);lr(!0);var U0=C.array(C.string().or(C.number()));lr(!0);var P_e=C.object({x:Le,y:Le,z:Le}),ijt=C.object({x:C.union([C.number(),C.string()]),y:C.union([C.number(),C.string()]),z:C.union([C.number(),C.string()])}),a1=C.object({rotationOffset:C.number().or(ijt).optional(),positionOffset:P_e.optional(),size:P_e.optional()});lr(!0);var ojt=a1.extend({stlUrl:C.string()}),ujt=a1.extend({objUrl:C.string(),mtlUrl:C.string().optional()}),cjt=a1.extend({gltfUrl:C.string()}),ljt=a1.extend({glbUrl:C.string()}),djt=a1.extend({stepUrl:C.string()}),pjt=a1.extend({wrlUrl:C.string()}),xjt=a1.extend({jscad:C.record(C.any())}),M_e=C.union([C.null(),C.string(),ojt,ujt,cjt,ljt,djt,pjt,xjt]);lr(!0);var fjt=C.custom(n=>!0),hjt=C.custom(n=>!0),Ea=C.object({pcbX:Le.optional(),pcbY:Le.optional(),pcbRotation:Ba.optional(),pcbPositionAnchor:C.string().optional(),layer:hn.optional(),pcbMarginTop:Le.optional(),pcbMarginRight:Le.optional(),pcbMarginBottom:Le.optional(),pcbMarginLeft:Le.optional(),pcbMarginX:Le.optional(),pcbMarginY:Le.optional(),pcbRelative:C.boolean().optional(),relative:C.boolean().optional()});lr(!0);var r5=C.object({pcbX:Le.optional(),pcbY:Le.optional(),pcbRotation:Ba.optional(),pcbPositionAnchor:C.string().optional(),pcbMarginTop:Le.optional(),pcbMarginRight:Le.optional(),pcbMarginBottom:Le.optional(),pcbMarginLeft:Le.optional(),pcbMarginX:Le.optional(),pcbMarginY:Le.optional(),schMarginTop:Le.optional(),schMarginRight:Le.optional(),schMarginBottom:Le.optional(),schMarginLeft:Le.optional(),schMarginX:Le.optional(),schMarginY:Le.optional(),schX:Le.optional(),schY:Le.optional(),schRotation:Ba.optional(),layer:hn.optional(),footprint:fjt.optional(),symbol:hjt.optional(),relative:C.boolean().optional(),schRelative:C.boolean().optional(),pcbRelative:C.boolean().optional()});lr(!0);var mjt=C.object({supplierPartNumbers:C.record(jm,C.array(C.string())).optional()});lr(!0);var gjt=C.object({providesPower:C.boolean().optional(),requiresPower:C.boolean().optional(),providesGround:C.boolean().optional(),requiresGround:C.boolean().optional(),providesVoltage:C.union([C.string(),C.number()]).optional(),requiresVoltage:C.union([C.string(),C.number()]).optional(),doNotConnect:C.boolean().optional()});lr(!0);var ms=r5.merge(mjt).extend({key:C.any().optional(),name:C.string(),cadModel:M_e.optional(),children:C.any().optional(),symbolName:C.string().optional(),doNotPlace:C.boolean().optional(),pinAttributes:C.record(C.string(),gjt).optional()});lr(!0);var DY=["pin1","left","pin2","right"],n5=["pin1","left","anode","pos","pin2","right","cathode","neg"],War=Le.or(C.enum(["2x","3x","4x"])),kp=C.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)");lr(!0);var e5=C.object({pins:C.array(C.union([C.number(),C.string()])),direction:C.union([C.literal("top-to-bottom"),C.literal("left-to-right"),C.literal("bottom-to-top"),C.literal("right-to-left")])}),Ob=C.object({leftSize:C.number().optional().describe("@deprecated, use leftPinCount"),topSize:C.number().optional().describe("@deprecated, use topPinCount"),rightSize:C.number().optional().describe("@deprecated, use rightPinCount"),bottomSize:C.number().optional().describe("@deprecated, use bottomPinCount"),leftPinCount:C.number().optional(),rightPinCount:C.number().optional(),topPinCount:C.number().optional(),bottomPinCount:C.number().optional(),leftSide:e5.optional(),rightSide:e5.optional(),topSide:e5.optional(),bottomSide:e5.optional()}),O_e=Ob;lr(!0);var a5=C.record(C.object({marginLeft:Le.optional(),marginRight:Le.optional(),marginTop:Le.optional(),marginBottom:Le.optional(),leftMargin:Le.optional(),rightMargin:Le.optional(),topMargin:Le.optional(),bottomMargin:Le.optional()}));lr(!0);var Zu=C.string().regex(/^[A-Za-z0-9_]+$/),rg=C.object({x:Le,y:Le}),Lb=C.object({edit_event_id:C.string(),in_progress:C.boolean().optional(),created_at:C.number()});lr(!0);var Djt=Lb.extend({pcb_edit_event_type:C.literal("edit_component_location").describe("deprecated"),edit_event_type:C.literal("edit_pcb_component_location"),pcb_component_id:C.string(),original_center:C.object({x:C.number(),y:C.number()}),new_center:C.object({x:C.number(),y:C.number()})});lr(!0);var yjt=Lb.extend({pcb_edit_event_type:C.literal("edit_trace_hint").describe("deprecated"),edit_event_type:C.literal("edit_pcb_trace_hint").optional(),pcb_port_id:C.string(),pcb_trace_hint_id:C.string().optional(),route:C.array(C.object({x:C.number(),y:C.number(),via:C.boolean().optional()}))});lr(!0);var bjt=Lb.extend({edit_event_type:C.literal("edit_schematic_component_location"),schematic_component_id:C.string(),original_center:C.object({x:C.number(),y:C.number()}),new_center:C.object({x:C.number(),y:C.number()})});lr(!0);var xsr=Lb.extend({edit_event_type:C.literal("edit_pcb_group_location"),pcb_group_id:C.string(),original_center:C.object({x:C.number(),y:C.number()}),new_center:C.object({x:C.number(),y:C.number()})});lr(!0);var hsr=Lb.extend({edit_event_type:C.literal("edit_schematic_group_location"),schematic_group_id:C.string(),original_center:C.object({x:C.number(),y:C.number()}),new_center:C.object({x:C.number(),y:C.number()})});lr(!0);var gsr=C.union([Djt,yjt,bjt]);lr(!0);var Fjt=C.object({selector:C.string(),relative_to:C.string().optional().default("group_center").describe("Can be a selector or 'group_center'"),center:mn});lr(!0);var Ejt=C.object({pcb_port_selector:C.string(),offsets:C.array(bo)});lr(!0);var vjt=C.object({selector:C.string(),relative_to:C.string().optional().default("group_center").describe("Can be a selector or 'group_center'"),center:mn});lr(!0);var Cjt=C.object({pcb_placements:C.array(Fjt).optional(),manual_trace_hints:C.array(Ejt).optional(),schematic_placements:C.array(vjt).optional()});lr(!0);var Mb=C.object({layoutMode:C.enum(["grid","flex","match-adapt","relative","none"]).optional(),position:C.enum(["absolute","relative"]).optional(),grid:C.boolean().optional(),gridCols:C.number().or(C.string()).optional(),gridRows:C.number().or(C.string()).optional(),gridTemplateRows:C.string().optional(),gridTemplateColumns:C.string().optional(),gridTemplate:C.string().optional(),gridGap:C.number().or(C.string()).optional(),gridRowGap:C.number().or(C.string()).optional(),gridColumnGap:C.number().or(C.string()).optional(),flex:C.boolean().or(C.string()).optional(),flexDirection:C.enum(["row","column"]).optional(),alignItems:C.enum(["start","center","end","stretch"]).optional(),justifyContent:C.enum(["start","center","end","stretch","space-between","space-around","space-evenly"]).optional(),flexRow:C.boolean().optional(),flexColumn:C.boolean().optional(),gap:C.number().or(C.string()).optional(),pack:C.boolean().optional().describe("Pack the contents of this group using a packing strategy"),packOrderStrategy:C.enum(["largest_to_smallest","first_to_last","highest_to_lowest_pin_count"]).optional(),packPlacementStrategy:C.enum(["shortest_connection_along_outline"]).optional(),padding:xe.optional(),paddingLeft:xe.optional(),paddingRight:xe.optional(),paddingTop:xe.optional(),paddingBottom:xe.optional(),paddingX:xe.optional(),paddingY:xe.optional(),width:xe.optional(),height:xe.optional(),matchAdapt:C.boolean().optional(),matchAdaptTemplate:C.any().optional()});lr(!0);var I_e=C.object({strokeWidth:xe.optional(),dashed:C.boolean().optional(),solid:C.boolean().optional()}),_jt=C.object({serverUrl:C.string().optional(),inputFormat:C.enum(["simplified","circuit-json"]).optional(),serverMode:C.enum(["job","solve-endpoint"]).optional(),serverCacheEnabled:C.boolean().optional(),cache:C.custom(n=>!0).optional(),traceClearance:xe.optional(),groupMode:C.enum(["sequential-trace","subcircuit"]).optional(),algorithmFn:C.custom(n=>typeof n=="function"||n===void 0).optional(),preset:C.enum(["sequential-trace","subcircuit","auto","auto-local","auto-cloud"]).optional(),local:C.boolean().optional()}),L_e=C.union([_jt,C.literal("sequential-trace"),C.literal("subcircuit"),C.literal("auto"),C.literal("auto-local"),C.literal("auto-cloud")]),$_e=r5.extend({name:C.string().optional(),children:C.any().optional(),schTitle:C.string().optional(),key:C.any().optional(),...Mb.shape,grid:Mb.shape.grid.describe("@deprecated use pcbGrid"),flex:Mb.shape.flex.describe("@deprecated use pcbFlex"),pcbGrid:C.boolean().optional(),pcbGridCols:C.number().or(C.string()).optional(),pcbGridRows:C.number().or(C.string()).optional(),pcbGridTemplateRows:C.string().optional(),pcbGridTemplateColumns:C.string().optional(),pcbGridTemplate:C.string().optional(),pcbGridGap:C.number().or(C.string()).optional(),pcbGridRowGap:C.number().or(C.string()).optional(),pcbGridColumnGap:C.number().or(C.string()).optional(),pcbFlex:C.boolean().or(C.string()).optional(),pcbFlexGap:C.number().or(C.string()).optional(),pcbFlexDirection:C.enum(["row","column"]).optional(),pcbAlignItems:C.enum(["start","center","end","stretch"]).optional(),pcbJustifyContent:C.enum(["start","center","end","stretch","space-between","space-around","space-evenly"]).optional(),pcbFlexRow:C.boolean().optional(),pcbFlexColumn:C.boolean().optional(),pcbGap:C.number().or(C.string()).optional(),pcbPack:C.boolean().optional(),schGrid:C.boolean().optional(),schGridCols:C.number().or(C.string()).optional(),schGridRows:C.number().or(C.string()).optional(),schGridTemplateRows:C.string().optional(),schGridTemplateColumns:C.string().optional(),schGridTemplate:C.string().optional(),schGridGap:C.number().or(C.string()).optional(),schGridRowGap:C.number().or(C.string()).optional(),schGridColumnGap:C.number().or(C.string()).optional(),schFlex:C.boolean().or(C.string()).optional(),schFlexGap:C.number().or(C.string()).optional(),schFlexDirection:C.enum(["row","column"]).optional(),schAlignItems:C.enum(["start","center","end","stretch"]).optional(),schJustifyContent:C.enum(["start","center","end","stretch","space-between","space-around","space-evenly"]).optional(),schFlexRow:C.boolean().optional(),schFlexColumn:C.boolean().optional(),schGap:C.number().or(C.string()).optional(),schPack:C.boolean().optional(),schMatchAdapt:C.boolean().optional(),pcbWidth:xe.optional(),pcbHeight:xe.optional(),schWidth:xe.optional(),schHeight:xe.optional(),pcbLayout:Mb.optional(),schLayout:Mb.optional(),cellBorder:I_e.nullable().optional(),border:I_e.nullable().optional(),schPadding:xe.optional(),schPaddingLeft:xe.optional(),schPaddingRight:xe.optional(),schPaddingTop:xe.optional(),schPaddingBottom:xe.optional(),pcbPadding:xe.optional(),pcbPaddingLeft:xe.optional(),pcbPaddingRight:xe.optional(),pcbPaddingTop:xe.optional(),pcbPaddingBottom:xe.optional()}),z_e=C.custom(n=>"findPart"in n),yY=$_e.extend({manualEdits:Cjt.optional(),schAutoLayoutEnabled:C.boolean().optional(),schTraceAutoLabelEnabled:C.boolean().optional(),schMaxTraceDistance:Le.optional(),routingDisabled:C.boolean().optional(),defaultTraceWidth:xe.optional(),minTraceWidth:xe.optional(),partsEngine:z_e.optional(),pcbRouteCache:C.custom(n=>!0).optional(),autorouter:L_e.optional(),square:C.boolean().optional(),emptyArea:C.string().optional(),filledArea:C.string().optional(),width:Le.optional(),height:Le.optional(),outline:C.array(rg).optional(),outlineOffsetX:Le.optional(),outlineOffsetY:Le.optional()}),Ajt=yY.extend({subcircuit:C.literal(!0)}),q_e=C.discriminatedUnion("subcircuit",[$_e.extend({subcircuit:C.literal(!1).optional()}),Ajt]);lr(!0);lr(!0);lr(!0);var bY=yY.extend({material:C.enum(["fr4","fr1"]).default("fr4"),layers:C.union([C.literal(2),C.literal(4)]).default(2),borderRadius:Le.optional()});lr(!0);var Asr=yY.extend({padding:Le.optional(),paddingLeft:Le.optional(),paddingRight:Le.optional(),paddingTop:Le.optional(),paddingBottom:Le.optional()});lr(!0);var Rjt=C.string().or(C.array(C.string()).readonly()).or(C.array(C.string())),Sjt=C.custom().pipe(C.record(C.string(),Rjt)),Bjt=C.record(Zu,Zu.or(C.array(Zu).readonly()).or(C.array(Zu)));lr(!0);var wjt=C.object({manufacturerPartNumber:C.string().optional(),supplierPartNumber:C.record(jm,C.array(C.string())).optional()}),ng=ms.extend({manufacturerPartNumber:C.string().optional(),pinLabels:Bjt.optional(),showPinAliases:C.boolean().optional(),pcbPinLabels:C.record(C.string(),C.string()).optional(),internallyConnectedPins:C.array(C.array(C.union([C.string(),C.number()]))).optional(),externallyConnectedPins:C.array(C.array(C.string())).optional(),schPinArrangement:Ob.optional(),schPortArrangement:Ob.optional(),pinCompatibleVariants:C.array(wjt).optional(),schPinStyle:a5.optional(),schPinSpacing:Le.optional(),schWidth:Le.optional(),schHeight:Le.optional(),noSchematicRepresentation:C.boolean().optional(),connections:Sjt.optional()});lr(!0);var U_e=ng;lr(!0);var FY=C.string().or(C.array(C.string()).readonly()).or(C.array(C.string())),s1=n=>C.record(C.enum(n),FY),EY=ms.extend({manufacturerPartNumber:C.string().optional(),pinLabels:C.record(C.number().or(Zu),Zu.or(C.array(Zu))).optional(),schPinStyle:a5.optional(),schPinSpacing:Le.optional(),schWidth:Le.optional(),schHeight:Le.optional(),schDirection:C.enum(["left","right"]).optional(),schPinArrangement:O_e.optional(),schPortArrangement:Ob.optional(),pcbPinLabels:C.record(C.string(),C.string()).optional(),pinCount:C.union([C.literal(2),C.literal(3)]).optional(),internallyConnectedPins:C.array(C.array(C.union([C.string(),C.number()]))).optional(),connections:C.custom().pipe(C.record(C.string(),FY)).optional()});lr(!0);var V_e=EY.extend({bridgedPins:C.array(C.array(C.string())).optional(),bridged:C.boolean().optional()});lr(!0);var ksr=ms.extend({manufacturerPartNumber:C.string().optional(),pinLabels:C.record(C.number().or(Zu),Zu.or(C.array(Zu))).optional(),schPinStyle:a5.optional(),schPinSpacing:Le.optional(),schWidth:Le.optional(),schHeight:Le.optional(),schDirection:C.enum(["left","right"]).optional(),schPortArrangement:Ob.optional(),internallyConnectedPins:C.array(C.array(C.union([C.string(),C.number()]))).optional(),standard:C.enum(["usb_c","m2"]).optional()});lr(!0);var G_e=ms.extend({currentRating:C.union([C.number(),C.string()]),voltageRating:C.union([C.number(),C.string()]).optional(),schShowRatings:C.boolean().optional(),schOrientation:kp.optional(),connections:C.record(C.string(),C.union([C.string(),C.array(C.string()).readonly(),C.array(C.string())])).optional()}),t5=C.custom().transform(n=>{if(n!==void 0)return Le.parse(n)}),X_e=C.discriminatedUnion("shape",[Ea.omit({pcbRotation:!0,layer:!0}).extend({name:C.string().optional(),connectsTo:C.string().or(C.array(C.string())).optional(),shape:C.literal("circle"),holeDiameter:Le,outerDiameter:Le,portHints:U0.optional()}),Ea.omit({pcbRotation:!0,layer:!0}).extend({name:C.string().optional(),connectsTo:C.string().or(C.array(C.string())).optional(),shape:C.literal("oval"),outerWidth:Le,outerHeight:Le,holeWidth:t5,holeHeight:t5,innerWidth:Le.optional().describe("DEPRECATED use holeWidth"),innerHeight:Le.optional().describe("DEPRECATED use holeHeight"),portHints:U0.optional()}),Ea.omit({layer:!0}).extend({name:C.string().optional(),connectsTo:C.string().or(C.array(C.string())).optional(),shape:C.literal("pill"),rectPad:C.boolean().optional(),outerWidth:Le,outerHeight:Le,holeWidth:t5,holeHeight:t5,innerWidth:Le.optional().describe("DEPRECATED use holeWidth"),innerHeight:Le.optional().describe("DEPRECATED use holeHeight"),portHints:U0.optional()}),Ea.omit({pcbRotation:!0,layer:!0}).extend({name:C.string().optional(),connectsTo:C.string().or(C.array(C.string())).optional(),shape:C.literal("circular_hole_with_rect_pad"),holeDiameter:Le,rectPadWidth:Le,rectPadHeight:Le,holeShape:C.literal("circle").optional(),padShape:C.literal("rect").optional(),portHints:U0.optional()}),Ea.omit({pcbRotation:!0,layer:!0}).extend({name:C.string().optional(),connectsTo:C.string().or(C.array(C.string())).optional(),shape:C.literal("pill_hole_with_rect_pad"),holeShape:C.literal("pill"),padShape:C.literal("rect"),holeWidth:Le,holeHeight:Le,rectPadWidth:Le,rectPadHeight:Le,portHints:U0.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));lr(!0);var Tjt=["pin1","pin2","pos","neg"],Y_e=ms.extend({resistance:Rp,pullupFor:C.string().optional(),pullupTo:C.string().optional(),pulldownFor:C.string().optional(),pulldownTo:C.string().optional(),schOrientation:kp.optional(),connections:s1(Tjt).optional()}),H_e=DY;lr(!0);var W_e=ms.extend({maxResistance:Rp,pinVariant:C.enum(["two_pin","three_pin"]).optional()});lr(!0);var Pjt=DY,K_e=ms.extend({frequency:Nc,loadCapacitance:Ul,manufacturerPartNumber:C.string().optional(),mpn:C.string().optional(),pinVariant:C.enum(["two_pin","four_pin"]).optional(),schOrientation:kp.optional(),connections:s1(Pjt).optional()});lr(!0);var J_e=ms.extend({frequency:Nc,loadCapacitance:Ul,pinVariant:C.enum(["no_ground","ground_pin","two_ground_pins"]).optional()});lr(!0);var Wsr=bY.extend({leftPinCount:C.number().optional(),rightPinCount:C.number().optional(),topPinCount:C.number().optional(),bottomPinCount:C.number().optional(),leftPins:C.array(C.string()).optional(),rightPins:C.array(C.string()).optional(),topPins:C.array(C.string()).optional(),bottomPins:C.array(C.string()).optional(),pinPitch:Le.optional(),innerHoles:C.boolean().optional()});lr(!0);var Ijt=["pin1","pin2","pos","neg","anode","cathode"],Z_e=ms.extend({capacitance:Ul,maxVoltageRating:Us.optional(),schShowRatings:C.boolean().optional().default(!1),polarized:C.boolean().optional().default(!1),decouplingFor:C.string().optional(),decouplingTo:C.string().optional(),bypassFor:C.string().optional(),bypassTo:C.string().optional(),maxDecouplingTraceLength:C.number().optional(),schOrientation:kp.optional(),connections:s1(Ijt).optional()}),Q_e=n5;lr(!0);var Qsr=C.object({name:C.string(),connectsTo:C.string().or(C.array(C.string())).optional()});lr(!0);var tir=C.object({name:C.string().optional(),pcbOnly:C.boolean().optional(),schOnly:C.boolean().optional()});lr(!0);var jjt=C.object({pcb:C.literal(!0).optional(),xDist:Le,left:C.string(),right:C.string(),edgeToEdge:C.literal(!0).optional(),centerToCenter:C.literal(!0).optional()});lr(!0);var kjt=C.object({pcb:C.literal(!0).optional(),yDist:Le,top:C.string(),bottom:C.string(),edgeToEdge:C.literal(!0).optional(),centerToCenter:C.literal(!0).optional()});lr(!0);var Njt=C.object({pcb:C.literal(!0).optional(),sameY:C.literal(!0).optional(),for:C.array(C.string())});lr(!0);var Mjt=C.object({pcb:C.literal(!0).optional(),sameX:C.literal(!0).optional(),for:C.array(C.string())});lr(!0);var eAe=C.union([jjt,kjt,Njt,Mjt]);lr(!0);var Ojt=Ea.omit({layer:!0,pcbRotation:!0}).extend({name:C.string().optional(),shape:C.literal("rect"),width:Le,height:Le});lr(!0);var Ljt=Ea.omit({layer:!0,pcbRotation:!0}).extend({name:C.string().optional(),shape:C.literal("circle"),radius:Le});lr(!0);var $jt=Ea.omit({layer:!0,pcbRotation:!0}).extend({name:C.string().optional(),shape:C.literal("polygon"),points:C.array(rg)});lr(!0);var tAe=C.discriminatedUnion("shape",[Ojt,Ljt,$jt]),zjt=Ea.omit({pcbRotation:!0}).extend({name:C.string().optional(),shape:C.literal("rect"),width:Le,height:Le,portHints:U0.optional()});lr(!0);var qjt=Ea.omit({pcbRotation:!0}).extend({name:C.string().optional(),shape:C.literal("rotated_rect"),width:Le,height:Le,ccwRotation:C.number(),portHints:U0.optional()});lr(!0);var Ujt=Ea.omit({pcbRotation:!0}).extend({name:C.string().optional(),shape:C.literal("circle"),radius:Le,portHints:U0.optional()});lr(!0);var Vjt=Ea.omit({pcbRotation:!0}).extend({name:C.string().optional(),shape:C.literal("pill"),width:Le,height:Le,radius:Le,portHints:U0.optional()});lr(!0);var Gjt=Ea.omit({pcbRotation:!0}).extend({name:C.string().optional(),shape:C.literal("polygon"),points:C.array(rg),portHints:U0.optional()});lr(!0);var rAe=C.discriminatedUnion("shape",[Ujt,zjt,qjt,Vjt,Gjt]);lr(!0);var Xjt=Ea.omit({pcbRotation:!0}).extend({shape:C.literal("rect"),width:Le,height:Le});lr(!0);var Yjt=Ea.omit({pcbRotation:!0}).extend({shape:C.literal("circle"),radius:Le});lr(!0);var iir=C.union([Yjt,Xjt]);lr(!0);var nAe=Ea.omit({pcbRotation:!0}).extend({name:C.string().optional(),diameter:Le.optional(),radius:Le.optional()}).transform(n=>({...n,diameter:n.diameter??2*n.radius,radius:n.radius??n.diameter/2}));lr(!0);var gY=C.union([C.string(),C.custom(n=>!!n.getPortSelector)]),j_e=C.object({key:C.string().optional(),thickness:Le.optional(),schematicRouteHints:C.array(rg).optional(),pcbRouteHints:C.array(bo).optional(),pcbPathRelativeTo:C.string().optional(),pcbPath:C.array(rg).optional(),schDisplayLabel:C.string().optional(),schStroke:C.string().optional(),maxLength:Le.optional()}),aAe=C.union([j_e.extend({path:C.array(gY)}),j_e.extend({from:gY,to:gY})]),sAe=C.object({originalLayer:hn.default("top").optional()});lr(!0);var xir=C.object({originalFacingDirection:C.enum(["up","down","left","right"]).default("right").optional()});lr(!0);var Hjt=C.number().or(C.string().endsWith("mAh")).transform(n=>{if(typeof n=="string"){let e=n.replace("mAh",""),a=Number.parseFloat(e);if(Number.isNaN(a))throw new Error("Invalid capacity");return a}return n}).describe("Battery capacity in mAh"),iAe=ms.extend({capacity:Hjt.optional(),voltage:Us.optional(),standard:C.enum(["AA","AAA","9V","CR2032","18650","C"]).optional(),schOrientation:kp.optional()});lr(!0);var Wjt=C.enum(["vertical","horizontal"]).describe("vertical means pins go 1->2 downward and horizontal means pins go 1->2 rightward");lr(!0);var oAe=ms.extend({pinCount:C.number(),pitch:Le.optional(),schFacingDirection:C.enum(["up","down","left","right"]).optional(),gender:C.enum(["male","female","unpopulated"]).optional().default("male"),showSilkscreenPinLabels:C.boolean().optional(),pcbPinLabels:C.record(C.string(),C.string()).optional(),doubleRow:C.boolean().optional(),rightAngle:C.boolean().optional(),pcbOrientation:Wjt.optional(),holeDiameter:Le.optional(),platedDiameter:Le.optional(),pinLabels:C.record(C.string(),Zu).or(C.array(Zu)).optional(),connections:C.custom().pipe(C.record(C.string(),FY)).optional(),facingDirection:C.enum(["left","right"]).optional(),schPinArrangement:O_e.optional(),schPinStyle:a5.optional(),schPinSpacing:Le.optional(),schWidth:Le.optional(),schHeight:Le.optional()});lr(!0);var Fir=C.object({net:C.string().optional(),connection:C.string().optional(),schX:Le.optional(),schY:Le.optional(),schRotation:Ba.optional(),anchorSide:C.enum(["left","top","right","bottom"]).optional()});lr(!0);var uAe=C.object({net:C.string().optional(),connection:C.string().optional(),connectsTo:C.string().or(C.array(C.string())).optional(),schX:Le.optional(),schY:Le.optional(),schRotation:Ba.optional(),anchorSide:C.enum(["left","top","right","bottom"]).optional()});lr(!0);var cAe=ng.extend({});lr(!0);lr(!0);var Kjt=["pin1","pin2","pin3","emitter","collector","base","gate","source","drain"],lAe=ms.extend({type:C.enum(["npn","pnp","bjt","jfet","mosfet","igbt"]),connections:s1(Kjt).optional()});lr(!0);var dAe=ms.extend({channelType:C.enum(["n","p"]),mosfetMode:C.enum(["enhancement","depletion"])});lr(!0);var Jjt=DY,pAe=ms.extend({inductance:jA,maxCurrentRating:C.union([C.string(),C.number()]).optional(),schOrientation:kp.optional(),connections:s1(Jjt).optional()});lr(!0);var Zjt=C.enum(["anode","cathode","pin1","pin2","pos","neg"]),Qjt=C.string().or(C.array(C.string()).readonly()).or(C.array(C.string())),ekt=C.record(Zjt,Qjt),tkt=C.enum(["standard","schottky","zener","avalanche","photo","tvs"]),xAe=ms.extend({connections:ekt.optional(),variant:tkt.optional().default("standard"),standard:C.boolean().optional(),schottky:C.boolean().optional(),zener:C.boolean().optional(),avalanche:C.boolean().optional(),photo:C.boolean().optional(),tvs:C.boolean().optional(),schOrientation:kp.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:C.ZodIssueCode.custom,message:"Exactly one diode variant must be enabled",path:[]}),C.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}),fAe=n5;lr(!0);var hAe=ms.extend({color:C.string().optional(),wavelength:C.string().optional(),schDisplayValue:C.string().optional(),schOrientation:kp.optional(),connections:s1(n5).optional(),laser:C.boolean().optional()}),mAe=n5,gAe=ms.extend({type:C.enum(["spst","spdt","dpst","dpdt"]).optional(),isNormallyClosed:C.boolean().optional().default(!1),spst:C.boolean().optional(),spdt:C.boolean().optional(),dpst:C.boolean().optional(),dpdt:C.boolean().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});lr(!0);var DAe=Ea.extend({text:C.string(),anchorAlignment:C.enum(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),font:C.enum(["tscircuit2024"]).optional(),fontSize:xe.optional(),color:C.string().optional()}),yAe=Ea.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({route:C.array(bo),strokeWidth:xe.optional(),color:C.string().optional()}),Mir=C.object({layer:C.string().optional(),thickness:Le.optional(),route:C.array(bo)}),bAe=r5.extend({name:C.string().optional(),fromLayer:hn,toLayer:hn,holeDiameter:Le,outerDiameter:Le,connectsTo:C.string().or(C.array(C.string())).optional()});lr(!0);var FAe=ms.extend({footprintVariant:C.enum(["pad","through_hole"]).optional(),padShape:C.enum(["rect","circle"]).optional().default("circle"),padDiameter:Le.optional(),holeDiameter:Le.optional(),width:Le.optional(),height:Le.optional()}).refine(n=>n.footprintVariant!=="through_hole"||n.holeDiameter!==void 0,{message:"holeDiameter is required for through_hole testpoints"});lr(!0);var EAe=Ea.omit({pcbRotation:!0,layer:!0}).extend({connection:C.string()});lr(!0);var vAe=C.union([Ea.omit({pcbRotation:!0}).extend({shape:C.literal("circle"),radius:Le}),Ea.extend({shape:C.literal("rect"),width:Le,height:Le})]),rkt=Ea.omit({pcbRotation:!0}).extend({shape:C.literal("rect"),width:Le,height:Le,connectsTo:C.string().or(C.array(C.string())).optional()});lr(!0);var nkt=Ea.omit({pcbRotation:!0}).extend({shape:C.literal("circle"),radius:Le,connectsTo:C.string().or(C.array(C.string())).optional()});lr(!0);var akt=Ea.omit({pcbRotation:!0}).extend({shape:C.literal("polygon"),points:C.array(rg),connectsTo:C.string().or(C.array(C.string())).optional()});lr(!0);var Xir=C.discriminatedUnion("shape",[rkt,nkt,akt]),CAe=ms.extend({voltage:Us}),skt=["pin1","pin2","pos","neg"],ikt=C.union([C.string(),C.number()]).transform(n=>typeof n=="string"?n.endsWith("%")?parseFloat(n.slice(0,-1))/100:parseFloat(n):n).pipe(C.number().min(0,"Duty cycle must be non-negative").max(1,"Duty cycle cannot be greater than 100%")),Kir=ms.extend({voltage:Us.optional(),frequency:Nc.optional(),peakToPeakVoltage:Us.optional(),waveShape:C.enum(["sinewave","square","triangle","sawtooth"]).optional(),phase:Ba.optional(),dutyCycle:ikt.optional(),connections:s1(skt).optional()});lr(!0);var s5=C.enum(["top_left","top_center","top_right","center_left","center","center_right","bottom_left","bottom_center","bottom_right"]),_Ae=C.object({schX:Le.optional(),schY:Le.optional(),width:Le.optional(),height:Le.optional(),overlay:C.array(C.string()).optional(),padding:Le.optional(),paddingLeft:Le.optional(),paddingRight:Le.optional(),paddingTop:Le.optional(),paddingBottom:Le.optional(),title:C.string().optional(),titleAlignment:s5.default("top_left"),titleColor:C.string().optional(),titleFontSize:Le.optional(),titleInside:C.boolean().default(!1),strokeStyle:C.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."}),ror=C.object({x1:Le,y1:Le,x2:Le,y2:Le}),okt=C.enum(["center","left","right","top","bottom"]),AAe=C.object({schX:Le.optional(),schY:Le.optional(),text:C.string(),fontSize:C.number().default(1),anchor:C.union([okt.describe("legacy"),s5]).default("center"),color:C.string().default("#000000"),schRotation:Ba.default(0)}),uor=C.object({points:C.array(mn),isFilled:C.boolean().optional().default(!1),fillColor:C.enum(["red","blue"]).optional()}),RAe=C.object({schX:Le.optional(),schY:Le.optional(),children:C.any().optional(),cellPadding:Le.optional(),borderWidth:Le.optional(),anchor:s5.optional(),fontSize:Le.optional()});lr(!0);var SAe=C.object({children:C.any().optional(),height:Le.optional()});lr(!0);var BAe=C.object({children:C.string().optional(),horizontalAlign:C.enum(["left","center","right"]).optional(),verticalAlign:C.enum(["top","middle","bottom"]).optional(),fontSize:Le.optional(),rowSpan:C.number().optional(),colSpan:C.number().optional(),width:Le.optional(),text:C.string().optional()});lr(!0);var wAe=Ea.extend({text:C.string(),anchorAlignment:s5.default("center"),font:C.enum(["tscircuit2024"]).optional(),fontSize:xe.optional(),layers:C.array(hn).optional()}),TAe=Ea.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({route:C.array(bo),strokeWidth:xe.optional()}),PAe=Ea.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({strokeWidth:Le,x1:Le,y1:Le,x2:Le,y2:Le}),IAe=Ea.omit({pcbRotation:!0}).extend({filled:C.boolean().default(!0).optional(),stroke:C.enum(["dashed","solid","none"]).optional(),strokeWidth:Le.optional(),width:Le,height:Le}),jAe=Ea.omit({pcbRotation:!0}).extend({isFilled:C.boolean().optional(),isOutline:C.boolean().optional(),strokeWidth:Le.optional(),radius:Le}),k_e=C.object({x:Le,y:Le,via:C.boolean().optional(),toLayer:hn.optional()}),kAe=C.object({for:C.string().optional().describe("Selector for the port you're targeting, not required if you're inside a trace"),order:C.number().optional(),offset:bo.or(k_e).optional(),offsets:C.array(bo).or(C.array(k_e)).optional(),traceWidth:C.number().optional()}),Sor=r5.extend({name:C.string(),pinNumber:C.number().optional(),aliases:C.array(C.string()).optional(),direction:sjt}),ukt=C.array(C.any()).describe("Circuit JSON"),ckt=C.object({footprintCircuitJson:C.array(C.any()),cadModel:M_e.optional()}),N_e=C.function().args(C.string()).returns(C.promise(ckt)).describe("A function that takes a path and returns Circuit JSON"),wor=C.object({partsEngine:z_e.optional(),autorouter:L_e.optional(),registryApiUrl:C.string().optional(),cloudAutorouterUrl:C.string().optional(),projectName:C.string().optional(),version:C.string().optional(),url:C.string().optional(),printBoardInformationToSilkscreen:C.boolean().optional(),localCacheEngine:C.any().optional(),pcbDisabled:C.boolean().optional(),schematicDisabled:C.boolean().optional(),partsEngineDisabled:C.boolean().optional(),footprintLibraryMap:C.record(C.string(),C.union([N_e,C.record(C.string(),C.union([ukt,N_e]))])).optional()});lr(!0);Xe();Yt();Hl();Xe();var zF=qr(Ic(),1);Hl();Xe();function Np(){return new vY}var vY=class n{constructor(){q(this,"index",{});q(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 a=this.index[e.id()];return a===void 0?void 0:this.array[a]}setDefault(e,a){let s=this.index[e.id()];if(s===void 0){let l=new i5(e,a());return this.index[e.id()]=this.array.length,this.array.push(l),l}else return this.array[s]}insert(e,a){let s=new i5(e,a),l=this.index[e.id()];return l===void 0?(this.index[e.id()]=this.array.length,this.array.push(s)):this.array[l]=s,s}erase(e){let a=this.index[e.id()];if(a===void 0)return;this.index[e.id()]=void 0;let s=this.array[a],l=this.array.pop();return s!==l&&(this.array[a]=l,this.index[l.first.id()]=a),s}copy(){let e=new n;for(let a=0;a<this.array.length;a++){let s=this.array[a].copy();e.array[a]=s,e.index[s.first.id()]=a}return e}},i5=class n{constructor(e,a){q(this,"first");q(this,"second");this.first=e,this.second=a}copy(){return new n(this.first,this.second)}};var ed=class{constructor(e=""){q(this,"_name");q(this,"_value",0);q(this,"_context",null);q(this,"_id",lkt++);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 Ga(this,e)}minus(e){return new Ga(this,typeof e=="number"?-e:[-1,e])}multiply(e){return new Ga([e,this])}divide(e){return new Ga([1/e,this])}toJSON(){return{name:this._name,value:this._value}}toString(){return this._context+"["+this._name+":"+this._value+"]"}},lkt=0;var Ga=class n{constructor(){q(this,"_terms");q(this,"_constant");let e=dkt(arguments);this._terms=e.terms,this._constant=e.constant}terms(){return this._terms}constant(){return this._constant}value(){let e=this._constant;for(let a=0,s=this._terms.size();a<s;a++){let l=this._terms.itemAt(a);e+=l.first.value()*l.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(a){return a.second+"*"+a.first.toString()}).join(" + ");return!this.isConstant()&&this._constant!==0&&(e+=" + "),e+=this._constant,e}};function dkt(n){let e=0,a=()=>0,s=Np();for(let l=0,p=n.length;l<p;++l){let x=n[l];if(typeof x=="number")e+=x;else if(x instanceof ed)s.setDefault(x,a).second+=1;else if(x instanceof Ga){e+=x.constant();let f=x.terms();for(let m=0,D=f.size();m<D;m++){let b=f.itemAt(m);s.setDefault(b.first,a).second+=b.second}}else if(x instanceof Array){if(x.length!==2)throw new Error("array must have length 2");let f=x[0],m=x[1];if(typeof f!="number")throw new Error("array item 0 must be a number");if(m instanceof ed)s.setDefault(m,a).second+=f;else if(m instanceof Ga){e+=m.constant()*f;let D=m.terms();for(let b=0,E=D.size();b<E;b++){let A=D.itemAt(b);s.setDefault(A.first,a).second+=A.second*f}}else throw new Error("array item 1 must be a variable or expression")}else throw new Error("invalid Expression argument: "+x)}return{terms:s,constant:e}}var Oc=class Oc{static create(e,a,s,l=1){let p=0;return p+=Math.max(0,Math.min(1e3,e*l))*1e6,p+=Math.max(0,Math.min(1e3,a*l))*1e3,p+=Math.max(0,Math.min(1e3,s*l)),p}static clip(e){return Math.max(0,Math.min(Oc.required,e))}};q(Oc,"required",Oc.create(1e3,1e3,1e3)),q(Oc,"strong",Oc.create(1,0,0)),q(Oc,"medium",Oc.create(0,1,0)),q(Oc,"weak",Oc.create(0,0,1));var Na=Oc;var gs;(function(n){n[n.Le=0]="Le",n[n.Ge=1]="Ge",n[n.Eq=2]="Eq"})(gs||(gs={}));var Vs=class{constructor(e,a,s,l=Na.required){q(this,"_expression");q(this,"_operator");q(this,"_strength");q(this,"_id",pkt++);this._operator=a,this._strength=Na.clip(l),s===void 0&&e instanceof Ga?this._expression=e:this._expression=e.minus(s)}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()+")"}},pkt=0;var ag=class{constructor(){q(this,"maxIterations",1e3);q(this,"_cnMap",xkt());q(this,"_rowMap",fkt());q(this,"_varMap",hkt());q(this,"_editMap",mkt());q(this,"_infeasibleRows",[]);q(this,"_objective",new c5);q(this,"_artificial",null);q(this,"_idTick",0)}createConstraint(e,a,s,l=Na.required){let p=new Vs(e,a,s,l);return this.addConstraint(p),p}addConstraint(e){if(this._cnMap.find(e)!==void 0)throw new Error("duplicate constraint");let s=this._createRow(e),l=s.row,p=s.tag,x=this._chooseSubject(l,p);if(x.type()===Qn.Invalid&&l.allDummies())if(o5(l.constant()))x=p.marker;else throw new Error("unsatisfiable constraint");if(x.type()===Qn.Invalid){if(!this._addWithArtificialVariable(l))throw new Error("unsatisfiable constraint")}else l.solveFor(x),this._substitute(x,l),this._rowMap.insert(x,l);this._cnMap.insert(e,p),this._optimize(this._objective)}removeConstraint(e){let a=this._cnMap.erase(e);if(a===void 0)throw new Error("unknown constraint");this._removeConstraintEffects(e,a.second);let s=a.second.marker,l=this._rowMap.erase(s);if(l===void 0){let p=this._getMarkerLeavingSymbol(s);if(p.type()===Qn.Invalid)throw new Error("failed to find leaving row");l=this._rowMap.erase(p),l.second.solveForEx(p,s),this._substitute(s,l.second)}this._optimize(this._objective)}hasConstraint(e){return this._cnMap.contains(e)}getConstraints(){return this._cnMap.array.map(({first:e})=>e)}addEditVariable(e,a){if(this._editMap.find(e)!==void 0)throw new Error("duplicate edit variable");if(a=Na.clip(a),a===Na.required)throw new Error("bad required strength");let l=new Ga(e),p=new Vs(l,gs.Eq,void 0,a);this.addConstraint(p);let f={tag:this._cnMap.find(p).second,constraint:p,constant:0};this._editMap.insert(e,f)}removeEditVariable(e){let a=this._editMap.erase(e);if(a===void 0)throw new Error("unknown edit variable");this.removeConstraint(a.second.constraint)}hasEditVariable(e){return this._editMap.contains(e)}suggestValue(e,a){let s=this._editMap.find(e);if(s===void 0)throw new Error("unknown edit variable");let l=this._rowMap,p=s.second,x=a-p.constant;p.constant=a;let f=p.tag.marker,m=l.find(f);if(m!==void 0){m.second.add(-x)<0&&this._infeasibleRows.push(f),this._dualOptimize();return}let D=p.tag.other;if(m=l.find(D),m!==void 0){m.second.add(x)<0&&this._infeasibleRows.push(D),this._dualOptimize();return}for(let b=0,E=l.size();b<E;++b){let A=l.itemAt(b),B=A.second,w=B.coefficientFor(f);w!==0&&B.add(x*w)<0&&A.first.type()!==Qn.External&&this._infeasibleRows.push(A.first)}this._dualOptimize()}updateVariables(){let e=this._varMap,a=this._rowMap;for(let s=0,l=e.size();s<l;++s){let p=e.itemAt(s),x=a.find(p.second);x!==void 0?p.first.setValue(x.second.constant()):p.first.setValue(0)}}_getVarSymbol(e){let a=()=>this._makeSymbol(Qn.External);return this._varMap.setDefault(e,a).second}_createRow(e){let a=e.expression(),s=new c5(a.constant()),l=a.terms();for(let m=0,D=l.size();m<D;++m){let b=l.itemAt(m);if(!o5(b.second)){let E=this._getVarSymbol(b.first),A=this._rowMap.find(E);A!==void 0?s.insertRow(A.second,b.second):s.insertSymbol(E,b.second)}}let p=this._objective,x=e.strength(),f={marker:Mp,other:Mp};switch(e.op()){case gs.Le:case gs.Ge:{let m=e.op()===gs.Le?1:-1,D=this._makeSymbol(Qn.Slack);if(f.marker=D,s.insertSymbol(D,m),x<Na.required){let b=this._makeSymbol(Qn.Error);f.other=b,s.insertSymbol(b,-m),p.insertSymbol(b,x)}break}case gs.Eq:{if(x<Na.required){let m=this._makeSymbol(Qn.Error),D=this._makeSymbol(Qn.Error);f.marker=m,f.other=D,s.insertSymbol(m,-1),s.insertSymbol(D,1),p.insertSymbol(m,x),p.insertSymbol(D,x)}else{let m=this._makeSymbol(Qn.Dummy);f.marker=m,s.insertSymbol(m)}break}}return s.constant()<0&&s.reverseSign(),{row:s,tag:f}}_chooseSubject(e,a){let s=e.cells();for(let p=0,x=s.size();p<x;++p){let f=s.itemAt(p);if(f.first.type()===Qn.External)return f.first}let l=a.marker.type();return(l===Qn.Slack||l===Qn.Error)&&e.coefficientFor(a.marker)<0?a.marker:(l=a.other.type(),(l===Qn.Slack||l===Qn.Error)&&e.coefficientFor(a.other)<0?a.other:Mp)}_addWithArtificialVariable(e){let a=this._makeSymbol(Qn.Slack);this._rowMap.insert(a,e.copy()),this._artificial=e.copy(),this._optimize(this._artificial);let s=o5(this._artificial.constant());this._artificial=null;let l=this._rowMap.erase(a);if(l!==void 0){let x=l.second;if(x.isConstant())return s;let f=this._anyPivotableSymbol(x);if(f.type()===Qn.Invalid)return!1;x.solveForEx(a,f),this._substitute(f,x),this._rowMap.insert(f,x)}let p=this._rowMap;for(let x=0,f=p.size();x<f;++x)p.itemAt(x).second.removeSymbol(a);return this._objective.removeSymbol(a),s}_substitute(e,a){let s=this._rowMap;for(let l=0,p=s.size();l<p;++l){let x=s.itemAt(l);x.second.substitute(e,a),x.second.constant()<0&&x.first.type()!==Qn.External&&this._infeasibleRows.push(x.first)}this._objective.substitute(e,a),this._artificial&&this._artificial.substitute(e,a)}_optimize(e){let a=0;for(;a<this.maxIterations;){let s=this._getEnteringSymbol(e);if(s.type()===Qn.Invalid)return;let l=this._getLeavingSymbol(s);if(l.type()===Qn.Invalid)throw new Error("the objective is unbounded");let p=this._rowMap.erase(l).second;p.solveForEx(l,s),this._substitute(s,p),this._rowMap.insert(s,p),a++}throw new Error("solver iterations exceeded")}_dualOptimize(){let e=this._rowMap,a=this._infeasibleRows;for(;a.length!==0;){let s=a.pop(),l=e.find(s);if(l!==void 0&&l.second.constant()<0){let p=this._getDualEnteringSymbol(l.second);if(p.type()===Qn.Invalid)throw new Error("dual optimize failed");let x=l.second;e.erase(s),x.solveForEx(s,p),this._substitute(p,x),e.insert(p,x)}}}_getEnteringSymbol(e){let a=e.cells();for(let s=0,l=a.size();s<l;++s){let p=a.itemAt(s),x=p.first;if(p.second<0&&x.type()!==Qn.Dummy)return x}return Mp}_getDualEnteringSymbol(e){let a=Number.MAX_VALUE,s=Mp,l=e.cells();for(let p=0,x=l.size();p<x;++p){let f=l.itemAt(p),m=f.first,D=f.second;if(D>0&&m.type()!==Qn.Dummy){let E=this._objective.coefficientFor(m)/D;E<a&&(a=E,s=m)}}return s}_getLeavingSymbol(e){let a=Number.MAX_VALUE,s=Mp,l=this._rowMap;for(let p=0,x=l.size();p<x;++p){let f=l.itemAt(p),m=f.first;if(m.type()!==Qn.External){let D=f.second,b=D.coefficientFor(e);if(b<0){let E=-D.constant()/b;E<a&&(a=E,s=m)}}}return s}_getMarkerLeavingSymbol(e){let a=Number.MAX_VALUE,s=a,l=a,p=Mp,x=p,f=p,m=p,D=this._rowMap;for(let b=0,E=D.size();b<E;++b){let A=D.itemAt(b),B=A.second,w=B.coefficientFor(e);if(w===0)continue;let P=A.first;if(P.type()===Qn.External)m=P;else if(w<0){let k=-B.constant()/w;k<s&&(s=k,x=P)}else{let k=B.constant()/w;k<l&&(l=k,f=P)}}return x!==p?x:f!==p?f:m}_removeConstraintEffects(e,a){a.marker.type()===Qn.Error&&this._removeMarkerEffects(a.marker,e.strength()),a.other.type()===Qn.Error&&this._removeMarkerEffects(a.other,e.strength())}_removeMarkerEffects(e,a){let s=this._rowMap.find(e);s!==void 0?this._objective.insertRow(s.second,-a):this._objective.insertSymbol(e,-a)}_anyPivotableSymbol(e){let a=e.cells();for(let s=0,l=a.size();s<l;++s){let p=a.itemAt(s),x=p.first.type();if(x===Qn.Slack||x===Qn.Error)return p.first}return Mp}_makeSymbol(e){return new u5(e,this._idTick++)}};function o5(n){let e=1e-8;return n<0?-n<e:n<e}function xkt(){return Np()}function fkt(){return Np()}function hkt(){return Np()}function mkt(){return Np()}var Qn;(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"})(Qn||(Qn={}));var u5=class{constructor(e,a){q(this,"_id");q(this,"_type");this._id=a,this._type=e}id(){return this._id}type(){return this._type}},Mp=new u5(Qn.Invalid,-1),c5=class n{constructor(e=0){q(this,"_cellMap",Np());q(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 a=0,s=e.size();a<s;++a)if(e.itemAt(a).first.type()!==Qn.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,a=1){let s=this._cellMap.setDefault(e,()=>0);o5(s.second+=a)&&this._cellMap.erase(e)}insertRow(e,a=1){this._constant+=e._constant*a;let s=e._cellMap;for(let l=0,p=s.size();l<p;++l){let x=s.itemAt(l);this.insertSymbol(x.first,x.second*a)}}removeSymbol(e){this._cellMap.erase(e)}reverseSign(){this._constant=-this._constant;let e=this._cellMap;for(let a=0,s=e.size();a<s;++a){let l=e.itemAt(a);l.second=-l.second}}solveFor(e){let a=this._cellMap,l=-1/a.erase(e).second;this._constant*=l;for(let p=0,x=a.size();p<x;++p)a.itemAt(p).second*=l}solveForEx(e,a){this.insertSymbol(e,-1),this.solveFor(a)}coefficientFor(e){let a=this._cellMap.find(e);return a!==void 0?a.second:0}substitute(e,a){let s=this._cellMap.erase(e);s!==void 0&&this.insertRow(a,s.second)}};var SBe=qr(As(),1);Yt();Zo();var CY={};Fm(CY,{boundsAreaOverlap:()=>XAe,boundsDistance:()=>YAe,clamp:()=>hs,computeDistanceBetweenBoxes:()=>tg,distSq:()=>qAe,distance:()=>Bi,doBoundsOverlap:()=>zb,doSegmentsIntersect:()=>Qo,doesLineIntersectLine:()=>Op,doesSegmentIntersectRect:()=>OAe,findNearestPointsBetweenBoxSets:()=>Nb,getBoundingBox:()=>Ql,getSegmentIntersection:()=>MAe,getUnitVectorFromDirection:()=>x5,getUnitVectorFromPointAToB:()=>p5,grid:()=>HAe,midpoint:()=>zAe,onSegment:()=>ig,orientation:()=>sg,pointToBoundsDistance:()=>$Ae,pointToBoxDistance:()=>LAe,pointToSegmentClosestPoint:()=>GAe,pointToSegmentDistance:()=>Gs,range:()=>UAe,segmentToBoundsMinDistance:()=>$b,segmentToBoxMinDistance:()=>VAe,segmentToCircleMinDistance:()=>d5,segmentToSegmentMinDistance:()=>l5});function Op([n,e],[a,s],{lineThickness:l=0}={}){return l===0?Qo(n,e,a,s):gkt(n,e,a,s)<=l}function Qo(n,e,a,s){let l=sg(n,e,a),p=sg(n,e,s),x=sg(a,s,n),f=sg(a,s,e);return!!(l!==p&&x!==f||l===0&&ig(n,a,e)||p===0&&ig(n,s,e)||x===0&&ig(a,n,s)||f===0&&ig(a,e,s))}function sg(n,e,a){let s=(e.y-n.y)*(a.x-e.x)-(e.x-n.x)*(a.y-e.y);return s===0?0:s>0?1:2}function ig(n,e,a){return e.x<=Math.max(n.x,a.x)&&e.x>=Math.min(n.x,a.x)&&e.y<=Math.max(n.y,a.y)&&e.y>=Math.min(n.y,a.y)}function gkt(n,e,a,s){if(n.x===e.x&&n.y===e.y)return Gs(n,a,s);if(a.x===s.x&&a.y===s.y)return Gs(a,n,e);if(Qo(n,e,a,s))return 0;let l=[Gs(n,a,s),Gs(e,a,s),Gs(a,n,e),Gs(s,n,e)];return Math.min(...l)}function Gs(n,e,a){let s=(a.x-e.x)**2+(a.y-e.y)**2;if(s===0)return Bi(n,e);let l=((n.x-e.x)*(a.x-e.x)+(n.y-e.y)*(a.y-e.y))/s;l=Math.max(0,Math.min(1,l));let p={x:e.x+l*(a.x-e.x),y:e.y+l*(a.y-e.y)};return Bi(n,p)}function Bi(n,e){let a=n.x-e.x,s=n.y-e.y;return Math.sqrt(a*a+s*s)}function MAe(n,e,a,s){let l=e.x-n.x,p=e.y-n.y,x=s.x-a.x,f=s.y-a.y,m=n.x-a.x,D=n.y-a.y,b=l*f-p*x;if(Math.abs(b)<1e-10)return null;let E=(D*x-m*f)/b,A=(l*D-p*m)/b,B=1e-9;if(E>=-B&&E<=1+B&&A>=-B&&A<=1+B){let w=n.x+E*l,P=n.y+E*p;return{x:w,y:P}}return null}function OAe(n,e,a){let s=m=>m.x>=a.minX&&m.x<=a.maxX&&m.y>=a.minY&&m.y<=a.maxY;if(s(n)||s(e))return!0;let l={x:a.minX,y:a.minY},p={x:a.maxX,y:a.minY},x={x:a.minX,y:a.maxY},f={x:a.maxX,y:a.maxY};return Qo(n,e,l,p)||Qo(n,e,p,f)||Qo(n,e,f,x)||Qo(n,e,x,l)}function LAe(n,e){let a=e.width/2,s=e.height/2,l=e.center.x-a,p=e.center.x+a,x=e.center.y-s,f=e.center.y+s;if(n.x>=l&&n.x<=p&&n.y>=x&&n.y<=f)return 0;let m=hs(n.x,l,p),D=hs(n.y,x,f);return Bi(n,{x:m,y:D})}function $Ae(n,e){if(n.x>=e.minX&&n.x<=e.maxX&&n.y>=e.minY&&n.y<=e.maxY)return 0;let a=hs(n.x,e.minX,e.maxX),s=hs(n.y,e.minY,e.maxY);return Bi(n,{x:a,y:s})}function zAe(n,e){return{x:(n.x+e.x)/2,y:(n.y+e.y)/2}}function qAe(n,e){let a=n.x-e.x,s=n.y-e.y;return a*a+s*s}function UAe(n,e,a=1){if(a===0)throw new Error("step cannot be 0");let s,l;e===void 0?(s=0,l=n):(s=n,l=e);let p=[];if(a>0)for(let x=s;x<l;x+=a)p.push(x);else for(let x=s;x>l;x+=a)p.push(x);return p}function l5(n,e,a,s){if(n.x===e.x&&n.y===e.y)return Gs(n,a,s);if(a.x===s.x&&a.y===s.y)return Gs(a,n,e);if(Qo(n,e,a,s))return 0;let l=[Gs(n,a,s),Gs(e,a,s),Gs(a,n,e),Gs(s,n,e)];return Math.min(...l)}function $b(n,e,a){let s={x:a.minX,y:a.minY},l={x:a.maxX,y:a.minY},p={x:a.minX,y:a.maxY},x={x:a.maxX,y:a.maxY};if(Qo(n,e,s,l)||Qo(n,e,l,x)||Qo(n,e,x,p)||Qo(n,e,p,s)||n.x>=a.minX&&n.x<=a.maxX&&n.y>=a.minY&&n.y<=a.maxY&&e.x>=a.minX&&e.x<=a.maxX&&e.y>=a.minY&&e.y<=a.maxY)return 0;let f=[Gs(s,n,e),Gs(l,n,e),Gs(p,n,e),Gs(x,n,e)];if(n.x>=a.minX&&n.x<=a.maxX&&n.y>=a.minY&&n.y<=a.maxY||e.x>=a.minX&&e.x<=a.maxX&&e.y>=a.minY&&e.y<=a.maxY)return 0;if(n.x<a.minX||n.x>a.maxX||n.y<a.minY||n.y>a.maxY){let m=hs(n.x,a.minX,a.maxX),D=hs(n.y,a.minY,a.maxY);f.push(Bi(n,{x:m,y:D}))}if(e.x<a.minX||e.x>a.maxX||e.y<a.minY||e.y>a.maxY){let m=hs(e.x,a.minX,a.maxX),D=hs(e.y,a.minY,a.maxY);f.push(Bi(e,{x:m,y:D}))}return Math.min(...f)}function VAe(n,e,a){let s=a.width/2,l=a.height/2,p={minX:a.center.x-s,maxX:a.center.x+s,minY:a.center.y-l,maxY:a.center.y+l};return $b(n,e,p)}function d5(n,e,a){let s={x:a.x,y:a.y};if(n.x===e.x&&n.y===e.y)return Math.max(0,Bi(n,s)-a.radius);let l={x:e.x-n.x,y:e.y-n.y},p={x:s.x-n.x,y:s.y-n.y},x=l.x*l.x+l.y*l.y,f=Math.max(0,Math.min(1,(l.x*p.x+l.y*p.y)/x)),m={x:n.x+f*l.x,y:n.y+f*l.y},D=Bi(m,s);return Math.max(0,D-a.radius)}function GAe(n,e,a){let s=a.x-e.x,l=a.y-e.y,p=s*s+l*l;if(p===0)return{x:e.x,y:e.y};let x=((n.x-e.x)*s+(n.y-e.y)*l)/p;return x=Math.max(0,Math.min(1,x)),{x:e.x+x*s,y:e.y+x*l}}var XAe=(n,e)=>{let a=Math.max(0,Math.min(n.maxX,e.maxX)-Math.max(n.minX,e.minX)),s=Math.max(0,Math.min(n.maxY,e.maxY)-Math.max(n.minY,e.minY));return a*s};var YAe=(n,e)=>{let a=n.maxX<e.minX?e.minX-n.maxX:e.maxX<n.minX?n.minX-e.maxX:0,s=n.maxY<e.minY?e.minY-n.maxY:e.maxY<n.minY?n.minY-e.maxY:0;return Math.sqrt(a*a+s*s)};var zb=(n,e)=>!(n.maxX<e.minX||e.maxX<n.minX||n.maxY<e.minY||e.maxY<n.minY);var p5=(n,e)=>{let a={x:e.x-n.x,y:e.y-n.y},s=Math.sqrt(a.x**2+a.y**2);return{x:a.x/s,y:a.y/s}},x5=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 HAe({rows:n,cols:e,xSpacing:a,ySpacing:s,width:l,height:p,offsetX:x=0,offsetY:f=0,yDirection:m="cartesian",centered:D=!0}){let b=a??1,E=s??1,A=l??e*b,B=p??n*E,w=D?-A/2:0,P=D?-B/2:0,k=l?l/e:b,O=p?p/n:E,$=[];for(let ee=0;ee<n;ee++)for(let X=0;X<e;X++){let te=ee*e+X,L=x+w+X*k+k/2,J=f+ee*O+O/2,U=m==="cartesian"?f+P+(n-1-ee)*O+O/2:f+P+ee*O+O/2;$.push({index:te,center:{x:L,y:U},topLeft:{x:L-k/2,y:U+O/2},bottomRight:{x:L+k/2,y:U-O/2},row:ee,col:X})}return $}Yt();var Dkt=(n,e,a)=>{let s=[{x:n.x,y:n.y}],l=(n.x+e.x)/2,p=(n.y+e.y)/2,x={x:e.x,y:e.y};switch(e.facingDirection){case"x+":x.x+=a;break;case"x-":x.x-=a;break;case"y+":x.y+=a;break;case"y-":x.y-=a;break}let f=n.facingDirection??"none",m=e.facingDirection??"none",D=A=>{let B=s[s.length-1];(B.x!==A.x||B.y!==A.y)&&s.push(A)},b=Math.abs(n.y-e.y)<=Math.max(1e-6,a*.1),E=Math.abs(n.x-e.x)<=Math.max(1e-6,a*.1);if(f==="none"&&m==="none")D({x:l,y:n.y}),D({x:l,y:e.y});else if(f==="x+"&&m==="y+")n.x>e.x&&n.y<e.y?(D({x:n.x+a,y:n.y}),D({x:n.x+a,y:e.y+a}),D({x:e.x,y:e.y+a})):!E&&!b&&n.x<e.x&&n.y>e.y?D({x:e.x,y:n.y}):E?(D({x:n.x+a,y:n.y}),D({x:n.x+a,y:e.y+a}),D({x:e.x,y:e.y+a})):n.x<e.x?(D({x:l,y:n.y}),D({x:l,y:x.y}),D({x:e.x,y:x.y})):n.y<=e.y+a?(D({x:n.x+a,y:n.y}),D({x:n.x+a,y:n.y+a}),D({x:e.x,y:n.y+a}),D({x:e.x,y:e.y})):(D({x:n.x+a,y:n.y}),D({x:n.x+a,y:(n.y+e.y)/2}),D({x:e.x,y:(n.y+e.y)/2}));else if(f==="x+"&&m==="x+"&&!b){let A=Math.max(n.x+a,x.x);D({x:A,y:n.y}),D({x:A,y:e.y})}else if(f==="x+"&&m==="x+"&&b)D({x:n.x+a,y:n.y}),D({x:n.x+a,y:n.y+a}),D({x:e.x+a,y:n.y+a}),D({x:e.x+a,y:e.y});else if(f==="x+"&&m==="y-")if(E&&n.y<=e.y)D({x:n.x+a,y:n.y}),D({x:n.x+a,y:p}),D({x:e.x,y:p});else if(E&&n.y>e.y)D({x:n.x+a,y:n.y}),D({x:n.x+a,y:e.y-a}),D({x:e.x,y:e.y-a});else if(n.x<e.x&&n.y<e.y)D({x:e.x,y:n.y});else if(n.x>e.x&&n.y<e.y){let A=n.x+a;D({x:A,y:n.y}),D({x:A,y:p}),D({x:e.x,y:p})}else if(n.x>e.x&&n.y>e.y){let A=n.x+a;D({x:A,y:n.y}),D({x:A,y:x.y}),D({x:e.x,y:x.y})}else n.y===e.y?(D({x:n.x+a,y:n.y}),D({x:n.x+a,y:n.y-a}),D({x:e.x,y:n.y-a})):(D({x:l,y:n.y}),D({x:l,y:x.y}),D({x:e.x,y:x.y}));else if(f==="x+"&&m==="x-"&&n.x+a>=e.x-a&&!b){let A=n.x+a;D({x:A,y:n.y}),D({x:A,y:p}),D({x:x.x,y:p}),D({x:x.x,y:x.y})}else f==="x+"&&m==="x-"&&b&&e.x>n.x||(f==="x+"&&m==="x-"&&b?(D({x:n.x+a,y:n.y}),D({x:n.x+a,y:n.y+a}),D({x:e.x-a,y:n.y+a}),D({x:e.x-a,y:n.y})):(f==="x+"&&D({x:n.x+a,y:n.y}),D({x:l,y:s[s.length-1].y}),D({x:l,y:x.y}),D({x:x.x,y:x.y})));return D({x:e.x,y:e.y}),s},og=(n,e,a={})=>{let s=n,l=e,p=!1;(s.x>l.x||s.x===l.x&&s.y>l.y)&&(p=!0,[s,l]=[l,s]);let x=s.facingDirection==="x-",f=s.facingDirection==="y-",m=$=>{let ee=x?s.x-($.x-s.x):$.x,X=f?s.y-($.y-s.y):$.y,te=$.facingDirection;return x&&(te==="x+"?te="x-":te==="x-"&&(te="x+")),f&&(te==="y+"?te="y-":te==="y-"&&(te="y+")),{x:ee,y:X,facingDirection:te}},D=($,ee)=>{let X=$.x-ee.x,te=$.y-ee.y,L=ee.x+te,J=ee.y-X,U=$.facingDirection;switch(U){case"x+":U="y-";break;case"y-":U="x-";break;case"x-":U="y+";break;case"y+":U="x+";break}return{x:L,y:J,facingDirection:U}},b=($,ee)=>{let X=$.x-ee.x,te=$.y-ee.y;return{x:ee.x-te,y:ee.y+X}},E=x||f?m(s):s,A=x||f?m(l):l,B=E,w=A,P=!1;E.facingDirection==="y+"&&(P=!0,B={...E,facingDirection:"x+"},w=D(A,E));let k=a?.overshoot??.1*Math.max(Math.abs(B.x-w.x),Math.abs(B.y-w.y)),O=Dkt(B,w,k);return P&&(O=O.map($=>b($,B))),(x||f)&&(O=O.map(({x:$,y:ee})=>({x:x?s.x-($-s.x):$,y:f?s.y-(ee-s.y):ee}))),p?O.reverse():O};var WAe={name:"@tscircuit/capacity-autorouter",main:"./dist/index.js",version:"0.0.107",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"},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","@tscircuit/checks":"^0.0.36","@tscircuit/circuit-json-util":"^0.0.46","@tscircuit/core":"^0.0.337","@tscircuit/math-utils":"^0.0.18","@types/bun":"^1.2.16","@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","bun-match-svg":"^0.0.9","circuit-json-to-connectivity-map":"^0.0.19","circuit-to-svg":"^0.0.110",clsx:"^2.1.1",flatbush:"^4.4.0","graphics-debug":"^0.0.44",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","use-mouse-matrix-transform":"^1.3.0",vite:"^6.0.11","vite-tsconfig-paths":"^5.1.4"},peerDependencies:{typescript:"^5.7.3"},dependencies:{"fast-json-stable-stringify":"^2.1.0","object-hash":"^3.0.0"}};Yt();Zo();ia();var VW=qr(Ic(),1);var e6e=qr(SY(),1),n6e=qr(SY(),1);var w5=(...n)=>{let e={points:[],lines:[],circles:[],rects:[]};return n.forEach((a,s)=>{a&&(a.lines&&(e.lines=[...e.lines||[],...a.lines.map(l=>({...l,step:s}))]),a.points&&(e.points=[...e.points||[],...a.points.map(l=>({...l,step:s}))]),a.circles&&(e.circles=[...e.circles||[],...a.circles.map(l=>({...l,step:s}))]),a.rects&&(e.rects=[...e.rects||[],...a.rects.map(l=>({...l,step:s}))]))}),e},Aa=class{constructor(){q(this,"MAX_ITERATIONS",1e3);q(this,"solved",!1);q(this,"failed",!1);q(this,"iterations",0);q(this,"progress",0);q(this,"error",null);q(this,"activeSubSolver");q(this,"failedSubSolvers");q(this,"timeToSolve");q(this,"stats",{});q(this,"cacheHit");q(this,"cacheKey");q(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 tu(){return tu=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var a=arguments[e];for(var s in a)({}).hasOwnProperty.call(a,s)&&(n[s]=a[s])}return n},tu.apply(null,arguments)}function j5(n,e){return(j5=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,s){return a.__proto__=s,a})(n,e)}function L4e(n){return(L4e=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(n)}function $4e(){try{var n=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return($4e=function(){return!!n})()}function $Y(n){var e=typeof Map=="function"?new Map:void 0;return $Y=function(a){if(a===null||!(function(l){try{return Function.toString.call(l).indexOf("[native code]")!==-1}catch{return typeof l=="function"}})(a))return a;if(typeof a!="function")throw new TypeError("Super expression must either be null or a function");if(e!==void 0){if(e.has(a))return e.get(a);e.set(a,s)}function s(){return(function(l,p,x){if($4e())return Reflect.construct.apply(null,arguments);var f=[null];f.push.apply(f,p);var m=new(l.bind.apply(l,f));return x&&j5(m,x.prototype),m})(a,arguments,L4e(this).constructor)}return s.prototype=Object.create(a.prototype,{constructor:{value:s,enumerable:!1,writable:!0,configurable:!0}}),j5(s,a)},$Y(n)}var eu=(function(n){var e,a;function s(l){var p;if(1)p=n.call(this,"An error occurred. See https://github.com/styled-components/polished/blob/main/src/internalHelpers/errors.md#"+l+" for more information.")||this;else for(var x,f,m;m<x;m++);return(function(D){if(D===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return D})(p)}return a=n,(e=s).prototype=Object.create(a.prototype),e.prototype.constructor=e,j5(e,a),s})($Y(Error));function l4e(n,e){return n.substr(-e.length)===e}var wkt=/^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/;function d4e(n){return typeof n!="string"?n:n.match(wkt)?parseFloat(n):n}var p4e=function(n){return function(e,a){a===void 0&&(a="16px");var s=e,l=a;if(typeof e=="string"){if(!l4e(e,"px"))throw new eu(69,n,e);s=d4e(e)}if(typeof a=="string"){if(!l4e(a,"px"))throw new eu(70,n,a);l=d4e(a)}if(typeof s=="string")throw new eu(71,e,n);if(typeof l=="string")throw new eu(72,a,n);return""+s/l+n}};p4e("em"),p4e("rem");function BY(n){return Math.round(255*n)}function Tkt(n,e,a){return BY(n)+","+BY(e)+","+BY(a)}function Jb(n,e,a,s){if(s===void 0&&(s=Tkt),e===0)return s(a,a,a);var l=(n%360+360)%360/60,p=(1-Math.abs(2*a-1))*e,x=p*(1-Math.abs(l%2-1)),f=0,m=0,D=0;l>=0&&l<1?(f=p,m=x):l>=1&&l<2?(f=x,m=p):l>=2&&l<3?(m=p,D=x):l>=3&&l<4?(m=x,D=p):l>=4&&l<5?(f=x,D=p):l>=5&&l<6&&(f=p,D=x);var b=a-p/2;return s(f+b,m+b,D+b)}var x4e={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"},Pkt=/^#[a-fA-F0-9]{6}$/,Ikt=/^#[a-fA-F0-9]{8}$/,jkt=/^#[a-fA-F0-9]{3}$/,kkt=/^#[a-fA-F0-9]{4}$/,wY=/^rgb\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*\)$/i,Nkt=/^rgb(?:a)?\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i,Mkt=/^hsl\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*\)$/i,Okt=/^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 fg(n){if(typeof n!="string")throw new eu(3);var e=(function(A){if(typeof A!="string")return A;var B=A.toLowerCase();return x4e[B]?"#"+x4e[B]:A})(n);if(e.match(Pkt))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(Ikt)){var a=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:a}}if(e.match(jkt))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(kkt)){var s=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:s}}var l=wY.exec(e);if(l)return{red:parseInt(""+l[1],10),green:parseInt(""+l[2],10),blue:parseInt(""+l[3],10)};var p=Nkt.exec(e.substring(0,50));if(p)return{red:parseInt(""+p[1],10),green:parseInt(""+p[2],10),blue:parseInt(""+p[3],10),alpha:parseFloat(""+p[4])>1?parseFloat(""+p[4])/100:parseFloat(""+p[4])};var x=Mkt.exec(e);if(x){var f="rgb("+Jb(parseInt(""+x[1],10),parseInt(""+x[2],10)/100,parseInt(""+x[3],10)/100)+")",m=wY.exec(f);if(!m)throw new eu(4,e,f);return{red:parseInt(""+m[1],10),green:parseInt(""+m[2],10),blue:parseInt(""+m[3],10)}}var D=Okt.exec(e.substring(0,50));if(D){var b="rgb("+Jb(parseInt(""+D[1],10),parseInt(""+D[2],10)/100,parseInt(""+D[3],10)/100)+")",E=wY.exec(b);if(!E)throw new eu(4,e,b);return{red:parseInt(""+E[1],10),green:parseInt(""+E[2],10),blue:parseInt(""+E[3],10),alpha:parseFloat(""+D[4])>1?parseFloat(""+D[4])/100:parseFloat(""+D[4])}}throw new eu(5)}function $p(n){return(function(e){var a,s=e.red/255,l=e.green/255,p=e.blue/255,x=Math.max(s,l,p),f=Math.min(s,l,p),m=(x+f)/2;if(x===f)return e.alpha!==void 0?{hue:0,saturation:0,lightness:m,alpha:e.alpha}:{hue:0,saturation:0,lightness:m};var D=x-f,b=m>.5?D/(2-x-f):D/(x+f);switch(x){case s:a=(l-p)/D+(l<p?6:0);break;case l:a=(p-s)/D+2;break;default:a=(s-l)/D+4}return a*=60,e.alpha!==void 0?{hue:a,saturation:b,lightness:m,alpha:e.alpha}:{hue:a,saturation:b,lightness:m}})(fg(n))}var zY=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 o1(n){var e=n.toString(16);return e.length===1?"0"+e:e}function TY(n){return o1(Math.round(255*n))}function Lkt(n,e,a){return zY("#"+TY(n)+TY(e)+TY(a))}function D5(n,e,a){return Jb(n,e,a,Lkt)}function qY(n,e,a){if(typeof n=="number"&&typeof e=="number"&&typeof a=="number")return zY("#"+o1(n)+o1(e)+o1(a));if(typeof n=="object"&&e===void 0&&a===void 0)return zY("#"+o1(n.red)+o1(n.green)+o1(n.blue));throw new eu(6)}function L5(n,e,a,s){if(typeof n=="string"&&typeof e=="number"){var l=fg(n);return"rgba("+l.red+","+l.green+","+l.blue+","+e+")"}if(typeof n=="number"&&typeof e=="number"&&typeof a=="number"&&typeof s=="number")return s>=1?qY(n,e,a):"rgba("+n+","+e+","+a+","+s+")";if(typeof n=="object"&&e===void 0&&a===void 0&&s===void 0)return n.alpha>=1?qY(n.red,n.green,n.blue):"rgba("+n.red+","+n.green+","+n.blue+","+n.alpha+")";throw new eu(7)}function zp(n){if(typeof n!="object")throw new eu(8);if((function(e){return typeof e.red=="number"&&typeof e.green=="number"&&typeof e.blue=="number"&&typeof e.alpha=="number"})(n))return L5(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 qY(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,a,s,l){if(typeof e=="number"&&typeof a=="number"&&typeof s=="number"&&typeof l=="number")return l>=1?D5(e,a,s):"rgba("+Jb(e,a,s)+","+l+")";if(typeof e=="object"&&a===void 0&&s===void 0&&l===void 0)return e.alpha>=1?D5(e.hue,e.saturation,e.lightness):"rgba("+Jb(e.hue,e.saturation,e.lightness)+","+e.alpha+")";throw new eu(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,a,s){if(typeof e=="number"&&typeof a=="number"&&typeof s=="number")return D5(e,a,s);if(typeof e=="object"&&a===void 0&&s===void 0)return D5(e.hue,e.saturation,e.lightness);throw new eu(1)})(n);throw new eu(8)}function z4e(n,e,a){return function(){var s=a.concat(Array.prototype.slice.call(arguments));return s.length>=e?n.apply(this,s):z4e(n,e,s)}}function fu(n){return z4e(n,n.length,[])}fu(function(n,e){if(e==="transparent")return e;var a=$p(e);return zp(tu({},a,{hue:a.hue+parseFloat(n)}))});function mg(n,e,a){return Math.max(n,Math.min(e,a))}fu(function(n,e){if(e==="transparent")return e;var a=$p(e);return zp(tu({},a,{lightness:mg(0,1,a.lightness-parseFloat(n))}))});fu(function(n,e){if(e==="transparent")return e;var a=$p(e);return zp(tu({},a,{saturation:mg(0,1,a.saturation-parseFloat(n))}))});fu(function(n,e){if(e==="transparent")return e;var a=$p(e);return zp(tu({},a,{lightness:mg(0,1,a.lightness+parseFloat(n))}))});var q4e=fu(function(n,e,a){if(e==="transparent")return a;if(a==="transparent")return e;if(n===0)return a;var s=fg(e),l=tu({},s,{alpha:typeof s.alpha=="number"?s.alpha:1}),p=fg(a),x=tu({},p,{alpha:typeof p.alpha=="number"?p.alpha:1}),f=l.alpha-x.alpha,m=2*parseFloat(n)-1,D=((m*f===-1?m:m+f)/(1+m*f)+1)/2,b=1-D;return L5({red:Math.floor(l.red*D+x.red*b),green:Math.floor(l.green*D+x.green*b),blue:Math.floor(l.blue*D+x.blue*b),alpha:l.alpha*parseFloat(n)+x.alpha*(1-parseFloat(n))})});fu(function(n,e){if(e==="transparent")return e;var a=fg(e);return L5(tu({},a,{alpha:mg(0,1,(100*(typeof a.alpha=="number"?a.alpha:1)+100*parseFloat(n))/100)}))});fu(function(n,e){if(e==="transparent")return e;var a=$p(e);return zp(tu({},a,{saturation:mg(0,1,a.saturation+parseFloat(n))}))});fu(function(n,e){return e==="transparent"?e:zp(tu({},$p(e),{hue:parseFloat(n)}))});fu(function(n,e){return e==="transparent"?e:zp(tu({},$p(e),{lightness:parseFloat(n)}))});fu(function(n,e){return e==="transparent"?e:zp(tu({},$p(e),{saturation:parseFloat(n)}))});fu(function(n,e){return e==="transparent"?e:q4e(parseFloat(n),"rgb(0, 0, 0)",e)});fu(function(n,e){return e==="transparent"?e:q4e(parseFloat(n),"rgb(255, 255, 255)",e)});var $kt=fu(function(n,e){if(e==="transparent")return e;var a=fg(e);return L5(tu({},a,{alpha:mg(0,1,+(100*(typeof a.alpha=="number"?a.alpha:1)-100*parseFloat(n)).toFixed(2)/100)}))}),f4e=["blue","orange","purple","cyan","magenta","yellowgreen","darkgoldenrod","deeppink"],UY=(n,e)=>{let a={};for(let s=0;s<n.connections.length;s++){let l=n.connections[s],p=e?.getNetConnectedToId(l.name);p&&!a[p]&&(a[p]=`hsl(${300*s/n.connections.length}, 100%, 50%)`),a[l.name]=(p?a[p]:null)??`hsl(${340*s/n.connections.length}, 100%, 50%)`}return a},Ds=(n,e)=>{try{return $kt(e,n)}catch(a){return console.error(a),n}},Zb=(n,e)=>n==="top"?0:n==="bottom"?e-1:parseInt(n.slice(5)),V0=(n,e=1)=>{let a=(("width"in n?n.width:n)/.5/2)**1.1*e;return n.availableZ?.length===1&&a>1?1:a},zkt=(n,e=.5,a=16)=>{let s=0,l=n;for(;s<a&&!(V0({width:l})<=e);)l/=2,s++;return Math.max(1,s)};function U4e(n,e,a=0,s=n.length-1,l=qkt){for(;s>a;){if(s-a>600){let m=s-a+1,D=e-a+1,b=Math.log(m),E=.5*Math.exp(2*b/3),A=.5*Math.sqrt(b*E*(m-E)/m)*(D-m/2<0?-1:1);U4e(n,e,Math.max(a,Math.floor(e-D*E/m+A)),Math.min(s,Math.floor(e+(m-D)*E/m+A)),l)}let p=n[e],x=a,f=s;for(Vb(n,a,e),l(n[s],p)>0&&Vb(n,a,s);x<f;){for(Vb(n,x,f),x++,f--;l(n[x],p)<0;)x++;for(;l(n[f],p)>0;)f--}l(n[a],p)===0?Vb(n,a,f):(f++,Vb(n,f,s)),f<=e&&(a=f+1),e<=f&&(s=f-1)}}function Vb(n,e,a){let s=n[e];n[e]=n[a],n[a]=s}function qkt(n,e){return n<e?-1:n>e?1:0}var Ukt=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,a=[];if(!b5(n,e))return a;let s=this.toBBox,l=[];for(;e;){for(let p=0;p<e.children.length;p++){let x=e.children[p],f=e.leaf?s(x):x;b5(n,f)&&(e.leaf?a.push(x):IY(n,f)?this._all(x,a):l.push(x))}e=l.pop()}return a}collides(n){let e=this.data;if(!b5(n,e))return!1;let a=[];for(;e;){for(let s=0;s<e.children.length;s++){let l=e.children[s],p=e.leaf?this.toBBox(l):l;if(b5(n,p)){if(e.leaf||IY(n,p))return!0;a.push(l)}}e=a.pop()}return!1}load(n){if(!n||!n.length)return this;if(n.length<this._minEntries){for(let a=0;a<n.length;a++)this.insert(n[a]);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 a=this.data;this.data=e,e=a}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=dg([]),this}remove(n,e){if(!n)return this;let a=this.data,s=this.toBBox(n),l=[],p=[],x,f,m;for(;a||l.length;){if(a||(a=l.pop(),f=l[l.length-1],x=p.pop(),m=!0),a.leaf){let D=Vkt(n,a.children,e);if(D!==-1)return a.children.splice(D,1),l.push(a),this._condense(l),this}m||a.leaf||!IY(a,s)?f?(x++,a=f.children[x],m=!1):a=null:(l.push(a),p.push(x),x=0,f=a,a=a.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 a=[];for(;n;)n.leaf?e.push(...n.children):a.push(...n.children),n=a.pop();return e}_build(n,e,a,s){let l=a-e+1,p,x=this._maxEntries;if(l<=x)return p=dg(n.slice(e,a+1)),lg(p,this.toBBox),p;s||(s=Math.ceil(Math.log(l)/Math.log(x)),x=Math.ceil(l/Math.pow(x,s-1))),p=dg([]),p.leaf=!1,p.height=s;let f=Math.ceil(l/x),m=f*Math.ceil(Math.sqrt(x));h4e(n,e,a,m,this.compareMinX);for(let D=e;D<=a;D+=m){let b=Math.min(D+m-1,a);h4e(n,D,b,f,this.compareMinY);for(let E=D;E<=b;E+=f){let A=Math.min(E+f-1,b);p.children.push(this._build(n,E,A,s-1))}}return lg(p,this.toBBox),p}_chooseSubtree(n,e,a,s){for(;s.push(e),!e.leaf&&s.length-1!==a;){let l,p=1/0,x=1/0;for(let f=0;f<e.children.length;f++){let m=e.children[f],D=PY(m),b=Ykt(n,m)-D;b<x?(x=b,p=D<p?D:p,l=m):b===x&&D<p&&(p=D,l=m)}e=l||e.children[0]}return e}_insert(n,e,a){let s=a?n:this.toBBox(n),l=[],p=this._chooseSubtree(s,this.data,e,l);for(p.children.push(n),Xb(p,s);e>=0&&l[e].children.length>this._maxEntries;)this._split(l,e),e--;this._adjustParentBBoxes(s,l,e)}_split(n,e){let a=n[e],s=a.children.length,l=this._minEntries;this._chooseSplitAxis(a,l,s);let p=this._chooseSplitIndex(a,l,s),x=dg(a.children.splice(p,a.children.length-p));x.height=a.height,x.leaf=a.leaf,lg(a,this.toBBox),lg(x,this.toBBox),e?n[e-1].children.push(x):this._splitRoot(a,x)}_splitRoot(n,e){this.data=dg([n,e]),this.data.height=n.height+1,this.data.leaf=!1,lg(this.data,this.toBBox)}_chooseSplitIndex(n,e,a){let s,l=1/0,p=1/0;for(let x=e;x<=a-e;x++){let f=Gb(n,0,x,this.toBBox),m=Gb(n,x,a,this.toBBox),D=Hkt(f,m),b=PY(f)+PY(m);D<l?(l=D,s=x,p=b<p?b:p):D===l&&b<p&&(p=b,s=x)}return s||a-e}_chooseSplitAxis(n,e,a){let s=n.leaf?this.compareMinX:Gkt,l=n.leaf?this.compareMinY:Xkt;this._allDistMargin(n,e,a,s)<this._allDistMargin(n,e,a,l)&&n.children.sort(s)}_allDistMargin(n,e,a,s){n.children.sort(s);let l=this.toBBox,p=Gb(n,0,e,l),x=Gb(n,a-e,a,l),f=y5(p)+y5(x);for(let m=e;m<a-e;m++){let D=n.children[m];Xb(p,n.leaf?l(D):D),f+=y5(p)}for(let m=a-e-1;m>=e;m--){let D=n.children[m];Xb(x,n.leaf?l(D):D),f+=y5(x)}return f}_adjustParentBBoxes(n,e,a){for(let s=a;s>=0;s--)Xb(e[s],n)}_condense(n){for(let e,a=n.length-1;a>=0;a--)n[a].children.length===0?a>0?(e=n[a-1].children,e.splice(e.indexOf(n[a]),1)):this.clear():lg(n[a],this.toBBox)}};function Vkt(n,e,a){if(!a)return e.indexOf(n);for(let s=0;s<e.length;s++)if(a(n,e[s]))return s;return-1}function lg(n,e){Gb(n,0,n.children.length,e,n)}function Gb(n,e,a,s,l){l||(l=dg(null)),l.minX=1/0,l.minY=1/0,l.maxX=-1/0,l.maxY=-1/0;for(let p=e;p<a;p++){let x=n.children[p];Xb(l,n.leaf?s(x):x)}return l}function Xb(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 Gkt(n,e){return n.minX-e.minX}function Xkt(n,e){return n.minY-e.minY}function PY(n){return(n.maxX-n.minX)*(n.maxY-n.minY)}function y5(n){return n.maxX-n.minX+(n.maxY-n.minY)}function Ykt(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 Hkt(n,e){let a=Math.max(n.minX,e.minX),s=Math.max(n.minY,e.minY),l=Math.min(n.maxX,e.maxX),p=Math.min(n.maxY,e.maxY);return Math.max(0,l-a)*Math.max(0,p-s)}function IY(n,e){return n.minX<=e.minX&&n.minY<=e.minY&&e.maxX<=n.maxX&&e.maxY<=n.maxY}function b5(n,e){return e.minX<=n.maxX&&e.minY<=n.maxY&&e.maxX>=n.minX&&e.maxY>=n.minY}function dg(n){return{children:n,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function h4e(n,e,a,s,l){let p=[e,a];for(;p.length;){if((a=p.pop())-(e=p.pop())<=s)continue;let x=e+Math.ceil((a-e)/s/2)*s;U4e(n,x,e,a,l),p.push(e,x,x,a)}}var m4e=class{constructor(n=9){q(this,"tree");this.tree=new Ukt(n)}insert(n,e,a,s,l){this.tree.insert({minX:e,minY:a,maxX:s,maxY:l,data:n})}bulkLoad(n){let e=n.map(({item:a,minX:s,minY:l,maxX:p,maxY:x})=>({minX:s,minY:l,maxX:p,maxY:x,data:a}));this.tree.load(e)}search(n,e,a,s){return this.tree.search({minX:n,minY:e,maxX:a,maxY:s}).map(l=>l.data)}clear(){this.tree.clear()}},Wkt=class{constructor(){this.ids=[],this.values=[],this.length=0}clear(){this.length=0}push(n,e){let a=this.length++;for(;a>0;){let s=a-1>>1,l=this.values[s];if(e>=l)break;this.ids[a]=this.ids[s],this.values[a]=l,a=s}this.ids[a]=n,this.values[a]=e}pop(){if(this.length===0)return;let n=this.ids[0];if(this.length--,this.length>0){let e=this.ids[0]=this.ids[this.length],a=this.values[0]=this.values[this.length],s=this.length>>1,l=0;for(;l<s;){let p=1+(l<<1),x=p+1,f=this.ids[p],m=this.values[p],D=this.values[x];if(x<this.length&&D<m&&(p=x,f=this.ids[x],m=D),m>=a)break;this.ids[l]=f,this.values[l]=m,l=p}this.ids[l]=e,this.values[l]=a}return n}peek(){if(this.length!==0)return this.ids[0]}peekValue(){if(this.length!==0)return this.values[0]}shrink(){this.ids.length=this.values.length=this.length}},g4e=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],D4e=class V4e{static from(e,a=0){if(a%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[s,l]=new Uint8Array(e,a+0,2);if(s!==251)throw new Error("Data does not appear to be in a Flatbush format.");let p=l>>4;if(p!==3)throw new Error(`Got v${p} data when expected v3.`);let x=g4e[15&l];if(!x)throw new Error("Unrecognized array type.");let[f]=new Uint16Array(e,a+2,1),[m]=new Uint32Array(e,a+4,1);return new V4e(m,f,x,void 0,e,a)}constructor(e,a=16,s=Float64Array,l=ArrayBuffer,p,x=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(+a,2),65535),this.byteOffset=x;let f=e,m=f;this._levelBounds=[4*f];do f=Math.ceil(f/this.nodeSize),m+=f,this._levelBounds.push(4*m);while(f!==1);this.ArrayType=s,this.IndexArrayType=m<16384?Uint16Array:Uint32Array;let D=g4e.indexOf(this.ArrayType),b=4*m*this.ArrayType.BYTES_PER_ELEMENT;if(D<0)throw new Error(`Unexpected typed array class: ${s}.`);p&&p.byteLength!==void 0&&!p.buffer?(this.data=p,this._boxes=new this.ArrayType(this.data,x+8,4*m),this._indices=new this.IndexArrayType(this.data,x+8+b,m),this._pos=4*m,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]):(this.data=new l(8+b+m*this.IndexArrayType.BYTES_PER_ELEMENT),this._boxes=new this.ArrayType(this.data,8,4*m),this._indices=new this.IndexArrayType(this.data,8+b,m),this._pos=0,this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,new Uint8Array(this.data,0,2).set([251,48+D]),new Uint16Array(this.data,2,1)[0]=a,new Uint32Array(this.data,4,1)[0]=e),this._queue=new Wkt}add(e,a,s=e,l=a){let p=this._pos>>2,x=this._boxes;return this._indices[p]=p,x[this._pos++]=e,x[this._pos++]=a,x[this._pos++]=s,x[this._pos++]=l,e<this.minX&&(this.minX=e),a<this.minY&&(this.minY=a),s>this.maxX&&(this.maxX=s),l>this.maxY&&(this.maxY=l),p}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 a=this.maxX-this.minX||1,s=this.maxY-this.minY||1,l=new Uint32Array(this.numItems);for(let p=0,x=0;p<this.numItems;p++){let f=e[x++],m=e[x++],D=e[x++],b=e[x++],E=Math.floor(65535*((f+D)/2-this.minX)/a),A=Math.floor(65535*((m+b)/2-this.minY)/s);l[p]=Jkt(E,A)}VY(l,e,this._indices,0,this.numItems-1,this.nodeSize);for(let p=0,x=0;p<this._levelBounds.length-1;p++){let f=this._levelBounds[p];for(;x<f;){let m=x,D=e[x++],b=e[x++],E=e[x++],A=e[x++];for(let B=1;B<this.nodeSize&&x<f;B++)D=Math.min(D,e[x++]),b=Math.min(b,e[x++]),E=Math.max(E,e[x++]),A=Math.max(A,e[x++]);this._indices[this._pos>>2]=m,e[this._pos++]=D,e[this._pos++]=b,e[this._pos++]=E,e[this._pos++]=A}}}search(e,a,s,l,p){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let x=this._boxes.length-4,f=[],m=[];for(;x!==void 0;){let D=Math.min(x+4*this.nodeSize,b4e(x,this._levelBounds));for(let b=x;b<D;b+=4){if(s<this._boxes[b]||l<this._boxes[b+1]||e>this._boxes[b+2]||a>this._boxes[b+3])continue;let E=0|this._indices[b>>2];x>=4*this.numItems?f.push(E):(p===void 0||p(E))&&m.push(E)}x=f.pop()}return m}neighbors(e,a,s=1/0,l=1/0,p){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let x=this._boxes.length-4,f=this._queue,m=[],D=l*l;e:for(;x!==void 0;){let b=Math.min(x+4*this.nodeSize,b4e(x,this._levelBounds));for(let E=x;E<b;E+=4){let A=0|this._indices[E>>2],B=y4e(e,this._boxes[E],this._boxes[E+2]),w=y4e(a,this._boxes[E+1],this._boxes[E+3]),P=B*B+w*w;P>D||(x>=4*this.numItems?f.push(A<<1,P):(p===void 0||p(A))&&f.push(1+(A<<1),P))}for(;f.length&&1&f.peek();)if(f.peekValue()>D||(m.push(f.pop()>>1),m.length===s))break e;x=f.length?f.pop()>>1:void 0}return f.clear(),m}};function y4e(n,e,a){return n<e?e-n:n<=a?0:n-a}function b4e(n,e){let a=0,s=e.length-1;for(;a<s;){let l=a+s>>1;e[l]>n?s=l:a=l+1}return e[a]}function VY(n,e,a,s,l,p){if(Math.floor(s/p)>=Math.floor(l/p))return;let x=n[s+l>>1],f=s-1,m=l+1;for(;;){do f++;while(n[f]<x);do m--;while(n[m]>x);if(f>=m)break;Kkt(n,e,a,f,m)}VY(n,e,a,s,m,p),VY(n,e,a,m+1,l,p)}function Kkt(n,e,a,s,l){let p=n[s];n[s]=n[l],n[l]=p;let x=4*s,f=4*l,m=e[x],D=e[x+1],b=e[x+2],E=e[x+3];e[x]=e[f],e[x+1]=e[f+1],e[x+2]=e[f+2],e[x+3]=e[f+3],e[f]=m,e[f+1]=D,e[f+2]=b,e[f+3]=E;let A=a[s];a[s]=a[l],a[l]=A}function Jkt(n,e){let a=n^e,s=65535^a,l=65535^(n|e),p=n&(65535^e),x=a|s>>1,f=a>>1^a,m=l>>1^s&p>>1^l,D=a&l>>1^p>>1^p;a=x,s=f,l=m,p=D,x=a&a>>2^s&s>>2,f=a&s>>2^s&(a^s)>>2,m^=a&l>>2^s&p>>2,D^=s&l>>2^(a^s)&p>>2,a=x,s=f,l=m,p=D,x=a&a>>4^s&s>>4,f=a&s>>4^s&(a^s)>>4,m^=a&l>>4^s&p>>4,D^=s&l>>4^(a^s)&p>>4,a=x,s=f,l=m,p=D,m^=a&l>>8^s&p>>8,D^=s&l>>8^(a^s)&p>>8,a=m^m>>1,s=D^D>>1;let b=n^e,E=s|65535^(b|a);return b=16711935&(b|b<<8),b=252645135&(b|b<<4),b=858993459&(b|b<<2),b=1431655765&(b|b<<1),E=16711935&(E|E<<8),E=252645135&(E|E<<4),E=858993459&(E|E<<2),E=1431655765&(E|E<<1),(E<<1|b)>>>0}var Zkt=class{constructor(n){q(this,"index");q(this,"items",[]);q(this,"currentIndex",0);q(this,"capacity");this.capacity=Math.max(1,n),this.index=new D4e(this.capacity)}insert(n,e,a,s,l){if(this.currentIndex>=this.index.numItems)throw new Error("Exceeded initial capacity");this.items[this.currentIndex]=n,this.index.add(e,a,s,l),this.currentIndex++}finish(){this.index.finish()}search(n,e,a,s){return this.index.search(n,e,a,s).map(l=>this.items[l]||null).filter(Boolean)}clear(){this.items=[],this.currentIndex=0,this.index=new D4e(this.capacity)}},G4e=class{constructor(n="native",e=[]){q(this,"idx");q(this,"storage",[]);n==="flatbush"?e.length===0?(this.idx=new m4e,n="rbush"):this.idx=new Zkt(e.length):this.idx=n==="rbush"?new m4e:new class{constructor(){q(this,"shi",new Qkt(e))}insert(a){}search(a,s,l,p){let x=(a+l)/2,f=(s+p)/2,m=l-a,D=p-s;return this.shi.getNodesInArea(x,f,m,D)}clear(){}},e.forEach(a=>this.insert(a)),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,a,s){return this.search({minX:n-a/2,minY:e-s/2,maxX:n+a/2,maxY:e+s/2})}},Qkt=class{constructor(n){q(this,"buckets");q(this,"CELL_SIZE",.4);this.obstacles=n,this.buckets=new Map;for(let e=0;e<n.length;e++){let a=n[e],s=a.center.x-a.width/2,l=a.center.y-a.height/2,p=a.center.x+a.width/2,x=a.center.y+a.height/2;for(let f=s;f<=p;f+=this.CELL_SIZE)for(let m=l;m<=x;m+=this.CELL_SIZE){let D=this.getBucketKey(f,m),b=this.buckets.get(D);b?b.push([a,e]):this.buckets.set(D,[[a,e]])}}}getBucketKey(n,e){return`${Math.floor(n/this.CELL_SIZE)}x${Math.floor(e/this.CELL_SIZE)}`}getNodesInArea(n,e,a,s){let l=[],p=new Set,x=e-s/2,f=n+a/2,m=e+s/2;for(let D=n-a/2;D<=f;D+=this.CELL_SIZE)for(let b=x;b<=m;b+=this.CELL_SIZE){let E=this.getBucketKey(D,b),A=this.buckets.get(E)||[];for(let B of A)p.has(B[1])||(p.add(B[1]),l.push(B[0]))}return l}},eNt=class{constructor(n){q(this,"buckets");q(this,"CELL_SIZE",5);this.targets=n,this.buckets=new Map;for(let e=0;e<n.length;e++){let a=n[e],s=Math.floor(a.bounds.minX/this.CELL_SIZE)*this.CELL_SIZE,l=Math.floor(a.bounds.minY/this.CELL_SIZE)*this.CELL_SIZE,p=a.bounds.maxX,x=a.bounds.maxY;for(let f=s;f<=p;f+=this.CELL_SIZE)for(let m=l;m<=x;m+=this.CELL_SIZE){let D=this.getBucketKey(f,m),b=this.buckets.get(D);b?b.push([a,e]):this.buckets.set(D,[[a,e]])}}}getBucketKey(n,e){return`${Math.floor(n/this.CELL_SIZE)}x${Math.floor(e/this.CELL_SIZE)}`}getTargetsInArea(n,e,a,s){let l=[],p=new Set,x=Math.floor((n-a/2)/this.CELL_SIZE)*this.CELL_SIZE,f=Math.floor((e-s/2)/this.CELL_SIZE)*this.CELL_SIZE,m=n+a/2,D=e+s/2;for(let b=x;b<=m;b+=this.CELL_SIZE)for(let E=f;E<=D;E+=this.CELL_SIZE){let A=this.getBucketKey(b,E),B=this.buckets.get(A)||[];for(let w of B)p.has(w[1])||(p.add(w[1]),l.push(w[0]))}return l}},tNt=class extends Aa{constructor(e,a={}){super();q(this,"unfinishedNodes");q(this,"finishedNodes");q(this,"nodeToXYOverlappingObstaclesMap");q(this,"layerCount");q(this,"MAX_DEPTH",4);q(this,"targets");q(this,"targetTree");q(this,"obstacleTree");q(this,"_nextNodeCounter",0);this.srj=e,this.opts=a,this.MAX_DEPTH=a?.capacityDepth??this.MAX_DEPTH,this.MAX_ITERATIONS=1e5,this.layerCount=e.layerCount??2;for(let x of e.obstacles)if(!x.zLayers){let f=[];for(let m of x.layers)f.push(Zb(m,e.layerCount));x.zLayers=f}let s={x:(e.bounds.minX+e.bounds.maxX)/2,y:(e.bounds.minY+e.bounds.maxY)/2},l={width:e.bounds.maxX-e.bounds.minX,height:e.bounds.maxY-e.bounds.minY},p=Math.max(l.width,l.height);this.unfinishedNodes=[{capacityMeshNodeId:this.getNextNodeId(),center:s,width:p,height:p,layer:"top",availableZ:[0,1],_depth:0,_containsTarget:!0,_containsObstacle:!0,_completelyInsideObstacle:!1}],this.finishedNodes=[],this.nodeToXYOverlappingObstaclesMap=new Map,this.obstacleTree=new G4e("flatbush",this.srj.obstacles),this.targets=this.computeTargets(),this.targetTree=new eNt(this.targets)}computeTargets(){let e=[];for(let a of this.srj.connections)for(let s of a.pointsToConnect){let l=this.obstacleTree.searchArea(s.x,s.y,.01,.01).filter(f=>f.zLayers.some(m=>s.layer==="top"?m===0:m===1)),p={minX:s.x-.005,minY:s.y-.005,maxX:s.x+.005,maxY:s.y+.005};l.length>0&&(p={minX:Math.min(...l.map(f=>f.center.x-f.width/2)),minY:Math.min(...l.map(f=>f.center.y-f.height/2)),maxX:Math.max(...l.map(f=>f.center.x+f.width/2)),maxY:Math.max(...l.map(f=>f.center.y+f.height/2))});let x={...s,connectionName:a.name,availableZ:s.layer==="top"?[0]:[1],bounds:p};e.push(x)}return e}getNextNodeId(){return"cn"+this._nextNodeCounter++}getCapacityFromDepth(e){return(this.MAX_DEPTH-e+1)**2}getTargetIfNodeContainsTarget(e){let a=e.width>4*this.targetTree.CELL_SIZE?this.targets:this.targetTree.getTargetsInArea(e.center.x,e.center.y,e.width,e.height);for(let s of a)if(s.bounds.minX<=e.center.x+e.width/2&&s.bounds.maxX>=e.center.x-e.width/2&&s.bounds.minY<=e.center.y+e.height/2&&s.bounds.maxY>=e.center.y-e.height/2&&s.availableZ.some(l=>e.availableZ.includes(l)))return s;return null}getXYOverlappingObstacles(e){let a=this.nodeToXYOverlappingObstaclesMap.get(e.capacityMeshNodeId);if(a)return a;let s=[],l=e.center.x-e.width/2,p=e.center.x+e.width/2,x=e.center.y-e.height/2,f=e.center.y+e.height/2,m=e._parent?this.getXYOverlappingObstacles(e._parent):this.srj.obstacles;for(let D of m){let b=D.center.x-D.width/2,E=D.center.x+D.width/2,A=D.center.y-D.height/2,B=D.center.y+D.height/2;(p>=b&&l<=E&&f>=A&&x<=B||l>=b&&p<=E&&x>=A&&f<=B||b>=l&&E<=p&&A>=x&&B<=f)&&s.push(D)}return this.nodeToXYOverlappingObstaclesMap.set(e.capacityMeshNodeId,s),s}getXYZOverlappingObstacles(e){let a=this.getXYOverlappingObstacles(e),s=[];for(let l of a)e.availableZ.some(p=>l.zLayers.includes(p))&&s.push(l);return s}doesNodeOverlapObstacle(e){if(this.getXYZOverlappingObstacles(e).length>0)return!0;let a=e.center.x-e.width/2,s=e.center.x+e.width/2,l=e.center.y-e.height/2,p=e.center.y+e.height/2;return a<this.srj.bounds.minX||s>this.srj.bounds.maxX||l<this.srj.bounds.minY||p>this.srj.bounds.maxY}isNodeCompletelyInsideObstacle(e){let a=this.getXYZOverlappingObstacles(e),s=e.center.x-e.width/2,l=e.center.x+e.width/2,p=e.center.y-e.height/2,x=e.center.y+e.height/2;for(let f of a){let m=f.center.x-f.width/2,D=f.center.x+f.width/2,b=f.center.y-f.height/2,E=f.center.y+f.height/2;if(s>=m&&l<=D&&p>=b&&x<=E)return!0}return!1}getChildNodes(e){if(e._depth===this.MAX_DEPTH)return[];let a=[],s={width:e.width/2,height:e.height/2},l=[{x:e.center.x-s.width/2,y:e.center.y-s.height/2},{x:e.center.x+s.width/2,y:e.center.y-s.height/2},{x:e.center.x-s.width/2,y:e.center.y+s.height/2},{x:e.center.x+s.width/2,y:e.center.y+s.height/2}];for(let p of l){let x={capacityMeshNodeId:this.getNextNodeId(),center:p,width:s.width,height:s.height,layer:e.layer,availableZ:[0,1],_depth:(e._depth??0)+1,_parent:e};x._containsObstacle=this.doesNodeOverlapObstacle(x);let f=this.getTargetIfNodeContainsTarget(x);f&&(x._targetConnectionName=f.connectionName,x.availableZ=f.availableZ,x._containsTarget=!0),x._containsObstacle&&(x._completelyInsideObstacle=this.isNodeCompletelyInsideObstacle(x)),x._completelyInsideObstacle&&!x._containsTarget||a.push(x)}return a}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 a=this.getChildNodes(e),s=[],l=[];for(let p of a){let x=this.shouldNodeBeXYSubdivided(p);x?l.push(p):x||p._containsObstacle?!x&&p._containsTarget&&s.push(p):s.push(p)}this.unfinishedNodes.push(...l),this.finishedNodes.push(...s)}visualize(){let e={lines:[],points:[],rects:[],circles:[],coordinateSystem:"cartesian",title:"Capacity Mesh Visualization"};for(let s of this.srj.obstacles)e.rects.push({center:s.center,width:s.width,height:s.height,fill:s.zLayers?.length===1&&s.zLayers?.includes(1)?"rgba(0,0,255,0.3)":"rgba(255,0,0,0.3)",stroke:"red",label:["obstacle",`z: ${s.zLayers.join(",")}`].join(`
954
954
  `)});let a=[...this.finishedNodes,...this.unfinishedNodes];for(let s of a){let l=Math.min(...s.availableZ),p=this.unfinishedNodes.length>0&&s===this.unfinishedNodes[this.unfinishedNodes.length-1];e.rects.push({center:{x:s.center.x+l*s.width*.05,y:s.center.y-l*s.width*.05},width:Math.max(s.width-2,.8*s.width),height:Math.max(s.height-2,.8*s.height),fill:s._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)"}[s.availableZ.join(",")]??"rgba(0,200,200,0.1)",stroke:p?"rgba(255,165,0,0.5)":void 0,label:[s.capacityMeshNodeId,`availableZ: ${s.availableZ.join(",")}`,`target? ${s._containsTarget??!1}`,`obs? ${s._containsObstacle??!1}`,`${s.width.toFixed(2)}x${s.height.toFixed(2)}`,`capacity: ${V0(s).toFixed(2)}`].join(`
package/lib/index.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from "./runner"
2
2
  export * from "./worker"
3
3
  export * from "./getPossibleEntrypointComponentPaths"
4
- export * from "./getPlatformConfig"
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.310",
4
+ "version": "0.0.311",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "bun run build:lib && bun run build:webworker && bun run build:blob-url && bun run build:runner && bun run build:worker-wrapper",
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="800" height="600" data-software-used-string="@tscircuit/core@0.0.706"><style></style><rect class="boundary" x="0" y="0" fill="#000" width="800" height="600"/><rect class="pcb-boundary" fill="none" stroke="#fff" stroke-width="0.3" x="69.204152249135" y="139.44636678200698" width="661.5916955017301" height="321.10726643598616"/><path class="pcb-board" d="M 69.204152249135 460.55363321799314 L 730.795847750865 460.55363321799314 L 730.795847750865 139.44636678200698 L 69.204152249135 139.44636678200698 Z" fill="none" stroke="rgba(255, 255, 255, 0.5)" stroke-width="6.920415224913495"/><path class="pcb-trace" stroke="rgb(200, 52, 52)" fill="none" d="M 503.11418685121106 300.00000000000006 L 296.88581314878894 300.00000000000006" stroke-width="10.380622837370241" stroke-linecap="round" stroke-linejoin="round" shape-rendering="crispEdges" data-layer="top"/><path class="pcb-trace" stroke="rgb(200, 52, 52)" fill="none" d="M 296.88581314878894 300.00000000000006 L 296.88581314878894 300.00000000000006" stroke-width="10.380622837370241" stroke-linecap="round" stroke-linejoin="round" shape-rendering="crispEdges" data-layer="top"/><rect class="pcb-pad" fill="rgb(200, 52, 52)" x="484.42906574394465" y="277.8546712802769" width="37.37024221453287" height="44.29065743944637" data-layer="top"/><rect class="pcb-pad" fill="rgb(200, 52, 52)" x="555.0173010380622" y="277.8546712802769" width="37.37024221453287" height="44.29065743944637" data-layer="top"/><rect class="pcb-pad" fill="rgb(200, 52, 52)" x="207.61245674740485" y="277.8546712802769" width="37.37024221453287" height="44.29065743944637" data-layer="top"/><rect class="pcb-pad" fill="rgb(200, 52, 52)" x="278.20069204152253" y="277.8546712802769" width="37.37024221453287" height="44.29065743944637" data-layer="top"/><path class="pcb-silkscreen pcb-silkscreen-top" d="M 573.7024221453287 250.17301038062288 L 470.5882352941177 250.17301038062288 L 470.5882352941177 349.82698961937723 L 573.7024221453287 349.82698961937723" fill="none" stroke="#f2eda1" stroke-width="6.920415224913495" stroke-linecap="round" stroke-linejoin="round" data-pcb-component-id="pcb_component_1" data-pcb-silkscreen-path-id="pcb_silkscreen_path_0"/><path class="pcb-silkscreen pcb-silkscreen-top" d="M 250.95910034602076 273.7024221453288 L 272.22429065743944 273.7024221453288" fill="none" stroke="#f2eda1" stroke-width="8.304498269896193" stroke-linecap="round" stroke-linejoin="round" data-pcb-component-id="pcb_component_0" data-pcb-silkscreen-path-id="pcb_silkscreen_path_1"/><path class="pcb-silkscreen pcb-silkscreen-top" d="M 250.95910034602076 326.2975778546713 L 272.22429065743944 326.2975778546713" fill="none" stroke="#f2eda1" stroke-width="8.304498269896193" stroke-linecap="round" stroke-linejoin="round" data-pcb-component-id="pcb_component_0" data-pcb-silkscreen-path-id="pcb_silkscreen_path_2"/><text x="0" y="0" dx="0" dy="0" fill="#f2eda1" font-family="Arial, sans-serif" font-size="27.68166089965398" text-anchor="middle" dominant-baseline="central" transform="matrix(1,0,0,1,538.4083044982699,215.5709342560554)" class="pcb-silkscreen-text pcb-silkscreen-top" data-pcb-silkscreen-text-id="pcb_component_1" stroke="none">C1</text><text x="0" y="0" dx="0" dy="0" fill="#f2eda1" font-family="Arial, sans-serif" font-size="101.73010380622837" text-anchor="middle" dominant-baseline="central" transform="matrix(1,0,0,1,261.5916955017301,219.03114186851218)" class="pcb-silkscreen-text pcb-silkscreen-top" data-pcb-silkscreen-text-id="pcb_component_0" stroke="none">R1</text></svg>
@@ -1,75 +0,0 @@
1
- import { CircuitRunner } from "lib/runner/CircuitRunner"
2
- import { getPlatformConfig } from "lib/getPlatformConfig"
3
- import { expect, test } from "bun:test"
4
- import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
5
-
6
- test("example19-service-like-browser-preview", async () => {
7
- // Simulate the service code pattern with platform config
8
- const worker = new CircuitRunner({
9
- platform: getPlatformConfig(), // This is the key - pass platform config
10
- })
11
-
12
- // Simulate user code that uses kicad footprints
13
- const userCode = `
14
- export default () => (
15
- <board>
16
- <resistor name="R1" resistance="1k" footprint="kicad:Resistor_SMD.pretty/R_0402_1005Metric" pcbX={-2} />
17
- <capacitor name="C1" capacitance="100uF" footprint="0402" pcbX={2} />
18
- <trace from=".R1 > .pin2" to=".C1 > .pin1" />
19
- </board>
20
- )
21
- `
22
-
23
- // Execute with fsMap similar to service code
24
- await worker.executeWithFsMap({
25
- fsMap: {
26
- "entrypoint.tsx": `
27
- import UserComponents from "./UserCode.tsx";
28
-
29
- const hasBoard = ${userCode.includes("<board").toString()};
30
-
31
- circuit.add(
32
- hasBoard ? (
33
- <UserComponents />
34
- ) : (
35
- <board>
36
- <UserComponents name="U1" />
37
- </board>
38
- )
39
- );
40
- `,
41
- "UserCode.tsx": userCode,
42
- },
43
- entrypoint: "entrypoint.tsx",
44
- })
45
-
46
- await worker.renderUntilSettled()
47
-
48
- const circuitJson = await worker.getCircuitJson()
49
-
50
- // Verify the circuit was created successfully
51
- expect(circuitJson).toBeDefined()
52
- expect(Array.isArray(circuitJson)).toBe(true)
53
- expect(circuitJson.length).toBeGreaterThan(0)
54
-
55
- // Check that we have the expected elements
56
- const pcb_trace = circuitJson.filter((el: any) => el.type === "pcb_trace")
57
- expect(pcb_trace).toBeDefined()
58
- expect(pcb_trace.length).toBe(1)
59
-
60
- // Check that kicad footprint was processed (should have footprint elements)
61
- const footprintElements = circuitJson.filter(
62
- (el: any) =>
63
- el.type === "pcb_silkscreen_text" ||
64
- el.type === "pcb_pad" ||
65
- el.type === "pcb_silkscreen_line",
66
- )
67
- expect(footprintElements.length).toBeGreaterThan(0)
68
-
69
- // Generate SVG to verify visual output
70
- expect(convertCircuitJsonToPcbSvg(circuitJson)).toMatchSvgSnapshot(
71
- import.meta.path,
72
- )
73
-
74
- await worker.kill()
75
- })