@tscircuit/eval 0.0.486 → 0.0.487
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/blob-url.js +1 -1
- package/dist/eval/index.js +34 -8
- package/dist/lib/index.js +34 -8
- package/dist/webworker/entrypoint.js +3 -3
- package/package.json +1 -1
|
@@ -251,7 +251,7 @@ ${o}`)}catch(c){Ba(`Failed to convert circuit JSON to SPICE: ${c}`);return}for(l
|
|
|
251
251
|
`),a={x:t.center.x+t.width/2-.25,y:t.center.y-t.height/2+1};this.root.db.pcb_silkscreen_text.insert({pcb_component_id:this.pcb_board_id,layer:"top",font:"tscircuit2024",font_size:.45,text:r,ccw_rotation:0,anchor_alignment:"bottom_right",anchor_position:a})}doInitialSourceRender(){super.doInitialSourceRender();let{db:e}=this.root,t=e.source_board.insert({source_group_id:this.source_group_id,title:this.props.title||this.props.name});this.source_board_id=t.source_board_id}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=t.width??0,r=t.height??0,s={x:(t.pcbX??0)+(t.outlineOffsetX??0),y:(t.pcbY??0)+(t.outlineOffsetY??0)},{boardAnchorPosition:o,boardAnchorAlignment:a}=t;if(o&&(s=lLt({boardAnchorPosition:o,boardAnchorAlignment:a??"center",width:i,height:r})),t.outline){let u=t.outline.map(v=>v.x),h=t.outline.map(v=>v.y),f=Math.min(...u),_=Math.max(...u),g=Math.min(...h),x=Math.max(...h);i=_-f,r=x-g,s={x:(f+_)/2+(t.outlineOffsetX??0),y:(g+x)/2+(t.outlineOffsetY??0)}}let c=t.outline;!c&&t.borderRadius!=null&&i>0&&r>0&&(c=$et(i,r,t.borderRadius));let l=e.pcb_board.insert({center:s,thickness:this.boardThickness,num_layers:this.allLayers.length,width:i,height:r,outline:c?.map(u=>({x:u.x+(t.outlineOffsetX??0),y:u.y+(t.outlineOffsetY??0)})),material:t.material});this.pcb_board_id=l.pcb_board_id,this._addBoardInformationToSilkscreen()}removePcbComponentRender(){let{db:e}=this.root;this.pcb_board_id&&(e.pcb_board.delete(this.pcb_board_id),this.pcb_board_id=null)}doInitialPcbDesignRuleChecks(){this.root?.pcbDisabled||this.getInheritedProperty("routingDisabled")||super.doInitialPcbDesignRuleChecks()}updatePcbDesignRuleChecks(){if(this.root?.pcbDisabled||this.getInheritedProperty("routingDisabled"))return;let{db:e}=this.root;if(!this._areChildSubcircuitsRouted()||this._drcChecksComplete)return;this._drcChecksComplete=!0;let t=jQ(e.toArray());for(let u of t)e.pcb_trace_error.insert(u);let i=DQ(e.toArray());for(let u of i)e.pcb_port_not_connected_error.insert(u);let r=XQ(e.toArray());for(let u of r)e.pcb_component_outside_board_error.insert(u);let s=GQ(e.toArray());for(let u of s)e.pcb_trace_error.insert(u);let o=VQ(e.toArray());for(let u of o)e.pcb_via_clearance_error.insert(u);let a=UQ(e.toArray());for(let u of a)e.pcb_via_clearance_error.insert(u);let c=HQ(e.toArray());for(let u of c)e.pcb_footprint_overlap_error.insert(u);let l=WQ(e.toArray());for(let u of l)e.source_pin_must_be_connected_error.insert(u)}_emitRenderLifecycleEvent(e,t){super._emitRenderLifecycleEvent(e,t),t==="start"&&this.root?.emit("board:renderPhaseStarted",{renderId:this._renderId,phase:e})}},Det=5,c7t=5,jet=2;function l7t(n,e){let t=n.center.x-n.width/2,i=n.center.x+n.width/2,r=n.center.y-n.height/2,s=n.center.y+n.height/2,o=e.center.x-e.width/2,a=e.center.x+e.width/2,c=e.center.y-e.height/2,l=e.center.y+e.height/2;return!(i<=o||t>=a||s<=c||r>=l)}function u7t(n,e,t){let i=t.center.x-t.width/2,r=t.center.x+t.width/2,s=t.center.y-t.height/2,o=t.center.y+t.height/2,a=Math.max(i,Math.min(n.x,r)),c=Math.max(s,Math.min(n.y,o)),l=n.x-a,u=n.y-c;return l*l+u*u<=e*e}function p7t({board:n,edge:e,otherBoards:t,options:i}){let r=[];if(!n.width||!n.height)return r;let s=n.center.x-n.width/2,o=n.center.x+n.width/2,a=n.center.y-n.height/2,c=n.center.y+n.height/2,l,u,h;e==="top"||e==="bottom"?(l=n.width,u=!0,h=e==="top"?c:a):(l=n.height,u=!1,h=e==="right"?o:s);let f=i.tabLength,_=i.boardGap;if(i.mouseBites){let S=i.tabWidth*.45,T=S*.1,k=Math.max(2,Math.ceil(i.tabLength/2));_=(k*S+(k-1)*T)*1.1}let g=Math.floor((l-_)/(f+_));if(g<1&&l>=f&&(g=1),g===0)return r;let x=_,v=-l/2,P=l/2;for(let S=0;S<g;S++){let T=v+x+S*(f+x)+f/2,k=S===0,C=S===g-1,M=k||C,I=T-f/2,E=T+f/2;if(M&&(k&&(I=v),C&&(E=P)),I=Math.max(I,v),E=Math.min(E,P),M&&(k&&(I-=i.tabWidth),C&&(E+=i.tabWidth)),E<=I)continue;let A=(I+E)/2,R=E-I,j=e==="top"||e==="right"?i.tabWidth/2:-i.tabWidth/2,B=u?{x:n.center.x+A,y:h+j}:{x:h+j,y:n.center.y+A},V=u?R:i.tabWidth,U=u?i.tabWidth:R,H={center:B,width:V,height:U,boardId:`${n.center.x}_${n.center.y}`},et=!1;for(let tt of t){if(!tt.width||!tt.height)continue;let _t={center:tt.center,width:tt.width,height:tt.height};if(l7t(H,_t)){et=!0;break}}et&&!M||r.push(H)}return r}function h7t({board:n,edge:e,edgeTabs:t,allBoards:i,options:r}){let s=[];if(t.length===0||!n.width||!n.height)return s;let o=n.center.x-n.width/2,a=n.center.x+n.width/2,c=n.center.y-n.height/2,l=n.center.y+n.height/2,u=e==="top"||e==="bottom",h=r.tabWidth*.45,f=h*.1,_=Math.max(2,Math.ceil(r.tabLength/2)),g,x=h/2;e==="top"?g=l:e==="bottom"?g=c:e==="right"?g=a:g=o;let v=[...t].sort((P,S)=>u?P.center.x-S.center.x:P.center.y-S.center.y);for(let P=0;P<v.length-1;P++){let S=v[P],T=v[P+1],k,C;u?(k=S.center.x+S.width/2,C=T.center.x-T.width/2):(k=S.center.y+S.height/2,C=T.center.y-T.height/2);let M=C-k,I=_*h,E=(_-1)*f;if(M<I+E)continue;let A=(k+C)/2;for(let R=0;R<_;R++){let j=(R-(_-1)/2)*(h+f),B=u?{x:A+j,y:g}:{x:g,y:A+j},V=h/2,U=!1;for(let H of i){if(!H.width||!H.height)continue;let et={center:H.center,width:H.width,height:H.height};if(u7t(B,V,et)){U=!0;break}}U||s.push(B)}}return s}function d7t(n,e){let t=[],i=[];for(let a=0;a<n.length;a++){let c=n[a],l=n.filter((u,h)=>h!==a);for(let u of["top","bottom","left","right"]){let h=p7t({board:c,edge:u,otherBoards:l,options:e});if(t.push(...h),e.mouseBites){let f=h7t({board:c,edge:u,edgeTabs:h,allBoards:l,options:e});i.push(...f)}}}let r=t.map((a,c)=>{let l=Math.min(a.width,a.height);return{type:"pcb_cutout",pcb_cutout_id:`panel_tab_${c}`,shape:"rect",center:a.center,width:a.width,height:a.height,corner_radius:l/2}}),s=e.tabWidth*.45,o=i.map((a,c)=>({type:"pcb_hole",pcb_hole_id:`panel_mouse_bite_${c}`,hole_shape:"circle",hole_diameter:s,x:a.x,y:a.y}));return{tabCutouts:r,mouseBiteHoles:o}}var ynt=class extends ml{constructor(){super(...arguments);d(this,"pcb_panel_id",null);d(this,"_tabsAndMouseBitesGenerated",!1)}get config(){return{componentName:"Panel",zodProps:EH}}get isGroup(){return!0}get isSubcircuit(){return!0}add(e){if(e.lowercaseComponentName!=="board")throw new Error("<panel> can only contain <board> elements");super.add(e)}doInitialPcbComponentAnchorAlignment(){if(this.root?.pcbDisabled)return;super.doInitialPcbComponentAnchorAlignment();let{db:e}=this.root,t=this.children.filter(a=>a instanceof y9),i=t.some(a=>a.props.pcbX!==void 0||a.props.pcbY!==void 0),r=t.filter(a=>a.props.pcbX===void 0&&a.props.pcbY===void 0);if(r.length>0&&!i){let a=this._parsedProps.tabWidth??jet,c=this._parsedProps.boardGap??a,l=Math.ceil(Math.sqrt(r.length)),u=Math.ceil(r.length/l),h=Array(l).fill(0),f=Array(u).fill(0);r.forEach((A,R)=>{let j=R%l,B=Math.floor(R/l),V=e.pcb_board.get(A.pcb_board_id);!V||V.width===void 0||V.height===void 0||(h[j]=Math.max(h[j],V.width),f[B]=Math.max(f[B],V.height))});let _=h.reduce((A,R)=>A+R,0)+(l>1?(l-1)*c:0),g=f.reduce((A,R)=>A+R,0)+(u>1?(u-1)*c:0),x=-_/2,P=[-g/2];for(let A=0;A<u-1;A++)P.push(P[A]+f[A]+c);let S=[x];for(let A=0;A<l-1;A++)S.push(S[A]+h[A]+c);r.forEach((A,R)=>{let j=R%l,B=Math.floor(R/l),V=e.pcb_board.get(A.pcb_board_id);if(!V||!V.width||!V.height)return;let U=S[j]+h[j]/2,H=P[B]+f[B]/2;A._repositionOnPcb({x:U,y:H}),e.pcb_board.update(A.pcb_board_id,{center:{x:U,y:H}})});let T=t.map(A=>A.pcb_board_id).filter(A=>!!A),k=e.pcb_board.list().filter(A=>T.includes(A.pcb_board_id)),C=1/0,M=1/0,I=-1/0,E=-1/0;for(let A of k){if(A.width===void 0||A.height===void 0||!isFinite(A.width)||!isFinite(A.height))continue;let R=A.center.x-A.width/2,j=A.center.x+A.width/2,B=A.center.y-A.height/2,V=A.center.y+A.height/2;C=Math.min(C,R),I=Math.max(I,j),M=Math.min(M,B),E=Math.max(E,V)}if(isFinite(C)){let A=I-C,R=E-M,j=A+2*Det,B=R+2*Det;e.pcb_panel.update(this.pcb_panel_id,{width:j,height:B})}}if(this._tabsAndMouseBitesGenerated)return;let s=this._parsedProps;if((s.panelizationMethod??"tab-routing")!=="none"){let a=t.map(_=>_.pcb_board_id).filter(_=>!!_),c=e.pcb_board.list().filter(_=>a.includes(_.pcb_board_id));if(c.length===0)return;let l=s.tabWidth??jet,u=s.boardGap??l,{tabCutouts:h,mouseBiteHoles:f}=d7t(c,{boardGap:u,tabWidth:l,tabLength:s.tabLength??c7t,mouseBites:s.mouseBites??!0});for(let _ of h)e.pcb_cutout.insert(_);for(let _ of f)e.pcb_hole.insert(_)}this._tabsAndMouseBitesGenerated=!0}runRenderCycle(){if(!this.children.some(e=>e.componentName==="Board"))throw new Error("<panel> must contain at least one <board>");super.runRenderCycle()}doInitialPcbComponentRender(){if(super.doInitialPcbComponentRender(),this.root?.pcbDisabled)return;let{db:e}=this.root,t=this._parsedProps,i=e.pcb_panel.insert({width:Y.parse(t.width),height:Y.parse(t.height),center:this._getGlobalPcbPositionBeforeLayout(),covered_with_solder_mask:!(t.noSolderMask??!1)});this.pcb_panel_id=i.pcb_panel_id}updatePcbComponentRender(){if(this.root?.pcbDisabled||!this.pcb_panel_id)return;let{db:e}=this.root,t=this._parsedProps;e.pcb_panel.update(this.pcb_panel_id,{width:Y.parse(t.width),height:Y.parse(t.height),center:this._getGlobalPcbPositionBeforeLayout(),covered_with_solder_mask:!(t.noSolderMask??!1)})}removePcbComponentRender(){this.pcb_panel_id&&(this.root?.db.pcb_panel.delete(this.pcb_panel_id),this.pcb_panel_id=null)}},f7t=new Proxy({},{get:(n,e)=>e}),Ua=f7t,rP="rgba(132, 0, 0)",sP=.12,g9=class extends Gn{constructor(){super(...arguments);d(this,"_adjustSilkscreenTextAutomatically",!0)}get config(){return{componentName:"Capacitor",schematicSymbolName:this.props.polarized?"capacitor_polarized":this.props.symbolName??"capacitor",zodProps:$H,sourceFtype:Ua.simple_capacitor}}initPorts(){typeof this.props.footprint=="string"?super.initPorts({additionalAliases:{pin1:["anode","pos"],pin2:["cathode","neg"]}}):super.initPorts()}_getSchematicSymbolDisplayValue(){let e=this.props.capacitance,t=typeof e=="string"?e:`${gi(this._parsedProps.capacitance)}F`;return this._parsedProps.schShowRatings&&this._parsedProps.maxVoltageRating?`${t}/${gi(this._parsedProps.maxVoltageRating)}V`:t}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.decouplingFor,this.props.decouplingTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.decouplingFor&&this.props.decouplingTo&&(this.add(new Ls({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.decouplingFor})),this.add(new Ls({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.decouplingTo}))),this._createTracesFromConnectionsProp()}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,i=e.source_component.insert({ftype:"simple_capacitor",name:this.name,manufacturer_part_number:t.manufacturerPartNumber??t.mfn,supplier_part_numbers:t.supplierPartNumbers,capacitance:t.capacitance,max_voltage_rating:t.maxVoltageRating,max_decoupling_trace_length:t.maxDecouplingTraceLength,display_capacitance:this._getSchematicSymbolDisplayValue(),are_pins_interchangeable:!t.polarized});this.source_component_id=i.source_component_id}},X1=class extends Gn{constructor(e){super(e);d(this,"schematicBoxDimensions",null)}get config(){return{componentName:"Chip",zodProps:e_,shouldRenderAsSchematicBox:!0}}initPorts(e={}){super.initPorts(e);let{_parsedProps:t}=this;if(t.externallyConnectedPins){let i=new Set;for(let[r,s]of t.externallyConnectedPins)i.add(r),i.add(s);for(let r of i)if(!this.children.find(o=>o instanceof Vi&&o.isMatchingAnyOf([r]))){let o=r.match(/^pin(\d+)$/);if(o){let a=parseInt(o[1]);this.add(new Vi({pinNumber:a,aliases:[r]}))}else this.add(new Vi({name:r,aliases:[r]}))}}}doInitialSchematicComponentRender(){let{_parsedProps:e}=this;e?.noSchematicRepresentation!==!0&&super.doInitialSchematicComponentRender()}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,i=e.source_component.insert({ftype:"simple_chip",name:this.name,manufacturer_part_number:t.manufacturerPartNumber,supplier_part_numbers:t.supplierPartNumbers});this.source_component_id=i.source_component_id}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=t.layer??"top";if(i!=="top"&&i!=="bottom"){let s=this.getSubcircuit(),o=Rm.parse({type:"pcb_component_invalid_layer_error",message:`Component cannot be placed on layer '${i}'. Components can only be placed on 'top' or 'bottom' layers.`,source_component_id:this.source_component_id,layer:i,subcircuit_id:s.subcircuit_id??void 0});e.pcb_component_invalid_layer_error.insert(o)}let r=e.pcb_component.insert({center:{x:t.pcbX??0,y:t.pcbY??0},width:2,height:3,layer:i==="top"||i==="bottom"?i:"top",rotation:t.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0,do_not_place:t.doNotPlace??!1,obstructs_within_bounds:t.obstructsWithinBounds??!0});this.pcb_component_id=r.pcb_component_id}doInitialCreateTracesFromProps(){let{_parsedProps:e}=this;if(e.externallyConnectedPins)for(let[t,i]of e.externallyConnectedPins)this.add(new Ls({from:`${this.getSubcircuitSelector()} > port.${t}`,to:`${this.getSubcircuitSelector()} > port.${i}`}));this._createTracesFromConnectionsProp()}doInitialSimulationRender(){let{db:e}=this.root,{pinAttributes:t}=this.props;if(!t)return;let i=null,r=null,s,o=this.selectAll("port");for(let h of o)for(let f of h.getNameAndAliases())if(t[f]){let _=t[f];_.providesPower&&(i=h,s=_.providesVoltage),_.providesGround&&(r=h)}if(!i||!r||s===void 0)return;let a=e.source_port.get(i.source_port_id);if(!a?.subcircuit_connectivity_map_key)return;let c=e.source_port.get(r.source_port_id);if(!c?.subcircuit_connectivity_map_key)return;let l=e.source_net.getWhere({subcircuit_connectivity_map_key:a.subcircuit_connectivity_map_key}),u=e.source_net.getWhere({subcircuit_connectivity_map_key:c.subcircuit_connectivity_map_key});!l||!u||e.simulation_voltage_source.insert({type:"simulation_voltage_source",positive_source_port_id:i.source_port_id,positive_source_net_id:l.source_net_id,negative_source_port_id:r.source_port_id,negative_source_net_id:u.source_net_id,voltage:s})}},gnt=class extends X1{constructor(n){super(n)}get config(){return{...super.config,componentName:"Pinout",zodProps:CH}}doInitialSourceRender(){let{db:n}=this.root,{_parsedProps:e}=this,t=n.source_component.insert({ftype:"simple_pinout",name:this.name,manufacturer_part_number:e.manufacturerPartNumber,supplier_part_numbers:e.supplierPartNumbers});this.source_component_id=t.source_component_id}},x9=class extends Gn{constructor(){super(...arguments);d(this,"pos",this.portMap.pin1);d(this,"anode",this.portMap.pin1);d(this,"neg",this.portMap.pin2);d(this,"cathode",this.portMap.pin2)}get config(){let e={schottky:"schottky_diode",avalanche:"avalanche_diode",zener:"zener_diode",photodiode:"photodiode"},t=this.props.schottky?"schottky":this.props.avalanche?"avalanche":this.props.zener?"zener":this.props.photo?"photodiode":null;return{schematicSymbolName:t?e[t]:this.props.symbolName??"diode",componentName:"Diode",zodProps:eW,sourceFtype:"simple_diode"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,i=e.source_component.insert({ftype:"simple_diode",name:this.name,manufacturer_part_number:t.manufacturerPartNumber??t.mfn,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},xnt=class extends Gn{get config(){return{componentName:"fuse",schematicSymbolName:this.props.symbolName??"fuse",zodProps:NH,sourceFtype:Ua.simple_fuse}}_getSchematicSymbolDisplayValue(){let n=this._parsedProps.currentRating,e=this._parsedProps.voltageRating,t=typeof n=="string"?parseFloat(n):n,i=typeof e=="string"?parseFloat(e):e;return`${gi(t)}A / ${gi(i)}V`}doInitialSourceRender(){let{db:n}=this.root,{_parsedProps:e}=this,t=typeof e.currentRating=="string"?parseFloat(e.currentRating):e.currentRating,i=typeof e.voltageRating=="string"?parseFloat(e.voltageRating):e.voltageRating,r=n.source_component.insert({name:this.name,ftype:Ua.simple_fuse,current_rating_amps:t,voltage_rating_volts:i,display_current_rating:`${gi(t)}A`,display_voltage_rating:`${gi(i)}V`});this.source_component_id=r.source_component_id}},bnt=class extends Gn{constructor(){super(...arguments);d(this,"schematicDimensions",null)}get config(){return{schematicSymbolName:void 0,componentName:"Jumper",zodProps:l4,shouldRenderAsSchematicBox:!0}}_getSchematicPortArrangement(){let e=super._getSchematicPortArrangement();if(e&&Object.keys(e).length>0)return e;let t=this._parsedProps.pinCount??(Array.isArray(this._parsedProps.pinLabels)?this._parsedProps.pinLabels.length:this._parsedProps.pinLabels?Object.keys(this._parsedProps.pinLabels).length:this.getPortsFromFootprint().length),i=this._parsedProps.schDirection??"right";return{leftSize:i==="left"?t:0,rightSize:i==="right"?t:0}}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,i=e.source_component.insert({ftype:"simple_chip",name:this.name,manufacturer_part_number:t.manufacturerPartNumber,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=i.source_component_id}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=e.pcb_component.insert({center:{x:t.pcbX??0,y:t.pcbY??0},width:2,height:3,layer:t.layer??"top",rotation:t.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0,do_not_place:t.doNotPlace??!1,obstructs_within_bounds:t.obstructsWithinBounds??!0});this.pcb_component_id=i.pcb_component_id}doInitialPcbTraceRender(){let{db:e}=this.root,t=e.pcb_port.list({pcb_component_id:this.pcb_component_id}),i={};for(let o=0;o<t.length;o++){let a=t[o],c=e.source_port.get(a.source_port_id),l="";if(typeof c?.pin_number=="number")l=c.pin_number.toString();else if(Array.isArray(c?.port_hints)){let u=c.port_hints.find(h=>/^(pin)?\d+$/.test(h));u&&(/^pin\d+$/.test(u)?l=u.replace(/^pin/,""):l=u)}i[l]=a.pcb_port_id}let r=e.pcb_trace.list({pcb_component_id:this.pcb_component_id}),s=o=>{if(o&&typeof o=="string"&&o.startsWith("{PIN")){let a=o.replace("{PIN","").replace("}","");return i[a]||o}return o};for(let o of r)if(o.route)for(let a of o.route)a.route_type==="wire"&&(a.start_pcb_port_id=s(a.start_pcb_port_id),a.end_pcb_port_id=s(a.end_pcb_port_id))}},vnt=class extends Gn{constructor(){super(...arguments);d(this,"schematicDimensions",null)}_getPinNumberFromBridgedPinName(e){return this.selectOne(`port.${e}`,{type:"port"})?._parsedProps.pinNumber??null}get defaultInternallyConnectedPinNames(){if(this._parsedProps.bridged){let e=this.children.filter(t=>t.componentName==="Port").map(t=>t.name);return e.length>0?[e]:[]}return this._parsedProps.bridgedPins??[]}get config(){let e=this._parsedProps??this.props,t=e.pinCount;if(e.pinCount==null&&!e.footprint&&(t=2),e.pinCount==null){let s=(e.bridgedPins??[]).flat().map(l=>this._getPinNumberFromBridgedPinName(l)).filter(l=>l!==null),o=s.length>0?Math.max(...s):0,a=e.pinLabels?Object.keys(e.pinLabels).length:0,c=Math.max(o,a);(c===2||c===3)&&(t=c),t==null&&e.footprint&&[2,3].includes(this.getPortsFromFootprint().length)&&(t=this.getPortsFromFootprint().length)}let i="";t?i+=`solderjumper${t}`:i="solderjumper";let r=[];return Array.isArray(e.bridgedPins)&&e.bridgedPins.length>0?r=Array.from(new Set(e.bridgedPins.flat().map(s=>this._getPinNumberFromBridgedPinName(s)).filter(s=>s!==null))).sort((s,o)=>s-o):e.bridged&&t&&(r=Array.from({length:t},(s,o)=>o+1)),r.length>0&&(i+=`_bridged${r.join("")}`),{schematicSymbolName:e.symbolName??i,componentName:"SolderJumper",zodProps:IH,shouldRenderAsSchematicBox:!0}}_getSchematicPortArrangement(){let e=super._getSchematicPortArrangement();if(e&&Object.keys(e).length>0)return e;let t=this._parsedProps.pinCount??(Array.isArray(this._parsedProps.pinLabels)?this._parsedProps.pinLabels.length:this._parsedProps.pinLabels?Object.keys(this._parsedProps.pinLabels).length:this.getPortsFromFootprint().length);t==null&&!this._parsedProps.footprint&&(t=2);let i=this._parsedProps.schDirection??"right";return{leftSize:i==="left"?t:0,rightSize:i==="right"?t:0}}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,i=e.source_component.insert({ftype:"simple_chip",name:this.name,manufacturer_part_number:t.manufacturerPartNumber,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=i.source_component_id}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=e.pcb_component.insert({center:{x:t.pcbX??0,y:t.pcbY??0},width:2,height:3,layer:t.layer??"top",rotation:t.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0,do_not_place:t.doNotPlace??!1,obstructs_within_bounds:t.obstructsWithinBounds??!0});this.pcb_component_id=i.pcb_component_id}doInitialPcbTraceRender(){let{db:e}=this.root,t=e.pcb_port.list({pcb_component_id:this.pcb_component_id}),i={};for(let o=0;o<t.length;o++){let a=t[o],c=e.source_port.get(a.source_port_id),l="";if(typeof c?.pin_number=="number")l=c.pin_number.toString();else if(Array.isArray(c?.port_hints)){let u=c.port_hints.find(h=>/^(pin)?\d+$/.test(h));u&&(/^pin\d+$/.test(u)?l=u.replace(/^pin/,""):l=u)}i[l]=a.pcb_port_id}let r=e.pcb_trace.list({pcb_component_id:this.pcb_component_id}),s=o=>{if(o&&typeof o=="string"&&o.startsWith("{PIN")){let a=o.replace("{PIN","").replace("}","");return i[a]||o}return o};for(let o of r)if(o.route)for(let a of o.route)a.route_type==="wire"&&(a.start_pcb_port_id=s(a.start_pcb_port_id),a.end_pcb_port_id=s(a.end_pcb_port_id))}},wnt=class extends Gn{constructor(){super(...arguments);d(this,"pos",this.portMap.pin1);d(this,"anode",this.portMap.pin1);d(this,"neg",this.portMap.pin2);d(this,"cathode",this.portMap.pin2)}get config(){let e={laser:"laser_diode"},t=this.props.laser?"laser":null;return{schematicSymbolName:t?e[t]:this.props.symbolName??"led",componentName:"Led",zodProps:iW,sourceFtype:"simple_led"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return this._parsedProps.schDisplayValue||this._parsedProps.color||void 0}getFootprinterString(){let e=super.getFootprinterString();return e&&this.props.color?`${e}_color(${this.props.color})`:e}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,i=e.source_component.insert({ftype:"simple_led",name:this.name,wave_length:t.wavelength,color:t.color,symbol_display_value:this._getSchematicSymbolDisplayValue(),manufacturer_part_number:t.manufacturerPartNumber??t.mfn,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},Snt=class extends Gn{constructor(){super(...arguments);d(this,"pos",this.portMap.pin1);d(this,"positive",this.portMap.pin1);d(this,"neg",this.portMap.pin2);d(this,"negative",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"power_factor_meter_horz",componentName:"PowerSource",zodProps:yW,sourceFtype:"simple_power_source"}}initPorts(){this.add(new Vi({name:"pin1",pinNumber:1,aliases:["positive","pos"]})),this.add(new Vi({name:"pin2",pinNumber:2,aliases:["negative","neg"]}))}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,i=e.source_component.insert({ftype:"simple_power_source",name:this.name,voltage:t.voltage,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},m7t=Kn.extend({voltage:Si.optional(),frequency:ur.optional(),peakToPeakVoltage:Si.optional(),waveShape:p.enum(["sinewave","square","triangle","sawtooth"]).optional(),phase:He.optional(),dutyCycle:p.number().optional()}),Pnt=class extends Gn{constructor(){super(...arguments);d(this,"terminal1",this.portMap.terminal1);d(this,"terminal2",this.portMap.terminal2)}get config(){return{componentName:"VoltageSource",schematicSymbolName:this.props.waveShape==="square"?"square_wave":"ac_voltmeter",zodProps:m7t,sourceFtype:"simple_voltage_source"}}runRenderPhaseForChildren(e){if(!e.startsWith("Pcb"))for(let t of this.children)t.runRenderPhaseForChildren(e),t.runRenderPhase(e)}doInitialPcbComponentRender(){}initPorts(){super.initPorts({additionalAliases:{pin1:["terminal1"],pin2:["terminal2"]}})}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,i=e.source_component.insert({ftype:"simple_voltage_source",name:this.name,voltage:t.voltage,frequency:t.frequency,peak_to_peak_voltage:t.peakToPeakVoltage,wave_shape:t.waveShape,phase:t.phase,duty_cycle:t.dutyCycle,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=i.source_component_id}doInitialSimulationRender(){let{db:e}=this.root,{_parsedProps:t}=this,i=this.portMap.terminal1,r=this.portMap.terminal2;e.simulation_voltage_source.insert({type:"simulation_voltage_source",is_dc_source:!1,terminal1_source_port_id:i.source_port_id,terminal2_source_port_id:r.source_port_id,voltage:t.voltage,frequency:t.frequency,peak_to_peak_voltage:t.peakToPeakVoltage,wave_shape:t.waveShape,phase:t.phase,duty_cycle:t.dutyCycle})}},b9=class extends Gn{constructor(){super(...arguments);d(this,"_adjustSilkscreenTextAutomatically",!0)}get config(){return{componentName:"Resistor",schematicSymbolName:this.props.symbolName??"boxresistor",zodProps:RH,sourceFtype:"simple_resistor"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${gi(this._parsedProps.resistance)}\u03A9`}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.pullupFor,this.props.pullupTo,this.props.pulldownFor,this.props.pulldownTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.pullupFor&&this.props.pullupTo&&(this.add(new Ls({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pullupFor})),this.add(new Ls({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pullupTo}))),this.props.pulldownFor&&this.props.pulldownTo&&(this.add(new Ls({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pulldownFor})),this.add(new Ls({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pulldownTo}))),this._createTracesFromConnectionsProp()}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,i=e.source_component.insert({ftype:"simple_resistor",name:this.name,manufacturer_part_number:t.manufacturerPartNumber??t.mfn,supplier_part_numbers:t.supplierPartNumbers,resistance:t.resistance,display_resistance:this._getSchematicSymbolDisplayValue(),are_pins_interchangeable:!0});this.source_component_id=i.source_component_id}},_7t=["leftedge","rightedge","topedge","bottomedge","center"],knt=class extends Me{get config(){return{componentName:"Constraint",zodProps:jH}}constructor(n){if(super(n),("xdist"in n||"ydist"in n)&&!("edgeToEdge"in n)&&!("centerToCenter"in n))throw new Error(`edgeToEdge, centerToCenter must be set for xDist or yDist for ${this}`);if("for"in n&&n.for.length<2)throw new Error(`"for" must have at least two selectors for ${this}`)}_getAllReferencedComponents(){let n=[],e=this.getPrimitiveContainer();function t(i){let r=i.split(" ").pop(),s=_7t.includes(r)?r:void 0,o=s?i.replace(` ${s}`,""):i,a=e.selectOne(o,{pcbPrimitive:!0});a&&n.push({selector:i,component:a,componentSelector:o,edge:s})}for(let i of["left","right","top","bottom"])i in this._parsedProps&&t(this._parsedProps[i]);if("for"in this._parsedProps)for(let i of this._parsedProps.for)t(i);return{componentsWithSelectors:n}}},Tnt=class extends Me{constructor(){super(...arguments);d(this,"fabrication_note_rect_id",null)}get config(){return{componentName:"FabricationNoteRect",zodProps:aW}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),r=i(t.layer??"top");if(r!=="top"&&r!=="bottom")throw new Error(`Invalid layer "${r}" for FabricationNoteRect. Must be "top" or "bottom".`);let s=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id,o=this.getSubcircuit(),a=t.hasStroke??(t.strokeWidth!==void 0&&t.strokeWidth!==null),c=e.pcb_fabrication_note_rect.insert({pcb_component_id:s,layer:r,color:t.color,center:{x:t.pcbX??0,y:t.pcbY??0},width:t.width,height:t.height,stroke_width:t.strokeWidth??1,is_filled:t.isFilled??!1,has_stroke:a,is_stroke_dashed:t.isStrokeDashed??!1,subcircuit_id:o?.subcircuit_id??void 0,pcb_group_id:this.getGroup()?.pcb_group_id??void 0,corner_radius:t.cornerRadius??void 0});this.fabrication_note_rect_id=c.pcb_fabrication_note_rect_id}getPcbSize(){let{_parsedProps:e}=this;return{width:e.width,height:e.height}}},Mnt=class extends Me{constructor(){super(...arguments);d(this,"fabrication_note_path_id",null)}get config(){return{componentName:"FabricationNotePath",zodProps:cW}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,t=this.getSubcircuit(),{_parsedProps:i}=this,r=i.layer??"top";if(r!=="top"&&r!=="bottom")throw new Error(`Invalid layer "${r}" for SilkscreenPath. Must be "top" or "bottom".`);let s=this._computePcbGlobalTransformBeforeLayout(),o=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id,a=e.pcb_fabrication_note_path.insert({pcb_component_id:o,layer:r,color:i.color,route:i.route.map(c=>{let l=$e(s,{x:c.x,y:c.y});return{...c,x:l.x,y:l.y}}),stroke_width:i.strokeWidth??.1,subcircuit_id:t?.subcircuit_id??void 0});this.fabrication_note_path_id=a.pcb_fabrication_note_path_id}},Ent=class extends Me{get config(){return{componentName:"FabricationNoteText",zodProps:oW}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:n}=this.root,{_parsedProps:e}=this,t=this.getPrimitiveContainer(),i=this.getSubcircuit();n.pcb_fabrication_note_text.insert({anchor_alignment:e.anchorAlignment,anchor_position:{x:e.pcbX??0,y:e.pcbY??0},font:e.font??"tscircuit2024",font_size:e.fontSize??1,layer:"top",color:e.color,text:e.text??"",pcb_component_id:t.pcb_component_id,subcircuit_id:i?.subcircuit_id??void 0,pcb_group_id:this.getGroup()?.pcb_group_id??void 0})}},Cnt=class extends Me{constructor(){super(...arguments);d(this,"fabrication_note_dimension_id",null);d(this,"isPcbPrimitive",!0)}get config(){return{componentName:"FabricationNoteDimension",zodProps:lW}}_resolvePoint(e,t){if(typeof e=="string"){let s=this.getSubcircuit().selectOne(e);return s?s._getGlobalPcbPositionBeforeLayout():(this.renderError(`FabricationNoteDimension could not find selector "${e}"`),$e(t,{x:0,y:0}))}let i=typeof e.x=="string"?parseFloat(e.x):e.x,r=typeof e.y=="string"?parseFloat(e.y):e.y;return $e(t,{x:i,y:r})}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=this._computePcbGlobalTransformBeforeLayout(),r=this._resolvePoint(t.from,i),s=this._resolvePoint(t.to,i),o=this.getSubcircuit(),a=this.getGroup(),{maybeFlipLayer:c}=this._getPcbPrimitiveFlippedHelpers(),l=c(t.layer??"top");if(l!=="top"&&l!=="bottom")throw new Error(`Invalid layer "${l}" for FabricationNoteDimension. Must be "top" or "bottom".`);let u=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id,h=t.text??this._formatDistanceText({from:r,to:s,units:t.units??"mm"}),f=e.pcb_fabrication_note_dimension.insert({pcb_component_id:u,subcircuit_id:o?.subcircuit_id??void 0,pcb_group_id:a?.pcb_group_id??void 0,layer:l,from:r,to:s,text:h,offset:t.offset,font:t.font??"tscircuit2024",font_size:t.fontSize??1,color:t.color,arrow_size:t.arrowSize??1});this.fabrication_note_dimension_id=f.pcb_fabrication_note_dimension_id}getPcbSize(){let e=this._computePcbGlobalTransformBeforeLayout(),t=this._resolvePoint(this._parsedProps.from,e),i=this._resolvePoint(this._parsedProps.to,e);return{width:Math.abs(i.x-t.x),height:Math.abs(i.y-t.y)}}_formatDistanceText({from:e,to:t,units:i}){let r=t.x-e.x,s=t.y-e.y,o=Math.sqrt(r*r+s*s),a=i==="in"?o/25.4:o,c=Math.round(a);if(Math.abs(a-c)<1e-9)return`${c}${i}`;let u=i==="in"?3:2;return`${i==="in"?Number(a.toFixed(u)).toString():a.toFixed(u)}${i}`}},Int=class extends Me{constructor(){super(...arguments);d(this,"pcb_note_line_id",null);d(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbNoteLine",zodProps:zW}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=this.getSubcircuit(),r=this.getGroup(),s=this._computePcbGlobalTransformBeforeLayout(),o=$e(s,{x:t.x1,y:t.y1}),a=$e(s,{x:t.x2,y:t.y2}),c=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id??void 0,l=e.pcb_note_line.insert({pcb_component_id:c,subcircuit_id:i?.subcircuit_id??void 0,pcb_group_id:r?.pcb_group_id??void 0,x1:o.x,y1:o.y,x2:a.x,y2:a.y,stroke_width:t.strokeWidth??.1,color:t.color,is_dashed:t.isDashed});this.pcb_note_line_id=l.pcb_note_line_id}getPcbSize(){let{_parsedProps:e}=this;return{width:Math.abs(e.x2-e.x1),height:Math.abs(e.y2-e.y1)}}},Nnt=class extends Me{constructor(){super(...arguments);d(this,"pcb_note_rect_id",null);d(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbNoteRect",zodProps:LW}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=this._computePcbGlobalTransformBeforeLayout(),r=$e(i,{x:0,y:0}),s=this.getSubcircuit(),o=this.getGroup(),a=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id??void 0,c=e.pcb_note_rect.insert({pcb_component_id:a,subcircuit_id:s?.subcircuit_id??void 0,pcb_group_id:o?.pcb_group_id??void 0,center:r,width:t.width,height:t.height,stroke_width:t.strokeWidth??.1,is_filled:t.isFilled??!1,has_stroke:t.hasStroke??!0,is_stroke_dashed:t.isStrokeDashed??!1,color:t.color,corner_radius:t.cornerRadius??void 0});this.pcb_note_rect_id=c.pcb_note_rect_id}getPcbSize(){let{_parsedProps:e}=this,t=typeof e.width=="string"?parseFloat(e.width):e.width,i=typeof e.height=="string"?parseFloat(e.height):e.height;return{width:t,height:i}}},Ant=class extends Me{constructor(){super(...arguments);d(this,"pcb_note_text_id",null);d(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbNoteText",zodProps:OW}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=this._computePcbGlobalTransformBeforeLayout(),r=$e(i,{x:0,y:0}),s=this.getSubcircuit(),o=this.getGroup(),a=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id??void 0,c=e.pcb_note_text.insert({pcb_component_id:a,subcircuit_id:s?.subcircuit_id??void 0,pcb_group_id:o?.pcb_group_id??void 0,font:t.font??"tscircuit2024",font_size:t.fontSize??1,text:t.text,anchor_position:r,anchor_alignment:t.anchorAlignment??"center",color:t.color});this.pcb_note_text_id=c.pcb_note_text_id}getPcbSize(){let{_parsedProps:e}=this,t=typeof e.fontSize=="string"?parseFloat(e.fontSize):e.fontSize??1,i=t*.6;return{width:e.text.length*i,height:t}}},Rnt=class extends Me{constructor(){super(...arguments);d(this,"pcb_note_path_id",null);d(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbNotePath",zodProps:FW}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=this._computePcbGlobalTransformBeforeLayout(),r=this.getSubcircuit(),s=this.getGroup(),o=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id??void 0,a=t.route.map(l=>{let{x:u,y:h,...f}=l,_=typeof u=="string"?parseFloat(u):u,g=typeof h=="string"?parseFloat(h):h,x=$e(i,{x:_,y:g});return{...f,x:x.x,y:x.y}}),c=e.pcb_note_path.insert({pcb_component_id:o,subcircuit_id:r?.subcircuit_id??void 0,pcb_group_id:s?.pcb_group_id??void 0,route:a,stroke_width:t.strokeWidth??.1,color:t.color});this.pcb_note_path_id=c.pcb_note_path_id}getPcbSize(){let{_parsedProps:e}=this;if(e.route.length===0)return{width:0,height:0};let t=e.route.map(c=>typeof c.x=="string"?parseFloat(c.x):c.x),i=e.route.map(c=>typeof c.y=="string"?parseFloat(c.y):c.y),r=Math.min(...t),s=Math.max(...t),o=Math.min(...i),a=Math.max(...i);return{width:s-r,height:a-o}}},Ont=class extends Me{constructor(){super(...arguments);d(this,"pcb_note_dimension_id",null);d(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbNoteDimension",zodProps:$W}}_resolvePoint(e,t){if(typeof e=="string"){let s=this.getSubcircuit().selectOne(`.${e}`);return s?s._getGlobalPcbPositionBeforeLayout():(this.renderError(`PcbNoteDimension could not find selector "${e}"`),$e(t,{x:0,y:0}))}let i=typeof e.x=="string"?parseFloat(e.x):e.x,r=typeof e.y=="string"?parseFloat(e.y):e.y;return $e(t,{x:i,y:r})}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=this._computePcbGlobalTransformBeforeLayout(),r=this._resolvePoint(t.from,i),s=this._resolvePoint(t.to,i),o=this.getSubcircuit(),a=this.getGroup(),c=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id??void 0,l=t.text??this._formatDistanceText({from:r,to:s,units:t.units??"mm"}),u=e.pcb_note_dimension.insert({pcb_component_id:c,subcircuit_id:o?.subcircuit_id??void 0,pcb_group_id:a?.pcb_group_id??void 0,from:r,to:s,text:l,font:t.font??"tscircuit2024",font_size:t.fontSize??1,color:t.color,arrow_size:t.arrowSize??1});this.pcb_note_dimension_id=u.pcb_note_dimension_id}getPcbSize(){let e=this._computePcbGlobalTransformBeforeLayout(),t=this._resolvePoint(this._parsedProps.from,e),i=this._resolvePoint(this._parsedProps.to,e);return{width:Math.abs(i.x-t.x),height:Math.abs(i.y-t.y)}}_formatDistanceText({from:e,to:t,units:i}){let r=t.x-e.x,s=t.y-e.y,o=Math.sqrt(r*r+s*s),a=i==="in"?o/25.4:o,c=Math.round(a);if(Math.abs(a-c)<1e-9)return`${c}${i}`;let u=i==="in"?3:2;return`${i==="in"?Number(a.toFixed(u)).toString():a.toFixed(u)}${i}`}},q_=(n,e)=>{let{injectionDb:t,normalComponent:i}=e;if(!i)return;let r=G_({componentName:i.name,componentRotation:"0deg"},t.toArray().filter(s=>"pcb_component_id"in s&&s.pcb_component_id===n.pcb_component_id));i.addAll(r)};function y7t(n,e){let{injectionDb:t,subcircuit:i,groupsMap:r}=e,s=t.pcb_component.getWhere({source_component_id:n.source_component_id}),o=t.cad_component.getWhere({source_component_id:n.source_component_id}),a=new b9({name:n.name,resistance:n.resistance});s&&q_(s,{...e,normalComponent:a}),n.source_group_id&&r?.has(n.source_group_id)?r.get(n.source_group_id).add(a):i.add(a)}function g7t(n,e){let{injectionDb:t,subcircuit:i}=e;if(n.source_component_id!==null)return;let r=t.pcb_port.getWhere({source_port_id:n.source_port_id}),s=new Vi({name:n.name,pinNumber:n.pin_number});i.add(s),s.source_port_id=n.source_port_id;let o=i.root;if(o&&r){let{db:a}=o,c=a.pcb_port.insert({pcb_component_id:void 0,layers:r.layers,subcircuit_id:i.subcircuit_id??void 0,pcb_group_id:i.getGroup()?.pcb_group_id??void 0,x:r.x,y:r.y,source_port_id:n.source_port_id,is_board_pinout:!1});s.pcb_port_id=c.pcb_port_id}}function x7t(n,e){let{subcircuit:t,groupsMap:i}=e,r=new ml({name:n.name});return r.source_group_id=n.source_group_id,t.add(r),i&&i.set(n.source_group_id,r),r}var b7t=(n,e)=>{if(!n||n.length===0)return;let{injectionDb:t}=e,i=n.map(r=>r.map(s=>{let o=t.source_port.get(s);return o?o.pin_number!==void 0&&o.pin_number!==null?`pin${o.pin_number}`:o.name:null}).filter(s=>s!==null)).filter(r=>r.length>0);return i.length>0?i:void 0},v7t=(n,e)=>{let{injectionDb:t,subcircuit:i,groupsMap:r}=e,s=t.pcb_component.getWhere({source_component_id:n.source_component_id}),o=t.schematic_component.getWhere({source_component_id:n.source_component_id}),a=t.cad_component.getWhere({source_component_id:n.source_component_id}),c=b7t(n.internally_connected_source_port_ids,e),l=new X1({name:n.name,manufacturerPartNumber:n.manufacturer_part_number,supplierPartNumbers:n.supplier_part_numbers??void 0,pinLabels:o?.port_labels??void 0,schWidth:o?.size?.width,schHeight:o?.size?.height,schPinSpacing:o?.pin_spacing,schX:o?.center?.x,schY:o?.center?.y,layer:s?.layer,pcbX:s?.center?.x,pcbY:s?.center?.y,pcbRotation:s?.rotation,doNotPlace:s?.do_not_place,obstructsWithinBounds:s?.obstructs_within_bounds,internallyConnectedPins:c}),u=a?.footprinter_string??"soic8";u&&(Object.assign(l.props,{footprint:u}),Object.assign(l._parsedProps,{footprint:u}),a||l._addChildrenFromStringFootprint?.()),s&&q_(s,{...e,normalComponent:l}),n.source_group_id&&r?.has(n.source_group_id)?r.get(n.source_group_id).add(l):i.add(l)};function w7t(n,e){let{injectionDb:t,subcircuit:i,groupsMap:r}=e,s=t.pcb_component.getWhere({source_component_id:n.source_component_id}),o=t.cad_component.getWhere({source_component_id:n.source_component_id}),a=new g9({name:n.name,capacitance:n.capacitance});s&&q_(s,{...e,normalComponent:a}),n.source_group_id&&r?.has(n.source_group_id)?r.get(n.source_group_id).add(a):i.add(a)}var v9=class extends Gn{constructor(){super(...arguments);d(this,"_adjustSilkscreenTextAutomatically",!0)}get config(){return{componentName:"Inductor",schematicSymbolName:this.props.symbolName??"inductor",zodProps:tW,sourceFtype:Ua.simple_inductor}}_getSchematicSymbolDisplayValue(){return`${gi(this._parsedProps.inductance)}H`}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,i=e.source_component.insert({name:this.name,ftype:Ua.simple_inductor,inductance:t.inductance,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=i.source_component_id}};function S7t(n,e){let{injectionDb:t,subcircuit:i,groupsMap:r}=e,s=t.pcb_component.getWhere({source_component_id:n.source_component_id}),o=t.cad_component.getWhere({source_component_id:n.source_component_id}),a=new v9({name:n.name,inductance:n.inductance});s&&q_(s,{...e,normalComponent:a}),n.source_group_id&&r?.has(n.source_group_id)?r.get(n.source_group_id).add(a):i.add(a)}function P7t(n,e){let{injectionDb:t,subcircuit:i,groupsMap:r}=e,s=t.pcb_component.getWhere({source_component_id:n.source_component_id}),o=t.cad_component.getWhere({source_component_id:n.source_component_id}),a=new x9({name:n.name});s&&q_(s,{...e,normalComponent:a}),n.source_group_id&&r?.has(n.source_group_id)?r.get(n.source_group_id).add(a):i.add(a)}var k7t=(n,e)=>{let t=[],i=n.source_group_id;for(;i;){let r=e.source_group.get(i);if(!r)break;t.unshift(`.${r.name}`),i=r.parent_source_group_id}return t.push(`.${n.name}`),t.join(" > ")};function T7t(n,e){let{injectionDb:t,subcircuit:i}=e,r=[];for(let o of n.connected_source_port_ids){let a=t.source_port.get(o);if(!a)continue;let c;if(a.source_component_id){let l=t.source_component.get(a.source_component_id);l&&(c=`${k7t({name:l.name,source_group_id:l.source_group_id},t)} > .${a.name}`)}else c=`.${a.name}`;c&&r.push(c)}for(let o of n.connected_source_net_ids){let a=t.source_net.get(o);a&&r.push(`net.${a.name}`)}if(r.length<2)return;let s=new Ls({path:r});s.source_trace_id=n.source_trace_id,i.add(s)}var w9=class extends Gn{constructor(){super(...arguments);d(this,"emitter",this.portMap.pin1);d(this,"collector",this.portMap.pin2);d(this,"base",this.portMap.pin3)}get config(){let e=this.props.type==="npn"?"npn_bipolar_transistor":"pnp_bipolar_transistor";return{componentName:"Transistor",schematicSymbolName:this.props.symbolName??e,zodProps:JH,sourceFtype:"simple_transistor",shouldRenderAsSchematicBox:!1}}initPorts(){let e={pin1:["collector","c"],pin2:["emitter","e"],pin3:["base","b"]};super.initPorts({pinCount:3,additionalAliases:e})}doInitialCreateNetsFromProps(){this._createNetsFromProps([...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this._createTracesFromConnectionsProp()}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,i=e.source_component.insert({ftype:"simple_transistor",name:this.name,transistor_type:t.type});this.source_component_id=i.source_component_id}};function M7t(n,e){let{injectionDb:t,subcircuit:i,groupsMap:r}=e,s=t.pcb_component.getWhere({source_component_id:n.source_component_id}),o=t.cad_component.getWhere({source_component_id:n.source_component_id}),a=new w9({name:n.name,type:n.transistor_type});s&&q_(s,{...e,normalComponent:a}),n.source_group_id&&r?.has(n.source_group_id)?r.get(n.source_group_id).add(a):i.add(a)}var Lnt=class extends ml{constructor(n){super({...n,subcircuit:!0})}doInitialInflateSubcircuitCircuitJson(){let{circuitJson:n,children:e}=this._parsedProps;if(!n)return;let t=Ke(n);if(n&&e?.length>0)throw new Error("Subcircuit cannot have both circuitJson and children");let r={injectionDb:t,subcircuit:this,groupsMap:new Map},s=t.source_group.list();for(let l of s)x7t(l,r);let o=t.source_component.list();for(let l of o)switch(l.ftype){case"simple_resistor":y7t(l,r);break;case"simple_capacitor":w7t(l,r);break;case"simple_inductor":S7t(l,r);break;case"simple_diode":P7t(l,r);break;case"simple_chip":v7t(l,r);break;case"simple_transistor":M7t(l,r);break;default:throw new Error(`No inflator implemented for source component ftype: "${l.ftype}"`)}let a=t.source_port.list();for(let l of a)g7t(l,r);let c=t.source_trace.list();for(let l of c)T7t(l,r)}},Fnt=class extends ml{constructor(n){super({...n,subcircuit:!0})}doInitialPcbPrimitiveRender(){if(super.doInitialPcbPrimitiveRender(),this.root?.pcbDisabled)return;let{db:n}=this.root,e=this._parsedProps;if(!this.pcb_group_id)return;let t=n.pcb_group.get(this.pcb_group_id),i=e.paddingLeft??e.padding??0,r=e.paddingRight??e.padding??0,s=e.paddingTop??e.padding??0,o=e.paddingBottom??e.padding??0;n.pcb_group.update(this.pcb_group_id,{width:(t.width??0)+i+r,height:(t.height??0)+s+o,center:{x:t.center.x+(r-i)/2,y:t.center.y+(s-o)/2}})}},znt=class extends Me{constructor(){super(...arguments);d(this,"pcb_breakout_point_id",null);d(this,"matchedPort",null);d(this,"matchedNet",null);d(this,"isPcbPrimitive",!0)}get config(){return{componentName:"BreakoutPoint",zodProps:hW}}_matchConnection(){let{connection:e}=this._parsedProps,t=this.getSubcircuit();t&&(this.matchedPort=t.selectOne(e,{type:"port"}),this.matchedPort||(this.matchedNet=t.selectOne(e,{type:"net"})),!this.matchedPort&&!this.matchedNet&&this.renderError(`Could not find connection target "${e}"`))}_getSourceTraceIdForPort(e){let{db:t}=this.root;return t.source_trace.list().find(r=>r.connected_source_port_ids.includes(e.source_port_id))?.source_trace_id}_getSourceNetIdForPort(e){let{db:t}=this.root;return t.source_trace.list().find(r=>r.connected_source_port_ids.includes(e.source_port_id))?.connected_source_net_ids[0]}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root;this._matchConnection();let{pcbX:t=0,pcbY:i=0}=this._parsedProps,r=this.parent?.getGroup(),s=this.getSubcircuit();if(!r||!r.pcb_group_id)return;let o=e.pcb_breakout_point.insert({pcb_group_id:r.pcb_group_id,subcircuit_id:s?.subcircuit_id??void 0,source_port_id:this.matchedPort?.source_port_id??void 0,source_trace_id:this.matchedPort?this._getSourceTraceIdForPort(this.matchedPort):void 0,source_net_id:this.matchedNet?this.matchedNet.source_net_id:this.matchedPort?this._getSourceNetIdForPort(this.matchedPort):void 0,x:t,y:i});this.pcb_breakout_point_id=o.pcb_breakout_point_id}_getPcbCircuitJsonBounds(){let{pcbX:e=0,pcbY:t=0}=this._parsedProps;return{center:{x:e,y:t},bounds:{left:e,top:t,right:e,bottom:t},width:0,height:0}}_setPositionFromLayout(e){let{db:t}=this.root;this.pcb_breakout_point_id&&t.pcb_breakout_point.update(this.pcb_breakout_point_id,{x:e.x,y:e.y})}getPcbSize(){return{width:0,height:0}}},$nt=class extends Me{constructor(){super(...arguments);d(this,"source_net_label_id")}get config(){return{componentName:"NetLabel",zodProps:qH}}_getAnchorSide(){let{_parsedProps:e}=this;if(e.anchorSide)return e.anchorSide;if(!this._resolveConnectsTo())return"right";let i=this._getGlobalSchematicPositionBeforeLayout(),r=this._getConnectedPorts();if(r.length===0)return"right";let s=r[0]._getGlobalSchematicPositionBeforeLayout(),o=s.x-i.x,a=s.y-i.y;if(Math.abs(o)>Math.abs(a)){if(o>0)return"right";if(o<0)return"left"}else{if(a>0)return"top";if(a<0)return"bottom"}return"right"}_getConnectedPorts(){let e=this._resolveConnectsTo();if(!e)return[];let t=[];for(let i of e){let r=this.getSubcircuit().selectOne(i);r&&t.push(r)}return t}computeSchematicPropsTransform(){let{_parsedProps:e}=this;if(e.schX===void 0&&e.schY===void 0){let t=this._getConnectedPorts();if(t.length>0){let i=t[0]._getGlobalSchematicPositionBeforeLayout(),r=$e(this.parent?.computeSchematicGlobalTransform?.()??Sr(),{x:0,y:0});return An(i.x-r.x,i.y-r.y)}}return super.computeSchematicPropsTransform()}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=this._getGlobalSchematicPositionBeforeLayout(),r=this.getSubcircuit().selectOne(`net.${this._getNetName()}`),s=t.anchorSide??"right",o=fl({anchor_position:i,anchor_side:s,text:t.net}),a=e.schematic_net_label.insert({text:t.net,source_net_id:r.source_net_id,anchor_position:i,center:o,anchor_side:this._getAnchorSide()});this.source_net_label_id=a.source_net_id}_resolveConnectsTo(){let{_parsedProps:e}=this,t=e.connectsTo??e.connection;if(Array.isArray(t))return t;if(typeof t=="string")return[t]}_getNetName(){let{_parsedProps:e}=this;return e.net}doInitialCreateNetsFromProps(){let{_parsedProps:e}=this;e.net&&eP(this,[`net.${e.net}`])}doInitialCreateTracesFromNetLabels(){if(this.root?.schematicDisabled)return;let e=this._resolveConnectsTo();if(e)for(let t of e)this.add(new Ls({from:t,to:`net.${this._getNetName()}`}))}doInitialSchematicTraceRender(){if(!this.root?._featureMspSchematicTraceRouting||this.root?.schematicDisabled)return;let{db:e}=this.root,t=this._resolveConnectsTo();if(!t||t.length===0)return;let i=this._getGlobalSchematicPositionBeforeLayout(),r=this._getAnchorSide(),o={left:"x-",right:"x+",top:"y+",bottom:"y-"}[r],a=this.getSubcircuit().selectOne(`net.${this._getNetName()}`);for(let c of t){let l=this.getSubcircuit().selectOne(c,{type:"port"});if(!l||!l.schematic_port_id)continue;let u=!1;if(a?.source_net_id){let P=e.source_trace.list().find(S=>S.connected_source_net_ids?.includes(a.source_net_id)&&S.connected_source_port_ids?.includes(l.source_port_id??""));if(P&&(u=e.schematic_trace.list().some(S=>S.source_trace_id===P.source_trace_id)),u)continue}let h=l._getGlobalSchematicPositionAfterLayout(),f=n9(l.facingDirection??"right")??"x+",_=Hc({x:h.x,y:h.y,facingDirection:f},{x:i.x,y:i.y,facingDirection:o});if(!Array.isArray(_)||_.length<2)continue;let g=[];for(let P=0;P<_.length-1;P++)g.push({from:{x:_[P].x,y:_[P].y},to:{x:_[P+1].x,y:_[P+1].y}});let x,v;if(a?.source_net_id&&l.source_port_id){let P=e.source_trace.list().find(S=>S.connected_source_net_ids?.includes(a.source_net_id)&&S.connected_source_port_ids?.includes(l.source_port_id));x=P?.source_trace_id,v=P?.subcircuit_connectivity_map_key||e.source_net.get(a.source_net_id)?.subcircuit_connectivity_map_key}e.schematic_trace.insert({source_trace_id:x,edges:g,junctions:[],subcircuit_connectivity_map_key:v}),e.schematic_port.update(l.schematic_port_id,{is_connected:!0})}}},Dnt=class extends Me{constructor(){super(...arguments);d(this,"pcb_silkscreen_circle_id",null);d(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenCircle",zodProps:AW}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),r=i(t.layer??"top");if(r!=="top"&&r!=="bottom")throw new Error(`Invalid layer "${r}" for SilkscreenCircle. Must be "top" or "bottom".`);let s=this._computePcbGlobalTransformBeforeLayout(),o=this.getSubcircuit(),a=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id,c=e.pcb_silkscreen_circle.insert({pcb_component_id:a,layer:r,center:{x:t.pcbX??0,y:t.pcbY??0},radius:t.radius,subcircuit_id:o?.subcircuit_id??void 0,pcb_group_id:this.getGroup()?.pcb_group_id??void 0,stroke_width:t.strokeWidth??.1});this.pcb_silkscreen_circle_id=c.pcb_silkscreen_circle_id}getPcbSize(){let{_parsedProps:e}=this,t=e.radius*2;return{width:t,height:t}}},jnt=class extends Me{constructor(){super(...arguments);d(this,"pcb_silkscreen_rect_id",null);d(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenRect",zodProps:NW}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),r=i(t.layer??"top");if(r!=="top"&&r!=="bottom")throw new Error(`Invalid layer "${r}" for SilkscreenRect. Must be "top" or "bottom".`);let s=this.getSubcircuit(),o=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id,a=e.pcb_silkscreen_rect.insert({pcb_component_id:o,layer:r,center:{x:t.pcbX??0,y:t.pcbY??0},width:t.width,height:t.height,subcircuit_id:s?.subcircuit_id??void 0,pcb_group_id:this?.getGroup()?.pcb_group_id??void 0,stroke_width:t.strokeWidth??.1,is_filled:t.filled??!1,corner_radius:t.cornerRadius??void 0});this.pcb_silkscreen_rect_id=a.pcb_silkscreen_rect_id}getPcbSize(){let{_parsedProps:e}=this;return{width:e.width,height:e.height}}},Bnt=class extends Me{constructor(){super(...arguments);d(this,"pcb_silkscreen_line_id",null);d(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenLine",zodProps:IW}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),r=i(t.layer??"top");if(r!=="top"&&r!=="bottom")throw new Error(`Invalid layer "${r}" for SilkscreenLine. Must be "top" or "bottom".`);let s=this.getSubcircuit(),o=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id,a=e.pcb_silkscreen_line.insert({pcb_component_id:o,layer:r,x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke_width:t.strokeWidth??.1,subcircuit_id:s?.subcircuit_id??void 0,pcb_group_id:s?.getGroup()?.pcb_group_id??void 0});this.pcb_silkscreen_line_id=a.pcb_silkscreen_line_id}getPcbSize(){let{_parsedProps:e}=this,t=Math.abs(e.x2-e.x1),i=Math.abs(e.y2-e.y1);return{width:t,height:i}}},Ynt=class extends Me{constructor(e){super(e);d(this,"pcb_via_id",null);d(this,"matchedPort",null);d(this,"isPcbPrimitive",!0);d(this,"source_manually_placed_via_id",null);d(this,"subcircuit_connectivity_map_key",null);let t=this._getLayers();this._parsedProps.layers=t,this.initPorts()}get config(){return{componentName:"Via",zodProps:uW}}getAvailablePcbLayers(){return["top","inner1","inner2","bottom"]}getPcbSize(){let{_parsedProps:e}=this;return{width:e.outerDiameter,height:e.outerDiameter}}_getPcbCircuitJsonBounds(){let{db:e}=this.root,t=e.pcb_via.get(this.pcb_via_id),i=this.getPcbSize();return{center:{x:t.x,y:t.y},bounds:{left:t.x-i.width/2,top:t.y-i.height/2,right:t.x+i.width/2,bottom:t.y+i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(e){let{db:t}=this.root;t.pcb_via.update(this.pcb_via_id,{x:e.x,y:e.y})}_getLayers(){let{fromLayer:e="top",toLayer:t="bottom"}=this._parsedProps;return e===t?[e]:[e,t]}initPorts(){let e=this._parsedProps.layers;for(let i of e){let r=new Vi({name:i,layer:i});r.registerMatch(this),this.add(r)}let t=new Vi({name:"pin1"});t.registerMatch(this),this.add(t)}_getConnectedNetOrTrace(){let e=this._parsedProps.connectsTo;if(!e)return null;let t=this.getSubcircuit(),i=Array.isArray(e)?e:[e];for(let r of i)if(r.startsWith("net.")){let s=t.selectOne(r,{type:"net"});if(s)return s}return null}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=this._getGlobalPcbPositionBeforeLayout(),r=this.getSubcircuit(),s=e.pcb_component.insert({center:i,width:t.outerDiameter,height:t.outerDiameter,layer:t.fromLayer??"top",rotation:0,source_component_id:this.source_component_id,subcircuit_id:r?.subcircuit_id??void 0,obstructs_within_bounds:!0});this.pcb_component_id=s.pcb_component_id}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,i=this.getGroup(),r=this.getSubcircuit(),s=e.source_manually_placed_via.insert({source_group_id:i?.source_group_id,source_net_id:t.net??"",subcircuit_id:r?.subcircuit_id??void 0});this.source_component_id=s.source_manually_placed_via_id}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=this._getGlobalPcbPositionBeforeLayout(),r=this.getSubcircuit(),s=e.pcb_via.insert({x:i.x,y:i.y,hole_diameter:t.holeDiameter,outer_diameter:t.outerDiameter,layers:["bottom","top"],from_layer:t.fromLayer||"bottom",to_layer:t.toLayer||"top",subcircuit_id:r?.subcircuit_id??void 0,subcircuit_connectivity_map_key:this.subcircuit_connectivity_map_key??void 0,pcb_group_id:this.getGroup()?.pcb_group_id??void 0,net_is_assignable:t.netIsAssignable??void 0});this.pcb_via_id=s.pcb_via_id}},Xnt=class extends Me{constructor(){super(...arguments);d(this,"isPcbPrimitive",!0)}get config(){return{componentName:"CopperPour",zodProps:fW}}getPcbSize(){return{width:0,height:0}}doInitialCreateNetsFromProps(){let{_parsedProps:e}=this;eP(this,[e.connectsTo])}doInitialPcbCopperPourRender(){this.root?.pcbDisabled||this._queueAsyncEffect("PcbCopperPourRender",async()=>{let{db:e}=this.root,{_parsedProps:t}=this,i=this.getSubcircuit().selectOne(t.connectsTo);if(!i||!i.source_net_id){this.renderError(`Net "${t.connectsTo}" not found for copper pour`);return}let r=this.getSubcircuit(),s=e.toArray().filter(h=>h.type==="source_net"&&h.name===i.name)[0]||"",o=t.clearance??.2,a=JQ(e.toArray(),{layer:t.layer,pour_connectivity_key:s.subcircuit_connectivity_map_key||"",pad_margin:t.padMargin??o,trace_margin:t.traceMargin??o,board_edge_margin:t.boardEdgeMargin??o,cutout_margin:t.cutoutMargin??o}),c=new KQ(a),{brep_shapes:l}=c.getOutput(),u=t.coveredWithSolderMask??!1;for(let h of l)e.pcb_copper_pour.insert({shape:"brep",layer:t.layer,brep_shape:h,source_net_id:i.source_net_id,subcircuit_id:r?.subcircuit_id??void 0,covered_with_solder_mask:u})})}},Unt=class extends Gn{get config(){return{componentName:"Battery",schematicSymbolName:this.props.symbolName??"battery",zodProps:HH,sourceFtype:"simple_power_source"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){let{db:n}=this.root,{_parsedProps:e}=this,t=n.source_component.insert({name:this.name,ftype:"simple_power_source",capacity:e.capacity,supplier_part_numbers:e.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=t.source_component_id}},Vnt=class extends Gn{_getPcbRotationBeforeLayout(){let n=this.props.pcbOrientation==="vertical"?-90:0;return(super._getPcbRotationBeforeLayout()??0)+n}get config(){return{componentName:"PinHeader",zodProps:WH,shouldRenderAsSchematicBox:!0}}_getImpliedFootprintString(){let n=this._parsedProps.pinCount??(Array.isArray(this._parsedProps.pinLabels)?this._parsedProps.pinLabels.length:this._parsedProps.pinLabels?Object.keys(this._parsedProps.pinLabels).length:0),e=this._parsedProps.holeDiameter,t=this._parsedProps.platedDiameter,i=this._parsedProps.pitch,r=this._parsedProps.showSilkscreenPinLabels;if(n>0){let s;if(i)!e&&!t?s=`pinrow${n}_p${i}`:s=`pinrow${n}_p${i}_id${e}_od${t}`;else if(!e&&!t)s=`pinrow${n}`;else return null;return r!==!0&&(s+="_nopinlabels"),s}return null}initPorts(){let n=this._parsedProps.pinCount??(Array.isArray(this._parsedProps.pinLabels)?this._parsedProps.pinLabels.length:this._parsedProps.pinLabels?Object.keys(this._parsedProps.pinLabels).length:1);for(let e=1;e<=n;e++){let t=Array.isArray(this._parsedProps.pinLabels)?this._parsedProps.pinLabels[e-1]:this._parsedProps.pinLabels?.[`pin${e}`];if(t){let i=Array.isArray(t)?t[0]:t,r=Array.isArray(t)?t.slice(1):[];this.add(new Vi({pinNumber:e,name:i,aliases:[`pin${e}`,...r]}))}else this.add(new Vi({pinNumber:e,name:`pin${e}`}))}}_getSchematicPortArrangement(){let n=this._parsedProps.pinCount??1,e=this._parsedProps.schFacingDirection??this._parsedProps.facingDirection??"right",t=this._parsedProps.schPinArrangement;return e==="left"?{leftSide:{direction:t?.leftSide?.direction??"top-to-bottom",pins:t?.leftSide?.pins??Array.from({length:n},(i,r)=>`pin${r+1}`)}}:{rightSide:{direction:t?.rightSide?.direction??"top-to-bottom",pins:t?.rightSide?.pins??Array.from({length:n},(i,r)=>`pin${r+1}`)}}}doInitialSourceRender(){let{db:n}=this.root,{_parsedProps:e}=this,t=n.source_component.insert({ftype:"simple_pin_header",name:this.name,supplier_part_numbers:e.supplierPartNumbers,pin_count:e.pinCount,gender:e.gender,are_pins_interchangeable:!0});this.source_component_id=t.source_component_id}};function E7t(n){switch(n){case"two_ground_pins":return"crystal_4pin";case"ground_pin":return"resonator";case"no_ground":return"crystal";default:return"crystal"}}var Gnt=class extends Gn{get config(){return{componentName:"Resonator",schematicSymbolName:this.props.symbolName??E7t(this.props.pinVariant),zodProps:zH,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){let{db:n}=this.root,{_parsedProps:e}=this,t=e.pinVariant||"no_ground",i=n.source_component.insert({ftype:"simple_resonator",name:this.name,frequency:e.frequency,load_capacitance:e.loadCapacitance,supplier_part_numbers:e.supplierPartNumbers,pin_variant:t,are_pins_interchangeable:t==="no_ground"||t==="ground_pin"});this.source_component_id=i.source_component_id}_getSchematicSymbolDisplayValue(){let n=`${gi(this._parsedProps.frequency)}Hz`;return this._parsedProps.loadCapacitance?`${n} / ${gi(this._parsedProps.loadCapacitance)}F`:n}};function C7t(n){switch(n){case"three_pin":return"potentiometer3";case"two_pin":return"potentiometer2";default:return"potentiometer2"}}var Hnt=class extends Gn{get config(){return{componentName:"Potentiometer",schematicSymbolName:this.props.symbolName??C7t(this.props.pinVariant),zodProps:LH,shouldRenderAsSchematicBox:!1}}_getSchematicSymbolDisplayValue(){return`${gi(this._parsedProps.maxResistance)}\u03A9`}doInitialSourceRender(){let{db:n}=this.root,{_parsedProps:e}=this,t=e.pinVariant||"two_pin",i=n.source_component.insert({ftype:"simple_potentiometer",name:this.name,max_resistance:e.maxResistance,pin_variant:t,are_pins_interchangeable:t==="two_pin"});this.source_component_id=i.source_component_id}},Wnt=class extends Gn{get config(){return{componentName:"PushButton",schematicSymbolName:this.props.symbolName??"push_button_normally_open_momentary",zodProps:ZH,sourceFtype:Ua.simple_push_button}}get defaultInternallyConnectedPinNames(){return[]}initPorts(){super.initPorts({pinCount:2,ignoreSymbolPorts:!0});let n=_i[this._getSchematicSymbolNameOrThrow()],e=n.ports.find(l=>l.labels.includes("1")),t=n.ports.find(l=>l.labels.includes("2")),i=this.selectAll("port"),r=i.find(l=>l.props.pinNumber===1),s=i.find(l=>l.props.pinNumber===2),o=i.find(l=>l.props.pinNumber===3),a=i.find(l=>l.props.pinNumber===4),{internallyConnectedPins:c}=this._parsedProps;r.schematicSymbolPortDef=e,(!c||c.length===0)&&(s.schematicSymbolPortDef=t);for(let[l,u]of[[2,s],[3,o],[4,a]]){let h=c?.find(([_,g])=>_===`pin${l}`||g===`pin${l}`);if(!h){u.schematicSymbolPortDef=t;break}(h?.[0]===`pin${l}`?h[1]:h?.[0])!=="pin1"&&(u.schematicSymbolPortDef=t)}}doInitialSourceRender(){let{db:n}=this.root,{_parsedProps:e}=this,t=n.source_component.insert({name:this.name,ftype:Ua.simple_push_button,supplier_part_numbers:e.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=t.source_component_id}},qnt=class extends Gn{get config(){return{schematicSymbolName:this.props.symbolName??(this.props.pinVariant==="four_pin"?"crystal_4pin":"crystal"),componentName:"Crystal",zodProps:FH,sourceFtype:"simple_crystal"}}initPorts(){let n=this.props.pinVariant==="four_pin"?{pin1:["left1","1"],pin2:["top1","2","gnd1"],pin3:["right1","3"],pin4:["bottom1","4","gnd2"]}:{pin1:["pos","left"],pin2:["neg","right"]};super.initPorts({additionalAliases:n})}_getSchematicSymbolDisplayValue(){let n=`${gi(this._parsedProps.frequency)}Hz`;return this._parsedProps.loadCapacitance?`${n} / ${gi(this._parsedProps.loadCapacitance)}F`:n}doInitialSourceRender(){let{db:n}=this.root,{_parsedProps:e}=this,t=n.source_component.insert({name:this.name,ftype:"simple_crystal",frequency:e.frequency,load_capacitance:e.loadCapacitance,pin_variant:e.pinVariant||"two_pin",are_pins_interchangeable:(e.pinVariant||"two_pin")==="two_pin"});this.source_component_id=t.source_component_id}},Znt=class extends Gn{get config(){let n=this.props.mosfetMode==="depletion"?"d":"e",t=`${this.props.channelType}_channel_${n}_mosfet_transistor`;return{componentName:"Mosfet",schematicSymbolName:this.props.symbolName??t,zodProps:QH,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){let{db:n}=this.root,{_parsedProps:e}=this,t=n.source_component.insert({ftype:"simple_mosfet",name:this.name,mosfet_mode:e.mosfetMode,channel_type:e.channelType});this.source_component_id=t.source_component_id}};function I7t(n){return n.simSwitchFrequency!==void 0||n.simCloseAt!==void 0||n.simOpenAt!==void 0||n.simStartClosed!==void 0||n.simStartOpen!==void 0}var Knt=class extends Gn{_getSwitchType(){let n=this._parsedProps;return n?n.dpdt?"dpdt":n.spst?"spst":n.spdt?"spdt":n.dpst?"dpst":n.type??"spst":"spst"}get config(){let n=this._getSwitchType(),e=this._parsedProps?.isNormallyClosed??!1,t={spst:e?"spst_normally_closed_switch":"spst_switch",spdt:e?"spdt_normally_closed_switch":"spdt_switch",dpst:e?"dpst_normally_closed_switch":"dpst_switch",dpdt:e?"dpdt_normally_closed_switch":"dpdt_switch"};return{componentName:"Switch",schematicSymbolName:this.props.symbolName??t[n],zodProps:sW,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){let{db:n}=this.root,e=this._parsedProps??{},t=n.source_component.insert({ftype:"simple_switch",name:this.name,are_pins_interchangeable:this._getSwitchType()==="spst"});this.source_component_id=t.source_component_id}doInitialSimulationRender(){let{_parsedProps:n}=this;if(!I7t(n))return;let{db:e}=this.root,t={type:"simulation_switch",source_component_id:this.source_component_id||""};n.simSwitchFrequency!==void 0&&(t.switching_frequency=ur.parse(n.simSwitchFrequency)),n.simCloseAt!==void 0&&(t.closes_at=lr.parse(n.simCloseAt)),n.simOpenAt!==void 0&&(t.opens_at=lr.parse(n.simOpenAt)),n.simStartOpen!==void 0&&(t.starts_closed=!n.simStartOpen),n.simStartClosed!==void 0&&(t.starts_closed=n.simStartClosed),e.simulation_switch.insert(t)}},QA={HOLE_DIAMETER:.5,SMT_CIRCLE_DIAMETER:1.2,SMT_RECT_SIZE:2},Jnt=class extends Gn{get config(){return{componentName:"TestPoint",schematicSymbolName:this.props.symbolName??"testpoint",zodProps:pW,sourceFtype:Ua.simple_test_point}}_getPropsWithDefaults(){let{padShape:n,holeDiameter:e,footprintVariant:t,padDiameter:i,width:r,height:s}=this._parsedProps;return!t&&e&&(t="through_hole"),t??(t="through_hole"),n??(n="circle"),t==="pad"?n==="circle"?i??(i=QA.SMT_CIRCLE_DIAMETER):n==="rect"&&(r??(r=QA.SMT_RECT_SIZE),s??(s=r)):t==="through_hole"&&(e??(e=QA.HOLE_DIAMETER)),{padShape:n,holeDiameter:e,footprintVariant:t,padDiameter:i,width:r,height:s}}_getImpliedFootprintString(){let{padShape:n,holeDiameter:e,footprintVariant:t,padDiameter:i,width:r,height:s}=this._getPropsWithDefaults();if(t==="through_hole")return`platedhole_d${e}`;if(t==="pad"){if(n==="circle")return`smtpad_circle_d${i}`;if(n==="rect")return`smtpad_rect_w${r}_h${s}`}throw new Error(`Footprint variant "${t}" with pad shape "${n}" not implemented`)}doInitialSourceRender(){let{db:n}=this.root,{_parsedProps:e}=this,{padShape:t,holeDiameter:i,footprintVariant:r,padDiameter:s,width:o,height:a}=this._getPropsWithDefaults(),c=n.source_component.insert({ftype:Ua.simple_test_point,name:this.name,supplier_part_numbers:e.supplierPartNumbers,footprint_variant:r,pad_shape:t,pad_diameter:s,hole_diameter:i,width:o,height:a,are_pins_interchangeable:!0});this.source_component_id=c.source_component_id}},Qnt=class extends Me{constructor(){super(...arguments);d(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicText",zodProps:PW}}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=this._getGlobalSchematicPositionBeforeLayout();e.schematic_text.insert({anchor:t.anchor??"center",text:t.text,font_size:t.fontSize,color:t.color||"#000000",position:{x:i.x,y:i.y},rotation:t.schRotation??0})}},tit=class extends Me{constructor(){super(...arguments);d(this,"isSchematicPrimitive",!0);d(this,"schematic_line_id")}get config(){return{componentName:"SchematicLine",zodProps:SW}}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=this._getGlobalSchematicPositionBeforeLayout(),r=this.getPrimitiveContainer()?.parent?.schematic_component_id,s=e.schematic_line.insert({schematic_component_id:r,x1:t.x1+i.x,y1:t.y1+i.y,x2:t.x2+i.x,y2:t.y2+i.y,stroke_width:t.strokeWidth??sP,color:t.color??rP,is_dashed:!1,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.schematic_line_id=s.schematic_line_id}},eit=class extends Me{constructor(){super(...arguments);d(this,"isSchematicPrimitive",!0);d(this,"schematic_rect_id")}get config(){return{componentName:"SchematicRect",zodProps:wW}}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=this._getGlobalSchematicPositionBeforeLayout(),r=this.getPrimitiveContainer()?.parent?.schematic_component_id,s=e.schematic_rect.insert({center:{x:i.x,y:i.y},width:t.width,height:t.height,stroke_width:t.strokeWidth??sP,color:t.color??rP,is_filled:t.isFilled,schematic_component_id:r,is_dashed:t.isDashed,rotation:t.rotation??0,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.schematic_rect_id=s.schematic_rect_id}},nit=class extends Me{constructor(){super(...arguments);d(this,"isSchematicPrimitive",!0);d(this,"schematic_arc_id")}get config(){return{componentName:"SchematicArc",zodProps:xW}}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=this._getGlobalSchematicPositionBeforeLayout(),r=this.getPrimitiveContainer()?.parent?.schematic_component_id,s=e.schematic_arc.insert({schematic_component_id:r,center:{x:t.center.x+i.x,y:t.center.y+i.y},radius:t.radius,start_angle_degrees:t.startAngleDegrees,end_angle_degrees:t.endAngleDegrees,direction:t.direction,stroke_width:t.strokeWidth??sP,color:t.color??rP,is_dashed:t.isDashed,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.schematic_arc_id=s.schematic_arc_id}},iit=class extends Me{constructor(){super(...arguments);d(this,"isSchematicPrimitive",!0);d(this,"schematic_circle_id")}get config(){return{componentName:"SchematicCircle",zodProps:vW}}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=this._getGlobalSchematicPositionBeforeLayout(),r=this.getPrimitiveContainer()?.parent?.schematic_component_id,s=e.schematic_circle.insert({schematic_component_id:r,center:{x:t.center.x+i.x,y:t.center.y+i.y},radius:t.radius,stroke_width:t.strokeWidth??sP,color:t.color??rP,is_filled:t.isFilled,fill_color:t.fillColor,is_dashed:t.isDashed,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.schematic_circle_id=s.schematic_circle_id}};function N7t({anchor:n,x:e,y:t,width:i,height:r,isInside:s}){switch(n){case"top_left":return{x:e,y:t+r,textAnchor:s?"top_left":"bottom_left"};case"top_center":return{x:e+i/2,y:t+r,textAnchor:s?"top_center":"bottom_center"};case"top_right":return{x:e+i,y:t+r,textAnchor:s?"top_right":"bottom_right"};case"center_left":return{x:e,y:t+r/2,textAnchor:s?"center_left":"center_right"};case"center":return{x:e+i/2,y:t+r/2,textAnchor:"center"};case"center_right":return{x:e+i,y:t+r/2,textAnchor:s?"center_right":"center_left"};case"bottom_left":return{x:e,y:t,textAnchor:s?"bottom_left":"top_left"};case"bottom_center":return{x:e+i/2,y:t,textAnchor:s?"bottom_center":"top_center"};case"bottom_right":return{x:e+i,y:t,textAnchor:s?"bottom_right":"top_right"};default:return{x:e+i/2,y:t+r,textAnchor:"center"}}}var rit=class extends Me{constructor(){super(...arguments);d(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicBox",zodProps:bW,shouldRenderAsSchematicBox:!0}}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=.6,r=typeof t.padding=="number"?t.padding:0,s=typeof t.paddingTop=="number"?t.paddingTop:r,o=typeof t.paddingBottom=="number"?t.paddingBottom:r,a=typeof t.paddingLeft=="number"?t.paddingLeft:r,c=typeof t.paddingRight=="number"?t.paddingRight:r,l=t.overlay&&t.overlay.length>0,u=typeof t.width=="number"&&typeof t.height=="number",h,f,_,g,x,v;if(l){let S=t.overlay.map(nt=>({selector:nt,port:this.getSubcircuit().selectOne(nt,{type:"port"})})).filter(({port:nt})=>nt!=null).map(({port:nt})=>({position:nt._getGlobalSchematicPositionAfterLayout()}));if(S.length===0)return;let T=S.map(nt=>nt.position.x),k=S.map(nt=>nt.position.y),C=Math.min(...T),M=Math.max(...T),I=Math.min(...k),E=Math.max(...k),A=M-C,R=E-I,j=A===0?i:0,B=R===0?i:0,V=a+j/2,U=c+j/2,H=s+B/2,et=o+B/2,tt=C-V,_t=M+U,G=I-et,J=E+H;h=_t-tt,f=J-G,_=tt+(t.schX??0),g=G+(t.schY??0),x=_+h/2,v=g+f/2}else if(u){h=t.width,f=t.height;let P=this._getGlobalSchematicPositionBeforeLayout();x=P.x,v=P.y,_=x-h/2,g=v-f/2}else return;if(e.schematic_box.insert({height:f,width:h,x:_,y:g,is_dashed:t.strokeStyle==="dashed"}),t.title){let P=t.titleInside,S=.1,T=t.titleAlignment,k=N7t({anchor:T,x:_,y:g,width:h,height:f,isInside:P}),C,M,I=k.textAnchor;P?(C=T.includes("top")?-S:T.includes("bottom")?S:0,M=T.includes("left")?S:T.includes("right")?-S:0):(C=T.includes("top")?S:T.includes("bottom")?-S:0,M=T.includes("center_left")?-S:T.includes("center_right")?S:0);let E=k.x+M,A=k.y+C;e.schematic_text.insert({anchor:I,text:t.title,font_size:t.titleFontSize??.18,color:t.titleColor??"#000000",position:{x:E,y:A},rotation:0})}}},sit=class extends Me{constructor(){super(...arguments);d(this,"isSchematicPrimitive",!0);d(this,"schematic_table_id",null)}get config(){return{componentName:"SchematicTable",zodProps:kW}}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,i=this.children.filter(f=>f.componentName==="SchematicRow");if(i.length===0)return;let r=[],s=0;for(let f of i){let _=f.children.filter(g=>g.componentName==="SchematicCell");s=Math.max(s,_.length)}for(let f=0;f<i.length;f++)r[f]=[];for(let f=0;f<i.length;f++){let g=i[f].children.filter(v=>v.componentName==="SchematicCell"),x=0;for(let v=0;v<g.length;v++){for(;r[f][x];)x++;let P=g[v],S=P._parsedProps.colSpan??1,T=P._parsedProps.rowSpan??1;for(let k=0;k<T;k++)for(let C=0;C<S;C++)r[f+k]||(r[f+k]=[]),r[f+k][x+C]=P;x+=S}}s=Math.max(0,...r.map(f=>f.length));let o=i.map((f,_)=>f._parsedProps.height??1),a=Array.from({length:s},(f,_)=>{let g=0;for(let x=0;x<i.length;x++){let v=r[x]?.[_];if(v){let P=v._parsedProps.text??v._parsedProps.children,S=v._parsedProps.width??(P?.length??2)*.5;S>g&&(g=S)}}return g||10}),c=this._getGlobalSchematicPositionBeforeLayout(),l=e.schematic_table.insert({anchor_position:c,column_widths:a,row_heights:o,cell_padding:t.cellPadding,border_width:t.borderWidth,anchor:t.anchor,subcircuit_id:this.getSubcircuit()?.subcircuit_id||"",schematic_component_id:this.parent?.schematic_component_id||""});this.schematic_table_id=l.schematic_table_id;let u=new Set,h=0;for(let f=0;f<i.length;f++){let _=0;for(let g=0;g<s;g++){let x=r[f]?.[g];if(x&&!u.has(x)){u.add(x);let v=x._parsedProps,P=v.rowSpan??1,S=v.colSpan??1,T=0;for(let C=0;C<S;C++)T+=a[g+C];let k=0;for(let C=0;C<P;C++)k+=o[f+C];e.schematic_table_cell.insert({schematic_table_id:this.schematic_table_id,start_row_index:f,end_row_index:f+P-1,start_column_index:g,end_column_index:g+S-1,text:v.text??v.children,center:{x:c.x+_+T/2,y:c.y-h-k/2},width:T,height:k,horizontal_align:v.horizontalAlign,vertical_align:v.verticalAlign,font_size:v.fontSize??t.fontSize,subcircuit_id:this.getSubcircuit()?.subcircuit_id||""})}a[g]&&(_+=a[g])}h+=o[f]}}},oit=class extends Me{constructor(){super(...arguments);d(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicRow",zodProps:TW}}},ait=class extends Me{constructor(){super(...arguments);d(this,"isSchematicPrimitive",!0);d(this,"canHaveTextChildren",!0)}get config(){return{componentName:"SchematicCell",zodProps:MW}}},cit=class extends Me{constructor(){super(...arguments);d(this,"isPrimitiveContainer",!0)}get config(){return{componentName:"Symbol",zodProps:GH}}},lit=class extends Me{get config(){return{componentName:"AnalogSimulation",zodProps:KH}}doInitialSimulationRender(){let{db:n}=this.root,{duration:e,timePerStep:t}=this._parsedProps,i=e||10,r=t||.01;n.simulation_experiment.insert({name:"spice_transient_analysis",experiment_type:"spice_transient_analysis",end_time_ms:i,time_per_step:r})}},uit=class extends Me{constructor(){super(...arguments);d(this,"simulation_voltage_probe_id",null);d(this,"schematic_voltage_probe_id",null);d(this,"finalProbeName",null);d(this,"color",null)}get config(){return{componentName:"VoltageProbe",zodProps:gW}}doInitialSimulationRender(){let{db:e}=this.root,{connectsTo:t,name:i}=this._parsedProps,r=this.getSubcircuit();if(!r){this.renderError("VoltageProbe must be inside a subcircuit");return}let s=Array.isArray(t)?t:[t];if(s.length!==1){this.renderError("VoltageProbe must connect to exactly one port or net");return}let o=s[0],a=r.selectOne(o,{type:"port"}),c=a?null:r.selectOne(o,{type:"net"});if(c&&c.componentName!=="Net"){this.renderError(`VoltageProbe connection target "${o}" resolved to a non-net component "${c.componentName}".`);return}if(!a&&!c){this.renderError(`VoltageProbe could not find connection target "${o}"`);return}let l=a?.source_port_id??c?.source_net_id;if(!l){this.renderError("Could not identify connected source for VoltageProbe");return}this.color=i7t(l);let u=i;u||(u=s[0].split(" > ").map(f=>f.replace(/^\./,"")).join(".")),this.finalProbeName=u;let{simulation_voltage_probe_id:h}=e.simulation_voltage_probe.insert({name:u,source_port_id:a?.source_port_id??void 0,source_net_id:c?.source_net_id??void 0,subcircuit_id:r.subcircuit_id||void 0,color:this.color});this.simulation_voltage_probe_id=h}doInitialSchematicReplaceNetLabelsWithSymbols(){if(this.root?.schematicDisabled)return;let{db:e}=this.root,{connectsTo:t,name:i}=this._parsedProps,r=this.getSubcircuit();if(!r)return;let s=Array.isArray(t)?t:[t];if(s.length!==1)return;let o=s[0],a=r.selectOne(o,{type:"port"});if(!a||!a.schematic_port_id)return;let c=a._getGlobalSchematicPositionAfterLayout(),l=null;for(let f of e.schematic_trace.list()){for(let _ of f.edges)if(Math.abs(_.from.x-c.x)<1e-6&&Math.abs(_.from.y-c.y)<1e-6||Math.abs(_.to.x-c.x)<1e-6&&Math.abs(_.to.y-c.y)<1e-6){l=f.schematic_trace_id;break}if(l)break}if(!l)return;let u=this.finalProbeName,h=e.schematic_voltage_probe.insert({name:u,position:c,schematic_trace_id:l,subcircuit_id:r.subcircuit_id||void 0,color:this.color??void 0});this.schematic_voltage_probe_id=h.schematic_voltage_probe_id}},A7t={name:"@tscircuit/core",type:"module",version:"0.0.876",types:"dist/index.d.ts",main:"dist/index.js",module:"dist/index.js",exports:{".":{import:"./dist/index.js",types:"./dist/index.d.ts"}},files:["dist"],repository:{type:"git",url:"https://github.com/tscircuit/core"},scripts:{build:"tsup-node index.ts --format esm --dts",format:"biome format . --write","measure-bundle":"howfat -r table .","pkg-pr-new-release":"bunx pkg-pr-new publish --comment=off --peerDeps","smoke-test:dist":"bun run scripts/smoke-tests/test-dist-simple-circuit.tsx","build:benchmarking":"bun build --experimental-html ./benchmarking/website/index.html --outdir ./benchmarking-dist","build:benchmarking:watch":`chokidar "./{benchmarking,lib}/**/*.{ts,tsx}" -c 'bun build --experimental-html ./benchmarking/website/index.html --outdir ./benchmarking-dist'`,"start:benchmarking":'concurrently "bun run build:benchmarking:watch" "live-server ./benchmarking-dist"',"generate-test-plan":"bun run scripts/generate-test-plan.ts"},devDependencies:{"@biomejs/biome":"^1.8.3","@resvg/resvg-js":"^2.6.2","@tscircuit/capacity-autorouter":"^0.0.140","@tscircuit/checks":"^0.0.87","@tscircuit/circuit-json-util":"^0.0.72","@tscircuit/common":"^0.0.20","@tscircuit/copper-pour-solver":"^0.0.14","@tscircuit/footprinter":"^0.0.236","@tscircuit/import-snippet":"^0.0.4","@tscircuit/infgrid-ijump-astar":"^0.0.33","@tscircuit/log-soup":"^1.0.2","@tscircuit/matchpack":"^0.0.16","@tscircuit/math-utils":"^0.0.29","@tscircuit/miniflex":"^0.0.4","@tscircuit/ngspice-spice-engine":"^0.0.4","@tscircuit/props":"^0.0.410","@tscircuit/schematic-autolayout":"^0.0.6","@tscircuit/schematic-match-adapt":"^0.0.16","@tscircuit/schematic-trace-solver":"^v0.0.45","@tscircuit/solver-utils":"^0.0.3","@types/bun":"^1.2.16","@types/debug":"^4.1.12","@types/react":"^19.1.8","@types/react-dom":"^19.1.6","@types/react-reconciler":"^0.28.9","bpc-graph":"^0.0.57","bun-match-svg":"0.0.12","calculate-elbow":"^0.0.12","chokidar-cli":"^3.0.0","circuit-json":"^0.0.321","circuit-json-to-bpc":"^0.0.13","circuit-json-to-connectivity-map":"^0.0.22","circuit-json-to-gltf":"^0.0.31","circuit-json-to-simple-3d":"^0.0.9","circuit-json-to-spice":"^0.0.25","circuit-to-svg":"^0.0.277",concurrently:"^9.1.2","connectivity-map":"^1.0.0",debug:"^4.3.6","eecircuit-engine":"^1.5.6",flatbush:"^4.5.0","graphics-debug":"^0.0.60",howfat:"^0.3.8","live-server":"^1.2.2","looks-same":"^9.0.1",minicssgrid:"^0.0.9","pkg-pr-new":"^0.0.37",poppygl:"^0.0.16",react:"^19.1.0","react-dom":"^19.1.0","schematic-symbols":"^0.0.202",spicey:"^0.0.14","ts-expect":"^1.3.0",tsup:"^8.2.4"},peerDependencies:{"@tscircuit/capacity-autorouter":"*","@tscircuit/checks":"*","@tscircuit/circuit-json-util":"*","@tscircuit/footprinter":"*","@tscircuit/infgrid-ijump-astar":"*","@tscircuit/math-utils":"*","@tscircuit/props":"*","@tscircuit/schematic-autolayout":"*","@tscircuit/schematic-match-adapt":"*","circuit-json-to-bpc":"*","bpc-graph":"*","@tscircuit/matchpack":"*","circuit-json":"*","circuit-json-to-connectivity-map":"*","schematic-symbols":"*",typescript:"^5.0.0"},dependencies:{"@flatten-js/core":"^1.6.2","@lume/kiwi":"^0.4.3","calculate-packing":"0.0.50","css-select":"5.1.0","format-si-unit":"^0.0.3",nanoid:"^5.0.7","performance-now":"^2.1.0","react-reconciler":"^0.32.0","transformation-matrix":"^2.16.1",zod:"^3.25.67"}},Z_=class{constructor({platform:n,projectUrl:e}={}){d(this,"firstChild",null);d(this,"children");d(this,"db");d(this,"root",null);d(this,"isRoot",!0);d(this,"_schematicDisabledOverride");d(this,"pcbDisabled",!1);d(this,"pcbRoutingDisabled",!1);d(this,"_featureMspSchematicTraceRouting",!0);d(this,"name");d(this,"platform");d(this,"projectUrl");d(this,"_hasRenderedAtleastOnce",!1);d(this,"_eventListeners",{});this.children=[],this.db=Ee([]),this.root=this,this.platform=n,this.projectUrl=e,this.pcbDisabled=n?.pcbDisabled??!1}get schematicDisabled(){return this._schematicDisabledOverride!==void 0?this._schematicDisabledOverride:this._getBoard()?._parsedProps?.schematicDisabled??!1}set schematicDisabled(n){this._schematicDisabledOverride=n}add(n){let e;(0,pit.isValidElement)(n)?e=Het(n):e=n,this.children.push(e)}setPlatform(n){this.platform={...this.platform,...n}}_getBoard(){let n=this.children.find(e=>e.componentName==="Board");if(n)return n}_guessRootComponent(){if(this.firstChild)return;if(this.children.length===0)throw new Error("Not able to guess root component: RootCircuit has no children (use circuit.add(...))");let n=this.children.filter(t=>t.lowercaseComponentName==="panel");if(n.length>1)throw new Error("Only one <panel> is allowed per circuit");if(n.length===1){if(this.children.length!==1)throw new Error("<panel> must be the root element of the circuit");this.firstChild=n[0];return}if(this.children.length===1&&this.children[0].isGroup){this.firstChild=this.children[0];return}let e=new ml({subcircuit:!0});e.parent=this,e.addAll(this.children),this.children=[e],this.firstChild=e}render(){this.firstChild||this._guessRootComponent();let{firstChild:n,db:e}=this;if(!n)throw new Error("RootCircuit has no root component");n.parent=this,n.runRenderCycle(),this._hasRenderedAtleastOnce=!0}async renderUntilSettled(){for(this.db.source_project_metadata.list()?.[0]||this.db.source_project_metadata.insert({software_used_string:`@tscircuit/core@${this.getCoreVersion()}`,...this.projectUrl?{project_url:this.projectUrl}:{}}),this.render();this._hasIncompleteAsyncEffects();)await new Promise(e=>setTimeout(e,100)),this.render();this.emit("renderComplete")}_hasIncompleteAsyncEffects(){return this.children.some(n=>n._hasIncompleteAsyncEffects()?!0:n.children.some(e=>e._hasIncompleteAsyncEffects()))}getCircuitJson(){return this._hasRenderedAtleastOnce||this.render(),this.db.toArray()}toJson(){return this.getCircuitJson()}async getSvg(n){let e=await Promise.resolve().then(()=>(pet(),uet)).catch(t=>{throw new Error(`To use circuit.getSvg, you must install the "circuit-to-svg" package.
|
|
252
252
|
|
|
253
253
|
"${t.message}"`)});if(n.view==="pcb")return e.convertCircuitJsonToPcbSvg(this.getCircuitJson());if(n.view==="schematic")return e.convertCircuitJsonToSchematicSvg(this.getCircuitJson());throw new Error(`Invalid view: ${n.view}`)}getCoreVersion(){let[n,e,t]=A7t.version.split(".").map(Number);return`${n}.${e}.${t+1}`}async preview(n){let e=typeof n=="object"?n:{previewName:n};throw new Error("project.preview is not yet implemented")}computeSchematicGlobalTransform(){return Sr()}_computePcbGlobalTransformBeforeLayout(){return Sr()}selectAll(n){return this._guessRootComponent(),this.firstChild?.selectAll(n)??[]}selectOne(n,e){return this._guessRootComponent(),this.firstChild?.selectOne(n,e)??null}emit(n,...e){if(this._eventListeners[n])for(let t of this._eventListeners[n])t(...e)}on(n,e){this._eventListeners[n]||(this._eventListeners[n]=[]),this._eventListeners[n].push(e)}removeListener(n,e){this._eventListeners[n]&&(this._eventListeners[n]=this._eventListeners[n].filter(t=>t!==e))}enableDebug(n){typeof n=="string"?c9.default.enable(n):(n===null||n===!1)&&c9.default.disable()}getClientOrigin(){return typeof window<"u"&&window.location?window.location.origin:typeof self<"u"&&self.location?self.location.origin:""}},R7t=Z_,O7t=Z_,L7t=n=>{let[e,t]=U_.default.useState(!0),[i,r]=U_.default.useState(null),[s,o]=U_.default.useState(),[a,c]=U_.default.useState();return U_.default.useEffect(()=>{t(!0),r(null),n&&setTimeout(()=>{try{let l=new Z_;l.add(n),o(l),c(l.toJson())}catch(l){r(l)}t(!1)},1)},[n]),{isLoading:e,error:i,circuit:s,circuitJson:a}},K_=(n,e)=>(t,i)=>{let r=[];Array.isArray(e)?r.push(...e.flat()):typeof e=="object"&&r.push(...Object.values(e).flat(),...Object.keys(e));let s=o=>{if(o?.name&&o.name!==t)throw new Error(`Component name mismatch. Hook name: ${t}, Component prop name: ${o.name}`);let a={...i,...o,name:t},c=[];for(let l of r)if(a[l]){let u=`.${t} > .${l}`,h=a[l];c.push({from:u,to:h}),delete a[l]}return(0,Id.jsxs)(Id.Fragment,{children:[(0,Id.jsx)(n,{...a}),c.map((l,u)=>(0,Id.jsx)("trace",{...l},u))]})};for(let o of r)s[o]=`.${t} > .${o}`;return s},F7t=K_(n=>(0,hit.jsx)("capacitor",{...n}),DH),z7t=n=>K_(e=>(0,dit.jsx)("chip",{pinLabels:n,...e}),n),$7t=K_(n=>(0,fit.jsx)("diode",{...n}),nW),D7t=K_(n=>(0,mit.jsx)("led",{...n}),rW),j7t=K_(n=>(0,_it.jsx)("resistor",{...n}),OH),B7t=new Proxy(n=>new Proxy({},{get:(e,t)=>`.${n} > .${t}`}),{get:(n,e)=>{let t=(...i)=>{let r=i[0];return new Proxy({},{get:(s,o)=>`.${e} > .${o}`})};return new Proxy(t,{get:(i,r)=>e==="net"?`net.${r}`:e==="subcircuit"?new Proxy({},{get:(s,o)=>new Proxy({},{get:(a,c)=>`subcircuit.${r} > .${o} > .${c}`})}):`.${e} > .${r}`,apply:(i,r,s)=>e==="net"?new Proxy({},{get:(o,a)=>`net.${a}`}):new Proxy({},{get:(o,a)=>{let c=`.${e} > .${a}`;return["U","J","CN"].some(u=>e.startsWith(u))?c:new Proxy(new String(c),{get:(u,h)=>typeof h=="symbol"||h==="toString"?()=>c:`.${e} > .${a} > .${h}`})}})})}});Get(Bet);Get({Bug:X1});var zit=Gt(Ws(),1);var git=n=>{let e=n.match(/:[RC]_(\d{4})_/);if(e||(e=n.match(/:(SOIC-\d+|SOT-\d+|SOD-\d+|SSOP-\d+|TSSOP-\d+|QFP-\d+|QFN-\d+)/),e))return e[1]};var S9=n=>n.includes("cap")?n.replace(/cap/g,""):n;var xit=n=>{if(n){if(n.startsWith("kicad:")){let e=git(n);return e?S9(e):n}return S9(n)}};var P9=new Map,Tr=async(n,e)=>{let t=new URLSearchParams({...e,json:"true"}).toString();if(P9.has(t))return P9.get(t);let r=await(await fetch(`https://jlcsearch.tscircuit.com/${n}/list?${t}`)).json();return P9.set(t,r),r},Mr=n=>n?[...n].sort((e,t)=>Number(t.is_basic??!1)-Number(e.is_basic??!1)):[],bit={findPart:async({sourceComponent:n,footprinterString:e})=>{let t=xit(e);if(n.type==="source_component"&&n.ftype==="simple_resistor"){let{resistors:i}=await Tr("resistors",{resistance:n.resistance,package:t});return{jlcpcb:Mr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(n.type==="source_component"&&n.ftype==="simple_capacitor"){let{capacitors:i}=await Tr("capacitors",{capacitance:n.capacitance,package:t});return{jlcpcb:Mr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(n.type==="source_component"&&n.ftype==="simple_pin_header"){let i;e?.includes("_p")&&(i=Number(e.split("_p")[1]));let{headers:r}=await Tr("headers",i?{pitch:i,num_pins:n.pin_count,gender:n.gender}:{num_pins:n.pin_count,gender:n.gender});return{jlcpcb:Mr(r).map(s=>`C${s.lcsc}`).slice(0,3)}}else if(n.type==="source_component"&&n.ftype==="simple_potentiometer"){let{potentiometers:i}=await Tr("potentiometers",{resistance:n.max_resistance,package:t});return{jlcpcb:Mr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(n.type==="source_component"&&n.ftype==="simple_diode"){let{diodes:i}=await Tr("diodes",{package:t});return{jlcpcb:Mr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(n.type==="source_component"&&n.ftype==="simple_chip"){let{chips:i}=await Tr("chips",{package:t});return{jlcpcb:Mr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(n.type==="source_component"&&n.ftype==="simple_transistor"){let{transistors:i}=await Tr("transistors",{package:t,transistor_type:n.transistor_type});return{jlcpcb:Mr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(n.type==="source_component"&&n.ftype==="simple_power_source"){let{power_sources:i}=await Tr("power_sources",{voltage:n.voltage,package:t});return{jlcpcb:Mr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(n.type==="source_component"&&n.ftype==="simple_inductor"){let{inductors:i}=await Tr("inductors",{inductance:n.inductance,package:t});return{jlcpcb:Mr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(n.type==="source_component"&&n.ftype==="simple_crystal"){let{crystals:i}=await Tr("crystals",{frequency:n.frequency,load_capacitance:n.load_capacitance,package:t});return{jlcpcb:Mr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(n.type==="source_component"&&n.ftype==="simple_mosfet"){let{mosfets:i}=await Tr("mosfets",{package:t,mosfet_mode:n.mosfet_mode,channel_type:n.channel_type});return{jlcpcb:Mr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(n.type==="source_component"&&n.ftype==="simple_resonator"){let{resonators:i}=await Tr("resonators",{frequency:n.frequency,package:t});return{jlcpcb:Mr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(n.type==="source_component"&&n.ftype==="simple_switch"){let{switches:i}=await Tr("switches",{switch_type:n.type,package:t});return{jlcpcb:Mr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(n.type==="source_component"&&n.ftype==="simple_led"){let{leds:i}=await Tr("leds",{package:t});return{jlcpcb:Mr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(n.type==="source_component"&&n.ftype==="simple_fuse"){let{fuses:i}=await Tr("fuses",{package:t});return{jlcpcb:Mr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}return{}}};var kit=Gt(vit(),1);Q();var Iit=Gt(En(),1),Nit=Gt(En(),1),xi=p.tuple([p.coerce.number(),p.coerce.number()]),K7t=p.tuple([p.number(),p.number(),p.number()]),pP=p.union([xi,K7t]),J7t=p.object({kind:p.literal("arc"),start:xi,mid:xi,end:xi}),Q7t=p.union([xi,J7t]),Tit=p.object({at:pP,size:xi,layer:p.string(),layers:p.array(p.string()),roundrect_rratio:p.number(),uuid:p.string()}).partial(),tFt=p.object({key:p.string(),val:p.string(),attributes:Tit}),cP=p.object({oval:p.boolean().default(!1),width:p.number().optional(),height:p.number().optional(),offset:xi.optional()}),Mit=p.object({name:p.string(),pad_type:p.enum(["thru_hole","smd","np_thru_hole","connect"]),pad_shape:p.enum(["roundrect","circle","rect","oval","trapezoid","custom"]),at:pP,drill:p.union([p.number(),p.array(p.any()),cP]).transform(n=>typeof n=="number"?{oval:!1,width:n,height:n}:"oval"in n?n:n.length===2?{oval:!1,width:Number.parseFloat(n[0]),height:Number.parseFloat(n[0]),offset:xi.parse(n[1].slice(1))}:n.length===3||n.length===4?{oval:n[0]==="oval",width:Number.parseFloat(n[1]),height:Number.parseFloat(n[2]),offset:n[3]?xi.parse(n[3].slice(1)):void 0}:n).pipe(cP),size:p.union([p.array(p.number()).length(2).transform(([n,e])=>({width:n,height:e})),p.object({width:p.number(),height:p.number()})]),layers:p.array(p.string()).optional(),roundrect_rratio:p.number().optional(),uuid:p.string().optional()}),Eit=p.object({name:p.string(),pad_type:p.enum(["thru_hole","smd","np_thru_hole","connect"]),pad_shape:p.enum(["roundrect","circle","rect","oval","trapezoid","custom"]),at:pP,size:xi,drill:p.union([p.number(),p.array(p.any()),cP]).transform(n=>typeof n=="number"?{oval:!1,width:n,height:n}:"oval"in n?n:n.length===2?{oval:!1,width:Number.parseFloat(n[0]),height:Number.parseFloat(n[0]),offset:xi.parse(n[1].slice(1))}:n.length===3||n.length===4?{oval:n[0]==="oval",width:Number.parseFloat(n[1]),height:Number.parseFloat(n[2]),offset:n[3]?xi.parse(n[3].slice(1)):void 0}:n).pipe(cP).optional(),layers:p.array(p.string()).optional(),roundrect_rratio:p.number().optional(),chamfer_ratio:p.number().optional(),solder_paste_margin:p.number().optional(),solder_paste_margin_ratio:p.number().optional(),clearance:p.number().optional(),zone_connection:p.union([p.literal(0).describe("Pad is not connect to zone"),p.literal(1).describe("Pad is connected to zone using thermal relief"),p.literal(2).describe("Pad is connected to zone using solid fill")]).optional(),thermal_width:p.number().optional(),thermal_gap:p.number().optional(),uuid:p.string().optional()}),Cit=p.object({font:p.object({size:xi,thickness:p.number().optional()})}).partial(),eFt=p.object({fp_text_type:p.literal("user"),text:p.string(),at:pP,layer:p.string(),uuid:p.string().optional(),effects:Cit.partial()}),nFt=p.object({start:xi,mid:xi,end:xi,stroke:p.object({width:p.number(),type:p.string()}),layer:p.string(),uuid:p.string().optional()}),iFt=p.object({center:xi,end:xi,stroke:p.object({width:p.number(),type:p.string()}),fill:p.string().optional(),layer:p.string(),uuid:p.string().optional()}),rFt=p.object({pts:p.array(Q7t),stroke:p.object({width:p.number(),type:p.string()}).optional(),width:p.number().optional(),layer:p.string(),uuid:p.string().optional(),fill:p.string().optional()}).transform(n=>({...n,width:void 0,stroke:n.stroke??{width:n.width}})),sFt=p.object({start:xi,end:xi,stroke:p.object({width:p.number(),type:p.string()}).optional(),width:p.number().optional(),layer:p.string(),uuid:p.string().optional()}).transform(n=>({...n,width:void 0,stroke:n.stroke??{width:n.width}})),wit=p.object({footprint_name:p.string(),version:p.string().optional(),generator:p.string().optional(),generator_version:p.string().optional(),layer:p.string(),descr:p.string().default(""),tags:p.array(p.string()).optional(),properties:p.array(tFt),fp_lines:p.array(sFt),fp_texts:p.array(eFt),fp_arcs:p.array(nFt),fp_circles:p.array(iFt).optional(),fp_polys:p.array(rFt).optional(),pads:p.array(Eit),holes:p.array(Mit).optional()}),lP=(n,e)=>{if(e==="effects"&&Array.isArray(n)){let t={};for(let i of n)if(i[0]==="font"){let r={};for(let s of i.slice(1))s.length===2?r[s[0].valueOf()]=Number.parseFloat(s[1].valueOf()):r[s[0].valueOf()]=s.slice(1).map(o=>Number.parseFloat(o.valueOf()));t.font=r}return Cit.parse(t)}if(e==="pts")return n.map(t=>{let i=t[0]?.valueOf?.()??t[0];if(i==="xy")return t.slice(1).map(r=>Number.parseFloat(r.valueOf()));if(i==="arc"){let r={kind:"arc"};for(let s of t.slice(1)){let o=s[0].valueOf();r[o]=s.slice(1).map(a=>Number.parseFloat(a.valueOf()))}return r}return t});if(e==="stroke"){let t={};for(let i of n){let r=i[0].valueOf();t[r]=lP(i.slice(1),r)}return t}return e==="at"||e==="size"||e==="start"||e==="mid"||e==="end"?(Array.isArray(n)?n:[n]).map(i=>i?.valueOf?.()??i).filter(i=>typeof i=="number"||typeof i=="string"&&/^[-+]?\d*\.?\d+(e[-+]?\d+)?$/i.test(i)).map(i=>typeof i=="number"?i:Number.parseFloat(i)):e==="tags"?n.map(t=>t.valueOf()):e==="generator_version"||e==="version"?n[0].valueOf():n.length===2?n.valueOf():e==="uuid"?Array.isArray(n)?n[0].valueOf():n.valueOf():/^[\d\.]+$/.test(n)&&!Number.isNaN(Number.parseFloat(n))?Number.parseFloat(n):Array.isArray(n)&&n.length===1?n[0].valueOf():Array.isArray(n)?n.map(t=>t.valueOf()):n},Be=(n,e)=>{for(let t of n)if(Array.isArray(t)&&t[0]===e)return lP(t.slice(1),e)},k9=(0,Iit.default)("kicad-mod-converter"),oFt=n=>{let e=(0,kit.default)(n),t=e[1].valueOf(),i={},r=Object.entries(wit.shape).filter(([T,k])=>k._def.typeName==="ZodString"||T==="tags").map(([T])=>T);for(let T of e.slice(2)){if(!r.includes(T[0]))continue;let k=T[0].valueOf(),C=lP(T.slice(1),k);i[k]=C}let s=e.slice(2).filter(T=>T[0]==="property").map(T=>{let k=T[1].valueOf(),C=T[2].valueOf(),M=Tit.parse(T.slice(3).reduce((I,E)=>{let A=E[0].valueOf();return I[A]=lP(E.slice(1),A),I},{}));return{key:k,val:C,attributes:M}}),o=e.slice(2).filter(T=>T[0]==="pad"),a=[];for(let T of o){let k=Be(T,"at"),C=Be(T,"size"),M=Be(T,"drill"),I=Be(T,"layers");if(Array.isArray(I)?I=I.map(j=>j.valueOf()):typeof I=="string"?I=[I]:I||(I=[]),!I.includes("F.Cu")){k9(`Skipping pad without F.Cu layer: layers=${I.join(", ")}`);continue}let E=Be(T,"roundrect_rratio"),A=Be(T,"uuid"),R={name:T[1].valueOf(),pad_type:T[2].valueOf(),pad_shape:T[3].valueOf(),at:k,drill:M,size:C,layers:I,roundrect_rratio:E,uuid:A};k9(`attempting to parse pad: ${JSON.stringify(R,null," ")}`),a.push(Eit.parse(R))}let c=e.slice(2).filter(T=>T[0]==="fp_text"),l=[];for(let T of c){let k=T[2].valueOf(),C=Be(T,"at"),M=Be(T,"layer"),I=Be(T,"uuid"),E=Be(T,"effects");l.push({fp_text_type:"user",text:k,at:C,layer:M,uuid:I,effects:E})}let u=[],h=e.slice(2).filter(T=>T[0]==="fp_line");for(let T of h){let k=Be(T,"start"),C=Be(T,"end"),M=Be(T,"stroke"),I=Be(T,"layer"),E=Be(T,"uuid");u.push({start:k,end:C,stroke:M,layer:I,uuid:E})}let f=[],_=e.slice(2).filter(T=>T[0]==="fp_arc");for(let T of _){let k=Be(T,"start"),C=Be(T,"mid"),M=Be(T,"end"),I=Be(T,"stroke"),E=Be(T,"layer"),A=Be(T,"uuid");!k||!M||!C||!I||!E||f.push({start:k,mid:C,end:M,stroke:I,layer:E,uuid:A})}let g=[],x=e.slice(2).filter(T=>T[0]==="fp_circle");for(let T of x){let k=Be(T,"center"),C=Be(T,"end"),M=Be(T,"stroke"),I=Be(T,"fill"),E=Be(T,"layer"),A=Be(T,"uuid");!k||!C||!M||!E||g.push({center:k,end:C,stroke:M,fill:I,layer:E,uuid:A})}let v=[],P=e.slice(2).filter(T=>T[0]==="fp_poly");for(let T of P){let k=Be(T,"pts"),C=Be(T,"stroke"),M=Be(T,"width"),I=Be(T,"layer"),E=Be(T,"uuid"),A=Be(T,"fill"),R=C;!R&&typeof M=="number"?R={width:M,type:"solid"}:R&&typeof R=="object"&&typeof M=="number"&&R.width===void 0&&(R={...R,width:M}),v.push({pts:k,stroke:R,layer:I,uuid:E,fill:A})}let S=[];for(let T of e.slice(2)){if(T[0]!=="pad"||T[2]?.valueOf?.()!=="thru_hole")continue;let k=T[1]?.valueOf?.(),C=T[2]?.valueOf?.(),M=T[3]?.valueOf?.(),I=Be(T,"at"),E=Be(T,"drill"),A=Be(T,"size");Array.isArray(A)&&(A[0]==="size"&&(A=A.slice(1)),A={width:Number(A[0]),height:Number(A[1])});let R=Be(T,"uuid"),j=Be(T,"roundrect_rratio"),B=Be(T,"layers");Array.isArray(B)?B=B.map(U=>U.valueOf()):typeof B=="string"?B=[B]:B||(B=[]);let V={name:k,pad_type:C,pad_shape:M,at:I,drill:E,size:A,layers:B,roundrect_rratio:j,uuid:R};k9(`attempting to parse holes: ${JSON.stringify(V,null,2)}`),S.push(Mit.parse(V))}return wit.parse({footprint_name:t,...i,properties:s,fp_lines:u,fp_texts:l,fp_arcs:f,fp_circles:g,pads:a,holes:S,fp_polys:v})},U1=Math.PI*2,Sit=n=>{let e=n%U1;return e<0&&(e+=U1),e},uP=(n,e)=>{let t=Sit(n),r=Sit(e)-t;return r<0&&(r+=U1),r};function Ait(n,e,t){let i={x:(n.x+e.x)/2,y:(n.y+e.y)/2},r={x:(e.x+t.x)/2,y:(e.y+t.y)/2},s=-(n.x-e.x)/(n.y-e.y),o=-(e.x-t.x)/(e.y-t.y),a=(i.y-r.y+o*r.x-s*i.x)/(o-s),c=i.y+s*(a-i.x);return{x:a,y:c}}function Rit(n,e){return Math.sqrt((n.x-e.x)**2+(n.y-e.y)**2)}function Q_(n,e){return Math.atan2(e.y-n.y,e.x-n.x)}var C9=(n,e,t)=>{let i=Ait(n,e,t),r=Rit(i,n),s=Q_(i,n),o=Q_(i,e),a=Q_(i,t),c=uP(s,o),l=uP(s,a),u=l;return c>l&&(u=l-U1),Math.abs(r*u)};function I9(n,e,t,i){let r=Ait(n,e,t),s=Rit(r,n),o=Q_(r,n),a=Q_(r,e),c=Q_(r,t),l=uP(o,a),u=uP(o,c),h=u;l>u&&(h=u-U1);let f=[];for(let _=0;_<=i;_++){let g=o+_/i*h,x=r.x+s*Math.cos(g),v=r.y+s*Math.sin(g);f.push({x,y:v})}return f}var _l=n=>Array.isArray(n)?{x:n[0],y:n[1]}:n,T9=(n,e,t=1e-4)=>Math.abs(n.x-e.x)<t&&Math.abs(n.y-e.y)<t,aFt=n=>{let e=[],t=new Set;for(let i=0;i<n.length;i++){if(t.has(i))continue;let r=[n[i]];t.add(i);let s=n[i].end,o=!0;for(;o;){if(o=!1,r.length>1&&T9(s,r[0].start)){e.push(r);break}for(let a=0;a<n.length;a++)if(!t.has(a)){if(T9(s,n[a].start)){r.push(n[a]),t.add(a),s=n[a].end,o=!0;break}else if(T9(s,n[a].end)){n[a].type==="arc"?r.push({...n[a],reversed:!0}):r.push({...n[a],start:n[a].end,end:n[a].start}),t.add(a),s=n[a].start,o=!0;break}}if(!o){for(let a=r.length-1;a>=0;a--){let c=n.indexOf(r[a]);c!==-1&&t.delete(c)}break}}}return e},cFt=n=>{let e=[];for(let t of n)if(t.type==="line")e.push(t.start);else if(t.type==="arc"&&t.mid){let i=C9(t.start,t.mid,t.end),r=Math.max(3,Math.ceil(i)),s=I9(t.start,t.mid,t.end,r);t.reversed&&(s=s.reverse()),e.push(...s.slice(0,-1))}return e};function lFt(n){if(!Array.isArray(n))return null;let e=n.find(o=>o.layer?.toLowerCase()==="f.silks"&&(o.text?.includes("${REFERENCE}")||o.fp_text_type?.toLowerCase()==="reference"||o.text?.match(/^R\d+|C\d+|U\d+/))),t=e||n.find(o=>o.layer?.toLowerCase()==="f.fab"&&(o.text?.includes("${REFERENCE}")||o.fp_text_type?.toLowerCase()==="reference")),i=e||t;if(!i?.effects?.font?.size)return null;let[r,s]=i.effects.font.size;return s??r??1}var uFt=n=>n*Math.PI/180,M9=(n,e,t)=>{let i=uFt(t),r=Math.cos(i),s=Math.sin(i);return{x:n*r-e*s,y:n*s+e*r}},pFt=n=>{let e=[...new Map(n.map(u=>[`${u.x},${u.y}`,u])).values()];if(e.length!==4)return null;let t=e.map(u=>u.x),i=e.map(u=>u.y),r=[...new Set(t)],s=[...new Set(i)];if(r.length!==2||s.length!==2)return null;let[o,a]=r.sort((u,h)=>u-h),[c,l]=s.sort((u,h)=>u-h);return o===void 0||a===void 0||c===void 0||l===void 0?null:{x:(o+a)/2,y:(c+l)/2,width:a-o,height:l-c}},hFt=n=>{if(!n)return!1;let e=n.toLowerCase();return e!=="no"&&e!=="none"&&e!=="outline"},E9=n=>n&&Array.isArray(n)&&n.length>=3&&typeof n[2]=="number"?n[2]:0,Ur=n=>{let e=(n%360+360)%360;return e===90||e===270},Nd=n=>{if(n!=null)return`${n}`},Pit=n=>{let e=Nd(n),t=e!==void 0?Number(e):NaN;return Number.isFinite(t)?t:void 0},J_=(0,Nit.default)("kicad-mod-converter"),Fs=n=>{switch(n.toLowerCase()){case"f.cu":case"f.fab":case"f.silks":case"edge.cuts":return"top";case"b.cu":case"b.fab":case"b.silks":return"bottom"}},dFt=async n=>{let{fp_lines:e,fp_texts:t,fp_arcs:i,fp_circles:r,pads:s,properties:o,holes:a,fp_polys:c}=n,l=[];l.push({type:"source_component",source_component_id:"source_component_0",supplier_part_numbers:{}}),l.push({type:"schematic_component",schematic_component_id:"schematic_component_0",source_component_id:"source_component_0",center:{x:0,y:0},rotation:0,size:{width:0,height:0}});let u=new Set,h=new Map;for(let G of s){let J=Nd(G.name);if(J){u.add(J);let nt=Pit(G.name);nt!==void 0&&h.set(J,nt)}}if(a)for(let G of a){let J=Nd(G.name);if(J){u.add(J);let nt=Pit(G.name);nt!==void 0&&h.set(J,nt)}}let f=0,_=new Map;for(let G of u){let J=`source_port_${f++}`;_.set(G,J),l.push({type:"source_port",source_port_id:J,source_component_id:"source_component_0",name:G,port_hints:[G],pin_number:h.get(G)}),l.push({type:"schematic_port",schematic_port_id:`schematic_port_${f++}`,source_port_id:J,schematic_component_id:"schematic_component_0",center:{x:0,y:0}})}let g=Number.POSITIVE_INFINITY,x=Number.NEGATIVE_INFINITY,v=Number.POSITIVE_INFINITY,P=Number.NEGATIVE_INFINITY;for(let G of s){let J=G.at[0],nt=-G.at[1],ut=G.size[0],ht=G.size[1];g=Math.min(g,J-ut/2),x=Math.max(x,J+ut/2),v=Math.min(v,nt-ht/2),P=Math.max(P,nt+ht/2)}let S="pcb_component_0";l.push({type:"pcb_component",source_component_id:"source_component_0",pcb_component_id:S,layer:"top",center:{x:0,y:0},rotation:0,width:Number.isFinite(g)?x-g:0,height:Number.isFinite(v)?P-v:0});let T=0,k=new Map;for(let G of u){let J=`pcb_port_${T++}`,nt=_.get(G);k.set(G,J);let ut=0,ht=0,kt=["top","bottom"],Et=s.find(ot=>Nd(ot.name)===G);if(Et)ut=Et.at[0],ht=-Et.at[1],kt=Et.layers?Et.layers.map(ot=>Fs(ot)).filter(Boolean):["top","bottom"];else if(a){let ot=a.find(X=>Nd(X.name)===G);ot&&(ut=ot.at[0],ht=-ot.at[1],kt=ot.layers?ot.layers.map(X=>Fs(X)).filter(Boolean):["top","bottom"])}l.push({type:"pcb_port",pcb_port_id:J,source_port_id:nt,pcb_component_id:S,x:ut,y:ht,layers:kt})}let C=0,M=0,I=0;for(let G of s){let J=Nd(G.name),nt=J?h.get(J):void 0;if(G.pad_type==="smd"){let ut=E9(G.at),ht=Ur(ut)?G.size[1]:G.size[0],kt=Ur(ut)?G.size[0]:G.size[1],Et=J?k.get(J):void 0;l.push({type:"pcb_smtpad",pcb_smtpad_id:`pcb_smtpad_${C++}`,shape:"rect",x:G.at[0],y:-G.at[1],width:ht,height:kt,layer:Fs(G.layers?.[0]??"F.Cu"),pcb_component_id:S,port_hints:J?[J]:[],pcb_port_id:Et,pin_number:nt})}else if(G.pad_type==="thru_hole"){if(G.pad_shape==="rect"){let ut=E9(G.at),ht=Ur(ut)?G.size[1]:G.size[0],kt=Ur(ut)?G.size[0]:G.size[1],Et=G.drill?.offset?.[0]??0,ot=G.drill?.offset?.[1]??0,X=M9(Et,ot,ut),W=J?k.get(J):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${M++}`,shape:"circular_hole_with_rect_pad",hole_shape:"circle",pad_shape:"rect",x:G.at[0],y:-G.at[1],hole_offset_x:-X.x,hole_offset_y:-X.y,hole_diameter:G.drill?.width,rect_pad_width:ht,rect_pad_height:kt,layers:["top","bottom"],pcb_component_id:S,port_hints:J?[J]:[],pcb_port_id:W,pin_number:nt})}else if(G.pad_shape==="circle"){let ut=J?k.get(J):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${M++}`,shape:"circle",x:G.at[0],y:-G.at[1],outer_diameter:G.size[0],hole_diameter:G.drill?.width,layers:["top","bottom"],pcb_component_id:S,port_hints:J?[J]:[],pcb_port_id:ut,pin_number:nt})}else if(G.pad_shape==="oval"){let ut=J?k.get(J):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${M++}`,shape:"pill",x:G.at[0],y:-G.at[1],outer_width:G.size[0],outer_height:G.size[1],hole_width:G.drill?.width,hole_height:G.drill?.height,layers:["top","bottom"],pcb_component_id:S,port_hints:J?[J]:[],pcb_port_id:ut,pin_number:nt})}}else G.pad_type==="np_thru_hole"&&l.push({type:"pcb_hole",pcb_hole_id:`pcb_hole_${I++}`,x:G.at[0],y:-G.at[1],hole_diameter:G.drill?.width,pcb_component_id:S})}if(a)for(let G of a){let J=Nd(G.name),nt=J?h.get(J):void 0,ut=G.layers?.some(at=>at.endsWith(".Cu")||at==="*.Cu"),ht=E9(G.at),kt=G.drill?.offset?.[0]??0,Et=G.drill?.offset?.[1]??0,ot=M9(kt,Et,ht),X=G.at[0]+ot.x,W=-(G.at[1]+ot.y),rt=G.drill?.width??0,pt=G.size?.width??rt,yt=G.roundrect_rratio??0,Z=yt>0?Math.min(Ur(ht)?G.size?.height??pt:G.size?.width??pt,Ur(ht)?G.size?.width??pt:G.size?.height??pt)/2*yt:0;if(ut)if(G.pad_shape==="rect"){let at=J?k.get(J):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${M++}`,shape:"circular_hole_with_rect_pad",hole_shape:"circle",pad_shape:"rect",x:G.at[0],y:-G.at[1],hole_offset_x:-ot.x,hole_offset_y:-ot.y,hole_diameter:rt,rect_pad_width:Ur(ht)?G.size?.height??pt:G.size?.width??pt,rect_pad_height:Ur(ht)?G.size?.width??pt:G.size?.height??pt,rect_border_radius:Z,port_hints:J?[J]:[],layers:["top","bottom"],pcb_component_id:S,pcb_port_id:at,pin_number:nt})}else if(G.pad_shape==="oval"){let at=J?k.get(J):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${M++}`,shape:"pill",x:X,y:W,outer_width:Ur(ht)?G.size?.height??pt:G.size?.width??pt,outer_height:Ur(ht)?G.size?.width??pt:G.size?.height??pt,hole_width:Ur(ht)?G.drill?.height??rt:G.drill?.width??rt,hole_height:Ur(ht)?G.drill?.width??rt:G.drill?.height??rt,port_hints:J?[J]:[],layers:["top","bottom"],pcb_component_id:S,pcb_port_id:at,pin_number:nt})}else if(G.pad_shape==="roundrect"){let at=J?k.get(J):void 0,Mt=G.drill?.offset?.[0]??0,Ft=G.drill?.offset?.[1]??0,Ot=M9(Mt,Ft,ht),Ce=Ur(ht)?G.size?.height??pt:G.size?.width??pt,we=Ur(ht)?G.size?.width??pt:G.size?.height??pt;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${M++}`,shape:"circular_hole_with_rect_pad",hole_shape:"circle",pad_shape:"rect",x:X,y:W,hole_offset_x:-Ot.x,hole_offset_y:Ot.y,hole_diameter:rt,rect_pad_width:Ce,rect_pad_height:we,rect_border_radius:Z,port_hints:J?[J]:[],layers:["top","bottom"],pcb_component_id:S,pcb_port_id:at,pin_number:nt})}else{let at=J?k.get(J):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${M++}`,shape:"circle",x:X,y:W,outer_diameter:pt,hole_diameter:rt,port_hints:J?[J]:[],layers:["top","bottom"],pcb_component_id:S,pcb_port_id:at,pin_number:nt})}else l.push({type:"pcb_hole",pcb_hole_id:`pcb_hole_${I++}`,x:X,y:W,hole_diameter:pt,hole_shape:"circle",pcb_component_id:S})}let E=[];for(let G of e)G.layer.toLowerCase()==="edge.cuts"&&E.push({type:"line",start:{x:G.start[0],y:G.start[1]},end:{x:G.end[0],y:G.end[1]},strokeWidth:G.stroke.width});for(let G of i)G.layer.toLowerCase()==="edge.cuts"&&E.push({type:"arc",start:{x:G.start[0],y:G.start[1]},mid:{x:G.mid[0],y:G.mid[1]},end:{x:G.end[0],y:G.end[1]},strokeWidth:G.stroke.width});let A=aFt(E),R=0;for(let G of A){let J=cFt(G);J.length>=3&&l.push({type:"pcb_cutout",pcb_cutout_id:`pcb_cutout_${R++}`,shape:"polygon",points:J.map(nt=>({x:nt.x,y:-nt.y})),pcb_component_id:S})}let j=0,B=0,V=0,U=0;for(let G of e){let J=[{x:G.start[0],y:-G.start[1]},{x:G.end[0],y:-G.end[1]}],nt=G.layer.toLowerCase();nt==="f.cu"?l.push({type:"pcb_trace",pcb_trace_id:`pcb_trace_${j++}`,pcb_component_id:S,layer:Fs(G.layer),route:J,thickness:G.stroke.width}):nt==="f.silks"?l.push({type:"pcb_silkscreen_path",pcb_silkscreen_path_id:`pcb_silkscreen_path_${B++}`,pcb_component_id:S,layer:"top",route:J,stroke_width:G.stroke.width}):nt==="edge.cuts"?J_("Skipping Edge.Cuts fp_line (converted to pcb_cutout)",G.layer):nt==="f.fab"?l.push({type:"pcb_fabrication_note_path",fabrication_note_path_id:`fabrication_note_path_${V++}`,pcb_component_id:S,layer:"top",route:J,stroke_width:G.stroke.width,port_hints:[]}):nt.startsWith("user.")?l.push({type:"pcb_note_line",pcb_note_line_id:`pcb_note_line_${U++}`,pcb_component_id:S,x1:G.start[0],y1:-G.start[1],x2:G.end[0],y2:-G.end[1],stroke_width:G.stroke.width}):J_("Unhandled layer for fp_line",G.layer)}if(c)for(let G of c){let J=[],nt=ot=>{!Number.isFinite(ot.x)||!Number.isFinite(ot.y)||J.push(ot)};for(let ot of G.pts){if(Array.isArray(ot)){nt({x:ot[0],y:-ot[1]});continue}if(ot&&typeof ot=="object"&&"kind"in ot){if(ot.kind==="arc"){let X=_l(ot.start),W=_l(ot.mid),rt=_l(ot.end),pt=C9(X,W,rt),yt=Math.max(8,Math.ceil(pt)),Z=Math.max(2,Math.ceil(pt/.1)),at=I9(X,W,rt,Z).map(Mt=>({x:Mt.x,y:-Mt.y}));for(let Mt of at)nt(Mt)}continue}}let ut=J,kt=ut.length>2&&ut[0].x===ut[ut.length-1].x&&ut[0].y===ut[ut.length-1].y?ut.slice(0,-1):ut;if(ut.length===0)continue;let Et=G.stroke?.width??0;if(G.layer.endsWith(".Cu")){let ot=pFt(kt);ot?l.push({type:"pcb_smtpad",pcb_smtpad_id:`pcb_smtpad_${C++}`,shape:"rect",x:ot.x,y:ot.y,width:ot.width,height:ot.height,layer:Fs(G.layer),pcb_component_id:S}):hFt(G.fill)?kt.length>=3?l.push({type:"pcb_smtpad",pcb_smtpad_id:`pcb_smtpad_${C++}`,shape:"polygon",points:kt,layer:Fs(G.layer),pcb_component_id:S}):kt.length>=2&&l.push({type:"pcb_trace",pcb_trace_id:`pcb_trace_${j++}`,pcb_component_id:S,layer:Fs(G.layer),route:kt,thickness:Et}):kt.length>=2&&l.push({type:"pcb_trace",pcb_trace_id:`pcb_trace_${j++}`,pcb_component_id:S,layer:Fs(G.layer),route:kt,thickness:Et})}else G.layer.endsWith(".SilkS")?l.push({type:"pcb_silkscreen_path",pcb_silkscreen_path_id:`pcb_silkscreen_path_${B++}`,pcb_component_id:S,layer:Fs(G.layer),route:ut,stroke_width:Et}):G.layer.endsWith(".Fab")?l.push({type:"pcb_fabrication_note_path",fabrication_note_path_id:`fabrication_note_path_${V++}`,pcb_component_id:S,layer:Fs(G.layer),route:kt,stroke_width:Et,port_hints:[]}):J_("Unhandled layer for fp_poly",G.layer)}let H=0;for(let G of i){let J=G.layer.toLowerCase();if(J==="edge.cuts"){J_("Skipping Edge.Cuts fp_arc (converted to pcb_cutout)",G.layer);continue}let nt=_l(G.start),ut=_l(G.mid),ht=_l(G.end),kt=C9(nt,ut,ht),Et=I9(nt,ut,ht,Math.ceil(kt));if(J.startsWith("user.")){l.push({type:"pcb_note_path",pcb_note_path_id:`pcb_note_path_${H++}`,pcb_component_id:S,route:Et.map(X=>({x:X.x,y:-X.y})),stroke_width:G.stroke.width});continue}let ot=Fs(G.layer);if(!ot){J_("Unable to convert layer for fp_arc",G.layer);continue}l.push({type:"pcb_silkscreen_path",pcb_silkscreen_path_id:`pcb_silkscreen_path_${B++}`,layer:ot,pcb_component_id:S,route:Et.map(X=>({x:X.x,y:-X.y})),stroke_width:G.stroke.width})}if(r)for(let G of r){let J=G.layer.toLowerCase(),nt=_l(G.center),ut=_l(G.end),ht=Math.sqrt((ut.x-nt.x)**2+(ut.y-nt.y)**2),kt=Math.max(16,Math.ceil(2*Math.PI*ht)),Et=[];for(let ot=0;ot<=kt;ot++){let X=ot/kt*2*Math.PI;Et.push({x:nt.x+ht*Math.cos(X),y:nt.y+ht*Math.sin(X)})}J.startsWith("user.")&&l.push({type:"pcb_note_path",pcb_note_path_id:`pcb_note_path_${H++}`,pcb_component_id:S,route:Et.map(ot=>({x:ot.x,y:-ot.y})),stroke_width:G.stroke.width})}for(let G of t){let J=Fs(G.layer);G.layer.endsWith(".SilkS")?l.push({type:"pcb_silkscreen_text",layer:J,font:"tscircuit2024",font_size:G.effects?.font?.size[0]??1,pcb_component_id:S,anchor_position:{x:G.at[0],y:-G.at[1]},anchor_alignment:"center",text:G.text}):G.layer.endsWith(".Fab")?l.push({type:"pcb_fabrication_note_text",layer:J,font:"tscircuit2024",font_size:G.effects?.font?.size[0]??1,pcb_component_id:S,anchor_position:{x:G.at[0],y:-G.at[1]},anchor_alignment:"center",text:G.text}):J_("Unhandled layer for fp_text",G.layer)}let et=o.find(G=>G.key==="Reference"),tt=o.find(G=>G.key==="Value"),_t=[et,tt].filter(G=>G&&!!G.val);for(let G of _t){let J=G.attributes.at;if(!J)continue;let ut=G.attributes.layer?.toLowerCase()?.endsWith(".fab"),ht=lFt(t);l.push({type:ut?"pcb_fabrication_note_text":"pcb_silkscreen_text",layer:"top",font:"tscircuit2024",font_size:ht,pcb_component_id:S,anchor_position:{x:J[0],y:-J[1]},anchor_alignment:"center",text:G.val})}return l},Oit=async n=>{let e=oFt(n);return await dFt(e)};var Lit=async n=>{try{return(await import(n)).default}catch{console.log(`Failed to load ${n} locally, trying CDN fallback...`);try{let t=await fetch(`https://cdn.jsdelivr.net/npm/${n}/+esm`);if(!t.ok)throw new Error(`Failed to fetch ${n} from CDN: ${t.statusText}`);let i=await t.text(),r=new Blob([i],{type:"application/javascript"}),s=URL.createObjectURL(r);try{let{default:o}=await import(s);return o}finally{URL.revokeObjectURL(s)}}catch(t){throw console.error(`CDN fallback for ${n} also failed:`,t),t}}};var fFt="https://kicad-mod-cache.tscircuit.com",hP=null,Fit=()=>({partsEngine:bit,spiceEngineMap:{ngspice:{simulate:async n=>{if(!hP){let e=await Lit("@tscircuit/ngspice-spice-engine").catch(t=>{throw new Error("Could not load ngspice engine from local node_modules or CDN fallback.",{cause:t})});e&&(hP=await e())}if(!hP)throw new Error("Could not load ngspice engine from local node_modules or CDN fallback.");return hP.simulate(n)}}},footprintLibraryMap:{kicad:async n=>{let e=`${fFt}/${n}`,t=`${e}.circuit.json`,r=await(await fetch(t)).json(),s=Array.isArray(r)?r.filter(a=>a?.type==="pcb_silkscreen_text"?a?.text==="REF**":!0):r,o=`${e}.wrl`;return{footprintCircuitJson:s,cadModel:{wrlUrl:o,modelUnitToMmScale:2.54}}}},footprintFileParserMap:{kicad_mod:{loadFromUrl:async n=>{let e=await fetch(n).then(i=>i.text()),t=await Oit(e);return{footprintCircuitJson:Array.isArray(t)?t:[t]}}}}});var N9=Gt(En(),1),dxe=(0,N9.default)("tsci:eval:execution-context");function dP(n,e={}){globalThis.React=zit;let t=e.platform||Fit(),i=e.projectConfig?{...t,...e.projectConfig}:t;i.partsEngineDisabled&&(i.partsEngine=void 0);let r=new Z_({platform:i});e.name&&(r.name=e.name),e.debugNamespace&&r.enableDebug(e.debugNamespace);let s=[];return{fsMap:{},entrypoint:"",logger:{info:o=>{s.push({msg:o})},getLogs:()=>s,stringifyLogs:()=>s.map(o=>o.msg).join(`
|
|
254
|
-
`)},preSuppliedImports:{"@tscircuit/core":oP,tscircuit:oP,"@tscircuit/math-utils":m4,react:zit,debug:N9.default,"@tscircuit/props":{}},circuit:r,tsConfig:null,importStack:[],currentlyImporting:new Set,...n}}function yl(n){let e=n;return e=e.replace(/\\/g,"/"),e=e.trim(),e.startsWith("./")&&(e=e.slice(2)),e.startsWith("/")&&(e=e.slice(1)),e}function $it(n){let e={};for(let[t,i]of Object.entries(n))e[yl(t)]=i;return e}function ao(n){if(!n)return".";let t=n.replace(/\\/g,"/").replace(/\/+$/,"");return t.indexOf("/")===-1?".":t.substring(0,t.lastIndexOf("/"))||"/"}function fP(n,e){if(n.startsWith("../")){let t=ao(e);return fP(n.slice(3),t)}return n.startsWith("./")?fP(n.slice(2),e):n.startsWith("/")?n.slice(1):`${e}/${n}`}function V1(n){if(Array.isArray(n))return null;let e=n["tsconfig.json"];if(!e)return null;try{let t=e.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g,"");return JSON.parse(t)}catch(t){throw new Error(`Failed to parse tsconfig.json: ${t.message}`)}}function Dit(n){let{importPath:e,normalizedFilePathMap:t,extensions:i,tsConfig:r}=n,
|
|
254
|
+
`)},preSuppliedImports:{"@tscircuit/core":oP,tscircuit:oP,"@tscircuit/math-utils":m4,react:zit,debug:N9.default,"@tscircuit/props":{}},circuit:r,tsConfig:null,importStack:[],currentlyImporting:new Set,...n}}function yl(n){let e=n;return e=e.replace(/\\/g,"/"),e=e.trim(),e.startsWith("./")&&(e=e.slice(2)),e.startsWith("/")&&(e=e.slice(1)),e}function $it(n){let e={};for(let[t,i]of Object.entries(n))e[yl(t)]=i;return e}function ao(n){if(!n)return".";let t=n.replace(/\\/g,"/").replace(/\/+$/,"");return t.indexOf("/")===-1?".":t.substring(0,t.lastIndexOf("/"))||"/"}function fP(n,e){if(n.startsWith("../")){let t=ao(e);return fP(n.slice(3),t)}return n.startsWith("./")?fP(n.slice(2),e):n.startsWith("/")?n.slice(1):`${e}/${n}`}function V1(n){if(Array.isArray(n))return null;let e=n["tsconfig.json"];if(!e)return null;try{let t=e.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g,"");return JSON.parse(t)}catch(t){throw new Error(`Failed to parse tsconfig.json: ${t.message}`)}}function Dit(n){let{importPath:e,normalizedFilePathMap:t,extensions:i,tsConfig:r,tsconfigDir:s}=n,o=r?.compilerOptions?.paths;if(!o)return null;let a=r?.compilerOptions?.baseUrl||".",c=u=>{let h=yl(u);if(t.has(h))return t.get(h);for(let f of i){let _=`${h}.${f}`;if(t.has(_))return t.get(_)}return null};for(let[u,h]of Object.entries(o))if(u.includes("*")){let[_,g]=u.split("*");if(!e.startsWith(_)||!e.endsWith(g||""))continue;let x=e.slice(_.length,e.length-(g?g.length:0));for(let v of h){let P=v.replace("*",x),S=a&&!P.startsWith("./")&&!P.startsWith("/")?`${a}/${P}`:P,T=c(S);if(T)return T}}else{if(e!==u)continue;for(let _ of h){let g=a&&!_.startsWith("./")&&!_.startsWith("/")?`${a}/${_}`:_,x=c(g);if(x)return x}}let l=A9({importPath:e,normalizedFilePathMap:t,extensions:i,tsConfig:r,tsconfigDir:s});return l||null}function A9(n){let{importPath:e,normalizedFilePathMap:t,extensions:i,tsConfig:r,tsconfigDir:s}=n,o=r?.compilerOptions?.baseUrl;if(!o)return null;let c=`${s||"."}/${o}/${e}`.replace(/\/\//g,"/"),l=yl(c);if(t.has(l))return t.get(l);for(let u of i){let h=`${l}.${u}`;if(t.has(h))return t.get(h)}return null}function jit(n,e){let t=e?.compilerOptions?.paths;if(!t)return!1;for(let[i]of Object.entries(t))if(i.includes("*")){let[s,o]=i.split("*");if(n.startsWith(s)&&n.endsWith(o||""))return!0}else if(n===i)return!0;return!1}var G1=(n,e,t,i={})=>{let r=t?fP(n,t):n,s=new Set(Array.isArray(e)?e:Object.keys(e));if(s.has(r))return r;let o=new Map;for(let u of s)o.set(yl(u),u);let a=yl(r);if(o.has(a))return o.get(a);let c=["tsx","ts","json","js","jsx","obj","gltf","glb"];for(let u of c){let h=`${a}.${u}`;if(o.has(h))return o.get(h)}let l=i.tsConfig??null;if(!n.startsWith("./")&&!n.startsWith("../")){let u=Dit({importPath:n,normalizedFilePathMap:o,extensions:c,tsConfig:l,tsconfigDir:i.tsconfigDir});if(u)return u;let h=A9({importPath:n,normalizedFilePathMap:o,extensions:c,tsConfig:l,tsconfigDir:i.tsconfigDir});if(h)return h}if(!n.startsWith("./")&&!n.startsWith("../")){let u=yl(n);if(o.has(u))return o.get(u);for(let h of c){let f=`${u}.${h}`;if(o.has(f))return o.get(f)}}return null},mP=(n,e,t,i={})=>{let r=G1(n,e,t,i);if(!r)throw new Error(`File not found "${n}", available paths:
|
|
255
255
|
|
|
256
256
|
${Object.keys(e).join(", ")}`);return r};var _P=n=>{let e=/^\s*import\s+(?:(?:[\w\s]+,\s*)?(?:\*\s+as\s+[\w\s]+|\{[\s\w,]+\}|\w+)\s+from\s*)?['"](.+?)['"]/gm,t=[],i;for(;(i=e.exec(n))!==null;){let o=i[0];/^\s*import\s+type\b/.test(o)||t.push(i[1])}let r=/^\s*export\s+(?:type\s+)?(?:\*\s+as\s+[\w$]+|\*|\{[^}]+\})\s+from\s*['"](.+?)['"]/gm,s;for(;(s=r.exec(n))!==null;){let o=s[0];/^\s*export\s+type\b/.test(o)||t.push(s[1])}return t};function Ad(n,e,t){globalThis.__tscircuit_require=r=>{let s=G1(r,e,t),o=s&&e[s];if(!e[r]&&!o)throw new Error(`Import "${r}" not found ${t?`in "${t}"`:""}`);let a=e[r]||e[s];return new Proxy(a,{get(c,l){if(!(l in c)){if(l==="default")return c.default!==void 0?c.default:c.__esModule?void 0:typeof c=="function"||typeof c=="object"?c:void 0;if(l==="__esModule")return!0;throw new Error(`Component "${String(l)}" is not exported by "${r}"`)}return c[l]}})};let i=`
|
|
257
257
|
var exports = {};
|
|
@@ -456,9 +456,9 @@ ${u.join(" -> ")}`)}if(!e.fsMap[a])throw yy("fsPath not found in fsMap:",a),new
|
|
|
456
456
|
|
|
457
457
|
${e.logger.stringifyLogs()}`);return{content:await f.text(),error:null}}).catch(f=>({error:f,content:null}));if(a)throw console.error("Error fetching npm import",n,a),a;let c=eXt(s),l=ao(c),u=_P(o);for(let f of u)i[f]||await Tf(f,e,t+1,{cwd:l});let h=I0(o,c||n);try{let f=Ad(h,i,l).exports;i[n]=f,i[c]=f,i[s]=f}catch(f){throw new Error(`Eval npm package error for "${n}": ${f.message}
|
|
458
458
|
|
|
459
|
-
${e.logger.stringifyLogs()}`)}}var Flt=Gt(En(),1),Llt=(0,Flt.default)("tsci:eval:import-eval-path");async function Tf(n,e,t=0,i={}){Llt("importEvalPath called with:",{importName:n,depth:t,opts:i}),e.logger.info(`importEvalPath("${n}", {cwd: "${i.cwd}", depth: ${t}})`),Llt(`${" ".repeat(t)}\u27A1\uFE0F`,n);let{preSuppliedImports:r}=e;if(r[n]){e.logger.info(`Import "${n}" in preSuppliedImports[1]`);return}if(n.startsWith("./")&&r[n.slice(2)]){e.logger.info(`Import "${n}" in preSuppliedImports[2]`);return}if(t>30)throw new Error(`Max depth for imports reached (30) Import Path: ${e.importStack.join(" -> ")}`);if(n.startsWith("/npm/")){let
|
|
459
|
+
${e.logger.stringifyLogs()}`)}}var Flt=Gt(En(),1),Llt=(0,Flt.default)("tsci:eval:import-eval-path");async function Tf(n,e,t=0,i={}){Llt("importEvalPath called with:",{importName:n,depth:t,opts:i}),e.logger.info(`importEvalPath("${n}", {cwd: "${i.cwd}", depth: ${t}})`),Llt(`${" ".repeat(t)}\u27A1\uFE0F`,n);let{preSuppliedImports:r}=e;if(r[n]){e.logger.info(`Import "${n}" in preSuppliedImports[1]`);return}if(n.startsWith("./")&&r[n.slice(2)]){e.logger.info(`Import "${n}" in preSuppliedImports[2]`);return}if(t>30)throw new Error(`Max depth for imports reached (30) Import Path: ${e.importStack.join(" -> ")}`);if(n.startsWith("/npm/")){let l=n.replace(/^\/npm\//,"").replace(/\/\+esm$/,"");e.logger.info(`importNpmPackage("${l}")`),await M7(l,e,t);let u=r[l];u&&(r[n]=u);return}let s=".";if(e.tsConfig&&i.cwd){let l=i.cwd.match(/^(node_modules\/[^\/]+)/);l&&(s=l[1])}let o=G1(n,e.fsMap,i.cwd,{tsConfig:e.tsConfig,tsconfigDir:s});if(o){e.logger.info(`importLocalFile("${o}")`),await $0(o,e,t),n!==o&&(r[n]=r[o]);return}let a=e.tsConfig??V1(e.fsMap);if(!e.tsConfig&&a&&(e.tsConfig=a),jit(n,a))throw new Error(`Import "${n}" matches a tsconfig path alias but could not be resolved to an existing file${i.cwd?` from directory "${i.cwd}"`:""}
|
|
460
460
|
|
|
461
|
-
${e.logger.stringifyLogs()}`);let
|
|
461
|
+
${e.logger.stringifyLogs()}`);let c=uT(n,e.fsMap,i.cwd||"");if(c)return e.logger.info(`resolvedNodeModulePath="${c}"`),e.logger.info(`importNodeModule("${n}")`),T7(n,e,t);if(!n.startsWith(".")&&!n.startsWith("/")&&!n.startsWith("@tsci/")&&e.circuit?.platform?.nodeModulesResolver){e.logger.info(`importNodeModule("${n}") via nodeModulesResolver`);try{await T7(n,e,t);return}catch{e.logger.info(`nodeModulesResolver failed for "${n}", falling back to npm CDN`)}}if(n.startsWith("@tsci/"))return e.logger.info(`importSnippet("${n}")`),Nlt(n,e,t);if(!n.startsWith(".")&&!n.startsWith("/"))return e.logger.info(`importNpmPackage("${n}")`),M7(n,e,t);throw new Error(`Unresolved import "${n}" ${i.cwd?`from directory "${i.cwd}"`:""}
|
|
462
462
|
|
|
463
463
|
${e.logger.stringifyLogs()}`)}var zlt=Gt(En(),1),nXt=(0,zlt.default)("tsci:eval:setupDefaultEntrypointIfNeeded"),$lt=n=>{if(!n.entrypoint&&!n.mainComponentPath)if("index.tsx"in n.fsMap)n.mainComponentPath="index.tsx";else if("index.ts"in n.fsMap)n.mainComponentPath="index.ts";else if(Object.keys(n.fsMap).filter(e=>e.endsWith(".tsx")).length===1)n.mainComponentPath=Object.keys(n.fsMap)[0];else if("tscircuit.config.json"in n.fsMap){let e=n.fsMap["tscircuit.config.json"];try{let t=JSON.parse(e);t.mainEntrypoint&&(n.entrypoint=t.mainEntrypoint)}catch(t){console.warn("Failed to parse tscircuit.config.json:",t)}}else throw new Error("Either entrypoint or mainComponentPath must be provided (no index file, could not infer entrypoint)");if(!n.entrypoint&&n.mainComponentPath){if(n.entrypoint="entrypoint.tsx",!n.fsMap[mP(n.mainComponentPath,n.fsMap)])throw new Error(`Main component path "${n.mainComponentPath}" not found in fsMap. Available paths: ${Object.keys(n.fsMap).join(", ")}`);n.fsMap[n.entrypoint]=`
|
|
464
464
|
import * as UserComponents from "./${n.mainComponentPath}";
|