tscircuit 0.0.778 → 0.0.779-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.
- package/dist/browser.min.js +2 -2
- package/dist/webworker.min.js +4 -2
- package/package.json +5 -11
- package/cli.mjs +0 -14
package/dist/webworker.min.js
CHANGED
|
@@ -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=y3t({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=tV(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 Ai()}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=_Y(t.toArray());for(let l of n)t.pcb_trace_error.insert(l);let i=mY(t.toArray());for(let l of i)t.pcb_port_not_connected_error.insert(l);let r=bY(t.toArray());for(let l of r)t.pcb_component_outside_board_error.insert(l);let o=wY(t.toArray());for(let l of o)t.pcb_trace_error.insert(l);let s=vY(t.toArray());for(let l of s)t.pcb_via_clearance_error.insert(l);let a=xY(t.toArray());for(let l of a)t.pcb_via_clearance_error.insert(l);let c=SY(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})}},h5t=new Proxy({},{get:(e,t)=>t}),na=h5t,px="rgba(132, 0, 0)",hx=.12,kV=class extends On{constructor(){super(...arguments);T(this,"_adjustSilkscreenTextAutomatically",!0)}get config(){return{componentName:"Capacitor",schematicSymbolName:this.props.polarized?"capacitor_polarized":this.props.symbolName??"capacitor",zodProps:Mz,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 Eo({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.decouplingFor})),this.add(new Eo({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}},dx=class extends On{constructor(t){super(t);T(this,"schematicBoxDimensions",null)}get config(){return{componentName:"Chip",zodProps:Rp,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 Di&&s.isMatchingAnyOf([r]))){let s=r.match(/^pin(\d+)$/);if(s){let a=parseInt(s[1]);this.add(new Di({pinNumber:a,aliases:[r]}))}else this.add(new Di({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=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}doInitialCreateTracesFromProps(){let{_parsedProps:t}=this;if(t.externallyConnectedPins)for(let[n,i]of t.externallyConnectedPins)this.add(new Eo({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})}},NV=class extends dx{constructor(e){super(e)}get config(){return{...super.config,componentName:"Pinout",zodProps:gz}}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}},AV=class extends On{constructor(){super(...arguments);T(this,"pos",this.portMap.pin1);T(this,"anode",this.portMap.pin1);T(this,"neg",this.portMap.pin2);T(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:Vz,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}},RV=class extends On{get config(){return{componentName:"fuse",schematicSymbolName:this.props.symbolName??"fuse",zodProps:xz,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}},OV=class extends On{constructor(){super(...arguments);T(this,"schematicDimensions",null)}get config(){return{schematicSymbolName:void 0,componentName:"Jumper",zodProps:i4,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))}},LV=class extends On{constructor(){super(...arguments);T(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:bz,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))}},zV=class extends On{constructor(){super(...arguments);T(this,"pos",this.portMap.pin1);T(this,"anode",this.portMap.pin1);T(this,"neg",this.portMap.pin2);T(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:Gz,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}},FV=class extends On{constructor(){super(...arguments);T(this,"pos",this.portMap.pin1);T(this,"positive",this.portMap.pin1);T(this,"neg",this.portMap.pin2);T(this,"negative",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"power_factor_meter_horz",componentName:"PowerSource",zodProps:sF,sourceFtype:"simple_power_source"}}initPorts(){this.add(new Di({name:"pin1",pinNumber:1,aliases:["positive","pos"]})),this.add(new Di({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}},d5t=Fn.extend({voltage:oi.optional(),frequency:to.optional(),peakToPeakVoltage:oi.optional(),waveShape:p.enum(["sinewave","square","triangle","sawtooth"]).optional(),phase:Fe.optional(),dutyCycle:p.number().optional()}),DV=class extends On{constructor(){super(...arguments);T(this,"terminal1",this.portMap.terminal1);T(this,"terminal2",this.portMap.terminal2)}get config(){return{componentName:"VoltageSource",schematicSymbolName:this.props.waveShape==="square"?"square_wave":"ac_voltmeter",zodProps:d5t,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})}},$V=class extends On{constructor(){super(...arguments);T(this,"_adjustSilkscreenTextAutomatically",!0)}get config(){return{componentName:"Resistor",schematicSymbolName:this.props.symbolName??"boxresistor",zodProps:wz,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 Eo({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pullupFor})),this.add(new Eo({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pullupTo}))),this.props.pulldownFor&&this.props.pulldownTo&&(this.add(new Eo({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pulldownFor})),this.add(new Eo({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}},f5t=["leftedge","rightedge","topedge","bottomedge","center"],BV=class extends be{get config(){return{componentName:"Constraint",zodProps:Ez}}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=f5t.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}}},jV=class extends be{constructor(){super(...arguments);T(this,"fabrication_note_rect_id",null)}get config(){return{componentName:"FabricationNoteRect",zodProps:Zz}}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}}},YV=class extends be{constructor(){super(...arguments);T(this,"fabrication_note_path_id",null)}get config(){return{componentName:"FabricationNotePath",zodProps:Kz}}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}},XV=class extends be{get config(){return{componentName:"FabricationNoteText",zodProps:Wz}}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})}},VV=class extends be{constructor(){super(...arguments);T(this,"fabrication_note_dimension_id",null);T(this,"isPcbPrimitive",!0)}get config(){return{componentName:"FabricationNoteDimension",zodProps:Jz}}_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)}}},HV=class extends be{constructor(){super(...arguments);T(this,"pcb_note_line_id",null);T(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbNoteLine",zodProps:IF}}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)}}},GV=class extends be{constructor(){super(...arguments);T(this,"pcb_note_rect_id",null);T(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbNoteRect",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_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}}},UV=class extends be{constructor(){super(...arguments);T(this,"pcb_note_text_id",null);T(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbNoteText",zodProps:SF}}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}}},qV=class extends be{constructor(){super(...arguments);T(this,"pcb_note_path_id",null);T(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbNotePath",zodProps:TF}}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}}},WV=class extends be{constructor(){super(...arguments);T(this,"pcb_note_dimension_id",null);T(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbNoteDimension",zodProps:MF}}_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)}}},ZV=class extends Th{constructor(e){super({...e,subcircuit:!0})}},KV=class extends Th{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}})}},JV=class extends be{constructor(){super(...arguments);T(this,"pcb_breakout_point_id",null);T(this,"matchedPort",null);T(this,"matchedNet",null);T(this,"isPcbPrimitive",!0)}get config(){return{componentName:"BreakoutPoint",zodProps:eF}}_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}}},QV=class extends be{constructor(){super(...arguments);T(this,"source_net_label_id")}get config(){return{componentName:"NetLabel",zodProps:Dz}}_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?.()??Ai(),{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&&WI(this,[`net.${t.net}`])}doInitialCreateTracesFromNetLabels(){if(this.root?.schematicDisabled)return;let t=this._resolveConnectsTo();if(t)for(let n of t)this.add(new Eo({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=jI(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})}}},tH=class extends be{constructor(){super(...arguments);T(this,"pcb_silkscreen_circle_id",null);T(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenCircle",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 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}}},eH=class extends be{constructor(){super(...arguments);T(this,"pcb_silkscreen_rect_id",null);T(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenRect",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 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}}},nH=class extends be{constructor(){super(...arguments);T(this,"pcb_silkscreen_line_id",null);T(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenLine",zodProps:bF}}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}}},iH=class extends be{constructor(t){super(t);T(this,"pcb_via_id",null);T(this,"matchedPort",null);T(this,"isPcbPrimitive",!0);T(this,"source_manually_placed_via_id",null);let n=this._getLayers();this._parsedProps.layers=n,this.initPorts()}get config(){return{componentName:"Via",zodProps:Qz}}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 Di({name:i,layer:i});r.registerMatch(this),this.add(r)}let n=new Di({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}},rH=class extends be{constructor(){super(...arguments);T(this,"isPcbPrimitive",!0)}get config(){return{componentName:"CopperPour",zodProps:iF}}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=JI(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 M=(g.x+x.x)/2,C=(g.y+x.y)/2,N=Math.atan2(x.y-g.y,x.x-g.x)*180/Math.PI,k=yV({center:{x:M,y:C},width:S,height:w,rotation:N});for(let E of k)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(I=>I.orientation()===z.ORIENTATION.CCW),S=x.filter(I=>I.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 M=I=>I.edges.map(k=>{let E={x:k.start.x,y:k.start.y};if(k.isArc){let A=Math.tan(k.shape.sweep/4);Math.abs(A)>1e-9&&(E.bulge=A)}return E});w.reverse();let C=M(w),N=S.map(I=>(I.reverse(),{vertices:M(I)}));for(let I of l){let k=z.point(I.center.x,I.center.y);g.contains(k)&&N.push({vertices:[{x:I.center.x,y:I.center.y-I.radius,bulge:1},{x:I.center.x,y:I.center.y+I.radius,bulge:1}]})}t.pcb_copper_pour.insert({shape:"brep",layer:n.layer,brep_shape:{outer_ring:{vertices:C},inner_rings:N},source_net_id:i.source_net_id,subcircuit_id:this.getSubcircuit()?.subcircuit_id??void 0})}}})}},oH=class extends On{get config(){return{componentName:"Battery",schematicSymbolName:this.props.symbolName??"battery",zodProps:zz,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}},sH=class extends On{_getPcbRotationBeforeLayout(){let e=this.props.pcbOrientation==="vertical"?-90:0;return(super._getPcbRotationBeforeLayout()??0)+e}get config(){return{componentName:"PinHeader",zodProps:Fz,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 Di({pinNumber:t,name:i,aliases:[`pin${t}`,...r]}))}else this.add(new Di({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 m5t(e){switch(e){case"two_ground_pins":return"crystal_4pin";case"ground_pin":return"resonator";case"no_ground":return"crystal";default:return"crystal"}}var aH=class extends On{get config(){return{componentName:"Resonator",schematicSymbolName:this.props.symbolName??m5t(this.props.pinVariant),zodProps:Iz,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}},cH=class extends On{constructor(){super(...arguments);T(this,"_adjustSilkscreenTextAutomatically",!0)}get config(){return{componentName:"Inductor",schematicSymbolName:this.props.symbolName??"inductor",zodProps:Xz,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 _5t(e){switch(e){case"three_pin":return"potentiometer3";case"two_pin":return"potentiometer2";default:return"potentiometer2"}}var lH=class extends On{get config(){return{componentName:"Potentiometer",schematicSymbolName:this.props.symbolName??_5t(this.props.pinVariant),zodProps:Pz,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}},uH=class extends On{get config(){return{componentName:"PushButton",schematicSymbolName:this.props.symbolName??"push_button_normally_open_momentary",zodProps:$z,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}},pH=class extends On{get config(){return{schematicSymbolName:this.props.symbolName??(this.props.pinVariant==="four_pin"?"crystal_4pin":"crystal"),componentName:"Crystal",zodProps:Tz,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}},hH=class extends On{constructor(){super(...arguments);T(this,"emitter",this.portMap.pin1);T(this,"collector",this.portMap.pin2);T(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:jz,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}},dH=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:Yz,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}},y5t=e=>e?e.closesAt!==void 0||e.opensAt!==void 0||e.startsClosed!==void 0||e.switchingFrequency!==void 0:!1,g5t=e=>!e||typeof e!="object"?!1:Object.prototype.hasOwnProperty.call(e,"spice"),b5t=e=>{if(!e||typeof e!="object")return null;let t=g5t(e)?e.spice??null:e;return y5t(t)?{...t}:null},fH=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:qz,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=b5t(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)}},DI={HOLE_DIAMETER:.5,SMT_CIRCLE_DIAMETER:1.2,SMT_RECT_SIZE:2},mH=class extends On{get config(){return{componentName:"TestPoint",schematicSymbolName:this.props.symbolName??"testpoint",zodProps:tF,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=DI.SMT_CIRCLE_DIAMETER):e==="rect"&&(r??(r=DI.SMT_RECT_SIZE),o??(o=r)):n==="through_hole"&&(t??(t=DI.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}},_H=class extends be{constructor(){super(...arguments);T(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicText",zodProps:dF}}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})}},yH=class extends be{constructor(){super(...arguments);T(this,"isSchematicPrimitive",!0);T(this,"schematic_line_id")}get config(){return{componentName:"SchematicLine",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_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??hx,color:n.color??px,is_dashed:!1,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.schematic_line_id=o.schematic_line_id}},gH=class extends be{constructor(){super(...arguments);T(this,"isSchematicPrimitive",!0);T(this,"schematic_rect_id")}get config(){return{componentName:"SchematicRect",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_rect.insert({center:{x:i.x,y:i.y},width:n.width,height:n.height,stroke_width:n.strokeWidth??hx,color:n.color??px,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}},bH=class extends be{constructor(){super(...arguments);T(this,"isSchematicPrimitive",!0);T(this,"schematic_arc_id")}get config(){return{componentName:"SchematicArc",zodProps:cF}}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??hx,color:n.color??px,is_dashed:n.isDashed,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.schematic_arc_id=o.schematic_arc_id}},xH=class extends be{constructor(){super(...arguments);T(this,"isSchematicPrimitive",!0);T(this,"schematic_circle_id")}get config(){return{componentName:"SchematicCircle",zodProps:uF}}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??hx,color:n.color??px,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 x5t({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 vH=class extends be{constructor(){super(...arguments);T(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicBox",zodProps:lF,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(nt=>({selector:nt,port:this.getSubcircuit().selectOne(nt,{type:"port"})})).filter(({port:nt})=>nt!=null).map(({port:nt})=>({position:nt._getGlobalSchematicPositionAfterLayout()}));if(S.length===0)return;let M=S.map(nt=>nt.position.x),C=S.map(nt=>nt.position.y),N=Math.min(...M),I=Math.max(...M),k=Math.min(...C),E=Math.max(...C),A=I-N,O=E-k,$=A===0?i:0,B=O===0?i:0,H=a+$/2,Y=c+$/2,U=o+B/2,et=s+B/2,Q=N-H,V=I+Y,ot=k-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,M=n.titleAlignment,C=x5t({anchor:M,x:_,y,width:h,height:d,isInside:w}),N,I,k=C.textAnchor;w?(N=M.includes("top")?-S:M.includes("bottom")?S:0,I=M.includes("left")?S:M.includes("right")?-S:0):(N=M.includes("top")?S:M.includes("bottom")?-S:0,I=M.includes("center_left")?-S:M.includes("center_right")?S:0);let E=C.x+I,A=C.y+N;t.schematic_text.insert({anchor:k,text:n.title,font_size:n.titleFontSize??.18,color:n.titleColor??"#000000",position:{x:E,y:A},rotation:0})}}},wH=class extends be{constructor(){super(...arguments);T(this,"isSchematicPrimitive",!0);T(this,"schematic_table_id",null)}get config(){return{componentName:"SchematicTable",zodProps:fF}}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,M=w._parsedProps.rowSpan??1;for(let C=0;C<M;C++)for(let N=0;N<S;N++)r[d+C]||(r[d+C]=[]),r[d+C][g+N]=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,M=0;for(let N=0;N<S;N++)M+=a[y+N];let C=0;for(let N=0;N<w;N++)C+=s[d+N];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+_+M/2,y:c.y-h-C/2},width:M,height:C,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]}}},SH=class extends be{constructor(){super(...arguments);T(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicRow",zodProps:mF}}},PH=class extends be{constructor(){super(...arguments);T(this,"isSchematicPrimitive",!0);T(this,"canHaveTextChildren",!0)}get config(){return{componentName:"SchematicCell",zodProps:_F}}},TH=class extends be{constructor(){super(...arguments);T(this,"isPrimitiveContainer",!0)}get config(){return{componentName:"Symbol",zodProps:Lz}}},IH=class extends be{get config(){return{componentName:"AnalogSimulation",zodProps:Bz}}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})}},MH=class extends be{constructor(){super(...arguments);T(this,"simulation_voltage_probe_id",null)}get config(){return{componentName:"VoltageProbe",zodProps:aF}}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}},v5t={name:"@tscircuit/core",type:"module",version:"0.0.792",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.363","@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.278","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.238","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.48","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"}},Ih=class{constructor({platform:e,projectUrl:t}={}){T(this,"firstChild",null);T(this,"children");T(this,"db");T(this,"root",null);T(this,"isRoot",!0);T(this,"schematicDisabled",!1);T(this,"pcbDisabled",!1);T(this,"pcbRoutingDisabled",!1);T(this,"_featureMspSchematicTraceRouting",!0);T(this,"name");T(this,"platform");T(this,"projectUrl");T(this,"_hasRenderedAtleastOnce",!1);T(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,CH.isValidElement)(e)?t=sV(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 Th({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(()=>(kX(),EX)).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]=v5t.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 Ai()}_computePcbGlobalTransformBeforeLayout(){return Ai()}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"?HI.default.enable(e):(e===null||e===!1)&&HI.default.disable()}getClientOrigin(){return typeof window<"u"&&window.location?window.location.origin:typeof self<"u"&&self.location?self.location.origin:""}},w5t=Ih,S5t=Ih,P5t=e=>{let[t,n]=wh.default.useState(!0),[i,r]=wh.default.useState(null),[o,s]=wh.default.useState(),[a,c]=wh.default.useState();return wh.default.useEffect(()=>{n(!0),r(null),e&&setTimeout(()=>{try{let l=new Ih;l.add(e),s(l),c(l.toJson())}catch(l){r(l)}n(!1)},1)},[e]),{isLoading:t,error:i,circuit:o,circuitJson:a}},Mh=(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},T5t=Mh(e=>(0,EH.jsx)("capacitor",{...e}),Cz),I5t=e=>Mh(t=>(0,kH.jsx)("chip",{pinLabels:e,...t}),e),M5t=Mh(e=>(0,NH.jsx)("diode",{...e}),Hz),C5t=Mh(e=>(0,AH.jsx)("led",{...e}),Uz),E5t=Mh(e=>(0,RH.jsx)("resistor",{...e}),Sz),k5t=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}`})}})})}});oV(eV);oV({Bug:dx});var tG=Yt(xo(),1);var LH=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 nM=e=>e.includes("cap")?e.replace(/cap/g,""):e;var zH=e=>{if(e){if(e.startsWith("kicad:")){let t=LH(e);return t?nM(t):e}return nM(e)}};var iM=new Map,ir=async(e,t)=>{let n=new URLSearchParams({...t,json:"true"}).toString();if(iM.has(n))return iM.get(n);let r=await(await fetch(`https://jlcsearch.tscircuit.com/${e}/list?${n}`)).json();return iM.set(n,r),r},rr=e=>e?[...e].sort((t,n)=>Number(n.is_basic??!1)-Number(t.is_basic??!1)):[],FH={findPart:async({sourceComponent:e,footprinterString:t})=>{let n=zH(t);if(e.type==="source_component"&&e.ftype==="simple_resistor"){let{resistors:i}=await ir("resistors",{resistance:e.resistance,package:n});return{jlcpcb:rr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_capacitor"){let{capacitors:i}=await ir("capacitors",{capacitance:e.capacitance,package:n});return{jlcpcb:rr(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 ir("headers",i?{pitch:i,num_pins:e.pin_count,gender:e.gender}:{num_pins:e.pin_count,gender:e.gender});return{jlcpcb:rr(r).map(o=>`C${o.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_potentiometer"){let{potentiometers:i}=await ir("potentiometers",{resistance:e.max_resistance,package:n});return{jlcpcb:rr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_diode"){let{diodes:i}=await ir("diodes",{package:n});return{jlcpcb:rr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_chip"){let{chips:i}=await ir("chips",{package:n});return{jlcpcb:rr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_transistor"){let{transistors:i}=await ir("transistors",{package:n,transistor_type:e.transistor_type});return{jlcpcb:rr(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 ir("power_sources",{voltage:e.voltage,package:n});return{jlcpcb:rr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_inductor"){let{inductors:i}=await ir("inductors",{inductance:e.inductance,package:n});return{jlcpcb:rr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_crystal"){let{crystals:i}=await ir("crystals",{frequency:e.frequency,load_capacitance:e.load_capacitance,package:n});return{jlcpcb:rr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_mosfet"){let{mosfets:i}=await ir("mosfets",{package:n,mosfet_mode:e.mosfet_mode,channel_type:e.channel_type});return{jlcpcb:rr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_resonator"){let{resonators:i}=await ir("resonators",{frequency:e.frequency,package:n});return{jlcpcb:rr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_switch"){let{switches:i}=await ir("switches",{switch_type:e.type,package:n});return{jlcpcb:rr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_led"){let{leds:i}=await ir("leds",{package:n});return{jlcpcb:rr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}else if(e.type==="source_component"&&e.ftype==="simple_fuse"){let{fuses:i}=await ir("fuses",{package:n});return{jlcpcb:rr(i).map(r=>`C${r.lcsc}`).slice(0,3)}}return{}}};var jH=Yt(DH(),1);Z();var GH=Yt(Mn(),1),UH=Yt(Mn(),1),$i=p.tuple([p.coerce.number(),p.coerce.number()]),B5t=p.tuple([p.number(),p.number(),p.number()]),bx=p.union([$i,B5t]),YH=p.object({at:bx,size:$i,layer:p.string(),layers:p.array(p.string()),roundrect_rratio:p.number(),uuid:p.string()}).partial(),j5t=p.object({key:p.string(),val:p.string(),attributes:YH}),_x=p.object({oval:p.boolean().default(!1),width:p.number().optional(),height:p.number().optional(),offset:$i.optional()}),XH=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:bx,drill:p.union([p.number(),p.array(p.any()),_x]).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:$i.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]?$i.parse(e[3].slice(1)):void 0}:e).pipe(_x),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()}),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:bx,size:$i,drill:p.union([p.number(),p.array(p.any()),_x]).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:$i.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]?$i.parse(e[3].slice(1)):void 0}:e).pipe(_x).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()}),HH=p.object({font:p.object({size:$i,thickness:p.number().optional()})}).partial(),Y5t=p.object({fp_text_type:p.literal("user"),text:p.string(),at:bx,layer:p.string(),uuid:p.string().optional(),effects:HH.partial()}),X5t=p.object({start:$i,mid:$i,end:$i,stroke:p.object({width:p.number(),type:p.string()}),layer:p.string(),uuid:p.string().optional()}),V5t=p.object({center:$i,end:$i,stroke:p.object({width:p.number(),type:p.string()}),fill:p.string().optional(),layer:p.string(),uuid:p.string().optional()}),H5t=p.object({pts:p.array($i),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}})),G5t=p.object({start:$i,end:$i,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}})),$H=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(j5t),fp_lines:p.array(G5t),fp_texts:p.array(Y5t),fp_arcs:p.array(X5t),fp_circles:p.array(V5t).optional(),fp_polys:p.array(H5t).optional(),pads:p.array(VH),holes:p.array(XH).optional()}),yx=(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 HH.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]=yx(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 yx(n.slice(1),t)},rM=(0,GH.default)("kicad-mod-converter"),U5t=e=>{let t=(0,jH.default)(e),n=t[1].valueOf(),i={},r=Object.entries($H.shape).filter(([M,C])=>C._def.typeName==="ZodString"||M==="tags").map(([M])=>M);for(let M of t.slice(2)){if(!r.includes(M[0]))continue;let C=M[0].valueOf(),N=yx(M.slice(1),C);i[C]=N}let o=t.slice(2).filter(M=>M[0]==="property").map(M=>{let C=M[1].valueOf(),N=M[2].valueOf(),I=YH.parse(M.slice(3).reduce((k,E)=>{let A=E[0].valueOf();return k[A]=yx(E.slice(1),A),k},{}));return{key:C,val:N,attributes:I}}),s=t.slice(2).filter(M=>M[0]==="pad"),a=[];for(let M of s){let C=De(M,"at"),N=De(M,"size"),I=De(M,"drill"),k=De(M,"layers");if(Array.isArray(k)?k=k.map($=>$.valueOf()):typeof k=="string"?k=[k]:k||(k=[]),!k.includes("F.Cu")){rM(`Skipping pad without F.Cu layer: layers=${k.join(", ")}`);continue}let E=De(M,"roundrect_rratio"),A=De(M,"uuid"),O={name:M[1].valueOf(),pad_type:M[2].valueOf(),pad_shape:M[3].valueOf(),at:C,drill:I,size:N,layers:k,roundrect_rratio:E,uuid:A};rM(`attempting to parse pad: ${JSON.stringify(O,null," ")}`),a.push(VH.parse(O))}let c=t.slice(2).filter(M=>M[0]==="fp_text"),l=[];for(let M of c){let C=M[2].valueOf(),N=De(M,"at"),I=De(M,"layer"),k=De(M,"uuid"),E=De(M,"effects");l.push({fp_text_type:"user",text:C,at:N,layer:I,uuid:k,effects:E})}let u=[],h=t.slice(2).filter(M=>M[0]==="fp_line");for(let M of h){let C=De(M,"start"),N=De(M,"end"),I=De(M,"stroke"),k=De(M,"layer"),E=De(M,"uuid");u.push({start:C,end:N,stroke:I,layer:k,uuid:E})}let d=[],_=t.slice(2).filter(M=>M[0]==="fp_arc");for(let M of _){let C=De(M,"start"),N=De(M,"mid"),I=De(M,"end"),k=De(M,"stroke"),E=De(M,"layer"),A=De(M,"uuid");!C||!I||!N||!k||!E||d.push({start:C,mid:N,end:I,stroke:k,layer:E,uuid:A})}let y=[],g=t.slice(2).filter(M=>M[0]==="fp_circle");for(let M of g){let C=De(M,"center"),N=De(M,"end"),I=De(M,"stroke"),k=De(M,"fill"),E=De(M,"layer"),A=De(M,"uuid");!C||!N||!I||!E||y.push({center:C,end:N,stroke:I,fill:k,layer:E,uuid:A})}let x=[],w=t.slice(2).filter(M=>M[0]==="fp_poly");for(let M of w){let C=De(M,"pts"),N=De(M,"stroke"),I=De(M,"layer"),k=De(M,"uuid");x.push({pts:C,stroke:N,layer:I,uuid:k})}let S=[];for(let M of t.slice(2)){if(M[0]!=="pad"||M[2]?.valueOf?.()!=="thru_hole")continue;let C=M[1]?.valueOf?.(),N=M[2]?.valueOf?.(),I=M[3]?.valueOf?.(),k=De(M,"at"),E=De(M,"drill"),A=De(M,"size");Array.isArray(A)&&(A[0]==="size"&&(A=A.slice(1)),A={width:Number(A[0]),height:Number(A[1])});let O=De(M,"uuid"),$=De(M,"roundrect_rratio"),B=De(M,"layers");Array.isArray(B)?B=B.map(Y=>Y.valueOf()):typeof B=="string"?B=[B]:B||(B=[]);let H={name:C,pad_type:N,pad_shape:I,at:k,drill:E,size:A,layers:B,roundrect_rratio:$,uuid:O};rM(`attempting to parse holes: ${JSON.stringify(H,null,2)}`),S.push(XH.parse(H))}return $H.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 qH(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 WH(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function gx(e,t){return Math.atan2(t.y-e.y,t.x-e.x)}var ZH=(e,t,n)=>{let i=qH(e,t,n),r=WH(i,e),o=gx(i,e),a=gx(i,n)-o;return a<0&&(a+=2*Math.PI),r*a};function KH(e,t,n,i){let r=qH(e,t,n),o=WH(r,e),s=gx(r,e),c=gx(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 pm=e=>Array.isArray(e)?{x:e[0],y:e[1]}:e,oM=(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&&oM(o,r[0].start)){t.push(r);break}for(let a=0;a<e.length;a++)if(!n.has(a)){if(oM(o,e[a].start)){r.push(e[a]),n.add(a),o=e[a].end,s=!0;break}else if(oM(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},W5t=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=ZH(n.start,n.mid,n.end),r=Math.max(3,Math.ceil(i)),o=KH(n.start,n.mid,n.end,r);n.reversed&&(o=o.reverse()),t.push(...o.slice(0,-1))}return t},Z5t=e=>e*Math.PI/180,sM=(e,t,n)=>{let i=Z5t(n),r=Math.cos(i),o=Math.sin(i);return{x:e*r-t*o,y:e*o+t*r}},K5t=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}},BH=e=>e&&Array.isArray(e)&&e.length>=3&&typeof e[2]=="number"?e[2]:0,lo=e=>{let t=(e%360+360)%360;return t===90||t===270},Ch=(0,UH.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"}},J5t=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],nt=V.size[0],ht=V.size[1];_=Math.min(_,ot-nt/2),y=Math.max(y,ot+nt/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,M=new Map;for(let V of u){let ot=`pcb_port_${S++}`,K=d.get(V);M.set(V,ot);let nt=0,ht=0,ft=["top","bottom"],xt=o.find(It=>It.name===V);if(xt)nt=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&&(nt=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:nt,y:ht,layers:ft})}let C=0,N=0,I=0;for(let V of o)if(V.pad_type==="smd"){let ot=V.name?M.get(V.name):void 0;l.push({type:"pcb_smtpad",pcb_smtpad_id:`pcb_smtpad_${C++}`,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=BH(V.at),K=lo(ot)?V.size[1]:V.size[0],nt=lo(ot)?V.size[0]:V.size[1],ht=V.drill?.offset?.[0]??0,ft=V.drill?.offset?.[1]??0,xt=sM(ht,ft,ot),It=V.name?M.get(V.name):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${N++}`,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:nt,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?M.get(V.name):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${N++}`,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?M.get(V.name):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${N++}`,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_${I++}`,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=BH(V.at),nt=V.drill?.offset?.[0]??0,ht=V.drill?.offset?.[1]??0,ft=sM(nt,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(lo(K)?V.size?.height??j:V.size?.width??j,lo(K)?V.size?.width??j:V.size?.height??j)/2*q:0;if(ot)if(V.pad_shape==="rect"){let J=V.name?M.get(V.name):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${N++}`,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:lo(K)?V.size?.height??j:V.size?.width??j,rect_pad_height:lo(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?M.get(V.name):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${N++}`,shape:"pill",x:xt,y:It,outer_width:lo(K)?V.size?.height??j:V.size?.width??j,outer_height:lo(K)?V.size?.width??j:V.size?.height??j,hole_width:lo(K)?V.drill?.height??ut:V.drill?.width??ut,hole_height:lo(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?M.get(V.name):void 0,it=V.drill?.offset?.[0]??0,lt=V.drill?.offset?.[1]??0,Tt=sM(it,lt,K),zt=lo(K)?V.size?.height??j:V.size?.width??j,ee=lo(K)?V.size?.width??j:V.size?.height??j;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${N++}`,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?M.get(V.name):void 0;l.push({type:"pcb_plated_hole",pcb_plated_hole_id:`pcb_plated_hole_${N++}`,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_${I++}`,x:xt,y:It,hole_diameter:j,hole_shape:"circle",pcb_component_id:w})}let k=[];for(let V of t)V.layer.toLowerCase()==="edge.cuts"&&k.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"&&k.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(k),A=0;for(let V of E){let ot=W5t(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"?Ch("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}):Ch("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=K5t(ot);K?l.push({type:"pcb_smtpad",pcb_smtpad_id:`pcb_smtpad_${C++}`,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:[]}):Ch("Unhandled layer for fp_poly",V.layer)}let Y=0;for(let V of i){let ot=V.layer.toLowerCase();if(ot==="edge.cuts"){Ch("Skipping Edge.Cuts fp_arc (converted to pcb_cutout)",V.layer);continue}let K=pm(V.start),nt=pm(V.mid),ht=pm(V.end),ft=ZH(K,nt,ht),xt=KH(K,nt,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){Ch("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=pm(V.center),nt=pm(V.end),ht=Math.sqrt((nt.x-K.x)**2+(nt.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}):Ch("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 nt=V.attributes.layer?.toLowerCase()?.endsWith(".fab");l.push({type:nt?"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},JH=async e=>{let t=U5t(e);return await J5t(t)};var Q5t="https://kicad-mod-cache.tscircuit.com",QH=()=>({partsEngine:FH,footprintLibraryMap:{kicad:async e=>{let t=`${Q5t}/${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 JH(t);return{footprintCircuitJson:Array.isArray(n)?n:[n]}}}}});var aM=Yt(Mn(),1),eee=(0,aM.default)("tsci:eval:execution-context");function xx(e,t={}){globalThis.React=tG;let n=t.platform||QH(),i=t.projectConfig?{...n,...t.projectConfig}:n,r=new Ih({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":fx,tscircuit:fx,"@tscircuit/math-utils":o4,react:tG,debug:aM.default,"@tscircuit/props":{}},circuit:r,tsConfig:null,...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 eG(e){let t={};for(let[n,i]of Object.entries(e))t[xc(n)]=i;return t}function ko(e){if(!e)return".";let n=e.replace(/\\/g,"/").replace(/\/+$/,"");return n.indexOf("/")===-1?".":n.substring(0,n.lastIndexOf("/"))||"/"}function vx(e,t){if(e.startsWith("../")){let n=ko(t);return vx(e.slice(3),n)}return e.startsWith("./")?vx(e.slice(2),t):e.startsWith("/")?e.slice(1):`${t}/${e}`}function hm(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 nG(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=cM({importPath:t,normalizedFilePathMap:n,extensions:i,tsConfig:r});return c||null}function cM(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 iG(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 dm=(e,t,n,i={})=>{let r=n?vx(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=nG({importPath:e,normalizedFilePathMap:s,extensions:c,tsConfig:l});if(u)return u;let h=cM({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},wx=(e,t,n,i={})=>{let r=dm(e,t,n,i);if(!r)throw new Error(`File not found "${e}", available paths:
|
|
247
|
+
`)},preSuppliedImports:{"@tscircuit/core":fx,tscircuit:fx,"@tscircuit/math-utils":o4,react:tG,debug:aM.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 eG(e){let t={};for(let[n,i]of Object.entries(e))t[xc(n)]=i;return t}function ko(e){if(!e)return".";let n=e.replace(/\\/g,"/").replace(/\/+$/,"");return n.indexOf("/")===-1?".":n.substring(0,n.lastIndexOf("/"))||"/"}function vx(e,t){if(e.startsWith("../")){let n=ko(t);return vx(e.slice(3),n)}return e.startsWith("./")?vx(e.slice(2),t):e.startsWith("/")?e.slice(1):`${t}/${e}`}function hm(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 nG(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=cM({importPath:t,normalizedFilePathMap:n,extensions:i,tsConfig:r});return c||null}function cM(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 iG(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 dm=(e,t,n,i={})=>{let r=n?vx(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=nG({importPath:e,normalizedFilePathMap:s,extensions:c,tsConfig:l});if(u)return u;let h=cM({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},wx=(e,t,n,i={})=>{let r=dm(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 Sx=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=dm(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 = {};
|
|
@@ -385,7 +385,9 @@ ${n.map(({variableName:i,uniqueLocalName:r})=>` reactHotLoader.register(${i}, "
|
|
|
385
385
|
leaveModule(module);
|
|
386
386
|
})();`}process(){return!1}};var VMt=new Set(["break","case","catch","class","const","continue","debugger","default","delete","do","else","export","extends","finally","for","function","if","import","in","instanceof","new","return","super","switch","this","throw","try","typeof","var","void","while","with","yield","enum","implements","interface","let","package","private","protected","public","static","await","false","null","true"]);function o2(e){if(e.length===0||!ra[e.charCodeAt(0)])return!1;for(let t=1;t<e.length;t++)if(!or[e.charCodeAt(t)])return!1;return!VMt.has(e)}var qm=class extends kn{constructor(t,n,i){super(),this.rootTransformer=t,this.tokens=n,this.isImportsTransformEnabled=i}process(){return this.rootTransformer.processPossibleArrowParamEnd()||this.rootTransformer.processPossibleAsyncArrowWithTypeParams()||this.rootTransformer.processPossibleTypeRange()?!0:this.tokens.matches1(b._public)||this.tokens.matches1(b._protected)||this.tokens.matches1(b._private)||this.tokens.matches1(b._abstract)||this.tokens.matches1(b._readonly)||this.tokens.matches1(b._override)||this.tokens.matches1(b.nonNullAssertion)?(this.tokens.removeInitialToken(),!0):this.tokens.matches1(b._enum)||this.tokens.matches2(b._const,b._enum)?(this.processEnum(),!0):this.tokens.matches2(b._export,b._enum)||this.tokens.matches3(b._export,b._const,b._enum)?(this.processEnum(!0),!0):!1}processEnum(t=!1){for(this.tokens.removeInitialToken();this.tokens.matches1(b._const)||this.tokens.matches1(b._enum);)this.tokens.removeToken();let n=this.tokens.identifierName();this.tokens.removeToken(),t&&!this.isImportsTransformEnabled&&this.tokens.appendCode("export "),this.tokens.appendCode(`var ${n}; (function (${n})`),this.tokens.copyExpectedToken(b.braceL),this.processEnumBody(n),this.tokens.copyExpectedToken(b.braceR),t&&this.isImportsTransformEnabled?this.tokens.appendCode(`)(${n} || (exports.${n} = ${n} = {}));`):this.tokens.appendCode(`)(${n} || (${n} = {}));`)}processEnumBody(t){let n=null;for(;!this.tokens.matches1(b.braceR);){let{nameStringCode:i,variableName:r}=this.extractEnumKeyInfo(this.tokens.currentToken());this.tokens.removeInitialToken(),this.tokens.matches3(b.eq,b.string,b.comma)||this.tokens.matches3(b.eq,b.string,b.braceR)?this.processStringLiteralEnumMember(t,i,r):this.tokens.matches1(b.eq)?this.processExplicitValueEnumMember(t,i,r):this.processImplicitValueEnumMember(t,i,r,n),this.tokens.matches1(b.comma)&&this.tokens.removeToken(),r!=null?n=r:n=`${t}[${i}]`}}extractEnumKeyInfo(t){if(t.type===b.name){let n=this.tokens.identifierNameForToken(t);return{nameStringCode:`"${n}"`,variableName:o2(n)?n:null}}else if(t.type===b.string){let n=this.tokens.stringValueForToken(t);return{nameStringCode:this.tokens.code.slice(t.start,t.end),variableName:o2(n)?n:null}}else throw new Error("Expected name or string at beginning of enum element.")}processStringLiteralEnumMember(t,n,i){i!=null?(this.tokens.appendCode(`const ${i}`),this.tokens.copyToken(),this.tokens.copyToken(),this.tokens.appendCode(`; ${t}[${n}] = ${i};`)):(this.tokens.appendCode(`${t}[${n}]`),this.tokens.copyToken(),this.tokens.copyToken(),this.tokens.appendCode(";"))}processExplicitValueEnumMember(t,n,i){let r=this.tokens.currentToken().rhsEndIndex;if(r==null)throw new Error("Expected rhsEndIndex on enum assign.");if(i!=null){for(this.tokens.appendCode(`const ${i}`),this.tokens.copyToken();this.tokens.currentIndex()<r;)this.rootTransformer.processToken();this.tokens.appendCode(`; ${t}[${t}[${n}] = ${i}] = ${n};`)}else{for(this.tokens.appendCode(`${t}[${t}[${n}]`),this.tokens.copyToken();this.tokens.currentIndex()<r;)this.rootTransformer.processToken();this.tokens.appendCode(`] = ${n};`)}}processImplicitValueEnumMember(t,n,i,r){let o=r!=null?`${r} + 1`:"0";i!=null&&(this.tokens.appendCode(`const ${i} = ${o}; `),o=i),this.tokens.appendCode(`${t}[${t}[${n}] = ${o}] = ${n};`)}};var Wm=class e{__init(){this.transformers=[]}__init2(){this.generatedVariables=[]}constructor(t,n,i,r){e.prototype.__init.call(this),e.prototype.__init2.call(this),this.nameManager=t.nameManager,this.helperManager=t.helperManager;let{tokenProcessor:o,importProcessor:s}=t;this.tokens=o,this.isImportsTransformEnabled=n.includes("imports"),this.isReactHotLoaderTransformEnabled=n.includes("react-hot-loader"),this.disableESTransforms=!!r.disableESTransforms,r.disableESTransforms||(this.transformers.push(new Hm(o,this.nameManager)),this.transformers.push(new Xm(o)),this.transformers.push(new Vm(o,this.nameManager))),n.includes("jsx")&&(r.jsxRuntime!=="preserve"&&this.transformers.push(new ym(this,o,s,this.nameManager,r)),this.transformers.push(new Gm(this,o,s,r)));let a=null;if(n.includes("react-hot-loader")){if(!r.filePath)throw new Error("filePath is required when using the react-hot-loader transform.");a=new Um(o,r.filePath),this.transformers.push(a)}if(n.includes("imports")){if(s===null)throw new Error("Expected non-null importProcessor with imports transform enabled.");this.transformers.push(new $m(this,o,s,this.nameManager,this.helperManager,a,i,!!r.enableLegacyTypeScriptModuleInterop,n.includes("typescript"),n.includes("flow"),!!r.preserveDynamicImport,!!r.keepUnusedImports))}else this.transformers.push(new Bm(o,this.nameManager,this.helperManager,a,n.includes("typescript"),n.includes("flow"),!!r.keepUnusedImports,r));n.includes("flow")&&this.transformers.push(new jm(this,o,n.includes("imports"))),n.includes("typescript")&&this.transformers.push(new qm(this,o,n.includes("imports"))),n.includes("jest")&&this.transformers.push(new Ym(this,o,this.nameManager,s))}transform(){this.tokens.reset(),this.processBalancedCode();let n=this.isImportsTransformEnabled?'"use strict";':"";for(let s of this.transformers)n+=s.getPrefixCode();n+=this.helperManager.emitHelpers(),n+=this.generatedVariables.map(s=>` var ${s};`).join("");for(let s of this.transformers)n+=s.getHoistedCode();let i="";for(let s of this.transformers)i+=s.getSuffixCode();let r=this.tokens.finish(),{code:o}=r;if(o.startsWith("#!")){let s=o.indexOf(`
|
|
387
387
|
`);return s===-1&&(s=o.length,o+=`
|
|
388
|
-
`),{code:o.slice(0,s+1)+n+o.slice(s+1)+i,mappings:this.shiftMappings(r.mappings,n.length)}}else return{code:n+o+i,mappings:this.shiftMappings(r.mappings,n.length)}}processBalancedCode(){let t=0,n=0;for(;!this.tokens.isAtEnd();){if(this.tokens.matches1(b.braceL)||this.tokens.matches1(b.dollarBraceL))t++;else if(this.tokens.matches1(b.braceR)){if(t===0)return;t--}if(this.tokens.matches1(b.parenL))n++;else if(this.tokens.matches1(b.parenR)){if(n===0)return;n--}this.processToken()}}processToken(){if(this.tokens.matches1(b._class)){this.processClass();return}for(let t of this.transformers)if(t.process())return;this.tokens.copyToken()}processNamedClass(){if(!this.tokens.matches2(b._class,b.name))throw new Error("Expected identifier for exported class name.");let t=this.tokens.identifierNameAtIndex(this.tokens.currentIndex()+1);return this.processClass(),t}processClass(){let t=PC(this,this.tokens,this.nameManager,this.disableESTransforms),n=(t.headerInfo.isExpression||!t.headerInfo.className)&&t.staticInitializerNames.length+t.instanceInitializerNames.length>0,i=t.headerInfo.className;n&&(i=this.nameManager.claimFreeName("_class"),this.generatedVariables.push(i),this.tokens.appendCode(` (${i} =`));let o=this.tokens.currentToken().contextId;if(o==null)throw new Error("Expected class to have a context ID.");for(this.tokens.copyExpectedToken(b._class);!this.tokens.matchesContextIdAndLabel(b.braceL,o);)this.processToken();this.processClassBody(t,i);let s=t.staticInitializerNames.map(a=>`${i}.${a}()`);n?this.tokens.appendCode(`, ${s.map(a=>`${a}, `).join("")}${i})`):t.staticInitializerNames.length>0&&this.tokens.appendCode(` ${s.map(a=>`${a};`).join(" ")}`)}processClassBody(t,n){let{headerInfo:i,constructorInsertPos:r,constructorInitializerStatements:o,fields:s,instanceInitializerNames:a,rangesToRemove:c}=t,l=0,u=0,h=this.tokens.currentToken().contextId;if(h==null)throw new Error("Expected non-null context ID on class.");this.tokens.copyExpectedToken(b.braceL),this.isReactHotLoaderTransformEnabled&&this.tokens.appendCode("__reactstandin__regenerateByEval(key, code) {this[key] = eval(code);}");let d=o.length+a.length>0;if(r===null&&d){let _=this.makeConstructorInitCode(o,a,n);if(i.hasSuperclass){let y=this.nameManager.claimFreeName("args");this.tokens.appendCode(`constructor(...${y}) { super(...${y}); ${_}; }`)}else this.tokens.appendCode(`constructor() { ${_}; }`)}for(;!this.tokens.matchesContextIdAndLabel(b.braceR,h);)if(l<s.length&&this.tokens.currentIndex()===s[l].start){let _=!1;for(this.tokens.matches1(b.bracketL)?this.tokens.copyTokenWithPrefix(`${s[l].initializerName}() {this`):this.tokens.matches1(b.string)||this.tokens.matches1(b.num)?(this.tokens.copyTokenWithPrefix(`${s[l].initializerName}() {this[`),_=!0):this.tokens.copyTokenWithPrefix(`${s[l].initializerName}() {this.`);this.tokens.currentIndex()<s[l].end;)_&&this.tokens.currentIndex()===s[l].equalsIndex&&this.tokens.appendCode("]"),this.processToken();this.tokens.appendCode("}"),l++}else if(u<c.length&&this.tokens.currentIndex()>=c[u].start){for(this.tokens.currentIndex()<c[u].end&&this.tokens.removeInitialToken();this.tokens.currentIndex()<c[u].end;)this.tokens.removeToken();u++}else this.tokens.currentIndex()===r?(this.tokens.copyToken(),d&&this.tokens.appendCode(`;${this.makeConstructorInitCode(o,a,n)};`),this.processToken()):this.processToken();this.tokens.copyExpectedToken(b.braceR)}makeConstructorInitCode(t,n,i){return[...t,...n.map(r=>`${i}.prototype.${r}.call(this)`)].join(";")}processPossibleArrowParamEnd(){if(this.tokens.matches2(b.parenR,b.colon)&&this.tokens.tokenAtRelativeIndex(1).isType){let t=this.tokens.currentIndex()+1;for(;this.tokens.tokens[t].isType;)t++;if(this.tokens.matches1AtIndex(t,b.arrow)){for(this.tokens.removeInitialToken();this.tokens.currentIndex()<t;)this.tokens.removeToken();return this.tokens.replaceTokenTrimmingLeftWhitespace(") =>"),!0}}return!1}processPossibleAsyncArrowWithTypeParams(){if(!this.tokens.matchesContextual(tt._async)&&!this.tokens.matches1(b._async))return!1;let t=this.tokens.tokenAtRelativeIndex(1);if(t.type!==b.lessThan||!t.isType)return!1;let n=this.tokens.currentIndex()+1;for(;this.tokens.tokens[n].isType;)n++;if(this.tokens.matches1AtIndex(n,b.parenL)){for(this.tokens.replaceToken("async ("),this.tokens.removeInitialToken();this.tokens.currentIndex()<n;)this.tokens.removeToken();return this.tokens.removeToken(),this.processBalancedCode(),this.processToken(),!0}return!1}processPossibleTypeRange(){if(this.tokens.currentToken().isType){for(this.tokens.removeInitialToken();this.tokens.currentToken().isType;)this.tokens.removeToken();return!0}return!1}shiftMappings(t,n){for(let i=0;i<t.length;i++){let r=t[i];r!==void 0&&(t[i]=r+n)}return t}};var HMt=Yt(Eq());function TC(e){let t=new Set;for(let n=0;n<e.tokens.length;n++)e.matches1AtIndex(n,b._import)&&!e.matches3AtIndex(n,b._import,b.name,b.eq)&&GMt(e,n,t);return t}function GMt(e,t,n){t++,!e.matches1AtIndex(t,b.parenL)&&(e.matches1AtIndex(t,b.name)&&(n.add(e.identifierNameAtIndex(t)),t++,e.matches1AtIndex(t,b.comma)&&t++),e.matches1AtIndex(t,b.star)&&(t+=2,n.add(e.identifierNameAtIndex(t)),t++),e.matches1AtIndex(t,b.braceL)&&(t++,UMt(e,t,n)))}function UMt(e,t,n){for(;;){if(e.matches1AtIndex(t,b.braceR))return;let i=ls(e,t);if(t=i.endIndex,i.isType||n.add(i.rightName),e.matches2AtIndex(t,b.comma,b.braceR))return;if(e.matches1AtIndex(t,b.braceR))return;if(e.matches1AtIndex(t,b.comma))t++;else throw new Error(`Unexpected token: ${JSON.stringify(e.tokens[t])}`)}}function kq(e,t){qG(t);try{let n=qMt(e,t),r=new Wm(n,t.transforms,!!t.enableLegacyBabel5ModuleInterop,t).transform(),o={code:r.code};if(t.sourceMapOptions){if(!t.filePath)throw new Error("filePath must be specified when generating a source map.");o={...o,sourceMap:kM(r,t.filePath,t.sourceMapOptions,e,n.tokenProcessor.tokens)}}return o}catch(n){throw t.filePath&&(n.message=`Error transforming ${t.filePath}: ${n.message}`),n}}function qMt(e,t){let n=t.transforms.includes("jsx"),i=t.transforms.includes("typescript"),r=t.transforms.includes("flow"),o=t.disableESTransforms===!0,s=Tq(e,n,i,r),a=s.tokens,c=s.scopes,l=new xm(e,a),u=new Ax(l),h=new Om(e,a,r,o,u),d=!!t.enableLegacyTypeScriptModuleInterop,_=null;return t.transforms.includes("imports")?(_=new gm(l,h,d,t,t.transforms.includes("typescript"),!!t.keepUnusedImports,u),_.preprocessTokens(),Rx(h,c,_.getGlobalNames()),t.transforms.includes("typescript")&&!t.keepUnusedImports&&_.pruneTypeOnlyImports()):t.transforms.includes("typescript")&&!t.keepUnusedImports&&Rx(h,c,TC(h)),{tokenProcessor:h,scopes:c,nameManager:l,importProcessor:_,helperManager:u}}var WMt=new Set([".ts",".tsx",".mts",".cts"]),ZMt=new Set([".tsx",".jsx",".ts"]),KMt=e=>{let t=e.indexOf("?"),n=e.indexOf("#"),i=e.length;return t!==-1&&n!==-1?i=Math.min(t,n):t!==-1?i=t:n!==-1&&(i=n),e.slice(0,i)},JMt=e=>{let t=KMt(e),n=t.lastIndexOf(".");return n===-1||Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"))>n?"":t.slice(n).toLowerCase()},QMt=e=>{let t=JMt(e),n=["imports"];return WMt.has(t)&&n.unshift("typescript"),ZMt.has(t)&&n.push("jsx"),n},Km=(e,t)=>{let n=QMt(t),{code:i}=kq(e,{filePath:t,production:!0,transforms:n});return i};var jh=(0,Nq.default)("tsci:eval:import-local-file"),a2=async(e,t,n=0)=>{jh("importLocalFile called with:",{importName:e});let{fsMap:i,preSuppliedImports:r}=t,o=wx(e,i,void 0,{tsConfig:t.tsConfig});if(jh("fsPath:",o),!t.fsMap[o])throw jh("fsPath not found in fsMap:",o),new Error(`File "${o}" not found`);let s=i[o];if(jh("fileContent:",s?.slice(0,100)),o.endsWith(".json")){let a=JSON.parse(s);r[o]={__esModule:!0,default:a}}else if(rG(o)){let c=`${t.circuit.platform?.projectBaseUrl??""}/${o.startsWith("./")?o.slice(2):o}`;r[o]={__esModule:!0,default:c}}else if(o.endsWith(".tsx")||o.endsWith(".ts")){let a=Sx(s);for(let c of a)r[c]||await su(c,t,n+1,{cwd:ko(o)});try{let c=Km(s,o);jh("evalCompiledJs called with:",{code:c.slice(0,100),dirname:ko(o)});let l=Ql(c,r,ko(o));jh("importRunResult:",{fsPath:o,importRunResult:l}),r[o]=l.exports}catch(c){throw new Error(`Eval compiled js error for "${e}": ${c.message}`)}}else if(o.endsWith(".js"))r[o]=Ql(Km(s,o),r,ko(o)).exports;else throw new Error(`Unsupported file extension "${o.split(".").pop()}" for "${o}"`)};async function Aq(e,t,n=0){let{preSuppliedImports:i}=t,r=e.replace("@tsci/","").replace(".","/"),{cjs:o,error:s}=await globalThis.fetch(`${t.cjsRegistryUrl}/${r}`).then(async a=>({cjs:await a.text(),error:null})).catch(a=>({error:a,cjs:null}));if(s){console.error("Error fetching import",e,s);return}try{i[e]=Ql(o,i).exports}catch(a){console.error("Error importing snippet",a)}}function tCt(e,t,n){return{fsMap:t,extensions:[".js",".jsx",".ts",".tsx",".json"],basePath:n,modulePath:e}}function eCt(e,t){let n=`${e}/package.json`;if(!t.fsMap[n])return null;try{return JSON.parse(t.fsMap[n])}catch{return null}}function MC(e,t){if(t.fsMap[e])return e;for(let n of t.extensions){let i=e.replace(/\.js$|\.jsx$/,"")+n;if(t.fsMap[i])return i}return null}function IC(e,t,n){let i=`${e}/${t.replace(/^\.\//,"")}`;return MC(i,n)}function nCt(e,t,n,i){if(!t.exports)return null;let r=t.exports["."];if(n===""&&r&&typeof r=="string"){let a=IC(e,r,i);if(a)return a}let o=n?t.exports[`./${n}`]:null;if(o&&typeof o=="string"){let a=IC(e,o,i);if(a)return a}let s=t.exports.import;if(n===""&&s&&typeof s=="string"){let a=IC(e,s,i);if(a)return a}return null}function iCt(e,t,n){let i=t.module||t.main||"index.js",r=`${e}/${i}`;return MC(r,n)}function rCt(e,t,n){if(!t){for(let o of n.extensions){let s=`${e}/index${o}`;if(n.fsMap[s])return s}return null}let i=`${e}/${t}`,r=MC(i,n);if(r)return r;for(let o of n.extensions){let s=`${i}/index${o}`;if(n.fsMap[s])return s}return null}function Rq(e,t){let n=t.modulePath.split("/"),i=n[0].startsWith("@")?n.slice(0,2).join("/"):n[0],r=n.slice(i.includes("/")?2:1).join("/"),o=`${e=="."?"":`${e}/`}node_modules/${i}`,s=eCt(o,t);if(s){let l=nCt(o,s,r,t);if(l)return l;let u=iCt(o,s,t);if(u)return u}let a=rCt(o,r,t);if(a)return a;let c=ko(e);return c&&c!==e?Rq(c,t):null}function c2(e,t,n){let i=tCt(e,t,n);return Rq(i.basePath,i)}var Oq=async(e,t,n=0)=>{let{preSuppliedImports:i}=t;if(i[e])return;let r=c2(e,t.fsMap,"");if(!r)throw new Error(`Node module "${e}" not found`);await a2(r,t,n),i[e]=i[r];let o=r.replace(/^node_modules\//,"");if(i[o]=i[r],r.endsWith("/index.tsx")||r.endsWith("/index.ts")||r.endsWith("/index.js")){let a=r.replace(/\/index\.(tsx?|js)$/,"").replace(/^node_modules\//,"");if(i[a]=i[r],a.startsWith("@")){let c=a.split("/");if(c.length>=2){let l=`${c[0]}/${c[1]}`;i[l]=i[r]}}}};var Lq=Yt(Mn(),1);var oCt=(0,Lq.default)("tsci:eval:import-npm-package");function sCt(e){let t="https://cdn.jsdelivr.net/npm/";return e.startsWith(t)?e.substring(t.length).replace(/\/\+esm$/,""):e}async function CC(e,t,n=0){oCt(`importing npm package: ${e}`);let{preSuppliedImports:i}=t;if(i[e])return;let r=`https://cdn.jsdelivr.net/npm/${e}/+esm`,o,{content:s,error:a}=await globalThis.fetch(r).then(async d=>{if(o=d.url,!d.ok)throw new Error(`Could not fetch "${e}" from jsdelivr: ${d.statusText}
|
|
388
|
+
`),{code:o.slice(0,s+1)+n+o.slice(s+1)+i,mappings:this.shiftMappings(r.mappings,n.length)}}else return{code:n+o+i,mappings:this.shiftMappings(r.mappings,n.length)}}processBalancedCode(){let t=0,n=0;for(;!this.tokens.isAtEnd();){if(this.tokens.matches1(b.braceL)||this.tokens.matches1(b.dollarBraceL))t++;else if(this.tokens.matches1(b.braceR)){if(t===0)return;t--}if(this.tokens.matches1(b.parenL))n++;else if(this.tokens.matches1(b.parenR)){if(n===0)return;n--}this.processToken()}}processToken(){if(this.tokens.matches1(b._class)){this.processClass();return}for(let t of this.transformers)if(t.process())return;this.tokens.copyToken()}processNamedClass(){if(!this.tokens.matches2(b._class,b.name))throw new Error("Expected identifier for exported class name.");let t=this.tokens.identifierNameAtIndex(this.tokens.currentIndex()+1);return this.processClass(),t}processClass(){let t=PC(this,this.tokens,this.nameManager,this.disableESTransforms),n=(t.headerInfo.isExpression||!t.headerInfo.className)&&t.staticInitializerNames.length+t.instanceInitializerNames.length>0,i=t.headerInfo.className;n&&(i=this.nameManager.claimFreeName("_class"),this.generatedVariables.push(i),this.tokens.appendCode(` (${i} =`));let o=this.tokens.currentToken().contextId;if(o==null)throw new Error("Expected class to have a context ID.");for(this.tokens.copyExpectedToken(b._class);!this.tokens.matchesContextIdAndLabel(b.braceL,o);)this.processToken();this.processClassBody(t,i);let s=t.staticInitializerNames.map(a=>`${i}.${a}()`);n?this.tokens.appendCode(`, ${s.map(a=>`${a}, `).join("")}${i})`):t.staticInitializerNames.length>0&&this.tokens.appendCode(` ${s.map(a=>`${a};`).join(" ")}`)}processClassBody(t,n){let{headerInfo:i,constructorInsertPos:r,constructorInitializerStatements:o,fields:s,instanceInitializerNames:a,rangesToRemove:c}=t,l=0,u=0,h=this.tokens.currentToken().contextId;if(h==null)throw new Error("Expected non-null context ID on class.");this.tokens.copyExpectedToken(b.braceL),this.isReactHotLoaderTransformEnabled&&this.tokens.appendCode("__reactstandin__regenerateByEval(key, code) {this[key] = eval(code);}");let d=o.length+a.length>0;if(r===null&&d){let _=this.makeConstructorInitCode(o,a,n);if(i.hasSuperclass){let y=this.nameManager.claimFreeName("args");this.tokens.appendCode(`constructor(...${y}) { super(...${y}); ${_}; }`)}else this.tokens.appendCode(`constructor() { ${_}; }`)}for(;!this.tokens.matchesContextIdAndLabel(b.braceR,h);)if(l<s.length&&this.tokens.currentIndex()===s[l].start){let _=!1;for(this.tokens.matches1(b.bracketL)?this.tokens.copyTokenWithPrefix(`${s[l].initializerName}() {this`):this.tokens.matches1(b.string)||this.tokens.matches1(b.num)?(this.tokens.copyTokenWithPrefix(`${s[l].initializerName}() {this[`),_=!0):this.tokens.copyTokenWithPrefix(`${s[l].initializerName}() {this.`);this.tokens.currentIndex()<s[l].end;)_&&this.tokens.currentIndex()===s[l].equalsIndex&&this.tokens.appendCode("]"),this.processToken();this.tokens.appendCode("}"),l++}else if(u<c.length&&this.tokens.currentIndex()>=c[u].start){for(this.tokens.currentIndex()<c[u].end&&this.tokens.removeInitialToken();this.tokens.currentIndex()<c[u].end;)this.tokens.removeToken();u++}else this.tokens.currentIndex()===r?(this.tokens.copyToken(),d&&this.tokens.appendCode(`;${this.makeConstructorInitCode(o,a,n)};`),this.processToken()):this.processToken();this.tokens.copyExpectedToken(b.braceR)}makeConstructorInitCode(t,n,i){return[...t,...n.map(r=>`${i}.prototype.${r}.call(this)`)].join(";")}processPossibleArrowParamEnd(){if(this.tokens.matches2(b.parenR,b.colon)&&this.tokens.tokenAtRelativeIndex(1).isType){let t=this.tokens.currentIndex()+1;for(;this.tokens.tokens[t].isType;)t++;if(this.tokens.matches1AtIndex(t,b.arrow)){for(this.tokens.removeInitialToken();this.tokens.currentIndex()<t;)this.tokens.removeToken();return this.tokens.replaceTokenTrimmingLeftWhitespace(") =>"),!0}}return!1}processPossibleAsyncArrowWithTypeParams(){if(!this.tokens.matchesContextual(tt._async)&&!this.tokens.matches1(b._async))return!1;let t=this.tokens.tokenAtRelativeIndex(1);if(t.type!==b.lessThan||!t.isType)return!1;let n=this.tokens.currentIndex()+1;for(;this.tokens.tokens[n].isType;)n++;if(this.tokens.matches1AtIndex(n,b.parenL)){for(this.tokens.replaceToken("async ("),this.tokens.removeInitialToken();this.tokens.currentIndex()<n;)this.tokens.removeToken();return this.tokens.removeToken(),this.processBalancedCode(),this.processToken(),!0}return!1}processPossibleTypeRange(){if(this.tokens.currentToken().isType){for(this.tokens.removeInitialToken();this.tokens.currentToken().isType;)this.tokens.removeToken();return!0}return!1}shiftMappings(t,n){for(let i=0;i<t.length;i++){let r=t[i];r!==void 0&&(t[i]=r+n)}return t}};var HMt=Yt(Eq());function TC(e){let t=new Set;for(let n=0;n<e.tokens.length;n++)e.matches1AtIndex(n,b._import)&&!e.matches3AtIndex(n,b._import,b.name,b.eq)&&GMt(e,n,t);return t}function GMt(e,t,n){t++,!e.matches1AtIndex(t,b.parenL)&&(e.matches1AtIndex(t,b.name)&&(n.add(e.identifierNameAtIndex(t)),t++,e.matches1AtIndex(t,b.comma)&&t++),e.matches1AtIndex(t,b.star)&&(t+=2,n.add(e.identifierNameAtIndex(t)),t++),e.matches1AtIndex(t,b.braceL)&&(t++,UMt(e,t,n)))}function UMt(e,t,n){for(;;){if(e.matches1AtIndex(t,b.braceR))return;let i=ls(e,t);if(t=i.endIndex,i.isType||n.add(i.rightName),e.matches2AtIndex(t,b.comma,b.braceR))return;if(e.matches1AtIndex(t,b.braceR))return;if(e.matches1AtIndex(t,b.comma))t++;else throw new Error(`Unexpected token: ${JSON.stringify(e.tokens[t])}`)}}function kq(e,t){qG(t);try{let n=qMt(e,t),r=new Wm(n,t.transforms,!!t.enableLegacyBabel5ModuleInterop,t).transform(),o={code:r.code};if(t.sourceMapOptions){if(!t.filePath)throw new Error("filePath must be specified when generating a source map.");o={...o,sourceMap:kM(r,t.filePath,t.sourceMapOptions,e,n.tokenProcessor.tokens)}}return o}catch(n){throw t.filePath&&(n.message=`Error transforming ${t.filePath}: ${n.message}`),n}}function qMt(e,t){let n=t.transforms.includes("jsx"),i=t.transforms.includes("typescript"),r=t.transforms.includes("flow"),o=t.disableESTransforms===!0,s=Tq(e,n,i,r),a=s.tokens,c=s.scopes,l=new xm(e,a),u=new Ax(l),h=new Om(e,a,r,o,u),d=!!t.enableLegacyTypeScriptModuleInterop,_=null;return t.transforms.includes("imports")?(_=new gm(l,h,d,t,t.transforms.includes("typescript"),!!t.keepUnusedImports,u),_.preprocessTokens(),Rx(h,c,_.getGlobalNames()),t.transforms.includes("typescript")&&!t.keepUnusedImports&&_.pruneTypeOnlyImports()):t.transforms.includes("typescript")&&!t.keepUnusedImports&&Rx(h,c,TC(h)),{tokenProcessor:h,scopes:c,nameManager:l,importProcessor:_,helperManager:u}}var WMt=new Set([".ts",".tsx",".mts",".cts"]),ZMt=new Set([".tsx",".jsx",".ts"]),KMt=e=>{let t=e.indexOf("?"),n=e.indexOf("#"),i=e.length;return t!==-1&&n!==-1?i=Math.min(t,n):t!==-1?i=t:n!==-1&&(i=n),e.slice(0,i)},JMt=e=>{let t=KMt(e),n=t.lastIndexOf(".");return n===-1||Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"))>n?"":t.slice(n).toLowerCase()},QMt=e=>{let t=JMt(e),n=["imports"];return WMt.has(t)&&n.unshift("typescript"),ZMt.has(t)&&n.push("jsx"),n},Km=(e,t)=>{let n=QMt(t),{code:i}=kq(e,{filePath:t,production:!0,transforms:n});return i};var jh=(0,Nq.default)("tsci:eval:import-local-file"),a2=async(e,t,n=0)=>{jh("importLocalFile called with:",{importName:e});let{fsMap:i,preSuppliedImports:r,importStack:o,currentlyImporting:s}=t,a=wx(e,i,void 0,{tsConfig:t.tsConfig});if(jh("fsPath:",a),s.has(a)){let l=o.indexOf(a),u=l>=0?o.slice(l).concat(a):[...o,a];throw new Error(`Circular dependency detected while importing "${a}". The following import chain forms a cycle:
|
|
389
|
+
|
|
390
|
+
${u.join(" -> ")}`)}if(!t.fsMap[a])throw jh("fsPath not found in fsMap:",a),new Error(`File "${a}" not found`);let c=i[a];jh("fileContent:",c?.slice(0,100)),s.add(a),o.push(a);try{if(a.endsWith(".json")){let l=JSON.parse(c);r[a]={__esModule:!0,default:l}}else if(rG(a)){let u=`${t.circuit.platform?.projectBaseUrl??""}/${a.startsWith("./")?a.slice(2):a}`;r[a]={__esModule:!0,default:u}}else if(a.endsWith(".tsx")||a.endsWith(".ts")){let l=Sx(c);for(let u of l)r[u]||await su(u,t,n+1,{cwd:ko(a)});try{let u=Km(c,a);jh("evalCompiledJs called with:",{code:u.slice(0,100),dirname:ko(a)});let h=Ql(u,r,ko(a));jh("importRunResult:",{fsPath:a,importRunResult:h}),r[a]=h.exports}catch(u){throw new Error(`Eval compiled js error for "${e}": ${u.message}`)}}else if(a.endsWith(".js"))r[a]=Ql(Km(c,a),r,ko(a)).exports;else throw new Error(`Unsupported file extension "${a.split(".").pop()}" for "${a}"`)}finally{o.pop(),s.delete(a)}};async function Aq(e,t,n=0){let{preSuppliedImports:i}=t,r=e.replace("@tsci/","").replace(".","/"),{cjs:o,error:s}=await globalThis.fetch(`${t.cjsRegistryUrl}/${r}`).then(async a=>({cjs:await a.text(),error:null})).catch(a=>({error:a,cjs:null}));if(s){console.error("Error fetching import",e,s);return}try{i[e]=Ql(o,i).exports}catch(a){console.error("Error importing snippet",a)}}function tCt(e,t,n){return{fsMap:t,extensions:[".js",".jsx",".ts",".tsx",".json"],basePath:n,modulePath:e}}function eCt(e,t){let n=`${e}/package.json`;if(!t.fsMap[n])return null;try{return JSON.parse(t.fsMap[n])}catch{return null}}function MC(e,t){if(t.fsMap[e])return e;for(let n of t.extensions){let i=e.replace(/\.js$|\.jsx$/,"")+n;if(t.fsMap[i])return i}return null}function IC(e,t,n){let i=`${e}/${t.replace(/^\.\//,"")}`;return MC(i,n)}function nCt(e,t,n,i){if(!t.exports)return null;let r=t.exports["."];if(n===""&&r&&typeof r=="string"){let a=IC(e,r,i);if(a)return a}let o=n?t.exports[`./${n}`]:null;if(o&&typeof o=="string"){let a=IC(e,o,i);if(a)return a}let s=t.exports.import;if(n===""&&s&&typeof s=="string"){let a=IC(e,s,i);if(a)return a}return null}function iCt(e,t,n){let i=t.module||t.main||"index.js",r=`${e}/${i}`;return MC(r,n)}function rCt(e,t,n){if(!t){for(let o of n.extensions){let s=`${e}/index${o}`;if(n.fsMap[s])return s}return null}let i=`${e}/${t}`,r=MC(i,n);if(r)return r;for(let o of n.extensions){let s=`${i}/index${o}`;if(n.fsMap[s])return s}return null}function Rq(e,t){let n=t.modulePath.split("/"),i=n[0].startsWith("@")?n.slice(0,2).join("/"):n[0],r=n.slice(i.includes("/")?2:1).join("/"),o=`${e=="."?"":`${e}/`}node_modules/${i}`,s=eCt(o,t);if(s){let l=nCt(o,s,r,t);if(l)return l;let u=iCt(o,s,t);if(u)return u}let a=rCt(o,r,t);if(a)return a;let c=ko(e);return c&&c!==e?Rq(c,t):null}function c2(e,t,n){let i=tCt(e,t,n);return Rq(i.basePath,i)}var Oq=async(e,t,n=0)=>{let{preSuppliedImports:i}=t;if(i[e])return;let r=c2(e,t.fsMap,"");if(!r)throw new Error(`Node module "${e}" not found`);await a2(r,t,n),i[e]=i[r];let o=r.replace(/^node_modules\//,"");if(i[o]=i[r],r.endsWith("/index.tsx")||r.endsWith("/index.ts")||r.endsWith("/index.js")){let a=r.replace(/\/index\.(tsx?|js)$/,"").replace(/^node_modules\//,"");if(i[a]=i[r],a.startsWith("@")){let c=a.split("/");if(c.length>=2){let l=`${c[0]}/${c[1]}`;i[l]=i[r]}}}};var Lq=Yt(Mn(),1);var oCt=(0,Lq.default)("tsci:eval:import-npm-package");function sCt(e){let t="https://cdn.jsdelivr.net/npm/";return e.startsWith(t)?e.substring(t.length).replace(/\/\+esm$/,""):e}async function CC(e,t,n=0){oCt(`importing npm package: ${e}`);let{preSuppliedImports:i}=t;if(i[e])return;let r=`https://cdn.jsdelivr.net/npm/${e}/+esm`,o,{content:s,error:a}=await globalThis.fetch(r).then(async d=>{if(o=d.url,!d.ok)throw new Error(`Could not fetch "${e}" from jsdelivr: ${d.statusText}
|
|
389
391
|
|
|
390
392
|
${t.logger.stringifyLogs()}`);return{content:await d.text(),error:null}}).catch(d=>({error:d,content:null}));if(a)throw console.error("Error fetching npm import",e,a),a;let c=sCt(o),l=ko(c),u=Sx(s);for(let d of u)i[d]||await su(d,t,n+1,{cwd:l});let h=Km(s,c||e);try{let d=Ql(h,i,l).exports;i[e]=d,i[c]=d,i[o]=d}catch(d){throw new Error(`Eval npm package error for "${e}": ${d.message}
|
|
391
393
|
|
package/package.json
CHANGED
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
"main": "dist/index.js",
|
|
4
4
|
"types": "dist/index.d.ts",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.779-libonly",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/tscircuit/tscircuit"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"dist",
|
|
13
|
-
"cli.mjs",
|
|
14
13
|
"globals.d.ts"
|
|
15
14
|
],
|
|
16
15
|
"scripts": {
|
|
@@ -29,10 +28,6 @@
|
|
|
29
28
|
},
|
|
30
29
|
"./browser": "./dist/browser.min.js"
|
|
31
30
|
},
|
|
32
|
-
"bin": {
|
|
33
|
-
"tsci": "cli.mjs",
|
|
34
|
-
"tscircuit": "cli.mjs"
|
|
35
|
-
},
|
|
36
31
|
"devDependencies": {
|
|
37
32
|
"@types/bun": "^1.2.16",
|
|
38
33
|
"esbuild": "^0.20.2",
|
|
@@ -49,16 +44,15 @@
|
|
|
49
44
|
"@tscircuit/checks": "^0.0.85",
|
|
50
45
|
"@tscircuit/circuit-json-flex": "^0.0.3",
|
|
51
46
|
"@tscircuit/circuit-json-util": "^0.0.72",
|
|
52
|
-
"@tscircuit/
|
|
53
|
-
"@tscircuit/
|
|
54
|
-
"@tscircuit/eval": "^0.0.401",
|
|
47
|
+
"@tscircuit/core": "^0.0.794",
|
|
48
|
+
"@tscircuit/eval": "^0.0.402",
|
|
55
49
|
"@tscircuit/footprinter": "^0.0.236",
|
|
56
50
|
"@tscircuit/infgrid-ijump-astar": "^0.0.33",
|
|
57
51
|
"@tscircuit/matchpack": "^0.0.16",
|
|
58
52
|
"@tscircuit/math-utils": "^0.0.21",
|
|
59
53
|
"@tscircuit/miniflex": "^0.0.4",
|
|
60
54
|
"@tscircuit/props": "0.0.363",
|
|
61
|
-
"@tscircuit/runframe": "^0.0.
|
|
55
|
+
"@tscircuit/runframe": "^0.0.1116",
|
|
62
56
|
"@tscircuit/schematic-match-adapt": "^0.0.16",
|
|
63
57
|
"@tscircuit/schematic-trace-solver": "^0.0.41",
|
|
64
58
|
"@tscircuit/simple-3d-svg": "^0.0.41",
|
|
@@ -93,4 +87,4 @@
|
|
|
93
87
|
"transformation-matrix": "^2.16.1",
|
|
94
88
|
"zod": "^3.25.67"
|
|
95
89
|
}
|
|
96
|
-
}
|
|
90
|
+
}
|
package/cli.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
|
-
import { createRequire } from "node:module";
|
|
4
|
-
const require = createRequire(import.meta.url);
|
|
5
|
-
|
|
6
|
-
// Use require to import package.json
|
|
7
|
-
const packageJson = require("./package.json");
|
|
8
|
-
global.TSCIRCUIT_VERSION = packageJson.version;
|
|
9
|
-
|
|
10
|
-
async function main() {
|
|
11
|
-
await import("@tscircuit/cli");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
main();
|