@tscircuit/runframe 0.0.1763 → 0.0.1764
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.
|
@@ -1796,7 +1796,7 @@ var package_default = {
|
|
|
1796
1796
|
"chokidar-cli": "^3.0.0",
|
|
1797
1797
|
"circuit-json-to-bom-csv": "^0.0.8",
|
|
1798
1798
|
"circuit-json-to-gerber": "^0.0.48",
|
|
1799
|
-
"circuit-json-to-kicad": "^0.0.
|
|
1799
|
+
"circuit-json-to-kicad": "^0.0.91",
|
|
1800
1800
|
"circuit-json-to-lbrn": "^0.0.4",
|
|
1801
1801
|
"circuit-json-to-pnp-csv": "^0.0.7",
|
|
1802
1802
|
"circuit-json-to-step": "^0.0.18",
|
package/dist/preview.js
CHANGED
package/dist/runner.js
CHANGED
|
@@ -5826,7 +5826,7 @@ ${a.join(`
|
|
|
5826
5826
|
`)}};LA.register(GCi);var ift=class ASA extends LA{static token="locked";static parentToken="group";token="locked";value;constructor(A){super(),this.value=A}static fromSexprPrimitives(A){if(A.length===0)return new ASA(!0);const t=Di(A[0]);return new ASA(t==="yes")}getString(){return this.value?"(locked yes)":"(locked no)"}};LA.register(ift);var nft=class cxt extends LA{static token="members";static parentToken="group";token="members";members;constructor(A){super(),this.members=A}static fromSexprPrimitives(A){const t=[];for(const i of A){const n=Di(i);n&&t.push(n)}return new cxt(t)}getString(){return this.members.length===0?"(members)":`(members ${this.members.map(t=>`"${t}"`).join(" ")})`}};LA.register(nft);var S1A=class Ixt extends LA{static token="end";static parentToken="segment";token="end";_x;_y;constructor(A,t){super(),this._x=A,this._y=t}static fromSexprPrimitives(A){const[t,i]=A,n=Ci(t),o=Ci(i);if(n===void 0||o===void 0)throw new Error("end expects two numeric arguments");return new Ixt(n,o)}get x(){return this._x}set x(A){this._x=A}get y(){return this._y}set y(A){this._y=A}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(end ${this._x} ${this._y})`}};LA.register(S1A);var RCi=new Set(["true","yes","1"]),oft=class Hz extends Wl{static token="locked";static parentToken="segment";token="locked";constructor(A){super(A)}static fromSexprPrimitives(A){const[t]=A;return typeof t=="boolean"?new Hz(t):typeof t=="string"?new Hz(RCi.has(t.toLowerCase())):new Hz(!1)}getString(){return`(locked ${this.value?"yes":"no"})`}};LA.register(oft);var rj=class lxt extends LA{static token="net";static parentToken="segment";token="net";_id;_name;constructor(A,t){super(),this._id=A,this._name=t}static fromSexprPrimitives(A){const[t,i]=A,n=Ci(t);if(n===void 0)throw new Error("net expects a numeric identifier");const o=i===void 0?void 0:Di(i);return new lxt(n,o??void 0)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A===""?void 0:A}toObject(){return this._name===void 0?{id:this._id}:{id:this._id,name:this._name}}getChildren(){return[]}getString(){const A=this._name?` ${mn(this._name)}`:"";return`(net ${this._id}${A})`}};LA.register(rj);var b1A=class Bxt extends LA{static token="start";static parentToken="segment";token="start";_x;_y;constructor(A,t){super(),this._x=A,this._y=t}static fromSexprPrimitives(A){const[t,i]=A,n=Ci(t),o=Ci(i);if(n===void 0||o===void 0)throw new Error("start expects two numeric arguments");return new Bxt(n,o)}get x(){return this._x}set x(A){this._x=A}get y(){return this._y}set y(A){this._y=A}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(start ${this._x} ${this._y})`}};LA.register(b1A);var sft=new Set(["start","end","width","layer","net","tstamp","uuid","locked"]),_1A=class Cxt extends LA{static token="segment";token="segment";_sxStart;_sxEnd;_sxWidth;_sxLayer;_sxNet;_sxTstamp;_sxUuid;_sxLocked;constructor(A={}){super(),A.start!==void 0&&(this.start=A.start),A.end!==void 0&&(this.end=A.end),A.width!==void 0&&(this.width=A.width),A.layer!==void 0&&(this.layer=A.layer),A.net!==void 0&&(this.net=A.net),A.tstamp!==void 0&&(this.tstamp=A.tstamp),A.uuid!==void 0&&(this.uuid=A.uuid),A.locked!==void 0&&(this.locked=A.locked)}static fromSexprPrimitives(A){const t=new Cxt,{propertyMap:i,arrayPropertyMap:n}=LA.parsePrimitivesToClassProperties(A,this.token),o=Object.keys(i).filter(r=>!sft.has(r));if(o.length>0)throw new Error(`Unsupported child tokens inside segment expression: ${o.join(", ")}`);for(const[r,a]of Object.entries(n)){if(!sft.has(r))throw new Error(`Unsupported child tokens inside segment expression: ${r}`);if(a.length>1)throw new Error(`Segment does not support repeated child tokens: ${r}`)}t._sxStart=n.start?.[0]??i.start,t._sxEnd=n.end?.[0]??i.end,t._sxWidth=n.width?.[0]??i.width,t._sxLayer=n.layer?.[0]??i.layer,t._sxNet=n.net?.[0]??i.net;const s=n.locked?.[0]??i.locked;return t._sxLocked=s&&s.value?s:void 0,t._sxTstamp=n.tstamp?.[0]??i.tstamp,t._sxUuid=n.uuid?.[0]??i.uuid,t}get start(){return this._sxStart}set start(A){this._sxStart=this.normalizeStart(A)}get end(){return this._sxEnd}set end(A){this._sxEnd=this.normalizeEnd(A)}get startPoint(){return this._sxStart?.toObject()}get endPoint(){return this._sxEnd?.toObject()}get width(){return this._sxWidth?.value}set width(A){if(A===void 0){this._sxWidth=void 0;return}this._sxWidth=A instanceof Jr?A:new Jr(A)}get widthClass(){return this._sxWidth}set widthClass(A){this._sxWidth=A}get layer(){return this._sxLayer}set layer(A){if(A===void 0){this._sxLayer=void 0;return}if(A instanceof kr){this._sxLayer=A;return}const t=Array.isArray(A)?A:[A];this._sxLayer=new kr(t)}get net(){return this._sxNet}set net(A){if(A===void 0){this._sxNet=void 0;return}if(A instanceof rj){this._sxNet=A;return}this._sxNet=new rj(A.id,A.name)}get tstamp(){return this._sxTstamp}set tstamp(A){if(A===void 0){this._sxTstamp=void 0;return}this._sxTstamp=A instanceof sc?A:new sc(A)}get uuid(){return this._sxUuid}set uuid(A){if(A===void 0){this._sxUuid=void 0;return}this._sxUuid=A instanceof qi?A:new qi(A)}get locked(){return this._sxLocked?.value??!1}set locked(A){this._sxLocked=A?new oft(!0):void 0}getChildren(){const A=[];return this._sxStart&&A.push(this._sxStart),this._sxEnd&&A.push(this._sxEnd),this._sxWidth&&A.push(this._sxWidth),this._sxLayer&&A.push(this._sxLayer),this._sxNet&&A.push(this._sxNet),this._sxLocked&&A.push(this._sxLocked),this._sxTstamp&&A.push(this._sxTstamp),this._sxUuid&&A.push(this._sxUuid),A}normalizeStart(A){if(A!==void 0)return A instanceof b1A?A:new b1A(A.x,A.y)}normalizeEnd(A){if(A!==void 0)return A instanceof S1A?A:new S1A(A.x,A.y)}};LA.register(_1A);var rft=class Qxt extends LA{static token="zone";token="zone";_rawChildren=[];static fromSexprPrimitives(A){const t=new Qxt;return t._rawChildren=[...A],t}get rawChildren(){return[...this._rawChildren]}set rawChildren(A){this._rawChildren=[...A]}getChildren(){return[]}getString(){const A=["(zone"];for(const t of this._rawChildren)A.push(` ${A0(t)}`);return A.push(")"),A.join(`
|
|
5827
5827
|
`)}};LA.register(rft);var aj=class hxt extends LA{static token="layers";token="layers";_names=[];constructor(A=[]){super(),this.names=A}static fromSexprPrimitives(A){const t=A.map(i=>typeof i=="string"||typeof i=="number"?String(i):A0(i));return new hxt(t)}get names(){return[...this._names]}set names(A){this._names=A.map(t=>String(t))}getString(){return`(layers ${this._names.map(t=>/^[^\s()"]+$/u.test(t)&&!["nil","#t","#f"].includes(t)?t:mn(t)).join(" ")})`}};LA.register(aj);var B6=class extends LA{_value;quoteStringValue=!1;constructor(e){super(),this._value=e}static fromSexprPrimitives(e){const[A]=e,t=this.parsePrimitiveValue(A),i=this;return new i(t)}static parsePrimitiveValue(e){const A=Di(e);if(A===void 0)throw new Error(`${this.name} expects a primitive value`);return A}get value(){return this._value}set value(e){this._value=e}getChildren(){return[]}formatValue(){return typeof this._value=="string"?this.quoteStringValue?mn(this._value):this._value:`${this._value}`}getString(){return`(${this.token} ${this.formatValue()})`}},NCi=class extends LA{_values;constructor(e){super(),this._values=e}static fromSexprPrimitives(e){const A=e.map(i=>{const n=Ci(i);if(n===void 0)throw new Error(`${this.name} expects numeric primitives but received ${i}`);return n}),t=this;return new t(A)}get values(){return[...this._values]}set values(e){this._values=[...e]}getChildren(){return[]}getString(){return`(${this.token} ${this._values.join(" ")})`}},LCi=class extends LA{_x;_y;constructor(e,A){super(),this._x=e,this._y=A}static fromSexprPrimitives(e){const[A,t]=e,i=Ci(A),n=Ci(t);if(i===void 0||n===void 0)throw new Error(`${this.name} expects two numeric values`);const o=this;return new o(i,n)}get x(){return this._x}set x(e){this._x=e}get y(){return this._y}set y(e){this._y=e}getChildren(){return[]}getString(){return`(${this.token} ${this._x} ${this._y})`}},vr=class extends B6{static parentToken="pcbplotparams"},Sm=class extends vr{static parsePrimitiveValue(e){const A=Ci(e);if(A===void 0)throw new Error(`pcbplotparams ${this.token} expects a numeric value`);return A}},aft=class extends vr{static token="layerselection";token="layerselection"};LA.register(aft);var gft=class extends vr{static token="plot_on_all_layers_selection";token="plot_on_all_layers_selection"};LA.register(gft);var cft=class extends Sm{static token="dashed_line_dash_ratio";token="dashed_line_dash_ratio"};LA.register(cft);var Ift=class extends Sm{static token="dashed_line_gap_ratio";token="dashed_line_gap_ratio"};LA.register(Ift);var lft=class extends Sm{static token="svgprecision";token="svgprecision"};LA.register(lft);var Bft=class extends Sm{static token="linewidth";token="linewidth"};LA.register(Bft);var Cft=class extends Sm{static token="mode";token="mode"};LA.register(Cft);var Qft=class extends Sm{static token="hpglpennumber";token="hpglpennumber"};LA.register(Qft);var hft=class extends Sm{static token="hpglpenspeed";token="hpglpenspeed"};LA.register(hft);var Eft=class extends Sm{static token="hpglpendiameter";token="hpglpendiameter"};LA.register(Eft);var uft=class extends Sm{static token="hpglpenoverlay";token="hpglpenoverlay"};LA.register(uft);var dft=class extends Sm{static token="outputformat";token="outputformat"};LA.register(dft);var pft=class extends Sm{static token="drillshape";token="drillshape"};LA.register(pft);var fft=class extends Sm{static token="scaleselection";token="scaleselection"};LA.register(fft);var yft=class extends vr{static token="disableapertmacros";token="disableapertmacros"};LA.register(yft);var mft=class extends vr{static token="usegerberextensions";token="usegerberextensions"};LA.register(mft);var wft=class extends vr{static token="usegerberattributes";token="usegerberattributes"};LA.register(wft);var Dft=class extends vr{static token="usegerberadvancedattributes";token="usegerberadvancedattributes"};LA.register(Dft);var xft=class extends vr{static token="creategerberjobfile";token="creategerberjobfile"};LA.register(xft);var Sft=class extends vr{static token="excludeedgelayer";token="excludeedgelayer"};LA.register(Sft);var bft=class extends vr{static token="plotframeref";token="plotframeref"};LA.register(bft);var _ft=class extends vr{static token="viasonmask";token="viasonmask"};LA.register(_ft);var kft=class extends vr{static token="useauxorigin";token="useauxorigin"};LA.register(kft);var vft=class extends vr{static token="pdf_front_fp_property_popups";token="pdf_front_fp_property_popups"};LA.register(vft);var Fft=class extends vr{static token="pdf_back_fp_property_popups";token="pdf_back_fp_property_popups"};LA.register(Fft);var Mft=class extends vr{static token="pdf_metadata";token="pdf_metadata"};LA.register(Mft);var Gft=class extends vr{static token="pdf_single_document";token="pdf_single_document"};LA.register(Gft);var Rft=class extends vr{static token="dxfpolygonmode";token="dxfpolygonmode"};LA.register(Rft);var Nft=class extends vr{static token="dxfimperialunits";token="dxfimperialunits"};LA.register(Nft);var Lft=class extends vr{static token="dxfusepcbnewfont";token="dxfusepcbnewfont"};LA.register(Lft);var Uft=class extends vr{static token="psnegative";token="psnegative"};LA.register(Uft);var Hft=class extends vr{static token="psa4output";token="psa4output"};LA.register(Hft);var Yft=class extends vr{static token="plotreference";token="plotreference"};LA.register(Yft);var Jft=class extends vr{static token="plotvalue";token="plotvalue"};LA.register(Jft);var Tft=class extends vr{static token="plotothertext";token="plotothertext"};LA.register(Tft);var Pft=class extends vr{static token="plotinvisibletext";token="plotinvisibletext"};LA.register(Pft);var Kft=class extends vr{static token="padsonsilk";token="padsonsilk"};LA.register(Kft);var qft=class extends vr{static token="sketchpadsonfab";token="sketchpadsonfab"};LA.register(qft);var Oft=class extends vr{static token="plotpadnumbers";token="plotpadnumbers"};LA.register(Oft);var Wft=class extends vr{static token="hidednponfab";token="hidednponfab"};LA.register(Wft);var Zft=class extends vr{static token="sketchdnponfab";token="sketchdnponfab"};LA.register(Zft);var Vft=class extends vr{static token="crossoutdnponfab";token="crossoutdnponfab"};LA.register(Vft);var jft=class extends vr{static token="subtractmaskfromsilk";token="subtractmaskfromsilk"};LA.register(jft);var zft=class extends vr{static token="plot_black_and_white";token="plot_black_and_white"};LA.register(zft);var Xft=class extends vr{static token="mirror";token="mirror"};LA.register(Xft);var $ft=class extends vr{static token="outputdirectory";token="outputdirectory";quoteStringValue=!0};LA.register($ft);var Ayt=class extends vr{static token="plot_on_all_layers";token="plot_on_all_layers"};LA.register(Ayt);var tyt=class extends vr{static token="plotinvisible";token="plotinvisible"};LA.register(tyt);var UCi={layerselection:"layerselection",plot_on_all_layers_selection:"plot_on_all_layers_selection",disableapertmacros:"disableapertmacros",usegerberextensions:"usegerberextensions",usegerberattributes:"usegerberattributes",usegerberadvancedattributes:"usegerberadvancedattributes",creategerberjobfile:"creategerberjobfile",excludeedgelayer:"excludeedgelayer",dashed_line_dash_ratio:"dashed_line_dash_ratio",dashed_line_gap_ratio:"dashed_line_gap_ratio",svgprecision:"svgprecision",linewidth:"linewidth",plotframeref:"plotframeref",plotreference:"plotreference",plotvalue:"plotvalue",plotothertext:"plotothertext",plotinvisibletext:"plotinvisibletext",padsonsilk:"padsonsilk",sketchpadsonfab:"sketchpadsonfab",plotpadnumbers:"plotpadnumbers",hidednponfab:"hidednponfab",sketchdnponfab:"sketchdnponfab",crossoutdnponfab:"crossoutdnponfab",subtractmaskfromsilk:"subtractmaskfromsilk",plot_black_and_white:"plot_black_and_white",plot_on_all_layers:"plot_on_all_layers",plotinvisible:"plotinvisible",mode:"mode",useauxorigin:"useauxorigin",viasonmask:"viasonmask",hpglpennumber:"hpglpennumber",hpglpenspeed:"hpglpenspeed",hpglpendiameter:"hpglpendiameter",hpglpenoverlay:"hpglpenoverlay",pdf_front_fp_property_popups:"pdf_front_fp_property_popups",pdf_back_fp_property_popups:"pdf_back_fp_property_popups",pdf_metadata:"pdf_metadata",pdf_single_document:"pdf_single_document",dxfpolygonmode:"dxfpolygonmode",dxfimperialunits:"dxfimperialunits",dxfusepcbnewfont:"dxfusepcbnewfont",psnegative:"psnegative",psa4output:"psa4output",mirror:"mirror",outputformat:"outputformat",drillshape:"drillshape",scaleselection:"scaleselection",outputdirectory:"outputdirectory"},HCi=["layerselection","plot_on_all_layers_selection","disableapertmacros","usegerberextensions","usegerberattributes","usegerberadvancedattributes","creategerberjobfile","excludeedgelayer","dashed_line_dash_ratio","dashed_line_gap_ratio","svgprecision","linewidth","plotframeref","plotreference","plotvalue","plotothertext","mode","useauxorigin","viasonmask","hpglpennumber","hpglpenspeed","hpglpendiameter","hpglpenoverlay","pdf_front_fp_property_popups","pdf_back_fp_property_popups","pdf_metadata","pdf_single_document","dxfpolygonmode","dxfimperialunits","dxfusepcbnewfont","psnegative","psa4output","plot_black_and_white","plot_on_all_layers","plotinvisible","plotinvisibletext","padsonsilk","sketchpadsonfab","plotpadnumbers","hidednponfab","sketchdnponfab","crossoutdnponfab","subtractmaskfromsilk","outputformat","mirror","drillshape","scaleselection","outputdirectory"],k1A=class Ext extends LA{static token="pcbplotparams";static parentToken="setup";token="pcbplotparams";_properties={};static fromSexprPrimitives(A){const t=new Ext,{propertyMap:i}=LA.parsePrimitivesToClassProperties(A,this.token);for(const[n,o]of Object.entries(i)){const s=UCi[n];if(!s)throw new Error(`Unsupported pcbplotparams token: ${n}`);t._properties[s]=o}return t}getChildren(){const A=[];for(const t of HCi){const i=this._properties[t];i&&A.push(i)}return A}clearProperty(A){delete this._properties[A]}setStringProperty(A,t,i){if(t===void 0){this.clearProperty(A);return}this._properties[A]=new i(t)}setNumberProperty(A,t,i){if(t===void 0){this.clearProperty(A);return}this._properties[A]=new i(t)}setStringOrNumberProperty(A,t,i){if(t===void 0){this.clearProperty(A);return}this._properties[A]=new i(t)}get layerselection(){return this._properties.layerselection?.value}set layerselection(A){this.setStringOrNumberProperty("layerselection",A,aft)}get plot_on_all_layers_selection(){return this._properties.plot_on_all_layers_selection?.value}set plot_on_all_layers_selection(A){this.setStringOrNumberProperty("plot_on_all_layers_selection",A,gft)}get disableapertmacros(){return this._properties.disableapertmacros?.value}set disableapertmacros(A){this.setStringProperty("disableapertmacros",A,yft)}get usegerberextensions(){return this._properties.usegerberextensions?.value}set usegerberextensions(A){this.setStringProperty("usegerberextensions",A,mft)}get usegerberattributes(){return this._properties.usegerberattributes?.value}set usegerberattributes(A){this.setStringProperty("usegerberattributes",A,wft)}get usegerberadvancedattributes(){return this._properties.usegerberadvancedattributes?.value}set usegerberadvancedattributes(A){this.setStringProperty("usegerberadvancedattributes",A,Dft)}get creategerberjobfile(){return this._properties.creategerberjobfile?.value}set creategerberjobfile(A){this.setStringProperty("creategerberjobfile",A,xft)}get excludeedgelayer(){return this._properties.excludeedgelayer?.value}set excludeedgelayer(A){this.setStringProperty("excludeedgelayer",A,Sft)}get dashed_line_dash_ratio(){return this._properties.dashed_line_dash_ratio?.value}set dashed_line_dash_ratio(A){this.setNumberProperty("dashed_line_dash_ratio",A,cft)}get dashed_line_gap_ratio(){return this._properties.dashed_line_gap_ratio?.value}set dashed_line_gap_ratio(A){this.setNumberProperty("dashed_line_gap_ratio",A,Ift)}get svgprecision(){return this._properties.svgprecision?.value}set svgprecision(A){this.setNumberProperty("svgprecision",A,lft)}get linewidth(){return this._properties.linewidth?.value}set linewidth(A){this.setNumberProperty("linewidth",A,Bft)}get plotframeref(){return this._properties.plotframeref?.value}set plotframeref(A){this.setStringProperty("plotframeref",A,bft)}get plotreference(){return this._properties.plotreference?.value}set plotreference(A){this.setStringProperty("plotreference",A,Yft)}get plotvalue(){return this._properties.plotvalue?.value}set plotvalue(A){this.setStringProperty("plotvalue",A,Jft)}get plotothertext(){return this._properties.plotothertext?.value}set plotothertext(A){this.setStringProperty("plotothertext",A,Tft)}get plotinvisibletext(){return this._properties.plotinvisibletext?.value}set plotinvisibletext(A){this.setStringProperty("plotinvisibletext",A,Pft)}get padsonsilk(){return this._properties.padsonsilk?.value}set padsonsilk(A){this.setStringProperty("padsonsilk",A,Kft)}get plotpadnumbers(){return this._properties.plotpadnumbers?.value}set plotpadnumbers(A){this.setStringProperty("plotpadnumbers",A,Oft)}get sketchpadsonfab(){return this._properties.sketchpadsonfab?.value}set sketchpadsonfab(A){this.setStringProperty("sketchpadsonfab",A,qft)}get hidednponfab(){return this._properties.hidednponfab?.value}set hidednponfab(A){this.setStringProperty("hidednponfab",A,Wft)}get sketchdnponfab(){return this._properties.sketchdnponfab?.value}set sketchdnponfab(A){this.setStringProperty("sketchdnponfab",A,Zft)}get crossoutdnponfab(){return this._properties.crossoutdnponfab?.value}set crossoutdnponfab(A){this.setStringProperty("crossoutdnponfab",A,Vft)}get subtractmaskfromsilk(){return this._properties.subtractmaskfromsilk?.value}set subtractmaskfromsilk(A){this.setStringProperty("subtractmaskfromsilk",A,jft)}get plot_black_and_white(){return this._properties.plot_black_and_white?.value}set plot_black_and_white(A){this.setStringProperty("plot_black_and_white",A,zft)}get plot_on_all_layers(){return this._properties.plot_on_all_layers?.value}set plot_on_all_layers(A){this.setStringProperty("plot_on_all_layers",A,Ayt)}get plotinvisible(){return this._properties.plotinvisible?.value}set plotinvisible(A){this.setStringProperty("plotinvisible",A,tyt)}get mode(){return this._properties.mode?.value}set mode(A){this.setNumberProperty("mode",A,Cft)}get useauxorigin(){return this._properties.useauxorigin?.value}set useauxorigin(A){this.setStringProperty("useauxorigin",A,kft)}get viasonmask(){return this._properties.viasonmask?.value}set viasonmask(A){this.setStringProperty("viasonmask",A,_ft)}get hpglpennumber(){return this._properties.hpglpennumber?.value}set hpglpennumber(A){this.setNumberProperty("hpglpennumber",A,Qft)}get hpglpenspeed(){return this._properties.hpglpenspeed?.value}set hpglpenspeed(A){this.setNumberProperty("hpglpenspeed",A,hft)}get hpglpendiameter(){return this._properties.hpglpendiameter?.value}set hpglpendiameter(A){this.setNumberProperty("hpglpendiameter",A,Eft)}get hpglpenoverlay(){return this._properties.hpglpenoverlay?.value}set hpglpenoverlay(A){this.setNumberProperty("hpglpenoverlay",A,uft)}get pdf_front_fp_property_popups(){return this._properties.pdf_front_fp_property_popups?.value}set pdf_front_fp_property_popups(A){this.setStringProperty("pdf_front_fp_property_popups",A,vft)}get pdf_back_fp_property_popups(){return this._properties.pdf_back_fp_property_popups?.value}set pdf_back_fp_property_popups(A){this.setStringProperty("pdf_back_fp_property_popups",A,Fft)}get pdf_metadata(){return this._properties.pdf_metadata?.value}set pdf_metadata(A){this.setStringProperty("pdf_metadata",A,Mft)}get pdf_single_document(){return this._properties.pdf_single_document?.value}set pdf_single_document(A){this.setStringProperty("pdf_single_document",A,Gft)}get dxfpolygonmode(){return this._properties.dxfpolygonmode?.value}set dxfpolygonmode(A){this.setStringProperty("dxfpolygonmode",A,Rft)}get dxfimperialunits(){return this._properties.dxfimperialunits?.value}set dxfimperialunits(A){this.setStringProperty("dxfimperialunits",A,Nft)}get dxfusepcbnewfont(){return this._properties.dxfusepcbnewfont?.value}set dxfusepcbnewfont(A){this.setStringProperty("dxfusepcbnewfont",A,Lft)}get psnegative(){return this._properties.psnegative?.value}set psnegative(A){this.setStringProperty("psnegative",A,Uft)}get psa4output(){return this._properties.psa4output?.value}set psa4output(A){this.setStringProperty("psa4output",A,Hft)}get mirror(){return this._properties.mirror?.value}set mirror(A){this.setStringProperty("mirror",A,Xft)}get outputformat(){return this._properties.outputformat?.value}set outputformat(A){this.setNumberProperty("outputformat",A,dft)}get drillshape(){return this._properties.drillshape?.value}set drillshape(A){this.setNumberProperty("drillshape",A,pft)}get scaleselection(){return this._properties.scaleselection?.value}set scaleselection(A){this.setNumberProperty("scaleselection",A,fft)}get outputdirectory(){return this._properties.outputdirectory?.value}set outputdirectory(A){this.setStringProperty("outputdirectory",A,$ft)}};LA.register(k1A);var gj=class extends B6{static parentToken="setup"},v1A=class extends gj{static token="zone_45_only";token="zone_45_only"};LA.register(v1A);var F1A=class extends gj{static token="allow_soldermask_bridges_in_footprints";token="allow_soldermask_bridges_in_footprints"};LA.register(F1A);var M1A=class extends gj{static token="visible_elements";token="visible_elements"};LA.register(M1A);var G1A=class extends gj{static token="uvias_allowed";token="uvias_allowed"};LA.register(G1A);var R1A=class uxt extends LA{static token="tenting";static parentToken="setup";token="tenting";_sides=[];constructor(A=[]){super(),this.sides=A}static fromSexprPrimitives(A){const t=A.map(i=>Di(i)).filter(i=>i!==void 0);return new uxt(t)}get sides(){return[...this._sides]}set sides(A){this._sides=A.map(t=>String(t))}getChildren(){return[]}getString(){return this._sides.length===0?"(tenting)":`(tenting ${this._sides.join(" ")})`}};LA.register(R1A);var C6=class extends NCi{static parentToken="setup"},eyt=class extends LCi{static parentToken="setup"},N1A=class extends C6{static token="pcb_text_size";token="pcb_text_size"};LA.register(N1A);var L1A=class extends C6{static token="mod_text_size";token="mod_text_size"};LA.register(L1A);var U1A=class extends C6{static token="pad_size";token="pad_size"};LA.register(U1A);var H1A=class extends C6{static token="pad_to_paste_clearance_values";token="pad_to_paste_clearance_values"};LA.register(H1A);var Y1A=class extends C6{static token="trace_width";token="trace_width"};LA.register(Y1A);var J1A=class extends eyt{static token="aux_axis_origin";token="aux_axis_origin"};LA.register(J1A);var T1A=class extends eyt{static token="grid_origin";token="grid_origin"};LA.register(T1A);var mB=class extends B6{static parentToken="setup";static parsePrimitiveValue(e){const A=Ci(e);if(A===void 0)throw new Error(`${this.name} expects a numeric value`);return A}},P1A=class extends mB{static token="pad_to_mask_clearance";token="pad_to_mask_clearance"};LA.register(P1A);var K1A=class extends mB{static token="solder_mask_min_width";token="solder_mask_min_width"};LA.register(K1A);var q1A=class extends mB{static token="pad_to_paste_clearance";token="pad_to_paste_clearance"};LA.register(q1A);var O1A=class extends mB{static token="pad_to_paste_clearance_ratio";token="pad_to_paste_clearance_ratio"};LA.register(O1A);var W1A=class extends mB{static token="last_trace_width";token="last_trace_width"};LA.register(W1A);var Z1A=class extends mB{static token="trace_clearance";token="trace_clearance"};LA.register(Z1A);var V1A=class extends mB{static token="zone_clearance";token="zone_clearance"};LA.register(V1A);var j1A=class extends mB{static token="trace_min";token="trace_min"};LA.register(j1A);var z1A=class extends mB{static token="segment_width";token="segment_width"};LA.register(z1A);var X1A=class extends mB{static token="edge_width";token="edge_width"};LA.register(X1A);var $1A=class extends mB{static token="via_size";token="via_size"};LA.register($1A);var A2A=class extends mB{static token="via_drill";token="via_drill"};LA.register(A2A);var t2A=class extends mB{static token="via_min_size";token="via_min_size"};LA.register(t2A);var e2A=class extends mB{static token="via_min_drill";token="via_min_drill"};LA.register(e2A);var i2A=class extends mB{static token="uvia_size";token="uvia_size"};LA.register(i2A);var n2A=class extends mB{static token="uvia_drill";token="uvia_drill"};LA.register(n2A);var o2A=class extends mB{static token="uvia_min_size";token="uvia_min_size"};LA.register(o2A);var s2A=class extends mB{static token="uvia_min_drill";token="uvia_min_drill"};LA.register(s2A);var r2A=class extends mB{static token="pcb_text_width";token="pcb_text_width"};LA.register(r2A);var a2A=class extends mB{static token="mod_edge_width";token="mod_edge_width"};LA.register(a2A);var g2A=class extends mB{static token="mod_text_width";token="mod_text_width"};LA.register(g2A);var c2A=class extends mB{static token="pad_drill";token="pad_drill"};LA.register(c2A);var Q6=class extends B6{static parentToken="stackup"},iyt=class extends Q6{static token="copper_finish";token="copper_finish";quoteStringValue=!0};LA.register(iyt);var nyt=class extends Q6{static token="dielectric_constraints";token="dielectric_constraints"};LA.register(nyt);var oyt=class extends Q6{static token="edge_connector";token="edge_connector"};LA.register(oyt);var syt=class extends Q6{static token="castellated_pads";token="castellated_pads"};LA.register(syt);var ryt=class extends Q6{static token="edge_plating";token="edge_plating"};LA.register(ryt);var HM=class extends B6{static parentToken="layer"},I2A=class extends HM{static token="type";token="type";quoteStringValue=!0};LA.register(I2A);var l2A=class extends HM{static token="color";token="color";quoteStringValue=!0};LA.register(l2A);var B2A=class extends HM{static token="thickness";token="thickness";static parsePrimitiveValue(e){const A=Ci(e);if(A===void 0)throw new Error("Stackup layer thickness expects a numeric value");return A}};LA.register(B2A);var C2A=class extends HM{static token="material";token="material";quoteStringValue=!0};LA.register(C2A);var Q2A=class extends HM{static token="epsilon_r";token="epsilon_r";static parsePrimitiveValue(e){const A=Ci(e);if(A===void 0)throw new Error("Stackup layer epsilon_r expects a numeric value");return A}};LA.register(Q2A);var h2A=class extends HM{static token="loss_tangent";token="loss_tangent";static parsePrimitiveValue(e){const A=Ci(e);if(A===void 0)throw new Error("Stackup layer loss_tangent expects a numeric value");return A}};LA.register(h2A);var ayt=class dxt extends LA{static token="layer";static parentToken="stackup";token="layer";_name;_number;_sxType;_sxColor;_sxThickness;_sxMaterial;_sxEpsilonR;_sxLossTangent;constructor(A,t={}){super(),this._name=A,this._number=t.number,this._sxType=t.type,this._sxColor=t.color,this._sxThickness=t.thickness,this._sxMaterial=t.material,this._sxEpsilonR=t.epsilonR,this._sxLossTangent=t.lossTangent}static fromSexprPrimitives(A){if(A.length===0)throw new Error("Stackup layer requires at least a name");const t=Di(A[0]);if(t===void 0)throw new Error("Stackup layer name must be a string");let i=1,n;const o=A[i],s=Ci(o);s!==void 0&&(n=s,i+=1);const r=A.slice(i),{propertyMap:a}=LA.parsePrimitivesToClassProperties(r,this.token);return new dxt(t,{number:n,type:a.type,color:a.color,thickness:a.thickness,material:a.material,epsilonR:a.epsilon_r,lossTangent:a.loss_tangent})}get name(){return this._name}set name(A){const t=Di(A);if(t===void 0)throw new Error("Stackup layer name must be a string");this._name=t}get number(){return this._number}set number(A){if(A===void 0){this._number=void 0;return}const t=Ci(A);if(t===void 0)throw new Error("Stackup layer number must be numeric");this._number=t}get type(){return this._sxType?.value}set type(A){if(A===void 0){this._sxType=void 0;return}this._sxType=A instanceof I2A?A:new I2A(A)}get color(){return this._sxColor?.value}set color(A){if(A===void 0){this._sxColor=void 0;return}this._sxColor=A instanceof l2A?A:new l2A(A)}get thickness(){return this._sxThickness?.value}set thickness(A){if(A===void 0){this._sxThickness=void 0;return}this._sxThickness=A instanceof B2A?A:new B2A(A)}get material(){return this._sxMaterial?.value}set material(A){if(A===void 0){this._sxMaterial=void 0;return}this._sxMaterial=A instanceof C2A?A:new C2A(A)}get epsilonR(){return this._sxEpsilonR?.value}set epsilonR(A){if(A===void 0){this._sxEpsilonR=void 0;return}this._sxEpsilonR=A instanceof Q2A?A:new Q2A(A)}get lossTangent(){return this._sxLossTangent?.value}set lossTangent(A){if(A===void 0){this._sxLossTangent=void 0;return}this._sxLossTangent=A instanceof h2A?A:new h2A(A)}getChildren(){const A=[];return this._sxType&&A.push(this._sxType),this._sxColor&&A.push(this._sxColor),this._sxThickness&&A.push(this._sxThickness),this._sxMaterial&&A.push(this._sxMaterial),this._sxEpsilonR&&A.push(this._sxEpsilonR),this._sxLossTangent&&A.push(this._sxLossTangent),A}getString(){const A=`(layer ${mn(this._name)}${this._number!==void 0?` ${this._number}`:""}`,t=this.getChildren();if(t.length===0)return`${A})`;const i=[A];for(const n of t)i.push(n.getStringIndented());return i.push(")"),i.join(`
|
|
5828
5828
|
`)}};LA.register(ayt);var E2A=class pxt extends LA{static token="stackup";static parentToken="setup";token="stackup";_layers=[];_sxCopperFinish;_sxDielectricConstraints;_sxEdgeConnector;_sxCastellatedPads;_sxEdgePlating;constructor(A={}){super(),this.layers=A.layers??[],this._sxCopperFinish=A.copperFinish,this._sxDielectricConstraints=A.dielectricConstraints,this._sxEdgeConnector=A.edgeConnector,this._sxCastellatedPads=A.castellatedPads,this._sxEdgePlating=A.edgePlating}static fromSexprPrimitives(A){const{propertyMap:t,arrayPropertyMap:i}=LA.parsePrimitivesToClassProperties(A,this.token);return new pxt({layers:i.layer??[],copperFinish:t.copper_finish,dielectricConstraints:t.dielectric_constraints,edgeConnector:t.edge_connector,castellatedPads:t.castellated_pads,edgePlating:t.edge_plating})}get layers(){return[...this._layers]}set layers(A){this._layers=A.map(t=>{if(!(t instanceof ayt))throw new Error("Stackup layers must be StackupLayer instances");return t})}get copperFinish(){return this._sxCopperFinish?.value}set copperFinish(A){this._sxCopperFinish=A?new iyt(A):void 0}get dielectricConstraints(){return this._sxDielectricConstraints?.value}set dielectricConstraints(A){this._sxDielectricConstraints=A?new nyt(A):void 0}get edgeConnector(){return this._sxEdgeConnector?.value}set edgeConnector(A){this._sxEdgeConnector=A?new oyt(A):void 0}get castellatedPads(){return this._sxCastellatedPads?.value}set castellatedPads(A){this._sxCastellatedPads=A?new syt(A):void 0}get edgePlating(){return this._sxEdgePlating?.value}set edgePlating(A){this._sxEdgePlating=A?new ryt(A):void 0}getChildren(){const A=[...this._layers],t=[this._sxCopperFinish,this._sxDielectricConstraints,this._sxEdgeConnector,this._sxCastellatedPads,this._sxEdgePlating];for(const i of t)i&&A.push(i);return A}};LA.register(E2A);var YCi={stackup:"stackup",pcbplotparams:"pcbPlotParams",pad_to_mask_clearance:"padToMaskClearance",solder_mask_min_width:"solderMaskMinWidth",pad_to_paste_clearance:"padToPasteClearance",pad_to_paste_clearance_ratio:"padToPasteClearanceRatio",last_trace_width:"lastTraceWidth",trace_clearance:"traceClearance",zone_clearance:"zoneClearance",zone_45_only:"zone45Only",trace_min:"traceMin",segment_width:"segmentWidth",edge_width:"edgeWidth",via_size:"viaSize",via_drill:"viaDrill",via_min_size:"viaMinSize",via_min_drill:"viaMinDrill",uvias_allowed:"uviasAllowed",uvia_size:"uviaSize",uvia_drill:"uviaDrill",uvia_min_size:"uviaMinSize",uvia_min_drill:"uviaMinDrill",pcb_text_width:"pcbTextWidth",pcb_text_size:"pcbTextSize",mod_edge_width:"modEdgeWidth",mod_text_size:"modTextSize",mod_text_width:"modTextWidth",pad_size:"padSize",pad_drill:"padDrill",allow_soldermask_bridges_in_footprints:"allowSoldermaskBridgesInFootprints",tenting:"tenting",aux_axis_origin:"auxAxisOrigin",grid_origin:"gridOrigin",visible_elements:"visibleElements",pad_to_paste_clearance_values:"padToPasteClearanceValues",trace_width:"traceWidth"},JCi=["stackup","padToMaskClearance","solderMaskMinWidth","padToPasteClearance","padToPasteClearanceRatio","lastTraceWidth","traceClearance","zoneClearance","zone45Only","traceMin","segmentWidth","edgeWidth","viaSize","viaDrill","viaMinSize","viaMinDrill","uviaSize","uviaDrill","uviasAllowed","uviaMinSize","uviaMinDrill","pcbTextWidth","pcbTextSize","modEdgeWidth","modTextSize","modTextWidth","padSize","padDrill","allowSoldermaskBridgesInFootprints","tenting","auxAxisOrigin","gridOrigin","visibleElements","padToPasteClearanceValues","traceWidth","pcbPlotParams"],u2A=class fxt extends LA{static token="setup";token="setup";_properties={};static fromSexprPrimitives(A){const t=new fxt,{propertyMap:i}=LA.parsePrimitivesToClassProperties(A,this.token);for(const[n,o]of Object.entries(i)){const s=YCi[n];if(!s)throw new Error(`Unsupported setup property token: ${n}`);t._properties[s]=o}return t}getChildren(){const A=[];for(const t of JCi){const i=this._properties[t];i&&A.push(i)}return A}setProperty(A,t){if(t){this._properties[A]=t;return}delete this._properties[A]}setNumberProperty(A,t,i){if(t===void 0){delete this._properties[A];return}this._properties[A]=new i(t)}getPropertyInstance(A,t){const i=this._properties[A];return i instanceof t?i:void 0}get stackup(){return this.getPropertyInstance("stackup",E2A)}set stackup(A){if(A!==void 0&&!(A instanceof E2A))throw new Error("stackup must be a Stackup instance");this.setProperty("stackup",A)}get pcbPlotParams(){return this.getPropertyInstance("pcbPlotParams",k1A)}set pcbPlotParams(A){if(A!==void 0&&!(A instanceof k1A))throw new Error("pcbPlotParams must be a PcbPlotParams instance");this.setProperty("pcbPlotParams",A)}get padToMaskClearance(){return this.getPropertyInstance("padToMaskClearance",P1A)?.value}set padToMaskClearance(A){this.setNumberProperty("padToMaskClearance",A,P1A)}get solderMaskMinWidth(){return this.getPropertyInstance("solderMaskMinWidth",K1A)?.value}set solderMaskMinWidth(A){this.setNumberProperty("solderMaskMinWidth",A,K1A)}get padToPasteClearance(){return this.getPropertyInstance("padToPasteClearance",q1A)?.value}set padToPasteClearance(A){this.setNumberProperty("padToPasteClearance",A,q1A)}get padToPasteClearanceRatio(){return this.getPropertyInstance("padToPasteClearanceRatio",O1A)?.value}set padToPasteClearanceRatio(A){this.setNumberProperty("padToPasteClearanceRatio",A,O1A)}get lastTraceWidth(){return this.getPropertyInstance("lastTraceWidth",W1A)?.value}set lastTraceWidth(A){this.setNumberProperty("lastTraceWidth",A,W1A)}get traceClearance(){return this.getPropertyInstance("traceClearance",Z1A)?.value}set traceClearance(A){this.setNumberProperty("traceClearance",A,Z1A)}get zoneClearance(){return this.getPropertyInstance("zoneClearance",V1A)?.value}set zoneClearance(A){this.setNumberProperty("zoneClearance",A,V1A)}get zone45Only(){return this.getPropertyInstance("zone45Only",v1A)?.value}set zone45Only(A){this.setProperty("zone45Only",A===void 0?void 0:new v1A(A))}get traceMin(){return this.getPropertyInstance("traceMin",j1A)?.value}set traceMin(A){this.setNumberProperty("traceMin",A,j1A)}get segmentWidth(){return this.getPropertyInstance("segmentWidth",z1A)?.value}set segmentWidth(A){this.setNumberProperty("segmentWidth",A,z1A)}get edgeWidth(){return this.getPropertyInstance("edgeWidth",X1A)?.value}set edgeWidth(A){this.setNumberProperty("edgeWidth",A,X1A)}get viaSize(){return this.getPropertyInstance("viaSize",$1A)?.value}set viaSize(A){this.setNumberProperty("viaSize",A,$1A)}get viaDrill(){return this.getPropertyInstance("viaDrill",A2A)?.value}set viaDrill(A){this.setNumberProperty("viaDrill",A,A2A)}get viaMinSize(){return this.getPropertyInstance("viaMinSize",t2A)?.value}set viaMinSize(A){this.setNumberProperty("viaMinSize",A,t2A)}get viaMinDrill(){return this.getPropertyInstance("viaMinDrill",e2A)?.value}set viaMinDrill(A){this.setNumberProperty("viaMinDrill",A,e2A)}get uviasAllowed(){return this.getPropertyInstance("uviasAllowed",G1A)?.value}set uviasAllowed(A){this.setProperty("uviasAllowed",A===void 0?void 0:new G1A(A))}get uviaSize(){return this.getPropertyInstance("uviaSize",i2A)?.value}set uviaSize(A){this.setNumberProperty("uviaSize",A,i2A)}get uviaDrill(){return this.getPropertyInstance("uviaDrill",n2A)?.value}set uviaDrill(A){this.setNumberProperty("uviaDrill",A,n2A)}get uviaMinSize(){return this.getPropertyInstance("uviaMinSize",o2A)?.value}set uviaMinSize(A){this.setNumberProperty("uviaMinSize",A,o2A)}get uviaMinDrill(){return this.getPropertyInstance("uviaMinDrill",s2A)?.value}set uviaMinDrill(A){this.setNumberProperty("uviaMinDrill",A,s2A)}get pcbTextWidth(){return this.getPropertyInstance("pcbTextWidth",r2A)?.value}set pcbTextWidth(A){this.setNumberProperty("pcbTextWidth",A,r2A)}get pcbTextSize(){return this.getPropertyInstance("pcbTextSize",N1A)?.values}set pcbTextSize(A){if(A===void 0){delete this._properties.pcbTextSize;return}this.setProperty("pcbTextSize",new N1A(A))}get modEdgeWidth(){return this.getPropertyInstance("modEdgeWidth",a2A)?.value}set modEdgeWidth(A){this.setNumberProperty("modEdgeWidth",A,a2A)}get modTextSize(){return this.getPropertyInstance("modTextSize",L1A)?.values}set modTextSize(A){if(A===void 0){delete this._properties.modTextSize;return}this.setProperty("modTextSize",new L1A(A))}get modTextWidth(){return this.getPropertyInstance("modTextWidth",g2A)?.value}set modTextWidth(A){this.setNumberProperty("modTextWidth",A,g2A)}get padSize(){return this.getPropertyInstance("padSize",U1A)?.values}set padSize(A){if(A===void 0){delete this._properties.padSize;return}this.setProperty("padSize",new U1A(A))}get padDrill(){return this.getPropertyInstance("padDrill",c2A)?.value}set padDrill(A){this.setNumberProperty("padDrill",A,c2A)}get allowSoldermaskBridgesInFootprints(){return this.getPropertyInstance("allowSoldermaskBridgesInFootprints",F1A)?.value}set allowSoldermaskBridgesInFootprints(A){this.setProperty("allowSoldermaskBridgesInFootprints",A===void 0?void 0:new F1A(A))}get tenting(){return this.getPropertyInstance("tenting",R1A)?.sides}set tenting(A){if(A===void 0){delete this._properties.tenting;return}this.setProperty("tenting",new R1A(A))}get auxAxisOrigin(){const A=this.getPropertyInstance("auxAxisOrigin",J1A);if(A)return{x:A.x,y:A.y}}set auxAxisOrigin(A){if(!A){delete this._properties.auxAxisOrigin;return}this.setProperty("auxAxisOrigin",new J1A(A.x,A.y))}get gridOrigin(){const A=this.getPropertyInstance("gridOrigin",T1A);if(A)return{x:A.x,y:A.y}}set gridOrigin(A){if(!A){delete this._properties.gridOrigin;return}this.setProperty("gridOrigin",new T1A(A.x,A.y))}get visibleElements(){return this.getPropertyInstance("visibleElements",M1A)?.value}set visibleElements(A){this.setProperty("visibleElements",A===void 0?void 0:new M1A(A))}get padToPasteClearanceValues(){return this.getPropertyInstance("padToPasteClearanceValues",H1A)?.values}set padToPasteClearanceValues(A){if(A===void 0){delete this._properties.padToPasteClearanceValues;return}this.setProperty("padToPasteClearanceValues",new H1A(A))}get traceWidth(){return this.getPropertyInstance("traceWidth",Y1A)?.values}set traceWidth(A){if(A===void 0){delete this._properties.traceWidth;return}this.setProperty("traceWidth",new Y1A(A))}};LA.register(u2A);var gyt=class extends ha{static token="thickness";static parentToken="general";token="thickness"};LA.register(gyt);var cyt=class yxt extends LA{static token="legacy_teardrops";static parentToken="general";token="legacy_teardrops";_enabled;constructor(A){super(),this._enabled=A}static fromSexprPrimitives(A){const t=Di(A[0]);if(t===void 0)throw new Error("legacy_teardrops expects a string value");const i=/^(yes|true)$/iu.test(t);return new yxt(i)}get enabled(){return this._enabled}set enabled(A){this._enabled=A}getChildren(){return[]}getString(){return`(legacy_teardrops ${this._enabled?"yes":"no"})`}};LA.register(cyt);var Iyt=new Set(["thickness","legacy_teardrops"]),d2A=class mxt extends LA{static token="general";static parentToken="kicad_pcb";token="general";_sxThickness;_sxLegacyTeardrops;static fromSexprPrimitives(A){const t=new mxt,{propertyMap:i,arrayPropertyMap:n}=LA.parsePrimitivesToClassProperties(A,this.token);for(const o of Object.keys(i))if(!Iyt.has(o))throw new Error(`general encountered unsupported child token "${o}"`);for(const[o,s]of Object.entries(n)){if(!Iyt.has(o))throw new Error(`general encountered unsupported child token "${o}"`);if(s.length>1)throw new Error(`general encountered repeated child token "${o}"`)}return t._sxThickness=n.thickness?.[0]??i.thickness,t._sxLegacyTeardrops=n.legacy_teardrops?.[0]??i.legacy_teardrops,t}get thickness(){return this._sxThickness?.value}set thickness(A){this._sxThickness=A===void 0?void 0:new gyt(A)}get legacyTeardrops(){return this._sxLegacyTeardrops?.enabled}set legacyTeardrops(A){if(A===void 0){this._sxLegacyTeardrops=void 0;return}this._sxLegacyTeardrops=new cyt(A)}getChildren(){const A=[];return this._sxThickness&&A.push(this._sxThickness),this._sxLegacyTeardrops&&A.push(this._sxLegacyTeardrops),A}};LA.register(d2A);var Zl=class wxt extends LA{static token="__pcb_layer_definition__";static parentToken="layers";token="__pcb_layer_definition__";_index;_name;_type;_userName;constructor(A){super(),this._index=A.index,this._name=A.name,this._type=A.type,this._userName=A.userName}static fromPrimitive(A){if(!Array.isArray(A)||A.length<3)throw new Error(`layers entry must be an array with at least index, name, and type: ${JSON.stringify(A)}`);const[t,i,n,o]=A,s=Ci(t),r=Di(i),a=Di(n),g=o===void 0?void 0:Di(o);if(s===void 0||r===void 0||a===void 0)throw new Error(`layers entry is missing required values: ${JSON.stringify(A)}`);return new wxt({index:s,name:r,type:a,userName:g})}get index(){return this._index}set index(A){this._index=A}get name(){return this._name}set name(A){this._name=A}get type(){return this._type}set type(A){this._type=A}get userName(){return this._userName}set userName(A){this._userName=A}getChildren(){return[]}getString(){if(this._index===void 0||this._name===void 0||this._type===void 0)return"()";const A=[String(this._index),mn(this._name),this._type];return this._userName!==void 0&&A.push(mn(this._userName)),`(${A.join(" ")})`}};LA.register(Zl);var p2A=class Dxt extends LA{static token="layers";static parentToken="kicad_pcb";token="layers";_definitions=[];static fromSexprPrimitives(A){const t=new Dxt;return t._definitions=A.map(i=>Zl.fromPrimitive(i)),t}get definitions(){return[...this._definitions]}set definitions(A){this._definitions=[...A]}getChildren(){return[...this._definitions]}};LA.register(p2A);var cj=class xxt extends LA{static token="net";static parentToken="kicad_pcb";token="net";_id;_name;constructor(A,t){super(),this._id=A,this._name=t}static fromSexprPrimitives(A){const t=Ci(A[0]),i=Di(A[1]);if(t===void 0||i===void 0)throw new Error("net requires numeric id and string name");return new xxt(t,i)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A}getChildren(){return[]}getString(){return`(net ${this._id} ${mn(this._name)})`}};LA.register(cj);var f2A=class extends ha{static token="version";static parentToken="kicad_pcb";token="version"};LA.register(f2A);var TCi=e=>/^[A-Za-z0-9._-]+$/.test(e),y2A=class extends xm{static token="generator";static parentToken="kicad_pcb";token="generator";getString(){return`(generator ${TCi(this.value)?this.value:mn(this.value)})`}};LA.register(y2A);var PCi=e=>/^[A-Za-z0-9._-]+$/.test(e),m2A=class extends xm{static token="generator_version";static parentToken="kicad_pcb";token="generator_version";getString(){return`(generator_version ${PCi(this.value)?this.value:mn(this.value)})`}};LA.register(m2A);var w2A=class Sxt extends LA{static token="net";static parentToken="via";token="net";_id;_name;constructor(A,t){super(),this._id=A,this._name=t}static fromSexprPrimitives(A){const t=Ci(A[0]);if(t===void 0)throw new Error("via net requires a numeric id");const i=A.length>1?Di(A[1]):void 0;return new Sxt(t,i)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A}getChildren(){return[]}getString(){return this._name!==void 0?`(net ${this._id} ${mn(this._name)})`:`(net ${this._id})`}};LA.register(w2A);var KCi=new Set(["locked","free","remove_unused_layers","keep_end_layers"]),D2A=class bxt extends LA{static token="via";token="via";_type;_locked=!1;_free=!1;_removeUnusedLayers=!1;_keepEndLayers=!1;_sxAt;_size;_drill;_sxLayers;_sxNet;_sxUuid;_sxTstamp;_sxTeardrops;constructor(A={}){super(),A.type!==void 0&&(this.type=A.type),A.locked!==void 0&&(this.locked=A.locked),A.free!==void 0&&(this.free=A.free),A.removeUnusedLayers!==void 0&&(this.removeUnusedLayers=A.removeUnusedLayers),A.keepEndLayers!==void 0&&(this.keepEndLayers=A.keepEndLayers),A.at!==void 0&&(this.at=A.at),A.size!==void 0&&(this.size=A.size),A.drill!==void 0&&(this.drill=A.drill),A.layers!==void 0&&(this.layers=A.layers),A.net!==void 0&&(this.net=A.net),A.uuid!==void 0&&(this.uuid=A.uuid),A.tstamp!==void 0&&(this.tstamp=A.tstamp),A.teardrops!==void 0&&(this.teardrops=A.teardrops)}static fromSexprPrimitives(A){const t=new bxt;for(const i of A){if(typeof i=="string"){t.consumeBareToken(i);continue}if(!Array.isArray(i)||i.length===0)throw new Error(`via encountered unsupported primitive child: ${JSON.stringify(i)}`);const[n,...o]=i;if(typeof n!="string")throw new Error(`via encountered child with non-string token: ${JSON.stringify(i)}`);t.consumeNode(n,o)}return t}consumeBareToken(A){if(A==="blind"||A==="micro"){this._type=A;return}if(!KCi.has(A))throw new Error(`via encountered unsupported flag "${A}"`);switch(A){case"locked":this._locked=!0;break;case"free":this._free=!0;break;case"remove_unused_layers":this._removeUnusedLayers=!0;break;case"keep_end_layers":this._keepEndLayers=!0;break}}consumeNode(A,t){switch(A){case"type":{const i=Di(t[0]);if(i===void 0)throw new Error("via type expects a string value");this._type=i;return}case"locked":this._locked=this.parseYesNo(t);return;case"free":this._free=this.parseYesNo(t);return;case"remove_unused_layers":this._removeUnusedLayers=this.parseYesNo(t);return;case"keep_end_layers":this._keepEndLayers=this.parseYesNo(t);return;case"at":{const i=LA.parsePrimitiveSexpr(["at",...t],{parentToken:this.token});if(!(i instanceof oc))throw new Error("via failed to parse at child");this._sxAt=i;return}case"size":{const i=Ci(t[0]);if(i===void 0)throw new Error("via size expects a numeric value");this._size=i;return}case"drill":{const i=Ci(t[0]);if(i===void 0)throw new Error("via drill expects a numeric value");this._drill=i;return}case"layers":{this._sxLayers=aj.fromSexprPrimitives(t);return}case"net":{this._sxNet=w2A.fromSexprPrimitives(t);return}case"teardrops":{this._sxTeardrops=Gpt.fromSexprPrimitives(t);return}case"uuid":{const i=Di(t[0]);if(i===void 0)throw new Error("via uuid expects a string value");this._sxUuid=new qi(i);return}case"tstamp":{const i=Di(t[0]);if(i===void 0)throw new Error("via tstamp expects a string value");this._sxTstamp=new sc(i);return}default:throw new Error(`via encountered unsupported child token "${A}"`)}}parseYesNo(A){if(A.length===0)return!0;const t=Di(A[0]);if(t===void 0)throw new Error("Expected string when parsing via boolean child");return/^(yes|true)$/iu.test(t)}get type(){return this._type}set type(A){this._type=A}get locked(){return this._locked}set locked(A){this._locked=A}get free(){return this._free}set free(A){this._free=A}get removeUnusedLayers(){return this._removeUnusedLayers}set removeUnusedLayers(A){this._removeUnusedLayers=A}get keepEndLayers(){return this._keepEndLayers}set keepEndLayers(A){this._keepEndLayers=A}get at(){return this._sxAt}set at(A){this._sxAt=A!==void 0?oc.from(A):void 0}get size(){return this._size}set size(A){this._size=A}get drill(){return this._drill}set drill(A){this._drill=A}get layers(){return this._sxLayers}set layers(A){if(A===void 0){this._sxLayers=void 0;return}this._sxLayers=A instanceof aj?A:new aj(A)}get net(){return this._sxNet}set net(A){this._sxNet=A}get uuid(){return this._sxUuid}set uuid(A){if(A===void 0){this._sxUuid=void 0;return}this._sxUuid=A instanceof qi?A:new qi(A)}get teardrops(){return this._sxTeardrops}set teardrops(A){this._sxTeardrops=A}get tstamp(){return this._sxTstamp}set tstamp(A){if(A===void 0){this._sxTstamp=void 0;return}this._sxTstamp=A instanceof sc?A:new sc(A)}getChildren(){const A=[];return this._sxAt&&A.push(this._sxAt),this._sxLayers&&A.push(this._sxLayers),this._sxNet&&A.push(this._sxNet),this._sxUuid&&A.push(this._sxUuid),this._sxTstamp&&A.push(this._sxTstamp),this._sxTeardrops&&A.push(this._sxTeardrops),A}getString(){const A=["(via"];return this._type!==void 0&&A.push(` (type ${this._type})`),this._locked&&A.push(" (locked)"),this._free&&A.push(" (free)"),this._removeUnusedLayers&&A.push(" (remove_unused_layers)"),this._keepEndLayers&&A.push(" (keep_end_layers)"),this._sxAt&&A.push(this._sxAt.getStringIndented()),this._size!==void 0&&A.push(` (size ${this._size})`),this._drill!==void 0&&A.push(` (drill ${this._drill})`),this._sxLayers&&A.push(this._sxLayers.getStringIndented()),this._sxNet&&A.push(this._sxNet.getStringIndented()),this._sxUuid&&A.push(this._sxUuid.getStringIndented()),this._sxTstamp&&A.push(this._sxTstamp.getStringIndented()),this._sxTeardrops&&A.push(this._sxTeardrops.getStringIndented()),A.push(")"),A.join(`
|
|
5829
|
-
`)}};LA.register(D2A);var x2A=class _xt extends LA{static token="kicad_pcb";token="kicad_pcb";_sxVersion;_sxGenerator;_sxGeneratorVersion;_sxGeneral;_sxPaper;_sxTitleBlock;_sxLayers;_sxSetup;_properties=[];_nets=[];_footprints=[];_images=[];_segments=[];_grLines=[];_grTexts=[];_grPolys=[];_grRects=[];_vias=[];_zones=[];_otherChildren=[];constructor(A={}){super(),A.version!==void 0&&(this.version=A.version),A.generator!==void 0&&(this.generator=A.generator),A.generatorVersion!==void 0&&(this.generatorVersion=A.generatorVersion),A.general!==void 0&&(this.general=A.general),A.paper!==void 0&&(this.paper=A.paper),A.titleBlock!==void 0&&(this.titleBlock=A.titleBlock),A.layers!==void 0&&(this.layers=A.layers),A.setup!==void 0&&(this.setup=A.setup),A.properties!==void 0&&(this.properties=A.properties),A.nets!==void 0&&(this.nets=A.nets),A.footprints!==void 0&&(this.footprints=A.footprints),A.images!==void 0&&(this.images=A.images),A.segments!==void 0&&(this.segments=A.segments),A.graphicLines!==void 0&&(this.graphicLines=A.graphicLines),A.graphicTexts!==void 0&&(this.graphicTexts=A.graphicTexts),A.graphicPolys!==void 0&&(this.graphicPolys=A.graphicPolys),A.graphicRects!==void 0&&(this.graphicRects=A.graphicRects),A.vias!==void 0&&(this.vias=A.vias),A.zones!==void 0&&(this.zones=A.zones),A.otherChildren!==void 0&&(this.otherChildren=A.otherChildren)}static fromSexprPrimitives(A){const t=new _xt;for(const i of A){if(!Array.isArray(i)||i.length===0)throw new Error(`kicad_pcb encountered unsupported primitive child: ${JSON.stringify(i)}`);const n=LA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(n instanceof LA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);t.consumeChild(n)}return t}consumeChild(A){if(A instanceof f2A){this._sxVersion=A;return}if(A instanceof y2A){this._sxGenerator=A;return}if(A instanceof m2A){this._sxGeneratorVersion=A;return}if(A instanceof d2A){this._sxGeneral=A;return}if(A instanceof OV){this._sxPaper=A;return}if(A instanceof cdt){this._sxTitleBlock=A;return}if(A instanceof p2A){this._sxLayers=A;return}if(A instanceof u2A){this._sxSetup=A;return}if(A instanceof y1){this._properties.push(A);return}if(A instanceof cj){this._nets.push(A);return}if(A instanceof nj){this._footprints.push(A);return}if(A instanceof ldt){this._images.push(A);return}if(A instanceof _1A){this._segments.push(A);return}if(A instanceof oj){this._grLines.push(A);return}if(A instanceof sj){this._grTexts.push(A);return}if(A instanceof tft){this._grPolys.push(A);return}if(A instanceof Xpt){this._grRects.push(A);return}if(A instanceof D2A){this._vias.push(A);return}if(A instanceof rft){this._zones.push(A);return}this._otherChildren.push(A)}get version(){return this._sxVersion?.value}set version(A){this._sxVersion=A===void 0?void 0:new f2A(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new y2A(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new m2A(A)}get general(){return this._sxGeneral}set general(A){this._sxGeneral=A}get paper(){return this._sxPaper}set paper(A){this._sxPaper=A}get titleBlock(){return this._sxTitleBlock}set titleBlock(A){this._sxTitleBlock=A}get layers(){return this._sxLayers}set layers(A){this._sxLayers=A}get setup(){return this._sxSetup}set setup(A){this._sxSetup=A}get properties(){return[...this._properties]}set properties(A){this._properties=[...A]}get nets(){return[...this._nets]}set nets(A){this._nets=[...A]}get footprints(){return[...this._footprints]}set footprints(A){this._footprints=[...A]}get images(){return[...this._images]}set images(A){this._images=[...A]}get segments(){return[...this._segments]}set segments(A){this._segments=[...A]}get graphicLines(){return[...this._grLines]}set graphicLines(A){this._grLines=[...A]}get graphicTexts(){return[...this._grTexts]}set graphicTexts(A){this._grTexts=[...A]}get graphicPolys(){return[...this._grPolys]}set graphicPolys(A){this._grPolys=[...A]}get graphicRects(){return[...this._grRects]}set graphicRects(A){this._grRects=[...A]}get vias(){return[...this._vias]}set vias(A){this._vias=[...A]}get zones(){return[...this._zones]}set zones(A){this._zones=[...A]}get otherChildren(){return[...this._otherChildren]}set otherChildren(A){this._otherChildren=[...A]}getChildren(){const A=[];return this._sxVersion&&A.push(this._sxVersion),this._sxGenerator&&A.push(this._sxGenerator),this._sxGeneratorVersion&&A.push(this._sxGeneratorVersion),this._sxGeneral&&A.push(this._sxGeneral),this._sxPaper&&A.push(this._sxPaper),this._sxTitleBlock&&A.push(this._sxTitleBlock),this._sxLayers&&A.push(this._sxLayers),this._sxSetup&&A.push(this._sxSetup),A.push(...this._properties),A.push(...this._nets),A.push(...this._footprints),A.push(...this._images),A.push(...this._segments),A.push(...this._grLines),A.push(...this._grTexts),A.push(...this._grPolys),A.push(...this._grRects),A.push(...this._vias),A.push(...this._zones),A.push(...this._otherChildren),A}};LA.register(x2A);var lyt=e=>LA.parse(e),t0=class{MAX_ITERATIONS=1e3;iteration=0;finished=!1;input;ctx;constructor(e,A){this.input=e,this.ctx=A}step(){if(this.iteration++,this.iteration>this.MAX_ITERATIONS)throw new Error("Max iterations reached");this._step()}_step(){throw new Error("Not implemented")}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){throw new Error("Not implemented")}},qCi=class extends t0{_step(){const{kicadSch:e,schematicPaperSize:A}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");e.version=20250114;const t=new OV;t.size=A?.name??"A4",e.paper=t,e.uuid=new qi(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function U3(e,A){if(e.manufacturer_part_number)return S2A(e.manufacturer_part_number);const t=OCi(e.ftype),i=A?.footprinter_string;return S2A(i?`${t}_${i}`:t)}function OCi(e){if(!e)return"component";let A=e.replace(/^simple_/,"");return A||"component"}function S2A(e){return e.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function Byt(e){return e?e.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}var Cyt={simple_resistor:"R",simple_capacitor:"C",simple_inductor:"L",simple_diode:"D",simple_led:"D",simple_chip:"U",simple_transistor:"Q",simple_mosfet:"Q",simple_fuse:"F",simple_switch:"SW",simple_push_button:"SW",simple_potentiometer:"RV",simple_crystal:"Y",simple_resonator:"Y",simple_pin_header:"J",simple_pinout:"J",simple_test_point:"TP",simple_battery:"BT"},WCi=/^[A-Za-z]+\d+$/;function Qyt(e){return e?WCi.test(e.trim()):!1}function Ij(e){const A=e?.ftype;if(A&&Cyt[A])return Cyt[A];const t=e?.name;return Qyt(t),Byt(t)}function ZCi(e){const A=e?.name;return Qyt(A)?A.trim():`${Ij(e)}?`}function hyt(e){return e in qQ}function Eyt(e,A,t,i){if(i)return`Custom:${i}`;if(e.type!=="source_component")return A.symbol_name?hyt(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return hyt(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const n=U3(e,t);return`Device:${Ij(e)}_${n}`}function VCi(e){const{circuitJson:A,schematicSymbolId:t,schematicSymbol:i,schematicComponentId:n}=e,o=A.filter(Q=>Q.type==="schematic_circle"&&Q.schematic_symbol_id===t),s=A.filter(Q=>Q.type==="schematic_line"&&Q.schematic_symbol_id===t),r=n?A.filter(Q=>Q.type==="schematic_line"&&Q.schematic_component_id===n&&!Q.schematic_symbol_id):[],a=[...s,...r],g=A.filter(Q=>Q.type==="schematic_path"&&Q.schematic_symbol_id===t),c=A.filter(Q=>Q.type==="schematic_text"&&Q.schematic_symbol_id===t);let I=A.filter(Q=>Q.type==="schematic_port"&&"schematic_symbol_id"in Q&&Q.schematic_symbol_id===t);if(I.length===0&&n){const Q=A.filter(E=>E.type==="schematic_port"&&E.schematic_component_id===n&&E.display_pin_label!==void 0),h=new Map;for(const E of Q)E.display_pin_label&&h.set(E.display_pin_label,E);if(I=h.size>0?Array.from(h.values()):Q,I.length===0){const E=A.filter(d=>d.type==="schematic_port"&&d.schematic_component_id===n),u=new Set;I=E.filter(d=>{const f=d.pin_number;if(f!==void 0){if(u.has(f))return!1;u.add(f)}return!0})}}const l=[];for(const Q of o)l.push({type:"circle",x:Q.center?.x??0,y:Q.center?.y??0,radius:Q.radius??.5,fill:Q.is_filled??!1,fillColor:Q.fill_color});for(const Q of a)l.push({type:"path",points:[{x:Q.x1??0,y:Q.y1??0},{x:Q.x2??0,y:Q.y2??0}]});for(const Q of g)Q.points&&Q.points.length>0&&l.push({type:"path",points:Q.points,fill:Q.is_filled??!1,fillColor:Q.fill_color});const B=c.map(Q=>({text:Q.text??"",x:Q.position?.x??0,y:Q.position?.y??0,fontSize:Q.font_size??.2,anchor:Q.anchor??"center"})),C=I.map((Q,h)=>({x:Q.center?.x??0,y:Q.center?.y??0,labels:[Q.display_pin_label||`${Q.pin_number||h+1}`],pinNumber:Q.pin_number||h+1,facingDirection:Q.facing_direction}));return C.sort((Q,h)=>Q.pinNumber-h.pinNumber),{center:i.center||{x:0,y:0},size:i.size||{width:1,height:1},primitives:l,texts:B,ports:C}}function jCi({points:e,transform:A,fillType:t}){const i=new Cdt,n=e.map(a=>{const g=Ct(A,a);return new oh(g.x,g.y)}),o=new oQ(n);i.points=o;const s=new f1;s.width=.254,s.type="default",i.stroke=s;const r=new fdt;return r.type=t,i.fill=r,i}function zCi({primitive:e,transform:A,scale:t}){const i=new wdt,n=Ct(A,{x:e.x,y:e.y}),o=i;o._sxCenter=new ddt(n.x,n.y),o._sxRadius=new pdt(e.radius*t);const s=new f1;s.width=.254,s.type="default",o._sxStroke=s;const r=new ydt;return r.type=e.fill?"background":"none",o._sxFill=r,i}function XCi({schText:e,transform:A,scale:t}){const i=new Ddt,n=Ct(A,{x:e.x,y:e.y});i.value=e.text,i.at=[n.x,n.y,0];const o=e.fontSize*t,s=new Tp;return s.size={height:o,width:o},i.effects=new Jp({font:s}),i}function $Ci({libId:e,symbolData:A,isChip:t,c2kMatSchScale:i}){const n=new NM({libraryId:`${e.split(":")[1]}_0_1`}),o=i,s=A.center?.x??0,r=A.center?.y??0,a=tn(za(o,o),sn(-s,-r));for(const c of A.primitives||[])if(c.type==="path"&&c.points){const I=t||c.fill?"background":"none",l=jCi({points:c.points,transform:a,fillType:I});n.polylines.push(l)}else if(c.type==="circle"){const I=zCi({primitive:c,transform:a,scale:o});n.circles.push(I)}const g=Array.isArray(A.texts)?A.texts:[];for(const c of g){const I=XCi({schText:c,transform:a,scale:o});n.texts.push(I)}return n}function AQi(e,A){const t=A.schematic_port.list().filter(r=>r.schematic_component_id===e.schematic_component_id).sort((r,a)=>(r.pin_number||0)-(a.pin_number||0)),i=e.size?.width||1.5,n=e.size?.height||1,o={type:"path",points:[{x:-i/2,y:-n/2},{x:i/2,y:-n/2},{x:i/2,y:n/2},{x:-i/2,y:n/2},{x:-i/2,y:-n/2}]},s=t.map(r=>{const a=r.center.x-e.center.x,g=r.center.y-e.center.y;return{x:a,y:g,labels:[r.display_pin_label||`${r.pin_number||1}`],pinNumber:r.pin_number||1}});return{center:{x:0,y:0},primitives:[o],ports:s,size:{width:i,height:n}}}function tQi(e,A){const t=new Tp;return t.size={height:e,width:e},new Jp({font:t,hiddenText:A})}function eQi({symbol:e,libId:A,description:t,keywords:i,fpFilters:n,footprintRef:o="",referencePrefix:s}){const r=s||A.split(":")[1]?.[0]||"U",a=[{key:"Reference",value:r,id:0,at:[2.032,0,90],hide:!1},{key:"Value",value:r,id:1,at:[0,0,90],hide:!1},{key:"Footprint",value:o,id:2,at:[-1.778,0,90],hide:!0},{key:"Datasheet",value:"~",id:3,at:[0,0,0],hide:!0},{key:"Description",value:t,id:4,at:[0,0,0],hide:!0},{key:"ki_keywords",value:i,id:5,at:[0,0,0],hide:!0},{key:"ki_fp_filters",value:n,id:6,at:[0,0,0],hide:!0}];for(const g of a)e.properties.push(new Pp({key:g.key,value:g.value,id:g.id,at:g.at,effects:tQi(1.27,g.hide)}))}function iQi({port:e,center:A,size:t,isChip:i,portIndex:n,schematicComponent:o,schematicPorts:s,c2kMatSchScale:r}){const a=r;let g=e.x??0,c=e.y??0,I=!1;if(i&&n!==void 0&&o){const m=s.filter(w=>w.schematic_component_id===o.schematic_component_id).sort((w,D)=>(w.pin_number||0)-(D.pin_number||0));if(m[n]){const w=m[n];g=w.center.x-o.center.x,c=w.center.y-o.center.y,I=!0}}let l,B;if(I)l=g,B=c;else{const m=A?.x??0,w=A?.y??0;l=g-m,B=c-w}const C=za(a,a),Q=Ct(C,{x:l,y:B});let h;if(i&&t){const m=t.width/2,w=t.height/2,D=Math.abs(l)/m,x=Math.abs(B)/w;h=D>x}else h=Math.abs(l)>Math.abs(B);let E=Q.x,u=Q.y;const d=6;if(i&&t){const m=t.width/2*a,w=t.height/2*a;h?(E=l>0?m:-m,u=B*a):(E=l*a,u=B>0?w:-w)}let f=0;return h?l>0?(f=180,i&&(E=E+d)):(f=0,i&&(E=E-d)):B>0?(f=270,i&&(u=u+d)):(f=90,i&&(u=u-d)),{x:E,y:u,angle:f}}function nQi({libId:e,symbolData:A,isChip:t,schematicComponent:i,schematicPorts:n,c2kMatSchScale:o}){const s=new NM({libraryId:`${e.split(":")[1]}_1_1`}),r=6,a=2.54;for(let g=0;g<(A.ports?.length||0);g++){const c=A.ports[g],I=new jV;I.pinElectricalType="passive",I.pinGraphicStyle="line";const{x:l,y:B,angle:C}=iQi({port:c,center:A.center,size:A.size,isChip:t,portIndex:g,schematicComponent:i,schematicPorts:n,c2kMatSchScale:o});I.at=[l,B,C],I.length=t?r:a;const Q=new Tp;Q.size={height:1.27,width:1.27};const h=new Jp({font:Q}),E=c.labels?.[0]||"~";I._sxName=new rDA({value:E,effects:h});const u=new Tp;u.size={height:1.27,width:1.27};const d=new Jp({font:u}),f=c.pinNumber?.toString()||`${g+1}`;I._sxNumber=new Sdt({value:f,effects:d}),s.pins.push(I)}return s}var oQi=class extends t0{processedSymbolNames=new Set;_step(){const{kicadSch:e,db:A}=this.ctx,t=new Gdt,i=[];this.processedSymbolNames=new Set;const n=A.schematic_component.list();for(const s of n){const r=this.createLibrarySymbolForComponent(s);r&&i.push(r)}const o=A.schematic_net_label?.list?.()||[];for(const s of o)if(s.symbol_name){const r=s.source_net_id?A.source_net.get(s.source_net_id)?.is_power:!1,a=s.source_net_id?A.source_net.get(s.source_net_id)?.is_ground:!1;if(r||a){const c=this.createLibrarySymbolForNetLabel({netLabel:s,isPower:r??!1,isGround:a??!1});c&&i.push(c)}}t.symbols=i,e&&(e.libSymbols=t),this.finished=!0}createLibrarySymbolForComponent(e){const{db:A}=this.ctx,t=e.source_component_id?A.source_component.get(e.source_component_id):null;if(!t)return null;const i=A.cad_component?.list()?.find(c=>c.source_component_id===t.source_component_id);let n=e.schematic_symbol_id;if(!n){const c=this.ctx.circuitJson.find(I=>(I.type==="schematic_line"||I.type==="schematic_circle"||I.type==="schematic_path")&&I.schematic_component_id===e.schematic_component_id&&I.schematic_symbol_id);c&&(n=c.schematic_symbol_id)}if(n)return this.createLibrarySymbolFromSchematicSymbol(e,t,i,n);const o=e.symbol_name||(t.ftype==="simple_chip"?`generic_chip_${e.source_component_id}`:null);if(!o)return null;const s=this.getSymbolData(o,e);if(!s)return null;const r=Eyt(t,e,i),a=t.ftype==="simple_chip",g=U3(t,i);return this.createLibrarySymbol({libId:r,symbolData:s,isChip:a,schematicComponent:e,description:this.getDescription(t),keywords:this.getKeywords(t),fpFilters:this.getFpFilters(t),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:Ij(t)})}createLibrarySymbolFromSchematicSymbol(e,A,t,i){const{db:n}=this.ctx,o=this.ctx.circuitJson.find(c=>c.type==="schematic_symbol"&&c.schematic_symbol_id===i);if(!o)return null;let s;if(o.name)s=o.name;else{const c=U3(A,t);c?s=c:s=`custom_${A.ftype||"component"}_${i}`}const r=`Custom:${s}`;if(this.processedSymbolNames.has(r))return null;this.processedSymbolNames.add(r);const a=VCi({circuitJson:this.ctx.circuitJson,schematicSymbolId:i,schematicSymbol:o,schematicComponentId:e.schematic_component_id}),g=U3(A,t);return this.createLibrarySymbol({libId:r,symbolData:a,isChip:!1,schematicComponent:e,description:this.getDescription(A),keywords:this.getKeywords(A),fpFilters:this.getFpFilters(A,o.name),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:Ij(A),symbolScale:1})}createLibrarySymbolForNetLabel({netLabel:e,isPower:A,isGround:t}){const i=e.symbol_name;if(!i)return null;const n=qQ[i];if(!n)return null;const o=`Custom:${i}`;return this.createLibrarySymbol({libId:o,symbolData:n,isChip:!1,schematicComponent:void 0,description:A?"Power net label":t?"Ground net label":"Net symbol",keywords:A?"power net":t?"ground net":"net",fpFilters:"",referencePrefix:o.split(":")[1]?.[0]||"U"})}getSymbolData(e,A){return e.startsWith("generic_chip_")?AQi(A,this.ctx.db):qQ[e]||null}createLibrarySymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i,description:n,keywords:o,fpFilters:s,footprintRef:r="",referencePrefix:a,symbolScale:g}){const I=g??this.ctx.c2kMatSch?.a??15,l=new NM({libraryId:e,excludeFromSim:!1,inBom:!0,onBoard:!0}),B=new nDA;B.hide=!t,l._sxPinNumbers=B;const C=new sDA;C.offset=t?1.27:0,l._sxPinNames=C,eQi({symbol:l,libId:e,description:n,keywords:o,fpFilters:s,footprintRef:r,referencePrefix:a});const Q=$Ci({libId:e,symbolData:A,isChip:t,c2kMatSchScale:I});l.subSymbols.push(Q);const h=nQi({libId:e,symbolData:A,isChip:t,schematicComponent:i,schematicPorts:this.ctx.db.schematic_port.list(),c2kMatSchScale:I});return l.subSymbols.push(h),l._sxEmbeddedFonts=new GM(!1),l}getDescription(e){return e?.ftype==="simple_resistor"?"Resistor":e?.ftype==="simple_capacitor"?"Capacitor":e?.ftype==="simple_chip"?"Integrated Circuit":"Component"}getKeywords(e){return e?.ftype==="simple_resistor"?"R res resistor":e?.ftype==="simple_capacitor"?"C cap capacitor":e?.ftype==="simple_chip"?"U IC chip":""}getFpFilters(e,A){return A?`${A}*`:e?.ftype==="simple_resistor"?"R_*":e?.ftype==="simple_capacitor"?"C_*":(e?.ftype==="simple_chip","*")}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},sQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx,t=A.schematic_component.list();if(t.length===0){this.finished=!0;return}const i=[];for(const n of t){const o=n.source_component_id?A.source_component.get(n.source_component_id):null;if(!o||!this.ctx.c2kMatSch)continue;const{x:s,y:r}=Ct(this.ctx.c2kMatSch,{x:n.center.x,y:n.center.y}),a=crypto.randomUUID(),g=new NM({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:a,fieldsAutoplaced:!0}),c=A.cad_component?.list()?.find(oA=>oA.source_component_id===o.source_component_id);let I,l=n.schematic_symbol_id;if(!l){const oA=this.ctx.circuitJson.find(rA=>(rA.type==="schematic_line"||rA.type==="schematic_circle"||rA.type==="schematic_path")&&rA.schematic_component_id===n.schematic_component_id&&rA.schematic_symbol_id);oA&&(l=oA.schematic_symbol_id)}if(l){const oA=this.ctx.circuitJson.find(rA=>rA.type==="schematic_symbol"&&rA.schematic_symbol_id===l);if(oA?.name)I=oA.name;else{const rA=U3(o,c);rA?I=rA:I=`custom_${o.ftype||"component"}_${l}`}}const B=Eyt(o,n,c,I),C=new eDA(B);g._sxLibId=C;const{reference:Q,value:h,description:E}=this.getComponentMetadata(o),{refTextPos:u,valTextPos:d}=this.getTextPositions(n,{x:s,y:r});let f;if(l){const oA=this.ctx.circuitJson.find(rA=>rA.type==="schematic_symbol"&&rA.schematic_symbol_id===l);oA&&oA.type==="schematic_symbol"&&(f=oA.metadata?.kicad_symbol)}const m=f?.properties?.Reference,w=new Pp({key:"Reference",value:m?.value??Q,id:0,at:[u.x,u.y,0],effects:this.createTextEffects(Number(m?.effects?.font?.size?.x??1.27),m?.effects?.hide??!1)}),D=o.ftype==="simple_chip",x=f?.properties?.Value,_=new Pp({key:"Value",value:x?.value??h,id:1,at:[d.x,d.y,0],effects:this.createTextEffects(Number(x?.effects?.font?.size?.x??1.27),x?.effects?.hide??D)}),b=f?.properties?.Footprint,R=new Pp({key:"Footprint",value:b?.value??"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,b?.effects?.hide??!0)}),F=f?.properties?.Datasheet,H=new Pp({key:"Datasheet",value:F?.value??"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,F?.effects?.hide??!0)}),Y=f?.properties?.Description,J=new Pp({key:"Description",value:Y?.value??E,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,Y?.effects?.hide??!0)});g.properties.push(w,_,R,H,J);const O=f?.properties?.ki_keywords;if(O?.value){const oA=new Pp({key:"ki_keywords",value:O.value,id:5,at:[s,r,0],effects:this.createTextEffects(1.27,O.effects?.hide??!0)});g.properties.push(oA)}const W=f?.properties?.ki_fp_filters;if(W?.value){const oA=new Pp({key:"ki_fp_filters",value:W.value,id:6,at:[s,r,0],effects:this.createTextEffects(1.27,W.effects?.hide??!0)});g.properties.push(oA)}if(f){if(f.inBom!==void 0&&(g.inBom=f.inBom),f.onBoard!==void 0&&(g.onBoard=f.onBoard),f.excludeFromSim!==void 0&&(g.excludeFromSim=f.excludeFromSim),f.pinNames){const oA=new sDA;f.pinNames.offset!==void 0&&(oA.offset=Number(f.pinNames.offset)),f.pinNames.hide!==void 0&&(oA.hide=f.pinNames.hide),g.pinNames=oA}if(f.pinNumbers){const oA=new nDA;f.pinNumbers.hide!==void 0&&(oA.hide=f.pinNumbers.hide),g.pinNumbers=oA}f.embeddedFonts!==void 0&&(g._sxEmbeddedFonts=new GM(f.embeddedFonts))}let z=A.schematic_port.list().filter(oA=>oA.schematic_component_id===n.schematic_component_id);if(l){const oA=z.filter(rA=>rA.display_pin_label);oA.length>0&&(z=oA)}z.sort((oA,rA)=>(oA.pin_number||0)-(rA.pin_number||0));for(let oA=0;oA<z.length;oA++){const rA=z[oA];if(!rA)continue;const lA=new jV;lA.numberString=`${rA.pin_number||oA+1}`,lA.uuid=crypto.randomUUID(),g.pins.push(lA)}const tA=new aDA,aA=new cDA(""),eA=new IDA(`/${e?.uuid?.value||""}`);eA.reference=Q,eA.unit=1,aA.paths.push(eA),tA.projects.push(aA),g._sxInstances=tA,i.push(g)}e&&(e.symbols=i),this.finished=!0}getTextPositions(e,A){const i=(this.ctx.db.schematic_text?.list?.()?.filter(B=>B.schematic_component_id===e.schematic_component_id)||[]).find(B=>B.text&&B.text.length>0);if(i&&this.ctx.c2kMatSch){const B=Ct(this.ctx.c2kMatSch,{x:i.position.x,y:i.position.y}),C={x:A.x,y:A.y+6};return{refTextPos:B,valTextPos:C}}const n=e.symbol_name,o=qQ[n];if(!o)return{refTextPos:{x:A.x,y:A.y-6},valTextPos:{x:A.x,y:A.y+6}};let s=null,r=null;for(const B of o.primitives)B.type==="text"&&(B.text==="{REF}"?s=B:B.text==="{VAL}"&&(r=B));const a=o.center||{x:0,y:0},c=n.includes("_down")||n.includes("_up")?.15:0,I=s&&this.ctx.c2kMatSch?Ct(this.ctx.c2kMatSch,{x:e.center.x+(s.x-a.x)+c,y:e.center.y+(s.y-a.y)}):{x:A.x,y:A.y-6},l=r&&this.ctx.c2kMatSch?Ct(this.ctx.c2kMatSch,{x:e.center.x+(r.x-a.x)+c,y:e.center.y+(r.y-a.y)}):{x:A.x,y:A.y+6};return{refTextPos:I,valTextPos:l}}getComponentMetadata(e){const A=e.name||"?",t=ZCi(e);return e.ftype==="simple_resistor"?{reference:t,value:e.display_resistance||"R",description:"Resistor"}:e.ftype==="simple_capacitor"?{reference:t,value:e.display_capacitance||"C",description:"Capacitor"}:e.ftype==="simple_inductor"?{reference:t,value:e.display_inductance||"L",description:"Inductor"}:e.ftype==="simple_diode"?{reference:t,value:"D",description:"Diode"}:e.ftype==="simple_chip"?{reference:t,value:A,description:"Integrated Circuit"}:e.ftype==="simple_led"?{reference:t,value:e.manufacturer_part_number||"",description:"LED"}:e.ftype==="simple_switch"?{reference:t,value:e.manufacturer_part_number||"",description:"Switch"}:e.ftype==="simple_potentiometer"?{reference:t,value:e.display_max_resistance||"",description:"Potentiometer"}:{reference:t,value:A,description:"Component"}}createTextEffects(e,A=!1,t){const i=new Tp;i.size={height:e,width:e};const n=t?new a6({horizontal:t}):void 0;return new Jp({font:i,hiddenText:A,justify:n})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},rQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx,t=A.schematic_net_label?.list?.()||[];if(t.length===0){this.finished=!0;return}if(!this.ctx.c2kMatSch){this.finished=!0;return}const i=[],n=[];for(const o of t){const s=o.text||"",r=o.symbol_name;if(r){const a=this.createSymbolFromNetLabel(o,s,r);a&&i.push(a)}else{const a=this.createGlobalLabel(o,s);a&&n.push(a)}}if(e&&i.length>0){const o=e.symbols||[];e.symbols=[...o,...i]}e&&n.length>0&&(e.globalLabels=[...e.globalLabels||[],...n]),this.finished=!0}createSymbolFromNetLabel(e,A,t){if(!this.ctx.c2kMatSch)return null;const{x:i,y:n}=Ct(this.ctx.c2kMatSch,{x:e.anchor_position?.x??e.center?.x??0,y:e.anchor_position?.y??e.center?.y??0}),o=crypto.randomUUID(),s=new NM({at:[i,n,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:o,fieldsAutoplaced:!0}),r=`Custom:${t}`,a=new eDA(r);s._sxLibId=a;const g=t.includes("_up")||t.toLowerCase().includes("vcc"),c=g?-4:4,I=g?-6:6,l=new Pp({key:"Reference",value:A,id:0,at:[i,n+c,0],effects:this.createTextEffects(1.27,!1)}),B=new Pp({key:"Value",value:A,id:1,at:[i,n+I,0],effects:this.createTextEffects(1.27,!0)}),C=new Pp({key:"Footprint",value:"",id:2,at:[i-1.778,n,90],effects:this.createTextEffects(1.27,!0)}),Q=new Pp({key:"Datasheet",value:"~",id:3,at:[i,n,0],effects:this.createTextEffects(1.27,!0)}),h=new Pp({key:"Description",value:`Power/Net symbol: ${A}`,id:4,at:[i,n,0],effects:this.createTextEffects(1.27,!0)});s.properties.push(l,B,C,Q,h);const E=new jV;E.numberString="1",E.uuid=crypto.randomUUID(),s.pins.push(E);const{kicadSch:u}=this.ctx,d=new aDA,f=new cDA(""),m=new IDA(`/${u?.uuid?.value||""}`);return m.reference=A,m.unit=1,f.paths.push(m),d.projects.push(f),s._sxInstances=d,s}createGlobalLabel(e,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:t,y:i}=Ct(this.ctx.c2kMatSch,{x:e.anchor_position?.x??e.center?.x??0,y:e.anchor_position?.y??e.center?.y??0}),n=e.anchor_side||"left",s={left:0,right:180,top:270,bottom:90}[n]||0,a={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[n]||{},g=this.createTextEffects(1.27,!1);return Object.keys(a).length>0&&(g.justify=new a6(a)),new Pdt({value:A,at:[t,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(e,A=!1){const t=new Tp;return t.size={height:e,width:e},new Jp({font:t,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},aQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const t=A.schematic_trace.list();if(t.length===0){this.finished=!0;return}const i=[],n=[];for(const o of t){for(const s of o.edges){const r=this.createWireFromEdge(s);i.push(r)}for(const s of o.junctions){const r=this.createJunction(s);n.push(r)}}e.wires=i,e.junctions=n,this.finished=!0}createWireFromEdge(e){const A=new Ndt;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const t=Ct(this.ctx.c2kMatSch,{x:e.from.x,y:e.from.y}),i=Ct(this.ctx.c2kMatSch,{x:e.to.x,y:e.to.y}),n=t.x,o=t.y,s=i.x,r=i.y,a=new oQ([new oh(n,o),new oh(s,r)]);A.points=a;const g=new f1;return g.width=0,g.type="default",A.stroke=g,A.uuid=crypto.randomUUID(),A}createJunction(e){if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const{x:A,y:t}=Ct(this.ctx.c2kMatSch,{x:e.x,y:e.y}),i=new Ldt({at:[A,t],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},gQi=class extends t0{_step(){const{kicadSch:e}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const A=new QDA,t=new Odt;t.value="/";const i=new Wdt("1");t.pages=[i],A.paths=[t],e.sheetInstances=A,e.embeddedFonts=new GM(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function cQi(e){const A=e.schematic_component.list(),t=e.schematic_trace.list();let i=1/0,n=1/0,o=-1/0,s=-1/0;for(const g of A){const c=g.size?.width??0,I=g.size?.height??0;i=Math.min(i,g.center.x-c/2),n=Math.min(n,g.center.y-I/2),o=Math.max(o,g.center.x+c/2),s=Math.max(s,g.center.y+I/2)}for(const g of t)for(const c of g.edges)i=Math.min(i,c.from.x,c.to.x),n=Math.min(n,c.from.y,c.to.y),o=Math.max(o,c.from.x,c.to.x),s=Math.max(s,c.from.y,c.to.y);i===1/0&&(i=0,n=0,o=0,s=0);const r=(i+o)/2,a=(n+s)/2;return{center:{x:r,y:a},bounds:{minX:i,minY:n,maxX:o,maxY:s}}}var lj=[{name:"A4",width:297,height:210},{name:"A3",width:420,height:297},{name:"A2",width:594,height:420},{name:"A1",width:841,height:594},{name:"A0",width:1189,height:841}];function IQi(e,A,t=20){const i=e+2*t,n=A+2*t;for(let o=0;o<lj.length;o++){const s=lj[o];if(i<=s.width&&n<=s.height)return s}return lj[lj.length-1]}var uyt=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e){const t=Na(e),{center:i,bounds:n}=cQi(t),o=(n.maxX-n.minX)*15,s=(n.maxY-n.minY)*15,r=IQi(o,s),a=r.width/2,g=r.height/2;this.ctx={db:t,circuitJson:e,kicadSch:new EDA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:r,c2kMatSch:tn(sn(a,g),za(15,-15),sn(-i.x,-i.y))},this.pipeline=[new qCi(e,this.ctx),new oQi(e,this.ctx),new sQi(e,this.ctx),new rQi(e,this.ctx),new aQi(e,this.ctx),new gQi(e,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadSch}getOutputString(){return this.ctx.kicadSch.getString()}},lQi=class extends t0{_step(){const{kicadPcb:e,db:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");const i=A.pcb_board?.list()?.[0]?.num_layers??2;this.ctx.numLayers=i,e.version=20241229;const n=new OV;n.size="A4",e.paper=n;const o=new d2A;o.thickness=1.6,e.general=o;const s=new u2A;s.padToMaskClearance=0,e.setup=s;const r=new p2A,a=[new Zl({index:0,name:"F.Cu",type:"signal"})];for(let g=1;g<i-1;g++)a.push(new Zl({index:g,name:`In${g}.Cu`,type:"signal"}));a.push(new Zl({index:31,name:"B.Cu",type:"signal"})),a.push(new Zl({index:32,name:"B.Adhes",type:"user"}),new Zl({index:33,name:"F.Adhes",type:"user"}),new Zl({index:34,name:"B.Paste",type:"user"}),new Zl({index:35,name:"F.Paste",type:"user"}),new Zl({index:36,name:"B.SilkS",type:"user"}),new Zl({index:37,name:"F.SilkS",type:"user"}),new Zl({index:38,name:"B.Mask",type:"user"}),new Zl({index:39,name:"F.Mask",type:"user"}),new Zl({index:40,name:"Dwgs.User",type:"user"}),new Zl({index:41,name:"Cmts.User",type:"user"}),new Zl({index:42,name:"Eco1.User",type:"user"}),new Zl({index:43,name:"Eco2.User",type:"user"}),new Zl({index:44,name:"Edge.Cuts",type:"user"}),new Zl({index:45,name:"Margin",type:"user"}),new Zl({index:46,name:"B.CrtYd",type:"user"}),new Zl({index:47,name:"F.CrtYd",type:"user"}),new Zl({index:48,name:"B.Fab",type:"user"}),new Zl({index:49,name:"F.Fab",type:"user"})),r.definitions=a,e.layers=r,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},BQi=class extends t0{_step(){const{kicadPcb:e}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");this.ctx.pcbNetMap=new Map;const A=new Map,t=this.ctx.db.source_net?.list()??[];for(const r of t){const a=r.subcircuit_connectivity_map_key||r.source_net_id;if(!a)continue;const g=r.name||r.source_net_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}const i=this.ctx.db.source_trace?.list()??[];for(const r of i){let a=r.subcircuit_connectivity_map_key;if(!a&&r.connected_source_net_ids?.length)for(const g of r.connected_source_net_ids){const c=this.ctx.db.source_net?.get(g);if(c?.subcircuit_connectivity_map_key&&c.subcircuit_connectivity_map_key.length>0){a=c.subcircuit_connectivity_map_key;break}}if(a&&!A.has(a)){const g=r.display_name||r.source_trace_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}}const n=Array.from(A.entries()).sort((r,a)=>r[0].localeCompare(a[0])),o=[];o.push(new cj(0,""));let s=1;for(const[r,a]of n){const g=new cj(s,a);o.push(g);const c={id:s,name:a};this.ctx.pcbNetMap.set(r,c),s++}e.nets=o,this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function CQi(e){let A=0;for(let i=0;i<e.length;i++){const n=e.charCodeAt(i);A=(A<<5)-A+n,A=A&A}let t="";for(let i=0;i<4;i++){let n=A;for(let o=0;o<e.length;o++)n=(n<<5)-n+e.charCodeAt(o)+i*31,n=n&n;t+=Math.abs(n).toString(16).padStart(8,"0")}return t}function cd(e){const A=CQi(e);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}var dyt="https://modelcdn.tscircuit.com/jscad_models",QQi=20240108,hQi="pcbnew",EQi="8.0";function b2A(e){const A=e.split(/[/\\]/),t=A[A.length-1]||e;return t.split("?")[0]||t}var uQi=class extends t0{classifyFootprints(){const e=new Set,A=new Map,t=this.ctx.db.cad_component?.list()??[],i=this.ctx.db.source_component;for(const n of t){const o=n.source_component_id?i?.get(n.source_component_id):null;if(!o)continue;const s=U3(o,n);if(n.footprinter_string)A.set(s,n.footprinter_string);else{e.add(s);const r=this.ctx.circuitJson.find(a=>a.type==="pcb_component"&&a.source_component_id===n.source_component_id);r&&r.type==="pcb_component"&&r.metadata?.kicad_footprint?.footprintName&&e.add(r.metadata.kicad_footprint.footprintName)}}return{customFootprintNames:e,footprinterStrings:A}}_step(){const e=this.ctx.kicadPcbString,A=this.ctx.fpLibraryName??"tscircuit";if(!e)throw new Error("PCB content not available. Run GenerateKicadSchAndPcbStage first.");const{customFootprintNames:t,footprinterStrings:i}=this.classifyFootprints(),n=new Map;try{const s=lyt(e).find(a=>a instanceof x2A);if(!s){this.ctx.footprintEntries=[],this.finished=!0;return}const r=s.footprints??[];for(const a of r){const g=this.sanitizeFootprint({footprint:a,fpLibraryName:A,customFootprintNames:t,footprinterStrings:i});n.has(g.footprintName)||n.set(g.footprintName,g)}}catch(o){console.warn("Failed to parse PCB for footprint extraction:",o)}this.ctx.footprintEntries=Array.from(n.values()),this.finished=!0}sanitizeFootprint({footprint:e,fpLibraryName:A,customFootprintNames:t,footprinterStrings:i}){const o=(e.libraryLink??"footprint").split(":"),s=(o.length>1?o[1]:o[0])?.replace(/[\\\/]/g,"-").trim()||"footprint",r=!t.has(s);if(e.libraryLink=s,e.position=oc.from([0,0,0]),e.locked=!1,e.placed=!1,e.version=QQi,e.generator=hQi,e.generatorVersion=EQi,e.descr||(e.descr=""),e.tags||(e.tags=""),e.embeddedFonts||(e.embeddedFonts=new GM(!1)),!e.attr){const f=new uDA,m=(e.fpPads??[]).map(w=>w.padType);m.some(w=>w.includes("thru_hole"))?f.type="through_hole":m.some(w=>w.includes("smd"))&&(f.type="smd"),e.attr=f}e.uuid=void 0,e.path=void 0,e.sheetfile=void 0,e.sheetname=void 0;const a=new Tp;a.size={width:1.27,height:1.27},a.thickness=.15;const g=new Jp({font:a}),c=e.fpPads??[];let I=0,l=0;for(const f of c){const m=f.at,w=f.size;if(m&&w){const D=m.y??0,x=w.height??0,_=D-x/2,b=D+x/2;I=Math.min(I,_),l=Math.max(l,b)}}const B=I-.5,C=l+.5;e.properties=[new y1({key:"Reference",value:"REF**",position:[0,B,0],layer:"F.SilkS",uuid:cd(`${s}-property-Reference`),effects:g}),new y1({key:"Value",value:"Val**",position:[0,C,0],layer:"F.Fab",uuid:cd(`${s}-property-Value`),effects:g}),new y1({key:"Datasheet",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:cd(`${s}-property-Datasheet`),effects:g}),new y1({key:"Description",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:cd(`${s}-property-Description`),effects:g})];const Q=e.fpTexts??[];for(const f of Q)f.uuid=void 0,f.type==="reference"?f.text="REF**":f.type==="value"&&f.text.trim().length===0&&(f.text=s);e.fpTexts=Q;const h=e.fpPads??[];for(let f=0;f<h.length;f++){const m=h[f];m&&(m.uuid=cd(`${s}-pad-${m.number??f}`),m.net=void 0)}e.fpPads=h;const E=e.models??[],u=[],d=[];for(const f of E)if(f.path){const m=b2A(f.path),x=`../../3dmodels/${f.path.startsWith("http://modelcdn.tscircuit.com")||f.path.startsWith("https://modelcdn.tscircuit.com")?"tscircuit_builtin":A}.3dshapes/${m}`,_=new L3(x);f.offset&&(_.offset=f.offset),f.scale&&(_.scale=f.scale),f.rotate&&(_.rotate=f.rotate),u.push(_),d.push(f.path.split("?")[0]??f.path)}if(u.length===0){const f=i.get(s);if(f){const m=`${dyt}/${f}.step`,D=`../../3dmodels/tscircuit_builtin.3dshapes/${b2A(m)}`;u.push(new L3(D)),d.push(m)}}return e.models=u,{footprintName:s,kicadModString:e.getString(),model3dSourcePaths:d,isBuiltin:r}}getOutput(){return this.ctx.libraryOutput}};function Bj(e){const A=new Tp;return e?.font?.size?A.size={width:Number(e.font.size.x),height:Number(e.font.size.y)}:A.size={width:1.27,height:1.27},e?.font?.thickness!==void 0?A.thickness=Number(e.font.thickness):A.thickness=.15,new Jp({font:A})}function dQi(e,A,t){if(A.properties){const i=[],n=A.properties.Reference;i.push(new y1({key:"Reference",value:n?.value??t,position:n?.at?[Number(n.at.x),Number(n.at.y),Number(n.at.rotation??0)]:[0,-3,0],layer:n?.layer??"F.SilkS",uuid:cd(`${t}-property-Reference`),effects:Bj(n?.effects),hidden:n?.hide}));const o=A.properties.Value,s=o?.value??A.footprintName??"";i.push(new y1({key:"Value",value:s,position:o?.at?[Number(o.at.x),Number(o.at.y),Number(o.at.rotation??0)]:[0,3,0],layer:o?.layer??"F.Fab",uuid:cd(`${t}-property-Value`),effects:Bj(o?.effects),hidden:o?.hide}));const r=A.properties.Datasheet;i.push(new y1({key:"Datasheet",value:r?.value??"",position:r?.at?[Number(r.at.x),Number(r.at.y),Number(r.at.rotation??0)]:[0,0,0],layer:r?.layer??"F.Fab",uuid:cd(`${t}-property-Datasheet`),effects:Bj(r?.effects),hidden:r?.hide??!0}));const a=A.properties.Description;i.push(new y1({key:"Description",value:a?.value??"",position:a?.at?[Number(a.at.x),Number(a.at.y),Number(a.at.rotation??0)]:[0,0,0],layer:a?.layer??"F.Fab",uuid:cd(`${t}-property-Description`),effects:Bj(a?.effects),hidden:a?.hide??!0})),e.properties=i}if(A.attributes&&(e.attr||(e.attr=new uDA),A.attributes.through_hole?e.attr.type="through_hole":A.attributes.smd&&(e.attr.type="smd"),A.attributes.exclude_from_pos_files!==void 0&&(e.attr.excludeFromPosFiles=A.attributes.exclude_from_pos_files),A.attributes.exclude_from_bom!==void 0&&(e.attr.excludeFromBom=A.attributes.exclude_from_bom)),A.footprintName&&(e.libraryLink=A.footprintName),A.layer&&(e.layer=A.layer),A.embeddedFonts!==void 0&&(e.embeddedFonts=new GM(A.embeddedFonts)),A.model){const i=new L3(A.model.path);A.model.offset&&(i.offset={x:Number(A.model.offset.x),y:Number(A.model.offset.y),z:Number(A.model.offset.z)}),A.model.scale&&(i.scale={x:Number(A.model.scale.x),y:Number(A.model.scale.y),z:Number(A.model.scale.z)}),A.model.rotate&&(i.rotate={x:Number(A.model.rotate.x),y:Number(A.model.rotate.y),z:Number(A.model.rotate.z)});const n=e.models||[];e.models=[i,...n]}}function pQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.SilkS",bottom:"B.SilkS"}[i.layer]||i.layer||"F.SilkS",a=new t1A({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new f1,fill:!1});a.stroke&&(a.stroke.width=i.stroke_width||.05,a.stroke.type="default"),t.push(a)}return t}function fQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",a=new t1A({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new f1,fill:!1});a.stroke&&(a.stroke.width=.05,a.stroke.type="default"),t.push(a)}return t}function yQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.Fab",bottom:"B.Fab"}[i.layer]||i.layer||"F.Fab",c=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new f1,fill:!1});c.stroke&&(c.stroke.width=i.stroke_width||.1,c.stroke.type="default"),t.push(c)}return t}function mQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,a="F.Fab",g=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:a,stroke:new f1,fill:!1});g.stroke&&(g.stroke.width=i.stroke_width||.1,g.stroke.type="default"),t.push(g)}return t}function wQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",c=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new f1,fill:!1});c.stroke&&(c.stroke.width=.05,c.stroke.type="default"),t.push(c)}return t}function DQi(e,A){const t=[];for(const i of e){if(!i.outline||i.outline.length<2)continue;const o={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",s=i.outline.map(g=>{const c=g.x-A.x,I=-(g.y-A.y);return new oh(c,I)}),r=new Hpt;r.points=new oQ(s),r.layer=o,r.fill=!1;const a=new f1;a.width=.05,a.type="default",r.stroke=a,t.push(r)}return t}function xQi({textElement:e,componentCenter:A,componentRotation:t=0}){if(!e.text||!e.anchor_position)return null;const i=e.anchor_position.x-A.x,n=-(e.anchor_position.y-A.y),o=t!==0?Jl(t*Math.PI/180):Sa(),s=Ct(o,{x:i,y:n}),r={x:s.x,y:s.y},g={top:"F.SilkS",bottom:"B.SilkS"}[e.layer]||e.layer||"F.SilkS",c=(e.font_size||1)/1.5,I=new Tp;I.size={width:c,height:c};const l=new Jp({font:I}),B=e.ccw_rotation||0;return new qDA({type:"user",text:e.text,position:{x:r.x,y:r.y,angle:B},layer:g,effects:l})}function SQi(e,A,t,i){const n=[];for(const o of e){const s=xQi({textElement:o,componentCenter:A,componentRotation:t});s&&(i&&o.text===i&&(s.type="reference"),n.push(s))}return n}function bQi(e,A,t){const i=[];for(const n of e){const o=n.anchor_position.x-A.x,s=-(n.anchor_position.y-A.y),r=t!==0?Jl(t*Math.PI/180):Sa(),a=Ct(r,{x:o,y:s}),g=n.font_size||1,c=new Tp;c.size={width:g,height:g};const I=new Jp({font:c}),l=new qDA({type:"user",text:n.text,position:{x:a.x,y:a.y,angle:0},layer:"F.Fab",effects:I});i.push(l)}return i}function _Qi(e,A,t){const i=[],n=e.model_step_url||e.model_wrl_url;if(!n)return i;const o=new L3(n);if(e.position){const s=t?.boardLayerZOffset??0;o.offset={x:(e.position.x||0)-A.x,y:-((e.position.y||0)-A.y),z:(e.position.z||0)-s}}if(e.rotation&&(o.rotate={x:e.rotation.x||0,y:e.rotation.y||0,z:e.rotation.z||0}),e.model_unit_to_mm_scale_factor){const s=e.model_unit_to_mm_scale_factor;o.scale={x:s,y:s,z:s}}return i.push(o),i}function kQi({pcbPad:e,componentCenter:A,padNumber:t,componentRotation:i=0,netInfo:n,componentId:o}){let s,r;if("x"in e&&"y"in e)s=e.x,r=e.y;else if("points"in e&&Array.isArray(e.points)){const u=e.points;s=u.reduce((d,f)=>d+f.x,0)/u.length,r=u.reduce((d,f)=>d+f.y,0)/u.length}else throw new Error("Pad must have either x/y coordinates or points array");const a=tn(i!==0?Jl(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},za(1,-1),sn(-A.x,-A.y)),g=Ct(a,{x:s,y:r}),I={top:"F.Cu",bottom:"B.Cu"}[e.layer]||"F.Cu";let l,B,C,Q;if(e.shape==="circle")l="circle",B=["radius"in e?e.radius*2:.5,"radius"in e?e.radius*2:.5];else if(e.shape==="polygon"&&"points"in e){const u=e.points,d=tn(za(1,-1),sn(-s,-r)),f=u.map(w=>{const D=Ct(d,{x:w.x,y:w.y});return new oh(D.x,D.y)}),m=new YDA;m.contours=[new oQ(f)],m.width=0,m.filled=!0,Q=new ypt,Q.addGraphic(m),l="custom",C=new opt,C.anchor="circle",B=[.2,.2]}else l="rect",B=["width"in e?e.width:.5,"height"in e?e.height:.5];const h=`pad:${o}:${t}:${g.x},${g.y}`,E=new $V({number:String(t),padType:"smd",shape:l,at:[g.x,g.y,0],size:B,layers:[`${I}`,`${I==="F.Cu"?"F":"B"}.Paste`,`${I==="F.Cu"?"F":"B"}.Mask`],uuid:cd(h)});return C&&(E.options=C),Q&&(E.primitives=Q),n&&(E.net=new GDA(n.id,n.name)),E}function vQi(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=kQi({pcbPad:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});s.push(c),r++}return{pads:s,nextPadNumber:r}}function FQi({platedHole:e,componentCenter:A,padNumber:t,componentRotation:i=0,netInfo:n,componentId:o}){if(!("x"in e&&"y"in e))return null;const s=e.x-A.x,r=-(e.y-A.y),a=i!==0?Jl(i*Math.PI/180):Sa(),g=Ct(a,{x:s,y:r});let c="circle",I,l,B=0;const C="hole_offset_x"in e||"hole_offset_y"in e;let Q;if(C){const u={x:e.hole_offset_x??0,y:e.hole_offset_y??0};(u.x!==0||u.y!==0)&&(Q=Ct(a,{x:-u.x,y:u.y}))}e.shape==="circle"?(c="circle",I=[e.outer_diameter,e.outer_diameter],l=new m1({diameter:e.hole_diameter,offset:Q})):e.shape==="pill"||e.shape==="oval"?(c="oval",I=[e.outer_width,e.outer_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q})):e.shape==="pill_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q})):e.shape==="circular_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({diameter:e.hole_diameter,offset:Q})):e.shape==="rotated_pill_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q}),B=e.rect_ccw_rotation||0):(c="circle",I=[1.6,1.6],l=new m1({diameter:.8,offset:Q}));const h=`thruhole:${o}:${t}:${g.x},${g.y}`,E=new $V({number:String(t),padType:"thru_hole",shape:c,at:[g.x,g.y,B],size:I,drill:l,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:cd(h)});return n&&(E.net=new GDA(n.id,n.name)),E}function MQi(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=FQi({platedHole:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});c&&(s.push(c),r++)}return{pads:s,nextPadNumber:r}}function GQi({pcbHole:e,componentCenter:A,componentRotation:t=0}){if(!("x"in e&&"y"in e))return null;const i=e.x-A.x,n=-(e.y-A.y),o=t!==0?Jl(t*Math.PI/180):Sa(),s=Ct(o,{x:i,y:n});let r="circle",a,g;if(e.hole_shape==="circle"){r="circle";const c=e.hole_diameter;a=[c,c],g=new m1({diameter:c})}else if(e.hole_shape==="oval"){r="oval";const c=e.hole_width,I=e.hole_height;a=[c,I],g=new m1({oval:!0,diameter:c,width:I})}else{r="circle";const c="hole_diameter"in e?e.hole_diameter:1;a=[c,c],g=new m1({diameter:c})}return new $V({number:"",padType:"np_thru_hole",shape:r,at:[s.x,s.y,0],size:a,drill:g,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:crypto.randomUUID()})}function pyt(e,A,t){const i=[];for(const n of e){const o=GQi({pcbHole:n,componentCenter:A,componentRotation:t});o&&i.push(o)}return i}var RQi=class extends t0{componentsProcessed=0;pcbComponents=[];includeBuiltin3dModels;getNetInfoForPcbPort(e){if(!e)return;const A=this.ctx.db.pcb_port?.get(e);if(!A)return;const t=A.source_port_id;if(!t)return;const i=this.ctx.db.source_port?.get(t);if(!i)return;const n=i.subcircuit_connectivity_map_key;if(n)return this.ctx.pcbNetMap?.get(n)}getCadComponentForPcbComponent(e){return(this.ctx.db.cad_component?.list()||[]).find(t=>t.pcb_component_id===e)}constructor(e,A,t){super(e,A),this.pcbComponents=this.ctx.db.pcb_component.list(),this.includeBuiltin3dModels=t?.includeBuiltin3dModels??!1}_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.componentsProcessed>=this.pcbComponents.length){this.finished=!0;return}const t=this.pcbComponents[this.componentsProcessed],i=t.source_component_id?this.ctx.db.source_component.get(t.source_component_id):null,n=this.getCadComponentForPcbComponent(t.pcb_component_id),o=i?U3(i,n):"Unknown",s=Ct(A,{x:t.center.x,y:t.center.y}),r=`footprint:${t.pcb_component_id}:${s.x},${s.y}`,a=new nj({libraryLink:`tscircuit:${o}`,layer:"F.Cu",at:[s.x,s.y,t.rotation||0],uuid:cd(r)}),g=a.fpTexts,c=this.ctx.db.pcb_silkscreen_text?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];g.push(...SQi(c,t.center,t.rotation||0,i?.name));const I=this.ctx.db.pcb_note_text?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];g.push(...bQi(I,t.center,t.rotation||0)),a.fpTexts=g;const l=a.fpPads,B=O=>this.getNetInfoForPcbPort(O),C=this.ctx.db.pcb_smtpad?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],{pads:Q,nextPadNumber:h}=vQi(C,t.center,t.rotation||0,t.pcb_component_id,1,B);l.push(...Q);const E=this.ctx.db.pcb_plated_hole?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],{pads:u}=MQi(E,t.center,t.rotation||0,t.pcb_component_id,h,B);l.push(...u);const d=this.ctx.db.pcb_hole?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],f=pyt(d,t.center,t.rotation||0);l.push(...f),a.fpPads=l;const m=this.ctx.db.pcb_silkscreen_circle?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],w=a.fpCircles??[];w.push(...pQi(m,t.center));const D=this.ctx.db.pcb_courtyard_circle?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];w.push(...fQi(D,t.center)),a.fpCircles=w;const x=this.ctx.db.pcb_fabrication_note_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],_=a.fpRects??[];_.push(...yQi(x,t.center));const b=this.ctx.db.pcb_note_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];_.push(...mQi(b,t.center));const R=this.ctx.db.pcb_courtyard_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];_.push(...wQi(R,t.center)),a.fpRects=_;const F=this.ctx.db.pcb_courtyard_outline?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],H=DQi(F,t.center);if(H.length>0&&(a.fpPolys=H),n){const W=this.ctx.db.pcb_board?.list()[0]?.thickness??0,z=t.layer==="bottom"?-(W/2):W/2,tA=_Qi(n,t.center,{boardLayerZOffset:z}),aA="${KIPRJMOD}/3dmodels";if(tA.length>0)this.includeBuiltin3dModels?a.models=tA.map(eA=>{if(!eA.path)return eA;const oA=b2A(eA.path),lA=eA.path.startsWith("http://modelcdn.tscircuit.com")||eA.path.startsWith("https://modelcdn.tscircuit.com")?"tscircuit_builtin":this.ctx.projectName??oA.replace(/\.[^.]+$/,""),pA=new L3(`${aA}/${lA}.3dshapes/${oA}`);eA.offset&&(pA.offset=eA.offset),eA.scale&&(pA.scale=eA.scale),eA.rotate&&(pA.rotate=eA.rotate);const kA=eA.path?.split("?")[0];return kA&&!this.ctx.pcbModel3dSourcePaths?.includes(kA)&&this.ctx.pcbModel3dSourcePaths?.push(kA),pA}):a.models=tA;else if(n.footprinter_string&&this.includeBuiltin3dModels){const{footprinter_string:eA}=n,oA=`${aA}/tscircuit_builtin.3dshapes/${eA}.step`;a.models=[new L3(oA)];const rA=`${dyt}/${eA}.step`;this.ctx.pcbModel3dSourcePaths?.includes(rA)||this.ctx.pcbModel3dSourcePaths?.push(rA)}}const Y=t.metadata?.kicad_footprint;Y&&i?.name&&dQi(a,Y,i.name);const J=e.footprints;J.push(a),e.footprints=J,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},NQi={top:"F.Cu",bottom:"B.Cu",inner1:"In1.Cu",inner2:"In2.Cu",inner3:"In3.Cu",inner4:"In4.Cu",inner5:"In5.Cu",inner6:"In6.Cu"};function LQi(e){return e&&(NQi[e]||e)||"F.Cu"}function UQi(e){const A=["F.Cu"];for(let t=1;t<e-1;t++)A.push(`In${t}.Cu`);return A.push("B.Cu"),A}var HQi=class extends t0{tracesProcessed=0;pcbTraces=[];constructor(e,A){super(e,A),this.pcbTraces=this.ctx.db.pcb_trace.list()}_step(){const{kicadPcb:e,c2kMatPcb:A,pcbNetMap:t}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.tracesProcessed>=this.pcbTraces.length){this.finished=!0;return}const i=this.pcbTraces[this.tracesProcessed];if(!i.route||i.route.length<2){this.tracesProcessed++;return}let n=i.route[0]?.layer;for(let o=0;o<i.route.length-1;o++){const s=i.route[o],r=i.route[o+1],a=Ct(A,{x:s.x,y:s.y}),g=Ct(A,{x:r.x,y:r.y});let c;if(t){let h=i.subcircuit_connectivity_map_key;if(!h&&i.source_trace_id){const E=this.ctx.db.source_trace?.get(i.source_trace_id);if(E&&(h=E.subcircuit_connectivity_map_key,!h&&E.connected_source_net_ids?.length))for(const u of E.connected_source_net_ids){const d=this.ctx.db.source_net?.get(u);if(d?.subcircuit_connectivity_map_key){h=d.subcircuit_connectivity_map_key;break}}}if(!h&&typeof i.connection_name=="string"){const E=this.ctx.db.source_net?.get(i.connection_name);E?.subcircuit_connectivity_map_key&&(h=E.subcircuit_connectivity_map_key)}h&&(c=t.get(h))}const I=s.layer??r.layer??n,l=LQi(I),B=`segment:${a.x},${a.y}:${g.x},${g.y}:${l}:${c?.id??0}`,C=new _1A({start:{x:a.x,y:a.y},end:{x:g.x,y:g.y},layer:l,width:i.width||.25,net:new rj(c?.id??0),uuid:cd(B)}),Q=e.segments;Q.push(C),e.segments=Q,s.layer&&(n=s.layer),r.layer&&(n=r.layer)}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},YQi=class extends t0{viasProcessed=0;pcbVias=[];constructor(e,A){super(e,A),this.pcbVias=this.ctx.db.pcb_via?.list()||[]}_step(){const{kicadPcb:e,c2kMatPcb:A,pcbNetMap:t}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.viasProcessed>=this.pcbVias.length){this.finished=!0;return}const i=this.pcbVias[this.viasProcessed],n=Ct(A,{x:i.x,y:i.y});let o;if(t){let I=i.subcircuit_connectivity_map_key;if(!I&&i.pcb_trace_id){const l=this.ctx.db.pcb_trace?.get(i.pcb_trace_id);if(l&&("subcircuit_connectivity_map_key"in l&&(I=l.subcircuit_connectivity_map_key),!I&&l.source_trace_id)){const B=this.ctx.db.source_trace?.get(l.source_trace_id);if(B&&("subcircuit_connectivity_map_key"in B&&(I=B.subcircuit_connectivity_map_key),!I&&B.connected_source_net_ids?.length))for(const C of B.connected_source_net_ids){const Q=this.ctx.db.source_net?.get(C);if(Q?.subcircuit_connectivity_map_key){I=Q.subcircuit_connectivity_map_key;break}}}}if(!I&&i.connection_name){const l=this.ctx.db.source_net?.get(i.connection_name);l?.subcircuit_connectivity_map_key&&(I=l.subcircuit_connectivity_map_key)}I&&(o=t.get(I))}const s=this.ctx.numLayers??2,r=i.layers?i.layers.map(I=>I==="top"?"F.Cu":I==="bottom"?"B.Cu":`In${I.replace("inner","")}.Cu`):UQi(s),a=`via:${n.x},${n.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${o?.id??0}`,g=new D2A({at:[n.x,n.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:r,net:new w2A(o?.id??0),uuid:cd(a)}),c=e.vias;c.push(g),e.vias=c,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}},JQi=class extends t0{holesProcessed=0;standaloneHoles=[];constructor(e,A){super(e,A),this.standaloneHoles=this.ctx.db.pcb_hole.list().filter(t=>!t.pcb_component_id)}_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.holesProcessed>=this.standaloneHoles.length){this.finished=!0;return}const t=this.standaloneHoles[this.holesProcessed];if(!t){this.holesProcessed++;return}const i=Ct(A,{x:0,y:0}),n=`standalone_hole:${t.pcb_hole_id}:${t.x},${t.y}`,o=new nj({libraryLink:"tscircuit:MountingHole",layer:"F.Cu",at:[i.x,i.y,0],uuid:cd(n)}),r=pyt([t],{x:0,y:0},0);if(r.length>0){o.fpPads=r;const a=e.footprints;a.push(o),e.footprints=a}this.holesProcessed++}getOutput(){return this.ctx.kicadPcb}};function TQi({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Ct(A,{x:e.anchor_position.x,y:e.anchor_position.y}),n={top:"F.Fab",bottom:"B.Fab"}[e.layer]||e.layer||"F.Fab",o=(e.font_size||1)/1.5,s=new Tp;s.size={width:o,height:o};const r=new a6,a=e.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new Jp({font:s});a!=="center"&&(g.justify=r);const c=new oc([t.x,t.y,0]),I=new sj({text:e.text,layer:n,effects:g});return I.position=c,I}function PQi({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Ct(A,{x:e.anchor_position.x,y:e.anchor_position.y}),n={top:"F.SilkS",bottom:"B.SilkS"}[e.layer]||e.layer||"F.SilkS",o=(e.font_size||1)/1.5,s=new Tp;s.size={width:o,height:o};const r=new a6,a=e.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new Jp({font:s});a!=="center"&&(g.justify=r);const c=e.ccw_rotation||0,I=new oc([t.x,t.y,c]),l=new sj({text:e.text,layer:n,effects:g});return l.position=I,l}var KQi=class extends t0{_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");const t=this.ctx.db.pcb_silkscreen_path?.list()||[];for(const s of t)if(!(!s.route||s.route.length<2))for(let r=0;r<s.route.length-1;r++){const a=s.route[r],g=s.route[r+1];if(!a||!g)continue;const c=Ct(A,{x:a.x,y:a.y}),I=Ct(A,{x:g.x,y:g.y}),B={top:"F.SilkS",bottom:"B.SilkS"}[s.layer]||s.layer||"F.SilkS",C=new oj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:B,width:s.stroke_width||.15}),Q=e.graphicLines;Q.push(C),e.graphicLines=Q}const i=this.ctx.db.pcb_silkscreen_text?.list().filter(s=>!s.pcb_component_id)||[];for(const s of i){const r=PQi({textElement:s,c2kMatPcb:A});if(r){const a=e.graphicTexts;a.push(r),e.graphicTexts=a}}const n=this.ctx.db.pcb_fabrication_note_text?.list()||[];for(const s of n){const r=TQi({textElement:s,c2kMatPcb:A});if(r){const a=e.graphicTexts;a.push(r),e.graphicTexts=a}}const o=this.ctx.db.pcb_board?.list()||[];if(o.length>0){const s=o[0];if(!s){this.finished=!0;return}let r;if(s.outline&&s.outline.length>0)r=s.outline;else{const g=s.width?s.width/2:0,c=s.height?s.height/2:0;r=[{x:s.center.x-g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y+c},{x:s.center.x-g,y:s.center.y+c}]}const a=r.map(g=>Ct(A,g));for(let g=0;g<a.length;g++){const c=a[g],I=a[(g+1)%a.length];if(!c||!I)continue;const l=new oj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:"Edge.Cuts",width:.1}),B=e.graphicLines;B.push(l),e.graphicLines=B}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},fyt=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e,A){this.ctx={db:Na(e),circuitJson:e,kicadPcb:new x2A({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:tn(sn(100,100),za(1,-1)),projectName:A?.projectName,pcbModel3dSourcePaths:[]},this.pipeline=[new lQi(e,this.ctx),new BQi(e,this.ctx),new RQi(e,this.ctx,{includeBuiltin3dModels:A?.includeBuiltin3dModels}),new HQi(e,this.ctx),new YQi(e,this.ctx),new JQi(e,this.ctx),new KQi(e,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadPcb}getOutputString(){return this.ctx.kicadPcb.getString()}getModel3dSourcePaths(){return this.ctx.pcbModel3dSourcePaths??[]}},qQi=class{ctx;project;constructor(e,A={}){const t=A.projectName??e?.project?.name??"circuit-json-project",i=A.schematicFilename??`${t}.kicad_sch`,n=A.pcbFilename??`${t}.kicad_pcb`,o=new Date().toISOString();this.ctx={db:Na(e),circuitJson:e},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:t,created:o,modified:o},meta:{version:1},text_variables:{},libraries:{pinned_symbol_libs:[],pinned_footprint_libs:[]},boards:[],cvpcb:{meta:{version:0}},erc:{meta:{version:0},erc_exclusions:[]},net_settings:{meta:{version:1},last_net_id:0,classes:[]},pcbnew:{page_layout_descr_file:"",last_paths:{}},schematic:{meta:{version:1},page_layout_descr_file:"",last_opened_files:[i]},board:{meta:{version:1},last_opened_board:n},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
|
|
5829
|
+
`)}};LA.register(D2A);var x2A=class _xt extends LA{static token="kicad_pcb";token="kicad_pcb";_sxVersion;_sxGenerator;_sxGeneratorVersion;_sxGeneral;_sxPaper;_sxTitleBlock;_sxLayers;_sxSetup;_properties=[];_nets=[];_footprints=[];_images=[];_segments=[];_grLines=[];_grTexts=[];_grPolys=[];_grRects=[];_vias=[];_zones=[];_otherChildren=[];constructor(A={}){super(),A.version!==void 0&&(this.version=A.version),A.generator!==void 0&&(this.generator=A.generator),A.generatorVersion!==void 0&&(this.generatorVersion=A.generatorVersion),A.general!==void 0&&(this.general=A.general),A.paper!==void 0&&(this.paper=A.paper),A.titleBlock!==void 0&&(this.titleBlock=A.titleBlock),A.layers!==void 0&&(this.layers=A.layers),A.setup!==void 0&&(this.setup=A.setup),A.properties!==void 0&&(this.properties=A.properties),A.nets!==void 0&&(this.nets=A.nets),A.footprints!==void 0&&(this.footprints=A.footprints),A.images!==void 0&&(this.images=A.images),A.segments!==void 0&&(this.segments=A.segments),A.graphicLines!==void 0&&(this.graphicLines=A.graphicLines),A.graphicTexts!==void 0&&(this.graphicTexts=A.graphicTexts),A.graphicPolys!==void 0&&(this.graphicPolys=A.graphicPolys),A.graphicRects!==void 0&&(this.graphicRects=A.graphicRects),A.vias!==void 0&&(this.vias=A.vias),A.zones!==void 0&&(this.zones=A.zones),A.otherChildren!==void 0&&(this.otherChildren=A.otherChildren)}static fromSexprPrimitives(A){const t=new _xt;for(const i of A){if(!Array.isArray(i)||i.length===0)throw new Error(`kicad_pcb encountered unsupported primitive child: ${JSON.stringify(i)}`);const n=LA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(n instanceof LA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);t.consumeChild(n)}return t}consumeChild(A){if(A instanceof f2A){this._sxVersion=A;return}if(A instanceof y2A){this._sxGenerator=A;return}if(A instanceof m2A){this._sxGeneratorVersion=A;return}if(A instanceof d2A){this._sxGeneral=A;return}if(A instanceof OV){this._sxPaper=A;return}if(A instanceof cdt){this._sxTitleBlock=A;return}if(A instanceof p2A){this._sxLayers=A;return}if(A instanceof u2A){this._sxSetup=A;return}if(A instanceof y1){this._properties.push(A);return}if(A instanceof cj){this._nets.push(A);return}if(A instanceof nj){this._footprints.push(A);return}if(A instanceof ldt){this._images.push(A);return}if(A instanceof _1A){this._segments.push(A);return}if(A instanceof oj){this._grLines.push(A);return}if(A instanceof sj){this._grTexts.push(A);return}if(A instanceof tft){this._grPolys.push(A);return}if(A instanceof Xpt){this._grRects.push(A);return}if(A instanceof D2A){this._vias.push(A);return}if(A instanceof rft){this._zones.push(A);return}this._otherChildren.push(A)}get version(){return this._sxVersion?.value}set version(A){this._sxVersion=A===void 0?void 0:new f2A(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new y2A(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new m2A(A)}get general(){return this._sxGeneral}set general(A){this._sxGeneral=A}get paper(){return this._sxPaper}set paper(A){this._sxPaper=A}get titleBlock(){return this._sxTitleBlock}set titleBlock(A){this._sxTitleBlock=A}get layers(){return this._sxLayers}set layers(A){this._sxLayers=A}get setup(){return this._sxSetup}set setup(A){this._sxSetup=A}get properties(){return[...this._properties]}set properties(A){this._properties=[...A]}get nets(){return[...this._nets]}set nets(A){this._nets=[...A]}get footprints(){return[...this._footprints]}set footprints(A){this._footprints=[...A]}get images(){return[...this._images]}set images(A){this._images=[...A]}get segments(){return[...this._segments]}set segments(A){this._segments=[...A]}get graphicLines(){return[...this._grLines]}set graphicLines(A){this._grLines=[...A]}get graphicTexts(){return[...this._grTexts]}set graphicTexts(A){this._grTexts=[...A]}get graphicPolys(){return[...this._grPolys]}set graphicPolys(A){this._grPolys=[...A]}get graphicRects(){return[...this._grRects]}set graphicRects(A){this._grRects=[...A]}get vias(){return[...this._vias]}set vias(A){this._vias=[...A]}get zones(){return[...this._zones]}set zones(A){this._zones=[...A]}get otherChildren(){return[...this._otherChildren]}set otherChildren(A){this._otherChildren=[...A]}getChildren(){const A=[];return this._sxVersion&&A.push(this._sxVersion),this._sxGenerator&&A.push(this._sxGenerator),this._sxGeneratorVersion&&A.push(this._sxGeneratorVersion),this._sxGeneral&&A.push(this._sxGeneral),this._sxPaper&&A.push(this._sxPaper),this._sxTitleBlock&&A.push(this._sxTitleBlock),this._sxLayers&&A.push(this._sxLayers),this._sxSetup&&A.push(this._sxSetup),A.push(...this._properties),A.push(...this._nets),A.push(...this._footprints),A.push(...this._images),A.push(...this._segments),A.push(...this._grLines),A.push(...this._grTexts),A.push(...this._grPolys),A.push(...this._grRects),A.push(...this._vias),A.push(...this._zones),A.push(...this._otherChildren),A}};LA.register(x2A);var lyt=e=>LA.parse(e),t0=class{MAX_ITERATIONS=1e3;iteration=0;finished=!1;input;ctx;constructor(e,A){this.input=e,this.ctx=A}step(){if(this.iteration++,this.iteration>this.MAX_ITERATIONS)throw new Error("Max iterations reached");this._step()}_step(){throw new Error("Not implemented")}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){throw new Error("Not implemented")}},qCi=class extends t0{_step(){const{kicadSch:e,schematicPaperSize:A}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");e.version=20250114;const t=new OV;t.size=A?.name??"A4",e.paper=t,e.uuid=new qi(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function U3(e,A){if(e.manufacturer_part_number)return S2A(e.manufacturer_part_number);const t=OCi(e.ftype),i=A?.footprinter_string;return S2A(i?`${t}_${i}`:t)}function OCi(e){if(!e)return"component";let A=e.replace(/^simple_/,"");return A||"component"}function S2A(e){return e.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function Byt(e){return e?e.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}var Cyt={simple_resistor:"R",simple_capacitor:"C",simple_inductor:"L",simple_diode:"D",simple_led:"D",simple_chip:"U",simple_transistor:"Q",simple_mosfet:"Q",simple_fuse:"F",simple_switch:"SW",simple_push_button:"SW",simple_potentiometer:"RV",simple_crystal:"Y",simple_resonator:"Y",simple_pin_header:"J",simple_pinout:"J",simple_test_point:"TP",simple_battery:"BT"},WCi=/^[A-Za-z]+\d+$/;function Qyt(e){return e?WCi.test(e.trim()):!1}function Ij(e){const A=e?.ftype;if(A&&Cyt[A])return Cyt[A];const t=e?.name;return Qyt(t),Byt(t)}function ZCi(e){const A=e?.name;return Qyt(A)?A.trim():`${Ij(e)}?`}function hyt(e){return e in qQ}function Eyt(e,A,t,i){if(i)return`Custom:${i}`;if(e.type!=="source_component")return A.symbol_name?hyt(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return hyt(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const n=U3(e,t);return`Device:${Ij(e)}_${n}`}function VCi(e){const{circuitJson:A,schematicSymbolId:t,schematicSymbol:i,schematicComponentId:n}=e,o=A.filter(Q=>Q.type==="schematic_circle"&&Q.schematic_symbol_id===t),s=A.filter(Q=>Q.type==="schematic_line"&&Q.schematic_symbol_id===t),r=n?A.filter(Q=>Q.type==="schematic_line"&&Q.schematic_component_id===n&&!Q.schematic_symbol_id):[],a=[...s,...r],g=A.filter(Q=>Q.type==="schematic_path"&&Q.schematic_symbol_id===t),c=A.filter(Q=>Q.type==="schematic_text"&&Q.schematic_symbol_id===t);let I=A.filter(Q=>Q.type==="schematic_port"&&"schematic_symbol_id"in Q&&Q.schematic_symbol_id===t);if(I.length===0&&n){const Q=A.filter(E=>E.type==="schematic_port"&&E.schematic_component_id===n&&E.display_pin_label!==void 0),h=new Map;for(const E of Q)E.display_pin_label&&h.set(E.display_pin_label,E);if(I=h.size>0?Array.from(h.values()):Q,I.length===0){const E=A.filter(d=>d.type==="schematic_port"&&d.schematic_component_id===n),u=new Set;I=E.filter(d=>{const f=d.pin_number;if(f!==void 0){if(u.has(f))return!1;u.add(f)}return!0})}}const l=[];for(const Q of o)l.push({type:"circle",x:Q.center?.x??0,y:Q.center?.y??0,radius:Q.radius??.5,fill:Q.is_filled??!1,fillColor:Q.fill_color});for(const Q of a)l.push({type:"path",points:[{x:Q.x1??0,y:Q.y1??0},{x:Q.x2??0,y:Q.y2??0}]});for(const Q of g)Q.points&&Q.points.length>0&&l.push({type:"path",points:Q.points,fill:Q.is_filled??!1,fillColor:Q.fill_color});const B=c.map(Q=>({text:Q.text??"",x:Q.position?.x??0,y:Q.position?.y??0,fontSize:Q.font_size??.2,anchor:Q.anchor??"center"})),C=I.map((Q,h)=>({x:Q.center?.x??0,y:Q.center?.y??0,labels:[Q.display_pin_label||`${Q.pin_number||h+1}`],pinNumber:Q.pin_number||h+1,facingDirection:Q.facing_direction}));return C.sort((Q,h)=>Q.pinNumber-h.pinNumber),{center:i.center||{x:0,y:0},size:i.size||{width:1,height:1},primitives:l,texts:B,ports:C}}function jCi({points:e,transform:A,fillType:t}){const i=new Cdt,n=e.map(a=>{const g=Ct(A,a);return new oh(g.x,g.y)}),o=new oQ(n);i.points=o;const s=new f1;s.width=.254,s.type="default",i.stroke=s;const r=new fdt;return r.type=t,i.fill=r,i}function zCi({primitive:e,transform:A,scale:t}){const i=new wdt,n=Ct(A,{x:e.x,y:e.y}),o=i;o._sxCenter=new ddt(n.x,n.y),o._sxRadius=new pdt(e.radius*t);const s=new f1;s.width=.254,s.type="default",o._sxStroke=s;const r=new ydt;return r.type=e.fill?"background":"none",o._sxFill=r,i}function XCi({schText:e,transform:A,scale:t}){const i=new Ddt,n=Ct(A,{x:e.x,y:e.y});i.value=e.text,i.at=[n.x,n.y,0];const o=e.fontSize*t,s=new Tp;return s.size={height:o,width:o},i.effects=new Jp({font:s}),i}function $Ci({libId:e,symbolData:A,isChip:t,c2kMatSchScale:i}){const n=new NM({libraryId:`${e.split(":")[1]}_0_1`}),o=i,s=A.center?.x??0,r=A.center?.y??0,a=tn(za(o,o),sn(-s,-r));for(const c of A.primitives||[])if(c.type==="path"&&c.points){const I=t||c.fill?"background":"none",l=jCi({points:c.points,transform:a,fillType:I});n.polylines.push(l)}else if(c.type==="circle"){const I=zCi({primitive:c,transform:a,scale:o});n.circles.push(I)}const g=Array.isArray(A.texts)?A.texts:[];for(const c of g){const I=XCi({schText:c,transform:a,scale:o});n.texts.push(I)}return n}function AQi(e,A){const t=A.schematic_port.list().filter(r=>r.schematic_component_id===e.schematic_component_id).sort((r,a)=>(r.pin_number||0)-(a.pin_number||0)),i=e.size?.width||1.5,n=e.size?.height||1,o={type:"path",points:[{x:-i/2,y:-n/2},{x:i/2,y:-n/2},{x:i/2,y:n/2},{x:-i/2,y:n/2},{x:-i/2,y:-n/2}]},s=t.map(r=>{const a=r.center.x-e.center.x,g=r.center.y-e.center.y;return{x:a,y:g,labels:[r.display_pin_label||`${r.pin_number||1}`],pinNumber:r.pin_number||1}});return{center:{x:0,y:0},primitives:[o],ports:s,size:{width:i,height:n}}}function tQi(e,A){const t=new Tp;return t.size={height:e,width:e},new Jp({font:t,hiddenText:A})}function eQi({symbol:e,libId:A,description:t,keywords:i,fpFilters:n,footprintRef:o="",referencePrefix:s}){const r=s||A.split(":")[1]?.[0]||"U",a=[{key:"Reference",value:r,id:0,at:[2.032,0,90],hide:!1},{key:"Value",value:r,id:1,at:[0,0,90],hide:!1},{key:"Footprint",value:o,id:2,at:[-1.778,0,90],hide:!0},{key:"Datasheet",value:"~",id:3,at:[0,0,0],hide:!0},{key:"Description",value:t,id:4,at:[0,0,0],hide:!0},{key:"ki_keywords",value:i,id:5,at:[0,0,0],hide:!0},{key:"ki_fp_filters",value:n,id:6,at:[0,0,0],hide:!0}];for(const g of a)e.properties.push(new Pp({key:g.key,value:g.value,id:g.id,at:g.at,effects:tQi(1.27,g.hide)}))}function iQi({port:e,center:A,size:t,isChip:i,portIndex:n,schematicComponent:o,schematicPorts:s,c2kMatSchScale:r}){const a=r;let g=e.x??0,c=e.y??0,I=!1;if(i&&n!==void 0&&o){const m=s.filter(w=>w.schematic_component_id===o.schematic_component_id).sort((w,D)=>(w.pin_number||0)-(D.pin_number||0));if(m[n]){const w=m[n];g=w.center.x-o.center.x,c=w.center.y-o.center.y,I=!0}}let l,B;if(I)l=g,B=c;else{const m=A?.x??0,w=A?.y??0;l=g-m,B=c-w}const C=za(a,a),Q=Ct(C,{x:l,y:B});let h;if(i&&t){const m=t.width/2,w=t.height/2,D=Math.abs(l)/m,x=Math.abs(B)/w;h=D>x}else h=Math.abs(l)>Math.abs(B);let E=Q.x,u=Q.y;const d=6;if(i&&t){const m=t.width/2*a,w=t.height/2*a;h?(E=l>0?m:-m,u=B*a):(E=l*a,u=B>0?w:-w)}let f=0;return h?l>0?(f=180,i&&(E=E+d)):(f=0,i&&(E=E-d)):B>0?(f=270,i&&(u=u+d)):(f=90,i&&(u=u-d)),{x:E,y:u,angle:f}}function nQi({libId:e,symbolData:A,isChip:t,schematicComponent:i,schematicPorts:n,c2kMatSchScale:o}){const s=new NM({libraryId:`${e.split(":")[1]}_1_1`}),r=6,a=2.54;for(let g=0;g<(A.ports?.length||0);g++){const c=A.ports[g],I=new jV;I.pinElectricalType="passive",I.pinGraphicStyle="line";const{x:l,y:B,angle:C}=iQi({port:c,center:A.center,size:A.size,isChip:t,portIndex:g,schematicComponent:i,schematicPorts:n,c2kMatSchScale:o});I.at=[l,B,C],I.length=t?r:a;const Q=new Tp;Q.size={height:1.27,width:1.27};const h=new Jp({font:Q}),E=c.labels?.[0]||"~";I._sxName=new rDA({value:E,effects:h});const u=new Tp;u.size={height:1.27,width:1.27};const d=new Jp({font:u}),f=c.pinNumber?.toString()||`${g+1}`;I._sxNumber=new Sdt({value:f,effects:d}),s.pins.push(I)}return s}var oQi=class extends t0{processedSymbolNames=new Set;_step(){const{kicadSch:e,db:A}=this.ctx,t=new Gdt,i=[];this.processedSymbolNames=new Set;const n=A.schematic_component.list();for(const s of n){const r=this.createLibrarySymbolForComponent(s);r&&i.push(r)}const o=A.schematic_net_label?.list?.()||[];for(const s of o)if(s.symbol_name){const r=s.source_net_id?A.source_net.get(s.source_net_id)?.is_power:!1,a=s.source_net_id?A.source_net.get(s.source_net_id)?.is_ground:!1;if(r||a){const c=this.createLibrarySymbolForNetLabel({netLabel:s,isPower:r??!1,isGround:a??!1});c&&i.push(c)}}t.symbols=i,e&&(e.libSymbols=t),this.finished=!0}createLibrarySymbolForComponent(e){const{db:A}=this.ctx,t=e.source_component_id?A.source_component.get(e.source_component_id):null;if(!t)return null;const i=A.cad_component?.list()?.find(c=>c.source_component_id===t.source_component_id);let n=e.schematic_symbol_id;if(!n){const c=this.ctx.circuitJson.find(I=>(I.type==="schematic_line"||I.type==="schematic_circle"||I.type==="schematic_path")&&I.schematic_component_id===e.schematic_component_id&&I.schematic_symbol_id);c&&(n=c.schematic_symbol_id)}if(n)return this.createLibrarySymbolFromSchematicSymbol(e,t,i,n);const o=e.symbol_name||(t.ftype==="simple_chip"?`generic_chip_${e.source_component_id}`:null);if(!o)return null;const s=this.getSymbolData(o,e);if(!s)return null;const r=Eyt(t,e,i),a=t.ftype==="simple_chip",g=U3(t,i);return this.createLibrarySymbol({libId:r,symbolData:s,isChip:a,schematicComponent:e,description:this.getDescription(t),keywords:this.getKeywords(t),fpFilters:this.getFpFilters(t),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:Ij(t)})}createLibrarySymbolFromSchematicSymbol(e,A,t,i){const{db:n}=this.ctx,o=this.ctx.circuitJson.find(c=>c.type==="schematic_symbol"&&c.schematic_symbol_id===i);if(!o)return null;let s;if(o.name)s=o.name;else{const c=U3(A,t);c?s=c:s=`custom_${A.ftype||"component"}_${i}`}const r=`Custom:${s}`;if(this.processedSymbolNames.has(r))return null;this.processedSymbolNames.add(r);const a=VCi({circuitJson:this.ctx.circuitJson,schematicSymbolId:i,schematicSymbol:o,schematicComponentId:e.schematic_component_id}),g=U3(A,t);return this.createLibrarySymbol({libId:r,symbolData:a,isChip:!1,schematicComponent:e,description:this.getDescription(A),keywords:this.getKeywords(A),fpFilters:this.getFpFilters(A,o.name),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:Ij(A),symbolScale:1})}createLibrarySymbolForNetLabel({netLabel:e,isPower:A,isGround:t}){const i=e.symbol_name;if(!i)return null;const n=qQ[i];if(!n)return null;const o=`Custom:${i}`;return this.createLibrarySymbol({libId:o,symbolData:n,isChip:!1,schematicComponent:void 0,description:A?"Power net label":t?"Ground net label":"Net symbol",keywords:A?"power net":t?"ground net":"net",fpFilters:"",referencePrefix:o.split(":")[1]?.[0]||"U"})}getSymbolData(e,A){return e.startsWith("generic_chip_")?AQi(A,this.ctx.db):qQ[e]||null}createLibrarySymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i,description:n,keywords:o,fpFilters:s,footprintRef:r="",referencePrefix:a,symbolScale:g}){const I=g??this.ctx.c2kMatSch?.a??15,l=new NM({libraryId:e,excludeFromSim:!1,inBom:!0,onBoard:!0}),B=new nDA;B.hide=!t,l._sxPinNumbers=B;const C=new sDA;C.offset=t?1.27:0,l._sxPinNames=C,eQi({symbol:l,libId:e,description:n,keywords:o,fpFilters:s,footprintRef:r,referencePrefix:a});const Q=$Ci({libId:e,symbolData:A,isChip:t,c2kMatSchScale:I});l.subSymbols.push(Q);const h=nQi({libId:e,symbolData:A,isChip:t,schematicComponent:i,schematicPorts:this.ctx.db.schematic_port.list(),c2kMatSchScale:I});return l.subSymbols.push(h),l._sxEmbeddedFonts=new GM(!1),l}getDescription(e){return e?.ftype==="simple_resistor"?"Resistor":e?.ftype==="simple_capacitor"?"Capacitor":e?.ftype==="simple_chip"?"Integrated Circuit":"Component"}getKeywords(e){return e?.ftype==="simple_resistor"?"R res resistor":e?.ftype==="simple_capacitor"?"C cap capacitor":e?.ftype==="simple_chip"?"U IC chip":""}getFpFilters(e,A){return A?`${A}*`:e?.ftype==="simple_resistor"?"R_*":e?.ftype==="simple_capacitor"?"C_*":(e?.ftype==="simple_chip","*")}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},sQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx,t=A.schematic_component.list();if(t.length===0){this.finished=!0;return}const i=[];for(const n of t){const o=n.source_component_id?A.source_component.get(n.source_component_id):null;if(!o||!this.ctx.c2kMatSch)continue;const{x:s,y:r}=Ct(this.ctx.c2kMatSch,{x:n.center.x,y:n.center.y}),a=crypto.randomUUID(),g=new NM({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:a,fieldsAutoplaced:!0}),c=A.cad_component?.list()?.find(oA=>oA.source_component_id===o.source_component_id);let I,l=n.schematic_symbol_id;if(!l){const oA=this.ctx.circuitJson.find(rA=>(rA.type==="schematic_line"||rA.type==="schematic_circle"||rA.type==="schematic_path")&&rA.schematic_component_id===n.schematic_component_id&&rA.schematic_symbol_id);oA&&(l=oA.schematic_symbol_id)}if(l){const oA=this.ctx.circuitJson.find(rA=>rA.type==="schematic_symbol"&&rA.schematic_symbol_id===l);if(oA?.name)I=oA.name;else{const rA=U3(o,c);rA?I=rA:I=`custom_${o.ftype||"component"}_${l}`}}const B=Eyt(o,n,c,I),C=new eDA(B);g._sxLibId=C;const{reference:Q,value:h,description:E}=this.getComponentMetadata(o),{refTextPos:u,valTextPos:d}=this.getTextPositions(n,{x:s,y:r});let f;if(l){const oA=this.ctx.circuitJson.find(rA=>rA.type==="schematic_symbol"&&rA.schematic_symbol_id===l);oA&&oA.type==="schematic_symbol"&&(f=oA.metadata?.kicad_symbol)}const m=f?.properties?.Reference,w=new Pp({key:"Reference",value:m?.value??Q,id:0,at:[u.x,u.y,0],effects:this.createTextEffects(Number(m?.effects?.font?.size?.x??1.27),m?.effects?.hide??!1)}),D=o.ftype==="simple_chip",x=f?.properties?.Value,_=new Pp({key:"Value",value:x?.value??h,id:1,at:[d.x,d.y,0],effects:this.createTextEffects(Number(x?.effects?.font?.size?.x??1.27),x?.effects?.hide??D)}),b=f?.properties?.Footprint,R=new Pp({key:"Footprint",value:b?.value??"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,b?.effects?.hide??!0)}),F=f?.properties?.Datasheet,H=new Pp({key:"Datasheet",value:F?.value??"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,F?.effects?.hide??!0)}),Y=f?.properties?.Description,J=new Pp({key:"Description",value:Y?.value??E,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,Y?.effects?.hide??!0)});g.properties.push(w,_,R,H,J);const O=f?.properties?.ki_keywords;if(O?.value){const oA=new Pp({key:"ki_keywords",value:O.value,id:5,at:[s,r,0],effects:this.createTextEffects(1.27,O.effects?.hide??!0)});g.properties.push(oA)}const W=f?.properties?.ki_fp_filters;if(W?.value){const oA=new Pp({key:"ki_fp_filters",value:W.value,id:6,at:[s,r,0],effects:this.createTextEffects(1.27,W.effects?.hide??!0)});g.properties.push(oA)}if(f){if(f.inBom!==void 0&&(g.inBom=f.inBom),f.onBoard!==void 0&&(g.onBoard=f.onBoard),f.excludeFromSim!==void 0&&(g.excludeFromSim=f.excludeFromSim),f.pinNames){const oA=new sDA;f.pinNames.offset!==void 0&&(oA.offset=Number(f.pinNames.offset)),f.pinNames.hide!==void 0&&(oA.hide=f.pinNames.hide),g.pinNames=oA}if(f.pinNumbers){const oA=new nDA;f.pinNumbers.hide!==void 0&&(oA.hide=f.pinNumbers.hide),g.pinNumbers=oA}f.embeddedFonts!==void 0&&(g._sxEmbeddedFonts=new GM(f.embeddedFonts))}let z=A.schematic_port.list().filter(oA=>oA.schematic_component_id===n.schematic_component_id);if(l){const oA=z.filter(rA=>rA.display_pin_label);oA.length>0&&(z=oA)}z.sort((oA,rA)=>(oA.pin_number||0)-(rA.pin_number||0));for(let oA=0;oA<z.length;oA++){const rA=z[oA];if(!rA)continue;const lA=new jV;lA.numberString=`${rA.pin_number||oA+1}`,lA.uuid=crypto.randomUUID(),g.pins.push(lA)}const tA=new aDA,aA=new cDA(""),eA=new IDA(`/${e?.uuid?.value||""}`);eA.reference=Q,eA.unit=1,aA.paths.push(eA),tA.projects.push(aA),g._sxInstances=tA,i.push(g)}e&&(e.symbols=i),this.finished=!0}getTextPositions(e,A){const i=(this.ctx.db.schematic_text?.list?.()?.filter(B=>B.schematic_component_id===e.schematic_component_id)||[]).find(B=>B.text&&B.text.length>0);if(i&&this.ctx.c2kMatSch){const B=Ct(this.ctx.c2kMatSch,{x:i.position.x,y:i.position.y}),C={x:A.x,y:A.y+6};return{refTextPos:B,valTextPos:C}}const n=e.symbol_name,o=qQ[n];if(!o)return{refTextPos:{x:A.x,y:A.y-6},valTextPos:{x:A.x,y:A.y+6}};let s=null,r=null;for(const B of o.primitives)B.type==="text"&&(B.text==="{REF}"?s=B:B.text==="{VAL}"&&(r=B));const a=o.center||{x:0,y:0},c=n.includes("_down")||n.includes("_up")?.15:0,I=s&&this.ctx.c2kMatSch?Ct(this.ctx.c2kMatSch,{x:e.center.x+(s.x-a.x)+c,y:e.center.y+(s.y-a.y)}):{x:A.x,y:A.y-6},l=r&&this.ctx.c2kMatSch?Ct(this.ctx.c2kMatSch,{x:e.center.x+(r.x-a.x)+c,y:e.center.y+(r.y-a.y)}):{x:A.x,y:A.y+6};return{refTextPos:I,valTextPos:l}}getComponentMetadata(e){const A=e.name||"?",t=ZCi(e);return e.ftype==="simple_resistor"?{reference:t,value:e.display_resistance||"R",description:"Resistor"}:e.ftype==="simple_capacitor"?{reference:t,value:e.display_capacitance||"C",description:"Capacitor"}:e.ftype==="simple_inductor"?{reference:t,value:e.display_inductance||"L",description:"Inductor"}:e.ftype==="simple_diode"?{reference:t,value:"D",description:"Diode"}:e.ftype==="simple_chip"?{reference:t,value:A,description:"Integrated Circuit"}:e.ftype==="simple_led"?{reference:t,value:e.manufacturer_part_number||"",description:"LED"}:e.ftype==="simple_switch"?{reference:t,value:e.manufacturer_part_number||"",description:"Switch"}:e.ftype==="simple_potentiometer"?{reference:t,value:e.display_max_resistance||"",description:"Potentiometer"}:{reference:t,value:A,description:"Component"}}createTextEffects(e,A=!1,t){const i=new Tp;i.size={height:e,width:e};const n=t?new a6({horizontal:t}):void 0;return new Jp({font:i,hiddenText:A,justify:n})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},rQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx,t=A.schematic_net_label?.list?.()||[];if(t.length===0){this.finished=!0;return}if(!this.ctx.c2kMatSch){this.finished=!0;return}const i=[],n=[];for(const o of t){const s=o.text||"",r=o.symbol_name;if(r){const a=this.createSymbolFromNetLabel(o,s,r);a&&i.push(a)}else{const a=this.createGlobalLabel(o,s);a&&n.push(a)}}if(e&&i.length>0){const o=e.symbols||[];e.symbols=[...o,...i]}e&&n.length>0&&(e.globalLabels=[...e.globalLabels||[],...n]),this.finished=!0}createSymbolFromNetLabel(e,A,t){if(!this.ctx.c2kMatSch)return null;const{x:i,y:n}=Ct(this.ctx.c2kMatSch,{x:e.anchor_position?.x??e.center?.x??0,y:e.anchor_position?.y??e.center?.y??0}),o=crypto.randomUUID(),s=new NM({at:[i,n,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:o,fieldsAutoplaced:!0}),r=`Custom:${t}`,a=new eDA(r);s._sxLibId=a;const g=t.includes("_up")||t.toLowerCase().includes("vcc"),c=g?-4:4,I=g?-6:6,l=new Pp({key:"Reference",value:A,id:0,at:[i,n+c,0],effects:this.createTextEffects(1.27,!1)}),B=new Pp({key:"Value",value:A,id:1,at:[i,n+I,0],effects:this.createTextEffects(1.27,!0)}),C=new Pp({key:"Footprint",value:"",id:2,at:[i-1.778,n,90],effects:this.createTextEffects(1.27,!0)}),Q=new Pp({key:"Datasheet",value:"~",id:3,at:[i,n,0],effects:this.createTextEffects(1.27,!0)}),h=new Pp({key:"Description",value:`Power/Net symbol: ${A}`,id:4,at:[i,n,0],effects:this.createTextEffects(1.27,!0)});s.properties.push(l,B,C,Q,h);const E=new jV;E.numberString="1",E.uuid=crypto.randomUUID(),s.pins.push(E);const{kicadSch:u}=this.ctx,d=new aDA,f=new cDA(""),m=new IDA(`/${u?.uuid?.value||""}`);return m.reference=A,m.unit=1,f.paths.push(m),d.projects.push(f),s._sxInstances=d,s}createGlobalLabel(e,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:t,y:i}=Ct(this.ctx.c2kMatSch,{x:e.anchor_position?.x??e.center?.x??0,y:e.anchor_position?.y??e.center?.y??0}),n=e.anchor_side||"left",s={left:0,right:180,top:270,bottom:90}[n]||0,a={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[n]||{},g=this.createTextEffects(1.27,!1);return Object.keys(a).length>0&&(g.justify=new a6(a)),new Pdt({value:A,at:[t,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(e,A=!1){const t=new Tp;return t.size={height:e,width:e},new Jp({font:t,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},aQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const t=A.schematic_trace.list();if(t.length===0){this.finished=!0;return}const i=[],n=[];for(const o of t){for(const s of o.edges){const r=this.createWireFromEdge(s);i.push(r)}for(const s of o.junctions){const r=this.createJunction(s);n.push(r)}}e.wires=i,e.junctions=n,this.finished=!0}createWireFromEdge(e){const A=new Ndt;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const t=Ct(this.ctx.c2kMatSch,{x:e.from.x,y:e.from.y}),i=Ct(this.ctx.c2kMatSch,{x:e.to.x,y:e.to.y}),n=t.x,o=t.y,s=i.x,r=i.y,a=new oQ([new oh(n,o),new oh(s,r)]);A.points=a;const g=new f1;return g.width=0,g.type="default",A.stroke=g,A.uuid=crypto.randomUUID(),A}createJunction(e){if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const{x:A,y:t}=Ct(this.ctx.c2kMatSch,{x:e.x,y:e.y}),i=new Ldt({at:[A,t],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},gQi=class extends t0{_step(){const{kicadSch:e}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const A=new QDA,t=new Odt;t.value="/";const i=new Wdt("1");t.pages=[i],A.paths=[t],e.sheetInstances=A,e.embeddedFonts=new GM(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function cQi(e){const A=e.schematic_component.list(),t=e.schematic_trace.list();let i=1/0,n=1/0,o=-1/0,s=-1/0;for(const g of A){const c=g.size?.width??0,I=g.size?.height??0;i=Math.min(i,g.center.x-c/2),n=Math.min(n,g.center.y-I/2),o=Math.max(o,g.center.x+c/2),s=Math.max(s,g.center.y+I/2)}for(const g of t)for(const c of g.edges)i=Math.min(i,c.from.x,c.to.x),n=Math.min(n,c.from.y,c.to.y),o=Math.max(o,c.from.x,c.to.x),s=Math.max(s,c.from.y,c.to.y);i===1/0&&(i=0,n=0,o=0,s=0);const r=(i+o)/2,a=(n+s)/2;return{center:{x:r,y:a},bounds:{minX:i,minY:n,maxX:o,maxY:s}}}var lj=[{name:"A4",width:297,height:210},{name:"A3",width:420,height:297},{name:"A2",width:594,height:420},{name:"A1",width:841,height:594},{name:"A0",width:1189,height:841}];function IQi(e,A,t=20){const i=e+2*t,n=A+2*t;for(let o=0;o<lj.length;o++){const s=lj[o];if(i<=s.width&&n<=s.height)return s}return lj[lj.length-1]}var uyt=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e){const t=Na(e),{center:i,bounds:n}=cQi(t),o=(n.maxX-n.minX)*15,s=(n.maxY-n.minY)*15,r=IQi(o,s),a=r.width/2,g=r.height/2;this.ctx={db:t,circuitJson:e,kicadSch:new EDA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:r,c2kMatSch:tn(sn(a,g),za(15,-15),sn(-i.x,-i.y))},this.pipeline=[new qCi(e,this.ctx),new oQi(e,this.ctx),new sQi(e,this.ctx),new rQi(e,this.ctx),new aQi(e,this.ctx),new gQi(e,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadSch}getOutputString(){return this.ctx.kicadSch.getString()}},lQi=class extends t0{_step(){const{kicadPcb:e,db:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");const i=A.pcb_board?.list()?.[0]?.num_layers??2;this.ctx.numLayers=i,e.version=20241229;const n=new OV;n.size="A4",e.paper=n;const o=new d2A;o.thickness=1.6,e.general=o;const s=new u2A;s.padToMaskClearance=0,e.setup=s;const r=new p2A,a=[new Zl({index:0,name:"F.Cu",type:"signal"})];for(let g=1;g<i-1;g++)a.push(new Zl({index:g,name:`In${g}.Cu`,type:"signal"}));a.push(new Zl({index:31,name:"B.Cu",type:"signal"})),a.push(new Zl({index:32,name:"B.Adhes",type:"user"}),new Zl({index:33,name:"F.Adhes",type:"user"}),new Zl({index:34,name:"B.Paste",type:"user"}),new Zl({index:35,name:"F.Paste",type:"user"}),new Zl({index:36,name:"B.SilkS",type:"user"}),new Zl({index:37,name:"F.SilkS",type:"user"}),new Zl({index:38,name:"B.Mask",type:"user"}),new Zl({index:39,name:"F.Mask",type:"user"}),new Zl({index:40,name:"Dwgs.User",type:"user"}),new Zl({index:41,name:"Cmts.User",type:"user"}),new Zl({index:42,name:"Eco1.User",type:"user"}),new Zl({index:43,name:"Eco2.User",type:"user"}),new Zl({index:44,name:"Edge.Cuts",type:"user"}),new Zl({index:45,name:"Margin",type:"user"}),new Zl({index:46,name:"B.CrtYd",type:"user"}),new Zl({index:47,name:"F.CrtYd",type:"user"}),new Zl({index:48,name:"B.Fab",type:"user"}),new Zl({index:49,name:"F.Fab",type:"user"})),r.definitions=a,e.layers=r,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},BQi=class extends t0{_step(){const{kicadPcb:e}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");this.ctx.pcbNetMap=new Map;const A=new Map,t=this.ctx.db.source_net?.list()??[];for(const r of t){const a=r.subcircuit_connectivity_map_key||r.source_net_id;if(!a)continue;const g=r.name||r.source_net_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}const i=this.ctx.db.source_trace?.list()??[];for(const r of i){let a=r.subcircuit_connectivity_map_key;if(!a&&r.connected_source_net_ids?.length)for(const g of r.connected_source_net_ids){const c=this.ctx.db.source_net?.get(g);if(c?.subcircuit_connectivity_map_key&&c.subcircuit_connectivity_map_key.length>0){a=c.subcircuit_connectivity_map_key;break}}if(a&&!A.has(a)){const g=r.display_name||r.source_trace_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}}const n=Array.from(A.entries()).sort((r,a)=>r[0].localeCompare(a[0])),o=[];o.push(new cj(0,""));let s=1;for(const[r,a]of n){const g=new cj(s,a);o.push(g);const c={id:s,name:a};this.ctx.pcbNetMap.set(r,c),s++}e.nets=o,this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function CQi(e){let A=0;for(let i=0;i<e.length;i++){const n=e.charCodeAt(i);A=(A<<5)-A+n,A=A&A}let t="";for(let i=0;i<4;i++){let n=A;for(let o=0;o<e.length;o++)n=(n<<5)-n+e.charCodeAt(o)+i*31,n=n&n;t+=Math.abs(n).toString(16).padStart(8,"0")}return t}function cd(e){const A=CQi(e);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}var dyt="https://modelcdn.tscircuit.com/jscad_models",QQi=20240108,hQi="pcbnew",EQi="8.0";function b2A(e){const A=e.split(/[/\\]/),t=A[A.length-1]||e;return t.split("?")[0]||t}var uQi=class extends t0{classifyFootprints(){const e=new Set,A=new Map,t=this.ctx.db.cad_component?.list()??[],i=this.ctx.db.source_component;for(const n of t){const o=n.source_component_id?i?.get(n.source_component_id):null;if(!o)continue;const s=U3(o,n);if(n.footprinter_string)A.set(s,n.footprinter_string);else{e.add(s);const r=this.ctx.circuitJson.find(a=>a.type==="pcb_component"&&a.source_component_id===n.source_component_id);r&&r.type==="pcb_component"&&r.metadata?.kicad_footprint?.footprintName&&e.add(r.metadata.kicad_footprint.footprintName)}}return{customFootprintNames:e,footprinterStrings:A}}_step(){const e=this.ctx.kicadPcbString,A=this.ctx.fpLibraryName??"tscircuit";if(!e)throw new Error("PCB content not available. Run GenerateKicadSchAndPcbStage first.");const{customFootprintNames:t,footprinterStrings:i}=this.classifyFootprints(),n=new Map;try{const s=lyt(e).find(a=>a instanceof x2A);if(!s){this.ctx.footprintEntries=[],this.finished=!0;return}const r=s.footprints??[];for(const a of r){const g=this.sanitizeFootprint({footprint:a,fpLibraryName:A,customFootprintNames:t,footprinterStrings:i});n.has(g.footprintName)||n.set(g.footprintName,g)}}catch(o){console.warn("Failed to parse PCB for footprint extraction:",o)}this.ctx.footprintEntries=Array.from(n.values()),this.finished=!0}sanitizeFootprint({footprint:e,fpLibraryName:A,customFootprintNames:t,footprinterStrings:i}){const o=(e.libraryLink??"footprint").split(":"),s=(o.length>1?o[1]:o[0])?.replace(/[\\\/]/g,"-").trim()||"footprint",r=!t.has(s);if(e.libraryLink=s,e.position=oc.from([0,0,0]),e.locked=!1,e.placed=!1,e.version=QQi,e.generator=hQi,e.generatorVersion=EQi,e.descr||(e.descr=""),e.tags||(e.tags=""),e.embeddedFonts||(e.embeddedFonts=new GM(!1)),!e.attr){const f=new uDA,m=(e.fpPads??[]).map(w=>w.padType);m.some(w=>w.includes("thru_hole"))?f.type="through_hole":m.some(w=>w.includes("smd"))&&(f.type="smd"),e.attr=f}e.uuid=void 0,e.path=void 0,e.sheetfile=void 0,e.sheetname=void 0;const a=new Tp;a.size={width:1.27,height:1.27},a.thickness=.15;const g=new Jp({font:a}),c=e.fpPads??[];let I=0,l=0;for(const f of c){const m=f.at,w=f.size;if(m&&w){const D=m.y??0,x=w.height??0,_=D-x/2,b=D+x/2;I=Math.min(I,_),l=Math.max(l,b)}}const B=I-.5,C=l+.5;e.properties=[new y1({key:"Reference",value:"REF**",position:[0,B,0],layer:"F.SilkS",uuid:cd(`${s}-property-Reference`),effects:g}),new y1({key:"Value",value:"Val**",position:[0,C,0],layer:"F.Fab",uuid:cd(`${s}-property-Value`),effects:g}),new y1({key:"Datasheet",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:cd(`${s}-property-Datasheet`),effects:g}),new y1({key:"Description",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:cd(`${s}-property-Description`),effects:g})];const Q=e.fpTexts??[];for(const f of Q)f.uuid=void 0,f.type==="reference"?f.text="REF**":f.type==="value"&&f.text.trim().length===0&&(f.text=s);e.fpTexts=Q;const h=e.fpPads??[];for(let f=0;f<h.length;f++){const m=h[f];m&&(m.uuid=cd(`${s}-pad-${m.number??f}`),m.net=void 0)}e.fpPads=h;const E=e.models??[],u=[],d=[];for(const f of E)if(f.path){const m=b2A(f.path),x=`../../3dmodels/${f.path.startsWith("http://modelcdn.tscircuit.com")||f.path.startsWith("https://modelcdn.tscircuit.com")?"tscircuit_builtin":A}.3dshapes/${m}`,_=new L3(x);f.offset&&(_.offset=f.offset),f.scale&&(_.scale=f.scale),f.rotate&&(_.rotate=f.rotate),u.push(_),d.push(f.path.split("?")[0]??f.path)}if(u.length===0){const f=i.get(s);if(f){const m=`${dyt}/${f}.step`,D=`../../3dmodels/tscircuit_builtin.3dshapes/${b2A(m)}`;u.push(new L3(D)),d.push(m)}}return e.models=u,{footprintName:s,kicadModString:e.getString(),model3dSourcePaths:d,isBuiltin:r}}getOutput(){return this.ctx.libraryOutput}};function Bj(e){const A=new Tp;return e?.font?.size?A.size={width:Number(e.font.size.x),height:Number(e.font.size.y)}:A.size={width:1.27,height:1.27},e?.font?.thickness!==void 0?A.thickness=Number(e.font.thickness):A.thickness=.15,new Jp({font:A})}function dQi(e,A,t){if(A.properties){const i=[],n=A.properties.Reference;i.push(new y1({key:"Reference",value:n?.value??t,position:n?.at?[Number(n.at.x),Number(n.at.y),Number(n.at.rotation??0)]:[0,-3,0],layer:n?.layer??"F.SilkS",uuid:cd(`${t}-property-Reference`),effects:Bj(n?.effects),hidden:n?.hide}));const o=A.properties.Value,s=o?.value??A.footprintName??"";i.push(new y1({key:"Value",value:s,position:o?.at?[Number(o.at.x),Number(o.at.y),Number(o.at.rotation??0)]:[0,3,0],layer:o?.layer??"F.Fab",uuid:cd(`${t}-property-Value`),effects:Bj(o?.effects),hidden:o?.hide}));const r=A.properties.Datasheet;i.push(new y1({key:"Datasheet",value:r?.value??"",position:r?.at?[Number(r.at.x),Number(r.at.y),Number(r.at.rotation??0)]:[0,0,0],layer:r?.layer??"F.Fab",uuid:cd(`${t}-property-Datasheet`),effects:Bj(r?.effects),hidden:r?.hide??!0}));const a=A.properties.Description;i.push(new y1({key:"Description",value:a?.value??"",position:a?.at?[Number(a.at.x),Number(a.at.y),Number(a.at.rotation??0)]:[0,0,0],layer:a?.layer??"F.Fab",uuid:cd(`${t}-property-Description`),effects:Bj(a?.effects),hidden:a?.hide??!0})),e.properties=i}if(A.attributes&&(e.attr||(e.attr=new uDA),A.attributes.through_hole?e.attr.type="through_hole":A.attributes.smd&&(e.attr.type="smd"),A.attributes.exclude_from_pos_files!==void 0&&(e.attr.excludeFromPosFiles=A.attributes.exclude_from_pos_files),A.attributes.exclude_from_bom!==void 0&&(e.attr.excludeFromBom=A.attributes.exclude_from_bom)),A.footprintName&&(e.libraryLink=A.footprintName),A.layer&&(e.layer=A.layer),A.embeddedFonts!==void 0&&(e.embeddedFonts=new GM(A.embeddedFonts)),A.model){const i=new L3(A.model.path);A.model.offset&&(i.offset={x:Number(A.model.offset.x),y:Number(A.model.offset.y),z:Number(A.model.offset.z)}),A.model.scale&&(i.scale={x:Number(A.model.scale.x),y:Number(A.model.scale.y),z:Number(A.model.scale.z)}),A.model.rotate&&(i.rotate={x:Number(A.model.rotate.x),y:Number(A.model.rotate.y),z:Number(A.model.rotate.z)});const n=e.models||[];e.models=[i,...n]}}function pQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.SilkS",bottom:"B.SilkS"}[i.layer]||i.layer||"F.SilkS",a=new t1A({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new f1,fill:!1});a.stroke&&(a.stroke.width=i.stroke_width||.05,a.stroke.type="default"),t.push(a)}return t}function fQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",a=new t1A({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new f1,fill:!1});a.stroke&&(a.stroke.width=.05,a.stroke.type="default"),t.push(a)}return t}function yQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.Fab",bottom:"B.Fab"}[i.layer]||i.layer||"F.Fab",c=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new f1,fill:!1});c.stroke&&(c.stroke.width=i.stroke_width||.1,c.stroke.type="default"),t.push(c)}return t}function mQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,a="F.Fab",g=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:a,stroke:new f1,fill:!1});g.stroke&&(g.stroke.width=i.stroke_width||.1,g.stroke.type="default"),t.push(g)}return t}function wQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",c=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new f1,fill:!1});c.stroke&&(c.stroke.width=.05,c.stroke.type="default"),t.push(c)}return t}function DQi(e,A){const t=[];for(const i of e){if(!i.outline||i.outline.length<2)continue;const o={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",s=i.outline.map(g=>{const c=g.x-A.x,I=-(g.y-A.y);return new oh(c,I)}),r=new Hpt;r.points=new oQ(s),r.layer=o,r.fill=!1;const a=new f1;a.width=.05,a.type="default",r.stroke=a,t.push(r)}return t}function xQi({textElement:e,componentCenter:A,componentRotation:t=0}){if(!e.text||!e.anchor_position)return null;const i=e.anchor_position.x-A.x,n=-(e.anchor_position.y-A.y),o=t!==0?Jl(t*Math.PI/180):Sa(),s=Ct(o,{x:i,y:n}),r={x:s.x,y:s.y},g={top:"F.SilkS",bottom:"B.SilkS"}[e.layer]||e.layer||"F.SilkS",c=(e.font_size||1)/1.5,I=new Tp;I.size={width:c,height:c};const l=new Jp({font:I}),B=e.ccw_rotation||0;return new qDA({type:"user",text:e.text,position:{x:r.x,y:r.y,angle:B},layer:g,effects:l})}function SQi(e,A,t,i){const n=[];for(const o of e){const s=xQi({textElement:o,componentCenter:A,componentRotation:t});s&&(i&&o.text===i&&(s.type="reference"),n.push(s))}return n}function bQi(e,A,t){const i=[];for(const n of e){const o=n.anchor_position.x-A.x,s=-(n.anchor_position.y-A.y),r=t!==0?Jl(t*Math.PI/180):Sa(),a=Ct(r,{x:o,y:s}),g=n.font_size||1,c=new Tp;c.size={width:g,height:g};const I=new Jp({font:c}),l=new qDA({type:"user",text:n.text,position:{x:a.x,y:a.y,angle:0},layer:"F.Fab",effects:I});i.push(l)}return i}function _Qi(e,A,t){const i=[],n=e.model_step_url||e.model_wrl_url;if(!n)return i;const o=new L3(n);if(e.position){const s=t?.boardLayerZOffset??0;o.offset={x:(e.position.x||0)-A.x,y:(e.position.y||0)-A.y,z:(e.position.z||0)-s}}if(e.rotation&&(o.rotate={x:e.rotation.x||0,y:e.rotation.y||0,z:e.rotation.z||0}),e.model_unit_to_mm_scale_factor){const s=e.model_unit_to_mm_scale_factor;o.scale={x:s,y:s,z:s}}return i.push(o),i}function kQi({pcbPad:e,componentCenter:A,padNumber:t,componentRotation:i=0,netInfo:n,componentId:o}){let s,r;if("x"in e&&"y"in e)s=e.x,r=e.y;else if("points"in e&&Array.isArray(e.points)){const u=e.points;s=u.reduce((d,f)=>d+f.x,0)/u.length,r=u.reduce((d,f)=>d+f.y,0)/u.length}else throw new Error("Pad must have either x/y coordinates or points array");const a=tn(i!==0?Jl(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},za(1,-1),sn(-A.x,-A.y)),g=Ct(a,{x:s,y:r}),I={top:"F.Cu",bottom:"B.Cu"}[e.layer]||"F.Cu";let l,B,C,Q;if(e.shape==="circle")l="circle",B=["radius"in e?e.radius*2:.5,"radius"in e?e.radius*2:.5];else if(e.shape==="polygon"&&"points"in e){const u=e.points,d=tn(za(1,-1),sn(-s,-r)),f=u.map(w=>{const D=Ct(d,{x:w.x,y:w.y});return new oh(D.x,D.y)}),m=new YDA;m.contours=[new oQ(f)],m.width=0,m.filled=!0,Q=new ypt,Q.addGraphic(m),l="custom",C=new opt,C.anchor="circle",B=[.2,.2]}else l="rect",B=["width"in e?e.width:.5,"height"in e?e.height:.5];const h=`pad:${o}:${t}:${g.x},${g.y}`,E=new $V({number:String(t),padType:"smd",shape:l,at:[g.x,g.y,0],size:B,layers:[`${I}`,`${I==="F.Cu"?"F":"B"}.Paste`,`${I==="F.Cu"?"F":"B"}.Mask`],uuid:cd(h)});return C&&(E.options=C),Q&&(E.primitives=Q),n&&(E.net=new GDA(n.id,n.name)),E}function vQi(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=kQi({pcbPad:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});s.push(c),r++}return{pads:s,nextPadNumber:r}}function FQi({platedHole:e,componentCenter:A,padNumber:t,componentRotation:i=0,netInfo:n,componentId:o}){if(!("x"in e&&"y"in e))return null;const s=e.x-A.x,r=-(e.y-A.y),a=i!==0?Jl(i*Math.PI/180):Sa(),g=Ct(a,{x:s,y:r});let c="circle",I,l,B=0;const C="hole_offset_x"in e||"hole_offset_y"in e;let Q;if(C){const u={x:e.hole_offset_x??0,y:e.hole_offset_y??0};(u.x!==0||u.y!==0)&&(Q=Ct(a,{x:-u.x,y:u.y}))}e.shape==="circle"?(c="circle",I=[e.outer_diameter,e.outer_diameter],l=new m1({diameter:e.hole_diameter,offset:Q})):e.shape==="pill"||e.shape==="oval"?(c="oval",I=[e.outer_width,e.outer_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q})):e.shape==="pill_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q})):e.shape==="circular_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({diameter:e.hole_diameter,offset:Q})):e.shape==="rotated_pill_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q}),B=e.rect_ccw_rotation||0):(c="circle",I=[1.6,1.6],l=new m1({diameter:.8,offset:Q}));const h=`thruhole:${o}:${t}:${g.x},${g.y}`,E=new $V({number:String(t),padType:"thru_hole",shape:c,at:[g.x,g.y,B],size:I,drill:l,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:cd(h)});return n&&(E.net=new GDA(n.id,n.name)),E}function MQi(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=FQi({platedHole:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});c&&(s.push(c),r++)}return{pads:s,nextPadNumber:r}}function GQi({pcbHole:e,componentCenter:A,componentRotation:t=0}){if(!("x"in e&&"y"in e))return null;const i=e.x-A.x,n=-(e.y-A.y),o=t!==0?Jl(t*Math.PI/180):Sa(),s=Ct(o,{x:i,y:n});let r="circle",a,g;if(e.hole_shape==="circle"){r="circle";const c=e.hole_diameter;a=[c,c],g=new m1({diameter:c})}else if(e.hole_shape==="oval"){r="oval";const c=e.hole_width,I=e.hole_height;a=[c,I],g=new m1({oval:!0,diameter:c,width:I})}else{r="circle";const c="hole_diameter"in e?e.hole_diameter:1;a=[c,c],g=new m1({diameter:c})}return new $V({number:"",padType:"np_thru_hole",shape:r,at:[s.x,s.y,0],size:a,drill:g,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:crypto.randomUUID()})}function pyt(e,A,t){const i=[];for(const n of e){const o=GQi({pcbHole:n,componentCenter:A,componentRotation:t});o&&i.push(o)}return i}var RQi=class extends t0{componentsProcessed=0;pcbComponents=[];includeBuiltin3dModels;getNetInfoForPcbPort(e){if(!e)return;const A=this.ctx.db.pcb_port?.get(e);if(!A)return;const t=A.source_port_id;if(!t)return;const i=this.ctx.db.source_port?.get(t);if(!i)return;const n=i.subcircuit_connectivity_map_key;if(n)return this.ctx.pcbNetMap?.get(n)}getCadComponentForPcbComponent(e){return(this.ctx.db.cad_component?.list()||[]).find(t=>t.pcb_component_id===e)}constructor(e,A,t){super(e,A),this.pcbComponents=this.ctx.db.pcb_component.list(),this.includeBuiltin3dModels=t?.includeBuiltin3dModels??!1}_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.componentsProcessed>=this.pcbComponents.length){this.finished=!0;return}const t=this.pcbComponents[this.componentsProcessed],i=t.source_component_id?this.ctx.db.source_component.get(t.source_component_id):null,n=this.getCadComponentForPcbComponent(t.pcb_component_id),o=i?U3(i,n):"Unknown",s=Ct(A,{x:t.center.x,y:t.center.y}),r=`footprint:${t.pcb_component_id}:${s.x},${s.y}`,a=new nj({libraryLink:`tscircuit:${o}`,layer:"F.Cu",at:[s.x,s.y,t.rotation||0],uuid:cd(r)}),g=a.fpTexts,c=this.ctx.db.pcb_silkscreen_text?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];g.push(...SQi(c,t.center,t.rotation||0,i?.name));const I=this.ctx.db.pcb_note_text?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];g.push(...bQi(I,t.center,t.rotation||0)),a.fpTexts=g;const l=a.fpPads,B=O=>this.getNetInfoForPcbPort(O),C=this.ctx.db.pcb_smtpad?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],{pads:Q,nextPadNumber:h}=vQi(C,t.center,t.rotation||0,t.pcb_component_id,1,B);l.push(...Q);const E=this.ctx.db.pcb_plated_hole?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],{pads:u}=MQi(E,t.center,t.rotation||0,t.pcb_component_id,h,B);l.push(...u);const d=this.ctx.db.pcb_hole?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],f=pyt(d,t.center,t.rotation||0);l.push(...f),a.fpPads=l;const m=this.ctx.db.pcb_silkscreen_circle?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],w=a.fpCircles??[];w.push(...pQi(m,t.center));const D=this.ctx.db.pcb_courtyard_circle?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];w.push(...fQi(D,t.center)),a.fpCircles=w;const x=this.ctx.db.pcb_fabrication_note_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],_=a.fpRects??[];_.push(...yQi(x,t.center));const b=this.ctx.db.pcb_note_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];_.push(...mQi(b,t.center));const R=this.ctx.db.pcb_courtyard_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];_.push(...wQi(R,t.center)),a.fpRects=_;const F=this.ctx.db.pcb_courtyard_outline?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],H=DQi(F,t.center);if(H.length>0&&(a.fpPolys=H),n){const W=this.ctx.db.pcb_board?.list()[0]?.thickness??0,z=t.layer==="bottom"?-(W/2):W/2,tA=_Qi(n,t.center,{boardLayerZOffset:z}),aA="${KIPRJMOD}/3dmodels";if(tA.length>0)this.includeBuiltin3dModels?a.models=tA.map(eA=>{if(!eA.path)return eA;const oA=b2A(eA.path),lA=eA.path.startsWith("http://modelcdn.tscircuit.com")||eA.path.startsWith("https://modelcdn.tscircuit.com")?"tscircuit_builtin":this.ctx.projectName??oA.replace(/\.[^.]+$/,""),pA=new L3(`${aA}/${lA}.3dshapes/${oA}`);eA.offset&&(pA.offset=eA.offset),eA.scale&&(pA.scale=eA.scale),eA.rotate&&(pA.rotate=eA.rotate);const kA=eA.path?.split("?")[0];return kA&&!this.ctx.pcbModel3dSourcePaths?.includes(kA)&&this.ctx.pcbModel3dSourcePaths?.push(kA),pA}):a.models=tA;else if(n.footprinter_string&&this.includeBuiltin3dModels){const{footprinter_string:eA}=n,oA=`${aA}/tscircuit_builtin.3dshapes/${eA}.step`;a.models=[new L3(oA)];const rA=`${dyt}/${eA}.step`;this.ctx.pcbModel3dSourcePaths?.includes(rA)||this.ctx.pcbModel3dSourcePaths?.push(rA)}}const Y=t.metadata?.kicad_footprint;Y&&i?.name&&dQi(a,Y,i.name);const J=e.footprints;J.push(a),e.footprints=J,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},NQi={top:"F.Cu",bottom:"B.Cu",inner1:"In1.Cu",inner2:"In2.Cu",inner3:"In3.Cu",inner4:"In4.Cu",inner5:"In5.Cu",inner6:"In6.Cu"};function LQi(e){return e&&(NQi[e]||e)||"F.Cu"}function UQi(e){const A=["F.Cu"];for(let t=1;t<e-1;t++)A.push(`In${t}.Cu`);return A.push("B.Cu"),A}var HQi=class extends t0{tracesProcessed=0;pcbTraces=[];constructor(e,A){super(e,A),this.pcbTraces=this.ctx.db.pcb_trace.list()}_step(){const{kicadPcb:e,c2kMatPcb:A,pcbNetMap:t}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.tracesProcessed>=this.pcbTraces.length){this.finished=!0;return}const i=this.pcbTraces[this.tracesProcessed];if(!i.route||i.route.length<2){this.tracesProcessed++;return}let n=i.route[0]?.layer;for(let o=0;o<i.route.length-1;o++){const s=i.route[o],r=i.route[o+1],a=Ct(A,{x:s.x,y:s.y}),g=Ct(A,{x:r.x,y:r.y});let c;if(t){let h=i.subcircuit_connectivity_map_key;if(!h&&i.source_trace_id){const E=this.ctx.db.source_trace?.get(i.source_trace_id);if(E&&(h=E.subcircuit_connectivity_map_key,!h&&E.connected_source_net_ids?.length))for(const u of E.connected_source_net_ids){const d=this.ctx.db.source_net?.get(u);if(d?.subcircuit_connectivity_map_key){h=d.subcircuit_connectivity_map_key;break}}}if(!h&&typeof i.connection_name=="string"){const E=this.ctx.db.source_net?.get(i.connection_name);E?.subcircuit_connectivity_map_key&&(h=E.subcircuit_connectivity_map_key)}h&&(c=t.get(h))}const I=s.layer??r.layer??n,l=LQi(I),B=`segment:${a.x},${a.y}:${g.x},${g.y}:${l}:${c?.id??0}`,C=new _1A({start:{x:a.x,y:a.y},end:{x:g.x,y:g.y},layer:l,width:i.width||.25,net:new rj(c?.id??0),uuid:cd(B)}),Q=e.segments;Q.push(C),e.segments=Q,s.layer&&(n=s.layer),r.layer&&(n=r.layer)}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},YQi=class extends t0{viasProcessed=0;pcbVias=[];constructor(e,A){super(e,A),this.pcbVias=this.ctx.db.pcb_via?.list()||[]}_step(){const{kicadPcb:e,c2kMatPcb:A,pcbNetMap:t}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.viasProcessed>=this.pcbVias.length){this.finished=!0;return}const i=this.pcbVias[this.viasProcessed],n=Ct(A,{x:i.x,y:i.y});let o;if(t){let I=i.subcircuit_connectivity_map_key;if(!I&&i.pcb_trace_id){const l=this.ctx.db.pcb_trace?.get(i.pcb_trace_id);if(l&&("subcircuit_connectivity_map_key"in l&&(I=l.subcircuit_connectivity_map_key),!I&&l.source_trace_id)){const B=this.ctx.db.source_trace?.get(l.source_trace_id);if(B&&("subcircuit_connectivity_map_key"in B&&(I=B.subcircuit_connectivity_map_key),!I&&B.connected_source_net_ids?.length))for(const C of B.connected_source_net_ids){const Q=this.ctx.db.source_net?.get(C);if(Q?.subcircuit_connectivity_map_key){I=Q.subcircuit_connectivity_map_key;break}}}}if(!I&&i.connection_name){const l=this.ctx.db.source_net?.get(i.connection_name);l?.subcircuit_connectivity_map_key&&(I=l.subcircuit_connectivity_map_key)}I&&(o=t.get(I))}const s=this.ctx.numLayers??2,r=i.layers?i.layers.map(I=>I==="top"?"F.Cu":I==="bottom"?"B.Cu":`In${I.replace("inner","")}.Cu`):UQi(s),a=`via:${n.x},${n.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${o?.id??0}`,g=new D2A({at:[n.x,n.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:r,net:new w2A(o?.id??0),uuid:cd(a)}),c=e.vias;c.push(g),e.vias=c,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}},JQi=class extends t0{holesProcessed=0;standaloneHoles=[];constructor(e,A){super(e,A),this.standaloneHoles=this.ctx.db.pcb_hole.list().filter(t=>!t.pcb_component_id)}_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.holesProcessed>=this.standaloneHoles.length){this.finished=!0;return}const t=this.standaloneHoles[this.holesProcessed];if(!t){this.holesProcessed++;return}const i=Ct(A,{x:0,y:0}),n=`standalone_hole:${t.pcb_hole_id}:${t.x},${t.y}`,o=new nj({libraryLink:"tscircuit:MountingHole",layer:"F.Cu",at:[i.x,i.y,0],uuid:cd(n)}),r=pyt([t],{x:0,y:0},0);if(r.length>0){o.fpPads=r;const a=e.footprints;a.push(o),e.footprints=a}this.holesProcessed++}getOutput(){return this.ctx.kicadPcb}};function TQi({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Ct(A,{x:e.anchor_position.x,y:e.anchor_position.y}),n={top:"F.Fab",bottom:"B.Fab"}[e.layer]||e.layer||"F.Fab",o=(e.font_size||1)/1.5,s=new Tp;s.size={width:o,height:o};const r=new a6,a=e.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new Jp({font:s});a!=="center"&&(g.justify=r);const c=new oc([t.x,t.y,0]),I=new sj({text:e.text,layer:n,effects:g});return I.position=c,I}function PQi({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Ct(A,{x:e.anchor_position.x,y:e.anchor_position.y}),n={top:"F.SilkS",bottom:"B.SilkS"}[e.layer]||e.layer||"F.SilkS",o=(e.font_size||1)/1.5,s=new Tp;s.size={width:o,height:o};const r=new a6,a=e.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new Jp({font:s});a!=="center"&&(g.justify=r);const c=e.ccw_rotation||0,I=new oc([t.x,t.y,c]),l=new sj({text:e.text,layer:n,effects:g});return l.position=I,l}var KQi=class extends t0{_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");const t=this.ctx.db.pcb_silkscreen_path?.list()||[];for(const s of t)if(!(!s.route||s.route.length<2))for(let r=0;r<s.route.length-1;r++){const a=s.route[r],g=s.route[r+1];if(!a||!g)continue;const c=Ct(A,{x:a.x,y:a.y}),I=Ct(A,{x:g.x,y:g.y}),B={top:"F.SilkS",bottom:"B.SilkS"}[s.layer]||s.layer||"F.SilkS",C=new oj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:B,width:s.stroke_width||.15}),Q=e.graphicLines;Q.push(C),e.graphicLines=Q}const i=this.ctx.db.pcb_silkscreen_text?.list().filter(s=>!s.pcb_component_id)||[];for(const s of i){const r=PQi({textElement:s,c2kMatPcb:A});if(r){const a=e.graphicTexts;a.push(r),e.graphicTexts=a}}const n=this.ctx.db.pcb_fabrication_note_text?.list()||[];for(const s of n){const r=TQi({textElement:s,c2kMatPcb:A});if(r){const a=e.graphicTexts;a.push(r),e.graphicTexts=a}}const o=this.ctx.db.pcb_board?.list()||[];if(o.length>0){const s=o[0];if(!s){this.finished=!0;return}let r;if(s.outline&&s.outline.length>0)r=s.outline;else{const g=s.width?s.width/2:0,c=s.height?s.height/2:0;r=[{x:s.center.x-g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y+c},{x:s.center.x-g,y:s.center.y+c}]}const a=r.map(g=>Ct(A,g));for(let g=0;g<a.length;g++){const c=a[g],I=a[(g+1)%a.length];if(!c||!I)continue;const l=new oj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:"Edge.Cuts",width:.1}),B=e.graphicLines;B.push(l),e.graphicLines=B}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},fyt=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e,A){this.ctx={db:Na(e),circuitJson:e,kicadPcb:new x2A({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:tn(sn(100,100),za(1,-1)),projectName:A?.projectName,pcbModel3dSourcePaths:[]},this.pipeline=[new lQi(e,this.ctx),new BQi(e,this.ctx),new RQi(e,this.ctx,{includeBuiltin3dModels:A?.includeBuiltin3dModels}),new HQi(e,this.ctx),new YQi(e,this.ctx),new JQi(e,this.ctx),new KQi(e,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadPcb}getOutputString(){return this.ctx.kicadPcb.getString()}getModel3dSourcePaths(){return this.ctx.pcbModel3dSourcePaths??[]}},qQi=class{ctx;project;constructor(e,A={}){const t=A.projectName??e?.project?.name??"circuit-json-project",i=A.schematicFilename??`${t}.kicad_sch`,n=A.pcbFilename??`${t}.kicad_pcb`,o=new Date().toISOString();this.ctx={db:Na(e),circuitJson:e},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:t,created:o,modified:o},meta:{version:1},text_variables:{},libraries:{pinned_symbol_libs:[],pinned_footprint_libs:[]},boards:[],cvpcb:{meta:{version:0}},erc:{meta:{version:0},erc_exclusions:[]},net_settings:{meta:{version:1},last_net_id:0,classes:[]},pcbnew:{page_layout_descr_file:"",last_paths:{}},schematic:{meta:{version:1},page_layout_descr_file:"",last_opened_files:[i]},board:{meta:{version:1},last_opened_board:n},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
|
|
5830
5830
|
`}},OQi=class extends t0{_step(){const e=new uyt(this.ctx.circuitJson);e.runUntilFinished(),this.ctx.kicadSchString=e.getOutputString();const A=new fyt(this.ctx.circuitJson);A.runUntilFinished(),this.ctx.kicadPcbString=A.getOutputString(),this.finished=!0}getOutput(){return this.ctx.libraryOutput}},WQi=class extends t0{isCustomSymbol(e){return e?.startsWith("Custom:")??!1}_step(){const e=this.ctx.kicadSchString,A=this.ctx.fpLibraryName??"tscircuit";if(!e)throw new Error("Schematic content not available. Run GenerateKicadSchAndPcbStage first.");const t=new Map;try{const n=lyt(e).find(r=>r instanceof EDA);if(!n){this.ctx.symbolEntries=[],this.finished=!0;return}const o=n.libSymbols;if(!o){this.ctx.symbolEntries=[],this.finished=!0;return}const s=o.symbols??[];for(const r of s){const a=this.isCustomSymbol(r.libraryId),g=this.sanitizeSymbolName(r.libraryId);t.has(g)||(r.libraryId=g,this.updateFootprintProperty(r,A),a||this.snapPinPositionsToGrid(r),t.set(g,{symbolName:g,symbol:r,isBuiltin:!a}))}}catch(i){console.warn("Failed to parse schematic for symbol extraction:",i)}this.ctx.symbolEntries=Array.from(t.values()),this.finished=!0}updateFootprintProperty(e,A){const t=e.properties??[];for(const i of t)if(i.key==="Footprint"&&i.value){const n=i.value.split(":");n.length>1?i.value=`${A}:${n[1]}`:i.value.trim()&&(i.value=`${A}:${i.value}`)}}sanitizeSymbolName(e){if(!e)return"symbol";const A=e.split(":");return(A.length>1?A[1]:A[0])?.replace(/[\\\/]/g,"-").trim()||"symbol"}snapPinPositionsToGrid(e){for(const t of e.subSymbols??[]){for(const i of t.pins??[])i.at&&(i.at.x=Math.round(i.at.x/1.27)*1.27,i.at.y=Math.round(i.at.y/1.27)*1.27);for(const i of t.polylines??[])if(i.points?.points)for(const n of i.points.points)"x"in n&&"y"in n&&(n.x=Math.round(n.x/1.27)*1.27,n.y=Math.round(n.y/1.27)*1.27)}}getOutput(){return this.ctx.libraryOutput}},ZQi=20211014,VQi="circuit-json-to-kicad",jQi=class extends t0{_step(){const e=this.ctx.symbolEntries??[],A=this.generateSymbolLibrary(e);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.kicadSymString=A,this.finished=!0}generateSymbolLibrary(e){return new Fdt({version:ZQi,generator:VQi,symbols:e.map(t=>t.symbol)}).getString()}getOutput(){return this.ctx.libraryOutput}},zQi=class extends t0{_step(){const e=this.ctx.libraryName??"tscircuit",A=this.ctx.fpLibraryName??"tscircuit",t=this.ctx.footprintEntries??[],i=this.ctx.symbolEntries??[],n=new Set;for(const r of t)for(const a of r.model3dSourcePaths)n.add(a);const o=this.generateFpLibTable(A),s=this.generateSymLibTable(e);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.symbols=i,this.ctx.libraryOutput.footprints=t,this.ctx.libraryOutput.fpLibTableString=o,this.ctx.libraryOutput.symLibTableString=s,this.ctx.libraryOutput.model3dSourcePaths=Array.from(n),this.finished=!0}generateFpLibTable(e){return`(fp_lib_table
|
|
5831
5831
|
(version 7)
|
|
5832
5832
|
(lib (name "${e}") (type "KiCad") (uri "\${KIPRJMOD}/${e}.pretty") (options "") (descr "Generated by circuit-json-to-kicad"))
|
package/dist/standalone.min.js
CHANGED
|
@@ -5826,7 +5826,7 @@ ${a.join(`
|
|
|
5826
5826
|
`)}};UA.register(_0i);var dye=class DbA extends UA{static token="locked";static parentToken="group";token="locked";value;constructor(A){super(),this.value=A}static fromSexprPrimitives(A){if(A.length===0)return new DbA(!0);const e=Di(A[0]);return new DbA(e==="yes")}getString(){return this.value?"(locked yes)":"(locked no)"}};UA.register(dye);var pye=class jbe extends UA{static token="members";static parentToken="group";token="members";members;constructor(A){super(),this.members=A}static fromSexprPrimitives(A){const e=[];for(const i of A){const n=Di(i);n&&e.push(n)}return new jbe(e)}getString(){return this.members.length===0?"(members)":`(members ${this.members.map(e=>`"${e}"`).join(" ")})`}};UA.register(pye);var _2A=class zbe extends UA{static token="end";static parentToken="segment";token="end";_x;_y;constructor(A,e){super(),this._x=A,this._y=e}static fromSexprPrimitives(A){const[e,i]=A,n=Ci(e),o=Ci(i);if(n===void 0||o===void 0)throw new Error("end expects two numeric arguments");return new zbe(n,o)}get x(){return this._x}set x(A){this._x=A}get y(){return this._y}set y(A){this._y=A}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(end ${this._x} ${this._y})`}};UA.register(_2A);var k0i=new Set(["true","yes","1"]),fye=class JX extends Vl{static token="locked";static parentToken="segment";token="locked";constructor(A){super(A)}static fromSexprPrimitives(A){const[e]=A;return typeof e=="boolean"?new JX(e):typeof e=="string"?new JX(k0i.has(e.toLowerCase())):new JX(!1)}getString(){return`(locked ${this.value?"yes":"no"})`}};UA.register(fye);var zj=class Xbe extends UA{static token="net";static parentToken="segment";token="net";_id;_name;constructor(A,e){super(),this._id=A,this._name=e}static fromSexprPrimitives(A){const[e,i]=A,n=Ci(e);if(n===void 0)throw new Error("net expects a numeric identifier");const o=i===void 0?void 0:Di(i);return new Xbe(n,o??void 0)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A===""?void 0:A}toObject(){return this._name===void 0?{id:this._id}:{id:this._id,name:this._name}}getChildren(){return[]}getString(){const A=this._name?` ${Dn(this._name)}`:"";return`(net ${this._id}${A})`}};UA.register(zj);var k2A=class $be extends UA{static token="start";static parentToken="segment";token="start";_x;_y;constructor(A,e){super(),this._x=A,this._y=e}static fromSexprPrimitives(A){const[e,i]=A,n=Ci(e),o=Ci(i);if(n===void 0||o===void 0)throw new Error("start expects two numeric arguments");return new $be(n,o)}get x(){return this._x}set x(A){this._x=A}get y(){return this._y}set y(A){this._y=A}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(start ${this._x} ${this._y})`}};UA.register(k2A);var yye=new Set(["start","end","width","layer","net","tstamp","uuid","locked"]),v2A=class A_e extends UA{static token="segment";token="segment";_sxStart;_sxEnd;_sxWidth;_sxLayer;_sxNet;_sxTstamp;_sxUuid;_sxLocked;constructor(A={}){super(),A.start!==void 0&&(this.start=A.start),A.end!==void 0&&(this.end=A.end),A.width!==void 0&&(this.width=A.width),A.layer!==void 0&&(this.layer=A.layer),A.net!==void 0&&(this.net=A.net),A.tstamp!==void 0&&(this.tstamp=A.tstamp),A.uuid!==void 0&&(this.uuid=A.uuid),A.locked!==void 0&&(this.locked=A.locked)}static fromSexprPrimitives(A){const e=new A_e,{propertyMap:i,arrayPropertyMap:n}=UA.parsePrimitivesToClassProperties(A,this.token),o=Object.keys(i).filter(r=>!yye.has(r));if(o.length>0)throw new Error(`Unsupported child tokens inside segment expression: ${o.join(", ")}`);for(const[r,a]of Object.entries(n)){if(!yye.has(r))throw new Error(`Unsupported child tokens inside segment expression: ${r}`);if(a.length>1)throw new Error(`Segment does not support repeated child tokens: ${r}`)}e._sxStart=n.start?.[0]??i.start,e._sxEnd=n.end?.[0]??i.end,e._sxWidth=n.width?.[0]??i.width,e._sxLayer=n.layer?.[0]??i.layer,e._sxNet=n.net?.[0]??i.net;const s=n.locked?.[0]??i.locked;return e._sxLocked=s&&s.value?s:void 0,e._sxTstamp=n.tstamp?.[0]??i.tstamp,e._sxUuid=n.uuid?.[0]??i.uuid,e}get start(){return this._sxStart}set start(A){this._sxStart=this.normalizeStart(A)}get end(){return this._sxEnd}set end(A){this._sxEnd=this.normalizeEnd(A)}get startPoint(){return this._sxStart?.toObject()}get endPoint(){return this._sxEnd?.toObject()}get width(){return this._sxWidth?.value}set width(A){if(A===void 0){this._sxWidth=void 0;return}this._sxWidth=A instanceof Jr?A:new Jr(A)}get widthClass(){return this._sxWidth}set widthClass(A){this._sxWidth=A}get layer(){return this._sxLayer}set layer(A){if(A===void 0){this._sxLayer=void 0;return}if(A instanceof kr){this._sxLayer=A;return}const e=Array.isArray(A)?A:[A];this._sxLayer=new kr(e)}get net(){return this._sxNet}set net(A){if(A===void 0){this._sxNet=void 0;return}if(A instanceof zj){this._sxNet=A;return}this._sxNet=new zj(A.id,A.name)}get tstamp(){return this._sxTstamp}set tstamp(A){if(A===void 0){this._sxTstamp=void 0;return}this._sxTstamp=A instanceof cc?A:new cc(A)}get uuid(){return this._sxUuid}set uuid(A){if(A===void 0){this._sxUuid=void 0;return}this._sxUuid=A instanceof qi?A:new qi(A)}get locked(){return this._sxLocked?.value??!1}set locked(A){this._sxLocked=A?new fye(!0):void 0}getChildren(){const A=[];return this._sxStart&&A.push(this._sxStart),this._sxEnd&&A.push(this._sxEnd),this._sxWidth&&A.push(this._sxWidth),this._sxLayer&&A.push(this._sxLayer),this._sxNet&&A.push(this._sxNet),this._sxLocked&&A.push(this._sxLocked),this._sxTstamp&&A.push(this._sxTstamp),this._sxUuid&&A.push(this._sxUuid),A}normalizeStart(A){if(A!==void 0)return A instanceof k2A?A:new k2A(A.x,A.y)}normalizeEnd(A){if(A!==void 0)return A instanceof _2A?A:new _2A(A.x,A.y)}};UA.register(v2A);var mye=class e_e extends UA{static token="zone";token="zone";_rawChildren=[];static fromSexprPrimitives(A){const e=new e_e;return e._rawChildren=[...A],e}get rawChildren(){return[...this._rawChildren]}set rawChildren(A){this._rawChildren=[...A]}getChildren(){return[]}getString(){const A=["(zone"];for(const e of this._rawChildren)A.push(` ${e0(e)}`);return A.push(")"),A.join(`
|
|
5827
5827
|
`)}};UA.register(mye);var Xj=class t_e extends UA{static token="layers";token="layers";_names=[];constructor(A=[]){super(),this.names=A}static fromSexprPrimitives(A){const e=A.map(i=>typeof i=="string"||typeof i=="number"?String(i):e0(i));return new t_e(e)}get names(){return[...this._names]}set names(A){this._names=A.map(e=>String(e))}getString(){return`(layers ${this._names.map(e=>/^[^\s()"]+$/u.test(e)&&!["nil","#t","#f"].includes(e)?e:Dn(e)).join(" ")})`}};UA.register(Xj);var M6=class extends UA{_value;quoteStringValue=!1;constructor(t){super(),this._value=t}static fromSexprPrimitives(t){const[A]=t,e=this.parsePrimitiveValue(A),i=this;return new i(e)}static parsePrimitiveValue(t){const A=Di(t);if(A===void 0)throw new Error(`${this.name} expects a primitive value`);return A}get value(){return this._value}set value(t){this._value=t}getChildren(){return[]}formatValue(){return typeof this._value=="string"?this.quoteStringValue?Dn(this._value):this._value:`${this._value}`}getString(){return`(${this.token} ${this.formatValue()})`}},v0i=class extends UA{_values;constructor(t){super(),this._values=t}static fromSexprPrimitives(t){const A=t.map(i=>{const n=Ci(i);if(n===void 0)throw new Error(`${this.name} expects numeric primitives but received ${i}`);return n}),e=this;return new e(A)}get values(){return[...this._values]}set values(t){this._values=[...t]}getChildren(){return[]}getString(){return`(${this.token} ${this._values.join(" ")})`}},F0i=class extends UA{_x;_y;constructor(t,A){super(),this._x=t,this._y=A}static fromSexprPrimitives(t){const[A,e]=t,i=Ci(A),n=Ci(e);if(i===void 0||n===void 0)throw new Error(`${this.name} expects two numeric values`);const o=this;return new o(i,n)}get x(){return this._x}set x(t){this._x=t}get y(){return this._y}set y(t){this._y=t}getChildren(){return[]}getString(){return`(${this.token} ${this._x} ${this._y})`}},vr=class extends M6{static parentToken="pcbplotparams"},Um=class extends vr{static parsePrimitiveValue(t){const A=Ci(t);if(A===void 0)throw new Error(`pcbplotparams ${this.token} expects a numeric value`);return A}},wye=class extends vr{static token="layerselection";token="layerselection"};UA.register(wye);var Dye=class extends vr{static token="plot_on_all_layers_selection";token="plot_on_all_layers_selection"};UA.register(Dye);var xye=class extends Um{static token="dashed_line_dash_ratio";token="dashed_line_dash_ratio"};UA.register(xye);var Sye=class extends Um{static token="dashed_line_gap_ratio";token="dashed_line_gap_ratio"};UA.register(Sye);var bye=class extends Um{static token="svgprecision";token="svgprecision"};UA.register(bye);var _ye=class extends Um{static token="linewidth";token="linewidth"};UA.register(_ye);var kye=class extends Um{static token="mode";token="mode"};UA.register(kye);var vye=class extends Um{static token="hpglpennumber";token="hpglpennumber"};UA.register(vye);var Fye=class extends Um{static token="hpglpenspeed";token="hpglpenspeed"};UA.register(Fye);var Mye=class extends Um{static token="hpglpendiameter";token="hpglpendiameter"};UA.register(Mye);var Rye=class extends Um{static token="hpglpenoverlay";token="hpglpenoverlay"};UA.register(Rye);var Nye=class extends Um{static token="outputformat";token="outputformat"};UA.register(Nye);var Gye=class extends Um{static token="drillshape";token="drillshape"};UA.register(Gye);var Lye=class extends Um{static token="scaleselection";token="scaleselection"};UA.register(Lye);var Uye=class extends vr{static token="disableapertmacros";token="disableapertmacros"};UA.register(Uye);var Hye=class extends vr{static token="usegerberextensions";token="usegerberextensions"};UA.register(Hye);var Yye=class extends vr{static token="usegerberattributes";token="usegerberattributes"};UA.register(Yye);var Jye=class extends vr{static token="usegerberadvancedattributes";token="usegerberadvancedattributes"};UA.register(Jye);var Tye=class extends vr{static token="creategerberjobfile";token="creategerberjobfile"};UA.register(Tye);var Pye=class extends vr{static token="excludeedgelayer";token="excludeedgelayer"};UA.register(Pye);var Kye=class extends vr{static token="plotframeref";token="plotframeref"};UA.register(Kye);var qye=class extends vr{static token="viasonmask";token="viasonmask"};UA.register(qye);var Oye=class extends vr{static token="useauxorigin";token="useauxorigin"};UA.register(Oye);var Wye=class extends vr{static token="pdf_front_fp_property_popups";token="pdf_front_fp_property_popups"};UA.register(Wye);var Zye=class extends vr{static token="pdf_back_fp_property_popups";token="pdf_back_fp_property_popups"};UA.register(Zye);var Vye=class extends vr{static token="pdf_metadata";token="pdf_metadata"};UA.register(Vye);var jye=class extends vr{static token="pdf_single_document";token="pdf_single_document"};UA.register(jye);var zye=class extends vr{static token="dxfpolygonmode";token="dxfpolygonmode"};UA.register(zye);var Xye=class extends vr{static token="dxfimperialunits";token="dxfimperialunits"};UA.register(Xye);var $ye=class extends vr{static token="dxfusepcbnewfont";token="dxfusepcbnewfont"};UA.register($ye);var Ame=class extends vr{static token="psnegative";token="psnegative"};UA.register(Ame);var eme=class extends vr{static token="psa4output";token="psa4output"};UA.register(eme);var tme=class extends vr{static token="plotreference";token="plotreference"};UA.register(tme);var ime=class extends vr{static token="plotvalue";token="plotvalue"};UA.register(ime);var nme=class extends vr{static token="plotothertext";token="plotothertext"};UA.register(nme);var ome=class extends vr{static token="plotinvisibletext";token="plotinvisibletext"};UA.register(ome);var sme=class extends vr{static token="padsonsilk";token="padsonsilk"};UA.register(sme);var rme=class extends vr{static token="sketchpadsonfab";token="sketchpadsonfab"};UA.register(rme);var ame=class extends vr{static token="plotpadnumbers";token="plotpadnumbers"};UA.register(ame);var gme=class extends vr{static token="hidednponfab";token="hidednponfab"};UA.register(gme);var cme=class extends vr{static token="sketchdnponfab";token="sketchdnponfab"};UA.register(cme);var Ime=class extends vr{static token="crossoutdnponfab";token="crossoutdnponfab"};UA.register(Ime);var lme=class extends vr{static token="subtractmaskfromsilk";token="subtractmaskfromsilk"};UA.register(lme);var Bme=class extends vr{static token="plot_black_and_white";token="plot_black_and_white"};UA.register(Bme);var Cme=class extends vr{static token="mirror";token="mirror"};UA.register(Cme);var Qme=class extends vr{static token="outputdirectory";token="outputdirectory";quoteStringValue=!0};UA.register(Qme);var hme=class extends vr{static token="plot_on_all_layers";token="plot_on_all_layers"};UA.register(hme);var Eme=class extends vr{static token="plotinvisible";token="plotinvisible"};UA.register(Eme);var M0i={layerselection:"layerselection",plot_on_all_layers_selection:"plot_on_all_layers_selection",disableapertmacros:"disableapertmacros",usegerberextensions:"usegerberextensions",usegerberattributes:"usegerberattributes",usegerberadvancedattributes:"usegerberadvancedattributes",creategerberjobfile:"creategerberjobfile",excludeedgelayer:"excludeedgelayer",dashed_line_dash_ratio:"dashed_line_dash_ratio",dashed_line_gap_ratio:"dashed_line_gap_ratio",svgprecision:"svgprecision",linewidth:"linewidth",plotframeref:"plotframeref",plotreference:"plotreference",plotvalue:"plotvalue",plotothertext:"plotothertext",plotinvisibletext:"plotinvisibletext",padsonsilk:"padsonsilk",sketchpadsonfab:"sketchpadsonfab",plotpadnumbers:"plotpadnumbers",hidednponfab:"hidednponfab",sketchdnponfab:"sketchdnponfab",crossoutdnponfab:"crossoutdnponfab",subtractmaskfromsilk:"subtractmaskfromsilk",plot_black_and_white:"plot_black_and_white",plot_on_all_layers:"plot_on_all_layers",plotinvisible:"plotinvisible",mode:"mode",useauxorigin:"useauxorigin",viasonmask:"viasonmask",hpglpennumber:"hpglpennumber",hpglpenspeed:"hpglpenspeed",hpglpendiameter:"hpglpendiameter",hpglpenoverlay:"hpglpenoverlay",pdf_front_fp_property_popups:"pdf_front_fp_property_popups",pdf_back_fp_property_popups:"pdf_back_fp_property_popups",pdf_metadata:"pdf_metadata",pdf_single_document:"pdf_single_document",dxfpolygonmode:"dxfpolygonmode",dxfimperialunits:"dxfimperialunits",dxfusepcbnewfont:"dxfusepcbnewfont",psnegative:"psnegative",psa4output:"psa4output",mirror:"mirror",outputformat:"outputformat",drillshape:"drillshape",scaleselection:"scaleselection",outputdirectory:"outputdirectory"},R0i=["layerselection","plot_on_all_layers_selection","disableapertmacros","usegerberextensions","usegerberattributes","usegerberadvancedattributes","creategerberjobfile","excludeedgelayer","dashed_line_dash_ratio","dashed_line_gap_ratio","svgprecision","linewidth","plotframeref","plotreference","plotvalue","plotothertext","mode","useauxorigin","viasonmask","hpglpennumber","hpglpenspeed","hpglpendiameter","hpglpenoverlay","pdf_front_fp_property_popups","pdf_back_fp_property_popups","pdf_metadata","pdf_single_document","dxfpolygonmode","dxfimperialunits","dxfusepcbnewfont","psnegative","psa4output","plot_black_and_white","plot_on_all_layers","plotinvisible","plotinvisibletext","padsonsilk","sketchpadsonfab","plotpadnumbers","hidednponfab","sketchdnponfab","crossoutdnponfab","subtractmaskfromsilk","outputformat","mirror","drillshape","scaleselection","outputdirectory"],F2A=class i_e extends UA{static token="pcbplotparams";static parentToken="setup";token="pcbplotparams";_properties={};static fromSexprPrimitives(A){const e=new i_e,{propertyMap:i}=UA.parsePrimitivesToClassProperties(A,this.token);for(const[n,o]of Object.entries(i)){const s=M0i[n];if(!s)throw new Error(`Unsupported pcbplotparams token: ${n}`);e._properties[s]=o}return e}getChildren(){const A=[];for(const e of R0i){const i=this._properties[e];i&&A.push(i)}return A}clearProperty(A){delete this._properties[A]}setStringProperty(A,e,i){if(e===void 0){this.clearProperty(A);return}this._properties[A]=new i(e)}setNumberProperty(A,e,i){if(e===void 0){this.clearProperty(A);return}this._properties[A]=new i(e)}setStringOrNumberProperty(A,e,i){if(e===void 0){this.clearProperty(A);return}this._properties[A]=new i(e)}get layerselection(){return this._properties.layerselection?.value}set layerselection(A){this.setStringOrNumberProperty("layerselection",A,wye)}get plot_on_all_layers_selection(){return this._properties.plot_on_all_layers_selection?.value}set plot_on_all_layers_selection(A){this.setStringOrNumberProperty("plot_on_all_layers_selection",A,Dye)}get disableapertmacros(){return this._properties.disableapertmacros?.value}set disableapertmacros(A){this.setStringProperty("disableapertmacros",A,Uye)}get usegerberextensions(){return this._properties.usegerberextensions?.value}set usegerberextensions(A){this.setStringProperty("usegerberextensions",A,Hye)}get usegerberattributes(){return this._properties.usegerberattributes?.value}set usegerberattributes(A){this.setStringProperty("usegerberattributes",A,Yye)}get usegerberadvancedattributes(){return this._properties.usegerberadvancedattributes?.value}set usegerberadvancedattributes(A){this.setStringProperty("usegerberadvancedattributes",A,Jye)}get creategerberjobfile(){return this._properties.creategerberjobfile?.value}set creategerberjobfile(A){this.setStringProperty("creategerberjobfile",A,Tye)}get excludeedgelayer(){return this._properties.excludeedgelayer?.value}set excludeedgelayer(A){this.setStringProperty("excludeedgelayer",A,Pye)}get dashed_line_dash_ratio(){return this._properties.dashed_line_dash_ratio?.value}set dashed_line_dash_ratio(A){this.setNumberProperty("dashed_line_dash_ratio",A,xye)}get dashed_line_gap_ratio(){return this._properties.dashed_line_gap_ratio?.value}set dashed_line_gap_ratio(A){this.setNumberProperty("dashed_line_gap_ratio",A,Sye)}get svgprecision(){return this._properties.svgprecision?.value}set svgprecision(A){this.setNumberProperty("svgprecision",A,bye)}get linewidth(){return this._properties.linewidth?.value}set linewidth(A){this.setNumberProperty("linewidth",A,_ye)}get plotframeref(){return this._properties.plotframeref?.value}set plotframeref(A){this.setStringProperty("plotframeref",A,Kye)}get plotreference(){return this._properties.plotreference?.value}set plotreference(A){this.setStringProperty("plotreference",A,tme)}get plotvalue(){return this._properties.plotvalue?.value}set plotvalue(A){this.setStringProperty("plotvalue",A,ime)}get plotothertext(){return this._properties.plotothertext?.value}set plotothertext(A){this.setStringProperty("plotothertext",A,nme)}get plotinvisibletext(){return this._properties.plotinvisibletext?.value}set plotinvisibletext(A){this.setStringProperty("plotinvisibletext",A,ome)}get padsonsilk(){return this._properties.padsonsilk?.value}set padsonsilk(A){this.setStringProperty("padsonsilk",A,sme)}get plotpadnumbers(){return this._properties.plotpadnumbers?.value}set plotpadnumbers(A){this.setStringProperty("plotpadnumbers",A,ame)}get sketchpadsonfab(){return this._properties.sketchpadsonfab?.value}set sketchpadsonfab(A){this.setStringProperty("sketchpadsonfab",A,rme)}get hidednponfab(){return this._properties.hidednponfab?.value}set hidednponfab(A){this.setStringProperty("hidednponfab",A,gme)}get sketchdnponfab(){return this._properties.sketchdnponfab?.value}set sketchdnponfab(A){this.setStringProperty("sketchdnponfab",A,cme)}get crossoutdnponfab(){return this._properties.crossoutdnponfab?.value}set crossoutdnponfab(A){this.setStringProperty("crossoutdnponfab",A,Ime)}get subtractmaskfromsilk(){return this._properties.subtractmaskfromsilk?.value}set subtractmaskfromsilk(A){this.setStringProperty("subtractmaskfromsilk",A,lme)}get plot_black_and_white(){return this._properties.plot_black_and_white?.value}set plot_black_and_white(A){this.setStringProperty("plot_black_and_white",A,Bme)}get plot_on_all_layers(){return this._properties.plot_on_all_layers?.value}set plot_on_all_layers(A){this.setStringProperty("plot_on_all_layers",A,hme)}get plotinvisible(){return this._properties.plotinvisible?.value}set plotinvisible(A){this.setStringProperty("plotinvisible",A,Eme)}get mode(){return this._properties.mode?.value}set mode(A){this.setNumberProperty("mode",A,kye)}get useauxorigin(){return this._properties.useauxorigin?.value}set useauxorigin(A){this.setStringProperty("useauxorigin",A,Oye)}get viasonmask(){return this._properties.viasonmask?.value}set viasonmask(A){this.setStringProperty("viasonmask",A,qye)}get hpglpennumber(){return this._properties.hpglpennumber?.value}set hpglpennumber(A){this.setNumberProperty("hpglpennumber",A,vye)}get hpglpenspeed(){return this._properties.hpglpenspeed?.value}set hpglpenspeed(A){this.setNumberProperty("hpglpenspeed",A,Fye)}get hpglpendiameter(){return this._properties.hpglpendiameter?.value}set hpglpendiameter(A){this.setNumberProperty("hpglpendiameter",A,Mye)}get hpglpenoverlay(){return this._properties.hpglpenoverlay?.value}set hpglpenoverlay(A){this.setNumberProperty("hpglpenoverlay",A,Rye)}get pdf_front_fp_property_popups(){return this._properties.pdf_front_fp_property_popups?.value}set pdf_front_fp_property_popups(A){this.setStringProperty("pdf_front_fp_property_popups",A,Wye)}get pdf_back_fp_property_popups(){return this._properties.pdf_back_fp_property_popups?.value}set pdf_back_fp_property_popups(A){this.setStringProperty("pdf_back_fp_property_popups",A,Zye)}get pdf_metadata(){return this._properties.pdf_metadata?.value}set pdf_metadata(A){this.setStringProperty("pdf_metadata",A,Vye)}get pdf_single_document(){return this._properties.pdf_single_document?.value}set pdf_single_document(A){this.setStringProperty("pdf_single_document",A,jye)}get dxfpolygonmode(){return this._properties.dxfpolygonmode?.value}set dxfpolygonmode(A){this.setStringProperty("dxfpolygonmode",A,zye)}get dxfimperialunits(){return this._properties.dxfimperialunits?.value}set dxfimperialunits(A){this.setStringProperty("dxfimperialunits",A,Xye)}get dxfusepcbnewfont(){return this._properties.dxfusepcbnewfont?.value}set dxfusepcbnewfont(A){this.setStringProperty("dxfusepcbnewfont",A,$ye)}get psnegative(){return this._properties.psnegative?.value}set psnegative(A){this.setStringProperty("psnegative",A,Ame)}get psa4output(){return this._properties.psa4output?.value}set psa4output(A){this.setStringProperty("psa4output",A,eme)}get mirror(){return this._properties.mirror?.value}set mirror(A){this.setStringProperty("mirror",A,Cme)}get outputformat(){return this._properties.outputformat?.value}set outputformat(A){this.setNumberProperty("outputformat",A,Nye)}get drillshape(){return this._properties.drillshape?.value}set drillshape(A){this.setNumberProperty("drillshape",A,Gye)}get scaleselection(){return this._properties.scaleselection?.value}set scaleselection(A){this.setNumberProperty("scaleselection",A,Lye)}get outputdirectory(){return this._properties.outputdirectory?.value}set outputdirectory(A){this.setStringProperty("outputdirectory",A,Qme)}};UA.register(F2A);var $j=class extends M6{static parentToken="setup"},M2A=class extends $j{static token="zone_45_only";token="zone_45_only"};UA.register(M2A);var R2A=class extends $j{static token="allow_soldermask_bridges_in_footprints";token="allow_soldermask_bridges_in_footprints"};UA.register(R2A);var N2A=class extends $j{static token="visible_elements";token="visible_elements"};UA.register(N2A);var G2A=class extends $j{static token="uvias_allowed";token="uvias_allowed"};UA.register(G2A);var L2A=class n_e extends UA{static token="tenting";static parentToken="setup";token="tenting";_sides=[];constructor(A=[]){super(),this.sides=A}static fromSexprPrimitives(A){const e=A.map(i=>Di(i)).filter(i=>i!==void 0);return new n_e(e)}get sides(){return[...this._sides]}set sides(A){this._sides=A.map(e=>String(e))}getChildren(){return[]}getString(){return this._sides.length===0?"(tenting)":`(tenting ${this._sides.join(" ")})`}};UA.register(L2A);var R6=class extends v0i{static parentToken="setup"},ume=class extends F0i{static parentToken="setup"},U2A=class extends R6{static token="pcb_text_size";token="pcb_text_size"};UA.register(U2A);var H2A=class extends R6{static token="mod_text_size";token="mod_text_size"};UA.register(H2A);var Y2A=class extends R6{static token="pad_size";token="pad_size"};UA.register(Y2A);var J2A=class extends R6{static token="pad_to_paste_clearance_values";token="pad_to_paste_clearance_values"};UA.register(J2A);var T2A=class extends R6{static token="trace_width";token="trace_width"};UA.register(T2A);var P2A=class extends ume{static token="aux_axis_origin";token="aux_axis_origin"};UA.register(P2A);var K2A=class extends ume{static token="grid_origin";token="grid_origin"};UA.register(K2A);var DB=class extends M6{static parentToken="setup";static parsePrimitiveValue(t){const A=Ci(t);if(A===void 0)throw new Error(`${this.name} expects a numeric value`);return A}},q2A=class extends DB{static token="pad_to_mask_clearance";token="pad_to_mask_clearance"};UA.register(q2A);var O2A=class extends DB{static token="solder_mask_min_width";token="solder_mask_min_width"};UA.register(O2A);var W2A=class extends DB{static token="pad_to_paste_clearance";token="pad_to_paste_clearance"};UA.register(W2A);var Z2A=class extends DB{static token="pad_to_paste_clearance_ratio";token="pad_to_paste_clearance_ratio"};UA.register(Z2A);var V2A=class extends DB{static token="last_trace_width";token="last_trace_width"};UA.register(V2A);var j2A=class extends DB{static token="trace_clearance";token="trace_clearance"};UA.register(j2A);var z2A=class extends DB{static token="zone_clearance";token="zone_clearance"};UA.register(z2A);var X2A=class extends DB{static token="trace_min";token="trace_min"};UA.register(X2A);var $2A=class extends DB{static token="segment_width";token="segment_width"};UA.register($2A);var AxA=class extends DB{static token="edge_width";token="edge_width"};UA.register(AxA);var exA=class extends DB{static token="via_size";token="via_size"};UA.register(exA);var txA=class extends DB{static token="via_drill";token="via_drill"};UA.register(txA);var ixA=class extends DB{static token="via_min_size";token="via_min_size"};UA.register(ixA);var nxA=class extends DB{static token="via_min_drill";token="via_min_drill"};UA.register(nxA);var oxA=class extends DB{static token="uvia_size";token="uvia_size"};UA.register(oxA);var sxA=class extends DB{static token="uvia_drill";token="uvia_drill"};UA.register(sxA);var rxA=class extends DB{static token="uvia_min_size";token="uvia_min_size"};UA.register(rxA);var axA=class extends DB{static token="uvia_min_drill";token="uvia_min_drill"};UA.register(axA);var gxA=class extends DB{static token="pcb_text_width";token="pcb_text_width"};UA.register(gxA);var cxA=class extends DB{static token="mod_edge_width";token="mod_edge_width"};UA.register(cxA);var IxA=class extends DB{static token="mod_text_width";token="mod_text_width"};UA.register(IxA);var lxA=class extends DB{static token="pad_drill";token="pad_drill"};UA.register(lxA);var N6=class extends M6{static parentToken="stackup"},dme=class extends N6{static token="copper_finish";token="copper_finish";quoteStringValue=!0};UA.register(dme);var pme=class extends N6{static token="dielectric_constraints";token="dielectric_constraints"};UA.register(pme);var fme=class extends N6{static token="edge_connector";token="edge_connector"};UA.register(fme);var yme=class extends N6{static token="castellated_pads";token="castellated_pads"};UA.register(yme);var mme=class extends N6{static token="edge_plating";token="edge_plating"};UA.register(mme);var eR=class extends M6{static parentToken="layer"},BxA=class extends eR{static token="type";token="type";quoteStringValue=!0};UA.register(BxA);var CxA=class extends eR{static token="color";token="color";quoteStringValue=!0};UA.register(CxA);var QxA=class extends eR{static token="thickness";token="thickness";static parsePrimitiveValue(t){const A=Ci(t);if(A===void 0)throw new Error("Stackup layer thickness expects a numeric value");return A}};UA.register(QxA);var hxA=class extends eR{static token="material";token="material";quoteStringValue=!0};UA.register(hxA);var ExA=class extends eR{static token="epsilon_r";token="epsilon_r";static parsePrimitiveValue(t){const A=Ci(t);if(A===void 0)throw new Error("Stackup layer epsilon_r expects a numeric value");return A}};UA.register(ExA);var uxA=class extends eR{static token="loss_tangent";token="loss_tangent";static parsePrimitiveValue(t){const A=Ci(t);if(A===void 0)throw new Error("Stackup layer loss_tangent expects a numeric value");return A}};UA.register(uxA);var wme=class o_e extends UA{static token="layer";static parentToken="stackup";token="layer";_name;_number;_sxType;_sxColor;_sxThickness;_sxMaterial;_sxEpsilonR;_sxLossTangent;constructor(A,e={}){super(),this._name=A,this._number=e.number,this._sxType=e.type,this._sxColor=e.color,this._sxThickness=e.thickness,this._sxMaterial=e.material,this._sxEpsilonR=e.epsilonR,this._sxLossTangent=e.lossTangent}static fromSexprPrimitives(A){if(A.length===0)throw new Error("Stackup layer requires at least a name");const e=Di(A[0]);if(e===void 0)throw new Error("Stackup layer name must be a string");let i=1,n;const o=A[i],s=Ci(o);s!==void 0&&(n=s,i+=1);const r=A.slice(i),{propertyMap:a}=UA.parsePrimitivesToClassProperties(r,this.token);return new o_e(e,{number:n,type:a.type,color:a.color,thickness:a.thickness,material:a.material,epsilonR:a.epsilon_r,lossTangent:a.loss_tangent})}get name(){return this._name}set name(A){const e=Di(A);if(e===void 0)throw new Error("Stackup layer name must be a string");this._name=e}get number(){return this._number}set number(A){if(A===void 0){this._number=void 0;return}const e=Ci(A);if(e===void 0)throw new Error("Stackup layer number must be numeric");this._number=e}get type(){return this._sxType?.value}set type(A){if(A===void 0){this._sxType=void 0;return}this._sxType=A instanceof BxA?A:new BxA(A)}get color(){return this._sxColor?.value}set color(A){if(A===void 0){this._sxColor=void 0;return}this._sxColor=A instanceof CxA?A:new CxA(A)}get thickness(){return this._sxThickness?.value}set thickness(A){if(A===void 0){this._sxThickness=void 0;return}this._sxThickness=A instanceof QxA?A:new QxA(A)}get material(){return this._sxMaterial?.value}set material(A){if(A===void 0){this._sxMaterial=void 0;return}this._sxMaterial=A instanceof hxA?A:new hxA(A)}get epsilonR(){return this._sxEpsilonR?.value}set epsilonR(A){if(A===void 0){this._sxEpsilonR=void 0;return}this._sxEpsilonR=A instanceof ExA?A:new ExA(A)}get lossTangent(){return this._sxLossTangent?.value}set lossTangent(A){if(A===void 0){this._sxLossTangent=void 0;return}this._sxLossTangent=A instanceof uxA?A:new uxA(A)}getChildren(){const A=[];return this._sxType&&A.push(this._sxType),this._sxColor&&A.push(this._sxColor),this._sxThickness&&A.push(this._sxThickness),this._sxMaterial&&A.push(this._sxMaterial),this._sxEpsilonR&&A.push(this._sxEpsilonR),this._sxLossTangent&&A.push(this._sxLossTangent),A}getString(){const A=`(layer ${Dn(this._name)}${this._number!==void 0?` ${this._number}`:""}`,e=this.getChildren();if(e.length===0)return`${A})`;const i=[A];for(const n of e)i.push(n.getStringIndented());return i.push(")"),i.join(`
|
|
5828
5828
|
`)}};UA.register(wme);var dxA=class s_e extends UA{static token="stackup";static parentToken="setup";token="stackup";_layers=[];_sxCopperFinish;_sxDielectricConstraints;_sxEdgeConnector;_sxCastellatedPads;_sxEdgePlating;constructor(A={}){super(),this.layers=A.layers??[],this._sxCopperFinish=A.copperFinish,this._sxDielectricConstraints=A.dielectricConstraints,this._sxEdgeConnector=A.edgeConnector,this._sxCastellatedPads=A.castellatedPads,this._sxEdgePlating=A.edgePlating}static fromSexprPrimitives(A){const{propertyMap:e,arrayPropertyMap:i}=UA.parsePrimitivesToClassProperties(A,this.token);return new s_e({layers:i.layer??[],copperFinish:e.copper_finish,dielectricConstraints:e.dielectric_constraints,edgeConnector:e.edge_connector,castellatedPads:e.castellated_pads,edgePlating:e.edge_plating})}get layers(){return[...this._layers]}set layers(A){this._layers=A.map(e=>{if(!(e instanceof wme))throw new Error("Stackup layers must be StackupLayer instances");return e})}get copperFinish(){return this._sxCopperFinish?.value}set copperFinish(A){this._sxCopperFinish=A?new dme(A):void 0}get dielectricConstraints(){return this._sxDielectricConstraints?.value}set dielectricConstraints(A){this._sxDielectricConstraints=A?new pme(A):void 0}get edgeConnector(){return this._sxEdgeConnector?.value}set edgeConnector(A){this._sxEdgeConnector=A?new fme(A):void 0}get castellatedPads(){return this._sxCastellatedPads?.value}set castellatedPads(A){this._sxCastellatedPads=A?new yme(A):void 0}get edgePlating(){return this._sxEdgePlating?.value}set edgePlating(A){this._sxEdgePlating=A?new mme(A):void 0}getChildren(){const A=[...this._layers],e=[this._sxCopperFinish,this._sxDielectricConstraints,this._sxEdgeConnector,this._sxCastellatedPads,this._sxEdgePlating];for(const i of e)i&&A.push(i);return A}};UA.register(dxA);var N0i={stackup:"stackup",pcbplotparams:"pcbPlotParams",pad_to_mask_clearance:"padToMaskClearance",solder_mask_min_width:"solderMaskMinWidth",pad_to_paste_clearance:"padToPasteClearance",pad_to_paste_clearance_ratio:"padToPasteClearanceRatio",last_trace_width:"lastTraceWidth",trace_clearance:"traceClearance",zone_clearance:"zoneClearance",zone_45_only:"zone45Only",trace_min:"traceMin",segment_width:"segmentWidth",edge_width:"edgeWidth",via_size:"viaSize",via_drill:"viaDrill",via_min_size:"viaMinSize",via_min_drill:"viaMinDrill",uvias_allowed:"uviasAllowed",uvia_size:"uviaSize",uvia_drill:"uviaDrill",uvia_min_size:"uviaMinSize",uvia_min_drill:"uviaMinDrill",pcb_text_width:"pcbTextWidth",pcb_text_size:"pcbTextSize",mod_edge_width:"modEdgeWidth",mod_text_size:"modTextSize",mod_text_width:"modTextWidth",pad_size:"padSize",pad_drill:"padDrill",allow_soldermask_bridges_in_footprints:"allowSoldermaskBridgesInFootprints",tenting:"tenting",aux_axis_origin:"auxAxisOrigin",grid_origin:"gridOrigin",visible_elements:"visibleElements",pad_to_paste_clearance_values:"padToPasteClearanceValues",trace_width:"traceWidth"},G0i=["stackup","padToMaskClearance","solderMaskMinWidth","padToPasteClearance","padToPasteClearanceRatio","lastTraceWidth","traceClearance","zoneClearance","zone45Only","traceMin","segmentWidth","edgeWidth","viaSize","viaDrill","viaMinSize","viaMinDrill","uviaSize","uviaDrill","uviasAllowed","uviaMinSize","uviaMinDrill","pcbTextWidth","pcbTextSize","modEdgeWidth","modTextSize","modTextWidth","padSize","padDrill","allowSoldermaskBridgesInFootprints","tenting","auxAxisOrigin","gridOrigin","visibleElements","padToPasteClearanceValues","traceWidth","pcbPlotParams"],pxA=class r_e extends UA{static token="setup";token="setup";_properties={};static fromSexprPrimitives(A){const e=new r_e,{propertyMap:i}=UA.parsePrimitivesToClassProperties(A,this.token);for(const[n,o]of Object.entries(i)){const s=N0i[n];if(!s)throw new Error(`Unsupported setup property token: ${n}`);e._properties[s]=o}return e}getChildren(){const A=[];for(const e of G0i){const i=this._properties[e];i&&A.push(i)}return A}setProperty(A,e){if(e){this._properties[A]=e;return}delete this._properties[A]}setNumberProperty(A,e,i){if(e===void 0){delete this._properties[A];return}this._properties[A]=new i(e)}getPropertyInstance(A,e){const i=this._properties[A];return i instanceof e?i:void 0}get stackup(){return this.getPropertyInstance("stackup",dxA)}set stackup(A){if(A!==void 0&&!(A instanceof dxA))throw new Error("stackup must be a Stackup instance");this.setProperty("stackup",A)}get pcbPlotParams(){return this.getPropertyInstance("pcbPlotParams",F2A)}set pcbPlotParams(A){if(A!==void 0&&!(A instanceof F2A))throw new Error("pcbPlotParams must be a PcbPlotParams instance");this.setProperty("pcbPlotParams",A)}get padToMaskClearance(){return this.getPropertyInstance("padToMaskClearance",q2A)?.value}set padToMaskClearance(A){this.setNumberProperty("padToMaskClearance",A,q2A)}get solderMaskMinWidth(){return this.getPropertyInstance("solderMaskMinWidth",O2A)?.value}set solderMaskMinWidth(A){this.setNumberProperty("solderMaskMinWidth",A,O2A)}get padToPasteClearance(){return this.getPropertyInstance("padToPasteClearance",W2A)?.value}set padToPasteClearance(A){this.setNumberProperty("padToPasteClearance",A,W2A)}get padToPasteClearanceRatio(){return this.getPropertyInstance("padToPasteClearanceRatio",Z2A)?.value}set padToPasteClearanceRatio(A){this.setNumberProperty("padToPasteClearanceRatio",A,Z2A)}get lastTraceWidth(){return this.getPropertyInstance("lastTraceWidth",V2A)?.value}set lastTraceWidth(A){this.setNumberProperty("lastTraceWidth",A,V2A)}get traceClearance(){return this.getPropertyInstance("traceClearance",j2A)?.value}set traceClearance(A){this.setNumberProperty("traceClearance",A,j2A)}get zoneClearance(){return this.getPropertyInstance("zoneClearance",z2A)?.value}set zoneClearance(A){this.setNumberProperty("zoneClearance",A,z2A)}get zone45Only(){return this.getPropertyInstance("zone45Only",M2A)?.value}set zone45Only(A){this.setProperty("zone45Only",A===void 0?void 0:new M2A(A))}get traceMin(){return this.getPropertyInstance("traceMin",X2A)?.value}set traceMin(A){this.setNumberProperty("traceMin",A,X2A)}get segmentWidth(){return this.getPropertyInstance("segmentWidth",$2A)?.value}set segmentWidth(A){this.setNumberProperty("segmentWidth",A,$2A)}get edgeWidth(){return this.getPropertyInstance("edgeWidth",AxA)?.value}set edgeWidth(A){this.setNumberProperty("edgeWidth",A,AxA)}get viaSize(){return this.getPropertyInstance("viaSize",exA)?.value}set viaSize(A){this.setNumberProperty("viaSize",A,exA)}get viaDrill(){return this.getPropertyInstance("viaDrill",txA)?.value}set viaDrill(A){this.setNumberProperty("viaDrill",A,txA)}get viaMinSize(){return this.getPropertyInstance("viaMinSize",ixA)?.value}set viaMinSize(A){this.setNumberProperty("viaMinSize",A,ixA)}get viaMinDrill(){return this.getPropertyInstance("viaMinDrill",nxA)?.value}set viaMinDrill(A){this.setNumberProperty("viaMinDrill",A,nxA)}get uviasAllowed(){return this.getPropertyInstance("uviasAllowed",G2A)?.value}set uviasAllowed(A){this.setProperty("uviasAllowed",A===void 0?void 0:new G2A(A))}get uviaSize(){return this.getPropertyInstance("uviaSize",oxA)?.value}set uviaSize(A){this.setNumberProperty("uviaSize",A,oxA)}get uviaDrill(){return this.getPropertyInstance("uviaDrill",sxA)?.value}set uviaDrill(A){this.setNumberProperty("uviaDrill",A,sxA)}get uviaMinSize(){return this.getPropertyInstance("uviaMinSize",rxA)?.value}set uviaMinSize(A){this.setNumberProperty("uviaMinSize",A,rxA)}get uviaMinDrill(){return this.getPropertyInstance("uviaMinDrill",axA)?.value}set uviaMinDrill(A){this.setNumberProperty("uviaMinDrill",A,axA)}get pcbTextWidth(){return this.getPropertyInstance("pcbTextWidth",gxA)?.value}set pcbTextWidth(A){this.setNumberProperty("pcbTextWidth",A,gxA)}get pcbTextSize(){return this.getPropertyInstance("pcbTextSize",U2A)?.values}set pcbTextSize(A){if(A===void 0){delete this._properties.pcbTextSize;return}this.setProperty("pcbTextSize",new U2A(A))}get modEdgeWidth(){return this.getPropertyInstance("modEdgeWidth",cxA)?.value}set modEdgeWidth(A){this.setNumberProperty("modEdgeWidth",A,cxA)}get modTextSize(){return this.getPropertyInstance("modTextSize",H2A)?.values}set modTextSize(A){if(A===void 0){delete this._properties.modTextSize;return}this.setProperty("modTextSize",new H2A(A))}get modTextWidth(){return this.getPropertyInstance("modTextWidth",IxA)?.value}set modTextWidth(A){this.setNumberProperty("modTextWidth",A,IxA)}get padSize(){return this.getPropertyInstance("padSize",Y2A)?.values}set padSize(A){if(A===void 0){delete this._properties.padSize;return}this.setProperty("padSize",new Y2A(A))}get padDrill(){return this.getPropertyInstance("padDrill",lxA)?.value}set padDrill(A){this.setNumberProperty("padDrill",A,lxA)}get allowSoldermaskBridgesInFootprints(){return this.getPropertyInstance("allowSoldermaskBridgesInFootprints",R2A)?.value}set allowSoldermaskBridgesInFootprints(A){this.setProperty("allowSoldermaskBridgesInFootprints",A===void 0?void 0:new R2A(A))}get tenting(){return this.getPropertyInstance("tenting",L2A)?.sides}set tenting(A){if(A===void 0){delete this._properties.tenting;return}this.setProperty("tenting",new L2A(A))}get auxAxisOrigin(){const A=this.getPropertyInstance("auxAxisOrigin",P2A);if(A)return{x:A.x,y:A.y}}set auxAxisOrigin(A){if(!A){delete this._properties.auxAxisOrigin;return}this.setProperty("auxAxisOrigin",new P2A(A.x,A.y))}get gridOrigin(){const A=this.getPropertyInstance("gridOrigin",K2A);if(A)return{x:A.x,y:A.y}}set gridOrigin(A){if(!A){delete this._properties.gridOrigin;return}this.setProperty("gridOrigin",new K2A(A.x,A.y))}get visibleElements(){return this.getPropertyInstance("visibleElements",N2A)?.value}set visibleElements(A){this.setProperty("visibleElements",A===void 0?void 0:new N2A(A))}get padToPasteClearanceValues(){return this.getPropertyInstance("padToPasteClearanceValues",J2A)?.values}set padToPasteClearanceValues(A){if(A===void 0){delete this._properties.padToPasteClearanceValues;return}this.setProperty("padToPasteClearanceValues",new J2A(A))}get traceWidth(){return this.getPropertyInstance("traceWidth",T2A)?.values}set traceWidth(A){if(A===void 0){delete this._properties.traceWidth;return}this.setProperty("traceWidth",new T2A(A))}};UA.register(pxA);var Dme=class extends Ea{static token="thickness";static parentToken="general";token="thickness"};UA.register(Dme);var xme=class a_e extends UA{static token="legacy_teardrops";static parentToken="general";token="legacy_teardrops";_enabled;constructor(A){super(),this._enabled=A}static fromSexprPrimitives(A){const e=Di(A[0]);if(e===void 0)throw new Error("legacy_teardrops expects a string value");const i=/^(yes|true)$/iu.test(e);return new a_e(i)}get enabled(){return this._enabled}set enabled(A){this._enabled=A}getChildren(){return[]}getString(){return`(legacy_teardrops ${this._enabled?"yes":"no"})`}};UA.register(xme);var Sme=new Set(["thickness","legacy_teardrops"]),fxA=class g_e extends UA{static token="general";static parentToken="kicad_pcb";token="general";_sxThickness;_sxLegacyTeardrops;static fromSexprPrimitives(A){const e=new g_e,{propertyMap:i,arrayPropertyMap:n}=UA.parsePrimitivesToClassProperties(A,this.token);for(const o of Object.keys(i))if(!Sme.has(o))throw new Error(`general encountered unsupported child token "${o}"`);for(const[o,s]of Object.entries(n)){if(!Sme.has(o))throw new Error(`general encountered unsupported child token "${o}"`);if(s.length>1)throw new Error(`general encountered repeated child token "${o}"`)}return e._sxThickness=n.thickness?.[0]??i.thickness,e._sxLegacyTeardrops=n.legacy_teardrops?.[0]??i.legacy_teardrops,e}get thickness(){return this._sxThickness?.value}set thickness(A){this._sxThickness=A===void 0?void 0:new Dme(A)}get legacyTeardrops(){return this._sxLegacyTeardrops?.enabled}set legacyTeardrops(A){if(A===void 0){this._sxLegacyTeardrops=void 0;return}this._sxLegacyTeardrops=new xme(A)}getChildren(){const A=[];return this._sxThickness&&A.push(this._sxThickness),this._sxLegacyTeardrops&&A.push(this._sxLegacyTeardrops),A}};UA.register(fxA);var jl=class c_e extends UA{static token="__pcb_layer_definition__";static parentToken="layers";token="__pcb_layer_definition__";_index;_name;_type;_userName;constructor(A){super(),this._index=A.index,this._name=A.name,this._type=A.type,this._userName=A.userName}static fromPrimitive(A){if(!Array.isArray(A)||A.length<3)throw new Error(`layers entry must be an array with at least index, name, and type: ${JSON.stringify(A)}`);const[e,i,n,o]=A,s=Ci(e),r=Di(i),a=Di(n),g=o===void 0?void 0:Di(o);if(s===void 0||r===void 0||a===void 0)throw new Error(`layers entry is missing required values: ${JSON.stringify(A)}`);return new c_e({index:s,name:r,type:a,userName:g})}get index(){return this._index}set index(A){this._index=A}get name(){return this._name}set name(A){this._name=A}get type(){return this._type}set type(A){this._type=A}get userName(){return this._userName}set userName(A){this._userName=A}getChildren(){return[]}getString(){if(this._index===void 0||this._name===void 0||this._type===void 0)return"()";const A=[String(this._index),Dn(this._name),this._type];return this._userName!==void 0&&A.push(Dn(this._userName)),`(${A.join(" ")})`}};UA.register(jl);var yxA=class I_e extends UA{static token="layers";static parentToken="kicad_pcb";token="layers";_definitions=[];static fromSexprPrimitives(A){const e=new I_e;return e._definitions=A.map(i=>jl.fromPrimitive(i)),e}get definitions(){return[...this._definitions]}set definitions(A){this._definitions=[...A]}getChildren(){return[...this._definitions]}};UA.register(yxA);var Az=class l_e extends UA{static token="net";static parentToken="kicad_pcb";token="net";_id;_name;constructor(A,e){super(),this._id=A,this._name=e}static fromSexprPrimitives(A){const e=Ci(A[0]),i=Di(A[1]);if(e===void 0||i===void 0)throw new Error("net requires numeric id and string name");return new l_e(e,i)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A}getChildren(){return[]}getString(){return`(net ${this._id} ${Dn(this._name)})`}};UA.register(Az);var mxA=class extends Ea{static token="version";static parentToken="kicad_pcb";token="version"};UA.register(mxA);var L0i=t=>/^[A-Za-z0-9._-]+$/.test(t),wxA=class extends Lm{static token="generator";static parentToken="kicad_pcb";token="generator";getString(){return`(generator ${L0i(this.value)?this.value:Dn(this.value)})`}};UA.register(wxA);var U0i=t=>/^[A-Za-z0-9._-]+$/.test(t),DxA=class extends Lm{static token="generator_version";static parentToken="kicad_pcb";token="generator_version";getString(){return`(generator_version ${U0i(this.value)?this.value:Dn(this.value)})`}};UA.register(DxA);var xxA=class B_e extends UA{static token="net";static parentToken="via";token="net";_id;_name;constructor(A,e){super(),this._id=A,this._name=e}static fromSexprPrimitives(A){const e=Ci(A[0]);if(e===void 0)throw new Error("via net requires a numeric id");const i=A.length>1?Di(A[1]):void 0;return new B_e(e,i)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A}getChildren(){return[]}getString(){return this._name!==void 0?`(net ${this._id} ${Dn(this._name)})`:`(net ${this._id})`}};UA.register(xxA);var H0i=new Set(["locked","free","remove_unused_layers","keep_end_layers"]),SxA=class C_e extends UA{static token="via";token="via";_type;_locked=!1;_free=!1;_removeUnusedLayers=!1;_keepEndLayers=!1;_sxAt;_size;_drill;_sxLayers;_sxNet;_sxUuid;_sxTstamp;_sxTeardrops;constructor(A={}){super(),A.type!==void 0&&(this.type=A.type),A.locked!==void 0&&(this.locked=A.locked),A.free!==void 0&&(this.free=A.free),A.removeUnusedLayers!==void 0&&(this.removeUnusedLayers=A.removeUnusedLayers),A.keepEndLayers!==void 0&&(this.keepEndLayers=A.keepEndLayers),A.at!==void 0&&(this.at=A.at),A.size!==void 0&&(this.size=A.size),A.drill!==void 0&&(this.drill=A.drill),A.layers!==void 0&&(this.layers=A.layers),A.net!==void 0&&(this.net=A.net),A.uuid!==void 0&&(this.uuid=A.uuid),A.tstamp!==void 0&&(this.tstamp=A.tstamp),A.teardrops!==void 0&&(this.teardrops=A.teardrops)}static fromSexprPrimitives(A){const e=new C_e;for(const i of A){if(typeof i=="string"){e.consumeBareToken(i);continue}if(!Array.isArray(i)||i.length===0)throw new Error(`via encountered unsupported primitive child: ${JSON.stringify(i)}`);const[n,...o]=i;if(typeof n!="string")throw new Error(`via encountered child with non-string token: ${JSON.stringify(i)}`);e.consumeNode(n,o)}return e}consumeBareToken(A){if(A==="blind"||A==="micro"){this._type=A;return}if(!H0i.has(A))throw new Error(`via encountered unsupported flag "${A}"`);switch(A){case"locked":this._locked=!0;break;case"free":this._free=!0;break;case"remove_unused_layers":this._removeUnusedLayers=!0;break;case"keep_end_layers":this._keepEndLayers=!0;break}}consumeNode(A,e){switch(A){case"type":{const i=Di(e[0]);if(i===void 0)throw new Error("via type expects a string value");this._type=i;return}case"locked":this._locked=this.parseYesNo(e);return;case"free":this._free=this.parseYesNo(e);return;case"remove_unused_layers":this._removeUnusedLayers=this.parseYesNo(e);return;case"keep_end_layers":this._keepEndLayers=this.parseYesNo(e);return;case"at":{const i=UA.parsePrimitiveSexpr(["at",...e],{parentToken:this.token});if(!(i instanceof gc))throw new Error("via failed to parse at child");this._sxAt=i;return}case"size":{const i=Ci(e[0]);if(i===void 0)throw new Error("via size expects a numeric value");this._size=i;return}case"drill":{const i=Ci(e[0]);if(i===void 0)throw new Error("via drill expects a numeric value");this._drill=i;return}case"layers":{this._sxLayers=Xj.fromSexprPrimitives(e);return}case"net":{this._sxNet=xxA.fromSexprPrimitives(e);return}case"teardrops":{this._sxTeardrops=jfe.fromSexprPrimitives(e);return}case"uuid":{const i=Di(e[0]);if(i===void 0)throw new Error("via uuid expects a string value");this._sxUuid=new qi(i);return}case"tstamp":{const i=Di(e[0]);if(i===void 0)throw new Error("via tstamp expects a string value");this._sxTstamp=new cc(i);return}default:throw new Error(`via encountered unsupported child token "${A}"`)}}parseYesNo(A){if(A.length===0)return!0;const e=Di(A[0]);if(e===void 0)throw new Error("Expected string when parsing via boolean child");return/^(yes|true)$/iu.test(e)}get type(){return this._type}set type(A){this._type=A}get locked(){return this._locked}set locked(A){this._locked=A}get free(){return this._free}set free(A){this._free=A}get removeUnusedLayers(){return this._removeUnusedLayers}set removeUnusedLayers(A){this._removeUnusedLayers=A}get keepEndLayers(){return this._keepEndLayers}set keepEndLayers(A){this._keepEndLayers=A}get at(){return this._sxAt}set at(A){this._sxAt=A!==void 0?gc.from(A):void 0}get size(){return this._size}set size(A){this._size=A}get drill(){return this._drill}set drill(A){this._drill=A}get layers(){return this._sxLayers}set layers(A){if(A===void 0){this._sxLayers=void 0;return}this._sxLayers=A instanceof Xj?A:new Xj(A)}get net(){return this._sxNet}set net(A){this._sxNet=A}get uuid(){return this._sxUuid}set uuid(A){if(A===void 0){this._sxUuid=void 0;return}this._sxUuid=A instanceof qi?A:new qi(A)}get teardrops(){return this._sxTeardrops}set teardrops(A){this._sxTeardrops=A}get tstamp(){return this._sxTstamp}set tstamp(A){if(A===void 0){this._sxTstamp=void 0;return}this._sxTstamp=A instanceof cc?A:new cc(A)}getChildren(){const A=[];return this._sxAt&&A.push(this._sxAt),this._sxLayers&&A.push(this._sxLayers),this._sxNet&&A.push(this._sxNet),this._sxUuid&&A.push(this._sxUuid),this._sxTstamp&&A.push(this._sxTstamp),this._sxTeardrops&&A.push(this._sxTeardrops),A}getString(){const A=["(via"];return this._type!==void 0&&A.push(` (type ${this._type})`),this._locked&&A.push(" (locked)"),this._free&&A.push(" (free)"),this._removeUnusedLayers&&A.push(" (remove_unused_layers)"),this._keepEndLayers&&A.push(" (keep_end_layers)"),this._sxAt&&A.push(this._sxAt.getStringIndented()),this._size!==void 0&&A.push(` (size ${this._size})`),this._drill!==void 0&&A.push(` (drill ${this._drill})`),this._sxLayers&&A.push(this._sxLayers.getStringIndented()),this._sxNet&&A.push(this._sxNet.getStringIndented()),this._sxUuid&&A.push(this._sxUuid.getStringIndented()),this._sxTstamp&&A.push(this._sxTstamp.getStringIndented()),this._sxTeardrops&&A.push(this._sxTeardrops.getStringIndented()),A.push(")"),A.join(`
|
|
5829
|
-
`)}};UA.register(SxA);var bxA=class Q_e extends UA{static token="kicad_pcb";token="kicad_pcb";_sxVersion;_sxGenerator;_sxGeneratorVersion;_sxGeneral;_sxPaper;_sxTitleBlock;_sxLayers;_sxSetup;_properties=[];_nets=[];_footprints=[];_images=[];_segments=[];_grLines=[];_grTexts=[];_grPolys=[];_grRects=[];_vias=[];_zones=[];_otherChildren=[];constructor(A={}){super(),A.version!==void 0&&(this.version=A.version),A.generator!==void 0&&(this.generator=A.generator),A.generatorVersion!==void 0&&(this.generatorVersion=A.generatorVersion),A.general!==void 0&&(this.general=A.general),A.paper!==void 0&&(this.paper=A.paper),A.titleBlock!==void 0&&(this.titleBlock=A.titleBlock),A.layers!==void 0&&(this.layers=A.layers),A.setup!==void 0&&(this.setup=A.setup),A.properties!==void 0&&(this.properties=A.properties),A.nets!==void 0&&(this.nets=A.nets),A.footprints!==void 0&&(this.footprints=A.footprints),A.images!==void 0&&(this.images=A.images),A.segments!==void 0&&(this.segments=A.segments),A.graphicLines!==void 0&&(this.graphicLines=A.graphicLines),A.graphicTexts!==void 0&&(this.graphicTexts=A.graphicTexts),A.graphicPolys!==void 0&&(this.graphicPolys=A.graphicPolys),A.graphicRects!==void 0&&(this.graphicRects=A.graphicRects),A.vias!==void 0&&(this.vias=A.vias),A.zones!==void 0&&(this.zones=A.zones),A.otherChildren!==void 0&&(this.otherChildren=A.otherChildren)}static fromSexprPrimitives(A){const e=new Q_e;for(const i of A){if(!Array.isArray(i)||i.length===0)throw new Error(`kicad_pcb encountered unsupported primitive child: ${JSON.stringify(i)}`);const n=UA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(n instanceof UA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);e.consumeChild(n)}return e}consumeChild(A){if(A instanceof mxA){this._sxVersion=A;return}if(A instanceof wxA){this._sxGenerator=A;return}if(A instanceof DxA){this._sxGeneratorVersion=A;return}if(A instanceof fxA){this._sxGeneral=A;return}if(A instanceof Gj){this._sxPaper=A;return}if(A instanceof xpe){this._sxTitleBlock=A;return}if(A instanceof yxA){this._sxLayers=A;return}if(A instanceof pxA){this._sxSetup=A;return}if(A instanceof F1){this._properties.push(A);return}if(A instanceof Az){this._nets.push(A);return}if(A instanceof Zj){this._footprints.push(A);return}if(A instanceof bpe){this._images.push(A);return}if(A instanceof v2A){this._segments.push(A);return}if(A instanceof Vj){this._grLines.push(A);return}if(A instanceof jj){this._grTexts.push(A);return}if(A instanceof Eye){this._grPolys.push(A);return}if(A instanceof Cye){this._grRects.push(A);return}if(A instanceof SxA){this._vias.push(A);return}if(A instanceof mye){this._zones.push(A);return}this._otherChildren.push(A)}get version(){return this._sxVersion?.value}set version(A){this._sxVersion=A===void 0?void 0:new mxA(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new wxA(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new DxA(A)}get general(){return this._sxGeneral}set general(A){this._sxGeneral=A}get paper(){return this._sxPaper}set paper(A){this._sxPaper=A}get titleBlock(){return this._sxTitleBlock}set titleBlock(A){this._sxTitleBlock=A}get layers(){return this._sxLayers}set layers(A){this._sxLayers=A}get setup(){return this._sxSetup}set setup(A){this._sxSetup=A}get properties(){return[...this._properties]}set properties(A){this._properties=[...A]}get nets(){return[...this._nets]}set nets(A){this._nets=[...A]}get footprints(){return[...this._footprints]}set footprints(A){this._footprints=[...A]}get images(){return[...this._images]}set images(A){this._images=[...A]}get segments(){return[...this._segments]}set segments(A){this._segments=[...A]}get graphicLines(){return[...this._grLines]}set graphicLines(A){this._grLines=[...A]}get graphicTexts(){return[...this._grTexts]}set graphicTexts(A){this._grTexts=[...A]}get graphicPolys(){return[...this._grPolys]}set graphicPolys(A){this._grPolys=[...A]}get graphicRects(){return[...this._grRects]}set graphicRects(A){this._grRects=[...A]}get vias(){return[...this._vias]}set vias(A){this._vias=[...A]}get zones(){return[...this._zones]}set zones(A){this._zones=[...A]}get otherChildren(){return[...this._otherChildren]}set otherChildren(A){this._otherChildren=[...A]}getChildren(){const A=[];return this._sxVersion&&A.push(this._sxVersion),this._sxGenerator&&A.push(this._sxGenerator),this._sxGeneratorVersion&&A.push(this._sxGeneratorVersion),this._sxGeneral&&A.push(this._sxGeneral),this._sxPaper&&A.push(this._sxPaper),this._sxTitleBlock&&A.push(this._sxTitleBlock),this._sxLayers&&A.push(this._sxLayers),this._sxSetup&&A.push(this._sxSetup),A.push(...this._properties),A.push(...this._nets),A.push(...this._footprints),A.push(...this._images),A.push(...this._segments),A.push(...this._grLines),A.push(...this._grTexts),A.push(...this._grPolys),A.push(...this._grRects),A.push(...this._vias),A.push(...this._zones),A.push(...this._otherChildren),A}};UA.register(bxA);var bme=t=>UA.parse(t),t0=class{MAX_ITERATIONS=1e3;iteration=0;finished=!1;input;ctx;constructor(t,A){this.input=t,this.ctx=A}step(){if(this.iteration++,this.iteration>this.MAX_ITERATIONS)throw new Error("Max iterations reached");this._step()}_step(){throw new Error("Not implemented")}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){throw new Error("Not implemented")}},Y0i=class extends t0{_step(){const{kicadSch:t,schematicPaperSize:A}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");t.version=20250114;const e=new Gj;e.size=A?.name??"A4",t.paper=e,t.uuid=new qi(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function A5(t,A){if(t.manufacturer_part_number)return _xA(t.manufacturer_part_number);const e=J0i(t.ftype),i=A?.footprinter_string;return _xA(i?`${e}_${i}`:e)}function J0i(t){if(!t)return"component";let A=t.replace(/^simple_/,"");return A||"component"}function _xA(t){return t.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function _me(t){return t?t.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}var kme={simple_resistor:"R",simple_capacitor:"C",simple_inductor:"L",simple_diode:"D",simple_led:"D",simple_chip:"U",simple_transistor:"Q",simple_mosfet:"Q",simple_fuse:"F",simple_switch:"SW",simple_push_button:"SW",simple_potentiometer:"RV",simple_crystal:"Y",simple_resonator:"Y",simple_pin_header:"J",simple_pinout:"J",simple_test_point:"TP",simple_battery:"BT"},T0i=/^[A-Za-z]+\d+$/;function vme(t){return t?T0i.test(t.trim()):!1}function ez(t){const A=t?.ftype;if(A&&kme[A])return kme[A];const e=t?.name;return vme(e),_me(e)}function P0i(t){const A=t?.name;return vme(A)?A.trim():`${ez(t)}?`}function Fme(t){return t in JQ}function Mme(t,A,e,i){if(i)return`Custom:${i}`;if(t.type!=="source_component")return A.symbol_name?Fme(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return Fme(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const n=A5(t,e);return`Device:${ez(t)}_${n}`}function K0i(t){const{circuitJson:A,schematicSymbolId:e,schematicSymbol:i,schematicComponentId:n}=t,o=A.filter(Q=>Q.type==="schematic_circle"&&Q.schematic_symbol_id===e),s=A.filter(Q=>Q.type==="schematic_line"&&Q.schematic_symbol_id===e),r=n?A.filter(Q=>Q.type==="schematic_line"&&Q.schematic_component_id===n&&!Q.schematic_symbol_id):[],a=[...s,...r],g=A.filter(Q=>Q.type==="schematic_path"&&Q.schematic_symbol_id===e),c=A.filter(Q=>Q.type==="schematic_text"&&Q.schematic_symbol_id===e);let I=A.filter(Q=>Q.type==="schematic_port"&&"schematic_symbol_id"in Q&&Q.schematic_symbol_id===e);if(I.length===0&&n){const Q=A.filter(E=>E.type==="schematic_port"&&E.schematic_component_id===n&&E.display_pin_label!==void 0),h=new Map;for(const E of Q)E.display_pin_label&&h.set(E.display_pin_label,E);if(I=h.size>0?Array.from(h.values()):Q,I.length===0){const E=A.filter(d=>d.type==="schematic_port"&&d.schematic_component_id===n),u=new Set;I=E.filter(d=>{const p=d.pin_number;if(p!==void 0){if(u.has(p))return!1;u.add(p)}return!0})}}const l=[];for(const Q of o)l.push({type:"circle",x:Q.center?.x??0,y:Q.center?.y??0,radius:Q.radius??.5,fill:Q.is_filled??!1,fillColor:Q.fill_color});for(const Q of a)l.push({type:"path",points:[{x:Q.x1??0,y:Q.y1??0},{x:Q.x2??0,y:Q.y2??0}]});for(const Q of g)Q.points&&Q.points.length>0&&l.push({type:"path",points:Q.points,fill:Q.is_filled??!1,fillColor:Q.fill_color});const B=c.map(Q=>({text:Q.text??"",x:Q.position?.x??0,y:Q.position?.y??0,fontSize:Q.font_size??.2,anchor:Q.anchor??"center"})),C=I.map((Q,h)=>({x:Q.center?.x??0,y:Q.center?.y??0,labels:[Q.display_pin_label||`${Q.pin_number||h+1}`],pinNumber:Q.pin_number||h+1,facingDirection:Q.facing_direction}));return C.sort((Q,h)=>Q.pinNumber-h.pinNumber),{center:i.center||{x:0,y:0},size:i.size||{width:1,height:1},primitives:l,texts:B,ports:C}}function q0i({points:t,transform:A,fillType:e}){const i=new kpe,n=t.map(a=>{const g=Ce(A,a);return new sh(g.x,g.y)}),o=new sQ(n);i.points=o;const s=new v1;s.width=.254,s.type="default",i.stroke=s;const r=new Lpe;return r.type=e,i.fill=r,i}function O0i({primitive:t,transform:A,scale:e}){const i=new Ype,n=Ce(A,{x:t.x,y:t.y}),o=i;o._sxCenter=new Npe(n.x,n.y),o._sxRadius=new Gpe(t.radius*e);const s=new v1;s.width=.254,s.type="default",o._sxStroke=s;const r=new Upe;return r.type=t.fill?"background":"none",o._sxFill=r,i}function W0i({schText:t,transform:A,scale:e}){const i=new Jpe,n=Ce(A,{x:t.x,y:t.y});i.value=t.text,i.at=[n.x,n.y,0];const o=t.fontSize*e,s=new Zp;return s.size={height:o,width:o},i.effects=new Wp({font:s}),i}function Z0i({libId:t,symbolData:A,isChip:e,c2kMatSchScale:i}){const n=new XM({libraryId:`${t.split(":")[1]}_0_1`}),o=i,s=A.center?.x??0,r=A.center?.y??0,a=An($a(o,o),on(-s,-r));for(const c of A.primitives||[])if(c.type==="path"&&c.points){const I=e||c.fill?"background":"none",l=q0i({points:c.points,transform:a,fillType:I});n.polylines.push(l)}else if(c.type==="circle"){const I=O0i({primitive:c,transform:a,scale:o});n.circles.push(I)}const g=Array.isArray(A.texts)?A.texts:[];for(const c of g){const I=W0i({schText:c,transform:a,scale:o});n.texts.push(I)}return n}function V0i(t,A){const e=A.schematic_port.list().filter(r=>r.schematic_component_id===t.schematic_component_id).sort((r,a)=>(r.pin_number||0)-(a.pin_number||0)),i=t.size?.width||1.5,n=t.size?.height||1,o={type:"path",points:[{x:-i/2,y:-n/2},{x:i/2,y:-n/2},{x:i/2,y:n/2},{x:-i/2,y:n/2},{x:-i/2,y:-n/2}]},s=e.map(r=>{const a=r.center.x-t.center.x,g=r.center.y-t.center.y;return{x:a,y:g,labels:[r.display_pin_label||`${r.pin_number||1}`],pinNumber:r.pin_number||1}});return{center:{x:0,y:0},primitives:[o],ports:s,size:{width:i,height:n}}}function j0i(t,A){const e=new Zp;return e.size={height:t,width:t},new Wp({font:e,hiddenText:A})}function z0i({symbol:t,libId:A,description:e,keywords:i,fpFilters:n,footprintRef:o="",referencePrefix:s}){const r=s||A.split(":")[1]?.[0]||"U",a=[{key:"Reference",value:r,id:0,at:[2.032,0,90],hide:!1},{key:"Value",value:r,id:1,at:[0,0,90],hide:!1},{key:"Footprint",value:o,id:2,at:[-1.778,0,90],hide:!0},{key:"Datasheet",value:"~",id:3,at:[0,0,0],hide:!0},{key:"Description",value:e,id:4,at:[0,0,0],hide:!0},{key:"ki_keywords",value:i,id:5,at:[0,0,0],hide:!0},{key:"ki_fp_filters",value:n,id:6,at:[0,0,0],hide:!0}];for(const g of a)t.properties.push(new Vp({key:g.key,value:g.value,id:g.id,at:g.at,effects:j0i(1.27,g.hide)}))}function X0i({port:t,center:A,size:e,isChip:i,portIndex:n,schematicComponent:o,schematicPorts:s,c2kMatSchScale:r}){const a=r;let g=t.x??0,c=t.y??0,I=!1;if(i&&n!==void 0&&o){const y=s.filter(w=>w.schematic_component_id===o.schematic_component_id).sort((w,D)=>(w.pin_number||0)-(D.pin_number||0));if(y[n]){const w=y[n];g=w.center.x-o.center.x,c=w.center.y-o.center.y,I=!0}}let l,B;if(I)l=g,B=c;else{const y=A?.x??0,w=A?.y??0;l=g-y,B=c-w}const C=$a(a,a),Q=Ce(C,{x:l,y:B});let h;if(i&&e){const y=e.width/2,w=e.height/2,D=Math.abs(l)/y,x=Math.abs(B)/w;h=D>x}else h=Math.abs(l)>Math.abs(B);let E=Q.x,u=Q.y;const d=6;if(i&&e){const y=e.width/2*a,w=e.height/2*a;h?(E=l>0?y:-y,u=B*a):(E=l*a,u=B>0?w:-w)}let p=0;return h?l>0?(p=180,i&&(E=E+d)):(p=0,i&&(E=E-d)):B>0?(p=270,i&&(u=u+d)):(p=90,i&&(u=u-d)),{x:E,y:u,angle:p}}function $0i({libId:t,symbolData:A,isChip:e,schematicComponent:i,schematicPorts:n,c2kMatSchScale:o}){const s=new XM({libraryId:`${t.split(":")[1]}_1_1`}),r=6,a=2.54;for(let g=0;g<(A.ports?.length||0);g++){const c=A.ports[g],I=new Yj;I.pinElectricalType="passive",I.pinGraphicStyle="line";const{x:l,y:B,angle:C}=X0i({port:c,center:A.center,size:A.size,isChip:e,portIndex:g,schematicComponent:i,schematicPorts:n,c2kMatSchScale:o});I.at=[l,B,C],I.length=e?r:a;const Q=new Zp;Q.size={height:1.27,width:1.27};const h=new Wp({font:Q}),E=c.labels?.[0]||"~";I._sxName=new g1A({value:E,effects:h});const u=new Zp;u.size={height:1.27,width:1.27};const d=new Wp({font:u}),p=c.pinNumber?.toString()||`${g+1}`;I._sxNumber=new Ppe({value:p,effects:d}),s.pins.push(I)}return s}var AEi=class extends t0{processedSymbolNames=new Set;_step(){const{kicadSch:t,db:A}=this.ctx,e=new jpe,i=[];this.processedSymbolNames=new Set;const n=A.schematic_component.list();for(const s of n){const r=this.createLibrarySymbolForComponent(s);r&&i.push(r)}const o=A.schematic_net_label?.list?.()||[];for(const s of o)if(s.symbol_name){const r=s.source_net_id?A.source_net.get(s.source_net_id)?.is_power:!1,a=s.source_net_id?A.source_net.get(s.source_net_id)?.is_ground:!1;if(r||a){const c=this.createLibrarySymbolForNetLabel({netLabel:s,isPower:r??!1,isGround:a??!1});c&&i.push(c)}}e.symbols=i,t&&(t.libSymbols=e),this.finished=!0}createLibrarySymbolForComponent(t){const{db:A}=this.ctx,e=t.source_component_id?A.source_component.get(t.source_component_id):null;if(!e)return null;const i=A.cad_component?.list()?.find(c=>c.source_component_id===e.source_component_id);let n=t.schematic_symbol_id;if(!n){const c=this.ctx.circuitJson.find(I=>(I.type==="schematic_line"||I.type==="schematic_circle"||I.type==="schematic_path")&&I.schematic_component_id===t.schematic_component_id&&I.schematic_symbol_id);c&&(n=c.schematic_symbol_id)}if(n)return this.createLibrarySymbolFromSchematicSymbol(t,e,i,n);const o=t.symbol_name||(e.ftype==="simple_chip"?`generic_chip_${t.source_component_id}`:null);if(!o)return null;const s=this.getSymbolData(o,t);if(!s)return null;const r=Mme(e,t,i),a=e.ftype==="simple_chip",g=A5(e,i);return this.createLibrarySymbol({libId:r,symbolData:s,isChip:a,schematicComponent:t,description:this.getDescription(e),keywords:this.getKeywords(e),fpFilters:this.getFpFilters(e),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:ez(e)})}createLibrarySymbolFromSchematicSymbol(t,A,e,i){const{db:n}=this.ctx,o=this.ctx.circuitJson.find(c=>c.type==="schematic_symbol"&&c.schematic_symbol_id===i);if(!o)return null;let s;if(o.name)s=o.name;else{const c=A5(A,e);c?s=c:s=`custom_${A.ftype||"component"}_${i}`}const r=`Custom:${s}`;if(this.processedSymbolNames.has(r))return null;this.processedSymbolNames.add(r);const a=K0i({circuitJson:this.ctx.circuitJson,schematicSymbolId:i,schematicSymbol:o,schematicComponentId:t.schematic_component_id}),g=A5(A,e);return this.createLibrarySymbol({libId:r,symbolData:a,isChip:!1,schematicComponent:t,description:this.getDescription(A),keywords:this.getKeywords(A),fpFilters:this.getFpFilters(A,o.name),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:ez(A),symbolScale:1})}createLibrarySymbolForNetLabel({netLabel:t,isPower:A,isGround:e}){const i=t.symbol_name;if(!i)return null;const n=JQ[i];if(!n)return null;const o=`Custom:${i}`;return this.createLibrarySymbol({libId:o,symbolData:n,isChip:!1,schematicComponent:void 0,description:A?"Power net label":e?"Ground net label":"Net symbol",keywords:A?"power net":e?"ground net":"net",fpFilters:"",referencePrefix:o.split(":")[1]?.[0]||"U"})}getSymbolData(t,A){return t.startsWith("generic_chip_")?V0i(A,this.ctx.db):JQ[t]||null}createLibrarySymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i,description:n,keywords:o,fpFilters:s,footprintRef:r="",referencePrefix:a,symbolScale:g}){const I=g??this.ctx.c2kMatSch?.a??15,l=new XM({libraryId:t,excludeFromSim:!1,inBom:!0,onBoard:!0}),B=new s1A;B.hide=!e,l._sxPinNumbers=B;const C=new a1A;C.offset=e?1.27:0,l._sxPinNames=C,z0i({symbol:l,libId:t,description:n,keywords:o,fpFilters:s,footprintRef:r,referencePrefix:a});const Q=Z0i({libId:t,symbolData:A,isChip:e,c2kMatSchScale:I});l.subSymbols.push(Q);const h=$0i({libId:t,symbolData:A,isChip:e,schematicComponent:i,schematicPorts:this.ctx.db.schematic_port.list(),c2kMatSchScale:I});return l.subSymbols.push(h),l._sxEmbeddedFonts=new jM(!1),l}getDescription(t){return t?.ftype==="simple_resistor"?"Resistor":t?.ftype==="simple_capacitor"?"Capacitor":t?.ftype==="simple_chip"?"Integrated Circuit":"Component"}getKeywords(t){return t?.ftype==="simple_resistor"?"R res resistor":t?.ftype==="simple_capacitor"?"C cap capacitor":t?.ftype==="simple_chip"?"U IC chip":""}getFpFilters(t,A){return A?`${A}*`:t?.ftype==="simple_resistor"?"R_*":t?.ftype==="simple_capacitor"?"C_*":(t?.ftype==="simple_chip","*")}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},eEi=class extends t0{_step(){const{kicadSch:t,db:A}=this.ctx,e=A.schematic_component.list();if(e.length===0){this.finished=!0;return}const i=[];for(const n of e){const o=n.source_component_id?A.source_component.get(n.source_component_id):null;if(!o||!this.ctx.c2kMatSch)continue;const{x:s,y:r}=Ce(this.ctx.c2kMatSch,{x:n.center.x,y:n.center.y}),a=crypto.randomUUID(),g=new XM({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:a,fieldsAutoplaced:!0}),c=A.cad_component?.list()?.find(iA=>iA.source_component_id===o.source_component_id);let I,l=n.schematic_symbol_id;if(!l){const iA=this.ctx.circuitJson.find(sA=>(sA.type==="schematic_line"||sA.type==="schematic_circle"||sA.type==="schematic_path")&&sA.schematic_component_id===n.schematic_component_id&&sA.schematic_symbol_id);iA&&(l=iA.schematic_symbol_id)}if(l){const iA=this.ctx.circuitJson.find(sA=>sA.type==="schematic_symbol"&&sA.schematic_symbol_id===l);if(iA?.name)I=iA.name;else{const sA=A5(o,c);sA?I=sA:I=`custom_${o.ftype||"component"}_${l}`}}const B=Mme(o,n,c,I),C=new n1A(B);g._sxLibId=C;const{reference:Q,value:h,description:E}=this.getComponentMetadata(o),{refTextPos:u,valTextPos:d}=this.getTextPositions(n,{x:s,y:r});let p;if(l){const iA=this.ctx.circuitJson.find(sA=>sA.type==="schematic_symbol"&&sA.schematic_symbol_id===l);iA&&iA.type==="schematic_symbol"&&(p=iA.metadata?.kicad_symbol)}const y=p?.properties?.Reference,w=new Vp({key:"Reference",value:y?.value??Q,id:0,at:[u.x,u.y,0],effects:this.createTextEffects(Number(y?.effects?.font?.size?.x??1.27),y?.effects?.hide??!1)}),D=o.ftype==="simple_chip",x=p?.properties?.Value,_=new Vp({key:"Value",value:x?.value??h,id:1,at:[d.x,d.y,0],effects:this.createTextEffects(Number(x?.effects?.font?.size?.x??1.27),x?.effects?.hide??D)}),S=p?.properties?.Footprint,N=new Vp({key:"Footprint",value:S?.value??"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,S?.effects?.hide??!0)}),F=p?.properties?.Datasheet,L=new Vp({key:"Datasheet",value:F?.value??"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,F?.effects?.hide??!0)}),Y=p?.properties?.Description,J=new Vp({key:"Description",value:Y?.value??E,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,Y?.effects?.hide??!0)});g.properties.push(w,_,N,L,J);const q=p?.properties?.ki_keywords;if(q?.value){const iA=new Vp({key:"ki_keywords",value:q.value,id:5,at:[s,r,0],effects:this.createTextEffects(1.27,q.effects?.hide??!0)});g.properties.push(iA)}const Z=p?.properties?.ki_fp_filters;if(Z?.value){const iA=new Vp({key:"ki_fp_filters",value:Z.value,id:6,at:[s,r,0],effects:this.createTextEffects(1.27,Z.effects?.hide??!0)});g.properties.push(iA)}if(p){if(p.inBom!==void 0&&(g.inBom=p.inBom),p.onBoard!==void 0&&(g.onBoard=p.onBoard),p.excludeFromSim!==void 0&&(g.excludeFromSim=p.excludeFromSim),p.pinNames){const iA=new a1A;p.pinNames.offset!==void 0&&(iA.offset=Number(p.pinNames.offset)),p.pinNames.hide!==void 0&&(iA.hide=p.pinNames.hide),g.pinNames=iA}if(p.pinNumbers){const iA=new s1A;p.pinNumbers.hide!==void 0&&(iA.hide=p.pinNumbers.hide),g.pinNumbers=iA}p.embeddedFonts!==void 0&&(g._sxEmbeddedFonts=new jM(p.embeddedFonts))}let X=A.schematic_port.list().filter(iA=>iA.schematic_component_id===n.schematic_component_id);if(l){const iA=X.filter(sA=>sA.display_pin_label);iA.length>0&&(X=iA)}X.sort((iA,sA)=>(iA.pin_number||0)-(sA.pin_number||0));for(let iA=0;iA<X.length;iA++){const sA=X[iA];if(!sA)continue;const aA=new Yj;aA.numberString=`${sA.pin_number||iA+1}`,aA.uuid=crypto.randomUUID(),g.pins.push(aA)}const eA=new c1A,gA=new l1A(""),tA=new B1A(`/${t?.uuid?.value||""}`);tA.reference=Q,tA.unit=1,gA.paths.push(tA),eA.projects.push(gA),g._sxInstances=eA,i.push(g)}t&&(t.symbols=i),this.finished=!0}getTextPositions(t,A){const i=(this.ctx.db.schematic_text?.list?.()?.filter(B=>B.schematic_component_id===t.schematic_component_id)||[]).find(B=>B.text&&B.text.length>0);if(i&&this.ctx.c2kMatSch){const B=Ce(this.ctx.c2kMatSch,{x:i.position.x,y:i.position.y}),C={x:A.x,y:A.y+6};return{refTextPos:B,valTextPos:C}}const n=t.symbol_name,o=JQ[n];if(!o)return{refTextPos:{x:A.x,y:A.y-6},valTextPos:{x:A.x,y:A.y+6}};let s=null,r=null;for(const B of o.primitives)B.type==="text"&&(B.text==="{REF}"?s=B:B.text==="{VAL}"&&(r=B));const a=o.center||{x:0,y:0},c=n.includes("_down")||n.includes("_up")?.15:0,I=s&&this.ctx.c2kMatSch?Ce(this.ctx.c2kMatSch,{x:t.center.x+(s.x-a.x)+c,y:t.center.y+(s.y-a.y)}):{x:A.x,y:A.y-6},l=r&&this.ctx.c2kMatSch?Ce(this.ctx.c2kMatSch,{x:t.center.x+(r.x-a.x)+c,y:t.center.y+(r.y-a.y)}):{x:A.x,y:A.y+6};return{refTextPos:I,valTextPos:l}}getComponentMetadata(t){const A=t.name||"?",e=P0i(t);return t.ftype==="simple_resistor"?{reference:e,value:t.display_resistance||"R",description:"Resistor"}:t.ftype==="simple_capacitor"?{reference:e,value:t.display_capacitance||"C",description:"Capacitor"}:t.ftype==="simple_inductor"?{reference:e,value:t.display_inductance||"L",description:"Inductor"}:t.ftype==="simple_diode"?{reference:e,value:"D",description:"Diode"}:t.ftype==="simple_chip"?{reference:e,value:A,description:"Integrated Circuit"}:t.ftype==="simple_led"?{reference:e,value:t.manufacturer_part_number||"",description:"LED"}:t.ftype==="simple_switch"?{reference:e,value:t.manufacturer_part_number||"",description:"Switch"}:t.ftype==="simple_potentiometer"?{reference:e,value:t.display_max_resistance||"",description:"Potentiometer"}:{reference:e,value:A,description:"Component"}}createTextEffects(t,A=!1,e){const i=new Zp;i.size={height:t,width:t};const n=e?new b6({horizontal:e}):void 0;return new Wp({font:i,hiddenText:A,justify:n})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},tEi=class extends t0{_step(){const{kicadSch:t,db:A}=this.ctx,e=A.schematic_net_label?.list?.()||[];if(e.length===0){this.finished=!0;return}if(!this.ctx.c2kMatSch){this.finished=!0;return}const i=[],n=[];for(const o of e){const s=o.text||"",r=o.symbol_name;if(r){const a=this.createSymbolFromNetLabel(o,s,r);a&&i.push(a)}else{const a=this.createGlobalLabel(o,s);a&&n.push(a)}}if(t&&i.length>0){const o=t.symbols||[];t.symbols=[...o,...i]}t&&n.length>0&&(t.globalLabels=[...t.globalLabels||[],...n]),this.finished=!0}createSymbolFromNetLabel(t,A,e){if(!this.ctx.c2kMatSch)return null;const{x:i,y:n}=Ce(this.ctx.c2kMatSch,{x:t.anchor_position?.x??t.center?.x??0,y:t.anchor_position?.y??t.center?.y??0}),o=crypto.randomUUID(),s=new XM({at:[i,n,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:o,fieldsAutoplaced:!0}),r=`Custom:${e}`,a=new n1A(r);s._sxLibId=a;const g=e.includes("_up")||e.toLowerCase().includes("vcc"),c=g?-4:4,I=g?-6:6,l=new Vp({key:"Reference",value:A,id:0,at:[i,n+c,0],effects:this.createTextEffects(1.27,!1)}),B=new Vp({key:"Value",value:A,id:1,at:[i,n+I,0],effects:this.createTextEffects(1.27,!0)}),C=new Vp({key:"Footprint",value:"",id:2,at:[i-1.778,n,90],effects:this.createTextEffects(1.27,!0)}),Q=new Vp({key:"Datasheet",value:"~",id:3,at:[i,n,0],effects:this.createTextEffects(1.27,!0)}),h=new Vp({key:"Description",value:`Power/Net symbol: ${A}`,id:4,at:[i,n,0],effects:this.createTextEffects(1.27,!0)});s.properties.push(l,B,C,Q,h);const E=new Yj;E.numberString="1",E.uuid=crypto.randomUUID(),s.pins.push(E);const{kicadSch:u}=this.ctx,d=new c1A,p=new l1A(""),y=new B1A(`/${u?.uuid?.value||""}`);return y.reference=A,y.unit=1,p.paths.push(y),d.projects.push(p),s._sxInstances=d,s}createGlobalLabel(t,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:e,y:i}=Ce(this.ctx.c2kMatSch,{x:t.anchor_position?.x??t.center?.x??0,y:t.anchor_position?.y??t.center?.y??0}),n=t.anchor_side||"left",s={left:0,right:180,top:270,bottom:90}[n]||0,a={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[n]||{},g=this.createTextEffects(1.27,!1);return Object.keys(a).length>0&&(g.justify=new b6(a)),new ofe({value:A,at:[e,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(t,A=!1){const e=new Zp;return e.size={height:t,width:t},new Wp({font:e,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},iEi=class extends t0{_step(){const{kicadSch:t,db:A}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");const e=A.schematic_trace.list();if(e.length===0){this.finished=!0;return}const i=[],n=[];for(const o of e){for(const s of o.edges){const r=this.createWireFromEdge(s);i.push(r)}for(const s of o.junctions){const r=this.createJunction(s);n.push(r)}}t.wires=i,t.junctions=n,this.finished=!0}createWireFromEdge(t){const A=new Xpe;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const e=Ce(this.ctx.c2kMatSch,{x:t.from.x,y:t.from.y}),i=Ce(this.ctx.c2kMatSch,{x:t.to.x,y:t.to.y}),n=e.x,o=e.y,s=i.x,r=i.y,a=new sQ([new sh(n,o),new sh(s,r)]);A.points=a;const g=new v1;return g.width=0,g.type="default",A.stroke=g,A.uuid=crypto.randomUUID(),A}createJunction(t){if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const{x:A,y:e}=Ce(this.ctx.c2kMatSch,{x:t.x,y:t.y}),i=new $pe({at:[A,e],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},nEi=class extends t0{_step(){const{kicadSch:t}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");const A=new E1A,e=new afe;e.value="/";const i=new gfe("1");e.pages=[i],A.paths=[e],t.sheetInstances=A,t.embeddedFonts=new jM(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function oEi(t){const A=t.schematic_component.list(),e=t.schematic_trace.list();let i=1/0,n=1/0,o=-1/0,s=-1/0;for(const g of A){const c=g.size?.width??0,I=g.size?.height??0;i=Math.min(i,g.center.x-c/2),n=Math.min(n,g.center.y-I/2),o=Math.max(o,g.center.x+c/2),s=Math.max(s,g.center.y+I/2)}for(const g of e)for(const c of g.edges)i=Math.min(i,c.from.x,c.to.x),n=Math.min(n,c.from.y,c.to.y),o=Math.max(o,c.from.x,c.to.x),s=Math.max(s,c.from.y,c.to.y);i===1/0&&(i=0,n=0,o=0,s=0);const r=(i+o)/2,a=(n+s)/2;return{center:{x:r,y:a},bounds:{minX:i,minY:n,maxX:o,maxY:s}}}var tz=[{name:"A4",width:297,height:210},{name:"A3",width:420,height:297},{name:"A2",width:594,height:420},{name:"A1",width:841,height:594},{name:"A0",width:1189,height:841}];function sEi(t,A,e=20){const i=t+2*e,n=A+2*e;for(let o=0;o<tz.length;o++){const s=tz[o];if(i<=s.width&&n<=s.height)return s}return tz[tz.length-1]}var Rme=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(t){const e=Ua(t),{center:i,bounds:n}=oEi(e),o=(n.maxX-n.minX)*15,s=(n.maxY-n.minY)*15,r=sEi(o,s),a=r.width/2,g=r.height/2;this.ctx={db:e,circuitJson:t,kicadSch:new d1A({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:r,c2kMatSch:An(on(a,g),$a(15,-15),on(-i.x,-i.y))},this.pipeline=[new Y0i(t,this.ctx),new AEi(t,this.ctx),new eEi(t,this.ctx),new tEi(t,this.ctx),new iEi(t,this.ctx),new nEi(t,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadSch}getOutputString(){return this.ctx.kicadSch.getString()}},rEi=class extends t0{_step(){const{kicadPcb:t,db:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");const i=A.pcb_board?.list()?.[0]?.num_layers??2;this.ctx.numLayers=i,t.version=20241229;const n=new Gj;n.size="A4",t.paper=n;const o=new fxA;o.thickness=1.6,t.general=o;const s=new pxA;s.padToMaskClearance=0,t.setup=s;const r=new yxA,a=[new jl({index:0,name:"F.Cu",type:"signal"})];for(let g=1;g<i-1;g++)a.push(new jl({index:g,name:`In${g}.Cu`,type:"signal"}));a.push(new jl({index:31,name:"B.Cu",type:"signal"})),a.push(new jl({index:32,name:"B.Adhes",type:"user"}),new jl({index:33,name:"F.Adhes",type:"user"}),new jl({index:34,name:"B.Paste",type:"user"}),new jl({index:35,name:"F.Paste",type:"user"}),new jl({index:36,name:"B.SilkS",type:"user"}),new jl({index:37,name:"F.SilkS",type:"user"}),new jl({index:38,name:"B.Mask",type:"user"}),new jl({index:39,name:"F.Mask",type:"user"}),new jl({index:40,name:"Dwgs.User",type:"user"}),new jl({index:41,name:"Cmts.User",type:"user"}),new jl({index:42,name:"Eco1.User",type:"user"}),new jl({index:43,name:"Eco2.User",type:"user"}),new jl({index:44,name:"Edge.Cuts",type:"user"}),new jl({index:45,name:"Margin",type:"user"}),new jl({index:46,name:"B.CrtYd",type:"user"}),new jl({index:47,name:"F.CrtYd",type:"user"}),new jl({index:48,name:"B.Fab",type:"user"}),new jl({index:49,name:"F.Fab",type:"user"})),r.definitions=a,t.layers=r,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},aEi=class extends t0{_step(){const{kicadPcb:t}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");this.ctx.pcbNetMap=new Map;const A=new Map,e=this.ctx.db.source_net?.list()??[];for(const r of e){const a=r.subcircuit_connectivity_map_key||r.source_net_id;if(!a)continue;const g=r.name||r.source_net_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}const i=this.ctx.db.source_trace?.list()??[];for(const r of i){let a=r.subcircuit_connectivity_map_key;if(!a&&r.connected_source_net_ids?.length)for(const g of r.connected_source_net_ids){const c=this.ctx.db.source_net?.get(g);if(c?.subcircuit_connectivity_map_key&&c.subcircuit_connectivity_map_key.length>0){a=c.subcircuit_connectivity_map_key;break}}if(a&&!A.has(a)){const g=r.display_name||r.source_trace_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}}const n=Array.from(A.entries()).sort((r,a)=>r[0].localeCompare(a[0])),o=[];o.push(new Az(0,""));let s=1;for(const[r,a]of n){const g=new Az(s,a);o.push(g);const c={id:s,name:a};this.ctx.pcbNetMap.set(r,c),s++}t.nets=o,this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function gEi(t){let A=0;for(let i=0;i<t.length;i++){const n=t.charCodeAt(i);A=(A<<5)-A+n,A=A&A}let e="";for(let i=0;i<4;i++){let n=A;for(let o=0;o<t.length;o++)n=(n<<5)-n+t.charCodeAt(o)+i*31,n=n&n;e+=Math.abs(n).toString(16).padStart(8,"0")}return e}function Bd(t){const A=gEi(t);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}var Nme="https://modelcdn.tscircuit.com/jscad_models",cEi=20240108,IEi="pcbnew",lEi="8.0";function kxA(t){const A=t.split(/[/\\]/),e=A[A.length-1]||t;return e.split("?")[0]||e}var BEi=class extends t0{classifyFootprints(){const t=new Set,A=new Map,e=this.ctx.db.cad_component?.list()??[],i=this.ctx.db.source_component;for(const n of e){const o=n.source_component_id?i?.get(n.source_component_id):null;if(!o)continue;const s=A5(o,n);if(n.footprinter_string)A.set(s,n.footprinter_string);else{t.add(s);const r=this.ctx.circuitJson.find(a=>a.type==="pcb_component"&&a.source_component_id===n.source_component_id);r&&r.type==="pcb_component"&&r.metadata?.kicad_footprint?.footprintName&&t.add(r.metadata.kicad_footprint.footprintName)}}return{customFootprintNames:t,footprinterStrings:A}}_step(){const t=this.ctx.kicadPcbString,A=this.ctx.fpLibraryName??"tscircuit";if(!t)throw new Error("PCB content not available. Run GenerateKicadSchAndPcbStage first.");const{customFootprintNames:e,footprinterStrings:i}=this.classifyFootprints(),n=new Map;try{const s=bme(t).find(a=>a instanceof bxA);if(!s){this.ctx.footprintEntries=[],this.finished=!0;return}const r=s.footprints??[];for(const a of r){const g=this.sanitizeFootprint({footprint:a,fpLibraryName:A,customFootprintNames:e,footprinterStrings:i});n.has(g.footprintName)||n.set(g.footprintName,g)}}catch(o){console.warn("Failed to parse PCB for footprint extraction:",o)}this.ctx.footprintEntries=Array.from(n.values()),this.finished=!0}sanitizeFootprint({footprint:t,fpLibraryName:A,customFootprintNames:e,footprinterStrings:i}){const o=(t.libraryLink??"footprint").split(":"),s=(o.length>1?o[1]:o[0])?.replace(/[\\\/]/g,"-").trim()||"footprint",r=!e.has(s);if(t.libraryLink=s,t.position=gc.from([0,0,0]),t.locked=!1,t.placed=!1,t.version=cEi,t.generator=IEi,t.generatorVersion=lEi,t.descr||(t.descr=""),t.tags||(t.tags=""),t.embeddedFonts||(t.embeddedFonts=new jM(!1)),!t.attr){const p=new p1A,y=(t.fpPads??[]).map(w=>w.padType);y.some(w=>w.includes("thru_hole"))?p.type="through_hole":y.some(w=>w.includes("smd"))&&(p.type="smd"),t.attr=p}t.uuid=void 0,t.path=void 0,t.sheetfile=void 0,t.sheetname=void 0;const a=new Zp;a.size={width:1.27,height:1.27},a.thickness=.15;const g=new Wp({font:a}),c=t.fpPads??[];let I=0,l=0;for(const p of c){const y=p.at,w=p.size;if(y&&w){const D=y.y??0,x=w.height??0,_=D-x/2,S=D+x/2;I=Math.min(I,_),l=Math.max(l,S)}}const B=I-.5,C=l+.5;t.properties=[new F1({key:"Reference",value:"REF**",position:[0,B,0],layer:"F.SilkS",uuid:Bd(`${s}-property-Reference`),effects:g}),new F1({key:"Value",value:"Val**",position:[0,C,0],layer:"F.Fab",uuid:Bd(`${s}-property-Value`),effects:g}),new F1({key:"Datasheet",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:Bd(`${s}-property-Datasheet`),effects:g}),new F1({key:"Description",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:Bd(`${s}-property-Description`),effects:g})];const Q=t.fpTexts??[];for(const p of Q)p.uuid=void 0,p.type==="reference"?p.text="REF**":p.type==="value"&&p.text.trim().length===0&&(p.text=s);t.fpTexts=Q;const h=t.fpPads??[];for(let p=0;p<h.length;p++){const y=h[p];y&&(y.uuid=Bd(`${s}-pad-${y.number??p}`),y.net=void 0)}t.fpPads=h;const E=t.models??[],u=[],d=[];for(const p of E)if(p.path){const y=kxA(p.path),x=`../../3dmodels/${p.path.startsWith("http://modelcdn.tscircuit.com")||p.path.startsWith("https://modelcdn.tscircuit.com")?"tscircuit_builtin":A}.3dshapes/${y}`,_=new $3(x);p.offset&&(_.offset=p.offset),p.scale&&(_.scale=p.scale),p.rotate&&(_.rotate=p.rotate),u.push(_),d.push(p.path.split("?")[0]??p.path)}if(u.length===0){const p=i.get(s);if(p){const y=`${Nme}/${p}.step`,D=`../../3dmodels/tscircuit_builtin.3dshapes/${kxA(y)}`;u.push(new $3(D)),d.push(y)}}return t.models=u,{footprintName:s,kicadModString:t.getString(),model3dSourcePaths:d,isBuiltin:r}}getOutput(){return this.ctx.libraryOutput}};function iz(t){const A=new Zp;return t?.font?.size?A.size={width:Number(t.font.size.x),height:Number(t.font.size.y)}:A.size={width:1.27,height:1.27},t?.font?.thickness!==void 0?A.thickness=Number(t.font.thickness):A.thickness=.15,new Wp({font:A})}function CEi(t,A,e){if(A.properties){const i=[],n=A.properties.Reference;i.push(new F1({key:"Reference",value:n?.value??e,position:n?.at?[Number(n.at.x),Number(n.at.y),Number(n.at.rotation??0)]:[0,-3,0],layer:n?.layer??"F.SilkS",uuid:Bd(`${e}-property-Reference`),effects:iz(n?.effects),hidden:n?.hide}));const o=A.properties.Value,s=o?.value??A.footprintName??"";i.push(new F1({key:"Value",value:s,position:o?.at?[Number(o.at.x),Number(o.at.y),Number(o.at.rotation??0)]:[0,3,0],layer:o?.layer??"F.Fab",uuid:Bd(`${e}-property-Value`),effects:iz(o?.effects),hidden:o?.hide}));const r=A.properties.Datasheet;i.push(new F1({key:"Datasheet",value:r?.value??"",position:r?.at?[Number(r.at.x),Number(r.at.y),Number(r.at.rotation??0)]:[0,0,0],layer:r?.layer??"F.Fab",uuid:Bd(`${e}-property-Datasheet`),effects:iz(r?.effects),hidden:r?.hide??!0}));const a=A.properties.Description;i.push(new F1({key:"Description",value:a?.value??"",position:a?.at?[Number(a.at.x),Number(a.at.y),Number(a.at.rotation??0)]:[0,0,0],layer:a?.layer??"F.Fab",uuid:Bd(`${e}-property-Description`),effects:iz(a?.effects),hidden:a?.hide??!0})),t.properties=i}if(A.attributes&&(t.attr||(t.attr=new p1A),A.attributes.through_hole?t.attr.type="through_hole":A.attributes.smd&&(t.attr.type="smd"),A.attributes.exclude_from_pos_files!==void 0&&(t.attr.excludeFromPosFiles=A.attributes.exclude_from_pos_files),A.attributes.exclude_from_bom!==void 0&&(t.attr.excludeFromBom=A.attributes.exclude_from_bom)),A.footprintName&&(t.libraryLink=A.footprintName),A.layer&&(t.layer=A.layer),A.embeddedFonts!==void 0&&(t.embeddedFonts=new jM(A.embeddedFonts)),A.model){const i=new $3(A.model.path);A.model.offset&&(i.offset={x:Number(A.model.offset.x),y:Number(A.model.offset.y),z:Number(A.model.offset.z)}),A.model.scale&&(i.scale={x:Number(A.model.scale.x),y:Number(A.model.scale.y),z:Number(A.model.scale.z)}),A.model.rotate&&(i.rotate={x:Number(A.model.rotate.x),y:Number(A.model.rotate.y),z:Number(A.model.rotate.z)});const n=t.models||[];t.models=[i,...n]}}function QEi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.SilkS",bottom:"B.SilkS"}[i.layer]||i.layer||"F.SilkS",a=new i2A({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new v1,fill:!1});a.stroke&&(a.stroke.width=i.stroke_width||.05,a.stroke.type="default"),e.push(a)}return e}function hEi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",a=new i2A({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new v1,fill:!1});a.stroke&&(a.stroke.width=.05,a.stroke.type="default"),e.push(a)}return e}function EEi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.Fab",bottom:"B.Fab"}[i.layer]||i.layer||"F.Fab",c=new Kj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new v1,fill:!1});c.stroke&&(c.stroke.width=i.stroke_width||.1,c.stroke.type="default"),e.push(c)}return e}function uEi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,a="F.Fab",g=new Kj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:a,stroke:new v1,fill:!1});g.stroke&&(g.stroke.width=i.stroke_width||.1,g.stroke.type="default"),e.push(g)}return e}function dEi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",c=new Kj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new v1,fill:!1});c.stroke&&(c.stroke.width=.05,c.stroke.type="default"),e.push(c)}return e}function pEi(t,A){const e=[];for(const i of t){if(!i.outline||i.outline.length<2)continue;const o={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",s=i.outline.map(g=>{const c=g.x-A.x,I=-(g.y-A.y);return new sh(c,I)}),r=new eye;r.points=new sQ(s),r.layer=o,r.fill=!1;const a=new v1;a.width=.05,a.type="default",r.stroke=a,e.push(r)}return e}function fEi({textElement:t,componentCenter:A,componentRotation:e=0}){if(!t.text||!t.anchor_position)return null;const i=t.anchor_position.x-A.x,n=-(t.anchor_position.y-A.y),o=e!==0?Tl(e*Math.PI/180):ba(),s=Ce(o,{x:i,y:n}),r={x:s.x,y:s.y},g={top:"F.SilkS",bottom:"B.SilkS"}[t.layer]||t.layer||"F.SilkS",c=(t.font_size||1)/1.5,I=new Zp;I.size={width:c,height:c};const l=new Wp({font:I}),B=t.ccw_rotation||0;return new W1A({type:"user",text:t.text,position:{x:r.x,y:r.y,angle:B},layer:g,effects:l})}function yEi(t,A,e,i){const n=[];for(const o of t){const s=fEi({textElement:o,componentCenter:A,componentRotation:e});s&&(i&&o.text===i&&(s.type="reference"),n.push(s))}return n}function mEi(t,A,e){const i=[];for(const n of t){const o=n.anchor_position.x-A.x,s=-(n.anchor_position.y-A.y),r=e!==0?Tl(e*Math.PI/180):ba(),a=Ce(r,{x:o,y:s}),g=n.font_size||1,c=new Zp;c.size={width:g,height:g};const I=new Wp({font:c}),l=new W1A({type:"user",text:n.text,position:{x:a.x,y:a.y,angle:0},layer:"F.Fab",effects:I});i.push(l)}return i}function wEi(t,A,e){const i=[],n=t.model_step_url||t.model_wrl_url;if(!n)return i;const o=new $3(n);if(t.position){const s=e?.boardLayerZOffset??0;o.offset={x:(t.position.x||0)-A.x,y:-((t.position.y||0)-A.y),z:(t.position.z||0)-s}}if(t.rotation&&(o.rotate={x:t.rotation.x||0,y:t.rotation.y||0,z:t.rotation.z||0}),t.model_unit_to_mm_scale_factor){const s=t.model_unit_to_mm_scale_factor;o.scale={x:s,y:s,z:s}}return i.push(o),i}function DEi({pcbPad:t,componentCenter:A,padNumber:e,componentRotation:i=0,netInfo:n,componentId:o}){let s,r;if("x"in t&&"y"in t)s=t.x,r=t.y;else if("points"in t&&Array.isArray(t.points)){const u=t.points;s=u.reduce((d,p)=>d+p.x,0)/u.length,r=u.reduce((d,p)=>d+p.y,0)/u.length}else throw new Error("Pad must have either x/y coordinates or points array");const a=An(i!==0?Tl(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},$a(1,-1),on(-A.x,-A.y)),g=Ce(a,{x:s,y:r}),I={top:"F.Cu",bottom:"B.Cu"}[t.layer]||"F.Cu";let l,B,C,Q;if(t.shape==="circle")l="circle",B=["radius"in t?t.radius*2:.5,"radius"in t?t.radius*2:.5];else if(t.shape==="polygon"&&"points"in t){const u=t.points,d=An($a(1,-1),on(-s,-r)),p=u.map(w=>{const D=Ce(d,{x:w.x,y:w.y});return new sh(D.x,D.y)}),y=new T1A;y.contours=[new sQ(p)],y.width=0,y.filled=!0,Q=new Ufe,Q.addGraphic(y),l="custom",C=new ffe,C.anchor="circle",B=[.2,.2]}else l="rect",B=["width"in t?t.width:.5,"height"in t?t.height:.5];const h=`pad:${o}:${e}:${g.x},${g.y}`,E=new Pj({number:String(e),padType:"smd",shape:l,at:[g.x,g.y,0],size:B,layers:[`${I}`,`${I==="F.Cu"?"F":"B"}.Paste`,`${I==="F.Cu"?"F":"B"}.Mask`],uuid:Bd(h)});return C&&(E.options=C),Q&&(E.primitives=Q),n&&(E.net=new G1A(n.id,n.name)),E}function xEi(t,A,e,i,n,o){const s=[];let r=n;for(const a of t){const g=o(a.pcb_port_id),c=DEi({pcbPad:a,componentCenter:A,padNumber:r,componentRotation:e,netInfo:g,componentId:i});s.push(c),r++}return{pads:s,nextPadNumber:r}}function SEi({platedHole:t,componentCenter:A,padNumber:e,componentRotation:i=0,netInfo:n,componentId:o}){if(!("x"in t&&"y"in t))return null;const s=t.x-A.x,r=-(t.y-A.y),a=i!==0?Tl(i*Math.PI/180):ba(),g=Ce(a,{x:s,y:r});let c="circle",I,l,B=0;const C="hole_offset_x"in t||"hole_offset_y"in t;let Q;if(C){const u={x:t.hole_offset_x??0,y:t.hole_offset_y??0};(u.x!==0||u.y!==0)&&(Q=Ce(a,{x:-u.x,y:u.y}))}t.shape==="circle"?(c="circle",I=[t.outer_diameter,t.outer_diameter],l=new M1({diameter:t.hole_diameter,offset:Q})):t.shape==="pill"||t.shape==="oval"?(c="oval",I=[t.outer_width,t.outer_height],l=new M1({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q})):t.shape==="pill_hole_with_rect_pad"?(c="rect",I=[t.rect_pad_width,t.rect_pad_height],l=new M1({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q})):t.shape==="circular_hole_with_rect_pad"?(c="rect",I=[t.rect_pad_width,t.rect_pad_height],l=new M1({diameter:t.hole_diameter,offset:Q})):t.shape==="rotated_pill_hole_with_rect_pad"?(c="rect",I=[t.rect_pad_width,t.rect_pad_height],l=new M1({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q}),B=t.rect_ccw_rotation||0):(c="circle",I=[1.6,1.6],l=new M1({diameter:.8,offset:Q}));const h=`thruhole:${o}:${e}:${g.x},${g.y}`,E=new Pj({number:String(e),padType:"thru_hole",shape:c,at:[g.x,g.y,B],size:I,drill:l,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:Bd(h)});return n&&(E.net=new G1A(n.id,n.name)),E}function bEi(t,A,e,i,n,o){const s=[];let r=n;for(const a of t){const g=o(a.pcb_port_id),c=SEi({platedHole:a,componentCenter:A,padNumber:r,componentRotation:e,netInfo:g,componentId:i});c&&(s.push(c),r++)}return{pads:s,nextPadNumber:r}}function _Ei({pcbHole:t,componentCenter:A,componentRotation:e=0}){if(!("x"in t&&"y"in t))return null;const i=t.x-A.x,n=-(t.y-A.y),o=e!==0?Tl(e*Math.PI/180):ba(),s=Ce(o,{x:i,y:n});let r="circle",a,g;if(t.hole_shape==="circle"){r="circle";const c=t.hole_diameter;a=[c,c],g=new M1({diameter:c})}else if(t.hole_shape==="oval"){r="oval";const c=t.hole_width,I=t.hole_height;a=[c,I],g=new M1({oval:!0,diameter:c,width:I})}else{r="circle";const c="hole_diameter"in t?t.hole_diameter:1;a=[c,c],g=new M1({diameter:c})}return new Pj({number:"",padType:"np_thru_hole",shape:r,at:[s.x,s.y,0],size:a,drill:g,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:crypto.randomUUID()})}function Gme(t,A,e){const i=[];for(const n of t){const o=_Ei({pcbHole:n,componentCenter:A,componentRotation:e});o&&i.push(o)}return i}var kEi=class extends t0{componentsProcessed=0;pcbComponents=[];includeBuiltin3dModels;getNetInfoForPcbPort(t){if(!t)return;const A=this.ctx.db.pcb_port?.get(t);if(!A)return;const e=A.source_port_id;if(!e)return;const i=this.ctx.db.source_port?.get(e);if(!i)return;const n=i.subcircuit_connectivity_map_key;if(n)return this.ctx.pcbNetMap?.get(n)}getCadComponentForPcbComponent(t){return(this.ctx.db.cad_component?.list()||[]).find(e=>e.pcb_component_id===t)}constructor(t,A,e){super(t,A),this.pcbComponents=this.ctx.db.pcb_component.list(),this.includeBuiltin3dModels=e?.includeBuiltin3dModels??!1}_step(){const{kicadPcb:t,c2kMatPcb:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.componentsProcessed>=this.pcbComponents.length){this.finished=!0;return}const e=this.pcbComponents[this.componentsProcessed],i=e.source_component_id?this.ctx.db.source_component.get(e.source_component_id):null,n=this.getCadComponentForPcbComponent(e.pcb_component_id),o=i?A5(i,n):"Unknown",s=Ce(A,{x:e.center.x,y:e.center.y}),r=`footprint:${e.pcb_component_id}:${s.x},${s.y}`,a=new Zj({libraryLink:`tscircuit:${o}`,layer:"F.Cu",at:[s.x,s.y,e.rotation||0],uuid:Bd(r)}),g=a.fpTexts,c=this.ctx.db.pcb_silkscreen_text?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[];g.push(...yEi(c,e.center,e.rotation||0,i?.name));const I=this.ctx.db.pcb_note_text?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[];g.push(...mEi(I,e.center,e.rotation||0)),a.fpTexts=g;const l=a.fpPads,B=q=>this.getNetInfoForPcbPort(q),C=this.ctx.db.pcb_smtpad?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[],{pads:Q,nextPadNumber:h}=xEi(C,e.center,e.rotation||0,e.pcb_component_id,1,B);l.push(...Q);const E=this.ctx.db.pcb_plated_hole?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[],{pads:u}=bEi(E,e.center,e.rotation||0,e.pcb_component_id,h,B);l.push(...u);const d=this.ctx.db.pcb_hole?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[],p=Gme(d,e.center,e.rotation||0);l.push(...p),a.fpPads=l;const y=this.ctx.db.pcb_silkscreen_circle?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[],w=a.fpCircles??[];w.push(...QEi(y,e.center));const D=this.ctx.db.pcb_courtyard_circle?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[];w.push(...hEi(D,e.center)),a.fpCircles=w;const x=this.ctx.db.pcb_fabrication_note_rect?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[],_=a.fpRects??[];_.push(...EEi(x,e.center));const S=this.ctx.db.pcb_note_rect?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[];_.push(...uEi(S,e.center));const N=this.ctx.db.pcb_courtyard_rect?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[];_.push(...dEi(N,e.center)),a.fpRects=_;const F=this.ctx.db.pcb_courtyard_outline?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[],L=pEi(F,e.center);if(L.length>0&&(a.fpPolys=L),n){const Z=this.ctx.db.pcb_board?.list()[0]?.thickness??0,X=e.layer==="bottom"?-(Z/2):Z/2,eA=wEi(n,e.center,{boardLayerZOffset:X}),gA="${KIPRJMOD}/3dmodels";if(eA.length>0)this.includeBuiltin3dModels?a.models=eA.map(tA=>{if(!tA.path)return tA;const iA=kxA(tA.path),aA=tA.path.startsWith("http://modelcdn.tscircuit.com")||tA.path.startsWith("https://modelcdn.tscircuit.com")?"tscircuit_builtin":this.ctx.projectName??iA.replace(/\.[^.]+$/,""),EA=new $3(`${gA}/${aA}.3dshapes/${iA}`);tA.offset&&(EA.offset=tA.offset),tA.scale&&(EA.scale=tA.scale),tA.rotate&&(EA.rotate=tA.rotate);const SA=tA.path?.split("?")[0];return SA&&!this.ctx.pcbModel3dSourcePaths?.includes(SA)&&this.ctx.pcbModel3dSourcePaths?.push(SA),EA}):a.models=eA;else if(n.footprinter_string&&this.includeBuiltin3dModels){const{footprinter_string:tA}=n,iA=`${gA}/tscircuit_builtin.3dshapes/${tA}.step`;a.models=[new $3(iA)];const sA=`${Nme}/${tA}.step`;this.ctx.pcbModel3dSourcePaths?.includes(sA)||this.ctx.pcbModel3dSourcePaths?.push(sA)}}const Y=e.metadata?.kicad_footprint;Y&&i?.name&&CEi(a,Y,i.name);const J=t.footprints;J.push(a),t.footprints=J,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},vEi={top:"F.Cu",bottom:"B.Cu",inner1:"In1.Cu",inner2:"In2.Cu",inner3:"In3.Cu",inner4:"In4.Cu",inner5:"In5.Cu",inner6:"In6.Cu"};function FEi(t){return t&&(vEi[t]||t)||"F.Cu"}function MEi(t){const A=["F.Cu"];for(let e=1;e<t-1;e++)A.push(`In${e}.Cu`);return A.push("B.Cu"),A}var REi=class extends t0{tracesProcessed=0;pcbTraces=[];constructor(t,A){super(t,A),this.pcbTraces=this.ctx.db.pcb_trace.list()}_step(){const{kicadPcb:t,c2kMatPcb:A,pcbNetMap:e}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.tracesProcessed>=this.pcbTraces.length){this.finished=!0;return}const i=this.pcbTraces[this.tracesProcessed];if(!i.route||i.route.length<2){this.tracesProcessed++;return}let n=i.route[0]?.layer;for(let o=0;o<i.route.length-1;o++){const s=i.route[o],r=i.route[o+1],a=Ce(A,{x:s.x,y:s.y}),g=Ce(A,{x:r.x,y:r.y});let c;if(e){let h=i.subcircuit_connectivity_map_key;if(!h&&i.source_trace_id){const E=this.ctx.db.source_trace?.get(i.source_trace_id);if(E&&(h=E.subcircuit_connectivity_map_key,!h&&E.connected_source_net_ids?.length))for(const u of E.connected_source_net_ids){const d=this.ctx.db.source_net?.get(u);if(d?.subcircuit_connectivity_map_key){h=d.subcircuit_connectivity_map_key;break}}}if(!h&&typeof i.connection_name=="string"){const E=this.ctx.db.source_net?.get(i.connection_name);E?.subcircuit_connectivity_map_key&&(h=E.subcircuit_connectivity_map_key)}h&&(c=e.get(h))}const I=s.layer??r.layer??n,l=FEi(I),B=`segment:${a.x},${a.y}:${g.x},${g.y}:${l}:${c?.id??0}`,C=new v2A({start:{x:a.x,y:a.y},end:{x:g.x,y:g.y},layer:l,width:i.width||.25,net:new zj(c?.id??0),uuid:Bd(B)}),Q=t.segments;Q.push(C),t.segments=Q,s.layer&&(n=s.layer),r.layer&&(n=r.layer)}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},NEi=class extends t0{viasProcessed=0;pcbVias=[];constructor(t,A){super(t,A),this.pcbVias=this.ctx.db.pcb_via?.list()||[]}_step(){const{kicadPcb:t,c2kMatPcb:A,pcbNetMap:e}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.viasProcessed>=this.pcbVias.length){this.finished=!0;return}const i=this.pcbVias[this.viasProcessed],n=Ce(A,{x:i.x,y:i.y});let o;if(e){let I=i.subcircuit_connectivity_map_key;if(!I&&i.pcb_trace_id){const l=this.ctx.db.pcb_trace?.get(i.pcb_trace_id);if(l&&("subcircuit_connectivity_map_key"in l&&(I=l.subcircuit_connectivity_map_key),!I&&l.source_trace_id)){const B=this.ctx.db.source_trace?.get(l.source_trace_id);if(B&&("subcircuit_connectivity_map_key"in B&&(I=B.subcircuit_connectivity_map_key),!I&&B.connected_source_net_ids?.length))for(const C of B.connected_source_net_ids){const Q=this.ctx.db.source_net?.get(C);if(Q?.subcircuit_connectivity_map_key){I=Q.subcircuit_connectivity_map_key;break}}}}if(!I&&i.connection_name){const l=this.ctx.db.source_net?.get(i.connection_name);l?.subcircuit_connectivity_map_key&&(I=l.subcircuit_connectivity_map_key)}I&&(o=e.get(I))}const s=this.ctx.numLayers??2,r=i.layers?i.layers.map(I=>I==="top"?"F.Cu":I==="bottom"?"B.Cu":`In${I.replace("inner","")}.Cu`):MEi(s),a=`via:${n.x},${n.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${o?.id??0}`,g=new SxA({at:[n.x,n.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:r,net:new xxA(o?.id??0),uuid:Bd(a)}),c=t.vias;c.push(g),t.vias=c,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}},GEi=class extends t0{holesProcessed=0;standaloneHoles=[];constructor(t,A){super(t,A),this.standaloneHoles=this.ctx.db.pcb_hole.list().filter(e=>!e.pcb_component_id)}_step(){const{kicadPcb:t,c2kMatPcb:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.holesProcessed>=this.standaloneHoles.length){this.finished=!0;return}const e=this.standaloneHoles[this.holesProcessed];if(!e){this.holesProcessed++;return}const i=Ce(A,{x:0,y:0}),n=`standalone_hole:${e.pcb_hole_id}:${e.x},${e.y}`,o=new Zj({libraryLink:"tscircuit:MountingHole",layer:"F.Cu",at:[i.x,i.y,0],uuid:Bd(n)}),r=Gme([e],{x:0,y:0},0);if(r.length>0){o.fpPads=r;const a=t.footprints;a.push(o),t.footprints=a}this.holesProcessed++}getOutput(){return this.ctx.kicadPcb}};function LEi({textElement:t,c2kMatPcb:A}){if(!t.text||!t.anchor_position)return null;const e=Ce(A,{x:t.anchor_position.x,y:t.anchor_position.y}),n={top:"F.Fab",bottom:"B.Fab"}[t.layer]||t.layer||"F.Fab",o=(t.font_size||1)/1.5,s=new Zp;s.size={width:o,height:o};const r=new b6,a=t.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new Wp({font:s});a!=="center"&&(g.justify=r);const c=new gc([e.x,e.y,0]),I=new jj({text:t.text,layer:n,effects:g});return I.position=c,I}function UEi({textElement:t,c2kMatPcb:A}){if(!t.text||!t.anchor_position)return null;const e=Ce(A,{x:t.anchor_position.x,y:t.anchor_position.y}),n={top:"F.SilkS",bottom:"B.SilkS"}[t.layer]||t.layer||"F.SilkS",o=(t.font_size||1)/1.5,s=new Zp;s.size={width:o,height:o};const r=new b6,a=t.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new Wp({font:s});a!=="center"&&(g.justify=r);const c=t.ccw_rotation||0,I=new gc([e.x,e.y,c]),l=new jj({text:t.text,layer:n,effects:g});return l.position=I,l}var HEi=class extends t0{_step(){const{kicadPcb:t,c2kMatPcb:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");const e=this.ctx.db.pcb_silkscreen_path?.list()||[];for(const s of e)if(!(!s.route||s.route.length<2))for(let r=0;r<s.route.length-1;r++){const a=s.route[r],g=s.route[r+1];if(!a||!g)continue;const c=Ce(A,{x:a.x,y:a.y}),I=Ce(A,{x:g.x,y:g.y}),B={top:"F.SilkS",bottom:"B.SilkS"}[s.layer]||s.layer||"F.SilkS",C=new Vj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:B,width:s.stroke_width||.15}),Q=t.graphicLines;Q.push(C),t.graphicLines=Q}const i=this.ctx.db.pcb_silkscreen_text?.list().filter(s=>!s.pcb_component_id)||[];for(const s of i){const r=UEi({textElement:s,c2kMatPcb:A});if(r){const a=t.graphicTexts;a.push(r),t.graphicTexts=a}}const n=this.ctx.db.pcb_fabrication_note_text?.list()||[];for(const s of n){const r=LEi({textElement:s,c2kMatPcb:A});if(r){const a=t.graphicTexts;a.push(r),t.graphicTexts=a}}const o=this.ctx.db.pcb_board?.list()||[];if(o.length>0){const s=o[0];if(!s){this.finished=!0;return}let r;if(s.outline&&s.outline.length>0)r=s.outline;else{const g=s.width?s.width/2:0,c=s.height?s.height/2:0;r=[{x:s.center.x-g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y+c},{x:s.center.x-g,y:s.center.y+c}]}const a=r.map(g=>Ce(A,g));for(let g=0;g<a.length;g++){const c=a[g],I=a[(g+1)%a.length];if(!c||!I)continue;const l=new Vj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:"Edge.Cuts",width:.1}),B=t.graphicLines;B.push(l),t.graphicLines=B}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},Lme=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(t,A){this.ctx={db:Ua(t),circuitJson:t,kicadPcb:new bxA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:An(on(100,100),$a(1,-1)),projectName:A?.projectName,pcbModel3dSourcePaths:[]},this.pipeline=[new rEi(t,this.ctx),new aEi(t,this.ctx),new kEi(t,this.ctx,{includeBuiltin3dModels:A?.includeBuiltin3dModels}),new REi(t,this.ctx),new NEi(t,this.ctx),new GEi(t,this.ctx),new HEi(t,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadPcb}getOutputString(){return this.ctx.kicadPcb.getString()}getModel3dSourcePaths(){return this.ctx.pcbModel3dSourcePaths??[]}},YEi=class{ctx;project;constructor(t,A={}){const e=A.projectName??t?.project?.name??"circuit-json-project",i=A.schematicFilename??`${e}.kicad_sch`,n=A.pcbFilename??`${e}.kicad_pcb`,o=new Date().toISOString();this.ctx={db:Ua(t),circuitJson:t},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:e,created:o,modified:o},meta:{version:1},text_variables:{},libraries:{pinned_symbol_libs:[],pinned_footprint_libs:[]},boards:[],cvpcb:{meta:{version:0}},erc:{meta:{version:0},erc_exclusions:[]},net_settings:{meta:{version:1},last_net_id:0,classes:[]},pcbnew:{page_layout_descr_file:"",last_paths:{}},schematic:{meta:{version:1},page_layout_descr_file:"",last_opened_files:[i]},board:{meta:{version:1},last_opened_board:n},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
|
|
5829
|
+
`)}};UA.register(SxA);var bxA=class Q_e extends UA{static token="kicad_pcb";token="kicad_pcb";_sxVersion;_sxGenerator;_sxGeneratorVersion;_sxGeneral;_sxPaper;_sxTitleBlock;_sxLayers;_sxSetup;_properties=[];_nets=[];_footprints=[];_images=[];_segments=[];_grLines=[];_grTexts=[];_grPolys=[];_grRects=[];_vias=[];_zones=[];_otherChildren=[];constructor(A={}){super(),A.version!==void 0&&(this.version=A.version),A.generator!==void 0&&(this.generator=A.generator),A.generatorVersion!==void 0&&(this.generatorVersion=A.generatorVersion),A.general!==void 0&&(this.general=A.general),A.paper!==void 0&&(this.paper=A.paper),A.titleBlock!==void 0&&(this.titleBlock=A.titleBlock),A.layers!==void 0&&(this.layers=A.layers),A.setup!==void 0&&(this.setup=A.setup),A.properties!==void 0&&(this.properties=A.properties),A.nets!==void 0&&(this.nets=A.nets),A.footprints!==void 0&&(this.footprints=A.footprints),A.images!==void 0&&(this.images=A.images),A.segments!==void 0&&(this.segments=A.segments),A.graphicLines!==void 0&&(this.graphicLines=A.graphicLines),A.graphicTexts!==void 0&&(this.graphicTexts=A.graphicTexts),A.graphicPolys!==void 0&&(this.graphicPolys=A.graphicPolys),A.graphicRects!==void 0&&(this.graphicRects=A.graphicRects),A.vias!==void 0&&(this.vias=A.vias),A.zones!==void 0&&(this.zones=A.zones),A.otherChildren!==void 0&&(this.otherChildren=A.otherChildren)}static fromSexprPrimitives(A){const e=new Q_e;for(const i of A){if(!Array.isArray(i)||i.length===0)throw new Error(`kicad_pcb encountered unsupported primitive child: ${JSON.stringify(i)}`);const n=UA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(n instanceof UA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);e.consumeChild(n)}return e}consumeChild(A){if(A instanceof mxA){this._sxVersion=A;return}if(A instanceof wxA){this._sxGenerator=A;return}if(A instanceof DxA){this._sxGeneratorVersion=A;return}if(A instanceof fxA){this._sxGeneral=A;return}if(A instanceof Gj){this._sxPaper=A;return}if(A instanceof xpe){this._sxTitleBlock=A;return}if(A instanceof yxA){this._sxLayers=A;return}if(A instanceof pxA){this._sxSetup=A;return}if(A instanceof F1){this._properties.push(A);return}if(A instanceof Az){this._nets.push(A);return}if(A instanceof Zj){this._footprints.push(A);return}if(A instanceof bpe){this._images.push(A);return}if(A instanceof v2A){this._segments.push(A);return}if(A instanceof Vj){this._grLines.push(A);return}if(A instanceof jj){this._grTexts.push(A);return}if(A instanceof Eye){this._grPolys.push(A);return}if(A instanceof Cye){this._grRects.push(A);return}if(A instanceof SxA){this._vias.push(A);return}if(A instanceof mye){this._zones.push(A);return}this._otherChildren.push(A)}get version(){return this._sxVersion?.value}set version(A){this._sxVersion=A===void 0?void 0:new mxA(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new wxA(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new DxA(A)}get general(){return this._sxGeneral}set general(A){this._sxGeneral=A}get paper(){return this._sxPaper}set paper(A){this._sxPaper=A}get titleBlock(){return this._sxTitleBlock}set titleBlock(A){this._sxTitleBlock=A}get layers(){return this._sxLayers}set layers(A){this._sxLayers=A}get setup(){return this._sxSetup}set setup(A){this._sxSetup=A}get properties(){return[...this._properties]}set properties(A){this._properties=[...A]}get nets(){return[...this._nets]}set nets(A){this._nets=[...A]}get footprints(){return[...this._footprints]}set footprints(A){this._footprints=[...A]}get images(){return[...this._images]}set images(A){this._images=[...A]}get segments(){return[...this._segments]}set segments(A){this._segments=[...A]}get graphicLines(){return[...this._grLines]}set graphicLines(A){this._grLines=[...A]}get graphicTexts(){return[...this._grTexts]}set graphicTexts(A){this._grTexts=[...A]}get graphicPolys(){return[...this._grPolys]}set graphicPolys(A){this._grPolys=[...A]}get graphicRects(){return[...this._grRects]}set graphicRects(A){this._grRects=[...A]}get vias(){return[...this._vias]}set vias(A){this._vias=[...A]}get zones(){return[...this._zones]}set zones(A){this._zones=[...A]}get otherChildren(){return[...this._otherChildren]}set otherChildren(A){this._otherChildren=[...A]}getChildren(){const A=[];return this._sxVersion&&A.push(this._sxVersion),this._sxGenerator&&A.push(this._sxGenerator),this._sxGeneratorVersion&&A.push(this._sxGeneratorVersion),this._sxGeneral&&A.push(this._sxGeneral),this._sxPaper&&A.push(this._sxPaper),this._sxTitleBlock&&A.push(this._sxTitleBlock),this._sxLayers&&A.push(this._sxLayers),this._sxSetup&&A.push(this._sxSetup),A.push(...this._properties),A.push(...this._nets),A.push(...this._footprints),A.push(...this._images),A.push(...this._segments),A.push(...this._grLines),A.push(...this._grTexts),A.push(...this._grPolys),A.push(...this._grRects),A.push(...this._vias),A.push(...this._zones),A.push(...this._otherChildren),A}};UA.register(bxA);var bme=t=>UA.parse(t),t0=class{MAX_ITERATIONS=1e3;iteration=0;finished=!1;input;ctx;constructor(t,A){this.input=t,this.ctx=A}step(){if(this.iteration++,this.iteration>this.MAX_ITERATIONS)throw new Error("Max iterations reached");this._step()}_step(){throw new Error("Not implemented")}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){throw new Error("Not implemented")}},Y0i=class extends t0{_step(){const{kicadSch:t,schematicPaperSize:A}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");t.version=20250114;const e=new Gj;e.size=A?.name??"A4",t.paper=e,t.uuid=new qi(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function A5(t,A){if(t.manufacturer_part_number)return _xA(t.manufacturer_part_number);const e=J0i(t.ftype),i=A?.footprinter_string;return _xA(i?`${e}_${i}`:e)}function J0i(t){if(!t)return"component";let A=t.replace(/^simple_/,"");return A||"component"}function _xA(t){return t.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function _me(t){return t?t.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}var kme={simple_resistor:"R",simple_capacitor:"C",simple_inductor:"L",simple_diode:"D",simple_led:"D",simple_chip:"U",simple_transistor:"Q",simple_mosfet:"Q",simple_fuse:"F",simple_switch:"SW",simple_push_button:"SW",simple_potentiometer:"RV",simple_crystal:"Y",simple_resonator:"Y",simple_pin_header:"J",simple_pinout:"J",simple_test_point:"TP",simple_battery:"BT"},T0i=/^[A-Za-z]+\d+$/;function vme(t){return t?T0i.test(t.trim()):!1}function ez(t){const A=t?.ftype;if(A&&kme[A])return kme[A];const e=t?.name;return vme(e),_me(e)}function P0i(t){const A=t?.name;return vme(A)?A.trim():`${ez(t)}?`}function Fme(t){return t in JQ}function Mme(t,A,e,i){if(i)return`Custom:${i}`;if(t.type!=="source_component")return A.symbol_name?Fme(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return Fme(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const n=A5(t,e);return`Device:${ez(t)}_${n}`}function K0i(t){const{circuitJson:A,schematicSymbolId:e,schematicSymbol:i,schematicComponentId:n}=t,o=A.filter(Q=>Q.type==="schematic_circle"&&Q.schematic_symbol_id===e),s=A.filter(Q=>Q.type==="schematic_line"&&Q.schematic_symbol_id===e),r=n?A.filter(Q=>Q.type==="schematic_line"&&Q.schematic_component_id===n&&!Q.schematic_symbol_id):[],a=[...s,...r],g=A.filter(Q=>Q.type==="schematic_path"&&Q.schematic_symbol_id===e),c=A.filter(Q=>Q.type==="schematic_text"&&Q.schematic_symbol_id===e);let I=A.filter(Q=>Q.type==="schematic_port"&&"schematic_symbol_id"in Q&&Q.schematic_symbol_id===e);if(I.length===0&&n){const Q=A.filter(E=>E.type==="schematic_port"&&E.schematic_component_id===n&&E.display_pin_label!==void 0),h=new Map;for(const E of Q)E.display_pin_label&&h.set(E.display_pin_label,E);if(I=h.size>0?Array.from(h.values()):Q,I.length===0){const E=A.filter(d=>d.type==="schematic_port"&&d.schematic_component_id===n),u=new Set;I=E.filter(d=>{const p=d.pin_number;if(p!==void 0){if(u.has(p))return!1;u.add(p)}return!0})}}const l=[];for(const Q of o)l.push({type:"circle",x:Q.center?.x??0,y:Q.center?.y??0,radius:Q.radius??.5,fill:Q.is_filled??!1,fillColor:Q.fill_color});for(const Q of a)l.push({type:"path",points:[{x:Q.x1??0,y:Q.y1??0},{x:Q.x2??0,y:Q.y2??0}]});for(const Q of g)Q.points&&Q.points.length>0&&l.push({type:"path",points:Q.points,fill:Q.is_filled??!1,fillColor:Q.fill_color});const B=c.map(Q=>({text:Q.text??"",x:Q.position?.x??0,y:Q.position?.y??0,fontSize:Q.font_size??.2,anchor:Q.anchor??"center"})),C=I.map((Q,h)=>({x:Q.center?.x??0,y:Q.center?.y??0,labels:[Q.display_pin_label||`${Q.pin_number||h+1}`],pinNumber:Q.pin_number||h+1,facingDirection:Q.facing_direction}));return C.sort((Q,h)=>Q.pinNumber-h.pinNumber),{center:i.center||{x:0,y:0},size:i.size||{width:1,height:1},primitives:l,texts:B,ports:C}}function q0i({points:t,transform:A,fillType:e}){const i=new kpe,n=t.map(a=>{const g=Ce(A,a);return new sh(g.x,g.y)}),o=new sQ(n);i.points=o;const s=new v1;s.width=.254,s.type="default",i.stroke=s;const r=new Lpe;return r.type=e,i.fill=r,i}function O0i({primitive:t,transform:A,scale:e}){const i=new Ype,n=Ce(A,{x:t.x,y:t.y}),o=i;o._sxCenter=new Npe(n.x,n.y),o._sxRadius=new Gpe(t.radius*e);const s=new v1;s.width=.254,s.type="default",o._sxStroke=s;const r=new Upe;return r.type=t.fill?"background":"none",o._sxFill=r,i}function W0i({schText:t,transform:A,scale:e}){const i=new Jpe,n=Ce(A,{x:t.x,y:t.y});i.value=t.text,i.at=[n.x,n.y,0];const o=t.fontSize*e,s=new Zp;return s.size={height:o,width:o},i.effects=new Wp({font:s}),i}function Z0i({libId:t,symbolData:A,isChip:e,c2kMatSchScale:i}){const n=new XM({libraryId:`${t.split(":")[1]}_0_1`}),o=i,s=A.center?.x??0,r=A.center?.y??0,a=An($a(o,o),on(-s,-r));for(const c of A.primitives||[])if(c.type==="path"&&c.points){const I=e||c.fill?"background":"none",l=q0i({points:c.points,transform:a,fillType:I});n.polylines.push(l)}else if(c.type==="circle"){const I=O0i({primitive:c,transform:a,scale:o});n.circles.push(I)}const g=Array.isArray(A.texts)?A.texts:[];for(const c of g){const I=W0i({schText:c,transform:a,scale:o});n.texts.push(I)}return n}function V0i(t,A){const e=A.schematic_port.list().filter(r=>r.schematic_component_id===t.schematic_component_id).sort((r,a)=>(r.pin_number||0)-(a.pin_number||0)),i=t.size?.width||1.5,n=t.size?.height||1,o={type:"path",points:[{x:-i/2,y:-n/2},{x:i/2,y:-n/2},{x:i/2,y:n/2},{x:-i/2,y:n/2},{x:-i/2,y:-n/2}]},s=e.map(r=>{const a=r.center.x-t.center.x,g=r.center.y-t.center.y;return{x:a,y:g,labels:[r.display_pin_label||`${r.pin_number||1}`],pinNumber:r.pin_number||1}});return{center:{x:0,y:0},primitives:[o],ports:s,size:{width:i,height:n}}}function j0i(t,A){const e=new Zp;return e.size={height:t,width:t},new Wp({font:e,hiddenText:A})}function z0i({symbol:t,libId:A,description:e,keywords:i,fpFilters:n,footprintRef:o="",referencePrefix:s}){const r=s||A.split(":")[1]?.[0]||"U",a=[{key:"Reference",value:r,id:0,at:[2.032,0,90],hide:!1},{key:"Value",value:r,id:1,at:[0,0,90],hide:!1},{key:"Footprint",value:o,id:2,at:[-1.778,0,90],hide:!0},{key:"Datasheet",value:"~",id:3,at:[0,0,0],hide:!0},{key:"Description",value:e,id:4,at:[0,0,0],hide:!0},{key:"ki_keywords",value:i,id:5,at:[0,0,0],hide:!0},{key:"ki_fp_filters",value:n,id:6,at:[0,0,0],hide:!0}];for(const g of a)t.properties.push(new Vp({key:g.key,value:g.value,id:g.id,at:g.at,effects:j0i(1.27,g.hide)}))}function X0i({port:t,center:A,size:e,isChip:i,portIndex:n,schematicComponent:o,schematicPorts:s,c2kMatSchScale:r}){const a=r;let g=t.x??0,c=t.y??0,I=!1;if(i&&n!==void 0&&o){const y=s.filter(w=>w.schematic_component_id===o.schematic_component_id).sort((w,D)=>(w.pin_number||0)-(D.pin_number||0));if(y[n]){const w=y[n];g=w.center.x-o.center.x,c=w.center.y-o.center.y,I=!0}}let l,B;if(I)l=g,B=c;else{const y=A?.x??0,w=A?.y??0;l=g-y,B=c-w}const C=$a(a,a),Q=Ce(C,{x:l,y:B});let h;if(i&&e){const y=e.width/2,w=e.height/2,D=Math.abs(l)/y,x=Math.abs(B)/w;h=D>x}else h=Math.abs(l)>Math.abs(B);let E=Q.x,u=Q.y;const d=6;if(i&&e){const y=e.width/2*a,w=e.height/2*a;h?(E=l>0?y:-y,u=B*a):(E=l*a,u=B>0?w:-w)}let p=0;return h?l>0?(p=180,i&&(E=E+d)):(p=0,i&&(E=E-d)):B>0?(p=270,i&&(u=u+d)):(p=90,i&&(u=u-d)),{x:E,y:u,angle:p}}function $0i({libId:t,symbolData:A,isChip:e,schematicComponent:i,schematicPorts:n,c2kMatSchScale:o}){const s=new XM({libraryId:`${t.split(":")[1]}_1_1`}),r=6,a=2.54;for(let g=0;g<(A.ports?.length||0);g++){const c=A.ports[g],I=new Yj;I.pinElectricalType="passive",I.pinGraphicStyle="line";const{x:l,y:B,angle:C}=X0i({port:c,center:A.center,size:A.size,isChip:e,portIndex:g,schematicComponent:i,schematicPorts:n,c2kMatSchScale:o});I.at=[l,B,C],I.length=e?r:a;const Q=new Zp;Q.size={height:1.27,width:1.27};const h=new Wp({font:Q}),E=c.labels?.[0]||"~";I._sxName=new g1A({value:E,effects:h});const u=new Zp;u.size={height:1.27,width:1.27};const d=new Wp({font:u}),p=c.pinNumber?.toString()||`${g+1}`;I._sxNumber=new Ppe({value:p,effects:d}),s.pins.push(I)}return s}var AEi=class extends t0{processedSymbolNames=new Set;_step(){const{kicadSch:t,db:A}=this.ctx,e=new jpe,i=[];this.processedSymbolNames=new Set;const n=A.schematic_component.list();for(const s of n){const r=this.createLibrarySymbolForComponent(s);r&&i.push(r)}const o=A.schematic_net_label?.list?.()||[];for(const s of o)if(s.symbol_name){const r=s.source_net_id?A.source_net.get(s.source_net_id)?.is_power:!1,a=s.source_net_id?A.source_net.get(s.source_net_id)?.is_ground:!1;if(r||a){const c=this.createLibrarySymbolForNetLabel({netLabel:s,isPower:r??!1,isGround:a??!1});c&&i.push(c)}}e.symbols=i,t&&(t.libSymbols=e),this.finished=!0}createLibrarySymbolForComponent(t){const{db:A}=this.ctx,e=t.source_component_id?A.source_component.get(t.source_component_id):null;if(!e)return null;const i=A.cad_component?.list()?.find(c=>c.source_component_id===e.source_component_id);let n=t.schematic_symbol_id;if(!n){const c=this.ctx.circuitJson.find(I=>(I.type==="schematic_line"||I.type==="schematic_circle"||I.type==="schematic_path")&&I.schematic_component_id===t.schematic_component_id&&I.schematic_symbol_id);c&&(n=c.schematic_symbol_id)}if(n)return this.createLibrarySymbolFromSchematicSymbol(t,e,i,n);const o=t.symbol_name||(e.ftype==="simple_chip"?`generic_chip_${t.source_component_id}`:null);if(!o)return null;const s=this.getSymbolData(o,t);if(!s)return null;const r=Mme(e,t,i),a=e.ftype==="simple_chip",g=A5(e,i);return this.createLibrarySymbol({libId:r,symbolData:s,isChip:a,schematicComponent:t,description:this.getDescription(e),keywords:this.getKeywords(e),fpFilters:this.getFpFilters(e),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:ez(e)})}createLibrarySymbolFromSchematicSymbol(t,A,e,i){const{db:n}=this.ctx,o=this.ctx.circuitJson.find(c=>c.type==="schematic_symbol"&&c.schematic_symbol_id===i);if(!o)return null;let s;if(o.name)s=o.name;else{const c=A5(A,e);c?s=c:s=`custom_${A.ftype||"component"}_${i}`}const r=`Custom:${s}`;if(this.processedSymbolNames.has(r))return null;this.processedSymbolNames.add(r);const a=K0i({circuitJson:this.ctx.circuitJson,schematicSymbolId:i,schematicSymbol:o,schematicComponentId:t.schematic_component_id}),g=A5(A,e);return this.createLibrarySymbol({libId:r,symbolData:a,isChip:!1,schematicComponent:t,description:this.getDescription(A),keywords:this.getKeywords(A),fpFilters:this.getFpFilters(A,o.name),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:ez(A),symbolScale:1})}createLibrarySymbolForNetLabel({netLabel:t,isPower:A,isGround:e}){const i=t.symbol_name;if(!i)return null;const n=JQ[i];if(!n)return null;const o=`Custom:${i}`;return this.createLibrarySymbol({libId:o,symbolData:n,isChip:!1,schematicComponent:void 0,description:A?"Power net label":e?"Ground net label":"Net symbol",keywords:A?"power net":e?"ground net":"net",fpFilters:"",referencePrefix:o.split(":")[1]?.[0]||"U"})}getSymbolData(t,A){return t.startsWith("generic_chip_")?V0i(A,this.ctx.db):JQ[t]||null}createLibrarySymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i,description:n,keywords:o,fpFilters:s,footprintRef:r="",referencePrefix:a,symbolScale:g}){const I=g??this.ctx.c2kMatSch?.a??15,l=new XM({libraryId:t,excludeFromSim:!1,inBom:!0,onBoard:!0}),B=new s1A;B.hide=!e,l._sxPinNumbers=B;const C=new a1A;C.offset=e?1.27:0,l._sxPinNames=C,z0i({symbol:l,libId:t,description:n,keywords:o,fpFilters:s,footprintRef:r,referencePrefix:a});const Q=Z0i({libId:t,symbolData:A,isChip:e,c2kMatSchScale:I});l.subSymbols.push(Q);const h=$0i({libId:t,symbolData:A,isChip:e,schematicComponent:i,schematicPorts:this.ctx.db.schematic_port.list(),c2kMatSchScale:I});return l.subSymbols.push(h),l._sxEmbeddedFonts=new jM(!1),l}getDescription(t){return t?.ftype==="simple_resistor"?"Resistor":t?.ftype==="simple_capacitor"?"Capacitor":t?.ftype==="simple_chip"?"Integrated Circuit":"Component"}getKeywords(t){return t?.ftype==="simple_resistor"?"R res resistor":t?.ftype==="simple_capacitor"?"C cap capacitor":t?.ftype==="simple_chip"?"U IC chip":""}getFpFilters(t,A){return A?`${A}*`:t?.ftype==="simple_resistor"?"R_*":t?.ftype==="simple_capacitor"?"C_*":(t?.ftype==="simple_chip","*")}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},eEi=class extends t0{_step(){const{kicadSch:t,db:A}=this.ctx,e=A.schematic_component.list();if(e.length===0){this.finished=!0;return}const i=[];for(const n of e){const o=n.source_component_id?A.source_component.get(n.source_component_id):null;if(!o||!this.ctx.c2kMatSch)continue;const{x:s,y:r}=Ce(this.ctx.c2kMatSch,{x:n.center.x,y:n.center.y}),a=crypto.randomUUID(),g=new XM({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:a,fieldsAutoplaced:!0}),c=A.cad_component?.list()?.find(iA=>iA.source_component_id===o.source_component_id);let I,l=n.schematic_symbol_id;if(!l){const iA=this.ctx.circuitJson.find(sA=>(sA.type==="schematic_line"||sA.type==="schematic_circle"||sA.type==="schematic_path")&&sA.schematic_component_id===n.schematic_component_id&&sA.schematic_symbol_id);iA&&(l=iA.schematic_symbol_id)}if(l){const iA=this.ctx.circuitJson.find(sA=>sA.type==="schematic_symbol"&&sA.schematic_symbol_id===l);if(iA?.name)I=iA.name;else{const sA=A5(o,c);sA?I=sA:I=`custom_${o.ftype||"component"}_${l}`}}const B=Mme(o,n,c,I),C=new n1A(B);g._sxLibId=C;const{reference:Q,value:h,description:E}=this.getComponentMetadata(o),{refTextPos:u,valTextPos:d}=this.getTextPositions(n,{x:s,y:r});let p;if(l){const iA=this.ctx.circuitJson.find(sA=>sA.type==="schematic_symbol"&&sA.schematic_symbol_id===l);iA&&iA.type==="schematic_symbol"&&(p=iA.metadata?.kicad_symbol)}const y=p?.properties?.Reference,w=new Vp({key:"Reference",value:y?.value??Q,id:0,at:[u.x,u.y,0],effects:this.createTextEffects(Number(y?.effects?.font?.size?.x??1.27),y?.effects?.hide??!1)}),D=o.ftype==="simple_chip",x=p?.properties?.Value,_=new Vp({key:"Value",value:x?.value??h,id:1,at:[d.x,d.y,0],effects:this.createTextEffects(Number(x?.effects?.font?.size?.x??1.27),x?.effects?.hide??D)}),S=p?.properties?.Footprint,N=new Vp({key:"Footprint",value:S?.value??"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,S?.effects?.hide??!0)}),F=p?.properties?.Datasheet,L=new Vp({key:"Datasheet",value:F?.value??"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,F?.effects?.hide??!0)}),Y=p?.properties?.Description,J=new Vp({key:"Description",value:Y?.value??E,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,Y?.effects?.hide??!0)});g.properties.push(w,_,N,L,J);const q=p?.properties?.ki_keywords;if(q?.value){const iA=new Vp({key:"ki_keywords",value:q.value,id:5,at:[s,r,0],effects:this.createTextEffects(1.27,q.effects?.hide??!0)});g.properties.push(iA)}const Z=p?.properties?.ki_fp_filters;if(Z?.value){const iA=new Vp({key:"ki_fp_filters",value:Z.value,id:6,at:[s,r,0],effects:this.createTextEffects(1.27,Z.effects?.hide??!0)});g.properties.push(iA)}if(p){if(p.inBom!==void 0&&(g.inBom=p.inBom),p.onBoard!==void 0&&(g.onBoard=p.onBoard),p.excludeFromSim!==void 0&&(g.excludeFromSim=p.excludeFromSim),p.pinNames){const iA=new a1A;p.pinNames.offset!==void 0&&(iA.offset=Number(p.pinNames.offset)),p.pinNames.hide!==void 0&&(iA.hide=p.pinNames.hide),g.pinNames=iA}if(p.pinNumbers){const iA=new s1A;p.pinNumbers.hide!==void 0&&(iA.hide=p.pinNumbers.hide),g.pinNumbers=iA}p.embeddedFonts!==void 0&&(g._sxEmbeddedFonts=new jM(p.embeddedFonts))}let X=A.schematic_port.list().filter(iA=>iA.schematic_component_id===n.schematic_component_id);if(l){const iA=X.filter(sA=>sA.display_pin_label);iA.length>0&&(X=iA)}X.sort((iA,sA)=>(iA.pin_number||0)-(sA.pin_number||0));for(let iA=0;iA<X.length;iA++){const sA=X[iA];if(!sA)continue;const aA=new Yj;aA.numberString=`${sA.pin_number||iA+1}`,aA.uuid=crypto.randomUUID(),g.pins.push(aA)}const eA=new c1A,gA=new l1A(""),tA=new B1A(`/${t?.uuid?.value||""}`);tA.reference=Q,tA.unit=1,gA.paths.push(tA),eA.projects.push(gA),g._sxInstances=eA,i.push(g)}t&&(t.symbols=i),this.finished=!0}getTextPositions(t,A){const i=(this.ctx.db.schematic_text?.list?.()?.filter(B=>B.schematic_component_id===t.schematic_component_id)||[]).find(B=>B.text&&B.text.length>0);if(i&&this.ctx.c2kMatSch){const B=Ce(this.ctx.c2kMatSch,{x:i.position.x,y:i.position.y}),C={x:A.x,y:A.y+6};return{refTextPos:B,valTextPos:C}}const n=t.symbol_name,o=JQ[n];if(!o)return{refTextPos:{x:A.x,y:A.y-6},valTextPos:{x:A.x,y:A.y+6}};let s=null,r=null;for(const B of o.primitives)B.type==="text"&&(B.text==="{REF}"?s=B:B.text==="{VAL}"&&(r=B));const a=o.center||{x:0,y:0},c=n.includes("_down")||n.includes("_up")?.15:0,I=s&&this.ctx.c2kMatSch?Ce(this.ctx.c2kMatSch,{x:t.center.x+(s.x-a.x)+c,y:t.center.y+(s.y-a.y)}):{x:A.x,y:A.y-6},l=r&&this.ctx.c2kMatSch?Ce(this.ctx.c2kMatSch,{x:t.center.x+(r.x-a.x)+c,y:t.center.y+(r.y-a.y)}):{x:A.x,y:A.y+6};return{refTextPos:I,valTextPos:l}}getComponentMetadata(t){const A=t.name||"?",e=P0i(t);return t.ftype==="simple_resistor"?{reference:e,value:t.display_resistance||"R",description:"Resistor"}:t.ftype==="simple_capacitor"?{reference:e,value:t.display_capacitance||"C",description:"Capacitor"}:t.ftype==="simple_inductor"?{reference:e,value:t.display_inductance||"L",description:"Inductor"}:t.ftype==="simple_diode"?{reference:e,value:"D",description:"Diode"}:t.ftype==="simple_chip"?{reference:e,value:A,description:"Integrated Circuit"}:t.ftype==="simple_led"?{reference:e,value:t.manufacturer_part_number||"",description:"LED"}:t.ftype==="simple_switch"?{reference:e,value:t.manufacturer_part_number||"",description:"Switch"}:t.ftype==="simple_potentiometer"?{reference:e,value:t.display_max_resistance||"",description:"Potentiometer"}:{reference:e,value:A,description:"Component"}}createTextEffects(t,A=!1,e){const i=new Zp;i.size={height:t,width:t};const n=e?new b6({horizontal:e}):void 0;return new Wp({font:i,hiddenText:A,justify:n})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},tEi=class extends t0{_step(){const{kicadSch:t,db:A}=this.ctx,e=A.schematic_net_label?.list?.()||[];if(e.length===0){this.finished=!0;return}if(!this.ctx.c2kMatSch){this.finished=!0;return}const i=[],n=[];for(const o of e){const s=o.text||"",r=o.symbol_name;if(r){const a=this.createSymbolFromNetLabel(o,s,r);a&&i.push(a)}else{const a=this.createGlobalLabel(o,s);a&&n.push(a)}}if(t&&i.length>0){const o=t.symbols||[];t.symbols=[...o,...i]}t&&n.length>0&&(t.globalLabels=[...t.globalLabels||[],...n]),this.finished=!0}createSymbolFromNetLabel(t,A,e){if(!this.ctx.c2kMatSch)return null;const{x:i,y:n}=Ce(this.ctx.c2kMatSch,{x:t.anchor_position?.x??t.center?.x??0,y:t.anchor_position?.y??t.center?.y??0}),o=crypto.randomUUID(),s=new XM({at:[i,n,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:o,fieldsAutoplaced:!0}),r=`Custom:${e}`,a=new n1A(r);s._sxLibId=a;const g=e.includes("_up")||e.toLowerCase().includes("vcc"),c=g?-4:4,I=g?-6:6,l=new Vp({key:"Reference",value:A,id:0,at:[i,n+c,0],effects:this.createTextEffects(1.27,!1)}),B=new Vp({key:"Value",value:A,id:1,at:[i,n+I,0],effects:this.createTextEffects(1.27,!0)}),C=new Vp({key:"Footprint",value:"",id:2,at:[i-1.778,n,90],effects:this.createTextEffects(1.27,!0)}),Q=new Vp({key:"Datasheet",value:"~",id:3,at:[i,n,0],effects:this.createTextEffects(1.27,!0)}),h=new Vp({key:"Description",value:`Power/Net symbol: ${A}`,id:4,at:[i,n,0],effects:this.createTextEffects(1.27,!0)});s.properties.push(l,B,C,Q,h);const E=new Yj;E.numberString="1",E.uuid=crypto.randomUUID(),s.pins.push(E);const{kicadSch:u}=this.ctx,d=new c1A,p=new l1A(""),y=new B1A(`/${u?.uuid?.value||""}`);return y.reference=A,y.unit=1,p.paths.push(y),d.projects.push(p),s._sxInstances=d,s}createGlobalLabel(t,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:e,y:i}=Ce(this.ctx.c2kMatSch,{x:t.anchor_position?.x??t.center?.x??0,y:t.anchor_position?.y??t.center?.y??0}),n=t.anchor_side||"left",s={left:0,right:180,top:270,bottom:90}[n]||0,a={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[n]||{},g=this.createTextEffects(1.27,!1);return Object.keys(a).length>0&&(g.justify=new b6(a)),new ofe({value:A,at:[e,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(t,A=!1){const e=new Zp;return e.size={height:t,width:t},new Wp({font:e,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},iEi=class extends t0{_step(){const{kicadSch:t,db:A}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");const e=A.schematic_trace.list();if(e.length===0){this.finished=!0;return}const i=[],n=[];for(const o of e){for(const s of o.edges){const r=this.createWireFromEdge(s);i.push(r)}for(const s of o.junctions){const r=this.createJunction(s);n.push(r)}}t.wires=i,t.junctions=n,this.finished=!0}createWireFromEdge(t){const A=new Xpe;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const e=Ce(this.ctx.c2kMatSch,{x:t.from.x,y:t.from.y}),i=Ce(this.ctx.c2kMatSch,{x:t.to.x,y:t.to.y}),n=e.x,o=e.y,s=i.x,r=i.y,a=new sQ([new sh(n,o),new sh(s,r)]);A.points=a;const g=new v1;return g.width=0,g.type="default",A.stroke=g,A.uuid=crypto.randomUUID(),A}createJunction(t){if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const{x:A,y:e}=Ce(this.ctx.c2kMatSch,{x:t.x,y:t.y}),i=new $pe({at:[A,e],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},nEi=class extends t0{_step(){const{kicadSch:t}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");const A=new E1A,e=new afe;e.value="/";const i=new gfe("1");e.pages=[i],A.paths=[e],t.sheetInstances=A,t.embeddedFonts=new jM(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function oEi(t){const A=t.schematic_component.list(),e=t.schematic_trace.list();let i=1/0,n=1/0,o=-1/0,s=-1/0;for(const g of A){const c=g.size?.width??0,I=g.size?.height??0;i=Math.min(i,g.center.x-c/2),n=Math.min(n,g.center.y-I/2),o=Math.max(o,g.center.x+c/2),s=Math.max(s,g.center.y+I/2)}for(const g of e)for(const c of g.edges)i=Math.min(i,c.from.x,c.to.x),n=Math.min(n,c.from.y,c.to.y),o=Math.max(o,c.from.x,c.to.x),s=Math.max(s,c.from.y,c.to.y);i===1/0&&(i=0,n=0,o=0,s=0);const r=(i+o)/2,a=(n+s)/2;return{center:{x:r,y:a},bounds:{minX:i,minY:n,maxX:o,maxY:s}}}var tz=[{name:"A4",width:297,height:210},{name:"A3",width:420,height:297},{name:"A2",width:594,height:420},{name:"A1",width:841,height:594},{name:"A0",width:1189,height:841}];function sEi(t,A,e=20){const i=t+2*e,n=A+2*e;for(let o=0;o<tz.length;o++){const s=tz[o];if(i<=s.width&&n<=s.height)return s}return tz[tz.length-1]}var Rme=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(t){const e=Ua(t),{center:i,bounds:n}=oEi(e),o=(n.maxX-n.minX)*15,s=(n.maxY-n.minY)*15,r=sEi(o,s),a=r.width/2,g=r.height/2;this.ctx={db:e,circuitJson:t,kicadSch:new d1A({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:r,c2kMatSch:An(on(a,g),$a(15,-15),on(-i.x,-i.y))},this.pipeline=[new Y0i(t,this.ctx),new AEi(t,this.ctx),new eEi(t,this.ctx),new tEi(t,this.ctx),new iEi(t,this.ctx),new nEi(t,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadSch}getOutputString(){return this.ctx.kicadSch.getString()}},rEi=class extends t0{_step(){const{kicadPcb:t,db:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");const i=A.pcb_board?.list()?.[0]?.num_layers??2;this.ctx.numLayers=i,t.version=20241229;const n=new Gj;n.size="A4",t.paper=n;const o=new fxA;o.thickness=1.6,t.general=o;const s=new pxA;s.padToMaskClearance=0,t.setup=s;const r=new yxA,a=[new jl({index:0,name:"F.Cu",type:"signal"})];for(let g=1;g<i-1;g++)a.push(new jl({index:g,name:`In${g}.Cu`,type:"signal"}));a.push(new jl({index:31,name:"B.Cu",type:"signal"})),a.push(new jl({index:32,name:"B.Adhes",type:"user"}),new jl({index:33,name:"F.Adhes",type:"user"}),new jl({index:34,name:"B.Paste",type:"user"}),new jl({index:35,name:"F.Paste",type:"user"}),new jl({index:36,name:"B.SilkS",type:"user"}),new jl({index:37,name:"F.SilkS",type:"user"}),new jl({index:38,name:"B.Mask",type:"user"}),new jl({index:39,name:"F.Mask",type:"user"}),new jl({index:40,name:"Dwgs.User",type:"user"}),new jl({index:41,name:"Cmts.User",type:"user"}),new jl({index:42,name:"Eco1.User",type:"user"}),new jl({index:43,name:"Eco2.User",type:"user"}),new jl({index:44,name:"Edge.Cuts",type:"user"}),new jl({index:45,name:"Margin",type:"user"}),new jl({index:46,name:"B.CrtYd",type:"user"}),new jl({index:47,name:"F.CrtYd",type:"user"}),new jl({index:48,name:"B.Fab",type:"user"}),new jl({index:49,name:"F.Fab",type:"user"})),r.definitions=a,t.layers=r,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},aEi=class extends t0{_step(){const{kicadPcb:t}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");this.ctx.pcbNetMap=new Map;const A=new Map,e=this.ctx.db.source_net?.list()??[];for(const r of e){const a=r.subcircuit_connectivity_map_key||r.source_net_id;if(!a)continue;const g=r.name||r.source_net_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}const i=this.ctx.db.source_trace?.list()??[];for(const r of i){let a=r.subcircuit_connectivity_map_key;if(!a&&r.connected_source_net_ids?.length)for(const g of r.connected_source_net_ids){const c=this.ctx.db.source_net?.get(g);if(c?.subcircuit_connectivity_map_key&&c.subcircuit_connectivity_map_key.length>0){a=c.subcircuit_connectivity_map_key;break}}if(a&&!A.has(a)){const g=r.display_name||r.source_trace_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}}const n=Array.from(A.entries()).sort((r,a)=>r[0].localeCompare(a[0])),o=[];o.push(new Az(0,""));let s=1;for(const[r,a]of n){const g=new Az(s,a);o.push(g);const c={id:s,name:a};this.ctx.pcbNetMap.set(r,c),s++}t.nets=o,this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function gEi(t){let A=0;for(let i=0;i<t.length;i++){const n=t.charCodeAt(i);A=(A<<5)-A+n,A=A&A}let e="";for(let i=0;i<4;i++){let n=A;for(let o=0;o<t.length;o++)n=(n<<5)-n+t.charCodeAt(o)+i*31,n=n&n;e+=Math.abs(n).toString(16).padStart(8,"0")}return e}function Bd(t){const A=gEi(t);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}var Nme="https://modelcdn.tscircuit.com/jscad_models",cEi=20240108,IEi="pcbnew",lEi="8.0";function kxA(t){const A=t.split(/[/\\]/),e=A[A.length-1]||t;return e.split("?")[0]||e}var BEi=class extends t0{classifyFootprints(){const t=new Set,A=new Map,e=this.ctx.db.cad_component?.list()??[],i=this.ctx.db.source_component;for(const n of e){const o=n.source_component_id?i?.get(n.source_component_id):null;if(!o)continue;const s=A5(o,n);if(n.footprinter_string)A.set(s,n.footprinter_string);else{t.add(s);const r=this.ctx.circuitJson.find(a=>a.type==="pcb_component"&&a.source_component_id===n.source_component_id);r&&r.type==="pcb_component"&&r.metadata?.kicad_footprint?.footprintName&&t.add(r.metadata.kicad_footprint.footprintName)}}return{customFootprintNames:t,footprinterStrings:A}}_step(){const t=this.ctx.kicadPcbString,A=this.ctx.fpLibraryName??"tscircuit";if(!t)throw new Error("PCB content not available. Run GenerateKicadSchAndPcbStage first.");const{customFootprintNames:e,footprinterStrings:i}=this.classifyFootprints(),n=new Map;try{const s=bme(t).find(a=>a instanceof bxA);if(!s){this.ctx.footprintEntries=[],this.finished=!0;return}const r=s.footprints??[];for(const a of r){const g=this.sanitizeFootprint({footprint:a,fpLibraryName:A,customFootprintNames:e,footprinterStrings:i});n.has(g.footprintName)||n.set(g.footprintName,g)}}catch(o){console.warn("Failed to parse PCB for footprint extraction:",o)}this.ctx.footprintEntries=Array.from(n.values()),this.finished=!0}sanitizeFootprint({footprint:t,fpLibraryName:A,customFootprintNames:e,footprinterStrings:i}){const o=(t.libraryLink??"footprint").split(":"),s=(o.length>1?o[1]:o[0])?.replace(/[\\\/]/g,"-").trim()||"footprint",r=!e.has(s);if(t.libraryLink=s,t.position=gc.from([0,0,0]),t.locked=!1,t.placed=!1,t.version=cEi,t.generator=IEi,t.generatorVersion=lEi,t.descr||(t.descr=""),t.tags||(t.tags=""),t.embeddedFonts||(t.embeddedFonts=new jM(!1)),!t.attr){const p=new p1A,y=(t.fpPads??[]).map(w=>w.padType);y.some(w=>w.includes("thru_hole"))?p.type="through_hole":y.some(w=>w.includes("smd"))&&(p.type="smd"),t.attr=p}t.uuid=void 0,t.path=void 0,t.sheetfile=void 0,t.sheetname=void 0;const a=new Zp;a.size={width:1.27,height:1.27},a.thickness=.15;const g=new Wp({font:a}),c=t.fpPads??[];let I=0,l=0;for(const p of c){const y=p.at,w=p.size;if(y&&w){const D=y.y??0,x=w.height??0,_=D-x/2,S=D+x/2;I=Math.min(I,_),l=Math.max(l,S)}}const B=I-.5,C=l+.5;t.properties=[new F1({key:"Reference",value:"REF**",position:[0,B,0],layer:"F.SilkS",uuid:Bd(`${s}-property-Reference`),effects:g}),new F1({key:"Value",value:"Val**",position:[0,C,0],layer:"F.Fab",uuid:Bd(`${s}-property-Value`),effects:g}),new F1({key:"Datasheet",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:Bd(`${s}-property-Datasheet`),effects:g}),new F1({key:"Description",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:Bd(`${s}-property-Description`),effects:g})];const Q=t.fpTexts??[];for(const p of Q)p.uuid=void 0,p.type==="reference"?p.text="REF**":p.type==="value"&&p.text.trim().length===0&&(p.text=s);t.fpTexts=Q;const h=t.fpPads??[];for(let p=0;p<h.length;p++){const y=h[p];y&&(y.uuid=Bd(`${s}-pad-${y.number??p}`),y.net=void 0)}t.fpPads=h;const E=t.models??[],u=[],d=[];for(const p of E)if(p.path){const y=kxA(p.path),x=`../../3dmodels/${p.path.startsWith("http://modelcdn.tscircuit.com")||p.path.startsWith("https://modelcdn.tscircuit.com")?"tscircuit_builtin":A}.3dshapes/${y}`,_=new $3(x);p.offset&&(_.offset=p.offset),p.scale&&(_.scale=p.scale),p.rotate&&(_.rotate=p.rotate),u.push(_),d.push(p.path.split("?")[0]??p.path)}if(u.length===0){const p=i.get(s);if(p){const y=`${Nme}/${p}.step`,D=`../../3dmodels/tscircuit_builtin.3dshapes/${kxA(y)}`;u.push(new $3(D)),d.push(y)}}return t.models=u,{footprintName:s,kicadModString:t.getString(),model3dSourcePaths:d,isBuiltin:r}}getOutput(){return this.ctx.libraryOutput}};function iz(t){const A=new Zp;return t?.font?.size?A.size={width:Number(t.font.size.x),height:Number(t.font.size.y)}:A.size={width:1.27,height:1.27},t?.font?.thickness!==void 0?A.thickness=Number(t.font.thickness):A.thickness=.15,new Wp({font:A})}function CEi(t,A,e){if(A.properties){const i=[],n=A.properties.Reference;i.push(new F1({key:"Reference",value:n?.value??e,position:n?.at?[Number(n.at.x),Number(n.at.y),Number(n.at.rotation??0)]:[0,-3,0],layer:n?.layer??"F.SilkS",uuid:Bd(`${e}-property-Reference`),effects:iz(n?.effects),hidden:n?.hide}));const o=A.properties.Value,s=o?.value??A.footprintName??"";i.push(new F1({key:"Value",value:s,position:o?.at?[Number(o.at.x),Number(o.at.y),Number(o.at.rotation??0)]:[0,3,0],layer:o?.layer??"F.Fab",uuid:Bd(`${e}-property-Value`),effects:iz(o?.effects),hidden:o?.hide}));const r=A.properties.Datasheet;i.push(new F1({key:"Datasheet",value:r?.value??"",position:r?.at?[Number(r.at.x),Number(r.at.y),Number(r.at.rotation??0)]:[0,0,0],layer:r?.layer??"F.Fab",uuid:Bd(`${e}-property-Datasheet`),effects:iz(r?.effects),hidden:r?.hide??!0}));const a=A.properties.Description;i.push(new F1({key:"Description",value:a?.value??"",position:a?.at?[Number(a.at.x),Number(a.at.y),Number(a.at.rotation??0)]:[0,0,0],layer:a?.layer??"F.Fab",uuid:Bd(`${e}-property-Description`),effects:iz(a?.effects),hidden:a?.hide??!0})),t.properties=i}if(A.attributes&&(t.attr||(t.attr=new p1A),A.attributes.through_hole?t.attr.type="through_hole":A.attributes.smd&&(t.attr.type="smd"),A.attributes.exclude_from_pos_files!==void 0&&(t.attr.excludeFromPosFiles=A.attributes.exclude_from_pos_files),A.attributes.exclude_from_bom!==void 0&&(t.attr.excludeFromBom=A.attributes.exclude_from_bom)),A.footprintName&&(t.libraryLink=A.footprintName),A.layer&&(t.layer=A.layer),A.embeddedFonts!==void 0&&(t.embeddedFonts=new jM(A.embeddedFonts)),A.model){const i=new $3(A.model.path);A.model.offset&&(i.offset={x:Number(A.model.offset.x),y:Number(A.model.offset.y),z:Number(A.model.offset.z)}),A.model.scale&&(i.scale={x:Number(A.model.scale.x),y:Number(A.model.scale.y),z:Number(A.model.scale.z)}),A.model.rotate&&(i.rotate={x:Number(A.model.rotate.x),y:Number(A.model.rotate.y),z:Number(A.model.rotate.z)});const n=t.models||[];t.models=[i,...n]}}function QEi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.SilkS",bottom:"B.SilkS"}[i.layer]||i.layer||"F.SilkS",a=new i2A({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new v1,fill:!1});a.stroke&&(a.stroke.width=i.stroke_width||.05,a.stroke.type="default"),e.push(a)}return e}function hEi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",a=new i2A({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new v1,fill:!1});a.stroke&&(a.stroke.width=.05,a.stroke.type="default"),e.push(a)}return e}function EEi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.Fab",bottom:"B.Fab"}[i.layer]||i.layer||"F.Fab",c=new Kj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new v1,fill:!1});c.stroke&&(c.stroke.width=i.stroke_width||.1,c.stroke.type="default"),e.push(c)}return e}function uEi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,a="F.Fab",g=new Kj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:a,stroke:new v1,fill:!1});g.stroke&&(g.stroke.width=i.stroke_width||.1,g.stroke.type="default"),e.push(g)}return e}function dEi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",c=new Kj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new v1,fill:!1});c.stroke&&(c.stroke.width=.05,c.stroke.type="default"),e.push(c)}return e}function pEi(t,A){const e=[];for(const i of t){if(!i.outline||i.outline.length<2)continue;const o={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",s=i.outline.map(g=>{const c=g.x-A.x,I=-(g.y-A.y);return new sh(c,I)}),r=new eye;r.points=new sQ(s),r.layer=o,r.fill=!1;const a=new v1;a.width=.05,a.type="default",r.stroke=a,e.push(r)}return e}function fEi({textElement:t,componentCenter:A,componentRotation:e=0}){if(!t.text||!t.anchor_position)return null;const i=t.anchor_position.x-A.x,n=-(t.anchor_position.y-A.y),o=e!==0?Tl(e*Math.PI/180):ba(),s=Ce(o,{x:i,y:n}),r={x:s.x,y:s.y},g={top:"F.SilkS",bottom:"B.SilkS"}[t.layer]||t.layer||"F.SilkS",c=(t.font_size||1)/1.5,I=new Zp;I.size={width:c,height:c};const l=new Wp({font:I}),B=t.ccw_rotation||0;return new W1A({type:"user",text:t.text,position:{x:r.x,y:r.y,angle:B},layer:g,effects:l})}function yEi(t,A,e,i){const n=[];for(const o of t){const s=fEi({textElement:o,componentCenter:A,componentRotation:e});s&&(i&&o.text===i&&(s.type="reference"),n.push(s))}return n}function mEi(t,A,e){const i=[];for(const n of t){const o=n.anchor_position.x-A.x,s=-(n.anchor_position.y-A.y),r=e!==0?Tl(e*Math.PI/180):ba(),a=Ce(r,{x:o,y:s}),g=n.font_size||1,c=new Zp;c.size={width:g,height:g};const I=new Wp({font:c}),l=new W1A({type:"user",text:n.text,position:{x:a.x,y:a.y,angle:0},layer:"F.Fab",effects:I});i.push(l)}return i}function wEi(t,A,e){const i=[],n=t.model_step_url||t.model_wrl_url;if(!n)return i;const o=new $3(n);if(t.position){const s=e?.boardLayerZOffset??0;o.offset={x:(t.position.x||0)-A.x,y:(t.position.y||0)-A.y,z:(t.position.z||0)-s}}if(t.rotation&&(o.rotate={x:t.rotation.x||0,y:t.rotation.y||0,z:t.rotation.z||0}),t.model_unit_to_mm_scale_factor){const s=t.model_unit_to_mm_scale_factor;o.scale={x:s,y:s,z:s}}return i.push(o),i}function DEi({pcbPad:t,componentCenter:A,padNumber:e,componentRotation:i=0,netInfo:n,componentId:o}){let s,r;if("x"in t&&"y"in t)s=t.x,r=t.y;else if("points"in t&&Array.isArray(t.points)){const u=t.points;s=u.reduce((d,p)=>d+p.x,0)/u.length,r=u.reduce((d,p)=>d+p.y,0)/u.length}else throw new Error("Pad must have either x/y coordinates or points array");const a=An(i!==0?Tl(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},$a(1,-1),on(-A.x,-A.y)),g=Ce(a,{x:s,y:r}),I={top:"F.Cu",bottom:"B.Cu"}[t.layer]||"F.Cu";let l,B,C,Q;if(t.shape==="circle")l="circle",B=["radius"in t?t.radius*2:.5,"radius"in t?t.radius*2:.5];else if(t.shape==="polygon"&&"points"in t){const u=t.points,d=An($a(1,-1),on(-s,-r)),p=u.map(w=>{const D=Ce(d,{x:w.x,y:w.y});return new sh(D.x,D.y)}),y=new T1A;y.contours=[new sQ(p)],y.width=0,y.filled=!0,Q=new Ufe,Q.addGraphic(y),l="custom",C=new ffe,C.anchor="circle",B=[.2,.2]}else l="rect",B=["width"in t?t.width:.5,"height"in t?t.height:.5];const h=`pad:${o}:${e}:${g.x},${g.y}`,E=new Pj({number:String(e),padType:"smd",shape:l,at:[g.x,g.y,0],size:B,layers:[`${I}`,`${I==="F.Cu"?"F":"B"}.Paste`,`${I==="F.Cu"?"F":"B"}.Mask`],uuid:Bd(h)});return C&&(E.options=C),Q&&(E.primitives=Q),n&&(E.net=new G1A(n.id,n.name)),E}function xEi(t,A,e,i,n,o){const s=[];let r=n;for(const a of t){const g=o(a.pcb_port_id),c=DEi({pcbPad:a,componentCenter:A,padNumber:r,componentRotation:e,netInfo:g,componentId:i});s.push(c),r++}return{pads:s,nextPadNumber:r}}function SEi({platedHole:t,componentCenter:A,padNumber:e,componentRotation:i=0,netInfo:n,componentId:o}){if(!("x"in t&&"y"in t))return null;const s=t.x-A.x,r=-(t.y-A.y),a=i!==0?Tl(i*Math.PI/180):ba(),g=Ce(a,{x:s,y:r});let c="circle",I,l,B=0;const C="hole_offset_x"in t||"hole_offset_y"in t;let Q;if(C){const u={x:t.hole_offset_x??0,y:t.hole_offset_y??0};(u.x!==0||u.y!==0)&&(Q=Ce(a,{x:-u.x,y:u.y}))}t.shape==="circle"?(c="circle",I=[t.outer_diameter,t.outer_diameter],l=new M1({diameter:t.hole_diameter,offset:Q})):t.shape==="pill"||t.shape==="oval"?(c="oval",I=[t.outer_width,t.outer_height],l=new M1({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q})):t.shape==="pill_hole_with_rect_pad"?(c="rect",I=[t.rect_pad_width,t.rect_pad_height],l=new M1({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q})):t.shape==="circular_hole_with_rect_pad"?(c="rect",I=[t.rect_pad_width,t.rect_pad_height],l=new M1({diameter:t.hole_diameter,offset:Q})):t.shape==="rotated_pill_hole_with_rect_pad"?(c="rect",I=[t.rect_pad_width,t.rect_pad_height],l=new M1({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q}),B=t.rect_ccw_rotation||0):(c="circle",I=[1.6,1.6],l=new M1({diameter:.8,offset:Q}));const h=`thruhole:${o}:${e}:${g.x},${g.y}`,E=new Pj({number:String(e),padType:"thru_hole",shape:c,at:[g.x,g.y,B],size:I,drill:l,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:Bd(h)});return n&&(E.net=new G1A(n.id,n.name)),E}function bEi(t,A,e,i,n,o){const s=[];let r=n;for(const a of t){const g=o(a.pcb_port_id),c=SEi({platedHole:a,componentCenter:A,padNumber:r,componentRotation:e,netInfo:g,componentId:i});c&&(s.push(c),r++)}return{pads:s,nextPadNumber:r}}function _Ei({pcbHole:t,componentCenter:A,componentRotation:e=0}){if(!("x"in t&&"y"in t))return null;const i=t.x-A.x,n=-(t.y-A.y),o=e!==0?Tl(e*Math.PI/180):ba(),s=Ce(o,{x:i,y:n});let r="circle",a,g;if(t.hole_shape==="circle"){r="circle";const c=t.hole_diameter;a=[c,c],g=new M1({diameter:c})}else if(t.hole_shape==="oval"){r="oval";const c=t.hole_width,I=t.hole_height;a=[c,I],g=new M1({oval:!0,diameter:c,width:I})}else{r="circle";const c="hole_diameter"in t?t.hole_diameter:1;a=[c,c],g=new M1({diameter:c})}return new Pj({number:"",padType:"np_thru_hole",shape:r,at:[s.x,s.y,0],size:a,drill:g,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:crypto.randomUUID()})}function Gme(t,A,e){const i=[];for(const n of t){const o=_Ei({pcbHole:n,componentCenter:A,componentRotation:e});o&&i.push(o)}return i}var kEi=class extends t0{componentsProcessed=0;pcbComponents=[];includeBuiltin3dModels;getNetInfoForPcbPort(t){if(!t)return;const A=this.ctx.db.pcb_port?.get(t);if(!A)return;const e=A.source_port_id;if(!e)return;const i=this.ctx.db.source_port?.get(e);if(!i)return;const n=i.subcircuit_connectivity_map_key;if(n)return this.ctx.pcbNetMap?.get(n)}getCadComponentForPcbComponent(t){return(this.ctx.db.cad_component?.list()||[]).find(e=>e.pcb_component_id===t)}constructor(t,A,e){super(t,A),this.pcbComponents=this.ctx.db.pcb_component.list(),this.includeBuiltin3dModels=e?.includeBuiltin3dModels??!1}_step(){const{kicadPcb:t,c2kMatPcb:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.componentsProcessed>=this.pcbComponents.length){this.finished=!0;return}const e=this.pcbComponents[this.componentsProcessed],i=e.source_component_id?this.ctx.db.source_component.get(e.source_component_id):null,n=this.getCadComponentForPcbComponent(e.pcb_component_id),o=i?A5(i,n):"Unknown",s=Ce(A,{x:e.center.x,y:e.center.y}),r=`footprint:${e.pcb_component_id}:${s.x},${s.y}`,a=new Zj({libraryLink:`tscircuit:${o}`,layer:"F.Cu",at:[s.x,s.y,e.rotation||0],uuid:Bd(r)}),g=a.fpTexts,c=this.ctx.db.pcb_silkscreen_text?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[];g.push(...yEi(c,e.center,e.rotation||0,i?.name));const I=this.ctx.db.pcb_note_text?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[];g.push(...mEi(I,e.center,e.rotation||0)),a.fpTexts=g;const l=a.fpPads,B=q=>this.getNetInfoForPcbPort(q),C=this.ctx.db.pcb_smtpad?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[],{pads:Q,nextPadNumber:h}=xEi(C,e.center,e.rotation||0,e.pcb_component_id,1,B);l.push(...Q);const E=this.ctx.db.pcb_plated_hole?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[],{pads:u}=bEi(E,e.center,e.rotation||0,e.pcb_component_id,h,B);l.push(...u);const d=this.ctx.db.pcb_hole?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[],p=Gme(d,e.center,e.rotation||0);l.push(...p),a.fpPads=l;const y=this.ctx.db.pcb_silkscreen_circle?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[],w=a.fpCircles??[];w.push(...QEi(y,e.center));const D=this.ctx.db.pcb_courtyard_circle?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[];w.push(...hEi(D,e.center)),a.fpCircles=w;const x=this.ctx.db.pcb_fabrication_note_rect?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[],_=a.fpRects??[];_.push(...EEi(x,e.center));const S=this.ctx.db.pcb_note_rect?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[];_.push(...uEi(S,e.center));const N=this.ctx.db.pcb_courtyard_rect?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[];_.push(...dEi(N,e.center)),a.fpRects=_;const F=this.ctx.db.pcb_courtyard_outline?.list().filter(q=>q.pcb_component_id===e.pcb_component_id)||[],L=pEi(F,e.center);if(L.length>0&&(a.fpPolys=L),n){const Z=this.ctx.db.pcb_board?.list()[0]?.thickness??0,X=e.layer==="bottom"?-(Z/2):Z/2,eA=wEi(n,e.center,{boardLayerZOffset:X}),gA="${KIPRJMOD}/3dmodels";if(eA.length>0)this.includeBuiltin3dModels?a.models=eA.map(tA=>{if(!tA.path)return tA;const iA=kxA(tA.path),aA=tA.path.startsWith("http://modelcdn.tscircuit.com")||tA.path.startsWith("https://modelcdn.tscircuit.com")?"tscircuit_builtin":this.ctx.projectName??iA.replace(/\.[^.]+$/,""),EA=new $3(`${gA}/${aA}.3dshapes/${iA}`);tA.offset&&(EA.offset=tA.offset),tA.scale&&(EA.scale=tA.scale),tA.rotate&&(EA.rotate=tA.rotate);const SA=tA.path?.split("?")[0];return SA&&!this.ctx.pcbModel3dSourcePaths?.includes(SA)&&this.ctx.pcbModel3dSourcePaths?.push(SA),EA}):a.models=eA;else if(n.footprinter_string&&this.includeBuiltin3dModels){const{footprinter_string:tA}=n,iA=`${gA}/tscircuit_builtin.3dshapes/${tA}.step`;a.models=[new $3(iA)];const sA=`${Nme}/${tA}.step`;this.ctx.pcbModel3dSourcePaths?.includes(sA)||this.ctx.pcbModel3dSourcePaths?.push(sA)}}const Y=e.metadata?.kicad_footprint;Y&&i?.name&&CEi(a,Y,i.name);const J=t.footprints;J.push(a),t.footprints=J,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},vEi={top:"F.Cu",bottom:"B.Cu",inner1:"In1.Cu",inner2:"In2.Cu",inner3:"In3.Cu",inner4:"In4.Cu",inner5:"In5.Cu",inner6:"In6.Cu"};function FEi(t){return t&&(vEi[t]||t)||"F.Cu"}function MEi(t){const A=["F.Cu"];for(let e=1;e<t-1;e++)A.push(`In${e}.Cu`);return A.push("B.Cu"),A}var REi=class extends t0{tracesProcessed=0;pcbTraces=[];constructor(t,A){super(t,A),this.pcbTraces=this.ctx.db.pcb_trace.list()}_step(){const{kicadPcb:t,c2kMatPcb:A,pcbNetMap:e}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.tracesProcessed>=this.pcbTraces.length){this.finished=!0;return}const i=this.pcbTraces[this.tracesProcessed];if(!i.route||i.route.length<2){this.tracesProcessed++;return}let n=i.route[0]?.layer;for(let o=0;o<i.route.length-1;o++){const s=i.route[o],r=i.route[o+1],a=Ce(A,{x:s.x,y:s.y}),g=Ce(A,{x:r.x,y:r.y});let c;if(e){let h=i.subcircuit_connectivity_map_key;if(!h&&i.source_trace_id){const E=this.ctx.db.source_trace?.get(i.source_trace_id);if(E&&(h=E.subcircuit_connectivity_map_key,!h&&E.connected_source_net_ids?.length))for(const u of E.connected_source_net_ids){const d=this.ctx.db.source_net?.get(u);if(d?.subcircuit_connectivity_map_key){h=d.subcircuit_connectivity_map_key;break}}}if(!h&&typeof i.connection_name=="string"){const E=this.ctx.db.source_net?.get(i.connection_name);E?.subcircuit_connectivity_map_key&&(h=E.subcircuit_connectivity_map_key)}h&&(c=e.get(h))}const I=s.layer??r.layer??n,l=FEi(I),B=`segment:${a.x},${a.y}:${g.x},${g.y}:${l}:${c?.id??0}`,C=new v2A({start:{x:a.x,y:a.y},end:{x:g.x,y:g.y},layer:l,width:i.width||.25,net:new zj(c?.id??0),uuid:Bd(B)}),Q=t.segments;Q.push(C),t.segments=Q,s.layer&&(n=s.layer),r.layer&&(n=r.layer)}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},NEi=class extends t0{viasProcessed=0;pcbVias=[];constructor(t,A){super(t,A),this.pcbVias=this.ctx.db.pcb_via?.list()||[]}_step(){const{kicadPcb:t,c2kMatPcb:A,pcbNetMap:e}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.viasProcessed>=this.pcbVias.length){this.finished=!0;return}const i=this.pcbVias[this.viasProcessed],n=Ce(A,{x:i.x,y:i.y});let o;if(e){let I=i.subcircuit_connectivity_map_key;if(!I&&i.pcb_trace_id){const l=this.ctx.db.pcb_trace?.get(i.pcb_trace_id);if(l&&("subcircuit_connectivity_map_key"in l&&(I=l.subcircuit_connectivity_map_key),!I&&l.source_trace_id)){const B=this.ctx.db.source_trace?.get(l.source_trace_id);if(B&&("subcircuit_connectivity_map_key"in B&&(I=B.subcircuit_connectivity_map_key),!I&&B.connected_source_net_ids?.length))for(const C of B.connected_source_net_ids){const Q=this.ctx.db.source_net?.get(C);if(Q?.subcircuit_connectivity_map_key){I=Q.subcircuit_connectivity_map_key;break}}}}if(!I&&i.connection_name){const l=this.ctx.db.source_net?.get(i.connection_name);l?.subcircuit_connectivity_map_key&&(I=l.subcircuit_connectivity_map_key)}I&&(o=e.get(I))}const s=this.ctx.numLayers??2,r=i.layers?i.layers.map(I=>I==="top"?"F.Cu":I==="bottom"?"B.Cu":`In${I.replace("inner","")}.Cu`):MEi(s),a=`via:${n.x},${n.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${o?.id??0}`,g=new SxA({at:[n.x,n.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:r,net:new xxA(o?.id??0),uuid:Bd(a)}),c=t.vias;c.push(g),t.vias=c,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}},GEi=class extends t0{holesProcessed=0;standaloneHoles=[];constructor(t,A){super(t,A),this.standaloneHoles=this.ctx.db.pcb_hole.list().filter(e=>!e.pcb_component_id)}_step(){const{kicadPcb:t,c2kMatPcb:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.holesProcessed>=this.standaloneHoles.length){this.finished=!0;return}const e=this.standaloneHoles[this.holesProcessed];if(!e){this.holesProcessed++;return}const i=Ce(A,{x:0,y:0}),n=`standalone_hole:${e.pcb_hole_id}:${e.x},${e.y}`,o=new Zj({libraryLink:"tscircuit:MountingHole",layer:"F.Cu",at:[i.x,i.y,0],uuid:Bd(n)}),r=Gme([e],{x:0,y:0},0);if(r.length>0){o.fpPads=r;const a=t.footprints;a.push(o),t.footprints=a}this.holesProcessed++}getOutput(){return this.ctx.kicadPcb}};function LEi({textElement:t,c2kMatPcb:A}){if(!t.text||!t.anchor_position)return null;const e=Ce(A,{x:t.anchor_position.x,y:t.anchor_position.y}),n={top:"F.Fab",bottom:"B.Fab"}[t.layer]||t.layer||"F.Fab",o=(t.font_size||1)/1.5,s=new Zp;s.size={width:o,height:o};const r=new b6,a=t.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new Wp({font:s});a!=="center"&&(g.justify=r);const c=new gc([e.x,e.y,0]),I=new jj({text:t.text,layer:n,effects:g});return I.position=c,I}function UEi({textElement:t,c2kMatPcb:A}){if(!t.text||!t.anchor_position)return null;const e=Ce(A,{x:t.anchor_position.x,y:t.anchor_position.y}),n={top:"F.SilkS",bottom:"B.SilkS"}[t.layer]||t.layer||"F.SilkS",o=(t.font_size||1)/1.5,s=new Zp;s.size={width:o,height:o};const r=new b6,a=t.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new Wp({font:s});a!=="center"&&(g.justify=r);const c=t.ccw_rotation||0,I=new gc([e.x,e.y,c]),l=new jj({text:t.text,layer:n,effects:g});return l.position=I,l}var HEi=class extends t0{_step(){const{kicadPcb:t,c2kMatPcb:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");const e=this.ctx.db.pcb_silkscreen_path?.list()||[];for(const s of e)if(!(!s.route||s.route.length<2))for(let r=0;r<s.route.length-1;r++){const a=s.route[r],g=s.route[r+1];if(!a||!g)continue;const c=Ce(A,{x:a.x,y:a.y}),I=Ce(A,{x:g.x,y:g.y}),B={top:"F.SilkS",bottom:"B.SilkS"}[s.layer]||s.layer||"F.SilkS",C=new Vj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:B,width:s.stroke_width||.15}),Q=t.graphicLines;Q.push(C),t.graphicLines=Q}const i=this.ctx.db.pcb_silkscreen_text?.list().filter(s=>!s.pcb_component_id)||[];for(const s of i){const r=UEi({textElement:s,c2kMatPcb:A});if(r){const a=t.graphicTexts;a.push(r),t.graphicTexts=a}}const n=this.ctx.db.pcb_fabrication_note_text?.list()||[];for(const s of n){const r=LEi({textElement:s,c2kMatPcb:A});if(r){const a=t.graphicTexts;a.push(r),t.graphicTexts=a}}const o=this.ctx.db.pcb_board?.list()||[];if(o.length>0){const s=o[0];if(!s){this.finished=!0;return}let r;if(s.outline&&s.outline.length>0)r=s.outline;else{const g=s.width?s.width/2:0,c=s.height?s.height/2:0;r=[{x:s.center.x-g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y+c},{x:s.center.x-g,y:s.center.y+c}]}const a=r.map(g=>Ce(A,g));for(let g=0;g<a.length;g++){const c=a[g],I=a[(g+1)%a.length];if(!c||!I)continue;const l=new Vj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:"Edge.Cuts",width:.1}),B=t.graphicLines;B.push(l),t.graphicLines=B}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},Lme=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(t,A){this.ctx={db:Ua(t),circuitJson:t,kicadPcb:new bxA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:An(on(100,100),$a(1,-1)),projectName:A?.projectName,pcbModel3dSourcePaths:[]},this.pipeline=[new rEi(t,this.ctx),new aEi(t,this.ctx),new kEi(t,this.ctx,{includeBuiltin3dModels:A?.includeBuiltin3dModels}),new REi(t,this.ctx),new NEi(t,this.ctx),new GEi(t,this.ctx),new HEi(t,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadPcb}getOutputString(){return this.ctx.kicadPcb.getString()}getModel3dSourcePaths(){return this.ctx.pcbModel3dSourcePaths??[]}},YEi=class{ctx;project;constructor(t,A={}){const e=A.projectName??t?.project?.name??"circuit-json-project",i=A.schematicFilename??`${e}.kicad_sch`,n=A.pcbFilename??`${e}.kicad_pcb`,o=new Date().toISOString();this.ctx={db:Ua(t),circuitJson:t},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:e,created:o,modified:o},meta:{version:1},text_variables:{},libraries:{pinned_symbol_libs:[],pinned_footprint_libs:[]},boards:[],cvpcb:{meta:{version:0}},erc:{meta:{version:0},erc_exclusions:[]},net_settings:{meta:{version:1},last_net_id:0,classes:[]},pcbnew:{page_layout_descr_file:"",last_paths:{}},schematic:{meta:{version:1},page_layout_descr_file:"",last_opened_files:[i]},board:{meta:{version:1},last_opened_board:n},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
|
|
5830
5830
|
`}},JEi=class extends t0{_step(){const t=new Rme(this.ctx.circuitJson);t.runUntilFinished(),this.ctx.kicadSchString=t.getOutputString();const A=new Lme(this.ctx.circuitJson);A.runUntilFinished(),this.ctx.kicadPcbString=A.getOutputString(),this.finished=!0}getOutput(){return this.ctx.libraryOutput}},TEi=class extends t0{isCustomSymbol(t){return t?.startsWith("Custom:")??!1}_step(){const t=this.ctx.kicadSchString,A=this.ctx.fpLibraryName??"tscircuit";if(!t)throw new Error("Schematic content not available. Run GenerateKicadSchAndPcbStage first.");const e=new Map;try{const n=bme(t).find(r=>r instanceof d1A);if(!n){this.ctx.symbolEntries=[],this.finished=!0;return}const o=n.libSymbols;if(!o){this.ctx.symbolEntries=[],this.finished=!0;return}const s=o.symbols??[];for(const r of s){const a=this.isCustomSymbol(r.libraryId),g=this.sanitizeSymbolName(r.libraryId);e.has(g)||(r.libraryId=g,this.updateFootprintProperty(r,A),a||this.snapPinPositionsToGrid(r),e.set(g,{symbolName:g,symbol:r,isBuiltin:!a}))}}catch(i){console.warn("Failed to parse schematic for symbol extraction:",i)}this.ctx.symbolEntries=Array.from(e.values()),this.finished=!0}updateFootprintProperty(t,A){const e=t.properties??[];for(const i of e)if(i.key==="Footprint"&&i.value){const n=i.value.split(":");n.length>1?i.value=`${A}:${n[1]}`:i.value.trim()&&(i.value=`${A}:${i.value}`)}}sanitizeSymbolName(t){if(!t)return"symbol";const A=t.split(":");return(A.length>1?A[1]:A[0])?.replace(/[\\\/]/g,"-").trim()||"symbol"}snapPinPositionsToGrid(t){for(const e of t.subSymbols??[]){for(const i of e.pins??[])i.at&&(i.at.x=Math.round(i.at.x/1.27)*1.27,i.at.y=Math.round(i.at.y/1.27)*1.27);for(const i of e.polylines??[])if(i.points?.points)for(const n of i.points.points)"x"in n&&"y"in n&&(n.x=Math.round(n.x/1.27)*1.27,n.y=Math.round(n.y/1.27)*1.27)}}getOutput(){return this.ctx.libraryOutput}},PEi=20211014,KEi="circuit-json-to-kicad",qEi=class extends t0{_step(){const t=this.ctx.symbolEntries??[],A=this.generateSymbolLibrary(t);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.kicadSymString=A,this.finished=!0}generateSymbolLibrary(t){return new Zpe({version:PEi,generator:KEi,symbols:t.map(e=>e.symbol)}).getString()}getOutput(){return this.ctx.libraryOutput}},OEi=class extends t0{_step(){const t=this.ctx.libraryName??"tscircuit",A=this.ctx.fpLibraryName??"tscircuit",e=this.ctx.footprintEntries??[],i=this.ctx.symbolEntries??[],n=new Set;for(const r of e)for(const a of r.model3dSourcePaths)n.add(a);const o=this.generateFpLibTable(A),s=this.generateSymLibTable(t);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.symbols=i,this.ctx.libraryOutput.footprints=e,this.ctx.libraryOutput.fpLibTableString=o,this.ctx.libraryOutput.symLibTableString=s,this.ctx.libraryOutput.model3dSourcePaths=Array.from(n),this.finished=!0}generateFpLibTable(t){return`(fp_lib_table
|
|
5831
5831
|
(version 7)
|
|
5832
5832
|
(lib (name "${t}") (type "KiCad") (uri "\${KIPRJMOD}/${t}.pretty") (options "") (descr "Generated by circuit-json-to-kicad"))
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tscircuit/runframe",
|
|
3
3
|
"main": "dist/preview.js",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.1764",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./dist/preview.js",
|
|
8
8
|
"./preview": "./dist/preview.js",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"chokidar-cli": "^3.0.0",
|
|
64
64
|
"circuit-json-to-bom-csv": "^0.0.8",
|
|
65
65
|
"circuit-json-to-gerber": "^0.0.48",
|
|
66
|
-
"circuit-json-to-kicad": "^0.0.
|
|
66
|
+
"circuit-json-to-kicad": "^0.0.91",
|
|
67
67
|
"circuit-json-to-lbrn": "^0.0.4",
|
|
68
68
|
"circuit-json-to-pnp-csv": "^0.0.7",
|
|
69
69
|
"circuit-json-to-step": "^0.0.18",
|