@tscircuit/runframe 0.0.466 → 0.0.467
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/standalone.min.js
CHANGED
|
@@ -826,7 +826,7 @@ ${a.width}x${a.height}
|
|
|
826
826
|
`)});const i=this.getPointAtDistance(this.headDistanceAlongPath+this.currentStepSize);e.points.push({x:i.x,y:i.y,color:"red",label:["Tentative Head",`z: ${i.z}`].join(`
|
|
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}},_ft=class extends e9{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 cge({}),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 gft({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,n,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:(n=a.layers)!=null&&n.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}},xft=class extends e9{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)&&AG(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=A1(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(n=>t.availableZ.includes(n))}visualize(){const e={lines:[],points:[],rects:this.nodes.map(t=>{const n=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+n*t.width*.05,y:t.center.y-n*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 n=this.nodes.find(a=>a.capacityMeshNodeId===t.nodeIds[0]),i=this.nodes.find(a=>a.capacityMeshNodeId===t.nodeIds[1]);if(n!=null&&n.center&&(i!=null&&i.center)){const a=Math.min(...n.availableZ),o=Math.min(...i.availableZ),s={x:n.center.x+a*n.width*.05,y:n.center.y-a*n.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:n.availableZ.join(",")===i.availableZ.join(",")?void 0:"10 5"})}}return e}},bft=class extends xft{step(){this.edges=[];const r=new Set,e=new PG(this.nodes);for(let t=0;t<this.nodes.length;t++){const n=this.nodes[t],i=e.getNodesInArea(n.center.x,n.center.y,n.width*2,n.height*2);for(const a of i){if(!AG(n,a))continue;!(n._strawNode&&a._strawNode&&n._strawParentCapacityMeshNodeId===a._strawParentCapacityMeshNodeId)&&this.doNodesHaveSharedLayer(n,a)&&!r.has(`${n.capacityMeshNodeId}-${a.capacityMeshNodeId}`)&&(r.add(`${n.capacityMeshNodeId}-${a.capacityMeshNodeId}`),r.add(`${a.capacityMeshNodeId}-${n.capacityMeshNodeId}`),this.edges.push({capacityMeshEdgeId:this.getNextCapacityMeshEdgeId(),nodeIds:[n.capacityMeshNodeId,a.capacityMeshNodeId]}))}}this.handleTargetNodes(),this.solved=!0}},vge=r=>({minX:Math.min(r[0].x,r[1].x),maxX:Math.max(r[0].x,r[1].x),minY:Math.min(r[0].y,r[1].y),maxY:Math.max(r[0].y,r[1].y)});function wL(r,e){const t=r.x-e.x,n=r.y-e.y;return t*t+n*n}function vT(r,e,t){const n=wL(e,t);if(n===0)return wL(r,e);let i=((r.x-e.x)*(t.x-e.x)+(r.y-e.y)*(t.y-e.y))/n;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 wL(r,a)}function Sft(r,e,t,n){if(Gb(r,e,t,n))return 0;const i={x:r.x,y:r.y},a={x:e.x,y:e.y},o={x:t.x,y:t.y},s={x:n.x,y:n.y};return Math.min(vT(i,o,s),vT(a,o,s),vT(o,i,a),vT(s,i,a))}var wft=class{constructor(r,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 n of r){if(!n||!n.connectionName){console.warn("Skipping route with missing data:",n);continue}if(this.routes.has(n.connectionName)){console.warn(`Skipping duplicate route connectionName: ${n.connectionName}`);continue}if(this.routes.set(n.connectionName,n),n.route&&n.route.length>=2)for(let i=0;i<n.route.length-1;i++){const a=n.route[i],o=n.route[i+1];if(a.x===o.x&&a.y===o.y)continue;const s=[a,o],l=vge(s),c={segmentId:`${n.connectionName}-seg-${i}`,segment:s,parentRoute:n},u=Math.floor(l.minX/this.CELL_SIZE),f=Math.floor((l.maxX+t)/this.CELL_SIZE),d=Math.floor(l.minY/this.CELL_SIZE),m=Math.floor((l.maxY+t)/this.CELL_SIZE);for(let y=u;y<=f;y++)for(let w=d;w<=m;w++){const S=`${y}x${w}`;let b=this.segmentBuckets.get(S);b||(b=[],this.segmentBuckets.set(S,b)),b.push(c)}}if(n.vias&&n.vias.length>0)for(let i=0;i<n.vias.length;i++){const a=n.vias[i];if(a==null)continue;const o={viaId:`${n.connectionName}-via-${i}`,x:a.x,y:a.y,parentRoute:n},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(r,e,t){const i=vge([r,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),f=Math.floor((s+c)/this.CELL_SIZE),d=Math.floor(o/this.CELL_SIZE),m=Math.floor((l+c)/this.CELL_SIZE),y=new Map,w=new Set,S=new Set,b={x:r.x,y:r.y},E={x:e.x,y:e.y};for(let U=u;U<=f;U++)for(let V=d;V<=m;V++){const Y=`${U}x${V}`,W=this.segmentBuckets.get(Y);if(W)for(const K of W){if(w.has(K.segmentId))continue;w.add(K.segmentId);const X=K.parentRoute,[ce,pe]=K.segment,ue=t+X.traceThickness/2,Se=ue*ue,he=Sft(r,e,ce,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(Y);if($)for(const K of $){if(S.has(K.viaId))continue;S.add(K.viaId);const X=K.parentRoute,ce={x:K.x,y:K.y},pe=t+X.viaDiameter/2,ue=pe*pe,Se=vT(ce,b,E);if(Se<ue){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(r,e){const t=r.x-e,n=r.y-e,i=r.x+e,a=r.y+e,o=1e-9,s=Math.floor(t/this.CELL_SIZE),l=Math.floor((i+o)/this.CELL_SIZE),c=Math.floor(n/this.CELL_SIZE),u=Math.floor((a+o)/this.CELL_SIZE),f=new Map,d=new Set,m=new Set;for(let w=s;w<=l;w++)for(let S=c;S<=u;S++){const b=`${w}x${S}`,E=this.segmentBuckets.get(b);if(E)for(const U of E){if(d.has(U.segmentId))continue;d.add(U.segmentId);const V=U.parentRoute,Y={x:U.segment[0].x,y:U.segment[0].y},W={x:U.segment[1].x,y:U.segment[1].y},$=e+V.traceThickness/2,K=$*$,X=vT(r,Y,W);if(X<K){const ce=V.connectionName,pe=f.get(ce);(!pe||X<pe.minDistSq)&&f.set(ce,{route:V,minDistSq:X})}}const P=this.viaBuckets.get(b);if(P)for(const U of P){if(m.has(U.viaId))continue;m.add(U.viaId);const V=U.parentRoute,Y={x:U.x,y:U.y},W=e+V.viaDiameter/2,$=W*W,K=wL(r,Y);if(K<$){const X=V.connectionName,ce=f.get(X);(!ce||K<ce.minDistSq)&&f.set(X,{route:V,minDistSq:K})}}}const y=[];for(const w of f.values())y.push({conflictingRoute:w.route,distance:Math.sqrt(w.minDistSq)});return y}},Eft=class extends e9{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=[],n=e.route;if(n.length===0)return[];let i={startIndex:0,endIndex:-1,z:n[0].z,points:[n[0]]};for(let a=1;a<n.length;a++)n[a].z===i.z?i.points.push(n[a]):(i.endIndex=a-1,t.push(i),i={startIndex:a,endIndex:-1,z:n[a].z,points:[n[a]]});return i.endIndex=n.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],n=this.routeSections[this.currentSectionIndex+1];if(e.z!==n.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 n=0;n<e.points.length-1;n++){const i={...e.points[n],z:t},a={...e.points[n+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(tge(i,a,c)<this.TRACE_THICKNESS+this.OBSTACLE_MARGIN)return!1}return!0}getOptimizedHdRoute(){const e=this.routeSections.flatMap(n=>n.points),t=[];for(let n=0;n<e.length-1;n++)e[n].z!==e[n+1].z&&t.push({x:e[n].x,y:e[n].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 n=this.routeSections[t];e.lines.push({points:n.points,strokeWidth:this.TRACE_THICKNESS,strokeColor:t===this.currentSectionIndex?"orange":n.z===0?"red":"blue"})}return e}},Tft=class extends e9{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 Qye(e.obstacles),this.hdRouteSHI=new wft(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 Eft({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 n=0;n<t.route.length-1;n++){const i=t.route[n],a=t.route[n+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 n of t.vias)e.circles.push({center:{x:n.x,y:n.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 r3(r,e,t,n={}){return{solverName:r,solverClass:e,getConstructorParams:t,onSolved:n.onSolved}}var Mft=class extends e9{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",[r3("netToPointPairsSolver",Zut,e=>[e.srj,e.colorMap],{onSolved:e=>{var t;e.srjWithPointPairs=(t=e.netToPointPairsSolver)==null?void 0:t.getNewSimpleRouteJson(),e.colorMap=CG(e.srjWithPointPairs,this.connMap),e.connMap=uge(e.srjWithPointPairs)}}),r3("nodeSolver",but,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}}),r3("singleLayerNodeMerger",fft,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}}),r3("strawSolver",uft,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()}}),r3("edgeSolver",bft,e=>[e.capacityNodes]),r3("pathingSolver",cft,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}}]}),r3("edgeToPortSegmentSolver",Sut,e=>{var t,n;return[{nodes:e.capacityNodes,edges:((t=e.edgeSolver)==null?void 0:t.edges)||[],capacityPaths:((n=e.pathingSolver)==null?void 0:n.getCapacityPaths())||[],colorMap:e.colorMap}]}),r3("segmentToPointSolver",Mut,e=>{var n;const t=[];return(n=e.edgeToPortSegmentSolver)!=null&&n.nodePortSegments&&e.edgeToPortSegmentSolver.nodePortSegments.forEach(i=>{t.push(...i)}),[{segments:t,colorMap:e.colorMap,nodes:e.capacityNodes}]}),r3("unravelMultiSectionSolver",sft,e=>{var t;return[{assignedSegments:((t=e.segmentToPointSolver)==null?void 0:t.solvedSegments)||[],colorMap:e.colorMap,nodes:e.capacityNodes}]}),r3("highDensityRouteSolver",qut,e=>{var t,n;return[{nodePortPoints:((t=e.unravelMultiSectionSolver)==null?void 0:t.getNodesWithPortPoints())??((n=e.segmentToPointOptimizer)==null?void 0:n.getNodesWithPortPoints())??[],colorMap:e.colorMap,connMap:e.connMap}]}),r3("highDensityStitchSolver",Jut,e=>[{connections:e.srjWithPointPairs.connections,hdRoutes:e.highDensityRouteSolver.routes,layerCount:e.srj.layerCount}]),r3("uselessViaRemovalSolver",Tft,e=>[{unsimplifiedHdRoutes:e.highDensityStitchSolver.mergedHdRoutes,obstacles:e.srj.obstacles,colorMap:e.colorMap,layerCount:e.srj.layerCount}]),r3("multiSimplifiedPathSolver",_ft,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 n=e.bounds.maxX-e.bounds.minX,i=e.bounds.maxY-e.bounds.minY,a=Math.max(n,i),o=t.targetMinCapacity??.5;t.capacityDepth=gut(a,o)}this.connMap=uge(e),this.colorMap=CG(e,this.connMap),this.startTimeOfPhase={},this.endTimeOfPhase={},this.timeSpentOnPhase={}}_step(){var n,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],(n=e.onSolved)==null||n.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 b,E,P,U,V,Y,W,$,K,X,ce,pe,ue,Se,he,ge,Te,xe,Pe,De,Ue,Re,$e,Ke,ut;if(!this.solved&&this.activeSubSolver)return this.activeSubSolver.visualize();const e=(b=this.netToPointPairsSolver)==null?void 0:b.visualize(),t=(E=this.nodeSolver)==null?void 0:E.visualize(),n=(P=this.nodeTargetMerger)==null?void 0:P.visualize(),i=(U=this.singleLayerNodeMerger)==null?void 0:U.visualize(),a=(V=this.strawSolver)==null?void 0:V.visualize(),o=(Y=this.edgeSolver)==null?void 0:Y.visualize(),s=(W=this.pathingSolver)==null?void 0:W.visualize(),l=($=this.edgeToPortSegmentSolver)==null?void 0:$.visualize(),c=(K=this.segmentToPointSolver)==null?void 0:K.visualize(),u=((X=this.unravelMultiSectionSolver)==null?void 0:X.visualize())??((ce=this.segmentToPointOptimizer)==null?void 0:ce.visualize()),f=(pe=this.highDensityRouteSolver)==null?void 0:pe.visualize(),d=(ue=this.highDensityStitchSolver)==null?void 0:ue.visualize(),m=(Se=this.uselessViaRemovalSolver)==null?void 0:Se.visualize(),y=(he=this.multiSimplifiedPathSolver)==null?void 0:he.visualize(),w={points:[...this.srj.connections.flatMap(pt=>pt.pointsToConnect.map(At=>({...At,label:`${pt.name} ${At.pcb_port_id??""}`})))],rects:[...(this.srj.obstacles??[]).map(pt=>{var At,Bt,Qt;return{...pt,fill:(At=pt.layers)!=null&&At.includes("top")?"rgba(255,0,0,0.25)":(Bt=pt.layers)!=null&&Bt.includes("bottom")?"rgba(0,0,255,0.25)":"rgba(255,0,0,0.25)",label:(Qt=pt.layers)==null?void 0:Qt.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:((Pe=this.srj.bounds)==null?void 0:Pe.minY)??-50},{x:((De=this.srj.bounds)==null?void 0:De.maxX)??50,y:((Ue=this.srj.bounds)==null?void 0:Ue.maxY)??50},{x:((Re=this.srj.bounds)==null?void 0:Re.minX)??-50,y:(($e=this.srj.bounds)==null?void 0:$e.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)"}]},S=[w,e,t,n,i,a,o,s,l,c,u,f?dL(w,f):null,d,m,y,this.solved?dL(w,eft(this.getOutputSimpleRouteJson())):null].filter(Boolean);return dL(...S)}preview(){var e;if(this.highDensityRouteSolver){const t=[];for(let n=this.highDensityRouteSolver.routes.length-1;n>=0;n--){const i=this.highDensityRouteSolver.routes[n];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 n of this.pathingSolver.connectionsWithNodes)n.path&&t.push({points:n.path.map(i=>({x:i.center.x,y:i.center.y})),strokeColor:this.colorMap[n.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 n;if(!this.solved||!this.highDensityRouteSolver)throw new Error("Cannot get output before solving is complete");const e=[],t=this._getOutputHdRoutes();for(const i of((n=this.netToPointPairsSolver)==null?void 0:n.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:Qut(s,this.srj.layerCount)};e.push(l)}}return e}getOutputSimpleRouteJson(){return{...this.srj,traces:this.getOutputSimplifiedPcbTraces()}}},DG=Mft,z5=(r,e={})=>{let t=r._internal_store;if(!t){t={counts:{},editCount:0},r._internal_store=t;for(const i of r){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()=>(r.editCount=t.editCount,r);if(a==="editCount")return t.editCount;const o=a;return{get:s=>r.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",""),f=r.find(d=>d.type===u&&d[c]===s[c]);return f?r.find(d=>d.type===o&&d[`${o}_id`]===f[`${o}_id`]):null},getWhere:s=>{const l=Object.keys(s);return r.find(c=>c.type===o&&l.every(u=>c[u]===s[u]))},list:s=>{const l=s?Object.keys(s):[];return r.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&&(kN[o]??J7).parse(c),r.push(c),t.editCount++,c},delete:s=>{const l=r.find(c=>c[`${o}_id`]===s);l&&(r.splice(r.indexOf(l),1),t.editCount++)},update:(s,l)=>{const c=r.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 r.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=r.find(d=>d.type==="source_component"&&d.name===l);if(!u)return null;const f=r.find(d=>d.type==="source_port"&&d.source_component_id===u.source_component_id&&(d.name===c||(d.port_hints??[]).includes(c)));if(!f)return null;if(o==="source_port")return f;if(o==="pcb_port")return r.find(d=>d.type==="pcb_port"&&d.source_port_id===f.source_port_id);if(o==="schematic_port")return r.find(d=>d.type==="schematic_port"&&d.source_port_id===f.source_port_id)}}}}})};z5.unparsed=z5;var i3=z5,A3=z5;function LG(r){const e=r.type;return`${e}:${r[`${e}_id`]}`}var yge=(r,e={})=>{let t=r._internal_store_indexed;if(!t){t={counts:{},editCount:0,indexes:{}};for(const o of r){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 r){if(i.byId){const s=LG(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,f=u.get(c)||[];f.push(o),u.set(c,f),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),f=u.get(c)||[];f.push(o),u.set(c,f)}}}}r._internal_store_indexed=t}return new Proxy({},{get:(i,a)=>{if(a==="toArray")return()=>(r.editCount=t.editCount,r);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:r.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],f=u.replace("_id","");if(l.byRelation&&t.indexes.byRelation){const m=t.indexes.byRelation.get(u);if(m){const w=(m.get(s[u])||[]).find(b=>b.type===f);if(!w)return null;const S=w[`${o}_id`];return l.byId&&t.indexes.byId?t.indexes.byId.get(`${o}:${S}`)||null:l.byType&&t.indexes.byType?(t.indexes.byType.get(o)||[]).find(E=>E[`${o}_id`]===S)||null:r.find(b=>b.type===o&&b[`${o}_id`]===S)||null}}const d=r.find(m=>m.type===f&&m[u]===s[u]);return d&&r.find(m=>m.type===o&&m[`${o}_id`]===d[`${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],f=t.indexes.byCustomField.get(u);if(f){const d=String(s[u]);return(f.get(d)||[]).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(d=>d.type===o&&c.every(m=>d[m]===s[m]))||null}return l.byType&&t.indexes.byType?(t.indexes.byType.get(o)||[]).find(f=>c.every(d=>f[d]===s[d]))||null:r.find(u=>u.type===o&&c.every(f=>u[f]===s[f]))||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 f=s.subcircuit_id;return(t.indexes.bySubcircuit.get(f)||[]).filter(m=>m.type===o)}let u;return l.byType&&t.indexes.byType?u=t.indexes.byType.get(o)||[]:u=r.filter(f=>f.type===o),c.length>0?u.filter(f=>c.every(d=>f[d]===s[d])):u},insert:s=>{var f;(f=t.counts)[o]??(f[o]=-1),t.counts[o]++;const l=t.counts[o],c={type:o,[`${o}_id`]:`${o}_${l}`,...s};e.validateInserts&&(kN[o]??J7).parse(c),r.push(c),t.editCount++;const u=e.indexConfig||{};if(u.byId&&t.indexes.byId){const d=LG(c);t.indexes.byId.set(d,c)}if(u.byType&&t.indexes.byType){const d=t.indexes.byType.get(o)||[];d.push(c),t.indexes.byType.set(o,d)}if(u.byRelation&&t.indexes.byRelation){const d=Object.entries(c);for(const[m,y]of d)if(m.endsWith("_id")&&m!==`${c.type}_id`&&typeof y=="string"){const w=t.indexes.byRelation.get(m)||new Map,S=w.get(y)||[];S.push(c),w.set(y,S),t.indexes.byRelation.set(m,w)}}if(u.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in c){const d=c.subcircuit_id;if(d&&typeof d=="string"){const m=t.indexes.bySubcircuit.get(d)||[];m.push(c),t.indexes.bySubcircuit.set(d,m)}}if(u.byCustomField&&t.indexes.byCustomField){for(const d of u.byCustomField)if(d in c){const m=c[d];if(m!==void 0&&(typeof m=="string"||typeof m=="number")){const y=String(m),w=t.indexes.byCustomField.get(d),S=w.get(y)||[];S.push(c),w.set(y,S)}}}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(d=>d[`${o}_id`]===s):c=r.find(f=>f[`${o}_id`]===s),!c)return;const u=r.indexOf(c);if(u>=0&&(r.splice(u,1),t.editCount++),l.byId&&t.indexes.byId){const f=LG(c);t.indexes.byId.delete(f)}if(l.byType&&t.indexes.byType){const d=(t.indexes.byType.get(o)||[]).filter(m=>m[`${o}_id`]!==s);t.indexes.byType.set(o,d)}if(l.byRelation&&t.indexes.byRelation)for(const[f,d]of t.indexes.byRelation.entries())for(const[m,y]of d.entries()){const w=y.filter(S=>S!==c);w.length===0?d.delete(m):d.set(m,w)}if(l.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in c){const f=c.subcircuit_id;if(f){const m=(t.indexes.bySubcircuit.get(f)||[]).filter(y=>y!==c);m.length===0?t.indexes.bySubcircuit.delete(f):t.indexes.bySubcircuit.set(f,m)}}if(l.byCustomField&&t.indexes.byCustomField)for(const f of t.indexes.byCustomField.values())for(const[d,m]of f.entries()){const y=m.filter(w=>w!==c);y.length===0?f.delete(d):f.set(d,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(d=>d[`${o}_id`]===s):u=r.find(f=>f.type===o&&f[`${o}_id`]===s),!u)return null;if(c.byRelation&&t.indexes.byRelation){const f=Object.entries(u);for(const[d,m]of f)if(d.endsWith("_id")&&d!==`${u.type}_id`&&typeof m=="string"&&d in l&&l[d]!==m){const y=t.indexes.byRelation.get(d);if(y){const S=(y.get(m)||[]).filter(b=>b!==u);S.length===0?y.delete(m):y.set(m,S)}}}if(c.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in u&&"subcircuit_id"in l){const f=u.subcircuit_id,d=l.subcircuit_id;if(f!==d){const y=(t.indexes.bySubcircuit.get(f)||[]).filter(w=>w!==u);y.length===0?t.indexes.bySubcircuit.delete(f):t.indexes.bySubcircuit.set(f,y)}}if(c.byCustomField&&t.indexes.byCustomField){for(const f of c.byCustomField)if(f in u&&f in l&&u[f]!==l[f]){const d=t.indexes.byCustomField.get(f);if(d){const m=String(u[f]),w=(d.get(m)||[]).filter(S=>S!==u);w.length===0?d.delete(m):d.set(m,w)}}}if(Object.assign(u,l),t.editCount++,c.byRelation&&t.indexes.byRelation){const f=Object.entries(u);for(const[d,m]of f)if(d.endsWith("_id")&&d!==`${u.type}_id`&&typeof m=="string"&&d in l){const y=t.indexes.byRelation.get(d)||new Map,w=y.get(m)||[];w.includes(u)||(w.push(u),y.set(m,w),t.indexes.byRelation.set(d,y))}}if(c.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in u&&"subcircuit_id"in l){const f=u.subcircuit_id;if(f&&typeof f=="string"){const d=t.indexes.bySubcircuit.get(f)||[];d.includes(u)||(d.push(u),t.indexes.bySubcircuit.set(f,d))}}if(c.byCustomField&&t.indexes.byCustomField){for(const f of c.byCustomField)if(f in u&&f in l){const d=u[f];if(d!==void 0&&(typeof d=="string"||typeof d=="number")){const m=String(d),y=t.indexes.byCustomField.get(f),w=y.get(m)||[];w.includes(u)||(w.push(u),y.set(m,w))}}}return u},select:s=>{if(o==="source_component")return r.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=r.find(d=>d.type==="source_component"&&d.name===l);if(!u)return null;const f=r.find(d=>d.type==="source_port"&&d.source_component_id===u.source_component_id&&(d.name===c||(d.port_hints??[]).includes(c)));if(!f)return null;if(o==="source_port")return f;if(o==="pcb_port")return r.find(d=>d.type==="pcb_port"&&d.source_port_id===f.source_port_id)||null;if(o==="schematic_port")return r.find(d=>d.type==="schematic_port"&&d.source_port_id===f.source_port_id)||null}return null}}}})};yge.unparsed=yge;var Cft=(r,e)=>{if(r.type==="pcb_plated_hole"||r.type==="pcb_hole"||r.type==="pcb_via"||r.type==="pcb_smtpad"||r.type==="pcb_port"){const{x:t,y:n}=kr(e,{x:r.x,y:r.y});r.x=t,r.y=n}else if(r.type==="pcb_keepout"||r.type==="pcb_board")r.center=kr(e,r.center);else if(r.type==="pcb_silkscreen_text"||r.type==="pcb_fabrication_note_text")r.anchor_position=kr(e,r.anchor_position);else if(r.type==="pcb_silkscreen_circle"||r.type==="pcb_silkscreen_rect"||r.type==="pcb_component")r.center=kr(e,r.center);else if(r.type==="pcb_silkscreen_path"||r.type==="pcb_trace"||r.type==="pcb_fabrication_note_path")r.route=r.route.map(t=>{const n=kr(e,t);return t.x=n.x,t.y=n.y,t});else if(r.type==="pcb_silkscreen_line"){const t={x:r.x1,y:r.y1},n={x:r.x2,y:r.y2},i=kr(e,t),a=kr(e,n);r.x1=i.x,r.y1=i.y,r.x2=a.x,r.y2=a.y}else if(r.type==="cad_component"){const t=kr(e,{x:r.position.x,y:r.position.y});r.position.x=t.x,r.position.y=t.y}return r},gge=r=>{const e=r.type;return r[`${e}_id`]},Rft=(r,e)=>r.find(t=>gge(t)===e)??null;function Aft(r,e){const t=z5(r).pcb_trace.get(e);if(!t)return`trace[${e}]`;const n=t.route.flatMap(o=>[o.start_pcb_port_id,o.end_pcb_port_id]).filter(Boolean);if(n.length===0)return`trace[${e}]`;function i(o){const s=z5(r).pcb_port.get(o);if(!s)return null;const l=z5(r).pcb_component.get(s.pcb_component_id);if(!l)return null;const c=z5(r).source_component.get(l.source_component_id);if(!c)return null;const u=z5(r).source_port.get(s.source_port_id),f=u!=null&&u.port_hints?u.port_hints[1]:"";return{componentName:c.name,portHint:f}}return`trace[${n.map(o=>{const s=i(o);return s?`.${s.componentName} > port.${s.portHint}`:`port[${o}]`}).join(", ")}]`}var _ge=(r,e)=>{const t=z5(r).pcb_port.get(e);if(!t)return`pcb_port[#${e}]`;const n=z5(r).pcb_component.get(t==null?void 0:t.pcb_component_id);if(!n)return`pcb_port[#${e}]`;const i=z5(r).source_component.get(n.source_component_id);if(!i)return`pcb_port[#${e}]`;const a=z5(r).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 Pft(r,e){const t=z5(r).pcb_smtpad.get(e);return!t||!t.pcb_port_id?`smtpad[${e}]`:_ge(r,t.pcb_port_id)}var OG=(r,e)=>{if(typeof e=="string"){const t=Rft(r,e);return OG(r,t)}switch(e.type){case"pcb_port":return _ge(r,e.pcb_port_id);case"pcb_smtpad":return Pft(r,e.pcb_smtpad_id);case"pcb_trace":return Aft(r,e.pcb_trace_id);case"source_component":return`source_component[${e.name}]`;default:return`${e.type}[#${gge(e)}]`}},xge=r=>{let e=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(const a of r){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),n=Math.max(n,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),n=Math.max(n,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),n=Math.max(n,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),n=Math.max(n,u.x),i=Math.max(i,u.y)}return{minX:e,minY:t,maxX:n,maxY:i}},yT=r=>r[`${r.type}_id`],Nft=class{constructor({objects:e,getBounds:t,getId:n,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=n??(()=>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),n=this.getId(e),i={...e,spatialIndexId:n};this.objectsById.set(n,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 f=`${c}x${u}`,d=this.buckets.get(f);d?d.push(i):this.buckets.set(f,[i])}}removeObject(e){const t=this.objectsById.get(e);if(!t)return!1;this.objectsById.delete(e);const n=this.getBounds(t),i=Math.floor(n.minX/this.CELL_SIZE),a=Math.floor(n.minY/this.CELL_SIZE),o=Math.floor(n.maxX/this.CELL_SIZE),s=Math.floor(n.maxY/this.CELL_SIZE);for(let l=i;l<=o;l++)for(let c=a;c<=s;c++){const u=`${l}x${c}`,f=this.buckets.get(u);if(f){const d=f.findIndex(m=>m.spatialIndexId===e);d!==-1&&(f.splice(d,1),f.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 n=[],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 f=`${c}x${u}`,d=this.buckets.get(f)||[];for(const m of d){const y=m.spatialIndexId;i.has(y)||(i.add(y),n.push(m))}}return n}},pC=r=>r.type==="pcb_trace_segment"?{minX:Math.min(r.x1,r.x2),minY:Math.min(r.y1,r.y2),maxX:Math.max(r.x1,r.x2),maxY:Math.max(r.y1,r.y2)}:xge([r]),zG=.1,Dft=.15,UG=.005;function Lft(r){const e=new Set;for(const t of r.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 kG(r){const e=new Set;for(const t of r)for(const n of Lft(t))e.add(n);return Array.from(e)}var Oft=(r,e)=>{const t={x:r.x1,y:r.y1},n={x:r.x2,y:r.y2},i={x:e.x1,y:e.y1},a={x:e.x2,y:e.y2},o={x:n.x-t.x,y:n.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 $=B4(((t.x-i.x)*s.x+(t.y-i.y)*s.y)/c,0,1),K={x:i.x+$*s.x,y:i.y+$*s.y};return{x:(t.x+K.x)/2,y:(t.y+K.y)/2}}const Y=B4(((i.x-t.x)*o.x+(i.y-t.y)*o.y)/l,0,1),W={x:t.x+Y*o.x,y:t.y+Y*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},f=o.x*o.x+o.y*o.y,d=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,w=s.x*u.x+s.y*u.y,S=f*y-d*d;if(S<1e-10)return zft(t,n,i,a,o,s,l,c);let b=(d*w-y*m)/S,E=(f*w-d*m)/S;b=B4(b,0,1),E=B4(E,0,1),E=(b*d+w)/y,E=B4(E,0,1),b=(E*d-m)/f,b=B4(b,0,1);const P={x:t.x+b*o.x,y:t.y+b*o.y},U={x:i.x+E*s.x,y:i.y+E*s.y};return{x:(P.x+U.x)/2,y:(P.y+U.y)/2}},zft=(r,e,t,n,i,a,o,s)=>{let l=((t.x-r.x)*i.x+(t.y-r.y)*i.y)/o;l=B4(l,0,1);const c={x:r.x+l*i.x,y:r.y+l*i.y};let u=((n.x-r.x)*i.x+(n.y-r.y)*i.y)/o;u=B4(u,0,1);const f={x:r.x+u*i.x,y:r.y+u*i.y};let d=((r.x-t.x)*a.x+(r.y-t.y)*a.y)/s;d=B4(d,0,1);const m={x:t.x+d*a.x,y:t.y+d*a.y};let y=((e.x-t.x)*a.x+(e.y-t.y)*a.y)/s;y=B4(y,0,1);const w={x:t.x+y*a.x,y:t.y+y*a.y},b=[{pointA:c,pointB:t,distance:Math.sqrt((c.x-t.x)**2+(c.y-t.y)**2)},{pointA:f,pointB:n,distance:Math.sqrt((f.x-n.x)**2+(f.y-n.y)**2)},{pointA:r,pointB:m,distance:Math.sqrt((r.x-m.x)**2+(r.y-m.y)**2)},{pointA:e,pointB:w,distance:Math.sqrt((e.x-w.x)**2+(e.y-w.y)**2)}].reduce((E,P)=>P.distance<E.distance?P:E);return{x:(b.pointA.x+b.pointB.x)/2,y:(b.pointA.y+b.pointB.y)/2}},B4=(r,e,t)=>Math.max(e,Math.min(t,r)),Uft=r=>{if(r.type==="pcb_via"||r.type==="pcb_plated_hole"&&r.shape==="circle")return r.outer_diameter/2;if(r.type==="pcb_hole"&&r.hole_shape==="circle")return r.hole_diameter/2;if(r.type==="pcb_smtpad"&&r.shape==="circle")return r.radius;throw new Error(`Could not determine radius of element: ${JSON.stringify(r)}`)},bge=(r,e)=>{const t={x:r.x1,y:r.y1},n={x:r.x2,y:r.y2},i=e.minX,a=e.minY,o=e.maxX,s=e.maxY;if(t.x===n.x&&t.y===n.y){const $=Math.max(i,Math.min(o,t.x)),K=Math.max(a,Math.min(s,t.y));return $===t.x&&K===t.y?{x:t.x,y:t.y}:{x:$,y:K}}const l=n.x-t.x,c=n.y-t.y,u=l!==0?(i-t.x)/l:Number.NEGATIVE_INFINITY,f=l!==0?(o-t.x)/l:Number.POSITIVE_INFINITY,d=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,f),Math.min(d,m)),w=Math.min(Math.max(u,f),Math.max(d,m));if(y<=w&&w>=0&&y<=1){const $=Math.max(0,Math.min(1,y));return{x:t.x+$*l,y:t.y+$*c}}const S={x:Math.max(i,Math.min(o,t.x)),y:Math.max(a,Math.min(s,t.y))},b={x:Math.max(i,Math.min(o,n.x)),y:Math.max(a,Math.min(s,n.y))},E=(S.x-t.x)**2+(S.y-t.y)**2,P=(b.x-n.x)**2+(b.y-n.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 V=Math.min(E,P),Y=E<=P?S:b;const W=($,K,X)=>Math.max(K,Math.min(X,$));for(const $ of U){const K={x:n.x-t.x,y:n.y-t.y},X={x:$.end.x-$.start.x,y:$.end.y-$.start.y},ce={x:t.x-$.start.x,y:t.y-$.start.y},pe=K.x*K.x+K.y*K.y,ue=K.x*X.x+K.y*X.y,Se=K.x*ce.x+K.y*ce.y,he=X.x*X.x+X.y*X.y,ge=X.x*ce.x+X.y*ce.y,Te=pe*he-ue*ue;if(Math.abs(Te)<1e-10)continue;let xe=(ue*ge-he*Se)/Te,Pe=(pe*ge-ue*Se)/Te;xe=W(xe,0,1),Pe=W(Pe,0,1);const De={x:t.x+xe*K.x,y:t.y+xe*K.y},Ue={x:$.start.x+Pe*X.x,y:$.start.y+Pe*X.y},Re=De.x-Ue.x,$e=De.y-Ue.y,Ke=Re*Re+$e*$e;Ke<V&&(V=Ke,Y={x:(De.x+Ue.x)/2,y:(De.y+Ue.y)/2})}return Y};function kft(r){return r.type==="pcb_trace_segment"?[r.layer]:r.type==="pcb_smtpad"?[r.layer]:r.type==="pcb_plated_hole"?Array.isArray(r.layers)?r.layers:[...K7]:r.type==="pcb_hole"?[...K7]:r.type==="pcb_via"?Array.isArray(r.layers)?r.layers:[...K7]:r.type==="pcb_keepout"?Array.isArray(r.layers)?r.layers:[]:[]}function Sge(r,{connMap:e}={}){const t=[];e??(e=n4(r));const i=A3(r).pcb_trace.list().flatMap(y=>{const w=[];for(let S=0;S<y.route.length-1;S++){const b=y.route[S],E=y.route[S+1];b.route_type==="wire"&&E.route_type==="wire"&&b.layer===E.layer&&w.push({type:"pcb_trace_segment",pcb_trace_id:y.pcb_trace_id,_pcbTrace:y,thickness:"width"in b?b.width:"width"in E?E.width:Dft,layer:b.layer,x1:b.x,y1:b.y,x2:E.x,y2:E.y})}return w}),a=A3(r).pcb_smtpad.list(),o=A3(r).pcb_plated_hole.list(),s=A3(r).pcb_hole.list(),l=A3(r).pcb_via.list(),c=A3(r).pcb_keepout.list(),u=[...i,...a,...o,...s,...l,...c],f=new Nft({objects:u,getBounds:pC}),d=y=>OG(r,y),m=new Set;for(const y of i){const w=zG,S=pC(y),b=f.getObjectsInBounds(S,w+y.thickness/2);if(!(y.x1===y.x2&&y.y1===y.y2))for(const E of b){if(!kft(E).includes(y.layer))continue;if(E.type==="pcb_trace_segment"){const Y=E;if(y.layer!==Y.layer||e.areIdsConnected(y.pcb_trace_id,Y.pcb_trace_id))continue;const W=yct({x:y.x1,y:y.y1},{x:y.x2,y:y.y2},{x:Y.x1,y:Y.y1},{x:Y.x2,y:Y.y2})-y.thickness/2-Y.thickness/2;if(W>zG-UG)continue;const $=`overlap_${y.pcb_trace_id}_${Y.pcb_trace_id}`,K=`overlap_${Y.pcb_trace_id}_${y.pcb_trace_id}`;if(m.has($)||m.has(K))continue;m.add($),t.push({type:"pcb_trace_error",error_type:"pcb_trace_error",message:`PCB trace ${d(y.pcb_trace_id)} overlaps with ${d(Y.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:Oft(y,Y),pcb_port_ids:kG([y._pcbTrace,Y._pcbTrace])});continue}const P=yT(E);if(e.areIdsConnected(y.pcb_trace_id,"pcb_trace_id"in E?E.pcb_trace_id:P))continue;if(E.type==="pcb_via"||E.type==="pcb_plated_hole"&&E.shape==="circle"||E.type==="pcb_hole"||E.type==="pcb_smtpad"&&E.shape==="circle"){const Y=Uft(E),$=_ct({x:y.x1,y:y.y1},{x:y.x2,y:y.y2},{x:E.x,y:E.y,radius:Y})-y.thickness/2;if($>zG-UG)continue;const K=`overlap_${y.pcb_trace_id}_${P}`;if(m.has(K))continue;m.add(K),t.push({type:"pcb_trace_error",error_type:"pcb_trace_error",message:`PCB trace ${d(y.pcb_trace_id)} overlaps with ${E.type} "${d(yT(E))}" ${$<0?"(accidental contact)":`(gap: ${$.toFixed(3)}mm)`}`,pcb_trace_id:y.pcb_trace_id,center:bge(y,pC(E)),source_trace_id:"",pcb_trace_error_id:K,pcb_component_ids:["pcb_component_id"in E?E.pcb_component_id:void 0].filter(Boolean),pcb_port_ids:[...kG([y._pcbTrace]),"pcb_port_id"in E?E.pcb_port_id:void 0].filter(Boolean)})}const V=gct({x:y.x1,y:y.y1},{x:y.x2,y:y.y2},pC(E))-y.thickness/2;if(V+UG<w){const Y=`overlap_${y.pcb_trace_id}_${P}`;if(m.has(Y))continue;m.add(Y),t.push({type:"pcb_trace_error",error_type:"pcb_trace_error",message:`PCB trace ${d(y.pcb_trace_id)} overlaps with ${E.type} "${d(yT(E))}" ${V<0?"(accidental contact)":`(gap: ${V.toFixed(3)}mm)`}`,pcb_trace_id:y.pcb_trace_id,source_trace_id:"",pcb_trace_error_id:Y,pcb_component_ids:["pcb_component_id"in E?E.pcb_component_id:void 0].filter(Boolean),center:bge(y,pC(E)),pcb_port_ids:[...kG([y._pcbTrace]),"pcb_port_id"in E?E.pcb_port_id:void 0].filter(Boolean)})}}}return t}var IG=[{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 P3(r){if(r==null)return"";if(r===0)return"0";const e=Math.abs(r),t=IG.find(a=>{const o=e/a.value;return o>=1&&o<1e3})||IG[IG.length-1];let i=(r/t.value).toPrecision(3);return i.includes(".")&&!/\.0+$/.test(i)&&(i=i.replace(/0+$/,"")),i=i.replace(/\.0+$/,""),`${i}${t.symbol}`}var Ift=Object.defineProperty,Fft=(r,e)=>{for(var t in e)Ift(r,t,{get:e[t],enumerable:!0})},wge={};Fft(wge,{Battery:()=>Kdt,Board:()=>Odt,Capacitor:()=>Udt,Chip:()=>qge,Constraint:()=>Vdt,Crystal:()=>opt,Diode:()=>kdt,FabricationNotePath:()=>Gdt,FabricationNoteText:()=>qdt,Footprint:()=>ldt,Group:()=>XG,Hole:()=>zge,Inductor:()=>npt,Jumper:()=>Idt,Keepout:()=>VG,Led:()=>Fdt,Mosfet:()=>lpt,Net:()=>Pge,NetAlias:()=>Ydt,NormalComponent:()=>Jx,PcbTrace:()=>Lge,PinHeader:()=>Jdt,PlatedHole:()=>Oge,Port:()=>US,Potentiometer:()=>ipt,PowerSource:()=>Bdt,PrimitiveComponent:()=>N_,PushButton:()=>apt,Renderable:()=>Ege,Resistor:()=>jdt,Resonator:()=>tpt,SchematicText:()=>upt,SilkscreenCircle:()=>Xdt,SilkscreenLine:()=>Zdt,SilkscreenPath:()=>Dge,SilkscreenRect:()=>Wdt,SilkscreenText:()=>GG,SmtPad:()=>HG,Subcircuit:()=>$dt,Switch:()=>cpt,Trace:()=>a8,TraceHint:()=>Hge,Transistor:()=>spt,Via:()=>Qdt});var Bft=Jm("tscircuit:renderable"),U5=["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"],jft=0,Ege=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=`${jft++}`,this.children=[],this.renderPhaseStates={};for(const t of U5)this.renderPhaseStates[t]={initialized:!1,dirty:!1}}_markDirty(e){var n;this.renderPhaseStates[e].dirty=!0;const t=U5.indexOf(e);for(let i=t+1;i<U5.length;i++)this.renderPhaseStates[U5[i]].dirty=!0;(n=this.parent)!=null&&n._markDirty&&this.parent._markDirty(e)}_queueAsyncEffect(e,t){const n={promise:t(),phase:this._currentRenderPhase,effectName:e,complete:!1};this._asyncEffects.push(n),"root"in this&&this.root&&this.root.emit("asyncEffect:start",{effectName:e,componentDisplayName:this.getString(),phase:n.phase}),n.promise.then(()=>{n.complete=!0,"root"in this&&this.root&&this.root.emit("asyncEffect:end",{effectName:e,componentDisplayName:this.getString(),phase:n.phase})}).catch(i=>{console.error(`Async effect error in ${n.phase} "${e}":
|
|
829
|
-
${i.stack}`),n.complete=!0,"root"in this&&this.root&&this.root.emit("asyncEffect:end",{effectName:e,componentDisplayName:this.getString(),phase:n.phase,error:i.toString()})})}_emitRenderLifecycleEvent(e,t){Bft(`${e}:${t} ${this.getString()}`);const n=`renderable:renderLifecycle:${e}:${t}`,i={renderId:this._renderId,componentDisplayName:this.getString(),type:n};"root"in this&&this.root&&(this.root.emit(n,i),this.root.emit("renderable:renderLifecycle:anyEvent",{...i,type:n}))}getString(){return this.constructor.name}_hasIncompleteAsyncEffects(){return this._asyncEffects.some(e=>!e.complete)}getCurrentRenderPhase(){return this._currentRenderPhase}getRenderGraph(){return{id:this._renderId,currentPhase:this._currentRenderPhase,renderPhaseStates:this.renderPhaseStates,shouldBeRemoved:this.shouldBeRemoved,children:this.children.map(e=>e.getRenderGraph())}}runRenderCycle(){for(const e of U5)this.runRenderPhaseForChildren(e),this.runRenderPhase(e)}runRenderPhase(e){var o,s,l;this._currentRenderPhase=e;const t=this.renderPhaseStates[e],n=t.initialized,i=t.dirty;if(!n&&this.shouldBeRemoved)return;if(this.shouldBeRemoved&&n){this._emitRenderLifecycleEvent(e,"start"),(o=this==null?void 0:this[`remove${e}`])==null||o.call(this),t.initialized=!1,t.dirty=!1,this._emitRenderLifecycleEvent(e,"end");return}const a=U5.indexOf(e)-1;if(a>=0){const c=U5[a];if(this._asyncEffects.filter(f=>f.phase===c).some(f=>!f.complete))return}if(this._emitRenderLifecycleEvent(e,"start"),n){i&&((s=this==null?void 0:this[`update${e}`])==null||s.call(this),t.dirty=!1),this._emitRenderLifecycleEvent(e,"end");return}t.dirty=!1,(l=this==null?void 0:this[`doInitial${e}`])==null||l.call(this),t.initialized=!0,this._emitRenderLifecycleEvent(e,"end")}runRenderPhaseForChildren(e){for(const t of this.children)t.runRenderPhaseForChildren(e),t.runRenderPhase(e)}renderError(e){throw typeof e=="string"?new Error(e):new Error(JSON.stringify(e,null,2))}},EL={},Tge=r=>{const e=Object.fromEntries(Object.entries(r).map(([t,n])=>[t.toLowerCase(),n]));Object.assign(EL,r),Object.assign(EL,e)},Hft=class extends Error{constructor(e,t,n){let i;const o=Object.keys(n).filter(s=>s!=="_errors").map(s=>n[s]._errors[0]?`${s} (${n[s]._errors[0]})`:`${s} (${JSON.stringify(n[s])})`).join(", ");"name"in t?i=`Invalid props for ${e} "${t.name}": ${o}`:"footprint"in t&&typeof t.footprint=="string"?i=`Invalid props for ${e} (unnamed ${t.footprint} component): ${o}`:i=`Invalid props for ${e} (unnamed): ${o}`,super(i),this.componentName=e,this.originalProps=t,this.formattedError=n}};function FG(r,e){const t=e.match(/^#(\w+)/);if(t)return r.props.id===t[1];const n=e.match(/^\.(\w+)/);if(n)return r.isMatchingNameOrAlias(n[1]);let[i,...a]=e.split(/(?=[#.[])/);return i==="pin"&&(i="port"),i&&i!=="*"&&r.lowercaseComponentName!==i.toLowerCase()?!1:a.every(o=>{if(o.startsWith("#"))return r.props.id===o.slice(1);if(o.startsWith("."))return r.isMatchingNameOrAlias(o.slice(1));const s=o.match(/\[(\w+)=['"]?(.+?)['"]?\]/);if(!s)return!0;const[,l,c]=s;return r.props[l].toString()===c})}var BG={isTag:r=>!0,getParent:r=>r.parent,getChildren:r=>r.children,getName:r=>r.lowercaseComponentName,getAttributeValue:(r,e)=>{var t;if(e==="class"&&"getNameAndAliases"in r)return r.getNameAndAliases().join(" ");if(e==="name"&&((t=r._parsedProps)!=null&&t.name))return r._parsedProps.name;if(r._parsedProps&&e in r._parsedProps){const n=r._parsedProps[e];return typeof n=="string"?n:n!=null?String(n):null}return null},hasAttrib:(r,e)=>{var t;return e==="class"?!!((t=r._parsedProps)!=null&&t.name):r._parsedProps&&e in r._parsedProps},getSiblings:r=>r.parent?r.parent.children:[],prevElementSibling:r=>{if(!r.parent)return null;const e=r.parent.children,t=e.indexOf(r);return t>0?e[t-1]:null},getText:()=>"",removeSubsets:r=>r.filter((e,t)=>!r.some((n,i)=>t!==i&&n!==e&&n.getDescendants().includes(e))),existsOne:(r,e)=>e.some(r),findAll:(r,e)=>{const t=[],n=i=>{r(i)&&t.push(i);for(const a of i.children)n(a)};for(const i of e)n(i);return t},findOne:(r,e)=>{for(const t of e){if(r(t))return t;const n=t.children;if(n.length>0){const i=BG.findOne(r,n);if(i)return i}}return null},equals:(r,e)=>r._renderId===e._renderId,isHovered:r=>!1,isVisited:r=>!1,isActive:r=>!1},Vft={...BG,getChildren:r=>r.children.filter(e=>!e.isSubcircuit)},Mge={...BG,getChildren:r=>r.children.filter(e=>e.isSubcircuit)},Cge=r=>r.replace(/ pin/g," port").replace(/ subcircuit\./g," group[isSubcircuit=true]").replace(/([^ ])\>([^ ])/g,"$1 > $2").trim(),jG={adapter:Vft,cacheResults:!0},N_=class extends Ege{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 n=this.config.zodProps.safeParse(t??{});if(n.success)this._parsedProps=n.data;else throw new Hft(this.lowercaseComponentName,this.props,n.error.format())}get config(){return{componentName:"",zodProps:R.object({}).passthrough()}}get componentName(){return this.config.componentName}getInheritedProperty(t){var i;let n=this;for(;n;){if(n._parsedProps&&t in n._parsedProps)return n._parsedProps[t];n=n.parent}if((i=this.root)!=null&&i.platform&&t in this.root.platform)return this.root.platform[t]}get lowercaseComponentName(){return this.componentName.toLowerCase()}get isSubcircuit(){var t;return!!this.props.subcircuit||this.lowercaseComponentName==="group"&&((t=this==null?void 0:this.parent)==null?void 0:t.isRoot)}get isGroup(){return this.lowercaseComponentName==="group"}setProps(t){var a,o;const n=this.config.zodProps.parse({...this.props,...t}),i=this.props;this.props=n,this._parsedProps=this.config.zodProps.parse(t),this.onPropsChange({oldProps:i,newProps:n,changedProps:Object.keys(t)}),(o=(a=this.parent)==null?void 0:a.onChildChanged)==null||o.call(a,this)}computePcbPropsTransform(){const{_parsedProps:t}=this;return wc(zf(t.pcbX??0,t.pcbY??0),f2((t.pcbRotation??0)*Math.PI/180))}_computePcbGlobalTransformBeforeLayout(){var i,a,o;const{_parsedProps:t}=this,n=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if(n&&this.props.pcbX===void 0&&this.props.pcbY===void 0)return wc(((i=this.parent)==null?void 0:i._computePcbGlobalTransformBeforeLayout())??ev(),wc(zf(n.x,n.y),f2((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 wc(zf(c.x,c.y),WE(),zf(-c.x,-c.y)),wc(((a=this.parent)==null?void 0:a._computePcbGlobalTransformBeforeLayout())??ev(),WE(),this.computePcbPropsTransform())}}return wc(((o=this.parent)==null?void 0:o._computePcbGlobalTransformBeforeLayout())??ev(),this.computePcbPropsTransform())}getPrimitiveContainer(){var t,n;return this.isPrimitiveContainer?this:((n=(t=this.parent)==null?void 0:t.getPrimitiveContainer)==null?void 0:n.call(t))??null}_getPcbCircuitJsonBounds(){return{center:{x:0,y:0},bounds:{left:0,top:0,right:0,bottom:0},width:0,height:0}}_getPcbPrimitiveFlippedHelpers(){const t=this.getPrimitiveContainer(),n=t?t._parsedProps.layer==="bottom":!1;return{isFlipped:n,maybeFlipLayer:a=>n?a==="top"?"bottom":"top":a}}_setPositionFromLayout(t){throw new Error(`_setPositionFromLayout not implemented for ${this.componentName}`)}computeSchematicPropsTransform(){const{_parsedProps:t}=this;return wc(zf(t.schX??0,t.schY??0))}computeSchematicGlobalTransform(){var n,i;const t=this._getSchematicGlobalManualPlacementTransform(this);return t||wc(((i=(n=this.parent)==null?void 0:n.computeSchematicGlobalTransform)==null?void 0:i.call(n))??ev(),this.computeSchematicPropsTransform())}_getSchematicSymbolName(){const{_parsedProps:t}=this,n=this.config.schematicSymbolName;let i=t.schRotation;if(i===void 0&&(i=0),i=i%360,i<0&&(i+=360),t.schRotation!==void 0&&i%90!==0)throw new Error(`Schematic rotation ${t.schRotation} is not supported for ${this.componentName}`);const a=`${n}_horz`,o=`${n}_vert`,s=`${n}_up`,l=`${n}_down`,c=`${n}_left`,u=`${n}_right`;if(u in d_&&i===0)return u;if(s in d_&&i===90)return s;if(c in d_&&i===180)return c;if(l in d_&&i===270)return l;if(a in d_&&(i===0||i===180))return a;if(o in d_&&(i===90||i===270))return o;if(n in d_)return n}_getSchematicSymbolNameOrThrow(){const t=this._getSchematicSymbolName();if(!t)throw new Error(`No schematic symbol found (given: "${this.config.schematicSymbolName}")`);return t}getSchematicSymbol(){const t=this._getSchematicSymbolName();return t?d_[t]??null:null}_getPcbManualPlacementForComponent(t){var o;if(!this.isSubcircuit)return null;const n=this.props.layout,i=this.props.manualEdits;if(!n&&!i)return null;const a=((o=n==null?void 0:n.manual_pcb_placement_config)==null?void 0:o.positions)||(i==null?void 0:i.pcb_placements);if(!a)return null;for(const s of a)if(n&&FG(t,s.selector)||t.props.name===s.selector)return kr(this._computePcbGlobalTransformBeforeLayout(),s.center);return null}_getSchematicManualPlacementForComponent(t){if(!this.isSubcircuit)return null;const n=this.props.manualEdits;if(!n)return null;const i=n.schematic_placements;if(!i)return null;for(const a of i)if(FG(t,a.selector)||t.props.name===a.selector)return kr(this.computeSchematicGlobalTransform(),a.center);return null}_getSchematicGlobalManualPlacementTransform(t){var i,a;const n=(i=this.getSubcircuit())==null?void 0:i._parsedProps.manualEdits;if(!n)return null;for(const o of n.schematic_placements??[])if((FG(t,o.selector)||t.props.name===o.selector)&&o.relative_to==="group_center")return wc(((a=this.parent)==null?void 0:a._computePcbGlobalTransformBeforeLayout())??ev(),zf(o.center.x,o.center.y));return null}_getGlobalPcbPositionBeforeLayout(){return kr(this._computePcbGlobalTransformBeforeLayout(),{x:0,y:0})}_getGlobalSchematicPositionBeforeLayout(){return kr(this.computeSchematicGlobalTransform(),{x:0,y:0})}get root(){var t;return((t=this.parent)==null?void 0:t.root)??null}onAddToParent(t){this.parent=t}onPropsChange(t){}onChildChanged(t){var n,i;(i=(n=this.parent)==null?void 0:n.onChildChanged)==null||i.call(n,t)}add(t){if(!t.onAddToParent)throw new Error(`Invalid JSX Element: Expected a React component but received "${JSON.stringify(t)}"`);t.onAddToParent(this),t.parent=this,this.children.push(t)}addAll(t){for(const n of t)this.add(n)}remove(t){this.children=this.children.filter(n=>n!==t),this.childrenPendingRemoval.push(t),t.shouldBeRemoved=!0}getSubcircuitSelector(){const t=this._parsedProps.name,n=t?`${this.lowercaseComponentName}.${t}`:this.lowercaseComponentName;return!this.parent||this.parent.isSubcircuit?n:`${this.parent.getSubcircuitSelector()} > ${n}`}getFullPathSelector(){var a,o;const t=this._parsedProps.name,n=t?`${this.lowercaseComponentName}.${t}`:this.lowercaseComponentName,i=(o=(a=this.parent)==null?void 0:a.getFullPathSelector)==null?void 0:o.call(a);return i?`${i} > ${n}`:n}getNameAndAliases(){return[this._parsedProps.name,...this._parsedProps.portHints??[]].filter(Boolean)}isMatchingNameOrAlias(t){return this.getNameAndAliases().includes(t)}isMatchingAnyOf(t){return this.getNameAndAliases().some(n=>t.map(i=>i.toString()).includes(n))}getPcbSize(){throw new Error(`getPcbSize not implemented for ${this.componentName}`)}doesSelectorMatch(t){const n=[this.componentName,this.lowercaseComponentName],i=[this._parsedProps.name].filter(Boolean),a=t.trim().split(/\> /)[0],o=a[0];return a.length>1?!1:!!(t==="*"||t[0]==="#"&&t.slice(1)===this.props.id||t[0]==="."&&i.includes(t.slice(1))||/^[a-zA-Z0-9_]/.test(o)&&n.includes(o))}getSubcircuit(){var n,i;if(this.isSubcircuit)return this;const t=(i=(n=this.parent)==null?void 0:n.getSubcircuit)==null?void 0:i.call(n);if(!t)throw new Error("Component is not inside an opaque group (no board?)");return t}getGroup(){var t,n;return this.isGroup?this:((n=(t=this.parent)==null?void 0:t.getGroup)==null?void 0:n.call(t))??null}doInitialOptimizeSelectorCache(){var n;if(!this.isSubcircuit)return;const t=this.selectAll("port");for(const i of t){const a=(n=i.parent)==null?void 0:n.getNameAndAliases(),o=i.getNameAndAliases();if(a)for(const s of a)for(const l of o){const c=[`.${s} > .${l}`,`.${s} .${l}`];for(const u of c){const f=this._cachedSelectAllQueries.get(u);f?f.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 n=Cge(t),i=lT(n,this,jG);if(i.length>0)return this._cachedSelectAllQueries.set(t,i),i;const[a,...o]=n.split(" "),s=zS(a,this,{adapter:Mge});if(!s)return[];const l=s.selectAll(o.join(" "));return this._cachedSelectAllQueries.set(t,l),l}selectOne(t,n){if(this._cachedSelectOneQueries.has(t))return this._cachedSelectOneQueries.get(t);const i=Cge(t);n!=null&&n.port&&(n.type="port");let a=null;if(n!=null&&n.type&&(a=lT(i,this,jG).find(u=>u.lowercaseComponentName===n.type)),a??(a=zS(i,this,jG)),a)return this._cachedSelectOneQueries.set(t,a),a;const[o,...s]=i.split(" "),l=zS(o,this,{adapter:Mge});return l?(a=l.selectOne(s.join(" "),n),this._cachedSelectOneQueries.set(t,a),a):null}getAvailablePcbLayers(){var t,n;if(this.isPcbPrimitive){const{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers();return"layer"in this._parsedProps||this.componentName==="SmtPad"?[i(this._parsedProps.layer??"top")]:"layers"in this._parsedProps?this._parsedProps.layers:this.componentName==="PlatedHole"?((n=(t=this.root)==null?void 0:t._getBoard())==null?void 0:n.allLayers)??["top","bottom"]:[]}return[]}getDescendants(){const t=[];for(const n of this.children)t.push(n),t.push(...n.getDescendants());return t}getSelectableDescendants(){const t=[];for(const n of this.children)n.isSubcircuit?t.push(n):(t.push(n),t.push(...n.getSelectableDescendants()));return t}_getPinCount(){return 0}_getSchematicBoxDimensions(){return null}renderError(t){var n;if(typeof t=="string")return super.renderError(t);(n=this.root)==null||n.db.pcb_placement_error.insert(t)}getString(){var a,o;const{lowercaseComponentName:t,_parsedProps:n,parent:i}=this;return(n==null?void 0:n.pinNumber)!==void 0&&((a=i==null?void 0:i.props)!=null&&a.name)&&(n!=null&&n.name)?`<${t}#${this._renderId}(pin:${n.pinNumber} .${i==null?void 0:i.props.name}>.${n.name}) />`:(o=i==null?void 0:i.props)!=null&&o.name&&(n!=null&&n.name)?`<${t}#${this._renderId}(.${i==null?void 0:i.props.name}>.${n==null?void 0:n.name}) />`:n!=null&&n.from&&(n!=null&&n.to)?`<${t}#${this._renderId}(from:${n.from} to:${n==null?void 0:n.to}) />`:n!=null&&n.name?`<${t}#${this._renderId} name=".${n==null?void 0:n.name}" />`:n!=null&&n.portHints?`<${t}#${this._renderId}(${n.portHints.map(s=>`.${s}`).join(", ")}) />`:`<${t}#${this._renderId} />`}get[Symbol.toStringTag](){return this.getString()}[Symbol.for("nodejs.util.inspect.custom")](){return this.getString()}},Gft=class extends N_{constructor(e,t){super(e),this._parsedProps={...e,error:t,type:e.type||"unknown",component_name:e.name,error_type:"source_failed_to_create_component_error",message:t instanceof Error?t.message:String(t),pcbX:e.pcbX,pcbY:e.pcbY,schX:e.schX,schY:e.schY}}get config(){return{componentName:"ErrorPlaceholder",zodProps:R.object({}).passthrough()}}doInitialSourceRender(){var e;if((e=this.root)!=null&&e.db){const t=this._getGlobalPcbPositionBeforeLayout(),n=this._getGlobalSchematicPositionBeforeLayout();this.root.db.source_failed_to_create_component_error.insert({component_name:this._parsedProps.component_name,message:this._parsedProps.message,pcb_center:t,schematic_center:n})}}};function qft(r,e){return new Gft(r,e)}function $ft(r,e){const t=r;return t.__tsci={...e},r}var Rge={supportsMutation:!0,createInstance(r,e){const t=EL[r];if(!t)throw Object.keys(EL).length===0?new Error("No components registered in catalogue, did you forget to import lib/register-catalogue in your test file?"):new Error(`Unsupported component type (not registered in @tscircuit/core catalogue): "${r}" See CREATING_NEW_COMPONENTS.md`);try{return $ft(new t(e),{})}catch(n){return qft(e,n)}},createTextInstance(){return{}},appendInitialChild(r,e){r.add(e)},appendChild(r,e){r.add(e)},appendChildToContainer(r,e){r.add(e)},finalizeInitialChildren(){return!1},prepareUpdate(){return null},shouldSetTextContent(){return!1},getRootHostContext(){return{}},getChildHostContext(){return{}},prepareForCommit(){return null},resetAfterCommit(){},commitMount(){},commitUpdate(){},removeChild(){},clearContainer(){},supportsPersistence:!1,getPublicInstance(r){return r},preparePortalMount(r){throw new Error("Function not implemented.")},scheduleTimeout(r,e){throw new Error("Function not implemented.")},cancelTimeout(r){throw new Error("Function not implemented.")},noTimeout:void 0,isPrimaryRenderer:!1,getInstanceFromNode(r){throw new Error("Function not implemented.")},beforeActiveInstanceBlur(){throw new Error("Function not implemented.")},afterActiveInstanceBlur(){throw new Error("Function not implemented.")},prepareScopeUpdate:(r,e)=>{throw new Error("Function not implemented.")},getInstanceFromScope:r=>{throw new Error("Function not implemented.")},detachDeletedInstance:r=>{throw new Error("Function not implemented.")},getCurrentEventPriority:()=>OS.DefaultEventPriority,getCurrentUpdatePriority:()=>OS.DefaultEventPriority,resolveUpdatePriority:()=>OS.DefaultEventPriority,setCurrentUpdatePriority:()=>{},maySuspendCommit:()=>!1,supportsHydration:!1},i8;Zc.version.startsWith("19.")?i8=TH(Rge):i8=RH(Rge);var Yft=r=>{const e={children:[],props:{name:"$root"},add(a){a.parent=this,this.children.push(a)},computePcbGlobalTransform(){return ev()}},t=[],n=i8.createContainer(e,0,null,!1,null,"tsci",a=>{console.log("Error in createContainer"),console.error(a),t.push(a)},null);if(Zc.version.startsWith("19.")?(i8.updateContainerSync(r,n,null,()=>{}),i8.flushSyncWork()):i8.updateContainer(r,n,null,()=>{}),t.length>0)throw t[0];const i=i8.getPublicRootInstance(n);return i||e.children[0]},hC=(r,e)=>{if(typeof r=="number")return r;if(r.startsWith("pin"))return Number(r.slice(3));if(!e)throw new Error(`No pin labels provided and pin number or label is not a number: "${r}"`);for(const t in e)if((Array.isArray(e[t])?e[t]:[e[t]]).includes(r))return Number(t.replace("pin",""));throw new Error(`No pin labels provided and pin number or label is not a number: "${r}"`)},Xft=(r,e)=>{if(!r)return;const t={},n={};for(const[i,a]of Object.entries(r)){const o=hC(i,e);n[o]={...n[o],...a}}for(const[i,a]of Object.entries(n)){const o=`pin${i}`;t[o]={bottom_margin:a.bottomMargin,left_margin:a.leftMargin,right_margin:a.rightMargin,top_margin:a.topMargin}}return t},Wft=r=>{if(r){if("leftSide"in r||"rightSide"in r||"topSide"in r||"bottomSide"in r)return{left_side:r.leftSide,right_side:r.rightSide,top_side:r.topSide,bottom_side:r.bottomSide};if("leftPinCount"in r||"rightPinCount"in r||"topPinCount"in r||"bottomPinCount"in r)return{left_size:r.leftPinCount,right_size:r.rightPinCount,top_size:r.topPinCount,bottom_size:r.bottomPinCount};if("leftSize"in r||"rightSize"in r||"topSize"in r||"bottomSize"in r)return{left_size:r.leftSize,right_size:r.rightSize,top_size:r.topSize,bottom_size:r.bottomSize}}};function Age(r){const e=[];for(let t=0;t<r.length-1;t++)e.push([r[t],r[t+1]]);return e}var Zft=R.object({name:R.string()}),Pge=class extends N_{constructor(){super(...arguments);Je(this,"source_net_id")}get config(){return{componentName:"Net",zodProps:Zft}}getPortSelector(){return`net.${this.props.name}`}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_net.insert({name:n.name,member_source_group_ids:[]});this.source_net_id=i.source_net_id}doInitialSourceParentAttachment(){const t=this.getSubcircuit();if(!t)return;const{db:n}=this.root;n.source_net.update(this.source_net_id,{subcircuit_id:t.subcircuit_id})}getAllConnectedPorts(){const t=this.getSubcircuit().selectAll("port"),n=[];for(const i of t){const a=i._getDirectlyConnectedTraces();for(const o of a)if(o._isExplicitlyConnectedToNet(this)){n.push(i);break}}return n}_getAllDirectlyConnectedTraces(){const t=this.getSubcircuit().selectAll("trace"),n=[];for(const i of t)i._isExplicitlyConnectedToNet(this)&&n.push(i);return n}doInitialPcbRouteNetIslands(){var s;if((s=this.root)!=null&&s.pcbDisabled||this.getSubcircuit()._parsedProps.routingDisabled||this.getSubcircuit()._getAutorouterConfig().groupMode!=="sequential-trace")return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getAllDirectlyConnectedTraces().filter(l=>{var c;return(((c=l._portsRoutedOnPcb)==null?void 0:c.length)??0)>0}),a=[];for(const l of i){const c=l._portsRoutedOnPcb,u=a.find(f=>c.some(d=>f.ports.includes(d)));if(!u){a.push({ports:[...c],traces:[l]});continue}u.traces.push(l),u.ports.push(...c)}if(a.length===0)return;const o=Age(a);for(const[l,c]of o){const u=l.ports.map(P=>P._getGlobalPcbPositionBeforeLayout()),f=c.ports.map(P=>P._getGlobalPcbPositionBeforeLayout());let d=1/0,m=[-1,-1];for(let P=0;P<u.length;P++){const U=u[P];for(let V=0;V<f.length;V++){const Y=f[V],W=Math.sqrt((U.x-Y.x)**2+(U.y-Y.y)**2);W<d&&(d=W,m=[P,V])}}const y=l.ports[m[0]],w=c.ports[m[1]],S=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:b}=lG(S.concat([{type:"source_trace",source_trace_id:"__net_trace_tmp",connected_source_port_ids:[y.source_port_id,w.source_port_id]}])),E=b[0];if(!E){this.renderError({pcb_trace_error_id:"",pcb_trace_id:"__net_trace_tmp",pcb_component_ids:[y.pcb_component_id,w.pcb_component_id].filter(Boolean),pcb_port_ids:[y.pcb_port_id,w.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(E)}}renderError(t){var n;if(typeof t=="string")return super.renderError(t);(n=this.root)==null||n.db.pcb_trace_error.insert(t)}},Nge=(r,e)=>{for(const t of e)if(typeof t=="string"&&t.startsWith("net.")){const n=r.getSubcircuit();if(!n.selectOne(t)){const i=new Pge({name:t.split("net.")[1]});n.add(i)}}},HG=class extends N_{constructor(){super(...arguments);Je(this,"pcb_smtpad_id",null);Je(this,"matchedPort",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SmtPad",zodProps:uye}}getPcbSize(){const{_parsedProps:t}=this;if(t.shape==="circle")return{width:t.radius*2,height:t.radius*2};if(t.shape==="rect")return{width:t.width,height:t.height};throw new Error(`getPcbSize for shape "${t.shape}" not implemented for ${this.componentName}`)}doInitialPortMatching(){var n;const t=(n=this.getPrimitiveContainer())==null?void 0:n.selectAll("port");if(this.props.portHints){for(const i of t)if(i.isMatchingAnyOf(this.props.portHints)){this.matchedPort=i,i.registerMatch(this);return}}}doInitialPcbPrimitiveRender(){var m,y,w,S,b,E,P,U,V,Y;if((m=this.root)!=null&&m.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this;if(!n.portHints)return;const i=this.getPrimitiveContainer(),a=this.getSubcircuit(),o=this._getGlobalPcbPositionBeforeLayout();i==null||i._getGlobalPcbPositionBeforeLayout();const s=kw(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 f=null;const d=((y=this.parent)==null?void 0:y.pcb_component_id)??((w=this.getPrimitiveContainer())==null?void 0:w.pcb_component_id);n.shape==="circle"?(f=t.pcb_smtpad.insert({pcb_component_id:d,pcb_port_id:(S=this.matchedPort)==null?void 0:S.pcb_port_id,layer:c(n.layer??"top"),shape:"circle",radius:n.radius,port_hints:n.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:f.layer,shape:"circle",radius:f.radius*.7,x:f.x,y:f.y,pcb_component_id:f.pcb_component_id,pcb_smtpad_id:f.pcb_smtpad_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((b=this.getGroup())==null?void 0:b.pcb_group_id)??void 0})):n.shape==="rect"&&(f=u===0||l?t.pcb_smtpad.insert({pcb_component_id:d,pcb_port_id:(E=this.matchedPort)==null?void 0:E.pcb_port_id,layer:c(n.layer??"top"),shape:"rect",width:l?n.height:n.width,height:l?n.width:n.height,port_hints:n.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:d,layer:n.layer??"top",shape:"rotated_rect",width:n.width,height:n.height,x:o.x,y:o.y,ccw_rotation:u,port_hints:n.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}),f.shape==="rect"&&t.pcb_solder_paste.insert({layer:f.layer,shape:"rect",width:f.width*.7,height:f.height*.7,x:f.x,y:f.y,pcb_component_id:f.pcb_component_id,pcb_smtpad_id:f.pcb_smtpad_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((V=this.getGroup())==null?void 0:V.pcb_group_id)??void 0}),f.shape==="rotated_rect"&&t.pcb_solder_paste.insert({layer:f.layer,shape:"rotated_rect",width:f.width*.7,height:f.height*.7,x:f.x,y:f.y,ccw_rotation:u,pcb_component_id:f.pcb_component_id,pcb_smtpad_id:f.pcb_smtpad_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((Y=this.getGroup())==null?void 0:Y.pcb_group_id)??void 0})),f&&(this.pcb_smtpad_id=f.pcb_smtpad_id)}doInitialPcbPortAttachment(){var n,i;if((n=this.root)!=null&&n.pcbDisabled)return;const{db:t}=this.root;t.pcb_smtpad.update(this.pcb_smtpad_id,{pcb_port_id:(i=this.matchedPort)==null?void 0:i.pcb_port_id})}_getPcbCircuitJsonBounds(){const{db:t}=this.root,n=t.pcb_smtpad.get(this.pcb_smtpad_id);if(n.shape==="rect")return{center:{x:n.x,y:n.y},bounds:{left:n.x-n.width/2,top:n.y+n.height/2,right:n.x+n.width/2,bottom:n.y-n.height/2},width:n.width,height:n.height};if(n.shape==="rotated_rect"){const i=n.ccw_rotation*Math.PI/180,a=Math.cos(i),o=Math.sin(i),s=n.width/2,l=n.height/2,c=Math.abs(s*a)+Math.abs(l*o),u=Math.abs(s*o)+Math.abs(l*a);return{center:{x:n.x,y:n.y},bounds:{left:n.x-c,right:n.x+c,top:n.y-u,bottom:n.y+u},width:c*2,height:u*2}}if(n.shape==="circle")return{center:{x:n.x,y:n.y},bounds:{left:n.x-n.radius,top:n.y-n.radius,right:n.x+n.radius,bottom:n.y+n.radius},width:n.radius*2,height:n.radius*2};throw new Error(`circuitJson bounds calculation not implemented for shape "${n.shape}"`)}_setPositionFromLayout(t){var a;const{db:n}=this.root;n.pcb_smtpad.update(this.pcb_smtpad_id,{x:t.x,y:t.y});const i=n.pcb_solder_paste.list().find(o=>o.pcb_smtpad_id===this.pcb_smtpad_id);n.pcb_solder_paste.update(i==null?void 0:i.pcb_solder_paste_id,{x:t.x,y:t.y}),(a=this.matchedPort)==null||a._setPositionFromLayout(t)}},Dge=class extends N_{constructor(){super(...arguments);Je(this,"pcb_silkscreen_path_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenPath",zodProps:Dye}}doInitialPcbPrimitiveRender(){var c,u,f;if((c=this.root)!=null&&c.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(n.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenPath. Must be "top" or "bottom".`);const o=this._computePcbGlobalTransformBeforeLayout(),s=this.getSubcircuit(),l=t.pcb_silkscreen_path.insert({pcb_component_id:(u=this.parent)==null?void 0:u.pcb_component_id,layer:a,route:n.route.map(d=>{const m=kr(o,{x:d.x,y:d.y});return{...d,x:m.x,y:m.y}}),stroke_width:n.strokeWidth??.1,subcircuit_id:(s==null?void 0:s.subcircuit_id)??void 0,pcb_group_id:((f=this.getGroup())==null?void 0:f.pcb_group_id)??void 0});this.pcb_silkscreen_path_id=l.pcb_silkscreen_path_id}getPcbSize(){const{_parsedProps:t}=this;if(!t.route||t.route.length===0)return{width:0,height:0};let n=1/0,i=-1/0,a=1/0,o=-1/0;for(const s of t.route)n=Math.min(n,s.x),i=Math.max(i,s.x),a=Math.min(a,s.y),o=Math.max(o,s.y);return{width:i-n,height:o-a}}},Qft=R.object({route:R.array(zN),source_trace_id:R.string().optional()}),Lge=class extends N_{constructor(){super(...arguments);Je(this,"pcb_trace_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbTrace",zodProps:Qft}}doInitialPcbPrimitiveRender(){var u,f;if((u=this.root)!=null&&u.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getPrimitiveContainer(),a=this.getSubcircuit(),{maybeFlipLayer:o}=this._getPcbPrimitiveFlippedHelpers(),s=this._computePcbGlobalTransformBeforeLayout(),l=n.route.map(d=>{const{x:m,y,...w}=d,S=kr(s,{x:m,y});return d.route_type==="wire"&&d.layer?{...S,...w,layer:o(d.layer)}:{...S,...w}}),c=t.pcb_trace.insert({pcb_component_id:i.pcb_component_id,source_trace_id:n.source_trace_id,route:l,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((f=this.getGroup())==null?void 0:f.pcb_group_id)??void 0});this.pcb_trace_id=c.pcb_trace_id}getPcbSize(){const{_parsedProps:t}=this;if(!t.route||t.route.length===0)return{width:0,height:0};let n=1/0,i=-1/0,a=1/0,o=-1/0;for(const s of t.route)n=Math.min(n,s.x),i=Math.max(i,s.x),a=Math.min(a,s.y),o=Math.max(o,s.y),s.route_type==="wire"&&(n=Math.min(n,s.x-s.width/2),i=Math.max(i,s.x+s.width/2),a=Math.min(a,s.y-s.width/2),o=Math.max(o,s.y+s.width/2));return n===1/0||i===-1/0||a===1/0||o===-1/0?{width:0,height:0}:{width:i-n,height:o-a}}},Oge=class extends N_{constructor(){super(...arguments);Je(this,"pcb_plated_hole_id",null);Je(this,"matchedPort",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PlatedHole",zodProps:nye}}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,n=t.pcb_plated_hole.get(this.pcb_plated_hole_id),i=this.getPcbSize();return{center:{x:n.x,y:n.y},bounds:{left:n.x-i.width/2,top:n.y+i.height/2,right:n.x+i.width/2,bottom:n.y-i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(t){var i;const{db:n}=this.root;n.pcb_plated_hole.update(this.pcb_plated_hole_id,{x:t.x,y:t.y}),(i=this.matchedPort)==null||i._setPositionFromLayout(t)}doInitialPortMatching(){var n;const t=(n=this.getPrimitiveContainer())==null?void 0:n.selectAll("port");if(this.props.portHints){for(const i of t)if(i.isMatchingAnyOf(this.props.portHints)){this.matchedPort=i,i.registerMatch(this);return}}}doInitialPcbPrimitiveRender(){var s,l,c,u,f,d,m,y,w,S,b;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalPcbPositionBeforeLayout(),a=((l=this.parent)==null?void 0:l.pcb_component_id)??((c=this.getPrimitiveContainer())==null?void 0:c.pcb_component_id),o=this.getSubcircuit();if(n.shape==="circle"){const E=t.pcb_plated_hole.insert({pcb_component_id:a,pcb_port_id:(u=this.matchedPort)==null?void 0:u.pcb_port_id,outer_diameter:n.outerDiameter,hole_diameter:n.holeDiameter,shape:"circle",port_hints:this.getNameAndAliases(),x:i.x,y:i.y,layers:["top","bottom"],subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((f=this.getGroup())==null?void 0:f.pcb_group_id)??void 0});this.pcb_plated_hole_id=E.pcb_plated_hole_id,t.pcb_solder_paste.insert({layer:"top",shape:"circle",radius:n.outerDiameter/2,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((d=this.getGroup())==null?void 0:d.pcb_group_id)??void 0}),t.pcb_solder_paste.insert({layer:"bottom",shape:"circle",radius:n.outerDiameter/2,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((m=this.getGroup())==null?void 0:m.pcb_group_id)??void 0})}else if(n.shape==="pill"||n.shape==="oval"){const E=t.pcb_plated_hole.insert({pcb_component_id:a,pcb_port_id:(y=this.matchedPort)==null?void 0:y.pcb_port_id,outer_width:n.outerWidth,outer_height:n.outerHeight,hole_width:n.holeWidth,hole_height:n.holeHeight,shape:n.shape,port_hints:this.getNameAndAliases(),x:i.x,y:i.y,layers:["top","bottom"],subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((w=this.getGroup())==null?void 0:w.pcb_group_id)??void 0});this.pcb_plated_hole_id=E.pcb_plated_hole_id,t.pcb_solder_paste.insert({layer:"top",shape:n.shape,width:n.outerWidth,height:n.outerHeight,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((S=this.getGroup())==null?void 0:S.pcb_group_id)??void 0}),t.pcb_solder_paste.insert({layer:"bottom",shape:n.shape,width:n.outerWidth,height:n.outerHeight,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((b=this.getGroup())==null?void 0:b.pcb_group_id)??void 0})}}doInitialPcbPortAttachment(){var n,i;if((n=this.root)!=null&&n.pcbDisabled)return;const{db:t}=this.root;t.pcb_plated_hole.update(this.pcb_plated_hole_id,{pcb_port_id:(i=this.matchedPort)==null?void 0:i.pcb_port_id})}},VG=class extends N_{constructor(){super(...arguments);Je(this,"pcb_keepout_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Keepout",zodProps:Rye}}doInitialPcbPrimitiveRender(){var c,u,f;if((c=this.root)!=null&&c.pcbDisabled)return;const t=this.getSubcircuit(),{db:n}=this.root,{_parsedProps:i}=this,a=this._getGlobalPcbPositionBeforeLayout(),o=kw(this._computePcbGlobalTransformBeforeLayout()),s=Math.abs(o.rotation.angle*(180/Math.PI)-90)%180<.01;let l=null;i.shape==="circle"?l=n.pcb_keepout.insert({layers:["top"],shape:"circle",radius:i.radius,center:{x:a.x,y:a.y},subcircuit_id:(t==null?void 0:t.subcircuit_id)??void 0,pcb_group_id:((u=t==null?void 0:t.getGroup())==null?void 0:u.pcb_group_id)??void 0}):i.shape==="rect"&&(l=n.pcb_keepout.insert({layers:["top"],shape:"rect",...s?{width:i.height,height:i.width}:{width:i.width,height:i.height},center:{x:a.x,y:a.y},subcircuit_id:(t==null?void 0:t.subcircuit_id)??void 0,pcb_group_id:((f=t==null?void 0:t.getGroup())==null?void 0:f.pcb_group_id)??void 0})),l&&(this.pcb_keepout_id=l.pcb_keepout_id)}},zge=class extends N_{constructor(){super(...arguments);Je(this,"pcb_hole_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Hole",zodProps:fye}}getPcbSize(){const{_parsedProps:t}=this;return{width:t.diameter,height:t.diameter}}doInitialPcbPrimitiveRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getSubcircuit(),a=this._getGlobalPcbPositionBeforeLayout(),o=t.pcb_hole.insert({hole_shape:"circle",hole_diameter:n.diameter,x:a.x,y:a.y,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((l=i==null?void 0:i.getGroup())==null?void 0:l.pcb_group_id)??void 0});this.pcb_hole_id=o.pcb_hole_id}_getPcbCircuitJsonBounds(){const{db:t}=this.root,n=t.pcb_hole.get(this.pcb_hole_id),i=this.getPcbSize();return{center:{x:n.x,y:n.y},bounds:{left:n.x-i.width/2,top:n.y-i.height/2,right:n.x+i.width/2,bottom:n.y+i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(t){const{db:n}=this.root;n.pcb_hole.update(this.pcb_hole_id,{x:t.x,y:t.y})}},GG=class extends N_{constructor(){super(...arguments);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenText",zodProps:Nye}}doInitialPcbPrimitiveRender(){var l,c;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getPrimitiveContainer(),a=this._getGlobalPcbPositionBeforeLayout(),{maybeFlipLayer:o}=this._getPcbPrimitiveFlippedHelpers(),s=this.getSubcircuit();t.pcb_silkscreen_text.insert({anchor_alignment:n.anchorAlignment,anchor_position:{x:a.x,y:a.y},font:n.font??"tscircuit2024",font_size:n.fontSize??1,layer:o(n.layer??"top"),text:n.text??"",ccw_rotation:n.pcbRotation,pcb_component_id:i.pcb_component_id,subcircuit_id:(s==null?void 0:s.subcircuit_id)??void 0,pcb_group_id:((c=this.getGroup())==null?void 0:c.pcb_group_id)??void 0})}getPcbSize(){const{_parsedProps:t}=this,n=t.fontSize??1,a=(t.text??"").length*n,o=n;return{width:a*n,height:o*n}}},Kft=({elm:r,pinLabels:e,readableRotation:t})=>{var a;const n=r.text.replace(/[{}]/g,"").toLowerCase();let i=n;if(Array.isArray(e)){const o=parseInt(n.replace(/[^\d]/g,""),10)-1;i=e[o]??n}else typeof e=="object"&&(i=((a=e[n])==null?void 0:a[0])??n);return new GG({anchorAlignment:"center",text:i??n,fontSize:r.font_size+.2,pcbX:isNaN(r.anchor_position.x)?0:r.anchor_position.x,pcbY:r.anchor_position.y,pcbRotation:t??0})},Jft=({componentName:r,componentRotation:e,footprint:t,pinLabels:n},i)=>{const a=[];for(const o of i)if(o.type==="pcb_smtpad"&&o.shape==="rect")a.push(new HG({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 HG({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 Dge({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 Oge({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 VG({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 VG({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 zge({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")&&n?a.push(Kft({elm:o,pinLabels:n,readableRotation:s})):o.text==="{REF}"&&a.push(new GG({anchorAlignment:"center",text:r,fontSize:o.font_size+.2,pcbX:isNaN(o.anchor_position.x)?0:o.anchor_position.x,pcbY:o.anchor_position.y,pcbRotation:s??0}))}else o.type==="pcb_trace"&&a.push(new Lge({route:o.route}));return a};function Uge(r){let e=1/0,t=1/0,n=-1/0,i=-1/0;for(const s of r)if(s.isPcbPrimitive&&!s.componentName.startsWith("Silkscreen")){const{x:l,y:c}=s._getGlobalPcbPositionBeforeLayout(),{width:u,height:f}=s.getPcbSize();e=Math.min(e,l-u/2),t=Math.min(t,c-f/2),n=Math.max(n,l+u/2),i=Math.max(i,c+f/2)}else if(s.componentName==="Footprint"){const l=Uge(s.children);e=Math.min(e,l.minX),t=Math.min(t,l.minY),n=Math.max(n,l.maxX),i=Math.max(i,l.maxY)}let a=n-e,o=i-t;return a<0&&(a=0),o<0&&(o=0),{minX:e,minY:t,maxX:n,maxY:i,width:a,height:o}}function edt(r,e){const t=e.x-r.x,n=e.y-r.y;return Math.abs(t)>Math.abs(n)?t>=0?"right":"left":n>=0?"up":"down"}var tdt=r=>{if(r.length<=1)return!0;const e=r.map(a=>{const o=a._getPcbCircuitJsonBounds();return{left:o.bounds.left,right:o.bounds.right,top:o.bounds.top,bottom:o.bounds.bottom}}),t=Array(e.length).fill(!1).map(()=>Array(e.length).fill(!1));for(let a=0;a<e.length;a++)for(let o=a+1;o<e.length;o++){const s=e[a],l=e[o];t[a][o]=t[o][a]=!(s.right<l.left||s.left>l.right||s.bottom>l.top||s.top<l.bottom)}const n=new Set,i=a=>{n.add(a);for(let o=0;o<e.length;o++)t[a][o]&&!n.has(o)&&i(o)};return i(0),n.size===e.length},ndt=r=>{if(r.length===0)throw new Error("Cannot get center of empty PCB primitives array");const e=r.map(i=>i._getPcbCircuitJsonBounds().center).filter(Boolean),t=e.reduce((i,a)=>i+a.x,0),n=e.reduce((i,a)=>i+a.y,0);return{x:t/e.length,y:n/e.length}},rdt=R.object({name:R.string().optional(),pinNumber:R.number().optional(),aliases:R.array(R.string()).optional()}),US=class extends N_{constructor(t,n={}){if(!t.name&&t.pinNumber!==void 0&&(t.name=`pin${t.pinNumber}`),!t.name)throw new Error("Port must have a name or a pinNumber");super(t);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);n.originDescription&&(this.originDescription=n.originDescription),this.matchedComponents=[]}get config(){return{componentName:"Port",zodProps:rdt}}_getGlobalPcbPositionBeforeLayout(){const t=this.matchedComponents.find(i=>i.isPcbPrimitive),n=this.parent;if(n&&!n.props.footprint)throw new Error(`${n.componentName} "${n.props.name}" does not have a footprint. Add a footprint prop, e.g. <${n.componentName.toLowerCase()} footprint="..." />`);if(!t)throw new Error(`Port ${this} has no matching PCB primitives. This often means the footprint's pads lack matching port hints.`);return(t==null?void 0:t._getGlobalPcbPositionBeforeLayout())??{x:0,y:0}}_getPcbCircuitJsonBounds(){if(!this.pcb_port_id)return super._getPcbCircuitJsonBounds();const{db:t}=this.root,n=t.pcb_port.get(this.pcb_port_id);return{center:{x:n.x,y:n.y},bounds:{left:0,top:0,right:0,bottom:0},width:0,height:0}}_getGlobalPcbPositionAfterLayout(){return this._getPcbCircuitJsonBounds().center}_getPortsInternallyConnectedToThisPort(){const t=this.parent;if(!t||!t._getInternallyConnectedPins)return[];const n=t._getInternallyConnectedPins();for(const i of n)if(i.some(a=>a===this))return i;return[]}_hasSchematicPort(){var i,a;if((i=this.parent)==null?void 0:i.getSchematicSymbol())return!!(this.schematicSymbolPortDef||this._getPortsInternallyConnectedToThisPort().some(s=>s.schematicSymbolPortDef));const n=(a=this==null?void 0:this.parent)==null?void 0:a._getSchematicBoxDimensions();return!!(n&&this.props.pinNumber!==void 0&&n.getPortPositionByPinNumber(this.props.pinNumber))}_getGlobalSchematicPositionBeforeLayout(){var i,a,o;const t=(i=this.parent)==null?void 0:i.getSchematicSymbol();if(t){let s=this.schematicSymbolPortDef;if(!s&&(s=((a=this._getPortsInternallyConnectedToThisPort().find(c=>c.schematicSymbolPortDef))==null?void 0:a.schematicSymbolPortDef)??null,!s))throw new Error(`Couldn't find schematicSymbolPortDef for port ${this.getString()}, searched internally connected ports and none had a schematicSymbolPortDef. Why are we trying to get the schematic position of this port?`);const l=wc(this.parent.computeSchematicGlobalTransform(),zf(-t.center.x,-t.center.y));return kr(l,s)}const n=(o=this==null?void 0:this.parent)==null?void 0:o._getSchematicBoxDimensions();if(n&&this.props.pinNumber!==void 0){const s=n.getPortPositionByPinNumber(this.props.pinNumber);if(!s)throw new Error(`Couldn't find position for schematic_port for port ${this.getString()} inside of the schematic box`);return kr(this.parent.computeSchematicGlobalTransform(),s)}throw new Error(`Couldn't find position for schematic_port for port ${this.getString()}`)}_getGlobalSchematicPositionAfterLayout(){const{db:t}=this.root;if(!this.schematic_port_id)throw new Error(`Can't get schematic port position after layout for "${this.getString()}", no schematic_port_id`);const n=t.schematic_port.get(this.schematic_port_id);if(!n)throw new Error(`Schematic port not found when trying to get post-layout position: ${this.schematic_port_id}`);return n.center}registerMatch(t){this.matchedComponents.push(t)}getNameAndAliases(){const{_parsedProps:t}=this;return Array.from(new Set([...t.aliases??[],...t.name?[t.name]:[],...typeof t.pinNumber=="number"?[`pin${t.pinNumber}`,t.pinNumber.toString()]:[],...this.externallyAddedAliases??[]]))}isMatchingPort(t){return this.isMatchingAnyOf(t.getNameAndAliases())}getPortSelector(){var t;return`.${(t=this.parent)==null?void 0:t.props.name} > port.${this.props.name}`}getAvailablePcbLayers(){return Array.from(new Set(this.matchedComponents.flatMap(t=>t.getAvailablePcbLayers())))}_getDirectlyConnectedTraces(){return this.getSubcircuit().selectAll("trace").filter(i=>i._isExplicitlyConnectedToPort(this))}doInitialSourceRender(){var o,s;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getNameAndAliases(),a=t.source_port.insert({name:n.name,pin_number:n.pinNumber,port_hints:i,source_component_id:(o=this.parent)==null?void 0:o.source_component_id,subcircuit_id:(s=this.getSubcircuit())==null?void 0:s.subcircuit_id});this.source_port_id=a.source_port_id}doInitialSourceParentAttachment(){var n,i,a,o,s;const{db:t}=this.root;if(!((n=this.parent)!=null&&n.source_component_id))throw new Error(`${this.getString()} has no parent source component (parent: ${(i=this.parent)==null?void 0:i.getString()})`);t.source_port.update(this.source_port_id,{source_component_id:(a=this.parent)==null?void 0:a.source_component_id,subcircuit_id:(o=this.getSubcircuit())==null?void 0:o.subcircuit_id}),this.source_component_id=(s=this.parent)==null?void 0:s.source_component_id}doInitialPcbPortRender(){var o,s,l,c,u;if((o=this.root)!=null&&o.pcbDisabled)return;const{db:t}=this.root,{matchedComponents:n}=this;if(!((s=this.parent)!=null&&s.pcb_component_id))throw new Error(`${this.getString()} has no parent pcb component, cannot render pcb_port (parent: ${(l=this.parent)==null?void 0:l.getString()})`);const i=n.filter(f=>f.isPcbPrimitive);if(i.length===0)return;let a=null;if(i.length===1&&(a=i[0]._getPcbCircuitJsonBounds().center),i.length>1){if(!tdt(i))throw new Error(`${this.getString()} has multiple non-overlapping pcb matches, unclear how to place pcb_port: ${i.map(f=>f.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=ndt(i)}if(a){const f=this.getSubcircuit(),d=t.pcb_port.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layers:this.getAvailablePcbLayers(),subcircuit_id:(f==null?void 0:f.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=d.pcb_port_id}else{const f=i[0];throw new Error(`${f.getString()} does not have a center or _getGlobalPcbPositionBeforeLayout method (needed for pcb_port placement)`)}}doInitialSchematicPortRender(){var d;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getPrimitiveContainer();if(!i||!this._hasSchematicPort())return;const a=i._getGlobalSchematicPositionBeforeLayout(),o=this._getGlobalSchematicPositionBeforeLayout();let s=null;const l=i._getSchematicBoxDimensions();l&&n.pinNumber!==void 0&&(s=l.getPortPositionByPinNumber(n.pinNumber)),this.getSubcircuit().props._schDebugObjectsEnabled&&t.schematic_debug_object.insert({shape:"rect",center:o,size:{width:.1,height:.1},label:"obstacle"}),s!=null&&s.side?this.facingDirection={left:"left",right:"right",top:"up",bottom:"down"}[s.side]:this.facingDirection=edt(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 f=t.schematic_port.insert({schematic_component_id:(d=this.parent)==null?void 0:d.schematic_component_id,center:o,source_port_id:this.source_port_id,facing_direction:this.facingDirection,distance_from_component_edge:.4,side_of_component:s==null?void 0:s.side,pin_number:n.pinNumber,true_ccw_index:s==null?void 0:s.trueIndex,display_pin_label:u});this.schematic_port_id=f.schematic_port_id}_setPositionFromLayout(t){const{db:n}=this.root;this.pcb_port_id&&n.pcb_port.update(this.pcb_port_id,{x:t.x,y:t.y})}_hasMatchedPcbPrimitive(){return this.matchedComponents.some(t=>t.isPcbPrimitive)}},kge=r=>{const e=r.find(t=>/^(pin)?\d+$/.test(t));return e?Number.parseInt(e.replace(/^pin/,"")):null};function mC(r,e){var a;const t=kge(r);if(!t)return null;const i=[...r.filter(o=>o.toString()!==t.toString()&&o!==`pin${t}`),...((a=e==null?void 0:e.additionalAliases)==null?void 0:a[`pin${t}`])??[]];return new US({pinNumber:t,aliases:i})}var idt=r=>{for(const e of["leftSide","rightSide","topSide","bottomSide"])if(e in r&&typeof r[e]=="number")throw new Error(`A number was specified for "${e}", you probably meant to use "size" not "side"`);return"leftSide"in r||"rightSide"in r||"topSide"in r||"bottomSide"in r},adt=r=>{var a,o,s,l;if(idt(r))return{leftSize:((a=r.leftSide)==null?void 0:a.pins.length)??0,rightSize:((o=r.rightSide)==null?void 0:o.pins.length)??0,topSize:((s=r.topSide)==null?void 0:s.pins.length)??0,bottomSize:((l=r.bottomSide)==null?void 0:l.pins.length)??0};const{leftSize:e=0,rightSize:t=0,topSize:n=0,bottomSize:i=0}=r;return{leftSize:e,rightSize:t,topSize:n,bottomSize:i}};function Ige(r){return r.leftSide!==void 0}var odt=r=>{var S,b,E,P,U,V,Y,W;const e=r.portDistanceFromEdge??.4;let t=r.schPortArrangement?adt(r.schPortArrangement):null;const n={left:0,right:0,top:0,bottom:0};let i=r.pinCount??null;if(i===null)if(t)i=t.leftSize+t.rightSize+t.topSize;else throw new Error("Could not determine pin count for the schematic box");if(i&&!t){const $=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:K,truePinIndex:X})=>{var he,ge,Te,xe;if(!r.schPortArrangement||!Ige(r.schPortArrangement))return X+1;const ce={left:"top-to-bottom",bottom:"left-to-right",right:"bottom-to-top",top:"right-to-left"}[$],pe=((ge=(he=r.schPortArrangement)==null?void 0:he[`${$}Side`])==null?void 0:ge.direction)??ce,ue=(xe=(Te=r.schPortArrangement)==null?void 0:Te[`${$}Side`])==null?void 0:xe.pins;let Se=K;return pe!==ce&&(Se=ue.length-K-1),hC(ue[Se],r.pinLabels)},o=[];let s=0,l=0;for(let $=0;$<t.leftSize;$++){const K=a({side:"left",sideIndex:$,truePinIndex:l}),X=((S=r.numericSchPinStyle)==null?void 0:S[`pin${K}`])??((b=r.numericSchPinStyle)==null?void 0:b[K]);X!=null&&X.topMargin&&(s+=X.topMargin),o.push({trueIndex:l,pinNumber:K,side:"left",distanceFromOrthogonalEdge:s}),X!=null&&X.bottomMargin&&(s+=X.bottomMargin),$===t.leftSize-1?n.left=s:s+=r.schPinSpacing,l++}s=0;for(let $=0;$<t.bottomSize;$++){const K=a({side:"bottom",sideIndex:$,truePinIndex:l}),X=((E=r.numericSchPinStyle)==null?void 0:E[`pin${K}`])??((P=r.numericSchPinStyle)==null?void 0:P[K]);X!=null&&X.leftMargin&&(s+=X.leftMargin),o.push({trueIndex:l,pinNumber:K,side:"bottom",distanceFromOrthogonalEdge:s}),X!=null&&X.rightMargin&&(s+=X.rightMargin),$===t.bottomSize-1?n.bottom=s:s+=r.schPinSpacing,l++}s=0;for(let $=0;$<t.rightSize;$++){const K=a({side:"right",sideIndex:$,truePinIndex:l}),X=((U=r.numericSchPinStyle)==null?void 0:U[`pin${K}`])??((V=r.numericSchPinStyle)==null?void 0:V[K]);X!=null&&X.bottomMargin&&(s+=X.bottomMargin),o.push({trueIndex:l,pinNumber:K,side:"right",distanceFromOrthogonalEdge:s}),X!=null&&X.topMargin&&(s+=X.topMargin),$===t.rightSize-1?n.right=s:s+=r.schPinSpacing,l++}s=0;for(let $=0;$<t.topSize;$++){const K=a({side:"top",sideIndex:$,truePinIndex:l}),X=((Y=r.numericSchPinStyle)==null?void 0:Y[`pin${K}`])??((W=r.numericSchPinStyle)==null?void 0:W[K]);X!=null&&X.rightMargin&&(s+=X.rightMargin),o.push({trueIndex:l,pinNumber:K,side:"top",distanceFromOrthogonalEdge:s}),X!=null&&X.leftMargin&&(s+=X.leftMargin),$===t.topSize-1?n.top=s:s+=r.schPinSpacing,l++}let c=r.schWidth;c||(c=Math.max(n.top+r.schPinSpacing*2,n.bottom+r.schPinSpacing*2));const u=r.pinLabels?Math.max(...Object.values(r.pinLabels).map($=>$.length*.1)):0,f=u>0?1.1:0;c=Math.max(c,u+f);let d=r.schHeight;d||(d=Math.max(n.left+r.schPinSpacing*2,n.right+r.schPinSpacing*2));const m={left:{x:-c/2-e,y:n.left/2},bottom:{x:-n.bottom/2,y:-d/2-e},right:{x:c/2+e,y:-n.right/2},top:{x:n.top/2,y:d/2+e}},y={left:{x:0,y:-1},right:{x:0,y:1},top:{x:-1,y:0},bottom:{x:1,y:0}},w=o.map($=>{const{distanceFromOrthogonalEdge:K,side:X}=$,ce=m[X],pe=y[X];return{x:ce.x+K*pe.x,y:ce.y+K*pe.y,...$}});return{getPortPositionByPinNumber($){const K=w.find(X=>X.pinNumber.toString()===$.toString());return K||null},getSize(){return{width:c,height:d}},getSizeIncludingPins(){return{width:c+(t.leftSize||t.rightSize?.4:0),height:d+(t.topSize||t.bottomSize?.4:0)}},pinCount:i}},sdt=Jm("tscircuit:core:footprint"),ldt=class extends N_{get config(){return{componentName:"Footprint",zodProps:hye}}doInitialPcbFootprintLayout(){var d,m,y,w,S;if((d=this.root)!=null&&d.pcbDisabled)return;const e=this.children.filter(b=>b.componentName==="Constraint");if(e.length===0)return;const{isFlipped:t}=this._getPcbPrimitiveFlippedHelpers(),n=b=>t&&"left"in b&&"right"in b?{...b,left:b.right,right:b.left}:b,i=e.flatMap(b=>b._getAllReferencedComponents().componentsWithSelectors).map(({component:b,selector:E,componentSelector:P,edge:U})=>({component:b,selector:E,componentSelector:P,edge:U,bounds:b._getPcbCircuitJsonBounds()}));if(i.some(b=>b.edge))throw new Error("edge constraints not implemented yet for footprint layout, contributions welcome!");function a(b){return i.find(({selector:E})=>E===b)}const o=new yG,s={};function l(b){return b in s||(s[b]=new sC(b),o.addEditVariable(s[b],ry.weak)),s[b]}for(const{selector:b,bounds:E}of i){const P=l(`${b}_x`),U=l(`${b}_y`);o.suggestValue(P,E.center.x),o.suggestValue(U,E.center.y)}for(const b of e){const E=b._parsedProps;if("xDist"in E){const{xDist:P,left:U,right:V,edgeToEdge:Y,centerToCenter:W}=n(E),$=l(`${U}_x`),K=l(`${V}_x`),X=(m=a(U))==null?void 0:m.bounds,ce=(y=a(V))==null?void 0:y.bounds;if(W){const pe=new R1(K,[-1,$]);o.addConstraint(new Cx(pe,p_.Eq,E.xDist,ry.required))}else if(Y){const pe=new R1(K,-ce.width/2,[-1,$],-X.width/2);o.addConstraint(new Cx(pe,p_.Eq,E.xDist,ry.required))}}else if("yDist"in E){const{yDist:P,top:U,bottom:V,edgeToEdge:Y,centerToCenter:W}=E,$=l(`${U}_y`),K=l(`${V}_y`),X=(w=a(U))==null?void 0:w.bounds,ce=(S=a(V))==null?void 0:S.bounds;if(W){const pe=new R1($,[-1,K]);o.addConstraint(new Cx(pe,p_.Eq,E.yDist,ry.required))}else if(Y){const pe=new R1($,X.height/2,[-1,K],-ce.height/2);o.addConstraint(new Cx(pe,p_.Eq,E.yDist,ry.required))}}else if("sameY"in E){const{for:P}=E;if(P.length<2)continue;const U=P.map(Y=>l(`${Y}_y`)),V=new R1(...U.slice(1));o.addConstraint(new Cx(V,p_.Eq,U[0],ry.required))}else if("sameX"in E){const{for:P}=E;if(P.length<2)continue;const U=P.map(Y=>l(`${Y}_x`)),V=new R1(...U.slice(1));o.addConstraint(new Cx(V,p_.Eq,U[0],ry.required))}}o.updateVariables(),sdt.enabled&&(console.log("Solution to layout constraints:"),console.table(Object.entries(s).map(([b,E])=>({var:b,val:E.value()}))));const c={left:1/0,right:-1/0,top:-1/0,bottom:1/0};for(const{selector:b,bounds:{width:E,height:P}}of i){const U=l(`${b}_x`),V=l(`${b}_y`),Y=U.value()-E/2,W=U.value()+E/2,$=V.value()+P/2,K=V.value()-P/2;c.left=Math.min(c.left,Y),c.right=Math.max(c.right,W),c.top=Math.max(c.top,$),c.bottom=Math.min(c.bottom,K)}const u={x:-(c.right+c.left)/2,y:-(c.top+c.bottom)/2},f=this.getPrimitiveContainer()._getGlobalPcbPositionBeforeLayout();u.x+=f.x,u.y+=f.y;for(const{component:b,selector:E}of i){const P=l(`${E}_x`),U=l(`${E}_y`);b._setPositionFromLayout({x:P.value()+u.x,y:U.value()+u.y})}}},cdt=(r,e)=>{if(!r)return;const t={};for(const[n,i]of Object.entries(r)){const a=hC(n,e),o={leftMargin:i.marginLeft??i.leftMargin,rightMargin:i.marginRight??i.rightMargin,topMargin:i.marginTop??i.topMargin,bottomMargin:i.marginBottom??i.bottomMargin};t[`pin${a}`]={...t[`pin${a}`],...o}}return t},Fge=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[n,i]=t.pointsToConnect,a={type:"pcb_trace",pcb_trace_id:"",connection_name:t.name,route:[{route_type:"wire",x:n.x,y:n.y,layer:"top",width:.1},{route_type:"wire",x:i.x,y:i.y,layer:"top",width:.1}]};e.push(a)}return e}},udt=r=>{const e=Math.min(...r.map(a=>a.center.x)),t=Math.max(...r.map(a=>a.center.x)),n=Math.min(...r.map(a=>a.center.y)),i=Math.max(...r.map(a=>a.center.y));return{minX:e,maxX:t,minY:n,maxY:i}},Bge=["top","bottom","inner1","inner2"],TL=(r,e=[])=>{var s;const t=[];if(e.length===0){const l=r[0].layers;for(const c of l)t.push(...TL(r.slice(1),[c]));return t}if(r.length===0)return[];const n=r[0],i=n.via||n.optional_via,a=e[e.length-1];if(r.length===1){const l=n;return l.layers&&i?l.layers.map(c=>({layer_path:[...e,c]})):(s=l.layers)!=null&&s.includes(a)?[{layer_path:[...e,a]}]:[]}if(!i)return n.layers&&!n.layers.includes(a)?[]:TL(r.slice(1),e.concat([a]));const o=(n.optional_via?Bge:Bge.filter(l=>l!==a)).filter(l=>{var c;return!n.layers||((c=n.layers)==null?void 0:c.includes(l))});for(const l of o)t.push(...TL(r.slice(1),e.concat(l)));return t};function jge(r){const e={x:r.to.x-r.from.x,y:r.to.y-r.from.y},t=Math.abs(e.x),n=Math.abs(e.y);return t>n?e.x>0?"right":"left":e.y>0?"down":"up"}function gT(r,e){return Math.hypot(r.x-e.x,r.y-e.y)}var fdt=r=>{if(r.length===1)return r[0];if(r.some(l=>l.length===0))throw new Error("Cannot merge routes with zero length");const e=[],t=r[0][0],n=r[0][r[0].length-1],i=r[1][0],a=r[1][r[1].length-1],o=Math.min(gT(t,i),gT(t,a)),s=Math.min(gT(n,i),gT(n,a));o<s?e.push(...r[0].reverse()):e.push(...r[0]);for(let l=1;l<r.length;l++){const c=e[e.length-1],u=r[l],f=u[0],d=u[u.length-1],m=gT(c,f),y=gT(c,d);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},ddt=(r,e)=>{const t="_getGlobalPcbPositionBeforeLayout"in r?r._getGlobalPcbPositionBeforeLayout():r,n="_getGlobalPcbPositionBeforeLayout"in e?e._getGlobalPcbPositionBeforeLayout():e;return Math.sqrt((t.x-n.x)**2+(t.y-n.y)**2)};function pdt(r,e){if(e.length===0)throw new Error("No candidates given to getClosest method");let t=e[0],n=1/0;for(const i of e){const a=ddt(r,i);a<n&&(t=i,n=a)}return t}var hdt=(r,e)=>{let t=0;t+=r.length??0,t+=e.filter(n=>n.is_crossing).length;for(let n=1;n<e.length;n++){const i=e[n-1],a=e[n],o=Math.abs(i.from.x-i.to.x)<.01,s=Math.abs(a.from.x-a.to.x)<.01;o!==s&&t++}return t},qG=r=>({up:"bottom",down:"top",left:"right",right:"left"})[r]??null,$G=({firstEdge:r,firstEdgePort:e,firstDominantDirection:t,lastEdge:n,lastEdgePort:i,lastDominantDirection:a})=>{if(r&&e)return $G({lastEdge:{from:r.to,to:r.from},lastEdgePort:e,lastDominantDirection:t}).reverse().map(s=>({from:s.to,to:s.from}));let o=[];if(n&&i){const s={x:n.to.x,y:n.to.y};a==="left"||a==="right"?(s.x=i.position.x,o.push({from:n.to,to:{...s}}),o.push({from:s,to:{...i.position}})):(s.y=i.position.y,o.push({from:n.to,to:{...s}}),o.push({from:s,to:{...i.position}}))}return o=o.filter(s=>R3(s.from,s.to)>.01),o};function mdt(r){try{return[r(),null]}catch(e){return[null,e]}}function vdt(r){let e=0;for(let t=0;t<r.length;t++){const n=r[t];if(n.route_type==="wire"){const i=r[t+1];if(i){const a=i.x-n.x,o=i.y-n.y;e+=Math.sqrt(a*a+o*o)}}else n.route_type==="via"&&(e+=1.6)}return e}var ydt=r=>{var s,l;const e={left:{x:-.5,y:0},up:{x:.5,y:.5},right:{x:.5,y:0},down:{x:0,y:-.5}}[r.facingDirection],t=(s=r.parent)!=null&&s.config.shouldRenderAsSchematicBox?3:1,n=(l=r.parent)!=null&&l.config.shouldRenderAsSchematicBox&&(r.facingDirection==="left"||r.facingDirection==="right")?3:1,i=e.x,a=e.y,o=r.facingDirection==="up"?.5:0;return{schBoxVertOffset:t,schBoxHorzOffset:n,horzPortDirection:i,vertPortDirectionOffset:a,handleUp:o}},ML=({port:r,anchorPos:e,schDisplayLabel:t,source_trace_id:n},{db:i})=>{const a=ydt(r);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:r.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:n})},YG=({db:r,source_trace_id:e,sameNetOnly:t,differentNetOnly:n})=>{!t&&!n&&(n=!0);const i=r.source_trace.get(e),a=[];for(const o of r.schematic_trace.list()){if(o.source_trace_id===e)continue;const s=r.source_trace.get(o.source_trace_id),l=(s==null?void 0:s.subcircuit_connectivity_map_key)===i.subcircuit_connectivity_map_key;n&&l||t&&!l||a.push(o)}return a},gdt=({edges:r,otherEdges:e})=>{const t=[...r];for(let n=0;n<t.length;n++){if(n>2e3)throw new Error("Over 2000 iterations spent inside createSchematicTraceCrossingSegments, you have triggered an infinite loop, please report this!");const i=t[n],a=Math.abs(i.from.x-i.to.x)<.01?"vertical":i.from.y===i.to.y?"horizontal":"not-orthogonal";if(a==="not-orthogonal")continue;const o=[];for(const w of e){const S=w.from.x===w.to.x?"vertical":w.from.y===w.to.y?"horizontal":"not-orthogonal";if(S==="not-orthogonal"||a===S)continue;if(cL([i.from,i.to],[w.from,w.to],{lineThickness:.01})){const E=a==="vertical"?i.from.x:w.from.x,P=a==="vertical"?w.from.y:i.from.y,U={x:E,y:P};o.push({otherEdge:w,crossingPoint:U,distanceFromEdgeFrom:R3(i.from,U)})}}if(o.length===0)continue;let s=o[0];for(const w of o)w.distanceFromEdgeFrom<s.distanceFromEdgeFrom&&(s=w);const l=s.crossingPoint,c=.075;if(l.x===i.from.x&&l.y===i.from.y)continue;const u=Fye(i.from,l),f={x:l.x-u.x*c/2,y:l.y-u.y*c/2},d={x:l.x+u.x*c/2,y:l.y+u.y*c/2},m=R3(d,i.to)<c,y=[{from:i.from,to:f},{from:f,to:d,is_crossing:!0},{from:d,to:i.to}];t.splice(n,1,...y),n+=y.length-2,m&&n++}return t},_dt=(r,e)=>{if(r.from.x===r.to.x&&e.from.x===e.to.x)return null;if(r.from.x===r.to.x){const u=r.from.x,f=(e.to.y-e.from.y)/(e.to.x-e.from.x),d=e.from.y-f*e.from.x,m=f*u+d;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,f=(r.to.y-r.from.y)/(r.to.x-r.from.x),d=r.from.y-f*r.from.x,m=f*u+d;return u>=Math.min(r.from.x,r.to.x)&&u<=Math.max(r.from.x,r.to.x)&&m>=Math.min(r.from.y,r.to.y)&&m<=Math.max(r.from.y,r.to.y)?{x:u,y:m}:null}const t=(r.to.y-r.from.y)/(r.to.x-r.from.x),n=r.from.y-t*r.from.x,i=(e.to.y-e.from.y)/(e.to.x-e.from.x),a=e.from.y-i*e.from.x;if(t===i)return null;const o=(a-n)/(t-i),s=t*o+n,l=o>=Math.min(r.from.x,r.to.x)&&o<=Math.max(r.from.x,r.to.x)&&s>=Math.min(r.from.y,r.to.y)&&s<=Math.max(r.from.y,r.to.y),c=o>=Math.min(e.from.x,e.to.x)&&o<=Math.max(e.from.x,e.to.x)&&s>=Math.min(e.from.y,e.to.y)&&s<=Math.max(e.from.y,e.to.y);return l&&c?{x:o,y:s}:null},xdt=({edges:r,db:e,source_trace_id:t})=>{const n=YG({db:e,source_trace_id:t,sameNetOnly:!0}).flatMap(i=>i.edges);for(const i of r)for(const a of n){const o=_dt(i,a);if(o)return`${o.x}${o.y}`,[{x:o.x,y:o.y}]}return[]},bdt=(r,{db:e})=>{const t=r.map(n=>{const i=e.source_port.get(n.source_port_id);if(!(i!=null&&i.source_component_id))return null;const a=e.source_component.get(i.source_component_id);return(a==null?void 0:a.ftype)==="simple_capacitor"?a.max_decoupling_trace_length:null}).filter(n=>n!==null);if(t.length!==0)return Math.min(...t)};function Sdt(r){var a,o,s,l,c,u,f,d,m;let e=1/0,t=1/0,n=-1/0,i=-1/0;for(const y of r){let w,S,b,E;y.type==="schematic_component"?(w=(a=y.center)==null?void 0:a.x,S=(o=y.center)==null?void 0:o.y,b=(s=y.size)==null?void 0:s.width,E=(l=y.size)==null?void 0:l.height):y.type==="schematic_box"?(w=y.x,S=y.y,b=y.width,E=y.height):y.type==="schematic_port"?(w=(c=y.center)==null?void 0:c.x,S=(u=y.center)==null?void 0:u.y,b=.2,E=.2):y.type==="schematic_text"&&(w=(f=y.position)==null?void 0:f.x,S=(d=y.position)==null?void 0:d.y,b=(((m=y.text)==null?void 0:m.length)??0)*.1,E=.2),typeof w=="number"&&typeof S=="number"&&typeof b=="number"&&typeof E=="number"&&(e=Math.min(e,w-b/2),n=Math.max(n,w+b/2),t=Math.min(t,S-E/2),i=Math.max(i,S+E/2))}return{minX:e,maxX:n,minY:t,maxY:i}}function wdt(r,e={}){const{minX:t,maxX:n,minY:i,maxY:a}=r,o=e.padding??1;if(!isFinite(t)||!isFinite(n)||!isFinite(i)||!isFinite(a))return[];const s=t-o,l=n+o,c=a+o,u=i-o,f=.01;return[{type:"rect",layers:["top"],center:{x:(s+l)/2,y:c},width:l-s,height:f,connectedTo:[]},{type:"rect",layers:["top"],center:{x:(s+l)/2,y:u},width:l-s,height:f,connectedTo:[]},{type:"rect",layers:["top"],center:{x:s,y:(c+u)/2},width:f,height:c-u,connectedTo:[]},{type:"rect",layers:["top"],center:{x:l,y:(c+u)/2},width:f,height:c-u,connectedTo:[]}]}var Edt=r=>{var o;const e=r.root.db,t=r._findConnectedPorts().ports??[],n=new Set(t.map(s=>s.schematic_port_id)),i=[];for(const s of e.toArray()){if(s.type==="schematic_component"){const l=!!s.symbol_name,c=s.size.width>s.size.height?"horz":"vert";i.push({type:"rect",layers:["top"],center:s.center,width:s.size.width+(l&&c==="horz"?-.5:0),height:s.size.height+(l&&c==="vert"?-.5:0),connectedTo:[]})}if(s.type==="schematic_port"){if(n.has(s.schematic_port_id))continue;const l=s.facing_direction?Bye(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=Sdt(e.toArray());return i.push(...wdt(a,{padding:1})),i};function Tdt({ports:r,nets:e}){var t,n,i;if(r.length>=2)return`${(t=r[0])==null?void 0:t.selector} to ${(n=r[1])==null?void 0:n.selector}`;if(r.length===1&&e.length===1)return`${(i=r[0])==null?void 0:i.selector} to net.${e[0]._parsedProps.name}`}var Mdt=({edges:r,db:e,source_trace_id:t})=>{e.source_trace.get(t);const n=YG({db:e,source_trace_id:t,differentNetOnly:!0}).flatMap(a=>a.edges),i=a=>{const{from:o,to:s}=a;return o.x===s.x?"vertical":"horizontal"};for(const a of r){const o=i(a),s=()=>n.find(c=>i(c)===o&&cL([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()}},Cdt=(r,{db:e})=>{const t=e.pcb_board.list()[0];if(t.outline){const l=t.outline,c=(u,f)=>{let d=!1;for(let m=0,y=f.length-1;m<f.length;y=m++){const w=f[m].x,S=f[m].y,b=f[y].x,E=f[y].y;S>u.y!=E>u.y&&u.x<(b-w)*(u.y-S)/(E-S)+w&&(d=!d)}return d};return r.some(u=>!c(u,l))}const n=t.width,i=t.height,a=t.center.x,o=t.center.y;return r.some(l=>l.x<a-n/2||l.y<o-i/2||l.x>a+n/2||l.y>o+i/2)},CL=r=>({...r._getGlobalPcbPositionAfterLayout(),layers:r.getAvailablePcbLayers()}),a8=class extends N_{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:pye,componentName:"Trace"}}_getTracePortOrNetSelectorListFromProps(){return"from"in this.props&&"to"in this.props?[typeof this.props.from=="string"?this.props.from:this.props.from.getPortSelector(),typeof this.props.to=="string"?this.props.to:this.props.to.getPortSelector()]:"path"in this.props?this.props.path.map(t=>typeof t=="string"?t:t.getPortSelector()):[]}getTracePortPathSelectors(){return this._getTracePortOrNetSelectorListFromProps().filter(t=>!t.includes("net."))}getTracePathNetSelectors(){return this._getTracePortOrNetSelectorListFromProps().filter(t=>t.includes("net."))}_findConnectedPorts(){const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i)throw new Error("Trace has no parent");const o=this.getTracePortPathSelectors().map(s=>({selector:s,port:this.getSubcircuit().selectOne(s,{type:"port"})??null}));for(const{selector:s,port:l}of o)if(!l){const c=s.replace(/(\> )?[^ ]+$/,""),u=this.getSubcircuit().selectOne(c);u?this.renderError(`Could not find port for selector "${s}" (did you forget to include the pin name?)
|
|
829
|
+
${i.stack}`),n.complete=!0,"root"in this&&this.root&&this.root.emit("asyncEffect:end",{effectName:e,componentDisplayName:this.getString(),phase:n.phase,error:i.toString()})})}_emitRenderLifecycleEvent(e,t){Bft(`${e}:${t} ${this.getString()}`);const n=`renderable:renderLifecycle:${e}:${t}`,i={renderId:this._renderId,componentDisplayName:this.getString(),type:n};"root"in this&&this.root&&(this.root.emit(n,i),this.root.emit("renderable:renderLifecycle:anyEvent",{...i,type:n}))}getString(){return this.constructor.name}_hasIncompleteAsyncEffects(){return this._asyncEffects.some(e=>!e.complete)}getCurrentRenderPhase(){return this._currentRenderPhase}getRenderGraph(){return{id:this._renderId,currentPhase:this._currentRenderPhase,renderPhaseStates:this.renderPhaseStates,shouldBeRemoved:this.shouldBeRemoved,children:this.children.map(e=>e.getRenderGraph())}}runRenderCycle(){for(const e of U5)this.runRenderPhaseForChildren(e),this.runRenderPhase(e)}runRenderPhase(e){var o,s,l;this._currentRenderPhase=e;const t=this.renderPhaseStates[e],n=t.initialized,i=t.dirty;if(!n&&this.shouldBeRemoved)return;if(this.shouldBeRemoved&&n){this._emitRenderLifecycleEvent(e,"start"),(o=this==null?void 0:this[`remove${e}`])==null||o.call(this),t.initialized=!1,t.dirty=!1,this._emitRenderLifecycleEvent(e,"end");return}const a=U5.indexOf(e)-1;if(a>=0){const c=U5[a];if(this._asyncEffects.filter(f=>f.phase===c).some(f=>!f.complete))return}if(this._emitRenderLifecycleEvent(e,"start"),n){i&&((s=this==null?void 0:this[`update${e}`])==null||s.call(this),t.dirty=!1),this._emitRenderLifecycleEvent(e,"end");return}t.dirty=!1,(l=this==null?void 0:this[`doInitial${e}`])==null||l.call(this),t.initialized=!0,this._emitRenderLifecycleEvent(e,"end")}runRenderPhaseForChildren(e){for(const t of this.children)t.runRenderPhaseForChildren(e),t.runRenderPhase(e)}renderError(e){throw typeof e=="string"?new Error(e):new Error(JSON.stringify(e,null,2))}},EL={},Tge=r=>{const e=Object.fromEntries(Object.entries(r).map(([t,n])=>[t.toLowerCase(),n]));Object.assign(EL,r),Object.assign(EL,e)},Hft=class extends Error{constructor(e,t,n){let i;const o=Object.keys(n).filter(s=>s!=="_errors").map(s=>n[s]._errors[0]?`${s} (${n[s]._errors[0]})`:`${s} (${JSON.stringify(n[s])})`).join(", ");"name"in t?i=`Invalid props for ${e} "${t.name}": ${o}`:"footprint"in t&&typeof t.footprint=="string"?i=`Invalid props for ${e} (unnamed ${t.footprint} component): ${o}`:i=`Invalid props for ${e} (unnamed): ${o}`,super(i),this.componentName=e,this.originalProps=t,this.formattedError=n}};function FG(r,e){const t=e.match(/^#(\w+)/);if(t)return r.props.id===t[1];const n=e.match(/^\.(\w+)/);if(n)return r.isMatchingNameOrAlias(n[1]);let[i,...a]=e.split(/(?=[#.[])/);return i==="pin"&&(i="port"),i&&i!=="*"&&r.lowercaseComponentName!==i.toLowerCase()?!1:a.every(o=>{if(o.startsWith("#"))return r.props.id===o.slice(1);if(o.startsWith("."))return r.isMatchingNameOrAlias(o.slice(1));const s=o.match(/\[(\w+)=['"]?(.+?)['"]?\]/);if(!s)return!0;const[,l,c]=s;return r.props[l].toString()===c})}var BG={isTag:r=>!0,getParent:r=>r.parent,getChildren:r=>r.children,getName:r=>r.lowercaseComponentName,getAttributeValue:(r,e)=>{var t;if(e==="class"&&"getNameAndAliases"in r)return r.getNameAndAliases().join(" ");if(e==="name"&&((t=r._parsedProps)!=null&&t.name))return r._parsedProps.name;if(r._parsedProps&&e in r._parsedProps){const n=r._parsedProps[e];return typeof n=="string"?n:n!=null?String(n):null}return null},hasAttrib:(r,e)=>{var t;return e==="class"?!!((t=r._parsedProps)!=null&&t.name):r._parsedProps&&e in r._parsedProps},getSiblings:r=>r.parent?r.parent.children:[],prevElementSibling:r=>{if(!r.parent)return null;const e=r.parent.children,t=e.indexOf(r);return t>0?e[t-1]:null},getText:()=>"",removeSubsets:r=>r.filter((e,t)=>!r.some((n,i)=>t!==i&&n!==e&&n.getDescendants().includes(e))),existsOne:(r,e)=>e.some(r),findAll:(r,e)=>{const t=[],n=i=>{r(i)&&t.push(i);for(const a of i.children)n(a)};for(const i of e)n(i);return t},findOne:(r,e)=>{for(const t of e){if(r(t))return t;const n=t.children;if(n.length>0){const i=BG.findOne(r,n);if(i)return i}}return null},equals:(r,e)=>r._renderId===e._renderId,isHovered:r=>!1,isVisited:r=>!1,isActive:r=>!1},Vft={...BG,getChildren:r=>r.children.filter(e=>!e.isSubcircuit)},Mge={...BG,getChildren:r=>r.children.filter(e=>e.isSubcircuit)},Cge=r=>r.replace(/ pin/g," port").replace(/ subcircuit\./g," group[isSubcircuit=true]").replace(/([^ ])\>([^ ])/g,"$1 > $2").trim(),jG={adapter:Vft,cacheResults:!0},N_=class extends Ege{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 n=this.config.zodProps.safeParse(t??{});if(n.success)this._parsedProps=n.data;else throw new Hft(this.lowercaseComponentName,this.props,n.error.format())}get config(){return{componentName:"",zodProps:R.object({}).passthrough()}}get componentName(){return this.config.componentName}getInheritedProperty(t){var i;let n=this;for(;n;){if(n._parsedProps&&t in n._parsedProps)return n._parsedProps[t];n=n.parent}if((i=this.root)!=null&&i.platform&&t in this.root.platform)return this.root.platform[t]}get lowercaseComponentName(){return this.componentName.toLowerCase()}get isSubcircuit(){var t;return!!this.props.subcircuit||this.lowercaseComponentName==="group"&&((t=this==null?void 0:this.parent)==null?void 0:t.isRoot)}get isGroup(){return this.lowercaseComponentName==="group"}setProps(t){var a,o;const n=this.config.zodProps.parse({...this.props,...t}),i=this.props;this.props=n,this._parsedProps=this.config.zodProps.parse(t),this.onPropsChange({oldProps:i,newProps:n,changedProps:Object.keys(t)}),(o=(a=this.parent)==null?void 0:a.onChildChanged)==null||o.call(a,this)}computePcbPropsTransform(){const{_parsedProps:t}=this;return wc(zf(t.pcbX??0,t.pcbY??0),f2((t.pcbRotation??0)*Math.PI/180))}_computePcbGlobalTransformBeforeLayout(){var i,a,o;const{_parsedProps:t}=this,n=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if(n&&this.props.pcbX===void 0&&this.props.pcbY===void 0)return wc(((i=this.parent)==null?void 0:i._computePcbGlobalTransformBeforeLayout())??ev(),wc(zf(n.x,n.y),f2((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 wc(zf(c.x,c.y),WE(),zf(-c.x,-c.y)),wc(((a=this.parent)==null?void 0:a._computePcbGlobalTransformBeforeLayout())??ev(),WE(),this.computePcbPropsTransform())}}return wc(((o=this.parent)==null?void 0:o._computePcbGlobalTransformBeforeLayout())??ev(),this.computePcbPropsTransform())}getPrimitiveContainer(){var t,n;return this.isPrimitiveContainer?this:((n=(t=this.parent)==null?void 0:t.getPrimitiveContainer)==null?void 0:n.call(t))??null}_getPcbCircuitJsonBounds(){return{center:{x:0,y:0},bounds:{left:0,top:0,right:0,bottom:0},width:0,height:0}}_getPcbPrimitiveFlippedHelpers(){const t=this.getPrimitiveContainer(),n=t?t._parsedProps.layer==="bottom":!1;return{isFlipped:n,maybeFlipLayer:a=>n?a==="top"?"bottom":"top":a}}_setPositionFromLayout(t){throw new Error(`_setPositionFromLayout not implemented for ${this.componentName}`)}computeSchematicPropsTransform(){const{_parsedProps:t}=this;return wc(zf(t.schX??0,t.schY??0))}computeSchematicGlobalTransform(){var n,i;const t=this._getSchematicGlobalManualPlacementTransform(this);return t||wc(((i=(n=this.parent)==null?void 0:n.computeSchematicGlobalTransform)==null?void 0:i.call(n))??ev(),this.computeSchematicPropsTransform())}_getSchematicSymbolName(){const{_parsedProps:t}=this,n=this.config.schematicSymbolName;let i=t.schRotation;if(i===void 0&&(i=0),i=i%360,i<0&&(i+=360),t.schRotation!==void 0&&i%90!==0)throw new Error(`Schematic rotation ${t.schRotation} is not supported for ${this.componentName}`);const a=`${n}_horz`,o=`${n}_vert`,s=`${n}_up`,l=`${n}_down`,c=`${n}_left`,u=`${n}_right`;if(u in d_&&i===0)return u;if(s in d_&&i===90)return s;if(c in d_&&i===180)return c;if(l in d_&&i===270)return l;if(a in d_&&(i===0||i===180))return a;if(o in d_&&(i===90||i===270))return o;if(n in d_)return n}_getSchematicSymbolNameOrThrow(){const t=this._getSchematicSymbolName();if(!t)throw new Error(`No schematic symbol found (given: "${this.config.schematicSymbolName}")`);return t}getSchematicSymbol(){const t=this._getSchematicSymbolName();return t?d_[t]??null:null}_getPcbManualPlacementForComponent(t){var o;if(!this.isSubcircuit)return null;const n=this.props.layout,i=this.props.manualEdits;if(!n&&!i)return null;const a=((o=n==null?void 0:n.manual_pcb_placement_config)==null?void 0:o.positions)||(i==null?void 0:i.pcb_placements);if(!a)return null;for(const s of a)if(n&&FG(t,s.selector)||t.props.name===s.selector)return kr(this._computePcbGlobalTransformBeforeLayout(),s.center);return null}_getSchematicManualPlacementForComponent(t){if(!this.isSubcircuit)return null;const n=this.props.manualEdits;if(!n)return null;const i=n.schematic_placements;if(!i)return null;for(const a of i)if(FG(t,a.selector)||t.props.name===a.selector)return kr(this.computeSchematicGlobalTransform(),a.center);return null}_getSchematicGlobalManualPlacementTransform(t){var i,a;const n=(i=this.getSubcircuit())==null?void 0:i._parsedProps.manualEdits;if(!n)return null;for(const o of n.schematic_placements??[])if((FG(t,o.selector)||t.props.name===o.selector)&&o.relative_to==="group_center")return wc(((a=this.parent)==null?void 0:a._computePcbGlobalTransformBeforeLayout())??ev(),zf(o.center.x,o.center.y));return null}_getGlobalPcbPositionBeforeLayout(){return kr(this._computePcbGlobalTransformBeforeLayout(),{x:0,y:0})}_getGlobalSchematicPositionBeforeLayout(){return kr(this.computeSchematicGlobalTransform(),{x:0,y:0})}get root(){var t;return((t=this.parent)==null?void 0:t.root)??null}onAddToParent(t){this.parent=t}onPropsChange(t){}onChildChanged(t){var n,i;(i=(n=this.parent)==null?void 0:n.onChildChanged)==null||i.call(n,t)}add(t){if(!t.onAddToParent)throw new Error(`Invalid JSX Element: Expected a React component but received "${JSON.stringify(t)}"`);t.onAddToParent(this),t.parent=this,this.children.push(t)}addAll(t){for(const n of t)this.add(n)}remove(t){this.children=this.children.filter(n=>n!==t),this.childrenPendingRemoval.push(t),t.shouldBeRemoved=!0}getSubcircuitSelector(){const t=this._parsedProps.name,n=t?`${this.lowercaseComponentName}.${t}`:this.lowercaseComponentName;return!this.parent||this.parent.isSubcircuit?n:`${this.parent.getSubcircuitSelector()} > ${n}`}getFullPathSelector(){var a,o;const t=this._parsedProps.name,n=t?`${this.lowercaseComponentName}.${t}`:this.lowercaseComponentName,i=(o=(a=this.parent)==null?void 0:a.getFullPathSelector)==null?void 0:o.call(a);return i?`${i} > ${n}`:n}getNameAndAliases(){return[this._parsedProps.name,...this._parsedProps.portHints??[]].filter(Boolean)}isMatchingNameOrAlias(t){return this.getNameAndAliases().includes(t)}isMatchingAnyOf(t){return this.getNameAndAliases().some(n=>t.map(i=>i.toString()).includes(n))}getPcbSize(){throw new Error(`getPcbSize not implemented for ${this.componentName}`)}doesSelectorMatch(t){const n=[this.componentName,this.lowercaseComponentName],i=[this._parsedProps.name].filter(Boolean),a=t.trim().split(/\> /)[0],o=a[0];return a.length>1?!1:!!(t==="*"||t[0]==="#"&&t.slice(1)===this.props.id||t[0]==="."&&i.includes(t.slice(1))||/^[a-zA-Z0-9_]/.test(o)&&n.includes(o))}getSubcircuit(){var n,i;if(this.isSubcircuit)return this;const t=(i=(n=this.parent)==null?void 0:n.getSubcircuit)==null?void 0:i.call(n);if(!t)throw new Error("Component is not inside an opaque group (no board?)");return t}getGroup(){var t,n;return this.isGroup?this:((n=(t=this.parent)==null?void 0:t.getGroup)==null?void 0:n.call(t))??null}doInitialOptimizeSelectorCache(){var n;if(!this.isSubcircuit)return;const t=this.selectAll("port");for(const i of t){const a=(n=i.parent)==null?void 0:n.getNameAndAliases(),o=i.getNameAndAliases();if(a)for(const s of a)for(const l of o){const c=[`.${s} > .${l}`,`.${s} .${l}`];for(const u of c){const f=this._cachedSelectAllQueries.get(u);f?f.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 n=Cge(t),i=lT(n,this,jG);if(i.length>0)return this._cachedSelectAllQueries.set(t,i),i;const[a,...o]=n.split(" "),s=zS(a,this,{adapter:Mge});if(!s)return[];const l=s.selectAll(o.join(" "));return this._cachedSelectAllQueries.set(t,l),l}selectOne(t,n){if(this._cachedSelectOneQueries.has(t))return this._cachedSelectOneQueries.get(t);const i=Cge(t);n!=null&&n.port&&(n.type="port");let a=null;if(n!=null&&n.type&&(a=lT(i,this,jG).find(u=>u.lowercaseComponentName===n.type)),a??(a=zS(i,this,jG)),a)return this._cachedSelectOneQueries.set(t,a),a;const[o,...s]=i.split(" "),l=zS(o,this,{adapter:Mge});return l?(a=l.selectOne(s.join(" "),n),this._cachedSelectOneQueries.set(t,a),a):null}getAvailablePcbLayers(){var t,n;if(this.isPcbPrimitive){const{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers();return"layer"in this._parsedProps||this.componentName==="SmtPad"?[i(this._parsedProps.layer??"top")]:"layers"in this._parsedProps?this._parsedProps.layers:this.componentName==="PlatedHole"?((n=(t=this.root)==null?void 0:t._getBoard())==null?void 0:n.allLayers)??["top","bottom"]:[]}return[]}getDescendants(){const t=[];for(const n of this.children)t.push(n),t.push(...n.getDescendants());return t}getSelectableDescendants(){const t=[];for(const n of this.children)n.isSubcircuit?t.push(n):(t.push(n),t.push(...n.getSelectableDescendants()));return t}_getPinCount(){return 0}_getSchematicBoxDimensions(){return null}renderError(t){var n;if(typeof t=="string")return super.renderError(t);(n=this.root)==null||n.db.pcb_placement_error.insert(t)}getString(){var a,o;const{lowercaseComponentName:t,_parsedProps:n,parent:i}=this;return(n==null?void 0:n.pinNumber)!==void 0&&((a=i==null?void 0:i.props)!=null&&a.name)&&(n!=null&&n.name)?`<${t}#${this._renderId}(pin:${n.pinNumber} .${i==null?void 0:i.props.name}>.${n.name}) />`:(o=i==null?void 0:i.props)!=null&&o.name&&(n!=null&&n.name)?`<${t}#${this._renderId}(.${i==null?void 0:i.props.name}>.${n==null?void 0:n.name}) />`:n!=null&&n.from&&(n!=null&&n.to)?`<${t}#${this._renderId}(from:${n.from} to:${n==null?void 0:n.to}) />`:n!=null&&n.name?`<${t}#${this._renderId} name=".${n==null?void 0:n.name}" />`:n!=null&&n.portHints?`<${t}#${this._renderId}(${n.portHints.map(s=>`.${s}`).join(", ")}) />`:`<${t}#${this._renderId} />`}get[Symbol.toStringTag](){return this.getString()}[Symbol.for("nodejs.util.inspect.custom")](){return this.getString()}},Gft=class extends N_{constructor(e,t){super(e),this._parsedProps={...e,error:t,type:e.type||"unknown",component_name:e.name,error_type:"source_failed_to_create_component_error",message:t instanceof Error?t.message:String(t),pcbX:e.pcbX,pcbY:e.pcbY,schX:e.schX,schY:e.schY}}get config(){return{componentName:"ErrorPlaceholder",zodProps:R.object({}).passthrough()}}doInitialSourceRender(){var e;if((e=this.root)!=null&&e.db){const t=this._getGlobalPcbPositionBeforeLayout(),n=this._getGlobalSchematicPositionBeforeLayout();this.root.db.source_failed_to_create_component_error.insert({component_name:this._parsedProps.component_name,message:this._parsedProps.message,pcb_center:t,schematic_center:n})}}};function qft(r,e){return new Gft(r,e)}function $ft(r,e){const t=r;return t.__tsci={...e},r}var Rge={supportsMutation:!0,createInstance(r,e){const t=EL[r];if(!t)throw Object.keys(EL).length===0?new Error("No components registered in catalogue, did you forget to import lib/register-catalogue in your test file?"):new Error(`Unsupported component type (not registered in @tscircuit/core catalogue): "${r}" See CREATING_NEW_COMPONENTS.md`);try{return $ft(new t(e),{})}catch(n){return qft(e,n)}},createTextInstance(){return{}},appendInitialChild(r,e){r.add(e)},appendChild(r,e){r.add(e)},appendChildToContainer(r,e){r.add(e)},finalizeInitialChildren(){return!1},prepareUpdate(){return null},shouldSetTextContent(){return!1},getRootHostContext(){return{}},getChildHostContext(){return{}},prepareForCommit(){return null},resetAfterCommit(){},commitMount(){},commitUpdate(){},removeChild(){},clearContainer(){},supportsPersistence:!1,getPublicInstance(r){return r},preparePortalMount(r){throw new Error("Function not implemented.")},scheduleTimeout(r,e){throw new Error("Function not implemented.")},cancelTimeout(r){throw new Error("Function not implemented.")},noTimeout:void 0,isPrimaryRenderer:!1,getInstanceFromNode(r){throw new Error("Function not implemented.")},beforeActiveInstanceBlur(){throw new Error("Function not implemented.")},afterActiveInstanceBlur(){throw new Error("Function not implemented.")},prepareScopeUpdate:(r,e)=>{throw new Error("Function not implemented.")},getInstanceFromScope:r=>{throw new Error("Function not implemented.")},detachDeletedInstance:r=>{throw new Error("Function not implemented.")},getCurrentEventPriority:()=>OS.DefaultEventPriority,getCurrentUpdatePriority:()=>OS.DefaultEventPriority,resolveUpdatePriority:()=>OS.DefaultEventPriority,setCurrentUpdatePriority:()=>{},maySuspendCommit:()=>!1,supportsHydration:!1},i8;Zc.version.startsWith("19.")?i8=TH(Rge):i8=RH(Rge);var Yft=r=>{const e={children:[],props:{name:"$root"},add(a){a.parent=this,this.children.push(a)},computePcbGlobalTransform(){return ev()}},t=[],n=i8.createContainer(e,0,null,!1,null,"tsci",a=>{console.log("Error in createContainer"),console.error(a),t.push(a)},null);if(Zc.version.startsWith("19.")?(i8.updateContainerSync(r,n,null,()=>{}),i8.flushSyncWork()):i8.updateContainer(r,n,null,()=>{}),t.length>0)throw t[0];const i=i8.getPublicRootInstance(n);return i||e.children[0]},hC=(r,e)=>{if(typeof r=="number")return r;if(r.startsWith("pin"))return Number(r.slice(3));if(!e)throw new Error(`No pin labels provided and pin number or label is not a number: "${r}"`);for(const t in e)if((Array.isArray(e[t])?e[t]:[e[t]]).includes(r))return Number(t.replace("pin",""));throw new Error(`No pin labels provided and pin number or label is not a number: "${r}"`)},Xft=(r,e)=>{if(!r)return;const t={},n={};for(const[i,a]of Object.entries(r)){const o=hC(i,e);n[o]={...n[o],...a}}for(const[i,a]of Object.entries(n)){const o=`pin${i}`;t[o]={bottom_margin:a.bottomMargin,left_margin:a.leftMargin,right_margin:a.rightMargin,top_margin:a.topMargin}}return t},Wft=r=>{if(r){if("leftSide"in r||"rightSide"in r||"topSide"in r||"bottomSide"in r)return{left_side:r.leftSide,right_side:r.rightSide,top_side:r.topSide,bottom_side:r.bottomSide};if("leftPinCount"in r||"rightPinCount"in r||"topPinCount"in r||"bottomPinCount"in r)return{left_size:r.leftPinCount,right_size:r.rightPinCount,top_size:r.topPinCount,bottom_size:r.bottomPinCount};if("leftSize"in r||"rightSize"in r||"topSize"in r||"bottomSize"in r)return{left_size:r.leftSize,right_size:r.rightSize,top_size:r.topSize,bottom_size:r.bottomSize}}};function Age(r){const e=[];for(let t=0;t<r.length-1;t++)e.push([r[t],r[t+1]]);return e}var Zft=R.object({name:R.string()}),Pge=class extends N_{constructor(){super(...arguments);Je(this,"source_net_id")}get config(){return{componentName:"Net",zodProps:Zft}}getPortSelector(){return`net.${this.props.name}`}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_net.insert({name:n.name,member_source_group_ids:[]});this.source_net_id=i.source_net_id}doInitialSourceParentAttachment(){const t=this.getSubcircuit();if(!t)return;const{db:n}=this.root;n.source_net.update(this.source_net_id,{subcircuit_id:t.subcircuit_id})}getAllConnectedPorts(){const t=this.getSubcircuit().selectAll("port"),n=[];for(const i of t){const a=i._getDirectlyConnectedTraces();for(const o of a)if(o._isExplicitlyConnectedToNet(this)){n.push(i);break}}return n}_getAllDirectlyConnectedTraces(){const t=this.getSubcircuit().selectAll("trace"),n=[];for(const i of t)i._isExplicitlyConnectedToNet(this)&&n.push(i);return n}doInitialPcbRouteNetIslands(){var s;if((s=this.root)!=null&&s.pcbDisabled||this.getSubcircuit()._parsedProps.routingDisabled||this.getSubcircuit()._getAutorouterConfig().groupMode!=="sequential-trace")return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getAllDirectlyConnectedTraces().filter(l=>{var c;return(((c=l._portsRoutedOnPcb)==null?void 0:c.length)??0)>0}),a=[];for(const l of i){const c=l._portsRoutedOnPcb,u=a.find(f=>c.some(d=>f.ports.includes(d)));if(!u){a.push({ports:[...c],traces:[l]});continue}u.traces.push(l),u.ports.push(...c)}if(a.length===0)return;const o=Age(a);for(const[l,c]of o){const u=l.ports.map(P=>P._getGlobalPcbPositionBeforeLayout()),f=c.ports.map(P=>P._getGlobalPcbPositionBeforeLayout());let d=1/0,m=[-1,-1];for(let P=0;P<u.length;P++){const U=u[P];for(let V=0;V<f.length;V++){const Y=f[V],W=Math.sqrt((U.x-Y.x)**2+(U.y-Y.y)**2);W<d&&(d=W,m=[P,V])}}const y=l.ports[m[0]],w=c.ports[m[1]],S=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:b}=lG(S.concat([{type:"source_trace",source_trace_id:"__net_trace_tmp",connected_source_port_ids:[y.source_port_id,w.source_port_id]}])),E=b[0];if(!E){this.renderError({pcb_trace_error_id:"",pcb_trace_id:"__net_trace_tmp",pcb_component_ids:[y.pcb_component_id,w.pcb_component_id].filter(Boolean),pcb_port_ids:[y.pcb_port_id,w.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(E)}}renderError(t){var n;if(typeof t=="string")return super.renderError(t);(n=this.root)==null||n.db.pcb_trace_error.insert(t)}},Nge=(r,e)=>{for(const t of e)if(typeof t=="string"&&t.startsWith("net.")){const n=r.getSubcircuit();if(!n.selectOne(t)){const i=new Pge({name:t.split("net.")[1]});n.add(i)}}},HG=class extends N_{constructor(){super(...arguments);Je(this,"pcb_smtpad_id",null);Je(this,"matchedPort",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SmtPad",zodProps:uye}}getPcbSize(){const{_parsedProps:t}=this;if(t.shape==="circle")return{width:t.radius*2,height:t.radius*2};if(t.shape==="rect")return{width:t.width,height:t.height};throw new Error(`getPcbSize for shape "${t.shape}" not implemented for ${this.componentName}`)}doInitialPortMatching(){var n;const t=(n=this.getPrimitiveContainer())==null?void 0:n.selectAll("port");if(this.props.portHints){for(const i of t)if(i.isMatchingAnyOf(this.props.portHints)){this.matchedPort=i,i.registerMatch(this);return}}}doInitialPcbPrimitiveRender(){var m,y,w,S,b,E,P,U,V,Y;if((m=this.root)!=null&&m.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this;if(!n.portHints)return;const i=this.getPrimitiveContainer(),a=this.getSubcircuit(),o=this._getGlobalPcbPositionBeforeLayout();i==null||i._getGlobalPcbPositionBeforeLayout();const s=kw(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 f=null;const d=((y=this.parent)==null?void 0:y.pcb_component_id)??((w=this.getPrimitiveContainer())==null?void 0:w.pcb_component_id);n.shape==="circle"?(f=t.pcb_smtpad.insert({pcb_component_id:d,pcb_port_id:(S=this.matchedPort)==null?void 0:S.pcb_port_id,layer:c(n.layer??"top"),shape:"circle",radius:n.radius,port_hints:n.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:f.layer,shape:"circle",radius:f.radius*.7,x:f.x,y:f.y,pcb_component_id:f.pcb_component_id,pcb_smtpad_id:f.pcb_smtpad_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((b=this.getGroup())==null?void 0:b.pcb_group_id)??void 0})):n.shape==="rect"&&(f=u===0||l?t.pcb_smtpad.insert({pcb_component_id:d,pcb_port_id:(E=this.matchedPort)==null?void 0:E.pcb_port_id,layer:c(n.layer??"top"),shape:"rect",width:l?n.height:n.width,height:l?n.width:n.height,port_hints:n.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:d,layer:c(n.layer??"top"),shape:"rotated_rect",width:n.width,height:n.height,x:o.x,y:o.y,ccw_rotation:u,port_hints:n.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}),f.shape==="rect"&&t.pcb_solder_paste.insert({layer:c(n.layer??"top"),shape:"rect",width:f.width*.7,height:f.height*.7,x:f.x,y:f.y,pcb_component_id:f.pcb_component_id,pcb_smtpad_id:f.pcb_smtpad_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((V=this.getGroup())==null?void 0:V.pcb_group_id)??void 0}),f.shape==="rotated_rect"&&t.pcb_solder_paste.insert({layer:c(n.layer??"top"),shape:"rotated_rect",width:f.width*.7,height:f.height*.7,x:f.x,y:f.y,ccw_rotation:u,pcb_component_id:f.pcb_component_id,pcb_smtpad_id:f.pcb_smtpad_id,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((Y=this.getGroup())==null?void 0:Y.pcb_group_id)??void 0})),f&&(this.pcb_smtpad_id=f.pcb_smtpad_id)}doInitialPcbPortAttachment(){var n,i;if((n=this.root)!=null&&n.pcbDisabled)return;const{db:t}=this.root;t.pcb_smtpad.update(this.pcb_smtpad_id,{pcb_port_id:(i=this.matchedPort)==null?void 0:i.pcb_port_id})}_getPcbCircuitJsonBounds(){const{db:t}=this.root,n=t.pcb_smtpad.get(this.pcb_smtpad_id);if(n.shape==="rect")return{center:{x:n.x,y:n.y},bounds:{left:n.x-n.width/2,top:n.y+n.height/2,right:n.x+n.width/2,bottom:n.y-n.height/2},width:n.width,height:n.height};if(n.shape==="rotated_rect"){const i=n.ccw_rotation*Math.PI/180,a=Math.cos(i),o=Math.sin(i),s=n.width/2,l=n.height/2,c=Math.abs(s*a)+Math.abs(l*o),u=Math.abs(s*o)+Math.abs(l*a);return{center:{x:n.x,y:n.y},bounds:{left:n.x-c,right:n.x+c,top:n.y-u,bottom:n.y+u},width:c*2,height:u*2}}if(n.shape==="circle")return{center:{x:n.x,y:n.y},bounds:{left:n.x-n.radius,top:n.y-n.radius,right:n.x+n.radius,bottom:n.y+n.radius},width:n.radius*2,height:n.radius*2};throw new Error(`circuitJson bounds calculation not implemented for shape "${n.shape}"`)}_setPositionFromLayout(t){var a;const{db:n}=this.root;n.pcb_smtpad.update(this.pcb_smtpad_id,{x:t.x,y:t.y});const i=n.pcb_solder_paste.list().find(o=>o.pcb_smtpad_id===this.pcb_smtpad_id);n.pcb_solder_paste.update(i==null?void 0:i.pcb_solder_paste_id,{x:t.x,y:t.y}),(a=this.matchedPort)==null||a._setPositionFromLayout(t)}},Dge=class extends N_{constructor(){super(...arguments);Je(this,"pcb_silkscreen_path_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenPath",zodProps:Dye}}doInitialPcbPrimitiveRender(){var c,u,f;if((c=this.root)!=null&&c.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(n.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenPath. Must be "top" or "bottom".`);const o=this._computePcbGlobalTransformBeforeLayout(),s=this.getSubcircuit(),l=t.pcb_silkscreen_path.insert({pcb_component_id:(u=this.parent)==null?void 0:u.pcb_component_id,layer:a,route:n.route.map(d=>{const m=kr(o,{x:d.x,y:d.y});return{...d,x:m.x,y:m.y}}),stroke_width:n.strokeWidth??.1,subcircuit_id:(s==null?void 0:s.subcircuit_id)??void 0,pcb_group_id:((f=this.getGroup())==null?void 0:f.pcb_group_id)??void 0});this.pcb_silkscreen_path_id=l.pcb_silkscreen_path_id}getPcbSize(){const{_parsedProps:t}=this;if(!t.route||t.route.length===0)return{width:0,height:0};let n=1/0,i=-1/0,a=1/0,o=-1/0;for(const s of t.route)n=Math.min(n,s.x),i=Math.max(i,s.x),a=Math.min(a,s.y),o=Math.max(o,s.y);return{width:i-n,height:o-a}}},Qft=R.object({route:R.array(zN),source_trace_id:R.string().optional()}),Lge=class extends N_{constructor(){super(...arguments);Je(this,"pcb_trace_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbTrace",zodProps:Qft}}doInitialPcbPrimitiveRender(){var u,f;if((u=this.root)!=null&&u.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getPrimitiveContainer(),a=this.getSubcircuit(),{maybeFlipLayer:o}=this._getPcbPrimitiveFlippedHelpers(),s=this._computePcbGlobalTransformBeforeLayout(),l=n.route.map(d=>{const{x:m,y,...w}=d,S=kr(s,{x:m,y});return d.route_type==="wire"&&d.layer?{...S,...w,layer:o(d.layer)}:{...S,...w}}),c=t.pcb_trace.insert({pcb_component_id:i.pcb_component_id,source_trace_id:n.source_trace_id,route:l,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((f=this.getGroup())==null?void 0:f.pcb_group_id)??void 0});this.pcb_trace_id=c.pcb_trace_id}getPcbSize(){const{_parsedProps:t}=this;if(!t.route||t.route.length===0)return{width:0,height:0};let n=1/0,i=-1/0,a=1/0,o=-1/0;for(const s of t.route)n=Math.min(n,s.x),i=Math.max(i,s.x),a=Math.min(a,s.y),o=Math.max(o,s.y),s.route_type==="wire"&&(n=Math.min(n,s.x-s.width/2),i=Math.max(i,s.x+s.width/2),a=Math.min(a,s.y-s.width/2),o=Math.max(o,s.y+s.width/2));return n===1/0||i===-1/0||a===1/0||o===-1/0?{width:0,height:0}:{width:i-n,height:o-a}}},Oge=class extends N_{constructor(){super(...arguments);Je(this,"pcb_plated_hole_id",null);Je(this,"matchedPort",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PlatedHole",zodProps:nye}}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,n=t.pcb_plated_hole.get(this.pcb_plated_hole_id),i=this.getPcbSize();return{center:{x:n.x,y:n.y},bounds:{left:n.x-i.width/2,top:n.y+i.height/2,right:n.x+i.width/2,bottom:n.y-i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(t){var i;const{db:n}=this.root;n.pcb_plated_hole.update(this.pcb_plated_hole_id,{x:t.x,y:t.y}),(i=this.matchedPort)==null||i._setPositionFromLayout(t)}doInitialPortMatching(){var n;const t=(n=this.getPrimitiveContainer())==null?void 0:n.selectAll("port");if(this.props.portHints){for(const i of t)if(i.isMatchingAnyOf(this.props.portHints)){this.matchedPort=i,i.registerMatch(this);return}}}doInitialPcbPrimitiveRender(){var s,l,c,u,f,d,m,y,w,S,b;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalPcbPositionBeforeLayout(),a=((l=this.parent)==null?void 0:l.pcb_component_id)??((c=this.getPrimitiveContainer())==null?void 0:c.pcb_component_id),o=this.getSubcircuit();if(n.shape==="circle"){const E=t.pcb_plated_hole.insert({pcb_component_id:a,pcb_port_id:(u=this.matchedPort)==null?void 0:u.pcb_port_id,outer_diameter:n.outerDiameter,hole_diameter:n.holeDiameter,shape:"circle",port_hints:this.getNameAndAliases(),x:i.x,y:i.y,layers:["top","bottom"],subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((f=this.getGroup())==null?void 0:f.pcb_group_id)??void 0});this.pcb_plated_hole_id=E.pcb_plated_hole_id,t.pcb_solder_paste.insert({layer:"top",shape:"circle",radius:n.outerDiameter/2,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((d=this.getGroup())==null?void 0:d.pcb_group_id)??void 0}),t.pcb_solder_paste.insert({layer:"bottom",shape:"circle",radius:n.outerDiameter/2,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((m=this.getGroup())==null?void 0:m.pcb_group_id)??void 0})}else if(n.shape==="pill"||n.shape==="oval"){const E=t.pcb_plated_hole.insert({pcb_component_id:a,pcb_port_id:(y=this.matchedPort)==null?void 0:y.pcb_port_id,outer_width:n.outerWidth,outer_height:n.outerHeight,hole_width:n.holeWidth,hole_height:n.holeHeight,shape:n.shape,port_hints:this.getNameAndAliases(),x:i.x,y:i.y,layers:["top","bottom"],subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((w=this.getGroup())==null?void 0:w.pcb_group_id)??void 0});this.pcb_plated_hole_id=E.pcb_plated_hole_id,t.pcb_solder_paste.insert({layer:"top",shape:n.shape,width:n.outerWidth,height:n.outerHeight,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((S=this.getGroup())==null?void 0:S.pcb_group_id)??void 0}),t.pcb_solder_paste.insert({layer:"bottom",shape:n.shape,width:n.outerWidth,height:n.outerHeight,x:i.x,y:i.y,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((b=this.getGroup())==null?void 0:b.pcb_group_id)??void 0})}}doInitialPcbPortAttachment(){var n,i;if((n=this.root)!=null&&n.pcbDisabled)return;const{db:t}=this.root;t.pcb_plated_hole.update(this.pcb_plated_hole_id,{pcb_port_id:(i=this.matchedPort)==null?void 0:i.pcb_port_id})}},VG=class extends N_{constructor(){super(...arguments);Je(this,"pcb_keepout_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Keepout",zodProps:Rye}}doInitialPcbPrimitiveRender(){var c,u,f;if((c=this.root)!=null&&c.pcbDisabled)return;const t=this.getSubcircuit(),{db:n}=this.root,{_parsedProps:i}=this,a=this._getGlobalPcbPositionBeforeLayout(),o=kw(this._computePcbGlobalTransformBeforeLayout()),s=Math.abs(o.rotation.angle*(180/Math.PI)-90)%180<.01;let l=null;i.shape==="circle"?l=n.pcb_keepout.insert({layers:["top"],shape:"circle",radius:i.radius,center:{x:a.x,y:a.y},subcircuit_id:(t==null?void 0:t.subcircuit_id)??void 0,pcb_group_id:((u=t==null?void 0:t.getGroup())==null?void 0:u.pcb_group_id)??void 0}):i.shape==="rect"&&(l=n.pcb_keepout.insert({layers:["top"],shape:"rect",...s?{width:i.height,height:i.width}:{width:i.width,height:i.height},center:{x:a.x,y:a.y},subcircuit_id:(t==null?void 0:t.subcircuit_id)??void 0,pcb_group_id:((f=t==null?void 0:t.getGroup())==null?void 0:f.pcb_group_id)??void 0})),l&&(this.pcb_keepout_id=l.pcb_keepout_id)}},zge=class extends N_{constructor(){super(...arguments);Je(this,"pcb_hole_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Hole",zodProps:fye}}getPcbSize(){const{_parsedProps:t}=this;return{width:t.diameter,height:t.diameter}}doInitialPcbPrimitiveRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getSubcircuit(),a=this._getGlobalPcbPositionBeforeLayout(),o=t.pcb_hole.insert({hole_shape:"circle",hole_diameter:n.diameter,x:a.x,y:a.y,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((l=i==null?void 0:i.getGroup())==null?void 0:l.pcb_group_id)??void 0});this.pcb_hole_id=o.pcb_hole_id}_getPcbCircuitJsonBounds(){const{db:t}=this.root,n=t.pcb_hole.get(this.pcb_hole_id),i=this.getPcbSize();return{center:{x:n.x,y:n.y},bounds:{left:n.x-i.width/2,top:n.y-i.height/2,right:n.x+i.width/2,bottom:n.y+i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(t){const{db:n}=this.root;n.pcb_hole.update(this.pcb_hole_id,{x:t.x,y:t.y})}},GG=class extends N_{constructor(){super(...arguments);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenText",zodProps:Nye}}doInitialPcbPrimitiveRender(){var l,c;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getPrimitiveContainer(),a=this._getGlobalPcbPositionBeforeLayout(),{maybeFlipLayer:o}=this._getPcbPrimitiveFlippedHelpers(),s=this.getSubcircuit();t.pcb_silkscreen_text.insert({anchor_alignment:n.anchorAlignment,anchor_position:{x:a.x,y:a.y},font:n.font??"tscircuit2024",font_size:n.fontSize??1,layer:o(n.layer??"top"),text:n.text??"",ccw_rotation:n.pcbRotation,pcb_component_id:i.pcb_component_id,subcircuit_id:(s==null?void 0:s.subcircuit_id)??void 0,pcb_group_id:((c=this.getGroup())==null?void 0:c.pcb_group_id)??void 0})}getPcbSize(){const{_parsedProps:t}=this,n=t.fontSize??1,a=(t.text??"").length*n,o=n;return{width:a*n,height:o*n}}},Kft=({elm:r,pinLabels:e,readableRotation:t})=>{var a;const n=r.text.replace(/[{}]/g,"").toLowerCase();let i=n;if(Array.isArray(e)){const o=parseInt(n.replace(/[^\d]/g,""),10)-1;i=e[o]??n}else typeof e=="object"&&(i=((a=e[n])==null?void 0:a[0])??n);return new GG({anchorAlignment:"center",text:i??n,fontSize:r.font_size+.2,pcbX:isNaN(r.anchor_position.x)?0:r.anchor_position.x,pcbY:r.anchor_position.y,pcbRotation:t??0})},Jft=({componentName:r,componentRotation:e,footprint:t,pinLabels:n},i)=>{const a=[];for(const o of i)if(o.type==="pcb_smtpad"&&o.shape==="rect")a.push(new HG({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 HG({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 Dge({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 Oge({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 VG({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 VG({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 zge({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")&&n?a.push(Kft({elm:o,pinLabels:n,readableRotation:s})):o.text==="{REF}"&&a.push(new GG({anchorAlignment:"center",text:r,fontSize:o.font_size+.2,pcbX:isNaN(o.anchor_position.x)?0:o.anchor_position.x,pcbY:o.anchor_position.y,pcbRotation:s??0}))}else o.type==="pcb_trace"&&a.push(new Lge({route:o.route}));return a};function Uge(r){let e=1/0,t=1/0,n=-1/0,i=-1/0;for(const s of r)if(s.isPcbPrimitive&&!s.componentName.startsWith("Silkscreen")){const{x:l,y:c}=s._getGlobalPcbPositionBeforeLayout(),{width:u,height:f}=s.getPcbSize();e=Math.min(e,l-u/2),t=Math.min(t,c-f/2),n=Math.max(n,l+u/2),i=Math.max(i,c+f/2)}else if(s.componentName==="Footprint"){const l=Uge(s.children);e=Math.min(e,l.minX),t=Math.min(t,l.minY),n=Math.max(n,l.maxX),i=Math.max(i,l.maxY)}let a=n-e,o=i-t;return a<0&&(a=0),o<0&&(o=0),{minX:e,minY:t,maxX:n,maxY:i,width:a,height:o}}function edt(r,e){const t=e.x-r.x,n=e.y-r.y;return Math.abs(t)>Math.abs(n)?t>=0?"right":"left":n>=0?"up":"down"}var tdt=r=>{if(r.length<=1)return!0;const e=r.map(a=>{const o=a._getPcbCircuitJsonBounds();return{left:o.bounds.left,right:o.bounds.right,top:o.bounds.top,bottom:o.bounds.bottom}}),t=Array(e.length).fill(!1).map(()=>Array(e.length).fill(!1));for(let a=0;a<e.length;a++)for(let o=a+1;o<e.length;o++){const s=e[a],l=e[o];t[a][o]=t[o][a]=!(s.right<l.left||s.left>l.right||s.bottom>l.top||s.top<l.bottom)}const n=new Set,i=a=>{n.add(a);for(let o=0;o<e.length;o++)t[a][o]&&!n.has(o)&&i(o)};return i(0),n.size===e.length},ndt=r=>{if(r.length===0)throw new Error("Cannot get center of empty PCB primitives array");const e=r.map(i=>i._getPcbCircuitJsonBounds().center).filter(Boolean),t=e.reduce((i,a)=>i+a.x,0),n=e.reduce((i,a)=>i+a.y,0);return{x:t/e.length,y:n/e.length}},rdt=R.object({name:R.string().optional(),pinNumber:R.number().optional(),aliases:R.array(R.string()).optional()}),US=class extends N_{constructor(t,n={}){if(!t.name&&t.pinNumber!==void 0&&(t.name=`pin${t.pinNumber}`),!t.name)throw new Error("Port must have a name or a pinNumber");super(t);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);n.originDescription&&(this.originDescription=n.originDescription),this.matchedComponents=[]}get config(){return{componentName:"Port",zodProps:rdt}}_getGlobalPcbPositionBeforeLayout(){const t=this.matchedComponents.find(i=>i.isPcbPrimitive),n=this.parent;if(n&&!n.props.footprint)throw new Error(`${n.componentName} "${n.props.name}" does not have a footprint. Add a footprint prop, e.g. <${n.componentName.toLowerCase()} footprint="..." />`);if(!t)throw new Error(`Port ${this} has no matching PCB primitives. This often means the footprint's pads lack matching port hints.`);return(t==null?void 0:t._getGlobalPcbPositionBeforeLayout())??{x:0,y:0}}_getPcbCircuitJsonBounds(){if(!this.pcb_port_id)return super._getPcbCircuitJsonBounds();const{db:t}=this.root,n=t.pcb_port.get(this.pcb_port_id);return{center:{x:n.x,y:n.y},bounds:{left:0,top:0,right:0,bottom:0},width:0,height:0}}_getGlobalPcbPositionAfterLayout(){return this._getPcbCircuitJsonBounds().center}_getPortsInternallyConnectedToThisPort(){const t=this.parent;if(!t||!t._getInternallyConnectedPins)return[];const n=t._getInternallyConnectedPins();for(const i of n)if(i.some(a=>a===this))return i;return[]}_hasSchematicPort(){var i,a;if((i=this.parent)==null?void 0:i.getSchematicSymbol())return!!(this.schematicSymbolPortDef||this._getPortsInternallyConnectedToThisPort().some(s=>s.schematicSymbolPortDef));const n=(a=this==null?void 0:this.parent)==null?void 0:a._getSchematicBoxDimensions();return!!(n&&this.props.pinNumber!==void 0&&n.getPortPositionByPinNumber(this.props.pinNumber))}_getGlobalSchematicPositionBeforeLayout(){var i,a,o;const t=(i=this.parent)==null?void 0:i.getSchematicSymbol();if(t){let s=this.schematicSymbolPortDef;if(!s&&(s=((a=this._getPortsInternallyConnectedToThisPort().find(c=>c.schematicSymbolPortDef))==null?void 0:a.schematicSymbolPortDef)??null,!s))throw new Error(`Couldn't find schematicSymbolPortDef for port ${this.getString()}, searched internally connected ports and none had a schematicSymbolPortDef. Why are we trying to get the schematic position of this port?`);const l=wc(this.parent.computeSchematicGlobalTransform(),zf(-t.center.x,-t.center.y));return kr(l,s)}const n=(o=this==null?void 0:this.parent)==null?void 0:o._getSchematicBoxDimensions();if(n&&this.props.pinNumber!==void 0){const s=n.getPortPositionByPinNumber(this.props.pinNumber);if(!s)throw new Error(`Couldn't find position for schematic_port for port ${this.getString()} inside of the schematic box`);return kr(this.parent.computeSchematicGlobalTransform(),s)}throw new Error(`Couldn't find position for schematic_port for port ${this.getString()}`)}_getGlobalSchematicPositionAfterLayout(){const{db:t}=this.root;if(!this.schematic_port_id)throw new Error(`Can't get schematic port position after layout for "${this.getString()}", no schematic_port_id`);const n=t.schematic_port.get(this.schematic_port_id);if(!n)throw new Error(`Schematic port not found when trying to get post-layout position: ${this.schematic_port_id}`);return n.center}registerMatch(t){this.matchedComponents.push(t)}getNameAndAliases(){const{_parsedProps:t}=this;return Array.from(new Set([...t.aliases??[],...t.name?[t.name]:[],...typeof t.pinNumber=="number"?[`pin${t.pinNumber}`,t.pinNumber.toString()]:[],...this.externallyAddedAliases??[]]))}isMatchingPort(t){return this.isMatchingAnyOf(t.getNameAndAliases())}getPortSelector(){var t;return`.${(t=this.parent)==null?void 0:t.props.name} > port.${this.props.name}`}getAvailablePcbLayers(){return Array.from(new Set(this.matchedComponents.flatMap(t=>t.getAvailablePcbLayers())))}_getDirectlyConnectedTraces(){return this.getSubcircuit().selectAll("trace").filter(i=>i._isExplicitlyConnectedToPort(this))}doInitialSourceRender(){var o,s;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getNameAndAliases(),a=t.source_port.insert({name:n.name,pin_number:n.pinNumber,port_hints:i,source_component_id:(o=this.parent)==null?void 0:o.source_component_id,subcircuit_id:(s=this.getSubcircuit())==null?void 0:s.subcircuit_id});this.source_port_id=a.source_port_id}doInitialSourceParentAttachment(){var n,i,a,o,s;const{db:t}=this.root;if(!((n=this.parent)!=null&&n.source_component_id))throw new Error(`${this.getString()} has no parent source component (parent: ${(i=this.parent)==null?void 0:i.getString()})`);t.source_port.update(this.source_port_id,{source_component_id:(a=this.parent)==null?void 0:a.source_component_id,subcircuit_id:(o=this.getSubcircuit())==null?void 0:o.subcircuit_id}),this.source_component_id=(s=this.parent)==null?void 0:s.source_component_id}doInitialPcbPortRender(){var o,s,l,c,u;if((o=this.root)!=null&&o.pcbDisabled)return;const{db:t}=this.root,{matchedComponents:n}=this;if(!((s=this.parent)!=null&&s.pcb_component_id))throw new Error(`${this.getString()} has no parent pcb component, cannot render pcb_port (parent: ${(l=this.parent)==null?void 0:l.getString()})`);const i=n.filter(f=>f.isPcbPrimitive);if(i.length===0)return;let a=null;if(i.length===1&&(a=i[0]._getPcbCircuitJsonBounds().center),i.length>1){if(!tdt(i))throw new Error(`${this.getString()} has multiple non-overlapping pcb matches, unclear how to place pcb_port: ${i.map(f=>f.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=ndt(i)}if(a){const f=this.getSubcircuit(),d=t.pcb_port.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layers:this.getAvailablePcbLayers(),subcircuit_id:(f==null?void 0:f.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=d.pcb_port_id}else{const f=i[0];throw new Error(`${f.getString()} does not have a center or _getGlobalPcbPositionBeforeLayout method (needed for pcb_port placement)`)}}doInitialSchematicPortRender(){var d;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getPrimitiveContainer();if(!i||!this._hasSchematicPort())return;const a=i._getGlobalSchematicPositionBeforeLayout(),o=this._getGlobalSchematicPositionBeforeLayout();let s=null;const l=i._getSchematicBoxDimensions();l&&n.pinNumber!==void 0&&(s=l.getPortPositionByPinNumber(n.pinNumber)),this.getSubcircuit().props._schDebugObjectsEnabled&&t.schematic_debug_object.insert({shape:"rect",center:o,size:{width:.1,height:.1},label:"obstacle"}),s!=null&&s.side?this.facingDirection={left:"left",right:"right",top:"up",bottom:"down"}[s.side]:this.facingDirection=edt(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 f=t.schematic_port.insert({schematic_component_id:(d=this.parent)==null?void 0:d.schematic_component_id,center:o,source_port_id:this.source_port_id,facing_direction:this.facingDirection,distance_from_component_edge:.4,side_of_component:s==null?void 0:s.side,pin_number:n.pinNumber,true_ccw_index:s==null?void 0:s.trueIndex,display_pin_label:u});this.schematic_port_id=f.schematic_port_id}_setPositionFromLayout(t){const{db:n}=this.root;this.pcb_port_id&&n.pcb_port.update(this.pcb_port_id,{x:t.x,y:t.y})}_hasMatchedPcbPrimitive(){return this.matchedComponents.some(t=>t.isPcbPrimitive)}},kge=r=>{const e=r.find(t=>/^(pin)?\d+$/.test(t));return e?Number.parseInt(e.replace(/^pin/,"")):null};function mC(r,e){var a;const t=kge(r);if(!t)return null;const i=[...r.filter(o=>o.toString()!==t.toString()&&o!==`pin${t}`),...((a=e==null?void 0:e.additionalAliases)==null?void 0:a[`pin${t}`])??[]];return new US({pinNumber:t,aliases:i})}var idt=r=>{for(const e of["leftSide","rightSide","topSide","bottomSide"])if(e in r&&typeof r[e]=="number")throw new Error(`A number was specified for "${e}", you probably meant to use "size" not "side"`);return"leftSide"in r||"rightSide"in r||"topSide"in r||"bottomSide"in r},adt=r=>{var a,o,s,l;if(idt(r))return{leftSize:((a=r.leftSide)==null?void 0:a.pins.length)??0,rightSize:((o=r.rightSide)==null?void 0:o.pins.length)??0,topSize:((s=r.topSide)==null?void 0:s.pins.length)??0,bottomSize:((l=r.bottomSide)==null?void 0:l.pins.length)??0};const{leftSize:e=0,rightSize:t=0,topSize:n=0,bottomSize:i=0}=r;return{leftSize:e,rightSize:t,topSize:n,bottomSize:i}};function Ige(r){return r.leftSide!==void 0}var odt=r=>{var S,b,E,P,U,V,Y,W;const e=r.portDistanceFromEdge??.4;let t=r.schPortArrangement?adt(r.schPortArrangement):null;const n={left:0,right:0,top:0,bottom:0};let i=r.pinCount??null;if(i===null)if(t)i=t.leftSize+t.rightSize+t.topSize;else throw new Error("Could not determine pin count for the schematic box");if(i&&!t){const $=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:K,truePinIndex:X})=>{var he,ge,Te,xe;if(!r.schPortArrangement||!Ige(r.schPortArrangement))return X+1;const ce={left:"top-to-bottom",bottom:"left-to-right",right:"bottom-to-top",top:"right-to-left"}[$],pe=((ge=(he=r.schPortArrangement)==null?void 0:he[`${$}Side`])==null?void 0:ge.direction)??ce,ue=(xe=(Te=r.schPortArrangement)==null?void 0:Te[`${$}Side`])==null?void 0:xe.pins;let Se=K;return pe!==ce&&(Se=ue.length-K-1),hC(ue[Se],r.pinLabels)},o=[];let s=0,l=0;for(let $=0;$<t.leftSize;$++){const K=a({side:"left",sideIndex:$,truePinIndex:l}),X=((S=r.numericSchPinStyle)==null?void 0:S[`pin${K}`])??((b=r.numericSchPinStyle)==null?void 0:b[K]);X!=null&&X.topMargin&&(s+=X.topMargin),o.push({trueIndex:l,pinNumber:K,side:"left",distanceFromOrthogonalEdge:s}),X!=null&&X.bottomMargin&&(s+=X.bottomMargin),$===t.leftSize-1?n.left=s:s+=r.schPinSpacing,l++}s=0;for(let $=0;$<t.bottomSize;$++){const K=a({side:"bottom",sideIndex:$,truePinIndex:l}),X=((E=r.numericSchPinStyle)==null?void 0:E[`pin${K}`])??((P=r.numericSchPinStyle)==null?void 0:P[K]);X!=null&&X.leftMargin&&(s+=X.leftMargin),o.push({trueIndex:l,pinNumber:K,side:"bottom",distanceFromOrthogonalEdge:s}),X!=null&&X.rightMargin&&(s+=X.rightMargin),$===t.bottomSize-1?n.bottom=s:s+=r.schPinSpacing,l++}s=0;for(let $=0;$<t.rightSize;$++){const K=a({side:"right",sideIndex:$,truePinIndex:l}),X=((U=r.numericSchPinStyle)==null?void 0:U[`pin${K}`])??((V=r.numericSchPinStyle)==null?void 0:V[K]);X!=null&&X.bottomMargin&&(s+=X.bottomMargin),o.push({trueIndex:l,pinNumber:K,side:"right",distanceFromOrthogonalEdge:s}),X!=null&&X.topMargin&&(s+=X.topMargin),$===t.rightSize-1?n.right=s:s+=r.schPinSpacing,l++}s=0;for(let $=0;$<t.topSize;$++){const K=a({side:"top",sideIndex:$,truePinIndex:l}),X=((Y=r.numericSchPinStyle)==null?void 0:Y[`pin${K}`])??((W=r.numericSchPinStyle)==null?void 0:W[K]);X!=null&&X.rightMargin&&(s+=X.rightMargin),o.push({trueIndex:l,pinNumber:K,side:"top",distanceFromOrthogonalEdge:s}),X!=null&&X.leftMargin&&(s+=X.leftMargin),$===t.topSize-1?n.top=s:s+=r.schPinSpacing,l++}let c=r.schWidth;c||(c=Math.max(n.top+r.schPinSpacing*2,n.bottom+r.schPinSpacing*2));const u=r.pinLabels?Math.max(...Object.values(r.pinLabels).map($=>$.length*.1)):0,f=u>0?1.1:0;c=Math.max(c,u+f);let d=r.schHeight;d||(d=Math.max(n.left+r.schPinSpacing*2,n.right+r.schPinSpacing*2));const m={left:{x:-c/2-e,y:n.left/2},bottom:{x:-n.bottom/2,y:-d/2-e},right:{x:c/2+e,y:-n.right/2},top:{x:n.top/2,y:d/2+e}},y={left:{x:0,y:-1},right:{x:0,y:1},top:{x:-1,y:0},bottom:{x:1,y:0}},w=o.map($=>{const{distanceFromOrthogonalEdge:K,side:X}=$,ce=m[X],pe=y[X];return{x:ce.x+K*pe.x,y:ce.y+K*pe.y,...$}});return{getPortPositionByPinNumber($){const K=w.find(X=>X.pinNumber.toString()===$.toString());return K||null},getSize(){return{width:c,height:d}},getSizeIncludingPins(){return{width:c+(t.leftSize||t.rightSize?.4:0),height:d+(t.topSize||t.bottomSize?.4:0)}},pinCount:i}},sdt=Jm("tscircuit:core:footprint"),ldt=class extends N_{get config(){return{componentName:"Footprint",zodProps:hye}}doInitialPcbFootprintLayout(){var d,m,y,w,S;if((d=this.root)!=null&&d.pcbDisabled)return;const e=this.children.filter(b=>b.componentName==="Constraint");if(e.length===0)return;const{isFlipped:t}=this._getPcbPrimitiveFlippedHelpers(),n=b=>t&&"left"in b&&"right"in b?{...b,left:b.right,right:b.left}:b,i=e.flatMap(b=>b._getAllReferencedComponents().componentsWithSelectors).map(({component:b,selector:E,componentSelector:P,edge:U})=>({component:b,selector:E,componentSelector:P,edge:U,bounds:b._getPcbCircuitJsonBounds()}));if(i.some(b=>b.edge))throw new Error("edge constraints not implemented yet for footprint layout, contributions welcome!");function a(b){return i.find(({selector:E})=>E===b)}const o=new yG,s={};function l(b){return b in s||(s[b]=new sC(b),o.addEditVariable(s[b],ry.weak)),s[b]}for(const{selector:b,bounds:E}of i){const P=l(`${b}_x`),U=l(`${b}_y`);o.suggestValue(P,E.center.x),o.suggestValue(U,E.center.y)}for(const b of e){const E=b._parsedProps;if("xDist"in E){const{xDist:P,left:U,right:V,edgeToEdge:Y,centerToCenter:W}=n(E),$=l(`${U}_x`),K=l(`${V}_x`),X=(m=a(U))==null?void 0:m.bounds,ce=(y=a(V))==null?void 0:y.bounds;if(W){const pe=new R1(K,[-1,$]);o.addConstraint(new Cx(pe,p_.Eq,E.xDist,ry.required))}else if(Y){const pe=new R1(K,-ce.width/2,[-1,$],-X.width/2);o.addConstraint(new Cx(pe,p_.Eq,E.xDist,ry.required))}}else if("yDist"in E){const{yDist:P,top:U,bottom:V,edgeToEdge:Y,centerToCenter:W}=E,$=l(`${U}_y`),K=l(`${V}_y`),X=(w=a(U))==null?void 0:w.bounds,ce=(S=a(V))==null?void 0:S.bounds;if(W){const pe=new R1($,[-1,K]);o.addConstraint(new Cx(pe,p_.Eq,E.yDist,ry.required))}else if(Y){const pe=new R1($,X.height/2,[-1,K],-ce.height/2);o.addConstraint(new Cx(pe,p_.Eq,E.yDist,ry.required))}}else if("sameY"in E){const{for:P}=E;if(P.length<2)continue;const U=P.map(Y=>l(`${Y}_y`)),V=new R1(...U.slice(1));o.addConstraint(new Cx(V,p_.Eq,U[0],ry.required))}else if("sameX"in E){const{for:P}=E;if(P.length<2)continue;const U=P.map(Y=>l(`${Y}_x`)),V=new R1(...U.slice(1));o.addConstraint(new Cx(V,p_.Eq,U[0],ry.required))}}o.updateVariables(),sdt.enabled&&(console.log("Solution to layout constraints:"),console.table(Object.entries(s).map(([b,E])=>({var:b,val:E.value()}))));const c={left:1/0,right:-1/0,top:-1/0,bottom:1/0};for(const{selector:b,bounds:{width:E,height:P}}of i){const U=l(`${b}_x`),V=l(`${b}_y`),Y=U.value()-E/2,W=U.value()+E/2,$=V.value()+P/2,K=V.value()-P/2;c.left=Math.min(c.left,Y),c.right=Math.max(c.right,W),c.top=Math.max(c.top,$),c.bottom=Math.min(c.bottom,K)}const u={x:-(c.right+c.left)/2,y:-(c.top+c.bottom)/2},f=this.getPrimitiveContainer()._getGlobalPcbPositionBeforeLayout();u.x+=f.x,u.y+=f.y;for(const{component:b,selector:E}of i){const P=l(`${E}_x`),U=l(`${E}_y`);b._setPositionFromLayout({x:P.value()+u.x,y:U.value()+u.y})}}},cdt=(r,e)=>{if(!r)return;const t={};for(const[n,i]of Object.entries(r)){const a=hC(n,e),o={leftMargin:i.marginLeft??i.leftMargin,rightMargin:i.marginRight??i.rightMargin,topMargin:i.marginTop??i.topMargin,bottomMargin:i.marginBottom??i.bottomMargin};t[`pin${a}`]={...t[`pin${a}`],...o}}return t},Fge=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[n,i]=t.pointsToConnect,a={type:"pcb_trace",pcb_trace_id:"",connection_name:t.name,route:[{route_type:"wire",x:n.x,y:n.y,layer:"top",width:.1},{route_type:"wire",x:i.x,y:i.y,layer:"top",width:.1}]};e.push(a)}return e}},udt=r=>{const e=Math.min(...r.map(a=>a.center.x)),t=Math.max(...r.map(a=>a.center.x)),n=Math.min(...r.map(a=>a.center.y)),i=Math.max(...r.map(a=>a.center.y));return{minX:e,maxX:t,minY:n,maxY:i}},Bge=["top","bottom","inner1","inner2"],TL=(r,e=[])=>{var s;const t=[];if(e.length===0){const l=r[0].layers;for(const c of l)t.push(...TL(r.slice(1),[c]));return t}if(r.length===0)return[];const n=r[0],i=n.via||n.optional_via,a=e[e.length-1];if(r.length===1){const l=n;return l.layers&&i?l.layers.map(c=>({layer_path:[...e,c]})):(s=l.layers)!=null&&s.includes(a)?[{layer_path:[...e,a]}]:[]}if(!i)return n.layers&&!n.layers.includes(a)?[]:TL(r.slice(1),e.concat([a]));const o=(n.optional_via?Bge:Bge.filter(l=>l!==a)).filter(l=>{var c;return!n.layers||((c=n.layers)==null?void 0:c.includes(l))});for(const l of o)t.push(...TL(r.slice(1),e.concat(l)));return t};function jge(r){const e={x:r.to.x-r.from.x,y:r.to.y-r.from.y},t=Math.abs(e.x),n=Math.abs(e.y);return t>n?e.x>0?"right":"left":e.y>0?"down":"up"}function gT(r,e){return Math.hypot(r.x-e.x,r.y-e.y)}var fdt=r=>{if(r.length===1)return r[0];if(r.some(l=>l.length===0))throw new Error("Cannot merge routes with zero length");const e=[],t=r[0][0],n=r[0][r[0].length-1],i=r[1][0],a=r[1][r[1].length-1],o=Math.min(gT(t,i),gT(t,a)),s=Math.min(gT(n,i),gT(n,a));o<s?e.push(...r[0].reverse()):e.push(...r[0]);for(let l=1;l<r.length;l++){const c=e[e.length-1],u=r[l],f=u[0],d=u[u.length-1],m=gT(c,f),y=gT(c,d);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},ddt=(r,e)=>{const t="_getGlobalPcbPositionBeforeLayout"in r?r._getGlobalPcbPositionBeforeLayout():r,n="_getGlobalPcbPositionBeforeLayout"in e?e._getGlobalPcbPositionBeforeLayout():e;return Math.sqrt((t.x-n.x)**2+(t.y-n.y)**2)};function pdt(r,e){if(e.length===0)throw new Error("No candidates given to getClosest method");let t=e[0],n=1/0;for(const i of e){const a=ddt(r,i);a<n&&(t=i,n=a)}return t}var hdt=(r,e)=>{let t=0;t+=r.length??0,t+=e.filter(n=>n.is_crossing).length;for(let n=1;n<e.length;n++){const i=e[n-1],a=e[n],o=Math.abs(i.from.x-i.to.x)<.01,s=Math.abs(a.from.x-a.to.x)<.01;o!==s&&t++}return t},qG=r=>({up:"bottom",down:"top",left:"right",right:"left"})[r]??null,$G=({firstEdge:r,firstEdgePort:e,firstDominantDirection:t,lastEdge:n,lastEdgePort:i,lastDominantDirection:a})=>{if(r&&e)return $G({lastEdge:{from:r.to,to:r.from},lastEdgePort:e,lastDominantDirection:t}).reverse().map(s=>({from:s.to,to:s.from}));let o=[];if(n&&i){const s={x:n.to.x,y:n.to.y};a==="left"||a==="right"?(s.x=i.position.x,o.push({from:n.to,to:{...s}}),o.push({from:s,to:{...i.position}})):(s.y=i.position.y,o.push({from:n.to,to:{...s}}),o.push({from:s,to:{...i.position}}))}return o=o.filter(s=>R3(s.from,s.to)>.01),o};function mdt(r){try{return[r(),null]}catch(e){return[null,e]}}function vdt(r){let e=0;for(let t=0;t<r.length;t++){const n=r[t];if(n.route_type==="wire"){const i=r[t+1];if(i){const a=i.x-n.x,o=i.y-n.y;e+=Math.sqrt(a*a+o*o)}}else n.route_type==="via"&&(e+=1.6)}return e}var ydt=r=>{var s,l;const e={left:{x:-.5,y:0},up:{x:.5,y:.5},right:{x:.5,y:0},down:{x:0,y:-.5}}[r.facingDirection],t=(s=r.parent)!=null&&s.config.shouldRenderAsSchematicBox?3:1,n=(l=r.parent)!=null&&l.config.shouldRenderAsSchematicBox&&(r.facingDirection==="left"||r.facingDirection==="right")?3:1,i=e.x,a=e.y,o=r.facingDirection==="up"?.5:0;return{schBoxVertOffset:t,schBoxHorzOffset:n,horzPortDirection:i,vertPortDirectionOffset:a,handleUp:o}},ML=({port:r,anchorPos:e,schDisplayLabel:t,source_trace_id:n},{db:i})=>{const a=ydt(r);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:r.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:n})},YG=({db:r,source_trace_id:e,sameNetOnly:t,differentNetOnly:n})=>{!t&&!n&&(n=!0);const i=r.source_trace.get(e),a=[];for(const o of r.schematic_trace.list()){if(o.source_trace_id===e)continue;const s=r.source_trace.get(o.source_trace_id),l=(s==null?void 0:s.subcircuit_connectivity_map_key)===i.subcircuit_connectivity_map_key;n&&l||t&&!l||a.push(o)}return a},gdt=({edges:r,otherEdges:e})=>{const t=[...r];for(let n=0;n<t.length;n++){if(n>2e3)throw new Error("Over 2000 iterations spent inside createSchematicTraceCrossingSegments, you have triggered an infinite loop, please report this!");const i=t[n],a=Math.abs(i.from.x-i.to.x)<.01?"vertical":i.from.y===i.to.y?"horizontal":"not-orthogonal";if(a==="not-orthogonal")continue;const o=[];for(const w of e){const S=w.from.x===w.to.x?"vertical":w.from.y===w.to.y?"horizontal":"not-orthogonal";if(S==="not-orthogonal"||a===S)continue;if(cL([i.from,i.to],[w.from,w.to],{lineThickness:.01})){const E=a==="vertical"?i.from.x:w.from.x,P=a==="vertical"?w.from.y:i.from.y,U={x:E,y:P};o.push({otherEdge:w,crossingPoint:U,distanceFromEdgeFrom:R3(i.from,U)})}}if(o.length===0)continue;let s=o[0];for(const w of o)w.distanceFromEdgeFrom<s.distanceFromEdgeFrom&&(s=w);const l=s.crossingPoint,c=.075;if(l.x===i.from.x&&l.y===i.from.y)continue;const u=Fye(i.from,l),f={x:l.x-u.x*c/2,y:l.y-u.y*c/2},d={x:l.x+u.x*c/2,y:l.y+u.y*c/2},m=R3(d,i.to)<c,y=[{from:i.from,to:f},{from:f,to:d,is_crossing:!0},{from:d,to:i.to}];t.splice(n,1,...y),n+=y.length-2,m&&n++}return t},_dt=(r,e)=>{if(r.from.x===r.to.x&&e.from.x===e.to.x)return null;if(r.from.x===r.to.x){const u=r.from.x,f=(e.to.y-e.from.y)/(e.to.x-e.from.x),d=e.from.y-f*e.from.x,m=f*u+d;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,f=(r.to.y-r.from.y)/(r.to.x-r.from.x),d=r.from.y-f*r.from.x,m=f*u+d;return u>=Math.min(r.from.x,r.to.x)&&u<=Math.max(r.from.x,r.to.x)&&m>=Math.min(r.from.y,r.to.y)&&m<=Math.max(r.from.y,r.to.y)?{x:u,y:m}:null}const t=(r.to.y-r.from.y)/(r.to.x-r.from.x),n=r.from.y-t*r.from.x,i=(e.to.y-e.from.y)/(e.to.x-e.from.x),a=e.from.y-i*e.from.x;if(t===i)return null;const o=(a-n)/(t-i),s=t*o+n,l=o>=Math.min(r.from.x,r.to.x)&&o<=Math.max(r.from.x,r.to.x)&&s>=Math.min(r.from.y,r.to.y)&&s<=Math.max(r.from.y,r.to.y),c=o>=Math.min(e.from.x,e.to.x)&&o<=Math.max(e.from.x,e.to.x)&&s>=Math.min(e.from.y,e.to.y)&&s<=Math.max(e.from.y,e.to.y);return l&&c?{x:o,y:s}:null},xdt=({edges:r,db:e,source_trace_id:t})=>{const n=YG({db:e,source_trace_id:t,sameNetOnly:!0}).flatMap(i=>i.edges);for(const i of r)for(const a of n){const o=_dt(i,a);if(o)return`${o.x}${o.y}`,[{x:o.x,y:o.y}]}return[]},bdt=(r,{db:e})=>{const t=r.map(n=>{const i=e.source_port.get(n.source_port_id);if(!(i!=null&&i.source_component_id))return null;const a=e.source_component.get(i.source_component_id);return(a==null?void 0:a.ftype)==="simple_capacitor"?a.max_decoupling_trace_length:null}).filter(n=>n!==null);if(t.length!==0)return Math.min(...t)};function Sdt(r){var a,o,s,l,c,u,f,d,m;let e=1/0,t=1/0,n=-1/0,i=-1/0;for(const y of r){let w,S,b,E;y.type==="schematic_component"?(w=(a=y.center)==null?void 0:a.x,S=(o=y.center)==null?void 0:o.y,b=(s=y.size)==null?void 0:s.width,E=(l=y.size)==null?void 0:l.height):y.type==="schematic_box"?(w=y.x,S=y.y,b=y.width,E=y.height):y.type==="schematic_port"?(w=(c=y.center)==null?void 0:c.x,S=(u=y.center)==null?void 0:u.y,b=.2,E=.2):y.type==="schematic_text"&&(w=(f=y.position)==null?void 0:f.x,S=(d=y.position)==null?void 0:d.y,b=(((m=y.text)==null?void 0:m.length)??0)*.1,E=.2),typeof w=="number"&&typeof S=="number"&&typeof b=="number"&&typeof E=="number"&&(e=Math.min(e,w-b/2),n=Math.max(n,w+b/2),t=Math.min(t,S-E/2),i=Math.max(i,S+E/2))}return{minX:e,maxX:n,minY:t,maxY:i}}function wdt(r,e={}){const{minX:t,maxX:n,minY:i,maxY:a}=r,o=e.padding??1;if(!isFinite(t)||!isFinite(n)||!isFinite(i)||!isFinite(a))return[];const s=t-o,l=n+o,c=a+o,u=i-o,f=.01;return[{type:"rect",layers:["top"],center:{x:(s+l)/2,y:c},width:l-s,height:f,connectedTo:[]},{type:"rect",layers:["top"],center:{x:(s+l)/2,y:u},width:l-s,height:f,connectedTo:[]},{type:"rect",layers:["top"],center:{x:s,y:(c+u)/2},width:f,height:c-u,connectedTo:[]},{type:"rect",layers:["top"],center:{x:l,y:(c+u)/2},width:f,height:c-u,connectedTo:[]}]}var Edt=r=>{var o;const e=r.root.db,t=r._findConnectedPorts().ports??[],n=new Set(t.map(s=>s.schematic_port_id)),i=[];for(const s of e.toArray()){if(s.type==="schematic_component"){const l=!!s.symbol_name,c=s.size.width>s.size.height?"horz":"vert";i.push({type:"rect",layers:["top"],center:s.center,width:s.size.width+(l&&c==="horz"?-.5:0),height:s.size.height+(l&&c==="vert"?-.5:0),connectedTo:[]})}if(s.type==="schematic_port"){if(n.has(s.schematic_port_id))continue;const l=s.facing_direction?Bye(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=Sdt(e.toArray());return i.push(...wdt(a,{padding:1})),i};function Tdt({ports:r,nets:e}){var t,n,i;if(r.length>=2)return`${(t=r[0])==null?void 0:t.selector} to ${(n=r[1])==null?void 0:n.selector}`;if(r.length===1&&e.length===1)return`${(i=r[0])==null?void 0:i.selector} to net.${e[0]._parsedProps.name}`}var Mdt=({edges:r,db:e,source_trace_id:t})=>{e.source_trace.get(t);const n=YG({db:e,source_trace_id:t,differentNetOnly:!0}).flatMap(a=>a.edges),i=a=>{const{from:o,to:s}=a;return o.x===s.x?"vertical":"horizontal"};for(const a of r){const o=i(a),s=()=>n.find(c=>i(c)===o&&cL([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()}},Cdt=(r,{db:e})=>{const t=e.pcb_board.list()[0];if(t.outline){const l=t.outline,c=(u,f)=>{let d=!1;for(let m=0,y=f.length-1;m<f.length;y=m++){const w=f[m].x,S=f[m].y,b=f[y].x,E=f[y].y;S>u.y!=E>u.y&&u.x<(b-w)*(u.y-S)/(E-S)+w&&(d=!d)}return d};return r.some(u=>!c(u,l))}const n=t.width,i=t.height,a=t.center.x,o=t.center.y;return r.some(l=>l.x<a-n/2||l.y<o-i/2||l.x>a+n/2||l.y>o+i/2)},CL=r=>({...r._getGlobalPcbPositionAfterLayout(),layers:r.getAvailablePcbLayers()}),a8=class extends N_{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:pye,componentName:"Trace"}}_getTracePortOrNetSelectorListFromProps(){return"from"in this.props&&"to"in this.props?[typeof this.props.from=="string"?this.props.from:this.props.from.getPortSelector(),typeof this.props.to=="string"?this.props.to:this.props.to.getPortSelector()]:"path"in this.props?this.props.path.map(t=>typeof t=="string"?t:t.getPortSelector()):[]}getTracePortPathSelectors(){return this._getTracePortOrNetSelectorListFromProps().filter(t=>!t.includes("net."))}getTracePathNetSelectors(){return this._getTracePortOrNetSelectorListFromProps().filter(t=>t.includes("net."))}_findConnectedPorts(){const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i)throw new Error("Trace has no parent");const o=this.getTracePortPathSelectors().map(s=>({selector:s,port:this.getSubcircuit().selectOne(s,{type:"port"})??null}));for(const{selector:s,port:l}of o)if(!l){const c=s.replace(/(\> )?[^ ]+$/,""),u=this.getSubcircuit().selectOne(c);u?this.renderError(`Could not find port for selector "${s}" (did you forget to include the pin name?)
|
|
830
830
|
searched component ${u.getString()}, which has ports: ${u.children.filter(f=>f.componentName==="Port").map(f=>`${f.getString()}(${f.getNameAndAliases().join(",")})`).join(" & ")}`):this.renderError(`Could not find port for selector "${s}"`)}return o.some(s=>!s.port)?{allPortsFound:!1}:{allPortsFound:!0,portsWithSelectors:o,ports:o.map(({port:s})=>s)}}_findConnectedNets(){const t=this.getTracePathNetSelectors().map(i=>({selector:i,net:this.getSubcircuit().selectOne(i,{type:"net"})})),n=t.filter(i=>!i.net);return n.length>0&&this.renderError(`Could not find net for selector "${n[0].selector}" inside ${this}`),{netsWithSelectors:t,nets:t.map(i=>i.net)}}_getAllTracesConnectedToSameNet(){const t=this.getSubcircuit().selectAll("trace"),n=this._findConnectedNets().nets,i=this._findConnectedPorts().ports??[];return t.filter(a=>{if(a===this)return!1;const o=a._findConnectedNets().nets,s=a._findConnectedPorts().ports??[];return o.some(l=>n.includes(l))||s.some(l=>i.includes(l))})}_isExplicitlyConnectedToPort(t){const{allPortsFound:n,portsWithSelectors:i}=this._findConnectedPorts();return n?i.map(o=>o.port).includes(t):!1}_isExplicitlyConnectedToNet(t){return this._findConnectedNets().nets.includes(t)}doInitialCreateNetsFromProps(){Nge(this,this.getTracePathNetSelectors())}_computeTraceConnectionHash(){const{allPortsFound:t,ports:n}=this._findConnectedPorts();return!t||!n?null:[...n].sort((o,s)=>(o.pcb_port_id||"").localeCompare(s.pcb_port_id||"")).map(o=>o.pcb_port_id).join(",")}doInitialSourceTraceRender(){var d;const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i){this.renderError("Trace has no parent");return}const{allPortsFound:a,portsWithSelectors:o}=this._findConnectedPorts();if(!a)return;this._traceConnectionHash=this._computeTraceConnectionHash();const l=t.source_trace.list().find(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=Tdt({ports:o,nets:c}),f=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:(d=this.getSubcircuit())==null?void 0:d.subcircuit_id,max_length:bdt(o.map(m=>m.port),{db:t})??n.maxLength,display_name:u,min_trace_thickness:n.thickness});this.source_trace_id=f.source_trace_id}_insertErrorIfTraceIsOutsideBoard(t,n){const{db:i}=this.root;Cdt(t,{db:i})&&i.pcb_trace_error.insert({error_type:"pcb_trace_error",source_trace_id:this.source_trace_id,message:`Trace ${this.getString()} routed outside the board boundaries.`,pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[],pcb_port_ids:n.map(o=>o.pcb_port_id)})}doInitialPcbTraceRender(){var K,X,ce,pe;if((K=this.root)!=null&&K.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n,parent:i}=this,a=this.getSubcircuit();if(!i)throw new Error("Trace has no parent");if(a._parsedProps.routingDisabled)return;const o=(X=a._parsedProps.pcbRouteCache)==null?void 0:X.pcbTraces;if(o){const ue=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:((ce=this.getGroup())==null?void 0:ce.pcb_group_id)??void 0});this.pcb_trace_id=ue.pcb_trace_id;return}if(!a._shouldUseTraceByTraceRouting())return;const{allPortsFound:s,ports:l}=this._findConnectedPorts();if(!s)return;const c=[];for(const ue of l)ue._hasMatchedPcbPrimitive()||c.push(ue);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(ue=>ue.getString()).join(", ")}`,pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[],pcb_port_ids:c.map(ue=>ue.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 ue=l[0],he=u[0].net.getAllConnectedPorts().filter(Te=>Te!==ue);if(he.length===0){console.log("Nothing to connect this port to, the net is empty. TODO should emit a warning!");return}const ge=pdt(ue,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 f=l.flatMap(ue=>ue.matchedComponents.filter(Se=>Se.componentName==="TraceHint")),d=(this._parsedProps.pcbRouteHints??[]).concat(f.flatMap(ue=>ue.getPcbRouteHints()));if(l.length>2){this.renderError(`Trace has more than two ports (${l.map(ue=>ue.getString()).join(", ")}), routing between more than two ports for a single trace is not implemented`);return}if(this.getSubcircuit().selectAll("trace").filter(ue=>ue.renderPhaseStates.PcbTraceRender.initialized).some(ue=>ue._portsRoutedOnPcb.length===l.length&&ue._portsRoutedOnPcb.every(Se=>l.includes(Se))))return;let w=[];d.length===0?w=[CL(l[0]),CL(l[1])]:w=[CL(l[0]),...d,CL(l[1])];const S=TL(w),b=n4(this.root.db.toArray()),[E,P]=mdt(()=>dT(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(ue=>ue.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[]});return}for(const ue of E)if(ue.connectedTo.length>0){const he=b.getNetConnectedToId(ue.connectedTo[0]);he&&ue.connectedTo.push(he)}let U=[];if(S.length===0)U=w;else{const ue=S[0].layer_path;U=w.map((Se,he)=>Se.via?{...Se,via_to_layer:ue[he]}:{...Se,layers:[ue[he]]})}U[0].pcb_port_id=l[0].pcb_port_id,U[U.length-1].pcb_port_id=l[1].pcb_port_id;const V=[];for(const[ue,Se]of Age(U)){const he="via_to_layer"in ue?ue.via_to_layer:null,ge=2,Te="layers"in ue&&ue.layers.length===1?ue.layers[0]:he??"top",xe="layers"in Se&&Se.layers.length===1?Se.layers[0]:he??"top",Pe="pcb_port_id"in ue?ue.pcb_port_id:null,De="pcb_port_id"in Se?Se.pcb_port_id:null,Ue=this.getSubcircuit()._parsedProps.minTraceWidth??.16,Re=new fT({OBSTACLE_MARGIN:Ue*2,isRemovePathLoopsEnabled:!0,optimizeWithGoalBoxes:!!(Pe&&De),connMap:b,input:{obstacles:E,minTraceWidth:Ue,connections:[{name:this.source_trace_id,pointsToConnect:[{...ue,layer:Te,pcb_port_id:Pe},{...Se,layer:xe,pcb_port_id:De}]}],layerCount:2,bounds:{minX:Math.min(ue.x,Se.x)-ge,maxX:Math.max(ue.x,Se.x)+ge,minY:Math.min(ue.y,Se.y)-ge,maxY:Math.max(ue.y,Se.y)+ge}}});let $e=null;try{$e=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:(ue.x+Se.x)/2,y:(ue.y+Se.y)/2},pcb_port_ids:l.map(At=>At.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:l.map(At=>At.pcb_component_id)})}if(!$e)return;if($e.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:(ue.x+Se.x)/2,y:(ue.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]=$e;he&&(Ke.route=Ke.route.map(pt=>(pt.route_type==="wire"&&!pt.layer&&(pt.layer=he),pt))),Pe&&Ke.route[0].route_type==="wire"&&(Ke.route[0].start_pcb_port_id=Pe);const ut=Ke.route[Ke.route.length-1];De&&ut.route_type==="wire"&&(ut.end_pcb_port_id=De),V.push(Ke.route)}const Y=fdt(V),W=vdt(Y),$=t.pcb_trace.insert({route:Y,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 ue of Y)ue.route_type==="via"&&t.pcb_via.insert({pcb_trace_id:$.pcb_trace_id,x:ue.x,y:ue.y,hole_diameter:.3,outer_diameter:.6,layers:[ue.from_layer,ue.to_layer],from_layer:ue.from_layer,to_layer:ue.to_layer});this._insertErrorIfTraceIsOutsideBoard(Y,l)}_doInitialSchematicTraceRenderWithDisplayLabel(){var V,Y,W,$;if((V=this.root)!=null&&V.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i)throw new Error("Trace has no parent");const{allPortsFound:a,portsWithSelectors:o}=this._findConnectedPorts();if(!a)return;const s=o.map(({port:K})=>({port:K,position:K._getGlobalSchematicPositionAfterLayout(),schematic_port_id:K.schematic_port_id,facingDirection:K.facingDirection}));if(s.length<2)throw new Error("Expected at least two ports in portsWithPosition.");let l,c;const u=s[0].position,f=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(!f.source_port_id)throw new Error(`Missing source_port_id for the 'from' port (${l}).`);const d=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(K=>K.source_net_id===f.source_port_id),w=t.schematic_net_label.list().find(K=>K.source_net_id===m.source_port_id),[S,b]=o.map(({port:K})=>K),P=((Y=S.parent)==null?void 0:Y.config.shouldRenderAsSchematicBox)?`${(W=S==null?void 0:S.parent)==null?void 0:W.props.name}_${S==null?void 0:S.props.name}`:`${($=b==null?void 0:b.parent)==null?void 0:$.props.name}_${b==null?void 0:b.props.name}`,U=this.props.schDisplayLabel??P;if(y&&y.text!==U&&(y.text=`${U} / ${y.text}`),w&&(w==null?void 0:w.text)!==U&&(w.text=`${U} / ${w.text}`),U!=null&&U.toLocaleLowerCase().includes("gnd")||U!=null&&U.toLocaleLowerCase().includes("ground")){!y&&!w?(ML({port:f,anchorPos:u,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t}),ML({port:m,anchorPos:d,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t})):y?w||ML({port:m,anchorPos:d,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t}):ML({port:f,anchorPos:u,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t});return}w||t.schematic_net_label.insert({text:this.props.schDisplayLabel??P,source_net_id:m.source_port_id,anchor_position:d,center:d,anchor_side:qG(m.facingDirection)??"bottom"}),y||t.schematic_net_label.insert({text:this.props.schDisplayLabel??P,source_net_id:f.source_port_id,anchor_position:u,center:u,anchor_side:qG(f.facingDirection)??"bottom"})}_isSymbolToChipConnection(){const{allPortsFound:t,ports:n}=this._findConnectedPorts();if(!t||n.length!==2)return!1;const[i,a]=n;if(!(i!=null&&i.parent)||!(a!=null&&a.parent))return!1;const o=i.parent.config.shouldRenderAsSchematicBox,s=a.parent.config.shouldRenderAsSchematicBox;return o&&!s||!o&&s}_isSymbolToSymbolConnection(){const{allPortsFound:t,ports:n}=this._findConnectedPorts();if(!t||n.length!==2)return!1;const[i,a]=n;if(!(i!=null&&i.parent)||!(a!=null&&a.parent))return!1;const o=!i.parent.config.shouldRenderAsSchematicBox,s=!a.parent.config.shouldRenderAsSchematicBox;return o&&s}_isChipToChipConnection(){const{allPortsFound:t,ports:n}=this._findConnectedPorts();if(!t||n.length!==2)return!1;const[i,a]=n;if(!(i!=null&&i.parent)||!(a!=null&&a.parent))return!1;const o=i.parent.config.shouldRenderAsSchematicBox,s=a.parent.config.shouldRenderAsSchematicBox;return o&&s}doInitialSchematicTraceRender(){var Te,xe;if((Te=this.root)!=null&&Te.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i)throw new Error("Trace has no parent");const{allPortsFound:a,portsWithSelectors:o}=this._findConnectedPorts(),{netsWithSelectors:s}=this._findConnectedNets();if(!a)return;const c=o.map(Pe=>Pe.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 f={name:this.source_trace_id,pointsToConnect:[]},d=Edt(this),m=o.map(({port:Pe})=>({port:Pe,position:Pe._getGlobalSchematicPositionAfterLayout(),schematic_port_id:Pe.schematic_port_id??void 0,facingDirection:Pe.facingDirection}));if(m.length===1&&s.length===1){const Pe=s[0].net,{port:De,position:Ue}=m[0];t.schematic_net_label.insert({text:Pe._parsedProps.name,source_net_id:Pe.source_net_id,anchor_position:Ue,center:Ue,anchor_side:qG(De.facingDirection)??"bottom"});return}if(m.length<2)return;f.pointsToConnect=m.map(({position:Pe})=>({...Pe,layer:"top"}));const w=udt(d),S=2,b={minTraceWidth:.1,obstacles:d,connections:[f],bounds:{minX:w.minX-S,maxX:w.maxX+S,minY:w.minY-S,maxY:w.maxY+S},layerCount:1};let E=fT,P=!1;this.getSubcircuit().props._schDirectLineRoutingEnabled&&(E=Fge,P=!0);let V=new E({input:b,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(V.length===0){if(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection()){this._doInitialSchematicTraceRenderWithDisplayLabel();return}V=new Fge({input:b}).solveAndMapToTraces(),P=!0}const[{route:Y}]=V;let W=[];for(let Pe=0;Pe<Y.length-1;Pe++)W.push({from:Y[Pe],to:Y[Pe+1]});const $=this.source_trace_id;let K=[];if(!P){Mdt({edges:W,db:t,source_trace_id:$});const Pe=YG({db:t,source_trace_id:$,differentNetOnly:!0}).flatMap(De=>De.edges);W=gdt({edges:W,otherEdges:Pe}),K=xdt({edges:W,db:t,source_trace_id:this.source_trace_id})}const X=W[W.length-1],ce=m[m.length-1],pe=jge(X);W.push(...$G({lastEdge:X,lastEdgePort:ce,lastDominantDirection:pe}));const ue=W[0],Se=m[0],he=jge(ue);if(W.unshift(...$G({firstEdge:ue,firstEdgePort:Se,firstDominantDirection:he})),!this.source_trace_id)throw new Error("Missing source_trace_id for schematic trace insertion.");if(this.getSubcircuit()._parsedProps.schTraceAutoLabelEnabled&&hdt(K,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:K});this.schematic_trace_id=ge.schematic_trace_id,u!=null&&u._connectedSchematicPortPairs&&u._connectedSchematicPortPairs.add(c)}},Rdt=Jm("tscircuit:core"),Adt=R.object({x:D5,y:D5,z:D5}),Jx=class extends N_{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,f,d,m,y,w,S;if((s=this.root)!=null&&s.schematicDisabled)return;const{config:n}=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 V of U){const Y=hC(V,this._parsedProps.pinLabels);i.push(new US({pinNumber:Y,aliases:((l=t.additionalAliases)==null?void 0:l[`pin${Y}`])??[]},{originDescription:`schPortArrangement:${P}`}))}}const b=["left","right","top","bottom"];let E=1;for(const P of b){const U=a[`${P}Size`];for(let V=0;V<U;V++)i.push(new US({pinNumber:E++,aliases:((c=t.additionalAliases)==null?void 0:c[`pin${E}`])??[]},{originDescription:`schPortArrangement:${P}`}))}}const o=this._parsedProps.pinLabels;if(o)for(let[b,E]of Object.entries(o)){b=b.replace("pin","");let P=i.find(Y=>Y._parsedProps.pinNumber===Number(b));const U=Array.isArray(E)?E[0]:E,V=Array.isArray(E)?E.slice(1):[];P?(P.externallyAddedAliases.push(U,...V),P.props.name=U):(P=new US({pinNumber:parseInt(b),name:U,aliases:[...V,...((u=t.additionalAliases)==null?void 0:u[`pin${parseInt(b)}`])??[]]},{originDescription:`pinLabels:pin${b}`}),i.push(P))}if(n.schematicSymbolName){const b=d_[this._getSchematicSymbolNameOrThrow()];if(!b)return;for(const E of b.ports){const P=kge(E.labels);if(!P)continue;const U=i.find(V=>V._parsedProps.pinNumber===Number(P));if(U)U.schematicSymbolPortDef=E;else{const V=mC(E.labels.concat(((f=t.additionalAliases)==null?void 0:f[`pin${P}`])??[]));V&&(V.originDescription=`schematicSymbol:labels[0]:${E.labels[0]}`,V.schematicSymbolPortDef=E,i.push(V))}}this.addAll(i)}if(!this._getSchematicPortArrangement()){const b=this.getPortsFromFootprint(t);for(const E of b)i.some(P=>P.isMatchingAnyOf(E.getNameAndAliases()))||i.push(E)}for(let b=1;b<=(t.pinCount??this._getPinCount());b++){if(!a||i.find(P=>P._parsedProps.pinNumber===b))continue;let E=[...((d=a.leftSide)==null?void 0:d.pins)??[],...((m=a.rightSide)==null?void 0:m.pins)??[],...((y=a.topSide)==null?void 0:y.pins)??[],...((w=a.bottomSide)==null?void 0:w.pins)??[]].map(P=>hC(P,this._parsedProps.pinLabels));["leftSize","rightSize","topSize","bottomSize","leftPinCount","rightPinCount","topPinCount","bottomPinCount"].some(P=>P in a)&&(E=Array.from({length:this._getPinCount()},(P,U)=>U+1)),E.includes(b)&&i.push(new US({pinNumber:b,aliases:((S=t.additionalAliases)==null?void 0:S[`pin${b}`])??[]},{originDescription:`notOtherwiseAddedButDeducedFromPinCount:${b}`}))}i.length>0&&this.addAll(i)}_getImpliedFootprintString(){return null}_addChildrenFromStringFootprint(){var o;const{name:t,pcbRotation:n,pinLabels:i}=this.props;let{footprint:a}=this.props;if(a??(a=(o=this._getImpliedFootprintString)==null?void 0:o.call(this)),!!a&&typeof a=="string"){const s=nT.string(a).soup(),l=Jft({componentName:t,componentRotation:n,footprint:a,pinLabels:i},s);this.addAll(l)}}get portMap(){return new Proxy({},{get:(t,n)=>{const i=this.children.find(a=>a.componentName==="Port"&&a.isMatchingNameOrAlias(n));if(!i)throw new Error(`There was an issue finding the port "${n.toString()}" inside of a ${this.componentName} component with name: "${this.props.name}". This is a bug in @tscircuit/core`);return i}})}getInstanceForReactElement(t){for(const n of this.reactSubtrees)if(n.element===t)return n.component;return null}doInitialSourceRender(){const t=this.config.sourceFtype;if(!t)return;const{db:n}=this.root,{_parsedProps:i}=this,a=n.source_component.insert({ftype:t,name:i.name,manufacturer_part_number:i.manufacturerPartNumber??i.mfn,supplier_part_numbers:i.supplierPartNumbers});this.source_component_id=a.source_component_id}doInitialSchematicComponentRender(){var a,o,s;if((a=this.root)!=null&&a.schematicDisabled)return;const{db:t}=this.root,{schematicSymbolName:n}=this.config;n?this._doInitialSchematicComponentRenderWithSymbol():this._getSchematicBoxDimensions()&&this._doInitialSchematicComponentRenderWithSchematicBoxDimensions();const i=(o=this.getSubcircuit())==null?void 0:o._getSchematicManualPlacementForComponent(this);if(this.schematic_component_id&&(this.props.schX!==void 0||this.props.schY!==void 0)&&i){if(!this.schematic_component_id)return;const l=ON.parse({type:"schematic_manual_edit_conflict_warning",schematic_manual_edit_conflict_warning_id:`schematic_manual_edit_conflict_${this.source_component_id}`,message:`${this.getString()} has both manual placement and prop coordinates. schX and schY will be used. Remove schX/schY or clear the manual placement.`,schematic_component_id:this.schematic_component_id,source_component_id:this.source_component_id,subcircuit_id:(s=this.getSubcircuit())==null?void 0:s.subcircuit_id});t.schematic_manual_edit_conflict_warning.insert(l)}}_getSchematicSymbolDisplayValue(){}_getInternallyConnectedPins(){if(this.internallyConnectedPinNames.length===0)return[];const t=[];for(const n of this.internallyConnectedPinNames){const i=[];for(const a of n)i.push(this.portMap[a]);t.push(i)}return t}_doInitialSchematicComponentRenderWithSymbol(){var s;if((s=this.root)!=null&&s.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getSchematicSymbolNameOrThrow(),a=d_[i],o=this._getGlobalSchematicPositionBeforeLayout();if(a){const l=t.schematic_component.insert({center:o,size:a.size,source_component_id:this.source_component_id,symbol_name:i,symbol_display_value:this._getSchematicSymbolDisplayValue()});this.schematic_component_id=l.schematic_component_id}}_doInitialSchematicComponentRenderWithSchematicBoxDimensions(){var d;if((d=this.root)!=null&&d.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getSchematicBoxDimensions(),a={};if(Array.isArray(n.pinLabels))n.pinLabels.forEach((m,y)=>{a[String(y+1)]=m});else for(const[m,y]of Object.entries(n.pinLabels??{}))a[m]=Array.isArray(y)?y[0]:y;const o=this._getGlobalSchematicPositionBeforeLayout(),s=this._getSchematicPortArrangement(),l=t.schematic_component.insert({center:o,rotation:n.schRotation??0,size:i.getSize(),port_arrangement:Wft(s),pin_spacing:n.schPinSpacing??.2,pin_styles:Xft(n.schPinStyle,n.pinLabels),port_labels:a,source_component_id:this.source_component_id}),c=(s==null?void 0:s.topSide)!==void 0||(s==null?void 0:s.bottomSide)!==void 0,u=i==null?void 0:i.getSize().width,f=i==null?void 0:i.getSize().height;t.schematic_text.insert({text:n.manufacturerPartNumber??"",schematic_component_id:l.schematic_component_id,anchor:"left",rotation:0,position:{x:c?o.x+(u??0)/2+.1:o.x-(u??0)/2,y:c?o.y+(f??0)/2+.35:o.y-(f??0)/2-.13},color:"#006464",font_size:.05}),t.schematic_text.insert({text:n.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+(f??0)/2+.55:o.y+(f??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:n}=this,i=this.getSubcircuit(),a=t.pcb_component.insert({center:this._getGlobalPcbPositionBeforeLayout(),width:0,height:0,layer:n.layer??"top",rotation:n.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:i.subcircuit_id??void 0});if(!n.footprint&&!this.isGroup){const l=t.pcb_missing_footprint_error.insert({message:`No footprint found for component: ${this.getString()}`,source_component_id:`${this.source_component_id}`,error_type:"pcb_missing_footprint_error"});this.pcb_missing_footprint_error_id=l.pcb_missing_footprint_error_id}this.pcb_component_id=a.pcb_component_id;const o=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if((this.props.pcbX!==void 0||this.props.pcbY!==void 0)&&o){const l=UN.parse({type:"pcb_manual_edit_conflict_warning",pcb_manual_edit_conflict_warning_id:`pcb_manual_edit_conflict_${this.source_component_id}`,message:`${this.getString()} has both manual placement and prop coordinates. pcbX and pcbY will be used. Remove pcbX/pcbY or clear the manual placement.`,pcb_component_id:this.pcb_component_id,source_component_id:this.source_component_id,subcircuit_id:i.subcircuit_id??void 0});t.pcb_manual_edit_conflict_warning.insert(l)}}doInitialPcbComponentSizeCalculation(){var o;if((o=this.root)!=null&&o.pcbDisabled||!this.pcb_component_id)return;const{db:t}=this.root,{_parsedProps:n}=this,i=Uge(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:Yft(t)}}doInitialInitializePortsFromChildren(){this.initPorts()}doInitialReactSubtreesRender(){if(rt.isValidElement(this.props.footprint)){if(this.reactSubtrees.some(n=>n.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 n;if(rt.isValidElement(t)){const i=this._renderReactSubtree(t);this.reactSubtrees.push(i),n=i.component}else n=t;if(n.componentName==="Port"){if(this._hasExistingPortExactly(n))return;const a=this.children.filter(o=>o.componentName==="Port").find(o=>o.isMatchingAnyOf(n.getNameAndAliases()));a&&Rdt(`Similar ports added. Port 1: ${a}, Port 2: ${n}`)}super.add(n)}getPortsFromFootprint(t){let{footprint:n}=this.props;if((!n||rt.isValidElement(n))&&(n=this.children.find(a=>a.componentName==="Footprint")),typeof n=="string"){const a=nT.string(n).soup(),o=[];for(const s of a)if("port_hints"in s&&s.port_hints){const l=mC(s.port_hints,t);if(!l)continue;l.originDescription=`footprint:string:${n}:port_hints[0]:${s.port_hints[0]}`,o.push(l)}return o}if(!rt.isValidElement(n)&&n&&n.componentName==="Footprint"){const a=n;let o=1;const s=[];for(const l of a.children){if(!l.props.portHints)continue;let c=l.props.portHints;c.some(d=>d.startsWith("pin"))||(c=[...c,`pin${o}`]),o++;const f=mC(c);f&&(f.originDescription=`footprint:${n}`,s.push(f))}return s}const i=[];if(!n){for(const a of this.children)if(a.props.portHints&&a.isPcbPrimitive){const o=mC(a.props.portHints);o&&i.push(o)}}return i}getPortsFromSchematicSymbol(){var a;if((a=this.root)!=null&&a.schematicDisabled)return[];const{config:t}=this;if(!t.schematicSymbolName)return[];const n=d_[t.schematicSymbolName];if(!n)return[];const i=[];for(const o of n.ports){const s=mC(o.labels);s&&(s.schematicSymbolPortDef=o,i.push(s))}return i}doInitialCreateNetsFromProps(){this._createNetsFromProps(this._getNetsFromConnectionsProp())}_getNetsFromConnectionsProp(){const{_parsedProps:t}=this,n=[];if(t.connections)for(const[i,a]of Object.entries(t.connections)){const o=Array.isArray(a)?a:[a];for(const s of o)n.push(s)}return n}_createNetsFromProps(t){Nge(this,t)}_getPcbCircuitJsonBounds(){const{db:t}=this.root;if(!this.pcb_component_id)return super._getPcbCircuitJsonBounds();const n=t.pcb_component.get(this.pcb_component_id);return{center:{x:n.center.x,y:n.center.y},bounds:{left:n.center.x-n.width/2,top:n.center.y-n.height/2,right:n.center.x+n.width/2,bottom:n.center.y+n.height/2},width:n.width,height:n.height}}_getPinCountFromSchematicPortArrangement(){const t=this._getSchematicPortArrangement();if(!t)return 0;if(!Ige(t))return(t.leftSize??t.leftPinCount??0)+(t.rightSize??t.rightPinCount??0)+(t.topSize??t.topPinCount??0)+(t.bottomSize??t.bottomPinCount??0);const{leftSide:i,rightSide:a,topSide:o,bottomSide:s}=t;return Math.max(...(i==null?void 0:i.pins)??[],...(a==null?void 0:a.pins)??[],...(o==null?void 0:o.pins)??[],...(s==null?void 0:s.pins)??[])}_getPinCount(){return this._getSchematicPortArrangement()?this._getPinCountFromSchematicPortArrangement():this.getPortsFromFootprint().length}_getSchematicPortArrangement(){return this._parsedProps.schPinArrangement??this._parsedProps.schPortArrangement}_getSchematicBoxDimensions(){if(this.getSchematicSymbol()||!this.config.shouldRenderAsSchematicBox)return null;const{_parsedProps:t}=this,n=this._getPinCount(),i=t.schPinSpacing??.2;return odt({schWidth:t.schWidth,schHeight:t.schHeight,schPinSpacing:i,numericSchPinStyle:cdt(t.schPinStyle,t.pinLabels),pinCount:n,schPortArrangement:this._getSchematicPortArrangement(),pinLabels:t.pinLabels})}doInitialCadModelRender(){var u;const{db:t}=this.root,{boardThickness:n=0}=((u=this.root)==null?void 0:u._getBoard())??{},i=this._parsedProps.cadModel;if(!this.pcb_component_id||!i&&!this.props.footprint||i===null)return;const 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=Adt.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=YE.parse({x:0,y:0,z:0,...typeof(i==null?void 0:i.positionOffset)=="object"?i.positionOffset:{}}),c=this.props.layer==="bottom"?"bottom":"top";t.cad_component.insert({position:{x:a.center.x+l.x,y:a.center.y+l.y,z:(c==="bottom"?-n/2:n/2)+l.z},rotation:{x:s.x,y:(c==="top"?0:180)+s.y,z:((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 n=((i=this.root)==null?void 0:i.getClientOrigin())??"";return`${t}${t.includes("?")?"&":"?"}cachebust_origin=${encodeURIComponent(n)}`}doInitialPartsEngineRender(){const t=this.getInheritedProperty("partsEngine");if(!t)return;const{db:n}=this.root,i=n.source_component.get(this.source_component_id);if(!i||i.supplier_part_numbers)return;let a;this.props.footprint&&typeof this.props.footprint=="string"&&(a=this.props.footprint);const o=t.findPart({sourceComponent:i,footprinterString:a});if(!(o instanceof Promise)){n.source_component.update(this.source_component_id,{supplier_part_numbers:o});return}this._queueAsyncEffect("get-supplier-part-numbers",async()=>{this._asyncSupplierPartNumbers=await o,this._markDirty("PartsEngineRender")})}updatePartsEngineRender(){const{db:t}=this.root,n=t.source_component.get(this.source_component_id);if(n&&!n.supplier_part_numbers&&this._asyncSupplierPartNumbers){t.source_component.update(this.source_component_id,{supplier_part_numbers:this._asyncSupplierPartNumbers});return}}doInitialCreateTracesFromProps(){this._createTracesFromConnectionsProp()}_createTracesFromConnectionsProp(){const{_parsedProps:t}=this;if(t.connections)for(const[n,i]of Object.entries(t.connections)){const a=Array.isArray(i)?i:[i];for(const o of a)this.add(new a8({from:`${this.getSubcircuitSelector()} > port.${n}`,to:o}))}}},Pdt=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:n,targetMinCapacity:i,stepDelay:a=0}=t;this.solver=new DG(e,{capacityDepth:n,targetMinCapacity:i,cacheProvider:null}),this.stepDelay=a}start(){this.isRouting||(this.isRouting=!0,this.cycleCount=0,this.runCycleAndQueueNextCycle())}runCycleAndQueueNextCycle(){var e;if(this.isRouting)try{if(this.solver.solved||this.solver.failed){this.solver.failed?this.emitEvent({type:"error",error:new Error(this.solver.error||"Routing failed")}):this.emitEvent({type:"complete",traces:this.solver.getOutputSimpleRouteJson().traces||[]}),this.isRouting=!1;return}const t=Date.now(),n=this.solver.iterations;for(;Date.now()-t<250&&!this.solver.failed&&!this.solver.solved;)this.solver.step();const i=(this.solver.iterations-n)/(Date.now()-t)*1e3;this.cycleCount++;const a=((e=this.solver)==null?void 0:e.preview())||void 0,o=this.solver.progress;this.emitEvent({type:"progress",steps:this.cycleCount,iterationsPerSecond:i,progress:o,phase:this.solver.getCurrentPhase(),debugGraphics:a}),this.stepDelay>0?this.timeoutId=setTimeout(()=>this.runCycleAndQueueNextCycle(),this.stepDelay):this.timeoutId=setTimeout(()=>this.runCycleAndQueueNextCycle(),0)}catch(t){this.emitEvent({type:"error",error:t instanceof Error?t:new Error(String(t))}),this.isRouting=!1}}stop(){this.isRouting&&(this.isRouting=!1,this.timeoutId!==void 0&&(clearTimeout(this.timeoutId),this.timeoutId=void 0))}on(e,t){e==="complete"?this.eventHandlers.complete.push(t):e==="error"?this.eventHandlers.error.push(t):e==="progress"&&this.eventHandlers.progress.push(t)}emitEvent(e){if(e.type==="complete")for(const t of this.eventHandlers.complete)t(e);else if(e.type==="error")for(const t of this.eventHandlers.error)t(e);else if(e.type==="progress")for(const t of this.eventHandlers.progress)t(e)}solveSync(){if(this.solver.solve(),this.solver.failed)throw new Error(this.solver.error||"Routing failed");return this.solver.getOutputSimpleRouteJson().traces||[]}},Hge=class extends N_{constructor(){super(...arguments);Je(this,"matchedPort",null)}get config(){return{componentName:"TraceHint",zodProps:kye}}doInitialPortMatching(){const{db:t}=this.root,{_parsedProps:n,parent:i}=this;if(!i)return;if(i.componentName==="Trace"){this.renderError(`Port inference inside trace is not yet supported (${this})`);return}if(!i)throw new Error("TraceHint has no parent");if(!n.for){this.renderError(`TraceHint has no for property (${this})`);return}const a=i.selectOne(n.for,{type:"port"});a||this.renderError(`${this} could not find port for selector "${n.for}"`),this.matchedPort=a,a.registerMatch(this)}getPcbRouteHints(){const{_parsedProps:t}=this,n=t.offset?[t.offset]:t.offsets;if(!n)return[];const i=this._computePcbGlobalTransformBeforeLayout();return n.map(a=>({...kr(i,a),via:a.via,to_layer:a.to_layer,trace_width:a.trace_width}))}doInitialPcbTraceHintRender(){var i,a,o;if((i=this.root)!=null&&i.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this;t.pcb_trace_hint.insert({pcb_component_id:(a=this.matchedPort)==null?void 0:a.pcb_component_id,pcb_port_id:(o=this.matchedPort)==null?void 0:o.pcb_port_id,route:this.getPcbRouteHints()})}},Ndt=({circuitJson:r,editEvents:e,manualEditsFile:t})=>{var i;const n={...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=i3(r).pcb_component.get(o);if(!l)continue;const c=i3(r).source_component.get(l.source_component_id);if(!c)continue;const u=(i=n.pcb_placements)==null?void 0:i.findIndex(d=>d.selector===c.name),f={selector:c.name,center:s,relative_to:"group_center"};u>=0?n.pcb_placements[u]=f:n.pcb_placements.push(f)}return n},Ddt=({circuitJson:r,editEvents:e,manualEditsFile:t})=>{var i;const n={...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=i3(r).schematic_component.get(o);if(!l)continue;const c=i3(r).source_component.get(l.source_component_id);if(!c)continue;const u=(i=n.schematic_placements)==null?void 0:i.findIndex(d=>d.selector===c.name),f={selector:c.name,center:s,relative_to:"group_center"};u>=0?n.schematic_placements[u]=f:n.schematic_placements.push(f)}return n},Vge=({circuitJson:r,editEvents:e,manualEditsFile:t})=>{const n=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 n.length>0&&(a=Ddt({circuitJson:r,editEvents:n,manualEditsFile:a})),i.length>0&&(a=Ndt({circuitJson:r,editEvents:i,manualEditsFile:a})),a},Ldt=(r,e)=>{const t=r.source_group.list(),n=[],i=a=>{const o=t.filter(s=>s.parent_subcircuit_id===a);for(const s of o)s.subcircuit_id&&(n.push(s.subcircuit_id),i(s.subcircuit_id))};return i(e),n},Gge=({db:r,circuitJson:e,subcircuit_id:t,minTraceWidth:n=.1})=>{if(!r&&e&&(r=i3(e)),!r)throw new Error("db or circuitJson is required");const i=r.pcb_trace_hint.list(),a=t?new Set([t]):null;if(t){const w=Ldt(r,t);for(const S of w)a.add(S)}const o=(e??r.toArray()).filter(w=>!t||"subcircuit_id"in w&&a.has(w.subcircuit_id)),s=r.pcb_board.list()[0];r=i3(o);const l=n4(o),c=dT([...r.pcb_component.list(),...r.pcb_smtpad.list(),...r.pcb_plated_hole.list(),...r.pcb_hole.list(),...r.pcb_via.list()].filter(w=>!t||(a==null?void 0:a.has(w.subcircuit_id))),l);for(const w of c){const S=w.connectedTo.flatMap(b=>l.getIdsConnectedToNet(b));w.connectedTo.push(...S)}const u=c.flatMap(w=>[{x:w.center.x-w.width/2,y:w.center.y-w.height/2},{x:w.center.x+w.width/2,y:w.center.y+w.height/2}]);let f;s?f={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}:f={minX:Math.min(...u.map(w=>w.x))-1,maxX:Math.max(...u.map(w=>w.x))+1,minY:Math.min(...u.map(w=>w.y))-1,maxY:Math.max(...u.map(w=>w.y))+1};const d=r.source_trace.list().map(w=>{var W,$,K;const S=w.connected_source_port_ids.map(X=>{const ce=r.source_port.get(X),pe=r.pcb_port.getWhere({source_port_id:X});return{...ce,...pe}});if(S.length<2)return null;const[b,E]=S,P=((W=b.layers)==null?void 0:W[0])??"top",U=(($=E.layers)==null?void 0:$[0])??"top",V=i.filter(X=>X.pcb_port_id===b.pcb_port_id||X.pcb_port_id===E.pcb_port_id),Y=[];for(const X of V){const ce=r.pcb_port.get(X.pcb_port_id),pe=((K=ce==null?void 0:ce.layers)==null?void 0:K[0])??"top";for(const ue of X.route)Y.push({x:ue.x,y:ue.y,layer:pe})}return{name:w.source_trace_id??l.getNetConnectedToId(w.source_trace_id)??"",source_trace_id:w.source_trace_id,pointsToConnect:[{x:b.x,y:b.y,layer:P},...Y,{x:E.x,y:E.y,layer:U}]}}).filter(w=>w!==null),m=r.source_net.list().filter(w=>!t||(a==null?void 0:a.has(w.subcircuit_id))),y=[];for(const w of m){const S=r.source_trace.list().filter(b=>{var E;return(E=b.connected_source_net_ids)==null?void 0:E.includes(w.source_net_id)});y.push({name:w.source_net_id??l.getNetConnectedToId(w.source_net_id),pointsToConnect:S.flatMap(b=>r.pcb_port.list().filter(P=>b.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:f,obstacles:c,connections:[...d,...y],layerCount:2,minTraceWidth:n},connMap:l}},XG=class extends Jx{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:eye,componentName:"Group"}}doInitialSourceRender(){const{db:t}=this.root,n=t.source_group.insert({name:this._parsedProps.name,is_subcircuit:this.isSubcircuit});this.subcircuit_id=`subcircuit_${n.source_group_id}`,this.source_group_id=n.source_group_id,t.source_group.update(n.source_group_id,{subcircuit_id:this.subcircuit_id})}doInitialSourceParentAttachment(){var i,a,o;const{db:t}=this.root;if(!this.isSubcircuit)return;const n=(o=(a=(i=this.parent)==null?void 0:i.getSubcircuit)==null?void 0:a.call(i))==null?void 0:o.subcircuit_id;n&&t.source_group.update(this.source_group_id,{parent_subcircuit_id:n})}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=t.pcb_group.insert({is_subcircuit:this.isSubcircuit,subcircuit_id:this.subcircuit_id,name:this._parsedProps.name,center:this._getGlobalPcbPositionBeforeLayout(),width:0,height:0,pcb_component_ids:[],source_group_id:this.source_group_id});this.pcb_group_id=i.pcb_group_id}doInitialCreateTraceHintsFromProps(){var o;const{_parsedProps:t}=this,{db:n}=this.root,i=t;if(!this.isSubcircuit)return;const a=(o=i.layout)==null?void 0:o.manual_trace_hints;if(a)for(const s of a)this.add(new Hge({for:s.pcb_port_selector,offsets:s.offsets}))}doInitialSourceAddConnectivityMapKey(){if(!this.isSubcircuit)return;const{db:t}=this.root,n=this.selectAll("trace"),i=new uT({});i.addConnections(n.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 n){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(n=>n.isSubcircuit);for(const n of t)if(n._shouldRouteAsync()&&!n._asyncAutoroutingResult)return!1;return!0}_shouldRouteAsync(){const t=this._getAutorouterConfig();return t.groupMode==="sequential-trace"?!1:!!(t.local&&t.groupMode==="subcircuit"||!t.local)}_hasTracesToRoute(){const t=Jm("tscircuit:core:_hasTracesToRoute"),n=this.selectAll("trace");return t(`[${this.getString()}] has ${n.length} traces to route`),n.length>0}async _runEffectMakeHttpAutoroutingRequest(){var u,f,d,m;const{db:t}=this.root,n=Jm("tscircuit:core:_runEffectMakeHttpAutoroutingRequest");this._parsedProps;const i=this._getAutorouterConfig(),a=i.serverUrl,o=i.serverMode,s=(y,w)=>{var S;return n("fetching",y),w.headers&&(w.headers["Tscircuit-Core-Version"]=(S=this.root)==null?void 0:S.getCoreVersion()),fetch(y,w)},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:w}=await s(`${a}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_simple_route_json:Gge({db:t,minTraceWidth:((f=this.props.autorouter)==null?void 0:f.minTraceWidth)??.15,subcircuit_id:this.subcircuit_id}).simpleRouteJson,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(S=>S.json());this._asyncAutoroutingResult=w,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(w=>w.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:(d=this.root)==null?void 0:d.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(w=>w.json());if(y.is_finished){const{autorouting_job_output:w}=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(S=>S.json());this._asyncAutoroutingResult={output_pcb_traces:w.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(w=>setTimeout(w,100))}}async _runLocalAutorouting(){var l,c,u,f,d;const{db:t}=this.root;this._parsedProps;const n=Jm("tscircuit:core:_runLocalAutorouting");n(`[${this.getString()}] starting local autorouting`);const i=this._getAutorouterConfig(),{simpleRouteJson:a}=Gge({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 Pdt(a,{capacityDepth:(u=this.props.autorouter)==null?void 0:u.capacityDepth,targetMinCapacity:(f=this.props.autorouter)==null?void 0:f.targetMinCapacity});const s=new Promise((m,y)=>{o.on("complete",w=>{n(`[${this.getString()}] local autorouting complete`),m(w.traces)}),o.on("error",w=>{n(`[${this.getString()}] local autorouting error: ${w.error.message}`),y(w.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)}),(d=this.root)==null||d.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 n;const t=Jm("tscircuit:core:doInitialPcbTraceRender");if(this.isSubcircuit&&!((n=this.root)!=null&&n.pcbDisabled)&&!this.getInheritedProperty("routingDisabled")&&!this._shouldUseTraceByTraceRouting()){if(!this._areChildSubcircuitsRouted()){t(`[${this.getString()}] child subcircuits are not routed, skipping async autorouting until subcircuits routed`);return}t(`[${this.getString()}] no child subcircuits to wait for, initiating async routing`),this._hasTracesToRoute()&&this._startAsyncAutorouting()}}updatePcbTraceRender(){var i;const t=Jm("tscircuit:core:updatePcbTraceRender");if(t(`[${this.getString()}] updating...`),!this.isSubcircuit)return;if(this._shouldRouteAsync()&&this._hasTracesToRoute()&&!this._hasStartedAsyncAutorouting){this._areChildSubcircuitsRouted()&&(t(`[${this.getString()}] child subcircuits are now routed, starting async autorouting`),this._startAsyncAutorouting());return}if(!this._asyncAutoroutingResult||this._shouldUseTraceByTraceRouting())return;const{db:n}=this.root;if(this._asyncAutoroutingResult.output_simple_route_json){t(`[${this.getString()}] updating PCB traces from simple route json (${(i=this._asyncAutoroutingResult.output_simple_route_json.traces)==null?void 0:i.length} traces)`),this._updatePcbTraceRenderFromSimpleRouteJson();return}if(this._asyncAutoroutingResult.output_pcb_traces){t(`[${this.getString()}] updating PCB traces from ${this._asyncAutoroutingResult.output_pcb_traces.length} traces`),this._updatePcbTraceRenderFromPcbTraces();return}}_updatePcbTraceRenderFromSimpleRouteJson(){const{db:t}=this.root,{traces:n}=this._asyncAutoroutingResult.output_simple_route_json;if(n)for(const i of n)t.pcb_trace.insert({subcircuit_id:this.subcircuit_id,route:i.route})}_updatePcbTraceRenderFromPcbTraces(){const{output_pcb_traces:t}=this._asyncAutoroutingResult;if(!t)return;const{db:n}=this.root;for(const i of t)if(i.type==="pcb_trace"){if(i.subcircuit_id=this.subcircuit_id,i.connection_name){const a=i.connection_name;i.source_trace_id=a}n.pcb_trace.insert(i)}for(const i of t)if(i.type!=="pcb_via"&&i.type==="pcb_trace")for(const a of i.route)a.route_type==="via"&&n.pcb_via.insert({pcb_trace_id:i.pcb_trace_id,x:a.x,y:a.y,hole_diameter:.3,outer_diameter:.6,layers:[a.from_layer,a.to_layer],from_layer:a.from_layer,to_layer:a.to_layer})}doInitialSchematicLayout(){if(!this.isSubcircuit||!this._parsedProps.schAutoLayoutEnabled)return;const{db:n}=this.root,i=this.getDescendants(),a=[];for(const l of i)if("schematic_component_id"in l){const c=n.schematic_component.get(l.schematic_component_id);if(c){const u=n.schematic_port.list().filter(f=>f.schematic_component_id===c.schematic_component_id);a.push(...u)}}const o=_G(n.toArray()),s=xG(o);gG(n.toArray(),s)}_getAutorouterConfig(){const t={serverUrl:"https://registry-api.tscircuit.com",serverMode:"job",serverCacheEnabled:!0},n=this._parsedProps.autorouter??this.getInheritedProperty("autorouter");return typeof n=="object"?{local:!(n.serverUrl||n.serverMode||n.serverCacheEnabled),...t,...n}:n==="auto-local"?{local:!0,groupMode:"subcircuit"}:n==="sequential-trace"?{local:!0,groupMode:"sequential-trace"}:n==="subcircuit"?{local:!0,groupMode:"subcircuit"}:n==="auto-cloud"?{local:!1,groupMode:"subcircuit",serverUrl:t.serverUrl,serverMode:t.serverMode,serverCacheEnabled:!0}:{local:!0,groupMode:"subcircuit"}}_shouldUseTraceByTraceRouting(){return this._getAutorouterConfig().groupMode==="sequential-trace"}doInitialPcbDesignRuleChecks(){var n;if((n=this.root)!=null&&n.pcbDisabled||this.getInheritedProperty("routingDisabled"))return;const{db:t}=this.root;if(this.isSubcircuit){const i=new Map;for(const a of this.children)if(!a.isSubcircuit&&a._parsedProps.name){const o=i.get(a._parsedProps.name)||[];o.push(a),i.set(a._parsedProps.name,o)}for(const[a,o]of i.entries())o.length>1&&t.pcb_trace_error.insert({error_type:"pcb_trace_error",message:`Multiple components found with name "${a}" in subcircuit "${this._parsedProps.name||"unnamed"}". Component names must be unique within a subcircuit.`,source_trace_id:"",pcb_trace_id:"",pcb_component_ids:o.map(s=>s.pcb_component_id).filter(Boolean),pcb_port_ids:[]})}}},Odt=class extends XG{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:pG}}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:n}=this;if(n.width&&n.height)return;let i=1/0,a=1/0,o=-1/0,s=-1/0;const l=t.pcb_component.list();let c=!1;for(const w of l){const{width:S,height:b,center:E}=w;S===0||b===0||(c=!0,i=Math.min(i,E.x-S/2),a=Math.min(a,E.y-b/2),o=Math.max(o,E.x+S/2),s=Math.max(s,E.y+b/2))}const u=2,f=c?o-i+u*2:0,d=c?s-a+u*2:0,m={x:c?(i+o)/2+(n.outlineOffsetX??0):n.outlineOffsetX??0,y:c?(a+s)/2+(n.outlineOffsetY??0):n.outlineOffsetY??0};t.pcb_board.update(this.pcb_board_id,{width:f,height:d,center:m})}doInitialPcbComponentRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this;let i=n.width??0,a=n.height??0;if(n.outline){const c=n.outline.map(w=>w.x),u=n.outline.map(w=>w.y),f=Math.min(...c),d=Math.max(...c),m=Math.min(...u),y=Math.max(...u);i=d-f,a=y-m}const o=t.pcb_board.insert({center:{x:(n.pcbX??0)+(n.outlineOffsetX??0),y:(n.pcbY??0)+(n.outlineOffsetY??0)},thickness:this.boardThickness,num_layers:this.allLayers.length,width:i,height:a,outline:(l=n.outline)==null?void 0:l.map(c=>({x:c.x+(n.outlineOffsetX??0),y:c.y+(n.outlineOffsetY??0)})),material:n.material});this.pcb_board_id=o.pcb_board_id}removePcbComponentRender(){const{db:t}=this.root;this.pcb_board_id&&(t.pcb_board.delete(this.pcb_board_id),this.pcb_board_id=null)}_computePcbGlobalTransformBeforeLayout(){return ev()}doInitialPcbDesignRuleChecks(){var t;(t=this.root)!=null&&t.pcbDisabled||this.getInheritedProperty("routingDisabled")||super.doInitialPcbDesignRuleChecks()}updatePcbDesignRuleChecks(){var i;if((i=this.root)!=null&&i.pcbDisabled||this.getInheritedProperty("routingDisabled"))return;const{db:t}=this.root;if(!this._areChildSubcircuitsRouted()||this._drcChecksComplete)return;this._drcChecksComplete=!0;const n=Sge(t.toArray());for(const a of n)t.pcb_trace_error.insert(a)}_emitRenderLifecycleEvent(t,n){var i;super._emitRenderLifecycleEvent(t,n),n==="start"&&((i=this.root)==null||i.emit("board:renderPhaseStarted",{renderId:this._renderId,phase:t}))}},zdt=new Proxy({},{get:(r,e)=>e}),vC=zdt,Udt=class extends Jx{get config(){return{componentName:"Capacitor",schematicSymbolName:this.props.polarized?"capacitor_polarized":this.props.symbolName??"capacitor",zodProps:lye,sourceFtype:vC.simple_capacitor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){const e=`${P3(this._parsedProps.capacitance)}F`;return this._parsedProps.schShowRatings&&this._parsedProps.maxVoltageRating?`${e}/${P3(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 a8({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.decouplingFor})),this.add(new a8({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.decouplingTo}))),this._createTracesFromConnectionsProp()}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_capacitor",name:t.name,manufacturer_part_number:t.manufacturerPartNumber??t.mfn,supplier_part_numbers:t.supplierPartNumbers,capacitance:t.capacitance,max_voltage_rating:t.maxVoltageRating,max_decoupling_trace_length:t.maxDecouplingTraceLength,display_capacitance:this._getSchematicSymbolDisplayValue(),are_pins_interchangeable:!t.polarized});this.source_component_id=n.source_component_id}},qge=class extends Jx{constructor(){super(...arguments);Je(this,"schematicBoxDimensions",null)}get config(){return{componentName:"Chip",zodProps:hG,shouldRenderAsSchematicBox:!0}}doInitialSchematicComponentRender(){const{_parsedProps:t}=this;(t==null?void 0:t.noSchematicRepresentation)!==!0&&super.doInitialSchematicComponentRender()}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_chip",name:n.name,manufacturer_part_number:n.manufacturerPartNumber,supplier_part_numbers:n.supplierPartNumbers});this.source_component_id=i.source_component_id}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=t.pcb_component.insert({center:{x:n.pcbX??0,y:n.pcbY??0},width:2,height:3,layer:n.layer??"top",rotation:n.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.pcb_component_id=i.pcb_component_id}doInitialCreateTracesFromProps(){const{_parsedProps:t}=this;if(t.externallyConnectedPins)for(const[n,i]of t.externallyConnectedPins)this.add(new a8({from:`${this.getSubcircuitSelector()} > port.${n}`,to:`${this.getSubcircuitSelector()} > port.${i}`}));this._createTracesFromConnectionsProp()}},kdt=class extends Jx{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:Sye,sourceFtype:"simple_diode"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_diode",name:n.name,manufacturer_part_number:n.manufacturerPartNumber??n.mfn,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},Idt=class extends Jx{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 n=Array.from(new Set(this.props.internallyConnectedPins.flat())).sort().join("");t+=`_bridged${n}`}return{schematicSymbolName:t,componentName:"Jumper",zodProps:tye,shouldRenderAsSchematicBox:!0}}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_chip",name:n.name,manufacturer_part_number:n.manufacturerPartNumber,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=i.source_component_id}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=t.pcb_component.insert({center:{x:n.pcbX??0,y:n.pcbY??0},width:2,height:3,layer:n.layer??"top",rotation:n.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.pcb_component_id=i.pcb_component_id}doInitialPcbTraceRender(){const{db:t}=this.root,n=t.pcb_port.list({pcb_component_id:this.pcb_component_id}),i={};for(let s=0;s<n.length;s++){const l=n[s],c=t.source_port.get(l.source_port_id);let 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 f=c.port_hints.find(d=>/^(pin)?\d+$/.test(d));f&&(/^pin\d+$/.test(f)?u=f.replace(/^pin/,""):u=f)}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))}},Fdt=class extends Jx{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:wye,sourceFtype:"simple_diode"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_diode",name:n.name,manufacturer_part_number:n.manufacturerPartNumber??n.mfn,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},Bdt=class extends Jx{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:Aye,sourceFtype:"simple_power_source"}}initPorts(){this.add(new US({name:"pin1",pinNumber:1,aliases:["positive","pos"]})),this.add(new US({name:"pin2",pinNumber:2,aliases:["negative","neg"]}))}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_power_source",name:n.name,voltage:n.voltage,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},jdt=class extends Jx{get config(){return{componentName:"Resistor",schematicSymbolName:this.props.symbolName??"boxresistor",zodProps:iye,sourceFtype:"simple_resistor"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${P3(this._parsedProps.resistance)}Ω`}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.pullupFor,this.props.pullupTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.pullupFor&&this.props.pullupTo&&(this.add(new a8({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pullupFor})),this.add(new a8({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pullupTo}))),this._createTracesFromConnectionsProp()}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_resistor",name:t.name,manufacturer_part_number:t.manufacturerPartNumber??t.mfn,supplier_part_numbers:t.supplierPartNumbers,resistance:t.resistance,display_resistance:this._getSchematicSymbolDisplayValue(),are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}},Hdt=["leftedge","rightedge","topedge","bottomedge","center"],Vdt=class extends N_{get config(){return{componentName:"Constraint",zodProps:cye}}constructor(e){if(super(e),("xdist"in e||"ydist"in e)&&!("edgeToEdge"in e)&&!("centerToCenter"in e))throw new Error(`edgeToEdge, centerToCenter must be set for xDist or yDist for ${this}`);if("for"in e&&e.for.length<2)throw new Error(`"for" must have at least two selectors for ${this}`)}_getAllReferencedComponents(){const e=[],t=this.getPrimitiveContainer();function n(i){const a=i.split(" ").pop(),o=Hdt.includes(a)?a:void 0,s=o?i.replace(` ${o}`,""):i,l=t.selectOne(s,{pcbPrimitive:!0});l&&e.push({selector:i,component:l,componentSelector:s,edge:o})}for(const i of["left","right","top","bottom"])i in this._parsedProps&&n(this._parsedProps[i]);if("for"in this._parsedProps)for(const i of this._parsedProps.for)n(i);return{componentsWithSelectors:e}}},Gdt=class extends N_{constructor(){super(...arguments);Je(this,"fabrication_note_path_id",null)}get config(){return{componentName:"FabricationNotePath",zodProps:Mye}}doInitialPcbPrimitiveRender(){var l,c;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,n=this.getSubcircuit(),{_parsedProps:i}=this,a=i.layer??"top";if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenPath. Must be "top" or "bottom".`);const o=this._computePcbGlobalTransformBeforeLayout(),s=t.pcb_fabrication_note_path.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,color:i.color,route:i.route.map(u=>{const f=kr(o,{x:u.x,y:u.y});return{...u,x:f.x,y:f.y}}),stroke_width:i.strokeWidth??.1,subcircuit_id:(n==null?void 0:n.subcircuit_id)??void 0});this.fabrication_note_path_id=s.pcb_fabrication_note_path_id}},qdt=class extends N_{get config(){return{componentName:"FabricationNoteText",zodProps:Tye}}doInitialPcbPrimitiveRender(){var a,o;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=this.getPrimitiveContainer(),i=this.getSubcircuit();e.pcb_fabrication_note_text.insert({anchor_alignment:t.anchorAlignment,anchor_position:{x:t.pcbX??0,y:t.pcbY??0},font:t.font??"tscircuit2024",font_size:t.fontSize??1,layer:"top",color:t.color,text:t.text??"",pcb_component_id:n.pcb_component_id,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((o=this.getGroup())==null?void 0:o.pcb_group_id)??void 0})}},$dt=class extends XG{constructor(e){super({...e,subcircuit:!0})}},Ydt=class extends N_{constructor(){super(...arguments);Je(this,"source_net_alias_id")}get config(){return{componentName:"NetAlias",zodProps:yye}}doInitialSchematicComponentRender(){var o;if((o=this.root)!=null&&o.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i={x:n.schX??0,y:n.schY??0},a=t.schematic_net_label.insert({text:n.net,source_net_id:n.net,anchor_position:i,center:i,anchor_side:"bottom"});this.source_net_alias_id=a.source_net_id}},Xdt=class extends N_{constructor(){super(...arguments);Je(this,"pcb_silkscreen_circle_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenCircle",zodProps:zye}}doInitialPcbPrimitiveRender(){var l,c,u;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(n.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenCircle. Must be "top" or "bottom".`);this._computePcbGlobalTransformBeforeLayout();const o=this.getSubcircuit(),s=t.pcb_silkscreen_circle.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,center:{x:n.pcbX??0,y:n.pcbY??0},radius:n.radius,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((u=this.getGroup())==null?void 0:u.pcb_group_id)??void 0,stroke_width:n.strokeWidth??.1});this.pcb_silkscreen_circle_id=s.pcb_silkscreen_circle_id}getPcbSize(){const{_parsedProps:t}=this,n=t.radius*2;return{width:n,height:n}}},Wdt=class extends N_{constructor(){super(...arguments);Je(this,"pcb_silkscreen_rect_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenRect",zodProps:Oye}}doInitialPcbPrimitiveRender(){var l,c,u;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(n.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenRect. Must be "top" or "bottom".`);const o=this.getSubcircuit(),s=t.pcb_silkscreen_rect.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,center:{x:n.pcbX??0,y:n.pcbY??0},width:n.width,height:n.height,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((u=this==null?void 0:this.getGroup())==null?void 0:u.pcb_group_id)??void 0,stroke_width:n.strokeWidth??.1});this.pcb_silkscreen_rect_id=s.pcb_silkscreen_rect_id}getPcbSize(){const{_parsedProps:t}=this;return{width:t.width,height:t.height}}},Zdt=class extends N_{constructor(){super(...arguments);Je(this,"pcb_silkscreen_line_id",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenLine",zodProps:Lye}}doInitialPcbPrimitiveRender(){var l,c,u;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),a=i(n.layer??"top");if(a!=="top"&&a!=="bottom")throw new Error(`Invalid layer "${a}" for SilkscreenLine. Must be "top" or "bottom".`);const o=this.getSubcircuit(),s=t.pcb_silkscreen_line.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:a,x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2,stroke_width:n.strokeWidth??.1,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((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,n=Math.abs(t.x2-t.x1),i=Math.abs(t.y2-t.y1);return{width:n,height:i}}},Qdt=class extends N_{constructor(){super(...arguments);Je(this,"pcb_via_id",null);Je(this,"matchedPort",null);Je(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Via",zodProps:Cye}}getAvailablePcbLayers(){return["top","inner1","inner2","bottom"]}getPcbSize(){const{_parsedProps:t}=this;return{width:t.outerDiameter,height:t.outerDiameter}}_getPcbCircuitJsonBounds(){const{db:t}=this.root,n=t.pcb_via.get(this.pcb_via_id),i=this.getPcbSize();return{center:{x:n.x,y:n.y},bounds:{left:n.x-i.width/2,top:n.y-i.height/2,right:n.x+i.width/2,bottom:n.y+i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(t){const{db:n}=this.root;n.pcb_via.update(this.pcb_via_id,{x:t.x,y:t.y})}doInitialPcbPrimitiveRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalPcbPositionBeforeLayout(),a=this.getSubcircuit(),o=t.pcb_via.insert({x:i.x,y:i.y,hole_diameter:n.holeDiameter,outer_diameter:n.outerDiameter,layers:["bottom","top"],from_layer:n.fromLayer||"bottom",to_layer:n.toLayer||"top",subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((l=this.getGroup())==null?void 0:l.pcb_group_id)??void 0});this.pcb_via_id=o.pcb_via_id}},Kdt=class extends Jx{get config(){return{componentName:"Battery",schematicSymbolName:this.props.symbolName??"battery",zodProps:mye,sourceFtype:"simple_power_source"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:t.name,ftype:"simple_power_source",capacity:t.capacity,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=n.source_component_id}},Jdt=class extends Jx{get config(){return{componentName:"PinHeader",zodProps:vye,shouldRenderAsSchematicBox:!0}}_getImpliedFootprintString(){var a;const e=this._parsedProps.pinCount??((a=this._parsedProps.pinLabels)==null?void 0:a.length)??0,t=this._parsedProps.holeDiameter,n=this._parsedProps.platedDiameter,i=this._parsedProps.pitch;return e>0&&i?!t&&!n?`pinrow${e}_p${i}`:`pinrow${e}_p${i}_id${t}_od${n}`:null}initPorts(){var t,n;const e=this._parsedProps.pinCount??((t=this._parsedProps.pinLabels)==null?void 0:t.length)??1;for(let i=1;i<=e;i++)this.add(new US({name:`pin${i}`,pinNumber:i,aliases:[(n=this._parsedProps.pinLabels)==null?void 0:n[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,n=e.source_component.insert({ftype:"simple_pin_header",name:t.name,supplier_part_numbers:t.supplierPartNumbers,pin_count:t.pinCount,gender:t.gender,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}};function ept(r){switch(r){case"two_ground_pins":return"crystal_4pin";case"ground_pin":return"resonator";case"no_ground":return"crystal";default:return"crystal"}}var tpt=class extends Jx{get config(){return{componentName:"Resonator",schematicSymbolName:this.props.symbolName??ept(this.props.pinVariant),zodProps:sye,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=t.pinVariant||"no_ground",i=e.source_component.insert({ftype:"simple_resonator",name:t.name,frequency:t.frequency,load_capacitance:t.loadCapacitance,supplier_part_numbers:t.supplierPartNumbers,pin_variant:n,are_pins_interchangeable:n==="no_ground"||n==="ground_pin"});this.source_component_id=i.source_component_id}},npt=class extends Jx{get config(){return{componentName:"Inductor",schematicSymbolName:this.props.symbolName??"inductor",zodProps:bye,sourceFtype:vC.simple_inductor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:t.name,ftype:vC.simple_inductor,inductance:t.inductance,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}};function rpt(r){switch(r){case"three_pin":return"potentiometer3";case"two_pin":return"potentiometer2";default:return"potentiometer2"}}var ipt=class extends Jx{get config(){return{componentName:"Potentiometer",schematicSymbolName:this.props.symbolName??rpt(this.props.pinVariant),zodProps:aye,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=t.pinVariant||"two_pin",i=e.source_component.insert({ftype:"simple_potentiometer",name:t.name,max_resistance:t.maxResistance,pin_variant:n,are_pins_interchangeable:n==="two_pin"});this.source_component_id=i.source_component_id}},apt=class extends Jx{get config(){return{componentName:"PushButton",schematicSymbolName:this.props.symbolName??"push_button_normally_open_momentary",zodProps:gye,sourceFtype:vC.simple_push_button}}get defaultInternallyConnectedPinNames(){return[["pin1","pin4"],["pin2","pin3"]]}initPorts(){super.initPorts({pinCount:4,additionalAliases:{pin1:["side1"],pin3:["side2"]}})}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:t.name,ftype:vC.simple_push_button,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}},opt=class extends Jx{get config(){return{schematicSymbolName:this.props.symbolName??(this.props.pinVariant==="four_pin"?"crystal_4pin":"crystal"),componentName:"Crystal",zodProps:oye,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`${P3(this._parsedProps.frequency)}Hz`}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:t.name,ftype:"simple_crystal",frequency:t.frequency,load_capacitance:t.loadCapacitance,pin_variant:t.pinVariant||"two_pin",are_pins_interchangeable:(t.pinVariant||"two_pin")==="two_pin"});this.source_component_id=n.source_component_id}},spt=class extends Jx{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:_ye,sourceFtype:"simple_transistor",shouldRenderAsSchematicBox:!1}}initPorts(){const t=this.props.type==="npn"?{pin1:["emitter","e"],pin2:["collector","c"],pin3:["base","b"]}:{pin1:["collector","c"],pin2:["emitter","e"],pin3:["base","b"]};super.initPorts({pinCount:3,additionalAliases:t})}doInitialSourceRender(){const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_transistor",name:n.name,transistor_type:n.type});this.source_component_id=i.source_component_id}},lpt=class extends Jx{get config(){const e=this.props.mosfetMode==="depletion"?"d":"e";return{componentName:"Mosfet",schematicSymbolName:`${this.props.channelType}_channel_${e}_mosfet_transistor`,zodProps:xye,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_mosfet",name:t.name,mosfet_mode:t.mosfetMode,channel_type:t.channelType});this.source_component_id=n.source_component_id}},cpt=class extends Jx{_getSwitchType(){const{spst:e,spdt:t,dpst:n,dpdt:i,type:a}=this._parsedProps??{};return i?"dpdt":e?"spst":t?"spdt":n?"dpst":a??"spst"}get config(){const e=this._getSwitchType(),{isNormallyClosed:t}=this._parsedProps??{};return{componentName:"Switch",schematicSymbolName:{spst:t?"spst_normally_closed_switch":"spst_switch",spdt:t?"spdt_normally_closed_switch":"spdt_switch",dpst:t?"dpst_normally_closed_switch":"dpst_switch",dpdt:t?"dpdt_normally_closed_switch":"dpdt_switch"}[e]??"spst_switch",zodProps:Eye,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_switch",name:t.name,switch_type:t.type,is_normally_closed:t.isNormallyClosed??!1,are_pins_interchangeable:this._getSwitchType()==="spst"});this.source_component_id=n.source_component_id}},upt=class extends N_{constructor(){super(...arguments);Je(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicText",zodProps:Pye}}doInitialSchematicPrimitiveRender(){var i;if((i=this.root)!=null&&i.schematicDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this;t.schematic_text.insert({anchor:n.anchor??"center",text:n.text,font_size:n.fontSize,color:n.color||"#000000",position:{x:n.schX,y:n.schY},rotation:n.schRotation??0})}};new Proxy({},{get:(r,e)=>{const t=(...n)=>(n[0],new Proxy({},{get:(i,a)=>`.${e} > .${a}`}));return new Proxy(t,{get:(n,i)=>e==="net"?`net.${i}`:e==="subcircuit"?new Proxy({},{get:(a,o)=>new Proxy({},{get:(s,l)=>`subcircuit.${i} > .${o} > .${l}`})}):`.${e} > .${i}`,apply:(n,i,a)=>new Proxy({},{get:(o,s)=>{const l=`.${e} > .${s}`;return e.startsWith("U")?l:new Proxy(new String(l),{get:(c,u)=>typeof u=="symbol"||u==="toString"?()=>l:`.${e} > .${s} > .${u}`})}})})}}),Tge(wge),Tge({Bug:qge});const $ge=Jm("run-frame"),fpt={},Yge=r=>{let e;const t=new Set,n=(u,f)=>{const d=typeof u=="function"?u(e):u;if(!Object.is(d,e)){const m=e;e=f??(typeof d!="object"||d===null)?d:Object.assign({},e,d),t.forEach(y=>y(e,m))}},i=()=>e,l={setState:n,getState:i,getInitialState:()=>c,subscribe:u=>(t.add(u),()=>t.delete(u)),destroy:()=>{(fpt?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),t.clear()}},c=e=r(n,i,l);return l},Xge=r=>r?Yge(r):Yge;var RL={exports:{}},WG={},AL={exports:{}},ZG={};/**
|
|
831
831
|
* @license React
|
|
832
832
|
* use-sync-external-store-shim.production.js
|
|
@@ -13451,7 +13451,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}return yce}ctn();function Qje(r,e,t,n=
|
|
|
13451
13451
|
&:hover {
|
|
13452
13452
|
background-color: rgba(255, 255, 255, 0.1);
|
|
13453
13453
|
}
|
|
13454
|
-
`,onClick:n=>{n.stopPropagation(),t()},children:[Ge.jsx("input",{type:"checkbox",checked:e}),Ge.jsx("span",{style:{color:"#eee"},children:r})]}),Din=({children:r,elements:e})=>{const[t,n]=Ox($=>[$.is_mouse_over_container,$.setIsMouseOverContainer]),[i,a]=rt.useState(!1),[o,s]=rt.useState(!1),[l,c]=rt.useState(!1),[u,f]=Ox($=>[$.selected_layer,$.selectLayer]),[d,m,y,w,S,b]=Ox($=>[$.in_move_footprint_mode,$.in_draw_trace_mode,$.is_showing_rats_nest,$.is_showing_multiple_traces_length,$.is_showing_autorouting,$.is_showing_drc_errors]),E=Ox($=>$.setEditMode),P=Ox($=>$.setIsShowingRatsNest),U=Ox($=>$.setIsShowingMultipleTracesLength),V=Ox($=>$.setIsShowingAutorouting),Y=Ox($=>$.setIsShowingDrcErrors);DE("1",()=>f("top")),DE("2",()=>f("bottom")),DE("3",()=>f("inner1")),DE("4",()=>f("inner2")),DE("5",()=>f("inner3")),DE("6",()=>f("inner4")),DE("7",()=>f("inner5")),DE("8",()=>f("inner6"));const W=(e==null?void 0:e.filter($=>$.type.includes("error")).length)??0;return Ge.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>{n(!0)},onMouseLeave:$=>{n(!1),s(!1)},children:[r,Ge.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@",Pin.version]}),Ge.jsxs("div",{style:{position:"absolute",opacity:t?1:0,top:16,left:16,transition:t?"opacity 100ms linear":"opacity 1s linear",zIndex:n5.toolbarOverlay,color:"red",display:"flex",fontSize:12,height:100,fontFamily:"sans-serif"},children:[Ge.jsxs(u7,{onClick:()=>{s(!o)},onMouseLeave:()=>{o&&s(!1)},children:[Ge.jsxs("div",{children:["layer:"," ",Ge.jsx("span",{style:{marginLeft:2,fontWeight:500,color:c7[u]},children:u})]}),o&&Ge.jsx("div",{style:{marginTop:4,minWidth:120},children:Kce.map($=>$.replace(/-/g,"")).map($=>Ge.jsx(Nin,{name:$,selected:$===u,onClick:()=>{f($.replace(/-/,""))}},$))})]}),Ge.jsxs(u7,{style:W>0?{color:"red"}:{},onClick:()=>c(!l),onMouseLeave:()=>c(!1),children:[Ge.jsxs("div",{children:[W," errors"]}),l&&Ge.jsx("div",{style:{display:"grid",gridTemplateColumns:"100px 300px"},children:e==null?void 0:e.filter($=>$.type.includes("error")).map(($,K)=>Ge.jsxs(rt.Fragment,{children:[Ge.jsx("div",{children:$.error_type}),Ge.jsx("div",{children:$.message})]},K))})]}),Ge.jsx(u7,{style:{},onClick:()=>{E(m?"off":"draw_trace")},children:Ge.jsxs("div",{children:[m?"✖ ":"","Edit Traces"]})}),Ge.jsx(u7,{style:{},onClick:()=>{E(d?"off":"move_footprint")},children:Ge.jsxs("div",{children:[d?"✖ ":"","Move Components"]})}),Ge.jsx(u7,{style:{},onClick:()=>{P(!y)},children:Ge.jsxs("div",{children:[y?"✖ ":"","Rats Nest"]})}),Ge.jsx(u7,{onClick:()=>{a(!i)},children:Ge.jsxs("div",{children:[Ge.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:["View"," ",Ge.jsx("span",{style:{fontSize:"8px",transform:i?"rotate(180deg)":"rotate(0)",transition:"transform 0.1s ease",display:"inline-block"},children:"▼"})]}),i&&Ge.jsxs("div",{style:{marginTop:4,minWidth:120},children:[Ge.jsx(rue,{label:"Show All Trace Lengths",checked:w,onClick:()=>{U(!w)}}),Ge.jsx(rue,{label:"Show Autorouting Animation",checked:S,onClick:()=>{V(!S)}}),Ge.jsx(rue,{label:"Show DRC Errors",checked:b,onClick:()=>{Y(!b)}})]})]})})]})]})},Lin=r=>{const{transform:e,elements:t}=r,[n,i]=rt.useMemo(()=>{const c=r.elements.flatMap(f=>Grn(f,r.elements)),u=n4(r.elements);return[c,u]},[r.elements]),[a,o]=rt.useState({drawingObjectIdsWithMouseOver:new Set,primitiveIdsInMousedOverNet:[]}),s=rt.useMemo(()=>jrn({primitivesWithoutInteractionMetadata:n,drawingObjectIdsWithMouseOver:a.drawingObjectIdsWithMouseOver,primitiveIdsInMousedOverNet:a.primitiveIdsInMousedOverNet}),[n,a]),l=rt.useCallback(c=>{var d,m;const u=[];for(const y of c)if(y._element){const w=i.getNetConnectedToId("pcb_port_id"in y._element?(d=y._element)==null?void 0:d.pcb_port_id:"pcb_trace_id"in y._element?(m=y._element)==null?void 0:m.pcb_trace_id:"");u.push(...i.getIdsConnectedToNet(w))}const f=new Set(c.map(y=>y._pcb_drawing_object_id));o({drawingObjectIdsWithMouseOver:f,primitiveIdsInMousedOverNet:u})},[i]);return Ge.jsx(Rin,{elements:t,transform:e,primitives:n,onMouseHoverOverPrimitives:l,children:Ge.jsx(fin,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:Ge.jsx(min,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:Ge.jsx(cin,{transform:e,focusOnHover:r.focusOnHover,children:Ge.jsx(Din,{elements:t,children:Ge.jsx(gin,{transform:e,elements:t,children:Ge.jsx(Ain,{transform:e,soup:t,children:Ge.jsx(sin,{transform:e,debugGraphics:r.debugGraphics,children:Ge.jsx(lin,{transform:e,elements:t,children:Ge.jsx(oin,{transform:e,primitives:s,width:r.width,height:r.height,grid:r.grid})})})})})})})})})})},Oin=wc(zf(400,300),Zx(40,-40)),zin=({circuitJson:r,debugGraphics:e,height:t=600,initialState:n,allowEditing:i=!0,editEvents:a,onEditEventsChanged:o,focusOnHover:s=!1,clickToInteractEnabled:l=!1})=>{const[c,u]=rt.useState(!l),[f,d]=tue(),[m,y]=rt.useState(Oin),{ref:w,setTransform:S,cancelDrag:b}=Brn({transform:m,onSetTransform:y,enabled:c});let[E,P]=rt.useState([]);E=a??E;const U=rt.useRef(!1),V=rt.useRef(null),Y=`${(r==null?void 0:r.length)||0}_${(r==null?void 0:r.editCount)||0}`,W=()=>{const pe=(d==null?void 0:d.width)>0?d:{width:500,height:500},{center:ue,width:Se,height:he}=K.some(xe=>xe.type.startsWith("pcb_"))?Prn(K.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=wc(zf((pe.width??0)/2,(pe.height??0)/2),Zx(ge,-ge,0,0),zf(-ue.x,-ue.y));S(Te)};rt.useEffect(()=>{d!=null&&d.width&&r&&r.length!==0&&(U.current||(W(),U.current=!0))},[r,d]);const $=rt.useMemo(()=>(r==null?void 0:r.filter(pe=>pe.type.startsWith("pcb_")||pe.type.startsWith("source_")))??[],[Y]),K=rt.useMemo(()=>nen({circuitJson:$,editEvents:E}),[$,E]),X=pe=>{P([...E,pe]),o==null||o([...E,pe])},ce=pe=>{const ue=E.map(Se=>Se.edit_event_id===pe.edit_event_id?{...Se,...pe}:Se);P(ue),o==null||o(ue)};return Ge.jsxs("div",{ref:w,style:{position:"relative"},children:[Ge.jsx("div",{ref:f,children:Ge.jsxs(Drn,{initialState:n,children:[Ge.jsx(Lin,{transform:m,height:t,width:d.width,allowEditing:i,focusOnHover:s,cancelPanDrag:b,onCreateEditEvent:X,onModifyEditEvent:ce,grid:{spacing:1,view_window:{left:0,right:d.width||500,top:t,bottom:0}},elements:K,debugGraphics:e},d.width),Ge.jsx(Orn,{})]})}),l&&!c&&Ge.jsx("div",{onClick:()=>{u(!0),W()},onTouchStart:pe=>{const ue=pe.touches[0];V.current={x:ue.clientX,y:ue.clientY}},onTouchEnd:pe=>{const ue=pe.changedTouches[0],Se=V.current;if(!Se)return;const he=Math.abs(ue.clientX-Se.x),ge=Math.abs(ue.clientY-Se.y);he<10&&ge<10&&(pe.preventDefault(),u(!0),W()),V.current=null},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:n5.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center",touchAction:"pan-x pan-y pinch-zoom"},children:Ge.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 Uin=({containerClassName:r,...e})=>{const t=rt.useRef(null),[n,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)}},[]),Ge.jsx("div",{ref:t,className:r||"rf-w-full rf-h-full",children:Ge.jsx(zin,{...e,height:n})})},kin='*,: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}',Iin=()=>{rt.useEffect(()=>{if(document.querySelector('style[data-styles="tscircuit-runframe"]'))return;const e=document.createElement("style");e.setAttribute("data-styles","tscircuit-runframe"),e.textContent=kin,document.head.appendChild(e)},[])},nGe=r=>`hsl(${U5.indexOf(r)*137.5%360}, 70%, 50%)`,Fin=({phaseTimings:r})=>{if(!r)return null;const e=Object.values(r).reduce((t,n)=>t+n,0);return Ge.jsxs("div",{className:"rf-space-y-2 rf-w-full rf-px-4",children:[Ge.jsx("div",{className:"rf-relative rf-h-8 rf-flex rf-rounded-sm",children:U5.map(t=>{const n=r[t]||0,i=n/e*100;return Ge.jsx("div",{className:"rf-group/bar rf-relative rf-overflow-visible",style:{width:`${i}%`,backgroundColor:nGe(t)},children:Ge.jsxs("div",{className:"rf-opacity-0 group-hover/bar:rf-opacity-100 rf-transition-opacity rf-absolute rf-bottom-full rf-left-1/2 rf-transform -rf-translate-x-1/2 rf-mb-2 rf-px-2 rf-py-1 rf-text-xs rf-whitespace-nowrap rf-rounded rf-bg-gray-900 rf-text-white rf-pointer-events-none",children:[t,": ",n.toFixed(1),"ms"]})},t)})}),Ge.jsxs("div",{className:"rf-text-xs rf-text-gray-500",children:["Total: ",e.toFixed(2),"ms"]})]})},Bin=({renderLog:r})=>{const[e,t]=rt.useState("chronological");if(!r)return Ge.jsx("div",{className:"rf-p-4 rf-bg-gray-100 rf-rounded-md",children:"No render log, make sure this tab is open when you render (TODO add a rerender button here)"});const n=Object.entries((r==null?void 0:r.phaseTimings)??{});e==="chronological"?n.sort((a,o)=>U5.indexOf(a[0])-U5.indexOf(o[0])):n.sort((a,o)=>o[1]-a[1]);const i=n.reduce((a,[o,s])=>a+s,0);return Ge.jsxs("div",{className:"rf-bg-white",children:[Ge.jsxs("div",{className:"rf-flex rf-justify-between rf-items-center",children:[Ge.jsx("div",{children:"Render Logs"}),Ge.jsxs("div",{className:"rf-mb-4 rf-pr-2 rf-flex rf-text-xs rf-items-center",children:[Ge.jsx("div",{className:"rf-mr-2",children:"Sort by:"}),Ge.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:[Ge.jsx("option",{value:"chronological",children:"Phase Order"}),Ge.jsx("option",{value:"longest",children:"Duration"})]})]})]}),Ge.jsx(Fin,{phaseTimings:r.phaseTimings}),Ge.jsxs("table",{className:"rf-w-full rf-text-xs",children:[Ge.jsx("thead",{children:Ge.jsxs("tr",{children:[Ge.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase Order"}),Ge.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase"}),Ge.jsx("th",{className:"rf-text-left rf-p-2",children:"Duration (ms)"})]})}),Ge.jsx("tbody",{children:n.map(([a,o])=>Ge.jsxs("tr",{children:[Ge.jsx("td",{className:"rf-p-2",children:U5.indexOf(a)}),Ge.jsx("td",{className:"rf-p-2",children:a}),Ge.jsx("td",{className:"rf-p-2",children:Ge.jsx("div",{className:"rf-w-8",children:Ge.jsx("div",{className:"rf-h-2 rf-rounded-sm",style:{backgroundColor:nGe(a),width:`${o/i*100}%`}})})}),Ge.jsx("td",{className:"rf-p-2",children:Ge.jsxs("div",{className:"rf-flex w-full",children:[Ge.jsxs("span",{className:"rf-flex-grow",children:[o,"ms"]}),Ge.jsxs("span",{className:"rf-text-gray-500 rf-pr-2",children:[(o/i*100).toFixed(1),"%"]})]})})]},a))})]})]})},jin="0.0.465",Hin=["assembly","bom","circuit_json","errors","render_log"],Vin=({code:r,onRunClicked:e=void 0,errorMessage:t,circuitJson:n,autoroutingGraphics:i,showRightHeaderContent:a=!0,showCodeTab:o=!1,codeTabContent:s,showJsonTab:l=!0,showRenderLogTab:c=!0,onActiveTabChange:u,renderLog:f,showImportAndFormatButtons:d=!0,className:m,headerClassName:y,leftHeaderContent:w,readOnly:S,isStreaming:b,autoroutingLog:E,onReportAutoroutingLog:P,isRunningCode:U,hasCodeChangedSinceLastRun:V,onEditEvent:Y,editEvents:W,defaultActiveTab:$,autoRotate3dViewerDisabled:K,showSchematicDebugGrid:X=!1,showToggleFullScreen:ce=!0,defaultToFullScreen:pe=!1})=>{var Ue;Iin();const ue=rt.useMemo(()=>n?n.filter(Re=>Re&&"error_type"in Re||Re.type.includes("error")):null,[n]),[Se,he]=rt.useState($??"pcb"),[ge,Te]=rt.useState(pe),xe=rt.useCallback(Re=>{he(Re),u==null||u(Re)},[u]),Pe=()=>{Te(!ge)};rt.useEffect(()=>{t&&xe("errors")},[t]),rt.useEffect(()=>{(Se==="code"||Se==="errors")&&n&&!t&&xe($??"pcb")},[n]);const De=rt.useCallback(Re=>{window.TSCIRCUIT_3D_OBJECT_REF=Re===null?void 0:Re},[]);return Ge.jsx("div",{className:v0("flex flex-col relative rf-overflow-x-hidden",m),children:Ge.jsx("div",{className:v0("rf-md:sticky rf-md:top-2",ge&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-bg-white"),children:Ge.jsxs(H_e,{value:Se,onValueChange:xe,className:"rf-flex-grow rf-flex rf-flex-col",children:[Ge.jsxs("div",{className:v0("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",y),children:[w,w&&Ge.jsx("div",{className:"rf-flex-grow"}),!w&&U&&Ge.jsx(jM,{className:"rf-w-4 rf-h-4 rf-animate-spin"}),!w&&Ge.jsx("div",{className:"rf-flex-grow"}),f&&f.progress!==1&&Ge.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[f.lastRenderEvent&&Ge.jsx("div",{className:"rf-text-xs rf-text-gray-500",children:((Ue=f.lastRenderEvent)==null?void 0:Ue.phase)??""}),Ge.jsx("div",{className:"rf-w-4 rf-h-4 rf-bg-blue-500 rf-opacity-50 rf-rounded-full rf-text-white",children:Ge.jsx(jM,{className:"rf-w-4 rf-h-4 rf-animate-spin"})}),Ge.jsxs("div",{className:"rf-text-xs rf-font-bold rf-text-gray-700 rf-tabular-nums",children:[((f.progress??0)*100).toFixed(1),"%"]})]}),a&&Ge.jsxs(pq,{children:[o&&Ge.jsx(Zw,{value:"code",children:"Code"}),Ge.jsxs(Zw,{value:"pcb",className:"rf-whitespace-nowrap",children:[n&&Ge.jsx("span",{className:v0("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",V?"rf-bg-gray-500":"rf-bg-blue-500")}),"PCB"]}),Ge.jsxs(Zw,{value:"schematic",className:"rf-whitespace-nowrap",children:[n&&Ge.jsx("span",{className:v0("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",V?"rf-bg-gray-500":"rf-bg-blue-500")}),"Schematic"]}),Ge.jsxs(Zw,{value:"cad",children:[n&&Ge.jsx("span",{className:v0("inline-flex items-center justify-center w-2 h-2 mr-1 text-xs font-bold text-white rounded-full",V?"rf-bg-gray-500":"rf-bg-blue-500")}),"3D"]}),!["pcb","cad","schematic"].includes(Se)&&Ge.jsx(Zw,{value:Se,children:j_e(Se)}),Ge.jsxs(fle,{children:[Ge.jsx(dle,{asChild:!0,children:Ge.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[Ge.jsx(DYt,{className:"rf-w-4 rf-h-4"}),(ue&&ue.length>0||t)&&Ge.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"})]})}),Ge.jsxs(UF,{className:"rf-*:text-xs",children:[Hin.map(Re=>Ge.jsxs(g4,{onSelect:()=>xe(Re),children:[Se!==Re&&Ge.jsx(Kke,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),Se===Re&&Ge.jsx(_se,{className:"rf-w-3 rf-h-3"}),Ge.jsx("div",{className:"rf-pr-2",children:j_e(Re)}),Re==="errors"&&(ue&&ue.length>0||t)&&Ge.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:ue==null?void 0:ue.length})]},Re)),Ge.jsx(g4,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:Ge.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/runframe@",jin.split(".").map((Re,$e)=>$e===2?parseInt(Re)+1:Re).join(".")]})})]})]})]}),ce&&Ge.jsx(T2,{onClick:Pe,variant:"ghost",children:ge?Ge.jsx(UYt,{size:16}):Ge.jsx(OYt,{size:16})})]}),o&&Ge.jsx(G4,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:Ge.jsx("div",{className:"rf-h-full",children:s})}),Ge.jsx(G4,{value:"pcb",children:Ge.jsx("div",{className:v0("rf-overflow-hidden",ge?"rf-h-[calc(100vh-52px)]":"rf-h-[620px]"),children:Ge.jsx(BM,{fallbackRender:({error:Re})=>Ge.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ge.jsxs("div",{className:"rf-p-4",children:[Ge.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading PCB viewer"}),Ge.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Re==null?void 0:Re.message)||"An unknown error occurred"})]})}),children:n?Ge.jsx(Uin,{focusOnHover:!1,circuitJson:n,debugGraphics:i,containerClassName:v0("rf-h-full rf-w-full",ge?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:Re=>{Y&&Re.forEach($e=>Y($e))}}):Ge.jsx(g6,{onRunClicked:e})})})}),Ge.jsx(G4,{value:"assembly",children:Ge.jsx("div",{className:v0("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(BM,{fallback:Ge.jsx("div",{children:"Error loading Assembly"}),children:n?Ge.jsx(nJt,{circuitJson:n,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):Ge.jsx(g6,{onRunClicked:e})})})}),Ge.jsx(G4,{value:"schematic",children:Ge.jsx("div",{className:v0("rf-overflow-auto rf-bg-white",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(BM,{fallbackRender:({error:Re})=>Ge.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ge.jsxs("div",{className:"rf-p-4",children:[Ge.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Schematic"}),Ge.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Re==null?void 0:Re.message)||"An unknown error occurred"})]})}),children:n?Ge.jsx(JKt,{circuitJson:n,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:Re=>{Y==null||Y(Re)},debugGrid:X,colorOverrides:{schematic:{background:"transparent"}}}):Ge.jsx(g6,{onRunClicked:e})})})}),Ge.jsx(G4,{value:"cad",children:Ge.jsx("div",{className:v0("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(BM,{FallbackComponent:_Yt,children:n?Ge.jsx(yYt,{ref:De,circuitJson:n,autoRotateDisabled:K}):Ge.jsx(g6,{onRunClicked:e})})})}),Ge.jsx(G4,{value:"bom",children:Ge.jsx("div",{className:v0("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(BM,{fallbackRender:({error:Re})=>Ge.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ge.jsxs("div",{className:"rf-p-4",children:[Ge.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Bill of Materials"}),Ge.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Re==null?void 0:Re.message)||"An unknown error occurred"})]})}),children:n?Ge.jsx(sJt,{circuitJson:n}):Ge.jsx(g6,{onRunClicked:e})})})}),Ge.jsx(G4,{value:"circuit_json",children:Ge.jsx("div",{className:v0("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(BM,{fallback:Ge.jsx("div",{children:"Error loading JSON viewer"}),children:n?Ge.jsx(aJt,{elements:n}):Ge.jsx(g6,{onRunClicked:e})})})}),Ge.jsx(G4,{value:"errors",children:Ge.jsx("div",{className:v0("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:n?Ge.jsx(PQt,{code:r,circuitJsonErrors:ue,errorMessage:t,autoroutingLog:E,onReportAutoroutingLog:P}):Ge.jsx(g6,{onRunClicked:e})})}),c&&Ge.jsx(G4,{value:"render_log",children:Ge.jsx(Bin,{renderLog:f})})]})})})};var AB="Dialog",[rGe,iGe]=IS(AB),[Gin,S4]=rGe(AB),aGe=r=>{const{__scopeDialog:e,children:t,open:n,defaultOpen:i,onOpenChange:a,modal:o=!0}=r,s=rt.useRef(null),l=rt.useRef(null),[c,u]=xT({prop:n,defaultProp:i??!1,onChange:a,caller:AB});return Ge.jsx(Gin,{scope:e,triggerRef:s,contentRef:l,contentId:FS(),titleId:FS(),descriptionId:FS(),open:c,onOpenChange:u,onOpenToggle:rt.useCallback(()=>u(f=>!f),[u]),modal:o,children:t})};aGe.displayName=AB;var oGe="DialogTrigger",sGe=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=S4(oGe,t),a=R9(e,i.triggerRef);return Ge.jsx(xg.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":oue(i.open),...n,ref:a,onClick:Ch(r.onClick,i.onOpenToggle)})});sGe.displayName=oGe;var iue="DialogPortal",[qin,lGe]=rGe(iue,{forceMount:void 0}),cGe=r=>{const{__scopeDialog:e,forceMount:t,children:n,container:i}=r,a=S4(iue,e);return Ge.jsx(qin,{scope:e,forceMount:t,children:rt.Children.map(n,o=>Ge.jsx(H4,{present:t||a.open,children:Ge.jsx(Wse,{asChild:!0,container:i,children:o})}))})};cGe.displayName=iue;var PB="DialogOverlay",uGe=rt.forwardRef((r,e)=>{const t=lGe(PB,r.__scopeDialog),{forceMount:n=t.forceMount,...i}=r,a=S4(PB,r.__scopeDialog);return a.modal?Ge.jsx(H4,{present:n||a.open,children:Ge.jsx(Yin,{...i,ref:e})}):null});uGe.displayName=PB;var $in=_T("DialogOverlay.RemoveScroll"),Yin=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=S4(PB,t);return Ge.jsx(tle,{as:$in,allowPinchZoom:!0,shards:[i.contentRef],children:Ge.jsx(xg.div,{"data-state":oue(i.open),...n,ref:e,style:{pointerEvents:"auto",...n.style}})})}),R6="DialogContent",fGe=rt.forwardRef((r,e)=>{const t=lGe(R6,r.__scopeDialog),{forceMount:n=t.forceMount,...i}=r,a=S4(R6,r.__scopeDialog);return Ge.jsx(H4,{present:n||a.open,children:a.modal?Ge.jsx(Xin,{...i,ref:e}):Ge.jsx(Win,{...i,ref:e})})});fGe.displayName=R6;var Xin=rt.forwardRef((r,e)=>{const t=S4(R6,r.__scopeDialog),n=rt.useRef(null),i=R9(e,t.contentRef,n);return rt.useEffect(()=>{const a=n.current;if(a)return rFe(a)},[]),Ge.jsx(dGe,{...r,ref:i,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ch(r.onCloseAutoFocus,a=>{var o;a.preventDefault(),(o=t.triggerRef.current)==null||o.focus()}),onPointerDownOutside:Ch(r.onPointerDownOutside,a=>{const o=a.detail.originalEvent,s=o.button===0&&o.ctrlKey===!0;(o.button===2||s)&&a.preventDefault()}),onFocusOutside:Ch(r.onFocusOutside,a=>a.preventDefault())})}),Win=rt.forwardRef((r,e)=>{const t=S4(R6,r.__scopeDialog),n=rt.useRef(!1),i=rt.useRef(!1);return Ge.jsx(dGe,{...r,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var o,s;(o=r.onCloseAutoFocus)==null||o.call(r,a),a.defaultPrevented||(n.current||(s=t.triggerRef.current)==null||s.focus(),a.preventDefault()),n.current=!1,i.current=!1},onInteractOutside:a=>{var l,c;(l=r.onInteractOutside)==null||l.call(r,a),a.defaultPrevented||(n.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()}})}),dGe=rt.forwardRef((r,e)=>{const{__scopeDialog:t,trapFocus:n,onOpenAutoFocus:i,onCloseAutoFocus:a,...o}=r,s=S4(R6,t),l=rt.useRef(null),c=R9(e,l);return gIe(),Ge.jsxs(Ge.Fragment,{children:[Ge.jsx(Ose,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:i,onUnmountAutoFocus:a,children:Ge.jsx(Pse,{role:"dialog",id:s.contentId,"aria-describedby":s.descriptionId,"aria-labelledby":s.titleId,"data-state":oue(s.open),...o,ref:c,onDismiss:()=>s.onOpenChange(!1)})}),Ge.jsxs(Ge.Fragment,{children:[Ge.jsx(Qin,{titleId:s.titleId}),Ge.jsx(Jin,{contentRef:l,descriptionId:s.descriptionId})]})]})}),aue="DialogTitle",pGe=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=S4(aue,t);return Ge.jsx(xg.h2,{id:i.titleId,...n,ref:e})});pGe.displayName=aue;var hGe="DialogDescription",mGe=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=S4(hGe,t);return Ge.jsx(xg.p,{id:i.descriptionId,...n,ref:e})});mGe.displayName=hGe;var vGe="DialogClose",yGe=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=S4(vGe,t);return Ge.jsx(xg.button,{type:"button",...n,ref:e,onClick:Ch(r.onClick,()=>i.onOpenChange(!1))})});yGe.displayName=vGe;function oue(r){return r?"open":"closed"}var gGe="DialogTitleWarning",[Zin,_Ge]=Rpt(gGe,{contentName:R6,titleName:aue,docsSlug:"dialog"}),Qin=({titleId:r})=>{const e=_Ge(gGe),t=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
|
|
13454
|
+
`,onClick:n=>{n.stopPropagation(),t()},children:[Ge.jsx("input",{type:"checkbox",checked:e}),Ge.jsx("span",{style:{color:"#eee"},children:r})]}),Din=({children:r,elements:e})=>{const[t,n]=Ox($=>[$.is_mouse_over_container,$.setIsMouseOverContainer]),[i,a]=rt.useState(!1),[o,s]=rt.useState(!1),[l,c]=rt.useState(!1),[u,f]=Ox($=>[$.selected_layer,$.selectLayer]),[d,m,y,w,S,b]=Ox($=>[$.in_move_footprint_mode,$.in_draw_trace_mode,$.is_showing_rats_nest,$.is_showing_multiple_traces_length,$.is_showing_autorouting,$.is_showing_drc_errors]),E=Ox($=>$.setEditMode),P=Ox($=>$.setIsShowingRatsNest),U=Ox($=>$.setIsShowingMultipleTracesLength),V=Ox($=>$.setIsShowingAutorouting),Y=Ox($=>$.setIsShowingDrcErrors);DE("1",()=>f("top")),DE("2",()=>f("bottom")),DE("3",()=>f("inner1")),DE("4",()=>f("inner2")),DE("5",()=>f("inner3")),DE("6",()=>f("inner4")),DE("7",()=>f("inner5")),DE("8",()=>f("inner6"));const W=(e==null?void 0:e.filter($=>$.type.includes("error")).length)??0;return Ge.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>{n(!0)},onMouseLeave:$=>{n(!1),s(!1)},children:[r,Ge.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@",Pin.version]}),Ge.jsxs("div",{style:{position:"absolute",opacity:t?1:0,top:16,left:16,transition:t?"opacity 100ms linear":"opacity 1s linear",zIndex:n5.toolbarOverlay,color:"red",display:"flex",fontSize:12,height:100,fontFamily:"sans-serif"},children:[Ge.jsxs(u7,{onClick:()=>{s(!o)},onMouseLeave:()=>{o&&s(!1)},children:[Ge.jsxs("div",{children:["layer:"," ",Ge.jsx("span",{style:{marginLeft:2,fontWeight:500,color:c7[u]},children:u})]}),o&&Ge.jsx("div",{style:{marginTop:4,minWidth:120},children:Kce.map($=>$.replace(/-/g,"")).map($=>Ge.jsx(Nin,{name:$,selected:$===u,onClick:()=>{f($.replace(/-/,""))}},$))})]}),Ge.jsxs(u7,{style:W>0?{color:"red"}:{},onClick:()=>c(!l),onMouseLeave:()=>c(!1),children:[Ge.jsxs("div",{children:[W," errors"]}),l&&Ge.jsx("div",{style:{display:"grid",gridTemplateColumns:"100px 300px"},children:e==null?void 0:e.filter($=>$.type.includes("error")).map(($,K)=>Ge.jsxs(rt.Fragment,{children:[Ge.jsx("div",{children:$.error_type}),Ge.jsx("div",{children:$.message})]},K))})]}),Ge.jsx(u7,{style:{},onClick:()=>{E(m?"off":"draw_trace")},children:Ge.jsxs("div",{children:[m?"✖ ":"","Edit Traces"]})}),Ge.jsx(u7,{style:{},onClick:()=>{E(d?"off":"move_footprint")},children:Ge.jsxs("div",{children:[d?"✖ ":"","Move Components"]})}),Ge.jsx(u7,{style:{},onClick:()=>{P(!y)},children:Ge.jsxs("div",{children:[y?"✖ ":"","Rats Nest"]})}),Ge.jsx(u7,{onClick:()=>{a(!i)},children:Ge.jsxs("div",{children:[Ge.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:["View"," ",Ge.jsx("span",{style:{fontSize:"8px",transform:i?"rotate(180deg)":"rotate(0)",transition:"transform 0.1s ease",display:"inline-block"},children:"▼"})]}),i&&Ge.jsxs("div",{style:{marginTop:4,minWidth:120},children:[Ge.jsx(rue,{label:"Show All Trace Lengths",checked:w,onClick:()=>{U(!w)}}),Ge.jsx(rue,{label:"Show Autorouting Animation",checked:S,onClick:()=>{V(!S)}}),Ge.jsx(rue,{label:"Show DRC Errors",checked:b,onClick:()=>{Y(!b)}})]})]})})]})]})},Lin=r=>{const{transform:e,elements:t}=r,[n,i]=rt.useMemo(()=>{const c=r.elements.flatMap(f=>Grn(f,r.elements)),u=n4(r.elements);return[c,u]},[r.elements]),[a,o]=rt.useState({drawingObjectIdsWithMouseOver:new Set,primitiveIdsInMousedOverNet:[]}),s=rt.useMemo(()=>jrn({primitivesWithoutInteractionMetadata:n,drawingObjectIdsWithMouseOver:a.drawingObjectIdsWithMouseOver,primitiveIdsInMousedOverNet:a.primitiveIdsInMousedOverNet}),[n,a]),l=rt.useCallback(c=>{var d,m;const u=[];for(const y of c)if(y._element){const w=i.getNetConnectedToId("pcb_port_id"in y._element?(d=y._element)==null?void 0:d.pcb_port_id:"pcb_trace_id"in y._element?(m=y._element)==null?void 0:m.pcb_trace_id:"");u.push(...i.getIdsConnectedToNet(w))}const f=new Set(c.map(y=>y._pcb_drawing_object_id));o({drawingObjectIdsWithMouseOver:f,primitiveIdsInMousedOverNet:u})},[i]);return Ge.jsx(Rin,{elements:t,transform:e,primitives:n,onMouseHoverOverPrimitives:l,children:Ge.jsx(fin,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:Ge.jsx(min,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:Ge.jsx(cin,{transform:e,focusOnHover:r.focusOnHover,children:Ge.jsx(Din,{elements:t,children:Ge.jsx(gin,{transform:e,elements:t,children:Ge.jsx(Ain,{transform:e,soup:t,children:Ge.jsx(sin,{transform:e,debugGraphics:r.debugGraphics,children:Ge.jsx(lin,{transform:e,elements:t,children:Ge.jsx(oin,{transform:e,primitives:s,width:r.width,height:r.height,grid:r.grid})})})})})})})})})})},Oin=wc(zf(400,300),Zx(40,-40)),zin=({circuitJson:r,debugGraphics:e,height:t=600,initialState:n,allowEditing:i=!0,editEvents:a,onEditEventsChanged:o,focusOnHover:s=!1,clickToInteractEnabled:l=!1})=>{const[c,u]=rt.useState(!l),[f,d]=tue(),[m,y]=rt.useState(Oin),{ref:w,setTransform:S,cancelDrag:b}=Brn({transform:m,onSetTransform:y,enabled:c});let[E,P]=rt.useState([]);E=a??E;const U=rt.useRef(!1),V=rt.useRef(null),Y=`${(r==null?void 0:r.length)||0}_${(r==null?void 0:r.editCount)||0}`,W=()=>{const pe=(d==null?void 0:d.width)>0?d:{width:500,height:500},{center:ue,width:Se,height:he}=K.some(xe=>xe.type.startsWith("pcb_"))?Prn(K.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=wc(zf((pe.width??0)/2,(pe.height??0)/2),Zx(ge,-ge,0,0),zf(-ue.x,-ue.y));S(Te)};rt.useEffect(()=>{d!=null&&d.width&&r&&r.length!==0&&(U.current||(W(),U.current=!0))},[r,d]);const $=rt.useMemo(()=>(r==null?void 0:r.filter(pe=>pe.type.startsWith("pcb_")||pe.type.startsWith("source_")))??[],[Y]),K=rt.useMemo(()=>nen({circuitJson:$,editEvents:E}),[$,E]),X=pe=>{P([...E,pe]),o==null||o([...E,pe])},ce=pe=>{const ue=E.map(Se=>Se.edit_event_id===pe.edit_event_id?{...Se,...pe}:Se);P(ue),o==null||o(ue)};return Ge.jsxs("div",{ref:w,style:{position:"relative"},children:[Ge.jsx("div",{ref:f,children:Ge.jsxs(Drn,{initialState:n,children:[Ge.jsx(Lin,{transform:m,height:t,width:d.width,allowEditing:i,focusOnHover:s,cancelPanDrag:b,onCreateEditEvent:X,onModifyEditEvent:ce,grid:{spacing:1,view_window:{left:0,right:d.width||500,top:t,bottom:0}},elements:K,debugGraphics:e},d.width),Ge.jsx(Orn,{})]})}),l&&!c&&Ge.jsx("div",{onClick:()=>{u(!0),W()},onTouchStart:pe=>{const ue=pe.touches[0];V.current={x:ue.clientX,y:ue.clientY}},onTouchEnd:pe=>{const ue=pe.changedTouches[0],Se=V.current;if(!Se)return;const he=Math.abs(ue.clientX-Se.x),ge=Math.abs(ue.clientY-Se.y);he<10&&ge<10&&(pe.preventDefault(),u(!0),W()),V.current=null},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:n5.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center",touchAction:"pan-x pan-y pinch-zoom"},children:Ge.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 Uin=({containerClassName:r,...e})=>{const t=rt.useRef(null),[n,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)}},[]),Ge.jsx("div",{ref:t,className:r||"rf-w-full rf-h-full",children:Ge.jsx(zin,{...e,height:n})})},kin='*,: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}',Iin=()=>{rt.useEffect(()=>{if(document.querySelector('style[data-styles="tscircuit-runframe"]'))return;const e=document.createElement("style");e.setAttribute("data-styles","tscircuit-runframe"),e.textContent=kin,document.head.appendChild(e)},[])},nGe=r=>`hsl(${U5.indexOf(r)*137.5%360}, 70%, 50%)`,Fin=({phaseTimings:r})=>{if(!r)return null;const e=Object.values(r).reduce((t,n)=>t+n,0);return Ge.jsxs("div",{className:"rf-space-y-2 rf-w-full rf-px-4",children:[Ge.jsx("div",{className:"rf-relative rf-h-8 rf-flex rf-rounded-sm",children:U5.map(t=>{const n=r[t]||0,i=n/e*100;return Ge.jsx("div",{className:"rf-group/bar rf-relative rf-overflow-visible",style:{width:`${i}%`,backgroundColor:nGe(t)},children:Ge.jsxs("div",{className:"rf-opacity-0 group-hover/bar:rf-opacity-100 rf-transition-opacity rf-absolute rf-bottom-full rf-left-1/2 rf-transform -rf-translate-x-1/2 rf-mb-2 rf-px-2 rf-py-1 rf-text-xs rf-whitespace-nowrap rf-rounded rf-bg-gray-900 rf-text-white rf-pointer-events-none",children:[t,": ",n.toFixed(1),"ms"]})},t)})}),Ge.jsxs("div",{className:"rf-text-xs rf-text-gray-500",children:["Total: ",e.toFixed(2),"ms"]})]})},Bin=({renderLog:r})=>{const[e,t]=rt.useState("chronological");if(!r)return Ge.jsx("div",{className:"rf-p-4 rf-bg-gray-100 rf-rounded-md",children:"No render log, make sure this tab is open when you render (TODO add a rerender button here)"});const n=Object.entries((r==null?void 0:r.phaseTimings)??{});e==="chronological"?n.sort((a,o)=>U5.indexOf(a[0])-U5.indexOf(o[0])):n.sort((a,o)=>o[1]-a[1]);const i=n.reduce((a,[o,s])=>a+s,0);return Ge.jsxs("div",{className:"rf-bg-white",children:[Ge.jsxs("div",{className:"rf-flex rf-justify-between rf-items-center",children:[Ge.jsx("div",{children:"Render Logs"}),Ge.jsxs("div",{className:"rf-mb-4 rf-pr-2 rf-flex rf-text-xs rf-items-center",children:[Ge.jsx("div",{className:"rf-mr-2",children:"Sort by:"}),Ge.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:[Ge.jsx("option",{value:"chronological",children:"Phase Order"}),Ge.jsx("option",{value:"longest",children:"Duration"})]})]})]}),Ge.jsx(Fin,{phaseTimings:r.phaseTimings}),Ge.jsxs("table",{className:"rf-w-full rf-text-xs",children:[Ge.jsx("thead",{children:Ge.jsxs("tr",{children:[Ge.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase Order"}),Ge.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase"}),Ge.jsx("th",{className:"rf-text-left rf-p-2",children:"Duration (ms)"})]})}),Ge.jsx("tbody",{children:n.map(([a,o])=>Ge.jsxs("tr",{children:[Ge.jsx("td",{className:"rf-p-2",children:U5.indexOf(a)}),Ge.jsx("td",{className:"rf-p-2",children:a}),Ge.jsx("td",{className:"rf-p-2",children:Ge.jsx("div",{className:"rf-w-8",children:Ge.jsx("div",{className:"rf-h-2 rf-rounded-sm",style:{backgroundColor:nGe(a),width:`${o/i*100}%`}})})}),Ge.jsx("td",{className:"rf-p-2",children:Ge.jsxs("div",{className:"rf-flex w-full",children:[Ge.jsxs("span",{className:"rf-flex-grow",children:[o,"ms"]}),Ge.jsxs("span",{className:"rf-text-gray-500 rf-pr-2",children:[(o/i*100).toFixed(1),"%"]})]})})]},a))})]})]})},jin="0.0.466",Hin=["assembly","bom","circuit_json","errors","render_log"],Vin=({code:r,onRunClicked:e=void 0,errorMessage:t,circuitJson:n,autoroutingGraphics:i,showRightHeaderContent:a=!0,showCodeTab:o=!1,codeTabContent:s,showJsonTab:l=!0,showRenderLogTab:c=!0,onActiveTabChange:u,renderLog:f,showImportAndFormatButtons:d=!0,className:m,headerClassName:y,leftHeaderContent:w,readOnly:S,isStreaming:b,autoroutingLog:E,onReportAutoroutingLog:P,isRunningCode:U,hasCodeChangedSinceLastRun:V,onEditEvent:Y,editEvents:W,defaultActiveTab:$,autoRotate3dViewerDisabled:K,showSchematicDebugGrid:X=!1,showToggleFullScreen:ce=!0,defaultToFullScreen:pe=!1})=>{var Ue;Iin();const ue=rt.useMemo(()=>n?n.filter(Re=>Re&&"error_type"in Re||Re.type.includes("error")):null,[n]),[Se,he]=rt.useState($??"pcb"),[ge,Te]=rt.useState(pe),xe=rt.useCallback(Re=>{he(Re),u==null||u(Re)},[u]),Pe=()=>{Te(!ge)};rt.useEffect(()=>{t&&xe("errors")},[t]),rt.useEffect(()=>{(Se==="code"||Se==="errors")&&n&&!t&&xe($??"pcb")},[n]);const De=rt.useCallback(Re=>{window.TSCIRCUIT_3D_OBJECT_REF=Re===null?void 0:Re},[]);return Ge.jsx("div",{className:v0("flex flex-col relative rf-overflow-x-hidden",m),children:Ge.jsx("div",{className:v0("rf-md:sticky rf-md:top-2",ge&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-bg-white"),children:Ge.jsxs(H_e,{value:Se,onValueChange:xe,className:"rf-flex-grow rf-flex rf-flex-col",children:[Ge.jsxs("div",{className:v0("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",y),children:[w,w&&Ge.jsx("div",{className:"rf-flex-grow"}),!w&&U&&Ge.jsx(jM,{className:"rf-w-4 rf-h-4 rf-animate-spin"}),!w&&Ge.jsx("div",{className:"rf-flex-grow"}),f&&f.progress!==1&&Ge.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[f.lastRenderEvent&&Ge.jsx("div",{className:"rf-text-xs rf-text-gray-500",children:((Ue=f.lastRenderEvent)==null?void 0:Ue.phase)??""}),Ge.jsx("div",{className:"rf-w-4 rf-h-4 rf-bg-blue-500 rf-opacity-50 rf-rounded-full rf-text-white",children:Ge.jsx(jM,{className:"rf-w-4 rf-h-4 rf-animate-spin"})}),Ge.jsxs("div",{className:"rf-text-xs rf-font-bold rf-text-gray-700 rf-tabular-nums",children:[((f.progress??0)*100).toFixed(1),"%"]})]}),a&&Ge.jsxs(pq,{children:[o&&Ge.jsx(Zw,{value:"code",children:"Code"}),Ge.jsxs(Zw,{value:"pcb",className:"rf-whitespace-nowrap",children:[n&&Ge.jsx("span",{className:v0("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",V?"rf-bg-gray-500":"rf-bg-blue-500")}),"PCB"]}),Ge.jsxs(Zw,{value:"schematic",className:"rf-whitespace-nowrap",children:[n&&Ge.jsx("span",{className:v0("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",V?"rf-bg-gray-500":"rf-bg-blue-500")}),"Schematic"]}),Ge.jsxs(Zw,{value:"cad",children:[n&&Ge.jsx("span",{className:v0("inline-flex items-center justify-center w-2 h-2 mr-1 text-xs font-bold text-white rounded-full",V?"rf-bg-gray-500":"rf-bg-blue-500")}),"3D"]}),!["pcb","cad","schematic"].includes(Se)&&Ge.jsx(Zw,{value:Se,children:j_e(Se)}),Ge.jsxs(fle,{children:[Ge.jsx(dle,{asChild:!0,children:Ge.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[Ge.jsx(DYt,{className:"rf-w-4 rf-h-4"}),(ue&&ue.length>0||t)&&Ge.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"})]})}),Ge.jsxs(UF,{className:"rf-*:text-xs",children:[Hin.map(Re=>Ge.jsxs(g4,{onSelect:()=>xe(Re),children:[Se!==Re&&Ge.jsx(Kke,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),Se===Re&&Ge.jsx(_se,{className:"rf-w-3 rf-h-3"}),Ge.jsx("div",{className:"rf-pr-2",children:j_e(Re)}),Re==="errors"&&(ue&&ue.length>0||t)&&Ge.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:ue==null?void 0:ue.length})]},Re)),Ge.jsx(g4,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:Ge.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/runframe@",jin.split(".").map((Re,$e)=>$e===2?parseInt(Re)+1:Re).join(".")]})})]})]})]}),ce&&Ge.jsx(T2,{onClick:Pe,variant:"ghost",children:ge?Ge.jsx(UYt,{size:16}):Ge.jsx(OYt,{size:16})})]}),o&&Ge.jsx(G4,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:Ge.jsx("div",{className:"rf-h-full",children:s})}),Ge.jsx(G4,{value:"pcb",children:Ge.jsx("div",{className:v0("rf-overflow-hidden",ge?"rf-h-[calc(100vh-52px)]":"rf-h-[620px]"),children:Ge.jsx(BM,{fallbackRender:({error:Re})=>Ge.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ge.jsxs("div",{className:"rf-p-4",children:[Ge.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading PCB viewer"}),Ge.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Re==null?void 0:Re.message)||"An unknown error occurred"})]})}),children:n?Ge.jsx(Uin,{focusOnHover:!1,circuitJson:n,debugGraphics:i,containerClassName:v0("rf-h-full rf-w-full",ge?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:Re=>{Y&&Re.forEach($e=>Y($e))}}):Ge.jsx(g6,{onRunClicked:e})})})}),Ge.jsx(G4,{value:"assembly",children:Ge.jsx("div",{className:v0("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(BM,{fallback:Ge.jsx("div",{children:"Error loading Assembly"}),children:n?Ge.jsx(nJt,{circuitJson:n,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):Ge.jsx(g6,{onRunClicked:e})})})}),Ge.jsx(G4,{value:"schematic",children:Ge.jsx("div",{className:v0("rf-overflow-auto rf-bg-white",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(BM,{fallbackRender:({error:Re})=>Ge.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ge.jsxs("div",{className:"rf-p-4",children:[Ge.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Schematic"}),Ge.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Re==null?void 0:Re.message)||"An unknown error occurred"})]})}),children:n?Ge.jsx(JKt,{circuitJson:n,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:Re=>{Y==null||Y(Re)},debugGrid:X,colorOverrides:{schematic:{background:"transparent"}}}):Ge.jsx(g6,{onRunClicked:e})})})}),Ge.jsx(G4,{value:"cad",children:Ge.jsx("div",{className:v0("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(BM,{FallbackComponent:_Yt,children:n?Ge.jsx(yYt,{ref:De,circuitJson:n,autoRotateDisabled:K}):Ge.jsx(g6,{onRunClicked:e})})})}),Ge.jsx(G4,{value:"bom",children:Ge.jsx("div",{className:v0("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(BM,{fallbackRender:({error:Re})=>Ge.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:Ge.jsxs("div",{className:"rf-p-4",children:[Ge.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Bill of Materials"}),Ge.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Re==null?void 0:Re.message)||"An unknown error occurred"})]})}),children:n?Ge.jsx(sJt,{circuitJson:n}):Ge.jsx(g6,{onRunClicked:e})})})}),Ge.jsx(G4,{value:"circuit_json",children:Ge.jsx("div",{className:v0("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(BM,{fallback:Ge.jsx("div",{children:"Error loading JSON viewer"}),children:n?Ge.jsx(aJt,{elements:n}):Ge.jsx(g6,{onRunClicked:e})})})}),Ge.jsx(G4,{value:"errors",children:Ge.jsx("div",{className:v0("rf-overflow-auto",ge?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:n?Ge.jsx(PQt,{code:r,circuitJsonErrors:ue,errorMessage:t,autoroutingLog:E,onReportAutoroutingLog:P}):Ge.jsx(g6,{onRunClicked:e})})}),c&&Ge.jsx(G4,{value:"render_log",children:Ge.jsx(Bin,{renderLog:f})})]})})})};var AB="Dialog",[rGe,iGe]=IS(AB),[Gin,S4]=rGe(AB),aGe=r=>{const{__scopeDialog:e,children:t,open:n,defaultOpen:i,onOpenChange:a,modal:o=!0}=r,s=rt.useRef(null),l=rt.useRef(null),[c,u]=xT({prop:n,defaultProp:i??!1,onChange:a,caller:AB});return Ge.jsx(Gin,{scope:e,triggerRef:s,contentRef:l,contentId:FS(),titleId:FS(),descriptionId:FS(),open:c,onOpenChange:u,onOpenToggle:rt.useCallback(()=>u(f=>!f),[u]),modal:o,children:t})};aGe.displayName=AB;var oGe="DialogTrigger",sGe=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=S4(oGe,t),a=R9(e,i.triggerRef);return Ge.jsx(xg.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":oue(i.open),...n,ref:a,onClick:Ch(r.onClick,i.onOpenToggle)})});sGe.displayName=oGe;var iue="DialogPortal",[qin,lGe]=rGe(iue,{forceMount:void 0}),cGe=r=>{const{__scopeDialog:e,forceMount:t,children:n,container:i}=r,a=S4(iue,e);return Ge.jsx(qin,{scope:e,forceMount:t,children:rt.Children.map(n,o=>Ge.jsx(H4,{present:t||a.open,children:Ge.jsx(Wse,{asChild:!0,container:i,children:o})}))})};cGe.displayName=iue;var PB="DialogOverlay",uGe=rt.forwardRef((r,e)=>{const t=lGe(PB,r.__scopeDialog),{forceMount:n=t.forceMount,...i}=r,a=S4(PB,r.__scopeDialog);return a.modal?Ge.jsx(H4,{present:n||a.open,children:Ge.jsx(Yin,{...i,ref:e})}):null});uGe.displayName=PB;var $in=_T("DialogOverlay.RemoveScroll"),Yin=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=S4(PB,t);return Ge.jsx(tle,{as:$in,allowPinchZoom:!0,shards:[i.contentRef],children:Ge.jsx(xg.div,{"data-state":oue(i.open),...n,ref:e,style:{pointerEvents:"auto",...n.style}})})}),R6="DialogContent",fGe=rt.forwardRef((r,e)=>{const t=lGe(R6,r.__scopeDialog),{forceMount:n=t.forceMount,...i}=r,a=S4(R6,r.__scopeDialog);return Ge.jsx(H4,{present:n||a.open,children:a.modal?Ge.jsx(Xin,{...i,ref:e}):Ge.jsx(Win,{...i,ref:e})})});fGe.displayName=R6;var Xin=rt.forwardRef((r,e)=>{const t=S4(R6,r.__scopeDialog),n=rt.useRef(null),i=R9(e,t.contentRef,n);return rt.useEffect(()=>{const a=n.current;if(a)return rFe(a)},[]),Ge.jsx(dGe,{...r,ref:i,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ch(r.onCloseAutoFocus,a=>{var o;a.preventDefault(),(o=t.triggerRef.current)==null||o.focus()}),onPointerDownOutside:Ch(r.onPointerDownOutside,a=>{const o=a.detail.originalEvent,s=o.button===0&&o.ctrlKey===!0;(o.button===2||s)&&a.preventDefault()}),onFocusOutside:Ch(r.onFocusOutside,a=>a.preventDefault())})}),Win=rt.forwardRef((r,e)=>{const t=S4(R6,r.__scopeDialog),n=rt.useRef(!1),i=rt.useRef(!1);return Ge.jsx(dGe,{...r,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var o,s;(o=r.onCloseAutoFocus)==null||o.call(r,a),a.defaultPrevented||(n.current||(s=t.triggerRef.current)==null||s.focus(),a.preventDefault()),n.current=!1,i.current=!1},onInteractOutside:a=>{var l,c;(l=r.onInteractOutside)==null||l.call(r,a),a.defaultPrevented||(n.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()}})}),dGe=rt.forwardRef((r,e)=>{const{__scopeDialog:t,trapFocus:n,onOpenAutoFocus:i,onCloseAutoFocus:a,...o}=r,s=S4(R6,t),l=rt.useRef(null),c=R9(e,l);return gIe(),Ge.jsxs(Ge.Fragment,{children:[Ge.jsx(Ose,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:i,onUnmountAutoFocus:a,children:Ge.jsx(Pse,{role:"dialog",id:s.contentId,"aria-describedby":s.descriptionId,"aria-labelledby":s.titleId,"data-state":oue(s.open),...o,ref:c,onDismiss:()=>s.onOpenChange(!1)})}),Ge.jsxs(Ge.Fragment,{children:[Ge.jsx(Qin,{titleId:s.titleId}),Ge.jsx(Jin,{contentRef:l,descriptionId:s.descriptionId})]})]})}),aue="DialogTitle",pGe=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=S4(aue,t);return Ge.jsx(xg.h2,{id:i.titleId,...n,ref:e})});pGe.displayName=aue;var hGe="DialogDescription",mGe=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=S4(hGe,t);return Ge.jsx(xg.p,{id:i.descriptionId,...n,ref:e})});mGe.displayName=hGe;var vGe="DialogClose",yGe=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=S4(vGe,t);return Ge.jsx(xg.button,{type:"button",...n,ref:e,onClick:Ch(r.onClick,()=>i.onOpenChange(!1))})});yGe.displayName=vGe;function oue(r){return r?"open":"closed"}var gGe="DialogTitleWarning",[Zin,_Ge]=Rpt(gGe,{contentName:R6,titleName:aue,docsSlug:"dialog"}),Qin=({titleId:r})=>{const e=_Ge(gGe),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
|
|