@tscircuit/runframe 0.0.539 → 0.0.540
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/standalone.min.js
CHANGED
|
@@ -850,7 +850,7 @@ ${o.width}x${o.height}
|
|
|
850
850
|
`)};function Qdt(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 Mdt(r,e){var i;const t={boxes:e.boxes.map(o=>({...o})),nets:((i=e.nets)==null?void 0:i.map(o=>({...o})))||[],connections:e.connections.map(o=>({...o,connectedPorts:[...o.connectedPorts]}))},n=r.chips.filter(o=>o.isPassive);for(const o of n){const a=t.boxes.find(s=>s.boxId===o.chipId);if(a)try{if(Qdt(o)==="vertical"){if(a.leftPinCount>0||a.rightPinCount>0){const l=a.leftPinCount+a.rightPinCount;a.leftPinCount=0,a.rightPinCount=0,a.bottomPinCount=Math.ceil(l/2),a.topPinCount=Math.floor(l/2)}}else if(a.bottomPinCount>0||a.topPinCount>0){const l=a.bottomPinCount+a.topPinCount;a.bottomPinCount=0,a.topPinCount=0,a.leftPinCount=Math.ceil(l/2),a.rightPinCount=Math.floor(l/2)}}catch{continue}}return t}var Ddt=r=>{const e=d=>{const f=new Set;for(const p of r.connections)for(const C of p.connectedPorts)"boxId"in C&&C.boxId===d&&f.add(C.pinNumber);return Array.from(f).sort((p,C)=>p-C)},t=new Map;for(const d of r.connections)for(const f of d.connectedPorts)if("boxId"in f){const p=`${f.boxId}|${f.pinNumber}`;t.has(p)||t.set(p,[]),t.get(p).push(d)}let n="",i=-1;for(const d of r.boxes){const f=(d.leftPinCount??0)+(d.rightPinCount??0)+(d.topPinCount??0)+(d.bottomPinCount??0);(f>i||f===i&&d.boxId<n)&&(n=d.boxId,i=f)}const o={[n]:0},a=new Set([n]),s=new Set,l=new Set;let c=1;const u=[],A=d=>{const f=e(d).slice().reverse();for(const p of f)u.push({boxId:d,pinNumber:p})};for(A(n);u.length;){const{boxId:d,pinNumber:f}=u.pop(),p=`${d}|${f}`;if(l.has(p))continue;l.add(p);const C=[],v=new Set,_=t.get(p)??[];for(const T of _)for(const F of T.connectedPorts)"boxId"in F?F.boxId!==d&&C.push([F.boxId,F.pinNumber]):"netId"in F&&v.add(F.netId);const x=Array.from(v).sort();for(const T of x)s.has(T)||(o[T]=c++,s.add(T));const b={};for(const[T,F]of C)b[T]=b[T]===void 0?F:Math.min(b[T],F);for(const[T]of Object.entries(b).sort((F,U)=>{if(F[1]!==U[1])return F[1]-U[1];const H=O=>{const ne=new Set;for(const te of r.connections){const ie=te.connectedPorts.find(pe=>"boxId"in pe&&pe.boxId===O);if(ie&&"pinNumber"in ie)for(const pe of te.connectedPorts)pe!==ie&&"boxId"in pe&&"pinNumber"in pe&&ne.add(pe.pinNumber)}return Array.from(ne).sort((te,ie)=>te-ie).join(",")},G=H(F[0]),j=H(U[0]);return G.localeCompare(j)}))a.has(T)||(o[T]=c++,a.add(T),A(T))}return o},nw=r=>{const e={boxIdToBoxIndex:{},netIdToNetIndex:{},boxIndexToBoxId:{},netIndexToNetId:{}},t=Ddt(r),n=r.boxes.map(l=>l.boxId).sort((l,c)=>{const u=t[l]??Number.MAX_SAFE_INTEGER,A=t[c]??Number.MAX_SAFE_INTEGER;return u!==A?u-A: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(u=>u.boxId===l);return{boxIndex:e.boxIdToBoxIndex[l],leftPinCount:c.leftPinCount,rightPinCount:c.rightPinCount,topPinCount:c.topPinCount,bottomPinCount:c.bottomPinCount}}),o=r.nets.map(l=>l.netId).sort((l,c)=>t[l]-t[c]);o.forEach((l,c)=>{e.netIdToNetIndex[l]=c,e.netIndexToNetId[c]=l});const a=o.map(l=>({netIndex:e.netIdToNetIndex[l]})),s=r.connections.map(l=>({connectedPorts:l.connectedPorts.map(u=>"boxId"in u?{boxIndex:e.boxIdToBoxIndex[u.boxId],pinNumber:u.pinNumber}:{netIndex:e.netIdToNetIndex[u.netId]}).sort((u,A)=>{const d="boxIndex"in u,f="boxIndex"in A;return d&&!f?-1:!d&&f?1:d&&f?u.boxIndex!==A.boxIndex?u.boxIndex-A.boxIndex:u.pinNumber-A.pinNumber:u.netIndex-A.netIndex})}));return s.sort((l,c)=>{const u=A=>A.connectedPorts.map(d=>"boxIndex"in d?`b${d.boxIndex}p${d.pinNumber}`:`n${d.netIndex}`).join(",");return u(l).localeCompare(u(c))}),{normalizedNetlist:{boxes:i,nets:a,connections:s},transform:e}};function $K(r){return r.length}var ej=["left","bottom","right","top"],VB=(r,e)=>{let t=0,n=0;for(let i=0;i<r&&t<4;){const o=ej[t],a=e[`${o}PinCount`];if(a===void 0||a===0){t++;continue}if(n>=a){t++,n=0;continue}if(i+1===r){const s={side:o,indexOnSide:n};return o==="left"?s.indexFromTop=n:o==="right"&&(s.indexFromTop=e.rightPinCount-n-1),o==="bottom"?s.indexFromLeft=n:o==="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}`)},wM=.5,Rdt=.3,Ndt=class{constructor(){Le(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,o=new Set,a=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),a.set(l,s);let c=0;const u=200,A=Math.min(this.getHeuristic(t,n)*2,10/wM);for(;i.size>0&&c<u;){c++;let d=Array.from(i)[0],f=a.get(d);for(const C of i){const v=a.get(C);(v.fCost<f.fCost||v.fCost===f.fCost&&v.hCost<f.hCost)&&(d=C,f=v)}if(i.delete(d),o.add(d),f.point.x===n.x&&f.point.y===n.y)return this.reconstructPath(f);if(f.gCost>A)continue;const p=this.getNeighbors(f.point);for(const C of p){const v=this.pointToKey(C);if(o.has(v)||this.isObstacle(C))continue;const _=this.getDirection(f.point,C);let x=1;f.direction&&f.direction!==_&&(x+=Rdt);const b=f.gCost+x;if(i.has(v)){const T=a.get(v);b<T.gCost&&(T.gCost=b,T.fCost=T.gCost+T.hCost,T.parent=f,T.direction=_)}else{const T={point:C,gCost:b,hCost:this.getHeuristic(C,n),fCost:0,parent:f,direction:_};T.fCost=T.gCost+T.hCost,i.add(v),a.set(v,T)}}}return c>=u&&console.warn(`Pathfinding exceeded max iterations (${u})`),[]}worldToGrid(r){return{x:Math.round(r.x/wM),y:Math.round(r.y/wM)}}gridToWorld(r){return{x:r.x*wM,y:r.y*wM}}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*wM>10)return[];const e=[];let t=r;for(;t;)e.unshift(this.gridToWorld(t.point)),t=t.parent;return e}};function Tdt(r,e,t,n){for(let o=1;o<10;o++){const a=o/10,s=r.x+(e.x-r.x)*a,l=r.y+(e.y-r.y)*a;if(rw(s,l,t,n))return!1}return!0}function rw(r,e,t,n){for(const i of t.chips){if(i.chipId===n)continue;const o=i.getWidth(),a=i.getHeight(),s=.1;if(r>=i.x-o/2-s&&r<=i.x+o/2+s&&e>=i.y-a/2-s&&e<=i.y+a/2+s)return!0}return!1}function Pdt(r,e,t,n,i,o){let a=-1/0,s=1/0;for(const f of i.chips){if(f.chipId===o)continue;const p=f.getWidth(),C=f.getHeight(),v=.1,_=f.x-p/2-v,x=f.x+p/2+v,b=f.y+C/2+v,T=f.y-C/2-v,F=Math.min(r,t),U=Math.max(r,t);x>F&&_<U&&(a=Math.max(a,b),s=Math.min(s,T))}if(a!==-1/0){const f=a+.5;if(!rw(r,f,i,o)&&!rw(t,f,i,o))return{x:r,y:f};const p=s-.5;if(!rw(r,p,i,o)&&!rw(t,p,i,o))return{x:r,y:p}}const l={x:t,y:e};if(!rw(l.x,l.y,i,o))return l;const c={x:r,y:n};if(!rw(c.x,c.y,i,o))return c;const u=t-r,A=n-e;let d=1;for(;d<4;){const f=r+(u>0?d:-d),p=e+(A>0?d:-d);if(!rw(f,p,i,o))return{x:f,y:p};d+=.5}return{x:r,y:e}}var tj=class{constructor(r,e){Le(this,"x",0);Le(this,"y",0);Le(this,"pathId",null);Le(this,"lastConnected",null);Le(this,"lastCreatedLine",null);Le(this,"lastDx",0);Le(this,"lastDy",0);Le(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(Tdt(t,n,this.circuit,this.chip.chipId))return this.lineAt(r,e);const i=new Ndt;for(const s of this.circuit.chips){if(s.chipId===this.chip.chipId)continue;const l=s.getWidth(),c=s.getHeight(),u=.1,A={minX:s.x-l/2-u,maxX:s.x+l/2+u,minY:s.y-c/2-u,maxY:s.y+c/2+u};i.addObstacle(A)}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],u=c.x-this.x,A=c.y-this.y;this.line(u,A)}return this}}const a=Pdt(this.x,this.y,r,e,this.circuit,this.chip.chipId);return this.lineAt(a.x,a.y).lineAt(r,e)}getPinDirection(){const r=this.side;return r==="left"||r==="right"?"horizontal":"vertical"}get side(){const{side:r}=VB(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,o=this.x+Math.sign(this.lastDx)*(Math.abs(this.lastDx)>0?n:0),a=this.y+Math.sign(this.lastDy)*(Math.abs(this.lastDy)>0?i:0);t.at(o,a);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}},nj=class{constructor(r,e,t=!1){Le(this,"x",0);Le(this,"y",0);Le(this,"leftPins",[]);Le(this,"rightPins",[]);Le(this,"topPins",[]);Le(this,"bottomPins",[]);Le(this,"leftPinCount",0);Le(this,"rightPinCount",0);Le(this,"topPinCount",0);Le(this,"bottomPinCount",0);Le(this,"pinMap",{});Le(this,"marks",{});Le(this,"pinMargins",{});Le(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 tj(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}=VB(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,o;const a=this.circuit.defaultPinSpacing,s=.2;if(e==="left"||e==="right"){i=this.x+(e==="left"?0:this.getWidth());let l=t*a;for(let c=0;c<=t;c++){const u=this.getPinNumberFromSideIndex(e,c),A=this.pinMargins[u];A!=null&&A.marginTop&&A.marginTop>s&&(l+=A.marginTop-s)}o=this.y+this.getHeight()-l-this.circuit.defaultPinSpacing*2}else{let l=n*a;for(let c=0;c<=n;c++){const u=this.getPinNumberFromSideIndex(e,c),A=this.pinMargins[u];A!=null&&A.marginLeft&&A.marginLeft>s&&(l+=A.marginLeft-s)}i=this.x+l,o=this.y+(e==="bottom"?0:this.getHeight())}return{x:i,y:o}}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}},kdt=r=>{const e=[];for(const o of r.chips)e.push(o.x),e.push(o.x+4);for(const o of r.lines)e.push(o.start.x,o.end.x);for(const o of r.netLabels)e.push(o.x);for(const o of r.connectionPoints)e.push(o.x);if(e.length===0)return r;const t=Math.min(...e),n=Math.max(...e),i=t+n;for(const o of r.chips){o.x=i-(o.x+4);const a=o.leftPins,s=o.rightPins;o.leftPins=s.slice(),o.rightPins=a.slice().reverse();const l=o.leftPinCount;o.leftPinCount=o.rightPinCount,o.rightPinCount=l}for(const o of r.lines)o.start.x=i-o.start.x,o.end.x=i-o.end.x;for(const o of r.netLabels)o.x=i-o.x;for(const o of r.connectionPoints)o.x=i-o.x;return r},dm={left:1,right:2,up:4,down:8};function Udt(r){switch(r){case 0:return" ";case dm.left:case dm.right:return"─";case dm.up:case dm.down:return"│";case dm.left|dm.right:return"─";case dm.up|dm.down:return"│";case dm.left|dm.up:return"┘";case dm.left|dm.down:return"┐";case dm.right|dm.up:return"└";case dm.right|dm.down:return"┌";case dm.left|dm.right|dm.up:return"┴";case dm.left|dm.right|dm.down:return"┬";case dm.left|dm.up|dm.down:return"┤";case dm.right|dm.up|dm.down:return"├";case dm.left|dm.right|dm.up|dm.down:return"┼";default:return" "}}var Fdt=class{constructor(e={}){Le(this,"traces",new Map);Le(this,"overlay",new Map);Le(this,"gridScaleX");Le(this,"gridScaleY");Le(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),o=Math.round(t*this.gridScaleY),a=`${i},${o}`,s=dm[n];this.traces.set(a,(this.traces.get(a)??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),o=Math.round(t*this.gridScaleY);this.overlay.set(`${i},${o}`,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[a,s]of this.coords())a<e&&(e=a),a>t&&(t=a),s<n&&(n=s),s>i&&(i=s);const o=[];if(this.showAxisLabels){const a=Math.max(1,Math.round(5*this.gridScaleX));let s=" ";for(let l=e;l<=t;l++)if(l%a===0){const u=(this.gridScaleX!==1?(l/this.gridScaleX).toFixed(1).slice(-4):l).toString();s+=u;for(let A=1;A<a&&l+A<=t;A++)s+=" ";l+=a-1}else s+=" ";o.push(s)}for(let a=i;a>=n;a--){let s="";this.showAxisLabels&&(s=`${(a/this.gridScaleY).toFixed(1).slice(-4).toString().padStart(4," ")} `);for(let l=e;l<=t;l++){const c=`${l},${a}`,u=this.overlay.get(c),A=this.traces.get(c)??0;s+=u??Udt(A)}o.push(s.replace(/ +$/g,""))}return o.join(`
|
|
851
851
|
`)}},qye=(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,o=new Fdt({showAxisLabels:e.showAxisLabels,gridScaleX:t,gridScaleY:n}),a=[];for(const s of r.chips){if(s.isPassive){a.push(s);continue}const l=s.getWidth(),c=s.getHeight(),u=Math.round(c*e.gridScaleY);if(e.chipLabels&&s.topPinCount===0){const f=s.y+s.getHeight(),p=s.chipId;for(let C=s.x,v=0;v<p.length;v++,C+=i)o.putOverlay(C,f,p[v])}const A=Math.round(s.x*e.gridScaleX),d=Math.round(s.y*e.gridScaleY);for(let f=0;f<u;++f){let p=" ",C=" ",v=" ";const _=f===0,x=f===u-1,b=l*e.gridScaleX;if(_)p="└",C="─".repeat(b),v="┘";else if(x)p="┌",C="─".repeat(b),v="┐";else{const F=d+f;let U,H;for(const O of s.leftPins){const ne=s.getPinLocation(O.pinNumber);if(Math.round(ne.y*e.gridScaleY)===F){U=O;break}}for(const O of s.rightPins){const ne=s.getPinLocation(O.pinNumber);if(Math.round(ne.y*e.gridScaleY)===F){H=O;break}}p=U?"┤":"│",v=H?"├":"│";const G=U?String(U.pinNumber):null,j=H?String(H.pinNumber):null;if(G&&j){const O=b-G.length-j.length;C=G+" ".repeat(Math.max(1,O))+j}else G?C=G+" ".repeat(Math.max(0,b-G.length)):j?C=" ".repeat(Math.max(0,b-j.length))+j:C=" ".repeat(Math.max(0,b))}const T=p+(C.length===l-2?C:C.padEnd(l-2," "))+v;for(let F=0;F<T.length;++F){const U=(A+F)/e.gridScaleX,H=(d+f)/e.gridScaleY;o.putOverlay(U,H,T[F])}}}for(const s of r.netLabels)if(s.netId.length>0){const l=s.netId[0];o.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,u=s.end.y,A=Math.min(c,u),d=Math.max(c,u);if(A===d)continue;o.addEdge(l,c,c<u?"up":"down"),o.addEdge(l,u,c<u?"down":"up");const f=Math.round(A*e.gridScaleY),p=Math.round(d*e.gridScaleY);for(let C=f+1;C<p;C++){const v=C/e.gridScaleY;o.addEdge(l,v,"up"),o.addEdge(l,v,"down")}}else if(s.start.y===s.end.y){const l=s.start.y,c=s.start.x,u=s.end.x,A=Math.min(c,u),d=Math.max(c,u);if(A===d)continue;o.addEdge(c,l,c<u?"right":"left"),o.addEdge(u,l,c<u?"left":"right");const f=Math.round(A*e.gridScaleX),p=Math.round(d*e.gridScaleX);for(let C=f+1;C<p;C++){const v=C/e.gridScaleX;o.addEdge(v,l,"left"),o.addEdge(v,l,"right")}}for(const s of r.connectionPoints)s.showAsIntersection&&o.putOverlay(s.x,s.y,"●");for(const s of a)if(s.leftPinCount>0||s.rightPinCount>0){const c=s.x-s.getWidth()/2,u=s.getWidth()/(1/e.gridScaleX);for(let A=0,d=0;A<s.getWidth();A+=1/e.gridScaleX,d++)u<=3?s.chipId[d]&&o.putOverlay(c+A,s.y,s.chipId[d]):A===0?o.putOverlay(c+A,s.y,"["):A>=s.getWidth()-1/e.gridScaleX?o.putOverlay(c+A,s.y,"]"):s.chipId[d-1]&&o.putOverlay(c+A,s.y,s.chipId[d-1])}else o.putOverlay(s.x,s.y-s.getHeight()/2,"┬"),o.putOverlay(s.x,s.y,s.chipId[0]),s.chipId[1]&&o.putOverlay(s.x+1/e.gridScaleX,s.y,s.chipId[1]),o.putOverlay(s.x,s.y+s.getHeight()/2,"┴");return o},rj=(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,_E=r=>"boxId"in r?`box[${r.boxId}].${r.pinNumber}`:"junctionId"in r?`junction[${r.junctionId}]`:`netlabel[${r.netId},${r.netLabelId}]`,vk=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}`)},Ldt=r=>{const e=[],t=[],n=[],i=[];for(const o of r.chips){o.pinPositionsAreSet||o.setPinPositions();const a=[],s=[...o.leftPins,...o.bottomPins,...o.rightPins,...o.topPins];for(const c of s){const u=o.getPinLocation(c.pinNumber);a.push({pinNumber:c.pinNumber,x:u.x,y:u.y})}const l=o.getCenter();e.push({boxId:o.chipId,leftPinCount:o.leftPinCount,rightPinCount:o.rightPinCount,topPinCount:o.topPinCount,bottomPinCount:o.bottomPinCount,centerX:l.x,centerY:l.y,pins:a})}for(const o of r.netLabels)t.push({netLabelId:o.netLabelId,netId:o.netId,x:o.x,y:o.y,anchorPosition:o.anchorSide});for(const o of r.paths){const a=r.lines.filter(A=>A.pathId===o.pathId),s=new Set(a.flatMap(A=>[_E(A.start.fromJunctionId?{junctionId:A.start.fromJunctionId}:A.start.ref),_E(A.end.fromJunctionId?{junctionId:A.end.fromJunctionId}:A.end.ref)]));let l=Array.from(s);if(l.length===3&&l.some(A=>A.startsWith("junction["))&&(l=l.filter(A=>!A.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,u]=l;_E(a[0].start.ref)===u&&([c,u]=[u,c]),n.push({points:a.flatMap(A=>[{x:A.start.x,y:A.start.y},{x:A.end.x,y:A.end.y}]),from:vk(c),to:vk(u)})}for(const o of r.connectionPoints)i.push({junctionId:o.junctionId,x:o.x,y:o.y});return{boxes:e,netLabels:t,paths:n,junctions:i}},Zye="ABCDEFGHIJKLMNOPQRSTUVWXYZ",Gdt=class rKe{constructor(e={}){Le(this,"chips",[]);Le(this,"netLabels",[]);Le(this,"lines",[]);Le(this,"paths",[]);Le(this,"connectionPoints",[]);Le(this,"defaultChipWidth",2);Le(this,"defaultSingleSidedChipWidth",2);Le(this,"defaultPinSpacing",.2);Le(this,"defaultPassiveWidth",1);Le(this,"defaultPassiveHeight",.2);Le(this,"autoLabelCounter",1);Le(this,"name");Le(this,"_pathCounter",1);Le(this,"_netLabelCounter",1);Le(this,"_junctionCounter",1);this.name=e.name??"Circuit"}clone(){const e=new rKe({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 nj(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=(o,a,s)=>Array.from({length:o},(l,c)=>{const u=new tj(n,a+c),A=s[c];return A&&typeof A.x=="number"&&(u.x=A.x),A&&typeof A.y=="number"&&(u.y=A.y),u});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 nj(this,e);return this.chips.push(t),t}passive(e){const t=e??`R${this.chips.length+1}`,n=new nj(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 a of this.connectionPoints)if(a.x===e&&a.y===t)return a;const o={junctionId:`XX${this._junctionCounter++}`,x:e,y:t,pinRef:n,showAsIntersection:i};return this.connectionPoints.push(o),o}toString(){return qye(this,{chipLabels:!0,showAxisLabels:!0,gridScaleX:2,gridScaleY:5}).toString()}getNetlist(){const e=new Sdt;for(const a of this.chips)e.addBox({boxId:a.chipId,leftPinCount:a.leftPinCount||0,rightPinCount:a.rightPinCount||0,topPinCount:a.topPinCount||0,bottomPinCount:a.bottomPinCount||0});for(const a of this.netLabels)e.addNet({netId:a.netId}),e.connect(a.fromRef,{netId:a.netId,netLabelId:a.netLabelId});for(const a of this.lines)rj(a.start.ref,a.end.ref)||e.connect(a.start.ref,a.end.ref);const t=(a,s,l)=>{const c=a.get(s)??[];c.push(l),a.set(s,c)},n=new Map;for(const a of this.connectionPoints)t(n,`${a.x},${a.y}`,a.pinRef);const i=new Set;for(const a of this.connectionPoints)i.add(`${a.x},${a.y}`);for(const a of this.lines)t(n,`${a.start.x},${a.start.y}`,a.start.ref),t(n,`${a.end.x},${a.end.y}`,a.end.ref);for(const[a,s]of n.entries())if(i.has(a))for(let l=0;l<s.length;++l)for(let c=l+1;c<s.length;++c)e.connect(s[l],s[c]);const o=(a,s,l)=>{if(l.start.x===l.end.x){if(a!==l.start.x)return!1;const c=Math.min(l.start.y,l.end.y),u=Math.max(l.start.y,l.end.y);return s>=c&&s<=u}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),u=Math.max(l.start.x,l.end.x);return a>=c&&a<=u}return!1};for(const a of this.connectionPoints)for(const s of this.lines)o(a.x,a.y,s)&&e.connect(a.pinRef,s.start.ref);return e.getNetlist()}getReadableNetlist(){return wR(this.getNetlist())}flipX(){return kdt(this)}generateAutoLabel(){return Zye[this.autoLabelCounter++-1]??`L${this.autoLabelCounter-Zye.length}`}getGrid(){return qye(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 Ldt(this)}};function HS(r={}){return new Gdt({name:r.name})}function Odt(r){const e=r.candidateNetlist.boxes[r.candidateBoxIndex],t=r.targetNetlist.boxes[r.targetBoxIndex],n=[];for(const i of ej){const o=e[`${i}PinCount`]??0,a=t[`${i}PinCount`]??0;o!==a&&n.push({type:"matched_box_side_has_wrong_pin_count",candidateBoxIndex:r.candidateBoxIndex,targetBoxIndex:r.targetBoxIndex})}return n}var Ik=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(o=>"boxIndex"in o?{boxId:`box${o.boxIndex}`,pinNumber:o.pinNumber}:{netId:`net${o.netIndex}`})}));return{boxes:e,nets:t,connections:n}};function ij(r){const{netlist:e,chipId:t,pinNumber:n}=r,i=`${t}.pin${n}`,o=[{boxId:i,leftPinCount:0,rightPinCount:1,topPinCount:0,bottomPinCount:0}],a=[],s=[],l=new Set([i]),c=new Set;for(const u of e.connections)if(u.connectedPorts.some(d=>"boxId"in d&&d.boxId===t&&d.pinNumber===n)){const d=[{boxId:i,pinNumber:1}];for(const f of u.connectedPorts)if("boxId"in f){if(f.boxId===t&&f.pinNumber===n)continue;if(d.push({boxId:f.boxId,pinNumber:f.pinNumber}),!l.has(f.boxId)){const p=e.boxes.find(C=>C.boxId===f.boxId);p&&o.push(p),l.add(f.boxId)}}else"netId"in f&&(d.push({netId:f.netId}),c.has(f.netId)||(a.push({netId:f.netId}),c.add(f.netId)));d.length>1&&s.push({connectedPorts:d})}return{boxes:o,nets:a,connections:s}}var oj=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(""),aj=r=>{const{netlist:e,chipId:t,pinNumber:n}=r,i=new Set;for(const o of e.connections)if(o.connectedPorts.some(s=>"boxId"in s&&s.boxId===t&&s.pinNumber===n))for(const s of o.connectedPorts)"boxId"in s&&s.boxId!==t&&i.add(s.boxId);return`box_count_${i.size}`},sj=r=>{let e;if("pinShapeNetlist"in r)e=r.pinShapeNetlist;else{const{netlist:n,chipId:i,pinNumber:o}=r;e=ij({chipId:i,pinNumber:o,netlist:n})}return`${nw(e).normalizedNetlist.boxes.map(n=>oj(n)).join(",")}`};function zdt(r){const e=Ik(r.candidateNetlist),t=Ik(r.targetNetlist),n=[],i=e.boxes[r.candidateBoxIndex],o=t.boxes[r.targetBoxIndex],a=i.leftPinCount+i.rightPinCount+i.topPinCount+i.bottomPinCount,s=a===2&&Math.max(i.leftPinCount,i.rightPinCount,i.topPinCount,i.bottomPinCount)===1;for(let d=0;d<a;d++){const f=d+1,p=ij({netlist:e,chipId:i.boxId,pinNumber:f});n.push({side:VB(f,i).side,signature:sj({pinShapeNetlist:p})})}const l=[...n],c=[],u=o.leftPinCount+o.rightPinCount+o.topPinCount+o.bottomPinCount,A=u===2&&Math.max(o.leftPinCount,o.rightPinCount,o.topPinCount,o.bottomPinCount)===1;for(let d=0;d<u;d++){const f=d+1,p=ij({netlist:t,chipId:o.boxId,pinNumber:f});if(p.connections.length===0)continue;const C={signature:sj({pinShapeNetlist:p}),side:VB(f,o).side},v=A&&s,_=l.findIndex(x=>x.signature===C.signature&&(x.side===C.side||v));if(_!==-1){l.splice(_,1);continue}c.push({type:"matched_box_missing_pin_shape_on_side",candidateBoxIndex:r.candidateBoxIndex,targetBoxIndex:r.targetBoxIndex,targetPinNumber:f,targetPinShapeSignature:C.signature,candidateShapeSignatures:l.map(x=>x.signature),side:C.side})}return c}function Hdt(r){const{candidateNetlist:e,targetNetlist:t,candidateBoxIndex:n,targetBoxIndex:i}=r,o=[],a=Ik(e),s=Ik(t),l=a.boxes[n],c=s.boxes[i];if(!l||!c)return o;const u=[],A=l.leftPinCount+l.rightPinCount+l.topPinCount+l.bottomPinCount;for(let C=0;C<A;C++){const v=C+1,_=aj({netlist:a,chipId:l.boxId,pinNumber:v});u.push({side:VB(v,l).side,signature:_})}const d=[...u],f=c.leftPinCount+c.rightPinCount+c.topPinCount+c.bottomPinCount;if(A===2&&f===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=u.map(_=>_.signature).filter(_=>_!=="box_count_0").sort(),v=[];for(let _=0;_<f;_++){const x=_+1,b=aj({netlist:s,chipId:c.boxId,pinNumber:x});b!=="box_count_0"&&v.push(b)}v.sort(),C.length>0&&v.length>0&&C.join(",")!==v.join(",")&&o.push({type:"matched_box_missing_pin_shape_box_count_on_side",candidateBoxIndex:n,targetBoxIndex:i,side:"left",targetPinNumber:-1,targetBoxCountSignature:v.join(","),candidateBoxCountSignatures:C})}else for(let C=0;C<f;C++){const v=C+1,_=aj({netlist:s,chipId:c.boxId,pinNumber:v});if(_==="box_count_0")continue;const x={signature:_,side:VB(v,c).side},b=d.findIndex(T=>T.signature===x.signature&&T.side===x.side);if(b===-1){const T=u.filter(F=>F.side===x.side).map(F=>F.signature);o.push({type:"matched_box_missing_pin_shape_box_count_on_side",candidateBoxIndex:n,targetBoxIndex:i,side:x.side,targetPinNumber:v,targetBoxCountSignature:_,candidateBoxCountSignatures:T})}else d.splice(b,1)}return o}var Ydt=[Odt,zdt,Hdt];function Vdt(r){const e=[];for(const t of Ydt)e.push(...t(r));return e}function Xye(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 Kdt(r){return{...r,leftPinCount:r.topPinCount,rightPinCount:r.bottomPinCount,topPinCount:r.leftPinCount,bottomPinCount:r.rightPinCount}}function jdt(r){return{...r,leftPinCount:r.rightPinCount,rightPinCount:r.leftPinCount,topPinCount:r.bottomPinCount,bottomPinCount:r.topPinCount}}function Jdt(r){const{targetNetlist:e,candidateNetlist:t,targetBoxIndex:n,candidateBoxIndex:i}=r,o=e.boxes[n],a=t.boxes[i];if(!o||!a)return[{netlist:e,rotation:0}];if(!Xye(o)||!Xye(a))return[{netlist:e,rotation:0}];const s=[];let l={...o},c=0;for(let p=0;p<4&&!(l.leftPinCount===a.leftPinCount&&l.rightPinCount===a.rightPinCount&&l.topPinCount===a.topPinCount&&l.bottomPinCount===a.bottomPinCount);p++)l=Kdt(l),c=(c+90)%360;const u={...e,boxes:e.boxes.map((p,C)=>C===n?l:p)};s.push({netlist:u,rotation:c});const A=jdt(l),d={...e,boxes:e.boxes.map((p,C)=>C===n?A:p)},f=(c+180)%360;return s.push({netlist:d,rotation:f}),s}function Ck(r){const{candidateNetlist:e,targetNetlist:t}=r,n=[],i=new Set;for(let o=0;o<t.boxes.length;o++){const a=new Map;for(let c=0;c<e.boxes.length;c++){if(i.has(c))continue;const u=Jdt({targetNetlist:t,candidateNetlist:e,targetBoxIndex:o,candidateBoxIndex:c});let A=[],d=1/0,f=0;for(const{netlist:p,rotation:C}of u){const v=Vdt({candidateNetlist:e,targetNetlist:p,candidateBoxIndex:c,targetBoxIndex:o,alreadyMatchedBoxes:n}),_=$K(v);_<d&&(d=_,A=v,f=C)}a.set({targetBoxIndex:o,candidateBoxIndex:c},{issues:A,similarityDistance:d,rotation:f})}let s=null,l=1/0;for(const[c,{similarityDistance:u}]of a.entries())u<l&&(l=u,s=c);if(s){const{candidateBoxIndex:c}=s,{issues:u,similarityDistance:A,rotation:d}=a.get(s);i.add(c),n.push({targetBoxIndex:o,candidateBoxIndex:c,issues:u,score:A,targetBoxRotationCcw:d})}}return n}function lj(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 Wdt(r,e){const{chipId:t,pinNumber:n,netName:i}=e,o=r.chips.find(A=>A.chipId===t);if(!o||n<1||n>o.totalPinCount)return;const a=o.pin(n);if(!a||typeof a.line!="function")return;const{side:s}=VB(n,o),{dx:l,dy:c}=lj(s);a.line(l*2,c*2);const u=i||r.generateAutoLabel();a.label(u)}function qdt(r,e){const{chipId:t,pinNumber:n}=e,i=o=>"boxId"in o&&o.boxId===t&&o.pinNumber===n;r.lines=r.lines.filter(o=>!i(o.start.ref)&&!i(o.end.ref)),r.connectionPoints=r.connectionPoints.filter(o=>!i(o.pinRef)),r.netLabels=r.netLabels.filter(o=>!i(o.fromRef))}function Zdt(r,e){const{chipId:t,pinNumber:n}=e,i=r.chips.find(a=>a.chipId===t);if(!i)return;const o=i.pin(n);if(o.lastDx===0&&o.lastDy===0&&!o.lastCreatedLine){const a=lj(o.side);o.line(a.dx*2,a.dy*2)}o.passive()}function Xdt(r,e){const{chipId:t,pinNumber:n,labelNetId:i}=e,o=r.chips.find(l=>l.chipId===t);if(!o)return;const a=o.pin(n);if(a.lastDx===0&&a.lastDy===0&&!a.lastCreatedLine){const l=lj(a.side);a.line(l.dx*2,l.dy*2)}a.passive().label(i)}function $dt(r,e){const{chipId:t}=e;r.chips=r.chips.filter(o=>o.chipId!==t);const n=o=>"boxId"in o&&o.boxId===t,i=r.lines.filter(o=>n(o.start.ref)||n(o.end.ref));r.lines=r.lines.filter(o=>!(n(o.start.ref)&&n(o.end.ref)));for(const o of i){if(n(o.start.ref)&&n(o.end.ref))continue;const a=n(o.start.ref)?o.start:o.end,s=n(o.start.ref)?o.end:o.start;$ye(r,s.x,s.y,o)?r.lines=r.lines.filter(c=>c!==o):(r.lines=r.lines.filter(c=>c!==o),eve(r,s.x,s.y,s.ref,a.ref))}r.connectionPoints=r.connectionPoints.filter(o=>!n(o.pinRef)),r.netLabels=r.netLabels.filter(o=>!n(o.fromRef))}function $ye(r,e,t,n){let i=0;for(const o of r.lines)o!==n&&(o.start.x===e&&o.start.y===t||o.end.x===e&&o.end.y===t)&&i++;for(const o of r.connectionPoints)if(o.x===e&&o.y===t){i++;break}return i>=2}function eve(r,e,t,n,i){const o=r.lines.filter(a=>{const s=a.start.x===e&&a.start.y===t&&!rj(a.start.ref,i),l=a.end.x===e&&a.end.y===t&&!rj(a.end.ref,i);return s||l});for(const a of o){const s=a.start.x===e&&a.start.y===t?a.end:a.start;if($ye(r,s.x,s.y,a))return;r.lines=r.lines.filter(c=>c!==a),eve(r,s.x,s.y,s.ref,i)}}var eft=(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 tft(r,e){const{chipId:t,side:n,pinNumber:i}=e,o=r.chips.find(b=>b.chipId===t);if(!o)return;const a=o.totalPinCount;if(i<1||i>a)throw new Error(`Invalid pin number: ${i} for chip ${o.chipId} with dimensions ${o.leftPinCount}x${o.bottomPinCount}x${o.rightPinCount}x${o.topPinCount}`);o.pinPositionsAreSet||o.setPinPositions();const s=new Map;for(let b=1;b<=a;++b)s.set(b,o.getPinLocation(b));const l=b=>"boxId"in b&&b.boxId===t&&b.pinNumber===i;r.lines=r.lines.filter(b=>!l(b.start.ref)&&!l(b.end.ref)),r.connectionPoints=r.connectionPoints.filter(b=>!l(b.pinRef)),r.netLabels=r.netLabels.filter(b=>!l(b.fromRef));let c,u;switch(n){case"left":c=o.leftPins,u="leftPinCount";break;case"right":c=o.rightPins,u="rightPinCount";break;case"top":c=o.topPins,u="topPinCount";break;case"bottom":c=o.bottomPins,u="bottomPinCount";break;default:return}const A=c.findIndex(b=>b.pinNumber===i);if(A===-1)throw new Error(`Pin number ${i} not found on side ${n} of chip ${o.chipId}`);c.splice(A,1),o[u]--;const d=new Map;for(let b=1;b<=a;++b)b!==i&&(b<i?d.set(b,b):d.set(b,b-1));const f=[...o.leftPins,...o.bottomPins,...o.rightPins,...o.topPins];for(const b of f){const T=b.pinNumber,F=d.get(T);F!==void 0&&(b.pinNumber=F)}const{side:p,indexOnSide:C}=VB(i,{leftPinCount:o.leftPinCount+(n==="left"?1:0),rightPinCount:o.rightPinCount+(n==="right"?1:0),topPinCount:o.topPinCount+(n==="top"?1:0),bottomPinCount:o.bottomPinCount+(n==="bottom"?1:0)}),v={};for(const[b,T]of d.entries())o.pinMargins[b]&&(v[T]={...o.pinMargins[b]});for(const[b,T]of d.entries()){const F=VB(b,{leftPinCount:o.leftPinCount+(n==="left"?1:0),rightPinCount:o.rightPinCount+(n==="right"?1:0),topPinCount:o.topPinCount+(n==="top"?1:0),bottomPinCount:o.bottomPinCount+(n==="bottom"?1:0)});if(F.side===p&&F.indexOnSide>C){const U=v[T]||{marginTop:.2,marginLeft:.2};n==="left"||n==="right"?v[T]={...U,marginTop:U.marginTop+.2}:v[T]={...U,marginLeft:U.marginLeft+.2}}}o.pinMargins=v;const _=new Map;for(const[b,T]of d.entries())b!==T&&_.set(b,T);_.size>0&&eft(r,o.chipId,_),o.pinPositionsAreSet=!1,o.setPinPositions();const x=new Map;for(let b=1;b<=a;++b){if(b===i)continue;const T=d.get(b),F=s.get(b),U=o.getPinLocation(T),H=U.x-F.x,G=U.y-F.y;(H!==0||G!==0)&&x.set(T,{dx:H,dy:G})}if(x.size>0){const b=T=>"boxId"in T&&T.boxId===t&&x.has(T.pinNumber)?x.get(T.pinNumber):null;for(const T of r.lines){const F=b(T.start.ref),U=b(T.end.ref);(F??U)&&(F&&(T.start.x+=F.dx,T.start.y+=F.dy),U&&(T.end.x+=U.dx,T.end.y+=U.dy))}for(const T of r.connectionPoints){const F=b(T.pinRef);F&&(T.x+=F.dx,T.y+=F.dy)}for(const T of r.netLabels){const F=b(T.fromRef);F&&(T.x+=F.dx,T.y+=F.dy)}}}var nft=(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 rft(r,e){const{chipId:t,side:n,betweenPinNumbers:i}=e,o=r.chips.find(b=>b.chipId===t);if(!o)return;const a=o.totalPinCount,s=new Map;for(let b=1;b<=a;++b)s.set(b,o.getPinLocation(b));const l=Math.min(...i),c=n==="left"?o.leftPins:n==="right"?o.rightPins:n==="top"?o.topPins:o.bottomPins,u=c.findIndex(b=>b.pinNumber===l)+1;if(l!==0&&u===0)return;o[`${n}PinCount`]+=1;const A=l+1,d=new tj(o,A);c.splice(u,0,d);const f=new Map,p=o.totalPinCount-1;for(let b=1;b<=p;++b)b>l&&f.set(b,b+1);const C=new Set([d]),v=b=>b.forEach(T=>{C.has(T)||f.has(T.pinNumber)&&(T.pinNumber=f.get(T.pinNumber))});v(o.leftPins),v(o.rightPins),v(o.topPins),v(o.bottomPins),nft(r,t,f),o.pinPositionsAreSet=!1,o.setPinPositions();const _=new Map;for(let b=1;b<=a;++b){const T=s.get(b),F=f.get(b)??b,U=o.getPinLocation(F),H=U.x-T.x,G=U.y-T.y;(H||G)&&_.set(F,{dx:H,dy:G})}const x=b=>"boxId"in b&&b.boxId===t&&_.has(b.pinNumber)?_.get(b.pinNumber):null;for(const b of r.lines){const T=x(b.start.ref)??x(b.end.ref);T&&(b.start.x+=T.dx,b.start.y+=T.dy,b.end.x+=T.dx,b.end.y+=T.dy)}for(const b of r.connectionPoints){const T=x(b.pinRef);T&&(b.x+=T.dx,b.y+=T.dy)}for(const b of r.netLabels){const T=x(b.fromRef);T&&(b.x+=T.dx,b.y+=T.dy)}}function ift(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 oft(r,e){const{fromChipId:t,fromPinNumber:n,toChipId:i,toPinNumber:o,netName:a}=e,s=r.chips.find(f=>f.chipId===t),l=r.chips.find(f=>f.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),u=l.pin(o);if(!c)throw new Error(`Could not find pin ${n} on chip ${t}`);if(!u)throw new Error(`Could not find pin ${o} on chip ${i}`);const A=l.getPinLocation(o),d=a||`connection_${t}_${n}_to_${i}_${o}`;c.pathTo(A.x,A.y).mark(d),u.connectToMark(d)}function QM(r,e){switch(e.type){case"add_label_to_pin":Wdt(r,e);break;case"add_passive_to_pin":Zdt(r,e);break;case"add_passive_with_label_to_pin":Xdt(r,e);break;case"clear_pin":qdt(r,e);break;case"add_pin_to_side":rft(r,e);break;case"remove_pin_from_side":tft(r,e);break;case"remove_chip":$dt(r,e);break;case"change_passive_orientation":ift(r,e);break;case"draw_line_between_pins":oft(r,e);break}}function QR(r){const e=[],{template:t,target:n}=r,i=t.getNetlist(),o=nw(i),a=nw(n),s=o.normalizedNetlist,l=a.normalizedNetlist,c=Ck({candidateNetlist:s,targetNetlist:l}).map(u=>{var A,d;return{...u,candidateChipId:(A=Object.entries(o.transform.boxIdToBoxIndex).find(([f,p])=>p===u.candidateBoxIndex))==null?void 0:A[0],targetChipId:(d=Object.entries(a.transform.boxIdToBoxIndex).find(([f,p])=>p===u.targetBoxIndex))==null?void 0:d[0]}});for(const u of t.chips){if(c.some(f=>f.candidateChipId===u.chipId))continue;const d={type:"remove_chip",chipId:u.chipId};QM(t,d),e.push(d);break}return{appliedOperations:e,matchedBoxes:c}}function aft(r){const{template:e,target:t,matchedBoxes:n}=r,i=[],o=t.boxes;for(const{candidateChipId:a,targetChipId:s}of n){const l=e.chips.find(u=>u.chipId===a),c=o.find(u=>u.boxId===s);if(!(!c||!l)&&!l.isPassive)for(const u of ej){const A=c[`${u}PinCount`];if(l[`${u}PinCount`]<A){let d;u==="left"?d=0:u==="bottom"?d=l.leftPinCount+l.bottomPinCount:u==="right"?d=l.leftPinCount+l.bottomPinCount+l.rightPinCount:d=l.totalPinCount;const f={type:"add_pin_to_side",chipId:l.chipId,side:u,betweenPinNumbers:[d,d+1]};return QM(e,f),i.push(f),{appliedOperations:i}}if(l[`${u}PinCount`]>A){const d=sft({template:e,target:t,chipId:l.chipId,side:u}),f={type:"remove_pin_from_side",chipId:l.chipId,side:u,pinNumber:d};return QM(e,f),i.push(f),{appliedOperations:i}}}}return{appliedOperations:i}}function sft(r){const{template:e,target:t,chipId:n,side:i}=r,o=e.chips.find(u=>u.chipId===n);if(!o)throw new Error(`Chip ${n} not found`);const s={left:o.leftPins,right:o.rightPins,top:o.topPins,bottom:o.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 u of s)try{const A=e.clone(),d={type:"remove_pin_from_side",chipId:n,side:i,pinNumber:u.pinNumber};QM(A,d);const f=lft(A,t);f<c&&(c=f,l=u.pinNumber)}catch{continue}return l}function lft(r,e){try{const t=nw(r.getNetlist()),n=nw(e),o=Ck({candidateNetlist:t.normalizedNetlist,targetNetlist:n.normalizedNetlist}).flatMap(a=>a.issues||[]);return $K(o)}catch{return Number.POSITIVE_INFINITY}}function cft(r){const{template:e,target:t,matchedBoxes:n}=r,i=[];for(const{candidateChipId:o,targetChipId:a}of n){const s=e.chips.find(u=>u.chipId===o),l=t.boxes.find(u=>u.boxId===a);if(!l||!s)continue;const c=["left","right","top","bottom"];for(const u of c){const A=s[`${u}PinCount`],d=l[`${u}PinCount`]||0;if(A>d){const f=A-d,p=uft({template:e,chipId:o,side:u,pinsToRemove:f});if(p.length>0){const C=p[0];return QM(e,C),i.push(C),{appliedOperations:i}}}}}return{appliedOperations:i}}function uft(r){const{template:e,chipId:t,side:n,pinsToRemove:i}=r,o=e.chips.find(c=>c.chipId===t);if(!o)return[];const s={left:o.leftPins,right:o.rightPins,top:o.topPins,bottom:o.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 Aft(r){const e=[],{template:t,target:n,matchedBoxes:i}=r,o=n.connections||[];for(const a of o){const s=a.connectedPorts.filter(_=>"boxId"in _);if(s.length!==2)continue;const[l,c]=s;if(!l||!c)continue;const u=i.find(_=>{var x,b;return((b=(x=n.boxes)==null?void 0:x[_.targetBoxIndex])==null?void 0:b.boxId)===l.boxId}),A=i.find(_=>{var x,b;return((b=(x=n.boxes)==null?void 0:x[_.targetBoxIndex])==null?void 0:b.boxId)===c.boxId});if(!(u!=null&&u.candidateChipId)||!(A!=null&&A.candidateChipId))continue;const d=u.candidateChipId,f=A.candidateChipId;if(!(t.getNetlist().connections||[]).some(_=>{const x=_.connectedPorts.filter(F=>"boxId"in F),b=x.some(F=>F.boxId===d&&F.pinNumber===l.pinNumber),T=x.some(F=>F.boxId===f&&F.pinNumber===c.pinNumber);return b&&T})){const _={type:"draw_line_between_pins",fromChipId:d,fromPinNumber:l.pinNumber,toChipId:f,toPinNumber:c.pinNumber};try{QM(t,_),e.push(_);break}catch(x){console.warn("Failed to apply draw line operation:",x)}}}return{appliedOperations:e}}var dft=class extends BM{constructor(e){super();Le(this,"inputTemplate");Le(this,"targetNetlist");Le(this,"transformedTarget",null);Le(this,"outputAdaptedTemplate",null);Le(this,"outputAppliedOperations",[]);Le(this,"phase","transform-target");Le(this,"matchedBoxes",[]);Le(this,"stepCount",0);Le(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=Mdt(this.outputAdaptedTemplate,this.targetNetlist),this.phase="remove-unmatched-chips-1";break;case"remove-unmatched-chips-1":{const n=QR({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=QR({template:this.outputAdaptedTemplate,target:this.transformedTarget}),i=aft({template:this.outputAdaptedTemplate,target:this.transformedTarget,matchedBoxes:n.matchedBoxes});if(i.appliedOperations.length>0){const o=i.appliedOperations[0];this.outputAppliedOperations.push(o)}else this.phase="fix-matched-box-pin-shapes";break}case"fix-matched-box-pin-shapes":{const n=QR({template:this.outputAdaptedTemplate,target:this.transformedTarget}),i=cft({template:this.outputAdaptedTemplate,target:this.transformedTarget,matchedBoxes:n.matchedBoxes});if(i.appliedOperations.length>0){const o=i.appliedOperations[0];this.outputAppliedOperations.push(o)}else this.phase="remove-unmatched-chips-2";break}case"remove-unmatched-chips-2":{const n=QR({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=QR({template:this.outputAdaptedTemplate,target:this.transformedTarget}),i=Aft({template:this.outputAdaptedTemplate,target:this.transformedTarget,matchedBoxes:n.matchedBoxes});if(i.appliedOperations.length>0){const o=i.appliedOperations[0];this.outputAppliedOperations.push(o)}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:wR(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"}]}},fft=class extends BM{constructor(e){super();Le(this,"matchedTemplates");Le(this,"adaptationSolvers",[]);Le(this,"currentAdaptationIndex",0);Le(this,"outputAdaptedTemplates",[]);this.matchedTemplates=e.matchedTemplates,this.adaptationSolvers=this.matchedTemplates.map(t=>new dft({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}},hft=()=>{const r=HS({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},pft=()=>{const r=HS({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},gft=()=>{const r=HS({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},mft=()=>{const r=HS({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},yft=()=>{const r=HS({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},vft=()=>{const r=HS({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},Ift=()=>{const r=HS({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},Cft=()=>{const r=HS({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},_ft=()=>{const r=HS({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},Eft={template1:hft,template2:pft,template3:gft,template4:mft,template5:yft,template6:vft,template7:Ift,template8:Cft,template9:_ft},xft=Object.values(Eft);function tve(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 bft(r,e,t){if(t===0)return r;const{side:n,indexOnSide:i}=VB(r,e),o=tve(e,t);let a;switch(t){case 90:switch(n){case"left":a="top";break;case"bottom":a="left";break;case"right":a="bottom";break;case"top":a="right";break;default:a=n}break;case 180:switch(n){case"left":a="right";break;case"right":a="left";break;case"top":a="bottom";break;case"bottom":a="top";break;default:a=n}break;case 270:switch(n){case"left":a="bottom";break;case"bottom":a="right";break;case"right":a="top";break;case"top":a="left";break;default:a=n}break;default:a=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 u=["left","bottom","right","top"];for(const A of u){const d=o[`${A}PinCount`];if(d){if(A===a)return c+s;c+=d}}throw new Error(`Could not map pin ${r} after ${t}° rotation`)}function Bft(r){const{inputNetlist:e,matchedBoxes:t}=r,n=new Map;for(const a of t)n.set(a.targetBoxIndex,a.targetBoxRotationCcw);const i=e.boxes.map((a,s)=>{const l=n.get(s);return l?tve(a,l):a}),o=e.connections.map(a=>{const s=a.connectedPorts.map(l=>{if("boxId"in l){const c=e.boxes.findIndex(u=>u.boxId===l.boxId);if(c!==-1){const u=n.get(c);if(u){const A=e.boxes[c],d=bft(l.pinNumber,A,u);return{...l,pinNumber:d}}}}return l});return{...a,connectedPorts:s}});return{...e,boxes:i,connections:o}}function Sft(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 o=e.boxes.find(C=>C.boxId===i);if(!o)return[`Box ${i} (not found)`];const a=[],{leftPinCount:s,rightPinCount:l,topPinCount:c,bottomPinCount:u}=o,A=Math.min(n-4,16),d=2,f=Math.max(s,l,1);let p=i;if(i.length>A-2&&(p=`${i.substring(0,A-3)}…`),c>0){let C="";for(let b=0;b<c;b++){const T=s+u+l+b+1;C+=T.toString().padStart(2)}const v=C.substring(0,A),_=Math.floor((A-v.length)/2),x=" ".repeat(_)+v;a.push(`${" ".repeat(d+1)}${x}`)}a.push(`${" ".repeat(d)}┌${"─".repeat(A)}┐`);for(let C=0;C<f;C++){const v=C<s?(C+1).toString():"",_=C<l?(s+u+(l-1-C)+1).toString():"";let x="";if(C===Math.floor((f-1)/2)){const b=Math.floor((A-p.length)/2),T=A-p.length-b;x=" ".repeat(b)+p+" ".repeat(T)}else x=" ".repeat(A);a.push(`${v.padStart(d)}│${x}│${_.padEnd(d)}`)}if(a.push(`${" ".repeat(d)}└${"─".repeat(A)}┘`),u>0){let C="";for(let b=0;b<u;b++){const T=s+b+1;C+=T.toString().padStart(2)}const v=C.substring(0,A),_=Math.floor((A-v.length)/2),x=" ".repeat(_)+v;a.push(`${" ".repeat(d+1)}${x}`)}return a}function wft(r){const{candidateNetlist:e,targetNetlist:t}=r,n=[],i=new Map;for(let o=0;o<e.boxes.length;o++){const a=e.boxes[o],s=oj({leftPinCount:a.leftPinCount,bottomPinCount:a.bottomPinCount,rightPinCount:a.rightPinCount,topPinCount:a.topPinCount});i.has(s)||i.set(s,[]),i.get(s).push(o)}for(let o=0;o<t.boxes.length;o++){const a=t.boxes[o],s=oj({leftPinCount:a.leftPinCount,bottomPinCount:a.bottomPinCount,rightPinCount:a.rightPinCount,topPinCount:a.topPinCount});(i.get(s)||[]).length===0&&n.push({type:"no_box_matching_pin_counts",candidateBoxIndex:-1,targetBoxIndex:o})}return n}function Qft(r){const{candidateNetlist:e,targetNetlist:t}=r,n=wft({candidateNetlist:e,targetNetlist:t}),i=Ck({candidateNetlist:e,targetNetlist:t});return[...n,...i.flatMap(o=>o.issues)]}var nve=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 o=sj({netlist:r,chipId:t.boxId,pinNumber:i});e.push({boxId:t.boxId,pinNumber:i,pinShapeSignature:o})}}return e},Mft=({targetNetlist:r,candidateNetlist:e,matchedBoxes:t,targetTransform:n,candidateTransform:i})=>{const o=nve(r),a=nve(e),s=[];for(const l of t){const c=Object.keys(n.boxIdToBoxIndex).find(p=>n.boxIdToBoxIndex[p]===l.targetBoxIndex),u=Object.keys(i.boxIdToBoxIndex).find(p=>i.boxIdToBoxIndex[p]===l.candidateBoxIndex);if(!c||!u)continue;const A=o.filter(p=>p.boxId===c),d=a.filter(p=>p.boxId===u),f=new Set([...A.map(p=>p.pinNumber),...d.map(p=>p.pinNumber)]);for(const p of f){const C=A.find(_=>_.pinNumber===p),v=d.find(_=>_.pinNumber===p);s.push({targetBoxIdPinNumber:C?`${c}.${p}`:"",candidateBoxIdPinNumber:v?`${u}.${p}`:"",targetPinShapeSignature:(C==null?void 0:C.pinShapeSignature)||"",candidatePinShapeSignature:(v==null?void 0:v.pinShapeSignature)||""})}}return s},Dft=class extends BM{constructor(e){super();Le(this,"inputNetlist");Le(this,"template");Le(this,"inputNetlistWithRotations",null);Le(this,"outputIssues",[]);Le(this,"outputSimilarityDistance",1/0);Le(this,"candidateTransform",null);Le(this,"targetTransform",null);Le(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,u;const e=this.template.getNetlist(),t=nw(e),n=nw(structuredClone(this.inputNetlist)),i=t.normalizedNetlist,o=n.normalizedNetlist;this.matchedBoxes=Ck({candidateNetlist:i,targetNetlist:o});for(const A of this.matchedBoxes)A._targetBoxId=n.transform.boxIndexToBoxId[A.targetBoxIndex],A._candidateBoxId=t.transform.boxIndexToBoxId[A.candidateBoxIndex];const a=Bft({inputNetlist:structuredClone(this.inputNetlist),matchedBoxes:this.matchedBoxes});this.inputNetlistWithRotations=a;const s=nw(a),l=s.normalizedNetlist;this.candidateTransform=t.transform,this.targetTransform=s.transform,this.outputIssues=Qft({candidateNetlist:i,targetNetlist:l}),this.outputSimilarityDistance=$K(this.outputIssues),this.stats={similarityDistance:this.outputSimilarityDistance,issueCount:this.outputIssues.length,templateBoxCount:((c=i.boxes)==null?void 0:c.length)||0,templateConnectionCount:((u=i.connections)==null?void 0:u.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(o=>n.boxIdToBoxIndex[o]===e);return i?`${e} (${i})`:e.toString()}getAsciiForNetlistBoxHelper(e,t,n=45){const i=t?this.template.getNetlist():this.inputNetlistWithRotations,o=t?this.candidateTransform:this.targetTransform;return o?Sft(e,i,o,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),o=Math.max(n.length,i.length);for(;n.length<o;)n.push(" ".repeat(48));for(;i.length<o;)i.push(" ".repeat(48));const a=`Target ${this.getBoxNameFromIndex(t.targetBoxIndex,!1)}`.padEnd(48),s=`Template ${this.getBoxNameFromIndex(t.candidateBoxIndex,!0)}`.padEnd(48);e.push(`${a} → ${s}`),e.push(`${"─".repeat(48)} → ${"─".repeat(48)}`);for(let l=0;l<o;l++){const c=n[l]||"",u=i[l]||"",A=l===Math.floor(o/2)?" → ":" ";e.push(`${c.padEnd(48)}${A}${u.padEnd(48)}`)}e.push("")}return e.join(`
|
|
852
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:Mft({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:wR(this.inputNetlist)},this.inputNetlistWithRotations&&{title:"targetReadableNetlistWithRotations",ascii:wR(this.inputNetlistWithRotations)}].filter(Boolean)}},Rft=class extends BM{constructor(e){var t;super();Le(this,"inputNetlist");Le(this,"templates");Le(this,"scoringSolvers",[]);Le(this,"currentScoringIndex",0);Le(this,"outputBestMatchTemplate",null);Le(this,"templateMatchResults",[]);this.inputNetlist=e.inputNetlist,this.templates=((t=e.templateFns)==null?void 0:t.map(n=>n()))||xft.map(n=>n()),this.scoringSolvers=this.templates.map(n=>new Dft({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:wR(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}))}]}},Nft=class extends BM{constructor(e){super();Le(this,"inputNetlists");Le(this,"currentInputNetlistIndex",0);Le(this,"templateFns");Le(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 Rft({inputNetlist:this.inputNetlists[this.currentInputNetlistIndex],templateFns:this.templateFns}))}};function rve(r,e,t,n={}){return{solverName:r,solverClass:e,getConstructorParams:t,onSolved:n.onSolved}}var ive=class extends BM{constructor(e){super();Le(this,"inputNetlist");Le(this,"templateFnsOverride");Le(this,"matchPhaseSolver");Le(this,"adaptPhaseSolver");Le(this,"startTimeOfPhase",{});Le(this,"endTimeOfPhase",{});Le(this,"timeSpentOnPhase",{});Le(this,"pipelineDef",[rve("matchPhaseSolver",Nft,()=>[{inputNetlists:[this.inputNetlist],templateFns:this.templateFnsOverride}]),rve("adaptPhaseSolver",fft,()=>{var e;return[{matchedTemplates:(e=this.matchPhaseSolver)==null?void 0:e.outputMatchedTemplates}]})]);Le(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()}},Tft=r=>{switch(r){case"left":return"left";case"right":return"right";case"up":return"top";case"down":return"bottom"}},ove=r=>{const e=lB(r),t=gb(r).source_component.list().map(a=>({source_component:a,schematic_component:gb(r).schematic_component.getWhere({source_component_id:a.source_component_id}),source_ports:gb(r).source_port.list().filter(s=>s.source_component_id===a.source_component_id).map(s=>{const l=e.getNetConnectedToId(s.source_port_id),c=gb(r).schematic_port.getWhere({source_port_id:s.source_port_id}),u=(c==null?void 0:c.true_ccw_index)!=null?c.true_ccw_index+1:s.pin_number;return{source_port:s,schematic_port:gb(r).schematic_port.getWhere({source_port_id:s.source_port_id}),pin_number:u,connectivity_net_id:l}}).filter(({schematic_port:s})=>!!s)})),n=[],i=[];for(const{source_component:a,schematic_component:s,source_ports:l}of t){const c={boxId:a.name,leftPinCount:0,rightPinCount:0,topPinCount:0,bottomPinCount:0};for(const{source_port:u,schematic_port:A,pin_number:d}of l){const f=Tft(A.facing_direction);c[`${f}PinCount`]++;const p=e.getNetConnectedToId(u.source_port_id);let C=i.find(v=>v._connectivityNetId===p);C||(C={_connectivityNetId:p,connectedPorts:[]},i.push(C)),C.connectedPorts.push({boxId:a.name,pinNumber:(A==null?void 0:A.true_ccw_index)!=null?A.true_ccw_index+1:d})}n.push(c)}const o=[];for(const a of i){if(a.connectedPorts.length<2)continue;let s=a._connectivityNetId;const l=e.getIdsConnectedToNet(s).map(c=>Kye(r,c));for(const c of l)if((c==null?void 0:c.type)==="source_net"){s=c.name;break}a.connectedPorts.push({netId:s}),o.push({netId:s})}return{boxes:n,connections:i,nets:o}},ave=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(a=>a.type==="schematic_port"&&a.schematic_component_id===n.schematic_component_id&&a.true_ccw_index!==void 0);if(i.length===0)continue;i.sort((a,s)=>a.true_ccw_index-s.true_ccw_index);const o={};i.forEach((a,s)=>{o[a.pin_number]=s+1});for(const a of i){const s=o[a.pin_number];a.pin_number=s}for(const a of i){const s=e.find(l=>l.type==="source_port"&&l.source_port_id===a.source_port_id);s&&(s.pin_number=a.pin_number)}if(n.port_arrangement){const a=s=>{var l;(l=n.port_arrangement[s])!=null&&l.pins&&(n.port_arrangement[s].pins=n.port_arrangement[s].pins.map(c=>o[c]||c))};a("left_side"),a("right_side"),a("top_side"),a("bottom_side")}if(n.port_labels){const a={};for(const[s,l]of Object.entries(n.port_labels)){const c=parseInt(s.replace("pin","")),u=o[c];u!==void 0?a[`pin${u}`]=l:a[s]=l}n.port_labels=a}if(n.pin_styles){const a={};for(const[s,l]of Object.entries(n.pin_styles)){const c=parseInt(s.replace("pin","")),u=o[c];u!==void 0?a[`pin${u}`]=l:a[s]=l}n.pin_styles=a}}return e},cj=[{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 U1(r){if(r==null)return"";if(r===0)return"0";const e=Math.abs(r),t=cj.find(o=>{const a=e/o.value;return a>=1&&a<1e3})||cj[cj.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 Pft=Object.defineProperty,kft=(r,e)=>{for(var t in e)Pft(r,t,{get:e[t],enumerable:!0})},sve={};kft(sve,{Battery:()=>ept,Board:()=>Tht,Capacitor:()=>kht,Chip:()=>Mve,Constraint:()=>Yht,Crystal:()=>lpt,Cutout:()=>$ht,Diode:()=>Uht,FabricationNotePath:()=>Vht,FabricationNoteText:()=>Kht,Footprint:()=>oht,Fuse:()=>Fht,Group:()=>Cj,Hole:()=>yve,Inductor:()=>ipt,Jumper:()=>Lht,Keepout:()=>pj,Led:()=>Ght,Mosfet:()=>upt,Net:()=>hve,NetAlias:()=>Jht,NormalComponent:()=>F1,PcbTrace:()=>mve,PinHeader:()=>tpt,PlatedHole:()=>hj,Port:()=>YS,Potentiometer:()=>apt,PowerSource:()=>Oht,PrimitiveComponent:()=>nI,PushButton:()=>spt,Renderable:()=>lve,Resistor:()=>zht,Resonator:()=>rpt,SchematicBox:()=>fpt,SchematicText:()=>dpt,SilkscreenCircle:()=>Wht,SilkscreenLine:()=>Zht,SilkscreenPath:()=>gve,SilkscreenRect:()=>qht,SilkscreenText:()=>gj,SmtPad:()=>fj,Subcircuit:()=>jht,Switch:()=>Apt,Trace:()=>VS,TraceHint:()=>Sve,Transistor:()=>cpt,Via:()=>Xht});var Uft=l0("tscircuit:renderable"),jx=["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"],Fft=0,lve=class{constructor(e){Le(this,"renderPhaseStates");Le(this,"shouldBeRemoved",!1);Le(this,"children");Le(this,"isPcbPrimitive",!1);Le(this,"isSchematicPrimitive",!1);Le(this,"_renderId");Le(this,"_currentRenderPhase",null);Le(this,"_asyncEffects",[]);Le(this,"parent",null);this._renderId=`${Fft++}`,this.children=[],this.renderPhaseStates={};for(const t of jx)this.renderPhaseStates[t]={initialized:!1,dirty:!1}}_markDirty(e){var n;this.renderPhaseStates[e].dirty=!0;const t=jx.indexOf(e);for(let i=t+1;i<jx.length;i++)this.renderPhaseStates[jx[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){Uft(`${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 jx)this.runRenderPhaseForChildren(e),this.runRenderPhase(e)}runRenderPhase(e){var a,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"),(a=this==null?void 0:this[`remove${e}`])==null||a.call(this),t.initialized=!1,t.dirty=!1,this._emitRenderLifecycleEvent(e,"end");return}const o=jx.indexOf(e)-1;if(o>=0){const c=jx[o];if(this._asyncEffects.filter(A=>A.phase===c).some(A=>!A.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))}},_k={},cve=r=>{const e=Object.fromEntries(Object.entries(r).map(([t,n])=>[t.toLowerCase(),n]));Object.assign(_k,r),Object.assign(_k,e)},Lft=class extends Error{constructor(e,t,n){let i;const a=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}": ${a}`:"footprint"in t&&typeof t.footprint=="string"?i=`Invalid props for ${e} (unnamed ${t.footprint} component): ${a}`:i=`Invalid props for ${e} (unnamed): ${a}`,super(i),this.componentName=e,this.originalProps=t,this.formattedError=n}};function uj(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,...o]=e.split(/(?=[#.[])/);return i==="pin"&&(i="port"),i&&i!=="*"&&r.lowercaseComponentName!==i.toLowerCase()?!1:o.every(a=>{if(a.startsWith("#"))return r.props.id===a.slice(1);if(a.startsWith("."))return r.isMatchingNameOrAlias(a.slice(1));const s=a.match(/\[(\w+)=['"]?(.+?)['"]?\]/);if(!s)return!0;const[,l,c]=s;return r.props[l].toString()===c})}var Aj={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 o of i.children)n(o)};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=Aj.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},Gft={...Aj,getChildren:r=>r.children.filter(e=>!e.isSubcircuit)},uve={...Aj,getChildren:r=>r.children.filter(e=>e.isSubcircuit)},Ave=r=>r.replace(/ pin/g," port").replace(/ subcircuit\./g," group[isSubcircuit=true]").replace(/([^ ])\>([^ ])/g,"$1 > $2").trim(),dj={adapter:Gft,cacheResults:!0},nI=class extends lve{constructor(t){super(t);Le(this,"parent",null);Le(this,"children");Le(this,"childrenPendingRemoval");Le(this,"props");Le(this,"_parsedProps");Le(this,"externallyAddedAliases");Le(this,"isPrimitiveContainer",!1);Le(this,"source_group_id",null);Le(this,"source_component_id",null);Le(this,"schematic_component_id",null);Le(this,"pcb_component_id",null);Le(this,"cad_component_id",null);Le(this,"_cachedSelectAllQueries",new Map);Le(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 Lft(this.lowercaseComponentName,this.props,n.error.format())}get config(){return{componentName:"",zodProps:Xt({}).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 o,a;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)}),(a=(o=this.parent)==null?void 0:o.onChildChanged)==null||a.call(o,this)}computePcbPropsTransform(){const{_parsedProps:t}=this;return Qc(QA(t.pcbX??0,t.pcbY??0),IE((t.pcbRotation??0)*Math.PI/180))}_computePcbGlobalTransformBeforeLayout(){var i,o,a;const{_parsedProps:t}=this,n=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if(n&&this.props.pcbX===void 0&&this.props.pcbY===void 0)return Qc(((i=this.parent)==null?void 0:i._computePcbGlobalTransformBeforeLayout())??c0(),Qc(QA(n.x,n.y),IE((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 Qc(QA(c.x,c.y),iQ(),QA(-c.x,-c.y)),Qc(((o=this.parent)==null?void 0:o._computePcbGlobalTransformBeforeLayout())??c0(),iQ(),this.computePcbPropsTransform())}}return Qc(((a=this.parent)==null?void 0:a._computePcbGlobalTransformBeforeLayout())??c0(),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:o=>n?o==="top"?"bottom":"top":o}}_setPositionFromLayout(t){throw new Error(`_setPositionFromLayout not implemented for ${this.componentName}`)}computeSchematicPropsTransform(){const{_parsedProps:t}=this;return Qc(QA(t.schX??0,t.schY??0))}computeSchematicGlobalTransform(){var n,i;const t=this._getSchematicGlobalManualPlacementTransform(this);return t||Qc(((i=(n=this.parent)==null?void 0:n.computeSchematicGlobalTransform)==null?void 0:i.call(n))??c0(),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 o=`${n}_horz`,a=`${n}_vert`,s=`${n}_up`,l=`${n}_down`,c=`${n}_left`,u=`${n}_right`;if(u in A0&&i===0)return u;if(s in A0&&i===90)return s;if(c in A0&&i===180)return c;if(l in A0&&i===270)return l;if(o in A0&&(i===0||i===180))return o;if(a in A0&&(i===90||i===270))return a;if(n in A0)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?A0[t]??null:null}_getPcbManualPlacementForComponent(t){var a;if(!this.isSubcircuit)return null;const n=this.props.layout,i=this.props.manualEdits;if(!n&&!i)return null;const o=((a=n==null?void 0:n.manual_pcb_placement_config)==null?void 0:a.positions)||(i==null?void 0:i.pcb_placements);if(!o)return null;for(const s of o)if(n&&uj(t,s.selector)||t.props.name===s.selector)return Wr(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 o of i)if(uj(t,o.selector)||t.props.name===o.selector)return Wr(this.computeSchematicGlobalTransform(),o.center);return null}_getSchematicGlobalManualPlacementTransform(t){var i,o;const n=(i=this.getSubcircuit())==null?void 0:i._parsedProps.manualEdits;if(!n)return null;for(const a of n.schematic_placements??[])if((uj(t,a.selector)||t.props.name===a.selector)&&a.relative_to==="group_center")return Qc(((o=this.parent)==null?void 0:o._computePcbGlobalTransformBeforeLayout())??c0(),QA(a.center.x,a.center.y));return null}_getGlobalPcbPositionBeforeLayout(){return Wr(this._computePcbGlobalTransformBeforeLayout(),{x:0,y:0})}_getGlobalSchematicPositionBeforeLayout(){return Wr(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 o,a;const t=this._parsedProps.name,n=t?`${this.lowercaseComponentName}.${t}`:this.lowercaseComponentName,i=(a=(o=this.parent)==null?void 0:o.getFullPathSelector)==null?void 0:a.call(o);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),o=t.trim().split(/\> /)[0],a=o[0];return o.length>1?!1:!!(t==="*"||t[0]==="#"&&t.slice(1)===this.props.id||t[0]==="."&&i.includes(t.slice(1))||/^[a-zA-Z0-9_]/.test(a)&&n.includes(a))}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 o=(n=i.parent)==null?void 0:n.getNameAndAliases(),a=i.getNameAndAliases();if(o)for(const s of o)for(const l of a){const c=[`.${s} > .${l}`,`.${s} .${l}`];for(const u of c){const A=this._cachedSelectAllQueries.get(u);A?A.push(i):this._cachedSelectAllQueries.set(u,[i])}}}for(const[i,o]of this._cachedSelectAllQueries.entries())o.length===1&&this._cachedSelectOneQueries.set(i,o[0])}selectAll(t){if(this._cachedSelectAllQueries.has(t))return this._cachedSelectAllQueries.get(t);const n=Ave(t),i=fM(n,this,dj);if(i.length>0)return this._cachedSelectAllQueries.set(t,i),i;const[o,...a]=n.split(" "),s=zS(o,this,{adapter:uve});if(!s)return[];const l=s.selectAll(a.join(" "));return this._cachedSelectAllQueries.set(t,l),l}selectOne(t,n){if(this._cachedSelectOneQueries.has(t))return this._cachedSelectOneQueries.get(t);const i=Ave(t);n!=null&&n.port&&(n.type="port");let o=null;if(n!=null&&n.type&&(o=fM(i,this,dj).find(u=>u.lowercaseComponentName===n.type)),o??(o=zS(i,this,dj)),o)return this._cachedSelectOneQueries.set(t,o),o;const[a,...s]=i.split(" "),l=zS(a,this,{adapter:uve});return l?(o=l.selectOne(s.join(" "),n),this._cachedSelectOneQueries.set(t,o),o):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 o,a;const{lowercaseComponentName:t,_parsedProps:n,parent:i}=this;return(n==null?void 0:n.pinNumber)!==void 0&&((o=i==null?void 0:i.props)!=null&&o.name)&&(n!=null&&n.name)?`<${t}#${this._renderId}(pin:${n.pinNumber} .${i==null?void 0:i.props.name}>.${n.name}) />`:(a=i==null?void 0:i.props)!=null&&a.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()}},Oft=class extends nI{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:Xt({}).passthrough()}}doInitialSourceRender(){var e,t,n,i;if((e=this.root)!=null&&e.db){const o=this._getGlobalPcbPositionBeforeLayout(),a=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:o,schematic_center:a})}}};function zft(r,e){return new Oft(r,e)}function Hft(r,e){const t=r;return t.__tsci={...e},r}var dve={supportsMutation:!0,createInstance(r,e){const t=_k[r];if(!t)throw Object.keys(_k).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 Hft(new t(e),{})}catch(n){return zft(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:()=>GS.DefaultEventPriority,getCurrentUpdatePriority:()=>GS.DefaultEventPriority,resolveUpdatePriority:()=>GS.DefaultEventPriority,setCurrentUpdatePriority:()=>{},maySuspendCommit:()=>!1,supportsHydration:!1},dQ;_u.version.startsWith("19.")?dQ=cz(dve):dQ=dz(dve);var Yft=r=>{const e={children:[],props:{name:"$root"},add(o){o.parent=this,this.children.push(o)},computePcbGlobalTransform(){return c0()}},t=[],n=dQ.createContainer(e,0,null,!1,null,"tsci",o=>{console.log("Error in createContainer"),console.error(o),t.push(o)},null);if(_u.version.startsWith("19.")?(dQ.updateContainerSync(r,n,null,()=>{}),dQ.flushSyncWork()):dQ.updateContainer(r,n,null,()=>{}),t.length>0)throw t[0];const i=dQ.getPublicRootInstance(n);return i||e.children[0]},MR=(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}"`)},Vft=(r,e)=>{if(!r)return;const t={},n={};for(const[i,o]of Object.entries(r)){const a=MR(i,e);n[a]={...n[a],...o}}for(const[i,o]of Object.entries(n)){const a=`pin${i}`;t[a]={bottom_margin:o.bottomMargin,left_margin:o.leftMargin,right_margin:o.rightMargin,top_margin:o.topMargin}}return t},Kft=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 fve(r){const e=[];for(let t=0;t<r.length-1;t++)e.push([r[t],r[t+1]]);return e}var jft=Xt({name:Be()}),hve=class extends nI{constructor(){super(...arguments);Le(this,"source_net_id")}get config(){return{componentName:"Net",zodProps:jft}}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 o=i._getDirectlyConnectedTraces();for(const a of o)if(a._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}),o=[];for(const l of i){const c=l._portsRoutedOnPcb,u=o.find(A=>c.some(d=>A.ports.includes(d)));if(!u){o.push({ports:[...c],traces:[l]});continue}u.traces.push(l),u.ports.push(...c)}if(o.length===0)return;const a=fve(o);for(const[l,c]of a){const u=l.ports.map(b=>b._getGlobalPcbPositionBeforeLayout()),A=c.ports.map(b=>b._getGlobalPcbPositionBeforeLayout());let d=1/0,f=[-1,-1];for(let b=0;b<u.length;b++){const T=u[b];for(let F=0;F<A.length;F++){const U=A[F],H=Math.sqrt((T.x-U.x)**2+(T.y-U.y)**2);H<d&&(d=H,f=[b,F])}}const p=l.ports[f[0]],C=c.ports[f[1]],v=t.toArray().filter(b=>b.type==="pcb_smtpad"||b.type==="pcb_trace"||b.type==="pcb_plated_hole"||b.type==="pcb_hole"||b.type==="source_port"||b.type==="pcb_port"),{solution:_}=wV(v.concat([{type:"source_trace",source_trace_id:"__net_trace_tmp",connected_source_port_ids:[p.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:[p.pcb_component_id,C.pcb_component_id].filter(Boolean),pcb_port_ids:[p.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)}},pve=(r,e)=>{for(const t of e)if(typeof t=="string"&&t.startsWith("net.")){const n=r.getSubcircuit();if(!n.selectOne(t)){const i=new hve({name:t.split("net.")[1]});n.add(i)}}},fj=class extends nI{constructor(){super(...arguments);Le(this,"pcb_smtpad_id",null);Le(this,"matchedPort",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SmtPad",zodProps:zV}}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 f,p,C,v,_,x,b,T,F,U;if((f=this.root)!=null&&f.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this;if(!n.portHints)return;const i=this.getPrimitiveContainer(),o=this.getSubcircuit(),a=this._getGlobalPcbPositionBeforeLayout();i==null||i._getGlobalPcbPositionBeforeLayout();const s=OS(this._computePcbGlobalTransformBeforeLayout()),l=Math.abs(s.rotation.angle*(180/Math.PI)-90)%180<.01,{maybeFlipLayer:c}=this._getPcbPrimitiveFlippedHelpers(),u=(i==null?void 0:i._parsedProps.pcbRotation)??0;let A=null;const d=((p=this.parent)==null?void 0:p.pcb_component_id)??((C=this.getPrimitiveContainer())==null?void 0:C.pcb_component_id);n.shape==="circle"?(A=t.pcb_smtpad.insert({pcb_component_id:d,pcb_port_id:(v=this.matchedPort)==null?void 0:v.pcb_port_id,layer:c(n.layer??"top"),shape:"circle",radius:n.radius,port_hints:n.portHints.map(H=>H.toString()),x:a.x,y:a.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0}),t.pcb_solder_paste.insert({layer:A.layer,shape:"circle",radius:A.radius*.7,x:A.x,y:A.y,pcb_component_id:A.pcb_component_id,pcb_smtpad_id:A.pcb_smtpad_id,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((_=this.getGroup())==null?void 0:_.pcb_group_id)??void 0})):n.shape==="rect"&&(A=u===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(H=>H.toString()),x:a.x,y:a.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((b=this.getGroup())==null?void 0:b.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:a.x,y:a.y,ccw_rotation:u,port_hints:n.portHints.map(H=>H.toString()),subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((T=this.getGroup())==null?void 0:T.pcb_group_id)??void 0}),A.shape==="rect"&&t.pcb_solder_paste.insert({layer:c(n.layer??"top"),shape:"rect",width:A.width*.7,height:A.height*.7,x:A.x,y:A.y,pcb_component_id:A.pcb_component_id,pcb_smtpad_id:A.pcb_smtpad_id,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((F=this.getGroup())==null?void 0:F.pcb_group_id)??void 0}),A.shape==="rotated_rect"&&t.pcb_solder_paste.insert({layer:c(n.layer??"top"),shape:"rotated_rect",width:A.width*.7,height:A.height*.7,x:A.x,y:A.y,ccw_rotation:u,pcb_component_id:A.pcb_component_id,pcb_smtpad_id:A.pcb_smtpad_id,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})),A&&(this.pcb_smtpad_id=A.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,o=Math.cos(i),a=Math.sin(i),s=n.width/2,l=n.height/2,c=Math.abs(s*o)+Math.abs(l*a),u=Math.abs(s*a)+Math.abs(l*o);return{center:{x:n.x,y:n.y},bounds:{left:n.x-c,right:n.x+c,top:n.y-u,bottom:n.y+u},width:c*2,height:u*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 o;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(a=>a.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}),(o=this.matchedPort)==null||o._setPositionFromLayout(t)}},gve=class extends nI{constructor(){super(...arguments);Le(this,"pcb_silkscreen_path_id",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenPath",zodProps:AK}}doInitialPcbPrimitiveRender(){var c,u,A;if((c=this.root)!=null&&c.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),o=i(n.layer??"top");if(o!=="top"&&o!=="bottom")throw new Error(`Invalid layer "${o}" for SilkscreenPath. Must be "top" or "bottom".`);const a=this._computePcbGlobalTransformBeforeLayout(),s=this.getSubcircuit(),l=t.pcb_silkscreen_path.insert({pcb_component_id:(u=this.parent)==null?void 0:u.pcb_component_id,layer:o,route:n.route.map(d=>{const f=Wr(a,{x:d.x,y:d.y});return{...d,x:f.x,y:f.y}}),stroke_width:n.strokeWidth??.1,subcircuit_id:(s==null?void 0:s.subcircuit_id)??void 0,pcb_group_id:((A=this.getGroup())==null?void 0:A.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,o=1/0,a=-1/0;for(const s of t.route)n=Math.min(n,s.x),i=Math.max(i,s.x),o=Math.min(o,s.y),a=Math.max(a,s.y);return{width:i-n,height:a-o}}},Jft=Xt({route:hi(nR),source_trace_id:Be().optional()}),mve=class extends nI{constructor(){super(...arguments);Le(this,"pcb_trace_id",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbTrace",zodProps:Jft}}doInitialPcbPrimitiveRender(){var u,A;if((u=this.root)!=null&&u.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getPrimitiveContainer(),o=this.getSubcircuit(),{maybeFlipLayer:a}=this._getPcbPrimitiveFlippedHelpers(),s=this._computePcbGlobalTransformBeforeLayout(),l=n.route.map(d=>{const{x:f,y:p,...C}=d,v=Wr(s,{x:f,y:p});return d.route_type==="wire"&&d.layer?{...v,...C,layer:a(d.layer)}:{...v,...C}}),c=t.pcb_trace.insert({pcb_component_id:i.pcb_component_id,source_trace_id:n.source_trace_id,route:l,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});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,o=1/0,a=-1/0;for(const s of t.route)n=Math.min(n,s.x),i=Math.max(i,s.x),o=Math.min(o,s.y),a=Math.max(a,s.y),s.route_type==="wire"&&(n=Math.min(n,s.x-s.width/2),i=Math.max(i,s.x+s.width/2),o=Math.min(o,s.y-s.width/2),a=Math.max(a,s.y+s.width/2));return n===1/0||i===-1/0||o===1/0||a===-1/0?{width:0,height:0}:{width:i-n,height:a-o}}},hj=class extends nI{constructor(){super(...arguments);Le(this,"pcb_plated_hole_id",null);Le(this,"matchedPort",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PlatedHole",zodProps:TV}}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,u,A,d,f,p,C,v,_,x,b,T,F;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalPcbPositionBeforeLayout(),o=((l=this.parent)==null?void 0:l.pcb_component_id)??((c=this.getPrimitiveContainer())==null?void 0:c.pcb_component_id),a=this.getSubcircuit();if(n.shape==="circle"){const U=t.pcb_plated_hole.insert({pcb_component_id:o,pcb_port_id:(u=this.matchedPort)==null?void 0:u.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:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((A=this.getGroup())==null?void 0:A.pcb_group_id)??void 0});this.pcb_plated_hole_id=U.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:(a==null?void 0:a.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:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((f=this.getGroup())==null?void 0:f.pcb_group_id)??void 0})}else if(n.shape==="pill"||n.shape==="oval"){const U=t.pcb_plated_hole.insert({pcb_component_id:o,pcb_port_id:(p=this.matchedPort)==null?void 0:p.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:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((C=this.getGroup())==null?void 0:C.pcb_group_id)??void 0});this.pcb_plated_hole_id=U.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:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((v=this.getGroup())==null?void 0:v.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:(a==null?void 0:a.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 U=t.pcb_plated_hole.insert({pcb_component_id:o,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:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((b=this.getGroup())==null?void 0:b.pcb_group_id)??void 0});this.pcb_plated_hole_id=U.pcb_plated_hole_id}else if(n.shape==="pill_hole_with_rect_pad"){const U=t.pcb_plated_hole.insert({pcb_component_id:o,pcb_port_id:(T=this.matchedPort)==null?void 0:T.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:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((F=this.getGroup())==null?void 0:F.pcb_group_id)??void 0});this.pcb_plated_hole_id=U.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})}},pj=class extends nI{constructor(){super(...arguments);Le(this,"pcb_keepout_id",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Keepout",zodProps:aK}}doInitialPcbPrimitiveRender(){var c,u,A;if((c=this.root)!=null&&c.pcbDisabled)return;const t=this.getSubcircuit(),{db:n}=this.root,{_parsedProps:i}=this,o=this._getGlobalPcbPositionBeforeLayout(),a=OS(this._computePcbGlobalTransformBeforeLayout()),s=Math.abs(a.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:o.x,y:o.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}):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:o.x,y:o.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})),l&&(this.pcb_keepout_id=l.pcb_keepout_id)}},yve=class extends nI{constructor(){super(...arguments);Le(this,"pcb_hole_id",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Hole",zodProps:HV}}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(),o=this._getGlobalPcbPositionBeforeLayout(),a=t.pcb_hole.insert({hole_shape:"circle",hole_diameter:n.diameter,x:o.x,y:o.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=a.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})}},gj=class extends nI{constructor(){super(...arguments);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenText",zodProps:uK}}doInitialPcbPrimitiveRender(){var l,c;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getPrimitiveContainer(),o=this._getGlobalPcbPositionBeforeLayout(),{maybeFlipLayer:a}=this._getPcbPrimitiveFlippedHelpers(),s=this.getSubcircuit();t.pcb_silkscreen_text.insert({anchor_alignment:n.anchorAlignment,anchor_position:{x:o.x,y:o.y},font:n.font??"tscircuit2024",font_size:n.fontSize??1,layer:a(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,o=(t.text??"").length*n,a=n;return{width:o*n,height:a*n}}},Wft=({elm:r,pinLabels:e,readableRotation:t,anchorAlignment:n})=>{var a;const i=r.text.replace(/[{}]/g,"").toLowerCase();let o=i;if(Array.isArray(e)){const s=parseInt(i.replace(/[^\d]/g,""),10)-1;o=e[s]??i}else typeof e=="object"&&(o=((a=e[i])==null?void 0:a[0])??i);return new gj({anchorAlignment:n||"center",text:o??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})},qft=(r,e)=>((-parseInt(r||"0",10)+(e??0))%360+360)%360,vve=({componentName:r,componentRotation:e,footprint:t,pinLabels:n},i)=>{const o=[];for(const a of i)if(a.type==="pcb_smtpad"&&a.shape==="rect")o.push(new fj({pcbX:a.x,pcbY:a.y,layer:a.layer,shape:"rect",height:a.height,width:a.width,portHints:a.port_hints}));else if(a.type==="pcb_smtpad"&&a.shape==="circle")o.push(new fj({pcbX:a.x,pcbY:a.y,layer:a.layer,shape:"circle",radius:a.radius,portHints:a.port_hints}));else if(a.type==="pcb_silkscreen_path")o.push(new gve({layer:a.layer,route:a.route,strokeWidth:a.stroke_width}));else if(a.type==="pcb_plated_hole")a.shape==="circle"?o.push(new hj({pcbX:a.x,pcbY:a.y,shape:"circle",holeDiameter:a.hole_diameter,outerDiameter:a.outer_diameter,portHints:a.port_hints})):a.shape==="circular_hole_with_rect_pad"&&o.push(new hj({pcbX:a.x,pcbY:a.y,shape:"circular_hole_with_rect_pad",holeDiameter:a.hole_diameter,rectPadHeight:a.rect_pad_height,rectPadWidth:a.rect_pad_width,portHints:a.port_hints}));else if(a.type==="pcb_keepout"&&a.shape==="circle")o.push(new pj({pcbX:a.center.x,pcbY:a.center.y,shape:"circle",radius:a.radius}));else if(a.type==="pcb_keepout"&&a.shape==="rect")o.push(new pj({pcbX:a.center.x,pcbY:a.center.y,shape:"rect",width:a.width,height:a.height}));else if(a.type==="pcb_hole"&&a.hole_shape==="circle")o.push(new yve({pcbX:a.x,pcbY:a.y,diameter:a.hole_diameter}));else if(a.type==="pcb_silkscreen_text"){const s=qft(e,a.ccw_rotation);t.includes("pinrow")&&a.text.includes("PIN")?o.push(Wft({elm:a,pinLabels:n,readableRotation:s,anchorAlignment:a.anchor_alignment})):o.push(new gj({anchorAlignment:a.anchor_alignment||"center",text:r,fontSize:a.font_size+.2,pcbX:isNaN(a.anchor_position.x)?0:a.anchor_position.x,pcbY:a.anchor_position.y,pcbRotation:s??0}))}else a.type==="pcb_trace"&&o.push(new mve({route:a.route}));return o};function mj(r){let e=1/0,t=1/0,n=-1/0,i=-1/0,o=!1;for(const l of r)if(l.isPcbPrimitive&&!l.componentName.startsWith("Silkscreen")){const{x:c,y:u}=l._getGlobalPcbPositionBeforeLayout(),{width:A,height:d}=l.getPcbSize();e=Math.min(e,c-A/2),t=Math.min(t,u-d/2),n=Math.max(n,c+A/2),i=Math.max(i,u+d/2),o=!0}else if(l.children.length>0){const c=mj(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),o=!0)}if(!o)return{minX:0,minY:0,maxX:0,maxY:0,width:0,height:0};let a=n-e,s=i-t;return a<0&&(a=0),s<0&&(s=0),{minX:e,minY:t,maxX:n,maxY:i,width:a,height:s}}function Zft(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 Xft=r=>{if(r.length<=1)return!0;const e=r.map(o=>{const a=o._getPcbCircuitJsonBounds();return{left:a.bounds.left,right:a.bounds.right,top:a.bounds.top,bottom:a.bounds.bottom}}),t=Array(e.length).fill(!1).map(()=>Array(e.length).fill(!1));for(let o=0;o<e.length;o++)for(let a=o+1;a<e.length;a++){const s=e[o],l=e[a];t[o][a]=t[a][o]=!(s.right<l.left||s.left>l.right||s.bottom>l.top||s.top<l.bottom)}const n=new Set,i=o=>{n.add(o);for(let a=0;a<e.length;a++)t[o][a]&&!n.has(a)&&i(a)};return i(0),n.size===e.length},$ft=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,o)=>i+o.x,0),n=e.reduce((i,o)=>i+o.y,0);return{x:t/e.length,y:n/e.length}},eht=Xt({name:Be().optional(),pinNumber:yn().optional(),aliases:hi(Be()).optional()}),YS=class extends nI{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);Le(this,"source_port_id",null);Le(this,"pcb_port_id",null);Le(this,"schematic_port_id",null);Le(this,"schematicSymbolPortDef",null);Le(this,"matchedComponents");Le(this,"facingDirection",null);Le(this,"originDescription",null);n.originDescription&&(this.originDescription=n.originDescription),this.matchedComponents=[]}get config(){return{componentName:"Port",zodProps:eht}}_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(o=>o===this))return i;return[]}_hasSchematicPort(){var i,o;if((i=this.parent)==null?void 0:i.getSchematicSymbol())return!!(this.schematicSymbolPortDef||this._getPortsInternallyConnectedToThisPort().some(s=>s.schematicSymbolPortDef));const n=(o=this==null?void 0:this.parent)==null?void 0:o._getSchematicBoxDimensions();return!!(n&&this.props.pinNumber!==void 0&&n.getPortPositionByPinNumber(this.props.pinNumber))}_getGlobalSchematicPositionBeforeLayout(){var i,o,a;const t=(i=this.parent)==null?void 0:i.getSchematicSymbol();if(t){let s=this.schematicSymbolPortDef;if(!s&&(s=((o=this._getPortsInternallyConnectedToThisPort().find(c=>c.schematicSymbolPortDef))==null?void 0:o.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=Qc(this.parent.computeSchematicGlobalTransform(),QA(-t.center.x,-t.center.y));return Wr(l,s)}const n=(a=this==null?void 0:this.parent)==null?void 0:a._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 Wr(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 a,s;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getNameAndAliases(),o=t.source_port.insert({name:n.name,pin_number:n.pinNumber,port_hints:i,source_component_id:(a=this.parent)==null?void 0:a.source_component_id,subcircuit_id:(s=this.getSubcircuit())==null?void 0:s.subcircuit_id});this.source_port_id=o.source_port_id}doInitialSourceParentAttachment(){var n,i,o,a,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:(o=this.parent)==null?void 0:o.source_component_id,subcircuit_id:(a=this.getSubcircuit())==null?void 0:a.subcircuit_id}),this.source_component_id=(s=this.parent)==null?void 0:s.source_component_id}doInitialPcbPortRender(){var a,s,l,c,u;if((a=this.root)!=null&&a.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(A=>A.isPcbPrimitive);if(i.length===0)return;let o=null;if(i.length===1&&(o=i[0]._getPcbCircuitJsonBounds().center),i.length>1){if(!Xft(i))throw new Error(`${this.getString()} has multiple non-overlapping pcb matches, unclear how to place pcb_port: ${i.map(A=>A.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)`);o=$ft(i)}if(o){const A=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:(A==null?void 0:A.subcircuit_id)??void 0,pcb_group_id:((u=this.getGroup())==null?void 0:u.pcb_group_id)??void 0,...o,source_port_id:this.source_port_id});this.pcb_port_id=d.pcb_port_id}else{const A=i[0];throw new Error(`${A.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 o=i._getGlobalSchematicPositionBeforeLayout(),a=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:a,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=Zft(o,a);const c=t.source_port.get(this.source_port_id);let u;for(const f of(c==null?void 0:c.port_hints)??[])f.match(/^(pin)?\d+$/)||f.match(/^(left|right)/)&&!(c!=null&&c.name.match(/^(left|right)/))||(u=f);const A=t.schematic_port.insert({schematic_component_id:(d=this.parent)==null?void 0:d.schematic_component_id,center:a,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:u});this.schematic_port_id=A.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)}},Ive=r=>{const e=r.find(t=>/^(pin)?\d+$/.test(t));return e?Number.parseInt(e.replace(/^pin/,"")):null};function DR(r,e){var o;const t=Ive(r);if(!t)return null;const i=[...r.filter(a=>a.toString()!==t.toString()&&a!==`pin${t}`),...((o=e==null?void 0:e.additionalAliases)==null?void 0:o[`pin${t}`])??[]];return new YS({pinNumber:t,aliases:i})}var tht=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},nht=r=>{var o,a,s,l;if(tht(r))return{leftSize:((o=r.leftSide)==null?void 0:o.pins.length)??0,rightSize:((a=r.rightSide)==null?void 0:a.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 Cve(r){return r.leftSide!==void 0}var rht=r=>{var v,_,x,b,T,F,U,H;const e=r.portDistanceFromEdge??.4;let t=r.schPortArrangement?nht(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 G=Math.floor(i/2);t={leftSize:i-G,rightSize:G,topSize:0,bottomSize:0}}t||(t={leftSize:0,rightSize:0,topSize:0,bottomSize:0});const o=({side:G,sideIndex:j,truePinIndex:O})=>{var de,Ae,Ie,ge;if(!r.schPortArrangement||!Cve(r.schPortArrangement))return O+1;const ne={left:"top-to-bottom",bottom:"left-to-right",right:"bottom-to-top",top:"right-to-left"}[G],te=((Ae=(de=r.schPortArrangement)==null?void 0:de[`${G}Side`])==null?void 0:Ae.direction)??ne,ie=(ge=(Ie=r.schPortArrangement)==null?void 0:Ie[`${G}Side`])==null?void 0:ge.pins;let pe=j;return te!==ne&&(pe=ie.length-j-1),MR(ie[pe],r.pinLabels)},a=[];let s=0,l=0;for(let G=0;G<t.leftSize;G++){const j=o({side:"left",sideIndex:G,truePinIndex:l}),O=((v=r.numericSchPinStyle)==null?void 0:v[`pin${j}`])??((_=r.numericSchPinStyle)==null?void 0:_[j]);O!=null&&O.topMargin&&(s+=O.topMargin),a.push({trueIndex:l,pinNumber:j,side:"left",distanceFromOrthogonalEdge:s}),O!=null&&O.bottomMargin&&(s+=O.bottomMargin),G===t.leftSize-1?n.left=s:s+=r.schPinSpacing,l++}s=0;for(let G=0;G<t.bottomSize;G++){const j=o({side:"bottom",sideIndex:G,truePinIndex:l}),O=((x=r.numericSchPinStyle)==null?void 0:x[`pin${j}`])??((b=r.numericSchPinStyle)==null?void 0:b[j]);O!=null&&O.leftMargin&&(s+=O.leftMargin),a.push({trueIndex:l,pinNumber:j,side:"bottom",distanceFromOrthogonalEdge:s}),O!=null&&O.rightMargin&&(s+=O.rightMargin),G===t.bottomSize-1?n.bottom=s:s+=r.schPinSpacing,l++}s=0;for(let G=0;G<t.rightSize;G++){const j=o({side:"right",sideIndex:G,truePinIndex:l}),O=((T=r.numericSchPinStyle)==null?void 0:T[`pin${j}`])??((F=r.numericSchPinStyle)==null?void 0:F[j]);O!=null&&O.bottomMargin&&(s+=O.bottomMargin),a.push({trueIndex:l,pinNumber:j,side:"right",distanceFromOrthogonalEdge:s}),O!=null&&O.topMargin&&(s+=O.topMargin),G===t.rightSize-1?n.right=s:s+=r.schPinSpacing,l++}s=0;for(let G=0;G<t.topSize;G++){const j=o({side:"top",sideIndex:G,truePinIndex:l}),O=((U=r.numericSchPinStyle)==null?void 0:U[`pin${j}`])??((H=r.numericSchPinStyle)==null?void 0:H[j]);O!=null&&O.rightMargin&&(s+=O.rightMargin),a.push({trueIndex:l,pinNumber:j,side:"top",distanceFromOrthogonalEdge:s}),O!=null&&O.leftMargin&&(s+=O.leftMargin),G===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 u=r.pinLabels?Math.max(...Object.values(r.pinLabels).map(G=>G.length*.1)):0,A=u>0?1.1:0;c=Math.max(c,u+A);let d=r.schHeight;d||(d=Math.max(n.left+r.schPinSpacing*2,n.right+r.schPinSpacing*2));const f={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}},p={left:{x:0,y:-1},right:{x:0,y:1},top:{x:-1,y:0},bottom:{x:1,y:0}},C=a.map(G=>{const{distanceFromOrthogonalEdge:j,side:O}=G,ne=f[O],te=p[O];return{x:ne.x+j*te.x,y:ne.y+j*te.y,...G}});return{getPortPositionByPinNumber(G){const j=C.find(O=>O.pinNumber.toString()===G.toString());return j||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}},iht=l0("tscircuit:core:footprint"),oht=class extends nI{get config(){return{componentName:"Footprint",zodProps:KV}}doInitialPcbFootprintLayout(){var d,f,p,C,v;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:b,edge:T})=>({component:_,selector:x,componentSelector:b,edge:T,bounds:_._getPcbCircuitJsonBounds()}));if(i.some(_=>_.edge))throw new Error("edge constraints not implemented yet for footprint layout, contributions welcome!");function o(_){return i.find(({selector:x})=>x===_)}const a=new mK,s={};function l(_){return _ in s||(s[_]=new hR(_),a.addEditVariable(s[_],cy.weak)),s[_]}for(const{selector:_,bounds:x}of i){const b=l(`${_}_x`),T=l(`${_}_y`);a.suggestValue(b,x.center.x),a.suggestValue(T,x.center.y)}for(const _ of e){const x=_._parsedProps;if("xDist"in x){const{xDist:b,left:T,right:F,edgeToEdge:U,centerToCenter:H}=n(x),G=l(`${T}_x`),j=l(`${F}_x`),O=(f=o(T))==null?void 0:f.bounds,ne=(p=o(F))==null?void 0:p.bounds;if(H){const te=new Pm(j,[-1,G]);a.addConstraint(new k1(te,EI.Eq,x.xDist,cy.required))}else if(U){const te=new Pm(j,-ne.width/2,[-1,G],-O.width/2);a.addConstraint(new k1(te,EI.Eq,x.xDist,cy.required))}}else if("yDist"in x){const{yDist:b,top:T,bottom:F,edgeToEdge:U,centerToCenter:H}=x,G=l(`${T}_y`),j=l(`${F}_y`),O=(C=o(T))==null?void 0:C.bounds,ne=(v=o(F))==null?void 0:v.bounds;if(H){const te=new Pm(G,[-1,j]);a.addConstraint(new k1(te,EI.Eq,x.yDist,cy.required))}else if(U){const te=new Pm(G,O.height/2,[-1,j],-ne.height/2);a.addConstraint(new k1(te,EI.Eq,x.yDist,cy.required))}}else if("sameY"in x){const{for:b}=x;if(b.length<2)continue;const T=b.map(U=>l(`${U}_y`)),F=new Pm(...T.slice(1));a.addConstraint(new k1(F,EI.Eq,T[0],cy.required))}else if("sameX"in x){const{for:b}=x;if(b.length<2)continue;const T=b.map(U=>l(`${U}_x`)),F=new Pm(...T.slice(1));a.addConstraint(new k1(F,EI.Eq,T[0],cy.required))}}a.updateVariables(),iht.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:b}}of i){const T=l(`${_}_x`),F=l(`${_}_y`),U=T.value()-x/2,H=T.value()+x/2,G=F.value()+b/2,j=F.value()-b/2;c.left=Math.min(c.left,U),c.right=Math.max(c.right,H),c.top=Math.max(c.top,G),c.bottom=Math.min(c.bottom,j)}const u={x:-(c.right+c.left)/2,y:-(c.top+c.bottom)/2},A=this.getPrimitiveContainer()._getGlobalPcbPositionBeforeLayout();u.x+=A.x,u.y+=A.y;for(const{component:_,selector:x}of i){const b=l(`${x}_x`),T=l(`${x}_y`);_._setPositionFromLayout({x:b.value()+u.x,y:T.value()+u.y})}}},aht=(r,e)=>{if(!r)return;const t={};for(const[n,i]of Object.entries(r)){const o=MR(n,e),a={leftMargin:i.marginLeft??i.leftMargin,rightMargin:i.marginRight??i.rightMargin,topMargin:i.marginTop??i.topMargin,bottomMargin:i.marginBottom??i.bottomMargin};t[`pin${o}`]={...t[`pin${o}`],...a}}return t},_ve=class{constructor({input:e}){Le(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,o={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(o)}return e}},sht=r=>{const e=Math.min(...r.map(o=>o.center.x)),t=Math.max(...r.map(o=>o.center.x)),n=Math.min(...r.map(o=>o.center.y)),i=Math.max(...r.map(o=>o.center.y));return{minX:e,maxX:t,minY:n,maxY:i}},Eve=["top","bottom","inner1","inner2"],Ek=(r,e=[])=>{var s;const t=[];if(e.length===0){const l=r[0].layers;for(const c of l)t.push(...Ek(r.slice(1),[c]));return t}if(r.length===0)return[];const n=r[0],i=n.via||n.optional_via,o=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(o)?[{layer_path:[...e,o]}]:[]}if(!i)return n.layers&&!n.layers.includes(o)?[]:Ek(r.slice(1),e.concat([o]));const a=(n.optional_via?Eve:Eve.filter(l=>l!==o)).filter(l=>{var c;return!n.layers||((c=n.layers)==null?void 0:c.includes(l))});for(const l of a)t.push(...Ek(r.slice(1),e.concat(l)));return t};function xve(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 MM(r,e){return Math.hypot(r.x-e.x,r.y-e.y)}var lht=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],o=r[1][r[1].length-1],a=Math.min(MM(t,i),MM(t,o)),s=Math.min(MM(n,i),MM(n,o));a<s?e.push(...r[0].reverse()):e.push(...r[0]);for(let l=1;l<r.length;l++){const c=e[e.length-1],u=r[l],A=u[0],d=u[u.length-1],f=MM(c,A),p=MM(c,d);f<p?e.push(...u):e.push(...u.reverse())}for(let l=1;l<e.length-1;l++){const c=e[l-1],u=e[l];c.route_type==="wire"&&u.route_type==="wire"&&c.layer!==u.layer&&e.splice(l,0,{x:c.x,y:c.y,from_layer:c.layer,to_layer:u.layer,route_type:"via"})}return e},cht=(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 uht(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 o=cht(r,i);o<n&&(t=i,n=o)}return t}var Aht=(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],o=e[n],a=Math.abs(i.from.x-i.to.x)<.01,s=Math.abs(o.from.x-o.to.x)<.01;a!==s&&t++}return t},yj=r=>({up:"bottom",down:"top",left:"right",right:"left"})[r]??null,vj=({firstEdge:r,firstEdgePort:e,firstDominantDirection:t,lastEdge:n,lastEdgePort:i,lastDominantDirection:o})=>{if(r&&e)return vj({lastEdge:{from:r.to,to:r.from},lastEdgePort:e,lastDominantDirection:t}).reverse().map(s=>({from:s.to,to:s.from}));let a=[];if(n&&i){const s={x:n.to.x,y:n.to.y};o==="left"||o==="right"?(s.x=i.position.x,a.push({from:n.to,to:{...s}}),a.push({from:s,to:{...i.position}})):(s.y=i.position.y,a.push({from:n.to,to:{...s}}),a.push({from:s,to:{...i.position}}))}return a=a.filter(s=>Cx(s.from,s.to)>.01),a};function dht(r){try{return[r(),null]}catch(e){return[null,e]}}function fht(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 o=i.x-n.x,a=i.y-n.y;e+=Math.sqrt(o*o+a*a)}}else n.route_type==="via"&&(e+=1.6)}return e}var hht=r=>{var s,l;const e={left:{x:-.5,y:0},up:{x:.5,y:.5},right:{x:.5,y:0},down:{x:0,y:-.5}}[r.facingDirection],t=(s=r.parent)!=null&&s.config.shouldRenderAsSchematicBox?3:1,n=(l=r.parent)!=null&&l.config.shouldRenderAsSchematicBox&&(r.facingDirection==="left"||r.facingDirection==="right")?3:1,i=e.x,o=e.y,a=r.facingDirection==="up"?.5:0;return{schBoxVertOffset:t,schBoxHorzOffset:n,horzPortDirection:i,vertPortDirectionOffset:o,handleUp:a}},xk=({port:r,anchorPos:e,schDisplayLabel:t,source_trace_id:n},{db:i})=>{const o=hht(r),a=r.facingDirection==="left"||r.facingDirection==="right",s={x:e.x+o.horzPortDirection*o.schBoxHorzOffset,y:e.y+o.vertPortDirectionOffset*o.schBoxVertOffset},l=a?{x:s.x,y:s.y-.5}:s;i.schematic_net_label.insert({anchor_side:"top",center:l,source_net_id:r.source_port_id,text:t,anchor_position:l,symbol_name:"ground_horz"});const c=[{from:{x:e.x,y:e.y},to:{x:e.x,y:e.y+o.handleUp*o.schBoxVertOffset}},{from:{x:e.x,y:e.y},to:s}];a&&c.push({from:s,to:l}),i.schematic_trace.insert({edges:c,junctions:[],source_trace_id:n})},bk=({db:r,source_trace_id:e,sameNetOnly:t,differentNetOnly:n})=>{!t&&!n&&(n=!0);const i=r.source_trace.get(e),o=[];for(const a of r.schematic_trace.list()){if(a.source_trace_id===e)continue;const s=r.source_trace.get(a.source_trace_id),l=(s==null?void 0:s.subcircuit_connectivity_map_key)===i.subcircuit_connectivity_map_key;n&&l||t&&!l||o.push(a)}return o},bve=({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],o=Math.abs(i.from.x-i.to.x)<.01?"vertical":i.from.y===i.to.y?"horizontal":"not-orthogonal";if(o==="not-orthogonal")continue;const a=[];for(const C of e){const v=C.from.x===C.to.x?"vertical":C.from.y===C.to.y?"horizontal":"not-orthogonal";if(v==="not-orthogonal"||o===v)continue;if(yM([i.from,i.to],[C.from,C.to],{lineThickness:.01})){const x=o==="vertical"?i.from.x:C.from.x,b=o==="vertical"?C.from.y:i.from.y,T={x,y:b};a.push({otherEdge:C,crossingPoint:T,distanceFromEdgeFrom:Cx(i.from,T)})}}if(a.length===0)continue;let s=a[0];for(const C of a)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 u=yK(i.from,l),A={x:l.x-u.x*c/2,y:l.y-u.y*c/2},d={x:l.x+u.x*c/2,y:l.y+u.y*c/2},f=Cx(d,i.to)<c,p=[{from:i.from,to:A},{from:A,to:d,is_crossing:!0},{from:d,to:i.to}];t.splice(n,1,...p),n+=p.length-2,f&&n++}return t},pht=(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 u=r.from.x,A=(e.to.y-e.from.y)/(e.to.x-e.from.x),d=e.from.y-A*e.from.x,f=A*u+d;return u>=Math.min(e.from.x,e.to.x)&&u<=Math.max(e.from.x,e.to.x)&&f>=Math.min(e.from.y,e.to.y)&&f<=Math.max(e.from.y,e.to.y)?{x:u,y:f}:null}if(e.from.x===e.to.x){const u=e.from.x,A=(r.to.y-r.from.y)/(r.to.x-r.from.x),d=r.from.y-A*r.from.x,f=A*u+d;return u>=Math.min(r.from.x,r.to.x)&&u<=Math.max(r.from.x,r.to.x)&&f>=Math.min(r.from.y,r.to.y)&&f<=Math.max(r.from.y,r.to.y)?{x:u,y:f}: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),o=e.from.y-i*e.from.x;if(t===i)return null;const a=(o-n)/(t-i),s=t*a+n,l=a>=Math.min(r.from.x,r.to.x)&&a<=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=a>=Math.min(e.from.x,e.to.x)&&a<=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:a,y:s}:null},Bve=({edges:r,db:e,source_trace_id:t})=>{const n=bk({db:e,source_trace_id:t,sameNetOnly:!0}).flatMap(i=>i.edges);for(const i of r)for(const o of n){const a=pht(i,o);if(a)return`${a.x}${a.y}`,[{x:a.x,y:a.y}]}return[]},ght=(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 o=e.source_component.get(i.source_component_id);return(o==null?void 0:o.ftype)==="simple_capacitor"?o.max_decoupling_trace_length:null}).filter(n=>n!==null);if(t.length!==0)return Math.min(...t)};function mht(r){var o,a,s,l,c,u,A,d,f;let e=1/0,t=1/0,n=-1/0,i=-1/0;for(const p of r){let C,v,_,x;p.type==="schematic_component"?(C=(o=p.center)==null?void 0:o.x,v=(a=p.center)==null?void 0:a.y,_=(s=p.size)==null?void 0:s.width,x=(l=p.size)==null?void 0:l.height):p.type==="schematic_box"?(C=p.x,v=p.y,_=p.width,x=p.height):p.type==="schematic_port"?(C=(c=p.center)==null?void 0:c.x,v=(u=p.center)==null?void 0:u.y,_=.2,x=.2):p.type==="schematic_text"&&(C=(A=p.position)==null?void 0:A.x,v=(d=p.position)==null?void 0:d.y,_=(((f=p.text)==null?void 0:f.length)??0)*.1,x=.2),typeof C=="number"&&typeof v=="number"&&typeof _=="number"&&typeof x=="number"&&(e=Math.min(e,C-_/2),n=Math.max(n,C+_/2),t=Math.min(t,v-x/2),i=Math.max(i,v+x/2))}return{minX:e,maxX:n,minY:t,maxY:i}}function yht(r,e={}){const{minX:t,maxX:n,minY:i,maxY:o}=r,a=e.padding??1;if(!isFinite(t)||!isFinite(n)||!isFinite(i)||!isFinite(o))return[];const s=t-a,l=n+a,c=o+a,u=i-a,A=.01;return[{type:"rect",layers:["top"],center:{x:(s+l)/2,y:c},width:l-s,height:A,connectedTo:[]},{type:"rect",layers:["top"],center:{x:(s+l)/2,y:u},width:l-s,height:A,connectedTo:[]},{type:"rect",layers:["top"],center:{x:s,y:(c+u)/2},width:A,height:c-u,connectedTo:[]},{type:"rect",layers:["top"],center:{x:l,y:(c+u)/2},width:A,height:c-u,connectedTo:[]}]}var vht=r=>{var a;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?vK(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:(((a=s.text)==null?void 0:a.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 o=mht(e.toArray());return i.push(...yht(o,{padding:1})),i};function Iht({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 Cht=({edges:r,db:e,source_trace_id:t})=>{e.source_trace.get(t);const n=bk({db:e,source_trace_id:t,differentNetOnly:!0}).flatMap(o=>o.edges),i=o=>{const{from:a,to:s}=o;return a.x===s.x?"vertical":"horizontal"};for(const o of r){const a=i(o),s=()=>n.find(c=>i(c)===a&&yM([o.from,o.to],[c.from,c.to],{lineThickness:.05}));let l=s();for(;l;)a==="horizontal"?(o.from.y+=.1,o.to.y+=.1):(o.from.x+=.1,o.to.x+=.1),l=s()}},_ht=(r,{db:e})=>{const t=e.pcb_board.list()[0];if(t.outline){const l=t.outline,c=(u,A)=>{let d=!1;for(let f=0,p=A.length-1;f<A.length;p=f++){const C=A[f].x,v=A[f].y,_=A[p].x,x=A[p].y;v>u.y!=x>u.y&&u.x<(_-C)*(u.y-v)/(x-v)+C&&(d=!d)}return d};return r.some(u=>!c(u,l))}const n=t.width,i=t.height,o=t.center.x,a=t.center.y;return r.some(l=>l.x<o-n/2||l.y<a-i/2||l.x>o+n/2||l.y>a+i/2)},Bk=r=>({...r._getGlobalPcbPositionAfterLayout(),layers:r.getAvailablePcbLayers()}),VS=class extends nI{constructor(t){super(t);Le(this,"source_trace_id",null);Le(this,"pcb_trace_id",null);Le(this,"schematic_trace_id",null);Le(this,"_portsRoutedOnPcb");Le(this,"subcircuit_connectivity_map_key",null);Le(this,"_traceConnectionHash",null);this._portsRoutedOnPcb=[]}get config(){return{zodProps:VV,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 a=this.getTracePortPathSelectors().map(s=>({selector:s,port:this.getSubcircuit().selectOne(s,{type:"port"})??null}));for(const{selector:s,port:l}of a)if(!l){const c=s.replace(/(\> )?[^ ]+$/,""),u=this.getSubcircuit().selectOne(c);u?this.renderError(`Could not find port for selector "${s}" (did you forget to include the pin name?)
|
|
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){Uft(`${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 jx)this.runRenderPhaseForChildren(e),this.runRenderPhase(e)}runRenderPhase(e){var a,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"),(a=this==null?void 0:this[`remove${e}`])==null||a.call(this),t.initialized=!1,t.dirty=!1,this._emitRenderLifecycleEvent(e,"end");return}const o=jx.indexOf(e)-1;if(o>=0){const c=jx[o];if(this._asyncEffects.filter(A=>A.phase===c).some(A=>!A.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))}},_k={},cve=r=>{const e=Object.fromEntries(Object.entries(r).map(([t,n])=>[t.toLowerCase(),n]));Object.assign(_k,r),Object.assign(_k,e)},Lft=class extends Error{constructor(e,t,n){let i;const a=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}": ${a}`:"footprint"in t&&typeof t.footprint=="string"?i=`Invalid props for ${e} (unnamed ${t.footprint} component): ${a}`:i=`Invalid props for ${e} (unnamed): ${a}`,super(i),this.componentName=e,this.originalProps=t,this.formattedError=n}};function uj(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,...o]=e.split(/(?=[#.[])/);return i==="pin"&&(i="port"),i&&i!=="*"&&r.lowercaseComponentName!==i.toLowerCase()?!1:o.every(a=>{if(a.startsWith("#"))return r.props.id===a.slice(1);if(a.startsWith("."))return r.isMatchingNameOrAlias(a.slice(1));const s=a.match(/\[(\w+)=['"]?(.+?)['"]?\]/);if(!s)return!0;const[,l,c]=s;return r.props[l].toString()===c})}var Aj={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 o of i.children)n(o)};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=Aj.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},Gft={...Aj,getChildren:r=>r.children.filter(e=>!e.isSubcircuit)},uve={...Aj,getChildren:r=>r.children.filter(e=>e.isSubcircuit)},Ave=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 o=/^\d+$/.test(i)?`pin${i}`:i;return`${t}.${n} > .${o}`}).trim()},dj={adapter:Gft,cacheResults:!0},nI=class extends lve{constructor(t){super(t);Le(this,"parent",null);Le(this,"children");Le(this,"childrenPendingRemoval");Le(this,"props");Le(this,"_parsedProps");Le(this,"externallyAddedAliases");Le(this,"isPrimitiveContainer",!1);Le(this,"source_group_id",null);Le(this,"source_component_id",null);Le(this,"schematic_component_id",null);Le(this,"pcb_component_id",null);Le(this,"cad_component_id",null);Le(this,"_cachedSelectAllQueries",new Map);Le(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 Lft(this.lowercaseComponentName,this.props,n.error.format())}get config(){return{componentName:"",zodProps:Xt({}).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 o,a;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)}),(a=(o=this.parent)==null?void 0:o.onChildChanged)==null||a.call(o,this)}computePcbPropsTransform(){const{_parsedProps:t}=this;return Qc(QA(t.pcbX??0,t.pcbY??0),IE((t.pcbRotation??0)*Math.PI/180))}_computePcbGlobalTransformBeforeLayout(){var i,o,a;const{_parsedProps:t}=this,n=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if(n&&this.props.pcbX===void 0&&this.props.pcbY===void 0)return Qc(((i=this.parent)==null?void 0:i._computePcbGlobalTransformBeforeLayout())??c0(),Qc(QA(n.x,n.y),IE((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 Qc(QA(c.x,c.y),iQ(),QA(-c.x,-c.y)),Qc(((o=this.parent)==null?void 0:o._computePcbGlobalTransformBeforeLayout())??c0(),iQ(),this.computePcbPropsTransform())}}return Qc(((a=this.parent)==null?void 0:a._computePcbGlobalTransformBeforeLayout())??c0(),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:o=>n?o==="top"?"bottom":"top":o}}_setPositionFromLayout(t){throw new Error(`_setPositionFromLayout not implemented for ${this.componentName}`)}computeSchematicPropsTransform(){const{_parsedProps:t}=this;return Qc(QA(t.schX??0,t.schY??0))}computeSchematicGlobalTransform(){var n,i;const t=this._getSchematicGlobalManualPlacementTransform(this);return t||Qc(((i=(n=this.parent)==null?void 0:n.computeSchematicGlobalTransform)==null?void 0:i.call(n))??c0(),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 o=`${n}_horz`,a=`${n}_vert`,s=`${n}_up`,l=`${n}_down`,c=`${n}_left`,u=`${n}_right`;if(u in A0&&i===0)return u;if(s in A0&&i===90)return s;if(c in A0&&i===180)return c;if(l in A0&&i===270)return l;if(o in A0&&(i===0||i===180))return o;if(a in A0&&(i===90||i===270))return a;if(n in A0)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?A0[t]??null:null}_getPcbManualPlacementForComponent(t){var a;if(!this.isSubcircuit)return null;const n=this.props.layout,i=this.props.manualEdits;if(!n&&!i)return null;const o=((a=n==null?void 0:n.manual_pcb_placement_config)==null?void 0:a.positions)||(i==null?void 0:i.pcb_placements);if(!o)return null;for(const s of o)if(n&&uj(t,s.selector)||t.props.name===s.selector)return Wr(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 o of i)if(uj(t,o.selector)||t.props.name===o.selector)return Wr(this.computeSchematicGlobalTransform(),o.center);return null}_getSchematicGlobalManualPlacementTransform(t){var i,o;const n=(i=this.getSubcircuit())==null?void 0:i._parsedProps.manualEdits;if(!n)return null;for(const a of n.schematic_placements??[])if((uj(t,a.selector)||t.props.name===a.selector)&&a.relative_to==="group_center")return Qc(((o=this.parent)==null?void 0:o._computePcbGlobalTransformBeforeLayout())??c0(),QA(a.center.x,a.center.y));return null}_getGlobalPcbPositionBeforeLayout(){return Wr(this._computePcbGlobalTransformBeforeLayout(),{x:0,y:0})}_getGlobalSchematicPositionBeforeLayout(){return Wr(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 o,a;const t=this._parsedProps.name,n=t?`${this.lowercaseComponentName}.${t}`:this.lowercaseComponentName,i=(a=(o=this.parent)==null?void 0:o.getFullPathSelector)==null?void 0:a.call(o);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),o=t.trim().split(/\> /)[0],a=o[0];return o.length>1?!1:!!(t==="*"||t[0]==="#"&&t.slice(1)===this.props.id||t[0]==="."&&i.includes(t.slice(1))||/^[a-zA-Z0-9_]/.test(a)&&n.includes(a))}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 o=(n=i.parent)==null?void 0:n.getNameAndAliases(),a=i.getNameAndAliases();if(o)for(const s of o)for(const l of a){const c=[`.${s} > .${l}`,`.${s} .${l}`];for(const u of c){const A=this._cachedSelectAllQueries.get(u);A?A.push(i):this._cachedSelectAllQueries.set(u,[i])}}}for(const[i,o]of this._cachedSelectAllQueries.entries())o.length===1&&this._cachedSelectOneQueries.set(i,o[0])}selectAll(t){if(this._cachedSelectAllQueries.has(t))return this._cachedSelectAllQueries.get(t);const n=Ave(t),i=fM(n,this,dj);if(i.length>0)return this._cachedSelectAllQueries.set(t,i),i;const[o,...a]=n.split(" "),s=zS(o,this,{adapter:uve});if(!s)return[];const l=s.selectAll(a.join(" "));return this._cachedSelectAllQueries.set(t,l),l}selectOne(t,n){if(this._cachedSelectOneQueries.has(t))return this._cachedSelectOneQueries.get(t);const i=Ave(t);n!=null&&n.port&&(n.type="port");let o=null;if(n!=null&&n.type&&(o=fM(i,this,dj).find(u=>u.lowercaseComponentName===n.type)),o??(o=zS(i,this,dj)),o)return this._cachedSelectOneQueries.set(t,o),o;const[a,...s]=i.split(" "),l=zS(a,this,{adapter:uve});return l?(o=l.selectOne(s.join(" "),n),this._cachedSelectOneQueries.set(t,o),o):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 o,a;const{lowercaseComponentName:t,_parsedProps:n,parent:i}=this;return(n==null?void 0:n.pinNumber)!==void 0&&((o=i==null?void 0:i.props)!=null&&o.name)&&(n!=null&&n.name)?`<${t}#${this._renderId}(pin:${n.pinNumber} .${i==null?void 0:i.props.name}>.${n.name}) />`:(a=i==null?void 0:i.props)!=null&&a.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()}},Oft=class extends nI{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:Xt({}).passthrough()}}doInitialSourceRender(){var e,t,n,i;if((e=this.root)!=null&&e.db){const o=this._getGlobalPcbPositionBeforeLayout(),a=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:o,schematic_center:a})}}};function zft(r,e){return new Oft(r,e)}function Hft(r,e){const t=r;return t.__tsci={...e},r}var dve={supportsMutation:!0,createInstance(r,e){const t=_k[r];if(!t)throw Object.keys(_k).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 Hft(new t(e),{})}catch(n){return zft(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:()=>GS.DefaultEventPriority,getCurrentUpdatePriority:()=>GS.DefaultEventPriority,resolveUpdatePriority:()=>GS.DefaultEventPriority,setCurrentUpdatePriority:()=>{},maySuspendCommit:()=>!1,supportsHydration:!1},dQ;_u.version.startsWith("19.")?dQ=cz(dve):dQ=dz(dve);var Yft=r=>{const e={children:[],props:{name:"$root"},add(o){o.parent=this,this.children.push(o)},computePcbGlobalTransform(){return c0()}},t=[],n=dQ.createContainer(e,0,null,!1,null,"tsci",o=>{console.log("Error in createContainer"),console.error(o),t.push(o)},null);if(_u.version.startsWith("19.")?(dQ.updateContainerSync(r,n,null,()=>{}),dQ.flushSyncWork()):dQ.updateContainer(r,n,null,()=>{}),t.length>0)throw t[0];const i=dQ.getPublicRootInstance(n);return i||e.children[0]},MR=(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}"`)},Vft=(r,e)=>{if(!r)return;const t={},n={};for(const[i,o]of Object.entries(r)){const a=MR(i,e);n[a]={...n[a],...o}}for(const[i,o]of Object.entries(n)){const a=`pin${i}`;t[a]={bottom_margin:o.bottomMargin,left_margin:o.leftMargin,right_margin:o.rightMargin,top_margin:o.topMargin}}return t},Kft=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 fve(r){const e=[];for(let t=0;t<r.length-1;t++)e.push([r[t],r[t+1]]);return e}var jft=Xt({name:Be()}),hve=class extends nI{constructor(){super(...arguments);Le(this,"source_net_id")}get config(){return{componentName:"Net",zodProps:jft}}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 o=i._getDirectlyConnectedTraces();for(const a of o)if(a._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}),o=[];for(const l of i){const c=l._portsRoutedOnPcb,u=o.find(A=>c.some(d=>A.ports.includes(d)));if(!u){o.push({ports:[...c],traces:[l]});continue}u.traces.push(l),u.ports.push(...c)}if(o.length===0)return;const a=fve(o);for(const[l,c]of a){const u=l.ports.map(b=>b._getGlobalPcbPositionBeforeLayout()),A=c.ports.map(b=>b._getGlobalPcbPositionBeforeLayout());let d=1/0,f=[-1,-1];for(let b=0;b<u.length;b++){const T=u[b];for(let F=0;F<A.length;F++){const U=A[F],H=Math.sqrt((T.x-U.x)**2+(T.y-U.y)**2);H<d&&(d=H,f=[b,F])}}const p=l.ports[f[0]],C=c.ports[f[1]],v=t.toArray().filter(b=>b.type==="pcb_smtpad"||b.type==="pcb_trace"||b.type==="pcb_plated_hole"||b.type==="pcb_hole"||b.type==="source_port"||b.type==="pcb_port"),{solution:_}=wV(v.concat([{type:"source_trace",source_trace_id:"__net_trace_tmp",connected_source_port_ids:[p.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:[p.pcb_component_id,C.pcb_component_id].filter(Boolean),pcb_port_ids:[p.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)}},pve=(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 hve({name:t.split("net.")[1]});n.add(i)}}},fj=class extends nI{constructor(){super(...arguments);Le(this,"pcb_smtpad_id",null);Le(this,"matchedPort",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SmtPad",zodProps:zV}}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 f,p,C,v,_,x,b,T,F,U;if((f=this.root)!=null&&f.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this;if(!n.portHints)return;const i=this.getPrimitiveContainer(),o=this.getSubcircuit(),a=this._getGlobalPcbPositionBeforeLayout();i==null||i._getGlobalPcbPositionBeforeLayout();const s=OS(this._computePcbGlobalTransformBeforeLayout()),l=Math.abs(s.rotation.angle*(180/Math.PI)-90)%180<.01,{maybeFlipLayer:c}=this._getPcbPrimitiveFlippedHelpers(),u=(i==null?void 0:i._parsedProps.pcbRotation)??0;let A=null;const d=((p=this.parent)==null?void 0:p.pcb_component_id)??((C=this.getPrimitiveContainer())==null?void 0:C.pcb_component_id);n.shape==="circle"?(A=t.pcb_smtpad.insert({pcb_component_id:d,pcb_port_id:(v=this.matchedPort)==null?void 0:v.pcb_port_id,layer:c(n.layer??"top"),shape:"circle",radius:n.radius,port_hints:n.portHints.map(H=>H.toString()),x:a.x,y:a.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0}),t.pcb_solder_paste.insert({layer:A.layer,shape:"circle",radius:A.radius*.7,x:A.x,y:A.y,pcb_component_id:A.pcb_component_id,pcb_smtpad_id:A.pcb_smtpad_id,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((_=this.getGroup())==null?void 0:_.pcb_group_id)??void 0})):n.shape==="rect"&&(A=u===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(H=>H.toString()),x:a.x,y:a.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((b=this.getGroup())==null?void 0:b.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:a.x,y:a.y,ccw_rotation:u,port_hints:n.portHints.map(H=>H.toString()),subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((T=this.getGroup())==null?void 0:T.pcb_group_id)??void 0}),A.shape==="rect"&&t.pcb_solder_paste.insert({layer:c(n.layer??"top"),shape:"rect",width:A.width*.7,height:A.height*.7,x:A.x,y:A.y,pcb_component_id:A.pcb_component_id,pcb_smtpad_id:A.pcb_smtpad_id,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((F=this.getGroup())==null?void 0:F.pcb_group_id)??void 0}),A.shape==="rotated_rect"&&t.pcb_solder_paste.insert({layer:c(n.layer??"top"),shape:"rotated_rect",width:A.width*.7,height:A.height*.7,x:A.x,y:A.y,ccw_rotation:u,pcb_component_id:A.pcb_component_id,pcb_smtpad_id:A.pcb_smtpad_id,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})),A&&(this.pcb_smtpad_id=A.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,o=Math.cos(i),a=Math.sin(i),s=n.width/2,l=n.height/2,c=Math.abs(s*o)+Math.abs(l*a),u=Math.abs(s*a)+Math.abs(l*o);return{center:{x:n.x,y:n.y},bounds:{left:n.x-c,right:n.x+c,top:n.y-u,bottom:n.y+u},width:c*2,height:u*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 o;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(a=>a.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}),(o=this.matchedPort)==null||o._setPositionFromLayout(t)}},gve=class extends nI{constructor(){super(...arguments);Le(this,"pcb_silkscreen_path_id",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenPath",zodProps:AK}}doInitialPcbPrimitiveRender(){var c,u,A;if((c=this.root)!=null&&c.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),o=i(n.layer??"top");if(o!=="top"&&o!=="bottom")throw new Error(`Invalid layer "${o}" for SilkscreenPath. Must be "top" or "bottom".`);const a=this._computePcbGlobalTransformBeforeLayout(),s=this.getSubcircuit(),l=t.pcb_silkscreen_path.insert({pcb_component_id:(u=this.parent)==null?void 0:u.pcb_component_id,layer:o,route:n.route.map(d=>{const f=Wr(a,{x:d.x,y:d.y});return{...d,x:f.x,y:f.y}}),stroke_width:n.strokeWidth??.1,subcircuit_id:(s==null?void 0:s.subcircuit_id)??void 0,pcb_group_id:((A=this.getGroup())==null?void 0:A.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,o=1/0,a=-1/0;for(const s of t.route)n=Math.min(n,s.x),i=Math.max(i,s.x),o=Math.min(o,s.y),a=Math.max(a,s.y);return{width:i-n,height:a-o}}},Jft=Xt({route:hi(nR),source_trace_id:Be().optional()}),mve=class extends nI{constructor(){super(...arguments);Le(this,"pcb_trace_id",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbTrace",zodProps:Jft}}doInitialPcbPrimitiveRender(){var u,A;if((u=this.root)!=null&&u.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getPrimitiveContainer(),o=this.getSubcircuit(),{maybeFlipLayer:a}=this._getPcbPrimitiveFlippedHelpers(),s=this._computePcbGlobalTransformBeforeLayout(),l=n.route.map(d=>{const{x:f,y:p,...C}=d,v=Wr(s,{x:f,y:p});return d.route_type==="wire"&&d.layer?{...v,...C,layer:a(d.layer)}:{...v,...C}}),c=t.pcb_trace.insert({pcb_component_id:i.pcb_component_id,source_trace_id:n.source_trace_id,route:l,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});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,o=1/0,a=-1/0;for(const s of t.route)n=Math.min(n,s.x),i=Math.max(i,s.x),o=Math.min(o,s.y),a=Math.max(a,s.y),s.route_type==="wire"&&(n=Math.min(n,s.x-s.width/2),i=Math.max(i,s.x+s.width/2),o=Math.min(o,s.y-s.width/2),a=Math.max(a,s.y+s.width/2));return n===1/0||i===-1/0||o===1/0||a===-1/0?{width:0,height:0}:{width:i-n,height:a-o}}},hj=class extends nI{constructor(){super(...arguments);Le(this,"pcb_plated_hole_id",null);Le(this,"matchedPort",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PlatedHole",zodProps:TV}}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,u,A,d,f,p,C,v,_,x,b,T,F;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalPcbPositionBeforeLayout(),o=((l=this.parent)==null?void 0:l.pcb_component_id)??((c=this.getPrimitiveContainer())==null?void 0:c.pcb_component_id),a=this.getSubcircuit();if(n.shape==="circle"){const U=t.pcb_plated_hole.insert({pcb_component_id:o,pcb_port_id:(u=this.matchedPort)==null?void 0:u.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:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((A=this.getGroup())==null?void 0:A.pcb_group_id)??void 0});this.pcb_plated_hole_id=U.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:(a==null?void 0:a.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:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((f=this.getGroup())==null?void 0:f.pcb_group_id)??void 0})}else if(n.shape==="pill"||n.shape==="oval"){const U=t.pcb_plated_hole.insert({pcb_component_id:o,pcb_port_id:(p=this.matchedPort)==null?void 0:p.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:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((C=this.getGroup())==null?void 0:C.pcb_group_id)??void 0});this.pcb_plated_hole_id=U.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:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((v=this.getGroup())==null?void 0:v.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:(a==null?void 0:a.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 U=t.pcb_plated_hole.insert({pcb_component_id:o,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:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((b=this.getGroup())==null?void 0:b.pcb_group_id)??void 0});this.pcb_plated_hole_id=U.pcb_plated_hole_id}else if(n.shape==="pill_hole_with_rect_pad"){const U=t.pcb_plated_hole.insert({pcb_component_id:o,pcb_port_id:(T=this.matchedPort)==null?void 0:T.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:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((F=this.getGroup())==null?void 0:F.pcb_group_id)??void 0});this.pcb_plated_hole_id=U.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})}},pj=class extends nI{constructor(){super(...arguments);Le(this,"pcb_keepout_id",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Keepout",zodProps:aK}}doInitialPcbPrimitiveRender(){var c,u,A;if((c=this.root)!=null&&c.pcbDisabled)return;const t=this.getSubcircuit(),{db:n}=this.root,{_parsedProps:i}=this,o=this._getGlobalPcbPositionBeforeLayout(),a=OS(this._computePcbGlobalTransformBeforeLayout()),s=Math.abs(a.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:o.x,y:o.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}):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:o.x,y:o.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})),l&&(this.pcb_keepout_id=l.pcb_keepout_id)}},yve=class extends nI{constructor(){super(...arguments);Le(this,"pcb_hole_id",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Hole",zodProps:HV}}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(),o=this._getGlobalPcbPositionBeforeLayout(),a=t.pcb_hole.insert({hole_shape:"circle",hole_diameter:n.diameter,x:o.x,y:o.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=a.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})}},gj=class extends nI{constructor(){super(...arguments);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenText",zodProps:uK}}doInitialPcbPrimitiveRender(){var l,c;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getPrimitiveContainer(),o=this._getGlobalPcbPositionBeforeLayout(),{maybeFlipLayer:a}=this._getPcbPrimitiveFlippedHelpers(),s=this.getSubcircuit();t.pcb_silkscreen_text.insert({anchor_alignment:n.anchorAlignment,anchor_position:{x:o.x,y:o.y},font:n.font??"tscircuit2024",font_size:n.fontSize??1,layer:a(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,o=(t.text??"").length*n,a=n;return{width:o*n,height:a*n}}},Wft=({elm:r,pinLabels:e,readableRotation:t,anchorAlignment:n})=>{var a;const i=r.text.replace(/[{}]/g,"").toLowerCase();let o=i;if(Array.isArray(e)){const s=parseInt(i.replace(/[^\d]/g,""),10)-1;o=e[s]??i}else typeof e=="object"&&(o=((a=e[i])==null?void 0:a[0])??i);return new gj({anchorAlignment:n||"center",text:o??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})},qft=(r,e)=>((-parseInt(r||"0",10)+(e??0))%360+360)%360,vve=({componentName:r,componentRotation:e,footprint:t,pinLabels:n},i)=>{const o=[];for(const a of i)if(a.type==="pcb_smtpad"&&a.shape==="rect")o.push(new fj({pcbX:a.x,pcbY:a.y,layer:a.layer,shape:"rect",height:a.height,width:a.width,portHints:a.port_hints}));else if(a.type==="pcb_smtpad"&&a.shape==="circle")o.push(new fj({pcbX:a.x,pcbY:a.y,layer:a.layer,shape:"circle",radius:a.radius,portHints:a.port_hints}));else if(a.type==="pcb_silkscreen_path")o.push(new gve({layer:a.layer,route:a.route,strokeWidth:a.stroke_width}));else if(a.type==="pcb_plated_hole")a.shape==="circle"?o.push(new hj({pcbX:a.x,pcbY:a.y,shape:"circle",holeDiameter:a.hole_diameter,outerDiameter:a.outer_diameter,portHints:a.port_hints})):a.shape==="circular_hole_with_rect_pad"&&o.push(new hj({pcbX:a.x,pcbY:a.y,shape:"circular_hole_with_rect_pad",holeDiameter:a.hole_diameter,rectPadHeight:a.rect_pad_height,rectPadWidth:a.rect_pad_width,portHints:a.port_hints}));else if(a.type==="pcb_keepout"&&a.shape==="circle")o.push(new pj({pcbX:a.center.x,pcbY:a.center.y,shape:"circle",radius:a.radius}));else if(a.type==="pcb_keepout"&&a.shape==="rect")o.push(new pj({pcbX:a.center.x,pcbY:a.center.y,shape:"rect",width:a.width,height:a.height}));else if(a.type==="pcb_hole"&&a.hole_shape==="circle")o.push(new yve({pcbX:a.x,pcbY:a.y,diameter:a.hole_diameter}));else if(a.type==="pcb_silkscreen_text"){const s=qft(e,a.ccw_rotation);t.includes("pinrow")&&a.text.includes("PIN")?o.push(Wft({elm:a,pinLabels:n,readableRotation:s,anchorAlignment:a.anchor_alignment})):o.push(new gj({anchorAlignment:a.anchor_alignment||"center",text:r,fontSize:a.font_size+.2,pcbX:isNaN(a.anchor_position.x)?0:a.anchor_position.x,pcbY:a.anchor_position.y,pcbRotation:s??0}))}else a.type==="pcb_trace"&&o.push(new mve({route:a.route}));return o};function mj(r){let e=1/0,t=1/0,n=-1/0,i=-1/0,o=!1;for(const l of r)if(l.isPcbPrimitive&&!l.componentName.startsWith("Silkscreen")){const{x:c,y:u}=l._getGlobalPcbPositionBeforeLayout(),{width:A,height:d}=l.getPcbSize();e=Math.min(e,c-A/2),t=Math.min(t,u-d/2),n=Math.max(n,c+A/2),i=Math.max(i,u+d/2),o=!0}else if(l.children.length>0){const c=mj(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),o=!0)}if(!o)return{minX:0,minY:0,maxX:0,maxY:0,width:0,height:0};let a=n-e,s=i-t;return a<0&&(a=0),s<0&&(s=0),{minX:e,minY:t,maxX:n,maxY:i,width:a,height:s}}function Zft(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 Xft=r=>{if(r.length<=1)return!0;const e=r.map(o=>{const a=o._getPcbCircuitJsonBounds();return{left:a.bounds.left,right:a.bounds.right,top:a.bounds.top,bottom:a.bounds.bottom}}),t=Array(e.length).fill(!1).map(()=>Array(e.length).fill(!1));for(let o=0;o<e.length;o++)for(let a=o+1;a<e.length;a++){const s=e[o],l=e[a];t[o][a]=t[a][o]=!(s.right<l.left||s.left>l.right||s.bottom>l.top||s.top<l.bottom)}const n=new Set,i=o=>{n.add(o);for(let a=0;a<e.length;a++)t[o][a]&&!n.has(a)&&i(a)};return i(0),n.size===e.length},$ft=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,o)=>i+o.x,0),n=e.reduce((i,o)=>i+o.y,0);return{x:t/e.length,y:n/e.length}},eht=Xt({name:Be().optional(),pinNumber:yn().optional(),aliases:hi(Be()).optional()}),YS=class extends nI{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);Le(this,"source_port_id",null);Le(this,"pcb_port_id",null);Le(this,"schematic_port_id",null);Le(this,"schematicSymbolPortDef",null);Le(this,"matchedComponents");Le(this,"facingDirection",null);Le(this,"originDescription",null);n.originDescription&&(this.originDescription=n.originDescription),this.matchedComponents=[]}get config(){return{componentName:"Port",zodProps:eht}}_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(o=>o===this))return i;return[]}_hasSchematicPort(){var i,o;if((i=this.parent)==null?void 0:i.getSchematicSymbol())return!!(this.schematicSymbolPortDef||this._getPortsInternallyConnectedToThisPort().some(s=>s.schematicSymbolPortDef));const n=(o=this==null?void 0:this.parent)==null?void 0:o._getSchematicBoxDimensions();return!!(n&&this.props.pinNumber!==void 0&&n.getPortPositionByPinNumber(this.props.pinNumber))}_getGlobalSchematicPositionBeforeLayout(){var i,o,a;const t=(i=this.parent)==null?void 0:i.getSchematicSymbol();if(t){let s=this.schematicSymbolPortDef;if(!s&&(s=((o=this._getPortsInternallyConnectedToThisPort().find(c=>c.schematicSymbolPortDef))==null?void 0:o.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=Qc(this.parent.computeSchematicGlobalTransform(),QA(-t.center.x,-t.center.y));return Wr(l,s)}const n=(a=this==null?void 0:this.parent)==null?void 0:a._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 Wr(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 a,s;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getNameAndAliases(),o=t.source_port.insert({name:n.name,pin_number:n.pinNumber,port_hints:i,source_component_id:(a=this.parent)==null?void 0:a.source_component_id,subcircuit_id:(s=this.getSubcircuit())==null?void 0:s.subcircuit_id});this.source_port_id=o.source_port_id}doInitialSourceParentAttachment(){var n,i,o,a,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:(o=this.parent)==null?void 0:o.source_component_id,subcircuit_id:(a=this.getSubcircuit())==null?void 0:a.subcircuit_id}),this.source_component_id=(s=this.parent)==null?void 0:s.source_component_id}doInitialPcbPortRender(){var a,s,l,c,u;if((a=this.root)!=null&&a.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(A=>A.isPcbPrimitive);if(i.length===0)return;let o=null;if(i.length===1&&(o=i[0]._getPcbCircuitJsonBounds().center),i.length>1){if(!Xft(i))throw new Error(`${this.getString()} has multiple non-overlapping pcb matches, unclear how to place pcb_port: ${i.map(A=>A.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)`);o=$ft(i)}if(o){const A=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:(A==null?void 0:A.subcircuit_id)??void 0,pcb_group_id:((u=this.getGroup())==null?void 0:u.pcb_group_id)??void 0,...o,source_port_id:this.source_port_id});this.pcb_port_id=d.pcb_port_id}else{const A=i[0];throw new Error(`${A.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 o=i._getGlobalSchematicPositionBeforeLayout(),a=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:a,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=Zft(o,a);const c=t.source_port.get(this.source_port_id);let u;for(const f of(c==null?void 0:c.port_hints)??[])f.match(/^(pin)?\d+$/)||f.match(/^(left|right)/)&&!(c!=null&&c.name.match(/^(left|right)/))||(u=f);const A=t.schematic_port.insert({schematic_component_id:(d=this.parent)==null?void 0:d.schematic_component_id,center:a,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:u});this.schematic_port_id=A.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)}},Ive=r=>{const e=r.find(t=>/^(pin)?\d+$/.test(t));return e?Number.parseInt(e.replace(/^pin/,"")):null};function DR(r,e){var o;const t=Ive(r);if(!t)return null;const i=[...r.filter(a=>a.toString()!==t.toString()&&a!==`pin${t}`),...((o=e==null?void 0:e.additionalAliases)==null?void 0:o[`pin${t}`])??[]];return new YS({pinNumber:t,aliases:i})}var tht=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},nht=r=>{var o,a,s,l;if(tht(r))return{leftSize:((o=r.leftSide)==null?void 0:o.pins.length)??0,rightSize:((a=r.rightSide)==null?void 0:a.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 Cve(r){return r.leftSide!==void 0}var rht=r=>{var v,_,x,b,T,F,U,H;const e=r.portDistanceFromEdge??.4;let t=r.schPortArrangement?nht(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 G=Math.floor(i/2);t={leftSize:i-G,rightSize:G,topSize:0,bottomSize:0}}t||(t={leftSize:0,rightSize:0,topSize:0,bottomSize:0});const o=({side:G,sideIndex:j,truePinIndex:O})=>{var de,Ae,Ie,ge;if(!r.schPortArrangement||!Cve(r.schPortArrangement))return O+1;const ne={left:"top-to-bottom",bottom:"left-to-right",right:"bottom-to-top",top:"right-to-left"}[G],te=((Ae=(de=r.schPortArrangement)==null?void 0:de[`${G}Side`])==null?void 0:Ae.direction)??ne,ie=(ge=(Ie=r.schPortArrangement)==null?void 0:Ie[`${G}Side`])==null?void 0:ge.pins;let pe=j;return te!==ne&&(pe=ie.length-j-1),MR(ie[pe],r.pinLabels)},a=[];let s=0,l=0;for(let G=0;G<t.leftSize;G++){const j=o({side:"left",sideIndex:G,truePinIndex:l}),O=((v=r.numericSchPinStyle)==null?void 0:v[`pin${j}`])??((_=r.numericSchPinStyle)==null?void 0:_[j]);O!=null&&O.topMargin&&(s+=O.topMargin),a.push({trueIndex:l,pinNumber:j,side:"left",distanceFromOrthogonalEdge:s}),O!=null&&O.bottomMargin&&(s+=O.bottomMargin),G===t.leftSize-1?n.left=s:s+=r.schPinSpacing,l++}s=0;for(let G=0;G<t.bottomSize;G++){const j=o({side:"bottom",sideIndex:G,truePinIndex:l}),O=((x=r.numericSchPinStyle)==null?void 0:x[`pin${j}`])??((b=r.numericSchPinStyle)==null?void 0:b[j]);O!=null&&O.leftMargin&&(s+=O.leftMargin),a.push({trueIndex:l,pinNumber:j,side:"bottom",distanceFromOrthogonalEdge:s}),O!=null&&O.rightMargin&&(s+=O.rightMargin),G===t.bottomSize-1?n.bottom=s:s+=r.schPinSpacing,l++}s=0;for(let G=0;G<t.rightSize;G++){const j=o({side:"right",sideIndex:G,truePinIndex:l}),O=((T=r.numericSchPinStyle)==null?void 0:T[`pin${j}`])??((F=r.numericSchPinStyle)==null?void 0:F[j]);O!=null&&O.bottomMargin&&(s+=O.bottomMargin),a.push({trueIndex:l,pinNumber:j,side:"right",distanceFromOrthogonalEdge:s}),O!=null&&O.topMargin&&(s+=O.topMargin),G===t.rightSize-1?n.right=s:s+=r.schPinSpacing,l++}s=0;for(let G=0;G<t.topSize;G++){const j=o({side:"top",sideIndex:G,truePinIndex:l}),O=((U=r.numericSchPinStyle)==null?void 0:U[`pin${j}`])??((H=r.numericSchPinStyle)==null?void 0:H[j]);O!=null&&O.rightMargin&&(s+=O.rightMargin),a.push({trueIndex:l,pinNumber:j,side:"top",distanceFromOrthogonalEdge:s}),O!=null&&O.leftMargin&&(s+=O.leftMargin),G===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 u=r.pinLabels?Math.max(...Object.values(r.pinLabels).map(G=>G.length*.1)):0,A=u>0?1.1:0;c=Math.max(c,u+A);let d=r.schHeight;d||(d=Math.max(n.left+r.schPinSpacing*2,n.right+r.schPinSpacing*2));const f={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}},p={left:{x:0,y:-1},right:{x:0,y:1},top:{x:-1,y:0},bottom:{x:1,y:0}},C=a.map(G=>{const{distanceFromOrthogonalEdge:j,side:O}=G,ne=f[O],te=p[O];return{x:ne.x+j*te.x,y:ne.y+j*te.y,...G}});return{getPortPositionByPinNumber(G){const j=C.find(O=>O.pinNumber.toString()===G.toString());return j||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}},iht=l0("tscircuit:core:footprint"),oht=class extends nI{get config(){return{componentName:"Footprint",zodProps:KV}}doInitialPcbFootprintLayout(){var d,f,p,C,v;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:b,edge:T})=>({component:_,selector:x,componentSelector:b,edge:T,bounds:_._getPcbCircuitJsonBounds()}));if(i.some(_=>_.edge))throw new Error("edge constraints not implemented yet for footprint layout, contributions welcome!");function o(_){return i.find(({selector:x})=>x===_)}const a=new mK,s={};function l(_){return _ in s||(s[_]=new hR(_),a.addEditVariable(s[_],cy.weak)),s[_]}for(const{selector:_,bounds:x}of i){const b=l(`${_}_x`),T=l(`${_}_y`);a.suggestValue(b,x.center.x),a.suggestValue(T,x.center.y)}for(const _ of e){const x=_._parsedProps;if("xDist"in x){const{xDist:b,left:T,right:F,edgeToEdge:U,centerToCenter:H}=n(x),G=l(`${T}_x`),j=l(`${F}_x`),O=(f=o(T))==null?void 0:f.bounds,ne=(p=o(F))==null?void 0:p.bounds;if(H){const te=new Pm(j,[-1,G]);a.addConstraint(new k1(te,EI.Eq,x.xDist,cy.required))}else if(U){const te=new Pm(j,-ne.width/2,[-1,G],-O.width/2);a.addConstraint(new k1(te,EI.Eq,x.xDist,cy.required))}}else if("yDist"in x){const{yDist:b,top:T,bottom:F,edgeToEdge:U,centerToCenter:H}=x,G=l(`${T}_y`),j=l(`${F}_y`),O=(C=o(T))==null?void 0:C.bounds,ne=(v=o(F))==null?void 0:v.bounds;if(H){const te=new Pm(G,[-1,j]);a.addConstraint(new k1(te,EI.Eq,x.yDist,cy.required))}else if(U){const te=new Pm(G,O.height/2,[-1,j],-ne.height/2);a.addConstraint(new k1(te,EI.Eq,x.yDist,cy.required))}}else if("sameY"in x){const{for:b}=x;if(b.length<2)continue;const T=b.map(U=>l(`${U}_y`)),F=new Pm(...T.slice(1));a.addConstraint(new k1(F,EI.Eq,T[0],cy.required))}else if("sameX"in x){const{for:b}=x;if(b.length<2)continue;const T=b.map(U=>l(`${U}_x`)),F=new Pm(...T.slice(1));a.addConstraint(new k1(F,EI.Eq,T[0],cy.required))}}a.updateVariables(),iht.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:b}}of i){const T=l(`${_}_x`),F=l(`${_}_y`),U=T.value()-x/2,H=T.value()+x/2,G=F.value()+b/2,j=F.value()-b/2;c.left=Math.min(c.left,U),c.right=Math.max(c.right,H),c.top=Math.max(c.top,G),c.bottom=Math.min(c.bottom,j)}const u={x:-(c.right+c.left)/2,y:-(c.top+c.bottom)/2},A=this.getPrimitiveContainer()._getGlobalPcbPositionBeforeLayout();u.x+=A.x,u.y+=A.y;for(const{component:_,selector:x}of i){const b=l(`${x}_x`),T=l(`${x}_y`);_._setPositionFromLayout({x:b.value()+u.x,y:T.value()+u.y})}}},aht=(r,e)=>{if(!r)return;const t={};for(const[n,i]of Object.entries(r)){const o=MR(n,e),a={leftMargin:i.marginLeft??i.leftMargin,rightMargin:i.marginRight??i.rightMargin,topMargin:i.marginTop??i.topMargin,bottomMargin:i.marginBottom??i.bottomMargin};t[`pin${o}`]={...t[`pin${o}`],...a}}return t},_ve=class{constructor({input:e}){Le(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,o={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(o)}return e}},sht=r=>{const e=Math.min(...r.map(o=>o.center.x)),t=Math.max(...r.map(o=>o.center.x)),n=Math.min(...r.map(o=>o.center.y)),i=Math.max(...r.map(o=>o.center.y));return{minX:e,maxX:t,minY:n,maxY:i}},Eve=["top","bottom","inner1","inner2"],Ek=(r,e=[])=>{var s;const t=[];if(e.length===0){const l=r[0].layers;for(const c of l)t.push(...Ek(r.slice(1),[c]));return t}if(r.length===0)return[];const n=r[0],i=n.via||n.optional_via,o=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(o)?[{layer_path:[...e,o]}]:[]}if(!i)return n.layers&&!n.layers.includes(o)?[]:Ek(r.slice(1),e.concat([o]));const a=(n.optional_via?Eve:Eve.filter(l=>l!==o)).filter(l=>{var c;return!n.layers||((c=n.layers)==null?void 0:c.includes(l))});for(const l of a)t.push(...Ek(r.slice(1),e.concat(l)));return t};function xve(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 MM(r,e){return Math.hypot(r.x-e.x,r.y-e.y)}var lht=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],o=r[1][r[1].length-1],a=Math.min(MM(t,i),MM(t,o)),s=Math.min(MM(n,i),MM(n,o));a<s?e.push(...r[0].reverse()):e.push(...r[0]);for(let l=1;l<r.length;l++){const c=e[e.length-1],u=r[l],A=u[0],d=u[u.length-1],f=MM(c,A),p=MM(c,d);f<p?e.push(...u):e.push(...u.reverse())}for(let l=1;l<e.length-1;l++){const c=e[l-1],u=e[l];c.route_type==="wire"&&u.route_type==="wire"&&c.layer!==u.layer&&e.splice(l,0,{x:c.x,y:c.y,from_layer:c.layer,to_layer:u.layer,route_type:"via"})}return e},cht=(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 uht(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 o=cht(r,i);o<n&&(t=i,n=o)}return t}var Aht=(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],o=e[n],a=Math.abs(i.from.x-i.to.x)<.01,s=Math.abs(o.from.x-o.to.x)<.01;a!==s&&t++}return t},yj=r=>({up:"bottom",down:"top",left:"right",right:"left"})[r]??null,vj=({firstEdge:r,firstEdgePort:e,firstDominantDirection:t,lastEdge:n,lastEdgePort:i,lastDominantDirection:o})=>{if(r&&e)return vj({lastEdge:{from:r.to,to:r.from},lastEdgePort:e,lastDominantDirection:t}).reverse().map(s=>({from:s.to,to:s.from}));let a=[];if(n&&i){const s={x:n.to.x,y:n.to.y};o==="left"||o==="right"?(s.x=i.position.x,a.push({from:n.to,to:{...s}}),a.push({from:s,to:{...i.position}})):(s.y=i.position.y,a.push({from:n.to,to:{...s}}),a.push({from:s,to:{...i.position}}))}return a=a.filter(s=>Cx(s.from,s.to)>.01),a};function dht(r){try{return[r(),null]}catch(e){return[null,e]}}function fht(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 o=i.x-n.x,a=i.y-n.y;e+=Math.sqrt(o*o+a*a)}}else n.route_type==="via"&&(e+=1.6)}return e}var hht=r=>{var s,l;const e={left:{x:-.5,y:0},up:{x:.5,y:.5},right:{x:.5,y:0},down:{x:0,y:-.5}}[r.facingDirection],t=(s=r.parent)!=null&&s.config.shouldRenderAsSchematicBox?3:1,n=(l=r.parent)!=null&&l.config.shouldRenderAsSchematicBox&&(r.facingDirection==="left"||r.facingDirection==="right")?3:1,i=e.x,o=e.y,a=r.facingDirection==="up"?.5:0;return{schBoxVertOffset:t,schBoxHorzOffset:n,horzPortDirection:i,vertPortDirectionOffset:o,handleUp:a}},xk=({port:r,anchorPos:e,schDisplayLabel:t,source_trace_id:n},{db:i})=>{const o=hht(r),a=r.facingDirection==="left"||r.facingDirection==="right",s={x:e.x+o.horzPortDirection*o.schBoxHorzOffset,y:e.y+o.vertPortDirectionOffset*o.schBoxVertOffset},l=a?{x:s.x,y:s.y-.5}:s;i.schematic_net_label.insert({anchor_side:"top",center:l,source_net_id:r.source_port_id,text:t,anchor_position:l,symbol_name:"ground_horz"});const c=[{from:{x:e.x,y:e.y},to:{x:e.x,y:e.y+o.handleUp*o.schBoxVertOffset}},{from:{x:e.x,y:e.y},to:s}];a&&c.push({from:s,to:l}),i.schematic_trace.insert({edges:c,junctions:[],source_trace_id:n})},bk=({db:r,source_trace_id:e,sameNetOnly:t,differentNetOnly:n})=>{!t&&!n&&(n=!0);const i=r.source_trace.get(e),o=[];for(const a of r.schematic_trace.list()){if(a.source_trace_id===e)continue;const s=r.source_trace.get(a.source_trace_id),l=(s==null?void 0:s.subcircuit_connectivity_map_key)===i.subcircuit_connectivity_map_key;n&&l||t&&!l||o.push(a)}return o},bve=({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],o=Math.abs(i.from.x-i.to.x)<.01?"vertical":i.from.y===i.to.y?"horizontal":"not-orthogonal";if(o==="not-orthogonal")continue;const a=[];for(const C of e){const v=C.from.x===C.to.x?"vertical":C.from.y===C.to.y?"horizontal":"not-orthogonal";if(v==="not-orthogonal"||o===v)continue;if(yM([i.from,i.to],[C.from,C.to],{lineThickness:.01})){const x=o==="vertical"?i.from.x:C.from.x,b=o==="vertical"?C.from.y:i.from.y,T={x,y:b};a.push({otherEdge:C,crossingPoint:T,distanceFromEdgeFrom:Cx(i.from,T)})}}if(a.length===0)continue;let s=a[0];for(const C of a)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 u=yK(i.from,l),A={x:l.x-u.x*c/2,y:l.y-u.y*c/2},d={x:l.x+u.x*c/2,y:l.y+u.y*c/2},f=Cx(d,i.to)<c,p=[{from:i.from,to:A},{from:A,to:d,is_crossing:!0},{from:d,to:i.to}];t.splice(n,1,...p),n+=p.length-2,f&&n++}return t},pht=(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 u=r.from.x,A=(e.to.y-e.from.y)/(e.to.x-e.from.x),d=e.from.y-A*e.from.x,f=A*u+d;return u>=Math.min(e.from.x,e.to.x)&&u<=Math.max(e.from.x,e.to.x)&&f>=Math.min(e.from.y,e.to.y)&&f<=Math.max(e.from.y,e.to.y)?{x:u,y:f}:null}if(e.from.x===e.to.x){const u=e.from.x,A=(r.to.y-r.from.y)/(r.to.x-r.from.x),d=r.from.y-A*r.from.x,f=A*u+d;return u>=Math.min(r.from.x,r.to.x)&&u<=Math.max(r.from.x,r.to.x)&&f>=Math.min(r.from.y,r.to.y)&&f<=Math.max(r.from.y,r.to.y)?{x:u,y:f}: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),o=e.from.y-i*e.from.x;if(t===i)return null;const a=(o-n)/(t-i),s=t*a+n,l=a>=Math.min(r.from.x,r.to.x)&&a<=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=a>=Math.min(e.from.x,e.to.x)&&a<=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:a,y:s}:null},Bve=({edges:r,db:e,source_trace_id:t})=>{const n=bk({db:e,source_trace_id:t,sameNetOnly:!0}).flatMap(i=>i.edges);for(const i of r)for(const o of n){const a=pht(i,o);if(a)return`${a.x}${a.y}`,[{x:a.x,y:a.y}]}return[]},ght=(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 o=e.source_component.get(i.source_component_id);return(o==null?void 0:o.ftype)==="simple_capacitor"?o.max_decoupling_trace_length:null}).filter(n=>n!==null);if(t.length!==0)return Math.min(...t)};function mht(r){var o,a,s,l,c,u,A,d,f;let e=1/0,t=1/0,n=-1/0,i=-1/0;for(const p of r){let C,v,_,x;p.type==="schematic_component"?(C=(o=p.center)==null?void 0:o.x,v=(a=p.center)==null?void 0:a.y,_=(s=p.size)==null?void 0:s.width,x=(l=p.size)==null?void 0:l.height):p.type==="schematic_box"?(C=p.x,v=p.y,_=p.width,x=p.height):p.type==="schematic_port"?(C=(c=p.center)==null?void 0:c.x,v=(u=p.center)==null?void 0:u.y,_=.2,x=.2):p.type==="schematic_text"&&(C=(A=p.position)==null?void 0:A.x,v=(d=p.position)==null?void 0:d.y,_=(((f=p.text)==null?void 0:f.length)??0)*.1,x=.2),typeof C=="number"&&typeof v=="number"&&typeof _=="number"&&typeof x=="number"&&(e=Math.min(e,C-_/2),n=Math.max(n,C+_/2),t=Math.min(t,v-x/2),i=Math.max(i,v+x/2))}return{minX:e,maxX:n,minY:t,maxY:i}}function yht(r,e={}){const{minX:t,maxX:n,minY:i,maxY:o}=r,a=e.padding??1;if(!isFinite(t)||!isFinite(n)||!isFinite(i)||!isFinite(o))return[];const s=t-a,l=n+a,c=o+a,u=i-a,A=.01;return[{type:"rect",layers:["top"],center:{x:(s+l)/2,y:c},width:l-s,height:A,connectedTo:[]},{type:"rect",layers:["top"],center:{x:(s+l)/2,y:u},width:l-s,height:A,connectedTo:[]},{type:"rect",layers:["top"],center:{x:s,y:(c+u)/2},width:A,height:c-u,connectedTo:[]},{type:"rect",layers:["top"],center:{x:l,y:(c+u)/2},width:A,height:c-u,connectedTo:[]}]}var vht=r=>{var a;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?vK(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:(((a=s.text)==null?void 0:a.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 o=mht(e.toArray());return i.push(...yht(o,{padding:1})),i};function Iht({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 Cht=({edges:r,db:e,source_trace_id:t})=>{e.source_trace.get(t);const n=bk({db:e,source_trace_id:t,differentNetOnly:!0}).flatMap(o=>o.edges),i=o=>{const{from:a,to:s}=o;return a.x===s.x?"vertical":"horizontal"};for(const o of r){const a=i(o),s=()=>n.find(c=>i(c)===a&&yM([o.from,o.to],[c.from,c.to],{lineThickness:.05}));let l=s();for(;l;)a==="horizontal"?(o.from.y+=.1,o.to.y+=.1):(o.from.x+=.1,o.to.x+=.1),l=s()}},_ht=(r,{db:e})=>{const t=e.pcb_board.list()[0];if(t.outline){const l=t.outline,c=(u,A)=>{let d=!1;for(let f=0,p=A.length-1;f<A.length;p=f++){const C=A[f].x,v=A[f].y,_=A[p].x,x=A[p].y;v>u.y!=x>u.y&&u.x<(_-C)*(u.y-v)/(x-v)+C&&(d=!d)}return d};return r.some(u=>!c(u,l))}const n=t.width,i=t.height,o=t.center.x,a=t.center.y;return r.some(l=>l.x<o-n/2||l.y<a-i/2||l.x>o+n/2||l.y>a+i/2)},Bk=r=>({...r._getGlobalPcbPositionAfterLayout(),layers:r.getAvailablePcbLayers()}),VS=class extends nI{constructor(t){super(t);Le(this,"source_trace_id",null);Le(this,"pcb_trace_id",null);Le(this,"schematic_trace_id",null);Le(this,"_portsRoutedOnPcb");Le(this,"subcircuit_connectivity_map_key",null);Le(this,"_traceConnectionHash",null);this._portsRoutedOnPcb=[]}get config(){return{zodProps:VV,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 a=this.getTracePortPathSelectors().map(s=>({selector:s,port:this.getSubcircuit().selectOne(s,{type:"port"})??null}));for(const{selector:s,port:l}of a)if(!l){const c=s.replace(/(\> )?[^ ]+$/,""),u=this.getSubcircuit().selectOne(c);u?this.renderError(`Could not find port for selector "${s}" (did you forget to include the pin name?)
|
|
854
854
|
searched component ${u.getString()}, which has ports: ${u.children.filter(A=>A.componentName==="Port").map(A=>`${A.getString()}(${A.getNameAndAliases().join(",")})`).join(" & ")}`):this.renderError(`Could not find port for selector "${s}"`)}return a.some(s=>!s.port)?{allPortsFound:!1}:{allPortsFound:!0,portsWithSelectors:a,ports:a.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(o=>{if(o===this)return!1;const a=o._findConnectedNets().nets,s=o._findConnectedPorts().ports??[];return a.some(l=>n.includes(l))||s.some(l=>i.includes(l))})}_isExplicitlyConnectedToPort(t){const{allPortsFound:n,portsWithSelectors:i}=this._findConnectedPorts();return n?i.map(a=>a.port).includes(t):!1}_isExplicitlyConnectedToNet(t){return this._findConnectedNets().nets.includes(t)}doInitialCreateNetsFromProps(){pve(this,this.getTracePathNetSelectors())}_computeTraceConnectionHash(){const{allPortsFound:t,ports:n}=this._findConnectedPorts();return!t||!n?null:[...n].sort((a,s)=>(a.pcb_port_id||"").localeCompare(s.pcb_port_id||"")).map(a=>a.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:o,portsWithSelectors:a}=this._findConnectedPorts();if(!o)return;this._traceConnectionHash=this._computeTraceConnectionHash();const l=t.source_trace.list().find(f=>f.subcircuit_connectivity_map_key===this.subcircuit_connectivity_map_key&&f.connected_source_port_ids.sort().join(",")===this._traceConnectionHash);if(l){this.source_trace_id=l.source_trace_id;return}const c=this._findConnectedNets().nets,u=Iht({ports:a,nets:c}),A=t.source_trace.insert({connected_source_port_ids:a.map(f=>f.port.source_port_id),connected_source_net_ids:c.map(f=>f.source_net_id),subcircuit_id:(d=this.getSubcircuit())==null?void 0:d.subcircuit_id,max_length:ght(a.map(f=>f.port),{db:t})??n.maxLength,display_name:u,min_trace_thickness:n.thickness});this.source_trace_id=A.source_trace_id}_insertErrorIfTraceIsOutsideBoard(t,n){const{db:i}=this.root;_ht(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(a=>a.pcb_port_id)})}doInitialPcbTraceRender(){var j,O,ne,te;if((j=this.root)!=null&&j.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n,parent:i}=this,o=this.getSubcircuit();if(!i)throw new Error("Trace has no parent");if(o._parsedProps.routingDisabled)return;const a=(O=o._parsedProps.pcbRouteCache)==null?void 0:O.pcbTraces;if(a){const ie=t.pcb_trace.insert({route:a.flatMap(pe=>pe.route),source_trace_id:this.source_trace_id,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((ne=this.getGroup())==null?void 0:ne.pcb_group_id)??void 0});this.pcb_trace_id=ie.pcb_trace_id;return}if(!o._shouldUseTraceByTraceRouting())return;const{allPortsFound:s,ports:l}=this._findConnectedPorts();if(!s)return;const c=[];for(const ie of l)ie._hasMatchedPcbPrimitive()||c.push(ie);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(ie=>ie.getString()).join(", ")}`,pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[],pcb_port_ids:c.map(ie=>ie.pcb_port_id).filter(Boolean)});return}const u=this._findConnectedNets().netsWithSelectors;if(l.length===0&&u.length===2){this.renderError("Trace connects two nets, we haven't implemented a way to route this yet");return}else if(l.length===1&&u.length===1){const ie=l[0],de=u[0].net.getAllConnectedPorts().filter(Ie=>Ie!==ie);if(de.length===0){console.log("Nothing to connect this port to, the net is empty. TODO should emit a warning!");return}const Ae=uht(ie,de);l.push(Ae)}else if(l.length>1&&u.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 A=l.flatMap(ie=>ie.matchedComponents.filter(pe=>pe.componentName==="TraceHint")),d=(this._parsedProps.pcbRouteHints??[]).concat(A.flatMap(ie=>ie.getPcbRouteHints()));if(l.length>2){this.renderError(`Trace has more than two ports (${l.map(ie=>ie.getString()).join(", ")}), routing between more than two ports for a single trace is not implemented`);return}if(this.getSubcircuit().selectAll("trace").filter(ie=>ie.renderPhaseStates.PcbTraceRender.initialized).some(ie=>ie._portsRoutedOnPcb.length===l.length&&ie._portsRoutedOnPcb.every(pe=>l.includes(pe))))return;let C=[];d.length===0?C=[Bk(l[0]),Bk(l[1])]:C=[Bk(l[0]),...d,Bk(l[1])];const v=Ek(C),_=lB(this.root.db.toArray()),[x,b]=dht(()=>gM(this.root.db.toArray()));if(b){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: ${b.message}`,source_trace_id:this.source_trace_id,center:{x:0,y:0},pcb_port_ids:l.map(ie=>ie.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[]});return}for(const ie of x)if(ie.connectedTo.length>0){const de=_.getNetConnectedToId(ie.connectedTo[0]);de&&ie.connectedTo.push(de)}let T=[];if(v.length===0)T=C;else{const ie=v[0].layer_path;T=C.map((pe,de)=>pe.via?{...pe,via_to_layer:ie[de]}:{...pe,layers:[ie[de]]})}T[0].pcb_port_id=l[0].pcb_port_id,T[T.length-1].pcb_port_id=l[1].pcb_port_id;const F=[];for(const[ie,pe]of fve(T)){const de="via_to_layer"in ie?ie.via_to_layer:null,Ae=2,Ie="layers"in ie&&ie.layers.length===1?ie.layers[0]:de??"top",ge="layers"in pe&&pe.layers.length===1?pe.layers[0]:de??"top",Me="pcb_port_id"in ie?ie.pcb_port_id:null,be="pcb_port_id"in pe?pe.pcb_port_id:null,Re=this.getSubcircuit()._parsedProps.minTraceWidth??.16,Se=new pM({OBSTACLE_MARGIN:Re*2,isRemovePathLoopsEnabled:!0,optimizeWithGoalBoxes:!!(Me&&be),connMap:_,input:{obstacles:x,minTraceWidth:Re,connections:[{name:this.source_trace_id,pointsToConnect:[{...ie,layer:Ie,pcb_port_id:Me},{...pe,layer:ge,pcb_port_id:be}]}],layerCount:2,bounds:{minX:Math.min(ie.x,pe.x)-Ae,maxX:Math.max(ie.x,pe.x)+Ae,minY:Math.min(ie.y,pe.y)-Ae,maxY:Math.max(ie.y,pe.y)+Ae}}});let Ke=null;try{Ke=Se.solveAndMapToTraces()}catch(ft){this.renderError({type:"pcb_trace_error",pcb_trace_error_id:this.source_trace_id,error_type:"pcb_trace_error",message:`error solving route: ${ft.message}`,source_trace_id:this.pcb_trace_id,center:{x:(ie.x+pe.x)/2,y:(ie.y+pe.y)/2},pcb_port_ids:l.map(Pt=>Pt.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:l.map(Pt=>Pt.pcb_component_id)})}if(!Ke)return;if(Ke.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:(ie.x+pe.x)/2,y:(ie.y+pe.y)/2},pcb_port_ids:l.map(ft=>ft.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:l.map(ft=>ft.pcb_component_id)});return}const[Ze]=Ke;de&&(Ze.route=Ze.route.map(ft=>(ft.route_type==="wire"&&!ft.layer&&(ft.layer=de),ft))),Me&&Ze.route[0].route_type==="wire"&&(Ze.route[0].start_pcb_port_id=Me);const lt=Ze.route[Ze.route.length-1];be&<.route_type==="wire"&&(lt.end_pcb_port_id=be),F.push(Ze.route)}const U=lht(F),H=fht(U),G=t.pcb_trace.insert({route:U,source_trace_id:this.source_trace_id,subcircuit_id:(te=this.getSubcircuit())==null?void 0:te.subcircuit_id,trace_length:H});this._portsRoutedOnPcb=l,this.pcb_trace_id=G.pcb_trace_id;for(const ie of U)ie.route_type==="via"&&t.pcb_via.insert({pcb_trace_id:G.pcb_trace_id,x:ie.x,y:ie.y,hole_diameter:.3,outer_diameter:.6,layers:[ie.from_layer,ie.to_layer],from_layer:ie.from_layer,to_layer:ie.to_layer});this._insertErrorIfTraceIsOutsideBoard(U,l)}_doInitialSchematicTraceRenderWithDisplayLabel(){var F,U,H,G;if((F=this.root)!=null&&F.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i)throw new Error("Trace has no parent");const{allPortsFound:o,portsWithSelectors:a}=this._findConnectedPorts();if(!o)return;const s=a.map(({port:j})=>({port:j,position:j._getGlobalSchematicPositionAfterLayout(),schematic_port_id:j.schematic_port_id,facingDirection:j.facingDirection}));if(s.length<2)throw new Error("Expected at least two ports in portsWithPosition.");let l,c;const u=s[0].position,A=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(!A.source_port_id)throw new Error(`Missing source_port_id for the 'from' port (${l}).`);const d=s[1].position,f=s[1].port;if(!f.source_port_id)throw new Error(`Missing source_port_id for the 'to' port (${c}).`);const p=t.schematic_net_label.list().find(j=>j.source_net_id===A.source_port_id),C=t.schematic_net_label.list().find(j=>j.source_net_id===f.source_port_id),[v,_]=a.map(({port:j})=>j),b=((U=v.parent)==null?void 0:U.config.shouldRenderAsSchematicBox)?`${(H=v==null?void 0:v.parent)==null?void 0:H.props.name}_${v==null?void 0:v.props.name}`:`${(G=_==null?void 0:_.parent)==null?void 0:G.props.name}_${_==null?void 0:_.props.name}`,T=this.props.schDisplayLabel??b;if(p&&p.text!==T&&(p.text=`${T} / ${p.text}`),C&&(C==null?void 0:C.text)!==T&&(C.text=`${T} / ${C.text}`),T!=null&&T.toLocaleLowerCase().includes("gnd")||T!=null&&T.toLocaleLowerCase().includes("ground")){!p&&!C?(xk({port:A,anchorPos:u,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t}),xk({port:f,anchorPos:d,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t})):p?C||xk({port:f,anchorPos:d,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t}):xk({port:A,anchorPos:u,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t});return}C||t.schematic_net_label.insert({text:this.props.schDisplayLabel??b,source_net_id:f.source_port_id,anchor_position:d,center:d,anchor_side:yj(f.facingDirection)??"bottom"}),p||t.schematic_net_label.insert({text:this.props.schDisplayLabel??b,source_net_id:A.source_port_id,anchor_position:u,center:u,anchor_side:yj(A.facingDirection)??"bottom"})}_isSymbolToChipConnection(){const{allPortsFound:t,ports:n}=this._findConnectedPorts();if(!t||n.length!==2)return!1;const[i,o]=n;if(!(i!=null&&i.parent)||!(o!=null&&o.parent))return!1;const a=i.parent.config.shouldRenderAsSchematicBox,s=o.parent.config.shouldRenderAsSchematicBox;return a&&!s||!a&&s}_isSymbolToSymbolConnection(){const{allPortsFound:t,ports:n}=this._findConnectedPorts();if(!t||n.length!==2)return!1;const[i,o]=n;if(!(i!=null&&i.parent)||!(o!=null&&o.parent))return!1;const a=!i.parent.config.shouldRenderAsSchematicBox,s=!o.parent.config.shouldRenderAsSchematicBox;return a&&s}_isChipToChipConnection(){const{allPortsFound:t,ports:n}=this._findConnectedPorts();if(!t||n.length!==2)return!1;const[i,o]=n;if(!(i!=null&&i.parent)||!(o!=null&&o.parent))return!1;const a=i.parent.config.shouldRenderAsSchematicBox,s=o.parent.config.shouldRenderAsSchematicBox;return a&&s}doInitialSchematicTraceRender(){var Ie,ge,Me;if((Ie=this.root)!=null&&Ie.schematicDisabled||((ge=this.getGroup())==null?void 0:ge._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:o,portsWithSelectors:a}=this._findConnectedPorts(),{netsWithSelectors:s}=this._findConnectedNets();if(!o)return;const c=a.map(be=>be.port.schematic_port_id).sort().join(","),u=(Me=this.root)==null?void 0:Me._getBoard();if(u!=null&&u._connectedSchematicPortPairs&&u._connectedSchematicPortPairs.has(c))return;if(this.props.schDisplayLabel&&("from"in this.props&&"to"in this.props||"path"in this.props)){this._doInitialSchematicTraceRenderWithDisplayLabel();return}const A={name:this.source_trace_id,pointsToConnect:[]},d=vht(this),f=a.map(({port:be})=>({port:be,position:be._getGlobalSchematicPositionAfterLayout(),schematic_port_id:be.schematic_port_id??void 0,facingDirection:be.facingDirection}));if(f.length===1&&s.length===1){const be=s[0].net,{port:Re,position:Se}=f[0];t.schematic_net_label.insert({text:be._parsedProps.name,source_net_id:be.source_net_id,anchor_position:Se,center:Se,anchor_side:yj(Re.facingDirection)??"bottom"});return}if(f.length<2)return;A.pointsToConnect=f.map(({position:be})=>({...be,layer:"top"}));const C=sht(d),v=2,_={minTraceWidth:.1,obstacles:d,connections:[A],bounds:{minX:C.minX-v,maxX:C.maxX+v,minY:C.minY-v,maxY:C.maxY+v},layerCount:1};let x=pM,b=!1;this.getSubcircuit().props._schDirectLineRoutingEnabled&&(x=_ve,b=!0);let F=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(F.length===0){if(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection()){this._doInitialSchematicTraceRenderWithDisplayLabel();return}F=new _ve({input:_}).solveAndMapToTraces(),b=!0}const[{route:U}]=F;let H=[];for(let be=0;be<U.length-1;be++)H.push({from:U[be],to:U[be+1]});const G=this.source_trace_id;let j=[];if(!b){Cht({edges:H,db:t,source_trace_id:G});const be=bk({db:t,source_trace_id:G,differentNetOnly:!0}).flatMap(Re=>Re.edges);H=bve({edges:H,otherEdges:be}),j=Bve({edges:H,db:t,source_trace_id:this.source_trace_id})}const O=H[H.length-1],ne=f[f.length-1],te=xve(O);H.push(...vj({lastEdge:O,lastEdgePort:ne,lastDominantDirection:te}));const ie=H[0],pe=f[0],de=xve(ie);if(H.unshift(...vj({firstEdge:ie,firstEdgePort:pe,firstDominantDirection:de})),!this.source_trace_id)throw new Error("Missing source_trace_id for schematic trace insertion.");if(this.getSubcircuit()._parsedProps.schTraceAutoLabelEnabled&&Aht(j,H)>=5&&(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection())){this._doInitialSchematicTraceRenderWithDisplayLabel();return}const Ae=t.schematic_trace.insert({source_trace_id:this.source_trace_id,edges:H,junctions:j});this.schematic_trace_id=Ae.schematic_trace_id,u!=null&&u._connectedSchematicPortPairs&&u._connectedSchematicPortPairs.add(c)}},Eht=l0("tscircuit:core"),xht=Xt({x:vE,y:vE,z:vE}),F1=class extends nI{constructor(t){super(t);Le(this,"reactSubtrees",[]);Le(this,"_impliedFootprint");Le(this,"isPrimitiveContainer",!0);Le(this,"_asyncSupplierPartNumbers");Le(this,"pcb_missing_footprint_error_id");Le(this,"_hasStartedFootprintUrlLoad",!1);this._addChildrenFromStringFootprint(),this.initPorts()}get defaultInternallyConnectedPinNames(){return[]}get internallyConnectedPinNames(){return this._parsedProps.internallyConnectedPins??this.defaultInternallyConnectedPinNames}initPorts(t={}){var s,l,c,u,A,d,f,p,C,v;if((s=this.root)!=null&&s.schematicDisabled)return;const{config:n}=this,i=[],o=this._getSchematicPortArrangement();if(o&&!this._parsedProps.pinLabels){for(const b in o){const T=o[b].pins;if(Array.isArray(T))for(const F of T){const U=MR(F,this._parsedProps.pinLabels);i.push(new YS({pinNumber:U,aliases:((l=t.additionalAliases)==null?void 0:l[`pin${U}`])??[]},{originDescription:`schPortArrangement:${b}`}))}}const _=["left","right","top","bottom"];let x=1;for(const b of _){const T=o[`${b}Size`];for(let F=0;F<T;F++)i.push(new YS({pinNumber:x++,aliases:((c=t.additionalAliases)==null?void 0:c[`pin${x}`])??[]},{originDescription:`schPortArrangement:${b}`}))}}const a=this._parsedProps.pinLabels;if(a)for(let[_,x]of Object.entries(a)){_=_.replace("pin","");let b=i.find(U=>U._parsedProps.pinNumber===Number(_));const T=Array.isArray(x)?x[0]:x,F=Array.isArray(x)?x.slice(1):[];b?(b.externallyAddedAliases.push(T,...F),b.props.name=T):(b=new YS({pinNumber:parseInt(_),name:T,aliases:[...F,...((u=t.additionalAliases)==null?void 0:u[`pin${parseInt(_)}`])??[]]},{originDescription:`pinLabels:pin${_}`}),i.push(b))}if(n.schematicSymbolName){const _=A0[this._getSchematicSymbolNameOrThrow()];if(!_)return;for(const x of _.ports){const b=Ive(x.labels);if(!b)continue;const T=i.find(F=>F._parsedProps.pinNumber===Number(b));if(T)T.schematicSymbolPortDef=x;else{const F=DR(x.labels.concat(((A=t.additionalAliases)==null?void 0:A[`pin${b}`])??[]));F&&(F.originDescription=`schematicSymbol:labels[0]:${x.labels[0]}`,F.schematicSymbolPortDef=x,i.push(F))}}this.addAll(i)}if(!this._getSchematicPortArrangement()){const _=this.getPortsFromFootprint(t);for(const x of _)i.some(b=>b.isMatchingAnyOf(x.getNameAndAliases()))||i.push(x)}for(let _=1;_<=(t.pinCount??this._getPinCount());_++){if(!o||i.find(b=>b._parsedProps.pinNumber===_))continue;let x=[...((d=o.leftSide)==null?void 0:d.pins)??[],...((f=o.rightSide)==null?void 0:f.pins)??[],...((p=o.topSide)==null?void 0:p.pins)??[],...((C=o.bottomSide)==null?void 0:C.pins)??[]].map(b=>MR(b,this._parsedProps.pinLabels));["leftSize","rightSize","topSize","bottomSize","leftPinCount","rightPinCount","topPinCount","bottomPinCount"].some(b=>b in o)&&(x=Array.from({length:this._getPinCount()},(b,T)=>T+1)),x.includes(_)&&i.push(new YS({pinNumber:_,aliases:((v=t.additionalAliases)==null?void 0:v[`pin${_}`])??[]},{originDescription:`notOtherwiseAddedButDeducedFromPinCount:${_}`}))}i.length>0&&this.addAll(i)}_getImpliedFootprintString(){return null}_isFootprintUrl(t){return t.startsWith("http://")||t.startsWith("https://")}_addChildrenFromStringFootprint(){var a;const{name:t,pcbRotation:n,pinLabels:i}=this.props;let{footprint:o}=this.props;if(o??(o=(a=this._getImpliedFootprintString)==null?void 0:a.call(this)),!!o&&typeof o=="string"){if(this._isFootprintUrl(o))return;const s=lM.string(o).soup(),l=vve({componentName:t,componentRotation:n,footprint:o,pinLabels:i},s);this.addAll(l)}}get portMap(){return new Proxy({},{get:(t,n)=>{const i=this.children.find(o=>o.componentName==="Port"&&o.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,o=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=o.source_component_id}doInitialSchematicComponentRender(){var o,a,s;if((o=this.root)!=null&&o.schematicDisabled)return;const{db:t}=this.root,{schematicSymbolName:n}=this.config;n?this._doInitialSchematicComponentRenderWithSymbol():this._getSchematicBoxDimensions()&&this._doInitialSchematicComponentRenderWithSchematicBoxDimensions();const i=(a=this.getSubcircuit())==null?void 0:a._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=eR.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 o of n)i.push(this.portMap[o]);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(),o=A0[i],a=this._getGlobalSchematicPositionBeforeLayout();if(o){const l=t.schematic_component.insert({center:a,size:o.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(),o={};if(Array.isArray(n.pinLabels))n.pinLabels.forEach((f,p)=>{o[String(p+1)]=f});else for(const[f,p]of Object.entries(n.pinLabels??{}))o[f]=Array.isArray(p)?p[0]:p;const a=this._getGlobalSchematicPositionBeforeLayout(),s=this._getSchematicPortArrangement(),l=t.schematic_component.insert({center:a,rotation:n.schRotation??0,size:i.getSize(),port_arrangement:Kft(s),pin_spacing:n.schPinSpacing??.2,pin_styles:Vft(n.schPinStyle,n.pinLabels),port_labels:o,source_component_id:this.source_component_id}),c=(s==null?void 0:s.topSide)!==void 0||(s==null?void 0:s.bottomSide)!==void 0,u=i==null?void 0:i.getSize().width,A=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?a.x+(u??0)/2+.1:a.x-(u??0)/2,y:c?a.y+(A??0)/2+.35:a.y-(A??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?a.x+(u??0)/2+.1:a.x-(u??0)/2,y:c?a.y+(A??0)/2+.55:a.y+(A??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(),o=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=o.pcb_component_id;const a=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if((this.props.pcbX!==void 0||this.props.pcbY!==void 0)&&a){const l=rR.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 a;if((a=this.root)!=null&&a.pcbDisabled||!this.pcb_component_id)return;const{db:t}=this.root,{_parsedProps:n}=this,i=mj(this.children);if(i.width===0||i.height===0)return;const o={x:(i.minX+i.maxX)/2,y:(i.minY+i.maxY)/2};t.pcb_component.update(this.pcb_component_id,{center:o,width:i.width,height:i.height})}_renderReactSubtree(t){return{element:t,component:Yft(t)}}doInitialInitializePortsFromChildren(){this.initPorts()}doInitialReactSubtreesRender(){}doInitialPcbFootprintStringRender(){var a;let{footprint:t}=this.props;if(t??(t=(a=this._getImpliedFootprintString)==null?void 0:a.call(this)),!t)return;const{name:n,pcbRotation:i,pinLabels:o}=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(),u=vve({componentName:n,componentRotation:i,footprint:s,pinLabels:o},c);this.addAll(u),this._markDirty("InitializePortsFromChildren")});return}if(nt.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}!nt.isValidElement(t)&&t.componentName==="Footprint"&&this.add(t)}_hasExistingPortExactly(t){return this.children.filter(i=>i.componentName==="Port").some(i=>{const o=t.getNameAndAliases(),a=i.getNameAndAliases();return o.length===a.length&&o.every(s=>a.includes(s))})}add(t){let n;if(nt.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 o=this.children.filter(a=>a.componentName==="Port").find(a=>a.isMatchingAnyOf(n.getNameAndAliases()));o&&Eht(`Similar ports added. Port 1: ${o}, Port 2: ${n}`)}super.add(n)}getPortsFromFootprint(t){let{footprint:n}=this.props;if((!n||nt.isValidElement(n))&&(n=this.children.find(o=>o.componentName==="Footprint")),typeof n=="string"){if(this._isFootprintUrl(n))return[];const o=lM.string(n).soup(),a=[];for(const s of o)if("port_hints"in s&&s.port_hints){const l=DR(s.port_hints,t);if(!l)continue;l.originDescription=`footprint:string:${n}:port_hints[0]:${s.port_hints[0]}`,a.push(l)}return a}if(!nt.isValidElement(n)&&n&&n.componentName==="Footprint"){const o=n;let a=1;const s=[];for(const l of o.children){if(!l.props.portHints)continue;let c=l.props.portHints;c.some(d=>d.startsWith("pin"))||(c=[...c,`pin${a}`]),a++;const A=DR(c);A&&(A.originDescription=`footprint:${n}`,s.push(A))}return s}const i=[];if(!n){for(const o of this.children)if(o.props.portHints&&o.isPcbPrimitive){const a=DR(o.props.portHints);a&&i.push(a)}}return i}getPortsFromSchematicSymbol(){var o;if((o=this.root)!=null&&o.schematicDisabled)return[];const{config:t}=this;if(!t.schematicSymbolName)return[];const n=A0[t.schematicSymbolName];if(!n)return[];const i=[];for(const a of n.ports){const s=DR(a.labels);s&&(s.schematicSymbolPortDef=a,i.push(s))}return i}doInitialCreateNetsFromProps(){this._createNetsFromProps(this._getNetsFromConnectionsProp())}_getNetsFromConnectionsProp(){const{_parsedProps:t}=this,n=[];if(t.connections)for(const[i,o]of Object.entries(t.connections)){const a=Array.isArray(o)?o:[o];for(const s of a)n.push(s)}return n}_createNetsFromProps(t){pve(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(!Cve(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:o,topSide:a,bottomSide:s}=t;return Math.max(...(i==null?void 0:i.pins)??[],...(o==null?void 0:o.pins)??[],...(a==null?void 0:a.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 rht({schWidth:t.schWidth,schHeight:t.schHeight,schPinSpacing:i,numericSchPinStyle:aht(t.schPinStyle,t.pinLabels),pinCount:n,schPortArrangement:this._getSchematicPortArrangement(),pinLabels:t.pinLabels})}doInitialCadModelRender(){var u;const{db:t}=this.root,{boardThickness:n=0}=((u=this.root)==null?void 0:u._getBoard())??{},i=this._parsedProps.cadModel;if(!this.pcb_component_id||!i&&!this.props.footprint||i===null)return;const o=this._getPcbCircuitJsonBounds(),a=t.pcb_component.get(this.pcb_component_id);if(typeof i=="string")throw new Error("String cadModel not yet implemented");const s=xht.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=Y2.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:o.center.x+l.x,y:o.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"?-(((a==null?void 0:a.rotation)??0)+s.z)+180:((a==null?void 0:a.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,u;if(this.props.doNotPlace)return{};const o=(u=(c=this.root)==null?void 0:c.platform)==null?void 0:u.localCacheEngine,a=this._getPartsEngineCacheKey(n,i);if(o){const A=await o.getItem(a);if(A)try{return JSON.parse(A)}catch{}}const s=await Promise.resolve(t.findPart({sourceComponent:n,footprinterString:i})),l=s==="Not found"?{}:s;if(o)try{await o.setItem(a,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 o;this.props.footprint&&typeof this.props.footprint=="string"&&(o=this.props.footprint);const a=this._getSupplierPartNumbers(t,i,o);if(!(a instanceof Promise)){n.source_component.update(this.source_component_id,{supplier_part_numbers:a});return}this._queueAsyncEffect("get-supplier-part-numbers",async()=>{this._asyncSupplierPartNumbers=await a,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 o=Array.isArray(i)?i:[i];for(const a of o)this.add(new VS({from:`${this.getSubcircuitSelector()} > port.${n}`,to:a}))}}},bht=class{constructor(e,t={}){Le(this,"input");Le(this,"isRouting",!1);Le(this,"solver");Le(this,"eventHandlers",{complete:[],error:[],progress:[]});Le(this,"cycleCount",0);Le(this,"stepDelay");Le(this,"timeoutId");this.input=e;const{capacityDepth:n,targetMinCapacity:i,stepDelay:o=0}=t;this.solver=new jK(e,{capacityDepth:n,targetMinCapacity:i,cacheProvider:null}),this.stepDelay=o}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 o=((e=this.solver)==null?void 0:e.preview())||void 0,a=this.solver.progress;this.emitEvent({type:"progress",steps:this.cycleCount,iterationsPerSecond:i,progress:a,phase:this.solver.getCurrentPhase(),debugGraphics:o}),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||[]}},Sve=class extends nI{constructor(){super(...arguments);Le(this,"matchedPort",null)}get config(){return{componentName:"TraceHint",zodProps:pK}}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 o=i.selectOne(n.for,{type:"port"});o||this.renderError(`${this} could not find port for selector "${n.for}"`),this.matchedPort=o,o.registerMatch(this)}getPcbRouteHints(){const{_parsedProps:t}=this,n=t.offset?[t.offset]:t.offsets;if(!n)return[];const i=this._computePcbGlobalTransformBeforeLayout();return n.map(o=>({...Wr(i,o),via:o.via,to_layer:o.to_layer,trace_width:o.trace_width}))}doInitialPcbTraceHintRender(){var i,o,a;if((i=this.root)!=null&&i.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this;t.pcb_trace_hint.insert({pcb_component_id:(o=this.matchedPort)==null?void 0:o.pcb_component_id,pcb_port_id:(a=this.matchedPort)==null?void 0:a.pcb_port_id,route:this.getPcbRouteHints()})}},Bht=({circuitJson:r,editEvents:e,manualEditsFile:t})=>{var i;const n={...t,pcb_placements:[...t.pcb_placements??[]]};for(const o of e)if(o.edit_event_type==="edit_pcb_component_location"){const{pcb_component_id:a,new_center:s}=o,l=sC(r).pcb_component.get(a);if(!l)continue;const c=sC(r).source_component.get(l.source_component_id);if(!c)continue;const u=(i=n.pcb_placements)==null?void 0:i.findIndex(d=>d.selector===c.name),A={selector:c.name,center:s,relative_to:"group_center"};u>=0?n.pcb_placements[u]=A:n.pcb_placements.push(A)}return n},Sht=({circuitJson:r,editEvents:e,manualEditsFile:t})=>{var i;const n={...t,schematic_placements:[...t.schematic_placements??[]]};for(const o of e)if(o.edit_event_type==="edit_schematic_component_location"){const{schematic_component_id:a,new_center:s}=o,l=sC(r).schematic_component.get(a);if(!l)continue;const c=sC(r).source_component.get(l.source_component_id);if(!c)continue;const u=(i=n.schematic_placements)==null?void 0:i.findIndex(d=>d.selector===c.name),A={selector:c.name,center:s,relative_to:"group_center"};u>=0?n.schematic_placements[u]=A:n.schematic_placements.push(A)}return n},wve=({circuitJson:r,editEvents:e,manualEditsFile:t})=>{const n=e.filter(a=>a.edit_event_type==="edit_schematic_component_location"),i=e.filter(a=>a.edit_event_type==="edit_pcb_component_location");let o=t;return n.length>0&&(o=Sht({circuitJson:r,editEvents:n,manualEditsFile:o})),i.length>0&&(o=Bht({circuitJson:r,editEvents:i,manualEditsFile:o})),o},wht=(r,e)=>{const t=r.source_group.list(),n=[],i=o=>{const a=t.filter(s=>s.parent_subcircuit_id===o);for(const s of a)s.subcircuit_id&&(n.push(s.subcircuit_id),i(s.subcircuit_id))};return i(e),n},Qve=({db:r,circuitJson:e,subcircuit_id:t,minTraceWidth:n=.1})=>{if(!r&&e&&(r=sC(e)),!r)throw new Error("db or circuitJson is required");const i=r.pcb_trace_hint.list(),o=t?new Set([t]):null;if(t){const C=wht(r,t);for(const v of C)o.add(v)}const a=(e??r.toArray()).filter(C=>!t||"subcircuit_id"in C&&o.has(C.subcircuit_id)),s=r.pcb_board.list()[0];r=sC(a);const l=lB(a),c=gM([...r.pcb_component.list(),...r.pcb_smtpad.list(),...r.pcb_plated_hole.list(),...r.pcb_hole.list(),...r.pcb_via.list()].filter(C=>!t||(o==null?void 0:o.has(C.subcircuit_id))),l);for(const C of c){const v=C.connectedTo.flatMap(_=>l.getIdsConnectedToNet(_));C.connectedTo.push(...v)}const u=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 A;s?A={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}:A={minX:Math.min(...u.map(C=>C.x))-1,maxX:Math.max(...u.map(C=>C.x))+1,minY:Math.min(...u.map(C=>C.y))-1,maxY:Math.max(...u.map(C=>C.y))+1};const d=r.source_trace.list().map(C=>{var H,G,j;const v=C.connected_source_port_ids.map(O=>{const ne=r.source_port.get(O),te=r.pcb_port.getWhere({source_port_id:O});return{...ne,...te}});if(v.length<2)return null;const[_,x]=v,b=((H=_.layers)==null?void 0:H[0])??"top",T=((G=x.layers)==null?void 0:G[0])??"top",F=i.filter(O=>O.pcb_port_id===_.pcb_port_id||O.pcb_port_id===x.pcb_port_id),U=[];for(const O of F){const ne=r.pcb_port.get(O.pcb_port_id),te=((j=ne==null?void 0:ne.layers)==null?void 0:j[0])??"top";for(const ie of O.route)U.push({x:ie.x,y:ie.y,layer:te})}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:b},...U,{x:x.x,y:x.y,layer:T}]}}).filter(C=>C!==null),f=r.source_net.list().filter(C=>!t||(o==null?void 0:o.has(C.subcircuit_id))),p=[];for(const C of f){const v=r.source_trace.list().filter(_=>{var x;return(x=_.connected_source_net_ids)==null?void 0:x.includes(C.source_net_id)});p.push({name:C.source_net_id??l.getNetConnectedToId(C.source_net_id),pointsToConnect:v.flatMap(_=>r.pcb_port.list().filter(b=>_.connected_source_port_ids.includes(b.source_port_id)).map(b=>{var T;return{x:b.x,y:b.y,layer:((T=b.layers)==null?void 0:T[0])??"top",pcb_port_id:b.pcb_port_id}}))})}return{simpleRouteJson:{bounds:A,obstacles:c,connections:[...d,...p],layerCount:2,minTraceWidth:n},connMap:l}};function Ij(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 o=e.source_port.getWhere({source_component_id:i.source_component_id,pin_number:n});return{subcircuit_connectivity_map_key:(o==null?void 0:o.subcircuit_connectivity_map_key)??null,source_port_id:o.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 Qht({path:r,db:e,layoutConnMap:t}){let n=Ij(r.to,e)??Ij(r.from,e);if(!n){const o=t.getNetConnectedToId(_E(r.to));n=t.getIdsConnectedToNet(o).map(s=>vk(s)).map(s=>Ij(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 o of i)if(o.connected_source_port_ids.includes(n.source_port_id))return o.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 Mht(r){const{db:e}=r.root;let t=structuredClone(e.toArray());t=ave(t);const n=ove(t),i=new ive({inputNetlist:n});let o=null;try{i.solve(),o=i.getLayout()}catch(A){e.schematic_layout_error.insert({message:`Match-adapt layout failed: ${A.toString()}`,source_group_id:r.source_group_id,schematic_group_id:r.schematic_group_id});return}const{boxes:a,junctions:s,netLabels:l,paths:c}=o,u=new W2({});for(const A of c)u.addConnections([[_E(A.from),_E(A.to)]]);for(const A of s)for(const d of c)for(const f of d.points)Math.abs(f.x-A.x)<.001&&Math.abs(f.y-A.y)<.001&&u.addConnections([[_E(d.from),_E(A)],[_E(d.to),_E(A)]]);for(const A of a){const d=e.source_component.list().find(_=>_.name===A.boxId);if(!d)continue;const f=e.schematic_component.getWhere({source_component_id:d.source_component_id});if(!f)continue;const p={x:A.centerX-f.center.x+.1,y:A.centerY-f.center.y-.1};e.schematic_component.update(f.schematic_component_id,{center:{x:f.center.x+p.x,y:f.center.y+p.y}});const C=e.schematic_port.list({schematic_component_id:f.schematic_component_id});for(const _ of C)e.schematic_port.update(_.schematic_port_id,{center:{x:_.center.x+p.x,y:_.center.y+p.y}});const v=e.schematic_text.list({schematic_component_id:f.schematic_component_id});for(const _ of v)e.schematic_text.update(_.schematic_text_id,{position:{x:_.position.x+p.x,y:_.position.y+p.y}})}for(const A of l){const d=e.source_net.list().find(f=>f.name===A.netId);e.schematic_net_label.insert({text:A.netId,source_net_id:d==null?void 0:d.source_net_id,anchor_position:{x:A.x,y:A.y},center:{x:A.x,y:A.y},anchor_side:A.anchorPosition})}for(const A of c){if(!A.points||A.points.length<2)continue;const d=Qht({path:A,db:gb(t),layoutConnMap:u});let f=[];for(let v=0;v<A.points.length-1;v++)f.push({from:{x:A.points[v].x,y:A.points[v].y},to:{x:A.points[v+1].x,y:A.points[v+1].y}});const p=bk({db:e,source_trace_id:d,differentNetOnly:!0}).flatMap(v=>v.edges);p.length>0&&(f=bve({edges:f,otherEdges:p}));const C=Bve({edges:f,db:e,source_trace_id:d});e.schematic_trace.insert({source_trace_id:d,edges:f,junctions:C})}}function Dht(r){if(!r.isSubcircuit)return;const{db:e}=r.root,t=r.selectAll("trace"),n=new W2({});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 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_port_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_port.update(s,{subcircuit_connectivity_map_key:c})}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_net_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_net.update(s,{subcircuit_connectivity_map_key:c})}}function Rht(r){var x;const{db:e}=r.root,t=r._parsedProps,n=r.children.filter(b=>b.schematic_component_id);if(n.length===0)return;let i=0,o=0;for(const b of n){const T=e.schematic_component.get(b.schematic_component_id);T!=null&&T.size&&(i=Math.max(i,T.size.width),o=Math.max(o,T.size.height))}i===0&&n.length>0&&(i=1),o===0&&n.length>0&&(o=1);let a=t.gridCols,s,l=t.gridGap;(x=t.schLayout)!=null&&x.grid&&(a=t.schLayout.grid.cols??a,s=t.schLayout.grid.rows,l=t.schLayout.grid.gap??l);let c,u;a!==void 0&&s!==void 0?(c=a,u=s):a!==void 0?(c=a,u=Math.ceil(n.length/c)):s!==void 0?(u=s,c=Math.ceil(n.length/u)):(c=Math.ceil(Math.sqrt(n.length)),u=Math.ceil(n.length/c)),c===0&&n.length>0&&(c=1),u===0&&n.length>0&&(u=n.length);let A,d;typeof l=="number"?(A=l,d=l):typeof l=="object"&&l!==null?(A=l.x,d=l.y):(A=1,d=1);const f=c*i+Math.max(0,c-1)*A,p=u*o+Math.max(0,u-1)*d,C=r._getGlobalSchematicPositionBeforeLayout(),v=C.x-f/2+i/2,_=C.y+p/2-o/2;for(let b=0;b<n.length;b++){const T=n[b];if(!T.schematic_component_id)continue;const F=Math.floor(b/c),U=b%c;if(F>=u||U>=c){console.warn(`Schematic grid layout: Child ${T.getString()} at index ${b} (row ${F}, col ${U}) exceeds specified grid dimensions (${u}x${c}). Skipping placement.`);continue}const H=v+U*(i+A),G=_-F*(o+d),j=e.schematic_component.get(T.schematic_component_id);if(j){const O=j.center,ne={x:H,y:G};e.schematic_component.update(T.schematic_component_id,{center:ne});const te=ne.x-O.x,ie=ne.y-O.y,pe=e.schematic_port.list({schematic_component_id:T.schematic_component_id});for(const Ae of pe)e.schematic_port.update(Ae.schematic_port_id,{center:{x:Ae.center.x+te,y:Ae.center.y+ie}});const de=e.schematic_text.list({schematic_component_id:T.schematic_component_id});for(const Ae of de)e.schematic_text.update(Ae.schematic_text_id,{position:{x:Ae.position.x+te,y:Ae.position.y+ie}})}}r.schematic_group_id&&e.schematic_group.update(r.schematic_group_id,{width:f,height:p,center:C})}function Nht(r){var x;const{db:e}=r.root,t=r._parsedProps,n=r.children.filter(b=>b.pcb_component_id);if(n.length===0)return;let i=0,o=0;for(const b of n){const T=e.pcb_component.get(b.pcb_component_id);T&&(i=Math.max(i,T.width),o=Math.max(o,T.height))}i===0&&n.length>0&&(i=1),o===0&&n.length>0&&(o=1);let a=t.gridCols,s,l=t.gridGap;(x=t.pcbLayout)!=null&&x.grid&&(a=t.pcbLayout.grid.cols??a,s=t.pcbLayout.grid.rows,l=t.pcbLayout.grid.gap??l);let c,u;a!==void 0&&s!==void 0?(c=a,u=s):a!==void 0?(c=a,u=Math.ceil(n.length/c)):s!==void 0?(u=s,c=Math.ceil(n.length/u)):(c=Math.ceil(Math.sqrt(n.length)),u=Math.ceil(n.length/c)),c===0&&n.length>0&&(c=1),u===0&&n.length>0&&(u=n.length);let A,d;typeof l=="number"?(A=l,d=l):typeof l=="object"&&l!==null?(A=l.x,d=l.y):(A=1,d=1);const f=c*i+Math.max(0,c-1)*A,p=u*o+Math.max(0,u-1)*d,C=r._getGlobalPcbPositionBeforeLayout(),v=C.x-f/2+i/2,_=C.y+p/2-o/2;for(let b=0;b<n.length;b++){const T=n[b];if(!T.pcb_component_id)continue;const F=Math.floor(b/c),U=b%c;if(F>=u||U>=c){console.warn(`PCB grid layout: Child ${T.getString()} at index ${b} (row ${F}, col ${U}) exceeds grid dimensions (${u}x${c}). Skipping placement.`);continue}const H=v+U*(i+A),G=_-F*(o+d),j=e.pcb_component.get(T.pcb_component_id);if(j){const O=j.center,ne={x:H,y:G},te=ne.x-O.x,ie=ne.y-O.y,pe=QA(te,ie),de=e.toArray().filter(Ie=>Ie.pcb_component_id===T.pcb_component_id),Ae=gdt(de,pe);for(const Ie of Ae){const ge=mk(Ie);e[Ie.type].update(Ie[ge],Ie)}e.pcb_component.update(T.pcb_component_id,{center:ne}),T.setProps({...T.props,pcbX:(T.props.pcbX??0)+te,pcbY:(T.props.pcbY??0)+ie})}}r.pcb_group_id&&e.pcb_group.update(r.pcb_group_id,{width:f,height:p,center:C})}var Cj=class extends F1{constructor(){super(...arguments);Le(this,"pcb_group_id",null);Le(this,"schematic_group_id",null);Le(this,"subcircuit_id",null);Le(this,"_hasStartedAsyncAutorouting",!1);Le(this,"_asyncAutoroutingResult",null)}get config(){return{zodProps:RV,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,o,a;const{db:t}=this.root;if(!this.isSubcircuit)return;const n=(a=(o=(i=this.parent)==null?void 0:i.getSubcircuit)==null?void 0:o.call(i))==null?void 0:a.subcircuit_id;n&&t.source_group.update(this.source_group_id,{parent_subcircuit_id:n})}doInitialPcbComponentRender(){var o;if((o=this.root)!=null&&o.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 a of this.children)t.pcb_component.update(a.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=mj(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 a;const{_parsedProps:t}=this,{db:n}=this.root,i=t;if(!this.isSubcircuit)return;const o=(a=i.layout)==null?void 0:a.manual_trace_hints;if(o)for(const s of o)this.add(new Sve({for:s.pcb_port_selector,offsets:s.offsets}))}doInitialSourceAddConnectivityMapKey(){Dht(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=l0("tscircuit:core:_hasTracesToRoute"),n=this.selectAll("trace");return t(`[${this.getString()}] has ${n.length} traces to route`),n.length>0}async _runEffectMakeHttpAutoroutingRequest(){var u,A,d,f;const{db:t}=this.root,n=l0("tscircuit:core:_runEffectMakeHttpAutoroutingRequest");this._parsedProps;const i=this._getAutorouterConfig(),o=i.serverUrl,a=i.serverMode,s=(p,C)=>{var v;return n("fetching",p),C.headers&&(C.headers["Tscircuit-Core-Version"]=(v=this.root)==null?void 0:v.getCoreVersion()),fetch(p,C)},l=this.root.db.toArray().filter(p=>p.type.startsWith("source_")||p.type.startsWith("pcb_"));if(a==="solve-endpoint"){if(((u=this.props.autorouter)==null?void 0:u.inputFormat)==="simplified"){const{autorouting_result:C}=await s(`${o}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_simple_route_json:Qve({db:t,minTraceWidth:((A=this.props.autorouter)==null?void 0:A.minTraceWidth)??.15,subcircuit_id:this.subcircuit_id}).simpleRouteJson,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(v=>v.json());this._asyncAutoroutingResult=C,this._markDirty("PcbTraceRender");return}const{autorouting_result:p}=await s(`${o}/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=p,this._markDirty("PcbTraceRender");return}const{autorouting_job:c}=await s(`${o}/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(p=>p.json());for(;;){const{autorouting_job:p}=await s(`${o}/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(p.is_finished){const{autorouting_job_output:C}=await s(`${o}/autorouting/jobs/get_output`,{method:"POST",body:JSON.stringify({autorouting_job_id:c.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(v=>v.json());this._asyncAutoroutingResult={output_pcb_traces:C.output_pcb_traces},this._markDirty("PcbTraceRender");break}if(p.has_error)throw t.pcb_autorouting_error.insert({pcb_error_id:c.autorouting_job_id,message:((f=p.error)==null?void 0:f.message)??JSON.stringify(p.error)}),new Error(`Autorouting job failed: ${JSON.stringify(p.error)}`);await new Promise(C=>setTimeout(C,100))}}async _runLocalAutorouting(){var l,c,u,A,d;const{db:t}=this.root;this._parsedProps;const n=l0("tscircuit:core:_runLocalAutorouting");n(`[${this.getString()}] starting local autorouting`);const i=this._getAutorouterConfig(),{simpleRouteJson:o}=Qve({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:o});let a;i.algorithmFn?a=await i.algorithmFn(o):a=new bht(o,{capacityDepth:(u=this.props.autorouter)==null?void 0:u.capacityDepth,targetMinCapacity:(A=this.props.autorouter)==null?void 0:A.targetMinCapacity});const s=new Promise((f,p)=>{a.on("complete",C=>{n(`[${this.getString()}] local autorouting complete`),f(C.traces)}),a.on("error",C=>{n(`[${this.getString()}] local autorouting error: ${C.error.message}`),p(C.error)})});a.on("progress",f=>{var p;(p=this.root)==null||p.emit("autorouting:progress",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),...f})}),a.start();try{const f=await s;this._asyncAutoroutingResult={output_pcb_traces:f},this._markDirty("PcbTraceRender")}catch(f){const{db:p}=this.root;throw p.pcb_autorouting_error.insert({pcb_error_id:`pcb_autorouter_error_subcircuit_${this.subcircuit_id}`,message:f instanceof Error?f.message:String(f)}),(d=this.root)==null||d.emit("autorouting:error",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),error:{message:f instanceof Error?f.message:String(f)},simpleRouteJson:o}),f}finally{a.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=l0("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=l0("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 o=i.connection_name;i.source_trace_id=o}n.pcb_trace.insert(i)}for(const i of t)if(i.type!=="pcb_via"&&i.type==="pcb_trace")for(const o of i.route)o.route_type==="via"&&n.pcb_via.insert({pcb_trace_id:i.pcb_trace_id,x:o.x,y:o.y,hole_diameter:.3,outer_diameter:.6,layers:[o.from_layer,o.to_layer],from_layer:o.from_layer,to_layer:o.to_layer})}doInitialSchematicComponentRender(){var o;if((o=this.root)!=null&&o.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 a of this.children)a.schematic_component_id&&t.schematic_component.update(a.schematic_component_id,{schematic_group_id:i.schematic_group_id})}_getSchematicLayoutMode(){var n,i,o;const t=this._parsedProps;return(n=t.schLayout)!=null&&n.matchAdapt?"match-adapt":(i=t.schLayout)!=null&&i.flex?"flex":(o=t.schLayout)!=null&&o.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(){Mht(this)}_doInitialSchematicLayoutGrid(){Rht(this)}_getPcbLayoutMode(){var n,i,o;const t=this._parsedProps;return(n=t.pcbLayout)!=null&&n.matchAdapt?"match-adapt":(i=t.pcbLayout)!=null&&i.flex?"flex":(o=t.pcbLayout)!=null&&o.grid?"grid":t.matchAdapt?"match-adapt":t.flex?"flex":t.grid?"grid":"none"}doInitialPcbLayout(){this._getPcbLayoutMode()==="grid"&&this._doInitialPcbLayoutGrid()}_doInitialPcbLayoutGrid(){Nht(this)}_determineSideFromPosition(t,n){if(!t.center||!n.center)return"left";const i=t.center.x-n.center.x,o=t.center.y-n.center.y;return Math.abs(i)>Math.abs(o)?i>0?"right":"left":o>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,o=1/0,a=-1/0;for(const l of t)n=Math.min(n,l.centerX),i=Math.max(i,l.centerX),o=Math.min(o,l.centerY),a=Math.max(a,l.centerY);const s=2;return{minX:n-s,maxX:i+s,minY:o-s,maxY:a+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 o of this.children)if(!o.isSubcircuit&&o._parsedProps.name){const a=i.get(o._parsedProps.name)||[];a.push(o),i.set(o._parsedProps.name,a)}for(const[o,a]of i.entries())a.length>1&&t.pcb_trace_error.insert({error_type:"pcb_trace_error",message:`Multiple components found with name "${o}" in subcircuit "${this._parsedProps.name||"unnamed"}". Component names must be unique within a subcircuit.`,source_trace_id:"",pcb_trace_id:"",pcb_component_ids:a.map(s=>s.pcb_component_id).filter(Boolean),pcb_port_ids:[]})}}},Tht=class extends Cj{constructor(){super(...arguments);Le(this,"pcb_board_id",null);Le(this,"_drcChecksComplete",!1);Le(this,"_connectedSchematicPortPairs",new Set)}get isSubcircuit(){return!0}get isGroup(){return!0}get config(){return{componentName:"Board",zodProps:z8}}get boardThickness(){const{_parsedProps:t}=this;return 1.4}get allLayers(){return["top","bottom","inner1","inner2"]}doInitialPcbBoardAutoSize(){var p;if((p=this.root)!=null&&p.pcbDisabled||!this.pcb_board_id)return;const{db:t}=this.root,{_parsedProps:n}=this;if(n.width&&n.height)return;let i=1/0,o=1/0,a=-1/0,s=-1/0;const l=t.pcb_component.list();let c=!1;for(const C of l){const{width:v,height:_,center:x}=C;v===0||_===0||(c=!0,i=Math.min(i,x.x-v/2),o=Math.min(o,x.y-_/2),a=Math.max(a,x.x+v/2),s=Math.max(s,x.y+_/2))}const u=2,A=c?a-i+u*2:0,d=c?s-o+u*2:0,f={x:c?(i+a)/2+(n.outlineOffsetX??0):n.outlineOffsetX??0,y:c?(o+s)/2+(n.outlineOffsetY??0):n.outlineOffsetY??0};t.pcb_board.update(this.pcb_board_id,{width:A,height:d,center:f})}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,o=n.height??0;if(n.outline){const c=n.outline.map(C=>C.x),u=n.outline.map(C=>C.y),A=Math.min(...c),d=Math.max(...c),f=Math.min(...u),p=Math.max(...u);i=d-A,o=p-f}const a=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:o,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=a.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 c0()}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=XK(t.toArray());for(const o of n)t.pcb_trace_error.insert(o)}_emitRenderLifecycleEvent(t,n){var i;super._emitRenderLifecycleEvent(t,n),n==="start"&&((i=this.root)==null||i.emit("board:renderPhaseStarted",{renderId:this._renderId,phase:t}))}},Pht=new Proxy({},{get:(r,e)=>e}),fQ=Pht,kht=class extends F1{get config(){return{componentName:"Capacitor",schematicSymbolName:this.props.polarized?"capacitor_polarized":this.props.symbolName??"capacitor",zodProps:LV,sourceFtype:fQ.simple_capacitor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){const e=`${U1(this._parsedProps.capacitance)}F`;return this._parsedProps.schShowRatings&&this._parsedProps.maxVoltageRating?`${e}/${U1(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}},Mve=class extends F1{constructor(){super(...arguments);Le(this,"schematicBoxDimensions",null)}get config(){return{componentName:"Chip",zodProps:H8,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 o;if((o=this.root)!=null&&o.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()}},Uht=class extends F1{constructor(){super(...arguments);Le(this,"pos",this.portMap.pin1);Le(this,"anode",this.portMap.pin1);Le(this,"neg",this.portMap.pin2);Le(this,"cathode",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"diode",componentName:"Diode",zodProps:eK,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}},Fht=class extends F1{get config(){return{componentName:"fuse",schematicSymbolName:this.props.symbolName??"fuse",zodProps:Kme,sourceFtype:fQ.simple_fuse}}_getSchematicSymbolDisplayValue(){const e=this._parsedProps.currentRating,t=this._parsedProps.voltageRating,n=typeof e=="string"?parseFloat(e):e,i=typeof t=="string"?parseFloat(t):t;return`${U1(n)}A / ${U1(i)}V`}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=typeof t.currentRating=="string"?parseFloat(t.currentRating):t.currentRating,i=typeof t.voltageRating=="string"?parseFloat(t.voltageRating):t.voltageRating,o=e.source_component.insert({name:t.name,ftype:fQ.simple_fuse,current_rating_amps:n,voltage_rating_volts:i,display_current_rating:`${U1(n)}A`,display_voltage_rating:`${U1(i)}V`});this.source_component_id=o.source_component_id}},Lht=class extends F1{constructor(){super(...arguments);Le(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:NV,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 o;if((o=this.root)!=null&&o.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 u="";if(typeof(c==null?void 0:c.pin_number)=="number")u=c.pin_number.toString();else if(Array.isArray(c==null?void 0:c.port_hints)){let A=c.port_hints.find(d=>/^(pin)?\d+$/.test(d));A&&(/^pin\d+$/.test(A)?u=A.replace(/^pin/,""):u=A)}i[u]=l.pcb_port_id}const o=t.pcb_trace.list(),a=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 o)if(s.route)for(const l of s.route)l.route_type==="wire"&&(l.start_pcb_port_id=a(l.start_pcb_port_id),l.end_pcb_port_id=a(l.end_pcb_port_id))}},Ght=class extends F1{constructor(){super(...arguments);Le(this,"pos",this.portMap.pin1);Le(this,"anode",this.portMap.pin1);Le(this,"neg",this.portMap.pin2);Le(this,"cathode",this.portMap.pin2)}get config(){return{componentName:"Led",schematicSymbolName:this.props.symbolName??"led",zodProps:tK,sourceFtype:"simple_led"}}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_led",name:n.name,wave_length:n.wavelength,color:n.color,manufacturer_part_number:n.manufacturerPartNumber??n.mfn,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},Oht=class extends F1{constructor(){super(...arguments);Le(this,"pos",this.portMap.pin1);Le(this,"positive",this.portMap.pin1);Le(this,"neg",this.portMap.pin2);Le(this,"negative",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"power_factor_meter_horz",componentName:"PowerSource",zodProps:sK,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}},zht=class extends F1{get config(){return{componentName:"Resistor",schematicSymbolName:this.props.symbolName??"boxresistor",zodProps:PV,sourceFtype:"simple_resistor"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${U1(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}},Hht=["leftedge","rightedge","topedge","bottomedge","center"],Yht=class extends nI{get config(){return{componentName:"Constraint",zodProps:GV}}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 o=i.split(" ").pop(),a=Hht.includes(o)?o:void 0,s=a?i.replace(` ${a}`,""):i,l=t.selectOne(s,{pcbPrimitive:!0});l&&e.push({selector:i,component:l,componentSelector:s,edge:a})}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}}},Vht=class extends nI{constructor(){super(...arguments);Le(this,"fabrication_note_path_id",null)}get config(){return{componentName:"FabricationNotePath",zodProps:iK}}doInitialPcbPrimitiveRender(){var l,c;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,n=this.getSubcircuit(),{_parsedProps:i}=this,o=i.layer??"top";if(o!=="top"&&o!=="bottom")throw new Error(`Invalid layer "${o}" for SilkscreenPath. Must be "top" or "bottom".`);const a=this._computePcbGlobalTransformBeforeLayout(),s=t.pcb_fabrication_note_path.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:o,color:i.color,route:i.route.map(u=>{const A=Wr(a,{x:u.x,y:u.y});return{...u,x:A.x,y:A.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}},Kht=class extends nI{get config(){return{componentName:"FabricationNoteText",zodProps:rK}}doInitialPcbPrimitiveRender(){var o,a;if((o=this.root)!=null&&o.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:((a=this.getGroup())==null?void 0:a.pcb_group_id)??void 0})}},jht=class extends Cj{constructor(e){super({...e,subcircuit:!0})}},Jht=class extends nI{constructor(){super(...arguments);Le(this,"source_net_alias_id")}get config(){return{componentName:"NetAlias",zodProps:WV}}doInitialSchematicComponentRender(){var a;if((a=this.root)!=null&&a.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i={x:n.schX??0,y:n.schY??0},o=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=o.source_net_id}},Wht=class extends nI{constructor(){super(...arguments);Le(this,"pcb_silkscreen_circle_id",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenCircle",zodProps:hK}}doInitialPcbPrimitiveRender(){var l,c,u;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),o=i(n.layer??"top");if(o!=="top"&&o!=="bottom")throw new Error(`Invalid layer "${o}" for SilkscreenCircle. Must be "top" or "bottom".`);this._computePcbGlobalTransformBeforeLayout();const a=this.getSubcircuit(),s=t.pcb_silkscreen_circle.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:o,center:{x:n.pcbX??0,y:n.pcbY??0},radius:n.radius,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,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}}},qht=class extends nI{constructor(){super(...arguments);Le(this,"pcb_silkscreen_rect_id",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenRect",zodProps:fK}}doInitialPcbPrimitiveRender(){var l,c,u;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),o=i(n.layer??"top");if(o!=="top"&&o!=="bottom")throw new Error(`Invalid layer "${o}" for SilkscreenRect. Must be "top" or "bottom".`);const a=this.getSubcircuit(),s=t.pcb_silkscreen_rect.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:o,center:{x:n.pcbX??0,y:n.pcbY??0},width:n.width,height:n.height,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((u=this==null?void 0:this.getGroup())==null?void 0:u.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}}},Zht=class extends nI{constructor(){super(...arguments);Le(this,"pcb_silkscreen_line_id",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenLine",zodProps:dK}}doInitialPcbPrimitiveRender(){var l,c,u;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),o=i(n.layer??"top");if(o!=="top"&&o!=="bottom")throw new Error(`Invalid layer "${o}" for SilkscreenLine. Must be "top" or "bottom".`);const a=this.getSubcircuit(),s=t.pcb_silkscreen_line.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:o,x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2,stroke_width:n.strokeWidth??.1,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((u=a==null?void 0:a.getGroup())==null?void 0:u.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}}},Xht=class extends nI{constructor(){super(...arguments);Le(this,"pcb_via_id",null);Le(this,"matchedPort",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Via",zodProps:oK}}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(),o=this.getSubcircuit(),a=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:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((l=this.getGroup())==null?void 0:l.pcb_group_id)??void 0});this.pcb_via_id=a.pcb_via_id}},$ht=class extends nI{constructor(){super(...arguments);Le(this,"pcb_cutout_id",null);Le(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Cutout",zodProps:OV}}doInitialPcbPrimitiveRender(){var l,c;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getSubcircuit(),o=((c=this.getGroup())==null?void 0:c.pcb_group_id)??void 0,a=this._getGlobalPcbPositionBeforeLayout();let s;if(n.shape==="rect"){const u={shape:"rect",center:a,width:n.width,height:n.height,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:o};s=t.pcb_cutout.insert(u)}else if(n.shape==="circle"){const u={shape:"circle",center:a,radius:n.radius,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:o};s=t.pcb_cutout.insert(u)}else if(n.shape==="polygon"){const u=this._computePcbGlobalTransformBeforeLayout(),d={shape:"polygon",points:n.points.map(f=>Wr(u,f)),subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:o};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,o=1/0,a=-1/0;for(const s of t.points)n=Math.min(n,s.x),i=Math.max(i,s.x),o=Math.min(o,s.y),a=Math.max(a,s.y);return{width:i-n,height:a-o}}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,o=-1/0,a=1/0,s=-1/0;for(const l of n.points)i=Math.min(i,l.x),o=Math.max(o,l.x),a=Math.min(a,l.y),s=Math.max(s,l.y);return{center:{x:(i+o)/2,y:(a+s)/2},bounds:{left:i,top:s,right:o,bottom:a},width:o-i,height:s-a}}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 o=this._getPcbCircuitJsonBounds().center,a=t.x-o.x,s=t.y-o.y,l=i.points.map(c=>({x:c.x+a,y:c.y+s}));n.pcb_cutout.update(this.pcb_cutout_id,{...i,points:l})}}}},ept=class extends F1{get config(){return{componentName:"Battery",schematicSymbolName:this.props.symbolName??"battery",zodProps:jV,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}},tpt=class extends F1{get config(){return{componentName:"PinHeader",zodProps:JV,shouldRenderAsSchematicBox:!0}}_getImpliedFootprintString(){var o;const e=this._parsedProps.pinCount??((o=this._parsedProps.pinLabels)==null?void 0:o.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,o,a,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:((o=n==null?void 0:n.leftSide)==null?void 0:o.pins)??Array.from({length:e},(l,c)=>`pin${c+1}`)}}:{rightSide:{direction:((a=n==null?void 0:n.rightSide)==null?void 0:a.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 npt(r){switch(r){case"two_ground_pins":return"crystal_4pin";case"ground_pin":return"resonator";case"no_ground":return"crystal";default:return"crystal"}}var rpt=class extends F1{get config(){return{componentName:"Resonator",schematicSymbolName:this.props.symbolName??npt(this.props.pinVariant),zodProps:FV,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}},ipt=class extends F1{get config(){return{componentName:"Inductor",schematicSymbolName:this.props.symbolName??"inductor",zodProps:$V,sourceFtype:fQ.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:fQ.simple_inductor,inductance:t.inductance,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}};function opt(r){switch(r){case"three_pin":return"potentiometer3";case"two_pin":return"potentiometer2";default:return"potentiometer2"}}var apt=class extends F1{get config(){return{componentName:"Potentiometer",schematicSymbolName:this.props.symbolName??opt(this.props.pinVariant),zodProps:kV,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}},spt=class extends F1{get config(){return{componentName:"PushButton",schematicSymbolName:this.props.symbolName??"push_button_normally_open_momentary",zodProps:qV,sourceFtype:fQ.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:fQ.simple_push_button,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}},lpt=class extends F1{get config(){return{schematicSymbolName:this.props.symbolName??(this.props.pinVariant==="four_pin"?"crystal_4pin":"crystal"),componentName:"Crystal",zodProps:UV,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`${U1(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}},cpt=class extends F1{constructor(){super(...arguments);Le(this,"emitter",this.portMap.pin1);Le(this,"collector",this.portMap.pin2);Le(this,"base",this.portMap.pin3)}get config(){return{componentName:"Transistor",schematicSymbolName:this.props.type==="npn"?"npn_bipolar_transistor":"pnp_bipolar_transistor",zodProps:ZV,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}},upt=class extends F1{get config(){const e=this.props.mosfetMode==="depletion"?"d":"e";return{componentName:"Mosfet",schematicSymbolName:`${this.props.channelType}_channel_${e}_mosfet_transistor`,zodProps:XV,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}},Apt=class extends F1{_getSwitchType(){const{spst:e,spdt:t,dpst:n,dpdt:i,type:o}=this._parsedProps??{};return i?"dpdt":e?"spst":t?"spdt":n?"dpst":o??"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:nK,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}},dpt=class extends nI{constructor(){super(...arguments);Le(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicText",zodProps:cK}}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})}},fpt=class extends nI{constructor(){super(...arguments);Le(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicBox",zodProps:V8,shouldRenderAsSchematicBox:!0}}doInitialSchematicPrimitiveRender(){var _;if((_=this.root)!=null&&_.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=V8.safeParse(n);if(!i.success)throw console.error("Validation failed:",i.error.format()),i.error;const o=.6,a=typeof n.padding=="number"?n.padding:0,s=typeof n.paddingTop=="number"?n.paddingTop:a,l=typeof n.paddingBottom=="number"?n.paddingBottom:a,c=typeof n.paddingLeft=="number"?n.paddingLeft:a,u=typeof n.paddingRight=="number"?n.paddingRight:a,A=n.overlay&&n.overlay.length>0,d=typeof n.width=="number"&&typeof n.height=="number";let f,p,C,v;if(A){const b=n.overlay.map(Se=>({selector:Se,port:this.getSubcircuit().selectOne(Se,{type:"port"})})).filter(({port:Se})=>Se!=null).map(({port:Se})=>({position:Se._getGlobalSchematicPositionAfterLayout()}));if(b.length===0)return;const T=b.map(Se=>Se.position.x),F=b.map(Se=>Se.position.y),U=Math.min(...T),H=Math.max(...T),G=Math.min(...F),j=Math.max(...F),O=H-U,ne=j-G,te=O===0?o:0,ie=ne===0?o:0,pe=c+te/2,de=u+te/2,Ae=s+ie/2,Ie=l+ie/2,ge=U-pe,Me=H+de,be=G-Ie,Re=j+Ae;f=Me-ge,p=Re-be,C=ge+(n.schX??0),v=be+(n.schY??0)}else if(d){f=n.width,p=n.height;const x=typeof n.schX=="number"?n.schX:0,b=typeof n.schY=="number"?n.schY:0;C=x-f/2,v=b-p/2}else return;t.schematic_box.insert({height:p,width:f,x:C,y:v,is_dashed:n.strokeStyle==="dashed",schematic_component_id:""})}};new Proxy({},{get:(r,e)=>{const t=(...n)=>(n[0],new Proxy({},{get:(i,o)=>`.${e} > .${o}`}));return new Proxy(t,{get:(n,i)=>e==="net"?`net.${i}`:e==="subcircuit"?new Proxy({},{get:(o,a)=>new Proxy({},{get:(s,l)=>`subcircuit.${i} > .${a} > .${l}`})}):`.${e} > .${i}`,apply:(n,i,o)=>new Proxy({},{get:(a,s)=>{const l=`.${e} > .${s}`;return e.startsWith("U")?l:new Proxy(new String(l),{get:(c,u)=>typeof u=="symbol"||u==="toString"?()=>l:`.${e} > .${s} > .${u}`})}})})}}),cve(sve),cve({Bug:Mve});const Dve=l0("run-frame"),hpt={},Rve=r=>{let e;const t=new Set,n=(u,A)=>{const d=typeof u=="function"?u(e):u;if(!Object.is(d,e)){const f=e;e=A??(typeof d!="object"||d===null)?d:Object.assign({},e,d),t.forEach(p=>p(e,f))}},i=()=>e,l={setState:n,getState:i,getInitialState:()=>c,subscribe:u=>(t.add(u),()=>t.delete(u)),destroy:()=>{(hpt?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),t.clear()}},c=e=r(n,i,l);return l},Nve=r=>r?Rve(r):Rve;var Sk={exports:{}},_j={},wk={exports:{}},Ej={};/**
|
|
855
855
|
* @license React
|
|
856
856
|
* use-sync-external-store-shim.production.js
|
|
@@ -13494,7 +13494,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}return Wle}yJt();function u6e(r,e,t,n=
|
|
|
13494
13494
|
&:hover {
|
|
13495
13495
|
background-color: rgba(255, 255, 255, 0.1);
|
|
13496
13496
|
}
|
|
13497
|
-
`,onClick:n=>{n.stopPropagation(),t()},children:[Ve.jsx("input",{type:"checkbox",checked:e}),Ve.jsx("span",{style:{color:"#eee"},children:r})]}),VZt=({children:r,elements:e})=>{const[t,n]=V1(G=>[G.is_mouse_over_container,G.setIsMouseOverContainer]),[i,o]=nt.useState(!1),[a,s]=nt.useState(!1),[l,c]=nt.useState(!1),[u,A]=V1(G=>[G.selected_layer,G.selectLayer]),[d,f,p,C,v,_]=V1(G=>[G.in_move_footprint_mode,G.in_draw_trace_mode,G.is_showing_rats_nest,G.is_showing_multiple_traces_length,G.is_showing_autorouting,G.is_showing_drc_errors]),x=V1(G=>G.setEditMode),b=V1(G=>G.setIsShowingRatsNest),T=V1(G=>G.setIsShowingMultipleTracesLength),F=V1(G=>G.setIsShowingAutorouting),U=V1(G=>G.setIsShowingDrcErrors);Hw("1",()=>A("top")),Hw("2",()=>A("bottom")),Hw("3",()=>A("inner1")),Hw("4",()=>A("inner2")),Hw("5",()=>A("inner3")),Hw("6",()=>A("inner4")),Hw("7",()=>A("inner5")),Hw("8",()=>A("inner6"));const H=(e==null?void 0:e.filter(G=>G.type.includes("error")).length)??0;return Ve.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>{n(!0)},onMouseLeave:G=>{n(!1),s(!1)},children:[r,Ve.jsxs("div",{style:{position:"absolute",bottom:4,right:8,pointerEvents:"none",color:"white",fontSize:11,opacity:t?.5:0,transition:"opacity 1s",transitionDelay:"2s",fontFamily:"sans-serif"},children:["@tscircuit/pcb-viewer@",HZt.version]}),Ve.jsxs("div",{style:{position:"absolute",opacity:t?1:0,top:16,left:16,transition:t?"opacity 100ms linear":"opacity 1s linear",zIndex:fx.toolbarOverlay,color:"red",display:"flex",fontSize:12,height:100,fontFamily:"sans-serif"},children:[Ve.jsxs(ED,{onClick:()=>{s(!a)},onMouseLeave:()=>{a&&s(!1)},children:[Ve.jsxs("div",{children:["layer:"," ",Ve.jsx("span",{style:{marginLeft:2,fontWeight:500,color:_D[u]},children:u})]}),a&&Ve.jsx("div",{style:{marginTop:4,minWidth:120},children:Mce.map(G=>G.replace(/-/g,"")).map(G=>Ve.jsx(YZt,{name:G,selected:G===u,onClick:()=>{A(G.replace(/-/,""))}},G))})]}),Ve.jsxs(ED,{style:H>0?{color:"red"}:{},onClick:()=>c(!l),onMouseLeave:()=>c(!1),children:[Ve.jsxs("div",{children:[H," errors"]}),l&&Ve.jsx("div",{style:{display:"grid",gridTemplateColumns:"100px 300px"},children:e==null?void 0:e.filter(G=>G.type.includes("error")).map((G,j)=>Ve.jsxs(nt.Fragment,{children:[Ve.jsx("div",{children:G.error_type}),Ve.jsx("div",{children:G.message})]},j))})]}),Ve.jsx(ED,{style:{},onClick:()=>{x(f?"off":"draw_trace")},children:Ve.jsxs("div",{children:[f?"✖ ":"","Edit Traces"]})}),Ve.jsx(ED,{style:{},onClick:()=>{x(d?"off":"move_footprint")},children:Ve.jsxs("div",{children:[d?"✖ ":"","Move Components"]})}),Ve.jsx(ED,{style:{},onClick:()=>{b(!p)},children:Ve.jsxs("div",{children:[p?"✖ ":"","Rats Nest"]})}),Ve.jsx(ED,{onClick:()=>{o(!i)},children:Ve.jsxs("div",{children:[Ve.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:["View"," ",Ve.jsx("span",{style:{fontSize:"8px",transform:i?"rotate(180deg)":"rotate(0)",transition:"transform 0.1s ease",display:"inline-block"},children:"▼"})]}),i&&Ve.jsxs("div",{style:{marginTop:4,minWidth:120},children:[Ve.jsx(kce,{label:"Show All Trace Lengths",checked:C,onClick:()=>{T(!C)}}),Ve.jsx(kce,{label:"Show Autorouting Animation",checked:v,onClick:()=>{F(!v)}}),Ve.jsx(kce,{label:"Show DRC Errors",checked:_,onClick:()=>{U(!_)}})]})]})})]})]})},KZt=r=>{const{transform:e,elements:t}=r,[n,i]=nt.useMemo(()=>{const c=r.elements.flatMap(A=>rZt(A,r.elements)),u=lB(r.elements);return[c,u]},[r.elements]),[o,a]=nt.useState({drawingObjectIdsWithMouseOver:new Set,primitiveIdsInMousedOverNet:[]}),s=nt.useMemo(()=>tZt({primitivesWithoutInteractionMetadata:n,drawingObjectIdsWithMouseOver:o.drawingObjectIdsWithMouseOver,primitiveIdsInMousedOverNet:o.primitiveIdsInMousedOverNet}),[n,o]),l=nt.useCallback(c=>{var d,f;const u=[];for(const p of c)if(p._element){const C=i.getNetConnectedToId("pcb_port_id"in p._element?(d=p._element)==null?void 0:d.pcb_port_id:"pcb_trace_id"in p._element?(f=p._element)==null?void 0:f.pcb_trace_id:"");u.push(...i.getIdsConnectedToNet(C))}const A=new Set(c.map(p=>p._pcb_drawing_object_id));a({drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:u})},[i]);return Ve.jsx(OZt,{elements:t,transform:e,primitives:n,onMouseHoverOverPrimitives:l,children:Ve.jsx(xZt,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:Ve.jsx(wZt,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:Ve.jsx(_Zt,{transform:e,focusOnHover:r.focusOnHover,children:Ve.jsx(VZt,{elements:t,children:Ve.jsx(DZt,{transform:e,elements:t,children:Ve.jsx(zZt,{transform:e,soup:t,children:Ve.jsx(IZt,{transform:e,debugGraphics:r.debugGraphics,children:Ve.jsx(CZt,{transform:e,elements:t,children:Ve.jsx(vZt,{transform:e,primitives:s,width:r.width,height:r.height,grid:r.grid})})})})})})})})})})},jZt=Qc(QA(400,300),P1(40,-40)),JZt=({circuitJson:r,debugGraphics:e,height:t=600,initialState:n,allowEditing:i=!0,editEvents:o,onEditEventsChanged:a,focusOnHover:s=!1,clickToInteractEnabled:l=!1})=>{const[c,u]=nt.useState(!l),[A,d]=Tce(),[f,p]=nt.useState(jZt),{ref:C,setTransform:v,cancelDrag:_}=eZt({transform:f,onSetTransform:p,enabled:c});let[x,b]=nt.useState([]);x=o??x;const T=nt.useRef(!1),F=nt.useRef(null),U=`${(r==null?void 0:r.length)||0}_${(r==null?void 0:r.editCount)||0}`,H=()=>{const te=(d==null?void 0:d.width)>0?d:{width:500,height:500},{center:ie,width:pe,height:de}=j.some(ge=>ge.type.startsWith("pcb_"))?Yqt(j.filter(ge=>ge.type.startsWith("pcb_"))):{center:{x:0,y:0},width:.001,height:.001},Ae=Math.min((te.width??0)/pe,(te.height??0)/de,100)*.75,Ie=Qc(QA((te.width??0)/2,(te.height??0)/2),P1(Ae,-Ae,0,0),QA(-ie.x,-ie.y));v(Ie)};nt.useEffect(()=>{d!=null&&d.width&&r&&r.length!==0&&(T.current||(H(),T.current=!0))},[r,d]);const G=nt.useMemo(()=>(r==null?void 0:r.filter(te=>te.type.startsWith("pcb_")||te.type.startsWith("source_")))??[],[U]),j=nt.useMemo(()=>ujt({circuitJson:G,editEvents:x}),[G,x]),O=te=>{b([...x,te]),a==null||a([...x,te])},ne=te=>{const ie=x.map(pe=>pe.edit_event_id===te.edit_event_id?{...pe,...te}:pe);b(ie),a==null||a(ie)};return Ve.jsxs("div",{ref:C,style:{position:"relative"},children:[Ve.jsx("div",{ref:A,children:Ve.jsxs(Kqt,{initialState:n,children:[Ve.jsx(KZt,{transform:f,height:t,width:d.width,allowEditing:i,focusOnHover:s,cancelPanDrag:_,onCreateEditEvent:O,onModifyEditEvent:ne,grid:{spacing:1,view_window:{left:0,right:d.width||500,top:t,bottom:0}},elements:j,debugGraphics:e},d.width),Ve.jsx(Jqt,{})]})}),l&&!c&&Ve.jsx("div",{onClick:()=>{u(!0),H()},onTouchStart:te=>{const ie=te.touches[0];F.current={x:ie.clientX,y:ie.clientY}},onTouchEnd:te=>{const ie=te.changedTouches[0],pe=F.current;if(!pe)return;const de=Math.abs(ie.clientX-pe.x),Ae=Math.abs(ie.clientY-pe.y);de<10&&Ae<10&&(te.preventDefault(),u(!0),H()),F.current=null},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:fx.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center",touchAction:"pan-x pan-y pinch-zoom"},children:Ve.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",pointerEvents:"none"},children:typeof window<"u"&&("ontouchstart"in window||navigator.maxTouchPoints>0)?"Touch to Interact":"Click to Interact"})})]})};const WZt=({containerClassName:r,...e})=>{const t=nt.useRef(null),[n,i]=nt.useState(620);return nt.useLayoutEffect(()=>{const o=()=>{if(t.current){const s=t.current.clientHeight,l=window.innerHeight;i(Math.min(Math.max(s,620),l))}};o();const a=new ResizeObserver(o);return t.current&&a.observe(t.current),window.addEventListener("resize",o),()=>{a.disconnect(),window.removeEventListener("resize",o)}},[]),Ve.jsx("div",{ref:t,className:r||"rf-w-full rf-h-full",children:Ve.jsx(JZt,{...e,height:n})})},qZt='*,: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}',ZZt=()=>{nt.useEffect(()=>{if(document.querySelector('style[data-styles="tscircuit-runframe"]'))return;const e=document.createElement("style");e.setAttribute("data-styles","tscircuit-runframe"),e.textContent=qZt,document.head.appendChild(e)},[])},x7e=r=>`hsl(${jx.indexOf(r)*137.5%360}, 70%, 50%)`,XZt=({phaseTimings:r})=>{if(!r)return null;const e=Object.values(r).reduce((t,n)=>t+n,0);return Ve.jsxs("div",{className:"rf-space-y-2 rf-w-full rf-px-4",children:[Ve.jsx("div",{className:"rf-relative rf-h-8 rf-flex rf-rounded-sm",children:jx.map(t=>{const n=r[t]||0,i=n/e*100;return Ve.jsx("div",{className:"rf-group/bar rf-relative rf-overflow-visible",style:{width:`${i}%`,backgroundColor:x7e(t)},children:Ve.jsxs("div",{className:"rf-opacity-0 group-hover/bar:rf-opacity-100 rf-transition-opacity rf-absolute rf-bottom-full rf-left-1/2 rf-transform -rf-translate-x-1/2 rf-mb-2 rf-px-2 rf-py-1 rf-text-xs rf-whitespace-nowrap rf-rounded rf-bg-gray-900 rf-text-white rf-pointer-events-none",children:[t,": ",n.toFixed(1),"ms"]})},t)})}),Ve.jsxs("div",{className:"rf-text-xs rf-text-gray-500",children:["Total: ",e.toFixed(2),"ms"]})]})},$Zt=({renderLog:r})=>{const[e,t]=nt.useState("chronological");if(!r)return Ve.jsx("div",{className:"rf-p-4 rf-bg-gray-100 rf-rounded-md",children:"No render log, make sure this tab is open when you render (TODO add a rerender button here)"});const n=Object.entries((r==null?void 0:r.phaseTimings)??{});e==="chronological"?n.sort((o,a)=>jx.indexOf(o[0])-jx.indexOf(a[0])):n.sort((o,a)=>a[1]-o[1]);const i=n.reduce((o,[a,s])=>o+s,0);return Ve.jsxs("div",{className:"rf-bg-white",children:[Ve.jsxs("div",{className:"rf-flex rf-justify-between rf-items-center",children:[Ve.jsx("div",{children:"Render Logs"}),Ve.jsxs("div",{className:"rf-mb-4 rf-pr-2 rf-flex rf-text-xs rf-items-center",children:[Ve.jsx("div",{className:"rf-mr-2",children:"Sort by:"}),Ve.jsxs("select",{value:e,onChange:o=>t(o.target.value),className:"rf-px-2 rf-py-1 rf-border rf-rounded rf-text-xs",children:[Ve.jsx("option",{value:"chronological",children:"Phase Order"}),Ve.jsx("option",{value:"longest",children:"Duration"})]})]})]}),Ve.jsx(XZt,{phaseTimings:r.phaseTimings}),Ve.jsxs("table",{className:"rf-w-full rf-text-xs",children:[Ve.jsx("thead",{children:Ve.jsxs("tr",{children:[Ve.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase Order"}),Ve.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase"}),Ve.jsx("th",{className:"rf-text-left rf-p-2",children:"Duration (ms)"})]})}),Ve.jsx("tbody",{children:n.map(([o,a])=>Ve.jsxs("tr",{children:[Ve.jsx("td",{className:"rf-p-2",children:jx.indexOf(o)}),Ve.jsx("td",{className:"rf-p-2",children:o}),Ve.jsx("td",{className:"rf-p-2",children:Ve.jsx("div",{className:"rf-w-8",children:Ve.jsx("div",{className:"rf-h-2 rf-rounded-sm",style:{backgroundColor:x7e(o),width:`${a/i*100}%`}})})}),Ve.jsx("td",{className:"rf-p-2",children:Ve.jsxs("div",{className:"rf-flex w-full",children:[Ve.jsxs("span",{className:"rf-flex-grow",children:[a,"ms"]}),Ve.jsxs("span",{className:"rf-text-gray-500 rf-pr-2",children:[(a/i*100).toFixed(1),"%"]})]})})]},o))})]})]})},eXt="0.0.538",tXt=["assembly","bom","circuit_json","errors","render_log"],nXt=({code:r,onRunClicked:e=void 0,errorMessage:t,circuitJson:n,autoroutingGraphics:i,showRightHeaderContent:o=!0,showCodeTab:a=!1,codeTabContent:s,showJsonTab:l=!0,showRenderLogTab:c=!0,onActiveTabChange:u,renderLog:A,showImportAndFormatButtons:d=!0,className:f,headerClassName:p,leftHeaderContent:C,readOnly:v,isStreaming:_,autoroutingLog:x,onReportAutoroutingLog:b,isRunningCode:T,hasCodeChangedSinceLastRun:F,onEditEvent:U,editEvents:H,defaultActiveTab:G,autoRotate3dViewerDisabled:j,showSchematicDebugGrid:O=!1,showToggleFullScreen:ne=!0,defaultToFullScreen:te=!1})=>{var Re;ZZt();const ie=nt.useMemo(()=>n?n.filter(Se=>Se&&"error_type"in Se||Se.type.includes("error")):null,[n]),[pe,de]=nt.useState(G??"pcb"),[Ae,Ie]=nt.useState(te),ge=nt.useCallback(Se=>{de(Se),u==null||u(Se)},[u]),Me=()=>{Ie(!Ae)};nt.useEffect(()=>{t&&ge("errors")},[t]),nt.useEffect(()=>{(pe==="code"||pe==="errors")&&n&&!t&&ge(G??"pcb")},[n]);const be=nt.useCallback(Se=>{window.TSCIRCUIT_3D_OBJECT_REF=Se===null?void 0:Se},[]);return Ve.jsx("div",{className:Mp("flex flex-col relative rf-overflow-x-hidden",f),children:Ve.jsx("div",{className:Mp("rf-md:sticky rf-md:top-2",Ae&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-bg-white"),children:Ve.jsxs(SIe,{value:pe,onValueChange:ge,className:"rf-flex-grow rf-flex rf-flex-col",children:[Ve.jsxs("div",{className:Mp("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",p),children:[C,C&&Ve.jsx("div",{className:"rf-flex-grow"}),!C&&T&&Ve.jsx($3,{className:"rf-w-4 rf-h-4 rf-animate-spin"}),!C&&Ve.jsx("div",{className:"rf-flex-grow"}),A&&A.progress!==1&&!t&&Ve.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[A.lastRenderEvent&&Ve.jsx("div",{className:"rf-text-xs rf-text-gray-500",children:((Re=A.lastRenderEvent)==null?void 0:Re.phase)??""}),Ve.jsx("div",{className:"rf-w-4 rf-h-4 rf-bg-blue-500 rf-opacity-50 rf-rounded-full rf-text-white",children:Ve.jsx($3,{className:"rf-w-4 rf-h-4 rf-animate-spin"})}),Ve.jsxs("div",{className:"rf-text-xs rf-font-bold rf-text-gray-700 rf-tabular-nums",children:[((A.progress??0)*100).toFixed(1),"%"]})]}),o&&Ve.jsxs(Lj,{children:[a&&Ve.jsx(sw,{value:"code",children:"Code"}),Ve.jsxs(sw,{value:"pcb",className:"rf-whitespace-nowrap",children:[n&&Ve.jsx("span",{className:Mp("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",F?"rf-bg-gray-500":"rf-bg-blue-500")}),"PCB"]}),Ve.jsxs(sw,{value:"schematic",className:"rf-whitespace-nowrap",children:[n&&Ve.jsx("span",{className:Mp("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",F?"rf-bg-gray-500":"rf-bg-blue-500")}),"Schematic"]}),Ve.jsxs(sw,{value:"cad",children:[n&&Ve.jsx("span",{className:Mp("inline-flex items-center justify-center w-2 h-2 mr-1 text-xs font-bold text-white rounded-full",F?"rf-bg-gray-500":"rf-bg-blue-500")}),"3D"]}),!["pcb","cad","schematic"].includes(pe)&&Ve.jsx(sw,{value:pe,children:BIe(pe)}),Ve.jsxs(Vse,{children:[Ve.jsx(Kse,{asChild:!0,children:Ve.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[Ve.jsx(T7t,{className:"rf-w-4 rf-h-4"}),(ie&&ie.length>0||t)&&Ve.jsx("span",{className:"rf-inline-flex rf-absolute rf-top-[6px] rf-right-[4px] rf-items-center rf-justify-center rf-w-1 rf-h-1 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full"})]})}),Ve.jsxs(pG,{className:"rf-*:text-xs",children:[tXt.map(Se=>Ve.jsxs(CB,{onSelect:()=>ge(Se),children:[pe!==Se&&Ve.jsx(cke,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),pe===Se&&Ve.jsx($ae,{className:"rf-w-3 rf-h-3"}),Ve.jsx("div",{className:"rf-pr-2",children:BIe(Se)}),Se==="errors"&&(ie&&ie.length>0||t)&&Ve.jsx("span",{className:"rf-inline-flex rf-items-center rf-justify-center rf-w-3 rf-h-3 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full",children:t?1:ie==null?void 0:ie.length})]},Se)),Ve.jsx(CB,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:Ve.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/runframe@",eXt.split(".").map((Se,Ke)=>Ke===2?parseInt(Se)+1:Se).join(".")]})})]})]})]}),ne&&Ve.jsx(TE,{onClick:Me,variant:"ghost",children:Ae?Ve.jsx(F7t,{size:16}):Ve.jsx(k7t,{size:16})})]}),a&&Ve.jsx(WB,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:Ve.jsx("div",{className:"rf-h-full",children:s})}),Ve.jsx(WB,{value:"pcb",children:Ve.jsx("div",{className:Mp("rf-overflow-hidden",Ae?"rf-h-[calc(100vh-52px)]":"rf-h-[620px]"),children:Ve.jsx(X3,{fallbackRender:({error:Se})=>Ve.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ve.jsxs("div",{className:"rf-p-4",children:[Ve.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading PCB viewer"}),Ve.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Se==null?void 0:Se.message)||"An unknown error occurred"})]})}),children:n?Ve.jsx(WZt,{focusOnHover:!1,circuitJson:n,debugGraphics:i,containerClassName:Mp("rf-h-full rf-w-full",Ae?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:Se=>{U&&Se.forEach(Ke=>U(Ke))}}):Ve.jsx(Q9,{onRunClicked:e})})})}),Ve.jsx(WB,{value:"assembly",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",Ae?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(X3,{fallback:Ve.jsx("div",{children:"Error loading Assembly"}),children:n?Ve.jsx(uKt,{circuitJson:n,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):Ve.jsx(Q9,{onRunClicked:e})})})}),Ve.jsx(WB,{value:"schematic",children:Ve.jsx("div",{className:Mp("rf-overflow-auto rf-bg-white",Ae?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(X3,{fallbackRender:({error:Se})=>Ve.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ve.jsxs("div",{className:"rf-p-4",children:[Ve.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Schematic"}),Ve.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Se==null?void 0:Se.message)||"An unknown error occurred"})]})}),children:n?Ve.jsx(sKt,{circuitJson:n,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:Se=>{U==null||U(Se)},debugGrid:O}):Ve.jsx(Q9,{onRunClicked:e})})})}),Ve.jsx(WB,{value:"cad",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",Ae?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(X3,{FallbackComponent:C7t,children:n?Ve.jsx(v7t,{ref:be,circuitJson:n,autoRotateDisabled:j}):Ve.jsx(Q9,{onRunClicked:e})})})}),Ve.jsx(WB,{value:"bom",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",Ae?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(X3,{fallbackRender:({error:Se})=>Ve.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ve.jsxs("div",{className:"rf-p-4",children:[Ve.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Bill of Materials"}),Ve.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Se==null?void 0:Se.message)||"An unknown error occurred"})]})}),children:n?Ve.jsx(pKt,{circuitJson:n}):Ve.jsx(Q9,{onRunClicked:e})})})}),Ve.jsx(WB,{value:"circuit_json",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",Ae?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(X3,{fallback:Ve.jsx("div",{children:"Error loading JSON viewer"}),children:n?Ve.jsx(fKt,{elements:n}):Ve.jsx(Q9,{onRunClicked:e})})})}),Ve.jsx(WB,{value:"errors",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",Ae?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:t||ie&&ie.length>0?Ve.jsx(RYt,{code:r,circuitJsonErrors:ie,errorMessage:t,autoroutingLog:x,onReportAutoroutingLog:b}):Ve.jsx(Q9,{onRunClicked:e})})}),c&&Ve.jsx(WB,{value:"render_log",children:Ve.jsx($Zt,{renderLog:A})})]})})})};var A7="Dialog",[b7e,B7e]=jS(A7),[rXt,bB]=b7e(A7),S7e=r=>{const{__scopeDialog:e,children:t,open:n,defaultOpen:i,onOpenChange:o,modal:a=!0}=r,s=nt.useRef(null),l=nt.useRef(null),[c,u]=RM({prop:n,defaultProp:i??!1,onChange:o,caller:A7});return Ve.jsx(rXt,{scope:e,triggerRef:s,contentRef:l,contentId:JS(),titleId:JS(),descriptionId:JS(),open:c,onOpenChange:u,onOpenToggle:nt.useCallback(()=>u(A=>!A),[u]),modal:a,children:t})};S7e.displayName=A7;var w7e="DialogTrigger",Q7e=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=bB(w7e,t),o=c1(e,i.triggerRef);return Ve.jsx(wv.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Lce(i.open),...n,ref:o,onClick:Oh(r.onClick,i.onOpenToggle)})});Q7e.displayName=w7e;var Uce="DialogPortal",[iXt,M7e]=b7e(Uce,{forceMount:void 0}),D7e=r=>{const{__scopeDialog:e,forceMount:t,children:n,container:i}=r,o=bB(Uce,e);return Ve.jsx(iXt,{scope:e,forceMount:t,children:nt.Children.map(n,a=>Ve.jsx(jB,{present:t||o.open,children:Ve.jsx(Qse,{asChild:!0,container:i,children:a})}))})};D7e.displayName=Uce;var d7="DialogOverlay",R7e=nt.forwardRef((r,e)=>{const t=M7e(d7,r.__scopeDialog),{forceMount:n=t.forceMount,...i}=r,o=bB(d7,r.__scopeDialog);return o.modal?Ve.jsx(jB,{present:n||o.open,children:Ve.jsx(aXt,{...i,ref:e})}):null});R7e.displayName=d7;var oXt=DM("DialogOverlay.RemoveScroll"),aXt=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=bB(d7,t);return Ve.jsx(Pse,{as:oXt,allowPinchZoom:!0,shards:[i.contentRef],children:Ve.jsx(wv.div,{"data-state":Lce(i.open),...n,ref:e,style:{pointerEvents:"auto",...n.style}})})}),F9="DialogContent",N7e=nt.forwardRef((r,e)=>{const t=M7e(F9,r.__scopeDialog),{forceMount:n=t.forceMount,...i}=r,o=bB(F9,r.__scopeDialog);return Ve.jsx(jB,{present:n||o.open,children:o.modal?Ve.jsx(sXt,{...i,ref:e}):Ve.jsx(lXt,{...i,ref:e})})});N7e.displayName=F9;var sXt=nt.forwardRef((r,e)=>{const t=bB(F9,r.__scopeDialog),n=nt.useRef(null),i=c1(e,t.contentRef,n);return nt.useEffect(()=>{const o=n.current;if(o)return hUe(o)},[]),Ve.jsx(T7e,{...r,ref:i,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Oh(r.onCloseAutoFocus,o=>{var a;o.preventDefault(),(a=t.triggerRef.current)==null||a.focus()}),onPointerDownOutside:Oh(r.onPointerDownOutside,o=>{const a=o.detail.originalEvent,s=a.button===0&&a.ctrlKey===!0;(a.button===2||s)&&o.preventDefault()}),onFocusOutside:Oh(r.onFocusOutside,o=>o.preventDefault())})}),lXt=nt.forwardRef((r,e)=>{const t=bB(F9,r.__scopeDialog),n=nt.useRef(!1),i=nt.useRef(!1);return Ve.jsx(T7e,{...r,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{var a,s;(a=r.onCloseAutoFocus)==null||a.call(r,o),o.defaultPrevented||(n.current||(s=t.triggerRef.current)==null||s.focus(),o.preventDefault()),n.current=!1,i.current=!1},onInteractOutside:o=>{var l,c;(l=r.onInteractOutside)==null||l.call(r,o),o.defaultPrevented||(n.current=!0,o.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const a=o.target;((c=t.triggerRef.current)==null?void 0:c.contains(a))&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&i.current&&o.preventDefault()}})}),T7e=nt.forwardRef((r,e)=>{const{__scopeDialog:t,trapFocus:n,onOpenAutoFocus:i,onCloseAutoFocus:o,...a}=r,s=bB(F9,t),l=nt.useRef(null),c=c1(e,l);return Qke(),Ve.jsxs(Ve.Fragment,{children:[Ve.jsx(hse,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:i,onUnmountAutoFocus:o,children:Ve.jsx(use,{role:"dialog",id:s.contentId,"aria-describedby":s.descriptionId,"aria-labelledby":s.titleId,"data-state":Lce(s.open),...a,ref:c,onDismiss:()=>s.onOpenChange(!1)})}),Ve.jsxs(Ve.Fragment,{children:[Ve.jsx(uXt,{titleId:s.titleId}),Ve.jsx(dXt,{contentRef:l,descriptionId:s.descriptionId})]})]})}),Fce="DialogTitle",P7e=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=bB(Fce,t);return Ve.jsx(wv.h2,{id:i.titleId,...n,ref:e})});P7e.displayName=Fce;var k7e="DialogDescription",U7e=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=bB(k7e,t);return Ve.jsx(wv.p,{id:i.descriptionId,...n,ref:e})});U7e.displayName=k7e;var F7e="DialogClose",L7e=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=bB(F7e,t);return Ve.jsx(wv.button,{type:"button",...n,ref:e,onClick:Oh(r.onClick,()=>i.onOpenChange(!1))})});L7e.displayName=F7e;function Lce(r){return r?"open":"closed"}var G7e="DialogTitleWarning",[cXt,O7e]=Dpt(G7e,{contentName:F9,titleName:Fce,docsSlug:"dialog"}),uXt=({titleId:r})=>{const e=O7e(G7e),t=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
|
|
13497
|
+
`,onClick:n=>{n.stopPropagation(),t()},children:[Ve.jsx("input",{type:"checkbox",checked:e}),Ve.jsx("span",{style:{color:"#eee"},children:r})]}),VZt=({children:r,elements:e})=>{const[t,n]=V1(G=>[G.is_mouse_over_container,G.setIsMouseOverContainer]),[i,o]=nt.useState(!1),[a,s]=nt.useState(!1),[l,c]=nt.useState(!1),[u,A]=V1(G=>[G.selected_layer,G.selectLayer]),[d,f,p,C,v,_]=V1(G=>[G.in_move_footprint_mode,G.in_draw_trace_mode,G.is_showing_rats_nest,G.is_showing_multiple_traces_length,G.is_showing_autorouting,G.is_showing_drc_errors]),x=V1(G=>G.setEditMode),b=V1(G=>G.setIsShowingRatsNest),T=V1(G=>G.setIsShowingMultipleTracesLength),F=V1(G=>G.setIsShowingAutorouting),U=V1(G=>G.setIsShowingDrcErrors);Hw("1",()=>A("top")),Hw("2",()=>A("bottom")),Hw("3",()=>A("inner1")),Hw("4",()=>A("inner2")),Hw("5",()=>A("inner3")),Hw("6",()=>A("inner4")),Hw("7",()=>A("inner5")),Hw("8",()=>A("inner6"));const H=(e==null?void 0:e.filter(G=>G.type.includes("error")).length)??0;return Ve.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>{n(!0)},onMouseLeave:G=>{n(!1),s(!1)},children:[r,Ve.jsxs("div",{style:{position:"absolute",bottom:4,right:8,pointerEvents:"none",color:"white",fontSize:11,opacity:t?.5:0,transition:"opacity 1s",transitionDelay:"2s",fontFamily:"sans-serif"},children:["@tscircuit/pcb-viewer@",HZt.version]}),Ve.jsxs("div",{style:{position:"absolute",opacity:t?1:0,top:16,left:16,transition:t?"opacity 100ms linear":"opacity 1s linear",zIndex:fx.toolbarOverlay,color:"red",display:"flex",fontSize:12,height:100,fontFamily:"sans-serif"},children:[Ve.jsxs(ED,{onClick:()=>{s(!a)},onMouseLeave:()=>{a&&s(!1)},children:[Ve.jsxs("div",{children:["layer:"," ",Ve.jsx("span",{style:{marginLeft:2,fontWeight:500,color:_D[u]},children:u})]}),a&&Ve.jsx("div",{style:{marginTop:4,minWidth:120},children:Mce.map(G=>G.replace(/-/g,"")).map(G=>Ve.jsx(YZt,{name:G,selected:G===u,onClick:()=>{A(G.replace(/-/,""))}},G))})]}),Ve.jsxs(ED,{style:H>0?{color:"red"}:{},onClick:()=>c(!l),onMouseLeave:()=>c(!1),children:[Ve.jsxs("div",{children:[H," errors"]}),l&&Ve.jsx("div",{style:{display:"grid",gridTemplateColumns:"100px 300px"},children:e==null?void 0:e.filter(G=>G.type.includes("error")).map((G,j)=>Ve.jsxs(nt.Fragment,{children:[Ve.jsx("div",{children:G.error_type}),Ve.jsx("div",{children:G.message})]},j))})]}),Ve.jsx(ED,{style:{},onClick:()=>{x(f?"off":"draw_trace")},children:Ve.jsxs("div",{children:[f?"✖ ":"","Edit Traces"]})}),Ve.jsx(ED,{style:{},onClick:()=>{x(d?"off":"move_footprint")},children:Ve.jsxs("div",{children:[d?"✖ ":"","Move Components"]})}),Ve.jsx(ED,{style:{},onClick:()=>{b(!p)},children:Ve.jsxs("div",{children:[p?"✖ ":"","Rats Nest"]})}),Ve.jsx(ED,{onClick:()=>{o(!i)},children:Ve.jsxs("div",{children:[Ve.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:["View"," ",Ve.jsx("span",{style:{fontSize:"8px",transform:i?"rotate(180deg)":"rotate(0)",transition:"transform 0.1s ease",display:"inline-block"},children:"▼"})]}),i&&Ve.jsxs("div",{style:{marginTop:4,minWidth:120},children:[Ve.jsx(kce,{label:"Show All Trace Lengths",checked:C,onClick:()=>{T(!C)}}),Ve.jsx(kce,{label:"Show Autorouting Animation",checked:v,onClick:()=>{F(!v)}}),Ve.jsx(kce,{label:"Show DRC Errors",checked:_,onClick:()=>{U(!_)}})]})]})})]})]})},KZt=r=>{const{transform:e,elements:t}=r,[n,i]=nt.useMemo(()=>{const c=r.elements.flatMap(A=>rZt(A,r.elements)),u=lB(r.elements);return[c,u]},[r.elements]),[o,a]=nt.useState({drawingObjectIdsWithMouseOver:new Set,primitiveIdsInMousedOverNet:[]}),s=nt.useMemo(()=>tZt({primitivesWithoutInteractionMetadata:n,drawingObjectIdsWithMouseOver:o.drawingObjectIdsWithMouseOver,primitiveIdsInMousedOverNet:o.primitiveIdsInMousedOverNet}),[n,o]),l=nt.useCallback(c=>{var d,f;const u=[];for(const p of c)if(p._element){const C=i.getNetConnectedToId("pcb_port_id"in p._element?(d=p._element)==null?void 0:d.pcb_port_id:"pcb_trace_id"in p._element?(f=p._element)==null?void 0:f.pcb_trace_id:"");u.push(...i.getIdsConnectedToNet(C))}const A=new Set(c.map(p=>p._pcb_drawing_object_id));a({drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:u})},[i]);return Ve.jsx(OZt,{elements:t,transform:e,primitives:n,onMouseHoverOverPrimitives:l,children:Ve.jsx(xZt,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:Ve.jsx(wZt,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:Ve.jsx(_Zt,{transform:e,focusOnHover:r.focusOnHover,children:Ve.jsx(VZt,{elements:t,children:Ve.jsx(DZt,{transform:e,elements:t,children:Ve.jsx(zZt,{transform:e,soup:t,children:Ve.jsx(IZt,{transform:e,debugGraphics:r.debugGraphics,children:Ve.jsx(CZt,{transform:e,elements:t,children:Ve.jsx(vZt,{transform:e,primitives:s,width:r.width,height:r.height,grid:r.grid})})})})})})})})})})},jZt=Qc(QA(400,300),P1(40,-40)),JZt=({circuitJson:r,debugGraphics:e,height:t=600,initialState:n,allowEditing:i=!0,editEvents:o,onEditEventsChanged:a,focusOnHover:s=!1,clickToInteractEnabled:l=!1})=>{const[c,u]=nt.useState(!l),[A,d]=Tce(),[f,p]=nt.useState(jZt),{ref:C,setTransform:v,cancelDrag:_}=eZt({transform:f,onSetTransform:p,enabled:c});let[x,b]=nt.useState([]);x=o??x;const T=nt.useRef(!1),F=nt.useRef(null),U=`${(r==null?void 0:r.length)||0}_${(r==null?void 0:r.editCount)||0}`,H=()=>{const te=(d==null?void 0:d.width)>0?d:{width:500,height:500},{center:ie,width:pe,height:de}=j.some(ge=>ge.type.startsWith("pcb_"))?Yqt(j.filter(ge=>ge.type.startsWith("pcb_"))):{center:{x:0,y:0},width:.001,height:.001},Ae=Math.min((te.width??0)/pe,(te.height??0)/de,100)*.75,Ie=Qc(QA((te.width??0)/2,(te.height??0)/2),P1(Ae,-Ae,0,0),QA(-ie.x,-ie.y));v(Ie)};nt.useEffect(()=>{d!=null&&d.width&&r&&r.length!==0&&(T.current||(H(),T.current=!0))},[r,d]);const G=nt.useMemo(()=>(r==null?void 0:r.filter(te=>te.type.startsWith("pcb_")||te.type.startsWith("source_")))??[],[U]),j=nt.useMemo(()=>ujt({circuitJson:G,editEvents:x}),[G,x]),O=te=>{b([...x,te]),a==null||a([...x,te])},ne=te=>{const ie=x.map(pe=>pe.edit_event_id===te.edit_event_id?{...pe,...te}:pe);b(ie),a==null||a(ie)};return Ve.jsxs("div",{ref:C,style:{position:"relative"},children:[Ve.jsx("div",{ref:A,children:Ve.jsxs(Kqt,{initialState:n,children:[Ve.jsx(KZt,{transform:f,height:t,width:d.width,allowEditing:i,focusOnHover:s,cancelPanDrag:_,onCreateEditEvent:O,onModifyEditEvent:ne,grid:{spacing:1,view_window:{left:0,right:d.width||500,top:t,bottom:0}},elements:j,debugGraphics:e},d.width),Ve.jsx(Jqt,{})]})}),l&&!c&&Ve.jsx("div",{onClick:()=>{u(!0),H()},onTouchStart:te=>{const ie=te.touches[0];F.current={x:ie.clientX,y:ie.clientY}},onTouchEnd:te=>{const ie=te.changedTouches[0],pe=F.current;if(!pe)return;const de=Math.abs(ie.clientX-pe.x),Ae=Math.abs(ie.clientY-pe.y);de<10&&Ae<10&&(te.preventDefault(),u(!0),H()),F.current=null},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:fx.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center",touchAction:"pan-x pan-y pinch-zoom"},children:Ve.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",pointerEvents:"none"},children:typeof window<"u"&&("ontouchstart"in window||navigator.maxTouchPoints>0)?"Touch to Interact":"Click to Interact"})})]})};const WZt=({containerClassName:r,...e})=>{const t=nt.useRef(null),[n,i]=nt.useState(620);return nt.useLayoutEffect(()=>{const o=()=>{if(t.current){const s=t.current.clientHeight,l=window.innerHeight;i(Math.min(Math.max(s,620),l))}};o();const a=new ResizeObserver(o);return t.current&&a.observe(t.current),window.addEventListener("resize",o),()=>{a.disconnect(),window.removeEventListener("resize",o)}},[]),Ve.jsx("div",{ref:t,className:r||"rf-w-full rf-h-full",children:Ve.jsx(JZt,{...e,height:n})})},qZt='*,: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}',ZZt=()=>{nt.useEffect(()=>{if(document.querySelector('style[data-styles="tscircuit-runframe"]'))return;const e=document.createElement("style");e.setAttribute("data-styles","tscircuit-runframe"),e.textContent=qZt,document.head.appendChild(e)},[])},x7e=r=>`hsl(${jx.indexOf(r)*137.5%360}, 70%, 50%)`,XZt=({phaseTimings:r})=>{if(!r)return null;const e=Object.values(r).reduce((t,n)=>t+n,0);return Ve.jsxs("div",{className:"rf-space-y-2 rf-w-full rf-px-4",children:[Ve.jsx("div",{className:"rf-relative rf-h-8 rf-flex rf-rounded-sm",children:jx.map(t=>{const n=r[t]||0,i=n/e*100;return Ve.jsx("div",{className:"rf-group/bar rf-relative rf-overflow-visible",style:{width:`${i}%`,backgroundColor:x7e(t)},children:Ve.jsxs("div",{className:"rf-opacity-0 group-hover/bar:rf-opacity-100 rf-transition-opacity rf-absolute rf-bottom-full rf-left-1/2 rf-transform -rf-translate-x-1/2 rf-mb-2 rf-px-2 rf-py-1 rf-text-xs rf-whitespace-nowrap rf-rounded rf-bg-gray-900 rf-text-white rf-pointer-events-none",children:[t,": ",n.toFixed(1),"ms"]})},t)})}),Ve.jsxs("div",{className:"rf-text-xs rf-text-gray-500",children:["Total: ",e.toFixed(2),"ms"]})]})},$Zt=({renderLog:r})=>{const[e,t]=nt.useState("chronological");if(!r)return Ve.jsx("div",{className:"rf-p-4 rf-bg-gray-100 rf-rounded-md",children:"No render log, make sure this tab is open when you render (TODO add a rerender button here)"});const n=Object.entries((r==null?void 0:r.phaseTimings)??{});e==="chronological"?n.sort((o,a)=>jx.indexOf(o[0])-jx.indexOf(a[0])):n.sort((o,a)=>a[1]-o[1]);const i=n.reduce((o,[a,s])=>o+s,0);return Ve.jsxs("div",{className:"rf-bg-white",children:[Ve.jsxs("div",{className:"rf-flex rf-justify-between rf-items-center",children:[Ve.jsx("div",{children:"Render Logs"}),Ve.jsxs("div",{className:"rf-mb-4 rf-pr-2 rf-flex rf-text-xs rf-items-center",children:[Ve.jsx("div",{className:"rf-mr-2",children:"Sort by:"}),Ve.jsxs("select",{value:e,onChange:o=>t(o.target.value),className:"rf-px-2 rf-py-1 rf-border rf-rounded rf-text-xs",children:[Ve.jsx("option",{value:"chronological",children:"Phase Order"}),Ve.jsx("option",{value:"longest",children:"Duration"})]})]})]}),Ve.jsx(XZt,{phaseTimings:r.phaseTimings}),Ve.jsxs("table",{className:"rf-w-full rf-text-xs",children:[Ve.jsx("thead",{children:Ve.jsxs("tr",{children:[Ve.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase Order"}),Ve.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase"}),Ve.jsx("th",{className:"rf-text-left rf-p-2",children:"Duration (ms)"})]})}),Ve.jsx("tbody",{children:n.map(([o,a])=>Ve.jsxs("tr",{children:[Ve.jsx("td",{className:"rf-p-2",children:jx.indexOf(o)}),Ve.jsx("td",{className:"rf-p-2",children:o}),Ve.jsx("td",{className:"rf-p-2",children:Ve.jsx("div",{className:"rf-w-8",children:Ve.jsx("div",{className:"rf-h-2 rf-rounded-sm",style:{backgroundColor:x7e(o),width:`${a/i*100}%`}})})}),Ve.jsx("td",{className:"rf-p-2",children:Ve.jsxs("div",{className:"rf-flex w-full",children:[Ve.jsxs("span",{className:"rf-flex-grow",children:[a,"ms"]}),Ve.jsxs("span",{className:"rf-text-gray-500 rf-pr-2",children:[(a/i*100).toFixed(1),"%"]})]})})]},o))})]})]})},eXt="0.0.539",tXt=["assembly","bom","circuit_json","errors","render_log"],nXt=({code:r,onRunClicked:e=void 0,errorMessage:t,circuitJson:n,autoroutingGraphics:i,showRightHeaderContent:o=!0,showCodeTab:a=!1,codeTabContent:s,showJsonTab:l=!0,showRenderLogTab:c=!0,onActiveTabChange:u,renderLog:A,showImportAndFormatButtons:d=!0,className:f,headerClassName:p,leftHeaderContent:C,readOnly:v,isStreaming:_,autoroutingLog:x,onReportAutoroutingLog:b,isRunningCode:T,hasCodeChangedSinceLastRun:F,onEditEvent:U,editEvents:H,defaultActiveTab:G,autoRotate3dViewerDisabled:j,showSchematicDebugGrid:O=!1,showToggleFullScreen:ne=!0,defaultToFullScreen:te=!1})=>{var Re;ZZt();const ie=nt.useMemo(()=>n?n.filter(Se=>Se&&"error_type"in Se||Se.type.includes("error")):null,[n]),[pe,de]=nt.useState(G??"pcb"),[Ae,Ie]=nt.useState(te),ge=nt.useCallback(Se=>{de(Se),u==null||u(Se)},[u]),Me=()=>{Ie(!Ae)};nt.useEffect(()=>{t&&ge("errors")},[t]),nt.useEffect(()=>{(pe==="code"||pe==="errors")&&n&&!t&&ge(G??"pcb")},[n]);const be=nt.useCallback(Se=>{window.TSCIRCUIT_3D_OBJECT_REF=Se===null?void 0:Se},[]);return Ve.jsx("div",{className:Mp("flex flex-col relative rf-overflow-x-hidden",f),children:Ve.jsx("div",{className:Mp("rf-md:sticky rf-md:top-2",Ae&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-bg-white"),children:Ve.jsxs(SIe,{value:pe,onValueChange:ge,className:"rf-flex-grow rf-flex rf-flex-col",children:[Ve.jsxs("div",{className:Mp("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",p),children:[C,C&&Ve.jsx("div",{className:"rf-flex-grow"}),!C&&T&&Ve.jsx($3,{className:"rf-w-4 rf-h-4 rf-animate-spin"}),!C&&Ve.jsx("div",{className:"rf-flex-grow"}),A&&A.progress!==1&&!t&&Ve.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[A.lastRenderEvent&&Ve.jsx("div",{className:"rf-text-xs rf-text-gray-500",children:((Re=A.lastRenderEvent)==null?void 0:Re.phase)??""}),Ve.jsx("div",{className:"rf-w-4 rf-h-4 rf-bg-blue-500 rf-opacity-50 rf-rounded-full rf-text-white",children:Ve.jsx($3,{className:"rf-w-4 rf-h-4 rf-animate-spin"})}),Ve.jsxs("div",{className:"rf-text-xs rf-font-bold rf-text-gray-700 rf-tabular-nums",children:[((A.progress??0)*100).toFixed(1),"%"]})]}),o&&Ve.jsxs(Lj,{children:[a&&Ve.jsx(sw,{value:"code",children:"Code"}),Ve.jsxs(sw,{value:"pcb",className:"rf-whitespace-nowrap",children:[n&&Ve.jsx("span",{className:Mp("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",F?"rf-bg-gray-500":"rf-bg-blue-500")}),"PCB"]}),Ve.jsxs(sw,{value:"schematic",className:"rf-whitespace-nowrap",children:[n&&Ve.jsx("span",{className:Mp("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",F?"rf-bg-gray-500":"rf-bg-blue-500")}),"Schematic"]}),Ve.jsxs(sw,{value:"cad",children:[n&&Ve.jsx("span",{className:Mp("inline-flex items-center justify-center w-2 h-2 mr-1 text-xs font-bold text-white rounded-full",F?"rf-bg-gray-500":"rf-bg-blue-500")}),"3D"]}),!["pcb","cad","schematic"].includes(pe)&&Ve.jsx(sw,{value:pe,children:BIe(pe)}),Ve.jsxs(Vse,{children:[Ve.jsx(Kse,{asChild:!0,children:Ve.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[Ve.jsx(T7t,{className:"rf-w-4 rf-h-4"}),(ie&&ie.length>0||t)&&Ve.jsx("span",{className:"rf-inline-flex rf-absolute rf-top-[6px] rf-right-[4px] rf-items-center rf-justify-center rf-w-1 rf-h-1 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full"})]})}),Ve.jsxs(pG,{className:"rf-*:text-xs",children:[tXt.map(Se=>Ve.jsxs(CB,{onSelect:()=>ge(Se),children:[pe!==Se&&Ve.jsx(cke,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),pe===Se&&Ve.jsx($ae,{className:"rf-w-3 rf-h-3"}),Ve.jsx("div",{className:"rf-pr-2",children:BIe(Se)}),Se==="errors"&&(ie&&ie.length>0||t)&&Ve.jsx("span",{className:"rf-inline-flex rf-items-center rf-justify-center rf-w-3 rf-h-3 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full",children:t?1:ie==null?void 0:ie.length})]},Se)),Ve.jsx(CB,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:Ve.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/runframe@",eXt.split(".").map((Se,Ke)=>Ke===2?parseInt(Se)+1:Se).join(".")]})})]})]})]}),ne&&Ve.jsx(TE,{onClick:Me,variant:"ghost",children:Ae?Ve.jsx(F7t,{size:16}):Ve.jsx(k7t,{size:16})})]}),a&&Ve.jsx(WB,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:Ve.jsx("div",{className:"rf-h-full",children:s})}),Ve.jsx(WB,{value:"pcb",children:Ve.jsx("div",{className:Mp("rf-overflow-hidden",Ae?"rf-h-[calc(100vh-52px)]":"rf-h-[620px]"),children:Ve.jsx(X3,{fallbackRender:({error:Se})=>Ve.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ve.jsxs("div",{className:"rf-p-4",children:[Ve.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading PCB viewer"}),Ve.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Se==null?void 0:Se.message)||"An unknown error occurred"})]})}),children:n?Ve.jsx(WZt,{focusOnHover:!1,circuitJson:n,debugGraphics:i,containerClassName:Mp("rf-h-full rf-w-full",Ae?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:Se=>{U&&Se.forEach(Ke=>U(Ke))}}):Ve.jsx(Q9,{onRunClicked:e})})})}),Ve.jsx(WB,{value:"assembly",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",Ae?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(X3,{fallback:Ve.jsx("div",{children:"Error loading Assembly"}),children:n?Ve.jsx(uKt,{circuitJson:n,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):Ve.jsx(Q9,{onRunClicked:e})})})}),Ve.jsx(WB,{value:"schematic",children:Ve.jsx("div",{className:Mp("rf-overflow-auto rf-bg-white",Ae?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(X3,{fallbackRender:({error:Se})=>Ve.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ve.jsxs("div",{className:"rf-p-4",children:[Ve.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Schematic"}),Ve.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Se==null?void 0:Se.message)||"An unknown error occurred"})]})}),children:n?Ve.jsx(sKt,{circuitJson:n,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:Se=>{U==null||U(Se)},debugGrid:O}):Ve.jsx(Q9,{onRunClicked:e})})})}),Ve.jsx(WB,{value:"cad",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",Ae?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(X3,{FallbackComponent:C7t,children:n?Ve.jsx(v7t,{ref:be,circuitJson:n,autoRotateDisabled:j}):Ve.jsx(Q9,{onRunClicked:e})})})}),Ve.jsx(WB,{value:"bom",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",Ae?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(X3,{fallbackRender:({error:Se})=>Ve.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ve.jsxs("div",{className:"rf-p-4",children:[Ve.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Bill of Materials"}),Ve.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Se==null?void 0:Se.message)||"An unknown error occurred"})]})}),children:n?Ve.jsx(pKt,{circuitJson:n}):Ve.jsx(Q9,{onRunClicked:e})})})}),Ve.jsx(WB,{value:"circuit_json",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",Ae?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ve.jsx(X3,{fallback:Ve.jsx("div",{children:"Error loading JSON viewer"}),children:n?Ve.jsx(fKt,{elements:n}):Ve.jsx(Q9,{onRunClicked:e})})})}),Ve.jsx(WB,{value:"errors",children:Ve.jsx("div",{className:Mp("rf-overflow-auto",Ae?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:t||ie&&ie.length>0?Ve.jsx(RYt,{code:r,circuitJsonErrors:ie,errorMessage:t,autoroutingLog:x,onReportAutoroutingLog:b}):Ve.jsx(Q9,{onRunClicked:e})})}),c&&Ve.jsx(WB,{value:"render_log",children:Ve.jsx($Zt,{renderLog:A})})]})})})};var A7="Dialog",[b7e,B7e]=jS(A7),[rXt,bB]=b7e(A7),S7e=r=>{const{__scopeDialog:e,children:t,open:n,defaultOpen:i,onOpenChange:o,modal:a=!0}=r,s=nt.useRef(null),l=nt.useRef(null),[c,u]=RM({prop:n,defaultProp:i??!1,onChange:o,caller:A7});return Ve.jsx(rXt,{scope:e,triggerRef:s,contentRef:l,contentId:JS(),titleId:JS(),descriptionId:JS(),open:c,onOpenChange:u,onOpenToggle:nt.useCallback(()=>u(A=>!A),[u]),modal:a,children:t})};S7e.displayName=A7;var w7e="DialogTrigger",Q7e=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=bB(w7e,t),o=c1(e,i.triggerRef);return Ve.jsx(wv.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Lce(i.open),...n,ref:o,onClick:Oh(r.onClick,i.onOpenToggle)})});Q7e.displayName=w7e;var Uce="DialogPortal",[iXt,M7e]=b7e(Uce,{forceMount:void 0}),D7e=r=>{const{__scopeDialog:e,forceMount:t,children:n,container:i}=r,o=bB(Uce,e);return Ve.jsx(iXt,{scope:e,forceMount:t,children:nt.Children.map(n,a=>Ve.jsx(jB,{present:t||o.open,children:Ve.jsx(Qse,{asChild:!0,container:i,children:a})}))})};D7e.displayName=Uce;var d7="DialogOverlay",R7e=nt.forwardRef((r,e)=>{const t=M7e(d7,r.__scopeDialog),{forceMount:n=t.forceMount,...i}=r,o=bB(d7,r.__scopeDialog);return o.modal?Ve.jsx(jB,{present:n||o.open,children:Ve.jsx(aXt,{...i,ref:e})}):null});R7e.displayName=d7;var oXt=DM("DialogOverlay.RemoveScroll"),aXt=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=bB(d7,t);return Ve.jsx(Pse,{as:oXt,allowPinchZoom:!0,shards:[i.contentRef],children:Ve.jsx(wv.div,{"data-state":Lce(i.open),...n,ref:e,style:{pointerEvents:"auto",...n.style}})})}),F9="DialogContent",N7e=nt.forwardRef((r,e)=>{const t=M7e(F9,r.__scopeDialog),{forceMount:n=t.forceMount,...i}=r,o=bB(F9,r.__scopeDialog);return Ve.jsx(jB,{present:n||o.open,children:o.modal?Ve.jsx(sXt,{...i,ref:e}):Ve.jsx(lXt,{...i,ref:e})})});N7e.displayName=F9;var sXt=nt.forwardRef((r,e)=>{const t=bB(F9,r.__scopeDialog),n=nt.useRef(null),i=c1(e,t.contentRef,n);return nt.useEffect(()=>{const o=n.current;if(o)return hUe(o)},[]),Ve.jsx(T7e,{...r,ref:i,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Oh(r.onCloseAutoFocus,o=>{var a;o.preventDefault(),(a=t.triggerRef.current)==null||a.focus()}),onPointerDownOutside:Oh(r.onPointerDownOutside,o=>{const a=o.detail.originalEvent,s=a.button===0&&a.ctrlKey===!0;(a.button===2||s)&&o.preventDefault()}),onFocusOutside:Oh(r.onFocusOutside,o=>o.preventDefault())})}),lXt=nt.forwardRef((r,e)=>{const t=bB(F9,r.__scopeDialog),n=nt.useRef(!1),i=nt.useRef(!1);return Ve.jsx(T7e,{...r,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{var a,s;(a=r.onCloseAutoFocus)==null||a.call(r,o),o.defaultPrevented||(n.current||(s=t.triggerRef.current)==null||s.focus(),o.preventDefault()),n.current=!1,i.current=!1},onInteractOutside:o=>{var l,c;(l=r.onInteractOutside)==null||l.call(r,o),o.defaultPrevented||(n.current=!0,o.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const a=o.target;((c=t.triggerRef.current)==null?void 0:c.contains(a))&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&i.current&&o.preventDefault()}})}),T7e=nt.forwardRef((r,e)=>{const{__scopeDialog:t,trapFocus:n,onOpenAutoFocus:i,onCloseAutoFocus:o,...a}=r,s=bB(F9,t),l=nt.useRef(null),c=c1(e,l);return Qke(),Ve.jsxs(Ve.Fragment,{children:[Ve.jsx(hse,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:i,onUnmountAutoFocus:o,children:Ve.jsx(use,{role:"dialog",id:s.contentId,"aria-describedby":s.descriptionId,"aria-labelledby":s.titleId,"data-state":Lce(s.open),...a,ref:c,onDismiss:()=>s.onOpenChange(!1)})}),Ve.jsxs(Ve.Fragment,{children:[Ve.jsx(uXt,{titleId:s.titleId}),Ve.jsx(dXt,{contentRef:l,descriptionId:s.descriptionId})]})]})}),Fce="DialogTitle",P7e=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=bB(Fce,t);return Ve.jsx(wv.h2,{id:i.titleId,...n,ref:e})});P7e.displayName=Fce;var k7e="DialogDescription",U7e=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=bB(k7e,t);return Ve.jsx(wv.p,{id:i.descriptionId,...n,ref:e})});U7e.displayName=k7e;var F7e="DialogClose",L7e=nt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=bB(F7e,t);return Ve.jsx(wv.button,{type:"button",...n,ref:e,onClick:Oh(r.onClick,()=>i.onOpenChange(!1))})});L7e.displayName=F7e;function Lce(r){return r?"open":"closed"}var G7e="DialogTitleWarning",[cXt,O7e]=Dpt(G7e,{contentName:F9,titleName:Fce,docsSlug:"dialog"}),uXt=({titleId:r})=>{const e=O7e(G7e),t=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
|
|
13498
13498
|
|
|
13499
13499
|
If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
13500
13500
|
|