@tscircuit/runframe 0.0.477 → 0.0.479
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
|
@@ -827,7 +827,7 @@ ${a.width}x${a.height}
|
|
|
827
827
|
`)});let a=0;for(;a<this.totalPathLength;){const o=this.getPointAtDistance(a);e.circles.push({center:{x:o.x,y:o.y},radius:.05,fill:"rgba(100, 100, 100, 0.5)"}),a+=this.totalPathLength/20}if(this.lastValidPath&&this.lastValidPath.length>1)for(let o=0;o<this.lastValidPath.length-1;o++)e.lines.push({points:[{x:this.lastValidPath[o].x,y:this.lastValidPath[o].y},{x:this.lastValidPath[o+1].x,y:this.lastValidPath[o+1].y}],strokeColor:"rgba(0, 255, 255, 0.9)",strokeDash:"3, 3"});return e}},art=class extends W1{constructor(e){super();et(this,"simplifiedHdRoutes");et(this,"currentUnsimplifiedHdRouteIndex",0);et(this,"activeSubSolver",null);et(this,"unsimplifiedHdRoutes");et(this,"obstacles");et(this,"connMap");et(this,"colorMap");this.MAX_ITERATIONS=1e8,this.unsimplifiedHdRoutes=e.unsimplifiedHdRoutes,this.obstacles=e.obstacles,this.connMap=e.connMap||new xme({}),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 irt({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}},ort=class extends W1{constructor(e){super();et(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)&&xV(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=wg(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}},srt=class extends ort{step(){this.edges=[];const r=new Set,e=new bV(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(!xV(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}},Cme=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 K7(r,e){const t=r.x-e.x,n=r.y-e.y;return t*t+n*n}function eC(r,e,t){const n=K7(e,t);if(n===0)return K7(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 K7(r,a)}function lrt(r,e,t,n){if(US(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(eC(i,o,s),eC(a,o,s),eC(o,i,a),eC(s,i,a))}var crt=class{constructor(r,e=1){et(this,"segmentBuckets");et(this,"viaBuckets");et(this,"routes");et(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=Cme(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),v=Math.floor((l.maxY+t)/this.CELL_SIZE);for(let g=u;g<=f;g++)for(let w=d;w<=v;w++){const S=`${g}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=Cme([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),v=Math.floor((l+c)/this.CELL_SIZE),g=new Map,w=new Set,S=new Set,b={x:r.x,y:r.y},T={x:e.x,y:e.y};for(let z=u;z<=f;z++)for(let V=d;V<=v;V++){const q=`${z}x${V}`,X=this.segmentBuckets.get(q);if(X)for(const K of X){if(w.has(K.segmentId))continue;w.add(K.segmentId);const Y=K.parentRoute,[ce,he]=K.segment,ue=t+Y.traceThickness/2,Se=ue*ue,pe=lrt(r,e,ce,he);if(pe<Se){const ye=Y.connectionName,Te=g.get(ye);(!Te||pe<Te.minDistSq)&&g.set(ye,{route:Y,minDistSq:pe})}}const W=this.viaBuckets.get(q);if(W)for(const K of W){if(S.has(K.viaId))continue;S.add(K.viaId);const Y=K.parentRoute,ce={x:K.x,y:K.y},he=t+Y.viaDiameter/2,ue=he*he,Se=eC(ce,b,T);if(Se<ue){const pe=Y.connectionName,ye=g.get(pe);(!ye||Se<ye.minDistSq)&&g.set(pe,{route:Y,minDistSq:Se})}}}const A=[];for(const z of g.values())A.push({conflictingRoute:z.route,distance:Math.sqrt(z.minDistSq)});return A}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,v=new Set;for(let w=s;w<=l;w++)for(let S=c;S<=u;S++){const b=`${w}x${S}`,T=this.segmentBuckets.get(b);if(T)for(const z of T){if(d.has(z.segmentId))continue;d.add(z.segmentId);const V=z.parentRoute,q={x:z.segment[0].x,y:z.segment[0].y},X={x:z.segment[1].x,y:z.segment[1].y},W=e+V.traceThickness/2,K=W*W,Y=eC(r,q,X);if(Y<K){const ce=V.connectionName,he=f.get(ce);(!he||Y<he.minDistSq)&&f.set(ce,{route:V,minDistSq:Y})}}const A=this.viaBuckets.get(b);if(A)for(const z of A){if(v.has(z.viaId))continue;v.add(z.viaId);const V=z.parentRoute,q={x:z.x,y:z.y},X=e+V.viaDiameter/2,W=X*X,K=K7(r,q);if(K<W){const Y=V.connectionName,ce=f.get(Y);(!ce||K<ce.minDistSq)&&f.set(Y,{route:V,minDistSq:K})}}}const g=[];for(const w of f.values())g.push({conflictingRoute:w.route,distance:Math.sqrt(w.minDistSq)});return g}},urt=class extends W1{constructor(e){super();et(this,"obstacleSHI");et(this,"hdRouteSHI");et(this,"unsimplifiedRoute");et(this,"routeSections");et(this,"currentSectionIndex");et(this,"TRACE_THICKNESS",.15);et(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(dme(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}},frt=class extends W1{constructor(e){super();et(this,"unsimplifiedHdRoutes");et(this,"optimizedHdRoutes");et(this,"unprocessedRoutes");et(this,"activeSubSolver",null);et(this,"obstacleSHI",null);et(this,"hdRouteSHI",null);this.input=e,this.unsimplifiedHdRoutes=e.unsimplifiedHdRoutes,this.optimizedHdRoutes=[],this.unprocessedRoutes=[...e.unsimplifiedHdRoutes],this.obstacleSHI=new lme(e.obstacles),this.hdRouteSHI=new crt(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 urt({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 X9(r,e,t,n={}){return{solverName:r,solverClass:e,getConstructorParams:t,onSolved:n.onSolved}}var drt=class extends W1{constructor(e,t={}){super();et(this,"netToPointPairsSolver");et(this,"nodeSolver");et(this,"nodeTargetMerger");et(this,"edgeSolver");et(this,"pathingSolver");et(this,"edgeToPortSegmentSolver");et(this,"colorMap");et(this,"segmentToPointSolver");et(this,"unravelMultiSectionSolver");et(this,"segmentToPointOptimizer");et(this,"highDensityRouteSolver");et(this,"highDensityStitchSolver");et(this,"singleLayerNodeMerger");et(this,"strawSolver");et(this,"uselessViaRemovalSolver");et(this,"multiSimplifiedPathSolver");et(this,"startTimeOfPhase");et(this,"endTimeOfPhase");et(this,"timeSpentOnPhase");et(this,"activeSubSolver",null);et(this,"connMap");et(this,"srjWithPointPairs");et(this,"capacityNodes",null);et(this,"pipelineDef",[X9("netToPointPairsSolver",Unt,e=>[e.srj,e.colorMap],{onSolved:e=>{var t;e.srjWithPointPairs=(t=e.netToPointPairsSolver)==null?void 0:t.getNewSimpleRouteJson(),e.colorMap=yV(e.srjWithPointPairs,this.connMap),e.connMap=bme(e.srjWithPointPairs)}}),X9("nodeSolver",snt,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}}),X9("singleLayerNodeMerger",Qnt,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}}),X9("strawSolver",Znt,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()}}),X9("edgeSolver",srt,e=>[e.capacityNodes]),X9("pathingSolver",Xnt,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}}]}),X9("edgeToPortSegmentSolver",lnt,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}]}),X9("segmentToPointSolver",dnt,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}]}),X9("unravelMultiSectionSolver",Wnt,e=>{var t;return[{assignedSegments:((t=e.segmentToPointSolver)==null?void 0:t.solvedSegments)||[],colorMap:e.colorMap,nodes:e.capacityNodes}]}),X9("highDensityRouteSolver",Nnt,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}]}),X9("highDensityStitchSolver",Fnt,e=>[{connections:e.srjWithPointPairs.connections,hdRoutes:e.highDensityRouteSolver.routes,layerCount:e.srj.layerCount}]),X9("uselessViaRemovalSolver",frt,e=>[{unsimplifiedHdRoutes:e.highDensityStitchSolver.mergedHdRoutes,obstacles:e.srj.obstacles,colorMap:e.colorMap,layerCount:e.srj.layerCount}]),X9("multiSimplifiedPathSolver",art,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}]})]);et(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=int(a,o)}this.connMap=bme(e),this.colorMap=yV(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,T,A,z,V,q,X,W,K,Y,ce,he,ue,Se,pe,ye,Te,xe,Pe,De,ke,Re,$e,Ke,ut;if(!this.solved&&this.activeSubSolver)return this.activeSubSolver.visualize();const e=(b=this.netToPointPairsSolver)==null?void 0:b.visualize(),t=(T=this.nodeSolver)==null?void 0:T.visualize(),n=(A=this.nodeTargetMerger)==null?void 0:A.visualize(),i=(z=this.singleLayerNodeMerger)==null?void 0:z.visualize(),a=(V=this.strawSolver)==null?void 0:V.visualize(),o=(q=this.edgeSolver)==null?void 0:q.visualize(),s=(X=this.pathingSolver)==null?void 0:X.visualize(),l=(W=this.edgeToPortSegmentSolver)==null?void 0:W.visualize(),c=(K=this.segmentToPointSolver)==null?void 0:K.visualize(),u=((Y=this.unravelMultiSectionSolver)==null?void 0:Y.visualize())??((ce=this.segmentToPointOptimizer)==null?void 0:ce.visualize()),f=(he=this.highDensityRouteSolver)==null?void 0:he.visualize(),d=(ue=this.highDensityStitchSolver)==null?void 0:ue.visualize(),v=(Se=this.uselessViaRemovalSolver)==null?void 0:Se.visualize(),g=(pe=this.multiSimplifiedPathSolver)==null?void 0:pe.visualize(),w={points:[...this.srj.connections.flatMap(ht=>ht.pointsToConnect.map(At=>({...At,label:`${ht.name} ${At.pcb_port_id??""}`})))],rects:[...(this.srj.obstacles??[]).map(ht=>{var At,Bt,Qt;return{...ht,fill:(At=ht.layers)!=null&&At.includes("top")?"rgba(255,0,0,0.25)":(Bt=ht.layers)!=null&&Bt.includes("bottom")?"rgba(0,0,255,0.25)":"rgba(255,0,0,0.25)",label:(Qt=ht.layers)==null?void 0:Qt.join(", ")}})],lines:[{points:[{x:((ye=this.srj.bounds)==null?void 0:ye.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:((ke=this.srj.bounds)==null?void 0:ke.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?j7(w,f):null,d,v,g,this.solved?j7(w,Bnt(this.getOutputSimpleRouteJson())):null].filter(Boolean);return j7(...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:Int(s,this.srj.layerCount)};e.push(l)}}return e}getOutputSimpleRouteJson(){return{...this.srj,traces:this.getOutputSimplifiedPcbTraces()}}},wV=drt,C9=(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&&(fD[o]??FA).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)}}}}})};C9.unparsed=C9;var Y1=C9,tC=C9;function EV(r){const e=r.type;return`${e}:${r[`${e}_id`]}`}var Rme=(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=EV(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 v=t.indexes.byRelation.get(u);if(v){const w=(v.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(T=>T[`${o}_id`]===S)||null:r.find(b=>b.type===o&&b[`${o}_id`]===S)||null}}const d=r.find(v=>v.type===f&&v[u]===s[u]);return d&&r.find(v=>v.type===o&&v[`${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(g=>g.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(v=>d[v]===s[v]))||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(v=>v.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&&(fD[o]??FA).parse(c),r.push(c),t.editCount++;const u=e.indexConfig||{};if(u.byId&&t.indexes.byId){const d=EV(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[v,g]of d)if(v.endsWith("_id")&&v!==`${c.type}_id`&&typeof g=="string"){const w=t.indexes.byRelation.get(v)||new Map,S=w.get(g)||[];S.push(c),w.set(g,S),t.indexes.byRelation.set(v,w)}}if(u.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in c){const d=c.subcircuit_id;if(d&&typeof d=="string"){const v=t.indexes.bySubcircuit.get(d)||[];v.push(c),t.indexes.bySubcircuit.set(d,v)}}if(u.byCustomField&&t.indexes.byCustomField){for(const d of u.byCustomField)if(d in c){const v=c[d];if(v!==void 0&&(typeof v=="string"||typeof v=="number")){const g=String(v),w=t.indexes.byCustomField.get(d),S=w.get(g)||[];S.push(c),w.set(g,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=EV(c);t.indexes.byId.delete(f)}if(l.byType&&t.indexes.byType){const d=(t.indexes.byType.get(o)||[]).filter(v=>v[`${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[v,g]of d.entries()){const w=g.filter(S=>S!==c);w.length===0?d.delete(v):d.set(v,w)}if(l.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in c){const f=c.subcircuit_id;if(f){const v=(t.indexes.bySubcircuit.get(f)||[]).filter(g=>g!==c);v.length===0?t.indexes.bySubcircuit.delete(f):t.indexes.bySubcircuit.set(f,v)}}if(l.byCustomField&&t.indexes.byCustomField)for(const f of t.indexes.byCustomField.values())for(const[d,v]of f.entries()){const g=v.filter(w=>w!==c);g.length===0?f.delete(d):f.set(d,g)}},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,v]of f)if(d.endsWith("_id")&&d!==`${u.type}_id`&&typeof v=="string"&&d in l&&l[d]!==v){const g=t.indexes.byRelation.get(d);if(g){const S=(g.get(v)||[]).filter(b=>b!==u);S.length===0?g.delete(v):g.set(v,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 g=(t.indexes.bySubcircuit.get(f)||[]).filter(w=>w!==u);g.length===0?t.indexes.bySubcircuit.delete(f):t.indexes.bySubcircuit.set(f,g)}}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 v=String(u[f]),w=(d.get(v)||[]).filter(S=>S!==u);w.length===0?d.delete(v):d.set(v,w)}}}if(Object.assign(u,l),t.editCount++,c.byRelation&&t.indexes.byRelation){const f=Object.entries(u);for(const[d,v]of f)if(d.endsWith("_id")&&d!==`${u.type}_id`&&typeof v=="string"&&d in l){const g=t.indexes.byRelation.get(d)||new Map,w=g.get(v)||[];w.includes(u)||(w.push(u),g.set(v,w),t.indexes.byRelation.set(d,g))}}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 v=String(d),g=t.indexes.byCustomField.get(f),w=g.get(v)||[];w.includes(u)||(w.push(u),g.set(v,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}}}})};Rme.unparsed=Rme;var hrt=(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}=jr(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=jr(e,r.center);else if(r.type==="pcb_silkscreen_text"||r.type==="pcb_fabrication_note_text")r.anchor_position=jr(e,r.anchor_position);else if(r.type==="pcb_silkscreen_circle"||r.type==="pcb_silkscreen_rect"||r.type==="pcb_component")r.center=jr(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=jr(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=jr(e,t),a=jr(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=jr(e,{x:r.position.x,y:r.position.y});r.position.x=t.x,r.position.y=t.y}return r},Ame=r=>{const e=r.type;return r[`${e}_id`]},prt=(r,e)=>r.find(t=>Ame(t)===e)??null;function mrt(r,e){const t=C9(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=C9(r).pcb_port.get(o);if(!s)return null;const l=C9(r).pcb_component.get(s.pcb_component_id);if(!l)return null;const c=C9(r).source_component.get(l.source_component_id);if(!c)return null;const u=C9(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 Pme=(r,e)=>{const t=C9(r).pcb_port.get(e);if(!t)return`pcb_port[#${e}]`;const n=C9(r).pcb_component.get(t==null?void 0:t.pcb_component_id);if(!n)return`pcb_port[#${e}]`;const i=C9(r).source_component.get(n.source_component_id);if(!i)return`pcb_port[#${e}]`;const a=C9(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 vrt(r,e){const t=C9(r).pcb_smtpad.get(e);return!t||!t.pcb_port_id?`smtpad[${e}]`:Pme(r,t.pcb_port_id)}var Nme=(r,e)=>{if(typeof e=="string"){const t=prt(r,e);return Nme(r,t)}switch(e.type){case"pcb_port":return Pme(r,e.pcb_port_id);case"pcb_smtpad":return vrt(r,e.pcb_smtpad_id);case"pcb_trace":return mrt(r,e.pcb_trace_id);case"source_component":return`source_component[${e.name}]`;default:return`${e.type}[#${Ame(e)}]`}},grt=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}},TV=r=>r[`${r.type}_id`],yrt=class{constructor({objects:r,getBounds:e,getId:t,CELL_SIZE:n}){et(this,"buckets");et(this,"objectsById");et(this,"getBounds");et(this,"getId");et(this,"CELL_SIZE",.4);et(this,"_idCounter",0);this.buckets=new Map,this.objectsById=new Map,this.getBounds=e,this.getId=t??(()=>this._getNextId()),this.CELL_SIZE=n??this.CELL_SIZE;for(const i of r)this.addObject(i)}_getNextId(){return`${this._idCounter++}`}addObject(r){const e=this.getBounds(r),t=this.getId(r),n={...r,spatialIndexId:t};this.objectsById.set(t,n);const i=Math.floor(e.minX/this.CELL_SIZE),a=Math.floor(e.minY/this.CELL_SIZE),o=Math.floor(e.maxX/this.CELL_SIZE),s=Math.floor(e.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);f?f.push(n):this.buckets.set(u,[n])}}removeObject(r){const e=this.objectsById.get(r);if(!e)return!1;this.objectsById.delete(r);const t=this.getBounds(e),n=Math.floor(t.minX/this.CELL_SIZE),i=Math.floor(t.minY/this.CELL_SIZE),a=Math.floor(t.maxX/this.CELL_SIZE),o=Math.floor(t.maxY/this.CELL_SIZE);for(let s=n;s<=a;s++)for(let l=i;l<=o;l++){const c=`${s}x${l}`,u=this.buckets.get(c);if(u){const f=u.findIndex(d=>d.spatialIndexId===r);f!==-1&&(u.splice(f,1),u.length===0&&this.buckets.delete(c))}}return!0}getBucketKey(r,e){return`${Math.floor(r/this.CELL_SIZE)}x${Math.floor(e/this.CELL_SIZE)}`}getObjectsInBounds(r,e=0){const t=[],n=new Set,i=Math.floor((r.minX-e)/this.CELL_SIZE),a=Math.floor((r.minY-e)/this.CELL_SIZE),o=Math.floor((r.maxX+e)/this.CELL_SIZE),s=Math.floor((r.maxY+e)/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)||[];for(const d of f){const v=d.spatialIndexId;n.has(v)||(n.add(v),t.push(d))}}return t}},eP=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)}:grt([r]),MV=.1,_rt=.15,CV=.005;function xrt(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 RV(r){const e=new Set;for(const t of r)for(const n of xrt(t))e.add(n);return Array.from(e)}var brt=(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 W=T3(((t.x-i.x)*s.x+(t.y-i.y)*s.y)/c,0,1),K={x:i.x+W*s.x,y:i.y+W*s.y};return{x:(t.x+K.x)/2,y:(t.y+K.y)/2}}const q=T3(((i.x-t.x)*o.x+(i.y-t.y)*o.y)/l,0,1),X={x:t.x+q*o.x,y:t.y+q*o.y};return{x:(X.x+i.x)/2,y:(X.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,v=o.x*u.x+o.y*u.y,g=s.x*s.x+s.y*s.y,w=s.x*u.x+s.y*u.y,S=f*g-d*d;if(S<1e-10)return Srt(t,n,i,a,o,s,l,c);let b=(d*w-g*v)/S,T=(f*w-d*v)/S;b=T3(b,0,1),T=T3(T,0,1),T=(b*d+w)/g,T=T3(T,0,1),b=(T*d-v)/f,b=T3(b,0,1);const A={x:t.x+b*o.x,y:t.y+b*o.y},z={x:i.x+T*s.x,y:i.y+T*s.y};return{x:(A.x+z.x)/2,y:(A.y+z.y)/2}},Srt=(r,e,t,n,i,a,o,s)=>{let l=((t.x-r.x)*i.x+(t.y-r.y)*i.y)/o;l=T3(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=T3(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=T3(d,0,1);const v={x:t.x+d*a.x,y:t.y+d*a.y};let g=((e.x-t.x)*a.x+(e.y-t.y)*a.y)/s;g=T3(g,0,1);const w={x:t.x+g*a.x,y:t.y+g*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:v,distance:Math.sqrt((r.x-v.x)**2+(r.y-v.y)**2)},{pointA:e,pointB:w,distance:Math.sqrt((e.x-w.x)**2+(e.y-w.y)**2)}].reduce((T,A)=>A.distance<T.distance?A:T);return{x:(b.pointA.x+b.pointB.x)/2,y:(b.pointA.y+b.pointB.y)/2}},T3=(r,e,t)=>Math.max(e,Math.min(t,r)),wrt=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)}`)},Dme=(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 W=Math.max(i,Math.min(o,t.x)),K=Math.max(a,Math.min(s,t.y));return W===t.x&&K===t.y?{x:t.x,y:t.y}:{x:W,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,v=c!==0?(s-t.y)/c:Number.POSITIVE_INFINITY,g=Math.max(Math.min(u,f),Math.min(d,v)),w=Math.min(Math.max(u,f),Math.max(d,v));if(g<=w&&w>=0&&g<=1){const W=Math.max(0,Math.min(1,g));return{x:t.x+W*l,y:t.y+W*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))},T=(S.x-t.x)**2+(S.y-t.y)**2,A=(b.x-n.x)**2+(b.y-n.y)**2,z=[{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(T,A),q=T<=A?S:b;const X=(W,K,Y)=>Math.max(K,Math.min(Y,W));for(const W of z){const K={x:n.x-t.x,y:n.y-t.y},Y={x:W.end.x-W.start.x,y:W.end.y-W.start.y},ce={x:t.x-W.start.x,y:t.y-W.start.y},he=K.x*K.x+K.y*K.y,ue=K.x*Y.x+K.y*Y.y,Se=K.x*ce.x+K.y*ce.y,pe=Y.x*Y.x+Y.y*Y.y,ye=Y.x*ce.x+Y.y*ce.y,Te=he*pe-ue*ue;if(Math.abs(Te)<1e-10)continue;let xe=(ue*ye-pe*Se)/Te,Pe=(he*ye-ue*Se)/Te;xe=X(xe,0,1),Pe=X(Pe,0,1);const De={x:t.x+xe*K.x,y:t.y+xe*K.y},ke={x:W.start.x+Pe*Y.x,y:W.start.y+Pe*Y.y},Re=De.x-ke.x,$e=De.y-ke.y,Ke=Re*Re+$e*$e;Ke<V&&(V=Ke,q={x:(De.x+ke.x)/2,y:(De.y+ke.y)/2})}return q};function Ert(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:[...UA]:r.type==="pcb_hole"?[...UA]:r.type==="pcb_via"?Array.isArray(r.layers)?r.layers:[...UA]:r.type==="pcb_keepout"?Array.isArray(r.layers)?r.layers:[]:[]}function AV(r,{connMap:e}={}){const t=[];e??(e=w3(r));const i=tC(r).pcb_trace.list().flatMap(g=>{const w=[];for(let S=0;S<g.route.length-1;S++){const b=g.route[S],T=g.route[S+1];b.route_type==="wire"&&T.route_type==="wire"&&b.layer===T.layer&&w.push({type:"pcb_trace_segment",pcb_trace_id:g.pcb_trace_id,_pcbTrace:g,thickness:"width"in b?b.width:"width"in T?T.width:_rt,layer:b.layer,x1:b.x,y1:b.y,x2:T.x,y2:T.y})}return w}),a=tC(r).pcb_smtpad.list(),o=tC(r).pcb_plated_hole.list(),s=tC(r).pcb_hole.list(),l=tC(r).pcb_via.list(),c=tC(r).pcb_keepout.list(),u=[...i,...a,...o,...s,...l,...c],f=new yrt({objects:u,getBounds:eP}),d=g=>Nme(r,g),v=new Set;for(const g of i){const w=MV,S=eP(g),b=f.getObjectsInBounds(S,w+g.thickness/2);if(!(g.x1===g.x2&&g.y1===g.y2))for(const T of b){if(!Ert(T).includes(g.layer))continue;if(T.type==="pcb_trace_segment"){const q=T;if(g.layer!==q.layer||e.areIdsConnected(g.pcb_trace_id,q.pcb_trace_id))continue;const X=rtt({x:g.x1,y:g.y1},{x:g.x2,y:g.y2},{x:q.x1,y:q.y1},{x:q.x2,y:q.y2})-g.thickness/2-q.thickness/2;if(X>MV-CV)continue;const W=`overlap_${g.pcb_trace_id}_${q.pcb_trace_id}`,K=`overlap_${q.pcb_trace_id}_${g.pcb_trace_id}`;if(v.has(W)||v.has(K))continue;v.add(W),t.push({type:"pcb_trace_error",error_type:"pcb_trace_error",message:`PCB trace ${d(g.pcb_trace_id)} overlaps with ${d(q.pcb_trace_id)} ${X<0?"(accidental contact)":`(gap: ${X.toFixed(3)}mm)`}`,pcb_trace_id:g.pcb_trace_id,source_trace_id:"",pcb_trace_error_id:W,pcb_component_ids:[],center:brt(g,q),pcb_port_ids:RV([g._pcbTrace,q._pcbTrace])});continue}const A=TV(T);if(e.areIdsConnected(g.pcb_trace_id,"pcb_trace_id"in T?T.pcb_trace_id:A))continue;if(T.type==="pcb_via"||T.type==="pcb_plated_hole"&&T.shape==="circle"||T.type==="pcb_hole"||T.type==="pcb_smtpad"&&T.shape==="circle"){const q=wrt(T),W=att({x:g.x1,y:g.y1},{x:g.x2,y:g.y2},{x:T.x,y:T.y,radius:q})-g.thickness/2;if(W>MV-CV)continue;const K=`overlap_${g.pcb_trace_id}_${A}`;if(v.has(K))continue;v.add(K),t.push({type:"pcb_trace_error",error_type:"pcb_trace_error",message:`PCB trace ${d(g.pcb_trace_id)} overlaps with ${T.type} "${d(TV(T))}" ${W<0?"(accidental contact)":`(gap: ${W.toFixed(3)}mm)`}`,pcb_trace_id:g.pcb_trace_id,center:Dme(g,eP(T)),source_trace_id:"",pcb_trace_error_id:K,pcb_component_ids:["pcb_component_id"in T?T.pcb_component_id:void 0].filter(Boolean),pcb_port_ids:[...RV([g._pcbTrace]),"pcb_port_id"in T?T.pcb_port_id:void 0].filter(Boolean)})}const V=itt({x:g.x1,y:g.y1},{x:g.x2,y:g.y2},eP(T))-g.thickness/2;if(V+CV<w){const q=`overlap_${g.pcb_trace_id}_${A}`;if(v.has(q))continue;v.add(q),t.push({type:"pcb_trace_error",error_type:"pcb_trace_error",message:`PCB trace ${d(g.pcb_trace_id)} overlaps with ${T.type} "${d(TV(T))}" ${V<0?"(accidental contact)":`(gap: ${V.toFixed(3)}mm)`}`,pcb_trace_id:g.pcb_trace_id,source_trace_id:"",pcb_trace_error_id:q,pcb_component_ids:["pcb_component_id"in T?T.pcb_component_id:void 0].filter(Boolean),center:Dme(g,eP(T)),pcb_port_ids:[...RV([g._pcbTrace]),"pcb_port_id"in T?T.pcb_port_id:void 0].filter(Boolean)})}}}return t}var PV=[{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 _5(r){if(r==null)return"";if(r===0)return"0";const e=Math.abs(r),t=PV.find(a=>{const o=e/a.value;return o>=1&&o<1e3})||PV[PV.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 Trt=Object.defineProperty,Mrt=(r,e)=>{for(var t in e)Trt(r,t,{get:e[t],enumerable:!0})},Lme={};Mrt(Lme,{Battery:()=>Bit,Board:()=>bit,Capacitor:()=>wit,Chip:()=>t0e,Constraint:()=>Pit,Crystal:()=>Yit,Cutout:()=>Fit,Diode:()=>Eit,FabricationNotePath:()=>Nit,FabricationNoteText:()=>Dit,Footprint:()=>Xrt,Group:()=>BV,Hole:()=>qme,Inductor:()=>Git,Jumper:()=>Tit,Keepout:()=>zV,Led:()=>Mit,Mosfet:()=>Zit,Net:()=>Bme,NetAlias:()=>Oit,NormalComponent:()=>qb,PcbTrace:()=>Vme,PinHeader:()=>jit,PlatedHole:()=>Gme,Port:()=>yw,Potentiometer:()=>$it,PowerSource:()=>Cit,PrimitiveComponent:()=>s1,PushButton:()=>Wit,Renderable:()=>Ome,Resistor:()=>Rit,Resonator:()=>Vit,SchematicText:()=>Kit,SilkscreenCircle:()=>zit,SilkscreenLine:()=>Iit,SilkscreenPath:()=>Hme,SilkscreenRect:()=>Uit,SilkscreenText:()=>UV,SmtPad:()=>OV,Subcircuit:()=>Lit,Switch:()=>Qit,Trace:()=>BT,TraceHint:()=>Kme,Transistor:()=>Xit,Via:()=>kit});var Crt=Z0("tscircuit:renderable"),R9=["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"],Rrt=0,Ome=class{constructor(e){et(this,"renderPhaseStates");et(this,"shouldBeRemoved",!1);et(this,"children");et(this,"isPcbPrimitive",!1);et(this,"isSchematicPrimitive",!1);et(this,"_renderId");et(this,"_currentRenderPhase",null);et(this,"_asyncEffects",[]);et(this,"parent",null);this._renderId=`${Rrt++}`,this.children=[],this.renderPhaseStates={};for(const t of R9)this.renderPhaseStates[t]={initialized:!1,dirty:!1}}_markDirty(e){var n;this.renderPhaseStates[e].dirty=!0;const t=R9.indexOf(e);for(let i=t+1;i<R9.length;i++)this.renderPhaseStates[R9[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
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){Crt(`${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 R9)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=R9.indexOf(e)-1;if(a>=0){const c=R9[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))}},J7={},zme=r=>{const e=Object.fromEntries(Object.entries(r).map(([t,n])=>[t.toLowerCase(),n]));Object.assign(J7,r),Object.assign(J7,e)},Art=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 NV(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 DV={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=DV.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},Prt={...DV,getChildren:r=>r.children.filter(e=>!e.isSubcircuit)},Ume={...DV,getChildren:r=>r.children.filter(e=>e.isSubcircuit)},Ime=r=>r.replace(/ pin/g," port").replace(/ subcircuit\./g," group[isSubcircuit=true]").replace(/([^ ])\>([^ ])/g,"$1 > $2").trim(),LV={adapter:Prt,cacheResults:!0},s1=class extends Ome{constructor(t){super(t);et(this,"parent",null);et(this,"children");et(this,"childrenPendingRemoval");et(this,"props");et(this,"_parsedProps");et(this,"externallyAddedAliases");et(this,"isPrimitiveContainer",!1);et(this,"source_group_id",null);et(this,"source_component_id",null);et(this,"schematic_component_id",null);et(this,"pcb_component_id",null);et(this,"cad_component_id",null);et(this,"_cachedSelectAllQueries",new Map);et(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 Art(this.lowercaseComponentName,this.props,n.error.format())}get config(){return{componentName:"",zodProps:I.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 uc(pf(t.pcbX??0,t.pcbY??0),i2((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 uc(((i=this.parent)==null?void 0:i._computePcbGlobalTransformBeforeLayout())??Q0(),uc(pf(n.x,n.y),i2((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 uc(pf(c.x,c.y),PT(),pf(-c.x,-c.y)),uc(((a=this.parent)==null?void 0:a._computePcbGlobalTransformBeforeLayout())??Q0(),PT(),this.computePcbPropsTransform())}}return uc(((o=this.parent)==null?void 0:o._computePcbGlobalTransformBeforeLayout())??Q0(),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 uc(pf(t.schX??0,t.schY??0))}computeSchematicGlobalTransform(){var n,i;const t=this._getSchematicGlobalManualPlacementTransform(this);return t||uc(((i=(n=this.parent)==null?void 0:n.computeSchematicGlobalTransform)==null?void 0:i.call(n))??Q0(),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 K0&&i===0)return u;if(s in K0&&i===90)return s;if(c in K0&&i===180)return c;if(l in K0&&i===270)return l;if(a in K0&&(i===0||i===180))return a;if(o in K0&&(i===90||i===270))return o;if(n in K0)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?K0[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&&NV(t,s.selector)||t.props.name===s.selector)return jr(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(NV(t,a.selector)||t.props.name===a.selector)return jr(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((NV(t,o.selector)||t.props.name===o.selector)&&o.relative_to==="group_center")return uc(((a=this.parent)==null?void 0:a._computePcbGlobalTransformBeforeLayout())??Q0(),pf(o.center.x,o.center.y));return null}_getGlobalPcbPositionBeforeLayout(){return jr(this._computePcbGlobalTransformBeforeLayout(),{x:0,y:0})}_getGlobalSchematicPositionBeforeLayout(){return jr(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=Ime(t),i=q4(n,this,LV);if(i.length>0)return this._cachedSelectAllQueries.set(t,i),i;const[a,...o]=n.split(" "),s=gw(a,this,{adapter:Ume});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=Ime(t);n!=null&&n.port&&(n.type="port");let a=null;if(n!=null&&n.type&&(a=q4(i,this,LV).find(u=>u.lowercaseComponentName===n.type)),a??(a=gw(i,this,LV)),a)return this._cachedSelectOneQueries.set(t,a),a;const[o,...s]=i.split(" "),l=gw(o,this,{adapter:Ume});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()}},Nrt=class extends s1{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:I.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 Drt(r,e){return new Nrt(r,e)}function Lrt(r,e){const t=r;return t.__tsci={...e},r}var kme={supportsMutation:!0,createInstance(r,e){const t=J7[r];if(!t)throw Object.keys(J7).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 Lrt(new t(e),{})}catch(n){return Drt(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:()=>vw.DefaultEventPriority,getCurrentUpdatePriority:()=>vw.DefaultEventPriority,resolveUpdatePriority:()=>vw.DefaultEventPriority,setCurrentUpdatePriority:()=>{},maySuspendCommit:()=>!1,supportsHydration:!1},FT;Wc.version.startsWith("19.")?FT=zB(kme):FT=kB(kme);var Ort=r=>{const e={children:[],props:{name:"$root"},add(a){a.parent=this,this.children.push(a)},computePcbGlobalTransform(){return Q0()}},t=[],n=FT.createContainer(e,0,null,!1,null,"tsci",a=>{console.log("Error in createContainer"),console.error(a),t.push(a)},null);if(Wc.version.startsWith("19.")?(FT.updateContainerSync(r,n,null,()=>{}),FT.flushSyncWork()):FT.updateContainer(r,n,null,()=>{}),t.length>0)throw t[0];const i=FT.getPublicRootInstance(n);return i||e.children[0]},tP=(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}"`)},zrt=(r,e)=>{if(!r)return;const t={},n={};for(const[i,a]of Object.entries(r)){const o=tP(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},Urt=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 Fme(r){const e=[];for(let t=0;t<r.length-1;t++)e.push([r[t],r[t+1]]);return e}var Irt=I.object({name:I.string()}),Bme=class extends s1{constructor(){super(...arguments);et(this,"source_net_id")}get config(){return{componentName:"Net",zodProps:Irt}}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=Fme(a);for(const[l,c]of o){const u=l.ports.map(A=>A._getGlobalPcbPositionBeforeLayout()),f=c.ports.map(A=>A._getGlobalPcbPositionBeforeLayout());let d=1/0,v=[-1,-1];for(let A=0;A<u.length;A++){const z=u[A];for(let V=0;V<f.length;V++){const q=f[V],X=Math.sqrt((z.x-q.x)**2+(z.y-q.y)**2);X<d&&(d=X,v=[A,V])}}const g=l.ports[v[0]],w=c.ports[v[1]],S=t.toArray().filter(A=>A.type==="pcb_smtpad"||A.type==="pcb_trace"||A.type==="pcb_plated_hole"||A.type==="pcb_hole"||A.type==="source_port"||A.type==="pcb_port"),{solution:b}=yH(S.concat([{type:"source_trace",source_trace_id:"__net_trace_tmp",connected_source_port_ids:[g.source_port_id,w.source_port_id]}])),T=b[0];if(!T){this.renderError({pcb_trace_error_id:"",pcb_trace_id:"__net_trace_tmp",pcb_component_ids:[g.pcb_component_id,w.pcb_component_id].filter(Boolean),pcb_port_ids:[g.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(T)}}renderError(t){var n;if(typeof t=="string")return super.renderError(t);(n=this.root)==null||n.db.pcb_trace_error.insert(t)}},jme=(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 Bme({name:t.split("net.")[1]});n.add(i)}}},OV=class extends s1{constructor(){super(...arguments);et(this,"pcb_smtpad_id",null);et(this,"matchedPort",null);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SmtPad",zodProps:DH}}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 v,g,w,S,b,T,A,z,V,q;if((v=this.root)!=null&&v.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=SE(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=((g=this.parent)==null?void 0:g.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(X=>X.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:(T=this.matchedPort)==null?void 0:T.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(X=>X.toString()),x:o.x,y:o.y,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((A=this.getGroup())==null?void 0:A.pcb_group_id)??void 0}):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(X=>X.toString()),subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((z=this.getGroup())==null?void 0:z.pcb_group_id)??void 0}),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:((q=this.getGroup())==null?void 0:q.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)}},Hme=class extends s1{constructor(){super(...arguments);et(this,"pcb_silkscreen_path_id",null);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenPath",zodProps:eV}}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 v=jr(o,{x:d.x,y:d.y});return{...d,x:v.x,y:v.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}}},krt=I.object({route:I.array(IA),source_trace_id:I.string().optional()}),Vme=class extends s1{constructor(){super(...arguments);et(this,"pcb_trace_id",null);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbTrace",zodProps:krt}}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:v,y:g,...w}=d,S=jr(s,{x:v,y:g});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}}},Gme=class extends s1{constructor(){super(...arguments);et(this,"pcb_plated_hole_id",null);et(this,"matchedPort",null);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PlatedHole",zodProps:TH}}getAvailablePcbLayers(){return["top","inner1","inner2","bottom"]}getPcbSize(){const{_parsedProps:t}=this;if(t.shape==="circle")return{width:t.outerDiameter,height:t.outerDiameter};if(t.shape==="oval"||t.shape==="pill")return{width:t.outerWidth,height:t.outerHeight};if(t.shape==="circular_hole_with_rect_pad")return{width:t.rectPadWidth,height:t.rectPadHeight};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,v,g,w,S,b,T,A;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 z=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=z.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:((v=this.getGroup())==null?void 0:v.pcb_group_id)??void 0})}else if(n.shape==="pill"||n.shape==="oval"){const z=t.pcb_plated_hole.insert({pcb_component_id:a,pcb_port_id:(g=this.matchedPort)==null?void 0:g.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=z.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})}else if(n.shape==="circular_hole_with_rect_pad"){const z=t.pcb_plated_hole.insert({pcb_component_id:a,pcb_port_id:(T=this.matchedPort)==null?void 0:T.pcb_port_id,hole_diameter:n.holeDiameter,rect_pad_width:n.rectPadWidth,rect_pad_height:n.rectPadHeight,shape:"circular_hole_with_rect_pad",port_hints:this.getNameAndAliases(),x:i.x,y:i.y,layers:["top","bottom"],subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((A=this.getGroup())==null?void 0:A.pcb_group_id)??void 0});this.pcb_plated_hole_id=z.pcb_plated_hole_id}}doInitialPcbPortAttachment(){var n,i;if((n=this.root)!=null&&n.pcbDisabled)return;const{db:t}=this.root;t.pcb_plated_hole.update(this.pcb_plated_hole_id,{pcb_port_id:(i=this.matchedPort)==null?void 0:i.pcb_port_id})}},zV=class extends s1{constructor(){super(...arguments);et(this,"pcb_keepout_id",null);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Keepout",zodProps:ZH}}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=SE(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)}},qme=class extends s1{constructor(){super(...arguments);et(this,"pcb_hole_id",null);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Hole",zodProps:LH}}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})}},UV=class extends s1{constructor(){super(...arguments);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenText",zodProps:JH}}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}}},Frt=({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 UV({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})},Brt=({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 OV({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 OV({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 Hme({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 Gme({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 zV({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 zV({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 qme({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(Frt({elm:o,pinLabels:n,readableRotation:s})):o.text==="{REF}"&&a.push(new UV({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 Vme({route:o.route}));return a};function $me(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=$me(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 jrt(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 Hrt=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},Vrt=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}},Grt=I.object({name:I.string().optional(),pinNumber:I.number().optional(),aliases:I.array(I.string()).optional()}),yw=class extends s1{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);et(this,"source_port_id",null);et(this,"pcb_port_id",null);et(this,"schematic_port_id",null);et(this,"schematicSymbolPortDef",null);et(this,"matchedComponents");et(this,"facingDirection",null);et(this,"originDescription",null);n.originDescription&&(this.originDescription=n.originDescription),this.matchedComponents=[]}get config(){return{componentName:"Port",zodProps:Grt}}_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=uc(this.parent.computeSchematicGlobalTransform(),pf(-t.center.x,-t.center.y));return jr(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 jr(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(!Hrt(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=Vrt(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=jrt(a,o);const c=t.source_port.get(this.source_port_id);let u;for(const v of(c==null?void 0:c.port_hints)??[])v.match(/^(pin)?\d+$/)||v.match(/^(left|right)/)&&!(c!=null&&c.name.match(/^(left|right)/))||(u=v);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)}},Wme=r=>{const e=r.find(t=>/^(pin)?\d+$/.test(t));return e?Number.parseInt(e.replace(/^pin/,"")):null};function nP(r,e){var a;const t=Wme(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 yw({pinNumber:t,aliases:i})}var qrt=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},$rt=r=>{var a,o,s,l;if(qrt(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 Yme(r){return r.leftSide!==void 0}var Wrt=r=>{var S,b,T,A,z,V,q,X;const e=r.portDistanceFromEdge??.4;let t=r.schPortArrangement?$rt(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 W=Math.floor(i/2);t={leftSize:i-W,rightSize:W,topSize:0,bottomSize:0}}t||(t={leftSize:0,rightSize:0,topSize:0,bottomSize:0});const a=({side:W,sideIndex:K,truePinIndex:Y})=>{var pe,ye,Te,xe;if(!r.schPortArrangement||!Yme(r.schPortArrangement))return Y+1;const ce={left:"top-to-bottom",bottom:"left-to-right",right:"bottom-to-top",top:"right-to-left"}[W],he=((ye=(pe=r.schPortArrangement)==null?void 0:pe[`${W}Side`])==null?void 0:ye.direction)??ce,ue=(xe=(Te=r.schPortArrangement)==null?void 0:Te[`${W}Side`])==null?void 0:xe.pins;let Se=K;return he!==ce&&(Se=ue.length-K-1),tP(ue[Se],r.pinLabels)},o=[];let s=0,l=0;for(let W=0;W<t.leftSize;W++){const K=a({side:"left",sideIndex:W,truePinIndex:l}),Y=((S=r.numericSchPinStyle)==null?void 0:S[`pin${K}`])??((b=r.numericSchPinStyle)==null?void 0:b[K]);Y!=null&&Y.topMargin&&(s+=Y.topMargin),o.push({trueIndex:l,pinNumber:K,side:"left",distanceFromOrthogonalEdge:s}),Y!=null&&Y.bottomMargin&&(s+=Y.bottomMargin),W===t.leftSize-1?n.left=s:s+=r.schPinSpacing,l++}s=0;for(let W=0;W<t.bottomSize;W++){const K=a({side:"bottom",sideIndex:W,truePinIndex:l}),Y=((T=r.numericSchPinStyle)==null?void 0:T[`pin${K}`])??((A=r.numericSchPinStyle)==null?void 0:A[K]);Y!=null&&Y.leftMargin&&(s+=Y.leftMargin),o.push({trueIndex:l,pinNumber:K,side:"bottom",distanceFromOrthogonalEdge:s}),Y!=null&&Y.rightMargin&&(s+=Y.rightMargin),W===t.bottomSize-1?n.bottom=s:s+=r.schPinSpacing,l++}s=0;for(let W=0;W<t.rightSize;W++){const K=a({side:"right",sideIndex:W,truePinIndex:l}),Y=((z=r.numericSchPinStyle)==null?void 0:z[`pin${K}`])??((V=r.numericSchPinStyle)==null?void 0:V[K]);Y!=null&&Y.bottomMargin&&(s+=Y.bottomMargin),o.push({trueIndex:l,pinNumber:K,side:"right",distanceFromOrthogonalEdge:s}),Y!=null&&Y.topMargin&&(s+=Y.topMargin),W===t.rightSize-1?n.right=s:s+=r.schPinSpacing,l++}s=0;for(let W=0;W<t.topSize;W++){const K=a({side:"top",sideIndex:W,truePinIndex:l}),Y=((q=r.numericSchPinStyle)==null?void 0:q[`pin${K}`])??((X=r.numericSchPinStyle)==null?void 0:X[K]);Y!=null&&Y.rightMargin&&(s+=Y.rightMargin),o.push({trueIndex:l,pinNumber:K,side:"top",distanceFromOrthogonalEdge:s}),Y!=null&&Y.leftMargin&&(s+=Y.leftMargin),W===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(W=>W.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 v={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}},g={left:{x:0,y:-1},right:{x:0,y:1},top:{x:-1,y:0},bottom:{x:1,y:0}},w=o.map(W=>{const{distanceFromOrthogonalEdge:K,side:Y}=W,ce=v[Y],he=g[Y];return{x:ce.x+K*he.x,y:ce.y+K*he.y,...W}});return{getPortPositionByPinNumber(W){const K=w.find(Y=>Y.pinNumber.toString()===W.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}},Yrt=Z0("tscircuit:core:footprint"),Xrt=class extends s1{get config(){return{componentName:"Footprint",zodProps:UH}}doInitialPcbFootprintLayout(){var d,v,g,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:T,componentSelector:A,edge:z})=>({component:b,selector:T,componentSelector:A,edge:z,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:T})=>T===b)}const o=new oV,s={};function l(b){return b in s||(s[b]=new YA(b),o.addEditVariable(s[b],Qg.weak)),s[b]}for(const{selector:b,bounds:T}of i){const A=l(`${b}_x`),z=l(`${b}_y`);o.suggestValue(A,T.center.x),o.suggestValue(z,T.center.y)}for(const b of e){const T=b._parsedProps;if("xDist"in T){const{xDist:A,left:z,right:V,edgeToEdge:q,centerToCenter:X}=n(T),W=l(`${z}_x`),K=l(`${V}_x`),Y=(v=a(z))==null?void 0:v.bounds,ce=(g=a(V))==null?void 0:g.bounds;if(X){const he=new Sg(K,[-1,W]);o.addConstraint(new bb(he,o1.Eq,T.xDist,Qg.required))}else if(q){const he=new Sg(K,-ce.width/2,[-1,W],-Y.width/2);o.addConstraint(new bb(he,o1.Eq,T.xDist,Qg.required))}}else if("yDist"in T){const{yDist:A,top:z,bottom:V,edgeToEdge:q,centerToCenter:X}=T,W=l(`${z}_y`),K=l(`${V}_y`),Y=(w=a(z))==null?void 0:w.bounds,ce=(S=a(V))==null?void 0:S.bounds;if(X){const he=new Sg(W,[-1,K]);o.addConstraint(new bb(he,o1.Eq,T.yDist,Qg.required))}else if(q){const he=new Sg(W,Y.height/2,[-1,K],-ce.height/2);o.addConstraint(new bb(he,o1.Eq,T.yDist,Qg.required))}}else if("sameY"in T){const{for:A}=T;if(A.length<2)continue;const z=A.map(q=>l(`${q}_y`)),V=new Sg(...z.slice(1));o.addConstraint(new bb(V,o1.Eq,z[0],Qg.required))}else if("sameX"in T){const{for:A}=T;if(A.length<2)continue;const z=A.map(q=>l(`${q}_x`)),V=new Sg(...z.slice(1));o.addConstraint(new bb(V,o1.Eq,z[0],Qg.required))}}o.updateVariables(),Yrt.enabled&&(console.log("Solution to layout constraints:"),console.table(Object.entries(s).map(([b,T])=>({var:b,val:T.value()}))));const c={left:1/0,right:-1/0,top:-1/0,bottom:1/0};for(const{selector:b,bounds:{width:T,height:A}}of i){const z=l(`${b}_x`),V=l(`${b}_y`),q=z.value()-T/2,X=z.value()+T/2,W=V.value()+A/2,K=V.value()-A/2;c.left=Math.min(c.left,q),c.right=Math.max(c.right,X),c.top=Math.max(c.top,W),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:T}of i){const A=l(`${T}_x`),z=l(`${T}_y`);b._setPositionFromLayout({x:A.value()+u.x,y:z.value()+u.y})}}},Zrt=(r,e)=>{if(!r)return;const t={};for(const[n,i]of Object.entries(r)){const a=tP(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},Xme=class{constructor({input:e}){et(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}},Qrt=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}},Zme=["top","bottom","inner1","inner2"],eL=(r,e=[])=>{var s;const t=[];if(e.length===0){const l=r[0].layers;for(const c of l)t.push(...eL(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)?[]:eL(r.slice(1),e.concat([a]));const o=(n.optional_via?Zme:Zme.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(...eL(r.slice(1),e.concat(l)));return t};function Qme(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 nC(r,e){return Math.hypot(r.x-e.x,r.y-e.y)}var Krt=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(nC(t,i),nC(t,a)),s=Math.min(nC(n,i),nC(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],v=nC(c,f),g=nC(c,d);v<g?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},Jrt=(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 eit(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=Jrt(r,i);a<n&&(t=i,n=a)}return t}var tit=(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},IV=r=>({up:"bottom",down:"top",left:"right",right:"left"})[r]??null,kV=({firstEdge:r,firstEdgePort:e,firstDominantDirection:t,lastEdge:n,lastEdgePort:i,lastDominantDirection:a})=>{if(r&&e)return kV({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=>r9(s.from,s.to)>.01),o};function nit(r){try{return[r(),null]}catch(e){return[null,e]}}function rit(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 iit=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}},tL=({port:r,anchorPos:e,schDisplayLabel:t,source_trace_id:n},{db:i})=>{const a=iit(r),o=r.facingDirection==="left"||r.facingDirection==="right",s={x:e.x+a.horzPortDirection*a.schBoxHorzOffset,y:e.y+a.vertPortDirectionOffset*a.schBoxVertOffset},l=o?{x:s.x,y:s.y-.5}:s;i.schematic_net_label.insert({anchor_side:"top",center:l,source_net_id:r.source_port_id,text:t,anchor_position:l,symbol_name:"ground_horz"});const c=[{from:{x:e.x,y:e.y},to:{x:e.x,y:e.y+a.handleUp*a.schBoxVertOffset}},{from:{x:e.x,y:e.y},to:s}];o&&c.push({from:s,to:l}),i.schematic_trace.insert({edges:c,junctions:[],source_trace_id:n})},FV=({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},ait=({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(Q4([i.from,i.to],[w.from,w.to],{lineThickness:.01})){const T=a==="vertical"?i.from.x:w.from.x,A=a==="vertical"?w.from.y:i.from.y,z={x:T,y:A};o.push({otherEdge:w,crossingPoint:z,distanceFromEdgeFrom:r9(i.from,z)})}}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=sV(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},v=r9(d,i.to)<c,g=[{from:i.from,to:f},{from:f,to:d,is_crossing:!0},{from:d,to:i.to}];t.splice(n,1,...g),n+=g.length-2,v&&n++}return t},oit=(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,v=f*u+d;return u>=Math.min(e.from.x,e.to.x)&&u<=Math.max(e.from.x,e.to.x)&&v>=Math.min(e.from.y,e.to.y)&&v<=Math.max(e.from.y,e.to.y)?{x:u,y:v}: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,v=f*u+d;return u>=Math.min(r.from.x,r.to.x)&&u<=Math.max(r.from.x,r.to.x)&&v>=Math.min(r.from.y,r.to.y)&&v<=Math.max(r.from.y,r.to.y)?{x:u,y:v}: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},sit=({edges:r,db:e,source_trace_id:t})=>{const n=FV({db:e,source_trace_id:t,sameNetOnly:!0}).flatMap(i=>i.edges);for(const i of r)for(const a of n){const o=oit(i,a);if(o)return`${o.x}${o.y}`,[{x:o.x,y:o.y}]}return[]},lit=(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 cit(r){var a,o,s,l,c,u,f,d,v;let e=1/0,t=1/0,n=-1/0,i=-1/0;for(const g of r){let w,S,b,T;g.type==="schematic_component"?(w=(a=g.center)==null?void 0:a.x,S=(o=g.center)==null?void 0:o.y,b=(s=g.size)==null?void 0:s.width,T=(l=g.size)==null?void 0:l.height):g.type==="schematic_box"?(w=g.x,S=g.y,b=g.width,T=g.height):g.type==="schematic_port"?(w=(c=g.center)==null?void 0:c.x,S=(u=g.center)==null?void 0:u.y,b=.2,T=.2):g.type==="schematic_text"&&(w=(f=g.position)==null?void 0:f.x,S=(d=g.position)==null?void 0:d.y,b=(((v=g.text)==null?void 0:v.length)??0)*.1,T=.2),typeof w=="number"&&typeof S=="number"&&typeof b=="number"&&typeof T=="number"&&(e=Math.min(e,w-b/2),n=Math.max(n,w+b/2),t=Math.min(t,S-T/2),i=Math.max(i,S+T/2))}return{minX:e,maxX:n,minY:t,maxY:i}}function uit(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 fit=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?lV(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=cit(e.toArray());return i.push(...uit(a,{padding:1})),i};function dit({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 hit=({edges:r,db:e,source_trace_id:t})=>{e.source_trace.get(t);const n=FV({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&&Q4([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()}},pit=(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 v=0,g=f.length-1;v<f.length;g=v++){const w=f[v].x,S=f[v].y,b=f[g].x,T=f[g].y;S>u.y!=T>u.y&&u.x<(b-w)*(u.y-S)/(T-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)},nL=r=>({...r._getGlobalPcbPositionAfterLayout(),layers:r.getAvailablePcbLayers()}),BT=class extends s1{constructor(t){super(t);et(this,"source_trace_id",null);et(this,"pcb_trace_id",null);et(this,"schematic_trace_id",null);et(this,"_portsRoutedOnPcb");et(this,"subcircuit_connectivity_map_key",null);et(this,"_traceConnectionHash",null);this._portsRoutedOnPcb=[]}get config(){return{zodProps:zH,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
|
-
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(){jme(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(v=>v.subcircuit_connectivity_map_key===this.subcircuit_connectivity_map_key&&v.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=dit({ports:o,nets:c}),f=t.source_trace.insert({connected_source_port_ids:o.map(v=>v.port.source_port_id),connected_source_net_ids:c.map(v=>v.source_net_id),subcircuit_id:(d=this.getSubcircuit())==null?void 0:d.subcircuit_id,max_length:lit(o.map(v=>v.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;pit(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,Y,ce,he;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=(Y=a._parsedProps.pcbRouteCache)==null?void 0:Y.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],pe=u[0].net.getAllConnectedPorts().filter(Te=>Te!==ue);if(pe.length===0){console.log("Nothing to connect this port to, the net is empty. TODO should emit a warning!");return}const ye=eit(ue,pe);l.push(ye)}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=[nL(l[0]),nL(l[1])]:w=[nL(l[0]),...d,nL(l[1])];const S=eL(w),b=w3(this.root.db.toArray()),[T,A]=nit(()=>X4(this.root.db.toArray()));if(A){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: ${A.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 T)if(ue.connectedTo.length>0){const pe=b.getNetConnectedToId(ue.connectedTo[0]);pe&&ue.connectedTo.push(pe)}let z=[];if(S.length===0)z=w;else{const ue=S[0].layer_path;z=w.map((Se,pe)=>Se.via?{...Se,via_to_layer:ue[pe]}:{...Se,layers:[ue[pe]]})}z[0].pcb_port_id=l[0].pcb_port_id,z[z.length-1].pcb_port_id=l[1].pcb_port_id;const V=[];for(const[ue,Se]of Fme(z)){const pe="via_to_layer"in ue?ue.via_to_layer:null,ye=2,Te="layers"in ue&&ue.layers.length===1?ue.layers[0]:pe??"top",xe="layers"in Se&&Se.layers.length===1?Se.layers[0]:pe??"top",Pe="pcb_port_id"in ue?ue.pcb_port_id:null,De="pcb_port_id"in Se?Se.pcb_port_id:null,ke=this.getSubcircuit()._parsedProps.minTraceWidth??.16,Re=new Y4({OBSTACLE_MARGIN:ke*2,isRemovePathLoopsEnabled:!0,optimizeWithGoalBoxes:!!(Pe&&De),connMap:b,input:{obstacles:T,minTraceWidth:ke,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)-ye,maxX:Math.max(ue.x,Se.x)+ye,minY:Math.min(ue.y,Se.y)-ye,maxY:Math.max(ue.y,Se.y)+ye}}});let $e=null;try{$e=Re.solveAndMapToTraces()}catch(ht){this.renderError({type:"pcb_trace_error",pcb_trace_error_id:this.source_trace_id,error_type:"pcb_trace_error",message:`error solving route: ${ht.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(ht=>ht.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:l.map(ht=>ht.pcb_component_id)});return}const[Ke]=$e;pe&&(Ke.route=Ke.route.map(ht=>(ht.route_type==="wire"&&!ht.layer&&(ht.layer=pe),ht))),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 q=Krt(V),X=rit(q),W=t.pcb_trace.insert({route:q,source_trace_id:this.source_trace_id,subcircuit_id:(he=this.getSubcircuit())==null?void 0:he.subcircuit_id,trace_length:X});this._portsRoutedOnPcb=l,this.pcb_trace_id=W.pcb_trace_id;for(const ue of q)ue.route_type==="via"&&t.pcb_via.insert({pcb_trace_id:W.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(q,l)}_doInitialSchematicTraceRenderWithDisplayLabel(){var V,q,X,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,v=s[1].port;if(!v.source_port_id)throw new Error(`Missing source_port_id for the 'to' port (${c}).`);const g=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===v.source_port_id),[S,b]=o.map(({port:K})=>K),A=((q=S.parent)==null?void 0:q.config.shouldRenderAsSchematicBox)?`${(X=S==null?void 0:S.parent)==null?void 0:X.props.name}_${S==null?void 0:S.props.name}`:`${(W=b==null?void 0:b.parent)==null?void 0:W.props.name}_${b==null?void 0:b.props.name}`,z=this.props.schDisplayLabel??A;if(g&&g.text!==z&&(g.text=`${z} / ${g.text}`),w&&(w==null?void 0:w.text)!==z&&(w.text=`${z} / ${w.text}`),z!=null&&z.toLocaleLowerCase().includes("gnd")||z!=null&&z.toLocaleLowerCase().includes("ground")){!g&&!w?(tL({port:f,anchorPos:u,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t}),tL({port:v,anchorPos:d,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t})):g?w||tL({port:v,anchorPos:d,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t}):tL({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??A,source_net_id:v.source_port_id,anchor_position:d,center:d,anchor_side:IV(v.facingDirection)??"bottom"}),g||t.schematic_net_label.insert({text:this.props.schDisplayLabel??A,source_net_id:f.source_port_id,anchor_position:u,center:u,anchor_side:IV(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=fit(this),v=o.map(({port:Pe})=>({port:Pe,position:Pe._getGlobalSchematicPositionAfterLayout(),schematic_port_id:Pe.schematic_port_id??void 0,facingDirection:Pe.facingDirection}));if(v.length===1&&s.length===1){const Pe=s[0].net,{port:De,position:ke}=v[0];t.schematic_net_label.insert({text:Pe._parsedProps.name,source_net_id:Pe.source_net_id,anchor_position:ke,center:ke,anchor_side:IV(De.facingDirection)??"bottom"});return}if(v.length<2)return;f.pointsToConnect=v.map(({position:Pe})=>({...Pe,layer:"top"}));const w=Qrt(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 T=Y4,A=!1;this.getSubcircuit().props._schDirectLineRoutingEnabled&&(T=Xme,A=!0);let V=new T({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 Xme({input:b}).solveAndMapToTraces(),A=!0}const[{route:q}]=V;let X=[];for(let Pe=0;Pe<q.length-1;Pe++)X.push({from:q[Pe],to:q[Pe+1]});const W=this.source_trace_id;let K=[];if(!A){hit({edges:X,db:t,source_trace_id:W});const Pe=FV({db:t,source_trace_id:W,differentNetOnly:!0}).flatMap(De=>De.edges);X=ait({edges:X,otherEdges:Pe}),K=sit({edges:X,db:t,source_trace_id:this.source_trace_id})}const Y=X[X.length-1],ce=v[v.length-1],he=Qme(Y);X.push(...kV({lastEdge:Y,lastEdgePort:ce,lastDominantDirection:he}));const ue=X[0],Se=v[0],pe=Qme(ue);if(X.unshift(...kV({firstEdge:ue,firstEdgePort:Se,firstDominantDirection:pe})),!this.source_trace_id)throw new Error("Missing source_trace_id for schematic trace insertion.");if(this.getSubcircuit()._parsedProps.schTraceAutoLabelEnabled&&tit(K,X)>=5&&(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection())){this._doInitialSchematicTraceRenderWithDisplayLabel();return}const ye=t.schematic_trace.insert({source_trace_id:this.source_trace_id,edges:X,junctions:K});this.schematic_trace_id=ye.schematic_trace_id,u!=null&&u._connectedSchematicPortPairs&&u._connectedSchematicPortPairs.add(c)}},mit=Z0("tscircuit:core"),vit=I.object({x:r2,y:r2,z:r2}),qb=class extends s1{constructor(t){super(t);et(this,"reactSubtrees",[]);et(this,"_impliedFootprint");et(this,"isPrimitiveContainer",!0);et(this,"_asyncSupplierPartNumbers");et(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,v,g,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 A in a){const z=a[A].pins;if(Array.isArray(z))for(const V of z){const q=tP(V,this._parsedProps.pinLabels);i.push(new yw({pinNumber:q,aliases:((l=t.additionalAliases)==null?void 0:l[`pin${q}`])??[]},{originDescription:`schPortArrangement:${A}`}))}}const b=["left","right","top","bottom"];let T=1;for(const A of b){const z=a[`${A}Size`];for(let V=0;V<z;V++)i.push(new yw({pinNumber:T++,aliases:((c=t.additionalAliases)==null?void 0:c[`pin${T}`])??[]},{originDescription:`schPortArrangement:${A}`}))}}const o=this._parsedProps.pinLabels;if(o)for(let[b,T]of Object.entries(o)){b=b.replace("pin","");let A=i.find(q=>q._parsedProps.pinNumber===Number(b));const z=Array.isArray(T)?T[0]:T,V=Array.isArray(T)?T.slice(1):[];A?(A.externallyAddedAliases.push(z,...V),A.props.name=z):(A=new yw({pinNumber:parseInt(b),name:z,aliases:[...V,...((u=t.additionalAliases)==null?void 0:u[`pin${parseInt(b)}`])??[]]},{originDescription:`pinLabels:pin${b}`}),i.push(A))}if(n.schematicSymbolName){const b=K0[this._getSchematicSymbolNameOrThrow()];if(!b)return;for(const T of b.ports){const A=Wme(T.labels);if(!A)continue;const z=i.find(V=>V._parsedProps.pinNumber===Number(A));if(z)z.schematicSymbolPortDef=T;else{const V=nP(T.labels.concat(((f=t.additionalAliases)==null?void 0:f[`pin${A}`])??[]));V&&(V.originDescription=`schematicSymbol:labels[0]:${T.labels[0]}`,V.schematicSymbolPortDef=T,i.push(V))}}this.addAll(i)}if(!this._getSchematicPortArrangement()){const b=this.getPortsFromFootprint(t);for(const T of b)i.some(A=>A.isMatchingAnyOf(T.getNameAndAliases()))||i.push(T)}for(let b=1;b<=(t.pinCount??this._getPinCount());b++){if(!a||i.find(A=>A._parsedProps.pinNumber===b))continue;let T=[...((d=a.leftSide)==null?void 0:d.pins)??[],...((v=a.rightSide)==null?void 0:v.pins)??[],...((g=a.topSide)==null?void 0:g.pins)??[],...((w=a.bottomSide)==null?void 0:w.pins)??[]].map(A=>tP(A,this._parsedProps.pinLabels));["leftSize","rightSize","topSize","bottomSize","leftPinCount","rightPinCount","topPinCount","bottomPinCount"].some(A=>A in a)&&(T=Array.from({length:this._getPinCount()},(A,z)=>z+1)),T.includes(b)&&i.push(new yw({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=F4.string(a).soup(),l=Brt({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=zA.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=K0[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((v,g)=>{a[String(g+1)]=v});else for(const[v,g]of Object.entries(n.pinLabels??{}))a[v]=Array.isArray(g)?g[0]:g;const o=this._getGlobalSchematicPositionBeforeLayout(),s=this._getSchematicPortArrangement(),l=t.schematic_component.insert({center:o,rotation:n.schRotation??0,size:i.getSize(),port_arrangement:Urt(s),pin_spacing:n.schPinSpacing??.2,pin_styles:zrt(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=kA.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=$me(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:Ort(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&&mit(`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=F4.string(n).soup(),o=[];for(const s of a)if("port_hints"in s&&s.port_hints){const l=nP(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=nP(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=nP(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=K0[t.schematicSymbolName];if(!n)return[];const i=[];for(const o of n.ports){const s=nP(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){jme(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(!Yme(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 Wrt({schWidth:t.schWidth,schHeight:t.schHeight,schPinSpacing:i,numericSchPinStyle:Zrt(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=vit.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:c==="bottom"?-(((o==null?void 0:o.rotation)??0)+s.z)+180:((o==null?void 0:o.rotation)??0)+s.z},pcb_component_id:this.pcb_component_id,source_component_id:this.source_component_id,model_stl_url:"stlUrl"in(i??{})?this._addCachebustToModelUrl(i.stlUrl):void 0,model_obj_url:"objUrl"in(i??{})?this._addCachebustToModelUrl(i.objUrl):void 0,model_jscad:"jscad"in(i??{})?i.jscad:void 0,footprinter_string:typeof this.props.footprint=="string"&&!i?this.props.footprint:void 0})}_addCachebustToModelUrl(t){var i;if(!t||!t.includes("modelcdn.tscircuit.com"))return t;const n=((i=this.root)==null?void 0:i.getClientOrigin())??"";return`${t}${t.includes("?")?"&":"?"}cachebust_origin=${encodeURIComponent(n)}`}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 BT({from:`${this.getSubcircuitSelector()} > port.${n}`,to:o}))}}},git=class{constructor(e,t={}){et(this,"input");et(this,"isRouting",!1);et(this,"solver");et(this,"eventHandlers",{complete:[],error:[],progress:[]});et(this,"cycleCount",0);et(this,"stepDelay");et(this,"timeoutId");this.input=e;const{capacityDepth:n,targetMinCapacity:i,stepDelay:a=0}=t;this.solver=new wV(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||[]}},Kme=class extends s1{constructor(){super(...arguments);et(this,"matchedPort",null)}get config(){return{componentName:"TraceHint",zodProps:iV}}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=>({...jr(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()})}},yit=({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=Y1(r).pcb_component.get(o);if(!l)continue;const c=Y1(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},_it=({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=Y1(r).schematic_component.get(o);if(!l)continue;const c=Y1(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},Jme=({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=_it({circuitJson:r,editEvents:n,manualEditsFile:a})),i.length>0&&(a=yit({circuitJson:r,editEvents:i,manualEditsFile:a})),a},xit=(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},e0e=({db:r,circuitJson:e,subcircuit_id:t,minTraceWidth:n=.1})=>{if(!r&&e&&(r=Y1(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=xit(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=Y1(o);const l=w3(o),c=X4([...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 X,W,K;const S=w.connected_source_port_ids.map(Y=>{const ce=r.source_port.get(Y),he=r.pcb_port.getWhere({source_port_id:Y});return{...ce,...he}});if(S.length<2)return null;const[b,T]=S,A=((X=b.layers)==null?void 0:X[0])??"top",z=((W=T.layers)==null?void 0:W[0])??"top",V=i.filter(Y=>Y.pcb_port_id===b.pcb_port_id||Y.pcb_port_id===T.pcb_port_id),q=[];for(const Y of V){const ce=r.pcb_port.get(Y.pcb_port_id),he=((K=ce==null?void 0:ce.layers)==null?void 0:K[0])??"top";for(const ue of Y.route)q.push({x:ue.x,y:ue.y,layer:he})}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:A},...q,{x:T.x,y:T.y,layer:z}]}}).filter(w=>w!==null),v=r.source_net.list().filter(w=>!t||(a==null?void 0:a.has(w.subcircuit_id))),g=[];for(const w of v){const S=r.source_trace.list().filter(b=>{var T;return(T=b.connected_source_net_ids)==null?void 0:T.includes(w.source_net_id)});g.push({name:w.source_net_id??l.getNetConnectedToId(w.source_net_id),pointsToConnect:S.flatMap(b=>r.pcb_port.list().filter(A=>b.connected_source_port_ids.includes(A.source_port_id)).map(A=>{var z;return{x:A.x,y:A.y,layer:((z=A.layers)==null?void 0:z[0])??"top",pcb_port_id:A.pcb_port_id}}))})}return{simpleRouteJson:{bounds:f,obstacles:c,connections:[...d,...g],layerCount:2,minTraceWidth:n},connMap:l}},BV=class extends qb{constructor(){super(...arguments);et(this,"pcb_group_id",null);et(this,"subcircuit_id",null);et(this,"_hasStartedAsyncAutorouting",!1);et(this,"_asyncAutoroutingResult",null)}get config(){return{zodProps:wH,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 Kme({for:s.pcb_port_selector,offsets:s.offsets}))}doInitialSourceAddConnectivityMapKey(){if(!this.isSubcircuit)return;const{db:t}=this.root,n=this.selectAll("trace"),i=new W4({});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=Z0("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,v;const{db:t}=this.root,n=Z0("tscircuit:core:_runEffectMakeHttpAutoroutingRequest");this._parsedProps;const i=this._getAutorouterConfig(),a=i.serverUrl,o=i.serverMode,s=(g,w)=>{var S;return n("fetching",g),w.headers&&(w.headers["Tscircuit-Core-Version"]=(S=this.root)==null?void 0:S.getCoreVersion()),fetch(g,w)},l=this.root.db.toArray().filter(g=>g.type.startsWith("source_")||g.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:e0e({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:g}=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=g,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(g=>g.json());for(;;){const{autorouting_job:g}=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(g.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(g.has_error)throw t.pcb_autorouting_error.insert({pcb_error_id:c.autorouting_job_id,message:((v=g.error)==null?void 0:v.message)??JSON.stringify(g.error)}),new Error(`Autorouting job failed: ${JSON.stringify(g.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=Z0("tscircuit:core:_runLocalAutorouting");n(`[${this.getString()}] starting local autorouting`);const i=this._getAutorouterConfig(),{simpleRouteJson:a}=e0e({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 git(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((v,g)=>{o.on("complete",w=>{n(`[${this.getString()}] local autorouting complete`),v(w.traces)}),o.on("error",w=>{n(`[${this.getString()}] local autorouting error: ${w.error.message}`),g(w.error)})});o.on("progress",v=>{var g;(g=this.root)==null||g.emit("autorouting:progress",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),...v})}),o.start();try{const v=await s;this._asyncAutoroutingResult={output_pcb_traces:v},this._markDirty("PcbTraceRender")}catch(v){const{db:g}=this.root;throw g.pcb_autorouting_error.insert({pcb_error_id:`pcb_autorouter_error_subcircuit_${this.subcircuit_id}`,message:v instanceof Error?v.message:String(v)}),(d=this.root)==null||d.emit("autorouting:error",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),error:{message:v instanceof Error?v.message:String(v)},simpleRouteJson:a}),v}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=Z0("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=Z0("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=uV(n.toArray()),s=fV(o);cV(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:[]})}}},bit=class extends BV{constructor(){super(...arguments);et(this,"pcb_board_id",null);et(this,"_drcChecksComplete",!1);et(this,"_connectedSchematicPortPairs",new Set)}get isSubcircuit(){return!0}get config(){return{componentName:"Board",zodProps:L7}}get boardThickness(){const{_parsedProps:t}=this;return 1.4}get allLayers(){return["top","bottom","inner1","inner2"]}doInitialPcbBoardAutoSize(){var g;if((g=this.root)!=null&&g.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:T}=w;S===0||b===0||(c=!0,i=Math.min(i,T.x-S/2),a=Math.min(a,T.y-b/2),o=Math.max(o,T.x+S/2),s=Math.max(s,T.y+b/2))}const u=2,f=c?o-i+u*2:0,d=c?s-a+u*2:0,v={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:v})}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),v=Math.min(...u),g=Math.max(...u);i=d-f,a=g-v}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 Q0()}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=AV(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}))}},Sit=new Proxy({},{get:(r,e)=>e}),rP=Sit,wit=class extends qb{get config(){return{componentName:"Capacitor",schematicSymbolName:this.props.polarized?"capacitor_polarized":this.props.symbolName??"capacitor",zodProps:PH,sourceFtype:rP.simple_capacitor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){const e=`${_5(this._parsedProps.capacitance)}F`;return this._parsedProps.schShowRatings&&this._parsedProps.maxVoltageRating?`${e}/${_5(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 BT({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.decouplingFor})),this.add(new BT({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}},t0e=class extends qb{constructor(){super(...arguments);et(this,"schematicBoxDimensions",null)}get config(){return{componentName:"Chip",zodProps:O7,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 BT({from:`${this.getSubcircuitSelector()} > port.${n}`,to:`${this.getSubcircuitSelector()} > port.${i}`}));this._createTracesFromConnectionsProp()}},Eit=class extends qb{constructor(){super(...arguments);et(this,"pos",this.portMap.pin1);et(this,"anode",this.portMap.pin1);et(this,"neg",this.portMap.pin2);et(this,"cathode",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"diode",componentName:"Diode",zodProps:GH,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}},Tit=class extends qb{constructor(){super(...arguments);et(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:EH,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))}},Mit=class extends qb{constructor(){super(...arguments);et(this,"pos",this.portMap.pin1);et(this,"anode",this.portMap.pin1);et(this,"neg",this.portMap.pin2);et(this,"cathode",this.portMap.pin2)}get config(){return{componentName:"Led",schematicSymbolName:this.props.symbolName??"led",zodProps:qH,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}},Cit=class extends qb{constructor(){super(...arguments);et(this,"pos",this.portMap.pin1);et(this,"positive",this.portMap.pin1);et(this,"neg",this.portMap.pin2);et(this,"negative",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"power_factor_meter_horz",componentName:"PowerSource",zodProps:QH,sourceFtype:"simple_power_source"}}initPorts(){this.add(new yw({name:"pin1",pinNumber:1,aliases:["positive","pos"]})),this.add(new yw({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}},Rit=class extends qb{get config(){return{componentName:"Resistor",schematicSymbolName:this.props.symbolName??"boxresistor",zodProps:MH,sourceFtype:"simple_resistor"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${_5(this._parsedProps.resistance)}Ω`}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.pullupFor,this.props.pullupTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.pullupFor&&this.props.pullupTo&&(this.add(new BT({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pullupFor})),this.add(new BT({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}},Ait=["leftedge","rightedge","topedge","bottomedge","center"],Pit=class extends s1{get config(){return{componentName:"Constraint",zodProps:NH}}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=Ait.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}}},Nit=class extends s1{constructor(){super(...arguments);et(this,"fabrication_note_path_id",null)}get config(){return{componentName:"FabricationNotePath",zodProps:YH}}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=jr(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}},Dit=class extends s1{get config(){return{componentName:"FabricationNoteText",zodProps:WH}}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})}},Lit=class extends BV{constructor(e){super({...e,subcircuit:!0})}},Oit=class extends s1{constructor(){super(...arguments);et(this,"source_net_alias_id")}get config(){return{componentName:"NetAlias",zodProps:FH}}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}},zit=class extends s1{constructor(){super(...arguments);et(this,"pcb_silkscreen_circle_id",null);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenCircle",zodProps:rV}}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}}},Uit=class extends s1{constructor(){super(...arguments);et(this,"pcb_silkscreen_rect_id",null);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenRect",zodProps:nV}}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}}},Iit=class extends s1{constructor(){super(...arguments);et(this,"pcb_silkscreen_line_id",null);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenLine",zodProps:tV}}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}}},kit=class extends s1{constructor(){super(...arguments);et(this,"pcb_via_id",null);et(this,"matchedPort",null);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Via",zodProps:XH}}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}},Fit=class extends s1{constructor(){super(...arguments);et(this,"pcb_cutout_id",null);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Cutout",zodProps:zet}}doInitialPcbPrimitiveRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=this.getSubcircuit(),i=((l=this.getGroup())==null?void 0:l.pcb_group_id)??void 0,a=this._getGlobalPcbPositionBeforeLayout();let o;if(t.shape==="rect"){const c={shape:"rect",center:a,width:t.width,height:t.height,subcircuit_id:(n==null?void 0:n.subcircuit_id)??void 0,pcb_group_id:i};o=e.pcb_cutout.insert(c)}else if(t.shape==="circle"){const c={shape:"circle",center:a,radius:t.radius,subcircuit_id:(n==null?void 0:n.subcircuit_id)??void 0,pcb_group_id:i};o=e.pcb_cutout.insert(c)}else if(t.shape==="polygon"){const c=this._computePcbGlobalTransformBeforeLayout(),f={shape:"polygon",points:t.points.map(d=>jr(c,d)),subcircuit_id:(n==null?void 0:n.subcircuit_id)??void 0,pcb_group_id:i};o=e.pcb_cutout.insert(f)}o&&(this.pcb_cutout_id=o.pcb_cutout_id)}getPcbSize(){const{_parsedProps:e}=this;if(e.shape==="rect")return{width:e.width,height:e.height};if(e.shape==="circle")return{width:e.radius*2,height:e.radius*2};if(e.shape==="polygon"){if(e.points.length===0)return{width:0,height:0};let t=1/0,n=-1/0,i=1/0,a=-1/0;for(const o of e.points)t=Math.min(t,o.x),n=Math.max(n,o.x),i=Math.min(i,o.y),a=Math.max(a,o.y);return{width:n-t,height:a-i}}return{width:0,height:0}}_getPcbCircuitJsonBounds(){if(!this.pcb_cutout_id)return super._getPcbCircuitJsonBounds();const{db:e}=this.root,t=e.pcb_cutout.get(this.pcb_cutout_id);if(!t)return super._getPcbCircuitJsonBounds();if(t.shape==="rect")return{center:t.center,bounds:{left:t.center.x-t.width/2,top:t.center.y+t.height/2,right:t.center.x+t.width/2,bottom:t.center.y-t.height/2},width:t.width,height:t.height};if(t.shape==="circle")return{center:t.center,bounds:{left:t.center.x-t.radius,top:t.center.y+t.radius,right:t.center.x+t.radius,bottom:t.center.y-t.radius},width:t.radius*2,height:t.radius*2};if(t.shape==="polygon"){if(t.points.length===0)return super._getPcbCircuitJsonBounds();let n=1/0,i=-1/0,a=1/0,o=-1/0;for(const s of t.points)n=Math.min(n,s.x),i=Math.max(i,s.x),a=Math.min(a,s.y),o=Math.max(o,s.y);return{center:{x:(n+i)/2,y:(a+o)/2},bounds:{left:n,top:o,right:i,bottom:a},width:i-n,height:o-a}}return super._getPcbCircuitJsonBounds()}_setPositionFromLayout(e){if(!this.pcb_cutout_id)return;const{db:t}=this.root,n=t.pcb_cutout.get(this.pcb_cutout_id);if(n){if(n.shape==="rect"||n.shape==="circle")t.pcb_cutout.update(this.pcb_cutout_id,{...n,center:e});else if(n.shape==="polygon"){const i=this._getPcbCircuitJsonBounds().center,a=e.x-i.x,o=e.y-i.y,s=n.points.map(l=>({x:l.x+a,y:l.y+o}));t.pcb_cutout.update(this.pcb_cutout_id,{...n,points:s})}}}},Bit=class extends qb{get config(){return{componentName:"Battery",schematicSymbolName:this.props.symbolName??"battery",zodProps:IH,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}},jit=class extends qb{get config(){return{componentName:"PinHeader",zodProps:kH,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 yw({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 Hit(r){switch(r){case"two_ground_pins":return"crystal_4pin";case"ground_pin":return"resonator";case"no_ground":return"crystal";default:return"crystal"}}var Vit=class extends qb{get config(){return{componentName:"Resonator",schematicSymbolName:this.props.symbolName??Hit(this.props.pinVariant),zodProps:AH,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}},Git=class extends qb{get config(){return{componentName:"Inductor",schematicSymbolName:this.props.symbolName??"inductor",zodProps:VH,sourceFtype:rP.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:rP.simple_inductor,inductance:t.inductance,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}};function qit(r){switch(r){case"three_pin":return"potentiometer3";case"two_pin":return"potentiometer2";default:return"potentiometer2"}}var $it=class extends qb{get config(){return{componentName:"Potentiometer",schematicSymbolName:this.props.symbolName??qit(this.props.pinVariant),zodProps:CH,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}},Wit=class extends qb{get config(){return{componentName:"PushButton",schematicSymbolName:this.props.symbolName??"push_button_normally_open_momentary",zodProps:BH,sourceFtype:rP.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:rP.simple_push_button,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}},Yit=class extends qb{get config(){return{schematicSymbolName:this.props.symbolName??(this.props.pinVariant==="four_pin"?"crystal_4pin":"crystal"),componentName:"Crystal",zodProps:RH,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`${_5(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}},Xit=class extends qb{constructor(){super(...arguments);et(this,"emitter",this.portMap.pin1);et(this,"collector",this.portMap.pin2);et(this,"base",this.portMap.pin3)}get config(){return{componentName:"Transistor",schematicSymbolName:this.props.type==="npn"?"npn_bipolar_transistor":"pnp_bipolar_transistor",zodProps:jH,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}},Zit=class extends qb{get config(){const e=this.props.mosfetMode==="depletion"?"d":"e";return{componentName:"Mosfet",schematicSymbolName:`${this.props.channelType}_channel_${e}_mosfet_transistor`,zodProps:HH,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}},Qit=class extends qb{_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:$H,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}},Kit=class extends s1{constructor(){super(...arguments);et(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicText",zodProps:KH}}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}`})}})})}}),zme(Lme),zme({Bug:t0e});const n0e=Z0("run-frame"),Jit={},r0e=r=>{let e;const t=new Set,n=(u,f)=>{const d=typeof u=="function"?u(e):u;if(!Object.is(d,e)){const v=e;e=f??(typeof d!="object"||d===null)?d:Object.assign({},e,d),t.forEach(g=>g(e,v))}},i=()=>e,l={setState:n,getState:i,getInitialState:()=>c,subscribe:u=>(t.add(u),()=>t.delete(u)),destroy:()=>{(Jit?"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},i0e=r=>r?r0e(r):r0e;var rL={exports:{}},jV={},iL={exports:{}},HV={};/**
|
|
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(){jme(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(v=>v.subcircuit_connectivity_map_key===this.subcircuit_connectivity_map_key&&v.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=dit({ports:o,nets:c}),f=t.source_trace.insert({connected_source_port_ids:o.map(v=>v.port.source_port_id),connected_source_net_ids:c.map(v=>v.source_net_id),subcircuit_id:(d=this.getSubcircuit())==null?void 0:d.subcircuit_id,max_length:lit(o.map(v=>v.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;pit(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,Y,ce,he;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=(Y=a._parsedProps.pcbRouteCache)==null?void 0:Y.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],pe=u[0].net.getAllConnectedPorts().filter(Te=>Te!==ue);if(pe.length===0){console.log("Nothing to connect this port to, the net is empty. TODO should emit a warning!");return}const ye=eit(ue,pe);l.push(ye)}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=[nL(l[0]),nL(l[1])]:w=[nL(l[0]),...d,nL(l[1])];const S=eL(w),b=w3(this.root.db.toArray()),[T,A]=nit(()=>X4(this.root.db.toArray()));if(A){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: ${A.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 T)if(ue.connectedTo.length>0){const pe=b.getNetConnectedToId(ue.connectedTo[0]);pe&&ue.connectedTo.push(pe)}let z=[];if(S.length===0)z=w;else{const ue=S[0].layer_path;z=w.map((Se,pe)=>Se.via?{...Se,via_to_layer:ue[pe]}:{...Se,layers:[ue[pe]]})}z[0].pcb_port_id=l[0].pcb_port_id,z[z.length-1].pcb_port_id=l[1].pcb_port_id;const V=[];for(const[ue,Se]of Fme(z)){const pe="via_to_layer"in ue?ue.via_to_layer:null,ye=2,Te="layers"in ue&&ue.layers.length===1?ue.layers[0]:pe??"top",xe="layers"in Se&&Se.layers.length===1?Se.layers[0]:pe??"top",Pe="pcb_port_id"in ue?ue.pcb_port_id:null,De="pcb_port_id"in Se?Se.pcb_port_id:null,ke=this.getSubcircuit()._parsedProps.minTraceWidth??.16,Re=new Y4({OBSTACLE_MARGIN:ke*2,isRemovePathLoopsEnabled:!0,optimizeWithGoalBoxes:!!(Pe&&De),connMap:b,input:{obstacles:T,minTraceWidth:ke,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)-ye,maxX:Math.max(ue.x,Se.x)+ye,minY:Math.min(ue.y,Se.y)-ye,maxY:Math.max(ue.y,Se.y)+ye}}});let $e=null;try{$e=Re.solveAndMapToTraces()}catch(ht){this.renderError({type:"pcb_trace_error",pcb_trace_error_id:this.source_trace_id,error_type:"pcb_trace_error",message:`error solving route: ${ht.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(ht=>ht.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:l.map(ht=>ht.pcb_component_id)});return}const[Ke]=$e;pe&&(Ke.route=Ke.route.map(ht=>(ht.route_type==="wire"&&!ht.layer&&(ht.layer=pe),ht))),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 q=Krt(V),X=rit(q),W=t.pcb_trace.insert({route:q,source_trace_id:this.source_trace_id,subcircuit_id:(he=this.getSubcircuit())==null?void 0:he.subcircuit_id,trace_length:X});this._portsRoutedOnPcb=l,this.pcb_trace_id=W.pcb_trace_id;for(const ue of q)ue.route_type==="via"&&t.pcb_via.insert({pcb_trace_id:W.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(q,l)}_doInitialSchematicTraceRenderWithDisplayLabel(){var V,q,X,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,v=s[1].port;if(!v.source_port_id)throw new Error(`Missing source_port_id for the 'to' port (${c}).`);const g=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===v.source_port_id),[S,b]=o.map(({port:K})=>K),A=((q=S.parent)==null?void 0:q.config.shouldRenderAsSchematicBox)?`${(X=S==null?void 0:S.parent)==null?void 0:X.props.name}_${S==null?void 0:S.props.name}`:`${(W=b==null?void 0:b.parent)==null?void 0:W.props.name}_${b==null?void 0:b.props.name}`,z=this.props.schDisplayLabel??A;if(g&&g.text!==z&&(g.text=`${z} / ${g.text}`),w&&(w==null?void 0:w.text)!==z&&(w.text=`${z} / ${w.text}`),z!=null&&z.toLocaleLowerCase().includes("gnd")||z!=null&&z.toLocaleLowerCase().includes("ground")){!g&&!w?(tL({port:f,anchorPos:u,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t}),tL({port:v,anchorPos:d,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t})):g?w||tL({port:v,anchorPos:d,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:t}):tL({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??A,source_net_id:v.source_port_id,anchor_position:d,center:d,anchor_side:IV(v.facingDirection)??"bottom"}),g||t.schematic_net_label.insert({text:this.props.schDisplayLabel??A,source_net_id:f.source_port_id,anchor_position:u,center:u,anchor_side:IV(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=fit(this),v=o.map(({port:Pe})=>({port:Pe,position:Pe._getGlobalSchematicPositionAfterLayout(),schematic_port_id:Pe.schematic_port_id??void 0,facingDirection:Pe.facingDirection}));if(v.length===1&&s.length===1){const Pe=s[0].net,{port:De,position:ke}=v[0];t.schematic_net_label.insert({text:Pe._parsedProps.name,source_net_id:Pe.source_net_id,anchor_position:ke,center:ke,anchor_side:IV(De.facingDirection)??"bottom"});return}if(v.length<2)return;f.pointsToConnect=v.map(({position:Pe})=>({...Pe,layer:"top"}));const w=Qrt(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 T=Y4,A=!1;this.getSubcircuit().props._schDirectLineRoutingEnabled&&(T=Xme,A=!0);let V=new T({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 Xme({input:b}).solveAndMapToTraces(),A=!0}const[{route:q}]=V;let X=[];for(let Pe=0;Pe<q.length-1;Pe++)X.push({from:q[Pe],to:q[Pe+1]});const W=this.source_trace_id;let K=[];if(!A){hit({edges:X,db:t,source_trace_id:W});const Pe=FV({db:t,source_trace_id:W,differentNetOnly:!0}).flatMap(De=>De.edges);X=ait({edges:X,otherEdges:Pe}),K=sit({edges:X,db:t,source_trace_id:this.source_trace_id})}const Y=X[X.length-1],ce=v[v.length-1],he=Qme(Y);X.push(...kV({lastEdge:Y,lastEdgePort:ce,lastDominantDirection:he}));const ue=X[0],Se=v[0],pe=Qme(ue);if(X.unshift(...kV({firstEdge:ue,firstEdgePort:Se,firstDominantDirection:pe})),!this.source_trace_id)throw new Error("Missing source_trace_id for schematic trace insertion.");if(this.getSubcircuit()._parsedProps.schTraceAutoLabelEnabled&&tit(K,X)>=5&&(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection())){this._doInitialSchematicTraceRenderWithDisplayLabel();return}const ye=t.schematic_trace.insert({source_trace_id:this.source_trace_id,edges:X,junctions:K});this.schematic_trace_id=ye.schematic_trace_id,u!=null&&u._connectedSchematicPortPairs&&u._connectedSchematicPortPairs.add(c)}},mit=Z0("tscircuit:core"),vit=I.object({x:r2,y:r2,z:r2}),qb=class extends s1{constructor(t){super(t);et(this,"reactSubtrees",[]);et(this,"_impliedFootprint");et(this,"isPrimitiveContainer",!0);et(this,"_asyncSupplierPartNumbers");et(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,v,g,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 A in a){const z=a[A].pins;if(Array.isArray(z))for(const V of z){const q=tP(V,this._parsedProps.pinLabels);i.push(new yw({pinNumber:q,aliases:((l=t.additionalAliases)==null?void 0:l[`pin${q}`])??[]},{originDescription:`schPortArrangement:${A}`}))}}const b=["left","right","top","bottom"];let T=1;for(const A of b){const z=a[`${A}Size`];for(let V=0;V<z;V++)i.push(new yw({pinNumber:T++,aliases:((c=t.additionalAliases)==null?void 0:c[`pin${T}`])??[]},{originDescription:`schPortArrangement:${A}`}))}}const o=this._parsedProps.pinLabels;if(o)for(let[b,T]of Object.entries(o)){b=b.replace("pin","");let A=i.find(q=>q._parsedProps.pinNumber===Number(b));const z=Array.isArray(T)?T[0]:T,V=Array.isArray(T)?T.slice(1):[];A?(A.externallyAddedAliases.push(z,...V),A.props.name=z):(A=new yw({pinNumber:parseInt(b),name:z,aliases:[...V,...((u=t.additionalAliases)==null?void 0:u[`pin${parseInt(b)}`])??[]]},{originDescription:`pinLabels:pin${b}`}),i.push(A))}if(n.schematicSymbolName){const b=K0[this._getSchematicSymbolNameOrThrow()];if(!b)return;for(const T of b.ports){const A=Wme(T.labels);if(!A)continue;const z=i.find(V=>V._parsedProps.pinNumber===Number(A));if(z)z.schematicSymbolPortDef=T;else{const V=nP(T.labels.concat(((f=t.additionalAliases)==null?void 0:f[`pin${A}`])??[]));V&&(V.originDescription=`schematicSymbol:labels[0]:${T.labels[0]}`,V.schematicSymbolPortDef=T,i.push(V))}}this.addAll(i)}if(!this._getSchematicPortArrangement()){const b=this.getPortsFromFootprint(t);for(const T of b)i.some(A=>A.isMatchingAnyOf(T.getNameAndAliases()))||i.push(T)}for(let b=1;b<=(t.pinCount??this._getPinCount());b++){if(!a||i.find(A=>A._parsedProps.pinNumber===b))continue;let T=[...((d=a.leftSide)==null?void 0:d.pins)??[],...((v=a.rightSide)==null?void 0:v.pins)??[],...((g=a.topSide)==null?void 0:g.pins)??[],...((w=a.bottomSide)==null?void 0:w.pins)??[]].map(A=>tP(A,this._parsedProps.pinLabels));["leftSize","rightSize","topSize","bottomSize","leftPinCount","rightPinCount","topPinCount","bottomPinCount"].some(A=>A in a)&&(T=Array.from({length:this._getPinCount()},(A,z)=>z+1)),T.includes(b)&&i.push(new yw({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=F4.string(a).soup(),l=Brt({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=zA.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=K0[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((v,g)=>{a[String(g+1)]=v});else for(const[v,g]of Object.entries(n.pinLabels??{}))a[v]=Array.isArray(g)?g[0]:g;const o=this._getGlobalSchematicPositionBeforeLayout(),s=this._getSchematicPortArrangement(),l=t.schematic_component.insert({center:o,rotation:n.schRotation??0,size:i.getSize(),port_arrangement:Urt(s),pin_spacing:n.schPinSpacing??.2,pin_styles:zrt(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:.18}),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:.18}),this.schematic_component_id=l.schematic_component_id}doInitialPcbComponentRender(){var s;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=this.getSubcircuit(),a=t.pcb_component.insert({center:this._getGlobalPcbPositionBeforeLayout(),width:0,height:0,layer:n.layer??"top",rotation:n.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:i.subcircuit_id??void 0});if(!n.footprint&&!this.isGroup){const l=t.pcb_missing_footprint_error.insert({message:`No footprint found for component: ${this.getString()}`,source_component_id:`${this.source_component_id}`,error_type:"pcb_missing_footprint_error"});this.pcb_missing_footprint_error_id=l.pcb_missing_footprint_error_id}this.pcb_component_id=a.pcb_component_id;const o=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if((this.props.pcbX!==void 0||this.props.pcbY!==void 0)&&o){const l=kA.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=$me(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:Ort(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&&mit(`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=F4.string(n).soup(),o=[];for(const s of a)if("port_hints"in s&&s.port_hints){const l=nP(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=nP(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=nP(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=K0[t.schematicSymbolName];if(!n)return[];const i=[];for(const o of n.ports){const s=nP(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){jme(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(!Yme(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 Wrt({schWidth:t.schWidth,schHeight:t.schHeight,schPinSpacing:i,numericSchPinStyle:Zrt(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=vit.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:c==="bottom"?-(((o==null?void 0:o.rotation)??0)+s.z)+180:((o==null?void 0:o.rotation)??0)+s.z},pcb_component_id:this.pcb_component_id,source_component_id:this.source_component_id,model_stl_url:"stlUrl"in(i??{})?this._addCachebustToModelUrl(i.stlUrl):void 0,model_obj_url:"objUrl"in(i??{})?this._addCachebustToModelUrl(i.objUrl):void 0,model_jscad:"jscad"in(i??{})?i.jscad:void 0,footprinter_string:typeof this.props.footprint=="string"&&!i?this.props.footprint:void 0})}_addCachebustToModelUrl(t){var i;if(!t||!t.includes("modelcdn.tscircuit.com"))return t;const n=((i=this.root)==null?void 0:i.getClientOrigin())??"";return`${t}${t.includes("?")?"&":"?"}cachebust_origin=${encodeURIComponent(n)}`}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 BT({from:`${this.getSubcircuitSelector()} > port.${n}`,to:o}))}}},git=class{constructor(e,t={}){et(this,"input");et(this,"isRouting",!1);et(this,"solver");et(this,"eventHandlers",{complete:[],error:[],progress:[]});et(this,"cycleCount",0);et(this,"stepDelay");et(this,"timeoutId");this.input=e;const{capacityDepth:n,targetMinCapacity:i,stepDelay:a=0}=t;this.solver=new wV(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||[]}},Kme=class extends s1{constructor(){super(...arguments);et(this,"matchedPort",null)}get config(){return{componentName:"TraceHint",zodProps:iV}}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=>({...jr(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()})}},yit=({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=Y1(r).pcb_component.get(o);if(!l)continue;const c=Y1(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},_it=({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=Y1(r).schematic_component.get(o);if(!l)continue;const c=Y1(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},Jme=({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=_it({circuitJson:r,editEvents:n,manualEditsFile:a})),i.length>0&&(a=yit({circuitJson:r,editEvents:i,manualEditsFile:a})),a},xit=(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},e0e=({db:r,circuitJson:e,subcircuit_id:t,minTraceWidth:n=.1})=>{if(!r&&e&&(r=Y1(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=xit(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=Y1(o);const l=w3(o),c=X4([...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 X,W,K;const S=w.connected_source_port_ids.map(Y=>{const ce=r.source_port.get(Y),he=r.pcb_port.getWhere({source_port_id:Y});return{...ce,...he}});if(S.length<2)return null;const[b,T]=S,A=((X=b.layers)==null?void 0:X[0])??"top",z=((W=T.layers)==null?void 0:W[0])??"top",V=i.filter(Y=>Y.pcb_port_id===b.pcb_port_id||Y.pcb_port_id===T.pcb_port_id),q=[];for(const Y of V){const ce=r.pcb_port.get(Y.pcb_port_id),he=((K=ce==null?void 0:ce.layers)==null?void 0:K[0])??"top";for(const ue of Y.route)q.push({x:ue.x,y:ue.y,layer:he})}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:A},...q,{x:T.x,y:T.y,layer:z}]}}).filter(w=>w!==null),v=r.source_net.list().filter(w=>!t||(a==null?void 0:a.has(w.subcircuit_id))),g=[];for(const w of v){const S=r.source_trace.list().filter(b=>{var T;return(T=b.connected_source_net_ids)==null?void 0:T.includes(w.source_net_id)});g.push({name:w.source_net_id??l.getNetConnectedToId(w.source_net_id),pointsToConnect:S.flatMap(b=>r.pcb_port.list().filter(A=>b.connected_source_port_ids.includes(A.source_port_id)).map(A=>{var z;return{x:A.x,y:A.y,layer:((z=A.layers)==null?void 0:z[0])??"top",pcb_port_id:A.pcb_port_id}}))})}return{simpleRouteJson:{bounds:f,obstacles:c,connections:[...d,...g],layerCount:2,minTraceWidth:n},connMap:l}},BV=class extends qb{constructor(){super(...arguments);et(this,"pcb_group_id",null);et(this,"subcircuit_id",null);et(this,"_hasStartedAsyncAutorouting",!1);et(this,"_asyncAutoroutingResult",null)}get config(){return{zodProps:wH,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 Kme({for:s.pcb_port_selector,offsets:s.offsets}))}doInitialSourceAddConnectivityMapKey(){if(!this.isSubcircuit)return;const{db:t}=this.root,n=this.selectAll("trace"),i=new W4({});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=Z0("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,v;const{db:t}=this.root,n=Z0("tscircuit:core:_runEffectMakeHttpAutoroutingRequest");this._parsedProps;const i=this._getAutorouterConfig(),a=i.serverUrl,o=i.serverMode,s=(g,w)=>{var S;return n("fetching",g),w.headers&&(w.headers["Tscircuit-Core-Version"]=(S=this.root)==null?void 0:S.getCoreVersion()),fetch(g,w)},l=this.root.db.toArray().filter(g=>g.type.startsWith("source_")||g.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:e0e({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:g}=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=g,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(g=>g.json());for(;;){const{autorouting_job:g}=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(g.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(g.has_error)throw t.pcb_autorouting_error.insert({pcb_error_id:c.autorouting_job_id,message:((v=g.error)==null?void 0:v.message)??JSON.stringify(g.error)}),new Error(`Autorouting job failed: ${JSON.stringify(g.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=Z0("tscircuit:core:_runLocalAutorouting");n(`[${this.getString()}] starting local autorouting`);const i=this._getAutorouterConfig(),{simpleRouteJson:a}=e0e({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 git(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((v,g)=>{o.on("complete",w=>{n(`[${this.getString()}] local autorouting complete`),v(w.traces)}),o.on("error",w=>{n(`[${this.getString()}] local autorouting error: ${w.error.message}`),g(w.error)})});o.on("progress",v=>{var g;(g=this.root)==null||g.emit("autorouting:progress",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),...v})}),o.start();try{const v=await s;this._asyncAutoroutingResult={output_pcb_traces:v},this._markDirty("PcbTraceRender")}catch(v){const{db:g}=this.root;throw g.pcb_autorouting_error.insert({pcb_error_id:`pcb_autorouter_error_subcircuit_${this.subcircuit_id}`,message:v instanceof Error?v.message:String(v)}),(d=this.root)==null||d.emit("autorouting:error",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),error:{message:v instanceof Error?v.message:String(v)},simpleRouteJson:a}),v}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=Z0("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=Z0("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=uV(n.toArray()),s=fV(o);cV(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:[]})}}},bit=class extends BV{constructor(){super(...arguments);et(this,"pcb_board_id",null);et(this,"_drcChecksComplete",!1);et(this,"_connectedSchematicPortPairs",new Set)}get isSubcircuit(){return!0}get config(){return{componentName:"Board",zodProps:L7}}get boardThickness(){const{_parsedProps:t}=this;return 1.4}get allLayers(){return["top","bottom","inner1","inner2"]}doInitialPcbBoardAutoSize(){var g;if((g=this.root)!=null&&g.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:T}=w;S===0||b===0||(c=!0,i=Math.min(i,T.x-S/2),a=Math.min(a,T.y-b/2),o=Math.max(o,T.x+S/2),s=Math.max(s,T.y+b/2))}const u=2,f=c?o-i+u*2:0,d=c?s-a+u*2:0,v={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:v})}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),v=Math.min(...u),g=Math.max(...u);i=d-f,a=g-v}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 Q0()}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=AV(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}))}},Sit=new Proxy({},{get:(r,e)=>e}),rP=Sit,wit=class extends qb{get config(){return{componentName:"Capacitor",schematicSymbolName:this.props.polarized?"capacitor_polarized":this.props.symbolName??"capacitor",zodProps:PH,sourceFtype:rP.simple_capacitor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){const e=`${_5(this._parsedProps.capacitance)}F`;return this._parsedProps.schShowRatings&&this._parsedProps.maxVoltageRating?`${e}/${_5(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 BT({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.decouplingFor})),this.add(new BT({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}},t0e=class extends qb{constructor(){super(...arguments);et(this,"schematicBoxDimensions",null)}get config(){return{componentName:"Chip",zodProps:O7,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 BT({from:`${this.getSubcircuitSelector()} > port.${n}`,to:`${this.getSubcircuitSelector()} > port.${i}`}));this._createTracesFromConnectionsProp()}},Eit=class extends qb{constructor(){super(...arguments);et(this,"pos",this.portMap.pin1);et(this,"anode",this.portMap.pin1);et(this,"neg",this.portMap.pin2);et(this,"cathode",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"diode",componentName:"Diode",zodProps:GH,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}},Tit=class extends qb{constructor(){super(...arguments);et(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:EH,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))}},Mit=class extends qb{constructor(){super(...arguments);et(this,"pos",this.portMap.pin1);et(this,"anode",this.portMap.pin1);et(this,"neg",this.portMap.pin2);et(this,"cathode",this.portMap.pin2)}get config(){return{componentName:"Led",schematicSymbolName:this.props.symbolName??"led",zodProps:qH,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}},Cit=class extends qb{constructor(){super(...arguments);et(this,"pos",this.portMap.pin1);et(this,"positive",this.portMap.pin1);et(this,"neg",this.portMap.pin2);et(this,"negative",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"power_factor_meter_horz",componentName:"PowerSource",zodProps:QH,sourceFtype:"simple_power_source"}}initPorts(){this.add(new yw({name:"pin1",pinNumber:1,aliases:["positive","pos"]})),this.add(new yw({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}},Rit=class extends qb{get config(){return{componentName:"Resistor",schematicSymbolName:this.props.symbolName??"boxresistor",zodProps:MH,sourceFtype:"simple_resistor"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${_5(this._parsedProps.resistance)}Ω`}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.pullupFor,this.props.pullupTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.pullupFor&&this.props.pullupTo&&(this.add(new BT({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pullupFor})),this.add(new BT({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}},Ait=["leftedge","rightedge","topedge","bottomedge","center"],Pit=class extends s1{get config(){return{componentName:"Constraint",zodProps:NH}}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=Ait.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}}},Nit=class extends s1{constructor(){super(...arguments);et(this,"fabrication_note_path_id",null)}get config(){return{componentName:"FabricationNotePath",zodProps:YH}}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=jr(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}},Dit=class extends s1{get config(){return{componentName:"FabricationNoteText",zodProps:WH}}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})}},Lit=class extends BV{constructor(e){super({...e,subcircuit:!0})}},Oit=class extends s1{constructor(){super(...arguments);et(this,"source_net_alias_id")}get config(){return{componentName:"NetAlias",zodProps:FH}}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}},zit=class extends s1{constructor(){super(...arguments);et(this,"pcb_silkscreen_circle_id",null);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenCircle",zodProps:rV}}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}}},Uit=class extends s1{constructor(){super(...arguments);et(this,"pcb_silkscreen_rect_id",null);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenRect",zodProps:nV}}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}}},Iit=class extends s1{constructor(){super(...arguments);et(this,"pcb_silkscreen_line_id",null);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenLine",zodProps:tV}}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}}},kit=class extends s1{constructor(){super(...arguments);et(this,"pcb_via_id",null);et(this,"matchedPort",null);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Via",zodProps:XH}}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}},Fit=class extends s1{constructor(){super(...arguments);et(this,"pcb_cutout_id",null);et(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Cutout",zodProps:zet}}doInitialPcbPrimitiveRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=this.getSubcircuit(),i=((l=this.getGroup())==null?void 0:l.pcb_group_id)??void 0,a=this._getGlobalPcbPositionBeforeLayout();let o;if(t.shape==="rect"){const c={shape:"rect",center:a,width:t.width,height:t.height,subcircuit_id:(n==null?void 0:n.subcircuit_id)??void 0,pcb_group_id:i};o=e.pcb_cutout.insert(c)}else if(t.shape==="circle"){const c={shape:"circle",center:a,radius:t.radius,subcircuit_id:(n==null?void 0:n.subcircuit_id)??void 0,pcb_group_id:i};o=e.pcb_cutout.insert(c)}else if(t.shape==="polygon"){const c=this._computePcbGlobalTransformBeforeLayout(),f={shape:"polygon",points:t.points.map(d=>jr(c,d)),subcircuit_id:(n==null?void 0:n.subcircuit_id)??void 0,pcb_group_id:i};o=e.pcb_cutout.insert(f)}o&&(this.pcb_cutout_id=o.pcb_cutout_id)}getPcbSize(){const{_parsedProps:e}=this;if(e.shape==="rect")return{width:e.width,height:e.height};if(e.shape==="circle")return{width:e.radius*2,height:e.radius*2};if(e.shape==="polygon"){if(e.points.length===0)return{width:0,height:0};let t=1/0,n=-1/0,i=1/0,a=-1/0;for(const o of e.points)t=Math.min(t,o.x),n=Math.max(n,o.x),i=Math.min(i,o.y),a=Math.max(a,o.y);return{width:n-t,height:a-i}}return{width:0,height:0}}_getPcbCircuitJsonBounds(){if(!this.pcb_cutout_id)return super._getPcbCircuitJsonBounds();const{db:e}=this.root,t=e.pcb_cutout.get(this.pcb_cutout_id);if(!t)return super._getPcbCircuitJsonBounds();if(t.shape==="rect")return{center:t.center,bounds:{left:t.center.x-t.width/2,top:t.center.y+t.height/2,right:t.center.x+t.width/2,bottom:t.center.y-t.height/2},width:t.width,height:t.height};if(t.shape==="circle")return{center:t.center,bounds:{left:t.center.x-t.radius,top:t.center.y+t.radius,right:t.center.x+t.radius,bottom:t.center.y-t.radius},width:t.radius*2,height:t.radius*2};if(t.shape==="polygon"){if(t.points.length===0)return super._getPcbCircuitJsonBounds();let n=1/0,i=-1/0,a=1/0,o=-1/0;for(const s of t.points)n=Math.min(n,s.x),i=Math.max(i,s.x),a=Math.min(a,s.y),o=Math.max(o,s.y);return{center:{x:(n+i)/2,y:(a+o)/2},bounds:{left:n,top:o,right:i,bottom:a},width:i-n,height:o-a}}return super._getPcbCircuitJsonBounds()}_setPositionFromLayout(e){if(!this.pcb_cutout_id)return;const{db:t}=this.root,n=t.pcb_cutout.get(this.pcb_cutout_id);if(n){if(n.shape==="rect"||n.shape==="circle")t.pcb_cutout.update(this.pcb_cutout_id,{...n,center:e});else if(n.shape==="polygon"){const i=this._getPcbCircuitJsonBounds().center,a=e.x-i.x,o=e.y-i.y,s=n.points.map(l=>({x:l.x+a,y:l.y+o}));t.pcb_cutout.update(this.pcb_cutout_id,{...n,points:s})}}}},Bit=class extends qb{get config(){return{componentName:"Battery",schematicSymbolName:this.props.symbolName??"battery",zodProps:IH,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}},jit=class extends qb{get config(){return{componentName:"PinHeader",zodProps:kH,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 yw({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 Hit(r){switch(r){case"two_ground_pins":return"crystal_4pin";case"ground_pin":return"resonator";case"no_ground":return"crystal";default:return"crystal"}}var Vit=class extends qb{get config(){return{componentName:"Resonator",schematicSymbolName:this.props.symbolName??Hit(this.props.pinVariant),zodProps:AH,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}},Git=class extends qb{get config(){return{componentName:"Inductor",schematicSymbolName:this.props.symbolName??"inductor",zodProps:VH,sourceFtype:rP.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:rP.simple_inductor,inductance:t.inductance,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}};function qit(r){switch(r){case"three_pin":return"potentiometer3";case"two_pin":return"potentiometer2";default:return"potentiometer2"}}var $it=class extends qb{get config(){return{componentName:"Potentiometer",schematicSymbolName:this.props.symbolName??qit(this.props.pinVariant),zodProps:CH,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}},Wit=class extends qb{get config(){return{componentName:"PushButton",schematicSymbolName:this.props.symbolName??"push_button_normally_open_momentary",zodProps:BH,sourceFtype:rP.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:rP.simple_push_button,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}},Yit=class extends qb{get config(){return{schematicSymbolName:this.props.symbolName??(this.props.pinVariant==="four_pin"?"crystal_4pin":"crystal"),componentName:"Crystal",zodProps:RH,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`${_5(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}},Xit=class extends qb{constructor(){super(...arguments);et(this,"emitter",this.portMap.pin1);et(this,"collector",this.portMap.pin2);et(this,"base",this.portMap.pin3)}get config(){return{componentName:"Transistor",schematicSymbolName:this.props.type==="npn"?"npn_bipolar_transistor":"pnp_bipolar_transistor",zodProps:jH,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}},Zit=class extends qb{get config(){const e=this.props.mosfetMode==="depletion"?"d":"e";return{componentName:"Mosfet",schematicSymbolName:`${this.props.channelType}_channel_${e}_mosfet_transistor`,zodProps:HH,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}},Qit=class extends qb{_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:$H,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}},Kit=class extends s1{constructor(){super(...arguments);et(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicText",zodProps:KH}}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}`})}})})}}),zme(Lme),zme({Bug:t0e});const n0e=Z0("run-frame"),Jit={},r0e=r=>{let e;const t=new Set,n=(u,f)=>{const d=typeof u=="function"?u(e):u;if(!Object.is(d,e)){const v=e;e=f??(typeof d!="object"||d===null)?d:Object.assign({},e,d),t.forEach(g=>g(e,v))}},i=()=>e,l={setState:n,getState:i,getInitialState:()=>c,subscribe:u=>(t.add(u),()=>t.delete(u)),destroy:()=>{(Jit?"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},i0e=r=>r?r0e(r):r0e;var rL={exports:{}},jV={},iL={exports:{}},HV={};/**
|
|
831
831
|
* @license React
|
|
832
832
|
* use-sync-external-store-shim.production.js
|
|
833
833
|
*
|
|
@@ -13451,7 +13451,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}return fae}DIt();function MLe(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})]}),ajt=({children:r,elements:e})=>{const[t,n]=Cb(W=>[W.is_mouse_over_container,W.setIsMouseOverContainer]),[i,a]=rt.useState(!1),[o,s]=rt.useState(!1),[l,c]=rt.useState(!1),[u,f]=Cb(W=>[W.selected_layer,W.selectLayer]),[d,v,g,w,S,b]=Cb(W=>[W.in_move_footprint_mode,W.in_draw_trace_mode,W.is_showing_rats_nest,W.is_showing_multiple_traces_length,W.is_showing_autorouting,W.is_showing_drc_errors]),T=Cb(W=>W.setEditMode),A=Cb(W=>W.setIsShowingRatsNest),z=Cb(W=>W.setIsShowingMultipleTracesLength),V=Cb(W=>W.setIsShowingAutorouting),q=Cb(W=>W.setIsShowingDrcErrors);mT("1",()=>f("top")),mT("2",()=>f("bottom")),mT("3",()=>f("inner1")),mT("4",()=>f("inner2")),mT("5",()=>f("inner3")),mT("6",()=>f("inner4")),mT("7",()=>f("inner5")),mT("8",()=>f("inner6"));const X=(e==null?void 0:e.filter(W=>W.type.includes("error")).length)??0;return Ge.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>{n(!0)},onMouseLeave:W=>{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@",rjt.version]}),Ge.jsxs("div",{style:{position:"absolute",opacity:t?1:0,top:16,left:16,transition:t?"opacity 100ms linear":"opacity 1s linear",zIndex:Y2.toolbarOverlay,color:"red",display:"flex",fontSize:12,height:100,fontFamily:"sans-serif"},children:[Ge.jsxs(WR,{onClick:()=>{s(!o)},onMouseLeave:()=>{o&&s(!1)},children:[Ge.jsxs("div",{children:["layer:"," ",Ge.jsx("span",{style:{marginLeft:2,fontWeight:500,color:$R[u]},children:u})]}),o&&Ge.jsx("div",{style:{marginTop:4,minWidth:120},children:qae.map(W=>W.replace(/-/g,"")).map(W=>Ge.jsx(ijt,{name:W,selected:W===u,onClick:()=>{f(W.replace(/-/,""))}},W))})]}),Ge.jsxs(WR,{style:X>0?{color:"red"}:{},onClick:()=>c(!l),onMouseLeave:()=>c(!1),children:[Ge.jsxs("div",{children:[X," errors"]}),l&&Ge.jsx("div",{style:{display:"grid",gridTemplateColumns:"100px 300px"},children:e==null?void 0:e.filter(W=>W.type.includes("error")).map((W,K)=>Ge.jsxs(rt.Fragment,{children:[Ge.jsx("div",{children:W.error_type}),Ge.jsx("div",{children:W.message})]},K))})]}),Ge.jsx(WR,{style:{},onClick:()=>{T(v?"off":"draw_trace")},children:Ge.jsxs("div",{children:[v?"✖ ":"","Edit Traces"]})}),Ge.jsx(WR,{style:{},onClick:()=>{T(d?"off":"move_footprint")},children:Ge.jsxs("div",{children:[d?"✖ ":"","Move Components"]})}),Ge.jsx(WR,{style:{},onClick:()=>{A(!g)},children:Ge.jsxs("div",{children:[g?"✖ ":"","Rats Nest"]})}),Ge.jsx(WR,{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(Qae,{label:"Show All Trace Lengths",checked:w,onClick:()=>{z(!w)}}),Ge.jsx(Qae,{label:"Show Autorouting Animation",checked:S,onClick:()=>{V(!S)}}),Ge.jsx(Qae,{label:"Show DRC Errors",checked:b,onClick:()=>{q(!b)}})]})]})})]})]})},ojt=r=>{const{transform:e,elements:t}=r,[n,i]=rt.useMemo(()=>{const c=r.elements.flatMap(f=>gBt(f,r.elements)),u=w3(r.elements);return[c,u]},[r.elements]),[a,o]=rt.useState({drawingObjectIdsWithMouseOver:new Set,primitiveIdsInMousedOverNet:[]}),s=rt.useMemo(()=>mBt({primitivesWithoutInteractionMetadata:n,drawingObjectIdsWithMouseOver:a.drawingObjectIdsWithMouseOver,primitiveIdsInMousedOverNet:a.primitiveIdsInMousedOverNet}),[n,a]),l=rt.useCallback(c=>{var d,v;const u=[];for(const g of c)if(g._element){const w=i.getNetConnectedToId("pcb_port_id"in g._element?(d=g._element)==null?void 0:d.pcb_port_id:"pcb_trace_id"in g._element?(v=g._element)==null?void 0:v.pcb_trace_id:"");u.push(...i.getIdsConnectedToNet(w))}const f=new Set(c.map(g=>g._pcb_drawing_object_id));o({drawingObjectIdsWithMouseOver:f,primitiveIdsInMousedOverNet:u})},[i]);return Ge.jsx(tjt,{elements:t,transform:e,primitives:n,onMouseHoverOverPrimitives:l,children:Ge.jsx(kBt,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:Ge.jsx(HBt,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:Ge.jsx(UBt,{transform:e,focusOnHover:r.focusOnHover,children:Ge.jsx(ajt,{elements:t,children:Ge.jsx(qBt,{transform:e,elements:t,children:Ge.jsx(njt,{transform:e,soup:t,children:Ge.jsx(OBt,{transform:e,debugGraphics:r.debugGraphics,children:Ge.jsx(zBt,{transform:e,elements:t,children:Ge.jsx(LBt,{transform:e,primitives:s,width:r.width,height:r.height,grid:r.grid})})})})})})})})})})},sjt=uc(pf(400,300),_b(40,-40)),ljt=({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]=Xae(),[v,g]=rt.useState(sjt),{ref:w,setTransform:S,cancelDrag:b}=pBt({transform:v,onSetTransform:g,enabled:c});let[T,A]=rt.useState([]);T=a??T;const z=rt.useRef(!1),V=rt.useRef(null),q=`${(r==null?void 0:r.length)||0}_${(r==null?void 0:r.editCount)||0}`,X=()=>{const he=(d==null?void 0:d.width)>0?d:{width:500,height:500},{center:ue,width:Se,height:pe}=K.some(xe=>xe.type.startsWith("pcb_"))?iBt(K.filter(xe=>xe.type.startsWith("pcb_"))):{center:{x:0,y:0},width:.001,height:.001},ye=Math.min((he.width??0)/Se,(he.height??0)/pe,100)*.75,Te=uc(pf((he.width??0)/2,(he.height??0)/2),_b(ye,-ye,0,0),pf(-ue.x,-ue.y));S(Te)};rt.useEffect(()=>{d!=null&&d.width&&r&&r.length!==0&&(z.current||(X(),z.current=!0))},[r,d]);const W=rt.useMemo(()=>(r==null?void 0:r.filter(he=>he.type.startsWith("pcb_")||he.type.startsWith("source_")))??[],[q]),K=rt.useMemo(()=>TUt({circuitJson:W,editEvents:T}),[W,T]),Y=he=>{A([...T,he]),o==null||o([...T,he])},ce=he=>{const ue=T.map(Se=>Se.edit_event_id===he.edit_event_id?{...Se,...he}:Se);A(ue),o==null||o(ue)};return Ge.jsxs("div",{ref:w,style:{position:"relative"},children:[Ge.jsx("div",{ref:f,children:Ge.jsxs(oBt,{initialState:n,children:[Ge.jsx(ojt,{transform:v,height:t,width:d.width,allowEditing:i,focusOnHover:s,cancelPanDrag:b,onCreateEditEvent:Y,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(lBt,{})]})}),l&&!c&&Ge.jsx("div",{onClick:()=>{u(!0),X()},onTouchStart:he=>{const ue=he.touches[0];V.current={x:ue.clientX,y:ue.clientY}},onTouchEnd:he=>{const ue=he.changedTouches[0],Se=V.current;if(!Se)return;const pe=Math.abs(ue.clientX-Se.x),ye=Math.abs(ue.clientY-Se.y);pe<10&&ye<10&&(he.preventDefault(),u(!0),X()),V.current=null},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:Y2.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 cjt=({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(ljt,{...e,height:n})})},ujt='*,: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}',fjt=()=>{rt.useEffect(()=>{if(document.querySelector('style[data-styles="tscircuit-runframe"]'))return;const e=document.createElement("style");e.setAttribute("data-styles","tscircuit-runframe"),e.textContent=ujt,document.head.appendChild(e)},[])},Fze=r=>`hsl(${R9.indexOf(r)*137.5%360}, 70%, 50%)`,djt=({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:R9.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:Fze(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"]})]})},hjt=({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)=>R9.indexOf(a[0])-R9.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(djt,{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:R9.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:Fze(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))})]})]})},pjt="0.0.476",mjt=["assembly","bom","circuit_json","errors","render_log"],vjt=({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:v,headerClassName:g,leftHeaderContent:w,readOnly:S,isStreaming:b,autoroutingLog:T,onReportAutoroutingLog:A,isRunningCode:z,hasCodeChangedSinceLastRun:V,onEditEvent:q,editEvents:X,defaultActiveTab:W,autoRotate3dViewerDisabled:K,showSchematicDebugGrid:Y=!1,showToggleFullScreen:ce=!0,defaultToFullScreen:he=!1})=>{var ke;fjt();const ue=rt.useMemo(()=>n?n.filter(Re=>Re&&"error_type"in Re||Re.type.includes("error")):null,[n]),[Se,pe]=rt.useState(W??"pcb"),[ye,Te]=rt.useState(he),xe=rt.useCallback(Re=>{pe(Re),u==null||u(Re)},[u]),Pe=()=>{Te(!ye)};rt.useEffect(()=>{t&&xe("errors")},[t]),rt.useEffect(()=>{(Se==="code"||Se==="errors")&&n&&!t&&xe(W??"pcb")},[n]);const De=rt.useCallback(Re=>{window.TSCIRCUIT_3D_OBJECT_REF=Re===null?void 0:Re},[]);return Ge.jsx("div",{className:pm("flex flex-col relative rf-overflow-x-hidden",v),children:Ge.jsx("div",{className:pm("rf-md:sticky rf-md:top-2",ye&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-bg-white"),children:Ge.jsxs(K0e,{value:Se,onValueChange:xe,className:"rf-flex-grow rf-flex rf-flex-col",children:[Ge.jsxs("div",{className:pm("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",g),children:[w,w&&Ge.jsx("div",{className:"rf-flex-grow"}),!w&&z&&Ge.jsx(wR,{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:((ke=f.lastRenderEvent)==null?void 0:ke.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(wR,{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(aG,{children:[o&&Ge.jsx(zE,{value:"code",children:"Code"}),Ge.jsxs(zE,{value:"pcb",className:"rf-whitespace-nowrap",children:[n&&Ge.jsx("span",{className:pm("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(zE,{value:"schematic",className:"rf-whitespace-nowrap",children:[n&&Ge.jsx("span",{className:pm("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(zE,{value:"cad",children:[n&&Ge.jsx("span",{className:pm("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(zE,{value:Se,children:Q0e(Se)}),Ge.jsxs(sie,{children:[Ge.jsx(lie,{asChild:!0,children:Ge.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[Ge.jsx(Z8t,{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(HI,{className:"rf-*:text-xs",children:[mjt.map(Re=>Ge.jsxs(r3,{onSelect:()=>xe(Re),children:[Se!==Re&&Ge.jsx(T8e,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),Se===Re&&Ge.jsx(mre,{className:"rf-w-3 rf-h-3"}),Ge.jsx("div",{className:"rf-pr-2",children:Q0e(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(r3,{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@",pjt.split(".").map((Re,$e)=>$e===2?parseInt(Re)+1:Re).join(".")]})})]})]})]}),ce&&Ge.jsx(g2,{onClick:Pe,variant:"ghost",children:ye?Ge.jsx(eNt,{size:16}):Ge.jsx(K8t,{size:16})})]}),o&&Ge.jsx(A3,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:Ge.jsx("div",{className:"rf-h-full",children:s})}),Ge.jsx(A3,{value:"pcb",children:Ge.jsx("div",{className:pm("rf-overflow-hidden",ye?"rf-h-[calc(100vh-52px)]":"rf-h-[620px]"),children:Ge.jsx(SR,{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(cjt,{focusOnHover:!1,circuitJson:n,debugGraphics:i,containerClassName:pm("rf-h-full rf-w-full",ye?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:Re=>{q&&Re.forEach($e=>q($e))}}):Ge.jsx(t4,{onRunClicked:e})})})}),Ge.jsx(A3,{value:"assembly",children:Ge.jsx("div",{className:pm("rf-overflow-auto",ye?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(SR,{fallback:Ge.jsx("div",{children:"Error loading Assembly"}),children:n?Ge.jsx(Tzt,{circuitJson:n,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):Ge.jsx(t4,{onRunClicked:e})})})}),Ge.jsx(A3,{value:"schematic",children:Ge.jsx("div",{className:pm("rf-overflow-auto rf-bg-white",ye?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(SR,{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(Szt,{circuitJson:n,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:Re=>{q==null||q(Re)},debugGrid:Y,colorOverrides:{schematic:{background:"transparent"}}}):Ge.jsx(t4,{onRunClicked:e})})})}),Ge.jsx(A3,{value:"cad",children:Ge.jsx("div",{className:pm("rf-overflow-auto",ye?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(SR,{FallbackComponent:I8t,children:n?Ge.jsx(z8t,{ref:De,circuitJson:n,autoRotateDisabled:K}):Ge.jsx(t4,{onRunClicked:e})})})}),Ge.jsx(A3,{value:"bom",children:Ge.jsx("div",{className:pm("rf-overflow-auto",ye?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(SR,{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(Pzt,{circuitJson:n}):Ge.jsx(t4,{onRunClicked:e})})})}),Ge.jsx(A3,{value:"circuit_json",children:Ge.jsx("div",{className:pm("rf-overflow-auto",ye?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(SR,{fallback:Ge.jsx("div",{children:"Error loading JSON viewer"}),children:n?Ge.jsx(Rzt,{elements:n}):Ge.jsx(t4,{onRunClicked:e})})})}),Ge.jsx(A3,{value:"errors",children:Ge.jsx("div",{className:pm("rf-overflow-auto",ye?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:n?Ge.jsx(YLt,{code:r,circuitJsonErrors:ue,errorMessage:t,autoroutingLog:T,onReportAutoroutingLog:A}):Ge.jsx(t4,{onRunClicked:e})})}),c&&Ge.jsx(A3,{value:"render_log",children:Ge.jsx(hjt,{renderLog:f})})]})})})};var kk="Dialog",[Bze,jze]=xw(kk),[gjt,s3]=Bze(kk),Hze=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]=iC({prop:n,defaultProp:i??!1,onChange:a,caller:kk});return Ge.jsx(gjt,{scope:e,triggerRef:s,contentRef:l,contentId:bw(),titleId:bw(),descriptionId:bw(),open:c,onOpenChange:u,onOpenToggle:rt.useCallback(()=>u(f=>!f),[u]),modal:o,children:t})};Hze.displayName=kk;var Vze="DialogTrigger",Gze=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=s3(Vze,t),a=Sx(e,i.triggerRef);return Ge.jsx(p_.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":eoe(i.open),...n,ref:a,onClick:Ep(r.onClick,i.onOpenToggle)})});Gze.displayName=Vze;var Kae="DialogPortal",[yjt,qze]=Bze(Kae,{forceMount:void 0}),$ze=r=>{const{__scopeDialog:e,forceMount:t,children:n,container:i}=r,a=s3(Kae,e);return Ge.jsx(yjt,{scope:e,forceMount:t,children:rt.Children.map(n,o=>Ge.jsx(C3,{present:t||a.open,children:Ge.jsx(qre,{asChild:!0,container:i,children:o})}))})};$ze.displayName=Kae;var Fk="DialogOverlay",Wze=rt.forwardRef((r,e)=>{const t=qze(Fk,r.__scopeDialog),{forceMount:n=t.forceMount,...i}=r,a=s3(Fk,r.__scopeDialog);return a.modal?Ge.jsx(C3,{present:n||a.open,children:Ge.jsx(xjt,{...i,ref:e})}):null});Wze.displayName=Fk;var _jt=rC("DialogOverlay.RemoveScroll"),xjt=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=s3(Fk,t);return Ge.jsx(Qre,{as:_jt,allowPinchZoom:!0,shards:[i.contentRef],children:Ge.jsx(p_.div,{"data-state":eoe(i.open),...n,ref:e,style:{pointerEvents:"auto",...n.style}})})}),f4="DialogContent",Yze=rt.forwardRef((r,e)=>{const t=qze(f4,r.__scopeDialog),{forceMount:n=t.forceMount,...i}=r,a=s3(f4,r.__scopeDialog);return Ge.jsx(C3,{present:n||a.open,children:a.modal?Ge.jsx(bjt,{...i,ref:e}):Ge.jsx(Sjt,{...i,ref:e})})});Yze.displayName=f4;var bjt=rt.forwardRef((r,e)=>{const t=s3(f4,r.__scopeDialog),n=rt.useRef(null),i=Sx(e,t.contentRef,n);return rt.useEffect(()=>{const a=n.current;if(a)return PNe(a)},[]),Ge.jsx(Xze,{...r,ref:i,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ep(r.onCloseAutoFocus,a=>{var o;a.preventDefault(),(o=t.triggerRef.current)==null||o.focus()}),onPointerDownOutside:Ep(r.onPointerDownOutside,a=>{const o=a.detail.originalEvent,s=o.button===0&&o.ctrlKey===!0;(o.button===2||s)&&a.preventDefault()}),onFocusOutside:Ep(r.onFocusOutside,a=>a.preventDefault())})}),Sjt=rt.forwardRef((r,e)=>{const t=s3(f4,r.__scopeDialog),n=rt.useRef(!1),i=rt.useRef(!1);return Ge.jsx(Xze,{...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()}})}),Xze=rt.forwardRef((r,e)=>{const{__scopeDialog:t,trapFocus:n,onOpenAutoFocus:i,onCloseAutoFocus:a,...o}=r,s=s3(f4,t),l=rt.useRef(null),c=Sx(e,l);return q8e(),Ge.jsxs(Ge.Fragment,{children:[Ge.jsx(Pre,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:i,onUnmountAutoFocus:a,children:Ge.jsx(Mre,{role:"dialog",id:s.contentId,"aria-describedby":s.descriptionId,"aria-labelledby":s.titleId,"data-state":eoe(s.open),...o,ref:c,onDismiss:()=>s.onOpenChange(!1)})}),Ge.jsxs(Ge.Fragment,{children:[Ge.jsx(Ejt,{titleId:s.titleId}),Ge.jsx(Mjt,{contentRef:l,descriptionId:s.descriptionId})]})]})}),Jae="DialogTitle",Zze=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=s3(Jae,t);return Ge.jsx(p_.h2,{id:i.titleId,...n,ref:e})});Zze.displayName=Jae;var Qze="DialogDescription",Kze=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=s3(Qze,t);return Ge.jsx(p_.p,{id:i.descriptionId,...n,ref:e})});Kze.displayName=Qze;var Jze="DialogClose",eUe=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=s3(Jze,t);return Ge.jsx(p_.button,{type:"button",...n,ref:e,onClick:Ep(r.onClick,()=>i.onOpenChange(!1))})});eUe.displayName=Jze;function eoe(r){return r?"open":"closed"}var tUe="DialogTitleWarning",[wjt,nUe]=vat(tUe,{contentName:f4,titleName:Jae,docsSlug:"dialog"}),Ejt=({titleId:r})=>{const e=nUe(tUe),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})]}),ajt=({children:r,elements:e})=>{const[t,n]=Cb(W=>[W.is_mouse_over_container,W.setIsMouseOverContainer]),[i,a]=rt.useState(!1),[o,s]=rt.useState(!1),[l,c]=rt.useState(!1),[u,f]=Cb(W=>[W.selected_layer,W.selectLayer]),[d,v,g,w,S,b]=Cb(W=>[W.in_move_footprint_mode,W.in_draw_trace_mode,W.is_showing_rats_nest,W.is_showing_multiple_traces_length,W.is_showing_autorouting,W.is_showing_drc_errors]),T=Cb(W=>W.setEditMode),A=Cb(W=>W.setIsShowingRatsNest),z=Cb(W=>W.setIsShowingMultipleTracesLength),V=Cb(W=>W.setIsShowingAutorouting),q=Cb(W=>W.setIsShowingDrcErrors);mT("1",()=>f("top")),mT("2",()=>f("bottom")),mT("3",()=>f("inner1")),mT("4",()=>f("inner2")),mT("5",()=>f("inner3")),mT("6",()=>f("inner4")),mT("7",()=>f("inner5")),mT("8",()=>f("inner6"));const X=(e==null?void 0:e.filter(W=>W.type.includes("error")).length)??0;return Ge.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>{n(!0)},onMouseLeave:W=>{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@",rjt.version]}),Ge.jsxs("div",{style:{position:"absolute",opacity:t?1:0,top:16,left:16,transition:t?"opacity 100ms linear":"opacity 1s linear",zIndex:Y2.toolbarOverlay,color:"red",display:"flex",fontSize:12,height:100,fontFamily:"sans-serif"},children:[Ge.jsxs(WR,{onClick:()=>{s(!o)},onMouseLeave:()=>{o&&s(!1)},children:[Ge.jsxs("div",{children:["layer:"," ",Ge.jsx("span",{style:{marginLeft:2,fontWeight:500,color:$R[u]},children:u})]}),o&&Ge.jsx("div",{style:{marginTop:4,minWidth:120},children:qae.map(W=>W.replace(/-/g,"")).map(W=>Ge.jsx(ijt,{name:W,selected:W===u,onClick:()=>{f(W.replace(/-/,""))}},W))})]}),Ge.jsxs(WR,{style:X>0?{color:"red"}:{},onClick:()=>c(!l),onMouseLeave:()=>c(!1),children:[Ge.jsxs("div",{children:[X," errors"]}),l&&Ge.jsx("div",{style:{display:"grid",gridTemplateColumns:"100px 300px"},children:e==null?void 0:e.filter(W=>W.type.includes("error")).map((W,K)=>Ge.jsxs(rt.Fragment,{children:[Ge.jsx("div",{children:W.error_type}),Ge.jsx("div",{children:W.message})]},K))})]}),Ge.jsx(WR,{style:{},onClick:()=>{T(v?"off":"draw_trace")},children:Ge.jsxs("div",{children:[v?"✖ ":"","Edit Traces"]})}),Ge.jsx(WR,{style:{},onClick:()=>{T(d?"off":"move_footprint")},children:Ge.jsxs("div",{children:[d?"✖ ":"","Move Components"]})}),Ge.jsx(WR,{style:{},onClick:()=>{A(!g)},children:Ge.jsxs("div",{children:[g?"✖ ":"","Rats Nest"]})}),Ge.jsx(WR,{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(Qae,{label:"Show All Trace Lengths",checked:w,onClick:()=>{z(!w)}}),Ge.jsx(Qae,{label:"Show Autorouting Animation",checked:S,onClick:()=>{V(!S)}}),Ge.jsx(Qae,{label:"Show DRC Errors",checked:b,onClick:()=>{q(!b)}})]})]})})]})]})},ojt=r=>{const{transform:e,elements:t}=r,[n,i]=rt.useMemo(()=>{const c=r.elements.flatMap(f=>gBt(f,r.elements)),u=w3(r.elements);return[c,u]},[r.elements]),[a,o]=rt.useState({drawingObjectIdsWithMouseOver:new Set,primitiveIdsInMousedOverNet:[]}),s=rt.useMemo(()=>mBt({primitivesWithoutInteractionMetadata:n,drawingObjectIdsWithMouseOver:a.drawingObjectIdsWithMouseOver,primitiveIdsInMousedOverNet:a.primitiveIdsInMousedOverNet}),[n,a]),l=rt.useCallback(c=>{var d,v;const u=[];for(const g of c)if(g._element){const w=i.getNetConnectedToId("pcb_port_id"in g._element?(d=g._element)==null?void 0:d.pcb_port_id:"pcb_trace_id"in g._element?(v=g._element)==null?void 0:v.pcb_trace_id:"");u.push(...i.getIdsConnectedToNet(w))}const f=new Set(c.map(g=>g._pcb_drawing_object_id));o({drawingObjectIdsWithMouseOver:f,primitiveIdsInMousedOverNet:u})},[i]);return Ge.jsx(tjt,{elements:t,transform:e,primitives:n,onMouseHoverOverPrimitives:l,children:Ge.jsx(kBt,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:Ge.jsx(HBt,{disabled:!r.allowEditing,transform:e,soup:t,cancelPanDrag:r.cancelPanDrag,onCreateEditEvent:r.onCreateEditEvent,onModifyEditEvent:r.onModifyEditEvent,children:Ge.jsx(UBt,{transform:e,focusOnHover:r.focusOnHover,children:Ge.jsx(ajt,{elements:t,children:Ge.jsx(qBt,{transform:e,elements:t,children:Ge.jsx(njt,{transform:e,soup:t,children:Ge.jsx(OBt,{transform:e,debugGraphics:r.debugGraphics,children:Ge.jsx(zBt,{transform:e,elements:t,children:Ge.jsx(LBt,{transform:e,primitives:s,width:r.width,height:r.height,grid:r.grid})})})})})})})})})})},sjt=uc(pf(400,300),_b(40,-40)),ljt=({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]=Xae(),[v,g]=rt.useState(sjt),{ref:w,setTransform:S,cancelDrag:b}=pBt({transform:v,onSetTransform:g,enabled:c});let[T,A]=rt.useState([]);T=a??T;const z=rt.useRef(!1),V=rt.useRef(null),q=`${(r==null?void 0:r.length)||0}_${(r==null?void 0:r.editCount)||0}`,X=()=>{const he=(d==null?void 0:d.width)>0?d:{width:500,height:500},{center:ue,width:Se,height:pe}=K.some(xe=>xe.type.startsWith("pcb_"))?iBt(K.filter(xe=>xe.type.startsWith("pcb_"))):{center:{x:0,y:0},width:.001,height:.001},ye=Math.min((he.width??0)/Se,(he.height??0)/pe,100)*.75,Te=uc(pf((he.width??0)/2,(he.height??0)/2),_b(ye,-ye,0,0),pf(-ue.x,-ue.y));S(Te)};rt.useEffect(()=>{d!=null&&d.width&&r&&r.length!==0&&(z.current||(X(),z.current=!0))},[r,d]);const W=rt.useMemo(()=>(r==null?void 0:r.filter(he=>he.type.startsWith("pcb_")||he.type.startsWith("source_")))??[],[q]),K=rt.useMemo(()=>TUt({circuitJson:W,editEvents:T}),[W,T]),Y=he=>{A([...T,he]),o==null||o([...T,he])},ce=he=>{const ue=T.map(Se=>Se.edit_event_id===he.edit_event_id?{...Se,...he}:Se);A(ue),o==null||o(ue)};return Ge.jsxs("div",{ref:w,style:{position:"relative"},children:[Ge.jsx("div",{ref:f,children:Ge.jsxs(oBt,{initialState:n,children:[Ge.jsx(ojt,{transform:v,height:t,width:d.width,allowEditing:i,focusOnHover:s,cancelPanDrag:b,onCreateEditEvent:Y,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(lBt,{})]})}),l&&!c&&Ge.jsx("div",{onClick:()=>{u(!0),X()},onTouchStart:he=>{const ue=he.touches[0];V.current={x:ue.clientX,y:ue.clientY}},onTouchEnd:he=>{const ue=he.changedTouches[0],Se=V.current;if(!Se)return;const pe=Math.abs(ue.clientX-Se.x),ye=Math.abs(ue.clientY-Se.y);pe<10&&ye<10&&(he.preventDefault(),u(!0),X()),V.current=null},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:Y2.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 cjt=({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(ljt,{...e,height:n})})},ujt='*,: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}',fjt=()=>{rt.useEffect(()=>{if(document.querySelector('style[data-styles="tscircuit-runframe"]'))return;const e=document.createElement("style");e.setAttribute("data-styles","tscircuit-runframe"),e.textContent=ujt,document.head.appendChild(e)},[])},Fze=r=>`hsl(${R9.indexOf(r)*137.5%360}, 70%, 50%)`,djt=({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:R9.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:Fze(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"]})]})},hjt=({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)=>R9.indexOf(a[0])-R9.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(djt,{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:R9.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:Fze(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))})]})]})},pjt="0.0.478",mjt=["assembly","bom","circuit_json","errors","render_log"],vjt=({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:v,headerClassName:g,leftHeaderContent:w,readOnly:S,isStreaming:b,autoroutingLog:T,onReportAutoroutingLog:A,isRunningCode:z,hasCodeChangedSinceLastRun:V,onEditEvent:q,editEvents:X,defaultActiveTab:W,autoRotate3dViewerDisabled:K,showSchematicDebugGrid:Y=!1,showToggleFullScreen:ce=!0,defaultToFullScreen:he=!1})=>{var ke;fjt();const ue=rt.useMemo(()=>n?n.filter(Re=>Re&&"error_type"in Re||Re.type.includes("error")):null,[n]),[Se,pe]=rt.useState(W??"pcb"),[ye,Te]=rt.useState(he),xe=rt.useCallback(Re=>{pe(Re),u==null||u(Re)},[u]),Pe=()=>{Te(!ye)};rt.useEffect(()=>{t&&xe("errors")},[t]),rt.useEffect(()=>{(Se==="code"||Se==="errors")&&n&&!t&&xe(W??"pcb")},[n]);const De=rt.useCallback(Re=>{window.TSCIRCUIT_3D_OBJECT_REF=Re===null?void 0:Re},[]);return Ge.jsx("div",{className:pm("flex flex-col relative rf-overflow-x-hidden",v),children:Ge.jsx("div",{className:pm("rf-md:sticky rf-md:top-2",ye&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-bg-white"),children:Ge.jsxs(K0e,{value:Se,onValueChange:xe,className:"rf-flex-grow rf-flex rf-flex-col",children:[Ge.jsxs("div",{className:pm("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",g),children:[w,w&&Ge.jsx("div",{className:"rf-flex-grow"}),!w&&z&&Ge.jsx(wR,{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:((ke=f.lastRenderEvent)==null?void 0:ke.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(wR,{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(aG,{children:[o&&Ge.jsx(zE,{value:"code",children:"Code"}),Ge.jsxs(zE,{value:"pcb",className:"rf-whitespace-nowrap",children:[n&&Ge.jsx("span",{className:pm("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(zE,{value:"schematic",className:"rf-whitespace-nowrap",children:[n&&Ge.jsx("span",{className:pm("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(zE,{value:"cad",children:[n&&Ge.jsx("span",{className:pm("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(zE,{value:Se,children:Q0e(Se)}),Ge.jsxs(sie,{children:[Ge.jsx(lie,{asChild:!0,children:Ge.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[Ge.jsx(Z8t,{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(HI,{className:"rf-*:text-xs",children:[mjt.map(Re=>Ge.jsxs(r3,{onSelect:()=>xe(Re),children:[Se!==Re&&Ge.jsx(T8e,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),Se===Re&&Ge.jsx(mre,{className:"rf-w-3 rf-h-3"}),Ge.jsx("div",{className:"rf-pr-2",children:Q0e(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(r3,{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@",pjt.split(".").map((Re,$e)=>$e===2?parseInt(Re)+1:Re).join(".")]})})]})]})]}),ce&&Ge.jsx(g2,{onClick:Pe,variant:"ghost",children:ye?Ge.jsx(eNt,{size:16}):Ge.jsx(K8t,{size:16})})]}),o&&Ge.jsx(A3,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:Ge.jsx("div",{className:"rf-h-full",children:s})}),Ge.jsx(A3,{value:"pcb",children:Ge.jsx("div",{className:pm("rf-overflow-hidden",ye?"rf-h-[calc(100vh-52px)]":"rf-h-[620px]"),children:Ge.jsx(SR,{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(cjt,{focusOnHover:!1,circuitJson:n,debugGraphics:i,containerClassName:pm("rf-h-full rf-w-full",ye?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:Re=>{q&&Re.forEach($e=>q($e))}}):Ge.jsx(t4,{onRunClicked:e})})})}),Ge.jsx(A3,{value:"assembly",children:Ge.jsx("div",{className:pm("rf-overflow-auto",ye?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(SR,{fallback:Ge.jsx("div",{children:"Error loading Assembly"}),children:n?Ge.jsx(Tzt,{circuitJson:n,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):Ge.jsx(t4,{onRunClicked:e})})})}),Ge.jsx(A3,{value:"schematic",children:Ge.jsx("div",{className:pm("rf-overflow-auto rf-bg-white",ye?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(SR,{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(Szt,{circuitJson:n,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:Re=>{q==null||q(Re)},debugGrid:Y,colorOverrides:{schematic:{background:"transparent"}}}):Ge.jsx(t4,{onRunClicked:e})})})}),Ge.jsx(A3,{value:"cad",children:Ge.jsx("div",{className:pm("rf-overflow-auto",ye?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(SR,{FallbackComponent:I8t,children:n?Ge.jsx(z8t,{ref:De,circuitJson:n,autoRotateDisabled:K}):Ge.jsx(t4,{onRunClicked:e})})})}),Ge.jsx(A3,{value:"bom",children:Ge.jsx("div",{className:pm("rf-overflow-auto",ye?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(SR,{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(Pzt,{circuitJson:n}):Ge.jsx(t4,{onRunClicked:e})})})}),Ge.jsx(A3,{value:"circuit_json",children:Ge.jsx("div",{className:pm("rf-overflow-auto",ye?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:Ge.jsx(SR,{fallback:Ge.jsx("div",{children:"Error loading JSON viewer"}),children:n?Ge.jsx(Rzt,{elements:n}):Ge.jsx(t4,{onRunClicked:e})})})}),Ge.jsx(A3,{value:"errors",children:Ge.jsx("div",{className:pm("rf-overflow-auto",ye?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:n?Ge.jsx(YLt,{code:r,circuitJsonErrors:ue,errorMessage:t,autoroutingLog:T,onReportAutoroutingLog:A}):Ge.jsx(t4,{onRunClicked:e})})}),c&&Ge.jsx(A3,{value:"render_log",children:Ge.jsx(hjt,{renderLog:f})})]})})})};var kk="Dialog",[Bze,jze]=xw(kk),[gjt,s3]=Bze(kk),Hze=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]=iC({prop:n,defaultProp:i??!1,onChange:a,caller:kk});return Ge.jsx(gjt,{scope:e,triggerRef:s,contentRef:l,contentId:bw(),titleId:bw(),descriptionId:bw(),open:c,onOpenChange:u,onOpenToggle:rt.useCallback(()=>u(f=>!f),[u]),modal:o,children:t})};Hze.displayName=kk;var Vze="DialogTrigger",Gze=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=s3(Vze,t),a=Sx(e,i.triggerRef);return Ge.jsx(p_.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":eoe(i.open),...n,ref:a,onClick:Ep(r.onClick,i.onOpenToggle)})});Gze.displayName=Vze;var Kae="DialogPortal",[yjt,qze]=Bze(Kae,{forceMount:void 0}),$ze=r=>{const{__scopeDialog:e,forceMount:t,children:n,container:i}=r,a=s3(Kae,e);return Ge.jsx(yjt,{scope:e,forceMount:t,children:rt.Children.map(n,o=>Ge.jsx(C3,{present:t||a.open,children:Ge.jsx(qre,{asChild:!0,container:i,children:o})}))})};$ze.displayName=Kae;var Fk="DialogOverlay",Wze=rt.forwardRef((r,e)=>{const t=qze(Fk,r.__scopeDialog),{forceMount:n=t.forceMount,...i}=r,a=s3(Fk,r.__scopeDialog);return a.modal?Ge.jsx(C3,{present:n||a.open,children:Ge.jsx(xjt,{...i,ref:e})}):null});Wze.displayName=Fk;var _jt=rC("DialogOverlay.RemoveScroll"),xjt=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=s3(Fk,t);return Ge.jsx(Qre,{as:_jt,allowPinchZoom:!0,shards:[i.contentRef],children:Ge.jsx(p_.div,{"data-state":eoe(i.open),...n,ref:e,style:{pointerEvents:"auto",...n.style}})})}),f4="DialogContent",Yze=rt.forwardRef((r,e)=>{const t=qze(f4,r.__scopeDialog),{forceMount:n=t.forceMount,...i}=r,a=s3(f4,r.__scopeDialog);return Ge.jsx(C3,{present:n||a.open,children:a.modal?Ge.jsx(bjt,{...i,ref:e}):Ge.jsx(Sjt,{...i,ref:e})})});Yze.displayName=f4;var bjt=rt.forwardRef((r,e)=>{const t=s3(f4,r.__scopeDialog),n=rt.useRef(null),i=Sx(e,t.contentRef,n);return rt.useEffect(()=>{const a=n.current;if(a)return PNe(a)},[]),Ge.jsx(Xze,{...r,ref:i,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ep(r.onCloseAutoFocus,a=>{var o;a.preventDefault(),(o=t.triggerRef.current)==null||o.focus()}),onPointerDownOutside:Ep(r.onPointerDownOutside,a=>{const o=a.detail.originalEvent,s=o.button===0&&o.ctrlKey===!0;(o.button===2||s)&&a.preventDefault()}),onFocusOutside:Ep(r.onFocusOutside,a=>a.preventDefault())})}),Sjt=rt.forwardRef((r,e)=>{const t=s3(f4,r.__scopeDialog),n=rt.useRef(!1),i=rt.useRef(!1);return Ge.jsx(Xze,{...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()}})}),Xze=rt.forwardRef((r,e)=>{const{__scopeDialog:t,trapFocus:n,onOpenAutoFocus:i,onCloseAutoFocus:a,...o}=r,s=s3(f4,t),l=rt.useRef(null),c=Sx(e,l);return q8e(),Ge.jsxs(Ge.Fragment,{children:[Ge.jsx(Pre,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:i,onUnmountAutoFocus:a,children:Ge.jsx(Mre,{role:"dialog",id:s.contentId,"aria-describedby":s.descriptionId,"aria-labelledby":s.titleId,"data-state":eoe(s.open),...o,ref:c,onDismiss:()=>s.onOpenChange(!1)})}),Ge.jsxs(Ge.Fragment,{children:[Ge.jsx(Ejt,{titleId:s.titleId}),Ge.jsx(Mjt,{contentRef:l,descriptionId:s.descriptionId})]})]})}),Jae="DialogTitle",Zze=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=s3(Jae,t);return Ge.jsx(p_.h2,{id:i.titleId,...n,ref:e})});Zze.displayName=Jae;var Qze="DialogDescription",Kze=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=s3(Qze,t);return Ge.jsx(p_.p,{id:i.descriptionId,...n,ref:e})});Kze.displayName=Qze;var Jze="DialogClose",eUe=rt.forwardRef((r,e)=>{const{__scopeDialog:t,...n}=r,i=s3(Jze,t);return Ge.jsx(p_.button,{type:"button",...n,ref:e,onClick:Ep(r.onClick,()=>i.onOpenChange(!1))})});eUe.displayName=Jze;function eoe(r){return r?"open":"closed"}var tUe="DialogTitleWarning",[wjt,nUe]=vat(tUe,{contentName:f4,titleName:Jae,docsSlug:"dialog"}),Ejt=({titleId:r})=>{const e=nUe(tUe),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
|
|