@tscircuit/runframe 0.0.69 → 0.0.70
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 +2 -2
- package/package.json +2 -2
package/dist/standalone.min.js
CHANGED
|
@@ -22046,8 +22046,8 @@ void main() {
|
|
|
22046
22046
|
* SPDX-License-Identifier: MIT
|
|
22047
22047
|
*)
|
|
22048
22048
|
*/const dist$5=Object.freeze(Object.defineProperty({__proto__:null,A0402,A0603,A0805,BGA,ChipBody,ExtrudedPads,FootprintPad,FootprintPlatedHole,Footprinter3d,PinRow,QFN,QFP,SOD123,SOT233P,SOT563,SOT723,SmdChipLead,Tssop},Symbol.toStringTag,{value:"Module"})),require$$19=getAugmentedNamespace(dist$5);var dist$4,hasRequiredDist$2;function requireDist$2(){if(hasRequiredDist$2)return dist$4;hasRequiredDist$2=1;var lV=Object.create,J=Object.defineProperty,VV=Object.getOwnPropertyDescriptor,RV=Object.getOwnPropertyNames,UV=Object.getPrototypeOf,ZV=Object.prototype.hasOwnProperty,WV=(ol,vl)=>{for(var wR in vl)J(ol,wR,{get:vl[wR],enumerable:!0})},IV=(ol,vl,wR,ZU)=>{if(vl&&typeof vl=="object"||typeof vl=="function")for(let AU of RV(vl))!ZV.call(ol,AU)&&AU!==wR&&J(ol,AU,{get:()=>vl[AU],enumerable:!(ZU=VV(vl,AU))||ZU.enumerable});return ol},dV=(ol,vl,wR)=>(wR=ol!=null?lV(UV(ol)):{},IV(!ol||!ol.__esModule?J(wR,"default",{value:ol,enumerable:!0}):wR,ol)),CV=ol=>IV(J({},"__esModule",{value:!0}),ol),FV={};WV(FV,{CadViewer:()=>$U,useExportGltfUrl:()=>nV,useSaveGltfAs:()=>gV}),dist$4=CV(FV);var NV=requireThreeStdlib(),eV=requireReact();function gV(ol={}){const vl=JV(ol),wR=(0,eV.useMemo)(()=>document.createElement("a"),[]),ZU=async yU=>{const XZ=yU??ol.filename??"";ol.binary==null&&(ol.binary=XZ.endsWith(".glb"));const EZ=await vl(AU);wR.download=XZ,wR.href=EZ,wR.dispatchEvent(new MouseEvent("click")),URL.revokeObjectURL(EZ)};(0,eV.useEffect)(()=>()=>{wR.remove(),AU=null},[]);let AU;return[(0,eV.useCallback)(yU=>{AU=yU},[]),ZU]}function nV(ol={}){const vl=JV(ol),[wR,ZU]=(0,eV.useState)(),[AU,uU]=(0,eV.useState)(),yU=(0,eV.useCallback)(XZ=>vl(XZ).then(ZU).catch(uU),[]);return(0,eV.useEffect)(()=>()=>URL.revokeObjectURL(wR),[wR]),[yU,wR,AU]}function JV(ol={}){const vl=(0,eV.useMemo)(()=>new NV.GLTFExporter,[]);return wR=>{const{promise:ZU,resolve:AU,reject:uU}=Promise.withResolvers();return vl.parse(wR,yU=>{const XZ=ol.binary?"gltf-binary":"gltf+json",EZ=new Blob([yU instanceof ArrayBuffer?yU:JSON.stringify(yU)],{type:`model/${XZ}`});AU(URL.createObjectURL(EZ))},uU,ol),ZU}}var aV=require$$2$1,GV=requireReact(),YV=(ol,vl)=>(0,GV.useMemo)(()=>{if(!ol)return;const wR=new aV.Circuit;return wR.add(ol),wR.render(),wR.getCircuitJson()},[ol]),TV=requireDist$6(),iV=requireReact(),AV=requireDist$6(),SV=requireTransforms(),mV=requirePrimitives(),pV=requireColors(),HV=requireBooleans(),BV=requirePrimitives(),uV=requireColors(),jV=requireBooleans(),PV=.01,Zl={copper:[.9,.6,.2],fr4Green:[5/255,163/255,46/255],fr4GreenSolderWithMask:[0/255,152/255,19/255]},nl=(ol,vl)=>{if(ol.shape||(ol.shape="circle"),ol.shape==="circle")return(0,uV.colorize)(Zl.copper,(0,jV.subtract)((0,jV.union)((0,BV.cylinder)({center:[ol.x,ol.y,0],radius:ol.hole_diameter/2,height:1.2}),(0,BV.cylinder)({center:[ol.x,ol.y,1.2/2],radius:ol.outer_diameter/2,height:PV}),(0,BV.cylinder)({center:[ol.x,ol.y,-1.2/2],radius:ol.outer_diameter/2,height:PV})),(0,BV.cylinder)({center:[ol.x,ol.y,0],radius:ol.hole_diameter/2-PV,height:1.5})));if(ol.shape==="pill"){const wR=ol.hole_height>ol.hole_width,ZU=wR?ol.hole_height:ol.hole_width,AU=wR?ol.hole_width:ol.hole_height,uU=wR?ol.outer_width||ZU+.2:ol.outer_height||AU+.2,yU=AU/2,XZ=Math.abs(ZU-AU),EZ=(0,BV.cuboid)({center:wR?[ol.x,ol.y,0]:[ol.x,ol.y,0],size:wR?[AU,XZ,1.2]:[XZ,AU,1.2]}),QZ=(0,BV.cylinder)({center:wR?[ol.x,ol.y-XZ/2,0]:[ol.x-XZ/2,ol.y,0],radius:yU,height:1.2}),ZW=(0,BV.cylinder)({center:wR?[ol.x,ol.y+XZ/2,0]:[ol.x+XZ/2,ol.y,0],radius:yU,height:1.2}),nW=(0,BV.cuboid)({center:wR?[ol.x,ol.y,1.2/2]:[ol.x,ol.y,1.2/2],size:wR?[uU,XZ,PV]:[XZ,uU,PV]}),IZ=(0,BV.cylinder)({center:wR?[ol.x,ol.y-XZ/2,1.2/2]:[ol.x-XZ/2,ol.y,1.2/2],radius:uU/2,height:PV}),MR=(0,BV.cylinder)({center:wR?[ol.x,ol.y+XZ/2,1.2/2]:[ol.x+XZ/2,ol.y,1.2/2],radius:uU/2,height:PV}),WU=(0,BV.cuboid)({center:wR?[ol.x,ol.y,-1.2/2]:[ol.x,ol.y,-1.2/2],size:wR?[uU,XZ,PV]:[XZ,uU,PV]}),MU=(0,BV.cylinder)({center:wR?[ol.x,ol.y-XZ/2,-1.2/2]:[ol.x-XZ/2,ol.y,-1.2/2],radius:uU/2,height:PV}),VZ=(0,BV.cylinder)({center:wR?[ol.x,ol.y+XZ/2,-1.2/2]:[ol.x+XZ/2,ol.y,-1.2/2],radius:uU/2,height:PV});return(0,uV.colorize)(Zl.copper,(0,jV.subtract)((0,jV.union)(EZ,QZ,ZW,nW,IZ,MR,WU,MU,VZ),(0,jV.union)((0,BV.cuboid)({center:[ol.x,ol.y,0],size:wR?[AU-PV,XZ,1.5]:[XZ,AU-PV,1.5]}),(0,BV.cylinder)({center:wR?[ol.x,ol.y-XZ/2,0]:[ol.x-XZ/2,ol.y,0],radius:yU-PV,height:1.5}),(0,BV.cylinder)({center:wR?[ol.x,ol.y+XZ/2,0]:[ol.x+XZ/2,ol.y,0],radius:yU-PV,height:1.5}))))}else throw new Error(`Unsupported plated hole shape: ${ol.shape}`)},dl=requireExtrusions(),LV=requireExpansions(),OV=requireExtrusions(),$V=requirePrimitives(),Cl=requireTransforms(),Wl=ol=>{let vl=0;for(let ZU=0;ZU<ol.length;ZU++){const AU=(ZU+1)%ol.length;vl+=ol[ZU][0]*ol[AU][1],vl-=ol[AU][0]*ol[ZU][1]}return vl/2<=0},gl=(ol,vl=1.2)=>{let wR=ol.map(uU=>[uU.x,uU.y]);Wl(wR)&&(wR=wR.reverse());const ZU=(0,$V.polygon)({points:wR});let AU=(0,OV.extrudeLinear)({height:vl},ZU);return AU=(0,Cl.translate)([0,0,-vl/2],AU),AU},pl=requireText();function Al(ol){var EZ,QZ,ZW,nW;const vl=(0,pl.vectorText)({height:ol.font_size,input:ol.text});vl.forEach(IZ=>{IZ.length===29?(vl.splice(vl.indexOf(IZ),1,IZ.slice(0,15)),vl.splice(vl.indexOf(IZ),0,IZ.slice(14,29))):IZ.length===17&&(vl.splice(vl.indexOf(IZ),1,IZ.slice(0,10)),vl.splice(vl.indexOf(IZ),0,IZ.slice(9,17)))});const wR=vl.flatMap(IZ=>IZ),ZU={minX:Math.min(...wR.map(IZ=>IZ[0])),maxX:Math.max(...wR.map(IZ=>IZ[0])),minY:Math.min(...wR.map(IZ=>IZ[1])),maxY:Math.max(...wR.map(IZ=>IZ[1]))},AU=(ZU.minX+ZU.maxX)/2,uU=(ZU.minY+ZU.maxY)/2;let yU=-AU,XZ=-uU;return(EZ=ol.anchor_alignment)!=null&&EZ.includes("right")?yU=-ZU.maxX:(QZ=ol.anchor_alignment)!=null&&QZ.includes("left")&&(yU=-ZU.minX),(ZW=ol.anchor_alignment)!=null&&ZW.includes("top")?XZ=-ZU.maxY:(nW=ol.anchor_alignment)!=null&&nW.includes("bottom")&&(XZ=-ZU.minY),{textOutlines:vl,xOffset:yU,yOffset:XZ}}var Bl=ol=>{const vl=(0,AV.su)(ol).pcb_board.list()[0];if(!vl)throw new Error("No pcb_board found");const wR=(0,AV.su)(ol).pcb_plated_hole.list(),ZU=(0,AV.su)(ol).pcb_hole.list(),AU=(0,AV.su)(ol).pcb_smtpad.list(),uU=(0,AV.su)(ol).pcb_trace.list(),yU=(0,AV.su)(ol).pcb_via.list(),XZ=(0,AV.su)(ol).pcb_silkscreen_text.list();let EZ;vl.outline&&vl.outline.length>0?EZ=gl(vl.outline,1.2):EZ=(0,mV.cuboid)({size:[vl.width,vl.height,1.2]});const QZ=[],ZW=[],nW=[],IZ=WU=>{if(WU.shape==="circle"){const MU=(0,mV.cylinder)({center:[WU.x,WU.y,0],radius:WU.hole_diameter/2+PV});EZ=(0,HV.subtract)(EZ,MU);const VZ=nl(WU);QZ.push(VZ)}else if(WU.shape==="pill"){const MU=WU.hole_height>WU.hole_width,VZ=MU?WU.hole_height:WU.hole_width,GZ=MU?WU.hole_width:WU.hole_height,$Z=GZ/2,gW=Math.abs(VZ-GZ),iZ=(0,HV.union)((0,mV.cuboid)({center:[WU.x,WU.y,0],size:MU?[GZ,gW,1.5]:[gW,GZ,1.5]}),(0,mV.cylinder)({center:MU?[WU.x,WU.y-gW/2,0]:[WU.x-gW/2,WU.y,0],radius:$Z,height:1.5}),(0,mV.cylinder)({center:MU?[WU.x,WU.y+gW/2,0]:[WU.x+gW/2,WU.y,0],radius:$Z,height:1.5}));EZ=(0,HV.subtract)(EZ,iZ);const KU=nl(WU);QZ.push(KU)}};for(const WU of wR)IZ(WU);for(const WU of ZU)if(WU.hole_shape==="round"||WU.hole_shape==="circle"){const MU=(0,mV.cylinder)({center:[WU.x,WU.y,0],radius:WU.hole_diameter/2+PV});EZ=(0,HV.subtract)(EZ,MU)}for(const WU of AU){const MU=WU.layer==="bottom"?-1:1;if(WU.shape==="rect"){const VZ=(0,pV.colorize)(Zl.copper,(0,mV.cuboid)({center:[WU.x,WU.y,MU*1.2/2+MU*PV],size:[WU.width,WU.height,PV]}));ZW.push(VZ)}else if(WU.shape==="circle"){const VZ=(0,pV.colorize)(Zl.copper,(0,mV.cylinder)({center:[WU.x,WU.y,MU*1.2/2+MU*PV],radius:WU.radius,height:PV}));ZW.push(VZ)}}for(const{route:WU}of uU){if(WU.length<2)continue;const MU=[];let VZ=[WU[0]],GZ=WU[0].route_type==="wire"?WU[0].layer:"top";for(let $Z=1;$Z<WU.length;$Z++){const gW=WU[$Z];gW.route_type==="via"?(MU.push(VZ),VZ=[gW]):gW.route_type==="wire"&&gW.layer!==GZ?(MU.push(VZ),GZ=gW.layer,VZ=[gW]):VZ.push(gW)}MU.push(VZ);for(const $Z of MU){if($Z.length<2)continue;const gW=(0,mV.line)($Z.map(KZ=>[KZ.x,KZ.y])),iZ=$Z[0].route_type==="via"?$Z[0].to_layer==="top"?1:-1:$Z[0].layer==="top"?1:-1;let KU=(0,SV.translate)([0,0,iZ*1.2/2],(0,dl.extrudeLinear)({height:PV*iZ},(0,LV.expand)({delta:.1,corners:"edge"},gW)));const yZ=yU.map(KZ=>(0,mV.cylinder)({center:[KZ.x,KZ.y,0],radius:KZ.outer_diameter/2,height:5})),dW=wR.filter(KZ=>KZ.shape==="circle").map(KZ=>(0,mV.cylinder)({center:[KZ.x,KZ.y,0],radius:KZ.outer_diameter/2,height:5}));KU=(0,HV.subtract)(KU,...yZ,...dW),KU=(0,pV.colorize)(Zl.fr4GreenSolderWithMask,KU),nW.push(KU)}}for(const WU of yU)IZ({x:WU.x,y:WU.y,hole_diameter:WU.hole_diameter,outer_diameter:WU.outer_diameter,shape:"circle",layers:["top","bottom"],type:"pcb_plated_hole",pcb_plated_hole_id:""});const MR=[];for(const WU of XZ){const{textOutlines:MU,xOffset:VZ,yOffset:GZ}=Al(WU);for(let $Z of MU){const gW=$Z.map(AW=>[AW[0]+VZ+WU.anchor_position.x,AW[1]+GZ+WU.anchor_position.y]),iZ=(0,mV.line)(gW),KU=WU.font_size||.25,yZ=Math.min(Math.max(.01,KU*.1),KU*.2),dW=(0,LV.expand)({delta:yZ,corners:"round"},iZ);let KZ=(0,SV.translate)([0,0,.6],(0,dl.extrudeLinear)({height:.012},dW));KZ=(0,pV.colorize)([256,256,256],KZ),MR.push(KZ)}}return EZ=(0,pV.colorize)(Zl.fr4Green,EZ),[EZ,...QZ,...ZW,...nW,...MR]},rl=requireReact(),jl=dV(requireStlSerializer());function Pl(ol){return new Promise((vl,wR)=>{const ZU=new FileReader;ZU.onload=()=>{vl(ZU.result)},ZU.onerror=wR,ZU.readAsDataURL(ol)})}var Hl=ol=>{const[vl,wR]=(0,rl.useState)([]),[ZU,AU]=(0,rl.useState)(!0);return(0,rl.useEffect)(()=>{if(!ol)return;(async()=>{AU(!0);const XZ=(Array.isArray(ol)?ol:[ol]).map(async EZ=>{const QZ=jl.default.serialize({binary:!0},[EZ]),ZW=new Blob(QZ);return{stlUrl:await Pl(ZW),color:EZ.color}});try{const EZ=await Promise.all(XZ);wR(EZ)}catch(EZ){console.error("Error generating STLs:",EZ),wR([])}finally{AU(!1)}})()},[ol]),{stls:vl,loading:ZU}},Tl=require$$12,Sl=requireReact(),Dl=requireThreeStdlib(),ZR=requireJsxRuntime();function nR({stlUrl:ol,mtlUrl:vl,color:wR,opacity:ZU=1}){const AU=(0,Tl.useLoader)(Dl.STLLoader,ol),uU=(0,Sl.useRef)();return(0,ZR.jsxs)("mesh",{ref:uU,children:[(0,ZR.jsx)("primitive",{object:AU,attach:"geometry"}),(0,ZR.jsx)("meshStandardMaterial",{color:wR,transparent:ZU!==1,opacity:ZU})]})}var FR=require$$14,QR=require$$12,hR={name:"@tscircuit/3d-viewer",version:"0.0.85",main:"./dist/index.js",files:["dist"],scripts:{start:"bun run storybook","dev:old":"bunx --bun vite",build:"tsup ./src/index.tsx --dts --sourcemap",prepublish:"npm run build",preview:"vite preview",storybook:"storybook dev -p 6006","build-storybook":"storybook build","vercel-build":"bun run build-storybook",format:"biome format . --write","format:check":"biome format ."},dependencies:{"@jscad/modeling":"^2.12.2","@jscad/regl-renderer":"^2.6.9","@jscad/stl-serializer":"^2.1.17","@react-three/drei":"^9.115.0","@react-three/fiber":"^8.16.8","@tscircuit/core":"^0.0.253","@tscircuit/props":"^0.0.128","@tscircuit/react-fiber":"^1.1.29","@tscircuit/soup":"^0.0.69","@tscircuit/soup-util":"^0.0.26","@types/three":"^0.165.0","jscad-electronics":"^0.0.23","jscad-fiber":"^0.0.76","jscad-planner":"^0.0.11",react:"^18.3.1","react-dom":"^18.3.1","react-use-gesture":"^9.1.3",three:"^0.165.0","three-stdlib":"^2.30.3"},devDependencies:{"@biomejs/biome":"^1.8.3","@chromatic-com/storybook":"^1.5.0","@storybook/addon-essentials":"^8.4.7","@storybook/addon-interactions":"^8.4.7","@storybook/addon-links":"^8.4.7","@storybook/addon-onboarding":"^8.4.7","@storybook/blocks":"^8.4.7","@storybook/builder-vite":"^8.4.7","@storybook/react":"^8.4.7","@storybook/react-vite":"^8.4.7","@storybook/test":"^8.4.7","@types/react":"^18.3.3","@types/react-dom":"^18.3.0","@vitejs/plugin-react":"^4.3.4","circuit-json":"^0.0.116","circuit-to-svg":"^0.0.91",storybook:"^8.4.7","strip-ansi":"^7.1.0",tsup:"^8.1.0",typescript:"^5.7.2",vite:"^5.4.11","vite-tsconfig-paths":"^4.3.2"}},SR=require$$14,mR=require$$12,aR=requireReact(),TR=dV(requireThree()),xR=requireJsxRuntime();typeof window<"u"&&(window.TSCI_MAIN_CAMERA_ROTATION=new TR.Euler(0,0,0));function pR(ol,vl){const wR=new TR.Quaternion().setFromEuler(new TR.Euler(ol.x,ol.y,ol.z)),ZU=new TR.Vector3(0,0,1);return ZU.applyQuaternion(wR),ZU.multiplyScalar(vl)}var UU=({})=>{const ol=(0,aR.useRef)();return(0,aR.useRef)({lastRotation:new TR.Euler}),(0,mR.useFrame)((vl,wR)=>{if(!ol.current)return;const ZU=window.TSCI_MAIN_CAMERA_ROTATION,AU=pR(ZU,2);vl.camera.position.copy(AU),vl.camera.lookAt(0,0,0)}),(0,xR.jsxs)("mesh",{ref:ol,rotation:[Math.PI/2,0,0],children:[(0,xR.jsx)("boxGeometry",{args:[1,1,1]}),(0,xR.jsx)("meshStandardMaterial",{color:"white"}),(0,xR.jsx)(SR.Text,{position:[0,0,.51],fontSize:.25,color:"black",children:"Front"}),(0,xR.jsx)(SR.Text,{position:[0,0,-.51],fontSize:.25,color:"black",rotation:[0,Math.PI,0],children:"Back"}),(0,xR.jsx)(SR.Text,{position:[.51,0,0],fontSize:.25,color:"black",rotation:[0,Math.PI/2,0],children:"Right"}),(0,xR.jsx)(SR.Text,{position:[-.51,0,0],fontSize:.25,color:"black",rotation:[0,-Math.PI/2,0],children:"Left"}),(0,xR.jsx)(SR.Text,{position:[0,.51,0],fontSize:.25,color:"black",rotation:[-Math.PI/2,0,0],children:"Top"}),(0,xR.jsx)(SR.Text,{position:[0,-.51,0],fontSize:.25,color:"black",rotation:[Math.PI/2,0,0],children:"Bottom"}),(0,xR.jsx)("lineSegments",{args:[new TR.EdgesGeometry(new TR.BoxGeometry(1,1,1))],material:new TR.LineBasicMaterial({color:0,linewidth:2})})]})},kU=requireReact(),xU=require$$14,DR=requireJsxRuntime(),BR=()=>((0,QR.useFrame)(({camera:ol})=>{window.TSCI_MAIN_CAMERA_ROTATION=ol.rotation}),(0,DR.jsx)(DR.Fragment,{})),CU=(0,kU.forwardRef)(({children:ol,hoveredComponent:vl},wR)=>(0,DR.jsxs)("div",{style:{position:"relative",width:"100%",height:"100%"},children:[(0,DR.jsx)("div",{style:{position:"absolute",top:0,left:0,width:120,height:120},children:(0,DR.jsxs)(QR.Canvas,{camera:{up:[0,0,1],position:[1,1,1]},style:{zIndex:10},children:[(0,DR.jsx)("ambientLight",{intensity:Math.PI/2}),(0,DR.jsx)(UU,{})]})}),(0,DR.jsxs)(QR.Canvas,{scene:{up:[0,0,1]},camera:{up:[0,0,1],position:[5,5,5]},children:[(0,DR.jsx)(BR,{}),(0,DR.jsx)(FR.OrbitControls,{autoRotate:!0,autoRotateSpeed:1}),(0,DR.jsx)("ambientLight",{intensity:Math.PI/2}),(0,DR.jsx)("pointLight",{position:[-10,-10,10],decay:0,intensity:Math.PI/4}),(0,DR.jsx)(FR.Grid,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:1,sectionSize:10}),(0,DR.jsx)("object3D",{ref:wR,children:ol}),vl&&(0,DR.jsx)(xU.Html,{position:vl.mousePosition,style:{fontFamily:"sans-serif",transform:"translate3d(50%, 50%, 0)",backgroundColor:"white",padding:"5px",borderRadius:"3px",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:vl.name})]}),(0,DR.jsxs)("div",{style:{position:"absolute",right:24,bottom:24,fontFamily:"sans-serif",color:"white",WebkitTextStroke:"0.5px rgba(0, 0, 0, 0.5)",fontSize:11},children:["@",hR.version]})]})),bR=requireReact(),VR=dV(requireThree()),ER=requireJsxRuntime(),YR=ol=>(0,ER.jsx)("group",{...ol}),iR=({children:ol,isHovered:vl,onHover:wR,position:ZU})=>{const AU=(0,bR.useRef)(null),uU=(0,bR.useCallback)(XZ=>{XZ.stopPropagation();try{const EZ=XZ.point||(XZ.intersections&&XZ.intersections.length>0?XZ.intersections[0].point:null)||(ZU?new VR.Vector3(...ZU):null);EZ?(AU.current=EZ,wR({mousePosition:[EZ.x,EZ.y,EZ.z]})):wR({})}catch(EZ){console.warn("Hover event error:",EZ),wR({})}},[ZU]),yU=(0,bR.useCallback)(XZ=>{XZ.stopPropagation(),AU.current=null,wR(null)},[wR]);return(0,ER.jsx)(YR,{onPointerEnter:uU,onPointerMove:uU,onPointerLeave:yU,children:ol})},$R=iR,lU=requireReact(),hU=requireThreeStdlib();typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function GR(ol){const[vl,wR]=(0,lU.useState)(null);return(0,lU.useEffect)(()=>{if(!ol)return;const ZU=window.TSCIRCUIT_OBJ_LOADER_CACHE;let AU=!1;async function uU(){var XZ;try{const QZ=await(await fetch(ol)).text(),ZW=(XZ=QZ.match(/newmtl[\s\S]*?endmtl/g))==null?void 0:XZ.join(`
|
|
22049
|
-
`).replace(/d 0\./g,"d 1."),nW=QZ.replace(/newmtl[\s\S]*?endmtl/g,""),IZ=new hU.MTLLoader;IZ.setMaterialOptions({invertTrProperty:!0});const MR=IZ.parse(ZW.replace(/Kd\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/g,"Kd $2 $2 $2"),"test.mtl"),WU=new hU.OBJLoader;return WU.setMaterials(MR),WU.parse(nW)}catch(EZ){return EZ}}function yU(){if(ZU.has(ol)){const EZ=ZU.get(ol);return EZ.result?Promise.resolve(EZ.result.clone()):EZ.promise.then(QZ=>QZ.clone())}const XZ=uU().then(EZ=>(EZ instanceof Error||ZU.set(ol,{...ZU.get(ol),result:EZ}),EZ));return ZU.set(ol,{promise:XZ,result:null}),XZ}return yU().then(XZ=>{AU||wR(XZ)}).catch(XZ=>{console.error(XZ)}),()=>{AU=!0}},[ol]),vl}var IU=requireJsxRuntime();function FU({url:ol,position:vl,rotation:wR,onHover:ZU,isHovered:AU}){const uU=GR(ol);return uU?uU instanceof Error?(0,IU.jsx)($R,{isHovered:AU,onHover:ZU,children:(0,IU.jsxs)("mesh",{position:vl,children:[(0,IU.jsx)("boxGeometry",{args:[.5,.5,.5]}),(0,IU.jsx)("meshStandardMaterial",{transparent:!0,color:"red",opacity:.5}),(0,IU.jsx)("meshBasicMaterial",{color:"red"})]})}):(0,IU.jsx)($R,{isHovered:AU,onHover:ZU,children:(0,IU.jsx)("primitive",{rotation:wR,position:vl,object:uU})}):(0,IU.jsx)($R,{isHovered:AU,onHover:ZU,children:(0,IU.jsxs)("mesh",{position:vl,children:[(0,IU.jsx)("boxGeometry",{args:[.5,.5,.5]}),(0,IU.jsx)("meshStandardMaterial",{transparent:!0,color:"red",opacity:.25})]})})}var PU=requireDist$5(),hZ=dV(requireSrc$1()),zZ=requireDist$4(),rZ=dV(requireThree()),DZ=requireReact(),MW=requireJsxRuntime(),fU=({jscadPlan:ol,positionOffset:vl,rotationOffset:wR,onHover:ZU,isHovered:AU})=>{const{threeGeom:uU,material:yU}=(0,DZ.useMemo)(()=>{const XZ=(0,PU.executeJscadOperations)(hZ.default,ol),EZ=(0,zZ.convertCSGToThreeGeom)(XZ),QZ=new rZ.MeshStandardMaterial({vertexColors:!0,side:rZ.DoubleSide});return{threeGeom:EZ,material:QZ}},[ol]);return(0,DZ.useMemo)(()=>{if(AU){const XZ=new rZ.Color(yU.color.getHex());yU.emissive.copy(XZ),yU.emissive.setRGB(0,0,1),yU.emissiveIntensity=.2}else yU.emissiveIntensity=0},[AU,yU]),uU?(0,MW.jsx)($R,{isHovered:AU,onHover:ZU,position:vl,children:(0,MW.jsx)("mesh",{geometry:uU,material:yU,position:vl,rotation:wR})}):null},JW=require$$19,NW=requireDist$4(),cW=requireDist$5(),yW=requireReact(),zW=requireJsxRuntime(),{createJSCADRoot:FZ}=(0,NW.createJSCADRenderer)(cW.jscadPlanner),CW=({positionOffset:ol,footprint:vl,rotationOffset:wR,onHover:ZU,isHovered:AU})=>{const uU=(0,yW.useMemo)(()=>{if(!vl)return null;const yU=[];return FZ(yU).render((0,zW.jsx)(JW.Footprinter3d,{footprint:vl})),yU},[vl]);return uU?(0,zW.jsx)(zW.Fragment,{children:uU.map((yU,XZ)=>(0,zW.jsx)(fU,{positionOffset:ol,rotationOffset:wR,jscadPlan:yU,onHover:ZU,isHovered:AU},XZ))}):null},eW=(...ol)=>ol,TW=requireJsxRuntime(),sW=({cad_component:ol,onHover:vl=()=>{},isHovered:wR=!1})=>{const ZU=ol.model_obj_url??ol.model_stl_url,AU=ol.rotation?eW(ol.rotation.x*Math.PI/180,ol.rotation.y*Math.PI/180,ol.rotation.z*Math.PI/180):void 0;if(ZU)return(0,TW.jsx)(FU,{url:ZU,position:ol.position?[ol.position.x,ol.position.y,ol.position.z]:void 0,rotation:AU,onHover:vl,isHovered:wR},ol.cad_component_id);if(ol.model_jscad)return(0,TW.jsx)(fU,{jscadPlan:ol.model_jscad,rotationOffset:AU,onHover:vl,isHovered:wR},ol.cad_component_id);if(ol.footprinter_string)return(0,TW.jsx)(CW,{positionOffset:ol.position?[ol.position.x,ol.position.y,ol.position.z]:void 0,rotationOffset:AU,footprint:ol.footprinter_string,onHover:vl,isHovered:wR})},lZ=dV(requireReact()),wU=class extends lZ.default.Component{constructor(ol){super(ol),this.state={hasError:!1,error:null}}static getDerivedStateFromError(ol){return{hasError:!0,error:ol}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},LR=require$$14,TU=requireJsxRuntime(),vR=({error:ol,cad_component:vl})=>{let wR=[0,0,0];return vl!=null&&vl.position&&(wR=[vl.position.x,vl.position.y,vl.position.z],wR=wR.map(ZU=>Number.isNaN(ZU)?0:ZU)),(0,TU.jsxs)("group",{position:wR,children:[(0,TU.jsxs)("mesh",{renderOrder:-99999,rotation:[Math.PI/4,Math.PI/4,0],ref:ZU=>{ZU&&(ZU.renderOrder=999999)},children:[(0,TU.jsx)("boxGeometry",{args:[.5,.5,.5]}),(0,TU.jsx)("meshStandardMaterial",{depthTest:!1,transparent:!0,color:"red",opacity:.5})]}),(0,TU.jsxs)(LR.Text,{scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:[ol.toString().slice(0,50),"..."]})]})},DU=requireJsxRuntime(),$U=(0,iV.forwardRef)(({soup:ol,children:vl},wR)=>{const[ZU,AU]=(0,iV.useState)(null);if(ol??(ol=YV(vl)),!ol)return null;const uU=(0,iV.useMemo)(()=>ol.some(QZ=>QZ.type==="pcb_board")?Bl(ol):null,[ol]),{stls:yU,loading:XZ}=Hl(uU),EZ=(0,TV.su)(ol).cad_component.list();return(0,DU.jsxs)(CU,{ref:wR,hoveredComponent:ZU,children:[yU.map(({stlUrl:QZ,color:ZW},nW)=>(0,DU.jsx)(nR,{stlUrl:QZ,color:ZW,opacity:nW===0?.95:1},QZ)),EZ.map(QZ=>(0,DU.jsx)(wU,{fallback:({error:ZW})=>(0,DU.jsx)(vR,{cad_component:QZ,error:ZW}),children:(0,DU.jsx)(sW,{onHover:ZW=>{var IZ;if(ZW||AU(null),!ZW.mousePosition)return;const nW=(IZ=(0,TV.su)(ol).source_component.getUsing({source_component_id:QZ.source_component_id}))==null?void 0:IZ.name;AU({cad_component_id:QZ.cad_component_id,name:nW??"<unknown>",mousePosition:ZW.mousePosition})},cad_component:QZ,isHovered:(ZU==null?void 0:ZU.cad_component_id)===QZ.cad_component_id},QZ.cad_component_id)},QZ.cad_component_id))]})});return dist$4}var distExports$2=requireDist$2(),unitMappings={Hz:{baseUnit:"Hz",variants:{MHz:1e6,kHz:1e3,Hz:1}},g:{baseUnit:"g",variants:{kg:1e3,g:1}},Ω:{baseUnit:"Ω",variants:{mΩ:.001,Ω:1,kΩ:1e3,KΩ:1e3,MΩ:1e6,GΩ:1e9,TΩ:1e12}},V:{baseUnit:"V",variants:{mV:.001,V:1,kV:1e3,KV:1e3,MV:1e6,GV:1e9,TV:1e12}},A:{baseUnit:"A",variants:{µA:1e-6,mA:.001,ma:.001,A:1,kA:1e3,MA:1e6}},F:{baseUnit:"F",variants:{pF:1e-12,nF:1e-9,µF:1e-6,uF:1e-6,mF:.001,F:1}},ml:{baseUnit:"ml",variants:{ml:1,mL:1,l:1e3,L:1e3}},deg:{baseUnit:"deg",variants:{rad:180/Math.PI}},ms:{baseUnit:"ms",variants:{s:1e3}},mm:{baseUnit:"mm",variants:{nm:1e-6,µm:.001,um:.001,mm:1,cm:10,dm:100,m:1e3,km:1e6,in:25.4,ft:304.8,IN:25.4,FT:304.8,yd:914.4,mi:1609344,mil:.0254}}},unitMappingAndVariantSuffixes=new Set;for(const[lV,J]of Object.entries(unitMappings)){unitMappingAndVariantSuffixes.add(lV);for(const VV of Object.keys(J.variants))unitMappingAndVariantSuffixes.add(VV)}function getBaseTscircuitUnit(lV){for(const[J,VV]of Object.entries(unitMappings))if(lV in VV.variants)return{baseUnit:VV.baseUnit,conversionFactor:VV.variants[lV]};return{baseUnit:lV,conversionFactor:1}}var si_prefix_multiplier={tera:1e12,T:1e12,giga:1e9,G:1e9,mega:1e6,M:1e6,kilo:1e3,k:1e3,deci:.1,d:.1,centi:.01,c:.01,milli:.001,m:.001,micro:1e-6,u:1e-6,µ:1e-6,nano:1e-9,n:1e-9,pico:1e-12,p:1e-12},parseAndConvertSiUnit=lV=>{var IV;if(typeof lV>"u")return{parsedUnit:null,unitOfValue:null,value:null};if(typeof lV=="string"&&lV.match(/^[\d\.]+$/))return{value:Number.parseFloat(lV),parsedUnit:null,unitOfValue:null};if(typeof lV=="number")return{value:lV,parsedUnit:null,unitOfValue:null};if(typeof lV=="object"&&"x"in lV&&"y"in lV){const{parsedUnit:dV,unitOfValue:CV}=parseAndConvertSiUnit(lV.x);return{parsedUnit:dV,unitOfValue:CV,value:{x:parseAndConvertSiUnit(lV.x).value,y:parseAndConvertSiUnit(lV.y).value}}}const VV=(IV=lV.toString().split("").reverse().join("").match(/[^\d\s]+/))==null?void 0:IV[0];if(!VV)throw new Error(`Could not determine unit: "${lV}"`);const RV=VV.split("").reverse().join(""),UV=lV.slice(0,-RV.length);if(RV in si_prefix_multiplier&&!unitMappingAndVariantSuffixes.has(RV)){const dV=si_prefix_multiplier[RV];return{parsedUnit:null,unitOfValue:null,value:Number.parseFloat(UV)*dV}}const{baseUnit:ZV,conversionFactor:WV}=getBaseTscircuitUnit(RV);return{parsedUnit:RV,unitOfValue:ZV,value:WV*Number.parseFloat(UV)}},resistance=z$1.string().or(z$1.number()).transform(lV=>parseAndConvertSiUnit(lV).value),capacitance=z$1.string().or(z$1.number()).transform(lV=>parseAndConvertSiUnit(lV).value),inductance=z$1.string().or(z$1.number()).transform(lV=>parseAndConvertSiUnit(lV).value),voltage=z$1.string().or(z$1.number()).transform(lV=>parseAndConvertSiUnit(lV).value),length$1=z$1.string().or(z$1.number()).transform(lV=>parseAndConvertSiUnit(lV).value),frequency=z$1.string().or(z$1.number()).transform(lV=>parseAndConvertSiUnit(lV).value),distance$1=length$1,current=z$1.string().or(z$1.number()).transform(lV=>parseAndConvertSiUnit(lV).value),time=z$1.string().or(z$1.number()).transform(lV=>parseAndConvertSiUnit(lV).value),rotation=z$1.string().or(z$1.number()).transform(lV=>typeof lV=="number"?lV:lV.endsWith("deg")?Number.parseFloat(lV.split("deg")[0]):lV.endsWith("rad")?Number.parseFloat(lV.split("rad")[0])*180/Math.PI:Number.parseFloat(lV)),battery_capacity=z$1.number().or(z$1.string().endsWith("mAh")).transform(lV=>{if(typeof lV=="string"){const J=lV.replace("mAh",""),VV=Number.parseFloat(J);if(Number.isNaN(VV))throw new Error("Invalid capacity");return VV}return lV}).describe("Battery capacity in mAh"),point$1=z$1.object({x:distance$1,y:distance$1}),position$1=point$1,point3$1=z$1.object({x:distance$1,y:distance$1,z:distance$1}),position3=point3$1,size$3=z$1.object({width:z$1.number(),height:z$1.number()}),getZodPrefixedIdWithDefault=lV=>z$1.string().optional().default(()=>`${lV}_${nanoid(10)}`),supplier_name=z$1.enum(["jlcpcb","macrofab","pcbway","digikey","mouser","lcsc"]),source_component_base=z$1.object({type:z$1.literal("source_component"),ftype:z$1.string().optional(),source_component_id:z$1.string(),name:z$1.string(),manufacturer_part_number:z$1.string().optional(),supplier_part_numbers:z$1.record(supplier_name,z$1.array(z$1.string())).optional(),display_value:z$1.string().optional()}),source_simple_capacitor=source_component_base.extend({ftype:z$1.literal("simple_capacitor"),capacitance,display_capacitance:z$1.string().optional(),max_decoupling_trace_length:distance$1.optional()}),source_simple_resistor=source_component_base.extend({ftype:z$1.literal("simple_resistor"),resistance,display_resistance:z$1.string().optional()}),source_simple_diode=source_component_base.extend({ftype:z$1.literal("simple_diode")}),source_simple_ground=source_component_base.extend({ftype:z$1.literal("simple_ground")}),source_simple_bug=source_component_base.extend({ftype:z$1.literal("simple_bug")}).describe("@deprecated"),source_simple_chip=source_component_base.extend({ftype:z$1.literal("simple_chip")}),source_led=source_simple_diode.extend({ftype:z$1.literal("led")}),source_simple_power_source=source_component_base.extend({ftype:z$1.literal("simple_power_source"),voltage}),source_simple_battery=source_component_base.extend({ftype:z$1.literal("simple_battery"),capacity:battery_capacity}),source_simple_inductor=source_component_base.extend({ftype:z$1.literal("simple_inductor"),inductance}),source_simple_push_button=source_component_base.extend({ftype:z$1.literal("simple_push_button")}),source_simple_potentiometer=source_component_base.extend({ftype:z$1.literal("simple_potentiometer"),max_resistance:resistance}),source_simple_crystal=source_component_base.extend({ftype:z$1.literal("simple_crystal"),frequency:z$1.number().describe("Frequency in Hz"),load_capacitance:z$1.number().optional().describe("Load capacitance in pF")}),source_simple_pin_header=source_component_base.extend({ftype:z$1.literal("simple_pin_header"),pin_count:z$1.number(),gender:z$1.enum(["male","female"]).optional().default("male")}),source_simple_resonator=source_component_base.extend({ftype:z$1.literal("simple_resonator"),load_capacitance:capacitance,equivalent_series_resistance:resistance.optional(),frequency}),source_simple_transistor=source_component_base.extend({ftype:z$1.literal("simple_transistor"),transistor_type:z$1.enum(["npn","pnp"])}),source_simple_mosfet=source_component_base.extend({ftype:z$1.literal("simple_mosfet"),channel_type:z$1.enum(["n","p"]),mosfet_mode:z$1.enum(["enhancement","depletion"])}),any_source_component=z$1.union([source_simple_resistor,source_simple_capacitor,source_simple_diode,source_simple_ground,source_simple_chip,source_simple_bug,source_led,source_simple_power_source,source_simple_battery,source_simple_inductor,source_simple_push_button,source_simple_potentiometer,source_simple_crystal,source_simple_pin_header,source_simple_resonator,source_simple_transistor,source_simple_mosfet]),source_port=z$1.object({type:z$1.literal("source_port"),pin_number:z$1.number().optional(),port_hints:z$1.array(z$1.string()).optional(),name:z$1.string(),source_port_id:z$1.string(),source_component_id:z$1.string()}),source_trace=z$1.object({type:z$1.literal("source_trace"),source_trace_id:z$1.string(),connected_source_port_ids:z$1.array(z$1.string()),connected_source_net_ids:z$1.array(z$1.string()),subcircuit_connectivity_map_key:z$1.string().optional(),max_length:z$1.number().optional(),display_name:z$1.string().optional()}),source_group=z$1.object({type:z$1.literal("source_group"),source_group_id:z$1.string(),name:z$1.string().optional()}),source_net=z$1.object({type:z$1.literal("source_net"),source_net_id:z$1.string(),name:z$1.string(),member_source_group_ids:z$1.array(z$1.string()),is_power:z$1.boolean().optional(),is_ground:z$1.boolean().optional(),is_digital_signal:z$1.boolean().optional(),is_analog_signal:z$1.boolean().optional(),trace_width:z$1.number().optional()}),schematic_box=z$1.object({type:z$1.literal("schematic_box"),schematic_component_id:z$1.string(),width:distance$1,height:distance$1,x:distance$1,y:distance$1}).describe("Draws a box on the schematic"),schematic_path=z$1.object({type:z$1.literal("schematic_path"),schematic_component_id:z$1.string(),fill_color:z$1.enum(["red","blue"]).optional(),is_filled:z$1.boolean().optional(),points:z$1.array(point$1)}),schematic_pin_styles=z$1.record(z$1.object({left_margin:length$1.optional(),right_margin:length$1.optional(),top_margin:length$1.optional(),bottom_margin:length$1.optional()})),schematic_component_port_arrangement_by_size=z$1.object({left_size:z$1.number(),right_size:z$1.number(),top_size:z$1.number().optional(),bottom_size:z$1.number().optional()}),schematic_component_port_arrangement_by_sides=z$1.object({left_side:z$1.object({pins:z$1.array(z$1.number()),direction:z$1.enum(["top-to-bottom","bottom-to-top"]).optional()}).optional(),right_side:z$1.object({pins:z$1.array(z$1.number()),direction:z$1.enum(["top-to-bottom","bottom-to-top"]).optional()}).optional(),top_side:z$1.object({pins:z$1.array(z$1.number()),direction:z$1.enum(["left-to-right","right-to-left"]).optional()}).optional(),bottom_side:z$1.object({pins:z$1.array(z$1.number()),direction:z$1.enum(["left-to-right","right-to-left"]).optional()}).optional()}),port_arrangement=z$1.union([schematic_component_port_arrangement_by_size,schematic_component_port_arrangement_by_sides]),schematic_component=z$1.object({type:z$1.literal("schematic_component"),rotation:rotation.default(0),size:size$3,center:point$1,source_component_id:z$1.string(),schematic_component_id:z$1.string(),pin_spacing:length$1.optional(),pin_styles:schematic_pin_styles.optional(),box_width:length$1.optional(),symbol_name:z$1.string().optional(),port_arrangement:port_arrangement.optional(),port_labels:z$1.record(z$1.string()).optional(),symbol_display_value:z$1.string().optional()}),schematic_line=z$1.object({type:z$1.literal("schematic_line"),schematic_component_id:z$1.string(),x1:distance$1,x2:distance$1,y1:distance$1,y2:distance$1}),schematic_trace=z$1.object({type:z$1.literal("schematic_trace"),schematic_trace_id:z$1.string(),source_trace_id:z$1.string(),junctions:z$1.array(z$1.object({x:z$1.number(),y:z$1.number()})),edges:z$1.array(z$1.object({from:z$1.object({x:z$1.number(),y:z$1.number()}),to:z$1.object({x:z$1.number(),y:z$1.number()}),is_crossing:z$1.boolean().optional(),from_schematic_port_id:z$1.string().optional(),to_schematic_port_id:z$1.string().optional()}))}),schematic_text=z$1.object({type:z$1.literal("schematic_text"),schematic_component_id:z$1.string(),schematic_text_id:z$1.string(),text:z$1.string(),position:z$1.object({x:distance$1,y:distance$1}),rotation:z$1.number().default(0),anchor:z$1.enum(["center","left","right","top","bottom"]).default("center"),color:z$1.string().default("#000000")}),schematic_port=z$1.object({type:z$1.literal("schematic_port"),schematic_port_id:z$1.string(),source_port_id:z$1.string(),schematic_component_id:z$1.string().optional(),center:point$1,facing_direction:z$1.enum(["up","down","left","right"]).optional(),distance_from_component_edge:z$1.number().optional(),side_of_component:z$1.enum(["top","bottom","left","right"]).optional(),true_ccw_index:z$1.number().optional(),pin_number:z$1.number().optional(),display_pin_label:z$1.string().optional()}).describe("Defines a port on a schematic component"),schematic_net_label=z$1.object({type:z$1.literal("schematic_net_label"),source_net_id:z$1.string(),center:point$1,anchor_position:point$1.optional(),anchor_side:z$1.enum(["top","bottom","left","right"]),text:z$1.string(),symbol_name:z$1.string().optional()}),schematic_error=z$1.object({type:z$1.literal("schematic_error"),schematic_error_id:z$1.string(),error_type:z$1.literal("schematic_port_not_found"),message:z$1.string()}).describe("Defines a schematic error on the schematic"),schematic_debug_object_base=z$1.object({type:z$1.literal("schematic_debug_object"),label:z$1.string().optional()}),schematic_debug_rect=schematic_debug_object_base.extend({shape:z$1.literal("rect"),center:point$1,size:size$3}),schematic_debug_line=schematic_debug_object_base.extend({shape:z$1.literal("line"),start:point$1,end:point$1}),schematic_debug_point=schematic_debug_object_base.extend({shape:z$1.literal("point"),center:point$1}),schematic_debug_object=z$1.discriminatedUnion("shape",[schematic_debug_rect,schematic_debug_line,schematic_debug_point]),schematic_voltage_probe=z$1.object({type:z$1.literal("schematic_voltage_probe"),schematic_voltage_probe_id:z$1.string(),position:point$1,schematic_trace_id:z$1.string(),voltage:voltage.optional()}).describe("Defines a voltage probe measurement point on a schematic trace"),all_layers=["top","bottom","inner1","inner2","inner3","inner4","inner5","inner6"],layer_string=z$1.enum(all_layers),layer_ref=layer_string.or(z$1.object({name:layer_string})).transform(lV=>typeof lV=="string"?lV:lV.name),visible_layer=z$1.enum(["top","bottom"]),pcb_route_hint=z$1.object({x:distance$1,y:distance$1,via:z$1.boolean().optional(),via_to_layer:layer_ref.optional()}),pcb_route_hints=z$1.array(pcb_route_hint),route_hint_point=z$1.object({x:distance$1,y:distance$1,via:z$1.boolean().optional(),to_layer:layer_ref.optional(),trace_width:distance$1.optional()}),pcb_component=z$1.object({type:z$1.literal("pcb_component"),pcb_component_id:getZodPrefixedIdWithDefault("pcb_component"),source_component_id:z$1.string(),center:point$1,layer:layer_ref,rotation,width:length$1,height:length$1}).describe("Defines a component on the PCB"),pcb_hole_circle_or_square=z$1.object({type:z$1.literal("pcb_hole"),pcb_hole_id:getZodPrefixedIdWithDefault("pcb_hole"),hole_shape:z$1.enum(["circle","square"]),hole_diameter:z$1.number(),x:distance$1,y:distance$1}),pcb_hole_circle_or_square_shape=pcb_hole_circle_or_square.describe("Defines a circular or square hole on the PCB"),pcb_hole_oval=z$1.object({type:z$1.literal("pcb_hole"),pcb_hole_id:getZodPrefixedIdWithDefault("pcb_hole"),hole_shape:z$1.literal("oval"),hole_width:z$1.number(),hole_height:z$1.number(),x:distance$1,y:distance$1}),pcb_hole_oval_shape=pcb_hole_oval.describe("Defines an oval hole on the PCB"),pcb_hole=pcb_hole_circle_or_square.or(pcb_hole_oval),pcb_plated_hole_circle=z$1.object({type:z$1.literal("pcb_plated_hole"),shape:z$1.literal("circle"),outer_diameter:z$1.number(),hole_diameter:z$1.number(),x:distance$1,y:distance$1,layers:z$1.array(layer_ref),port_hints:z$1.array(z$1.string()).optional(),pcb_component_id:z$1.string().optional(),pcb_port_id:z$1.string().optional(),pcb_plated_hole_id:getZodPrefixedIdWithDefault("pcb_plated_hole")}),pcb_plated_hole_oval=z$1.object({type:z$1.literal("pcb_plated_hole"),shape:z$1.enum(["oval","pill"]),outer_width:z$1.number(),outer_height:z$1.number(),hole_width:z$1.number(),hole_height:z$1.number(),x:distance$1,y:distance$1,layers:z$1.array(layer_ref),port_hints:z$1.array(z$1.string()).optional(),pcb_component_id:z$1.string().optional(),pcb_port_id:z$1.string().optional(),pcb_plated_hole_id:getZodPrefixedIdWithDefault("pcb_plated_hole")}),pcb_circular_hole_with_rect_pad=z$1.object({type:z$1.literal("pcb_plated_hole"),shape:z$1.literal("circular_hole_with_rect_pad"),hole_shape:z$1.literal("circle"),pad_shape:z$1.literal("rect"),hole_diameter:z$1.number(),rect_pad_width:z$1.number(),rect_pad_height:z$1.number(),x:distance$1,y:distance$1,layers:z$1.array(layer_ref),port_hints:z$1.array(z$1.string()).optional(),pcb_component_id:z$1.string().optional(),pcb_port_id:z$1.string().optional(),pcb_plated_hole_id:getZodPrefixedIdWithDefault("pcb_plated_hole")}),pcb_plated_hole=z$1.union([pcb_plated_hole_circle,pcb_plated_hole_oval,pcb_circular_hole_with_rect_pad]),pcb_port=z$1.object({type:z$1.literal("pcb_port"),pcb_port_id:getZodPrefixedIdWithDefault("pcb_port"),source_port_id:z$1.string(),pcb_component_id:z$1.string(),x:distance$1,y:distance$1,layers:z$1.array(layer_ref)}).describe("Defines a port on the PCB"),pcb_smtpad_circle=z$1.object({type:z$1.literal("pcb_smtpad"),shape:z$1.literal("circle"),pcb_smtpad_id:getZodPrefixedIdWithDefault("pcb_smtpad"),x:distance$1,y:distance$1,radius:z$1.number(),layer:layer_ref,port_hints:z$1.array(z$1.string()).optional(),pcb_component_id:z$1.string().optional(),pcb_port_id:z$1.string().optional()}),pcb_smtpad_rect=z$1.object({type:z$1.literal("pcb_smtpad"),shape:z$1.literal("rect"),pcb_smtpad_id:getZodPrefixedIdWithDefault("pcb_smtpad"),x:distance$1,y:distance$1,width:z$1.number(),height:z$1.number(),layer:layer_ref,port_hints:z$1.array(z$1.string()).optional(),pcb_component_id:z$1.string().optional(),pcb_port_id:z$1.string().optional()}),pcb_smtpad_rotated_rect=z$1.object({type:z$1.literal("pcb_smtpad"),shape:z$1.literal("rotated_rect"),pcb_smtpad_id:getZodPrefixedIdWithDefault("pcb_smtpad"),x:distance$1,y:distance$1,width:z$1.number(),height:z$1.number(),ccw_rotation:rotation,layer:layer_ref,port_hints:z$1.array(z$1.string()).optional(),pcb_component_id:z$1.string().optional(),pcb_port_id:z$1.string().optional()}),pcb_smtpad=z$1.union([pcb_smtpad_circle,pcb_smtpad_rect,pcb_smtpad_rotated_rect]).describe("Defines an SMT pad on the PCB"),pcb_solder_paste_circle=z$1.object({type:z$1.literal("pcb_solder_paste"),shape:z$1.literal("circle"),pcb_solder_paste_id:getZodPrefixedIdWithDefault("pcb_solder_paste"),x:distance$1,y:distance$1,radius:z$1.number(),layer:layer_ref,pcb_component_id:z$1.string().optional(),pcb_smtpad_id:z$1.string().optional()}),pcb_solder_paste_rect=z$1.object({type:z$1.literal("pcb_solder_paste"),shape:z$1.literal("rect"),pcb_solder_paste_id:getZodPrefixedIdWithDefault("pcb_solder_paste"),x:distance$1,y:distance$1,width:z$1.number(),height:z$1.number(),layer:layer_ref,pcb_component_id:z$1.string().optional(),pcb_smtpad_id:z$1.string().optional()}),pcb_solder_paste=z$1.union([pcb_solder_paste_circle,pcb_solder_paste_rect]).describe("Defines solderpaste on the PCB"),pcb_text=z$1.object({type:z$1.literal("pcb_text"),pcb_text_id:getZodPrefixedIdWithDefault("pcb_text"),text:z$1.string(),center:point$1,layer:layer_ref,width:length$1,height:length$1,lines:z$1.number(),align:z$1.enum(["bottom-left"])}).describe("Defines text on the PCB"),pcb_trace_route_point_wire=z$1.object({route_type:z$1.literal("wire"),x:distance$1,y:distance$1,width:distance$1,start_pcb_port_id:z$1.string().optional(),end_pcb_port_id:z$1.string().optional(),layer:layer_ref}),pcb_trace_route_point_via=z$1.object({route_type:z$1.literal("via"),x:distance$1,y:distance$1,from_layer:z$1.string(),to_layer:z$1.string()}),pcb_trace_route_point=z$1.union([pcb_trace_route_point_wire,pcb_trace_route_point_via]),pcb_trace=z$1.object({type:z$1.literal("pcb_trace"),source_trace_id:z$1.string().optional(),pcb_component_id:z$1.string().optional(),pcb_trace_id:getZodPrefixedIdWithDefault("pcb_trace"),route_thickness_mode:z$1.enum(["constant","interpolated"]).default("constant").optional(),route_order_index:z$1.number().optional(),should_round_corners:z$1.boolean().optional(),trace_length:z$1.number().optional(),route:z$1.array(z$1.union([z$1.object({route_type:z$1.literal("wire"),x:distance$1,y:distance$1,width:distance$1,start_pcb_port_id:z$1.string().optional(),end_pcb_port_id:z$1.string().optional(),layer:layer_ref}),z$1.object({route_type:z$1.literal("via"),x:distance$1,y:distance$1,from_layer:z$1.string(),to_layer:z$1.string()})]))}).describe("Defines a trace on the PCB"),pcb_trace_error=z$1.object({type:z$1.literal("pcb_trace_error"),pcb_trace_error_id:getZodPrefixedIdWithDefault("pcb_trace_error"),error_type:z$1.literal("pcb_trace_error"),message:z$1.string(),center:point$1.optional(),pcb_trace_id:z$1.string(),source_trace_id:z$1.string(),pcb_component_ids:z$1.array(z$1.string()),pcb_port_ids:z$1.array(z$1.string())}).describe("Defines a trace error on the PCB"),pcb_port_not_matched_error=z$1.object({type:z$1.literal("pcb_port_not_matched_error"),pcb_error_id:getZodPrefixedIdWithDefault("pcb_error"),message:z$1.string(),pcb_component_ids:z$1.array(z$1.string())}).describe("Defines a trace error on the PCB where a port is not matched"),pcb_via=z$1.object({type:z$1.literal("pcb_via"),pcb_via_id:getZodPrefixedIdWithDefault("pcb_via"),x:distance$1,y:distance$1,outer_diameter:distance$1.default("0.6mm"),hole_diameter:distance$1.default("0.25mm"),from_layer:layer_ref.optional(),to_layer:layer_ref.optional(),layers:z$1.array(layer_ref),pcb_trace_id:z$1.string().optional()}).describe("Defines a via on the PCB"),pcb_board=z$1.object({type:z$1.literal("pcb_board"),pcb_board_id:getZodPrefixedIdWithDefault("pcb_board"),width:length$1,height:length$1,center:point$1,thickness:length$1.optional().default(1.4),num_layers:z$1.number().optional().default(4),outline:z$1.array(point$1).optional()}).describe("Defines the board outline of the PCB"),pcb_placement_error=z$1.object({type:z$1.literal("pcb_placement_error"),pcb_placement_error_id:getZodPrefixedIdWithDefault("pcb_placement_error"),message:z$1.string()}).describe("Defines a placement error on the PCB"),pcb_trace_hint=z$1.object({type:z$1.literal("pcb_trace_hint"),pcb_trace_hint_id:getZodPrefixedIdWithDefault("pcb_trace_hint"),pcb_port_id:z$1.string(),pcb_component_id:z$1.string(),route:z$1.array(route_hint_point)}).describe("A hint that can be used during generation of a PCB trace"),pcb_silkscreen_line=z$1.object({type:z$1.literal("pcb_silkscreen_line"),pcb_silkscreen_line_id:getZodPrefixedIdWithDefault("pcb_silkscreen_line"),pcb_component_id:z$1.string(),stroke_width:distance$1.default("0.1mm"),x1:distance$1,y1:distance$1,x2:distance$1,y2:distance$1,layer:visible_layer}).describe("Defines a silkscreen line on the PCB"),pcb_silkscreen_path=z$1.object({type:z$1.literal("pcb_silkscreen_path"),pcb_silkscreen_path_id:getZodPrefixedIdWithDefault("pcb_silkscreen_path"),pcb_component_id:z$1.string(),layer:visible_layer,route:z$1.array(point$1),stroke_width:length$1}).describe("Defines a silkscreen path on the PCB"),pcb_silkscreen_text=z$1.object({type:z$1.literal("pcb_silkscreen_text"),pcb_silkscreen_text_id:getZodPrefixedIdWithDefault("pcb_silkscreen_text"),font:z$1.literal("tscircuit2024").default("tscircuit2024"),font_size:distance$1.default("0.2mm"),pcb_component_id:z$1.string(),text:z$1.string(),ccw_rotation:z$1.number().optional(),layer:layer_ref,is_mirrored:z$1.boolean().default(!1).optional(),anchor_position:point$1.default({x:0,y:0}),anchor_alignment:z$1.enum(["center","top_left","top_right","bottom_left","bottom_right"]).default("center")}).describe("Defines silkscreen text on the PCB"),pcb_silkscreen_rect=z$1.object({type:z$1.literal("pcb_silkscreen_rect"),pcb_silkscreen_rect_id:getZodPrefixedIdWithDefault("pcb_silkscreen_rect"),pcb_component_id:z$1.string(),center:point$1,width:length$1,height:length$1,layer:layer_ref}).describe("Defines a silkscreen rect on the PCB"),pcb_silkscreen_circle=z$1.object({type:z$1.literal("pcb_silkscreen_circle"),pcb_silkscreen_circle_id:getZodPrefixedIdWithDefault("pcb_silkscreen_circle"),pcb_component_id:z$1.string(),center:point$1,radius:length$1,layer:visible_layer}).describe("Defines a silkscreen circle on the PCB"),pcb_silkscreen_oval=z$1.object({type:z$1.literal("pcb_silkscreen_oval"),pcb_silkscreen_oval_id:getZodPrefixedIdWithDefault("pcb_silkscreen_oval"),pcb_component_id:z$1.string(),center:point$1,radius_x:distance$1,radius_y:distance$1,layer:visible_layer}).describe("Defines a silkscreen oval on the PCB"),pcb_fabrication_note_text=z$1.object({type:z$1.literal("pcb_fabrication_note_text"),pcb_fabrication_note_text_id:getZodPrefixedIdWithDefault("pcb_fabrication_note_text"),font:z$1.literal("tscircuit2024").default("tscircuit2024"),font_size:distance$1.default("1mm"),pcb_component_id:z$1.string(),text:z$1.string(),layer:visible_layer,anchor_position:point$1.default({x:0,y:0}),anchor_alignment:z$1.enum(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),color:z$1.string().optional()}).describe("Defines a fabrication note in text on the PCB, useful for leaving notes for assemblers or fabricators"),pcb_fabrication_note_path=z$1.object({type:z$1.literal("pcb_fabrication_note_path"),pcb_fabrication_note_path_id:getZodPrefixedIdWithDefault("pcb_fabrication_note_path"),pcb_component_id:z$1.string(),layer:layer_ref,route:z$1.array(point$1),stroke_width:length$1,color:z$1.string().optional()}).describe("Defines a fabrication path on the PCB for fabricators or assemblers"),pcb_keepout=z$1.object({type:z$1.literal("pcb_keepout"),shape:z$1.literal("rect"),center:point$1,width:distance$1,height:distance$1,pcb_keepout_id:z$1.string(),layers:z$1.array(z$1.string()),description:z$1.string().optional()}).or(z$1.object({type:z$1.literal("pcb_keepout"),shape:z$1.literal("circle"),center:point$1,radius:distance$1,pcb_keepout_id:z$1.string(),layers:z$1.array(z$1.string()),description:z$1.string().optional()})),pcb_missing_footprint_error=z$1.object({type:z$1.literal("pcb_missing_footprint_error"),pcb_missing_footprint_error_id:getZodPrefixedIdWithDefault("pcb_missing_footprint_error"),error_type:z$1.literal("pcb_missing_footprint_error"),source_component_id:z$1.string(),message:z$1.string()}).describe("Defines a missing footprint error on the PCB"),pcb_manual_edit_conflict_error=z$1.object({type:z$1.literal("pcb_manual_edit_conflict_error"),pcb_error_id:getZodPrefixedIdWithDefault("pcb_manual_edit_conflict_error"),message:z$1.string(),pcb_component_id:z$1.string(),source_component_id:z$1.string()}).describe("Error emitted when a component has both manual placement and explicit pcbX/pcbY coordinates"),pcb_group=z$1.object({type:z$1.literal("pcb_group"),pcb_group_id:getZodPrefixedIdWithDefault("pcb_group"),width:length$1,height:length$1,center:point$1,pcb_component_ids:z$1.array(z$1.string()),name:z$1.string().optional(),description:z$1.string().optional()}).describe("Defines a group of components on the PCB"),cad_component=z$1.object({type:z$1.literal("cad_component"),cad_component_id:z$1.string(),pcb_component_id:z$1.string(),source_component_id:z$1.string(),position:point3$1,rotation:point3$1.optional(),size:point3$1.optional(),layer:layer_ref.optional(),footprinter_string:z$1.string().optional(),model_obj_url:z$1.string().optional(),model_stl_url:z$1.string().optional(),model_3mf_url:z$1.string().optional(),model_jscad:z$1.any().optional()}).describe("Defines a component on the PCB"),any_circuit_element=z$1.union([source_trace,source_port,any_source_component,source_led,source_net,source_group,source_simple_bug,source_simple_chip,source_simple_capacitor,source_simple_diode,source_simple_resistor,source_simple_power_source,source_simple_battery,source_simple_inductor,source_simple_pin_header,source_simple_resonator,source_simple_transistor,source_simple_mosfet,source_simple_potentiometer,source_simple_push_button,pcb_component,pcb_hole,pcb_missing_footprint_error,pcb_manual_edit_conflict_error,pcb_plated_hole,pcb_keepout,pcb_port,pcb_text,pcb_trace,pcb_via,pcb_smtpad,pcb_solder_paste,pcb_board,pcb_group,pcb_trace_hint,pcb_silkscreen_line,pcb_silkscreen_path,pcb_silkscreen_text,pcb_silkscreen_rect,pcb_silkscreen_circle,pcb_silkscreen_oval,pcb_trace_error,pcb_placement_error,pcb_port_not_matched_error,pcb_fabrication_note_path,pcb_fabrication_note_text,schematic_box,schematic_text,schematic_line,schematic_component,schematic_port,schematic_trace,schematic_path,schematic_error,schematic_net_label,schematic_debug_object,schematic_voltage_probe,cad_component]),any_soup_element=any_circuit_element;const Soup=Object.freeze(Object.defineProperty({__proto__:null,all_layers,any_circuit_element,any_soup_element,any_source_component,battery_capacity,cad_component,capacitance,current,distance:distance$1,frequency,getZodPrefixedIdWithDefault,inductance,layer_ref,layer_string,length:length$1,pcb_board,pcb_component,pcb_fabrication_note_path,pcb_fabrication_note_text,pcb_group,pcb_hole,pcb_hole_circle_or_square_shape,pcb_hole_oval_shape,pcb_keepout,pcb_manual_edit_conflict_error,pcb_missing_footprint_error,pcb_placement_error,pcb_plated_hole,pcb_port,pcb_port_not_matched_error,pcb_route_hint,pcb_route_hints,pcb_silkscreen_circle,pcb_silkscreen_line,pcb_silkscreen_oval,pcb_silkscreen_path,pcb_silkscreen_rect,pcb_silkscreen_text,pcb_smtpad,pcb_solder_paste,pcb_text,pcb_trace,pcb_trace_error,pcb_trace_hint,pcb_trace_route_point,pcb_trace_route_point_via,pcb_trace_route_point_wire,pcb_via,point:point$1,point3:point3$1,port_arrangement,position:position$1,position3,resistance,rotation,route_hint_point,schematic_box,schematic_component,schematic_component_port_arrangement_by_sides,schematic_component_port_arrangement_by_size,schematic_debug_line,schematic_debug_object,schematic_debug_object_base,schematic_debug_point,schematic_debug_rect,schematic_error,schematic_line,schematic_net_label,schematic_path,schematic_pin_styles,schematic_port,schematic_text,schematic_trace,schematic_voltage_probe,size:size$3,source_component_base,source_group,source_led,source_net,source_port,source_simple_battery,source_simple_bug,source_simple_capacitor,source_simple_chip,source_simple_crystal,source_simple_diode,source_simple_ground,source_simple_inductor,source_simple_mosfet,source_simple_pin_header,source_simple_potentiometer,source_simple_power_source,source_simple_push_button,source_simple_resistor,source_simple_resonator,source_simple_transistor,source_trace,supplier_name,time,visible_layer,voltage},Symbol.toStringTag,{value:"Module"}));var direction=z$1.enum(["up","down","left","right"]);z$1.enum(["top-to-bottom","left-to-right","bottom-to-top","right-to-left"]);var portHints=z$1.array(z$1.string().or(z$1.number())),point3=z$1.object({x:distance$6,y:distance$6,z:distance$6}),rotationPoint3=z$1.object({x:z$1.union([z$1.number(),z$1.string()]),y:z$1.union([z$1.number(),z$1.string()]),z:z$1.union([z$1.number(),z$1.string()])}),cadModelBase=z$1.object({rotationOffset:z$1.number().or(rotationPoint3).optional(),positionOffset:point3.optional(),size:point3.optional()}),cadModelStl=cadModelBase.extend({stlUrl:z$1.string()}),cadModelObj=cadModelBase.extend({objUrl:z$1.string(),mtlUrl:z$1.string().optional()}),cadModelJscad=cadModelBase.extend({jscad:z$1.record(z$1.any())}),cadModelProp=z$1.union([z$1.string(),cadModelStl,cadModelObj,cadModelJscad]),footprintProp=z$1.custom(lV=>!0),pcbLayoutProps=z$1.object({pcbX:distance$6.optional(),pcbY:distance$6.optional(),pcbRotation:rotation$5.optional(),layer:layer_ref$3.optional()}),commonLayoutProps=z$1.object({pcbX:distance$6.optional(),pcbY:distance$6.optional(),pcbRotation:rotation$5.optional(),schX:distance$6.optional(),schY:distance$6.optional(),schRotation:rotation$5.optional(),layer:layer_ref$3.optional(),footprint:footprintProp.optional()}),supplierProps=z$1.object({supplierPartNumbers:z$1.record(supplier_name$3,z$1.array(z$1.string())).optional()}),commonComponentProps=commonLayoutProps.merge(supplierProps).extend({key:z$1.any().optional(),name:z$1.string(),cadModel:cadModelProp.optional(),children:z$1.any().optional(),symbolName:z$1.string().optional()}),lrPins=["pin1","left","pin2","right"],lrPolarPins=["pin1","left","anode","pos","pin2","right","cathode","neg"];distance$6.or(z$1.enum(["2x","3x","4x"]));var explicitPinSideDefinition=z$1.object({pins:z$1.array(z$1.union([z$1.number(),z$1.string()])),direction:z$1.union([z$1.literal("top-to-bottom"),z$1.literal("left-to-right"),z$1.literal("bottom-to-top"),z$1.literal("right-to-left")])}),schematicPortArrangement=z$1.object({leftSize:z$1.number().optional().describe("@deprecated, use leftPinCount"),topSize:z$1.number().optional().describe("@deprecated, use topPinCount"),rightSize:z$1.number().optional().describe("@deprecated, use rightPinCount"),bottomSize:z$1.number().optional().describe("@deprecated, use bottomPinCount"),leftPinCount:z$1.number().optional(),rightPinCount:z$1.number().optional(),topPinCount:z$1.number().optional(),bottomPinCount:z$1.number().optional(),leftSide:explicitPinSideDefinition.optional(),rightSide:explicitPinSideDefinition.optional(),topSide:explicitPinSideDefinition.optional(),bottomSide:explicitPinSideDefinition.optional()}),schematicPinStyle=z$1.record(z$1.object({leftMargin:distance$6.optional(),rightMargin:distance$6.optional(),topMargin:distance$6.optional(),bottomMargin:distance$6.optional()})),point=z$1.object({x:distance$6,y:distance$6}),base_manual_edit_event=z$1.object({edit_event_id:z$1.string(),in_progress:z$1.boolean().optional(),created_at:z$1.number()}),edit_pcb_component_location_event=base_manual_edit_event.extend({pcb_edit_event_type:z$1.literal("edit_component_location").describe("deprecated"),edit_event_type:z$1.literal("edit_pcb_component_location"),pcb_component_id:z$1.string(),original_center:z$1.object({x:z$1.number(),y:z$1.number()}),new_center:z$1.object({x:z$1.number(),y:z$1.number()})}),edit_trace_hint_event=base_manual_edit_event.extend({pcb_edit_event_type:z$1.literal("edit_trace_hint").describe("deprecated"),edit_event_type:z$1.literal("edit_pcb_trace_hint").optional(),pcb_port_id:z$1.string(),pcb_trace_hint_id:z$1.string().optional(),route:z$1.array(z$1.object({x:z$1.number(),y:z$1.number(),via:z$1.boolean().optional()}))}),edit_schematic_component_location_event=base_manual_edit_event.extend({edit_event_type:z$1.literal("edit_schematic_component_location"),schematic_component_id:z$1.string(),original_center:z$1.object({x:z$1.number(),y:z$1.number()}),new_center:z$1.object({x:z$1.number(),y:z$1.number()})});z$1.union([edit_pcb_component_location_event,edit_trace_hint_event,edit_schematic_component_location_event]);var manual_pcb_placement=z$1.object({selector:z$1.string(),relative_to:z$1.string().optional().default("group_center").describe("Can be a selector or 'group_center'"),center:point$5}),manual_trace_hint=z$1.object({pcb_port_selector:z$1.string(),offsets:z$1.array(route_hint_point$3)}),manual_schematic_placement=z$1.object({selector:z$1.string(),relative_to:z$1.string().optional().default("group_center").describe("Can be a selector or 'group_center'"),center:point$5}),manual_edits_file=z$1.object({pcb_placements:z$1.array(manual_pcb_placement).optional(),manual_trace_hints:z$1.array(manual_trace_hint).optional(),schematic_placements:z$1.array(manual_schematic_placement).optional()}),autorouterConfig=z$1.object({serverUrl:z$1.string().optional(),inputFormat:z$1.enum(["simplified","circuit-json"]).optional(),serverMode:z$1.enum(["job","solve-endpoint"]).optional(),cache:z$1.custom(lV=>!0).optional()}),autorouterProp=z$1.union([autorouterConfig,z$1.literal("sequential-trace"),z$1.literal("subcircuit"),z$1.literal("auto"),z$1.literal("auto-local"),z$1.literal("auto-cloud")]),baseGroupProps=commonLayoutProps.extend({name:z$1.string().optional(),children:z$1.any().optional()}),subcircuitGroupProps=baseGroupProps.extend({layout:z$1.custom(lV=>!0).optional(),manualEdits:manual_edits_file.optional(),schAutoLayoutEnabled:z$1.boolean().optional(),routingDisabled:z$1.boolean().optional(),defaultTraceWidth:length$5.optional(),minTraceWidth:length$5.optional(),partsEngine:z$1.custom(lV=>"findPart"in lV).optional(),pcbRouteCache:z$1.custom(lV=>!0).optional(),autorouter:autorouterProp.optional()}),subcircuitGroupPropsWithBool=subcircuitGroupProps.extend({subcircuit:z$1.literal(!0)}),groupProps=z$1.discriminatedUnion("subcircuit",[baseGroupProps.extend({subcircuit:z$1.literal(!1).optional()}),subcircuitGroupPropsWithBool]),boardProps=subcircuitGroupProps.extend({width:distance$6.optional(),height:distance$6.optional(),outline:z$1.array(point).optional(),outlineOffsetX:distance$6.optional(),outlineOffsetY:distance$6.optional()});z$1.record(z$1.number().or(z$1.string()),z$1.string().or(z$1.array(z$1.string()).readonly()).or(z$1.array(z$1.string())));var chipProps=commonComponentProps.extend({manufacturerPartNumber:z$1.string().optional(),pinLabels:z$1.record(z$1.number().or(z$1.string()),z$1.string().or(z$1.array(z$1.string()).readonly())).optional(),schPortArrangement:schematicPortArrangement.optional(),schPinStyle:schematicPinStyle.optional(),schPinSpacing:distance$6.optional(),schWidth:distance$6.optional(),schHeight:distance$6.optional(),noSchematicRepresentation:z$1.boolean().optional()}),jumperProps=commonComponentProps.extend({manufacturerPartNumber:z$1.string().optional(),pinLabels:z$1.record(z$1.number().or(z$1.string()),z$1.string().or(z$1.array(z$1.string()))).optional(),schPinStyle:schematicPinStyle.optional(),schPinSpacing:distance$6.optional(),schWidth:distance$6.optional(),schHeight:distance$6.optional(),schDirection:z$1.enum(["left","right"]).optional(),schPortArrangement:schematicPortArrangement.optional()}),platedHoleProps=z$1.discriminatedUnion("shape",[pcbLayoutProps.omit({pcbRotation:!0,layer:!0}).extend({name:z$1.string().optional(),shape:z$1.literal("circle"),holeDiameter:distance$6,outerDiameter:distance$6,portHints:portHints.optional()}),pcbLayoutProps.omit({pcbRotation:!0,layer:!0}).extend({name:z$1.string().optional(),shape:z$1.literal("oval"),outerWidth:distance$6,outerHeight:distance$6,innerWidth:distance$6,innerHeight:distance$6,portHints:portHints.optional()}),pcbLayoutProps.omit({pcbRotation:!0,layer:!0}).extend({name:z$1.string().optional(),shape:z$1.literal("pill"),outerWidth:distance$6,outerHeight:distance$6,innerWidth:distance$6,innerHeight:distance$6,portHints:portHints.optional()})]),resistorProps=commonComponentProps.extend({resistance:resistance$3,pullupFor:z$1.string().optional(),pullupTo:z$1.string().optional(),pulldownFor:z$1.string().optional(),pulldownTo:z$1.string().optional()}),resistorPins=lrPins,potentiometerProps=commonComponentProps.extend({maxResistance:resistance$3}),crystalProps=commonComponentProps.extend({frequency:frequency$2,loadCapacitance:capacitance$3,pinVariant:z$1.enum(["2pin","4pin"]).optional()}),resonatorProps=commonComponentProps.extend({frequency:frequency$2,loadCapacitance:capacitance$3,pinVariant:z$1.enum(["no_ground","ground_pin","two_ground_pins"]).optional()}),capacitorProps=commonComponentProps.extend({capacitance:capacitance$3,polarized:z$1.boolean().optional().default(!1),decouplingFor:z$1.string().optional(),decouplingTo:z$1.string().optional(),bypassFor:z$1.string().optional(),bypassTo:z$1.string().optional(),maxDecouplingTraceLength:z$1.number().optional()}),capacitorPins=lrPolarPins;z$1.object({name:z$1.string()}),z$1.object({name:z$1.string().optional(),pcbOnly:z$1.boolean().optional(),schOnly:z$1.boolean().optional()});var pcbXDistConstraintProps=z$1.object({pcb:z$1.literal(!0).optional(),xDist:distance$6,left:z$1.string(),right:z$1.string(),edgeToEdge:z$1.literal(!0).optional(),centerToCenter:z$1.literal(!0).optional()}),pcbYDistConstraintProps=z$1.object({pcb:z$1.literal(!0).optional(),yDist:distance$6,top:z$1.string(),bottom:z$1.string(),edgeToEdge:z$1.literal(!0).optional(),centerToCenter:z$1.literal(!0).optional()}),pcbSameYConstraintProps=z$1.object({pcb:z$1.literal(!0).optional(),sameY:z$1.literal(!0).optional(),for:z$1.array(z$1.string())}),pcbSameXConstraintProps=z$1.object({pcb:z$1.literal(!0).optional(),sameX:z$1.literal(!0).optional(),for:z$1.array(z$1.string())}),constraintProps=z$1.union([pcbXDistConstraintProps,pcbYDistConstraintProps,pcbSameYConstraintProps,pcbSameXConstraintProps]),rectSmtPadProps=pcbLayoutProps.omit({pcbRotation:!0}).extend({shape:z$1.literal("rect"),width:distance$6,height:distance$6,portHints:portHints.optional()}),rotatedRectSmtPadProps=pcbLayoutProps.omit({pcbRotation:!0}).extend({shape:z$1.literal("rotated_rect"),width:distance$6,height:distance$6,ccwRotation:z$1.number(),portHints:portHints.optional()}),circleSmtPadProps=pcbLayoutProps.omit({pcbRotation:!0}).extend({shape:z$1.literal("circle"),radius:distance$6,portHints:portHints.optional()}),smtPadProps=z$1.union([circleSmtPadProps,rectSmtPadProps,rotatedRectSmtPadProps]),rectSolderPasteProps=pcbLayoutProps.omit({pcbRotation:!0}).extend({shape:z$1.literal("rect"),width:distance$6,height:distance$6}),circleSolderPasteProps=pcbLayoutProps.omit({pcbRotation:!0}).extend({shape:z$1.literal("circle"),radius:distance$6});z$1.union([circleSolderPasteProps,rectSolderPasteProps]);var holeProps=pcbLayoutProps.omit({pcbRotation:!0}).extend({name:z$1.string().optional(),diameter:distance$6.optional(),radius:distance$6.optional()}).transform(lV=>({...lV,diameter:lV.diameter??2*lV.radius,radius:lV.radius??lV.diameter/2})),portRef=z$1.union([z$1.string(),z$1.custom(lV=>!!lV.getPortSelector)]),baseTraceProps=z$1.object({key:z$1.string().optional(),thickness:distance$6.optional(),schematicRouteHints:z$1.array(point).optional(),pcbRouteHints:z$1.array(route_hint_point$3).optional(),schDisplayLabel:z$1.string().optional(),maxLength:z$1.number().optional()}),traceProps=z$1.union([baseTraceProps.extend({path:z$1.array(portRef)}),baseTraceProps.extend({from:portRef,to:portRef})]),footprintProps=z$1.object({originalLayer:layer_ref$3.default("top").optional()}),capacity=z$1.number().or(z$1.string().endsWith("mAh")).transform(lV=>{if(typeof lV=="string"){const J=lV.replace("mAh",""),VV=Number.parseFloat(J);if(Number.isNaN(VV))throw new Error("Invalid capacity");return VV}return lV}).describe("Battery capacity in mAh"),batteryProps=commonComponentProps.extend({capacity:capacity.optional()}),pinHeaderProps=commonComponentProps.extend({pinCount:z$1.number(),pitch:distance$6.optional(),gender:z$1.enum(["male","female"]).optional().default("male"),showSilkscreenPinLabels:z$1.boolean().optional(),doubleRow:z$1.boolean().optional(),holeDiameter:distance$6.optional(),platedDiameter:distance$6.optional(),pinLabels:z$1.array(z$1.string()).optional(),facingDirection:z$1.enum(["left","right"]).optional()}),netAliasProps=z$1.object({net:z$1.string().optional(),schX:distance$6.optional(),schY:distance$6.optional(),schRotation:rotation$5.optional(),anchorSide:z$1.enum(["left","up","right","down"]).optional()}),pushButtonProps=commonComponentProps.extend({}),transistorProps=commonComponentProps.extend({transistorType:z$1.enum(["npn","pnp"])}),mosfetProps=commonComponentProps.extend({channelType:z$1.enum(["n","p"]),mosfetMode:z$1.enum(["enhancement","depletion"])}),inductorProps=commonComponentProps.extend({inductance:inductance$3}),diodeProps=commonComponentProps.extend({}),diodePins=lrPolarPins,ledProps=commonComponentProps.extend({color:z$1.string().optional()}),ledPins=lrPolarPins;commonComponentProps.extend({ftype:z$1.literal("switch"),switchType:z$1.enum(["spst"]).default("spst"),isNormallyClosed:z$1.boolean().default(!1)}),distance$6.or(z$1.enum(["2x","3x","4x"]));var viaProps=commonLayoutProps.extend({fromLayer:layer_ref$3,toLayer:layer_ref$3,holeDiameter:distance$6,outerDiameter:distance$6}),pcbKeepoutProps=z$1.union([pcbLayoutProps.omit({pcbRotation:!0}).extend({shape:z$1.literal("circle"),radius:distance$6}),pcbLayoutProps.extend({shape:z$1.literal("rect"),width:distance$6,height:distance$6})]);z$1.object({schX:distance$6,schY:distance$6,width:distance$6,height:distance$6}),z$1.object({schX:distance$6,schY:distance$6,text:z$1.string()}),z$1.object({x1:distance$6,y1:distance$6,x2:distance$6,y2:distance$6}),z$1.object({points:z$1.array(point$5),isFilled:z$1.boolean().optional().default(!1),fillColor:z$1.enum(["red","blue"]).optional()});var powerSourceProps=commonComponentProps.extend({voltage:voltage$3});commonLayoutProps.extend({name:z$1.string(),pinNumber:z$1.number().optional(),aliases:z$1.array(z$1.string()).optional(),direction});var silkscreenTextProps=pcbLayoutProps.extend({text:z$1.string(),anchorAlignment:z$1.enum(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),font:z$1.enum(["tscircuit2024"]).optional(),fontSize:length$5.optional()}),silkscreenPathProps=pcbLayoutProps.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({route:z$1.array(route_hint_point$3),strokeWidth:length$5.optional()}),silkscreenLineProps=pcbLayoutProps.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({strokeWidth:distance$6,x1:distance$6,y1:distance$6,x2:distance$6,y2:distance$6}),silkscreenRectProps=pcbLayoutProps.omit({pcbRotation:!0}).extend({isFilled:z$1.boolean().optional(),isOutline:z$1.boolean().optional(),strokeWidth:distance$6.optional(),width:distance$6,height:distance$6}),silkscreenCircleProps=pcbLayoutProps.omit({pcbRotation:!0}).extend({isFilled:z$1.boolean().optional(),isOutline:z$1.boolean().optional(),strokeWidth:distance$6.optional(),radius:distance$6}),routeHintPointProps=z$1.object({x:distance$6,y:distance$6,via:z$1.boolean().optional(),toLayer:layer_ref$3.optional()}),traceHintProps=z$1.object({for:z$1.string().optional().describe("Selector for the port you're targeting, not required if you're inside a trace"),order:z$1.number().optional(),offset:route_hint_point$3.or(routeHintPointProps).optional(),offsets:z$1.array(route_hint_point$3).or(z$1.array(routeHintPointProps)).optional(),traceWidth:z$1.number().optional()});z$1.object({layer:z$1.string().optional(),thickness:distance$6.optional(),route:z$1.array(route_hint_point$3)});var fabricationNoteTextProps=pcbLayoutProps.extend({text:z$1.string(),anchorAlignment:z$1.enum(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),font:z$1.enum(["tscircuit2024"]).optional(),fontSize:length$5.optional(),color:z$1.string().optional()}),fabricationNotePathProps=pcbLayoutProps.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({route:z$1.array(route_hint_point$3),strokeWidth:length$5.optional(),color:z$1.string().optional()}),su$1=(lV,J={})=>{let VV=lV._internal_store;if(!VV){VV={counts:{}},lV._internal_store=VV;for(const UV of lV){const ZV=UV.type,WV=UV[`${ZV}_id`];if(!WV)continue;const IV=Number.parseInt(WV.split("_").pop());Number.isNaN(IV)||(VV.counts[ZV]=Math.max(VV.counts[ZV]??0,IV))}}return new Proxy({},{get:(UV,ZV)=>ZV==="toArray"?()=>lV:{get:WV=>lV.find(IV=>IV.type===ZV&&IV[`${ZV}_id`]===WV),getUsing:WV=>{const IV=Object.keys(WV);if(IV.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const dV=IV[0],CV=dV.replace("_id",""),FV=lV.find(NV=>NV.type===CV&&NV[dV]===WV[dV]);return FV?lV.find(NV=>NV.type===ZV&&NV[`${ZV}_id`]===FV[`${ZV}_id`]):null},getWhere:WV=>{const IV=Object.keys(WV);return lV.find(dV=>dV.type===ZV&&IV.every(CV=>dV[CV]===WV[CV]))},list:WV=>{const IV=WV?Object.keys(WV):[];return lV.filter(dV=>dV.type===ZV&&IV.every(CV=>dV[CV]===WV[CV]))},insert:WV=>{var CV;(CV=VV.counts)[ZV]??(CV[ZV]=-1),VV.counts[ZV]++;const IV=VV.counts[ZV],dV={type:ZV,[`${ZV}_id`]:`${ZV}_${IV}`,...WV};return J.validateInserts&&(Soup[ZV]??any_soup_element).parse(dV),lV.push(dV),dV},delete:WV=>{const IV=lV.find(dV=>dV[`${ZV}_id`]===WV);IV&&lV.splice(lV.indexOf(IV),1)},update:(WV,IV)=>{const dV=lV.find(CV=>CV.type===ZV&&CV[`${ZV}_id`]===WV);if(dV)return Object.assign(dV,IV),dV},select:WV=>{if(ZV==="source_component")return lV.find(IV=>IV.type==="source_component"&&IV.name===WV.replace(/\./g,""));if(ZV==="pcb_port"||ZV==="source_port"||ZV==="schematic_port"){const[IV,dV]=WV.replace(/\./g,"").split(/[\s\>]+/),CV=lV.find(NV=>NV.type==="source_component"&&NV.name===IV);if(!CV)return null;const FV=lV.find(NV=>NV.type==="source_port"&&NV.source_component_id===CV.source_component_id&&(NV.name===dV||(NV.port_hints??[]).includes(dV)));if(!FV)return null;if(ZV==="source_port")return FV;if(ZV==="pcb_port")return lV.find(NV=>NV.type==="pcb_port"&&NV.source_port_id===FV.source_port_id);if(ZV==="schematic_port")return lV.find(NV=>NV.type==="schematic_port"&&NV.source_port_id===FV.source_port_id)}}}})};su$1.unparsed=su$1;var su_default$1=su$1,__defProp=Object.defineProperty,__export=(lV,J)=>{for(var VV in J)__defProp(lV,VV,{get:J[VV],enumerable:!0})},components_exports={};__export(components_exports,{Battery:()=>Battery,Board:()=>Board,Capacitor:()=>Capacitor,Chip:()=>Chip,Constraint:()=>Constraint2,Crystal:()=>Crystal,Diode:()=>Diode,FabricationNotePath:()=>FabricationNotePath,FabricationNoteText:()=>FabricationNoteText,Footprint:()=>Footprint,Group:()=>Group$1,Hole:()=>Hole,Inductor:()=>Inductor,Jumper:()=>Jumper,Keepout:()=>Keepout,Led:()=>Led,Mosfet:()=>Mosfet,Net:()=>Net,NetAlias:()=>NetAlias,NormalComponent:()=>NormalComponent,PinHeader:()=>PinHeader,PlatedHole:()=>PlatedHole,Port:()=>Port,Potentiometer:()=>Potentiometer,PowerSource:()=>PowerSource,PrimitiveComponent:()=>PrimitiveComponent,PushButton:()=>PushButton,Renderable:()=>Renderable,Resistor:()=>Resistor,Resonator:()=>Resonator,SilkscreenCircle:()=>SilkscreenCircle,SilkscreenLine:()=>SilkscreenLine,SilkscreenPath:()=>SilkscreenPath,SilkscreenRect:()=>SilkscreenRect,SilkscreenText:()=>SilkscreenText,SmtPad:()=>SmtPad,Subcircuit:()=>Subcircuit,Trace:()=>Trace,TraceHint:()=>TraceHint,Transistor:()=>Transistor,Via:()=>Via});var orderedRenderPhases=["ReactSubtreesRender","InitializePortsFromChildren","CreateNetsFromProps","CreateTracesFromProps","CreateTraceHintsFromProps","SourceRender","SourceParentAttachment","PortDiscovery","PortMatching","SourceTraceRender","SourceAddConnectivityMapKey","SchematicComponentRender","SchematicPortRender","SchematicLayout","SchematicTraceRender","PcbComponentRender","PcbPrimitiveRender","PcbFootprintLayout","PcbPortRender","PcbPortAttachment","PcbLayout","PcbComponentSizeCalculation","PcbTraceRender","PcbTraceHintRender","PcbRouteNetIslands","CadModelRender","PartsEngineRender"],globalRenderCounter=0,Renderable=class{constructor(lV){kW(this,"renderPhaseStates");kW(this,"shouldBeRemoved",!1);kW(this,"children");kW(this,"isPcbPrimitive",!1);kW(this,"isSchematicPrimitive",!1);kW(this,"_renderId");kW(this,"_currentRenderPhase",null);kW(this,"_asyncEffects",[]);this._renderId=`${globalRenderCounter++}`,this.children=[],this.renderPhaseStates={};for(const J of orderedRenderPhases)this.renderPhaseStates[J]={initialized:!1,dirty:!1}}_markDirty(lV){this.renderPhaseStates[lV].dirty=!0;const J=orderedRenderPhases.indexOf(lV);for(let VV=J+1;VV<orderedRenderPhases.length;VV++)this.renderPhaseStates[orderedRenderPhases[VV]].dirty=!0}_queueAsyncEffect(lV,J){const VV={promise:J(),phase:this._currentRenderPhase,effectName:lV,complete:!1};this._asyncEffects.push(VV),VV.promise.then(()=>{VV.complete=!0,"root"in this&&this.root&&this.root.emit("asyncEffectComplete",{effectName:lV,componentDisplayName:this.getString(),phase:VV.phase})}).catch(RV=>{console.error(`Async effect error in ${VV.phase} "${lV}":
|
|
22050
|
-
${RV.stack}`),VV.complete=!0,"root"in this&&this.root&&this.root.emit("asyncEffectComplete",{effectName:lV,componentDisplayName:this.getString(),phase:VV.phase,error:RV.toString()})})}_emitRenderLifecycleEvent(lV,J){const VV={renderId:this._renderId,componentDisplayName:this.getString()},RV=`renderable:renderLifecycle:${lV}:${J}`;"root"in this&&this.root&&(this.root.emit(RV,{...VV,type:RV}),this.root.emit("renderable:renderLifecycle:anyEvent",{...VV,type:RV}))}getString(){return this.constructor.name}_hasIncompleteAsyncEffects(){return this._asyncEffects.some(lV=>!lV.complete)}getCurrentRenderPhase(){return this._currentRenderPhase}getRenderGraph(){return{id:this._renderId,currentPhase:this._currentRenderPhase,renderPhaseStates:this.renderPhaseStates,shouldBeRemoved:this.shouldBeRemoved,children:this.children.map(lV=>lV.getRenderGraph())}}runRenderCycle(){for(const lV of orderedRenderPhases)this.runRenderPhaseForChildren(lV),this.runRenderPhase(lV)}runRenderPhase(lV){var ZV,WV,IV;this._currentRenderPhase=lV;const J=this.renderPhaseStates[lV],VV=J.initialized,RV=J.dirty;if(!VV&&this.shouldBeRemoved)return;if(this.shouldBeRemoved&&VV){this._emitRenderLifecycleEvent(lV,"start"),(ZV=this==null?void 0:this[`remove${lV}`])==null||ZV.call(this),J.initialized=!1,J.dirty=!1,this._emitRenderLifecycleEvent(lV,"end");return}const UV=orderedRenderPhases.indexOf(lV)-1;if(UV>=0){const dV=orderedRenderPhases[UV];if(this._asyncEffects.filter(FV=>FV.phase===dV).some(FV=>!FV.complete))return}if(this._emitRenderLifecycleEvent(lV,"start"),VV){RV&&((WV=this==null?void 0:this[`update${lV}`])==null||WV.call(this),J.dirty=!1),this._emitRenderLifecycleEvent(lV,"end");return}J.dirty=!1,(IV=this==null?void 0:this[`doInitial${lV}`])==null||IV.call(this),J.initialized=!0,this._emitRenderLifecycleEvent(lV,"end")}runRenderPhaseForChildren(lV){for(const J of this.children)J.runRenderPhaseForChildren(lV),J.runRenderPhase(lV)}renderError(lV){throw typeof lV=="string"?new Error(lV):new Error(JSON.stringify(lV,null,2))}},catalogue={},extendCatalogue=lV=>{const J=Object.fromEntries(Object.entries(lV).map(([VV,RV])=>[VV.toLowerCase(),RV]));Object.assign(catalogue,lV),Object.assign(catalogue,J)};function prepare(lV,J){const VV=lV;return VV.__tsci={...J},lV}var hostConfig={supportsMutation:!0,createInstance(lV,J){const VV=catalogue[lV];if(!VV)throw Object.keys(catalogue).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): "${lV}" See CREATING_NEW_COMPONENTS.md`);return prepare(new VV(J),{})},createTextInstance(){return{}},appendInitialChild(lV,J){lV.add(J)},appendChild(lV,J){lV.add(J)},appendChildToContainer(lV,J){lV.add(J)},finalizeInitialChildren(){return!1},prepareUpdate(){return null},shouldSetTextContent(){return!1},getRootHostContext(){return{}},getChildHostContext(){return{}},prepareForCommit(){return null},resetAfterCommit(){},commitMount(){},commitUpdate(){},removeChild(){},clearContainer(){},supportsPersistence:!1,getPublicInstance(lV){return lV},preparePortalMount(lV){throw new Error("Function not implemented.")},scheduleTimeout(lV,J){throw new Error("Function not implemented.")},cancelTimeout(lV){throw new Error("Function not implemented.")},noTimeout:void 0,isPrimaryRenderer:!1,getCurrentEventPriority(){throw new Error("Function not implemented.")},getInstanceFromNode(lV){throw new Error("Function not implemented.")},beforeActiveInstanceBlur(){throw new Error("Function not implemented.")},afterActiveInstanceBlur(){throw new Error("Function not implemented.")},prepareScopeUpdate:(lV,J)=>{throw new Error("Function not implemented.")},getInstanceFromScope:lV=>{throw new Error("Function not implemented.")},detachDeletedInstance:lV=>{throw new Error("Function not implemented.")},supportsHydration:!1},reconciler=ReactReconciler(hostConfig),createInstanceFromReactElement=lV=>{const J={children:[],props:{name:"$root"},add(UV){UV.parent=this,this.children.push(UV)},computePcbGlobalTransform(){return identity$4()}},VV=reconciler.createContainer(J,0,null,!1,null,"tsci",UV=>{console.log("Error in createContainer"),console.error(UV)},null);reconciler.updateContainer(lV,VV,null,()=>{});const RV=reconciler.getPublicRootInstance(VV);return RV||J.children[0]},parsePinNumberFromLabelsOrThrow=(lV,J)=>{if(typeof lV=="number")return lV;if(lV.startsWith("pin"))return Number(lV.slice(3));if(!J)throw new Error(`No pin labels provided and pin number or label is not a number: "${lV}"`);for(const VV in J)if((Array.isArray(J[VV])?J[VV]:[J[VV]]).includes(lV))return Number(VV.replace("pin",""));throw new Error(`No pin labels provided and pin number or label is not a number: "${lV}"`)},underscorifyPinStyles=(lV,J)=>{if(!lV)return;const VV={},RV={};for(const[UV,ZV]of Object.entries(lV)){const WV=parsePinNumberFromLabelsOrThrow(UV,J);RV[WV]={...RV[WV],...ZV}}for(const[UV,ZV]of Object.entries(RV)){const WV=`pin${UV}`;VV[WV]={bottom_margin:ZV.bottomMargin,left_margin:ZV.leftMargin,right_margin:ZV.rightMargin,top_margin:ZV.topMargin}}return VV},underscorifyPortArrangement=lV=>{if(lV){if("leftSide"in lV||"rightSide"in lV||"topSide"in lV||"bottomSide"in lV)return{left_side:lV.leftSide,right_side:lV.rightSide,top_side:lV.topSide,bottom_side:lV.bottomSide};if("leftPinCount"in lV||"rightPinCount"in lV||"topPinCount"in lV||"bottomPinCount"in lV)return{left_size:lV.leftPinCount,right_size:lV.rightPinCount,top_size:lV.topPinCount,bottom_size:lV.bottomPinCount};if("leftSize"in lV||"rightSize"in lV||"topSize"in lV||"bottomSize"in lV)return{left_size:lV.leftSize,right_size:lV.rightSize,top_size:lV.topSize,bottom_size:lV.bottomSize}}},InvalidProps=class extends Error{constructor(lV,J,VV){let RV;const ZV=Object.keys(VV).filter(WV=>WV!=="_errors").map(WV=>VV[WV]._errors[0]?`${WV} (${VV[WV]._errors[0]})`:`${WV} (${JSON.stringify(VV[WV])})`).join(", ");"name"in J?RV=`Invalid props for ${lV} "${J.name}": ${ZV}`:"footprint"in J&&typeof J.footprint=="string"?RV=`Invalid props for ${lV} (unnamed ${J.footprint} component): ${ZV}`:RV=`Invalid props for ${lV} (unnamed): ${ZV}`,super(RV),this.componentName=lV,this.originalProps=J,this.formattedError=VV}};function isMatchingSelector(lV,J){const VV=J.match(/^#(\w+)/);if(VV)return lV.props.id===VV[1];const RV=J.match(/^\.(\w+)/);if(RV)return lV.isMatchingNameOrAlias(RV[1]);let[UV,...ZV]=J.split(/(?=[#.[])/);return UV==="pin"&&(UV="port"),UV&&UV!=="*"&&lV.lowercaseComponentName!==UV.toLowerCase()?!1:ZV.every(WV=>{if(WV.startsWith("#"))return lV.props.id===WV.slice(1);if(WV.startsWith("."))return lV.isMatchingNameOrAlias(WV.slice(1));const IV=WV.match(/\[(\w+)=['"]?(.+?)['"]?\]/);if(!IV)return!0;const[,dV,CV]=IV;return lV.props[dV].toString()===CV})}var debugSelectAll=Debug$1("tscircuit:primitive-component:selectAll"),PrimitiveComponent=class extends Renderable{constructor(J){super(J);kW(this,"parent",null);kW(this,"children");kW(this,"childrenPendingRemoval");kW(this,"props");kW(this,"_parsedProps");kW(this,"externallyAddedAliases");kW(this,"isPrimitiveContainer",!1);kW(this,"source_group_id",null);kW(this,"source_component_id",null);kW(this,"schematic_component_id",null);kW(this,"pcb_component_id",null);kW(this,"cad_component_id",null);this.children=[],this.childrenPendingRemoval=[],this.props=J??{},this.externallyAddedAliases=[];const VV=this.config.zodProps.safeParse(J??{});if(VV.success)this._parsedProps=VV.data;else throw new InvalidProps(this.lowercaseComponentName,this.props,VV.error.format())}get config(){return{componentName:"",zodProps:z$1.object({}).passthrough()}}get componentName(){return this.config.componentName}getInheritedProperty(J){let VV=this;for(;VV;){if(VV._parsedProps&&J in VV._parsedProps)return VV._parsedProps[J];VV=VV.parent}}get lowercaseComponentName(){return this.componentName.toLowerCase()}get isSubcircuit(){var J;return!!this.props.subcircuit||this.lowercaseComponentName==="group"&&((J=this==null?void 0:this.parent)==null?void 0:J.isRoot)}get isGroup(){return this.lowercaseComponentName==="group"}setProps(J){var UV,ZV;const VV=this.config.zodProps.parse({...this.props,...J}),RV=this.props;this.props=VV,this._parsedProps=this.config.zodProps.parse(J),this.onPropsChange({oldProps:RV,newProps:VV,changedProps:Object.keys(J)}),(ZV=(UV=this.parent)==null?void 0:UV.onChildChanged)==null||ZV.call(UV,this)}computePcbPropsTransform(){const{_parsedProps:J}=this;return compose(translate(J.pcbX??0,J.pcbY??0),rotate((J.pcbRotation??0)*Math.PI/180))}_computePcbGlobalTransformBeforeLayout(){var RV,UV,ZV;const{_parsedProps:J}=this,VV=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if(VV&&this.props.pcbX===void 0&&this.props.pcbY===void 0)return compose(((RV=this.parent)==null?void 0:RV._computePcbGlobalTransformBeforeLayout())??identity$4(),compose(translate(VV.x,VV.y),rotate((J.pcbRotation??0)*Math.PI/180)));if(this.isPcbPrimitive){const WV=this.getPrimitiveContainer();if(WV){const IV=WV._parsedProps.layer==="bottom",dV=WV._getGlobalPcbPositionBeforeLayout();if(IV)return compose(translate(dV.x,dV.y),flipY(),translate(-dV.x,-dV.y)),compose(((UV=this.parent)==null?void 0:UV._computePcbGlobalTransformBeforeLayout())??identity$4(),flipY(),this.computePcbPropsTransform())}}return compose(((ZV=this.parent)==null?void 0:ZV._computePcbGlobalTransformBeforeLayout())??identity$4(),this.computePcbPropsTransform())}getPrimitiveContainer(){var J,VV;return this.isPrimitiveContainer?this:((VV=(J=this.parent)==null?void 0:J.getPrimitiveContainer)==null?void 0:VV.call(J))??null}_getPcbCircuitJsonBounds(){return{center:{x:0,y:0},bounds:{left:0,top:0,right:0,bottom:0},width:0,height:0}}_getPcbPrimitiveFlippedHelpers(){const J=this.getPrimitiveContainer(),VV=J?J._parsedProps.layer==="bottom":!1;return{isFlipped:VV,maybeFlipLayer:UV=>VV?UV==="top"?"bottom":"top":UV}}_setPositionFromLayout(J){throw new Error(`_setPositionFromLayout not implemented for ${this.componentName}`)}computeSchematicPropsTransform(){return compose(translate(this.props.schX??0,this.props.schY??0))}computeSchematicGlobalTransform(){var VV,RV;const J=this._getSchematicGlobalManualPlacementTransform(this);return J||compose(((RV=(VV=this.parent)==null?void 0:VV.computeSchematicGlobalTransform)==null?void 0:RV.call(VV))??identity$4(),this.computeSchematicPropsTransform())}_getSchematicSymbolName(){const{_parsedProps:J}=this,VV=this.config.schematicSymbolName,RV=`${VV}_horz`,UV=`${VV}_vert`,ZV=`${VV}_up`,WV=`${VV}_down`,IV=`${VV}_left`,dV=`${VV}_right`;if(dV in symbols_index_default&&(J.schRotation===void 0||J.schRotation===0))return dV;if(ZV in symbols_index_default&&J.schRotation===90)return ZV;if(IV in symbols_index_default&&J.schRotation===180)return IV;if(WV in symbols_index_default&&J.schRotation===270)return WV;if(RV in symbols_index_default&&(J.schRotation===0||J.schRotation===void 0||J.schRotation===180))return RV;if(UV in symbols_index_default&&(J.schRotation===90||J.schRotation===270))return UV;if(VV in symbols_index_default)return VV}_getSchematicSymbolNameOrThrow(){const J=this._getSchematicSymbolName();if(!J)throw new Error(`No schematic symbol found (given: "${this.config.schematicSymbolName}")`);return J}getSchematicSymbol(){const J=this._getSchematicSymbolName();return J?symbols_index_default[J]??null:null}_getPcbManualPlacementForComponent(J){var ZV;if(!this.isSubcircuit)return null;const VV=this.props.layout,RV=this.props.manualEdits;if(!VV&&!RV)return null;const UV=((ZV=VV==null?void 0:VV.manual_pcb_placement_config)==null?void 0:ZV.positions)||(RV==null?void 0:RV.pcb_placements);if(!UV)return null;for(const WV of UV)if(VV&&isMatchingSelector(J,WV.selector)||J.props.name===WV.selector)return applyToPoint(this._computePcbGlobalTransformBeforeLayout(),WV.center);return null}_getSchematicGlobalManualPlacementTransform(J){var RV,UV;const VV=(RV=this.getSubcircuit())==null?void 0:RV._parsedProps.manualEdits;if(!VV)return null;for(const ZV of VV.schematic_placements??[])if((isMatchingSelector(J,ZV.selector)||J.props.name===ZV.selector)&&ZV.relative_to==="group_center")return compose(((UV=this.parent)==null?void 0:UV._computePcbGlobalTransformBeforeLayout())??identity$4(),translate(ZV.center.x,ZV.center.y));return null}_getGlobalPcbPositionBeforeLayout(){return applyToPoint(this._computePcbGlobalTransformBeforeLayout(),{x:0,y:0})}_getGlobalSchematicPositionBeforeLayout(){return applyToPoint(this.computeSchematicGlobalTransform(),{x:0,y:0})}get root(){var J;return((J=this.parent)==null?void 0:J.root)??null}onAddToParent(J){this.parent=J}onPropsChange(J){}onChildChanged(J){var VV,RV;(RV=(VV=this.parent)==null?void 0:VV.onChildChanged)==null||RV.call(VV,J)}add(J){J.onAddToParent(this),J.parent=this,this.children.push(J)}addAll(J){for(const VV of J)this.add(VV)}remove(J){this.children=this.children.filter(VV=>VV!==J),this.childrenPendingRemoval.push(J),J.shouldBeRemoved=!0}getSubcircuitSelector(){const J=this._parsedProps.name,VV=J?`${this.lowercaseComponentName}.${J}`:this.lowercaseComponentName;return!this.parent||this.parent.isSubcircuit?VV:`${this.parent.getSubcircuitSelector()} > ${VV}`}getFullPathSelector(){var UV,ZV;const J=this._parsedProps.name,VV=J?`${this.lowercaseComponentName}.${J}`:this.lowercaseComponentName,RV=(ZV=(UV=this.parent)==null?void 0:UV.getFullPathSelector)==null?void 0:ZV.call(UV);return RV?`${RV} > ${VV}`:VV}getNameAndAliases(){return[this._parsedProps.name,...this._parsedProps.portHints??[]].filter(Boolean)}isMatchingNameOrAlias(J){return this.getNameAndAliases().includes(J)}isMatchingAnyOf(J){return this.getNameAndAliases().some(VV=>J.map(RV=>RV.toString()).includes(VV))}getPcbSize(){throw new Error(`getPcbSize not implemented for ${this.componentName}`)}doesSelectorMatch(J){const VV=[this.componentName,this.lowercaseComponentName],RV=[this._parsedProps.name].filter(Boolean),UV=J.trim().split(/\> /)[0],ZV=UV[0];return UV.length>1?!1:!!(J==="*"||J[0]==="#"&&J.slice(1)===this.props.id||J[0]==="."&&RV.includes(J.slice(1))||/^[a-zA-Z0-9_]/.test(ZV)&&VV.includes(ZV))}getSubcircuit(){var VV,RV;if(this.isSubcircuit)return this;const J=(RV=(VV=this.parent)==null?void 0:VV.getSubcircuit)==null?void 0:RV.call(VV);if(!J)throw new Error("Component is not inside an opaque group (no board?)");return J}selectAll(J){debugSelectAll(`selectAll: "${J}"`);const VV=J.trim().split(/\s+/);let RV=VV[0]===">"?this.children:this.getSelectableDescendants(),UV=[],ZV=!1,WV=-1;for(const IV of VV)if(WV++,debugSelectAll(`
|
|
22049
|
+
`).replace(/d 0\./g,"d 1."),nW=QZ.replace(/newmtl[\s\S]*?endmtl/g,""),IZ=new hU.MTLLoader;IZ.setMaterialOptions({invertTrProperty:!0});const MR=IZ.parse(ZW.replace(/Kd\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/g,"Kd $2 $2 $2"),"test.mtl"),WU=new hU.OBJLoader;return WU.setMaterials(MR),WU.parse(nW)}catch(EZ){return EZ}}function yU(){if(ZU.has(ol)){const EZ=ZU.get(ol);return EZ.result?Promise.resolve(EZ.result.clone()):EZ.promise.then(QZ=>QZ.clone())}const XZ=uU().then(EZ=>(EZ instanceof Error||ZU.set(ol,{...ZU.get(ol),result:EZ}),EZ));return ZU.set(ol,{promise:XZ,result:null}),XZ}return yU().then(XZ=>{AU||wR(XZ)}).catch(XZ=>{console.error(XZ)}),()=>{AU=!0}},[ol]),vl}var IU=requireJsxRuntime();function FU({url:ol,position:vl,rotation:wR,onHover:ZU,isHovered:AU}){const uU=GR(ol);return uU?uU instanceof Error?(0,IU.jsx)($R,{isHovered:AU,onHover:ZU,children:(0,IU.jsxs)("mesh",{position:vl,children:[(0,IU.jsx)("boxGeometry",{args:[.5,.5,.5]}),(0,IU.jsx)("meshStandardMaterial",{transparent:!0,color:"red",opacity:.5}),(0,IU.jsx)("meshBasicMaterial",{color:"red"})]})}):(0,IU.jsx)($R,{isHovered:AU,onHover:ZU,children:(0,IU.jsx)("primitive",{rotation:wR,position:vl,object:uU})}):(0,IU.jsx)($R,{isHovered:AU,onHover:ZU,children:(0,IU.jsxs)("mesh",{position:vl,children:[(0,IU.jsx)("boxGeometry",{args:[.5,.5,.5]}),(0,IU.jsx)("meshStandardMaterial",{transparent:!0,color:"red",opacity:.25})]})})}var PU=requireDist$5(),hZ=dV(requireSrc$1()),zZ=requireDist$4(),rZ=dV(requireThree()),DZ=requireReact(),MW=requireJsxRuntime(),fU=({jscadPlan:ol,positionOffset:vl,rotationOffset:wR,onHover:ZU,isHovered:AU})=>{const{threeGeom:uU,material:yU}=(0,DZ.useMemo)(()=>{const XZ=(0,PU.executeJscadOperations)(hZ.default,ol),EZ=(0,zZ.convertCSGToThreeGeom)(XZ),QZ=new rZ.MeshStandardMaterial({vertexColors:!0,side:rZ.DoubleSide});return{threeGeom:EZ,material:QZ}},[ol]);return(0,DZ.useMemo)(()=>{if(AU){const XZ=new rZ.Color(yU.color.getHex());yU.emissive.copy(XZ),yU.emissive.setRGB(0,0,1),yU.emissiveIntensity=.2}else yU.emissiveIntensity=0},[AU,yU]),uU?(0,MW.jsx)($R,{isHovered:AU,onHover:ZU,position:vl,children:(0,MW.jsx)("mesh",{geometry:uU,material:yU,position:vl,rotation:wR})}):null},JW=require$$19,NW=requireDist$4(),cW=requireDist$5(),yW=requireReact(),zW=requireJsxRuntime(),{createJSCADRoot:FZ}=(0,NW.createJSCADRenderer)(cW.jscadPlanner),CW=({positionOffset:ol,footprint:vl,rotationOffset:wR,onHover:ZU,isHovered:AU})=>{const uU=(0,yW.useMemo)(()=>{if(!vl)return null;const yU=[];return FZ(yU).render((0,zW.jsx)(JW.Footprinter3d,{footprint:vl})),yU},[vl]);return uU?(0,zW.jsx)(zW.Fragment,{children:uU.map((yU,XZ)=>(0,zW.jsx)(fU,{positionOffset:ol,rotationOffset:wR,jscadPlan:yU,onHover:ZU,isHovered:AU},XZ))}):null},eW=(...ol)=>ol,TW=requireJsxRuntime(),sW=({cad_component:ol,onHover:vl=()=>{},isHovered:wR=!1})=>{const ZU=ol.model_obj_url??ol.model_stl_url,AU=ol.rotation?eW(ol.rotation.x*Math.PI/180,ol.rotation.y*Math.PI/180,ol.rotation.z*Math.PI/180):void 0;if(ZU)return(0,TW.jsx)(FU,{url:ZU,position:ol.position?[ol.position.x,ol.position.y,ol.position.z]:void 0,rotation:AU,onHover:vl,isHovered:wR},ol.cad_component_id);if(ol.model_jscad)return(0,TW.jsx)(fU,{jscadPlan:ol.model_jscad,rotationOffset:AU,onHover:vl,isHovered:wR},ol.cad_component_id);if(ol.footprinter_string)return(0,TW.jsx)(CW,{positionOffset:ol.position?[ol.position.x,ol.position.y,ol.position.z]:void 0,rotationOffset:AU,footprint:ol.footprinter_string,onHover:vl,isHovered:wR})},lZ=dV(requireReact()),wU=class extends lZ.default.Component{constructor(ol){super(ol),this.state={hasError:!1,error:null}}static getDerivedStateFromError(ol){return{hasError:!0,error:ol}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},LR=require$$14,TU=requireJsxRuntime(),vR=({error:ol,cad_component:vl})=>{let wR=[0,0,0];return vl!=null&&vl.position&&(wR=[vl.position.x,vl.position.y,vl.position.z],wR=wR.map(ZU=>Number.isNaN(ZU)?0:ZU)),(0,TU.jsxs)("group",{position:wR,children:[(0,TU.jsxs)("mesh",{renderOrder:-99999,rotation:[Math.PI/4,Math.PI/4,0],ref:ZU=>{ZU&&(ZU.renderOrder=999999)},children:[(0,TU.jsx)("boxGeometry",{args:[.5,.5,.5]}),(0,TU.jsx)("meshStandardMaterial",{depthTest:!1,transparent:!0,color:"red",opacity:.5})]}),(0,TU.jsxs)(LR.Text,{scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:[ol.toString().slice(0,50),"..."]})]})},DU=requireJsxRuntime(),$U=(0,iV.forwardRef)(({soup:ol,children:vl},wR)=>{const[ZU,AU]=(0,iV.useState)(null);if(ol??(ol=YV(vl)),!ol)return null;const uU=(0,iV.useMemo)(()=>ol.some(QZ=>QZ.type==="pcb_board")?Bl(ol):null,[ol]),{stls:yU,loading:XZ}=Hl(uU),EZ=(0,TV.su)(ol).cad_component.list();return(0,DU.jsxs)(CU,{ref:wR,hoveredComponent:ZU,children:[yU.map(({stlUrl:QZ,color:ZW},nW)=>(0,DU.jsx)(nR,{stlUrl:QZ,color:ZW,opacity:nW===0?.95:1},QZ)),EZ.map(QZ=>(0,DU.jsx)(wU,{fallback:({error:ZW})=>(0,DU.jsx)(vR,{cad_component:QZ,error:ZW}),children:(0,DU.jsx)(sW,{onHover:ZW=>{var IZ;if(ZW||AU(null),!ZW.mousePosition)return;const nW=(IZ=(0,TV.su)(ol).source_component.getUsing({source_component_id:QZ.source_component_id}))==null?void 0:IZ.name;AU({cad_component_id:QZ.cad_component_id,name:nW??"<unknown>",mousePosition:ZW.mousePosition})},cad_component:QZ,isHovered:(ZU==null?void 0:ZU.cad_component_id)===QZ.cad_component_id},QZ.cad_component_id)},QZ.cad_component_id))]})});return dist$4}var distExports$2=requireDist$2(),unitMappings={Hz:{baseUnit:"Hz",variants:{MHz:1e6,kHz:1e3,Hz:1}},g:{baseUnit:"g",variants:{kg:1e3,g:1}},Ω:{baseUnit:"Ω",variants:{mΩ:.001,Ω:1,kΩ:1e3,KΩ:1e3,MΩ:1e6,GΩ:1e9,TΩ:1e12}},V:{baseUnit:"V",variants:{mV:.001,V:1,kV:1e3,KV:1e3,MV:1e6,GV:1e9,TV:1e12}},A:{baseUnit:"A",variants:{µA:1e-6,mA:.001,ma:.001,A:1,kA:1e3,MA:1e6}},F:{baseUnit:"F",variants:{pF:1e-12,nF:1e-9,µF:1e-6,uF:1e-6,mF:.001,F:1}},ml:{baseUnit:"ml",variants:{ml:1,mL:1,l:1e3,L:1e3}},deg:{baseUnit:"deg",variants:{rad:180/Math.PI}},ms:{baseUnit:"ms",variants:{s:1e3}},mm:{baseUnit:"mm",variants:{nm:1e-6,µm:.001,um:.001,mm:1,cm:10,dm:100,m:1e3,km:1e6,in:25.4,ft:304.8,IN:25.4,FT:304.8,yd:914.4,mi:1609344,mil:.0254}}},unitMappingAndVariantSuffixes=new Set;for(const[lV,J]of Object.entries(unitMappings)){unitMappingAndVariantSuffixes.add(lV);for(const VV of Object.keys(J.variants))unitMappingAndVariantSuffixes.add(VV)}function getBaseTscircuitUnit(lV){for(const[J,VV]of Object.entries(unitMappings))if(lV in VV.variants)return{baseUnit:VV.baseUnit,conversionFactor:VV.variants[lV]};return{baseUnit:lV,conversionFactor:1}}var si_prefix_multiplier={tera:1e12,T:1e12,giga:1e9,G:1e9,mega:1e6,M:1e6,kilo:1e3,k:1e3,deci:.1,d:.1,centi:.01,c:.01,milli:.001,m:.001,micro:1e-6,u:1e-6,µ:1e-6,nano:1e-9,n:1e-9,pico:1e-12,p:1e-12},parseAndConvertSiUnit=lV=>{var IV;if(typeof lV>"u")return{parsedUnit:null,unitOfValue:null,value:null};if(typeof lV=="string"&&lV.match(/^[\d\.]+$/))return{value:Number.parseFloat(lV),parsedUnit:null,unitOfValue:null};if(typeof lV=="number")return{value:lV,parsedUnit:null,unitOfValue:null};if(typeof lV=="object"&&"x"in lV&&"y"in lV){const{parsedUnit:dV,unitOfValue:CV}=parseAndConvertSiUnit(lV.x);return{parsedUnit:dV,unitOfValue:CV,value:{x:parseAndConvertSiUnit(lV.x).value,y:parseAndConvertSiUnit(lV.y).value}}}const VV=(IV=lV.toString().split("").reverse().join("").match(/[^\d\s]+/))==null?void 0:IV[0];if(!VV)throw new Error(`Could not determine unit: "${lV}"`);const RV=VV.split("").reverse().join(""),UV=lV.slice(0,-RV.length);if(RV in si_prefix_multiplier&&!unitMappingAndVariantSuffixes.has(RV)){const dV=si_prefix_multiplier[RV];return{parsedUnit:null,unitOfValue:null,value:Number.parseFloat(UV)*dV}}const{baseUnit:ZV,conversionFactor:WV}=getBaseTscircuitUnit(RV);return{parsedUnit:RV,unitOfValue:ZV,value:WV*Number.parseFloat(UV)}},resistance=z$1.string().or(z$1.number()).transform(lV=>parseAndConvertSiUnit(lV).value),capacitance=z$1.string().or(z$1.number()).transform(lV=>parseAndConvertSiUnit(lV).value),inductance=z$1.string().or(z$1.number()).transform(lV=>parseAndConvertSiUnit(lV).value),voltage=z$1.string().or(z$1.number()).transform(lV=>parseAndConvertSiUnit(lV).value),length$1=z$1.string().or(z$1.number()).transform(lV=>parseAndConvertSiUnit(lV).value),frequency=z$1.string().or(z$1.number()).transform(lV=>parseAndConvertSiUnit(lV).value),distance$1=length$1,current=z$1.string().or(z$1.number()).transform(lV=>parseAndConvertSiUnit(lV).value),time=z$1.string().or(z$1.number()).transform(lV=>parseAndConvertSiUnit(lV).value),rotation=z$1.string().or(z$1.number()).transform(lV=>typeof lV=="number"?lV:lV.endsWith("deg")?Number.parseFloat(lV.split("deg")[0]):lV.endsWith("rad")?Number.parseFloat(lV.split("rad")[0])*180/Math.PI:Number.parseFloat(lV)),battery_capacity=z$1.number().or(z$1.string().endsWith("mAh")).transform(lV=>{if(typeof lV=="string"){const J=lV.replace("mAh",""),VV=Number.parseFloat(J);if(Number.isNaN(VV))throw new Error("Invalid capacity");return VV}return lV}).describe("Battery capacity in mAh"),point$1=z$1.object({x:distance$1,y:distance$1}),position$1=point$1,point3$1=z$1.object({x:distance$1,y:distance$1,z:distance$1}),position3=point3$1,size$3=z$1.object({width:z$1.number(),height:z$1.number()}),getZodPrefixedIdWithDefault=lV=>z$1.string().optional().default(()=>`${lV}_${nanoid(10)}`),supplier_name=z$1.enum(["jlcpcb","macrofab","pcbway","digikey","mouser","lcsc"]),source_component_base=z$1.object({type:z$1.literal("source_component"),ftype:z$1.string().optional(),source_component_id:z$1.string(),name:z$1.string(),manufacturer_part_number:z$1.string().optional(),supplier_part_numbers:z$1.record(supplier_name,z$1.array(z$1.string())).optional(),display_value:z$1.string().optional()}),source_simple_capacitor=source_component_base.extend({ftype:z$1.literal("simple_capacitor"),capacitance,display_capacitance:z$1.string().optional(),max_decoupling_trace_length:distance$1.optional()}),source_simple_resistor=source_component_base.extend({ftype:z$1.literal("simple_resistor"),resistance,display_resistance:z$1.string().optional()}),source_simple_diode=source_component_base.extend({ftype:z$1.literal("simple_diode")}),source_simple_ground=source_component_base.extend({ftype:z$1.literal("simple_ground")}),source_simple_bug=source_component_base.extend({ftype:z$1.literal("simple_bug")}).describe("@deprecated"),source_simple_chip=source_component_base.extend({ftype:z$1.literal("simple_chip")}),source_led=source_simple_diode.extend({ftype:z$1.literal("led")}),source_simple_power_source=source_component_base.extend({ftype:z$1.literal("simple_power_source"),voltage}),source_simple_battery=source_component_base.extend({ftype:z$1.literal("simple_battery"),capacity:battery_capacity}),source_simple_inductor=source_component_base.extend({ftype:z$1.literal("simple_inductor"),inductance}),source_simple_push_button=source_component_base.extend({ftype:z$1.literal("simple_push_button")}),source_simple_potentiometer=source_component_base.extend({ftype:z$1.literal("simple_potentiometer"),max_resistance:resistance}),source_simple_crystal=source_component_base.extend({ftype:z$1.literal("simple_crystal"),frequency:z$1.number().describe("Frequency in Hz"),load_capacitance:z$1.number().optional().describe("Load capacitance in pF")}),source_simple_pin_header=source_component_base.extend({ftype:z$1.literal("simple_pin_header"),pin_count:z$1.number(),gender:z$1.enum(["male","female"]).optional().default("male")}),source_simple_resonator=source_component_base.extend({ftype:z$1.literal("simple_resonator"),load_capacitance:capacitance,equivalent_series_resistance:resistance.optional(),frequency}),source_simple_transistor=source_component_base.extend({ftype:z$1.literal("simple_transistor"),transistor_type:z$1.enum(["npn","pnp"])}),source_simple_mosfet=source_component_base.extend({ftype:z$1.literal("simple_mosfet"),channel_type:z$1.enum(["n","p"]),mosfet_mode:z$1.enum(["enhancement","depletion"])}),any_source_component=z$1.union([source_simple_resistor,source_simple_capacitor,source_simple_diode,source_simple_ground,source_simple_chip,source_simple_bug,source_led,source_simple_power_source,source_simple_battery,source_simple_inductor,source_simple_push_button,source_simple_potentiometer,source_simple_crystal,source_simple_pin_header,source_simple_resonator,source_simple_transistor,source_simple_mosfet]),source_port=z$1.object({type:z$1.literal("source_port"),pin_number:z$1.number().optional(),port_hints:z$1.array(z$1.string()).optional(),name:z$1.string(),source_port_id:z$1.string(),source_component_id:z$1.string()}),source_trace=z$1.object({type:z$1.literal("source_trace"),source_trace_id:z$1.string(),connected_source_port_ids:z$1.array(z$1.string()),connected_source_net_ids:z$1.array(z$1.string()),subcircuit_connectivity_map_key:z$1.string().optional(),max_length:z$1.number().optional(),display_name:z$1.string().optional()}),source_group=z$1.object({type:z$1.literal("source_group"),source_group_id:z$1.string(),name:z$1.string().optional()}),source_net=z$1.object({type:z$1.literal("source_net"),source_net_id:z$1.string(),name:z$1.string(),member_source_group_ids:z$1.array(z$1.string()),is_power:z$1.boolean().optional(),is_ground:z$1.boolean().optional(),is_digital_signal:z$1.boolean().optional(),is_analog_signal:z$1.boolean().optional(),trace_width:z$1.number().optional()}),schematic_box=z$1.object({type:z$1.literal("schematic_box"),schematic_component_id:z$1.string(),width:distance$1,height:distance$1,x:distance$1,y:distance$1}).describe("Draws a box on the schematic"),schematic_path=z$1.object({type:z$1.literal("schematic_path"),schematic_component_id:z$1.string(),fill_color:z$1.enum(["red","blue"]).optional(),is_filled:z$1.boolean().optional(),points:z$1.array(point$1)}),schematic_pin_styles=z$1.record(z$1.object({left_margin:length$1.optional(),right_margin:length$1.optional(),top_margin:length$1.optional(),bottom_margin:length$1.optional()})),schematic_component_port_arrangement_by_size=z$1.object({left_size:z$1.number(),right_size:z$1.number(),top_size:z$1.number().optional(),bottom_size:z$1.number().optional()}),schematic_component_port_arrangement_by_sides=z$1.object({left_side:z$1.object({pins:z$1.array(z$1.number()),direction:z$1.enum(["top-to-bottom","bottom-to-top"]).optional()}).optional(),right_side:z$1.object({pins:z$1.array(z$1.number()),direction:z$1.enum(["top-to-bottom","bottom-to-top"]).optional()}).optional(),top_side:z$1.object({pins:z$1.array(z$1.number()),direction:z$1.enum(["left-to-right","right-to-left"]).optional()}).optional(),bottom_side:z$1.object({pins:z$1.array(z$1.number()),direction:z$1.enum(["left-to-right","right-to-left"]).optional()}).optional()}),port_arrangement=z$1.union([schematic_component_port_arrangement_by_size,schematic_component_port_arrangement_by_sides]),schematic_component=z$1.object({type:z$1.literal("schematic_component"),rotation:rotation.default(0),size:size$3,center:point$1,source_component_id:z$1.string(),schematic_component_id:z$1.string(),pin_spacing:length$1.optional(),pin_styles:schematic_pin_styles.optional(),box_width:length$1.optional(),symbol_name:z$1.string().optional(),port_arrangement:port_arrangement.optional(),port_labels:z$1.record(z$1.string()).optional(),symbol_display_value:z$1.string().optional()}),schematic_line=z$1.object({type:z$1.literal("schematic_line"),schematic_component_id:z$1.string(),x1:distance$1,x2:distance$1,y1:distance$1,y2:distance$1}),schematic_trace=z$1.object({type:z$1.literal("schematic_trace"),schematic_trace_id:z$1.string(),source_trace_id:z$1.string(),junctions:z$1.array(z$1.object({x:z$1.number(),y:z$1.number()})),edges:z$1.array(z$1.object({from:z$1.object({x:z$1.number(),y:z$1.number()}),to:z$1.object({x:z$1.number(),y:z$1.number()}),is_crossing:z$1.boolean().optional(),from_schematic_port_id:z$1.string().optional(),to_schematic_port_id:z$1.string().optional()}))}),schematic_text=z$1.object({type:z$1.literal("schematic_text"),schematic_component_id:z$1.string(),schematic_text_id:z$1.string(),text:z$1.string(),position:z$1.object({x:distance$1,y:distance$1}),rotation:z$1.number().default(0),anchor:z$1.enum(["center","left","right","top","bottom"]).default("center"),color:z$1.string().default("#000000")}),schematic_port=z$1.object({type:z$1.literal("schematic_port"),schematic_port_id:z$1.string(),source_port_id:z$1.string(),schematic_component_id:z$1.string().optional(),center:point$1,facing_direction:z$1.enum(["up","down","left","right"]).optional(),distance_from_component_edge:z$1.number().optional(),side_of_component:z$1.enum(["top","bottom","left","right"]).optional(),true_ccw_index:z$1.number().optional(),pin_number:z$1.number().optional(),display_pin_label:z$1.string().optional()}).describe("Defines a port on a schematic component"),schematic_net_label=z$1.object({type:z$1.literal("schematic_net_label"),source_net_id:z$1.string(),center:point$1,anchor_position:point$1.optional(),anchor_side:z$1.enum(["top","bottom","left","right"]),text:z$1.string(),symbol_name:z$1.string().optional()}),schematic_error=z$1.object({type:z$1.literal("schematic_error"),schematic_error_id:z$1.string(),error_type:z$1.literal("schematic_port_not_found"),message:z$1.string()}).describe("Defines a schematic error on the schematic"),schematic_debug_object_base=z$1.object({type:z$1.literal("schematic_debug_object"),label:z$1.string().optional()}),schematic_debug_rect=schematic_debug_object_base.extend({shape:z$1.literal("rect"),center:point$1,size:size$3}),schematic_debug_line=schematic_debug_object_base.extend({shape:z$1.literal("line"),start:point$1,end:point$1}),schematic_debug_point=schematic_debug_object_base.extend({shape:z$1.literal("point"),center:point$1}),schematic_debug_object=z$1.discriminatedUnion("shape",[schematic_debug_rect,schematic_debug_line,schematic_debug_point]),schematic_voltage_probe=z$1.object({type:z$1.literal("schematic_voltage_probe"),schematic_voltage_probe_id:z$1.string(),position:point$1,schematic_trace_id:z$1.string(),voltage:voltage.optional()}).describe("Defines a voltage probe measurement point on a schematic trace"),all_layers=["top","bottom","inner1","inner2","inner3","inner4","inner5","inner6"],layer_string=z$1.enum(all_layers),layer_ref=layer_string.or(z$1.object({name:layer_string})).transform(lV=>typeof lV=="string"?lV:lV.name),visible_layer=z$1.enum(["top","bottom"]),pcb_route_hint=z$1.object({x:distance$1,y:distance$1,via:z$1.boolean().optional(),via_to_layer:layer_ref.optional()}),pcb_route_hints=z$1.array(pcb_route_hint),route_hint_point=z$1.object({x:distance$1,y:distance$1,via:z$1.boolean().optional(),to_layer:layer_ref.optional(),trace_width:distance$1.optional()}),pcb_component=z$1.object({type:z$1.literal("pcb_component"),pcb_component_id:getZodPrefixedIdWithDefault("pcb_component"),source_component_id:z$1.string(),center:point$1,layer:layer_ref,rotation,width:length$1,height:length$1}).describe("Defines a component on the PCB"),pcb_hole_circle_or_square=z$1.object({type:z$1.literal("pcb_hole"),pcb_hole_id:getZodPrefixedIdWithDefault("pcb_hole"),hole_shape:z$1.enum(["circle","square"]),hole_diameter:z$1.number(),x:distance$1,y:distance$1}),pcb_hole_circle_or_square_shape=pcb_hole_circle_or_square.describe("Defines a circular or square hole on the PCB"),pcb_hole_oval=z$1.object({type:z$1.literal("pcb_hole"),pcb_hole_id:getZodPrefixedIdWithDefault("pcb_hole"),hole_shape:z$1.literal("oval"),hole_width:z$1.number(),hole_height:z$1.number(),x:distance$1,y:distance$1}),pcb_hole_oval_shape=pcb_hole_oval.describe("Defines an oval hole on the PCB"),pcb_hole=pcb_hole_circle_or_square.or(pcb_hole_oval),pcb_plated_hole_circle=z$1.object({type:z$1.literal("pcb_plated_hole"),shape:z$1.literal("circle"),outer_diameter:z$1.number(),hole_diameter:z$1.number(),x:distance$1,y:distance$1,layers:z$1.array(layer_ref),port_hints:z$1.array(z$1.string()).optional(),pcb_component_id:z$1.string().optional(),pcb_port_id:z$1.string().optional(),pcb_plated_hole_id:getZodPrefixedIdWithDefault("pcb_plated_hole")}),pcb_plated_hole_oval=z$1.object({type:z$1.literal("pcb_plated_hole"),shape:z$1.enum(["oval","pill"]),outer_width:z$1.number(),outer_height:z$1.number(),hole_width:z$1.number(),hole_height:z$1.number(),x:distance$1,y:distance$1,layers:z$1.array(layer_ref),port_hints:z$1.array(z$1.string()).optional(),pcb_component_id:z$1.string().optional(),pcb_port_id:z$1.string().optional(),pcb_plated_hole_id:getZodPrefixedIdWithDefault("pcb_plated_hole")}),pcb_circular_hole_with_rect_pad=z$1.object({type:z$1.literal("pcb_plated_hole"),shape:z$1.literal("circular_hole_with_rect_pad"),hole_shape:z$1.literal("circle"),pad_shape:z$1.literal("rect"),hole_diameter:z$1.number(),rect_pad_width:z$1.number(),rect_pad_height:z$1.number(),x:distance$1,y:distance$1,layers:z$1.array(layer_ref),port_hints:z$1.array(z$1.string()).optional(),pcb_component_id:z$1.string().optional(),pcb_port_id:z$1.string().optional(),pcb_plated_hole_id:getZodPrefixedIdWithDefault("pcb_plated_hole")}),pcb_plated_hole=z$1.union([pcb_plated_hole_circle,pcb_plated_hole_oval,pcb_circular_hole_with_rect_pad]),pcb_port=z$1.object({type:z$1.literal("pcb_port"),pcb_port_id:getZodPrefixedIdWithDefault("pcb_port"),source_port_id:z$1.string(),pcb_component_id:z$1.string(),x:distance$1,y:distance$1,layers:z$1.array(layer_ref)}).describe("Defines a port on the PCB"),pcb_smtpad_circle=z$1.object({type:z$1.literal("pcb_smtpad"),shape:z$1.literal("circle"),pcb_smtpad_id:getZodPrefixedIdWithDefault("pcb_smtpad"),x:distance$1,y:distance$1,radius:z$1.number(),layer:layer_ref,port_hints:z$1.array(z$1.string()).optional(),pcb_component_id:z$1.string().optional(),pcb_port_id:z$1.string().optional()}),pcb_smtpad_rect=z$1.object({type:z$1.literal("pcb_smtpad"),shape:z$1.literal("rect"),pcb_smtpad_id:getZodPrefixedIdWithDefault("pcb_smtpad"),x:distance$1,y:distance$1,width:z$1.number(),height:z$1.number(),layer:layer_ref,port_hints:z$1.array(z$1.string()).optional(),pcb_component_id:z$1.string().optional(),pcb_port_id:z$1.string().optional()}),pcb_smtpad_rotated_rect=z$1.object({type:z$1.literal("pcb_smtpad"),shape:z$1.literal("rotated_rect"),pcb_smtpad_id:getZodPrefixedIdWithDefault("pcb_smtpad"),x:distance$1,y:distance$1,width:z$1.number(),height:z$1.number(),ccw_rotation:rotation,layer:layer_ref,port_hints:z$1.array(z$1.string()).optional(),pcb_component_id:z$1.string().optional(),pcb_port_id:z$1.string().optional()}),pcb_smtpad=z$1.union([pcb_smtpad_circle,pcb_smtpad_rect,pcb_smtpad_rotated_rect]).describe("Defines an SMT pad on the PCB"),pcb_solder_paste_circle=z$1.object({type:z$1.literal("pcb_solder_paste"),shape:z$1.literal("circle"),pcb_solder_paste_id:getZodPrefixedIdWithDefault("pcb_solder_paste"),x:distance$1,y:distance$1,radius:z$1.number(),layer:layer_ref,pcb_component_id:z$1.string().optional(),pcb_smtpad_id:z$1.string().optional()}),pcb_solder_paste_rect=z$1.object({type:z$1.literal("pcb_solder_paste"),shape:z$1.literal("rect"),pcb_solder_paste_id:getZodPrefixedIdWithDefault("pcb_solder_paste"),x:distance$1,y:distance$1,width:z$1.number(),height:z$1.number(),layer:layer_ref,pcb_component_id:z$1.string().optional(),pcb_smtpad_id:z$1.string().optional()}),pcb_solder_paste=z$1.union([pcb_solder_paste_circle,pcb_solder_paste_rect]).describe("Defines solderpaste on the PCB"),pcb_text=z$1.object({type:z$1.literal("pcb_text"),pcb_text_id:getZodPrefixedIdWithDefault("pcb_text"),text:z$1.string(),center:point$1,layer:layer_ref,width:length$1,height:length$1,lines:z$1.number(),align:z$1.enum(["bottom-left"])}).describe("Defines text on the PCB"),pcb_trace_route_point_wire=z$1.object({route_type:z$1.literal("wire"),x:distance$1,y:distance$1,width:distance$1,start_pcb_port_id:z$1.string().optional(),end_pcb_port_id:z$1.string().optional(),layer:layer_ref}),pcb_trace_route_point_via=z$1.object({route_type:z$1.literal("via"),x:distance$1,y:distance$1,from_layer:z$1.string(),to_layer:z$1.string()}),pcb_trace_route_point=z$1.union([pcb_trace_route_point_wire,pcb_trace_route_point_via]),pcb_trace=z$1.object({type:z$1.literal("pcb_trace"),source_trace_id:z$1.string().optional(),pcb_component_id:z$1.string().optional(),pcb_trace_id:getZodPrefixedIdWithDefault("pcb_trace"),route_thickness_mode:z$1.enum(["constant","interpolated"]).default("constant").optional(),route_order_index:z$1.number().optional(),should_round_corners:z$1.boolean().optional(),trace_length:z$1.number().optional(),route:z$1.array(z$1.union([z$1.object({route_type:z$1.literal("wire"),x:distance$1,y:distance$1,width:distance$1,start_pcb_port_id:z$1.string().optional(),end_pcb_port_id:z$1.string().optional(),layer:layer_ref}),z$1.object({route_type:z$1.literal("via"),x:distance$1,y:distance$1,from_layer:z$1.string(),to_layer:z$1.string()})]))}).describe("Defines a trace on the PCB"),pcb_trace_error=z$1.object({type:z$1.literal("pcb_trace_error"),pcb_trace_error_id:getZodPrefixedIdWithDefault("pcb_trace_error"),error_type:z$1.literal("pcb_trace_error"),message:z$1.string(),center:point$1.optional(),pcb_trace_id:z$1.string(),source_trace_id:z$1.string(),pcb_component_ids:z$1.array(z$1.string()),pcb_port_ids:z$1.array(z$1.string())}).describe("Defines a trace error on the PCB"),pcb_port_not_matched_error=z$1.object({type:z$1.literal("pcb_port_not_matched_error"),pcb_error_id:getZodPrefixedIdWithDefault("pcb_error"),message:z$1.string(),pcb_component_ids:z$1.array(z$1.string())}).describe("Defines a trace error on the PCB where a port is not matched"),pcb_via=z$1.object({type:z$1.literal("pcb_via"),pcb_via_id:getZodPrefixedIdWithDefault("pcb_via"),x:distance$1,y:distance$1,outer_diameter:distance$1.default("0.6mm"),hole_diameter:distance$1.default("0.25mm"),from_layer:layer_ref.optional(),to_layer:layer_ref.optional(),layers:z$1.array(layer_ref),pcb_trace_id:z$1.string().optional()}).describe("Defines a via on the PCB"),pcb_board=z$1.object({type:z$1.literal("pcb_board"),pcb_board_id:getZodPrefixedIdWithDefault("pcb_board"),width:length$1,height:length$1,center:point$1,thickness:length$1.optional().default(1.4),num_layers:z$1.number().optional().default(4),outline:z$1.array(point$1).optional()}).describe("Defines the board outline of the PCB"),pcb_placement_error=z$1.object({type:z$1.literal("pcb_placement_error"),pcb_placement_error_id:getZodPrefixedIdWithDefault("pcb_placement_error"),message:z$1.string()}).describe("Defines a placement error on the PCB"),pcb_trace_hint=z$1.object({type:z$1.literal("pcb_trace_hint"),pcb_trace_hint_id:getZodPrefixedIdWithDefault("pcb_trace_hint"),pcb_port_id:z$1.string(),pcb_component_id:z$1.string(),route:z$1.array(route_hint_point)}).describe("A hint that can be used during generation of a PCB trace"),pcb_silkscreen_line=z$1.object({type:z$1.literal("pcb_silkscreen_line"),pcb_silkscreen_line_id:getZodPrefixedIdWithDefault("pcb_silkscreen_line"),pcb_component_id:z$1.string(),stroke_width:distance$1.default("0.1mm"),x1:distance$1,y1:distance$1,x2:distance$1,y2:distance$1,layer:visible_layer}).describe("Defines a silkscreen line on the PCB"),pcb_silkscreen_path=z$1.object({type:z$1.literal("pcb_silkscreen_path"),pcb_silkscreen_path_id:getZodPrefixedIdWithDefault("pcb_silkscreen_path"),pcb_component_id:z$1.string(),layer:visible_layer,route:z$1.array(point$1),stroke_width:length$1}).describe("Defines a silkscreen path on the PCB"),pcb_silkscreen_text=z$1.object({type:z$1.literal("pcb_silkscreen_text"),pcb_silkscreen_text_id:getZodPrefixedIdWithDefault("pcb_silkscreen_text"),font:z$1.literal("tscircuit2024").default("tscircuit2024"),font_size:distance$1.default("0.2mm"),pcb_component_id:z$1.string(),text:z$1.string(),ccw_rotation:z$1.number().optional(),layer:layer_ref,is_mirrored:z$1.boolean().default(!1).optional(),anchor_position:point$1.default({x:0,y:0}),anchor_alignment:z$1.enum(["center","top_left","top_right","bottom_left","bottom_right"]).default("center")}).describe("Defines silkscreen text on the PCB"),pcb_silkscreen_rect=z$1.object({type:z$1.literal("pcb_silkscreen_rect"),pcb_silkscreen_rect_id:getZodPrefixedIdWithDefault("pcb_silkscreen_rect"),pcb_component_id:z$1.string(),center:point$1,width:length$1,height:length$1,layer:layer_ref}).describe("Defines a silkscreen rect on the PCB"),pcb_silkscreen_circle=z$1.object({type:z$1.literal("pcb_silkscreen_circle"),pcb_silkscreen_circle_id:getZodPrefixedIdWithDefault("pcb_silkscreen_circle"),pcb_component_id:z$1.string(),center:point$1,radius:length$1,layer:visible_layer}).describe("Defines a silkscreen circle on the PCB"),pcb_silkscreen_oval=z$1.object({type:z$1.literal("pcb_silkscreen_oval"),pcb_silkscreen_oval_id:getZodPrefixedIdWithDefault("pcb_silkscreen_oval"),pcb_component_id:z$1.string(),center:point$1,radius_x:distance$1,radius_y:distance$1,layer:visible_layer}).describe("Defines a silkscreen oval on the PCB"),pcb_fabrication_note_text=z$1.object({type:z$1.literal("pcb_fabrication_note_text"),pcb_fabrication_note_text_id:getZodPrefixedIdWithDefault("pcb_fabrication_note_text"),font:z$1.literal("tscircuit2024").default("tscircuit2024"),font_size:distance$1.default("1mm"),pcb_component_id:z$1.string(),text:z$1.string(),layer:visible_layer,anchor_position:point$1.default({x:0,y:0}),anchor_alignment:z$1.enum(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),color:z$1.string().optional()}).describe("Defines a fabrication note in text on the PCB, useful for leaving notes for assemblers or fabricators"),pcb_fabrication_note_path=z$1.object({type:z$1.literal("pcb_fabrication_note_path"),pcb_fabrication_note_path_id:getZodPrefixedIdWithDefault("pcb_fabrication_note_path"),pcb_component_id:z$1.string(),layer:layer_ref,route:z$1.array(point$1),stroke_width:length$1,color:z$1.string().optional()}).describe("Defines a fabrication path on the PCB for fabricators or assemblers"),pcb_keepout=z$1.object({type:z$1.literal("pcb_keepout"),shape:z$1.literal("rect"),center:point$1,width:distance$1,height:distance$1,pcb_keepout_id:z$1.string(),layers:z$1.array(z$1.string()),description:z$1.string().optional()}).or(z$1.object({type:z$1.literal("pcb_keepout"),shape:z$1.literal("circle"),center:point$1,radius:distance$1,pcb_keepout_id:z$1.string(),layers:z$1.array(z$1.string()),description:z$1.string().optional()})),pcb_missing_footprint_error=z$1.object({type:z$1.literal("pcb_missing_footprint_error"),pcb_missing_footprint_error_id:getZodPrefixedIdWithDefault("pcb_missing_footprint_error"),error_type:z$1.literal("pcb_missing_footprint_error"),source_component_id:z$1.string(),message:z$1.string()}).describe("Defines a missing footprint error on the PCB"),pcb_manual_edit_conflict_error=z$1.object({type:z$1.literal("pcb_manual_edit_conflict_error"),pcb_error_id:getZodPrefixedIdWithDefault("pcb_manual_edit_conflict_error"),message:z$1.string(),pcb_component_id:z$1.string(),source_component_id:z$1.string()}).describe("Error emitted when a component has both manual placement and explicit pcbX/pcbY coordinates"),pcb_group=z$1.object({type:z$1.literal("pcb_group"),pcb_group_id:getZodPrefixedIdWithDefault("pcb_group"),width:length$1,height:length$1,center:point$1,pcb_component_ids:z$1.array(z$1.string()),name:z$1.string().optional(),description:z$1.string().optional()}).describe("Defines a group of components on the PCB"),cad_component=z$1.object({type:z$1.literal("cad_component"),cad_component_id:z$1.string(),pcb_component_id:z$1.string(),source_component_id:z$1.string(),position:point3$1,rotation:point3$1.optional(),size:point3$1.optional(),layer:layer_ref.optional(),footprinter_string:z$1.string().optional(),model_obj_url:z$1.string().optional(),model_stl_url:z$1.string().optional(),model_3mf_url:z$1.string().optional(),model_jscad:z$1.any().optional()}).describe("Defines a component on the PCB"),any_circuit_element=z$1.union([source_trace,source_port,any_source_component,source_led,source_net,source_group,source_simple_bug,source_simple_chip,source_simple_capacitor,source_simple_diode,source_simple_resistor,source_simple_power_source,source_simple_battery,source_simple_inductor,source_simple_pin_header,source_simple_resonator,source_simple_transistor,source_simple_mosfet,source_simple_potentiometer,source_simple_push_button,pcb_component,pcb_hole,pcb_missing_footprint_error,pcb_manual_edit_conflict_error,pcb_plated_hole,pcb_keepout,pcb_port,pcb_text,pcb_trace,pcb_via,pcb_smtpad,pcb_solder_paste,pcb_board,pcb_group,pcb_trace_hint,pcb_silkscreen_line,pcb_silkscreen_path,pcb_silkscreen_text,pcb_silkscreen_rect,pcb_silkscreen_circle,pcb_silkscreen_oval,pcb_trace_error,pcb_placement_error,pcb_port_not_matched_error,pcb_fabrication_note_path,pcb_fabrication_note_text,schematic_box,schematic_text,schematic_line,schematic_component,schematic_port,schematic_trace,schematic_path,schematic_error,schematic_net_label,schematic_debug_object,schematic_voltage_probe,cad_component]),any_soup_element=any_circuit_element;const Soup=Object.freeze(Object.defineProperty({__proto__:null,all_layers,any_circuit_element,any_soup_element,any_source_component,battery_capacity,cad_component,capacitance,current,distance:distance$1,frequency,getZodPrefixedIdWithDefault,inductance,layer_ref,layer_string,length:length$1,pcb_board,pcb_component,pcb_fabrication_note_path,pcb_fabrication_note_text,pcb_group,pcb_hole,pcb_hole_circle_or_square_shape,pcb_hole_oval_shape,pcb_keepout,pcb_manual_edit_conflict_error,pcb_missing_footprint_error,pcb_placement_error,pcb_plated_hole,pcb_port,pcb_port_not_matched_error,pcb_route_hint,pcb_route_hints,pcb_silkscreen_circle,pcb_silkscreen_line,pcb_silkscreen_oval,pcb_silkscreen_path,pcb_silkscreen_rect,pcb_silkscreen_text,pcb_smtpad,pcb_solder_paste,pcb_text,pcb_trace,pcb_trace_error,pcb_trace_hint,pcb_trace_route_point,pcb_trace_route_point_via,pcb_trace_route_point_wire,pcb_via,point:point$1,point3:point3$1,port_arrangement,position:position$1,position3,resistance,rotation,route_hint_point,schematic_box,schematic_component,schematic_component_port_arrangement_by_sides,schematic_component_port_arrangement_by_size,schematic_debug_line,schematic_debug_object,schematic_debug_object_base,schematic_debug_point,schematic_debug_rect,schematic_error,schematic_line,schematic_net_label,schematic_path,schematic_pin_styles,schematic_port,schematic_text,schematic_trace,schematic_voltage_probe,size:size$3,source_component_base,source_group,source_led,source_net,source_port,source_simple_battery,source_simple_bug,source_simple_capacitor,source_simple_chip,source_simple_crystal,source_simple_diode,source_simple_ground,source_simple_inductor,source_simple_mosfet,source_simple_pin_header,source_simple_potentiometer,source_simple_power_source,source_simple_push_button,source_simple_resistor,source_simple_resonator,source_simple_transistor,source_trace,supplier_name,time,visible_layer,voltage},Symbol.toStringTag,{value:"Module"}));var direction=z$1.enum(["up","down","left","right"]);z$1.enum(["top-to-bottom","left-to-right","bottom-to-top","right-to-left"]);var portHints=z$1.array(z$1.string().or(z$1.number())),point3=z$1.object({x:distance$6,y:distance$6,z:distance$6}),rotationPoint3=z$1.object({x:z$1.union([z$1.number(),z$1.string()]),y:z$1.union([z$1.number(),z$1.string()]),z:z$1.union([z$1.number(),z$1.string()])}),cadModelBase=z$1.object({rotationOffset:z$1.number().or(rotationPoint3).optional(),positionOffset:point3.optional(),size:point3.optional()}),cadModelStl=cadModelBase.extend({stlUrl:z$1.string()}),cadModelObj=cadModelBase.extend({objUrl:z$1.string(),mtlUrl:z$1.string().optional()}),cadModelJscad=cadModelBase.extend({jscad:z$1.record(z$1.any())}),cadModelProp=z$1.union([z$1.string(),cadModelStl,cadModelObj,cadModelJscad]),footprintProp=z$1.custom(lV=>!0),pcbLayoutProps=z$1.object({pcbX:distance$6.optional(),pcbY:distance$6.optional(),pcbRotation:rotation$5.optional(),layer:layer_ref$3.optional()}),commonLayoutProps=z$1.object({pcbX:distance$6.optional(),pcbY:distance$6.optional(),pcbRotation:rotation$5.optional(),schX:distance$6.optional(),schY:distance$6.optional(),schRotation:rotation$5.optional(),layer:layer_ref$3.optional(),footprint:footprintProp.optional()}),supplierProps=z$1.object({supplierPartNumbers:z$1.record(supplier_name$3,z$1.array(z$1.string())).optional()}),commonComponentProps=commonLayoutProps.merge(supplierProps).extend({key:z$1.any().optional(),name:z$1.string(),cadModel:cadModelProp.optional(),children:z$1.any().optional(),symbolName:z$1.string().optional()}),lrPins=["pin1","left","pin2","right"],lrPolarPins=["pin1","left","anode","pos","pin2","right","cathode","neg"];distance$6.or(z$1.enum(["2x","3x","4x"]));var explicitPinSideDefinition=z$1.object({pins:z$1.array(z$1.union([z$1.number(),z$1.string()])),direction:z$1.union([z$1.literal("top-to-bottom"),z$1.literal("left-to-right"),z$1.literal("bottom-to-top"),z$1.literal("right-to-left")])}),schematicPortArrangement=z$1.object({leftSize:z$1.number().optional().describe("@deprecated, use leftPinCount"),topSize:z$1.number().optional().describe("@deprecated, use topPinCount"),rightSize:z$1.number().optional().describe("@deprecated, use rightPinCount"),bottomSize:z$1.number().optional().describe("@deprecated, use bottomPinCount"),leftPinCount:z$1.number().optional(),rightPinCount:z$1.number().optional(),topPinCount:z$1.number().optional(),bottomPinCount:z$1.number().optional(),leftSide:explicitPinSideDefinition.optional(),rightSide:explicitPinSideDefinition.optional(),topSide:explicitPinSideDefinition.optional(),bottomSide:explicitPinSideDefinition.optional()}),schematicPinStyle=z$1.record(z$1.object({leftMargin:distance$6.optional(),rightMargin:distance$6.optional(),topMargin:distance$6.optional(),bottomMargin:distance$6.optional()})),point=z$1.object({x:distance$6,y:distance$6}),base_manual_edit_event=z$1.object({edit_event_id:z$1.string(),in_progress:z$1.boolean().optional(),created_at:z$1.number()}),edit_pcb_component_location_event=base_manual_edit_event.extend({pcb_edit_event_type:z$1.literal("edit_component_location").describe("deprecated"),edit_event_type:z$1.literal("edit_pcb_component_location"),pcb_component_id:z$1.string(),original_center:z$1.object({x:z$1.number(),y:z$1.number()}),new_center:z$1.object({x:z$1.number(),y:z$1.number()})}),edit_trace_hint_event=base_manual_edit_event.extend({pcb_edit_event_type:z$1.literal("edit_trace_hint").describe("deprecated"),edit_event_type:z$1.literal("edit_pcb_trace_hint").optional(),pcb_port_id:z$1.string(),pcb_trace_hint_id:z$1.string().optional(),route:z$1.array(z$1.object({x:z$1.number(),y:z$1.number(),via:z$1.boolean().optional()}))}),edit_schematic_component_location_event=base_manual_edit_event.extend({edit_event_type:z$1.literal("edit_schematic_component_location"),schematic_component_id:z$1.string(),original_center:z$1.object({x:z$1.number(),y:z$1.number()}),new_center:z$1.object({x:z$1.number(),y:z$1.number()})});z$1.union([edit_pcb_component_location_event,edit_trace_hint_event,edit_schematic_component_location_event]);var manual_pcb_placement=z$1.object({selector:z$1.string(),relative_to:z$1.string().optional().default("group_center").describe("Can be a selector or 'group_center'"),center:point$5}),manual_trace_hint=z$1.object({pcb_port_selector:z$1.string(),offsets:z$1.array(route_hint_point$3)}),manual_schematic_placement=z$1.object({selector:z$1.string(),relative_to:z$1.string().optional().default("group_center").describe("Can be a selector or 'group_center'"),center:point$5}),manual_edits_file=z$1.object({pcb_placements:z$1.array(manual_pcb_placement).optional(),manual_trace_hints:z$1.array(manual_trace_hint).optional(),schematic_placements:z$1.array(manual_schematic_placement).optional()}),autorouterConfig=z$1.object({serverUrl:z$1.string().optional(),inputFormat:z$1.enum(["simplified","circuit-json"]).optional(),serverMode:z$1.enum(["job","solve-endpoint"]).optional(),cache:z$1.custom(lV=>!0).optional()}),autorouterProp=z$1.union([autorouterConfig,z$1.literal("sequential-trace"),z$1.literal("subcircuit"),z$1.literal("auto"),z$1.literal("auto-local"),z$1.literal("auto-cloud")]),baseGroupProps=commonLayoutProps.extend({name:z$1.string().optional(),children:z$1.any().optional()}),subcircuitGroupProps=baseGroupProps.extend({layout:z$1.custom(lV=>!0).optional(),manualEdits:manual_edits_file.optional(),schAutoLayoutEnabled:z$1.boolean().optional(),routingDisabled:z$1.boolean().optional(),defaultTraceWidth:length$5.optional(),minTraceWidth:length$5.optional(),partsEngine:z$1.custom(lV=>"findPart"in lV).optional(),pcbRouteCache:z$1.custom(lV=>!0).optional(),autorouter:autorouterProp.optional()}),subcircuitGroupPropsWithBool=subcircuitGroupProps.extend({subcircuit:z$1.literal(!0)}),groupProps=z$1.discriminatedUnion("subcircuit",[baseGroupProps.extend({subcircuit:z$1.literal(!1).optional()}),subcircuitGroupPropsWithBool]),boardProps=subcircuitGroupProps.extend({width:distance$6.optional(),height:distance$6.optional(),outline:z$1.array(point).optional(),outlineOffsetX:distance$6.optional(),outlineOffsetY:distance$6.optional()});z$1.record(z$1.number().or(z$1.string()),z$1.string().or(z$1.array(z$1.string()).readonly()).or(z$1.array(z$1.string())));var chipProps=commonComponentProps.extend({manufacturerPartNumber:z$1.string().optional(),pinLabels:z$1.record(z$1.number().or(z$1.string()),z$1.string().or(z$1.array(z$1.string()).readonly())).optional(),schPortArrangement:schematicPortArrangement.optional(),schPinStyle:schematicPinStyle.optional(),schPinSpacing:distance$6.optional(),schWidth:distance$6.optional(),schHeight:distance$6.optional(),noSchematicRepresentation:z$1.boolean().optional()}),jumperProps=commonComponentProps.extend({manufacturerPartNumber:z$1.string().optional(),pinLabels:z$1.record(z$1.number().or(z$1.string()),z$1.string().or(z$1.array(z$1.string()))).optional(),schPinStyle:schematicPinStyle.optional(),schPinSpacing:distance$6.optional(),schWidth:distance$6.optional(),schHeight:distance$6.optional(),schDirection:z$1.enum(["left","right"]).optional(),schPortArrangement:schematicPortArrangement.optional()}),platedHoleProps=z$1.discriminatedUnion("shape",[pcbLayoutProps.omit({pcbRotation:!0,layer:!0}).extend({name:z$1.string().optional(),shape:z$1.literal("circle"),holeDiameter:distance$6,outerDiameter:distance$6,portHints:portHints.optional()}),pcbLayoutProps.omit({pcbRotation:!0,layer:!0}).extend({name:z$1.string().optional(),shape:z$1.literal("oval"),outerWidth:distance$6,outerHeight:distance$6,innerWidth:distance$6,innerHeight:distance$6,portHints:portHints.optional()}),pcbLayoutProps.omit({pcbRotation:!0,layer:!0}).extend({name:z$1.string().optional(),shape:z$1.literal("pill"),outerWidth:distance$6,outerHeight:distance$6,innerWidth:distance$6,innerHeight:distance$6,portHints:portHints.optional()})]),resistorProps=commonComponentProps.extend({resistance:resistance$3,pullupFor:z$1.string().optional(),pullupTo:z$1.string().optional(),pulldownFor:z$1.string().optional(),pulldownTo:z$1.string().optional()}),resistorPins=lrPins,potentiometerProps=commonComponentProps.extend({maxResistance:resistance$3}),crystalProps=commonComponentProps.extend({frequency:frequency$2,loadCapacitance:capacitance$3,pinVariant:z$1.enum(["2pin","4pin"]).optional()}),resonatorProps=commonComponentProps.extend({frequency:frequency$2,loadCapacitance:capacitance$3,pinVariant:z$1.enum(["no_ground","ground_pin","two_ground_pins"]).optional()}),capacitorProps=commonComponentProps.extend({capacitance:capacitance$3,polarized:z$1.boolean().optional().default(!1),decouplingFor:z$1.string().optional(),decouplingTo:z$1.string().optional(),bypassFor:z$1.string().optional(),bypassTo:z$1.string().optional(),maxDecouplingTraceLength:z$1.number().optional()}),capacitorPins=lrPolarPins;z$1.object({name:z$1.string()}),z$1.object({name:z$1.string().optional(),pcbOnly:z$1.boolean().optional(),schOnly:z$1.boolean().optional()});var pcbXDistConstraintProps=z$1.object({pcb:z$1.literal(!0).optional(),xDist:distance$6,left:z$1.string(),right:z$1.string(),edgeToEdge:z$1.literal(!0).optional(),centerToCenter:z$1.literal(!0).optional()}),pcbYDistConstraintProps=z$1.object({pcb:z$1.literal(!0).optional(),yDist:distance$6,top:z$1.string(),bottom:z$1.string(),edgeToEdge:z$1.literal(!0).optional(),centerToCenter:z$1.literal(!0).optional()}),pcbSameYConstraintProps=z$1.object({pcb:z$1.literal(!0).optional(),sameY:z$1.literal(!0).optional(),for:z$1.array(z$1.string())}),pcbSameXConstraintProps=z$1.object({pcb:z$1.literal(!0).optional(),sameX:z$1.literal(!0).optional(),for:z$1.array(z$1.string())}),constraintProps=z$1.union([pcbXDistConstraintProps,pcbYDistConstraintProps,pcbSameYConstraintProps,pcbSameXConstraintProps]),rectSmtPadProps=pcbLayoutProps.omit({pcbRotation:!0}).extend({shape:z$1.literal("rect"),width:distance$6,height:distance$6,portHints:portHints.optional()}),rotatedRectSmtPadProps=pcbLayoutProps.omit({pcbRotation:!0}).extend({shape:z$1.literal("rotated_rect"),width:distance$6,height:distance$6,ccwRotation:z$1.number(),portHints:portHints.optional()}),circleSmtPadProps=pcbLayoutProps.omit({pcbRotation:!0}).extend({shape:z$1.literal("circle"),radius:distance$6,portHints:portHints.optional()}),smtPadProps=z$1.union([circleSmtPadProps,rectSmtPadProps,rotatedRectSmtPadProps]),rectSolderPasteProps=pcbLayoutProps.omit({pcbRotation:!0}).extend({shape:z$1.literal("rect"),width:distance$6,height:distance$6}),circleSolderPasteProps=pcbLayoutProps.omit({pcbRotation:!0}).extend({shape:z$1.literal("circle"),radius:distance$6});z$1.union([circleSolderPasteProps,rectSolderPasteProps]);var holeProps=pcbLayoutProps.omit({pcbRotation:!0}).extend({name:z$1.string().optional(),diameter:distance$6.optional(),radius:distance$6.optional()}).transform(lV=>({...lV,diameter:lV.diameter??2*lV.radius,radius:lV.radius??lV.diameter/2})),portRef=z$1.union([z$1.string(),z$1.custom(lV=>!!lV.getPortSelector)]),baseTraceProps=z$1.object({key:z$1.string().optional(),thickness:distance$6.optional(),schematicRouteHints:z$1.array(point).optional(),pcbRouteHints:z$1.array(route_hint_point$3).optional(),schDisplayLabel:z$1.string().optional(),maxLength:z$1.number().optional()}),traceProps=z$1.union([baseTraceProps.extend({path:z$1.array(portRef)}),baseTraceProps.extend({from:portRef,to:portRef})]),footprintProps=z$1.object({originalLayer:layer_ref$3.default("top").optional()}),capacity=z$1.number().or(z$1.string().endsWith("mAh")).transform(lV=>{if(typeof lV=="string"){const J=lV.replace("mAh",""),VV=Number.parseFloat(J);if(Number.isNaN(VV))throw new Error("Invalid capacity");return VV}return lV}).describe("Battery capacity in mAh"),batteryProps=commonComponentProps.extend({capacity:capacity.optional()}),pinHeaderProps=commonComponentProps.extend({pinCount:z$1.number(),pitch:distance$6.optional(),gender:z$1.enum(["male","female"]).optional().default("male"),showSilkscreenPinLabels:z$1.boolean().optional(),doubleRow:z$1.boolean().optional(),holeDiameter:distance$6.optional(),platedDiameter:distance$6.optional(),pinLabels:z$1.array(z$1.string()).optional(),facingDirection:z$1.enum(["left","right"]).optional()}),netAliasProps=z$1.object({net:z$1.string().optional(),schX:distance$6.optional(),schY:distance$6.optional(),schRotation:rotation$5.optional(),anchorSide:z$1.enum(["left","up","right","down"]).optional()}),pushButtonProps=commonComponentProps.extend({}),transistorProps=commonComponentProps.extend({transistorType:z$1.enum(["npn","pnp"])}),mosfetProps=commonComponentProps.extend({channelType:z$1.enum(["n","p"]),mosfetMode:z$1.enum(["enhancement","depletion"])}),inductorProps=commonComponentProps.extend({inductance:inductance$3}),diodeProps=commonComponentProps.extend({}),diodePins=lrPolarPins,ledProps=commonComponentProps.extend({color:z$1.string().optional()}),ledPins=lrPolarPins;commonComponentProps.extend({ftype:z$1.literal("switch"),switchType:z$1.enum(["spst"]).default("spst"),isNormallyClosed:z$1.boolean().default(!1)}),distance$6.or(z$1.enum(["2x","3x","4x"]));var viaProps=commonLayoutProps.extend({fromLayer:layer_ref$3,toLayer:layer_ref$3,holeDiameter:distance$6,outerDiameter:distance$6}),pcbKeepoutProps=z$1.union([pcbLayoutProps.omit({pcbRotation:!0}).extend({shape:z$1.literal("circle"),radius:distance$6}),pcbLayoutProps.extend({shape:z$1.literal("rect"),width:distance$6,height:distance$6})]);z$1.object({schX:distance$6,schY:distance$6,width:distance$6,height:distance$6}),z$1.object({schX:distance$6,schY:distance$6,text:z$1.string()}),z$1.object({x1:distance$6,y1:distance$6,x2:distance$6,y2:distance$6}),z$1.object({points:z$1.array(point$5),isFilled:z$1.boolean().optional().default(!1),fillColor:z$1.enum(["red","blue"]).optional()});var powerSourceProps=commonComponentProps.extend({voltage:voltage$3});commonLayoutProps.extend({name:z$1.string(),pinNumber:z$1.number().optional(),aliases:z$1.array(z$1.string()).optional(),direction});var silkscreenTextProps=pcbLayoutProps.extend({text:z$1.string(),anchorAlignment:z$1.enum(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),font:z$1.enum(["tscircuit2024"]).optional(),fontSize:length$5.optional()}),silkscreenPathProps=pcbLayoutProps.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({route:z$1.array(route_hint_point$3),strokeWidth:length$5.optional()}),silkscreenLineProps=pcbLayoutProps.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({strokeWidth:distance$6,x1:distance$6,y1:distance$6,x2:distance$6,y2:distance$6}),silkscreenRectProps=pcbLayoutProps.omit({pcbRotation:!0}).extend({isFilled:z$1.boolean().optional(),isOutline:z$1.boolean().optional(),strokeWidth:distance$6.optional(),width:distance$6,height:distance$6}),silkscreenCircleProps=pcbLayoutProps.omit({pcbRotation:!0}).extend({isFilled:z$1.boolean().optional(),isOutline:z$1.boolean().optional(),strokeWidth:distance$6.optional(),radius:distance$6}),routeHintPointProps=z$1.object({x:distance$6,y:distance$6,via:z$1.boolean().optional(),toLayer:layer_ref$3.optional()}),traceHintProps=z$1.object({for:z$1.string().optional().describe("Selector for the port you're targeting, not required if you're inside a trace"),order:z$1.number().optional(),offset:route_hint_point$3.or(routeHintPointProps).optional(),offsets:z$1.array(route_hint_point$3).or(z$1.array(routeHintPointProps)).optional(),traceWidth:z$1.number().optional()});z$1.object({layer:z$1.string().optional(),thickness:distance$6.optional(),route:z$1.array(route_hint_point$3)});var fabricationNoteTextProps=pcbLayoutProps.extend({text:z$1.string(),anchorAlignment:z$1.enum(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),font:z$1.enum(["tscircuit2024"]).optional(),fontSize:length$5.optional(),color:z$1.string().optional()}),fabricationNotePathProps=pcbLayoutProps.omit({pcbX:!0,pcbY:!0,pcbRotation:!0}).extend({route:z$1.array(route_hint_point$3),strokeWidth:length$5.optional(),color:z$1.string().optional()}),su$1=(lV,J={})=>{let VV=lV._internal_store;if(!VV){VV={counts:{}},lV._internal_store=VV;for(const UV of lV){const ZV=UV.type,WV=UV[`${ZV}_id`];if(!WV)continue;const IV=Number.parseInt(WV.split("_").pop());Number.isNaN(IV)||(VV.counts[ZV]=Math.max(VV.counts[ZV]??0,IV))}}return new Proxy({},{get:(UV,ZV)=>ZV==="toArray"?()=>lV:{get:WV=>lV.find(IV=>IV.type===ZV&&IV[`${ZV}_id`]===WV),getUsing:WV=>{const IV=Object.keys(WV);if(IV.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const dV=IV[0],CV=dV.replace("_id",""),FV=lV.find(NV=>NV.type===CV&&NV[dV]===WV[dV]);return FV?lV.find(NV=>NV.type===ZV&&NV[`${ZV}_id`]===FV[`${ZV}_id`]):null},getWhere:WV=>{const IV=Object.keys(WV);return lV.find(dV=>dV.type===ZV&&IV.every(CV=>dV[CV]===WV[CV]))},list:WV=>{const IV=WV?Object.keys(WV):[];return lV.filter(dV=>dV.type===ZV&&IV.every(CV=>dV[CV]===WV[CV]))},insert:WV=>{var CV;(CV=VV.counts)[ZV]??(CV[ZV]=-1),VV.counts[ZV]++;const IV=VV.counts[ZV],dV={type:ZV,[`${ZV}_id`]:`${ZV}_${IV}`,...WV};return J.validateInserts&&(Soup[ZV]??any_soup_element).parse(dV),lV.push(dV),dV},delete:WV=>{const IV=lV.find(dV=>dV[`${ZV}_id`]===WV);IV&&lV.splice(lV.indexOf(IV),1)},update:(WV,IV)=>{const dV=lV.find(CV=>CV.type===ZV&&CV[`${ZV}_id`]===WV);if(dV)return Object.assign(dV,IV),dV},select:WV=>{if(ZV==="source_component")return lV.find(IV=>IV.type==="source_component"&&IV.name===WV.replace(/\./g,""));if(ZV==="pcb_port"||ZV==="source_port"||ZV==="schematic_port"){const[IV,dV]=WV.replace(/\./g,"").split(/[\s\>]+/),CV=lV.find(NV=>NV.type==="source_component"&&NV.name===IV);if(!CV)return null;const FV=lV.find(NV=>NV.type==="source_port"&&NV.source_component_id===CV.source_component_id&&(NV.name===dV||(NV.port_hints??[]).includes(dV)));if(!FV)return null;if(ZV==="source_port")return FV;if(ZV==="pcb_port")return lV.find(NV=>NV.type==="pcb_port"&&NV.source_port_id===FV.source_port_id);if(ZV==="schematic_port")return lV.find(NV=>NV.type==="schematic_port"&&NV.source_port_id===FV.source_port_id)}}}})};su$1.unparsed=su$1;var su_default$1=su$1,__defProp=Object.defineProperty,__export=(lV,J)=>{for(var VV in J)__defProp(lV,VV,{get:J[VV],enumerable:!0})},components_exports={};__export(components_exports,{Battery:()=>Battery,Board:()=>Board,Capacitor:()=>Capacitor,Chip:()=>Chip,Constraint:()=>Constraint2,Crystal:()=>Crystal,Diode:()=>Diode,FabricationNotePath:()=>FabricationNotePath,FabricationNoteText:()=>FabricationNoteText,Footprint:()=>Footprint,Group:()=>Group$1,Hole:()=>Hole,Inductor:()=>Inductor,Jumper:()=>Jumper,Keepout:()=>Keepout,Led:()=>Led,Mosfet:()=>Mosfet,Net:()=>Net,NetAlias:()=>NetAlias,NormalComponent:()=>NormalComponent,PinHeader:()=>PinHeader,PlatedHole:()=>PlatedHole,Port:()=>Port,Potentiometer:()=>Potentiometer,PowerSource:()=>PowerSource,PrimitiveComponent:()=>PrimitiveComponent,PushButton:()=>PushButton,Renderable:()=>Renderable,Resistor:()=>Resistor,Resonator:()=>Resonator,SilkscreenCircle:()=>SilkscreenCircle,SilkscreenLine:()=>SilkscreenLine,SilkscreenPath:()=>SilkscreenPath,SilkscreenRect:()=>SilkscreenRect,SilkscreenText:()=>SilkscreenText,SmtPad:()=>SmtPad,Subcircuit:()=>Subcircuit,Trace:()=>Trace,TraceHint:()=>TraceHint,Transistor:()=>Transistor,Via:()=>Via});var orderedRenderPhases=["ReactSubtreesRender","InitializePortsFromChildren","CreateNetsFromProps","CreateTracesFromProps","CreateTraceHintsFromProps","SourceRender","SourceParentAttachment","PortDiscovery","PortMatching","SourceTraceRender","SourceAddConnectivityMapKey","SchematicComponentRender","SchematicPortRender","SchematicLayout","SchematicTraceRender","PcbComponentRender","PcbPrimitiveRender","PcbFootprintLayout","PcbPortRender","PcbPortAttachment","PcbLayout","PcbComponentSizeCalculation","PcbTraceRender","PcbTraceHintRender","PcbRouteNetIslands","CadModelRender","PartsEngineRender"],globalRenderCounter=0,Renderable=class{constructor(lV){kW(this,"renderPhaseStates");kW(this,"shouldBeRemoved",!1);kW(this,"children");kW(this,"isPcbPrimitive",!1);kW(this,"isSchematicPrimitive",!1);kW(this,"_renderId");kW(this,"_currentRenderPhase",null);kW(this,"_asyncEffects",[]);this._renderId=`${globalRenderCounter++}`,this.children=[],this.renderPhaseStates={};for(const J of orderedRenderPhases)this.renderPhaseStates[J]={initialized:!1,dirty:!1}}_markDirty(lV){this.renderPhaseStates[lV].dirty=!0;const J=orderedRenderPhases.indexOf(lV);for(let VV=J+1;VV<orderedRenderPhases.length;VV++)this.renderPhaseStates[orderedRenderPhases[VV]].dirty=!0}_queueAsyncEffect(lV,J){const VV={promise:J(),phase:this._currentRenderPhase,effectName:lV,complete:!1};this._asyncEffects.push(VV),"root"in this&&this.root&&this.root.emit("asyncEffect:start",{effectName:lV,componentDisplayName:this.getString(),phase:VV.phase}),VV.promise.then(()=>{VV.complete=!0,"root"in this&&this.root&&this.root.emit("asyncEffect:end",{effectName:lV,componentDisplayName:this.getString(),phase:VV.phase})}).catch(RV=>{console.error(`Async effect error in ${VV.phase} "${lV}":
|
|
22050
|
+
${RV.stack}`),VV.complete=!0,"root"in this&&this.root&&this.root.emit("asyncEffect:end",{effectName:lV,componentDisplayName:this.getString(),phase:VV.phase,error:RV.toString()})})}_emitRenderLifecycleEvent(lV,J){const VV=`renderable:renderLifecycle:${lV}:${J}`,RV={renderId:this._renderId,componentDisplayName:this.getString(),type:VV};"root"in this&&this.root&&(this.root.emit(VV,RV),this.root.emit("renderable:renderLifecycle:anyEvent",{...RV,type:VV}))}getString(){return this.constructor.name}_hasIncompleteAsyncEffects(){return this._asyncEffects.some(lV=>!lV.complete)}getCurrentRenderPhase(){return this._currentRenderPhase}getRenderGraph(){return{id:this._renderId,currentPhase:this._currentRenderPhase,renderPhaseStates:this.renderPhaseStates,shouldBeRemoved:this.shouldBeRemoved,children:this.children.map(lV=>lV.getRenderGraph())}}runRenderCycle(){for(const lV of orderedRenderPhases)this.runRenderPhaseForChildren(lV),this.runRenderPhase(lV)}runRenderPhase(lV){var ZV,WV,IV;this._currentRenderPhase=lV;const J=this.renderPhaseStates[lV],VV=J.initialized,RV=J.dirty;if(!VV&&this.shouldBeRemoved)return;if(this.shouldBeRemoved&&VV){this._emitRenderLifecycleEvent(lV,"start"),(ZV=this==null?void 0:this[`remove${lV}`])==null||ZV.call(this),J.initialized=!1,J.dirty=!1,this._emitRenderLifecycleEvent(lV,"end");return}const UV=orderedRenderPhases.indexOf(lV)-1;if(UV>=0){const dV=orderedRenderPhases[UV];if(this._asyncEffects.filter(FV=>FV.phase===dV).some(FV=>!FV.complete))return}if(this._emitRenderLifecycleEvent(lV,"start"),VV){RV&&((WV=this==null?void 0:this[`update${lV}`])==null||WV.call(this),J.dirty=!1),this._emitRenderLifecycleEvent(lV,"end");return}J.dirty=!1,(IV=this==null?void 0:this[`doInitial${lV}`])==null||IV.call(this),J.initialized=!0,this._emitRenderLifecycleEvent(lV,"end")}runRenderPhaseForChildren(lV){for(const J of this.children)J.runRenderPhaseForChildren(lV),J.runRenderPhase(lV)}renderError(lV){throw typeof lV=="string"?new Error(lV):new Error(JSON.stringify(lV,null,2))}},catalogue={},extendCatalogue=lV=>{const J=Object.fromEntries(Object.entries(lV).map(([VV,RV])=>[VV.toLowerCase(),RV]));Object.assign(catalogue,lV),Object.assign(catalogue,J)};function prepare(lV,J){const VV=lV;return VV.__tsci={...J},lV}var hostConfig={supportsMutation:!0,createInstance(lV,J){const VV=catalogue[lV];if(!VV)throw Object.keys(catalogue).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): "${lV}" See CREATING_NEW_COMPONENTS.md`);return prepare(new VV(J),{})},createTextInstance(){return{}},appendInitialChild(lV,J){lV.add(J)},appendChild(lV,J){lV.add(J)},appendChildToContainer(lV,J){lV.add(J)},finalizeInitialChildren(){return!1},prepareUpdate(){return null},shouldSetTextContent(){return!1},getRootHostContext(){return{}},getChildHostContext(){return{}},prepareForCommit(){return null},resetAfterCommit(){},commitMount(){},commitUpdate(){},removeChild(){},clearContainer(){},supportsPersistence:!1,getPublicInstance(lV){return lV},preparePortalMount(lV){throw new Error("Function not implemented.")},scheduleTimeout(lV,J){throw new Error("Function not implemented.")},cancelTimeout(lV){throw new Error("Function not implemented.")},noTimeout:void 0,isPrimaryRenderer:!1,getCurrentEventPriority(){throw new Error("Function not implemented.")},getInstanceFromNode(lV){throw new Error("Function not implemented.")},beforeActiveInstanceBlur(){throw new Error("Function not implemented.")},afterActiveInstanceBlur(){throw new Error("Function not implemented.")},prepareScopeUpdate:(lV,J)=>{throw new Error("Function not implemented.")},getInstanceFromScope:lV=>{throw new Error("Function not implemented.")},detachDeletedInstance:lV=>{throw new Error("Function not implemented.")},supportsHydration:!1},reconciler=ReactReconciler(hostConfig),createInstanceFromReactElement=lV=>{const J={children:[],props:{name:"$root"},add(UV){UV.parent=this,this.children.push(UV)},computePcbGlobalTransform(){return identity$4()}},VV=reconciler.createContainer(J,0,null,!1,null,"tsci",UV=>{console.log("Error in createContainer"),console.error(UV)},null);reconciler.updateContainer(lV,VV,null,()=>{});const RV=reconciler.getPublicRootInstance(VV);return RV||J.children[0]},parsePinNumberFromLabelsOrThrow=(lV,J)=>{if(typeof lV=="number")return lV;if(lV.startsWith("pin"))return Number(lV.slice(3));if(!J)throw new Error(`No pin labels provided and pin number or label is not a number: "${lV}"`);for(const VV in J)if((Array.isArray(J[VV])?J[VV]:[J[VV]]).includes(lV))return Number(VV.replace("pin",""));throw new Error(`No pin labels provided and pin number or label is not a number: "${lV}"`)},underscorifyPinStyles=(lV,J)=>{if(!lV)return;const VV={},RV={};for(const[UV,ZV]of Object.entries(lV)){const WV=parsePinNumberFromLabelsOrThrow(UV,J);RV[WV]={...RV[WV],...ZV}}for(const[UV,ZV]of Object.entries(RV)){const WV=`pin${UV}`;VV[WV]={bottom_margin:ZV.bottomMargin,left_margin:ZV.leftMargin,right_margin:ZV.rightMargin,top_margin:ZV.topMargin}}return VV},underscorifyPortArrangement=lV=>{if(lV){if("leftSide"in lV||"rightSide"in lV||"topSide"in lV||"bottomSide"in lV)return{left_side:lV.leftSide,right_side:lV.rightSide,top_side:lV.topSide,bottom_side:lV.bottomSide};if("leftPinCount"in lV||"rightPinCount"in lV||"topPinCount"in lV||"bottomPinCount"in lV)return{left_size:lV.leftPinCount,right_size:lV.rightPinCount,top_size:lV.topPinCount,bottom_size:lV.bottomPinCount};if("leftSize"in lV||"rightSize"in lV||"topSize"in lV||"bottomSize"in lV)return{left_size:lV.leftSize,right_size:lV.rightSize,top_size:lV.topSize,bottom_size:lV.bottomSize}}},InvalidProps=class extends Error{constructor(lV,J,VV){let RV;const ZV=Object.keys(VV).filter(WV=>WV!=="_errors").map(WV=>VV[WV]._errors[0]?`${WV} (${VV[WV]._errors[0]})`:`${WV} (${JSON.stringify(VV[WV])})`).join(", ");"name"in J?RV=`Invalid props for ${lV} "${J.name}": ${ZV}`:"footprint"in J&&typeof J.footprint=="string"?RV=`Invalid props for ${lV} (unnamed ${J.footprint} component): ${ZV}`:RV=`Invalid props for ${lV} (unnamed): ${ZV}`,super(RV),this.componentName=lV,this.originalProps=J,this.formattedError=VV}};function isMatchingSelector(lV,J){const VV=J.match(/^#(\w+)/);if(VV)return lV.props.id===VV[1];const RV=J.match(/^\.(\w+)/);if(RV)return lV.isMatchingNameOrAlias(RV[1]);let[UV,...ZV]=J.split(/(?=[#.[])/);return UV==="pin"&&(UV="port"),UV&&UV!=="*"&&lV.lowercaseComponentName!==UV.toLowerCase()?!1:ZV.every(WV=>{if(WV.startsWith("#"))return lV.props.id===WV.slice(1);if(WV.startsWith("."))return lV.isMatchingNameOrAlias(WV.slice(1));const IV=WV.match(/\[(\w+)=['"]?(.+?)['"]?\]/);if(!IV)return!0;const[,dV,CV]=IV;return lV.props[dV].toString()===CV})}var debugSelectAll=Debug$1("tscircuit:primitive-component:selectAll"),PrimitiveComponent=class extends Renderable{constructor(J){super(J);kW(this,"parent",null);kW(this,"children");kW(this,"childrenPendingRemoval");kW(this,"props");kW(this,"_parsedProps");kW(this,"externallyAddedAliases");kW(this,"isPrimitiveContainer",!1);kW(this,"source_group_id",null);kW(this,"source_component_id",null);kW(this,"schematic_component_id",null);kW(this,"pcb_component_id",null);kW(this,"cad_component_id",null);this.children=[],this.childrenPendingRemoval=[],this.props=J??{},this.externallyAddedAliases=[];const VV=this.config.zodProps.safeParse(J??{});if(VV.success)this._parsedProps=VV.data;else throw new InvalidProps(this.lowercaseComponentName,this.props,VV.error.format())}get config(){return{componentName:"",zodProps:z$1.object({}).passthrough()}}get componentName(){return this.config.componentName}getInheritedProperty(J){let VV=this;for(;VV;){if(VV._parsedProps&&J in VV._parsedProps)return VV._parsedProps[J];VV=VV.parent}}get lowercaseComponentName(){return this.componentName.toLowerCase()}get isSubcircuit(){var J;return!!this.props.subcircuit||this.lowercaseComponentName==="group"&&((J=this==null?void 0:this.parent)==null?void 0:J.isRoot)}get isGroup(){return this.lowercaseComponentName==="group"}setProps(J){var UV,ZV;const VV=this.config.zodProps.parse({...this.props,...J}),RV=this.props;this.props=VV,this._parsedProps=this.config.zodProps.parse(J),this.onPropsChange({oldProps:RV,newProps:VV,changedProps:Object.keys(J)}),(ZV=(UV=this.parent)==null?void 0:UV.onChildChanged)==null||ZV.call(UV,this)}computePcbPropsTransform(){const{_parsedProps:J}=this;return compose(translate(J.pcbX??0,J.pcbY??0),rotate((J.pcbRotation??0)*Math.PI/180))}_computePcbGlobalTransformBeforeLayout(){var RV,UV,ZV;const{_parsedProps:J}=this,VV=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if(VV&&this.props.pcbX===void 0&&this.props.pcbY===void 0)return compose(((RV=this.parent)==null?void 0:RV._computePcbGlobalTransformBeforeLayout())??identity$4(),compose(translate(VV.x,VV.y),rotate((J.pcbRotation??0)*Math.PI/180)));if(this.isPcbPrimitive){const WV=this.getPrimitiveContainer();if(WV){const IV=WV._parsedProps.layer==="bottom",dV=WV._getGlobalPcbPositionBeforeLayout();if(IV)return compose(translate(dV.x,dV.y),flipY(),translate(-dV.x,-dV.y)),compose(((UV=this.parent)==null?void 0:UV._computePcbGlobalTransformBeforeLayout())??identity$4(),flipY(),this.computePcbPropsTransform())}}return compose(((ZV=this.parent)==null?void 0:ZV._computePcbGlobalTransformBeforeLayout())??identity$4(),this.computePcbPropsTransform())}getPrimitiveContainer(){var J,VV;return this.isPrimitiveContainer?this:((VV=(J=this.parent)==null?void 0:J.getPrimitiveContainer)==null?void 0:VV.call(J))??null}_getPcbCircuitJsonBounds(){return{center:{x:0,y:0},bounds:{left:0,top:0,right:0,bottom:0},width:0,height:0}}_getPcbPrimitiveFlippedHelpers(){const J=this.getPrimitiveContainer(),VV=J?J._parsedProps.layer==="bottom":!1;return{isFlipped:VV,maybeFlipLayer:UV=>VV?UV==="top"?"bottom":"top":UV}}_setPositionFromLayout(J){throw new Error(`_setPositionFromLayout not implemented for ${this.componentName}`)}computeSchematicPropsTransform(){return compose(translate(this.props.schX??0,this.props.schY??0))}computeSchematicGlobalTransform(){var VV,RV;const J=this._getSchematicGlobalManualPlacementTransform(this);return J||compose(((RV=(VV=this.parent)==null?void 0:VV.computeSchematicGlobalTransform)==null?void 0:RV.call(VV))??identity$4(),this.computeSchematicPropsTransform())}_getSchematicSymbolName(){const{_parsedProps:J}=this,VV=this.config.schematicSymbolName,RV=`${VV}_horz`,UV=`${VV}_vert`,ZV=`${VV}_up`,WV=`${VV}_down`,IV=`${VV}_left`,dV=`${VV}_right`;if(dV in symbols_index_default&&(J.schRotation===void 0||J.schRotation===0))return dV;if(ZV in symbols_index_default&&J.schRotation===90)return ZV;if(IV in symbols_index_default&&J.schRotation===180)return IV;if(WV in symbols_index_default&&J.schRotation===270)return WV;if(RV in symbols_index_default&&(J.schRotation===0||J.schRotation===void 0||J.schRotation===180))return RV;if(UV in symbols_index_default&&(J.schRotation===90||J.schRotation===270))return UV;if(VV in symbols_index_default)return VV}_getSchematicSymbolNameOrThrow(){const J=this._getSchematicSymbolName();if(!J)throw new Error(`No schematic symbol found (given: "${this.config.schematicSymbolName}")`);return J}getSchematicSymbol(){const J=this._getSchematicSymbolName();return J?symbols_index_default[J]??null:null}_getPcbManualPlacementForComponent(J){var ZV;if(!this.isSubcircuit)return null;const VV=this.props.layout,RV=this.props.manualEdits;if(!VV&&!RV)return null;const UV=((ZV=VV==null?void 0:VV.manual_pcb_placement_config)==null?void 0:ZV.positions)||(RV==null?void 0:RV.pcb_placements);if(!UV)return null;for(const WV of UV)if(VV&&isMatchingSelector(J,WV.selector)||J.props.name===WV.selector)return applyToPoint(this._computePcbGlobalTransformBeforeLayout(),WV.center);return null}_getSchematicGlobalManualPlacementTransform(J){var RV,UV;const VV=(RV=this.getSubcircuit())==null?void 0:RV._parsedProps.manualEdits;if(!VV)return null;for(const ZV of VV.schematic_placements??[])if((isMatchingSelector(J,ZV.selector)||J.props.name===ZV.selector)&&ZV.relative_to==="group_center")return compose(((UV=this.parent)==null?void 0:UV._computePcbGlobalTransformBeforeLayout())??identity$4(),translate(ZV.center.x,ZV.center.y));return null}_getGlobalPcbPositionBeforeLayout(){return applyToPoint(this._computePcbGlobalTransformBeforeLayout(),{x:0,y:0})}_getGlobalSchematicPositionBeforeLayout(){return applyToPoint(this.computeSchematicGlobalTransform(),{x:0,y:0})}get root(){var J;return((J=this.parent)==null?void 0:J.root)??null}onAddToParent(J){this.parent=J}onPropsChange(J){}onChildChanged(J){var VV,RV;(RV=(VV=this.parent)==null?void 0:VV.onChildChanged)==null||RV.call(VV,J)}add(J){J.onAddToParent(this),J.parent=this,this.children.push(J)}addAll(J){for(const VV of J)this.add(VV)}remove(J){this.children=this.children.filter(VV=>VV!==J),this.childrenPendingRemoval.push(J),J.shouldBeRemoved=!0}getSubcircuitSelector(){const J=this._parsedProps.name,VV=J?`${this.lowercaseComponentName}.${J}`:this.lowercaseComponentName;return!this.parent||this.parent.isSubcircuit?VV:`${this.parent.getSubcircuitSelector()} > ${VV}`}getFullPathSelector(){var UV,ZV;const J=this._parsedProps.name,VV=J?`${this.lowercaseComponentName}.${J}`:this.lowercaseComponentName,RV=(ZV=(UV=this.parent)==null?void 0:UV.getFullPathSelector)==null?void 0:ZV.call(UV);return RV?`${RV} > ${VV}`:VV}getNameAndAliases(){return[this._parsedProps.name,...this._parsedProps.portHints??[]].filter(Boolean)}isMatchingNameOrAlias(J){return this.getNameAndAliases().includes(J)}isMatchingAnyOf(J){return this.getNameAndAliases().some(VV=>J.map(RV=>RV.toString()).includes(VV))}getPcbSize(){throw new Error(`getPcbSize not implemented for ${this.componentName}`)}doesSelectorMatch(J){const VV=[this.componentName,this.lowercaseComponentName],RV=[this._parsedProps.name].filter(Boolean),UV=J.trim().split(/\> /)[0],ZV=UV[0];return UV.length>1?!1:!!(J==="*"||J[0]==="#"&&J.slice(1)===this.props.id||J[0]==="."&&RV.includes(J.slice(1))||/^[a-zA-Z0-9_]/.test(ZV)&&VV.includes(ZV))}getSubcircuit(){var VV,RV;if(this.isSubcircuit)return this;const J=(RV=(VV=this.parent)==null?void 0:VV.getSubcircuit)==null?void 0:RV.call(VV);if(!J)throw new Error("Component is not inside an opaque group (no board?)");return J}selectAll(J){debugSelectAll(`selectAll: "${J}"`);const VV=J.trim().split(/\s+/);let RV=VV[0]===">"?this.children:this.getSelectableDescendants(),UV=[],ZV=!1,WV=-1;for(const IV of VV)if(WV++,debugSelectAll(`
|
|
22051
22051
|
|
|
22052
22052
|
iteration: ${WV}`),debugSelectAll(`part: "${VV[WV]}"`),debugSelectAll(`currentSearch: [${RV.map(dV=>dV.getString()).join(",")}]`),debugSelectAll(`currentResults: [${UV.map(dV=>dV.getString()).join(",")}]`),IV===">")ZV=!0;else{const dV=RV.filter(FV=>isMatchingSelector(FV,IV));RV=dV.flatMap(FV=>ZV?FV.children:FV.getSelectableDescendants()),UV=dV,ZV=!1}return UV}selectOne(J,VV){var UV;let RV=(UV=VV==null?void 0:VV.type)==null?void 0:UV.toLowerCase();return VV!=null&&VV.port&&(RV="port"),RV?this.selectAll(J).find(ZV=>ZV.lowercaseComponentName===RV)??null:VV!=null&&VV.pcbPrimitive?this.selectAll(J).find(ZV=>ZV.isPcbPrimitive)??null:VV!=null&&VV.schematicPrimitive?this.selectAll(J).find(ZV=>ZV.isSchematicPrimitive)??null:this.selectAll(J)[0]??null}getAvailablePcbLayers(){var J,VV;if(this.isPcbPrimitive){const{maybeFlipLayer:RV}=this._getPcbPrimitiveFlippedHelpers();return"layer"in this._parsedProps||this.componentName==="SmtPad"?[RV(this._parsedProps.layer??"top")]:"layers"in this._parsedProps?this._parsedProps.layers:this.componentName==="PlatedHole"?((VV=(J=this.root)==null?void 0:J._getBoard())==null?void 0:VV.allLayers)??["top","bottom"]:[]}return[]}getDescendants(){const J=[];for(const VV of this.children)J.push(VV),J.push(...VV.getDescendants());return J}getSelectableDescendants(){const J=[];for(const VV of this.children)VV.isSubcircuit?J.push(VV):(J.push(VV),J.push(...VV.getSelectableDescendants()));return J}_getPinCount(){return 0}_getSchematicBoxDimensions(){return null}renderError(J){var VV;if(typeof J=="string")return super.renderError(J);(VV=this.root)==null||VV.db.pcb_placement_error.insert(J)}getString(){var UV,ZV;const{lowercaseComponentName:J,_parsedProps:VV,parent:RV}=this;return(VV==null?void 0:VV.pinNumber)!==void 0&&((UV=RV==null?void 0:RV.props)!=null&&UV.name)&&(VV!=null&&VV.name)?`<${J}#${this._renderId}(pin:${VV.pinNumber} .${RV==null?void 0:RV.props.name}>.${VV.name}) />`:(ZV=RV==null?void 0:RV.props)!=null&&ZV.name&&(VV!=null&&VV.name)?`<${J}#${this._renderId}(.${RV==null?void 0:RV.props.name}>.${VV==null?void 0:VV.name}) />`:VV!=null&&VV.from&&(VV!=null&&VV.to)?`<${J}#${this._renderId}(from:${VV.from} to:${VV==null?void 0:VV.to}) />`:VV!=null&&VV.name?`<${J}#${this._renderId} name=".${VV==null?void 0:VV.name}" />`:VV!=null&&VV.portHints?`<${J}#${this._renderId}(${VV.portHints.map(WV=>`.${WV}`).join(", ")}) />`:`<${J}#${this._renderId} />`}get[Symbol.toStringTag](){return this.getString()}[Symbol.for("nodejs.util.inspect.custom")](){return this.getString()}};function pairs$1(lV){const J=[];for(let VV=0;VV<lV.length-1;VV++)J.push([lV[VV],lV[VV+1]]);return J}var netProps=z$1.object({name:z$1.string()}),Net=class extends PrimitiveComponent{constructor(){super(...arguments);kW(this,"source_net_id")}get config(){return{componentName:"Net",zodProps:netProps}}getPortSelector(){return`net.${this.props.name}`}doInitialSourceRender(){const{db:J}=this.root,{_parsedProps:VV}=this,RV=J.source_net.insert({name:VV.name,member_source_group_ids:[]});this.source_net_id=RV.source_net_id}getAllConnectedPorts(){const J=this.getSubcircuit().selectAll("port"),VV=[];for(const RV of J){const UV=RV._getDirectlyConnectedTraces();for(const ZV of UV)if(ZV._isExplicitlyConnectedToNet(this)){VV.push(RV);break}}return VV}_getAllDirectlyConnectedTraces(){const J=this.getSubcircuit().selectAll("trace"),VV=[];for(const RV of J)RV._isExplicitlyConnectedToNet(this)&&VV.push(RV);return VV}doInitialPcbRouteNetIslands(){var ZV;if((ZV=this.root)!=null&&ZV.pcbDisabled)return;const{db:J}=this.root,VV=this._getAllDirectlyConnectedTraces().filter(WV=>{var IV;return(((IV=WV._portsRoutedOnPcb)==null?void 0:IV.length)??0)>0}),RV=[];for(const WV of VV){const IV=WV._portsRoutedOnPcb,dV=RV.find(CV=>IV.some(FV=>CV.ports.includes(FV)));if(!dV){RV.push({ports:[...IV],traces:[WV]});continue}dV.traces.push(WV),dV.ports.push(...IV)}if(RV.length===0)return;const UV=pairs$1(RV);for(const[WV,IV]of UV){const dV=WV.ports.map(GV=>GV._getGlobalPcbPositionBeforeLayout()),CV=IV.ports.map(GV=>GV._getGlobalPcbPositionBeforeLayout());let FV=1/0,NV=[-1,-1];for(let GV=0;GV<dV.length;GV++){const YV=dV[GV];for(let TV=0;TV<CV.length;TV++){const iV=CV[TV],AV=Math.sqrt((YV.x-iV.x)**2+(YV.y-iV.y)**2);AV<FV&&(FV=AV,NV=[GV,TV])}}const eV=WV.ports[NV[0]],gV=IV.ports[NV[1]],nV=J.toArray().filter(GV=>GV.type==="pcb_smtpad"||GV.type==="pcb_trace"||GV.type==="pcb_plated_hole"||GV.type==="pcb_hole"||GV.type==="source_port"||GV.type==="pcb_port"),{solution:JV}=autoroute2(nV.concat([{type:"source_trace",source_trace_id:"__net_trace_tmp",connected_source_port_ids:[eV.source_port_id,gV.source_port_id]}])),aV=JV[0];if(!aV){this.renderError({pcb_trace_error_id:"",pcb_trace_id:"__net_trace_tmp",pcb_component_ids:[eV.pcb_component_id,gV.pcb_component_id].filter(Boolean),pcb_port_ids:[eV.pcb_port_id,gV.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}J.pcb_trace.insert(aV)}}renderError(J){var VV;if(typeof J=="string")return super.renderError(J);(VV=this.root)==null||VV.db.pcb_trace_error.insert(J)}},createNetsFromProps=(lV,J)=>{for(const VV of J)typeof VV=="string"&&VV.startsWith("net.")&&(lV.getSubcircuit().selectOne(VV)||lV.getSubcircuit().add(new Net({name:VV.split("net.")[1]})))},SmtPad=class extends PrimitiveComponent{constructor(){super(...arguments);kW(this,"pcb_smtpad_id",null);kW(this,"matchedPort",null);kW(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SmtPad",zodProps:smtPadProps}}getPcbSize(){const{_parsedProps:J}=this;if(J.shape==="circle")return{width:J.radius*2,height:J.radius*2};if(J.shape==="rect")return{width:J.width,height:J.height};throw new Error(`getPcbSize for shape "${J.shape}" not implemented for ${this.componentName}`)}doInitialPortMatching(){var VV;const J=(VV=this.getPrimitiveContainer())==null?void 0:VV.selectAll("port");if(this.props.portHints){for(const RV of J)if(RV.isMatchingAnyOf(this.props.portHints)){this.matchedPort=RV,RV.registerMatch(this);return}}}doInitialPcbPrimitiveRender(){var NV,eV,gV,nV,JV;if((NV=this.root)!=null&&NV.pcbDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this;if(!VV.portHints)return;const RV=this.getPrimitiveContainer(),UV=this._getGlobalPcbPositionBeforeLayout();RV==null||RV._getGlobalPcbPositionBeforeLayout();const ZV=decomposeTSR(this._computePcbGlobalTransformBeforeLayout()),WV=Math.abs(ZV.rotation.angle*(180/Math.PI)-90)%180<.01,{maybeFlipLayer:IV}=this._getPcbPrimitiveFlippedHelpers(),dV=(RV==null?void 0:RV._parsedProps.pcbRotation)??0;let CV=null;const FV=((eV=this.parent)==null?void 0:eV.pcb_component_id)??((gV=this.getPrimitiveContainer())==null?void 0:gV.pcb_component_id);VV.shape==="circle"?(CV=J.pcb_smtpad.insert({pcb_component_id:FV,pcb_port_id:(nV=this.matchedPort)==null?void 0:nV.pcb_port_id,layer:IV(VV.layer??"top"),shape:"circle",radius:VV.radius,port_hints:VV.portHints.map(aV=>aV.toString()),x:UV.x,y:UV.y}),J.pcb_solder_paste.insert({layer:CV.layer,shape:"circle",radius:CV.radius*.7,x:CV.x,y:CV.y,pcb_component_id:CV.pcb_component_id,pcb_smtpad_id:CV.pcb_smtpad_id})):VV.shape==="rect"&&(CV=dV===0||WV?J.pcb_smtpad.insert({pcb_component_id:FV,pcb_port_id:(JV=this.matchedPort)==null?void 0:JV.pcb_port_id,layer:IV(VV.layer??"top"),shape:"rect",width:WV?VV.height:VV.width,height:WV?VV.width:VV.height,port_hints:VV.portHints.map(aV=>aV.toString()),x:UV.x,y:UV.y}):J.pcb_smtpad.insert({pcb_component_id:FV,layer:VV.layer??"top",shape:"rotated_rect",width:VV.width,height:VV.height,x:UV.x,y:UV.y,ccw_rotation:dV,port_hints:VV.portHints.map(aV=>aV.toString())}),CV.shape==="rect"&&J.pcb_solder_paste.insert({layer:CV.layer,shape:"rect",width:CV.width*.7,height:CV.height*.7,x:CV.x,y:CV.y,pcb_component_id:CV.pcb_component_id,pcb_smtpad_id:CV.pcb_smtpad_id})),CV&&(this.pcb_smtpad_id=CV.pcb_smtpad_id)}doInitialPcbPortAttachment(){var VV,RV;if((VV=this.root)!=null&&VV.pcbDisabled)return;const{db:J}=this.root;J.pcb_smtpad.update(this.pcb_smtpad_id,{pcb_port_id:(RV=this.matchedPort)==null?void 0:RV.pcb_port_id})}_getPcbCircuitJsonBounds(){const{db:J}=this.root,VV=J.pcb_smtpad.get(this.pcb_smtpad_id);if(VV.shape==="rect")return{center:{x:VV.x,y:VV.y},bounds:{left:VV.x-VV.width/2,top:VV.y+VV.height/2,right:VV.x+VV.width/2,bottom:VV.y-VV.height/2},width:VV.width,height:VV.height};if(VV.shape==="rotated_rect"){const RV=VV.ccw_rotation*Math.PI/180,UV=Math.cos(RV),ZV=Math.sin(RV),WV=VV.width/2,IV=VV.height/2,dV=Math.abs(WV*UV)+Math.abs(IV*ZV),CV=Math.abs(WV*ZV)+Math.abs(IV*UV);return{center:{x:VV.x,y:VV.y},bounds:{left:VV.x-dV,right:VV.x+dV,top:VV.y-CV,bottom:VV.y+CV},width:dV*2,height:CV*2}}if(VV.shape==="circle")return{center:{x:VV.x,y:VV.y},bounds:{left:VV.x-VV.radius,top:VV.y-VV.radius,right:VV.x+VV.radius,bottom:VV.y+VV.radius},width:VV.radius*2,height:VV.radius*2};throw new Error(`circuitJson bounds calculation not implemented for shape "${VV.shape}"`)}_setPositionFromLayout(J){var UV;const{db:VV}=this.root;VV.pcb_smtpad.update(this.pcb_smtpad_id,{x:J.x,y:J.y});const RV=VV.pcb_solder_paste.list().find(ZV=>ZV.pcb_smtpad_id===this.pcb_smtpad_id);VV.pcb_solder_paste.update(RV==null?void 0:RV.pcb_solder_paste_id,{x:J.x,y:J.y}),(UV=this.matchedPort)==null||UV._setPositionFromLayout(J)}},SilkscreenPath=class extends PrimitiveComponent{constructor(){super(...arguments);kW(this,"pcb_silkscreen_path_id",null)}get config(){return{componentName:"SilkscreenPath",zodProps:silkscreenPathProps}}doInitialPcbPrimitiveRender(){var WV,IV;if((WV=this.root)!=null&&WV.pcbDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this,RV=VV.layer??"top";if(RV!=="top"&&RV!=="bottom")throw new Error(`Invalid layer "${RV}" for SilkscreenPath. Must be "top" or "bottom".`);const UV=this._computePcbGlobalTransformBeforeLayout(),ZV=J.pcb_silkscreen_path.insert({pcb_component_id:(IV=this.parent)==null?void 0:IV.pcb_component_id,layer:RV,route:VV.route.map(dV=>{const CV=applyToPoint(UV,{x:dV.x,y:dV.y});return{...dV,x:CV.x,y:CV.y}}),stroke_width:VV.strokeWidth??.1});this.pcb_silkscreen_path_id=ZV.pcb_silkscreen_path_id}},PlatedHole=class extends PrimitiveComponent{constructor(){super(...arguments);kW(this,"pcb_plated_hole_id",null);kW(this,"matchedPort",null);kW(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PlatedHole",zodProps:platedHoleProps}}getAvailablePcbLayers(){return["top","inner1","inner2","bottom"]}getPcbSize(){const{_parsedProps:J}=this;if(J.shape==="circle")return{width:J.outerDiameter,height:J.outerDiameter};if(J.shape==="oval"||J.shape==="pill")return{width:J.outerWidth,height:J.outerHeight};throw new Error(`getPcbSize for shape "${J.shape}" not implemented for ${this.componentName}`)}_getPcbCircuitJsonBounds(){const{db:J}=this.root,VV=J.pcb_plated_hole.get(this.pcb_plated_hole_id),RV=this.getPcbSize();return{center:{x:VV.x,y:VV.y},bounds:{left:VV.x-RV.width/2,top:VV.y+RV.height/2,right:VV.x+RV.width/2,bottom:VV.y-RV.height/2},width:RV.width,height:RV.height}}_setPositionFromLayout(J){var RV;const{db:VV}=this.root;VV.pcb_plated_hole.update(this.pcb_plated_hole_id,{x:J.x,y:J.y}),(RV=this.matchedPort)==null||RV._setPositionFromLayout(J)}doInitialPortMatching(){var VV;const J=(VV=this.getPrimitiveContainer())==null?void 0:VV.selectAll("port");if(this.props.portHints){for(const RV of J)if(RV.isMatchingAnyOf(this.props.portHints)){this.matchedPort=RV,RV.registerMatch(this);return}}}doInitialPcbPrimitiveRender(){var ZV,WV,IV,dV,CV;if((ZV=this.root)!=null&&ZV.pcbDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this,RV=this._getGlobalPcbPositionBeforeLayout(),UV=((WV=this.parent)==null?void 0:WV.pcb_component_id)??((IV=this.getPrimitiveContainer())==null?void 0:IV.pcb_component_id);if(VV.shape==="circle"){const FV=J.pcb_plated_hole.insert({pcb_component_id:UV,pcb_port_id:(dV=this.matchedPort)==null?void 0:dV.pcb_port_id,outer_diameter:VV.outerDiameter,hole_diameter:VV.holeDiameter,shape:"circle",port_hints:this.getNameAndAliases(),x:RV.x,y:RV.y,layers:["top","bottom"]});this.pcb_plated_hole_id=FV.pcb_plated_hole_id}else if(VV.shape==="pill"||VV.shape==="oval"){const FV=J.pcb_plated_hole.insert({pcb_component_id:UV,pcb_port_id:(CV=this.matchedPort)==null?void 0:CV.pcb_port_id,outer_width:VV.outerWidth,outer_height:VV.outerHeight,hole_width:VV.innerWidth,hole_height:VV.innerHeight,shape:VV.shape,port_hints:this.getNameAndAliases(),x:RV.x,y:RV.y,layers:["top","bottom"]});this.pcb_plated_hole_id=FV.pcb_plated_hole_id}}doInitialPcbPortAttachment(){var VV,RV;if((VV=this.root)!=null&&VV.pcbDisabled)return;const{db:J}=this.root;J.pcb_plated_hole.update(this.pcb_plated_hole_id,{pcb_port_id:(RV=this.matchedPort)==null?void 0:RV.pcb_port_id})}},Keepout=class extends PrimitiveComponent{constructor(){super(...arguments);kW(this,"pcb_keepout_id",null);kW(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Keepout",zodProps:pcbKeepoutProps}}doInitialPcbPrimitiveRender(){var IV;if((IV=this.root)!=null&&IV.pcbDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this,RV=this._getGlobalPcbPositionBeforeLayout(),UV=decomposeTSR(this._computePcbGlobalTransformBeforeLayout()),ZV=Math.abs(UV.rotation.angle*(180/Math.PI)-90)%180<.01;let WV=null;VV.shape==="circle"?WV=J.pcb_keepout.insert({layers:["top"],shape:"circle",radius:VV.radius,center:{x:RV.x,y:RV.y}}):VV.shape==="rect"&&(WV=J.pcb_keepout.insert({layers:["top"],shape:"rect",...ZV?{width:VV.height,height:VV.width}:{width:VV.width,height:VV.height},center:{x:RV.x,y:RV.y}})),WV&&(this.pcb_keepout_id=WV.pcb_keepout_id)}},Hole=class extends PrimitiveComponent{constructor(){super(...arguments);kW(this,"pcb_hole_id",null);kW(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Hole",zodProps:holeProps}}getPcbSize(){const{_parsedProps:J}=this;return{width:J.diameter,height:J.diameter}}doInitialPcbPrimitiveRender(){var ZV;if((ZV=this.root)!=null&&ZV.pcbDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this,RV=this._getGlobalPcbPositionBeforeLayout(),UV=J.pcb_hole.insert({hole_shape:"circle",hole_diameter:VV.diameter,x:RV.x,y:RV.y});this.pcb_hole_id=UV.pcb_hole_id}_getPcbCircuitJsonBounds(){const{db:J}=this.root,VV=J.pcb_hole.get(this.pcb_hole_id),RV=this.getPcbSize();return{center:{x:VV.x,y:VV.y},bounds:{left:VV.x-RV.width/2,top:VV.y-RV.height/2,right:VV.x+RV.width/2,bottom:VV.y+RV.height/2},width:RV.width,height:RV.height}}_setPositionFromLayout(J){const{db:VV}=this.root;VV.pcb_hole.update(this.pcb_hole_id,{x:J.x,y:J.y})}},createComponentsFromSoup=lV=>{const J=[];for(const VV of lV)VV.type==="pcb_smtpad"&&VV.shape==="rect"?J.push(new SmtPad({pcbX:VV.x,pcbY:VV.y,layer:VV.layer,shape:"rect",height:VV.height,width:VV.width,portHints:VV.port_hints})):VV.type==="pcb_smtpad"&&VV.shape==="circle"?J.push(new SmtPad({pcbX:VV.x,pcbY:VV.y,layer:VV.layer,shape:"circle",radius:VV.radius,portHints:VV.port_hints})):VV.type==="pcb_silkscreen_path"?J.push(new SilkscreenPath({layer:VV.layer,route:VV.route,strokeWidth:VV.stroke_width})):VV.type==="pcb_plated_hole"&&VV.shape==="circle"?VV.shape==="circle"&&J.push(new PlatedHole({pcbX:VV.x,pcbY:VV.y,shape:"circle",holeDiameter:VV.hole_diameter,outerDiameter:VV.outer_diameter,portHints:VV.port_hints})):VV.type==="pcb_keepout"&&VV.shape==="circle"?J.push(new Keepout({pcbX:VV.center.x,pcbY:VV.center.y,shape:"circle",radius:VV.radius})):VV.type==="pcb_keepout"&&VV.shape==="rect"?J.push(new Keepout({pcbX:VV.center.x,pcbY:VV.center.y,shape:"rect",width:VV.width,height:VV.height})):VV.type==="pcb_hole"&&VV.hole_shape==="circle"&&J.push(new Hole({pcbX:VV.x,pcbY:VV.y,diameter:VV.hole_diameter}));return J};function getBoundsOfPcbComponents(lV){let J=1/0,VV=1/0,RV=-1/0,UV=-1/0;for(const IV of lV)if(IV.isPcbPrimitive){const{x:dV,y:CV}=IV._getGlobalPcbPositionBeforeLayout(),{width:FV,height:NV}=IV.getPcbSize();J=Math.min(J,dV-FV/2),VV=Math.min(VV,CV-NV/2),RV=Math.max(RV,dV+FV/2),UV=Math.max(UV,CV+NV/2)}else if(IV.componentName==="Footprint"){const dV=getBoundsOfPcbComponents(IV.children);J=Math.min(J,dV.minX),VV=Math.min(VV,dV.minY),RV=Math.max(RV,dV.maxX),UV=Math.max(UV,dV.maxY)}let ZV=RV-J,WV=UV-VV;return ZV<0&&(ZV=0),WV<0&&(WV=0),{minX:J,minY:VV,maxX:RV,maxY:UV,width:ZV,height:WV}}function getRelativeDirection(lV,J){const VV=J.x-lV.x,RV=J.y-lV.y;return Math.abs(VV)>Math.abs(RV)?VV>=0?"right":"left":RV>=0?"up":"down"}var areAllPcbPrimitivesOverlapping=lV=>{if(lV.length<=1)return!0;const J=lV.map(ZV=>{const WV=ZV._getPcbCircuitJsonBounds();return{left:WV.bounds.left,right:WV.bounds.right,top:WV.bounds.top,bottom:WV.bounds.bottom}}),VV=Array(J.length).fill(!1).map(()=>Array(J.length).fill(!1));for(let ZV=0;ZV<J.length;ZV++)for(let WV=ZV+1;WV<J.length;WV++){const IV=J[ZV],dV=J[WV];VV[ZV][WV]=VV[WV][ZV]=!(IV.right<dV.left||IV.left>dV.right||IV.bottom>dV.top||IV.top<dV.bottom)}const RV=new Set,UV=ZV=>{RV.add(ZV);for(let WV=0;WV<J.length;WV++)VV[ZV][WV]&&!RV.has(WV)&&UV(WV)};return UV(0),RV.size===J.length},getCenterOfPcbPrimitives=lV=>{if(lV.length===0)throw new Error("Cannot get center of empty PCB primitives array");const J=lV.map(UV=>UV._getPcbCircuitJsonBounds().center).filter(Boolean),VV=J.reduce((UV,ZV)=>UV+ZV.x,0),RV=J.reduce((UV,ZV)=>UV+ZV.y,0);return{x:VV/J.length,y:RV/J.length}},portProps=z$1.object({name:z$1.string().optional(),pinNumber:z$1.number().optional(),aliases:z$1.array(z$1.string()).optional()}),Port=class extends PrimitiveComponent{constructor(J,VV={}){if(!J.name&&J.pinNumber!==void 0&&(J.name=`pin${J.pinNumber}`),!J.name)throw new Error("Port must have a name or a pinNumber");super(J);kW(this,"source_port_id",null);kW(this,"pcb_port_id",null);kW(this,"schematic_port_id",null);kW(this,"schematicSymbolPortDef",null);kW(this,"matchedComponents");kW(this,"facingDirection",null);kW(this,"originDescription",null);VV.originDescription&&(this.originDescription=VV.originDescription),this.matchedComponents=[]}get config(){return{componentName:"Port",zodProps:portProps}}_getGlobalPcbPositionBeforeLayout(){const J=this.matchedComponents.find(VV=>VV.isPcbPrimitive);if(!J)throw new Error(`Port ${this} has no matched pcb component, can't get global pcb position`);return(J==null?void 0:J._getGlobalPcbPositionBeforeLayout())??{x:0,y:0}}_getPcbCircuitJsonBounds(){if(!this.pcb_port_id)return super._getPcbCircuitJsonBounds();const{db:J}=this.root,VV=J.pcb_port.get(this.pcb_port_id);return{center:{x:VV.x,y:VV.y},bounds:{left:0,top:0,right:0,bottom:0},width:0,height:0}}_getGlobalPcbPositionAfterLayout(){return this._getPcbCircuitJsonBounds().center}_getGlobalSchematicPositionBeforeLayout(){var RV,UV;const J=(RV=this.parent)==null?void 0:RV.getSchematicSymbol();if(J&&this.schematicSymbolPortDef){const ZV=compose(this.parent.computeSchematicGlobalTransform(),translate(-J.center.x,-J.center.y));return applyToPoint(ZV,this.schematicSymbolPortDef)}const VV=(UV=this==null?void 0:this.parent)==null?void 0:UV._getSchematicBoxDimensions();if(VV&&this.props.pinNumber!==void 0){const ZV=VV.getPortPositionByPinNumber(this.props.pinNumber);return ZV?applyToPoint(this.parent.computeSchematicGlobalTransform(),ZV):{x:0,y:0}}return{x:0,y:0}}_getGlobalSchematicPositionAfterLayout(){const{db:J}=this.root;if(!this.schematic_port_id)throw new Error("Can't get schematic port position after layout, no schematic_port_id");const VV=J.schematic_port.get(this.schematic_port_id);if(!VV)throw new Error(`Schematic port not found when trying to get post-layout position: ${this.schematic_port_id}`);return VV.center}registerMatch(J){this.matchedComponents.push(J)}getNameAndAliases(){const{_parsedProps:J}=this;return Array.from(new Set([...J.aliases??[],...J.name?[J.name]:[],...typeof J.pinNumber=="number"?[`pin${J.pinNumber}`,J.pinNumber.toString()]:[],...this.externallyAddedAliases??[]]))}isMatchingPort(J){return this.isMatchingAnyOf(J.getNameAndAliases())}getPortSelector(){var J;return`.${(J=this.parent)==null?void 0:J.props.name} > port.${this.props.name}`}getAvailablePcbLayers(){return Array.from(new Set(this.matchedComponents.flatMap(J=>J.getAvailablePcbLayers())))}_getDirectlyConnectedTraces(){return this.getSubcircuit().selectAll("trace").filter(RV=>RV._isExplicitlyConnectedToPort(this))}doInitialSourceRender(){var ZV;const{db:J}=this.root,{_parsedProps:VV}=this,RV=this.getNameAndAliases(),UV=J.source_port.insert({name:VV.name,pin_number:VV.pinNumber,port_hints:RV,source_component_id:(ZV=this.parent)==null?void 0:ZV.source_component_id});this.source_port_id=UV.source_port_id}doInitialSourceParentAttachment(){var VV,RV,UV,ZV;const{db:J}=this.root;if(!((VV=this.parent)!=null&&VV.source_component_id))throw new Error(`${this.getString()} has no parent source component (parent: ${(RV=this.parent)==null?void 0:RV.getString()})`);J.source_port.update(this.source_port_id,{source_component_id:(UV=this.parent)==null?void 0:UV.source_component_id}),this.source_component_id=(ZV=this.parent)==null?void 0:ZV.source_component_id}doInitialPcbPortRender(){var ZV,WV,IV,dV;if((ZV=this.root)!=null&&ZV.pcbDisabled)return;const{db:J}=this.root,{matchedComponents:VV}=this;if(!((WV=this.parent)!=null&&WV.pcb_component_id))throw new Error(`${this.getString()} has no parent pcb component, cannot render pcb_port (parent: ${(IV=this.parent)==null?void 0:IV.getString()})`);const RV=VV.filter(CV=>CV.isPcbPrimitive);if(RV.length===0)return;let UV=null;if(RV.length===1&&(UV=RV[0]._getPcbCircuitJsonBounds().center),RV.length>1){if(!areAllPcbPrimitivesOverlapping(RV))throw new Error(`${this.getString()} has multiple non-overlapping pcb matches, unclear how to place pcb_port: ${RV.map(CV=>CV.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)`);UV=getCenterOfPcbPrimitives(RV)}if(UV){const CV=J.pcb_port.insert({pcb_component_id:(dV=this.parent)==null?void 0:dV.pcb_component_id,layers:this.getAvailablePcbLayers(),...UV,source_port_id:this.source_port_id});this.pcb_port_id=CV.pcb_port_id}else{const CV=RV[0];throw new Error(`${CV.getString()} does not have a center or _getGlobalPcbPositionBeforeLayout method (needed for pcb_port placement)`)}}doInitialSchematicPortRender(){var NV;const{db:J}=this.root,{_parsedProps:VV}=this,RV=this.getPrimitiveContainer();if(!RV)return;const UV=RV._getGlobalSchematicPositionBeforeLayout(),ZV=this._getGlobalSchematicPositionBeforeLayout();let WV=null;const IV=RV._getSchematicBoxDimensions();IV&&VV.pinNumber!==void 0&&(WV=IV.getPortPositionByPinNumber(VV.pinNumber)),this.getSubcircuit().props._schDebugObjectsEnabled&&J.schematic_debug_object.insert({shape:"rect",center:ZV,size:{width:.1,height:.1},label:"obstacle"}),WV!=null&&WV.side?this.facingDirection={left:"left",right:"right",top:"up",bottom:"down"}[WV.side]:this.facingDirection=getRelativeDirection(UV,ZV);const dV=J.source_port.get(this.source_port_id);let CV;for(const eV of(dV==null?void 0:dV.port_hints)??[])eV.match(/^(pin)?\d+$/)||(CV=eV);const FV=J.schematic_port.insert({schematic_component_id:(NV=this.parent)==null?void 0:NV.schematic_component_id,center:ZV,source_port_id:this.source_port_id,facing_direction:this.facingDirection,distance_from_component_edge:.4,side_of_component:WV==null?void 0:WV.side,pin_number:VV.pinNumber,true_ccw_index:WV==null?void 0:WV.trueIndex,display_pin_label:CV});this.schematic_port_id=FV.schematic_port_id}_setPositionFromLayout(J){const{db:VV}=this.root;this.pcb_port_id&&VV.pcb_port.update(this.pcb_port_id,{x:J.x,y:J.y})}_hasMatchedPcbPrimitive(){return this.matchedComponents.some(J=>J.isPcbPrimitive)}},getPinNumberFromLabels=lV=>{const J=lV.find(VV=>/^(pin)?\d+$/.test(VV));return J?Number.parseInt(J.replace(/^pin/,"")):null};function getPortFromHints(lV){const J=getPinNumberFromLabels(lV);return J?new Port({pinNumber:J,aliases:lV.filter(VV=>VV.toString()!==J.toString()&&VV!==`pin${J}`)}):null}var hasExplicitPinMapping=lV=>{for(const J of["leftSide","rightSide","topSide","bottomSide"])if(J in lV&&typeof lV[J]=="number")throw new Error(`A number was specified for "${J}", you probably meant to use "size" not "side"`);return"leftSide"in lV||"rightSide"in lV||"topSide"in lV||"bottomSide"in lV},getSizeOfSidesFromPortArrangement=lV=>{var ZV,WV,IV,dV;if(hasExplicitPinMapping(lV))return{leftSize:((ZV=lV.leftSide)==null?void 0:ZV.pins.length)??0,rightSize:((WV=lV.rightSide)==null?void 0:WV.pins.length)??0,topSize:((IV=lV.topSide)==null?void 0:IV.pins.length)??0,bottomSize:((dV=lV.bottomSide)==null?void 0:dV.pins.length)??0};const{leftSize:J=0,rightSize:VV=0,topSize:RV=0,bottomSize:UV=0}=lV;return{leftSize:J,rightSize:VV,topSize:RV,bottomSize:UV}};function isExplicitPinMappingArrangement(lV){return lV.leftSide!==void 0}var getAllDimensionsForSchematicBox=lV=>{var aV,GV,YV,TV,iV,AV,SV,mV;const J=lV.portDistanceFromEdge??.4;let VV=lV.schPortArrangement?getSizeOfSidesFromPortArrangement(lV.schPortArrangement):null;const RV={left:0,right:0,top:0,bottom:0};let UV=lV.pinCount??null;if(UV===null)if(VV)UV=VV.leftSize+VV.rightSize+VV.topSize;else throw new Error("Could not determine pin count for the schematic box");if(UV&&!VV){const pV=Math.floor(UV/2);VV={leftSize:UV-pV,rightSize:pV,topSize:0,bottomSize:0}}VV||(VV={leftSize:0,rightSize:0,topSize:0,bottomSize:0});const ZV=({side:pV,sideIndex:HV,truePinIndex:BV})=>{var nl,dl,LV,OV;if(!lV.schPortArrangement||!isExplicitPinMappingArrangement(lV.schPortArrangement))return BV+1;const uV={left:"top-to-bottom",bottom:"left-to-right",right:"bottom-to-top",top:"right-to-left"}[pV],jV=((dl=(nl=lV.schPortArrangement)==null?void 0:nl[`${pV}Side`])==null?void 0:dl.direction)??uV,PV=(OV=(LV=lV.schPortArrangement)==null?void 0:LV[`${pV}Side`])==null?void 0:OV.pins;let Zl=HV;return jV!==uV&&(Zl=PV.length-HV-1),parsePinNumberFromLabelsOrThrow(PV[Zl],lV.pinLabels)},WV=[];let IV=0,dV=0;for(let pV=0;pV<VV.leftSize;pV++){const HV=ZV({side:"left",sideIndex:pV,truePinIndex:dV}),BV=((aV=lV.numericSchPinStyle)==null?void 0:aV[`pin${HV}`])??((GV=lV.numericSchPinStyle)==null?void 0:GV[HV]);BV!=null&&BV.topMargin&&(IV+=BV.topMargin),WV.push({trueIndex:dV,pinNumber:HV,side:"left",distanceFromOrthogonalEdge:IV}),BV!=null&&BV.bottomMargin&&(IV+=BV.bottomMargin),pV===VV.leftSize-1?RV.left=IV:IV+=lV.schPinSpacing,dV++}IV=0;for(let pV=0;pV<VV.bottomSize;pV++){const HV=ZV({side:"bottom",sideIndex:pV,truePinIndex:dV}),BV=((YV=lV.numericSchPinStyle)==null?void 0:YV[`pin${HV}`])??((TV=lV.numericSchPinStyle)==null?void 0:TV[HV]);BV!=null&&BV.leftMargin&&(IV+=BV.leftMargin),WV.push({trueIndex:dV,pinNumber:HV,side:"bottom",distanceFromOrthogonalEdge:IV}),BV!=null&&BV.rightMargin&&(IV+=BV.rightMargin),pV===VV.bottomSize-1?RV.bottom=IV:IV+=lV.schPinSpacing,dV++}IV=0;for(let pV=0;pV<VV.rightSize;pV++){const HV=ZV({side:"right",sideIndex:pV,truePinIndex:dV}),BV=((iV=lV.numericSchPinStyle)==null?void 0:iV[`pin${HV}`])??((AV=lV.numericSchPinStyle)==null?void 0:AV[HV]);BV!=null&&BV.bottomMargin&&(IV+=BV.bottomMargin),WV.push({trueIndex:dV,pinNumber:HV,side:"right",distanceFromOrthogonalEdge:IV}),BV!=null&&BV.topMargin&&(IV+=BV.topMargin),pV===VV.rightSize-1?RV.right=IV:IV+=lV.schPinSpacing,dV++}IV=0;for(let pV=0;pV<VV.topSize;pV++){const HV=ZV({side:"top",sideIndex:pV,truePinIndex:dV}),BV=((SV=lV.numericSchPinStyle)==null?void 0:SV[`pin${HV}`])??((mV=lV.numericSchPinStyle)==null?void 0:mV[HV]);BV!=null&&BV.rightMargin&&(IV+=BV.rightMargin),WV.push({trueIndex:dV,pinNumber:HV,side:"top",distanceFromOrthogonalEdge:IV}),BV!=null&&BV.leftMargin&&(IV+=BV.leftMargin),pV===VV.topSize-1?RV.top=IV:IV+=lV.schPinSpacing,dV++}let CV=lV.schWidth;CV||(CV=Math.max(RV.top+lV.schPinSpacing*2,RV.bottom+lV.schPinSpacing*2));const FV=lV.pinLabels?Math.max(...Object.values(lV.pinLabels).map(pV=>pV.length*.1)):0,NV=FV>0?1.1:0;CV=Math.max(CV,FV+NV);let eV=lV.schHeight;eV||(eV=Math.max(RV.left+lV.schPinSpacing*2,RV.right+lV.schPinSpacing*2));const gV={left:{x:-CV/2-J,y:RV.left/2},bottom:{x:-RV.bottom/2,y:-eV/2-J},right:{x:CV/2+J,y:-RV.right/2},top:{x:RV.top/2,y:eV/2+J}},nV={left:{x:0,y:-1},right:{x:0,y:1},top:{x:-1,y:0},bottom:{x:1,y:0}},JV=WV.map(pV=>{const{distanceFromOrthogonalEdge:HV,side:BV}=pV,uV=gV[BV],jV=nV[BV];return{x:uV.x+HV*jV.x,y:uV.y+HV*jV.y,...pV}});return{getPortPositionByPinNumber(pV){const HV=JV.find(BV=>BV.pinNumber.toString()===pV.toString());return HV||null},getSize(){return{width:CV,height:eV}},pinCount:UV}},debug$6=Debug$1("tscircuit:core:footprint"),Footprint=class extends PrimitiveComponent{get config(){return{componentName:"Footprint",zodProps:footprintProps}}doInitialPcbFootprintLayout(){var NV,eV,gV,nV,JV;if((NV=this.root)!=null&&NV.pcbDisabled)return;const lV=this.children.filter(aV=>aV.componentName==="Constraint");if(lV.length===0)return;const{isFlipped:J}=this._getPcbPrimitiveFlippedHelpers(),VV=aV=>J&&"left"in aV&&"right"in aV?{...aV,left:aV.right,right:aV.left}:aV,RV=lV.flatMap(aV=>aV._getAllReferencedComponents().componentsWithSelectors).map(({component:aV,selector:GV,componentSelector:YV,edge:TV})=>({component:aV,selector:GV,componentSelector:YV,edge:TV,bounds:aV._getPcbCircuitJsonBounds()}));if(RV.some(aV=>aV.edge))throw new Error("edge constraints not implemented yet for footprint layout, contributions welcome!");function UV(aV){return RV.find(({selector:GV})=>GV===aV)}const ZV=new Solver,WV={};function IV(aV){return aV in WV||(WV[aV]=new Variable(aV),ZV.addEditVariable(WV[aV],Strength.weak)),WV[aV]}for(const{selector:aV,bounds:GV}of RV){const YV=IV(`${aV}_x`),TV=IV(`${aV}_y`);ZV.suggestValue(YV,GV.center.x),ZV.suggestValue(TV,GV.center.y)}for(const aV of lV){const GV=aV._parsedProps;if("xDist"in GV){const{xDist:YV,left:TV,right:iV,edgeToEdge:AV,centerToCenter:SV}=VV(GV),mV=IV(`${TV}_x`),pV=IV(`${iV}_x`),HV=(eV=UV(TV))==null?void 0:eV.bounds,BV=(gV=UV(iV))==null?void 0:gV.bounds;if(SV){const uV=new Expression(pV,[-1,mV]);ZV.addConstraint(new Constraint(uV,Operator.Eq,GV.xDist,Strength.required))}else if(AV){const uV=new Expression(pV,-BV.width/2,[-1,mV],-HV.width/2);ZV.addConstraint(new Constraint(uV,Operator.Eq,GV.xDist,Strength.required))}}else if("yDist"in GV){const{yDist:YV,top:TV,bottom:iV,edgeToEdge:AV,centerToCenter:SV}=GV,mV=IV(`${TV}_y`),pV=IV(`${iV}_y`),HV=(nV=UV(TV))==null?void 0:nV.bounds,BV=(JV=UV(iV))==null?void 0:JV.bounds;if(SV){const uV=new Expression(mV,[-1,pV]);ZV.addConstraint(new Constraint(uV,Operator.Eq,GV.yDist,Strength.required))}else if(AV){const uV=new Expression(mV,HV.height/2,[-1,pV],-BV.height/2);ZV.addConstraint(new Constraint(uV,Operator.Eq,GV.yDist,Strength.required))}}else if("sameY"in GV){const{for:YV}=GV;if(YV.length<2)continue;const TV=YV.map(AV=>IV(`${AV}_y`)),iV=new Expression(...TV.slice(1));ZV.addConstraint(new Constraint(iV,Operator.Eq,TV[0],Strength.required))}else if("sameX"in GV){const{for:YV}=GV;if(YV.length<2)continue;const TV=YV.map(AV=>IV(`${AV}_x`)),iV=new Expression(...TV.slice(1));ZV.addConstraint(new Constraint(iV,Operator.Eq,TV[0],Strength.required))}}ZV.updateVariables(),debug$6.enabled&&(console.log("Solution to layout constraints:"),console.table(Object.entries(WV).map(([aV,GV])=>({var:aV,val:GV.value()}))));const dV={left:1/0,right:-1/0,top:-1/0,bottom:1/0};for(const{selector:aV,bounds:{width:GV,height:YV}}of RV){const TV=IV(`${aV}_x`),iV=IV(`${aV}_y`),AV=TV.value()-GV/2,SV=TV.value()+GV/2,mV=iV.value()+YV/2,pV=iV.value()-YV/2;dV.left=Math.min(dV.left,AV),dV.right=Math.max(dV.right,SV),dV.top=Math.max(dV.top,mV),dV.bottom=Math.min(dV.bottom,pV)}const CV={x:-(dV.right+dV.left)/2,y:-(dV.top+dV.bottom)/2},FV=this.getPrimitiveContainer()._getGlobalPcbPositionBeforeLayout();CV.x+=FV.x,CV.y+=FV.y;for(const{component:aV,selector:GV}of RV){const YV=IV(`${GV}_x`),TV=IV(`${GV}_y`);aV._setPositionFromLayout({x:YV.value()+CV.x,y:TV.value()+CV.y})}}},getNumericSchPinStyle=(lV,J)=>{if(!lV)return;const VV={};for(const[RV,UV]of Object.entries(lV)){const ZV=parsePinNumberFromLabelsOrThrow(RV,J);VV[`pin${ZV}`]={...VV[`pin${ZV}`],...UV}}return VV},debug2$1=Debug$1("tscircuit:core"),rotation3=z$1.object({x:rotation,y:rotation,z:rotation}),NormalComponent=class extends PrimitiveComponent{constructor(J){super(J);kW(this,"reactSubtrees",[]);kW(this,"_impliedFootprint");kW(this,"isPrimitiveContainer",!0);kW(this,"_asyncSupplierPartNumbers");kW(this,"pcb_missing_footprint_error_id");this._addChildrenFromStringFootprint(),this.initPorts()}initPorts(J={}){var WV,IV,dV,CV,FV,NV,eV,gV,nV,JV,aV,GV,YV,TV;if((WV=this.root)!=null&&WV.schematicDisabled)return;const{config:VV}=this,RV=[],UV=this._parsedProps.schPortArrangement;if(UV&&!this._parsedProps.pinLabels){for(const SV in UV){const mV=UV[SV].pins;if(Array.isArray(mV))for(const pV of mV){const HV=parsePinNumberFromLabelsOrThrow(pV,this._parsedProps.pinLabels);RV.push(new Port({pinNumber:HV,aliases:((IV=J.additionalAliases)==null?void 0:IV[`pin${HV}`])??[]},{originDescription:`schPortArrangement:${SV}`}))}}const iV=["left","right","top","bottom"];let AV=1;for(const SV of iV){const mV=UV[`${SV}Size`];for(let pV=0;pV<mV;pV++)RV.push(new Port({pinNumber:AV++,aliases:((dV=J.additionalAliases)==null?void 0:dV[`pin${AV}`])??[]},{originDescription:`schPortArrangement:${SV}`}))}}const ZV=this._parsedProps.pinLabels;if(ZV)for(let[iV,AV]of Object.entries(ZV)){iV=iV.replace("pin","");let SV=RV.find(HV=>HV._parsedProps.pinNumber===Number(iV));const mV=Array.isArray(AV)?AV[0]:AV,pV=Array.isArray(AV)?AV.slice(1):[];SV?(SV.externallyAddedAliases.push(mV,...pV),SV.props.name=mV):(SV=new Port({pinNumber:parseInt(iV),name:mV,aliases:[...pV,...((CV=J.additionalAliases)==null?void 0:CV[`pin${parseInt(iV)}`])??[]]},{originDescription:`pinLabels:pin${iV}`}),RV.push(SV))}if(VV.schematicSymbolName){const iV=symbols_index_default[this._getSchematicSymbolNameOrThrow()];if(!iV)return;for(const AV of iV.ports){const SV=getPinNumberFromLabels(AV.labels);if(!SV)continue;const mV=getPortFromHints(AV.labels.concat(((FV=J.additionalAliases)==null?void 0:FV[`pin${SV}`])??[]));mV&&(mV.originDescription=`schematicSymbol:labels[0]:${AV.labels[0]}`,mV.schematicSymbolPortDef=AV,RV.push(mV))}this.addAll(RV);return}if(!this._parsedProps.schPortArrangement){const iV=this.getPortsFromFootprint();for(const AV of iV)RV.some(SV=>SV.isMatchingAnyOf(AV.getNameAndAliases()))||RV.push(AV)}for(let iV=1;iV<=this._getPinCount();iV++){if(!this._parsedProps.schPortArrangement||RV.find(SV=>SV._parsedProps.pinNumber===iV))continue;let AV=[...((eV=(NV=this._parsedProps.schPortArrangement)==null?void 0:NV.leftSide)==null?void 0:eV.pins)??[],...((nV=(gV=this._parsedProps.schPortArrangement)==null?void 0:gV.rightSide)==null?void 0:nV.pins)??[],...((aV=(JV=this._parsedProps.schPortArrangement)==null?void 0:JV.topSide)==null?void 0:aV.pins)??[],...((YV=(GV=this._parsedProps.schPortArrangement)==null?void 0:GV.bottomSide)==null?void 0:YV.pins)??[]].map(SV=>parsePinNumberFromLabelsOrThrow(SV,this._parsedProps.pinLabels));["leftSize","rightSize","topSize","bottomSize","leftPinCount","rightPinCount","topPinCount","bottomPinCount"].some(SV=>SV in this._parsedProps.schPortArrangement)&&(AV=Array.from({length:this._getPinCount()},(SV,mV)=>mV+1)),AV.includes(iV)&&RV.push(new Port({pinNumber:iV,aliases:((TV=J.additionalAliases)==null?void 0:TV[`pin${iV}`])??[]},{originDescription:`notOtherwiseAddedButDeducedFromPinCount:${iV}`}))}RV.length>0&&this.addAll(RV)}_getImpliedFootprintString(){return null}_addChildrenFromStringFootprint(){var VV;let{footprint:J}=this.props;if(J??(J=(VV=this._getImpliedFootprintString)==null?void 0:VV.call(this)),!!J&&typeof J=="string"){const RV=fp$1.string(J).soup(),UV=createComponentsFromSoup(RV);this.addAll(UV)}}get portMap(){return new Proxy({},{get:(J,VV)=>{const RV=this.children.find(UV=>UV.componentName==="Port"&&UV.isMatchingNameOrAlias(VV));if(!RV)throw new Error(`There was an issue finding the port "${VV.toString()}" inside of a ${this.componentName} component with name: "${this.props.name}". This is a bug in @tscircuit/core`);return RV}})}getInstanceForReactElement(J){for(const VV of this.reactSubtrees)if(VV.element===J)return VV.component;return null}doInitialSourceRender(){const J=this.config.sourceFtype;if(!J)return;const{db:VV}=this.root,{_parsedProps:RV}=this,UV=VV.source_component.insert({ftype:J,name:RV.name,manufacturer_part_number:RV.manufacturerPartNumber??RV.mfn,supplier_part_numbers:RV.supplierPartNumbers});this.source_component_id=UV.source_component_id}doInitialSchematicComponentRender(){var RV;if((RV=this.root)!=null&&RV.schematicDisabled)return;const{schematicSymbolName:J}=this.config;if(J)return this._doInitialSchematicComponentRenderWithSymbol();if(this._getSchematicBoxDimensions())return this._doInitialSchematicComponentRenderWithSchematicBoxDimensions()}_getSchematicSymbolDisplayValue(){}_doInitialSchematicComponentRenderWithSymbol(){var WV;if((WV=this.root)!=null&&WV.schematicDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this,RV=this._getSchematicSymbolNameOrThrow(),UV=symbols_index_default[RV],ZV=this._getGlobalSchematicPositionBeforeLayout();if(UV){const IV=J.schematic_component.insert({center:ZV,rotation:VV.schRotation??0,size:UV.size,source_component_id:this.source_component_id,symbol_name:RV,symbol_display_value:this._getSchematicSymbolDisplayValue()});this.schematic_component_id=IV.schematic_component_id}}_doInitialSchematicComponentRenderWithSchematicBoxDimensions(){var FV,NV,eV;if((FV=this.root)!=null&&FV.schematicDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this,RV=this._getSchematicBoxDimensions(),UV={};if(Array.isArray(VV.pinLabels))VV.pinLabels.forEach((gV,nV)=>{UV[String(nV+1)]=gV});else for(const[gV,nV]of Object.entries(VV.pinLabels??{}))UV[gV]=Array.isArray(nV)?nV[0]:nV;const ZV=this._getGlobalSchematicPositionBeforeLayout(),WV=J.schematic_component.insert({center:ZV,rotation:VV.schRotation??0,size:RV.getSize(),port_arrangement:underscorifyPortArrangement(VV.schPortArrangement),pin_spacing:VV.schPinSpacing??.2,pin_styles:underscorifyPinStyles(VV.schPinStyle,VV.pinLabels),port_labels:UV,source_component_id:this.source_component_id}),IV=((NV=VV.schPortArrangement)==null?void 0:NV.topSide)!==void 0||((eV=VV.schPortArrangement)==null?void 0:eV.bottomSide)!==void 0,dV=RV==null?void 0:RV.getSize().width,CV=RV==null?void 0:RV.getSize().height;J.schematic_text.insert({text:VV.manufacturerPartNumber??"",schematic_component_id:WV.schematic_component_id,anchor:"left",rotation:0,position:{x:IV?ZV.x+(dV??0)/2+.1:ZV.x-(dV??0)/2,y:IV?ZV.y+(CV??0)/2+.35:ZV.y-(CV??0)/2-.13},color:"#006464"}),J.schematic_text.insert({text:VV.name??"",schematic_component_id:WV.schematic_component_id,anchor:"left",rotation:0,position:{x:IV?ZV.x+(dV??0)/2+.1:ZV.x-(dV??0)/2,y:IV?ZV.y+(CV??0)/2+.55:ZV.y+(CV??0)/2+.13},color:"#006464"}),this.schematic_component_id=WV.schematic_component_id}doInitialPcbComponentRender(){var ZV;if((ZV=this.root)!=null&&ZV.pcbDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this,RV=J.pcb_component.insert({center:this._getGlobalPcbPositionBeforeLayout(),width:0,height:0,layer:VV.layer??"top",rotation:VV.pcbRotation??0,source_component_id:this.source_component_id});if(!VV.footprint&&!this.isGroup){const WV=J.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=WV.pcb_missing_footprint_error_id}this.pcb_component_id=RV.pcb_component_id;const UV=this.getSubcircuit()._getPcbManualPlacementForComponent(this);this.props.pcbX!==void 0&&this.props.pcbY!==void 0&&UV&&this.renderError({type:"pcb_manual_edit_conflict_error",message:`${this.getString()} has both manual placement and explicit 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})}doInitialPcbComponentSizeCalculation(){var UV;if((UV=this.root)!=null&&UV.pcbDisabled||!this.pcb_component_id)return;const{db:J}=this.root,VV=getBoundsOfPcbComponents(this.children);if(VV.width===0||VV.height===0)return;const RV={x:(VV.minX+VV.maxX)/2,y:(VV.minY+VV.maxY)/2};J.pcb_component.update(this.pcb_component_id,{center:RV,width:VV.width,height:VV.height})}_renderReactSubtree(J){return{element:J,component:createInstanceFromReactElement(J)}}doInitialInitializePortsFromChildren(){this.initPorts()}doInitialReactSubtreesRender(){if(reactExports.isValidElement(this.props.footprint)){if(this.reactSubtrees.some(VV=>VV.element===this.props.footprint))return;const J=this._renderReactSubtree(this.props.footprint);this.reactSubtrees.push(J),this.add(J.component)}}_hasExistingPortExactly(J){return this.children.filter(RV=>RV.componentName==="Port").some(RV=>{const UV=J.getNameAndAliases(),ZV=RV.getNameAndAliases();return UV.length===ZV.length&&UV.every(WV=>ZV.includes(WV))})}add(J){let VV;if(reactExports.isValidElement(J)){const RV=this._renderReactSubtree(J);this.reactSubtrees.push(RV),VV=RV.component}else VV=J;if(VV.componentName==="Port"){if(this._hasExistingPortExactly(VV))return;const UV=this.children.filter(ZV=>ZV.componentName==="Port").find(ZV=>ZV.isMatchingAnyOf(VV.getNameAndAliases()));UV&&debug2$1(`Similar ports added. Port 1: ${UV}, Port 2: ${VV}`)}super.add(VV)}getPortsFromFootprint(){let{footprint:J}=this.props;if((!J||reactExports.isValidElement(J))&&(J=this.children.find(RV=>RV.componentName==="Footprint")),typeof J=="string"){const RV=fp$1.string(J).soup(),UV=[];for(const ZV of RV)if("port_hints"in ZV&&ZV.port_hints){const WV=getPortFromHints(ZV.port_hints);if(!WV)continue;WV.originDescription=`footprint:string:${J}:port_hints[0]:${ZV.port_hints[0]}`,UV.push(WV)}return UV}if(!reactExports.isValidElement(J)&&J&&J.componentName==="Footprint"){const RV=J;let UV=1;const ZV=[];for(const WV of RV.children){if(!WV.props.portHints)continue;let IV=WV.props.portHints;IV.some(FV=>FV.startsWith("pin"))||(IV=[...IV,`pin${UV}`]),UV++;const CV=getPortFromHints(IV);CV&&(CV.originDescription=`footprint:${J}`,ZV.push(CV))}return ZV}const VV=[];if(!J){for(const RV of this.children)if(RV.props.portHints&&RV.isPcbPrimitive){const UV=getPortFromHints(RV.props.portHints);UV&&VV.push(UV)}}return VV}getPortsFromSchematicSymbol(){var UV;if((UV=this.root)!=null&&UV.schematicDisabled)return[];const{config:J}=this;if(!J.schematicSymbolName)return[];const VV=symbols_index_default[J.schematicSymbolName];if(!VV)return[];const RV=[];for(const ZV of VV.ports){const WV=getPortFromHints(ZV.labels);WV&&(WV.schematicSymbolPortDef=ZV,RV.push(WV))}return RV}_createNetsFromProps(J){createNetsFromProps(this,J)}doInitialPortDiscovery(){const{_parsedProps:J}=this;let VV=[];J.schPortArrangement||(VV=[...this.getPortsFromFootprint(),...this.getPortsFromSchematicSymbol()]);const RV=this.children.filter(UV=>UV.componentName==="Port");for(const UV of VV){const ZV=RV.find(WV=>WV.isMatchingAnyOf(UV.getNameAndAliases()));if(ZV){!ZV.schematicSymbolPortDef&&UV.schematicSymbolPortDef&&(ZV.schematicSymbolPortDef=UV.schematicSymbolPortDef);continue}RV.push(UV),this.add(UV)}}_getPcbCircuitJsonBounds(){const{db:J}=this.root;if(!this.pcb_component_id)return super._getPcbCircuitJsonBounds();const VV=J.pcb_component.get(this.pcb_component_id);return{center:{x:VV.center.x,y:VV.center.y},bounds:{left:VV.center.x-VV.width/2,top:VV.center.y-VV.height/2,right:VV.center.x+VV.width/2,bottom:VV.center.y+VV.height/2},width:VV.width,height:VV.height}}_getPinCount(){const J=this._getSchematicPortArrangement();if(J){if(!isExplicitPinMappingArrangement(J))return(J.leftSize??J.leftPinCount??0)+(J.rightSize??J.rightPinCount??0)+(J.topSize??J.topPinCount??0)+(J.bottomSize??J.bottomPinCount??0);const{leftSide:RV,rightSide:UV,topSide:ZV,bottomSide:WV}=J;return Math.max(...(RV==null?void 0:RV.pins)??[],...(UV==null?void 0:UV.pins)??[],...(ZV==null?void 0:ZV.pins)??[],...(WV==null?void 0:WV.pins)??[])}return this.getPortsFromFootprint().length}_getSchematicPortArrangement(){return this._parsedProps.schPortArrangement}_getSchematicBoxDimensions(){if(this.getSchematicSymbol()||!this.config.shouldRenderAsSchematicBox)return null;const{_parsedProps:J}=this,VV=this._getPinCount(),RV=J.schPinSpacing??.2;return getAllDimensionsForSchematicBox({schWidth:J.schWidth,schHeight:J.schHeight,schPinSpacing:RV,numericSchPinStyle:getNumericSchPinStyle(J.schPinStyle,J.pinLabels),pinCount:VV,schPortArrangement:this._getSchematicPortArrangement(),pinLabels:J.pinLabels})}doInitialCadModelRender(){var CV;const{db:J}=this.root,{boardThickness:VV=0}=((CV=this.root)==null?void 0:CV._getBoard())??{},RV=this._parsedProps.cadModel;if(!this.pcb_component_id||!RV&&!this.props.footprint)return;const UV=this._getPcbCircuitJsonBounds(),ZV=J.pcb_component.get(this.pcb_component_id);if(typeof RV=="string")throw new Error("String cadModel not yet implemented");const WV=rotation3.parse({x:0,y:0,z:typeof(RV==null?void 0:RV.rotationOffset)=="number"?RV.rotationOffset:0,...typeof(RV==null?void 0:RV.rotationOffset)=="object"?RV.rotationOffset??{}:{}}),IV=point3$1.parse({x:0,y:0,z:0,...typeof(RV==null?void 0:RV.positionOffset)=="object"?RV.positionOffset:{}}),dV=this.props.layer==="bottom"?"bottom":"top";J.cad_component.insert({position:{x:UV.center.x+IV.x,y:UV.center.y+IV.y,z:(dV==="bottom"?-VV/2:VV/2)+IV.z},rotation:{x:WV.x,y:(dV==="top"?0:180)+WV.y,z:((ZV==null?void 0:ZV.rotation)??0)+(dV==="bottom"?180:0)+WV.z},pcb_component_id:this.pcb_component_id,source_component_id:this.source_component_id,model_stl_url:"stlUrl"in(RV??{})?this._addCachebustToModelUrl(RV.stlUrl):void 0,model_obj_url:"objUrl"in(RV??{})?this._addCachebustToModelUrl(RV.objUrl):void 0,model_jscad:"jscad"in(RV??{})?RV.jscad:void 0,footprinter_string:typeof this.props.footprint=="string"&&!RV?this.props.footprint:void 0})}_addCachebustToModelUrl(J){var RV;if(!J||!J.includes("modelcdn.tscircuit.com"))return J;const VV=((RV=this.root)==null?void 0:RV.getClientOrigin())??"";return`${J}${J.includes("?")?"&":"?"}cachebust_origin=${encodeURIComponent(VV)}`}doInitialPartsEngineRender(){const{partsEngine:J}=this.getSubcircuit()._parsedProps;if(!J)return;const{db:VV}=this.root,RV=VV.source_component.get(this.source_component_id);if(!RV||RV.supplier_part_numbers)return;let UV;this.props.footprint&&typeof this.props.footprint=="string"&&(UV=this.props.footprint);const ZV=J.findPart({sourceComponent:RV,footprinterString:UV});if(!(ZV instanceof Promise)){VV.source_component.update(this.source_component_id,{supplier_part_numbers:ZV});return}this._queueAsyncEffect("get-supplier-part-numbers",async()=>{this._asyncSupplierPartNumbers=await ZV,this._markDirty("PartsEngineRender")})}updatePartsEngineRender(){const{db:J}=this.root,VV=J.source_component.get(this.source_component_id);if(VV&&!VV.supplier_part_numbers&&this._asyncSupplierPartNumbers){J.source_component.update(this.source_component_id,{supplier_part_numbers:this._asyncSupplierPartNumbers});return}}},TraceHint=class extends PrimitiveComponent{constructor(){super(...arguments);kW(this,"matchedPort",null)}get config(){return{componentName:"TraceHint",zodProps:traceHintProps}}doInitialPortMatching(){this.root;const{_parsedProps:J,parent:VV}=this;if(!VV)return;if(VV.componentName==="Trace"){this.renderError(`Port inference inside trace is not yet supported (${this})`);return}if(!VV)throw new Error("TraceHint has no parent");if(!J.for){this.renderError(`TraceHint has no for property (${this})`);return}const RV=VV.selectOne(J.for,{type:"port"});RV||this.renderError(`${this} could not find port for selector "${J.for}"`),this.matchedPort=RV,RV.registerMatch(this)}getPcbRouteHints(){const{_parsedProps:J}=this,VV=J.offset?[J.offset]:J.offsets;if(!VV)return[];const RV=this._computePcbGlobalTransformBeforeLayout();return VV.map(UV=>({...applyToPoint(RV,UV),via:UV.via,to_layer:UV.to_layer,trace_width:UV.trace_width}))}doInitialPcbTraceHintRender(){var VV,RV,UV;if((VV=this.root)!=null&&VV.pcbDisabled)return;const{db:J}=this.root;J.pcb_trace_hint.insert({pcb_component_id:(RV=this.matchedPort)==null?void 0:RV.pcb_component_id,pcb_port_id:(UV=this.matchedPort)==null?void 0:UV.pcb_port_id,route:this.getPcbRouteHints()})}},getSimpleRouteJsonFromTracesAndDb=({db:lV,traces:J,minTraceWidth:VV=.1})=>{const UV=getObstaclesFromSoup([...lV.pcb_component.list(),...lV.pcb_smtpad.list(),...lV.pcb_plated_hole.list()]).flatMap(IV=>[{x:IV.center.x-IV.width/2,y:IV.center.y-IV.height/2},{x:IV.center.x+IV.width/2,y:IV.center.y+IV.height/2}]),ZV={minX:Math.min(...UV.map(IV=>IV.x))-1,maxX:Math.max(...UV.map(IV=>IV.x))+1,minY:Math.min(...UV.map(IV=>IV.y))-1,maxY:Math.max(...UV.map(IV=>IV.y))+1},WV=J.map(IV=>{const dV=IV._findConnectedPorts();return!dV.allPortsFound||dV.ports.length<2?null:{name:IV.source_trace_id??"",pointsToConnect:dV.ports.map(CV=>{const FV=CV._getGlobalPcbPositionBeforeLayout();return{x:FV.x,y:FV.y,layer:CV.getAvailablePcbLayers()[0]??"top"}})}}).filter(IV=>IV!==null);return{bounds:ZV,obstacles:[],connections:WV,layerCount:2,minTraceWidth:VV}},Group$1=class extends NormalComponent{constructor(){super(...arguments);kW(this,"_asyncAutoroutingResult",null)}get config(){return{zodProps:groupProps,componentName:"Group"}}doInitialCreateTraceHintsFromProps(){var ZV;const{_parsedProps:VV}=this;this.root;const RV=VV;if(!this.isSubcircuit)return;const UV=(ZV=RV.layout)==null?void 0:ZV.manual_trace_hints;if(UV)for(const WV of UV)this.add(new TraceHint({for:WV.pcb_port_selector,offsets:WV.offsets}))}_getSimpleRouteJsonFromPcbTraces(){const VV=this.selectAll("trace"),{db:RV}=this.root;return getSimpleRouteJsonFromTracesAndDb({db:RV,traces:VV,minTraceWidth:this._parsedProps.minTraceWidth??.1})}doInitialSourceAddConnectivityMapKey(){if(!this.isSubcircuit)return;const{db:VV}=this.root,RV=this.selectAll("trace"),UV=new ConnectivityMap$1({});UV.addConnections(RV.map(ZV=>{const WV=VV.source_trace.get(ZV.source_trace_id);return WV?[WV.source_trace_id,...WV.connected_source_port_ids,...WV.connected_source_net_ids]:null}).filter(ZV=>ZV!==null));for(const ZV of RV){if(!ZV.source_trace_id)continue;const WV=UV.getNetConnectedToId(ZV.source_trace_id);if(!WV)continue;const{name:IV}=this._parsedProps;ZV.subcircuit_connectivity_map_key=`${IV??`unnamedsubcircuit${this._renderId}`}_${WV}`,VV.source_trace.update(ZV.source_trace_id,{subcircuit_connectivity_map_key:ZV.subcircuit_connectivity_map_key})}}doInitialPcbTraceRender(){var WV,IV,dV;if((WV=this.root)!=null&&WV.pcbDisabled||this._shouldUseTraceByTraceRouting())return;const VV=((IV=this.props.autorouter)==null?void 0:IV.serverUrl)??"https://registry-api.tscircuit.com",RV=((dV=this.props.autorouter)==null?void 0:dV.serverMode)??"job",UV=Debug$1("tscircuit:core:autorouting"),ZV=(CV,FV)=>(UV("fetching",CV),fetch(CV,FV));this._queueAsyncEffect("make-http-autorouting-request",async()=>{var FV,NV;if(RV==="solve-endpoint"){if(((FV=this.props.autorouter)==null?void 0:FV.inputFormat)==="simplified"){const{autorouting_result:gV}=await ZV(`${VV}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_simple_route_json:this._getSimpleRouteJsonFromPcbTraces()}),headers:{"Content-Type":"application/json"}}).then(nV=>nV.json());this._asyncAutoroutingResult=gV,this._markDirty("PcbTraceRender");return}const{autorouting_result:eV}=await ZV(`${VV}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_circuit_json:this.root.db.toArray()}),headers:{"Content-Type":"application/json"}}).then(gV=>gV.json());this._asyncAutoroutingResult=eV,this._markDirty("PcbTraceRender");return}const{autorouting_job:CV}=await ZV(`${VV}/autorouting/jobs/create`,{method:"POST",body:JSON.stringify({input_circuit_json:this.root.db.toArray(),provider:"freerouting",autostart:!0,display_name:(NV=this.root)==null?void 0:NV.name}),headers:{"Content-Type":"application/json"}}).then(eV=>eV.json());for(;;){const{autorouting_job:eV}=await ZV(`${VV}/autorouting/jobs/get`,{method:"POST",body:JSON.stringify({autorouting_job_id:CV.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(gV=>gV.json());if(eV.is_finished){const{autorouting_job_output:gV}=await ZV(`${VV}/autorouting/jobs/get_output`,{method:"POST",body:JSON.stringify({autorouting_job_id:CV.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(nV=>nV.json());this._asyncAutoroutingResult={output_pcb_traces:gV.output_pcb_traces},this._markDirty("PcbTraceRender");break}if(eV.has_error)throw new Error(`Autorouting job failed: ${JSON.stringify(eV.error)}`);await new Promise(gV=>setTimeout(gV,100))}})}updatePcbTraceRender(){if(this._asyncAutoroutingResult&&!this._shouldUseTraceByTraceRouting()){if(this.root,this._asyncAutoroutingResult.output_simple_route_json){this._updatePcbTraceRenderFromSimpleRouteJson();return}if(this._asyncAutoroutingResult.output_pcb_traces){this._updatePcbTraceRenderFromPcbTraces();return}}}_updatePcbTraceRenderFromSimpleRouteJson(){const{db:VV}=this.root,{traces:RV}=this._asyncAutoroutingResult.output_simple_route_json;if(RV){this.selectAll("trace");for(const UV of RV)VV.pcb_trace.insert({route:UV.route})}}_updatePcbTraceRenderFromPcbTraces(){const{output_pcb_traces:VV}=this._asyncAutoroutingResult;if(!VV)return;const{db:RV}=this.root;for(const UV of VV)RV.pcb_trace.insert(UV)}doInitialSchematicLayout(){if(!this.isSubcircuit||!this._parsedProps.schAutoLayoutEnabled)return;const{db:RV}=this.root,UV=this.getDescendants(),ZV=[];for(const dV of UV)if("schematic_component_id"in dV){const CV=RV.schematic_component.get(dV.schematic_component_id);if(CV){const FV=RV.schematic_port.list().filter(NV=>NV.schematic_component_id===CV.schematic_component_id);ZV.push(...FV)}}const WV=convertSoupToScene(RV.toArray()),IV=ascendingCentralLrBug1(WV);mutateSoupForScene(RV.toArray(),IV)}_shouldUseTraceByTraceRouting(){const VV=this._parsedProps;return VV.autorouter==="auto-local"||VV.autorouter==="sequential-trace"?!0:!VV.autorouter}},Board=class extends Group$1{constructor(){super(...arguments);kW(this,"pcb_board_id",null)}get isSubcircuit(){return!0}get config(){return{componentName:"Board",zodProps:boardProps}}get boardThickness(){return 1.4}get allLayers(){return["top","bottom","inner1","inner2"]}doInitialPcbComponentRender(){var UV,ZV;if((UV=this.root)!=null&&UV.pcbDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this;if(!VV.width||!VV.height)throw new Error("Board width and height or an outline are required");const RV=J.pcb_board.insert({center:{x:(VV.pcbX??0)+(VV.outlineOffsetX??0),y:(VV.pcbY??0)+(VV.outlineOffsetY??0)},thickness:this.boardThickness,num_layers:this.allLayers.length,width:VV.width,height:VV.height,outline:(ZV=VV.outline)==null?void 0:ZV.map(WV=>({x:WV.x+(VV.outlineOffsetX??0),y:WV.y+(VV.outlineOffsetY??0)}))});this.pcb_board_id=RV.pcb_board_id}removePcbComponentRender(){const{db:J}=this.root;this.pcb_board_id&&(J.pcb_board.delete(this.pcb_board_id),this.pcb_board_id=null)}_computePcbGlobalTransformBeforeLayout(){return identity$4()}},stringProxy=new Proxy({},{get:(lV,J)=>J}),FTYPE=stringProxy,DirectLineRouter=class{constructor({input:lV}){kW(this,"input");this.input=lV}solveAndMapToTraces(){const lV=[];for(const J of this.input.connections){if(J.pointsToConnect.length!==2)continue;const[VV,RV]=J.pointsToConnect,UV={type:"pcb_trace",pcb_trace_id:"",route:[{route_type:"wire",x:VV.x,y:VV.y,layer:"top",width:.1},{route_type:"wire",x:RV.x,y:RV.y,layer:"top",width:.1}]};lV.push(UV)}return lV}},computeObstacleBounds=lV=>{const J=Math.min(...lV.map(ZV=>ZV.center.x)),VV=Math.max(...lV.map(ZV=>ZV.center.x)),RV=Math.min(...lV.map(ZV=>ZV.center.y)),UV=Math.max(...lV.map(ZV=>ZV.center.y));return{minX:J,maxX:VV,minY:RV,maxY:UV}},LAYER_SELECTION_PREFERENCE=["top","bottom","inner1","inner2"],findPossibleTraceLayerCombinations=(lV,J=[])=>{var IV;const VV=[];if(J.length===0){const dV=lV[0].layers;for(const CV of dV)VV.push(...findPossibleTraceLayerCombinations(lV.slice(1),[CV]));return VV}if(lV.length===0)return[];const RV=lV[0],UV=RV.via||RV.optional_via,ZV=J[J.length-1];if(lV.length===1){const dV=RV;return dV.layers&&UV?dV.layers.map(CV=>({layer_path:[...J,CV]})):(IV=dV.layers)!=null&&IV.includes(ZV)?[{layer_path:[...J,ZV]}]:[]}if(!UV)return RV.layers&&!RV.layers.includes(ZV)?[]:findPossibleTraceLayerCombinations(lV.slice(1),J.concat([ZV]));const WV=(RV.optional_via?LAYER_SELECTION_PREFERENCE:LAYER_SELECTION_PREFERENCE.filter(dV=>dV!==ZV)).filter(dV=>{var CV;return!RV.layers||((CV=RV.layers)==null?void 0:CV.includes(dV))});for(const dV of WV)VV.push(...findPossibleTraceLayerCombinations(lV.slice(1),J.concat(dV)));return VV};function getDominantDirection(lV){const J={x:lV.to.x-lV.from.x,y:lV.to.y-lV.from.y},VV=Math.abs(J.x),RV=Math.abs(J.y);return VV>RV?J.x>0?"right":"left":J.y>0?"down":"up"}function pdist(lV,J){return Math.hypot(lV.x-J.x,lV.y-J.y)}var mergeRoutes=lV=>{if(lV.length===1)return lV[0];if(lV.some(dV=>dV.length===0))throw new Error("Cannot merge routes with zero length");const J=[],VV=lV[0][0],RV=lV[0][lV[0].length-1],UV=lV[1][0],ZV=lV[1][lV[1].length-1],WV=Math.min(pdist(VV,UV),pdist(VV,ZV)),IV=Math.min(pdist(RV,UV),pdist(RV,ZV));WV<IV?J.push(...lV[0].reverse()):J.push(...lV[0]);for(let dV=1;dV<lV.length;dV++){const CV=J[J.length-1],FV=lV[dV],NV=FV[0],eV=FV[FV.length-1],gV=pdist(CV,NV),nV=pdist(CV,eV);gV<nV?J.push(...FV):J.push(...FV.reverse())}for(let dV=1;dV<J.length-1;dV++){const CV=J[dV-1],FV=J[dV];CV.route_type==="wire"&&FV.route_type==="wire"&&CV.layer!==FV.layer&&J.splice(dV,0,{x:CV.x,y:CV.y,from_layer:CV.layer,to_layer:FV.layer,route_type:"via"})}return J};function getTraceLength(lV){let J=0;for(let VV=0;VV<lV.length;VV++){const RV=lV[VV];if(RV.route_type==="wire"){const UV=lV[VV+1];if(UV){const ZV=UV.x-RV.x,WV=UV.y-RV.y;J+=Math.sqrt(ZV*ZV+WV*WV)}}else RV.route_type==="via"&&(J+=1.6)}return J}var getDistance=(lV,J)=>{const VV="_getGlobalPcbPositionBeforeLayout"in lV?lV._getGlobalPcbPositionBeforeLayout():lV,RV="_getGlobalPcbPositionBeforeLayout"in J?J._getGlobalPcbPositionBeforeLayout():J;return Math.sqrt((VV.x-RV.x)**2+(VV.y-RV.y)**2)};function getClosest(lV,J){if(J.length===0)throw new Error("No candidates given to getClosest method");let VV=J[0],RV=1/0;for(const UV of J){const ZV=getDistance(lV,UV);ZV<RV&&(VV=UV,RV=ZV)}return VV}var getEnteringEdgeFromDirection=lV=>({up:"bottom",down:"top",left:"right",right:"left"})[lV]??null,getStubEdges=({firstEdge:lV,firstEdgePort:J,firstDominantDirection:VV,lastEdge:RV,lastEdgePort:UV,lastDominantDirection:ZV})=>{if(lV&&J)return getStubEdges({lastEdge:{from:lV.to,to:lV.from},lastEdgePort:J,lastDominantDirection:VV}).reverse().map(IV=>({from:IV.to,to:IV.from}));let WV=[];if(RV&&UV){const IV={x:RV.to.x,y:RV.to.y};ZV==="left"||ZV==="right"?(IV.x=UV.position.x,WV.push({from:RV.to,to:{...IV}}),WV.push({from:IV,to:{...UV.position}})):(IV.y=UV.position.y,WV.push({from:RV.to,to:{...IV}}),WV.push({from:IV,to:{...UV.position}}))}return WV=WV.filter(IV=>distance$3(IV.from,IV.to)>.01),WV};function tryNow(lV){try{return[lV(),null]}catch(J){return[null,J]}}var getOtherSchematicTraces=({db:lV,source_trace_id:J,sameNetOnly:VV,differentNetOnly:RV})=>{!VV&&!RV&&(RV=!0);const UV=lV.source_trace.get(J),ZV=[];for(const WV of lV.schematic_trace.list()){if(WV.source_trace_id===J)continue;const IV=lV.source_trace.get(WV.source_trace_id),dV=(IV==null?void 0:IV.subcircuit_connectivity_map_key)===UV.subcircuit_connectivity_map_key;RV&&dV||VV&&!dV||ZV.push(WV)}return ZV},createSchematicTraceCrossingSegments=({edges:lV,db:J,source_trace_id:VV})=>{const RV=getOtherSchematicTraces({db:J,source_trace_id:VV,differentNetOnly:!0}).flatMap(UV=>UV.edges);for(let UV=0;UV<lV.length;UV++){const ZV=lV[UV],WV=Math.abs(ZV.from.x-ZV.to.x)<.01?"vertical":"horizontal",IV=[];for(const aV of RV){const GV=aV.from.x===aV.to.x?"vertical":"horizontal";if(WV===GV)continue;if(doesLineIntersectLine$1([ZV.from,ZV.to],[aV.from,aV.to],{lineThickness:.01})){const TV=WV==="vertical"?ZV.from.x:aV.from.x,iV=WV==="vertical"?aV.from.y:ZV.from.y,AV={x:TV,y:iV};IV.push({otherEdge:aV,crossingPoint:AV,distanceFromEdgeFrom:distance$3(ZV.from,AV)})}}if(IV.length===0)continue;let dV=IV[0];for(const aV of IV)aV.distanceFromEdgeFrom<dV.distanceFromEdgeFrom&&(dV=aV);const CV=dV.crossingPoint,FV=.075,NV=getUnitVectorFromPointAToB(ZV.from,CV),eV={x:CV.x-NV.x*FV/2,y:CV.y-NV.y*FV/2},gV={x:CV.x+NV.x*FV/2,y:CV.y+NV.y*FV/2},nV=distance$3(gV,ZV.to)<FV,JV=[{from:ZV.from,to:eV},{from:eV,to:gV,is_crossing:!0},{from:gV,to:ZV.to}];lV.splice(UV,1,...JV),UV+=JV.length-2,nV&&UV++}},isOrthogonal=(lV,J)=>{const VV=lV.from.x===lV.to.x,RV=J.from.x===J.to.x;return VV!==RV},getIntersectionPoint=(lV,J)=>{if(!isOrthogonal(lV,J))return null;const VV=lV.from.x===lV.to.x,RV=VV?lV:J,UV=VV?J:lV,ZV=Math.min(UV.from.x,UV.to.x),WV=Math.max(UV.from.x,UV.to.x);if(RV.from.x<ZV||RV.from.x>WV)return null;const IV=Math.min(RV.from.y,RV.to.y),dV=Math.max(RV.from.y,RV.to.y);return UV.from.y<IV||UV.from.y>dV?null:{x:RV.from.x,y:UV.from.y}},createSchematicTraceJunctions=({edges:lV,db:J,source_trace_id:VV})=>{const RV=getOtherSchematicTraces({db:J,source_trace_id:VV,sameNetOnly:!0}).flatMap(ZV=>ZV.edges),UV=new Set;for(const ZV of lV)for(const WV of RV){const IV=getIntersectionPoint(ZV,WV);IV&&UV.add(`${IV.x},${IV.y}`)}return Array.from(UV).map(ZV=>{const[WV,IV]=ZV.split(",").map(Number);return{x:WV,y:IV}})},pushEdgesOfSchematicTraceToPreventOverlap=({edges:lV,db:J,source_trace_id:VV})=>{J.source_trace.get(VV);const RV=getOtherSchematicTraces({db:J,source_trace_id:VV,differentNetOnly:!0}).flatMap(ZV=>ZV.edges),UV=ZV=>{const{from:WV,to:IV}=ZV;return WV.x===IV.x?"vertical":"horizontal"};for(const ZV of lV){const WV=UV(ZV),IV=()=>RV.find(CV=>UV(CV)===WV&&doesLineIntersectLine$1([ZV.from,ZV.to],[CV.from,CV.to],{lineThickness:.05}));let dV=IV();for(;dV;)WV==="horizontal"?(ZV.from.y+=.1,ZV.to.y+=.1):(ZV.from.x+=.1,ZV.to.x+=.1),dV=IV()}},countComplexElements=(lV,J)=>{let VV=0;VV+=lV.length??0,VV+=J.filter(RV=>RV.is_crossing).length;for(let RV=1;RV<J.length;RV++){const UV=J[RV-1],ZV=J[RV],WV=Math.abs(UV.from.x-UV.to.x)<.01,IV=Math.abs(ZV.from.x-ZV.to.x)<.01;WV!==IV&&VV++}return VV},calculateOffsets=lV=>{var IV,dV;const J={left:{x:-.5,y:0},up:{x:.5,y:.5},right:{x:.5,y:0},down:{x:0,y:-.5}}[lV.facingDirection],VV=(IV=lV.parent)!=null&&IV.config.shouldRenderAsSchematicBox?3:1,RV=(dV=lV.parent)!=null&&dV.config.shouldRenderAsSchematicBox&&(lV.facingDirection==="left"||lV.facingDirection==="right")?3:1,UV=J.x,ZV=J.y,WV=lV.facingDirection==="up"?.5:0;return{schBoxVertOffset:VV,schBoxHorzOffset:RV,horzPortDirection:UV,vertPortDirectionOffset:ZV,handleUp:WV}},createDownwardNetLabelGroundSymbol=({fromPort:lV,toPort:J,fromAnchorPos:VV,toAnchorPos:RV,schDisplayLabel:UV,source_trace_id:ZV},{db:WV})=>{const IV=calculateOffsets(lV);WV.schematic_net_label.insert({anchor_side:"top",center:{x:VV.x+IV.horzPortDirection*IV.schBoxHorzOffset,y:VV.y+IV.vertPortDirectionOffset*IV.schBoxVertOffset},source_net_id:lV.source_port_id,text:UV,anchor_position:{x:VV.x+IV.horzPortDirection*IV.schBoxHorzOffset,y:VV.y+IV.vertPortDirectionOffset*IV.schBoxVertOffset},symbol_name:"ground_horz"}),WV.schematic_trace.insert({edges:[{from:{x:VV.x,y:VV.y},to:{x:VV.x,y:VV.y+IV.handleUp*IV.schBoxVertOffset}},{from:{x:VV.x,y:VV.y},to:{x:VV.x+IV.horzPortDirection*IV.schBoxHorzOffset,y:VV.y+IV.vertPortDirectionOffset*IV.schBoxVertOffset}}],junctions:[{x:VV.x+IV.horzPortDirection*IV.schBoxHorzOffset,y:VV.y+IV.vertPortDirectionOffset*IV.schBoxVertOffset}],source_trace_id:ZV});const dV=calculateOffsets(J);WV.schematic_net_label.insert({anchor_side:"top",center:{x:RV.x+dV.horzPortDirection*dV.schBoxHorzOffset,y:RV.y+dV.vertPortDirectionOffset*dV.schBoxVertOffset},source_net_id:J.source_port_id,text:UV,anchor_position:{x:RV.x+dV.horzPortDirection*dV.schBoxHorzOffset,y:RV.y+dV.vertPortDirectionOffset*dV.schBoxVertOffset},symbol_name:"ground_horz"});const CV=J.facingDirection==="up"?.5:0;WV.schematic_trace.insert({edges:[{from:{x:RV.x,y:RV.y},to:{x:RV.x,y:RV.y+CV*dV.schBoxVertOffset}},{from:{x:RV.x,y:RV.y},to:{x:RV.x+dV.horzPortDirection*dV.schBoxHorzOffset,y:RV.y+dV.vertPortDirectionOffset*dV.schBoxVertOffset}}],junctions:[{x:RV.x+dV.horzPortDirection*dV.schBoxHorzOffset,y:RV.y+dV.vertPortDirectionOffset*dV.schBoxVertOffset}],source_trace_id:ZV})},getMaxLengthFromConnectedCapacitors=(lV,{db:J})=>{const VV=lV.map(RV=>{const UV=J.source_port.get(RV.source_port_id);if(!(UV!=null&&UV.source_component_id))return null;const ZV=J.source_component.get(UV.source_component_id);return(ZV==null?void 0:ZV.ftype)==="simple_capacitor"?ZV.max_decoupling_trace_length:null}).filter(RV=>RV!==null);if(VV.length!==0)return Math.min(...VV)};function getTraceDisplayName({ports:lV,nets:J}){var VV,RV,UV;if(lV.length>=2)return`${(VV=lV[0])==null?void 0:VV.selector} to ${(RV=lV[1])==null?void 0:RV.selector}`;if(lV.length===1&&J.length===1)return`${(UV=lV[0])==null?void 0:UV.selector} to net.${J[0]._parsedProps.name}`}var portToObjective=lV=>({...lV._getGlobalPcbPositionAfterLayout(),layers:lV.getAvailablePcbLayers()}),Trace=class extends PrimitiveComponent{constructor(J){super(J);kW(this,"source_trace_id",null);kW(this,"pcb_trace_id",null);kW(this,"schematic_trace_id",null);kW(this,"_portsRoutedOnPcb");kW(this,"subcircuit_connectivity_map_key",null);this._portsRoutedOnPcb=[]}get config(){return{zodProps:traceProps,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(J=>typeof J=="string"?J:J.getPortSelector()):[]}getTracePortPathSelectors(){return this._getTracePortOrNetSelectorListFromProps().filter(J=>!J.includes("net."))}getTracePathNetSelectors(){return this._getTracePortOrNetSelectorListFromProps().filter(J=>J.includes("net."))}_findConnectedPorts(){this.root;const{_parsedProps:J,parent:VV}=this;if(!VV)throw new Error("Trace has no parent");const UV=this.getTracePortPathSelectors().map(ZV=>({selector:ZV,port:this.getSubcircuit().selectOne(ZV,{type:"port"})??null}));for(const{selector:ZV,port:WV}of UV)if(!WV){const IV=ZV.replace(/\>.*$/,""),dV=this.getSubcircuit().selectOne(IV);dV?this.renderError(`Could not find port for selector "${ZV}" (did you forget to include the pin name?)
|
|
22053
22053
|
searched component ${dV.getString()}, which has ports: ${dV.children.filter(CV=>CV.componentName==="Port").map(CV=>`${CV.getString()}(${CV.getNameAndAliases().join(",")})`).join(" & ")}`):this.renderError(`Could not find port for selector "${ZV}"`)}return UV.some(ZV=>!ZV.port)?{allPortsFound:!1}:{allPortsFound:!0,portsWithSelectors:UV,ports:UV.map(({port:ZV})=>ZV)}}_findConnectedNets(){const J=this.getTracePathNetSelectors().map(RV=>({selector:RV,net:this.getSubcircuit().selectOne(RV,{type:"net"})})),VV=J.filter(RV=>!RV.net);return VV.length>0&&this.renderError(`Could not find net for selector "${VV[0].selector}" inside ${this}`),{netsWithSelectors:J,nets:J.map(RV=>RV.net)}}_getAllTracesConnectedToSameNet(){const J=this.getSubcircuit().selectAll("trace"),VV=this._findConnectedNets().nets,RV=this._findConnectedPorts().ports??[];return J.filter(UV=>{if(UV===this)return!1;const ZV=UV._findConnectedNets().nets,WV=UV._findConnectedPorts().ports??[];return ZV.some(IV=>VV.includes(IV))||WV.some(IV=>RV.includes(IV))})}_isExplicitlyConnectedToPort(J){const{allPortsFound:VV,portsWithSelectors:RV}=this._findConnectedPorts();return VV?RV.map(ZV=>ZV.port).includes(J):!1}_isExplicitlyConnectedToNet(J){return this._findConnectedNets().nets.includes(J)}doInitialCreateNetsFromProps(){createNetsFromProps(this,this.getTracePathNetSelectors())}doInitialSourceTraceRender(){const{db:J}=this.root,{_parsedProps:VV,parent:RV}=this;if(!RV){this.renderError("Trace has no parent");return}const{allPortsFound:UV,portsWithSelectors:ZV}=this._findConnectedPorts();if(!UV)return;const WV=this._findConnectedNets().nets,IV=getTraceDisplayName({ports:ZV,nets:WV}),dV=J.source_trace.insert({connected_source_port_ids:ZV.map(CV=>CV.port.source_port_id),connected_source_net_ids:WV.map(CV=>CV.source_net_id),max_length:getMaxLengthFromConnectedCapacitors(ZV.map(CV=>CV.port),{db:J})??VV.maxLength,display_name:IV});this.source_trace_id=dV.source_trace_id}doInitialPcbTraceRender(){var pV,HV;if((pV=this.root)!=null&&pV.pcbDisabled)return;const{db:J}=this.root,{_parsedProps:VV,parent:RV}=this,UV=this.getSubcircuit();if(!RV)throw new Error("Trace has no parent");if(UV._parsedProps.routingDisabled)return;const ZV=(HV=UV._parsedProps.pcbRouteCache)==null?void 0:HV.pcbTraces;if(ZV){const BV=J.pcb_trace.insert({route:ZV.flatMap(uV=>uV.route),source_trace_id:this.source_trace_id});this.pcb_trace_id=BV.pcb_trace_id;return}if(!UV._shouldUseTraceByTraceRouting())return;const{allPortsFound:WV,ports:IV}=this._findConnectedPorts();if(!WV)return;const dV=[];for(const BV of IV)BV._hasMatchedPcbPrimitive()||dV.push(BV);if(dV.length>0){J.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: ${dV.map(BV=>BV.getString()).join(", ")}`,pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[],pcb_port_ids:dV.map(BV=>BV.pcb_port_id).filter(Boolean)});return}const CV=this._findConnectedNets().netsWithSelectors;if(IV.length===0&&CV.length===2){this.renderError("Trace connects two nets, we haven't implemented a way to route this yet");return}else if(IV.length===1&&CV.length===1){const BV=IV[0],jV=CV[0].net.getAllConnectedPorts().filter(Zl=>Zl!==BV);if(jV.length===0){console.log("Nothing to connect this port to, the net is empty. TODO should emit a warning!");return}const PV=getClosest(BV,jV);IV.push(PV)}else if(IV.length>1&&CV.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 FV=IV.flatMap(BV=>BV.matchedComponents.filter(uV=>uV.componentName==="TraceHint")),NV=(this._parsedProps.pcbRouteHints??[]).concat(FV.flatMap(BV=>BV.getPcbRouteHints()));if(IV.length>2){this.renderError(`Trace has more than two ports (${IV.map(BV=>BV.getString()).join(", ")}), routing between more than two ports for a single trace is not implemented`);return}if(this.getSubcircuit().selectAll("trace").filter(BV=>BV.renderPhaseStates.PcbTraceRender.initialized).some(BV=>BV._portsRoutedOnPcb.length===IV.length&&BV._portsRoutedOnPcb.every(uV=>IV.includes(uV))))return;let nV=[];NV.length===0?nV=[portToObjective(IV[0]),portToObjective(IV[1])]:nV=[portToObjective(IV[0]),...NV,portToObjective(IV[1])];const JV=findPossibleTraceLayerCombinations(nV),aV=getFullConnectivityMapFromCircuitJson$1(this.root.db.toArray()),[GV,YV]=tryNow(()=>getObstaclesFromSoup(this.root.db.toArray()));if(YV){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: ${YV.message}`,source_trace_id:this.source_trace_id,center:{x:0,y:0},pcb_port_ids:IV.map(BV=>BV.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[]});return}for(const BV of GV)if(BV.connectedTo.length>0){const jV=aV.getNetConnectedToId(BV.connectedTo[0]);jV&&BV.connectedTo.push(jV)}let TV=[];if(JV.length===0)TV=nV;else{const BV=JV[0].layer_path;TV=nV.map((uV,jV)=>uV.via?{...uV,via_to_layer:BV[jV]}:{...uV,layers:[BV[jV]]})}TV[0].pcb_port_id=IV[0].pcb_port_id,TV[TV.length-1].pcb_port_id=IV[1].pcb_port_id;const iV=[];for(const[BV,uV]of pairs$1(TV)){const jV="via_to_layer"in BV?BV.via_to_layer:null,PV=2,Zl="layers"in BV&&BV.layers.length===1?BV.layers[0]:jV??"top",nl="layers"in uV&&uV.layers.length===1?uV.layers[0]:jV??"top",dl="pcb_port_id"in BV?BV.pcb_port_id:null,LV="pcb_port_id"in uV?uV.pcb_port_id:null,OV=this.getSubcircuit()._parsedProps.minTraceWidth??.16,$V=new MultilayerIjump({OBSTACLE_MARGIN:OV*2,isRemovePathLoopsEnabled:!0,optimizeWithGoalBoxes:!!(dl&&LV),connMap:aV,input:{obstacles:GV,minTraceWidth:OV,connections:[{name:this.source_trace_id,pointsToConnect:[{...BV,layer:Zl,pcb_port_id:dl},{...uV,layer:nl,pcb_port_id:LV}]}],layerCount:2,bounds:{minX:Math.min(BV.x,uV.x)-PV,maxX:Math.max(BV.x,uV.x)+PV,minY:Math.min(BV.y,uV.y)-PV,maxY:Math.max(BV.y,uV.y)+PV}}});let Cl=null;try{Cl=$V.solveAndMapToTraces()}catch(pl){this.renderError({type:"pcb_trace_error",pcb_trace_error_id:this.source_trace_id,error_type:"pcb_trace_error",message:`error solving route: ${pl.message}`,source_trace_id:this.pcb_trace_id,center:{x:(BV.x+uV.x)/2,y:(BV.y+uV.y)/2},pcb_port_ids:IV.map(Al=>Al.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:IV.map(Al=>Al.pcb_component_id)})}if(!Cl)return;if(Cl.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:(BV.x+uV.x)/2,y:(BV.y+uV.y)/2},pcb_port_ids:IV.map(pl=>pl.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:IV.map(pl=>pl.pcb_component_id)});return}const[Wl]=Cl;jV&&(Wl.route=Wl.route.map(pl=>(pl.route_type==="wire"&&!pl.layer&&(pl.layer=jV),pl))),dl&&Wl.route[0].route_type==="wire"&&(Wl.route[0].start_pcb_port_id=dl);const gl=Wl.route[Wl.route.length-1];LV&&gl.route_type==="wire"&&(gl.end_pcb_port_id=LV),iV.push(Wl.route)}const AV=mergeRoutes(iV),SV=getTraceLength(AV),mV=J.pcb_trace.insert({route:AV,source_trace_id:this.source_trace_id,trace_length:SV});this._portsRoutedOnPcb=IV,this.pcb_trace_id=mV.pcb_trace_id;for(const BV of AV)BV.route_type==="via"&&J.pcb_via.insert({pcb_trace_id:mV.pcb_trace_id,x:BV.x,y:BV.y,hole_diameter:.3,outer_diameter:.6,layers:[BV.from_layer,BV.to_layer],from_layer:BV.from_layer,to_layer:BV.to_layer})}_doInitialSchematicTraceRenderWithDisplayLabel(){var TV,iV,AV,SV,mV,pV;if((TV=this.root)!=null&&TV.schematicDisabled)return;const{db:J}=this.root,{_parsedProps:VV,parent:RV}=this;if(!RV)throw new Error("Trace has no parent");const{allPortsFound:UV,portsWithSelectors:ZV}=this._findConnectedPorts();if(!UV)return;const WV=ZV.map(({port:HV})=>({port:HV,position:HV._getGlobalSchematicPositionAfterLayout(),schematic_port_id:HV.schematic_port_id,facingDirection:HV.facingDirection}));if(WV.length<2)throw new Error("Expected at least two ports in portsWithPosition.");let IV,dV;const CV=WV[0].position,FV=WV[0].port;if("path"in this.props){if(this.props.path.length!==2)throw new Error("Invalid 'path': Must contain exactly two elements.");[IV,dV]=this.props.path}else{if(!("from"in this.props&&"to"in this.props))throw new Error("Missing 'from' or 'to' properties in props.");IV=this.props.from,dV=this.props.to}if(!FV.source_port_id)throw new Error(`Missing source_port_id for the 'from' port (${IV}).`);const NV=WV[1].position,eV=WV[1].port;if(!eV.source_port_id)throw new Error(`Missing source_port_id for the 'to' port (${dV}).`);const gV=J.schematic_net_label.list().find(HV=>HV.source_net_id===FV.source_port_id),nV=J.schematic_net_label.list().find(HV=>HV.source_net_id===eV.source_port_id);if(gV&&gV.text!==this.props.schDisplayLabel||nV&&(nV==null?void 0:nV.text)!==this.props.schDisplayLabel)throw new Error(`Cannot create net label for port ${gV?IV:dV} because it already has a net label with text "${gV?gV.text:nV==null?void 0:nV.text}".`);if((iV=this.props.schDisplayLabel)!=null&&iV.toLocaleLowerCase().includes("gnd")||(AV=this.props.schDisplayLabel)!=null&&AV.toLocaleLowerCase().includes("ground")){createDownwardNetLabelGroundSymbol({fromPort:FV,toPort:eV,fromAnchorPos:CV,toAnchorPos:NV,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:J});return}const[JV,aV]=ZV.map(({port:HV})=>HV),YV=((SV=JV.parent)==null?void 0:SV.config.shouldRenderAsSchematicBox)?`${(mV=JV==null?void 0:JV.parent)==null?void 0:mV.props.name}_${JV==null?void 0:JV.props.name}`:`${(pV=aV==null?void 0:aV.parent)==null?void 0:pV.props.name}_${aV==null?void 0:aV.props.name}`;J.schematic_net_label.insert({text:this.props.schDisplayLabel??YV,source_net_id:eV.source_port_id,anchor_position:NV,center:NV,anchor_side:getEnteringEdgeFromDirection(eV.facingDirection)??"bottom"}),J.schematic_net_label.insert({text:this.props.schDisplayLabel??YV,source_net_id:FV.source_port_id,anchor_position:CV,center:CV,anchor_side:getEnteringEdgeFromDirection(FV.facingDirection)??"bottom"})}_isPassiveToChipConnection(){const{allPortsFound:J,ports:VV}=this._findConnectedPorts();if(!J||VV.length!==2)return!1;const[RV,UV]=VV;if(!(RV!=null&&RV.parent)||!(UV!=null&&UV.parent))return!1;const ZV=RV.parent.config.shouldRenderAsSchematicBox,WV=UV.parent.config.shouldRenderAsSchematicBox;return ZV&&!WV||!ZV&&WV}doInitialSchematicTraceRender(){var BV,uV,jV;if((BV=this.root)!=null&&BV.schematicDisabled)return;const{db:J}=this.root,{_parsedProps:VV,parent:RV}=this;if(!RV)throw new Error("Trace has no parent");const{allPortsFound:UV,portsWithSelectors:ZV}=this._findConnectedPorts(),{netsWithSelectors:WV}=this._findConnectedNets();if(!UV)return;const IV=[],dV={name:this.source_trace_id,pointsToConnect:[]};if(this.props.schDisplayLabel&&("from"in this.props&&"to"in this.props||"path"in this.props)){this._doInitialSchematicTraceRenderWithDisplayLabel();return}for(const PV of J.toArray())PV.type==="schematic_component"&&IV.push({type:"rect",layers:["top"],center:PV.center,width:PV.size.width,height:PV.size.height,connectedTo:[]}),PV.type==="schematic_port"&&IV.push({type:"rect",layers:["top"],center:PV.center,width:.1,height:.1,connectedTo:[]}),PV.type==="schematic_text"&&IV.push({type:"rect",layers:["top"],center:PV.position,width:(((uV=PV.text)==null?void 0:uV.length)??0)*.1,height:.2,connectedTo:[]}),PV.type==="schematic_box"&&IV.push({type:"rect",layers:["top"],center:{x:PV.x,y:PV.y},width:PV.width,height:PV.width,connectedTo:[]}),PV.type==="schematic_net_label"&&PV.symbol_name?IV.push({type:"rect",layers:["top"],center:PV.center,width:.25,height:.6,connectedTo:[]}):PV.type==="schematic_net_label"&&IV.push({type:"rect",layers:["top"],center:PV.center,width:(((jV=PV.text)==null?void 0:jV.length)??0)*.1,height:.2,connectedTo:[]});const CV=ZV.map(({port:PV})=>({port:PV,position:PV._getGlobalSchematicPositionAfterLayout(),schematic_port_id:PV.schematic_port_id??void 0,facingDirection:PV.facingDirection}));if(CV.length===1&&WV.length===1){const PV=WV[0].net,{port:Zl,position:nl}=CV[0];J.schematic_net_label.insert({text:PV._parsedProps.name,source_net_id:PV.source_net_id,anchor_position:nl,center:nl,anchor_side:getEnteringEdgeFromDirection(Zl.facingDirection)??"bottom"});return}if(CV.length<2)return;dV.pointsToConnect=CV.map(({position:PV})=>({...PV,layer:"top"}));const NV=computeObstacleBounds(IV),eV={minTraceWidth:.1,obstacles:IV,connections:[dV],bounds:NV,layerCount:1};let gV=MultilayerIjump;this.getSubcircuit().props._schDirectLineRoutingEnabled&&(gV=DirectLineRouter);const JV=new gV({input:eV,OBSTACLE_MARGIN:.1,isRemovePathLoopsEnabled:!0}).solveAndMapToTraces();if(JV.length===0)return;const[{route:aV}]=JV,GV=[];for(let PV=0;PV<aV.length-1;PV++)GV.push({from:aV[PV],to:aV[PV+1]});const YV=this.source_trace_id;pushEdgesOfSchematicTraceToPreventOverlap({edges:GV,db:J,source_trace_id:YV}),createSchematicTraceCrossingSegments({edges:GV,db:J,source_trace_id:YV});const TV=createSchematicTraceJunctions({edges:GV,db:J,source_trace_id:this.source_trace_id}),iV=GV[GV.length-1],AV=CV[CV.length-1],SV=getDominantDirection(iV);GV.push(...getStubEdges({lastEdge:iV,lastEdgePort:AV,lastDominantDirection:SV}));const mV=GV[0],pV=CV[0],HV=getDominantDirection(mV);if(GV.unshift(...getStubEdges({firstEdge:mV,firstEdgePort:pV,firstDominantDirection:HV})),!this.source_trace_id)throw new Error("Missing source_trace_id for schematic trace insertion.");if(countComplexElements(TV,GV)>=5&&this._isPassiveToChipConnection())this._doInitialSchematicTraceRenderWithDisplayLabel(),J.schematic_trace.delete(this.schematic_trace_id);else{const PV=J.schematic_trace.insert({source_trace_id:this.source_trace_id,edges:GV,junctions:TV});this.schematic_trace_id=PV.schematic_trace_id}}},Capacitor=class extends NormalComponent{get config(){return{componentName:"Capacitor",schematicSymbolName:this.props.symbolName??"capacitor",zodProps:capacitorProps,sourceFtype:FTYPE.simple_capacitor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${formatSiUnit(this._parsedProps.capacitance)}F`}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.decouplingFor,this.props.decouplingTo])}doInitialCreateTracesFromProps(){this.props.decouplingFor&&this.props.decouplingTo&&(this.add(new Trace({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.decouplingFor})),this.add(new Trace({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.decouplingTo})))}doInitialSourceRender(){const{db:lV}=this.root,{_parsedProps:J}=this,VV=lV.source_component.insert({ftype:"simple_capacitor",name:J.name,manufacturer_part_number:J.manufacturerPartNumber??J.mfn,supplier_part_numbers:J.supplierPartNumbers,capacitance:J.capacitance,max_decoupling_trace_length:J.maxDecouplingTraceLength,display_capacitance:this._getSchematicSymbolDisplayValue()});this.source_component_id=VV.source_component_id}},Chip=class extends NormalComponent{constructor(){super(...arguments);kW(this,"schematicBoxDimensions",null)}get config(){return{componentName:"Chip",zodProps:chipProps,shouldRenderAsSchematicBox:!0}}doInitialSchematicComponentRender(){const{_parsedProps:J}=this;(J==null?void 0:J.noSchematicRepresentation)!==!0&&super.doInitialSchematicComponentRender()}doInitialSourceRender(){const{db:J}=this.root,{_parsedProps:VV}=this,RV=J.source_component.insert({ftype:"simple_chip",name:VV.name,manufacturer_part_number:VV.manufacturerPartNumber,supplier_part_numbers:VV.supplierPartNumbers});this.source_component_id=RV.source_component_id}doInitialPcbComponentRender(){var UV;if((UV=this.root)!=null&&UV.pcbDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this,RV=J.pcb_component.insert({center:{x:VV.pcbX??0,y:VV.pcbY??0},width:2,height:3,layer:VV.layer??"top",rotation:VV.pcbRotation??0,source_component_id:this.source_component_id});this.pcb_component_id=RV.pcb_component_id}},Diode=class extends NormalComponent{constructor(){super(...arguments);kW(this,"pos",this.portMap.pin1);kW(this,"anode",this.portMap.pin1);kW(this,"neg",this.portMap.pin2);kW(this,"cathode",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"diode",componentName:"Diode",zodProps:diodeProps,sourceFtype:"simple_diode"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}},Jumper=class extends NormalComponent{constructor(){super(...arguments);kW(this,"schematicDimensions",null)}get config(){return{componentName:"Jumper",zodProps:jumperProps,shouldRenderAsSchematicBox:!0}}doInitialSourceRender(){const{db:J}=this.root,{_parsedProps:VV}=this,RV=J.source_component.insert({ftype:"simple_chip",name:VV.name,manufacturer_part_number:VV.manufacturerPartNumber,supplier_part_numbers:VV.supplierPartNumbers});this.source_component_id=RV.source_component_id}doInitialPcbComponentRender(){var UV;if((UV=this.root)!=null&&UV.pcbDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this,RV=J.pcb_component.insert({center:{x:VV.pcbX??0,y:VV.pcbY??0},width:2,height:3,layer:VV.layer??"top",rotation:VV.pcbRotation??0,source_component_id:this.source_component_id});this.pcb_component_id=RV.pcb_component_id}},Led=class extends NormalComponent{constructor(){super(...arguments);kW(this,"pos",this.portMap.pin1);kW(this,"anode",this.portMap.pin1);kW(this,"neg",this.portMap.pin2);kW(this,"cathode",this.portMap.pin2)}get config(){return{componentName:"Led",schematicSymbolName:this.props.symbolName??"led",zodProps:ledProps,sourceFtype:"simple_diode"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}},PowerSource=class extends NormalComponent{constructor(){super(...arguments);kW(this,"pos",this.portMap.pin1);kW(this,"positive",this.portMap.pin1);kW(this,"neg",this.portMap.pin2);kW(this,"negative",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"power_factor_meter_horz",componentName:"PowerSource",zodProps:powerSourceProps,sourceFtype:"simple_power_source"}}initPorts(){this.add(new Port({name:"pin1",pinNumber:1,aliases:["positive","pos"]})),this.add(new Port({name:"pin2",pinNumber:2,aliases:["negative","neg"]}))}},Resistor=class extends NormalComponent{get config(){return{componentName:"Resistor",schematicSymbolName:this.props.symbolName??"boxresistor",zodProps:resistorProps,sourceFtype:"simple_resistor"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${formatSiUnit(this._parsedProps.resistance)}Ω`}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.pullupFor,this.props.pullupTo])}doInitialCreateTracesFromProps(){this.props.pullupFor&&this.props.pullupTo&&(this.add(new Trace({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pullupFor})),this.add(new Trace({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pullupTo})))}doInitialSourceRender(){const{db:lV}=this.root,{_parsedProps:J}=this,VV=lV.source_component.insert({ftype:"simple_resistor",name:J.name,manufacturer_part_number:J.manufacturerPartNumber??J.mfn,supplier_part_numbers:J.supplierPartNumbers,resistance:J.resistance,display_resistance:this._getSchematicSymbolDisplayValue()});this.source_component_id=VV.source_component_id}},edgeSpecifiers=["leftedge","rightedge","topedge","bottomedge","center"],Constraint2=class extends PrimitiveComponent{get config(){return{componentName:"Constraint",zodProps:constraintProps}}constructor(lV){if(super(lV),("xdist"in lV||"ydist"in lV)&&!("edgeToEdge"in lV)&&!("centerToCenter"in lV))throw new Error(`edgeToEdge, centerToCenter must be set for xDist or yDist for ${this}`);if("for"in lV&&lV.for.length<2)throw new Error(`"for" must have at least two selectors for ${this}`)}_getAllReferencedComponents(){const lV=[],J=this.getPrimitiveContainer();function VV(RV){const UV=RV.split(" ").pop(),ZV=edgeSpecifiers.includes(UV)?UV:void 0,WV=ZV?RV.replace(` ${ZV}`,""):RV,IV=J.selectOne(WV,{pcbPrimitive:!0});IV&&lV.push({selector:RV,component:IV,componentSelector:WV,edge:ZV})}for(const RV of["left","right","top","bottom"])RV in this._parsedProps&&VV(this._parsedProps[RV]);if("for"in this._parsedProps)for(const RV of this._parsedProps.for)VV(RV);return{componentsWithSelectors:lV}}},FabricationNotePath=class extends PrimitiveComponent{constructor(){super(...arguments);kW(this,"fabrication_note_path_id",null)}get config(){return{componentName:"FabricationNotePath",zodProps:fabricationNotePathProps}}doInitialPcbPrimitiveRender(){var WV,IV;if((WV=this.root)!=null&&WV.pcbDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this,RV=VV.layer??"top";if(RV!=="top"&&RV!=="bottom")throw new Error(`Invalid layer "${RV}" for SilkscreenPath. Must be "top" or "bottom".`);const UV=this._computePcbGlobalTransformBeforeLayout(),ZV=J.pcb_fabrication_note_path.insert({pcb_component_id:(IV=this.parent)==null?void 0:IV.pcb_component_id,layer:RV,color:VV.color,route:VV.route.map(dV=>{const CV=applyToPoint(UV,{x:dV.x,y:dV.y});return{...dV,x:CV.x,y:CV.y}}),stroke_width:VV.strokeWidth??.1});this.fabrication_note_path_id=ZV.pcb_fabrication_note_path_id}},FabricationNoteText=class extends PrimitiveComponent{get config(){return{componentName:"FabricationNoteText",zodProps:fabricationNoteTextProps}}doInitialPcbPrimitiveRender(){var RV;if((RV=this.root)!=null&&RV.pcbDisabled)return;const{db:lV}=this.root,{_parsedProps:J}=this,VV=this.getPrimitiveContainer();lV.pcb_fabrication_note_text.insert({anchor_alignment:J.anchorAlignment,anchor_position:{x:J.pcbX??0,y:J.pcbY??0},font:J.font??"tscircuit2024",font_size:J.fontSize??1,layer:"top",color:J.color,text:J.text??"",pcb_component_id:VV.pcb_component_id})}},Subcircuit=class extends Group$1{constructor(lV){super({...lV,subcircuit:!0})}},NetAlias=class extends PrimitiveComponent{constructor(){super(...arguments);kW(this,"source_net_alias_id")}get config(){return{componentName:"NetAlias",zodProps:netAliasProps}}doInitialSchematicComponentRender(){var ZV;if((ZV=this.root)!=null&&ZV.schematicDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this,RV={x:VV.schX??0,y:VV.schY??0},UV=J.schematic_net_label.insert({text:VV.net,source_net_id:VV.net,anchor_position:RV,center:RV,anchor_side:"bottom"});this.source_net_alias_id=UV.source_net_id}},SilkscreenCircle=class extends PrimitiveComponent{constructor(){super(...arguments);kW(this,"pcb_silkscreen_circle_id",null)}get config(){return{componentName:"SilkscreenCircle",zodProps:silkscreenCircleProps}}doInitialPcbPrimitiveRender(){var ZV,WV;if((ZV=this.root)!=null&&ZV.pcbDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this,RV=VV.layer??"top";if(RV!=="top"&&RV!=="bottom")throw new Error(`Invalid layer "${RV}" for SilkscreenCircle. Must be "top" or "bottom".`);this._computePcbGlobalTransformBeforeLayout();const UV=J.pcb_silkscreen_circle.insert({pcb_component_id:(WV=this.parent)==null?void 0:WV.pcb_component_id,layer:RV,center:{x:VV.pcbX??0,y:VV.pcbY??0},radius:VV.radius});this.pcb_silkscreen_circle_id=UV.pcb_silkscreen_circle_id}},SilkscreenRect=class extends PrimitiveComponent{constructor(){super(...arguments);kW(this,"pcb_silkscreen_rect_id",null)}get config(){return{componentName:"SilkscreenRect",zodProps:silkscreenRectProps}}doInitialPcbPrimitiveRender(){var ZV,WV;if((ZV=this.root)!=null&&ZV.pcbDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this,RV=VV.layer??"top";if(RV!=="top"&&RV!=="bottom")throw new Error(`Invalid layer "${RV}" for SilkscreenRect. Must be "top" or "bottom".`);const UV=J.pcb_silkscreen_rect.insert({pcb_component_id:(WV=this.parent)==null?void 0:WV.pcb_component_id,layer:RV,center:{x:VV.pcbX??0,y:VV.pcbY??0},width:VV.width,height:VV.height});this.pcb_silkscreen_rect_id=UV.pcb_silkscreen_rect_id}},SilkscreenText=class extends PrimitiveComponent{constructor(){super(...arguments);kW(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenText",zodProps:silkscreenTextProps}}doInitialPcbPrimitiveRender(){var WV;if((WV=this.root)!=null&&WV.pcbDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this,RV=this.getPrimitiveContainer(),UV=this._getGlobalPcbPositionBeforeLayout(),{maybeFlipLayer:ZV}=this._getPcbPrimitiveFlippedHelpers();J.pcb_silkscreen_text.insert({anchor_alignment:VV.anchorAlignment,anchor_position:{x:UV.x,y:UV.y},font:VV.font??"tscircuit2024",font_size:VV.fontSize??1,layer:ZV(VV.layer??"top"),text:VV.text??"",ccw_rotation:VV.pcbRotation,pcb_component_id:RV.pcb_component_id})}getPcbSize(){const{_parsedProps:J}=this,VV=J.fontSize??1,UV=(J.text??"").length*VV,ZV=VV;return{width:UV*VV,height:ZV*VV}}},SilkscreenLine=class extends PrimitiveComponent{constructor(){super(...arguments);kW(this,"pcb_silkscreen_line_id",null)}get config(){return{componentName:"SilkscreenLine",zodProps:silkscreenLineProps}}doInitialPcbPrimitiveRender(){var ZV,WV;if((ZV=this.root)!=null&&ZV.pcbDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this,RV=VV.layer??"top";if(RV!=="top"&&RV!=="bottom")throw new Error(`Invalid layer "${RV}" for SilkscreenLine. Must be "top" or "bottom".`);const UV=J.pcb_silkscreen_line.insert({pcb_component_id:(WV=this.parent)==null?void 0:WV.pcb_component_id,layer:RV,x1:VV.x1,y1:VV.y1,x2:VV.x2,y2:VV.y2,stroke_width:VV.strokeWidth??.1});this.pcb_silkscreen_line_id=UV.pcb_silkscreen_line_id}},Via=class extends PrimitiveComponent{constructor(){super(...arguments);kW(this,"pcb_via_id",null);kW(this,"matchedPort",null);kW(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Via",zodProps:viaProps}}getAvailablePcbLayers(){return["top","inner1","inner2","bottom"]}getPcbSize(){const{_parsedProps:J}=this;return{width:J.outerDiameter,height:J.outerDiameter}}_getPcbCircuitJsonBounds(){const{db:J}=this.root,VV=J.pcb_via.get(this.pcb_via_id),RV=this.getPcbSize();return{center:{x:VV.x,y:VV.y},bounds:{left:VV.x-RV.width/2,top:VV.y-RV.height/2,right:VV.x+RV.width/2,bottom:VV.y+RV.height/2},width:RV.width,height:RV.height}}_setPositionFromLayout(J){const{db:VV}=this.root;VV.pcb_via.update(this.pcb_via_id,{x:J.x,y:J.y})}doInitialPcbPrimitiveRender(){var ZV;if((ZV=this.root)!=null&&ZV.pcbDisabled)return;const{db:J}=this.root,{_parsedProps:VV}=this,RV=this._getGlobalPcbPositionBeforeLayout(),UV=J.pcb_via.insert({x:RV.x,y:RV.y,hole_diameter:VV.holeDiameter,outer_diameter:VV.outerDiameter,layers:["bottom","top"],from_layer:VV.fromLayer||"bottom",to_layer:VV.toLayer||"top"});this.pcb_via_id=UV.pcb_via_id}},Battery=class extends NormalComponent{get config(){return{componentName:"Battery",schematicSymbolName:this.props.symbolName??"battery",zodProps:batteryProps,sourceFtype:"simple_power_source"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:lV}=this.root,{_parsedProps:J}=this,VV=lV.source_component.insert({name:J.name,ftype:"simple_power_source",capacity:J.capacity,supplier_part_numbers:J.supplierPartNumbers});this.source_component_id=VV.source_component_id}},PinHeader=class extends NormalComponent{get config(){return{componentName:"PinHeader",zodProps:pinHeaderProps,shouldRenderAsSchematicBox:!0}}_getImpliedFootprintString(){var UV;const lV=this._parsedProps.pinCount??((UV=this._parsedProps.pinLabels)==null?void 0:UV.length)??0,J=this._parsedProps.holeDiameter,VV=this._parsedProps.platedDiameter,RV=this._parsedProps.pitch;return lV>0&&RV?!J&&!VV?`pinrow${lV}_p${RV}`:`pinrow${lV}_p${RV}_id${J}_od${VV}`:null}initPorts(){var J;const lV=this._parsedProps.pinCount??((J=this._parsedProps.pinLabels)==null?void 0:J.length)??1;for(let VV=1;VV<=lV;VV++)this.add(new Port({name:`pin${VV}`,pinNumber:VV,aliases:[]}))}_getSchematicPortArrangement(){const lV=this._parsedProps.pinCount??1,J=this._parsedProps.facingDirection??"right";return{leftSize:J==="left"?lV:0,rightSize:J==="right"?lV:0}}doInitialSourceRender(){const{db:lV}=this.root,{_parsedProps:J}=this,VV=lV.source_component.insert({ftype:"simple_pin_header",name:J.name,supplier_part_numbers:J.supplierPartNumbers,pin_count:J.pinCount,gender:J.gender});this.source_component_id=VV.source_component_id}};function getResonatorSymbolName(lV){switch(lV){case"two_ground_pins":return"crystal_4pin";case"ground_pin":return"resonator";case"no_ground":return"crystal";default:return"crystal"}}var Resonator=class extends NormalComponent{get config(){return{componentName:"Resonator",schematicSymbolName:this.props.symbolName??getResonatorSymbolName(this.props.pinVariant),zodProps:resonatorProps,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:lV}=this.root,{_parsedProps:J}=this,VV=lV.source_component.insert({ftype:"simple_resonator",name:J.name,frequency:J.frequency,load_capacitance:J.loadCapacitance,supplier_part_numbers:J.supplierPartNumbers,pin_variant:J.pinVariant||"no_ground"});this.source_component_id=VV.source_component_id}},Inductor=class extends NormalComponent{get config(){return{componentName:"Inductor",schematicSymbolName:this.props.symbolName??"inductor",zodProps:inductorProps,sourceFtype:FTYPE.simple_inductor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:lV}=this.root,{_parsedProps:J}=this,VV=lV.source_component.insert({name:J.name,ftype:FTYPE.simple_inductor,inductance:J.inductance,supplier_part_numbers:J.supplierPartNumbers});this.source_component_id=VV.source_component_id}},Potentiometer=class extends NormalComponent{get config(){return{schematicSymbolName:this.props.symbolName??"potentiometer2",componentName:"Potentiometer",zodProps:potentiometerProps,sourceFtype:"simple_potentiometer"}}initPorts(){super.initPorts({additionalAliases:{pin1:["pos","left"],pin2:["neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${formatSiUnit(this._parsedProps.maxResistance)}Ω`}doInitialSourceRender(){const{db:lV}=this.root,{_parsedProps:J}=this,VV=lV.source_component.insert({name:J.name,ftype:"simple_potentiometer",max_resistance:J.maxResistance});this.source_component_id=VV.source_component_id}},PushButton=class extends NormalComponent{get config(){return{componentName:"PushButton",schematicSymbolName:this.props.symbolName??"push_button_normally_open_momentary",zodProps:pushButtonProps,sourceFtype:FTYPE.simple_push_button}}initPorts(){super.initPorts({additionalAliases:{pin1:["side1"],pin3:["side2"]}})}doInitialSourceRender(){const{db:lV}=this.root,{_parsedProps:J}=this,VV=lV.source_component.insert({name:J.name,ftype:FTYPE.simple_push_button,supplier_part_numbers:J.supplierPartNumbers});this.source_component_id=VV.source_component_id}},Crystal=class extends NormalComponent{get config(){return{schematicSymbolName:this.props.symbolName??"crystal",componentName:"Crystal",zodProps:crystalProps,sourceFtype:"simple_crystal"}}initPorts(){super.initPorts({additionalAliases:{pin1:["pos","left"],pin2:["neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${formatSiUnit(this._parsedProps.frequency)}Hz`}doInitialSourceRender(){const{db:lV}=this.root,{_parsedProps:J}=this,VV=lV.source_component.insert({name:J.name,ftype:"simple_crystal",frequency:J.frequency,load_capacitance:J.loadCapacitance});this.source_component_id=VV.source_component_id}},Transistor=class extends NormalComponent{get config(){return{componentName:"Transistor",schematicSymbolName:this.props.transistorType==="npn"?"npn_bipolar_transistor":"pnp_bipolar_transistor",zodProps:transistorProps,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:lV}=this.root,{_parsedProps:J}=this,VV=lV.source_component.insert({ftype:"simple_transistor",name:J.name,transistor_type:J.transistorType});this.source_component_id=VV.source_component_id}},Mosfet=class extends NormalComponent{get config(){const lV=this.props.mosfetMode==="depletion"?"d":"e";return{componentName:"Mosfet",schematicSymbolName:`${this.props.channelType}_channel_${lV}_mosfet_transistor`,zodProps:mosfetProps,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:lV}=this.root,{_parsedProps:J}=this,VV=lV.source_component.insert({ftype:"simple_mosfet",name:J.name,mosfet_mode:J.mosfetMode,channel_type:J.channelType});this.source_component_id=VV.source_component_id}},RootCircuit=class{constructor(){kW(this,"firstChild",null);kW(this,"children");kW(this,"db");kW(this,"root",null);kW(this,"isRoot",!0);kW(this,"schematicDisabled",!1);kW(this,"pcbDisabled",!1);kW(this,"pcbRoutingDisabled",!1);kW(this,"name");kW(this,"_hasRenderedAtleastOnce",!1);kW(this,"_eventListeners",{});this.children=[],this.db=su_default$1([]),this.root=this}add(lV){let J;reactExports.isValidElement(lV)?J=createInstanceFromReactElement(lV):J=lV,this.children.push(J)}_getBoard(){return this.children.find(lV=>lV.componentName==="Board")}_guessRootComponent(){if(!this.firstChild){if(this.children.length===1){this.firstChild=this.children[0];return}if(this.children.length===0)throw new Error("Not able to guess root component: RootCircuit has no children (use circuit.add(...))");if(this.children.length>0){const lV=this.children.find(J=>J.componentName==="Board")??null;if(lV){this.firstChild=lV;return}}throw new Error("Not able to guess root component: RootCircuit has multiple children and no board")}}render(){this.firstChild||this._guessRootComponent();const{firstChild:lV,db:J}=this;if(!lV)throw new Error("RootCircuit has no root component");lV.parent=this,lV.runRenderCycle(),this._hasRenderedAtleastOnce=!0}async renderUntilSettled(){for(this.render();this._hasIncompleteAsyncEffects();)await new Promise(lV=>setTimeout(lV,100)),this.render()}_hasIncompleteAsyncEffects(){return this.children.some(lV=>lV._hasIncompleteAsyncEffects()?!0:lV.children.some(J=>J._hasIncompleteAsyncEffects()))}getSoup(){return this._hasRenderedAtleastOnce||this.render(),this.db.toArray()}getCircuitJson(){return this.getSoup()}toJson(){return this.getSoup()}async getSvg(lV){return(await Promise.resolve().then(()=>index$1).catch(VV=>{throw new Error(`To use project.getSvg, you must install the "circuit-to-svg" package.
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tscircuit/runframe",
|
|
3
3
|
"main": "dist/preview.js",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.70",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./dist/preview.js",
|
|
8
8
|
"./preview": "./dist/preview.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@radix-ui/react-tabs": "^1.1.1",
|
|
55
55
|
"@tscircuit/3d-viewer": "^0.0.86",
|
|
56
56
|
"@tscircuit/assembly-viewer": "^0.0.1",
|
|
57
|
-
"@tscircuit/core": "^0.0.
|
|
57
|
+
"@tscircuit/core": "^0.0.255",
|
|
58
58
|
"@tscircuit/eval-webworker": "^0.0.53",
|
|
59
59
|
"@tscircuit/file-server": "^0.0.13",
|
|
60
60
|
"@tscircuit/pcb-viewer": "^1.10.22",
|