@tscircuit/eval 0.0.278 → 0.0.279
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.
|
@@ -950,7 +950,7 @@ Using plugins:`),Ce.forEach(function(qe){y_t(qe,K,Fe)}),T||console.log("\nUsing
|
|
|
950
950
|
:is(button, input, select, textarea, optgroup, option)[disabled],
|
|
951
951
|
optgroup[disabled] > option,
|
|
952
952
|
fieldset[disabled]:not(fieldset[disabled] legend:first-of-type *)
|
|
953
|
-
)`,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 $l=Cr(bg(),1);var WH={};function KH(n,t){return n===$l.default.falseFunc?$l.default.falseFunc:a=>t.isTag(a)&&n(a)}function JH(n,t){let a=t.getSiblings(n);if(a.length<=1)return[];let o=a.indexOf(n);return o<0||o===a.length-1?[]:a.slice(o+1).filter(t.isTag)}function XH(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 YH=(n,t,a,o,l)=>{let p=l(t,XH(a),o);return p===$l.default.trueFunc?n:p===$l.default.falseFunc?$l.default.falseFunc:x=>p(x)&&n(x)},LA={is:YH,matches:YH,where:YH,not(n,t,a,o,l){let p=l(t,XH(a),o);return p===$l.default.falseFunc?n:p===$l.default.trueFunc?$l.default.falseFunc:x=>!p(x)&&n(x)},has(n,t,a,o,l){let{adapter:p}=a,x=XH(a);x.relativeSelector=!0;let m=t.some(F=>F.some(W3))?[WH]:void 0,g=l(t,x,m);if(g===$l.default.falseFunc)return $l.default.falseFunc;let _=KH(g,p);if(m&&g!==$l.default.trueFunc){let{shouldTestNextSiblings:F=!1}=g;return C=>{if(!n(C))return!1;m[0]=C;let S=p.getChildren(C),P=F?[...S,...JH(C,p)]:S;return p.existsOne(_,P)}}return F=>n(F)&&p.existsOne(_,p.getChildren(F))}};function Lve(n,t,a,o,l){var p;let{name:x,data:m}=t;if(Array.isArray(m)){if(!(x in LA))throw new Error(`Unknown pseudo-class :${x}(${m})`);return LA[x](n,m,a,o,l)}let g=(p=a.pseudos)===null||p===void 0?void 0:p[x],_=typeof g=="string"?g:HH[x];if(typeof _=="string"){if(m!=null)throw new Error(`Pseudo ${x} doesn't have any arguments`);let F=X3(_);return LA.is(n,F,a,o,l)}if(typeof g=="function")return GH(g,x,m,1),F=>g(F,m)&&n(F);if(x in J3)return J3[x](n,m,a,o);if(x in OA){let F=OA[x];return GH(F,x,m,2),C=>F(C,a,m)&&n(C)}throw new Error(`Unknown pseudo-class :${x}`)}function ZH(n,t){let a=t.getParent(n);return a&&t.isTag(a)?a:null}function zve(n,t,a,o,l){let{adapter:p,equals:x}=a;switch(t.type){case _n.PseudoElement:throw new Error("Pseudo-elements are not supported by css-select");case _n.ColumnCombinator:throw new Error("Column combinators are not yet supported by css-select");case _n.Attribute:{if(t.namespace!=null)throw new Error("Namespaced attributes are not yet supported by css-select");return(!a.xmlMode||a.lowerCaseAttributeNames)&&(t.name=t.name.toLowerCase()),jve[t.action](n,t,a)}case _n.Pseudo:return Lve(n,t,a,o,l);case _n.Tag:{if(t.namespace!=null)throw new Error("Namespaced tag names are not yet supported by css-select");let{name:m}=t;return(!a.xmlMode||a.lowerCaseTags)&&(m=m.toLowerCase()),function(_){return p.getName(_)===m&&n(_)}}case _n.Descendant:{if(a.cacheResults===!1||typeof WeakSet>"u")return function(_){let F=_;for(;F=ZH(F,p);)if(n(F))return!0;return!1};let m=new WeakSet;return function(_){let F=_;for(;F=ZH(F,p);)if(!m.has(F)){if(p.isTag(F)&&n(F))return!0;m.add(F)}return!1}}case"_flexibleDescendant":return function(g){let _=g;do if(n(_))return!0;while(_=ZH(_,p));return!1};case _n.Parent:return function(g){return p.getChildren(g).some(_=>p.isTag(_)&&n(_))};case _n.Child:return function(g){let _=p.getParent(g);return _!=null&&p.isTag(_)&&n(_)};case _n.Sibling:return function(g){let _=p.getSiblings(g);for(let F=0;F<_.length;F++){let C=_[F];if(x(g,C))break;if(p.isTag(C)&&n(C))return!0}return!1};case _n.Adjacent:return p.prevElementSibling?function(g){let _=p.prevElementSibling(g);return _!=null&&n(_)}:function(g){let _=p.getSiblings(g),F;for(let C=0;C<_.length;C++){let S=_[C];if(x(g,S))break;p.isTag(S)&&(F=S)}return!!F&&n(F)};case _n.Universal:{if(t.namespace!=null&&t.namespace!=="*")throw new Error("Namespaced universal selectors are not yet supported by css-select");return n}}}function $ve(n,t,a){let o=zA(n,t,a);return KH(o,t.adapter)}function zA(n,t,a){let o=typeof n=="string"?X3(n):n;return $A(o,t,a)}function qve(n){return n.type===_n.Pseudo&&(n.name==="scope"||Array.isArray(n.data)&&n.data.some(t=>t.some(qve)))}var jPt={type:_n.Descendant},NPt={type:"_flexibleDescendant"},MPt={type:_n.Pseudo,name:"scope",data:null};function OPt(n,{adapter:t},a){let o=!!a?.every(l=>{let p=t.isTag(l)&&t.getParent(l);return l===WH||p&&t.isTag(p)});for(let l of n){if(!(l.length>0&&W3(l[0])&&l[0].type!==_n.Descendant))if(o&&!l.some(qve))l.unshift(jPt);else continue;l.unshift(MPt)}}function $A(n,t,a){var o;n.forEach(qH),a=(o=t.context)!==null&&o!==void 0?o:a;let l=Array.isArray(a),p=a&&(Array.isArray(a)?a:[a]);if(t.relativeSelector!==!1)OPt(n,t,p);else if(n.some(g=>g.length>0&&W3(g[0])))throw new Error("Relative selectors are not allowed when the `relativeSelector` option is disabled");let x=!1,m=n.map(g=>{if(g.length>=2){let[_,F]=g;_.type!==_n.Pseudo||_.name!=="scope"||(l&&F.type===_n.Descendant?g[1]=NPt:(F.type===_n.Adjacent||F.type===_n.Sibling)&&(x=!0))}return LPt(g,t,p)}).reduce(zPt,kf.default.falseFunc);return m.shouldTestNextSiblings=x,m}function LPt(n,t,a){var o;return n.reduce((l,p)=>l===kf.default.falseFunc?kf.default.falseFunc:zve(l,p,t,a,$A),(o=t.rootFunc)!==null&&o!==void 0?o:kf.default.trueFunc)}function zPt(n,t){return t===kf.default.falseFunc||n===kf.default.trueFunc?n:n===kf.default.falseFunc||t===kf.default.trueFunc?t:function(o){return n(o)||t(o)}}var Uve=(n,t)=>n===t,$Pt={adapter:NA,equals:Uve};function Vve(n){var t,a,o,l;let p=n??$Pt;return(t=p.adapter)!==null&&t!==void 0||(p.adapter=NA),(a=p.equals)!==null&&a!==void 0||(p.equals=(l=(o=p.adapter)===null||o===void 0?void 0:o.equals)!==null&&l!==void 0?l:Uve),p}function eY(n){return function(a,o,l){let p=Vve(o);return n(a,p,l)}}var bnr=eY($ve),Fnr=eY(zA),vnr=eY($A);function Gve(n){return function(a,o,l){let p=Vve(l);typeof a!="function"&&(a=zA(a,p,o));let x=qPt(o,p.adapter,a.shouldTestNextSiblings);return n(a,x,p)}}function qPt(n,t,a=!1){return a&&(n=UPt(n,t)),Array.isArray(n)?t.removeSubsets(n):t.getChildren(n)}function UPt(n,t){let a=Array.isArray(n)?n.slice(0):[n],o=a.length;for(let l=0;l<o;l++){let p=JH(a[l],t);a.push(...p)}return a}var tY=Gve((n,t,a)=>n===QH.default.falseFunc||!t||t.length===0?[]:a.adapter.findAll(n,t)),qA=Gve((n,t,a)=>n===QH.default.falseFunc||!t||t.length===0?null:a.adapter.findOne(n,t));et();or();et();var uEe=Cr(e0(),1);or();var pEe=Cr(e0(),1),fEe=Cr(e0(),1);or();wm();rY();var nY=(n,t={})=>{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 m=Number.parseInt(x.split("_").pop());Number.isNaN(m)||(a.counts[p]=Math.max(a.counts[p]??0,m))}}return new Proxy({},{get:(l,p)=>p==="toArray"?()=>n:{get:x=>n.find(m=>m.type===p&&m[`${p}_id`]===x),getUsing:x=>{let m=Object.keys(x);if(m.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");let g=m[0],_=g.replace("_id",""),F=n.find(C=>C.type===_&&C[g]===x[g]);return F?n.find(C=>C.type===p&&C[`${p}_id`]===F[`${p}_id`]):null},getWhere:x=>{let m=Object.keys(x);return n.find(g=>g.type===p&&m.every(_=>g[_]===x[_]))},list:x=>{let m=x?Object.keys(x):[];return n.filter(g=>g.type===p&&m.every(_=>g[_]===x[_]))},insert:x=>{var _;(_=a.counts)[p]??(_[p]=-1),a.counts[p]++;let m=a.counts[p],g={type:p,[`${p}_id`]:`${p}_${m}`,...x};return t.validateInserts&&(ug[p]??cg).parse(g),n.push(g),g},delete:x=>{let m=n.find(g=>g[`${p}_id`]===x);m&&n.splice(n.indexOf(m),1)},update:(x,m)=>{let g=n.find(_=>_.type===p&&_[`${p}_id`]===x);if(g)return Object.assign(g,m),g},select:x=>{if(p==="source_component")return n.find(m=>m.type==="source_component"&&m.name===x.replace(/\./g,""));if(p==="pcb_port"||p==="source_port"||p==="schematic_port"){let[m,g]=x.replace(/\./g,"").split(/[\s\>]+/),_=n.find(C=>C.type==="source_component"&&C.name===m);if(!_)return null;let F=n.find(C=>C.type==="source_port"&&C.source_component_id===_.source_component_id&&(C.name===g||(C.port_hints??[]).includes(g)));if(!F)return null;if(p==="source_port")return F;if(p==="pcb_port")return n.find(C=>C.type==="pcb_port"&&C.source_port_id===F.source_port_id);if(p==="schematic_port")return n.find(C=>C.type==="schematic_port"&&C.source_port_id===F.source_port_id)}}}})};nY.unparsed=nY;var Yve=nY;var tar=Cr(Wve(),1);Nu();function rb(n){let t=n.width/2,a=n.height/2;return{minX:n.center.x-t,maxX:n.center.x+t,minY:n.center.y-a,maxY:n.center.y+a}}function q2(n,t){let a=rb(n),o=rb(t),l=Math.max(a.minX-o.maxX,o.minX-a.maxX,0),p=Math.max(a.minY-o.maxY,o.minY-a.maxY,0),x={x:0,y:0},m={x:0,y:0};return l===0&&p===0?{distance:0,pointA:n.center,pointB:t.center}:(x.x=r0(n.center.x,o.minX,o.maxX),x.y=r0(n.center.y,o.minY,o.maxY),m.x=r0(t.center.x,a.minX,a.maxX),m.y=r0(t.center.y,a.minY,a.maxY),{distance:Math.hypot(x.x-m.x,x.y-m.y),pointA:x,pointB:m})}function r0(n,t,a){return Math.max(t,Math.min(a,n))}function nb(n,t){let a=Number.POSITIVE_INFINITY,o={x:0,y:0},l={x:0,y:0};for(let p of n)for(let x of t){let{distance:m,pointA:g,pointB:_}=q2(p,x);m<a&&(a=m,o=g,l=_)}return{pointA:o,pointB:l,distance:a}}Nu();Nu();eq();Nu();var Cg=(n,t)=>Math.abs(n.x-t.x)+Math.abs(n.y-t.y),rEe=(n,t)=>{let a=t.x-n.x,o=t.y-n.y;return Math.abs(a)>Math.abs(o)?{dx:Math.sign(a),dy:0}:{dx:0,dy:Math.sign(o)}},oEe=(n,t,a)=>Math.abs(n.x-t.x)*Math.abs(a.dx)+Math.abs(n.y-t.y)*Math.abs(a.dy),cEe=(n,t=.1)=>`${Math.round(n.x/t)},${Math.round(n.y/t)}`,nEe=(n,t)=>Math.abs(n-t)<1e-4,lEe=(n,t,{viaDiameter:a=.5}={})=>{let o=[];for(let l=0;l<n.length-1;l++){let[p,x]=[n[l],n[l+1]],m=l-1>=0?n[l-1]:null,g=nEe(p.y,x.y),_=nEe(p.x,x.x);if(!g&&!_)throw new Error(`getObstaclesFromTrace currently only supports horizontal and vertical traces (not diagonals) Conflicting trace: ${t}, start: (${p.x}, ${p.y}), end: (${x.x}, ${x.y})`);let F={type:"rect",layers:[p.layer],center:{x:(p.x+x.x)/2,y:(p.y+x.y)/2},width:g?Math.abs(p.x-x.x):.1,height:_?Math.abs(p.y-x.y):.1,connectedTo:[t]};if(o.push(F),m&&m.layer===p.layer&&p.layer!==x.layer){let C={type:"rect",layers:[p.layer,x.layer],center:{x:p.x,y:p.y},connectedTo:[t],width:a,height:a};o.push(C)}}return o},dEe=class{constructor(n){J(this,"obstacles");J(this,"GRID_STEP",.1);this.obstacles=n.map(t=>({...t,left:t.center.x-t.width/2,right:t.center.x+t.width/2,top:t.center.y+t.height/2,bottom:t.center.y-t.height/2}))}getObstacleAt(n,t,a){a??(a=this.GRID_STEP);for(let o of this.obstacles){let l=o.width/2+a,p=o.height/2+a;if(n>=o.center.x-l&&n<=o.center.x+l&&t>=o.center.y-p&&t<=o.center.y+p)return o}return null}isObstacleAt(n,t,a){return this.getObstacleAt(n,t,a)!==null}getDirectionDistancesToNearestObstacle(n,t){let{GRID_STEP:a}=this,o={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,m=l.center.y+l.height/2+a,g=l.center.y-l.height/2-a;t>=g&&t<=m&&n>p&&(o.left=Math.min(o.left,n-x)),t>=g&&t<=m&&n<x&&(o.right=Math.min(o.right,p-n)),n>=p&&n<=x&&t<m&&(o.top=Math.min(o.top,g-t)),n>=p&&n<=x&&t>g&&(o.bottom=Math.min(o.bottom,t-m))}return o}getOrthoDirectionCollisionInfo(n,t,{margin:a=0}={}){let{x:o,y:l}=n,{dx:p,dy:x}=t,m=1/0,g=null;for(let _ of this.obstacles){let F=_.left-a,C=_.right+a,S=_.top+a,P=_.bottom-a,k=null;p===1&&x===0?l>P&&l<S&&o<_.left&&(k=_.left-o):p===-1&&x===0?l>P&&l<S&&o>_.right&&(k=o-_.right):p===0&&x===1?o>F&&o<C&&l<_.bottom&&(k=_.bottom-l):p===0&&x===-1&&o>F&&o<C&&l>_.top&&(k=l-_.top),k!==null&&k<m&&(m=k,g=_)}return{dx:p,dy:x,wallDistance:m,obstacle:g}}getObstaclesOverlappingRegion(n){let t=[];for(let a of this.obstacles){let{left:o,right:l,top:p,bottom:x}=a;o<=n.maxX&&l>=n.minX&&p<=n.maxY&&x>=n.minY&&t.push(a)}return t}};function HPt(n){if(n.length<4)return n;let t=[{...n[0]}],a=n[0].layer;for(let o=1;o<n.length;o++){let l={start:n[o-1],end:n[o]},p=n[o].route_type==="via"||n[o-1].route_type==="via";if(n[o].layer!==a||p){t.push({...n[o]}),a=n[o].layer;continue}let x=!1,m=null,g=-1;for(let F=0;F<t.length-1;F++){let C={start:t[F],end:t[F+1]};if(C.start.layer===l.start.layer&&C.start.layer===l.start.layer){let S=YPt(C,l);if(S){x=!0,m={...S,layer:a},g=F;break}}}x&&m&&(t.splice(g+1),t.push(m));let _=t[t.length-1];(_.x!==n[o].x||_.y!==n[o].y)&&t.push(n[o])}return t}function YPt(n,t){if(n.start.x===n.end.x&&t.start.x===t.end.x||n.start.y===n.end.y&&t.start.y===t.end.y)return null;let a;if(n.start.x===n.end.x){let o=n.start.x,l=t.start.y;a={...n.start,x:o,y:l}}else{let o=t.start.x,l=n.start.y;a={...n.start,x:o,y:l}}return aEe(a,n)&&aEe(a,t)?a:null}function aEe(n,t){return n.x>=Math.min(t.start.x,t.end.x)&&n.x<=Math.max(t.start.x,t.end.x)&&n.y>=Math.min(t.start.y,t.end.y)&&n.y<=Math.max(t.start.y,t.end.y)}function XPt(n){let t=[n[0]];for(let a=1;a<n.length-1;a++){let[o,l,p]=[n[a-1],n[a],n[a+1]];t.push(l),!(l.route_type!=="wire"||o.route_type!=="wire"||p.route_type!=="wire")&&o.layer===l.layer&&l.layer!==p.layer&&t.push({route_type:"via",from_layer:l.layer,to_layer:p.layer,x:l.x,y:l.y})}return t.push(n[n.length-1]),t}var Qnr=(0,pEe.default)("autorouter:shortenPathWithShortcuts");function WPt(n,t){if(n.length<=2)return n;let a=[n[0]];for(let o=1;o<n.length;o++){let l={start:a[a.length-1],end:n[o]},p=-1,x=l.start.x===l.end.x,m=l.start.y===l.end.y;for(let g=o+1;g<n.length;g++){if(g<=p)continue;let _={start:n[g],end:n[g+1]};if(!_.end)continue;let F=_.start.x===_.end.x,C=_.start.y===_.end.y,S=x&&F,P=m&&C;if(P&&S||!(S||P))continue;let q=!1,X=Math.min(l.start.x,l.end.x),Q=Math.max(l.start.x,l.end.x),ee=Math.min(_.start.x,_.end.x),ue=Math.max(_.start.x,_.end.x),ce=Math.min(l.start.y,l.end.y),fe=Math.max(l.start.y,l.end.y),U=Math.min(_.start.y,_.end.y),me=Math.max(_.start.y,_.end.y);if(P?q=X<=ue&&Q>=ee:S&&(q=ce<=me&&fe>=U),!q)continue;let W=[],pe=a[a.length-1],he=n[g+2];if(!he)continue;P&&ee<Q&&he.x===ee&&W.push({x:ee,y:l.start.y,layer:l.start.layer}),P&&ue>X&&he.x===ue&&W.push({x:ue,y:l.start.y,layer:l.start.layer}),S&&U<fe&&he.y===U&&W.push({x:l.start.x,y:U,layer:l.start.layer}),S&&me>ce&&he.y===me&&W.push({x:l.start.x,y:me,layer:l.start.layer});let Ae=null;for(let de of W)if(!(t(pe,de)||t(he,de))){Ae=de;break}if(Ae){a.push(Ae),o=g+1,p=g+1;break}}p===-1&&a.push(n[o])}return a[a.length-1]!==n[n.length-1]&&a.push(n[n.length-1]),a}var Eg=(0,uEe.default)("autorouting-dataset:astar"),xEe=class{constructor(n){J(this,"openSet",[]);J(this,"closedSet",new Set);J(this,"debug",!1);J(this,"debugSolutions");J(this,"debugMessage",null);J(this,"debugTraceCount",0);J(this,"input");J(this,"obstacles");J(this,"allObstacles");J(this,"startNode");J(this,"goalPoint");J(this,"GRID_STEP");J(this,"OBSTACLE_MARGIN");J(this,"MAX_ITERATIONS");J(this,"isRemovePathLoopsEnabled");J(this,"isShortenPathWithShortcutsEnabled");J(this,"GREEDY_MULTIPLIER",1.1);J(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??Eg.enabled,this.isRemovePathLoopsEnabled=n.isRemovePathLoopsEnabled??!1,this.isShortenPathWithShortcutsEnabled=n.isShortenPathWithShortcutsEnabled??!1,this.debug&&(Eg.enabled=!0),Eg.enabled&&(this.debugSolutions={},this.debugMessage="")}getNeighbors(n){return[]}isSameNode(n,t){return Cg(n,t)<this.GRID_STEP}computeG(n,t){return n.g+Cg(n,t)}computeH(n){return Cg(n,this.goalPoint)}getNodeName(n){return cEe(n,this.GRID_STEP)}solveOneStep(){this.iterations+=1;let{openSet:n,closedSet:t,GRID_STEP:a,goalPoint:o}=this;n.sort((m,g)=>m.f-g.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 m of this.getNeighbors(l)){if(t.has(this.getNodeName(m)))continue;let g=this.computeG(l,m),_=this.openSet.find(F=>this.isSameNode(F,m));if(!_||g<_.g){let F=this.computeH(m),C=g+F*this.GREEDY_MULTIPLIER,S={...m,g,h:F,f:C,obstacleHit:m.obstacleHit??void 0,manDistFromParent:Cg(l,m),nodesInPath:l.nodesInPath+1,parent:l,enterMarginCost:m.enterMarginCost,travelMarginCostFactor:m.travelMarginCostFactor};n.push(S),x.push(S)}}return Eg.enabled&&(n.sort((m,g)=>m.f-g.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:t}=n;for(this.iterations=0,this.closedSet=new Set,this.startNode=this.getStartNode(n),this.goalPoint={...t[t.length-1],l:this.layerToIndex(t[t.length-1].layer)},this.openSet=[this.startNode];this.iterations<this.MAX_ITERATIONS;){let{solved:a,current:o}=this.solveOneStep();if(a){let l=[],p=o;for(;p;){let x=p.l;l.unshift({x:p.x,y:p.y,layer:x!==void 0?this.indexToLayer(x):t[0].layer}),p=p.parent}return Eg.enabled&&(this.debugMessage+=`t${this.debugTraceCount}: ${this.iterations} iterations
|
|
953
|
+
)`,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 $l=Cr(bg(),1);var WH={};function KH(n,t){return n===$l.default.falseFunc?$l.default.falseFunc:a=>t.isTag(a)&&n(a)}function JH(n,t){let a=t.getSiblings(n);if(a.length<=1)return[];let o=a.indexOf(n);return o<0||o===a.length-1?[]:a.slice(o+1).filter(t.isTag)}function XH(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 YH=(n,t,a,o,l)=>{let p=l(t,XH(a),o);return p===$l.default.trueFunc?n:p===$l.default.falseFunc?$l.default.falseFunc:x=>p(x)&&n(x)},LA={is:YH,matches:YH,where:YH,not(n,t,a,o,l){let p=l(t,XH(a),o);return p===$l.default.falseFunc?n:p===$l.default.trueFunc?$l.default.falseFunc:x=>!p(x)&&n(x)},has(n,t,a,o,l){let{adapter:p}=a,x=XH(a);x.relativeSelector=!0;let m=t.some(F=>F.some(W3))?[WH]:void 0,g=l(t,x,m);if(g===$l.default.falseFunc)return $l.default.falseFunc;let _=KH(g,p);if(m&&g!==$l.default.trueFunc){let{shouldTestNextSiblings:F=!1}=g;return C=>{if(!n(C))return!1;m[0]=C;let S=p.getChildren(C),P=F?[...S,...JH(C,p)]:S;return p.existsOne(_,P)}}return F=>n(F)&&p.existsOne(_,p.getChildren(F))}};function Lve(n,t,a,o,l){var p;let{name:x,data:m}=t;if(Array.isArray(m)){if(!(x in LA))throw new Error(`Unknown pseudo-class :${x}(${m})`);return LA[x](n,m,a,o,l)}let g=(p=a.pseudos)===null||p===void 0?void 0:p[x],_=typeof g=="string"?g:HH[x];if(typeof _=="string"){if(m!=null)throw new Error(`Pseudo ${x} doesn't have any arguments`);let F=X3(_);return LA.is(n,F,a,o,l)}if(typeof g=="function")return GH(g,x,m,1),F=>g(F,m)&&n(F);if(x in J3)return J3[x](n,m,a,o);if(x in OA){let F=OA[x];return GH(F,x,m,2),C=>F(C,a,m)&&n(C)}throw new Error(`Unknown pseudo-class :${x}`)}function ZH(n,t){let a=t.getParent(n);return a&&t.isTag(a)?a:null}function zve(n,t,a,o,l){let{adapter:p,equals:x}=a;switch(t.type){case _n.PseudoElement:throw new Error("Pseudo-elements are not supported by css-select");case _n.ColumnCombinator:throw new Error("Column combinators are not yet supported by css-select");case _n.Attribute:{if(t.namespace!=null)throw new Error("Namespaced attributes are not yet supported by css-select");return(!a.xmlMode||a.lowerCaseAttributeNames)&&(t.name=t.name.toLowerCase()),jve[t.action](n,t,a)}case _n.Pseudo:return Lve(n,t,a,o,l);case _n.Tag:{if(t.namespace!=null)throw new Error("Namespaced tag names are not yet supported by css-select");let{name:m}=t;return(!a.xmlMode||a.lowerCaseTags)&&(m=m.toLowerCase()),function(_){return p.getName(_)===m&&n(_)}}case _n.Descendant:{if(a.cacheResults===!1||typeof WeakSet>"u")return function(_){let F=_;for(;F=ZH(F,p);)if(n(F))return!0;return!1};let m=new WeakSet;return function(_){let F=_;for(;F=ZH(F,p);)if(!m.has(F)){if(p.isTag(F)&&n(F))return!0;m.add(F)}return!1}}case"_flexibleDescendant":return function(g){let _=g;do if(n(_))return!0;while(_=ZH(_,p));return!1};case _n.Parent:return function(g){return p.getChildren(g).some(_=>p.isTag(_)&&n(_))};case _n.Child:return function(g){let _=p.getParent(g);return _!=null&&p.isTag(_)&&n(_)};case _n.Sibling:return function(g){let _=p.getSiblings(g);for(let F=0;F<_.length;F++){let C=_[F];if(x(g,C))break;if(p.isTag(C)&&n(C))return!0}return!1};case _n.Adjacent:return p.prevElementSibling?function(g){let _=p.prevElementSibling(g);return _!=null&&n(_)}:function(g){let _=p.getSiblings(g),F;for(let C=0;C<_.length;C++){let S=_[C];if(x(g,S))break;p.isTag(S)&&(F=S)}return!!F&&n(F)};case _n.Universal:{if(t.namespace!=null&&t.namespace!=="*")throw new Error("Namespaced universal selectors are not yet supported by css-select");return n}}}function $ve(n,t,a){let o=zA(n,t,a);return KH(o,t.adapter)}function zA(n,t,a){let o=typeof n=="string"?X3(n):n;return $A(o,t,a)}function qve(n){return n.type===_n.Pseudo&&(n.name==="scope"||Array.isArray(n.data)&&n.data.some(t=>t.some(qve)))}var jPt={type:_n.Descendant},NPt={type:"_flexibleDescendant"},MPt={type:_n.Pseudo,name:"scope",data:null};function OPt(n,{adapter:t},a){let o=!!a?.every(l=>{let p=t.isTag(l)&&t.getParent(l);return l===WH||p&&t.isTag(p)});for(let l of n){if(!(l.length>0&&W3(l[0])&&l[0].type!==_n.Descendant))if(o&&!l.some(qve))l.unshift(jPt);else continue;l.unshift(MPt)}}function $A(n,t,a){var o;n.forEach(qH),a=(o=t.context)!==null&&o!==void 0?o:a;let l=Array.isArray(a),p=a&&(Array.isArray(a)?a:[a]);if(t.relativeSelector!==!1)OPt(n,t,p);else if(n.some(g=>g.length>0&&W3(g[0])))throw new Error("Relative selectors are not allowed when the `relativeSelector` option is disabled");let x=!1,m=n.map(g=>{if(g.length>=2){let[_,F]=g;_.type!==_n.Pseudo||_.name!=="scope"||(l&&F.type===_n.Descendant?g[1]=NPt:(F.type===_n.Adjacent||F.type===_n.Sibling)&&(x=!0))}return LPt(g,t,p)}).reduce(zPt,kf.default.falseFunc);return m.shouldTestNextSiblings=x,m}function LPt(n,t,a){var o;return n.reduce((l,p)=>l===kf.default.falseFunc?kf.default.falseFunc:zve(l,p,t,a,$A),(o=t.rootFunc)!==null&&o!==void 0?o:kf.default.trueFunc)}function zPt(n,t){return t===kf.default.falseFunc||n===kf.default.trueFunc?n:n===kf.default.falseFunc||t===kf.default.trueFunc?t:function(o){return n(o)||t(o)}}var Uve=(n,t)=>n===t,$Pt={adapter:NA,equals:Uve};function Vve(n){var t,a,o,l;let p=n??$Pt;return(t=p.adapter)!==null&&t!==void 0||(p.adapter=NA),(a=p.equals)!==null&&a!==void 0||(p.equals=(l=(o=p.adapter)===null||o===void 0?void 0:o.equals)!==null&&l!==void 0?l:Uve),p}function eY(n){return function(a,o,l){let p=Vve(o);return n(a,p,l)}}var bnr=eY($ve),Fnr=eY(zA),vnr=eY($A);function Gve(n){return function(a,o,l){let p=Vve(l);typeof a!="function"&&(a=zA(a,p,o));let x=qPt(o,p.adapter,a.shouldTestNextSiblings);return n(a,x,p)}}function qPt(n,t,a=!1){return a&&(n=UPt(n,t)),Array.isArray(n)?t.removeSubsets(n):t.getChildren(n)}function UPt(n,t){let a=Array.isArray(n)?n.slice(0):[n],o=a.length;for(let l=0;l<o;l++){let p=JH(a[l],t);a.push(...p)}return a}var tY=Gve((n,t,a)=>n===QH.default.falseFunc||!t||t.length===0?[]:a.adapter.findAll(n,t)),qA=Gve((n,t,a)=>n===QH.default.falseFunc||!t||t.length===0?null:a.adapter.findOne(n,t));et();or();et();var uEe=Cr(e0(),1);or();var pEe=Cr(e0(),1),fEe=Cr(e0(),1);or();wm();rY();var nY=(n,t={})=>{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 m=Number.parseInt(x.split("_").pop());Number.isNaN(m)||(a.counts[p]=Math.max(a.counts[p]??0,m))}}return new Proxy({},{get:(l,p)=>p==="toArray"?()=>n:{get:x=>n.find(m=>m.type===p&&m[`${p}_id`]===x),getUsing:x=>{let m=Object.keys(x);if(m.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");let g=m[0],_=g.replace("_id",""),F=n.find(C=>C.type===_&&C[g]===x[g]);return F?n.find(C=>C.type===p&&C[`${p}_id`]===F[`${p}_id`]):null},getWhere:x=>{let m=Object.keys(x);return n.find(g=>g.type===p&&m.every(_=>g[_]===x[_]))},list:x=>{let m=x?Object.keys(x):[];return n.filter(g=>g.type===p&&m.every(_=>g[_]===x[_]))},insert:x=>{var _;(_=a.counts)[p]??(_[p]=-1),a.counts[p]++;let m=a.counts[p],g={type:p,[`${p}_id`]:`${p}_${m}`,...x};return t.validateInserts&&(ug[p]??cg).parse(g),n.push(g),g},delete:x=>{let m=n.find(g=>g[`${p}_id`]===x);m&&n.splice(n.indexOf(m),1)},update:(x,m)=>{let g=n.find(_=>_[`${p}_id`]===x);if(g)return Object.assign(g,m),g},select:x=>{if(p==="source_component")return n.find(m=>m.type==="source_component"&&m.name===x.replace(/\./g,""));if(p==="pcb_port"||p==="source_port"||p==="schematic_port"){let[m,g]=x.replace(/\./g,"").split(/[\s\>]+/),_=n.find(C=>C.type==="source_component"&&C.name===m);if(!_)return null;let F=n.find(C=>C.type==="source_port"&&C.source_component_id===_.source_component_id&&(C.name===g||(C.port_hints??[]).includes(g)));if(!F)return null;if(p==="source_port")return F;if(p==="pcb_port")return n.find(C=>C.type==="pcb_port"&&C.source_port_id===F.source_port_id);if(p==="schematic_port")return n.find(C=>C.type==="schematic_port"&&C.source_port_id===F.source_port_id)}}}})};nY.unparsed=nY;var Yve=nY;var tar=Cr(Wve(),1);Nu();function rb(n){let t=n.width/2,a=n.height/2;return{minX:n.center.x-t,maxX:n.center.x+t,minY:n.center.y-a,maxY:n.center.y+a}}function q2(n,t){let a=rb(n),o=rb(t),l=Math.max(a.minX-o.maxX,o.minX-a.maxX,0),p=Math.max(a.minY-o.maxY,o.minY-a.maxY,0),x={x:0,y:0},m={x:0,y:0};return l===0&&p===0?{distance:0,pointA:n.center,pointB:t.center}:(x.x=r0(n.center.x,o.minX,o.maxX),x.y=r0(n.center.y,o.minY,o.maxY),m.x=r0(t.center.x,a.minX,a.maxX),m.y=r0(t.center.y,a.minY,a.maxY),{distance:Math.hypot(x.x-m.x,x.y-m.y),pointA:x,pointB:m})}function r0(n,t,a){return Math.max(t,Math.min(a,n))}function nb(n,t){let a=Number.POSITIVE_INFINITY,o={x:0,y:0},l={x:0,y:0};for(let p of n)for(let x of t){let{distance:m,pointA:g,pointB:_}=q2(p,x);m<a&&(a=m,o=g,l=_)}return{pointA:o,pointB:l,distance:a}}Nu();Nu();eq();Nu();var Cg=(n,t)=>Math.abs(n.x-t.x)+Math.abs(n.y-t.y),rEe=(n,t)=>{let a=t.x-n.x,o=t.y-n.y;return Math.abs(a)>Math.abs(o)?{dx:Math.sign(a),dy:0}:{dx:0,dy:Math.sign(o)}},oEe=(n,t,a)=>Math.abs(n.x-t.x)*Math.abs(a.dx)+Math.abs(n.y-t.y)*Math.abs(a.dy),cEe=(n,t=.1)=>`${Math.round(n.x/t)},${Math.round(n.y/t)}`,nEe=(n,t)=>Math.abs(n-t)<1e-4,lEe=(n,t,{viaDiameter:a=.5}={})=>{let o=[];for(let l=0;l<n.length-1;l++){let[p,x]=[n[l],n[l+1]],m=l-1>=0?n[l-1]:null,g=nEe(p.y,x.y),_=nEe(p.x,x.x);if(!g&&!_)throw new Error(`getObstaclesFromTrace currently only supports horizontal and vertical traces (not diagonals) Conflicting trace: ${t}, start: (${p.x}, ${p.y}), end: (${x.x}, ${x.y})`);let F={type:"rect",layers:[p.layer],center:{x:(p.x+x.x)/2,y:(p.y+x.y)/2},width:g?Math.abs(p.x-x.x):.1,height:_?Math.abs(p.y-x.y):.1,connectedTo:[t]};if(o.push(F),m&&m.layer===p.layer&&p.layer!==x.layer){let C={type:"rect",layers:[p.layer,x.layer],center:{x:p.x,y:p.y},connectedTo:[t],width:a,height:a};o.push(C)}}return o},dEe=class{constructor(n){J(this,"obstacles");J(this,"GRID_STEP",.1);this.obstacles=n.map(t=>({...t,left:t.center.x-t.width/2,right:t.center.x+t.width/2,top:t.center.y+t.height/2,bottom:t.center.y-t.height/2}))}getObstacleAt(n,t,a){a??(a=this.GRID_STEP);for(let o of this.obstacles){let l=o.width/2+a,p=o.height/2+a;if(n>=o.center.x-l&&n<=o.center.x+l&&t>=o.center.y-p&&t<=o.center.y+p)return o}return null}isObstacleAt(n,t,a){return this.getObstacleAt(n,t,a)!==null}getDirectionDistancesToNearestObstacle(n,t){let{GRID_STEP:a}=this,o={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,m=l.center.y+l.height/2+a,g=l.center.y-l.height/2-a;t>=g&&t<=m&&n>p&&(o.left=Math.min(o.left,n-x)),t>=g&&t<=m&&n<x&&(o.right=Math.min(o.right,p-n)),n>=p&&n<=x&&t<m&&(o.top=Math.min(o.top,g-t)),n>=p&&n<=x&&t>g&&(o.bottom=Math.min(o.bottom,t-m))}return o}getOrthoDirectionCollisionInfo(n,t,{margin:a=0}={}){let{x:o,y:l}=n,{dx:p,dy:x}=t,m=1/0,g=null;for(let _ of this.obstacles){let F=_.left-a,C=_.right+a,S=_.top+a,P=_.bottom-a,k=null;p===1&&x===0?l>P&&l<S&&o<_.left&&(k=_.left-o):p===-1&&x===0?l>P&&l<S&&o>_.right&&(k=o-_.right):p===0&&x===1?o>F&&o<C&&l<_.bottom&&(k=_.bottom-l):p===0&&x===-1&&o>F&&o<C&&l>_.top&&(k=l-_.top),k!==null&&k<m&&(m=k,g=_)}return{dx:p,dy:x,wallDistance:m,obstacle:g}}getObstaclesOverlappingRegion(n){let t=[];for(let a of this.obstacles){let{left:o,right:l,top:p,bottom:x}=a;o<=n.maxX&&l>=n.minX&&p<=n.maxY&&x>=n.minY&&t.push(a)}return t}};function HPt(n){if(n.length<4)return n;let t=[{...n[0]}],a=n[0].layer;for(let o=1;o<n.length;o++){let l={start:n[o-1],end:n[o]},p=n[o].route_type==="via"||n[o-1].route_type==="via";if(n[o].layer!==a||p){t.push({...n[o]}),a=n[o].layer;continue}let x=!1,m=null,g=-1;for(let F=0;F<t.length-1;F++){let C={start:t[F],end:t[F+1]};if(C.start.layer===l.start.layer&&C.start.layer===l.start.layer){let S=YPt(C,l);if(S){x=!0,m={...S,layer:a},g=F;break}}}x&&m&&(t.splice(g+1),t.push(m));let _=t[t.length-1];(_.x!==n[o].x||_.y!==n[o].y)&&t.push(n[o])}return t}function YPt(n,t){if(n.start.x===n.end.x&&t.start.x===t.end.x||n.start.y===n.end.y&&t.start.y===t.end.y)return null;let a;if(n.start.x===n.end.x){let o=n.start.x,l=t.start.y;a={...n.start,x:o,y:l}}else{let o=t.start.x,l=n.start.y;a={...n.start,x:o,y:l}}return aEe(a,n)&&aEe(a,t)?a:null}function aEe(n,t){return n.x>=Math.min(t.start.x,t.end.x)&&n.x<=Math.max(t.start.x,t.end.x)&&n.y>=Math.min(t.start.y,t.end.y)&&n.y<=Math.max(t.start.y,t.end.y)}function XPt(n){let t=[n[0]];for(let a=1;a<n.length-1;a++){let[o,l,p]=[n[a-1],n[a],n[a+1]];t.push(l),!(l.route_type!=="wire"||o.route_type!=="wire"||p.route_type!=="wire")&&o.layer===l.layer&&l.layer!==p.layer&&t.push({route_type:"via",from_layer:l.layer,to_layer:p.layer,x:l.x,y:l.y})}return t.push(n[n.length-1]),t}var Qnr=(0,pEe.default)("autorouter:shortenPathWithShortcuts");function WPt(n,t){if(n.length<=2)return n;let a=[n[0]];for(let o=1;o<n.length;o++){let l={start:a[a.length-1],end:n[o]},p=-1,x=l.start.x===l.end.x,m=l.start.y===l.end.y;for(let g=o+1;g<n.length;g++){if(g<=p)continue;let _={start:n[g],end:n[g+1]};if(!_.end)continue;let F=_.start.x===_.end.x,C=_.start.y===_.end.y,S=x&&F,P=m&&C;if(P&&S||!(S||P))continue;let q=!1,X=Math.min(l.start.x,l.end.x),Q=Math.max(l.start.x,l.end.x),ee=Math.min(_.start.x,_.end.x),ue=Math.max(_.start.x,_.end.x),ce=Math.min(l.start.y,l.end.y),fe=Math.max(l.start.y,l.end.y),U=Math.min(_.start.y,_.end.y),me=Math.max(_.start.y,_.end.y);if(P?q=X<=ue&&Q>=ee:S&&(q=ce<=me&&fe>=U),!q)continue;let W=[],pe=a[a.length-1],he=n[g+2];if(!he)continue;P&&ee<Q&&he.x===ee&&W.push({x:ee,y:l.start.y,layer:l.start.layer}),P&&ue>X&&he.x===ue&&W.push({x:ue,y:l.start.y,layer:l.start.layer}),S&&U<fe&&he.y===U&&W.push({x:l.start.x,y:U,layer:l.start.layer}),S&&me>ce&&he.y===me&&W.push({x:l.start.x,y:me,layer:l.start.layer});let Ae=null;for(let de of W)if(!(t(pe,de)||t(he,de))){Ae=de;break}if(Ae){a.push(Ae),o=g+1,p=g+1;break}}p===-1&&a.push(n[o])}return a[a.length-1]!==n[n.length-1]&&a.push(n[n.length-1]),a}var Eg=(0,uEe.default)("autorouting-dataset:astar"),xEe=class{constructor(n){J(this,"openSet",[]);J(this,"closedSet",new Set);J(this,"debug",!1);J(this,"debugSolutions");J(this,"debugMessage",null);J(this,"debugTraceCount",0);J(this,"input");J(this,"obstacles");J(this,"allObstacles");J(this,"startNode");J(this,"goalPoint");J(this,"GRID_STEP");J(this,"OBSTACLE_MARGIN");J(this,"MAX_ITERATIONS");J(this,"isRemovePathLoopsEnabled");J(this,"isShortenPathWithShortcutsEnabled");J(this,"GREEDY_MULTIPLIER",1.1);J(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??Eg.enabled,this.isRemovePathLoopsEnabled=n.isRemovePathLoopsEnabled??!1,this.isShortenPathWithShortcutsEnabled=n.isShortenPathWithShortcutsEnabled??!1,this.debug&&(Eg.enabled=!0),Eg.enabled&&(this.debugSolutions={},this.debugMessage="")}getNeighbors(n){return[]}isSameNode(n,t){return Cg(n,t)<this.GRID_STEP}computeG(n,t){return n.g+Cg(n,t)}computeH(n){return Cg(n,this.goalPoint)}getNodeName(n){return cEe(n,this.GRID_STEP)}solveOneStep(){this.iterations+=1;let{openSet:n,closedSet:t,GRID_STEP:a,goalPoint:o}=this;n.sort((m,g)=>m.f-g.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 m of this.getNeighbors(l)){if(t.has(this.getNodeName(m)))continue;let g=this.computeG(l,m),_=this.openSet.find(F=>this.isSameNode(F,m));if(!_||g<_.g){let F=this.computeH(m),C=g+F*this.GREEDY_MULTIPLIER,S={...m,g,h:F,f:C,obstacleHit:m.obstacleHit??void 0,manDistFromParent:Cg(l,m),nodesInPath:l.nodesInPath+1,parent:l,enterMarginCost:m.enterMarginCost,travelMarginCostFactor:m.travelMarginCostFactor};n.push(S),x.push(S)}}return Eg.enabled&&(n.sort((m,g)=>m.f-g.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:t}=n;for(this.iterations=0,this.closedSet=new Set,this.startNode=this.getStartNode(n),this.goalPoint={...t[t.length-1],l:this.layerToIndex(t[t.length-1].layer)},this.openSet=[this.startNode];this.iterations<this.MAX_ITERATIONS;){let{solved:a,current:o}=this.solveOneStep();if(a){let l=[],p=o;for(;p;){let x=p.l;l.unshift({x:p.x,y:p.y,layer:x!==void 0?this.indexToLayer(x):t[0].layer}),p=p.parent}return Eg.enabled&&(this.debugMessage+=`t${this.debugTraceCount}: ${this.iterations} iterations
|
|
954
954
|
`),this.isRemovePathLoopsEnabled&&(l=HPt(l)),this.isShortenPathWithShortcutsEnabled&&(l=WPt(l,(x,m)=>{if(x.x===m.x&&x.y===m.y)return!1;let g=this.obstacles.getOrthoDirectionCollisionInfo({x:x.x,y:x.y,l:this.layerToIndex(x.layer)??0},{dx:Math.sign(m.x-x.x),dy:Math.sign(m.y-x.y),dl:0},{margin:.05}),_=Math.sqrt((x.x-m.x)**2+(x.y-m.y)**2);return g.wallDistance<_})),{solved:!0,route:l,connectionName:n.name}}if(this.openSet.length===0)break}return Eg.enabled&&(this.debugMessage+=`t${this.debugTraceCount}: ${this.iterations} iterations (failed)
|
|
955
955
|
`),{solved:!1,connectionName:n.name}}createObstacleList({dominantLayer:n,connection:t,obstaclesFromTraces:a}){return new dEe(this.allObstacles.filter(o=>!o.connectedTo.includes(t.name)).filter(o=>o.layers.includes(n)).concat(a??[]))}postprocessConnectionSolveResult(n,t){return t}solve(){let n=[],t=[];this.debugTraceCount=0;for(let a of this.input.connections){let o=a.pointsToConnect[0].layer??"top";this.debugTraceCount+=1,this.obstacles=this.createObstacleList({dominantLayer:o,connection:a,obstaclesFromTraces:t});let l=this.solveConnection(a);l=this.postprocessConnectionSolveResult(a,l),n.push(l),Eg.enabled&&this.drawDebugTraceObstacles(t),l.solved&&t.push(...lEe(l.route.map(p=>({x:p.x,y:p.y,layer:p.layer??o})),a.name))}return n}solveAndMapToTraces(){return this.solve().flatMap(t=>t.solved?[{type:"pcb_trace",pcb_trace_id:`pcb_trace_for_${t.connectionName}`,route:XPt(t.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:t,debugSolutions:a}=this;for(let o in a)o.startsWith(`t${t}_`)&&a[o].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:t}){let a=this.getDebugGroup();if(!a)return;let{openSet:o,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 m=0;m<o.length;m++){let g=o[m];x.push({type:"pcb_fabrication_note_path",pcb_component_id:"",pcb_fabrication_note_path_id:`note_path_${g.x}_${g.y}`,layer:"top",route:[[0,.05],[.05,0],[0,-.05],[-.05,0],[0,.05]].map(([_,F])=>({x:g.x+_,y:g.y+F})),stroke_width:.01}),x.push({type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:`debug_note_${g.x}_${g.y}`,font:"tscircuit2024",font_size:.03,text:m.toString(),pcb_component_id:"",layer:"top",anchor_position:{x:g.x,y:g.y},anchor_alignment:"center"})}if(n.parent){let m=[],g=n;for(;g;)m.unshift(g),g=g.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:m,stroke_width:.01})}}},KPt=(0,fEe.default)("autorouting-dataset:infinite-grid-ijump-astar:get-distance-to-overcome-obstacle");function oY({node:n,travelDir:t,wallDir:a,obstacle:o,obstacles:l,obstaclesInRow:p=0,OBSTACLE_MARGIN:x=.15,SHOULD_DETECT_CONJOINED_OBSTACLES:m=!1,MAX_CONJOINED_OBSTACLES:g=20}){let _;if(t.dx===0?t.dy>0?_=o.center.y+o.height/2-n.y:_=n.y-(o.center.y-o.height/2):t.dx>0?_=o.center.x+o.width/2-n.x:_=n.x-(o.center.x-o.width/2),_+=x,m&&p<g){let F=l.getObstacleAt(n.x+t.dx*_+a.dx*(a.wallDistance+.001),n.y+t.dy*_+a.dy*(a.wallDistance+.001));if(F===o)return _;if(F&&F.type==="rect"){let C=t.dy===0,S=C?o.height:o.width;if((C?F.height:F.width)>S)return KPt("next obstacle on path is bigger, not trying to overcome it"),_;let k=oY({node:{x:n.x+t.dx*_,y:n.y+t.dy*_},travelDir:t,wallDir:a,obstacle:F,obstacles:l,obstaclesInRow:p+1,SHOULD_DETECT_CONJOINED_OBSTACLES:m,MAX_CONJOINED_OBSTACLES:g,OBSTACLE_MARGIN:x});_+=k}}return _}var JPt=class extends xEe{constructor(){super(...arguments);J(this,"MAX_ITERATIONS",200)}getNeighbors(t){let a=this.obstacles,o=this.goalPoint,l;t.parent?l=rEe(t.parent,t):l=rEe(t,o);let p=[{dx:0,dy:1},{dx:1,dy:0},{dx:0,dy:-1},{dx:-1,dy:0}].filter(m=>m.dx===l.dx*-1&&m.dy===l.dy*-1?!1:!(m.dx===l.dx&&m.dy===l.dy&&t.parent?.obstacleHit)).map(m=>a.getOrthoDirectionCollisionInfo(t,m,{margin:this.OBSTACLE_MARGIN})).filter(m=>m.wallDistance>=this.OBSTACLE_MARGIN),x=[];for(let m of p){let g=null;t?.obstacleHit&&(g=oY({node:t,travelDir:m,wallDir:{...l,wallDistance:this.OBSTACLE_MARGIN},obstacle:t.obstacleHit,obstacles:a,OBSTACLE_MARGIN:this.OBSTACLE_MARGIN,SHOULD_DETECT_CONJOINED_OBSTACLES:!0}));let _=oEe(t,o,m),F=(m.dx===0||Math.sign(o.x-t.x)===m.dx)&&(m.dy===0||Math.sign(o.y-t.y)===m.dy);_<m.wallDistance&&_>0&&F?x.push({...m,travelDistance:_}):g!==null&&g<m.wallDistance?x.push({...m,travelDistance:g}):m.wallDistance!==1/0&&x.push({...m,travelDistance:m.wallDistance-this.OBSTACLE_MARGIN})}return x.filter(m=>!a.isObstacleAt(t.x+m.dx*m.travelDistance,t.y+m.dy*m.travelDistance)).map(m=>({x:t.x+m.dx*m.travelDistance,y:t.y+m.dy*m.travelDistance,obstacleHit:m.obstacle}))}};function ZPt(n,t=4){let{center:a,width:o,height:l,rotation:p}=n,x=[],m=p*Math.PI/180,g=Math.cos(m),_=Math.sin(m),F=(p%360+360)%360;if(l<=o?F>=45&&F<135||F>=225&&F<315:F>=135&&F<225||F>=315||F<45){let S=o/t;for(let P=0;P<t;P++){let k=(P-t/2+.5)*S,q=-k*g,X=-k*_,Q=S*1.1,ee=Math.abs(l*g)+Math.abs(S*_);x.push({center:{x:a.x+q,y:a.y+X},width:Q,height:ee})}}else{let S=l/t;for(let P=0;P<t;P++){let k=(P-t/2+.5)*S,q=-k*_,X=k*g,Q=Math.abs(o*g)+Math.abs(S*_),ee=S*1.1;x.push({center:{x:a.x+q,y:a.y+X},width:Q,height:ee})}}return x}var VA=["top","inner1","inner2","bottom"],mEe=(n,t)=>{let a=l=>t?l.concat(l.map(p=>t?.getNetConnectedToId(p)).filter(Boolean)):l,o=[];for(let l of n)if(l.type==="pcb_smtpad"){if(l.shape==="circle")o.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")o.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=ZPt(p);for(let m of x)o.push({type:"rect",layers:[l.layer],center:m.center,width:m.width,height:m.height,connectedTo:a([l.pcb_smtpad_id])})}}else if(l.type==="pcb_keepout")l.shape==="circle"?o.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"&&o.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"?o.push({type:"oval",center:{x:l.x,y:l.y},width:l.hole_width,height:l.hole_height,connectedTo:[]}):l.hole_shape==="square"?o.push({type:"rect",layers:VA,center:{x:l.x,y:l.y},width:l.hole_diameter,height:l.hole_diameter,connectedTo:[]}):(l.hole_shape==="round"||l.hole_shape==="circle")&&o.push({type:"rect",layers:VA,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"?o.push({type:"oval",layers:VA,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")&&o.push({type:"oval",layers:VA,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=lEe(l.route.map(x=>({x:x.x,y:x.y,layer:"layer"in x?x.layer:x.from_layer})),l.source_trace_id);o.push(...p)}else l.type==="pcb_via"&&o.push({type:"rect",layers:l.layers,center:{x:l.x,y:l.y},connectedTo:[],width:l.outer_diameter,height:l.outer_diameter});return o};function iEe(n){let{pcbConnMap:t,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 o=t.getAllTracesConnectedToPort(a);return mEe(o).map(l=>({...l,connectedTo:[a]}))}var hEe=n=>{let{connection:t,pcbConnMap:a}=n;if(t.pointsToConnect.length!==2)throw new Error(`Connection must have exactly 2 points for alternative goal boxes (got ${t.pointsToConnect.length})`);let[o,l]=t.pointsToConnect;if(!o.pcb_port_id||!l.pcb_port_id)throw new Error(`Connection points must have pcb_port_id for alternative goal box calculation (got ${o.pcb_port_id} and ${l.pcb_port_id})`);let p=iEe({goalElementId:o.pcb_port_id,pcbConnMap:a}).concat([{center:o,width:.01,height:.01,connectedTo:[o.pcb_port_id],layers:[o.layer],type:"rect"}]),x=iEe({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{...t,startPoint:o,endPoint:l,goalBoxes:[]};let m=nb(p,x),g,_,F;return p.length>=x.length?(g={...l,...m.pointB},_={...o,...m.pointA},F=p):(g={...o,...m.pointA},_={...l,...m.pointB},F=x),{startPoint:g,endPoint:_,goalBoxes:F,name:t.name,pointsToConnect:[g,_]}},QPt=(n,t={})=>{let a={minTraceWidth:.1};a.layerCount=t.layerCount??1,a.obstacles=mEe(n,t.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 m=Yve(n).pcb_port.getWhere({source_port_id:x});if(!m)throw new Error(`Could not find pcb_port for source_port_id "${x}"`);return{x:m.x,y:m.y,layer:m.layers?.[0]??"top",pcb_port_id:m.pcb_port_id}})};if(t.optimizeWithGoalBoxes){let x=new UA(n);p=hEe({connection:p,pcbConnMap:x})}a.connections.push(p),ekt(a.obstacles,p.pointsToConnect,p.name)}let o={minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0};for(let l of a.obstacles)o.minX=Math.min(o.minX,l.center.x-l.width/2),o.maxX=Math.max(o.maxX,l.center.x+l.width/2),o.minY=Math.min(o.minY,l.center.y-l.height/2),o.maxY=Math.max(o.maxY,l.center.y+l.height/2);for(let l of a.connections)for(let p of l.pointsToConnect)o.minX=Math.min(o.minX,p.x),o.maxX=Math.max(o.maxX,p.x),o.minY=Math.min(o.minY,p.y),o.maxY=Math.max(o.maxY,p.y);return a.bounds=o,a},ekt=(n,t,a)=>{for(let o of t)for(let l of n)tkt(o,l)&&l.connectedTo.push(a)};function tkt(n,t){let a=t.width/2,o=t.height/2;if(t.type==="rect")return n.x>=t.center.x-a&&n.x<=t.center.x+a&&n.y>=t.center.y-o&&n.y<=t.center.y+o;if(t.type==="oval"){let l=(n.x-t.center.x)/a,p=(n.y-t.center.y)/o;return l*l+p*p<=1}return!1}function sEe(n,t){let a=t.x>n.x?1:t.x<n.x?-1:0,o=t.y>n.y?1:t.y<n.y?-1:0,l=t.l>n.l?1:t.l<n.l?-1:0;return{dx:a,dy:o,dl:l}}var cY={1:["top"],2:["top","bottom"],4:["top","inner1","inner2","bottom"]},rkt=n=>cY[n];function yEe(n,t){let o=cY[n].indexOf(t);if(o===-1)throw new Error(`Invalid layer for getLayerIndex (for layerCount === ${n}): "${t}"`);return o}function nkt(n,t){let o=cY[n][t];if(!o)throw new Error(`Invalid index for indexToLayer (for layerCount === ${n}): "${t}"`);return o}var akt=class extends dEe{constructor(t,a){super([]);J(this,"obstacles");J(this,"GRID_STEP",.1);J(this,"layerCount");this.layerCount=t;let o=rkt(t);this.obstacles=a.flatMap(l=>l.layers.filter(p=>o.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:yEe(t,p)})))}getObstacleAt(t,a,o,l){l??(l=this.GRID_STEP);for(let p of this.obstacles){if(p.l!==o)continue;let x=p.width/2+l,m=p.height/2+l;if(t>=p.center.x-x&&t<=p.center.x+x&&a>=p.center.y-m&&a<=p.center.y+m)return p}return null}isObstacleAt(t,a,o,l){return this.getObstacleAt(t,a,o,l)!==null}getDirectionDistancesToNearestObstacle3d(t,a,o){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===o&&x.type==="rect"){let m=x.center.x-x.width/2-l,g=x.center.x+x.width/2+l,_=x.center.y+x.height/2+l,F=x.center.y-x.height/2-l;a>=F&&a<=_&&t>m&&(p.left=Math.min(p.left,t-g)),a>=F&&a<=_&&t<g&&(p.right=Math.min(p.right,m-t)),t>=m&&t<=g&&a<_&&(p.top=Math.min(p.top,F-a)),t>=m&&t<=g&&a>F&&(p.bottom=Math.min(p.bottom,a-_))}return p}getOrthoDirectionCollisionInfo(t,a,{margin:o=0}={}){let{x:l,y:p,l:x}=t,{dx:m,dy:g,dl:_}=a,F=1/0,C=null;if(_!==0){let S=x+_;return this.isObstacleAt(l,p,S,o)?(F=1,C=this.getObstacleAt(l,p,S,o)):F=1,{dx:m,dy:g,dl:_,wallDistance:F,obstacle:C}}else{for(let S of this.obstacles){if(S.l!==x)continue;let P=S.left-o,k=S.right+o,q=S.top+o,X=S.bottom-o,Q=null;m===1&&g===0?p>X&&p<q&&l<S.left&&(Q=S.left-l):m===-1&&g===0?p>X&&p<q&&l>S.right&&(Q=l-S.right):m===0&&g===1?l>P&&l<k&&p<S.bottom&&(Q=S.bottom-p):m===0&&g===-1&&l>P&&l<k&&p>S.top&&(Q=p-S.top),Q!==null&&Q<F&&(F=Q,C=S)}return{dx:m,dy:g,dl:0,wallDistance:F,obstacle:C}}}getObstaclesOverlappingRegion(t){let a=[];for(let o of this.obstacles){if(o.l!==t.l)continue;let{left:l,right:p,top:x,bottom:m}=o;l<=t.maxX&&p>=t.minX&&x>=t.minY&&m<=t.maxY&&a.push(o)}return a}},GA=class extends xEe{constructor(t){super(t);J(this,"MAX_ITERATIONS",500);J(this,"VIA_COST",4);J(this,"VIA_DIAMETER",.5);J(this,"allowLayerChange",!0);J(this,"layerCount");J(this,"obstacles");J(this,"optimizeWithGoalBoxes");J(this,"connMap");J(this,"pcbConnMap");J(this,"GOAL_RUSH_FACTOR",1.1);J(this,"defaultGoalViaMargin",.5);J(this,"marginsWithCosts");this.layerCount=t.input.layerCount??2,this.MAX_ITERATIONS=t.MAX_ITERATIONS??this.MAX_ITERATIONS,this.VIA_COST=t.VIA_COST??this.VIA_COST,this.connMap=t.connMap,this.pcbConnMap=t.pcbConnMap??new UA,this.optimizeWithGoalBoxes=t.optimizeWithGoalBoxes??!1,this.obstacles=null,this.marginsWithCosts=t.marginsWithCosts??[{margin:1,enterCost:0,travelCostFactor:1},{margin:this.OBSTACLE_MARGIN,enterCost:10,travelCostFactor:2}]}get largestMargin(){return this.marginsWithCosts[0].margin}preprocessConnectionBeforeSolving(t){return this.optimizeWithGoalBoxes?hEe({connection:t,pcbConnMap:this.pcbConnMap}):t}postprocessConnectionSolveResult(t,a){if(!a.solved)return a;if(this.optimizeWithGoalBoxes){let o=a.route.map(l=>({x:l.x,y:l.y,route_type:"wire",layer:l.layer,width:this.input.minTraceWidth}));o[0].start_pcb_port_id=t.pointsToConnect[0].pcb_port_id,o[o.length-1].end_pcb_port_id=t.pointsToConnect[1].pcb_port_id,this.pcbConnMap.addTrace({type:"pcb_trace",pcb_trace_id:`postprocess_trace_${CC(8)}`,route:o})}return a}createObstacleList({dominantLayer:t,connection:a,obstaclesFromTraces:o}){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 akt(this.layerCount,this.allObstacles.filter(p=>!p.connectedTo.includes(l)).concat(o??[]))}computeG(t,a){let o=t.g+Cg(t,a)*(t.travelMarginCostFactor??1)+(a.enterMarginCost??0);return(a.l??t.l!==-1??-1)&&(o+=this.VIA_COST),o}computeH(t){let a=Math.abs(t.x-this.goalPoint.x),o=Math.abs(t.y-this.goalPoint.y),l=Math.abs(t.l-this.goalPoint.l);return(a+o)**this.GOAL_RUSH_FACTOR+l*this.VIA_COST}getStartNode(t){return{...super.getStartNode(t),l:this.layerToIndex(t.pointsToConnect[0].layer)}}layerToIndex(t){return yEe(this.layerCount,t)}indexToLayer(t){return nkt(this.layerCount,t)}getNodeName(t){return`${cEe(t,this.GRID_STEP)}-${t.l??0}`}hasSpaceForVia(t,a){return t.every(o=>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:o}).length===0)}getNeighborsSurroundingGoal(t){let a=this.obstacles,o=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 m of p){let g={x:t.x+m.dx*x,y:t.y+m.dy*x,l:t.l+m.dl,obstacleHit:null};this.hasSpaceForVia([t.l,o.l],g)&&l.push(g)}return l}getNeighbors(t){let a=this.obstacles,o=this.goalPoint,l=Cg(t,o);if(l<=this.OBSTACLE_MARGIN)return this.getNeighborsSurroundingGoal(t);let p;t.parent?p=sEe(t.parent,t):p=sEe(t,o);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}],m=l>this.VIA_DIAMETER+this.OBSTACLE_MARGIN,g=Cg(t,this.startNode)>this.VIA_DIAMETER+this.OBSTACLE_MARGIN;this.allowLayerChange&&m&&g&&(t.l<this.layerCount-1&&x.push({dx:0,dy:0,dl:1}),t.l>0&&x.push({dx:0,dy:0,dl:-1}));let _=x.filter(C=>C.dx===p.dx*-1&&C.dy===p.dy*-1&&C.dl===p.dl*-1?!1:!(C.dx===p.dx&&C.dy===p.dy&&C.dl===p.dl&&t.parent?.obstacleHit)).map(C=>a.getOrthoDirectionCollisionInfo(t,C,{margin:this.OBSTACLE_MARGIN})).filter(C=>!(C.wallDistance<this.OBSTACLE_MARGIN)),F=[];for(let C of _){let S=C.dx===0&&C.dy===0&&C.dl===1,P=C.dx===0&&C.dy===0&&C.dl===-1;if((S||P)&&![t.l,t.l+C.dl].every(ee=>a.getObstaclesOverlappingRegion({minX:t.x-this.VIA_DIAMETER/2-this.OBSTACLE_MARGIN,minY:t.y-this.VIA_DIAMETER/2-this.OBSTACLE_MARGIN,maxX:t.x+this.VIA_DIAMETER/2+this.OBSTACLE_MARGIN,maxY:t.y+this.VIA_DIAMETER/2+this.OBSTACLE_MARGIN,l:ee}).length===0))continue;if(S){t.l<this.layerCount-1&&F.push({...C,travelDistance:0,enterMarginCost:0,travelMarginCostFactor:1});continue}if(P){t.l>0&&F.push({...C,travelDistance:0,enterMarginCost:0,travelMarginCostFactor:1});continue}let k=null;t?.obstacleHit&&(k=oY({node:t,travelDir:C,wallDir:{...p,wallDistance:this.OBSTACLE_MARGIN},obstacle:t.obstacleHit,obstacles:a,OBSTACLE_MARGIN:this.OBSTACLE_MARGIN,SHOULD_DETECT_CONJOINED_OBSTACLES:!0}));let q=oEe(t,o,C),X=(C.dx===0||Math.sign(o.x-t.x)===C.dx)&&(C.dy===0||Math.sign(o.y-t.y)===C.dy);if(q<C.wallDistance&&q>0&&X){let Q=t.l===o.l,ee=0;!Q&&Math.abs(q-l)<this.GRID_STEP&&(ee=this.VIA_DIAMETER+this.OBSTACLE_MARGIN+this.defaultGoalViaMargin),F.push({...C,travelDistance:q-ee,enterMarginCost:0,travelMarginCostFactor:1})}else if(k!==null&&k<C.wallDistance){for(let{margin:Q,enterCost:ee,travelCostFactor:ue}of this.marginsWithCosts)k-this.OBSTACLE_MARGIN+Q*2<C.wallDistance&&F.push({...C,travelDistance:k-this.OBSTACLE_MARGIN+Q,enterMarginCost:ee,travelMarginCostFactor:ue});if(C.wallDistance===1/0)F.push({...C,travelDistance:q,enterMarginCost:0,travelMarginCostFactor:1});else if(C.wallDistance>this.largestMargin)for(let{margin:Q,enterCost:ee,travelCostFactor:ue}of this.marginsWithCosts)C.wallDistance>this.largestMargin+Q&&F.push({...C,travelDistance:C.wallDistance-Q,enterMarginCost:ee,travelMarginCostFactor:ue})}else if(C.wallDistance!==1/0)for(let{margin:Q,enterCost:ee,travelCostFactor:ue}of this.marginsWithCosts)C.wallDistance>Q&&F.push({...C,travelDistance:C.wallDistance-Q,enterMarginCost:ee,travelMarginCostFactor:ue})}return F.map(C=>({x:t.x+C.dx*C.travelDistance,y:t.y+C.dy*C.travelDistance,l:t.l+C.dl,obstacleHit:C.obstacle,travelMarginCostFactor:C.travelMarginCostFactor,enterMarginCost:C.enterMarginCost}))}};function gEe(n){let t=QPt(n),a=new JPt({input:t});return{solution:a.solveAndMapToTraces(),debugSolutions:a.debugSolutions,debugMessage:a.debugMessage}}et();et();or();et();et();or();et();et();et();et();or();et();et();et();or();or();et();et();et();et();et();et();et();et();et();et();et();or();et();or();et();or();or();or();et();or();et();et();et();or();et();et();or();et();or();et();or();et();or();et();or();et();or();et();or();et();et();et();or();et();et();et();et();et();or();et();or();et();et();or();et();et();or();et();or();et();et();or();et();et();et();et();or();et();or();et();or();et();or();et();or();et();et();or();et();or();or();et();et();or();et();or();et();et();or();et();or();et();or();et();or();et();or();et();or();et();or();or();et();or();et();or();et();et();et();var Ar=n=>{};Ar("extra props b");Ar("missing props b");Ar(!0);Ar("property a has mismatched types");var ikt=E.enum(["up","down","left","right"]),yar=E.enum(["top-to-bottom","left-to-right","bottom-to-top","right-to-left"]);Ar(!0);Ar(!0);var nx=E.array(E.string().or(E.number()));Ar(!0);var DEe=E.object({x:Je,y:Je,z:Je}),skt=E.object({x:E.union([E.number(),E.string()]),y:E.union([E.number(),E.string()]),z:E.union([E.number(),E.string()])}),lY=E.object({rotationOffset:E.number().or(skt).optional(),positionOffset:DEe.optional(),size:DEe.optional()});Ar(!0);var okt=lY.extend({stlUrl:E.string()}),ckt=lY.extend({objUrl:E.string(),mtlUrl:E.string().optional()}),ukt=lY.extend({jscad:E.record(E.any())}),lkt=E.union([E.null(),E.string(),okt,ckt,ukt]);Ar(!0);var dkt=E.custom(n=>!0),Fi=E.object({pcbX:Je.optional(),pcbY:Je.optional(),pcbRotation:ws.optional(),layer:Zn.optional(),pcbRelative:E.boolean().optional(),relative:E.boolean().optional()});Ar(!0);var XA=E.object({pcbX:Je.optional(),pcbY:Je.optional(),pcbRotation:ws.optional(),schX:Je.optional(),schY:Je.optional(),schRotation:ws.optional(),layer:Zn.optional(),footprint:dkt.optional(),relative:E.boolean().optional(),schRelative:E.boolean().optional(),pcbRelative:E.boolean().optional()});Ar(!0);var pkt=E.object({supplierPartNumbers:E.record(E2,E.array(E.string())).optional()});Ar(!0);var xkt=E.object({providesPower:E.boolean().optional(),requiresPower:E.boolean().optional(),providesGround:E.boolean().optional(),requiresGround:E.boolean().optional(),providesVoltage:E.union([E.string(),E.number()]).optional(),requiresVoltage:E.union([E.string(),E.number()]).optional()});Ar(!0);var co=XA.merge(pkt).extend({key:E.any().optional(),name:E.string(),cadModel:lkt.optional(),children:E.any().optional(),symbolName:E.string().optional(),doNotPlace:E.boolean().optional(),pinAttributes:E.record(E.string(),xkt).optional()});Ar(!0);var vEe=["pin1","left","pin2","right"],WA=["pin1","left","anode","pos","pin2","right","cathode","neg"],Aar=Je.or(E.enum(["2x","3x","4x"])),Tm=E.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)");Ar(!0);var HA=E.object({pins:E.array(E.union([E.number(),E.string()])),direction:E.union([E.literal("top-to-bottom"),E.literal("left-to-right"),E.literal("bottom-to-top"),E.literal("right-to-left")])}),ib=E.object({leftSize:E.number().optional().describe("@deprecated, use leftPinCount"),topSize:E.number().optional().describe("@deprecated, use topPinCount"),rightSize:E.number().optional().describe("@deprecated, use rightPinCount"),bottomSize:E.number().optional().describe("@deprecated, use bottomPinCount"),leftPinCount:E.number().optional(),rightPinCount:E.number().optional(),topPinCount:E.number().optional(),bottomPinCount:E.number().optional(),leftSide:HA.optional(),rightSide:HA.optional(),topSide:HA.optional(),bottomSide:HA.optional()}),fkt=ib;Ar(!0);var KA=E.record(E.object({marginLeft:Je.optional(),marginRight:Je.optional(),marginTop:Je.optional(),marginBottom:Je.optional(),leftMargin:Je.optional(),rightMargin:Je.optional(),topMargin:Je.optional(),bottomMargin:Je.optional()}));Ar(!0);var kd=E.string().regex(/^[A-Za-z0-9_]+$/),sb=E.object({x:Je,y:Je}),ob=E.object({edit_event_id:E.string(),in_progress:E.boolean().optional(),created_at:E.number()});Ar(!0);var mkt=ob.extend({pcb_edit_event_type:E.literal("edit_component_location").describe("deprecated"),edit_event_type:E.literal("edit_pcb_component_location"),pcb_component_id:E.string(),original_center:E.object({x:E.number(),y:E.number()}),new_center:E.object({x:E.number(),y:E.number()})});Ar(!0);var hkt=ob.extend({pcb_edit_event_type:E.literal("edit_trace_hint").describe("deprecated"),edit_event_type:E.literal("edit_pcb_trace_hint").optional(),pcb_port_id:E.string(),pcb_trace_hint_id:E.string().optional(),route:E.array(E.object({x:E.number(),y:E.number(),via:E.boolean().optional()}))});Ar(!0);var ykt=ob.extend({edit_event_type:E.literal("edit_schematic_component_location"),schematic_component_id:E.string(),original_center:E.object({x:E.number(),y:E.number()}),new_center:E.object({x:E.number(),y:E.number()})});Ar(!0);var qar=ob.extend({edit_event_type:E.literal("edit_pcb_group_location"),pcb_group_id:E.string(),original_center:E.object({x:E.number(),y:E.number()}),new_center:E.object({x:E.number(),y:E.number()})});Ar(!0);var Var=ob.extend({edit_event_type:E.literal("edit_schematic_group_location"),schematic_group_id:E.string(),original_center:E.object({x:E.number(),y:E.number()}),new_center:E.object({x:E.number(),y:E.number()})});Ar(!0);var Har=E.union([mkt,hkt,ykt]);Ar(!0);var gkt=E.object({selector:E.string(),relative_to:E.string().optional().default("group_center").describe("Can be a selector or 'group_center'"),center:Qn});Ar(!0);var Dkt=E.object({pcb_port_selector:E.string(),offsets:E.array(yc)});Ar(!0);var _kt=E.object({selector:E.string(),relative_to:E.string().optional().default("group_center").describe("Can be a selector or 'group_center'"),center:Qn});Ar(!0);var bkt=E.object({pcb_placements:E.array(gkt).optional(),manual_trace_hints:E.array(Dkt).optional(),schematic_placements:E.array(_kt).optional()});Ar(!0);var ab=E.object({layoutMode:E.enum(["grid","flex","match-adapt","relative","none"]).optional(),position:E.enum(["absolute","relative"]).optional(),grid:E.boolean().optional(),gridCols:E.number().or(E.string()).optional(),gridRows:E.number().or(E.string()).optional(),gridTemplateRows:E.string().optional(),gridTemplateColumns:E.string().optional(),gridTemplate:E.string().optional(),gridGap:E.number().or(E.string()).optional(),gridRowGap:E.number().or(E.string()).optional(),gridColumnGap:E.number().or(E.string()).optional(),flex:E.boolean().or(E.string()).optional(),flexDirection:E.enum(["row","column"]).optional(),alignItems:E.enum(["start","center","end","stretch"]).optional(),justifyContent:E.enum(["start","center","end","stretch","space-between","space-around","space-evenly"]).optional(),flexRow:E.boolean().optional(),flexColumn:E.boolean().optional(),gap:E.number().or(E.string()).optional(),pack:E.boolean().optional().describe("Pack the contents of this group using a packing strategy"),packOrderStrategy:E.enum(["largest_to_smallest","first_to_last","highest_to_lowest_pin_count"]).optional(),packPlacementStrategy:E.enum(["shortest_connection_along_outline"]).optional(),padding:ge.optional(),paddingLeft:ge.optional(),paddingRight:ge.optional(),paddingTop:ge.optional(),paddingBottom:ge.optional(),paddingX:ge.optional(),paddingY:ge.optional(),width:ge.optional(),height:ge.optional(),matchAdapt:E.boolean().optional(),matchAdaptTemplate:E.any().optional()});Ar(!0);var _Ee=E.object({strokeWidth:ge.optional(),dashed:E.boolean().optional(),solid:E.boolean().optional()}),Fkt=E.object({serverUrl:E.string().optional(),inputFormat:E.enum(["simplified","circuit-json"]).optional(),serverMode:E.enum(["job","solve-endpoint"]).optional(),serverCacheEnabled:E.boolean().optional(),cache:E.custom(n=>!0).optional(),traceClearance:ge.optional(),groupMode:E.enum(["sequential-trace","subcircuit"]).optional(),algorithmFn:E.custom(n=>typeof n=="function"||n===void 0).optional(),preset:E.enum(["sequential-trace","subcircuit","auto","auto-local","auto-cloud"]).optional(),local:E.boolean().optional()}),EEe=E.union([Fkt,E.literal("sequential-trace"),E.literal("subcircuit"),E.literal("auto"),E.literal("auto-local"),E.literal("auto-cloud")]),CEe=XA.extend({name:E.string().optional(),children:E.any().optional(),schTitle:E.string().optional(),key:E.any().optional(),...ab.shape,grid:ab.shape.grid.describe("@deprecated use pcbGrid"),flex:ab.shape.flex.describe("@deprecated use pcbFlex"),pcbGrid:E.boolean().optional(),pcbGridCols:E.number().or(E.string()).optional(),pcbGridRows:E.number().or(E.string()).optional(),pcbGridTemplateRows:E.string().optional(),pcbGridTemplateColumns:E.string().optional(),pcbGridTemplate:E.string().optional(),pcbGridGap:E.number().or(E.string()).optional(),pcbGridRowGap:E.number().or(E.string()).optional(),pcbGridColumnGap:E.number().or(E.string()).optional(),pcbFlex:E.boolean().or(E.string()).optional(),pcbFlexGap:E.number().or(E.string()).optional(),pcbFlexDirection:E.enum(["row","column"]).optional(),pcbAlignItems:E.enum(["start","center","end","stretch"]).optional(),pcbJustifyContent:E.enum(["start","center","end","stretch","space-between","space-around","space-evenly"]).optional(),pcbFlexRow:E.boolean().optional(),pcbFlexColumn:E.boolean().optional(),pcbGap:E.number().or(E.string()).optional(),pcbPack:E.boolean().optional(),schGrid:E.boolean().optional(),schGridCols:E.number().or(E.string()).optional(),schGridRows:E.number().or(E.string()).optional(),schGridTemplateRows:E.string().optional(),schGridTemplateColumns:E.string().optional(),schGridTemplate:E.string().optional(),schGridGap:E.number().or(E.string()).optional(),schGridRowGap:E.number().or(E.string()).optional(),schGridColumnGap:E.number().or(E.string()).optional(),schFlex:E.boolean().or(E.string()).optional(),schFlexGap:E.number().or(E.string()).optional(),schFlexDirection:E.enum(["row","column"]).optional(),schAlignItems:E.enum(["start","center","end","stretch"]).optional(),schJustifyContent:E.enum(["start","center","end","stretch","space-between","space-around","space-evenly"]).optional(),schFlexRow:E.boolean().optional(),schFlexColumn:E.boolean().optional(),schGap:E.number().or(E.string()).optional(),schPack:E.boolean().optional(),schMatchAdapt:E.boolean().optional(),pcbWidth:ge.optional(),pcbHeight:ge.optional(),schWidth:ge.optional(),schHeight:ge.optional(),pcbLayout:ab.optional(),schLayout:ab.optional(),cellBorder:_Ee.nullable().optional(),border:_Ee.nullable().optional(),schPadding:ge.optional(),schPaddingLeft:ge.optional(),schPaddingRight:ge.optional(),schPaddingTop:ge.optional(),schPaddingBottom:ge.optional(),pcbPadding:ge.optional(),pcbPaddingLeft:ge.optional(),pcbPaddingRight:ge.optional(),pcbPaddingTop:ge.optional(),pcbPaddingBottom:ge.optional()}),AEe=E.custom(n=>"findPart"in n),dY=CEe.extend({manualEdits:bkt.optional(),schAutoLayoutEnabled:E.boolean().optional(),schTraceAutoLabelEnabled:E.boolean().optional(),routingDisabled:E.boolean().optional(),defaultTraceWidth:ge.optional(),minTraceWidth:ge.optional(),partsEngine:AEe.optional(),pcbRouteCache:E.custom(n=>!0).optional(),autorouter:EEe.optional(),square:E.boolean().optional(),emptyArea:E.string().optional(),filledArea:E.string().optional(),width:Je.optional(),height:Je.optional(),outline:E.array(sb).optional(),outlineOffsetX:Je.optional(),outlineOffsetY:Je.optional()}),vkt=dY.extend({subcircuit:E.literal(!0)}),REe=E.discriminatedUnion("subcircuit",[CEe.extend({subcircuit:E.literal(!1).optional()}),vkt]);Ar(!0);Ar(!0);Ar(!0);var pY=dY.extend({material:E.enum(["fr4","fr1"]).default("fr4"),layers:E.union([E.literal(2),E.literal(4)]).default(2)});Ar(!0);var tir=dY.extend({padding:Je.optional(),paddingLeft:Je.optional(),paddingRight:Je.optional(),paddingTop:Je.optional(),paddingBottom:Je.optional()});Ar(!0);var Ekt=E.string().or(E.array(E.string()).readonly()).or(E.array(E.string())),Ckt=E.custom().pipe(E.record(E.string(),Ekt)),Akt=E.record(kd,kd.or(E.array(kd).readonly()).or(E.array(kd)));Ar(!0);var Rkt=E.object({manufacturerPartNumber:E.string().optional(),supplierPartNumber:E.record(E2,E.array(E.string())).optional()}),xY=co.extend({manufacturerPartNumber:E.string().optional(),pinLabels:Akt.optional(),showPinAliases:E.boolean().optional(),pcbPinLabels:E.record(E.string(),E.string()).optional(),internallyConnectedPins:E.array(E.array(E.string())).optional(),externallyConnectedPins:E.array(E.array(E.string())).optional(),schPinArrangement:ib.optional(),schPortArrangement:ib.optional(),pinCompatibleVariants:E.array(Rkt).optional(),schPinStyle:KA.optional(),schPinSpacing:Je.optional(),schWidth:Je.optional(),schHeight:Je.optional(),noSchematicRepresentation:E.boolean().optional(),connections:Ckt.optional()});Ar(!0);var fY=E.string().or(E.array(E.string()).readonly()).or(E.array(E.string())),cb=n=>E.record(E.enum(n),fY),mY=co.extend({manufacturerPartNumber:E.string().optional(),pinLabels:E.record(E.number().or(kd),kd.or(E.array(kd))).optional(),schPinStyle:KA.optional(),schPinSpacing:Je.optional(),schWidth:Je.optional(),schHeight:Je.optional(),schDirection:E.enum(["left","right"]).optional(),schPortArrangement:ib.optional(),pcbPinLabels:E.record(E.string(),E.string()).optional(),pinCount:E.union([E.literal(2),E.literal(3)]).optional(),internallyConnectedPins:E.array(E.array(E.string())).optional(),connections:E.custom().pipe(E.record(E.string(),fY)).optional()});Ar(!0);var IEe=mY.extend({bridgedPins:E.array(E.array(E.string())).optional(),bridged:E.boolean().optional()});Ar(!0);var lir=co.extend({manufacturerPartNumber:E.string().optional(),pinLabels:E.record(E.number().or(kd),kd.or(E.array(kd))).optional(),schPinStyle:KA.optional(),schPinSpacing:Je.optional(),schWidth:Je.optional(),schHeight:Je.optional(),schDirection:E.enum(["left","right"]).optional(),schPortArrangement:ib.optional(),internallyConnectedPins:E.array(E.array(E.string())).optional(),standard:E.enum(["usb_c","m2"]).optional()});Ar(!0);var wEe=co.extend({currentRating:E.union([E.number(),E.string()]),voltageRating:E.union([E.number(),E.string()]).optional(),schShowRatings:E.boolean().optional(),schOrientation:Tm.optional(),connections:E.record(E.string(),E.union([E.string(),E.array(E.string()).readonly(),E.array(E.string())])).optional()}),YA=E.custom().transform(n=>{if(n!==void 0)return Je.parse(n)}),SEe=E.discriminatedUnion("shape",[Fi.omit({pcbRotation:!0,layer:!0}).extend({name:E.string().optional(),connectsTo:E.string().or(E.array(E.string())).optional(),shape:E.literal("circle"),holeDiameter:Je,outerDiameter:Je,portHints:nx.optional()}),Fi.omit({pcbRotation:!0,layer:!0}).extend({name:E.string().optional(),connectsTo:E.string().or(E.array(E.string())).optional(),shape:E.literal("oval"),outerWidth:Je,outerHeight:Je,holeWidth:YA,holeHeight:YA,innerWidth:Je.optional().describe("DEPRECATED use holeWidth"),innerHeight:Je.optional().describe("DEPRECATED use holeHeight"),portHints:nx.optional()}),Fi.omit({layer:!0}).extend({name:E.string().optional(),connectsTo:E.string().or(E.array(E.string())).optional(),shape:E.literal("pill"),rectPad:E.boolean().optional(),outerWidth:Je,outerHeight:Je,holeWidth:YA,holeHeight:YA,innerWidth:Je.optional().describe("DEPRECATED use holeWidth"),innerHeight:Je.optional().describe("DEPRECATED use holeHeight"),portHints:nx.optional()}),Fi.omit({pcbRotation:!0,layer:!0}).extend({name:E.string().optional(),connectsTo:E.string().or(E.array(E.string())).optional(),shape:E.literal("circular_hole_with_rect_pad"),holeDiameter:Je,rectPadWidth:Je,rectPadHeight:Je,holeShape:E.literal("circle").optional(),padShape:E.literal("rect").optional(),portHints:nx.optional()}),Fi.omit({pcbRotation:!0,layer:!0}).extend({name:E.string().optional(),connectsTo:E.string().or(E.array(E.string())).optional(),shape:E.literal("pill_hole_with_rect_pad"),holeShape:E.literal("pill"),padShape:E.literal("rect"),holeWidth:Je,holeHeight:Je,rectPadWidth:Je,rectPadHeight:Je,portHints:nx.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));Ar(!0);var Ikt=["pin1","pin2","pos","neg"],BEe=co.extend({resistance:vm,pullupFor:E.string().optional(),pullupTo:E.string().optional(),pulldownFor:E.string().optional(),pulldownTo:E.string().optional(),schOrientation:Tm.optional(),connections:cb(Ikt).optional()}),TEe=vEe;Ar(!0);var PEe=co.extend({maxResistance:vm,pinVariant:E.enum(["two_pin","three_pin"]).optional()});Ar(!0);var wkt=vEe,kEe=co.extend({frequency:v2,loadCapacitance:Cf,pinVariant:E.enum(["two_pin","four_pin"]).optional(),schOrientation:Tm.optional(),connections:cb(wkt).optional()});Ar(!0);var jEe=co.extend({frequency:v2,loadCapacitance:Cf,pinVariant:E.enum(["no_ground","ground_pin","two_ground_pins"]).optional()});Ar(!0);var Eir=pY.extend({leftPinCount:E.number().optional(),rightPinCount:E.number().optional(),topPinCount:E.number().optional(),bottomPinCount:E.number().optional(),leftPins:E.array(E.string()).optional(),rightPins:E.array(E.string()).optional(),topPins:E.array(E.string()).optional(),bottomPins:E.array(E.string()).optional(),pinPitch:Je.optional(),innerHoles:E.boolean().optional()});Ar(!0);var Skt=["pin1","pin2","pos","neg","anode","cathode"],NEe=co.extend({capacitance:Cf,maxVoltageRating:Af.optional(),schShowRatings:E.boolean().optional().default(!1),polarized:E.boolean().optional().default(!1),decouplingFor:E.string().optional(),decouplingTo:E.string().optional(),bypassFor:E.string().optional(),bypassTo:E.string().optional(),maxDecouplingTraceLength:E.number().optional(),schOrientation:Tm.optional(),connections:cb(Skt).optional()}),MEe=WA;Ar(!0);var Iir=E.object({name:E.string(),connectsTo:E.string().or(E.array(E.string())).optional()});Ar(!0);var Sir=E.object({name:E.string().optional(),pcbOnly:E.boolean().optional(),schOnly:E.boolean().optional()});Ar(!0);var Bkt=E.object({pcb:E.literal(!0).optional(),xDist:Je,left:E.string(),right:E.string(),edgeToEdge:E.literal(!0).optional(),centerToCenter:E.literal(!0).optional()});Ar(!0);var Tkt=E.object({pcb:E.literal(!0).optional(),yDist:Je,top:E.string(),bottom:E.string(),edgeToEdge:E.literal(!0).optional(),centerToCenter:E.literal(!0).optional()});Ar(!0);var Pkt=E.object({pcb:E.literal(!0).optional(),sameY:E.literal(!0).optional(),for:E.array(E.string())});Ar(!0);var kkt=E.object({pcb:E.literal(!0).optional(),sameX:E.literal(!0).optional(),for:E.array(E.string())});Ar(!0);var OEe=E.union([Bkt,Tkt,Pkt,kkt]);Ar(!0);var jkt=Fi.omit({layer:!0,pcbRotation:!0}).extend({name:E.string().optional(),shape:E.literal("rect"),width:Je,height:Je});Ar(!0);var Nkt=Fi.omit({layer:!0,pcbRotation:!0}).extend({name:E.string().optional(),shape:E.literal("circle"),radius:Je});Ar(!0);var Mkt=Fi.omit({layer:!0,pcbRotation:!0}).extend({name:E.string().optional(),shape:E.literal("polygon"),points:E.array(sb)});Ar(!0);var LEe=E.discriminatedUnion("shape",[jkt,Nkt,Mkt]),Okt=Fi.omit({pcbRotation:!0}).extend({name:E.string().optional(),shape:E.literal("rect"),width:Je,height:Je,portHints:nx.optional()});Ar(!0);var Lkt=Fi.omit({pcbRotation:!0}).extend({name:E.string().optional(),shape:E.literal("rotated_rect"),width:Je,height:Je,ccwRotation:E.number(),portHints:nx.optional()});Ar(!0);var zkt=Fi.omit({pcbRotation:!0}).extend({name:E.string().optional(),shape:E.literal("circle"),radius:Je,portHints:nx.optional()});Ar(!0);var $kt=Fi.omit({pcbRotation:!0}).extend({name:E.string().optional(),shape:E.literal("pill"),width:Je,height:Je,radius:Je,portHints:nx.optional()});Ar(!0);var qkt=Fi.omit({pcbRotation:!0}).extend({name:E.string().optional(),shape:E.literal("polygon"),points:E.array(sb),portHints:nx.optional()});Ar(!0);var zEe=E.discriminatedUnion("shape",[zkt,Okt,Lkt,$kt,qkt]);Ar(!0);var Ukt=Fi.omit({pcbRotation:!0}).extend({shape:E.literal("rect"),width:Je,height:Je});Ar(!0);var Vkt=Fi.omit({pcbRotation:!0}).extend({shape:E.literal("circle"),radius:Je});Ar(!0);var Mir=E.union([Vkt,Ukt]);Ar(!0);var $Ee=Fi.omit({pcbRotation:!0}).extend({name:E.string().optional(),diameter:Je.optional(),radius:Je.optional()}).transform(n=>({...n,diameter:n.diameter??2*n.radius,radius:n.radius??n.diameter/2}));Ar(!0);var uY=E.union([E.string(),E.custom(n=>!!n.getPortSelector)]),bEe=E.object({key:E.string().optional(),thickness:Je.optional(),schematicRouteHints:E.array(sb).optional(),pcbRouteHints:E.array(yc).optional(),pcbPathRelativeTo:E.string().optional(),pcbPath:E.array(sb).optional(),schDisplayLabel:E.string().optional(),maxLength:Je.optional()}),qEe=E.union([bEe.extend({path:E.array(uY)}),bEe.extend({from:uY,to:uY})]),UEe=E.object({originalLayer:Zn.default("top").optional()});Ar(!0);var Gkt=E.number().or(E.string().endsWith("mAh")).transform(n=>{if(typeof n=="string"){let t=n.replace("mAh",""),a=Number.parseFloat(t);if(Number.isNaN(a))throw new Error("Invalid capacity");return a}return n}).describe("Battery capacity in mAh"),VEe=co.extend({capacity:Gkt.optional(),schOrientation:Tm.optional()});Ar(!0);var GEe=co.extend({pinCount:E.number(),pitch:Je.optional(),schFacingDirection:E.enum(["up","down","left","right"]).optional(),gender:E.enum(["male","female","unpopulated"]).optional().default("male"),showSilkscreenPinLabels:E.boolean().optional(),pcbPinLabels:E.record(E.string(),E.string()).optional(),doubleRow:E.boolean().optional(),rightAngle:E.boolean().optional(),holeDiameter:Je.optional(),platedDiameter:Je.optional(),pinLabels:E.array(kd).optional(),connections:E.custom().pipe(E.record(E.string(),fY)).optional(),facingDirection:E.enum(["left","right"]).optional(),schPinArrangement:fkt.optional(),schPinStyle:KA.optional(),schPinSpacing:Je.optional(),schWidth:Je.optional(),schHeight:Je.optional()});Ar(!0);var Xir=E.object({net:E.string().optional(),connection:E.string().optional(),schX:Je.optional(),schY:Je.optional(),schRotation:ws.optional(),anchorSide:E.enum(["left","top","right","bottom"]).optional()});Ar(!0);var HEe=E.object({net:E.string().optional(),connection:E.string().optional(),connectsTo:E.string().or(E.array(E.string())).optional(),schX:Je.optional(),schY:Je.optional(),schRotation:ws.optional(),anchorSide:E.enum(["left","top","right","bottom"]).optional()});Ar(!0);var YEe=xY.extend({});Ar(!0);Ar(!0);var Hkt=["pin1","pin2","pin3","emitter","collector","base","gate","source","drain"],XEe=co.extend({type:E.enum(["npn","pnp","bjt","jfet","mosfet","igbt"]),connections:cb(Hkt).optional()});Ar(!0);var WEe=co.extend({channelType:E.enum(["n","p"]),mosfetMode:E.enum(["enhancement","depletion"])});Ar(!0);var KEe=co.extend({inductance:AC,maxCurrentRating:E.union([E.string(),E.number()]).optional(),schOrientation:Tm.optional()});Ar(!0);var Ykt=E.enum(["anode","cathode","pin1","pin2","pos","neg"]),Xkt=E.string().or(E.array(E.string()).readonly()).or(E.array(E.string())),Wkt=E.record(Ykt,Xkt),Kkt=E.enum(["standard","schottky","zener","avalanche","photo","tvs"]),JEe=co.extend({connections:Wkt.optional(),variant:Kkt.optional().default("standard"),standard:E.boolean().optional(),schottky:E.boolean().optional(),zener:E.boolean().optional(),avalanche:E.boolean().optional(),photo:E.boolean().optional(),tvs:E.boolean().optional(),schOrientation:Tm.optional()}).superRefine((n,t)=>{if([n.standard,n.schottky,n.zener,n.avalanche,n.photo,n.tvs].filter(Boolean).length>1)return t.addIssue({code:E.ZodIssueCode.custom,message:"Exactly one diode variant must be enabled",path:[]}),E.INVALID}).transform(n=>{let t={...n,standard:!1,schottky:!1,zener:!1,avalanche:!1,photo:!1,tvs:!1};if(n.standard)t.standard=!0;else if(n.schottky)t.schottky=!0;else if(n.zener)t.zener=!0;else if(n.photo)t.photo=!0;else if(n.tvs)t.tvs=!0;else switch(n.variant){case"standard":t.standard=!0;break;case"schottky":t.schottky=!0;break;case"zener":t.zener=!0;break;case"avalanche":t.avalanche=!0;break;case"photo":t.photo=!0;break;case"tvs":t.tvs=!0;break;default:t.standard=!0}return t}),ZEe=WA;Ar(!0);var QEe=co.extend({color:E.string().optional(),wavelength:E.string().optional(),schDisplayValue:E.string().optional(),schOrientation:Tm.optional(),connections:cb(WA).optional(),laser:E.boolean().optional()}),e4e=WA,t4e=co.extend({type:E.enum(["spst","spdt","dpst","dpdt"]).optional(),isNormallyClosed:E.boolean().optional().default(!1),spst:E.boolean().optional(),spdt:E.boolean().optional(),dpst:E.boolean().optional(),dpdt:E.boolean().optional()}).transform(n=>{let t={...n};switch(t.dpdt?t.type="dpdt":t.spst?t.type="spst":t.spdt?t.type="spdt":t.dpst&&(t.type="dpst"),t.type){case"spdt":t.spdt=!0;break;case"spst":t.spst=!0;break;case"dpst":t.dpst=!0;break;case"dpdt":t.dpdt=!0;break}return t});Ar(!0);var r4e=Fi.extend({text:E.string(),anchorAlignment:E.enum(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),font:E.enum(["tscircuit2024"]).optional(),fontSize:ge.optional(),color:E.string().optional()}),n4e=Fi.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({route:E.array(yc),strokeWidth:ge.optional(),color:E.string().optional()}),lsr=E.object({layer:E.string().optional(),thickness:Je.optional(),route:E.array(yc)}),a4e=XA.extend({name:E.string().optional(),fromLayer:Zn,toLayer:Zn,holeDiameter:Je,outerDiameter:Je,connectsTo:E.string().or(E.array(E.string())).optional()});Ar(!0);var i4e=co.extend({footprintVariant:E.enum(["pad","through_hole"]).optional(),padShape:E.enum(["rect","circle"]).optional().default("circle"),padDiameter:Je.optional(),holeDiameter:Je.optional(),width:Je.optional(),height:Je.optional()}).refine(n=>n.footprintVariant!=="through_hole"||n.holeDiameter!==void 0,{message:"holeDiameter is required for through_hole testpoints"});Ar(!0);var s4e=Fi.omit({pcbRotation:!0,layer:!0}).extend({connection:E.string()});Ar(!0);var o4e=E.union([Fi.omit({pcbRotation:!0}).extend({shape:E.literal("circle"),radius:Je}),Fi.extend({shape:E.literal("rect"),width:Je,height:Je})]),c4e=co.extend({voltage:Af}),JA=E.enum(["top_left","top_center","top_right","center_left","center","center_right","bottom_left","bottom_center","bottom_right"]),u4e=E.object({schX:Je.optional(),schY:Je.optional(),width:Je.optional(),height:Je.optional(),overlay:E.array(E.string()).optional(),padding:Je.optional(),paddingLeft:Je.optional(),paddingRight:Je.optional(),paddingTop:Je.optional(),paddingBottom:Je.optional(),title:E.string().optional(),titleAlignment:JA.default("top_left"),titleColor:E.string().optional(),titleFontSize:Je.optional(),titleInside:E.boolean().default(!1),strokeStyle:E.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."}),Esr=E.object({x1:Je,y1:Je,x2:Je,y2:Je}),Jkt=E.enum(["center","left","right","top","bottom"]),l4e=E.object({schX:Je.optional(),schY:Je.optional(),text:E.string(),fontSize:E.number().default(1),anchor:E.union([Jkt.describe("legacy"),JA]).default("center"),color:E.string().default("#000000"),schRotation:ws.default(0)}),Ssr=E.object({points:E.array(Qn),isFilled:E.boolean().optional().default(!1),fillColor:E.enum(["red","blue"]).optional()}),d4e=E.object({schX:Je.optional(),schY:Je.optional(),children:E.any().optional(),cellPadding:Je.optional(),borderWidth:Je.optional(),anchor:JA.optional(),fontSize:Je.optional()});Ar(!0);var p4e=E.object({children:E.any().optional(),height:Je.optional()});Ar(!0);var x4e=E.object({children:E.string().optional(),horizontalAlign:E.enum(["left","center","right"]).optional(),verticalAlign:E.enum(["top","middle","bottom"]).optional(),fontSize:Je.optional(),rowSpan:E.number().optional(),colSpan:E.number().optional(),width:Je.optional(),text:E.string().optional()});Ar(!0);var f4e=Fi.extend({text:E.string(),anchorAlignment:JA.default("center"),font:E.enum(["tscircuit2024"]).optional(),fontSize:ge.optional()}),m4e=Fi.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({route:E.array(yc),strokeWidth:ge.optional()}),h4e=Fi.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({strokeWidth:Je,x1:Je,y1:Je,x2:Je,y2:Je}),y4e=Fi.omit({pcbRotation:!0}).extend({filled:E.boolean().default(!0).optional(),stroke:E.enum(["dashed","solid","none"]).optional(),strokeWidth:Je.optional(),width:Je,height:Je}),g4e=Fi.omit({pcbRotation:!0}).extend({isFilled:E.boolean().optional(),isOutline:E.boolean().optional(),strokeWidth:Je.optional(),radius:Je}),FEe=E.object({x:Je,y:Je,via:E.boolean().optional(),toLayer:Zn.optional()}),D4e=E.object({for:E.string().optional().describe("Selector for the port you're targeting, not required if you're inside a trace"),order:E.number().optional(),offset:yc.or(FEe).optional(),offsets:E.array(yc).or(E.array(FEe)).optional(),traceWidth:E.number().optional()}),Wsr=XA.extend({name:E.string(),pinNumber:E.number().optional(),aliases:E.array(E.string()).optional(),direction:ikt}),Zkt=E.array(E.any()).describe("Circuit JSON"),Qkt=E.function().args(E.string()).returns(E.promise(E.object({footprintCircuitJson:E.array(E.any())}))).describe("A function that takes a path and returns Circuit JSON"),Jsr=E.object({partsEngine:AEe.optional(),autorouter:EEe.optional(),registryApiUrl:E.string().optional(),cloudAutorouterUrl:E.string().optional(),projectName:E.string().optional(),version:E.string().optional(),url:E.string().optional(),printBoardInformationToSilkscreen:E.boolean().optional(),localCacheEngine:E.any().optional(),pcbDisabled:E.boolean().optional(),schematicDisabled:E.boolean().optional(),partsEngineDisabled:E.boolean().optional(),footprintLibraryMap:E.record(E.string(),E.record(E.string(),E.union([Zkt,Qkt]))).optional()});Ar(!0);et();or();Bf();et();var Vg=Cr(ju(),1);Bf();et();function Pm(){return new hY}var hY=class n{constructor(){J(this,"index",{});J(this,"array",[])}size(){return this.array.length}empty(){return this.array.length===0}itemAt(t){return this.array[t]}contains(t){return this.index[t.id()]!==void 0}find(t){let a=this.index[t.id()];return a===void 0?void 0:this.array[a]}setDefault(t,a){let o=this.index[t.id()];if(o===void 0){let l=new ZA(t,a());return this.index[t.id()]=this.array.length,this.array.push(l),l}else return this.array[o]}insert(t,a){let o=new ZA(t,a),l=this.index[t.id()];return l===void 0?(this.index[t.id()]=this.array.length,this.array.push(o)):this.array[l]=o,o}erase(t){let a=this.index[t.id()];if(a===void 0)return;this.index[t.id()]=void 0;let o=this.array[a],l=this.array.pop();return o!==l&&(this.array[a]=l,this.index[l.first.id()]=a),o}copy(){let t=new n;for(let a=0;a<this.array.length;a++){let o=this.array[a].copy();t.array[a]=o,t.index[o.first.id()]=a}return t}},ZA=class n{constructor(t,a){J(this,"first");J(this,"second");this.first=t,this.second=a}copy(){return new n(this.first,this.second)}};var Ag=class{constructor(t=""){J(this,"_name");J(this,"_value",0);J(this,"_context",null);J(this,"_id",ejt++);this._name=t}id(){return this._id}name(){return this._name}setName(t){this._name=t}context(){return this._context}setContext(t){this._context=t}value(){return this._value}setValue(t){this._value=t}plus(t){return new Vs(this,t)}minus(t){return new Vs(this,typeof t=="number"?-t:[-1,t])}multiply(t){return new Vs([t,this])}divide(t){return new Vs([1/t,this])}toJSON(){return{name:this._name,value:this._value}}toString(){return this._context+"["+this._name+":"+this._value+"]"}},ejt=0;var Vs=class n{constructor(){J(this,"_terms");J(this,"_constant");let t=tjt(arguments);this._terms=t.terms,this._constant=t.constant}terms(){return this._terms}constant(){return this._constant}value(){let t=this._constant;for(let a=0,o=this._terms.size();a<o;a++){let l=this._terms.itemAt(a);t+=l.first.value()*l.second}return t}plus(t){return new n(this,t)}minus(t){return new n(this,typeof t=="number"?-t:[-1,t])}multiply(t){return new n([t,this])}divide(t){return new n([1/t,this])}isConstant(){return this._terms.size()==0}toString(){let t=this._terms.array.map(function(a){return a.second+"*"+a.first.toString()}).join(" + ");return!this.isConstant()&&this._constant!==0&&(t+=" + "),t+=this._constant,t}};function tjt(n){let t=0,a=()=>0,o=Pm();for(let l=0,p=n.length;l<p;++l){let x=n[l];if(typeof x=="number")t+=x;else if(x instanceof Ag)o.setDefault(x,a).second+=1;else if(x instanceof Vs){t+=x.constant();let m=x.terms();for(let g=0,_=m.size();g<_;g++){let F=m.itemAt(g);o.setDefault(F.first,a).second+=F.second}}else if(x instanceof Array){if(x.length!==2)throw new Error("array must have length 2");let m=x[0],g=x[1];if(typeof m!="number")throw new Error("array item 0 must be a number");if(g instanceof Ag)o.setDefault(g,a).second+=m;else if(g instanceof Vs){t+=g.constant()*m;let _=g.terms();for(let F=0,C=_.size();F<C;F++){let S=_.itemAt(F);o.setDefault(S.first,a).second+=S.second*m}}else throw new Error("array item 1 must be a variable or expression")}else throw new Error("invalid Expression argument: "+x)}return{terms:o,constant:t}}var jd=class jd{static create(t,a,o,l=1){let p=0;return p+=Math.max(0,Math.min(1e3,t*l))*1e6,p+=Math.max(0,Math.min(1e3,a*l))*1e3,p+=Math.max(0,Math.min(1e3,o*l)),p}static clip(t){return Math.max(0,Math.min(jd.required,t))}};J(jd,"required",jd.create(1e3,1e3,1e3)),J(jd,"strong",jd.create(1,0,0)),J(jd,"medium",jd.create(0,1,0)),J(jd,"weak",jd.create(0,0,1));var uo=jd;var Dc;(function(n){n[n.Le=0]="Le",n[n.Ge=1]="Ge",n[n.Eq=2]="Eq"})(Dc||(Dc={}));var ql=class{constructor(t,a,o,l=uo.required){J(this,"_expression");J(this,"_operator");J(this,"_strength");J(this,"_id",rjt++);this._operator=a,this._strength=uo.clip(l),o===void 0&&t instanceof Vs?this._expression=t:this._expression=t.minus(o)}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()+")"}},rjt=0;var e7=class{constructor(){J(this,"maxIterations",1e3);J(this,"_cnMap",njt());J(this,"_rowMap",ajt());J(this,"_varMap",ijt());J(this,"_editMap",sjt());J(this,"_infeasibleRows",[]);J(this,"_objective",new r7);J(this,"_artificial",null);J(this,"_idTick",0)}createConstraint(t,a,o,l=uo.required){let p=new ql(t,a,o,l);return this.addConstraint(p),p}addConstraint(t){if(this._cnMap.find(t)!==void 0)throw new Error("duplicate constraint");let o=this._createRow(t),l=o.row,p=o.tag,x=this._chooseSubject(l,p);if(x.type()===Ta.Invalid&&l.allDummies())if(QA(l.constant()))x=p.marker;else throw new Error("unsatisfiable constraint");if(x.type()===Ta.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(t,p),this._optimize(this._objective)}removeConstraint(t){let a=this._cnMap.erase(t);if(a===void 0)throw new Error("unknown constraint");this._removeConstraintEffects(t,a.second);let o=a.second.marker,l=this._rowMap.erase(o);if(l===void 0){let p=this._getMarkerLeavingSymbol(o);if(p.type()===Ta.Invalid)throw new Error("failed to find leaving row");l=this._rowMap.erase(p),l.second.solveForEx(p,o),this._substitute(o,l.second)}this._optimize(this._objective)}hasConstraint(t){return this._cnMap.contains(t)}getConstraints(){return this._cnMap.array.map(({first:t})=>t)}addEditVariable(t,a){if(this._editMap.find(t)!==void 0)throw new Error("duplicate edit variable");if(a=uo.clip(a),a===uo.required)throw new Error("bad required strength");let l=new Vs(t),p=new ql(l,Dc.Eq,void 0,a);this.addConstraint(p);let m={tag:this._cnMap.find(p).second,constraint:p,constant:0};this._editMap.insert(t,m)}removeEditVariable(t){let a=this._editMap.erase(t);if(a===void 0)throw new Error("unknown edit variable");this.removeConstraint(a.second.constraint)}hasEditVariable(t){return this._editMap.contains(t)}suggestValue(t,a){let o=this._editMap.find(t);if(o===void 0)throw new Error("unknown edit variable");let l=this._rowMap,p=o.second,x=a-p.constant;p.constant=a;let m=p.tag.marker,g=l.find(m);if(g!==void 0){g.second.add(-x)<0&&this._infeasibleRows.push(m),this._dualOptimize();return}let _=p.tag.other;if(g=l.find(_),g!==void 0){g.second.add(x)<0&&this._infeasibleRows.push(_),this._dualOptimize();return}for(let F=0,C=l.size();F<C;++F){let S=l.itemAt(F),P=S.second,k=P.coefficientFor(m);k!==0&&P.add(x*k)<0&&S.first.type()!==Ta.External&&this._infeasibleRows.push(S.first)}this._dualOptimize()}updateVariables(){let t=this._varMap,a=this._rowMap;for(let o=0,l=t.size();o<l;++o){let p=t.itemAt(o),x=a.find(p.second);x!==void 0?p.first.setValue(x.second.constant()):p.first.setValue(0)}}_getVarSymbol(t){let a=()=>this._makeSymbol(Ta.External);return this._varMap.setDefault(t,a).second}_createRow(t){let a=t.expression(),o=new r7(a.constant()),l=a.terms();for(let g=0,_=l.size();g<_;++g){let F=l.itemAt(g);if(!QA(F.second)){let C=this._getVarSymbol(F.first),S=this._rowMap.find(C);S!==void 0?o.insertRow(S.second,F.second):o.insertSymbol(C,F.second)}}let p=this._objective,x=t.strength(),m={marker:km,other:km};switch(t.op()){case Dc.Le:case Dc.Ge:{let g=t.op()===Dc.Le?1:-1,_=this._makeSymbol(Ta.Slack);if(m.marker=_,o.insertSymbol(_,g),x<uo.required){let F=this._makeSymbol(Ta.Error);m.other=F,o.insertSymbol(F,-g),p.insertSymbol(F,x)}break}case Dc.Eq:{if(x<uo.required){let g=this._makeSymbol(Ta.Error),_=this._makeSymbol(Ta.Error);m.marker=g,m.other=_,o.insertSymbol(g,-1),o.insertSymbol(_,1),p.insertSymbol(g,x),p.insertSymbol(_,x)}else{let g=this._makeSymbol(Ta.Dummy);m.marker=g,o.insertSymbol(g)}break}}return o.constant()<0&&o.reverseSign(),{row:o,tag:m}}_chooseSubject(t,a){let o=t.cells();for(let p=0,x=o.size();p<x;++p){let m=o.itemAt(p);if(m.first.type()===Ta.External)return m.first}let l=a.marker.type();return(l===Ta.Slack||l===Ta.Error)&&t.coefficientFor(a.marker)<0?a.marker:(l=a.other.type(),(l===Ta.Slack||l===Ta.Error)&&t.coefficientFor(a.other)<0?a.other:km)}_addWithArtificialVariable(t){let a=this._makeSymbol(Ta.Slack);this._rowMap.insert(a,t.copy()),this._artificial=t.copy(),this._optimize(this._artificial);let o=QA(this._artificial.constant());this._artificial=null;let l=this._rowMap.erase(a);if(l!==void 0){let x=l.second;if(x.isConstant())return o;let m=this._anyPivotableSymbol(x);if(m.type()===Ta.Invalid)return!1;x.solveForEx(a,m),this._substitute(m,x),this._rowMap.insert(m,x)}let p=this._rowMap;for(let x=0,m=p.size();x<m;++x)p.itemAt(x).second.removeSymbol(a);return this._objective.removeSymbol(a),o}_substitute(t,a){let o=this._rowMap;for(let l=0,p=o.size();l<p;++l){let x=o.itemAt(l);x.second.substitute(t,a),x.second.constant()<0&&x.first.type()!==Ta.External&&this._infeasibleRows.push(x.first)}this._objective.substitute(t,a),this._artificial&&this._artificial.substitute(t,a)}_optimize(t){let a=0;for(;a<this.maxIterations;){let o=this._getEnteringSymbol(t);if(o.type()===Ta.Invalid)return;let l=this._getLeavingSymbol(o);if(l.type()===Ta.Invalid)throw new Error("the objective is unbounded");let p=this._rowMap.erase(l).second;p.solveForEx(l,o),this._substitute(o,p),this._rowMap.insert(o,p),a++}throw new Error("solver iterations exceeded")}_dualOptimize(){let t=this._rowMap,a=this._infeasibleRows;for(;a.length!==0;){let o=a.pop(),l=t.find(o);if(l!==void 0&&l.second.constant()<0){let p=this._getDualEnteringSymbol(l.second);if(p.type()===Ta.Invalid)throw new Error("dual optimize failed");let x=l.second;t.erase(o),x.solveForEx(o,p),this._substitute(p,x),t.insert(p,x)}}}_getEnteringSymbol(t){let a=t.cells();for(let o=0,l=a.size();o<l;++o){let p=a.itemAt(o),x=p.first;if(p.second<0&&x.type()!==Ta.Dummy)return x}return km}_getDualEnteringSymbol(t){let a=Number.MAX_VALUE,o=km,l=t.cells();for(let p=0,x=l.size();p<x;++p){let m=l.itemAt(p),g=m.first,_=m.second;if(_>0&&g.type()!==Ta.Dummy){let C=this._objective.coefficientFor(g)/_;C<a&&(a=C,o=g)}}return o}_getLeavingSymbol(t){let a=Number.MAX_VALUE,o=km,l=this._rowMap;for(let p=0,x=l.size();p<x;++p){let m=l.itemAt(p),g=m.first;if(g.type()!==Ta.External){let _=m.second,F=_.coefficientFor(t);if(F<0){let C=-_.constant()/F;C<a&&(a=C,o=g)}}}return o}_getMarkerLeavingSymbol(t){let a=Number.MAX_VALUE,o=a,l=a,p=km,x=p,m=p,g=p,_=this._rowMap;for(let F=0,C=_.size();F<C;++F){let S=_.itemAt(F),P=S.second,k=P.coefficientFor(t);if(k===0)continue;let q=S.first;if(q.type()===Ta.External)g=q;else if(k<0){let X=-P.constant()/k;X<o&&(o=X,x=q)}else{let X=P.constant()/k;X<l&&(l=X,m=q)}}return x!==p?x:m!==p?m:g}_removeConstraintEffects(t,a){a.marker.type()===Ta.Error&&this._removeMarkerEffects(a.marker,t.strength()),a.other.type()===Ta.Error&&this._removeMarkerEffects(a.other,t.strength())}_removeMarkerEffects(t,a){let o=this._rowMap.find(t);o!==void 0?this._objective.insertRow(o.second,-a):this._objective.insertSymbol(t,-a)}_anyPivotableSymbol(t){let a=t.cells();for(let o=0,l=a.size();o<l;++o){let p=a.itemAt(o),x=p.first.type();if(x===Ta.Slack||x===Ta.Error)return p.first}return km}_makeSymbol(t){return new t7(t,this._idTick++)}};function QA(n){let t=1e-8;return n<0?-n<t:n<t}function njt(){return Pm()}function ajt(){return Pm()}function ijt(){return Pm()}function sjt(){return Pm()}var Ta;(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"})(Ta||(Ta={}));var t7=class{constructor(t,a){J(this,"_id");J(this,"_type");this._id=a,this._type=t}id(){return this._id}type(){return this._type}},km=new t7(Ta.Invalid,-1),r7=class n{constructor(t=0){J(this,"_cellMap",Pm());J(this,"_constant");this._constant=t}cells(){return this._cellMap}constant(){return this._constant}isConstant(){return this._cellMap.empty()}allDummies(){let t=this._cellMap;for(let a=0,o=t.size();a<o;++a)if(t.itemAt(a).first.type()!==Ta.Dummy)return!1;return!0}copy(){let t=new n(this._constant);return t._cellMap=this._cellMap.copy(),t}add(t){return this._constant+=t}insertSymbol(t,a=1){let o=this._cellMap.setDefault(t,()=>0);QA(o.second+=a)&&this._cellMap.erase(t)}insertRow(t,a=1){this._constant+=t._constant*a;let o=t._cellMap;for(let l=0,p=o.size();l<p;++l){let x=o.itemAt(l);this.insertSymbol(x.first,x.second*a)}}removeSymbol(t){this._cellMap.erase(t)}reverseSign(){this._constant=-this._constant;let t=this._cellMap;for(let a=0,o=t.size();a<o;++a){let l=t.itemAt(a);l.second=-l.second}}solveFor(t){let a=this._cellMap,l=-1/a.erase(t).second;this._constant*=l;for(let p=0,x=a.size();p<x;++p)a.itemAt(p).second*=l}solveForEx(t,a){this.insertSymbol(t,-1),this.solveFor(a)}coefficientFor(t){let a=this._cellMap.find(t);return a!==void 0?a.second:0}substitute(t,a){let o=this._cellMap.erase(t);o!==void 0&&this.insertRow(a,o.second)}};var v7e=Cr(e0(),1);or();Nu();var yY={};qy(yY,{clamp:()=>r0,computeDistanceBetweenBoxes:()=>q2,distSq:()=>R4e,distance:()=>n0,doSegmentsIntersect:()=>ax,doesLineIntersectLine:()=>jm,findNearestPointsBetweenBoxSets:()=>nb,getBoundingBox:()=>rb,getSegmentIntersection:()=>_4e,getUnitVectorFromDirection:()=>s7,getUnitVectorFromPointAToB:()=>i7,grid:()=>v4e,midpoint:()=>A4e,onSegment:()=>V2,orientation:()=>U2,pointToBoundsDistance:()=>C4e,pointToBoxDistance:()=>E4e,pointToSegmentClosestPoint:()=>F4e,pointToSegmentDistance:()=>lo,segmentToBoundsMinDistance:()=>ub,segmentToBoxMinDistance:()=>b4e,segmentToCircleMinDistance:()=>a7,segmentToSegmentMinDistance:()=>n7});function jm([n,t],[a,o],{lineThickness:l=0}={}){return l===0?ax(n,t,a,o):cjt(n,t,a,o)<=l}function ax(n,t,a,o){let l=U2(n,t,a),p=U2(n,t,o),x=U2(a,o,n),m=U2(a,o,t);return!!(l!==p&&x!==m||l===0&&V2(n,a,t)||p===0&&V2(n,o,t)||x===0&&V2(a,n,o)||m===0&&V2(a,t,o))}function U2(n,t,a){let o=(t.y-n.y)*(a.x-t.x)-(t.x-n.x)*(a.y-t.y);return o===0?0:o>0?1:2}function V2(n,t,a){return t.x<=Math.max(n.x,a.x)&&t.x>=Math.min(n.x,a.x)&&t.y<=Math.max(n.y,a.y)&&t.y>=Math.min(n.y,a.y)}function cjt(n,t,a,o){if(n.x===t.x&&n.y===t.y)return lo(n,a,o);if(a.x===o.x&&a.y===o.y)return lo(a,n,t);if(ax(n,t,a,o))return 0;let l=[lo(n,a,o),lo(t,a,o),lo(a,n,t),lo(o,n,t)];return Math.min(...l)}function lo(n,t,a){let o=(a.x-t.x)**2+(a.y-t.y)**2;if(o===0)return n0(n,t);let l=((n.x-t.x)*(a.x-t.x)+(n.y-t.y)*(a.y-t.y))/o;l=Math.max(0,Math.min(1,l));let p={x:t.x+l*(a.x-t.x),y:t.y+l*(a.y-t.y)};return n0(n,p)}function n0(n,t){let a=n.x-t.x,o=n.y-t.y;return Math.sqrt(a*a+o*o)}function _4e(n,t,a,o){let l=t.x-n.x,p=t.y-n.y,x=o.x-a.x,m=o.y-a.y,g=n.x-a.x,_=n.y-a.y,F=l*m-p*x;if(Math.abs(F)<1e-10)return null;let C=(_*x-g*m)/F,S=(l*_-p*g)/F,P=1e-9;if(C>=-P&&C<=1+P&&S>=-P&&S<=1+P){let k=n.x+C*l,q=n.y+C*p;return{x:k,y:q}}return null}function n7(n,t,a,o){if(n.x===t.x&&n.y===t.y)return lo(n,a,o);if(a.x===o.x&&a.y===o.y)return lo(a,n,t);if(ax(n,t,a,o))return 0;let l=[lo(n,a,o),lo(t,a,o),lo(a,n,t),lo(o,n,t)];return Math.min(...l)}function ub(n,t,a){let o={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(ax(n,t,o,l)||ax(n,t,l,x)||ax(n,t,x,p)||ax(n,t,p,o)||n.x>=a.minX&&n.x<=a.maxX&&n.y>=a.minY&&n.y<=a.maxY&&t.x>=a.minX&&t.x<=a.maxX&&t.y>=a.minY&&t.y<=a.maxY)return 0;let m=[lo(o,n,t),lo(l,n,t),lo(p,n,t),lo(x,n,t)];if(n.x>=a.minX&&n.x<=a.maxX&&n.y>=a.minY&&n.y<=a.maxY||t.x>=a.minX&&t.x<=a.maxX&&t.y>=a.minY&&t.y<=a.maxY)return 0;if(n.x<a.minX||n.x>a.maxX||n.y<a.minY||n.y>a.maxY){let g=r0(n.x,a.minX,a.maxX),_=r0(n.y,a.minY,a.maxY);m.push(n0(n,{x:g,y:_}))}if(t.x<a.minX||t.x>a.maxX||t.y<a.minY||t.y>a.maxY){let g=r0(t.x,a.minX,a.maxX),_=r0(t.y,a.minY,a.maxY);m.push(n0(t,{x:g,y:_}))}return Math.min(...m)}function b4e(n,t,a){let o=a.width/2,l=a.height/2,p={minX:a.center.x-o,maxX:a.center.x+o,minY:a.center.y-l,maxY:a.center.y+l};return ub(n,t,p)}function a7(n,t,a){let o={x:a.x,y:a.y};if(n.x===t.x&&n.y===t.y)return Math.max(0,n0(n,o)-a.radius);let l={x:t.x-n.x,y:t.y-n.y},p={x:o.x-n.x,y:o.y-n.y},x=l.x*l.x+l.y*l.y,m=Math.max(0,Math.min(1,(l.x*p.x+l.y*p.y)/x)),g={x:n.x+m*l.x,y:n.y+m*l.y},_=n0(g,o);return Math.max(0,_-a.radius)}function F4e(n,t,a){let o=a.x-t.x,l=a.y-t.y,p=o*o+l*l;if(p===0)return{x:t.x,y:t.y};let x=((n.x-t.x)*o+(n.y-t.y)*l)/p;return x=Math.max(0,Math.min(1,x)),{x:t.x+x*o,y:t.y+x*l}}var i7=(n,t)=>{let a={x:t.x-n.x,y:t.y-n.y},o=Math.sqrt(a.x**2+a.y**2);return{x:a.x/o,y:a.y/o}},s7=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 v4e({rows:n,cols:t,xSpacing:a,ySpacing:o,width:l,height:p,offsetX:x=0,offsetY:m=0,yDirection:g="cartesian",centered:_=!0}){let F=a??1,C=o??1,S=l??t*F,P=p??n*C,k=_?-S/2:0,q=_?-P/2:0,X=l?l/t:F,Q=p?p/n:C,ee=[];for(let ue=0;ue<n;ue++)for(let ce=0;ce<t;ce++){let fe=ue*t+ce,U=x+k+ce*X+X/2,me=m+ue*Q+Q/2,W=g==="cartesian"?m+q+(n-1-ue)*Q+Q/2:m+q+ue*Q+Q/2;ee.push({index:fe,center:{x:U,y:W},topLeft:{x:U-X/2,y:W+Q/2},bottomRight:{x:U+X/2,y:W-Q/2},row:ue,col:ce})}return ee}function E4e(n,t){let a=t.width/2,o=t.height/2,l=t.center.x-a,p=t.center.x+a,x=t.center.y-o,m=t.center.y+o;if(n.x>=l&&n.x<=p&&n.y>=x&&n.y<=m)return 0;let g=r0(n.x,l,p),_=r0(n.y,x,m);return n0(n,{x:g,y:_})}function C4e(n,t){if(n.x>=t.minX&&n.x<=t.maxX&&n.y>=t.minY&&n.y<=t.maxY)return 0;let a=r0(n.x,t.minX,t.maxX),o=r0(n.y,t.minY,t.maxY);return n0(n,{x:a,y:o})}function A4e(n,t){return{x:(n.x+t.x)/2,y:(n.y+t.y)/2}}function R4e(n,t){let a=n.x-t.x,o=n.y-t.y;return a*a+o*o}or();var I4e=(n,t,a={})=>{let o=a?.overshoot??.1*Math.max(Math.abs(n.x-t.x),Math.abs(n.y-t.y)),l=[{x:n.x,y:n.y}],p=(n.x+t.x)/2,x=(n.y+t.y)/2,m={x:t.x,y:t.y};switch(t.facingDirection){case"x+":m.x+=o;break;case"x-":m.x-=o;break;case"y+":m.y+=o;break;case"y-":m.y-=o;break}let g=n.facingDirection??"none",_=t.facingDirection??"none",F=C=>{let S=l[l.length-1];(S.x!==C.x||S.y!==C.y)&&l.push(C)};if(g==="none"&&_==="none")F({x:p,y:n.y}),F({x:p,y:t.y});else if(g==="y+"&&_==="x-")F({x:n.x,y:t.y});else if(g==="y-"&&_==="x-")if(n.y>=t.y)F({x:n.x,y:t.y});else{let C=n.y-o;F({x:n.x,y:C}),F({x:p,y:C}),F({x:p,y:t.y}),F({x:m.x,y:t.y})}else if(g==="x-"&&_==="x+")n.x>t.x?(F({x:p,y:n.y}),F({x:p,y:t.y})):(F({x:n.x-o,y:n.y}),F({x:n.x-o,y:x}),F({x:m.x,y:x}),F({x:m.x,y:t.y}));else if(g==="y+"&&_==="y+"){let C=Math.max(n.y+o,m.y);F({x:n.x,y:C}),F({x:t.x,y:C})}else if(g==="y-"&&_==="x+")if(n.x>t.x&&n.y>=t.y)F({x:n.x,y:t.y}),F({x:t.x,y:t.y});else{let C=n.y-o;F({x:n.x,y:C}),F({x:m.x,y:C}),F({x:m.x,y:t.y})}else if(g==="y+"&&_==="x+")if(n.x>t.x&&n.y<t.y)F({x:n.x,y:t.y}),F({x:t.x,y:t.y});else{let C=n.y+o;F({x:n.x,y:C}),F({x:m.x,y:C}),F({x:m.x,y:t.y})}else if(g==="x+"&&_==="y+")if(n.x>t.x&&n.y<t.y)F({x:n.x,y:t.y}),F({x:t.x,y:t.y});else if(n.x<t.x&&n.y>t.y)F({x:t.x,y:n.y});else if(n.x===t.x)F({x:n.x+o,y:n.y}),F({x:n.x+o,y:x}),F({x:t.x,y:x});else if(n.x<t.x)F({x:p,y:n.y}),F({x:p,y:m.y}),F({x:t.x,y:m.y});else{let C=n.x+o;F({x:C,y:n.y}),F({x:C,y:m.y}),F({x:t.x,y:m.y})}else if(g==="y-"&&_==="y-"){let C=Math.min(n.y-o,m.y);F({x:n.x,y:C}),F({x:t.x,y:C})}else if(g==="x+"&&_==="x+"){let C=Math.max(n.x+o,m.x);F({x:C,y:n.y}),F({x:C,y:t.y})}else if(g==="x-"&&_==="x-"){let C=Math.min(n.x-o,m.x);F({x:C,y:n.y}),F({x:C,y:t.y})}else if(g==="x-"&&_==="y+")n.x>t.x?F({x:t.x,y:n.y}):(F({x:n.x-o,y:n.y}),F({x:n.x-o,y:m.y}),F({x:t.x,y:m.y}));else if(g==="x-"&&_==="y-")if(n.x>t.x&&n.y<=t.y)F({x:t.x,y:n.y});else{let C=n.x-o;F({x:C,y:n.y}),F({x:C,y:m.y}),F({x:m.x,y:m.y})}else if(g==="x+"&&_==="y-")n.x===t.x?(F({x:n.x+o,y:n.y}),F({x:n.x+o,y:x}),F({x:t.x,y:x})):n.x<t.x&&n.y<t.y?F({x:t.x,y:n.y}):(F({x:n.x+o,y:n.y}),F({x:n.x+o,y:m.y}),F({x:t.x,y:m.y}));else if(g==="y-"&&_==="y+")if(n.y>=t.y)F({x:n.x,y:x}),F({x:t.x,y:x});else{let C=n.y-o;F({x:n.x,y:C}),F({x:p,y:C}),F({x:p,y:m.y}),F({x:t.x,y:m.y})}else if(g==="y+"&&_==="y-")if(n.y<=t.y)F({x:n.x,y:x}),F({x:t.x,y:x});else{let C=n.y+o;F({x:n.x,y:C}),F({x:p,y:C}),F({x:p,y:m.y}),F({x:t.x,y:m.y})}else g.startsWith("x")?F({x:n.x+(g==="x+"?o:-o),y:n.y}):g.startsWith("y")&&F({x:n.x,y:n.y+(g==="y+"?o:-o)}),F({x:p,y:l[l.length-1].y}),F({x:p,y:m.y}),F({x:m.x,y:m.y});return F({x:t.x,y:t.y}),l};var w4e={name:"@tscircuit/capacity-autorouter",main:"./dist/index.js",version:"0.0.100",type:"module",files:["dist"],scripts:{start:"cosmos",build:"tsup ./lib/index.ts --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",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"}};or();Nu();var _Ce=Cr(gY(),1),vCe=Cr(gY(),1);var g7=(...n)=>{let t={points:[],lines:[],circles:[],rects:[]};return n.forEach((a,o)=>{a&&(a.lines&&(t.lines=[...t.lines||[],...a.lines.map(l=>({...l,step:o}))]),a.points&&(t.points=[...t.points||[],...a.points.map(l=>({...l,step:o}))]),a.circles&&(t.circles=[...t.circles||[],...a.circles.map(l=>({...l,step:o}))]),a.rects&&(t.rects=[...t.rects||[],...a.rects.map(l=>({...l,step:o}))]))}),t},ui=class{constructor(){J(this,"MAX_ITERATIONS",1e3);J(this,"solved",!1);J(this,"failed",!1);J(this,"iterations",0);J(this,"progress",0);J(this,"error",null);J(this,"activeSubSolver");J(this,"failedSubSolvers");J(this,"timeToSolve");J(this,"stats",{});J(this,"cacheHit");J(this,"cacheKey");J(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 t=Date.now();this.timeToSolve=t-n}visualize(){return{lines:[],points:[],rects:[],circles:[]}}tryFinalAcceptance(){}preview(){return{lines:[],points:[],rects:[],circles:[]}}};function iu(){return iu=Object.assign?Object.assign.bind():function(n){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var o in a)({}).hasOwnProperty.call(a,o)&&(n[o]=a[o])}return n},iu.apply(null,arguments)}function ljt(n){if(n===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return n}function yb(n,t){return yb=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,o){return a.__proto__=o,a},yb(n,t)}function djt(n,t){n.prototype=Object.create(t.prototype),n.prototype.constructor=n,yb(n,t)}function BY(n){return BY=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},BY(n)}function pjt(n){try{return Function.toString.call(n).indexOf("[native code]")!==-1}catch{return typeof n=="function"}}function iCe(){try{var n=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(iCe=function(){return!!n})()}function xjt(n,t,a){if(iCe())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,t);var l=new(n.bind.apply(n,o));return a&&yb(l,a.prototype),l}function TY(n){var t=typeof Map=="function"?new Map:void 0;return TY=function(o){if(o===null||!pjt(o))return o;if(typeof o!="function")throw new TypeError("Super expression must either be null or a function");if(t!==void 0){if(t.has(o))return t.get(o);t.set(o,l)}function l(){return xjt(o,arguments,BY(this).constructor)}return l.prototype=Object.create(o.prototype,{constructor:{value:l,enumerable:!1,writable:!0,configurable:!0}}),yb(l,o)},TY(n)}var au=function(n){djt(t,n);function t(a){var o;if(1)o=n.call(this,"An error occurred. See https://github.com/styled-components/polished/blob/main/src/internalHelpers/errors.md#"+a+" for more information.")||this;else for(var l,p,x;x<l;x++);return ljt(o)}return t}(TY(Error));function T4e(n,t){return n.substr(-t.length)===t}var fjt=/^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/;function P4e(n){if(typeof n!="string")return n;var t=n.match(fjt);return t?parseFloat(n):n}var mjt=function(t){return function(a,o){o===void 0&&(o="16px");var l=a,p=o;if(typeof a=="string"){if(!T4e(a,"px"))throw new au(69,t,a);l=P4e(a)}if(typeof o=="string"){if(!T4e(o,"px"))throw new au(70,t,o);p=P4e(o)}if(typeof l=="string")throw new au(71,a,t);if(typeof p=="string")throw new au(72,o,t);return""+l/p+t}},sCe=mjt,Vor=sCe("em"),Gor=sCe("rem");function DY(n){return Math.round(n*255)}function hjt(n,t,a){return DY(n)+","+DY(t)+","+DY(a)}function gb(n,t,a,o){if(o===void 0&&(o=hjt),t===0)return o(a,a,a);var l=(n%360+360)%360/60,p=(1-Math.abs(2*a-1))*t,x=p*(1-Math.abs(l%2-1)),m=0,g=0,_=0;l>=0&&l<1?(m=p,g=x):l>=1&&l<2?(m=x,g=p):l>=2&&l<3?(g=p,_=x):l>=3&&l<4?(g=x,_=p):l>=4&&l<5?(m=x,_=p):l>=5&&l<6&&(m=p,_=x);var F=a-p/2,C=m+F,S=g+F,P=_+F;return o(C,S,P)}var k4e={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"};function yjt(n){if(typeof n!="string")return n;var t=n.toLowerCase();return k4e[t]?"#"+k4e[t]:n}var gjt=/^#[a-fA-F0-9]{6}$/,Djt=/^#[a-fA-F0-9]{8}$/,_jt=/^#[a-fA-F0-9]{3}$/,bjt=/^#[a-fA-F0-9]{4}$/,_Y=/^rgb\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*\)$/i,Fjt=/^rgb(?:a)?\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i,vjt=/^hsl\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*\)$/i,Ejt=/^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 W2(n){if(typeof n!="string")throw new au(3);var t=yjt(n);if(t.match(gjt))return{red:parseInt(""+t[1]+t[2],16),green:parseInt(""+t[3]+t[4],16),blue:parseInt(""+t[5]+t[6],16)};if(t.match(Djt)){var a=parseFloat((parseInt(""+t[7]+t[8],16)/255).toFixed(2));return{red:parseInt(""+t[1]+t[2],16),green:parseInt(""+t[3]+t[4],16),blue:parseInt(""+t[5]+t[6],16),alpha:a}}if(t.match(_jt))return{red:parseInt(""+t[1]+t[1],16),green:parseInt(""+t[2]+t[2],16),blue:parseInt(""+t[3]+t[3],16)};if(t.match(bjt)){var o=parseFloat((parseInt(""+t[4]+t[4],16)/255).toFixed(2));return{red:parseInt(""+t[1]+t[1],16),green:parseInt(""+t[2]+t[2],16),blue:parseInt(""+t[3]+t[3],16),alpha:o}}var l=_Y.exec(t);if(l)return{red:parseInt(""+l[1],10),green:parseInt(""+l[2],10),blue:parseInt(""+l[3],10)};var p=Fjt.exec(t.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=vjt.exec(t);if(x){var m=parseInt(""+x[1],10),g=parseInt(""+x[2],10)/100,_=parseInt(""+x[3],10)/100,F="rgb("+gb(m,g,_)+")",C=_Y.exec(F);if(!C)throw new au(4,t,F);return{red:parseInt(""+C[1],10),green:parseInt(""+C[2],10),blue:parseInt(""+C[3],10)}}var S=Ejt.exec(t.substring(0,50));if(S){var P=parseInt(""+S[1],10),k=parseInt(""+S[2],10)/100,q=parseInt(""+S[3],10)/100,X="rgb("+gb(P,k,q)+")",Q=_Y.exec(X);if(!Q)throw new au(4,t,X);return{red:parseInt(""+Q[1],10),green:parseInt(""+Q[2],10),blue:parseInt(""+Q[3],10),alpha:parseFloat(""+S[4])>1?parseFloat(""+S[4])/100:parseFloat(""+S[4])}}throw new au(5)}function Cjt(n){var t=n.red/255,a=n.green/255,o=n.blue/255,l=Math.max(t,a,o),p=Math.min(t,a,o),x=(l+p)/2;if(l===p)return n.alpha!==void 0?{hue:0,saturation:0,lightness:x,alpha:n.alpha}:{hue:0,saturation:0,lightness:x};var m,g=l-p,_=x>.5?g/(2-l-p):g/(l+p);switch(l){case t:m=(a-o)/g+(a<o?6:0);break;case a:m=(o-t)/g+2;break;default:m=(t-a)/g+4;break}return m*=60,n.alpha!==void 0?{hue:m,saturation:_,lightness:x,alpha:n.alpha}:{hue:m,saturation:_,lightness:x}}function Om(n){return Cjt(W2(n))}var Ajt=function(t){return t.length===7&&t[1]===t[2]&&t[3]===t[4]&&t[5]===t[6]?"#"+t[1]+t[3]+t[5]:t},PY=Ajt;function Ig(n){var t=n.toString(16);return t.length===1?"0"+t:t}function bY(n){return Ig(Math.round(n*255))}function Rjt(n,t,a){return PY("#"+bY(n)+bY(t)+bY(a))}function b7(n,t,a){return gb(n,t,a,Rjt)}function Ijt(n,t,a){if(typeof n=="number"&&typeof t=="number"&&typeof a=="number")return b7(n,t,a);if(typeof n=="object"&&t===void 0&&a===void 0)return b7(n.hue,n.saturation,n.lightness);throw new au(1)}function wjt(n,t,a,o){if(typeof n=="number"&&typeof t=="number"&&typeof a=="number"&&typeof o=="number")return o>=1?b7(n,t,a):"rgba("+gb(n,t,a)+","+o+")";if(typeof n=="object"&&t===void 0&&a===void 0&&o===void 0)return n.alpha>=1?b7(n.hue,n.saturation,n.lightness):"rgba("+gb(n.hue,n.saturation,n.lightness)+","+n.alpha+")";throw new au(2)}function kY(n,t,a){if(typeof n=="number"&&typeof t=="number"&&typeof a=="number")return PY("#"+Ig(n)+Ig(t)+Ig(a));if(typeof n=="object"&&t===void 0&&a===void 0)return PY("#"+Ig(n.red)+Ig(n.green)+Ig(n.blue));throw new au(6)}function A7(n,t,a,o){if(typeof n=="string"&&typeof t=="number"){var l=W2(n);return"rgba("+l.red+","+l.green+","+l.blue+","+t+")"}else{if(typeof n=="number"&&typeof t=="number"&&typeof a=="number"&&typeof o=="number")return o>=1?kY(n,t,a):"rgba("+n+","+t+","+a+","+o+")";if(typeof n=="object"&&t===void 0&&a===void 0&&o===void 0)return n.alpha>=1?kY(n.red,n.green,n.blue):"rgba("+n.red+","+n.green+","+n.blue+","+n.alpha+")"}throw new au(7)}var Sjt=function(t){return typeof t.red=="number"&&typeof t.green=="number"&&typeof t.blue=="number"&&(typeof t.alpha!="number"||typeof t.alpha>"u")},Bjt=function(t){return typeof t.red=="number"&&typeof t.green=="number"&&typeof t.blue=="number"&&typeof t.alpha=="number"},Tjt=function(t){return typeof t.hue=="number"&&typeof t.saturation=="number"&&typeof t.lightness=="number"&&(typeof t.alpha!="number"||typeof t.alpha>"u")},Pjt=function(t){return typeof t.hue=="number"&&typeof t.saturation=="number"&&typeof t.lightness=="number"&&typeof t.alpha=="number"};function Lm(n){if(typeof n!="object")throw new au(8);if(Bjt(n))return A7(n);if(Sjt(n))return kY(n);if(Pjt(n))return wjt(n);if(Tjt(n))return Ijt(n);throw new au(8)}function oCe(n,t,a){return function(){var l=a.concat(Array.prototype.slice.call(arguments));return l.length>=t?n.apply(this,l):oCe(n,t,l)}}function Mu(n){return oCe(n,n.length,[])}function kjt(n,t){if(t==="transparent")return t;var a=Om(t);return Lm(iu({},a,{hue:a.hue+parseFloat(n)}))}var Hor=Mu(kjt);function K2(n,t,a){return Math.max(n,Math.min(t,a))}function jjt(n,t){if(t==="transparent")return t;var a=Om(t);return Lm(iu({},a,{lightness:K2(0,1,a.lightness-parseFloat(n))}))}var Yor=Mu(jjt);function Njt(n,t){if(t==="transparent")return t;var a=Om(t);return Lm(iu({},a,{saturation:K2(0,1,a.saturation-parseFloat(n))}))}var Xor=Mu(Njt);function Mjt(n,t){if(t==="transparent")return t;var a=Om(t);return Lm(iu({},a,{lightness:K2(0,1,a.lightness+parseFloat(n))}))}var Wor=Mu(Mjt);function Ojt(n,t,a){if(t==="transparent")return a;if(a==="transparent")return t;if(n===0)return a;var o=W2(t),l=iu({},o,{alpha:typeof o.alpha=="number"?o.alpha:1}),p=W2(a),x=iu({},p,{alpha:typeof p.alpha=="number"?p.alpha:1}),m=l.alpha-x.alpha,g=parseFloat(n)*2-1,_=g*m===-1?g:g+m,F=1+g*m,C=(_/F+1)/2,S=1-C,P={red:Math.floor(l.red*C+x.red*S),green:Math.floor(l.green*C+x.green*S),blue:Math.floor(l.blue*C+x.blue*S),alpha:l.alpha*parseFloat(n)+x.alpha*(1-parseFloat(n))};return A7(P)}var Ljt=Mu(Ojt),cCe=Ljt;function zjt(n,t){if(t==="transparent")return t;var a=W2(t),o=typeof a.alpha=="number"?a.alpha:1,l=iu({},a,{alpha:K2(0,1,(o*100+parseFloat(n)*100)/100)});return A7(l)}var Kor=Mu(zjt);function $jt(n,t){if(t==="transparent")return t;var a=Om(t);return Lm(iu({},a,{saturation:K2(0,1,a.saturation+parseFloat(n))}))}var Jor=Mu($jt);function qjt(n,t){return t==="transparent"?t:Lm(iu({},Om(t),{hue:parseFloat(n)}))}var Zor=Mu(qjt);function Ujt(n,t){return t==="transparent"?t:Lm(iu({},Om(t),{lightness:parseFloat(n)}))}var Qor=Mu(Ujt);function Vjt(n,t){return t==="transparent"?t:Lm(iu({},Om(t),{saturation:parseFloat(n)}))}var e0r=Mu(Vjt);function Gjt(n,t){return t==="transparent"?t:cCe(parseFloat(n),"rgb(0, 0, 0)",t)}var t0r=Mu(Gjt);function Hjt(n,t){return t==="transparent"?t:cCe(parseFloat(n),"rgb(255, 255, 255)",t)}var r0r=Mu(Hjt);function Yjt(n,t){if(t==="transparent")return t;var a=W2(t),o=typeof a.alpha=="number"?a.alpha:1,l=iu({},a,{alpha:K2(0,1,+(o*100-parseFloat(n)*100).toFixed(2)/100)});return A7(l)}var Xjt=Mu(Yjt),Wjt=Xjt,j4e=["blue","orange","purple","cyan","magenta","yellowgreen","darkgoldenrod","deeppink"],jY=(n,t)=>{let a={};for(let o=0;o<n.connections.length;o++){let l=n.connections[o],p=t?.getNetConnectedToId(l.name);p&&!a[p]&&(a[p]=`hsl(${o*300/n.connections.length}, 100%, 50%)`),a[l.name]=(p?a[p]:null)??`hsl(${o*340/n.connections.length}, 100%, 50%)`}return a},ms=(n,t)=>{try{return Wjt(t,n)}catch(a){return console.error(a),n}},Db=(n,t)=>n==="top"?0:n==="bottom"?t-1:parseInt(n.slice(5)),ix=(n,t=1)=>{let m=(("width"in n?n.width:n)/(.6/2+.2)/2)**1.1*t;return n.availableZ?.length===1&&m>1?1:m},Kjt=(n,t=.5,a=16)=>{let o=0,l=n;for(;o<a&&!(ix({width:l})<=t);)l/=2,o++;return Math.max(1,o)};function uCe(n,t,a=0,o=n.length-1,l=Jjt){for(;o>a;){if(o-a>600){let g=o-a+1,_=t-a+1,F=Math.log(g),C=.5*Math.exp(2*F/3),S=.5*Math.sqrt(F*C*(g-C)/g)*(_-g/2<0?-1:1),P=Math.max(a,Math.floor(t-_*C/g+S)),k=Math.min(o,Math.floor(t+(g-_)*C/g+S));uCe(n,t,P,k,l)}let p=n[t],x=a,m=o;for(lb(n,a,t),l(n[o],p)>0&&lb(n,a,o);x<m;){for(lb(n,x,m),x++,m--;l(n[x],p)<0;)x++;for(;l(n[m],p)>0;)m--}l(n[a],p)===0?lb(n,a,m):(m++,lb(n,m,o)),m<=t&&(a=m+1),t<=m&&(o=m-1)}}function lb(n,t,a){let o=n[t];n[t]=n[a],n[a]=o}function Jjt(n,t){return n<t?-1:n>t?1:0}var Zjt=class{constructor(n=9){this._maxEntries=Math.max(4,n),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(n){let t=this.data,a=[];if(!c7(n,t))return a;let o=this.toBBox,l=[];for(;t;){for(let p=0;p<t.children.length;p++){let x=t.children[p],m=t.leaf?o(x):x;c7(n,m)&&(t.leaf?a.push(x):vY(n,m)?this._all(x,a):l.push(x))}t=l.pop()}return a}collides(n){let t=this.data;if(!c7(n,t))return!1;let a=[];for(;t;){for(let o=0;o<t.children.length;o++){let l=t.children[o],p=t.leaf?this.toBBox(l):l;if(c7(n,p)){if(t.leaf||vY(n,p))return!0;a.push(l)}}t=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 t=this._build(n.slice(),0,n.length-1,0);if(!this.data.children.length)this.data=t;else if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){let a=this.data;this.data=t,t=a}this._insert(t,this.data.height-t.height-1,!0)}return this}insert(n){return n&&this._insert(n,this.data.height-1),this}clear(){return this.data=H2([]),this}remove(n,t){if(!n)return this;let a=this.data,o=this.toBBox(n),l=[],p=[],x,m,g;for(;a||l.length;){if(a||(a=l.pop(),m=l[l.length-1],x=p.pop(),g=!0),a.leaf){let _=Qjt(n,a.children,t);if(_!==-1)return a.children.splice(_,1),l.push(a),this._condense(l),this}!g&&!a.leaf&&vY(a,o)?(l.push(a),p.push(x),x=0,m=a,a=a.children[0]):m?(x++,a=m.children[x],g=!1):a=null}return this}toBBox(n){return n}compareMinX(n,t){return n.minX-t.minX}compareMinY(n,t){return n.minY-t.minY}toJSON(){return this.data}fromJSON(n){return this.data=n,this}_all(n,t){let a=[];for(;n;)n.leaf?t.push(...n.children):a.push(...n.children),n=a.pop();return t}_build(n,t,a,o){let l=a-t+1,p=this._maxEntries,x;if(l<=p)return x=H2(n.slice(t,a+1)),G2(x,this.toBBox),x;o||(o=Math.ceil(Math.log(l)/Math.log(p)),p=Math.ceil(l/Math.pow(p,o-1))),x=H2([]),x.leaf=!1,x.height=o;let m=Math.ceil(l/p),g=m*Math.ceil(Math.sqrt(p));N4e(n,t,a,g,this.compareMinX);for(let _=t;_<=a;_+=g){let F=Math.min(_+g-1,a);N4e(n,_,F,m,this.compareMinY);for(let C=_;C<=F;C+=m){let S=Math.min(C+m-1,F);x.children.push(this._build(n,C,S,o-1))}}return G2(x,this.toBBox),x}_chooseSubtree(n,t,a,o){for(;o.push(t),!(t.leaf||o.length-1===a);){let l=1/0,p=1/0,x;for(let m=0;m<t.children.length;m++){let g=t.children[m],_=FY(g),F=rNt(n,g)-_;F<p?(p=F,l=_<l?_:l,x=g):F===p&&_<l&&(l=_,x=g)}t=x||t.children[0]}return t}_insert(n,t,a){let o=a?n:this.toBBox(n),l=[],p=this._chooseSubtree(o,this.data,t,l);for(p.children.push(n),pb(p,o);t>=0&&l[t].children.length>this._maxEntries;)this._split(l,t),t--;this._adjustParentBBoxes(o,l,t)}_split(n,t){let a=n[t],o=a.children.length,l=this._minEntries;this._chooseSplitAxis(a,l,o);let p=this._chooseSplitIndex(a,l,o),x=H2(a.children.splice(p,a.children.length-p));x.height=a.height,x.leaf=a.leaf,G2(a,this.toBBox),G2(x,this.toBBox),t?n[t-1].children.push(x):this._splitRoot(a,x)}_splitRoot(n,t){this.data=H2([n,t]),this.data.height=n.height+1,this.data.leaf=!1,G2(this.data,this.toBBox)}_chooseSplitIndex(n,t,a){let o,l=1/0,p=1/0;for(let x=t;x<=a-t;x++){let m=db(n,0,x,this.toBBox),g=db(n,x,a,this.toBBox),_=nNt(m,g),F=FY(m)+FY(g);_<l?(l=_,o=x,p=F<p?F:p):_===l&&F<p&&(p=F,o=x)}return o||a-t}_chooseSplitAxis(n,t,a){let o=n.leaf?this.compareMinX:eNt,l=n.leaf?this.compareMinY:tNt,p=this._allDistMargin(n,t,a,o),x=this._allDistMargin(n,t,a,l);p<x&&n.children.sort(o)}_allDistMargin(n,t,a,o){n.children.sort(o);let l=this.toBBox,p=db(n,0,t,l),x=db(n,a-t,a,l),m=o7(p)+o7(x);for(let g=t;g<a-t;g++){let _=n.children[g];pb(p,n.leaf?l(_):_),m+=o7(p)}for(let g=a-t-1;g>=t;g--){let _=n.children[g];pb(x,n.leaf?l(_):_),m+=o7(x)}return m}_adjustParentBBoxes(n,t,a){for(let o=a;o>=0;o--)pb(t[o],n)}_condense(n){for(let t=n.length-1,a;t>=0;t--)n[t].children.length===0?t>0?(a=n[t-1].children,a.splice(a.indexOf(n[t]),1)):this.clear():G2(n[t],this.toBBox)}};function Qjt(n,t,a){if(!a)return t.indexOf(n);for(let o=0;o<t.length;o++)if(a(n,t[o]))return o;return-1}function G2(n,t){db(n,0,n.children.length,t,n)}function db(n,t,a,o,l){l||(l=H2(null)),l.minX=1/0,l.minY=1/0,l.maxX=-1/0,l.maxY=-1/0;for(let p=t;p<a;p++){let x=n.children[p];pb(l,n.leaf?o(x):x)}return l}function pb(n,t){return n.minX=Math.min(n.minX,t.minX),n.minY=Math.min(n.minY,t.minY),n.maxX=Math.max(n.maxX,t.maxX),n.maxY=Math.max(n.maxY,t.maxY),n}function eNt(n,t){return n.minX-t.minX}function tNt(n,t){return n.minY-t.minY}function FY(n){return(n.maxX-n.minX)*(n.maxY-n.minY)}function o7(n){return n.maxX-n.minX+(n.maxY-n.minY)}function rNt(n,t){return(Math.max(t.maxX,n.maxX)-Math.min(t.minX,n.minX))*(Math.max(t.maxY,n.maxY)-Math.min(t.minY,n.minY))}function nNt(n,t){let a=Math.max(n.minX,t.minX),o=Math.max(n.minY,t.minY),l=Math.min(n.maxX,t.maxX),p=Math.min(n.maxY,t.maxY);return Math.max(0,l-a)*Math.max(0,p-o)}function vY(n,t){return n.minX<=t.minX&&n.minY<=t.minY&&t.maxX<=n.maxX&&t.maxY<=n.maxY}function c7(n,t){return t.minX<=n.maxX&&t.minY<=n.maxY&&t.maxX>=n.minX&&t.maxY>=n.minY}function H2(n){return{children:n,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function N4e(n,t,a,o,l){let p=[t,a];for(;p.length;){if(a=p.pop(),t=p.pop(),a-t<=o)continue;let x=t+Math.ceil((a-t)/o/2)*o;uCe(n,x,t,a,l),p.push(t,x,x,a)}}var aNt=class{constructor(n=9){J(this,"tree");this.tree=new Zjt(n)}insert(n,t,a,o,l){this.tree.insert({minX:t,minY:a,maxX:o,maxY:l,data:n})}bulkLoad(n){let t=n.map(({item:a,minX:o,minY:l,maxX:p,maxY:x})=>({minX:o,minY:l,maxX:p,maxY:x,data:a}));this.tree.load(t)}search(n,t,a,o){return this.tree.search({minX:n,minY:t,maxX:a,maxY:o}).map(l=>l.data)}clear(){this.tree.clear()}},iNt=class{constructor(){this.ids=[],this.values=[],this.length=0}clear(){this.length=0}push(n,t){let a=this.length++;for(;a>0;){let o=a-1>>1,l=this.values[o];if(t>=l)break;this.ids[a]=this.ids[o],this.values[a]=l,a=o}this.ids[a]=n,this.values[a]=t}pop(){if(this.length===0)return;let n=this.ids[0];if(this.length--,this.length>0){let t=this.ids[0]=this.ids[this.length],a=this.values[0]=this.values[this.length],o=this.length>>1,l=0;for(;l<o;){let p=(l<<1)+1,x=p+1,m=this.ids[p],g=this.values[p],_=this.values[x];if(x<this.length&&_<g&&(p=x,m=this.ids[x],g=_),g>=a)break;this.ids[l]=m,this.values[l]=g,l=p}this.ids[l]=t,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}},M4e=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],EY=3,O4e=class lCe{static from(t,a=0){if(a%8!==0)throw new Error("byteOffset must be 8-byte aligned.");if(!t||t.byteLength===void 0||t.buffer)throw new Error("Data must be an instance of ArrayBuffer or SharedArrayBuffer.");let[o,l]=new Uint8Array(t,a+0,2);if(o!==251)throw new Error("Data does not appear to be in a Flatbush format.");let p=l>>4;if(p!==EY)throw new Error(`Got v${p} data when expected v${EY}.`);let x=M4e[l&15];if(!x)throw new Error("Unrecognized array type.");let[m]=new Uint16Array(t,a+2,1),[g]=new Uint32Array(t,a+4,1);return new lCe(g,m,x,void 0,t,a)}constructor(t,a=16,o=Float64Array,l=ArrayBuffer,p,x=0){if(t===void 0)throw new Error("Missing required argument: numItems.");if(isNaN(t)||t<=0)throw new Error(`Unexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+a,2),65535),this.byteOffset=x;let m=t,g=m;this._levelBounds=[m*4];do m=Math.ceil(m/this.nodeSize),g+=m,this._levelBounds.push(g*4);while(m!==1);this.ArrayType=o,this.IndexArrayType=g<16384?Uint16Array:Uint32Array;let _=M4e.indexOf(this.ArrayType),F=g*4*this.ArrayType.BYTES_PER_ELEMENT;if(_<0)throw new Error(`Unexpected typed array class: ${o}.`);p&&p.byteLength!==void 0&&!p.buffer?(this.data=p,this._boxes=new this.ArrayType(this.data,x+8,g*4),this._indices=new this.IndexArrayType(this.data,x+8+F,g),this._pos=g*4,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+F+g*this.IndexArrayType.BYTES_PER_ELEMENT),this._boxes=new this.ArrayType(this.data,8,g*4),this._indices=new this.IndexArrayType(this.data,8+F,g),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,(EY<<4)+_]),new Uint16Array(this.data,2,1)[0]=a,new Uint32Array(this.data,4,1)[0]=t),this._queue=new iNt}add(t,a,o=t,l=a){let p=this._pos>>2,x=this._boxes;return this._indices[p]=p,x[this._pos++]=t,x[this._pos++]=a,x[this._pos++]=o,x[this._pos++]=l,t<this.minX&&(this.minX=t),a<this.minY&&(this.minY=a),o>this.maxX&&(this.maxX=o),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 t=this._boxes;if(this.numItems<=this.nodeSize){t[this._pos++]=this.minX,t[this._pos++]=this.minY,t[this._pos++]=this.maxX,t[this._pos++]=this.maxY;return}let a=this.maxX-this.minX||1,o=this.maxY-this.minY||1,l=new Uint32Array(this.numItems),p=65535;for(let x=0,m=0;x<this.numItems;x++){let g=t[m++],_=t[m++],F=t[m++],C=t[m++],S=Math.floor(p*((g+F)/2-this.minX)/a),P=Math.floor(p*((_+C)/2-this.minY)/o);l[x]=oNt(S,P)}NY(l,t,this._indices,0,this.numItems-1,this.nodeSize);for(let x=0,m=0;x<this._levelBounds.length-1;x++){let g=this._levelBounds[x];for(;m<g;){let _=m,F=t[m++],C=t[m++],S=t[m++],P=t[m++];for(let k=1;k<this.nodeSize&&m<g;k++)F=Math.min(F,t[m++]),C=Math.min(C,t[m++]),S=Math.max(S,t[m++]),P=Math.max(P,t[m++]);this._indices[this._pos>>2]=_,t[this._pos++]=F,t[this._pos++]=C,t[this._pos++]=S,t[this._pos++]=P}}}search(t,a,o,l,p){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let x=this._boxes.length-4,m=[],g=[];for(;x!==void 0;){let _=Math.min(x+this.nodeSize*4,z4e(x,this._levelBounds));for(let F=x;F<_;F+=4){if(o<this._boxes[F]||l<this._boxes[F+1]||t>this._boxes[F+2]||a>this._boxes[F+3])continue;let C=this._indices[F>>2]|0;x>=this.numItems*4?m.push(C):(p===void 0||p(C))&&g.push(C)}x=m.pop()}return g}neighbors(t,a,o=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,m=this._queue,g=[],_=l*l;e:for(;x!==void 0;){let F=Math.min(x+this.nodeSize*4,z4e(x,this._levelBounds));for(let C=x;C<F;C+=4){let S=this._indices[C>>2]|0,P=L4e(t,this._boxes[C],this._boxes[C+2]),k=L4e(a,this._boxes[C+1],this._boxes[C+3]),q=P*P+k*k;q>_||(x>=this.numItems*4?m.push(S<<1,q):(p===void 0||p(S))&&m.push((S<<1)+1,q))}for(;m.length&&m.peek()&1;)if(m.peekValue()>_||(g.push(m.pop()>>1),g.length===o))break e;x=m.length?m.pop()>>1:void 0}return m.clear(),g}};function L4e(n,t,a){return n<t?t-n:n<=a?0:n-a}function z4e(n,t){let a=0,o=t.length-1;for(;a<o;){let l=a+o>>1;t[l]>n?o=l:a=l+1}return t[a]}function NY(n,t,a,o,l,p){if(Math.floor(o/p)>=Math.floor(l/p))return;let x=n[o+l>>1],m=o-1,g=l+1;for(;;){do m++;while(n[m]<x);do g--;while(n[g]>x);if(m>=g)break;sNt(n,t,a,m,g)}NY(n,t,a,o,g,p),NY(n,t,a,g+1,l,p)}function sNt(n,t,a,o,l){let p=n[o];n[o]=n[l],n[l]=p;let x=4*o,m=4*l,g=t[x],_=t[x+1],F=t[x+2],C=t[x+3];t[x]=t[m],t[x+1]=t[m+1],t[x+2]=t[m+2],t[x+3]=t[m+3],t[m]=g,t[m+1]=_,t[m+2]=F,t[m+3]=C;let S=a[o];a[o]=a[l],a[l]=S}function oNt(n,t){let a=n^t,o=65535^a,l=65535^(n|t),p=n&(t^65535),x=a|o>>1,m=a>>1^a,g=l>>1^o&p>>1^l,_=a&l>>1^p>>1^p;a=x,o=m,l=g,p=_,x=a&a>>2^o&o>>2,m=a&o>>2^o&(a^o)>>2,g^=a&l>>2^o&p>>2,_^=o&l>>2^(a^o)&p>>2,a=x,o=m,l=g,p=_,x=a&a>>4^o&o>>4,m=a&o>>4^o&(a^o)>>4,g^=a&l>>4^o&p>>4,_^=o&l>>4^(a^o)&p>>4,a=x,o=m,l=g,p=_,g^=a&l>>8^o&p>>8,_^=o&l>>8^(a^o)&p>>8,a=g^g>>1,o=_^_>>1;let F=n^t,C=o|65535^(F|a);return F=(F|F<<8)&16711935,F=(F|F<<4)&252645135,F=(F|F<<2)&858993459,F=(F|F<<1)&1431655765,C=(C|C<<8)&16711935,C=(C|C<<4)&252645135,C=(C|C<<2)&858993459,C=(C|C<<1)&1431655765,(C<<1|F)>>>0}var cNt=class{constructor(n){J(this,"index");J(this,"items",[]);J(this,"currentIndex",0);this.index=new O4e(n)}insert(n,t,a,o,l){if(this.currentIndex>=this.index.numItems)throw new Error("Exceeded initial capacity");this.items[this.currentIndex]=n,this.index.add(t,a,o,l),this.currentIndex++}finish(){this.index.finish()}search(n,t,a,o){return this.index.search(n,t,a,o).map(p=>this.items[p]||null).filter(Boolean)}clear(){this.items=[],this.index=new O4e(0)}},dCe=class{constructor(n="native",t=[]){J(this,"idx");J(this,"storage",[]);n==="flatbush"?this.idx=new cNt(t.length):n==="rbush"?this.idx=new aNt:this.idx=new class{constructor(){J(this,"shi",new uNt(t))}insert(a){}search(a,o,l,p){let x=(a+l)/2,m=(o+p)/2,g=l-a,_=p-o;return this.shi.getNodesInArea(x,m,g,_)}clear(){}},t.forEach(a=>this.insert(a)),n==="flatbush"&&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,t,a,o){return this.search({minX:n-a/2,minY:t-o/2,maxX:n+a/2,maxY:t+o/2})}},uNt=class{constructor(n){J(this,"buckets");J(this,"CELL_SIZE",.4);this.obstacles=n,this.buckets=new Map;let t=0;for(let a=0;a<n.length;a++){let o=n[a],l=o.center.x-o.width/2,p=o.center.y-o.height/2,x=o.center.x+o.width/2,m=o.center.y+o.height/2;for(let g=l;g<=x;g+=this.CELL_SIZE)for(let _=p;_<=m;_+=this.CELL_SIZE){let F=this.getBucketKey(g,_),C=this.buckets.get(F);C?(C.push([o,a]),t++):this.buckets.set(F,[[o,a]])}}}getBucketKey(n,t){return`${Math.floor(n/this.CELL_SIZE)}x${Math.floor(t/this.CELL_SIZE)}`}getNodesInArea(n,t,a,o){let l=[],p=new Set,x=n-a/2,m=t-o/2,g=n+a/2,_=t+o/2;for(let F=x;F<=g;F+=this.CELL_SIZE)for(let C=m;C<=_;C+=this.CELL_SIZE){let S=this.getBucketKey(F,C),P=this.buckets.get(S)||[];for(let k of P)p.has(k[1])||(p.add(k[1]),l.push(k[0]))}return l}},lNt=class{constructor(n){J(this,"buckets");J(this,"CELL_SIZE",5);this.targets=n,this.buckets=new Map;for(let t=0;t<n.length;t++){let a=n[t],o=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 m=o;m<=p;m+=this.CELL_SIZE)for(let g=l;g<=x;g+=this.CELL_SIZE){let _=this.getBucketKey(m,g),F=this.buckets.get(_);F?F.push([a,t]):this.buckets.set(_,[[a,t]])}}}getBucketKey(n,t){return`${Math.floor(n/this.CELL_SIZE)}x${Math.floor(t/this.CELL_SIZE)}`}getTargetsInArea(n,t,a,o){let l=[],p=new Set,x=Math.floor((n-a/2)/this.CELL_SIZE)*this.CELL_SIZE,m=Math.floor((t-o/2)/this.CELL_SIZE)*this.CELL_SIZE,g=n+a/2,_=t+o/2;for(let F=x;F<=g;F+=this.CELL_SIZE)for(let C=m;C<=_;C+=this.CELL_SIZE){let S=this.getBucketKey(F,C),P=this.buckets.get(S)||[];for(let k of P)p.has(k[1])||(p.add(k[1]),l.push(k[0]))}return l}},dNt=class extends ui{constructor(t,a={}){super();J(this,"unfinishedNodes");J(this,"finishedNodes");J(this,"nodeToXYOverlappingObstaclesMap");J(this,"layerCount");J(this,"MAX_DEPTH",4);J(this,"targets");J(this,"targetTree");J(this,"obstacleTree");J(this,"_nextNodeCounter",0);this.srj=t,this.opts=a,this.MAX_DEPTH=a?.capacityDepth??this.MAX_DEPTH,this.MAX_ITERATIONS=1e5,this.layerCount=t.layerCount??2;for(let x of t.obstacles)if(!x.zLayers){let m=[];for(let g of x.layers)m.push(Db(g,t.layerCount));x.zLayers=m}let o={x:(t.bounds.minX+t.bounds.maxX)/2,y:(t.bounds.minY+t.bounds.maxY)/2},l={width:t.bounds.maxX-t.bounds.minX,height:t.bounds.maxY-t.bounds.minY},p=Math.max(l.width,l.height);this.unfinishedNodes=[{capacityMeshNodeId:this.getNextNodeId(),center:o,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 dCe("flatbush",this.srj.obstacles),this.targets=this.computeTargets(),this.targetTree=new lNt(this.targets)}computeTargets(){let t=[];for(let a of this.srj.connections)for(let o of a.pointsToConnect){let l=this.obstacleTree.searchArea(o.x,o.y,.01,.01).filter(m=>m.zLayers.some(g=>o.layer==="top"?g===0:g===1)),p={minX:o.x-.005,minY:o.y-.005,maxX:o.x+.005,maxY:o.y+.005};l.length>0&&(p={minX:Math.min(...l.map(m=>m.center.x-m.width/2)),minY:Math.min(...l.map(m=>m.center.y-m.height/2)),maxX:Math.max(...l.map(m=>m.center.x+m.width/2)),maxY:Math.max(...l.map(m=>m.center.y+m.height/2))});let x={...o,connectionName:a.name,availableZ:o.layer==="top"?[0]:[1],bounds:p};t.push(x)}return t}getNextNodeId(){return`cn${this._nextNodeCounter++}`}getCapacityFromDepth(t){return(this.MAX_DEPTH-t+1)**2}getTargetIfNodeContainsTarget(t){let a=t.width>this.targetTree.CELL_SIZE*4?this.targets:this.targetTree.getTargetsInArea(t.center.x,t.center.y,t.width,t.height);for(let o of a)if(o.bounds.minX<=t.center.x+t.width/2&&o.bounds.maxX>=t.center.x-t.width/2&&o.bounds.minY<=t.center.y+t.height/2&&o.bounds.maxY>=t.center.y-t.height/2&&o.availableZ.some(l=>t.availableZ.includes(l)))return o;return null}getXYOverlappingObstacles(t){let a=this.nodeToXYOverlappingObstaclesMap.get(t.capacityMeshNodeId);if(a)return a;let o=[],l=t.center.x-t.width/2,p=t.center.x+t.width/2,x=t.center.y-t.height/2,m=t.center.y+t.height/2,g=t._parent?this.getXYOverlappingObstacles(t._parent):this.srj.obstacles;for(let _ of g){let F=_.center.x-_.width/2,C=_.center.x+_.width/2,S=_.center.y-_.height/2,P=_.center.y+_.height/2;if(p>=F&&l<=C&&m>=S&&x<=P){o.push(_);continue}if(l>=F&&p<=C&&x>=S&&m<=P){o.push(_);continue}F>=l&&C<=p&&S>=x&&P<=m&&o.push(_)}return this.nodeToXYOverlappingObstaclesMap.set(t.capacityMeshNodeId,o),o}getXYZOverlappingObstacles(t){let a=this.getXYOverlappingObstacles(t),o=[];for(let l of a)t.availableZ.some(p=>l.zLayers.includes(p))&&o.push(l);return o}doesNodeOverlapObstacle(t){if(this.getXYZOverlappingObstacles(t).length>0)return!0;let o=t.center.x-t.width/2,l=t.center.x+t.width/2,p=t.center.y-t.height/2,x=t.center.y+t.height/2;return o<this.srj.bounds.minX||l>this.srj.bounds.maxX||p<this.srj.bounds.minY||x>this.srj.bounds.maxY}isNodeCompletelyInsideObstacle(t){let a=this.getXYZOverlappingObstacles(t),o=t.center.x-t.width/2,l=t.center.x+t.width/2,p=t.center.y-t.height/2,x=t.center.y+t.height/2;for(let m of a){let g=m.center.x-m.width/2,_=m.center.x+m.width/2,F=m.center.y-m.height/2,C=m.center.y+m.height/2;if(o>=g&&l<=_&&p>=F&&x<=C)return!0}return!1}getChildNodes(t){if(t._depth===this.MAX_DEPTH)return[];let a=[],o={width:t.width/2,height:t.height/2},l=[{x:t.center.x-o.width/2,y:t.center.y-o.height/2},{x:t.center.x+o.width/2,y:t.center.y-o.height/2},{x:t.center.x-o.width/2,y:t.center.y+o.height/2},{x:t.center.x+o.width/2,y:t.center.y+o.height/2}];for(let p of l){let x={capacityMeshNodeId:this.getNextNodeId(),center:p,width:o.width,height:o.height,layer:t.layer,availableZ:[0,1],_depth:(t._depth??0)+1,_parent:t};x._containsObstacle=this.doesNodeOverlapObstacle(x);let m=this.getTargetIfNodeContainsTarget(x);m&&(x._targetConnectionName=m.connectionName,x.availableZ=m.availableZ,x._containsTarget=!0),x._containsObstacle&&(x._completelyInsideObstacle=this.isNodeCompletelyInsideObstacle(x)),!(x._completelyInsideObstacle&&!x._containsTarget)&&a.push(x)}return a}shouldNodeBeXYSubdivided(t){return t._depth>=this.MAX_DEPTH?!1:!!(t._containsTarget||t._containsObstacle&&!t._completelyInsideObstacle)}_step(){let t=this.unfinishedNodes.pop();if(!t){this.solved=!0;return}let a=this.getChildNodes(t),o=[],l=[];for(let p of a){let x=this.shouldNodeBeXYSubdivided(p);x?l.push(p):(!x&&!p._containsObstacle||!x&&p._containsTarget)&&o.push(p)}this.unfinishedNodes.push(...l),this.finishedNodes.push(...o)}visualize(){let t={lines:[],points:[],rects:[],circles:[],coordinateSystem:"cartesian",title:"Capacity Mesh Visualization"};for(let o of this.srj.obstacles)t.rects.push({center:o.center,width:o.width,height:o.height,fill:o.zLayers?.length===1&&o.zLayers?.includes(1)?"rgba(0,0,255,0.3)":"rgba(255,0,0,0.3)",stroke:"red",label:["obstacle",`z: ${o.zLayers.join(",")}`].join(`
|
|
956
956
|
`)});let a=[...this.finishedNodes,...this.unfinishedNodes];for(let o of a){let l=Math.min(...o.availableZ),p=this.unfinishedNodes.length>0&&o===this.unfinishedNodes[this.unfinishedNodes.length-1];t.rects.push({center:{x:o.center.x+l*o.width*.05,y:o.center.y-l*o.width*.05},width:Math.max(o.width-2,o.width*.8),height:Math.max(o.height-2,o.height*.8),fill:o._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)"}[o.availableZ.join(",")]??"rgba(0,200,200,0.1)",stroke:p?"rgba(255,165,0,0.5)":void 0,label:[o.capacityMeshNodeId,`availableZ: ${o.availableZ.join(",")}`,`target? ${o._containsTarget??!1}`,`obs? ${o._containsObstacle??!1}`,`${o.width.toFixed(2)}x${o.height.toFixed(2)}`,`capacity: ${ix(o).toFixed(2)}`].join(`
|
|
@@ -1043,7 +1043,7 @@ ${Object.keys(t).join(", ")}`);return a};function h8(n,t,a){globalThis.__tscircu
|
|
|
1043
1043
|
var module = { exports };
|
|
1044
1044
|
var circuit = globalThis.__tscircuit_circuit;
|
|
1045
1045
|
${n};
|
|
1046
|
-
return module;`.trim();return Function(o).call(globalThis)}var qhr=Cr(kR(),1);var WW=Cr(kR(),1);var HIe=n=>{let t=/^\s*import\s+(?:(?:[\w\s]+,\s*)?(?:\*\s+as\s+[\w\s]+|\{[\s\w,]+\}|\w+)\s+from\s+)?['"](.+?)['"]/gm,a=[],o;for(;(o=t.exec(n))!==null;)a.push(o[1]);let l=/^\s*export\s+(?:\*|(?:\{[\s\w,]+\}))\s+from\s+['"](.+?)['"]/gm,p;for(;(p=l.exec(n))!==null;)a.push(p[1]);return a};var YIe=Cr(e0(),1),R_=(0,YIe.default)("tsci:eval:import-local-file"),jR=async(n,t,a=0)=>{R_("importLocalFile called with:",{importName:n});let{fsMap:o,preSuppliedImports:l}=t,p=TR(n,o);if(R_("fsPath:",p),!t.fsMap[p])throw R_("fsPath not found in fsMap:",p),new Error(`File "${p}" not found`);let x=o[p];if(R_("fileContent:",x?.slice(0,100)),p.endsWith(".json")){let m=JSON.parse(x);l[p]={__esModule:!0,default:m}}else if(p.endsWith(".tsx")||p.endsWith(".ts")){let m=HIe(x);for(let _ of m)l[_]||await y8(_,t,a+1,{cwd:Uf(p)});let g=WW.transform(x,{presets:["react","typescript"],plugins:["transform-modules-commonjs"],filename:"virtual.tsx"});if(!g||!g.code)throw new Error("Failed to transform code");try{R_("evalCompiledJs called with:",{code:g.code?.slice(0,100),dirname:Uf(p)});let _=h8(g.code,l,Uf(p));R_("importRunResult:",{fsPath:p,importRunResult:_}),l[p]=_.exports}catch(_){throw new Error(`Eval compiled js error for "${n}": ${_.message}`)}}else if(p.endsWith(".js")){let m=WW.transform(x,{presets:["env"],plugins:["transform-modules-commonjs"],filename:p});if(!m||!m.code)throw new Error("Failed to transform JS code");l[p]=h8(m.code,l,Uf(p)).exports}else throw new Error(`Unsupported file extension "${p.split(".").pop()}" for "${p}"`)};var whr=Cr(kR(),1);async function XIe(n,t,a=0){let{preSuppliedImports:o}=t,l=n.replace("@tsci/","").replace(".","/"),{cjs:p,error:x}=await fetch(`${t.cjsRegistryUrl}/${l}`).then(async m=>({cjs:await m.text(),error:null})).catch(m=>({error:m,cjs:null}));if(x){console.error("Error fetching import",n,x);return}try{o[n]=h8(p,o).exports}catch(m){console.error("Error importing snippet",m)}}function yGt(n,t,a){return{fsMap:t,extensions:[".js",".jsx",".ts",".tsx",".json"],basePath:a,modulePath:n}}function gGt(n,t){let a=`${n}/package.json`;if(!t.fsMap[a])return null;try{return JSON.parse(t.fsMap[a])}catch{return null}}function JW(n,t){if(t.fsMap[n])return n;for(let a of t.extensions){let o=n.replace(/\.js$|\.jsx$/,"")+a;if(t.fsMap[o])return o}return null}function KW(n,t,a){let o=`${n}/${t.replace(/^\.\//,"")}`;return JW(o,a)}function DGt(n,t,a,o){if(!t.exports)return null;let l=t.exports["."];if(a===""&&l&&typeof l=="string"){let m=KW(n,l,o);if(m)return m}let p=a?t.exports[`./${a}`]:null;if(p&&typeof p=="string"){let m=KW(n,p,o);if(m)return m}let x=t.exports.import;if(a===""&&x&&typeof x=="string"){let m=KW(n,x,o);if(m)return m}return null}function _Gt(n,t,a){let o=t.module||t.main||"index.js",l=`${n}/${o}`;return JW(l,a)}function bGt(n,t,a){if(!t){for(let p of a.extensions){let x=`${n}/index${p}`;if(a.fsMap[x])return x}return null}let o=`${n}/${t}`,l=JW(o,a);if(l)return l;for(let p of a.extensions){let x=`${o}/index${p}`;if(a.fsMap[x])return x}return null}function WIe(n,t){let a=t.modulePath.split("/"),o=a[0].startsWith("@")?a.slice(0,2).join("/"):a[0],l=a.slice(o.includes("/")?2:1).join("/"),p=`${n=="."?"":`${n}/`}node_modules/${o}`,x=gGt(p,t);if(x){let _=DGt(p,x,l,t);if(_)return _;let F=_Gt(p,x,t);if(F)return F}let m=bGt(p,l,t);if(m)return m;let g=Uf(n);return g&&g!==n?WIe(g,t):null}function NR(n,t,a){let o=yGt(n,t,a);return WIe(o.basePath,o)}var KIe=async(n,t,a=0)=>{let{preSuppliedImports:o}=t;if(o[n])return;let l=NR(n,t.fsMap,"");if(!l)throw new Error(`Node module "${n}" not found`);await jR(l,t,a),o[n]=o[l];let p=l.replace(/^node_modules\//,"");if(o[p]=o[l],l.endsWith("/index.tsx")||l.endsWith("/index.ts")||l.endsWith("/index.js")){let m=l.replace(/\/index\.(tsx?|js)$/,"").replace(/^node_modules\//,"");if(o[m]=o[l],m.startsWith("@")){let g=m.split("/");if(g.length>=2){let _=`${g[0]}/${g[1]}`;o[_]=o[l]}}}};var ZIe=Cr(e0(),1),JIe=(0,ZIe.default)("tsci:eval:import-eval-path");async function y8(n,t,a=0,o={}){JIe("importEvalPath called with:",{importName:n,depth:a,opts:o}),JIe(`${" ".repeat(a)}\u27A1\uFE0F`,n);let{preSuppliedImports:l}=t;if(l[n]||n.startsWith("./")&&l[n.slice(2)])return;if(a>5){console.log("Max depth for imports reached");return}let p=m8(n,t.fsMap,o.cwd);if(p)return jR(p,t,a);if(NR(n,t.fsMap,o.cwd||""))return KIe(n,t,a);if(n.startsWith("@tsci/"))return XIe(n,t,a);throw new Error(`Unresolved import "${n}" ${o.cwd?`from directory "${o.cwd}"`:""}`)}var QIe=Cr(e0(),1),FGt=(0,QIe.default)("tsci:eval:setupDefaultEntrypointIfNeeded"),ewe=n=>{if(!n.entrypoint&&!n.mainComponentPath)if("index.tsx"in n.fsMap)n.mainComponentPath="index.tsx";else if("index.ts"in n.fsMap)n.mainComponentPath="index.ts";else if(Object.keys(n.fsMap).filter(t=>t.endsWith(".tsx")).length===1)n.mainComponentPath=Object.keys(n.fsMap)[0];else if("tscircuit.config.json"in n.fsMap){let t=n.fsMap["tscircuit.config.json"];try{let a=JSON.parse(t);a.mainEntrypoint&&(n.entrypoint=a.mainEntrypoint)}catch(a){console.warn("Failed to parse tscircuit.config.json:",a)}}else throw new Error("Either entrypoint or mainComponentPath must be provided (no index file, could not infer entrypoint)");if(!n.entrypoint&&n.mainComponentPath){n.entrypoint="entrypoint.tsx"
|
|
1046
|
+
return module;`.trim();return Function(o).call(globalThis)}var qhr=Cr(kR(),1);var WW=Cr(kR(),1);var HIe=n=>{let t=/^\s*import\s+(?:(?:[\w\s]+,\s*)?(?:\*\s+as\s+[\w\s]+|\{[\s\w,]+\}|\w+)\s+from\s+)?['"](.+?)['"]/gm,a=[],o;for(;(o=t.exec(n))!==null;)a.push(o[1]);let l=/^\s*export\s+(?:\*|(?:\{[\s\w,]+\}))\s+from\s+['"](.+?)['"]/gm,p;for(;(p=l.exec(n))!==null;)a.push(p[1]);return a};var YIe=Cr(e0(),1),R_=(0,YIe.default)("tsci:eval:import-local-file"),jR=async(n,t,a=0)=>{R_("importLocalFile called with:",{importName:n});let{fsMap:o,preSuppliedImports:l}=t,p=TR(n,o);if(R_("fsPath:",p),!t.fsMap[p])throw R_("fsPath not found in fsMap:",p),new Error(`File "${p}" not found`);let x=o[p];if(R_("fileContent:",x?.slice(0,100)),p.endsWith(".json")){let m=JSON.parse(x);l[p]={__esModule:!0,default:m}}else if(p.endsWith(".tsx")||p.endsWith(".ts")){let m=HIe(x);for(let _ of m)l[_]||await y8(_,t,a+1,{cwd:Uf(p)});let g=WW.transform(x,{presets:["react","typescript"],plugins:["transform-modules-commonjs"],filename:"virtual.tsx"});if(!g||!g.code)throw new Error("Failed to transform code");try{R_("evalCompiledJs called with:",{code:g.code?.slice(0,100),dirname:Uf(p)});let _=h8(g.code,l,Uf(p));R_("importRunResult:",{fsPath:p,importRunResult:_}),l[p]=_.exports}catch(_){throw new Error(`Eval compiled js error for "${n}": ${_.message}`)}}else if(p.endsWith(".js")){let m=WW.transform(x,{presets:["env"],plugins:["transform-modules-commonjs"],filename:p});if(!m||!m.code)throw new Error("Failed to transform JS code");l[p]=h8(m.code,l,Uf(p)).exports}else throw new Error(`Unsupported file extension "${p.split(".").pop()}" for "${p}"`)};var whr=Cr(kR(),1);async function XIe(n,t,a=0){let{preSuppliedImports:o}=t,l=n.replace("@tsci/","").replace(".","/"),{cjs:p,error:x}=await fetch(`${t.cjsRegistryUrl}/${l}`).then(async m=>({cjs:await m.text(),error:null})).catch(m=>({error:m,cjs:null}));if(x){console.error("Error fetching import",n,x);return}try{o[n]=h8(p,o).exports}catch(m){console.error("Error importing snippet",m)}}function yGt(n,t,a){return{fsMap:t,extensions:[".js",".jsx",".ts",".tsx",".json"],basePath:a,modulePath:n}}function gGt(n,t){let a=`${n}/package.json`;if(!t.fsMap[a])return null;try{return JSON.parse(t.fsMap[a])}catch{return null}}function JW(n,t){if(t.fsMap[n])return n;for(let a of t.extensions){let o=n.replace(/\.js$|\.jsx$/,"")+a;if(t.fsMap[o])return o}return null}function KW(n,t,a){let o=`${n}/${t.replace(/^\.\//,"")}`;return JW(o,a)}function DGt(n,t,a,o){if(!t.exports)return null;let l=t.exports["."];if(a===""&&l&&typeof l=="string"){let m=KW(n,l,o);if(m)return m}let p=a?t.exports[`./${a}`]:null;if(p&&typeof p=="string"){let m=KW(n,p,o);if(m)return m}let x=t.exports.import;if(a===""&&x&&typeof x=="string"){let m=KW(n,x,o);if(m)return m}return null}function _Gt(n,t,a){let o=t.module||t.main||"index.js",l=`${n}/${o}`;return JW(l,a)}function bGt(n,t,a){if(!t){for(let p of a.extensions){let x=`${n}/index${p}`;if(a.fsMap[x])return x}return null}let o=`${n}/${t}`,l=JW(o,a);if(l)return l;for(let p of a.extensions){let x=`${o}/index${p}`;if(a.fsMap[x])return x}return null}function WIe(n,t){let a=t.modulePath.split("/"),o=a[0].startsWith("@")?a.slice(0,2).join("/"):a[0],l=a.slice(o.includes("/")?2:1).join("/"),p=`${n=="."?"":`${n}/`}node_modules/${o}`,x=gGt(p,t);if(x){let _=DGt(p,x,l,t);if(_)return _;let F=_Gt(p,x,t);if(F)return F}let m=bGt(p,l,t);if(m)return m;let g=Uf(n);return g&&g!==n?WIe(g,t):null}function NR(n,t,a){let o=yGt(n,t,a);return WIe(o.basePath,o)}var KIe=async(n,t,a=0)=>{let{preSuppliedImports:o}=t;if(o[n])return;let l=NR(n,t.fsMap,"");if(!l)throw new Error(`Node module "${n}" not found`);await jR(l,t,a),o[n]=o[l];let p=l.replace(/^node_modules\//,"");if(o[p]=o[l],l.endsWith("/index.tsx")||l.endsWith("/index.ts")||l.endsWith("/index.js")){let m=l.replace(/\/index\.(tsx?|js)$/,"").replace(/^node_modules\//,"");if(o[m]=o[l],m.startsWith("@")){let g=m.split("/");if(g.length>=2){let _=`${g[0]}/${g[1]}`;o[_]=o[l]}}}};var ZIe=Cr(e0(),1),JIe=(0,ZIe.default)("tsci:eval:import-eval-path");async function y8(n,t,a=0,o={}){JIe("importEvalPath called with:",{importName:n,depth:a,opts:o}),JIe(`${" ".repeat(a)}\u27A1\uFE0F`,n);let{preSuppliedImports:l}=t;if(l[n]||n.startsWith("./")&&l[n.slice(2)])return;if(a>5){console.log("Max depth for imports reached");return}let p=m8(n,t.fsMap,o.cwd);if(p)return jR(p,t,a);if(NR(n,t.fsMap,o.cwd||""))return KIe(n,t,a);if(n.startsWith("@tsci/"))return XIe(n,t,a);throw new Error(`Unresolved import "${n}" ${o.cwd?`from directory "${o.cwd}"`:""}`)}var QIe=Cr(e0(),1),FGt=(0,QIe.default)("tsci:eval:setupDefaultEntrypointIfNeeded"),ewe=n=>{if(!n.entrypoint&&!n.mainComponentPath)if("index.tsx"in n.fsMap)n.mainComponentPath="index.tsx";else if("index.ts"in n.fsMap)n.mainComponentPath="index.ts";else if(Object.keys(n.fsMap).filter(t=>t.endsWith(".tsx")).length===1)n.mainComponentPath=Object.keys(n.fsMap)[0];else if("tscircuit.config.json"in n.fsMap){let t=n.fsMap["tscircuit.config.json"];try{let a=JSON.parse(t);a.mainEntrypoint&&(n.entrypoint=a.mainEntrypoint)}catch(a){console.warn("Failed to parse tscircuit.config.json:",a)}}else throw new Error("Either entrypoint or mainComponentPath must be provided (no index file, could not infer entrypoint)");if(!n.entrypoint&&n.mainComponentPath){if(n.entrypoint="entrypoint.tsx",!n.fsMap[TR(n.mainComponentPath,n.fsMap)])throw new Error(`Main component path "${n.mainComponentPath}" not found in fsMap. Available paths: ${Object.keys(n.fsMap).join(", ")}`);n.fsMap[n.entrypoint]=`
|
|
1047
1047
|
import * as UserComponents from "./${n.mainComponentPath}";
|
|
1048
1048
|
|
|
1049
1049
|
${n.mainComponentName?`
|
|
@@ -1057,14 +1057,8 @@ ${Object.keys(t).join(", ")}`);return a};function h8(n,t,a){globalThis.__tscircu
|
|
|
1057
1057
|
console.log("ComponentToRender " + ComponentToRender.toString(), { ComponentToRender })
|
|
1058
1058
|
`:""}
|
|
1059
1059
|
|
|
1060
|
-
circuit.add(
|
|
1061
|
-
|
|
1062
|
-
<board>
|
|
1063
|
-
<ComponentToRender name="U1" ${n.mainComponentProps?`{...${JSON.stringify(n.mainComponentProps,null,2)}}`:""} />
|
|
1064
|
-
</board>
|
|
1065
|
-
`:`
|
|
1066
|
-
<ComponentToRender ${n.mainComponentProps?`{...${JSON.stringify(n.mainComponentProps,null,2)}}`:""} />
|
|
1067
|
-
`}
|
|
1060
|
+
circuit.add(
|
|
1061
|
+
<ComponentToRender ${n.mainComponentProps?`{...${JSON.stringify(n.mainComponentProps,null,2)}}`:""} />
|
|
1068
1062
|
);
|
|
1069
1063
|
`}!n.name&&n.mainComponentName&&(n.name=n.mainComponentName)};globalThis.React=vGt;var Mo=null,Qm={snippetsApiBaseUrl:"https://registry-api.tscircuit.com",cjsRegistryUrl:"https://cjs.tscircuit.com",verbose:!1,platform:void 0},fx={};function twe(n){for(let t in fx)for(let a of fx[t])n.on(t,a)}var EGt={setSnippetsApiBaseUrl:async n=>{Qm.snippetsApiBaseUrl=n},setPlatformConfig:async n=>{Qm.platform=n},version:async()=>"0.0.0",async executeWithFsMap(n){Qm.verbose&&console.log("[Worker] executeWithFsMap called with:",{entrypoint:n.entrypoint,fsMapKeys:Object.keys(n.fsMap),name:n.name}),ewe(n);let t=n.entrypoint;if(Mo=YW(Qm,{name:n.name,platform:Qm.platform}),twe(Mo.circuit),Mo.fsMap=VIe(n.fsMap),!Mo.fsMap[t])throw new Error(`Entrypoint "${n.entrypoint}" not found`);globalThis.__tscircuit_circuit=Mo.circuit,t.startsWith("./")||(t=`./${t}`),await y8(t,Mo)},async execute(n,t={}){Qm.verbose&&console.log("[Worker] execute called with code length:",n.length),Mo=YW(Qm,{...t,platform:Qm.platform}),twe(Mo.circuit),Mo.fsMap["entrypoint.tsx"]=n,globalThis.__tscircuit_circuit=Mo.circuit,await y8("./entrypoint.tsx",Mo)},on:(n,t)=>{fx[n]??(fx[n]=[]),fx[n].push(t),Mo?.circuit.on(n,t)},renderUntilSettled:async()=>{if(!Mo)throw new Error("No circuit has been created");await Mo.circuit.renderUntilSettled()},getCircuitJson:async()=>{if(!Mo)throw new Error("No circuit has been created");return Mo.circuit.getCircuitJson()},clearEventListeners:()=>{if(Mo?.circuit)for(let n in fx)for(let t of fx[n]){let a=Mo.circuit;typeof a.removeListener=="function"&&a.removeListener(n,t)}for(let n in fx)delete fx[n]},kill:async()=>{}};hC(EGt);
|
|
1070
1064
|
/*! Bundled license information:
|
|
@@ -46,14 +46,6 @@ export const setupDefaultEntrypointIfNeeded = (opts: {
|
|
|
46
46
|
`Main component path "${opts.mainComponentPath}" not found in fsMap. Available paths: ${Object.keys(opts.fsMap).join(", ")}`,
|
|
47
47
|
)
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
const hasExplicitBoard = mainComponentCode.includes("<board")
|
|
51
|
-
const hasTsciImport =
|
|
52
|
-
mainComponentCode.includes("@tsci/") ||
|
|
53
|
-
mainComponentCode.includes('from "@tsci')
|
|
54
|
-
const hasGroup = mainComponentCode.includes("<group")
|
|
55
|
-
const shouldWrapInBoard = !hasExplicitBoard && !hasTsciImport && !hasGroup
|
|
56
|
-
|
|
57
49
|
opts.fsMap[opts.entrypoint] = `
|
|
58
50
|
import * as UserComponents from "./${opts.mainComponentPath}";
|
|
59
51
|
|
|
@@ -76,18 +68,8 @@ export const setupDefaultEntrypointIfNeeded = (opts: {
|
|
|
76
68
|
: ""
|
|
77
69
|
}
|
|
78
70
|
|
|
79
|
-
circuit.add(
|
|
80
|
-
|
|
81
|
-
shouldWrapInBoard
|
|
82
|
-
? `
|
|
83
|
-
<board>
|
|
84
|
-
<ComponentToRender name="U1" ${opts.mainComponentProps ? `{...${JSON.stringify(opts.mainComponentProps, null, 2)}}` : ""} />
|
|
85
|
-
</board>
|
|
86
|
-
`
|
|
87
|
-
: `
|
|
88
|
-
<ComponentToRender ${opts.mainComponentProps ? `{...${JSON.stringify(opts.mainComponentProps, null, 2)}}` : ""} />
|
|
89
|
-
`
|
|
90
|
-
}
|
|
71
|
+
circuit.add(
|
|
72
|
+
<ComponentToRender ${opts.mainComponentProps ? `{...${JSON.stringify(opts.mainComponentProps, null, 2)}}` : ""} />
|
|
91
73
|
);
|
|
92
74
|
`
|
|
93
75
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/eval",
|
|
3
3
|
"main": "dist/lib/index.js",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.279",
|
|
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",
|
|
@@ -11,23 +11,27 @@ const example4 = {
|
|
|
11
11
|
},
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
test(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
test(
|
|
15
|
+
"example4-root-child-issue",
|
|
16
|
+
async () => {
|
|
17
|
+
const circuitWebWorker = await createCircuitWebWorker({
|
|
18
|
+
webWorkerUrl: new URL("../webworker/entrypoint.ts", import.meta.url),
|
|
19
|
+
})
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
await circuitWebWorker.executeWithFsMap({
|
|
22
|
+
fsMap: example4.fsMap,
|
|
23
|
+
entrypoint: example4.entrypoint,
|
|
24
|
+
})
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
await circuitWebWorker.renderUntilSettled()
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
const circuitJson = await circuitWebWorker.getCircuitJson()
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
const led = circuitJson.find((el: any) => el.name === "LED")
|
|
31
|
+
expect(led).toBeDefined()
|
|
32
|
+
expect(led?.type).toBe("source_component")
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
+
await circuitWebWorker.kill()
|
|
35
|
+
},
|
|
36
|
+
30 * 1000,
|
|
37
|
+
)
|