@tscircuit/runframe 0.0.443 → 0.0.444

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.
@@ -827,7 +827,7 @@ ${a.width}x${a.height}
827
827
  `)});let a=0;for(;a<this.totalPathLength;){const o=this.getPointAtDistance(a);e.circles.push({center:{x:o.x,y:o.y},radius:.05,fill:"rgba(100, 100, 100, 0.5)"}),a+=this.totalPathLength/20}if(this.lastValidPath&&this.lastValidPath.length>1)for(let o=0;o<this.lastValidPath.length-1;o++)e.lines.push({points:[{x:this.lastValidPath[o].x,y:this.lastValidPath[o].y},{x:this.lastValidPath[o+1].x,y:this.lastValidPath[o+1].y}],strokeColor:"rgba(0, 255, 255, 0.9)",strokeDash:"3, 3"});return e}},Zvt=class extends o_{constructor(e){super();Je(this,"simplifiedHdRoutes");Je(this,"currentUnsimplifiedHdRouteIndex",0);Je(this,"activeSubSolver",null);Je(this,"unsimplifiedHdRoutes");Je(this,"obstacles");Je(this,"connMap");Je(this,"colorMap");this.MAX_ITERATIONS=1e8,this.unsimplifiedHdRoutes=e.unsimplifiedHdRoutes,this.obstacles=e.obstacles,this.connMap=e.connMap||new _2e({}),this.colorMap=e.colorMap||{},this.simplifiedHdRoutes=[]}_step(){const e=this.unsimplifiedHdRoutes[this.currentUnsimplifiedHdRouteIndex];if(!this.activeSubSolver){if(!e){this.solved=!0;return}this.activeSubSolver=new Wvt({inputRoute:e,otherHdRoutes:this.unsimplifiedHdRoutes.slice(this.currentUnsimplifiedHdRouteIndex+1).concat(this.simplifiedHdRoutes),obstacles:this.obstacles,connMap:this.connMap,colorMap:this.colorMap}),this.currentUnsimplifiedHdRouteIndex++;return}this.activeSubSolver.step(),this.activeSubSolver.solved&&(this.simplifiedHdRoutes.push(this.activeSubSolver.simplifiedRoute),this.activeSubSolver=null)}visualize(){var t,r,i;if(this.activeSubSolver)return this.activeSubSolver.visualize();const e={lines:[],points:[],circles:[],rects:[],coordinateSystem:"cartesian",title:"Multi Simplified Path Solver"};for(const a of this.unsimplifiedHdRoutes)if(!this.simplifiedHdRoutes.some(o=>o.connectionName===a.connectionName)){for(let o=0;o<a.route.length-1;o++)e.lines.push({points:[{x:a.route[o].x,y:a.route[o].y},{x:a.route[o+1].x,y:a.route[o+1].y}],strokeColor:a.route[o].z===1?"rgba(0, 0, 255, 0.4)":"rgba(255, 0, 0, 0.4)",strokeWidth:.15,strokeDash:a.route[o].z===1?[.5,.5]:void 0});for(const o of a.vias||[])e.circles.push({center:o,radius:a.viaDiameter/2||.3,fill:"rgba(0, 0, 255, 0.4)"})}for(const a of this.simplifiedHdRoutes){const o=((t=this.colorMap)==null?void 0:t[a.connectionName])||"rgba(128, 128, 128, 0.8)";for(let s=0;s<a.route.length-1;s++)e.lines.push({points:[{x:a.route[s].x,y:a.route[s].y},{x:a.route[s+1].x,y:a.route[s+1].y}],strokeWidth:.15,strokeColor:o,strokeDash:a.route[s].z===1?[.5,.5]:void 0,step:1});for(const s of a.vias||[])e.circles.push({center:s,radius:a.viaDiameter/2,fill:"rgba(0, 0, 255, 0.5)",step:1})}for(const a of this.unsimplifiedHdRoutes){for(let o=0;o<a.route.length-1;o++)e.lines.push({points:[{x:a.route[o].x,y:a.route[o].y},{x:a.route[o+1].x,y:a.route[o+1].y}],strokeWidth:.15,strokeColor:"rgba(255, 0, 0, 0.2)",strokeDash:[.5,.5],step:0,layer:`z${a.route[o].z.toString()}`});for(const o of a.vias)e.circles.push({center:{x:o.x,y:o.y},radius:a.viaDiameter/2,fill:"rgba(255, 0, 0, 0.2)",step:0})}for(const a of this.obstacles)e.rects.push({center:a.center,width:a.width,height:a.height,fill:(r=a.layers)!=null&&r.includes("top")?"rgba(255, 0, 0, 0.3)":(i=a.layers)!=null&&i.includes("bottom")?"rgba(0, 0, 255, 0.3)":"rgba(128, 128, 128, 0.3)"});if(this.currentUnsimplifiedHdRouteIndex<this.unsimplifiedHdRoutes.length){const a=this.unsimplifiedHdRoutes[this.currentUnsimplifiedHdRouteIndex];a.route.length>0&&e.circles.push({center:{x:a.route[0].x,y:a.route[0].y},radius:.2,fill:"yellow",label:"Current"})}return e}},Qvt=class extends o_{constructor(e){super();Je(this,"edges");this.nodes=e,this.edges=[]}getNextCapacityMeshEdgeId(){return`ce${this.edges.length}`}step(){this.edges=[];for(let e=0;e<this.nodes.length;e++)for(let t=e+1;t<this.nodes.length;t++)!(this.nodes[e]._strawNode&&this.nodes[t]._strawNode&&this.nodes[e]._strawParentCapacityMeshNodeId===this.nodes[t]._strawParentCapacityMeshNodeId)&&Eq(this.nodes[e],this.nodes[t])&&this.doNodesHaveSharedLayer(this.nodes[e],this.nodes[t])&&this.edges.push({capacityMeshEdgeId:this.getNextCapacityMeshEdgeId(),nodeIds:[this.nodes[e].capacityMeshNodeId,this.nodes[t].capacityMeshNodeId]});this.handleTargetNodes(),this.solved=!0}handleTargetNodes(){const e=this.nodes.filter(t=>t._containsTarget);for(const t of e){if(this.edges.some(o=>o.nodeIds.includes(t.capacityMeshNodeId)))continue;let i=null,a=1/0;for(const o of this.nodes){if(o._containsObstacle||o._containsTarget)continue;const s=U9(t.center,o.center);s<a&&(a=s,i=o)}i&&this.edges.push({capacityMeshEdgeId:this.getNextCapacityMeshEdgeId(),nodeIds:[t.capacityMeshNodeId,i.capacityMeshNodeId]})}}doNodesHaveSharedLayer(e,t){return e.availableZ.some(r=>t.availableZ.includes(r))}visualize(){const e={lines:[],points:[],rects:this.nodes.map(t=>{const r=Math.min(...t.availableZ);return{width:Math.max(t.width-2,t.width*.8),height:Math.max(t.height-2,t.height*.8),center:{x:t.center.x+r*t.width*.05,y:t.center.y-r*t.width*.05},fill:t._containsObstacle?"rgba(255,0,0,0.1)":{"0,1":"rgba(0,0,0,0.1)",0:"rgba(0,200,200, 0.1)",1:"rgba(0,0,200, 0.1)"}[t.availableZ.join(",")]??"rgba(0,200,200,0.1)",label:[t.capacityMeshNodeId,`availableZ: ${t.availableZ.join(",")}`,`target? ${t._containsTarget??!1}`,`obs? ${t._containsObstacle??!1}`].join(`
828
828
  `)}}),circles:[]};for(const t of this.edges){const r=this.nodes.find(a=>a.capacityMeshNodeId===t.nodeIds[0]),i=this.nodes.find(a=>a.capacityMeshNodeId===t.nodeIds[1]);if(r!=null&&r.center&&(i!=null&&i.center)){const a=Math.min(...r.availableZ),o=Math.min(...i.availableZ),s={x:r.center.x+a*r.width*.05,y:r.center.y-a*r.width*.05},l={x:i.center.x+o*i.width*.05,y:i.center.y-o*i.width*.05};e.lines.push({points:[s,l],strokeDash:r.availableZ.join(",")===i.availableZ.join(",")?void 0:"10 5"})}}return e}},Kvt=class extends Qvt{step(){this.edges=[];const n=new Set,e=new Tq(this.nodes);for(let t=0;t<this.nodes.length;t++){const r=this.nodes[t],i=e.getNodesInArea(r.center.x,r.center.y,r.width*2,r.height*2);for(const a of i){if(!Eq(r,a))continue;!(r._strawNode&&a._strawNode&&r._strawParentCapacityMeshNodeId===a._strawParentCapacityMeshNodeId)&&this.doNodesHaveSharedLayer(r,a)&&!n.has(`${r.capacityMeshNodeId}-${a.capacityMeshNodeId}`)&&(n.add(`${r.capacityMeshNodeId}-${a.capacityMeshNodeId}`),n.add(`${a.capacityMeshNodeId}-${r.capacityMeshNodeId}`),this.edges.push({capacityMeshEdgeId:this.getNextCapacityMeshEdgeId(),nodeIds:[r.capacityMeshNodeId,a.capacityMeshNodeId]}))}}this.handleTargetNodes(),this.solved=!0}},M2e=n=>({minX:Math.min(n[0].x,n[1].x),maxX:Math.max(n[0].x,n[1].x),minY:Math.min(n[0].y,n[1].y),maxY:Math.max(n[0].y,n[1].y)});function GL(n,e){const t=n.x-e.x,r=n.y-e.y;return t*t+r*r}function OE(n,e,t){const r=GL(e,t);if(r===0)return GL(n,e);let i=((n.x-e.x)*(t.x-e.x)+(n.y-e.y)*(t.y-e.y))/r;i=Math.max(0,Math.min(1,i));const a={x:e.x+i*(t.x-e.x),y:e.y+i*(t.y-e.y)};return GL(n,a)}function Jvt(n,e,t,r){if(Q2(n,e,t,r))return 0;const i={x:n.x,y:n.y},a={x:e.x,y:e.y},o={x:t.x,y:t.y},s={x:r.x,y:r.y};return Math.min(OE(i,o,s),OE(a,o,s),OE(o,i,a),OE(s,i,a))}var eyt=class{constructor(n,e=1){Je(this,"segmentBuckets");Je(this,"viaBuckets");Je(this,"routes");Je(this,"CELL_SIZE");this.segmentBuckets=new Map,this.viaBuckets=new Map,this.routes=new Map,this.CELL_SIZE=e;const t=1e-9;for(const r of n){if(!r||!r.connectionName){console.warn("Skipping route with missing data:",r);continue}if(this.routes.has(r.connectionName)){console.warn(`Skipping duplicate route connectionName: ${r.connectionName}`);continue}if(this.routes.set(r.connectionName,r),r.route&&r.route.length>=2)for(let i=0;i<r.route.length-1;i++){const a=r.route[i],o=r.route[i+1];if(a.x===o.x&&a.y===o.y)continue;const s=[a,o],l=M2e(s),c={segmentId:`${r.connectionName}-seg-${i}`,segment:s,parentRoute:r},u=Math.floor(l.minX/this.CELL_SIZE),d=Math.floor((l.maxX+t)/this.CELL_SIZE),f=Math.floor(l.minY/this.CELL_SIZE),m=Math.floor((l.maxY+t)/this.CELL_SIZE);for(let y=u;y<=d;y++)for(let E=f;E<=m;E++){const w=`${y}x${E}`;let S=this.segmentBuckets.get(w);S||(S=[],this.segmentBuckets.set(w,S)),S.push(c)}}if(r.vias&&r.vias.length>0)for(let i=0;i<r.vias.length;i++){const a=r.vias[i];if(a==null)continue;const o={viaId:`${r.connectionName}-via-${i}`,x:a.x,y:a.y,parentRoute:r},s=Math.floor(a.x/this.CELL_SIZE),l=Math.floor(a.y/this.CELL_SIZE),c=`${s}x${l}`;let u=this.viaBuckets.get(c);u||(u=[],this.viaBuckets.set(c,u)),u.push(o)}}}getConflictingRoutesForSegment(n,e,t){const i=M2e([n,e]),a=i.minX-t,o=i.minY-t,s=i.maxX+t,l=i.maxY+t,c=1e-9,u=Math.floor(a/this.CELL_SIZE),d=Math.floor((s+c)/this.CELL_SIZE),f=Math.floor(o/this.CELL_SIZE),m=Math.floor((l+c)/this.CELL_SIZE),y=new Map,E=new Set,w=new Set,S={x:n.x,y:n.y},T={x:e.x,y:e.y};for(let U=u;U<=d;U++)for(let H=f;H<=m;H++){const G=`${U}x${H}`,W=this.segmentBuckets.get(G);if(W)for(const Q of W){if(E.has(Q.segmentId))continue;E.add(Q.segmentId);const X=Q.parentRoute,[ue,pe]=Q.segment,ce=t+X.traceThickness/2,Se=ce*ce,he=Jvt(n,e,ue,pe);if(he<Se){const ge=X.connectionName,Te=y.get(ge);(!Te||he<Te.minDistSq)&&y.set(ge,{route:X,minDistSq:he})}}const $=this.viaBuckets.get(G);if($)for(const Q of $){if(w.has(Q.viaId))continue;w.add(Q.viaId);const X=Q.parentRoute,ue={x:Q.x,y:Q.y},pe=t+X.viaDiameter/2,ce=pe*pe,Se=OE(ue,S,T);if(Se<ce){const he=X.connectionName,ge=y.get(he);(!ge||Se<ge.minDistSq)&&y.set(he,{route:X,minDistSq:Se})}}}const P=[];for(const U of y.values())P.push({conflictingRoute:U.route,distance:Math.sqrt(U.minDistSq)});return P}getConflictingRoutesNearPoint(n,e){const t=n.x-e,r=n.y-e,i=n.x+e,a=n.y+e,o=1e-9,s=Math.floor(t/this.CELL_SIZE),l=Math.floor((i+o)/this.CELL_SIZE),c=Math.floor(r/this.CELL_SIZE),u=Math.floor((a+o)/this.CELL_SIZE),d=new Map,f=new Set,m=new Set;for(let E=s;E<=l;E++)for(let w=c;w<=u;w++){const S=`${E}x${w}`,T=this.segmentBuckets.get(S);if(T)for(const U of T){if(f.has(U.segmentId))continue;f.add(U.segmentId);const H=U.parentRoute,G={x:U.segment[0].x,y:U.segment[0].y},W={x:U.segment[1].x,y:U.segment[1].y},$=e+H.traceThickness/2,Q=$*$,X=OE(n,G,W);if(X<Q){const ue=H.connectionName,pe=d.get(ue);(!pe||X<pe.minDistSq)&&d.set(ue,{route:H,minDistSq:X})}}const P=this.viaBuckets.get(S);if(P)for(const U of P){if(m.has(U.viaId))continue;m.add(U.viaId);const H=U.parentRoute,G={x:U.x,y:U.y},W=e+H.viaDiameter/2,$=W*W,Q=GL(n,G);if(Q<$){const X=H.connectionName,ue=d.get(X);(!ue||Q<ue.minDistSq)&&d.set(X,{route:H,minDistSq:Q})}}}const y=[];for(const E of d.values())y.push({conflictingRoute:E.route,distance:Math.sqrt(E.minDistSq)});return y}},tyt=class extends o_{constructor(e){super();Je(this,"obstacleSHI");Je(this,"hdRouteSHI");Je(this,"unsimplifiedRoute");Je(this,"routeSections");Je(this,"currentSectionIndex");Je(this,"TRACE_THICKNESS",.15);Je(this,"OBSTACLE_MARGIN",.1);this.currentSectionIndex=1,this.obstacleSHI=e.obstacleSHI,this.hdRouteSHI=e.hdRouteSHI,this.unsimplifiedRoute=e.unsimplifiedRoute,this.routeSections=this.breakRouteIntoSections(this.unsimplifiedRoute)}breakRouteIntoSections(e){const t=[],r=e.route;if(r.length===0)return[];let i={startIndex:0,endIndex:-1,z:r[0].z,points:[r[0]]};for(let a=1;a<r.length;a++)r[a].z===i.z?i.points.push(r[a]):(i.endIndex=a-1,t.push(i),i={startIndex:a,endIndex:-1,z:r[a].z,points:[r[a]]});return i.endIndex=r.length-1,t.push(i),t}_step(){if(this.currentSectionIndex>=this.routeSections.length-1){this.solved=!0;return}const e=this.routeSections[this.currentSectionIndex-1],t=this.routeSections[this.currentSectionIndex],r=this.routeSections[this.currentSectionIndex+1];if(e.z!==r.z){this.currentSectionIndex++;return}const i=e.z;if(this.canSectionMoveToLayer({currentSection:t,targetZ:i})){t.z=i,t.points=t.points.map(a=>({...a,z:i})),this.currentSectionIndex+=2;return}this.currentSectionIndex++}canSectionMoveToLayer({currentSection:e,targetZ:t}){for(let r=0;r<e.points.length-1;r++){const i={...e.points[r],z:t},a={...e.points[r+1],z:t},o=this.hdRouteSHI.getConflictingRoutesForSegment(i,a,this.TRACE_THICKNESS);for(const{conflictingRoute:c,distance:u}of o)if(c.connectionName!==this.unsimplifiedRoute.connectionName&&u<this.TRACE_THICKNESS+c.traceThickness)return!1;const s={centerX:(i.x+a.x)/2,centerY:(i.y+a.y)/2,width:Math.abs(i.x-a.x),height:Math.abs(i.y-a.y)},l=this.obstacleSHI.getNodesInArea(s.centerX,s.centerY,s.width,s.height);for(const c of l)if(d2e(i,a,c)<this.TRACE_THICKNESS+this.OBSTACLE_MARGIN)return!1}return!0}getOptimizedHdRoute(){const e=this.routeSections.flatMap(r=>r.points),t=[];for(let r=0;r<e.length-1;r++)e[r].z!==e[r+1].z&&t.push({x:e[r].x,y:e[r].y});return{connectionName:this.unsimplifiedRoute.connectionName,route:e,traceThickness:this.unsimplifiedRoute.traceThickness,vias:t,viaDiameter:this.unsimplifiedRoute.viaDiameter}}visualize(){const e={circles:[],lines:[],points:[],rects:[],coordinateSystem:"cartesian",title:"Single Route Useless Via Removal Solver"};for(let t=0;t<this.routeSections.length;t++){const r=this.routeSections[t];e.lines.push({points:r.points,strokeWidth:this.TRACE_THICKNESS,strokeColor:t===this.currentSectionIndex?"orange":r.z===0?"red":"blue"})}return e}},nyt=class extends o_{constructor(e){super();Je(this,"unsimplifiedHdRoutes");Je(this,"optimizedHdRoutes");Je(this,"unprocessedRoutes");Je(this,"activeSubSolver",null);Je(this,"obstacleSHI",null);Je(this,"hdRouteSHI",null);this.input=e,this.unsimplifiedHdRoutes=e.unsimplifiedHdRoutes,this.optimizedHdRoutes=[],this.unprocessedRoutes=[...e.unsimplifiedHdRoutes],this.obstacleSHI=new s2e(e.obstacles),this.hdRouteSHI=new eyt(this.unsimplifiedHdRoutes)}_step(){if(this.activeSubSolver){this.activeSubSolver.step(),this.activeSubSolver.solved?(this.optimizedHdRoutes.push(this.activeSubSolver.getOptimizedHdRoute()),this.activeSubSolver=null):(this.activeSubSolver.failed||this.activeSubSolver.error)&&(this.error=this.activeSubSolver.error,this.failed=!0);return}const e=this.unprocessedRoutes.shift();if(!e){this.solved=!0;return}this.activeSubSolver=new tyt({hdRouteSHI:this.hdRouteSHI,obstacleSHI:this.obstacleSHI,unsimplifiedRoute:e})}getOptimizedHdRoutes(){return this.optimizedHdRoutes}visualize(){const e={lines:[],points:[],rects:[],circles:[],coordinateSystem:"cartesian",title:"Useless Via Removal Solver"};for(const t of this.optimizedHdRoutes)if(t.route.length!==0){this.input.colorMap[t.connectionName];for(let r=0;r<t.route.length-1;r++){const i=t.route[r],a=t.route[r+1];i.z===a.z&&e.lines.push({points:[{x:i.x,y:i.y},{x:a.x,y:a.y}],strokeColor:i.z===0?"red":"blue",strokeWidth:t.traceThickness,label:`${t.connectionName} (z=${i.z})`})}for(const r of t.vias)e.circles.push({center:{x:r.x,y:r.y},radius:t.viaDiameter/2,fill:"rgba(255, 0, 255, 0.5)",label:`${t.connectionName} via`})}return this.activeSubSolver&&e.lines.push(...this.activeSubSolver.visualize().lines??[]),e}};function h3(n,e,t,r={}){return{solverName:n,solverClass:e,getConstructorParams:t,onSolved:r.onSolved}}var ryt=class extends o_{constructor(e,t={}){super();Je(this,"netToPointPairsSolver");Je(this,"nodeSolver");Je(this,"nodeTargetMerger");Je(this,"edgeSolver");Je(this,"pathingSolver");Je(this,"edgeToPortSegmentSolver");Je(this,"colorMap");Je(this,"segmentToPointSolver");Je(this,"unravelMultiSectionSolver");Je(this,"segmentToPointOptimizer");Je(this,"highDensityRouteSolver");Je(this,"highDensityStitchSolver");Je(this,"singleLayerNodeMerger");Je(this,"strawSolver");Je(this,"uselessViaRemovalSolver");Je(this,"multiSimplifiedPathSolver");Je(this,"startTimeOfPhase");Je(this,"endTimeOfPhase");Je(this,"timeSpentOnPhase");Je(this,"activeSubSolver",null);Je(this,"connMap");Je(this,"srjWithPointPairs");Je(this,"capacityNodes",null);Je(this,"pipelineDef",[h3("netToPointPairsSolver",Cvt,e=>[e.srj,e.colorMap],{onSolved:e=>{var t;e.srjWithPointPairs=(t=e.netToPointPairsSolver)==null?void 0:t.getNewSimpleRouteJson(),e.colorMap=Sq(e.srjWithPointPairs,this.connMap),e.connMap=x2e(e.srjWithPointPairs)}}),h3("nodeSolver",K9t,e=>{var t;return[((t=e.netToPointPairsSolver)==null?void 0:t.getNewSimpleRouteJson())||e.srj,e.opts]},{onSolved:e=>{var t;e.capacityNodes=(t=e.nodeSolver)==null?void 0:t.finishedNodes}}),h3("singleLayerNodeMerger",Hvt,e=>{var t;return[(t=e.nodeSolver)==null?void 0:t.finishedNodes]},{onSolved:e=>{var t;e.capacityNodes=(t=e.singleLayerNodeMerger)==null?void 0:t.newNodes}}),h3("strawSolver",jvt,e=>{var t;return[{nodes:(t=e.singleLayerNodeMerger)==null?void 0:t.newNodes}]},{onSolved:e=>{var t;e.capacityNodes=(t=e.strawSolver)==null?void 0:t.getResultNodes()}}),h3("edgeSolver",Kvt,e=>[e.capacityNodes]),h3("pathingSolver",Bvt,e=>{var t;return[{simpleRouteJson:e.srjWithPointPairs,nodes:e.capacityNodes,edges:((t=e.edgeSolver)==null?void 0:t.edges)||[],colorMap:e.colorMap,hyperParameters:{MAX_CAPACITY_FACTOR:1}}]}),h3("edgeToPortSegmentSolver",J9t,e=>{var t,r;return[{nodes:e.capacityNodes,edges:((t=e.edgeSolver)==null?void 0:t.edges)||[],capacityPaths:((r=e.pathingSolver)==null?void 0:r.getCapacityPaths())||[],colorMap:e.colorMap}]}),h3("segmentToPointSolver",rvt,e=>{var r;const t=[];return(r=e.edgeToPortSegmentSolver)!=null&&r.nodePortSegments&&e.edgeToPortSegmentSolver.nodePortSegments.forEach(i=>{t.push(...i)}),[{segments:t,colorMap:e.colorMap,nodes:e.capacityNodes}]}),h3("unravelMultiSectionSolver",Ivt,e=>{var t;return[{assignedSegments:((t=e.segmentToPointSolver)==null?void 0:t.solvedSegments)||[],colorMap:e.colorMap,nodes:e.capacityNodes}]}),h3("highDensityRouteSolver",Svt,e=>{var t,r;return[{nodePortPoints:((t=e.unravelMultiSectionSolver)==null?void 0:t.getNodesWithPortPoints())??((r=e.segmentToPointOptimizer)==null?void 0:r.getNodesWithPortPoints())??[],colorMap:e.colorMap,connMap:e.connMap}]}),h3("highDensityStitchSolver",Pvt,e=>[{connections:e.srjWithPointPairs.connections,hdRoutes:e.highDensityRouteSolver.routes,layerCount:e.srj.layerCount}]),h3("uselessViaRemovalSolver",nyt,e=>[{unsimplifiedHdRoutes:e.highDensityStitchSolver.mergedHdRoutes,obstacles:e.srj.obstacles,colorMap:e.colorMap,layerCount:e.srj.layerCount}]),h3("multiSimplifiedPathSolver",Zvt,e=>{var t;return[{unsimplifiedHdRoutes:((t=e.uselessViaRemovalSolver)==null?void 0:t.getOptimizedHdRoutes())||e.highDensityStitchSolver.mergedHdRoutes,obstacles:e.srj.obstacles,connMap:e.connMap,colorMap:e.colorMap}]})]);Je(this,"currentPipelineStepIndex",0);if(this.srj=e,this.opts=t,this.MAX_ITERATIONS=1e6,t.capacityDepth===void 0){const r=e.bounds.maxX-e.bounds.minX,i=e.bounds.maxY-e.bounds.minY,a=Math.max(r,i),o=t.targetMinCapacity??.5;t.capacityDepth=W9t(a,o)}this.connMap=x2e(e),this.colorMap=Sq(e,this.connMap),this.startTimeOfPhase={},this.endTimeOfPhase={},this.timeSpentOnPhase={}}_step(){var r,i;const e=this.pipelineDef[this.currentPipelineStepIndex];if(!e){this.solved=!0;return}if(this.activeSubSolver){this.activeSubSolver.step(),this.activeSubSolver.solved?(this.endTimeOfPhase[e.solverName]=performance.now(),this.timeSpentOnPhase[e.solverName]=this.endTimeOfPhase[e.solverName]-this.startTimeOfPhase[e.solverName],(r=e.onSolved)==null||r.call(e,this),this.activeSubSolver=null,this.currentPipelineStepIndex++):this.activeSubSolver.failed&&(this.error=(i=this.activeSubSolver)==null?void 0:i.error,this.failed=!0,this.activeSubSolver=null);return}const t=e.getConstructorParams(this);this.activeSubSolver=new e.solverClass(...t),this[e.solverName]=this.activeSubSolver,this.timeSpentOnPhase[e.solverName]=0,this.startTimeOfPhase[e.solverName]=performance.now()}solveUntilPhase(e){for(;this.getCurrentPhase()!==e;)this.step()}getCurrentPhase(){var e;return((e=this.pipelineDef[this.currentPipelineStepIndex])==null?void 0:e.solverName)??"none"}visualize(){var S,T,P,U,H,G,W,$,Q,X,ue,pe,ce,Se,he,ge,Te,xe,Ae,Ne,ze,Re,qe,Ke,ut;if(!this.solved&&this.activeSubSolver)return this.activeSubSolver.visualize();const e=(S=this.netToPointPairsSolver)==null?void 0:S.visualize(),t=(T=this.nodeSolver)==null?void 0:T.visualize(),r=(P=this.nodeTargetMerger)==null?void 0:P.visualize(),i=(U=this.singleLayerNodeMerger)==null?void 0:U.visualize(),a=(H=this.strawSolver)==null?void 0:H.visualize(),o=(G=this.edgeSolver)==null?void 0:G.visualize(),s=(W=this.pathingSolver)==null?void 0:W.visualize(),l=($=this.edgeToPortSegmentSolver)==null?void 0:$.visualize(),c=(Q=this.segmentToPointSolver)==null?void 0:Q.visualize(),u=((X=this.unravelMultiSectionSolver)==null?void 0:X.visualize())??((ue=this.segmentToPointOptimizer)==null?void 0:ue.visualize()),d=(pe=this.highDensityRouteSolver)==null?void 0:pe.visualize(),f=(ce=this.highDensityStitchSolver)==null?void 0:ce.visualize(),m=(Se=this.uselessViaRemovalSolver)==null?void 0:Se.visualize(),y=(he=this.multiSimplifiedPathSolver)==null?void 0:he.visualize(),E={points:[...this.srj.connections.flatMap(pt=>pt.pointsToConnect.map(Tt=>({...Tt,label:`${pt.name} ${Tt.pcb_port_id??""}`})))],rects:[...(this.srj.obstacles??[]).map(pt=>{var Tt,Gt,Kt;return{...pt,fill:(Tt=pt.layers)!=null&&Tt.includes("top")?"rgba(255,0,0,0.25)":(Gt=pt.layers)!=null&&Gt.includes("bottom")?"rgba(0,0,255,0.25)":"rgba(255,0,0,0.25)",label:(Kt=pt.layers)==null?void 0:Kt.join(", ")}})],lines:[{points:[{x:((ge=this.srj.bounds)==null?void 0:ge.minX)??-50,y:((Te=this.srj.bounds)==null?void 0:Te.minY)??-50},{x:((xe=this.srj.bounds)==null?void 0:xe.maxX)??50,y:((Ae=this.srj.bounds)==null?void 0:Ae.minY)??-50},{x:((Ne=this.srj.bounds)==null?void 0:Ne.maxX)??50,y:((ze=this.srj.bounds)==null?void 0:ze.maxY)??50},{x:((Re=this.srj.bounds)==null?void 0:Re.minX)??-50,y:((qe=this.srj.bounds)==null?void 0:qe.maxY)??50},{x:((Ke=this.srj.bounds)==null?void 0:Ke.minX)??-50,y:((ut=this.srj.bounds)==null?void 0:ut.minY)??-50}],strokeColor:"rgba(255,0,0,0.25)"}]},w=[E,e,t,r,i,a,o,s,l,c,u,d?OL(E,d):null,f,m,y,this.solved?OL(E,Nvt(this.getOutputSimpleRouteJson())):null].filter(Boolean);return OL(...w)}preview(){var e;if(this.highDensityRouteSolver){const t=[];for(let r=this.highDensityRouteSolver.routes.length-1;r>=0;r--){const i=this.highDensityRouteSolver.routes[r];if(t.push({points:i.route.map(a=>({x:a.x,y:a.y})),strokeColor:this.colorMap[i.connectionName]}),t.length>200)break}return{lines:t}}if(this.pathingSolver){const t=[];for(const r of this.pathingSolver.connectionsWithNodes)r.path&&t.push({points:r.path.map(i=>({x:i.center.x,y:i.center.y})),strokeColor:this.colorMap[r.connection.name]});return{lines:t}}return this.netToPointPairsSolver?(e=this.netToPointPairsSolver)==null?void 0:e.visualize():{}}getOriginalConnectionName(e){const t=e.match(/^(.+?)_mst\d+$/);return t?t[1]:e}_getOutputHdRoutes(){var e,t;return((e=this.multiSimplifiedPathSolver)==null?void 0:e.simplifiedHdRoutes)??((t=this.uselessViaRemovalSolver)==null?void 0:t.getOptimizedHdRoutes())??this.highDensityStitchSolver.mergedHdRoutes}getOutputSimplifiedPcbTraces(){var r;if(!this.solved||!this.highDensityRouteSolver)throw new Error("Cannot get output before solving is complete");const e=[],t=this._getOutputHdRoutes();for(const i of((r=this.netToPointPairsSolver)==null?void 0:r.newConnections)??[]){this.srj.connections.find(o=>o.name===i.netConnectionName);const a=t.filter(o=>o.connectionName===i.name);for(let o=0;o<a.length;o++){const s=a[o],l={type:"pcb_trace",pcb_trace_id:`${i.name}_${o}`,connection_name:this.getOriginalConnectionName(i.name),route:Rvt(s,this.srj.layerCount)};e.push(l)}}return e}getOutputSimpleRouteJson(){return{...this.srj,traces:this.getOutputSimplifiedPcbTraces()}}},Cq=ryt,Gb=(n,e={})=>{let t=n._internal_store;if(!t){t={counts:{},editCount:0},n._internal_store=t;for(const i of n){const a=i.type,o=i[`${a}_id`];if(!o)continue;const s=Number.parseInt(o.split("_").pop());Number.isNaN(s)||(t.counts[a]=Math.max(t.counts[a]??0,s))}}return new Proxy({},{get:(i,a)=>{if(a==="toArray")return()=>(n.editCount=t.editCount,n);if(a==="editCount")return t.editCount;const o=a;return{get:s=>n.find(l=>l.type===o&&l[`${o}_id`]===s),getUsing:s=>{const l=Object.keys(s);if(l.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const c=l[0],u=c.replace("_id",""),d=n.find(f=>f.type===u&&f[c]===s[c]);return d?n.find(f=>f.type===o&&f[`${o}_id`]===d[`${o}_id`]):null},getWhere:s=>{const l=Object.keys(s);return n.find(c=>c.type===o&&l.every(u=>c[u]===s[u]))},list:s=>{const l=s?Object.keys(s):[];return n.filter(c=>c.type===o&&l.every(u=>c[u]===s[u]))},insert:s=>{var u;(u=t.counts)[o]??(u[o]=-1),t.counts[o]++;const l=t.counts[o],c={type:o,[`${o}_id`]:`${o}_${l}`,...s};return e.validateInserts&&(oD[o]??yC).parse(c),n.push(c),t.editCount++,c},delete:s=>{const l=n.find(c=>c[`${o}_id`]===s);l&&(n.splice(n.indexOf(l),1),t.editCount++)},update:(s,l)=>{const c=n.find(u=>u.type===o&&u[`${o}_id`]===s);return c?(Object.assign(c,l),t.editCount++,c):null},select:s=>{if(o==="source_component")return n.find(l=>l.type==="source_component"&&l.name===s.replace(/\./g,""));if(o==="pcb_port"||o==="source_port"||o==="schematic_port"){const[l,c]=s.replace(/\./g,"").split(/[\s\>]+/),u=n.find(f=>f.type==="source_component"&&f.name===l);if(!u)return null;const d=n.find(f=>f.type==="source_port"&&f.source_component_id===u.source_component_id&&(f.name===c||(f.port_hints??[]).includes(c)));if(!d)return null;if(o==="source_port")return d;if(o==="pcb_port")return n.find(f=>f.type==="pcb_port"&&f.source_port_id===d.source_port_id);if(o==="schematic_port")return n.find(f=>f.type==="schematic_port"&&f.source_port_id===d.source_port_id)}}}}})};Gb.unparsed=Gb;var m3=Gb,K2=Gb;function Rq(n){const e=n.type;return`${e}:${n[`${e}_id`]}`}var C2e=(n,e={})=>{let t=n._internal_store_indexed;if(!t){t={counts:{},editCount:0,indexes:{}};for(const o of n){const s=o.type,l=o[`${s}_id`];if(!l)continue;const c=Number.parseInt(l.split("_").pop()||"");Number.isNaN(c)||(t.counts[s]=Math.max(t.counts[s]??0,c))}const i=e.indexConfig||{},a=t.indexes;if(i.byId&&(a.byId=new Map),i.byType&&(a.byType=new Map),i.byRelation&&(a.byRelation=new Map),i.bySubcircuit&&(a.bySubcircuit=new Map),i.byCustomField&&i.byCustomField.length>0){a.byCustomField=new Map;for(const o of i.byCustomField)a.byCustomField.set(o,new Map)}for(const o of n){if(i.byId){const s=Rq(o);a.byId.set(s,o)}if(i.byType){const s=a.byType.get(o.type)||[];s.push(o),a.byType.set(o.type,s)}if(i.byRelation){const s=Object.entries(o);for(const[l,c]of s)if(l.endsWith("_id")&&l!==`${o.type}_id`&&typeof c=="string"){const u=a.byRelation.get(l)||new Map,d=u.get(c)||[];d.push(o),u.set(c,d),a.byRelation.set(l,u)}}if(i.bySubcircuit&&"subcircuit_id"in o){const s=o.subcircuit_id;if(s&&typeof s=="string"){const l=a.bySubcircuit.get(s)||[];l.push(o),a.bySubcircuit.set(s,l)}}if(i.byCustomField&&a.byCustomField){for(const s of i.byCustomField)if(s in o){const l=o[s];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const c=String(l),u=a.byCustomField.get(s),d=u.get(c)||[];d.push(o),u.set(c,d)}}}}n._internal_store_indexed=t}return new Proxy({},{get:(i,a)=>{if(a==="toArray")return()=>(n.editCount=t.editCount,n);if(a==="editCount")return t.editCount;const o=a;return{get:s=>{const l=e.indexConfig||{};return l.byId&&t.indexes.byId?t.indexes.byId.get(`${o}:${s}`)||null:l.byType&&t.indexes.byType?(t.indexes.byType.get(o)||[]).find(u=>u[`${o}_id`]===s)||null:n.find(c=>c.type===o&&c[`${o}_id`]===s)||null},getUsing:s=>{const l=e.indexConfig||{},c=Object.keys(s);if(c.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const u=c[0],d=u.replace("_id","");if(l.byRelation&&t.indexes.byRelation){const m=t.indexes.byRelation.get(u);if(m){const E=(m.get(s[u])||[]).find(S=>S.type===d);if(!E)return null;const w=E[`${o}_id`];return l.byId&&t.indexes.byId?t.indexes.byId.get(`${o}:${w}`)||null:l.byType&&t.indexes.byType?(t.indexes.byType.get(o)||[]).find(T=>T[`${o}_id`]===w)||null:n.find(S=>S.type===o&&S[`${o}_id`]===w)||null}}const f=n.find(m=>m.type===d&&m[u]===s[u]);return f&&n.find(m=>m.type===o&&m[`${o}_id`]===f[`${o}_id`])||null},getWhere:s=>{const l=e.indexConfig||{},c=Object.keys(s);if(c.length===1&&l.byCustomField&&t.indexes.byCustomField){const u=c[0],d=t.indexes.byCustomField.get(u);if(d){const f=String(s[u]);return(d.get(f)||[]).find(y=>y.type===o)||null}}if("subcircuit_id"in s&&l.bySubcircuit&&t.indexes.bySubcircuit){const u=s.subcircuit_id;return(t.indexes.bySubcircuit.get(u)||[]).find(f=>f.type===o&&c.every(m=>f[m]===s[m]))||null}return l.byType&&t.indexes.byType?(t.indexes.byType.get(o)||[]).find(d=>c.every(f=>d[f]===s[f]))||null:n.find(u=>u.type===o&&c.every(d=>u[d]===s[d]))||null},list:s=>{const l=e.indexConfig||{},c=s?Object.keys(s):[];if(c.length===0&&l.byType&&t.indexes.byType)return t.indexes.byType.get(o)||[];if(c.length===1&&c[0]==="subcircuit_id"&&l.bySubcircuit&&t.indexes.bySubcircuit){const d=s.subcircuit_id;return(t.indexes.bySubcircuit.get(d)||[]).filter(m=>m.type===o)}let u;return l.byType&&t.indexes.byType?u=t.indexes.byType.get(o)||[]:u=n.filter(d=>d.type===o),c.length>0?u.filter(d=>c.every(f=>d[f]===s[f])):u},insert:s=>{var d;(d=t.counts)[o]??(d[o]=-1),t.counts[o]++;const l=t.counts[o],c={type:o,[`${o}_id`]:`${o}_${l}`,...s};e.validateInserts&&(oD[o]??yC).parse(c),n.push(c),t.editCount++;const u=e.indexConfig||{};if(u.byId&&t.indexes.byId){const f=Rq(c);t.indexes.byId.set(f,c)}if(u.byType&&t.indexes.byType){const f=t.indexes.byType.get(o)||[];f.push(c),t.indexes.byType.set(o,f)}if(u.byRelation&&t.indexes.byRelation){const f=Object.entries(c);for(const[m,y]of f)if(m.endsWith("_id")&&m!==`${c.type}_id`&&typeof y=="string"){const E=t.indexes.byRelation.get(m)||new Map,w=E.get(y)||[];w.push(c),E.set(y,w),t.indexes.byRelation.set(m,E)}}if(u.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in c){const f=c.subcircuit_id;if(f&&typeof f=="string"){const m=t.indexes.bySubcircuit.get(f)||[];m.push(c),t.indexes.bySubcircuit.set(f,m)}}if(u.byCustomField&&t.indexes.byCustomField){for(const f of u.byCustomField)if(f in c){const m=c[f];if(m!==void 0&&(typeof m=="string"||typeof m=="number")){const y=String(m),E=t.indexes.byCustomField.get(f),w=E.get(y)||[];w.push(c),E.set(y,w)}}}return c},delete:s=>{const l=e.indexConfig||{};let c;if(l.byId&&t.indexes.byId?c=t.indexes.byId.get(`${o}:${s}`):l.byType&&t.indexes.byType?c=(t.indexes.byType.get(o)||[]).find(f=>f[`${o}_id`]===s):c=n.find(d=>d[`${o}_id`]===s),!c)return;const u=n.indexOf(c);if(u>=0&&(n.splice(u,1),t.editCount++),l.byId&&t.indexes.byId){const d=Rq(c);t.indexes.byId.delete(d)}if(l.byType&&t.indexes.byType){const f=(t.indexes.byType.get(o)||[]).filter(m=>m[`${o}_id`]!==s);t.indexes.byType.set(o,f)}if(l.byRelation&&t.indexes.byRelation)for(const[d,f]of t.indexes.byRelation.entries())for(const[m,y]of f.entries()){const E=y.filter(w=>w!==c);E.length===0?f.delete(m):f.set(m,E)}if(l.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in c){const d=c.subcircuit_id;if(d){const m=(t.indexes.bySubcircuit.get(d)||[]).filter(y=>y!==c);m.length===0?t.indexes.bySubcircuit.delete(d):t.indexes.bySubcircuit.set(d,m)}}if(l.byCustomField&&t.indexes.byCustomField)for(const d of t.indexes.byCustomField.values())for(const[f,m]of d.entries()){const y=m.filter(E=>E!==c);y.length===0?d.delete(f):d.set(f,y)}},update:(s,l)=>{const c=e.indexConfig||{};let u;if(c.byId&&t.indexes.byId?u=t.indexes.byId.get(`${o}:${s}`):c.byType&&t.indexes.byType?u=(t.indexes.byType.get(o)||[]).find(f=>f[`${o}_id`]===s):u=n.find(d=>d.type===o&&d[`${o}_id`]===s),!u)return null;if(c.byRelation&&t.indexes.byRelation){const d=Object.entries(u);for(const[f,m]of d)if(f.endsWith("_id")&&f!==`${u.type}_id`&&typeof m=="string"&&f in l&&l[f]!==m){const y=t.indexes.byRelation.get(f);if(y){const w=(y.get(m)||[]).filter(S=>S!==u);w.length===0?y.delete(m):y.set(m,w)}}}if(c.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in u&&"subcircuit_id"in l){const d=u.subcircuit_id,f=l.subcircuit_id;if(d!==f){const y=(t.indexes.bySubcircuit.get(d)||[]).filter(E=>E!==u);y.length===0?t.indexes.bySubcircuit.delete(d):t.indexes.bySubcircuit.set(d,y)}}if(c.byCustomField&&t.indexes.byCustomField){for(const d of c.byCustomField)if(d in u&&d in l&&u[d]!==l[d]){const f=t.indexes.byCustomField.get(d);if(f){const m=String(u[d]),E=(f.get(m)||[]).filter(w=>w!==u);E.length===0?f.delete(m):f.set(m,E)}}}if(Object.assign(u,l),t.editCount++,c.byRelation&&t.indexes.byRelation){const d=Object.entries(u);for(const[f,m]of d)if(f.endsWith("_id")&&f!==`${u.type}_id`&&typeof m=="string"&&f in l){const y=t.indexes.byRelation.get(f)||new Map,E=y.get(m)||[];E.includes(u)||(E.push(u),y.set(m,E),t.indexes.byRelation.set(f,y))}}if(c.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in u&&"subcircuit_id"in l){const d=u.subcircuit_id;if(d&&typeof d=="string"){const f=t.indexes.bySubcircuit.get(d)||[];f.includes(u)||(f.push(u),t.indexes.bySubcircuit.set(d,f))}}if(c.byCustomField&&t.indexes.byCustomField){for(const d of c.byCustomField)if(d in u&&d in l){const f=u[d];if(f!==void 0&&(typeof f=="string"||typeof f=="number")){const m=String(f),y=t.indexes.byCustomField.get(d),E=y.get(m)||[];E.includes(u)||(E.push(u),y.set(m,E))}}}return u},select:s=>{if(o==="source_component")return n.find(l=>l.type==="source_component"&&l.name===s.replace(/\./g,""))||null;if(o==="pcb_port"||o==="source_port"||o==="schematic_port"){const[l,c]=s.replace(/\./g,"").split(/[\s\>]+/),u=n.find(f=>f.type==="source_component"&&f.name===l);if(!u)return null;const d=n.find(f=>f.type==="source_port"&&f.source_component_id===u.source_component_id&&(f.name===c||(f.port_hints??[]).includes(c)));if(!d)return null;if(o==="source_port")return d;if(o==="pcb_port")return n.find(f=>f.type==="pcb_port"&&f.source_port_id===d.source_port_id)||null;if(o==="schematic_port")return n.find(f=>f.type==="schematic_port"&&f.source_port_id===d.source_port_id)||null}return null}}}})};C2e.unparsed=C2e;var iyt=(n,e)=>{if(n.type==="pcb_plated_hole"||n.type==="pcb_hole"||n.type==="pcb_via"||n.type==="pcb_smtpad"||n.type==="pcb_port"){const{x:t,y:r}=Cr(e,{x:n.x,y:n.y});n.x=t,n.y=r}else if(n.type==="pcb_keepout"||n.type==="pcb_board")n.center=Cr(e,n.center);else if(n.type==="pcb_silkscreen_text"||n.type==="pcb_fabrication_note_text")n.anchor_position=Cr(e,n.anchor_position);else if(n.type==="pcb_silkscreen_circle"||n.type==="pcb_silkscreen_rect"||n.type==="pcb_component")n.center=Cr(e,n.center);else if(n.type==="pcb_silkscreen_path"||n.type==="pcb_trace"||n.type==="pcb_fabrication_note_path")n.route=n.route.map(t=>{const r=Cr(e,t);return t.x=r.x,t.y=r.y,t});else if(n.type==="pcb_silkscreen_line"){const t={x:n.x1,y:n.y1},r={x:n.x2,y:n.y2},i=Cr(e,t),a=Cr(e,r);n.x1=i.x,n.y1=i.y,n.x2=a.x,n.y2=a.y}else if(n.type==="cad_component"){const t=Cr(e,{x:n.position.x,y:n.position.y});n.position.x=t.x,n.position.y=t.y}return n},R2e=n=>{const e=n.type;return n[`${e}_id`]},ayt=(n,e)=>n.find(t=>R2e(t)===e)??null;function oyt(n,e){const t=Gb(n).pcb_trace.get(e);if(!t)return`trace[${e}]`;const r=t.route.flatMap(o=>[o.start_pcb_port_id,o.end_pcb_port_id]).filter(Boolean);if(r.length===0)return`trace[${e}]`;function i(o){const s=Gb(n).pcb_port.get(o);if(!s)return null;const l=Gb(n).pcb_component.get(s.pcb_component_id);if(!l)return null;const c=Gb(n).source_component.get(l.source_component_id);if(!c)return null;const u=Gb(n).source_port.get(s.source_port_id),d=u!=null&&u.port_hints?u.port_hints[1]:"";return{componentName:c.name,portHint:d}}return`trace[${r.map(o=>{const s=i(o);return s?`.${s.componentName} > port.${s.portHint}`:`port[${o}]`}).join(", ")}]`}var A2e=(n,e)=>{const t=Gb(n).pcb_port.get(e);if(!t)return`pcb_port[#${e}]`;const r=Gb(n).pcb_component.get(t==null?void 0:t.pcb_component_id);if(!r)return`pcb_port[#${e}]`;const i=Gb(n).source_component.get(r.source_component_id);if(!i)return`pcb_port[#${e}]`;const a=Gb(n).source_port.get(t.source_port_id);if(!a)return`pcb_port[#${e}]`;let o;return a!=null&&a.port_hints&&a.port_hints.length>0||a.port_hints&&a.port_hints.length>0?o=a.port_hints[0]:o=e,`pcb_port[.${i.name} > .${o}]`};function syt(n,e){const t=Gb(n).pcb_smtpad.get(e);return!t||!t.pcb_port_id?`smtpad[${e}]`:A2e(n,t.pcb_port_id)}var qL=(n,e)=>{if(typeof e=="string"){const t=ayt(n,e);return qL(n,t)}switch(e.type){case"pcb_port":return A2e(n,e.pcb_port_id);case"pcb_smtpad":return syt(n,e.pcb_smtpad_id);case"pcb_trace":return oyt(n,e.pcb_trace_id);case"source_component":return`source_component[${e.name}]`;default:return`${e.type}[#${R2e(e)}]`}},Aq=n=>{let e=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(const a of n){if(!a.type.startsWith("pcb_"))continue;let o,s,l,c;if("x"in a&&"y"in a&&(o=a.x,s=a.y),"outer_diameter"in a&&(l=a.outer_diameter,c=a.outer_diameter),"width"in a&&(l=a.width),"height"in a&&(c=a.height),"center"in a&&(o=a.center.x,s=a.center.y),o!==void 0&&s!==void 0)e=Math.min(e,o),t=Math.min(t,s),r=Math.max(r,o),i=Math.max(i,s),l!==void 0&&c!==void 0&&(e=Math.min(e,o-l/2),t=Math.min(t,s-c/2),r=Math.max(r,o+l/2),i=Math.max(i,s+c/2)),"radius"in a&&(e=Math.min(e,o-a.radius),t=Math.min(t,s-a.radius),r=Math.max(r,o+a.radius),i=Math.max(i,s+a.radius));else if(a.type==="pcb_trace")for(const u of a.route)e=Math.min(e,u.x),t=Math.min(t,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y)}return{minX:e,minY:t,maxX:r,maxY:i}},Q8=n=>n[`${n.type}_id`],lyt=class{constructor({objects:e,getBounds:t,getId:r,CELL_SIZE:i}){Je(this,"buckets");Je(this,"objectsById");Je(this,"getBounds");Je(this,"getId");Je(this,"CELL_SIZE",.4);Je(this,"_idCounter",0);this.buckets=new Map,this.objectsById=new Map,this.getBounds=t,this.getId=r??(()=>this._getNextId()),this.CELL_SIZE=i??this.CELL_SIZE;for(const a of e)this.addObject(a)}_getNextId(){return`${this._idCounter++}`}addObject(e){const t=this.getBounds(e),r=this.getId(e),i={...e,spatialIndexId:r};this.objectsById.set(r,i);const a=Math.floor(t.minX/this.CELL_SIZE),o=Math.floor(t.minY/this.CELL_SIZE),s=Math.floor(t.maxX/this.CELL_SIZE),l=Math.floor(t.maxY/this.CELL_SIZE);for(let c=a;c<=s;c++)for(let u=o;u<=l;u++){const d=`${c}x${u}`,f=this.buckets.get(d);f?f.push(i):this.buckets.set(d,[i])}}removeObject(e){const t=this.objectsById.get(e);if(!t)return!1;this.objectsById.delete(e);const r=this.getBounds(t),i=Math.floor(r.minX/this.CELL_SIZE),a=Math.floor(r.minY/this.CELL_SIZE),o=Math.floor(r.maxX/this.CELL_SIZE),s=Math.floor(r.maxY/this.CELL_SIZE);for(let l=i;l<=o;l++)for(let c=a;c<=s;c++){const u=`${l}x${c}`,d=this.buckets.get(u);if(d){const f=d.findIndex(m=>m.spatialIndexId===e);f!==-1&&(d.splice(f,1),d.length===0&&this.buckets.delete(u))}}return!0}getBucketKey(e,t){return`${Math.floor(e/this.CELL_SIZE)}x${Math.floor(t/this.CELL_SIZE)}`}getObjectsInBounds(e,t=0){const r=[],i=new Set,a=Math.floor((e.minX-t)/this.CELL_SIZE),o=Math.floor((e.minY-t)/this.CELL_SIZE),s=Math.floor((e.maxX+t)/this.CELL_SIZE),l=Math.floor((e.maxY+t)/this.CELL_SIZE);for(let c=a;c<=s;c++)for(let u=o;u<=l;u++){const d=`${c}x${u}`,f=this.buckets.get(d)||[];for(const m of f){const y=m.spatialIndexId;i.has(y)||(i.add(y),r.push(m))}}return r}},DC=n=>n.type==="pcb_trace_segment"?{minX:Math.min(n.x1,n.x2),minY:Math.min(n.y1,n.y2),maxX:Math.max(n.x1,n.x2),maxY:Math.max(n.y1,n.y2)}:Aq([n]),Pq=.1,cyt=.15,Nq=.005;function uyt(n){const e=new Set;for(const t of n.route)t.route_type==="wire"&&(t.start_pcb_port_id&&e.add(t.start_pcb_port_id),t.end_pcb_port_id&&e.add(t.end_pcb_port_id));return Array.from(e)}function Dq(n){const e=new Set;for(const t of n)for(const r of uyt(t))e.add(r);return Array.from(e)}var dyt=(n,e)=>{const t={x:n.x1,y:n.y1},r={x:n.x2,y:n.y2},i={x:e.x1,y:e.y1},a={x:e.x2,y:e.y2},o={x:r.x-t.x,y:r.y-t.y},s={x:a.x-i.x,y:a.y-i.y},l=o.x*o.x+o.y*o.y,c=s.x*s.x+s.y*s.y;if(l===0||c===0){if(l===0&&c===0)return{x:(t.x+i.x)/2,y:(t.y+i.y)/2};if(l===0){const $=Z4(((t.x-i.x)*s.x+(t.y-i.y)*s.y)/c,0,1),Q={x:i.x+$*s.x,y:i.y+$*s.y};return{x:(t.x+Q.x)/2,y:(t.y+Q.y)/2}}const G=Z4(((i.x-t.x)*o.x+(i.y-t.y)*o.y)/l,0,1),W={x:t.x+G*o.x,y:t.y+G*o.y};return{x:(W.x+i.x)/2,y:(W.y+i.y)/2}}const u={x:t.x-i.x,y:t.y-i.y},d=o.x*o.x+o.y*o.y,f=o.x*s.x+o.y*s.y,m=o.x*u.x+o.y*u.y,y=s.x*s.x+s.y*s.y,E=s.x*u.x+s.y*u.y,w=d*y-f*f;if(w<1e-10)return fyt(t,r,i,a,o,s,l,c);let S=(f*E-y*m)/w,T=(d*E-f*m)/w;S=Z4(S,0,1),T=Z4(T,0,1),T=(S*f+E)/y,T=Z4(T,0,1),S=(T*f-m)/d,S=Z4(S,0,1);const P={x:t.x+S*o.x,y:t.y+S*o.y},U={x:i.x+T*s.x,y:i.y+T*s.y};return{x:(P.x+U.x)/2,y:(P.y+U.y)/2}},fyt=(n,e,t,r,i,a,o,s)=>{let l=((t.x-n.x)*i.x+(t.y-n.y)*i.y)/o;l=Z4(l,0,1);const c={x:n.x+l*i.x,y:n.y+l*i.y};let u=((r.x-n.x)*i.x+(r.y-n.y)*i.y)/o;u=Z4(u,0,1);const d={x:n.x+u*i.x,y:n.y+u*i.y};let f=((n.x-t.x)*a.x+(n.y-t.y)*a.y)/s;f=Z4(f,0,1);const m={x:t.x+f*a.x,y:t.y+f*a.y};let y=((e.x-t.x)*a.x+(e.y-t.y)*a.y)/s;y=Z4(y,0,1);const E={x:t.x+y*a.x,y:t.y+y*a.y},S=[{pointA:c,pointB:t,distance:Math.sqrt((c.x-t.x)**2+(c.y-t.y)**2)},{pointA:d,pointB:r,distance:Math.sqrt((d.x-r.x)**2+(d.y-r.y)**2)},{pointA:n,pointB:m,distance:Math.sqrt((n.x-m.x)**2+(n.y-m.y)**2)},{pointA:e,pointB:E,distance:Math.sqrt((e.x-E.x)**2+(e.y-E.y)**2)}].reduce((T,P)=>P.distance<T.distance?P:T);return{x:(S.pointA.x+S.pointB.x)/2,y:(S.pointA.y+S.pointB.y)/2}},Z4=(n,e,t)=>Math.max(e,Math.min(t,n)),pyt=n=>{if(n.type==="pcb_via"||n.type==="pcb_plated_hole"&&n.shape==="circle")return n.outer_diameter/2;if(n.type==="pcb_hole"&&n.hole_shape==="circle")return n.hole_diameter/2;if(n.type==="pcb_smtpad"&&n.shape==="circle")return n.radius;throw new Error(`Could not determine radius of element: ${JSON.stringify(n)}`)},P2e=(n,e)=>{const t={x:n.x1,y:n.y1},r={x:n.x2,y:n.y2},i=e.minX,a=e.minY,o=e.maxX,s=e.maxY;if(t.x===r.x&&t.y===r.y){const $=Math.max(i,Math.min(o,t.x)),Q=Math.max(a,Math.min(s,t.y));return $===t.x&&Q===t.y?{x:t.x,y:t.y}:{x:$,y:Q}}const l=r.x-t.x,c=r.y-t.y,u=l!==0?(i-t.x)/l:Number.NEGATIVE_INFINITY,d=l!==0?(o-t.x)/l:Number.POSITIVE_INFINITY,f=c!==0?(a-t.y)/c:Number.NEGATIVE_INFINITY,m=c!==0?(s-t.y)/c:Number.POSITIVE_INFINITY,y=Math.max(Math.min(u,d),Math.min(f,m)),E=Math.min(Math.max(u,d),Math.max(f,m));if(y<=E&&E>=0&&y<=1){const $=Math.max(0,Math.min(1,y));return{x:t.x+$*l,y:t.y+$*c}}const w={x:Math.max(i,Math.min(o,t.x)),y:Math.max(a,Math.min(s,t.y))},S={x:Math.max(i,Math.min(o,r.x)),y:Math.max(a,Math.min(s,r.y))},T=(w.x-t.x)**2+(w.y-t.y)**2,P=(S.x-r.x)**2+(S.y-r.y)**2,U=[{start:{x:i,y:a},end:{x:o,y:a}},{start:{x:o,y:a},end:{x:o,y:s}},{start:{x:o,y:s},end:{x:i,y:s}},{start:{x:i,y:s},end:{x:i,y:a}}];let H=Math.min(T,P),G=T<=P?w:S;const W=($,Q,X)=>Math.max(Q,Math.min(X,$));for(const $ of U){const Q={x:r.x-t.x,y:r.y-t.y},X={x:$.end.x-$.start.x,y:$.end.y-$.start.y},ue={x:t.x-$.start.x,y:t.y-$.start.y},pe=Q.x*Q.x+Q.y*Q.y,ce=Q.x*X.x+Q.y*X.y,Se=Q.x*ue.x+Q.y*ue.y,he=X.x*X.x+X.y*X.y,ge=X.x*ue.x+X.y*ue.y,Te=pe*he-ce*ce;if(Math.abs(Te)<1e-10)continue;let xe=(ce*ge-he*Se)/Te,Ae=(pe*ge-ce*Se)/Te;xe=W(xe,0,1),Ae=W(Ae,0,1);const Ne={x:t.x+xe*Q.x,y:t.y+xe*Q.y},ze={x:$.start.x+Ae*X.x,y:$.start.y+Ae*X.y},Re=Ne.x-ze.x,qe=Ne.y-ze.y,Ke=Re*Re+qe*qe;Ke<H&&(H=Ke,G={x:(Ne.x+ze.x)/2,y:(Ne.y+ze.y)/2})}return G};function hyt(n){return n.type==="pcb_trace_segment"?[n.layer]:n.type==="pcb_smtpad"?[n.layer]:n.type==="pcb_plated_hole"?Array.isArray(n.layers)?n.layers:[...vC]:n.type==="pcb_hole"?[...vC]:n.type==="pcb_via"?Array.isArray(n.layers)?n.layers:[...vC]:n.type==="pcb_keepout"?Array.isArray(n.layers)?n.layers:[]:[]}function myt(n,{connMap:e}={}){const t=[];e??(e=W8(n));const i=K2(n).pcb_trace.list().flatMap(y=>{const E=[];for(let w=0;w<y.route.length-1;w++){const S=y.route[w],T=y.route[w+1];S.route_type==="wire"&&T.route_type==="wire"&&S.layer===T.layer&&E.push({type:"pcb_trace_segment",pcb_trace_id:y.pcb_trace_id,_pcbTrace:y,thickness:"width"in S?S.width:"width"in T?T.width:cyt,layer:S.layer,x1:S.x,y1:S.y,x2:T.x,y2:T.y})}return E}),a=K2(n).pcb_smtpad.list(),o=K2(n).pcb_plated_hole.list(),s=K2(n).pcb_hole.list(),l=K2(n).pcb_via.list(),c=K2(n).pcb_keepout.list(),u=[...i,...a,...o,...s,...l,...c],d=new lyt({objects:u,getBounds:DC}),f=y=>qL(n,y),m=new Set;for(const y of i){const E=Pq,w=DC(y),S=d.getObjectsInBounds(w,E+y.thickness/2);if(!(y.x1===y.x2&&y.y1===y.y2))for(const T of S){if(!hyt(T).includes(y.layer))continue;if(T.type==="pcb_trace_segment"){const G=T;if(y.layer!==G.layer||e.areIdsConnected(y.pcb_trace_id,G.pcb_trace_id))continue;const W=q1t({x:y.x1,y:y.y1},{x:y.x2,y:y.y2},{x:G.x1,y:G.y1},{x:G.x2,y:G.y2})-y.thickness/2-G.thickness/2;if(W>Pq-Nq)continue;const $=`overlap_${y.pcb_trace_id}_${G.pcb_trace_id}`,Q=`overlap_${G.pcb_trace_id}_${y.pcb_trace_id}`;if(m.has($)||m.has(Q))continue;m.add($),t.push({type:"pcb_trace_error",error_type:"pcb_trace_error",message:`PCB trace ${f(y.pcb_trace_id)} overlaps with ${f(G.pcb_trace_id)} ${W<0?"(accidental contact)":`(gap: ${W.toFixed(3)}mm)`}`,pcb_trace_id:y.pcb_trace_id,source_trace_id:"",pcb_trace_error_id:$,pcb_component_ids:[],center:dyt(y,G),pcb_port_ids:Dq([y._pcbTrace,G._pcbTrace])});continue}const P=Q8(T);if(e.areIdsConnected(y.pcb_trace_id,"pcb_trace_id"in T?T.pcb_trace_id:P))continue;if(T.type==="pcb_via"||T.type==="pcb_plated_hole"&&T.shape==="circle"||T.type==="pcb_hole"||T.type==="pcb_smtpad"&&T.shape==="circle"){const G=pyt(T),$=X1t({x:y.x1,y:y.y1},{x:y.x2,y:y.y2},{x:T.x,y:T.y,radius:G})-y.thickness/2;if($>Pq-Nq)continue;const Q=`overlap_${y.pcb_trace_id}_${P}`;if(m.has(Q))continue;m.add(Q),t.push({type:"pcb_trace_error",error_type:"pcb_trace_error",message:`PCB trace ${f(y.pcb_trace_id)} overlaps with ${T.type} "${f(Q8(T))}" ${$<0?"(accidental contact)":`(gap: ${$.toFixed(3)}mm)`}`,pcb_trace_id:y.pcb_trace_id,center:P2e(y,DC(T)),source_trace_id:"",pcb_trace_error_id:Q,pcb_component_ids:["pcb_component_id"in T?T.pcb_component_id:void 0].filter(Boolean),pcb_port_ids:[...Dq([y._pcbTrace]),"pcb_port_id"in T?T.pcb_port_id:void 0].filter(Boolean)})}const H=Y1t({x:y.x1,y:y.y1},{x:y.x2,y:y.y2},DC(T))-y.thickness/2;if(H+Nq<E){const G=`overlap_${y.pcb_trace_id}_${P}`;if(m.has(G))continue;m.add(G),t.push({type:"pcb_trace_error",error_type:"pcb_trace_error",message:`PCB trace ${f(y.pcb_trace_id)} overlaps with ${T.type} "${f(Q8(T))}" ${H<0?"(accidental contact)":`(gap: ${H.toFixed(3)}mm)`}`,pcb_trace_id:y.pcb_trace_id,source_trace_id:"",pcb_trace_error_id:G,pcb_component_ids:["pcb_component_id"in T?T.pcb_component_id:void 0].filter(Boolean),center:P2e(y,DC(T)),pcb_port_ids:[...Dq([y._pcbTrace]),"pcb_port_id"in T?T.pcb_port_id:void 0].filter(Boolean)})}}}return t}var Lq=[{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 B3(n){if(n==null)return"";if(n===0)return"0";const e=Math.abs(n),t=Lq.find(a=>{const o=e/a.value;return o>=1&&o<1e3})||Lq[Lq.length-1];let i=(n/t.value).toPrecision(3);return i.includes(".")&&!/\.0+$/.test(i)&&(i=i.replace(/0+$/,"")),i=i.replace(/\.0+$/,""),`${i}${t.symbol}`}var vyt=Object.defineProperty,yyt=(n,e)=>{for(var t in e)vyt(n,t,{get:e[t],enumerable:!0})},N2e={};yyt(N2e,{Battery:()=>Pgt,Board:()=>fgt,Capacitor:()=>hgt,Chip:()=>J2e,Constraint:()=>bgt,Crystal:()=>Igt,Diode:()=>mgt,FabricationNotePath:()=>Sgt,FabricationNoteText:()=>wgt,Footprint:()=>Byt,Group:()=>Vq,Hole:()=>V2e,Inductor:()=>Ogt,Jumper:()=>vgt,Keepout:()=>Iq,Led:()=>ygt,Mosfet:()=>Bgt,Net:()=>I2e,NetAlias:()=>Tgt,NormalComponent:()=>a2,PcbTrace:()=>j2e,PinHeader:()=>Ngt,PlatedHole:()=>H2e,Port:()=>K8,Potentiometer:()=>Ugt,PowerSource:()=>ggt,PrimitiveComponent:()=>Ig,PushButton:()=>kgt,Renderable:()=>D2e,Resistor:()=>_gt,Resonator:()=>Lgt,SchematicText:()=>Hgt,SilkscreenCircle:()=>Mgt,SilkscreenLine:()=>Rgt,SilkscreenPath:()=>B2e,SilkscreenRect:()=>Cgt,SilkscreenText:()=>Fq,SmtPad:()=>kq,Subcircuit:()=>Egt,Switch:()=>jgt,Trace:()=>w7,TraceHint:()=>Z2e,Transistor:()=>Fgt,Via:()=>Agt});var gyt=r1("tscircuit:renderable"),qb=["ReactSubtreesRender","InitializePortsFromChildren","CreateNetsFromProps","CreateTracesFromProps","CreateTraceHintsFromProps","SourceRender","SourceParentAttachment","PortMatching","OptimizeSelectorCache","SourceTraceRender","SourceAddConnectivityMapKey","SchematicComponentRender","SchematicPrimitiveRender","SchematicPortRender","SchematicLayout","SchematicTraceRender","PcbComponentRender","PcbPrimitiveRender","PcbFootprintLayout","PcbPortRender","PcbPortAttachment","PcbLayout","PcbComponentSizeCalculation","PcbBoardAutoSize","PcbTraceHintRender","PcbTraceRender","PcbRouteNetIslands","PcbDesignRuleChecks","CadModelRender","PartsEngineRender"],_yt=0,D2e=class{constructor(e){Je(this,"renderPhaseStates");Je(this,"shouldBeRemoved",!1);Je(this,"children");Je(this,"isPcbPrimitive",!1);Je(this,"isSchematicPrimitive",!1);Je(this,"_renderId");Je(this,"_currentRenderPhase",null);Je(this,"_asyncEffects",[]);Je(this,"parent",null);this._renderId=`${_yt++}`,this.children=[],this.renderPhaseStates={};for(const t of qb)this.renderPhaseStates[t]={initialized:!1,dirty:!1}}_markDirty(e){var r;this.renderPhaseStates[e].dirty=!0;const t=qb.indexOf(e);for(let i=t+1;i<qb.length;i++)this.renderPhaseStates[qb[i]].dirty=!0;(r=this.parent)!=null&&r._markDirty&&this.parent._markDirty(e)}_queueAsyncEffect(e,t){const r={promise:t(),phase:this._currentRenderPhase,effectName:e,complete:!1};this._asyncEffects.push(r),"root"in this&&this.root&&this.root.emit("asyncEffect:start",{effectName:e,componentDisplayName:this.getString(),phase:r.phase}),r.promise.then(()=>{r.complete=!0,"root"in this&&this.root&&this.root.emit("asyncEffect:end",{effectName:e,componentDisplayName:this.getString(),phase:r.phase})}).catch(i=>{console.error(`Async effect error in ${r.phase} "${e}":
829
829
  ${i.stack}`),r.complete=!0,"root"in this&&this.root&&this.root.emit("asyncEffect:end",{effectName:e,componentDisplayName:this.getString(),phase:r.phase,error:i.toString()})})}_emitRenderLifecycleEvent(e,t){gyt(`${e}:${t} ${this.getString()}`);const r=`renderable:renderLifecycle:${e}:${t}`,i={renderId:this._renderId,componentDisplayName:this.getString(),type:r};"root"in this&&this.root&&(this.root.emit(r,i),this.root.emit("renderable:renderLifecycle:anyEvent",{...i,type:r}))}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 qb)this.runRenderPhaseForChildren(e),this.runRenderPhase(e)}runRenderPhase(e){var o,s,l;this._currentRenderPhase=e;const t=this.renderPhaseStates[e],r=t.initialized,i=t.dirty;if(!r&&this.shouldBeRemoved)return;if(this.shouldBeRemoved&&r){this._emitRenderLifecycleEvent(e,"start"),(o=this==null?void 0:this[`remove${e}`])==null||o.call(this),t.initialized=!1,t.dirty=!1,this._emitRenderLifecycleEvent(e,"end");return}const a=qb.indexOf(e)-1;if(a>=0){const c=qb[a];if(this._asyncEffects.filter(d=>d.phase===c).some(d=>!d.complete))return}if(this._emitRenderLifecycleEvent(e,"start"),r){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))}},YL={},L2e=n=>{const e=Object.fromEntries(Object.entries(n).map(([t,r])=>[t.toLowerCase(),r]));Object.assign(YL,n),Object.assign(YL,e)},xyt=class extends Error{constructor(e,t,r){let i;const o=Object.keys(r).filter(s=>s!=="_errors").map(s=>r[s]._errors[0]?`${s} (${r[s]._errors[0]})`:`${s} (${JSON.stringify(r[s])})`).join(", ");"name"in t?i=`Invalid props for ${e} "${t.name}": ${o}`:"footprint"in t&&typeof t.footprint=="string"?i=`Invalid props for ${e} (unnamed ${t.footprint} component): ${o}`:i=`Invalid props for ${e} (unnamed): ${o}`,super(i),this.componentName=e,this.originalProps=t,this.formattedError=r}};function Oq(n,e){const t=e.match(/^#(\w+)/);if(t)return n.props.id===t[1];const r=e.match(/^\.(\w+)/);if(r)return n.isMatchingNameOrAlias(r[1]);let[i,...a]=e.split(/(?=[#.[])/);return i==="pin"&&(i="port"),i&&i!=="*"&&n.lowercaseComponentName!==i.toLowerCase()?!1:a.every(o=>{if(o.startsWith("#"))return n.props.id===o.slice(1);if(o.startsWith("."))return n.isMatchingNameOrAlias(o.slice(1));const s=o.match(/\[(\w+)=['"]?(.+?)['"]?\]/);if(!s)return!0;const[,l,c]=s;return n.props[l].toString()===c})}var zq={isTag:n=>!0,getParent:n=>n.parent,getChildren:n=>n.children,getName:n=>n.lowercaseComponentName,getAttributeValue:(n,e)=>{var t;if(e==="class"&&"getNameAndAliases"in n)return n.getNameAndAliases().join(" ");if(e==="name"&&((t=n._parsedProps)!=null&&t.name))return n._parsedProps.name;if(n._parsedProps&&e in n._parsedProps){const r=n._parsedProps[e];return typeof r=="string"?r:r!=null?String(r):null}return null},hasAttrib:(n,e)=>{var t;return e==="class"?!!((t=n._parsedProps)!=null&&t.name):n._parsedProps&&e in n._parsedProps},getSiblings:n=>n.parent?n.parent.children:[],prevElementSibling:n=>{if(!n.parent)return null;const e=n.parent.children,t=e.indexOf(n);return t>0?e[t-1]:null},getText:()=>"",removeSubsets:n=>n.filter((e,t)=>!n.some((r,i)=>t!==i&&r!==e&&r.getDescendants().includes(e))),existsOne:(n,e)=>e.some(n),findAll:(n,e)=>{const t=[],r=i=>{n(i)&&t.push(i);for(const a of i.children)r(a)};for(const i of e)r(i);return t},findOne:(n,e)=>{for(const t of e){if(n(t))return t;const r=t.children;if(r.length>0){const i=zq.findOne(n,r);if(i)return i}}return null},equals:(n,e)=>n._renderId===e._renderId,isHovered:n=>!1,isVisited:n=>!1,isActive:n=>!1},byt={...zq,getChildren:n=>n.children.filter(e=>!e.isSubcircuit)},O2e={...zq,getChildren:n=>n.children.filter(e=>e.isSubcircuit)},z2e=n=>n.replace(/ pin/g," port").replace(/ subcircuit\./g," group[isSubcircuit=true]").replace(/([^ ])\>([^ ])/g,"$1 > $2").trim(),Uq={adapter:byt,cacheResults:!0},Ig=class extends D2e{constructor(t){super(t);Je(this,"parent",null);Je(this,"children");Je(this,"childrenPendingRemoval");Je(this,"props");Je(this,"_parsedProps");Je(this,"externallyAddedAliases");Je(this,"isPrimitiveContainer",!1);Je(this,"source_group_id",null);Je(this,"source_component_id",null);Je(this,"schematic_component_id",null);Je(this,"pcb_component_id",null);Je(this,"cad_component_id",null);Je(this,"_cachedSelectAllQueries",new Map);Je(this,"_cachedSelectOneQueries",new Map);this.children=[],this.childrenPendingRemoval=[],this.props=t??{},this.externallyAddedAliases=[];const r=this.config.zodProps.safeParse(t??{});if(r.success)this._parsedProps=r.data;else throw new xyt(this.lowercaseComponentName,this.props,r.error.format())}get config(){return{componentName:"",zodProps:b.object({}).passthrough()}}get componentName(){return this.config.componentName}getInheritedProperty(t){var i;let r=this;for(;r;){if(r._parsedProps&&t in r._parsedProps)return r._parsedProps[t];r=r.parent}if((i=this.root)!=null&&i.platform&&t in this.root.platform)return this.root.platform[t]}get lowercaseComponentName(){return this.componentName.toLowerCase()}get isSubcircuit(){var t;return!!this.props.subcircuit||this.lowercaseComponentName==="group"&&((t=this==null?void 0:this.parent)==null?void 0:t.isRoot)}get isGroup(){return this.lowercaseComponentName==="group"}setProps(t){var a,o;const r=this.config.zodProps.parse({...this.props,...t}),i=this.props;this.props=r,this._parsedProps=this.config.zodProps.parse(t),this.onPropsChange({oldProps:i,newProps:r,changedProps:Object.keys(t)}),(o=(a=this.parent)==null?void 0:a.onChildChanged)==null||o.call(a,this)}computePcbPropsTransform(){const{_parsedProps:t}=this;return Mc(k0(t.pcbX??0,t.pcbY??0),Z2((t.pcbRotation??0)*Math.PI/180))}_computePcbGlobalTransformBeforeLayout(){var i,a,o;const{_parsedProps:t}=this,r=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if(r&&this.props.pcbX===void 0&&this.props.pcbY===void 0)return Mc(((i=this.parent)==null?void 0:i._computePcbGlobalTransformBeforeLayout())??i1(),Mc(k0(r.x,r.y),Z2((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 Mc(k0(c.x,c.y),p7(),k0(-c.x,-c.y)),Mc(((a=this.parent)==null?void 0:a._computePcbGlobalTransformBeforeLayout())??i1(),p7(),this.computePcbPropsTransform())}}return Mc(((o=this.parent)==null?void 0:o._computePcbGlobalTransformBeforeLayout())??i1(),this.computePcbPropsTransform())}getPrimitiveContainer(){var t,r;return this.isPrimitiveContainer?this:((r=(t=this.parent)==null?void 0:t.getPrimitiveContainer)==null?void 0:r.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(),r=t?t._parsedProps.layer==="bottom":!1;return{isFlipped:r,maybeFlipLayer:a=>r?a==="top"?"bottom":"top":a}}_setPositionFromLayout(t){throw new Error(`_setPositionFromLayout not implemented for ${this.componentName}`)}computeSchematicPropsTransform(){const{_parsedProps:t}=this;return Mc(k0(t.schX??0,t.schY??0))}computeSchematicGlobalTransform(){var r,i;const t=this._getSchematicGlobalManualPlacementTransform(this);return t||Mc(((i=(r=this.parent)==null?void 0:r.computeSchematicGlobalTransform)==null?void 0:i.call(r))??i1(),this.computeSchematicPropsTransform())}_getSchematicSymbolName(){const{_parsedProps:t}=this,r=this.config.schematicSymbolName;let i=t.schRotation;if(i===void 0&&(i=0),i=i%360,i<0&&(i+=360),t.schRotation!==void 0&&i%90!==0)throw new Error(`Schematic rotation ${t.schRotation} is not supported for ${this.componentName}`);const a=`${r}_horz`,o=`${r}_vert`,s=`${r}_up`,l=`${r}_down`,c=`${r}_left`,u=`${r}_right`;if(u in Hb&&i===0)return u;if(s in Hb&&i===90)return s;if(c in Hb&&i===180)return c;if(l in Hb&&i===270)return l;if(a in Hb&&(i===0||i===180))return a;if(o in Hb&&(i===90||i===270))return o;if(r in Hb)return r}_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?Hb[t]??null:null}_getPcbManualPlacementForComponent(t){var o;if(!this.isSubcircuit)return null;const r=this.props.layout,i=this.props.manualEdits;if(!r&&!i)return null;const a=((o=r==null?void 0:r.manual_pcb_placement_config)==null?void 0:o.positions)||(i==null?void 0:i.pcb_placements);if(!a)return null;for(const s of a)if(r&&Oq(t,s.selector)||t.props.name===s.selector)return Cr(this._computePcbGlobalTransformBeforeLayout(),s.center);return null}_getSchematicManualPlacementForComponent(t){if(!this.isSubcircuit)return null;const r=this.props.manualEdits;if(!r)return null;const i=r.schematic_placements;if(!i)return null;for(const a of i)if(Oq(t,a.selector)||t.props.name===a.selector)return Cr(this.computeSchematicGlobalTransform(),a.center);return null}_getSchematicGlobalManualPlacementTransform(t){var i,a;const r=(i=this.getSubcircuit())==null?void 0:i._parsedProps.manualEdits;if(!r)return null;for(const o of r.schematic_placements??[])if((Oq(t,o.selector)||t.props.name===o.selector)&&o.relative_to==="group_center")return Mc(((a=this.parent)==null?void 0:a._computePcbGlobalTransformBeforeLayout())??i1(),k0(o.center.x,o.center.y));return null}_getGlobalPcbPositionBeforeLayout(){return Cr(this._computePcbGlobalTransformBeforeLayout(),{x:0,y:0})}_getGlobalSchematicPositionBeforeLayout(){return Cr(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 r,i;(i=(r=this.parent)==null?void 0:r.onChildChanged)==null||i.call(r,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 r of t)this.add(r)}remove(t){this.children=this.children.filter(r=>r!==t),this.childrenPendingRemoval.push(t),t.shouldBeRemoved=!0}getSubcircuitSelector(){const t=this._parsedProps.name,r=t?`${this.lowercaseComponentName}.${t}`:this.lowercaseComponentName;return!this.parent||this.parent.isSubcircuit?r:`${this.parent.getSubcircuitSelector()} > ${r}`}getFullPathSelector(){var a,o;const t=this._parsedProps.name,r=t?`${this.lowercaseComponentName}.${t}`:this.lowercaseComponentName,i=(o=(a=this.parent)==null?void 0:a.getFullPathSelector)==null?void 0:o.call(a);return i?`${i} > ${r}`:r}getNameAndAliases(){return[this._parsedProps.name,...this._parsedProps.portHints??[]].filter(Boolean)}isMatchingNameOrAlias(t){return this.getNameAndAliases().includes(t)}isMatchingAnyOf(t){return this.getNameAndAliases().some(r=>t.map(i=>i.toString()).includes(r))}getPcbSize(){throw new Error(`getPcbSize not implemented for ${this.componentName}`)}doesSelectorMatch(t){const r=[this.componentName,this.lowercaseComponentName],i=[this._parsedProps.name].filter(Boolean),a=t.trim().split(/\> /)[0],o=a[0];return a.length>1?!1:!!(t==="*"||t[0]==="#"&&t.slice(1)===this.props.id||t[0]==="."&&i.includes(t.slice(1))||/^[a-zA-Z0-9_]/.test(o)&&r.includes(o))}getSubcircuit(){var r,i;if(this.isSubcircuit)return this;const t=(i=(r=this.parent)==null?void 0:r.getSubcircuit)==null?void 0:i.call(r);if(!t)throw new Error("Component is not inside an opaque group (no board?)");return t}getGroup(){var t,r;return this.isGroup?this:((r=(t=this.parent)==null?void 0:t.getGroup)==null?void 0:r.call(t))??null}doInitialOptimizeSelectorCache(){var r;if(!this.isSubcircuit)return;const t=this.selectAll("port");for(const i of t){const a=(r=i.parent)==null?void 0:r.getNameAndAliases(),o=i.getNameAndAliases();if(a)for(const s of a)for(const l of o){const c=[`.${s} > .${l}`,`.${s} .${l}`];for(const u of c){const d=this._cachedSelectAllQueries.get(u);d?d.push(i):this._cachedSelectAllQueries.set(u,[i])}}}for(const[i,a]of this._cachedSelectAllQueries.entries())a.length===1&&this._cachedSelectOneQueries.set(i,a[0])}selectAll(t){if(this._cachedSelectAllQueries.has(t))return this._cachedSelectAllQueries.get(t);const r=z2e(t),i=CE(r,this,Uq);if(i.length>0)return this._cachedSelectAllQueries.set(t,i),i;const[a,...o]=r.split(" "),s=X8(a,this,{adapter:O2e});if(!s)return[];const l=s.selectAll(o.join(" "));return this._cachedSelectAllQueries.set(t,l),l}selectOne(t,r){if(this._cachedSelectOneQueries.has(t))return this._cachedSelectOneQueries.get(t);const i=z2e(t);r!=null&&r.port&&(r.type="port");let a=null;if(r!=null&&r.type&&(a=CE(i,this,Uq).find(u=>u.lowercaseComponentName===r.type)),a??(a=X8(i,this,Uq)),a)return this._cachedSelectOneQueries.set(t,a),a;const[o,...s]=i.split(" "),l=X8(o,this,{adapter:O2e});return l?(a=l.selectOne(s.join(" "),r),this._cachedSelectOneQueries.set(t,a),a):null}getAvailablePcbLayers(){var t,r;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"?((r=(t=this.root)==null?void 0:t._getBoard())==null?void 0:r.allLayers)??["top","bottom"]:[]}return[]}getDescendants(){const t=[];for(const r of this.children)t.push(r),t.push(...r.getDescendants());return t}getSelectableDescendants(){const t=[];for(const r of this.children)r.isSubcircuit?t.push(r):(t.push(r),t.push(...r.getSelectableDescendants()));return t}_getPinCount(){return 0}_getSchematicBoxDimensions(){return null}renderError(t){var r;if(typeof t=="string")return super.renderError(t);(r=this.root)==null||r.db.pcb_placement_error.insert(t)}getString(){var a,o;const{lowercaseComponentName:t,_parsedProps:r,parent:i}=this;return(r==null?void 0:r.pinNumber)!==void 0&&((a=i==null?void 0:i.props)!=null&&a.name)&&(r!=null&&r.name)?`<${t}#${this._renderId}(pin:${r.pinNumber} .${i==null?void 0:i.props.name}>.${r.name}) />`:(o=i==null?void 0:i.props)!=null&&o.name&&(r!=null&&r.name)?`<${t}#${this._renderId}(.${i==null?void 0:i.props.name}>.${r==null?void 0:r.name}) />`:r!=null&&r.from&&(r!=null&&r.to)?`<${t}#${this._renderId}(from:${r.from} to:${r==null?void 0:r.to}) />`:r!=null&&r.name?`<${t}#${this._renderId} name=".${r==null?void 0:r.name}" />`:r!=null&&r.portHints?`<${t}#${this._renderId}(${r.portHints.map(s=>`.${s}`).join(", ")}) />`:`<${t}#${this._renderId} />`}get[Symbol.toStringTag](){return this.getString()}[Symbol.for("nodejs.util.inspect.custom")](){return this.getString()}},Syt=class extends Ig{constructor(n,e){super(n),this._parsedProps={...n,error:e,type:n.type||"unknown",component_name:n.name,error_type:"source_failed_to_create_component_error",message:e instanceof Error?e.message:String(e),pcb_center:{x:n.pcbX||0,y:n.pcbY||0},schematic_center:{x:n.schX||0,y:n.schY||0}}}get config(){return{componentName:"ErrorPlaceholder",zodProps:b.object({}).passthrough()}}doInitialSourceRender(){var n;(n=this.root)!=null&&n.db&&this.root.db.source_failed_to_create_component_error.insert({component_name:this._parsedProps.component_name,message:this._parsedProps.message,pcb_center:this._parsedProps.pcb_center,schematic_center:this._parsedProps.schematic_center})}};function wyt(n,e){return new Syt(n,e)}function Eyt(n,e){const t=n;return t.__tsci={...e},n}var U2e={supportsMutation:!0,createInstance(n,e){const t=YL[n];if(!t)throw Object.keys(YL).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): "${n}" See CREATING_NEW_COMPONENTS.md`);try{return Eyt(new t(e),{})}catch(r){return wyt(e,r)}},createTextInstance(){return{}},appendInitialChild(n,e){n.add(e)},appendChild(n,e){n.add(e)},appendChildToContainer(n,e){n.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(n){return n},preparePortalMount(n){throw new Error("Function not implemented.")},scheduleTimeout(n,e){throw new Error("Function not implemented.")},cancelTimeout(n){throw new Error("Function not implemented.")},noTimeout:void 0,isPrimaryRenderer:!1,getInstanceFromNode(n){throw new Error("Function not implemented.")},beforeActiveInstanceBlur(){throw new Error("Function not implemented.")},afterActiveInstanceBlur(){throw new Error("Function not implemented.")},prepareScopeUpdate:(n,e)=>{throw new Error("Function not implemented.")},getInstanceFromScope:n=>{throw new Error("Function not implemented.")},detachDeletedInstance:n=>{throw new Error("Function not implemented.")},getCurrentEventPriority:()=>Y8.DefaultEventPriority,getCurrentUpdatePriority:()=>Y8.DefaultEventPriority,resolveUpdatePriority:()=>Y8.DefaultEventPriority,setCurrentUpdatePriority:()=>{},maySuspendCommit:()=>!1,supportsHydration:!1},S7;Jc.version.startsWith("19.")?S7=S$(U2e):S7=T$(U2e);var Tyt=n=>{const e={children:[],props:{name:"$root"},add(a){a.parent=this,this.children.push(a)},computePcbGlobalTransform(){return i1()}},t=[],r=S7.createContainer(e,0,null,!1,null,"tsci",a=>{console.log("Error in createContainer"),console.error(a),t.push(a)},null);if(Jc.version.startsWith("19.")?(S7.updateContainerSync(n,r,null,()=>{}),S7.flushSyncWork()):S7.updateContainer(n,r,null,()=>{}),t.length>0)throw t[0];const i=S7.getPublicRootInstance(r);return i||e.children[0]},LC=(n,e)=>{if(typeof n=="number")return n;if(n.startsWith("pin"))return Number(n.slice(3));if(!e)throw new Error(`No pin labels provided and pin number or label is not a number: "${n}"`);for(const t in e)if((Array.isArray(e[t])?e[t]:[e[t]]).includes(n))return Number(t.replace("pin",""));throw new Error(`No pin labels provided and pin number or label is not a number: "${n}"`)},Myt=(n,e)=>{if(!n)return;const t={},r={};for(const[i,a]of Object.entries(n)){const o=LC(i,e);r[o]={...r[o],...a}}for(const[i,a]of Object.entries(r)){const o=`pin${i}`;t[o]={bottom_margin:a.bottomMargin,left_margin:a.leftMargin,right_margin:a.rightMargin,top_margin:a.topMargin}}return t},Cyt=n=>{if(n){if("leftSide"in n||"rightSide"in n||"topSide"in n||"bottomSide"in n)return{left_side:n.leftSide,right_side:n.rightSide,top_side:n.topSide,bottom_side:n.bottomSide};if("leftPinCount"in n||"rightPinCount"in n||"topPinCount"in n||"bottomPinCount"in n)return{left_size:n.leftPinCount,right_size:n.rightPinCount,top_size:n.topPinCount,bottom_size:n.bottomPinCount};if("leftSize"in n||"rightSize"in n||"topSize"in n||"bottomSize"in n)return{left_size:n.leftSize,right_size:n.rightSize,top_size:n.topSize,bottom_size:n.bottomSize}}};function k2e(n){const e=[];for(let t=0;t<n.length-1;t++)e.push([n[t],n[t+1]]);return e}var Ryt=b.object({name:b.string()}),I2e=class extends Ig{constructor(){super(...arguments);Je(this,"source_net_id")}get config(){return{componentName:"Net",zodProps:Ryt}}getPortSelector(){return`net.${this.props.name}`}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:r}=this,i=t.source_net.insert({name:r.name,member_source_group_ids:[]});this.source_net_id=i.source_net_id}doInitialSourceParentAttachment(){const t=this.getSubcircuit();if(!t)return;const{db:r}=this.root;r.source_net.update(this.source_net_id,{subcircuit_id:t.subcircuit_id})}getAllConnectedPorts(){const t=this.getSubcircuit().selectAll("port"),r=[];for(const i of t){const a=i._getDirectlyConnectedTraces();for(const o of a)if(o._isExplicitlyConnectedToNet(this)){r.push(i);break}}return r}_getAllDirectlyConnectedTraces(){const t=this.getSubcircuit().selectAll("trace"),r=[];for(const i of t)i._isExplicitlyConnectedToNet(this)&&r.push(i);return r}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:r}=this,i=this._getAllDirectlyConnectedTraces().filter(l=>{var c;return(((c=l._portsRoutedOnPcb)==null?void 0:c.length)??0)>0}),a=[];for(const l of i){const c=l._portsRoutedOnPcb,u=a.find(d=>c.some(f=>d.ports.includes(f)));if(!u){a.push({ports:[...c],traces:[l]});continue}u.traces.push(l),u.ports.push(...c)}if(a.length===0)return;const o=k2e(a);for(const[l,c]of o){const u=l.ports.map(P=>P._getGlobalPcbPositionBeforeLayout()),d=c.ports.map(P=>P._getGlobalPcbPositionBeforeLayout());let f=1/0,m=[-1,-1];for(let P=0;P<u.length;P++){const U=u[P];for(let H=0;H<d.length;H++){const G=d[H],W=Math.sqrt((U.x-G.x)**2+(U.y-G.y)**2);W<f&&(f=W,m=[P,H])}}const y=l.ports[m[0]],E=c.ports[m[1]],w=t.toArray().filter(P=>P.type==="pcb_smtpad"||P.type==="pcb_trace"||P.type==="pcb_plated_hole"||P.type==="pcb_hole"||P.type==="source_port"||P.type==="pcb_port"),{solution:S}=aq(w.concat([{type:"source_trace",source_trace_id:"__net_trace_tmp",connected_source_port_ids:[y.source_port_id,E.source_port_id]}])),T=S[0];if(!T){this.renderError({pcb_trace_error_id:"",pcb_trace_id:"__net_trace_tmp",pcb_component_ids:[y.pcb_component_id,E.pcb_component_id].filter(Boolean),pcb_port_ids:[y.pcb_port_id,E.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(T)}}renderError(t){var r;if(typeof t=="string")return super.renderError(t);(r=this.root)==null||r.db.pcb_trace_error.insert(t)}},F2e=(n,e)=>{for(const t of e)if(typeof t=="string"&&t.startsWith("net.")){const r=n.getSubcircuit();if(!r.selectOne(t)){const i=new I2e({name:t.split("net.")[1]});r.add(i)}}},kq=class extends Ig{constructor(){super(...arguments);Je(this,"pcb_smtpad_id",null);Je(this,"matchedPort",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SmtPad",zodProps:r1t}}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 r;const t=(r=this.getPrimitiveContainer())==null?void 0:r.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 m,y,E,w,S,T,P,U,H,G;if((m=this.root)!=null&&m.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this;if(!r.portHints)return;const i=this.getPrimitiveContainer(),a=this.getSubcircuit(),o=this._getGlobalPcbPositionBeforeLayout();i==null||i._getGlobalPcbPositionBeforeLayout();const s=e6(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 d=null;const f=((y=this.parent)==null?void 0:y.pcb_component_id)??((E=this.getPrimitiveContainer())==null?void 0:E.pcb_component_id);r.shape==="circle"?(d=t.pcb_smtpad.insert({pcb_component_id:f,pcb_port_id:(w=this.matchedPort)==null?void 0:w.pcb_port_id,layer:c(r.layer??"top"),shape:"circle",radius:r.radius,port_hints:r.portHints.map(W=>W.toString()),x:o.x,y:o.y,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0}),t.pcb_solder_paste.insert({layer:d.layer,shape:"circle",radius:d.radius*.7,x:d.x,y:d.y,pcb_component_id:d.pcb_component_id,pcb_smtpad_id:d.pcb_smtpad_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((S=this.getGroup())==null?void 0:S.pcb_group_id)??void 0})):r.shape==="rect"&&(d=u===0||l?t.pcb_smtpad.insert({pcb_component_id:f,pcb_port_id:(T=this.matchedPort)==null?void 0:T.pcb_port_id,layer:c(r.layer??"top"),shape:"rect",width:l?r.height:r.width,height:l?r.width:r.height,port_hints:r.portHints.map(W=>W.toString()),x:o.x,y:o.y,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((P=this.getGroup())==null?void 0:P.pcb_group_id)??void 0}):t.pcb_smtpad.insert({pcb_component_id:f,layer:r.layer??"top",shape:"rotated_rect",width:r.width,height:r.height,x:o.x,y:o.y,ccw_rotation:u,port_hints:r.portHints.map(W=>W.toString()),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}),d.shape==="rect"&&t.pcb_solder_paste.insert({layer:d.layer,shape:"rect",width:d.width*.7,height:d.height*.7,x:d.x,y:d.y,pcb_component_id:d.pcb_component_id,pcb_smtpad_id:d.pcb_smtpad_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((H=this.getGroup())==null?void 0:H.pcb_group_id)??void 0}),d.shape==="rotated_rect"&&t.pcb_solder_paste.insert({layer:d.layer,shape:"rotated_rect",width:d.width*.7,height:d.height*.7,x:d.x,y:d.y,ccw_rotation:u,pcb_component_id:d.pcb_component_id,pcb_smtpad_id:d.pcb_smtpad_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((G=this.getGroup())==null?void 0:G.pcb_group_id)??void 0})),d&&(this.pcb_smtpad_id=d.pcb_smtpad_id)}doInitialPcbPortAttachment(){var r,i;if((r=this.root)!=null&&r.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,r=t.pcb_smtpad.get(this.pcb_smtpad_id);if(r.shape==="rect")return{center:{x:r.x,y:r.y},bounds:{left:r.x-r.width/2,top:r.y+r.height/2,right:r.x+r.width/2,bottom:r.y-r.height/2},width:r.width,height:r.height};if(r.shape==="rotated_rect"){const i=r.ccw_rotation*Math.PI/180,a=Math.cos(i),o=Math.sin(i),s=r.width/2,l=r.height/2,c=Math.abs(s*a)+Math.abs(l*o),u=Math.abs(s*o)+Math.abs(l*a);return{center:{x:r.x,y:r.y},bounds:{left:r.x-c,right:r.x+c,top:r.y-u,bottom:r.y+u},width:c*2,height:u*2}}if(r.shape==="circle")return{center:{x:r.x,y:r.y},bounds:{left:r.x-r.radius,top:r.y-r.radius,right:r.x+r.radius,bottom:r.y+r.radius},width:r.radius*2,height:r.radius*2};throw new Error(`circuitJson bounds calculation not implemented for shape "${r.shape}"`)}_setPositionFromLayout(t){var a;const{db:r}=this.root;r.pcb_smtpad.update(this.pcb_smtpad_id,{x:t.x,y:t.y});const i=r.pcb_solder_paste.list().find(o=>o.pcb_smtpad_id===this.pcb_smtpad_id);r.pcb_solder_paste.update(i==null?void 0:i.pcb_solder_paste_id,{x:t.x,y:t.y}),(a=this.matchedPort)==null||a._setPositionFromLayout(t)}},B2e=class extends Ig{constructor(){super(...arguments);Je(this,"pcb_silkscreen_path_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenPath",zodProps:L1t}}doInitialPcbPrimitiveRender(){var c,u,d;if((c=this.root)!=null&&c.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(r.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenPath. Must be "top" or "bottom".`);const o=this._computePcbGlobalTransformBeforeLayout(),s=this.getSubcircuit(),l=t.pcb_silkscreen_path.insert({pcb_component_id:(u=this.parent)==null?void 0:u.pcb_component_id,layer:a,route:r.route.map(f=>{const m=Cr(o,{x:f.x,y:f.y});return{...f,x:m.x,y:m.y}}),stroke_width:r.strokeWidth??.1,subcircuit_id:(s==null?void 0:s.subcircuit_id)??void 0,pcb_group_id:((d=this.getGroup())==null?void 0:d.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 r=1/0,i=-1/0,a=1/0,o=-1/0;for(const s of t.route)r=Math.min(r,s.x),i=Math.max(i,s.x),a=Math.min(a,s.y),o=Math.max(o,s.y);return{width:i-r,height:o-a}}},Ayt=b.object({route:b.array(p$),source_trace_id:b.string().optional()}),j2e=class extends Ig{constructor(){super(...arguments);Je(this,"pcb_trace_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbTrace",zodProps:Ayt}}doInitialPcbPrimitiveRender(){var u,d;if((u=this.root)!=null&&u.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,i=this.getPrimitiveContainer(),a=this.getSubcircuit(),{maybeFlipLayer:o}=this._getPcbPrimitiveFlippedHelpers(),s=this._computePcbGlobalTransformBeforeLayout(),l=r.route.map(f=>{const{x:m,y,...E}=f,w=Cr(s,{x:m,y});return f.route_type==="wire"&&f.layer?{...w,...E,layer:o(f.layer)}:{...w,...E}}),c=t.pcb_trace.insert({pcb_component_id:i.pcb_component_id,source_trace_id:r.source_trace_id,route:l,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});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 r=1/0,i=-1/0,a=1/0,o=-1/0;for(const s of t.route)r=Math.min(r,s.x),i=Math.max(i,s.x),a=Math.min(a,s.y),o=Math.max(o,s.y),s.route_type==="wire"&&(r=Math.min(r,s.x-s.width/2),i=Math.max(i,s.x+s.width/2),a=Math.min(a,s.y-s.width/2),o=Math.max(o,s.y+s.width/2));return r===1/0||i===-1/0||a===1/0||o===-1/0?{width:0,height:0}:{width:i-r,height:o-a}}},H2e=class extends Ig{constructor(){super(...arguments);Je(this,"pcb_plated_hole_id",null);Je(this,"matchedPort",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PlatedHole",zodProps:Fmt}}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};throw new Error(`getPcbSize for shape "${t.shape}" not implemented for ${this.componentName}`)}_getPcbCircuitJsonBounds(){const{db:t}=this.root,r=t.pcb_plated_hole.get(this.pcb_plated_hole_id),i=this.getPcbSize();return{center:{x:r.x,y:r.y},bounds:{left:r.x-i.width/2,top:r.y+i.height/2,right:r.x+i.width/2,bottom:r.y-i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(t){var i;const{db:r}=this.root;r.pcb_plated_hole.update(this.pcb_plated_hole_id,{x:t.x,y:t.y}),(i=this.matchedPort)==null||i._setPositionFromLayout(t)}doInitialPortMatching(){var r;const t=(r=this.getPrimitiveContainer())==null?void 0:r.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,d,f,m,y,E,w,S;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,i=this._getGlobalPcbPositionBeforeLayout(),a=((l=this.parent)==null?void 0:l.pcb_component_id)??((c=this.getPrimitiveContainer())==null?void 0:c.pcb_component_id),o=this.getSubcircuit();if(r.shape==="circle"){const T=t.pcb_plated_hole.insert({pcb_component_id:a,pcb_port_id:(u=this.matchedPort)==null?void 0:u.pcb_port_id,outer_diameter:r.outerDiameter,hole_diameter:r.holeDiameter,shape:"circle",port_hints:this.getNameAndAliases(),x:i.x,y:i.y,layers:["top","bottom"],subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((d=this.getGroup())==null?void 0:d.pcb_group_id)??void 0});this.pcb_plated_hole_id=T.pcb_plated_hole_id,t.pcb_solder_paste.insert({layer:"top",shape:"circle",radius:r.outerDiameter/2,x:i.x,y:i.y,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}),t.pcb_solder_paste.insert({layer:"bottom",shape:"circle",radius:r.outerDiameter/2,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((m=this.getGroup())==null?void 0:m.pcb_group_id)??void 0})}else if(r.shape==="pill"||r.shape==="oval"){const T=t.pcb_plated_hole.insert({pcb_component_id:a,pcb_port_id:(y=this.matchedPort)==null?void 0:y.pcb_port_id,outer_width:r.outerWidth,outer_height:r.outerHeight,hole_width:r.holeWidth,hole_height:r.holeHeight,shape:r.shape,port_hints:this.getNameAndAliases(),x:i.x,y:i.y,layers:["top","bottom"],subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((E=this.getGroup())==null?void 0:E.pcb_group_id)??void 0});this.pcb_plated_hole_id=T.pcb_plated_hole_id,t.pcb_solder_paste.insert({layer:"top",shape:r.shape,width:r.outerWidth,height:r.outerHeight,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((w=this.getGroup())==null?void 0:w.pcb_group_id)??void 0}),t.pcb_solder_paste.insert({layer:"bottom",shape:r.shape,width:r.outerWidth,height:r.outerHeight,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((S=this.getGroup())==null?void 0:S.pcb_group_id)??void 0})}}doInitialPcbPortAttachment(){var r,i;if((r=this.root)!=null&&r.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})}},Iq=class extends Ig{constructor(){super(...arguments);Je(this,"pcb_keepout_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Keepout",zodProps:C1t}}doInitialPcbPrimitiveRender(){var c,u,d;if((c=this.root)!=null&&c.pcbDisabled)return;const t=this.getSubcircuit(),{db:r}=this.root,{_parsedProps:i}=this,a=this._getGlobalPcbPositionBeforeLayout(),o=e6(this._computePcbGlobalTransformBeforeLayout()),s=Math.abs(o.rotation.angle*(180/Math.PI)-90)%180<.01;let l=null;i.shape==="circle"?l=r.pcb_keepout.insert({layers:["top"],shape:"circle",radius:i.radius,center:{x:a.x,y:a.y},subcircuit_id:(t==null?void 0:t.subcircuit_id)??void 0,pcb_group_id:((u=t==null?void 0:t.getGroup())==null?void 0:u.pcb_group_id)??void 0}):i.shape==="rect"&&(l=r.pcb_keepout.insert({layers:["top"],shape:"rect",...s?{width:i.height,height:i.width}:{width:i.width,height:i.height},center:{x:a.x,y:a.y},subcircuit_id:(t==null?void 0:t.subcircuit_id)??void 0,pcb_group_id:((d=t==null?void 0:t.getGroup())==null?void 0:d.pcb_group_id)??void 0})),l&&(this.pcb_keepout_id=l.pcb_keepout_id)}},V2e=class extends Ig{constructor(){super(...arguments);Je(this,"pcb_hole_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Hole",zodProps:o1t}}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:r}=this,i=this.getSubcircuit(),a=this._getGlobalPcbPositionBeforeLayout(),o=t.pcb_hole.insert({hole_shape:"circle",hole_diameter:r.diameter,x:a.x,y:a.y,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((l=i==null?void 0:i.getGroup())==null?void 0:l.pcb_group_id)??void 0});this.pcb_hole_id=o.pcb_hole_id}_getPcbCircuitJsonBounds(){const{db:t}=this.root,r=t.pcb_hole.get(this.pcb_hole_id),i=this.getPcbSize();return{center:{x:r.x,y:r.y},bounds:{left:r.x-i.width/2,top:r.y-i.height/2,right:r.x+i.width/2,bottom:r.y+i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(t){const{db:r}=this.root;r.pcb_hole.update(this.pcb_hole_id,{x:t.x,y:t.y})}},Fq=class extends Ig{constructor(){super(...arguments);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenText",zodProps:D1t}}doInitialPcbPrimitiveRender(){var l,c;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,i=this.getPrimitiveContainer(),a=this._getGlobalPcbPositionBeforeLayout(),{maybeFlipLayer:o}=this._getPcbPrimitiveFlippedHelpers(),s=this.getSubcircuit();t.pcb_silkscreen_text.insert({anchor_alignment:r.anchorAlignment,anchor_position:{x:a.x,y:a.y},font:r.font??"tscircuit2024",font_size:r.fontSize??1,layer:o(r.layer??"top"),text:r.text??"",ccw_rotation:r.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,r=t.fontSize??1,a=(t.text??"").length*r,o=r;return{width:a*r,height:o*r}}},Pyt=({elm:n,pinLabels:e,readableRotation:t})=>{var a;const r=n.text.replace(/[{}]/g,"").toLowerCase();let i=r;if(Array.isArray(e)){const o=parseInt(r.replace(/[^\d]/g,""),10)-1;i=e[o]??r}else typeof e=="object"&&(i=((a=e[r])==null?void 0:a[0])??r);return new Fq({anchorAlignment:"center",text:i??r,fontSize:n.font_size+.2,pcbX:isNaN(n.anchor_position.x)?0:n.anchor_position.x,pcbY:n.anchor_position.y,pcbRotation:t??0})},Nyt=({componentName:n,componentRotation:e,footprint:t,pinLabels:r},i)=>{const a=[];for(const o of i)if(o.type==="pcb_smtpad"&&o.shape==="rect")a.push(new kq({pcbX:o.x,pcbY:o.y,layer:o.layer,shape:"rect",height:o.height,width:o.width,portHints:o.port_hints}));else if(o.type==="pcb_smtpad"&&o.shape==="circle")a.push(new kq({pcbX:o.x,pcbY:o.y,layer:o.layer,shape:"circle",radius:o.radius,portHints:o.port_hints}));else if(o.type==="pcb_silkscreen_path")a.push(new B2e({layer:o.layer,route:o.route,strokeWidth:o.stroke_width}));else if(o.type==="pcb_plated_hole"&&o.shape==="circle")o.shape==="circle"&&a.push(new H2e({pcbX:o.x,pcbY:o.y,shape:"circle",holeDiameter:o.hole_diameter,outerDiameter:o.outer_diameter,portHints:o.port_hints}));else if(o.type==="pcb_keepout"&&o.shape==="circle")a.push(new Iq({pcbX:o.center.x,pcbY:o.center.y,shape:"circle",radius:o.radius}));else if(o.type==="pcb_keepout"&&o.shape==="rect")a.push(new Iq({pcbX:o.center.x,pcbY:o.center.y,shape:"rect",width:o.width,height:o.height}));else if(o.type==="pcb_hole"&&o.hole_shape==="circle")a.push(new V2e({pcbX:o.x,pcbY:o.y,diameter:o.hole_diameter}));else if(o.type==="pcb_silkscreen_text"){let s=e?parseInt(e):0;const l=(s%360+360)%360;s=l>90&&l<=270?(l+180)%360:l,t.includes("pinrow")&&o.text.includes("PIN")&&r?a.push(Pyt({elm:o,pinLabels:r,readableRotation:s})):o.text==="{REF}"&&a.push(new Fq({anchorAlignment:"center",text:n,fontSize:o.font_size+.2,pcbX:isNaN(o.anchor_position.x)?0:o.anchor_position.x,pcbY:o.anchor_position.y,pcbRotation:s??0}))}else o.type==="pcb_trace"&&a.push(new j2e({route:o.route}));return a};function $2e(n){let e=1/0,t=1/0,r=-1/0,i=-1/0;for(const s of n)if(s.isPcbPrimitive&&!s.componentName.startsWith("Silkscreen")){const{x:l,y:c}=s._getGlobalPcbPositionBeforeLayout(),{width:u,height:d}=s.getPcbSize();e=Math.min(e,l-u/2),t=Math.min(t,c-d/2),r=Math.max(r,l+u/2),i=Math.max(i,c+d/2)}else if(s.componentName==="Footprint"){const l=$2e(s.children);e=Math.min(e,l.minX),t=Math.min(t,l.minY),r=Math.max(r,l.maxX),i=Math.max(i,l.maxY)}let a=r-e,o=i-t;return a<0&&(a=0),o<0&&(o=0),{minX:e,minY:t,maxX:r,maxY:i,width:a,height:o}}function Dyt(n,e){const t=e.x-n.x,r=e.y-n.y;return Math.abs(t)>Math.abs(r)?t>=0?"right":"left":r>=0?"up":"down"}var Lyt=n=>{if(n.length<=1)return!0;const e=n.map(a=>{const o=a._getPcbCircuitJsonBounds();return{left:o.bounds.left,right:o.bounds.right,top:o.bounds.top,bottom:o.bounds.bottom}}),t=Array(e.length).fill(!1).map(()=>Array(e.length).fill(!1));for(let a=0;a<e.length;a++)for(let o=a+1;o<e.length;o++){const s=e[a],l=e[o];t[a][o]=t[o][a]=!(s.right<l.left||s.left>l.right||s.bottom>l.top||s.top<l.bottom)}const r=new Set,i=a=>{r.add(a);for(let o=0;o<e.length;o++)t[a][o]&&!r.has(o)&&i(o)};return i(0),r.size===e.length},Oyt=n=>{if(n.length===0)throw new Error("Cannot get center of empty PCB primitives array");const e=n.map(i=>i._getPcbCircuitJsonBounds().center).filter(Boolean),t=e.reduce((i,a)=>i+a.x,0),r=e.reduce((i,a)=>i+a.y,0);return{x:t/e.length,y:r/e.length}},zyt=b.object({name:b.string().optional(),pinNumber:b.number().optional(),aliases:b.array(b.string()).optional()}),K8=class extends Ig{constructor(t,r={}){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);Je(this,"source_port_id",null);Je(this,"pcb_port_id",null);Je(this,"schematic_port_id",null);Je(this,"schematicSymbolPortDef",null);Je(this,"matchedComponents");Je(this,"facingDirection",null);Je(this,"originDescription",null);r.originDescription&&(this.originDescription=r.originDescription),this.matchedComponents=[]}get config(){return{componentName:"Port",zodProps:zyt}}_getGlobalPcbPositionBeforeLayout(){const t=this.matchedComponents.find(i=>i.isPcbPrimitive),r=this.parent;if(r&&!r.props.footprint)throw new Error(`${r.componentName} "${r.props.name}" does not have a footprint. Add a footprint prop, e.g. <${r.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,r=t.pcb_port.get(this.pcb_port_id);return{center:{x:r.x,y:r.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 r=t._getInternallyConnectedPins();for(const i of r)if(i.some(a=>a===this))return i;return[]}_hasSchematicPort(){var i,a;if((i=this.parent)==null?void 0:i.getSchematicSymbol())return!!(this.schematicSymbolPortDef||this._getPortsInternallyConnectedToThisPort().some(s=>s.schematicSymbolPortDef));const r=(a=this==null?void 0:this.parent)==null?void 0:a._getSchematicBoxDimensions();return!!(r&&this.props.pinNumber!==void 0&&r.getPortPositionByPinNumber(this.props.pinNumber))}_getGlobalSchematicPositionBeforeLayout(){var i,a,o;const t=(i=this.parent)==null?void 0:i.getSchematicSymbol();if(t){let s=this.schematicSymbolPortDef;if(!s&&(s=((a=this._getPortsInternallyConnectedToThisPort().find(c=>c.schematicSymbolPortDef))==null?void 0:a.schematicSymbolPortDef)??null,!s))throw new Error(`Couldn't find schematicSymbolPortDef for port ${this.getString()}, searched internally connected ports and none had a schematicSymbolPortDef. Why are we trying to get the schematic position of this port?`);const l=Mc(this.parent.computeSchematicGlobalTransform(),k0(-t.center.x,-t.center.y));return Cr(l,s)}const r=(o=this==null?void 0:this.parent)==null?void 0:o._getSchematicBoxDimensions();if(r&&this.props.pinNumber!==void 0){const s=r.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 Cr(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 r=t.schematic_port.get(this.schematic_port_id);if(!r)throw new Error(`Schematic port not found when trying to get post-layout position: ${this.schematic_port_id}`);return r.center}registerMatch(t){this.matchedComponents.push(t)}getNameAndAliases(){const{_parsedProps:t}=this;return Array.from(new Set([...t.aliases??[],...t.name?[t.name]:[],...typeof t.pinNumber=="number"?[`pin${t.pinNumber}`,t.pinNumber.toString()]:[],...this.externallyAddedAliases??[]]))}isMatchingPort(t){return this.isMatchingAnyOf(t.getNameAndAliases())}getPortSelector(){var t;return`.${(t=this.parent)==null?void 0:t.props.name} > port.${this.props.name}`}getAvailablePcbLayers(){return Array.from(new Set(this.matchedComponents.flatMap(t=>t.getAvailablePcbLayers())))}_getDirectlyConnectedTraces(){return this.getSubcircuit().selectAll("trace").filter(i=>i._isExplicitlyConnectedToPort(this))}doInitialSourceRender(){var o,s;const{db:t}=this.root,{_parsedProps:r}=this,i=this.getNameAndAliases(),a=t.source_port.insert({name:r.name,pin_number:r.pinNumber,port_hints:i,source_component_id:(o=this.parent)==null?void 0:o.source_component_id,subcircuit_id:(s=this.getSubcircuit())==null?void 0:s.subcircuit_id});this.source_port_id=a.source_port_id}doInitialSourceParentAttachment(){var r,i,a,o,s;const{db:t}=this.root;if(!((r=this.parent)!=null&&r.source_component_id))throw new Error(`${this.getString()} has no parent source component (parent: ${(i=this.parent)==null?void 0:i.getString()})`);t.source_port.update(this.source_port_id,{source_component_id:(a=this.parent)==null?void 0:a.source_component_id,subcircuit_id:(o=this.getSubcircuit())==null?void 0:o.subcircuit_id}),this.source_component_id=(s=this.parent)==null?void 0:s.source_component_id}doInitialPcbPortRender(){var o,s,l,c,u;if((o=this.root)!=null&&o.pcbDisabled)return;const{db:t}=this.root,{matchedComponents:r}=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=r.filter(d=>d.isPcbPrimitive);if(i.length===0)return;let a=null;if(i.length===1&&(a=i[0]._getPcbCircuitJsonBounds().center),i.length>1){if(!Lyt(i))throw new Error(`${this.getString()} has multiple non-overlapping pcb matches, unclear how to place pcb_port: ${i.map(d=>d.getString()).join(", ")}. (Note: tscircuit core does not currently allow you to specify internally connected pcb primitives with the same port hints, try giving them different port hints and specifying they are connected externally- or file an issue)`);a=Oyt(i)}if(a){const d=this.getSubcircuit(),f=t.pcb_port.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layers:this.getAvailablePcbLayers(),subcircuit_id:(d==null?void 0:d.subcircuit_id)??void 0,pcb_group_id:((u=this.getGroup())==null?void 0:u.pcb_group_id)??void 0,...a,source_port_id:this.source_port_id});this.pcb_port_id=f.pcb_port_id}else{const d=i[0];throw new Error(`${d.getString()} does not have a center or _getGlobalPcbPositionBeforeLayout method (needed for pcb_port placement)`)}}doInitialSchematicPortRender(){var f;const{db:t}=this.root,{_parsedProps:r}=this,i=this.getPrimitiveContainer();if(!i||!this._hasSchematicPort())return;const a=i._getGlobalSchematicPositionBeforeLayout(),o=this._getGlobalSchematicPositionBeforeLayout();let s=null;const l=i._getSchematicBoxDimensions();l&&r.pinNumber!==void 0&&(s=l.getPortPositionByPinNumber(r.pinNumber)),this.getSubcircuit().props._schDebugObjectsEnabled&&t.schematic_debug_object.insert({shape:"rect",center:o,size:{width:.1,height:.1},label:"obstacle"}),s!=null&&s.side?this.facingDirection={left:"left",right:"right",top:"up",bottom:"down"}[s.side]:this.facingDirection=Dyt(a,o);const c=t.source_port.get(this.source_port_id);let u;for(const m of(c==null?void 0:c.port_hints)??[])m.match(/^(pin)?\d+$/)||m.match(/^(left|right)/)&&!(c!=null&&c.name.match(/^(left|right)/))||(u=m);const d=t.schematic_port.insert({schematic_component_id:(f=this.parent)==null?void 0:f.schematic_component_id,center:o,source_port_id:this.source_port_id,facing_direction:this.facingDirection,distance_from_component_edge:.4,side_of_component:s==null?void 0:s.side,pin_number:r.pinNumber,true_ccw_index:s==null?void 0:s.trueIndex,display_pin_label:u});this.schematic_port_id=d.schematic_port_id}_setPositionFromLayout(t){const{db:r}=this.root;this.pcb_port_id&&r.pcb_port.update(this.pcb_port_id,{x:t.x,y:t.y})}_hasMatchedPcbPrimitive(){return this.matchedComponents.some(t=>t.isPcbPrimitive)}},G2e=n=>{const e=n.find(t=>/^(pin)?\d+$/.test(t));return e?Number.parseInt(e.replace(/^pin/,"")):null};function OC(n,e){var a;const t=G2e(n);if(!t)return null;const i=[...n.filter(o=>o.toString()!==t.toString()&&o!==`pin${t}`),...((a=e==null?void 0:e.additionalAliases)==null?void 0:a[`pin${t}`])??[]];return new K8({pinNumber:t,aliases:i})}var Uyt=n=>{for(const e of["leftSide","rightSide","topSide","bottomSide"])if(e in n&&typeof n[e]=="number")throw new Error(`A number was specified for "${e}", you probably meant to use "size" not "side"`);return"leftSide"in n||"rightSide"in n||"topSide"in n||"bottomSide"in n},kyt=n=>{var a,o,s,l;if(Uyt(n))return{leftSize:((a=n.leftSide)==null?void 0:a.pins.length)??0,rightSize:((o=n.rightSide)==null?void 0:o.pins.length)??0,topSize:((s=n.topSide)==null?void 0:s.pins.length)??0,bottomSize:((l=n.bottomSide)==null?void 0:l.pins.length)??0};const{leftSize:e=0,rightSize:t=0,topSize:r=0,bottomSize:i=0}=n;return{leftSize:e,rightSize:t,topSize:r,bottomSize:i}};function q2e(n){return n.leftSide!==void 0}var Iyt=n=>{var w,S,T,P,U,H,G,W;const e=n.portDistanceFromEdge??.4;let t=n.schPortArrangement?kyt(n.schPortArrangement):null;const r={left:0,right:0,top:0,bottom:0};let i=n.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 $=Math.floor(i/2);t={leftSize:i-$,rightSize:$,topSize:0,bottomSize:0}}t||(t={leftSize:0,rightSize:0,topSize:0,bottomSize:0});const a=({side:$,sideIndex:Q,truePinIndex:X})=>{var he,ge,Te,xe;if(!n.schPortArrangement||!q2e(n.schPortArrangement))return X+1;const ue={left:"top-to-bottom",bottom:"left-to-right",right:"bottom-to-top",top:"right-to-left"}[$],pe=((ge=(he=n.schPortArrangement)==null?void 0:he[`${$}Side`])==null?void 0:ge.direction)??ue,ce=(xe=(Te=n.schPortArrangement)==null?void 0:Te[`${$}Side`])==null?void 0:xe.pins;let Se=Q;return pe!==ue&&(Se=ce.length-Q-1),LC(ce[Se],n.pinLabels)},o=[];let s=0,l=0;for(let $=0;$<t.leftSize;$++){const Q=a({side:"left",sideIndex:$,truePinIndex:l}),X=((w=n.numericSchPinStyle)==null?void 0:w[`pin${Q}`])??((S=n.numericSchPinStyle)==null?void 0:S[Q]);X!=null&&X.topMargin&&(s+=X.topMargin),o.push({trueIndex:l,pinNumber:Q,side:"left",distanceFromOrthogonalEdge:s}),X!=null&&X.bottomMargin&&(s+=X.bottomMargin),$===t.leftSize-1?r.left=s:s+=n.schPinSpacing,l++}s=0;for(let $=0;$<t.bottomSize;$++){const Q=a({side:"bottom",sideIndex:$,truePinIndex:l}),X=((T=n.numericSchPinStyle)==null?void 0:T[`pin${Q}`])??((P=n.numericSchPinStyle)==null?void 0:P[Q]);X!=null&&X.leftMargin&&(s+=X.leftMargin),o.push({trueIndex:l,pinNumber:Q,side:"bottom",distanceFromOrthogonalEdge:s}),X!=null&&X.rightMargin&&(s+=X.rightMargin),$===t.bottomSize-1?r.bottom=s:s+=n.schPinSpacing,l++}s=0;for(let $=0;$<t.rightSize;$++){const Q=a({side:"right",sideIndex:$,truePinIndex:l}),X=((U=n.numericSchPinStyle)==null?void 0:U[`pin${Q}`])??((H=n.numericSchPinStyle)==null?void 0:H[Q]);X!=null&&X.bottomMargin&&(s+=X.bottomMargin),o.push({trueIndex:l,pinNumber:Q,side:"right",distanceFromOrthogonalEdge:s}),X!=null&&X.topMargin&&(s+=X.topMargin),$===t.rightSize-1?r.right=s:s+=n.schPinSpacing,l++}s=0;for(let $=0;$<t.topSize;$++){const Q=a({side:"top",sideIndex:$,truePinIndex:l}),X=((G=n.numericSchPinStyle)==null?void 0:G[`pin${Q}`])??((W=n.numericSchPinStyle)==null?void 0:W[Q]);X!=null&&X.rightMargin&&(s+=X.rightMargin),o.push({trueIndex:l,pinNumber:Q,side:"top",distanceFromOrthogonalEdge:s}),X!=null&&X.leftMargin&&(s+=X.leftMargin),$===t.topSize-1?r.top=s:s+=n.schPinSpacing,l++}let c=n.schWidth;c||(c=Math.max(r.top+n.schPinSpacing*2,r.bottom+n.schPinSpacing*2));const u=n.pinLabels?Math.max(...Object.values(n.pinLabels).map($=>$.length*.1)):0,d=u>0?1.1:0;c=Math.max(c,u+d);let f=n.schHeight;f||(f=Math.max(r.left+n.schPinSpacing*2,r.right+n.schPinSpacing*2));const m={left:{x:-c/2-e,y:r.left/2},bottom:{x:-r.bottom/2,y:-f/2-e},right:{x:c/2+e,y:-r.right/2},top:{x:r.top/2,y:f/2+e}},y={left:{x:0,y:-1},right:{x:0,y:1},top:{x:-1,y:0},bottom:{x:1,y:0}},E=o.map($=>{const{distanceFromOrthogonalEdge:Q,side:X}=$,ue=m[X],pe=y[X];return{x:ue.x+Q*pe.x,y:ue.y+Q*pe.y,...$}});return{getPortPositionByPinNumber($){const Q=E.find(X=>X.pinNumber.toString()===$.toString());return Q||null},getSize(){return{width:c,height:f}},getSizeIncludingPins(){return{width:c+(t.leftSize||t.rightSize?.4:0),height:f+(t.topSize||t.bottomSize?.4:0)}},pinCount:i}},Fyt=r1("tscircuit:core:footprint"),Byt=class extends Ig{get config(){return{componentName:"Footprint",zodProps:l1t}}doInitialPcbFootprintLayout(){var f,m,y,E,w;if((f=this.root)!=null&&f.pcbDisabled)return;const e=this.children.filter(S=>S.componentName==="Constraint");if(e.length===0)return;const{isFlipped:t}=this._getPcbPrimitiveFlippedHelpers(),r=S=>t&&"left"in S&&"right"in S?{...S,left:S.right,right:S.left}:S,i=e.flatMap(S=>S._getAllReferencedComponents().componentsWithSelectors).map(({component:S,selector:T,componentSelector:P,edge:U})=>({component:S,selector:T,componentSelector:P,edge:U,bounds:S._getPcbCircuitJsonBounds()}));if(i.some(S=>S.edge))throw new Error("edge constraints not implemented yet for footprint layout, contributions welcome!");function a(S){return i.find(({selector:T})=>T===S)}const o=new fq,s={};function l(S){return S in s||(s[S]=new MC(S),o.addEditVariable(s[S],uv.weak)),s[S]}for(const{selector:S,bounds:T}of i){const P=l(`${S}_x`),U=l(`${S}_y`);o.suggestValue(P,T.center.x),o.suggestValue(U,T.center.y)}for(const S of e){const T=S._parsedProps;if("xDist"in T){const{xDist:P,left:U,right:H,edgeToEdge:G,centerToCenter:W}=r(T),$=l(`${U}_x`),Q=l(`${H}_x`),X=(m=a(U))==null?void 0:m.bounds,ue=(y=a(H))==null?void 0:y.bounds;if(W){const pe=new z9(Q,[-1,$]);o.addConstraint(new Dx(pe,xg.Eq,T.xDist,uv.required))}else if(G){const pe=new z9(Q,-ue.width/2,[-1,$],-X.width/2);o.addConstraint(new Dx(pe,xg.Eq,T.xDist,uv.required))}}else if("yDist"in T){const{yDist:P,top:U,bottom:H,edgeToEdge:G,centerToCenter:W}=T,$=l(`${U}_y`),Q=l(`${H}_y`),X=(E=a(U))==null?void 0:E.bounds,ue=(w=a(H))==null?void 0:w.bounds;if(W){const pe=new z9($,[-1,Q]);o.addConstraint(new Dx(pe,xg.Eq,T.yDist,uv.required))}else if(G){const pe=new z9($,X.height/2,[-1,Q],-ue.height/2);o.addConstraint(new Dx(pe,xg.Eq,T.yDist,uv.required))}}else if("sameY"in T){const{for:P}=T;if(P.length<2)continue;const U=P.map(G=>l(`${G}_y`)),H=new z9(...U.slice(1));o.addConstraint(new Dx(H,xg.Eq,U[0],uv.required))}else if("sameX"in T){const{for:P}=T;if(P.length<2)continue;const U=P.map(G=>l(`${G}_x`)),H=new z9(...U.slice(1));o.addConstraint(new Dx(H,xg.Eq,U[0],uv.required))}}o.updateVariables(),Fyt.enabled&&(console.log("Solution to layout constraints:"),console.table(Object.entries(s).map(([S,T])=>({var:S,val:T.value()}))));const c={left:1/0,right:-1/0,top:-1/0,bottom:1/0};for(const{selector:S,bounds:{width:T,height:P}}of i){const U=l(`${S}_x`),H=l(`${S}_y`),G=U.value()-T/2,W=U.value()+T/2,$=H.value()+P/2,Q=H.value()-P/2;c.left=Math.min(c.left,G),c.right=Math.max(c.right,W),c.top=Math.max(c.top,$),c.bottom=Math.min(c.bottom,Q)}const u={x:-(c.right+c.left)/2,y:-(c.top+c.bottom)/2},d=this.getPrimitiveContainer()._getGlobalPcbPositionBeforeLayout();u.x+=d.x,u.y+=d.y;for(const{component:S,selector:T}of i){const P=l(`${T}_x`),U=l(`${T}_y`);S._setPositionFromLayout({x:P.value()+u.x,y:U.value()+u.y})}}},jyt=(n,e)=>{if(!n)return;const t={};for(const[r,i]of Object.entries(n)){const a=LC(r,e),o={leftMargin:i.marginLeft??i.leftMargin,rightMargin:i.marginRight??i.rightMargin,topMargin:i.marginTop??i.topMargin,bottomMargin:i.marginBottom??i.bottomMargin};t[`pin${a}`]={...t[`pin${a}`],...o}}return t},Y2e=class{constructor({input:e}){Je(this,"input");this.input=e}solveAndMapToTraces(){const e=[];for(const t of this.input.connections){if(t.pointsToConnect.length!==2)continue;const[r,i]=t.pointsToConnect,a={type:"pcb_trace",pcb_trace_id:"",connection_name:t.name,route:[{route_type:"wire",x:r.x,y:r.y,layer:"top",width:.1},{route_type:"wire",x:i.x,y:i.y,layer:"top",width:.1}]};e.push(a)}return e}},Hyt=n=>{const e=Math.min(...n.map(a=>a.center.x)),t=Math.max(...n.map(a=>a.center.x)),r=Math.min(...n.map(a=>a.center.y)),i=Math.max(...n.map(a=>a.center.y));return{minX:e,maxX:t,minY:r,maxY:i}},X2e=["top","bottom","inner1","inner2"],XL=(n,e=[])=>{var s;const t=[];if(e.length===0){const l=n[0].layers;for(const c of l)t.push(...XL(n.slice(1),[c]));return t}if(n.length===0)return[];const r=n[0],i=r.via||r.optional_via,a=e[e.length-1];if(n.length===1){const l=r;return l.layers&&i?l.layers.map(c=>({layer_path:[...e,c]})):(s=l.layers)!=null&&s.includes(a)?[{layer_path:[...e,a]}]:[]}if(!i)return r.layers&&!r.layers.includes(a)?[]:XL(n.slice(1),e.concat([a]));const o=(r.optional_via?X2e:X2e.filter(l=>l!==a)).filter(l=>{var c;return!r.layers||((c=r.layers)==null?void 0:c.includes(l))});for(const l of o)t.push(...XL(n.slice(1),e.concat(l)));return t};function W2e(n){const e={x:n.to.x-n.from.x,y:n.to.y-n.from.y},t=Math.abs(e.x),r=Math.abs(e.y);return t>r?e.x>0?"right":"left":e.y>0?"down":"up"}function zE(n,e){return Math.hypot(n.x-e.x,n.y-e.y)}var Vyt=n=>{if(n.length===1)return n[0];if(n.some(l=>l.length===0))throw new Error("Cannot merge routes with zero length");const e=[],t=n[0][0],r=n[0][n[0].length-1],i=n[1][0],a=n[1][n[1].length-1],o=Math.min(zE(t,i),zE(t,a)),s=Math.min(zE(r,i),zE(r,a));o<s?e.push(...n[0].reverse()):e.push(...n[0]);for(let l=1;l<n.length;l++){const c=e[e.length-1],u=n[l],d=u[0],f=u[u.length-1],m=zE(c,d),y=zE(c,f);m<y?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},$yt=(n,e)=>{const t="_getGlobalPcbPositionBeforeLayout"in n?n._getGlobalPcbPositionBeforeLayout():n,r="_getGlobalPcbPositionBeforeLayout"in e?e._getGlobalPcbPositionBeforeLayout():e;return Math.sqrt((t.x-r.x)**2+(t.y-r.y)**2)};function Gyt(n,e){if(e.length===0)throw new Error("No candidates given to getClosest method");let t=e[0],r=1/0;for(const i of e){const a=$yt(n,i);a<r&&(t=i,r=a)}return t}var qyt=(n,e)=>{let t=0;t+=n.length??0,t+=e.filter(r=>r.is_crossing).length;for(let r=1;r<e.length;r++){const i=e[r-1],a=e[r],o=Math.abs(i.from.x-i.to.x)<.01,s=Math.abs(a.from.x-a.to.x)<.01;o!==s&&t++}return t},Bq=n=>({up:"bottom",down:"top",left:"right",right:"left"})[n]??null,jq=({firstEdge:n,firstEdgePort:e,firstDominantDirection:t,lastEdge:r,lastEdgePort:i,lastDominantDirection:a})=>{if(n&&e)return jq({lastEdge:{from:n.to,to:n.from},lastEdgePort:e,lastDominantDirection:t}).reverse().map(s=>({from:s.to,to:s.from}));let o=[];if(r&&i){const s={x:r.to.x,y:r.to.y};a==="left"||a==="right"?(s.x=i.position.x,o.push({from:r.to,to:{...s}}),o.push({from:s,to:{...i.position}})):(s.y=i.position.y,o.push({from:r.to,to:{...s}}),o.push({from:s,to:{...i.position}}))}return o=o.filter(s=>Z8(s.from,s.to)>.01),o};function Yyt(n){try{return[n(),null]}catch(e){return[null,e]}}function Xyt(n){let e=0;for(let t=0;t<n.length;t++){const r=n[t];if(r.route_type==="wire"){const i=n[t+1];if(i){const a=i.x-r.x,o=i.y-r.y;e+=Math.sqrt(a*a+o*o)}}else r.route_type==="via"&&(e+=1.6)}return e}var Wyt=n=>{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}}[n.facingDirection],t=(s=n.parent)!=null&&s.config.shouldRenderAsSchematicBox?3:1,r=(l=n.parent)!=null&&l.config.shouldRenderAsSchematicBox&&(n.facingDirection==="left"||n.facingDirection==="right")?3:1,i=e.x,a=e.y,o=n.facingDirection==="up"?.5:0;return{schBoxVertOffset:t,schBoxHorzOffset:r,horzPortDirection:i,vertPortDirectionOffset:a,handleUp:o}},WL=({port:n,anchorPos:e,schDisplayLabel:t,source_trace_id:r},{db:i})=>{const a=Wyt(n);i.schematic_net_label.insert({anchor_side:"top",center:{x:e.x+a.horzPortDirection*a.schBoxHorzOffset,y:e.y+a.vertPortDirectionOffset*a.schBoxVertOffset},source_net_id:n.source_port_id,text:t,anchor_position:{x:e.x+a.horzPortDirection*a.schBoxHorzOffset,y:e.y+a.vertPortDirectionOffset*a.schBoxVertOffset},symbol_name:"ground_horz"}),i.schematic_trace.insert({edges:[{from:{x:e.x,y:e.y},to:{x:e.x,y:e.y+a.handleUp*a.schBoxVertOffset}},{from:{x:e.x,y:e.y},to:{x:e.x+a.horzPortDirection*a.schBoxHorzOffset,y:e.y+a.vertPortDirectionOffset*a.schBoxVertOffset}}],junctions:[{x:e.x+a.horzPortDirection*a.schBoxHorzOffset,y:e.y+a.vertPortDirectionOffset*a.schBoxVertOffset}],source_trace_id:r})},Hq=({db:n,source_trace_id:e,sameNetOnly:t,differentNetOnly:r})=>{!t&&!r&&(r=!0);const i=n.source_trace.get(e),a=[];for(const o of n.schematic_trace.list()){if(o.source_trace_id===e)continue;const s=n.source_trace.get(o.source_trace_id),l=(s==null?void 0:s.subcircuit_connectivity_map_key)===i.subcircuit_connectivity_map_key;r&&l||t&&!l||a.push(o)}return a},Zyt=({edges:n,otherEdges:e})=>{const t=[...n];for(let r=0;r<t.length;r++){if(r>2e3)throw new Error("Over 2000 iterations spent inside createSchematicTraceCrossingSegments, you have triggered an infinite loop, please report this!");const i=t[r],a=Math.abs(i.from.x-i.to.x)<.01?"vertical":i.from.y===i.to.y?"horizontal":"not-orthogonal";if(a==="not-orthogonal")continue;const o=[];for(const E of e){const w=E.from.x===E.to.x?"vertical":E.from.y===E.to.y?"horizontal":"not-orthogonal";if(w==="not-orthogonal"||a===w)continue;if(Zxe([i.from,i.to],[E.from,E.to],{lineThickness:.01})){const T=a==="vertical"?i.from.x:E.from.x,P=a==="vertical"?E.from.y:i.from.y,U={x:T,y:P};o.push({otherEdge:E,crossingPoint:U,distanceFromEdgeFrom:Z8(i.from,U)})}}if(o.length===0)continue;let s=o[0];for(const E of o)E.distanceFromEdgeFrom<s.distanceFromEdgeFrom&&(s=E);const l=s.crossingPoint,c=.075;if(l.x===i.from.x&&l.y===i.from.y)continue;const u=W1t(i.from,l),d={x:l.x-u.x*c/2,y:l.y-u.y*c/2},f={x:l.x+u.x*c/2,y:l.y+u.y*c/2},m=Z8(f,i.to)<c,y=[{from:i.from,to:d},{from:d,to:f,is_crossing:!0},{from:f,to:i.to}];t.splice(r,1,...y),r+=y.length-2,m&&r++}return t},Qyt=(n,e)=>{if(n.from.x===n.to.x&&e.from.x===e.to.x)return null;if(n.from.x===n.to.x){const u=n.from.x,d=(e.to.y-e.from.y)/(e.to.x-e.from.x),f=e.from.y-d*e.from.x,m=d*u+f;return u>=Math.min(e.from.x,e.to.x)&&u<=Math.max(e.from.x,e.to.x)&&m>=Math.min(e.from.y,e.to.y)&&m<=Math.max(e.from.y,e.to.y)?{x:u,y:m}:null}if(e.from.x===e.to.x){const u=e.from.x,d=(n.to.y-n.from.y)/(n.to.x-n.from.x),f=n.from.y-d*n.from.x,m=d*u+f;return u>=Math.min(n.from.x,n.to.x)&&u<=Math.max(n.from.x,n.to.x)&&m>=Math.min(n.from.y,n.to.y)&&m<=Math.max(n.from.y,n.to.y)?{x:u,y:m}:null}const t=(n.to.y-n.from.y)/(n.to.x-n.from.x),r=n.from.y-t*n.from.x,i=(e.to.y-e.from.y)/(e.to.x-e.from.x),a=e.from.y-i*e.from.x;if(t===i)return null;const o=(a-r)/(t-i),s=t*o+r,l=o>=Math.min(n.from.x,n.to.x)&&o<=Math.max(n.from.x,n.to.x)&&s>=Math.min(n.from.y,n.to.y)&&s<=Math.max(n.from.y,n.to.y),c=o>=Math.min(e.from.x,e.to.x)&&o<=Math.max(e.from.x,e.to.x)&&s>=Math.min(e.from.y,e.to.y)&&s<=Math.max(e.from.y,e.to.y);return l&&c?{x:o,y:s}:null},Kyt=({edges:n,db:e,source_trace_id:t})=>{const r=Hq({db:e,source_trace_id:t,sameNetOnly:!0}).flatMap(i=>i.edges);for(const i of n)for(const a of r){const o=Qyt(i,a);if(o)return`${o.x}${o.y}`,[{x:o.x,y:o.y}]}return[]},Jyt=(n,{db:e})=>{const t=n.map(r=>{const i=e.source_port.get(r.source_port_id);if(!(i!=null&&i.source_component_id))return null;const a=e.source_component.get(i.source_component_id);return(a==null?void 0:a.ftype)==="simple_capacitor"?a.max_decoupling_trace_length:null}).filter(r=>r!==null);if(t.length!==0)return Math.min(...t)};function egt(n){var a,o,s,l,c,u,d,f,m;let e=1/0,t=1/0,r=-1/0,i=-1/0;for(const y of n){let E,w,S,T;y.type==="schematic_component"?(E=(a=y.center)==null?void 0:a.x,w=(o=y.center)==null?void 0:o.y,S=(s=y.size)==null?void 0:s.width,T=(l=y.size)==null?void 0:l.height):y.type==="schematic_box"?(E=y.x,w=y.y,S=y.width,T=y.height):y.type==="schematic_port"?(E=(c=y.center)==null?void 0:c.x,w=(u=y.center)==null?void 0:u.y,S=.2,T=.2):y.type==="schematic_text"&&(E=(d=y.position)==null?void 0:d.x,w=(f=y.position)==null?void 0:f.y,S=(((m=y.text)==null?void 0:m.length)??0)*.1,T=.2),typeof E=="number"&&typeof w=="number"&&typeof S=="number"&&typeof T=="number"&&(e=Math.min(e,E-S/2),r=Math.max(r,E+S/2),t=Math.min(t,w-T/2),i=Math.max(i,w+T/2))}return{minX:e,maxX:r,minY:t,maxY:i}}function tgt(n,e={}){const{minX:t,maxX:r,minY:i,maxY:a}=n,o=e.padding??1;if(!isFinite(t)||!isFinite(r)||!isFinite(i)||!isFinite(a))return[];const s=t-o,l=r+o,c=a+o,u=i-o,d=.01;return[{type:"rect",layers:["top"],center:{x:(s+l)/2,y:c},width:l-s,height:d,connectedTo:[]},{type:"rect",layers:["top"],center:{x:(s+l)/2,y:u},width:l-s,height:d,connectedTo:[]},{type:"rect",layers:["top"],center:{x:s,y:(c+u)/2},width:d,height:c-u,connectedTo:[]},{type:"rect",layers:["top"],center:{x:l,y:(c+u)/2},width:d,height:c-u,connectedTo:[]}]}var ngt=n=>{var o;const e=n.root.db,t=n._findConnectedPorts().ports??[],r=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(r.has(s.schematic_port_id))continue;const l=s.facing_direction?Z1t(s.facing_direction):{x:0,y:0};i.push({type:"rect",layers:["top"],center:{x:s.center.x-l.x*.1,y:s.center.y-l.y*.1},width:.1+Math.abs(l.x)*.3,height:.1+Math.abs(l.y)*.3,connectedTo:[]})}s.type==="schematic_text"&&i.push({type:"rect",layers:["top"],center:s.position,width:(((o=s.text)==null?void 0:o.length)??0)*.1,height:.2,connectedTo:[]}),s.type==="schematic_box"&&i.push({type:"rect",layers:["top"],center:{x:s.x,y:s.y},width:s.width,height:s.height,connectedTo:[]})}const a=egt(e.toArray());return i.push(...tgt(a,{padding:1})),i};function rgt({ports:n,nets:e}){var t,r,i;if(n.length>=2)return`${(t=n[0])==null?void 0:t.selector} to ${(r=n[1])==null?void 0:r.selector}`;if(n.length===1&&e.length===1)return`${(i=n[0])==null?void 0:i.selector} to net.${e[0]._parsedProps.name}`}var igt=({edges:n,db:e,source_trace_id:t})=>{e.source_trace.get(t);const r=Hq({db:e,source_trace_id:t,differentNetOnly:!0}).flatMap(a=>a.edges),i=a=>{const{from:o,to:s}=a;return o.x===s.x?"vertical":"horizontal"};for(const a of n){const o=i(a),s=()=>r.find(c=>i(c)===o&&Zxe([a.from,a.to],[c.from,c.to],{lineThickness:.05}));let l=s();for(;l;)o==="horizontal"?(a.from.y+=.1,a.to.y+=.1):(a.from.x+=.1,a.to.x+=.1),l=s()}},agt=(n,{db:e})=>{const t=e.pcb_board.list()[0];if(t.outline){const l=t.outline,c=(u,d)=>{let f=!1;for(let m=0,y=d.length-1;m<d.length;y=m++){const E=d[m].x,w=d[m].y,S=d[y].x,T=d[y].y;w>u.y!=T>u.y&&u.x<(S-E)*(u.y-w)/(T-w)+E&&(f=!f)}return f};return n.some(u=>!c(u,l))}const r=t.width,i=t.height,a=t.center.x,o=t.center.y;return n.some(l=>l.x<a-r/2||l.y<o-i/2||l.x>a+r/2||l.y>o+i/2)},ZL=n=>({...n._getGlobalPcbPositionAfterLayout(),layers:n.getAvailablePcbLayers()}),w7=class extends Ig{constructor(t){super(t);Je(this,"source_trace_id",null);Je(this,"pcb_trace_id",null);Je(this,"schematic_trace_id",null);Je(this,"_portsRoutedOnPcb");Je(this,"subcircuit_connectivity_map_key",null);Je(this,"_traceConnectionHash",null);this._portsRoutedOnPcb=[]}get config(){return{zodProps:s1t,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:r,parent:i}=this;if(!i)throw new Error("Trace has no parent");const o=this.getTracePortPathSelectors().map(s=>({selector:s,port:this.getSubcircuit().selectOne(s,{type:"port"})??null}));for(const{selector:s,port:l}of o)if(!l){const c=s.replace(/(\> )?[^ ]+$/,""),u=this.getSubcircuit().selectOne(c);u?this.renderError(`Could not find port for selector "${s}" (did you forget to include the pin name?)
830
- searched component ${u.getString()}, which has ports: ${u.children.filter(d=>d.componentName==="Port").map(d=>`${d.getString()}(${d.getNameAndAliases().join(",")})`).join(" & ")}`):this.renderError(`Could not find port for selector "${s}"`)}return o.some(s=>!s.port)?{allPortsFound:!1}:{allPortsFound:!0,portsWithSelectors:o,ports:o.map(({port:s})=>s)}}_findConnectedNets(){const t=this.getTracePathNetSelectors().map(i=>({selector:i,net:this.getSubcircuit().selectOne(i,{type:"net"})})),r=t.filter(i=>!i.net);return r.length>0&&this.renderError(`Could not find net for selector "${r[0].selector}" inside ${this}`),{netsWithSelectors:t,nets:t.map(i=>i.net)}}_getAllTracesConnectedToSameNet(){const t=this.getSubcircuit().selectAll("trace"),r=this._findConnectedNets().nets,i=this._findConnectedPorts().ports??[];return t.filter(a=>{if(a===this)return!1;const o=a._findConnectedNets().nets,s=a._findConnectedPorts().ports??[];return o.some(l=>r.includes(l))||s.some(l=>i.includes(l))})}_isExplicitlyConnectedToPort(t){const{allPortsFound:r,portsWithSelectors:i}=this._findConnectedPorts();return r?i.map(o=>o.port).includes(t):!1}_isExplicitlyConnectedToNet(t){return this._findConnectedNets().nets.includes(t)}doInitialCreateNetsFromProps(){F2e(this,this.getTracePathNetSelectors())}_computeTraceConnectionHash(){const{allPortsFound:t,ports:r}=this._findConnectedPorts();return!t||!r?null:[...r].sort((o,s)=>(o.pcb_port_id||"").localeCompare(s.pcb_port_id||"")).map(o=>o.pcb_port_id).join(",")}doInitialSourceTraceRender(){var f;const{db:t}=this.root,{_parsedProps:r,parent:i}=this;if(!i){this.renderError("Trace has no parent");return}const{allPortsFound:a,portsWithSelectors:o}=this._findConnectedPorts();if(!a)return;this._traceConnectionHash=this._computeTraceConnectionHash();const l=t.source_trace.list().find(m=>m.subcircuit_connectivity_map_key===this.subcircuit_connectivity_map_key&&m.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=rgt({ports:o,nets:c}),d=t.source_trace.insert({connected_source_port_ids:o.map(m=>m.port.source_port_id),connected_source_net_ids:c.map(m=>m.source_net_id),subcircuit_id:(f=this.getSubcircuit())==null?void 0:f.subcircuit_id,max_length:Jyt(o.map(m=>m.port),{db:t})??r.maxLength,display_name:u,min_trace_thickness:r.thickness});this.source_trace_id=d.source_trace_id}_insertErrorIfTraceIsOutsideBoard(t,r){const{db:i}=this.root;agt(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:r.map(o=>o.pcb_port_id)})}doInitialPcbTraceRender(){var Q,X,ue,pe;if((Q=this.root)!=null&&Q.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r,parent:i}=this,a=this.getSubcircuit();if(!i)throw new Error("Trace has no parent");if(a._parsedProps.routingDisabled)return;const o=(X=a._parsedProps.pcbRouteCache)==null?void 0:X.pcbTraces;if(o){const ce=t.pcb_trace.insert({route:o.flatMap(Se=>Se.route),source_trace_id:this.source_trace_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((ue=this.getGroup())==null?void 0:ue.pcb_group_id)??void 0});this.pcb_trace_id=ce.pcb_trace_id;return}if(!a._shouldUseTraceByTraceRouting())return;const{allPortsFound:s,ports:l}=this._findConnectedPorts();if(!s)return;const c=[];for(const ce of l)ce._hasMatchedPcbPrimitive()||c.push(ce);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(ce=>ce.getString()).join(", ")}`,pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[],pcb_port_ids:c.map(ce=>ce.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 ce=l[0],he=u[0].net.getAllConnectedPorts().filter(Te=>Te!==ce);if(he.length===0){console.log("Nothing to connect this port to, the net is empty. TODO should emit a warning!");return}const ge=Gyt(ce,he);l.push(ge)}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 d=l.flatMap(ce=>ce.matchedComponents.filter(Se=>Se.componentName==="TraceHint")),f=(this._parsedProps.pcbRouteHints??[]).concat(d.flatMap(ce=>ce.getPcbRouteHints()));if(l.length>2){this.renderError(`Trace has more than two ports (${l.map(ce=>ce.getString()).join(", ")}), routing between more than two ports for a single trace is not implemented`);return}if(this.getSubcircuit().selectAll("trace").filter(ce=>ce.renderPhaseStates.PcbTraceRender.initialized).some(ce=>ce._portsRoutedOnPcb.length===l.length&&ce._portsRoutedOnPcb.every(Se=>l.includes(Se))))return;let E=[];f.length===0?E=[ZL(l[0]),ZL(l[1])]:E=[ZL(l[0]),...f,ZL(l[1])];const w=XL(E),S=W8(this.root.db.toArray()),[T,P]=Yyt(()=>PE(this.root.db.toArray()));if(P){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: ${P.message}`,source_trace_id:this.source_trace_id,center:{x:0,y:0},pcb_port_ids:l.map(ce=>ce.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[]});return}for(const ce of T)if(ce.connectedTo.length>0){const he=S.getNetConnectedToId(ce.connectedTo[0]);he&&ce.connectedTo.push(he)}let U=[];if(w.length===0)U=E;else{const ce=w[0].layer_path;U=E.map((Se,he)=>Se.via?{...Se,via_to_layer:ce[he]}:{...Se,layers:[ce[he]]})}U[0].pcb_port_id=l[0].pcb_port_id,U[U.length-1].pcb_port_id=l[1].pcb_port_id;const H=[];for(const[ce,Se]of k2e(U)){const he="via_to_layer"in ce?ce.via_to_layer:null,ge=2,Te="layers"in ce&&ce.layers.length===1?ce.layers[0]:he??"top",xe="layers"in Se&&Se.layers.length===1?Se.layers[0]:he??"top",Ae="pcb_port_id"in ce?ce.pcb_port_id:null,Ne="pcb_port_id"in Se?Se.pcb_port_id:null,ze=this.getSubcircuit()._parsedProps.minTraceWidth??.16,Re=new AE({OBSTACLE_MARGIN:ze*2,isRemovePathLoopsEnabled:!0,optimizeWithGoalBoxes:!!(Ae&&Ne),connMap:S,input:{obstacles:T,minTraceWidth:ze,connections:[{name:this.source_trace_id,pointsToConnect:[{...ce,layer:Te,pcb_port_id:Ae},{...Se,layer:xe,pcb_port_id:Ne}]}],layerCount:2,bounds:{minX:Math.min(ce.x,Se.x)-ge,maxX:Math.max(ce.x,Se.x)+ge,minY:Math.min(ce.y,Se.y)-ge,maxY:Math.max(ce.y,Se.y)+ge}}});let qe=null;try{qe=Re.solveAndMapToTraces()}catch(pt){this.renderError({type:"pcb_trace_error",pcb_trace_error_id:this.source_trace_id,error_type:"pcb_trace_error",message:`error solving route: ${pt.message}`,source_trace_id:this.pcb_trace_id,center:{x:(ce.x+Se.x)/2,y:(ce.y+Se.y)/2},pcb_port_ids:l.map(Tt=>Tt.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:l.map(Tt=>Tt.pcb_component_id)})}if(!qe)return;if(qe.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:(ce.x+Se.x)/2,y:(ce.y+Se.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)});return}const[Ke]=qe;he&&(Ke.route=Ke.route.map(pt=>(pt.route_type==="wire"&&!pt.layer&&(pt.layer=he),pt))),Ae&&Ke.route[0].route_type==="wire"&&(Ke.route[0].start_pcb_port_id=Ae);const ut=Ke.route[Ke.route.length-1];Ne&&ut.route_type==="wire"&&(ut.end_pcb_port_id=Ne),H.push(Ke.route)}const G=Vyt(H),W=Xyt(G),$=t.pcb_trace.insert({route:G,source_trace_id:this.source_trace_id,subcircuit_id:(pe=this.getSubcircuit())==null?void 0:pe.subcircuit_id,trace_length:W});this._portsRoutedOnPcb=l,this.pcb_trace_id=$.pcb_trace_id;for(const ce of G)ce.route_type==="via"&&t.pcb_via.insert({pcb_trace_id:$.pcb_trace_id,x:ce.x,y:ce.y,hole_diameter:.3,outer_diameter:.6,layers:[ce.from_layer,ce.to_layer],from_layer:ce.from_layer,to_layer:ce.to_layer});this._insertErrorIfTraceIsOutsideBoard(G,l)}_doInitialSchematicTraceRenderWithDisplayLabel(){var H,G,W,$;if((H=this.root)!=null&&H.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:r,parent:i}=this;if(!i)throw new Error("Trace has no parent");const{allPortsFound:a,portsWithSelectors:o}=this._findConnectedPorts();if(!a)return;const s=o.map(({port:Q})=>({port:Q,position:Q._getGlobalSchematicPositionAfterLayout(),schematic_port_id:Q.schematic_port_id,facingDirection:Q.facingDirection}));if(s.length<2)throw new Error("Expected at least two ports in portsWithPosition.");let l,c;const u=s[0].position,d=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(!d.source_port_id)throw new Error(`Missing source_port_id for the 'from' port (${l}).`);const f=s[1].position,m=s[1].port;if(!m.source_port_id)throw new Error(`Missing source_port_id for the 'to' port (${c}).`);const y=t.schematic_net_label.list().find(Q=>Q.source_net_id===d.source_port_id),E=t.schematic_net_label.list().find(Q=>Q.source_net_id===m.source_port_id),[w,S]=o.map(({port:Q})=>Q),P=((G=w.parent)==null?void 0:G.config.shouldRenderAsSchematicBox)?`${(W=w==null?void 0:w.parent)==null?void 0:W.props.name}_${w==null?void 0:w.props.name}`:`${($=S==null?void 0:S.parent)==null?void 0:$.props.name}_${S==null?void 0:S.props.name}`,U=this.props.schDisplayLabel??P;if(y&&y.text!==U&&(y.text=`${U} / ${y.text}`),E&&(E==null?void 0:E.text)!==U&&(E.text=`${U} / ${E.text}`),U!=null&&U.toLocaleLowerCase().includes("gnd")||U!=null&&U.toLocaleLowerCase().includes("ground")){!y&&!E?(WL({port:d,anchorPos:u,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t}),WL({port:m,anchorPos:f,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t})):y?E||WL({port:m,anchorPos:f,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t}):WL({port:d,anchorPos:u,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t});return}E||t.schematic_net_label.insert({text:this.props.schDisplayLabel??P,source_net_id:m.source_port_id,anchor_position:f,center:f,anchor_side:Bq(m.facingDirection)??"bottom"}),y||t.schematic_net_label.insert({text:this.props.schDisplayLabel??P,source_net_id:d.source_port_id,anchor_position:u,center:u,anchor_side:Bq(d.facingDirection)??"bottom"})}_isSymbolToChipConnection(){const{allPortsFound:t,ports:r}=this._findConnectedPorts();if(!t||r.length!==2)return!1;const[i,a]=r;if(!(i!=null&&i.parent)||!(a!=null&&a.parent))return!1;const o=i.parent.config.shouldRenderAsSchematicBox,s=a.parent.config.shouldRenderAsSchematicBox;return o&&!s||!o&&s}_isSymbolToSymbolConnection(){const{allPortsFound:t,ports:r}=this._findConnectedPorts();if(!t||r.length!==2)return!1;const[i,a]=r;if(!(i!=null&&i.parent)||!(a!=null&&a.parent))return!1;const o=!i.parent.config.shouldRenderAsSchematicBox,s=!a.parent.config.shouldRenderAsSchematicBox;return o&&s}_isChipToChipConnection(){const{allPortsFound:t,ports:r}=this._findConnectedPorts();if(!t||r.length!==2)return!1;const[i,a]=r;if(!(i!=null&&i.parent)||!(a!=null&&a.parent))return!1;const o=i.parent.config.shouldRenderAsSchematicBox,s=a.parent.config.shouldRenderAsSchematicBox;return o&&s}doInitialSchematicTraceRender(){var Te,xe;if((Te=this.root)!=null&&Te.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:r,parent:i}=this;if(!i)throw new Error("Trace has no parent");const{allPortsFound:a,portsWithSelectors:o}=this._findConnectedPorts(),{netsWithSelectors:s}=this._findConnectedNets();if(!a)return;const c=o.map(Ae=>Ae.port.schematic_port_id).sort().join(","),u=(xe=this.root)==null?void 0:xe._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 d={name:this.source_trace_id,pointsToConnect:[]},f=ngt(this),m=o.map(({port:Ae})=>({port:Ae,position:Ae._getGlobalSchematicPositionAfterLayout(),schematic_port_id:Ae.schematic_port_id??void 0,facingDirection:Ae.facingDirection}));if(m.length===1&&s.length===1){const Ae=s[0].net,{port:Ne,position:ze}=m[0];t.schematic_net_label.insert({text:Ae._parsedProps.name,source_net_id:Ae.source_net_id,anchor_position:ze,center:ze,anchor_side:Bq(Ne.facingDirection)??"bottom"});return}if(m.length<2)return;d.pointsToConnect=m.map(({position:Ae})=>({...Ae,layer:"top"}));const E=Hyt(f),w=2,S={minTraceWidth:.1,obstacles:f,connections:[d],bounds:{minX:E.minX-w,maxX:E.maxX+w,minY:E.minY-w,maxY:E.maxY+w},layerCount:1};let T=AE,P=!1;this.getSubcircuit().props._schDirectLineRoutingEnabled&&(T=Y2e,P=!0);let H=new T({input:S,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(H.length===0){if(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection()){this._doInitialSchematicTraceRenderWithDisplayLabel();return}H=new Y2e({input:S}).solveAndMapToTraces(),P=!0}const[{route:G}]=H;let W=[];for(let Ae=0;Ae<G.length-1;Ae++)W.push({from:G[Ae],to:G[Ae+1]});const $=this.source_trace_id;let Q=[];if(!P){igt({edges:W,db:t,source_trace_id:$});const Ae=Hq({db:t,source_trace_id:$,differentNetOnly:!0}).flatMap(Ne=>Ne.edges);W=Zyt({edges:W,otherEdges:Ae}),Q=Kyt({edges:W,db:t,source_trace_id:this.source_trace_id})}const X=W[W.length-1],ue=m[m.length-1],pe=W2e(X);W.push(...jq({lastEdge:X,lastEdgePort:ue,lastDominantDirection:pe}));const ce=W[0],Se=m[0],he=W2e(ce);if(W.unshift(...jq({firstEdge:ce,firstEdgePort:Se,firstDominantDirection:he})),!this.source_trace_id)throw new Error("Missing source_trace_id for schematic trace insertion.");if(this.getSubcircuit()._parsedProps.schTraceAutoLabelEnabled&&qyt(Q,W)>=5&&(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection())){this._doInitialSchematicTraceRenderWithDisplayLabel();return}const ge=t.schematic_trace.insert({source_trace_id:this.source_trace_id,edges:W,junctions:Q});this.schematic_trace_id=ge.schematic_trace_id,u!=null&&u._connectedSchematicPortPairs&&u._connectedSchematicPortPairs.add(c)}},ogt=r1("tscircuit:core"),sgt=b.object({x:d4,y:d4,z:d4}),a2=class extends Ig{constructor(t){super(t);Je(this,"reactSubtrees",[]);Je(this,"_impliedFootprint");Je(this,"isPrimitiveContainer",!0);Je(this,"_asyncSupplierPartNumbers");Je(this,"pcb_missing_footprint_error_id");this._addChildrenFromStringFootprint(),this.initPorts()}get defaultInternallyConnectedPinNames(){return[]}get internallyConnectedPinNames(){return this._parsedProps.internallyConnectedPins??this.defaultInternallyConnectedPinNames}initPorts(t={}){var s,l,c,u,d,f,m,y,E,w;if((s=this.root)!=null&&s.schematicDisabled)return;const{config:r}=this,i=[],a=this._getSchematicPortArrangement();if(a&&!this._parsedProps.pinLabels){for(const P in a){const U=a[P].pins;if(Array.isArray(U))for(const H of U){const G=LC(H,this._parsedProps.pinLabels);i.push(new K8({pinNumber:G,aliases:((l=t.additionalAliases)==null?void 0:l[`pin${G}`])??[]},{originDescription:`schPortArrangement:${P}`}))}}const S=["left","right","top","bottom"];let T=1;for(const P of S){const U=a[`${P}Size`];for(let H=0;H<U;H++)i.push(new K8({pinNumber:T++,aliases:((c=t.additionalAliases)==null?void 0:c[`pin${T}`])??[]},{originDescription:`schPortArrangement:${P}`}))}}const o=this._parsedProps.pinLabels;if(o)for(let[S,T]of Object.entries(o)){S=S.replace("pin","");let P=i.find(G=>G._parsedProps.pinNumber===Number(S));const U=Array.isArray(T)?T[0]:T,H=Array.isArray(T)?T.slice(1):[];P?(P.externallyAddedAliases.push(U,...H),P.props.name=U):(P=new K8({pinNumber:parseInt(S),name:U,aliases:[...H,...((u=t.additionalAliases)==null?void 0:u[`pin${parseInt(S)}`])??[]]},{originDescription:`pinLabels:pin${S}`}),i.push(P))}if(r.schematicSymbolName){const S=Hb[this._getSchematicSymbolNameOrThrow()];if(!S)return;for(const T of S.ports){const P=G2e(T.labels);if(!P)continue;const U=i.find(H=>H._parsedProps.pinNumber===Number(P));if(U)U.schematicSymbolPortDef=T;else{const H=OC(T.labels.concat(((d=t.additionalAliases)==null?void 0:d[`pin${P}`])??[]));H&&(H.originDescription=`schematicSymbol:labels[0]:${T.labels[0]}`,H.schematicSymbolPortDef=T,i.push(H))}}this.addAll(i)}if(!this._getSchematicPortArrangement()){const S=this.getPortsFromFootprint(t);for(const T of S)i.some(P=>P.isMatchingAnyOf(T.getNameAndAliases()))||i.push(T)}for(let S=1;S<=(t.pinCount??this._getPinCount());S++){if(!a||i.find(P=>P._parsedProps.pinNumber===S))continue;let T=[...((f=a.leftSide)==null?void 0:f.pins)??[],...((m=a.rightSide)==null?void 0:m.pins)??[],...((y=a.topSide)==null?void 0:y.pins)??[],...((E=a.bottomSide)==null?void 0:E.pins)??[]].map(P=>LC(P,this._parsedProps.pinLabels));["leftSize","rightSize","topSize","bottomSize","leftPinCount","rightPinCount","topPinCount","bottomPinCount"].some(P=>P in a)&&(T=Array.from({length:this._getPinCount()},(P,U)=>U+1)),T.includes(S)&&i.push(new K8({pinNumber:S,aliases:((w=t.additionalAliases)==null?void 0:w[`pin${S}`])??[]},{originDescription:`notOtherwiseAddedButDeducedFromPinCount:${S}`}))}i.length>0&&this.addAll(i)}_getImpliedFootprintString(){return null}_addChildrenFromStringFootprint(){var o;const{name:t,pcbRotation:r,pinLabels:i}=this.props;let{footprint:a}=this.props;if(a??(a=(o=this._getImpliedFootprintString)==null?void 0:o.call(this)),!!a&&typeof a=="string"){const s=bE.string(a).soup(),l=Nyt({componentName:t,componentRotation:r,footprint:a,pinLabels:i},s);this.addAll(l)}}get portMap(){return new Proxy({},{get:(t,r)=>{const i=this.children.find(a=>a.componentName==="Port"&&a.isMatchingNameOrAlias(r));if(!i)throw new Error(`There was an issue finding the port "${r.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 r of this.reactSubtrees)if(r.element===t)return r.component;return null}doInitialSourceRender(){const t=this.config.sourceFtype;if(!t)return;const{db:r}=this.root,{_parsedProps:i}=this,a=r.source_component.insert({ftype:t,name:i.name,manufacturer_part_number:i.manufacturerPartNumber??i.mfn,supplier_part_numbers:i.supplierPartNumbers});this.source_component_id=a.source_component_id}doInitialSchematicComponentRender(){var a,o,s;if((a=this.root)!=null&&a.schematicDisabled)return;const{db:t}=this.root,{schematicSymbolName:r}=this.config;r?this._doInitialSchematicComponentRenderWithSymbol():this._getSchematicBoxDimensions()&&this._doInitialSchematicComponentRenderWithSchematicBoxDimensions();const i=(o=this.getSubcircuit())==null?void 0:o._getSchematicManualPlacementForComponent(this);if(this.schematic_component_id&&(this.props.schX!==void 0||this.props.schY!==void 0)&&i){if(!this.schematic_component_id)return;const l=d$.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 r of this.internallyConnectedPinNames){const i=[];for(const a of r)i.push(this.portMap[a]);t.push(i)}return t}_doInitialSchematicComponentRenderWithSymbol(){var s;if((s=this.root)!=null&&s.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,i=this._getSchematicSymbolNameOrThrow(),a=Hb[i],o=this._getGlobalSchematicPositionBeforeLayout();if(a){const l=t.schematic_component.insert({center:o,size:a.size,source_component_id:this.source_component_id,symbol_name:i,symbol_display_value:this._getSchematicSymbolDisplayValue()});this.schematic_component_id=l.schematic_component_id}}_doInitialSchematicComponentRenderWithSchematicBoxDimensions(){var f;if((f=this.root)!=null&&f.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,i=this._getSchematicBoxDimensions(),a={};if(Array.isArray(r.pinLabels))r.pinLabels.forEach((m,y)=>{a[String(y+1)]=m});else for(const[m,y]of Object.entries(r.pinLabels??{}))a[m]=Array.isArray(y)?y[0]:y;const o=this._getGlobalSchematicPositionBeforeLayout(),s=this._getSchematicPortArrangement(),l=t.schematic_component.insert({center:o,rotation:r.schRotation??0,size:i.getSize(),port_arrangement:Cyt(s),pin_spacing:r.schPinSpacing??.2,pin_styles:Myt(r.schPinStyle,r.pinLabels),port_labels:a,source_component_id:this.source_component_id}),c=(s==null?void 0:s.topSide)!==void 0||(s==null?void 0:s.bottomSide)!==void 0,u=i==null?void 0:i.getSize().width,d=i==null?void 0:i.getSize().height;t.schematic_text.insert({text:r.manufacturerPartNumber??"",schematic_component_id:l.schematic_component_id,anchor:"left",rotation:0,position:{x:c?o.x+(u??0)/2+.1:o.x-(u??0)/2,y:c?o.y+(d??0)/2+.35:o.y-(d??0)/2-.13},color:"#006464",font_size:.05}),t.schematic_text.insert({text:r.name??"",schematic_component_id:l.schematic_component_id,anchor:"left",rotation:0,position:{x:c?o.x+(u??0)/2+.1:o.x-(u??0)/2,y:c?o.y+(d??0)/2+.55:o.y+(d??0)/2+.13},color:"#006464",font_size:.05}),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:r}=this,i=this.getSubcircuit(),a=t.pcb_component.insert({center:this._getGlobalPcbPositionBeforeLayout(),width:0,height:0,layer:r.layer??"top",rotation:r.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:i.subcircuit_id??void 0});if(!r.footprint&&!this.isGroup){const l=t.pcb_missing_footprint_error.insert({message:`No footprint found for component: ${this.getString()}`,source_component_id:`${this.source_component_id}`,error_type:"pcb_missing_footprint_error"});this.pcb_missing_footprint_error_id=l.pcb_missing_footprint_error_id}this.pcb_component_id=a.pcb_component_id;const o=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if((this.props.pcbX!==void 0||this.props.pcbY!==void 0)&&o){const l=h$.parse({type:"pcb_manual_edit_conflict_warning",pcb_manual_edit_conflict_warning_id:`pcb_manual_edit_conflict_${this.source_component_id}`,message:`${this.getString()} has both manual placement and prop coordinates. pcbX and pcbY will be used. Remove pcbX/pcbY or clear the manual placement.`,pcb_component_id:this.pcb_component_id,source_component_id:this.source_component_id,subcircuit_id:i.subcircuit_id??void 0});t.pcb_manual_edit_conflict_warning.insert(l)}}doInitialPcbComponentSizeCalculation(){var o;if((o=this.root)!=null&&o.pcbDisabled||!this.pcb_component_id)return;const{db:t}=this.root,{_parsedProps:r}=this,i=$2e(this.children);if(i.width===0||i.height===0)return;const a={x:(i.minX+i.maxX)/2,y:(i.minY+i.maxY)/2};t.pcb_component.update(this.pcb_component_id,{center:a,width:i.width,height:i.height})}_renderReactSubtree(t){return{element:t,component:Tyt(t)}}doInitialInitializePortsFromChildren(){this.initPorts()}doInitialReactSubtreesRender(){if(rt.isValidElement(this.props.footprint)){if(this.reactSubtrees.some(r=>r.element===this.props.footprint))return;const t=this._renderReactSubtree(this.props.footprint);this.reactSubtrees.push(t),this.add(t.component)}}_hasExistingPortExactly(t){return this.children.filter(i=>i.componentName==="Port").some(i=>{const a=t.getNameAndAliases(),o=i.getNameAndAliases();return a.length===o.length&&a.every(s=>o.includes(s))})}add(t){let r;if(rt.isValidElement(t)){const i=this._renderReactSubtree(t);this.reactSubtrees.push(i),r=i.component}else r=t;if(r.componentName==="Port"){if(this._hasExistingPortExactly(r))return;const a=this.children.filter(o=>o.componentName==="Port").find(o=>o.isMatchingAnyOf(r.getNameAndAliases()));a&&ogt(`Similar ports added. Port 1: ${a}, Port 2: ${r}`)}super.add(r)}getPortsFromFootprint(t){let{footprint:r}=this.props;if((!r||rt.isValidElement(r))&&(r=this.children.find(a=>a.componentName==="Footprint")),typeof r=="string"){const a=bE.string(r).soup(),o=[];for(const s of a)if("port_hints"in s&&s.port_hints){const l=OC(s.port_hints,t);if(!l)continue;l.originDescription=`footprint:string:${r}:port_hints[0]:${s.port_hints[0]}`,o.push(l)}return o}if(!rt.isValidElement(r)&&r&&r.componentName==="Footprint"){const a=r;let o=1;const s=[];for(const l of a.children){if(!l.props.portHints)continue;let c=l.props.portHints;c.some(f=>f.startsWith("pin"))||(c=[...c,`pin${o}`]),o++;const d=OC(c);d&&(d.originDescription=`footprint:${r}`,s.push(d))}return s}const i=[];if(!r){for(const a of this.children)if(a.props.portHints&&a.isPcbPrimitive){const o=OC(a.props.portHints);o&&i.push(o)}}return i}getPortsFromSchematicSymbol(){var a;if((a=this.root)!=null&&a.schematicDisabled)return[];const{config:t}=this;if(!t.schematicSymbolName)return[];const r=Hb[t.schematicSymbolName];if(!r)return[];const i=[];for(const o of r.ports){const s=OC(o.labels);s&&(s.schematicSymbolPortDef=o,i.push(s))}return i}doInitialCreateNetsFromProps(){this._createNetsFromProps(this._getNetsFromConnectionsProp())}_getNetsFromConnectionsProp(){const{_parsedProps:t}=this,r=[];if(t.connections)for(const[i,a]of Object.entries(t.connections)){const o=Array.isArray(a)?a:[a];for(const s of o)r.push(s)}return r}_createNetsFromProps(t){F2e(this,t)}_getPcbCircuitJsonBounds(){const{db:t}=this.root;if(!this.pcb_component_id)return super._getPcbCircuitJsonBounds();const r=t.pcb_component.get(this.pcb_component_id);return{center:{x:r.center.x,y:r.center.y},bounds:{left:r.center.x-r.width/2,top:r.center.y-r.height/2,right:r.center.x+r.width/2,bottom:r.center.y+r.height/2},width:r.width,height:r.height}}_getPinCountFromSchematicPortArrangement(){const t=this._getSchematicPortArrangement();if(!t)return 0;if(!q2e(t))return(t.leftSize??t.leftPinCount??0)+(t.rightSize??t.rightPinCount??0)+(t.topSize??t.topPinCount??0)+(t.bottomSize??t.bottomPinCount??0);const{leftSide:i,rightSide:a,topSide:o,bottomSide:s}=t;return Math.max(...(i==null?void 0:i.pins)??[],...(a==null?void 0:a.pins)??[],...(o==null?void 0:o.pins)??[],...(s==null?void 0:s.pins)??[])}_getPinCount(){return this._getSchematicPortArrangement()?this._getPinCountFromSchematicPortArrangement():this.getPortsFromFootprint().length}_getSchematicPortArrangement(){return this._parsedProps.schPinArrangement??this._parsedProps.schPortArrangement}_getSchematicBoxDimensions(){if(this.getSchematicSymbol()||!this.config.shouldRenderAsSchematicBox)return null;const{_parsedProps:t}=this,r=this._getPinCount(),i=t.schPinSpacing??.2;return Iyt({schWidth:t.schWidth,schHeight:t.schHeight,schPinSpacing:i,numericSchPinStyle:jyt(t.schPinStyle,t.pinLabels),pinCount:r,schPortArrangement:this._getSchematicPortArrangement(),pinLabels:t.pinLabels})}doInitialCadModelRender(){var u;const{db:t}=this.root,{boardThickness:r=0}=((u=this.root)==null?void 0:u._getBoard())??{},i=this._parsedProps.cadModel;if(!this.pcb_component_id||!i&&!this.props.footprint)return;const a=this._getPcbCircuitJsonBounds(),o=t.pcb_component.get(this.pcb_component_id);if(typeof i=="string")throw new Error("String cadModel not yet implemented");const s=sgt.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=gE.parse({x:0,y:0,z:0,...typeof(i==null?void 0:i.positionOffset)=="object"?i.positionOffset:{}}),c=this.props.layer==="bottom"?"bottom":"top";t.cad_component.insert({position:{x:a.center.x+l.x,y:a.center.y+l.y,z:(c==="bottom"?-r/2:r/2)+l.z},rotation:{x:s.x,y:(c==="top"?0:180)+s.y,z:((o==null?void 0:o.rotation)??0)+(c==="bottom"?180: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 r=((i=this.root)==null?void 0:i.getClientOrigin())??"";return`${t}${t.includes("?")?"&":"?"}cachebust_origin=${encodeURIComponent(r)}`}doInitialPartsEngineRender(){const t=this.getInheritedProperty("partsEngine");if(!t)return;const{db:r}=this.root,i=r.source_component.get(this.source_component_id);if(!i||i.supplier_part_numbers)return;let a;this.props.footprint&&typeof this.props.footprint=="string"&&(a=this.props.footprint);const o=t.findPart({sourceComponent:i,footprinterString:a});if(!(o instanceof Promise)){r.source_component.update(this.source_component_id,{supplier_part_numbers:o});return}this._queueAsyncEffect("get-supplier-part-numbers",async()=>{this._asyncSupplierPartNumbers=await o,this._markDirty("PartsEngineRender")})}updatePartsEngineRender(){const{db:t}=this.root,r=t.source_component.get(this.source_component_id);if(r&&!r.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[r,i]of Object.entries(t.connections)){const a=Array.isArray(i)?i:[i];for(const o of a)this.add(new w7({from:`${this.getSubcircuitSelector()} > port.${r}`,to:o}))}}},lgt=class{constructor(e,t={}){Je(this,"input");Je(this,"isRouting",!1);Je(this,"solver");Je(this,"eventHandlers",{complete:[],error:[],progress:[]});Je(this,"cycleCount",0);Je(this,"stepDelay");Je(this,"timeoutId");this.input=e;const{capacityDepth:r,targetMinCapacity:i,stepDelay:a=0}=t;this.solver=new Cq(e,{capacityDepth:r,targetMinCapacity:i}),this.stepDelay=a}start(){this.isRouting||(this.isRouting=!0,this.cycleCount=0,this.runCycleAndQueueNextCycle())}runCycleAndQueueNextCycle(){var e;if(this.isRouting)try{if(this.solver.solved||this.solver.failed){this.solver.failed?this.emitEvent({type:"error",error:new Error(this.solver.error||"Routing failed")}):this.emitEvent({type:"complete",traces:this.solver.getOutputSimpleRouteJson().traces||[]}),this.isRouting=!1;return}const t=Date.now(),r=this.solver.iterations;for(;Date.now()-t<250&&!this.solver.failed&&!this.solver.solved;)this.solver.step();const i=(this.solver.iterations-r)/(Date.now()-t)*1e3;this.cycleCount++;const a=((e=this.solver)==null?void 0:e.preview())||void 0,o=this.solver.progress;this.emitEvent({type:"progress",steps:this.cycleCount,iterationsPerSecond:i,progress:o,phase:this.solver.getCurrentPhase(),debugGraphics:a}),this.stepDelay>0?this.timeoutId=setTimeout(()=>this.runCycleAndQueueNextCycle(),this.stepDelay):this.timeoutId=setTimeout(()=>this.runCycleAndQueueNextCycle(),0)}catch(t){this.emitEvent({type:"error",error:t instanceof Error?t:new Error(String(t))}),this.isRouting=!1}}stop(){this.isRouting&&(this.isRouting=!1,this.timeoutId!==void 0&&(clearTimeout(this.timeoutId),this.timeoutId=void 0))}on(e,t){e==="complete"?this.eventHandlers.complete.push(t):e==="error"?this.eventHandlers.error.push(t):e==="progress"&&this.eventHandlers.progress.push(t)}emitEvent(e){if(e.type==="complete")for(const t of this.eventHandlers.complete)t(e);else if(e.type==="error")for(const t of this.eventHandlers.error)t(e);else if(e.type==="progress")for(const t of this.eventHandlers.progress)t(e)}solveSync(){if(this.solver.solve(),this.solver.failed)throw new Error(this.solver.error||"Routing failed");return this.solver.getOutputSimpleRouteJson().traces||[]}},Z2e=class extends Ig{constructor(){super(...arguments);Je(this,"matchedPort",null)}get config(){return{componentName:"TraceHint",zodProps:k1t}}doInitialPortMatching(){const{db:t}=this.root,{_parsedProps:r,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(!r.for){this.renderError(`TraceHint has no for property (${this})`);return}const a=i.selectOne(r.for,{type:"port"});a||this.renderError(`${this} could not find port for selector "${r.for}"`),this.matchedPort=a,a.registerMatch(this)}getPcbRouteHints(){const{_parsedProps:t}=this,r=t.offset?[t.offset]:t.offsets;if(!r)return[];const i=this._computePcbGlobalTransformBeforeLayout();return r.map(a=>({...Cr(i,a),via:a.via,to_layer:a.to_layer,trace_width:a.trace_width}))}doInitialPcbTraceHintRender(){var i,a,o;if((i=this.root)!=null&&i.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this;t.pcb_trace_hint.insert({pcb_component_id:(a=this.matchedPort)==null?void 0:a.pcb_component_id,pcb_port_id:(o=this.matchedPort)==null?void 0:o.pcb_port_id,route:this.getPcbRouteHints()})}},cgt=({circuitJson:n,editEvents:e,manualEditsFile:t})=>{var i;const r={...t,pcb_placements:[...t.pcb_placements??[]]};for(const a of e)if(a.edit_event_type==="edit_pcb_component_location"){const{pcb_component_id:o,new_center:s}=a,l=m3(n).pcb_component.get(o);if(!l)continue;const c=m3(n).source_component.get(l.source_component_id);if(!c)continue;const u=(i=r.pcb_placements)==null?void 0:i.findIndex(f=>f.selector===c.name),d={selector:c.name,center:s,relative_to:"group_center"};u>=0?r.pcb_placements[u]=d:r.pcb_placements.push(d)}return r},ugt=({circuitJson:n,editEvents:e,manualEditsFile:t})=>{var i;const r={...t,schematic_placements:[...t.schematic_placements??[]]};for(const a of e)if(a.edit_event_type==="edit_schematic_component_location"){const{schematic_component_id:o,new_center:s}=a,l=m3(n).schematic_component.get(o);if(!l)continue;const c=m3(n).source_component.get(l.source_component_id);if(!c)continue;const u=(i=r.schematic_placements)==null?void 0:i.findIndex(f=>f.selector===c.name),d={selector:c.name,center:s,relative_to:"group_center"};u>=0?r.schematic_placements[u]=d:r.schematic_placements.push(d)}return r},Q2e=({circuitJson:n,editEvents:e,manualEditsFile:t})=>{const r=e.filter(o=>o.edit_event_type==="edit_schematic_component_location"),i=e.filter(o=>o.edit_event_type==="edit_pcb_component_location");let a=t;return r.length>0&&(a=ugt({circuitJson:n,editEvents:r,manualEditsFile:a})),i.length>0&&(a=cgt({circuitJson:n,editEvents:i,manualEditsFile:a})),a},dgt=(n,e)=>{const t=n.source_group.list(),r=[],i=a=>{const o=t.filter(s=>s.parent_subcircuit_id===a);for(const s of o)s.subcircuit_id&&(r.push(s.subcircuit_id),i(s.subcircuit_id))};return i(e),r},K2e=({db:n,circuitJson:e,subcircuit_id:t,minTraceWidth:r=.1})=>{if(!n&&e&&(n=m3(e)),!n)throw new Error("db or circuitJson is required");const i=n.pcb_trace_hint.list(),a=t?new Set([t]):null;if(t){const E=dgt(n,t);for(const w of E)a.add(w)}const o=(e??n.toArray()).filter(E=>!t||"subcircuit_id"in E&&a.has(E.subcircuit_id)),s=n.pcb_board.list()[0];n=m3(o);const l=W8(o),c=PE([...n.pcb_component.list(),...n.pcb_smtpad.list(),...n.pcb_plated_hole.list(),...n.pcb_hole.list(),...n.pcb_via.list()].filter(E=>!t||(a==null?void 0:a.has(E.subcircuit_id))),l);for(const E of c){const w=E.connectedTo.flatMap(S=>l.getIdsConnectedToNet(S));E.connectedTo.push(...w)}const u=c.flatMap(E=>[{x:E.center.x-E.width/2,y:E.center.y-E.height/2},{x:E.center.x+E.width/2,y:E.center.y+E.height/2}]);let d;s?d={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}:d={minX:Math.min(...u.map(E=>E.x))-1,maxX:Math.max(...u.map(E=>E.x))+1,minY:Math.min(...u.map(E=>E.y))-1,maxY:Math.max(...u.map(E=>E.y))+1};const f=n.source_trace.list().map(E=>{var W,$,Q;const w=E.connected_source_port_ids.map(X=>{const ue=n.source_port.get(X),pe=n.pcb_port.getWhere({source_port_id:X});return{...ue,...pe}});if(w.length<2)return null;const[S,T]=w,P=((W=S.layers)==null?void 0:W[0])??"top",U=(($=T.layers)==null?void 0:$[0])??"top",H=i.filter(X=>X.pcb_port_id===S.pcb_port_id||X.pcb_port_id===T.pcb_port_id),G=[];for(const X of H){const ue=n.pcb_port.get(X.pcb_port_id),pe=((Q=ue==null?void 0:ue.layers)==null?void 0:Q[0])??"top";for(const ce of X.route)G.push({x:ce.x,y:ce.y,layer:pe})}return{name:E.source_trace_id??l.getNetConnectedToId(E.source_trace_id)??"",source_trace_id:E.source_trace_id,pointsToConnect:[{x:S.x,y:S.y,layer:P},...G,{x:T.x,y:T.y,layer:U}]}}).filter(E=>E!==null),m=n.source_net.list().filter(E=>!t||(a==null?void 0:a.has(E.subcircuit_id))),y=[];for(const E of m){const w=n.source_trace.list().filter(S=>{var T;return(T=S.connected_source_net_ids)==null?void 0:T.includes(E.source_net_id)});y.push({name:E.source_net_id??l.getNetConnectedToId(E.source_net_id),pointsToConnect:w.flatMap(S=>n.pcb_port.list().filter(P=>S.connected_source_port_ids.includes(P.source_port_id)).map(P=>{var U;return{x:P.x,y:P.y,layer:((U=P.layers)==null?void 0:U[0])??"top",pcb_port_id:P.pcb_port_id}}))})}return{simpleRouteJson:{bounds:d,obstacles:c,connections:[...f,...y],layerCount:2,minTraceWidth:r},connMap:l}},Vq=class extends a2{constructor(){super(...arguments);Je(this,"pcb_group_id",null);Je(this,"subcircuit_id",null);Je(this,"_hasStartedAsyncAutorouting",!1);Je(this,"_asyncAutoroutingResult",null)}get config(){return{zodProps:Omt,componentName:"Group"}}doInitialSourceRender(){const{db:t}=this.root,r=t.source_group.insert({name:this._parsedProps.name,is_subcircuit:this.isSubcircuit});this.subcircuit_id=`subcircuit_${r.source_group_id}`,this.source_group_id=r.source_group_id,t.source_group.update(r.source_group_id,{subcircuit_id:this.subcircuit_id})}doInitialSourceParentAttachment(){var i,a,o;const{db:t}=this.root;if(!this.isSubcircuit)return;const r=(o=(a=(i=this.parent)==null?void 0:i.getSubcircuit)==null?void 0:a.call(i))==null?void 0:o.subcircuit_id;r&&t.source_group.update(this.source_group_id,{parent_subcircuit_id:r})}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=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}doInitialCreateTraceHintsFromProps(){var o;const{_parsedProps:t}=this,{db:r}=this.root,i=t;if(!this.isSubcircuit)return;const a=(o=i.layout)==null?void 0:o.manual_trace_hints;if(a)for(const s of a)this.add(new Z2e({for:s.pcb_port_selector,offsets:s.offsets}))}doInitialSourceAddConnectivityMapKey(){if(!this.isSubcircuit)return;const{db:t}=this.root,r=this.selectAll("trace"),i=new TC({});i.addConnections(r.map(a=>{const o=t.source_trace.get(a.source_trace_id);return o?[o.source_trace_id,...o.connected_source_port_ids,...o.connected_source_net_ids]:null}).filter(a=>a!==null));for(const a of r){if(!a.source_trace_id)continue;const o=i.getNetConnectedToId(a.source_trace_id);if(!o)continue;const{name:s}=this._parsedProps;a.subcircuit_connectivity_map_key=`${s??`unnamedsubcircuit${this._renderId}`}_${o}`,t.source_trace.update(a.source_trace_id,{subcircuit_connectivity_map_key:a.subcircuit_connectivity_map_key})}}_areChildSubcircuitsRouted(){const t=this.selectAll("group").filter(r=>r.isSubcircuit);for(const r of t)if(r._shouldRouteAsync()&&!r._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=r1("tscircuit:core:_hasTracesToRoute"),r=this.selectAll("trace");return t(`[${this.getString()}] has ${r.length} traces to route`),r.length>0}async _runEffectMakeHttpAutoroutingRequest(){var u,d,f,m;const{db:t}=this.root,r=r1("tscircuit:core:_runEffectMakeHttpAutoroutingRequest");this._parsedProps;const i=this._getAutorouterConfig(),a=i.serverUrl,o=i.serverMode,s=(y,E)=>{var w;return r("fetching",y),E.headers&&(E.headers["Tscircuit-Core-Version"]=(w=this.root)==null?void 0:w.getCoreVersion()),fetch(y,E)},l=this.root.db.toArray().filter(y=>y.type.startsWith("source_")||y.type.startsWith("pcb_"));if(o==="solve-endpoint"){if(((u=this.props.autorouter)==null?void 0:u.inputFormat)==="simplified"){const{autorouting_result:E}=await s(`${a}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_simple_route_json:K2e({db:t,minTraceWidth:((d=this.props.autorouter)==null?void 0:d.minTraceWidth)??.15,subcircuit_id:this.subcircuit_id}).simpleRouteJson,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(w=>w.json());this._asyncAutoroutingResult=E,this._markDirty("PcbTraceRender");return}const{autorouting_result:y}=await s(`${a}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_circuit_json:l,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(E=>E.json());this._asyncAutoroutingResult=y,this._markDirty("PcbTraceRender");return}const{autorouting_job:c}=await s(`${a}/autorouting/jobs/create`,{method:"POST",body:JSON.stringify({input_circuit_json:l,provider:"freerouting",autostart:!0,display_name:(f=this.root)==null?void 0:f.name,subcircuit_id:this.subcircuit_id,server_cache_enabled:i.serverCacheEnabled}),headers:{"Content-Type":"application/json"}}).then(y=>y.json());for(;;){const{autorouting_job:y}=await s(`${a}/autorouting/jobs/get`,{method:"POST",body:JSON.stringify({autorouting_job_id:c.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(E=>E.json());if(y.is_finished){const{autorouting_job_output:E}=await s(`${a}/autorouting/jobs/get_output`,{method:"POST",body:JSON.stringify({autorouting_job_id:c.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(w=>w.json());this._asyncAutoroutingResult={output_pcb_traces:E.output_pcb_traces},this._markDirty("PcbTraceRender");break}if(y.has_error)throw t.pcb_autorouting_error.insert({pcb_error_id:c.autorouting_job_id,message:((m=y.error)==null?void 0:m.message)??JSON.stringify(y.error)}),new Error(`Autorouting job failed: ${JSON.stringify(y.error)}`);await new Promise(E=>setTimeout(E,100))}}async _runLocalAutorouting(){var l,c,u,d,f;const{db:t}=this.root;this._parsedProps;const r=r1("tscircuit:core:_runLocalAutorouting");r(`[${this.getString()}] starting local autorouting`);const i=this._getAutorouterConfig(),{simpleRouteJson:a}=K2e({db:t,minTraceWidth:((l=this.props.autorouter)==null?void 0:l.minTraceWidth)??.15,subcircuit_id:this.subcircuit_id});(c=this.root)==null||c.emit("autorouting:start",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),simpleRouteJson:a});let o;i.algorithmFn?o=await i.algorithmFn(a):o=new lgt(a,{capacityDepth:(u=this.props.autorouter)==null?void 0:u.capacityDepth,targetMinCapacity:(d=this.props.autorouter)==null?void 0:d.targetMinCapacity});const s=new Promise((m,y)=>{o.on("complete",E=>{r(`[${this.getString()}] local autorouting complete`),m(E.traces)}),o.on("error",E=>{r(`[${this.getString()}] local autorouting error: ${E.error.message}`),y(E.error)})});o.on("progress",m=>{var y;(y=this.root)==null||y.emit("autorouting:progress",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),...m})}),o.start();try{const m=await s;this._asyncAutoroutingResult={output_pcb_traces:m},this._markDirty("PcbTraceRender")}catch(m){const{db:y}=this.root;throw y.pcb_autorouting_error.insert({pcb_error_id:`pcb_autorouter_error_subcircuit_${this.subcircuit_id}`,message:m instanceof Error?m.message:String(m)}),(f=this.root)==null||f.emit("autorouting:error",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),error:{message:m instanceof Error?m.message:String(m)},simpleRouteJson:a}),m}finally{o.stop()}}_startAsyncAutorouting(){this._hasStartedAsyncAutorouting||(this._hasStartedAsyncAutorouting=!0,this._getAutorouterConfig().local?this._queueAsyncEffect("capacity-mesh-autorouting",async()=>this._runLocalAutorouting()):this._queueAsyncEffect("make-http-autorouting-request",async()=>this._runEffectMakeHttpAutoroutingRequest()))}doInitialPcbTraceRender(){var r;const t=r1("tscircuit:core:doInitialPcbTraceRender");if(this.isSubcircuit&&!((r=this.root)!=null&&r.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=r1("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:r}=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:r}=this._asyncAutoroutingResult.output_simple_route_json;if(r)for(const i of r)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:r}=this.root;for(const i of t)if(i.type==="pcb_trace"){if(i.subcircuit_id=this.subcircuit_id,i.connection_name){const a=i.connection_name;i.source_trace_id=a}r.pcb_trace.insert(i)}for(const i of t)if(i.type!=="pcb_via"&&i.type==="pcb_trace")for(const a of i.route)a.route_type==="via"&&r.pcb_via.insert({pcb_trace_id:i.pcb_trace_id,x:a.x,y:a.y,hole_diameter:.3,outer_diameter:.6,layers:[a.from_layer,a.to_layer],from_layer:a.from_layer,to_layer:a.to_layer})}doInitialSchematicLayout(){if(!this.isSubcircuit||!this._parsedProps.schAutoLayoutEnabled)return;const{db:r}=this.root,i=this.getDescendants(),a=[];for(const l of i)if("schematic_component_id"in l){const c=r.schematic_component.get(l.schematic_component_id);if(c){const u=r.schematic_port.list().filter(d=>d.schematic_component_id===c.schematic_component_id);a.push(...u)}}const o=hq(r.toArray()),s=mq(o);pq(r.toArray(),s)}_getAutorouterConfig(){const t={serverUrl:"https://registry-api.tscircuit.com",serverMode:"job",serverCacheEnabled:!0},r=this._parsedProps.autorouter??this.getInheritedProperty("autorouter");return typeof r=="object"?{local:!(r.serverUrl||r.serverMode||r.serverCacheEnabled),...t,...r}:r==="auto-local"?{local:!0,groupMode:"subcircuit"}:r==="sequential-trace"?{local:!0,groupMode:"sequential-trace"}:r==="subcircuit"?{local:!0,groupMode:"subcircuit"}:r==="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 r;if((r=this.root)!=null&&r.pcbDisabled||this.getInheritedProperty("routingDisabled"))return;const{db:t}=this.root;if(this.isSubcircuit){const i=new Map;for(const a of this.children)if(!a.isSubcircuit&&a._parsedProps.name){const o=i.get(a._parsedProps.name)||[];o.push(a),i.set(a._parsedProps.name,o)}for(const[a,o]of i.entries())o.length>1&&t.pcb_trace_error.insert({error_type:"pcb_trace_error",message:`Multiple components found with name "${a}" in subcircuit "${this._parsedProps.name||"unnamed"}". Component names must be unique within a subcircuit.`,source_trace_id:"",pcb_trace_id:"",pcb_component_ids:o.map(s=>s.pcb_component_id).filter(Boolean),pcb_port_ids:[]})}}},fgt=class extends Vq{constructor(){super(...arguments);Je(this,"pcb_board_id",null);Je(this,"_drcChecksComplete",!1);Je(this,"_connectedSchematicPortPairs",new Set)}get isSubcircuit(){return!0}get config(){return{componentName:"Board",zodProps:$xe}}get boardThickness(){const{_parsedProps:t}=this;return 1.4}get allLayers(){return["top","bottom","inner1","inner2"]}doInitialPcbBoardAutoSize(){var y;if((y=this.root)!=null&&y.pcbDisabled||!this.pcb_board_id)return;const{db:t}=this.root,{_parsedProps:r}=this;if(r.width&&r.height)return;let i=1/0,a=1/0,o=-1/0,s=-1/0;const l=t.pcb_component.list();let c=!1;for(const E of l){const{width:w,height:S,center:T}=E;w===0||S===0||(c=!0,i=Math.min(i,T.x-w/2),a=Math.min(a,T.y-S/2),o=Math.max(o,T.x+w/2),s=Math.max(s,T.y+S/2))}const u=2,d=c?o-i+u*2:0,f=c?s-a+u*2:0,m={x:c?(i+o)/2+(r.outlineOffsetX??0):r.outlineOffsetX??0,y:c?(a+s)/2+(r.outlineOffsetY??0):r.outlineOffsetY??0};t.pcb_board.update(this.pcb_board_id,{width:d,height:f,center:m})}doInitialPcbComponentRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this;let i=r.width??0,a=r.height??0;if(r.outline){const c=r.outline.map(E=>E.x),u=r.outline.map(E=>E.y),d=Math.min(...c),f=Math.max(...c),m=Math.min(...u),y=Math.max(...u);i=f-d,a=y-m}const o=t.pcb_board.insert({center:{x:(r.pcbX??0)+(r.outlineOffsetX??0),y:(r.pcbY??0)+(r.outlineOffsetY??0)},thickness:this.boardThickness,num_layers:this.allLayers.length,width:i,height:a,outline:(l=r.outline)==null?void 0:l.map(c=>({x:c.x+(r.outlineOffsetX??0),y:c.y+(r.outlineOffsetY??0)})),material:r.material});this.pcb_board_id=o.pcb_board_id}removePcbComponentRender(){const{db:t}=this.root;this.pcb_board_id&&(t.pcb_board.delete(this.pcb_board_id),this.pcb_board_id=null)}_computePcbGlobalTransformBeforeLayout(){return i1()}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 r=myt(t.toArray());for(const a of r)t.pcb_trace_error.insert(a)}_emitRenderLifecycleEvent(t,r){var i;super._emitRenderLifecycleEvent(t,r),r==="start"&&((i=this.root)==null||i.emit("board:renderPhaseStarted",{renderId:this._renderId,phase:t}))}},pgt=new Proxy({},{get:(n,e)=>e}),zC=pgt,hgt=class extends a2{get config(){return{componentName:"Capacitor",schematicSymbolName:this.props.polarized?"capacitor_polarized":this.props.symbolName??"capacitor",zodProps:Ymt,sourceFtype:zC.simple_capacitor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){const e=`${B3(this._parsedProps.capacitance)}F`;return this._parsedProps.schShowRatings&&this._parsedProps.maxVoltageRating?`${e}/${B3(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 w7({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.decouplingFor})),this.add(new w7({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.decouplingTo}))),this._createTracesFromConnectionsProp()}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=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=r.source_component_id}},J2e=class extends a2{constructor(){super(...arguments);Je(this,"schematicBoxDimensions",null)}get config(){return{componentName:"Chip",zodProps:Gxe,shouldRenderAsSchematicBox:!0}}doInitialSchematicComponentRender(){const{_parsedProps:t}=this;(t==null?void 0:t.noSchematicRepresentation)!==!0&&super.doInitialSchematicComponentRender()}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:r}=this,i=t.source_component.insert({ftype:"simple_chip",name:r.name,manufacturer_part_number:r.manufacturerPartNumber,supplier_part_numbers:r.supplierPartNumbers});this.source_component_id=i.source_component_id}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,i=t.pcb_component.insert({center:{x:r.pcbX??0,y:r.pcbY??0},width:2,height:3,layer:r.layer??"top",rotation:r.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[r,i]of t.externallyConnectedPins)this.add(new w7({from:`${this.getSubcircuitSelector()} > port.${r}`,to:`${this.getSubcircuitSelector()} > port.${i}`}));this._createTracesFromConnectionsProp()}},mgt=class extends a2{constructor(){super(...arguments);Je(this,"pos",this.portMap.pin1);Je(this,"anode",this.portMap.pin1);Je(this,"neg",this.portMap.pin2);Je(this,"cathode",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"diode",componentName:"Diode",zodProps:b1t,sourceFtype:"simple_diode"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:r}=this,i=t.source_component.insert({ftype:"simple_diode",name:r.name,manufacturer_part_number:r.manufacturerPartNumber??r.mfn,supplier_part_numbers:r.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},vgt=class extends a2{constructor(){super(...arguments);Je(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 r=Array.from(new Set(this.props.internallyConnectedPins.flat())).sort().join("");t+=`_bridged${r}`}return{schematicSymbolName:t,componentName:"Jumper",zodProps:Imt,shouldRenderAsSchematicBox:!0}}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:r}=this,i=t.source_component.insert({ftype:"simple_chip",name:r.name,manufacturer_part_number:r.manufacturerPartNumber,supplier_part_numbers:r.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=i.source_component_id}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,i=t.pcb_component.insert({center:{x:r.pcbX??0,y:r.pcbY??0},width:2,height:3,layer:r.layer??"top",rotation:r.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,r=t.pcb_port.list({pcb_component_id:this.pcb_component_id}),i={};for(const s of r){const l=s.source_port_id&&s.source_port_id.match(/(\d+)$/);if(l){const c=(parseInt(l[1],10)+1).toString();i[c]=s.pcb_port_id}}const a=t.pcb_trace.list(),o=s=>{if(s&&typeof s=="string"&&s.startsWith("{PIN")){const l=s.replace("{PIN","").replace("}","");return i[l]||s}return s};for(const s of a)if(s.route)for(const l of s.route)l.route_type==="wire"&&(l.start_pcb_port_id=o(l.start_pcb_port_id),l.end_pcb_port_id=o(l.end_pcb_port_id))}},ygt=class extends a2{constructor(){super(...arguments);Je(this,"pos",this.portMap.pin1);Je(this,"anode",this.portMap.pin1);Je(this,"neg",this.portMap.pin2);Je(this,"cathode",this.portMap.pin2)}get config(){return{componentName:"Led",schematicSymbolName:this.props.symbolName??"led",zodProps:S1t,sourceFtype:"simple_diode"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:r}=this,i=t.source_component.insert({ftype:"simple_diode",name:r.name,manufacturer_part_number:r.manufacturerPartNumber??r.mfn,supplier_part_numbers:r.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},ggt=class extends a2{constructor(){super(...arguments);Je(this,"pos",this.portMap.pin1);Je(this,"positive",this.portMap.pin1);Je(this,"neg",this.portMap.pin2);Je(this,"negative",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"power_factor_meter_horz",componentName:"PowerSource",zodProps:R1t,sourceFtype:"simple_power_source"}}initPorts(){this.add(new K8({name:"pin1",pinNumber:1,aliases:["positive","pos"]})),this.add(new K8({name:"pin2",pinNumber:2,aliases:["negative","neg"]}))}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:r}=this,i=t.source_component.insert({ftype:"simple_power_source",name:r.name,voltage:r.voltage,supplier_part_numbers:r.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},_gt=class extends a2{get config(){return{componentName:"Resistor",schematicSymbolName:this.props.symbolName??"boxresistor",zodProps:Hmt,sourceFtype:"simple_resistor"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${B3(this._parsedProps.resistance)}Ω`}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.pullupFor,this.props.pullupTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.pullupFor&&this.props.pullupTo&&(this.add(new w7({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pullupFor})),this.add(new w7({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pullupTo}))),this._createTracesFromConnectionsProp()}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=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=r.source_component_id}},xgt=["leftedge","rightedge","topedge","bottomedge","center"],bgt=class extends Ig{get config(){return{componentName:"Constraint",zodProps:Kmt}}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 r(i){const a=i.split(" ").pop(),o=xgt.includes(a)?a:void 0,s=o?i.replace(` ${o}`,""):i,l=t.selectOne(s,{pcbPrimitive:!0});l&&e.push({selector:i,component:l,componentSelector:s,edge:o})}for(const i of["left","right","top","bottom"])i in this._parsedProps&&r(this._parsedProps[i]);if("for"in this._parsedProps)for(const i of this._parsedProps.for)r(i);return{componentsWithSelectors:e}}},Sgt=class extends Ig{constructor(){super(...arguments);Je(this,"fabrication_note_path_id",null)}get config(){return{componentName:"FabricationNotePath",zodProps:T1t}}doInitialPcbPrimitiveRender(){var l,c;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,r=this.getSubcircuit(),{_parsedProps:i}=this,a=i.layer??"top";if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenPath. Must be "top" or "bottom".`);const o=this._computePcbGlobalTransformBeforeLayout(),s=t.pcb_fabrication_note_path.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,color:i.color,route:i.route.map(u=>{const d=Cr(o,{x:u.x,y:u.y});return{...u,x:d.x,y:d.y}}),stroke_width:i.strokeWidth??.1,subcircuit_id:(r==null?void 0:r.subcircuit_id)??void 0});this.fabrication_note_path_id=s.pcb_fabrication_note_path_id}},wgt=class extends Ig{get config(){return{componentName:"FabricationNoteText",zodProps:E1t}}doInitialPcbPrimitiveRender(){var a,o;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,r=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:r.pcb_component_id,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((o=this.getGroup())==null?void 0:o.pcb_group_id)??void 0})}},Egt=class extends Vq{constructor(e){super({...e,subcircuit:!0})}},Tgt=class extends Ig{constructor(){super(...arguments);Je(this,"source_net_alias_id")}get config(){return{componentName:"NetAlias",zodProps:f1t}}doInitialSchematicComponentRender(){var o;if((o=this.root)!=null&&o.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,i={x:r.schX??0,y:r.schY??0},a=t.schematic_net_label.insert({text:r.net,source_net_id:r.net,anchor_position:i,center:i,anchor_side:"bottom"});this.source_net_alias_id=a.source_net_id}},Mgt=class extends Ig{constructor(){super(...arguments);Je(this,"pcb_silkscreen_circle_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenCircle",zodProps:U1t}}doInitialPcbPrimitiveRender(){var l,c,u;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(r.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenCircle. Must be "top" or "bottom".`);this._computePcbGlobalTransformBeforeLayout();const o=this.getSubcircuit(),s=t.pcb_silkscreen_circle.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,center:{x:r.pcbX??0,y:r.pcbY??0},radius:r.radius,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,stroke_width:r.strokeWidth??.1});this.pcb_silkscreen_circle_id=s.pcb_silkscreen_circle_id}getPcbSize(){const{_parsedProps:t}=this,r=t.radius*2;return{width:r,height:r}}},Cgt=class extends Ig{constructor(){super(...arguments);Je(this,"pcb_silkscreen_rect_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenRect",zodProps:z1t}}doInitialPcbPrimitiveRender(){var l,c,u;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(r.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenRect. Must be "top" or "bottom".`);const o=this.getSubcircuit(),s=t.pcb_silkscreen_rect.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,center:{x:r.pcbX??0,y:r.pcbY??0},width:r.width,height:r.height,subcircuit_id:(o==null?void 0:o.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:r.strokeWidth??.1});this.pcb_silkscreen_rect_id=s.pcb_silkscreen_rect_id}getPcbSize(){const{_parsedProps:t}=this;return{width:t.width,height:t.height}}},Rgt=class extends Ig{constructor(){super(...arguments);Je(this,"pcb_silkscreen_line_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenLine",zodProps:O1t}}doInitialPcbPrimitiveRender(){var l,c,u;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(r.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenLine. Must be "top" or "bottom".`);const o=this.getSubcircuit(),s=t.pcb_silkscreen_line.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,x1:r.x1,y1:r.y1,x2:r.x2,y2:r.y2,stroke_width:r.strokeWidth??.1,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((u=o==null?void 0:o.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,r=Math.abs(t.x2-t.x1),i=Math.abs(t.y2-t.y1);return{width:r,height:i}}},Agt=class extends Ig{constructor(){super(...arguments);Je(this,"pcb_via_id",null);Je(this,"matchedPort",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Via",zodProps:M1t}}getAvailablePcbLayers(){return["top","inner1","inner2","bottom"]}getPcbSize(){const{_parsedProps:t}=this;return{width:t.outerDiameter,height:t.outerDiameter}}_getPcbCircuitJsonBounds(){const{db:t}=this.root,r=t.pcb_via.get(this.pcb_via_id),i=this.getPcbSize();return{center:{x:r.x,y:r.y},bounds:{left:r.x-i.width/2,top:r.y-i.height/2,right:r.x+i.width/2,bottom:r.y+i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(t){const{db:r}=this.root;r.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:r}=this,i=this._getGlobalPcbPositionBeforeLayout(),a=this.getSubcircuit(),o=t.pcb_via.insert({x:i.x,y:i.y,hole_diameter:r.holeDiameter,outer_diameter:r.outerDiameter,layers:["bottom","top"],from_layer:r.fromLayer||"bottom",to_layer:r.toLayer||"top",subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((l=this.getGroup())==null?void 0:l.pcb_group_id)??void 0});this.pcb_via_id=o.pcb_via_id}},Pgt=class extends a2{get config(){return{componentName:"Battery",schematicSymbolName:this.props.symbolName??"battery",zodProps:u1t,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,r=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=r.source_component_id}},Ngt=class extends a2{get config(){return{componentName:"PinHeader",zodProps:d1t,shouldRenderAsSchematicBox:!0}}_getImpliedFootprintString(){var a;const e=this._parsedProps.pinCount??((a=this._parsedProps.pinLabels)==null?void 0:a.length)??0,t=this._parsedProps.holeDiameter,r=this._parsedProps.platedDiameter,i=this._parsedProps.pitch;return e>0&&i?!t&&!r?`pinrow${e}_p${i}`:`pinrow${e}_p${i}_id${t}_od${r}`:null}initPorts(){var t,r;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 K8({name:`pin${i}`,pinNumber:i,aliases:[(r=this._parsedProps.pinLabels)==null?void 0:r[i-1]].filter(Boolean)}))}_getSchematicPortArrangement(){const e=this._parsedProps.pinCount??1,t=this._parsedProps.facingDirection??"right";return{leftSize:t==="left"?e:0,rightSize:t==="right"?e:0}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=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=r.source_component_id}};function Dgt(n){switch(n){case"two_ground_pins":return"crystal_4pin";case"ground_pin":return"resonator";case"no_ground":return"crystal";default:return"crystal"}}var Lgt=class extends a2{get config(){return{componentName:"Resonator",schematicSymbolName:this.props.symbolName??Dgt(this.props.pinVariant),zodProps:Gmt,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=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:r,are_pins_interchangeable:r==="no_ground"||r==="ground_pin"});this.source_component_id=i.source_component_id}},Ogt=class extends a2{get config(){return{componentName:"Inductor",schematicSymbolName:this.props.symbolName??"inductor",zodProps:v1t,sourceFtype:zC.simple_inductor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=e.source_component.insert({name:t.name,ftype:zC.simple_inductor,inductance:t.inductance,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=r.source_component_id}};function zgt(n){switch(n){case"three_pin":return"potentiometer3";case"two_pin":return"potentiometer2";default:return"potentiometer2"}}var Ugt=class extends a2{get config(){return{componentName:"Potentiometer",schematicSymbolName:this.props.symbolName??zgt(this.props.pinVariant),zodProps:Vmt,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=t.pinVariant||"two_pin",i=e.source_component.insert({ftype:"simple_potentiometer",name:t.name,max_resistance:t.maxResistance,pin_variant:r,are_pins_interchangeable:r==="two_pin"});this.source_component_id=i.source_component_id}},kgt=class extends a2{get config(){return{componentName:"PushButton",schematicSymbolName:this.props.symbolName??"push_button_normally_open_momentary",zodProps:p1t,sourceFtype:zC.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,r=e.source_component.insert({name:t.name,ftype:zC.simple_push_button,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=r.source_component_id}},Igt=class extends a2{get config(){return{schematicSymbolName:this.props.symbolName??(this.props.pinVariant==="four_pin"?"crystal_4pin":"crystal"),componentName:"Crystal",zodProps:$mt,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`${B3(this._parsedProps.frequency)}Hz`}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=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=r.source_component_id}},Fgt=class extends a2{constructor(){super(...arguments);Je(this,"emitter",this.portMap.pin1);Je(this,"collector",this.portMap.pin2);Je(this,"base",this.portMap.pin3)}get config(){return{componentName:"Transistor",schematicSymbolName:this.props.type==="npn"?"npn_bipolar_transistor":"pnp_bipolar_transistor",zodProps:h1t,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:r}=this,i=t.source_component.insert({ftype:"simple_transistor",name:r.name,transistor_type:r.type});this.source_component_id=i.source_component_id}},Bgt=class extends a2{get config(){const e=this.props.mosfetMode==="depletion"?"d":"e";return{componentName:"Mosfet",schematicSymbolName:`${this.props.channelType}_channel_${e}_mosfet_transistor`,zodProps:m1t,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=e.source_component.insert({ftype:"simple_mosfet",name:t.name,mosfet_mode:t.mosfetMode,channel_type:t.channelType});this.source_component_id=r.source_component_id}},jgt=class extends a2{_getSwitchType(){const{spst:e,spdt:t,dpst:r,dpdt:i,type:a}=this._parsedProps??{};return i?"dpdt":e?"spst":t?"spdt":r?"dpst":a??"spst"}get config(){const e=this._getSwitchType(),{isNormallyClosed:t}=this._parsedProps??{};return{componentName:"Switch",schematicSymbolName:{spst:t?"spst_normally_closed_switch":"spst_switch",spdt:t?"spdt_normally_closed_switch":"spdt_switch",dpst:t?"dpst_normally_closed_switch":"dpst_switch",dpdt:t?"dpdt_normally_closed_switch":"dpdt_switch"}[e]??"spst_switch",zodProps:w1t,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=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=r.source_component_id}},Hgt=class extends Ig{constructor(){super(...arguments);Je(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicText",zodProps:N1t}}doInitialSchematicPrimitiveRender(){var i;if((i=this.root)!=null&&i.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this;t.schematic_text.insert({anchor:r.anchor??"center",text:r.text,font_size:r.fontSize,color:r.color||"#000000",position:{x:r.schX,y:r.schY},rotation:r.schRotation??0})}};new Proxy({},{get:(n,e)=>{const t=(...r)=>(r[0],new Proxy({},{get:(i,a)=>`.${e} > .${a}`}));return new Proxy(t,{get:(r,i)=>e==="net"?`net.${i}`:e==="subcircuit"?new Proxy({},{get:(a,o)=>new Proxy({},{get:(s,l)=>`subcircuit.${i} > .${o} > .${l}`})}):`.${e} > .${i}`,apply:(r,i,a)=>new Proxy({},{get:(o,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}`})}})})}}),L2e(N2e),L2e({Bug:J2e});const e5e=r1("run-frame"),Vgt={},t5e=n=>{let e;const t=new Set,r=(u,d)=>{const f=typeof u=="function"?u(e):u;if(!Object.is(f,e)){const m=e;e=d??(typeof f!="object"||f===null)?f:Object.assign({},e,f),t.forEach(y=>y(e,m))}},i=()=>e,l={setState:r,getState:i,getInitialState:()=>c,subscribe:u=>(t.add(u),()=>t.delete(u)),destroy:()=>{(Vgt?"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=n(r,i,l);return l},n5e=n=>n?t5e(n):t5e;var QL={exports:{}},$q={},KL={exports:{}},Gq={};/**
830
+ searched component ${u.getString()}, which has ports: ${u.children.filter(d=>d.componentName==="Port").map(d=>`${d.getString()}(${d.getNameAndAliases().join(",")})`).join(" & ")}`):this.renderError(`Could not find port for selector "${s}"`)}return o.some(s=>!s.port)?{allPortsFound:!1}:{allPortsFound:!0,portsWithSelectors:o,ports:o.map(({port:s})=>s)}}_findConnectedNets(){const t=this.getTracePathNetSelectors().map(i=>({selector:i,net:this.getSubcircuit().selectOne(i,{type:"net"})})),r=t.filter(i=>!i.net);return r.length>0&&this.renderError(`Could not find net for selector "${r[0].selector}" inside ${this}`),{netsWithSelectors:t,nets:t.map(i=>i.net)}}_getAllTracesConnectedToSameNet(){const t=this.getSubcircuit().selectAll("trace"),r=this._findConnectedNets().nets,i=this._findConnectedPorts().ports??[];return t.filter(a=>{if(a===this)return!1;const o=a._findConnectedNets().nets,s=a._findConnectedPorts().ports??[];return o.some(l=>r.includes(l))||s.some(l=>i.includes(l))})}_isExplicitlyConnectedToPort(t){const{allPortsFound:r,portsWithSelectors:i}=this._findConnectedPorts();return r?i.map(o=>o.port).includes(t):!1}_isExplicitlyConnectedToNet(t){return this._findConnectedNets().nets.includes(t)}doInitialCreateNetsFromProps(){F2e(this,this.getTracePathNetSelectors())}_computeTraceConnectionHash(){const{allPortsFound:t,ports:r}=this._findConnectedPorts();return!t||!r?null:[...r].sort((o,s)=>(o.pcb_port_id||"").localeCompare(s.pcb_port_id||"")).map(o=>o.pcb_port_id).join(",")}doInitialSourceTraceRender(){var f;const{db:t}=this.root,{_parsedProps:r,parent:i}=this;if(!i){this.renderError("Trace has no parent");return}const{allPortsFound:a,portsWithSelectors:o}=this._findConnectedPorts();if(!a)return;this._traceConnectionHash=this._computeTraceConnectionHash();const l=t.source_trace.list().find(m=>m.subcircuit_connectivity_map_key===this.subcircuit_connectivity_map_key&&m.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=rgt({ports:o,nets:c}),d=t.source_trace.insert({connected_source_port_ids:o.map(m=>m.port.source_port_id),connected_source_net_ids:c.map(m=>m.source_net_id),subcircuit_id:(f=this.getSubcircuit())==null?void 0:f.subcircuit_id,max_length:Jyt(o.map(m=>m.port),{db:t})??r.maxLength,display_name:u,min_trace_thickness:r.thickness});this.source_trace_id=d.source_trace_id}_insertErrorIfTraceIsOutsideBoard(t,r){const{db:i}=this.root;agt(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:r.map(o=>o.pcb_port_id)})}doInitialPcbTraceRender(){var Q,X,ue,pe;if((Q=this.root)!=null&&Q.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r,parent:i}=this,a=this.getSubcircuit();if(!i)throw new Error("Trace has no parent");if(a._parsedProps.routingDisabled)return;const o=(X=a._parsedProps.pcbRouteCache)==null?void 0:X.pcbTraces;if(o){const ce=t.pcb_trace.insert({route:o.flatMap(Se=>Se.route),source_trace_id:this.source_trace_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((ue=this.getGroup())==null?void 0:ue.pcb_group_id)??void 0});this.pcb_trace_id=ce.pcb_trace_id;return}if(!a._shouldUseTraceByTraceRouting())return;const{allPortsFound:s,ports:l}=this._findConnectedPorts();if(!s)return;const c=[];for(const ce of l)ce._hasMatchedPcbPrimitive()||c.push(ce);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(ce=>ce.getString()).join(", ")}`,pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[],pcb_port_ids:c.map(ce=>ce.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 ce=l[0],he=u[0].net.getAllConnectedPorts().filter(Te=>Te!==ce);if(he.length===0){console.log("Nothing to connect this port to, the net is empty. TODO should emit a warning!");return}const ge=Gyt(ce,he);l.push(ge)}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 d=l.flatMap(ce=>ce.matchedComponents.filter(Se=>Se.componentName==="TraceHint")),f=(this._parsedProps.pcbRouteHints??[]).concat(d.flatMap(ce=>ce.getPcbRouteHints()));if(l.length>2){this.renderError(`Trace has more than two ports (${l.map(ce=>ce.getString()).join(", ")}), routing between more than two ports for a single trace is not implemented`);return}if(this.getSubcircuit().selectAll("trace").filter(ce=>ce.renderPhaseStates.PcbTraceRender.initialized).some(ce=>ce._portsRoutedOnPcb.length===l.length&&ce._portsRoutedOnPcb.every(Se=>l.includes(Se))))return;let E=[];f.length===0?E=[ZL(l[0]),ZL(l[1])]:E=[ZL(l[0]),...f,ZL(l[1])];const w=XL(E),S=W8(this.root.db.toArray()),[T,P]=Yyt(()=>PE(this.root.db.toArray()));if(P){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: ${P.message}`,source_trace_id:this.source_trace_id,center:{x:0,y:0},pcb_port_ids:l.map(ce=>ce.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[]});return}for(const ce of T)if(ce.connectedTo.length>0){const he=S.getNetConnectedToId(ce.connectedTo[0]);he&&ce.connectedTo.push(he)}let U=[];if(w.length===0)U=E;else{const ce=w[0].layer_path;U=E.map((Se,he)=>Se.via?{...Se,via_to_layer:ce[he]}:{...Se,layers:[ce[he]]})}U[0].pcb_port_id=l[0].pcb_port_id,U[U.length-1].pcb_port_id=l[1].pcb_port_id;const H=[];for(const[ce,Se]of k2e(U)){const he="via_to_layer"in ce?ce.via_to_layer:null,ge=2,Te="layers"in ce&&ce.layers.length===1?ce.layers[0]:he??"top",xe="layers"in Se&&Se.layers.length===1?Se.layers[0]:he??"top",Ae="pcb_port_id"in ce?ce.pcb_port_id:null,Ne="pcb_port_id"in Se?Se.pcb_port_id:null,ze=this.getSubcircuit()._parsedProps.minTraceWidth??.16,Re=new AE({OBSTACLE_MARGIN:ze*2,isRemovePathLoopsEnabled:!0,optimizeWithGoalBoxes:!!(Ae&&Ne),connMap:S,input:{obstacles:T,minTraceWidth:ze,connections:[{name:this.source_trace_id,pointsToConnect:[{...ce,layer:Te,pcb_port_id:Ae},{...Se,layer:xe,pcb_port_id:Ne}]}],layerCount:2,bounds:{minX:Math.min(ce.x,Se.x)-ge,maxX:Math.max(ce.x,Se.x)+ge,minY:Math.min(ce.y,Se.y)-ge,maxY:Math.max(ce.y,Se.y)+ge}}});let qe=null;try{qe=Re.solveAndMapToTraces()}catch(pt){this.renderError({type:"pcb_trace_error",pcb_trace_error_id:this.source_trace_id,error_type:"pcb_trace_error",message:`error solving route: ${pt.message}`,source_trace_id:this.pcb_trace_id,center:{x:(ce.x+Se.x)/2,y:(ce.y+Se.y)/2},pcb_port_ids:l.map(Tt=>Tt.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:l.map(Tt=>Tt.pcb_component_id)})}if(!qe)return;if(qe.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:(ce.x+Se.x)/2,y:(ce.y+Se.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)});return}const[Ke]=qe;he&&(Ke.route=Ke.route.map(pt=>(pt.route_type==="wire"&&!pt.layer&&(pt.layer=he),pt))),Ae&&Ke.route[0].route_type==="wire"&&(Ke.route[0].start_pcb_port_id=Ae);const ut=Ke.route[Ke.route.length-1];Ne&&ut.route_type==="wire"&&(ut.end_pcb_port_id=Ne),H.push(Ke.route)}const G=Vyt(H),W=Xyt(G),$=t.pcb_trace.insert({route:G,source_trace_id:this.source_trace_id,subcircuit_id:(pe=this.getSubcircuit())==null?void 0:pe.subcircuit_id,trace_length:W});this._portsRoutedOnPcb=l,this.pcb_trace_id=$.pcb_trace_id;for(const ce of G)ce.route_type==="via"&&t.pcb_via.insert({pcb_trace_id:$.pcb_trace_id,x:ce.x,y:ce.y,hole_diameter:.3,outer_diameter:.6,layers:[ce.from_layer,ce.to_layer],from_layer:ce.from_layer,to_layer:ce.to_layer});this._insertErrorIfTraceIsOutsideBoard(G,l)}_doInitialSchematicTraceRenderWithDisplayLabel(){var H,G,W,$;if((H=this.root)!=null&&H.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:r,parent:i}=this;if(!i)throw new Error("Trace has no parent");const{allPortsFound:a,portsWithSelectors:o}=this._findConnectedPorts();if(!a)return;const s=o.map(({port:Q})=>({port:Q,position:Q._getGlobalSchematicPositionAfterLayout(),schematic_port_id:Q.schematic_port_id,facingDirection:Q.facingDirection}));if(s.length<2)throw new Error("Expected at least two ports in portsWithPosition.");let l,c;const u=s[0].position,d=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(!d.source_port_id)throw new Error(`Missing source_port_id for the 'from' port (${l}).`);const f=s[1].position,m=s[1].port;if(!m.source_port_id)throw new Error(`Missing source_port_id for the 'to' port (${c}).`);const y=t.schematic_net_label.list().find(Q=>Q.source_net_id===d.source_port_id),E=t.schematic_net_label.list().find(Q=>Q.source_net_id===m.source_port_id),[w,S]=o.map(({port:Q})=>Q),P=((G=w.parent)==null?void 0:G.config.shouldRenderAsSchematicBox)?`${(W=w==null?void 0:w.parent)==null?void 0:W.props.name}_${w==null?void 0:w.props.name}`:`${($=S==null?void 0:S.parent)==null?void 0:$.props.name}_${S==null?void 0:S.props.name}`,U=this.props.schDisplayLabel??P;if(y&&y.text!==U&&(y.text=`${U} / ${y.text}`),E&&(E==null?void 0:E.text)!==U&&(E.text=`${U} / ${E.text}`),U!=null&&U.toLocaleLowerCase().includes("gnd")||U!=null&&U.toLocaleLowerCase().includes("ground")){!y&&!E?(WL({port:d,anchorPos:u,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t}),WL({port:m,anchorPos:f,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t})):y?E||WL({port:m,anchorPos:f,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t}):WL({port:d,anchorPos:u,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t});return}E||t.schematic_net_label.insert({text:this.props.schDisplayLabel??P,source_net_id:m.source_port_id,anchor_position:f,center:f,anchor_side:Bq(m.facingDirection)??"bottom"}),y||t.schematic_net_label.insert({text:this.props.schDisplayLabel??P,source_net_id:d.source_port_id,anchor_position:u,center:u,anchor_side:Bq(d.facingDirection)??"bottom"})}_isSymbolToChipConnection(){const{allPortsFound:t,ports:r}=this._findConnectedPorts();if(!t||r.length!==2)return!1;const[i,a]=r;if(!(i!=null&&i.parent)||!(a!=null&&a.parent))return!1;const o=i.parent.config.shouldRenderAsSchematicBox,s=a.parent.config.shouldRenderAsSchematicBox;return o&&!s||!o&&s}_isSymbolToSymbolConnection(){const{allPortsFound:t,ports:r}=this._findConnectedPorts();if(!t||r.length!==2)return!1;const[i,a]=r;if(!(i!=null&&i.parent)||!(a!=null&&a.parent))return!1;const o=!i.parent.config.shouldRenderAsSchematicBox,s=!a.parent.config.shouldRenderAsSchematicBox;return o&&s}_isChipToChipConnection(){const{allPortsFound:t,ports:r}=this._findConnectedPorts();if(!t||r.length!==2)return!1;const[i,a]=r;if(!(i!=null&&i.parent)||!(a!=null&&a.parent))return!1;const o=i.parent.config.shouldRenderAsSchematicBox,s=a.parent.config.shouldRenderAsSchematicBox;return o&&s}doInitialSchematicTraceRender(){var Te,xe;if((Te=this.root)!=null&&Te.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:r,parent:i}=this;if(!i)throw new Error("Trace has no parent");const{allPortsFound:a,portsWithSelectors:o}=this._findConnectedPorts(),{netsWithSelectors:s}=this._findConnectedNets();if(!a)return;const c=o.map(Ae=>Ae.port.schematic_port_id).sort().join(","),u=(xe=this.root)==null?void 0:xe._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 d={name:this.source_trace_id,pointsToConnect:[]},f=ngt(this),m=o.map(({port:Ae})=>({port:Ae,position:Ae._getGlobalSchematicPositionAfterLayout(),schematic_port_id:Ae.schematic_port_id??void 0,facingDirection:Ae.facingDirection}));if(m.length===1&&s.length===1){const Ae=s[0].net,{port:Ne,position:ze}=m[0];t.schematic_net_label.insert({text:Ae._parsedProps.name,source_net_id:Ae.source_net_id,anchor_position:ze,center:ze,anchor_side:Bq(Ne.facingDirection)??"bottom"});return}if(m.length<2)return;d.pointsToConnect=m.map(({position:Ae})=>({...Ae,layer:"top"}));const E=Hyt(f),w=2,S={minTraceWidth:.1,obstacles:f,connections:[d],bounds:{minX:E.minX-w,maxX:E.maxX+w,minY:E.minY-w,maxY:E.maxY+w},layerCount:1};let T=AE,P=!1;this.getSubcircuit().props._schDirectLineRoutingEnabled&&(T=Y2e,P=!0);let H=new T({input:S,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(H.length===0){if(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection()){this._doInitialSchematicTraceRenderWithDisplayLabel();return}H=new Y2e({input:S}).solveAndMapToTraces(),P=!0}const[{route:G}]=H;let W=[];for(let Ae=0;Ae<G.length-1;Ae++)W.push({from:G[Ae],to:G[Ae+1]});const $=this.source_trace_id;let Q=[];if(!P){igt({edges:W,db:t,source_trace_id:$});const Ae=Hq({db:t,source_trace_id:$,differentNetOnly:!0}).flatMap(Ne=>Ne.edges);W=Zyt({edges:W,otherEdges:Ae}),Q=Kyt({edges:W,db:t,source_trace_id:this.source_trace_id})}const X=W[W.length-1],ue=m[m.length-1],pe=W2e(X);W.push(...jq({lastEdge:X,lastEdgePort:ue,lastDominantDirection:pe}));const ce=W[0],Se=m[0],he=W2e(ce);if(W.unshift(...jq({firstEdge:ce,firstEdgePort:Se,firstDominantDirection:he})),!this.source_trace_id)throw new Error("Missing source_trace_id for schematic trace insertion.");if(this.getSubcircuit()._parsedProps.schTraceAutoLabelEnabled&&qyt(Q,W)>=5&&(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection())){this._doInitialSchematicTraceRenderWithDisplayLabel();return}const ge=t.schematic_trace.insert({source_trace_id:this.source_trace_id,edges:W,junctions:Q});this.schematic_trace_id=ge.schematic_trace_id,u!=null&&u._connectedSchematicPortPairs&&u._connectedSchematicPortPairs.add(c)}},ogt=r1("tscircuit:core"),sgt=b.object({x:d4,y:d4,z:d4}),a2=class extends Ig{constructor(t){super(t);Je(this,"reactSubtrees",[]);Je(this,"_impliedFootprint");Je(this,"isPrimitiveContainer",!0);Je(this,"_asyncSupplierPartNumbers");Je(this,"pcb_missing_footprint_error_id");this._addChildrenFromStringFootprint(),this.initPorts()}get defaultInternallyConnectedPinNames(){return[]}get internallyConnectedPinNames(){return this._parsedProps.internallyConnectedPins??this.defaultInternallyConnectedPinNames}initPorts(t={}){var s,l,c,u,d,f,m,y,E,w;if((s=this.root)!=null&&s.schematicDisabled)return;const{config:r}=this,i=[],a=this._getSchematicPortArrangement();if(a&&!this._parsedProps.pinLabels){for(const P in a){const U=a[P].pins;if(Array.isArray(U))for(const H of U){const G=LC(H,this._parsedProps.pinLabels);i.push(new K8({pinNumber:G,aliases:((l=t.additionalAliases)==null?void 0:l[`pin${G}`])??[]},{originDescription:`schPortArrangement:${P}`}))}}const S=["left","right","top","bottom"];let T=1;for(const P of S){const U=a[`${P}Size`];for(let H=0;H<U;H++)i.push(new K8({pinNumber:T++,aliases:((c=t.additionalAliases)==null?void 0:c[`pin${T}`])??[]},{originDescription:`schPortArrangement:${P}`}))}}const o=this._parsedProps.pinLabels;if(o)for(let[S,T]of Object.entries(o)){S=S.replace("pin","");let P=i.find(G=>G._parsedProps.pinNumber===Number(S));const U=Array.isArray(T)?T[0]:T,H=Array.isArray(T)?T.slice(1):[];P?(P.externallyAddedAliases.push(U,...H),P.props.name=U):(P=new K8({pinNumber:parseInt(S),name:U,aliases:[...H,...((u=t.additionalAliases)==null?void 0:u[`pin${parseInt(S)}`])??[]]},{originDescription:`pinLabels:pin${S}`}),i.push(P))}if(r.schematicSymbolName){const S=Hb[this._getSchematicSymbolNameOrThrow()];if(!S)return;for(const T of S.ports){const P=G2e(T.labels);if(!P)continue;const U=i.find(H=>H._parsedProps.pinNumber===Number(P));if(U)U.schematicSymbolPortDef=T;else{const H=OC(T.labels.concat(((d=t.additionalAliases)==null?void 0:d[`pin${P}`])??[]));H&&(H.originDescription=`schematicSymbol:labels[0]:${T.labels[0]}`,H.schematicSymbolPortDef=T,i.push(H))}}this.addAll(i)}if(!this._getSchematicPortArrangement()){const S=this.getPortsFromFootprint(t);for(const T of S)i.some(P=>P.isMatchingAnyOf(T.getNameAndAliases()))||i.push(T)}for(let S=1;S<=(t.pinCount??this._getPinCount());S++){if(!a||i.find(P=>P._parsedProps.pinNumber===S))continue;let T=[...((f=a.leftSide)==null?void 0:f.pins)??[],...((m=a.rightSide)==null?void 0:m.pins)??[],...((y=a.topSide)==null?void 0:y.pins)??[],...((E=a.bottomSide)==null?void 0:E.pins)??[]].map(P=>LC(P,this._parsedProps.pinLabels));["leftSize","rightSize","topSize","bottomSize","leftPinCount","rightPinCount","topPinCount","bottomPinCount"].some(P=>P in a)&&(T=Array.from({length:this._getPinCount()},(P,U)=>U+1)),T.includes(S)&&i.push(new K8({pinNumber:S,aliases:((w=t.additionalAliases)==null?void 0:w[`pin${S}`])??[]},{originDescription:`notOtherwiseAddedButDeducedFromPinCount:${S}`}))}i.length>0&&this.addAll(i)}_getImpliedFootprintString(){return null}_addChildrenFromStringFootprint(){var o;const{name:t,pcbRotation:r,pinLabels:i}=this.props;let{footprint:a}=this.props;if(a??(a=(o=this._getImpliedFootprintString)==null?void 0:o.call(this)),!!a&&typeof a=="string"){const s=bE.string(a).soup(),l=Nyt({componentName:t,componentRotation:r,footprint:a,pinLabels:i},s);this.addAll(l)}}get portMap(){return new Proxy({},{get:(t,r)=>{const i=this.children.find(a=>a.componentName==="Port"&&a.isMatchingNameOrAlias(r));if(!i)throw new Error(`There was an issue finding the port "${r.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 r of this.reactSubtrees)if(r.element===t)return r.component;return null}doInitialSourceRender(){const t=this.config.sourceFtype;if(!t)return;const{db:r}=this.root,{_parsedProps:i}=this,a=r.source_component.insert({ftype:t,name:i.name,manufacturer_part_number:i.manufacturerPartNumber??i.mfn,supplier_part_numbers:i.supplierPartNumbers});this.source_component_id=a.source_component_id}doInitialSchematicComponentRender(){var a,o,s;if((a=this.root)!=null&&a.schematicDisabled)return;const{db:t}=this.root,{schematicSymbolName:r}=this.config;r?this._doInitialSchematicComponentRenderWithSymbol():this._getSchematicBoxDimensions()&&this._doInitialSchematicComponentRenderWithSchematicBoxDimensions();const i=(o=this.getSubcircuit())==null?void 0:o._getSchematicManualPlacementForComponent(this);if(this.schematic_component_id&&(this.props.schX!==void 0||this.props.schY!==void 0)&&i){if(!this.schematic_component_id)return;const l=d$.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 r of this.internallyConnectedPinNames){const i=[];for(const a of r)i.push(this.portMap[a]);t.push(i)}return t}_doInitialSchematicComponentRenderWithSymbol(){var s;if((s=this.root)!=null&&s.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,i=this._getSchematicSymbolNameOrThrow(),a=Hb[i],o=this._getGlobalSchematicPositionBeforeLayout();if(a){const l=t.schematic_component.insert({center:o,size:a.size,source_component_id:this.source_component_id,symbol_name:i,symbol_display_value:this._getSchematicSymbolDisplayValue()});this.schematic_component_id=l.schematic_component_id}}_doInitialSchematicComponentRenderWithSchematicBoxDimensions(){var f;if((f=this.root)!=null&&f.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,i=this._getSchematicBoxDimensions(),a={};if(Array.isArray(r.pinLabels))r.pinLabels.forEach((m,y)=>{a[String(y+1)]=m});else for(const[m,y]of Object.entries(r.pinLabels??{}))a[m]=Array.isArray(y)?y[0]:y;const o=this._getGlobalSchematicPositionBeforeLayout(),s=this._getSchematicPortArrangement(),l=t.schematic_component.insert({center:o,rotation:r.schRotation??0,size:i.getSize(),port_arrangement:Cyt(s),pin_spacing:r.schPinSpacing??.2,pin_styles:Myt(r.schPinStyle,r.pinLabels),port_labels:a,source_component_id:this.source_component_id}),c=(s==null?void 0:s.topSide)!==void 0||(s==null?void 0:s.bottomSide)!==void 0,u=i==null?void 0:i.getSize().width,d=i==null?void 0:i.getSize().height;t.schematic_text.insert({text:r.manufacturerPartNumber??"",schematic_component_id:l.schematic_component_id,anchor:"left",rotation:0,position:{x:c?o.x+(u??0)/2+.1:o.x-(u??0)/2,y:c?o.y+(d??0)/2+.35:o.y-(d??0)/2-.13},color:"#006464",font_size:.05}),t.schematic_text.insert({text:r.name??"",schematic_component_id:l.schematic_component_id,anchor:"left",rotation:0,position:{x:c?o.x+(u??0)/2+.1:o.x-(u??0)/2,y:c?o.y+(d??0)/2+.55:o.y+(d??0)/2+.13},color:"#006464",font_size:.05}),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:r}=this,i=this.getSubcircuit(),a=t.pcb_component.insert({center:this._getGlobalPcbPositionBeforeLayout(),width:0,height:0,layer:r.layer??"top",rotation:r.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:i.subcircuit_id??void 0});if(!r.footprint&&!this.isGroup){const l=t.pcb_missing_footprint_error.insert({message:`No footprint found for component: ${this.getString()}`,source_component_id:`${this.source_component_id}`,error_type:"pcb_missing_footprint_error"});this.pcb_missing_footprint_error_id=l.pcb_missing_footprint_error_id}this.pcb_component_id=a.pcb_component_id;const o=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if((this.props.pcbX!==void 0||this.props.pcbY!==void 0)&&o){const l=h$.parse({type:"pcb_manual_edit_conflict_warning",pcb_manual_edit_conflict_warning_id:`pcb_manual_edit_conflict_${this.source_component_id}`,message:`${this.getString()} has both manual placement and prop coordinates. pcbX and pcbY will be used. Remove pcbX/pcbY or clear the manual placement.`,pcb_component_id:this.pcb_component_id,source_component_id:this.source_component_id,subcircuit_id:i.subcircuit_id??void 0});t.pcb_manual_edit_conflict_warning.insert(l)}}doInitialPcbComponentSizeCalculation(){var o;if((o=this.root)!=null&&o.pcbDisabled||!this.pcb_component_id)return;const{db:t}=this.root,{_parsedProps:r}=this,i=$2e(this.children);if(i.width===0||i.height===0)return;const a={x:(i.minX+i.maxX)/2,y:(i.minY+i.maxY)/2};t.pcb_component.update(this.pcb_component_id,{center:a,width:i.width,height:i.height})}_renderReactSubtree(t){return{element:t,component:Tyt(t)}}doInitialInitializePortsFromChildren(){this.initPorts()}doInitialReactSubtreesRender(){if(rt.isValidElement(this.props.footprint)){if(this.reactSubtrees.some(r=>r.element===this.props.footprint))return;const t=this._renderReactSubtree(this.props.footprint);this.reactSubtrees.push(t),this.add(t.component)}}_hasExistingPortExactly(t){return this.children.filter(i=>i.componentName==="Port").some(i=>{const a=t.getNameAndAliases(),o=i.getNameAndAliases();return a.length===o.length&&a.every(s=>o.includes(s))})}add(t){let r;if(rt.isValidElement(t)){const i=this._renderReactSubtree(t);this.reactSubtrees.push(i),r=i.component}else r=t;if(r.componentName==="Port"){if(this._hasExistingPortExactly(r))return;const a=this.children.filter(o=>o.componentName==="Port").find(o=>o.isMatchingAnyOf(r.getNameAndAliases()));a&&ogt(`Similar ports added. Port 1: ${a}, Port 2: ${r}`)}super.add(r)}getPortsFromFootprint(t){let{footprint:r}=this.props;if((!r||rt.isValidElement(r))&&(r=this.children.find(a=>a.componentName==="Footprint")),typeof r=="string"){const a=bE.string(r).soup(),o=[];for(const s of a)if("port_hints"in s&&s.port_hints){const l=OC(s.port_hints,t);if(!l)continue;l.originDescription=`footprint:string:${r}:port_hints[0]:${s.port_hints[0]}`,o.push(l)}return o}if(!rt.isValidElement(r)&&r&&r.componentName==="Footprint"){const a=r;let o=1;const s=[];for(const l of a.children){if(!l.props.portHints)continue;let c=l.props.portHints;c.some(f=>f.startsWith("pin"))||(c=[...c,`pin${o}`]),o++;const d=OC(c);d&&(d.originDescription=`footprint:${r}`,s.push(d))}return s}const i=[];if(!r){for(const a of this.children)if(a.props.portHints&&a.isPcbPrimitive){const o=OC(a.props.portHints);o&&i.push(o)}}return i}getPortsFromSchematicSymbol(){var a;if((a=this.root)!=null&&a.schematicDisabled)return[];const{config:t}=this;if(!t.schematicSymbolName)return[];const r=Hb[t.schematicSymbolName];if(!r)return[];const i=[];for(const o of r.ports){const s=OC(o.labels);s&&(s.schematicSymbolPortDef=o,i.push(s))}return i}doInitialCreateNetsFromProps(){this._createNetsFromProps(this._getNetsFromConnectionsProp())}_getNetsFromConnectionsProp(){const{_parsedProps:t}=this,r=[];if(t.connections)for(const[i,a]of Object.entries(t.connections)){const o=Array.isArray(a)?a:[a];for(const s of o)r.push(s)}return r}_createNetsFromProps(t){F2e(this,t)}_getPcbCircuitJsonBounds(){const{db:t}=this.root;if(!this.pcb_component_id)return super._getPcbCircuitJsonBounds();const r=t.pcb_component.get(this.pcb_component_id);return{center:{x:r.center.x,y:r.center.y},bounds:{left:r.center.x-r.width/2,top:r.center.y-r.height/2,right:r.center.x+r.width/2,bottom:r.center.y+r.height/2},width:r.width,height:r.height}}_getPinCountFromSchematicPortArrangement(){const t=this._getSchematicPortArrangement();if(!t)return 0;if(!q2e(t))return(t.leftSize??t.leftPinCount??0)+(t.rightSize??t.rightPinCount??0)+(t.topSize??t.topPinCount??0)+(t.bottomSize??t.bottomPinCount??0);const{leftSide:i,rightSide:a,topSide:o,bottomSide:s}=t;return Math.max(...(i==null?void 0:i.pins)??[],...(a==null?void 0:a.pins)??[],...(o==null?void 0:o.pins)??[],...(s==null?void 0:s.pins)??[])}_getPinCount(){return this._getSchematicPortArrangement()?this._getPinCountFromSchematicPortArrangement():this.getPortsFromFootprint().length}_getSchematicPortArrangement(){return this._parsedProps.schPinArrangement??this._parsedProps.schPortArrangement}_getSchematicBoxDimensions(){if(this.getSchematicSymbol()||!this.config.shouldRenderAsSchematicBox)return null;const{_parsedProps:t}=this,r=this._getPinCount(),i=t.schPinSpacing??.2;return Iyt({schWidth:t.schWidth,schHeight:t.schHeight,schPinSpacing:i,numericSchPinStyle:jyt(t.schPinStyle,t.pinLabels),pinCount:r,schPortArrangement:this._getSchematicPortArrangement(),pinLabels:t.pinLabels})}doInitialCadModelRender(){var u;const{db:t}=this.root,{boardThickness:r=0}=((u=this.root)==null?void 0:u._getBoard())??{},i=this._parsedProps.cadModel;if(!this.pcb_component_id||!i&&!this.props.footprint)return;const a=this._getPcbCircuitJsonBounds(),o=t.pcb_component.get(this.pcb_component_id);if(typeof i=="string")throw new Error("String cadModel not yet implemented");const s=sgt.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=gE.parse({x:0,y:0,z:0,...typeof(i==null?void 0:i.positionOffset)=="object"?i.positionOffset:{}}),c=this.props.layer==="bottom"?"bottom":"top";t.cad_component.insert({position:{x:a.center.x+l.x,y:a.center.y+l.y,z:(c==="bottom"?-r/2:r/2)+l.z},rotation:{x:s.x,y:(c==="top"?0:180)+s.y,z:((o==null?void 0:o.rotation)??0)+(c==="bottom"?180: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 r=((i=this.root)==null?void 0:i.getClientOrigin())??"";return`${t}${t.includes("?")?"&":"?"}cachebust_origin=${encodeURIComponent(r)}`}doInitialPartsEngineRender(){const t=this.getInheritedProperty("partsEngine");if(!t)return;const{db:r}=this.root,i=r.source_component.get(this.source_component_id);if(!i||i.supplier_part_numbers)return;let a;this.props.footprint&&typeof this.props.footprint=="string"&&(a=this.props.footprint);const o=t.findPart({sourceComponent:i,footprinterString:a});if(!(o instanceof Promise)){r.source_component.update(this.source_component_id,{supplier_part_numbers:o});return}this._queueAsyncEffect("get-supplier-part-numbers",async()=>{this._asyncSupplierPartNumbers=await o,this._markDirty("PartsEngineRender")})}updatePartsEngineRender(){const{db:t}=this.root,r=t.source_component.get(this.source_component_id);if(r&&!r.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[r,i]of Object.entries(t.connections)){const a=Array.isArray(i)?i:[i];for(const o of a)this.add(new w7({from:`${this.getSubcircuitSelector()} > port.${r}`,to:o}))}}},lgt=class{constructor(e,t={}){Je(this,"input");Je(this,"isRouting",!1);Je(this,"solver");Je(this,"eventHandlers",{complete:[],error:[],progress:[]});Je(this,"cycleCount",0);Je(this,"stepDelay");Je(this,"timeoutId");this.input=e;const{capacityDepth:r,targetMinCapacity:i,stepDelay:a=0}=t;this.solver=new Cq(e,{capacityDepth:r,targetMinCapacity:i}),this.stepDelay=a}start(){this.isRouting||(this.isRouting=!0,this.cycleCount=0,this.runCycleAndQueueNextCycle())}runCycleAndQueueNextCycle(){var e;if(this.isRouting)try{if(this.solver.solved||this.solver.failed){this.solver.failed?this.emitEvent({type:"error",error:new Error(this.solver.error||"Routing failed")}):this.emitEvent({type:"complete",traces:this.solver.getOutputSimpleRouteJson().traces||[]}),this.isRouting=!1;return}const t=Date.now(),r=this.solver.iterations;for(;Date.now()-t<250&&!this.solver.failed&&!this.solver.solved;)this.solver.step();const i=(this.solver.iterations-r)/(Date.now()-t)*1e3;this.cycleCount++;const a=((e=this.solver)==null?void 0:e.preview())||void 0,o=this.solver.progress;this.emitEvent({type:"progress",steps:this.cycleCount,iterationsPerSecond:i,progress:o,phase:this.solver.getCurrentPhase(),debugGraphics:a}),this.stepDelay>0?this.timeoutId=setTimeout(()=>this.runCycleAndQueueNextCycle(),this.stepDelay):this.timeoutId=setTimeout(()=>this.runCycleAndQueueNextCycle(),0)}catch(t){this.emitEvent({type:"error",error:t instanceof Error?t:new Error(String(t))}),this.isRouting=!1}}stop(){this.isRouting&&(this.isRouting=!1,this.timeoutId!==void 0&&(clearTimeout(this.timeoutId),this.timeoutId=void 0))}on(e,t){e==="complete"?this.eventHandlers.complete.push(t):e==="error"?this.eventHandlers.error.push(t):e==="progress"&&this.eventHandlers.progress.push(t)}emitEvent(e){if(e.type==="complete")for(const t of this.eventHandlers.complete)t(e);else if(e.type==="error")for(const t of this.eventHandlers.error)t(e);else if(e.type==="progress")for(const t of this.eventHandlers.progress)t(e)}solveSync(){if(this.solver.solve(),this.solver.failed)throw new Error(this.solver.error||"Routing failed");return this.solver.getOutputSimpleRouteJson().traces||[]}},Z2e=class extends Ig{constructor(){super(...arguments);Je(this,"matchedPort",null)}get config(){return{componentName:"TraceHint",zodProps:k1t}}doInitialPortMatching(){const{db:t}=this.root,{_parsedProps:r,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(!r.for){this.renderError(`TraceHint has no for property (${this})`);return}const a=i.selectOne(r.for,{type:"port"});a||this.renderError(`${this} could not find port for selector "${r.for}"`),this.matchedPort=a,a.registerMatch(this)}getPcbRouteHints(){const{_parsedProps:t}=this,r=t.offset?[t.offset]:t.offsets;if(!r)return[];const i=this._computePcbGlobalTransformBeforeLayout();return r.map(a=>({...Cr(i,a),via:a.via,to_layer:a.to_layer,trace_width:a.trace_width}))}doInitialPcbTraceHintRender(){var i,a,o;if((i=this.root)!=null&&i.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this;t.pcb_trace_hint.insert({pcb_component_id:(a=this.matchedPort)==null?void 0:a.pcb_component_id,pcb_port_id:(o=this.matchedPort)==null?void 0:o.pcb_port_id,route:this.getPcbRouteHints()})}},cgt=({circuitJson:n,editEvents:e,manualEditsFile:t})=>{var i;const r={...t,pcb_placements:[...t.pcb_placements??[]]};for(const a of e)if(a.edit_event_type==="edit_pcb_component_location"){const{pcb_component_id:o,new_center:s}=a,l=m3(n).pcb_component.get(o);if(!l)continue;const c=m3(n).source_component.get(l.source_component_id);if(!c)continue;const u=(i=r.pcb_placements)==null?void 0:i.findIndex(f=>f.selector===c.name),d={selector:c.name,center:s,relative_to:"group_center"};u>=0?r.pcb_placements[u]=d:r.pcb_placements.push(d)}return r},ugt=({circuitJson:n,editEvents:e,manualEditsFile:t})=>{var i;const r={...t,schematic_placements:[...t.schematic_placements??[]]};for(const a of e)if(a.edit_event_type==="edit_schematic_component_location"){const{schematic_component_id:o,new_center:s}=a,l=m3(n).schematic_component.get(o);if(!l)continue;const c=m3(n).source_component.get(l.source_component_id);if(!c)continue;const u=(i=r.schematic_placements)==null?void 0:i.findIndex(f=>f.selector===c.name),d={selector:c.name,center:s,relative_to:"group_center"};u>=0?r.schematic_placements[u]=d:r.schematic_placements.push(d)}return r},Q2e=({circuitJson:n,editEvents:e,manualEditsFile:t})=>{const r=e.filter(o=>o.edit_event_type==="edit_schematic_component_location"),i=e.filter(o=>o.edit_event_type==="edit_pcb_component_location");let a=t;return r.length>0&&(a=ugt({circuitJson:n,editEvents:r,manualEditsFile:a})),i.length>0&&(a=cgt({circuitJson:n,editEvents:i,manualEditsFile:a})),a},dgt=(n,e)=>{const t=n.source_group.list(),r=[],i=a=>{const o=t.filter(s=>s.parent_subcircuit_id===a);for(const s of o)s.subcircuit_id&&(r.push(s.subcircuit_id),i(s.subcircuit_id))};return i(e),r},K2e=({db:n,circuitJson:e,subcircuit_id:t,minTraceWidth:r=.1})=>{if(!n&&e&&(n=m3(e)),!n)throw new Error("db or circuitJson is required");const i=n.pcb_trace_hint.list(),a=t?new Set([t]):null;if(t){const E=dgt(n,t);for(const w of E)a.add(w)}const o=(e??n.toArray()).filter(E=>!t||"subcircuit_id"in E&&a.has(E.subcircuit_id)),s=n.pcb_board.list()[0];n=m3(o);const l=W8(o),c=PE([...n.pcb_component.list(),...n.pcb_smtpad.list(),...n.pcb_plated_hole.list(),...n.pcb_hole.list(),...n.pcb_via.list()].filter(E=>!t||(a==null?void 0:a.has(E.subcircuit_id))),l);for(const E of c){const w=E.connectedTo.flatMap(S=>l.getIdsConnectedToNet(S));E.connectedTo.push(...w)}const u=c.flatMap(E=>[{x:E.center.x-E.width/2,y:E.center.y-E.height/2},{x:E.center.x+E.width/2,y:E.center.y+E.height/2}]);let d;s?d={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}:d={minX:Math.min(...u.map(E=>E.x))-1,maxX:Math.max(...u.map(E=>E.x))+1,minY:Math.min(...u.map(E=>E.y))-1,maxY:Math.max(...u.map(E=>E.y))+1};const f=n.source_trace.list().map(E=>{var W,$,Q;const w=E.connected_source_port_ids.map(X=>{const ue=n.source_port.get(X),pe=n.pcb_port.getWhere({source_port_id:X});return{...ue,...pe}});if(w.length<2)return null;const[S,T]=w,P=((W=S.layers)==null?void 0:W[0])??"top",U=(($=T.layers)==null?void 0:$[0])??"top",H=i.filter(X=>X.pcb_port_id===S.pcb_port_id||X.pcb_port_id===T.pcb_port_id),G=[];for(const X of H){const ue=n.pcb_port.get(X.pcb_port_id),pe=((Q=ue==null?void 0:ue.layers)==null?void 0:Q[0])??"top";for(const ce of X.route)G.push({x:ce.x,y:ce.y,layer:pe})}return{name:E.source_trace_id??l.getNetConnectedToId(E.source_trace_id)??"",source_trace_id:E.source_trace_id,pointsToConnect:[{x:S.x,y:S.y,layer:P},...G,{x:T.x,y:T.y,layer:U}]}}).filter(E=>E!==null),m=n.source_net.list().filter(E=>!t||(a==null?void 0:a.has(E.subcircuit_id))),y=[];for(const E of m){const w=n.source_trace.list().filter(S=>{var T;return(T=S.connected_source_net_ids)==null?void 0:T.includes(E.source_net_id)});y.push({name:E.source_net_id??l.getNetConnectedToId(E.source_net_id),pointsToConnect:w.flatMap(S=>n.pcb_port.list().filter(P=>S.connected_source_port_ids.includes(P.source_port_id)).map(P=>{var U;return{x:P.x,y:P.y,layer:((U=P.layers)==null?void 0:U[0])??"top",pcb_port_id:P.pcb_port_id}}))})}return{simpleRouteJson:{bounds:d,obstacles:c,connections:[...f,...y],layerCount:2,minTraceWidth:r},connMap:l}},Vq=class extends a2{constructor(){super(...arguments);Je(this,"pcb_group_id",null);Je(this,"subcircuit_id",null);Je(this,"_hasStartedAsyncAutorouting",!1);Je(this,"_asyncAutoroutingResult",null)}get config(){return{zodProps:Omt,componentName:"Group"}}doInitialSourceRender(){const{db:t}=this.root,r=t.source_group.insert({name:this._parsedProps.name,is_subcircuit:this.isSubcircuit});this.subcircuit_id=`subcircuit_${r.source_group_id}`,this.source_group_id=r.source_group_id,t.source_group.update(r.source_group_id,{subcircuit_id:this.subcircuit_id})}doInitialSourceParentAttachment(){var i,a,o;const{db:t}=this.root;if(!this.isSubcircuit)return;const r=(o=(a=(i=this.parent)==null?void 0:i.getSubcircuit)==null?void 0:a.call(i))==null?void 0:o.subcircuit_id;r&&t.source_group.update(this.source_group_id,{parent_subcircuit_id:r})}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=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}doInitialCreateTraceHintsFromProps(){var o;const{_parsedProps:t}=this,{db:r}=this.root,i=t;if(!this.isSubcircuit)return;const a=(o=i.layout)==null?void 0:o.manual_trace_hints;if(a)for(const s of a)this.add(new Z2e({for:s.pcb_port_selector,offsets:s.offsets}))}doInitialSourceAddConnectivityMapKey(){if(!this.isSubcircuit)return;const{db:t}=this.root,r=this.selectAll("trace"),i=new TC({});i.addConnections(r.map(a=>{const o=t.source_trace.get(a.source_trace_id);return o?[o.source_trace_id,...o.connected_source_port_ids,...o.connected_source_net_ids]:null}).filter(a=>a!==null));for(const a of r){if(!a.source_trace_id)continue;const o=i.getNetConnectedToId(a.source_trace_id);if(!o)continue;const{name:s}=this._parsedProps;a.subcircuit_connectivity_map_key=`${s??`unnamedsubcircuit${this._renderId}`}_${o}`,t.source_trace.update(a.source_trace_id,{subcircuit_connectivity_map_key:a.subcircuit_connectivity_map_key})}}_areChildSubcircuitsRouted(){const t=this.selectAll("group").filter(r=>r.isSubcircuit);for(const r of t)if(r._shouldRouteAsync()&&!r._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=r1("tscircuit:core:_hasTracesToRoute"),r=this.selectAll("trace");return t(`[${this.getString()}] has ${r.length} traces to route`),r.length>0}async _runEffectMakeHttpAutoroutingRequest(){var u,d,f,m;const{db:t}=this.root,r=r1("tscircuit:core:_runEffectMakeHttpAutoroutingRequest");this._parsedProps;const i=this._getAutorouterConfig(),a=i.serverUrl,o=i.serverMode,s=(y,E)=>{var w;return r("fetching",y),E.headers&&(E.headers["Tscircuit-Core-Version"]=(w=this.root)==null?void 0:w.getCoreVersion()),fetch(y,E)},l=this.root.db.toArray().filter(y=>y.type.startsWith("source_")||y.type.startsWith("pcb_"));if(o==="solve-endpoint"){if(((u=this.props.autorouter)==null?void 0:u.inputFormat)==="simplified"){const{autorouting_result:E}=await s(`${a}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_simple_route_json:K2e({db:t,minTraceWidth:((d=this.props.autorouter)==null?void 0:d.minTraceWidth)??.15,subcircuit_id:this.subcircuit_id}).simpleRouteJson,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(w=>w.json());this._asyncAutoroutingResult=E,this._markDirty("PcbTraceRender");return}const{autorouting_result:y}=await s(`${a}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_circuit_json:l,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(E=>E.json());this._asyncAutoroutingResult=y,this._markDirty("PcbTraceRender");return}const{autorouting_job:c}=await s(`${a}/autorouting/jobs/create`,{method:"POST",body:JSON.stringify({input_circuit_json:l,provider:"freerouting",autostart:!0,display_name:(f=this.root)==null?void 0:f.name,subcircuit_id:this.subcircuit_id,server_cache_enabled:i.serverCacheEnabled}),headers:{"Content-Type":"application/json"}}).then(y=>y.json());for(;;){const{autorouting_job:y}=await s(`${a}/autorouting/jobs/get`,{method:"POST",body:JSON.stringify({autorouting_job_id:c.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(E=>E.json());if(y.is_finished){const{autorouting_job_output:E}=await s(`${a}/autorouting/jobs/get_output`,{method:"POST",body:JSON.stringify({autorouting_job_id:c.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(w=>w.json());this._asyncAutoroutingResult={output_pcb_traces:E.output_pcb_traces},this._markDirty("PcbTraceRender");break}if(y.has_error)throw t.pcb_autorouting_error.insert({pcb_error_id:c.autorouting_job_id,message:((m=y.error)==null?void 0:m.message)??JSON.stringify(y.error)}),new Error(`Autorouting job failed: ${JSON.stringify(y.error)}`);await new Promise(E=>setTimeout(E,100))}}async _runLocalAutorouting(){var l,c,u,d,f;const{db:t}=this.root;this._parsedProps;const r=r1("tscircuit:core:_runLocalAutorouting");r(`[${this.getString()}] starting local autorouting`);const i=this._getAutorouterConfig(),{simpleRouteJson:a}=K2e({db:t,minTraceWidth:((l=this.props.autorouter)==null?void 0:l.minTraceWidth)??.15,subcircuit_id:this.subcircuit_id});(c=this.root)==null||c.emit("autorouting:start",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),simpleRouteJson:a});let o;i.algorithmFn?o=await i.algorithmFn(a):o=new lgt(a,{capacityDepth:(u=this.props.autorouter)==null?void 0:u.capacityDepth,targetMinCapacity:(d=this.props.autorouter)==null?void 0:d.targetMinCapacity});const s=new Promise((m,y)=>{o.on("complete",E=>{r(`[${this.getString()}] local autorouting complete`),m(E.traces)}),o.on("error",E=>{r(`[${this.getString()}] local autorouting error: ${E.error.message}`),y(E.error)})});o.on("progress",m=>{var y;(y=this.root)==null||y.emit("autorouting:progress",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),...m})}),o.start();try{const m=await s;this._asyncAutoroutingResult={output_pcb_traces:m},this._markDirty("PcbTraceRender")}catch(m){const{db:y}=this.root;throw y.pcb_autorouting_error.insert({pcb_error_id:`pcb_autorouter_error_subcircuit_${this.subcircuit_id}`,message:m instanceof Error?m.message:String(m)}),(f=this.root)==null||f.emit("autorouting:error",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),error:{message:m instanceof Error?m.message:String(m)},simpleRouteJson:a}),m}finally{o.stop()}}_startAsyncAutorouting(){this._hasStartedAsyncAutorouting||(this._hasStartedAsyncAutorouting=!0,this._getAutorouterConfig().local?this._queueAsyncEffect("capacity-mesh-autorouting",async()=>this._runLocalAutorouting()):this._queueAsyncEffect("make-http-autorouting-request",async()=>this._runEffectMakeHttpAutoroutingRequest()))}doInitialPcbTraceRender(){var r;const t=r1("tscircuit:core:doInitialPcbTraceRender");if(this.isSubcircuit&&!((r=this.root)!=null&&r.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=r1("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:r}=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:r}=this._asyncAutoroutingResult.output_simple_route_json;if(r)for(const i of r)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:r}=this.root;for(const i of t)if(i.type==="pcb_trace"){if(i.subcircuit_id=this.subcircuit_id,i.connection_name){const a=i.connection_name;i.source_trace_id=a}r.pcb_trace.insert(i)}for(const i of t)if(i.type!=="pcb_via"&&i.type==="pcb_trace")for(const a of i.route)a.route_type==="via"&&r.pcb_via.insert({pcb_trace_id:i.pcb_trace_id,x:a.x,y:a.y,hole_diameter:.3,outer_diameter:.6,layers:[a.from_layer,a.to_layer],from_layer:a.from_layer,to_layer:a.to_layer})}doInitialSchematicLayout(){if(!this.isSubcircuit||!this._parsedProps.schAutoLayoutEnabled)return;const{db:r}=this.root,i=this.getDescendants(),a=[];for(const l of i)if("schematic_component_id"in l){const c=r.schematic_component.get(l.schematic_component_id);if(c){const u=r.schematic_port.list().filter(d=>d.schematic_component_id===c.schematic_component_id);a.push(...u)}}const o=hq(r.toArray()),s=mq(o);pq(r.toArray(),s)}_getAutorouterConfig(){const t={serverUrl:"https://registry-api.tscircuit.com",serverMode:"job",serverCacheEnabled:!0},r=this._parsedProps.autorouter??this.getInheritedProperty("autorouter");return typeof r=="object"?{local:!(r.serverUrl||r.serverMode||r.serverCacheEnabled),...t,...r}:r==="auto-local"?{local:!0,groupMode:"subcircuit"}:r==="sequential-trace"?{local:!0,groupMode:"sequential-trace"}:r==="subcircuit"?{local:!0,groupMode:"subcircuit"}:r==="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 r;if((r=this.root)!=null&&r.pcbDisabled||this.getInheritedProperty("routingDisabled"))return;const{db:t}=this.root;if(this.isSubcircuit){const i=new Map;for(const a of this.children)if(!a.isSubcircuit&&a._parsedProps.name){const o=i.get(a._parsedProps.name)||[];o.push(a),i.set(a._parsedProps.name,o)}for(const[a,o]of i.entries())o.length>1&&t.pcb_trace_error.insert({error_type:"pcb_trace_error",message:`Multiple components found with name "${a}" in subcircuit "${this._parsedProps.name||"unnamed"}". Component names must be unique within a subcircuit.`,source_trace_id:"",pcb_trace_id:"",pcb_component_ids:o.map(s=>s.pcb_component_id).filter(Boolean),pcb_port_ids:[]})}}},fgt=class extends Vq{constructor(){super(...arguments);Je(this,"pcb_board_id",null);Je(this,"_drcChecksComplete",!1);Je(this,"_connectedSchematicPortPairs",new Set)}get isSubcircuit(){return!0}get config(){return{componentName:"Board",zodProps:$xe}}get boardThickness(){const{_parsedProps:t}=this;return 1.4}get allLayers(){return["top","bottom","inner1","inner2"]}doInitialPcbBoardAutoSize(){var y;if((y=this.root)!=null&&y.pcbDisabled||!this.pcb_board_id)return;const{db:t}=this.root,{_parsedProps:r}=this;if(r.width&&r.height)return;let i=1/0,a=1/0,o=-1/0,s=-1/0;const l=t.pcb_component.list();let c=!1;for(const E of l){const{width:w,height:S,center:T}=E;w===0||S===0||(c=!0,i=Math.min(i,T.x-w/2),a=Math.min(a,T.y-S/2),o=Math.max(o,T.x+w/2),s=Math.max(s,T.y+S/2))}const u=2,d=c?o-i+u*2:0,f=c?s-a+u*2:0,m={x:c?(i+o)/2+(r.outlineOffsetX??0):r.outlineOffsetX??0,y:c?(a+s)/2+(r.outlineOffsetY??0):r.outlineOffsetY??0};t.pcb_board.update(this.pcb_board_id,{width:d,height:f,center:m})}doInitialPcbComponentRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this;let i=r.width??0,a=r.height??0;if(r.outline){const c=r.outline.map(E=>E.x),u=r.outline.map(E=>E.y),d=Math.min(...c),f=Math.max(...c),m=Math.min(...u),y=Math.max(...u);i=f-d,a=y-m}const o=t.pcb_board.insert({center:{x:(r.pcbX??0)+(r.outlineOffsetX??0),y:(r.pcbY??0)+(r.outlineOffsetY??0)},thickness:this.boardThickness,num_layers:this.allLayers.length,width:i,height:a,outline:(l=r.outline)==null?void 0:l.map(c=>({x:c.x+(r.outlineOffsetX??0),y:c.y+(r.outlineOffsetY??0)})),material:r.material});this.pcb_board_id=o.pcb_board_id}removePcbComponentRender(){const{db:t}=this.root;this.pcb_board_id&&(t.pcb_board.delete(this.pcb_board_id),this.pcb_board_id=null)}_computePcbGlobalTransformBeforeLayout(){return i1()}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 r=myt(t.toArray());for(const a of r)t.pcb_trace_error.insert(a)}_emitRenderLifecycleEvent(t,r){var i;super._emitRenderLifecycleEvent(t,r),r==="start"&&((i=this.root)==null||i.emit("board:renderPhaseStarted",{renderId:this._renderId,phase:t}))}},pgt=new Proxy({},{get:(n,e)=>e}),zC=pgt,hgt=class extends a2{get config(){return{componentName:"Capacitor",schematicSymbolName:this.props.polarized?"capacitor_polarized":this.props.symbolName??"capacitor",zodProps:Ymt,sourceFtype:zC.simple_capacitor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){const e=`${B3(this._parsedProps.capacitance)}F`;return this._parsedProps.schShowRatings&&this._parsedProps.maxVoltageRating?`${e}/${B3(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 w7({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.decouplingFor})),this.add(new w7({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.decouplingTo}))),this._createTracesFromConnectionsProp()}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=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=r.source_component_id}},J2e=class extends a2{constructor(){super(...arguments);Je(this,"schematicBoxDimensions",null)}get config(){return{componentName:"Chip",zodProps:Gxe,shouldRenderAsSchematicBox:!0}}doInitialSchematicComponentRender(){const{_parsedProps:t}=this;(t==null?void 0:t.noSchematicRepresentation)!==!0&&super.doInitialSchematicComponentRender()}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:r}=this,i=t.source_component.insert({ftype:"simple_chip",name:r.name,manufacturer_part_number:r.manufacturerPartNumber,supplier_part_numbers:r.supplierPartNumbers});this.source_component_id=i.source_component_id}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,i=t.pcb_component.insert({center:{x:r.pcbX??0,y:r.pcbY??0},width:2,height:3,layer:r.layer??"top",rotation:r.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[r,i]of t.externallyConnectedPins)this.add(new w7({from:`${this.getSubcircuitSelector()} > port.${r}`,to:`${this.getSubcircuitSelector()} > port.${i}`}));this._createTracesFromConnectionsProp()}},mgt=class extends a2{constructor(){super(...arguments);Je(this,"pos",this.portMap.pin1);Je(this,"anode",this.portMap.pin1);Je(this,"neg",this.portMap.pin2);Je(this,"cathode",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"diode",componentName:"Diode",zodProps:b1t,sourceFtype:"simple_diode"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:r}=this,i=t.source_component.insert({ftype:"simple_diode",name:r.name,manufacturer_part_number:r.manufacturerPartNumber??r.mfn,supplier_part_numbers:r.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},vgt=class extends a2{constructor(){super(...arguments);Je(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 r=Array.from(new Set(this.props.internallyConnectedPins.flat())).sort().join("");t+=`_bridged${r}`}return{schematicSymbolName:t,componentName:"Jumper",zodProps:Imt,shouldRenderAsSchematicBox:!0}}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:r}=this,i=t.source_component.insert({ftype:"simple_chip",name:r.name,manufacturer_part_number:r.manufacturerPartNumber,supplier_part_numbers:r.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=i.source_component_id}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,i=t.pcb_component.insert({center:{x:r.pcbX??0,y:r.pcbY??0},width:2,height:3,layer:r.layer??"top",rotation:r.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,r=t.pcb_port.list({pcb_component_id:this.pcb_component_id}),i={};for(let s=0;s<r.length;s++){const l=r[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 d=c.port_hints.find(f=>/^(pin)?\d+$/.test(f));d&&(/^pin\d+$/.test(d)?u=d.replace(/^pin/,""):u=d)}i[u]=l.pcb_port_id}const a=t.pcb_trace.list(),o=s=>{if(s&&typeof s=="string"&&s.startsWith("{PIN")){const l=s.replace("{PIN","").replace("}","");return i[l]||s}return s};for(const s of a)if(s.route)for(const l of s.route)l.route_type==="wire"&&(l.start_pcb_port_id=o(l.start_pcb_port_id),l.end_pcb_port_id=o(l.end_pcb_port_id))}},ygt=class extends a2{constructor(){super(...arguments);Je(this,"pos",this.portMap.pin1);Je(this,"anode",this.portMap.pin1);Je(this,"neg",this.portMap.pin2);Je(this,"cathode",this.portMap.pin2)}get config(){return{componentName:"Led",schematicSymbolName:this.props.symbolName??"led",zodProps:S1t,sourceFtype:"simple_diode"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:r}=this,i=t.source_component.insert({ftype:"simple_diode",name:r.name,manufacturer_part_number:r.manufacturerPartNumber??r.mfn,supplier_part_numbers:r.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},ggt=class extends a2{constructor(){super(...arguments);Je(this,"pos",this.portMap.pin1);Je(this,"positive",this.portMap.pin1);Je(this,"neg",this.portMap.pin2);Je(this,"negative",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"power_factor_meter_horz",componentName:"PowerSource",zodProps:R1t,sourceFtype:"simple_power_source"}}initPorts(){this.add(new K8({name:"pin1",pinNumber:1,aliases:["positive","pos"]})),this.add(new K8({name:"pin2",pinNumber:2,aliases:["negative","neg"]}))}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:r}=this,i=t.source_component.insert({ftype:"simple_power_source",name:r.name,voltage:r.voltage,supplier_part_numbers:r.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},_gt=class extends a2{get config(){return{componentName:"Resistor",schematicSymbolName:this.props.symbolName??"boxresistor",zodProps:Hmt,sourceFtype:"simple_resistor"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${B3(this._parsedProps.resistance)}Ω`}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.pullupFor,this.props.pullupTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.pullupFor&&this.props.pullupTo&&(this.add(new w7({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pullupFor})),this.add(new w7({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pullupTo}))),this._createTracesFromConnectionsProp()}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=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=r.source_component_id}},xgt=["leftedge","rightedge","topedge","bottomedge","center"],bgt=class extends Ig{get config(){return{componentName:"Constraint",zodProps:Kmt}}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 r(i){const a=i.split(" ").pop(),o=xgt.includes(a)?a:void 0,s=o?i.replace(` ${o}`,""):i,l=t.selectOne(s,{pcbPrimitive:!0});l&&e.push({selector:i,component:l,componentSelector:s,edge:o})}for(const i of["left","right","top","bottom"])i in this._parsedProps&&r(this._parsedProps[i]);if("for"in this._parsedProps)for(const i of this._parsedProps.for)r(i);return{componentsWithSelectors:e}}},Sgt=class extends Ig{constructor(){super(...arguments);Je(this,"fabrication_note_path_id",null)}get config(){return{componentName:"FabricationNotePath",zodProps:T1t}}doInitialPcbPrimitiveRender(){var l,c;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,r=this.getSubcircuit(),{_parsedProps:i}=this,a=i.layer??"top";if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenPath. Must be "top" or "bottom".`);const o=this._computePcbGlobalTransformBeforeLayout(),s=t.pcb_fabrication_note_path.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,color:i.color,route:i.route.map(u=>{const d=Cr(o,{x:u.x,y:u.y});return{...u,x:d.x,y:d.y}}),stroke_width:i.strokeWidth??.1,subcircuit_id:(r==null?void 0:r.subcircuit_id)??void 0});this.fabrication_note_path_id=s.pcb_fabrication_note_path_id}},wgt=class extends Ig{get config(){return{componentName:"FabricationNoteText",zodProps:E1t}}doInitialPcbPrimitiveRender(){var a,o;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,r=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:r.pcb_component_id,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((o=this.getGroup())==null?void 0:o.pcb_group_id)??void 0})}},Egt=class extends Vq{constructor(e){super({...e,subcircuit:!0})}},Tgt=class extends Ig{constructor(){super(...arguments);Je(this,"source_net_alias_id")}get config(){return{componentName:"NetAlias",zodProps:f1t}}doInitialSchematicComponentRender(){var o;if((o=this.root)!=null&&o.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,i={x:r.schX??0,y:r.schY??0},a=t.schematic_net_label.insert({text:r.net,source_net_id:r.net,anchor_position:i,center:i,anchor_side:"bottom"});this.source_net_alias_id=a.source_net_id}},Mgt=class extends Ig{constructor(){super(...arguments);Je(this,"pcb_silkscreen_circle_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenCircle",zodProps:U1t}}doInitialPcbPrimitiveRender(){var l,c,u;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(r.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenCircle. Must be "top" or "bottom".`);this._computePcbGlobalTransformBeforeLayout();const o=this.getSubcircuit(),s=t.pcb_silkscreen_circle.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,center:{x:r.pcbX??0,y:r.pcbY??0},radius:r.radius,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,stroke_width:r.strokeWidth??.1});this.pcb_silkscreen_circle_id=s.pcb_silkscreen_circle_id}getPcbSize(){const{_parsedProps:t}=this,r=t.radius*2;return{width:r,height:r}}},Cgt=class extends Ig{constructor(){super(...arguments);Je(this,"pcb_silkscreen_rect_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenRect",zodProps:z1t}}doInitialPcbPrimitiveRender(){var l,c,u;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(r.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenRect. Must be "top" or "bottom".`);const o=this.getSubcircuit(),s=t.pcb_silkscreen_rect.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,center:{x:r.pcbX??0,y:r.pcbY??0},width:r.width,height:r.height,subcircuit_id:(o==null?void 0:o.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:r.strokeWidth??.1});this.pcb_silkscreen_rect_id=s.pcb_silkscreen_rect_id}getPcbSize(){const{_parsedProps:t}=this;return{width:t.width,height:t.height}}},Rgt=class extends Ig{constructor(){super(...arguments);Je(this,"pcb_silkscreen_line_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenLine",zodProps:O1t}}doInitialPcbPrimitiveRender(){var l,c,u;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(r.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenLine. Must be "top" or "bottom".`);const o=this.getSubcircuit(),s=t.pcb_silkscreen_line.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,x1:r.x1,y1:r.y1,x2:r.x2,y2:r.y2,stroke_width:r.strokeWidth??.1,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((u=o==null?void 0:o.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,r=Math.abs(t.x2-t.x1),i=Math.abs(t.y2-t.y1);return{width:r,height:i}}},Agt=class extends Ig{constructor(){super(...arguments);Je(this,"pcb_via_id",null);Je(this,"matchedPort",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Via",zodProps:M1t}}getAvailablePcbLayers(){return["top","inner1","inner2","bottom"]}getPcbSize(){const{_parsedProps:t}=this;return{width:t.outerDiameter,height:t.outerDiameter}}_getPcbCircuitJsonBounds(){const{db:t}=this.root,r=t.pcb_via.get(this.pcb_via_id),i=this.getPcbSize();return{center:{x:r.x,y:r.y},bounds:{left:r.x-i.width/2,top:r.y-i.height/2,right:r.x+i.width/2,bottom:r.y+i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(t){const{db:r}=this.root;r.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:r}=this,i=this._getGlobalPcbPositionBeforeLayout(),a=this.getSubcircuit(),o=t.pcb_via.insert({x:i.x,y:i.y,hole_diameter:r.holeDiameter,outer_diameter:r.outerDiameter,layers:["bottom","top"],from_layer:r.fromLayer||"bottom",to_layer:r.toLayer||"top",subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((l=this.getGroup())==null?void 0:l.pcb_group_id)??void 0});this.pcb_via_id=o.pcb_via_id}},Pgt=class extends a2{get config(){return{componentName:"Battery",schematicSymbolName:this.props.symbolName??"battery",zodProps:u1t,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,r=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=r.source_component_id}},Ngt=class extends a2{get config(){return{componentName:"PinHeader",zodProps:d1t,shouldRenderAsSchematicBox:!0}}_getImpliedFootprintString(){var a;const e=this._parsedProps.pinCount??((a=this._parsedProps.pinLabels)==null?void 0:a.length)??0,t=this._parsedProps.holeDiameter,r=this._parsedProps.platedDiameter,i=this._parsedProps.pitch;return e>0&&i?!t&&!r?`pinrow${e}_p${i}`:`pinrow${e}_p${i}_id${t}_od${r}`:null}initPorts(){var t,r;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 K8({name:`pin${i}`,pinNumber:i,aliases:[(r=this._parsedProps.pinLabels)==null?void 0:r[i-1]].filter(Boolean)}))}_getSchematicPortArrangement(){const e=this._parsedProps.pinCount??1,t=this._parsedProps.facingDirection??"right";return{leftSize:t==="left"?e:0,rightSize:t==="right"?e:0}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=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=r.source_component_id}};function Dgt(n){switch(n){case"two_ground_pins":return"crystal_4pin";case"ground_pin":return"resonator";case"no_ground":return"crystal";default:return"crystal"}}var Lgt=class extends a2{get config(){return{componentName:"Resonator",schematicSymbolName:this.props.symbolName??Dgt(this.props.pinVariant),zodProps:Gmt,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=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:r,are_pins_interchangeable:r==="no_ground"||r==="ground_pin"});this.source_component_id=i.source_component_id}},Ogt=class extends a2{get config(){return{componentName:"Inductor",schematicSymbolName:this.props.symbolName??"inductor",zodProps:v1t,sourceFtype:zC.simple_inductor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=e.source_component.insert({name:t.name,ftype:zC.simple_inductor,inductance:t.inductance,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=r.source_component_id}};function zgt(n){switch(n){case"three_pin":return"potentiometer3";case"two_pin":return"potentiometer2";default:return"potentiometer2"}}var Ugt=class extends a2{get config(){return{componentName:"Potentiometer",schematicSymbolName:this.props.symbolName??zgt(this.props.pinVariant),zodProps:Vmt,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=t.pinVariant||"two_pin",i=e.source_component.insert({ftype:"simple_potentiometer",name:t.name,max_resistance:t.maxResistance,pin_variant:r,are_pins_interchangeable:r==="two_pin"});this.source_component_id=i.source_component_id}},kgt=class extends a2{get config(){return{componentName:"PushButton",schematicSymbolName:this.props.symbolName??"push_button_normally_open_momentary",zodProps:p1t,sourceFtype:zC.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,r=e.source_component.insert({name:t.name,ftype:zC.simple_push_button,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=r.source_component_id}},Igt=class extends a2{get config(){return{schematicSymbolName:this.props.symbolName??(this.props.pinVariant==="four_pin"?"crystal_4pin":"crystal"),componentName:"Crystal",zodProps:$mt,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`${B3(this._parsedProps.frequency)}Hz`}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=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=r.source_component_id}},Fgt=class extends a2{constructor(){super(...arguments);Je(this,"emitter",this.portMap.pin1);Je(this,"collector",this.portMap.pin2);Je(this,"base",this.portMap.pin3)}get config(){return{componentName:"Transistor",schematicSymbolName:this.props.type==="npn"?"npn_bipolar_transistor":"pnp_bipolar_transistor",zodProps:h1t,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:r}=this,i=t.source_component.insert({ftype:"simple_transistor",name:r.name,transistor_type:r.type});this.source_component_id=i.source_component_id}},Bgt=class extends a2{get config(){const e=this.props.mosfetMode==="depletion"?"d":"e";return{componentName:"Mosfet",schematicSymbolName:`${this.props.channelType}_channel_${e}_mosfet_transistor`,zodProps:m1t,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=e.source_component.insert({ftype:"simple_mosfet",name:t.name,mosfet_mode:t.mosfetMode,channel_type:t.channelType});this.source_component_id=r.source_component_id}},jgt=class extends a2{_getSwitchType(){const{spst:e,spdt:t,dpst:r,dpdt:i,type:a}=this._parsedProps??{};return i?"dpdt":e?"spst":t?"spdt":r?"dpst":a??"spst"}get config(){const e=this._getSwitchType(),{isNormallyClosed:t}=this._parsedProps??{};return{componentName:"Switch",schematicSymbolName:{spst:t?"spst_normally_closed_switch":"spst_switch",spdt:t?"spdt_normally_closed_switch":"spdt_switch",dpst:t?"dpst_normally_closed_switch":"dpst_switch",dpdt:t?"dpdt_normally_closed_switch":"dpdt_switch"}[e]??"spst_switch",zodProps:w1t,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,r=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=r.source_component_id}},Hgt=class extends Ig{constructor(){super(...arguments);Je(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicText",zodProps:N1t}}doInitialSchematicPrimitiveRender(){var i;if((i=this.root)!=null&&i.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:r}=this;t.schematic_text.insert({anchor:r.anchor??"center",text:r.text,font_size:r.fontSize,color:r.color||"#000000",position:{x:r.schX,y:r.schY},rotation:r.schRotation??0})}};new Proxy({},{get:(n,e)=>{const t=(...r)=>(r[0],new Proxy({},{get:(i,a)=>`.${e} > .${a}`}));return new Proxy(t,{get:(r,i)=>e==="net"?`net.${i}`:e==="subcircuit"?new Proxy({},{get:(a,o)=>new Proxy({},{get:(s,l)=>`subcircuit.${i} > .${o} > .${l}`})}):`.${e} > .${i}`,apply:(r,i,a)=>new Proxy({},{get:(o,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}`})}})})}}),L2e(N2e),L2e({Bug:J2e});const e5e=r1("run-frame"),Vgt={},t5e=n=>{let e;const t=new Set,r=(u,d)=>{const f=typeof u=="function"?u(e):u;if(!Object.is(f,e)){const m=e;e=d??(typeof f!="object"||f===null)?f:Object.assign({},e,f),t.forEach(y=>y(e,m))}},i=()=>e,l={setState:r,getState:i,getInitialState:()=>c,subscribe:u=>(t.add(u),()=>t.delete(u)),destroy:()=>{(Vgt?"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=n(r,i,l);return l},n5e=n=>n?t5e(n):t5e;var QL={exports:{}},$q={},KL={exports:{}},Gq={};/**
831
831
  * @license React
832
832
  * use-sync-external-store-shim.production.js
833
833
  *
@@ -13451,7 +13451,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}return lpe}K9n();function GWe(n,e,t,r=
13451
13451
  &:hover {
13452
13452
  background-color: rgba(255, 255, 255, 0.1);
13453
13453
  }
13454
- `,onClick:r=>{r.stopPropagation(),t()},children:[$e.jsx("input",{type:"checkbox",checked:e}),$e.jsx("span",{style:{color:"#eee"},children:n})]}),b_n=({children:n,elements:e})=>{const[t,r]=Bx($=>[$.is_mouse_over_container,$.setIsMouseOverContainer]),[i,a]=rt.useState(!1),[o,s]=rt.useState(!1),[l,c]=rt.useState(!1),[u,d]=Bx($=>[$.selected_layer,$.selectLayer]),[f,m,y,E,w,S]=Bx($=>[$.in_move_footprint_mode,$.in_draw_trace_mode,$.is_showing_rats_nest,$.is_showing_multiple_traces_length,$.is_showing_autorouting,$.is_showing_drc_errors]),T=Bx($=>$.setEditMode),P=Bx($=>$.setIsShowingRatsNest),U=Bx($=>$.setIsShowingMultipleTracesLength),H=Bx($=>$.setIsShowingAutorouting),G=Bx($=>$.setIsShowingDrcErrors);Q6("1",()=>d("top")),Q6("2",()=>d("bottom")),Q6("3",()=>d("inner1")),Q6("4",()=>d("inner2")),Q6("5",()=>d("inner3")),Q6("6",()=>d("inner4")),Q6("7",()=>d("inner5")),Q6("8",()=>d("inner6"));const W=(e==null?void 0:e.filter($=>$.type.includes("error")).length)??0;return $e.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>{r(!0)},onMouseLeave:$=>{r(!1),s(!1)},children:[n,$e.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@",__n.version]}),$e.jsxs("div",{style:{position:"absolute",opacity:t?1:0,top:16,left:16,transition:t?"opacity 100ms linear":"opacity 1s linear",zIndex:fb.toolbarOverlay,color:"red",display:"flex",fontSize:12,height:100,fontFamily:"sans-serif"},children:[$e.jsxs(CM,{onClick:()=>{s(!o)},onMouseLeave:()=>{o&&s(!1)},children:[$e.jsxs("div",{children:["layer:"," ",$e.jsx("span",{style:{marginLeft:2,fontWeight:500,color:MM[u]},children:u})]}),o&&$e.jsx("div",{style:{marginTop:4,minWidth:120},children:Vpe.map($=>$.replace(/-/g,"")).map($=>$e.jsx(x_n,{name:$,selected:$===u,onClick:()=>{d($.replace(/-/,""))}},$))})]}),$e.jsxs(CM,{style:W>0?{color:"red"}:{},onClick:()=>c(!l),onMouseLeave:()=>c(!1),children:[$e.jsxs("div",{children:[W," errors"]}),l&&$e.jsx("div",{style:{display:"grid",gridTemplateColumns:"100px 300px"},children:e==null?void 0:e.filter($=>$.type.includes("error")).map(($,Q)=>$e.jsxs(rt.Fragment,{children:[$e.jsx("div",{children:$.error_type}),$e.jsx("div",{children:$.message})]},Q))})]}),$e.jsx(CM,{style:{},onClick:()=>{T(m?"off":"draw_trace")},children:$e.jsxs("div",{children:[m?"✖ ":"","Edit Traces"]})}),$e.jsx(CM,{style:{},onClick:()=>{T(f?"off":"move_footprint")},children:$e.jsxs("div",{children:[f?"✖ ":"","Move Components"]})}),$e.jsx(CM,{style:{},onClick:()=>{P(!y)},children:$e.jsxs("div",{children:[y?"✖ ":"","Rats Nest"]})}),$e.jsx(CM,{onClick:()=>{a(!i)},children:$e.jsxs("div",{children:[$e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:["View"," ",$e.jsx("span",{style:{fontSize:"8px",transform:i?"rotate(180deg)":"rotate(0)",transition:"transform 0.1s ease",display:"inline-block"},children:"▼"})]}),i&&$e.jsxs("div",{style:{marginTop:4,minWidth:120},children:[$e.jsx(Xpe,{label:"Show All Trace Lengths",checked:E,onClick:()=>{U(!E)}}),$e.jsx(Xpe,{label:"Show Autorouting Animation",checked:w,onClick:()=>{H(!w)}}),$e.jsx(Xpe,{label:"Show DRC Errors",checked:S,onClick:()=>{G(!S)}})]})]})})]})]})},S_n=n=>{const{transform:e,elements:t}=n,[r,i]=rt.useMemo(()=>{const c=n.elements.flatMap(d=>Lgn(d,n.elements)),u=W8(n.elements);return[c,u]},[n.elements]),[a,o]=rt.useState({drawingObjectIdsWithMouseOver:new Set,primitiveIdsInMousedOverNet:[]}),s=rt.useMemo(()=>Pgn({primitivesWithoutInteractionMetadata:r,drawingObjectIdsWithMouseOver:a.drawingObjectIdsWithMouseOver,primitiveIdsInMousedOverNet:a.primitiveIdsInMousedOverNet}),[r,a]),l=rt.useCallback(c=>{var f,m;const u=[];for(const y of c)if(y._element){const E=i.getNetConnectedToId("pcb_port_id"in y._element?(f=y._element)==null?void 0:f.pcb_port_id:"pcb_trace_id"in y._element?(m=y._element)==null?void 0:m.pcb_trace_id:"");u.push(...i.getIdsConnectedToNet(E))}const d=new Set(c.map(y=>y._pcb_drawing_object_id));o({drawingObjectIdsWithMouseOver:d,primitiveIdsInMousedOverNet:u})},[i]);return $e.jsx(y_n,{elements:t,transform:e,primitives:r,onMouseHoverOverPrimitives:l,children:$e.jsx(e_n,{disabled:!n.allowEditing,transform:e,soup:t,cancelPanDrag:n.cancelPanDrag,onCreateEditEvent:n.onCreateEditEvent,onModifyEditEvent:n.onModifyEditEvent,children:$e.jsx(i_n,{disabled:!n.allowEditing,transform:e,soup:t,cancelPanDrag:n.cancelPanDrag,onCreateEditEvent:n.onCreateEditEvent,onModifyEditEvent:n.onModifyEditEvent,children:$e.jsx(Kgn,{transform:e,focusOnHover:n.focusOnHover,children:$e.jsx(b_n,{elements:t,children:$e.jsx(s_n,{transform:e,elements:t,children:$e.jsx(g_n,{transform:e,soup:t,children:$e.jsx(Zgn,{transform:e,debugGraphics:n.debugGraphics,children:$e.jsx(Qgn,{transform:e,elements:t,children:$e.jsx(Wgn,{transform:e,primitives:s,width:n.width,height:n.height,grid:n.grid})})})})})})})})})})},w_n=Mc(k0(400,300),n2(40,-40)),E_n=({circuitJson:n,debugGraphics:e,height:t=600,initialState:r,allowEditing:i=!0,editEvents:a,onEditEventsChanged:o,focusOnHover:s=!1,clickToInteractEnabled:l=!1})=>{const[c,u]=rt.useState(!l),[d,f]=qpe(),[m,y]=rt.useState(w_n),{ref:E,setTransform:w,cancelDrag:S}=Agn({transform:m,onSetTransform:y,enabled:c});let[T,P]=rt.useState([]);T=a??T;const U=rt.useRef(!1),H=rt.useRef(null),G=`${(n==null?void 0:n.length)||0}_${(n==null?void 0:n.editCount)||0}`,W=()=>{const pe=(f==null?void 0:f.width)>0?f:{width:500,height:500},{center:ce,width:Se,height:he}=Q.some(xe=>xe.type.startsWith("pcb_"))?_gn(Q.filter(xe=>xe.type.startsWith("pcb_"))):{center:{x:0,y:0},width:.001,height:.001},ge=Math.min((pe.width??0)/Se,(pe.height??0)/he,100)*.75,Te=Mc(k0((pe.width??0)/2,(pe.height??0)/2),n2(ge,-ge,0,0),k0(-ce.x,-ce.y));w(Te)};rt.useEffect(()=>{f!=null&&f.width&&n&&n.length!==0&&(U.current||(W(),U.current=!0))},[n,f]);const $=rt.useMemo(()=>(n==null?void 0:n.filter(pe=>pe.type.startsWith("pcb_")||pe.type.startsWith("source_")))??[],[G]),Q=rt.useMemo(()=>q1n({circuitJson:$,editEvents:T}),[$,T]),X=pe=>{P([...T,pe]),o==null||o([...T,pe])},ue=pe=>{const ce=T.map(Se=>Se.edit_event_id===pe.edit_event_id?{...Se,...pe}:Se);P(ce),o==null||o(ce)};return $e.jsxs("div",{ref:E,style:{position:"relative"},children:[$e.jsx("div",{ref:d,children:$e.jsxs(bgn,{initialState:r,children:[$e.jsx(S_n,{transform:m,height:t,width:f.width,allowEditing:i,focusOnHover:s,cancelPanDrag:S,onCreateEditEvent:X,onModifyEditEvent:ue,grid:{spacing:1,view_window:{left:0,right:f.width||500,top:t,bottom:0}},elements:Q,debugGraphics:e},f.width),$e.jsx(wgn,{})]})}),l&&!c&&$e.jsx("div",{onClick:()=>{u(!0),W()},onTouchStart:pe=>{const ce=pe.touches[0];H.current={x:ce.clientX,y:ce.clientY}},onTouchEnd:pe=>{const ce=pe.changedTouches[0],Se=H.current;if(!Se)return;const he=Math.abs(ce.clientX-Se.x),ge=Math.abs(ce.clientY-Se.y);he<10&&ge<10&&(pe.preventDefault(),u(!0),W()),H.current=null},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:fb.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center",touchAction:"pan-x pan-y pinch-zoom"},children:$e.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 T_n=({containerClassName:n,...e})=>{const t=rt.useRef(null),[r,i]=rt.useState(620);return rt.useLayoutEffect(()=>{const a=()=>{if(t.current){const s=t.current.clientHeight,l=window.innerHeight;i(Math.min(Math.max(s,620),l))}};a();const o=new ResizeObserver(a);return t.current&&o.observe(t.current),window.addEventListener("resize",a),()=>{o.disconnect(),window.removeEventListener("resize",a)}},[]),$e.jsx("div",{ref:t,className:n||"rf-w-full rf-h-full",children:$e.jsx(E_n,{...e,height:r})})},M_n='*,: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}',C_n=()=>{rt.useEffect(()=>{if(document.querySelector('style[data-styles="tscircuit-runframe"]'))return;const e=document.createElement("style");e.setAttribute("data-styles","tscircuit-runframe"),e.textContent=M_n,document.head.appendChild(e)},[])},ZQe=n=>`hsl(${qb.indexOf(n)*137.5%360}, 70%, 50%)`,R_n=({phaseTimings:n})=>{if(!n)return null;const e=Object.values(n).reduce((t,r)=>t+r,0);return $e.jsxs("div",{className:"rf-space-y-2 rf-w-full rf-px-4",children:[$e.jsx("div",{className:"rf-relative rf-h-8 rf-flex rf-rounded-sm",children:qb.map(t=>{const r=n[t]||0,i=r/e*100;return $e.jsx("div",{className:"rf-group/bar rf-relative rf-overflow-visible",style:{width:`${i}%`,backgroundColor:ZQe(t)},children:$e.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,": ",r.toFixed(1),"ms"]})},t)})}),$e.jsxs("div",{className:"rf-text-xs rf-text-gray-500",children:["Total: ",e.toFixed(2),"ms"]})]})},A_n=({renderLog:n})=>{const[e,t]=rt.useState("chronological");if(!n)return $e.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 r=Object.entries((n==null?void 0:n.phaseTimings)??{});e==="chronological"?r.sort((a,o)=>qb.indexOf(a[0])-qb.indexOf(o[0])):r.sort((a,o)=>o[1]-a[1]);const i=r.reduce((a,[o,s])=>a+s,0);return $e.jsxs("div",{className:"rf-bg-white",children:[$e.jsxs("div",{className:"rf-flex rf-justify-between rf-items-center",children:[$e.jsx("div",{children:"Render Logs"}),$e.jsxs("div",{className:"rf-mb-4 rf-pr-2 rf-flex rf-text-xs rf-items-center",children:[$e.jsx("div",{className:"rf-mr-2",children:"Sort by:"}),$e.jsxs("select",{value:e,onChange:a=>t(a.target.value),className:"rf-px-2 rf-py-1 rf-border rf-rounded rf-text-xs",children:[$e.jsx("option",{value:"chronological",children:"Phase Order"}),$e.jsx("option",{value:"longest",children:"Duration"})]})]})]}),$e.jsx(R_n,{phaseTimings:n.phaseTimings}),$e.jsxs("table",{className:"rf-w-full rf-text-xs",children:[$e.jsx("thead",{children:$e.jsxs("tr",{children:[$e.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase Order"}),$e.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase"}),$e.jsx("th",{className:"rf-text-left rf-p-2",children:"Duration (ms)"})]})}),$e.jsx("tbody",{children:r.map(([a,o])=>$e.jsxs("tr",{children:[$e.jsx("td",{className:"rf-p-2",children:qb.indexOf(a)}),$e.jsx("td",{className:"rf-p-2",children:a}),$e.jsx("td",{className:"rf-p-2",children:$e.jsx("div",{className:"rf-w-8",children:$e.jsx("div",{className:"rf-h-2 rf-rounded-sm",style:{backgroundColor:ZQe(a),width:`${o/i*100}%`}})})}),$e.jsx("td",{className:"rf-p-2",children:$e.jsxs("div",{className:"rf-flex w-full",children:[$e.jsxs("span",{className:"rf-flex-grow",children:[o,"ms"]}),$e.jsxs("span",{className:"rf-text-gray-500 rf-pr-2",children:[(o/i*100).toFixed(1),"%"]})]})})]},a))})]})]})},P_n="0.0.442",N_n=["assembly","bom","circuit_json","errors","render_log"],D_n=({code:n,onRunClicked:e=void 0,errorMessage:t,circuitJson:r,autoroutingGraphics:i,showRightHeaderContent:a=!0,showCodeTab:o=!1,codeTabContent:s,showJsonTab:l=!0,showRenderLogTab:c=!0,onActiveTabChange:u,renderLog:d,showImportAndFormatButtons:f=!0,className:m,headerClassName:y,leftHeaderContent:E,readOnly:w,isStreaming:S,autoroutingLog:T,onReportAutoroutingLog:P,isRunningCode:U,hasCodeChangedSinceLastRun:H,onEditEvent:G,editEvents:W,defaultActiveTab:$,autoRotate3dViewerDisabled:Q,showSchematicDebugGrid:X=!1,showToggleFullScreen:ue=!0,defaultToFullScreen:pe=!1})=>{var Ne;C_n();const ce=rt.useMemo(()=>r?r.filter(ze=>ze&&"error_type"in ze):null,[r]),[Se,he]=rt.useState($??"pcb"),[ge,Te]=rt.useState(pe),xe=rt.useCallback(ze=>{he(ze),u==null||u(ze)},[u]),Ae=()=>{Te(!ge)};return rt.useEffect(()=>{t&&xe("errors")},[t]),rt.useEffect(()=>{(Se==="code"||Se==="errors")&&r&&!t&&xe($??"pcb")},[r]),$e.jsx("div",{className:_h("flex flex-col relative rf-overflow-x-hidden",m),children:$e.jsx("div",{className:_h("rf-md:sticky rf-md:top-2",ge&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-bg-white"),children:$e.jsxs(Z5e,{value:Se,onValueChange:xe,className:"rf-flex-grow rf-flex rf-flex-col",children:[$e.jsxs("div",{className:_h("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",y),children:[E,E&&$e.jsx("div",{className:"rf-flex-grow"}),!E&&U&&$e.jsx(nM,{className:"rf-w-4 rf-h-4 rf-animate-spin"}),!E&&$e.jsx("div",{className:"rf-flex-grow"}),d&&d.progress!==1&&$e.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[d.lastRenderEvent&&$e.jsx("div",{className:"rf-text-xs rf-text-gray-500",children:((Ne=d.lastRenderEvent)==null?void 0:Ne.phase)??""}),$e.jsx("div",{className:"rf-w-4 rf-h-4 rf-bg-blue-500 rf-opacity-50 rf-rounded-full rf-text-white",children:$e.jsx(nM,{className:"rf-w-4 rf-h-4 rf-animate-spin"})}),$e.jsxs("div",{className:"rf-text-xs rf-font-bold rf-text-gray-700 rf-tabular-nums",children:[((d.progress??0)*100).toFixed(1),"%"]})]}),a&&$e.jsxs(lY,{children:[o&&$e.jsx(p6,{value:"code",children:"Code"}),$e.jsxs(p6,{value:"pcb",className:"rf-whitespace-nowrap",children:[r&&$e.jsx("span",{className:_h("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",H?"rf-bg-gray-500":"rf-bg-blue-500")}),"PCB"]}),$e.jsxs(p6,{value:"schematic",className:"rf-whitespace-nowrap",children:[r&&$e.jsx("span",{className:_h("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",H?"rf-bg-gray-500":"rf-bg-blue-500")}),"Schematic"]}),$e.jsxs(p6,{value:"cad",children:[r&&$e.jsx("span",{className:_h("inline-flex items-center justify-center w-2 h-2 mr-1 text-xs font-bold text-white rounded-full",H?"rf-bg-gray-500":"rf-bg-blue-500")}),"3D"]}),!["pcb","cad","schematic"].includes(Se)&&$e.jsx(p6,{value:Se,children:W5e(Se)}),$e.jsxs(sue,{children:[$e.jsx(lue,{asChild:!0,children:$e.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[$e.jsx(inn,{className:"rf-w-4 rf-h-4"}),(ce&&ce.length>0||t)&&$e.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"})]})}),$e.jsxs(aB,{className:"rf-*:text-xs",children:[N_n.map(ze=>$e.jsxs(R4,{onSelect:()=>xe(ze),children:[Se!==ze&&$e.jsx(sHe,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),Se===ze&&$e.jsx(mce,{className:"rf-w-3 rf-h-3"}),$e.jsx("div",{className:"rf-pr-2",children:W5e(ze)}),ze==="errors"&&(ce&&ce.length>0||t)&&$e.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:ce==null?void 0:ce.length})]},ze)),$e.jsx(R4,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:$e.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/runframe@",P_n.split(".").map((ze,Re)=>Re===2?parseInt(ze)+1:ze).join(".")]})})]})]})]}),ue&&$e.jsx(L5,{onClick:Ae,variant:"ghost",children:ge?$e.jsx(lnn,{size:16}):$e.jsx(onn,{size:16})})]}),o&&$e.jsx(e8,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:$e.jsx("div",{className:"rf-h-full",children:s})}),$e.jsx(e8,{value:"pcb",children:$e.jsx("div",{className:_h("rf-overflow-hidden",ge?"rf-h-[calc(100vh-52px)]":"rf-h-[620px]"),children:$e.jsx(tM,{fallbackRender:({error:ze})=>$e.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:$e.jsxs("div",{className:"rf-p-4",children:[$e.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading PCB viewer"}),$e.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(ze==null?void 0:ze.message)||"An unknown error occurred"})]})}),children:r?$e.jsx(T_n,{focusOnHover:!1,circuitJson:r,debugGraphics:i,containerClassName:_h("rf-h-full rf-w-full",ge?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:ze=>{G&&ze.forEach(Re=>G(Re))}}):$e.jsx(Uw,{onRunClicked:e})})})}),$e.jsx(e8,{value:"assembly",children:$e.jsx("div",{className:_h("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:$e.jsx(tM,{fallback:$e.jsx("div",{children:"Error loading Assembly"}),children:r?$e.jsx(Rsn,{circuitJson:r,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):$e.jsx(Uw,{onRunClicked:e})})})}),$e.jsx(e8,{value:"schematic",children:$e.jsx("div",{className:_h("rf-overflow-auto rf-bg-white",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:$e.jsx(tM,{fallbackRender:({error:ze})=>$e.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:$e.jsxs("div",{className:"rf-p-4",children:[$e.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Schematic"}),$e.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(ze==null?void 0:ze.message)||"An unknown error occurred"})]})}),children:r?$e.jsx(Tsn,{circuitJson:r,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:ze=>{G==null||G(ze)},debugGrid:X,colorOverrides:{schematic:{background:"transparent"}}}):$e.jsx(Uw,{onRunClicked:e})})})}),$e.jsx(e8,{value:"cad",children:$e.jsx("div",{className:_h("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:$e.jsx(tM,{FallbackComponent:Gtn,children:r?$e.jsx(Vtn,{soup:r,autoRotateDisabled:Q}):$e.jsx(Uw,{onRunClicked:e})})})}),$e.jsx(e8,{value:"bom",children:$e.jsx("div",{className:_h("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:$e.jsx(tM,{fallbackRender:({error:ze})=>$e.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:$e.jsxs("div",{className:"rf-p-4",children:[$e.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Bill of Materials"}),$e.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(ze==null?void 0:ze.message)||"An unknown error occurred"})]})}),children:r?$e.jsx(Lsn,{circuitJson:r}):$e.jsx(Uw,{onRunClicked:e})})})}),$e.jsx(e8,{value:"circuit_json",children:$e.jsx("div",{className:_h("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:$e.jsx(tM,{fallback:$e.jsx("div",{children:"Error loading JSON viewer"}),children:r?$e.jsx(Nsn,{elements:r}):$e.jsx(Uw,{onRunClicked:e})})})}),$e.jsx(e8,{value:"errors",children:$e.jsx("div",{className:_h("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Array.isArray(ce)&&ce.length>0||t?$e.jsx(non,{code:n,circuitJsonErrors:ce,errorMessage:t,autoroutingLog:T,onReportAutoroutingLog:P}):$e.jsx(Uw,{onRunClicked:e})})}),c&&$e.jsx(e8,{value:"render_log",children:$e.jsx(A_n,{renderLog:d})})]})})})};var SH="Dialog",[QQe,KQe]=eS(SH),[L_n,L4]=QQe(SH),JQe=n=>{const{__scopeDialog:e,children:t,open:r,defaultOpen:i,onOpenChange:a,modal:o=!0}=n,s=rt.useRef(null),l=rt.useRef(null),[c,u]=kE({prop:r,defaultProp:i??!1,onChange:a,caller:SH});return $e.jsx(L_n,{scope:e,triggerRef:s,contentRef:l,contentId:tS(),titleId:tS(),descriptionId:tS(),open:c,onOpenChange:u,onOpenToggle:rt.useCallback(()=>u(d=>!d),[u]),modal:o,children:t})};JQe.displayName=SH;var eKe="DialogTrigger",tKe=rt.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=L4(eKe,t),a=L_(e,i.triggerRef);return $e.jsx(Ry.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Qpe(i.open),...r,ref:a,onClick:Pp(n.onClick,i.onOpenToggle)})});tKe.displayName=eKe;var Wpe="DialogPortal",[O_n,nKe]=QQe(Wpe,{forceMount:void 0}),rKe=n=>{const{__scopeDialog:e,forceMount:t,children:r,container:i}=n,a=L4(Wpe,e);return $e.jsx(O_n,{scope:e,forceMount:t,children:rt.Children.map(r,o=>$e.jsx(K4,{present:t||a.open,children:$e.jsx(Gce,{asChild:!0,container:i,children:o})}))})};rKe.displayName=Wpe;var wH="DialogOverlay",iKe=rt.forwardRef((n,e)=>{const t=nKe(wH,n.__scopeDialog),{forceMount:r=t.forceMount,...i}=n,a=L4(wH,n.__scopeDialog);return a.modal?$e.jsx(K4,{present:r||a.open,children:$e.jsx(U_n,{...i,ref:e})}):null});iKe.displayName=wH;var z_n=UE("DialogOverlay.RemoveScroll"),U_n=rt.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=L4(wH,t);return $e.jsx(Qce,{as:z_n,allowPinchZoom:!0,shards:[i.contentRef],children:$e.jsx(Ry.div,{"data-state":Qpe(i.open),...r,ref:e,style:{pointerEvents:"auto",...r.style}})})}),qw="DialogContent",aKe=rt.forwardRef((n,e)=>{const t=nKe(qw,n.__scopeDialog),{forceMount:r=t.forceMount,...i}=n,a=L4(qw,n.__scopeDialog);return $e.jsx(K4,{present:r||a.open,children:a.modal?$e.jsx(k_n,{...i,ref:e}):$e.jsx(I_n,{...i,ref:e})})});aKe.displayName=qw;var k_n=rt.forwardRef((n,e)=>{const t=L4(qw,n.__scopeDialog),r=rt.useRef(null),i=L_(e,t.contentRef,r);return rt.useEffect(()=>{const a=r.current;if(a)return fVe(a)},[]),$e.jsx(oKe,{...n,ref:i,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Pp(n.onCloseAutoFocus,a=>{var o;a.preventDefault(),(o=t.triggerRef.current)==null||o.focus()}),onPointerDownOutside:Pp(n.onPointerDownOutside,a=>{const o=a.detail.originalEvent,s=o.button===0&&o.ctrlKey===!0;(o.button===2||s)&&a.preventDefault()}),onFocusOutside:Pp(n.onFocusOutside,a=>a.preventDefault())})}),I_n=rt.forwardRef((n,e)=>{const t=L4(qw,n.__scopeDialog),r=rt.useRef(!1),i=rt.useRef(!1);return $e.jsx(oKe,{...n,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var o,s;(o=n.onCloseAutoFocus)==null||o.call(n,a),a.defaultPrevented||(r.current||(s=t.triggerRef.current)==null||s.focus(),a.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:a=>{var l,c;(l=n.onInteractOutside)==null||l.call(n,a),a.defaultPrevented||(r.current=!0,a.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=a.target;((c=t.triggerRef.current)==null?void 0:c.contains(o))&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&i.current&&a.preventDefault()}})}),oKe=rt.forwardRef((n,e)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...o}=n,s=L4(qw,t),l=rt.useRef(null),c=L_(e,l);return CHe(),$e.jsxs($e.Fragment,{children:[$e.jsx(Pce,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:$e.jsx(Mce,{role:"dialog",id:s.contentId,"aria-describedby":s.descriptionId,"aria-labelledby":s.titleId,"data-state":Qpe(s.open),...o,ref:c,onDismiss:()=>s.onOpenChange(!1)})}),$e.jsxs($e.Fragment,{children:[$e.jsx(B_n,{titleId:s.titleId}),$e.jsx(H_n,{contentRef:l,descriptionId:s.descriptionId})]})]})}),Zpe="DialogTitle",sKe=rt.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=L4(Zpe,t);return $e.jsx(Ry.h2,{id:i.titleId,...r,ref:e})});sKe.displayName=Zpe;var lKe="DialogDescription",cKe=rt.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=L4(lKe,t);return $e.jsx(Ry.p,{id:i.descriptionId,...r,ref:e})});cKe.displayName=lKe;var uKe="DialogClose",dKe=rt.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=L4(uKe,t);return $e.jsx(Ry.button,{type:"button",...r,ref:e,onClick:Pp(n.onClick,()=>i.onOpenChange(!1))})});dKe.displayName=uKe;function Qpe(n){return n?"open":"closed"}var fKe="DialogTitleWarning",[F_n,pKe]=o_t(fKe,{contentName:qw,titleName:Zpe,docsSlug:"dialog"}),B_n=({titleId:n})=>{const e=pKe(fKe),t=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
13454
+ `,onClick:r=>{r.stopPropagation(),t()},children:[$e.jsx("input",{type:"checkbox",checked:e}),$e.jsx("span",{style:{color:"#eee"},children:n})]}),b_n=({children:n,elements:e})=>{const[t,r]=Bx($=>[$.is_mouse_over_container,$.setIsMouseOverContainer]),[i,a]=rt.useState(!1),[o,s]=rt.useState(!1),[l,c]=rt.useState(!1),[u,d]=Bx($=>[$.selected_layer,$.selectLayer]),[f,m,y,E,w,S]=Bx($=>[$.in_move_footprint_mode,$.in_draw_trace_mode,$.is_showing_rats_nest,$.is_showing_multiple_traces_length,$.is_showing_autorouting,$.is_showing_drc_errors]),T=Bx($=>$.setEditMode),P=Bx($=>$.setIsShowingRatsNest),U=Bx($=>$.setIsShowingMultipleTracesLength),H=Bx($=>$.setIsShowingAutorouting),G=Bx($=>$.setIsShowingDrcErrors);Q6("1",()=>d("top")),Q6("2",()=>d("bottom")),Q6("3",()=>d("inner1")),Q6("4",()=>d("inner2")),Q6("5",()=>d("inner3")),Q6("6",()=>d("inner4")),Q6("7",()=>d("inner5")),Q6("8",()=>d("inner6"));const W=(e==null?void 0:e.filter($=>$.type.includes("error")).length)??0;return $e.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>{r(!0)},onMouseLeave:$=>{r(!1),s(!1)},children:[n,$e.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@",__n.version]}),$e.jsxs("div",{style:{position:"absolute",opacity:t?1:0,top:16,left:16,transition:t?"opacity 100ms linear":"opacity 1s linear",zIndex:fb.toolbarOverlay,color:"red",display:"flex",fontSize:12,height:100,fontFamily:"sans-serif"},children:[$e.jsxs(CM,{onClick:()=>{s(!o)},onMouseLeave:()=>{o&&s(!1)},children:[$e.jsxs("div",{children:["layer:"," ",$e.jsx("span",{style:{marginLeft:2,fontWeight:500,color:MM[u]},children:u})]}),o&&$e.jsx("div",{style:{marginTop:4,minWidth:120},children:Vpe.map($=>$.replace(/-/g,"")).map($=>$e.jsx(x_n,{name:$,selected:$===u,onClick:()=>{d($.replace(/-/,""))}},$))})]}),$e.jsxs(CM,{style:W>0?{color:"red"}:{},onClick:()=>c(!l),onMouseLeave:()=>c(!1),children:[$e.jsxs("div",{children:[W," errors"]}),l&&$e.jsx("div",{style:{display:"grid",gridTemplateColumns:"100px 300px"},children:e==null?void 0:e.filter($=>$.type.includes("error")).map(($,Q)=>$e.jsxs(rt.Fragment,{children:[$e.jsx("div",{children:$.error_type}),$e.jsx("div",{children:$.message})]},Q))})]}),$e.jsx(CM,{style:{},onClick:()=>{T(m?"off":"draw_trace")},children:$e.jsxs("div",{children:[m?"✖ ":"","Edit Traces"]})}),$e.jsx(CM,{style:{},onClick:()=>{T(f?"off":"move_footprint")},children:$e.jsxs("div",{children:[f?"✖ ":"","Move Components"]})}),$e.jsx(CM,{style:{},onClick:()=>{P(!y)},children:$e.jsxs("div",{children:[y?"✖ ":"","Rats Nest"]})}),$e.jsx(CM,{onClick:()=>{a(!i)},children:$e.jsxs("div",{children:[$e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:["View"," ",$e.jsx("span",{style:{fontSize:"8px",transform:i?"rotate(180deg)":"rotate(0)",transition:"transform 0.1s ease",display:"inline-block"},children:"▼"})]}),i&&$e.jsxs("div",{style:{marginTop:4,minWidth:120},children:[$e.jsx(Xpe,{label:"Show All Trace Lengths",checked:E,onClick:()=>{U(!E)}}),$e.jsx(Xpe,{label:"Show Autorouting Animation",checked:w,onClick:()=>{H(!w)}}),$e.jsx(Xpe,{label:"Show DRC Errors",checked:S,onClick:()=>{G(!S)}})]})]})})]})]})},S_n=n=>{const{transform:e,elements:t}=n,[r,i]=rt.useMemo(()=>{const c=n.elements.flatMap(d=>Lgn(d,n.elements)),u=W8(n.elements);return[c,u]},[n.elements]),[a,o]=rt.useState({drawingObjectIdsWithMouseOver:new Set,primitiveIdsInMousedOverNet:[]}),s=rt.useMemo(()=>Pgn({primitivesWithoutInteractionMetadata:r,drawingObjectIdsWithMouseOver:a.drawingObjectIdsWithMouseOver,primitiveIdsInMousedOverNet:a.primitiveIdsInMousedOverNet}),[r,a]),l=rt.useCallback(c=>{var f,m;const u=[];for(const y of c)if(y._element){const E=i.getNetConnectedToId("pcb_port_id"in y._element?(f=y._element)==null?void 0:f.pcb_port_id:"pcb_trace_id"in y._element?(m=y._element)==null?void 0:m.pcb_trace_id:"");u.push(...i.getIdsConnectedToNet(E))}const d=new Set(c.map(y=>y._pcb_drawing_object_id));o({drawingObjectIdsWithMouseOver:d,primitiveIdsInMousedOverNet:u})},[i]);return $e.jsx(y_n,{elements:t,transform:e,primitives:r,onMouseHoverOverPrimitives:l,children:$e.jsx(e_n,{disabled:!n.allowEditing,transform:e,soup:t,cancelPanDrag:n.cancelPanDrag,onCreateEditEvent:n.onCreateEditEvent,onModifyEditEvent:n.onModifyEditEvent,children:$e.jsx(i_n,{disabled:!n.allowEditing,transform:e,soup:t,cancelPanDrag:n.cancelPanDrag,onCreateEditEvent:n.onCreateEditEvent,onModifyEditEvent:n.onModifyEditEvent,children:$e.jsx(Kgn,{transform:e,focusOnHover:n.focusOnHover,children:$e.jsx(b_n,{elements:t,children:$e.jsx(s_n,{transform:e,elements:t,children:$e.jsx(g_n,{transform:e,soup:t,children:$e.jsx(Zgn,{transform:e,debugGraphics:n.debugGraphics,children:$e.jsx(Qgn,{transform:e,elements:t,children:$e.jsx(Wgn,{transform:e,primitives:s,width:n.width,height:n.height,grid:n.grid})})})})})})})})})})},w_n=Mc(k0(400,300),n2(40,-40)),E_n=({circuitJson:n,debugGraphics:e,height:t=600,initialState:r,allowEditing:i=!0,editEvents:a,onEditEventsChanged:o,focusOnHover:s=!1,clickToInteractEnabled:l=!1})=>{const[c,u]=rt.useState(!l),[d,f]=qpe(),[m,y]=rt.useState(w_n),{ref:E,setTransform:w,cancelDrag:S}=Agn({transform:m,onSetTransform:y,enabled:c});let[T,P]=rt.useState([]);T=a??T;const U=rt.useRef(!1),H=rt.useRef(null),G=`${(n==null?void 0:n.length)||0}_${(n==null?void 0:n.editCount)||0}`,W=()=>{const pe=(f==null?void 0:f.width)>0?f:{width:500,height:500},{center:ce,width:Se,height:he}=Q.some(xe=>xe.type.startsWith("pcb_"))?_gn(Q.filter(xe=>xe.type.startsWith("pcb_"))):{center:{x:0,y:0},width:.001,height:.001},ge=Math.min((pe.width??0)/Se,(pe.height??0)/he,100)*.75,Te=Mc(k0((pe.width??0)/2,(pe.height??0)/2),n2(ge,-ge,0,0),k0(-ce.x,-ce.y));w(Te)};rt.useEffect(()=>{f!=null&&f.width&&n&&n.length!==0&&(U.current||(W(),U.current=!0))},[n,f]);const $=rt.useMemo(()=>(n==null?void 0:n.filter(pe=>pe.type.startsWith("pcb_")||pe.type.startsWith("source_")))??[],[G]),Q=rt.useMemo(()=>q1n({circuitJson:$,editEvents:T}),[$,T]),X=pe=>{P([...T,pe]),o==null||o([...T,pe])},ue=pe=>{const ce=T.map(Se=>Se.edit_event_id===pe.edit_event_id?{...Se,...pe}:Se);P(ce),o==null||o(ce)};return $e.jsxs("div",{ref:E,style:{position:"relative"},children:[$e.jsx("div",{ref:d,children:$e.jsxs(bgn,{initialState:r,children:[$e.jsx(S_n,{transform:m,height:t,width:f.width,allowEditing:i,focusOnHover:s,cancelPanDrag:S,onCreateEditEvent:X,onModifyEditEvent:ue,grid:{spacing:1,view_window:{left:0,right:f.width||500,top:t,bottom:0}},elements:Q,debugGraphics:e},f.width),$e.jsx(wgn,{})]})}),l&&!c&&$e.jsx("div",{onClick:()=>{u(!0),W()},onTouchStart:pe=>{const ce=pe.touches[0];H.current={x:ce.clientX,y:ce.clientY}},onTouchEnd:pe=>{const ce=pe.changedTouches[0],Se=H.current;if(!Se)return;const he=Math.abs(ce.clientX-Se.x),ge=Math.abs(ce.clientY-Se.y);he<10&&ge<10&&(pe.preventDefault(),u(!0),W()),H.current=null},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:fb.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center",touchAction:"pan-x pan-y pinch-zoom"},children:$e.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 T_n=({containerClassName:n,...e})=>{const t=rt.useRef(null),[r,i]=rt.useState(620);return rt.useLayoutEffect(()=>{const a=()=>{if(t.current){const s=t.current.clientHeight,l=window.innerHeight;i(Math.min(Math.max(s,620),l))}};a();const o=new ResizeObserver(a);return t.current&&o.observe(t.current),window.addEventListener("resize",a),()=>{o.disconnect(),window.removeEventListener("resize",a)}},[]),$e.jsx("div",{ref:t,className:n||"rf-w-full rf-h-full",children:$e.jsx(E_n,{...e,height:r})})},M_n='*,: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}',C_n=()=>{rt.useEffect(()=>{if(document.querySelector('style[data-styles="tscircuit-runframe"]'))return;const e=document.createElement("style");e.setAttribute("data-styles","tscircuit-runframe"),e.textContent=M_n,document.head.appendChild(e)},[])},ZQe=n=>`hsl(${qb.indexOf(n)*137.5%360}, 70%, 50%)`,R_n=({phaseTimings:n})=>{if(!n)return null;const e=Object.values(n).reduce((t,r)=>t+r,0);return $e.jsxs("div",{className:"rf-space-y-2 rf-w-full rf-px-4",children:[$e.jsx("div",{className:"rf-relative rf-h-8 rf-flex rf-rounded-sm",children:qb.map(t=>{const r=n[t]||0,i=r/e*100;return $e.jsx("div",{className:"rf-group/bar rf-relative rf-overflow-visible",style:{width:`${i}%`,backgroundColor:ZQe(t)},children:$e.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,": ",r.toFixed(1),"ms"]})},t)})}),$e.jsxs("div",{className:"rf-text-xs rf-text-gray-500",children:["Total: ",e.toFixed(2),"ms"]})]})},A_n=({renderLog:n})=>{const[e,t]=rt.useState("chronological");if(!n)return $e.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 r=Object.entries((n==null?void 0:n.phaseTimings)??{});e==="chronological"?r.sort((a,o)=>qb.indexOf(a[0])-qb.indexOf(o[0])):r.sort((a,o)=>o[1]-a[1]);const i=r.reduce((a,[o,s])=>a+s,0);return $e.jsxs("div",{className:"rf-bg-white",children:[$e.jsxs("div",{className:"rf-flex rf-justify-between rf-items-center",children:[$e.jsx("div",{children:"Render Logs"}),$e.jsxs("div",{className:"rf-mb-4 rf-pr-2 rf-flex rf-text-xs rf-items-center",children:[$e.jsx("div",{className:"rf-mr-2",children:"Sort by:"}),$e.jsxs("select",{value:e,onChange:a=>t(a.target.value),className:"rf-px-2 rf-py-1 rf-border rf-rounded rf-text-xs",children:[$e.jsx("option",{value:"chronological",children:"Phase Order"}),$e.jsx("option",{value:"longest",children:"Duration"})]})]})]}),$e.jsx(R_n,{phaseTimings:n.phaseTimings}),$e.jsxs("table",{className:"rf-w-full rf-text-xs",children:[$e.jsx("thead",{children:$e.jsxs("tr",{children:[$e.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase Order"}),$e.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase"}),$e.jsx("th",{className:"rf-text-left rf-p-2",children:"Duration (ms)"})]})}),$e.jsx("tbody",{children:r.map(([a,o])=>$e.jsxs("tr",{children:[$e.jsx("td",{className:"rf-p-2",children:qb.indexOf(a)}),$e.jsx("td",{className:"rf-p-2",children:a}),$e.jsx("td",{className:"rf-p-2",children:$e.jsx("div",{className:"rf-w-8",children:$e.jsx("div",{className:"rf-h-2 rf-rounded-sm",style:{backgroundColor:ZQe(a),width:`${o/i*100}%`}})})}),$e.jsx("td",{className:"rf-p-2",children:$e.jsxs("div",{className:"rf-flex w-full",children:[$e.jsxs("span",{className:"rf-flex-grow",children:[o,"ms"]}),$e.jsxs("span",{className:"rf-text-gray-500 rf-pr-2",children:[(o/i*100).toFixed(1),"%"]})]})})]},a))})]})]})},P_n="0.0.443",N_n=["assembly","bom","circuit_json","errors","render_log"],D_n=({code:n,onRunClicked:e=void 0,errorMessage:t,circuitJson:r,autoroutingGraphics:i,showRightHeaderContent:a=!0,showCodeTab:o=!1,codeTabContent:s,showJsonTab:l=!0,showRenderLogTab:c=!0,onActiveTabChange:u,renderLog:d,showImportAndFormatButtons:f=!0,className:m,headerClassName:y,leftHeaderContent:E,readOnly:w,isStreaming:S,autoroutingLog:T,onReportAutoroutingLog:P,isRunningCode:U,hasCodeChangedSinceLastRun:H,onEditEvent:G,editEvents:W,defaultActiveTab:$,autoRotate3dViewerDisabled:Q,showSchematicDebugGrid:X=!1,showToggleFullScreen:ue=!0,defaultToFullScreen:pe=!1})=>{var Ne;C_n();const ce=rt.useMemo(()=>r?r.filter(ze=>ze&&"error_type"in ze):null,[r]),[Se,he]=rt.useState($??"pcb"),[ge,Te]=rt.useState(pe),xe=rt.useCallback(ze=>{he(ze),u==null||u(ze)},[u]),Ae=()=>{Te(!ge)};return rt.useEffect(()=>{t&&xe("errors")},[t]),rt.useEffect(()=>{(Se==="code"||Se==="errors")&&r&&!t&&xe($??"pcb")},[r]),$e.jsx("div",{className:_h("flex flex-col relative rf-overflow-x-hidden",m),children:$e.jsx("div",{className:_h("rf-md:sticky rf-md:top-2",ge&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-bg-white"),children:$e.jsxs(Z5e,{value:Se,onValueChange:xe,className:"rf-flex-grow rf-flex rf-flex-col",children:[$e.jsxs("div",{className:_h("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",y),children:[E,E&&$e.jsx("div",{className:"rf-flex-grow"}),!E&&U&&$e.jsx(nM,{className:"rf-w-4 rf-h-4 rf-animate-spin"}),!E&&$e.jsx("div",{className:"rf-flex-grow"}),d&&d.progress!==1&&$e.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[d.lastRenderEvent&&$e.jsx("div",{className:"rf-text-xs rf-text-gray-500",children:((Ne=d.lastRenderEvent)==null?void 0:Ne.phase)??""}),$e.jsx("div",{className:"rf-w-4 rf-h-4 rf-bg-blue-500 rf-opacity-50 rf-rounded-full rf-text-white",children:$e.jsx(nM,{className:"rf-w-4 rf-h-4 rf-animate-spin"})}),$e.jsxs("div",{className:"rf-text-xs rf-font-bold rf-text-gray-700 rf-tabular-nums",children:[((d.progress??0)*100).toFixed(1),"%"]})]}),a&&$e.jsxs(lY,{children:[o&&$e.jsx(p6,{value:"code",children:"Code"}),$e.jsxs(p6,{value:"pcb",className:"rf-whitespace-nowrap",children:[r&&$e.jsx("span",{className:_h("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",H?"rf-bg-gray-500":"rf-bg-blue-500")}),"PCB"]}),$e.jsxs(p6,{value:"schematic",className:"rf-whitespace-nowrap",children:[r&&$e.jsx("span",{className:_h("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",H?"rf-bg-gray-500":"rf-bg-blue-500")}),"Schematic"]}),$e.jsxs(p6,{value:"cad",children:[r&&$e.jsx("span",{className:_h("inline-flex items-center justify-center w-2 h-2 mr-1 text-xs font-bold text-white rounded-full",H?"rf-bg-gray-500":"rf-bg-blue-500")}),"3D"]}),!["pcb","cad","schematic"].includes(Se)&&$e.jsx(p6,{value:Se,children:W5e(Se)}),$e.jsxs(sue,{children:[$e.jsx(lue,{asChild:!0,children:$e.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[$e.jsx(inn,{className:"rf-w-4 rf-h-4"}),(ce&&ce.length>0||t)&&$e.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"})]})}),$e.jsxs(aB,{className:"rf-*:text-xs",children:[N_n.map(ze=>$e.jsxs(R4,{onSelect:()=>xe(ze),children:[Se!==ze&&$e.jsx(sHe,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),Se===ze&&$e.jsx(mce,{className:"rf-w-3 rf-h-3"}),$e.jsx("div",{className:"rf-pr-2",children:W5e(ze)}),ze==="errors"&&(ce&&ce.length>0||t)&&$e.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:ce==null?void 0:ce.length})]},ze)),$e.jsx(R4,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:$e.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/runframe@",P_n.split(".").map((ze,Re)=>Re===2?parseInt(ze)+1:ze).join(".")]})})]})]})]}),ue&&$e.jsx(L5,{onClick:Ae,variant:"ghost",children:ge?$e.jsx(lnn,{size:16}):$e.jsx(onn,{size:16})})]}),o&&$e.jsx(e8,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:$e.jsx("div",{className:"rf-h-full",children:s})}),$e.jsx(e8,{value:"pcb",children:$e.jsx("div",{className:_h("rf-overflow-hidden",ge?"rf-h-[calc(100vh-52px)]":"rf-h-[620px]"),children:$e.jsx(tM,{fallbackRender:({error:ze})=>$e.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:$e.jsxs("div",{className:"rf-p-4",children:[$e.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading PCB viewer"}),$e.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(ze==null?void 0:ze.message)||"An unknown error occurred"})]})}),children:r?$e.jsx(T_n,{focusOnHover:!1,circuitJson:r,debugGraphics:i,containerClassName:_h("rf-h-full rf-w-full",ge?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:ze=>{G&&ze.forEach(Re=>G(Re))}}):$e.jsx(Uw,{onRunClicked:e})})})}),$e.jsx(e8,{value:"assembly",children:$e.jsx("div",{className:_h("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:$e.jsx(tM,{fallback:$e.jsx("div",{children:"Error loading Assembly"}),children:r?$e.jsx(Rsn,{circuitJson:r,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):$e.jsx(Uw,{onRunClicked:e})})})}),$e.jsx(e8,{value:"schematic",children:$e.jsx("div",{className:_h("rf-overflow-auto rf-bg-white",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:$e.jsx(tM,{fallbackRender:({error:ze})=>$e.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:$e.jsxs("div",{className:"rf-p-4",children:[$e.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Schematic"}),$e.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(ze==null?void 0:ze.message)||"An unknown error occurred"})]})}),children:r?$e.jsx(Tsn,{circuitJson:r,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:ze=>{G==null||G(ze)},debugGrid:X,colorOverrides:{schematic:{background:"transparent"}}}):$e.jsx(Uw,{onRunClicked:e})})})}),$e.jsx(e8,{value:"cad",children:$e.jsx("div",{className:_h("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:$e.jsx(tM,{FallbackComponent:Gtn,children:r?$e.jsx(Vtn,{soup:r,autoRotateDisabled:Q}):$e.jsx(Uw,{onRunClicked:e})})})}),$e.jsx(e8,{value:"bom",children:$e.jsx("div",{className:_h("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:$e.jsx(tM,{fallbackRender:({error:ze})=>$e.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:$e.jsxs("div",{className:"rf-p-4",children:[$e.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Bill of Materials"}),$e.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(ze==null?void 0:ze.message)||"An unknown error occurred"})]})}),children:r?$e.jsx(Lsn,{circuitJson:r}):$e.jsx(Uw,{onRunClicked:e})})})}),$e.jsx(e8,{value:"circuit_json",children:$e.jsx("div",{className:_h("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:$e.jsx(tM,{fallback:$e.jsx("div",{children:"Error loading JSON viewer"}),children:r?$e.jsx(Nsn,{elements:r}):$e.jsx(Uw,{onRunClicked:e})})})}),$e.jsx(e8,{value:"errors",children:$e.jsx("div",{className:_h("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Array.isArray(ce)&&ce.length>0||t?$e.jsx(non,{code:n,circuitJsonErrors:ce,errorMessage:t,autoroutingLog:T,onReportAutoroutingLog:P}):$e.jsx(Uw,{onRunClicked:e})})}),c&&$e.jsx(e8,{value:"render_log",children:$e.jsx(A_n,{renderLog:d})})]})})})};var SH="Dialog",[QQe,KQe]=eS(SH),[L_n,L4]=QQe(SH),JQe=n=>{const{__scopeDialog:e,children:t,open:r,defaultOpen:i,onOpenChange:a,modal:o=!0}=n,s=rt.useRef(null),l=rt.useRef(null),[c,u]=kE({prop:r,defaultProp:i??!1,onChange:a,caller:SH});return $e.jsx(L_n,{scope:e,triggerRef:s,contentRef:l,contentId:tS(),titleId:tS(),descriptionId:tS(),open:c,onOpenChange:u,onOpenToggle:rt.useCallback(()=>u(d=>!d),[u]),modal:o,children:t})};JQe.displayName=SH;var eKe="DialogTrigger",tKe=rt.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=L4(eKe,t),a=L_(e,i.triggerRef);return $e.jsx(Ry.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Qpe(i.open),...r,ref:a,onClick:Pp(n.onClick,i.onOpenToggle)})});tKe.displayName=eKe;var Wpe="DialogPortal",[O_n,nKe]=QQe(Wpe,{forceMount:void 0}),rKe=n=>{const{__scopeDialog:e,forceMount:t,children:r,container:i}=n,a=L4(Wpe,e);return $e.jsx(O_n,{scope:e,forceMount:t,children:rt.Children.map(r,o=>$e.jsx(K4,{present:t||a.open,children:$e.jsx(Gce,{asChild:!0,container:i,children:o})}))})};rKe.displayName=Wpe;var wH="DialogOverlay",iKe=rt.forwardRef((n,e)=>{const t=nKe(wH,n.__scopeDialog),{forceMount:r=t.forceMount,...i}=n,a=L4(wH,n.__scopeDialog);return a.modal?$e.jsx(K4,{present:r||a.open,children:$e.jsx(U_n,{...i,ref:e})}):null});iKe.displayName=wH;var z_n=UE("DialogOverlay.RemoveScroll"),U_n=rt.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=L4(wH,t);return $e.jsx(Qce,{as:z_n,allowPinchZoom:!0,shards:[i.contentRef],children:$e.jsx(Ry.div,{"data-state":Qpe(i.open),...r,ref:e,style:{pointerEvents:"auto",...r.style}})})}),qw="DialogContent",aKe=rt.forwardRef((n,e)=>{const t=nKe(qw,n.__scopeDialog),{forceMount:r=t.forceMount,...i}=n,a=L4(qw,n.__scopeDialog);return $e.jsx(K4,{present:r||a.open,children:a.modal?$e.jsx(k_n,{...i,ref:e}):$e.jsx(I_n,{...i,ref:e})})});aKe.displayName=qw;var k_n=rt.forwardRef((n,e)=>{const t=L4(qw,n.__scopeDialog),r=rt.useRef(null),i=L_(e,t.contentRef,r);return rt.useEffect(()=>{const a=r.current;if(a)return fVe(a)},[]),$e.jsx(oKe,{...n,ref:i,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Pp(n.onCloseAutoFocus,a=>{var o;a.preventDefault(),(o=t.triggerRef.current)==null||o.focus()}),onPointerDownOutside:Pp(n.onPointerDownOutside,a=>{const o=a.detail.originalEvent,s=o.button===0&&o.ctrlKey===!0;(o.button===2||s)&&a.preventDefault()}),onFocusOutside:Pp(n.onFocusOutside,a=>a.preventDefault())})}),I_n=rt.forwardRef((n,e)=>{const t=L4(qw,n.__scopeDialog),r=rt.useRef(!1),i=rt.useRef(!1);return $e.jsx(oKe,{...n,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var o,s;(o=n.onCloseAutoFocus)==null||o.call(n,a),a.defaultPrevented||(r.current||(s=t.triggerRef.current)==null||s.focus(),a.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:a=>{var l,c;(l=n.onInteractOutside)==null||l.call(n,a),a.defaultPrevented||(r.current=!0,a.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=a.target;((c=t.triggerRef.current)==null?void 0:c.contains(o))&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&i.current&&a.preventDefault()}})}),oKe=rt.forwardRef((n,e)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...o}=n,s=L4(qw,t),l=rt.useRef(null),c=L_(e,l);return CHe(),$e.jsxs($e.Fragment,{children:[$e.jsx(Pce,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:$e.jsx(Mce,{role:"dialog",id:s.contentId,"aria-describedby":s.descriptionId,"aria-labelledby":s.titleId,"data-state":Qpe(s.open),...o,ref:c,onDismiss:()=>s.onOpenChange(!1)})}),$e.jsxs($e.Fragment,{children:[$e.jsx(B_n,{titleId:s.titleId}),$e.jsx(H_n,{contentRef:l,descriptionId:s.descriptionId})]})]})}),Zpe="DialogTitle",sKe=rt.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=L4(Zpe,t);return $e.jsx(Ry.h2,{id:i.titleId,...r,ref:e})});sKe.displayName=Zpe;var lKe="DialogDescription",cKe=rt.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=L4(lKe,t);return $e.jsx(Ry.p,{id:i.descriptionId,...r,ref:e})});cKe.displayName=lKe;var uKe="DialogClose",dKe=rt.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=L4(uKe,t);return $e.jsx(Ry.button,{type:"button",...r,ref:e,onClick:Pp(n.onClick,()=>i.onOpenChange(!1))})});dKe.displayName=uKe;function Qpe(n){return n?"open":"closed"}var fKe="DialogTitleWarning",[F_n,pKe]=o_t(fKe,{contentName:qw,titleName:Zpe,docsSlug:"dialog"}),B_n=({titleId:n})=>{const e=pKe(fKe),t=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
13455
13455
 
13456
13456
  If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
13457
13457