@tscircuit/runframe 0.0.551 → 0.0.553
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.
|
@@ -849,9 +849,9 @@ ${a.width}x${a.height}
|
|
|
849
849
|
`);const i=Eat(n,r.connections);for(const a of i)e.push(` ${a}`)}e.push("");const t=r.connections.filter(n=>n.connectedPorts.length>2);if(e.push("Complex Connections (more than 2 points):"),t.length===0)e.push(" (none)");else for(let n=0;n<t.length;n++){const i=t[n];e.push(` - complex connection[${n}]:`);for(const a of i.connectedPorts)"boxId"in a?e.push(` - ${a.boxId}.${a.pinNumber}`):"netId"in a&&e.push(` - ${a.netId}`)}return e.join(`
|
|
850
850
|
`)};function _at(r){if(!r.isPassive)throw new Error(`Chip ${r.chipId} is not a passive component`);return r.leftPinCount>0||r.rightPinCount>0?"horizontal":"vertical"}function Bat(r,e){var i;const t={boxes:e.boxes.map(a=>({...a})),nets:((i=e.nets)==null?void 0:i.map(a=>({...a})))||[],connections:e.connections.map(a=>({...a,connectedPorts:[...a.connectedPorts]}))},n=r.chips.filter(a=>a.isPassive);for(const a of n){const o=t.boxes.find(s=>s.boxId===a.chipId);if(o)try{if(_at(a)==="vertical"){if(o.leftPinCount>0||o.rightPinCount>0){const l=o.leftPinCount+o.rightPinCount;o.leftPinCount=0,o.rightPinCount=0,o.bottomPinCount=Math.ceil(l/2),o.topPinCount=Math.floor(l/2)}}else if(o.bottomPinCount>0||o.topPinCount>0){const l=o.bottomPinCount+o.topPinCount;o.bottomPinCount=0,o.topPinCount=0,o.leftPinCount=Math.ceil(l/2),o.rightPinCount=Math.floor(l/2)}}catch{continue}}return t}var xat=r=>{const e=d=>{const g=new Set;for(const m of r.connections)for(const C of m.connectedPorts)"boxId"in C&&C.boxId===d&&g.add(C.pinNumber);return Array.from(g).sort((m,C)=>m-C)},t=new Map;for(const d of r.connections)for(const g of d.connectedPorts)if("boxId"in g){const m=`${g.boxId}|${g.pinNumber}`;t.has(m)||t.set(m,[]),t.get(m).push(d)}let n="",i=-1;for(const d of r.boxes){const g=(d.leftPinCount??0)+(d.rightPinCount??0)+(d.topPinCount??0)+(d.bottomPinCount??0);(g>i||g===i&&d.boxId<n)&&(n=d.boxId,i=g)}const a={[n]:0},o=new Set([n]),s=new Set,l=new Set;let c=1;const A=[],u=d=>{const g=e(d).slice().reverse();for(const m of g)A.push({boxId:d,pinNumber:m})};for(u(n);A.length;){const{boxId:d,pinNumber:g}=A.pop(),m=`${d}|${g}`;if(l.has(m))continue;l.add(m);const C=[],E=new Set,_=t.get(m)??[];for(const P of _)for(const z of P.connectedPorts)"boxId"in z?z.boxId!==d&&C.push([z.boxId,z.pinNumber]):"netId"in z&&E.add(z.netId);const x=Array.from(E).sort();for(const P of x)s.has(P)||(a[P]=c++,s.add(P));const Q={};for(const[P,z]of C)Q[P]=Q[P]===void 0?z:Math.min(Q[P],z);for(const[P]of Object.entries(Q).sort((z,O)=>{if(z[1]!==O[1])return z[1]-O[1];const V=J=>{const ce=new Set;for(const oe of r.connections){const de=oe.connectedPorts.find(Ie=>"boxId"in Ie&&Ie.boxId===J);if(de&&"pinNumber"in de)for(const Ie of oe.connectedPorts)Ie!==de&&"boxId"in Ie&&"pinNumber"in Ie&&ce.add(Ie.pinNumber)}return Array.from(ce).sort((oe,de)=>oe-de).join(",")},j=V(z[0]),q=V(O[0]);return j.localeCompare(q)}))o.has(P)||(a[P]=c++,o.add(P),u(P))}return a},m2=r=>{const e={boxIdToBoxIndex:{},netIdToNetIndex:{},boxIndexToBoxId:{},netIndexToNetId:{}},t=xat(r),n=r.boxes.map(l=>l.boxId).sort((l,c)=>{const A=t[l]??Number.MAX_SAFE_INTEGER,u=t[c]??Number.MAX_SAFE_INTEGER;return A!==u?A-u:l.localeCompare(c)});n.forEach((l,c)=>{e.boxIdToBoxIndex[l]=c,e.boxIndexToBoxId[c]=l});const i=n.map(l=>{const c=r.boxes.find(A=>A.boxId===l);return{boxIndex:e.boxIdToBoxIndex[l],leftPinCount:c.leftPinCount,rightPinCount:c.rightPinCount,topPinCount:c.topPinCount,bottomPinCount:c.bottomPinCount}}),a=r.nets.map(l=>l.netId).sort((l,c)=>t[l]-t[c]);a.forEach((l,c)=>{e.netIdToNetIndex[l]=c,e.netIndexToNetId[c]=l});const o=a.map(l=>({netIndex:e.netIdToNetIndex[l]})),s=r.connections.map(l=>({connectedPorts:l.connectedPorts.map(A=>"boxId"in A?{boxIndex:e.boxIdToBoxIndex[A.boxId],pinNumber:A.pinNumber}:{netIndex:e.netIdToNetIndex[A.netId]}).sort((A,u)=>{const d="boxIndex"in A,g="boxIndex"in u;return d&&!g?-1:!d&&g?1:d&&g?A.boxIndex!==u.boxIndex?A.boxIndex-u.boxIndex:A.pinNumber-u.pinNumber:A.netIndex-u.netIndex})}));return s.sort((l,c)=>{const A=u=>u.connectedPorts.map(d=>"boxIndex"in d?`b${d.boxIndex}p${d.pinNumber}`:`n${d.netIndex}`).join(",");return A(l).localeCompare(A(c))}),{normalizedNetlist:{boxes:i,nets:o,connections:s},transform:e}};function hY(r){return r.length}var gY=["left","bottom","right","top"],_b=(r,e)=>{let t=0,n=0;for(let i=0;i<r&&t<4;){const a=gY[t],o=e[`${a}PinCount`];if(o===void 0||o===0){t++;continue}if(n>=o){t++,n=0;continue}if(i+1===r){const s={side:a,indexOnSide:n};return a==="left"?s.indexFromTop=n:a==="right"&&(s.indexFromTop=e.rightPinCount-n-1),a==="bottom"?s.indexFromLeft=n:a==="top"&&(s.indexFromLeft=e.topPinCount-n-1),s}n++,i++}throw new Error(`Pin number out of bounds: ${r} with dimensions left=${e.leftPinCount}, right=${e.rightPinCount}, top=${e.topPinCount}, bottom=${e.bottomPinCount}`)},w9=.5,bat=.3,Sat=class{constructor(){Ve(this,"obstacles",[])}addObstacle(r){this.obstacles.push(r)}clearObstacles(){this.obstacles=[]}findPath(r,e){const t=this.worldToGrid(r),n=this.worldToGrid(e),i=new Set,a=new Set,o=new Map,s={point:t,gCost:0,hCost:this.getHeuristic(t,n),fCost:0,parent:null,direction:null};s.fCost=s.gCost+s.hCost;const l=this.pointToKey(t);i.add(l),o.set(l,s);let c=0;const A=200,u=Math.min(this.getHeuristic(t,n)*2,10/w9);for(;i.size>0&&c<A;){c++;let d=Array.from(i)[0],g=o.get(d);for(const C of i){const E=o.get(C);(E.fCost<g.fCost||E.fCost===g.fCost&&E.hCost<g.hCost)&&(d=C,g=E)}if(i.delete(d),a.add(d),g.point.x===n.x&&g.point.y===n.y)return this.reconstructPath(g);if(g.gCost>u)continue;const m=this.getNeighbors(g.point);for(const C of m){const E=this.pointToKey(C);if(a.has(E)||this.isObstacle(C))continue;const _=this.getDirection(g.point,C);let x=1;g.direction&&g.direction!==_&&(x+=bat);const Q=g.gCost+x;if(i.has(E)){const P=o.get(E);Q<P.gCost&&(P.gCost=Q,P.fCost=P.gCost+P.hCost,P.parent=g,P.direction=_)}else{const P={point:C,gCost:Q,hCost:this.getHeuristic(C,n),fCost:0,parent:g,direction:_};P.fCost=P.gCost+P.hCost,i.add(E),o.set(E,P)}}}return c>=A&&console.warn(`Pathfinding exceeded max iterations (${A})`),[]}worldToGrid(r){return{x:Math.round(r.x/w9),y:Math.round(r.y/w9)}}gridToWorld(r){return{x:r.x*w9,y:r.y*w9}}pointToKey(r){return`${r.x},${r.y}`}getHeuristic(r,e){return Math.abs(r.x-e.x)+Math.abs(r.y-e.y)}getNeighbors(r){return[{x:r.x,y:r.y+1},{x:r.x,y:r.y-1},{x:r.x-1,y:r.y},{x:r.x+1,y:r.y}]}getDirection(r,e){return e.y>r.y?"up":e.y<r.y?"down":e.x<r.x?"left":"right"}isObstacle(r){const e=this.gridToWorld(r);return this.obstacles.some(t=>e.x>=t.minX&&e.x<=t.maxX&&e.y>=t.minY&&e.y<=t.maxY)}reconstructPath(r){if(r.gCost*w9>10)return[];const e=[];let t=r;for(;t;)e.unshift(this.gridToWorld(t.point)),t=t.parent;return e}};function Qat(r,e,t,n){for(let a=1;a<10;a++){const o=a/10,s=r.x+(e.x-r.x)*o,l=r.y+(e.y-r.y)*o;if(y2(s,l,t,n))return!1}return!0}function y2(r,e,t,n){for(const i of t.chips){if(i.chipId===n)continue;const a=i.getWidth(),o=i.getHeight(),s=.1;if(r>=i.x-a/2-s&&r<=i.x+a/2+s&&e>=i.y-o/2-s&&e<=i.y+o/2+s)return!0}return!1}function wat(r,e,t,n,i,a){let o=-1/0,s=1/0;for(const g of i.chips){if(g.chipId===a)continue;const m=g.getWidth(),C=g.getHeight(),E=.1,_=g.x-m/2-E,x=g.x+m/2+E,Q=g.y+C/2+E,P=g.y-C/2-E,z=Math.min(r,t),O=Math.max(r,t);x>z&&_<O&&(o=Math.max(o,Q),s=Math.min(s,P))}if(o!==-1/0){const g=o+.5;if(!y2(r,g,i,a)&&!y2(t,g,i,a))return{x:r,y:g};const m=s-.5;if(!y2(r,m,i,a)&&!y2(t,m,i,a))return{x:r,y:m}}const l={x:t,y:e};if(!y2(l.x,l.y,i,a))return l;const c={x:r,y:n};if(!y2(c.x,c.y,i,a))return c;const A=t-r,u=n-e;let d=1;for(;d<4;){const g=r+(A>0?d:-d),m=e+(u>0?d:-d);if(!y2(g,m,i,a))return{x:g,y:m};d+=.5}return{x:r,y:e}}var pY=class{constructor(r,e){Ve(this,"x",0);Ve(this,"y",0);Ve(this,"pathId",null);Ve(this,"lastConnected",null);Ve(this,"lastCreatedLine",null);Ve(this,"lastDx",0);Ve(this,"lastDy",0);Ve(this,"fromJunctionId",null);this.chip=r,this.pinNumber=e}get circuit(){return this.chip.circuit}line(r,e){this.pathId||(this.pathId=this.circuit.addPath().pathId);const t={x:this.x,y:this.y,ref:this.ref};this.x+=r,this.y+=e;const n={x:this.x,y:this.y,ref:this.ref};this.fromJunctionId&&(t.fromJunctionId=this.fromJunctionId,n.fromJunctionId=this.fromJunctionId);const i={start:t,end:n,pathId:this.pathId};return this.circuit.lines.push(i),this.lastDx=r,this.lastDy=e,this.lastCreatedLine=i,this}lineAt(r,e){const t=r-this.x,n=e-this.y;if(t===0&&n===0)return this;if(t===0||n===0)return this.line(t,n);let i;return this.lastCreatedLine===null?this.getPinDirection()==="horizontal"?i="x":i="y":this.lastDx!==0?i="y":i="x",i==="x"?this.line(t,0).line(0,n):this.line(0,n).line(t,0)}pathTo(r,e){const t={x:this.x,y:this.y},n={x:r,y:e};if(t.x===n.x&&t.y===n.y)return this;if(Qat(t,n,this.circuit,this.chip.chipId))return this.lineAt(r,e);const i=new Sat;for(const s of this.circuit.chips){if(s.chipId===this.chip.chipId)continue;const l=s.getWidth(),c=s.getHeight(),A=.1,u={minX:s.x-l/2-A,maxX:s.x+l/2+A,minY:s.y-c/2-A,maxY:s.y+c/2+A};i.addObstacle(u)}if(Math.abs(r-this.x)+Math.abs(e-this.y)<10){const s=i.findPath(t,n);if(s.length>0){for(let l=1;l<s.length;l++){const c=s[l],A=c.x-this.x,u=c.y-this.y;this.line(A,u)}return this}}const o=wat(this.x,this.y,r,e,this.circuit,this.chip.chipId);return this.lineAt(o.x,o.y).lineAt(r,e)}getPinDirection(){const r=this.side;return r==="left"||r==="right"?"horizontal":"vertical"}get side(){const{side:r}=_b(this.pinNumber,this.chip);return r}get ref(){return{boxId:this.chip.chipId,pinNumber:this.pinNumber}}passive(r){const e=this.lastDx===0?"vertical":"horizontal",t=this.circuit.passive(r);e==="horizontal"?t.leftpins(1).rightpins(1):t.bottompins(1).toppins(1);const n=t.getWidth()/2,i=t.getHeight()/2,a=this.x+Math.sign(this.lastDx)*(Math.abs(this.lastDx)>0?n:0),o=this.y+Math.sign(this.lastDy)*(Math.abs(this.lastDy)>0?i:0);t.at(a,o);const s=this.lastDx>0?"left":this.lastDx<0?"right":this.lastDy>0?"bottom":"top",[l,c]=s==="left"||s==="bottom"?[t.pin(1),t.pin(2)]:[t.pin(2),t.pin(1)];return this.lastCreatedLine.end.ref=l.ref,this.lastCreatedLine.end.fromJunctionId=void 0,c}label(r){const e=r??this.circuit.generateAutoLabel(),t=this.circuit.addNetLabel({netId:e,x:this.x,y:this.y,anchorSide:this.lastDx>0?"left":this.lastDx<0?"right":this.lastDy>0?"bottom":"top",fromRef:this.ref});this.lastCreatedLine||this.line(0,0),this.lastCreatedLine.end.ref={netId:e,netLabelId:t.netLabelId},this.lastCreatedLine.end.fromJunctionId=void 0}connect(){return this.circuit.addJunction({pinRef:this.ref,x:this.x,y:this.y}),this}intersect(){const r=this.circuit.addJunction({pinRef:this.ref,x:this.x,y:this.y,showAsIntersection:!0});return this.lastCreatedLine.end.fromJunctionId=r.junctionId,this}intersectsAt(r,e){return this.lineAt(r,e),this.intersect()}connectToMark(r){const t=this.circuit.getMark(r).state;return this.lineAt(t.x,t.y),this.connect()}intersectAtMark(r){const t=this.circuit.getMark(r).state;return this.lineAt(t.x,t.y),this.intersect()}mark(r){return this.chip.addMark(r,this),this}getMarkableState(){return{x:this.x,y:this.y,lastConnected:this.lastConnected,lastDx:this.lastDx,lastDy:this.lastDy}}applyMarkableState(r){this.x=r.x,this.y=r.y,this.lastConnected=r.lastConnected,this.lastDx=r.lastDx,this.lastDy=r.lastDy,this.pathId=this.circuit.addPath().pathId}},mY=class{constructor(r,e,t=!1){Ve(this,"x",0);Ve(this,"y",0);Ve(this,"leftPins",[]);Ve(this,"rightPins",[]);Ve(this,"topPins",[]);Ve(this,"bottomPins",[]);Ve(this,"leftPinCount",0);Ve(this,"rightPinCount",0);Ve(this,"topPinCount",0);Ve(this,"bottomPinCount",0);Ve(this,"pinMap",{});Ve(this,"marks",{});Ve(this,"pinMargins",{});Ve(this,"pinPositionsAreSet",!1);this.circuit=r,this.chipId=e,this.isPassive=t}at(r,e){return this.x=r,this.y=e,this}makePin({side:r,indexOnSide:e,ccwPinNumber:t}){const n=new pY(this,t);return this.pinMap[`${r}${e}`]=n,n}leftpins(r){if(this.pinPositionsAreSet)throw new Error("Pin positions are already set, cannot add new pins");this.leftPinCount=r;for(let e=0;e<r;++e){const t=e+1,n=this.makePin({side:"left",indexOnSide:e,ccwPinNumber:t});this.leftPins.push(n)}return this}rightpins(r){if(this.pinPositionsAreSet)throw new Error("Pin positions are already set, cannot add new pins");this.rightPinCount=r;for(let e=0;e<r;++e){const t=this.leftPinCount+this.bottomPinCount+e+1,n=this.makePin({side:"right",indexOnSide:e,ccwPinNumber:t});this.rightPins.push(n)}return this}toppins(r){if(this.pinPositionsAreSet)throw new Error("Pin positions are already set, cannot add new pins");this.topPinCount=r;for(let e=0;e<r;++e){const t=this.leftPinCount+this.bottomPinCount+this.rightPinCount+e+1,n=this.makePin({side:"top",indexOnSide:e,ccwPinNumber:t});this.topPins.push(n)}return this}bottompins(r){if(this.pinPositionsAreSet)throw new Error("Pin positions are already set, cannot add new pins");this.bottomPinCount=r;for(let e=0;e<r;++e){const t=this.leftPinCount+e+1,n=this.makePin({side:"bottom",indexOnSide:e,ccwPinNumber:t});this.bottomPins.push(n)}return this}getWidth(){return this.isPassive?this.leftPinCount>0||this.rightPinCount>0?this.circuit.defaultPassiveWidth:this.circuit.defaultPassiveHeight:[this.leftPinCount>0?1:0,this.rightPinCount>0?1:0,this.topPinCount>0?1:0,this.bottomPinCount>0?1:0].reduce((e,t)=>e+t,0)===1?this.circuit.defaultSingleSidedChipWidth:this.circuit.defaultChipWidth}getHeight(){return this.isPassive?this.leftPinCount>0||this.rightPinCount>0?this.circuit.defaultPassiveHeight:this.circuit.defaultPassiveWidth:Math.max(this.leftPinCount,this.rightPinCount)*this.circuit.defaultPinSpacing+this.circuit.defaultPinSpacing*2}getCenter(){return this.isPassive?{x:this.x,y:this.y}:{x:this.x+this.getWidth()/2,y:this.y+this.getHeight()/2}}get totalPinCount(){return this.leftPinCount+this.rightPinCount+this.topPinCount+this.bottomPinCount}setPinPositions(){for(let r=1;r<=this.totalPinCount;r++){const e=this._getPin(r),t=this.getPinLocation(r);e.x=t.x,e.y=t.y}this.pinPositionsAreSet=!0}_getPin(r){let e=r;if(e<=this.leftPins.length)return this.leftPins[e-1];if(e-=this.leftPins.length,e<=this.bottomPins.length)return this.bottomPins[e-1];if(e-=this.bottomPins.length,e<=this.rightPins.length)return this.rightPins[e-1];if(e-=this.rightPins.length,e<=this.topPins.length)return this.topPins[e-1];throw new Error(`Pin number ${r} not found`)}pin(r){this.pinPositionsAreSet||this.setPinPositions();const e=this._getPin(r);return e.fromJunctionId=null,e}getPinLocation(r){const{side:e,indexFromTop:t,indexFromLeft:n}=_b(r,this);if(this.isPassive){const l=(this.leftPinCount>0?this.getWidth()/2:0)*(r===1?1:-1),c=(this.bottomPinCount>0?this.getHeight()/2:0)*(r===2?1:-1);return{x:this.x+l,y:this.y+c}}let i,a;const o=this.circuit.defaultPinSpacing,s=.2;if(e==="left"||e==="right"){i=this.x+(e==="left"?0:this.getWidth());let l=t*o;for(let c=0;c<=t;c++){const A=this.getPinNumberFromSideIndex(e,c),u=this.pinMargins[A];u!=null&&u.marginTop&&u.marginTop>s&&(l+=u.marginTop-s)}a=this.y+this.getHeight()-l-this.circuit.defaultPinSpacing*2}else{let l=n*o;for(let c=0;c<=n;c++){const A=this.getPinNumberFromSideIndex(e,c),u=this.pinMargins[A];u!=null&&u.marginLeft&&u.marginLeft>s&&(l+=u.marginLeft-s)}i=this.x+l,a=this.y+(e==="bottom"?0:this.getHeight())}return{x:i,y:a}}addMark(r,e){this.marks[r]={pinBuilder:e,state:e.getMarkableState()}}fromMark(r){if(!this.marks[r])throw new Error(`Mark "${r}" not found`);const{pinBuilder:e,state:t}=this.marks[r],n=this.circuit.addJunction({x:t.x,y:t.y,pinRef:this.marks[r].pinBuilder.ref});return e.applyMarkableState(t),e.fromJunctionId=n.junctionId,e}getPinNumberFromSideIndex(r,e){let t=1;return(r==="bottom"||r==="right"||r==="top")&&(t+=this.leftPinCount),(r==="right"||r==="top")&&(t+=this.bottomPinCount),r==="top"&&(t+=this.rightPinCount),t+=e,t}},Mat=r=>{const e=[];for(const a of r.chips)e.push(a.x),e.push(a.x+4);for(const a of r.lines)e.push(a.start.x,a.end.x);for(const a of r.netLabels)e.push(a.x);for(const a of r.connectionPoints)e.push(a.x);if(e.length===0)return r;const t=Math.min(...e),n=Math.max(...e),i=t+n;for(const a of r.chips){a.x=i-(a.x+4);const o=a.leftPins,s=a.rightPins;a.leftPins=s.slice(),a.rightPins=o.slice().reverse();const l=a.leftPinCount;a.leftPinCount=a.rightPinCount,a.rightPinCount=l}for(const a of r.lines)a.start.x=i-a.start.x,a.end.x=i-a.end.x;for(const a of r.netLabels)a.x=i-a.x;for(const a of r.connectionPoints)a.x=i-a.x;return r},im={left:1,right:2,up:4,down:8};function Dat(r){switch(r){case 0:return" ";case im.left:case im.right:return"─";case im.up:case im.down:return"│";case im.left|im.right:return"─";case im.up|im.down:return"│";case im.left|im.up:return"┘";case im.left|im.down:return"┐";case im.right|im.up:return"└";case im.right|im.down:return"┌";case im.left|im.right|im.up:return"┴";case im.left|im.right|im.down:return"┬";case im.left|im.up|im.down:return"┤";case im.right|im.up|im.down:return"├";case im.left|im.right|im.up|im.down:return"┼";default:return" "}}var Rat=class{constructor(e={}){Ve(this,"traces",new Map);Ve(this,"overlay",new Map);Ve(this,"gridScaleX");Ve(this,"gridScaleY");Ve(this,"showAxisLabels");this.gridScaleX=e.gridScaleX??e.gridScale??1,this.gridScaleY=e.gridScaleY??e.gridScale??1,this.showAxisLabels=e.showAxisLabels??!1}addEdge(e,t,n){const i=Math.round(e*this.gridScaleX),a=Math.round(t*this.gridScaleY),o=`${i},${a}`,s=im[n];this.traces.set(o,(this.traces.get(o)??0)|s)}putOverlay(e,t,n){if(n.length>1)throw new Error("putOverlay only supports single characters");const i=Math.round(e*this.gridScaleX),a=Math.round(t*this.gridScaleY);this.overlay.set(`${i},${a}`,n)}*coords(){const e=new Set;for(const t of this.traces.keys())e.add(t);for(const t of this.overlay.keys())e.add(t);for(const t of e){const[n,i]=t.split(",");yield[Number(n),Number(i)]}}toString(){if(this.traces.size===0&&this.overlay.size===0)return"";let e=1/0,t=-1/0,n=1/0,i=-1/0;for(const[o,s]of this.coords())o<e&&(e=o),o>t&&(t=o),s<n&&(n=s),s>i&&(i=s);const a=[];if(this.showAxisLabels){const o=Math.max(1,Math.round(5*this.gridScaleX));let s=" ";for(let l=e;l<=t;l++)if(l%o===0){const A=(this.gridScaleX!==1?(l/this.gridScaleX).toFixed(1).slice(-4):l).toString();s+=A;for(let u=1;u<o&&l+u<=t;u++)s+=" ";l+=o-1}else s+=" ";a.push(s)}for(let o=i;o>=n;o--){let s="";this.showAxisLabels&&(s=`${(o/this.gridScaleY).toFixed(1).slice(-4).toString().padStart(4," ")} `);for(let l=e;l<=t;l++){const c=`${l},${o}`,A=this.overlay.get(c),u=this.traces.get(c)??0;s+=A??Dat(u)}a.push(s.replace(/ +$/g,""))}return a.join(`
|
|
851
851
|
`)}},Ype=(r,e={})=>{e.chipLabels??(e.chipLabels=!0),e.showAxisLabels??(e.showAxisLabels=!1),e.gridScaleX??(e.gridScaleX=1),e.gridScaleY??(e.gridScaleY=1);const t=e.gridScaleX,n=e.gridScaleY,i=1/t,a=new Rat({showAxisLabels:e.showAxisLabels,gridScaleX:t,gridScaleY:n}),o=[];for(const s of r.chips){if(s.isPassive){o.push(s);continue}const l=s.getWidth(),c=s.getHeight(),A=Math.round(c*e.gridScaleY);if(e.chipLabels&&s.topPinCount===0){const g=s.y+s.getHeight(),m=s.chipId;for(let C=s.x,E=0;E<m.length;E++,C+=i)a.putOverlay(C,g,m[E])}const u=Math.round(s.x*e.gridScaleX),d=Math.round(s.y*e.gridScaleY);for(let g=0;g<A;++g){let m=" ",C=" ",E=" ";const _=g===0,x=g===A-1,Q=l*e.gridScaleX;if(_)m="└",C="─".repeat(Q),E="┘";else if(x)m="┌",C="─".repeat(Q),E="┐";else{const z=d+g;let O,V;for(const J of s.leftPins){const ce=s.getPinLocation(J.pinNumber);if(Math.round(ce.y*e.gridScaleY)===z){O=J;break}}for(const J of s.rightPins){const ce=s.getPinLocation(J.pinNumber);if(Math.round(ce.y*e.gridScaleY)===z){V=J;break}}m=O?"┤":"│",E=V?"├":"│";const j=O?String(O.pinNumber):null,q=V?String(V.pinNumber):null;if(j&&q){const J=Q-j.length-q.length;C=j+" ".repeat(Math.max(1,J))+q}else j?C=j+" ".repeat(Math.max(0,Q-j.length)):q?C=" ".repeat(Math.max(0,Q-q.length))+q:C=" ".repeat(Math.max(0,Q))}const P=m+(C.length===l-2?C:C.padEnd(l-2," "))+E;for(let z=0;z<P.length;++z){const O=(u+z)/e.gridScaleX,V=(d+g)/e.gridScaleY;a.putOverlay(O,V,P[z])}}}for(const s of r.netLabels)if(s.netId.length>0){const l=s.netId[0];a.putOverlay(s.x,s.y,l)}for(const s of r.lines)if(s.start.x===s.end.x){const l=s.start.x,c=s.start.y,A=s.end.y,u=Math.min(c,A),d=Math.max(c,A);if(u===d)continue;a.addEdge(l,c,c<A?"up":"down"),a.addEdge(l,A,c<A?"down":"up");const g=Math.round(u*e.gridScaleY),m=Math.round(d*e.gridScaleY);for(let C=g+1;C<m;C++){const E=C/e.gridScaleY;a.addEdge(l,E,"up"),a.addEdge(l,E,"down")}}else if(s.start.y===s.end.y){const l=s.start.y,c=s.start.x,A=s.end.x,u=Math.min(c,A),d=Math.max(c,A);if(u===d)continue;a.addEdge(c,l,c<A?"right":"left"),a.addEdge(A,l,c<A?"left":"right");const g=Math.round(u*e.gridScaleX),m=Math.round(d*e.gridScaleX);for(let C=g+1;C<m;C++){const E=C/e.gridScaleX;a.addEdge(E,l,"left"),a.addEdge(E,l,"right")}}for(const s of r.connectionPoints)s.showAsIntersection&&a.putOverlay(s.x,s.y,"●");for(const s of o)if(s.leftPinCount>0||s.rightPinCount>0){const c=s.x-s.getWidth()/2,A=s.getWidth()/(1/e.gridScaleX);for(let u=0,d=0;u<s.getWidth();u+=1/e.gridScaleX,d++)A<=3?s.chipId[d]&&a.putOverlay(c+u,s.y,s.chipId[d]):u===0?a.putOverlay(c+u,s.y,"["):u>=s.getWidth()-1/e.gridScaleX?a.putOverlay(c+u,s.y,"]"):s.chipId[d-1]&&a.putOverlay(c+u,s.y,s.chipId[d-1])}else a.putOverlay(s.x,s.y-s.getHeight()/2,"┬"),a.putOverlay(s.x,s.y,s.chipId[0]),s.chipId[1]&&a.putOverlay(s.x+1/e.gridScaleX,s.y,s.chipId[1]),a.putOverlay(s.x,s.y+s.getHeight()/2,"┴");return a},yY=(r,e)=>"boxId"in r&&"boxId"in e?r.boxId===e.boxId&&r.pinNumber===e.pinNumber:"netId"in r&&"netId"in e?r.netId===e.netId:"lineId"in r&&"lineId"in e?r.lineId===e.lineId:!1,Bb=r=>"boxId"in r?`box[${r.boxId}].${r.pinNumber}`:"junctionId"in r?`junction[${r.junctionId}]`:`netlabel[${r.netId},${r.netLabelId}]`,vY=r=>{let e=r.match(/^box\[([^\]]+)\]\.(\d+)$/);if(e)return{boxId:e[1],pinNumber:parseInt(e[2])};if(e=r.match(/^junction\[([^\]]+)\]$/),e)return{junctionId:e[1]};if(e=r.match(/^netlabel\[([^\]]+),([^\]]+)\]$/),e)return{netId:e[1],netLabelId:e[2]};throw new Error(`Invalid ref key: ${r}`)},Nat=r=>{const e=[],t=[],n=[],i=[];for(const a of r.chips){a.pinPositionsAreSet||a.setPinPositions();const o=[],s=[...a.leftPins,...a.bottomPins,...a.rightPins,...a.topPins];for(const c of s){const A=a.getPinLocation(c.pinNumber);o.push({pinNumber:c.pinNumber,x:A.x,y:A.y})}const l=a.getCenter();e.push({boxId:a.chipId,leftPinCount:a.leftPinCount,rightPinCount:a.rightPinCount,topPinCount:a.topPinCount,bottomPinCount:a.bottomPinCount,centerX:l.x,centerY:l.y,pins:o})}for(const a of r.netLabels)t.push({netLabelId:a.netLabelId,netId:a.netId,x:a.x,y:a.y,anchorPosition:a.anchorSide});for(const a of r.paths){const o=r.lines.filter(u=>u.pathId===a.pathId),s=new Set(o.flatMap(u=>[Bb(u.start.fromJunctionId?{junctionId:u.start.fromJunctionId}:u.start.ref),Bb(u.end.fromJunctionId?{junctionId:u.end.fromJunctionId}:u.end.ref)]));let l=Array.from(s);if(l.length===3&&l.some(u=>u.startsWith("junction["))&&(l=l.filter(u=>!u.startsWith("junction["))),l.length>2)throw new Error(`Path composed of "${Array.from(s).join(",")}" has more than 2 references (use a junction instead of connecting multiple points to the same pin)`);if(l.length===1)continue;let[c,A]=l;Bb(o[0].start.ref)===A&&([c,A]=[A,c]),n.push({points:o.flatMap(u=>[{x:u.start.x,y:u.start.y},{x:u.end.x,y:u.end.y}]),from:vY(c),to:vY(A)})}for(const a of r.connectionPoints)i.push({junctionId:a.junctionId,x:a.x,y:a.y});return{boxes:e,netLabels:t,paths:n,junctions:i}},Vpe="ABCDEFGHIJKLMNOPQRSTUVWXYZ",Tat=class HGe{constructor(e={}){Ve(this,"chips",[]);Ve(this,"netLabels",[]);Ve(this,"lines",[]);Ve(this,"paths",[]);Ve(this,"connectionPoints",[]);Ve(this,"defaultChipWidth",2);Ve(this,"defaultSingleSidedChipWidth",2);Ve(this,"defaultPinSpacing",.2);Ve(this,"defaultPassiveWidth",1);Ve(this,"defaultPassiveHeight",.2);Ve(this,"autoLabelCounter",1);Ve(this,"name");Ve(this,"_pathCounter",1);Ve(this,"_netLabelCounter",1);Ve(this,"_junctionCounter",1);this.name=e.name??"Circuit"}clone(){const e=new HGe({name:this.name});e.autoLabelCounter=this.autoLabelCounter,e.defaultChipWidth=this.defaultChipWidth,e.defaultSingleSidedChipWidth=this.defaultSingleSidedChipWidth,e.defaultPinSpacing=this.defaultPinSpacing,e.defaultPassiveWidth=this.defaultPassiveWidth,e.defaultPassiveHeight=this.defaultPassiveHeight;for(const t of this.chips){const n=new mY(e,t.chipId,t.isPassive);n.x=t.x,n.y=t.y,n.leftPinCount=t.leftPinCount,n.rightPinCount=t.rightPinCount,n.topPinCount=t.topPinCount,n.bottomPinCount=t.bottomPinCount,n.pinPositionsAreSet=t.pinPositionsAreSet;const i=(a,o,s)=>Array.from({length:a},(l,c)=>{const A=new pY(n,o+c),u=s[c];return u&&typeof u.x=="number"&&(A.x=u.x),u&&typeof u.y=="number"&&(A.y=u.y),A});n.leftPins=i(n.leftPinCount,1,t.leftPins),n.bottomPins=i(n.bottomPinCount,n.leftPinCount+1,t.bottomPins),n.rightPins=i(n.rightPinCount,n.leftPinCount+n.bottomPinCount+1,t.rightPins),n.topPins=i(n.topPinCount,n.leftPinCount+n.bottomPinCount+n.rightPinCount+1,t.topPins),e.chips.push(n)}return e.lines=structuredClone(this.lines),e.paths=structuredClone(this.paths),e.netLabels=structuredClone(this.netLabels),e.connectionPoints=structuredClone(this.connectionPoints),e}chip(e){e??(e=`U${this.chips.length+1}`);const t=new mY(this,e);return this.chips.push(t),t}passive(e){const t=e??`R${this.chips.length+1}`,n=new mY(this,t,!0);return this.chips.push(n),n}addPath(){const e={pathId:`PATH${this._pathCounter++}`};return this.paths.push(e),e}addNetLabel(e){const t={netLabelId:`NL${this._netLabelCounter++}`,...e};return this.netLabels.push(t),t}addJunction({x:e,y:t,pinRef:n,showAsIntersection:i=!1}){for(const o of this.connectionPoints)if(o.x===e&&o.y===t)return o;const a={junctionId:`XX${this._junctionCounter++}`,x:e,y:t,pinRef:n,showAsIntersection:i};return this.connectionPoints.push(a),a}toString(){return Ype(this,{chipLabels:!0,showAxisLabels:!0,gridScaleX:2,gridScaleY:5}).toString()}getNetlist(){const e=new Cat;for(const o of this.chips)e.addBox({boxId:o.chipId,leftPinCount:o.leftPinCount||0,rightPinCount:o.rightPinCount||0,topPinCount:o.topPinCount||0,bottomPinCount:o.bottomPinCount||0});for(const o of this.netLabels)e.addNet({netId:o.netId}),e.connect(o.fromRef,{netId:o.netId,netLabelId:o.netLabelId});for(const o of this.lines)yY(o.start.ref,o.end.ref)||e.connect(o.start.ref,o.end.ref);const t=(o,s,l)=>{const c=o.get(s)??[];c.push(l),o.set(s,c)},n=new Map;for(const o of this.connectionPoints)t(n,`${o.x},${o.y}`,o.pinRef);const i=new Set;for(const o of this.connectionPoints)i.add(`${o.x},${o.y}`);for(const o of this.lines)t(n,`${o.start.x},${o.start.y}`,o.start.ref),t(n,`${o.end.x},${o.end.y}`,o.end.ref);for(const[o,s]of n.entries())if(i.has(o))for(let l=0;l<s.length;++l)for(let c=l+1;c<s.length;++c)e.connect(s[l],s[c]);const a=(o,s,l)=>{if(l.start.x===l.end.x){if(o!==l.start.x)return!1;const c=Math.min(l.start.y,l.end.y),A=Math.max(l.start.y,l.end.y);return s>=c&&s<=A}else if(l.start.y===l.end.y){if(s!==l.start.y)return!1;const c=Math.min(l.start.x,l.end.x),A=Math.max(l.start.x,l.end.x);return o>=c&&o<=A}return!1};for(const o of this.connectionPoints)for(const s of this.lines)a(o.x,o.y,s)&&e.connect(o.pinRef,s.start.ref);return e.getNetlist()}getReadableNetlist(){return pD(this.getNetlist())}flipX(){return Mat(this)}generateAutoLabel(){return Vpe[this.autoLabelCounter++-1]??`L${this.autoLabelCounter-Vpe.length}`}getGrid(){return Ype(this)}getMark(e){var t;for(const n of this.chips){const i=(t=n.marks)==null?void 0:t[e];if(i)return i}throw new Error(`Mark "${e}" not found in circuit`)}getLayoutJson(){return Nat(this)}};function mS(r={}){return new Tat({name:r.name})}function Pat(r){const e=r.candidateNetlist.boxes[r.candidateBoxIndex],t=r.targetNetlist.boxes[r.targetBoxIndex],n=[];for(const i of gY){const a=e[`${i}PinCount`]??0,o=t[`${i}PinCount`]??0;a!==o&&n.push({type:"matched_box_side_has_wrong_pin_count",candidateBoxIndex:r.candidateBoxIndex,targetBoxIndex:r.targetBoxIndex})}return n}var n8=r=>{const e=r.boxes.map(i=>({boxId:`box${i.boxIndex}`,leftPinCount:i.leftPinCount,rightPinCount:i.rightPinCount,topPinCount:i.topPinCount,bottomPinCount:i.bottomPinCount})),t=r.nets.map(i=>({netId:`net${i.netIndex}`})),n=r.connections.map(i=>({connectedPorts:i.connectedPorts.map(a=>"boxIndex"in a?{boxId:`box${a.boxIndex}`,pinNumber:a.pinNumber}:{netId:`net${a.netIndex}`})}));return{boxes:e,nets:t,connections:n}};function IY(r){const{netlist:e,chipId:t,pinNumber:n}=r,i=`${t}.pin${n}`,a=[{boxId:i,leftPinCount:0,rightPinCount:1,topPinCount:0,bottomPinCount:0}],o=[],s=[],l=new Set([i]),c=new Set;for(const A of e.connections)if(A.connectedPorts.some(d=>"boxId"in d&&d.boxId===t&&d.pinNumber===n)){const d=[{boxId:i,pinNumber:1}];for(const g of A.connectedPorts)if("boxId"in g){if(g.boxId===t&&g.pinNumber===n)continue;if(d.push({boxId:g.boxId,pinNumber:g.pinNumber}),!l.has(g.boxId)){const m=e.boxes.find(C=>C.boxId===g.boxId);m&&a.push(m),l.add(g.boxId)}}else"netId"in g&&(d.push({netId:g.netId}),c.has(g.netId)||(o.push({netId:g.netId}),c.add(g.netId)));d.length>1&&s.push({connectedPorts:d})}return{boxes:a,nets:o,connections:s}}var CY=r=>[r.leftPinCount>0?`L${r.leftPinCount}`:"",r.bottomPinCount>0?`B${r.bottomPinCount}`:"",r.rightPinCount>0?`R${r.rightPinCount}`:"",r.topPinCount>0?`T${r.topPinCount}`:""].join(""),EY=r=>{const{netlist:e,chipId:t,pinNumber:n}=r,i=new Set;for(const a of e.connections)if(a.connectedPorts.some(s=>"boxId"in s&&s.boxId===t&&s.pinNumber===n))for(const s of a.connectedPorts)"boxId"in s&&s.boxId!==t&&i.add(s.boxId);return`box_count_${i.size}`},_Y=r=>{let e;if("pinShapeNetlist"in r)e=r.pinShapeNetlist;else{const{netlist:n,chipId:i,pinNumber:a}=r;e=IY({chipId:i,pinNumber:a,netlist:n})}return`${m2(e).normalizedNetlist.boxes.map(n=>CY(n)).join(",")}`};function Uat(r){const e=n8(r.candidateNetlist),t=n8(r.targetNetlist),n=[],i=e.boxes[r.candidateBoxIndex],a=t.boxes[r.targetBoxIndex],o=i.leftPinCount+i.rightPinCount+i.topPinCount+i.bottomPinCount,s=o===2&&Math.max(i.leftPinCount,i.rightPinCount,i.topPinCount,i.bottomPinCount)===1;for(let d=0;d<o;d++){const g=d+1,m=IY({netlist:e,chipId:i.boxId,pinNumber:g});n.push({side:_b(g,i).side,signature:_Y({pinShapeNetlist:m})})}const l=[...n],c=[],A=a.leftPinCount+a.rightPinCount+a.topPinCount+a.bottomPinCount,u=A===2&&Math.max(a.leftPinCount,a.rightPinCount,a.topPinCount,a.bottomPinCount)===1;for(let d=0;d<A;d++){const g=d+1,m=IY({netlist:t,chipId:a.boxId,pinNumber:g});if(m.connections.length===0)continue;const C={signature:_Y({pinShapeNetlist:m}),side:_b(g,a).side},E=u&&s,_=l.findIndex(x=>x.signature===C.signature&&(x.side===C.side||E));if(_!==-1){l.splice(_,1);continue}c.push({type:"matched_box_missing_pin_shape_on_side",candidateBoxIndex:r.candidateBoxIndex,targetBoxIndex:r.targetBoxIndex,targetPinNumber:g,targetPinShapeSignature:C.signature,candidateShapeSignatures:l.map(x=>x.signature),side:C.side})}return c}function Fat(r){const{candidateNetlist:e,targetNetlist:t,candidateBoxIndex:n,targetBoxIndex:i}=r,a=[],o=n8(e),s=n8(t),l=o.boxes[n],c=s.boxes[i];if(!l||!c)return a;const A=[],u=l.leftPinCount+l.rightPinCount+l.topPinCount+l.bottomPinCount;for(let C=0;C<u;C++){const E=C+1,_=EY({netlist:o,chipId:l.boxId,pinNumber:E});A.push({side:_b(E,l).side,signature:_})}const d=[...A],g=c.leftPinCount+c.rightPinCount+c.topPinCount+c.bottomPinCount;if(u===2&&g===2&&Math.max(l.leftPinCount,l.rightPinCount,l.topPinCount,l.bottomPinCount)===1&&Math.max(c.leftPinCount,c.rightPinCount,c.topPinCount,c.bottomPinCount)===1){const C=A.map(_=>_.signature).filter(_=>_!=="box_count_0").sort(),E=[];for(let _=0;_<g;_++){const x=_+1,Q=EY({netlist:s,chipId:c.boxId,pinNumber:x});Q!=="box_count_0"&&E.push(Q)}E.sort(),C.length>0&&E.length>0&&C.join(",")!==E.join(",")&&a.push({type:"matched_box_missing_pin_shape_box_count_on_side",candidateBoxIndex:n,targetBoxIndex:i,side:"left",targetPinNumber:-1,targetBoxCountSignature:E.join(","),candidateBoxCountSignatures:C})}else for(let C=0;C<g;C++){const E=C+1,_=EY({netlist:s,chipId:c.boxId,pinNumber:E});if(_==="box_count_0")continue;const x={signature:_,side:_b(E,c).side},Q=d.findIndex(P=>P.signature===x.signature&&P.side===x.side);if(Q===-1){const P=A.filter(z=>z.side===x.side).map(z=>z.signature);a.push({type:"matched_box_missing_pin_shape_box_count_on_side",candidateBoxIndex:n,targetBoxIndex:i,side:x.side,targetPinNumber:E,targetBoxCountSignature:_,candidateBoxCountSignatures:P})}else d.splice(Q,1)}return a}var kat=[Pat,Uat,Fat];function Gat(r){const e=[];for(const t of kat)e.push(...t(r));return e}function Kpe(r){if(r.leftPinCount+r.rightPinCount+r.topPinCount+r.bottomPinCount!==2)return!1;const t=r.leftPinCount>0&&r.rightPinCount>0,n=r.topPinCount>0&&r.bottomPinCount>0;return t||n}function Lat(r){return{...r,leftPinCount:r.topPinCount,rightPinCount:r.bottomPinCount,topPinCount:r.leftPinCount,bottomPinCount:r.rightPinCount}}function Oat(r){return{...r,leftPinCount:r.rightPinCount,rightPinCount:r.leftPinCount,topPinCount:r.bottomPinCount,bottomPinCount:r.topPinCount}}function zat(r){const{targetNetlist:e,candidateNetlist:t,targetBoxIndex:n,candidateBoxIndex:i}=r,a=e.boxes[n],o=t.boxes[i];if(!a||!o)return[{netlist:e,rotation:0}];if(!Kpe(a)||!Kpe(o))return[{netlist:e,rotation:0}];const s=[];let l={...a},c=0;for(let m=0;m<4&&!(l.leftPinCount===o.leftPinCount&&l.rightPinCount===o.rightPinCount&&l.topPinCount===o.topPinCount&&l.bottomPinCount===o.bottomPinCount);m++)l=Lat(l),c=(c+90)%360;const A={...e,boxes:e.boxes.map((m,C)=>C===n?l:m)};s.push({netlist:A,rotation:c});const u=Oat(l),d={...e,boxes:e.boxes.map((m,C)=>C===n?u:m)},g=(c+180)%360;return s.push({netlist:d,rotation:g}),s}function r8(r){const{candidateNetlist:e,targetNetlist:t}=r,n=[],i=new Set;for(let a=0;a<t.boxes.length;a++){const o=new Map;for(let c=0;c<e.boxes.length;c++){if(i.has(c))continue;const A=zat({targetNetlist:t,candidateNetlist:e,targetBoxIndex:a,candidateBoxIndex:c});let u=[],d=1/0,g=0;for(const{netlist:m,rotation:C}of A){const E=Gat({candidateNetlist:e,targetNetlist:m,candidateBoxIndex:c,targetBoxIndex:a,alreadyMatchedBoxes:n}),_=hY(E);_<d&&(d=_,u=E,g=C)}o.set({targetBoxIndex:a,candidateBoxIndex:c},{issues:u,similarityDistance:d,rotation:g})}let s=null,l=1/0;for(const[c,{similarityDistance:A}]of o.entries())A<l&&(l=A,s=c);if(s){const{candidateBoxIndex:c}=s,{issues:A,similarityDistance:u,rotation:d}=o.get(s);i.add(c),n.push({targetBoxIndex:a,candidateBoxIndex:c,issues:A,score:u,targetBoxRotationCcw:d})}}return n}function BY(r){return r==="left"?{dx:-1,dy:0}:r==="right"?{dx:1,dy:0}:r==="top"?{dx:0,dy:1}:{dx:0,dy:-1}}function Hat(r,e){const{chipId:t,pinNumber:n,netName:i}=e,a=r.chips.find(u=>u.chipId===t);if(!a||n<1||n>a.totalPinCount)return;const o=a.pin(n);if(!o||typeof o.line!="function")return;const{side:s}=_b(n,a),{dx:l,dy:c}=BY(s);o.line(l*2,c*2);const A=i||r.generateAutoLabel();o.label(A)}function Yat(r,e){const{chipId:t,pinNumber:n}=e,i=a=>"boxId"in a&&a.boxId===t&&a.pinNumber===n;r.lines=r.lines.filter(a=>!i(a.start.ref)&&!i(a.end.ref)),r.connectionPoints=r.connectionPoints.filter(a=>!i(a.pinRef)),r.netLabels=r.netLabels.filter(a=>!i(a.fromRef))}function Vat(r,e){const{chipId:t,pinNumber:n}=e,i=r.chips.find(o=>o.chipId===t);if(!i)return;const a=i.pin(n);if(a.lastDx===0&&a.lastDy===0&&!a.lastCreatedLine){const o=BY(a.side);a.line(o.dx*2,o.dy*2)}a.passive()}function Kat(r,e){const{chipId:t,pinNumber:n,labelNetId:i}=e,a=r.chips.find(l=>l.chipId===t);if(!a)return;const o=a.pin(n);if(o.lastDx===0&&o.lastDy===0&&!o.lastCreatedLine){const l=BY(o.side);o.line(l.dx*2,l.dy*2)}o.passive().label(i)}function Jat(r,e){const{chipId:t}=e;r.chips=r.chips.filter(a=>a.chipId!==t);const n=a=>"boxId"in a&&a.boxId===t,i=r.lines.filter(a=>n(a.start.ref)||n(a.end.ref));r.lines=r.lines.filter(a=>!(n(a.start.ref)&&n(a.end.ref)));for(const a of i){if(n(a.start.ref)&&n(a.end.ref))continue;const o=n(a.start.ref)?a.start:a.end,s=n(a.start.ref)?a.end:a.start;Jpe(r,s.x,s.y,a)?r.lines=r.lines.filter(c=>c!==a):(r.lines=r.lines.filter(c=>c!==a),jpe(r,s.x,s.y,s.ref,o.ref))}r.connectionPoints=r.connectionPoints.filter(a=>!n(a.pinRef)),r.netLabels=r.netLabels.filter(a=>!n(a.fromRef))}function Jpe(r,e,t,n){let i=0;for(const a of r.lines)a!==n&&(a.start.x===e&&a.start.y===t||a.end.x===e&&a.end.y===t)&&i++;for(const a of r.connectionPoints)if(a.x===e&&a.y===t){i++;break}return i>=2}function jpe(r,e,t,n,i){const a=r.lines.filter(o=>{const s=o.start.x===e&&o.start.y===t&&!yY(o.start.ref,i),l=o.end.x===e&&o.end.y===t&&!yY(o.end.ref,i);return s||l});for(const o of a){const s=o.start.x===e&&o.start.y===t?o.end:o.start;if(Jpe(r,s.x,s.y,o))return;r.lines=r.lines.filter(c=>c!==o),jpe(r,s.x,s.y,s.ref,i)}}var jat=(r,e,t)=>{const n=i=>"boxId"in i&&i.boxId===e&&t.has(i.pinNumber)?{...i,pinNumber:t.get(i.pinNumber)}:i;for(const i of r.lines)i.start.ref=n(i.start.ref),i.end.ref=n(i.end.ref);for(const i of r.connectionPoints)i.pinRef=n(i.pinRef);for(const i of r.netLabels)i.fromRef=n(i.fromRef)};function Wat(r,e){const{chipId:t,side:n,pinNumber:i}=e,a=r.chips.find(Q=>Q.chipId===t);if(!a)return;const o=a.totalPinCount;if(i<1||i>o)throw new Error(`Invalid pin number: ${i} for chip ${a.chipId} with dimensions ${a.leftPinCount}x${a.bottomPinCount}x${a.rightPinCount}x${a.topPinCount}`);a.pinPositionsAreSet||a.setPinPositions();const s=new Map;for(let Q=1;Q<=o;++Q)s.set(Q,a.getPinLocation(Q));const l=Q=>"boxId"in Q&&Q.boxId===t&&Q.pinNumber===i;r.lines=r.lines.filter(Q=>!l(Q.start.ref)&&!l(Q.end.ref)),r.connectionPoints=r.connectionPoints.filter(Q=>!l(Q.pinRef)),r.netLabels=r.netLabels.filter(Q=>!l(Q.fromRef));let c,A;switch(n){case"left":c=a.leftPins,A="leftPinCount";break;case"right":c=a.rightPins,A="rightPinCount";break;case"top":c=a.topPins,A="topPinCount";break;case"bottom":c=a.bottomPins,A="bottomPinCount";break;default:return}const u=c.findIndex(Q=>Q.pinNumber===i);if(u===-1)throw new Error(`Pin number ${i} not found on side ${n} of chip ${a.chipId}`);c.splice(u,1),a[A]--;const d=new Map;for(let Q=1;Q<=o;++Q)Q!==i&&(Q<i?d.set(Q,Q):d.set(Q,Q-1));const g=[...a.leftPins,...a.bottomPins,...a.rightPins,...a.topPins];for(const Q of g){const P=Q.pinNumber,z=d.get(P);z!==void 0&&(Q.pinNumber=z)}const{side:m,indexOnSide:C}=_b(i,{leftPinCount:a.leftPinCount+(n==="left"?1:0),rightPinCount:a.rightPinCount+(n==="right"?1:0),topPinCount:a.topPinCount+(n==="top"?1:0),bottomPinCount:a.bottomPinCount+(n==="bottom"?1:0)}),E={};for(const[Q,P]of d.entries())a.pinMargins[Q]&&(E[P]={...a.pinMargins[Q]});for(const[Q,P]of d.entries()){const z=_b(Q,{leftPinCount:a.leftPinCount+(n==="left"?1:0),rightPinCount:a.rightPinCount+(n==="right"?1:0),topPinCount:a.topPinCount+(n==="top"?1:0),bottomPinCount:a.bottomPinCount+(n==="bottom"?1:0)});if(z.side===m&&z.indexOnSide>C){const O=E[P]||{marginTop:.2,marginLeft:.2};n==="left"||n==="right"?E[P]={...O,marginTop:O.marginTop+.2}:E[P]={...O,marginLeft:O.marginLeft+.2}}}a.pinMargins=E;const _=new Map;for(const[Q,P]of d.entries())Q!==P&&_.set(Q,P);_.size>0&&jat(r,a.chipId,_),a.pinPositionsAreSet=!1,a.setPinPositions();const x=new Map;for(let Q=1;Q<=o;++Q){if(Q===i)continue;const P=d.get(Q),z=s.get(Q),O=a.getPinLocation(P),V=O.x-z.x,j=O.y-z.y;(V!==0||j!==0)&&x.set(P,{dx:V,dy:j})}if(x.size>0){const Q=P=>"boxId"in P&&P.boxId===t&&x.has(P.pinNumber)?x.get(P.pinNumber):null;for(const P of r.lines){const z=Q(P.start.ref),O=Q(P.end.ref);(z??O)&&(z&&(P.start.x+=z.dx,P.start.y+=z.dy),O&&(P.end.x+=O.dx,P.end.y+=O.dy))}for(const P of r.connectionPoints){const z=Q(P.pinRef);z&&(P.x+=z.dx,P.y+=z.dy)}for(const P of r.netLabels){const z=Q(P.fromRef);z&&(P.x+=z.dx,P.y+=z.dy)}}}var Zat=(r,e,t)=>{const n=i=>"boxId"in i&&i.boxId===e&&t.has(i.pinNumber)?{...i,pinNumber:t.get(i.pinNumber)}:i;for(const i of r.lines)i.start.ref=n(i.start.ref),i.end.ref=n(i.end.ref);for(const i of r.connectionPoints)i.pinRef=n(i.pinRef);for(const i of r.netLabels)i.fromRef=n(i.fromRef)};function qat(r,e){const{chipId:t,side:n,betweenPinNumbers:i}=e,a=r.chips.find(Q=>Q.chipId===t);if(!a)return;const o=a.totalPinCount,s=new Map;for(let Q=1;Q<=o;++Q)s.set(Q,a.getPinLocation(Q));const l=Math.min(...i),c=n==="left"?a.leftPins:n==="right"?a.rightPins:n==="top"?a.topPins:a.bottomPins,A=c.findIndex(Q=>Q.pinNumber===l)+1;if(l!==0&&A===0)return;a[`${n}PinCount`]+=1;const u=l+1,d=new pY(a,u);c.splice(A,0,d);const g=new Map,m=a.totalPinCount-1;for(let Q=1;Q<=m;++Q)Q>l&&g.set(Q,Q+1);const C=new Set([d]),E=Q=>Q.forEach(P=>{C.has(P)||g.has(P.pinNumber)&&(P.pinNumber=g.get(P.pinNumber))});E(a.leftPins),E(a.rightPins),E(a.topPins),E(a.bottomPins),Zat(r,t,g),a.pinPositionsAreSet=!1,a.setPinPositions();const _=new Map;for(let Q=1;Q<=o;++Q){const P=s.get(Q),z=g.get(Q)??Q,O=a.getPinLocation(z),V=O.x-P.x,j=O.y-P.y;(V||j)&&_.set(z,{dx:V,dy:j})}const x=Q=>"boxId"in Q&&Q.boxId===t&&_.has(Q.pinNumber)?_.get(Q.pinNumber):null;for(const Q of r.lines){const P=x(Q.start.ref)??x(Q.end.ref);P&&(Q.start.x+=P.dx,Q.start.y+=P.dy,Q.end.x+=P.dx,Q.end.y+=P.dy)}for(const Q of r.connectionPoints){const P=x(Q.pinRef);P&&(Q.x+=P.dx,Q.y+=P.dy)}for(const Q of r.netLabels){const P=x(Q.fromRef);P&&(Q.x+=P.dx,Q.y+=P.dy)}}function Xat(r,e){const t=r.chips.find(i=>i.chipId===e.chipId);if(!t)throw new Error(`Chip ${e.chipId} not found`);if(!t.isPassive)throw new Error(`Chip ${e.chipId} is not a passive component`);if(t.totalPinCount!==2)throw new Error(`Passive orientation change only supports 2-pin passives, got ${t.totalPinCount} pins`);(t.leftPinCount>0||t.rightPinCount>0?"horizontal":"vertical")!==e.toOrientation&&(e.toOrientation==="horizontal"?(t.leftPinCount=1,t.rightPinCount=1,t.bottomPinCount=0,t.topPinCount=0,t.leftPins=[t.bottomPins[0]||t.topPins[0]],t.rightPins=[t.topPins[0]||t.bottomPins[0]],t.bottomPins=[],t.topPins=[]):(t.bottomPinCount=1,t.topPinCount=1,t.leftPinCount=0,t.rightPinCount=0,t.bottomPins=[t.leftPins[0]||t.rightPins[0]],t.topPins=[t.rightPins[0]||t.leftPins[0]],t.leftPins=[],t.rightPins=[]))}function $at(r,e){const{fromChipId:t,fromPinNumber:n,toChipId:i,toPinNumber:a,netName:o}=e,s=r.chips.find(g=>g.chipId===t),l=r.chips.find(g=>g.chipId===i);if(!s)throw new Error(`Could not find from chip with id: ${t}`);if(!l)throw new Error(`Could not find to chip with id: ${i}`);const c=s.pin(n),A=l.pin(a);if(!c)throw new Error(`Could not find pin ${n} on chip ${t}`);if(!A)throw new Error(`Could not find pin ${a} on chip ${i}`);const u=l.getPinLocation(a),d=o||`connection_${t}_${n}_to_${i}_${a}`;c.pathTo(u.x,u.y).mark(d),A.connectToMark(d)}function M9(r,e){switch(e.type){case"add_label_to_pin":Hat(r,e);break;case"add_passive_to_pin":Vat(r,e);break;case"add_passive_with_label_to_pin":Kat(r,e);break;case"clear_pin":Yat(r,e);break;case"add_pin_to_side":qat(r,e);break;case"remove_pin_from_side":Wat(r,e);break;case"remove_chip":Jat(r,e);break;case"change_passive_orientation":Xat(r,e);break;case"draw_line_between_pins":$at(r,e);break}}function mD(r){const e=[],{template:t,target:n}=r,i=t.getNetlist(),a=m2(i),o=m2(n),s=a.normalizedNetlist,l=o.normalizedNetlist,c=r8({candidateNetlist:s,targetNetlist:l}).map(A=>{var u,d;return{...A,candidateChipId:(u=Object.entries(a.transform.boxIdToBoxIndex).find(([g,m])=>m===A.candidateBoxIndex))==null?void 0:u[0],targetChipId:(d=Object.entries(o.transform.boxIdToBoxIndex).find(([g,m])=>m===A.targetBoxIndex))==null?void 0:d[0]}});for(const A of t.chips){if(c.some(g=>g.candidateChipId===A.chipId))continue;const d={type:"remove_chip",chipId:A.chipId};M9(t,d),e.push(d);break}return{appliedOperations:e,matchedBoxes:c}}function eot(r){const{template:e,target:t,matchedBoxes:n}=r,i=[],a=t.boxes;for(const{candidateChipId:o,targetChipId:s}of n){const l=e.chips.find(A=>A.chipId===o),c=a.find(A=>A.boxId===s);if(!(!c||!l)&&!l.isPassive)for(const A of gY){const u=c[`${A}PinCount`];if(l[`${A}PinCount`]<u){let d;A==="left"?d=0:A==="bottom"?d=l.leftPinCount+l.bottomPinCount:A==="right"?d=l.leftPinCount+l.bottomPinCount+l.rightPinCount:d=l.totalPinCount;const g={type:"add_pin_to_side",chipId:l.chipId,side:A,betweenPinNumbers:[d,d+1]};return M9(e,g),i.push(g),{appliedOperations:i}}if(l[`${A}PinCount`]>u){const d=tot({template:e,target:t,chipId:l.chipId,side:A}),g={type:"remove_pin_from_side",chipId:l.chipId,side:A,pinNumber:d};return M9(e,g),i.push(g),{appliedOperations:i}}}}return{appliedOperations:i}}function tot(r){const{template:e,target:t,chipId:n,side:i}=r,a=e.chips.find(A=>A.chipId===n);if(!a)throw new Error(`Chip ${n} not found`);const s={left:a.leftPins,right:a.rightPins,top:a.topPins,bottom:a.bottomPins}[i];if(s.length===0)throw new Error(`No pins found on side ${i} of chip ${n}`);let l=s[s.length-1].pinNumber,c=Number.POSITIVE_INFINITY;for(const A of s)try{const u=e.clone(),d={type:"remove_pin_from_side",chipId:n,side:i,pinNumber:A.pinNumber};M9(u,d);const g=not(u,t);g<c&&(c=g,l=A.pinNumber)}catch{continue}return l}function not(r,e){try{const t=m2(r.getNetlist()),n=m2(e),a=r8({candidateNetlist:t.normalizedNetlist,targetNetlist:n.normalizedNetlist}).flatMap(o=>o.issues||[]);return hY(a)}catch{return Number.POSITIVE_INFINITY}}function rot(r){const{template:e,target:t,matchedBoxes:n}=r,i=[];for(const{candidateChipId:a,targetChipId:o}of n){const s=e.chips.find(A=>A.chipId===a),l=t.boxes.find(A=>A.boxId===o);if(!l||!s)continue;const c=["left","right","top","bottom"];for(const A of c){const u=s[`${A}PinCount`],d=l[`${A}PinCount`]||0;if(u>d){const g=u-d,m=iot({template:e,chipId:a,side:A,pinsToRemove:g});if(m.length>0){const C=m[0];return M9(e,C),i.push(C),{appliedOperations:i}}}}}return{appliedOperations:i}}function iot(r){const{template:e,chipId:t,side:n,pinsToRemove:i}=r,a=e.chips.find(c=>c.chipId===t);if(!a)return[];const s={left:a.leftPins,right:a.rightPins,top:a.topPins,bottom:a.bottomPins}[n];if(s.length<=i)return s.map(c=>({type:"remove_pin_from_side",chipId:t,side:n,pinNumber:c.pinNumber}));const l=s[s.length-1];return[{type:"remove_pin_from_side",chipId:t,side:n,pinNumber:l.pinNumber}]}function aot(r){const e=[],{template:t,target:n,matchedBoxes:i}=r,a=n.connections||[];for(const o of a){const s=o.connectedPorts.filter(_=>"boxId"in _);if(s.length!==2)continue;const[l,c]=s;if(!l||!c)continue;const A=i.find(_=>{var x,Q;return((Q=(x=n.boxes)==null?void 0:x[_.targetBoxIndex])==null?void 0:Q.boxId)===l.boxId}),u=i.find(_=>{var x,Q;return((Q=(x=n.boxes)==null?void 0:x[_.targetBoxIndex])==null?void 0:Q.boxId)===c.boxId});if(!(A!=null&&A.candidateChipId)||!(u!=null&&u.candidateChipId))continue;const d=A.candidateChipId,g=u.candidateChipId;if(!(t.getNetlist().connections||[]).some(_=>{const x=_.connectedPorts.filter(z=>"boxId"in z),Q=x.some(z=>z.boxId===d&&z.pinNumber===l.pinNumber),P=x.some(z=>z.boxId===g&&z.pinNumber===c.pinNumber);return Q&&P})){const _={type:"draw_line_between_pins",fromChipId:d,fromPinNumber:l.pinNumber,toChipId:g,toPinNumber:c.pinNumber};try{M9(t,_),e.push(_);break}catch(x){console.warn("Failed to apply draw line operation:",x)}}}return{appliedOperations:e}}var oot=class extends S9{constructor(e){super();Ve(this,"inputTemplate");Ve(this,"targetNetlist");Ve(this,"transformedTarget",null);Ve(this,"outputAdaptedTemplate",null);Ve(this,"outputAppliedOperations",[]);Ve(this,"phase","transform-target");Ve(this,"matchedBoxes",[]);Ve(this,"stepCount",0);Ve(this,"maxSteps",100);this.inputTemplate=e.inputTemplate,this.targetNetlist=e.targetNetlist}getConstructorParams(){return{inputTemplate:this.inputTemplate,targetNetlist:this.targetNetlist}}getStatsSummary(){return`Phase: ${this.phase}, ${this.outputAppliedOperations.length} operations applied`}_step(){var e,t;if(this.stepCount++,this.stepCount>this.maxSteps){console.warn(`AdaptTemplateToNetlistSolver exceeded max steps (${this.maxSteps}), stopping`),this.solved=!0;return}switch(this.outputAdaptedTemplate||(this.outputAdaptedTemplate=this.inputTemplate.clone()),this.phase){case"transform-target":this.transformedTarget=Bat(this.outputAdaptedTemplate,this.targetNetlist),this.phase="remove-unmatched-chips-1";break;case"remove-unmatched-chips-1":{const n=mD({template:this.outputAdaptedTemplate,target:this.transformedTarget});if(this.matchedBoxes=n.matchedBoxes,n.appliedOperations.length>0){const i=n.appliedOperations[0];this.outputAppliedOperations.push(i)}else this.phase="fix-matched-box-pin-counts";break}case"fix-matched-box-pin-counts":{const n=mD({template:this.outputAdaptedTemplate,target:this.transformedTarget}),i=eot({template:this.outputAdaptedTemplate,target:this.transformedTarget,matchedBoxes:n.matchedBoxes});if(i.appliedOperations.length>0){const a=i.appliedOperations[0];this.outputAppliedOperations.push(a)}else this.phase="fix-matched-box-pin-shapes";break}case"fix-matched-box-pin-shapes":{const n=mD({template:this.outputAdaptedTemplate,target:this.transformedTarget}),i=rot({template:this.outputAdaptedTemplate,target:this.transformedTarget,matchedBoxes:n.matchedBoxes});if(i.appliedOperations.length>0){const a=i.appliedOperations[0];this.outputAppliedOperations.push(a)}else this.phase="remove-unmatched-chips-2";break}case"remove-unmatched-chips-2":{const n=mD({template:this.outputAdaptedTemplate,target:this.transformedTarget});if(n.appliedOperations.length>0){const i=n.appliedOperations[0];this.outputAppliedOperations.push(i)}else this.phase="draw-missing-connections";break}case"draw-missing-connections":{const n=mD({template:this.outputAdaptedTemplate,target:this.transformedTarget}),i=aot({template:this.outputAdaptedTemplate,target:this.transformedTarget,matchedBoxes:n.matchedBoxes});if(i.appliedOperations.length>0){const a=i.appliedOperations[0];this.outputAppliedOperations.push(a)}else this.phase="complete";break}case"complete":this.stats={operationCount:this.outputAppliedOperations.length,templateBoxCount:((e=this.outputAdaptedTemplate.getNetlist().boxes)==null?void 0:e.length)||0,targetBoxCount:((t=this.targetNetlist.boxes)==null?void 0:t.length)||0},this.solved=!0;break}}visualize(){var e,t;return[{title:"inputTemplate",ascii:this.inputTemplate.toString()},{title:"targetNetlist",ascii:pD(this.targetNetlist)},{title:"adaptedTemplate",ascii:((e=this.outputAdaptedTemplate)==null?void 0:e.toString())||"No adapted template"},{title:"appliedOperations",table:this.outputAppliedOperations.map((n,i)=>({operation_index:i,type:n.type,details:n}))},{title:"inputTemplateReadableNetlist",ascii:this.inputTemplate.getReadableNetlist()},{title:"adaptedTemplateReadableNetlist",ascii:((t=this.outputAdaptedTemplate)==null?void 0:t.getReadableNetlist())||"No adapted template"}]}},sot=class extends S9{constructor(e){super();Ve(this,"matchedTemplates");Ve(this,"adaptationSolvers",[]);Ve(this,"currentAdaptationIndex",0);Ve(this,"outputAdaptedTemplates",[]);this.matchedTemplates=e.matchedTemplates,this.adaptationSolvers=this.matchedTemplates.map(t=>new oot({inputTemplate:t.template,targetNetlist:t.netlist})),this.setActiveSubSolver(this.adaptationSolvers[this.currentAdaptationIndex])}getConstructorParams(){return{matchedTemplates:this.matchedTemplates}}computeProgress(){return this.adaptationSolvers.length===0?1:this.currentAdaptationIndex/this.adaptationSolvers.length}_step(){if(this.currentAdaptationIndex<this.adaptationSolvers.length){const e=this.adaptationSolvers[this.currentAdaptationIndex];if(!e.solved&&!e.failed){e.step();return}this.clearActiveSubSolver(),e.solved&&e.outputAdaptedTemplate&&this.outputAdaptedTemplates.push({template:e.outputAdaptedTemplate,netlist:this.matchedTemplates[this.currentAdaptationIndex].netlist,appliedOperations:e.outputAppliedOperations}),this.currentAdaptationIndex++,this.setActiveSubSolver(this.adaptationSolvers[this.currentAdaptationIndex]);return}this.solved=!0}},lot=()=>{const r=mS({name:"Template 1"}),e=r.chip().leftpins(2).rightpins(2);return e.pin(1).line(-8,0).line(0,-2).passive().line(0,-2).label(),e.pin(2).line(-3,0).line(0,-2).label(),e.pin(3).line(4,0).label(),e.pin(4).line(4,0).label(),r},cot=()=>{const r=mS({name:"Template 2"}),e=r.chip("J1").rightpins(7);return e.pin(7).line(2,0).line(0,1).label("VUSB"),e.pin(6).line(3,0).line(0,.4).line(2,0).passive("R9").line(1,0).label("P"),e.pin(5).line(5,0).passive("R0").line(1,0).label("M"),e.pin(4).line(5,0).line(0,-.6).passive("R2").line(0,-1).label("GND"),e.pin(3).line(3,0).line(0,-.4).passive("R1").line(0,-1).label("GND"),e.pin(2).line(1,0).line(0,-2.2).label("GND"),e.pin(1).line(1,0).intersect(),r},Aot=()=>{const r=mS({name:"Template 3"}),e=r.chip().rightpins(3);return e.pin(3).line(4,0).mark("m0").line(3,0).mark("m1").line(0,1).label(),e.fromMark("m1").line(0,-2).passive().line(0,-3).label(),e.pin(2).line(2,0).line(0,-4).line(2,0).line(0,1.2).passive().line(0,2).intersectAtMark("m0"),e.pin(1).line(1,0).line(0,-3).label(),r},uot=()=>{const r=mS({name:"Template 4"}),e=r.chip().rightpins(3);return e.pin(3).line(4,0).mark("m1").line(0,2).label(),e.fromMark("m1").line(0,-2).passive().line(0,-2).label(),e.pin(2).line(2,0).label(),e.pin(1).line(1,0).line(0,-2).label(),r},dot=()=>{const r=mS({name:"Template 5"}),e=r.chip().leftpins(2).rightpins(2).at(0,0),t=r.chip().leftpins(1).rightpins(1).at(10,.2);return e.pin(4).line(3,0).mark("bus"),t.pin(1).connectToMark("bus"),r},fot=()=>{const r=mS({name:"Template 6"}),e=r.chip("U2").leftpins(3).rightpins(3).at(0,0);return e.pin(1).line(-1.9,0).mark("vin1").line(-1,0).mark("vin2").line(0,.8).label(),e.fromMark("vin2").line(0,-.4).passive("C1").line(0,-1).label("GND"),e.fromMark("vin1").line(0,-.4).passive("R3").line(0,-.4).mark("en1").line(-.2,0).label(),e.pin(2).line(-1,0).intersectAtMark("en1"),e.pin(3).line(-.5,0).line(0,-2).label("GND"),e.pin(6).line(1,0).mark("VOUT").line(0,-.4).passive("C2").line(0,-1).label("GND"),e.fromMark("VOUT").line(0,.8).label(),r},hot=()=>{const r=mS({name:"Template 7"}),e=r.chip("U1").leftpins(3).rightpins(3).at(0,0),t=r.chip("J2").leftpins(2).at(9,.2);return e.pin(1).line(-2,0).mark("VUSB1").line(-1,0).mark("VUSB2").line(0,.2).label("VUSB"),e.fromMark("VUSB2").line(0,-.4).passive("C3").line(0,-.2).label("GND"),e.fromMark("VUSB1").line(0,-.2).passive("D4").line(0,-.2).mark("belowD4"),e.pin(3).line(-1,0).line(0,-.2).passive("R5").line(0,-.2).connectToMark("belowD4"),e.pin(4).line(1,0).line(0,-1.2).line(1,0).mark("GND1").line(1,0).mark("GND2").line(2,0).mark("aboveGND").line(0,-.2).label("GND"),e.pin(5).line(2,0).line(0,-.2).passive("R6").connectToMark("GND1"),e.pin(6).line(2,0).mark("belowVBat").line(1,0).mark("aboveC4"),e.fromMark("belowVBat").line(0,.2).label("VBAT"),t.pin(1).connectToMark("aboveC4"),e.fromMark("aboveGND").line(0,.8).mark("aboveGND2"),e.fromMark("aboveC4").line(0,-.4).passive("C4").connectToMark("GND2"),t.pin(2).connectToMark("aboveGND2"),r},got=()=>{const r=mS({name:"Template 8"}),e=r.chip("U1").leftpins(4).at(0,0);return e.pin(1).line(-2,0).label("SCL"),e.pin(2).line(-2,0).label("SDA"),e.pin(3).line(-1,0).line(0,.8).label("V3_3"),e.pin(4).line(-1,0).line(0,-.4).label("GND"),r},pot=()=>{const r=mS({name:"Template 9"}),e=r.chip("U3").leftpins(6).rightpins(6);return e.pin(1).line(-1,0).mark("aboveC2").line(0,-.001).passive("C20").line(0,-.001).mark("GND1").line(0,-.2).label("GND"),e.fromMark("aboveC2").line(0,.2).label("V3_3"),e.pin(6).intersectAtMark("GND1"),e.pin(7).line(2,0).line(0,.2).mark("rightOf7").line(0,2).label("V3_3"),e.pin(8).intersectAtMark("rightOf7"),e.pin(9).line(3,0).label(),e.pin(10).line(3,0).label(),e.pin(11).line(3,0).label(),e.pin(12).line(1,0).mark("rightOfNCS").line(2,0).label(),e.fromMark("rightOfNCS").line(0,.2).passive("R11").line(0,.2).label("V3_3"),r},mot={template1:lot,template2:cot,template3:Aot,template4:uot,template5:dot,template6:fot,template7:hot,template8:got,template9:pot},yot=Object.values(mot);function Wpe(r,e){switch(e){case 0:return r;case 90:return{...r,leftPinCount:r.bottomPinCount,rightPinCount:r.topPinCount,topPinCount:r.leftPinCount,bottomPinCount:r.rightPinCount};case 180:return{...r,leftPinCount:r.rightPinCount,rightPinCount:r.leftPinCount,topPinCount:r.bottomPinCount,bottomPinCount:r.topPinCount};case 270:return{...r,leftPinCount:r.topPinCount,rightPinCount:r.bottomPinCount,topPinCount:r.rightPinCount,bottomPinCount:r.leftPinCount};default:return r}}function vot(r,e,t){if(t===0)return r;const{side:n,indexOnSide:i}=_b(r,e),a=Wpe(e,t);let o;switch(t){case 90:switch(n){case"left":o="top";break;case"bottom":o="left";break;case"right":o="bottom";break;case"top":o="right";break;default:o=n}break;case 180:switch(n){case"left":o="right";break;case"right":o="left";break;case"top":o="bottom";break;case"bottom":o="top";break;default:o=n}break;case 270:switch(n){case"left":o="bottom";break;case"bottom":o="right";break;case"right":o="top";break;case"top":o="left";break;default:o=n}break;default:o=n}let s=i;const l=e[`${n}PinCount`];t===180?s=l-1-i:t===90?(n==="left"||n==="right")&&(s=l-1-i):t===270&&(n==="left"||n==="right")&&(s=l-1-i);let c=1;const A=["left","bottom","right","top"];for(const u of A){const d=a[`${u}PinCount`];if(d){if(u===o)return c+s;c+=d}}throw new Error(`Could not map pin ${r} after ${t}° rotation`)}function Iot(r){const{inputNetlist:e,matchedBoxes:t}=r,n=new Map;for(const o of t)n.set(o.targetBoxIndex,o.targetBoxRotationCcw);const i=e.boxes.map((o,s)=>{const l=n.get(s);return l?Wpe(o,l):o}),a=e.connections.map(o=>{const s=o.connectedPorts.map(l=>{if("boxId"in l){const c=e.boxes.findIndex(A=>A.boxId===l.boxId);if(c!==-1){const A=n.get(c);if(A){const u=e.boxes[c],d=vot(l.pinNumber,u,A);return{...l,pinNumber:d}}}}return l});return{...o,connectedPorts:s}});return{...e,boxes:i,connections:a}}function Cot(r,e,t,n=45){if(!t)return[`Box ${r} (no transform)`];const i=Object.keys(t.boxIdToBoxIndex).find(C=>t.boxIdToBoxIndex[C]===r);if(!i)return[`Box ${r} (not found)`];const a=e.boxes.find(C=>C.boxId===i);if(!a)return[`Box ${i} (not found)`];const o=[],{leftPinCount:s,rightPinCount:l,topPinCount:c,bottomPinCount:A}=a,u=Math.min(n-4,16),d=2,g=Math.max(s,l,1);let m=i;if(i.length>u-2&&(m=`${i.substring(0,u-3)}…`),c>0){let C="";for(let Q=0;Q<c;Q++){const P=s+A+l+Q+1;C+=P.toString().padStart(2)}const E=C.substring(0,u),_=Math.floor((u-E.length)/2),x=" ".repeat(_)+E;o.push(`${" ".repeat(d+1)}${x}`)}o.push(`${" ".repeat(d)}┌${"─".repeat(u)}┐`);for(let C=0;C<g;C++){const E=C<s?(C+1).toString():"",_=C<l?(s+A+(l-1-C)+1).toString():"";let x="";if(C===Math.floor((g-1)/2)){const Q=Math.floor((u-m.length)/2),P=u-m.length-Q;x=" ".repeat(Q)+m+" ".repeat(P)}else x=" ".repeat(u);o.push(`${E.padStart(d)}│${x}│${_.padEnd(d)}`)}if(o.push(`${" ".repeat(d)}└${"─".repeat(u)}┘`),A>0){let C="";for(let Q=0;Q<A;Q++){const P=s+Q+1;C+=P.toString().padStart(2)}const E=C.substring(0,u),_=Math.floor((u-E.length)/2),x=" ".repeat(_)+E;o.push(`${" ".repeat(d+1)}${x}`)}return o}function Eot(r){const{candidateNetlist:e,targetNetlist:t}=r,n=[],i=new Map;for(let a=0;a<e.boxes.length;a++){const o=e.boxes[a],s=CY({leftPinCount:o.leftPinCount,bottomPinCount:o.bottomPinCount,rightPinCount:o.rightPinCount,topPinCount:o.topPinCount});i.has(s)||i.set(s,[]),i.get(s).push(a)}for(let a=0;a<t.boxes.length;a++){const o=t.boxes[a],s=CY({leftPinCount:o.leftPinCount,bottomPinCount:o.bottomPinCount,rightPinCount:o.rightPinCount,topPinCount:o.topPinCount});(i.get(s)||[]).length===0&&n.push({type:"no_box_matching_pin_counts",candidateBoxIndex:-1,targetBoxIndex:a})}return n}function _ot(r){const{candidateNetlist:e,targetNetlist:t}=r,n=Eot({candidateNetlist:e,targetNetlist:t}),i=r8({candidateNetlist:e,targetNetlist:t});return[...n,...i.flatMap(a=>a.issues)]}var Zpe=r=>{const e=[];for(const t of r.boxes){const n=t.leftPinCount+t.rightPinCount+t.topPinCount+t.bottomPinCount;for(let i=1;i<=n;i++){const a=_Y({netlist:r,chipId:t.boxId,pinNumber:i});e.push({boxId:t.boxId,pinNumber:i,pinShapeSignature:a})}}return e},Bot=({targetNetlist:r,candidateNetlist:e,matchedBoxes:t,targetTransform:n,candidateTransform:i})=>{const a=Zpe(r),o=Zpe(e),s=[];for(const l of t){const c=Object.keys(n.boxIdToBoxIndex).find(m=>n.boxIdToBoxIndex[m]===l.targetBoxIndex),A=Object.keys(i.boxIdToBoxIndex).find(m=>i.boxIdToBoxIndex[m]===l.candidateBoxIndex);if(!c||!A)continue;const u=a.filter(m=>m.boxId===c),d=o.filter(m=>m.boxId===A),g=new Set([...u.map(m=>m.pinNumber),...d.map(m=>m.pinNumber)]);for(const m of g){const C=u.find(_=>_.pinNumber===m),E=d.find(_=>_.pinNumber===m);s.push({targetBoxIdPinNumber:C?`${c}.${m}`:"",candidateBoxIdPinNumber:E?`${A}.${m}`:"",targetPinShapeSignature:(C==null?void 0:C.pinShapeSignature)||"",candidatePinShapeSignature:(E==null?void 0:E.pinShapeSignature)||""})}}return s},xot=class extends S9{constructor(e){super();Ve(this,"inputNetlist");Ve(this,"template");Ve(this,"inputNetlistWithRotations",null);Ve(this,"outputIssues",[]);Ve(this,"outputSimilarityDistance",1/0);Ve(this,"candidateTransform",null);Ve(this,"targetTransform",null);Ve(this,"matchedBoxes",[]);this.inputNetlist=e.inputNetlist,this.template=e.template}getConstructorParams(){return{inputNetlist:this.inputNetlist,template:this.template}}getStatsSummary(){return`${this.stats.similarityDistance.toFixed(1)} SD ・ ${this.stats.issueCount} issues ・ ${this.template.name}`}_step(){var c,A;const e=this.template.getNetlist(),t=m2(e),n=m2(structuredClone(this.inputNetlist)),i=t.normalizedNetlist,a=n.normalizedNetlist;this.matchedBoxes=r8({candidateNetlist:i,targetNetlist:a});for(const u of this.matchedBoxes)u._targetBoxId=n.transform.boxIndexToBoxId[u.targetBoxIndex],u._candidateBoxId=t.transform.boxIndexToBoxId[u.candidateBoxIndex];const o=Iot({inputNetlist:structuredClone(this.inputNetlist),matchedBoxes:this.matchedBoxes});this.inputNetlistWithRotations=o;const s=m2(o),l=s.normalizedNetlist;this.candidateTransform=t.transform,this.targetTransform=s.transform,this.outputIssues=_ot({candidateNetlist:i,targetNetlist:l}),this.outputSimilarityDistance=hY(this.outputIssues),this.stats={similarityDistance:this.outputSimilarityDistance,issueCount:this.outputIssues.length,templateBoxCount:((c=i.boxes)==null?void 0:c.length)||0,templateConnectionCount:((A=i.connections)==null?void 0:A.length)||0,matchedBoxCount:this.matchedBoxes.length},this.solved=!0}getBoxNameFromIndex(e,t){const n=t?this.candidateTransform:this.targetTransform;if(!n)return e.toString();const i=Object.keys(n.boxIdToBoxIndex).find(a=>n.boxIdToBoxIndex[a]===e);return i?`${e} (${i})`:e.toString()}getAsciiForNetlistBoxHelper(e,t,n=45){const i=t?this.template.getNetlist():this.inputNetlistWithRotations,a=t?this.candidateTransform:this.targetTransform;return a?Cot(e,i,a,n):[`Box ${e} (no transform)`]}generateMatchedBoxesVisualization(){if(this.matchedBoxes.length===0)return"No matched boxes found";const e=[];for(const t of this.matchedBoxes){const n=this.getAsciiForNetlistBoxHelper(t.targetBoxIndex,!1,48),i=this.getAsciiForNetlistBoxHelper(t.candidateBoxIndex,!0,48),a=Math.max(n.length,i.length);for(;n.length<a;)n.push(" ".repeat(48));for(;i.length<a;)i.push(" ".repeat(48));const o=`Target ${this.getBoxNameFromIndex(t.targetBoxIndex,!1)}`.padEnd(48),s=`Template ${this.getBoxNameFromIndex(t.candidateBoxIndex,!0)}`.padEnd(48);e.push(`${o} → ${s}`),e.push(`${"─".repeat(48)} → ${"─".repeat(48)}`);for(let l=0;l<a;l++){const c=n[l]||"",A=i[l]||"",u=l===Math.floor(a/2)?" → ":" ";e.push(`${c.padEnd(48)}${u}${A.padEnd(48)}`)}e.push("")}return e.join(`
|
|
852
|
-
`)}visualize(){return[{title:"inputTemplate",ascii:this.template.toString(),table:this.outputIssues.map((e,t)=>({issue_index:t,type:e.type,target_box:"targetBoxIndex"in e?this.getBoxNameFromIndex(e.targetBoxIndex,!1):"N/A",candidate_box:"candidateBoxIndex"in e?this.getBoxNameFromIndex(e.candidateBoxIndex,!0):"N/A",details:e}))},{title:"pairwisePinShapeSignatures",table:Bot({targetNetlist:this.inputNetlistWithRotations,candidateNetlist:this.template.getNetlist(),matchedBoxes:this.matchedBoxes,targetTransform:this.targetTransform,candidateTransform:this.candidateTransform})},{title:"matchedBoxes",ascii:this.generateMatchedBoxesVisualization(),table:this.matchedBoxes.map(e=>({target_box:this.getBoxNameFromIndex(e.targetBoxIndex,!1),candidate_box:this.getBoxNameFromIndex(e.candidateBoxIndex,!0),rotation:e.targetBoxRotationCcw,issueCount:e.issues.length,details:e}))},{title:"inputTemplateReadableNetlist",ascii:this.template.getReadableNetlist()},{title:"inputTargetReadableNetlist",ascii:pD(this.inputNetlist)},this.inputNetlistWithRotations&&{title:"targetReadableNetlistWithRotations",ascii:pD(this.inputNetlistWithRotations)}].filter(Boolean)}},bot=class extends S9{constructor(e){var t;super();Ve(this,"inputNetlist");Ve(this,"templates");Ve(this,"scoringSolvers",[]);Ve(this,"currentScoringIndex",0);Ve(this,"outputBestMatchTemplate",null);Ve(this,"templateMatchResults",[]);this.inputNetlist=e.inputNetlist,this.templates=((t=e.templateFns)==null?void 0:t.map(n=>n()))||yot.map(n=>n()),this.scoringSolvers=this.templates.map(n=>new xot({inputNetlist:this.inputNetlist,template:n}))}getConstructorParams(){return{inputNetlist:this.inputNetlist}}computeProgress(){return this.scoringSolvers.length===0?1:this.currentScoringIndex/this.scoringSolvers.length}_step(){if(this.currentScoringIndex<this.scoringSolvers.length){const t=this.scoringSolvers[this.currentScoringIndex];if(!t.solved&&!t.failed){this.setActiveSubSolver(t),t.step();return}this.clearActiveSubSolver(),this.currentScoringIndex++;return}if(this.templateMatchResults=this.scoringSolvers.map(t=>({template:t.template,issues:t.outputIssues,similarityDistance:t.outputSimilarityDistance})),this.templateMatchResults.length===0){this.outputBestMatchTemplate=null,this.solved=!0;return}let e=this.templateMatchResults[0];for(let t=1;t<this.templateMatchResults.length;t++)this.templateMatchResults[t].similarityDistance<e.similarityDistance&&(e=this.templateMatchResults[t]);e.similarityDistance===1/0?this.outputBestMatchTemplate=null:this.outputBestMatchTemplate=e.template,this.solved=!0}visualize(){var e;return[{title:"inputNetlist",ascii:pD(this.inputNetlist)},{title:"bestMatchTemplate",ascii:((e=this.outputBestMatchTemplate)==null?void 0:e.toString())||"No suitable match found"},{title:"templateScores",table:this.templateMatchResults.map((t,n)=>({template_index:n,template_name:t.template.name||`Template ${n}`,similarity_distance:t.similarityDistance,issue_count:t.issues.length,is_best_match:t.template===this.outputBestMatchTemplate}))}]}},Sot=class extends S9{constructor(e){super();Ve(this,"inputNetlists");Ve(this,"currentInputNetlistIndex",0);Ve(this,"templateFns");Ve(this,"outputMatchedTemplates",[]);this.inputNetlists=e.inputNetlists,this.templateFns=e.templateFns}get activeSubSolver(){return this._activeSubSolver}_step(){if(this.activeSubSolver)if(this.activeSubSolver.step(),this.activeSubSolver.solved){this.outputMatchedTemplates.push({template:this.activeSubSolver.outputBestMatchTemplate,netlist:this.inputNetlists[this.currentInputNetlistIndex]}),this.currentInputNetlistIndex++,this.clearActiveSubSolver();return}else return;if(this.currentInputNetlistIndex>=this.inputNetlists.length){this.solved=!0;return}this.setActiveSubSolver(new bot({inputNetlist:this.inputNetlists[this.currentInputNetlistIndex],templateFns:this.templateFns}))}};function qpe(r,e,t,n={}){return{solverName:r,solverClass:e,getConstructorParams:t,onSolved:n.onSolved}}var Qot=class extends S9{constructor(e){super();Ve(this,"inputNetlist");Ve(this,"templateFnsOverride");Ve(this,"matchPhaseSolver");Ve(this,"adaptPhaseSolver");Ve(this,"startTimeOfPhase",{});Ve(this,"endTimeOfPhase",{});Ve(this,"timeSpentOnPhase",{});Ve(this,"pipelineDef",[qpe("matchPhaseSolver",Sot,()=>[{inputNetlists:[this.inputNetlist],templateFns:this.templateFnsOverride}]),qpe("adaptPhaseSolver",sot,()=>{var e;return[{matchedTemplates:(e=this.matchPhaseSolver)==null?void 0:e.outputMatchedTemplates}]})]);Ve(this,"currentPipelineStepIndex",0);this.inputNetlist=e.inputNetlist,this.templateFnsOverride=e.templateFns}_step(){var n,i;const e=this.pipelineDef[this.currentPipelineStepIndex];if(!e){this.solved=!0;return}if(this.activeSubSolver){if(this.activeSubSolver.step(),this.activeSubSolver.solved){this.endTimeOfPhase[e.solverName]=performance.now(),this.timeSpentOnPhase[e.solverName]=this.endTimeOfPhase[e.solverName]-this.startTimeOfPhase[e.solverName],(n=e.onSolved)==null||n.call(e,this),this.clearActiveSubSolver(),this.currentPipelineStepIndex++;return}if(this.activeSubSolver.failed){this.error=(i=this.activeSubSolver)==null?void 0:i.error,this.failed=!0,this.clearActiveSubSolver();return}return}const t=e.getConstructorParams(this);this.setActiveSubSolver(new e.solverClass(...t)),this[e.solverName]=this.activeSubSolver,this.timeSpentOnPhase[e.solverName]=0,this.startTimeOfPhase[e.solverName]=performance.now()}getLayout(){var e,t;if(!((t=(e=this.adaptPhaseSolver)==null?void 0:e.outputAdaptedTemplates)!=null&&t[0]))throw new Error("No adapted template available. Make sure the pipeline has completed successfully.");return this.adaptPhaseSolver.outputAdaptedTemplates[0].template.getLayoutJson()}},wot=r=>{switch(r){case"left":return"left";case"right":return"right";case"up":return"top";case"down":return"bottom"}},Mot=r=>{const e=pS(r),t=yx(r).source_component.list().map(o=>({source_component:o,schematic_component:yx(r).schematic_component.getWhere({source_component_id:o.source_component_id}),source_ports:yx(r).source_port.list().filter(s=>s.source_component_id===o.source_component_id).map(s=>{const l=e.getNetConnectedToId(s.source_port_id),c=yx(r).schematic_port.getWhere({source_port_id:s.source_port_id}),A=(c==null?void 0:c.true_ccw_index)!=null?c.true_ccw_index+1:s.pin_number;return{source_port:s,schematic_port:yx(r).schematic_port.getWhere({source_port_id:s.source_port_id}),pin_number:A,connectivity_net_id:l}}).filter(({schematic_port:s})=>!!s)})),n=[],i=[];for(const{source_component:o,schematic_component:s,source_ports:l}of t){const c={boxId:o.name,leftPinCount:0,rightPinCount:0,topPinCount:0,bottomPinCount:0};for(const{source_port:A,schematic_port:u,pin_number:d}of l){const g=wot(u.facing_direction);c[`${g}PinCount`]++;const m=e.getNetConnectedToId(A.source_port_id);let C=i.find(E=>E._connectivityNetId===m);C||(C={_connectivityNetId:m,connectedPorts:[]},i.push(C)),C.connectedPorts.push({boxId:o.name,pinNumber:(u==null?void 0:u.true_ccw_index)!=null?u.true_ccw_index+1:d})}n.push(c)}const a=[];for(const o of i){if(o.connectedPorts.length<2)continue;let s=o._connectivityNetId;const l=e.getIdsConnectedToNet(s).map(c=>Gpe(r,c));for(const c of l)if((c==null?void 0:c.type)==="source_net"){s=c.name;break}o.connectedPorts.push({netId:s}),a.push({netId:s})}return{boxes:n,connections:i,nets:a}},Dot=r=>{const e=JSON.parse(JSON.stringify(r)),t=e.filter(n=>n.type==="schematic_component"&&n.port_arrangement);for(const n of t){const i=e.filter(o=>o.type==="schematic_port"&&o.schematic_component_id===n.schematic_component_id&&o.true_ccw_index!==void 0);if(i.length===0)continue;i.sort((o,s)=>o.true_ccw_index-s.true_ccw_index);const a={};i.forEach((o,s)=>{a[o.pin_number]=s+1});for(const o of i){const s=a[o.pin_number];o.pin_number=s}for(const o of i){const s=e.find(l=>l.type==="source_port"&&l.source_port_id===o.source_port_id);s&&(s.pin_number=o.pin_number)}if(n.port_arrangement){const o=s=>{var l;(l=n.port_arrangement[s])!=null&&l.pins&&(n.port_arrangement[s].pins=n.port_arrangement[s].pins.map(c=>a[c]||c))};o("left_side"),o("right_side"),o("top_side"),o("bottom_side")}if(n.port_labels){const o={};for(const[s,l]of Object.entries(n.port_labels)){const c=parseInt(s.replace("pin","")),A=a[c];A!==void 0?o[`pin${A}`]=l:o[s]=l}n.port_labels=o}if(n.pin_styles){const o={};for(const[s,l]of Object.entries(n.pin_styles)){const c=parseInt(s.replace("pin","")),A=a[c];A!==void 0?o[`pin${A}`]=l:o[s]=l}n.pin_styles=o}}return e},xY=[{value:1e12,symbol:"T"},{value:1e9,symbol:"G"},{value:1e6,symbol:"M"},{value:1e3,symbol:"k"},{value:1,symbol:""},{value:.001,symbol:"m"},{value:1e-6,symbol:"µ"},{value:1e-9,symbol:"n"},{value:1e-12,symbol:"p"}];function vx(r){if(r==null)return"";if(r===0)return"0";const e=Math.abs(r),t=xY.find(a=>{const o=e/a.value;return o>=1&&o<1e3})||xY[xY.length-1];let i=(r/t.value).toPrecision(3);return i.includes(".")&&!/\.0+$/.test(i)&&(i=i.replace(/0+$/,"")),i=i.replace(/\.0+$/,""),`${i}${t.symbol}`}var Rot=Object.defineProperty,Not=(r,e)=>{for(var t in e)Rot(r,t,{get:e[t],enumerable:!0})},Xpe={};Not(Xpe,{Battery:()=>Jst,Board:()=>Sst,Capacitor:()=>wst,Chip:()=>C0e,Constraint:()=>Fst,Crystal:()=>tlt,Cutout:()=>Kst,Diode:()=>Mst,FabricationNotePath:()=>kst,FabricationNoteText:()=>Gst,Footprint:()=>tst,Fuse:()=>Dst,Group:()=>FY,Hole:()=>A0e,Inductor:()=>qst,Jumper:()=>Rst,Keepout:()=>DY,Led:()=>Nst,Mosfet:()=>rlt,Net:()=>o0e,NetAlias:()=>Ost,NormalComponent:()=>m1,PcbTrace:()=>c0e,PinHeader:()=>jst,PlatedHole:()=>MY,Port:()=>yS,Potentiometer:()=>$st,PowerSource:()=>Tst,PrimitiveComponent:()=>Kv,PushButton:()=>elt,Renderable:()=>$pe,Resistor:()=>Pst,Resonator:()=>Zst,SchematicBox:()=>olt,SchematicText:()=>alt,SilkscreenCircle:()=>zst,SilkscreenLine:()=>Yst,SilkscreenPath:()=>l0e,SilkscreenRect:()=>Hst,SilkscreenText:()=>RY,SmtPad:()=>wY,Subcircuit:()=>Lst,Switch:()=>ilt,Trace:()=>vS,TraceHint:()=>v0e,Transistor:()=>nlt,Via:()=>Vst});var Tot=KI("tscircuit:renderable"),Ix=["ReactSubtreesRender","PcbFootprintStringRender","InitializePortsFromChildren","CreateNetsFromProps","CreateTracesFromProps","CreateTraceHintsFromProps","SourceRender","SourceParentAttachment","PortMatching","OptimizeSelectorCache","SourceTraceRender","SourceAddConnectivityMapKey","SchematicComponentRender","SchematicPortRender","SchematicPrimitiveRender","SchematicLayout","SchematicTraceRender","PcbComponentRender","PcbPrimitiveRender","PcbFootprintLayout","PcbPortRender","PcbPortAttachment","PcbLayout","PcbComponentSizeCalculation","PcbBoardAutoSize","PcbTraceHintRender","PcbTraceRender","PcbRouteNetIslands","PcbDesignRuleChecks","CadModelRender","PartsEngineRender"],Pot=0,$pe=class{constructor(e){Ve(this,"renderPhaseStates");Ve(this,"shouldBeRemoved",!1);Ve(this,"children");Ve(this,"isPcbPrimitive",!1);Ve(this,"isSchematicPrimitive",!1);Ve(this,"_renderId");Ve(this,"_currentRenderPhase",null);Ve(this,"_asyncEffects",[]);Ve(this,"parent",null);this._renderId=`${Pot++}`,this.children=[],this.renderPhaseStates={};for(const t of Ix)this.renderPhaseStates[t]={initialized:!1,dirty:!1}}_markDirty(e){var n;this.renderPhaseStates[e].dirty=!0;const t=Ix.indexOf(e);for(let i=t+1;i<Ix.length;i++)this.renderPhaseStates[Ix[i]].dirty=!0;(n=this.parent)!=null&&n._markDirty&&this.parent._markDirty(e)}_queueAsyncEffect(e,t){const n={promise:t(),phase:this._currentRenderPhase,effectName:e,complete:!1};this._asyncEffects.push(n),"root"in this&&this.root&&this.root.emit("asyncEffect:start",{effectName:e,componentDisplayName:this.getString(),phase:n.phase}),n.promise.then(()=>{n.complete=!0,"root"in this&&this.root&&this.root.emit("asyncEffect:end",{effectName:e,componentDisplayName:this.getString(),phase:n.phase})}).catch(i=>{console.error(`Async effect error in ${n.phase} "${e}":
|
|
853
|
-
${i.stack}`),n.complete=!0,"root"in this&&this.root&&this.root.emit("asyncEffect:end",{effectName:e,componentDisplayName:this.getString(),phase:n.phase,error:i.toString()})})}_emitRenderLifecycleEvent(e,t){Tot(`${e}:${t} ${this.getString()}`);const n=`renderable:renderLifecycle:${e}:${t}`,i={renderId:this._renderId,componentDisplayName:this.getString(),type:n};"root"in this&&this.root&&(this.root.emit(n,i),this.root.emit("renderable:renderLifecycle:anyEvent",{...i,type:n}))}getString(){return this.constructor.name}_hasIncompleteAsyncEffects(){return this._asyncEffects.some(e=>!e.complete)}getCurrentRenderPhase(){return this._currentRenderPhase}getRenderGraph(){return{id:this._renderId,currentPhase:this._currentRenderPhase,renderPhaseStates:this.renderPhaseStates,shouldBeRemoved:this.shouldBeRemoved,children:this.children.map(e=>e.getRenderGraph())}}runRenderCycle(){for(const e of Ix)this.runRenderPhaseForChildren(e),this.runRenderPhase(e)}runRenderPhase(e){var o,s,l;this._currentRenderPhase=e;const t=this.renderPhaseStates[e],n=t.initialized,i=t.dirty;if(!n&&this.shouldBeRemoved)return;if(this.shouldBeRemoved&&n){this._emitRenderLifecycleEvent(e,"start"),(o=this==null?void 0:this[`remove${e}`])==null||o.call(this),t.initialized=!1,t.dirty=!1,this._emitRenderLifecycleEvent(e,"end");return}const a=Ix.indexOf(e)-1;if(a>=0){const c=Ix[a];if(this._asyncEffects.filter(u=>u.phase===c).some(u=>!u.complete))return}if(this._emitRenderLifecycleEvent(e,"start"),n){i&&((s=this==null?void 0:this[`update${e}`])==null||s.call(this),t.dirty=!1),this._emitRenderLifecycleEvent(e,"end");return}t.dirty=!1,(l=this==null?void 0:this[`doInitial${e}`])==null||l.call(this),t.initialized=!0,this._emitRenderLifecycleEvent(e,"end")}runRenderPhaseForChildren(e){for(const t of this.children)t.runRenderPhaseForChildren(e),t.runRenderPhase(e)}renderError(e){throw typeof e=="string"?new Error(e):new Error(JSON.stringify(e,null,2))}},i8={},e0e=r=>{const e=Object.fromEntries(Object.entries(r).map(([t,n])=>[t.toLowerCase(),n]));Object.assign(i8,r),Object.assign(i8,e)},Uot=class extends Error{constructor(e,t,n){let i;const o=Object.keys(n).filter(s=>s!=="_errors").map(s=>n[s]._errors[0]?`${s} (${n[s]._errors[0]})`:`${s} (${JSON.stringify(n[s])})`).join(", ");"name"in t?i=`Invalid props for ${e} "${t.name}": ${o}`:"footprint"in t&&typeof t.footprint=="string"?i=`Invalid props for ${e} (unnamed ${t.footprint} component): ${o}`:i=`Invalid props for ${e} (unnamed): ${o}`,super(i),this.componentName=e,this.originalProps=t,this.formattedError=n}};function bY(r,e){const t=e.match(/^#(\w+)/);if(t)return r.props.id===t[1];const n=e.match(/^\.(\w+)/);if(n)return r.isMatchingNameOrAlias(n[1]);let[i,...a]=e.split(/(?=[#.[])/);return i==="pin"&&(i="port"),i&&i!=="*"&&r.lowercaseComponentName!==i.toLowerCase()?!1:a.every(o=>{if(o.startsWith("#"))return r.props.id===o.slice(1);if(o.startsWith("."))return r.isMatchingNameOrAlias(o.slice(1));const s=o.match(/\[(\w+)=['"]?(.+?)['"]?\]/);if(!s)return!0;const[,l,c]=s;return r.props[l].toString()===c})}var SY={isTag:r=>!0,getParent:r=>r.parent,getChildren:r=>r.children,getName:r=>r.lowercaseComponentName,getAttributeValue:(r,e)=>{var t;if(e==="class"&&"getNameAndAliases"in r)return r.getNameAndAliases().join(" ");if(e==="name"&&((t=r._parsedProps)!=null&&t.name))return r._parsedProps.name;if(r._parsedProps&&e in r._parsedProps){const n=r._parsedProps[e];return typeof n=="string"?n:n!=null?String(n):null}return null},hasAttrib:(r,e)=>{var t;return e==="class"?!!((t=r._parsedProps)!=null&&t.name):r._parsedProps&&e in r._parsedProps},getSiblings:r=>r.parent?r.parent.children:[],prevElementSibling:r=>{if(!r.parent)return null;const e=r.parent.children,t=e.indexOf(r);return t>0?e[t-1]:null},getText:()=>"",removeSubsets:r=>r.filter((e,t)=>!r.some((n,i)=>t!==i&&n!==e&&n.getDescendants().includes(e))),existsOne:(r,e)=>e.some(r),findAll:(r,e)=>{const t=[],n=i=>{r(i)&&t.push(i);for(const a of i.children)n(a)};for(const i of e)n(i);return t},findOne:(r,e)=>{for(const t of e){if(r(t))return t;const n=t.children;if(n.length>0){const i=SY.findOne(r,n);if(i)return i}}return null},equals:(r,e)=>r._renderId===e._renderId,isHovered:r=>!1,isVisited:r=>!1,isActive:r=>!1},Fot={...SY,getChildren:r=>r.children.filter(e=>!e.isSubcircuit)},t0e={...SY,getChildren:r=>r.children.filter(e=>e.isSubcircuit)},n0e=r=>{if(/net\.[^\s>]*\./.test(r))throw new Error('Net names cannot contain a period, try using "sel.net..." to autocomplete with conventional net names, e.g. V3_3');if(/net\.[0-9]/.test(r))throw new Error('Net names cannot start with a number, try using a prefix like "VBUS1"');return r.replace(/ pin/g," port").replace(/ subcircuit\./g," group[isSubcircuit=true]").replace(/([^ ])\>([^ ])/g,"$1 > $2").replace(/(^|[ >])(?!pin\.)(?!port\.)(?!net\.)([A-Z][A-Za-z0-9_-]*)\.([A-Za-z0-9_-]+)/g,(e,t,n,i)=>{const a=/^\d+$/.test(i)?`pin${i}`:i;return`${t}.${n} > .${a}`}).trim()},QY={adapter:Fot,cacheResults:!0},Kv=class extends $pe{constructor(t){super(t);Ve(this,"parent",null);Ve(this,"children");Ve(this,"childrenPendingRemoval");Ve(this,"props");Ve(this,"_parsedProps");Ve(this,"externallyAddedAliases");Ve(this,"isPrimitiveContainer",!1);Ve(this,"source_group_id",null);Ve(this,"source_component_id",null);Ve(this,"schematic_component_id",null);Ve(this,"pcb_component_id",null);Ve(this,"cad_component_id",null);Ve(this,"_cachedSelectAllQueries",new Map);Ve(this,"_cachedSelectOneQueries",new Map);this.children=[],this.childrenPendingRemoval=[],this.props=t??{},this.externallyAddedAliases=[];const n=this.config.zodProps.safeParse(t??{});if(n.success)this._parsedProps=n.data;else throw new Uot(this.lowercaseComponentName,this.props,n.error.format())}get config(){return{componentName:"",zodProps:Vn({}).passthrough()}}get componentName(){return this.config.componentName}getInheritedProperty(t){var i;let n=this;for(;n;){if(n._parsedProps&&t in n._parsedProps)return n._parsedProps[t];n=n.parent}if((i=this.root)!=null&&i.platform&&t in this.root.platform)return this.root.platform[t]}get lowercaseComponentName(){return this.componentName.toLowerCase()}get isSubcircuit(){var t;return!!this.props.subcircuit||this.lowercaseComponentName==="group"&&((t=this==null?void 0:this.parent)==null?void 0:t.isRoot)}get isGroup(){return this.lowercaseComponentName==="group"}setProps(t){var a,o;const n=this.config.zodProps.parse({...this.props,...t}),i=this.props;this.props=n,this._parsedProps=this.config.zodProps.parse(t),this.onPropsChange({oldProps:i,newProps:n,changedProps:Object.keys(t)}),(o=(a=this.parent)==null?void 0:a.onChildChanged)==null||o.call(a,this)}computePcbPropsTransform(){const{_parsedProps:t}=this;return OA(Kd(t.pcbX??0,t.pcbY??0),j_((t.pcbRotation??0)*Math.PI/180))}_computePcbGlobalTransformBeforeLayout(){var i,a,o;const{_parsedProps:t}=this,n=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if(n&&this.props.pcbX===void 0&&this.props.pcbY===void 0)return OA(((i=this.parent)==null?void 0:i._computePcbGlobalTransformBeforeLayout())??By(),OA(Kd(n.x,n.y),j_((t.pcbRotation??0)*Math.PI/180)));if(this.isPcbPrimitive){const s=this.getPrimitiveContainer();if(s){const l=s._parsedProps.layer==="bottom",c=s._getGlobalPcbPositionBeforeLayout();if(l)return OA(Kd(c.x,c.y),W3(),Kd(-c.x,-c.y)),OA(((a=this.parent)==null?void 0:a._computePcbGlobalTransformBeforeLayout())??By(),W3(),this.computePcbPropsTransform())}}return OA(((o=this.parent)==null?void 0:o._computePcbGlobalTransformBeforeLayout())??By(),this.computePcbPropsTransform())}getPrimitiveContainer(){var t,n;return this.isPrimitiveContainer?this:((n=(t=this.parent)==null?void 0:t.getPrimitiveContainer)==null?void 0:n.call(t))??null}_getPcbCircuitJsonBounds(){return{center:{x:0,y:0},bounds:{left:0,top:0,right:0,bottom:0},width:0,height:0}}_getPcbPrimitiveFlippedHelpers(){const t=this.getPrimitiveContainer(),n=t?t._parsedProps.layer==="bottom":!1;return{isFlipped:n,maybeFlipLayer:a=>n?a==="top"?"bottom":"top":a}}_setPositionFromLayout(t){throw new Error(`_setPositionFromLayout not implemented for ${this.componentName}`)}computeSchematicPropsTransform(){const{_parsedProps:t}=this;return OA(Kd(t.schX??0,t.schY??0))}computeSchematicGlobalTransform(){var n,i;const t=this._getSchematicGlobalManualPlacementTransform(this);return t||OA(((i=(n=this.parent)==null?void 0:n.computeSchematicGlobalTransform)==null?void 0:i.call(n))??By(),this.computeSchematicPropsTransform())}_getSchematicSymbolName(){const{_parsedProps:t}=this,n=this.config.schematicSymbolName;let i=t.schRotation;if(i===void 0&&(i=0),i=i%360,i<0&&(i+=360),t.schRotation!==void 0&&i%90!==0)throw new Error(`Schematic rotation ${t.schRotation} is not supported for ${this.componentName}`);const a=`${n}_horz`,o=`${n}_vert`,s=`${n}_up`,l=`${n}_down`,c=`${n}_left`,A=`${n}_right`;if(A in dI&&i===0)return A;if(s in dI&&i===90)return s;if(c in dI&&i===180)return c;if(l in dI&&i===270)return l;if(a in dI&&(i===0||i===180))return a;if(o in dI&&(i===90||i===270))return o;if(n in dI)return n}_getSchematicSymbolNameOrThrow(){const t=this._getSchematicSymbolName();if(!t)throw new Error(`No schematic symbol found (given: "${this.config.schematicSymbolName}")`);return t}getSchematicSymbol(){const t=this._getSchematicSymbolName();return t?dI[t]??null:null}_getPcbManualPlacementForComponent(t){var o;if(!this.isSubcircuit)return null;const n=this.props.layout,i=this.props.manualEdits;if(!n&&!i)return null;const a=((o=n==null?void 0:n.manual_pcb_placement_config)==null?void 0:o.positions)||(i==null?void 0:i.pcb_placements);if(!a)return null;for(const s of a)if(n&&bY(t,s.selector)||t.props.name===s.selector)return si(this._computePcbGlobalTransformBeforeLayout(),s.center);return null}_getSchematicManualPlacementForComponent(t){if(!this.isSubcircuit)return null;const n=this.props.manualEdits;if(!n)return null;const i=n.schematic_placements;if(!i)return null;for(const a of i)if(bY(t,a.selector)||t.props.name===a.selector)return si(this.computeSchematicGlobalTransform(),a.center);return null}_getSchematicGlobalManualPlacementTransform(t){var i,a;const n=(i=this.getSubcircuit())==null?void 0:i._parsedProps.manualEdits;if(!n)return null;for(const o of n.schematic_placements??[])if((bY(t,o.selector)||t.props.name===o.selector)&&o.relative_to==="group_center")return OA(((a=this.parent)==null?void 0:a._computePcbGlobalTransformBeforeLayout())??By(),Kd(o.center.x,o.center.y));return null}_getGlobalPcbPositionBeforeLayout(){return si(this._computePcbGlobalTransformBeforeLayout(),{x:0,y:0})}_getGlobalSchematicPositionBeforeLayout(){return si(this.computeSchematicGlobalTransform(),{x:0,y:0})}get root(){var t;return((t=this.parent)==null?void 0:t.root)??null}onAddToParent(t){this.parent=t}onPropsChange(t){}onChildChanged(t){var n,i;(i=(n=this.parent)==null?void 0:n.onChildChanged)==null||i.call(n,t)}add(t){if(!t.onAddToParent)throw new Error(`Invalid JSX Element: Expected a React component but received "${JSON.stringify(t)}"`);t.onAddToParent(this),t.parent=this,this.children.push(t)}addAll(t){for(const n of t)this.add(n)}remove(t){this.children=this.children.filter(n=>n!==t),this.childrenPendingRemoval.push(t),t.shouldBeRemoved=!0}getSubcircuitSelector(){const t=this._parsedProps.name,n=t?`${this.lowercaseComponentName}.${t}`:this.lowercaseComponentName;return!this.parent||this.parent.isSubcircuit?n:`${this.parent.getSubcircuitSelector()} > ${n}`}getFullPathSelector(){var a,o;const t=this._parsedProps.name,n=t?`${this.lowercaseComponentName}.${t}`:this.lowercaseComponentName,i=(o=(a=this.parent)==null?void 0:a.getFullPathSelector)==null?void 0:o.call(a);return i?`${i} > ${n}`:n}getNameAndAliases(){return[this._parsedProps.name,...this._parsedProps.portHints??[]].filter(Boolean)}isMatchingNameOrAlias(t){return this.getNameAndAliases().includes(t)}isMatchingAnyOf(t){return this.getNameAndAliases().some(n=>t.map(i=>i.toString()).includes(n))}getPcbSize(){throw new Error(`getPcbSize not implemented for ${this.componentName}`)}doesSelectorMatch(t){const n=[this.componentName,this.lowercaseComponentName],i=[this._parsedProps.name].filter(Boolean),a=t.trim().split(/\> /)[0],o=a[0];return a.length>1?!1:!!(t==="*"||t[0]==="#"&&t.slice(1)===this.props.id||t[0]==="."&&i.includes(t.slice(1))||/^[a-zA-Z0-9_]/.test(o)&&n.includes(o))}getSubcircuit(){var n,i;if(this.isSubcircuit)return this;const t=(i=(n=this.parent)==null?void 0:n.getSubcircuit)==null?void 0:i.call(n);if(!t)throw new Error("Component is not inside an opaque group (no board?)");return t}getGroup(){var t,n;return this.isGroup?this:((n=(t=this.parent)==null?void 0:t.getGroup)==null?void 0:n.call(t))??null}doInitialOptimizeSelectorCache(){var n;if(!this.isSubcircuit)return;const t=this.selectAll("port");for(const i of t){const a=(n=i.parent)==null?void 0:n.getNameAndAliases(),o=i.getNameAndAliases();if(a)for(const s of a)for(const l of o){const c=[`.${s} > .${l}`,`.${s} .${l}`];for(const A of c){const u=this._cachedSelectAllQueries.get(A);u?u.push(i):this._cachedSelectAllQueries.set(A,[i])}}}for(const[i,a]of this._cachedSelectAllQueries.entries())a.length===1&&this._cachedSelectOneQueries.set(i,a[0])}selectAll(t){if(this._cachedSelectAllQueries.has(t))return this._cachedSelectAllQueries.get(t);const n=n0e(t),i=pP(n,this,QY);if(i.length>0)return this._cachedSelectAllQueries.set(t,i),i;const[a,...o]=n.split(" "),s=p9(a,this,{adapter:t0e});if(!s)return[];const l=s.selectAll(o.join(" "));return this._cachedSelectAllQueries.set(t,l),l}selectOne(t,n){if(this._cachedSelectOneQueries.has(t))return this._cachedSelectOneQueries.get(t);const i=n0e(t);n!=null&&n.port&&(n.type="port");let a=null;if(n!=null&&n.type&&(a=pP(i,this,QY).find(A=>A.lowercaseComponentName===n.type)),a??(a=p9(i,this,QY)),a)return this._cachedSelectOneQueries.set(t,a),a;const[o,...s]=i.split(" "),l=p9(o,this,{adapter:t0e});return l?(a=l.selectOne(s.join(" "),n),this._cachedSelectOneQueries.set(t,a),a):null}getAvailablePcbLayers(){var t,n;if(this.isPcbPrimitive){const{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers();return"layer"in this._parsedProps||this.componentName==="SmtPad"?[i(this._parsedProps.layer??"top")]:"layers"in this._parsedProps?this._parsedProps.layers:this.componentName==="PlatedHole"?((n=(t=this.root)==null?void 0:t._getBoard())==null?void 0:n.allLayers)??["top","bottom"]:[]}return[]}getDescendants(){const t=[];for(const n of this.children)t.push(n),t.push(...n.getDescendants());return t}getSelectableDescendants(){const t=[];for(const n of this.children)n.isSubcircuit?t.push(n):(t.push(n),t.push(...n.getSelectableDescendants()));return t}_getPinCount(){return 0}_getSchematicBoxDimensions(){return null}_getSchematicBoxComponentDimensions(){if(this.getSchematicSymbol()||!this.config.shouldRenderAsSchematicBox)return null;const{_parsedProps:t}=this;return{schWidth:t.schWidth,schHeight:t.schHeight}}renderError(t){var n;if(typeof t=="string")return super.renderError(t);(n=this.root)==null||n.db.pcb_placement_error.insert(t)}getString(){var a,o;const{lowercaseComponentName:t,_parsedProps:n,parent:i}=this;return(n==null?void 0:n.pinNumber)!==void 0&&((a=i==null?void 0:i.props)!=null&&a.name)&&(n!=null&&n.name)?`<${t}#${this._renderId}(pin:${n.pinNumber} .${i==null?void 0:i.props.name}>.${n.name}) />`:(o=i==null?void 0:i.props)!=null&&o.name&&(n!=null&&n.name)?`<${t}#${this._renderId}(.${i==null?void 0:i.props.name}>.${n==null?void 0:n.name}) />`:n!=null&&n.from&&(n!=null&&n.to)?`<${t}#${this._renderId}(from:${n.from} to:${n==null?void 0:n.to}) />`:n!=null&&n.name?`<${t}#${this._renderId} name=".${n==null?void 0:n.name}" />`:n!=null&&n.portHints?`<${t}#${this._renderId}(${n.portHints.map(s=>`.${s}`).join(", ")}) />`:`<${t}#${this._renderId} />`}get[Symbol.toStringTag](){return this.getString()}[Symbol.for("nodejs.util.inspect.custom")](){return this.getString()}},kot=class extends Kv{constructor(e,t){super(e),this._parsedProps={...e,error:t,type:e.type||"unknown",component_name:e.name,error_type:"source_failed_to_create_component_error",message:t instanceof Error?t.message:String(t),pcbX:e.pcbX,pcbY:e.pcbY,schX:e.schX,schY:e.schY}}get config(){return{componentName:"ErrorPlaceholder",zodProps:Vn({}).passthrough()}}doInitialSourceRender(){var e,t,n,i;if((e=this.root)!=null&&e.db){const a=this._getGlobalPcbPositionBeforeLayout(),o=this._getGlobalSchematicPositionBeforeLayout();this.root.db.source_failed_to_create_component_error.insert({component_name:this._parsedProps.component_name,message:((i=(n=(t=this._parsedProps.error)==null?void 0:t.formattedError)==null?void 0:n._errors)==null?void 0:i.join("; "))||this._parsedProps.message,pcb_center:a,schematic_center:o})}}};function Got(r,e){return new kot(r,e)}function Lot(r,e){const t=r;return t.__tsci={...e},r}var r0e={supportsMutation:!0,createInstance(r,e){const t=i8[r];if(!t)throw Object.keys(i8).length===0?new Error("No components registered in catalogue, did you forget to import lib/register-catalogue in your test file?"):new Error(`Unsupported component type (not registered in @tscircuit/core catalogue): "${r}" See CREATING_NEW_COMPONENTS.md`);try{return Lot(new t(e),{})}catch(n){return Got(e,n)}},createTextInstance(){return{}},appendInitialChild(r,e){r.add(e)},appendChild(r,e){r.add(e)},appendChildToContainer(r,e){r.add(e)},finalizeInitialChildren(){return!1},prepareUpdate(){return null},shouldSetTextContent(){return!1},getRootHostContext(){return{}},getChildHostContext(){return{}},prepareForCommit(){return null},resetAfterCommit(){},commitMount(){},commitUpdate(){},removeChild(){},clearContainer(){},supportsPersistence:!1,getPublicInstance(r){return r},preparePortalMount(r){throw new Error("Function not implemented.")},scheduleTimeout(r,e){throw new Error("Function not implemented.")},cancelTimeout(r){throw new Error("Function not implemented.")},noTimeout:void 0,isPrimaryRenderer:!1,getInstanceFromNode(r){throw new Error("Function not implemented.")},beforeActiveInstanceBlur(){throw new Error("Function not implemented.")},afterActiveInstanceBlur(){throw new Error("Function not implemented.")},prepareScopeUpdate:(r,e)=>{throw new Error("Function not implemented.")},getInstanceFromScope:r=>{throw new Error("Function not implemented.")},detachDeletedInstance:r=>{throw new Error("Function not implemented.")},getCurrentEventPriority:()=>A9.DefaultEventPriority,getCurrentUpdatePriority:()=>A9.DefaultEventPriority,resolveUpdatePriority:()=>A9.DefaultEventPriority,setCurrentUpdatePriority:()=>{},maySuspendCommit:()=>!1,supportsHydration:!1},yQ;Gh.version.startsWith("19.")?yQ=BAe(r0e):yQ=QAe(r0e);var i0e=r=>{const e={children:[],props:{name:"$root"},add(a){a.parent=this,this.children.push(a)},computePcbGlobalTransform(){return By()}},t=[],n=yQ.createContainer(e,0,null,!1,null,"tsci",a=>{console.log("Error in createContainer"),console.error(a),t.push(a)},null);if(Gh.version.startsWith("19.")?(yQ.updateContainerSync(r,n,null,()=>{}),yQ.flushSyncWork()):yQ.updateContainer(r,n,null,()=>{}),t.length>0)throw t[0];const i=yQ.getPublicRootInstance(n);return i||e.children[0]},yD=(r,e)=>{if(typeof r=="number")return r;if(r.startsWith("pin"))return Number(r.slice(3));if(!e)throw new Error(`No pin labels provided and pin number or label is not a number: "${r}"`);for(const t in e)if((Array.isArray(e[t])?e[t]:[e[t]]).includes(r))return Number(t.replace("pin",""));throw new Error(`No pin labels provided and pin number or label is not a number: "${r}"`)},Oot=(r,e)=>{if(!r)return;const t={},n={};for(const[i,a]of Object.entries(r)){const o=yD(i,e);n[o]={...n[o],...a}}for(const[i,a]of Object.entries(n)){const o=`pin${i}`;t[o]={bottom_margin:a.bottomMargin,left_margin:a.leftMargin,right_margin:a.rightMargin,top_margin:a.topMargin}}return t},zot=r=>{if(r){if("leftSide"in r||"rightSide"in r||"topSide"in r||"bottomSide"in r)return{left_side:r.leftSide,right_side:r.rightSide,top_side:r.topSide,bottom_side:r.bottomSide};if("leftPinCount"in r||"rightPinCount"in r||"topPinCount"in r||"bottomPinCount"in r)return{left_size:r.leftPinCount,right_size:r.rightPinCount,top_size:r.topPinCount,bottom_size:r.bottomPinCount};if("leftSize"in r||"rightSize"in r||"topSize"in r||"bottomSize"in r)return{left_size:r.leftSize,right_size:r.rightSize,top_size:r.topSize,bottom_size:r.bottomSize}}};function a0e(r){const e=[];for(let t=0;t<r.length-1;t++)e.push([r[t],r[t+1]]);return e}var Hot=Vn({name:He()}),o0e=class extends Kv{constructor(){super(...arguments);Ve(this,"source_net_id")}get config(){return{componentName:"Net",zodProps:Hot}}getPortSelector(){return`net.${this.props.name}`}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_net.insert({name:n.name,member_source_group_ids:[]});this.source_net_id=i.source_net_id}doInitialSourceParentAttachment(){const t=this.getSubcircuit();if(!t)return;const{db:n}=this.root;n.source_net.update(this.source_net_id,{subcircuit_id:t.subcircuit_id})}getAllConnectedPorts(){const t=this.getSubcircuit().selectAll("port"),n=[];for(const i of t){const a=i._getDirectlyConnectedTraces();for(const o of a)if(o._isExplicitlyConnectedToNet(this)){n.push(i);break}}return n}_getAllDirectlyConnectedTraces(){const t=this.getSubcircuit().selectAll("trace"),n=[];for(const i of t)i._isExplicitlyConnectedToNet(this)&&n.push(i);return n}doInitialPcbRouteNetIslands(){var s;if((s=this.root)!=null&&s.pcbDisabled||this.getSubcircuit()._parsedProps.routingDisabled||this.getSubcircuit()._getAutorouterConfig().groupMode!=="sequential-trace")return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getAllDirectlyConnectedTraces().filter(l=>{var c;return(((c=l._portsRoutedOnPcb)==null?void 0:c.length)??0)>0}),a=[];for(const l of i){const c=l._portsRoutedOnPcb,A=a.find(u=>c.some(d=>u.ports.includes(d)));if(!A){a.push({ports:[...c],traces:[l]});continue}A.traces.push(l),A.ports.push(...c)}if(a.length===0)return;const o=a0e(a);for(const[l,c]of o){const A=l.ports.map(Q=>Q._getGlobalPcbPositionBeforeLayout()),u=c.ports.map(Q=>Q._getGlobalPcbPositionBeforeLayout());let d=1/0,g=[-1,-1];for(let Q=0;Q<A.length;Q++){const P=A[Q];for(let z=0;z<u.length;z++){const O=u[z],V=Math.sqrt((P.x-O.x)**2+(P.y-O.y)**2);V<d&&(d=V,g=[Q,z])}}const m=l.ports[g[0]],C=c.ports[g[1]],E=t.toArray().filter(Q=>Q.type==="pcb_smtpad"||Q.type==="pcb_trace"||Q.type==="pcb_plated_hole"||Q.type==="pcb_hole"||Q.type==="source_port"||Q.type==="pcb_port"),{solution:_}=Jhe(E.concat([{type:"source_trace",source_trace_id:"__net_trace_tmp",connected_source_port_ids:[m.source_port_id,C.source_port_id]}])),x=_[0];if(!x){this.renderError({pcb_trace_error_id:"",pcb_trace_id:"__net_trace_tmp",pcb_component_ids:[m.pcb_component_id,C.pcb_component_id].filter(Boolean),pcb_port_ids:[m.pcb_port_id,C.pcb_port_id].filter(Boolean),type:"pcb_trace_error",error_type:"pcb_trace_error",message:`Failed to route net islands for "${this.getString()}"`,source_trace_id:"__net_trace_tmp"});return}t.pcb_trace.insert(x)}}renderError(t){var n;if(typeof t=="string")return super.renderError(t);(n=this.root)==null||n.db.pcb_trace_error.insert(t)}},s0e=(r,e)=>{for(const t of e)if(typeof t=="string"&&t.startsWith("net.")){if(/net\.[^\s>]*\./.test(t))throw new Error('Net names cannot contain a period, try using "sel.net..." to autocomplete with conventional net names, e.g. V3_3');if(/net\.[0-9]/.test(t))throw new Error('Net names cannot start with a number, try using a prefix like "VBUS1"');const n=r.getSubcircuit();if(!n.selectOne(t)){const i=new o0e({name:t.split("net.")[1]});n.add(i)}}},wY=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_smtpad_id",null);Ve(this,"matchedPort",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SmtPad",zodProps:Age}}getPcbSize(){const{_parsedProps:t}=this;if(t.shape==="circle")return{width:t.radius*2,height:t.radius*2};if(t.shape==="rect")return{width:t.width,height:t.height};throw new Error(`getPcbSize for shape "${t.shape}" not implemented for ${this.componentName}`)}doInitialPortMatching(){var n;const t=(n=this.getPrimitiveContainer())==null?void 0:n.selectAll("port");if(this.props.portHints){for(const i of t)if(i.isMatchingAnyOf(this.props.portHints)){this.matchedPort=i,i.registerMatch(this);return}}}doInitialPcbPrimitiveRender(){var g,m,C,E,_,x,Q,P,z,O;if((g=this.root)!=null&&g.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this;if(!n.portHints)return;const i=this.getPrimitiveContainer(),a=this.getSubcircuit(),o=this._getGlobalPcbPositionBeforeLayout();i==null||i._getGlobalPcbPositionBeforeLayout();const s=f9(this._computePcbGlobalTransformBeforeLayout()),l=Math.abs(s.rotation.angle*(180/Math.PI)-90)%180<.01,{maybeFlipLayer:c}=this._getPcbPrimitiveFlippedHelpers(),A=(i==null?void 0:i._parsedProps.pcbRotation)??0;let u=null;const d=((m=this.parent)==null?void 0:m.pcb_component_id)??((C=this.getPrimitiveContainer())==null?void 0:C.pcb_component_id);n.shape==="circle"?(u=t.pcb_smtpad.insert({pcb_component_id:d,pcb_port_id:(E=this.matchedPort)==null?void 0:E.pcb_port_id,layer:c(n.layer??"top"),shape:"circle",radius:n.radius,port_hints:n.portHints.map(V=>V.toString()),x:o.x,y:o.y,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0}),t.pcb_solder_paste.insert({layer:u.layer,shape:"circle",radius:u.radius*.7,x:u.x,y:u.y,pcb_component_id:u.pcb_component_id,pcb_smtpad_id:u.pcb_smtpad_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((_=this.getGroup())==null?void 0:_.pcb_group_id)??void 0})):n.shape==="rect"&&(u=A===0||l?t.pcb_smtpad.insert({pcb_component_id:d,pcb_port_id:(x=this.matchedPort)==null?void 0:x.pcb_port_id,layer:c(n.layer??"top"),shape:"rect",width:l?n.height:n.width,height:l?n.width:n.height,port_hints:n.portHints.map(V=>V.toString()),x:o.x,y:o.y,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((Q=this.getGroup())==null?void 0:Q.pcb_group_id)??void 0}):t.pcb_smtpad.insert({pcb_component_id:d,layer:c(n.layer??"top"),shape:"rotated_rect",width:n.width,height:n.height,x:o.x,y:o.y,ccw_rotation:A,port_hints:n.portHints.map(V=>V.toString()),subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((P=this.getGroup())==null?void 0:P.pcb_group_id)??void 0}),u.shape==="rect"&&t.pcb_solder_paste.insert({layer:c(n.layer??"top"),shape:"rect",width:u.width*.7,height:u.height*.7,x:u.x,y:u.y,pcb_component_id:u.pcb_component_id,pcb_smtpad_id:u.pcb_smtpad_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((z=this.getGroup())==null?void 0:z.pcb_group_id)??void 0}),u.shape==="rotated_rect"&&t.pcb_solder_paste.insert({layer:c(n.layer??"top"),shape:"rotated_rect",width:u.width*.7,height:u.height*.7,x:u.x,y:u.y,ccw_rotation:A,pcb_component_id:u.pcb_component_id,pcb_smtpad_id:u.pcb_smtpad_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((O=this.getGroup())==null?void 0:O.pcb_group_id)??void 0})),u&&(this.pcb_smtpad_id=u.pcb_smtpad_id)}doInitialPcbPortAttachment(){var n,i;if((n=this.root)!=null&&n.pcbDisabled)return;const{db:t}=this.root;t.pcb_smtpad.update(this.pcb_smtpad_id,{pcb_port_id:(i=this.matchedPort)==null?void 0:i.pcb_port_id})}_getPcbCircuitJsonBounds(){const{db:t}=this.root,n=t.pcb_smtpad.get(this.pcb_smtpad_id);if(n.shape==="rect")return{center:{x:n.x,y:n.y},bounds:{left:n.x-n.width/2,top:n.y+n.height/2,right:n.x+n.width/2,bottom:n.y-n.height/2},width:n.width,height:n.height};if(n.shape==="rotated_rect"){const i=n.ccw_rotation*Math.PI/180,a=Math.cos(i),o=Math.sin(i),s=n.width/2,l=n.height/2,c=Math.abs(s*a)+Math.abs(l*o),A=Math.abs(s*o)+Math.abs(l*a);return{center:{x:n.x,y:n.y},bounds:{left:n.x-c,right:n.x+c,top:n.y-A,bottom:n.y+A},width:c*2,height:A*2}}if(n.shape==="circle")return{center:{x:n.x,y:n.y},bounds:{left:n.x-n.radius,top:n.y-n.radius,right:n.x+n.radius,bottom:n.y+n.radius},width:n.radius*2,height:n.radius*2};throw new Error(`circuitJson bounds calculation not implemented for shape "${n.shape}"`)}_setPositionFromLayout(t){var a;const{db:n}=this.root;n.pcb_smtpad.update(this.pcb_smtpad_id,{x:t.x,y:t.y});const i=n.pcb_solder_paste.list().find(o=>o.pcb_smtpad_id===this.pcb_smtpad_id);n.pcb_solder_paste.update(i==null?void 0:i.pcb_solder_paste_id,{x:t.x,y:t.y}),(a=this.matchedPort)==null||a._setPositionFromLayout(t)}},l0e=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_silkscreen_path_id",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenPath",zodProps:Nge}}doInitialPcbPrimitiveRender(){var c,A,u;if((c=this.root)!=null&&c.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(n.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenPath. Must be "top" or "bottom".`);const o=this._computePcbGlobalTransformBeforeLayout(),s=this.getSubcircuit(),l=t.pcb_silkscreen_path.insert({pcb_component_id:(A=this.parent)==null?void 0:A.pcb_component_id,layer:a,route:n.route.map(d=>{const g=si(o,{x:d.x,y:d.y});return{...d,x:g.x,y:g.y}}),stroke_width:n.strokeWidth??.1,subcircuit_id:(s==null?void 0:s.subcircuit_id)??void 0,pcb_group_id:((u=this.getGroup())==null?void 0:u.pcb_group_id)??void 0});this.pcb_silkscreen_path_id=l.pcb_silkscreen_path_id}getPcbSize(){const{_parsedProps:t}=this;if(!t.route||t.route.length===0)return{width:0,height:0};let n=1/0,i=-1/0,a=1/0,o=-1/0;for(const s of t.route)n=Math.min(n,s.x),i=Math.max(i,s.x),a=Math.min(a,s.y),o=Math.max(o,s.y);return{width:i-n,height:o-a}}},Yot=Vn({route:Ga(ET),source_trace_id:He().optional()}),c0e=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_trace_id",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbTrace",zodProps:Yot}}doInitialPcbPrimitiveRender(){var A,u;if((A=this.root)!=null&&A.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getPrimitiveContainer(),a=this.getSubcircuit(),{maybeFlipLayer:o}=this._getPcbPrimitiveFlippedHelpers(),s=this._computePcbGlobalTransformBeforeLayout(),l=n.route.map(d=>{const{x:g,y:m,...C}=d,E=si(s,{x:g,y:m});return d.route_type==="wire"&&d.layer?{...E,...C,layer:o(d.layer)}:{...E,...C}}),c=t.pcb_trace.insert({pcb_component_id:i.pcb_component_id,source_trace_id:n.source_trace_id,route:l,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((u=this.getGroup())==null?void 0:u.pcb_group_id)??void 0});this.pcb_trace_id=c.pcb_trace_id}getPcbSize(){const{_parsedProps:t}=this;if(!t.route||t.route.length===0)return{width:0,height:0};let n=1/0,i=-1/0,a=1/0,o=-1/0;for(const s of t.route)n=Math.min(n,s.x),i=Math.max(i,s.x),a=Math.min(a,s.y),o=Math.max(o,s.y),s.route_type==="wire"&&(n=Math.min(n,s.x-s.width/2),i=Math.max(i,s.x+s.width/2),a=Math.min(a,s.y-s.width/2),o=Math.max(o,s.y+s.width/2));return n===1/0||i===-1/0||a===1/0||o===-1/0?{width:0,height:0}:{width:i-n,height:o-a}}},MY=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_plated_hole_id",null);Ve(this,"matchedPort",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PlatedHole",zodProps:tge}}getAvailablePcbLayers(){return["top","inner1","inner2","bottom"]}getPcbSize(){const{_parsedProps:t}=this;if(t.shape==="circle")return{width:t.outerDiameter,height:t.outerDiameter};if(t.shape==="oval"||t.shape==="pill")return{width:t.outerWidth,height:t.outerHeight};if(t.shape==="circular_hole_with_rect_pad")return{width:t.rectPadWidth,height:t.rectPadHeight};if(t.shape==="pill_hole_with_rect_pad")return{width:t.rectPadWidth,height:t.rectPadHeight};throw new Error(`getPcbSize for shape "${t.shape}" not implemented for ${this.componentName}`)}_getPcbCircuitJsonBounds(){const{db:t}=this.root,n=t.pcb_plated_hole.get(this.pcb_plated_hole_id),i=this.getPcbSize();return{center:{x:n.x,y:n.y},bounds:{left:n.x-i.width/2,top:n.y+i.height/2,right:n.x+i.width/2,bottom:n.y-i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(t){var i;const{db:n}=this.root;n.pcb_plated_hole.update(this.pcb_plated_hole_id,{x:t.x,y:t.y}),(i=this.matchedPort)==null||i._setPositionFromLayout(t)}doInitialPortMatching(){var n;const t=(n=this.getPrimitiveContainer())==null?void 0:n.selectAll("port");if(this.props.portHints){for(const i of t)if(i.isMatchingAnyOf(this.props.portHints)){this.matchedPort=i,i.registerMatch(this);return}}}doInitialPcbPrimitiveRender(){var s,l,c,A,u,d,g,m,C,E,_,x,Q,P,z;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalPcbPositionBeforeLayout(),a=((l=this.parent)==null?void 0:l.pcb_component_id)??((c=this.getPrimitiveContainer())==null?void 0:c.pcb_component_id),o=this.getSubcircuit();if(n.shape==="circle"){const O=t.pcb_plated_hole.insert({pcb_component_id:a,pcb_port_id:(A=this.matchedPort)==null?void 0:A.pcb_port_id,outer_diameter:n.outerDiameter,hole_diameter:n.holeDiameter,shape:"circle",port_hints:this.getNameAndAliases(),x:i.x,y:i.y,layers:["top","bottom"],subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((u=this.getGroup())==null?void 0:u.pcb_group_id)??void 0});this.pcb_plated_hole_id=O.pcb_plated_hole_id,t.pcb_solder_paste.insert({layer:"top",shape:"circle",radius:n.outerDiameter/2,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((d=this.getGroup())==null?void 0:d.pcb_group_id)??void 0}),t.pcb_solder_paste.insert({layer:"bottom",shape:"circle",radius:n.outerDiameter/2,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((g=this.getGroup())==null?void 0:g.pcb_group_id)??void 0})}else if(n.shape==="pill"||n.shape==="oval"){const O=t.pcb_plated_hole.insert({pcb_component_id:a,pcb_port_id:(m=this.matchedPort)==null?void 0:m.pcb_port_id,outer_width:n.outerWidth,outer_height:n.outerHeight,hole_width:n.holeWidth,hole_height:n.holeHeight,shape:n.shape,port_hints:this.getNameAndAliases(),x:i.x,y:i.y,layers:["top","bottom"],subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((C=this.getGroup())==null?void 0:C.pcb_group_id)??void 0});this.pcb_plated_hole_id=O.pcb_plated_hole_id,t.pcb_solder_paste.insert({layer:"top",shape:n.shape,width:n.outerWidth,height:n.outerHeight,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((E=this.getGroup())==null?void 0:E.pcb_group_id)??void 0}),t.pcb_solder_paste.insert({layer:"bottom",shape:n.shape,width:n.outerWidth,height:n.outerHeight,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((_=this.getGroup())==null?void 0:_.pcb_group_id)??void 0})}else if(n.shape==="circular_hole_with_rect_pad"){const O=t.pcb_plated_hole.insert({pcb_component_id:a,pcb_port_id:(x=this.matchedPort)==null?void 0:x.pcb_port_id,hole_diameter:n.holeDiameter,rect_pad_width:n.rectPadWidth,rect_pad_height:n.rectPadHeight,shape:"circular_hole_with_rect_pad",port_hints:this.getNameAndAliases(),x:i.x,y:i.y,layers:["top","bottom"],subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((Q=this.getGroup())==null?void 0:Q.pcb_group_id)??void 0});this.pcb_plated_hole_id=O.pcb_plated_hole_id}else if(n.shape==="pill_hole_with_rect_pad"){const O=t.pcb_plated_hole.insert({pcb_component_id:a,pcb_port_id:(P=this.matchedPort)==null?void 0:P.pcb_port_id,hole_width:n.holeWidth,hole_height:n.holeHeight,rect_pad_width:n.rectPadWidth,rect_pad_height:n.rectPadHeight,shape:"pill_hole_with_rect_pad",port_hints:this.getNameAndAliases(),x:i.x,y:i.y,layers:["top","bottom"],subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((z=this.getGroup())==null?void 0:z.pcb_group_id)??void 0});this.pcb_plated_hole_id=O.pcb_plated_hole_id}}doInitialPcbPortAttachment(){var n,i;if((n=this.root)!=null&&n.pcbDisabled)return;const{db:t}=this.root;t.pcb_plated_hole.update(this.pcb_plated_hole_id,{pcb_port_id:(i=this.matchedPort)==null?void 0:i.pcb_port_id})}},DY=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_keepout_id",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Keepout",zodProps:Qge}}doInitialPcbPrimitiveRender(){var c,A,u;if((c=this.root)!=null&&c.pcbDisabled)return;const t=this.getSubcircuit(),{db:n}=this.root,{_parsedProps:i}=this,a=this._getGlobalPcbPositionBeforeLayout(),o=f9(this._computePcbGlobalTransformBeforeLayout()),s=Math.abs(o.rotation.angle*(180/Math.PI)-90)%180<.01;let l=null;i.shape==="circle"?l=n.pcb_keepout.insert({layers:["top"],shape:"circle",radius:i.radius,center:{x:a.x,y:a.y},subcircuit_id:(t==null?void 0:t.subcircuit_id)??void 0,pcb_group_id:((A=t==null?void 0:t.getGroup())==null?void 0:A.pcb_group_id)??void 0}):i.shape==="rect"&&(l=n.pcb_keepout.insert({layers:["top"],shape:"rect",...s?{width:i.height,height:i.width}:{width:i.width,height:i.height},center:{x:a.x,y:a.y},subcircuit_id:(t==null?void 0:t.subcircuit_id)??void 0,pcb_group_id:((u=t==null?void 0:t.getGroup())==null?void 0:u.pcb_group_id)??void 0})),l&&(this.pcb_keepout_id=l.pcb_keepout_id)}},A0e=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_hole_id",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Hole",zodProps:uge}}getPcbSize(){const{_parsedProps:t}=this;return{width:t.diameter,height:t.diameter}}doInitialPcbPrimitiveRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getSubcircuit(),a=this._getGlobalPcbPositionBeforeLayout(),o=t.pcb_hole.insert({hole_shape:"circle",hole_diameter:n.diameter,x:a.x,y:a.y,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((l=i==null?void 0:i.getGroup())==null?void 0:l.pcb_group_id)??void 0});this.pcb_hole_id=o.pcb_hole_id}_getPcbCircuitJsonBounds(){const{db:t}=this.root,n=t.pcb_hole.get(this.pcb_hole_id),i=this.getPcbSize();return{center:{x:n.x,y:n.y},bounds:{left:n.x-i.width/2,top:n.y-i.height/2,right:n.x+i.width/2,bottom:n.y+i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(t){const{db:n}=this.root;n.pcb_hole.update(this.pcb_hole_id,{x:t.x,y:t.y})}},RY=class extends Kv{constructor(){super(...arguments);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenText",zodProps:Rge}}doInitialPcbPrimitiveRender(){var l,c;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getPrimitiveContainer(),a=this._getGlobalPcbPositionBeforeLayout(),{maybeFlipLayer:o}=this._getPcbPrimitiveFlippedHelpers(),s=this.getSubcircuit();t.pcb_silkscreen_text.insert({anchor_alignment:n.anchorAlignment,anchor_position:{x:a.x,y:a.y},font:n.font??"tscircuit2024",font_size:n.fontSize??1,layer:o(n.layer??"top"),text:n.text??"",ccw_rotation:n.pcbRotation,pcb_component_id:i.pcb_component_id,subcircuit_id:(s==null?void 0:s.subcircuit_id)??void 0,pcb_group_id:((c=this.getGroup())==null?void 0:c.pcb_group_id)??void 0})}getPcbSize(){const{_parsedProps:t}=this,n=t.fontSize??1,a=(t.text??"").length*n,o=n;return{width:a*n,height:o*n}}},Vot=({elm:r,pinLabels:e,readableRotation:t,anchorAlignment:n})=>{var o;const i=r.text.replace(/[{}]/g,"").toLowerCase();let a=i;if(Array.isArray(e)){const s=parseInt(i.replace(/[^\d]/g,""),10)-1;a=e[s]??i}else typeof e=="object"&&(a=((o=e[i])==null?void 0:o[0])??i);return new RY({anchorAlignment:n||"center",text:a??i,fontSize:r.font_size+.2,pcbX:isNaN(r.anchor_position.x)?0:r.anchor_position.x,pcbY:r.anchor_position.y,pcbRotation:t??0})},Kot=(r,e)=>((-parseInt(r||"0",10)+(e??0))%360+360)%360,u0e=({componentName:r,componentRotation:e,footprint:t,pinLabels:n},i)=>{const a=[];for(const o of i)if(o.type==="pcb_smtpad"&&o.shape==="rect")a.push(new wY({pcbX:o.x,pcbY:o.y,layer:o.layer,shape:"rect",height:o.height,width:o.width,portHints:o.port_hints}));else if(o.type==="pcb_smtpad"&&o.shape==="circle")a.push(new wY({pcbX:o.x,pcbY:o.y,layer:o.layer,shape:"circle",radius:o.radius,portHints:o.port_hints}));else if(o.type==="pcb_silkscreen_path")a.push(new l0e({layer:o.layer,route:o.route,strokeWidth:o.stroke_width}));else if(o.type==="pcb_plated_hole")o.shape==="circle"?a.push(new MY({pcbX:o.x,pcbY:o.y,shape:"circle",holeDiameter:o.hole_diameter,outerDiameter:o.outer_diameter,portHints:o.port_hints})):o.shape==="circular_hole_with_rect_pad"&&a.push(new MY({pcbX:o.x,pcbY:o.y,shape:"circular_hole_with_rect_pad",holeDiameter:o.hole_diameter,rectPadHeight:o.rect_pad_height,rectPadWidth:o.rect_pad_width,portHints:o.port_hints}));else if(o.type==="pcb_keepout"&&o.shape==="circle")a.push(new DY({pcbX:o.center.x,pcbY:o.center.y,shape:"circle",radius:o.radius}));else if(o.type==="pcb_keepout"&&o.shape==="rect")a.push(new DY({pcbX:o.center.x,pcbY:o.center.y,shape:"rect",width:o.width,height:o.height}));else if(o.type==="pcb_hole"&&o.hole_shape==="circle")a.push(new A0e({pcbX:o.x,pcbY:o.y,diameter:o.hole_diameter}));else if(o.type==="pcb_silkscreen_text"){const s=Kot(e,o.ccw_rotation);t.includes("pinrow")&&o.text.includes("PIN")?a.push(Vot({elm:o,pinLabels:n,readableRotation:s,anchorAlignment:o.anchor_alignment})):a.push(new RY({anchorAlignment:o.anchor_alignment||"center",text:r,fontSize:o.font_size+.2,pcbX:isNaN(o.anchor_position.x)?0:o.anchor_position.x,pcbY:o.anchor_position.y,pcbRotation:s??0}))}else o.type==="pcb_trace"&&a.push(new c0e({route:o.route}));return a};function NY(r){let e=1/0,t=1/0,n=-1/0,i=-1/0,a=!1;for(const l of r)if(l.isPcbPrimitive&&!l.componentName.startsWith("Silkscreen")){const{x:c,y:A}=l._getGlobalPcbPositionBeforeLayout(),{width:u,height:d}=l.getPcbSize();e=Math.min(e,c-u/2),t=Math.min(t,A-d/2),n=Math.max(n,c+u/2),i=Math.max(i,A+d/2),a=!0}else if(l.children.length>0){const c=NY(l.children);(c.width>0||c.height>0)&&(e=Math.min(e,c.minX),t=Math.min(t,c.minY),n=Math.max(n,c.maxX),i=Math.max(i,c.maxY),a=!0)}if(!a)return{minX:0,minY:0,maxX:0,maxY:0,width:0,height:0};let o=n-e,s=i-t;return o<0&&(o=0),s<0&&(s=0),{minX:e,minY:t,maxX:n,maxY:i,width:o,height:s}}function Jot(r,e){const t=e.x-r.x,n=e.y-r.y;return Math.abs(t)>Math.abs(n)?t>=0?"right":"left":n>=0?"up":"down"}var jot=r=>{if(r.length<=1)return!0;const e=r.map(a=>{const o=a._getPcbCircuitJsonBounds();return{left:o.bounds.left,right:o.bounds.right,top:o.bounds.top,bottom:o.bounds.bottom}}),t=Array(e.length).fill(!1).map(()=>Array(e.length).fill(!1));for(let a=0;a<e.length;a++)for(let o=a+1;o<e.length;o++){const s=e[a],l=e[o];t[a][o]=t[o][a]=!(s.right<l.left||s.left>l.right||s.bottom>l.top||s.top<l.bottom)}const n=new Set,i=a=>{n.add(a);for(let o=0;o<e.length;o++)t[a][o]&&!n.has(o)&&i(o)};return i(0),n.size===e.length},Wot=r=>{if(r.length===0)throw new Error("Cannot get center of empty PCB primitives array");const e=r.map(i=>i._getPcbCircuitJsonBounds().center).filter(Boolean),t=e.reduce((i,a)=>i+a.x,0),n=e.reduce((i,a)=>i+a.y,0);return{x:t/e.length,y:n/e.length}},Zot=Vn({name:He().optional(),pinNumber:qr().optional(),aliases:Ga(He()).optional()}),yS=class extends Kv{constructor(t,n={}){if(!t.name&&t.pinNumber!==void 0&&(t.name=`pin${t.pinNumber}`),!t.name)throw new Error("Port must have a name or a pinNumber");super(t);Ve(this,"source_port_id",null);Ve(this,"pcb_port_id",null);Ve(this,"schematic_port_id",null);Ve(this,"schematicSymbolPortDef",null);Ve(this,"matchedComponents");Ve(this,"facingDirection",null);Ve(this,"originDescription",null);n.originDescription&&(this.originDescription=n.originDescription),this.matchedComponents=[]}get config(){return{componentName:"Port",zodProps:Zot}}_getGlobalPcbPositionBeforeLayout(){const t=this.matchedComponents.find(i=>i.isPcbPrimitive),n=this.parent;if(n&&!n.props.footprint)throw new Error(`${n.componentName} "${n.props.name}" does not have a footprint. Add a footprint prop, e.g. <${n.componentName.toLowerCase()} footprint="..." />`);if(!t)throw new Error(`Port ${this} has no matching PCB primitives. This often means the footprint's pads lack matching port hints.`);return(t==null?void 0:t._getGlobalPcbPositionBeforeLayout())??{x:0,y:0}}_getPcbCircuitJsonBounds(){if(!this.pcb_port_id)return super._getPcbCircuitJsonBounds();const{db:t}=this.root,n=t.pcb_port.get(this.pcb_port_id);return{center:{x:n.x,y:n.y},bounds:{left:0,top:0,right:0,bottom:0},width:0,height:0}}_getGlobalPcbPositionAfterLayout(){return this._getPcbCircuitJsonBounds().center}_getPortsInternallyConnectedToThisPort(){const t=this.parent;if(!t||!t._getInternallyConnectedPins)return[];const n=t._getInternallyConnectedPins();for(const i of n)if(i.some(a=>a===this))return i;return[]}_hasSchematicPort(){var i,a;if((i=this.parent)==null?void 0:i.getSchematicSymbol())return!!(this.schematicSymbolPortDef||this._getPortsInternallyConnectedToThisPort().some(s=>s.schematicSymbolPortDef));const n=(a=this==null?void 0:this.parent)==null?void 0:a._getSchematicBoxDimensions();return!!(n&&this.props.pinNumber!==void 0&&n.getPortPositionByPinNumber(this.props.pinNumber))}_getGlobalSchematicPositionBeforeLayout(){var i,a,o;const t=(i=this.parent)==null?void 0:i.getSchematicSymbol();if(t){let s=this.schematicSymbolPortDef;if(!s&&(s=((a=this._getPortsInternallyConnectedToThisPort().find(c=>c.schematicSymbolPortDef))==null?void 0:a.schematicSymbolPortDef)??null,!s))throw new Error(`Couldn't find schematicSymbolPortDef for port ${this.getString()}, searched internally connected ports and none had a schematicSymbolPortDef. Why are we trying to get the schematic position of this port?`);const l=OA(this.parent.computeSchematicGlobalTransform(),Kd(-t.center.x,-t.center.y));return si(l,s)}const n=(o=this==null?void 0:this.parent)==null?void 0:o._getSchematicBoxDimensions();if(n&&this.props.pinNumber!==void 0){const s=n.getPortPositionByPinNumber(this.props.pinNumber);if(!s)throw new Error(`Couldn't find position for schematic_port for port ${this.getString()} inside of the schematic box`);return si(this.parent.computeSchematicGlobalTransform(),s)}throw new Error(`Couldn't find position for schematic_port for port ${this.getString()}`)}_getGlobalSchematicPositionAfterLayout(){const{db:t}=this.root;if(!this.schematic_port_id)throw new Error(`Can't get schematic port position after layout for "${this.getString()}", no schematic_port_id`);const n=t.schematic_port.get(this.schematic_port_id);if(!n)throw new Error(`Schematic port not found when trying to get post-layout position: ${this.schematic_port_id}`);return n.center}registerMatch(t){this.matchedComponents.push(t)}getNameAndAliases(){const{_parsedProps:t}=this;return Array.from(new Set([...t.aliases??[],...t.name?[t.name]:[],...typeof t.pinNumber=="number"?[`pin${t.pinNumber}`,t.pinNumber.toString()]:[],...this.externallyAddedAliases??[]]))}isMatchingPort(t){return this.isMatchingAnyOf(t.getNameAndAliases())}getPortSelector(){var t;return`.${(t=this.parent)==null?void 0:t.props.name} > port.${this.props.name}`}getAvailablePcbLayers(){return Array.from(new Set(this.matchedComponents.flatMap(t=>t.getAvailablePcbLayers())))}_getDirectlyConnectedTraces(){return this.getSubcircuit().selectAll("trace").filter(i=>i._isExplicitlyConnectedToPort(this))}doInitialSourceRender(){var o,s;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getNameAndAliases(),a=t.source_port.insert({name:n.name,pin_number:n.pinNumber,port_hints:i,source_component_id:(o=this.parent)==null?void 0:o.source_component_id,subcircuit_id:(s=this.getSubcircuit())==null?void 0:s.subcircuit_id});this.source_port_id=a.source_port_id}doInitialSourceParentAttachment(){var n,i,a,o,s;const{db:t}=this.root;if(!((n=this.parent)!=null&&n.source_component_id))throw new Error(`${this.getString()} has no parent source component (parent: ${(i=this.parent)==null?void 0:i.getString()})`);t.source_port.update(this.source_port_id,{source_component_id:(a=this.parent)==null?void 0:a.source_component_id,subcircuit_id:(o=this.getSubcircuit())==null?void 0:o.subcircuit_id}),this.source_component_id=(s=this.parent)==null?void 0:s.source_component_id}doInitialPcbPortRender(){var o,s,l,c,A;if((o=this.root)!=null&&o.pcbDisabled)return;const{db:t}=this.root,{matchedComponents:n}=this;if(!((s=this.parent)!=null&&s.pcb_component_id))throw new Error(`${this.getString()} has no parent pcb component, cannot render pcb_port (parent: ${(l=this.parent)==null?void 0:l.getString()})`);const i=n.filter(u=>u.isPcbPrimitive);if(i.length===0)return;let a=null;if(i.length===1&&(a=i[0]._getPcbCircuitJsonBounds().center),i.length>1){if(!jot(i))throw new Error(`${this.getString()} has multiple non-overlapping pcb matches, unclear how to place pcb_port: ${i.map(u=>u.getString()).join(", ")}. (Note: tscircuit core does not currently allow you to specify internally connected pcb primitives with the same port hints, try giving them different port hints and specifying they are connected externally- or file an issue)`);a=Wot(i)}if(a){const u=this.getSubcircuit(),d=t.pcb_port.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layers:this.getAvailablePcbLayers(),subcircuit_id:(u==null?void 0:u.subcircuit_id)??void 0,pcb_group_id:((A=this.getGroup())==null?void 0:A.pcb_group_id)??void 0,...a,source_port_id:this.source_port_id});this.pcb_port_id=d.pcb_port_id}else{const u=i[0];throw new Error(`${u.getString()} does not have a center or _getGlobalPcbPositionBeforeLayout method (needed for pcb_port placement)`)}}doInitialSchematicPortRender(){var d;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getPrimitiveContainer();if(!i||!this._hasSchematicPort())return;const a=i._getGlobalSchematicPositionBeforeLayout(),o=this._getGlobalSchematicPositionBeforeLayout();let s=null;const l=i._getSchematicBoxDimensions();l&&n.pinNumber!==void 0&&(s=l.getPortPositionByPinNumber(n.pinNumber)),this.getSubcircuit().props._schDebugObjectsEnabled&&t.schematic_debug_object.insert({shape:"rect",center:o,size:{width:.1,height:.1},label:"obstacle"}),s!=null&&s.side?this.facingDirection={left:"left",right:"right",top:"up",bottom:"down"}[s.side]:this.facingDirection=Jot(a,o);const c=t.source_port.get(this.source_port_id);let A;for(const g of(c==null?void 0:c.port_hints)??[])g.match(/^(pin)?\d+$/)||g.match(/^(left|right)/)&&!(c!=null&&c.name.match(/^(left|right)/))||(A=g);const u=t.schematic_port.insert({schematic_component_id:(d=this.parent)==null?void 0:d.schematic_component_id,center:o,source_port_id:this.source_port_id,facing_direction:this.facingDirection,distance_from_component_edge:.4,side_of_component:s==null?void 0:s.side,pin_number:n.pinNumber,true_ccw_index:s==null?void 0:s.trueIndex,display_pin_label:A});this.schematic_port_id=u.schematic_port_id}_setPositionFromLayout(t){const{db:n}=this.root;this.pcb_port_id&&n.pcb_port.update(this.pcb_port_id,{x:t.x,y:t.y})}_hasMatchedPcbPrimitive(){return this.matchedComponents.some(t=>t.isPcbPrimitive)}},d0e=r=>{const e=r.find(t=>/^(pin)?\d+$/.test(t));return e?Number.parseInt(e.replace(/^pin/,"")):null};function vD(r,e){var a;const t=d0e(r);if(!t)return null;const i=[...r.filter(o=>o.toString()!==t.toString()&&o!==`pin${t}`),...((a=e==null?void 0:e.additionalAliases)==null?void 0:a[`pin${t}`])??[]];return new yS({pinNumber:t,aliases:i})}var qot=r=>{for(const e of["leftSide","rightSide","topSide","bottomSide"])if(e in r&&typeof r[e]=="number")throw new Error(`A number was specified for "${e}", you probably meant to use "size" not "side"`);return"leftSide"in r||"rightSide"in r||"topSide"in r||"bottomSide"in r},Xot=r=>{var a,o,s,l;if(qot(r))return{leftSize:((a=r.leftSide)==null?void 0:a.pins.length)??0,rightSize:((o=r.rightSide)==null?void 0:o.pins.length)??0,topSize:((s=r.topSide)==null?void 0:s.pins.length)??0,bottomSize:((l=r.bottomSide)==null?void 0:l.pins.length)??0};const{leftSize:e=0,rightSize:t=0,topSize:n=0,bottomSize:i=0}=r;return{leftSize:e,rightSize:t,topSize:n,bottomSize:i}};function f0e(r){return r.leftSide!==void 0}var $ot=r=>{var E,_,x,Q,P,z,O,V;const e=r.portDistanceFromEdge??.4;let t=r.schPortArrangement?Xot(r.schPortArrangement):null;const n={left:0,right:0,top:0,bottom:0};let i=r.pinCount??null;if(i===null)if(t)i=t.leftSize+t.rightSize+t.topSize;else throw new Error("Could not determine pin count for the schematic box");if(i&&!t){const j=Math.floor(i/2);t={leftSize:i-j,rightSize:j,topSize:0,bottomSize:0}}t||(t={leftSize:0,rightSize:0,topSize:0,bottomSize:0});const a=({side:j,sideIndex:q,truePinIndex:J})=>{var Be,pe,_e,ve;if(!r.schPortArrangement||!f0e(r.schPortArrangement))return J+1;const ce={left:"top-to-bottom",bottom:"left-to-right",right:"bottom-to-top",top:"right-to-left"}[j],oe=((pe=(Be=r.schPortArrangement)==null?void 0:Be[`${j}Side`])==null?void 0:pe.direction)??ce,de=(ve=(_e=r.schPortArrangement)==null?void 0:_e[`${j}Side`])==null?void 0:ve.pins;let Ie=q;return oe!==ce&&(Ie=de.length-q-1),yD(de[Ie],r.pinLabels)},o=[];let s=0,l=0;for(let j=0;j<t.leftSize;j++){const q=a({side:"left",sideIndex:j,truePinIndex:l}),J=((E=r.numericSchPinStyle)==null?void 0:E[`pin${q}`])??((_=r.numericSchPinStyle)==null?void 0:_[q]);J!=null&&J.topMargin&&(s+=J.topMargin),o.push({trueIndex:l,pinNumber:q,side:"left",distanceFromOrthogonalEdge:s}),J!=null&&J.bottomMargin&&(s+=J.bottomMargin),j===t.leftSize-1?n.left=s:s+=r.schPinSpacing,l++}s=0;for(let j=0;j<t.bottomSize;j++){const q=a({side:"bottom",sideIndex:j,truePinIndex:l}),J=((x=r.numericSchPinStyle)==null?void 0:x[`pin${q}`])??((Q=r.numericSchPinStyle)==null?void 0:Q[q]);J!=null&&J.leftMargin&&(s+=J.leftMargin),o.push({trueIndex:l,pinNumber:q,side:"bottom",distanceFromOrthogonalEdge:s}),J!=null&&J.rightMargin&&(s+=J.rightMargin),j===t.bottomSize-1?n.bottom=s:s+=r.schPinSpacing,l++}s=0;for(let j=0;j<t.rightSize;j++){const q=a({side:"right",sideIndex:j,truePinIndex:l}),J=((P=r.numericSchPinStyle)==null?void 0:P[`pin${q}`])??((z=r.numericSchPinStyle)==null?void 0:z[q]);J!=null&&J.bottomMargin&&(s+=J.bottomMargin),o.push({trueIndex:l,pinNumber:q,side:"right",distanceFromOrthogonalEdge:s}),J!=null&&J.topMargin&&(s+=J.topMargin),j===t.rightSize-1?n.right=s:s+=r.schPinSpacing,l++}s=0;for(let j=0;j<t.topSize;j++){const q=a({side:"top",sideIndex:j,truePinIndex:l}),J=((O=r.numericSchPinStyle)==null?void 0:O[`pin${q}`])??((V=r.numericSchPinStyle)==null?void 0:V[q]);J!=null&&J.rightMargin&&(s+=J.rightMargin),o.push({trueIndex:l,pinNumber:q,side:"top",distanceFromOrthogonalEdge:s}),J!=null&&J.leftMargin&&(s+=J.leftMargin),j===t.topSize-1?n.top=s:s+=r.schPinSpacing,l++}let c=r.schWidth;c||(c=Math.max(n.top+r.schPinSpacing*2,n.bottom+r.schPinSpacing*2));const A=r.pinLabels?Math.max(...Object.values(r.pinLabels).map(j=>j.length*.1)):0,u=A>0?1.1:0;c=Math.max(c,A+u);let d=r.schHeight;d||(d=Math.max(n.left+r.schPinSpacing*2,n.right+r.schPinSpacing*2));const g={left:{x:-c/2-e,y:n.left/2},bottom:{x:-n.bottom/2,y:-d/2-e},right:{x:c/2+e,y:-n.right/2},top:{x:n.top/2,y:d/2+e}},m={left:{x:0,y:-1},right:{x:0,y:1},top:{x:-1,y:0},bottom:{x:1,y:0}},C=o.map(j=>{const{distanceFromOrthogonalEdge:q,side:J}=j,ce=g[J],oe=m[J];return{x:ce.x+q*oe.x,y:ce.y+q*oe.y,...j}});return{getPortPositionByPinNumber(j){const q=C.find(J=>J.pinNumber.toString()===j.toString());return q||null},getSize(){return{width:c,height:d}},getSizeIncludingPins(){return{width:c+(t.leftSize||t.rightSize?.4:0),height:d+(t.topSize||t.bottomSize?.4:0)}},pinCount:i}},est=KI("tscircuit:core:footprint"),tst=class extends Kv{get config(){return{componentName:"Footprint",zodProps:hge}}doInitialPcbFootprintLayout(){var d,g,m,C,E;if((d=this.root)!=null&&d.pcbDisabled)return;const e=this.children.filter(_=>_.componentName==="Constraint");if(e.length===0)return;const{isFlipped:t}=this._getPcbPrimitiveFlippedHelpers(),n=_=>t&&"left"in _&&"right"in _?{..._,left:_.right,right:_.left}:_,i=e.flatMap(_=>_._getAllReferencedComponents().componentsWithSelectors).map(({component:_,selector:x,componentSelector:Q,edge:P})=>({component:_,selector:x,componentSelector:Q,edge:P,bounds:_._getPcbCircuitJsonBounds()}));if(i.some(_=>_.edge))throw new Error("edge constraints not implemented yet for footprint layout, contributions welcome!");function a(_){return i.find(({selector:x})=>x===_)}const o=new Gge,s={};function l(_){return _ in s||(s[_]=new SP(_),o.addEditVariable(s[_],JI.weak)),s[_]}for(const{selector:_,bounds:x}of i){const Q=l(`${_}_x`),P=l(`${_}_y`);o.suggestValue(Q,x.center.x),o.suggestValue(P,x.center.y)}for(const _ of e){const x=_._parsedProps;if("xDist"in x){const{xDist:Q,left:P,right:z,edgeToEdge:O,centerToCenter:V}=n(x),j=l(`${P}_x`),q=l(`${z}_x`),J=(g=a(P))==null?void 0:g.bounds,ce=(m=a(z))==null?void 0:m.bounds;if(V){const oe=new hI(q,[-1,j]);o.addConstraint(new CB(oe,Y1.Eq,x.xDist,JI.required))}else if(O){const oe=new hI(q,-ce.width/2,[-1,j],-J.width/2);o.addConstraint(new CB(oe,Y1.Eq,x.xDist,JI.required))}}else if("yDist"in x){const{yDist:Q,top:P,bottom:z,edgeToEdge:O,centerToCenter:V}=x,j=l(`${P}_y`),q=l(`${z}_y`),J=(C=a(P))==null?void 0:C.bounds,ce=(E=a(z))==null?void 0:E.bounds;if(V){const oe=new hI(j,[-1,q]);o.addConstraint(new CB(oe,Y1.Eq,x.yDist,JI.required))}else if(O){const oe=new hI(j,J.height/2,[-1,q],-ce.height/2);o.addConstraint(new CB(oe,Y1.Eq,x.yDist,JI.required))}}else if("sameY"in x){const{for:Q}=x;if(Q.length<2)continue;const P=Q.map(O=>l(`${O}_y`)),z=new hI(...P.slice(1));o.addConstraint(new CB(z,Y1.Eq,P[0],JI.required))}else if("sameX"in x){const{for:Q}=x;if(Q.length<2)continue;const P=Q.map(O=>l(`${O}_x`)),z=new hI(...P.slice(1));o.addConstraint(new CB(z,Y1.Eq,P[0],JI.required))}}o.updateVariables(),est.enabled&&(console.log("Solution to layout constraints:"),console.table(Object.entries(s).map(([_,x])=>({var:_,val:x.value()}))));const c={left:1/0,right:-1/0,top:-1/0,bottom:1/0};for(const{selector:_,bounds:{width:x,height:Q}}of i){const P=l(`${_}_x`),z=l(`${_}_y`),O=P.value()-x/2,V=P.value()+x/2,j=z.value()+Q/2,q=z.value()-Q/2;c.left=Math.min(c.left,O),c.right=Math.max(c.right,V),c.top=Math.max(c.top,j),c.bottom=Math.min(c.bottom,q)}const A={x:-(c.right+c.left)/2,y:-(c.top+c.bottom)/2},u=this.getPrimitiveContainer()._getGlobalPcbPositionBeforeLayout();A.x+=u.x,A.y+=u.y;for(const{component:_,selector:x}of i){const Q=l(`${x}_x`),P=l(`${x}_y`);_._setPositionFromLayout({x:Q.value()+A.x,y:P.value()+A.y})}}},nst=(r,e)=>{if(!r)return;const t={};for(const[n,i]of Object.entries(r)){const a=yD(n,e),o={leftMargin:i.marginLeft??i.leftMargin,rightMargin:i.marginRight??i.rightMargin,topMargin:i.marginTop??i.topMargin,bottomMargin:i.marginBottom??i.bottomMargin};t[`pin${a}`]={...t[`pin${a}`],...o}}return t},h0e=class{constructor({input:e}){Ve(this,"input");this.input=e}solveAndMapToTraces(){const e=[];for(const t of this.input.connections){if(t.pointsToConnect.length!==2)continue;const[n,i]=t.pointsToConnect,a={type:"pcb_trace",pcb_trace_id:"",connection_name:t.name,route:[{route_type:"wire",x:n.x,y:n.y,layer:"top",width:.1},{route_type:"wire",x:i.x,y:i.y,layer:"top",width:.1}]};e.push(a)}return e}},rst=r=>{const e=Math.min(...r.map(a=>a.center.x)),t=Math.max(...r.map(a=>a.center.x)),n=Math.min(...r.map(a=>a.center.y)),i=Math.max(...r.map(a=>a.center.y));return{minX:e,maxX:t,minY:n,maxY:i}},g0e=["top","bottom","inner1","inner2"],a8=(r,e=[])=>{var s;const t=[];if(e.length===0){const l=r[0].layers;for(const c of l)t.push(...a8(r.slice(1),[c]));return t}if(r.length===0)return[];const n=r[0],i=n.via||n.optional_via,a=e[e.length-1];if(r.length===1){const l=n;return l.layers&&i?l.layers.map(c=>({layer_path:[...e,c]})):(s=l.layers)!=null&&s.includes(a)?[{layer_path:[...e,a]}]:[]}if(!i)return n.layers&&!n.layers.includes(a)?[]:a8(r.slice(1),e.concat([a]));const o=(n.optional_via?g0e:g0e.filter(l=>l!==a)).filter(l=>{var c;return!n.layers||((c=n.layers)==null?void 0:c.includes(l))});for(const l of o)t.push(...a8(r.slice(1),e.concat(l)));return t};function p0e(r){const e={x:r.to.x-r.from.x,y:r.to.y-r.from.y},t=Math.abs(e.x),n=Math.abs(e.y);return t>n?e.x>0?"right":"left":e.y>0?"down":"up"}function D9(r,e){return Math.hypot(r.x-e.x,r.y-e.y)}var ist=r=>{if(r.length===1)return r[0];if(r.some(l=>l.length===0))throw new Error("Cannot merge routes with zero length");const e=[],t=r[0][0],n=r[0][r[0].length-1],i=r[1][0],a=r[1][r[1].length-1],o=Math.min(D9(t,i),D9(t,a)),s=Math.min(D9(n,i),D9(n,a));o<s?e.push(...r[0].reverse()):e.push(...r[0]);for(let l=1;l<r.length;l++){const c=e[e.length-1],A=r[l],u=A[0],d=A[A.length-1],g=D9(c,u),m=D9(c,d);g<m?e.push(...A):e.push(...A.reverse())}for(let l=1;l<e.length-1;l++){const c=e[l-1],A=e[l];c.route_type==="wire"&&A.route_type==="wire"&&c.layer!==A.layer&&e.splice(l,0,{x:c.x,y:c.y,from_layer:c.layer,to_layer:A.layer,route_type:"via"})}return e},ast=(r,e)=>{const t="_getGlobalPcbPositionBeforeLayout"in r?r._getGlobalPcbPositionBeforeLayout():r,n="_getGlobalPcbPositionBeforeLayout"in e?e._getGlobalPcbPositionBeforeLayout():e;return Math.sqrt((t.x-n.x)**2+(t.y-n.y)**2)};function ost(r,e){if(e.length===0)throw new Error("No candidates given to getClosest method");let t=e[0],n=1/0;for(const i of e){const a=ast(r,i);a<n&&(t=i,n=a)}return t}var sst=(r,e)=>{let t=0;t+=r.length??0,t+=e.filter(n=>n.is_crossing).length;for(let n=1;n<e.length;n++){const i=e[n-1],a=e[n],o=Math.abs(i.from.x-i.to.x)<.01,s=Math.abs(a.from.x-a.to.x)<.01;o!==s&&t++}return t},TY=r=>({up:"bottom",down:"top",left:"right",right:"left"})[r]??null,PY=({firstEdge:r,firstEdgePort:e,firstDominantDirection:t,lastEdge:n,lastEdgePort:i,lastDominantDirection:a})=>{if(r&&e)return PY({lastEdge:{from:r.to,to:r.from},lastEdgePort:e,lastDominantDirection:t}).reverse().map(s=>({from:s.to,to:s.from}));let o=[];if(n&&i){const s={x:n.to.x,y:n.to.y};a==="left"||a==="right"?(s.x=i.position.x,o.push({from:n.to,to:{...s}}),o.push({from:s,to:{...i.position}})):(s.y=i.position.y,o.push({from:n.to,to:{...s}}),o.push({from:s,to:{...i.position}}))}return o=o.filter(s=>px(s.from,s.to)>.01),o};function lst(r){try{return[r(),null]}catch(e){return[null,e]}}function cst(r){let e=0;for(let t=0;t<r.length;t++){const n=r[t];if(n.route_type==="wire"){const i=r[t+1];if(i){const a=i.x-n.x,o=i.y-n.y;e+=Math.sqrt(a*a+o*o)}}else n.route_type==="via"&&(e+=1.6)}return e}var o8=({db:r,source_trace_id:e,sameNetOnly:t,differentNetOnly:n})=>{!t&&!n&&(n=!0);const i=r.source_trace.get(e),a=[];for(const o of r.schematic_trace.list()){if(o.source_trace_id===e)continue;const s=r.source_trace.get(o.source_trace_id),l=(s==null?void 0:s.subcircuit_connectivity_map_key)===i.subcircuit_connectivity_map_key;n&&l||t&&!l||a.push(o)}return a},m0e=({edges:r,otherEdges:e})=>{const t=[...r];for(let n=0;n<t.length;n++){if(n>2e3)throw new Error("Over 2000 iterations spent inside createSchematicTraceCrossingSegments, you have triggered an infinite loop, please report this!");const i=t[n],a=Math.abs(i.from.x-i.to.x)<.01?"vertical":i.from.y===i.to.y?"horizontal":"not-orthogonal";if(a==="not-orthogonal")continue;const o=[];for(const C of e){const E=C.from.x===C.to.x?"vertical":C.from.y===C.to.y?"horizontal":"not-orthogonal";if(E==="not-orthogonal"||a===E)continue;if(MP([i.from,i.to],[C.from,C.to],{lineThickness:.01})){const x=a==="vertical"?i.from.x:C.from.x,Q=a==="vertical"?C.from.y:i.from.y,P={x,y:Q};o.push({otherEdge:C,crossingPoint:P,distanceFromEdgeFrom:px(i.from,P)})}}if(o.length===0)continue;let s=o[0];for(const C of o)C.distanceFromEdgeFrom<s.distanceFromEdgeFrom&&(s=C);const l=s.crossingPoint,c=.075;if(l.x===i.from.x&&l.y===i.from.y)continue;const A=Oge(i.from,l),u={x:l.x-A.x*c/2,y:l.y-A.y*c/2},d={x:l.x+A.x*c/2,y:l.y+A.y*c/2},g=px(d,i.to)<c,m=[{from:i.from,to:u},{from:u,to:d,is_crossing:!0},{from:d,to:i.to}];t.splice(n,1,...m),n+=m.length-2,g&&n++}return t},Ast=(r,e)=>{if(r.from.x===r.to.x&&e.from.x===e.to.x)return null;if(r.from.x===r.to.x){const A=r.from.x,u=(e.to.y-e.from.y)/(e.to.x-e.from.x),d=e.from.y-u*e.from.x,g=u*A+d;return A>=Math.min(e.from.x,e.to.x)&&A<=Math.max(e.from.x,e.to.x)&&g>=Math.min(e.from.y,e.to.y)&&g<=Math.max(e.from.y,e.to.y)?{x:A,y:g}:null}if(e.from.x===e.to.x){const A=e.from.x,u=(r.to.y-r.from.y)/(r.to.x-r.from.x),d=r.from.y-u*r.from.x,g=u*A+d;return A>=Math.min(r.from.x,r.to.x)&&A<=Math.max(r.from.x,r.to.x)&&g>=Math.min(r.from.y,r.to.y)&&g<=Math.max(r.from.y,r.to.y)?{x:A,y:g}:null}const t=(r.to.y-r.from.y)/(r.to.x-r.from.x),n=r.from.y-t*r.from.x,i=(e.to.y-e.from.y)/(e.to.x-e.from.x),a=e.from.y-i*e.from.x;if(t===i)return null;const o=(a-n)/(t-i),s=t*o+n,l=o>=Math.min(r.from.x,r.to.x)&&o<=Math.max(r.from.x,r.to.x)&&s>=Math.min(r.from.y,r.to.y)&&s<=Math.max(r.from.y,r.to.y),c=o>=Math.min(e.from.x,e.to.x)&&o<=Math.max(e.from.x,e.to.x)&&s>=Math.min(e.from.y,e.to.y)&&s<=Math.max(e.from.y,e.to.y);return l&&c?{x:o,y:s}:null},y0e=({edges:r,db:e,source_trace_id:t})=>{const n=o8({db:e,source_trace_id:t,sameNetOnly:!0}).flatMap(i=>i.edges);for(const i of r)for(const a of n){const o=Ast(i,a);if(o)return`${o.x}${o.y}`,[{x:o.x,y:o.y}]}return[]},ust=(r,{db:e})=>{const t=r.map(n=>{const i=e.source_port.get(n.source_port_id);if(!(i!=null&&i.source_component_id))return null;const a=e.source_component.get(i.source_component_id);return(a==null?void 0:a.ftype)==="simple_capacitor"?a.max_decoupling_trace_length:null}).filter(n=>n!==null);if(t.length!==0)return Math.min(...t)};function dst(r){var a,o,s,l,c,A,u,d,g;let e=1/0,t=1/0,n=-1/0,i=-1/0;for(const m of r){let C,E,_,x;m.type==="schematic_component"?(C=(a=m.center)==null?void 0:a.x,E=(o=m.center)==null?void 0:o.y,_=(s=m.size)==null?void 0:s.width,x=(l=m.size)==null?void 0:l.height):m.type==="schematic_box"?(C=m.x,E=m.y,_=m.width,x=m.height):m.type==="schematic_port"?(C=(c=m.center)==null?void 0:c.x,E=(A=m.center)==null?void 0:A.y,_=.2,x=.2):m.type==="schematic_text"&&(C=(u=m.position)==null?void 0:u.x,E=(d=m.position)==null?void 0:d.y,_=(((g=m.text)==null?void 0:g.length)??0)*.1,x=.2),typeof C=="number"&&typeof E=="number"&&typeof _=="number"&&typeof x=="number"&&(e=Math.min(e,C-_/2),n=Math.max(n,C+_/2),t=Math.min(t,E-x/2),i=Math.max(i,E+x/2))}return{minX:e,maxX:n,minY:t,maxY:i}}function fst(r,e={}){const{minX:t,maxX:n,minY:i,maxY:a}=r,o=e.padding??1;if(!isFinite(t)||!isFinite(n)||!isFinite(i)||!isFinite(a))return[];const s=t-o,l=n+o,c=a+o,A=i-o,u=.01;return[{type:"rect",layers:["top"],center:{x:(s+l)/2,y:c},width:l-s,height:u,connectedTo:[]},{type:"rect",layers:["top"],center:{x:(s+l)/2,y:A},width:l-s,height:u,connectedTo:[]},{type:"rect",layers:["top"],center:{x:s,y:(c+A)/2},width:u,height:c-A,connectedTo:[]},{type:"rect",layers:["top"],center:{x:l,y:(c+A)/2},width:u,height:c-A,connectedTo:[]}]}var hst=r=>{var o;const e=r.root.db,t=r._findConnectedPorts().ports??[],n=new Set(t.map(s=>s.schematic_port_id)),i=[];for(const s of e.toArray()){if(s.type==="schematic_component"){const l=!!s.symbol_name,c=s.size.width>s.size.height?"horz":"vert";i.push({type:"rect",layers:["top"],center:s.center,width:s.size.width+(l&&c==="horz"?-.5:0),height:s.size.height+(l&&c==="vert"?-.5:0),connectedTo:[]})}if(s.type==="schematic_port"){if(n.has(s.schematic_port_id))continue;const l=s.facing_direction?zge(s.facing_direction):{x:0,y:0};i.push({type:"rect",layers:["top"],center:{x:s.center.x-l.x*.1,y:s.center.y-l.y*.1},width:.1+Math.abs(l.x)*.3,height:.1+Math.abs(l.y)*.3,connectedTo:[]})}s.type==="schematic_text"&&i.push({type:"rect",layers:["top"],center:s.position,width:(((o=s.text)==null?void 0:o.length)??0)*.1,height:.2,connectedTo:[]}),s.type==="schematic_box"&&i.push({type:"rect",layers:["top"],center:{x:s.x,y:s.y},width:s.width,height:s.height,connectedTo:[]})}const a=dst(e.toArray());return i.push(...fst(a,{padding:1})),i};function gst({ports:r,nets:e}){var t,n,i;if(r.length>=2)return`${(t=r[0])==null?void 0:t.selector} to ${(n=r[1])==null?void 0:n.selector}`;if(r.length===1&&e.length===1)return`${(i=r[0])==null?void 0:i.selector} to net.${e[0]._parsedProps.name}`}var pst=({edges:r,db:e,source_trace_id:t})=>{e.source_trace.get(t);const n=o8({db:e,source_trace_id:t,differentNetOnly:!0}).flatMap(a=>a.edges),i=a=>{const{from:o,to:s}=a;return o.x===s.x?"vertical":"horizontal"};for(const a of r){const o=i(a),s=()=>n.find(c=>i(c)===o&&MP([a.from,a.to],[c.from,c.to],{lineThickness:.05}));let l=s();for(;l;)o==="horizontal"?(a.from.y+=.1,a.to.y+=.1):(a.from.x+=.1,a.to.x+=.1),l=s()}},mst=(r,{db:e})=>{const t=e.pcb_board.list()[0];if(t.outline){const l=t.outline,c=(A,u)=>{let d=!1;for(let g=0,m=u.length-1;g<u.length;m=g++){const C=u[g].x,E=u[g].y,_=u[m].x,x=u[m].y;E>A.y!=x>A.y&&A.x<(_-C)*(A.y-E)/(x-E)+C&&(d=!d)}return d};return r.some(A=>!c(A,l))}const n=t.width,i=t.height,a=t.center.x,o=t.center.y;return r.some(l=>l.x<a-n/2||l.y<o-i/2||l.x>a+n/2||l.y>o+i/2)},s8=r=>({...r._getGlobalPcbPositionAfterLayout(),layers:r.getAvailablePcbLayers()}),vS=class extends Kv{constructor(t){super(t);Ve(this,"source_trace_id",null);Ve(this,"pcb_trace_id",null);Ve(this,"schematic_trace_id",null);Ve(this,"_portsRoutedOnPcb");Ve(this,"subcircuit_connectivity_map_key",null);Ve(this,"_traceConnectionHash",null);this._portsRoutedOnPcb=[]}get config(){return{zodProps:fge,componentName:"Trace"}}_getTracePortOrNetSelectorListFromProps(){return"from"in this.props&&"to"in this.props?[typeof this.props.from=="string"?this.props.from:this.props.from.getPortSelector(),typeof this.props.to=="string"?this.props.to:this.props.to.getPortSelector()]:"path"in this.props?this.props.path.map(t=>typeof t=="string"?t:t.getPortSelector()):[]}getTracePortPathSelectors(){return this._getTracePortOrNetSelectorListFromProps().filter(t=>!t.includes("net."))}getTracePathNetSelectors(){return this._getTracePortOrNetSelectorListFromProps().filter(t=>t.includes("net."))}_findConnectedPorts(){const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i)throw new Error("Trace has no parent");const o=this.getTracePortPathSelectors().map(s=>({selector:s,port:this.getSubcircuit().selectOne(s,{type:"port"})??null}));for(const{selector:s,port:l}of o)if(!l){const c=s.replace(/(\> )?[^ ]+$/,""),A=this.getSubcircuit().selectOne(c);A?this.renderError(`Could not find port for selector "${s}" (did you forget to include the pin name?)
|
|
854
|
-
searched component ${A.getString()}, which has ports: ${A.children.filter(u=>u.componentName==="Port").map(u=>`${u.getString()}(${u.getNameAndAliases().join(",")})`).join(" & ")}`):this.renderError(`Could not find port for selector "${s}"`)}return o.some(s=>!s.port)?{allPortsFound:!1}:{allPortsFound:!0,portsWithSelectors:o,ports:o.map(({port:s})=>s)}}_findConnectedNets(){const t=this.getTracePathNetSelectors().map(i=>({selector:i,net:this.getSubcircuit().selectOne(i,{type:"net"})})),n=t.filter(i=>!i.net);return n.length>0&&this.renderError(`Could not find net for selector "${n[0].selector}" inside ${this}`),{netsWithSelectors:t,nets:t.map(i=>i.net)}}_getAllTracesConnectedToSameNet(){const t=this.getSubcircuit().selectAll("trace"),n=this._findConnectedNets().nets,i=this._findConnectedPorts().ports??[];return t.filter(a=>{if(a===this)return!1;const o=a._findConnectedNets().nets,s=a._findConnectedPorts().ports??[];return o.some(l=>n.includes(l))||s.some(l=>i.includes(l))})}_isExplicitlyConnectedToPort(t){const{allPortsFound:n,portsWithSelectors:i}=this._findConnectedPorts();return n?i.map(o=>o.port).includes(t):!1}_isExplicitlyConnectedToNet(t){return this._findConnectedNets().nets.includes(t)}doInitialCreateNetsFromProps(){s0e(this,this.getTracePathNetSelectors())}_computeTraceConnectionHash(){const{allPortsFound:t,ports:n}=this._findConnectedPorts();return!t||!n?null:[...n].sort((o,s)=>(o.pcb_port_id||"").localeCompare(s.pcb_port_id||"")).map(o=>o.pcb_port_id).join(",")}doInitialSourceTraceRender(){var d;const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i){this.renderError("Trace has no parent");return}const{allPortsFound:a,portsWithSelectors:o}=this._findConnectedPorts();if(!a)return;this._traceConnectionHash=this._computeTraceConnectionHash();const l=t.source_trace.list().find(g=>g.subcircuit_connectivity_map_key===this.subcircuit_connectivity_map_key&&g.connected_source_port_ids.sort().join(",")===this._traceConnectionHash);if(l){this.source_trace_id=l.source_trace_id;return}const c=this._findConnectedNets().nets,A=gst({ports:o,nets:c}),u=t.source_trace.insert({connected_source_port_ids:o.map(g=>g.port.source_port_id),connected_source_net_ids:c.map(g=>g.source_net_id),subcircuit_id:(d=this.getSubcircuit())==null?void 0:d.subcircuit_id,max_length:ust(o.map(g=>g.port),{db:t})??n.maxLength,display_name:A,min_trace_thickness:n.thickness});this.source_trace_id=u.source_trace_id}_insertErrorIfTraceIsOutsideBoard(t,n){const{db:i}=this.root;mst(t,{db:i})&&i.pcb_trace_error.insert({error_type:"pcb_trace_error",source_trace_id:this.source_trace_id,message:`Trace ${this.getString()} routed outside the board boundaries.`,pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[],pcb_port_ids:n.map(o=>o.pcb_port_id)})}doInitialPcbTraceRender(){var q,J,ce,oe;if((q=this.root)!=null&&q.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n,parent:i}=this,a=this.getSubcircuit();if(!i)throw new Error("Trace has no parent");if(a._parsedProps.routingDisabled)return;const o=(J=a._parsedProps.pcbRouteCache)==null?void 0:J.pcbTraces;if(o){const de=t.pcb_trace.insert({route:o.flatMap(Ie=>Ie.route),source_trace_id:this.source_trace_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((ce=this.getGroup())==null?void 0:ce.pcb_group_id)??void 0});this.pcb_trace_id=de.pcb_trace_id;return}if(!a._shouldUseTraceByTraceRouting())return;const{allPortsFound:s,ports:l}=this._findConnectedPorts();if(!s)return;const c=[];for(const de of l)de._hasMatchedPcbPrimitive()||c.push(de);if(c.length>0){t.pcb_trace_error.insert({error_type:"pcb_trace_error",source_trace_id:this.source_trace_id,message:`Some ports did not have a matching PCB primitive (e.g. a pad or plated hole), this can happen if a footprint is missing. As a result, ${this} wasn't routed. Missing ports: ${c.map(de=>de.getString()).join(", ")}`,pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[],pcb_port_ids:c.map(de=>de.pcb_port_id).filter(Boolean)});return}const A=this._findConnectedNets().netsWithSelectors;if(l.length===0&&A.length===2){this.renderError("Trace connects two nets, we haven't implemented a way to route this yet");return}else if(l.length===1&&A.length===1){const de=l[0],Be=A[0].net.getAllConnectedPorts().filter(_e=>_e!==de);if(Be.length===0){console.log("Nothing to connect this port to, the net is empty. TODO should emit a warning!");return}const pe=ost(de,Be);l.push(pe)}else if(l.length>1&&A.length>=1){this.renderError("Trace has more than one port and one or more nets, we don't currently support this type of complex trace routing");return}const u=l.flatMap(de=>de.matchedComponents.filter(Ie=>Ie.componentName==="TraceHint")),d=(this._parsedProps.pcbRouteHints??[]).concat(u.flatMap(de=>de.getPcbRouteHints()));if(l.length>2){this.renderError(`Trace has more than two ports (${l.map(de=>de.getString()).join(", ")}), routing between more than two ports for a single trace is not implemented`);return}if(this.getSubcircuit().selectAll("trace").filter(de=>de.renderPhaseStates.PcbTraceRender.initialized).some(de=>de._portsRoutedOnPcb.length===l.length&&de._portsRoutedOnPcb.every(Ie=>l.includes(Ie))))return;let C=[];d.length===0?C=[s8(l[0]),s8(l[1])]:C=[s8(l[0]),...d,s8(l[1])];const E=a8(C),_=pS(this.root.db.toArray()),[x,Q]=lst(()=>CP(this.root.db.toArray()));if(Q){this.renderError({type:"pcb_trace_error",error_type:"pcb_trace_error",pcb_trace_error_id:this.pcb_trace_id,message:`Error getting obstacles for autorouting: ${Q.message}`,source_trace_id:this.source_trace_id,center:{x:0,y:0},pcb_port_ids:l.map(de=>de.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[]});return}for(const de of x)if(de.connectedTo.length>0){const Be=_.getNetConnectedToId(de.connectedTo[0]);Be&&de.connectedTo.push(Be)}let P=[];if(E.length===0)P=C;else{const de=E[0].layer_path;P=C.map((Ie,Be)=>Ie.via?{...Ie,via_to_layer:de[Be]}:{...Ie,layers:[de[Be]]})}P[0].pcb_port_id=l[0].pcb_port_id,P[P.length-1].pcb_port_id=l[1].pcb_port_id;const z=[];for(const[de,Ie]of a0e(P)){const Be="via_to_layer"in de?de.via_to_layer:null,pe=2,_e="layers"in de&&de.layers.length===1?de.layers[0]:Be??"top",ve="layers"in Ie&&Ie.layers.length===1?Ie.layers[0]:Be??"top",Ne="pcb_port_id"in de?de.pcb_port_id:null,we="pcb_port_id"in Ie?Ie.pcb_port_id:null,Ue=this.getSubcircuit()._parsedProps.minTraceWidth??.16,Fe=new IP({OBSTACLE_MARGIN:Ue*2,isRemovePathLoopsEnabled:!0,optimizeWithGoalBoxes:!!(Ne&&we),connMap:_,input:{obstacles:x,minTraceWidth:Ue,connections:[{name:this.source_trace_id,pointsToConnect:[{...de,layer:_e,pcb_port_id:Ne},{...Ie,layer:ve,pcb_port_id:we}]}],layerCount:2,bounds:{minX:Math.min(de.x,Ie.x)-pe,maxX:Math.max(de.x,Ie.x)+pe,minY:Math.min(de.y,Ie.y)-pe,maxY:Math.max(de.y,Ie.y)+pe}}});let tt=null;try{tt=Fe.solveAndMapToTraces()}catch(bt){this.renderError({type:"pcb_trace_error",pcb_trace_error_id:this.source_trace_id,error_type:"pcb_trace_error",message:`error solving route: ${bt.message}`,source_trace_id:this.pcb_trace_id,center:{x:(de.x+Ie.x)/2,y:(de.y+Ie.y)/2},pcb_port_ids:l.map(Gt=>Gt.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:l.map(Gt=>Gt.pcb_component_id)})}if(!tt)return;if(tt.length===0){this.renderError({type:"pcb_trace_error",error_type:"pcb_trace_error",pcb_trace_error_id:this.pcb_trace_id,message:`Could not find a route for ${this}`,source_trace_id:this.source_trace_id,center:{x:(de.x+Ie.x)/2,y:(de.y+Ie.y)/2},pcb_port_ids:l.map(bt=>bt.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:l.map(bt=>bt.pcb_component_id)});return}const[rt]=tt;Be&&(rt.route=rt.route.map(bt=>(bt.route_type==="wire"&&!bt.layer&&(bt.layer=Be),bt))),Ne&&rt.route[0].route_type==="wire"&&(rt.route[0].start_pcb_port_id=Ne);const ht=rt.route[rt.route.length-1];we&&ht.route_type==="wire"&&(ht.end_pcb_port_id=we),z.push(rt.route)}const O=ist(z),V=cst(O),j=t.pcb_trace.insert({route:O,source_trace_id:this.source_trace_id,subcircuit_id:(oe=this.getSubcircuit())==null?void 0:oe.subcircuit_id,trace_length:V});this._portsRoutedOnPcb=l,this.pcb_trace_id=j.pcb_trace_id;for(const de of O)de.route_type==="via"&&t.pcb_via.insert({pcb_trace_id:j.pcb_trace_id,x:de.x,y:de.y,hole_diameter:.3,outer_diameter:.6,layers:[de.from_layer,de.to_layer],from_layer:de.from_layer,to_layer:de.to_layer});this._insertErrorIfTraceIsOutsideBoard(O,l)}_doInitialSchematicTraceRenderWithDisplayLabel(){var z,O,V,j;if((z=this.root)!=null&&z.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i)throw new Error("Trace has no parent");const{allPortsFound:a,portsWithSelectors:o}=this._findConnectedPorts();if(!a)return;const s=o.map(({port:q})=>({port:q,position:q._getGlobalSchematicPositionAfterLayout(),schematic_port_id:q.schematic_port_id,facingDirection:q.facingDirection}));if(s.length<2)throw new Error("Expected at least two ports in portsWithPosition.");let l,c;const A=s[0].position,u=s[0].port;if("path"in this.props){if(this.props.path.length!==2)throw new Error("Invalid 'path': Must contain exactly two elements.");[l,c]=this.props.path}else{if(!("from"in this.props&&"to"in this.props))throw new Error("Missing 'from' or 'to' properties in props.");l=this.props.from,c=this.props.to}if(!u.source_port_id)throw new Error(`Missing source_port_id for the 'from' port (${l}).`);const d=s[1].position,g=s[1].port;if(!g.source_port_id)throw new Error(`Missing source_port_id for the 'to' port (${c}).`);const m=t.schematic_net_label.list().find(q=>q.source_net_id===u.source_port_id),C=t.schematic_net_label.list().find(q=>q.source_net_id===g.source_port_id),[E,_]=o.map(({port:q})=>q),Q=((O=E.parent)==null?void 0:O.config.shouldRenderAsSchematicBox)?`${(V=E==null?void 0:E.parent)==null?void 0:V.props.name}_${E==null?void 0:E.props.name}`:`${(j=_==null?void 0:_.parent)==null?void 0:j.props.name}_${_==null?void 0:_.props.name}`,P=this.props.schDisplayLabel??Q;m&&m.text!==P&&(m.text=`${P} / ${m.text}`),C&&(C==null?void 0:C.text)!==P&&(C.text=`${P} / ${C.text}`),C||t.schematic_net_label.insert({text:this.props.schDisplayLabel??Q,source_net_id:g.source_port_id,anchor_position:d,center:d,anchor_side:TY(g.facingDirection)??"bottom"}),m||t.schematic_net_label.insert({text:this.props.schDisplayLabel??Q,source_net_id:u.source_port_id,anchor_position:A,center:A,anchor_side:TY(u.facingDirection)??"bottom"})}_isSymbolToChipConnection(){const{allPortsFound:t,ports:n}=this._findConnectedPorts();if(!t||n.length!==2)return!1;const[i,a]=n;if(!(i!=null&&i.parent)||!(a!=null&&a.parent))return!1;const o=i.parent.config.shouldRenderAsSchematicBox,s=a.parent.config.shouldRenderAsSchematicBox;return o&&!s||!o&&s}_isSymbolToSymbolConnection(){const{allPortsFound:t,ports:n}=this._findConnectedPorts();if(!t||n.length!==2)return!1;const[i,a]=n;if(!(i!=null&&i.parent)||!(a!=null&&a.parent))return!1;const o=!i.parent.config.shouldRenderAsSchematicBox,s=!a.parent.config.shouldRenderAsSchematicBox;return o&&s}_isChipToChipConnection(){const{allPortsFound:t,ports:n}=this._findConnectedPorts();if(!t||n.length!==2)return!1;const[i,a]=n;if(!(i!=null&&i.parent)||!(a!=null&&a.parent))return!1;const o=i.parent.config.shouldRenderAsSchematicBox,s=a.parent.config.shouldRenderAsSchematicBox;return o&&s}doInitialSchematicTraceRender(){var _e,ve,Ne;if((_e=this.root)!=null&&_e.schematicDisabled||((ve=this.getGroup())==null?void 0:ve._getSchematicLayoutMode())==="match-adapt")return;const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i)throw new Error("Trace has no parent");const{allPortsFound:a,portsWithSelectors:o}=this._findConnectedPorts(),{netsWithSelectors:s}=this._findConnectedNets();if(!a)return;const c=o.map(we=>we.port.schematic_port_id).sort().join(","),A=(Ne=this.root)==null?void 0:Ne._getBoard();if(A!=null&&A._connectedSchematicPortPairs&&A._connectedSchematicPortPairs.has(c))return;if(this.props.schDisplayLabel&&("from"in this.props&&"to"in this.props||"path"in this.props)){this._doInitialSchematicTraceRenderWithDisplayLabel();return}const u={name:this.source_trace_id,pointsToConnect:[]},d=hst(this),g=o.map(({port:we})=>({port:we,position:we._getGlobalSchematicPositionAfterLayout(),schematic_port_id:we.schematic_port_id??void 0,facingDirection:we.facingDirection}));if(g.length===1&&s.length===1){const we=s[0].net,{port:Ue,position:Fe}=g[0];t.schematic_net_label.insert({text:we._parsedProps.name,source_net_id:we.source_net_id,anchor_position:Fe,center:Fe,anchor_side:TY(Ue.facingDirection)??"bottom"});return}if(g.length<2)return;u.pointsToConnect=g.map(({position:we})=>({...we,layer:"top"}));const C=rst(d),E=2,_={minTraceWidth:.1,obstacles:d,connections:[u],bounds:{minX:C.minX-E,maxX:C.maxX+E,minY:C.minY-E,maxY:C.maxY+E},layerCount:1};let x=IP,Q=!1;this.getSubcircuit().props._schDirectLineRoutingEnabled&&(x=h0e,Q=!0);let z=new x({input:_,MAX_ITERATIONS:100,OBSTACLE_MARGIN:.1,isRemovePathLoopsEnabled:!0,isShortenPathWithShortcutsEnabled:!0,marginsWithCosts:[{margin:1,enterCost:0,travelCostFactor:1},{margin:.3,enterCost:0,travelCostFactor:1},{margin:.2,enterCost:0,travelCostFactor:2},{margin:.1,enterCost:0,travelCostFactor:3}]}).solveAndMapToTraces();if(z.length===0){if(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection()){this._doInitialSchematicTraceRenderWithDisplayLabel();return}z=new h0e({input:_}).solveAndMapToTraces(),Q=!0}const[{route:O}]=z;let V=[];for(let we=0;we<O.length-1;we++)V.push({from:O[we],to:O[we+1]});const j=this.source_trace_id;let q=[];if(!Q){pst({edges:V,db:t,source_trace_id:j});const we=o8({db:t,source_trace_id:j,differentNetOnly:!0}).flatMap(Ue=>Ue.edges);V=m0e({edges:V,otherEdges:we}),q=y0e({edges:V,db:t,source_trace_id:this.source_trace_id})}const J=V[V.length-1],ce=g[g.length-1],oe=p0e(J);V.push(...PY({lastEdge:J,lastEdgePort:ce,lastDominantDirection:oe}));const de=V[0],Ie=g[0],Be=p0e(de);if(V.unshift(...PY({firstEdge:de,firstEdgePort:Ie,firstDominantDirection:Be})),!this.source_trace_id)throw new Error("Missing source_trace_id for schematic trace insertion.");if(this.getSubcircuit()._parsedProps.schTraceAutoLabelEnabled&&sst(q,V)>=5&&(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection())){this._doInitialSchematicTraceRenderWithDisplayLabel();return}const pe=t.schematic_trace.insert({source_trace_id:this.source_trace_id,edges:V,junctions:q});this.schematic_trace_id=pe.schematic_trace_id,A!=null&&A._connectedSchematicPortPairs&&A._connectedSchematicPortPairs.add(c)}},yst=KI("tscircuit:core"),vst=Vn({x:vB,y:vB,z:vB}),m1=class extends Kv{constructor(t){super(t);Ve(this,"reactSubtrees",[]);Ve(this,"_impliedFootprint");Ve(this,"isPrimitiveContainer",!0);Ve(this,"_asyncSupplierPartNumbers");Ve(this,"pcb_missing_footprint_error_id");Ve(this,"_hasStartedFootprintUrlLoad",!1);this._addChildrenFromStringFootprint(),this.initPorts()}get defaultInternallyConnectedPinNames(){return[]}get internallyConnectedPinNames(){return this._parsedProps.internallyConnectedPins??this.defaultInternallyConnectedPinNames}initPorts(t={}){var s,l,c,A,u,d,g,m,C,E;if((s=this.root)!=null&&s.schematicDisabled)return;const{config:n}=this,i=[],a=this._getSchematicPortArrangement();if(a&&!this._parsedProps.pinLabels){for(const Q in a){const P=a[Q].pins;if(Array.isArray(P))for(const z of P){const O=yD(z,this._parsedProps.pinLabels);i.push(new yS({pinNumber:O,aliases:((l=t.additionalAliases)==null?void 0:l[`pin${O}`])??[]},{originDescription:`schPortArrangement:${Q}`}))}}const _=["left","right","top","bottom"];let x=1;for(const Q of _){const P=a[`${Q}Size`];for(let z=0;z<P;z++)i.push(new yS({pinNumber:x++,aliases:((c=t.additionalAliases)==null?void 0:c[`pin${x}`])??[]},{originDescription:`schPortArrangement:${Q}`}))}}const o=this._parsedProps.pinLabels;if(o)for(let[_,x]of Object.entries(o)){_=_.replace("pin","");let Q=i.find(O=>O._parsedProps.pinNumber===Number(_));const P=Array.isArray(x)?x[0]:x,z=Array.isArray(x)?x.slice(1):[];Q?(Q.externallyAddedAliases.push(P,...z),Q.props.name=P):(Q=new yS({pinNumber:parseInt(_),name:P,aliases:[...z,...((A=t.additionalAliases)==null?void 0:A[`pin${parseInt(_)}`])??[]]},{originDescription:`pinLabels:pin${_}`}),i.push(Q))}if(n.schematicSymbolName){const _=dI[this._getSchematicSymbolNameOrThrow()];if(!_)return;for(const x of _.ports){const Q=d0e(x.labels);if(!Q)continue;const P=i.find(z=>z._parsedProps.pinNumber===Number(Q));if(P)P.schematicSymbolPortDef=x;else{const z=vD(x.labels.concat(((u=t.additionalAliases)==null?void 0:u[`pin${Q}`])??[]));z&&(z.originDescription=`schematicSymbol:labels[0]:${x.labels[0]}`,z.schematicSymbolPortDef=x,i.push(z))}}this.addAll(i)}if(!this._getSchematicPortArrangement()){const _=this.getPortsFromFootprint(t);for(const x of _)i.some(Q=>Q.isMatchingAnyOf(x.getNameAndAliases()))||i.push(x)}for(let _=1;_<=(t.pinCount??this._getPinCount());_++){if(!a||i.find(Q=>Q._parsedProps.pinNumber===_))continue;let x=[...((d=a.leftSide)==null?void 0:d.pins)??[],...((g=a.rightSide)==null?void 0:g.pins)??[],...((m=a.topSide)==null?void 0:m.pins)??[],...((C=a.bottomSide)==null?void 0:C.pins)??[]].map(Q=>yD(Q,this._parsedProps.pinLabels));["leftSize","rightSize","topSize","bottomSize","leftPinCount","rightPinCount","topPinCount","bottomPinCount"].some(Q=>Q in a)&&(x=Array.from({length:this._getPinCount()},(Q,P)=>P+1)),x.includes(_)&&i.push(new yS({pinNumber:_,aliases:((E=t.additionalAliases)==null?void 0:E[`pin${_}`])??[]},{originDescription:`notOtherwiseAddedButDeducedFromPinCount:${_}`}))}i.length>0&&this.addAll(i)}_getImpliedFootprintString(){return null}_isFootprintUrl(t){return t.startsWith("http://")||t.startsWith("https://")}_addChildrenFromStringFootprint(){var o;const{name:t,pcbRotation:n,pinLabels:i}=this.props;let{footprint:a}=this.props;if(a??(a=(o=this._getImpliedFootprintString)==null?void 0:o.call(this)),!!a&&typeof a=="string"){if(this._isFootprintUrl(a))return;const s=DT.string(a).soup(),l=u0e({componentName:t,componentRotation:n,footprint:a,pinLabels:i},s);this.addAll(l)}}get portMap(){return new Proxy({},{get:(t,n)=>{const i=this.children.find(a=>a.componentName==="Port"&&a.isMatchingNameOrAlias(n));if(!i)throw new Error(`There was an issue finding the port "${n.toString()}" inside of a ${this.componentName} component with name: "${this.props.name}". This is a bug in @tscircuit/core`);return i}})}getInstanceForReactElement(t){for(const n of this.reactSubtrees)if(n.element===t)return n.component;return null}doInitialSourceRender(){const t=this.config.sourceFtype;if(!t)return;const{db:n}=this.root,{_parsedProps:i}=this,a=n.source_component.insert({ftype:t,name:i.name,manufacturer_part_number:i.manufacturerPartNumber??i.mfn,supplier_part_numbers:i.supplierPartNumbers});this.source_component_id=a.source_component_id}doInitialSchematicComponentRender(){var a,o,s;if((a=this.root)!=null&&a.schematicDisabled)return;const{db:t}=this.root,{schematicSymbolName:n}=this.config;n?this._doInitialSchematicComponentRenderWithSymbol():this._getSchematicBoxDimensions()&&this._doInitialSchematicComponentRenderWithSchematicBoxDimensions();const i=(o=this.getSubcircuit())==null?void 0:o._getSchematicManualPlacementForComponent(this);if(this.schematic_component_id&&(this.props.schX!==void 0||this.props.schY!==void 0)&&i){if(!this.schematic_component_id)return;const l=CT.parse({type:"schematic_manual_edit_conflict_warning",schematic_manual_edit_conflict_warning_id:`schematic_manual_edit_conflict_${this.source_component_id}`,message:`${this.getString()} has both manual placement and prop coordinates. schX and schY will be used. Remove schX/schY or clear the manual placement.`,schematic_component_id:this.schematic_component_id,source_component_id:this.source_component_id,subcircuit_id:(s=this.getSubcircuit())==null?void 0:s.subcircuit_id});t.schematic_manual_edit_conflict_warning.insert(l)}}_getSchematicSymbolDisplayValue(){}_getInternallyConnectedPins(){if(this.internallyConnectedPinNames.length===0)return[];const t=[];for(const n of this.internallyConnectedPinNames){const i=[];for(const a of n)i.push(this.portMap[a]);t.push(i)}return t}_doInitialSchematicComponentRenderWithSymbol(){var s;if((s=this.root)!=null&&s.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getSchematicSymbolNameOrThrow(),a=dI[i],o=this._getGlobalSchematicPositionBeforeLayout();if(a){const l=t.schematic_component.insert({center:o,size:a.size,source_component_id:this.source_component_id,symbol_name:i,symbol_display_value:this._getSchematicSymbolDisplayValue()});this.schematic_component_id=l.schematic_component_id}}_doInitialSchematicComponentRenderWithSchematicBoxDimensions(){var d;if((d=this.root)!=null&&d.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getSchematicBoxDimensions(),a={};if(Array.isArray(n.pinLabels))n.pinLabels.forEach((g,m)=>{a[String(m+1)]=g});else for(const[g,m]of Object.entries(n.pinLabels??{}))a[g]=Array.isArray(m)?m[0]:m;const o=this._getGlobalSchematicPositionBeforeLayout(),s=this._getSchematicPortArrangement(),l=t.schematic_component.insert({center:o,rotation:n.schRotation??0,size:i.getSize(),port_arrangement:zot(s),pin_spacing:n.schPinSpacing??.2,pin_styles:Oot(n.schPinStyle,n.pinLabels),port_labels:a,source_component_id:this.source_component_id}),c=(s==null?void 0:s.topSide)!==void 0||(s==null?void 0:s.bottomSide)!==void 0,A=i==null?void 0:i.getSize().width,u=i==null?void 0:i.getSize().height;t.schematic_text.insert({text:n.manufacturerPartNumber??"",schematic_component_id:l.schematic_component_id,anchor:"left",rotation:0,position:{x:c?o.x+(A??0)/2+.1:o.x-(A??0)/2,y:c?o.y+(u??0)/2+.35:o.y-(u??0)/2-.13},color:"#006464",font_size:.18}),t.schematic_text.insert({text:n.name??"",schematic_component_id:l.schematic_component_id,anchor:"left",rotation:0,position:{x:c?o.x+(A??0)/2+.1:o.x-(A??0)/2,y:c?o.y+(u??0)/2+.55:o.y+(u??0)/2+.13},color:"#006464",font_size:.18}),this.schematic_component_id=l.schematic_component_id}doInitialPcbComponentRender(){var s;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getSubcircuit(),a=t.pcb_component.insert({center:this._getGlobalPcbPositionBeforeLayout(),width:0,height:0,layer:n.layer??"top",rotation:n.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:i.subcircuit_id??void 0});if(!n.footprint&&!this.isGroup){const l=t.pcb_missing_footprint_error.insert({message:`No footprint found for component: ${this.getString()}`,source_component_id:`${this.source_component_id}`,error_type:"pcb_missing_footprint_error"});this.pcb_missing_footprint_error_id=l.pcb_missing_footprint_error_id}this.pcb_component_id=a.pcb_component_id;const o=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if((this.props.pcbX!==void 0||this.props.pcbY!==void 0)&&o){const l=_T.parse({type:"pcb_manual_edit_conflict_warning",pcb_manual_edit_conflict_warning_id:`pcb_manual_edit_conflict_${this.source_component_id}`,message:`${this.getString()} has both manual placement and prop coordinates. pcbX and pcbY will be used. Remove pcbX/pcbY or clear the manual placement.`,pcb_component_id:this.pcb_component_id,source_component_id:this.source_component_id,subcircuit_id:i.subcircuit_id??void 0});t.pcb_manual_edit_conflict_warning.insert(l)}}doInitialPcbComponentSizeCalculation(){var o;if((o=this.root)!=null&&o.pcbDisabled||!this.pcb_component_id)return;const{db:t}=this.root,{_parsedProps:n}=this,i=NY(this.children);if(i.width===0||i.height===0)return;const a={x:(i.minX+i.maxX)/2,y:(i.minY+i.maxY)/2};t.pcb_component.update(this.pcb_component_id,{center:a,width:i.width,height:i.height})}_renderReactSubtree(t){return{element:t,component:i0e(t)}}doInitialInitializePortsFromChildren(){this.initPorts()}doInitialReactSubtreesRender(){}doInitialPcbFootprintStringRender(){var o;let{footprint:t}=this.props;if(t??(t=(o=this._getImpliedFootprintString)==null?void 0:o.call(this)),!t)return;const{name:n,pcbRotation:i,pinLabels:a}=this.props;if(typeof t=="string"&&this._isFootprintUrl(t)){if(this._hasStartedFootprintUrlLoad)return;this._hasStartedFootprintUrlLoad=!0;const s=t;this._queueAsyncEffect("load-footprint-url",async()=>{const c=await(await fetch(s)).json(),A=u0e({componentName:n,componentRotation:i,footprint:s,pinLabels:a},c);this.addAll(A),this._markDirty("InitializePortsFromChildren")});return}if(yt.isValidElement(t)){if(this.reactSubtrees.some(l=>l.element===t))return;const s=this._renderReactSubtree(t);this.reactSubtrees.push(s),this.add(s.component);return}!yt.isValidElement(t)&&t.componentName==="Footprint"&&this.add(t)}_hasExistingPortExactly(t){return this.children.filter(i=>i.componentName==="Port").some(i=>{const a=t.getNameAndAliases(),o=i.getNameAndAliases();return a.length===o.length&&a.every(s=>o.includes(s))})}add(t){let n;if(yt.isValidElement(t)){const i=this._renderReactSubtree(t);this.reactSubtrees.push(i),n=i.component}else n=t;if(n.componentName==="Port"){if(this._hasExistingPortExactly(n))return;const a=this.children.filter(o=>o.componentName==="Port").find(o=>o.isMatchingAnyOf(n.getNameAndAliases()));a&&yst(`Similar ports added. Port 1: ${a}, Port 2: ${n}`)}super.add(n)}getPortsFromFootprint(t){let{footprint:n}=this.props;if((!n||yt.isValidElement(n))&&(n=this.children.find(a=>a.componentName==="Footprint")),typeof n=="string"){if(this._isFootprintUrl(n))return[];const a=DT.string(n).soup(),o=[];for(const s of a)if("port_hints"in s&&s.port_hints){const l=vD(s.port_hints,t);if(!l)continue;l.originDescription=`footprint:string:${n}:port_hints[0]:${s.port_hints[0]}`,o.push(l)}return o}if(!yt.isValidElement(n)&&n&&n.componentName==="Footprint"){const a=n;let o=1;const s=[];for(const l of a.children){if(!l.props.portHints)continue;let c=l.props.portHints;c.some(d=>d.startsWith("pin"))||(c=[...c,`pin${o}`]),o++;const u=vD(c);u&&(u.originDescription=`footprint:${n}`,s.push(u))}return s}const i=[];if(!n){for(const a of this.children)if(a.props.portHints&&a.isPcbPrimitive){const o=vD(a.props.portHints);o&&i.push(o)}}return i}getPortsFromSchematicSymbol(){var a;if((a=this.root)!=null&&a.schematicDisabled)return[];const{config:t}=this;if(!t.schematicSymbolName)return[];const n=dI[t.schematicSymbolName];if(!n)return[];const i=[];for(const o of n.ports){const s=vD(o.labels);s&&(s.schematicSymbolPortDef=o,i.push(s))}return i}doInitialCreateNetsFromProps(){this._createNetsFromProps(this._getNetsFromConnectionsProp())}_getNetsFromConnectionsProp(){const{_parsedProps:t}=this,n=[];if(t.connections)for(const[i,a]of Object.entries(t.connections)){const o=Array.isArray(a)?a:[a];for(const s of o)n.push(s)}return n}_createNetsFromProps(t){s0e(this,t)}_getPcbCircuitJsonBounds(){const{db:t}=this.root;if(!this.pcb_component_id)return super._getPcbCircuitJsonBounds();const n=t.pcb_component.get(this.pcb_component_id);return{center:{x:n.center.x,y:n.center.y},bounds:{left:n.center.x-n.width/2,top:n.center.y-n.height/2,right:n.center.x+n.width/2,bottom:n.center.y+n.height/2},width:n.width,height:n.height}}_getPinCountFromSchematicPortArrangement(){const t=this._getSchematicPortArrangement();if(!t)return 0;if(!f0e(t))return(t.leftSize??t.leftPinCount??0)+(t.rightSize??t.rightPinCount??0)+(t.topSize??t.topPinCount??0)+(t.bottomSize??t.bottomPinCount??0);const{leftSide:i,rightSide:a,topSide:o,bottomSide:s}=t;return Math.max(...(i==null?void 0:i.pins)??[],...(a==null?void 0:a.pins)??[],...(o==null?void 0:o.pins)??[],...(s==null?void 0:s.pins)??[])}_getPinCount(){return this._getSchematicPortArrangement()?this._getPinCountFromSchematicPortArrangement():this.getPortsFromFootprint().length}_getSchematicPortArrangement(){return this._parsedProps.schPinArrangement??this._parsedProps.schPortArrangement}_getSchematicBoxDimensions(){if(this.getSchematicSymbol()||!this.config.shouldRenderAsSchematicBox)return null;const{_parsedProps:t}=this,n=this._getPinCount(),i=t.schPinSpacing??.2;return $ot({schWidth:t.schWidth,schHeight:t.schHeight,schPinSpacing:i,numericSchPinStyle:nst(t.schPinStyle,t.pinLabels),pinCount:n,schPortArrangement:this._getSchematicPortArrangement(),pinLabels:t.pinLabels})}doInitialCadModelRender(){var A;const{db:t}=this.root,{boardThickness:n=0}=((A=this.root)==null?void 0:A._getBoard())??{},i=this._parsedProps.cadModel;if(!this.pcb_component_id||!i&&!this.props.footprint||i===null)return;const a=this._getPcbCircuitJsonBounds(),o=t.pcb_component.get(this.pcb_component_id);if(typeof i=="string")throw new Error("String cadModel not yet implemented");const s=vst.parse({x:0,y:0,z:typeof(i==null?void 0:i.rotationOffset)=="number"?i.rotationOffset:0,...typeof(i==null?void 0:i.rotationOffset)=="object"?i.rotationOffset??{}:{}}),l=AQ.parse({x:0,y:0,z:0,...typeof(i==null?void 0:i.positionOffset)=="object"?i.positionOffset:{}}),c=this.props.layer==="bottom"?"bottom":"top";t.cad_component.insert({position:{x:a.center.x+l.x,y:a.center.y+l.y,z:(c==="bottom"?-n/2:n/2)+l.z},rotation:{x:s.x,y:(c==="top"?0:180)+s.y,z:c==="bottom"?-(((o==null?void 0:o.rotation)??0)+s.z)+180:((o==null?void 0:o.rotation)??0)+s.z},pcb_component_id:this.pcb_component_id,source_component_id:this.source_component_id,model_stl_url:"stlUrl"in(i??{})?this._addCachebustToModelUrl(i.stlUrl):void 0,model_obj_url:"objUrl"in(i??{})?this._addCachebustToModelUrl(i.objUrl):void 0,model_jscad:"jscad"in(i??{})?i.jscad:void 0,footprinter_string:typeof this.props.footprint=="string"&&!i?this.props.footprint:void 0})}_addCachebustToModelUrl(t){var i;if(!t||!t.includes("modelcdn.tscircuit.com"))return t;const n=((i=this.root)==null?void 0:i.getClientOrigin())??"";return`${t}${t.includes("?")?"&":"?"}cachebust_origin=${encodeURIComponent(n)}`}_getPartsEngineCacheKey(t,n){return JSON.stringify({ftype:t.ftype,name:t.name,manufacturer_part_number:t.manufacturer_part_number,footprinterString:n})}async _getSupplierPartNumbers(t,n,i){var c,A;if(this.props.doNotPlace)return{};const a=(A=(c=this.root)==null?void 0:c.platform)==null?void 0:A.localCacheEngine,o=this._getPartsEngineCacheKey(n,i);if(a){const u=await a.getItem(o);if(u)try{return JSON.parse(u)}catch{}}const s=await Promise.resolve(t.findPart({sourceComponent:n,footprinterString:i})),l=s==="Not found"?{}:s;if(a)try{await a.setItem(o,JSON.stringify(l))}catch{}return l}doInitialPartsEngineRender(){if(this.props.doNotPlace)return;const t=this.getInheritedProperty("partsEngine");if(!t)return;const{db:n}=this.root,i=n.source_component.get(this.source_component_id);if(!i||i.supplier_part_numbers)return;let a;this.props.footprint&&typeof this.props.footprint=="string"&&(a=this.props.footprint);const o=this._getSupplierPartNumbers(t,i,a);if(!(o instanceof Promise)){n.source_component.update(this.source_component_id,{supplier_part_numbers:o});return}this._queueAsyncEffect("get-supplier-part-numbers",async()=>{this._asyncSupplierPartNumbers=await o,this._markDirty("PartsEngineRender")})}updatePartsEngineRender(){if(this.props.doNotPlace)return;const{db:t}=this.root,n=t.source_component.get(this.source_component_id);if(n&&!n.supplier_part_numbers&&this._asyncSupplierPartNumbers){t.source_component.update(this.source_component_id,{supplier_part_numbers:this._asyncSupplierPartNumbers});return}}doInitialCreateTracesFromProps(){this._createTracesFromConnectionsProp()}_createTracesFromConnectionsProp(){const{_parsedProps:t}=this;if(t.connections)for(const[n,i]of Object.entries(t.connections)){const a=Array.isArray(i)?i:[i];for(const o of a)this.add(new vS({from:`${this.getSubcircuitSelector()} > port.${n}`,to:o}))}}},Ist=class{constructor(e,t={}){Ve(this,"input");Ve(this,"isRouting",!1);Ve(this,"solver");Ve(this,"eventHandlers",{complete:[],error:[],progress:[]});Ve(this,"cycleCount",0);Ve(this,"stepDelay");Ve(this,"timeoutId");this.input=e;const{capacityDepth:n,targetMinCapacity:i,stepDelay:a=0}=t;this.solver=new Ppe(e,{capacityDepth:n,targetMinCapacity:i,cacheProvider:null}),this.stepDelay=a}start(){this.isRouting||(this.isRouting=!0,this.cycleCount=0,this.runCycleAndQueueNextCycle())}runCycleAndQueueNextCycle(){var e;if(this.isRouting)try{if(this.solver.solved||this.solver.failed){this.solver.failed?this.emitEvent({type:"error",error:new Error(this.solver.error||"Routing failed")}):this.emitEvent({type:"complete",traces:this.solver.getOutputSimpleRouteJson().traces||[]}),this.isRouting=!1;return}const t=Date.now(),n=this.solver.iterations;for(;Date.now()-t<250&&!this.solver.failed&&!this.solver.solved;)this.solver.step();const i=(this.solver.iterations-n)/(Date.now()-t)*1e3;this.cycleCount++;const a=((e=this.solver)==null?void 0:e.preview())||void 0,o=this.solver.progress;this.emitEvent({type:"progress",steps:this.cycleCount,iterationsPerSecond:i,progress:o,phase:this.solver.getCurrentPhase(),debugGraphics:a}),this.stepDelay>0?this.timeoutId=setTimeout(()=>this.runCycleAndQueueNextCycle(),this.stepDelay):this.timeoutId=setTimeout(()=>this.runCycleAndQueueNextCycle(),0)}catch(t){this.emitEvent({type:"error",error:t instanceof Error?t:new Error(String(t))}),this.isRouting=!1}}stop(){this.isRouting&&(this.isRouting=!1,this.timeoutId!==void 0&&(clearTimeout(this.timeoutId),this.timeoutId=void 0))}on(e,t){e==="complete"?this.eventHandlers.complete.push(t):e==="error"?this.eventHandlers.error.push(t):e==="progress"&&this.eventHandlers.progress.push(t)}emitEvent(e){if(e.type==="complete")for(const t of this.eventHandlers.complete)t(e);else if(e.type==="error")for(const t of this.eventHandlers.error)t(e);else if(e.type==="progress")for(const t of this.eventHandlers.progress)t(e)}solveSync(){if(this.solver.solve(),this.solver.failed)throw new Error(this.solver.error||"Routing failed");return this.solver.getOutputSimpleRouteJson().traces||[]}},v0e=class extends Kv{constructor(){super(...arguments);Ve(this,"matchedPort",null)}get config(){return{componentName:"TraceHint",zodProps:kge}}doInitialPortMatching(){const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i)return;if(i.componentName==="Trace"){this.renderError(`Port inference inside trace is not yet supported (${this})`);return}if(!i)throw new Error("TraceHint has no parent");if(!n.for){this.renderError(`TraceHint has no for property (${this})`);return}const a=i.selectOne(n.for,{type:"port"});a||this.renderError(`${this} could not find port for selector "${n.for}"`),this.matchedPort=a,a.registerMatch(this)}getPcbRouteHints(){const{_parsedProps:t}=this,n=t.offset?[t.offset]:t.offsets;if(!n)return[];const i=this._computePcbGlobalTransformBeforeLayout();return n.map(a=>({...si(i,a),via:a.via,to_layer:a.to_layer,trace_width:a.trace_width}))}doInitialPcbTraceHintRender(){var i,a,o;if((i=this.root)!=null&&i.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this;t.pcb_trace_hint.insert({pcb_component_id:(a=this.matchedPort)==null?void 0:a.pcb_component_id,pcb_port_id:(o=this.matchedPort)==null?void 0:o.pcb_port_id,route:this.getPcbRouteHints()})}},Cst=(r,e)=>{const t=r.source_group.list(),n=[],i=a=>{const o=t.filter(s=>s.parent_subcircuit_id===a);for(const s of o)s.subcircuit_id&&(n.push(s.subcircuit_id),i(s.subcircuit_id))};return i(e),n},I0e=({db:r,circuitJson:e,subcircuit_id:t,minTraceWidth:n=.1})=>{if(!r&&e&&(r=$E(e)),!r)throw new Error("db or circuitJson is required");const i=r.pcb_trace_hint.list(),a=t?new Set([t]):null;if(t){const C=Cst(r,t);for(const E of C)a.add(E)}const o=(e??r.toArray()).filter(C=>!t||"subcircuit_id"in C&&a.has(C.subcircuit_id)),s=r.pcb_board.list()[0];r=$E(o);const l=pS(o),c=CP([...r.pcb_component.list(),...r.pcb_smtpad.list(),...r.pcb_plated_hole.list(),...r.pcb_hole.list(),...r.pcb_via.list()].filter(C=>!t||(a==null?void 0:a.has(C.subcircuit_id))),l);for(const C of c){const E=C.connectedTo.flatMap(_=>l.getIdsConnectedToNet(_));C.connectedTo.push(...E)}const A=c.flatMap(C=>[{x:C.center.x-C.width/2,y:C.center.y-C.height/2},{x:C.center.x+C.width/2,y:C.center.y+C.height/2}]);let u;s?u={minX:s.center.x-s.width/2,maxX:s.center.x+s.width/2,minY:s.center.y-s.height/2,maxY:s.center.y+s.height/2}:u={minX:Math.min(...A.map(C=>C.x))-1,maxX:Math.max(...A.map(C=>C.x))+1,minY:Math.min(...A.map(C=>C.y))-1,maxY:Math.max(...A.map(C=>C.y))+1};const d=r.source_trace.list().map(C=>{var V,j,q;const E=C.connected_source_port_ids.map(J=>{const ce=r.source_port.get(J),oe=r.pcb_port.getWhere({source_port_id:J});return{...ce,...oe}});if(E.length<2)return null;const[_,x]=E,Q=((V=_.layers)==null?void 0:V[0])??"top",P=((j=x.layers)==null?void 0:j[0])??"top",z=i.filter(J=>J.pcb_port_id===_.pcb_port_id||J.pcb_port_id===x.pcb_port_id),O=[];for(const J of z){const ce=r.pcb_port.get(J.pcb_port_id),oe=((q=ce==null?void 0:ce.layers)==null?void 0:q[0])??"top";for(const de of J.route)O.push({x:de.x,y:de.y,layer:oe})}return{name:C.source_trace_id??l.getNetConnectedToId(C.source_trace_id)??"",source_trace_id:C.source_trace_id,pointsToConnect:[{x:_.x,y:_.y,layer:Q},...O,{x:x.x,y:x.y,layer:P}]}}).filter(C=>C!==null),g=r.source_net.list().filter(C=>!t||(a==null?void 0:a.has(C.subcircuit_id))),m=[];for(const C of g){const E=r.source_trace.list().filter(_=>{var x;return(x=_.connected_source_net_ids)==null?void 0:x.includes(C.source_net_id)});m.push({name:C.source_net_id??l.getNetConnectedToId(C.source_net_id),pointsToConnect:E.flatMap(_=>r.pcb_port.list().filter(Q=>_.connected_source_port_ids.includes(Q.source_port_id)).map(Q=>{var P;return{x:Q.x,y:Q.y,layer:((P=Q.layers)==null?void 0:P[0])??"top",pcb_port_id:Q.pcb_port_id}}))})}return{simpleRouteJson:{bounds:u,obstacles:c,connections:[...d,...m],layerCount:2,minTraceWidth:n},connMap:l}};function UY(r,e){if("boxId"in r){const{boxId:t,pinNumber:n}=r,i=e.source_component.getWhere({name:t});if(!i)throw new Error(`Source component "${t}" not found, but returned from match-adapt ${JSON.stringify(r)}`);const a=e.source_port.getWhere({source_component_id:i.source_component_id,pin_number:n});return{subcircuit_connectivity_map_key:(a==null?void 0:a.subcircuit_connectivity_map_key)??null,source_port_id:a.source_port_id}}if("netId"in r){const{netId:t}=r;return e.source_net.getWhere({name:t}),null}if("junctionId"in r){const{junctionId:t}=r;return null}return null}function Est({path:r,db:e,layoutConnMap:t}){let n=UY(r.to,e)??UY(r.from,e);if(!n){const a=t.getNetConnectedToId(Bb(r.to));n=t.getIdsConnectedToNet(a).map(s=>vY(s)).map(s=>UY(s,e)).find(Boolean)}if(!(n!=null&&n.subcircuit_connectivity_map_key))throw new Error(`No connectivity net id found for match-adapt path ${JSON.stringify(r)}`);const i=e.source_trace.list({subcircuit_connectivity_map_key:n.subcircuit_connectivity_map_key});for(const a of i)if(a.connected_source_port_ids.includes(n.source_port_id))return a.source_trace_id;if(i.length>0)return i[0].source_trace_id;throw new Error(`No source trace found for match-adapt path "${JSON.stringify(r)}"`)}function _st(r){const{db:e}=r.root;let t=structuredClone(e.toArray());t=Dot(t);const n=Mot(t),i=new Qot({inputNetlist:n});let a=null;try{i.solve(),a=i.getLayout()}catch(u){e.schematic_layout_error.insert({message:`Match-adapt layout failed: ${u.toString()}`,source_group_id:r.source_group_id,schematic_group_id:r.schematic_group_id});return}const{boxes:o,junctions:s,netLabels:l,paths:c}=a,A=new y9({});for(const u of c)A.addConnections([[Bb(u.from),Bb(u.to)]]);for(const u of s)for(const d of c)for(const g of d.points)Math.abs(g.x-u.x)<.001&&Math.abs(g.y-u.y)<.001&&A.addConnections([[Bb(d.from),Bb(u)],[Bb(d.to),Bb(u)]]);for(const u of o){const d=e.source_component.list().find(_=>_.name===u.boxId);if(!d)continue;const g=e.schematic_component.getWhere({source_component_id:d.source_component_id});if(!g)continue;const m={x:u.centerX-g.center.x+.1,y:u.centerY-g.center.y-.1};e.schematic_component.update(g.schematic_component_id,{center:{x:g.center.x+m.x,y:g.center.y+m.y}});const C=e.schematic_port.list({schematic_component_id:g.schematic_component_id});for(const _ of C)e.schematic_port.update(_.schematic_port_id,{center:{x:_.center.x+m.x,y:_.center.y+m.y}});const E=e.schematic_text.list({schematic_component_id:g.schematic_component_id});for(const _ of E)e.schematic_text.update(_.schematic_text_id,{position:{x:_.position.x+m.x,y:_.position.y+m.y}})}for(const u of l){const d=e.source_net.list().find(g=>g.name===u.netId);e.schematic_net_label.insert({text:u.netId,source_net_id:d==null?void 0:d.source_net_id,anchor_position:{x:u.x,y:u.y},center:{x:u.x,y:u.y},anchor_side:u.anchorPosition})}for(const u of c){if(!u.points||u.points.length<2)continue;const d=Est({path:u,db:yx(t),layoutConnMap:A});let g=[];for(let E=0;E<u.points.length-1;E++)g.push({from:{x:u.points[E].x,y:u.points[E].y},to:{x:u.points[E+1].x,y:u.points[E+1].y}});const m=o8({db:e,source_trace_id:d,differentNetOnly:!0}).flatMap(E=>E.edges);m.length>0&&(g=m0e({edges:g,otherEdges:m}));const C=y0e({edges:g,db:e,source_trace_id:d});e.schematic_trace.insert({source_trace_id:d,edges:g,junctions:C})}}function Bst(r){if(!r.isSubcircuit)return;const{db:e}=r.root,t=r.selectAll("trace"),n=new y9({});n.addConnections(t.map(s=>{const l=e.source_trace.get(s.source_trace_id);return l?[l.source_trace_id,...l.connected_source_port_ids,...l.connected_source_net_ids]:null}).filter(s=>s!==null));const{name:i}=r._parsedProps;for(const s of t){if(!s.source_trace_id)continue;const l=n.getNetConnectedToId(s.source_trace_id);l&&(s.subcircuit_connectivity_map_key=`${i??`unnamedsubcircuit${r._renderId}`}_${l}`,e.source_trace.update(s.source_trace_id,{subcircuit_connectivity_map_key:s.subcircuit_connectivity_map_key}))}const a=new Set;for(const s of t){if(!s.source_trace_id)continue;const l=e.source_trace.get(s.source_trace_id);if(l)for(const c of l.connected_source_port_ids)a.add(c)}for(const s of a){const l=n.getNetConnectedToId(s);if(!l)continue;const c=`${i??`unnamedsubcircuit${r._renderId}`}_${l}`;e.source_port.update(s,{subcircuit_connectivity_map_key:c})}const o=new Set;for(const s of t){if(!s.source_trace_id)continue;const l=e.source_trace.get(s.source_trace_id);if(l)for(const c of l.connected_source_net_ids)o.add(c)}for(const s of o){const l=n.getNetConnectedToId(s);if(!l)continue;const c=`${i??`unnamedsubcircuit${r._renderId}`}_${l}`;e.source_net.update(s,{subcircuit_connectivity_map_key:c})}}function xst(r){var x;const{db:e}=r.root,t=r._parsedProps,n=r.children.filter(Q=>Q.schematic_component_id);if(n.length===0)return;let i=0,a=0;for(const Q of n){const P=e.schematic_component.get(Q.schematic_component_id);P!=null&&P.size&&(i=Math.max(i,P.size.width),a=Math.max(a,P.size.height))}i===0&&n.length>0&&(i=1),a===0&&n.length>0&&(a=1);let o=t.gridCols,s,l=t.gridGap;(x=t.schLayout)!=null&&x.grid&&(o=t.schLayout.grid.cols??o,s=t.schLayout.grid.rows,l=t.schLayout.grid.gap??l);let c,A;o!==void 0&&s!==void 0?(c=o,A=s):o!==void 0?(c=o,A=Math.ceil(n.length/c)):s!==void 0?(A=s,c=Math.ceil(n.length/A)):(c=Math.ceil(Math.sqrt(n.length)),A=Math.ceil(n.length/c)),c===0&&n.length>0&&(c=1),A===0&&n.length>0&&(A=n.length);let u,d;typeof l=="number"?(u=l,d=l):typeof l=="object"&&l!==null?(u=l.x,d=l.y):(u=1,d=1);const g=c*i+Math.max(0,c-1)*u,m=A*a+Math.max(0,A-1)*d,C=r._getGlobalSchematicPositionBeforeLayout(),E=C.x-g/2+i/2,_=C.y+m/2-a/2;for(let Q=0;Q<n.length;Q++){const P=n[Q];if(!P.schematic_component_id)continue;const z=Math.floor(Q/c),O=Q%c;if(z>=A||O>=c){console.warn(`Schematic grid layout: Child ${P.getString()} at index ${Q} (row ${z}, col ${O}) exceeds specified grid dimensions (${A}x${c}). Skipping placement.`);continue}const V=E+O*(i+u),j=_-z*(a+d),q=e.schematic_component.get(P.schematic_component_id);if(q){const J=q.center,ce={x:V,y:j};e.schematic_component.update(P.schematic_component_id,{center:ce});const oe=ce.x-J.x,de=ce.y-J.y,Ie=e.schematic_port.list({schematic_component_id:P.schematic_component_id});for(const pe of Ie)e.schematic_port.update(pe.schematic_port_id,{center:{x:pe.center.x+oe,y:pe.center.y+de}});const Be=e.schematic_text.list({schematic_component_id:P.schematic_component_id});for(const pe of Be)e.schematic_text.update(pe.schematic_text_id,{position:{x:pe.position.x+oe,y:pe.position.y+de}})}}r.schematic_group_id&&e.schematic_group.update(r.schematic_group_id,{width:g,height:m,center:C})}function bst(r){var x;const{db:e}=r.root,t=r._parsedProps,n=r.children.filter(Q=>Q.pcb_component_id);if(n.length===0)return;let i=0,a=0;for(const Q of n){const P=e.pcb_component.get(Q.pcb_component_id);P&&(i=Math.max(i,P.width),a=Math.max(a,P.height))}i===0&&n.length>0&&(i=1),a===0&&n.length>0&&(a=1);let o=t.gridCols,s,l=t.gridGap;(x=t.pcbLayout)!=null&&x.grid&&(o=t.pcbLayout.grid.cols??o,s=t.pcbLayout.grid.rows,l=t.pcbLayout.grid.gap??l);let c,A;o!==void 0&&s!==void 0?(c=o,A=s):o!==void 0?(c=o,A=Math.ceil(n.length/c)):s!==void 0?(A=s,c=Math.ceil(n.length/A)):(c=Math.ceil(Math.sqrt(n.length)),A=Math.ceil(n.length/c)),c===0&&n.length>0&&(c=1),A===0&&n.length>0&&(A=n.length);let u,d;typeof l=="number"?(u=l,d=l):typeof l=="object"&&l!==null?(u=l.x,d=l.y):(u=1,d=1);const g=c*i+Math.max(0,c-1)*u,m=A*a+Math.max(0,A-1)*d,C=r._getGlobalPcbPositionBeforeLayout(),E=C.x-g/2+i/2,_=C.y+m/2-a/2;for(let Q=0;Q<n.length;Q++){const P=n[Q];if(!P.pcb_component_id)continue;const z=Math.floor(Q/c),O=Q%c;if(z>=A||O>=c){console.warn(`PCB grid layout: Child ${P.getString()} at index ${Q} (row ${z}, col ${O}) exceeds grid dimensions (${A}x${c}). Skipping placement.`);continue}const V=E+O*(i+u),j=_-z*(a+d),q=e.pcb_component.get(P.pcb_component_id);if(q){const J=q.center,ce={x:V,y:j},oe=ce.x-J.x,de=ce.y-J.y,Ie=Kd(oe,de),Be=e.toArray().filter(_e=>_e.pcb_component_id===P.pcb_component_id),pe=Aat(Be,Ie);for(const _e of pe){const ve=e8(_e);e[_e.type].update(_e[ve],_e)}e.pcb_component.update(P.pcb_component_id,{center:ce}),P.setProps({...P.props,pcbX:(P.props.pcbX??0)+oe,pcbY:(P.props.pcbY??0)+de})}}r.pcb_group_id&&e.pcb_group.update(r.pcb_group_id,{width:g,height:m,center:C})}var FY=class extends m1{constructor(){super(...arguments);Ve(this,"pcb_group_id",null);Ve(this,"schematic_group_id",null);Ve(this,"subcircuit_id",null);Ve(this,"_hasStartedAsyncAutorouting",!1);Ve(this,"_asyncAutoroutingResult",null)}get config(){return{zodProps:$he,componentName:"Group"}}doInitialSourceRender(){const{db:t}=this.root,n=t.source_group.insert({name:this._parsedProps.name,is_subcircuit:this.isSubcircuit});this.subcircuit_id=`subcircuit_${n.source_group_id}`,this.source_group_id=n.source_group_id,t.source_group.update(n.source_group_id,{subcircuit_id:this.subcircuit_id});for(const i of this.children)t.source_component.update(i.source_component_id,{source_group_id:this.source_group_id})}doInitialSourceParentAttachment(){var i,a,o;const{db:t}=this.root;if(!this.isSubcircuit)return;const n=(o=(a=(i=this.parent)==null?void 0:i.getSubcircuit)==null?void 0:a.call(i))==null?void 0:o.subcircuit_id;n&&t.source_group.update(this.source_group_id,{parent_subcircuit_id:n})}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=t.pcb_group.insert({is_subcircuit:this.isSubcircuit,subcircuit_id:this.subcircuit_id,name:this._parsedProps.name,center:this._getGlobalPcbPositionBeforeLayout(),width:0,height:0,pcb_component_ids:[],source_group_id:this.source_group_id});this.pcb_group_id=i.pcb_group_id;for(const o of this.children)t.pcb_component.update(o.pcb_component_id,{pcb_group_id:i.pcb_group_id})}doInitialPcbPrimitiveRender(){var i;if((i=this.root)!=null&&i.pcbDisabled)return;const{db:t}=this.root,n=NY(this.children);this.pcb_group_id&&t.pcb_group.update(this.pcb_group_id,{width:n.width,height:n.height,center:{x:(n.minX+n.maxX)/2,y:(n.minY+n.maxY)/2}})}doInitialCreateTraceHintsFromProps(){var o;const{_parsedProps:t}=this,{db:n}=this.root,i=t;if(!this.isSubcircuit)return;const a=(o=i.layout)==null?void 0:o.manual_trace_hints;if(a)for(const s of a)this.add(new v0e({for:s.pcb_port_selector,offsets:s.offsets}))}doInitialSourceAddConnectivityMapKey(){Bst(this)}_areChildSubcircuitsRouted(){const t=this.selectAll("group").filter(n=>n.isSubcircuit);for(const n of t)if(n._shouldRouteAsync()&&!n._asyncAutoroutingResult)return!1;return!0}_shouldRouteAsync(){const t=this._getAutorouterConfig();return t.groupMode==="sequential-trace"?!1:!!(t.local&&t.groupMode==="subcircuit"||!t.local)}_hasTracesToRoute(){const t=KI("tscircuit:core:_hasTracesToRoute"),n=this.selectAll("trace");return t(`[${this.getString()}] has ${n.length} traces to route`),n.length>0}async _runEffectMakeHttpAutoroutingRequest(){var A,u,d,g;const{db:t}=this.root,n=KI("tscircuit:core:_runEffectMakeHttpAutoroutingRequest");this._parsedProps;const i=this._getAutorouterConfig(),a=i.serverUrl,o=i.serverMode,s=(m,C)=>{var E;return n("fetching",m),C.headers&&(C.headers["Tscircuit-Core-Version"]=(E=this.root)==null?void 0:E.getCoreVersion()),fetch(m,C)},l=this.root.db.toArray().filter(m=>m.type.startsWith("source_")||m.type.startsWith("pcb_"));if(o==="solve-endpoint"){if(((A=this.props.autorouter)==null?void 0:A.inputFormat)==="simplified"){const{autorouting_result:C}=await s(`${a}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_simple_route_json:I0e({db:t,minTraceWidth:((u=this.props.autorouter)==null?void 0:u.minTraceWidth)??.15,subcircuit_id:this.subcircuit_id}).simpleRouteJson,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(E=>E.json());this._asyncAutoroutingResult=C,this._markDirty("PcbTraceRender");return}const{autorouting_result:m}=await s(`${a}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_circuit_json:l,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(C=>C.json());this._asyncAutoroutingResult=m,this._markDirty("PcbTraceRender");return}const{autorouting_job:c}=await s(`${a}/autorouting/jobs/create`,{method:"POST",body:JSON.stringify({input_circuit_json:l,provider:"freerouting",autostart:!0,display_name:(d=this.root)==null?void 0:d.name,subcircuit_id:this.subcircuit_id,server_cache_enabled:i.serverCacheEnabled}),headers:{"Content-Type":"application/json"}}).then(m=>m.json());for(;;){const{autorouting_job:m}=await s(`${a}/autorouting/jobs/get`,{method:"POST",body:JSON.stringify({autorouting_job_id:c.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(C=>C.json());if(m.is_finished){const{autorouting_job_output:C}=await s(`${a}/autorouting/jobs/get_output`,{method:"POST",body:JSON.stringify({autorouting_job_id:c.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(E=>E.json());this._asyncAutoroutingResult={output_pcb_traces:C.output_pcb_traces},this._markDirty("PcbTraceRender");break}if(m.has_error)throw t.pcb_autorouting_error.insert({pcb_error_id:c.autorouting_job_id,message:((g=m.error)==null?void 0:g.message)??JSON.stringify(m.error)}),new Error(`Autorouting job failed: ${JSON.stringify(m.error)}`);await new Promise(C=>setTimeout(C,100))}}async _runLocalAutorouting(){var l,c,A,u,d;const{db:t}=this.root;this._parsedProps;const n=KI("tscircuit:core:_runLocalAutorouting");n(`[${this.getString()}] starting local autorouting`);const i=this._getAutorouterConfig(),{simpleRouteJson:a}=I0e({db:t,minTraceWidth:((l=this.props.autorouter)==null?void 0:l.minTraceWidth)??.15,subcircuit_id:this.subcircuit_id});(c=this.root)==null||c.emit("autorouting:start",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),simpleRouteJson:a});let o;i.algorithmFn?o=await i.algorithmFn(a):o=new Ist(a,{capacityDepth:(A=this.props.autorouter)==null?void 0:A.capacityDepth,targetMinCapacity:(u=this.props.autorouter)==null?void 0:u.targetMinCapacity});const s=new Promise((g,m)=>{o.on("complete",C=>{n(`[${this.getString()}] local autorouting complete`),g(C.traces)}),o.on("error",C=>{n(`[${this.getString()}] local autorouting error: ${C.error.message}`),m(C.error)})});o.on("progress",g=>{var m;(m=this.root)==null||m.emit("autorouting:progress",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),...g})}),o.start();try{const g=await s;this._asyncAutoroutingResult={output_pcb_traces:g},this._markDirty("PcbTraceRender")}catch(g){const{db:m}=this.root;throw m.pcb_autorouting_error.insert({pcb_error_id:`pcb_autorouter_error_subcircuit_${this.subcircuit_id}`,message:g instanceof Error?g.message:String(g)}),(d=this.root)==null||d.emit("autorouting:error",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),error:{message:g instanceof Error?g.message:String(g)},simpleRouteJson:a}),g}finally{o.stop()}}_startAsyncAutorouting(){this._hasStartedAsyncAutorouting||(this._hasStartedAsyncAutorouting=!0,this._getAutorouterConfig().local?this._queueAsyncEffect("capacity-mesh-autorouting",async()=>this._runLocalAutorouting()):this._queueAsyncEffect("make-http-autorouting-request",async()=>this._runEffectMakeHttpAutoroutingRequest()))}doInitialPcbTraceRender(){var n;const t=KI("tscircuit:core:doInitialPcbTraceRender");if(this.isSubcircuit&&!((n=this.root)!=null&&n.pcbDisabled)&&!this.getInheritedProperty("routingDisabled")&&!this._shouldUseTraceByTraceRouting()){if(!this._areChildSubcircuitsRouted()){t(`[${this.getString()}] child subcircuits are not routed, skipping async autorouting until subcircuits routed`);return}t(`[${this.getString()}] no child subcircuits to wait for, initiating async routing`),this._hasTracesToRoute()&&this._startAsyncAutorouting()}}updatePcbTraceRender(){var i;const t=KI("tscircuit:core:updatePcbTraceRender");if(t(`[${this.getString()}] updating...`),!this.isSubcircuit)return;if(this._shouldRouteAsync()&&this._hasTracesToRoute()&&!this._hasStartedAsyncAutorouting){this._areChildSubcircuitsRouted()&&(t(`[${this.getString()}] child subcircuits are now routed, starting async autorouting`),this._startAsyncAutorouting());return}if(!this._asyncAutoroutingResult||this._shouldUseTraceByTraceRouting())return;const{db:n}=this.root;if(this._asyncAutoroutingResult.output_simple_route_json){t(`[${this.getString()}] updating PCB traces from simple route json (${(i=this._asyncAutoroutingResult.output_simple_route_json.traces)==null?void 0:i.length} traces)`),this._updatePcbTraceRenderFromSimpleRouteJson();return}if(this._asyncAutoroutingResult.output_pcb_traces){t(`[${this.getString()}] updating PCB traces from ${this._asyncAutoroutingResult.output_pcb_traces.length} traces`),this._updatePcbTraceRenderFromPcbTraces();return}}_updatePcbTraceRenderFromSimpleRouteJson(){const{db:t}=this.root,{traces:n}=this._asyncAutoroutingResult.output_simple_route_json;if(n)for(const i of n)t.pcb_trace.insert({subcircuit_id:this.subcircuit_id,route:i.route})}_updatePcbTraceRenderFromPcbTraces(){const{output_pcb_traces:t}=this._asyncAutoroutingResult;if(!t)return;const{db:n}=this.root;for(const i of t)if(i.type==="pcb_trace"){if(i.subcircuit_id=this.subcircuit_id,i.connection_name){const a=i.connection_name;i.source_trace_id=a}n.pcb_trace.insert(i)}for(const i of t)if(i.type!=="pcb_via"&&i.type==="pcb_trace")for(const a of i.route)a.route_type==="via"&&n.pcb_via.insert({pcb_trace_id:i.pcb_trace_id,x:a.x,y:a.y,hole_diameter:.3,outer_diameter:.6,layers:[a.from_layer,a.to_layer],from_layer:a.from_layer,to_layer:a.to_layer})}doInitialSchematicComponentRender(){var a;if((a=this.root)!=null&&a.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=t.schematic_group.insert({is_subcircuit:this.isSubcircuit,subcircuit_id:this.subcircuit_id,name:this._parsedProps.name,center:this._getGlobalSchematicPositionBeforeLayout(),width:0,height:0,schematic_component_ids:[],source_group_id:this.source_group_id});this.schematic_group_id=i.schematic_group_id;for(const o of this.children)o.schematic_component_id&&t.schematic_component.update(o.schematic_component_id,{schematic_group_id:i.schematic_group_id})}_getSchematicLayoutMode(){var n,i,a;const t=this._parsedProps;return(n=t.schLayout)!=null&&n.matchAdapt?"match-adapt":(i=t.schLayout)!=null&&i.flex?"flex":(a=t.schLayout)!=null&&a.grid?"grid":t.matchAdapt?"match-adapt":t.flex?"flex":t.grid?"grid":"none"}doInitialSchematicLayout(){this._parsedProps;const t=this._getSchematicLayoutMode();t==="match-adapt"&&this._doInitialSchematicLayoutMatchAdapt(),t==="grid"&&this._doInitialSchematicLayoutGrid()}_doInitialSchematicLayoutMatchAdapt(){_st(this)}_doInitialSchematicLayoutGrid(){xst(this)}_getPcbLayoutMode(){var n,i,a;const t=this._parsedProps;return(n=t.pcbLayout)!=null&&n.matchAdapt?"match-adapt":(i=t.pcbLayout)!=null&&i.flex?"flex":(a=t.pcbLayout)!=null&&a.grid?"grid":t.matchAdapt?"match-adapt":t.flex?"flex":t.grid?"grid":"none"}doInitialPcbLayout(){this._getPcbLayoutMode()==="grid"&&this._doInitialPcbLayoutGrid()}_doInitialPcbLayoutGrid(){bst(this)}_determineSideFromPosition(t,n){if(!t.center||!n.center)return"left";const i=t.center.x-n.center.x,a=t.center.y-n.center.y;return Math.abs(i)>Math.abs(a)?i>0?"right":"left":a>0?"bottom":"top"}_calculateSchematicBounds(t){if(t.length===0)return{minX:0,maxX:0,minY:0,maxY:0};let n=1/0,i=-1/0,a=1/0,o=-1/0;for(const l of t)n=Math.min(n,l.centerX),i=Math.max(i,l.centerX),a=Math.min(a,l.centerY),o=Math.max(o,l.centerY);const s=2;return{minX:n-s,maxX:i+s,minY:a-s,maxY:o+s}}_getAutorouterConfig(){const t={serverUrl:"https://registry-api.tscircuit.com",serverMode:"job",serverCacheEnabled:!0},n=this._parsedProps.autorouter??this.getInheritedProperty("autorouter");return typeof n=="object"?{local:!(n.serverUrl||n.serverMode||n.serverCacheEnabled),...t,...n}:n==="auto-local"?{local:!0,groupMode:"subcircuit"}:n==="sequential-trace"?{local:!0,groupMode:"sequential-trace"}:n==="subcircuit"?{local:!0,groupMode:"subcircuit"}:n==="auto-cloud"?{local:!1,groupMode:"subcircuit",serverUrl:t.serverUrl,serverMode:t.serverMode,serverCacheEnabled:!0}:{local:!0,groupMode:"subcircuit"}}_shouldUseTraceByTraceRouting(){return this._getAutorouterConfig().groupMode==="sequential-trace"}doInitialPcbDesignRuleChecks(){var n;if((n=this.root)!=null&&n.pcbDisabled||this.getInheritedProperty("routingDisabled"))return;const{db:t}=this.root;if(this.isSubcircuit){const i=new Map;for(const a of this.children)if(!a.isSubcircuit&&a._parsedProps.name){const o=i.get(a._parsedProps.name)||[];o.push(a),i.set(a._parsedProps.name,o)}for(const[a,o]of i.entries())o.length>1&&t.pcb_trace_error.insert({error_type:"pcb_trace_error",message:`Multiple components found with name "${a}" in subcircuit "${this._parsedProps.name||"unnamed"}". Component names must be unique within a subcircuit.`,source_trace_id:"",pcb_trace_id:"",pcb_component_ids:o.map(s=>s.pcb_component_id).filter(Boolean),pcb_port_ids:[]})}}},Sst=class extends FY{constructor(){super(...arguments);Ve(this,"pcb_board_id",null);Ve(this,"_drcChecksComplete",!1);Ve(this,"_connectedSchematicPortPairs",new Set)}get isSubcircuit(){return!0}get isGroup(){return!0}get config(){return{componentName:"Board",zodProps:RH}}get boardThickness(){const{_parsedProps:t}=this;return 1.4}get allLayers(){return["top","bottom","inner1","inner2"]}doInitialPcbBoardAutoSize(){var m;if((m=this.root)!=null&&m.pcbDisabled||!this.pcb_board_id)return;const{db:t}=this.root,{_parsedProps:n}=this;if(n.width&&n.height)return;let i=1/0,a=1/0,o=-1/0,s=-1/0;const l=t.pcb_component.list();let c=!1;for(const C of l){const{width:E,height:_,center:x}=C;E===0||_===0||(c=!0,i=Math.min(i,x.x-E/2),a=Math.min(a,x.y-_/2),o=Math.max(o,x.x+E/2),s=Math.max(s,x.y+_/2))}const A=2,u=c?o-i+A*2:0,d=c?s-a+A*2:0,g={x:c?(i+o)/2+(n.outlineOffsetX??0):n.outlineOffsetX??0,y:c?(a+s)/2+(n.outlineOffsetY??0):n.outlineOffsetY??0};t.pcb_board.update(this.pcb_board_id,{width:u,height:d,center:g})}doInitialPcbComponentRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this;let i=n.width??0,a=n.height??0;if(n.outline){const c=n.outline.map(C=>C.x),A=n.outline.map(C=>C.y),u=Math.min(...c),d=Math.max(...c),g=Math.min(...A),m=Math.max(...A);i=d-u,a=m-g}const o=t.pcb_board.insert({center:{x:(n.pcbX??0)+(n.outlineOffsetX??0),y:(n.pcbY??0)+(n.outlineOffsetY??0)},thickness:this.boardThickness,num_layers:this.allLayers.length,width:i,height:a,outline:(l=n.outline)==null?void 0:l.map(c=>({x:c.x+(n.outlineOffsetX??0),y:c.y+(n.outlineOffsetY??0)})),material:n.material});this.pcb_board_id=o.pcb_board_id}removePcbComponentRender(){const{db:t}=this.root;this.pcb_board_id&&(t.pcb_board.delete(this.pcb_board_id),this.pcb_board_id=null)}_computePcbGlobalTransformBeforeLayout(){return By()}doInitialPcbDesignRuleChecks(){var t;(t=this.root)!=null&&t.pcbDisabled||this.getInheritedProperty("routingDisabled")||super.doInitialPcbDesignRuleChecks()}updatePcbDesignRuleChecks(){var i;if((i=this.root)!=null&&i.pcbDisabled||this.getInheritedProperty("routingDisabled"))return;const{db:t}=this.root;if(!this._areChildSubcircuitsRouted()||this._drcChecksComplete)return;this._drcChecksComplete=!0;const n=Hpe(t.toArray());for(const a of n)t.pcb_trace_error.insert(a)}_emitRenderLifecycleEvent(t,n){var i;super._emitRenderLifecycleEvent(t,n),n==="start"&&((i=this.root)==null||i.emit("board:renderPhaseStarted",{renderId:this._renderId,phase:t}))}},Qst=new Proxy({},{get:(r,e)=>e}),vQ=Qst,wst=class extends m1{get config(){return{componentName:"Capacitor",schematicSymbolName:this.props.polarized?"capacitor_polarized":this.props.symbolName??"capacitor",zodProps:sge,sourceFtype:vQ.simple_capacitor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){const e=`${vx(this._parsedProps.capacitance)}F`;return this._parsedProps.schShowRatings&&this._parsedProps.maxVoltageRating?`${e}/${vx(this._parsedProps.maxVoltageRating)}V`:e}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.decouplingFor,this.props.decouplingTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.decouplingFor&&this.props.decouplingTo&&(this.add(new vS({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.decouplingFor})),this.add(new vS({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.decouplingTo}))),this._createTracesFromConnectionsProp()}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_capacitor",name:t.name,manufacturer_part_number:t.manufacturerPartNumber??t.mfn,supplier_part_numbers:t.supplierPartNumbers,capacitance:t.capacitance,max_voltage_rating:t.maxVoltageRating,max_decoupling_trace_length:t.maxDecouplingTraceLength,display_capacitance:this._getSchematicSymbolDisplayValue(),are_pins_interchangeable:!t.polarized});this.source_component_id=n.source_component_id}},C0e=class extends m1{constructor(){super(...arguments);Ve(this,"schematicBoxDimensions",null)}get config(){return{componentName:"Chip",zodProps:NH,shouldRenderAsSchematicBox:!0}}doInitialSchematicComponentRender(){const{_parsedProps:t}=this;(t==null?void 0:t.noSchematicRepresentation)!==!0&&super.doInitialSchematicComponentRender()}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_chip",name:n.name,manufacturer_part_number:n.manufacturerPartNumber,supplier_part_numbers:n.supplierPartNumbers});this.source_component_id=i.source_component_id}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=t.pcb_component.insert({center:{x:n.pcbX??0,y:n.pcbY??0},width:2,height:3,layer:n.layer??"top",rotation:n.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.pcb_component_id=i.pcb_component_id}doInitialCreateTracesFromProps(){const{_parsedProps:t}=this;if(t.externallyConnectedPins)for(const[n,i]of t.externallyConnectedPins)this.add(new vS({from:`${this.getSubcircuitSelector()} > port.${n}`,to:`${this.getSubcircuitSelector()} > port.${i}`}));this._createTracesFromConnectionsProp()}},Mst=class extends m1{constructor(){super(...arguments);Ve(this,"pos",this.portMap.pin1);Ve(this,"anode",this.portMap.pin1);Ve(this,"neg",this.portMap.pin2);Ve(this,"cathode",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"diode",componentName:"Diode",zodProps:Ege,sourceFtype:"simple_diode"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_diode",name:n.name,manufacturer_part_number:n.manufacturerPartNumber??n.mfn,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},Dst=class extends m1{get config(){return{componentName:"fuse",schematicSymbolName:this.props.symbolName??"fuse",zodProps:Ctt,sourceFtype:vQ.simple_fuse}}_getSchematicSymbolDisplayValue(){const r=this._parsedProps.currentRating,e=this._parsedProps.voltageRating,t=typeof r=="string"?parseFloat(r):r,n=typeof e=="string"?parseFloat(e):e;return`${vx(t)}A / ${vx(n)}V`}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=typeof e.currentRating=="string"?parseFloat(e.currentRating):e.currentRating,n=typeof e.voltageRating=="string"?parseFloat(e.voltageRating):e.voltageRating,i=r.source_component.insert({name:e.name,ftype:vQ.simple_fuse,current_rating_amps:t,voltage_rating_volts:n,display_current_rating:`${vx(t)}A`,display_voltage_rating:`${vx(n)}V`});this.source_component_id=i.source_component_id}},Rst=class extends m1{constructor(){super(...arguments);Ve(this,"schematicDimensions",null)}get config(){let t="";if(this.props.pinCount&&(t+=`solderjumper${this.props.pinCount||2}`),Array.isArray(this.props.internallyConnectedPins)&&this.props.internallyConnectedPins.length>0){const n=Array.from(new Set(this.props.internallyConnectedPins.flat())).sort().join("");t+=`_bridged${n}`}return{schematicSymbolName:t,componentName:"Jumper",zodProps:ege,shouldRenderAsSchematicBox:!0}}_getSchematicPortArrangement(){const t=super._getSchematicPortArrangement();if(t)return t;const n=this._parsedProps.pinCount??(Array.isArray(this._parsedProps.pinLabels)?this._parsedProps.pinLabels.length:this._parsedProps.pinLabels?Object.keys(this._parsedProps.pinLabels).length:this.getPortsFromFootprint().length),i=this._parsedProps.schDirection??"right";return{leftSize:i==="left"?n:0,rightSize:i==="right"?n:0}}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_chip",name:n.name,manufacturer_part_number:n.manufacturerPartNumber,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=i.source_component_id}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=t.pcb_component.insert({center:{x:n.pcbX??0,y:n.pcbY??0},width:2,height:3,layer:n.layer??"top",rotation:n.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.pcb_component_id=i.pcb_component_id}doInitialPcbTraceRender(){const{db:t}=this.root,n=t.pcb_port.list({pcb_component_id:this.pcb_component_id}),i={};for(let s=0;s<n.length;s++){const l=n[s],c=t.source_port.get(l.source_port_id);let A="";if(typeof(c==null?void 0:c.pin_number)=="number")A=c.pin_number.toString();else if(Array.isArray(c==null?void 0:c.port_hints)){let u=c.port_hints.find(d=>/^(pin)?\d+$/.test(d));u&&(/^pin\d+$/.test(u)?A=u.replace(/^pin/,""):A=u)}i[A]=l.pcb_port_id}const a=t.pcb_trace.list(),o=s=>{if(s&&typeof s=="string"&&s.startsWith("{PIN")){const l=s.replace("{PIN","").replace("}","");return i[l]||s}return s};for(const s of a)if(s.route)for(const l of s.route)l.route_type==="wire"&&(l.start_pcb_port_id=o(l.start_pcb_port_id),l.end_pcb_port_id=o(l.end_pcb_port_id))}},Nst=class extends m1{constructor(){super(...arguments);Ve(this,"pos",this.portMap.pin1);Ve(this,"anode",this.portMap.pin1);Ve(this,"neg",this.portMap.pin2);Ve(this,"cathode",this.portMap.pin2)}get config(){return{componentName:"Led",schematicSymbolName:this.props.symbolName??"led",zodProps:_ge,sourceFtype:"simple_led"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return this._parsedProps.schDisplayValue||this._parsedProps.color||void 0}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_led",name:n.name,wave_length:n.wavelength,color:n.color,symbol_display_value:this._getSchematicSymbolDisplayValue(),manufacturer_part_number:n.manufacturerPartNumber??n.mfn,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},Tst=class extends m1{constructor(){super(...arguments);Ve(this,"pos",this.portMap.pin1);Ve(this,"positive",this.portMap.pin1);Ve(this,"neg",this.portMap.pin2);Ve(this,"negative",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"power_factor_meter_horz",componentName:"PowerSource",zodProps:wge,sourceFtype:"simple_power_source"}}initPorts(){this.add(new yS({name:"pin1",pinNumber:1,aliases:["positive","pos"]})),this.add(new yS({name:"pin2",pinNumber:2,aliases:["negative","neg"]}))}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_power_source",name:n.name,voltage:n.voltage,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},Pst=class extends m1{get config(){return{componentName:"Resistor",schematicSymbolName:this.props.symbolName??"boxresistor",zodProps:rge,sourceFtype:"simple_resistor"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${vx(this._parsedProps.resistance)}Ω`}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.pullupFor,this.props.pullupTo,this.props.pulldownFor,this.props.pulldownTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.pullupFor&&this.props.pullupTo&&(this.add(new vS({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pullupFor})),this.add(new vS({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pullupTo}))),this.props.pulldownFor&&this.props.pulldownTo&&(this.add(new vS({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pulldownFor})),this.add(new vS({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pulldownTo}))),this._createTracesFromConnectionsProp()}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_resistor",name:t.name,manufacturer_part_number:t.manufacturerPartNumber??t.mfn,supplier_part_numbers:t.supplierPartNumbers,resistance:t.resistance,display_resistance:this._getSchematicSymbolDisplayValue(),are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}},Ust=["leftedge","rightedge","topedge","bottomedge","center"],Fst=class extends Kv{get config(){return{componentName:"Constraint",zodProps:lge}}constructor(e){if(super(e),("xdist"in e||"ydist"in e)&&!("edgeToEdge"in e)&&!("centerToCenter"in e))throw new Error(`edgeToEdge, centerToCenter must be set for xDist or yDist for ${this}`);if("for"in e&&e.for.length<2)throw new Error(`"for" must have at least two selectors for ${this}`)}_getAllReferencedComponents(){const e=[],t=this.getPrimitiveContainer();function n(i){const a=i.split(" ").pop(),o=Ust.includes(a)?a:void 0,s=o?i.replace(` ${o}`,""):i,l=t.selectOne(s,{pcbPrimitive:!0});l&&e.push({selector:i,component:l,componentSelector:s,edge:o})}for(const i of["left","right","top","bottom"])i in this._parsedProps&&n(this._parsedProps[i]);if("for"in this._parsedProps)for(const i of this._parsedProps.for)n(i);return{componentsWithSelectors:e}}},kst=class extends Kv{constructor(){super(...arguments);Ve(this,"fabrication_note_path_id",null)}get config(){return{componentName:"FabricationNotePath",zodProps:bge}}doInitialPcbPrimitiveRender(){var l,c;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,n=this.getSubcircuit(),{_parsedProps:i}=this,a=i.layer??"top";if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenPath. Must be "top" or "bottom".`);const o=this._computePcbGlobalTransformBeforeLayout(),s=t.pcb_fabrication_note_path.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,color:i.color,route:i.route.map(A=>{const u=si(o,{x:A.x,y:A.y});return{...A,x:u.x,y:u.y}}),stroke_width:i.strokeWidth??.1,subcircuit_id:(n==null?void 0:n.subcircuit_id)??void 0});this.fabrication_note_path_id=s.pcb_fabrication_note_path_id}},Gst=class extends Kv{get config(){return{componentName:"FabricationNoteText",zodProps:xge}}doInitialPcbPrimitiveRender(){var a,o;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=this.getPrimitiveContainer(),i=this.getSubcircuit();e.pcb_fabrication_note_text.insert({anchor_alignment:t.anchorAlignment,anchor_position:{x:t.pcbX??0,y:t.pcbY??0},font:t.font??"tscircuit2024",font_size:t.fontSize??1,layer:"top",color:t.color,text:t.text??"",pcb_component_id:n.pcb_component_id,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((o=this.getGroup())==null?void 0:o.pcb_group_id)??void 0})}},Lst=class extends FY{constructor(e){super({...e,subcircuit:!0})}},Ost=class extends Kv{constructor(){super(...arguments);Ve(this,"source_net_alias_id")}get config(){return{componentName:"NetAlias",zodProps:mge}}doInitialSchematicComponentRender(){var o;if((o=this.root)!=null&&o.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i={x:n.schX??0,y:n.schY??0},a=t.schematic_net_label.insert({text:n.net,source_net_id:n.net,anchor_position:i,center:i,anchor_side:"bottom"});this.source_net_alias_id=a.source_net_id}},zst=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_silkscreen_circle_id",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenCircle",zodProps:Uge}}doInitialPcbPrimitiveRender(){var l,c,A;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(n.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenCircle. Must be "top" or "bottom".`);this._computePcbGlobalTransformBeforeLayout();const o=this.getSubcircuit(),s=t.pcb_silkscreen_circle.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,center:{x:n.pcbX??0,y:n.pcbY??0},radius:n.radius,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((A=this.getGroup())==null?void 0:A.pcb_group_id)??void 0,stroke_width:n.strokeWidth??.1});this.pcb_silkscreen_circle_id=s.pcb_silkscreen_circle_id}getPcbSize(){const{_parsedProps:t}=this,n=t.radius*2;return{width:n,height:n}}},Hst=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_silkscreen_rect_id",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenRect",zodProps:Pge}}doInitialPcbPrimitiveRender(){var l,c,A;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(n.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenRect. Must be "top" or "bottom".`);const o=this.getSubcircuit(),s=t.pcb_silkscreen_rect.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,center:{x:n.pcbX??0,y:n.pcbY??0},width:n.width,height:n.height,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((A=this==null?void 0:this.getGroup())==null?void 0:A.pcb_group_id)??void 0,stroke_width:n.strokeWidth??.1});this.pcb_silkscreen_rect_id=s.pcb_silkscreen_rect_id}getPcbSize(){const{_parsedProps:t}=this;return{width:t.width,height:t.height}}},Yst=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_silkscreen_line_id",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenLine",zodProps:Tge}}doInitialPcbPrimitiveRender(){var l,c,A;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(n.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenLine. Must be "top" or "bottom".`);const o=this.getSubcircuit(),s=t.pcb_silkscreen_line.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2,stroke_width:n.strokeWidth??.1,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((A=o==null?void 0:o.getGroup())==null?void 0:A.pcb_group_id)??void 0});this.pcb_silkscreen_line_id=s.pcb_silkscreen_line_id}getPcbSize(){const{_parsedProps:t}=this,n=Math.abs(t.x2-t.x1),i=Math.abs(t.y2-t.y1);return{width:n,height:i}}},Vst=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_via_id",null);Ve(this,"matchedPort",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Via",zodProps:Sge}}getAvailablePcbLayers(){return["top","inner1","inner2","bottom"]}getPcbSize(){const{_parsedProps:t}=this;return{width:t.outerDiameter,height:t.outerDiameter}}_getPcbCircuitJsonBounds(){const{db:t}=this.root,n=t.pcb_via.get(this.pcb_via_id),i=this.getPcbSize();return{center:{x:n.x,y:n.y},bounds:{left:n.x-i.width/2,top:n.y-i.height/2,right:n.x+i.width/2,bottom:n.y+i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(t){const{db:n}=this.root;n.pcb_via.update(this.pcb_via_id,{x:t.x,y:t.y})}doInitialPcbPrimitiveRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalPcbPositionBeforeLayout(),a=this.getSubcircuit(),o=t.pcb_via.insert({x:i.x,y:i.y,hole_diameter:n.holeDiameter,outer_diameter:n.outerDiameter,layers:["bottom","top"],from_layer:n.fromLayer||"bottom",to_layer:n.toLayer||"top",subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((l=this.getGroup())==null?void 0:l.pcb_group_id)??void 0});this.pcb_via_id=o.pcb_via_id}},Kst=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_cutout_id",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Cutout",zodProps:cge}}doInitialPcbPrimitiveRender(){var l,c;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getSubcircuit(),a=((c=this.getGroup())==null?void 0:c.pcb_group_id)??void 0,o=this._getGlobalPcbPositionBeforeLayout();let s;if(n.shape==="rect"){const A={shape:"rect",center:o,width:n.width,height:n.height,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:a};s=t.pcb_cutout.insert(A)}else if(n.shape==="circle"){const A={shape:"circle",center:o,radius:n.radius,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:a};s=t.pcb_cutout.insert(A)}else if(n.shape==="polygon"){const A=this._computePcbGlobalTransformBeforeLayout(),d={shape:"polygon",points:n.points.map(g=>si(A,g)),subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:a};s=t.pcb_cutout.insert(d)}s&&(this.pcb_cutout_id=s.pcb_cutout_id)}getPcbSize(){const{_parsedProps:t}=this;if(t.shape==="rect")return{width:t.width,height:t.height};if(t.shape==="circle")return{width:t.radius*2,height:t.radius*2};if(t.shape==="polygon"){if(t.points.length===0)return{width:0,height:0};let n=1/0,i=-1/0,a=1/0,o=-1/0;for(const s of t.points)n=Math.min(n,s.x),i=Math.max(i,s.x),a=Math.min(a,s.y),o=Math.max(o,s.y);return{width:i-n,height:o-a}}return{width:0,height:0}}_getPcbCircuitJsonBounds(){if(!this.pcb_cutout_id)return super._getPcbCircuitJsonBounds();const{db:t}=this.root,n=t.pcb_cutout.get(this.pcb_cutout_id);if(!n)return super._getPcbCircuitJsonBounds();if(n.shape==="rect")return{center:n.center,bounds:{left:n.center.x-n.width/2,top:n.center.y+n.height/2,right:n.center.x+n.width/2,bottom:n.center.y-n.height/2},width:n.width,height:n.height};if(n.shape==="circle")return{center:n.center,bounds:{left:n.center.x-n.radius,top:n.center.y+n.radius,right:n.center.x+n.radius,bottom:n.center.y-n.radius},width:n.radius*2,height:n.radius*2};if(n.shape==="polygon"){if(n.points.length===0)return super._getPcbCircuitJsonBounds();let i=1/0,a=-1/0,o=1/0,s=-1/0;for(const l of n.points)i=Math.min(i,l.x),a=Math.max(a,l.x),o=Math.min(o,l.y),s=Math.max(s,l.y);return{center:{x:(i+a)/2,y:(o+s)/2},bounds:{left:i,top:s,right:a,bottom:o},width:a-i,height:s-o}}return super._getPcbCircuitJsonBounds()}_setPositionFromLayout(t){if(!this.pcb_cutout_id)return;const{db:n}=this.root,i=n.pcb_cutout.get(this.pcb_cutout_id);if(i){if(i.shape==="rect"||i.shape==="circle")n.pcb_cutout.update(this.pcb_cutout_id,{...i,center:t});else if(i.shape==="polygon"){const a=this._getPcbCircuitJsonBounds().center,o=t.x-a.x,s=t.y-a.y,l=i.points.map(c=>({x:c.x+o,y:c.y+s}));n.pcb_cutout.update(this.pcb_cutout_id,{...i,points:l})}}}},Jst=class extends m1{get config(){return{componentName:"Battery",schematicSymbolName:this.props.symbolName??"battery",zodProps:gge,sourceFtype:"simple_power_source"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:t.name,ftype:"simple_power_source",capacity:t.capacity,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=n.source_component_id}},jst=class extends m1{get config(){return{componentName:"PinHeader",zodProps:pge,shouldRenderAsSchematicBox:!0}}_getImpliedFootprintString(){var a;const e=this._parsedProps.pinCount??((a=this._parsedProps.pinLabels)==null?void 0:a.length)??0,t=this._parsedProps.holeDiameter,n=this._parsedProps.platedDiameter,i=this._parsedProps.pitch;return e>0&&i?!t&&!n?`pinrow${e}_p${i}`:`pinrow${e}_p${i}_id${t}_od${n}`:null}initPorts(){var t,n;const e=this._parsedProps.pinCount??((t=this._parsedProps.pinLabels)==null?void 0:t.length)??1;for(let i=1;i<=e;i++)this.add(new yS({name:`pin${i}`,pinNumber:i,aliases:[(n=this._parsedProps.pinLabels)==null?void 0:n[i-1]].filter(Boolean)}))}_getSchematicPortArrangement(){var i,a,o,s;const e=this._parsedProps.pinCount??1,t=this._parsedProps.facingDirection??"right",n=this._parsedProps.schPinArrangement;return t==="left"?{leftSide:{direction:((i=n==null?void 0:n.leftSide)==null?void 0:i.direction)??"top-to-bottom",pins:((a=n==null?void 0:n.leftSide)==null?void 0:a.pins)??Array.from({length:e},(l,c)=>`pin${c+1}`)}}:{rightSide:{direction:((o=n==null?void 0:n.rightSide)==null?void 0:o.direction)??"top-to-bottom",pins:((s=n==null?void 0:n.rightSide)==null?void 0:s.pins)??Array.from({length:e},(l,c)=>`pin${c+1}`)}}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_pin_header",name:t.name,supplier_part_numbers:t.supplierPartNumbers,pin_count:t.pinCount,gender:t.gender,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}};function Wst(r){switch(r){case"two_ground_pins":return"crystal_4pin";case"ground_pin":return"resonator";case"no_ground":return"crystal";default:return"crystal"}}var Zst=class extends m1{get config(){return{componentName:"Resonator",schematicSymbolName:this.props.symbolName??Wst(this.props.pinVariant),zodProps:oge,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=t.pinVariant||"no_ground",i=e.source_component.insert({ftype:"simple_resonator",name:t.name,frequency:t.frequency,load_capacitance:t.loadCapacitance,supplier_part_numbers:t.supplierPartNumbers,pin_variant:n,are_pins_interchangeable:n==="no_ground"||n==="ground_pin"});this.source_component_id=i.source_component_id}},qst=class extends m1{get config(){return{componentName:"Inductor",schematicSymbolName:this.props.symbolName??"inductor",zodProps:Cge,sourceFtype:vQ.simple_inductor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:t.name,ftype:vQ.simple_inductor,inductance:t.inductance,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}};function Xst(r){switch(r){case"three_pin":return"potentiometer3";case"two_pin":return"potentiometer2";default:return"potentiometer2"}}var $st=class extends m1{get config(){return{componentName:"Potentiometer",schematicSymbolName:this.props.symbolName??Xst(this.props.pinVariant),zodProps:ige,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=t.pinVariant||"two_pin",i=e.source_component.insert({ftype:"simple_potentiometer",name:t.name,max_resistance:t.maxResistance,pin_variant:n,are_pins_interchangeable:n==="two_pin"});this.source_component_id=i.source_component_id}},elt=class extends m1{get config(){return{componentName:"PushButton",schematicSymbolName:this.props.symbolName??"push_button_normally_open_momentary",zodProps:yge,sourceFtype:vQ.simple_push_button}}get defaultInternallyConnectedPinNames(){return[["pin1","pin4"],["pin2","pin3"]]}initPorts(){super.initPorts({pinCount:4,additionalAliases:{pin1:["side1"],pin3:["side2"]}})}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:t.name,ftype:vQ.simple_push_button,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}},tlt=class extends m1{get config(){return{schematicSymbolName:this.props.symbolName??(this.props.pinVariant==="four_pin"?"crystal_4pin":"crystal"),componentName:"Crystal",zodProps:age,sourceFtype:"simple_crystal"}}initPorts(){const e=this.props.pinVariant==="four_pin"?{pin1:["left1","1"],pin2:["top1","2","gnd1"],pin3:["right1","3"],pin4:["bottom1","4","gnd2"]}:{pin1:["pos","left"],pin2:["neg","right"]};super.initPorts({additionalAliases:e})}_getSchematicSymbolDisplayValue(){return`${vx(this._parsedProps.frequency)}Hz`}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:t.name,ftype:"simple_crystal",frequency:t.frequency,load_capacitance:t.loadCapacitance,pin_variant:t.pinVariant||"two_pin",are_pins_interchangeable:(t.pinVariant||"two_pin")==="two_pin"});this.source_component_id=n.source_component_id}},nlt=class extends m1{constructor(){super(...arguments);Ve(this,"emitter",this.portMap.pin1);Ve(this,"collector",this.portMap.pin2);Ve(this,"base",this.portMap.pin3)}get config(){return{componentName:"Transistor",schematicSymbolName:this.props.type==="npn"?"npn_bipolar_transistor":"pnp_bipolar_transistor",zodProps:vge,sourceFtype:"simple_transistor",shouldRenderAsSchematicBox:!1}}initPorts(){const t=this.props.type==="npn"?{pin1:["emitter","e"],pin2:["collector","c"],pin3:["base","b"]}:{pin1:["collector","c"],pin2:["emitter","e"],pin3:["base","b"]};super.initPorts({pinCount:3,additionalAliases:t})}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_transistor",name:n.name,transistor_type:n.type});this.source_component_id=i.source_component_id}},rlt=class extends m1{get config(){const e=this.props.mosfetMode==="depletion"?"d":"e";return{componentName:"Mosfet",schematicSymbolName:`${this.props.channelType}_channel_${e}_mosfet_transistor`,zodProps:Ige,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_mosfet",name:t.name,mosfet_mode:t.mosfetMode,channel_type:t.channelType});this.source_component_id=n.source_component_id}},ilt=class extends m1{_getSwitchType(){const{spst:e,spdt:t,dpst:n,dpdt:i,type:a}=this._parsedProps??{};return i?"dpdt":e?"spst":t?"spdt":n?"dpst":a??"spst"}get config(){const e=this._getSwitchType(),{isNormallyClosed:t}=this._parsedProps??{};return{componentName:"Switch",schematicSymbolName:{spst:t?"spst_normally_closed_switch":"spst_switch",spdt:t?"spdt_normally_closed_switch":"spdt_switch",dpst:t?"dpst_normally_closed_switch":"dpst_switch",dpdt:t?"dpdt_normally_closed_switch":"dpdt_switch"}[e]??"spst_switch",zodProps:Bge,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_switch",name:t.name,switch_type:t.type,is_normally_closed:t.isNormallyClosed??!1,are_pins_interchangeable:this._getSwitchType()==="spst"});this.source_component_id=n.source_component_id}},alt=class extends Kv{constructor(){super(...arguments);Ve(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicText",zodProps:Dge}}doInitialSchematicPrimitiveRender(){var i;if((i=this.root)!=null&&i.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this;t.schematic_text.insert({anchor:n.anchor??"center",text:n.text,font_size:n.fontSize,color:n.color||"#000000",position:{x:n.schX,y:n.schY},rotation:n.schRotation??0})}},olt=class extends Kv{constructor(){super(...arguments);Ve(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicBox",zodProps:Mge,shouldRenderAsSchematicBox:!0}}doInitialSchematicPrimitiveRender(){var E;if((E=this.root)!=null&&E.schematicDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=Mge.safeParse(t);if(!n.success)throw console.error("Validation failed:",n.error.format()),n.error;const i=.6,a=typeof t.padding=="number"?t.padding:0,o=typeof t.paddingTop=="number"?t.paddingTop:a,s=typeof t.paddingBottom=="number"?t.paddingBottom:a,l=typeof t.paddingLeft=="number"?t.paddingLeft:a,c=typeof t.paddingRight=="number"?t.paddingRight:a,A=t.overlay&&t.overlay.length>0,u=typeof t.width=="number"&&typeof t.height=="number";let d,g,m,C;if(A){const x=t.overlay.map(Ue=>({selector:Ue,port:this.getSubcircuit().selectOne(Ue,{type:"port"})})).filter(({port:Ue})=>Ue!=null).map(({port:Ue})=>({position:Ue._getGlobalSchematicPositionAfterLayout()}));if(x.length===0)return;const Q=x.map(Ue=>Ue.position.x),P=x.map(Ue=>Ue.position.y),z=Math.min(...Q),O=Math.max(...Q),V=Math.min(...P),j=Math.max(...P),q=O-z,J=j-V,ce=q===0?i:0,oe=J===0?i:0,de=l+ce/2,Ie=c+ce/2,Be=o+oe/2,pe=s+oe/2,_e=z-de,ve=O+Ie,Ne=V-pe,we=j+Be;d=ve-_e,g=we-Ne,m=_e+(t.schX??0),C=Ne+(t.schY??0)}else if(u){d=t.width,g=t.height;const _=typeof t.schX=="number"?t.schX:0,x=typeof t.schY=="number"?t.schY:0;m=_-d/2,C=x-g/2}else return;e.schematic_box.insert({height:g,width:d,x:m,y:C,is_dashed:t.strokeStyle==="dashed",schematic_component_id:""})}},slt={version:"0.0.445"},llt=class{constructor({platform:r}={}){Ve(this,"firstChild",null);Ve(this,"children");Ve(this,"db");Ve(this,"root",null);Ve(this,"isRoot",!0);Ve(this,"schematicDisabled",!1);Ve(this,"pcbDisabled",!1);Ve(this,"pcbRoutingDisabled",!1);Ve(this,"name");Ve(this,"platform");Ve(this,"_hasRenderedAtleastOnce",!1);Ve(this,"_eventListeners",{});this.children=[],this.db=$E([]),this.root=this,this.platform=r}add(r){let e;yt.isValidElement(r)?e=i0e(r):e=r,this.children.push(e)}_getBoard(){return this.children.find(r=>r.componentName==="Board")}_guessRootComponent(){if(!this.firstChild){if(this.children.length===1){this.firstChild=this.children[0];return}if(this.children.length===0)throw new Error("Not able to guess root component: RootCircuit has no children (use circuit.add(...))");if(this.children.length>0){const r=this.children.find(e=>e.componentName==="Board")??null;if(r){this.firstChild=r;return}}throw new Error("Not able to guess root component: RootCircuit has multiple children and no board")}}render(){this.firstChild||this._guessRootComponent();const{firstChild:r,db:e}=this;if(!r)throw new Error("RootCircuit has no root component");r.parent=this,r.runRenderCycle(),this._hasRenderedAtleastOnce=!0}async renderUntilSettled(){var r;for((r=this.db.source_project_metadata.list())!=null&&r[0]||this.db.source_project_metadata.insert({software_used_string:`@tscircuit/core@${this.getCoreVersion()}`}),this.render();this._hasIncompleteAsyncEffects();)await new Promise(e=>setTimeout(e,100)),this.render();this.emit("renderComplete")}_hasIncompleteAsyncEffects(){return this.children.some(r=>r._hasIncompleteAsyncEffects()?!0:r.children.some(e=>e._hasIncompleteAsyncEffects()))}getCircuitJson(){return this._hasRenderedAtleastOnce||this.render(),this.db.toArray()}toJson(){return this.getCircuitJson()}async getSvg(r){const e=await Promise.resolve().then(()=>rkt).catch(t=>{throw new Error(`To use circuit.getSvg, you must install the "circuit-to-svg" package.
|
|
852
|
+
`)}visualize(){return[{title:"inputTemplate",ascii:this.template.toString(),table:this.outputIssues.map((e,t)=>({issue_index:t,type:e.type,target_box:"targetBoxIndex"in e?this.getBoxNameFromIndex(e.targetBoxIndex,!1):"N/A",candidate_box:"candidateBoxIndex"in e?this.getBoxNameFromIndex(e.candidateBoxIndex,!0):"N/A",details:e}))},{title:"pairwisePinShapeSignatures",table:Bot({targetNetlist:this.inputNetlistWithRotations,candidateNetlist:this.template.getNetlist(),matchedBoxes:this.matchedBoxes,targetTransform:this.targetTransform,candidateTransform:this.candidateTransform})},{title:"matchedBoxes",ascii:this.generateMatchedBoxesVisualization(),table:this.matchedBoxes.map(e=>({target_box:this.getBoxNameFromIndex(e.targetBoxIndex,!1),candidate_box:this.getBoxNameFromIndex(e.candidateBoxIndex,!0),rotation:e.targetBoxRotationCcw,issueCount:e.issues.length,details:e}))},{title:"inputTemplateReadableNetlist",ascii:this.template.getReadableNetlist()},{title:"inputTargetReadableNetlist",ascii:pD(this.inputNetlist)},this.inputNetlistWithRotations&&{title:"targetReadableNetlistWithRotations",ascii:pD(this.inputNetlistWithRotations)}].filter(Boolean)}},bot=class extends S9{constructor(e){var t;super();Ve(this,"inputNetlist");Ve(this,"templates");Ve(this,"scoringSolvers",[]);Ve(this,"currentScoringIndex",0);Ve(this,"outputBestMatchTemplate",null);Ve(this,"templateMatchResults",[]);this.inputNetlist=e.inputNetlist,this.templates=((t=e.templateFns)==null?void 0:t.map(n=>n()))||yot.map(n=>n()),this.scoringSolvers=this.templates.map(n=>new xot({inputNetlist:this.inputNetlist,template:n}))}getConstructorParams(){return{inputNetlist:this.inputNetlist}}computeProgress(){return this.scoringSolvers.length===0?1:this.currentScoringIndex/this.scoringSolvers.length}_step(){if(this.currentScoringIndex<this.scoringSolvers.length){const t=this.scoringSolvers[this.currentScoringIndex];if(!t.solved&&!t.failed){this.setActiveSubSolver(t),t.step();return}this.clearActiveSubSolver(),this.currentScoringIndex++;return}if(this.templateMatchResults=this.scoringSolvers.map(t=>({template:t.template,issues:t.outputIssues,similarityDistance:t.outputSimilarityDistance})),this.templateMatchResults.length===0){this.outputBestMatchTemplate=null,this.solved=!0;return}let e=this.templateMatchResults[0];for(let t=1;t<this.templateMatchResults.length;t++)this.templateMatchResults[t].similarityDistance<e.similarityDistance&&(e=this.templateMatchResults[t]);e.similarityDistance===1/0?this.outputBestMatchTemplate=null:this.outputBestMatchTemplate=e.template,this.solved=!0}visualize(){var e;return[{title:"inputNetlist",ascii:pD(this.inputNetlist)},{title:"bestMatchTemplate",ascii:((e=this.outputBestMatchTemplate)==null?void 0:e.toString())||"No suitable match found"},{title:"templateScores",table:this.templateMatchResults.map((t,n)=>({template_index:n,template_name:t.template.name||`Template ${n}`,similarity_distance:t.similarityDistance,issue_count:t.issues.length,is_best_match:t.template===this.outputBestMatchTemplate}))}]}},Sot=class extends S9{constructor(e){super();Ve(this,"inputNetlists");Ve(this,"currentInputNetlistIndex",0);Ve(this,"templateFns");Ve(this,"outputMatchedTemplates",[]);this.inputNetlists=e.inputNetlists,this.templateFns=e.templateFns}get activeSubSolver(){return this._activeSubSolver}_step(){if(this.activeSubSolver)if(this.activeSubSolver.step(),this.activeSubSolver.solved){this.outputMatchedTemplates.push({template:this.activeSubSolver.outputBestMatchTemplate,netlist:this.inputNetlists[this.currentInputNetlistIndex]}),this.currentInputNetlistIndex++,this.clearActiveSubSolver();return}else return;if(this.currentInputNetlistIndex>=this.inputNetlists.length){this.solved=!0;return}this.setActiveSubSolver(new bot({inputNetlist:this.inputNetlists[this.currentInputNetlistIndex],templateFns:this.templateFns}))}};function qpe(r,e,t,n={}){return{solverName:r,solverClass:e,getConstructorParams:t,onSolved:n.onSolved}}var Qot=class extends S9{constructor(e){super();Ve(this,"inputNetlist");Ve(this,"templateFnsOverride");Ve(this,"matchPhaseSolver");Ve(this,"adaptPhaseSolver");Ve(this,"startTimeOfPhase",{});Ve(this,"endTimeOfPhase",{});Ve(this,"timeSpentOnPhase",{});Ve(this,"pipelineDef",[qpe("matchPhaseSolver",Sot,()=>[{inputNetlists:[this.inputNetlist],templateFns:this.templateFnsOverride}]),qpe("adaptPhaseSolver",sot,()=>{var e;return[{matchedTemplates:(e=this.matchPhaseSolver)==null?void 0:e.outputMatchedTemplates}]})]);Ve(this,"currentPipelineStepIndex",0);this.inputNetlist=e.inputNetlist,this.templateFnsOverride=e.templateFns}_step(){var n,i;const e=this.pipelineDef[this.currentPipelineStepIndex];if(!e){this.solved=!0;return}if(this.activeSubSolver){if(this.activeSubSolver.step(),this.activeSubSolver.solved){this.endTimeOfPhase[e.solverName]=performance.now(),this.timeSpentOnPhase[e.solverName]=this.endTimeOfPhase[e.solverName]-this.startTimeOfPhase[e.solverName],(n=e.onSolved)==null||n.call(e,this),this.clearActiveSubSolver(),this.currentPipelineStepIndex++;return}if(this.activeSubSolver.failed){this.error=(i=this.activeSubSolver)==null?void 0:i.error,this.failed=!0,this.clearActiveSubSolver();return}return}const t=e.getConstructorParams(this);this.setActiveSubSolver(new e.solverClass(...t)),this[e.solverName]=this.activeSubSolver,this.timeSpentOnPhase[e.solverName]=0,this.startTimeOfPhase[e.solverName]=performance.now()}getLayout(){var e,t;if(!((t=(e=this.adaptPhaseSolver)==null?void 0:e.outputAdaptedTemplates)!=null&&t[0]))throw new Error("No adapted template available. Make sure the pipeline has completed successfully.");return this.adaptPhaseSolver.outputAdaptedTemplates[0].template.getLayoutJson()}},wot=r=>{switch(r){case"left":return"left";case"right":return"right";case"up":return"top";case"down":return"bottom"}},Mot=r=>{const e=pS(r),t=yx(r).source_component.list().map(o=>({source_component:o,schematic_component:yx(r).schematic_component.getWhere({source_component_id:o.source_component_id}),source_ports:yx(r).source_port.list().filter(s=>s.source_component_id===o.source_component_id).map(s=>{const l=e.getNetConnectedToId(s.source_port_id),c=yx(r).schematic_port.getWhere({source_port_id:s.source_port_id}),A=(c==null?void 0:c.true_ccw_index)!=null?c.true_ccw_index+1:s.pin_number;return{source_port:s,schematic_port:yx(r).schematic_port.getWhere({source_port_id:s.source_port_id}),pin_number:A,connectivity_net_id:l}}).filter(({schematic_port:s})=>!!s)})),n=[],i=[];for(const{source_component:o,schematic_component:s,source_ports:l}of t){const c={boxId:o.name,leftPinCount:0,rightPinCount:0,topPinCount:0,bottomPinCount:0};for(const{source_port:A,schematic_port:u,pin_number:d}of l){const g=wot(u.facing_direction);c[`${g}PinCount`]++;const m=e.getNetConnectedToId(A.source_port_id);let C=i.find(E=>E._connectivityNetId===m);C||(C={_connectivityNetId:m,connectedPorts:[]},i.push(C)),C.connectedPorts.push({boxId:o.name,pinNumber:(u==null?void 0:u.true_ccw_index)!=null?u.true_ccw_index+1:d})}n.push(c)}const a=[];for(const o of i){if(o.connectedPorts.length<2)continue;let s=o._connectivityNetId;const l=e.getIdsConnectedToNet(s).map(c=>Gpe(r,c));for(const c of l)if((c==null?void 0:c.type)==="source_net"){s=c.name;break}o.connectedPorts.push({netId:s}),a.push({netId:s})}return{boxes:n,connections:i,nets:a}},Dot=r=>{const e=JSON.parse(JSON.stringify(r)),t=e.filter(n=>n.type==="schematic_component"&&n.port_arrangement);for(const n of t){const i=e.filter(o=>o.type==="schematic_port"&&o.schematic_component_id===n.schematic_component_id&&o.true_ccw_index!==void 0);if(i.length===0)continue;i.sort((o,s)=>o.true_ccw_index-s.true_ccw_index);const a={};i.forEach((o,s)=>{a[o.pin_number]=s+1});for(const o of i){const s=a[o.pin_number];o.pin_number=s}for(const o of i){const s=e.find(l=>l.type==="source_port"&&l.source_port_id===o.source_port_id);s&&(s.pin_number=o.pin_number)}if(n.port_arrangement){const o=s=>{var l;(l=n.port_arrangement[s])!=null&&l.pins&&(n.port_arrangement[s].pins=n.port_arrangement[s].pins.map(c=>a[c]||c))};o("left_side"),o("right_side"),o("top_side"),o("bottom_side")}if(n.port_labels){const o={};for(const[s,l]of Object.entries(n.port_labels)){const c=parseInt(s.replace("pin","")),A=a[c];A!==void 0?o[`pin${A}`]=l:o[s]=l}n.port_labels=o}if(n.pin_styles){const o={};for(const[s,l]of Object.entries(n.pin_styles)){const c=parseInt(s.replace("pin","")),A=a[c];A!==void 0?o[`pin${A}`]=l:o[s]=l}n.pin_styles=o}}return e},xY=[{value:1e12,symbol:"T"},{value:1e9,symbol:"G"},{value:1e6,symbol:"M"},{value:1e3,symbol:"k"},{value:1,symbol:""},{value:.001,symbol:"m"},{value:1e-6,symbol:"µ"},{value:1e-9,symbol:"n"},{value:1e-12,symbol:"p"}];function vx(r){if(r==null)return"";if(r===0)return"0";const e=Math.abs(r),t=xY.find(a=>{const o=e/a.value;return o>=1&&o<1e3})||xY[xY.length-1];let i=(r/t.value).toPrecision(3);return i.includes(".")&&!/\.0+$/.test(i)&&(i=i.replace(/0+$/,"")),i=i.replace(/\.0+$/,""),`${i}${t.symbol}`}var Rot=Object.defineProperty,Not=(r,e)=>{for(var t in e)Rot(r,t,{get:e[t],enumerable:!0})},Xpe={};Not(Xpe,{Battery:()=>Jst,Board:()=>Sst,Capacitor:()=>wst,Chip:()=>C0e,Constraint:()=>Fst,Crystal:()=>tlt,Cutout:()=>Kst,Diode:()=>Mst,FabricationNotePath:()=>kst,FabricationNoteText:()=>Gst,Footprint:()=>tst,Fuse:()=>Dst,Group:()=>FY,Hole:()=>A0e,Inductor:()=>qst,Jumper:()=>Rst,Keepout:()=>DY,Led:()=>Nst,Mosfet:()=>rlt,Net:()=>o0e,NetAlias:()=>Ost,NormalComponent:()=>m1,PcbTrace:()=>c0e,PinHeader:()=>jst,PlatedHole:()=>MY,Port:()=>yS,Potentiometer:()=>$st,PowerSource:()=>Tst,PrimitiveComponent:()=>Kv,PushButton:()=>elt,Renderable:()=>$pe,Resistor:()=>Pst,Resonator:()=>Zst,SchematicBox:()=>olt,SchematicText:()=>alt,SilkscreenCircle:()=>zst,SilkscreenLine:()=>Yst,SilkscreenPath:()=>l0e,SilkscreenRect:()=>Hst,SilkscreenText:()=>RY,SmtPad:()=>wY,Subcircuit:()=>Lst,Switch:()=>ilt,Trace:()=>vS,TraceHint:()=>v0e,Transistor:()=>nlt,Via:()=>Vst});var Tot=KI("tscircuit:renderable"),Ix=["ReactSubtreesRender","PcbFootprintStringRender","InitializePortsFromChildren","CreateNetsFromProps","CreateTracesFromProps","CreateTraceHintsFromProps","SourceRender","SourceParentAttachment","PortMatching","OptimizeSelectorCache","SourceTraceRender","SourceAddConnectivityMapKey","SchematicComponentRender","SchematicPortRender","SchematicPrimitiveRender","SchematicLayout","SchematicTraceRender","SchematicReplaceNetLabelsWithSymbols","PcbComponentRender","PcbPrimitiveRender","PcbFootprintLayout","PcbPortRender","PcbPortAttachment","PcbLayout","PcbComponentSizeCalculation","PcbBoardAutoSize","PcbTraceHintRender","PcbTraceRender","PcbRouteNetIslands","PcbDesignRuleChecks","CadModelRender","PartsEngineRender"],Pot=0,$pe=class{constructor(e){Ve(this,"renderPhaseStates");Ve(this,"shouldBeRemoved",!1);Ve(this,"children");Ve(this,"isPcbPrimitive",!1);Ve(this,"isSchematicPrimitive",!1);Ve(this,"_renderId");Ve(this,"_currentRenderPhase",null);Ve(this,"_asyncEffects",[]);Ve(this,"parent",null);this._renderId=`${Pot++}`,this.children=[],this.renderPhaseStates={};for(const t of Ix)this.renderPhaseStates[t]={initialized:!1,dirty:!1}}_markDirty(e){var n;this.renderPhaseStates[e].dirty=!0;const t=Ix.indexOf(e);for(let i=t+1;i<Ix.length;i++)this.renderPhaseStates[Ix[i]].dirty=!0;(n=this.parent)!=null&&n._markDirty&&this.parent._markDirty(e)}_queueAsyncEffect(e,t){const n={promise:t(),phase:this._currentRenderPhase,effectName:e,complete:!1};this._asyncEffects.push(n),"root"in this&&this.root&&this.root.emit("asyncEffect:start",{effectName:e,componentDisplayName:this.getString(),phase:n.phase}),n.promise.then(()=>{n.complete=!0,"root"in this&&this.root&&this.root.emit("asyncEffect:end",{effectName:e,componentDisplayName:this.getString(),phase:n.phase})}).catch(i=>{console.error(`Async effect error in ${n.phase} "${e}":
|
|
853
|
+
${i.stack}`),n.complete=!0,"root"in this&&this.root&&this.root.emit("asyncEffect:end",{effectName:e,componentDisplayName:this.getString(),phase:n.phase,error:i.toString()})})}_emitRenderLifecycleEvent(e,t){Tot(`${e}:${t} ${this.getString()}`);const n=`renderable:renderLifecycle:${e}:${t}`,i={renderId:this._renderId,componentDisplayName:this.getString(),type:n};"root"in this&&this.root&&(this.root.emit(n,i),this.root.emit("renderable:renderLifecycle:anyEvent",{...i,type:n}))}getString(){return this.constructor.name}_hasIncompleteAsyncEffects(){return this._asyncEffects.some(e=>!e.complete)}getCurrentRenderPhase(){return this._currentRenderPhase}getRenderGraph(){return{id:this._renderId,currentPhase:this._currentRenderPhase,renderPhaseStates:this.renderPhaseStates,shouldBeRemoved:this.shouldBeRemoved,children:this.children.map(e=>e.getRenderGraph())}}runRenderCycle(){for(const e of Ix)this.runRenderPhaseForChildren(e),this.runRenderPhase(e)}runRenderPhase(e){var o,s,l;this._currentRenderPhase=e;const t=this.renderPhaseStates[e],n=t.initialized,i=t.dirty;if(!n&&this.shouldBeRemoved)return;if(this.shouldBeRemoved&&n){this._emitRenderLifecycleEvent(e,"start"),(o=this==null?void 0:this[`remove${e}`])==null||o.call(this),t.initialized=!1,t.dirty=!1,this._emitRenderLifecycleEvent(e,"end");return}const a=Ix.indexOf(e)-1;if(a>=0){const c=Ix[a];if(this._asyncEffects.filter(u=>u.phase===c).some(u=>!u.complete))return}if(this._emitRenderLifecycleEvent(e,"start"),n){i&&((s=this==null?void 0:this[`update${e}`])==null||s.call(this),t.dirty=!1),this._emitRenderLifecycleEvent(e,"end");return}t.dirty=!1,(l=this==null?void 0:this[`doInitial${e}`])==null||l.call(this),t.initialized=!0,this._emitRenderLifecycleEvent(e,"end")}runRenderPhaseForChildren(e){for(const t of this.children)t.runRenderPhaseForChildren(e),t.runRenderPhase(e)}renderError(e){throw typeof e=="string"?new Error(e):new Error(JSON.stringify(e,null,2))}},i8={},e0e=r=>{const e=Object.fromEntries(Object.entries(r).map(([t,n])=>[t.toLowerCase(),n]));Object.assign(i8,r),Object.assign(i8,e)},Uot=class extends Error{constructor(e,t,n){let i;const o=Object.keys(n).filter(s=>s!=="_errors").map(s=>n[s]._errors[0]?`${s} (${n[s]._errors[0]})`:`${s} (${JSON.stringify(n[s])})`).join(", ");"name"in t?i=`Invalid props for ${e} "${t.name}": ${o}`:"footprint"in t&&typeof t.footprint=="string"?i=`Invalid props for ${e} (unnamed ${t.footprint} component): ${o}`:i=`Invalid props for ${e} (unnamed): ${o}`,super(i),this.componentName=e,this.originalProps=t,this.formattedError=n}};function bY(r,e){const t=e.match(/^#(\w+)/);if(t)return r.props.id===t[1];const n=e.match(/^\.(\w+)/);if(n)return r.isMatchingNameOrAlias(n[1]);let[i,...a]=e.split(/(?=[#.[])/);return i==="pin"&&(i="port"),i&&i!=="*"&&r.lowercaseComponentName!==i.toLowerCase()?!1:a.every(o=>{if(o.startsWith("#"))return r.props.id===o.slice(1);if(o.startsWith("."))return r.isMatchingNameOrAlias(o.slice(1));const s=o.match(/\[(\w+)=['"]?(.+?)['"]?\]/);if(!s)return!0;const[,l,c]=s;return r.props[l].toString()===c})}var SY={isTag:r=>!0,getParent:r=>r.parent,getChildren:r=>r.children,getName:r=>r.lowercaseComponentName,getAttributeValue:(r,e)=>{var t;if(e==="class"&&"getNameAndAliases"in r)return r.getNameAndAliases().join(" ");if(e==="name"&&((t=r._parsedProps)!=null&&t.name))return r._parsedProps.name;if(r._parsedProps&&e in r._parsedProps){const n=r._parsedProps[e];return typeof n=="string"?n:n!=null?String(n):null}return null},hasAttrib:(r,e)=>{var t;return e==="class"?!!((t=r._parsedProps)!=null&&t.name):r._parsedProps&&e in r._parsedProps},getSiblings:r=>r.parent?r.parent.children:[],prevElementSibling:r=>{if(!r.parent)return null;const e=r.parent.children,t=e.indexOf(r);return t>0?e[t-1]:null},getText:()=>"",removeSubsets:r=>r.filter((e,t)=>!r.some((n,i)=>t!==i&&n!==e&&n.getDescendants().includes(e))),existsOne:(r,e)=>e.some(r),findAll:(r,e)=>{const t=[],n=i=>{r(i)&&t.push(i);for(const a of i.children)n(a)};for(const i of e)n(i);return t},findOne:(r,e)=>{for(const t of e){if(r(t))return t;const n=t.children;if(n.length>0){const i=SY.findOne(r,n);if(i)return i}}return null},equals:(r,e)=>r._renderId===e._renderId,isHovered:r=>!1,isVisited:r=>!1,isActive:r=>!1},Fot={...SY,getChildren:r=>r.children.filter(e=>!e.isSubcircuit)},t0e={...SY,getChildren:r=>r.children.filter(e=>e.isSubcircuit)},n0e=r=>{if(/net\.[^\s>]*\./.test(r))throw new Error('Net names cannot contain a period, try using "sel.net..." to autocomplete with conventional net names, e.g. V3_3');if(/net\.[0-9]/.test(r))throw new Error('Net names cannot start with a number, try using a prefix like "VBUS1"');return r.replace(/ pin/g," port").replace(/ subcircuit\./g," group[isSubcircuit=true]").replace(/([^ ])\>([^ ])/g,"$1 > $2").replace(/(^|[ >])(?!pin\.)(?!port\.)(?!net\.)([A-Z][A-Za-z0-9_-]*)\.([A-Za-z0-9_-]+)/g,(e,t,n,i)=>{const a=/^\d+$/.test(i)?`pin${i}`:i;return`${t}.${n} > .${a}`}).trim()},QY={adapter:Fot,cacheResults:!0},Kv=class extends $pe{constructor(t){super(t);Ve(this,"parent",null);Ve(this,"children");Ve(this,"childrenPendingRemoval");Ve(this,"props");Ve(this,"_parsedProps");Ve(this,"externallyAddedAliases");Ve(this,"isPrimitiveContainer",!1);Ve(this,"source_group_id",null);Ve(this,"source_component_id",null);Ve(this,"schematic_component_id",null);Ve(this,"pcb_component_id",null);Ve(this,"cad_component_id",null);Ve(this,"_cachedSelectAllQueries",new Map);Ve(this,"_cachedSelectOneQueries",new Map);this.children=[],this.childrenPendingRemoval=[],this.props=t??{},this.externallyAddedAliases=[];const n=this.config.zodProps.safeParse(t??{});if(n.success)this._parsedProps=n.data;else throw new Uot(this.lowercaseComponentName,this.props,n.error.format())}get config(){return{componentName:"",zodProps:Vn({}).passthrough()}}get componentName(){return this.config.componentName}getInheritedProperty(t){var i;let n=this;for(;n;){if(n._parsedProps&&t in n._parsedProps)return n._parsedProps[t];n=n.parent}if((i=this.root)!=null&&i.platform&&t in this.root.platform)return this.root.platform[t]}get lowercaseComponentName(){return this.componentName.toLowerCase()}get isSubcircuit(){var t;return!!this.props.subcircuit||this.lowercaseComponentName==="group"&&((t=this==null?void 0:this.parent)==null?void 0:t.isRoot)}get isGroup(){return this.lowercaseComponentName==="group"}setProps(t){var a,o;const n=this.config.zodProps.parse({...this.props,...t}),i=this.props;this.props=n,this._parsedProps=this.config.zodProps.parse(t),this.onPropsChange({oldProps:i,newProps:n,changedProps:Object.keys(t)}),(o=(a=this.parent)==null?void 0:a.onChildChanged)==null||o.call(a,this)}computePcbPropsTransform(){const{_parsedProps:t}=this;return OA(Kd(t.pcbX??0,t.pcbY??0),j_((t.pcbRotation??0)*Math.PI/180))}_computePcbGlobalTransformBeforeLayout(){var i,a,o;const{_parsedProps:t}=this,n=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if(n&&this.props.pcbX===void 0&&this.props.pcbY===void 0)return OA(((i=this.parent)==null?void 0:i._computePcbGlobalTransformBeforeLayout())??By(),OA(Kd(n.x,n.y),j_((t.pcbRotation??0)*Math.PI/180)));if(this.isPcbPrimitive){const s=this.getPrimitiveContainer();if(s){const l=s._parsedProps.layer==="bottom",c=s._getGlobalPcbPositionBeforeLayout();if(l)return OA(Kd(c.x,c.y),W3(),Kd(-c.x,-c.y)),OA(((a=this.parent)==null?void 0:a._computePcbGlobalTransformBeforeLayout())??By(),W3(),this.computePcbPropsTransform())}}return OA(((o=this.parent)==null?void 0:o._computePcbGlobalTransformBeforeLayout())??By(),this.computePcbPropsTransform())}getPrimitiveContainer(){var t,n;return this.isPrimitiveContainer?this:((n=(t=this.parent)==null?void 0:t.getPrimitiveContainer)==null?void 0:n.call(t))??null}_getPcbCircuitJsonBounds(){return{center:{x:0,y:0},bounds:{left:0,top:0,right:0,bottom:0},width:0,height:0}}_getPcbPrimitiveFlippedHelpers(){const t=this.getPrimitiveContainer(),n=t?t._parsedProps.layer==="bottom":!1;return{isFlipped:n,maybeFlipLayer:a=>n?a==="top"?"bottom":"top":a}}_setPositionFromLayout(t){throw new Error(`_setPositionFromLayout not implemented for ${this.componentName}`)}computeSchematicPropsTransform(){const{_parsedProps:t}=this;return OA(Kd(t.schX??0,t.schY??0))}computeSchematicGlobalTransform(){var n,i;const t=this._getSchematicGlobalManualPlacementTransform(this);return t||OA(((i=(n=this.parent)==null?void 0:n.computeSchematicGlobalTransform)==null?void 0:i.call(n))??By(),this.computeSchematicPropsTransform())}_getSchematicSymbolName(){const{_parsedProps:t}=this,n=this.config.schematicSymbolName;let i=t.schRotation;if(i===void 0&&(i=0),i=i%360,i<0&&(i+=360),t.schRotation!==void 0&&i%90!==0)throw new Error(`Schematic rotation ${t.schRotation} is not supported for ${this.componentName}`);const a=`${n}_horz`,o=`${n}_vert`,s=`${n}_up`,l=`${n}_down`,c=`${n}_left`,A=`${n}_right`;if(A in dI&&i===0)return A;if(s in dI&&i===90)return s;if(c in dI&&i===180)return c;if(l in dI&&i===270)return l;if(a in dI&&(i===0||i===180))return a;if(o in dI&&(i===90||i===270))return o;if(n in dI)return n}_getSchematicSymbolNameOrThrow(){const t=this._getSchematicSymbolName();if(!t)throw new Error(`No schematic symbol found (given: "${this.config.schematicSymbolName}")`);return t}getSchematicSymbol(){const t=this._getSchematicSymbolName();return t?dI[t]??null:null}_getPcbManualPlacementForComponent(t){var o;if(!this.isSubcircuit)return null;const n=this.props.layout,i=this.props.manualEdits;if(!n&&!i)return null;const a=((o=n==null?void 0:n.manual_pcb_placement_config)==null?void 0:o.positions)||(i==null?void 0:i.pcb_placements);if(!a)return null;for(const s of a)if(n&&bY(t,s.selector)||t.props.name===s.selector)return si(this._computePcbGlobalTransformBeforeLayout(),s.center);return null}_getSchematicManualPlacementForComponent(t){if(!this.isSubcircuit)return null;const n=this.props.manualEdits;if(!n)return null;const i=n.schematic_placements;if(!i)return null;for(const a of i)if(bY(t,a.selector)||t.props.name===a.selector)return si(this.computeSchematicGlobalTransform(),a.center);return null}_getSchematicGlobalManualPlacementTransform(t){var i,a;const n=(i=this.getSubcircuit())==null?void 0:i._parsedProps.manualEdits;if(!n)return null;for(const o of n.schematic_placements??[])if((bY(t,o.selector)||t.props.name===o.selector)&&o.relative_to==="group_center")return OA(((a=this.parent)==null?void 0:a._computePcbGlobalTransformBeforeLayout())??By(),Kd(o.center.x,o.center.y));return null}_getGlobalPcbPositionBeforeLayout(){return si(this._computePcbGlobalTransformBeforeLayout(),{x:0,y:0})}_getGlobalSchematicPositionBeforeLayout(){return si(this.computeSchematicGlobalTransform(),{x:0,y:0})}get root(){var t;return((t=this.parent)==null?void 0:t.root)??null}onAddToParent(t){this.parent=t}onPropsChange(t){}onChildChanged(t){var n,i;(i=(n=this.parent)==null?void 0:n.onChildChanged)==null||i.call(n,t)}add(t){if(!t.onAddToParent)throw new Error(`Invalid JSX Element: Expected a React component but received "${JSON.stringify(t)}"`);t.onAddToParent(this),t.parent=this,this.children.push(t)}addAll(t){for(const n of t)this.add(n)}remove(t){this.children=this.children.filter(n=>n!==t),this.childrenPendingRemoval.push(t),t.shouldBeRemoved=!0}getSubcircuitSelector(){const t=this._parsedProps.name,n=t?`${this.lowercaseComponentName}.${t}`:this.lowercaseComponentName;return!this.parent||this.parent.isSubcircuit?n:`${this.parent.getSubcircuitSelector()} > ${n}`}getFullPathSelector(){var a,o;const t=this._parsedProps.name,n=t?`${this.lowercaseComponentName}.${t}`:this.lowercaseComponentName,i=(o=(a=this.parent)==null?void 0:a.getFullPathSelector)==null?void 0:o.call(a);return i?`${i} > ${n}`:n}getNameAndAliases(){return[this._parsedProps.name,...this._parsedProps.portHints??[]].filter(Boolean)}isMatchingNameOrAlias(t){return this.getNameAndAliases().includes(t)}isMatchingAnyOf(t){return this.getNameAndAliases().some(n=>t.map(i=>i.toString()).includes(n))}getPcbSize(){throw new Error(`getPcbSize not implemented for ${this.componentName}`)}doesSelectorMatch(t){const n=[this.componentName,this.lowercaseComponentName],i=[this._parsedProps.name].filter(Boolean),a=t.trim().split(/\> /)[0],o=a[0];return a.length>1?!1:!!(t==="*"||t[0]==="#"&&t.slice(1)===this.props.id||t[0]==="."&&i.includes(t.slice(1))||/^[a-zA-Z0-9_]/.test(o)&&n.includes(o))}getSubcircuit(){var n,i;if(this.isSubcircuit)return this;const t=(i=(n=this.parent)==null?void 0:n.getSubcircuit)==null?void 0:i.call(n);if(!t)throw new Error("Component is not inside an opaque group (no board?)");return t}getGroup(){var t,n;return this.isGroup?this:((n=(t=this.parent)==null?void 0:t.getGroup)==null?void 0:n.call(t))??null}doInitialOptimizeSelectorCache(){var n;if(!this.isSubcircuit)return;const t=this.selectAll("port");for(const i of t){const a=(n=i.parent)==null?void 0:n.getNameAndAliases(),o=i.getNameAndAliases();if(a)for(const s of a)for(const l of o){const c=[`.${s} > .${l}`,`.${s} .${l}`];for(const A of c){const u=this._cachedSelectAllQueries.get(A);u?u.push(i):this._cachedSelectAllQueries.set(A,[i])}}}for(const[i,a]of this._cachedSelectAllQueries.entries())a.length===1&&this._cachedSelectOneQueries.set(i,a[0])}selectAll(t){if(this._cachedSelectAllQueries.has(t))return this._cachedSelectAllQueries.get(t);const n=n0e(t),i=pP(n,this,QY);if(i.length>0)return this._cachedSelectAllQueries.set(t,i),i;const[a,...o]=n.split(" "),s=p9(a,this,{adapter:t0e});if(!s)return[];const l=s.selectAll(o.join(" "));return this._cachedSelectAllQueries.set(t,l),l}selectOne(t,n){if(this._cachedSelectOneQueries.has(t))return this._cachedSelectOneQueries.get(t);const i=n0e(t);n!=null&&n.port&&(n.type="port");let a=null;if(n!=null&&n.type&&(a=pP(i,this,QY).find(A=>A.lowercaseComponentName===n.type)),a??(a=p9(i,this,QY)),a)return this._cachedSelectOneQueries.set(t,a),a;const[o,...s]=i.split(" "),l=p9(o,this,{adapter:t0e});return l?(a=l.selectOne(s.join(" "),n),this._cachedSelectOneQueries.set(t,a),a):null}getAvailablePcbLayers(){var t,n;if(this.isPcbPrimitive){const{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers();return"layer"in this._parsedProps||this.componentName==="SmtPad"?[i(this._parsedProps.layer??"top")]:"layers"in this._parsedProps?this._parsedProps.layers:this.componentName==="PlatedHole"?((n=(t=this.root)==null?void 0:t._getBoard())==null?void 0:n.allLayers)??["top","bottom"]:[]}return[]}getDescendants(){const t=[];for(const n of this.children)t.push(n),t.push(...n.getDescendants());return t}getSelectableDescendants(){const t=[];for(const n of this.children)n.isSubcircuit?t.push(n):(t.push(n),t.push(...n.getSelectableDescendants()));return t}_getPinCount(){return 0}_getSchematicBoxDimensions(){return null}_getSchematicBoxComponentDimensions(){if(this.getSchematicSymbol()||!this.config.shouldRenderAsSchematicBox)return null;const{_parsedProps:t}=this;return{schWidth:t.schWidth,schHeight:t.schHeight}}renderError(t){var n;if(typeof t=="string")return super.renderError(t);(n=this.root)==null||n.db.pcb_placement_error.insert(t)}getString(){var a,o;const{lowercaseComponentName:t,_parsedProps:n,parent:i}=this;return(n==null?void 0:n.pinNumber)!==void 0&&((a=i==null?void 0:i.props)!=null&&a.name)&&(n!=null&&n.name)?`<${t}#${this._renderId}(pin:${n.pinNumber} .${i==null?void 0:i.props.name}>.${n.name}) />`:(o=i==null?void 0:i.props)!=null&&o.name&&(n!=null&&n.name)?`<${t}#${this._renderId}(.${i==null?void 0:i.props.name}>.${n==null?void 0:n.name}) />`:n!=null&&n.from&&(n!=null&&n.to)?`<${t}#${this._renderId}(from:${n.from} to:${n==null?void 0:n.to}) />`:n!=null&&n.name?`<${t}#${this._renderId} name=".${n==null?void 0:n.name}" />`:n!=null&&n.portHints?`<${t}#${this._renderId}(${n.portHints.map(s=>`.${s}`).join(", ")}) />`:`<${t}#${this._renderId} />`}get[Symbol.toStringTag](){return this.getString()}[Symbol.for("nodejs.util.inspect.custom")](){return this.getString()}},kot=class extends Kv{constructor(e,t){super(e),this._parsedProps={...e,error:t,type:e.type||"unknown",component_name:e.name,error_type:"source_failed_to_create_component_error",message:t instanceof Error?t.message:String(t),pcbX:e.pcbX,pcbY:e.pcbY,schX:e.schX,schY:e.schY}}get config(){return{componentName:"ErrorPlaceholder",zodProps:Vn({}).passthrough()}}doInitialSourceRender(){var e,t,n,i;if((e=this.root)!=null&&e.db){const a=this._getGlobalPcbPositionBeforeLayout(),o=this._getGlobalSchematicPositionBeforeLayout();this.root.db.source_failed_to_create_component_error.insert({component_name:this._parsedProps.component_name,message:((i=(n=(t=this._parsedProps.error)==null?void 0:t.formattedError)==null?void 0:n._errors)==null?void 0:i.join("; "))||this._parsedProps.message,pcb_center:a,schematic_center:o})}}};function Got(r,e){return new kot(r,e)}function Lot(r,e){const t=r;return t.__tsci={...e},r}var r0e={supportsMutation:!0,createInstance(r,e){const t=i8[r];if(!t)throw Object.keys(i8).length===0?new Error("No components registered in catalogue, did you forget to import lib/register-catalogue in your test file?"):new Error(`Unsupported component type (not registered in @tscircuit/core catalogue): "${r}" See CREATING_NEW_COMPONENTS.md`);try{return Lot(new t(e),{})}catch(n){return Got(e,n)}},createTextInstance(){return{}},appendInitialChild(r,e){r.add(e)},appendChild(r,e){r.add(e)},appendChildToContainer(r,e){r.add(e)},finalizeInitialChildren(){return!1},prepareUpdate(){return null},shouldSetTextContent(){return!1},getRootHostContext(){return{}},getChildHostContext(){return{}},prepareForCommit(){return null},resetAfterCommit(){},commitMount(){},commitUpdate(){},removeChild(){},clearContainer(){},supportsPersistence:!1,getPublicInstance(r){return r},preparePortalMount(r){throw new Error("Function not implemented.")},scheduleTimeout(r,e){throw new Error("Function not implemented.")},cancelTimeout(r){throw new Error("Function not implemented.")},noTimeout:void 0,isPrimaryRenderer:!1,getInstanceFromNode(r){throw new Error("Function not implemented.")},beforeActiveInstanceBlur(){throw new Error("Function not implemented.")},afterActiveInstanceBlur(){throw new Error("Function not implemented.")},prepareScopeUpdate:(r,e)=>{throw new Error("Function not implemented.")},getInstanceFromScope:r=>{throw new Error("Function not implemented.")},detachDeletedInstance:r=>{throw new Error("Function not implemented.")},getCurrentEventPriority:()=>A9.DefaultEventPriority,getCurrentUpdatePriority:()=>A9.DefaultEventPriority,resolveUpdatePriority:()=>A9.DefaultEventPriority,setCurrentUpdatePriority:()=>{},maySuspendCommit:()=>!1,supportsHydration:!1},yQ;Gh.version.startsWith("19.")?yQ=BAe(r0e):yQ=QAe(r0e);var i0e=r=>{const e={children:[],props:{name:"$root"},add(a){a.parent=this,this.children.push(a)},computePcbGlobalTransform(){return By()}},t=[],n=yQ.createContainer(e,0,null,!1,null,"tsci",a=>{console.log("Error in createContainer"),console.error(a),t.push(a)},null);if(Gh.version.startsWith("19.")?(yQ.updateContainerSync(r,n,null,()=>{}),yQ.flushSyncWork()):yQ.updateContainer(r,n,null,()=>{}),t.length>0)throw t[0];const i=yQ.getPublicRootInstance(n);return i||e.children[0]},yD=(r,e)=>{if(typeof r=="number")return r;if(r.startsWith("pin"))return Number(r.slice(3));if(!e)throw new Error(`No pin labels provided and pin number or label is not a number: "${r}"`);for(const t in e)if((Array.isArray(e[t])?e[t]:[e[t]]).includes(r))return Number(t.replace("pin",""));throw new Error(`No pin labels provided and pin number or label is not a number: "${r}"`)},Oot=(r,e)=>{if(!r)return;const t={},n={};for(const[i,a]of Object.entries(r)){const o=yD(i,e);n[o]={...n[o],...a}}for(const[i,a]of Object.entries(n)){const o=`pin${i}`;t[o]={bottom_margin:a.bottomMargin,left_margin:a.leftMargin,right_margin:a.rightMargin,top_margin:a.topMargin}}return t},zot=r=>{if(r){if("leftSide"in r||"rightSide"in r||"topSide"in r||"bottomSide"in r)return{left_side:r.leftSide,right_side:r.rightSide,top_side:r.topSide,bottom_side:r.bottomSide};if("leftPinCount"in r||"rightPinCount"in r||"topPinCount"in r||"bottomPinCount"in r)return{left_size:r.leftPinCount,right_size:r.rightPinCount,top_size:r.topPinCount,bottom_size:r.bottomPinCount};if("leftSize"in r||"rightSize"in r||"topSize"in r||"bottomSize"in r)return{left_size:r.leftSize,right_size:r.rightSize,top_size:r.topSize,bottom_size:r.bottomSize}}};function a0e(r){const e=[];for(let t=0;t<r.length-1;t++)e.push([r[t],r[t+1]]);return e}var Hot=Vn({name:He()}),o0e=class extends Kv{constructor(){super(...arguments);Ve(this,"source_net_id")}get config(){return{componentName:"Net",zodProps:Hot}}getPortSelector(){return`net.${this.props.name}`}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_net.insert({name:n.name,member_source_group_ids:[]});this.source_net_id=i.source_net_id}doInitialSourceParentAttachment(){const t=this.getSubcircuit();if(!t)return;const{db:n}=this.root;n.source_net.update(this.source_net_id,{subcircuit_id:t.subcircuit_id})}getAllConnectedPorts(){const t=this.getSubcircuit().selectAll("port"),n=[];for(const i of t){const a=i._getDirectlyConnectedTraces();for(const o of a)if(o._isExplicitlyConnectedToNet(this)){n.push(i);break}}return n}_getAllDirectlyConnectedTraces(){const t=this.getSubcircuit().selectAll("trace"),n=[];for(const i of t)i._isExplicitlyConnectedToNet(this)&&n.push(i);return n}doInitialPcbRouteNetIslands(){var s;if((s=this.root)!=null&&s.pcbDisabled||this.getSubcircuit()._parsedProps.routingDisabled||this.getSubcircuit()._getAutorouterConfig().groupMode!=="sequential-trace")return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getAllDirectlyConnectedTraces().filter(l=>{var c;return(((c=l._portsRoutedOnPcb)==null?void 0:c.length)??0)>0}),a=[];for(const l of i){const c=l._portsRoutedOnPcb,A=a.find(u=>c.some(d=>u.ports.includes(d)));if(!A){a.push({ports:[...c],traces:[l]});continue}A.traces.push(l),A.ports.push(...c)}if(a.length===0)return;const o=a0e(a);for(const[l,c]of o){const A=l.ports.map(Q=>Q._getGlobalPcbPositionBeforeLayout()),u=c.ports.map(Q=>Q._getGlobalPcbPositionBeforeLayout());let d=1/0,g=[-1,-1];for(let Q=0;Q<A.length;Q++){const P=A[Q];for(let z=0;z<u.length;z++){const O=u[z],V=Math.sqrt((P.x-O.x)**2+(P.y-O.y)**2);V<d&&(d=V,g=[Q,z])}}const m=l.ports[g[0]],C=c.ports[g[1]],E=t.toArray().filter(Q=>Q.type==="pcb_smtpad"||Q.type==="pcb_trace"||Q.type==="pcb_plated_hole"||Q.type==="pcb_hole"||Q.type==="source_port"||Q.type==="pcb_port"),{solution:_}=Jhe(E.concat([{type:"source_trace",source_trace_id:"__net_trace_tmp",connected_source_port_ids:[m.source_port_id,C.source_port_id]}])),x=_[0];if(!x){this.renderError({pcb_trace_error_id:"",pcb_trace_id:"__net_trace_tmp",pcb_component_ids:[m.pcb_component_id,C.pcb_component_id].filter(Boolean),pcb_port_ids:[m.pcb_port_id,C.pcb_port_id].filter(Boolean),type:"pcb_trace_error",error_type:"pcb_trace_error",message:`Failed to route net islands for "${this.getString()}"`,source_trace_id:"__net_trace_tmp"});return}t.pcb_trace.insert(x)}}renderError(t){var n;if(typeof t=="string")return super.renderError(t);(n=this.root)==null||n.db.pcb_trace_error.insert(t)}},s0e=(r,e)=>{for(const t of e)if(typeof t=="string"&&t.startsWith("net.")){if(/net\.[^\s>]*\./.test(t))throw new Error('Net names cannot contain a period, try using "sel.net..." to autocomplete with conventional net names, e.g. V3_3');if(/net\.[0-9]/.test(t))throw new Error('Net names cannot start with a number, try using a prefix like "VBUS1"');const n=r.getSubcircuit();if(!n.selectOne(t)){const i=new o0e({name:t.split("net.")[1]});n.add(i)}}},wY=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_smtpad_id",null);Ve(this,"matchedPort",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SmtPad",zodProps:Age}}getPcbSize(){const{_parsedProps:t}=this;if(t.shape==="circle")return{width:t.radius*2,height:t.radius*2};if(t.shape==="rect")return{width:t.width,height:t.height};throw new Error(`getPcbSize for shape "${t.shape}" not implemented for ${this.componentName}`)}doInitialPortMatching(){var n;const t=(n=this.getPrimitiveContainer())==null?void 0:n.selectAll("port");if(this.props.portHints){for(const i of t)if(i.isMatchingAnyOf(this.props.portHints)){this.matchedPort=i,i.registerMatch(this);return}}}doInitialPcbPrimitiveRender(){var g,m,C,E,_,x,Q,P,z,O;if((g=this.root)!=null&&g.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this;if(!n.portHints)return;const i=this.getPrimitiveContainer(),a=this.getSubcircuit(),o=this._getGlobalPcbPositionBeforeLayout();i==null||i._getGlobalPcbPositionBeforeLayout();const s=f9(this._computePcbGlobalTransformBeforeLayout()),l=Math.abs(s.rotation.angle*(180/Math.PI)-90)%180<.01,{maybeFlipLayer:c}=this._getPcbPrimitiveFlippedHelpers(),A=(i==null?void 0:i._parsedProps.pcbRotation)??0;let u=null;const d=((m=this.parent)==null?void 0:m.pcb_component_id)??((C=this.getPrimitiveContainer())==null?void 0:C.pcb_component_id);n.shape==="circle"?(u=t.pcb_smtpad.insert({pcb_component_id:d,pcb_port_id:(E=this.matchedPort)==null?void 0:E.pcb_port_id,layer:c(n.layer??"top"),shape:"circle",radius:n.radius,port_hints:n.portHints.map(V=>V.toString()),x:o.x,y:o.y,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0}),t.pcb_solder_paste.insert({layer:u.layer,shape:"circle",radius:u.radius*.7,x:u.x,y:u.y,pcb_component_id:u.pcb_component_id,pcb_smtpad_id:u.pcb_smtpad_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((_=this.getGroup())==null?void 0:_.pcb_group_id)??void 0})):n.shape==="rect"&&(u=A===0||l?t.pcb_smtpad.insert({pcb_component_id:d,pcb_port_id:(x=this.matchedPort)==null?void 0:x.pcb_port_id,layer:c(n.layer??"top"),shape:"rect",width:l?n.height:n.width,height:l?n.width:n.height,port_hints:n.portHints.map(V=>V.toString()),x:o.x,y:o.y,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((Q=this.getGroup())==null?void 0:Q.pcb_group_id)??void 0}):t.pcb_smtpad.insert({pcb_component_id:d,layer:c(n.layer??"top"),shape:"rotated_rect",width:n.width,height:n.height,x:o.x,y:o.y,ccw_rotation:A,port_hints:n.portHints.map(V=>V.toString()),subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((P=this.getGroup())==null?void 0:P.pcb_group_id)??void 0}),u.shape==="rect"&&t.pcb_solder_paste.insert({layer:c(n.layer??"top"),shape:"rect",width:u.width*.7,height:u.height*.7,x:u.x,y:u.y,pcb_component_id:u.pcb_component_id,pcb_smtpad_id:u.pcb_smtpad_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((z=this.getGroup())==null?void 0:z.pcb_group_id)??void 0}),u.shape==="rotated_rect"&&t.pcb_solder_paste.insert({layer:c(n.layer??"top"),shape:"rotated_rect",width:u.width*.7,height:u.height*.7,x:u.x,y:u.y,ccw_rotation:A,pcb_component_id:u.pcb_component_id,pcb_smtpad_id:u.pcb_smtpad_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((O=this.getGroup())==null?void 0:O.pcb_group_id)??void 0})),u&&(this.pcb_smtpad_id=u.pcb_smtpad_id)}doInitialPcbPortAttachment(){var n,i;if((n=this.root)!=null&&n.pcbDisabled)return;const{db:t}=this.root;t.pcb_smtpad.update(this.pcb_smtpad_id,{pcb_port_id:(i=this.matchedPort)==null?void 0:i.pcb_port_id})}_getPcbCircuitJsonBounds(){const{db:t}=this.root,n=t.pcb_smtpad.get(this.pcb_smtpad_id);if(n.shape==="rect")return{center:{x:n.x,y:n.y},bounds:{left:n.x-n.width/2,top:n.y+n.height/2,right:n.x+n.width/2,bottom:n.y-n.height/2},width:n.width,height:n.height};if(n.shape==="rotated_rect"){const i=n.ccw_rotation*Math.PI/180,a=Math.cos(i),o=Math.sin(i),s=n.width/2,l=n.height/2,c=Math.abs(s*a)+Math.abs(l*o),A=Math.abs(s*o)+Math.abs(l*a);return{center:{x:n.x,y:n.y},bounds:{left:n.x-c,right:n.x+c,top:n.y-A,bottom:n.y+A},width:c*2,height:A*2}}if(n.shape==="circle")return{center:{x:n.x,y:n.y},bounds:{left:n.x-n.radius,top:n.y-n.radius,right:n.x+n.radius,bottom:n.y+n.radius},width:n.radius*2,height:n.radius*2};throw new Error(`circuitJson bounds calculation not implemented for shape "${n.shape}"`)}_setPositionFromLayout(t){var a;const{db:n}=this.root;n.pcb_smtpad.update(this.pcb_smtpad_id,{x:t.x,y:t.y});const i=n.pcb_solder_paste.list().find(o=>o.pcb_smtpad_id===this.pcb_smtpad_id);n.pcb_solder_paste.update(i==null?void 0:i.pcb_solder_paste_id,{x:t.x,y:t.y}),(a=this.matchedPort)==null||a._setPositionFromLayout(t)}},l0e=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_silkscreen_path_id",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenPath",zodProps:Nge}}doInitialPcbPrimitiveRender(){var c,A,u;if((c=this.root)!=null&&c.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(n.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenPath. Must be "top" or "bottom".`);const o=this._computePcbGlobalTransformBeforeLayout(),s=this.getSubcircuit(),l=t.pcb_silkscreen_path.insert({pcb_component_id:(A=this.parent)==null?void 0:A.pcb_component_id,layer:a,route:n.route.map(d=>{const g=si(o,{x:d.x,y:d.y});return{...d,x:g.x,y:g.y}}),stroke_width:n.strokeWidth??.1,subcircuit_id:(s==null?void 0:s.subcircuit_id)??void 0,pcb_group_id:((u=this.getGroup())==null?void 0:u.pcb_group_id)??void 0});this.pcb_silkscreen_path_id=l.pcb_silkscreen_path_id}getPcbSize(){const{_parsedProps:t}=this;if(!t.route||t.route.length===0)return{width:0,height:0};let n=1/0,i=-1/0,a=1/0,o=-1/0;for(const s of t.route)n=Math.min(n,s.x),i=Math.max(i,s.x),a=Math.min(a,s.y),o=Math.max(o,s.y);return{width:i-n,height:o-a}}},Yot=Vn({route:Ga(ET),source_trace_id:He().optional()}),c0e=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_trace_id",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbTrace",zodProps:Yot}}doInitialPcbPrimitiveRender(){var A,u;if((A=this.root)!=null&&A.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getPrimitiveContainer(),a=this.getSubcircuit(),{maybeFlipLayer:o}=this._getPcbPrimitiveFlippedHelpers(),s=this._computePcbGlobalTransformBeforeLayout(),l=n.route.map(d=>{const{x:g,y:m,...C}=d,E=si(s,{x:g,y:m});return d.route_type==="wire"&&d.layer?{...E,...C,layer:o(d.layer)}:{...E,...C}}),c=t.pcb_trace.insert({pcb_component_id:i.pcb_component_id,source_trace_id:n.source_trace_id,route:l,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((u=this.getGroup())==null?void 0:u.pcb_group_id)??void 0});this.pcb_trace_id=c.pcb_trace_id}getPcbSize(){const{_parsedProps:t}=this;if(!t.route||t.route.length===0)return{width:0,height:0};let n=1/0,i=-1/0,a=1/0,o=-1/0;for(const s of t.route)n=Math.min(n,s.x),i=Math.max(i,s.x),a=Math.min(a,s.y),o=Math.max(o,s.y),s.route_type==="wire"&&(n=Math.min(n,s.x-s.width/2),i=Math.max(i,s.x+s.width/2),a=Math.min(a,s.y-s.width/2),o=Math.max(o,s.y+s.width/2));return n===1/0||i===-1/0||a===1/0||o===-1/0?{width:0,height:0}:{width:i-n,height:o-a}}},MY=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_plated_hole_id",null);Ve(this,"matchedPort",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PlatedHole",zodProps:tge}}getAvailablePcbLayers(){return["top","inner1","inner2","bottom"]}getPcbSize(){const{_parsedProps:t}=this;if(t.shape==="circle")return{width:t.outerDiameter,height:t.outerDiameter};if(t.shape==="oval"||t.shape==="pill")return{width:t.outerWidth,height:t.outerHeight};if(t.shape==="circular_hole_with_rect_pad")return{width:t.rectPadWidth,height:t.rectPadHeight};if(t.shape==="pill_hole_with_rect_pad")return{width:t.rectPadWidth,height:t.rectPadHeight};throw new Error(`getPcbSize for shape "${t.shape}" not implemented for ${this.componentName}`)}_getPcbCircuitJsonBounds(){const{db:t}=this.root,n=t.pcb_plated_hole.get(this.pcb_plated_hole_id),i=this.getPcbSize();return{center:{x:n.x,y:n.y},bounds:{left:n.x-i.width/2,top:n.y+i.height/2,right:n.x+i.width/2,bottom:n.y-i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(t){var i;const{db:n}=this.root;n.pcb_plated_hole.update(this.pcb_plated_hole_id,{x:t.x,y:t.y}),(i=this.matchedPort)==null||i._setPositionFromLayout(t)}doInitialPortMatching(){var n;const t=(n=this.getPrimitiveContainer())==null?void 0:n.selectAll("port");if(this.props.portHints){for(const i of t)if(i.isMatchingAnyOf(this.props.portHints)){this.matchedPort=i,i.registerMatch(this);return}}}doInitialPcbPrimitiveRender(){var s,l,c,A,u,d,g,m,C,E,_,x,Q,P,z;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalPcbPositionBeforeLayout(),a=((l=this.parent)==null?void 0:l.pcb_component_id)??((c=this.getPrimitiveContainer())==null?void 0:c.pcb_component_id),o=this.getSubcircuit();if(n.shape==="circle"){const O=t.pcb_plated_hole.insert({pcb_component_id:a,pcb_port_id:(A=this.matchedPort)==null?void 0:A.pcb_port_id,outer_diameter:n.outerDiameter,hole_diameter:n.holeDiameter,shape:"circle",port_hints:this.getNameAndAliases(),x:i.x,y:i.y,layers:["top","bottom"],subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((u=this.getGroup())==null?void 0:u.pcb_group_id)??void 0});this.pcb_plated_hole_id=O.pcb_plated_hole_id,t.pcb_solder_paste.insert({layer:"top",shape:"circle",radius:n.outerDiameter/2,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((d=this.getGroup())==null?void 0:d.pcb_group_id)??void 0}),t.pcb_solder_paste.insert({layer:"bottom",shape:"circle",radius:n.outerDiameter/2,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((g=this.getGroup())==null?void 0:g.pcb_group_id)??void 0})}else if(n.shape==="pill"||n.shape==="oval"){const O=t.pcb_plated_hole.insert({pcb_component_id:a,pcb_port_id:(m=this.matchedPort)==null?void 0:m.pcb_port_id,outer_width:n.outerWidth,outer_height:n.outerHeight,hole_width:n.holeWidth,hole_height:n.holeHeight,shape:n.shape,port_hints:this.getNameAndAliases(),x:i.x,y:i.y,layers:["top","bottom"],subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((C=this.getGroup())==null?void 0:C.pcb_group_id)??void 0});this.pcb_plated_hole_id=O.pcb_plated_hole_id,t.pcb_solder_paste.insert({layer:"top",shape:n.shape,width:n.outerWidth,height:n.outerHeight,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((E=this.getGroup())==null?void 0:E.pcb_group_id)??void 0}),t.pcb_solder_paste.insert({layer:"bottom",shape:n.shape,width:n.outerWidth,height:n.outerHeight,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((_=this.getGroup())==null?void 0:_.pcb_group_id)??void 0})}else if(n.shape==="circular_hole_with_rect_pad"){const O=t.pcb_plated_hole.insert({pcb_component_id:a,pcb_port_id:(x=this.matchedPort)==null?void 0:x.pcb_port_id,hole_diameter:n.holeDiameter,rect_pad_width:n.rectPadWidth,rect_pad_height:n.rectPadHeight,shape:"circular_hole_with_rect_pad",port_hints:this.getNameAndAliases(),x:i.x,y:i.y,layers:["top","bottom"],subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((Q=this.getGroup())==null?void 0:Q.pcb_group_id)??void 0});this.pcb_plated_hole_id=O.pcb_plated_hole_id}else if(n.shape==="pill_hole_with_rect_pad"){const O=t.pcb_plated_hole.insert({pcb_component_id:a,pcb_port_id:(P=this.matchedPort)==null?void 0:P.pcb_port_id,hole_width:n.holeWidth,hole_height:n.holeHeight,rect_pad_width:n.rectPadWidth,rect_pad_height:n.rectPadHeight,shape:"pill_hole_with_rect_pad",port_hints:this.getNameAndAliases(),x:i.x,y:i.y,layers:["top","bottom"],subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((z=this.getGroup())==null?void 0:z.pcb_group_id)??void 0});this.pcb_plated_hole_id=O.pcb_plated_hole_id}}doInitialPcbPortAttachment(){var n,i;if((n=this.root)!=null&&n.pcbDisabled)return;const{db:t}=this.root;t.pcb_plated_hole.update(this.pcb_plated_hole_id,{pcb_port_id:(i=this.matchedPort)==null?void 0:i.pcb_port_id})}},DY=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_keepout_id",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Keepout",zodProps:Qge}}doInitialPcbPrimitiveRender(){var c,A,u;if((c=this.root)!=null&&c.pcbDisabled)return;const t=this.getSubcircuit(),{db:n}=this.root,{_parsedProps:i}=this,a=this._getGlobalPcbPositionBeforeLayout(),o=f9(this._computePcbGlobalTransformBeforeLayout()),s=Math.abs(o.rotation.angle*(180/Math.PI)-90)%180<.01;let l=null;i.shape==="circle"?l=n.pcb_keepout.insert({layers:["top"],shape:"circle",radius:i.radius,center:{x:a.x,y:a.y},subcircuit_id:(t==null?void 0:t.subcircuit_id)??void 0,pcb_group_id:((A=t==null?void 0:t.getGroup())==null?void 0:A.pcb_group_id)??void 0}):i.shape==="rect"&&(l=n.pcb_keepout.insert({layers:["top"],shape:"rect",...s?{width:i.height,height:i.width}:{width:i.width,height:i.height},center:{x:a.x,y:a.y},subcircuit_id:(t==null?void 0:t.subcircuit_id)??void 0,pcb_group_id:((u=t==null?void 0:t.getGroup())==null?void 0:u.pcb_group_id)??void 0})),l&&(this.pcb_keepout_id=l.pcb_keepout_id)}},A0e=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_hole_id",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Hole",zodProps:uge}}getPcbSize(){const{_parsedProps:t}=this;return{width:t.diameter,height:t.diameter}}doInitialPcbPrimitiveRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getSubcircuit(),a=this._getGlobalPcbPositionBeforeLayout(),o=t.pcb_hole.insert({hole_shape:"circle",hole_diameter:n.diameter,x:a.x,y:a.y,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((l=i==null?void 0:i.getGroup())==null?void 0:l.pcb_group_id)??void 0});this.pcb_hole_id=o.pcb_hole_id}_getPcbCircuitJsonBounds(){const{db:t}=this.root,n=t.pcb_hole.get(this.pcb_hole_id),i=this.getPcbSize();return{center:{x:n.x,y:n.y},bounds:{left:n.x-i.width/2,top:n.y-i.height/2,right:n.x+i.width/2,bottom:n.y+i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(t){const{db:n}=this.root;n.pcb_hole.update(this.pcb_hole_id,{x:t.x,y:t.y})}},RY=class extends Kv{constructor(){super(...arguments);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenText",zodProps:Rge}}doInitialPcbPrimitiveRender(){var l,c;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getPrimitiveContainer(),a=this._getGlobalPcbPositionBeforeLayout(),{maybeFlipLayer:o}=this._getPcbPrimitiveFlippedHelpers(),s=this.getSubcircuit();t.pcb_silkscreen_text.insert({anchor_alignment:n.anchorAlignment,anchor_position:{x:a.x,y:a.y},font:n.font??"tscircuit2024",font_size:n.fontSize??1,layer:o(n.layer??"top"),text:n.text??"",ccw_rotation:n.pcbRotation,pcb_component_id:i.pcb_component_id,subcircuit_id:(s==null?void 0:s.subcircuit_id)??void 0,pcb_group_id:((c=this.getGroup())==null?void 0:c.pcb_group_id)??void 0})}getPcbSize(){const{_parsedProps:t}=this,n=t.fontSize??1,a=(t.text??"").length*n,o=n;return{width:a*n,height:o*n}}},Vot=({elm:r,pinLabels:e,layer:t,readableRotation:n,anchorAlignment:i})=>{const a=r.text.replace(/[{}]/g,"").toLowerCase();let o=a;if(Array.isArray(e)){const s=parseInt(a.replace(/[^\d]/g,""),10)-1;o=String(e[s]??a)}else typeof e=="object"&&(o=String(e[a]??a));return new RY({anchorAlignment:i||"center",text:o??a,layer:t||"top",fontSize:r.font_size+.2,pcbX:isNaN(r.anchor_position.x)?0:r.anchor_position.x,pcbY:r.anchor_position.y,pcbRotation:n??0})},Kot=(r,e)=>((-parseInt(r||"0",10)+(e??0))%360+360)%360,u0e=({componentName:r,componentRotation:e,footprint:t,pinLabels:n},i)=>{const a=[];for(const o of i)if(o.type==="pcb_smtpad"&&o.shape==="rect")a.push(new wY({pcbX:o.x,pcbY:o.y,layer:o.layer,shape:"rect",height:o.height,width:o.width,portHints:o.port_hints}));else if(o.type==="pcb_smtpad"&&o.shape==="circle")a.push(new wY({pcbX:o.x,pcbY:o.y,layer:o.layer,shape:"circle",radius:o.radius,portHints:o.port_hints}));else if(o.type==="pcb_silkscreen_path")a.push(new l0e({layer:o.layer,route:o.route,strokeWidth:o.stroke_width}));else if(o.type==="pcb_plated_hole")o.shape==="circle"?a.push(new MY({pcbX:o.x,pcbY:o.y,shape:"circle",holeDiameter:o.hole_diameter,outerDiameter:o.outer_diameter,portHints:o.port_hints})):o.shape==="circular_hole_with_rect_pad"&&a.push(new MY({pcbX:o.x,pcbY:o.y,shape:"circular_hole_with_rect_pad",holeDiameter:o.hole_diameter,rectPadHeight:o.rect_pad_height,rectPadWidth:o.rect_pad_width,portHints:o.port_hints}));else if(o.type==="pcb_keepout"&&o.shape==="circle")a.push(new DY({pcbX:o.center.x,pcbY:o.center.y,shape:"circle",radius:o.radius}));else if(o.type==="pcb_keepout"&&o.shape==="rect")a.push(new DY({pcbX:o.center.x,pcbY:o.center.y,shape:"rect",width:o.width,height:o.height}));else if(o.type==="pcb_hole"&&o.hole_shape==="circle")a.push(new A0e({pcbX:o.x,pcbY:o.y,diameter:o.hole_diameter}));else if(o.type==="pcb_silkscreen_text"){const s=Kot(e,o.ccw_rotation);t.includes("pinrow")&&o.text.includes("PIN")?a.push(Vot({elm:o,pinLabels:n,layer:o.layer,readableRotation:s,anchorAlignment:o.anchor_alignment})):a.push(new RY({anchorAlignment:o.anchor_alignment||"center",text:r,fontSize:o.font_size+.2,pcbX:isNaN(o.anchor_position.x)?0:o.anchor_position.x,pcbY:o.anchor_position.y,pcbRotation:s??0}))}else o.type==="pcb_trace"&&a.push(new c0e({route:o.route}));return a};function NY(r){let e=1/0,t=1/0,n=-1/0,i=-1/0,a=!1;for(const l of r)if(l.isPcbPrimitive&&!l.componentName.startsWith("Silkscreen")){const{x:c,y:A}=l._getGlobalPcbPositionBeforeLayout(),{width:u,height:d}=l.getPcbSize();e=Math.min(e,c-u/2),t=Math.min(t,A-d/2),n=Math.max(n,c+u/2),i=Math.max(i,A+d/2),a=!0}else if(l.children.length>0){const c=NY(l.children);(c.width>0||c.height>0)&&(e=Math.min(e,c.minX),t=Math.min(t,c.minY),n=Math.max(n,c.maxX),i=Math.max(i,c.maxY),a=!0)}if(!a)return{minX:0,minY:0,maxX:0,maxY:0,width:0,height:0};let o=n-e,s=i-t;return o<0&&(o=0),s<0&&(s=0),{minX:e,minY:t,maxX:n,maxY:i,width:o,height:s}}function Jot(r,e){const t=e.x-r.x,n=e.y-r.y;return Math.abs(t)>Math.abs(n)?t>=0?"right":"left":n>=0?"up":"down"}var jot=r=>{if(r.length<=1)return!0;const e=r.map(a=>{const o=a._getPcbCircuitJsonBounds();return{left:o.bounds.left,right:o.bounds.right,top:o.bounds.top,bottom:o.bounds.bottom}}),t=Array(e.length).fill(!1).map(()=>Array(e.length).fill(!1));for(let a=0;a<e.length;a++)for(let o=a+1;o<e.length;o++){const s=e[a],l=e[o];t[a][o]=t[o][a]=!(s.right<l.left||s.left>l.right||s.bottom>l.top||s.top<l.bottom)}const n=new Set,i=a=>{n.add(a);for(let o=0;o<e.length;o++)t[a][o]&&!n.has(o)&&i(o)};return i(0),n.size===e.length},Wot=r=>{if(r.length===0)throw new Error("Cannot get center of empty PCB primitives array");const e=r.map(i=>i._getPcbCircuitJsonBounds().center).filter(Boolean),t=e.reduce((i,a)=>i+a.x,0),n=e.reduce((i,a)=>i+a.y,0);return{x:t/e.length,y:n/e.length}},Zot=Vn({name:He().optional(),pinNumber:qr().optional(),aliases:Ga(He()).optional()}),yS=class extends Kv{constructor(t,n={}){if(!t.name&&t.pinNumber!==void 0&&(t.name=`pin${t.pinNumber}`),!t.name)throw new Error("Port must have a name or a pinNumber");super(t);Ve(this,"source_port_id",null);Ve(this,"pcb_port_id",null);Ve(this,"schematic_port_id",null);Ve(this,"schematicSymbolPortDef",null);Ve(this,"matchedComponents");Ve(this,"facingDirection",null);Ve(this,"originDescription",null);n.originDescription&&(this.originDescription=n.originDescription),this.matchedComponents=[]}get config(){return{componentName:"Port",zodProps:Zot}}_getGlobalPcbPositionBeforeLayout(){const t=this.matchedComponents.find(i=>i.isPcbPrimitive),n=this.parent;if(n&&!n.props.footprint)throw new Error(`${n.componentName} "${n.props.name}" does not have a footprint. Add a footprint prop, e.g. <${n.componentName.toLowerCase()} footprint="..." />`);if(!t)throw new Error(`Port ${this} has no matching PCB primitives. This often means the footprint's pads lack matching port hints.`);return(t==null?void 0:t._getGlobalPcbPositionBeforeLayout())??{x:0,y:0}}_getPcbCircuitJsonBounds(){if(!this.pcb_port_id)return super._getPcbCircuitJsonBounds();const{db:t}=this.root,n=t.pcb_port.get(this.pcb_port_id);return{center:{x:n.x,y:n.y},bounds:{left:0,top:0,right:0,bottom:0},width:0,height:0}}_getGlobalPcbPositionAfterLayout(){return this._getPcbCircuitJsonBounds().center}_getPortsInternallyConnectedToThisPort(){const t=this.parent;if(!t||!t._getInternallyConnectedPins)return[];const n=t._getInternallyConnectedPins();for(const i of n)if(i.some(a=>a===this))return i;return[]}_hasSchematicPort(){var i,a;if((i=this.parent)==null?void 0:i.getSchematicSymbol())return!!(this.schematicSymbolPortDef||this._getPortsInternallyConnectedToThisPort().some(s=>s.schematicSymbolPortDef));const n=(a=this==null?void 0:this.parent)==null?void 0:a._getSchematicBoxDimensions();return!!(n&&this.props.pinNumber!==void 0&&n.getPortPositionByPinNumber(this.props.pinNumber))}_getGlobalSchematicPositionBeforeLayout(){var i,a,o;const t=(i=this.parent)==null?void 0:i.getSchematicSymbol();if(t){let s=this.schematicSymbolPortDef;if(!s&&(s=((a=this._getPortsInternallyConnectedToThisPort().find(c=>c.schematicSymbolPortDef))==null?void 0:a.schematicSymbolPortDef)??null,!s))throw new Error(`Couldn't find schematicSymbolPortDef for port ${this.getString()}, searched internally connected ports and none had a schematicSymbolPortDef. Why are we trying to get the schematic position of this port?`);const l=OA(this.parent.computeSchematicGlobalTransform(),Kd(-t.center.x,-t.center.y));return si(l,s)}const n=(o=this==null?void 0:this.parent)==null?void 0:o._getSchematicBoxDimensions();if(n&&this.props.pinNumber!==void 0){const s=n.getPortPositionByPinNumber(this.props.pinNumber);if(!s)throw new Error(`Couldn't find position for schematic_port for port ${this.getString()} inside of the schematic box`);return si(this.parent.computeSchematicGlobalTransform(),s)}throw new Error(`Couldn't find position for schematic_port for port ${this.getString()}`)}_getGlobalSchematicPositionAfterLayout(){const{db:t}=this.root;if(!this.schematic_port_id)throw new Error(`Can't get schematic port position after layout for "${this.getString()}", no schematic_port_id`);const n=t.schematic_port.get(this.schematic_port_id);if(!n)throw new Error(`Schematic port not found when trying to get post-layout position: ${this.schematic_port_id}`);return n.center}registerMatch(t){this.matchedComponents.push(t)}getNameAndAliases(){const{_parsedProps:t}=this;return Array.from(new Set([...t.aliases??[],...t.name?[t.name]:[],...typeof t.pinNumber=="number"?[`pin${t.pinNumber}`,t.pinNumber.toString()]:[],...this.externallyAddedAliases??[]]))}isMatchingPort(t){return this.isMatchingAnyOf(t.getNameAndAliases())}getPortSelector(){var t;return`.${(t=this.parent)==null?void 0:t.props.name} > port.${this.props.name}`}getAvailablePcbLayers(){return Array.from(new Set(this.matchedComponents.flatMap(t=>t.getAvailablePcbLayers())))}_getDirectlyConnectedTraces(){return this.getSubcircuit().selectAll("trace").filter(i=>i._isExplicitlyConnectedToPort(this))}doInitialSourceRender(){var o,s;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getNameAndAliases(),a=t.source_port.insert({name:n.name,pin_number:n.pinNumber,port_hints:i,source_component_id:(o=this.parent)==null?void 0:o.source_component_id,subcircuit_id:(s=this.getSubcircuit())==null?void 0:s.subcircuit_id});this.source_port_id=a.source_port_id}doInitialSourceParentAttachment(){var n,i,a,o,s;const{db:t}=this.root;if(!((n=this.parent)!=null&&n.source_component_id))throw new Error(`${this.getString()} has no parent source component (parent: ${(i=this.parent)==null?void 0:i.getString()})`);t.source_port.update(this.source_port_id,{source_component_id:(a=this.parent)==null?void 0:a.source_component_id,subcircuit_id:(o=this.getSubcircuit())==null?void 0:o.subcircuit_id}),this.source_component_id=(s=this.parent)==null?void 0:s.source_component_id}doInitialPcbPortRender(){var o,s,l,c,A;if((o=this.root)!=null&&o.pcbDisabled)return;const{db:t}=this.root,{matchedComponents:n}=this;if(!((s=this.parent)!=null&&s.pcb_component_id))throw new Error(`${this.getString()} has no parent pcb component, cannot render pcb_port (parent: ${(l=this.parent)==null?void 0:l.getString()})`);const i=n.filter(u=>u.isPcbPrimitive);if(i.length===0)return;let a=null;if(i.length===1&&(a=i[0]._getPcbCircuitJsonBounds().center),i.length>1){if(!jot(i))throw new Error(`${this.getString()} has multiple non-overlapping pcb matches, unclear how to place pcb_port: ${i.map(u=>u.getString()).join(", ")}. (Note: tscircuit core does not currently allow you to specify internally connected pcb primitives with the same port hints, try giving them different port hints and specifying they are connected externally- or file an issue)`);a=Wot(i)}if(a){const u=this.getSubcircuit(),d=t.pcb_port.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layers:this.getAvailablePcbLayers(),subcircuit_id:(u==null?void 0:u.subcircuit_id)??void 0,pcb_group_id:((A=this.getGroup())==null?void 0:A.pcb_group_id)??void 0,...a,source_port_id:this.source_port_id});this.pcb_port_id=d.pcb_port_id}else{const u=i[0];throw new Error(`${u.getString()} does not have a center or _getGlobalPcbPositionBeforeLayout method (needed for pcb_port placement)`)}}doInitialSchematicPortRender(){var d;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getPrimitiveContainer();if(!i||!this._hasSchematicPort())return;const a=i._getGlobalSchematicPositionBeforeLayout(),o=this._getGlobalSchematicPositionBeforeLayout();let s=null;const l=i._getSchematicBoxDimensions();l&&n.pinNumber!==void 0&&(s=l.getPortPositionByPinNumber(n.pinNumber)),this.getSubcircuit().props._schDebugObjectsEnabled&&t.schematic_debug_object.insert({shape:"rect",center:o,size:{width:.1,height:.1},label:"obstacle"}),s!=null&&s.side?this.facingDirection={left:"left",right:"right",top:"up",bottom:"down"}[s.side]:this.facingDirection=Jot(a,o);const c=t.source_port.get(this.source_port_id);let A;for(const g of(c==null?void 0:c.port_hints)??[])g.match(/^(pin)?\d+$/)||g.match(/^(left|right)/)&&!(c!=null&&c.name.match(/^(left|right)/))||(A=g);const u=t.schematic_port.insert({schematic_component_id:(d=this.parent)==null?void 0:d.schematic_component_id,center:o,source_port_id:this.source_port_id,facing_direction:this.facingDirection,distance_from_component_edge:.4,side_of_component:s==null?void 0:s.side,pin_number:n.pinNumber,true_ccw_index:s==null?void 0:s.trueIndex,display_pin_label:A});this.schematic_port_id=u.schematic_port_id}_setPositionFromLayout(t){const{db:n}=this.root;this.pcb_port_id&&n.pcb_port.update(this.pcb_port_id,{x:t.x,y:t.y})}_hasMatchedPcbPrimitive(){return this.matchedComponents.some(t=>t.isPcbPrimitive)}},d0e=r=>{const e=r.find(t=>/^(pin)?\d+$/.test(t));return e?Number.parseInt(e.replace(/^pin/,"")):null};function vD(r,e){var a;const t=d0e(r);if(!t)return null;const i=[...r.filter(o=>o.toString()!==t.toString()&&o!==`pin${t}`),...((a=e==null?void 0:e.additionalAliases)==null?void 0:a[`pin${t}`])??[]];return new yS({pinNumber:t,aliases:i})}var qot=r=>{for(const e of["leftSide","rightSide","topSide","bottomSide"])if(e in r&&typeof r[e]=="number")throw new Error(`A number was specified for "${e}", you probably meant to use "size" not "side"`);return"leftSide"in r||"rightSide"in r||"topSide"in r||"bottomSide"in r},Xot=r=>{var a,o,s,l;if(qot(r))return{leftSize:((a=r.leftSide)==null?void 0:a.pins.length)??0,rightSize:((o=r.rightSide)==null?void 0:o.pins.length)??0,topSize:((s=r.topSide)==null?void 0:s.pins.length)??0,bottomSize:((l=r.bottomSide)==null?void 0:l.pins.length)??0};const{leftSize:e=0,rightSize:t=0,topSize:n=0,bottomSize:i=0}=r;return{leftSize:e,rightSize:t,topSize:n,bottomSize:i}};function f0e(r){return r.leftSide!==void 0}var $ot=r=>{var E,_,x,Q,P,z,O,V;const e=r.portDistanceFromEdge??.4;let t=r.schPortArrangement?Xot(r.schPortArrangement):null;const n={left:0,right:0,top:0,bottom:0};let i=r.pinCount??null;if(i===null)if(t)i=t.leftSize+t.rightSize+t.topSize;else throw new Error("Could not determine pin count for the schematic box");if(i&&!t){const j=Math.floor(i/2);t={leftSize:i-j,rightSize:j,topSize:0,bottomSize:0}}t||(t={leftSize:0,rightSize:0,topSize:0,bottomSize:0});const a=({side:j,sideIndex:q,truePinIndex:J})=>{var Be,pe,_e,ve;if(!r.schPortArrangement||!f0e(r.schPortArrangement))return J+1;const ce={left:"top-to-bottom",bottom:"left-to-right",right:"bottom-to-top",top:"right-to-left"}[j],oe=((pe=(Be=r.schPortArrangement)==null?void 0:Be[`${j}Side`])==null?void 0:pe.direction)??ce,de=(ve=(_e=r.schPortArrangement)==null?void 0:_e[`${j}Side`])==null?void 0:ve.pins;let Ie=q;return oe!==ce&&(Ie=de.length-q-1),yD(de[Ie],r.pinLabels)},o=[];let s=0,l=0;for(let j=0;j<t.leftSize;j++){const q=a({side:"left",sideIndex:j,truePinIndex:l}),J=((E=r.numericSchPinStyle)==null?void 0:E[`pin${q}`])??((_=r.numericSchPinStyle)==null?void 0:_[q]);J!=null&&J.topMargin&&(s+=J.topMargin),o.push({trueIndex:l,pinNumber:q,side:"left",distanceFromOrthogonalEdge:s}),J!=null&&J.bottomMargin&&(s+=J.bottomMargin),j===t.leftSize-1?n.left=s:s+=r.schPinSpacing,l++}s=0;for(let j=0;j<t.bottomSize;j++){const q=a({side:"bottom",sideIndex:j,truePinIndex:l}),J=((x=r.numericSchPinStyle)==null?void 0:x[`pin${q}`])??((Q=r.numericSchPinStyle)==null?void 0:Q[q]);J!=null&&J.leftMargin&&(s+=J.leftMargin),o.push({trueIndex:l,pinNumber:q,side:"bottom",distanceFromOrthogonalEdge:s}),J!=null&&J.rightMargin&&(s+=J.rightMargin),j===t.bottomSize-1?n.bottom=s:s+=r.schPinSpacing,l++}s=0;for(let j=0;j<t.rightSize;j++){const q=a({side:"right",sideIndex:j,truePinIndex:l}),J=((P=r.numericSchPinStyle)==null?void 0:P[`pin${q}`])??((z=r.numericSchPinStyle)==null?void 0:z[q]);J!=null&&J.bottomMargin&&(s+=J.bottomMargin),o.push({trueIndex:l,pinNumber:q,side:"right",distanceFromOrthogonalEdge:s}),J!=null&&J.topMargin&&(s+=J.topMargin),j===t.rightSize-1?n.right=s:s+=r.schPinSpacing,l++}s=0;for(let j=0;j<t.topSize;j++){const q=a({side:"top",sideIndex:j,truePinIndex:l}),J=((O=r.numericSchPinStyle)==null?void 0:O[`pin${q}`])??((V=r.numericSchPinStyle)==null?void 0:V[q]);J!=null&&J.rightMargin&&(s+=J.rightMargin),o.push({trueIndex:l,pinNumber:q,side:"top",distanceFromOrthogonalEdge:s}),J!=null&&J.leftMargin&&(s+=J.leftMargin),j===t.topSize-1?n.top=s:s+=r.schPinSpacing,l++}let c=r.schWidth;c||(c=Math.max(n.top+r.schPinSpacing*2,n.bottom+r.schPinSpacing*2));const A=r.pinLabels?Math.max(...Object.values(r.pinLabels).map(j=>j.length*.1)):0,u=A>0?1.1:0;c=Math.max(c,A+u);let d=r.schHeight;d||(d=Math.max(n.left+r.schPinSpacing*2,n.right+r.schPinSpacing*2));const g={left:{x:-c/2-e,y:n.left/2},bottom:{x:-n.bottom/2,y:-d/2-e},right:{x:c/2+e,y:-n.right/2},top:{x:n.top/2,y:d/2+e}},m={left:{x:0,y:-1},right:{x:0,y:1},top:{x:-1,y:0},bottom:{x:1,y:0}},C=o.map(j=>{const{distanceFromOrthogonalEdge:q,side:J}=j,ce=g[J],oe=m[J];return{x:ce.x+q*oe.x,y:ce.y+q*oe.y,...j}});return{getPortPositionByPinNumber(j){const q=C.find(J=>J.pinNumber.toString()===j.toString());return q||null},getSize(){return{width:c,height:d}},getSizeIncludingPins(){return{width:c+(t.leftSize||t.rightSize?.4:0),height:d+(t.topSize||t.bottomSize?.4:0)}},pinCount:i}},est=KI("tscircuit:core:footprint"),tst=class extends Kv{get config(){return{componentName:"Footprint",zodProps:hge}}doInitialPcbFootprintLayout(){var d,g,m,C,E;if((d=this.root)!=null&&d.pcbDisabled)return;const e=this.children.filter(_=>_.componentName==="Constraint");if(e.length===0)return;const{isFlipped:t}=this._getPcbPrimitiveFlippedHelpers(),n=_=>t&&"left"in _&&"right"in _?{..._,left:_.right,right:_.left}:_,i=e.flatMap(_=>_._getAllReferencedComponents().componentsWithSelectors).map(({component:_,selector:x,componentSelector:Q,edge:P})=>({component:_,selector:x,componentSelector:Q,edge:P,bounds:_._getPcbCircuitJsonBounds()}));if(i.some(_=>_.edge))throw new Error("edge constraints not implemented yet for footprint layout, contributions welcome!");function a(_){return i.find(({selector:x})=>x===_)}const o=new Gge,s={};function l(_){return _ in s||(s[_]=new SP(_),o.addEditVariable(s[_],JI.weak)),s[_]}for(const{selector:_,bounds:x}of i){const Q=l(`${_}_x`),P=l(`${_}_y`);o.suggestValue(Q,x.center.x),o.suggestValue(P,x.center.y)}for(const _ of e){const x=_._parsedProps;if("xDist"in x){const{xDist:Q,left:P,right:z,edgeToEdge:O,centerToCenter:V}=n(x),j=l(`${P}_x`),q=l(`${z}_x`),J=(g=a(P))==null?void 0:g.bounds,ce=(m=a(z))==null?void 0:m.bounds;if(V){const oe=new hI(q,[-1,j]);o.addConstraint(new CB(oe,Y1.Eq,x.xDist,JI.required))}else if(O){const oe=new hI(q,-ce.width/2,[-1,j],-J.width/2);o.addConstraint(new CB(oe,Y1.Eq,x.xDist,JI.required))}}else if("yDist"in x){const{yDist:Q,top:P,bottom:z,edgeToEdge:O,centerToCenter:V}=x,j=l(`${P}_y`),q=l(`${z}_y`),J=(C=a(P))==null?void 0:C.bounds,ce=(E=a(z))==null?void 0:E.bounds;if(V){const oe=new hI(j,[-1,q]);o.addConstraint(new CB(oe,Y1.Eq,x.yDist,JI.required))}else if(O){const oe=new hI(j,J.height/2,[-1,q],-ce.height/2);o.addConstraint(new CB(oe,Y1.Eq,x.yDist,JI.required))}}else if("sameY"in x){const{for:Q}=x;if(Q.length<2)continue;const P=Q.map(O=>l(`${O}_y`)),z=new hI(...P.slice(1));o.addConstraint(new CB(z,Y1.Eq,P[0],JI.required))}else if("sameX"in x){const{for:Q}=x;if(Q.length<2)continue;const P=Q.map(O=>l(`${O}_x`)),z=new hI(...P.slice(1));o.addConstraint(new CB(z,Y1.Eq,P[0],JI.required))}}o.updateVariables(),est.enabled&&(console.log("Solution to layout constraints:"),console.table(Object.entries(s).map(([_,x])=>({var:_,val:x.value()}))));const c={left:1/0,right:-1/0,top:-1/0,bottom:1/0};for(const{selector:_,bounds:{width:x,height:Q}}of i){const P=l(`${_}_x`),z=l(`${_}_y`),O=P.value()-x/2,V=P.value()+x/2,j=z.value()+Q/2,q=z.value()-Q/2;c.left=Math.min(c.left,O),c.right=Math.max(c.right,V),c.top=Math.max(c.top,j),c.bottom=Math.min(c.bottom,q)}const A={x:-(c.right+c.left)/2,y:-(c.top+c.bottom)/2},u=this.getPrimitiveContainer()._getGlobalPcbPositionBeforeLayout();A.x+=u.x,A.y+=u.y;for(const{component:_,selector:x}of i){const Q=l(`${x}_x`),P=l(`${x}_y`);_._setPositionFromLayout({x:Q.value()+A.x,y:P.value()+A.y})}}},nst=(r,e)=>{if(!r)return;const t={};for(const[n,i]of Object.entries(r)){const a=yD(n,e),o={leftMargin:i.marginLeft??i.leftMargin,rightMargin:i.marginRight??i.rightMargin,topMargin:i.marginTop??i.topMargin,bottomMargin:i.marginBottom??i.bottomMargin};t[`pin${a}`]={...t[`pin${a}`],...o}}return t},h0e=class{constructor({input:e}){Ve(this,"input");this.input=e}solveAndMapToTraces(){const e=[];for(const t of this.input.connections){if(t.pointsToConnect.length!==2)continue;const[n,i]=t.pointsToConnect,a={type:"pcb_trace",pcb_trace_id:"",connection_name:t.name,route:[{route_type:"wire",x:n.x,y:n.y,layer:"top",width:.1},{route_type:"wire",x:i.x,y:i.y,layer:"top",width:.1}]};e.push(a)}return e}},rst=r=>{const e=Math.min(...r.map(a=>a.center.x)),t=Math.max(...r.map(a=>a.center.x)),n=Math.min(...r.map(a=>a.center.y)),i=Math.max(...r.map(a=>a.center.y));return{minX:e,maxX:t,minY:n,maxY:i}},g0e=["top","bottom","inner1","inner2"],a8=(r,e=[])=>{var s;const t=[];if(e.length===0){const l=r[0].layers;for(const c of l)t.push(...a8(r.slice(1),[c]));return t}if(r.length===0)return[];const n=r[0],i=n.via||n.optional_via,a=e[e.length-1];if(r.length===1){const l=n;return l.layers&&i?l.layers.map(c=>({layer_path:[...e,c]})):(s=l.layers)!=null&&s.includes(a)?[{layer_path:[...e,a]}]:[]}if(!i)return n.layers&&!n.layers.includes(a)?[]:a8(r.slice(1),e.concat([a]));const o=(n.optional_via?g0e:g0e.filter(l=>l!==a)).filter(l=>{var c;return!n.layers||((c=n.layers)==null?void 0:c.includes(l))});for(const l of o)t.push(...a8(r.slice(1),e.concat(l)));return t};function p0e(r){const e={x:r.to.x-r.from.x,y:r.to.y-r.from.y},t=Math.abs(e.x),n=Math.abs(e.y);return t>n?e.x>0?"right":"left":e.y>0?"down":"up"}function D9(r,e){return Math.hypot(r.x-e.x,r.y-e.y)}var ist=r=>{if(r.length===1)return r[0];if(r.some(l=>l.length===0))throw new Error("Cannot merge routes with zero length");const e=[],t=r[0][0],n=r[0][r[0].length-1],i=r[1][0],a=r[1][r[1].length-1],o=Math.min(D9(t,i),D9(t,a)),s=Math.min(D9(n,i),D9(n,a));o<s?e.push(...r[0].reverse()):e.push(...r[0]);for(let l=1;l<r.length;l++){const c=e[e.length-1],A=r[l],u=A[0],d=A[A.length-1],g=D9(c,u),m=D9(c,d);g<m?e.push(...A):e.push(...A.reverse())}for(let l=1;l<e.length-1;l++){const c=e[l-1],A=e[l];c.route_type==="wire"&&A.route_type==="wire"&&c.layer!==A.layer&&e.splice(l,0,{x:c.x,y:c.y,from_layer:c.layer,to_layer:A.layer,route_type:"via"})}return e},ast=(r,e)=>{const t="_getGlobalPcbPositionBeforeLayout"in r?r._getGlobalPcbPositionBeforeLayout():r,n="_getGlobalPcbPositionBeforeLayout"in e?e._getGlobalPcbPositionBeforeLayout():e;return Math.sqrt((t.x-n.x)**2+(t.y-n.y)**2)};function ost(r,e){if(e.length===0)throw new Error("No candidates given to getClosest method");let t=e[0],n=1/0;for(const i of e){const a=ast(r,i);a<n&&(t=i,n=a)}return t}var sst=(r,e)=>{let t=0;t+=r.length??0,t+=e.filter(n=>n.is_crossing).length;for(let n=1;n<e.length;n++){const i=e[n-1],a=e[n],o=Math.abs(i.from.x-i.to.x)<.01,s=Math.abs(a.from.x-a.to.x)<.01;o!==s&&t++}return t},TY=r=>({up:"bottom",down:"top",left:"right",right:"left"})[r]??null,PY=({firstEdge:r,firstEdgePort:e,firstDominantDirection:t,lastEdge:n,lastEdgePort:i,lastDominantDirection:a})=>{if(r&&e)return PY({lastEdge:{from:r.to,to:r.from},lastEdgePort:e,lastDominantDirection:t}).reverse().map(s=>({from:s.to,to:s.from}));let o=[];if(n&&i){const s={x:n.to.x,y:n.to.y};a==="left"||a==="right"?(s.x=i.position.x,o.push({from:n.to,to:{...s}}),o.push({from:s,to:{...i.position}})):(s.y=i.position.y,o.push({from:n.to,to:{...s}}),o.push({from:s,to:{...i.position}}))}return o=o.filter(s=>px(s.from,s.to)>.01),o};function lst(r){try{return[r(),null]}catch(e){return[null,e]}}function cst(r){let e=0;for(let t=0;t<r.length;t++){const n=r[t];if(n.route_type==="wire"){const i=r[t+1];if(i){const a=i.x-n.x,o=i.y-n.y;e+=Math.sqrt(a*a+o*o)}}else n.route_type==="via"&&(e+=1.6)}return e}var o8=({db:r,source_trace_id:e,sameNetOnly:t,differentNetOnly:n})=>{!t&&!n&&(n=!0);const i=r.source_trace.get(e),a=[];for(const o of r.schematic_trace.list()){if(o.source_trace_id===e)continue;const s=r.source_trace.get(o.source_trace_id),l=(s==null?void 0:s.subcircuit_connectivity_map_key)===i.subcircuit_connectivity_map_key;n&&l||t&&!l||a.push(o)}return a},m0e=({edges:r,otherEdges:e})=>{const t=[...r];for(let n=0;n<t.length;n++){if(n>2e3)throw new Error("Over 2000 iterations spent inside createSchematicTraceCrossingSegments, you have triggered an infinite loop, please report this!");const i=t[n],a=Math.abs(i.from.x-i.to.x)<.01?"vertical":i.from.y===i.to.y?"horizontal":"not-orthogonal";if(a==="not-orthogonal")continue;const o=[];for(const C of e){const E=C.from.x===C.to.x?"vertical":C.from.y===C.to.y?"horizontal":"not-orthogonal";if(E==="not-orthogonal"||a===E)continue;if(MP([i.from,i.to],[C.from,C.to],{lineThickness:.01})){const x=a==="vertical"?i.from.x:C.from.x,Q=a==="vertical"?C.from.y:i.from.y,P={x,y:Q};o.push({otherEdge:C,crossingPoint:P,distanceFromEdgeFrom:px(i.from,P)})}}if(o.length===0)continue;let s=o[0];for(const C of o)C.distanceFromEdgeFrom<s.distanceFromEdgeFrom&&(s=C);const l=s.crossingPoint,c=.075;if(l.x===i.from.x&&l.y===i.from.y)continue;const A=Oge(i.from,l),u={x:l.x-A.x*c/2,y:l.y-A.y*c/2},d={x:l.x+A.x*c/2,y:l.y+A.y*c/2},g=px(d,i.to)<c,m=[{from:i.from,to:u},{from:u,to:d,is_crossing:!0},{from:d,to:i.to}];t.splice(n,1,...m),n+=m.length-2,g&&n++}return t},Ast=(r,e)=>{if(r.from.x===r.to.x&&e.from.x===e.to.x)return null;if(r.from.x===r.to.x){const A=r.from.x,u=(e.to.y-e.from.y)/(e.to.x-e.from.x),d=e.from.y-u*e.from.x,g=u*A+d;return A>=Math.min(e.from.x,e.to.x)&&A<=Math.max(e.from.x,e.to.x)&&g>=Math.min(e.from.y,e.to.y)&&g<=Math.max(e.from.y,e.to.y)?{x:A,y:g}:null}if(e.from.x===e.to.x){const A=e.from.x,u=(r.to.y-r.from.y)/(r.to.x-r.from.x),d=r.from.y-u*r.from.x,g=u*A+d;return A>=Math.min(r.from.x,r.to.x)&&A<=Math.max(r.from.x,r.to.x)&&g>=Math.min(r.from.y,r.to.y)&&g<=Math.max(r.from.y,r.to.y)?{x:A,y:g}:null}const t=(r.to.y-r.from.y)/(r.to.x-r.from.x),n=r.from.y-t*r.from.x,i=(e.to.y-e.from.y)/(e.to.x-e.from.x),a=e.from.y-i*e.from.x;if(t===i)return null;const o=(a-n)/(t-i),s=t*o+n,l=o>=Math.min(r.from.x,r.to.x)&&o<=Math.max(r.from.x,r.to.x)&&s>=Math.min(r.from.y,r.to.y)&&s<=Math.max(r.from.y,r.to.y),c=o>=Math.min(e.from.x,e.to.x)&&o<=Math.max(e.from.x,e.to.x)&&s>=Math.min(e.from.y,e.to.y)&&s<=Math.max(e.from.y,e.to.y);return l&&c?{x:o,y:s}:null},y0e=({edges:r,db:e,source_trace_id:t})=>{const n=o8({db:e,source_trace_id:t,sameNetOnly:!0}).flatMap(i=>i.edges);for(const i of r)for(const a of n){const o=Ast(i,a);if(o)return`${o.x}${o.y}`,[{x:o.x,y:o.y}]}return[]},ust=(r,{db:e})=>{const t=r.map(n=>{const i=e.source_port.get(n.source_port_id);if(!(i!=null&&i.source_component_id))return null;const a=e.source_component.get(i.source_component_id);return(a==null?void 0:a.ftype)==="simple_capacitor"?a.max_decoupling_trace_length:null}).filter(n=>n!==null);if(t.length!==0)return Math.min(...t)};function dst(r){var a,o,s,l,c,A,u,d,g;let e=1/0,t=1/0,n=-1/0,i=-1/0;for(const m of r){let C,E,_,x;m.type==="schematic_component"?(C=(a=m.center)==null?void 0:a.x,E=(o=m.center)==null?void 0:o.y,_=(s=m.size)==null?void 0:s.width,x=(l=m.size)==null?void 0:l.height):m.type==="schematic_box"?(C=m.x,E=m.y,_=m.width,x=m.height):m.type==="schematic_port"?(C=(c=m.center)==null?void 0:c.x,E=(A=m.center)==null?void 0:A.y,_=.2,x=.2):m.type==="schematic_text"&&(C=(u=m.position)==null?void 0:u.x,E=(d=m.position)==null?void 0:d.y,_=(((g=m.text)==null?void 0:g.length)??0)*.1,x=.2),typeof C=="number"&&typeof E=="number"&&typeof _=="number"&&typeof x=="number"&&(e=Math.min(e,C-_/2),n=Math.max(n,C+_/2),t=Math.min(t,E-x/2),i=Math.max(i,E+x/2))}return{minX:e,maxX:n,minY:t,maxY:i}}function fst(r,e={}){const{minX:t,maxX:n,minY:i,maxY:a}=r,o=e.padding??1;if(!isFinite(t)||!isFinite(n)||!isFinite(i)||!isFinite(a))return[];const s=t-o,l=n+o,c=a+o,A=i-o,u=.01;return[{type:"rect",layers:["top"],center:{x:(s+l)/2,y:c},width:l-s,height:u,connectedTo:[]},{type:"rect",layers:["top"],center:{x:(s+l)/2,y:A},width:l-s,height:u,connectedTo:[]},{type:"rect",layers:["top"],center:{x:s,y:(c+A)/2},width:u,height:c-A,connectedTo:[]},{type:"rect",layers:["top"],center:{x:l,y:(c+A)/2},width:u,height:c-A,connectedTo:[]}]}var hst=r=>{var o;const e=r.root.db,t=r._findConnectedPorts().ports??[],n=new Set(t.map(s=>s.schematic_port_id)),i=[];for(const s of e.toArray()){if(s.type==="schematic_component"){const l=!!s.symbol_name,c=s.size.width>s.size.height?"horz":"vert";i.push({type:"rect",layers:["top"],center:s.center,width:s.size.width+(l&&c==="horz"?-.5:0),height:s.size.height+(l&&c==="vert"?-.5:0),connectedTo:[]})}if(s.type==="schematic_port"){if(n.has(s.schematic_port_id))continue;const l=s.facing_direction?zge(s.facing_direction):{x:0,y:0};i.push({type:"rect",layers:["top"],center:{x:s.center.x-l.x*.1,y:s.center.y-l.y*.1},width:.1+Math.abs(l.x)*.3,height:.1+Math.abs(l.y)*.3,connectedTo:[]})}s.type==="schematic_text"&&i.push({type:"rect",layers:["top"],center:s.position,width:(((o=s.text)==null?void 0:o.length)??0)*.1,height:.2,connectedTo:[]}),s.type==="schematic_box"&&i.push({type:"rect",layers:["top"],center:{x:s.x,y:s.y},width:s.width,height:s.height,connectedTo:[]})}const a=dst(e.toArray());return i.push(...fst(a,{padding:1})),i};function gst({ports:r,nets:e}){var t,n,i;if(r.length>=2)return`${(t=r[0])==null?void 0:t.selector} to ${(n=r[1])==null?void 0:n.selector}`;if(r.length===1&&e.length===1)return`${(i=r[0])==null?void 0:i.selector} to net.${e[0]._parsedProps.name}`}var pst=({edges:r,db:e,source_trace_id:t})=>{e.source_trace.get(t);const n=o8({db:e,source_trace_id:t,differentNetOnly:!0}).flatMap(a=>a.edges),i=a=>{const{from:o,to:s}=a;return o.x===s.x?"vertical":"horizontal"};for(const a of r){const o=i(a),s=()=>n.find(c=>i(c)===o&&MP([a.from,a.to],[c.from,c.to],{lineThickness:.05}));let l=s();for(;l;)o==="horizontal"?(a.from.y+=.1,a.to.y+=.1):(a.from.x+=.1,a.to.x+=.1),l=s()}},mst=(r,{db:e})=>{const t=e.pcb_board.list()[0];if(t.outline){const l=t.outline,c=(A,u)=>{let d=!1;for(let g=0,m=u.length-1;g<u.length;m=g++){const C=u[g].x,E=u[g].y,_=u[m].x,x=u[m].y;E>A.y!=x>A.y&&A.x<(_-C)*(A.y-E)/(x-E)+C&&(d=!d)}return d};return r.some(A=>!c(A,l))}const n=t.width,i=t.height,a=t.center.x,o=t.center.y;return r.some(l=>l.x<a-n/2||l.y<o-i/2||l.x>a+n/2||l.y>o+i/2)},s8=r=>({...r._getGlobalPcbPositionAfterLayout(),layers:r.getAvailablePcbLayers()}),vS=class extends Kv{constructor(t){super(t);Ve(this,"source_trace_id",null);Ve(this,"pcb_trace_id",null);Ve(this,"schematic_trace_id",null);Ve(this,"_portsRoutedOnPcb");Ve(this,"subcircuit_connectivity_map_key",null);Ve(this,"_traceConnectionHash",null);this._portsRoutedOnPcb=[]}get config(){return{zodProps:fge,componentName:"Trace"}}_getTracePortOrNetSelectorListFromProps(){return"from"in this.props&&"to"in this.props?[typeof this.props.from=="string"?this.props.from:this.props.from.getPortSelector(),typeof this.props.to=="string"?this.props.to:this.props.to.getPortSelector()]:"path"in this.props?this.props.path.map(t=>typeof t=="string"?t:t.getPortSelector()):[]}getTracePortPathSelectors(){return this._getTracePortOrNetSelectorListFromProps().filter(t=>!t.includes("net."))}getTracePathNetSelectors(){return this._getTracePortOrNetSelectorListFromProps().filter(t=>t.includes("net."))}_findConnectedPorts(){const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i)throw new Error("Trace has no parent");const o=this.getTracePortPathSelectors().map(s=>({selector:s,port:this.getSubcircuit().selectOne(s,{type:"port"})??null}));for(const{selector:s,port:l}of o)if(!l){const c=s.replace(/(\> )?[^ ]+$/,""),A=this.getSubcircuit().selectOne(c);A?this.renderError(`Could not find port for selector "${s}" (did you forget to include the pin name?)
|
|
854
|
+
searched component ${A.getString()}, which has ports: ${A.children.filter(u=>u.componentName==="Port").map(u=>`${u.getString()}(${u.getNameAndAliases().join(",")})`).join(" & ")}`):this.renderError(`Could not find port for selector "${s}"`)}return o.some(s=>!s.port)?{allPortsFound:!1}:{allPortsFound:!0,portsWithSelectors:o,ports:o.map(({port:s})=>s)}}_findConnectedNets(){const t=this.getTracePathNetSelectors().map(i=>({selector:i,net:this.getSubcircuit().selectOne(i,{type:"net"})})),n=t.filter(i=>!i.net);return n.length>0&&this.renderError(`Could not find net for selector "${n[0].selector}" inside ${this}`),{netsWithSelectors:t,nets:t.map(i=>i.net)}}_getAllTracesConnectedToSameNet(){const t=this.getSubcircuit().selectAll("trace"),n=this._findConnectedNets().nets,i=this._findConnectedPorts().ports??[];return t.filter(a=>{if(a===this)return!1;const o=a._findConnectedNets().nets,s=a._findConnectedPorts().ports??[];return o.some(l=>n.includes(l))||s.some(l=>i.includes(l))})}_isExplicitlyConnectedToPort(t){const{allPortsFound:n,portsWithSelectors:i}=this._findConnectedPorts();return n?i.map(o=>o.port).includes(t):!1}_isExplicitlyConnectedToNet(t){return this._findConnectedNets().nets.includes(t)}doInitialCreateNetsFromProps(){s0e(this,this.getTracePathNetSelectors())}_computeTraceConnectionHash(){const{allPortsFound:t,ports:n}=this._findConnectedPorts();return!t||!n?null:[...n].sort((o,s)=>(o.pcb_port_id||"").localeCompare(s.pcb_port_id||"")).map(o=>o.pcb_port_id).join(",")}doInitialSourceTraceRender(){var d;const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i){this.renderError("Trace has no parent");return}const{allPortsFound:a,portsWithSelectors:o}=this._findConnectedPorts();if(!a)return;this._traceConnectionHash=this._computeTraceConnectionHash();const l=t.source_trace.list().find(g=>g.subcircuit_connectivity_map_key===this.subcircuit_connectivity_map_key&&g.connected_source_port_ids.sort().join(",")===this._traceConnectionHash);if(l){this.source_trace_id=l.source_trace_id;return}const c=this._findConnectedNets().nets,A=gst({ports:o,nets:c}),u=t.source_trace.insert({connected_source_port_ids:o.map(g=>g.port.source_port_id),connected_source_net_ids:c.map(g=>g.source_net_id),subcircuit_id:(d=this.getSubcircuit())==null?void 0:d.subcircuit_id,max_length:ust(o.map(g=>g.port),{db:t})??n.maxLength,display_name:A,min_trace_thickness:n.thickness});this.source_trace_id=u.source_trace_id}_insertErrorIfTraceIsOutsideBoard(t,n){const{db:i}=this.root;mst(t,{db:i})&&i.pcb_trace_error.insert({error_type:"pcb_trace_error",source_trace_id:this.source_trace_id,message:`Trace ${this.getString()} routed outside the board boundaries.`,pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[],pcb_port_ids:n.map(o=>o.pcb_port_id)})}doInitialPcbTraceRender(){var q,J,ce,oe;if((q=this.root)!=null&&q.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n,parent:i}=this,a=this.getSubcircuit();if(!i)throw new Error("Trace has no parent");if(a._parsedProps.routingDisabled)return;const o=(J=a._parsedProps.pcbRouteCache)==null?void 0:J.pcbTraces;if(o){const de=t.pcb_trace.insert({route:o.flatMap(Ie=>Ie.route),source_trace_id:this.source_trace_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((ce=this.getGroup())==null?void 0:ce.pcb_group_id)??void 0});this.pcb_trace_id=de.pcb_trace_id;return}if(!a._shouldUseTraceByTraceRouting())return;const{allPortsFound:s,ports:l}=this._findConnectedPorts();if(!s)return;const c=[];for(const de of l)de._hasMatchedPcbPrimitive()||c.push(de);if(c.length>0){t.pcb_trace_error.insert({error_type:"pcb_trace_error",source_trace_id:this.source_trace_id,message:`Some ports did not have a matching PCB primitive (e.g. a pad or plated hole), this can happen if a footprint is missing. As a result, ${this} wasn't routed. Missing ports: ${c.map(de=>de.getString()).join(", ")}`,pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[],pcb_port_ids:c.map(de=>de.pcb_port_id).filter(Boolean)});return}const A=this._findConnectedNets().netsWithSelectors;if(l.length===0&&A.length===2){this.renderError("Trace connects two nets, we haven't implemented a way to route this yet");return}else if(l.length===1&&A.length===1){const de=l[0],Be=A[0].net.getAllConnectedPorts().filter(_e=>_e!==de);if(Be.length===0){console.log("Nothing to connect this port to, the net is empty. TODO should emit a warning!");return}const pe=ost(de,Be);l.push(pe)}else if(l.length>1&&A.length>=1){this.renderError("Trace has more than one port and one or more nets, we don't currently support this type of complex trace routing");return}const u=l.flatMap(de=>de.matchedComponents.filter(Ie=>Ie.componentName==="TraceHint")),d=(this._parsedProps.pcbRouteHints??[]).concat(u.flatMap(de=>de.getPcbRouteHints()));if(l.length>2){this.renderError(`Trace has more than two ports (${l.map(de=>de.getString()).join(", ")}), routing between more than two ports for a single trace is not implemented`);return}if(this.getSubcircuit().selectAll("trace").filter(de=>de.renderPhaseStates.PcbTraceRender.initialized).some(de=>de._portsRoutedOnPcb.length===l.length&&de._portsRoutedOnPcb.every(Ie=>l.includes(Ie))))return;let C=[];d.length===0?C=[s8(l[0]),s8(l[1])]:C=[s8(l[0]),...d,s8(l[1])];const E=a8(C),_=pS(this.root.db.toArray()),[x,Q]=lst(()=>CP(this.root.db.toArray()));if(Q){this.renderError({type:"pcb_trace_error",error_type:"pcb_trace_error",pcb_trace_error_id:this.pcb_trace_id,message:`Error getting obstacles for autorouting: ${Q.message}`,source_trace_id:this.source_trace_id,center:{x:0,y:0},pcb_port_ids:l.map(de=>de.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[]});return}for(const de of x)if(de.connectedTo.length>0){const Be=_.getNetConnectedToId(de.connectedTo[0]);Be&&de.connectedTo.push(Be)}let P=[];if(E.length===0)P=C;else{const de=E[0].layer_path;P=C.map((Ie,Be)=>Ie.via?{...Ie,via_to_layer:de[Be]}:{...Ie,layers:[de[Be]]})}P[0].pcb_port_id=l[0].pcb_port_id,P[P.length-1].pcb_port_id=l[1].pcb_port_id;const z=[];for(const[de,Ie]of a0e(P)){const Be="via_to_layer"in de?de.via_to_layer:null,pe=2,_e="layers"in de&&de.layers.length===1?de.layers[0]:Be??"top",ve="layers"in Ie&&Ie.layers.length===1?Ie.layers[0]:Be??"top",Ne="pcb_port_id"in de?de.pcb_port_id:null,we="pcb_port_id"in Ie?Ie.pcb_port_id:null,Ue=this.getSubcircuit()._parsedProps.minTraceWidth??.16,Fe=new IP({OBSTACLE_MARGIN:Ue*2,isRemovePathLoopsEnabled:!0,optimizeWithGoalBoxes:!!(Ne&&we),connMap:_,input:{obstacles:x,minTraceWidth:Ue,connections:[{name:this.source_trace_id,pointsToConnect:[{...de,layer:_e,pcb_port_id:Ne},{...Ie,layer:ve,pcb_port_id:we}]}],layerCount:2,bounds:{minX:Math.min(de.x,Ie.x)-pe,maxX:Math.max(de.x,Ie.x)+pe,minY:Math.min(de.y,Ie.y)-pe,maxY:Math.max(de.y,Ie.y)+pe}}});let tt=null;try{tt=Fe.solveAndMapToTraces()}catch(bt){this.renderError({type:"pcb_trace_error",pcb_trace_error_id:this.source_trace_id,error_type:"pcb_trace_error",message:`error solving route: ${bt.message}`,source_trace_id:this.pcb_trace_id,center:{x:(de.x+Ie.x)/2,y:(de.y+Ie.y)/2},pcb_port_ids:l.map(Gt=>Gt.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:l.map(Gt=>Gt.pcb_component_id)})}if(!tt)return;if(tt.length===0){this.renderError({type:"pcb_trace_error",error_type:"pcb_trace_error",pcb_trace_error_id:this.pcb_trace_id,message:`Could not find a route for ${this}`,source_trace_id:this.source_trace_id,center:{x:(de.x+Ie.x)/2,y:(de.y+Ie.y)/2},pcb_port_ids:l.map(bt=>bt.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:l.map(bt=>bt.pcb_component_id)});return}const[rt]=tt;Be&&(rt.route=rt.route.map(bt=>(bt.route_type==="wire"&&!bt.layer&&(bt.layer=Be),bt))),Ne&&rt.route[0].route_type==="wire"&&(rt.route[0].start_pcb_port_id=Ne);const ht=rt.route[rt.route.length-1];we&&ht.route_type==="wire"&&(ht.end_pcb_port_id=we),z.push(rt.route)}const O=ist(z),V=cst(O),j=t.pcb_trace.insert({route:O,source_trace_id:this.source_trace_id,subcircuit_id:(oe=this.getSubcircuit())==null?void 0:oe.subcircuit_id,trace_length:V});this._portsRoutedOnPcb=l,this.pcb_trace_id=j.pcb_trace_id;for(const de of O)de.route_type==="via"&&t.pcb_via.insert({pcb_trace_id:j.pcb_trace_id,x:de.x,y:de.y,hole_diameter:.3,outer_diameter:.6,layers:[de.from_layer,de.to_layer],from_layer:de.from_layer,to_layer:de.to_layer});this._insertErrorIfTraceIsOutsideBoard(O,l)}_doInitialSchematicTraceRenderWithDisplayLabel(){var z,O,V,j;if((z=this.root)!=null&&z.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i)throw new Error("Trace has no parent");const{allPortsFound:a,portsWithSelectors:o}=this._findConnectedPorts();if(!a)return;const s=o.map(({port:q})=>({port:q,position:q._getGlobalSchematicPositionAfterLayout(),schematic_port_id:q.schematic_port_id,facingDirection:q.facingDirection}));if(s.length<2)throw new Error("Expected at least two ports in portsWithPosition.");let l,c;const A=s[0].position,u=s[0].port;if("path"in this.props){if(this.props.path.length!==2)throw new Error("Invalid 'path': Must contain exactly two elements.");[l,c]=this.props.path}else{if(!("from"in this.props&&"to"in this.props))throw new Error("Missing 'from' or 'to' properties in props.");l=this.props.from,c=this.props.to}if(!u.source_port_id)throw new Error(`Missing source_port_id for the 'from' port (${l}).`);const d=s[1].position,g=s[1].port;if(!g.source_port_id)throw new Error(`Missing source_port_id for the 'to' port (${c}).`);const m=t.schematic_net_label.list().find(q=>q.source_net_id===u.source_port_id),C=t.schematic_net_label.list().find(q=>q.source_net_id===g.source_port_id),[E,_]=o.map(({port:q})=>q),Q=((O=E.parent)==null?void 0:O.config.shouldRenderAsSchematicBox)?`${(V=E==null?void 0:E.parent)==null?void 0:V.props.name}_${E==null?void 0:E.props.name}`:`${(j=_==null?void 0:_.parent)==null?void 0:j.props.name}_${_==null?void 0:_.props.name}`,P=this.props.schDisplayLabel??Q;m&&m.text!==P&&(m.text=`${P} / ${m.text}`),C&&(C==null?void 0:C.text)!==P&&(C.text=`${P} / ${C.text}`),C||t.schematic_net_label.insert({text:this.props.schDisplayLabel??Q,source_net_id:g.source_port_id,anchor_position:d,center:d,anchor_side:TY(g.facingDirection)??"bottom"}),m||t.schematic_net_label.insert({text:this.props.schDisplayLabel??Q,source_net_id:u.source_port_id,anchor_position:A,center:A,anchor_side:TY(u.facingDirection)??"bottom"})}_isSymbolToChipConnection(){const{allPortsFound:t,ports:n}=this._findConnectedPorts();if(!t||n.length!==2)return!1;const[i,a]=n;if(!(i!=null&&i.parent)||!(a!=null&&a.parent))return!1;const o=i.parent.config.shouldRenderAsSchematicBox,s=a.parent.config.shouldRenderAsSchematicBox;return o&&!s||!o&&s}_isSymbolToSymbolConnection(){const{allPortsFound:t,ports:n}=this._findConnectedPorts();if(!t||n.length!==2)return!1;const[i,a]=n;if(!(i!=null&&i.parent)||!(a!=null&&a.parent))return!1;const o=!i.parent.config.shouldRenderAsSchematicBox,s=!a.parent.config.shouldRenderAsSchematicBox;return o&&s}_isChipToChipConnection(){const{allPortsFound:t,ports:n}=this._findConnectedPorts();if(!t||n.length!==2)return!1;const[i,a]=n;if(!(i!=null&&i.parent)||!(a!=null&&a.parent))return!1;const o=i.parent.config.shouldRenderAsSchematicBox,s=a.parent.config.shouldRenderAsSchematicBox;return o&&s}doInitialSchematicTraceRender(){var _e,ve,Ne;if((_e=this.root)!=null&&_e.schematicDisabled||((ve=this.getGroup())==null?void 0:ve._getSchematicLayoutMode())==="match-adapt")return;const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i)throw new Error("Trace has no parent");const{allPortsFound:a,portsWithSelectors:o}=this._findConnectedPorts(),{netsWithSelectors:s}=this._findConnectedNets();if(!a)return;const c=o.map(we=>we.port.schematic_port_id).sort().join(","),A=(Ne=this.root)==null?void 0:Ne._getBoard();if(A!=null&&A._connectedSchematicPortPairs&&A._connectedSchematicPortPairs.has(c))return;if(this.props.schDisplayLabel&&("from"in this.props&&"to"in this.props||"path"in this.props)){this._doInitialSchematicTraceRenderWithDisplayLabel();return}const u={name:this.source_trace_id,pointsToConnect:[]},d=hst(this),g=o.map(({port:we})=>({port:we,position:we._getGlobalSchematicPositionAfterLayout(),schematic_port_id:we.schematic_port_id??void 0,facingDirection:we.facingDirection}));if(g.length===1&&s.length===1){const we=s[0].net,{port:Ue,position:Fe}=g[0];t.schematic_net_label.insert({text:we._parsedProps.name,source_net_id:we.source_net_id,anchor_position:Fe,center:Fe,anchor_side:TY(Ue.facingDirection)??"bottom"});return}if(g.length<2)return;u.pointsToConnect=g.map(({position:we})=>({...we,layer:"top"}));const C=rst(d),E=2,_={minTraceWidth:.1,obstacles:d,connections:[u],bounds:{minX:C.minX-E,maxX:C.maxX+E,minY:C.minY-E,maxY:C.maxY+E},layerCount:1};let x=IP,Q=!1;this.getSubcircuit().props._schDirectLineRoutingEnabled&&(x=h0e,Q=!0);let z=new x({input:_,MAX_ITERATIONS:100,OBSTACLE_MARGIN:.1,isRemovePathLoopsEnabled:!0,isShortenPathWithShortcutsEnabled:!0,marginsWithCosts:[{margin:1,enterCost:0,travelCostFactor:1},{margin:.3,enterCost:0,travelCostFactor:1},{margin:.2,enterCost:0,travelCostFactor:2},{margin:.1,enterCost:0,travelCostFactor:3}]}).solveAndMapToTraces();if(z.length===0){if(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection()){this._doInitialSchematicTraceRenderWithDisplayLabel();return}z=new h0e({input:_}).solveAndMapToTraces(),Q=!0}const[{route:O}]=z;let V=[];for(let we=0;we<O.length-1;we++)V.push({from:O[we],to:O[we+1]});const j=this.source_trace_id;let q=[];if(!Q){pst({edges:V,db:t,source_trace_id:j});const we=o8({db:t,source_trace_id:j,differentNetOnly:!0}).flatMap(Ue=>Ue.edges);V=m0e({edges:V,otherEdges:we}),q=y0e({edges:V,db:t,source_trace_id:this.source_trace_id})}const J=V[V.length-1],ce=g[g.length-1],oe=p0e(J);V.push(...PY({lastEdge:J,lastEdgePort:ce,lastDominantDirection:oe}));const de=V[0],Ie=g[0],Be=p0e(de);if(V.unshift(...PY({firstEdge:de,firstEdgePort:Ie,firstDominantDirection:Be})),!this.source_trace_id)throw new Error("Missing source_trace_id for schematic trace insertion.");if(this.getSubcircuit()._parsedProps.schTraceAutoLabelEnabled&&sst(q,V)>=5&&(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection())){this._doInitialSchematicTraceRenderWithDisplayLabel();return}const pe=t.schematic_trace.insert({source_trace_id:this.source_trace_id,edges:V,junctions:q});this.schematic_trace_id=pe.schematic_trace_id,A!=null&&A._connectedSchematicPortPairs&&A._connectedSchematicPortPairs.add(c)}},yst=KI("tscircuit:core"),vst=Vn({x:vB,y:vB,z:vB}),m1=class extends Kv{constructor(t){super(t);Ve(this,"reactSubtrees",[]);Ve(this,"_impliedFootprint");Ve(this,"isPrimitiveContainer",!0);Ve(this,"_asyncSupplierPartNumbers");Ve(this,"pcb_missing_footprint_error_id");Ve(this,"_hasStartedFootprintUrlLoad",!1);this._addChildrenFromStringFootprint(),this.initPorts()}get defaultInternallyConnectedPinNames(){return[]}get internallyConnectedPinNames(){return this._parsedProps.internallyConnectedPins??this.defaultInternallyConnectedPinNames}initPorts(t={}){var s,l,c,A,u,d,g,m,C,E;if((s=this.root)!=null&&s.schematicDisabled)return;const{config:n}=this,i=[],a=this._getSchematicPortArrangement();if(a&&!this._parsedProps.pinLabels){for(const Q in a){const P=a[Q].pins;if(Array.isArray(P))for(const z of P){const O=yD(z,this._parsedProps.pinLabels);i.push(new yS({pinNumber:O,aliases:((l=t.additionalAliases)==null?void 0:l[`pin${O}`])??[]},{originDescription:`schPortArrangement:${Q}`}))}}const _=["left","right","top","bottom"];let x=1;for(const Q of _){const P=a[`${Q}Size`];for(let z=0;z<P;z++)i.push(new yS({pinNumber:x++,aliases:((c=t.additionalAliases)==null?void 0:c[`pin${x}`])??[]},{originDescription:`schPortArrangement:${Q}`}))}}const o=this._parsedProps.pinLabels;if(o)for(let[_,x]of Object.entries(o)){_=_.replace("pin","");let Q=i.find(O=>O._parsedProps.pinNumber===Number(_));const P=Array.isArray(x)?x[0]:x,z=Array.isArray(x)?x.slice(1):[];Q?(Q.externallyAddedAliases.push(P,...z),Q.props.name=P):(Q=new yS({pinNumber:parseInt(_),name:P,aliases:[...z,...((A=t.additionalAliases)==null?void 0:A[`pin${parseInt(_)}`])??[]]},{originDescription:`pinLabels:pin${_}`}),i.push(Q))}if(n.schematicSymbolName){const _=dI[this._getSchematicSymbolNameOrThrow()];if(!_)return;for(const x of _.ports){const Q=d0e(x.labels);if(!Q)continue;const P=i.find(z=>z._parsedProps.pinNumber===Number(Q));if(P)P.schematicSymbolPortDef=x;else{const z=vD(x.labels.concat(((u=t.additionalAliases)==null?void 0:u[`pin${Q}`])??[]));z&&(z.originDescription=`schematicSymbol:labels[0]:${x.labels[0]}`,z.schematicSymbolPortDef=x,i.push(z))}}this.addAll(i)}if(!this._getSchematicPortArrangement()){const _=this.getPortsFromFootprint(t);for(const x of _)i.some(Q=>Q.isMatchingAnyOf(x.getNameAndAliases()))||i.push(x)}for(let _=1;_<=(t.pinCount??this._getPinCount());_++){if(!a||i.find(Q=>Q._parsedProps.pinNumber===_))continue;let x=[...((d=a.leftSide)==null?void 0:d.pins)??[],...((g=a.rightSide)==null?void 0:g.pins)??[],...((m=a.topSide)==null?void 0:m.pins)??[],...((C=a.bottomSide)==null?void 0:C.pins)??[]].map(Q=>yD(Q,this._parsedProps.pinLabels));["leftSize","rightSize","topSize","bottomSize","leftPinCount","rightPinCount","topPinCount","bottomPinCount"].some(Q=>Q in a)&&(x=Array.from({length:this._getPinCount()},(Q,P)=>P+1)),x.includes(_)&&i.push(new yS({pinNumber:_,aliases:((E=t.additionalAliases)==null?void 0:E[`pin${_}`])??[]},{originDescription:`notOtherwiseAddedButDeducedFromPinCount:${_}`}))}i.length>0&&this.addAll(i)}_getImpliedFootprintString(){return null}_isFootprintUrl(t){return t.startsWith("http://")||t.startsWith("https://")}_addChildrenFromStringFootprint(){var o;const{name:t,pcbRotation:n,pinLabels:i}=this.props;let{footprint:a}=this.props;if(a??(a=(o=this._getImpliedFootprintString)==null?void 0:o.call(this)),!!a&&typeof a=="string"){if(this._isFootprintUrl(a))return;const s=DT.string(a).soup(),l=u0e({componentName:t,componentRotation:n,footprint:a,pinLabels:i},s);this.addAll(l)}}get portMap(){return new Proxy({},{get:(t,n)=>{const i=this.children.find(a=>a.componentName==="Port"&&a.isMatchingNameOrAlias(n));if(!i)throw new Error(`There was an issue finding the port "${n.toString()}" inside of a ${this.componentName} component with name: "${this.props.name}". This is a bug in @tscircuit/core`);return i}})}getInstanceForReactElement(t){for(const n of this.reactSubtrees)if(n.element===t)return n.component;return null}doInitialSourceRender(){const t=this.config.sourceFtype;if(!t)return;const{db:n}=this.root,{_parsedProps:i}=this,a=n.source_component.insert({ftype:t,name:i.name,manufacturer_part_number:i.manufacturerPartNumber??i.mfn,supplier_part_numbers:i.supplierPartNumbers});this.source_component_id=a.source_component_id}doInitialSchematicComponentRender(){var a,o,s;if((a=this.root)!=null&&a.schematicDisabled)return;const{db:t}=this.root,{schematicSymbolName:n}=this.config;n?this._doInitialSchematicComponentRenderWithSymbol():this._getSchematicBoxDimensions()&&this._doInitialSchematicComponentRenderWithSchematicBoxDimensions();const i=(o=this.getSubcircuit())==null?void 0:o._getSchematicManualPlacementForComponent(this);if(this.schematic_component_id&&(this.props.schX!==void 0||this.props.schY!==void 0)&&i){if(!this.schematic_component_id)return;const l=CT.parse({type:"schematic_manual_edit_conflict_warning",schematic_manual_edit_conflict_warning_id:`schematic_manual_edit_conflict_${this.source_component_id}`,message:`${this.getString()} has both manual placement and prop coordinates. schX and schY will be used. Remove schX/schY or clear the manual placement.`,schematic_component_id:this.schematic_component_id,source_component_id:this.source_component_id,subcircuit_id:(s=this.getSubcircuit())==null?void 0:s.subcircuit_id});t.schematic_manual_edit_conflict_warning.insert(l)}}_getSchematicSymbolDisplayValue(){}_getInternallyConnectedPins(){if(this.internallyConnectedPinNames.length===0)return[];const t=[];for(const n of this.internallyConnectedPinNames){const i=[];for(const a of n)i.push(this.portMap[a]);t.push(i)}return t}_doInitialSchematicComponentRenderWithSymbol(){var s;if((s=this.root)!=null&&s.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getSchematicSymbolNameOrThrow(),a=dI[i],o=this._getGlobalSchematicPositionBeforeLayout();if(a){const l=t.schematic_component.insert({center:o,size:a.size,source_component_id:this.source_component_id,symbol_name:i,symbol_display_value:this._getSchematicSymbolDisplayValue()});this.schematic_component_id=l.schematic_component_id}}_doInitialSchematicComponentRenderWithSchematicBoxDimensions(){var d;if((d=this.root)!=null&&d.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getSchematicBoxDimensions(),a={};if(Array.isArray(n.pinLabels))n.pinLabels.forEach((g,m)=>{a[String(m+1)]=g});else for(const[g,m]of Object.entries(n.pinLabels??{}))a[g]=Array.isArray(m)?m[0]:m;const o=this._getGlobalSchematicPositionBeforeLayout(),s=this._getSchematicPortArrangement(),l=t.schematic_component.insert({center:o,rotation:n.schRotation??0,size:i.getSize(),port_arrangement:zot(s),pin_spacing:n.schPinSpacing??.2,pin_styles:Oot(n.schPinStyle,n.pinLabels),port_labels:a,source_component_id:this.source_component_id}),c=(s==null?void 0:s.topSide)!==void 0||(s==null?void 0:s.bottomSide)!==void 0,A=i==null?void 0:i.getSize().width,u=i==null?void 0:i.getSize().height;t.schematic_text.insert({text:n.manufacturerPartNumber??"",schematic_component_id:l.schematic_component_id,anchor:"left",rotation:0,position:{x:c?o.x+(A??0)/2+.1:o.x-(A??0)/2,y:c?o.y+(u??0)/2+.35:o.y-(u??0)/2-.13},color:"#006464",font_size:.18}),t.schematic_text.insert({text:n.name??"",schematic_component_id:l.schematic_component_id,anchor:"left",rotation:0,position:{x:c?o.x+(A??0)/2+.1:o.x-(A??0)/2,y:c?o.y+(u??0)/2+.55:o.y+(u??0)/2+.13},color:"#006464",font_size:.18}),this.schematic_component_id=l.schematic_component_id}doInitialPcbComponentRender(){var s;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getSubcircuit(),a=t.pcb_component.insert({center:this._getGlobalPcbPositionBeforeLayout(),width:0,height:0,layer:n.layer??"top",rotation:n.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:i.subcircuit_id??void 0});if(!n.footprint&&!this.isGroup){const l=t.pcb_missing_footprint_error.insert({message:`No footprint found for component: ${this.getString()}`,source_component_id:`${this.source_component_id}`,error_type:"pcb_missing_footprint_error"});this.pcb_missing_footprint_error_id=l.pcb_missing_footprint_error_id}this.pcb_component_id=a.pcb_component_id;const o=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if((this.props.pcbX!==void 0||this.props.pcbY!==void 0)&&o){const l=_T.parse({type:"pcb_manual_edit_conflict_warning",pcb_manual_edit_conflict_warning_id:`pcb_manual_edit_conflict_${this.source_component_id}`,message:`${this.getString()} has both manual placement and prop coordinates. pcbX and pcbY will be used. Remove pcbX/pcbY or clear the manual placement.`,pcb_component_id:this.pcb_component_id,source_component_id:this.source_component_id,subcircuit_id:i.subcircuit_id??void 0});t.pcb_manual_edit_conflict_warning.insert(l)}}doInitialPcbComponentSizeCalculation(){var o;if((o=this.root)!=null&&o.pcbDisabled||!this.pcb_component_id)return;const{db:t}=this.root,{_parsedProps:n}=this,i=NY(this.children);if(i.width===0||i.height===0)return;const a={x:(i.minX+i.maxX)/2,y:(i.minY+i.maxY)/2};t.pcb_component.update(this.pcb_component_id,{center:a,width:i.width,height:i.height})}_renderReactSubtree(t){return{element:t,component:i0e(t)}}doInitialInitializePortsFromChildren(){this.initPorts()}doInitialReactSubtreesRender(){}doInitialPcbFootprintStringRender(){var o;let{footprint:t}=this.props;if(t??(t=(o=this._getImpliedFootprintString)==null?void 0:o.call(this)),!t)return;const{name:n,pcbRotation:i,pinLabels:a}=this.props;if(typeof t=="string"&&this._isFootprintUrl(t)){if(this._hasStartedFootprintUrlLoad)return;this._hasStartedFootprintUrlLoad=!0;const s=t;this._queueAsyncEffect("load-footprint-url",async()=>{const c=await(await fetch(s)).json(),A=u0e({componentName:n,componentRotation:i,footprint:s,pinLabels:a},c);this.addAll(A),this._markDirty("InitializePortsFromChildren")});return}if(yt.isValidElement(t)){if(this.reactSubtrees.some(l=>l.element===t))return;const s=this._renderReactSubtree(t);this.reactSubtrees.push(s),this.add(s.component);return}!yt.isValidElement(t)&&t.componentName==="Footprint"&&this.add(t)}_hasExistingPortExactly(t){return this.children.filter(i=>i.componentName==="Port").some(i=>{const a=t.getNameAndAliases(),o=i.getNameAndAliases();return a.length===o.length&&a.every(s=>o.includes(s))})}add(t){let n;if(yt.isValidElement(t)){const i=this._renderReactSubtree(t);this.reactSubtrees.push(i),n=i.component}else n=t;if(n.componentName==="Port"){if(this._hasExistingPortExactly(n))return;const a=this.children.filter(o=>o.componentName==="Port").find(o=>o.isMatchingAnyOf(n.getNameAndAliases()));a&&yst(`Similar ports added. Port 1: ${a}, Port 2: ${n}`)}super.add(n)}getPortsFromFootprint(t){let{footprint:n}=this.props;if((!n||yt.isValidElement(n))&&(n=this.children.find(a=>a.componentName==="Footprint")),typeof n=="string"){if(this._isFootprintUrl(n))return[];const a=DT.string(n).soup(),o=[];for(const s of a)if("port_hints"in s&&s.port_hints){const l=vD(s.port_hints,t);if(!l)continue;l.originDescription=`footprint:string:${n}:port_hints[0]:${s.port_hints[0]}`,o.push(l)}return o}if(!yt.isValidElement(n)&&n&&n.componentName==="Footprint"){const a=n;let o=1;const s=[];for(const l of a.children){if(!l.props.portHints)continue;let c=l.props.portHints;c.some(d=>d.startsWith("pin"))||(c=[...c,`pin${o}`]),o++;const u=vD(c);u&&(u.originDescription=`footprint:${n}`,s.push(u))}return s}const i=[];if(!n){for(const a of this.children)if(a.props.portHints&&a.isPcbPrimitive){const o=vD(a.props.portHints);o&&i.push(o)}}return i}getPortsFromSchematicSymbol(){var a;if((a=this.root)!=null&&a.schematicDisabled)return[];const{config:t}=this;if(!t.schematicSymbolName)return[];const n=dI[t.schematicSymbolName];if(!n)return[];const i=[];for(const o of n.ports){const s=vD(o.labels);s&&(s.schematicSymbolPortDef=o,i.push(s))}return i}doInitialCreateNetsFromProps(){this._createNetsFromProps(this._getNetsFromConnectionsProp())}_getNetsFromConnectionsProp(){const{_parsedProps:t}=this,n=[];if(t.connections)for(const[i,a]of Object.entries(t.connections)){const o=Array.isArray(a)?a:[a];for(const s of o)n.push(s)}return n}_createNetsFromProps(t){s0e(this,t)}_getPcbCircuitJsonBounds(){const{db:t}=this.root;if(!this.pcb_component_id)return super._getPcbCircuitJsonBounds();const n=t.pcb_component.get(this.pcb_component_id);return{center:{x:n.center.x,y:n.center.y},bounds:{left:n.center.x-n.width/2,top:n.center.y-n.height/2,right:n.center.x+n.width/2,bottom:n.center.y+n.height/2},width:n.width,height:n.height}}_getPinCountFromSchematicPortArrangement(){const t=this._getSchematicPortArrangement();if(!t)return 0;if(!f0e(t))return(t.leftSize??t.leftPinCount??0)+(t.rightSize??t.rightPinCount??0)+(t.topSize??t.topPinCount??0)+(t.bottomSize??t.bottomPinCount??0);const{leftSide:i,rightSide:a,topSide:o,bottomSide:s}=t;return Math.max(...(i==null?void 0:i.pins)??[],...(a==null?void 0:a.pins)??[],...(o==null?void 0:o.pins)??[],...(s==null?void 0:s.pins)??[])}_getPinCount(){return this._getSchematicPortArrangement()?this._getPinCountFromSchematicPortArrangement():this.getPortsFromFootprint().length}_getSchematicPortArrangement(){return this._parsedProps.schPinArrangement??this._parsedProps.schPortArrangement}_getSchematicBoxDimensions(){if(this.getSchematicSymbol()||!this.config.shouldRenderAsSchematicBox)return null;const{_parsedProps:t}=this,n=this._getPinCount(),i=t.schPinSpacing??.2;return $ot({schWidth:t.schWidth,schHeight:t.schHeight,schPinSpacing:i,numericSchPinStyle:nst(t.schPinStyle,t.pinLabels),pinCount:n,schPortArrangement:this._getSchematicPortArrangement(),pinLabels:t.pinLabels})}doInitialCadModelRender(){var A;const{db:t}=this.root,{boardThickness:n=0}=((A=this.root)==null?void 0:A._getBoard())??{},i=this._parsedProps.cadModel;if(!this.pcb_component_id||!i&&!this.props.footprint||i===null)return;const a=this._getPcbCircuitJsonBounds(),o=t.pcb_component.get(this.pcb_component_id);if(typeof i=="string")throw new Error("String cadModel not yet implemented");const s=vst.parse({x:0,y:0,z:typeof(i==null?void 0:i.rotationOffset)=="number"?i.rotationOffset:0,...typeof(i==null?void 0:i.rotationOffset)=="object"?i.rotationOffset??{}:{}}),l=AQ.parse({x:0,y:0,z:0,...typeof(i==null?void 0:i.positionOffset)=="object"?i.positionOffset:{}}),c=this.props.layer==="bottom"?"bottom":"top";t.cad_component.insert({position:{x:a.center.x+l.x,y:a.center.y+l.y,z:(c==="bottom"?-n/2:n/2)+l.z},rotation:{x:s.x,y:(c==="top"?0:180)+s.y,z:c==="bottom"?-(((o==null?void 0:o.rotation)??0)+s.z)+180:((o==null?void 0:o.rotation)??0)+s.z},pcb_component_id:this.pcb_component_id,source_component_id:this.source_component_id,model_stl_url:"stlUrl"in(i??{})?this._addCachebustToModelUrl(i.stlUrl):void 0,model_obj_url:"objUrl"in(i??{})?this._addCachebustToModelUrl(i.objUrl):void 0,model_jscad:"jscad"in(i??{})?i.jscad:void 0,footprinter_string:typeof this.props.footprint=="string"&&!i?this.props.footprint:void 0})}_addCachebustToModelUrl(t){var i;if(!t||!t.includes("modelcdn.tscircuit.com"))return t;const n=((i=this.root)==null?void 0:i.getClientOrigin())??"";return`${t}${t.includes("?")?"&":"?"}cachebust_origin=${encodeURIComponent(n)}`}_getPartsEngineCacheKey(t,n){return JSON.stringify({ftype:t.ftype,name:t.name,manufacturer_part_number:t.manufacturer_part_number,footprinterString:n})}async _getSupplierPartNumbers(t,n,i){var c,A;if(this.props.doNotPlace)return{};const a=(A=(c=this.root)==null?void 0:c.platform)==null?void 0:A.localCacheEngine,o=this._getPartsEngineCacheKey(n,i);if(a){const u=await a.getItem(o);if(u)try{return JSON.parse(u)}catch{}}const s=await Promise.resolve(t.findPart({sourceComponent:n,footprinterString:i})),l=s==="Not found"?{}:s;if(a)try{await a.setItem(o,JSON.stringify(l))}catch{}return l}doInitialPartsEngineRender(){if(this.props.doNotPlace)return;const t=this.getInheritedProperty("partsEngine");if(!t)return;const{db:n}=this.root,i=n.source_component.get(this.source_component_id);if(!i||i.supplier_part_numbers)return;let a;this.props.footprint&&typeof this.props.footprint=="string"&&(a=this.props.footprint);const o=this._getSupplierPartNumbers(t,i,a);if(!(o instanceof Promise)){n.source_component.update(this.source_component_id,{supplier_part_numbers:o});return}this._queueAsyncEffect("get-supplier-part-numbers",async()=>{this._asyncSupplierPartNumbers=await o,this._markDirty("PartsEngineRender")})}updatePartsEngineRender(){if(this.props.doNotPlace)return;const{db:t}=this.root,n=t.source_component.get(this.source_component_id);if(n&&!n.supplier_part_numbers&&this._asyncSupplierPartNumbers){t.source_component.update(this.source_component_id,{supplier_part_numbers:this._asyncSupplierPartNumbers});return}}doInitialCreateTracesFromProps(){this._createTracesFromConnectionsProp()}_createTracesFromConnectionsProp(){const{_parsedProps:t}=this;if(t.connections)for(const[n,i]of Object.entries(t.connections)){const a=Array.isArray(i)?i:[i];for(const o of a)this.add(new vS({from:`${this.getSubcircuitSelector()} > port.${n}`,to:o}))}}},Ist=class{constructor(e,t={}){Ve(this,"input");Ve(this,"isRouting",!1);Ve(this,"solver");Ve(this,"eventHandlers",{complete:[],error:[],progress:[]});Ve(this,"cycleCount",0);Ve(this,"stepDelay");Ve(this,"timeoutId");this.input=e;const{capacityDepth:n,targetMinCapacity:i,stepDelay:a=0}=t;this.solver=new Ppe(e,{capacityDepth:n,targetMinCapacity:i,cacheProvider:null}),this.stepDelay=a}start(){this.isRouting||(this.isRouting=!0,this.cycleCount=0,this.runCycleAndQueueNextCycle())}runCycleAndQueueNextCycle(){var e;if(this.isRouting)try{if(this.solver.solved||this.solver.failed){this.solver.failed?this.emitEvent({type:"error",error:new Error(this.solver.error||"Routing failed")}):this.emitEvent({type:"complete",traces:this.solver.getOutputSimpleRouteJson().traces||[]}),this.isRouting=!1;return}const t=Date.now(),n=this.solver.iterations;for(;Date.now()-t<250&&!this.solver.failed&&!this.solver.solved;)this.solver.step();const i=(this.solver.iterations-n)/(Date.now()-t)*1e3;this.cycleCount++;const a=((e=this.solver)==null?void 0:e.preview())||void 0,o=this.solver.progress;this.emitEvent({type:"progress",steps:this.cycleCount,iterationsPerSecond:i,progress:o,phase:this.solver.getCurrentPhase(),debugGraphics:a}),this.stepDelay>0?this.timeoutId=setTimeout(()=>this.runCycleAndQueueNextCycle(),this.stepDelay):this.timeoutId=setTimeout(()=>this.runCycleAndQueueNextCycle(),0)}catch(t){this.emitEvent({type:"error",error:t instanceof Error?t:new Error(String(t))}),this.isRouting=!1}}stop(){this.isRouting&&(this.isRouting=!1,this.timeoutId!==void 0&&(clearTimeout(this.timeoutId),this.timeoutId=void 0))}on(e,t){e==="complete"?this.eventHandlers.complete.push(t):e==="error"?this.eventHandlers.error.push(t):e==="progress"&&this.eventHandlers.progress.push(t)}emitEvent(e){if(e.type==="complete")for(const t of this.eventHandlers.complete)t(e);else if(e.type==="error")for(const t of this.eventHandlers.error)t(e);else if(e.type==="progress")for(const t of this.eventHandlers.progress)t(e)}solveSync(){if(this.solver.solve(),this.solver.failed)throw new Error(this.solver.error||"Routing failed");return this.solver.getOutputSimpleRouteJson().traces||[]}},v0e=class extends Kv{constructor(){super(...arguments);Ve(this,"matchedPort",null)}get config(){return{componentName:"TraceHint",zodProps:kge}}doInitialPortMatching(){const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i)return;if(i.componentName==="Trace"){this.renderError(`Port inference inside trace is not yet supported (${this})`);return}if(!i)throw new Error("TraceHint has no parent");if(!n.for){this.renderError(`TraceHint has no for property (${this})`);return}const a=i.selectOne(n.for,{type:"port"});a||this.renderError(`${this} could not find port for selector "${n.for}"`),this.matchedPort=a,a.registerMatch(this)}getPcbRouteHints(){const{_parsedProps:t}=this,n=t.offset?[t.offset]:t.offsets;if(!n)return[];const i=this._computePcbGlobalTransformBeforeLayout();return n.map(a=>({...si(i,a),via:a.via,to_layer:a.to_layer,trace_width:a.trace_width}))}doInitialPcbTraceHintRender(){var i,a,o;if((i=this.root)!=null&&i.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this;t.pcb_trace_hint.insert({pcb_component_id:(a=this.matchedPort)==null?void 0:a.pcb_component_id,pcb_port_id:(o=this.matchedPort)==null?void 0:o.pcb_port_id,route:this.getPcbRouteHints()})}},Cst=(r,e)=>{const t=r.source_group.list(),n=[],i=a=>{const o=t.filter(s=>s.parent_subcircuit_id===a);for(const s of o)s.subcircuit_id&&(n.push(s.subcircuit_id),i(s.subcircuit_id))};return i(e),n},I0e=({db:r,circuitJson:e,subcircuit_id:t,minTraceWidth:n=.1})=>{if(!r&&e&&(r=$E(e)),!r)throw new Error("db or circuitJson is required");const i=r.pcb_trace_hint.list(),a=t?new Set([t]):null;if(t){const C=Cst(r,t);for(const E of C)a.add(E)}const o=(e??r.toArray()).filter(C=>!t||"subcircuit_id"in C&&a.has(C.subcircuit_id)),s=r.pcb_board.list()[0];r=$E(o);const l=pS(o),c=CP([...r.pcb_component.list(),...r.pcb_smtpad.list(),...r.pcb_plated_hole.list(),...r.pcb_hole.list(),...r.pcb_via.list()].filter(C=>!t||(a==null?void 0:a.has(C.subcircuit_id))),l);for(const C of c){const E=C.connectedTo.flatMap(_=>l.getIdsConnectedToNet(_));C.connectedTo.push(...E)}const A=c.flatMap(C=>[{x:C.center.x-C.width/2,y:C.center.y-C.height/2},{x:C.center.x+C.width/2,y:C.center.y+C.height/2}]);let u;s?u={minX:s.center.x-s.width/2,maxX:s.center.x+s.width/2,minY:s.center.y-s.height/2,maxY:s.center.y+s.height/2}:u={minX:Math.min(...A.map(C=>C.x))-1,maxX:Math.max(...A.map(C=>C.x))+1,minY:Math.min(...A.map(C=>C.y))-1,maxY:Math.max(...A.map(C=>C.y))+1};const d=r.source_trace.list().map(C=>{var V,j,q;const E=C.connected_source_port_ids.map(J=>{const ce=r.source_port.get(J),oe=r.pcb_port.getWhere({source_port_id:J});return{...ce,...oe}});if(E.length<2)return null;const[_,x]=E,Q=((V=_.layers)==null?void 0:V[0])??"top",P=((j=x.layers)==null?void 0:j[0])??"top",z=i.filter(J=>J.pcb_port_id===_.pcb_port_id||J.pcb_port_id===x.pcb_port_id),O=[];for(const J of z){const ce=r.pcb_port.get(J.pcb_port_id),oe=((q=ce==null?void 0:ce.layers)==null?void 0:q[0])??"top";for(const de of J.route)O.push({x:de.x,y:de.y,layer:oe})}return{name:C.source_trace_id??l.getNetConnectedToId(C.source_trace_id)??"",source_trace_id:C.source_trace_id,pointsToConnect:[{x:_.x,y:_.y,layer:Q},...O,{x:x.x,y:x.y,layer:P}]}}).filter(C=>C!==null),g=r.source_net.list().filter(C=>!t||(a==null?void 0:a.has(C.subcircuit_id))),m=[];for(const C of g){const E=r.source_trace.list().filter(_=>{var x;return(x=_.connected_source_net_ids)==null?void 0:x.includes(C.source_net_id)});m.push({name:C.source_net_id??l.getNetConnectedToId(C.source_net_id),pointsToConnect:E.flatMap(_=>r.pcb_port.list().filter(Q=>_.connected_source_port_ids.includes(Q.source_port_id)).map(Q=>{var P;return{x:Q.x,y:Q.y,layer:((P=Q.layers)==null?void 0:P[0])??"top",pcb_port_id:Q.pcb_port_id}}))})}return{simpleRouteJson:{bounds:u,obstacles:c,connections:[...d,...m],layerCount:2,minTraceWidth:n},connMap:l}};function UY(r,e){if("boxId"in r){const{boxId:t,pinNumber:n}=r,i=e.source_component.getWhere({name:t});if(!i)throw new Error(`Source component "${t}" not found, but returned from match-adapt ${JSON.stringify(r)}`);const a=e.source_port.getWhere({source_component_id:i.source_component_id,pin_number:n});return{subcircuit_connectivity_map_key:(a==null?void 0:a.subcircuit_connectivity_map_key)??null,source_port_id:a.source_port_id}}if("netId"in r){const{netId:t}=r;return e.source_net.getWhere({name:t}),null}if("junctionId"in r){const{junctionId:t}=r;return null}return null}function Est({path:r,db:e,layoutConnMap:t}){let n=UY(r.to,e)??UY(r.from,e);if(!n){const a=t.getNetConnectedToId(Bb(r.to));n=t.getIdsConnectedToNet(a).map(s=>vY(s)).map(s=>UY(s,e)).find(Boolean)}if(!(n!=null&&n.subcircuit_connectivity_map_key))throw new Error(`No connectivity net id found for match-adapt path ${JSON.stringify(r)}`);const i=e.source_trace.list({subcircuit_connectivity_map_key:n.subcircuit_connectivity_map_key});for(const a of i)if(a.connected_source_port_ids.includes(n.source_port_id))return a.source_trace_id;if(i.length>0)return i[0].source_trace_id;throw new Error(`No source trace found for match-adapt path "${JSON.stringify(r)}"`)}function _st(r){const{db:e}=r.root;let t=structuredClone(e.toArray());t=Dot(t);const n=Mot(t),i=new Qot({inputNetlist:n});let a=null;try{i.solve(),a=i.getLayout()}catch(u){e.schematic_layout_error.insert({message:`Match-adapt layout failed: ${u.toString()}`,source_group_id:r.source_group_id,schematic_group_id:r.schematic_group_id});return}const{boxes:o,junctions:s,netLabels:l,paths:c}=a,A=new y9({});for(const u of c)A.addConnections([[Bb(u.from),Bb(u.to)]]);for(const u of s)for(const d of c)for(const g of d.points)Math.abs(g.x-u.x)<.001&&Math.abs(g.y-u.y)<.001&&A.addConnections([[Bb(d.from),Bb(u)],[Bb(d.to),Bb(u)]]);for(const u of o){const d=e.source_component.list().find(_=>_.name===u.boxId);if(!d)continue;const g=e.schematic_component.getWhere({source_component_id:d.source_component_id});if(!g)continue;const m={x:u.centerX-g.center.x+.1,y:u.centerY-g.center.y-.1};e.schematic_component.update(g.schematic_component_id,{center:{x:g.center.x+m.x,y:g.center.y+m.y}});const C=e.schematic_port.list({schematic_component_id:g.schematic_component_id});for(const _ of C)e.schematic_port.update(_.schematic_port_id,{center:{x:_.center.x+m.x,y:_.center.y+m.y}});const E=e.schematic_text.list({schematic_component_id:g.schematic_component_id});for(const _ of E)e.schematic_text.update(_.schematic_text_id,{position:{x:_.position.x+m.x,y:_.position.y+m.y}})}for(const u of l){const d=e.source_net.list().find(g=>g.name===u.netId);e.schematic_net_label.insert({text:u.netId,source_net_id:d==null?void 0:d.source_net_id,anchor_position:{x:u.x,y:u.y},center:{x:u.x,y:u.y},anchor_side:u.anchorPosition})}for(const u of c){if(!u.points||u.points.length<2)continue;const d=Est({path:u,db:yx(t),layoutConnMap:A});let g=[];for(let E=0;E<u.points.length-1;E++)g.push({from:{x:u.points[E].x,y:u.points[E].y},to:{x:u.points[E+1].x,y:u.points[E+1].y}});const m=o8({db:e,source_trace_id:d,differentNetOnly:!0}).flatMap(E=>E.edges);m.length>0&&(g=m0e({edges:g,otherEdges:m}));const C=y0e({edges:g,db:e,source_trace_id:d});e.schematic_trace.insert({source_trace_id:d,edges:g,junctions:C})}}function Bst(r){if(!r.isSubcircuit)return;const{db:e}=r.root,t=r.selectAll("trace"),n=new y9({});n.addConnections(t.map(s=>{const l=e.source_trace.get(s.source_trace_id);return l?[l.source_trace_id,...l.connected_source_port_ids,...l.connected_source_net_ids]:null}).filter(s=>s!==null));const{name:i}=r._parsedProps;for(const s of t){if(!s.source_trace_id)continue;const l=n.getNetConnectedToId(s.source_trace_id);l&&(s.subcircuit_connectivity_map_key=`${i??`unnamedsubcircuit${r._renderId}`}_${l}`,e.source_trace.update(s.source_trace_id,{subcircuit_connectivity_map_key:s.subcircuit_connectivity_map_key}))}const a=new Set;for(const s of t){if(!s.source_trace_id)continue;const l=e.source_trace.get(s.source_trace_id);if(l)for(const c of l.connected_source_port_ids)a.add(c)}for(const s of a){const l=n.getNetConnectedToId(s);if(!l)continue;const c=`${i??`unnamedsubcircuit${r._renderId}`}_${l}`;e.source_port.update(s,{subcircuit_connectivity_map_key:c})}const o=new Set;for(const s of t){if(!s.source_trace_id)continue;const l=e.source_trace.get(s.source_trace_id);if(l)for(const c of l.connected_source_net_ids)o.add(c)}for(const s of o){const l=n.getNetConnectedToId(s);if(!l)continue;const c=`${i??`unnamedsubcircuit${r._renderId}`}_${l}`;e.source_net.update(s,{subcircuit_connectivity_map_key:c})}}function xst(r){var x;const{db:e}=r.root,t=r._parsedProps,n=r.children.filter(Q=>Q.schematic_component_id);if(n.length===0)return;let i=0,a=0;for(const Q of n){const P=e.schematic_component.get(Q.schematic_component_id);P!=null&&P.size&&(i=Math.max(i,P.size.width),a=Math.max(a,P.size.height))}i===0&&n.length>0&&(i=1),a===0&&n.length>0&&(a=1);let o=t.gridCols,s,l=t.gridGap;(x=t.schLayout)!=null&&x.grid&&(o=t.schLayout.grid.cols??o,s=t.schLayout.grid.rows,l=t.schLayout.grid.gap??l);let c,A;o!==void 0&&s!==void 0?(c=o,A=s):o!==void 0?(c=o,A=Math.ceil(n.length/c)):s!==void 0?(A=s,c=Math.ceil(n.length/A)):(c=Math.ceil(Math.sqrt(n.length)),A=Math.ceil(n.length/c)),c===0&&n.length>0&&(c=1),A===0&&n.length>0&&(A=n.length);let u,d;typeof l=="number"?(u=l,d=l):typeof l=="object"&&l!==null?(u=l.x,d=l.y):(u=1,d=1);const g=c*i+Math.max(0,c-1)*u,m=A*a+Math.max(0,A-1)*d,C=r._getGlobalSchematicPositionBeforeLayout(),E=C.x-g/2+i/2,_=C.y+m/2-a/2;for(let Q=0;Q<n.length;Q++){const P=n[Q];if(!P.schematic_component_id)continue;const z=Math.floor(Q/c),O=Q%c;if(z>=A||O>=c){console.warn(`Schematic grid layout: Child ${P.getString()} at index ${Q} (row ${z}, col ${O}) exceeds specified grid dimensions (${A}x${c}). Skipping placement.`);continue}const V=E+O*(i+u),j=_-z*(a+d),q=e.schematic_component.get(P.schematic_component_id);if(q){const J=q.center,ce={x:V,y:j};e.schematic_component.update(P.schematic_component_id,{center:ce});const oe=ce.x-J.x,de=ce.y-J.y,Ie=e.schematic_port.list({schematic_component_id:P.schematic_component_id});for(const pe of Ie)e.schematic_port.update(pe.schematic_port_id,{center:{x:pe.center.x+oe,y:pe.center.y+de}});const Be=e.schematic_text.list({schematic_component_id:P.schematic_component_id});for(const pe of Be)e.schematic_text.update(pe.schematic_text_id,{position:{x:pe.position.x+oe,y:pe.position.y+de}})}}r.schematic_group_id&&e.schematic_group.update(r.schematic_group_id,{width:g,height:m,center:C})}function bst(r){var x;const{db:e}=r.root,t=r._parsedProps,n=r.children.filter(Q=>Q.pcb_component_id);if(n.length===0)return;let i=0,a=0;for(const Q of n){const P=e.pcb_component.get(Q.pcb_component_id);P&&(i=Math.max(i,P.width),a=Math.max(a,P.height))}i===0&&n.length>0&&(i=1),a===0&&n.length>0&&(a=1);let o=t.gridCols,s,l=t.gridGap;(x=t.pcbLayout)!=null&&x.grid&&(o=t.pcbLayout.grid.cols??o,s=t.pcbLayout.grid.rows,l=t.pcbLayout.grid.gap??l);let c,A;o!==void 0&&s!==void 0?(c=o,A=s):o!==void 0?(c=o,A=Math.ceil(n.length/c)):s!==void 0?(A=s,c=Math.ceil(n.length/A)):(c=Math.ceil(Math.sqrt(n.length)),A=Math.ceil(n.length/c)),c===0&&n.length>0&&(c=1),A===0&&n.length>0&&(A=n.length);let u,d;typeof l=="number"?(u=l,d=l):typeof l=="object"&&l!==null?(u=l.x,d=l.y):(u=1,d=1);const g=c*i+Math.max(0,c-1)*u,m=A*a+Math.max(0,A-1)*d,C=r._getGlobalPcbPositionBeforeLayout(),E=C.x-g/2+i/2,_=C.y+m/2-a/2;for(let Q=0;Q<n.length;Q++){const P=n[Q];if(!P.pcb_component_id)continue;const z=Math.floor(Q/c),O=Q%c;if(z>=A||O>=c){console.warn(`PCB grid layout: Child ${P.getString()} at index ${Q} (row ${z}, col ${O}) exceeds grid dimensions (${A}x${c}). Skipping placement.`);continue}const V=E+O*(i+u),j=_-z*(a+d),q=e.pcb_component.get(P.pcb_component_id);if(q){const J=q.center,ce={x:V,y:j},oe=ce.x-J.x,de=ce.y-J.y,Ie=Kd(oe,de),Be=e.toArray().filter(_e=>_e.pcb_component_id===P.pcb_component_id),pe=Aat(Be,Ie);for(const _e of pe){const ve=e8(_e);e[_e.type].update(_e[ve],_e)}e.pcb_component.update(P.pcb_component_id,{center:ce}),P.setProps({...P.props,pcbX:(P.props.pcbX??0)+oe,pcbY:(P.props.pcbY??0)+de})}}r.pcb_group_id&&e.pcb_group.update(r.pcb_group_id,{width:g,height:m,center:C})}var FY=class extends m1{constructor(){super(...arguments);Ve(this,"pcb_group_id",null);Ve(this,"schematic_group_id",null);Ve(this,"subcircuit_id",null);Ve(this,"_hasStartedAsyncAutorouting",!1);Ve(this,"_asyncAutoroutingResult",null)}get config(){return{zodProps:$he,componentName:"Group"}}doInitialSourceRender(){const{db:t}=this.root,n=t.source_group.insert({name:this._parsedProps.name,is_subcircuit:this.isSubcircuit});this.subcircuit_id=`subcircuit_${n.source_group_id}`,this.source_group_id=n.source_group_id,t.source_group.update(n.source_group_id,{subcircuit_id:this.subcircuit_id});for(const i of this.children)t.source_component.update(i.source_component_id,{source_group_id:this.source_group_id})}doInitialSourceParentAttachment(){var i,a,o;const{db:t}=this.root;if(!this.isSubcircuit)return;const n=(o=(a=(i=this.parent)==null?void 0:i.getSubcircuit)==null?void 0:a.call(i))==null?void 0:o.subcircuit_id;n&&t.source_group.update(this.source_group_id,{parent_subcircuit_id:n})}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=t.pcb_group.insert({is_subcircuit:this.isSubcircuit,subcircuit_id:this.subcircuit_id,name:this._parsedProps.name,center:this._getGlobalPcbPositionBeforeLayout(),width:0,height:0,pcb_component_ids:[],source_group_id:this.source_group_id});this.pcb_group_id=i.pcb_group_id;for(const o of this.children)t.pcb_component.update(o.pcb_component_id,{pcb_group_id:i.pcb_group_id})}doInitialPcbPrimitiveRender(){var i;if((i=this.root)!=null&&i.pcbDisabled)return;const{db:t}=this.root,n=NY(this.children);this.pcb_group_id&&t.pcb_group.update(this.pcb_group_id,{width:n.width,height:n.height,center:{x:(n.minX+n.maxX)/2,y:(n.minY+n.maxY)/2}})}doInitialCreateTraceHintsFromProps(){var o;const{_parsedProps:t}=this,{db:n}=this.root,i=t;if(!this.isSubcircuit)return;const a=(o=i.layout)==null?void 0:o.manual_trace_hints;if(a)for(const s of a)this.add(new v0e({for:s.pcb_port_selector,offsets:s.offsets}))}doInitialSourceAddConnectivityMapKey(){Bst(this)}_areChildSubcircuitsRouted(){const t=this.selectAll("group").filter(n=>n.isSubcircuit);for(const n of t)if(n._shouldRouteAsync()&&!n._asyncAutoroutingResult)return!1;return!0}_shouldRouteAsync(){const t=this._getAutorouterConfig();return t.groupMode==="sequential-trace"?!1:!!(t.local&&t.groupMode==="subcircuit"||!t.local)}_hasTracesToRoute(){const t=KI("tscircuit:core:_hasTracesToRoute"),n=this.selectAll("trace");return t(`[${this.getString()}] has ${n.length} traces to route`),n.length>0}async _runEffectMakeHttpAutoroutingRequest(){var A,u,d,g;const{db:t}=this.root,n=KI("tscircuit:core:_runEffectMakeHttpAutoroutingRequest");this._parsedProps;const i=this._getAutorouterConfig(),a=i.serverUrl,o=i.serverMode,s=(m,C)=>{var E;return n("fetching",m),C.headers&&(C.headers["Tscircuit-Core-Version"]=(E=this.root)==null?void 0:E.getCoreVersion()),fetch(m,C)},l=this.root.db.toArray().filter(m=>m.type.startsWith("source_")||m.type.startsWith("pcb_"));if(o==="solve-endpoint"){if(((A=this.props.autorouter)==null?void 0:A.inputFormat)==="simplified"){const{autorouting_result:C}=await s(`${a}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_simple_route_json:I0e({db:t,minTraceWidth:((u=this.props.autorouter)==null?void 0:u.minTraceWidth)??.15,subcircuit_id:this.subcircuit_id}).simpleRouteJson,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(E=>E.json());this._asyncAutoroutingResult=C,this._markDirty("PcbTraceRender");return}const{autorouting_result:m}=await s(`${a}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_circuit_json:l,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(C=>C.json());this._asyncAutoroutingResult=m,this._markDirty("PcbTraceRender");return}const{autorouting_job:c}=await s(`${a}/autorouting/jobs/create`,{method:"POST",body:JSON.stringify({input_circuit_json:l,provider:"freerouting",autostart:!0,display_name:(d=this.root)==null?void 0:d.name,subcircuit_id:this.subcircuit_id,server_cache_enabled:i.serverCacheEnabled}),headers:{"Content-Type":"application/json"}}).then(m=>m.json());for(;;){const{autorouting_job:m}=await s(`${a}/autorouting/jobs/get`,{method:"POST",body:JSON.stringify({autorouting_job_id:c.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(C=>C.json());if(m.is_finished){const{autorouting_job_output:C}=await s(`${a}/autorouting/jobs/get_output`,{method:"POST",body:JSON.stringify({autorouting_job_id:c.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(E=>E.json());this._asyncAutoroutingResult={output_pcb_traces:C.output_pcb_traces},this._markDirty("PcbTraceRender");break}if(m.has_error)throw t.pcb_autorouting_error.insert({pcb_error_id:c.autorouting_job_id,message:((g=m.error)==null?void 0:g.message)??JSON.stringify(m.error)}),new Error(`Autorouting job failed: ${JSON.stringify(m.error)}`);await new Promise(C=>setTimeout(C,100))}}async _runLocalAutorouting(){var l,c,A,u,d;const{db:t}=this.root;this._parsedProps;const n=KI("tscircuit:core:_runLocalAutorouting");n(`[${this.getString()}] starting local autorouting`);const i=this._getAutorouterConfig(),{simpleRouteJson:a}=I0e({db:t,minTraceWidth:((l=this.props.autorouter)==null?void 0:l.minTraceWidth)??.15,subcircuit_id:this.subcircuit_id});(c=this.root)==null||c.emit("autorouting:start",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),simpleRouteJson:a});let o;i.algorithmFn?o=await i.algorithmFn(a):o=new Ist(a,{capacityDepth:(A=this.props.autorouter)==null?void 0:A.capacityDepth,targetMinCapacity:(u=this.props.autorouter)==null?void 0:u.targetMinCapacity});const s=new Promise((g,m)=>{o.on("complete",C=>{n(`[${this.getString()}] local autorouting complete`),g(C.traces)}),o.on("error",C=>{n(`[${this.getString()}] local autorouting error: ${C.error.message}`),m(C.error)})});o.on("progress",g=>{var m;(m=this.root)==null||m.emit("autorouting:progress",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),...g})}),o.start();try{const g=await s;this._asyncAutoroutingResult={output_pcb_traces:g},this._markDirty("PcbTraceRender")}catch(g){const{db:m}=this.root;throw m.pcb_autorouting_error.insert({pcb_error_id:`pcb_autorouter_error_subcircuit_${this.subcircuit_id}`,message:g instanceof Error?g.message:String(g)}),(d=this.root)==null||d.emit("autorouting:error",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),error:{message:g instanceof Error?g.message:String(g)},simpleRouteJson:a}),g}finally{o.stop()}}_startAsyncAutorouting(){this._hasStartedAsyncAutorouting||(this._hasStartedAsyncAutorouting=!0,this._getAutorouterConfig().local?this._queueAsyncEffect("capacity-mesh-autorouting",async()=>this._runLocalAutorouting()):this._queueAsyncEffect("make-http-autorouting-request",async()=>this._runEffectMakeHttpAutoroutingRequest()))}doInitialPcbTraceRender(){var n;const t=KI("tscircuit:core:doInitialPcbTraceRender");if(this.isSubcircuit&&!((n=this.root)!=null&&n.pcbDisabled)&&!this.getInheritedProperty("routingDisabled")&&!this._shouldUseTraceByTraceRouting()){if(!this._areChildSubcircuitsRouted()){t(`[${this.getString()}] child subcircuits are not routed, skipping async autorouting until subcircuits routed`);return}t(`[${this.getString()}] no child subcircuits to wait for, initiating async routing`),this._hasTracesToRoute()&&this._startAsyncAutorouting()}}updatePcbTraceRender(){var i;const t=KI("tscircuit:core:updatePcbTraceRender");if(t(`[${this.getString()}] updating...`),!this.isSubcircuit)return;if(this._shouldRouteAsync()&&this._hasTracesToRoute()&&!this._hasStartedAsyncAutorouting){this._areChildSubcircuitsRouted()&&(t(`[${this.getString()}] child subcircuits are now routed, starting async autorouting`),this._startAsyncAutorouting());return}if(!this._asyncAutoroutingResult||this._shouldUseTraceByTraceRouting())return;const{db:n}=this.root;if(this._asyncAutoroutingResult.output_simple_route_json){t(`[${this.getString()}] updating PCB traces from simple route json (${(i=this._asyncAutoroutingResult.output_simple_route_json.traces)==null?void 0:i.length} traces)`),this._updatePcbTraceRenderFromSimpleRouteJson();return}if(this._asyncAutoroutingResult.output_pcb_traces){t(`[${this.getString()}] updating PCB traces from ${this._asyncAutoroutingResult.output_pcb_traces.length} traces`),this._updatePcbTraceRenderFromPcbTraces();return}}_updatePcbTraceRenderFromSimpleRouteJson(){const{db:t}=this.root,{traces:n}=this._asyncAutoroutingResult.output_simple_route_json;if(n)for(const i of n)t.pcb_trace.insert({subcircuit_id:this.subcircuit_id,route:i.route})}_updatePcbTraceRenderFromPcbTraces(){const{output_pcb_traces:t}=this._asyncAutoroutingResult;if(!t)return;const{db:n}=this.root;for(const i of t)if(i.type==="pcb_trace"){if(i.subcircuit_id=this.subcircuit_id,i.connection_name){const a=i.connection_name;i.source_trace_id=a}n.pcb_trace.insert(i)}for(const i of t)if(i.type!=="pcb_via"&&i.type==="pcb_trace")for(const a of i.route)a.route_type==="via"&&n.pcb_via.insert({pcb_trace_id:i.pcb_trace_id,x:a.x,y:a.y,hole_diameter:.3,outer_diameter:.6,layers:[a.from_layer,a.to_layer],from_layer:a.from_layer,to_layer:a.to_layer})}doInitialSchematicComponentRender(){var a;if((a=this.root)!=null&&a.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=t.schematic_group.insert({is_subcircuit:this.isSubcircuit,subcircuit_id:this.subcircuit_id,name:this._parsedProps.name,center:this._getGlobalSchematicPositionBeforeLayout(),width:0,height:0,schematic_component_ids:[],source_group_id:this.source_group_id});this.schematic_group_id=i.schematic_group_id;for(const o of this.children)o.schematic_component_id&&t.schematic_component.update(o.schematic_component_id,{schematic_group_id:i.schematic_group_id})}_getSchematicLayoutMode(){var n,i,a;const t=this._parsedProps;return(n=t.schLayout)!=null&&n.matchAdapt?"match-adapt":(i=t.schLayout)!=null&&i.flex?"flex":(a=t.schLayout)!=null&&a.grid?"grid":t.matchAdapt?"match-adapt":t.flex?"flex":t.grid?"grid":"none"}doInitialSchematicLayout(){this._parsedProps;const t=this._getSchematicLayoutMode();t==="match-adapt"&&this._doInitialSchematicLayoutMatchAdapt(),t==="grid"&&this._doInitialSchematicLayoutGrid()}_doInitialSchematicLayoutMatchAdapt(){_st(this)}_doInitialSchematicLayoutGrid(){xst(this)}_getPcbLayoutMode(){var n,i,a;const t=this._parsedProps;return(n=t.pcbLayout)!=null&&n.matchAdapt?"match-adapt":(i=t.pcbLayout)!=null&&i.flex?"flex":(a=t.pcbLayout)!=null&&a.grid?"grid":t.matchAdapt?"match-adapt":t.flex?"flex":t.grid?"grid":"none"}doInitialPcbLayout(){this._getPcbLayoutMode()==="grid"&&this._doInitialPcbLayoutGrid()}_doInitialPcbLayoutGrid(){bst(this)}_determineSideFromPosition(t,n){if(!t.center||!n.center)return"left";const i=t.center.x-n.center.x,a=t.center.y-n.center.y;return Math.abs(i)>Math.abs(a)?i>0?"right":"left":a>0?"bottom":"top"}_calculateSchematicBounds(t){if(t.length===0)return{minX:0,maxX:0,minY:0,maxY:0};let n=1/0,i=-1/0,a=1/0,o=-1/0;for(const l of t)n=Math.min(n,l.centerX),i=Math.max(i,l.centerX),a=Math.min(a,l.centerY),o=Math.max(o,l.centerY);const s=2;return{minX:n-s,maxX:i+s,minY:a-s,maxY:o+s}}_getAutorouterConfig(){const t={serverUrl:"https://registry-api.tscircuit.com",serverMode:"job",serverCacheEnabled:!0},n=this._parsedProps.autorouter??this.getInheritedProperty("autorouter");return typeof n=="object"?{local:!(n.serverUrl||n.serverMode||n.serverCacheEnabled),...t,...n}:n==="auto-local"?{local:!0,groupMode:"subcircuit"}:n==="sequential-trace"?{local:!0,groupMode:"sequential-trace"}:n==="subcircuit"?{local:!0,groupMode:"subcircuit"}:n==="auto-cloud"?{local:!1,groupMode:"subcircuit",serverUrl:t.serverUrl,serverMode:t.serverMode,serverCacheEnabled:!0}:{local:!0,groupMode:"subcircuit"}}_shouldUseTraceByTraceRouting(){return this._getAutorouterConfig().groupMode==="sequential-trace"}doInitialPcbDesignRuleChecks(){var n;if((n=this.root)!=null&&n.pcbDisabled||this.getInheritedProperty("routingDisabled"))return;const{db:t}=this.root;if(this.isSubcircuit){const i=new Map;for(const a of this.children)if(!a.isSubcircuit&&a._parsedProps.name){const o=i.get(a._parsedProps.name)||[];o.push(a),i.set(a._parsedProps.name,o)}for(const[a,o]of i.entries())o.length>1&&t.pcb_trace_error.insert({error_type:"pcb_trace_error",message:`Multiple components found with name "${a}" in subcircuit "${this._parsedProps.name||"unnamed"}". Component names must be unique within a subcircuit.`,source_trace_id:"",pcb_trace_id:"",pcb_component_ids:o.map(s=>s.pcb_component_id).filter(Boolean),pcb_port_ids:[]})}}doInitialSchematicReplaceNetLabelsWithSymbols(){var n;if((n=this.root)!=null&&n.schematicDisabled)return;const{db:t}=this.root;for(const i of t.schematic_net_label.list()){const a=t.source_net.get(i.source_net_id),o=i.text||(a==null?void 0:a.name)||"";if(i.anchor_side==="top"&&/^gnd/i.test(o)){t.schematic_net_label.update(i.schematic_net_label_id,{symbol_name:"ground_down"});continue}i.anchor_side==="bottom"&&/^v/i.test(o)&&t.schematic_net_label.update(i.schematic_net_label_id,{symbol_name:"vcc_up"})}}},Sst=class extends FY{constructor(){super(...arguments);Ve(this,"pcb_board_id",null);Ve(this,"_drcChecksComplete",!1);Ve(this,"_connectedSchematicPortPairs",new Set)}get isSubcircuit(){return!0}get isGroup(){return!0}get config(){return{componentName:"Board",zodProps:RH}}get boardThickness(){const{_parsedProps:t}=this;return 1.4}get allLayers(){return["top","bottom","inner1","inner2"]}doInitialPcbBoardAutoSize(){var m;if((m=this.root)!=null&&m.pcbDisabled||!this.pcb_board_id)return;const{db:t}=this.root,{_parsedProps:n}=this;if(n.width&&n.height)return;let i=1/0,a=1/0,o=-1/0,s=-1/0;const l=t.pcb_component.list();let c=!1;for(const C of l){const{width:E,height:_,center:x}=C;E===0||_===0||(c=!0,i=Math.min(i,x.x-E/2),a=Math.min(a,x.y-_/2),o=Math.max(o,x.x+E/2),s=Math.max(s,x.y+_/2))}const A=2,u=c?o-i+A*2:0,d=c?s-a+A*2:0,g={x:c?(i+o)/2+(n.outlineOffsetX??0):n.outlineOffsetX??0,y:c?(a+s)/2+(n.outlineOffsetY??0):n.outlineOffsetY??0};t.pcb_board.update(this.pcb_board_id,{width:u,height:d,center:g})}doInitialPcbComponentRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this;let i=n.width??0,a=n.height??0;if(n.outline){const c=n.outline.map(C=>C.x),A=n.outline.map(C=>C.y),u=Math.min(...c),d=Math.max(...c),g=Math.min(...A),m=Math.max(...A);i=d-u,a=m-g}const o=t.pcb_board.insert({center:{x:(n.pcbX??0)+(n.outlineOffsetX??0),y:(n.pcbY??0)+(n.outlineOffsetY??0)},thickness:this.boardThickness,num_layers:this.allLayers.length,width:i,height:a,outline:(l=n.outline)==null?void 0:l.map(c=>({x:c.x+(n.outlineOffsetX??0),y:c.y+(n.outlineOffsetY??0)})),material:n.material});this.pcb_board_id=o.pcb_board_id}removePcbComponentRender(){const{db:t}=this.root;this.pcb_board_id&&(t.pcb_board.delete(this.pcb_board_id),this.pcb_board_id=null)}_computePcbGlobalTransformBeforeLayout(){return By()}doInitialPcbDesignRuleChecks(){var t;(t=this.root)!=null&&t.pcbDisabled||this.getInheritedProperty("routingDisabled")||super.doInitialPcbDesignRuleChecks()}updatePcbDesignRuleChecks(){var i;if((i=this.root)!=null&&i.pcbDisabled||this.getInheritedProperty("routingDisabled"))return;const{db:t}=this.root;if(!this._areChildSubcircuitsRouted()||this._drcChecksComplete)return;this._drcChecksComplete=!0;const n=Hpe(t.toArray());for(const a of n)t.pcb_trace_error.insert(a)}_emitRenderLifecycleEvent(t,n){var i;super._emitRenderLifecycleEvent(t,n),n==="start"&&((i=this.root)==null||i.emit("board:renderPhaseStarted",{renderId:this._renderId,phase:t}))}},Qst=new Proxy({},{get:(r,e)=>e}),vQ=Qst,wst=class extends m1{get config(){return{componentName:"Capacitor",schematicSymbolName:this.props.polarized?"capacitor_polarized":this.props.symbolName??"capacitor",zodProps:sge,sourceFtype:vQ.simple_capacitor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){const e=`${vx(this._parsedProps.capacitance)}F`;return this._parsedProps.schShowRatings&&this._parsedProps.maxVoltageRating?`${e}/${vx(this._parsedProps.maxVoltageRating)}V`:e}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.decouplingFor,this.props.decouplingTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.decouplingFor&&this.props.decouplingTo&&(this.add(new vS({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.decouplingFor})),this.add(new vS({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.decouplingTo}))),this._createTracesFromConnectionsProp()}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_capacitor",name:t.name,manufacturer_part_number:t.manufacturerPartNumber??t.mfn,supplier_part_numbers:t.supplierPartNumbers,capacitance:t.capacitance,max_voltage_rating:t.maxVoltageRating,max_decoupling_trace_length:t.maxDecouplingTraceLength,display_capacitance:this._getSchematicSymbolDisplayValue(),are_pins_interchangeable:!t.polarized});this.source_component_id=n.source_component_id}},C0e=class extends m1{constructor(){super(...arguments);Ve(this,"schematicBoxDimensions",null)}get config(){return{componentName:"Chip",zodProps:NH,shouldRenderAsSchematicBox:!0}}doInitialSchematicComponentRender(){const{_parsedProps:t}=this;(t==null?void 0:t.noSchematicRepresentation)!==!0&&super.doInitialSchematicComponentRender()}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_chip",name:n.name,manufacturer_part_number:n.manufacturerPartNumber,supplier_part_numbers:n.supplierPartNumbers});this.source_component_id=i.source_component_id}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=t.pcb_component.insert({center:{x:n.pcbX??0,y:n.pcbY??0},width:2,height:3,layer:n.layer??"top",rotation:n.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.pcb_component_id=i.pcb_component_id}doInitialCreateTracesFromProps(){const{_parsedProps:t}=this;if(t.externallyConnectedPins)for(const[n,i]of t.externallyConnectedPins)this.add(new vS({from:`${this.getSubcircuitSelector()} > port.${n}`,to:`${this.getSubcircuitSelector()} > port.${i}`}));this._createTracesFromConnectionsProp()}},Mst=class extends m1{constructor(){super(...arguments);Ve(this,"pos",this.portMap.pin1);Ve(this,"anode",this.portMap.pin1);Ve(this,"neg",this.portMap.pin2);Ve(this,"cathode",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"diode",componentName:"Diode",zodProps:Ege,sourceFtype:"simple_diode"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_diode",name:n.name,manufacturer_part_number:n.manufacturerPartNumber??n.mfn,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},Dst=class extends m1{get config(){return{componentName:"fuse",schematicSymbolName:this.props.symbolName??"fuse",zodProps:Ctt,sourceFtype:vQ.simple_fuse}}_getSchematicSymbolDisplayValue(){const r=this._parsedProps.currentRating,e=this._parsedProps.voltageRating,t=typeof r=="string"?parseFloat(r):r,n=typeof e=="string"?parseFloat(e):e;return`${vx(t)}A / ${vx(n)}V`}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=typeof e.currentRating=="string"?parseFloat(e.currentRating):e.currentRating,n=typeof e.voltageRating=="string"?parseFloat(e.voltageRating):e.voltageRating,i=r.source_component.insert({name:e.name,ftype:vQ.simple_fuse,current_rating_amps:t,voltage_rating_volts:n,display_current_rating:`${vx(t)}A`,display_voltage_rating:`${vx(n)}V`});this.source_component_id=i.source_component_id}},Rst=class extends m1{constructor(){super(...arguments);Ve(this,"schematicDimensions",null)}get config(){let t="";if(this.props.pinCount&&(t+=`solderjumper${this.props.pinCount||2}`),Array.isArray(this.props.internallyConnectedPins)&&this.props.internallyConnectedPins.length>0){const n=Array.from(new Set(this.props.internallyConnectedPins.flat())).sort().join("");t+=`_bridged${n}`}return{schematicSymbolName:t,componentName:"Jumper",zodProps:ege,shouldRenderAsSchematicBox:!0}}_getSchematicPortArrangement(){const t=super._getSchematicPortArrangement();if(t)return t;const n=this._parsedProps.pinCount??(Array.isArray(this._parsedProps.pinLabels)?this._parsedProps.pinLabels.length:this._parsedProps.pinLabels?Object.keys(this._parsedProps.pinLabels).length:this.getPortsFromFootprint().length),i=this._parsedProps.schDirection??"right";return{leftSize:i==="left"?n:0,rightSize:i==="right"?n:0}}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_chip",name:n.name,manufacturer_part_number:n.manufacturerPartNumber,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=i.source_component_id}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=t.pcb_component.insert({center:{x:n.pcbX??0,y:n.pcbY??0},width:2,height:3,layer:n.layer??"top",rotation:n.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.pcb_component_id=i.pcb_component_id}doInitialPcbTraceRender(){const{db:t}=this.root,n=t.pcb_port.list({pcb_component_id:this.pcb_component_id}),i={};for(let s=0;s<n.length;s++){const l=n[s],c=t.source_port.get(l.source_port_id);let A="";if(typeof(c==null?void 0:c.pin_number)=="number")A=c.pin_number.toString();else if(Array.isArray(c==null?void 0:c.port_hints)){let u=c.port_hints.find(d=>/^(pin)?\d+$/.test(d));u&&(/^pin\d+$/.test(u)?A=u.replace(/^pin/,""):A=u)}i[A]=l.pcb_port_id}const a=t.pcb_trace.list(),o=s=>{if(s&&typeof s=="string"&&s.startsWith("{PIN")){const l=s.replace("{PIN","").replace("}","");return i[l]||s}return s};for(const s of a)if(s.route)for(const l of s.route)l.route_type==="wire"&&(l.start_pcb_port_id=o(l.start_pcb_port_id),l.end_pcb_port_id=o(l.end_pcb_port_id))}},Nst=class extends m1{constructor(){super(...arguments);Ve(this,"pos",this.portMap.pin1);Ve(this,"anode",this.portMap.pin1);Ve(this,"neg",this.portMap.pin2);Ve(this,"cathode",this.portMap.pin2)}get config(){return{componentName:"Led",schematicSymbolName:this.props.symbolName??"led",zodProps:_ge,sourceFtype:"simple_led"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return this._parsedProps.schDisplayValue||this._parsedProps.color||void 0}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_led",name:n.name,wave_length:n.wavelength,color:n.color,symbol_display_value:this._getSchematicSymbolDisplayValue(),manufacturer_part_number:n.manufacturerPartNumber??n.mfn,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},Tst=class extends m1{constructor(){super(...arguments);Ve(this,"pos",this.portMap.pin1);Ve(this,"positive",this.portMap.pin1);Ve(this,"neg",this.portMap.pin2);Ve(this,"negative",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"power_factor_meter_horz",componentName:"PowerSource",zodProps:wge,sourceFtype:"simple_power_source"}}initPorts(){this.add(new yS({name:"pin1",pinNumber:1,aliases:["positive","pos"]})),this.add(new yS({name:"pin2",pinNumber:2,aliases:["negative","neg"]}))}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_power_source",name:n.name,voltage:n.voltage,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},Pst=class extends m1{get config(){return{componentName:"Resistor",schematicSymbolName:this.props.symbolName??"boxresistor",zodProps:rge,sourceFtype:"simple_resistor"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${vx(this._parsedProps.resistance)}Ω`}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.pullupFor,this.props.pullupTo,this.props.pulldownFor,this.props.pulldownTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.pullupFor&&this.props.pullupTo&&(this.add(new vS({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pullupFor})),this.add(new vS({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pullupTo}))),this.props.pulldownFor&&this.props.pulldownTo&&(this.add(new vS({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pulldownFor})),this.add(new vS({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pulldownTo}))),this._createTracesFromConnectionsProp()}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_resistor",name:t.name,manufacturer_part_number:t.manufacturerPartNumber??t.mfn,supplier_part_numbers:t.supplierPartNumbers,resistance:t.resistance,display_resistance:this._getSchematicSymbolDisplayValue(),are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}},Ust=["leftedge","rightedge","topedge","bottomedge","center"],Fst=class extends Kv{get config(){return{componentName:"Constraint",zodProps:lge}}constructor(e){if(super(e),("xdist"in e||"ydist"in e)&&!("edgeToEdge"in e)&&!("centerToCenter"in e))throw new Error(`edgeToEdge, centerToCenter must be set for xDist or yDist for ${this}`);if("for"in e&&e.for.length<2)throw new Error(`"for" must have at least two selectors for ${this}`)}_getAllReferencedComponents(){const e=[],t=this.getPrimitiveContainer();function n(i){const a=i.split(" ").pop(),o=Ust.includes(a)?a:void 0,s=o?i.replace(` ${o}`,""):i,l=t.selectOne(s,{pcbPrimitive:!0});l&&e.push({selector:i,component:l,componentSelector:s,edge:o})}for(const i of["left","right","top","bottom"])i in this._parsedProps&&n(this._parsedProps[i]);if("for"in this._parsedProps)for(const i of this._parsedProps.for)n(i);return{componentsWithSelectors:e}}},kst=class extends Kv{constructor(){super(...arguments);Ve(this,"fabrication_note_path_id",null)}get config(){return{componentName:"FabricationNotePath",zodProps:bge}}doInitialPcbPrimitiveRender(){var l,c;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,n=this.getSubcircuit(),{_parsedProps:i}=this,a=i.layer??"top";if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenPath. Must be "top" or "bottom".`);const o=this._computePcbGlobalTransformBeforeLayout(),s=t.pcb_fabrication_note_path.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,color:i.color,route:i.route.map(A=>{const u=si(o,{x:A.x,y:A.y});return{...A,x:u.x,y:u.y}}),stroke_width:i.strokeWidth??.1,subcircuit_id:(n==null?void 0:n.subcircuit_id)??void 0});this.fabrication_note_path_id=s.pcb_fabrication_note_path_id}},Gst=class extends Kv{get config(){return{componentName:"FabricationNoteText",zodProps:xge}}doInitialPcbPrimitiveRender(){var a,o;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=this.getPrimitiveContainer(),i=this.getSubcircuit();e.pcb_fabrication_note_text.insert({anchor_alignment:t.anchorAlignment,anchor_position:{x:t.pcbX??0,y:t.pcbY??0},font:t.font??"tscircuit2024",font_size:t.fontSize??1,layer:"top",color:t.color,text:t.text??"",pcb_component_id:n.pcb_component_id,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((o=this.getGroup())==null?void 0:o.pcb_group_id)??void 0})}},Lst=class extends FY{constructor(e){super({...e,subcircuit:!0})}},Ost=class extends Kv{constructor(){super(...arguments);Ve(this,"source_net_alias_id")}get config(){return{componentName:"NetAlias",zodProps:mge}}doInitialSchematicComponentRender(){var o;if((o=this.root)!=null&&o.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i={x:n.schX??0,y:n.schY??0},a=t.schematic_net_label.insert({text:n.net,source_net_id:n.net,anchor_position:i,center:i,anchor_side:"bottom"});this.source_net_alias_id=a.source_net_id}},zst=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_silkscreen_circle_id",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenCircle",zodProps:Uge}}doInitialPcbPrimitiveRender(){var l,c,A;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(n.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenCircle. Must be "top" or "bottom".`);this._computePcbGlobalTransformBeforeLayout();const o=this.getSubcircuit(),s=t.pcb_silkscreen_circle.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,center:{x:n.pcbX??0,y:n.pcbY??0},radius:n.radius,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((A=this.getGroup())==null?void 0:A.pcb_group_id)??void 0,stroke_width:n.strokeWidth??.1});this.pcb_silkscreen_circle_id=s.pcb_silkscreen_circle_id}getPcbSize(){const{_parsedProps:t}=this,n=t.radius*2;return{width:n,height:n}}},Hst=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_silkscreen_rect_id",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenRect",zodProps:Pge}}doInitialPcbPrimitiveRender(){var l,c,A;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(n.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenRect. Must be "top" or "bottom".`);const o=this.getSubcircuit(),s=t.pcb_silkscreen_rect.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,center:{x:n.pcbX??0,y:n.pcbY??0},width:n.width,height:n.height,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((A=this==null?void 0:this.getGroup())==null?void 0:A.pcb_group_id)??void 0,stroke_width:n.strokeWidth??.1});this.pcb_silkscreen_rect_id=s.pcb_silkscreen_rect_id}getPcbSize(){const{_parsedProps:t}=this;return{width:t.width,height:t.height}}},Yst=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_silkscreen_line_id",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenLine",zodProps:Tge}}doInitialPcbPrimitiveRender(){var l,c,A;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(n.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenLine. Must be "top" or "bottom".`);const o=this.getSubcircuit(),s=t.pcb_silkscreen_line.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2,stroke_width:n.strokeWidth??.1,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((A=o==null?void 0:o.getGroup())==null?void 0:A.pcb_group_id)??void 0});this.pcb_silkscreen_line_id=s.pcb_silkscreen_line_id}getPcbSize(){const{_parsedProps:t}=this,n=Math.abs(t.x2-t.x1),i=Math.abs(t.y2-t.y1);return{width:n,height:i}}},Vst=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_via_id",null);Ve(this,"matchedPort",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Via",zodProps:Sge}}getAvailablePcbLayers(){return["top","inner1","inner2","bottom"]}getPcbSize(){const{_parsedProps:t}=this;return{width:t.outerDiameter,height:t.outerDiameter}}_getPcbCircuitJsonBounds(){const{db:t}=this.root,n=t.pcb_via.get(this.pcb_via_id),i=this.getPcbSize();return{center:{x:n.x,y:n.y},bounds:{left:n.x-i.width/2,top:n.y-i.height/2,right:n.x+i.width/2,bottom:n.y+i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(t){const{db:n}=this.root;n.pcb_via.update(this.pcb_via_id,{x:t.x,y:t.y})}doInitialPcbPrimitiveRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalPcbPositionBeforeLayout(),a=this.getSubcircuit(),o=t.pcb_via.insert({x:i.x,y:i.y,hole_diameter:n.holeDiameter,outer_diameter:n.outerDiameter,layers:["bottom","top"],from_layer:n.fromLayer||"bottom",to_layer:n.toLayer||"top",subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((l=this.getGroup())==null?void 0:l.pcb_group_id)??void 0});this.pcb_via_id=o.pcb_via_id}},Kst=class extends Kv{constructor(){super(...arguments);Ve(this,"pcb_cutout_id",null);Ve(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Cutout",zodProps:cge}}doInitialPcbPrimitiveRender(){var l,c;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getSubcircuit(),a=((c=this.getGroup())==null?void 0:c.pcb_group_id)??void 0,o=this._getGlobalPcbPositionBeforeLayout();let s;if(n.shape==="rect"){const A={shape:"rect",center:o,width:n.width,height:n.height,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:a};s=t.pcb_cutout.insert(A)}else if(n.shape==="circle"){const A={shape:"circle",center:o,radius:n.radius,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:a};s=t.pcb_cutout.insert(A)}else if(n.shape==="polygon"){const A=this._computePcbGlobalTransformBeforeLayout(),d={shape:"polygon",points:n.points.map(g=>si(A,g)),subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:a};s=t.pcb_cutout.insert(d)}s&&(this.pcb_cutout_id=s.pcb_cutout_id)}getPcbSize(){const{_parsedProps:t}=this;if(t.shape==="rect")return{width:t.width,height:t.height};if(t.shape==="circle")return{width:t.radius*2,height:t.radius*2};if(t.shape==="polygon"){if(t.points.length===0)return{width:0,height:0};let n=1/0,i=-1/0,a=1/0,o=-1/0;for(const s of t.points)n=Math.min(n,s.x),i=Math.max(i,s.x),a=Math.min(a,s.y),o=Math.max(o,s.y);return{width:i-n,height:o-a}}return{width:0,height:0}}_getPcbCircuitJsonBounds(){if(!this.pcb_cutout_id)return super._getPcbCircuitJsonBounds();const{db:t}=this.root,n=t.pcb_cutout.get(this.pcb_cutout_id);if(!n)return super._getPcbCircuitJsonBounds();if(n.shape==="rect")return{center:n.center,bounds:{left:n.center.x-n.width/2,top:n.center.y+n.height/2,right:n.center.x+n.width/2,bottom:n.center.y-n.height/2},width:n.width,height:n.height};if(n.shape==="circle")return{center:n.center,bounds:{left:n.center.x-n.radius,top:n.center.y+n.radius,right:n.center.x+n.radius,bottom:n.center.y-n.radius},width:n.radius*2,height:n.radius*2};if(n.shape==="polygon"){if(n.points.length===0)return super._getPcbCircuitJsonBounds();let i=1/0,a=-1/0,o=1/0,s=-1/0;for(const l of n.points)i=Math.min(i,l.x),a=Math.max(a,l.x),o=Math.min(o,l.y),s=Math.max(s,l.y);return{center:{x:(i+a)/2,y:(o+s)/2},bounds:{left:i,top:s,right:a,bottom:o},width:a-i,height:s-o}}return super._getPcbCircuitJsonBounds()}_setPositionFromLayout(t){if(!this.pcb_cutout_id)return;const{db:n}=this.root,i=n.pcb_cutout.get(this.pcb_cutout_id);if(i){if(i.shape==="rect"||i.shape==="circle")n.pcb_cutout.update(this.pcb_cutout_id,{...i,center:t});else if(i.shape==="polygon"){const a=this._getPcbCircuitJsonBounds().center,o=t.x-a.x,s=t.y-a.y,l=i.points.map(c=>({x:c.x+o,y:c.y+s}));n.pcb_cutout.update(this.pcb_cutout_id,{...i,points:l})}}}},Jst=class extends m1{get config(){return{componentName:"Battery",schematicSymbolName:this.props.symbolName??"battery",zodProps:gge,sourceFtype:"simple_power_source"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:t.name,ftype:"simple_power_source",capacity:t.capacity,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=n.source_component_id}},jst=class extends m1{get config(){return{componentName:"PinHeader",zodProps:pge,shouldRenderAsSchematicBox:!0}}_getImpliedFootprintString(){var a;const e=this._parsedProps.pinCount??((a=this._parsedProps.pinLabels)==null?void 0:a.length)??0,t=this._parsedProps.holeDiameter,n=this._parsedProps.platedDiameter,i=this._parsedProps.pitch;return e>0&&i?!t&&!n?`pinrow${e}_p${i}`:`pinrow${e}_p${i}_id${t}_od${n}`:null}initPorts(){var t,n;const e=this._parsedProps.pinCount??((t=this._parsedProps.pinLabels)==null?void 0:t.length)??1;for(let i=1;i<=e;i++)this.add(new yS({name:`pin${i}`,pinNumber:i,aliases:[(n=this._parsedProps.pinLabels)==null?void 0:n[i-1]].filter(Boolean)}))}_getSchematicPortArrangement(){var i,a,o,s;const e=this._parsedProps.pinCount??1,t=this._parsedProps.facingDirection??"right",n=this._parsedProps.schPinArrangement;return t==="left"?{leftSide:{direction:((i=n==null?void 0:n.leftSide)==null?void 0:i.direction)??"top-to-bottom",pins:((a=n==null?void 0:n.leftSide)==null?void 0:a.pins)??Array.from({length:e},(l,c)=>`pin${c+1}`)}}:{rightSide:{direction:((o=n==null?void 0:n.rightSide)==null?void 0:o.direction)??"top-to-bottom",pins:((s=n==null?void 0:n.rightSide)==null?void 0:s.pins)??Array.from({length:e},(l,c)=>`pin${c+1}`)}}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_pin_header",name:t.name,supplier_part_numbers:t.supplierPartNumbers,pin_count:t.pinCount,gender:t.gender,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}};function Wst(r){switch(r){case"two_ground_pins":return"crystal_4pin";case"ground_pin":return"resonator";case"no_ground":return"crystal";default:return"crystal"}}var Zst=class extends m1{get config(){return{componentName:"Resonator",schematicSymbolName:this.props.symbolName??Wst(this.props.pinVariant),zodProps:oge,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=t.pinVariant||"no_ground",i=e.source_component.insert({ftype:"simple_resonator",name:t.name,frequency:t.frequency,load_capacitance:t.loadCapacitance,supplier_part_numbers:t.supplierPartNumbers,pin_variant:n,are_pins_interchangeable:n==="no_ground"||n==="ground_pin"});this.source_component_id=i.source_component_id}},qst=class extends m1{get config(){return{componentName:"Inductor",schematicSymbolName:this.props.symbolName??"inductor",zodProps:Cge,sourceFtype:vQ.simple_inductor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:t.name,ftype:vQ.simple_inductor,inductance:t.inductance,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}};function Xst(r){switch(r){case"three_pin":return"potentiometer3";case"two_pin":return"potentiometer2";default:return"potentiometer2"}}var $st=class extends m1{get config(){return{componentName:"Potentiometer",schematicSymbolName:this.props.symbolName??Xst(this.props.pinVariant),zodProps:ige,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=t.pinVariant||"two_pin",i=e.source_component.insert({ftype:"simple_potentiometer",name:t.name,max_resistance:t.maxResistance,pin_variant:n,are_pins_interchangeable:n==="two_pin"});this.source_component_id=i.source_component_id}},elt=class extends m1{get config(){return{componentName:"PushButton",schematicSymbolName:this.props.symbolName??"push_button_normally_open_momentary",zodProps:yge,sourceFtype:vQ.simple_push_button}}get defaultInternallyConnectedPinNames(){return[["pin1","pin4"],["pin2","pin3"]]}initPorts(){super.initPorts({pinCount:4,additionalAliases:{pin1:["side1"],pin3:["side2"]}})}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:t.name,ftype:vQ.simple_push_button,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}},tlt=class extends m1{get config(){return{schematicSymbolName:this.props.symbolName??(this.props.pinVariant==="four_pin"?"crystal_4pin":"crystal"),componentName:"Crystal",zodProps:age,sourceFtype:"simple_crystal"}}initPorts(){const e=this.props.pinVariant==="four_pin"?{pin1:["left1","1"],pin2:["top1","2","gnd1"],pin3:["right1","3"],pin4:["bottom1","4","gnd2"]}:{pin1:["pos","left"],pin2:["neg","right"]};super.initPorts({additionalAliases:e})}_getSchematicSymbolDisplayValue(){return`${vx(this._parsedProps.frequency)}Hz`}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:t.name,ftype:"simple_crystal",frequency:t.frequency,load_capacitance:t.loadCapacitance,pin_variant:t.pinVariant||"two_pin",are_pins_interchangeable:(t.pinVariant||"two_pin")==="two_pin"});this.source_component_id=n.source_component_id}},nlt=class extends m1{constructor(){super(...arguments);Ve(this,"emitter",this.portMap.pin1);Ve(this,"collector",this.portMap.pin2);Ve(this,"base",this.portMap.pin3)}get config(){return{componentName:"Transistor",schematicSymbolName:this.props.type==="npn"?"npn_bipolar_transistor":"pnp_bipolar_transistor",zodProps:vge,sourceFtype:"simple_transistor",shouldRenderAsSchematicBox:!1}}initPorts(){const t=this.props.type==="npn"?{pin1:["emitter","e"],pin2:["collector","c"],pin3:["base","b"]}:{pin1:["collector","c"],pin2:["emitter","e"],pin3:["base","b"]};super.initPorts({pinCount:3,additionalAliases:t})}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_transistor",name:n.name,transistor_type:n.type});this.source_component_id=i.source_component_id}},rlt=class extends m1{get config(){const e=this.props.mosfetMode==="depletion"?"d":"e";return{componentName:"Mosfet",schematicSymbolName:`${this.props.channelType}_channel_${e}_mosfet_transistor`,zodProps:Ige,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_mosfet",name:t.name,mosfet_mode:t.mosfetMode,channel_type:t.channelType});this.source_component_id=n.source_component_id}},ilt=class extends m1{_getSwitchType(){const{spst:e,spdt:t,dpst:n,dpdt:i,type:a}=this._parsedProps??{};return i?"dpdt":e?"spst":t?"spdt":n?"dpst":a??"spst"}get config(){const e=this._getSwitchType(),{isNormallyClosed:t}=this._parsedProps??{};return{componentName:"Switch",schematicSymbolName:{spst:t?"spst_normally_closed_switch":"spst_switch",spdt:t?"spdt_normally_closed_switch":"spdt_switch",dpst:t?"dpst_normally_closed_switch":"dpst_switch",dpdt:t?"dpdt_normally_closed_switch":"dpdt_switch"}[e]??"spst_switch",zodProps:Bge,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_switch",name:t.name,switch_type:t.type,is_normally_closed:t.isNormallyClosed??!1,are_pins_interchangeable:this._getSwitchType()==="spst"});this.source_component_id=n.source_component_id}},alt=class extends Kv{constructor(){super(...arguments);Ve(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicText",zodProps:Dge}}doInitialSchematicPrimitiveRender(){var i;if((i=this.root)!=null&&i.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this;t.schematic_text.insert({anchor:n.anchor??"center",text:n.text,font_size:n.fontSize,color:n.color||"#000000",position:{x:n.schX,y:n.schY},rotation:n.schRotation??0})}},olt=class extends Kv{constructor(){super(...arguments);Ve(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicBox",zodProps:Mge,shouldRenderAsSchematicBox:!0}}doInitialSchematicPrimitiveRender(){var E;if((E=this.root)!=null&&E.schematicDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=Mge.safeParse(t);if(!n.success)throw console.error("Validation failed:",n.error.format()),n.error;const i=.6,a=typeof t.padding=="number"?t.padding:0,o=typeof t.paddingTop=="number"?t.paddingTop:a,s=typeof t.paddingBottom=="number"?t.paddingBottom:a,l=typeof t.paddingLeft=="number"?t.paddingLeft:a,c=typeof t.paddingRight=="number"?t.paddingRight:a,A=t.overlay&&t.overlay.length>0,u=typeof t.width=="number"&&typeof t.height=="number";let d,g,m,C;if(A){const x=t.overlay.map(Ue=>({selector:Ue,port:this.getSubcircuit().selectOne(Ue,{type:"port"})})).filter(({port:Ue})=>Ue!=null).map(({port:Ue})=>({position:Ue._getGlobalSchematicPositionAfterLayout()}));if(x.length===0)return;const Q=x.map(Ue=>Ue.position.x),P=x.map(Ue=>Ue.position.y),z=Math.min(...Q),O=Math.max(...Q),V=Math.min(...P),j=Math.max(...P),q=O-z,J=j-V,ce=q===0?i:0,oe=J===0?i:0,de=l+ce/2,Ie=c+ce/2,Be=o+oe/2,pe=s+oe/2,_e=z-de,ve=O+Ie,Ne=V-pe,we=j+Be;d=ve-_e,g=we-Ne,m=_e+(t.schX??0),C=Ne+(t.schY??0)}else if(u){d=t.width,g=t.height;const _=typeof t.schX=="number"?t.schX:0,x=typeof t.schY=="number"?t.schY:0;m=_-d/2,C=x-g/2}else return;e.schematic_box.insert({height:g,width:d,x:m,y:C,is_dashed:t.strokeStyle==="dashed",schematic_component_id:""})}},slt={version:"0.0.448"},llt=class{constructor({platform:r}={}){Ve(this,"firstChild",null);Ve(this,"children");Ve(this,"db");Ve(this,"root",null);Ve(this,"isRoot",!0);Ve(this,"schematicDisabled",!1);Ve(this,"pcbDisabled",!1);Ve(this,"pcbRoutingDisabled",!1);Ve(this,"name");Ve(this,"platform");Ve(this,"_hasRenderedAtleastOnce",!1);Ve(this,"_eventListeners",{});this.children=[],this.db=$E([]),this.root=this,this.platform=r}add(r){let e;yt.isValidElement(r)?e=i0e(r):e=r,this.children.push(e)}_getBoard(){return this.children.find(r=>r.componentName==="Board")}_guessRootComponent(){if(!this.firstChild){if(this.children.length===1){this.firstChild=this.children[0];return}if(this.children.length===0)throw new Error("Not able to guess root component: RootCircuit has no children (use circuit.add(...))");if(this.children.length>0){const r=this.children.find(e=>e.componentName==="Board")??null;if(r){this.firstChild=r;return}}throw new Error("Not able to guess root component: RootCircuit has multiple children and no board")}}render(){this.firstChild||this._guessRootComponent();const{firstChild:r,db:e}=this;if(!r)throw new Error("RootCircuit has no root component");r.parent=this,r.runRenderCycle(),this._hasRenderedAtleastOnce=!0}async renderUntilSettled(){var r;for((r=this.db.source_project_metadata.list())!=null&&r[0]||this.db.source_project_metadata.insert({software_used_string:`@tscircuit/core@${this.getCoreVersion()}`}),this.render();this._hasIncompleteAsyncEffects();)await new Promise(e=>setTimeout(e,100)),this.render();this.emit("renderComplete")}_hasIncompleteAsyncEffects(){return this.children.some(r=>r._hasIncompleteAsyncEffects()?!0:r.children.some(e=>e._hasIncompleteAsyncEffects()))}getCircuitJson(){return this._hasRenderedAtleastOnce||this.render(),this.db.toArray()}toJson(){return this.getCircuitJson()}async getSvg(r){const e=await Promise.resolve().then(()=>rkt).catch(t=>{throw new Error(`To use circuit.getSvg, you must install the "circuit-to-svg" package.
|
|
855
855
|
|
|
856
856
|
"${t.message}"`)});if(r.view==="pcb")return e.convertCircuitJsonToPcbSvg(this.getCircuitJson());if(r.view==="schematic")return e.convertCircuitJsonToSchematicSvg(this.getCircuitJson());throw new Error(`Invalid view: ${r.view}`)}getCoreVersion(){const[r,e,t]=slt.version.split(".").map(Number);return`${r}.${e}.${t+1}`}async preview(r){throw new Error("project.preview is not yet implemented")}computeSchematicGlobalTransform(){return By()}_computePcbGlobalTransformBeforeLayout(){return By()}selectAll(r){var e;return this._guessRootComponent(),((e=this.firstChild)==null?void 0:e.selectAll(r))??[]}selectOne(r,e){var t;return this._guessRootComponent(),((t=this.firstChild)==null?void 0:t.selectOne(r,e))??null}emit(r,...e){if(this._eventListeners[r])for(const t of this._eventListeners[r])t(...e)}on(r,e){this._eventListeners[r]||(this._eventListeners[r]=[]),this._eventListeners[r].push(e)}removeListener(r,e){this._eventListeners[r]&&(this._eventListeners[r]=this._eventListeners[r].filter(t=>t!==e))}getClientOrigin(){return typeof window<"u"?window.location.origin:typeof self<"u"?self.origin:""}},clt=llt;new Proxy({},{get:(r,e)=>{const t=(...n)=>(n[0],new Proxy({},{get:(i,a)=>`.${e} > .${a}`}));return new Proxy(t,{get:(n,i)=>e==="net"?`net.${i}`:e==="subcircuit"?new Proxy({},{get:(a,o)=>new Proxy({},{get:(s,l)=>`subcircuit.${i} > .${o} > .${l}`})}):`.${e} > .${i}`,apply:(n,i,a)=>new Proxy({},{get:(o,s)=>{const l=`.${e} > .${s}`;return e.startsWith("U")?l:new Proxy(new String(l),{get:(c,A)=>typeof A=="symbol"||A==="toString"?()=>l:`.${e} > .${s} > .${A}`})}})})}}),e0e(Xpe),e0e({Bug:C0e});var kY,E0e;function Of(){if(E0e)return kY;E0e=1;const r=e=>e.reduce((t,n)=>Array.isArray(n)?t.concat(r(n)):t.concat(n),[]);return kY=r,kY}var GY,_0e;function Alt(){return _0e||(_0e=1,GY=e=>Object.assign({},e)),GY}var LY,B0e;function ult(){return B0e||(B0e=1,LY=(e,t,n)=>(e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e[3]=t[3]+n[3],e[4]=t[4]+n[4],e[5]=t[5]+n[5],e[6]=t[6]+n[6],e[7]=t[7]+n[7],e[8]=t[8]+n[8],e[9]=t[9]+n[9],e[10]=t[10]+n[10],e[11]=t[11]+n[11],e[12]=t[12]+n[12],e[13]=t[13]+n[13],e[14]=t[14]+n[14],e[15]=t[15]+n[15],e)),LY}var OY,x0e;function zY(){return x0e||(x0e=1,OY=()=>[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),OY}var HY,b0e;function dlt(){if(b0e)return HY;b0e=1;const r=zY();return HY=t=>{const n=r();return n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=t[3],n[4]=t[4],n[5]=t[5],n[6]=t[6],n[7]=t[7],n[8]=t[8],n[9]=t[9],n[10]=t[10],n[11]=t[11],n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15],n},HY}var YY,S0e;function Q0e(){return S0e||(S0e=1,YY=(e,t)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e)),YY}var VY,w0e;function flt(){return w0e||(w0e=1,VY=(e,t)=>{const n=t[0],i=t[1],a=t[2],o=t[3],s=t[4],l=t[5],c=t[6],A=t[7],u=t[8],d=t[9],g=t[10],m=t[11],C=t[12],E=t[13],_=t[14],x=t[15],Q=n*l-i*s,P=n*c-a*s,z=n*A-o*s,O=i*c-a*l,V=i*A-o*l,j=a*A-o*c,q=u*E-d*C,J=u*_-g*C,ce=u*x-m*C,oe=d*_-g*E,de=d*x-m*E,Ie=g*x-m*_;let Be=Q*Ie-P*de+z*oe+O*ce-V*J+j*q;return Be?(Be=1/Be,e[0]=(l*Ie-c*de+A*oe)*Be,e[1]=(a*de-i*Ie-o*oe)*Be,e[2]=(E*j-_*V+x*O)*Be,e[3]=(g*V-d*j-m*O)*Be,e[4]=(c*ce-s*Ie-A*J)*Be,e[5]=(n*Ie-a*ce+o*J)*Be,e[6]=(_*z-C*j-x*P)*Be,e[7]=(u*j-g*z+m*P)*Be,e[8]=(s*de-l*ce+A*q)*Be,e[9]=(i*ce-n*de-o*q)*Be,e[10]=(C*V-E*z+x*Q)*Be,e[11]=(d*z-u*V-m*Q)*Be,e[12]=(l*J-s*oe-c*q)*Be,e[13]=(n*oe-i*J+a*q)*Be,e[14]=(E*P-C*O-_*Q)*Be,e[15]=(u*O-d*P+g*Q)*Be,e):null}),VY}var KY,M0e;function hlt(){return M0e||(M0e=1,KY=(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15]),KY}var JY,D0e;function Hp(){if(D0e)return JY;D0e=1;const r=1e5,e=1e-5,t=1e-13,n=Math.PI*2;return JY={EPS:e,NEPS:t,TAU:n,spatialResolution:r},JY}var jY,R0e;function e_(){if(R0e)return jY;R0e=1;const{NEPS:r}=Hp(),e=i=>Math.abs(i)<r?0:i;return jY={sin:i=>e(Math.sin(i)),cos:i=>e(Math.cos(i))},jY}var WY,N0e;function T0e(){return N0e||(N0e=1,WY=e=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e)),WY}var ZY,P0e;function U0e(){if(P0e)return ZY;P0e=1;const{EPS:r}=Hp(),{sin:e,cos:t}=e_(),n=T0e();return ZY=(a,o,s)=>{let[l,c,A]=s;const u=l*l+c*c+A*A;if(Math.abs(u)<r)return n(a);const d=1/Math.sqrt(u);l*=d,c*=d,A*=d;const g=e(o),m=t(o),C=1-m;return a[0]=l*l*C+m,a[1]=c*l*C+A*g,a[2]=A*l*C-c*g,a[3]=0,a[4]=l*c*C-A*g,a[5]=c*c*C+m,a[6]=A*c*C+l*g,a[7]=0,a[8]=l*A*C+c*g,a[9]=c*A*C-l*g,a[10]=A*A*C+m,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},ZY}var qY,F0e;function glt(){return F0e||(F0e=1,qY=(e,t)=>(e[0]=t[0],e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=t[1],e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=t[2],e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e)),qY}var XY,k0e;function plt(){if(k0e)return XY;k0e=1;const{sin:r,cos:e}=e_();return XY=(n,i,a,o)=>{const s=r(i),l=e(i),c=r(a),A=e(a),u=r(o),d=e(o);return n[0]=A*l,n[1]=A*s,n[2]=-c,n[3]=0,n[4]=u*c*l-d*s,n[5]=d*l+u*c*s,n[6]=u*A,n[7]=0,n[8]=u*s+d*c*l,n[9]=d*c*s-u*l,n[10]=d*A,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},XY}var $Y,G0e;function mlt(){return G0e||(G0e=1,$Y=(e,t)=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e)),$Y}var eV,L0e;function ylt(){if(L0e)return eV;L0e=1;const r=zY();return eV=(t,n,i,a,o,s,l,c,A,u,d,g,m,C,E,_)=>{const x=r();return x[0]=t,x[1]=n,x[2]=i,x[3]=a,x[4]=o,x[5]=s,x[6]=l,x[7]=c,x[8]=A,x[9]=u,x[10]=d,x[11]=g,x[12]=m,x[13]=C,x[14]=E,x[15]=_,x},eV}var tV,O0e;function z0e(){return O0e||(O0e=1,tV=(e,t)=>(e[0]=Math.abs(t[0]),e[1]=Math.abs(t[1]),e[2]=Math.abs(t[2]),e)),tV}var nV,H0e;function Y0e(){return H0e||(H0e=1,nV=(e,t,n)=>(e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e)),nV}var rV,V0e;function l8(){return V0e||(V0e=1,rV=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]),rV}var iV,K0e;function vlt(){if(K0e)return iV;K0e=1;const r=l8();return iV=(t,n)=>{const i=t[0],a=t[1],o=t[2],s=n[0],l=n[1],c=n[2],A=Math.sqrt(i*i+a*a+o*o),u=Math.sqrt(s*s+l*l+c*c),d=A*u,g=d&&r(t,n)/d;return Math.acos(Math.min(Math.max(g,-1),1))},iV}var aV,J0e;function c8(){return J0e||(J0e=1,aV=()=>[0,0,0]),aV}var oV,j0e;function Ilt(){if(j0e)return oV;j0e=1;const r=c8();return oV=t=>{const n=r();return n[0]=t[0],n[1]=t[1],n[2]=t[2],n},oV}var sV,W0e;function Z0e(){return W0e||(W0e=1,sV=(e,t)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],e)),sV}var lV,q0e;function ID(){return q0e||(q0e=1,lV=(e,t,n)=>{const i=t[0],a=t[1],o=t[2],s=n[0],l=n[1],c=n[2];return e[0]=a*c-o*l,e[1]=o*s-i*c,e[2]=i*l-a*s,e}),lV}var cV,X0e;function $0e(){return X0e||(X0e=1,cV=(e,t)=>{const n=t[0]-e[0],i=t[1]-e[1],a=t[2]-e[2];return Math.sqrt(n*n+i*i+a*a)}),cV}var AV,eme;function Clt(){return eme||(eme=1,AV=(e,t,n)=>(e[0]=t[0]/n[0],e[1]=t[1]/n[1],e[2]=t[2]/n[2],e)),AV}var uV,tme;function Elt(){return tme||(tme=1,uV=(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]),uV}var dV,nme;function _lt(){return nme||(nme=1,dV=(e,t)=>(e[0]=t,e[1]=t,e[2]=t,e)),dV}var fV,rme;function Blt(){if(rme)return fV;rme=1;const r=c8();return fV=(t,n,i)=>{const a=r();return a[0]=t,a[1]=n,a[2]=i,a},fV}var hV,ime;function xlt(){return ime||(ime=1,hV=(e,t,n=0)=>(e[0]=t[0],e[1]=t[1],e[2]=n,e)),hV}var gV,ame;function ome(){return ame||(ame=1,gV=e=>{const t=e[0],n=e[1],i=e[2];return Math.sqrt(t*t+n*n+i*i)}),gV}var pV,sme;function blt(){return sme||(sme=1,pV=(e,t,n,i)=>(e[0]=t[0]+i*(n[0]-t[0]),e[1]=t[1]+i*(n[1]-t[1]),e[2]=t[2]+i*(n[2]-t[2]),e)),pV}var mV,lme;function cme(){return lme||(lme=1,mV=(e,t,n)=>(e[0]=Math.max(t[0],n[0]),e[1]=Math.max(t[1],n[1]),e[2]=Math.max(t[2],n[2]),e)),mV}var yV,Ame;function ume(){return Ame||(Ame=1,yV=(e,t,n)=>(e[0]=Math.min(t[0],n[0]),e[1]=Math.min(t[1],n[1]),e[2]=Math.min(t[2],n[2]),e)),yV}var vV,dme;function Slt(){return dme||(dme=1,vV=(e,t,n)=>(e[0]=t[0]*n[0],e[1]=t[1]*n[1],e[2]=t[2]*n[2],e)),vV}var IV,fme;function Qlt(){return fme||(fme=1,IV=(e,t)=>(e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e)),IV}var CV,hme;function EV(){return hme||(hme=1,CV=(e,t)=>{const n=t[0],i=t[1],a=t[2];let o=n*n+i*i+a*a;return o>0&&(o=1/Math.sqrt(o)),e[0]=n*o,e[1]=i*o,e[2]=a*o,e}),CV}var _V,gme;function wlt(){if(gme)return _V;gme=1;const r=z0e(),e=c8(),t=ID();return _V=(i,a)=>{const o=r(e(),a),s=0+(o[0]<o[1]&&o[0]<o[2]),l=0+(o[1]<=o[0]&&o[1]<o[2]),c=0+(o[2]<=o[0]&&o[2]<=o[1]);return t(i,a,[s,l,c])},_V}var BV,pme;function Mlt(){return pme||(pme=1,BV=(e,t,n,i)=>{const a=[],o=[];return a[0]=t[0]-n[0],a[1]=t[1]-n[1],a[2]=t[2]-n[2],o[0]=a[0],o[1]=a[1]*Math.cos(i)-a[2]*Math.sin(i),o[2]=a[1]*Math.sin(i)+a[2]*Math.cos(i),e[0]=o[0]+n[0],e[1]=o[1]+n[1],e[2]=o[2]+n[2],e}),BV}var xV,mme;function Dlt(){return mme||(mme=1,xV=(e,t,n,i)=>{const a=[],o=[];return a[0]=t[0]-n[0],a[1]=t[1]-n[1],a[2]=t[2]-n[2],o[0]=a[2]*Math.sin(i)+a[0]*Math.cos(i),o[1]=a[1],o[2]=a[2]*Math.cos(i)-a[0]*Math.sin(i),e[0]=o[0]+n[0],e[1]=o[1]+n[1],e[2]=o[2]+n[2],e}),xV}var bV,yme;function Rlt(){return yme||(yme=1,bV=(e,t,n,i)=>{const a=[],o=[];return a[0]=t[0]-n[0],a[1]=t[1]-n[1],o[0]=a[0]*Math.cos(i)-a[1]*Math.sin(i),o[1]=a[0]*Math.sin(i)+a[1]*Math.cos(i),e[0]=o[0]+n[0],e[1]=o[1]+n[1],e[2]=t[2],e}),bV}var SV,vme;function Ime(){return vme||(vme=1,SV=(e,t,n)=>(e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e)),SV}var QV,Cme;function Nlt(){return Cme||(Cme=1,QV=(e,t,n)=>(e[0]=Math.round(t[0]/n)*n+0,e[1]=Math.round(t[1]/n)*n+0,e[2]=Math.round(t[2]/n)*n+0,e)),QV}var wV,Eme;function _me(){return Eme||(Eme=1,wV=(e,t)=>{const n=t[0]-e[0],i=t[1]-e[1],a=t[2]-e[2];return n*n+i*i+a*a}),wV}var MV,Bme;function xme(){return Bme||(Bme=1,MV=e=>{const t=e[0],n=e[1],i=e[2];return t*t+n*n+i*i}),MV}var DV,bme;function A8(){return bme||(bme=1,DV=(e,t,n)=>(e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e)),DV}var RV,Sme;function Tlt(){return Sme||(Sme=1,RV=e=>`[${e[0].toFixed(7)}, ${e[1].toFixed(7)}, ${e[2].toFixed(7)}]`),RV}var NV,Qme;function Plt(){return Qme||(Qme=1,NV=(e,t,n)=>{const i=t[0],a=t[1],o=t[2];let s=n[3]*i+n[7]*a+n[11]*o+n[15];return s=s||1,e[0]=(n[0]*i+n[4]*a+n[8]*o+n[12])/s,e[1]=(n[1]*i+n[5]*a+n[9]*o+n[13])/s,e[2]=(n[2]*i+n[6]*a+n[10]*o+n[14])/s,e}),NV}var TV,wme;function du(){return wme||(wme=1,TV={abs:z0e(),add:Y0e(),angle:vlt(),clone:Ilt(),copy:Z0e(),create:c8(),cross:ID(),distance:$0e(),divide:Clt(),dot:l8(),equals:Elt(),fromScalar:_lt(),fromValues:Blt(),fromVec2:xlt(),length:ome(),lerp:blt(),max:cme(),min:ume(),multiply:Slt(),negate:Qlt(),normalize:EV(),orthogonal:wlt(),rotateX:Mlt(),rotateY:Dlt(),rotateZ:Rlt(),scale:Ime(),snap:Nlt(),squaredDistance:_me(),squaredLength:xme(),subtract:A8(),toString:Tlt(),transform:Plt()}),TV}var PV,Mme;function Ult(){if(Mme)return PV;Mme=1;const r=du(),e=U0e();return PV=(n,i,a)=>{const o=r.normalize(r.create(),i),s=r.normalize(r.create(),a),l=r.cross(r.create(),s,o),c=r.dot(s,o);if(c===-1)return e(n,Math.PI,r.orthogonal(l,o));const A=1/(1+c);return n[0]=l[0]*l[0]*A+c,n[1]=l[1]*l[0]*A-l[2],n[2]=l[2]*l[0]*A+l[1],n[3]=0,n[4]=l[0]*l[1]*A+l[2],n[5]=l[1]*l[1]*A+c,n[6]=l[2]*l[1]*A-l[0],n[7]=0,n[8]=l[0]*l[2]*A-l[1],n[9]=l[1]*l[2]*A+l[0],n[10]=l[2]*l[2]*A+c,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},PV}var UV,Dme;function Flt(){if(Dme)return UV;Dme=1;const{sin:r,cos:e}=e_();return UV=(n,i)=>{const a=r(i),o=e(i);return n[0]=1,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=o,n[6]=a,n[7]=0,n[8]=0,n[9]=-a,n[10]=o,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},UV}var FV,Rme;function klt(){if(Rme)return FV;Rme=1;const{sin:r,cos:e}=e_();return FV=(n,i)=>{const a=r(i),o=e(i);return n[0]=o,n[1]=0,n[2]=-a,n[3]=0,n[4]=0,n[5]=1,n[6]=0,n[7]=0,n[8]=a,n[9]=0,n[10]=o,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},FV}var kV,Nme;function Glt(){if(Nme)return kV;Nme=1;const{sin:r,cos:e}=e_();return kV=(n,i)=>{const a=r(i),o=e(i);return n[0]=o,n[1]=a,n[2]=0,n[3]=0,n[4]=-a,n[5]=o,n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[10]=1,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},kV}var GV,Tme;function Llt(){return Tme||(Tme=1,GV=e=>e[0]===1&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===1&&e[6]===0&&e[7]===0&&e[8]===0&&e[9]===0&&e[10]===1&&e[11]===0&&e[12]===0&&e[13]===0&&e[14]===0&&e[15]===1),GV}var LV,Pme;function Olt(){if(Pme)return LV;Pme=1;const r=t=>e(t[1])&&e(t[2])&&e(t[3])&&e(t[4])&&e(t[6])&&e(t[7])&&e(t[8])&&e(t[9])&&e(t[11])&&t[15]===1,e=t=>Math.abs(t)<Number.EPSILON;return LV=r,LV}var OV,Ume;function zlt(){return Ume||(Ume=1,OV=e=>{const t=e[4]*e[9]-e[8]*e[5],n=e[8]*e[1]-e[0]*e[9],i=e[0]*e[5]-e[4]*e[1];return t*e[2]+n*e[6]+i*e[10]<0}),OV}var zV,Fme;function Hlt(){return Fme||(Fme=1,zV=(e,t)=>{const[n,i,a,o]=t;return e[0]=1-2*n*n,e[1]=-2*i*n,e[2]=-2*a*n,e[3]=0,e[4]=-2*n*i,e[5]=1-2*i*i,e[6]=-2*a*i,e[7]=0,e[8]=-2*n*a,e[9]=-2*i*a,e[10]=1-2*a*a,e[11]=0,e[12]=2*n*o,e[13]=2*i*o,e[14]=2*a*o,e[15]=1,e}),zV}var HV,kme;function Ylt(){return kme||(kme=1,HV=(e,t,n)=>{const i=t[0],a=t[1],o=t[2],s=t[3],l=t[4],c=t[5],A=t[6],u=t[7],d=t[8],g=t[9],m=t[10],C=t[11],E=t[12],_=t[13],x=t[14],Q=t[15];let P=n[0],z=n[1],O=n[2],V=n[3];return e[0]=P*i+z*l+O*d+V*E,e[1]=P*a+z*c+O*g+V*_,e[2]=P*o+z*A+O*m+V*x,e[3]=P*s+z*u+O*C+V*Q,P=n[4],z=n[5],O=n[6],V=n[7],e[4]=P*i+z*l+O*d+V*E,e[5]=P*a+z*c+O*g+V*_,e[6]=P*o+z*A+O*m+V*x,e[7]=P*s+z*u+O*C+V*Q,P=n[8],z=n[9],O=n[10],V=n[11],e[8]=P*i+z*l+O*d+V*E,e[9]=P*a+z*c+O*g+V*_,e[10]=P*o+z*A+O*m+V*x,e[11]=P*s+z*u+O*C+V*Q,P=n[12],z=n[13],O=n[14],V=n[15],e[12]=P*i+z*l+O*d+V*E,e[13]=P*a+z*c+O*g+V*_,e[14]=P*o+z*A+O*m+V*x,e[15]=P*s+z*u+O*C+V*Q,e}),HV}var YV,Gme;function Vlt(){if(Gme)return YV;Gme=1;const{EPS:r}=Hp(),{sin:e,cos:t}=e_(),n=Q0e();return YV=(a,o,s,l)=>{let[c,A,u]=l;const d=c*c+A*A+u*u;if(Math.abs(d)<r)return n(a,o);const g=1/Math.sqrt(d);c*=g,A*=g,u*=g;const m=e(s),C=t(s),E=1-C,_=o[0],x=o[1],Q=o[2],P=o[3],z=o[4],O=o[5],V=o[6],j=o[7],q=o[8],J=o[9],ce=o[10],oe=o[11],de=c*c*E+C,Ie=A*c*E+u*m,Be=u*c*E-A*m,pe=c*A*E-u*m,_e=A*A*E+C,ve=u*A*E+c*m,Ne=c*u*E+A*m,we=A*u*E-c*m,Ue=u*u*E+C;return a[0]=_*de+z*Ie+q*Be,a[1]=x*de+O*Ie+J*Be,a[2]=Q*de+V*Ie+ce*Be,a[3]=P*de+j*Ie+oe*Be,a[4]=_*pe+z*_e+q*ve,a[5]=x*pe+O*_e+J*ve,a[6]=Q*pe+V*_e+ce*ve,a[7]=P*pe+j*_e+oe*ve,a[8]=_*Ne+z*we+q*Ue,a[9]=x*Ne+O*we+J*Ue,a[10]=Q*Ne+V*we+ce*Ue,a[11]=P*Ne+j*we+oe*Ue,o!==a&&(a[12]=o[12],a[13]=o[13],a[14]=o[14],a[15]=o[15]),a},YV}var VV,Lme;function Klt(){if(Lme)return VV;Lme=1;const{sin:r,cos:e}=e_();return VV=(n,i,a)=>{const o=r(a),s=e(a),l=i[4],c=i[5],A=i[6],u=i[7],d=i[8],g=i[9],m=i[10],C=i[11];return i!==n&&(n[0]=i[0],n[1]=i[1],n[2]=i[2],n[3]=i[3],n[12]=i[12],n[13]=i[13],n[14]=i[14],n[15]=i[15]),n[4]=l*s+d*o,n[5]=c*s+g*o,n[6]=A*s+m*o,n[7]=u*s+C*o,n[8]=d*s-l*o,n[9]=g*s-c*o,n[10]=m*s-A*o,n[11]=C*s-u*o,n},VV}var KV,Ome;function Jlt(){if(Ome)return KV;Ome=1;const{sin:r,cos:e}=e_();return KV=(n,i,a)=>{const o=r(a),s=e(a),l=i[0],c=i[1],A=i[2],u=i[3],d=i[8],g=i[9],m=i[10],C=i[11];return i!==n&&(n[4]=i[4],n[5]=i[5],n[6]=i[6],n[7]=i[7],n[12]=i[12],n[13]=i[13],n[14]=i[14],n[15]=i[15]),n[0]=l*s-d*o,n[1]=c*s-g*o,n[2]=A*s-m*o,n[3]=u*s-C*o,n[8]=l*o+d*s,n[9]=c*o+g*s,n[10]=A*o+m*s,n[11]=u*o+C*s,n},KV}var JV,zme;function jlt(){if(zme)return JV;zme=1;const{sin:r,cos:e}=e_();return JV=(n,i,a)=>{const o=r(a),s=e(a),l=i[0],c=i[1],A=i[2],u=i[3],d=i[4],g=i[5],m=i[6],C=i[7];return i!==n&&(n[8]=i[8],n[9]=i[9],n[10]=i[10],n[11]=i[11],n[12]=i[12],n[13]=i[13],n[14]=i[14],n[15]=i[15]),n[0]=l*s+d*o,n[1]=c*s+g*o,n[2]=A*s+m*o,n[3]=u*s+C*o,n[4]=d*s-l*o,n[5]=g*s-c*o,n[6]=m*s-A*o,n[7]=C*s-u*o,n},JV}var jV,Hme;function Wlt(){return Hme||(Hme=1,jV=(e,t,n)=>{const i=n[0],a=n[1],o=n[2];return e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e[3]=t[3]*i,e[4]=t[4]*a,e[5]=t[5]*a,e[6]=t[6]*a,e[7]=t[7]*a,e[8]=t[8]*o,e[9]=t[9]*o,e[10]=t[10]*o,e[11]=t[11]*o,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}),jV}var WV,Yme;function Zlt(){return Yme||(Yme=1,WV=(e,t,n)=>(e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e[3]=t[3]-n[3],e[4]=t[4]-n[4],e[5]=t[5]-n[5],e[6]=t[6]-n[6],e[7]=t[7]-n[7],e[8]=t[8]-n[8],e[9]=t[9]-n[9],e[10]=t[10]-n[10],e[11]=t[11]-n[11],e[12]=t[12]-n[12],e[13]=t[13]-n[13],e[14]=t[14]-n[14],e[15]=t[15]-n[15],e)),WV}var ZV,Vme;function qlt(){return Vme||(Vme=1,ZV=e=>e.map(t=>t.toFixed(7)).toString()),ZV}var qV,Kme;function Xlt(){return Kme||(Kme=1,qV=(e,t,n)=>{const i=n[0],a=n[1],o=n[2];let s,l,c,A,u,d,g,m,C,E,_,x;return t===e?(e[12]=t[0]*i+t[4]*a+t[8]*o+t[12],e[13]=t[1]*i+t[5]*a+t[9]*o+t[13],e[14]=t[2]*i+t[6]*a+t[10]*o+t[14],e[15]=t[3]*i+t[7]*a+t[11]*o+t[15]):(s=t[0],l=t[1],c=t[2],A=t[3],u=t[4],d=t[5],g=t[6],m=t[7],C=t[8],E=t[9],_=t[10],x=t[11],e[0]=s,e[1]=l,e[2]=c,e[3]=A,e[4]=u,e[5]=d,e[6]=g,e[7]=m,e[8]=C,e[9]=E,e[10]=_,e[11]=x,e[12]=s*i+u*a+C*o+t[12],e[13]=l*i+d*a+E*o+t[13],e[14]=c*i+g*a+_*o+t[14],e[15]=A*i+m*a+x*o+t[15]),e}),qV}var XV,Jme;function Xy(){return Jme||(Jme=1,XV={add:ult(),clone:dlt(),copy:Q0e(),create:zY(),invert:flt(),equals:hlt(),fromRotation:U0e(),fromScaling:glt(),fromTaitBryanRotation:plt(),fromTranslation:mlt(),fromValues:ylt(),fromVectorRotation:Ult(),fromXRotation:Flt(),fromYRotation:klt(),fromZRotation:Glt(),identity:T0e(),isIdentity:Llt(),isOnlyTransformScale:Olt(),isMirroring:zlt(),mirrorByPlane:Hlt(),multiply:Ylt(),rotate:Vlt(),rotateX:Klt(),rotateY:Jlt(),rotateZ:jlt(),scale:Wlt(),subtract:Zlt(),toString:qlt(),translate:Xlt()}),XV}var $V,jme;function u8(){if(jme)return $V;jme=1;const r=Xy();return $V=t=>(t===void 0&&(t=[]),{sides:t,transforms:r.create()}),$V}var eK,Wme;function $lt(){return Wme||(Wme=1,eK=(e,t)=>(e[0]=Math.abs(t[0]),e[1]=Math.abs(t[1]),e)),eK}var tK,Zme;function ect(){return Zme||(Zme=1,tK=(e,t,n)=>(e[0]=t[0]+n[0],e[1]=t[1]+n[1],e)),tK}var nK,qme;function rK(){return qme||(qme=1,nK=e=>Math.atan2(e[1],e[0])),nK}var iK,Xme;function tct(){return Xme||(Xme=1,iK=rK()),iK}var aK,$me;function nct(){if($me)return aK;$me=1;const r=rK();return aK=t=>r(t)*57.29577951308232,aK}var oK,eye;function d8(){return eye||(eye=1,oK=()=>[0,0]),oK}var sK,tye;function rct(){if(tye)return sK;tye=1;const r=d8();return sK=t=>{const n=r();return n[0]=t[0],n[1]=t[1],n},sK}var lK,nye;function ict(){return nye||(nye=1,lK=(e,t)=>(e[0]=t[0],e[1]=t[1],e)),lK}var cK,rye;function act(){return rye||(rye=1,cK=(e,t,n)=>(e[0]=0,e[1]=0,e[2]=t[0]*n[1]-t[1]*n[0],e)),cK}var AK,iye;function oct(){return iye||(iye=1,AK=(e,t)=>{const n=t[0]-e[0],i=t[1]-e[1];return Math.sqrt(n*n+i*i)}),AK}var uK,aye;function sct(){return aye||(aye=1,uK=(e,t,n)=>(e[0]=t[0]/n[0],e[1]=t[1]/n[1],e)),uK}var dK,oye;function lct(){return oye||(oye=1,dK=(e,t)=>e[0]*t[0]+e[1]*t[1]),dK}var fK,sye;function cct(){return sye||(sye=1,fK=(e,t)=>e[0]===t[0]&&e[1]===t[1]),fK}var hK,lye;function cye(){if(lye)return hK;lye=1;const{sin:r,cos:e}=e_();return hK=(n,i)=>(n[0]=e(i),n[1]=r(i),n),hK}var gK,Aye;function Act(){if(Aye)return gK;Aye=1;const r=cye();return gK=(t,n)=>r(t,n*.017453292519943295),gK}var pK,uye;function uct(){return uye||(uye=1,pK=(e,t)=>(e[0]=t,e[1]=t,e)),pK}var mK,dye;function dct(){if(dye)return mK;dye=1;const r=d8();return mK=(t,n)=>{const i=r();return i[0]=t,i[1]=n,i},mK}var yK,fye;function fct(){return fye||(fye=1,yK=e=>Math.sqrt(e[0]*e[0]+e[1]*e[1])),yK}var vK,hye;function hct(){return hye||(hye=1,vK=(e,t,n,i)=>{const a=t[0],o=t[1];return e[0]=a+i*(n[0]-a),e[1]=o+i*(n[1]-o),e}),vK}var IK,gye;function gct(){return gye||(gye=1,IK=(e,t,n)=>(e[0]=Math.max(t[0],n[0]),e[1]=Math.max(t[1],n[1]),e)),IK}var CK,pye;function pct(){return pye||(pye=1,CK=(e,t,n)=>(e[0]=Math.min(t[0],n[0]),e[1]=Math.min(t[1],n[1]),e)),CK}var EK,mye;function mct(){return mye||(mye=1,EK=(e,t,n)=>(e[0]=t[0]*n[0],e[1]=t[1]*n[1],e)),EK}var _K,yye;function yct(){return yye||(yye=1,_K=(e,t)=>(e[0]=-t[0],e[1]=-t[1],e)),_K}var BK,vye;function Iye(){return vye||(vye=1,BK=(e,t,n,i)=>{const a=t[0]-n[0],o=t[1]-n[1],s=Math.cos(i),l=Math.sin(i);return e[0]=a*s-o*l+n[0],e[1]=a*l+o*s+n[1],e}),BK}var xK,Cye;function vct(){if(Cye)return xK;Cye=1;const{TAU:r}=Hp(),e=d8(),t=Iye();return xK=(i,a)=>t(i,a,e(),r/4),xK}var bK,Eye;function Ict(){return Eye||(Eye=1,bK=(e,t)=>{const n=t[0],i=t[1];let a=n*n+i*i;return a>0&&(a=1/Math.sqrt(a)),e[0]=n*a,e[1]=i*a,e}),bK}var SK,_ye;function Cct(){return _ye||(_ye=1,SK=(e,t,n)=>(e[0]=t[0]*n,e[1]=t[1]*n,e)),SK}var QK,Bye;function Ect(){return Bye||(Bye=1,QK=(e,t,n)=>(e[0]=Math.round(t[0]/n)*n+0,e[1]=Math.round(t[1]/n)*n+0,e)),QK}var wK,xye;function _ct(){return xye||(xye=1,wK=(e,t)=>{const n=t[0]-e[0],i=t[1]-e[1];return n*n+i*i}),wK}var MK,bye;function Bct(){return bye||(bye=1,MK=e=>{const t=e[0],n=e[1];return t*t+n*n}),MK}var DK,Sye;function xct(){return Sye||(Sye=1,DK=(e,t,n)=>(e[0]=t[0]-n[0],e[1]=t[1]-n[1],e)),DK}var RK,Qye;function bct(){return Qye||(Qye=1,RK=e=>`[${e[0].toFixed(7)}, ${e[1].toFixed(7)}]`),RK}var NK,wye;function Sct(){return wye||(wye=1,NK=(e,t,n)=>{const i=t[0],a=t[1];return e[0]=n[0]*i+n[4]*a+n[12],e[1]=n[1]*i+n[5]*a+n[13],e}),NK}var TK,Mye;function hg(){return Mye||(Mye=1,TK={abs:$lt(),add:ect(),angle:tct(),angleDegrees:nct(),angleRadians:rK(),clone:rct(),copy:ict(),create:d8(),cross:act(),distance:oct(),divide:sct(),dot:lct(),equals:cct(),fromAngleDegrees:Act(),fromAngleRadians:cye(),fromScalar:uct(),fromValues:dct(),length:fct(),lerp:hct(),max:gct(),min:pct(),multiply:mct(),negate:yct(),normal:vct(),normalize:Ict(),rotate:Iye(),scale:Cct(),snap:Ect(),squaredDistance:_ct(),squaredLength:Bct(),subtract:xct(),toString:bct(),transform:Sct()}),TK}var PK,Dye;function Qct(){if(Dye)return PK;Dye=1;const r=hg(),e=u8();return PK=n=>{if(!Array.isArray(n))throw new Error("the given points must be an array");let i=n.length;if(i<3)throw new Error("the given points must define a closed geometry with three or more points");r.equals(n[0],n[i-1])&&--i;const a=[];let o=n[i-1];for(let s=0;s<i;s++){const l=n[s];a.push([r.clone(o),r.clone(l)]),o=l}return e(a)},PK}var UK,Rye;function wct(){if(Rye)return UK;Rye=1;const r=Xy(),e=hg(),t=u8();return UK=i=>{if(i[0]!==0)throw new Error("invalid compact binary data");const a=t();a.transforms=r.clone(i.slice(1,17));for(let o=21;o<i.length;o+=4){const s=e.fromValues(i[o+0],i[o+1]),l=e.fromValues(i[o+2],i[o+3]);a.sides.push([s,l])}return i[17]>=0&&(a.color=[i[17],i[18],i[19],i[20]]),a},UK}var FK,Nye;function Tye(){return Nye||(Nye=1,FK=e=>!!(e&&typeof e=="object"&&"sides"in e&&"transforms"in e&&Array.isArray(e.sides)&&"length"in e.transforms)),FK}var kK,Pye;function Mct(){if(Pye)return kK;Pye=1;const r=Xy(),e=hg();return kK=n=>(r.isIdentity(n.transforms)||(n.sides=n.sides.map(i=>{const a=e.transform(e.create(),i[0],n.transforms),o=e.transform(e.create(),i[1],n.transforms);return[a,o]}),n.transforms=r.create()),n),kK}var GK,Uye;function CD(){if(Uye)return GK;Uye=1;const r=Mct();return GK=t=>r(t).sides,GK}var LK,Fye;function kye(){if(Fye)return LK;Fye=1;const r=u8(),e=CD();return LK=n=>{const a=e(n).map(o=>[o[1],o[0]]);return a.reverse(),r(a)},LK}var OK,Gye;function Lye(){if(Gye)return OK;Gye=1;const r=hg(),e=CD(),t=o=>{const s=new Map,l=c=>{const A=c.toString();return s.has(A)?s.get(A):(s.set(A,c),c)};return o.map(c=>c.map(l))},n=o=>{const s=new Map;return t(o).forEach(c=>{s.has(c[0])?s.get(c[0]).push(c):s.set(c[0],[c])}),s},i=o=>{const s=n(e(o)),l=[];for(;;){let c;for(const[d,g]of s){if(c=g.shift(),!c){s.delete(d);continue}break}if(c===void 0)break;const A=[],u=c[0];for(;;){A.push(c[0]);const d=c[1];if(d===u)break;const g=s.get(d);if(!g)throw new Error(`geometry is not closed at vertex ${d}`);const m=a(c,g);g.length===0&&s.delete(d),c=m}A.length>0&&A.push(A.shift()),l.push(A)}return s.clear(),l},a=(o,s)=>{if(s.length===1)return s.pop();const l=r.create(),c=r.angleDegrees(r.subtract(l,o[1],o[0]));let A,u;s.forEach((g,m)=>{let E=r.angleDegrees(r.subtract(l,g[1],g[0]))-c;E<-180&&(E+=360),E>=180&&(E-=360),(u===void 0||E>A)&&(u=m,A=E)});const d=s[u];return s.splice(u,1),d};return OK=i,OK}var zK,Oye;function Dct(){if(Oye)return zK;Oye=1;const r=CD();return zK=t=>{const i=r(t).map(a=>a[0]);return i.length>0&&i.push(i.shift()),i},zK}var HK,zye;function Rct(){if(zye)return HK;zye=1;const r=hg(),e=CD();return HK=n=>{const i=e(n);let a="geom2 ("+i.length+` sides):
|
|
857
857
|
[
|
|
@@ -13071,7 +13071,7 @@ ${l.join(`
|
|
|
13071
13071
|
`)!==-1&&(r=r.replace(/\r\n/g,`
|
|
13072
13072
|
`)),r.indexOf(`\\
|
|
13073
13073
|
`)!==-1&&(r=r.replace(/\\\n/g,""));const t=r.split(`
|
|
13074
|
-
`);let n="",i="",a=0,o=[];const s=typeof"".trimLeft=="function";for(let A=0,u=t.length;A<u;A++)if(n=t[A],n=s?n.trimLeft():n.trim(),a=n.length,a!==0&&(i=n.charAt(0),i!=="#"))if(i==="v"){const d=n.split(/\s+/);switch(d[0]){case"v":e.vertices.push(parseFloat(d[1]),parseFloat(d[2]),parseFloat(d[3])),d.length>=7?e.colors.push(parseFloat(d[4]),parseFloat(d[5]),parseFloat(d[6])):e.colors.push(void 0,void 0,void 0);break;case"vn":e.normals.push(parseFloat(d[1]),parseFloat(d[2]),parseFloat(d[3]));break;case"vt":e.uvs.push(parseFloat(d[1]),parseFloat(d[2]));break}}else if(i==="f"){const g=n.substr(1).trim().split(/\s+/),m=[];for(let E=0,_=g.length;E<_;E++){const x=g[E];if(x.length>0){const Q=x.split("/");m.push(Q)}}const C=m[0];for(let E=1,_=m.length-1;E<_;E++){const x=m[E],Q=m[E+1];e.addFace(C[0],x[0],Q[0],C[1],x[1],Q[1],C[2],x[2],Q[2])}}else if(i==="l"){const d=n.substring(1).trim().split(" ");let g=[];const m=[];if(n.indexOf("/")===-1)g=d;else for(let C=0,E=d.length;C<E;C++){const _=d[C].split("/");_[0]!==""&&g.push(_[0]),_[1]!==""&&m.push(_[1])}e.addLineGeometry(g,m)}else if(i==="p"){const g=n.substr(1).trim().split(" ");e.addPointGeometry(g)}else if((o=mNt.exec(n))!==null){const d=(" "+o[0].substr(1).trim()).substr(1);e.startObject(d)}else if(vNt.test(n))e.object.startMaterial(n.substring(7).trim(),e.materialLibraries);else if(yNt.test(n))e.materialLibraries.push(n.substring(7).trim());else if(INt.test(n))console.warn('THREE.OBJLoader: Rendering identifier "usemap" not supported. Textures must be defined in MTL files.');else if(i==="s"){if(o=n.split(" "),o.length>1){const g=o[1].trim().toLowerCase();e.object.smooth=g!=="0"&&g!=="off"}else e.object.smooth=!0;const d=e.object.currentMaterial();d&&(d.smooth=e.object.smooth)}else{if(n==="\0")continue;console.warn('THREE.OBJLoader: Unexpected line: "'+n+'"')}e.finalize();const l=new VQ;if(l.materialLibraries=[].concat(e.materialLibraries),!(e.objects.length===1&&e.objects[0].geometry.vertices.length===0)===!0)for(let A=0,u=e.objects.length;A<u;A++){const d=e.objects[A],g=d.geometry,m=d.materials,C=g.type==="Line",E=g.type==="Points";let _=!1;if(g.vertices.length===0)continue;const x=new xf;x.setAttribute("position",new Kc(g.vertices,3)),g.normals.length>0&&x.setAttribute("normal",new Kc(g.normals,3)),g.colors.length>0&&(_=!0,x.setAttribute("color",new Kc(g.colors,3))),g.hasUVIndices===!0&&x.setAttribute("uv",new Kc(g.uvs,2));const Q=[];for(let z=0,O=m.length;z<O;z++){const V=m[z],j=V.name+"_"+V.smooth+"_"+_;let q=e.materials[j];if(this.materials!==null){if(q=this.materials.create(V.name),C&&q&&!(q instanceof W1)){const J=new W1;PE.prototype.copy.call(J,q),J.color.copy(q.color),q=J}else if(E&&q&&!(q instanceof qQ)){const J=new qQ({size:10,sizeAttenuation:!1});PE.prototype.copy.call(J,q),J.color.copy(q.color),J.map=q.map,q=J}}q===void 0&&(C?q=new W1:E?q=new qQ({size:1,sizeAttenuation:!1}):q=new wF,q.name=V.name,q.flatShading=!V.smooth,q.vertexColors=_,e.materials[j]=q),Q.push(q)}let P;if(Q.length>1){for(let z=0,O=m.length;z<O;z++){const V=m[z];x.addGroup(V.groupStart,V.groupCount,z)}C?P=new xx(x,Q):E?P=new dR(x,Q):P=new $y(x,Q)}else C?P=new xx(x,Q[0]):E?P=new dR(x,Q[0]):P=new $y(x,Q[0]);P.name=d.name,l.add(P)}else if(e.vertices.length>0){const A=new qQ({size:1,sizeAttenuation:!1}),u=new xf;u.setAttribute("position",new Kc(e.vertices,3)),e.colors.length>0&&e.colors[0]!==void 0&&(u.setAttribute("color",new Kc(e.colors,3)),A.vertexColors=!0);const d=new dR(u,A);l.add(d)}return l}};function _Nt({stlUrl:r,mtlUrl:e,color:t,opacity:n=1}){const i=ete(hNt,r),a=yt.useRef();return dt.jsxs("mesh",{ref:a,children:[dt.jsx("primitive",{object:i,attach:"geometry"}),dt.jsx("meshStandardMaterial",{color:t,transparent:n!==1,opacity:n})]})}var BNt={version:"0.0.256"};typeof window<"u"&&(window.TSCI_MAIN_CAMERA_ROTATION=new bB(0,0,0));function xNt(r,e){const t=new n_().setFromEuler(new bB(r.x,r.y,r.z)),n=new zn(0,0,1);return n.applyQuaternion(t),n.multiplyScalar(e)}var bNt=({})=>{const r=yt.useRef();return yt.useRef({lastRotation:new bB}),RR((e,t)=>{if(!r.current)return;const n=window.TSCI_MAIN_CAMERA_ROTATION,i=xNt(n,2);e.camera.position.copy(i),e.camera.lookAt(0,0,0)}),dt.jsxs("mesh",{ref:r,rotation:[Math.PI/2,0,0],children:[dt.jsx("boxGeometry",{args:[1,1,1]}),dt.jsx("meshStandardMaterial",{color:"white"}),dt.jsx(dw,{position:[0,0,.51],fontSize:.25,color:"black",children:"Front"}),dt.jsx(dw,{position:[0,0,-.51],fontSize:.25,color:"black",rotation:[0,Math.PI,0],children:"Back"}),dt.jsx(dw,{position:[.51,0,0],fontSize:.25,color:"black",rotation:[0,Math.PI/2,0],children:"Right"}),dt.jsx(dw,{position:[-.51,0,0],fontSize:.25,color:"black",rotation:[0,-Math.PI/2,0],children:"Left"}),dt.jsx(dw,{position:[0,.51,0],fontSize:.25,color:"black",rotation:[-Math.PI/2,0,0],children:"Top"}),dt.jsx(dw,{position:[0,-.51,0],fontSize:.25,color:"black",rotation:[Math.PI/2,0,0],children:"Bottom"}),dt.jsx("lineSegments",{args:[new pee(new Q2(1,1,1))],material:new W1({color:0,linewidth:2})})]})},SNt=()=>(RR(({camera:r})=>{window.TSCI_MAIN_CAMERA_ROTATION=r.rotation}),dt.jsx(dt.Fragment,{})),yNe=yt.forwardRef(({children:r,initialCameraPosition:e=[5,5,5],autoRotateDisabled:t,clickToInteractEnabled:n=!1},i)=>{const[a,o]=yt.useState(!n);return dt.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[dt.jsx("div",{style:{position:"absolute",top:0,left:0,width:120,height:120},children:dt.jsxs(W2e,{camera:{up:[0,0,1],position:[1,1,1]},style:{zIndex:10},children:[dt.jsx("ambientLight",{intensity:Math.PI/2}),dt.jsx(bNt,{})]})}),dt.jsxs(W2e,{scene:{up:[0,0,1]},camera:{up:[0,0,1],position:e},children:[dt.jsx(SNt,{}),a&&dt.jsx(JCt,{autoRotate:!t,autoRotateSpeed:1}),dt.jsx("ambientLight",{intensity:Math.PI/2}),dt.jsx("pointLight",{position:[-10,-10,10],decay:0,intensity:Math.PI/4}),dt.jsx(WCt,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:1,sectionSize:10}),dt.jsx("object3D",{ref:i,children:r})]}),dt.jsxs("div",{style:{position:"absolute",right:24,bottom:24,fontFamily:"sans-serif",color:"white",WebkitTextStroke:"0.5px rgba(0, 0, 0, 0.5)",fontSize:11},children:["@",BNt.version]}),n&&!a&&dt.jsx("div",{onClick:()=>o(!0),style:{position:"absolute",inset:0,cursor:"pointer",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center"},children:dt.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",fontFamily:"sans-serif",pointerEvents:"none"},children:"Click to Interact"})})]})}),QNt=wI(VM()),wNt=wI(N5()),gm=.01,eE={copper:[.9,.6,.2],fr4Green:[5/255,163/255,46/255],fr4GreenSolderWithMask:[0/255,152/255,19/255],fr1Copper:[.8,.4,.2],fr1CopperSolderWithMask:[.9,.6,.2]},KM=.001,bw=32,MNt=.035,fG=50,Lre={fr1:eE.fr1Copper,fr4:eE.fr4Green},vNe={fr1:eE.fr1CopperSolderWithMask,fr4:eE.fr4GreenSolderWithMask},DNt=wI(cG()),RNt=wI(VM()),NNt=wI(dG()),INe=r=>{let e=0;for(let n=0;n<r.length;n++){const i=(n+1)%r.length;e+=r[n][0]*r[i][1],e-=r[i][0]*r[n][1]}return e/2<=0},CNe=(r,e=1.2)=>{const{center:t,outline:n}=r;let i=n.map(s=>[s.x,s.y]);INe(i)&&(i=i.reverse());const a=(0,RNt.polygon)({points:i});let o=(0,DNt.extrudeLinear)({height:e},a);return o=(0,NNt.translate)([t.x,t.y,-e/2],o),o},TNt=r=>{const e=hm(r).pcb_board.list()[0];if(!e)return console.warn("No pcb_board found for simplified geometry"),[];let t;const n=1.2;e.outline&&e.outline.length>0?t=CNe({center:e.center,outline:e.outline},n):t=(0,QNt.cuboid)({size:[e.width,e.height,n],center:[e.center.x,e.center.y,0]});const i=Lre[e.material]??eE.fr4Green;return[(0,wNt.colorize)(i,t)]},Sw=wI(dG()),k_=wI(VM()),JM=wI(N5()),Qw=wI(Nre()),nv=wI(VM()),hG=wI(N5()),$B=wI(Nre()),_C=.05,ENe=(r,e)=>{if(r.shape||(r.shape="circle"),r.shape==="circle")return(0,hG.colorize)(eE.copper,(0,$B.subtract)((0,$B.union)((0,nv.cylinder)({center:[r.x,r.y,0],radius:r.hole_diameter/2,height:e.pcbThickness}),(0,nv.cylinder)({center:[r.x,r.y,e.pcbThickness/2+_C/2+gm],radius:r.outer_diameter/2,height:_C}),(0,nv.cylinder)({center:[r.x,r.y,-e.pcbThickness/2-_C/2-gm],radius:r.outer_diameter/2,height:_C})),(0,nv.cylinder)({center:[r.x,r.y,0],radius:r.hole_diameter/2-gm,height:1.5})));if(r.shape==="circular_hole_with_rect_pad"){const t=r.rect_pad_width||r.hole_diameter,n=r.rect_pad_height||r.hole_diameter;return(0,hG.colorize)(eE.copper,(0,$B.subtract)((0,$B.union)((0,nv.cuboid)({center:[r.x,r.y,1.2/2],size:[t,n,_C]}),(0,nv.cuboid)({center:[r.x,r.y,-1.2/2],size:[t,n,_C]}),(0,nv.cylinder)({center:[r.x,r.y,0],radius:r.hole_diameter/2,height:1.2})),(0,nv.cylinder)({center:[r.x,r.y,0],radius:Math.max(r.hole_diameter/2-gm,.01),height:1.5})))}if(r.shape==="pill"){const t=r.hole_height>r.hole_width,n=t?r.hole_height:r.hole_width,i=t?r.hole_width:r.hole_height,a=t?r.outer_height||i+.2:r.outer_width||n+.2,o=t?r.outer_width||n+.2:r.outer_height||i+.2,s=i/2,l=o/2,c=Math.abs(n-i),A=Math.abs(a-o),u=(0,nv.cuboid)({center:[r.x,r.y,0],size:t?[i,c,e.pcbThickness]:[c,i,e.pcbThickness]}),d=(0,nv.cylinder)({center:t?[r.x,r.y-c/2,0]:[r.x-c/2,r.y,0],radius:s,height:e.pcbThickness}),g=(0,nv.cylinder)({center:t?[r.x,r.y+c/2,0]:[r.x+c/2,r.y,0],radius:s,height:e.pcbThickness}),m=(0,$B.union)(u,d,g),C=e.pcbThickness/2+_C/2+gm,E=(0,nv.cuboid)({center:[r.x,r.y,C],size:t?[o,A,_C]:[A,o,_C]}),_=(0,nv.cylinder)({center:t?[r.x,r.y-A/2,C]:[r.x-A/2,r.y,C],radius:l,height:_C}),x=(0,nv.cylinder)({center:t?[r.x,r.y+A/2,C]:[r.x+A/2,r.y,C],radius:l,height:_C}),Q=(0,$B.union)(E,_,x),P=-e.pcbThickness/2-_C/2-gm,z=(0,nv.cuboid)({center:[r.x,r.y,P],size:t?[o,A,_C]:[A,o,_C]}),O=(0,nv.cylinder)({center:t?[r.x,r.y-A/2,P]:[r.x-A/2,r.y,P],radius:l,height:_C}),V=(0,nv.cylinder)({center:t?[r.x,r.y+A/2,P]:[r.x+A/2,r.y,P],radius:l,height:_C}),j=(0,$B.union)(z,O,V),q=(0,nv.cuboid)({center:[r.x,r.y,0],size:t?[i-2*gm,c,e.pcbThickness+2*gm]:[c,i-2*gm,e.pcbThickness+2*gm]}),J=(0,nv.cylinder)({center:t?[r.x,r.y-c/2,0]:[r.x-c/2,r.y,0],radius:s-gm,height:e.pcbThickness+2*gm}),ce=(0,nv.cylinder)({center:t?[r.x,r.y+c/2,0]:[r.x+c/2,r.y,0],radius:s-gm,height:e.pcbThickness+2*gm}),oe=(0,$B.union)(q,J,ce);return(0,hG.colorize)(eE.copper,(0,$B.subtract)((0,$B.union)(m,Q,j),oe))}if(r.shape==="pill_hole_with_rect_pad"){const t=r.hole_height>r.hole_width,n=t?r.hole_height:r.hole_width,i=t?r.hole_width:r.hole_height,a=i/2,o=Math.abs(n-i),s=r.rect_pad_width||n+.2,l=r.rect_pad_height||i+.2,c=(0,nv.cuboid)({center:[r.x,r.y,0],size:t?[i,o,1.2]:[o,i,1.2]}),A=(0,nv.cylinder)({center:t?[r.x,r.y-o/2,0]:[r.x-o/2,r.y,0],radius:a,height:1.2}),u=(0,nv.cylinder)({center:t?[r.x,r.y+o/2,0]:[r.x+o/2,r.y,0],radius:a,height:1.2}),d=(0,nv.cuboid)({center:[r.x,r.y,1.2/2],size:[s,l,_C]}),g=(0,nv.cuboid)({center:[r.x,r.y,-1.2/2],size:[s,l,_C]}),m=(0,$B.union)((0,nv.cuboid)({center:[r.x,r.y,0],size:t?[i-_C,o,1.5]:[o,i-_C,1.5]}),(0,nv.cylinder)({center:t?[r.x,r.y-o/2,0]:[r.x-o/2,r.y,0],radius:a-_C,height:1.5}),(0,nv.cylinder)({center:t?[r.x,r.y+o/2,0]:[r.x+o/2,r.y,0],radius:a-_C,height:1.5}));return(0,hG.colorize)(eE.copper,(0,$B.subtract)((0,$B.union)(c,A,u,d,g),m))}else throw new Error(`Unsupported plated hole shape: ${r.shape}`)},gG=wI(cG()),_Ne=wI(Tre()),PNt=wI(Pre());function BNe(r,e){return Array.isArray(e)?[r.a*e[0]+r.c*e[1]+r.e,r.b*e[0]+r.d*e[1]+r.f]:{x:r.a*e.x+r.c*e.y+r.e,y:r.b*e.x+r.d*e.y+r.f}}function z2(r,e=0){return{a:1,c:0,e:r,b:0,d:1,f:e}}function xNe(...r){r=Array.isArray(r[0])?r[0]:r;const e=(t,n)=>({a:t.a*n.a+t.c*n.b,c:t.a*n.c+t.c*n.d,e:t.a*n.e+t.c*n.f+t.e,b:t.b*n.a+t.d*n.b,d:t.b*n.c+t.d*n.d,f:t.b*n.e+t.d*n.f+t.f});switch(r.length){case 0:throw new Error("no matrices provided");case 1:return r[0];case 2:return e(r[0],r[1]);default:{const[t,n,...i]=r,a=e(t,n);return xNe(a,...i)}}}function bNe(...r){return xNe(...r)}var{cos:UNt,sin:FNt}=Math;function SNe(r,e,t){const n=UNt(r),i=FNt(r);return{a:n,c:-i,e:0,b:i,d:n,f:0}}function kNt(r,e){function t(){this.constructor=r}t.prototype=e.prototype,r.prototype=new t}function pG(r,e,t,n){var i=Error.call(this,r);return Object.setPrototypeOf&&Object.setPrototypeOf(i,pG.prototype),i.expected=e,i.found=t,i.location=n,i.name="SyntaxError",i}kNt(pG,Error);function Ore(r,e,t){return t=t||" ",r.length>e?r:(e-=r.length,t+=t.repeat(e),r+t.slice(0,e))}pG.prototype.format=function(r){var e="Error: "+this.message;if(this.location){var t=null,n;for(n=0;n<r.length;n++)if(r[n].source===this.location.source){t=r[n].text.split(/\r\n|\n|\r/g);break}var i=this.location.start,a=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(i):i,o=this.location.source+":"+a.line+":"+a.column;if(t){var s=this.location.end,l=Ore("",a.line.toString().length," "),c=t[i.line-1],A=i.line===s.line?s.column:c.length+1,u=A-i.column||1;e+=`
|
|
13074
|
+
`);let n="",i="",a=0,o=[];const s=typeof"".trimLeft=="function";for(let A=0,u=t.length;A<u;A++)if(n=t[A],n=s?n.trimLeft():n.trim(),a=n.length,a!==0&&(i=n.charAt(0),i!=="#"))if(i==="v"){const d=n.split(/\s+/);switch(d[0]){case"v":e.vertices.push(parseFloat(d[1]),parseFloat(d[2]),parseFloat(d[3])),d.length>=7?e.colors.push(parseFloat(d[4]),parseFloat(d[5]),parseFloat(d[6])):e.colors.push(void 0,void 0,void 0);break;case"vn":e.normals.push(parseFloat(d[1]),parseFloat(d[2]),parseFloat(d[3]));break;case"vt":e.uvs.push(parseFloat(d[1]),parseFloat(d[2]));break}}else if(i==="f"){const g=n.substr(1).trim().split(/\s+/),m=[];for(let E=0,_=g.length;E<_;E++){const x=g[E];if(x.length>0){const Q=x.split("/");m.push(Q)}}const C=m[0];for(let E=1,_=m.length-1;E<_;E++){const x=m[E],Q=m[E+1];e.addFace(C[0],x[0],Q[0],C[1],x[1],Q[1],C[2],x[2],Q[2])}}else if(i==="l"){const d=n.substring(1).trim().split(" ");let g=[];const m=[];if(n.indexOf("/")===-1)g=d;else for(let C=0,E=d.length;C<E;C++){const _=d[C].split("/");_[0]!==""&&g.push(_[0]),_[1]!==""&&m.push(_[1])}e.addLineGeometry(g,m)}else if(i==="p"){const g=n.substr(1).trim().split(" ");e.addPointGeometry(g)}else if((o=mNt.exec(n))!==null){const d=(" "+o[0].substr(1).trim()).substr(1);e.startObject(d)}else if(vNt.test(n))e.object.startMaterial(n.substring(7).trim(),e.materialLibraries);else if(yNt.test(n))e.materialLibraries.push(n.substring(7).trim());else if(INt.test(n))console.warn('THREE.OBJLoader: Rendering identifier "usemap" not supported. Textures must be defined in MTL files.');else if(i==="s"){if(o=n.split(" "),o.length>1){const g=o[1].trim().toLowerCase();e.object.smooth=g!=="0"&&g!=="off"}else e.object.smooth=!0;const d=e.object.currentMaterial();d&&(d.smooth=e.object.smooth)}else{if(n==="\0")continue;console.warn('THREE.OBJLoader: Unexpected line: "'+n+'"')}e.finalize();const l=new VQ;if(l.materialLibraries=[].concat(e.materialLibraries),!(e.objects.length===1&&e.objects[0].geometry.vertices.length===0)===!0)for(let A=0,u=e.objects.length;A<u;A++){const d=e.objects[A],g=d.geometry,m=d.materials,C=g.type==="Line",E=g.type==="Points";let _=!1;if(g.vertices.length===0)continue;const x=new xf;x.setAttribute("position",new Kc(g.vertices,3)),g.normals.length>0&&x.setAttribute("normal",new Kc(g.normals,3)),g.colors.length>0&&(_=!0,x.setAttribute("color",new Kc(g.colors,3))),g.hasUVIndices===!0&&x.setAttribute("uv",new Kc(g.uvs,2));const Q=[];for(let z=0,O=m.length;z<O;z++){const V=m[z],j=V.name+"_"+V.smooth+"_"+_;let q=e.materials[j];if(this.materials!==null){if(q=this.materials.create(V.name),C&&q&&!(q instanceof W1)){const J=new W1;PE.prototype.copy.call(J,q),J.color.copy(q.color),q=J}else if(E&&q&&!(q instanceof qQ)){const J=new qQ({size:10,sizeAttenuation:!1});PE.prototype.copy.call(J,q),J.color.copy(q.color),J.map=q.map,q=J}}q===void 0&&(C?q=new W1:E?q=new qQ({size:1,sizeAttenuation:!1}):q=new wF,q.name=V.name,q.flatShading=!V.smooth,q.vertexColors=_,e.materials[j]=q),Q.push(q)}let P;if(Q.length>1){for(let z=0,O=m.length;z<O;z++){const V=m[z];x.addGroup(V.groupStart,V.groupCount,z)}C?P=new xx(x,Q):E?P=new dR(x,Q):P=new $y(x,Q)}else C?P=new xx(x,Q[0]):E?P=new dR(x,Q[0]):P=new $y(x,Q[0]);P.name=d.name,l.add(P)}else if(e.vertices.length>0){const A=new qQ({size:1,sizeAttenuation:!1}),u=new xf;u.setAttribute("position",new Kc(e.vertices,3)),e.colors.length>0&&e.colors[0]!==void 0&&(u.setAttribute("color",new Kc(e.colors,3)),A.vertexColors=!0);const d=new dR(u,A);l.add(d)}return l}};function _Nt({stlUrl:r,mtlUrl:e,color:t,opacity:n=1}){const i=ete(hNt,r),a=yt.useRef();return dt.jsxs("mesh",{ref:a,children:[dt.jsx("primitive",{object:i,attach:"geometry"}),dt.jsx("meshStandardMaterial",{color:t,transparent:n!==1,opacity:n})]})}var BNt={version:"0.0.259"};typeof window<"u"&&(window.TSCI_MAIN_CAMERA_ROTATION=new bB(0,0,0));function xNt(r,e){const t=new n_().setFromEuler(new bB(r.x,r.y,r.z)),n=new zn(0,0,1);return n.applyQuaternion(t),n.multiplyScalar(e)}var bNt=({})=>{const r=yt.useRef();return yt.useRef({lastRotation:new bB}),RR((e,t)=>{if(!r.current)return;const n=window.TSCI_MAIN_CAMERA_ROTATION,i=xNt(n,2);e.camera.position.copy(i),e.camera.lookAt(0,0,0)}),dt.jsxs("mesh",{ref:r,rotation:[Math.PI/2,0,0],children:[dt.jsx("boxGeometry",{args:[1,1,1]}),dt.jsx("meshStandardMaterial",{color:"white"}),dt.jsx(dw,{position:[0,0,.51],fontSize:.25,color:"black",children:"Front"}),dt.jsx(dw,{position:[0,0,-.51],fontSize:.25,color:"black",rotation:[0,Math.PI,0],children:"Back"}),dt.jsx(dw,{position:[.51,0,0],fontSize:.25,color:"black",rotation:[0,Math.PI/2,0],children:"Right"}),dt.jsx(dw,{position:[-.51,0,0],fontSize:.25,color:"black",rotation:[0,-Math.PI/2,0],children:"Left"}),dt.jsx(dw,{position:[0,.51,0],fontSize:.25,color:"black",rotation:[-Math.PI/2,0,0],children:"Top"}),dt.jsx(dw,{position:[0,-.51,0],fontSize:.25,color:"black",rotation:[Math.PI/2,0,0],children:"Bottom"}),dt.jsx("lineSegments",{args:[new pee(new Q2(1,1,1))],material:new W1({color:0,linewidth:2})})]})},SNt=()=>(RR(({camera:r})=>{window.TSCI_MAIN_CAMERA_ROTATION=r.rotation}),dt.jsx(dt.Fragment,{})),yNe=yt.forwardRef(({children:r,initialCameraPosition:e=[5,5,5],autoRotateDisabled:t,clickToInteractEnabled:n=!1},i)=>{const[a,o]=yt.useState(!n);return dt.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[dt.jsx("div",{style:{position:"absolute",top:0,left:0,width:120,height:120},children:dt.jsxs(W2e,{camera:{up:[0,0,1],position:[1,1,1]},style:{zIndex:10},children:[dt.jsx("ambientLight",{intensity:Math.PI/2}),dt.jsx(bNt,{})]})}),dt.jsxs(W2e,{scene:{up:[0,0,1]},camera:{up:[0,0,1],position:e},children:[dt.jsx(SNt,{}),a&&dt.jsx(JCt,{autoRotate:!t,autoRotateSpeed:1}),dt.jsx("ambientLight",{intensity:Math.PI/2}),dt.jsx("pointLight",{position:[-10,-10,10],decay:0,intensity:Math.PI/4}),dt.jsx(WCt,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:1,sectionSize:10}),dt.jsx("object3D",{ref:i,children:r})]}),dt.jsxs("div",{style:{position:"absolute",right:24,bottom:24,fontFamily:"sans-serif",color:"white",WebkitTextStroke:"0.5px rgba(0, 0, 0, 0.5)",fontSize:11},children:["@",BNt.version]}),n&&!a&&dt.jsx("div",{onClick:()=>o(!0),style:{position:"absolute",inset:0,cursor:"pointer",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center"},children:dt.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",fontFamily:"sans-serif",pointerEvents:"none"},children:"Click to Interact"})})]})}),QNt=wI(VM()),wNt=wI(N5()),gm=.01,eE={copper:[.9,.6,.2],fr4Green:[5/255,163/255,46/255],fr4GreenSolderWithMask:[0/255,152/255,19/255],fr1Copper:[.8,.4,.2],fr1CopperSolderWithMask:[.9,.6,.2]},KM=.001,bw=32,MNt=.035,fG=50,Lre={fr1:eE.fr1Copper,fr4:eE.fr4Green},vNe={fr1:eE.fr1CopperSolderWithMask,fr4:eE.fr4GreenSolderWithMask},DNt=wI(cG()),RNt=wI(VM()),NNt=wI(dG()),INe=r=>{let e=0;for(let n=0;n<r.length;n++){const i=(n+1)%r.length;e+=r[n][0]*r[i][1],e-=r[i][0]*r[n][1]}return e/2<=0},CNe=(r,e=1.2)=>{const{center:t,outline:n}=r;let i=n.map(s=>[s.x,s.y]);INe(i)&&(i=i.reverse());const a=(0,RNt.polygon)({points:i});let o=(0,DNt.extrudeLinear)({height:e},a);return o=(0,NNt.translate)([t.x,t.y,-e/2],o),o},TNt=r=>{const e=hm(r).pcb_board.list()[0];if(!e)return console.warn("No pcb_board found for simplified geometry"),[];let t;const n=1.2;e.outline&&e.outline.length>0?t=CNe({center:e.center,outline:e.outline},n):t=(0,QNt.cuboid)({size:[e.width,e.height,n],center:[e.center.x,e.center.y,0]});const i=Lre[e.material]??eE.fr4Green;return[(0,wNt.colorize)(i,t)]},Sw=wI(dG()),k_=wI(VM()),JM=wI(N5()),Qw=wI(Nre()),nv=wI(VM()),hG=wI(N5()),$B=wI(Nre()),_C=.05,ENe=(r,e)=>{if(r.shape||(r.shape="circle"),r.shape==="circle")return(0,hG.colorize)(eE.copper,(0,$B.subtract)((0,$B.union)((0,nv.cylinder)({center:[r.x,r.y,0],radius:r.hole_diameter/2,height:e.pcbThickness}),(0,nv.cylinder)({center:[r.x,r.y,e.pcbThickness/2+_C/2+gm],radius:r.outer_diameter/2,height:_C}),(0,nv.cylinder)({center:[r.x,r.y,-e.pcbThickness/2-_C/2-gm],radius:r.outer_diameter/2,height:_C})),(0,nv.cylinder)({center:[r.x,r.y,0],radius:r.hole_diameter/2-gm,height:1.5})));if(r.shape==="circular_hole_with_rect_pad"){const t=r.rect_pad_width||r.hole_diameter,n=r.rect_pad_height||r.hole_diameter;return(0,hG.colorize)(eE.copper,(0,$B.subtract)((0,$B.union)((0,nv.cuboid)({center:[r.x,r.y,1.2/2],size:[t,n,_C]}),(0,nv.cuboid)({center:[r.x,r.y,-1.2/2],size:[t,n,_C]}),(0,nv.cylinder)({center:[r.x,r.y,0],radius:r.hole_diameter/2,height:1.2})),(0,nv.cylinder)({center:[r.x,r.y,0],radius:Math.max(r.hole_diameter/2-gm,.01),height:1.5})))}if(r.shape==="pill"){const t=r.hole_height>r.hole_width,n=t?r.hole_height:r.hole_width,i=t?r.hole_width:r.hole_height,a=t?r.outer_height||i+.2:r.outer_width||n+.2,o=t?r.outer_width||n+.2:r.outer_height||i+.2,s=i/2,l=o/2,c=Math.abs(n-i),A=Math.abs(a-o),u=(0,nv.cuboid)({center:[r.x,r.y,0],size:t?[i,c,e.pcbThickness]:[c,i,e.pcbThickness]}),d=(0,nv.cylinder)({center:t?[r.x,r.y-c/2,0]:[r.x-c/2,r.y,0],radius:s,height:e.pcbThickness}),g=(0,nv.cylinder)({center:t?[r.x,r.y+c/2,0]:[r.x+c/2,r.y,0],radius:s,height:e.pcbThickness}),m=(0,$B.union)(u,d,g),C=e.pcbThickness/2+_C/2+gm,E=(0,nv.cuboid)({center:[r.x,r.y,C],size:t?[o,A,_C]:[A,o,_C]}),_=(0,nv.cylinder)({center:t?[r.x,r.y-A/2,C]:[r.x-A/2,r.y,C],radius:l,height:_C}),x=(0,nv.cylinder)({center:t?[r.x,r.y+A/2,C]:[r.x+A/2,r.y,C],radius:l,height:_C}),Q=(0,$B.union)(E,_,x),P=-e.pcbThickness/2-_C/2-gm,z=(0,nv.cuboid)({center:[r.x,r.y,P],size:t?[o,A,_C]:[A,o,_C]}),O=(0,nv.cylinder)({center:t?[r.x,r.y-A/2,P]:[r.x-A/2,r.y,P],radius:l,height:_C}),V=(0,nv.cylinder)({center:t?[r.x,r.y+A/2,P]:[r.x+A/2,r.y,P],radius:l,height:_C}),j=(0,$B.union)(z,O,V),q=(0,nv.cuboid)({center:[r.x,r.y,0],size:t?[i-2*gm,c,e.pcbThickness+2*gm]:[c,i-2*gm,e.pcbThickness+2*gm]}),J=(0,nv.cylinder)({center:t?[r.x,r.y-c/2,0]:[r.x-c/2,r.y,0],radius:s-gm,height:e.pcbThickness+2*gm}),ce=(0,nv.cylinder)({center:t?[r.x,r.y+c/2,0]:[r.x+c/2,r.y,0],radius:s-gm,height:e.pcbThickness+2*gm}),oe=(0,$B.union)(q,J,ce);return(0,hG.colorize)(eE.copper,(0,$B.subtract)((0,$B.union)(m,Q,j),oe))}if(r.shape==="pill_hole_with_rect_pad"){const t=r.hole_height>r.hole_width,n=t?r.hole_height:r.hole_width,i=t?r.hole_width:r.hole_height,a=i/2,o=Math.abs(n-i),s=r.rect_pad_width||n+.2,l=r.rect_pad_height||i+.2,c=(0,nv.cuboid)({center:[r.x,r.y,0],size:t?[i,o,1.2]:[o,i,1.2]}),A=(0,nv.cylinder)({center:t?[r.x,r.y-o/2,0]:[r.x-o/2,r.y,0],radius:a,height:1.2}),u=(0,nv.cylinder)({center:t?[r.x,r.y+o/2,0]:[r.x+o/2,r.y,0],radius:a,height:1.2}),d=(0,nv.cuboid)({center:[r.x,r.y,1.2/2],size:[s,l,_C]}),g=(0,nv.cuboid)({center:[r.x,r.y,-1.2/2],size:[s,l,_C]}),m=(0,$B.union)((0,nv.cuboid)({center:[r.x,r.y,0],size:t?[i-_C,o,1.5]:[o,i-_C,1.5]}),(0,nv.cylinder)({center:t?[r.x,r.y-o/2,0]:[r.x-o/2,r.y,0],radius:a-_C,height:1.5}),(0,nv.cylinder)({center:t?[r.x,r.y+o/2,0]:[r.x+o/2,r.y,0],radius:a-_C,height:1.5}));return(0,hG.colorize)(eE.copper,(0,$B.subtract)((0,$B.union)(c,A,u,d,g),m))}else throw new Error(`Unsupported plated hole shape: ${r.shape}`)},gG=wI(cG()),_Ne=wI(Tre()),PNt=wI(Pre());function BNe(r,e){return Array.isArray(e)?[r.a*e[0]+r.c*e[1]+r.e,r.b*e[0]+r.d*e[1]+r.f]:{x:r.a*e.x+r.c*e.y+r.e,y:r.b*e.x+r.d*e.y+r.f}}function z2(r,e=0){return{a:1,c:0,e:r,b:0,d:1,f:e}}function xNe(...r){r=Array.isArray(r[0])?r[0]:r;const e=(t,n)=>({a:t.a*n.a+t.c*n.b,c:t.a*n.c+t.c*n.d,e:t.a*n.e+t.c*n.f+t.e,b:t.b*n.a+t.d*n.b,d:t.b*n.c+t.d*n.d,f:t.b*n.e+t.d*n.f+t.f});switch(r.length){case 0:throw new Error("no matrices provided");case 1:return r[0];case 2:return e(r[0],r[1]);default:{const[t,n,...i]=r,a=e(t,n);return xNe(a,...i)}}}function bNe(...r){return xNe(...r)}var{cos:UNt,sin:FNt}=Math;function SNe(r,e,t){const n=UNt(r),i=FNt(r);return{a:n,c:-i,e:0,b:i,d:n,f:0}}function kNt(r,e){function t(){this.constructor=r}t.prototype=e.prototype,r.prototype=new t}function pG(r,e,t,n){var i=Error.call(this,r);return Object.setPrototypeOf&&Object.setPrototypeOf(i,pG.prototype),i.expected=e,i.found=t,i.location=n,i.name="SyntaxError",i}kNt(pG,Error);function Ore(r,e,t){return t=t||" ",r.length>e?r:(e-=r.length,t+=t.repeat(e),r+t.slice(0,e))}pG.prototype.format=function(r){var e="Error: "+this.message;if(this.location){var t=null,n;for(n=0;n<r.length;n++)if(r[n].source===this.location.source){t=r[n].text.split(/\r\n|\n|\r/g);break}var i=this.location.start,a=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(i):i,o=this.location.source+":"+a.line+":"+a.column;if(t){var s=this.location.end,l=Ore("",a.line.toString().length," "),c=t[i.line-1],A=i.line===s.line?s.column:c.length+1,u=A-i.column||1;e+=`
|
|
13075
13075
|
--> `+o+`
|
|
13076
13076
|
`+l+` |
|
|
13077
13077
|
`+a.line+" | "+c+`
|
|
@@ -13461,4 +13461,4 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}return Qae}SLt();function F8e(r,e,t,n=
|
|
|
13461
13461
|
&:hover {
|
|
13462
13462
|
background-color: rgba(255, 255, 255, 0.1);
|
|
13463
13463
|
}
|
|
13464
|
-
`,onClick:n=>{n.stopPropagation(),t()},children:[dt.jsx("input",{type:"checkbox",checked:e}),dt.jsx("span",{style:{color:"#eee"},children:r})]}),ezt=({children:r,elements:e})=>{const[t,n]=_1(j=>[j.is_mouse_over_container,j.setIsMouseOverContainer]),[i,a]=yt.useState(!1),[o,s]=yt.useState(!1),[l,c]=yt.useState(!1),[A,u]=_1(j=>[j.selected_layer,j.selectLayer]),[d,g,m,C,E,_]=_1(j=>[j.in_move_footprint_mode,j.in_draw_trace_mode,j.is_showing_rats_nest,j.is_showing_multiple_traces_length,j.is_showing_autorouting,j.is_showing_drc_errors]),x=_1(j=>j.setEditMode),Q=_1(j=>j.setIsShowingRatsNest),P=_1(j=>j.setIsShowingMultipleTracesLength),z=_1(j=>j.setIsShowingAutorouting),O=_1(j=>j.setIsShowingDrcErrors);eQ("1",()=>u("top")),eQ("2",()=>u("bottom")),eQ("3",()=>u("inner1")),eQ("4",()=>u("inner2")),eQ("5",()=>u("inner3")),eQ("6",()=>u("inner4")),eQ("7",()=>u("inner5")),eQ("8",()=>u("inner6"));const V=(e==null?void 0:e.filter(j=>j.type.includes("error")).length)??0;return dt.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>{n(!0)},onMouseLeave:j=>{n(!1),s(!1)},children:[r,dt.jsxs("div",{style:{position:"absolute",bottom:4,right:8,pointerEvents:"none",color:"white",fontSize:11,opacity:t?.5:0,transition:"opacity 1s",transitionDelay:"2s",fontFamily:"sans-serif"},children:["@tscircuit/pcb-viewer@",XOt.version]}),dt.jsxs("div",{style:{position:"absolute",opacity:t?1:0,top:16,left:16,transition:t?"opacity 100ms linear":"opacity 1s linear",zIndex:L_.toolbarOverlay,color:"red",display:"flex",fontSize:12,height:100,fontFamily:"sans-serif"},children:[dt.jsxs(m3,{onClick:()=>{s(!o)},onMouseLeave:()=>{o&&s(!1)},children:[dt.jsxs("div",{children:["layer:"," ",dt.jsx("span",{style:{marginLeft:2,fontWeight:500,color:p3[A]},children:A})]}),o&&dt.jsx("div",{style:{marginTop:4,minWidth:120},children:coe.map(j=>j.replace(/-/g,"")).map(j=>dt.jsx($Ot,{name:j,selected:j===A,onClick:()=>{u(j.replace(/-/,""))}},j))})]}),dt.jsxs(m3,{style:V>0?{color:"red"}:{},onClick:()=>c(!l),onMouseLeave:()=>c(!1),children:[dt.jsxs("div",{children:[V," errors"]}),l&&dt.jsx("div",{style:{display:"grid",gridTemplateColumns:"100px 300px"},children:e==null?void 0:e.filter(j=>j.type.includes("error")).map((j,q)=>dt.jsxs(yt.Fragment,{children:[dt.jsx("div",{children:j.error_type}),dt.jsx("div",{children:j.message})]},q))})]}),dt.jsx(m3,{style:{},onClick:()=>{x(g?"off":"draw_trace")},children:dt.jsxs("div",{children:[g?"✖ ":"","Edit Traces"]})}),dt.jsx(m3,{style:{},onClick:()=>{x(d?"off":"move_footprint")},children:dt.jsxs("div",{children:[d?"✖ ":"","Move Components"]})}),dt.jsx(m3,{style:{},onClick:()=>{Q(!m)},children:dt.jsxs("div",{children:[m?"✖ ":"","Rats Nest"]})}),dt.jsx(m3,{onClick:()=>{a(!i)},children:dt.jsxs("div",{children:[dt.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:["View"," ",dt.jsx("span",{style:{fontSize:"8px",transform:i?"rotate(180deg)":"rotate(0)",transition:"transform 0.1s ease",display:"inline-block"},children:"▼"})]}),i&&dt.jsxs("div",{style:{marginTop:4,minWidth:120},children:[dt.jsx(goe,{label:"Show All Trace Lengths",checked:C,onClick:()=>{P(!C)}}),dt.jsx(goe,{label:"Show Autorouting Animation",checked:E,onClick:()=>{z(!E)}}),dt.jsx(goe,{label:"Show DRC Errors",checked:_,onClick:()=>{O(!_)}})]})]})})]})]})},tzt=r=>{const{transform:e,elements:t}=r,[n,i]=yt.useMemo(()=>{const c=r.elements.flatMap(u=>dOt(u,r.elements)),A=pS(r.elements);return[c,A]},[r.elements]),[a,o]=yt.useState({drawingObjectIdsWithMouseOver:new Set,primitiveIdsInMousedOverNet:[]}),s=yt.useMemo(()=>AOt({primitivesWithoutInteractionMetadata:n,drawingObjectIdsWithMouseOver:a.drawingObjectIdsWithMouseOver,primitiveIdsInMousedOverNet:a.primitiveIdsInMousedOverNet}),[n,a]),l=yt.useCallback(c=>{var d,g;const A=[];for(const m of c)if(m._element){const C=i.getNetConnectedToId("pcb_port_id"in m._element?(d=m._element)==null?void 0:d.pcb_port_id:"pcb_trace_id"in m._element?(g=m._element)==null?void 0:g.pcb_trace_id:"");A.push(...i.getIdsConnectedToNet(C))}const u=new Set(c.map(m=>m._pcb_drawing_object_id));o({drawingObjectIdsWithMouseOver:u,primitiveIdsInMousedOverNet:A})},[i]);return dt.jsx(ZOt,{elements:t,transform:e,primitives:n,onMouseHoverOverPrimitives:l,children:dt.jsx(NOt,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:dt.jsx(FOt,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:dt.jsx(DOt,{transform:e,focusOnHover:r.focusOnHover,children:dt.jsx(ezt,{elements:t,children:dt.jsx(LOt,{transform:e,elements:t,children:dt.jsx(qOt,{transform:e,soup:t,children:dt.jsx(wOt,{transform:e,debugGraphics:r.debugGraphics,children:dt.jsx(MOt,{transform:e,elements:t,children:dt.jsx(QOt,{transform:e,primitives:s,width:r.width,height:r.height,grid:r.grid})})})})})})})})})})},nzt=OA(Kd(400,300),L1(40,-40)),rzt=({circuitJson:r,debugGraphics:e,height:t=600,initialState:n,allowEditing:i=!0,editEvents:a,onEditEventsChanged:o,focusOnHover:s=!1,clickToInteractEnabled:l=!1})=>{const[c,A]=yt.useState(!l),[u,d]=foe(),[g,m]=yt.useState(nzt),{ref:C,setTransform:E,cancelDrag:_}=cOt({transform:g,onSetTransform:m,enabled:c});let[x,Q]=yt.useState([]);x=a??x;const P=yt.useRef(!1),z=yt.useRef(null),O=`${(r==null?void 0:r.length)||0}_${(r==null?void 0:r.editCount)||0}`,V=()=>{const oe=(d==null?void 0:d.width)>0?d:{width:500,height:500},{center:de,width:Ie,height:Be}=q.some(ve=>ve.type.startsWith("pcb_"))?$7t(q.filter(ve=>ve.type.startsWith("pcb_"))):{center:{x:0,y:0},width:.001,height:.001},pe=Math.min((oe.width??0)/Ie,(oe.height??0)/Be,100)*.75,_e=OA(Kd((oe.width??0)/2,(oe.height??0)/2),L1(pe,-pe,0,0),Kd(-de.x,-de.y));E(_e)};yt.useEffect(()=>{d!=null&&d.width&&r&&r.length!==0&&(P.current||(V(),P.current=!0))},[r,d]);const j=yt.useMemo(()=>(r==null?void 0:r.filter(oe=>oe.type.startsWith("pcb_")||oe.type.startsWith("source_")))??[],[O]),q=yt.useMemo(()=>vGt({circuitJson:j,editEvents:x}),[j,x]),J=oe=>{Q([...x,oe]),o==null||o([...x,oe])},ce=oe=>{const de=x.map(Ie=>Ie.edit_event_id===oe.edit_event_id?{...Ie,...oe}:Ie);Q(de),o==null||o(de)};return dt.jsxs("div",{ref:C,style:{position:"relative"},children:[dt.jsx("div",{ref:u,children:dt.jsxs(tOt,{initialState:n,children:[dt.jsx(tzt,{transform:g,height:t,width:d.width,allowEditing:i,focusOnHover:s,cancelPanDrag:_,onCreateEditEvent:J,onModifyEditEvent:ce,grid:{spacing:1,view_window:{left:0,right:d.width||500,top:t,bottom:0}},elements:q,debugGraphics:e},d.width),dt.jsx(rOt,{})]})}),l&&!c&&dt.jsx("div",{onClick:()=>{A(!0),V()},onTouchStart:oe=>{const de=oe.touches[0];z.current={x:de.clientX,y:de.clientY}},onTouchEnd:oe=>{const de=oe.changedTouches[0],Ie=z.current;if(!Ie)return;const Be=Math.abs(de.clientX-Ie.x),pe=Math.abs(de.clientY-Ie.y);Be<10&&pe<10&&(oe.preventDefault(),A(!0),V()),z.current=null},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:L_.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center",touchAction:"pan-x pan-y pinch-zoom"},children:dt.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",pointerEvents:"none"},children:typeof window<"u"&&("ontouchstart"in window||navigator.maxTouchPoints>0)?"Touch to Interact":"Click to Interact"})})]})};const izt=({containerClassName:r,...e})=>{const t=yt.useRef(null),[n,i]=yt.useState(620);return yt.useLayoutEffect(()=>{const a=()=>{if(t.current){const s=t.current.clientHeight,l=window.innerHeight;i(Math.min(Math.max(s,620),l))}};a();const o=new ResizeObserver(a);return t.current&&o.observe(t.current),window.addEventListener("resize",a),()=>{o.disconnect(),window.removeEventListener("resize",a)}},[]),dt.jsx("div",{ref:t,className:r||"rf-w-full rf-h-full",children:dt.jsx(rzt,{...e,height:n})})},azt='*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }/*! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com*/*,:after,:before{border:0 solid #e5e7eb;box-sizing:border-box}:after,:before{--tw-content:""}:host,html{line-height:1.5;-webkit-text-size-adjust:100%;font-family:ui-sans-serif,system-ui,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-tap-highlight-color:transparent}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-size:1em;font-variation-settings:normal}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{color:inherit;font-family:inherit;font-feature-settings:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;letter-spacing:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{color:#9ca3af;opacity:1}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]:where(:not([hidden=until-found])){display:none}:root{--radius:0.5rem}.rf-pointer-events-none{pointer-events:none}.rf-invisible{visibility:hidden}.rf-fixed{position:fixed}.rf-absolute{position:absolute}.rf-relative{position:relative}.rf-inset-0{inset:0}.-rf-left-2{left:-.5rem}.-rf-right-10{right:-2.5rem}.-rf-right-2{right:-.5rem}.-rf-right-4{right:-1rem}.-rf-right-6{right:-1.5rem}.-rf-right-7{right:-1.75rem}.-rf-right-8{right:-2rem}.-rf-right-9{right:-2.25rem}.rf-bottom-full{bottom:100%}.rf-left-0{left:0}.rf-left-1{left:.25rem}.rf-left-1\\/2{left:50%}.rf-left-2{left:.5rem}.rf-left-\\[50\\%\\]{left:50%}.rf-right-0{right:0}.rf-right-4{right:1rem}.rf-right-\\[4px\\]{right:4px}.rf-top-0{top:0}.rf-top-1{top:.25rem}.rf-top-2{top:.5rem}.rf-top-2\\.5{top:.625rem}.rf-top-\\[50\\%\\]{top:50%}.rf-top-\\[6px\\]{top:6px}.rf-z-50{z-index:50}.rf-z-\\[100\\]{z-index:100}.-rf-mx-1,.rf--mx-1{margin-left:-.25rem;margin-right:-.25rem}.rf-mx-1{margin-left:.25rem;margin-right:.25rem}.rf-mx-2{margin-left:.5rem;margin-right:.5rem}.rf-mx-auto{margin-left:auto;margin-right:auto}.rf-my-1{margin-bottom:.25rem;margin-top:.25rem}.rf-my-12{margin-bottom:3rem;margin-top:3rem}.rf-my-4{margin-bottom:1rem;margin-top:1rem}.rf-my-auto{margin-bottom:auto;margin-top:auto}.rf-mb-1{margin-bottom:.25rem}.rf-mb-12{margin-bottom:3rem}.rf-mb-2{margin-bottom:.5rem}.rf-mb-3{margin-bottom:.75rem}.rf-mb-4{margin-bottom:1rem}.rf-mb-6{margin-bottom:1.5rem}.rf-mb-8{margin-bottom:2rem}.rf-ml-1{margin-left:.25rem}.rf-ml-2{margin-left:.5rem}.rf-ml-auto{margin-left:auto}.rf-mr-1{margin-right:.25rem}.rf-mr-2{margin-right:.5rem}.rf-mt-0{margin-top:0}.rf-mt-0\\.5{margin-top:.125rem}.rf-mt-1{margin-top:.25rem}.rf-mt-2{margin-top:.5rem}.rf-mt-3{margin-top:.75rem}.rf-mt-4{margin-top:1rem}.rf-mt-5{margin-top:1.25rem}.rf-mt-auto{margin-top:auto}.rf-block{display:block}.rf-inline{display:inline}.rf-flex{display:flex}.rf-inline-flex{display:inline-flex}.rf-grid{display:grid}.rf-hidden{display:none}.rf-aspect-square{aspect-ratio:1/1}.rf-aspect-video{aspect-ratio:16/9}.rf-size-14{height:3.5rem;width:3.5rem}.rf-size-4{height:1rem;width:1rem}.\\!rf-h-2{height:.5rem!important}.\\!rf-h-2\\.5{height:.625rem!important}.\\!rf-h-3{height:.75rem!important}.\\!rf-h-full{height:100%!important}.rf-h-1{height:.25rem}.rf-h-10{height:2.5rem}.rf-h-12{height:3rem}.rf-h-2{height:.5rem}.rf-h-2\\.5{height:.625rem}.rf-h-3{height:.75rem}.rf-h-3\\.5{height:.875rem}.rf-h-4{height:1rem}.rf-h-5{height:1.25rem}.rf-h-6{height:1.5rem}.rf-h-60{height:15rem}.rf-h-64{height:16rem}.rf-h-8{height:2rem}.rf-h-9{height:2.25rem}.rf-h-\\[620px\\]{height:620px}.rf-h-\\[calc\\(100vh-52px\\)\\]{height:calc(100vh - 52px)}.rf-h-\\[calc\\(100vh-96px\\)\\]{height:calc(100vh - 96px)}.rf-h-\\[var\\(--radix-select-trigger-height\\)\\]{height:var(--radix-select-trigger-height)}.rf-h-fit{height:-moz-fit-content;height:fit-content}.rf-h-full{height:100%}.rf-h-px{height:1px}.\\!rf-max-h-\\[40vh\\]{max-height:40vh!important}.\\!rf-max-h-\\[70\\%\\]{max-height:70%!important}.rf-max-h-32{max-height:8rem}.rf-max-h-96{max-height:24rem}.rf-max-h-\\[500px\\]{max-height:500px}.rf-max-h-\\[90vh\\]{max-height:90vh}.rf-min-h-0{min-height:0}.rf-min-h-\\[200px\\]{min-height:200px}.rf-min-h-\\[620px\\]{min-height:620px}.rf-min-h-\\[calc\\(100vh-240px\\)\\]{min-height:calc(100vh - 240px)}.\\!rf-w-2{width:.5rem!important}.\\!rf-w-2\\.5{width:.625rem!important}.rf-w-1{width:.25rem}.rf-w-1\\/2{width:50%}.rf-w-11{width:2.75rem}.rf-w-11\\/12{width:91.666667%}.rf-w-12{width:3rem}.rf-w-16{width:4rem}.rf-w-2{width:.5rem}.rf-w-2\\.5{width:.625rem}.rf-w-3{width:.75rem}.rf-w-3\\.5{width:.875rem}.rf-w-32{width:8rem}.rf-w-4{width:1rem}.rf-w-5{width:1.25rem}.rf-w-6{width:1.5rem}.rf-w-64{width:16rem}.rf-w-72{width:18rem}.rf-w-8{width:2rem}.rf-w-9{width:2.25rem}.rf-w-96{width:24rem}.rf-w-\\[95\\%\\]{width:95%}.rf-w-fit{width:-moz-fit-content;width:fit-content}.rf-w-full{width:100%}.rf-min-w-10{min-width:2.5rem}.rf-min-w-16{min-width:4rem}.rf-min-w-\\[148px\\]{min-width:148px}.rf-min-w-\\[8rem\\]{min-width:8rem}.rf-min-w-\\[var\\(--radix-select-trigger-width\\)\\]{min-width:var(--radix-select-trigger-width)}.\\!rf-max-w-\\[60vw\\]{max-width:60vw!important}.\\!rf-max-w-\\[660px\\]{max-width:660px!important}.rf-max-w-2xl{max-width:42rem}.rf-max-w-3xl{max-width:48rem}.rf-max-w-5xl{max-width:64rem}.rf-max-w-full{max-width:100%}.rf-max-w-lg{max-width:32rem}.rf-max-w-md{max-width:28rem}.rf-max-w-xl{max-width:36rem}.rf-flex-1{flex:1 1 0%}.rf-flex-shrink-0,.rf-shrink-0{flex-shrink:0}.rf-flex-grow{flex-grow:1}.rf-table-auto{table-layout:auto}.-rf-translate-x-1{--tw-translate-x:-0.25rem}.-rf-translate-x-1,.-rf-translate-x-1\\/2{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.-rf-translate-x-1\\/2{--tw-translate-x:-50%}.-rf-translate-y-1{--tw-translate-y:-0.25rem}.-rf-translate-y-1,.rf--translate-x-1{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rf--translate-x-1{--tw-translate-x:-0.25rem}.rf-translate-x-\\[-50\\%\\]{--tw-translate-x:-50%}.rf-translate-x-\\[-50\\%\\],.rf-translate-y-\\[-50\\%\\]{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rf-translate-y-\\[-50\\%\\]{--tw-translate-y:-50%}.rf-transform{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes rf-pulse{50%{opacity:.5}}.rf-animate-pulse{animation:rf-pulse 2s cubic-bezier(.4,0,.6,1) infinite}@keyframes rf-spin{to{transform:rotate(1turn)}}.rf-animate-spin{animation:rf-spin 1s linear infinite}.rf-cursor-default{cursor:default}.rf-cursor-not-allowed{cursor:not-allowed}.rf-cursor-pointer{cursor:pointer}.rf-select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.rf-grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.rf-grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.rf-flex-row{flex-direction:row}.rf-flex-col{flex-direction:column}.rf-flex-col-reverse{flex-direction:column-reverse}.rf-flex-wrap{flex-wrap:wrap}.rf-place-items-center{place-items:center}.rf-items-start{align-items:flex-start}.rf-items-end{align-items:flex-end}.rf-items-center{align-items:center}.rf-justify-end{justify-content:flex-end}.rf-justify-center{justify-content:center}.rf-justify-between{justify-content:space-between}.rf-gap-0{gap:0}.rf-gap-1{gap:.25rem}.rf-gap-2{gap:.5rem}.rf-gap-3{gap:.75rem}.rf-gap-4{gap:1rem}.rf-gap-5{gap:1.25rem}.rf-gap-6{gap:1.5rem}.rf-gap-8{gap:2rem}.rf-space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-left:calc(.5rem*(1 - var(--tw-space-x-reverse)));margin-right:calc(.5rem*var(--tw-space-x-reverse))}.rf-space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(.5rem*var(--tw-space-y-reverse));margin-top:calc(.5rem*(1 - var(--tw-space-y-reverse)))}.rf-space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(1rem*var(--tw-space-y-reverse));margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)))}.rf-space-y-6>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(1.5rem*var(--tw-space-y-reverse));margin-top:calc(1.5rem*(1 - var(--tw-space-y-reverse)))}.rf-divide-y>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-bottom-width:calc(1px*var(--tw-divide-y-reverse));border-top-width:calc(1px*(1 - var(--tw-divide-y-reverse)))}.rf-overflow-auto{overflow:auto}.rf-overflow-hidden{overflow:hidden}.rf-overflow-visible{overflow:visible}.rf-overflow-x-auto{overflow-x:auto}.\\!rf-overflow-y-auto{overflow-y:auto!important}.rf-overflow-y-auto{overflow-y:auto}.\\!rf-overflow-x-hidden{overflow-x:hidden!important}.rf-overflow-x-hidden{overflow-x:hidden}.rf-overflow-x-clip{overflow-x:clip}.rf-truncate{overflow:hidden;text-overflow:ellipsis}.rf-truncate,.rf-whitespace-nowrap{white-space:nowrap}.rf-whitespace-pre-wrap{white-space:pre-wrap}.rf-break-words{overflow-wrap:break-word}.rf-rounded{border-radius:.25rem}.rf-rounded-2xl{border-radius:1rem}.rf-rounded-full{border-radius:9999px}.rf-rounded-lg{border-radius:var(--radius)}.rf-rounded-md{border-radius:calc(var(--radius) - 2px)}.rf-rounded-sm{border-radius:calc(var(--radius) - 4px)}.rf-rounded-xl{border-radius:.75rem}.rf-border{border-width:1px}.rf-border-b{border-bottom-width:1px}.rf-border-t{border-top-width:1px}.rf-border-blue-200{--tw-border-opacity:1;border-color:rgb(191 219 254/var(--tw-border-opacity,1))}.rf-border-blue-500{--tw-border-opacity:1;border-color:rgb(59 130 246/var(--tw-border-opacity,1))}.rf-border-blue-600{--tw-border-opacity:1;border-color:rgb(37 99 235/var(--tw-border-opacity,1))}.rf-border-gray-200{--tw-border-opacity:1;border-color:rgb(229 231 235/var(--tw-border-opacity,1))}.rf-border-gray-300{--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity,1))}.rf-border-green-200{--tw-border-opacity:1;border-color:rgb(187 247 208/var(--tw-border-opacity,1))}.rf-border-input{border-color:hsl(var(--input))}.rf-border-neutral-200{--tw-border-opacity:1;border-color:rgb(229 229 229/var(--tw-border-opacity,1))}.rf-border-primary{border-color:hsl(var(--primary))}.rf-border-red-200{--tw-border-opacity:1;border-color:rgb(254 202 202/var(--tw-border-opacity,1))}.rf-border-red-500{--tw-border-opacity:1;border-color:rgb(239 68 68/var(--tw-border-opacity,1))}.rf-border-zinc-200{--tw-border-opacity:1;border-color:rgb(228 228 231/var(--tw-border-opacity,1))}.rf-border-zinc-900{--tw-border-opacity:1;border-color:rgb(24 24 27/var(--tw-border-opacity,1))}.rf-bg-background{background-color:hsl(var(--background))}.rf-bg-black{--tw-bg-opacity:1;background-color:rgb(0 0 0/var(--tw-bg-opacity,1))}.rf-bg-black\\/80{background-color:rgba(0,0,0,.8)}.rf-bg-blue-100{--tw-bg-opacity:1;background-color:rgb(219 234 254/var(--tw-bg-opacity,1))}.rf-bg-blue-50{--tw-bg-opacity:1;background-color:rgb(239 246 255/var(--tw-bg-opacity,1))}.rf-bg-blue-500{--tw-bg-opacity:1;background-color:rgb(59 130 246/var(--tw-bg-opacity,1))}.rf-bg-blue-600{--tw-bg-opacity:1;background-color:rgb(37 99 235/var(--tw-bg-opacity,1))}.rf-bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.rf-bg-gray-200{--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity,1))}.rf-bg-gray-300{--tw-bg-opacity:1;background-color:rgb(209 213 219/var(--tw-bg-opacity,1))}.rf-bg-gray-400{--tw-bg-opacity:1;background-color:rgb(156 163 175/var(--tw-bg-opacity,1))}.rf-bg-gray-50{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity,1))}.rf-bg-gray-500{--tw-bg-opacity:1;background-color:rgb(107 114 128/var(--tw-bg-opacity,1))}.rf-bg-gray-700{--tw-bg-opacity:1;background-color:rgb(55 65 81/var(--tw-bg-opacity,1))}.rf-bg-gray-800{--tw-bg-opacity:1;background-color:rgb(31 41 55/var(--tw-bg-opacity,1))}.rf-bg-gray-900{--tw-bg-opacity:1;background-color:rgb(17 24 39/var(--tw-bg-opacity,1))}.rf-bg-green-100{--tw-bg-opacity:1;background-color:rgb(220 252 231/var(--tw-bg-opacity,1))}.rf-bg-green-50{--tw-bg-opacity:1;background-color:rgb(240 253 244/var(--tw-bg-opacity,1))}.rf-bg-muted{background-color:hsl(var(--muted))}.rf-bg-neutral-100{--tw-bg-opacity:1;background-color:rgb(245 245 245/var(--tw-bg-opacity,1))}.rf-bg-neutral-50{--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.rf-bg-neutral-800{--tw-bg-opacity:1;background-color:rgb(38 38 38/var(--tw-bg-opacity,1))}.rf-bg-neutral-900{--tw-bg-opacity:1;background-color:rgb(23 23 23/var(--tw-bg-opacity,1))}.rf-bg-orange-400{--tw-bg-opacity:1;background-color:rgb(251 146 60/var(--tw-bg-opacity,1))}.rf-bg-popover{background-color:hsl(var(--popover))}.rf-bg-red-100{--tw-bg-opacity:1;background-color:rgb(254 226 226/var(--tw-bg-opacity,1))}.rf-bg-red-50{--tw-bg-opacity:1;background-color:rgb(254 242 242/var(--tw-bg-opacity,1))}.rf-bg-red-500{--tw-bg-opacity:1;background-color:rgb(239 68 68/var(--tw-bg-opacity,1))}.rf-bg-red-900{--tw-bg-opacity:1;background-color:rgb(127 29 29/var(--tw-bg-opacity,1))}.rf-bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.rf-bg-yellow-100{--tw-bg-opacity:1;background-color:rgb(254 249 195/var(--tw-bg-opacity,1))}.rf-bg-zinc-100{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.rf-bg-zinc-200{--tw-bg-opacity:1;background-color:rgb(228 228 231/var(--tw-bg-opacity,1))}.rf-bg-zinc-50{--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.rf-bg-zinc-800{--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.rf-bg-zinc-900{--tw-bg-opacity:1;background-color:rgb(24 24 27/var(--tw-bg-opacity,1))}.rf-bg-opacity-50{--tw-bg-opacity:0.5}.rf-fill-current{fill:currentColor}.rf-object-contain{-o-object-fit:contain;object-fit:contain}.\\!rf-p-0{padding:0!important}.rf-p-0{padding:0}.rf-p-1{padding:.25rem}.rf-p-2{padding:.5rem}.rf-p-3{padding:.75rem}.rf-p-4{padding:1rem}.rf-p-5{padding:1.25rem}.rf-p-6{padding:1.5rem}.rf-p-8{padding:2rem}.rf-px-1{padding-left:.25rem;padding-right:.25rem}.rf-px-2{padding-left:.5rem;padding-right:.5rem}.rf-px-3{padding-left:.75rem;padding-right:.75rem}.rf-px-4{padding-left:1rem;padding-right:1rem}.rf-px-6{padding-left:1.5rem;padding-right:1.5rem}.rf-px-8{padding-left:2rem;padding-right:2rem}.rf-py-0{padding-bottom:0;padding-top:0}.rf-py-0\\.5{padding-bottom:.125rem;padding-top:.125rem}.rf-py-1{padding-bottom:.25rem;padding-top:.25rem}.rf-py-1\\.5{padding-bottom:.375rem;padding-top:.375rem}.rf-py-10{padding-bottom:2.5rem;padding-top:2.5rem}.rf-py-12{padding-bottom:3rem;padding-top:3rem}.rf-py-2{padding-bottom:.5rem;padding-top:.5rem}.rf-py-3{padding-bottom:.75rem;padding-top:.75rem}.rf-py-4{padding-bottom:1rem;padding-top:1rem}.rf-py-8{padding-bottom:2rem;padding-top:2rem}.rf-pb-0{padding-bottom:0}.rf-pb-2{padding-bottom:.5rem}.rf-pb-3{padding-bottom:.75rem}.rf-pb-4{padding-bottom:1rem}.rf-pl-2{padding-left:.5rem}.rf-pl-4{padding-left:1rem}.rf-pl-8{padding-left:2rem}.rf-pr-2{padding-right:.5rem}.rf-pt-2{padding-top:.5rem}.rf-pt-4{padding-top:1rem}.rf-text-left{text-align:left}.rf-text-center{text-align:center}.rf-text-right{text-align:right}.rf-font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.rf-text-2xl{font-size:1.5rem;line-height:2rem}.rf-text-3xl{font-size:1.875rem;line-height:2.25rem}.rf-text-\\[8px\\]{font-size:8px}.rf-text-base{font-size:1rem;line-height:1.5rem}.rf-text-lg{font-size:1.125rem;line-height:1.75rem}.rf-text-sm{font-size:.875rem;line-height:1.25rem}.rf-text-xl{font-size:1.25rem;line-height:1.75rem}.rf-text-xs{font-size:.75rem;line-height:1rem}.rf-font-bold{font-weight:700}.rf-font-medium{font-weight:500}.rf-font-semibold{font-weight:600}.rf-capitalize{text-transform:capitalize}.rf-tabular-nums{--tw-numeric-spacing:tabular-nums;font-variant-numeric:var(--tw-ordinal) var(--tw-slashed-zero) var(--tw-numeric-figure) var(--tw-numeric-spacing) var(--tw-numeric-fraction)}.rf-leading-5{line-height:1.25rem}.rf-leading-none{line-height:1}.rf-leading-tight{line-height:1.25}.rf-tracking-widest{letter-spacing:.1em}.rf-text-black{--tw-text-opacity:1;color:rgb(0 0 0/var(--tw-text-opacity,1))}.rf-text-blue-500{--tw-text-opacity:1;color:rgb(59 130 246/var(--tw-text-opacity,1))}.rf-text-blue-600{--tw-text-opacity:1;color:rgb(37 99 235/var(--tw-text-opacity,1))}.rf-text-blue-700{--tw-text-opacity:1;color:rgb(29 78 216/var(--tw-text-opacity,1))}.rf-text-blue-800{--tw-text-opacity:1;color:rgb(30 64 175/var(--tw-text-opacity,1))}.rf-text-blue-900{--tw-text-opacity:1;color:rgb(30 58 138/var(--tw-text-opacity,1))}.rf-text-current{color:currentColor}.rf-text-gray-400{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity,1))}.rf-text-gray-500{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity,1))}.rf-text-gray-600{--tw-text-opacity:1;color:rgb(75 85 99/var(--tw-text-opacity,1))}.rf-text-gray-700{--tw-text-opacity:1;color:rgb(55 65 81/var(--tw-text-opacity,1))}.rf-text-gray-800{--tw-text-opacity:1;color:rgb(31 41 55/var(--tw-text-opacity,1))}.rf-text-gray-900{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity,1))}.rf-text-green-500{--tw-text-opacity:1;color:rgb(34 197 94/var(--tw-text-opacity,1))}.rf-text-green-600{--tw-text-opacity:1;color:rgb(22 163 74/var(--tw-text-opacity,1))}.rf-text-green-700{--tw-text-opacity:1;color:rgb(21 128 61/var(--tw-text-opacity,1))}.rf-text-green-800{--tw-text-opacity:1;color:rgb(22 101 52/var(--tw-text-opacity,1))}.rf-text-green-900{--tw-text-opacity:1;color:rgb(20 83 45/var(--tw-text-opacity,1))}.rf-text-muted-foreground{color:hsl(var(--muted-foreground))}.rf-text-neutral-50{--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.rf-text-neutral-500{--tw-text-opacity:1;color:rgb(115 115 115/var(--tw-text-opacity,1))}.rf-text-neutral-900{--tw-text-opacity:1;color:rgb(23 23 23/var(--tw-text-opacity,1))}.rf-text-neutral-950{--tw-text-opacity:1;color:rgb(10 10 10/var(--tw-text-opacity,1))}.rf-text-popover-foreground{color:hsl(var(--popover-foreground))}.rf-text-red-200{--tw-text-opacity:1;color:rgb(254 202 202/var(--tw-text-opacity,1))}.rf-text-red-300{--tw-text-opacity:1;color:rgb(252 165 165/var(--tw-text-opacity,1))}.rf-text-red-400{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.rf-text-red-500{--tw-text-opacity:1;color:rgb(239 68 68/var(--tw-text-opacity,1))}.rf-text-red-600{--tw-text-opacity:1;color:rgb(220 38 38/var(--tw-text-opacity,1))}.rf-text-red-700{--tw-text-opacity:1;color:rgb(185 28 28/var(--tw-text-opacity,1))}.rf-text-red-800{--tw-text-opacity:1;color:rgb(153 27 27/var(--tw-text-opacity,1))}.rf-text-red-900{--tw-text-opacity:1;color:rgb(127 29 29/var(--tw-text-opacity,1))}.rf-text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.rf-text-yellow-400{--tw-text-opacity:1;color:rgb(250 204 21/var(--tw-text-opacity,1))}.rf-text-yellow-500{--tw-text-opacity:1;color:rgb(234 179 8/var(--tw-text-opacity,1))}.rf-text-yellow-900{--tw-text-opacity:1;color:rgb(113 63 18/var(--tw-text-opacity,1))}.rf-text-zinc-200{--tw-text-opacity:1;color:rgb(228 228 231/var(--tw-text-opacity,1))}.rf-text-zinc-300{--tw-text-opacity:1;color:rgb(212 212 216/var(--tw-text-opacity,1))}.rf-text-zinc-400{--tw-text-opacity:1;color:rgb(161 161 170/var(--tw-text-opacity,1))}.rf-text-zinc-50{--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.rf-text-zinc-500{--tw-text-opacity:1;color:rgb(113 113 122/var(--tw-text-opacity,1))}.rf-text-zinc-900{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.rf-text-zinc-950{--tw-text-opacity:1;color:rgb(9 9 11/var(--tw-text-opacity,1))}.rf-underline{text-decoration-line:underline}.rf-line-through{text-decoration-line:line-through}.rf-underline-offset-4{text-underline-offset:4px}.rf-opacity-0{opacity:0}.rf-opacity-25{opacity:.25}.rf-opacity-30{opacity:.3}.rf-opacity-50{opacity:.5}.rf-opacity-60{opacity:.6}.rf-opacity-75{opacity:.75}.rf-shadow{--tw-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px -1px rgba(0,0,0,.1);--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color)}.rf-shadow,.rf-shadow-lg{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.rf-shadow-lg{--tw-shadow:0 10px 15px -3px rgba(0,0,0,.1),0 4px 6px -4px rgba(0,0,0,.1);--tw-shadow-colored:0 10px 15px -3px var(--tw-shadow-color),0 4px 6px -4px var(--tw-shadow-color)}.rf-shadow-md{--tw-shadow:0 4px 6px -1px rgba(0,0,0,.1),0 2px 4px -2px rgba(0,0,0,.1);--tw-shadow-colored:0 4px 6px -1px var(--tw-shadow-color),0 2px 4px -2px var(--tw-shadow-color)}.rf-shadow-md,.rf-shadow-sm{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.rf-shadow-sm{--tw-shadow:0 1px 2px 0 rgba(0,0,0,.05);--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color)}.rf-outline-none{outline:2px solid transparent;outline-offset:2px}.rf-ring-2{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.rf-ring-blue-500{--tw-ring-opacity:1;--tw-ring-color:rgb(59 130 246/var(--tw-ring-opacity,1))}.rf-ring-primary{--tw-ring-color:hsl(var(--primary))}.rf-ring-offset-background{--tw-ring-offset-color:hsl(var(--background))}.rf-ring-offset-white{--tw-ring-offset-color:#fff}.rf-transition{transition-duration:.15s;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-transition-all{transition-duration:.15s;transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-transition-colors{transition-duration:.15s;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-transition-opacity{transition-duration:.15s;transition-property:opacity;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-duration-200{transition-duration:.2s}.rf-ease-in-out{transition-timing-function:cubic-bezier(.4,0,.2,1)}@keyframes enter{0%{opacity:var(--tw-enter-opacity,1);transform:translate3d(var(--tw-enter-translate-x,0),var(--tw-enter-translate-y,0),0) scale3d(var(--tw-enter-scale,1),var(--tw-enter-scale,1),var(--tw-enter-scale,1)) rotate(var(--tw-enter-rotate,0))}}@keyframes exit{to{opacity:var(--tw-exit-opacity,1);transform:translate3d(var(--tw-exit-translate-x,0),var(--tw-exit-translate-y,0),0) scale3d(var(--tw-exit-scale,1),var(--tw-exit-scale,1),var(--tw-exit-scale,1)) rotate(var(--tw-exit-rotate,0))}}.rf-slide-in-from-left-1{--tw-enter-translate-x:-0.25rem}.rf-slide-out-to-left-1{--tw-exit-translate-x:-0.25rem}.rf-duration-200{animation-duration:.2s}.rf-ease-in-out{animation-timing-function:cubic-bezier(.4,0,.2,1)}.file\\:rf-border-0::file-selector-button{border-width:0}.file\\:rf-bg-transparent::file-selector-button{background-color:transparent}.file\\:rf-text-sm::file-selector-button{font-size:.875rem;line-height:1.25rem}.file\\:rf-font-medium::file-selector-button{font-weight:500}.placeholder\\:rf-text-zinc-500::-moz-placeholder{--tw-text-opacity:1;color:rgb(113 113 122/var(--tw-text-opacity,1))}.placeholder\\:rf-text-zinc-500::placeholder{--tw-text-opacity:1;color:rgb(113 113 122/var(--tw-text-opacity,1))}.hover\\:rf-border-blue-300:hover{--tw-border-opacity:1;border-color:rgb(147 197 253/var(--tw-border-opacity,1))}.hover\\:\\!rf-bg-transparent:hover{background-color:transparent!important}.hover\\:rf-bg-blue-700:hover{--tw-bg-opacity:1;background-color:rgb(29 78 216/var(--tw-bg-opacity,1))}.hover\\:rf-bg-red-500\\/90:hover{background-color:rgba(239,68,68,.9)}.hover\\:rf-bg-zinc-100:hover{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.hover\\:rf-bg-zinc-100\\/80:hover{background-color:hsla(240,5%,96%,.8)}.hover\\:rf-bg-zinc-900\\/90:hover{background-color:rgba(24,24,27,.9)}.hover\\:rf-text-red-400:hover{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.hover\\:rf-text-zinc-900:hover{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.hover\\:rf-underline:hover{text-decoration-line:underline}.focus\\:rf-bg-gray-100:focus{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.focus\\:rf-bg-zinc-100:focus{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.focus\\:rf-text-gray-900:focus{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity,1))}.focus\\:rf-text-zinc-900:focus{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.focus\\:rf-outline-none:focus{outline:2px solid transparent;outline-offset:2px}.focus\\:rf-ring-2:focus{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus\\:rf-ring-ring:focus{--tw-ring-color:hsl(var(--ring))}.focus\\:rf-ring-offset-2:focus{--tw-ring-offset-width:2px}.focus-visible\\:rf-outline-none:focus-visible{outline:2px solid transparent;outline-offset:2px}.focus-visible\\:rf-ring-1:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:rf-ring-2:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:rf-ring-zinc-950:focus-visible{--tw-ring-opacity:1;--tw-ring-color:rgb(9 9 11/var(--tw-ring-opacity,1))}.focus-visible\\:rf-ring-offset-2:focus-visible{--tw-ring-offset-width:2px}.disabled\\:rf-pointer-events-none:disabled{pointer-events:none}.disabled\\:rf-cursor-not-allowed:disabled{cursor:not-allowed}.disabled\\:rf-opacity-50:disabled{opacity:.5}.rf-group\\/bar:hover .group-hover\\/bar\\:rf-opacity-100{opacity:1}.data-\\[disabled\\]\\:rf-pointer-events-none[data-disabled]{pointer-events:none}.data-\\[side\\=bottom\\]\\:rf-translate-y-1[data-side=bottom]{--tw-translate-y:0.25rem}.data-\\[side\\=bottom\\]\\:rf-translate-y-1[data-side=bottom],.data-\\[side\\=left\\]\\:-rf-translate-x-1[data-side=left]{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.data-\\[side\\=left\\]\\:-rf-translate-x-1[data-side=left]{--tw-translate-x:-0.25rem}.data-\\[side\\=right\\]\\:rf-translate-x-1[data-side=right]{--tw-translate-x:0.25rem}.data-\\[side\\=right\\]\\:rf-translate-x-1[data-side=right],.data-\\[side\\=top\\]\\:-rf-translate-y-1[data-side=top]{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.data-\\[side\\=top\\]\\:-rf-translate-y-1[data-side=top]{--tw-translate-y:-0.25rem}.data-\\[state\\=active\\]\\:rf-bg-white[data-state=active]{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.data-\\[state\\=checked\\]\\:rf-bg-zinc-900[data-state=checked]{--tw-bg-opacity:1;background-color:rgb(24 24 27/var(--tw-bg-opacity,1))}.data-\\[state\\=open\\]\\:rf-bg-zinc-100[data-state=open]{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.data-\\[state\\=active\\]\\:rf-text-zinc-950[data-state=active]{--tw-text-opacity:1;color:rgb(9 9 11/var(--tw-text-opacity,1))}.data-\\[state\\=checked\\]\\:rf-text-zinc-50[data-state=checked]{--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.data-\\[disabled\\]\\:rf-opacity-50[data-disabled]{opacity:.5}.data-\\[state\\=active\\]\\:rf-shadow[data-state=active]{--tw-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px -1px rgba(0,0,0,.1);--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.data-\\[state\\=open\\]\\:rf-animate-in[data-state=open]{animation-duration:.15s;animation-name:enter;--tw-enter-opacity:initial;--tw-enter-scale:initial;--tw-enter-rotate:initial;--tw-enter-translate-x:initial;--tw-enter-translate-y:initial}.data-\\[state\\=closed\\]\\:rf-animate-out[data-state=closed]{animation-duration:.15s;animation-name:exit;--tw-exit-opacity:initial;--tw-exit-scale:initial;--tw-exit-rotate:initial;--tw-exit-translate-x:initial;--tw-exit-translate-y:initial}.data-\\[state\\=closed\\]\\:rf-fade-out-0[data-state=closed]{--tw-exit-opacity:0}.data-\\[state\\=open\\]\\:rf-fade-in-0[data-state=open]{--tw-enter-opacity:0}.data-\\[state\\=closed\\]\\:rf-zoom-out-95[data-state=closed]{--tw-exit-scale:.95}.data-\\[state\\=open\\]\\:rf-zoom-in-95[data-state=open]{--tw-enter-scale:.95}.data-\\[side\\=bottom\\]\\:rf-slide-in-from-top-2[data-side=bottom]{--tw-enter-translate-y:-0.5rem}.data-\\[side\\=left\\]\\:rf-slide-in-from-right-2[data-side=left]{--tw-enter-translate-x:0.5rem}.data-\\[side\\=right\\]\\:rf-slide-in-from-left-2[data-side=right]{--tw-enter-translate-x:-0.5rem}.data-\\[side\\=top\\]\\:rf-slide-in-from-bottom-2[data-side=top]{--tw-enter-translate-y:0.5rem}.data-\\[state\\=closed\\]\\:rf-slide-out-to-left-1\\/2[data-state=closed]{--tw-exit-translate-x:-50%}.data-\\[state\\=closed\\]\\:rf-slide-out-to-top-\\[48\\%\\][data-state=closed]{--tw-exit-translate-y:-48%}.data-\\[state\\=open\\]\\:rf-slide-in-from-left-1\\/2[data-state=open]{--tw-enter-translate-x:-50%}.data-\\[state\\=open\\]\\:rf-slide-in-from-top-\\[48\\%\\][data-state=open]{--tw-enter-translate-y:-48%}.dark\\:rf-border-zinc-50:is(.rf-dark *){--tw-border-opacity:1;border-color:rgb(250 250 250/var(--tw-border-opacity,1))}.dark\\:rf-border-zinc-800:is(.rf-dark *){--tw-border-opacity:1;border-color:rgb(39 39 42/var(--tw-border-opacity,1))}.dark\\:rf-bg-red-900:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(127 29 29/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-50:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-800:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-950:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(9 9 11/var(--tw-bg-opacity,1))}.dark\\:rf-text-zinc-400:is(.rf-dark *){--tw-text-opacity:1;color:rgb(161 161 170/var(--tw-text-opacity,1))}.dark\\:rf-text-zinc-50:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:rf-text-zinc-900:is(.rf-dark *){--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.dark\\:rf-placeholder-zinc-400:is(.rf-dark *)::-moz-placeholder{--tw-placeholder-opacity:1;color:rgb(161 161 170/var(--tw-placeholder-opacity,1))}.dark\\:rf-placeholder-zinc-400:is(.rf-dark *)::placeholder{--tw-placeholder-opacity:1;color:rgb(161 161 170/var(--tw-placeholder-opacity,1))}.dark\\:rf-ring-offset-zinc-950:is(.rf-dark *){--tw-ring-offset-color:#09090b}.dark\\:hover\\:rf-bg-red-900\\/90:hover:is(.rf-dark *){background-color:rgba(127,29,29,.9)}.dark\\:hover\\:rf-bg-zinc-50\\/90:hover:is(.rf-dark *){background-color:hsla(0,0%,98%,.9)}.dark\\:hover\\:rf-bg-zinc-800:hover:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:hover\\:rf-bg-zinc-800\\/80:hover:is(.rf-dark *){background-color:rgba(39,39,42,.8)}.dark\\:hover\\:rf-text-zinc-50:hover:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:focus\\:rf-bg-zinc-800:focus:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:focus\\:rf-text-zinc-50:focus:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:focus-visible\\:rf-ring-zinc-300:focus-visible:is(.rf-dark *){--tw-ring-opacity:1;--tw-ring-color:rgb(212 212 216/var(--tw-ring-opacity,1))}.dark\\:data-\\[state\\=active\\]\\:rf-bg-zinc-950[data-state=active]:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(9 9 11/var(--tw-bg-opacity,1))}.dark\\:data-\\[state\\=checked\\]\\:rf-bg-zinc-50[data-state=checked]:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.dark\\:data-\\[state\\=open\\]\\:rf-bg-zinc-800[data-state=open]:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:data-\\[state\\=active\\]\\:rf-text-zinc-50[data-state=active]:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:data-\\[state\\=checked\\]\\:rf-text-zinc-900[data-state=checked]:is(.rf-dark *){--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}@media (min-width:640px){.sm\\:rf-mt-0{margin-top:0}.sm\\:rf-flex-row{flex-direction:row}.sm\\:rf-justify-end{justify-content:flex-end}.sm\\:rf-space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-left:calc(.5rem*(1 - var(--tw-space-x-reverse)));margin-right:calc(.5rem*var(--tw-space-x-reverse))}.sm\\:rf-rounded-lg{border-radius:var(--radius)}.sm\\:rf-text-left{text-align:left}}@media (min-width:768px){.md\\:rf-grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}}.\\[\\&\\>span\\]\\:rf-line-clamp-1>span{display:-webkit-box;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1}.\\[\\&\\>svg\\]\\:rf-size-4>svg{height:1rem;width:1rem}.\\[\\&\\>svg\\]\\:rf-shrink-0>svg{flex-shrink:0}.\\[\\&\\>svg\\]\\:rf-text-red-300>svg{--tw-text-opacity:1;color:rgb(252 165 165/var(--tw-text-opacity,1))}.\\[\\&\\>svg\\]\\:hover\\:rf-text-red-400:hover>svg{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.\\[\\&_svg\\]\\:rf-pointer-events-none svg{pointer-events:none}.\\[\\&_svg\\]\\:rf-size-4 svg{height:1rem;width:1rem}.\\[\\&_svg\\]\\:rf-shrink-0 svg{flex-shrink:0}',ozt=()=>{yt.useEffect(()=>{if(document.querySelector('style[data-styles="tscircuit-runframe"]'))return;const e=document.createElement("style");e.setAttribute("data-styles","tscircuit-runframe"),e.textContent=azt,document.head.appendChild(e)},[])},qFe=r=>`hsl(${Ix.indexOf(r)*137.5%360}, 70%, 50%)`,szt=({phaseTimings:r})=>{if(!r)return null;const e=Object.values(r).reduce((t,n)=>t+n,0);return dt.jsxs("div",{className:"rf-space-y-2 rf-w-full rf-px-4",children:[dt.jsx("div",{className:"rf-relative rf-h-8 rf-flex rf-rounded-sm",children:Ix.map(t=>{const n=r[t]||0,i=n/e*100;return dt.jsx("div",{className:"rf-group/bar rf-relative rf-overflow-visible",style:{width:`${i}%`,backgroundColor:qFe(t)},children:dt.jsxs("div",{className:"rf-opacity-0 group-hover/bar:rf-opacity-100 rf-transition-opacity rf-absolute rf-bottom-full rf-left-1/2 rf-transform -rf-translate-x-1/2 rf-mb-2 rf-px-2 rf-py-1 rf-text-xs rf-whitespace-nowrap rf-rounded rf-bg-gray-900 rf-text-white rf-pointer-events-none",children:[t,": ",n.toFixed(1),"ms"]})},t)})}),dt.jsxs("div",{className:"rf-text-xs rf-text-gray-500",children:["Total: ",e.toFixed(2),"ms"]})]})},lzt=({renderLog:r})=>{const[e,t]=yt.useState("chronological");if(!r)return dt.jsx("div",{className:"rf-p-4 rf-bg-gray-100 rf-rounded-md",children:"No render log, make sure this tab is open when you render (TODO add a rerender button here)"});const n=Object.entries((r==null?void 0:r.phaseTimings)??{});e==="chronological"?n.sort((a,o)=>Ix.indexOf(a[0])-Ix.indexOf(o[0])):n.sort((a,o)=>o[1]-a[1]);const i=n.reduce((a,[o,s])=>a+s,0);return dt.jsxs("div",{className:"rf-bg-white",children:[dt.jsxs("div",{className:"rf-flex rf-justify-between rf-items-center",children:[dt.jsx("div",{children:"Render Logs"}),dt.jsxs("div",{className:"rf-mb-4 rf-pr-2 rf-flex rf-text-xs rf-items-center",children:[dt.jsx("div",{className:"rf-mr-2",children:"Sort by:"}),dt.jsxs("select",{value:e,onChange:a=>t(a.target.value),className:"rf-px-2 rf-py-1 rf-border rf-rounded rf-text-xs",children:[dt.jsx("option",{value:"chronological",children:"Phase Order"}),dt.jsx("option",{value:"longest",children:"Duration"})]})]})]}),dt.jsx(szt,{phaseTimings:r.phaseTimings}),dt.jsxs("table",{className:"rf-w-full rf-text-xs",children:[dt.jsx("thead",{children:dt.jsxs("tr",{children:[dt.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase Order"}),dt.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase"}),dt.jsx("th",{className:"rf-text-left rf-p-2",children:"Duration (ms)"})]})}),dt.jsx("tbody",{children:n.map(([a,o])=>dt.jsxs("tr",{children:[dt.jsx("td",{className:"rf-p-2",children:Ix.indexOf(a)}),dt.jsx("td",{className:"rf-p-2",children:a}),dt.jsx("td",{className:"rf-p-2",children:dt.jsx("div",{className:"rf-w-8",children:dt.jsx("div",{className:"rf-h-2 rf-rounded-sm",style:{backgroundColor:qFe(a),width:`${o/i*100}%`}})})}),dt.jsx("td",{className:"rf-p-2",children:dt.jsxs("div",{className:"rf-flex w-full",children:[dt.jsxs("span",{className:"rf-flex-grow",children:[o,"ms"]}),dt.jsxs("span",{className:"rf-text-gray-500 rf-pr-2",children:[(o/i*100).toFixed(1),"%"]})]})})]},a))})]})]})},czt="0.0.550",Azt=["assembly","bom","circuit_json","errors","render_log"],uzt=({code:r,onRunClicked:e=void 0,errorMessage:t,errorStack:n,circuitJson:i,autoroutingGraphics:a,showRightHeaderContent:o=!0,showCodeTab:s=!1,codeTabContent:l,showJsonTab:c=!0,showRenderLogTab:A=!0,onActiveTabChange:u,renderLog:d,showImportAndFormatButtons:g=!0,className:m,headerClassName:C,leftHeaderContent:E,readOnly:_,isStreaming:x,autoroutingLog:Q,onReportAutoroutingLog:P,isRunningCode:z,hasCodeChangedSinceLastRun:O,onEditEvent:V,editEvents:j,defaultActiveTab:q,autoRotate3dViewerDisabled:J,showSchematicDebugGrid:ce=!1,showToggleFullScreen:oe=!0,defaultToFullScreen:de=!1})=>{var Fe;ozt();const Ie=yt.useMemo(()=>i?i.filter(tt=>tt&&"error_type"in tt||tt.type.includes("error")):null,[i]),[Be,pe]=yt.useState(q??"pcb"),[_e,ve]=yt.useState(de),Ne=yt.useCallback(tt=>{pe(tt),u==null||u(tt)},[u]),we=()=>{ve(!_e)};yt.useEffect(()=>{t&&Ne("errors")},[t]),yt.useEffect(()=>{(Be==="code"||Be==="errors")&&i&&!t&&Ne(q??"pcb")},[i]);const Ue=yt.useCallback(tt=>{window.TSCIRCUIT_3D_OBJECT_REF=tt===null?void 0:tt},[]);return dt.jsx("div",{className:Vv("flex flex-col relative rf-overflow-x-hidden",m),children:dt.jsx("div",{className:Vv("rf-md:sticky rf-md:top-2",_e&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-bg-white"),children:dt.jsxs(a7e,{value:Be,onValueChange:Ne,className:"rf-flex-grow rf-flex rf-flex-col",children:[dt.jsxs("div",{className:Vv("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",C),children:[E,E&&dt.jsx("div",{className:"rf-flex-grow"}),!E&&z&&dt.jsx(zNe,{className:"rf-w-4 rf-h-4 rf-animate-spin"}),!E&&dt.jsx("div",{className:"rf-flex-grow"}),d&&d.progress!==1&&!t&&dt.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[d.lastRenderEvent&&dt.jsx("div",{className:"rf-text-xs rf-text-gray-500",children:((Fe=d.lastRenderEvent)==null?void 0:Fe.phase)??""}),dt.jsx("div",{className:"rf-w-4 rf-h-4 rf-bg-blue-500 rf-opacity-50 rf-rounded-full rf-text-white",children:dt.jsx(zNe,{className:"rf-w-4 rf-h-4 rf-animate-spin"})}),dt.jsxs("div",{className:"rf-text-xs rf-font-bold rf-text-gray-700 rf-tabular-nums",children:[((d.progress??0)*100).toFixed(1),"%"]})]}),o&&dt.jsxs(Ele,{children:[s&&dt.jsx(t9,{value:"code",children:"Code"}),dt.jsxs(t9,{value:"pcb",className:"rf-whitespace-nowrap",children:[i&&dt.jsx("span",{className:Vv("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",O?"rf-bg-gray-500":"rf-bg-blue-500")}),"PCB"]}),dt.jsxs(t9,{value:"schematic",className:"rf-whitespace-nowrap",children:[i&&dt.jsx("span",{className:Vv("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",O?"rf-bg-gray-500":"rf-bg-blue-500")}),"Schematic"]}),dt.jsxs(t9,{value:"cad",children:[i&&dt.jsx("span",{className:Vv("inline-flex items-center justify-center w-2 h-2 mr-1 text-xs font-bold text-white rounded-full",O?"rf-bg-gray-500":"rf-bg-blue-500")}),"3D"]}),!["pcb","cad","schematic"].includes(Be)&&dt.jsx(t9,{value:Be,children:Cle(Be)}),dt.jsxs(X4e,{children:[dt.jsx($4e,{asChild:!0,children:dt.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[dt.jsx(OTt,{className:"rf-w-4 rf-h-4"}),(Ie&&Ie.length>0||t)&&dt.jsx("span",{className:"rf-inline-flex rf-absolute rf-top-[6px] rf-right-[4px] rf-items-center rf-justify-center rf-w-1 rf-h-1 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full"})]})}),dt.jsxs(Qie,{className:"rf-*:text-xs",children:[Azt.map(tt=>dt.jsxs(OG,{onSelect:()=>Ne(tt),children:[Be!==tt&&dt.jsx(ONe,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),Be===tt&&dt.jsx(GNe,{className:"rf-w-3 rf-h-3"}),dt.jsx("div",{className:"rf-pr-2",children:Cle(tt)}),tt==="errors"&&(Ie&&Ie.length>0||t)&&dt.jsx("span",{className:"rf-inline-flex rf-items-center rf-justify-center rf-w-3 rf-h-3 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full",children:t?1:Ie==null?void 0:Ie.length})]},tt)),dt.jsx(OG,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:dt.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/runframe@",czt.split(".").map((tt,rt)=>rt===2?parseInt(tt)+1:tt).join(".")]})})]})]})]}),oe&&dt.jsx(H2,{onClick:we,variant:"ghost",children:_e?dt.jsx(YTt,{size:16}):dt.jsx(zTt,{size:16})})]}),s&&dt.jsx(hb,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:dt.jsx("div",{className:"rf-h-full",children:l})}),dt.jsx(hb,{value:"pcb",children:dt.jsx("div",{className:Vv("rf-overflow-hidden",_e?"rf-h-[calc(100vh-52px)]":"rf-h-[620px]"),children:dt.jsx(jM,{fallbackRender:({error:tt})=>dt.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:dt.jsxs("div",{className:"rf-p-4",children:[dt.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading PCB viewer"}),dt.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(tt==null?void 0:tt.message)||"An unknown error occurred"})]})}),children:i?dt.jsx(izt,{focusOnHover:!1,circuitJson:i,debugGraphics:a,containerClassName:Vv("rf-h-full rf-w-full",_e?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:tt=>{V&&tt.forEach(rt=>V(rt))}}):dt.jsx(Tw,{onRunClicked:e})})})}),dt.jsx(hb,{value:"assembly",children:dt.jsx("div",{className:Vv("rf-overflow-auto",_e?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:dt.jsx(jM,{fallback:dt.jsx("div",{children:"Error loading Assembly"}),children:i?dt.jsx(vkt,{circuitJson:i,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):dt.jsx(Tw,{onRunClicked:e})})})}),dt.jsx(hb,{value:"schematic",children:dt.jsx("div",{className:Vv("rf-overflow-auto rf-bg-white",_e?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:dt.jsx(jM,{fallbackRender:({error:tt})=>dt.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:dt.jsxs("div",{className:"rf-p-4",children:[dt.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Schematic"}),dt.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(tt==null?void 0:tt.message)||"An unknown error occurred"})]})}),children:i?dt.jsx(pkt,{circuitJson:i,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:tt=>{V==null||V(tt)},debugGrid:ce}):dt.jsx(Tw,{onRunClicked:e})})})}),dt.jsx(hb,{value:"cad",children:dt.jsx("div",{className:Vv("rf-overflow-auto",_e?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:dt.jsx(jM,{FallbackComponent:STt,children:i?dt.jsx(xTt,{ref:Ue,circuitJson:i,autoRotateDisabled:J}):dt.jsx(Tw,{onRunClicked:e})})})}),dt.jsx(hb,{value:"bom",children:dt.jsx("div",{className:Vv("rf-overflow-auto",_e?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:dt.jsx(jM,{fallbackRender:({error:tt})=>dt.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:dt.jsxs("div",{className:"rf-p-4",children:[dt.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Bill of Materials"}),dt.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(tt==null?void 0:tt.message)||"An unknown error occurred"})]})}),children:i?dt.jsx(Bkt,{circuitJson:i}):dt.jsx(Tw,{onRunClicked:e})})})}),dt.jsx(hb,{value:"circuit_json",children:dt.jsx("div",{className:Vv("rf-overflow-auto",_e?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:dt.jsx(jM,{fallback:dt.jsx("div",{children:"Error loading JSON viewer"}),children:i?dt.jsx(Ekt,{elements:i}):dt.jsx(Tw,{onRunClicked:e})})})}),dt.jsx(hb,{value:"errors",children:dt.jsx("div",{className:Vv("rf-overflow-auto",_e?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:t||Ie&&Ie.length>0?dt.jsx(OUt,{code:r,circuitJsonErrors:Ie,errorMessage:t,errorStack:n,autoroutingLog:Q,onReportAutoroutingLog:P}):dt.jsx(Tw,{onRunClicked:e})})}),A&&dt.jsx(hb,{value:"render_log",children:dt.jsx(lzt,{renderLog:d})})]})})})};zse.createRoot(document.getElementById("root")).render(dt.jsx(uzt,{defaultActiveTab:"cad",autoRotate3dViewerDisabled:!0,showRightHeaderContent:!1,circuitJson:window.CIRCUIT_JSON||{},...window.CIRCUIT_JSON_PREVIEW_PROPS||{}}));const dzt=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}))});
|
|
13464
|
+
`,onClick:n=>{n.stopPropagation(),t()},children:[dt.jsx("input",{type:"checkbox",checked:e}),dt.jsx("span",{style:{color:"#eee"},children:r})]}),ezt=({children:r,elements:e})=>{const[t,n]=_1(j=>[j.is_mouse_over_container,j.setIsMouseOverContainer]),[i,a]=yt.useState(!1),[o,s]=yt.useState(!1),[l,c]=yt.useState(!1),[A,u]=_1(j=>[j.selected_layer,j.selectLayer]),[d,g,m,C,E,_]=_1(j=>[j.in_move_footprint_mode,j.in_draw_trace_mode,j.is_showing_rats_nest,j.is_showing_multiple_traces_length,j.is_showing_autorouting,j.is_showing_drc_errors]),x=_1(j=>j.setEditMode),Q=_1(j=>j.setIsShowingRatsNest),P=_1(j=>j.setIsShowingMultipleTracesLength),z=_1(j=>j.setIsShowingAutorouting),O=_1(j=>j.setIsShowingDrcErrors);eQ("1",()=>u("top")),eQ("2",()=>u("bottom")),eQ("3",()=>u("inner1")),eQ("4",()=>u("inner2")),eQ("5",()=>u("inner3")),eQ("6",()=>u("inner4")),eQ("7",()=>u("inner5")),eQ("8",()=>u("inner6"));const V=(e==null?void 0:e.filter(j=>j.type.includes("error")).length)??0;return dt.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>{n(!0)},onMouseLeave:j=>{n(!1),s(!1)},children:[r,dt.jsxs("div",{style:{position:"absolute",bottom:4,right:8,pointerEvents:"none",color:"white",fontSize:11,opacity:t?.5:0,transition:"opacity 1s",transitionDelay:"2s",fontFamily:"sans-serif"},children:["@tscircuit/pcb-viewer@",XOt.version]}),dt.jsxs("div",{style:{position:"absolute",opacity:t?1:0,top:16,left:16,transition:t?"opacity 100ms linear":"opacity 1s linear",zIndex:L_.toolbarOverlay,color:"red",display:"flex",fontSize:12,height:100,fontFamily:"sans-serif"},children:[dt.jsxs(m3,{onClick:()=>{s(!o)},onMouseLeave:()=>{o&&s(!1)},children:[dt.jsxs("div",{children:["layer:"," ",dt.jsx("span",{style:{marginLeft:2,fontWeight:500,color:p3[A]},children:A})]}),o&&dt.jsx("div",{style:{marginTop:4,minWidth:120},children:coe.map(j=>j.replace(/-/g,"")).map(j=>dt.jsx($Ot,{name:j,selected:j===A,onClick:()=>{u(j.replace(/-/,""))}},j))})]}),dt.jsxs(m3,{style:V>0?{color:"red"}:{},onClick:()=>c(!l),onMouseLeave:()=>c(!1),children:[dt.jsxs("div",{children:[V," errors"]}),l&&dt.jsx("div",{style:{display:"grid",gridTemplateColumns:"100px 300px"},children:e==null?void 0:e.filter(j=>j.type.includes("error")).map((j,q)=>dt.jsxs(yt.Fragment,{children:[dt.jsx("div",{children:j.error_type}),dt.jsx("div",{children:j.message})]},q))})]}),dt.jsx(m3,{style:{},onClick:()=>{x(g?"off":"draw_trace")},children:dt.jsxs("div",{children:[g?"✖ ":"","Edit Traces"]})}),dt.jsx(m3,{style:{},onClick:()=>{x(d?"off":"move_footprint")},children:dt.jsxs("div",{children:[d?"✖ ":"","Move Components"]})}),dt.jsx(m3,{style:{},onClick:()=>{Q(!m)},children:dt.jsxs("div",{children:[m?"✖ ":"","Rats Nest"]})}),dt.jsx(m3,{onClick:()=>{a(!i)},children:dt.jsxs("div",{children:[dt.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:["View"," ",dt.jsx("span",{style:{fontSize:"8px",transform:i?"rotate(180deg)":"rotate(0)",transition:"transform 0.1s ease",display:"inline-block"},children:"▼"})]}),i&&dt.jsxs("div",{style:{marginTop:4,minWidth:120},children:[dt.jsx(goe,{label:"Show All Trace Lengths",checked:C,onClick:()=>{P(!C)}}),dt.jsx(goe,{label:"Show Autorouting Animation",checked:E,onClick:()=>{z(!E)}}),dt.jsx(goe,{label:"Show DRC Errors",checked:_,onClick:()=>{O(!_)}})]})]})})]})]})},tzt=r=>{const{transform:e,elements:t}=r,[n,i]=yt.useMemo(()=>{const c=r.elements.flatMap(u=>dOt(u,r.elements)),A=pS(r.elements);return[c,A]},[r.elements]),[a,o]=yt.useState({drawingObjectIdsWithMouseOver:new Set,primitiveIdsInMousedOverNet:[]}),s=yt.useMemo(()=>AOt({primitivesWithoutInteractionMetadata:n,drawingObjectIdsWithMouseOver:a.drawingObjectIdsWithMouseOver,primitiveIdsInMousedOverNet:a.primitiveIdsInMousedOverNet}),[n,a]),l=yt.useCallback(c=>{var d,g;const A=[];for(const m of c)if(m._element){const C=i.getNetConnectedToId("pcb_port_id"in m._element?(d=m._element)==null?void 0:d.pcb_port_id:"pcb_trace_id"in m._element?(g=m._element)==null?void 0:g.pcb_trace_id:"");A.push(...i.getIdsConnectedToNet(C))}const u=new Set(c.map(m=>m._pcb_drawing_object_id));o({drawingObjectIdsWithMouseOver:u,primitiveIdsInMousedOverNet:A})},[i]);return dt.jsx(ZOt,{elements:t,transform:e,primitives:n,onMouseHoverOverPrimitives:l,children:dt.jsx(NOt,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:dt.jsx(FOt,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:dt.jsx(DOt,{transform:e,focusOnHover:r.focusOnHover,children:dt.jsx(ezt,{elements:t,children:dt.jsx(LOt,{transform:e,elements:t,children:dt.jsx(qOt,{transform:e,soup:t,children:dt.jsx(wOt,{transform:e,debugGraphics:r.debugGraphics,children:dt.jsx(MOt,{transform:e,elements:t,children:dt.jsx(QOt,{transform:e,primitives:s,width:r.width,height:r.height,grid:r.grid})})})})})})})})})})},nzt=OA(Kd(400,300),L1(40,-40)),rzt=({circuitJson:r,debugGraphics:e,height:t=600,initialState:n,allowEditing:i=!0,editEvents:a,onEditEventsChanged:o,focusOnHover:s=!1,clickToInteractEnabled:l=!1})=>{const[c,A]=yt.useState(!l),[u,d]=foe(),[g,m]=yt.useState(nzt),{ref:C,setTransform:E,cancelDrag:_}=cOt({transform:g,onSetTransform:m,enabled:c});let[x,Q]=yt.useState([]);x=a??x;const P=yt.useRef(!1),z=yt.useRef(null),O=`${(r==null?void 0:r.length)||0}_${(r==null?void 0:r.editCount)||0}`,V=()=>{const oe=(d==null?void 0:d.width)>0?d:{width:500,height:500},{center:de,width:Ie,height:Be}=q.some(ve=>ve.type.startsWith("pcb_"))?$7t(q.filter(ve=>ve.type.startsWith("pcb_"))):{center:{x:0,y:0},width:.001,height:.001},pe=Math.min((oe.width??0)/Ie,(oe.height??0)/Be,100)*.75,_e=OA(Kd((oe.width??0)/2,(oe.height??0)/2),L1(pe,-pe,0,0),Kd(-de.x,-de.y));E(_e)};yt.useEffect(()=>{d!=null&&d.width&&r&&r.length!==0&&(P.current||(V(),P.current=!0))},[r,d]);const j=yt.useMemo(()=>(r==null?void 0:r.filter(oe=>oe.type.startsWith("pcb_")||oe.type.startsWith("source_")))??[],[O]),q=yt.useMemo(()=>vGt({circuitJson:j,editEvents:x}),[j,x]),J=oe=>{Q([...x,oe]),o==null||o([...x,oe])},ce=oe=>{const de=x.map(Ie=>Ie.edit_event_id===oe.edit_event_id?{...Ie,...oe}:Ie);Q(de),o==null||o(de)};return dt.jsxs("div",{ref:C,style:{position:"relative"},children:[dt.jsx("div",{ref:u,children:dt.jsxs(tOt,{initialState:n,children:[dt.jsx(tzt,{transform:g,height:t,width:d.width,allowEditing:i,focusOnHover:s,cancelPanDrag:_,onCreateEditEvent:J,onModifyEditEvent:ce,grid:{spacing:1,view_window:{left:0,right:d.width||500,top:t,bottom:0}},elements:q,debugGraphics:e},d.width),dt.jsx(rOt,{})]})}),l&&!c&&dt.jsx("div",{onClick:()=>{A(!0),V()},onTouchStart:oe=>{const de=oe.touches[0];z.current={x:de.clientX,y:de.clientY}},onTouchEnd:oe=>{const de=oe.changedTouches[0],Ie=z.current;if(!Ie)return;const Be=Math.abs(de.clientX-Ie.x),pe=Math.abs(de.clientY-Ie.y);Be<10&&pe<10&&(oe.preventDefault(),A(!0),V()),z.current=null},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:L_.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center",touchAction:"pan-x pan-y pinch-zoom"},children:dt.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",pointerEvents:"none"},children:typeof window<"u"&&("ontouchstart"in window||navigator.maxTouchPoints>0)?"Touch to Interact":"Click to Interact"})})]})};const izt=({containerClassName:r,...e})=>{const t=yt.useRef(null),[n,i]=yt.useState(620);return yt.useLayoutEffect(()=>{const a=()=>{if(t.current){const s=t.current.clientHeight,l=window.innerHeight;i(Math.min(Math.max(s,620),l))}};a();const o=new ResizeObserver(a);return t.current&&o.observe(t.current),window.addEventListener("resize",a),()=>{o.disconnect(),window.removeEventListener("resize",a)}},[]),dt.jsx("div",{ref:t,className:r||"rf-w-full rf-h-full",children:dt.jsx(rzt,{...e,height:n})})},azt='*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }/*! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com*/*,:after,:before{border:0 solid #e5e7eb;box-sizing:border-box}:after,:before{--tw-content:""}:host,html{line-height:1.5;-webkit-text-size-adjust:100%;font-family:ui-sans-serif,system-ui,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-tap-highlight-color:transparent}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-size:1em;font-variation-settings:normal}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{color:inherit;font-family:inherit;font-feature-settings:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;letter-spacing:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{color:#9ca3af;opacity:1}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]:where(:not([hidden=until-found])){display:none}:root{--radius:0.5rem}.rf-pointer-events-none{pointer-events:none}.rf-invisible{visibility:hidden}.rf-fixed{position:fixed}.rf-absolute{position:absolute}.rf-relative{position:relative}.rf-inset-0{inset:0}.-rf-left-2{left:-.5rem}.-rf-right-10{right:-2.5rem}.-rf-right-2{right:-.5rem}.-rf-right-4{right:-1rem}.-rf-right-6{right:-1.5rem}.-rf-right-7{right:-1.75rem}.-rf-right-8{right:-2rem}.-rf-right-9{right:-2.25rem}.rf-bottom-full{bottom:100%}.rf-left-0{left:0}.rf-left-1{left:.25rem}.rf-left-1\\/2{left:50%}.rf-left-2{left:.5rem}.rf-left-\\[50\\%\\]{left:50%}.rf-right-0{right:0}.rf-right-4{right:1rem}.rf-right-\\[4px\\]{right:4px}.rf-top-0{top:0}.rf-top-1{top:.25rem}.rf-top-2{top:.5rem}.rf-top-2\\.5{top:.625rem}.rf-top-\\[50\\%\\]{top:50%}.rf-top-\\[6px\\]{top:6px}.rf-z-50{z-index:50}.rf-z-\\[100\\]{z-index:100}.-rf-mx-1,.rf--mx-1{margin-left:-.25rem;margin-right:-.25rem}.rf-mx-1{margin-left:.25rem;margin-right:.25rem}.rf-mx-2{margin-left:.5rem;margin-right:.5rem}.rf-mx-auto{margin-left:auto;margin-right:auto}.rf-my-1{margin-bottom:.25rem;margin-top:.25rem}.rf-my-12{margin-bottom:3rem;margin-top:3rem}.rf-my-4{margin-bottom:1rem;margin-top:1rem}.rf-my-auto{margin-bottom:auto;margin-top:auto}.rf-mb-1{margin-bottom:.25rem}.rf-mb-12{margin-bottom:3rem}.rf-mb-2{margin-bottom:.5rem}.rf-mb-3{margin-bottom:.75rem}.rf-mb-4{margin-bottom:1rem}.rf-mb-6{margin-bottom:1.5rem}.rf-mb-8{margin-bottom:2rem}.rf-ml-1{margin-left:.25rem}.rf-ml-2{margin-left:.5rem}.rf-ml-auto{margin-left:auto}.rf-mr-1{margin-right:.25rem}.rf-mr-2{margin-right:.5rem}.rf-mt-0{margin-top:0}.rf-mt-0\\.5{margin-top:.125rem}.rf-mt-1{margin-top:.25rem}.rf-mt-2{margin-top:.5rem}.rf-mt-3{margin-top:.75rem}.rf-mt-4{margin-top:1rem}.rf-mt-5{margin-top:1.25rem}.rf-mt-auto{margin-top:auto}.rf-block{display:block}.rf-inline{display:inline}.rf-flex{display:flex}.rf-inline-flex{display:inline-flex}.rf-grid{display:grid}.rf-hidden{display:none}.rf-aspect-square{aspect-ratio:1/1}.rf-aspect-video{aspect-ratio:16/9}.rf-size-14{height:3.5rem;width:3.5rem}.rf-size-4{height:1rem;width:1rem}.\\!rf-h-2{height:.5rem!important}.\\!rf-h-2\\.5{height:.625rem!important}.\\!rf-h-3{height:.75rem!important}.\\!rf-h-full{height:100%!important}.rf-h-1{height:.25rem}.rf-h-10{height:2.5rem}.rf-h-12{height:3rem}.rf-h-2{height:.5rem}.rf-h-2\\.5{height:.625rem}.rf-h-3{height:.75rem}.rf-h-3\\.5{height:.875rem}.rf-h-4{height:1rem}.rf-h-5{height:1.25rem}.rf-h-6{height:1.5rem}.rf-h-60{height:15rem}.rf-h-64{height:16rem}.rf-h-8{height:2rem}.rf-h-9{height:2.25rem}.rf-h-\\[620px\\]{height:620px}.rf-h-\\[calc\\(100vh-52px\\)\\]{height:calc(100vh - 52px)}.rf-h-\\[calc\\(100vh-96px\\)\\]{height:calc(100vh - 96px)}.rf-h-\\[var\\(--radix-select-trigger-height\\)\\]{height:var(--radix-select-trigger-height)}.rf-h-fit{height:-moz-fit-content;height:fit-content}.rf-h-full{height:100%}.rf-h-px{height:1px}.\\!rf-max-h-\\[40vh\\]{max-height:40vh!important}.\\!rf-max-h-\\[70\\%\\]{max-height:70%!important}.rf-max-h-32{max-height:8rem}.rf-max-h-96{max-height:24rem}.rf-max-h-\\[500px\\]{max-height:500px}.rf-max-h-\\[90vh\\]{max-height:90vh}.rf-min-h-0{min-height:0}.rf-min-h-\\[200px\\]{min-height:200px}.rf-min-h-\\[620px\\]{min-height:620px}.rf-min-h-\\[calc\\(100vh-240px\\)\\]{min-height:calc(100vh - 240px)}.\\!rf-w-2{width:.5rem!important}.\\!rf-w-2\\.5{width:.625rem!important}.rf-w-1{width:.25rem}.rf-w-1\\/2{width:50%}.rf-w-11{width:2.75rem}.rf-w-11\\/12{width:91.666667%}.rf-w-12{width:3rem}.rf-w-16{width:4rem}.rf-w-2{width:.5rem}.rf-w-2\\.5{width:.625rem}.rf-w-3{width:.75rem}.rf-w-3\\.5{width:.875rem}.rf-w-32{width:8rem}.rf-w-4{width:1rem}.rf-w-5{width:1.25rem}.rf-w-6{width:1.5rem}.rf-w-64{width:16rem}.rf-w-72{width:18rem}.rf-w-8{width:2rem}.rf-w-9{width:2.25rem}.rf-w-96{width:24rem}.rf-w-\\[95\\%\\]{width:95%}.rf-w-fit{width:-moz-fit-content;width:fit-content}.rf-w-full{width:100%}.rf-min-w-10{min-width:2.5rem}.rf-min-w-16{min-width:4rem}.rf-min-w-\\[148px\\]{min-width:148px}.rf-min-w-\\[8rem\\]{min-width:8rem}.rf-min-w-\\[var\\(--radix-select-trigger-width\\)\\]{min-width:var(--radix-select-trigger-width)}.\\!rf-max-w-\\[60vw\\]{max-width:60vw!important}.\\!rf-max-w-\\[660px\\]{max-width:660px!important}.rf-max-w-2xl{max-width:42rem}.rf-max-w-3xl{max-width:48rem}.rf-max-w-5xl{max-width:64rem}.rf-max-w-full{max-width:100%}.rf-max-w-lg{max-width:32rem}.rf-max-w-md{max-width:28rem}.rf-max-w-xl{max-width:36rem}.rf-flex-1{flex:1 1 0%}.rf-flex-shrink-0,.rf-shrink-0{flex-shrink:0}.rf-flex-grow{flex-grow:1}.rf-table-auto{table-layout:auto}.-rf-translate-x-1{--tw-translate-x:-0.25rem}.-rf-translate-x-1,.-rf-translate-x-1\\/2{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.-rf-translate-x-1\\/2{--tw-translate-x:-50%}.-rf-translate-y-1{--tw-translate-y:-0.25rem}.-rf-translate-y-1,.rf--translate-x-1{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rf--translate-x-1{--tw-translate-x:-0.25rem}.rf-translate-x-\\[-50\\%\\]{--tw-translate-x:-50%}.rf-translate-x-\\[-50\\%\\],.rf-translate-y-\\[-50\\%\\]{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rf-translate-y-\\[-50\\%\\]{--tw-translate-y:-50%}.rf-transform{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes rf-pulse{50%{opacity:.5}}.rf-animate-pulse{animation:rf-pulse 2s cubic-bezier(.4,0,.6,1) infinite}@keyframes rf-spin{to{transform:rotate(1turn)}}.rf-animate-spin{animation:rf-spin 1s linear infinite}.rf-cursor-default{cursor:default}.rf-cursor-not-allowed{cursor:not-allowed}.rf-cursor-pointer{cursor:pointer}.rf-select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.rf-grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.rf-grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.rf-flex-row{flex-direction:row}.rf-flex-col{flex-direction:column}.rf-flex-col-reverse{flex-direction:column-reverse}.rf-flex-wrap{flex-wrap:wrap}.rf-place-items-center{place-items:center}.rf-items-start{align-items:flex-start}.rf-items-end{align-items:flex-end}.rf-items-center{align-items:center}.rf-justify-end{justify-content:flex-end}.rf-justify-center{justify-content:center}.rf-justify-between{justify-content:space-between}.rf-gap-0{gap:0}.rf-gap-1{gap:.25rem}.rf-gap-2{gap:.5rem}.rf-gap-3{gap:.75rem}.rf-gap-4{gap:1rem}.rf-gap-5{gap:1.25rem}.rf-gap-6{gap:1.5rem}.rf-gap-8{gap:2rem}.rf-space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-left:calc(.5rem*(1 - var(--tw-space-x-reverse)));margin-right:calc(.5rem*var(--tw-space-x-reverse))}.rf-space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(.5rem*var(--tw-space-y-reverse));margin-top:calc(.5rem*(1 - var(--tw-space-y-reverse)))}.rf-space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(1rem*var(--tw-space-y-reverse));margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)))}.rf-space-y-6>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(1.5rem*var(--tw-space-y-reverse));margin-top:calc(1.5rem*(1 - var(--tw-space-y-reverse)))}.rf-divide-y>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-bottom-width:calc(1px*var(--tw-divide-y-reverse));border-top-width:calc(1px*(1 - var(--tw-divide-y-reverse)))}.rf-overflow-auto{overflow:auto}.rf-overflow-hidden{overflow:hidden}.rf-overflow-visible{overflow:visible}.rf-overflow-x-auto{overflow-x:auto}.\\!rf-overflow-y-auto{overflow-y:auto!important}.rf-overflow-y-auto{overflow-y:auto}.\\!rf-overflow-x-hidden{overflow-x:hidden!important}.rf-overflow-x-hidden{overflow-x:hidden}.rf-overflow-x-clip{overflow-x:clip}.rf-truncate{overflow:hidden;text-overflow:ellipsis}.rf-truncate,.rf-whitespace-nowrap{white-space:nowrap}.rf-whitespace-pre-wrap{white-space:pre-wrap}.rf-break-words{overflow-wrap:break-word}.rf-rounded{border-radius:.25rem}.rf-rounded-2xl{border-radius:1rem}.rf-rounded-full{border-radius:9999px}.rf-rounded-lg{border-radius:var(--radius)}.rf-rounded-md{border-radius:calc(var(--radius) - 2px)}.rf-rounded-sm{border-radius:calc(var(--radius) - 4px)}.rf-rounded-xl{border-radius:.75rem}.rf-border{border-width:1px}.rf-border-b{border-bottom-width:1px}.rf-border-t{border-top-width:1px}.rf-border-blue-200{--tw-border-opacity:1;border-color:rgb(191 219 254/var(--tw-border-opacity,1))}.rf-border-blue-500{--tw-border-opacity:1;border-color:rgb(59 130 246/var(--tw-border-opacity,1))}.rf-border-blue-600{--tw-border-opacity:1;border-color:rgb(37 99 235/var(--tw-border-opacity,1))}.rf-border-gray-200{--tw-border-opacity:1;border-color:rgb(229 231 235/var(--tw-border-opacity,1))}.rf-border-gray-300{--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity,1))}.rf-border-green-200{--tw-border-opacity:1;border-color:rgb(187 247 208/var(--tw-border-opacity,1))}.rf-border-input{border-color:hsl(var(--input))}.rf-border-neutral-200{--tw-border-opacity:1;border-color:rgb(229 229 229/var(--tw-border-opacity,1))}.rf-border-primary{border-color:hsl(var(--primary))}.rf-border-red-200{--tw-border-opacity:1;border-color:rgb(254 202 202/var(--tw-border-opacity,1))}.rf-border-red-500{--tw-border-opacity:1;border-color:rgb(239 68 68/var(--tw-border-opacity,1))}.rf-border-zinc-200{--tw-border-opacity:1;border-color:rgb(228 228 231/var(--tw-border-opacity,1))}.rf-border-zinc-900{--tw-border-opacity:1;border-color:rgb(24 24 27/var(--tw-border-opacity,1))}.rf-bg-background{background-color:hsl(var(--background))}.rf-bg-black{--tw-bg-opacity:1;background-color:rgb(0 0 0/var(--tw-bg-opacity,1))}.rf-bg-black\\/80{background-color:rgba(0,0,0,.8)}.rf-bg-blue-100{--tw-bg-opacity:1;background-color:rgb(219 234 254/var(--tw-bg-opacity,1))}.rf-bg-blue-50{--tw-bg-opacity:1;background-color:rgb(239 246 255/var(--tw-bg-opacity,1))}.rf-bg-blue-500{--tw-bg-opacity:1;background-color:rgb(59 130 246/var(--tw-bg-opacity,1))}.rf-bg-blue-600{--tw-bg-opacity:1;background-color:rgb(37 99 235/var(--tw-bg-opacity,1))}.rf-bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.rf-bg-gray-200{--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity,1))}.rf-bg-gray-300{--tw-bg-opacity:1;background-color:rgb(209 213 219/var(--tw-bg-opacity,1))}.rf-bg-gray-400{--tw-bg-opacity:1;background-color:rgb(156 163 175/var(--tw-bg-opacity,1))}.rf-bg-gray-50{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity,1))}.rf-bg-gray-500{--tw-bg-opacity:1;background-color:rgb(107 114 128/var(--tw-bg-opacity,1))}.rf-bg-gray-700{--tw-bg-opacity:1;background-color:rgb(55 65 81/var(--tw-bg-opacity,1))}.rf-bg-gray-800{--tw-bg-opacity:1;background-color:rgb(31 41 55/var(--tw-bg-opacity,1))}.rf-bg-gray-900{--tw-bg-opacity:1;background-color:rgb(17 24 39/var(--tw-bg-opacity,1))}.rf-bg-green-100{--tw-bg-opacity:1;background-color:rgb(220 252 231/var(--tw-bg-opacity,1))}.rf-bg-green-50{--tw-bg-opacity:1;background-color:rgb(240 253 244/var(--tw-bg-opacity,1))}.rf-bg-muted{background-color:hsl(var(--muted))}.rf-bg-neutral-100{--tw-bg-opacity:1;background-color:rgb(245 245 245/var(--tw-bg-opacity,1))}.rf-bg-neutral-50{--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.rf-bg-neutral-800{--tw-bg-opacity:1;background-color:rgb(38 38 38/var(--tw-bg-opacity,1))}.rf-bg-neutral-900{--tw-bg-opacity:1;background-color:rgb(23 23 23/var(--tw-bg-opacity,1))}.rf-bg-orange-400{--tw-bg-opacity:1;background-color:rgb(251 146 60/var(--tw-bg-opacity,1))}.rf-bg-popover{background-color:hsl(var(--popover))}.rf-bg-red-100{--tw-bg-opacity:1;background-color:rgb(254 226 226/var(--tw-bg-opacity,1))}.rf-bg-red-50{--tw-bg-opacity:1;background-color:rgb(254 242 242/var(--tw-bg-opacity,1))}.rf-bg-red-500{--tw-bg-opacity:1;background-color:rgb(239 68 68/var(--tw-bg-opacity,1))}.rf-bg-red-900{--tw-bg-opacity:1;background-color:rgb(127 29 29/var(--tw-bg-opacity,1))}.rf-bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.rf-bg-yellow-100{--tw-bg-opacity:1;background-color:rgb(254 249 195/var(--tw-bg-opacity,1))}.rf-bg-zinc-100{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.rf-bg-zinc-200{--tw-bg-opacity:1;background-color:rgb(228 228 231/var(--tw-bg-opacity,1))}.rf-bg-zinc-50{--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.rf-bg-zinc-800{--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.rf-bg-zinc-900{--tw-bg-opacity:1;background-color:rgb(24 24 27/var(--tw-bg-opacity,1))}.rf-bg-opacity-50{--tw-bg-opacity:0.5}.rf-fill-current{fill:currentColor}.rf-object-contain{-o-object-fit:contain;object-fit:contain}.\\!rf-p-0{padding:0!important}.rf-p-0{padding:0}.rf-p-1{padding:.25rem}.rf-p-2{padding:.5rem}.rf-p-3{padding:.75rem}.rf-p-4{padding:1rem}.rf-p-5{padding:1.25rem}.rf-p-6{padding:1.5rem}.rf-p-8{padding:2rem}.rf-px-1{padding-left:.25rem;padding-right:.25rem}.rf-px-2{padding-left:.5rem;padding-right:.5rem}.rf-px-3{padding-left:.75rem;padding-right:.75rem}.rf-px-4{padding-left:1rem;padding-right:1rem}.rf-px-6{padding-left:1.5rem;padding-right:1.5rem}.rf-px-8{padding-left:2rem;padding-right:2rem}.rf-py-0{padding-bottom:0;padding-top:0}.rf-py-0\\.5{padding-bottom:.125rem;padding-top:.125rem}.rf-py-1{padding-bottom:.25rem;padding-top:.25rem}.rf-py-1\\.5{padding-bottom:.375rem;padding-top:.375rem}.rf-py-10{padding-bottom:2.5rem;padding-top:2.5rem}.rf-py-12{padding-bottom:3rem;padding-top:3rem}.rf-py-2{padding-bottom:.5rem;padding-top:.5rem}.rf-py-3{padding-bottom:.75rem;padding-top:.75rem}.rf-py-4{padding-bottom:1rem;padding-top:1rem}.rf-py-8{padding-bottom:2rem;padding-top:2rem}.rf-pb-0{padding-bottom:0}.rf-pb-2{padding-bottom:.5rem}.rf-pb-3{padding-bottom:.75rem}.rf-pb-4{padding-bottom:1rem}.rf-pl-2{padding-left:.5rem}.rf-pl-4{padding-left:1rem}.rf-pl-8{padding-left:2rem}.rf-pr-2{padding-right:.5rem}.rf-pt-2{padding-top:.5rem}.rf-pt-4{padding-top:1rem}.rf-text-left{text-align:left}.rf-text-center{text-align:center}.rf-text-right{text-align:right}.rf-font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.rf-text-2xl{font-size:1.5rem;line-height:2rem}.rf-text-3xl{font-size:1.875rem;line-height:2.25rem}.rf-text-\\[8px\\]{font-size:8px}.rf-text-base{font-size:1rem;line-height:1.5rem}.rf-text-lg{font-size:1.125rem;line-height:1.75rem}.rf-text-sm{font-size:.875rem;line-height:1.25rem}.rf-text-xl{font-size:1.25rem;line-height:1.75rem}.rf-text-xs{font-size:.75rem;line-height:1rem}.rf-font-bold{font-weight:700}.rf-font-medium{font-weight:500}.rf-font-semibold{font-weight:600}.rf-capitalize{text-transform:capitalize}.rf-tabular-nums{--tw-numeric-spacing:tabular-nums;font-variant-numeric:var(--tw-ordinal) var(--tw-slashed-zero) var(--tw-numeric-figure) var(--tw-numeric-spacing) var(--tw-numeric-fraction)}.rf-leading-5{line-height:1.25rem}.rf-leading-none{line-height:1}.rf-leading-tight{line-height:1.25}.rf-tracking-widest{letter-spacing:.1em}.rf-text-black{--tw-text-opacity:1;color:rgb(0 0 0/var(--tw-text-opacity,1))}.rf-text-blue-500{--tw-text-opacity:1;color:rgb(59 130 246/var(--tw-text-opacity,1))}.rf-text-blue-600{--tw-text-opacity:1;color:rgb(37 99 235/var(--tw-text-opacity,1))}.rf-text-blue-700{--tw-text-opacity:1;color:rgb(29 78 216/var(--tw-text-opacity,1))}.rf-text-blue-800{--tw-text-opacity:1;color:rgb(30 64 175/var(--tw-text-opacity,1))}.rf-text-blue-900{--tw-text-opacity:1;color:rgb(30 58 138/var(--tw-text-opacity,1))}.rf-text-current{color:currentColor}.rf-text-gray-400{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity,1))}.rf-text-gray-500{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity,1))}.rf-text-gray-600{--tw-text-opacity:1;color:rgb(75 85 99/var(--tw-text-opacity,1))}.rf-text-gray-700{--tw-text-opacity:1;color:rgb(55 65 81/var(--tw-text-opacity,1))}.rf-text-gray-800{--tw-text-opacity:1;color:rgb(31 41 55/var(--tw-text-opacity,1))}.rf-text-gray-900{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity,1))}.rf-text-green-500{--tw-text-opacity:1;color:rgb(34 197 94/var(--tw-text-opacity,1))}.rf-text-green-600{--tw-text-opacity:1;color:rgb(22 163 74/var(--tw-text-opacity,1))}.rf-text-green-700{--tw-text-opacity:1;color:rgb(21 128 61/var(--tw-text-opacity,1))}.rf-text-green-800{--tw-text-opacity:1;color:rgb(22 101 52/var(--tw-text-opacity,1))}.rf-text-green-900{--tw-text-opacity:1;color:rgb(20 83 45/var(--tw-text-opacity,1))}.rf-text-muted-foreground{color:hsl(var(--muted-foreground))}.rf-text-neutral-50{--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.rf-text-neutral-500{--tw-text-opacity:1;color:rgb(115 115 115/var(--tw-text-opacity,1))}.rf-text-neutral-900{--tw-text-opacity:1;color:rgb(23 23 23/var(--tw-text-opacity,1))}.rf-text-neutral-950{--tw-text-opacity:1;color:rgb(10 10 10/var(--tw-text-opacity,1))}.rf-text-popover-foreground{color:hsl(var(--popover-foreground))}.rf-text-red-200{--tw-text-opacity:1;color:rgb(254 202 202/var(--tw-text-opacity,1))}.rf-text-red-300{--tw-text-opacity:1;color:rgb(252 165 165/var(--tw-text-opacity,1))}.rf-text-red-400{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.rf-text-red-500{--tw-text-opacity:1;color:rgb(239 68 68/var(--tw-text-opacity,1))}.rf-text-red-600{--tw-text-opacity:1;color:rgb(220 38 38/var(--tw-text-opacity,1))}.rf-text-red-700{--tw-text-opacity:1;color:rgb(185 28 28/var(--tw-text-opacity,1))}.rf-text-red-800{--tw-text-opacity:1;color:rgb(153 27 27/var(--tw-text-opacity,1))}.rf-text-red-900{--tw-text-opacity:1;color:rgb(127 29 29/var(--tw-text-opacity,1))}.rf-text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.rf-text-yellow-400{--tw-text-opacity:1;color:rgb(250 204 21/var(--tw-text-opacity,1))}.rf-text-yellow-500{--tw-text-opacity:1;color:rgb(234 179 8/var(--tw-text-opacity,1))}.rf-text-yellow-900{--tw-text-opacity:1;color:rgb(113 63 18/var(--tw-text-opacity,1))}.rf-text-zinc-200{--tw-text-opacity:1;color:rgb(228 228 231/var(--tw-text-opacity,1))}.rf-text-zinc-300{--tw-text-opacity:1;color:rgb(212 212 216/var(--tw-text-opacity,1))}.rf-text-zinc-400{--tw-text-opacity:1;color:rgb(161 161 170/var(--tw-text-opacity,1))}.rf-text-zinc-50{--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.rf-text-zinc-500{--tw-text-opacity:1;color:rgb(113 113 122/var(--tw-text-opacity,1))}.rf-text-zinc-900{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.rf-text-zinc-950{--tw-text-opacity:1;color:rgb(9 9 11/var(--tw-text-opacity,1))}.rf-underline{text-decoration-line:underline}.rf-line-through{text-decoration-line:line-through}.rf-underline-offset-4{text-underline-offset:4px}.rf-opacity-0{opacity:0}.rf-opacity-25{opacity:.25}.rf-opacity-30{opacity:.3}.rf-opacity-50{opacity:.5}.rf-opacity-60{opacity:.6}.rf-opacity-75{opacity:.75}.rf-shadow{--tw-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px -1px rgba(0,0,0,.1);--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color)}.rf-shadow,.rf-shadow-lg{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.rf-shadow-lg{--tw-shadow:0 10px 15px -3px rgba(0,0,0,.1),0 4px 6px -4px rgba(0,0,0,.1);--tw-shadow-colored:0 10px 15px -3px var(--tw-shadow-color),0 4px 6px -4px var(--tw-shadow-color)}.rf-shadow-md{--tw-shadow:0 4px 6px -1px rgba(0,0,0,.1),0 2px 4px -2px rgba(0,0,0,.1);--tw-shadow-colored:0 4px 6px -1px var(--tw-shadow-color),0 2px 4px -2px var(--tw-shadow-color)}.rf-shadow-md,.rf-shadow-sm{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.rf-shadow-sm{--tw-shadow:0 1px 2px 0 rgba(0,0,0,.05);--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color)}.rf-outline-none{outline:2px solid transparent;outline-offset:2px}.rf-ring-2{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.rf-ring-blue-500{--tw-ring-opacity:1;--tw-ring-color:rgb(59 130 246/var(--tw-ring-opacity,1))}.rf-ring-primary{--tw-ring-color:hsl(var(--primary))}.rf-ring-offset-background{--tw-ring-offset-color:hsl(var(--background))}.rf-ring-offset-white{--tw-ring-offset-color:#fff}.rf-transition{transition-duration:.15s;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-transition-all{transition-duration:.15s;transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-transition-colors{transition-duration:.15s;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-transition-opacity{transition-duration:.15s;transition-property:opacity;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-duration-200{transition-duration:.2s}.rf-ease-in-out{transition-timing-function:cubic-bezier(.4,0,.2,1)}@keyframes enter{0%{opacity:var(--tw-enter-opacity,1);transform:translate3d(var(--tw-enter-translate-x,0),var(--tw-enter-translate-y,0),0) scale3d(var(--tw-enter-scale,1),var(--tw-enter-scale,1),var(--tw-enter-scale,1)) rotate(var(--tw-enter-rotate,0))}}@keyframes exit{to{opacity:var(--tw-exit-opacity,1);transform:translate3d(var(--tw-exit-translate-x,0),var(--tw-exit-translate-y,0),0) scale3d(var(--tw-exit-scale,1),var(--tw-exit-scale,1),var(--tw-exit-scale,1)) rotate(var(--tw-exit-rotate,0))}}.rf-slide-in-from-left-1{--tw-enter-translate-x:-0.25rem}.rf-slide-out-to-left-1{--tw-exit-translate-x:-0.25rem}.rf-duration-200{animation-duration:.2s}.rf-ease-in-out{animation-timing-function:cubic-bezier(.4,0,.2,1)}.file\\:rf-border-0::file-selector-button{border-width:0}.file\\:rf-bg-transparent::file-selector-button{background-color:transparent}.file\\:rf-text-sm::file-selector-button{font-size:.875rem;line-height:1.25rem}.file\\:rf-font-medium::file-selector-button{font-weight:500}.placeholder\\:rf-text-zinc-500::-moz-placeholder{--tw-text-opacity:1;color:rgb(113 113 122/var(--tw-text-opacity,1))}.placeholder\\:rf-text-zinc-500::placeholder{--tw-text-opacity:1;color:rgb(113 113 122/var(--tw-text-opacity,1))}.hover\\:rf-border-blue-300:hover{--tw-border-opacity:1;border-color:rgb(147 197 253/var(--tw-border-opacity,1))}.hover\\:\\!rf-bg-transparent:hover{background-color:transparent!important}.hover\\:rf-bg-blue-700:hover{--tw-bg-opacity:1;background-color:rgb(29 78 216/var(--tw-bg-opacity,1))}.hover\\:rf-bg-red-500\\/90:hover{background-color:rgba(239,68,68,.9)}.hover\\:rf-bg-zinc-100:hover{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.hover\\:rf-bg-zinc-100\\/80:hover{background-color:hsla(240,5%,96%,.8)}.hover\\:rf-bg-zinc-900\\/90:hover{background-color:rgba(24,24,27,.9)}.hover\\:rf-text-red-400:hover{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.hover\\:rf-text-zinc-900:hover{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.hover\\:rf-underline:hover{text-decoration-line:underline}.focus\\:rf-bg-gray-100:focus{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.focus\\:rf-bg-zinc-100:focus{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.focus\\:rf-text-gray-900:focus{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity,1))}.focus\\:rf-text-zinc-900:focus{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.focus\\:rf-outline-none:focus{outline:2px solid transparent;outline-offset:2px}.focus\\:rf-ring-2:focus{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus\\:rf-ring-ring:focus{--tw-ring-color:hsl(var(--ring))}.focus\\:rf-ring-offset-2:focus{--tw-ring-offset-width:2px}.focus-visible\\:rf-outline-none:focus-visible{outline:2px solid transparent;outline-offset:2px}.focus-visible\\:rf-ring-1:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:rf-ring-2:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:rf-ring-zinc-950:focus-visible{--tw-ring-opacity:1;--tw-ring-color:rgb(9 9 11/var(--tw-ring-opacity,1))}.focus-visible\\:rf-ring-offset-2:focus-visible{--tw-ring-offset-width:2px}.disabled\\:rf-pointer-events-none:disabled{pointer-events:none}.disabled\\:rf-cursor-not-allowed:disabled{cursor:not-allowed}.disabled\\:rf-opacity-50:disabled{opacity:.5}.rf-group\\/bar:hover .group-hover\\/bar\\:rf-opacity-100{opacity:1}.data-\\[disabled\\]\\:rf-pointer-events-none[data-disabled]{pointer-events:none}.data-\\[side\\=bottom\\]\\:rf-translate-y-1[data-side=bottom]{--tw-translate-y:0.25rem}.data-\\[side\\=bottom\\]\\:rf-translate-y-1[data-side=bottom],.data-\\[side\\=left\\]\\:-rf-translate-x-1[data-side=left]{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.data-\\[side\\=left\\]\\:-rf-translate-x-1[data-side=left]{--tw-translate-x:-0.25rem}.data-\\[side\\=right\\]\\:rf-translate-x-1[data-side=right]{--tw-translate-x:0.25rem}.data-\\[side\\=right\\]\\:rf-translate-x-1[data-side=right],.data-\\[side\\=top\\]\\:-rf-translate-y-1[data-side=top]{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.data-\\[side\\=top\\]\\:-rf-translate-y-1[data-side=top]{--tw-translate-y:-0.25rem}.data-\\[state\\=active\\]\\:rf-bg-white[data-state=active]{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.data-\\[state\\=checked\\]\\:rf-bg-zinc-900[data-state=checked]{--tw-bg-opacity:1;background-color:rgb(24 24 27/var(--tw-bg-opacity,1))}.data-\\[state\\=open\\]\\:rf-bg-zinc-100[data-state=open]{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.data-\\[state\\=active\\]\\:rf-text-zinc-950[data-state=active]{--tw-text-opacity:1;color:rgb(9 9 11/var(--tw-text-opacity,1))}.data-\\[state\\=checked\\]\\:rf-text-zinc-50[data-state=checked]{--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.data-\\[disabled\\]\\:rf-opacity-50[data-disabled]{opacity:.5}.data-\\[state\\=active\\]\\:rf-shadow[data-state=active]{--tw-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px -1px rgba(0,0,0,.1);--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.data-\\[state\\=open\\]\\:rf-animate-in[data-state=open]{animation-duration:.15s;animation-name:enter;--tw-enter-opacity:initial;--tw-enter-scale:initial;--tw-enter-rotate:initial;--tw-enter-translate-x:initial;--tw-enter-translate-y:initial}.data-\\[state\\=closed\\]\\:rf-animate-out[data-state=closed]{animation-duration:.15s;animation-name:exit;--tw-exit-opacity:initial;--tw-exit-scale:initial;--tw-exit-rotate:initial;--tw-exit-translate-x:initial;--tw-exit-translate-y:initial}.data-\\[state\\=closed\\]\\:rf-fade-out-0[data-state=closed]{--tw-exit-opacity:0}.data-\\[state\\=open\\]\\:rf-fade-in-0[data-state=open]{--tw-enter-opacity:0}.data-\\[state\\=closed\\]\\:rf-zoom-out-95[data-state=closed]{--tw-exit-scale:.95}.data-\\[state\\=open\\]\\:rf-zoom-in-95[data-state=open]{--tw-enter-scale:.95}.data-\\[side\\=bottom\\]\\:rf-slide-in-from-top-2[data-side=bottom]{--tw-enter-translate-y:-0.5rem}.data-\\[side\\=left\\]\\:rf-slide-in-from-right-2[data-side=left]{--tw-enter-translate-x:0.5rem}.data-\\[side\\=right\\]\\:rf-slide-in-from-left-2[data-side=right]{--tw-enter-translate-x:-0.5rem}.data-\\[side\\=top\\]\\:rf-slide-in-from-bottom-2[data-side=top]{--tw-enter-translate-y:0.5rem}.data-\\[state\\=closed\\]\\:rf-slide-out-to-left-1\\/2[data-state=closed]{--tw-exit-translate-x:-50%}.data-\\[state\\=closed\\]\\:rf-slide-out-to-top-\\[48\\%\\][data-state=closed]{--tw-exit-translate-y:-48%}.data-\\[state\\=open\\]\\:rf-slide-in-from-left-1\\/2[data-state=open]{--tw-enter-translate-x:-50%}.data-\\[state\\=open\\]\\:rf-slide-in-from-top-\\[48\\%\\][data-state=open]{--tw-enter-translate-y:-48%}.dark\\:rf-border-zinc-50:is(.rf-dark *){--tw-border-opacity:1;border-color:rgb(250 250 250/var(--tw-border-opacity,1))}.dark\\:rf-border-zinc-800:is(.rf-dark *){--tw-border-opacity:1;border-color:rgb(39 39 42/var(--tw-border-opacity,1))}.dark\\:rf-bg-red-900:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(127 29 29/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-50:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-800:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-950:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(9 9 11/var(--tw-bg-opacity,1))}.dark\\:rf-text-zinc-400:is(.rf-dark *){--tw-text-opacity:1;color:rgb(161 161 170/var(--tw-text-opacity,1))}.dark\\:rf-text-zinc-50:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:rf-text-zinc-900:is(.rf-dark *){--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.dark\\:rf-placeholder-zinc-400:is(.rf-dark *)::-moz-placeholder{--tw-placeholder-opacity:1;color:rgb(161 161 170/var(--tw-placeholder-opacity,1))}.dark\\:rf-placeholder-zinc-400:is(.rf-dark *)::placeholder{--tw-placeholder-opacity:1;color:rgb(161 161 170/var(--tw-placeholder-opacity,1))}.dark\\:rf-ring-offset-zinc-950:is(.rf-dark *){--tw-ring-offset-color:#09090b}.dark\\:hover\\:rf-bg-red-900\\/90:hover:is(.rf-dark *){background-color:rgba(127,29,29,.9)}.dark\\:hover\\:rf-bg-zinc-50\\/90:hover:is(.rf-dark *){background-color:hsla(0,0%,98%,.9)}.dark\\:hover\\:rf-bg-zinc-800:hover:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:hover\\:rf-bg-zinc-800\\/80:hover:is(.rf-dark *){background-color:rgba(39,39,42,.8)}.dark\\:hover\\:rf-text-zinc-50:hover:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:focus\\:rf-bg-zinc-800:focus:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:focus\\:rf-text-zinc-50:focus:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:focus-visible\\:rf-ring-zinc-300:focus-visible:is(.rf-dark *){--tw-ring-opacity:1;--tw-ring-color:rgb(212 212 216/var(--tw-ring-opacity,1))}.dark\\:data-\\[state\\=active\\]\\:rf-bg-zinc-950[data-state=active]:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(9 9 11/var(--tw-bg-opacity,1))}.dark\\:data-\\[state\\=checked\\]\\:rf-bg-zinc-50[data-state=checked]:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.dark\\:data-\\[state\\=open\\]\\:rf-bg-zinc-800[data-state=open]:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:data-\\[state\\=active\\]\\:rf-text-zinc-50[data-state=active]:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:data-\\[state\\=checked\\]\\:rf-text-zinc-900[data-state=checked]:is(.rf-dark *){--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}@media (min-width:640px){.sm\\:rf-mt-0{margin-top:0}.sm\\:rf-flex-row{flex-direction:row}.sm\\:rf-justify-end{justify-content:flex-end}.sm\\:rf-space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-left:calc(.5rem*(1 - var(--tw-space-x-reverse)));margin-right:calc(.5rem*var(--tw-space-x-reverse))}.sm\\:rf-rounded-lg{border-radius:var(--radius)}.sm\\:rf-text-left{text-align:left}}@media (min-width:768px){.md\\:rf-grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}}.\\[\\&\\>span\\]\\:rf-line-clamp-1>span{display:-webkit-box;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1}.\\[\\&\\>svg\\]\\:rf-size-4>svg{height:1rem;width:1rem}.\\[\\&\\>svg\\]\\:rf-shrink-0>svg{flex-shrink:0}.\\[\\&\\>svg\\]\\:rf-text-red-300>svg{--tw-text-opacity:1;color:rgb(252 165 165/var(--tw-text-opacity,1))}.\\[\\&\\>svg\\]\\:hover\\:rf-text-red-400:hover>svg{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.\\[\\&_svg\\]\\:rf-pointer-events-none svg{pointer-events:none}.\\[\\&_svg\\]\\:rf-size-4 svg{height:1rem;width:1rem}.\\[\\&_svg\\]\\:rf-shrink-0 svg{flex-shrink:0}',ozt=()=>{yt.useEffect(()=>{if(document.querySelector('style[data-styles="tscircuit-runframe"]'))return;const e=document.createElement("style");e.setAttribute("data-styles","tscircuit-runframe"),e.textContent=azt,document.head.appendChild(e)},[])},qFe=r=>`hsl(${Ix.indexOf(r)*137.5%360}, 70%, 50%)`,szt=({phaseTimings:r})=>{if(!r)return null;const e=Object.values(r).reduce((t,n)=>t+n,0);return dt.jsxs("div",{className:"rf-space-y-2 rf-w-full rf-px-4",children:[dt.jsx("div",{className:"rf-relative rf-h-8 rf-flex rf-rounded-sm",children:Ix.map(t=>{const n=r[t]||0,i=n/e*100;return dt.jsx("div",{className:"rf-group/bar rf-relative rf-overflow-visible",style:{width:`${i}%`,backgroundColor:qFe(t)},children:dt.jsxs("div",{className:"rf-opacity-0 group-hover/bar:rf-opacity-100 rf-transition-opacity rf-absolute rf-bottom-full rf-left-1/2 rf-transform -rf-translate-x-1/2 rf-mb-2 rf-px-2 rf-py-1 rf-text-xs rf-whitespace-nowrap rf-rounded rf-bg-gray-900 rf-text-white rf-pointer-events-none",children:[t,": ",n.toFixed(1),"ms"]})},t)})}),dt.jsxs("div",{className:"rf-text-xs rf-text-gray-500",children:["Total: ",e.toFixed(2),"ms"]})]})},lzt=({renderLog:r})=>{const[e,t]=yt.useState("chronological");if(!r)return dt.jsx("div",{className:"rf-p-4 rf-bg-gray-100 rf-rounded-md",children:"No render log, make sure this tab is open when you render (TODO add a rerender button here)"});const n=Object.entries((r==null?void 0:r.phaseTimings)??{});e==="chronological"?n.sort((a,o)=>Ix.indexOf(a[0])-Ix.indexOf(o[0])):n.sort((a,o)=>o[1]-a[1]);const i=n.reduce((a,[o,s])=>a+s,0);return dt.jsxs("div",{className:"rf-bg-white",children:[dt.jsxs("div",{className:"rf-flex rf-justify-between rf-items-center",children:[dt.jsx("div",{children:"Render Logs"}),dt.jsxs("div",{className:"rf-mb-4 rf-pr-2 rf-flex rf-text-xs rf-items-center",children:[dt.jsx("div",{className:"rf-mr-2",children:"Sort by:"}),dt.jsxs("select",{value:e,onChange:a=>t(a.target.value),className:"rf-px-2 rf-py-1 rf-border rf-rounded rf-text-xs",children:[dt.jsx("option",{value:"chronological",children:"Phase Order"}),dt.jsx("option",{value:"longest",children:"Duration"})]})]})]}),dt.jsx(szt,{phaseTimings:r.phaseTimings}),dt.jsxs("table",{className:"rf-w-full rf-text-xs",children:[dt.jsx("thead",{children:dt.jsxs("tr",{children:[dt.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase Order"}),dt.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase"}),dt.jsx("th",{className:"rf-text-left rf-p-2",children:"Duration (ms)"})]})}),dt.jsx("tbody",{children:n.map(([a,o])=>dt.jsxs("tr",{children:[dt.jsx("td",{className:"rf-p-2",children:Ix.indexOf(a)}),dt.jsx("td",{className:"rf-p-2",children:a}),dt.jsx("td",{className:"rf-p-2",children:dt.jsx("div",{className:"rf-w-8",children:dt.jsx("div",{className:"rf-h-2 rf-rounded-sm",style:{backgroundColor:qFe(a),width:`${o/i*100}%`}})})}),dt.jsx("td",{className:"rf-p-2",children:dt.jsxs("div",{className:"rf-flex w-full",children:[dt.jsxs("span",{className:"rf-flex-grow",children:[o,"ms"]}),dt.jsxs("span",{className:"rf-text-gray-500 rf-pr-2",children:[(o/i*100).toFixed(1),"%"]})]})})]},a))})]})]})},czt="0.0.552",Azt=["assembly","bom","circuit_json","errors","render_log"],uzt=({code:r,onRunClicked:e=void 0,errorMessage:t,errorStack:n,circuitJson:i,autoroutingGraphics:a,showRightHeaderContent:o=!0,showCodeTab:s=!1,codeTabContent:l,showJsonTab:c=!0,showRenderLogTab:A=!0,onActiveTabChange:u,renderLog:d,showImportAndFormatButtons:g=!0,className:m,headerClassName:C,leftHeaderContent:E,readOnly:_,isStreaming:x,autoroutingLog:Q,onReportAutoroutingLog:P,isRunningCode:z,hasCodeChangedSinceLastRun:O,onEditEvent:V,editEvents:j,defaultActiveTab:q,autoRotate3dViewerDisabled:J,showSchematicDebugGrid:ce=!1,showToggleFullScreen:oe=!0,defaultToFullScreen:de=!1})=>{var Fe;ozt();const Ie=yt.useMemo(()=>i?i.filter(tt=>tt&&"error_type"in tt||tt.type.includes("error")):null,[i]),[Be,pe]=yt.useState(q??"pcb"),[_e,ve]=yt.useState(de),Ne=yt.useCallback(tt=>{pe(tt),u==null||u(tt)},[u]),we=()=>{ve(!_e)};yt.useEffect(()=>{t&&Ne("errors")},[t]),yt.useEffect(()=>{(Be==="code"||Be==="errors")&&i&&!t&&Ne(q??"pcb")},[i]);const Ue=yt.useCallback(tt=>{window.TSCIRCUIT_3D_OBJECT_REF=tt===null?void 0:tt},[]);return dt.jsx("div",{className:Vv("flex flex-col relative rf-overflow-x-hidden",m),children:dt.jsx("div",{className:Vv("rf-md:sticky rf-md:top-2",_e&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-bg-white"),children:dt.jsxs(a7e,{value:Be,onValueChange:Ne,className:"rf-flex-grow rf-flex rf-flex-col",children:[dt.jsxs("div",{className:Vv("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",C),children:[E,E&&dt.jsx("div",{className:"rf-flex-grow"}),!E&&z&&dt.jsx(zNe,{className:"rf-w-4 rf-h-4 rf-animate-spin"}),!E&&dt.jsx("div",{className:"rf-flex-grow"}),d&&d.progress!==1&&!t&&dt.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[d.lastRenderEvent&&dt.jsx("div",{className:"rf-text-xs rf-text-gray-500",children:((Fe=d.lastRenderEvent)==null?void 0:Fe.phase)??""}),dt.jsx("div",{className:"rf-w-4 rf-h-4 rf-bg-blue-500 rf-opacity-50 rf-rounded-full rf-text-white",children:dt.jsx(zNe,{className:"rf-w-4 rf-h-4 rf-animate-spin"})}),dt.jsxs("div",{className:"rf-text-xs rf-font-bold rf-text-gray-700 rf-tabular-nums",children:[((d.progress??0)*100).toFixed(1),"%"]})]}),o&&dt.jsxs(Ele,{children:[s&&dt.jsx(t9,{value:"code",children:"Code"}),dt.jsxs(t9,{value:"pcb",className:"rf-whitespace-nowrap",children:[i&&dt.jsx("span",{className:Vv("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",O?"rf-bg-gray-500":"rf-bg-blue-500")}),"PCB"]}),dt.jsxs(t9,{value:"schematic",className:"rf-whitespace-nowrap",children:[i&&dt.jsx("span",{className:Vv("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",O?"rf-bg-gray-500":"rf-bg-blue-500")}),"Schematic"]}),dt.jsxs(t9,{value:"cad",children:[i&&dt.jsx("span",{className:Vv("inline-flex items-center justify-center w-2 h-2 mr-1 text-xs font-bold text-white rounded-full",O?"rf-bg-gray-500":"rf-bg-blue-500")}),"3D"]}),!["pcb","cad","schematic"].includes(Be)&&dt.jsx(t9,{value:Be,children:Cle(Be)}),dt.jsxs(X4e,{children:[dt.jsx($4e,{asChild:!0,children:dt.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[dt.jsx(OTt,{className:"rf-w-4 rf-h-4"}),(Ie&&Ie.length>0||t)&&dt.jsx("span",{className:"rf-inline-flex rf-absolute rf-top-[6px] rf-right-[4px] rf-items-center rf-justify-center rf-w-1 rf-h-1 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full"})]})}),dt.jsxs(Qie,{className:"rf-*:text-xs",children:[Azt.map(tt=>dt.jsxs(OG,{onSelect:()=>Ne(tt),children:[Be!==tt&&dt.jsx(ONe,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),Be===tt&&dt.jsx(GNe,{className:"rf-w-3 rf-h-3"}),dt.jsx("div",{className:"rf-pr-2",children:Cle(tt)}),tt==="errors"&&(Ie&&Ie.length>0||t)&&dt.jsx("span",{className:"rf-inline-flex rf-items-center rf-justify-center rf-w-3 rf-h-3 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full",children:t?1:Ie==null?void 0:Ie.length})]},tt)),dt.jsx(OG,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:dt.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/runframe@",czt.split(".").map((tt,rt)=>rt===2?parseInt(tt)+1:tt).join(".")]})})]})]})]}),oe&&dt.jsx(H2,{onClick:we,variant:"ghost",children:_e?dt.jsx(YTt,{size:16}):dt.jsx(zTt,{size:16})})]}),s&&dt.jsx(hb,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:dt.jsx("div",{className:"rf-h-full",children:l})}),dt.jsx(hb,{value:"pcb",children:dt.jsx("div",{className:Vv("rf-overflow-hidden",_e?"rf-h-[calc(100vh-52px)]":"rf-h-[620px]"),children:dt.jsx(jM,{fallbackRender:({error:tt})=>dt.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:dt.jsxs("div",{className:"rf-p-4",children:[dt.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading PCB viewer"}),dt.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(tt==null?void 0:tt.message)||"An unknown error occurred"})]})}),children:i?dt.jsx(izt,{focusOnHover:!1,circuitJson:i,debugGraphics:a,containerClassName:Vv("rf-h-full rf-w-full",_e?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:tt=>{V&&tt.forEach(rt=>V(rt))}}):dt.jsx(Tw,{onRunClicked:e})})})}),dt.jsx(hb,{value:"assembly",children:dt.jsx("div",{className:Vv("rf-overflow-auto",_e?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:dt.jsx(jM,{fallback:dt.jsx("div",{children:"Error loading Assembly"}),children:i?dt.jsx(vkt,{circuitJson:i,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):dt.jsx(Tw,{onRunClicked:e})})})}),dt.jsx(hb,{value:"schematic",children:dt.jsx("div",{className:Vv("rf-overflow-auto rf-bg-white",_e?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:dt.jsx(jM,{fallbackRender:({error:tt})=>dt.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:dt.jsxs("div",{className:"rf-p-4",children:[dt.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Schematic"}),dt.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(tt==null?void 0:tt.message)||"An unknown error occurred"})]})}),children:i?dt.jsx(pkt,{circuitJson:i,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:tt=>{V==null||V(tt)},debugGrid:ce}):dt.jsx(Tw,{onRunClicked:e})})})}),dt.jsx(hb,{value:"cad",children:dt.jsx("div",{className:Vv("rf-overflow-auto",_e?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:dt.jsx(jM,{FallbackComponent:STt,children:i?dt.jsx(xTt,{ref:Ue,circuitJson:i,autoRotateDisabled:J}):dt.jsx(Tw,{onRunClicked:e})})})}),dt.jsx(hb,{value:"bom",children:dt.jsx("div",{className:Vv("rf-overflow-auto",_e?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:dt.jsx(jM,{fallbackRender:({error:tt})=>dt.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:dt.jsxs("div",{className:"rf-p-4",children:[dt.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Bill of Materials"}),dt.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(tt==null?void 0:tt.message)||"An unknown error occurred"})]})}),children:i?dt.jsx(Bkt,{circuitJson:i}):dt.jsx(Tw,{onRunClicked:e})})})}),dt.jsx(hb,{value:"circuit_json",children:dt.jsx("div",{className:Vv("rf-overflow-auto",_e?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:dt.jsx(jM,{fallback:dt.jsx("div",{children:"Error loading JSON viewer"}),children:i?dt.jsx(Ekt,{elements:i}):dt.jsx(Tw,{onRunClicked:e})})})}),dt.jsx(hb,{value:"errors",children:dt.jsx("div",{className:Vv("rf-overflow-auto",_e?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:t||Ie&&Ie.length>0?dt.jsx(OUt,{code:r,circuitJsonErrors:Ie,errorMessage:t,errorStack:n,autoroutingLog:Q,onReportAutoroutingLog:P}):dt.jsx(Tw,{onRunClicked:e})})}),A&&dt.jsx(hb,{value:"render_log",children:dt.jsx(lzt,{renderLog:d})})]})})})};zse.createRoot(document.getElementById("root")).render(dt.jsx(uzt,{defaultActiveTab:"cad",autoRotate3dViewerDisabled:!0,showRightHeaderContent:!1,circuitJson:window.CIRCUIT_JSON||{},...window.CIRCUIT_JSON_PREVIEW_PROPS||{}}));const dzt=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}))});
|