tscircuit 0.0.786-libonly → 0.0.787-libonly

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.
@@ -244,7 +244,7 @@ ${o}`)}catch(s){Qs(`Failed to convert circuit JSON to SPICE: ${s}`);return}for(l
244
244
  `),a={x:n.center.x+n.width/2-.25,y:n.center.y-n.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:t}=this.root,n=t.source_board.insert({source_group_id:this.source_group_id,title:this.props.title||this.props.name});this.source_board_id=n.source_board_id}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=n.width??0,r=n.height??0,o={x:(n.pcbX??0)+(n.outlineOffsetX??0),y:(n.pcbY??0)+(n.outlineOffsetY??0)},{boardAnchorPosition:s,boardAnchorAlignment:a}=n;if(s&&(o=v3t({boardAnchorPosition:s,boardAnchorAlignment:a??"center",width:i,height:r})),n.outline){let u=n.outline.map(x=>x.x),h=n.outline.map(x=>x.y),d=Math.min(...u),_=Math.max(...u),y=Math.min(...h),g=Math.max(...h);i=_-d,r=g-y,o={x:(d+_)/2+(n.outlineOffsetX??0),y:(y+g)/2+(n.outlineOffsetY??0)}}let c=n.outline;!c&&n.borderRadius!=null&&i>0&&r>0&&(c=eV(i,r,n.borderRadius));let l=t.pcb_board.insert({center:o,thickness:this.boardThickness,num_layers:this.allLayers.length,width:i,height:r,outline:c?.map(u=>({x:u.x+(n.outlineOffsetX??0),y:u.y+(n.outlineOffsetY??0)})),material:n.material});this.pcb_board_id=l.pcb_board_id,this._addBoardInformationToSilkscreen()}removePcbComponentRender(){let{db:t}=this.root;this.pcb_board_id&&(t.pcb_board.delete(this.pcb_board_id),this.pcb_board_id=null)}_computePcbGlobalTransformBeforeLayout(){return Ri()}doInitialPcbDesignRuleChecks(){this.root?.pcbDisabled||this.getInheritedProperty("routingDisabled")||super.doInitialPcbDesignRuleChecks()}updatePcbDesignRuleChecks(){if(this.root?.pcbDisabled||this.getInheritedProperty("routingDisabled"))return;let{db:t}=this.root;if(!this._areChildSubcircuitsRouted()||this._drcChecksComplete)return;this._drcChecksComplete=!0;let n=yY(t.toArray());for(let l of n)t.pcb_trace_error.insert(l);let i=_Y(t.toArray());for(let l of i)t.pcb_port_not_connected_error.insert(l);let r=xY(t.toArray());for(let l of r)t.pcb_component_outside_board_error.insert(l);let o=SY(t.toArray());for(let l of o)t.pcb_trace_error.insert(l);let s=wY(t.toArray());for(let l of s)t.pcb_via_clearance_error.insert(l);let a=vY(t.toArray());for(let l of a)t.pcb_via_clearance_error.insert(l);let c=PY(t.toArray());for(let l of c)t.pcb_footprint_overlap_error.insert(l)}_emitRenderLifecycleEvent(t,n){super._emitRenderLifecycleEvent(t,n),n==="start"&&this.root?.emit("board:renderPhaseStarted",{renderId:this._renderId,phase:t})}},y5t=new Proxy({},{get:(e,t)=>t}),na=y5t,hx="rgba(132, 0, 0)",dx=.12,NV=class extends On{constructor(){super(...arguments);I(this,"_adjustSilkscreenTextAutomatically",!0)}get config(){return{componentName:"Capacitor",schematicSymbolName:this.props.polarized?"capacitor_polarized":this.props.symbolName??"capacitor",zodProps:Cz,sourceFtype:na.simple_capacitor}}initPorts(){typeof this.props.footprint=="string"?super.initPorts({additionalAliases:{pin1:["anode","pos"],pin2:["cathode","neg"]}}):super.initPorts()}_getSchematicSymbolDisplayValue(){let t=this.props.capacitance,n=typeof t=="string"?t:`${ti(this._parsedProps.capacitance)}F`;return this._parsedProps.schShowRatings&&this._parsedProps.maxVoltageRating?`${n}/${ti(this._parsedProps.maxVoltageRating)}V`:n}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.decouplingFor,this.props.decouplingTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.decouplingFor&&this.props.decouplingTo&&(this.add(new ko({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.decouplingFor})),this.add(new ko({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.decouplingTo}))),this._createTracesFromConnectionsProp()}doInitialSourceRender(){let{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_capacitor",name:this.name,manufacturer_part_number:n.manufacturerPartNumber??n.mfn,supplier_part_numbers:n.supplierPartNumbers,capacitance:n.capacitance,max_voltage_rating:n.maxVoltageRating,max_decoupling_trace_length:n.maxDecouplingTraceLength,display_capacitance:this._getSchematicSymbolDisplayValue(),are_pins_interchangeable:!n.polarized});this.source_component_id=i.source_component_id}},fx=class extends On{constructor(t){super(t);I(this,"schematicBoxDimensions",null)}get config(){return{componentName:"Chip",zodProps:Op,shouldRenderAsSchematicBox:!0}}initPorts(t={}){super.initPorts(t);let{_parsedProps:n}=this;if(n.externallyConnectedPins){let i=new Set;for(let[r,o]of n.externallyConnectedPins)i.add(r),i.add(o);for(let r of i)if(!this.children.find(s=>s instanceof $i&&s.isMatchingAnyOf([r]))){let s=r.match(/^pin(\d+)$/);if(s){let a=parseInt(s[1]);this.add(new $i({pinNumber:a,aliases:[r]}))}else this.add(new $i({name:r,aliases:[r]}))}}}doInitialSchematicComponentRender(){let{_parsedProps:t}=this;t?.noSchematicRepresentation!==!0&&super.doInitialSchematicComponentRender()}doInitialSourceRender(){let{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_chip",name:this.name,manufacturer_part_number:n.manufacturerPartNumber,supplier_part_numbers:n.supplierPartNumbers});this.source_component_id=i.source_component_id}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=n.layer??"top";if(i!=="top"&&i!=="bottom"){let o=this.getSubcircuit(),s=fp.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:o.subcircuit_id??void 0});t.pcb_component_invalid_layer_error.insert(s)}let r=t.pcb_component.insert({center:{x:n.pcbX??0,y:n.pcbY??0},width:2,height:3,layer:i==="top"||i==="bottom"?i:"top",rotation:n.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0,do_not_place:n.doNotPlace??!1,obstructs_within_bounds:n.obstructsWithinBounds??!0});this.pcb_component_id=r.pcb_component_id}doInitialCreateTracesFromProps(){let{_parsedProps:t}=this;if(t.externallyConnectedPins)for(let[n,i]of t.externallyConnectedPins)this.add(new ko({from:`${this.getSubcircuitSelector()} > port.${n}`,to:`${this.getSubcircuitSelector()} > port.${i}`}));this._createTracesFromConnectionsProp()}doInitialSimulationRender(){let{db:t}=this.root,{pinAttributes:n}=this.props;if(!n)return;let i=null,r=null,o,s=this.selectAll("port");for(let h of s)for(let d of h.getNameAndAliases())if(n[d]){let _=n[d];_.providesPower&&(i=h,o=_.providesVoltage),_.providesGround&&(r=h)}if(!i||!r||o===void 0)return;let a=t.source_port.get(i.source_port_id);if(!a?.subcircuit_connectivity_map_key)return;let c=t.source_port.get(r.source_port_id);if(!c?.subcircuit_connectivity_map_key)return;let l=t.source_net.getWhere({subcircuit_connectivity_map_key:a.subcircuit_connectivity_map_key}),u=t.source_net.getWhere({subcircuit_connectivity_map_key:c.subcircuit_connectivity_map_key});!l||!u||t.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:o})}},AV=class extends fx{constructor(e){super(e)}get config(){return{...super.config,componentName:"Pinout",zodProps:bz}}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_pinout",name:this.name,manufacturer_part_number:t.manufacturerPartNumber,supplier_part_numbers:t.supplierPartNumbers});this.source_component_id=n.source_component_id}},RV=class extends On{constructor(){super(...arguments);I(this,"pos",this.portMap.pin1);I(this,"anode",this.portMap.pin1);I(this,"neg",this.portMap.pin2);I(this,"cathode",this.portMap.pin2)}get config(){let t={schottky:"schottky_diode",avalanche:"avalanche_diode",zener:"zener_diode",photodiode:"photodiode"},n=this.props.schottky?"schottky":this.props.avalanche?"avalanche":this.props.zener?"zener":this.props.photo?"photodiode":null;return{schematicSymbolName:n?t[n]:this.props.symbolName??"diode",componentName:"Diode",zodProps:Hz,sourceFtype:"simple_diode"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){let{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_diode",name:this.name,manufacturer_part_number:n.manufacturerPartNumber??n.mfn,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},OV=class extends On{get config(){return{componentName:"fuse",schematicSymbolName:this.props.symbolName??"fuse",zodProps:vz,sourceFtype:na.simple_fuse}}_getSchematicSymbolDisplayValue(){let e=this._parsedProps.currentRating,t=this._parsedProps.voltageRating,n=typeof e=="string"?parseFloat(e):e,i=typeof t=="string"?parseFloat(t):t;return`${ti(n)}A / ${ti(i)}V`}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,n=typeof t.currentRating=="string"?parseFloat(t.currentRating):t.currentRating,i=typeof t.voltageRating=="string"?parseFloat(t.voltageRating):t.voltageRating,r=e.source_component.insert({name:this.name,ftype:na.simple_fuse,current_rating_amps:n,voltage_rating_volts:i,display_current_rating:`${ti(n)}A`,display_voltage_rating:`${ti(i)}V`});this.source_component_id=r.source_component_id}},LV=class extends On{constructor(){super(...arguments);I(this,"schematicDimensions",null)}get config(){return{schematicSymbolName:void 0,componentName:"Jumper",zodProps:o4,shouldRenderAsSchematicBox:!0}}_getSchematicPortArrangement(){let t=super._getSchematicPortArrangement();if(t&&Object.keys(t).length>0)return t;let n=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"?n:0,rightSize:i==="right"?n:0}}doInitialSourceRender(){let{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_chip",name:this.name,manufacturer_part_number:n.manufacturerPartNumber,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=i.source_component_id}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=t.pcb_component.insert({center:{x:n.pcbX??0,y:n.pcbY??0},width:2,height:3,layer:n.layer??"top",rotation:n.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0,do_not_place:n.doNotPlace??!1,obstructs_within_bounds:n.obstructsWithinBounds??!0});this.pcb_component_id=i.pcb_component_id}doInitialPcbTraceRender(){let{db:t}=this.root,n=t.pcb_port.list({pcb_component_id:this.pcb_component_id}),i={};for(let s=0;s<n.length;s++){let a=n[s],c=t.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=t.pcb_trace.list({pcb_component_id:this.pcb_component_id}),o=s=>{if(s&&typeof s=="string"&&s.startsWith("{PIN")){let a=s.replace("{PIN","").replace("}","");return i[a]||s}return s};for(let s of r)if(s.route)for(let a of s.route)a.route_type==="wire"&&(a.start_pcb_port_id=o(a.start_pcb_port_id),a.end_pcb_port_id=o(a.end_pcb_port_id))}},zV=class extends On{constructor(){super(...arguments);I(this,"schematicDimensions",null)}_getPinNumberFromBridgedPinName(t){return this.selectOne(`port.${t}`,{type:"port"})?._parsedProps.pinNumber??null}get defaultInternallyConnectedPinNames(){if(this._parsedProps.bridged){let t=this.children.filter(n=>n.componentName==="Port").map(n=>n.name);return t.length>0?[t]:[]}return this._parsedProps.bridgedPins??[]}get config(){let t=this._parsedProps??this.props,n=t.pinCount;if(t.pinCount==null&&!t.footprint&&(n=2),t.pinCount==null){let o=(t.bridgedPins??[]).flat().map(l=>this._getPinNumberFromBridgedPinName(l)).filter(l=>l!==null),s=o.length>0?Math.max(...o):0,a=t.pinLabels?Object.keys(t.pinLabels).length:0,c=Math.max(s,a);(c===2||c===3)&&(n=c),n==null&&t.footprint&&[2,3].includes(this.getPortsFromFootprint().length)&&(n=this.getPortsFromFootprint().length)}let i="";n?i+=`solderjumper${n}`:i="solderjumper";let r=[];return Array.isArray(t.bridgedPins)&&t.bridgedPins.length>0?r=Array.from(new Set(t.bridgedPins.flat().map(o=>this._getPinNumberFromBridgedPinName(o)).filter(o=>o!==null))).sort((o,s)=>o-s):t.bridged&&n&&(r=Array.from({length:n},(o,s)=>s+1)),r.length>0&&(i+=`_bridged${r.join("")}`),{schematicSymbolName:t.symbolName??i,componentName:"SolderJumper",zodProps:xz,shouldRenderAsSchematicBox:!0}}_getSchematicPortArrangement(){let t=super._getSchematicPortArrangement();if(t&&Object.keys(t).length>0)return t;let n=this._parsedProps.pinCount??(Array.isArray(this._parsedProps.pinLabels)?this._parsedProps.pinLabels.length:this._parsedProps.pinLabels?Object.keys(this._parsedProps.pinLabels).length:this.getPortsFromFootprint().length);n==null&&!this._parsedProps.footprint&&(n=2);let i=this._parsedProps.schDirection??"right";return{leftSize:i==="left"?n:0,rightSize:i==="right"?n:0}}doInitialSourceRender(){let{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_chip",name:this.name,manufacturer_part_number:n.manufacturerPartNumber,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=i.source_component_id}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=t.pcb_component.insert({center:{x:n.pcbX??0,y:n.pcbY??0},width:2,height:3,layer:n.layer??"top",rotation:n.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0,do_not_place:n.doNotPlace??!1,obstructs_within_bounds:n.obstructsWithinBounds??!0});this.pcb_component_id=i.pcb_component_id}doInitialPcbTraceRender(){let{db:t}=this.root,n=t.pcb_port.list({pcb_component_id:this.pcb_component_id}),i={};for(let s=0;s<n.length;s++){let a=n[s],c=t.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=t.pcb_trace.list({pcb_component_id:this.pcb_component_id}),o=s=>{if(s&&typeof s=="string"&&s.startsWith("{PIN")){let a=s.replace("{PIN","").replace("}","");return i[a]||s}return s};for(let s of r)if(s.route)for(let a of s.route)a.route_type==="wire"&&(a.start_pcb_port_id=o(a.start_pcb_port_id),a.end_pcb_port_id=o(a.end_pcb_port_id))}},FV=class extends On{constructor(){super(...arguments);I(this,"pos",this.portMap.pin1);I(this,"anode",this.portMap.pin1);I(this,"neg",this.portMap.pin2);I(this,"cathode",this.portMap.pin2)}get config(){let t={laser:"laser_diode"},n=this.props.laser?"laser":null;return{schematicSymbolName:n?t[n]:this.props.symbolName??"led",componentName:"Led",zodProps:Uz,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 t=super.getFootprinterString();return t&&this.props.color?`${t}_color(${this.props.color})`:t}doInitialSourceRender(){let{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_led",name:this.name,wave_length:n.wavelength,color:n.color,symbol_display_value:this._getSchematicSymbolDisplayValue(),manufacturer_part_number:n.manufacturerPartNumber??n.mfn,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},DV=class extends On{constructor(){super(...arguments);I(this,"pos",this.portMap.pin1);I(this,"positive",this.portMap.pin1);I(this,"neg",this.portMap.pin2);I(this,"negative",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"power_factor_meter_horz",componentName:"PowerSource",zodProps:aF,sourceFtype:"simple_power_source"}}initPorts(){this.add(new $i({name:"pin1",pinNumber:1,aliases:["positive","pos"]})),this.add(new $i({name:"pin2",pinNumber:2,aliases:["negative","neg"]}))}doInitialSourceRender(){let{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_power_source",name:this.name,voltage:n.voltage,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=i.source_component_id}},g5t=Fn.extend({voltage:oi.optional(),frequency:mr.optional(),peakToPeakVoltage:oi.optional(),waveShape:p.enum(["sinewave","square","triangle","sawtooth"]).optional(),phase:Fe.optional(),dutyCycle:p.number().optional()}),$V=class extends On{constructor(){super(...arguments);I(this,"terminal1",this.portMap.terminal1);I(this,"terminal2",this.portMap.terminal2)}get config(){return{componentName:"VoltageSource",schematicSymbolName:this.props.waveShape==="square"?"square_wave":"ac_voltmeter",zodProps:g5t,sourceFtype:"simple_voltage_source"}}runRenderPhaseForChildren(t){if(!t.startsWith("Pcb"))for(let n of this.children)n.runRenderPhaseForChildren(t),n.runRenderPhase(t)}doInitialPcbComponentRender(){}initPorts(){super.initPorts({additionalAliases:{pin1:["terminal1"],pin2:["terminal2"]}})}doInitialSourceRender(){let{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_voltage_source",name:this.name,voltage:n.voltage,frequency:n.frequency,peak_to_peak_voltage:n.peakToPeakVoltage,wave_shape:n.waveShape,phase:n.phase,duty_cycle:n.dutyCycle,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=i.source_component_id}doInitialSimulationRender(){let{db:t}=this.root,{_parsedProps:n}=this,i=this.portMap.terminal1,r=this.portMap.terminal2;t.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:n.voltage,frequency:n.frequency,peak_to_peak_voltage:n.peakToPeakVoltage,wave_shape:n.waveShape,phase:n.phase,duty_cycle:n.dutyCycle})}},BV=class extends On{constructor(){super(...arguments);I(this,"_adjustSilkscreenTextAutomatically",!0)}get config(){return{componentName:"Resistor",schematicSymbolName:this.props.symbolName??"boxresistor",zodProps:Sz,sourceFtype:"simple_resistor"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${ti(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 ko({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pullupFor})),this.add(new ko({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pullupTo}))),this.props.pulldownFor&&this.props.pulldownTo&&(this.add(new ko({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pulldownFor})),this.add(new ko({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pulldownTo}))),this._createTracesFromConnectionsProp()}doInitialSourceRender(){let{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_resistor",name:this.name,manufacturer_part_number:n.manufacturerPartNumber??n.mfn,supplier_part_numbers:n.supplierPartNumbers,resistance:n.resistance,display_resistance:this._getSchematicSymbolDisplayValue(),are_pins_interchangeable:!0});this.source_component_id=i.source_component_id}},b5t=["leftedge","rightedge","topedge","bottomedge","center"],jV=class extends be{get config(){return{componentName:"Constraint",zodProps:kz}}constructor(e){if(super(e),("xdist"in e||"ydist"in e)&&!("edgeToEdge"in e)&&!("centerToCenter"in e))throw new Error(`edgeToEdge, centerToCenter must be set for xDist or yDist for ${this}`);if("for"in e&&e.for.length<2)throw new Error(`"for" must have at least two selectors for ${this}`)}_getAllReferencedComponents(){let e=[],t=this.getPrimitiveContainer();function n(i){let r=i.split(" ").pop(),o=b5t.includes(r)?r:void 0,s=o?i.replace(` ${o}`,""):i,a=t.selectOne(s,{pcbPrimitive:!0});a&&e.push({selector:i,component:a,componentSelector:s,edge:o})}for(let i of["left","right","top","bottom"])i in this._parsedProps&&n(this._parsedProps[i]);if("for"in this._parsedProps)for(let i of this._parsedProps.for)n(i);return{componentsWithSelectors:e}}},YV=class extends be{constructor(){super(...arguments);I(this,"fabrication_note_rect_id",null)}get config(){return{componentName:"FabricationNoteRect",zodProps:Kz}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),r=i(n.layer??"top");if(r!=="top"&&r!=="bottom")throw new Error(`Invalid layer "${r}" for FabricationNoteRect. Must be "top" or "bottom".`);let o=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id,s=this.getSubcircuit(),a=t.pcb_fabrication_note_rect.insert({pcb_component_id:o,layer:r,color:n.color,center:{x:n.pcbX??0,y:n.pcbY??0},width:n.width,height:n.height,stroke_width:n.strokeWidth??1,is_filled:n.isFilled??!1,has_stroke:n.hasStroke??!1,is_stroke_dashed:n.isStrokeDashed??!1,subcircuit_id:s?.subcircuit_id??void 0,pcb_group_id:this.getGroup()?.pcb_group_id??void 0});this.fabrication_note_rect_id=a.pcb_fabrication_note_rect_id}getPcbSize(){let{_parsedProps:t}=this;return{width:t.width,height:t.height}}},XV=class extends be{constructor(){super(...arguments);I(this,"fabrication_note_path_id",null)}get config(){return{componentName:"FabricationNotePath",zodProps:Jz}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,n=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 o=this._computePcbGlobalTransformBeforeLayout(),s=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id,a=t.pcb_fabrication_note_path.insert({pcb_component_id:s,layer:r,color:i.color,route:i.route.map(c=>{let l=ke(o,{x:c.x,y:c.y});return{...c,x:l.x,y:l.y}}),stroke_width:i.strokeWidth??.1,subcircuit_id:n?.subcircuit_id??void 0});this.fabrication_note_path_id=a.pcb_fabrication_note_path_id}},VV=class extends be{get config(){return{componentName:"FabricationNoteText",zodProps:Zz}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:e}=this.root,{_parsedProps:t}=this,n=this.getPrimitiveContainer(),i=this.getSubcircuit();e.pcb_fabrication_note_text.insert({anchor_alignment:t.anchorAlignment,anchor_position:{x:t.pcbX??0,y:t.pcbY??0},font:t.font??"tscircuit2024",font_size:t.fontSize??1,layer:"top",color:t.color,text:t.text??"",pcb_component_id:n.pcb_component_id,subcircuit_id:i?.subcircuit_id??void 0,pcb_group_id:this.getGroup()?.pcb_group_id??void 0})}},HV=class extends be{constructor(){super(...arguments);I(this,"fabrication_note_dimension_id",null);I(this,"isPcbPrimitive",!0)}get config(){return{componentName:"FabricationNoteDimension",zodProps:Qz}}_resolvePoint(t,n){if(typeof t=="string"){let o=this.getSubcircuit().selectOne(t);return o?o._getGlobalPcbPositionBeforeLayout():(this.renderError(`FabricationNoteDimension could not find selector "${t}"`),ke(n,{x:0,y:0}))}let i=typeof t.x=="string"?parseFloat(t.x):t.x,r=typeof t.y=="string"?parseFloat(t.y):t.y;return ke(n,{x:i,y:r})}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=this._computePcbGlobalTransformBeforeLayout(),r=this._resolvePoint(n.from,i),o=this._resolvePoint(n.to,i),s=this.getSubcircuit(),a=this.getGroup(),{maybeFlipLayer:c}=this._getPcbPrimitiveFlippedHelpers(),l=c(n.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.pcb_fabrication_note_dimension.insert({pcb_component_id:u,subcircuit_id:s?.subcircuit_id??void 0,pcb_group_id:a?.pcb_group_id??void 0,layer:l,from:r,to:o,text:n.text,offset:n.offset,font:n.font??"tscircuit2024",font_size:n.fontSize??1,color:n.color,arrow_size:n.arrowSize??1});this.fabrication_note_dimension_id=h.pcb_fabrication_note_dimension_id}getPcbSize(){let t=this._computePcbGlobalTransformBeforeLayout(),n=this._resolvePoint(this._parsedProps.from,t),i=this._resolvePoint(this._parsedProps.to,t);return{width:Math.abs(i.x-n.x),height:Math.abs(i.y-n.y)}}},GV=class extends be{constructor(){super(...arguments);I(this,"pcb_note_line_id",null);I(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbNoteLine",zodProps:MF}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=this.getSubcircuit(),r=this.getGroup(),o=this._computePcbGlobalTransformBeforeLayout(),s=ke(o,{x:n.x1,y:n.y1}),a=ke(o,{x:n.x2,y:n.y2}),c=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id??void 0,l=t.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:s.x,y1:s.y,x2:a.x,y2:a.y,stroke_width:n.strokeWidth??.1,color:n.color,is_dashed:n.isDashed});this.pcb_note_line_id=l.pcb_note_line_id}getPcbSize(){let{_parsedProps:t}=this;return{width:Math.abs(t.x2-t.x1),height:Math.abs(t.y2-t.y1)}}},UV=class extends be{constructor(){super(...arguments);I(this,"pcb_note_rect_id",null);I(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbNoteRect",zodProps:TF}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=this._computePcbGlobalTransformBeforeLayout(),r=ke(i,{x:0,y:0}),o=this.getSubcircuit(),s=this.getGroup(),a=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id??void 0,c=t.pcb_note_rect.insert({pcb_component_id:a,subcircuit_id:o?.subcircuit_id??void 0,pcb_group_id:s?.pcb_group_id??void 0,center:r,width:n.width,height:n.height,stroke_width:n.strokeWidth??.1,is_filled:n.isFilled??!1,has_stroke:n.hasStroke??!0,is_stroke_dashed:n.isStrokeDashed??!1,color:n.color});this.pcb_note_rect_id=c.pcb_note_rect_id}getPcbSize(){let{_parsedProps:t}=this,n=typeof t.width=="string"?parseFloat(t.width):t.width,i=typeof t.height=="string"?parseFloat(t.height):t.height;return{width:n,height:i}}},qV=class extends be{constructor(){super(...arguments);I(this,"pcb_note_text_id",null);I(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbNoteText",zodProps:PF}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=this._computePcbGlobalTransformBeforeLayout(),r=ke(i,{x:0,y:0}),o=this.getSubcircuit(),s=this.getGroup(),a=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id??void 0,c=t.pcb_note_text.insert({pcb_component_id:a,subcircuit_id:o?.subcircuit_id??void 0,pcb_group_id:s?.pcb_group_id??void 0,font:n.font??"tscircuit2024",font_size:n.fontSize??1,text:n.text,anchor_position:r,anchor_alignment:n.anchorAlignment??"center",color:n.color});this.pcb_note_text_id=c.pcb_note_text_id}getPcbSize(){let{_parsedProps:t}=this,n=typeof t.fontSize=="string"?parseFloat(t.fontSize):t.fontSize??1,i=n*.6;return{width:t.text.length*i,height:n}}},WV=class extends be{constructor(){super(...arguments);I(this,"pcb_note_path_id",null);I(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbNotePath",zodProps:IF}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=this._computePcbGlobalTransformBeforeLayout(),r=this.getSubcircuit(),o=this.getGroup(),s=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id??void 0,a=n.route.map(l=>{let{x:u,y:h,...d}=l,_=typeof u=="string"?parseFloat(u):u,y=typeof h=="string"?parseFloat(h):h,g=ke(i,{x:_,y});return{...d,x:g.x,y:g.y}}),c=t.pcb_note_path.insert({pcb_component_id:s,subcircuit_id:r?.subcircuit_id??void 0,pcb_group_id:o?.pcb_group_id??void 0,route:a,stroke_width:n.strokeWidth??.1,color:n.color});this.pcb_note_path_id=c.pcb_note_path_id}getPcbSize(){let{_parsedProps:t}=this;if(t.route.length===0)return{width:0,height:0};let n=t.route.map(c=>typeof c.x=="string"?parseFloat(c.x):c.x),i=t.route.map(c=>typeof c.y=="string"?parseFloat(c.y):c.y),r=Math.min(...n),o=Math.max(...n),s=Math.min(...i),a=Math.max(...i);return{width:o-r,height:a-s}}},ZV=class extends be{constructor(){super(...arguments);I(this,"pcb_note_dimension_id",null);I(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbNoteDimension",zodProps:CF}}_resolvePoint(t,n){if(typeof t=="string"){let o=this.getSubcircuit().selectOne(`.${t}`);return o?o._getGlobalPcbPositionBeforeLayout():(this.renderError(`PcbNoteDimension could not find selector "${t}"`),ke(n,{x:0,y:0}))}let i=typeof t.x=="string"?parseFloat(t.x):t.x,r=typeof t.y=="string"?parseFloat(t.y):t.y;return ke(n,{x:i,y:r})}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=this._computePcbGlobalTransformBeforeLayout(),r=this._resolvePoint(n.from,i),o=this._resolvePoint(n.to,i),s=this.getSubcircuit(),a=this.getGroup(),c=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id??void 0,l=t.pcb_note_dimension.insert({pcb_component_id:c,subcircuit_id:s?.subcircuit_id??void 0,pcb_group_id:a?.pcb_group_id??void 0,from:r,to:o,text:n.text,font:n.font??"tscircuit2024",font_size:n.fontSize??1,color:n.color,arrow_size:n.arrowSize??1});this.pcb_note_dimension_id=l.pcb_note_dimension_id}getPcbSize(){let t=this._computePcbGlobalTransformBeforeLayout(),n=this._resolvePoint(this._parsedProps.from,t),i=this._resolvePoint(this._parsedProps.to,t);return{width:Math.abs(i.x-n.x),height:Math.abs(i.y-n.y)}}},KV=class extends Mh{constructor(e){super({...e,subcircuit:!0})}},JV=class extends Mh{constructor(e){super({...e,subcircuit:!0})}doInitialPcbPrimitiveRender(){if(super.doInitialPcbPrimitiveRender(),this.root?.pcbDisabled)return;let{db:e}=this.root,t=this._parsedProps;if(!this.pcb_group_id)return;let n=e.pcb_group.get(this.pcb_group_id),i=t.paddingLeft??t.padding??0,r=t.paddingRight??t.padding??0,o=t.paddingTop??t.padding??0,s=t.paddingBottom??t.padding??0;e.pcb_group.update(this.pcb_group_id,{width:n.width+i+r,height:n.height+o+s,center:{x:n.center.x+(r-i)/2,y:n.center.y+(o-s)/2}})}},QV=class extends be{constructor(){super(...arguments);I(this,"pcb_breakout_point_id",null);I(this,"matchedPort",null);I(this,"matchedNet",null);I(this,"isPcbPrimitive",!0)}get config(){return{componentName:"BreakoutPoint",zodProps:nF}}_matchConnection(){let{connection:t}=this._parsedProps,n=this.getSubcircuit();n&&(this.matchedPort=n.selectOne(t,{type:"port"}),this.matchedPort||(this.matchedNet=n.selectOne(t,{type:"net"})),!this.matchedPort&&!this.matchedNet&&this.renderError(`Could not find connection target "${t}"`))}_getSourceTraceIdForPort(t){let{db:n}=this.root;return n.source_trace.list().find(r=>r.connected_source_port_ids.includes(t.source_port_id))?.source_trace_id}_getSourceNetIdForPort(t){let{db:n}=this.root;return n.source_trace.list().find(r=>r.connected_source_port_ids.includes(t.source_port_id))?.connected_source_net_ids[0]}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root;this._matchConnection();let{pcbX:n=0,pcbY:i=0}=this._parsedProps,r=this.parent?.getGroup(),o=this.getSubcircuit();if(!r||!r.pcb_group_id)return;let s=t.pcb_breakout_point.insert({pcb_group_id:r.pcb_group_id,subcircuit_id:o?.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:n,y:i});this.pcb_breakout_point_id=s.pcb_breakout_point_id}_getPcbCircuitJsonBounds(){let{pcbX:t=0,pcbY:n=0}=this._parsedProps;return{center:{x:t,y:n},bounds:{left:t,top:n,right:t,bottom:n},width:0,height:0}}_setPositionFromLayout(t){let{db:n}=this.root;this.pcb_breakout_point_id&&n.pcb_breakout_point.update(this.pcb_breakout_point_id,{x:t.x,y:t.y})}getPcbSize(){return{width:0,height:0}}},tH=class extends be{constructor(){super(...arguments);I(this,"source_net_label_id")}get config(){return{componentName:"NetLabel",zodProps:$z}}_getAnchorSide(){let{_parsedProps:t}=this;if(t.anchorSide)return t.anchorSide;if(!this._resolveConnectsTo())return"right";let i=this._getGlobalSchematicPositionBeforeLayout(),r=this._getConnectedPorts();if(r.length===0)return"right";let o=r[0]._getGlobalSchematicPositionBeforeLayout(),s=o.x-i.x,a=o.y-i.y;if(Math.abs(s)>Math.abs(a)){if(s>0)return"right";if(s<0)return"left"}else{if(a>0)return"top";if(a<0)return"bottom"}return"right"}_getConnectedPorts(){let t=this._resolveConnectsTo();if(!t)return[];let n=[];for(let i of t){let r=this.getSubcircuit().selectOne(i);r&&n.push(r)}return n}computeSchematicPropsTransform(){let{_parsedProps:t}=this;if(t.schX===void 0&&t.schY===void 0){let n=this._getConnectedPorts();if(n.length>0){let i=n[0]._getGlobalSchematicPositionBeforeLayout(),r=ke(this.parent?.computeSchematicGlobalTransform?.()??Ri(),{x:0,y:0});return vn(i.x-r.x,i.y-r.y)}}return super.computeSchematicPropsTransform()}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalSchematicPositionBeforeLayout(),r=this.getSubcircuit().selectOne(`net.${this._getNetName()}`),o=n.anchorSide??"right",s=bc({anchor_position:i,anchor_side:o,text:n.net}),a=t.schematic_net_label.insert({text:n.net,source_net_id:r.source_net_id,anchor_position:i,center:s,anchor_side:this._getAnchorSide()});this.source_net_label_id=a.source_net_id}_resolveConnectsTo(){let{_parsedProps:t}=this,n=t.connectsTo??t.connection;if(Array.isArray(n))return n;if(typeof n=="string")return[n]}_getNetName(){let{_parsedProps:t}=this;return t.net}doInitialCreateNetsFromProps(){let{_parsedProps:t}=this;t.net&&KI(this,[`net.${t.net}`])}doInitialCreateTracesFromNetLabels(){if(this.root?.schematicDisabled)return;let t=this._resolveConnectsTo();if(t)for(let n of t)this.add(new ko({from:n,to:`net.${this._getNetName()}`}))}doInitialSchematicTraceRender(){if(!this.root?._featureMspSchematicTraceRouting||this.root?.schematicDisabled)return;let{db:t}=this.root,n=this._resolveConnectsTo();if(!n||n.length===0)return;let i=this._getGlobalSchematicPositionBeforeLayout(),r=this._getAnchorSide(),s={left:"x-",right:"x+",top:"y+",bottom:"y-"}[r],a=this.getSubcircuit().selectOne(`net.${this._getNetName()}`);for(let c of n){let l=this.getSubcircuit().selectOne(c,{type:"port"});if(!l||!l.schematic_port_id)continue;let u=!1;if(a?.source_net_id){let w=t.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(w&&(u=t.schematic_trace.list().some(S=>S.source_trace_id===w.source_trace_id)),u)continue}let h=l._getGlobalSchematicPositionAfterLayout(),d=XI(l.facingDirection??"right")??"x+",_=Ja({x:h.x,y:h.y,facingDirection:d},{x:i.x,y:i.y,facingDirection:s});if(!Array.isArray(_)||_.length<2)continue;let y=[];for(let w=0;w<_.length-1;w++)y.push({from:{x:_[w].x,y:_[w].y},to:{x:_[w+1].x,y:_[w+1].y}});let g,x;if(a?.source_net_id&&l.source_port_id){let w=t.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));g=w?.source_trace_id,x=w?.subcircuit_connectivity_map_key||t.source_net.get(a.source_net_id)?.subcircuit_connectivity_map_key}t.schematic_trace.insert({source_trace_id:g,edges:y,junctions:[],subcircuit_connectivity_map_key:x}),t.schematic_port.update(l.schematic_port_id,{is_connected:!0})}}},eH=class extends be{constructor(){super(...arguments);I(this,"pcb_silkscreen_circle_id",null);I(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenCircle",zodProps:wF}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),r=i(n.layer??"top");if(r!=="top"&&r!=="bottom")throw new Error(`Invalid layer "${r}" for SilkscreenCircle. Must be "top" or "bottom".`);let o=this._computePcbGlobalTransformBeforeLayout(),s=this.getSubcircuit(),a=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id,c=t.pcb_silkscreen_circle.insert({pcb_component_id:a,layer:r,center:{x:n.pcbX??0,y:n.pcbY??0},radius:n.radius,subcircuit_id:s?.subcircuit_id??void 0,pcb_group_id:this.getGroup()?.pcb_group_id??void 0,stroke_width:n.strokeWidth??.1});this.pcb_silkscreen_circle_id=c.pcb_silkscreen_circle_id}getPcbSize(){let{_parsedProps:t}=this,n=t.radius*2;return{width:n,height:n}}},nH=class extends be{constructor(){super(...arguments);I(this,"pcb_silkscreen_rect_id",null);I(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenRect",zodProps:vF}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),r=i(n.layer??"top");if(r!=="top"&&r!=="bottom")throw new Error(`Invalid layer "${r}" for SilkscreenRect. Must be "top" or "bottom".`);let o=this.getSubcircuit(),s=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id,a=t.pcb_silkscreen_rect.insert({pcb_component_id:s,layer:r,center:{x:n.pcbX??0,y:n.pcbY??0},width:n.width,height:n.height,subcircuit_id:o?.subcircuit_id??void 0,pcb_group_id:this?.getGroup()?.pcb_group_id??void 0,stroke_width:n.strokeWidth??.1});this.pcb_silkscreen_rect_id=a.pcb_silkscreen_rect_id}getPcbSize(){let{_parsedProps:t}=this;return{width:t.width,height:t.height}}},iH=class extends be{constructor(){super(...arguments);I(this,"pcb_silkscreen_line_id",null);I(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenLine",zodProps:xF}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,{maybeFlipLayer:i}=this._getPcbPrimitiveFlippedHelpers(),r=i(n.layer??"top");if(r!=="top"&&r!=="bottom")throw new Error(`Invalid layer "${r}" for SilkscreenLine. Must be "top" or "bottom".`);let o=this.getSubcircuit(),s=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id,a=t.pcb_silkscreen_line.insert({pcb_component_id:s,layer:r,x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2,stroke_width:n.strokeWidth??.1,subcircuit_id:o?.subcircuit_id??void 0,pcb_group_id:o?.getGroup()?.pcb_group_id??void 0});this.pcb_silkscreen_line_id=a.pcb_silkscreen_line_id}getPcbSize(){let{_parsedProps:t}=this,n=Math.abs(t.x2-t.x1),i=Math.abs(t.y2-t.y1);return{width:n,height:i}}},rH=class extends be{constructor(t){super(t);I(this,"pcb_via_id",null);I(this,"matchedPort",null);I(this,"isPcbPrimitive",!0);I(this,"source_manually_placed_via_id",null);let n=this._getLayers();this._parsedProps.layers=n,this.initPorts()}get config(){return{componentName:"Via",zodProps:tF}}getAvailablePcbLayers(){return["top","inner1","inner2","bottom"]}getPcbSize(){let{_parsedProps:t}=this;return{width:t.outerDiameter,height:t.outerDiameter}}_getPcbCircuitJsonBounds(){let{db:t}=this.root,n=t.pcb_via.get(this.pcb_via_id),i=this.getPcbSize();return{center:{x:n.x,y:n.y},bounds:{left:n.x-i.width/2,top:n.y-i.height/2,right:n.x+i.width/2,bottom:n.y+i.height/2},width:i.width,height:i.height}}_setPositionFromLayout(t){let{db:n}=this.root;n.pcb_via.update(this.pcb_via_id,{x:t.x,y:t.y})}_getLayers(){let{fromLayer:t="top",toLayer:n="bottom"}=this._parsedProps;return t===n?[t]:[t,n]}initPorts(){let t=this._parsedProps.layers;for(let i of t){let r=new $i({name:i,layer:i});r.registerMatch(this),this.add(r)}let n=new $i({name:"pin1"});n.registerMatch(this),this.add(n)}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalPcbPositionBeforeLayout(),r=this.getSubcircuit(),o=t.pcb_component.insert({center:i,width:n.outerDiameter,height:n.outerDiameter,layer:n.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=o.pcb_component_id}doInitialSourceRender(){let{db:t}=this.root,{_parsedProps:n}=this,i=this.getGroup(),r=this.getSubcircuit(),o=t.source_manually_placed_via.insert({source_group_id:i?.source_group_id,source_net_id:n.net??"",subcircuit_id:r?.subcircuit_id??void 0});this.source_component_id=o.source_manually_placed_via_id}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalPcbPositionBeforeLayout(),r=this.getSubcircuit(),o=t.pcb_via.insert({x:i.x,y:i.y,hole_diameter:n.holeDiameter,outer_diameter:n.outerDiameter,layers:["bottom","top"],from_layer:n.fromLayer||"bottom",to_layer:n.toLayer||"top",subcircuit_id:r?.subcircuit_id??void 0,pcb_group_id:this.getGroup()?.pcb_group_id??void 0});this.pcb_via_id=o.pcb_via_id}},oH=class extends be{constructor(){super(...arguments);I(this,"isPcbPrimitive",!0)}get config(){return{componentName:"CopperPour",zodProps:rF}}getPcbSize(){return{width:0,height:0}}doInitialPcbCopperPourRender(){this.root?.pcbDisabled||this._queueAsyncEffect("PcbCopperPourRender",async()=>{let{db:t}=this.root,{_parsedProps:n}=this,i=this.getSubcircuit().selectOne(n.connectsTo);if(!i||!i.source_net_id){this.renderError(`Net "${n.connectsTo}" not found for copper pour`);return}let r=t.pcb_board.list()[0];if(!r){this.renderError("No board found for copper pour");return}let o;r.outline&&r.outline.length>0?o=new z.Polygon(r.outline.map(_=>z.point(_.x,_.y))):o=new z.Polygon(new z.Box(r.center.x-r.width/2,r.center.y-r.height/2,r.center.x+r.width/2,r.center.y+r.height/2).toPoints());let s=si(t.toArray()),a=tM(t.toArray(),s).filter(_=>_.layers.includes(n.layer));for(let _ of t.pcb_trace.list())if(_.route)for(let y=0;y<_.route.length-1;y++){let g=_.route[y],x=_.route[y+1];if(g.route_type!=="wire"||x.route_type!=="wire"||g.layer!==n.layer)continue;let w=g.width;if(w===0)continue;let S=Math.hypot(g.x-x.x,g.y-x.y);if(S===0)continue;let C=(g.x+x.x)/2,M=(g.y+x.y)/2,k=Math.atan2(x.y-g.y,x.x-g.x)*180/Math.PI,N=gV({center:{x:C,y:M},width:S,height:w,rotation:k});for(let E of N)a.push({type:"rect",layers:[g.layer],center:E.center,width:E.width,height:E.height,connectedTo:_.source_trace_id?[_.source_trace_id]:[],obstacle_type:"trace"})}let c=[],l=[],u=n.traceMargin??.2,h=n.padMargin??.2;for(let _ of a){if(_.connectedTo.some(w=>s.areIdsConnected(w,i.source_net_id)))continue;if(_.type==="oval"&&_.width===_.height){let w=_.width/2+h;l.push({center:_.center,radius:w});continue}if(_.type==="rect"&&_.width===_.height&&_.connectedTo.length===0){let w=_.width/2;l.push({center:_.center,radius:w});continue}let g=u,x=new z.Box(_.center.x-_.width/2-g,_.center.y-_.height/2-g,_.center.x+_.width/2+g,_.center.y+_.height/2+g);c.push(new z.Polygon(x.toPoints()))}let d=o;if(c.length>0){let _=c.reduce((y,g)=>z.BooleanOperations.unify(y,g));_&&!_.isEmpty()&&(d=z.BooleanOperations.subtract(o,_))}Array.isArray(d)||(d=[d]);for(let _ of d){let y=_.splitToIslands();for(let g of y){if(g.isEmpty())continue;let x=[...g.faces],w=x.find(T=>T.orientation()===z.ORIENTATION.CCW),S=x.filter(T=>T.orientation()===z.ORIENTATION.CW);if(!w)continue;if(!t.pcb_copper_pour){this.renderError("db.pcb_copper_pour not found. The database schema may be outdated.");return}let C=T=>T.edges.map(N=>{let E={x:N.start.x,y:N.start.y};if(N.isArc){let A=Math.tan(N.shape.sweep/4);Math.abs(A)>1e-9&&(E.bulge=A)}return E});w.reverse();let M=C(w),k=S.map(T=>(T.reverse(),{vertices:C(T)}));for(let T of l){let N=z.point(T.center.x,T.center.y);g.contains(N)&&k.push({vertices:[{x:T.center.x,y:T.center.y-T.radius,bulge:1},{x:T.center.x,y:T.center.y+T.radius,bulge:1}]})}t.pcb_copper_pour.insert({shape:"brep",layer:n.layer,brep_shape:{outer_ring:{vertices:M},inner_rings:k},source_net_id:i.source_net_id,subcircuit_id:this.getSubcircuit()?.subcircuit_id??void 0})}}})}},sH=class extends On{get config(){return{componentName:"Battery",schematicSymbolName:this.props.symbolName??"battery",zodProps:Fz,sourceFtype:"simple_power_source"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:this.name,ftype:"simple_power_source",capacity:t.capacity,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!1});this.source_component_id=n.source_component_id}},aH=class extends On{_getPcbRotationBeforeLayout(){let e=this.props.pcbOrientation==="vertical"?-90:0;return(super._getPcbRotationBeforeLayout()??0)+e}get config(){return{componentName:"PinHeader",zodProps:Dz,shouldRenderAsSchematicBox:!0}}_getImpliedFootprintString(){let e=this._parsedProps.pinCount??(Array.isArray(this._parsedProps.pinLabels)?this._parsedProps.pinLabels.length:this._parsedProps.pinLabels?Object.keys(this._parsedProps.pinLabels).length:0),t=this._parsedProps.holeDiameter,n=this._parsedProps.platedDiameter,i=this._parsedProps.pitch,r=this._parsedProps.showSilkscreenPinLabels;if(e>0){let o;if(i)!t&&!n?o=`pinrow${e}_p${i}`:o=`pinrow${e}_p${i}_id${t}_od${n}`;else if(!t&&!n)o=`pinrow${e}`;else return null;return r!==!0&&(o+="_nopinlabels"),o}return null}initPorts(){let e=this._parsedProps.pinCount??(Array.isArray(this._parsedProps.pinLabels)?this._parsedProps.pinLabels.length:this._parsedProps.pinLabels?Object.keys(this._parsedProps.pinLabels).length:1);for(let t=1;t<=e;t++){let n=Array.isArray(this._parsedProps.pinLabels)?this._parsedProps.pinLabels[t-1]:this._parsedProps.pinLabels?.[`pin${t}`];if(n){let i=Array.isArray(n)?n[0]:n,r=Array.isArray(n)?n.slice(1):[];this.add(new $i({pinNumber:t,name:i,aliases:[`pin${t}`,...r]}))}else this.add(new $i({pinNumber:t,name:`pin${t}`}))}}_getSchematicPortArrangement(){let e=this._parsedProps.pinCount??1,t=this._parsedProps.schFacingDirection??this._parsedProps.facingDirection??"right",n=this._parsedProps.schPinArrangement;return t==="left"?{leftSide:{direction:n?.leftSide?.direction??"top-to-bottom",pins:n?.leftSide?.pins??Array.from({length:e},(i,r)=>`pin${r+1}`)}}:{rightSide:{direction:n?.rightSide?.direction??"top-to-bottom",pins:n?.rightSide?.pins??Array.from({length:e},(i,r)=>`pin${r+1}`)}}}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_pin_header",name:this.name,supplier_part_numbers:t.supplierPartNumbers,pin_count:t.pinCount,gender:t.gender,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}};function x5t(e){switch(e){case"two_ground_pins":return"crystal_4pin";case"ground_pin":return"resonator";case"no_ground":return"crystal";default:return"crystal"}}var cH=class extends On{get config(){return{componentName:"Resonator",schematicSymbolName:this.props.symbolName??x5t(this.props.pinVariant),zodProps:Mz,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,n=t.pinVariant||"no_ground",i=e.source_component.insert({ftype:"simple_resonator",name:this.name,frequency:t.frequency,load_capacitance:t.loadCapacitance,supplier_part_numbers:t.supplierPartNumbers,pin_variant:n,are_pins_interchangeable:n==="no_ground"||n==="ground_pin"});this.source_component_id=i.source_component_id}_getSchematicSymbolDisplayValue(){let e=`${ti(this._parsedProps.frequency)}Hz`;return this._parsedProps.loadCapacitance?`${e} / ${ti(this._parsedProps.loadCapacitance)}F`:e}},lH=class extends On{constructor(){super(...arguments);I(this,"_adjustSilkscreenTextAutomatically",!0)}get config(){return{componentName:"Inductor",schematicSymbolName:this.props.symbolName??"inductor",zodProps:Vz,sourceFtype:na.simple_inductor}}_getSchematicSymbolDisplayValue(){return`${ti(this._parsedProps.inductance)}H`}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){let{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({name:this.name,ftype:na.simple_inductor,inductance:n.inductance,supplier_part_numbers:n.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=i.source_component_id}};function v5t(e){switch(e){case"three_pin":return"potentiometer3";case"two_pin":return"potentiometer2";default:return"potentiometer2"}}var uH=class extends On{get config(){return{componentName:"Potentiometer",schematicSymbolName:this.props.symbolName??v5t(this.props.pinVariant),zodProps:Tz,shouldRenderAsSchematicBox:!1}}_getSchematicSymbolDisplayValue(){return`${ti(this._parsedProps.maxResistance)}\u03A9`}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,n=t.pinVariant||"two_pin",i=e.source_component.insert({ftype:"simple_potentiometer",name:this.name,max_resistance:t.maxResistance,pin_variant:n,are_pins_interchangeable:n==="two_pin"});this.source_component_id=i.source_component_id}},pH=class extends On{get config(){return{componentName:"PushButton",schematicSymbolName:this.props.symbolName??"push_button_normally_open_momentary",zodProps:Bz,sourceFtype:na.simple_push_button}}get defaultInternallyConnectedPinNames(){return[]}initPorts(){super.initPorts({pinCount:2,ignoreSymbolPorts:!0});let e=Qn[this._getSchematicSymbolNameOrThrow()],t=e.ports.find(l=>l.labels.includes("1")),n=e.ports.find(l=>l.labels.includes("2")),i=this.selectAll("port"),r=i.find(l=>l.props.pinNumber===1),o=i.find(l=>l.props.pinNumber===2),s=i.find(l=>l.props.pinNumber===3),a=i.find(l=>l.props.pinNumber===4),{internallyConnectedPins:c}=this._parsedProps;r.schematicSymbolPortDef=t,(!c||c.length===0)&&(o.schematicSymbolPortDef=n);for(let[l,u]of[[2,o],[3,s],[4,a]]){let h=c?.find(([_,y])=>_===`pin${l}`||y===`pin${l}`);if(!h){u.schematicSymbolPortDef=n;break}(h?.[0]===`pin${l}`?h[1]:h?.[0])!=="pin1"&&(u.schematicSymbolPortDef=n)}}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:this.name,ftype:na.simple_push_button,supplier_part_numbers:t.supplierPartNumbers,are_pins_interchangeable:!0});this.source_component_id=n.source_component_id}},hH=class extends On{get config(){return{schematicSymbolName:this.props.symbolName??(this.props.pinVariant==="four_pin"?"crystal_4pin":"crystal"),componentName:"Crystal",zodProps:Iz,sourceFtype:"simple_crystal"}}initPorts(){let e=this.props.pinVariant==="four_pin"?{pin1:["left1","1"],pin2:["top1","2","gnd1"],pin3:["right1","3"],pin4:["bottom1","4","gnd2"]}:{pin1:["pos","left"],pin2:["neg","right"]};super.initPorts({additionalAliases:e})}_getSchematicSymbolDisplayValue(){let e=`${ti(this._parsedProps.frequency)}Hz`;return this._parsedProps.loadCapacitance?`${e} / ${ti(this._parsedProps.loadCapacitance)}F`:e}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:this.name,ftype:"simple_crystal",frequency:t.frequency,load_capacitance:t.loadCapacitance,pin_variant:t.pinVariant||"two_pin",are_pins_interchangeable:(t.pinVariant||"two_pin")==="two_pin"});this.source_component_id=n.source_component_id}},dH=class extends On{constructor(){super(...arguments);I(this,"emitter",this.portMap.pin1);I(this,"collector",this.portMap.pin2);I(this,"base",this.portMap.pin3)}get config(){let t=this.props.type==="npn"?"npn_bipolar_transistor":"pnp_bipolar_transistor";return{componentName:"Transistor",schematicSymbolName:this.props.symbolName??t,zodProps:Yz,sourceFtype:"simple_transistor",shouldRenderAsSchematicBox:!1}}initPorts(){let t={pin1:["collector","c"],pin2:["emitter","e"],pin3:["base","b"]};super.initPorts({pinCount:3,additionalAliases:t})}doInitialCreateNetsFromProps(){this._createNetsFromProps([...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this._createTracesFromConnectionsProp()}doInitialSourceRender(){let{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:"simple_transistor",name:this.name,transistor_type:n.type});this.source_component_id=i.source_component_id}},fH=class extends On{get config(){let e=this.props.mosfetMode==="depletion"?"d":"e",n=`${this.props.channelType}_channel_${e}_mosfet_transistor`;return{componentName:"Mosfet",schematicSymbolName:this.props.symbolName??n,zodProps:Xz,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_mosfet",name:this.name,mosfet_mode:t.mosfetMode,channel_type:t.channelType});this.source_component_id=n.source_component_id}},w5t=e=>e?e.closesAt!==void 0||e.opensAt!==void 0||e.startsClosed!==void 0||e.switchingFrequency!==void 0:!1,S5t=e=>!e||typeof e!="object"?!1:Object.prototype.hasOwnProperty.call(e,"spice"),P5t=e=>{if(!e||typeof e!="object")return null;let t=S5t(e)?e.spice??null:e;return w5t(t)?{...t}:null},mH=class extends On{_getSwitchType(){let e=this._parsedProps;return e?e.dpdt?"dpdt":e.spst?"spst":e.spdt?"spdt":e.dpst?"dpst":e.type??"spst":"spst"}get config(){let e=this._getSwitchType(),t=this._parsedProps?.isNormallyClosed??!1,n={spst:t?"spst_normally_closed_switch":"spst_switch",spdt:t?"spdt_normally_closed_switch":"spdt_switch",dpst:t?"dpst_normally_closed_switch":"dpst_switch",dpdt:t?"dpdt_normally_closed_switch":"dpdt_switch"};return{componentName:"Switch",schematicSymbolName:this.props.symbolName??n[e],zodProps:Wz,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){let{db:e}=this.root,t=this._parsedProps??{},n=e.source_component.insert({ftype:"simple_switch",name:this.name,switch_type:t.type,is_normally_closed:t.isNormallyClosed??!1,are_pins_interchangeable:this._getSwitchType()==="spst"});this.source_component_id=n.source_component_id}doInitialSimulationRender(){let e=this.props,t=P5t(e.simulation);if(!t)return;let{db:n}=this.root,i={type:"simulation_switch"};t.closesAt!==void 0&&(i.closes_at=t.closesAt),t.opensAt!==void 0&&(i.opens_at=t.opensAt),t.startsClosed!==void 0&&(i.starts_closed=t.startsClosed),t.switchingFrequency!==void 0&&(i.switching_frequency=t.switchingFrequency),n.simulation_switch.insert(i)}},BI={HOLE_DIAMETER:.5,SMT_CIRCLE_DIAMETER:1.2,SMT_RECT_SIZE:2},_H=class extends On{get config(){return{componentName:"TestPoint",schematicSymbolName:this.props.symbolName??"testpoint",zodProps:eF,sourceFtype:na.simple_test_point}}_getPropsWithDefaults(){let{padShape:e,holeDiameter:t,footprintVariant:n,padDiameter:i,width:r,height:o}=this._parsedProps;return!n&&t&&(n="through_hole"),n??(n="through_hole"),e??(e="circle"),n==="pad"?e==="circle"?i??(i=BI.SMT_CIRCLE_DIAMETER):e==="rect"&&(r??(r=BI.SMT_RECT_SIZE),o??(o=r)):n==="through_hole"&&(t??(t=BI.HOLE_DIAMETER)),{padShape:e,holeDiameter:t,footprintVariant:n,padDiameter:i,width:r,height:o}}_getImpliedFootprintString(){let{padShape:e,holeDiameter:t,footprintVariant:n,padDiameter:i,width:r,height:o}=this._getPropsWithDefaults();if(n==="through_hole")return`platedhole_d${t}`;if(n==="pad"){if(e==="circle")return`smtpad_circle_d${i}`;if(e==="rect")return`smtpad_rect_w${r}_h${o}`}throw new Error(`Footprint variant "${n}" with pad shape "${e}" not implemented`)}doInitialSourceRender(){let{db:e}=this.root,{_parsedProps:t}=this,{padShape:n,holeDiameter:i,footprintVariant:r,padDiameter:o,width:s,height:a}=this._getPropsWithDefaults(),c=e.source_component.insert({ftype:na.simple_test_point,name:this.name,supplier_part_numbers:t.supplierPartNumbers,footprint_variant:r,pad_shape:n,pad_diameter:o,hole_diameter:i,width:s,height:a,are_pins_interchangeable:!0});this.source_component_id=c.source_component_id}},yH=class extends be{constructor(){super(...arguments);I(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicText",zodProps:fF}}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalSchematicPositionBeforeLayout();t.schematic_text.insert({anchor:n.anchor??"center",text:n.text,font_size:n.fontSize,color:n.color||"#000000",position:{x:i.x,y:i.y},rotation:n.schRotation??0})}},gH=class extends be{constructor(){super(...arguments);I(this,"isSchematicPrimitive",!0);I(this,"schematic_line_id")}get config(){return{componentName:"SchematicLine",zodProps:dF}}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalSchematicPositionBeforeLayout(),r=this.getPrimitiveContainer()?.parent?.schematic_component_id,o=t.schematic_line.insert({schematic_component_id:r,x1:n.x1+i.x,y1:n.y1+i.y,x2:n.x2+i.x,y2:n.y2+i.y,stroke_width:n.strokeWidth??dx,color:n.color??hx,is_dashed:!1,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.schematic_line_id=o.schematic_line_id}},bH=class extends be{constructor(){super(...arguments);I(this,"isSchematicPrimitive",!0);I(this,"schematic_rect_id")}get config(){return{componentName:"SchematicRect",zodProps:hF}}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalSchematicPositionBeforeLayout(),r=this.getPrimitiveContainer()?.parent?.schematic_component_id,o=t.schematic_rect.insert({center:{x:i.x,y:i.y},width:n.width,height:n.height,stroke_width:n.strokeWidth??dx,color:n.color??hx,is_filled:n.isFilled,schematic_component_id:r,is_dashed:n.isDashed,rotation:n.rotation??0,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.schematic_rect_id=o.schematic_rect_id}},xH=class extends be{constructor(){super(...arguments);I(this,"isSchematicPrimitive",!0);I(this,"schematic_arc_id")}get config(){return{componentName:"SchematicArc",zodProps:lF}}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalSchematicPositionBeforeLayout(),r=this.getPrimitiveContainer()?.parent?.schematic_component_id,o=t.schematic_arc.insert({schematic_component_id:r,center:{x:n.center.x+i.x,y:n.center.y+i.y},radius:n.radius,start_angle_degrees:n.startAngleDegrees,end_angle_degrees:n.endAngleDegrees,direction:n.direction,stroke_width:n.strokeWidth??dx,color:n.color??hx,is_dashed:n.isDashed,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.schematic_arc_id=o.schematic_arc_id}},vH=class extends be{constructor(){super(...arguments);I(this,"isSchematicPrimitive",!0);I(this,"schematic_circle_id")}get config(){return{componentName:"SchematicCircle",zodProps:pF}}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalSchematicPositionBeforeLayout(),r=this.getPrimitiveContainer()?.parent?.schematic_component_id,o=t.schematic_circle.insert({schematic_component_id:r,center:{x:n.center.x+i.x,y:n.center.y+i.y},radius:n.radius,stroke_width:n.strokeWidth??dx,color:n.color??hx,is_filled:n.isFilled,fill_color:n.fillColor,is_dashed:n.isDashed,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.schematic_circle_id=o.schematic_circle_id}};function T5t({anchor:e,x:t,y:n,width:i,height:r,isInside:o}){switch(e){case"top_left":return{x:t,y:n+r,textAnchor:o?"top_left":"bottom_left"};case"top_center":return{x:t+i/2,y:n+r,textAnchor:o?"top_center":"bottom_center"};case"top_right":return{x:t+i,y:n+r,textAnchor:o?"top_right":"bottom_right"};case"center_left":return{x:t,y:n+r/2,textAnchor:o?"center_left":"center_right"};case"center":return{x:t+i/2,y:n+r/2,textAnchor:"center"};case"center_right":return{x:t+i,y:n+r/2,textAnchor:o?"center_right":"center_left"};case"bottom_left":return{x:t,y:n,textAnchor:o?"bottom_left":"top_left"};case"bottom_center":return{x:t+i/2,y:n,textAnchor:o?"bottom_center":"top_center"};case"bottom_right":return{x:t+i,y:n,textAnchor:o?"bottom_right":"top_right"};default:return{x:t+i/2,y:n+r,textAnchor:"center"}}}var wH=class extends be{constructor(){super(...arguments);I(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicBox",zodProps:uF,shouldRenderAsSchematicBox:!0}}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=.6,r=typeof n.padding=="number"?n.padding:0,o=typeof n.paddingTop=="number"?n.paddingTop:r,s=typeof n.paddingBottom=="number"?n.paddingBottom:r,a=typeof n.paddingLeft=="number"?n.paddingLeft:r,c=typeof n.paddingRight=="number"?n.paddingRight:r,l=n.overlay&&n.overlay.length>0,u=typeof n.width=="number"&&typeof n.height=="number",h,d,_,y,g,x;if(l){let S=n.overlay.map(it=>({selector:it,port:this.getSubcircuit().selectOne(it,{type:"port"})})).filter(({port:it})=>it!=null).map(({port:it})=>({position:it._getGlobalSchematicPositionAfterLayout()}));if(S.length===0)return;let C=S.map(it=>it.position.x),M=S.map(it=>it.position.y),k=Math.min(...C),T=Math.max(...C),N=Math.min(...M),E=Math.max(...M),A=T-k,O=E-N,$=A===0?i:0,B=O===0?i:0,H=a+$/2,Y=c+$/2,U=o+B/2,et=s+B/2,Q=k-H,V=T+Y,ot=N-et,K=E+U;h=V-Q,d=K-ot,_=Q+(n.schX??0),y=ot+(n.schY??0),g=_+h/2,x=y+d/2}else if(u){h=n.width,d=n.height;let w=this._getGlobalSchematicPositionBeforeLayout();g=w.x,x=w.y,_=g-h/2,y=x-d/2}else return;if(t.schematic_box.insert({height:d,width:h,x:_,y,is_dashed:n.strokeStyle==="dashed"}),n.title){let w=n.titleInside,S=.1,C=n.titleAlignment,M=T5t({anchor:C,x:_,y,width:h,height:d,isInside:w}),k,T,N=M.textAnchor;w?(k=C.includes("top")?-S:C.includes("bottom")?S:0,T=C.includes("left")?S:C.includes("right")?-S:0):(k=C.includes("top")?S:C.includes("bottom")?-S:0,T=C.includes("center_left")?-S:C.includes("center_right")?S:0);let E=M.x+T,A=M.y+k;t.schematic_text.insert({anchor:N,text:n.title,font_size:n.titleFontSize??.18,color:n.titleColor??"#000000",position:{x:E,y:A},rotation:0})}}},SH=class extends be{constructor(){super(...arguments);I(this,"isSchematicPrimitive",!0);I(this,"schematic_table_id",null)}get config(){return{componentName:"SchematicTable",zodProps:mF}}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled)return;let{db:t}=this.root,{_parsedProps:n}=this,i=this.children.filter(d=>d.componentName==="SchematicRow");if(i.length===0)return;let r=[],o=0;for(let d of i){let _=d.children.filter(y=>y.componentName==="SchematicCell");o=Math.max(o,_.length)}for(let d=0;d<i.length;d++)r[d]=[];for(let d=0;d<i.length;d++){let y=i[d].children.filter(x=>x.componentName==="SchematicCell"),g=0;for(let x=0;x<y.length;x++){for(;r[d][g];)g++;let w=y[x],S=w._parsedProps.colSpan??1,C=w._parsedProps.rowSpan??1;for(let M=0;M<C;M++)for(let k=0;k<S;k++)r[d+M]||(r[d+M]=[]),r[d+M][g+k]=w;g+=S}}o=Math.max(0,...r.map(d=>d.length));let s=i.map((d,_)=>d._parsedProps.height??1),a=Array.from({length:o},(d,_)=>{let y=0;for(let g=0;g<i.length;g++){let x=r[g]?.[_];if(x){let w=x._parsedProps.text??x._parsedProps.children,S=x._parsedProps.width??(w?.length??2)*.5;S>y&&(y=S)}}return y||10}),c=this._getGlobalSchematicPositionBeforeLayout(),l=t.schematic_table.insert({anchor_position:c,column_widths:a,row_heights:s,cell_padding:n.cellPadding,border_width:n.borderWidth,anchor:n.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 d=0;d<i.length;d++){let _=0;for(let y=0;y<o;y++){let g=r[d]?.[y];if(g&&!u.has(g)){u.add(g);let x=g._parsedProps,w=x.rowSpan??1,S=x.colSpan??1,C=0;for(let k=0;k<S;k++)C+=a[y+k];let M=0;for(let k=0;k<w;k++)M+=s[d+k];t.schematic_table_cell.insert({schematic_table_id:this.schematic_table_id,start_row_index:d,end_row_index:d+w-1,start_column_index:y,end_column_index:y+S-1,text:x.text??x.children,center:{x:c.x+_+C/2,y:c.y-h-M/2},width:C,height:M,horizontal_align:x.horizontalAlign,vertical_align:x.verticalAlign,font_size:x.fontSize??n.fontSize,subcircuit_id:this.getSubcircuit()?.subcircuit_id||""})}a[y]&&(_+=a[y])}h+=s[d]}}},PH=class extends be{constructor(){super(...arguments);I(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicRow",zodProps:_F}}},TH=class extends be{constructor(){super(...arguments);I(this,"isSchematicPrimitive",!0);I(this,"canHaveTextChildren",!0)}get config(){return{componentName:"SchematicCell",zodProps:yF}}},IH=class extends be{constructor(){super(...arguments);I(this,"isPrimitiveContainer",!0)}get config(){return{componentName:"Symbol",zodProps:zz}}},MH=class extends be{get config(){return{componentName:"AnalogSimulation",zodProps:jz}}doInitialSimulationRender(){let{db:e}=this.root,{duration:t,timePerStep:n}=this._parsedProps,i=t||10,r=n||.01;e.simulation_experiment.insert({name:"spice_transient_analysis",experiment_type:"spice_transient_analysis",end_time_ms:i,time_per_step:r})}},CH=class extends be{constructor(){super(...arguments);I(this,"simulation_voltage_probe_id",null)}get config(){return{componentName:"VoltageProbe",zodProps:cF}}doInitialSimulationRender(){let{db:t}=this.root,{connectsTo:n,name:i}=this._parsedProps,r=this.getSubcircuit();if(!r){this.renderError("VoltageProbe must be inside a subcircuit");return}let o=Array.isArray(n)?n:[n];if(o.length!==1){this.renderError("VoltageProbe must connect to exactly one port or net");return}let s=o[0],a=r.selectOne(s,{type:"port"}),c=a?null:r.selectOne(s,{type:"net"});if(c&&c.componentName!=="Net"){this.renderError(`VoltageProbe connection target "${s}" resolved to a non-net component "${c.componentName}".`);return}if(!a&&!c){this.renderError(`VoltageProbe could not find connection target "${s}"`);return}let{simulation_voltage_probe_id:l}=t.simulation_voltage_probe.insert({name:i??this.name,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});this.simulation_voltage_probe_id=l}},I5t={name:"@tscircuit/core",type:"module",version:"0.0.798",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"'},devDependencies:{"@biomejs/biome":"^1.8.3","@tscircuit/capacity-autorouter":"^0.0.132","@tscircuit/checks":"^0.0.85","@tscircuit/circuit-json-util":"^0.0.72","@tscircuit/common":"^0.0.11","@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.21","@tscircuit/miniflex":"^0.0.4","@tscircuit/props":"0.0.369","@tscircuit/schematic-autolayout":"^0.0.6","@tscircuit/schematic-match-adapt":"^0.0.16","@tscircuit/schematic-trace-solver":"^0.0.41","@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.283","circuit-json-to-bpc":"^0.0.13","circuit-json-to-connectivity-map":"^0.0.22","circuit-json-to-gltf":"^0.0.7","circuit-json-to-simple-3d":"^0.0.9","circuit-to-svg":"^0.0.245","circuit-json-to-spice":"^0.0.14",concurrently:"^9.1.2","connectivity-map":"^1.0.0",debug:"^4.3.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.6",react:"^19.1.0","react-dom":"^19.1.0","schematic-symbols":"^0.0.202",spicey:"^0.0.8","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.49","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"}},Ch=class{constructor({platform:e,projectUrl:t}={}){I(this,"firstChild",null);I(this,"children");I(this,"db");I(this,"root",null);I(this,"isRoot",!0);I(this,"schematicDisabled",!1);I(this,"pcbDisabled",!1);I(this,"pcbRoutingDisabled",!1);I(this,"_featureMspSchematicTraceRouting",!0);I(this,"name");I(this,"platform");I(this,"projectUrl");I(this,"_hasRenderedAtleastOnce",!1);I(this,"_eventListeners",{});this.children=[],this.db=Ne([]),this.root=this,this.platform=e,this.projectUrl=t,this.pcbDisabled=e?.pcbDisabled??!1}add(e){let t;(0,EH.isValidElement)(e)?t=aV(e):t=e,this.children.push(t)}_getBoard(){return this.children.find(e=>e.componentName==="Board")}_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(...))");if(this.children.length===1&&this.children[0].isGroup){this.firstChild=this.children[0];return}let e=new Mh({subcircuit:!0});e.parent=this,e.addAll(this.children),this.children=[e],this.firstChild=e}render(){this.firstChild||this._guessRootComponent();let{firstChild:e,db:t}=this;if(!e)throw new Error("RootCircuit has no root component");e.parent=this,e.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(t=>setTimeout(t,100)),this.render();this.emit("renderComplete")}_hasIncompleteAsyncEffects(){return this.children.some(e=>e._hasIncompleteAsyncEffects()?!0:e.children.some(t=>t._hasIncompleteAsyncEffects()))}getCircuitJson(){return this._hasRenderedAtleastOnce||this.render(),this.db.toArray()}toJson(){return this.getCircuitJson()}async getSvg(e){let t=await Promise.resolve().then(()=>(NX(),kX)).catch(n=>{throw new Error(`To use circuit.getSvg, you must install the "circuit-to-svg" package.
245
245
 
246
246
  "${n.message}"`)});if(e.view==="pcb")return t.convertCircuitJsonToPcbSvg(this.getCircuitJson());if(e.view==="schematic")return t.convertCircuitJsonToSchematicSvg(this.getCircuitJson());throw new Error(`Invalid view: ${e.view}`)}getCoreVersion(){let[e,t,n]=I5t.version.split(".").map(Number);return`${e}.${t}.${n+1}`}async preview(e){let t=typeof e=="object"?e:{previewName:e};throw new Error("project.preview is not yet implemented")}computeSchematicGlobalTransform(){return Ri()}_computePcbGlobalTransformBeforeLayout(){return Ri()}selectAll(e){return this._guessRootComponent(),this.firstChild?.selectAll(e)??[]}selectOne(e,t){return this._guessRootComponent(),this.firstChild?.selectOne(e,t)??null}emit(e,...t){if(this._eventListeners[e])for(let n of this._eventListeners[e])n(...t)}on(e,t){this._eventListeners[e]||(this._eventListeners[e]=[]),this._eventListeners[e].push(t)}removeListener(e,t){this._eventListeners[e]&&(this._eventListeners[e]=this._eventListeners[e].filter(n=>n!==t))}enableDebug(e){typeof e=="string"?UI.default.enable(e):(e===null||e===!1)&&UI.default.disable()}getClientOrigin(){return typeof window<"u"&&window.location?window.location.origin:typeof self<"u"&&self.location?self.location.origin:""}},M5t=Ch,C5t=Ch,E5t=e=>{let[t,n]=Ph.default.useState(!0),[i,r]=Ph.default.useState(null),[o,s]=Ph.default.useState(),[a,c]=Ph.default.useState();return Ph.default.useEffect(()=>{n(!0),r(null),e&&setTimeout(()=>{try{let l=new Ch;l.add(e),s(l),c(l.toJson())}catch(l){r(l)}n(!1)},1)},[e]),{isLoading:t,error:i,circuit:o,circuitJson:a}},Eh=(e,t)=>(n,i)=>{let r=[];Array.isArray(t)?r.push(...t.flat()):typeof t=="object"&&r.push(...Object.values(t).flat(),...Object.keys(t));let o=s=>{if(s?.name&&s.name!==n)throw new Error(`Component name mismatch. Hook name: ${n}, Component prop name: ${s.name}`);let a={...i,...s,name:n},c=[];for(let l of r)if(a[l]){let u=`.${n} > .${l}`,h=a[l];c.push({from:u,to:h}),delete a[l]}return(0,Jl.jsxs)(Jl.Fragment,{children:[(0,Jl.jsx)(e,{...a}),c.map((l,u)=>(0,Jl.jsx)("trace",{...l},u))]})};for(let s of r)o[s]=`.${n} > .${s}`;return o},k5t=Eh(e=>(0,kH.jsx)("capacitor",{...e}),Ez),N5t=e=>Eh(t=>(0,NH.jsx)("chip",{pinLabels:e,...t}),e),A5t=Eh(e=>(0,AH.jsx)("diode",{...e}),Gz),R5t=Eh(e=>(0,RH.jsx)("led",{...e}),qz),O5t=Eh(e=>(0,OH.jsx)("resistor",{...e}),Pz),L5t=new Proxy(e=>new Proxy({},{get:(t,n)=>`.${e} > .${n}`}),{get:(e,t)=>{let n=(...i)=>{let r=i[0];return new Proxy({},{get:(o,s)=>`.${t} > .${s}`})};return new Proxy(n,{get:(i,r)=>t==="net"?`net.${r}`:t==="subcircuit"?new Proxy({},{get:(o,s)=>new Proxy({},{get:(a,c)=>`subcircuit.${r} > .${s} > .${c}`})}):`.${t} > .${r}`,apply:(i,r,o)=>t==="net"?new Proxy({},{get:(s,a)=>`net.${a}`}):new Proxy({},{get:(s,a)=>{let c=`.${t} > .${a}`;return["U","J","CN"].some(u=>t.startsWith(u))?c:new Proxy(new String(c),{get:(u,h)=>typeof h=="symbol"||h==="toString"?()=>c:`.${t} > .${a} > .${h}`})}})})}});sV(nV);sV({Bug:fx});var eG=Yt(vo(),1);var zH=e=>{let t=e.match(/:[RC]_(\d{4})_/);if(t||(t=e.match(/:(SOIC-\d+|SOT-\d+|SOD-\d+|SSOP-\d+|TSSOP-\d+|QFP-\d+|QFN-\d+)/),t))return t[1]};var rM=e=>e.includes("cap")?e.replace(/cap/g,""):e;var FH=e=>{if(e){if(e.startsWith("kicad:")){let t=zH(e);return t?rM(t):e}return rM(e)}};var oM=new Map,rr=async(e,t)=>{let n=new URLSearchParams({...t,json:"true"}).toString();if(oM.has(n))return oM.get(n);let r=await(await fetch(`https://jlcsearch.tscircuit.com/${e}/list?${n}`)).json();return oM.set(n,r),r},or=e=>e?[...e].sort((t,n)=>Number(n.is_basic??!1)-Number(t.is_basic??!1)):[],DH={findPart:async({sourceComponent:e,footprinterString:t})=>{let n=FH(t);if(e.type==="source_component"&&e.ftype==="simple_resistor"){let{resistors:i}=await rr("resistors",{resistance:e.resistance,package:n});return{jlcpcb:or(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_capacitor"){let{capacitors:i}=await rr("capacitors",{capacitance:e.capacitance,package:n});return{jlcpcb:or(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_pin_header"){let i;t?.includes("_p")&&(i=Number(t.split("_p")[1]));let{headers:r}=await rr("headers",i?{pitch:i,num_pins:e.pin_count,gender:e.gender}:{num_pins:e.pin_count,gender:e.gender});return{jlcpcb:or(r).map(o=>`C${o.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_potentiometer"){let{potentiometers:i}=await rr("potentiometers",{resistance:e.max_resistance,package:n});return{jlcpcb:or(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_diode"){let{diodes:i}=await rr("diodes",{package:n});return{jlcpcb:or(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_chip"){let{chips:i}=await rr("chips",{package:n});return{jlcpcb:or(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_transistor"){let{transistors:i}=await rr("transistors",{package:n,transistor_type:e.transistor_type});return{jlcpcb:or(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_power_source"){let{power_sources:i}=await rr("power_sources",{voltage:e.voltage,package:n});return{jlcpcb:or(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_inductor"){let{inductors:i}=await rr("inductors",{inductance:e.inductance,package:n});return{jlcpcb:or(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_crystal"){let{crystals:i}=await rr("crystals",{frequency:e.frequency,load_capacitance:e.load_capacitance,package:n});return{jlcpcb:or(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_mosfet"){let{mosfets:i}=await rr("mosfets",{package:n,mosfet_mode:e.mosfet_mode,channel_type:e.channel_type});return{jlcpcb:or(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_resonator"){let{resonators:i}=await rr("resonators",{frequency:e.frequency,package:n});return{jlcpcb:or(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_switch"){let{switches:i}=await rr("switches",{switch_type:e.type,package:n});return{jlcpcb:or(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_led"){let{leds:i}=await rr("leds",{package:n});return{jlcpcb:or(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_fuse"){let{fuses:i}=await rr("fuses",{package:n});return{jlcpcb:or(i).map(r=>`C${r.lcsc}`).slice(0,3)}}return{}}};var YH=Yt($H(),1);Z();var UH=Yt(Mn(),1),qH=Yt(Mn(),1),Bi=p.tuple([p.coerce.number(),p.coerce.number()]),H5t=p.tuple([p.number(),p.number(),p.number()]),xx=p.union([Bi,H5t]),XH=p.object({at:xx,size:Bi,layer:p.string(),layers:p.array(p.string()),roundrect_rratio:p.number(),uuid:p.string()}).partial(),G5t=p.object({key:p.string(),val:p.string(),attributes:XH}),yx=p.object({oval:p.boolean().default(!1),width:p.number().optional(),height:p.number().optional(),offset:Bi.optional()}),VH=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:xx,drill:p.union([p.number(),p.array(p.any()),yx]).transform(e=>typeof e=="number"?{oval:!1,width:e,height:e}:"oval"in e?e:e.length===2?{oval:!1,width:Number.parseFloat(e[0]),height:Number.parseFloat(e[0]),offset:Bi.parse(e[1].slice(1))}:e.length===3||e.length===4?{oval:e[0]==="oval",width:Number.parseFloat(e[1]),height:Number.parseFloat(e[2]),offset:e[3]?Bi.parse(e[3].slice(1)):void 0}:e).pipe(yx),size:p.union([p.array(p.number()).length(2).transform(([e,t])=>({width:e,height:t})),p.object({width:p.number(),height:p.number()})]),layers:p.array(p.string()).optional(),roundrect_rratio:p.number().optional(),uuid:p.string().optional()}),HH=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:xx,size:Bi,drill:p.union([p.number(),p.array(p.any()),yx]).transform(e=>typeof e=="number"?{oval:!1,width:e,height:e}:"oval"in e?e:e.length===2?{oval:!1,width:Number.parseFloat(e[0]),height:Number.parseFloat(e[0]),offset:Bi.parse(e[1].slice(1))}:e.length===3||e.length===4?{oval:e[0]==="oval",width:Number.parseFloat(e[1]),height:Number.parseFloat(e[2]),offset:e[3]?Bi.parse(e[3].slice(1)):void 0}:e).pipe(yx).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()}),GH=p.object({font:p.object({size:Bi,thickness:p.number().optional()})}).partial(),U5t=p.object({fp_text_type:p.literal("user"),text:p.string(),at:xx,layer:p.string(),uuid:p.string().optional(),effects:GH.partial()}),q5t=p.object({start:Bi,mid:Bi,end:Bi,stroke:p.object({width:p.number(),type:p.string()}),layer:p.string(),uuid:p.string().optional()}),W5t=p.object({center:Bi,end:Bi,stroke:p.object({width:p.number(),type:p.string()}),fill:p.string().optional(),layer:p.string(),uuid:p.string().optional()}),Z5t=p.object({pts:p.array(Bi),stroke:p.object({width:p.number(),type:p.string()}).optional(),width:p.number().optional(),layer:p.string(),uuid:p.string().optional()}).transform(e=>({...e,width:void 0,stroke:e.stroke??{width:e.width}})),K5t=p.object({start:Bi,end:Bi,stroke:p.object({width:p.number(),type:p.string()}).optional(),width:p.number().optional(),layer:p.string(),uuid:p.string().optional()}).transform(e=>({...e,width:void 0,stroke:e.stroke??{width:e.width}})),BH=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(G5t),fp_lines:p.array(K5t),fp_texts:p.array(U5t),fp_arcs:p.array(q5t),fp_circles:p.array(W5t).optional(),fp_polys:p.array(Z5t).optional(),pads:p.array(HH),holes:p.array(VH).optional()}),gx=(e,t)=>{if(t==="effects"&&Array.isArray(e)){let n={};for(let i of e)if(i[0]==="font"){let r={};for(let o of i.slice(1))o.length===2?r[o[0].valueOf()]=Number.parseFloat(o[1].valueOf()):r[o[0].valueOf()]=o.slice(1).map(s=>Number.parseFloat(s.valueOf()));n.font=r}return GH.parse(n)}if(t==="pts")return e.map(n=>n.slice(1).map(i=>Number.parseFloat(i.valueOf())));if(t==="stroke"){let n={};for(let i of e){let r=i[0].valueOf();n[r]=gx(i.slice(1),r)}return n}return t==="at"||t==="size"||t==="start"||t==="mid"||t==="end"?(Array.isArray(e)?e:[e]).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)):t==="tags"?e.map(n=>n.valueOf()):t==="generator_version"||t==="version"?e[0].valueOf():e.length===2?e.valueOf():t==="uuid"?Array.isArray(e)?e[0].valueOf():e.valueOf():/^[\d\.]+$/.test(e)&&!Number.isNaN(Number.parseFloat(e))?Number.parseFloat(e):Array.isArray(e)&&e.length===1?e[0].valueOf():Array.isArray(e)?e.map(n=>n.valueOf()):e},De=(e,t)=>{for(let n of e)if(Array.isArray(n)&&n[0]===t)return gx(n.slice(1),t)},sM=(0,UH.default)("kicad-mod-converter"),J5t=e=>{let t=(0,YH.default)(e),n=t[1].valueOf(),i={},r=Object.entries(BH.shape).filter(([C,M])=>M._def.typeName==="ZodString"||C==="tags").map(([C])=>C);for(let C of t.slice(2)){if(!r.includes(C[0]))continue;let M=C[0].valueOf(),k=gx(C.slice(1),M);i[M]=k}let o=t.slice(2).filter(C=>C[0]==="property").map(C=>{let M=C[1].valueOf(),k=C[2].valueOf(),T=XH.parse(C.slice(3).reduce((N,E)=>{let A=E[0].valueOf();return N[A]=gx(E.slice(1),A),N},{}));return{key:M,val:k,attributes:T}}),s=t.slice(2).filter(C=>C[0]==="pad"),a=[];for(let C of s){let M=De(C,"at"),k=De(C,"size"),T=De(C,"drill"),N=De(C,"layers");if(Array.isArray(N)?N=N.map($=>$.valueOf()):typeof N=="string"?N=[N]:N||(N=[]),!N.includes("F.Cu")){sM(`Skipping pad without F.Cu layer: layers=${N.join(", ")}`);continue}let E=De(C,"roundrect_rratio"),A=De(C,"uuid"),O={name:C[1].valueOf(),pad_type:C[2].valueOf(),pad_shape:C[3].valueOf(),at:M,drill:T,size:k,layers:N,roundrect_rratio:E,uuid:A};sM(`attempting to parse pad: ${JSON.stringify(O,null," ")}`),a.push(HH.parse(O))}let c=t.slice(2).filter(C=>C[0]==="fp_text"),l=[];for(let C of c){let M=C[2].valueOf(),k=De(C,"at"),T=De(C,"layer"),N=De(C,"uuid"),E=De(C,"effects");l.push({fp_text_type:"user",text:M,at:k,layer:T,uuid:N,effects:E})}let u=[],h=t.slice(2).filter(C=>C[0]==="fp_line");for(let C of h){let M=De(C,"start"),k=De(C,"end"),T=De(C,"stroke"),N=De(C,"layer"),E=De(C,"uuid");u.push({start:M,end:k,stroke:T,layer:N,uuid:E})}let d=[],_=t.slice(2).filter(C=>C[0]==="fp_arc");for(let C of _){let M=De(C,"start"),k=De(C,"mid"),T=De(C,"end"),N=De(C,"stroke"),E=De(C,"layer"),A=De(C,"uuid");!M||!T||!k||!N||!E||d.push({start:M,mid:k,end:T,stroke:N,layer:E,uuid:A})}let y=[],g=t.slice(2).filter(C=>C[0]==="fp_circle");for(let C of g){let M=De(C,"center"),k=De(C,"end"),T=De(C,"stroke"),N=De(C,"fill"),E=De(C,"layer"),A=De(C,"uuid");!M||!k||!T||!E||y.push({center:M,end:k,stroke:T,fill:N,layer:E,uuid:A})}let x=[],w=t.slice(2).filter(C=>C[0]==="fp_poly");for(let C of w){let M=De(C,"pts"),k=De(C,"stroke"),T=De(C,"layer"),N=De(C,"uuid");x.push({pts:M,stroke:k,layer:T,uuid:N})}let S=[];for(let C of t.slice(2)){if(C[0]!=="pad"||C[2]?.valueOf?.()!=="thru_hole")continue;let M=C[1]?.valueOf?.(),k=C[2]?.valueOf?.(),T=C[3]?.valueOf?.(),N=De(C,"at"),E=De(C,"drill"),A=De(C,"size");Array.isArray(A)&&(A[0]==="size"&&(A=A.slice(1)),A={width:Number(A[0]),height:Number(A[1])});let O=De(C,"uuid"),$=De(C,"roundrect_rratio"),B=De(C,"layers");Array.isArray(B)?B=B.map(Y=>Y.valueOf()):typeof B=="string"?B=[B]:B||(B=[]);let H={name:M,pad_type:k,pad_shape:T,at:N,drill:E,size:A,layers:B,roundrect_rratio:$,uuid:O};sM(`attempting to parse holes: ${JSON.stringify(H,null,2)}`),S.push(VH.parse(H))}return BH.parse({footprint_name:n,...i,properties:o,fp_lines:u,fp_texts:l,fp_arcs:d,fp_circles:y,pads:a,holes:S,fp_polys:x})};function WH(e,t,n){let i={x:(e.x+t.x)/2,y:(e.y+t.y)/2},r={x:(t.x+n.x)/2,y:(t.y+n.y)/2},o=-(e.x-t.x)/(e.y-t.y),s=-(t.x-n.x)/(t.y-n.y),a=(i.y-r.y+s*r.x-o*i.x)/(s-o),c=i.y+o*(a-i.x);return{x:a,y:c}}function ZH(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function bx(e,t){return Math.atan2(t.y-e.y,t.x-e.x)}var KH=(e,t,n)=>{let i=WH(e,t,n),r=ZH(i,e),o=bx(i,e),a=bx(i,n)-o;return a<0&&(a+=2*Math.PI),r*a};function JH(e,t,n,i){let r=WH(e,t,n),o=ZH(r,e),s=bx(r,e),c=bx(r,n)-s;c<0&&(c+=2*Math.PI);let l=[];for(let u=0;u<=i;u++){let h=s+u/i*c,d=r.x+o*Math.cos(h),_=r.y+o*Math.sin(h);l.push({x:d,y:_})}return l}var hm=e=>Array.isArray(e)?{x:e[0],y:e[1]}:e,aM=(e,t,n=1e-4)=>Math.abs(e.x-t.x)<n&&Math.abs(e.y-t.y)<n,Q5t=e=>{let t=[],n=new Set;for(let i=0;i<e.length;i++){if(n.has(i))continue;let r=[e[i]];n.add(i);let o=e[i].end,s=!0;for(;s;){if(s=!1,r.length>1&&aM(o,r[0].start)){t.push(r);break}for(let a=0;a<e.length;a++)if(!n.has(a)){if(aM(o,e[a].start)){r.push(e[a]),n.add(a),o=e[a].end,s=!0;break}else if(aM(o,e[a].end)){e[a].type==="arc"?r.push({...e[a],reversed:!0}):r.push({...e[a],start:e[a].end,end:e[a].start}),n.add(a),o=e[a].start,s=!0;break}}if(!s){for(let a=r.length-1;a>=0;a--){let c=e.indexOf(r[a]);c!==-1&&n.delete(c)}break}}}return t},t4t=e=>{let t=[];for(let n of e)if(n.type==="line")t.push(n.start);else if(n.type==="arc"&&n.mid){let i=KH(n.start,n.mid,n.end),r=Math.max(3,Math.ceil(i)),o=JH(n.start,n.mid,n.end,r);n.reversed&&(o=o.reverse()),t.push(...o.slice(0,-1))}return t},e4t=e=>e*Math.PI/180,cM=(e,t,n)=>{let i=e4t(n),r=Math.cos(i),o=Math.sin(i);return{x:e*r-t*o,y:e*o+t*r}},n4t=e=>{let t=[...new Map(e.map(u=>[`${u.x},${u.y}`,u])).values()];if(t.length!==4)return null;let n=t.map(u=>u.x),i=t.map(u=>u.y),r=[...new Set(n)],o=[...new Set(i)];if(r.length!==2||o.length!==2)return null;let[s,a]=r.sort((u,h)=>u-h),[c,l]=o.sort((u,h)=>u-h);return s===void 0||a===void 0||c===void 0||l===void 0?null:{x:(s+a)/2,y:(c+l)/2,width:a-s,height:l-c}},jH=e=>e&&Array.isArray(e)&&e.length>=3&&typeof e[2]=="number"?e[2]:0,uo=e=>{let t=(e%360+360)%360;return t===90||t===270},kh=(0,qH.default)("kicad-mod-converter"),as=e=>{switch(e.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"}},i4t=async e=>{let{fp_lines:t,fp_texts:n,fp_arcs:i,fp_circles:r,pads:o,properties:s,holes:a,fp_polys:c}=e,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;for(let V of o)V.name&&u.add(V.name);if(a)for(let V of a)V.name&&u.add(V.name);let h=0,d=new Map;for(let V of u){let ot=`source_port_${h++}`;d.set(V,ot),l.push({type:"source_port",source_port_id:ot,source_component_id:"source_component_0",name:V,port_hints:[V]}),l.push({type:"schematic_port",schematic_port_id:`schematic_port_${h++}`,source_port_id:ot,schematic_component_id:"schematic_component_0",center:{x:0,y:0}})}let _=Number.POSITIVE_INFINITY,y=Number.NEGATIVE_INFINITY,g=Number.POSITIVE_INFINITY,x=Number.NEGATIVE_INFINITY;for(let V of o){let ot=V.at[0],K=-V.at[1],it=V.size[0],ht=V.size[1];_=Math.min(_,ot-it/2),y=Math.max(y,ot+it/2),g=Math.min(g,K-ht/2),x=Math.max(x,K+ht/2)}let w="pcb_component_0";l.push({type:"pcb_component",source_component_id:"source_component_0",pcb_component_id:w,layer:"top",center:{x:0,y:0},rotation:0,width:Number.isFinite(_)?y-_:0,height:Number.isFinite(g)?x-g:0});let S=0,C=new Map;for(let V of u){let ot=`pcb_port_${S++}`,K=d.get(V);C.set(V,ot);let it=0,ht=0,ft=["top","bottom"],xt=o.find(It=>It.name===V);if(xt)it=xt.at[0],ht=-xt.at[1],ft=xt.layers?xt.layers.map(It=>as(It)).filter(Boolean):["top","bottom"];else if(a){let It=a.find(ut=>ut.name===V);It&&(it=It.at[0],ht=-It.at[1],ft=It.layers?It.layers.map(ut=>as(ut)).filter(Boolean):["top","bottom"])}l.push({type:"pcb_port",pcb_port_id:ot,source_port_id:K,pcb_component_id:w,x:it,y:ht,layers:ft})}let M=0,k=0,T=0;for(let V of o)if(V.pad_type==="smd"){let ot=V.name?C.get(V.name):void 0;l.push({type:"pcb_smtpad",pcb_smtpad_id:`pcb_smtpad_${M++}`,shape:"rect",x:V.at[0],y:-V.at[1],width:V.size[0],height:V.size[1],layer:as(V.layers?.[0]??"F.Cu"),pcb_component_id:w,port_hints:[V.name],pcb_port_id:ot})}else if(V.pad_type==="thru_hole"){if(V.pad_shape==="rect"){let ot=jH(V.at),K=uo(ot)?V.size[1]:V.size[0],it=uo(ot)?V.size[0]:V.size[1],ht=V.drill?.offset?.[0]??0,ft=V.drill?.offset?.[1]??0,xt=cM(ht,ft,ot),It=V.name?C.get(V.name):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${k++}`,shape:"circular_hole_with_rect_pad",hole_shape:"circle",pad_shape:"rect",x:V.at[0],y:-V.at[1],hole_offset_x:xt.x,hole_offset_y:-xt.y,hole_diameter:V.drill?.width,rect_pad_width:K,rect_pad_height:it,layers:["top","bottom"],pcb_component_id:w,port_hints:[V.name],pcb_port_id:It})}else if(V.pad_shape==="circle"){let ot=V.name?C.get(V.name):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${k++}`,shape:"circle",x:V.at[0],y:-V.at[1],outer_diameter:V.size[0],hole_diameter:V.drill?.width,layers:["top","bottom"],pcb_component_id:w,port_hints:[V.name],pcb_port_id:ot})}else if(V.pad_shape==="oval"){let ot=V.name?C.get(V.name):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${k++}`,shape:"pill",x:V.at[0],y:-V.at[1],outer_width:V.size[0],outer_height:V.size[1],hole_width:V.drill?.width,hole_height:V.drill?.height,layers:["top","bottom"],pcb_component_id:w,port_hints:[V.name],pcb_port_id:ot})}}else V.pad_type==="np_thru_hole"&&l.push({type:"pcb_hole",pcb_hole_id:`pcb_hole_${T++}`,x:V.at[0],y:-V.at[1],hole_diameter:V.drill?.width,pcb_component_id:w});if(a)for(let V of a){let ot=V.layers?.some(J=>J.endsWith(".Cu")||J==="*.Cu"),K=jH(V.at),it=V.drill?.offset?.[0]??0,ht=V.drill?.offset?.[1]??0,ft=cM(it,ht,K),xt=V.at[0]+ft.x,It=-(V.at[1]+ft.y),ut=V.drill?.width??0,j=V.size?.width??ut,q=V.roundrect_rratio??0,rt=q>0?Math.min(uo(K)?V.size?.height??j:V.size?.width??j,uo(K)?V.size?.width??j:V.size?.height??j)/2*q:0;if(ot)if(V.pad_shape==="rect"){let J=V.name?C.get(V.name):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${k++}`,shape:"circular_hole_with_rect_pad",hole_shape:"circle",pad_shape:"rect",x:V.at[0],y:-V.at[1],hole_offset_x:ft.x,hole_offset_y:-ft.y,hole_diameter:ut,rect_pad_width:uo(K)?V.size?.height??j:V.size?.width??j,rect_pad_height:uo(K)?V.size?.width??j:V.size?.height??j,rect_border_radius:rt,port_hints:[V.name],layers:["top","bottom"],pcb_component_id:w,pcb_port_id:J})}else if(V.pad_shape==="oval"){let J=V.name?C.get(V.name):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${k++}`,shape:"pill",x:xt,y:It,outer_width:uo(K)?V.size?.height??j:V.size?.width??j,outer_height:uo(K)?V.size?.width??j:V.size?.height??j,hole_width:uo(K)?V.drill?.height??ut:V.drill?.width??ut,hole_height:uo(K)?V.drill?.width??ut:V.drill?.height??ut,port_hints:[V.name],layers:["top","bottom"],pcb_component_id:w,pcb_port_id:J})}else if(V.pad_shape==="roundrect"){let J=V.name?C.get(V.name):void 0,tt=V.drill?.offset?.[0]??0,lt=V.drill?.offset?.[1]??0,Tt=cM(tt,lt,K),zt=uo(K)?V.size?.height??j:V.size?.width??j,ee=uo(K)?V.size?.width??j:V.size?.height??j;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${k++}`,shape:"circular_hole_with_rect_pad",hole_shape:"circle",pad_shape:"rect",x:xt,y:It,hole_offset_x:Tt.x,hole_offset_y:-Tt.y,hole_diameter:ut,rect_pad_width:zt,rect_pad_height:ee,rect_border_radius:rt,port_hints:[V.name],layers:["top","bottom"],pcb_component_id:w,pcb_port_id:J})}else{let J=V.name?C.get(V.name):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${k++}`,shape:"circle",x:xt,y:It,outer_diameter:j,hole_diameter:ut,port_hints:[V.name],layers:["top","bottom"],pcb_component_id:w,pcb_port_id:J})}else l.push({type:"pcb_hole",pcb_hole_id:`pcb_hole_${T++}`,x:xt,y:It,hole_diameter:j,hole_shape:"circle",pcb_component_id:w})}let N=[];for(let V of t)V.layer.toLowerCase()==="edge.cuts"&&N.push({type:"line",start:{x:V.start[0],y:V.start[1]},end:{x:V.end[0],y:V.end[1]},strokeWidth:V.stroke.width});for(let V of i)V.layer.toLowerCase()==="edge.cuts"&&N.push({type:"arc",start:{x:V.start[0],y:V.start[1]},mid:{x:V.mid[0],y:V.mid[1]},end:{x:V.end[0],y:V.end[1]},strokeWidth:V.stroke.width});let E=Q5t(N),A=0;for(let V of E){let ot=t4t(V);ot.length>=3&&l.push({type:"pcb_cutout",pcb_cutout_id:`pcb_cutout_${A++}`,shape:"polygon",points:ot.map(K=>({x:K.x,y:-K.y})),pcb_component_id:w})}let O=0,$=0,B=0,H=0;for(let V of t){let ot=[{x:V.start[0],y:-V.start[1]},{x:V.end[0],y:-V.end[1]}],K=V.layer.toLowerCase();K==="f.cu"?l.push({type:"pcb_trace",pcb_trace_id:`pcb_trace_${O++}`,pcb_component_id:w,layer:as(V.layer),route:ot,thickness:V.stroke.width}):K==="f.silks"?l.push({type:"pcb_silkscreen_path",pcb_silkscreen_path_id:`pcb_silkscreen_path_${$++}`,pcb_component_id:w,layer:"top",route:ot,stroke_width:V.stroke.width}):K==="edge.cuts"?kh("Skipping Edge.Cuts fp_line (converted to pcb_cutout)",V.layer):K==="f.fab"?l.push({type:"pcb_fabrication_note_path",fabrication_note_path_id:`fabrication_note_path_${B++}`,pcb_component_id:w,layer:"top",route:ot,stroke_width:V.stroke.width,port_hints:[]}):K.startsWith("user.")?l.push({type:"pcb_note_line",pcb_note_line_id:`pcb_note_line_${H++}`,pcb_component_id:w,x1:V.start[0],y1:-V.start[1],x2:V.end[0],y2:-V.end[1],stroke_width:V.stroke.width}):kh("Unhandled layer for fp_line",V.layer)}if(c)for(let V of c){let ot=V.pts.map(K=>({x:K[0],y:-K[1]}));if(V.layer.endsWith(".Cu")){let K=n4t(ot);K?l.push({type:"pcb_smtpad",pcb_smtpad_id:`pcb_smtpad_${M++}`,shape:"rect",x:K.x,y:K.y,width:K.width,height:K.height,layer:as(V.layer),pcb_component_id:w}):l.push({type:"pcb_trace",pcb_trace_id:`pcb_trace_${O++}`,pcb_component_id:w,layer:as(V.layer),route:ot,thickness:V.stroke.width})}else V.layer.endsWith(".SilkS")?l.push({type:"pcb_silkscreen_path",pcb_silkscreen_path_id:`pcb_silkscreen_path_${$++}`,pcb_component_id:w,layer:as(V.layer),route:ot,stroke_width:V.stroke.width}):V.layer.endsWith(".Fab")?l.push({type:"pcb_fabrication_note_path",fabrication_note_path_id:`fabrication_note_path_${B++}`,pcb_component_id:w,layer:as(V.layer),route:ot,stroke_width:V.stroke.width,port_hints:[]}):kh("Unhandled layer for fp_poly",V.layer)}let Y=0;for(let V of i){let ot=V.layer.toLowerCase();if(ot==="edge.cuts"){kh("Skipping Edge.Cuts fp_arc (converted to pcb_cutout)",V.layer);continue}let K=hm(V.start),it=hm(V.mid),ht=hm(V.end),ft=KH(K,it,ht),xt=JH(K,it,ht,Math.ceil(ft));if(ot.startsWith("user.")){l.push({type:"pcb_note_path",pcb_note_path_id:`pcb_note_path_${Y++}`,pcb_component_id:w,route:xt.map(ut=>({x:ut.x,y:-ut.y})),stroke_width:V.stroke.width});continue}let It=as(V.layer);if(!It){kh("Unable to convert layer for fp_arc",V.layer);continue}l.push({type:"pcb_silkscreen_path",pcb_silkscreen_path_id:`pcb_silkscreen_path_${$++}`,layer:It,pcb_component_id:w,route:xt.map(ut=>({x:ut.x,y:-ut.y})),stroke_width:V.stroke.width})}if(r)for(let V of r){let ot=V.layer.toLowerCase(),K=hm(V.center),it=hm(V.end),ht=Math.sqrt((it.x-K.x)**2+(it.y-K.y)**2),ft=Math.max(16,Math.ceil(2*Math.PI*ht)),xt=[];for(let It=0;It<=ft;It++){let ut=It/ft*2*Math.PI;xt.push({x:K.x+ht*Math.cos(ut),y:K.y+ht*Math.sin(ut)})}ot.startsWith("user.")&&l.push({type:"pcb_note_path",pcb_note_path_id:`pcb_note_path_${Y++}`,pcb_component_id:w,route:xt.map(It=>({x:It.x,y:-It.y})),stroke_width:V.stroke.width})}for(let V of n){let ot=as(V.layer);V.layer.endsWith(".SilkS")?l.push({type:"pcb_silkscreen_text",layer:ot,font:"tscircuit2024",font_size:V.effects?.font?.size[0]??1,pcb_component_id:w,anchor_position:{x:V.at[0],y:-V.at[1]},anchor_alignment:"center",text:V.text}):V.layer.endsWith(".Fab")?l.push({type:"pcb_fabrication_note_text",layer:ot,font:"tscircuit2024",font_size:V.effects?.font?.size[0]??1,pcb_component_id:w,anchor_position:{x:V.at[0],y:-V.at[1]},anchor_alignment:"center",text:V.text}):kh("Unhandled layer for fp_text",V.layer)}let U=s.find(V=>V.key==="Reference"),et=s.find(V=>V.key==="Value"),Q=[U,et].filter(V=>V&&!!V.val);for(let V of Q){let ot=V.attributes.at;if(!ot)continue;let it=V.attributes.layer?.toLowerCase()?.endsWith(".fab");l.push({type:it?"pcb_fabrication_note_text":"pcb_silkscreen_text",layer:"top",font:"tscircuit2024",font_size:1.27,pcb_component_id:w,anchor_position:{x:ot[0],y:-ot[1]},anchor_alignment:"center",text:V.val})}return l},QH=async e=>{let t=J5t(e);return await i4t(t)};var r4t="https://kicad-mod-cache.tscircuit.com",tG=()=>({partsEngine:DH,footprintLibraryMap:{kicad:async e=>{let t=`${r4t}/${e}`,n=`${t}.circuit.json`,r=await(await fetch(n)).json(),o=Array.isArray(r)?r.filter(a=>a?.type==="pcb_silkscreen_text"?a?.text==="REF**":!0):r,s=`${t}.wrl`;return{footprintCircuitJson:o,cadModel:{wrlUrl:s,modelUnitToMmScale:2.54}}}},footprintFileParserMap:{kicad_mod:{loadFromUrl:async e=>{let t=await fetch(e).then(i=>i.text()),n=await QH(t);return{footprintCircuitJson:Array.isArray(n)?n:[n]}}}}});var lM=Yt(Mn(),1),hee=(0,lM.default)("tsci:eval:execution-context");function vx(e,t={}){globalThis.React=eG;let n=t.platform||tG(),i=t.projectConfig?{...n,...t.projectConfig}:n,r=new Ch({platform:i});t.name&&(r.name=t.name),t.debugNamespace&&r.enableDebug(t.debugNamespace);let o=[];return{fsMap:{},entrypoint:"",logger:{info:s=>{o.push({msg:s})},getLogs:()=>o,stringifyLogs:()=>o.map(s=>s.msg).join(`
247
- `)},preSuppliedImports:{"@tscircuit/core":mx,tscircuit:mx,"@tscircuit/math-utils":a4,react:eG,debug:lM.default,"@tscircuit/props":{}},circuit:r,tsConfig:null,importStack:[],currentlyImporting:new Set,...e}}function xc(e){let t=e;return t=t.replace(/\\/g,"/"),t=t.trim(),t.startsWith("./")&&(t=t.slice(2)),t.startsWith("/")&&(t=t.slice(1)),t}function nG(e){let t={};for(let[n,i]of Object.entries(e))t[xc(n)]=i;return t}function No(e){if(!e)return".";let n=e.replace(/\\/g,"/").replace(/\/+$/,"");return n.indexOf("/")===-1?".":n.substring(0,n.lastIndexOf("/"))||"/"}function wx(e,t){if(e.startsWith("../")){let n=No(t);return wx(e.slice(3),n)}return e.startsWith("./")?wx(e.slice(2),t):e.startsWith("/")?e.slice(1):`${t}/${e}`}function dm(e){if(Array.isArray(e))return null;let t=e["tsconfig.json"];if(!t)return null;try{return JSON.parse(t)}catch{return null}}function iG(e){let{importPath:t,normalizedFilePathMap:n,extensions:i,tsConfig:r}=e,o=r?.compilerOptions?.paths;if(!o)return null;let s=r?.compilerOptions?.baseUrl||".",a=l=>{let u=xc(l);if(n.has(u))return n.get(u);for(let h of i){let d=`${u}.${h}`;if(n.has(d))return n.get(d)}return null};for(let[l,u]of Object.entries(o))if(l.includes("*")){let[d,_]=l.split("*");if(!t.startsWith(d)||!t.endsWith(_||""))continue;let y=t.slice(d.length,t.length-(_?_.length:0));for(let g of u){let x=g.replace("*",y),w=s&&!x.startsWith("./")&&!x.startsWith("/")?`${s}/${x}`:x,S=a(w);if(S)return S}}else{if(t!==l)continue;for(let d of u){let _=s&&!d.startsWith("./")&&!d.startsWith("/")?`${s}/${d}`:d,y=a(_);if(y)return y}}let c=uM({importPath:t,normalizedFilePathMap:n,extensions:i,tsConfig:r});return c||null}function uM(e){let{importPath:t,normalizedFilePathMap:n,extensions:i,tsConfig:r}=e,o=r?.compilerOptions?.baseUrl;if(!o)return null;let s=`${o}/${t}`,a=xc(s);if(n.has(a))return n.get(a);for(let c of i){let l=`${a}.${c}`;if(n.has(l))return n.get(l)}return null}function rG(e,t){let n=t?.compilerOptions?.paths;if(!n)return!1;for(let[i]of Object.entries(n))if(i.includes("*")){let[o,s]=i.split("*");if(e.startsWith(o)&&e.endsWith(s||""))return!0}else if(e===i)return!0;return!1}var fm=(e,t,n,i={})=>{let r=n?wx(e,n):e,o=new Set(Array.isArray(t)?t:Object.keys(t));if(o.has(r))return r;let s=new Map;for(let u of o)s.set(xc(u),u);let a=xc(r);if(s.has(a))return s.get(a);let c=["tsx","ts","json","js","jsx","obj","gltf","glb"];for(let u of c){let h=`${a}.${u}`;if(s.has(h))return s.get(h)}let l=i.tsConfig??null;if(!e.startsWith("./")&&!e.startsWith("../")){let u=iG({importPath:e,normalizedFilePathMap:s,extensions:c,tsConfig:l});if(u)return u;let h=uM({importPath:e,normalizedFilePathMap:s,extensions:c,tsConfig:l});if(h)return h}if(!e.startsWith("./")&&!e.startsWith("../")){let u=xc(e);if(s.has(u))return s.get(u);for(let h of c){let d=`${u}.${h}`;if(s.has(d))return s.get(d)}}return null},Sx=(e,t,n,i={})=>{let r=fm(e,t,n,i);if(!r)throw new Error(`File not found "${e}", available paths:
247
+ `)},preSuppliedImports:{"@tscircuit/core":mx,tscircuit:mx,"@tscircuit/math-utils":a4,react:eG,debug:lM.default,"@tscircuit/props":{}},circuit:r,tsConfig:null,importStack:[],currentlyImporting:new Set,...e}}function xc(e){let t=e;return t=t.replace(/\\/g,"/"),t=t.trim(),t.startsWith("./")&&(t=t.slice(2)),t.startsWith("/")&&(t=t.slice(1)),t}function nG(e){let t={};for(let[n,i]of Object.entries(e))t[xc(n)]=i;return t}function No(e){if(!e)return".";let n=e.replace(/\\/g,"/").replace(/\/+$/,"");return n.indexOf("/")===-1?".":n.substring(0,n.lastIndexOf("/"))||"/"}function wx(e,t){if(e.startsWith("../")){let n=No(t);return wx(e.slice(3),n)}return e.startsWith("./")?wx(e.slice(2),t):e.startsWith("/")?e.slice(1):`${t}/${e}`}function dm(e){if(Array.isArray(e))return null;let t=e["tsconfig.json"];if(!t)return null;try{let n=t.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g,"");return JSON.parse(n)}catch(n){throw new Error(`Failed to parse tsconfig.json: ${n.message}`)}}function iG(e){let{importPath:t,normalizedFilePathMap:n,extensions:i,tsConfig:r}=e,o=r?.compilerOptions?.paths;if(!o)return null;let s=r?.compilerOptions?.baseUrl||".",a=l=>{let u=xc(l);if(n.has(u))return n.get(u);for(let h of i){let d=`${u}.${h}`;if(n.has(d))return n.get(d)}return null};for(let[l,u]of Object.entries(o))if(l.includes("*")){let[d,_]=l.split("*");if(!t.startsWith(d)||!t.endsWith(_||""))continue;let y=t.slice(d.length,t.length-(_?_.length:0));for(let g of u){let x=g.replace("*",y),w=s&&!x.startsWith("./")&&!x.startsWith("/")?`${s}/${x}`:x,S=a(w);if(S)return S}}else{if(t!==l)continue;for(let d of u){let _=s&&!d.startsWith("./")&&!d.startsWith("/")?`${s}/${d}`:d,y=a(_);if(y)return y}}let c=uM({importPath:t,normalizedFilePathMap:n,extensions:i,tsConfig:r});return c||null}function uM(e){let{importPath:t,normalizedFilePathMap:n,extensions:i,tsConfig:r}=e,o=r?.compilerOptions?.baseUrl;if(!o)return null;let s=`${o}/${t}`,a=xc(s);if(n.has(a))return n.get(a);for(let c of i){let l=`${a}.${c}`;if(n.has(l))return n.get(l)}return null}function rG(e,t){let n=t?.compilerOptions?.paths;if(!n)return!1;for(let[i]of Object.entries(n))if(i.includes("*")){let[o,s]=i.split("*");if(e.startsWith(o)&&e.endsWith(s||""))return!0}else if(e===i)return!0;return!1}var fm=(e,t,n,i={})=>{let r=n?wx(e,n):e,o=new Set(Array.isArray(t)?t:Object.keys(t));if(o.has(r))return r;let s=new Map;for(let u of o)s.set(xc(u),u);let a=xc(r);if(s.has(a))return s.get(a);let c=["tsx","ts","json","js","jsx","obj","gltf","glb"];for(let u of c){let h=`${a}.${u}`;if(s.has(h))return s.get(h)}let l=i.tsConfig??null;if(!e.startsWith("./")&&!e.startsWith("../")){let u=iG({importPath:e,normalizedFilePathMap:s,extensions:c,tsConfig:l});if(u)return u;let h=uM({importPath:e,normalizedFilePathMap:s,extensions:c,tsConfig:l});if(h)return h}if(!e.startsWith("./")&&!e.startsWith("../")){let u=xc(e);if(s.has(u))return s.get(u);for(let h of c){let d=`${u}.${h}`;if(s.has(d))return s.get(d)}}return null},Sx=(e,t,n,i={})=>{let r=fm(e,t,n,i);if(!r)throw new Error(`File not found "${e}", available paths:
248
248
 
249
249
  ${Object.keys(t).join(", ")}`);return r};var Px=e=>{let t=/^\s*import\s+(?:(?:[\w\s]+,\s*)?(?:\*\s+as\s+[\w\s]+|\{[\s\w,]+\}|\w+)\s+from\s*)?['"](.+?)['"]/gm,n=[],i;for(;(i=t.exec(e))!==null;)n.push(i[1]);let r=/^\s*export\s+(?:\*|(?:\{[\s\w,]+\}))\s+from\s*['"](.+?)['"]/gm,o;for(;(o=r.exec(e))!==null;)n.push(o[1]);return n};function Ql(e,t,n){globalThis.__tscircuit_require=r=>{let o=fm(r,t,n),s=o&&t[o];if(!t[r]&&!s)throw new Error(`Import "${r}" not found ${n?`in "${n}"`:""}`);let a=t[r]||t[o];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=`
250
250
  var exports = {};
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "dist/index.js",
4
4
  "types": "dist/index.d.ts",
5
5
  "type": "module",
6
- "version": "0.0.786-libonly",
6
+ "version": "0.0.787-libonly",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "https://github.com/tscircuit/tscircuit"
@@ -45,14 +45,14 @@
45
45
  "@tscircuit/circuit-json-flex": "^0.0.3",
46
46
  "@tscircuit/circuit-json-util": "^0.0.72",
47
47
  "@tscircuit/core": "^0.0.799",
48
- "@tscircuit/eval": "^0.0.405",
48
+ "@tscircuit/eval": "^0.0.406",
49
49
  "@tscircuit/footprinter": "^0.0.236",
50
50
  "@tscircuit/infgrid-ijump-astar": "^0.0.33",
51
51
  "@tscircuit/matchpack": "^0.0.16",
52
52
  "@tscircuit/math-utils": "^0.0.21",
53
53
  "@tscircuit/miniflex": "^0.0.4",
54
54
  "@tscircuit/props": "0.0.369",
55
- "@tscircuit/runframe": "^0.0.1121",
55
+ "@tscircuit/runframe": "^0.0.1122",
56
56
  "@tscircuit/schematic-match-adapt": "^0.0.16",
57
57
  "@tscircuit/schematic-trace-solver": "^0.0.41",
58
58
  "@tscircuit/simple-3d-svg": "^0.0.41",