@tscircuit/fake-snippets 0.0.119 → 0.0.121
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/bun-pver-release.yml +29 -4
- package/bun-tests/fake-snippets-api/routes/bug_reports/create.test.ts +37 -0
- package/bun-tests/fake-snippets-api/routes/bug_reports/upload_file.test.ts +89 -0
- package/bun.lock +2 -2
- package/dist/assets/404-CnNkOMw-.js +1 -0
- package/dist/assets/Analytics-DIw7l2gi.js +84 -0
- package/dist/assets/BuildsList-CeqVVhbz.js +1 -0
- package/dist/assets/CodeAndPreview-Dycd0s15.js +722 -0
- package/dist/assets/DownloadButtonAndMenu-OIUhbKkj.js +194 -0
- package/dist/assets/FileSaver.min-BDsOlqKl.js +1 -0
- package/dist/assets/Footer-DU-HdqGk.js +1 -0
- package/dist/assets/GithubAvatarWithFallback-CQhrBiKP.js +6 -0
- package/dist/assets/Header-CI4GZVOv.js +1 -0
- package/dist/assets/Header2-CrMDmo3P.js +5 -0
- package/dist/assets/NotFound-DaXtEPsC.js +1 -0
- package/dist/assets/OrganizationCard-Bs2dw-AL.js +1 -0
- package/dist/assets/PackageBreadcrumb-DpOpPbGc.js +6 -0
- package/dist/assets/PackageCard-ejE2dLlA.js +16 -0
- package/dist/assets/PackageSearchResults-BI3Rtmr2.js +1 -0
- package/dist/assets/ProfileRouter-4xNgtXr5.js +6 -0
- package/dist/assets/alert-dialog-DrOB4Tui.js +1 -0
- package/dist/assets/authorize-D-5R3QHA.js +16 -0
- package/dist/assets/badge-Bk-k6kyg.js +1 -0
- package/dist/assets/card-CzXDit7x.js +1 -0
- package/dist/assets/circle-alert-Du9-4of0.js +6 -0
- package/dist/assets/circle-check-big-KaRyRsht.js +6 -0
- package/dist/assets/cpu-BnvjzmIA.js +6 -0
- package/dist/assets/create-organization-BHNFvE7B.js +1 -0
- package/dist/assets/dashboard-DDH4V91X.js +11 -0
- package/dist/assets/datasheet-DqKtWt-O.js +1 -0
- package/dist/assets/datasheets-4W6pEMf3.js +1 -0
- package/dist/assets/dev-login-CbHdDthp.js +1 -0
- package/dist/assets/editor-bqg9Yv91.js +1 -0
- package/dist/assets/editor_example_1-1000w.webp +0 -0
- package/dist/assets/editor_example_1-1200w.webp +0 -0
- package/dist/assets/editor_example_1-1600w.webp +0 -0
- package/dist/assets/editor_example_1-2000w.webp +0 -0
- package/dist/assets/editor_example_1-400w.webp +0 -0
- package/dist/assets/editor_example_1-600w.webp +0 -0
- package/dist/assets/editor_example_1-800w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-1000w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-1200w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-1600w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-2000w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-400w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-600w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-800w.webp +0 -0
- package/dist/assets/editor_example_2-1000w.webp +0 -0
- package/dist/assets/editor_example_2-1200w.webp +0 -0
- package/dist/assets/editor_example_2-1600w.webp +0 -0
- package/dist/assets/editor_example_2-2000w.webp +0 -0
- package/dist/assets/editor_example_2-400w.webp +0 -0
- package/dist/assets/editor_example_2-600w.webp +0 -0
- package/dist/assets/editor_example_2-800w.webp +0 -0
- package/dist/assets/example_schematic-1000w.webp +0 -0
- package/dist/assets/example_schematic-1200w.webp +0 -0
- package/dist/assets/example_schematic-1600w.webp +0 -0
- package/dist/assets/example_schematic-2000w.webp +0 -0
- package/dist/assets/example_schematic-400w.webp +0 -0
- package/dist/assets/example_schematic-600w.webp +0 -0
- package/dist/assets/example_schematic-800w.webp +0 -0
- package/dist/assets/eye-B_NMTTT7.js +6 -0
- package/dist/assets/fallback-image.svg +1 -0
- package/dist/assets/favicon-BwEjZKGP.ico +0 -0
- package/dist/assets/formatTimeAgo-CawXna5h.js +6 -0
- package/dist/assets/github-DjKGjbX1.js +6 -0
- package/dist/assets/github-dark-DHJKELXO.js +1 -0
- package/dist/assets/github-light-DAi9KRSo.js +1 -0
- package/dist/assets/hash-DfKYpqTm.js +6 -0
- package/dist/assets/index-B17tE1vy.js +1 -0
- package/dist/assets/index-BQPj88OW.js +6051 -0
- package/dist/assets/index-DvNLZBaq.js +6 -0
- package/dist/assets/keyboard-4b_qLHIF.js +11 -0
- package/dist/assets/label-CTudXc4q.js +1 -0
- package/dist/assets/landing-Cjvvx-9q.js +11 -0
- package/dist/assets/latest-DMk4BmXW.js +1 -0
- package/dist/assets/layers-BJ1iwaVM.js +6 -0
- package/dist/assets/load-prettier-DgbV1Jgu.js +1 -0
- package/dist/assets/lock-BOZRJdUv.js +6 -0
- package/dist/assets/main-DPEM9abA.js +26 -0
- package/dist/assets/main-MTKdI4FA.css +1 -0
- package/dist/assets/my-orders-B7lEyNR9.js +1 -0
- package/dist/assets/organization-settings-rNvhYFgZ.js +6 -0
- package/dist/assets/package-editor-T4WIRP49.js +1 -0
- package/dist/assets/pen-D54fxNRf.js +6 -0
- package/dist/assets/plus-KkE_6Dq2.js +6 -0
- package/dist/assets/preview-release-DWhKHFWp.js +1 -0
- package/dist/assets/quickstart-WF3HR9Dc.js +1 -0
- package/dist/assets/refresh-cw-aWASTRku.js +6 -0
- package/dist/assets/release-builds-COa5ndHa.js +1 -0
- package/dist/assets/release-detail-iclJPUO-.js +6 -0
- package/dist/assets/releases-Clsyp-7n.js +1 -0
- package/dist/assets/role-badge-BGF_IMlO.js +16 -0
- package/dist/assets/search-CwH23pAU.js +1 -0
- package/dist/assets/select-BN8AF1J7.js +1 -0
- package/dist/assets/settings-B2bMEtS4.js +6 -0
- package/dist/assets/skeleton-DLAS40-y.js +1 -0
- package/dist/assets/svg-to-png-BX4YEHCP-JcDm8Hc5.js +1 -0
- package/dist/assets/svg-to-png-BX4YEHCP-pNo9Afg8.js +1 -0
- package/dist/assets/tabs-Ce0NFuwd.js +1 -0
- package/dist/assets/timeAgo-VY0F2EV9.js +10 -0
- package/dist/assets/tooltip-C1pwvC0K.js +11 -0
- package/dist/assets/trash-2-BW3eClHz.js +6 -0
- package/dist/assets/trending-C8246HGf.js +1 -0
- package/dist/assets/triangle-alert-BMIBEO1D.js +6 -0
- package/dist/assets/tsx-COt5Ahok.js +1 -0
- package/dist/assets/use-create-datasheet-B7TDsTUt.js +1 -0
- package/dist/assets/use-delete-package-DLKtoTOj.js +1 -0
- package/dist/assets/use-download-zip-CAOKjGXW.js +1 -0
- package/dist/assets/use-list-user-orgs-CgJIT7N4.js +1 -0
- package/dist/assets/use-organization-XwYYTFck.js +1 -0
- package/dist/assets/use-package-builds-Bx8rfxi1.js +1 -0
- package/dist/assets/use-package-by-package-name-1s1Pcarw.js +1 -0
- package/dist/assets/use-package-files-CmmWVuGn.js +1 -0
- package/dist/assets/use-package-release-by-id-or-version-BuuXcSZq.js +1 -0
- package/dist/assets/use-package-release-images-BMaZtvmk.js +1 -0
- package/dist/assets/use-packages-base-api-url-DA1hucM7.js +1 -0
- package/dist/assets/useQueries-BJ7Ue7HV.js +1 -0
- package/dist/assets/user-settings-BqO5FkMf.js +1 -0
- package/dist/assets/view-package-C-OvJr_Q.js +165 -0
- package/dist/assets/vitesse-light-CVO1_9PV.js +1 -0
- package/dist/assets/wasm-CG6Dc4jp.js +1 -0
- package/dist/index.html +127 -0
- package/dist/landing.html +34 -0
- package/dist/robots.txt +9 -0
- package/dist/sitemap.xml +118 -0
- package/dist/stats.html +4949 -0
- package/fake-snippets-api/lib/db/db-client.ts +89 -0
- package/fake-snippets-api/lib/db/schema.ts +29 -0
- package/fake-snippets-api/routes/api/bug_reports/create.ts +43 -0
- package/fake-snippets-api/routes/api/bug_reports/upload_file.ts +113 -0
- package/package.json +2 -2
- package/src/components/Header.tsx +16 -0
- package/src/components/PackageCard.tsx +7 -4
- package/src/components/PackageSearchResults.tsx +1 -7
- package/src/components/SearchComponent.tsx +64 -53
- package/src/components/TrendingPackagesCarousel.tsx +16 -23
- package/src/components/ViewPackagePage/components/mobile-sidebar.tsx +3 -2
- package/src/components/ViewPackagePage/components/preview-image-squares.tsx +6 -3
- package/src/hooks/use-preview-images.ts +22 -17
- package/src/hooks/useUpdatePackageFilesMutation.ts +8 -0
- package/src/lib/utils/getPackagePreviewImageUrl.ts +15 -0
- package/src/pages/dashboard.tsx +0 -1
- package/src/pages/editor.tsx +12 -9
- package/src/pages/organization-profile.tsx +0 -1
- package/src/pages/package-editor.tsx +13 -9
- package/src/pages/user-profile.tsx +0 -1
- package/dist/bundle.js +0 -9034
- package/dist/index.d.ts +0 -2065
- package/dist/index.js +0 -3737
- package/dist/schema.d.ts +0 -2972
- package/dist/schema.js +0 -426
- package/fake-snippets-api/bun.lockb +0 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
var Cx=Object.defineProperty;var Nx=(n,t,e)=>t in n?Cx(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var o=(n,t,e)=>Nx(n,typeof t!="symbol"?t+"":t,e);import{k as ec,b as at,_ as ri,aB as $x,aC as ct,aD as B,aE as pr,aF as Mt,as as ig,aG as Ax,aH as Ix,aI as Lx,aJ as Mx,aK as Rx,aL as Ox,aM as Fx,aN as og,aO as ag,aP as Ge,aQ as cg,j as P,aR as lg,n as zp,aS as zx,aT as Ux,aU as np,a3 as jx,a4 as Bx,a5 as Dx,a6 as Wx,a9 as Gx,B as Aa,aV as si,aW as co,aX as fr,aY as Wh,aZ as gr,a_ as tc,a$ as Vx,b0 as Hx,b1 as hg,m as Yx,w as Xx,b2 as qx,b3 as sc,b4 as Kx,b5 as Jx,b6 as Zx,b7 as Qx,b8 as ey,g as ty,b9 as sy,I as Ne,ba as Up}from"./index-BQPj88OW.js";import{m as ny,B as Ci,u as dg,E as ry,C as jp,D as iy,h as oy,i as ay,j as Se}from"./Analytics-DIw7l2gi.js";import{F as tt}from"./FileSaver.min-BDsOlqKl.js";import{L as mo}from"./label-CTudXc4q.js";import{S as cy,a as ly,b as hy,c as dy,d as yc}from"./select-BN8AF1J7.js";import{u as uy}from"./use-package-by-package-name-1s1Pcarw.js";/**
|
|
2
|
+
* @license lucide-react v0.488.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const py=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],qT=ec("copy",py);/**
|
|
7
|
+
* @license lucide-react v0.488.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const fy=[["circle",{cx:"12",cy:"18",r:"3",key:"1mpf1b"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9",key:"1uq4wg"}],["path",{d:"M12 12v3",key:"158kv8"}]],KT=ec("git-fork",fy);/**
|
|
12
|
+
* @license lucide-react v0.488.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const gy=[["path",{d:"m15 12-8.373 8.373a1 1 0 1 1-3-3L12 9",key:"eefl8a"}],["path",{d:"m18 15 4-4",key:"16gjal"}],["path",{d:"m21.5 11.5-1.914-1.914A2 2 0 0 1 19 8.172V7l-2.26-2.26a6 6 0 0 0-4.202-1.756L9 2.96l.92.82A6.18 6.18 0 0 1 12 8.4V10l2 2h1.172a2 2 0 0 1 1.414.586L18.5 14.5",key:"b7pghm"}]],_y=ec("hammer",gy);/**
|
|
17
|
+
* @license lucide-react v0.488.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const my=[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]],JT=ec("tag",my);let Ae=class extends Error{constructor(t){super(t),this.name="ShikiError"}};function xy(n){return rp(n)}function rp(n){return Array.isArray(n)?yy(n):n instanceof RegExp?n:typeof n=="object"?vy(n):n}function yy(n){let t=[];for(let e=0,s=n.length;e<s;e++)t[e]=rp(n[e]);return t}function vy(n){let t={};for(let e in n)t[e]=rp(n[e]);return t}function ug(n,...t){return t.forEach(e=>{for(let s in e)n[s]=e[s]}),n}function pg(n){const t=~n.lastIndexOf("/")||~n.lastIndexOf("\\");return t===0?n:~t===n.length-1?pg(n.substring(0,n.length-1)):n.substr(~t+1)}var vc=/\$(\d+)|\${(\d+):\/(downcase|upcase)}/g,xo=class{static hasCaptures(n){return n===null?!1:(vc.lastIndex=0,vc.test(n))}static replaceCaptures(n,t,e){return n.replace(vc,(s,r,i,a)=>{let l=e[parseInt(r||i,10)];if(l){let c=t.substring(l.start,l.end);for(;c[0]===".";)c=c.substring(1);switch(a){case"downcase":return c.toLowerCase();case"upcase":return c.toUpperCase();default:return c}}else return s})}};function fg(n,t){return n<t?-1:n>t?1:0}function gg(n,t){if(n===null&&t===null)return 0;if(!n)return-1;if(!t)return 1;let e=n.length,s=t.length;if(e===s){for(let r=0;r<e;r++){let i=fg(n[r],t[r]);if(i!==0)return i}return 0}return e-s}function Bp(n){return!!(/^#[0-9a-f]{6}$/i.test(n)||/^#[0-9a-f]{8}$/i.test(n)||/^#[0-9a-f]{3}$/i.test(n)||/^#[0-9a-f]{4}$/i.test(n))}function _g(n){return n.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g,"\\$&")}var mg=class{constructor(n){o(this,"cache",new Map);this.fn=n}get(n){if(this.cache.has(n))return this.cache.get(n);const t=this.fn(n);return this.cache.set(n,t),t}},Ia=class{constructor(n,t,e){o(this,"_cachedMatchRoot",new mg(n=>this._root.match(n)));this._colorMap=n,this._defaults=t,this._root=e}static createFromRawTheme(n,t){return this.createFromParsedTheme(ky(n),t)}static createFromParsedTheme(n,t){return Py(n,t)}getColorMap(){return this._colorMap.getColorMap()}getDefaults(){return this._defaults}match(n){if(n===null)return this._defaults;const t=n.scopeName,s=this._cachedMatchRoot.get(t).find(r=>wy(n.parent,r.parentScopes));return s?new xg(s.fontStyle,s.foreground,s.background):null}},wc=class ba{constructor(t,e){this.parent=t,this.scopeName=e}static push(t,e){for(const s of e)t=new ba(t,s);return t}static from(...t){let e=null;for(let s=0;s<t.length;s++)e=new ba(e,t[s]);return e}push(t){return new ba(this,t)}getSegments(){let t=this;const e=[];for(;t;)e.push(t.scopeName),t=t.parent;return e.reverse(),e}toString(){return this.getSegments().join(" ")}extends(t){return this===t?!0:this.parent===null?!1:this.parent.extends(t)}getExtensionIfDefined(t){const e=[];let s=this;for(;s&&s!==t;)e.push(s.scopeName),s=s.parent;return s===t?e.reverse():void 0}};function wy(n,t){if(t.length===0)return!0;for(let e=0;e<t.length;e++){let s=t[e],r=!1;if(s===">"){if(e===t.length-1)return!1;s=t[++e],r=!0}for(;n&&!by(n.scopeName,s);){if(r)return!1;n=n.parent}if(!n)return!1;n=n.parent}return!0}function by(n,t){return t===n||n.startsWith(t)&&n[t.length]==="."}var xg=class{constructor(n,t,e){this.fontStyle=n,this.foregroundId=t,this.backgroundId=e}};function ky(n){if(!n)return[];if(!n.settings||!Array.isArray(n.settings))return[];let t=n.settings,e=[],s=0;for(let r=0,i=t.length;r<i;r++){let a=t[r];if(!a.settings)continue;let l;if(typeof a.scope=="string"){let p=a.scope;p=p.replace(/^[,]+/,""),p=p.replace(/[,]+$/,""),l=p.split(",")}else Array.isArray(a.scope)?l=a.scope:l=[""];let c=-1;if(typeof a.settings.fontStyle=="string"){c=0;let p=a.settings.fontStyle.split(" ");for(let u=0,g=p.length;u<g;u++)switch(p[u]){case"italic":c=c|1;break;case"bold":c=c|2;break;case"underline":c=c|4;break;case"strikethrough":c=c|8;break}}let h=null;typeof a.settings.foreground=="string"&&Bp(a.settings.foreground)&&(h=a.settings.foreground);let d=null;typeof a.settings.background=="string"&&Bp(a.settings.background)&&(d=a.settings.background);for(let p=0,u=l.length;p<u;p++){let _=l[p].trim().split(" "),x=_[_.length-1],v=null;_.length>1&&(v=_.slice(0,_.length-1),v.reverse()),e[s++]=new Sy(x,v,r,c,h,d)}}return e}var Sy=class{constructor(n,t,e,s,r,i){this.scope=n,this.parentScopes=t,this.index=e,this.fontStyle=s,this.foreground=r,this.background=i}},ze=(n=>(n[n.NotSet=-1]="NotSet",n[n.None=0]="None",n[n.Italic=1]="Italic",n[n.Bold=2]="Bold",n[n.Underline=4]="Underline",n[n.Strikethrough=8]="Strikethrough",n))(ze||{});function Py(n,t){n.sort((c,h)=>{let d=fg(c.scope,h.scope);return d!==0||(d=gg(c.parentScopes,h.parentScopes),d!==0)?d:c.index-h.index});let e=0,s="#000000",r="#ffffff";for(;n.length>=1&&n[0].scope==="";){let c=n.shift();c.fontStyle!==-1&&(e=c.fontStyle),c.foreground!==null&&(s=c.foreground),c.background!==null&&(r=c.background)}let i=new Ty(t),a=new xg(e,i.getId(s),i.getId(r)),l=new Cy(new Gh(0,null,-1,0,0),[]);for(let c=0,h=n.length;c<h;c++){let d=n[c];l.insert(0,d.scope,d.parentScopes,d.fontStyle,i.getId(d.foreground),i.getId(d.background))}return new Ia(i,a,l)}var Ty=class{constructor(n){o(this,"_isFrozen");o(this,"_lastColorId");o(this,"_id2color");o(this,"_color2id");if(this._lastColorId=0,this._id2color=[],this._color2id=Object.create(null),Array.isArray(n)){this._isFrozen=!0;for(let t=0,e=n.length;t<e;t++)this._color2id[n[t]]=t,this._id2color[t]=n[t]}else this._isFrozen=!1}getId(n){if(n===null)return 0;n=n.toUpperCase();let t=this._color2id[n];if(t)return t;if(this._isFrozen)throw new Error(`Missing color in color map - ${n}`);return t=++this._lastColorId,this._color2id[n]=t,this._id2color[t]=n,t}getColorMap(){return this._id2color.slice(0)}},Ey=Object.freeze([]),Gh=class yg{constructor(t,e,s,r,i){o(this,"scopeDepth");o(this,"parentScopes");o(this,"fontStyle");o(this,"foreground");o(this,"background");this.scopeDepth=t,this.parentScopes=e||Ey,this.fontStyle=s,this.foreground=r,this.background=i}clone(){return new yg(this.scopeDepth,this.parentScopes,this.fontStyle,this.foreground,this.background)}static cloneArr(t){let e=[];for(let s=0,r=t.length;s<r;s++)e[s]=t[s].clone();return e}acceptOverwrite(t,e,s,r){this.scopeDepth>t?console.log("how did this happen?"):this.scopeDepth=t,e!==-1&&(this.fontStyle=e),s!==0&&(this.foreground=s),r!==0&&(this.background=r)}},Cy=class Vh{constructor(t,e=[],s={}){o(this,"_rulesWithParentScopes");this._mainRule=t,this._children=s,this._rulesWithParentScopes=e}static _cmpBySpecificity(t,e){if(t.scopeDepth!==e.scopeDepth)return e.scopeDepth-t.scopeDepth;let s=0,r=0;for(;t.parentScopes[s]===">"&&s++,e.parentScopes[r]===">"&&r++,!(s>=t.parentScopes.length||r>=e.parentScopes.length);){const i=e.parentScopes[r].length-t.parentScopes[s].length;if(i!==0)return i;s++,r++}return e.parentScopes.length-t.parentScopes.length}match(t){if(t!==""){let s=t.indexOf("."),r,i;if(s===-1?(r=t,i=""):(r=t.substring(0,s),i=t.substring(s+1)),this._children.hasOwnProperty(r))return this._children[r].match(i)}const e=this._rulesWithParentScopes.concat(this._mainRule);return e.sort(Vh._cmpBySpecificity),e}insert(t,e,s,r,i,a){if(e===""){this._doInsertHere(t,s,r,i,a);return}let l=e.indexOf("."),c,h;l===-1?(c=e,h=""):(c=e.substring(0,l),h=e.substring(l+1));let d;this._children.hasOwnProperty(c)?d=this._children[c]:(d=new Vh(this._mainRule.clone(),Gh.cloneArr(this._rulesWithParentScopes)),this._children[c]=d),d.insert(t+1,h,s,r,i,a)}_doInsertHere(t,e,s,r,i){if(e===null){this._mainRule.acceptOverwrite(t,s,r,i);return}for(let a=0,l=this._rulesWithParentScopes.length;a<l;a++){let c=this._rulesWithParentScopes[a];if(gg(c.parentScopes,e)===0){c.acceptOverwrite(t,s,r,i);return}}s===-1&&(s=this._mainRule.fontStyle),r===0&&(r=this._mainRule.foreground),i===0&&(i=this._mainRule.background),this._rulesWithParentScopes.push(new Gh(t,e,s,r,i))}},ui=class rt{static toBinaryStr(t){return t.toString(2).padStart(32,"0")}static print(t){const e=rt.getLanguageId(t),s=rt.getTokenType(t),r=rt.getFontStyle(t),i=rt.getForeground(t),a=rt.getBackground(t);console.log({languageId:e,tokenType:s,fontStyle:r,foreground:i,background:a})}static getLanguageId(t){return(t&255)>>>0}static getTokenType(t){return(t&768)>>>8}static containsBalancedBrackets(t){return(t&1024)!==0}static getFontStyle(t){return(t&30720)>>>11}static getForeground(t){return(t&16744448)>>>15}static getBackground(t){return(t&4278190080)>>>24}static set(t,e,s,r,i,a,l){let c=rt.getLanguageId(t),h=rt.getTokenType(t),d=rt.containsBalancedBrackets(t)?1:0,p=rt.getFontStyle(t),u=rt.getForeground(t),g=rt.getBackground(t);return e!==0&&(c=e),s!==8&&(h=s),r!==null&&(d=r?1:0),i!==-1&&(p=i),a!==0&&(u=a),l!==0&&(g=l),(c<<0|h<<8|d<<10|p<<11|u<<15|g<<24)>>>0}};function La(n,t){const e=[],s=Ny(n);let r=s.next();for(;r!==null;){let c=0;if(r.length===2&&r.charAt(1)===":"){switch(r.charAt(0)){case"R":c=1;break;case"L":c=-1;break;default:console.log(`Unknown priority ${r} in scope selector`)}r=s.next()}let h=a();if(e.push({matcher:h,priority:c}),r!==",")break;r=s.next()}return e;function i(){if(r==="-"){r=s.next();const c=i();return h=>!!c&&!c(h)}if(r==="("){r=s.next();const c=l();return r===")"&&(r=s.next()),c}if(Dp(r)){const c=[];do c.push(r),r=s.next();while(Dp(r));return h=>t(c,h)}return null}function a(){const c=[];let h=i();for(;h;)c.push(h),h=i();return d=>c.every(p=>p(d))}function l(){const c=[];let h=a();for(;h&&(c.push(h),r==="|"||r===",");){do r=s.next();while(r==="|"||r===",");h=a()}return d=>c.some(p=>p(d))}}function Dp(n){return!!n&&!!n.match(/[\w\.:]+/)}function Ny(n){let t=/([LR]:|[\w\.:][\w\.:\-]*|[\,\|\-\(\)])/g,e=t.exec(n);return{next:()=>{if(!e)return null;const s=e[0];return e=t.exec(n),s}}}function vg(n){typeof n.dispose=="function"&&n.dispose()}var Ii=class{constructor(n){this.scopeName=n}toKey(){return this.scopeName}},$y=class{constructor(n,t){this.scopeName=n,this.ruleName=t}toKey(){return`${this.scopeName}#${this.ruleName}`}},Ay=class{constructor(){o(this,"_references",[]);o(this,"_seenReferenceKeys",new Set);o(this,"visitedRule",new Set)}get references(){return this._references}add(n){const t=n.toKey();this._seenReferenceKeys.has(t)||(this._seenReferenceKeys.add(t),this._references.push(n))}},Iy=class{constructor(n,t){o(this,"seenFullScopeRequests",new Set);o(this,"seenPartialScopeRequests",new Set);o(this,"Q");this.repo=n,this.initialScopeName=t,this.seenFullScopeRequests.add(this.initialScopeName),this.Q=[new Ii(this.initialScopeName)]}processQueue(){const n=this.Q;this.Q=[];const t=new Ay;for(const e of n)Ly(e,this.initialScopeName,this.repo,t);for(const e of t.references)if(e instanceof Ii){if(this.seenFullScopeRequests.has(e.scopeName))continue;this.seenFullScopeRequests.add(e.scopeName),this.Q.push(e)}else{if(this.seenFullScopeRequests.has(e.scopeName)||this.seenPartialScopeRequests.has(e.toKey()))continue;this.seenPartialScopeRequests.add(e.toKey()),this.Q.push(e)}}};function Ly(n,t,e,s){const r=e.lookup(n.scopeName);if(!r){if(n.scopeName===t)throw new Error(`No grammar provided for <${t}>`);return}const i=e.lookup(t);n instanceof Ii?ka({baseGrammar:i,selfGrammar:r},s):Hh(n.ruleName,{baseGrammar:i,selfGrammar:r,repository:r.repository},s);const a=e.injections(n.scopeName);if(a)for(const l of a)s.add(new Ii(l))}function Hh(n,t,e){if(t.repository&&t.repository[n]){const s=t.repository[n];Ma([s],t,e)}}function ka(n,t){n.selfGrammar.patterns&&Array.isArray(n.selfGrammar.patterns)&&Ma(n.selfGrammar.patterns,{...n,repository:n.selfGrammar.repository},t),n.selfGrammar.injections&&Ma(Object.values(n.selfGrammar.injections),{...n,repository:n.selfGrammar.repository},t)}function Ma(n,t,e){for(const s of n){if(e.visitedRule.has(s))continue;e.visitedRule.add(s);const r=s.repository?ug({},t.repository,s.repository):t.repository;Array.isArray(s.patterns)&&Ma(s.patterns,{...t,repository:r},e);const i=s.include;if(!i)continue;const a=wg(i);switch(a.kind){case 0:ka({...t,selfGrammar:t.baseGrammar},e);break;case 1:ka(t,e);break;case 2:Hh(a.ruleName,{...t,repository:r},e);break;case 3:case 4:const l=a.scopeName===t.selfGrammar.scopeName?t.selfGrammar:a.scopeName===t.baseGrammar.scopeName?t.baseGrammar:void 0;if(l){const c={baseGrammar:t.baseGrammar,selfGrammar:l,repository:r};a.kind===4?Hh(a.ruleName,c,e):ka(c,e)}else a.kind===4?e.add(new $y(a.scopeName,a.ruleName)):e.add(new Ii(a.scopeName));break}}}var My=class{constructor(){o(this,"kind",0)}},Ry=class{constructor(){o(this,"kind",1)}},Oy=class{constructor(n){o(this,"kind",2);this.ruleName=n}},Fy=class{constructor(n){o(this,"kind",3);this.scopeName=n}},zy=class{constructor(n,t){o(this,"kind",4);this.scopeName=n,this.ruleName=t}};function wg(n){if(n==="$base")return new My;if(n==="$self")return new Ry;const t=n.indexOf("#");if(t===-1)return new Fy(n);if(t===0)return new Oy(n.substring(1));{const e=n.substring(0,t),s=n.substring(t+1);return new zy(e,s)}}var Uy=/\\(\d+)/,Wp=/\\(\d+)/g,jy=-1,bg=-2;var lo=class{constructor(n,t,e,s){o(this,"$location");o(this,"id");o(this,"_nameIsCapturing");o(this,"_name");o(this,"_contentNameIsCapturing");o(this,"_contentName");this.$location=n,this.id=t,this._name=e||null,this._nameIsCapturing=xo.hasCaptures(this._name),this._contentName=s||null,this._contentNameIsCapturing=xo.hasCaptures(this._contentName)}get debugName(){const n=this.$location?`${pg(this.$location.filename)}:${this.$location.line}`:"unknown";return`${this.constructor.name}#${this.id} @ ${n}`}getName(n,t){return!this._nameIsCapturing||this._name===null||n===null||t===null?this._name:xo.replaceCaptures(this._name,n,t)}getContentName(n,t){return!this._contentNameIsCapturing||this._contentName===null?this._contentName:xo.replaceCaptures(this._contentName,n,t)}},By=class extends lo{constructor(t,e,s,r,i){super(t,e,s,r);o(this,"retokenizeCapturedWithRuleId");this.retokenizeCapturedWithRuleId=i}dispose(){}collectPatterns(t,e){throw new Error("Not supported!")}compile(t,e){throw new Error("Not supported!")}compileAG(t,e,s,r){throw new Error("Not supported!")}},Dy=class extends lo{constructor(t,e,s,r,i){super(t,e,s,null);o(this,"_match");o(this,"captures");o(this,"_cachedCompiledPatterns");this._match=new Li(r,this.id),this.captures=i,this._cachedCompiledPatterns=null}dispose(){this._cachedCompiledPatterns&&(this._cachedCompiledPatterns.dispose(),this._cachedCompiledPatterns=null)}get debugMatchRegExp(){return`${this._match.source}`}collectPatterns(t,e){e.push(this._match)}compile(t,e){return this._getCachedCompiledPatterns(t).compile(t)}compileAG(t,e,s,r){return this._getCachedCompiledPatterns(t).compileAG(t,s,r)}_getCachedCompiledPatterns(t){return this._cachedCompiledPatterns||(this._cachedCompiledPatterns=new Mi,this.collectPatterns(t,this._cachedCompiledPatterns)),this._cachedCompiledPatterns}},Gp=class extends lo{constructor(t,e,s,r,i){super(t,e,s,r);o(this,"hasMissingPatterns");o(this,"patterns");o(this,"_cachedCompiledPatterns");this.patterns=i.patterns,this.hasMissingPatterns=i.hasMissingPatterns,this._cachedCompiledPatterns=null}dispose(){this._cachedCompiledPatterns&&(this._cachedCompiledPatterns.dispose(),this._cachedCompiledPatterns=null)}collectPatterns(t,e){for(const s of this.patterns)t.getRule(s).collectPatterns(t,e)}compile(t,e){return this._getCachedCompiledPatterns(t).compile(t)}compileAG(t,e,s,r){return this._getCachedCompiledPatterns(t).compileAG(t,s,r)}_getCachedCompiledPatterns(t){return this._cachedCompiledPatterns||(this._cachedCompiledPatterns=new Mi,this.collectPatterns(t,this._cachedCompiledPatterns)),this._cachedCompiledPatterns}},Yh=class extends lo{constructor(t,e,s,r,i,a,l,c,h,d){super(t,e,s,r);o(this,"_begin");o(this,"beginCaptures");o(this,"_end");o(this,"endHasBackReferences");o(this,"endCaptures");o(this,"applyEndPatternLast");o(this,"hasMissingPatterns");o(this,"patterns");o(this,"_cachedCompiledPatterns");this._begin=new Li(i,this.id),this.beginCaptures=a,this._end=new Li(l||"",-1),this.endHasBackReferences=this._end.hasBackReferences,this.endCaptures=c,this.applyEndPatternLast=h||!1,this.patterns=d.patterns,this.hasMissingPatterns=d.hasMissingPatterns,this._cachedCompiledPatterns=null}dispose(){this._cachedCompiledPatterns&&(this._cachedCompiledPatterns.dispose(),this._cachedCompiledPatterns=null)}get debugBeginRegExp(){return`${this._begin.source}`}get debugEndRegExp(){return`${this._end.source}`}getEndWithResolvedBackReferences(t,e){return this._end.resolveBackReferences(t,e)}collectPatterns(t,e){e.push(this._begin)}compile(t,e){return this._getCachedCompiledPatterns(t,e).compile(t)}compileAG(t,e,s,r){return this._getCachedCompiledPatterns(t,e).compileAG(t,s,r)}_getCachedCompiledPatterns(t,e){if(!this._cachedCompiledPatterns){this._cachedCompiledPatterns=new Mi;for(const s of this.patterns)t.getRule(s).collectPatterns(t,this._cachedCompiledPatterns);this.applyEndPatternLast?this._cachedCompiledPatterns.push(this._end.hasBackReferences?this._end.clone():this._end):this._cachedCompiledPatterns.unshift(this._end.hasBackReferences?this._end.clone():this._end)}return this._end.hasBackReferences&&(this.applyEndPatternLast?this._cachedCompiledPatterns.setSource(this._cachedCompiledPatterns.length()-1,e):this._cachedCompiledPatterns.setSource(0,e)),this._cachedCompiledPatterns}},Ra=class extends lo{constructor(t,e,s,r,i,a,l,c,h){super(t,e,s,r);o(this,"_begin");o(this,"beginCaptures");o(this,"whileCaptures");o(this,"_while");o(this,"whileHasBackReferences");o(this,"hasMissingPatterns");o(this,"patterns");o(this,"_cachedCompiledPatterns");o(this,"_cachedCompiledWhilePatterns");this._begin=new Li(i,this.id),this.beginCaptures=a,this.whileCaptures=c,this._while=new Li(l,bg),this.whileHasBackReferences=this._while.hasBackReferences,this.patterns=h.patterns,this.hasMissingPatterns=h.hasMissingPatterns,this._cachedCompiledPatterns=null,this._cachedCompiledWhilePatterns=null}dispose(){this._cachedCompiledPatterns&&(this._cachedCompiledPatterns.dispose(),this._cachedCompiledPatterns=null),this._cachedCompiledWhilePatterns&&(this._cachedCompiledWhilePatterns.dispose(),this._cachedCompiledWhilePatterns=null)}get debugBeginRegExp(){return`${this._begin.source}`}get debugWhileRegExp(){return`${this._while.source}`}getWhileWithResolvedBackReferences(t,e){return this._while.resolveBackReferences(t,e)}collectPatterns(t,e){e.push(this._begin)}compile(t,e){return this._getCachedCompiledPatterns(t).compile(t)}compileAG(t,e,s,r){return this._getCachedCompiledPatterns(t).compileAG(t,s,r)}_getCachedCompiledPatterns(t){if(!this._cachedCompiledPatterns){this._cachedCompiledPatterns=new Mi;for(const e of this.patterns)t.getRule(e).collectPatterns(t,this._cachedCompiledPatterns)}return this._cachedCompiledPatterns}compileWhile(t,e){return this._getCachedCompiledWhilePatterns(t,e).compile(t)}compileWhileAG(t,e,s,r){return this._getCachedCompiledWhilePatterns(t,e).compileAG(t,s,r)}_getCachedCompiledWhilePatterns(t,e){return this._cachedCompiledWhilePatterns||(this._cachedCompiledWhilePatterns=new Mi,this._cachedCompiledWhilePatterns.push(this._while.hasBackReferences?this._while.clone():this._while)),this._while.hasBackReferences&&this._cachedCompiledWhilePatterns.setSource(0,e||""),this._cachedCompiledWhilePatterns}},kg=class Fe{static createCaptureRule(t,e,s,r,i){return t.registerRule(a=>new By(e,a,s,r,i))}static getCompiledRuleId(t,e,s){return t.id||e.registerRule(r=>{if(t.id=r,t.match)return new Dy(t.$vscodeTextmateLocation,t.id,t.name,t.match,Fe._compileCaptures(t.captures,e,s));if(typeof t.begin>"u"){t.repository&&(s=ug({},s,t.repository));let i=t.patterns;return typeof i>"u"&&t.include&&(i=[{include:t.include}]),new Gp(t.$vscodeTextmateLocation,t.id,t.name,t.contentName,Fe._compilePatterns(i,e,s))}return t.while?new Ra(t.$vscodeTextmateLocation,t.id,t.name,t.contentName,t.begin,Fe._compileCaptures(t.beginCaptures||t.captures,e,s),t.while,Fe._compileCaptures(t.whileCaptures||t.captures,e,s),Fe._compilePatterns(t.patterns,e,s)):new Yh(t.$vscodeTextmateLocation,t.id,t.name,t.contentName,t.begin,Fe._compileCaptures(t.beginCaptures||t.captures,e,s),t.end,Fe._compileCaptures(t.endCaptures||t.captures,e,s),t.applyEndPatternLast,Fe._compilePatterns(t.patterns,e,s))}),t.id}static _compileCaptures(t,e,s){let r=[];if(t){let i=0;for(const a in t){if(a==="$vscodeTextmateLocation")continue;const l=parseInt(a,10);l>i&&(i=l)}for(let a=0;a<=i;a++)r[a]=null;for(const a in t){if(a==="$vscodeTextmateLocation")continue;const l=parseInt(a,10);let c=0;t[a].patterns&&(c=Fe.getCompiledRuleId(t[a],e,s)),r[l]=Fe.createCaptureRule(e,t[a].$vscodeTextmateLocation,t[a].name,t[a].contentName,c)}}return r}static _compilePatterns(t,e,s){let r=[];if(t)for(let i=0,a=t.length;i<a;i++){const l=t[i];let c=-1;if(l.include){const h=wg(l.include);switch(h.kind){case 0:case 1:c=Fe.getCompiledRuleId(s[l.include],e,s);break;case 2:let d=s[h.ruleName];d&&(c=Fe.getCompiledRuleId(d,e,s));break;case 3:case 4:const p=h.scopeName,u=h.kind===4?h.ruleName:null,g=e.getExternalGrammar(p,s);if(g)if(u){let _=g.repository[u];_&&(c=Fe.getCompiledRuleId(_,e,g.repository))}else c=Fe.getCompiledRuleId(g.repository.$self,e,g.repository);break}}else c=Fe.getCompiledRuleId(l,e,s);if(c!==-1){const h=e.getRule(c);let d=!1;if((h instanceof Gp||h instanceof Yh||h instanceof Ra)&&h.hasMissingPatterns&&h.patterns.length===0&&(d=!0),d)continue;r.push(c)}}return{patterns:r,hasMissingPatterns:(t?t.length:0)!==r.length}}},Li=class Sg{constructor(t,e){o(this,"source");o(this,"ruleId");o(this,"hasAnchor");o(this,"hasBackReferences");o(this,"_anchorCache");if(t&&typeof t=="string"){const s=t.length;let r=0,i=[],a=!1;for(let l=0;l<s;l++)if(t.charAt(l)==="\\"&&l+1<s){const h=t.charAt(l+1);h==="z"?(i.push(t.substring(r,l)),i.push("$(?!\\n)(?<!\\n)"),r=l+2):(h==="A"||h==="G")&&(a=!0),l++}this.hasAnchor=a,r===0?this.source=t:(i.push(t.substring(r,s)),this.source=i.join(""))}else this.hasAnchor=!1,this.source=t;this.hasAnchor?this._anchorCache=this._buildAnchorCache():this._anchorCache=null,this.ruleId=e,typeof this.source=="string"?this.hasBackReferences=Uy.test(this.source):this.hasBackReferences=!1}clone(){return new Sg(this.source,this.ruleId)}setSource(t){this.source!==t&&(this.source=t,this.hasAnchor&&(this._anchorCache=this._buildAnchorCache()))}resolveBackReferences(t,e){if(typeof this.source!="string")throw new Error("This method should only be called if the source is a string");let s=e.map(r=>t.substring(r.start,r.end));return Wp.lastIndex=0,this.source.replace(Wp,(r,i)=>_g(s[parseInt(i,10)]||""))}_buildAnchorCache(){if(typeof this.source!="string")throw new Error("This method should only be called if the source is a string");let t=[],e=[],s=[],r=[],i,a,l,c;for(i=0,a=this.source.length;i<a;i++)l=this.source.charAt(i),t[i]=l,e[i]=l,s[i]=l,r[i]=l,l==="\\"&&i+1<a&&(c=this.source.charAt(i+1),c==="A"?(t[i+1]="",e[i+1]="",s[i+1]="A",r[i+1]="A"):c==="G"?(t[i+1]="",e[i+1]="G",s[i+1]="",r[i+1]="G"):(t[i+1]=c,e[i+1]=c,s[i+1]=c,r[i+1]=c),i++);return{A0_G0:t.join(""),A0_G1:e.join(""),A1_G0:s.join(""),A1_G1:r.join("")}}resolveAnchors(t,e){return!this.hasAnchor||!this._anchorCache||typeof this.source!="string"?this.source:t?e?this._anchorCache.A1_G1:this._anchorCache.A1_G0:e?this._anchorCache.A0_G1:this._anchorCache.A0_G0}},Mi=class{constructor(){o(this,"_items");o(this,"_hasAnchors");o(this,"_cached");o(this,"_anchorCache");this._items=[],this._hasAnchors=!1,this._cached=null,this._anchorCache={A0_G0:null,A0_G1:null,A1_G0:null,A1_G1:null}}dispose(){this._disposeCaches()}_disposeCaches(){this._cached&&(this._cached.dispose(),this._cached=null),this._anchorCache.A0_G0&&(this._anchorCache.A0_G0.dispose(),this._anchorCache.A0_G0=null),this._anchorCache.A0_G1&&(this._anchorCache.A0_G1.dispose(),this._anchorCache.A0_G1=null),this._anchorCache.A1_G0&&(this._anchorCache.A1_G0.dispose(),this._anchorCache.A1_G0=null),this._anchorCache.A1_G1&&(this._anchorCache.A1_G1.dispose(),this._anchorCache.A1_G1=null)}push(n){this._items.push(n),this._hasAnchors=this._hasAnchors||n.hasAnchor}unshift(n){this._items.unshift(n),this._hasAnchors=this._hasAnchors||n.hasAnchor}length(){return this._items.length}setSource(n,t){this._items[n].source!==t&&(this._disposeCaches(),this._items[n].setSource(t))}compile(n){if(!this._cached){let t=this._items.map(e=>e.source);this._cached=new Vp(n,t,this._items.map(e=>e.ruleId))}return this._cached}compileAG(n,t,e){return this._hasAnchors?t?e?(this._anchorCache.A1_G1||(this._anchorCache.A1_G1=this._resolveAnchors(n,t,e)),this._anchorCache.A1_G1):(this._anchorCache.A1_G0||(this._anchorCache.A1_G0=this._resolveAnchors(n,t,e)),this._anchorCache.A1_G0):e?(this._anchorCache.A0_G1||(this._anchorCache.A0_G1=this._resolveAnchors(n,t,e)),this._anchorCache.A0_G1):(this._anchorCache.A0_G0||(this._anchorCache.A0_G0=this._resolveAnchors(n,t,e)),this._anchorCache.A0_G0):this.compile(n)}_resolveAnchors(n,t,e){let s=this._items.map(r=>r.resolveAnchors(t,e));return new Vp(n,s,this._items.map(r=>r.ruleId))}},Vp=class{constructor(n,t,e){o(this,"scanner");this.regExps=t,this.rules=e,this.scanner=n.createOnigScanner(t)}dispose(){typeof this.scanner.dispose=="function"&&this.scanner.dispose()}toString(){const n=[];for(let t=0,e=this.rules.length;t<e;t++)n.push(" - "+this.rules[t]+": "+this.regExps[t]);return n.join(`
|
|
22
|
+
`)}findNextMatchSync(n,t,e){const s=this.scanner.findNextMatchSync(n,t,e);return s?{ruleId:this.rules[s.index],captureIndices:s.captureIndices}:null}},bc=class{constructor(n,t){this.languageId=n,this.tokenType=t}},zt,Wy=(zt=class{constructor(t,e){o(this,"_defaultAttributes");o(this,"_embeddedLanguagesMatcher");o(this,"_getBasicScopeAttributes",new mg(t=>{const e=this._scopeToLanguage(t),s=this._toStandardTokenType(t);return new bc(e,s)}));this._defaultAttributes=new bc(t,8),this._embeddedLanguagesMatcher=new Gy(Object.entries(e||{}))}getDefaultAttributes(){return this._defaultAttributes}getBasicScopeAttributes(t){return t===null?zt._NULL_SCOPE_METADATA:this._getBasicScopeAttributes.get(t)}_scopeToLanguage(t){return this._embeddedLanguagesMatcher.match(t)||0}_toStandardTokenType(t){const e=t.match(zt.STANDARD_TOKEN_TYPE_REGEXP);if(!e)return 8;switch(e[1]){case"comment":return 1;case"string":return 2;case"regex":return 3;case"meta.embedded":return 0}throw new Error("Unexpected match for standard token type!")}},o(zt,"_NULL_SCOPE_METADATA",new bc(0,0)),o(zt,"STANDARD_TOKEN_TYPE_REGEXP",/\b(comment|string|regex|meta\.embedded)\b/),zt),Gy=class{constructor(n){o(this,"values");o(this,"scopesRegExp");if(n.length===0)this.values=null,this.scopesRegExp=null;else{this.values=new Map(n);const t=n.map(([e,s])=>_g(e));t.sort(),t.reverse(),this.scopesRegExp=new RegExp(`^((${t.join(")|(")}))($|\\.)`,"")}}match(n){if(!this.scopesRegExp)return;const t=n.match(this.scopesRegExp);if(t)return this.values.get(t[1])}},Hp=class{constructor(n,t){this.stack=n,this.stoppedEarly=t}};function Pg(n,t,e,s,r,i,a,l){const c=t.content.length;let h=!1,d=-1;if(a){const g=Vy(n,t,e,s,r,i);r=g.stack,s=g.linePos,e=g.isFirstLine,d=g.anchorPosition}const p=Date.now();for(;!h;){if(l!==0&&Date.now()-p>l)return new Hp(r,!0);u()}return new Hp(r,!1);function u(){const g=Hy(n,t,e,s,r,d);if(!g){i.produce(r,c),h=!0;return}const _=g.captureIndices,x=g.matchedRuleId,v=_&&_.length>0?_[0].end>s:!1;if(x===jy){const m=r.getRule(n);i.produce(r,_[0].start),r=r.withContentNameScopesList(r.nameScopesList),Ni(n,t,e,r,i,m.endCaptures,_),i.produce(r,_[0].end);const y=r;if(r=r.parent,d=y.getAnchorPos(),!v&&y.getEnterPos()===s){r=y,i.produce(r,c),h=!0;return}}else{const m=n.getRule(x);i.produce(r,_[0].start);const y=r,w=m.getName(t.content,_),b=r.contentNameScopesList.pushAttributed(w,n);if(r=r.push(x,s,d,_[0].end===c,null,b,b),m instanceof Yh){const k=m;Ni(n,t,e,r,i,k.beginCaptures,_),i.produce(r,_[0].end),d=_[0].end;const C=k.getContentName(t.content,_),E=b.pushAttributed(C,n);if(r=r.withContentNameScopesList(E),k.endHasBackReferences&&(r=r.withEndRule(k.getEndWithResolvedBackReferences(t.content,_))),!v&&y.hasSameRuleAs(r)){r=r.pop(),i.produce(r,c),h=!0;return}}else if(m instanceof Ra){const k=m;Ni(n,t,e,r,i,k.beginCaptures,_),i.produce(r,_[0].end),d=_[0].end;const C=k.getContentName(t.content,_),E=b.pushAttributed(C,n);if(r=r.withContentNameScopesList(E),k.whileHasBackReferences&&(r=r.withEndRule(k.getWhileWithResolvedBackReferences(t.content,_))),!v&&y.hasSameRuleAs(r)){r=r.pop(),i.produce(r,c),h=!0;return}}else if(Ni(n,t,e,r,i,m.captures,_),i.produce(r,_[0].end),r=r.pop(),!v){r=r.safePop(),i.produce(r,c),h=!0;return}}_[0].end>s&&(s=_[0].end,e=!1)}}function Vy(n,t,e,s,r,i){let a=r.beginRuleCapturedEOL?0:-1;const l=[];for(let c=r;c;c=c.pop()){const h=c.getRule(n);h instanceof Ra&&l.push({rule:h,stack:c})}for(let c=l.pop();c;c=l.pop()){const{ruleScanner:h,findOptions:d}=qy(c.rule,n,c.stack.endRule,e,s===a),p=h.findNextMatchSync(t,s,d);if(p){if(p.ruleId!==bg){r=c.stack.pop();break}p.captureIndices&&p.captureIndices.length&&(i.produce(c.stack,p.captureIndices[0].start),Ni(n,t,e,c.stack,i,c.rule.whileCaptures,p.captureIndices),i.produce(c.stack,p.captureIndices[0].end),a=p.captureIndices[0].end,p.captureIndices[0].end>s&&(s=p.captureIndices[0].end,e=!1))}else{r=c.stack.pop();break}}return{stack:r,linePos:s,anchorPosition:a,isFirstLine:e}}function Hy(n,t,e,s,r,i){const a=Yy(n,t,e,s,r,i),l=n.getInjections();if(l.length===0)return a;const c=Xy(l,n,t,e,s,r,i);if(!c)return a;if(!a)return c;const h=a.captureIndices[0].start,d=c.captureIndices[0].start;return d<h||c.priorityMatch&&d===h?c:a}function Yy(n,t,e,s,r,i){const a=r.getRule(n),{ruleScanner:l,findOptions:c}=Tg(a,n,r.endRule,e,s===i),h=l.findNextMatchSync(t,s,c);return h?{captureIndices:h.captureIndices,matchedRuleId:h.ruleId}:null}function Xy(n,t,e,s,r,i,a){let l=Number.MAX_VALUE,c=null,h,d=0;const p=i.contentNameScopesList.getScopeNames();for(let u=0,g=n.length;u<g;u++){const _=n[u];if(!_.matcher(p))continue;const x=t.getRule(_.ruleId),{ruleScanner:v,findOptions:m}=Tg(x,t,null,s,r===a),y=v.findNextMatchSync(e,r,m);if(!y)continue;const w=y.captureIndices[0].start;if(!(w>=l)&&(l=w,c=y.captureIndices,h=y.ruleId,d=_.priority,l===r))break}return c?{priorityMatch:d===-1,captureIndices:c,matchedRuleId:h}:null}function Tg(n,t,e,s,r){return{ruleScanner:n.compileAG(t,e,s,r),findOptions:0}}function qy(n,t,e,s,r){return{ruleScanner:n.compileWhileAG(t,e,s,r),findOptions:0}}function Ni(n,t,e,s,r,i,a){if(i.length===0)return;const l=t.content,c=Math.min(i.length,a.length),h=[],d=a[0].end;for(let p=0;p<c;p++){const u=i[p];if(u===null)continue;const g=a[p];if(g.length===0)continue;if(g.start>d)break;for(;h.length>0&&h[h.length-1].endPos<=g.start;)r.produceFromScopes(h[h.length-1].scopes,h[h.length-1].endPos),h.pop();if(h.length>0?r.produceFromScopes(h[h.length-1].scopes,g.start):r.produce(s,g.start),u.retokenizeCapturedWithRuleId){const x=u.getName(l,a),v=s.contentNameScopesList.pushAttributed(x,n),m=u.getContentName(l,a),y=v.pushAttributed(m,n),w=s.push(u.retokenizeCapturedWithRuleId,g.start,-1,!1,null,v,y),b=n.createOnigString(l.substring(0,g.end));Pg(n,b,e&&g.start===0,g.start,w,r,!1,0),vg(b);continue}const _=u.getName(l,a);if(_!==null){const v=(h.length>0?h[h.length-1].scopes:s.contentNameScopesList).pushAttributed(_,n);h.push(new Ky(v,g.end))}}for(;h.length>0;)r.produceFromScopes(h[h.length-1].scopes,h[h.length-1].endPos),h.pop()}var Ky=class{constructor(n,t){o(this,"scopes");o(this,"endPos");this.scopes=n,this.endPos=t}};function Jy(n,t,e,s,r,i,a,l){return new Qy(n,t,e,s,r,i,a,l)}function Yp(n,t,e,s,r){const i=La(t,Oa),a=kg.getCompiledRuleId(e,s,r.repository);for(const l of i)n.push({debugSelector:t,matcher:l.matcher,ruleId:a,grammar:r,priority:l.priority})}function Oa(n,t){if(t.length<n.length)return!1;let e=0;return n.every(s=>{for(let r=e;r<t.length;r++)if(Zy(t[r],s))return e=r+1,!0;return!1})}function Zy(n,t){if(!n)return!1;if(n===t)return!0;const e=t.length;return n.length>e&&n.substr(0,e)===t&&n[e]==="."}var Qy=class{constructor(n,t,e,s,r,i,a,l){o(this,"_rootId");o(this,"_lastRuleId");o(this,"_ruleId2desc");o(this,"_includedGrammars");o(this,"_grammarRepository");o(this,"_grammar");o(this,"_injections");o(this,"_basicScopeAttributesProvider");o(this,"_tokenTypeMatchers");if(this._rootScopeName=n,this.balancedBracketSelectors=i,this._onigLib=l,this._basicScopeAttributesProvider=new Wy(e,s),this._rootId=-1,this._lastRuleId=0,this._ruleId2desc=[null],this._includedGrammars={},this._grammarRepository=a,this._grammar=Xp(t,null),this._injections=null,this._tokenTypeMatchers=[],r)for(const c of Object.keys(r)){const h=La(c,Oa);for(const d of h)this._tokenTypeMatchers.push({matcher:d.matcher,type:r[c]})}}get themeProvider(){return this._grammarRepository}dispose(){for(const n of this._ruleId2desc)n&&n.dispose()}createOnigScanner(n){return this._onigLib.createOnigScanner(n)}createOnigString(n){return this._onigLib.createOnigString(n)}getMetadataForScope(n){return this._basicScopeAttributesProvider.getBasicScopeAttributes(n)}_collectInjections(){const n={lookup:r=>r===this._rootScopeName?this._grammar:this.getExternalGrammar(r),injections:r=>this._grammarRepository.injections(r)},t=[],e=this._rootScopeName,s=n.lookup(e);if(s){const r=s.injections;if(r)for(let a in r)Yp(t,a,r[a],this,s);const i=this._grammarRepository.injections(e);i&&i.forEach(a=>{const l=this.getExternalGrammar(a);if(l){const c=l.injectionSelector;c&&Yp(t,c,l,this,l)}})}return t.sort((r,i)=>r.priority-i.priority),t}getInjections(){return this._injections===null&&(this._injections=this._collectInjections()),this._injections}registerRule(n){const t=++this._lastRuleId,e=n(t);return this._ruleId2desc[t]=e,e}getRule(n){return this._ruleId2desc[n]}getExternalGrammar(n,t){if(this._includedGrammars[n])return this._includedGrammars[n];if(this._grammarRepository){const e=this._grammarRepository.lookup(n);if(e)return this._includedGrammars[n]=Xp(e,t&&t.$base),this._includedGrammars[n]}}tokenizeLine(n,t,e=0){const s=this._tokenize(n,t,!1,e);return{tokens:s.lineTokens.getResult(s.ruleStack,s.lineLength),ruleStack:s.ruleStack,stoppedEarly:s.stoppedEarly}}tokenizeLine2(n,t,e=0){const s=this._tokenize(n,t,!0,e);return{tokens:s.lineTokens.getBinaryResult(s.ruleStack,s.lineLength),ruleStack:s.ruleStack,stoppedEarly:s.stoppedEarly}}_tokenize(n,t,e,s){this._rootId===-1&&(this._rootId=kg.getCompiledRuleId(this._grammar.repository.$self,this,this._grammar.repository),this.getInjections());let r;if(!t||t===Xh.NULL){r=!0;const h=this._basicScopeAttributesProvider.getDefaultAttributes(),d=this.themeProvider.getDefaults(),p=ui.set(0,h.languageId,h.tokenType,null,d.fontStyle,d.foregroundId,d.backgroundId),u=this.getRule(this._rootId).getName(null,null);let g;u?g=Ai.createRootAndLookUpScopeName(u,p,this):g=Ai.createRoot("unknown",p),t=new Xh(null,this._rootId,-1,-1,!1,null,g,g)}else r=!1,t.reset();n=n+`
|
|
23
|
+
`;const i=this.createOnigString(n),a=i.content.length,l=new tv(e,n,this._tokenTypeMatchers,this.balancedBracketSelectors),c=Pg(this,i,r,0,t,l,!0,s);return vg(i),{lineLength:a,lineTokens:l,ruleStack:c.stack,stoppedEarly:c.stoppedEarly}}};function Xp(n,t){return n=xy(n),n.repository=n.repository||{},n.repository.$self={$vscodeTextmateLocation:n.$vscodeTextmateLocation,patterns:n.patterns,name:n.scopeName},n.repository.$base=t||n.repository.$self,n}var Ai=class Pt{constructor(t,e,s){this.parent=t,this.scopePath=e,this.tokenAttributes=s}static fromExtension(t,e){let s=t,r=(t==null?void 0:t.scopePath)??null;for(const i of e)r=wc.push(r,i.scopeNames),s=new Pt(s,r,i.encodedTokenAttributes);return s}static createRoot(t,e){return new Pt(null,new wc(null,t),e)}static createRootAndLookUpScopeName(t,e,s){const r=s.getMetadataForScope(t),i=new wc(null,t),a=s.themeProvider.themeMatch(i),l=Pt.mergeAttributes(e,r,a);return new Pt(null,i,l)}get scopeName(){return this.scopePath.scopeName}toString(){return this.getScopeNames().join(" ")}equals(t){return Pt.equals(this,t)}static equals(t,e){do{if(t===e||!t&&!e)return!0;if(!t||!e||t.scopeName!==e.scopeName||t.tokenAttributes!==e.tokenAttributes)return!1;t=t.parent,e=e.parent}while(!0)}static mergeAttributes(t,e,s){let r=-1,i=0,a=0;return s!==null&&(r=s.fontStyle,i=s.foregroundId,a=s.backgroundId),ui.set(t,e.languageId,e.tokenType,null,r,i,a)}pushAttributed(t,e){if(t===null)return this;if(t.indexOf(" ")===-1)return Pt._pushAttributed(this,t,e);const s=t.split(/ /g);let r=this;for(const i of s)r=Pt._pushAttributed(r,i,e);return r}static _pushAttributed(t,e,s){const r=s.getMetadataForScope(e),i=t.scopePath.push(e),a=s.themeProvider.themeMatch(i),l=Pt.mergeAttributes(t.tokenAttributes,r,a);return new Pt(t,i,l)}getScopeNames(){return this.scopePath.getSegments()}getExtensionIfDefined(t){var r;const e=[];let s=this;for(;s&&s!==t;)e.push({encodedTokenAttributes:s.tokenAttributes,scopeNames:s.scopePath.getExtensionIfDefined(((r=s.parent)==null?void 0:r.scopePath)??null)}),s=s.parent;return s===t?e.reverse():void 0}},it,Xh=(it=class{constructor(t,e,s,r,i,a,l,c){o(this,"_stackElementBrand");o(this,"_enterPos");o(this,"_anchorPos");o(this,"depth");this.parent=t,this.ruleId=e,this.beginRuleCapturedEOL=i,this.endRule=a,this.nameScopesList=l,this.contentNameScopesList=c,this.depth=this.parent?this.parent.depth+1:1,this._enterPos=s,this._anchorPos=r}equals(t){return t===null?!1:it._equals(this,t)}static _equals(t,e){return t===e?!0:this._structuralEquals(t,e)?Ai.equals(t.contentNameScopesList,e.contentNameScopesList):!1}static _structuralEquals(t,e){do{if(t===e||!t&&!e)return!0;if(!t||!e||t.depth!==e.depth||t.ruleId!==e.ruleId||t.endRule!==e.endRule)return!1;t=t.parent,e=e.parent}while(!0)}clone(){return this}static _reset(t){for(;t;)t._enterPos=-1,t._anchorPos=-1,t=t.parent}reset(){it._reset(this)}pop(){return this.parent}safePop(){return this.parent?this.parent:this}push(t,e,s,r,i,a,l){return new it(this,t,e,s,r,i,a,l)}getEnterPos(){return this._enterPos}getAnchorPos(){return this._anchorPos}getRule(t){return t.getRule(this.ruleId)}toString(){const t=[];return this._writeString(t,0),"["+t.join(",")+"]"}_writeString(t,e){var s,r;return this.parent&&(e=this.parent._writeString(t,e)),t[e++]=`(${this.ruleId}, ${(s=this.nameScopesList)==null?void 0:s.toString()}, ${(r=this.contentNameScopesList)==null?void 0:r.toString()})`,e}withContentNameScopesList(t){return this.contentNameScopesList===t?this:this.parent.push(this.ruleId,this._enterPos,this._anchorPos,this.beginRuleCapturedEOL,this.endRule,this.nameScopesList,t)}withEndRule(t){return this.endRule===t?this:new it(this.parent,this.ruleId,this._enterPos,this._anchorPos,this.beginRuleCapturedEOL,t,this.nameScopesList,this.contentNameScopesList)}hasSameRuleAs(t){let e=this;for(;e&&e._enterPos===t._enterPos;){if(e.ruleId===t.ruleId)return!0;e=e.parent}return!1}toStateStackFrame(){var t,e,s;return{ruleId:this.ruleId,beginRuleCapturedEOL:this.beginRuleCapturedEOL,endRule:this.endRule,nameScopesList:((e=this.nameScopesList)==null?void 0:e.getExtensionIfDefined(((t=this.parent)==null?void 0:t.nameScopesList)??null))??[],contentNameScopesList:((s=this.contentNameScopesList)==null?void 0:s.getExtensionIfDefined(this.nameScopesList))??[]}}static pushFrame(t,e){const s=Ai.fromExtension((t==null?void 0:t.nameScopesList)??null,e.nameScopesList);return new it(t,e.ruleId,e.enterPos??-1,e.anchorPos??-1,e.beginRuleCapturedEOL,e.endRule,s,Ai.fromExtension(s,e.contentNameScopesList))}},o(it,"NULL",new it(null,0,0,0,!1,null,null,null)),it),ev=class{constructor(n,t){o(this,"balancedBracketScopes");o(this,"unbalancedBracketScopes");o(this,"allowAny",!1);this.balancedBracketScopes=n.flatMap(e=>e==="*"?(this.allowAny=!0,[]):La(e,Oa).map(s=>s.matcher)),this.unbalancedBracketScopes=t.flatMap(e=>La(e,Oa).map(s=>s.matcher))}get matchesAlways(){return this.allowAny&&this.unbalancedBracketScopes.length===0}get matchesNever(){return this.balancedBracketScopes.length===0&&!this.allowAny}match(n){for(const t of this.unbalancedBracketScopes)if(t(n))return!1;for(const t of this.balancedBracketScopes)if(t(n))return!0;return this.allowAny}},tv=class{constructor(n,t,e,s){o(this,"_emitBinaryTokens");o(this,"_lineText");o(this,"_tokens");o(this,"_binaryTokens");o(this,"_lastTokenEndIndex");o(this,"_tokenTypeOverrides");this.balancedBracketSelectors=s,this._emitBinaryTokens=n,this._tokenTypeOverrides=e,this._lineText=null,this._tokens=[],this._binaryTokens=[],this._lastTokenEndIndex=0}produce(n,t){this.produceFromScopes(n.contentNameScopesList,t)}produceFromScopes(n,t){var s;if(this._lastTokenEndIndex>=t)return;if(this._emitBinaryTokens){let r=(n==null?void 0:n.tokenAttributes)??0,i=!1;if((s=this.balancedBracketSelectors)!=null&&s.matchesAlways&&(i=!0),this._tokenTypeOverrides.length>0||this.balancedBracketSelectors&&!this.balancedBracketSelectors.matchesAlways&&!this.balancedBracketSelectors.matchesNever){const a=(n==null?void 0:n.getScopeNames())??[];for(const l of this._tokenTypeOverrides)l.matcher(a)&&(r=ui.set(r,0,l.type,null,-1,0,0));this.balancedBracketSelectors&&(i=this.balancedBracketSelectors.match(a))}if(i&&(r=ui.set(r,0,8,i,-1,0,0)),this._binaryTokens.length>0&&this._binaryTokens[this._binaryTokens.length-1]===r){this._lastTokenEndIndex=t;return}this._binaryTokens.push(this._lastTokenEndIndex),this._binaryTokens.push(r),this._lastTokenEndIndex=t;return}const e=(n==null?void 0:n.getScopeNames())??[];this._tokens.push({startIndex:this._lastTokenEndIndex,endIndex:t,scopes:e}),this._lastTokenEndIndex=t}getResult(n,t){return this._tokens.length>0&&this._tokens[this._tokens.length-1].startIndex===t-1&&this._tokens.pop(),this._tokens.length===0&&(this._lastTokenEndIndex=-1,this.produce(n,t),this._tokens[this._tokens.length-1].startIndex=0),this._tokens}getBinaryResult(n,t){this._binaryTokens.length>0&&this._binaryTokens[this._binaryTokens.length-2]===t-1&&(this._binaryTokens.pop(),this._binaryTokens.pop()),this._binaryTokens.length===0&&(this._lastTokenEndIndex=-1,this.produce(n,t),this._binaryTokens[this._binaryTokens.length-2]=0);const e=new Uint32Array(this._binaryTokens.length);for(let s=0,r=this._binaryTokens.length;s<r;s++)e[s]=this._binaryTokens[s];return e}},sv=class{constructor(n,t){o(this,"_grammars",new Map);o(this,"_rawGrammars",new Map);o(this,"_injectionGrammars",new Map);o(this,"_theme");this._onigLib=t,this._theme=n}dispose(){for(const n of this._grammars.values())n.dispose()}setTheme(n){this._theme=n}getColorMap(){return this._theme.getColorMap()}addGrammar(n,t){this._rawGrammars.set(n.scopeName,n),t&&this._injectionGrammars.set(n.scopeName,t)}lookup(n){return this._rawGrammars.get(n)}injections(n){return this._injectionGrammars.get(n)}getDefaults(){return this._theme.getDefaults()}themeMatch(n){return this._theme.match(n)}grammarForScopeName(n,t,e,s,r){if(!this._grammars.has(n)){let i=this._rawGrammars.get(n);if(!i)return null;this._grammars.set(n,Jy(n,i,t,e,s,r,this,this._onigLib))}return this._grammars.get(n)}},nv=class{constructor(t){o(this,"_options");o(this,"_syncRegistry");o(this,"_ensureGrammarCache");this._options=t,this._syncRegistry=new sv(Ia.createFromRawTheme(t.theme,t.colorMap),t.onigLib),this._ensureGrammarCache=new Map}dispose(){this._syncRegistry.dispose()}setTheme(t,e){this._syncRegistry.setTheme(Ia.createFromRawTheme(t,e))}getColorMap(){return this._syncRegistry.getColorMap()}loadGrammarWithEmbeddedLanguages(t,e,s){return this.loadGrammarWithConfiguration(t,e,{embeddedLanguages:s})}loadGrammarWithConfiguration(t,e,s){return this._loadGrammar(t,e,s.embeddedLanguages,s.tokenTypes,new ev(s.balancedBracketSelectors||[],s.unbalancedBracketSelectors||[]))}loadGrammar(t){return this._loadGrammar(t,0,null,null,null)}_loadGrammar(t,e,s,r,i){const a=new Iy(this._syncRegistry,t);for(;a.Q.length>0;)a.Q.map(l=>this._loadSingleGrammar(l.scopeName)),a.processQueue();return this._grammarForScopeName(t,e,s,r,i)}_loadSingleGrammar(t){this._ensureGrammarCache.has(t)||(this._doLoadSingleGrammar(t),this._ensureGrammarCache.set(t,!0))}_doLoadSingleGrammar(t){const e=this._options.loadGrammar(t);if(e){const s=typeof this._options.getInjections=="function"?this._options.getInjections(t):void 0;this._syncRegistry.addGrammar(e,s)}}addGrammar(t,e=[],s=0,r=null){return this._syncRegistry.addGrammar(t,e),this._grammarForScopeName(t.scopeName,s,r)}_grammarForScopeName(t,e=0,s=null,r=null,i=null){return this._syncRegistry.grammarForScopeName(t,e,s,r,i)}},qh=Xh.NULL;const rv=["area","base","basefont","bgsound","br","col","command","embed","frame","hr","image","img","input","keygen","link","meta","param","source","track","wbr"];class ho{constructor(t,e,s){this.normal=e,this.property=t,s&&(this.space=s)}}ho.prototype.normal={};ho.prototype.property={};ho.prototype.space=void 0;function Eg(n,t){const e={},s={};for(const r of n)Object.assign(e,r.property),Object.assign(s,r.normal);return new ho(e,s,t)}function Kh(n){return n.toLowerCase()}class Ke{constructor(t,e){this.attribute=e,this.property=t}}Ke.prototype.attribute="";Ke.prototype.booleanish=!1;Ke.prototype.boolean=!1;Ke.prototype.commaOrSpaceSeparated=!1;Ke.prototype.commaSeparated=!1;Ke.prototype.defined=!1;Ke.prototype.mustUseProperty=!1;Ke.prototype.number=!1;Ke.prototype.overloadedBoolean=!1;Ke.prototype.property="";Ke.prototype.spaceSeparated=!1;Ke.prototype.space=void 0;let iv=0;const Z=ni(),ve=ni(),Jh=ni(),A=ni(),le=ni(),ci=ni(),Ze=ni();function ni(){return 2**++iv}const Zh=Object.freeze(Object.defineProperty({__proto__:null,boolean:Z,booleanish:ve,commaOrSpaceSeparated:Ze,commaSeparated:ci,number:A,overloadedBoolean:Jh,spaceSeparated:le},Symbol.toStringTag,{value:"Module"})),kc=Object.keys(Zh);class ip extends Ke{constructor(t,e,s,r){let i=-1;if(super(t,e),qp(this,"space",r),typeof s=="number")for(;++i<kc.length;){const a=kc[i];qp(this,kc[i],(s&Zh[a])===Zh[a])}}}ip.prototype.defined=!0;function qp(n,t,e){e&&(n[t]=e)}function xi(n){const t={},e={};for(const[s,r]of Object.entries(n.properties)){const i=new ip(s,n.transform(n.attributes||{},s),r,n.space);n.mustUseProperty&&n.mustUseProperty.includes(s)&&(i.mustUseProperty=!0),t[s]=i,e[Kh(s)]=s,e[Kh(i.attribute)]=s}return new ho(t,e,n.space)}const Cg=xi({properties:{ariaActiveDescendant:null,ariaAtomic:ve,ariaAutoComplete:null,ariaBusy:ve,ariaChecked:ve,ariaColCount:A,ariaColIndex:A,ariaColSpan:A,ariaControls:le,ariaCurrent:null,ariaDescribedBy:le,ariaDetails:null,ariaDisabled:ve,ariaDropEffect:le,ariaErrorMessage:null,ariaExpanded:ve,ariaFlowTo:le,ariaGrabbed:ve,ariaHasPopup:null,ariaHidden:ve,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:le,ariaLevel:A,ariaLive:null,ariaModal:ve,ariaMultiLine:ve,ariaMultiSelectable:ve,ariaOrientation:null,ariaOwns:le,ariaPlaceholder:null,ariaPosInSet:A,ariaPressed:ve,ariaReadOnly:ve,ariaRelevant:null,ariaRequired:ve,ariaRoleDescription:le,ariaRowCount:A,ariaRowIndex:A,ariaRowSpan:A,ariaSelected:ve,ariaSetSize:A,ariaSort:null,ariaValueMax:A,ariaValueMin:A,ariaValueNow:A,ariaValueText:null,role:null},transform(n,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function Ng(n,t){return t in n?n[t]:t}function $g(n,t){return Ng(n,t.toLowerCase())}const ov=xi({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:ci,acceptCharset:le,accessKey:le,action:null,allow:null,allowFullScreen:Z,allowPaymentRequest:Z,allowUserMedia:Z,alt:null,as:null,async:Z,autoCapitalize:null,autoComplete:le,autoFocus:Z,autoPlay:Z,blocking:le,capture:null,charSet:null,checked:Z,cite:null,className:le,cols:A,colSpan:null,content:null,contentEditable:ve,controls:Z,controlsList:le,coords:A|ci,crossOrigin:null,data:null,dateTime:null,decoding:null,default:Z,defer:Z,dir:null,dirName:null,disabled:Z,download:Jh,draggable:ve,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:Z,formTarget:null,headers:le,height:A,hidden:Jh,high:A,href:null,hrefLang:null,htmlFor:le,httpEquiv:le,id:null,imageSizes:null,imageSrcSet:null,inert:Z,inputMode:null,integrity:null,is:null,isMap:Z,itemId:null,itemProp:le,itemRef:le,itemScope:Z,itemType:le,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:Z,low:A,manifest:null,max:null,maxLength:A,media:null,method:null,min:null,minLength:A,multiple:Z,muted:Z,name:null,nonce:null,noModule:Z,noValidate:Z,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:Z,optimum:A,pattern:null,ping:le,placeholder:null,playsInline:Z,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:Z,referrerPolicy:null,rel:le,required:Z,reversed:Z,rows:A,rowSpan:A,sandbox:le,scope:null,scoped:Z,seamless:Z,selected:Z,shadowRootClonable:Z,shadowRootDelegatesFocus:Z,shadowRootMode:null,shape:null,size:A,sizes:null,slot:null,span:A,spellCheck:ve,src:null,srcDoc:null,srcLang:null,srcSet:null,start:A,step:null,style:null,tabIndex:A,target:null,title:null,translate:null,type:null,typeMustMatch:Z,useMap:null,value:ve,width:A,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:le,axis:null,background:null,bgColor:null,border:A,borderColor:null,bottomMargin:A,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:Z,declare:Z,event:null,face:null,frame:null,frameBorder:null,hSpace:A,leftMargin:A,link:null,longDesc:null,lowSrc:null,marginHeight:A,marginWidth:A,noResize:Z,noHref:Z,noShade:Z,noWrap:Z,object:null,profile:null,prompt:null,rev:null,rightMargin:A,rules:null,scheme:null,scrolling:ve,standby:null,summary:null,text:null,topMargin:A,valueType:null,version:null,vAlign:null,vLink:null,vSpace:A,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:Z,disableRemotePlayback:Z,prefix:null,property:null,results:A,security:null,unselectable:null},space:"html",transform:$g}),av=xi({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:Ze,accentHeight:A,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:A,amplitude:A,arabicForm:null,ascent:A,attributeName:null,attributeType:null,azimuth:A,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:A,by:null,calcMode:null,capHeight:A,className:le,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:A,diffuseConstant:A,direction:null,display:null,dur:null,divisor:A,dominantBaseline:null,download:Z,dx:null,dy:null,edgeMode:null,editable:null,elevation:A,enableBackground:null,end:null,event:null,exponent:A,externalResourcesRequired:null,fill:null,fillOpacity:A,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:ci,g2:ci,glyphName:ci,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:A,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:A,horizOriginX:A,horizOriginY:A,id:null,ideographic:A,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:A,k:A,k1:A,k2:A,k3:A,k4:A,kernelMatrix:Ze,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:A,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:A,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:A,overlineThickness:A,paintOrder:null,panose1:null,path:null,pathLength:A,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:le,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:A,pointsAtY:A,pointsAtZ:A,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:Ze,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:Ze,rev:Ze,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:Ze,requiredFeatures:Ze,requiredFonts:Ze,requiredFormats:Ze,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:A,specularExponent:A,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:A,strikethroughThickness:A,string:null,stroke:null,strokeDashArray:Ze,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:A,strokeOpacity:A,strokeWidth:null,style:null,surfaceScale:A,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:Ze,tabIndex:A,tableValues:null,target:null,targetX:A,targetY:A,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:Ze,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:A,underlineThickness:A,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:A,values:null,vAlphabetic:A,vMathematical:A,vectorEffect:null,vHanging:A,vIdeographic:A,version:null,vertAdvY:A,vertOriginX:A,vertOriginY:A,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:A,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:Ng}),Ag=xi({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(n,t){return"xlink:"+t.slice(5).toLowerCase()}}),Ig=xi({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:$g}),Lg=xi({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(n,t){return"xml:"+t.slice(3).toLowerCase()}}),cv=/[A-Z]/g,Kp=/-[a-z]/g,lv=/^data[-\w.:]+$/i;function hv(n,t){const e=Kh(t);let s=t,r=Ke;if(e in n.normal)return n.property[n.normal[e]];if(e.length>4&&e.slice(0,4)==="data"&&lv.test(t)){if(t.charAt(4)==="-"){const i=t.slice(5).replace(Kp,uv);s="data"+i.charAt(0).toUpperCase()+i.slice(1)}else{const i=t.slice(4);if(!Kp.test(i)){let a=i.replace(cv,dv);a.charAt(0)!=="-"&&(a="-"+a),t="data"+a}}r=ip}return new r(s,t)}function dv(n){return"-"+n.toLowerCase()}function uv(n){return n.charAt(1).toUpperCase()}const pv=Eg([Cg,ov,Ag,Ig,Lg],"html"),Mg=Eg([Cg,av,Ag,Ig,Lg],"svg"),Jp={}.hasOwnProperty;function fv(n,t){const e=t||{};function s(r,...i){let a=s.invalid;const l=s.handlers;if(r&&Jp.call(r,n)){const c=String(r[n]);a=Jp.call(l,c)?l[c]:s.unknown}if(a)return a.call(this,r,...i)}return s.handlers=e.handlers||{},s.invalid=e.invalid,s.unknown=e.unknown,s}const gv=/["&'<>`]/g,_v=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,mv=/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,xv=/[|\\{}()[\]^$+*?.]/g,Zp=new WeakMap;function yv(n,t){if(n=n.replace(t.subset?vv(t.subset):gv,s),t.subset||t.escapeOnly)return n;return n.replace(_v,e).replace(mv,s);function e(r,i,a){return t.format((r.charCodeAt(0)-55296)*1024+r.charCodeAt(1)-56320+65536,a.charCodeAt(i+2),t)}function s(r,i,a){return t.format(r.charCodeAt(0),a.charCodeAt(i+1),t)}}function vv(n){let t=Zp.get(n);return t||(t=wv(n),Zp.set(n,t)),t}function wv(n){const t=[];let e=-1;for(;++e<n.length;)t.push(n[e].replace(xv,"\\$&"));return new RegExp("(?:"+t.join("|")+")","g")}const bv=/[\dA-Fa-f]/;function kv(n,t,e){const s="&#x"+n.toString(16).toUpperCase();return e&&t&&!bv.test(String.fromCharCode(t))?s:s+";"}const Sv=/\d/;function Pv(n,t,e){const s="&#"+String(n);return e&&t&&!Sv.test(String.fromCharCode(t))?s:s+";"}const Tv=["AElig","AMP","Aacute","Acirc","Agrave","Aring","Atilde","Auml","COPY","Ccedil","ETH","Eacute","Ecirc","Egrave","Euml","GT","Iacute","Icirc","Igrave","Iuml","LT","Ntilde","Oacute","Ocirc","Ograve","Oslash","Otilde","Ouml","QUOT","REG","THORN","Uacute","Ucirc","Ugrave","Uuml","Yacute","aacute","acirc","acute","aelig","agrave","amp","aring","atilde","auml","brvbar","ccedil","cedil","cent","copy","curren","deg","divide","eacute","ecirc","egrave","eth","euml","frac12","frac14","frac34","gt","iacute","icirc","iexcl","igrave","iquest","iuml","laquo","lt","macr","micro","middot","nbsp","not","ntilde","oacute","ocirc","ograve","ordf","ordm","oslash","otilde","ouml","para","plusmn","pound","quot","raquo","reg","sect","shy","sup1","sup2","sup3","szlig","thorn","times","uacute","ucirc","ugrave","uml","uuml","yacute","yen","yuml"],Sc={nbsp:" ",iexcl:"¡",cent:"¢",pound:"£",curren:"¤",yen:"¥",brvbar:"¦",sect:"§",uml:"¨",copy:"©",ordf:"ª",laquo:"«",not:"¬",shy:"",reg:"®",macr:"¯",deg:"°",plusmn:"±",sup2:"²",sup3:"³",acute:"´",micro:"µ",para:"¶",middot:"·",cedil:"¸",sup1:"¹",ordm:"º",raquo:"»",frac14:"¼",frac12:"½",frac34:"¾",iquest:"¿",Agrave:"À",Aacute:"Á",Acirc:"Â",Atilde:"Ã",Auml:"Ä",Aring:"Å",AElig:"Æ",Ccedil:"Ç",Egrave:"È",Eacute:"É",Ecirc:"Ê",Euml:"Ë",Igrave:"Ì",Iacute:"Í",Icirc:"Î",Iuml:"Ï",ETH:"Ð",Ntilde:"Ñ",Ograve:"Ò",Oacute:"Ó",Ocirc:"Ô",Otilde:"Õ",Ouml:"Ö",times:"×",Oslash:"Ø",Ugrave:"Ù",Uacute:"Ú",Ucirc:"Û",Uuml:"Ü",Yacute:"Ý",THORN:"Þ",szlig:"ß",agrave:"à",aacute:"á",acirc:"â",atilde:"ã",auml:"ä",aring:"å",aelig:"æ",ccedil:"ç",egrave:"è",eacute:"é",ecirc:"ê",euml:"ë",igrave:"ì",iacute:"í",icirc:"î",iuml:"ï",eth:"ð",ntilde:"ñ",ograve:"ò",oacute:"ó",ocirc:"ô",otilde:"õ",ouml:"ö",divide:"÷",oslash:"ø",ugrave:"ù",uacute:"ú",ucirc:"û",uuml:"ü",yacute:"ý",thorn:"þ",yuml:"ÿ",fnof:"ƒ",Alpha:"Α",Beta:"Β",Gamma:"Γ",Delta:"Δ",Epsilon:"Ε",Zeta:"Ζ",Eta:"Η",Theta:"Θ",Iota:"Ι",Kappa:"Κ",Lambda:"Λ",Mu:"Μ",Nu:"Ν",Xi:"Ξ",Omicron:"Ο",Pi:"Π",Rho:"Ρ",Sigma:"Σ",Tau:"Τ",Upsilon:"Υ",Phi:"Φ",Chi:"Χ",Psi:"Ψ",Omega:"Ω",alpha:"α",beta:"β",gamma:"γ",delta:"δ",epsilon:"ε",zeta:"ζ",eta:"η",theta:"θ",iota:"ι",kappa:"κ",lambda:"λ",mu:"μ",nu:"ν",xi:"ξ",omicron:"ο",pi:"π",rho:"ρ",sigmaf:"ς",sigma:"σ",tau:"τ",upsilon:"υ",phi:"φ",chi:"χ",psi:"ψ",omega:"ω",thetasym:"ϑ",upsih:"ϒ",piv:"ϖ",bull:"•",hellip:"…",prime:"′",Prime:"″",oline:"‾",frasl:"⁄",weierp:"℘",image:"ℑ",real:"ℜ",trade:"™",alefsym:"ℵ",larr:"←",uarr:"↑",rarr:"→",darr:"↓",harr:"↔",crarr:"↵",lArr:"⇐",uArr:"⇑",rArr:"⇒",dArr:"⇓",hArr:"⇔",forall:"∀",part:"∂",exist:"∃",empty:"∅",nabla:"∇",isin:"∈",notin:"∉",ni:"∋",prod:"∏",sum:"∑",minus:"−",lowast:"∗",radic:"√",prop:"∝",infin:"∞",ang:"∠",and:"∧",or:"∨",cap:"∩",cup:"∪",int:"∫",there4:"∴",sim:"∼",cong:"≅",asymp:"≈",ne:"≠",equiv:"≡",le:"≤",ge:"≥",sub:"⊂",sup:"⊃",nsub:"⊄",sube:"⊆",supe:"⊇",oplus:"⊕",otimes:"⊗",perp:"⊥",sdot:"⋅",lceil:"⌈",rceil:"⌉",lfloor:"⌊",rfloor:"⌋",lang:"〈",rang:"〉",loz:"◊",spades:"♠",clubs:"♣",hearts:"♥",diams:"♦",quot:'"',amp:"&",lt:"<",gt:">",OElig:"Œ",oelig:"œ",Scaron:"Š",scaron:"š",Yuml:"Ÿ",circ:"ˆ",tilde:"˜",ensp:" ",emsp:" ",thinsp:" ",zwnj:"",zwj:"",lrm:"",rlm:"",ndash:"–",mdash:"—",lsquo:"‘",rsquo:"’",sbquo:"‚",ldquo:"“",rdquo:"”",bdquo:"„",dagger:"†",Dagger:"‡",permil:"‰",lsaquo:"‹",rsaquo:"›",euro:"€"},Ev=["cent","copy","divide","gt","lt","not","para","times"],Rg={}.hasOwnProperty,Qh={};let yo;for(yo in Sc)Rg.call(Sc,yo)&&(Qh[Sc[yo]]=yo);const Cv=/[^\dA-Za-z]/;function Nv(n,t,e,s){const r=String.fromCharCode(n);if(Rg.call(Qh,r)){const i=Qh[r],a="&"+i;return e&&Tv.includes(i)&&!Ev.includes(i)&&(!s||t&&t!==61&&Cv.test(String.fromCharCode(t)))?a:a+";"}return""}function $v(n,t,e){let s=kv(n,t,e.omitOptionalSemicolons),r;if((e.useNamedReferences||e.useShortestReferences)&&(r=Nv(n,t,e.omitOptionalSemicolons,e.attribute)),(e.useShortestReferences||!r)&&e.useShortestReferences){const i=Pv(n,t,e.omitOptionalSemicolons);i.length<s.length&&(s=i)}return r&&(!e.useShortestReferences||r.length<s.length)?r:s}function li(n,t){return yv(n,Object.assign({format:$v},t))}const Av=/^>|^->|<!--|-->|--!>|<!-$/g,Iv=[">"],Lv=["<",">"];function Mv(n,t,e,s){return s.settings.bogusComments?"<?"+li(n.value,Object.assign({},s.settings.characterReferences,{subset:Iv}))+">":"<!--"+n.value.replace(Av,r)+"-->";function r(i){return li(i,Object.assign({},s.settings.characterReferences,{subset:Lv}))}}function Rv(n,t,e,s){return"<!"+(s.settings.upperDoctype?"DOCTYPE":"doctype")+(s.settings.tightDoctype?"":" ")+"html>"}function Qp(n,t){const e=String(n);if(typeof t!="string")throw new TypeError("Expected character");let s=0,r=e.indexOf(t);for(;r!==-1;)s++,r=e.indexOf(t,r+t.length);return s}function Ov(n,t){const e=t||{};return(n[n.length-1]===""?[...n,""]:n).join((e.padRight?" ":"")+","+(e.padLeft===!1?"":" ")).trim()}function Fv(n){return n.join(" ").trim()}const zv=/[ \t\n\f\r]/g;function op(n){return typeof n=="object"?n.type==="text"?ef(n.value):!1:ef(n)}function ef(n){return n.replace(zv,"")===""}const Ee=Fg(1),Og=Fg(-1),Uv=[];function Fg(n){return t;function t(e,s,r){const i=e?e.children:Uv;let a=(s||0)+n,l=i[a];if(!r)for(;l&&op(l);)a+=n,l=i[a];return l}}const jv={}.hasOwnProperty;function zg(n){return t;function t(e,s,r){return jv.call(n,e.tagName)&&n[e.tagName](e,s,r)}}const ap=zg({body:Dv,caption:Pc,colgroup:Pc,dd:Hv,dt:Vv,head:Pc,html:Bv,li:Gv,optgroup:Yv,option:Xv,p:Wv,rp:tf,rt:tf,tbody:Kv,td:sf,tfoot:Jv,th:sf,thead:qv,tr:Zv});function Pc(n,t,e){const s=Ee(e,t,!0);return!s||s.type!=="comment"&&!(s.type==="text"&&op(s.value.charAt(0)))}function Bv(n,t,e){const s=Ee(e,t);return!s||s.type!=="comment"}function Dv(n,t,e){const s=Ee(e,t);return!s||s.type!=="comment"}function Wv(n,t,e){const s=Ee(e,t);return s?s.type==="element"&&(s.tagName==="address"||s.tagName==="article"||s.tagName==="aside"||s.tagName==="blockquote"||s.tagName==="details"||s.tagName==="div"||s.tagName==="dl"||s.tagName==="fieldset"||s.tagName==="figcaption"||s.tagName==="figure"||s.tagName==="footer"||s.tagName==="form"||s.tagName==="h1"||s.tagName==="h2"||s.tagName==="h3"||s.tagName==="h4"||s.tagName==="h5"||s.tagName==="h6"||s.tagName==="header"||s.tagName==="hgroup"||s.tagName==="hr"||s.tagName==="main"||s.tagName==="menu"||s.tagName==="nav"||s.tagName==="ol"||s.tagName==="p"||s.tagName==="pre"||s.tagName==="section"||s.tagName==="table"||s.tagName==="ul"):!e||!(e.type==="element"&&(e.tagName==="a"||e.tagName==="audio"||e.tagName==="del"||e.tagName==="ins"||e.tagName==="map"||e.tagName==="noscript"||e.tagName==="video"))}function Gv(n,t,e){const s=Ee(e,t);return!s||s.type==="element"&&s.tagName==="li"}function Vv(n,t,e){const s=Ee(e,t);return!!(s&&s.type==="element"&&(s.tagName==="dt"||s.tagName==="dd"))}function Hv(n,t,e){const s=Ee(e,t);return!s||s.type==="element"&&(s.tagName==="dt"||s.tagName==="dd")}function tf(n,t,e){const s=Ee(e,t);return!s||s.type==="element"&&(s.tagName==="rp"||s.tagName==="rt")}function Yv(n,t,e){const s=Ee(e,t);return!s||s.type==="element"&&s.tagName==="optgroup"}function Xv(n,t,e){const s=Ee(e,t);return!s||s.type==="element"&&(s.tagName==="option"||s.tagName==="optgroup")}function qv(n,t,e){const s=Ee(e,t);return!!(s&&s.type==="element"&&(s.tagName==="tbody"||s.tagName==="tfoot"))}function Kv(n,t,e){const s=Ee(e,t);return!s||s.type==="element"&&(s.tagName==="tbody"||s.tagName==="tfoot")}function Jv(n,t,e){return!Ee(e,t)}function Zv(n,t,e){const s=Ee(e,t);return!s||s.type==="element"&&s.tagName==="tr"}function sf(n,t,e){const s=Ee(e,t);return!s||s.type==="element"&&(s.tagName==="td"||s.tagName==="th")}const Qv=zg({body:sw,colgroup:nw,head:tw,html:ew,tbody:rw});function ew(n){const t=Ee(n,-1);return!t||t.type!=="comment"}function tw(n){const t=new Set;for(const s of n.children)if(s.type==="element"&&(s.tagName==="base"||s.tagName==="title")){if(t.has(s.tagName))return!1;t.add(s.tagName)}const e=n.children[0];return!e||e.type==="element"}function sw(n){const t=Ee(n,-1,!0);return!t||t.type!=="comment"&&!(t.type==="text"&&op(t.value.charAt(0)))&&!(t.type==="element"&&(t.tagName==="meta"||t.tagName==="link"||t.tagName==="script"||t.tagName==="style"||t.tagName==="template"))}function nw(n,t,e){const s=Og(e,t),r=Ee(n,-1,!0);return e&&s&&s.type==="element"&&s.tagName==="colgroup"&&ap(s,e.children.indexOf(s),e)?!1:!!(r&&r.type==="element"&&r.tagName==="col")}function rw(n,t,e){const s=Og(e,t),r=Ee(n,-1);return e&&s&&s.type==="element"&&(s.tagName==="thead"||s.tagName==="tbody")&&ap(s,e.children.indexOf(s),e)?!1:!!(r&&r.type==="element"&&r.tagName==="tr")}const vo={name:[[`
|
|
24
|
+
\f\r &/=>`.split(""),`
|
|
25
|
+
\f\r "&'/=>\``.split("")],[`\0
|
|
26
|
+
\f\r "&'/<=>`.split(""),`\0
|
|
27
|
+
\f\r "&'/<=>\``.split("")]],unquoted:[[`
|
|
28
|
+
\f\r &>`.split(""),`\0
|
|
29
|
+
\f\r "&'<=>\``.split("")],[`\0
|
|
30
|
+
\f\r "&'<=>\``.split(""),`\0
|
|
31
|
+
\f\r "&'<=>\``.split("")]],single:[["&'".split(""),"\"&'`".split("")],["\0&'".split(""),"\0\"&'`".split("")]],double:[['"&'.split(""),"\"&'`".split("")],['\0"&'.split(""),"\0\"&'`".split("")]]};function iw(n,t,e,s){const r=s.schema,i=r.space==="svg"?!1:s.settings.omitOptionalTags;let a=r.space==="svg"?s.settings.closeEmptyElements:s.settings.voids.includes(n.tagName.toLowerCase());const l=[];let c;r.space==="html"&&n.tagName==="svg"&&(s.schema=Mg);const h=ow(s,n.properties),d=s.all(r.space==="html"&&n.tagName==="template"?n.content:n);return s.schema=r,d&&(a=!1),(h||!i||!Qv(n,t,e))&&(l.push("<",n.tagName,h?" "+h:""),a&&(r.space==="svg"||s.settings.closeSelfClosing)&&(c=h.charAt(h.length-1),(!s.settings.tightSelfClosing||c==="/"||c&&c!=='"'&&c!=="'")&&l.push(" "),l.push("/")),l.push(">")),l.push(d),!a&&(!i||!ap(n,t,e))&&l.push("</"+n.tagName+">"),l.join("")}function ow(n,t){const e=[];let s=-1,r;if(t){for(r in t)if(t[r]!==null&&t[r]!==void 0){const i=aw(n,r,t[r]);i&&e.push(i)}}for(;++s<e.length;){const i=n.settings.tightAttributes?e[s].charAt(e[s].length-1):void 0;s!==e.length-1&&i!=='"'&&i!=="'"&&(e[s]+=" ")}return e.join("")}function aw(n,t,e){const s=hv(n.schema,t),r=n.settings.allowParseErrors&&n.schema.space==="html"?0:1,i=n.settings.allowDangerousCharacters?0:1;let a=n.quote,l;if(s.overloadedBoolean&&(e===s.attribute||e==="")?e=!0:(s.boolean||s.overloadedBoolean)&&(typeof e!="string"||e===s.attribute||e==="")&&(e=!!e),e==null||e===!1||typeof e=="number"&&Number.isNaN(e))return"";const c=li(s.attribute,Object.assign({},n.settings.characterReferences,{subset:vo.name[r][i]}));return e===!0||(e=Array.isArray(e)?(s.commaSeparated?Ov:Fv)(e,{padLeft:!n.settings.tightCommaSeparatedLists}):String(e),n.settings.collapseEmptyAttributes&&!e)?c:(n.settings.preferUnquoted&&(l=li(e,Object.assign({},n.settings.characterReferences,{attribute:!0,subset:vo.unquoted[r][i]}))),l!==e&&(n.settings.quoteSmart&&Qp(e,a)>Qp(e,n.alternative)&&(a=n.alternative),l=a+li(e,Object.assign({},n.settings.characterReferences,{subset:(a==="'"?vo.single:vo.double)[r][i],attribute:!0}))+a),c+(l&&"="+l))}const cw=["<","&"];function Ug(n,t,e,s){return e&&e.type==="element"&&(e.tagName==="script"||e.tagName==="style")?n.value:li(n.value,Object.assign({},s.settings.characterReferences,{subset:cw}))}function lw(n,t,e,s){return s.settings.allowDangerousHtml?n.value:Ug(n,t,e,s)}function hw(n,t,e,s){return s.all(n)}const dw=fv("type",{invalid:uw,unknown:pw,handlers:{comment:Mv,doctype:Rv,element:iw,raw:lw,root:hw,text:Ug}});function uw(n){throw new Error("Expected node, not `"+n+"`")}function pw(n){const t=n;throw new Error("Cannot compile unknown node `"+t.type+"`")}const fw={},gw={},_w=[];function mw(n,t){const e=t||fw,s=e.quote||'"',r=s==='"'?"'":'"';if(s!=='"'&&s!=="'")throw new Error("Invalid quote `"+s+"`, expected `'` or `\"`");return{one:xw,all:yw,settings:{omitOptionalTags:e.omitOptionalTags||!1,allowParseErrors:e.allowParseErrors||!1,allowDangerousCharacters:e.allowDangerousCharacters||!1,quoteSmart:e.quoteSmart||!1,preferUnquoted:e.preferUnquoted||!1,tightAttributes:e.tightAttributes||!1,upperDoctype:e.upperDoctype||!1,tightDoctype:e.tightDoctype||!1,bogusComments:e.bogusComments||!1,tightCommaSeparatedLists:e.tightCommaSeparatedLists||!1,tightSelfClosing:e.tightSelfClosing||!1,collapseEmptyAttributes:e.collapseEmptyAttributes||!1,allowDangerousHtml:e.allowDangerousHtml||!1,voids:e.voids||rv,characterReferences:e.characterReferences||gw,closeSelfClosing:e.closeSelfClosing||!1,closeEmptyElements:e.closeEmptyElements||!1},schema:e.space==="svg"?Mg:pv,quote:s,alternative:r}.one(Array.isArray(n)?{type:"root",children:n}:n,void 0,void 0)}function xw(n,t,e){return dw(n,t,e,this)}function yw(n){const t=[],e=n&&n.children||_w;let s=-1;for(;++s<e.length;)t[s]=this.one(e[s],s,n);return t.join("")}function Fa(n,t){const e=typeof n=="string"?{}:{...n.colorReplacements},s=typeof n=="string"?n:n.name;for(const[r,i]of Object.entries((t==null?void 0:t.colorReplacements)||{}))typeof i=="string"?e[r]=i:r===s&&Object.assign(e,i);return e}function hr(n,t){return n&&((t==null?void 0:t[n==null?void 0:n.toLowerCase()])||n)}function vw(n){return Array.isArray(n)?n:[n]}async function jg(n){return Promise.resolve(typeof n=="function"?n():n).then(t=>t.default||t)}function cp(n){return!n||["plaintext","txt","text","plain"].includes(n)}function ww(n){return n==="ansi"||cp(n)}function lp(n){return n==="none"}function bw(n){return lp(n)}function Bg(n,t){var s;if(!t)return n;n.properties||(n.properties={}),(s=n.properties).class||(s.class=[]),typeof n.properties.class=="string"&&(n.properties.class=n.properties.class.split(/\s+/g)),Array.isArray(n.properties.class)||(n.properties.class=[]);const e=Array.isArray(t)?t:t.split(/\s+/g);for(const r of e)r&&!n.properties.class.includes(r)&&n.properties.class.push(r);return n}function nc(n,t=!1){var i;const e=n.split(/(\r?\n)/g);let s=0;const r=[];for(let a=0;a<e.length;a+=2){const l=t?e[a]+(e[a+1]||""):e[a];r.push([l,s]),s+=e[a].length,s+=((i=e[a+1])==null?void 0:i.length)||0}return r}function kw(n){const t=nc(n,!0).map(([r])=>r);function e(r){if(r===n.length)return{line:t.length-1,character:t[t.length-1].length};let i=r,a=0;for(const l of t){if(i<l.length)break;i-=l.length,a++}return{line:a,character:i}}function s(r,i){let a=0;for(let l=0;l<r;l++)a+=t[l].length;return a+=i,a}return{lines:t,indexToPos:e,posToIndex:s}}const hp="light-dark()",Sw=["color","background-color"];function Pw(n,t){let e=0;const s=[];for(const r of t)r>e&&s.push({...n,content:n.content.slice(e,r),offset:n.offset+e}),e=r;return e<n.content.length&&s.push({...n,content:n.content.slice(e),offset:n.offset+e}),s}function Tw(n,t){const e=Array.from(t instanceof Set?t:new Set(t)).sort((s,r)=>s-r);return e.length?n.map(s=>s.flatMap(r=>{const i=e.filter(a=>r.offset<a&&a<r.offset+r.content.length).map(a=>a-r.offset).sort((a,l)=>a-l);return i.length?Pw(r,i):r})):n}function Ew(n,t,e,s,r="css-vars"){const i={content:n.content,explanation:n.explanation,offset:n.offset},a=t.map(d=>za(n.variants[d])),l=new Set(a.flatMap(d=>Object.keys(d))),c={},h=(d,p)=>{const u=p==="color"?"":p==="background-color"?"-bg":`-${p}`;return e+t[d]+(p==="color"?"":u)};return a.forEach((d,p)=>{for(const u of l){const g=d[u]||"inherit";if(p===0&&s&&Sw.includes(u))if(s===hp&&a.length>1){const _=t.findIndex(y=>y==="light"),x=t.findIndex(y=>y==="dark");if(_===-1||x===-1)throw new Ae('When using `defaultColor: "light-dark()"`, you must provide both `light` and `dark` themes');const v=a[_][u]||"inherit",m=a[x][u]||"inherit";c[u]=`light-dark(${v}, ${m})`,r==="css-vars"&&(c[h(p,u)]=g)}else c[u]=g;else r==="css-vars"&&(c[h(p,u)]=g)}}),i.htmlStyle=c,i}function za(n){const t={};if(n.color&&(t.color=n.color),n.bgColor&&(t["background-color"]=n.bgColor),n.fontStyle){n.fontStyle&ze.Italic&&(t["font-style"]="italic"),n.fontStyle&ze.Bold&&(t["font-weight"]="bold");const e=[];n.fontStyle&ze.Underline&&e.push("underline"),n.fontStyle&ze.Strikethrough&&e.push("line-through"),e.length&&(t["text-decoration"]=e.join(" "))}return t}function ed(n){return typeof n=="string"?n:Object.entries(n).map(([t,e])=>`${t}:${e}`).join(";")}const Dg=new WeakMap;function rc(n,t){Dg.set(n,t)}function Ri(n){return Dg.get(n)}class yi{constructor(...t){o(this,"_stacks",{});o(this,"lang");if(t.length===2){const[e,s]=t;this.lang=s,this._stacks=e}else{const[e,s,r]=t;this.lang=s,this._stacks={[r]:e}}}get themes(){return Object.keys(this._stacks)}get theme(){return this.themes[0]}get _stack(){return this._stacks[this.theme]}static initial(t,e){return new yi(Object.fromEntries(vw(e).map(s=>[s,qh])),t)}getInternalStack(t=this.theme){return this._stacks[t]}getScopes(t=this.theme){return Cw(this._stacks[t])}toJSON(){return{lang:this.lang,theme:this.theme,themes:this.themes,scopes:this.getScopes()}}}function Cw(n){const t=[],e=new Set;function s(r){var a;if(e.has(r))return;e.add(r);const i=(a=r==null?void 0:r.nameScopesList)==null?void 0:a.scopeName;i&&t.push(i),r.parent&&s(r.parent)}return s(n),t}function Nw(n,t){if(!(n instanceof yi))throw new Ae("Invalid grammar state");return n.getInternalStack(t)}function $w(){const n=new WeakMap;function t(e){if(!n.has(e.meta)){let s=function(a){if(typeof a=="number"){if(a<0||a>e.source.length)throw new Ae(`Invalid decoration offset: ${a}. Code length: ${e.source.length}`);return{...r.indexToPos(a),offset:a}}else{const l=r.lines[a.line];if(l===void 0)throw new Ae(`Invalid decoration position ${JSON.stringify(a)}. Lines length: ${r.lines.length}`);let c=a.character;if(c<0&&(c=l.length+c),c<0||c>l.length)throw new Ae(`Invalid decoration position ${JSON.stringify(a)}. Line ${a.line} length: ${l.length}`);return{...a,character:c,offset:r.posToIndex(a.line,c)}}};const r=kw(e.source),i=(e.options.decorations||[]).map(a=>({...a,start:s(a.start),end:s(a.end)}));Aw(i),n.set(e.meta,{decorations:i,converter:r,source:e.source})}return n.get(e.meta)}return{name:"shiki:decorations",tokens(e){var a;if(!((a=this.options.decorations)!=null&&a.length))return;const r=t(this).decorations.flatMap(l=>[l.start.offset,l.end.offset]);return Tw(e,r)},code(e){var d;if(!((d=this.options.decorations)!=null&&d.length))return;const s=t(this),r=Array.from(e.children).filter(p=>p.type==="element"&&p.tagName==="span");if(r.length!==s.converter.lines.length)throw new Ae(`Number of lines in code element (${r.length}) does not match the number of lines in the source (${s.converter.lines.length}). Failed to apply decorations.`);function i(p,u,g,_){const x=r[p];let v="",m=-1,y=-1;if(u===0&&(m=0),g===0&&(y=0),g===Number.POSITIVE_INFINITY&&(y=x.children.length),m===-1||y===-1)for(let b=0;b<x.children.length;b++)v+=Wg(x.children[b]),m===-1&&v.length===u&&(m=b+1),y===-1&&v.length===g&&(y=b+1);if(m===-1)throw new Ae(`Failed to find start index for decoration ${JSON.stringify(_.start)}`);if(y===-1)throw new Ae(`Failed to find end index for decoration ${JSON.stringify(_.end)}`);const w=x.children.slice(m,y);if(!_.alwaysWrap&&w.length===x.children.length)l(x,_,"line");else if(!_.alwaysWrap&&w.length===1&&w[0].type==="element")l(w[0],_,"token");else{const b={type:"element",tagName:"span",properties:{},children:w};l(b,_,"wrapper"),x.children.splice(m,w.length,b)}}function a(p,u){r[p]=l(r[p],u,"line")}function l(p,u,g){var v;const _=u.properties||{},x=u.transform||(m=>m);return p.tagName=u.tagName||"span",p.properties={...p.properties,..._,class:p.properties.class},(v=u.properties)!=null&&v.class&&Bg(p,u.properties.class),p=x(p,g)||p,p}const c=[],h=s.decorations.sort((p,u)=>u.start.offset-p.start.offset||p.end.offset-u.end.offset);for(const p of h){const{start:u,end:g}=p;if(u.line===g.line)i(u.line,u.character,g.character,p);else if(u.line<g.line){i(u.line,u.character,Number.POSITIVE_INFINITY,p);for(let _=u.line+1;_<g.line;_++)c.unshift(()=>a(_,p));i(g.line,0,g.character,p)}}c.forEach(p=>p())}}}function Aw(n){for(let t=0;t<n.length;t++){const e=n[t];if(e.start.offset>e.end.offset)throw new Ae(`Invalid decoration range: ${JSON.stringify(e.start)} - ${JSON.stringify(e.end)}`);for(let s=t+1;s<n.length;s++){const r=n[s],i=e.start.offset<=r.start.offset&&r.start.offset<e.end.offset,a=e.start.offset<r.end.offset&&r.end.offset<=e.end.offset,l=r.start.offset<=e.start.offset&&e.start.offset<r.end.offset,c=r.start.offset<e.end.offset&&e.end.offset<=r.end.offset;if(i||a||l||c){if(i&&a||l&&c||l&&e.start.offset===e.end.offset||a&&r.start.offset===r.end.offset)continue;throw new Ae(`Decorations ${JSON.stringify(e.start)} and ${JSON.stringify(r.start)} intersect.`)}}}}function Wg(n){return n.type==="text"?n.value:n.type==="element"?n.children.map(Wg).join(""):""}const Iw=[$w()];function Ua(n){const t=Lw(n.transformers||[]);return[...t.pre,...t.normal,...t.post,...Iw]}function Lw(n){const t=[],e=[],s=[];for(const r of n)switch(r.enforce){case"pre":t.push(r);break;case"post":e.push(r);break;default:s.push(r)}return{pre:t,post:e,normal:s}}var wr=["black","red","green","yellow","blue","magenta","cyan","white","brightBlack","brightRed","brightGreen","brightYellow","brightBlue","brightMagenta","brightCyan","brightWhite"],Tc={1:"bold",2:"dim",3:"italic",4:"underline",7:"reverse",8:"hidden",9:"strikethrough"};function Mw(n,t){const e=n.indexOf("\x1B",t);if(e!==-1&&n[e+1]==="["){const s=n.indexOf("m",e);if(s!==-1)return{sequence:n.substring(e+2,s).split(";"),startPosition:e,position:s+1}}return{position:n.length}}function nf(n){const t=n.shift();if(t==="2"){const e=n.splice(0,3).map(s=>Number.parseInt(s));return e.length!==3||e.some(s=>Number.isNaN(s))?void 0:{type:"rgb",rgb:e}}else if(t==="5"){const e=n.shift();if(e)return{type:"table",index:Number(e)}}}function Rw(n){const t=[];for(;n.length>0;){const e=n.shift();if(!e)continue;const s=Number.parseInt(e);if(!Number.isNaN(s))if(s===0)t.push({type:"resetAll"});else if(s<=9)Tc[s]&&t.push({type:"setDecoration",value:Tc[s]});else if(s<=29){const r=Tc[s-20];r&&(t.push({type:"resetDecoration",value:r}),r==="dim"&&t.push({type:"resetDecoration",value:"bold"}))}else if(s<=37)t.push({type:"setForegroundColor",value:{type:"named",name:wr[s-30]}});else if(s===38){const r=nf(n);r&&t.push({type:"setForegroundColor",value:r})}else if(s===39)t.push({type:"resetForegroundColor"});else if(s<=47)t.push({type:"setBackgroundColor",value:{type:"named",name:wr[s-40]}});else if(s===48){const r=nf(n);r&&t.push({type:"setBackgroundColor",value:r})}else s===49?t.push({type:"resetBackgroundColor"}):s===53?t.push({type:"setDecoration",value:"overline"}):s===55?t.push({type:"resetDecoration",value:"overline"}):s>=90&&s<=97?t.push({type:"setForegroundColor",value:{type:"named",name:wr[s-90+8]}}):s>=100&&s<=107&&t.push({type:"setBackgroundColor",value:{type:"named",name:wr[s-100+8]}})}return t}function Ow(){let n=null,t=null,e=new Set;return{parse(s){const r=[];let i=0;do{const a=Mw(s,i),l=a.sequence?s.substring(i,a.startPosition):s.substring(i);if(l.length>0&&r.push({value:l,foreground:n,background:t,decorations:new Set(e)}),a.sequence){const c=Rw(a.sequence);for(const h of c)h.type==="resetAll"?(n=null,t=null,e.clear()):h.type==="resetForegroundColor"?n=null:h.type==="resetBackgroundColor"?t=null:h.type==="resetDecoration"&&e.delete(h.value);for(const h of c)h.type==="setForegroundColor"?n=h.value:h.type==="setBackgroundColor"?t=h.value:h.type==="setDecoration"&&e.add(h.value)}i=a.position}while(i<s.length);return r}}}var Fw={black:"#000000",red:"#bb0000",green:"#00bb00",yellow:"#bbbb00",blue:"#0000bb",magenta:"#ff00ff",cyan:"#00bbbb",white:"#eeeeee",brightBlack:"#555555",brightRed:"#ff5555",brightGreen:"#00ff00",brightYellow:"#ffff55",brightBlue:"#5555ff",brightMagenta:"#ff55ff",brightCyan:"#55ffff",brightWhite:"#ffffff"};function zw(n=Fw){function t(l){return n[l]}function e(l){return`#${l.map(c=>Math.max(0,Math.min(c,255)).toString(16).padStart(2,"0")).join("")}`}let s;function r(){if(s)return s;s=[];for(let h=0;h<wr.length;h++)s.push(t(wr[h]));let l=[0,95,135,175,215,255];for(let h=0;h<6;h++)for(let d=0;d<6;d++)for(let p=0;p<6;p++)s.push(e([l[h],l[d],l[p]]));let c=8;for(let h=0;h<24;h++,c+=10)s.push(e([c,c,c]));return s}function i(l){return r()[l]}function a(l){switch(l.type){case"named":return t(l.name);case"rgb":return e(l.rgb);case"table":return i(l.index)}}return{value:a}}function Uw(n,t,e){const s=Fa(n,e),r=nc(t),i=zw(Object.fromEntries(wr.map(l=>{var c;return[l,(c=n.colors)==null?void 0:c[`terminal.ansi${l[0].toUpperCase()}${l.substring(1)}`]]}))),a=Ow();return r.map(l=>a.parse(l[0]).map(c=>{let h,d;c.decorations.has("reverse")?(h=c.background?i.value(c.background):n.bg,d=c.foreground?i.value(c.foreground):n.fg):(h=c.foreground?i.value(c.foreground):n.fg,d=c.background?i.value(c.background):void 0),h=hr(h,s),d=hr(d,s),c.decorations.has("dim")&&(h=jw(h));let p=ze.None;return c.decorations.has("bold")&&(p|=ze.Bold),c.decorations.has("italic")&&(p|=ze.Italic),c.decorations.has("underline")&&(p|=ze.Underline),c.decorations.has("strikethrough")&&(p|=ze.Strikethrough),{content:c.value,offset:l[1],color:h,bgColor:d,fontStyle:p}}))}function jw(n){const t=n.match(/#([0-9a-f]{3})([0-9a-f]{3})?([0-9a-f]{2})?/);if(t)if(t[3]){const s=Math.round(Number.parseInt(t[3],16)/2).toString(16).padStart(2,"0");return`#${t[1]}${t[2]}${s}`}else return t[2]?`#${t[1]}${t[2]}80`:`#${Array.from(t[1]).map(s=>`${s}${s}`).join("")}80`;const e=n.match(/var\((--[\w-]+-ansi-[\w-]+)\)/);return e?`var(${e[1]}-dim)`:n}function dp(n,t,e={}){const{lang:s="text",theme:r=n.getLoadedThemes()[0]}=e;if(cp(s)||lp(r))return nc(t).map(c=>[{content:c[0],offset:c[1]}]);const{theme:i,colorMap:a}=n.setTheme(r);if(s==="ansi")return Uw(i,t,e);const l=n.getLanguage(s);if(e.grammarState){if(e.grammarState.lang!==l.name)throw new Ae(`Grammar state language "${e.grammarState.lang}" does not match highlight language "${l.name}"`);if(!e.grammarState.themes.includes(i.name))throw new Ae(`Grammar state themes "${e.grammarState.themes}" do not contain highlight theme "${i.name}"`)}return Dw(t,l,i,a,e)}function Bw(...n){if(n.length===2)return Ri(n[1]);const[t,e,s={}]=n,{lang:r="text",theme:i=t.getLoadedThemes()[0]}=s;if(cp(r)||lp(i))throw new Ae("Plain language does not have grammar state");if(r==="ansi")throw new Ae("ANSI language does not have grammar state");const{theme:a,colorMap:l}=t.setTheme(i),c=t.getLanguage(r);return new yi(ja(e,c,a,l,s).stateStack,c.name,a.name)}function Dw(n,t,e,s,r){const i=ja(n,t,e,s,r),a=new yi(ja(n,t,e,s,r).stateStack,t.name,e.name);return rc(i.tokens,a),i.tokens}function ja(n,t,e,s,r){const i=Fa(e,r),{tokenizeMaxLineLength:a=0,tokenizeTimeLimit:l=500}=r,c=nc(n);let h=r.grammarState?Nw(r.grammarState,e.name)??qh:r.grammarContextCode!=null?ja(r.grammarContextCode,t,e,s,{...r,grammarState:void 0,grammarContextCode:void 0}).stateStack:qh,d=[];const p=[];for(let u=0,g=c.length;u<g;u++){const[_,x]=c[u];if(_===""){d=[],p.push([]);continue}if(a>0&&_.length>=a){d=[],p.push([{content:_,offset:x,color:"",fontStyle:0}]);continue}let v,m,y;r.includeExplanation&&(v=t.tokenizeLine(_,h,l),m=v.tokens,y=0);const w=t.tokenizeLine2(_,h,l),b=w.tokens.length/2;for(let k=0;k<b;k++){const C=w.tokens[2*k],E=k+1<b?w.tokens[2*k+2]:_.length;if(C===E)continue;const N=w.tokens[2*k+1],I=hr(s[ui.getForeground(N)],i),M=ui.getFontStyle(N),S={content:_.substring(C,E),offset:x+C,color:I,fontStyle:M};if(r.includeExplanation){const L=[];if(r.includeExplanation!=="scopeName")for(const U of e.settings){let j;switch(typeof U.scope){case"string":j=U.scope.split(/,/).map(V=>V.trim());break;case"object":j=U.scope;break;default:continue}L.push({settings:U,selectors:j.map(V=>V.split(/ /))})}S.explanation=[];let R=0;for(;C+R<E;){const U=m[y],j=_.substring(U.startIndex,U.endIndex);R+=j.length,S.explanation.push({content:j,scopes:r.includeExplanation==="scopeName"?Ww(U.scopes):Gw(L,U.scopes)}),y+=1}}d.push(S)}p.push(d),d=[],h=w.ruleStack}return{tokens:p,stateStack:h}}function Ww(n){return n.map(t=>({scopeName:t}))}function Gw(n,t){const e=[];for(let s=0,r=t.length;s<r;s++){const i=t[s];e[s]={scopeName:i,themeMatches:Hw(n,i,t.slice(0,s))}}return e}function rf(n,t){return n===t||t.substring(0,n.length)===n&&t[n.length]==="."}function Vw(n,t,e){if(!rf(n[n.length-1],t))return!1;let s=n.length-2,r=e.length-1;for(;s>=0&&r>=0;)rf(n[s],e[r])&&(s-=1),r-=1;return s===-1}function Hw(n,t,e){const s=[];for(const{selectors:r,settings:i}of n)for(const a of r)if(Vw(a,t,e)){s.push(i);break}return s}function Gg(n,t,e){const s=Object.entries(e.themes).filter(c=>c[1]).map(c=>({color:c[0],theme:c[1]})),r=s.map(c=>{const h=dp(n,t,{...e,theme:c.theme}),d=Ri(h),p=typeof c.theme=="string"?c.theme:c.theme.name;return{tokens:h,state:d,theme:p}}),i=Yw(...r.map(c=>c.tokens)),a=i[0].map((c,h)=>c.map((d,p)=>{const u={content:d.content,variants:{},offset:d.offset};return"includeExplanation"in e&&e.includeExplanation&&(u.explanation=d.explanation),i.forEach((g,_)=>{const{content:x,explanation:v,offset:m,...y}=g[h][p];u.variants[s[_].color]=y}),u})),l=r[0].state?new yi(Object.fromEntries(r.map(c=>{var h;return[c.theme,(h=c.state)==null?void 0:h.getInternalStack(c.theme)]})),r[0].state.lang):void 0;return l&&rc(a,l),a}function Yw(...n){const t=n.map(()=>[]),e=n.length;for(let s=0;s<n[0].length;s++){const r=n.map(c=>c[s]),i=t.map(()=>[]);t.forEach((c,h)=>c.push(i[h]));const a=r.map(()=>0),l=r.map(c=>c[0]);for(;l.every(c=>c);){const c=Math.min(...l.map(h=>h.content.length));for(let h=0;h<e;h++){const d=l[h];d.content.length===c?(i[h].push(d),a[h]+=1,l[h]=r[h][a[h]]):(i[h].push({...d,content:d.content.slice(0,c)}),l[h]={...d,content:d.content.slice(c),offset:d.offset+c})}}}return t}function Ba(n,t,e){let s,r,i,a,l,c;if("themes"in e){const{defaultColor:h="light",cssVariablePrefix:d="--shiki-",colorsRendering:p="css-vars"}=e,u=Object.entries(e.themes).filter(m=>m[1]).map(m=>({color:m[0],theme:m[1]})).sort((m,y)=>m.color===h?-1:y.color===h?1:0);if(u.length===0)throw new Ae("`themes` option must not be empty");const g=Gg(n,t,e);if(c=Ri(g),h&&hp!==h&&!u.find(m=>m.color===h))throw new Ae(`\`themes\` option must contain the defaultColor key \`${h}\``);const _=u.map(m=>n.getTheme(m.theme)),x=u.map(m=>m.color);i=g.map(m=>m.map(y=>Ew(y,x,d,h,p))),c&&rc(i,c);const v=u.map(m=>Fa(m.theme,e));r=of(u,_,v,d,h,"fg",p),s=of(u,_,v,d,h,"bg",p),a=`shiki-themes ${_.map(m=>m.name).join(" ")}`,l=h?void 0:[r,s].join(";")}else if("theme"in e){const h=Fa(e.theme,e);i=dp(n,t,e);const d=n.getTheme(e.theme);s=hr(d.bg,h),r=hr(d.fg,h),a=d.name,c=Ri(i)}else throw new Ae("Invalid options, either `theme` or `themes` must be provided");return{tokens:i,fg:r,bg:s,themeName:a,rootStyle:l,grammarState:c}}function of(n,t,e,s,r,i,a){return n.map((l,c)=>{const h=hr(t[c][i],e[c])||"inherit",d=`${s+l.color}${i==="bg"?"-bg":""}:${h}`;if(c===0&&r){if(r===hp&&n.length>1){const p=n.findIndex(x=>x.color==="light"),u=n.findIndex(x=>x.color==="dark");if(p===-1||u===-1)throw new Ae('When using `defaultColor: "light-dark()"`, you must provide both `light` and `dark` themes');const g=hr(t[p][i],e[p])||"inherit",_=hr(t[u][i],e[u])||"inherit";return`light-dark(${g}, ${_});${d}`}return h}return a==="css-vars"?d:null}).filter(l=>!!l).join(";")}function Da(n,t,e,s={meta:{},options:e,codeToHast:(r,i)=>Da(n,r,i),codeToTokens:(r,i)=>Ba(n,r,i)}){var _,x;let r=t;for(const v of Ua(e))r=((_=v.preprocess)==null?void 0:_.call(s,r,e))||r;let{tokens:i,fg:a,bg:l,themeName:c,rootStyle:h,grammarState:d}=Ba(n,r,e);const{mergeWhitespaces:p=!0,mergeSameStyleTokens:u=!1}=e;p===!0?i=qw(i):p==="never"&&(i=Kw(i)),u&&(i=Jw(i));const g={...s,get source(){return r}};for(const v of Ua(e))i=((x=v.tokens)==null?void 0:x.call(g,i))||i;return Xw(i,{...e,fg:a,bg:l,themeName:c,rootStyle:h},g,d)}function Xw(n,t,e,s=Ri(n)){var _,x,v;const r=Ua(t),i=[],a={type:"root",children:[]},{structure:l="classic",tabindex:c="0"}=t;let h={type:"element",tagName:"pre",properties:{class:`shiki ${t.themeName||""}`,style:t.rootStyle||`background-color:${t.bg};color:${t.fg}`,...c!==!1&&c!=null?{tabindex:c.toString()}:{},...Object.fromEntries(Array.from(Object.entries(t.meta||{})).filter(([m])=>!m.startsWith("_")))},children:[]},d={type:"element",tagName:"code",properties:{},children:i};const p=[],u={...e,structure:l,addClassToHast:Bg,get source(){return e.source},get tokens(){return n},get options(){return t},get root(){return a},get pre(){return h},get code(){return d},get lines(){return p}};if(n.forEach((m,y)=>{var k,C;y&&(l==="inline"?a.children.push({type:"element",tagName:"br",properties:{},children:[]}):l==="classic"&&i.push({type:"text",value:`
|
|
32
|
+
`}));let w={type:"element",tagName:"span",properties:{class:"line"},children:[]},b=0;for(const E of m){let N={type:"element",tagName:"span",properties:{...E.htmlAttrs},children:[{type:"text",value:E.content}]};const I=ed(E.htmlStyle||za(E));I&&(N.properties.style=I);for(const M of r)N=((k=M==null?void 0:M.span)==null?void 0:k.call(u,N,y+1,b,w,E))||N;l==="inline"?a.children.push(N):l==="classic"&&w.children.push(N),b+=E.content.length}if(l==="classic"){for(const E of r)w=((C=E==null?void 0:E.line)==null?void 0:C.call(u,w,y+1))||w;p.push(w),i.push(w)}}),l==="classic"){for(const m of r)d=((_=m==null?void 0:m.code)==null?void 0:_.call(u,d))||d;h.children.push(d);for(const m of r)h=((x=m==null?void 0:m.pre)==null?void 0:x.call(u,h))||h;a.children.push(h)}let g=a;for(const m of r)g=((v=m==null?void 0:m.root)==null?void 0:v.call(u,g))||g;return s&&rc(g,s),g}function qw(n){return n.map(t=>{const e=[];let s="",r=0;return t.forEach((i,a)=>{const c=!(i.fontStyle&&(i.fontStyle&ze.Underline||i.fontStyle&ze.Strikethrough));c&&i.content.match(/^\s+$/)&&t[a+1]?(r||(r=i.offset),s+=i.content):s?(c?e.push({...i,offset:r,content:s+i.content}):e.push({content:s,offset:r},i),r=0,s=""):e.push(i)}),e})}function Kw(n){return n.map(t=>t.flatMap(e=>{if(e.content.match(/^\s+$/))return e;const s=e.content.match(/^(\s*)(.*?)(\s*)$/);if(!s)return e;const[,r,i,a]=s;if(!r&&!a)return e;const l=[{...e,offset:e.offset+r.length,content:i}];return r&&l.unshift({content:r,offset:e.offset}),a&&l.push({content:a,offset:e.offset+r.length+i.length}),l}))}function Jw(n){return n.map(t=>{const e=[];for(const s of t){if(e.length===0){e.push({...s});continue}const r=e[e.length-1],i=ed(r.htmlStyle||za(r)),a=ed(s.htmlStyle||za(s)),l=r.fontStyle&&(r.fontStyle&ze.Underline||r.fontStyle&ze.Strikethrough),c=s.fontStyle&&(s.fontStyle&ze.Underline||s.fontStyle&ze.Strikethrough);!l&&!c&&i===a?r.content+=s.content:e.push({...s})}return e})}const Zw=mw;function Qw(n,t,e){var i;const s={meta:{},options:e,codeToHast:(a,l)=>Da(n,a,l),codeToTokens:(a,l)=>Ba(n,a,l)};let r=Zw(Da(n,t,e,s));for(const a of Ua(e))r=((i=a.postprocess)==null?void 0:i.call(s,r,e))||r;return r}const af={light:"#333333",dark:"#bbbbbb"},cf={light:"#fffffe",dark:"#1e1e1e"},lf="__shiki_resolved";function up(n){var l,c,h,d,p;if(n!=null&&n[lf])return n;const t={...n};t.tokenColors&&!t.settings&&(t.settings=t.tokenColors,delete t.tokenColors),t.type||(t.type="dark"),t.colorReplacements={...t.colorReplacements},t.settings||(t.settings=[]);let{bg:e,fg:s}=t;if(!e||!s){const u=t.settings?t.settings.find(g=>!g.name&&!g.scope):void 0;(l=u==null?void 0:u.settings)!=null&&l.foreground&&(s=u.settings.foreground),(c=u==null?void 0:u.settings)!=null&&c.background&&(e=u.settings.background),!s&&((h=t==null?void 0:t.colors)!=null&&h["editor.foreground"])&&(s=t.colors["editor.foreground"]),!e&&((d=t==null?void 0:t.colors)!=null&&d["editor.background"])&&(e=t.colors["editor.background"]),s||(s=t.type==="light"?af.light:af.dark),e||(e=t.type==="light"?cf.light:cf.dark),t.fg=s,t.bg=e}t.settings[0]&&t.settings[0].settings&&!t.settings[0].scope||t.settings.unshift({settings:{foreground:t.fg,background:t.bg}});let r=0;const i=new Map;function a(u){var _;if(i.has(u))return i.get(u);r+=1;const g=`#${r.toString(16).padStart(8,"0").toLowerCase()}`;return(_=t.colorReplacements)!=null&&_[`#${g}`]?a(u):(i.set(u,g),g)}t.settings=t.settings.map(u=>{var v,m;const g=((v=u.settings)==null?void 0:v.foreground)&&!u.settings.foreground.startsWith("#"),_=((m=u.settings)==null?void 0:m.background)&&!u.settings.background.startsWith("#");if(!g&&!_)return u;const x={...u,settings:{...u.settings}};if(g){const y=a(u.settings.foreground);t.colorReplacements[y]=u.settings.foreground,x.settings.foreground=y}if(_){const y=a(u.settings.background);t.colorReplacements[y]=u.settings.background,x.settings.background=y}return x});for(const u of Object.keys(t.colors||{}))if((u==="editor.foreground"||u==="editor.background"||u.startsWith("terminal.ansi"))&&!((p=t.colors[u])!=null&&p.startsWith("#"))){const g=a(t.colors[u]);t.colorReplacements[g]=t.colors[u],t.colors[u]=g}return Object.defineProperty(t,lf,{enumerable:!1,writable:!1,value:!0}),t}async function Vg(n){return Array.from(new Set((await Promise.all(n.filter(t=>!ww(t)).map(async t=>await jg(t).then(e=>Array.isArray(e)?e:[e])))).flat()))}async function Hg(n){return(await Promise.all(n.map(async e=>bw(e)?null:up(await jg(e))))).filter(e=>!!e)}let eb=3;function tb(n,t=3){t>eb||console.trace(`[SHIKI DEPRECATE]: ${n}`)}let oi=class extends Error{constructor(t){super(t),this.name="ShikiError"}};class sb extends nv{constructor(e,s,r,i={}){super(e);o(this,"_resolvedThemes",new Map);o(this,"_resolvedGrammars",new Map);o(this,"_langMap",new Map);o(this,"_langGraph",new Map);o(this,"_textmateThemeCache",new WeakMap);o(this,"_loadedThemesCache",null);o(this,"_loadedLanguagesCache",null);this._resolver=e,this._themes=s,this._langs=r,this._alias=i,this._themes.map(a=>this.loadTheme(a)),this.loadLanguages(this._langs)}getTheme(e){return typeof e=="string"?this._resolvedThemes.get(e):this.loadTheme(e)}loadTheme(e){const s=up(e);return s.name&&(this._resolvedThemes.set(s.name,s),this._loadedThemesCache=null),s}getLoadedThemes(){return this._loadedThemesCache||(this._loadedThemesCache=[...this._resolvedThemes.keys()]),this._loadedThemesCache}setTheme(e){let s=this._textmateThemeCache.get(e);s||(s=Ia.createFromRawTheme(e),this._textmateThemeCache.set(e,s)),this._syncRegistry.setTheme(s)}getGrammar(e){if(this._alias[e]){const s=new Set([e]);for(;this._alias[e];){if(e=this._alias[e],s.has(e))throw new oi(`Circular alias \`${Array.from(s).join(" -> ")} -> ${e}\``);s.add(e)}}return this._resolvedGrammars.get(e)}loadLanguage(e){var a,l,c,h;if(this.getGrammar(e.name))return;const s=new Set([...this._langMap.values()].filter(d=>{var p;return(p=d.embeddedLangsLazy)==null?void 0:p.includes(e.name)}));this._resolver.addLanguage(e);const r={balancedBracketSelectors:e.balancedBracketSelectors||["*"],unbalancedBracketSelectors:e.unbalancedBracketSelectors||[]};this._syncRegistry._rawGrammars.set(e.scopeName,e);const i=this.loadGrammarWithConfiguration(e.scopeName,1,r);if(i.name=e.name,this._resolvedGrammars.set(e.name,i),e.aliases&&e.aliases.forEach(d=>{this._alias[d]=e.name}),this._loadedLanguagesCache=null,s.size)for(const d of s)this._resolvedGrammars.delete(d.name),this._loadedLanguagesCache=null,(l=(a=this._syncRegistry)==null?void 0:a._injectionGrammars)==null||l.delete(d.scopeName),(h=(c=this._syncRegistry)==null?void 0:c._grammars)==null||h.delete(d.scopeName),this.loadLanguage(this._langMap.get(d.name))}dispose(){super.dispose(),this._resolvedThemes.clear(),this._resolvedGrammars.clear(),this._langMap.clear(),this._langGraph.clear(),this._loadedThemesCache=null}loadLanguages(e){for(const i of e)this.resolveEmbeddedLanguages(i);const s=Array.from(this._langGraph.entries()),r=s.filter(([i,a])=>!a);if(r.length){const i=s.filter(([a,l])=>{var c;return l&&((c=l.embeddedLangs)==null?void 0:c.some(h=>r.map(([d])=>d).includes(h)))}).filter(a=>!r.includes(a));throw new oi(`Missing languages ${r.map(([a])=>`\`${a}\``).join(", ")}, required by ${i.map(([a])=>`\`${a}\``).join(", ")}`)}for(const[i,a]of s)this._resolver.addLanguage(a);for(const[i,a]of s)this.loadLanguage(a)}getLoadedLanguages(){return this._loadedLanguagesCache||(this._loadedLanguagesCache=[...new Set([...this._resolvedGrammars.keys(),...Object.keys(this._alias)])]),this._loadedLanguagesCache}resolveEmbeddedLanguages(e){if(this._langMap.set(e.name,e),this._langGraph.set(e.name,e),e.embeddedLangs)for(const s of e.embeddedLangs)this._langGraph.set(s,this._langMap.get(s))}}class nb{constructor(t,e){o(this,"_langs",new Map);o(this,"_scopeToLang",new Map);o(this,"_injections",new Map);o(this,"_onigLib");this._onigLib={createOnigScanner:s=>t.createScanner(s),createOnigString:s=>t.createString(s)},e.forEach(s=>this.addLanguage(s))}get onigLib(){return this._onigLib}getLangRegistration(t){return this._langs.get(t)}loadGrammar(t){return this._scopeToLang.get(t)}addLanguage(t){this._langs.set(t.name,t),t.aliases&&t.aliases.forEach(e=>{this._langs.set(e,t)}),this._scopeToLang.set(t.scopeName,t),t.injectTo&&t.injectTo.forEach(e=>{this._injections.get(e)||this._injections.set(e,[]),this._injections.get(e).push(t.scopeName)})}getInjections(t){const e=t.split(".");let s=[];for(let r=1;r<=e.length;r++){const i=e.slice(0,r).join(".");s=[...s,...this._injections.get(i)||[]]}return s}}let bi=0;function rb(n){bi+=1,n.warnings!==!1&&bi>=10&&bi%10===0&&console.warn(`[Shiki] ${bi} instances have been created. Shiki is supposed to be used as a singleton, consider refactoring your code to cache your highlighter instance; Or call \`highlighter.dispose()\` to release unused instances.`);let t=!1;if(!n.engine)throw new oi("`engine` option is required for synchronous mode");const e=(n.langs||[]).flat(1),s=(n.themes||[]).flat(1).map(up),r=new nb(n.engine,e),i=new sb(r,s,e,n.langAlias);let a;function l(y){v();const w=i.getGrammar(typeof y=="string"?y:y.name);if(!w)throw new oi(`Language \`${y}\` not found, you may need to load it first`);return w}function c(y){if(y==="none")return{bg:"",fg:"",name:"none",settings:[],type:"dark"};v();const w=i.getTheme(y);if(!w)throw new oi(`Theme \`${y}\` not found, you may need to load it first`);return w}function h(y){v();const w=c(y);a!==y&&(i.setTheme(w),a=y);const b=i.getColorMap();return{theme:w,colorMap:b}}function d(){return v(),i.getLoadedThemes()}function p(){return v(),i.getLoadedLanguages()}function u(...y){v(),i.loadLanguages(y.flat(1))}async function g(...y){return u(await Vg(y))}function _(...y){v();for(const w of y.flat(1))i.loadTheme(w)}async function x(...y){return v(),_(await Hg(y))}function v(){if(t)throw new oi("Shiki instance has been disposed")}function m(){t||(t=!0,i.dispose(),bi-=1)}return{setTheme:h,getTheme:c,getLanguage:l,getLoadedThemes:d,getLoadedLanguages:p,loadLanguage:g,loadLanguageSync:u,loadTheme:x,loadThemeSync:_,dispose:m,[Symbol.dispose]:m}}async function ib(n){n.engine||tb("`engine` option is required. Use `createOnigurumaEngine` or `createJavaScriptRegexEngine` to create an engine.");const[t,e,s]=await Promise.all([Hg(n.themes||[]),Vg(n.langs||[]),n.engine]);return rb({...n,themes:t,langs:e,engine:s})}async function ob(n){const t=await ib(n);return{getLastGrammarState:(...e)=>Bw(t,...e),codeToTokensBase:(e,s)=>dp(t,e,s),codeToTokensWithThemes:(e,s)=>Gg(t,e,s),codeToTokens:(e,s)=>Ba(t,e,s),codeToHast:(e,s)=>Da(t,e,s),codeToHtml:(e,s)=>Qw(t,e,s),getBundledLanguages:()=>({}),getBundledThemes:()=>({}),...t,getInternalContext:()=>t}}class pp extends Error{constructor(t){super(t),this.name="ShikiError"}}function ab(){return 2147483648}function cb(){return typeof performance<"u"?performance.now():Date.now()}const lb=(n,t)=>n+(t-n%t)%t;async function hb(n){let t,e;const s={};function r(g){e=g,s.HEAPU8=new Uint8Array(g),s.HEAPU32=new Uint32Array(g)}function i(g,_,x){s.HEAPU8.copyWithin(g,_,_+x)}function a(g){try{return t.grow(g-e.byteLength+65535>>>16),r(t.buffer),1}catch{}}function l(g){const _=s.HEAPU8.length;g=g>>>0;const x=ab();if(g>x)return!1;for(let v=1;v<=4;v*=2){let m=_*(1+.2/v);m=Math.min(m,g+100663296);const y=Math.min(x,lb(Math.max(g,m),65536));if(a(y))return!0}return!1}const c=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0;function h(g,_,x=1024){const v=_+x;let m=_;for(;g[m]&&!(m>=v);)++m;if(m-_>16&&g.buffer&&c)return c.decode(g.subarray(_,m));let y="";for(;_<m;){let w=g[_++];if(!(w&128)){y+=String.fromCharCode(w);continue}const b=g[_++]&63;if((w&224)===192){y+=String.fromCharCode((w&31)<<6|b);continue}const k=g[_++]&63;if((w&240)===224?w=(w&15)<<12|b<<6|k:w=(w&7)<<18|b<<12|k<<6|g[_++]&63,w<65536)y+=String.fromCharCode(w);else{const C=w-65536;y+=String.fromCharCode(55296|C>>10,56320|C&1023)}}return y}function d(g,_){return g?h(s.HEAPU8,g,_):""}const p={emscripten_get_now:cb,emscripten_memcpy_big:i,emscripten_resize_heap:l,fd_write:()=>0};async function u(){const _=await n({env:p,wasi_snapshot_preview1:p});t=_.memory,r(t.buffer),Object.assign(s,_),s.UTF8ToString=d}return await u(),s}var db=Object.defineProperty,ub=(n,t,e)=>t in n?db(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Te=(n,t,e)=>ub(n,typeof t!="symbol"?t+"":t,e);let $e=null;function pb(n){throw new pp(n.UTF8ToString(n.getLastOnigError()))}class ic{constructor(t){Te(this,"utf16Length"),Te(this,"utf8Length"),Te(this,"utf16Value"),Te(this,"utf8Value"),Te(this,"utf16OffsetToUtf8"),Te(this,"utf8OffsetToUtf16");const e=t.length,s=ic._utf8ByteLength(t),r=s!==e,i=r?new Uint32Array(e+1):null;r&&(i[e]=s);const a=r?new Uint32Array(s+1):null;r&&(a[s]=e);const l=new Uint8Array(s);let c=0;for(let h=0;h<e;h++){const d=t.charCodeAt(h);let p=d,u=!1;if(d>=55296&&d<=56319&&h+1<e){const g=t.charCodeAt(h+1);g>=56320&&g<=57343&&(p=(d-55296<<10)+65536|g-56320,u=!0)}r&&(i[h]=c,u&&(i[h+1]=c),p<=127?a[c+0]=h:p<=2047?(a[c+0]=h,a[c+1]=h):p<=65535?(a[c+0]=h,a[c+1]=h,a[c+2]=h):(a[c+0]=h,a[c+1]=h,a[c+2]=h,a[c+3]=h)),p<=127?l[c++]=p:p<=2047?(l[c++]=192|(p&1984)>>>6,l[c++]=128|(p&63)>>>0):p<=65535?(l[c++]=224|(p&61440)>>>12,l[c++]=128|(p&4032)>>>6,l[c++]=128|(p&63)>>>0):(l[c++]=240|(p&1835008)>>>18,l[c++]=128|(p&258048)>>>12,l[c++]=128|(p&4032)>>>6,l[c++]=128|(p&63)>>>0),u&&h++}this.utf16Length=e,this.utf8Length=s,this.utf16Value=t,this.utf8Value=l,this.utf16OffsetToUtf8=i,this.utf8OffsetToUtf16=a}static _utf8ByteLength(t){let e=0;for(let s=0,r=t.length;s<r;s++){const i=t.charCodeAt(s);let a=i,l=!1;if(i>=55296&&i<=56319&&s+1<r){const c=t.charCodeAt(s+1);c>=56320&&c<=57343&&(a=(i-55296<<10)+65536|c-56320,l=!0)}a<=127?e+=1:a<=2047?e+=2:a<=65535?e+=3:e+=4,l&&s++}return e}createString(t){const e=t.omalloc(this.utf8Length);return t.HEAPU8.set(this.utf8Value,e),e}}const oc=class Tt{constructor(t){if(Te(this,"id",++Tt.LAST_ID),Te(this,"_onigBinding"),Te(this,"content"),Te(this,"utf16Length"),Te(this,"utf8Length"),Te(this,"utf16OffsetToUtf8"),Te(this,"utf8OffsetToUtf16"),Te(this,"ptr"),!$e)throw new pp("Must invoke loadWasm first.");this._onigBinding=$e,this.content=t;const e=new ic(t);this.utf16Length=e.utf16Length,this.utf8Length=e.utf8Length,this.utf16OffsetToUtf8=e.utf16OffsetToUtf8,this.utf8OffsetToUtf16=e.utf8OffsetToUtf16,this.utf8Length<1e4&&!Tt._sharedPtrInUse?(Tt._sharedPtr||(Tt._sharedPtr=$e.omalloc(1e4)),Tt._sharedPtrInUse=!0,$e.HEAPU8.set(e.utf8Value,Tt._sharedPtr),this.ptr=Tt._sharedPtr):this.ptr=e.createString($e)}convertUtf8OffsetToUtf16(t){return this.utf8OffsetToUtf16?t<0?0:t>this.utf8Length?this.utf16Length:this.utf8OffsetToUtf16[t]:t}convertUtf16OffsetToUtf8(t){return this.utf16OffsetToUtf8?t<0?0:t>this.utf16Length?this.utf8Length:this.utf16OffsetToUtf8[t]:t}dispose(){this.ptr===Tt._sharedPtr?Tt._sharedPtrInUse=!1:this._onigBinding.ofree(this.ptr)}};Te(oc,"LAST_ID",0);Te(oc,"_sharedPtr",0);Te(oc,"_sharedPtrInUse",!1);let Yg=oc;class fb{constructor(t){if(Te(this,"_onigBinding"),Te(this,"_ptr"),!$e)throw new pp("Must invoke loadWasm first.");const e=[],s=[];for(let l=0,c=t.length;l<c;l++){const h=new ic(t[l]);e[l]=h.createString($e),s[l]=h.utf8Length}const r=$e.omalloc(4*t.length);$e.HEAPU32.set(e,r/4);const i=$e.omalloc(4*t.length);$e.HEAPU32.set(s,i/4);const a=$e.createOnigScanner(r,i,t.length);for(let l=0,c=t.length;l<c;l++)$e.ofree(e[l]);$e.ofree(i),$e.ofree(r),a===0&&pb($e),this._onigBinding=$e,this._ptr=a}dispose(){this._onigBinding.freeOnigScanner(this._ptr)}findNextMatchSync(t,e,s){let r=0;if(typeof s=="number"&&(r=s),typeof t=="string"){t=new Yg(t);const i=this._findNextMatchSync(t,e,!1,r);return t.dispose(),i}return this._findNextMatchSync(t,e,!1,r)}_findNextMatchSync(t,e,s,r){const i=this._onigBinding,a=i.findNextOnigScannerMatch(this._ptr,t.id,t.ptr,t.utf8Length,t.convertUtf16OffsetToUtf8(e),r);if(a===0)return null;const l=i.HEAPU32;let c=a/4;const h=l[c++],d=l[c++],p=[];for(let u=0;u<d;u++){const g=t.convertUtf8OffsetToUtf16(l[c++]),_=t.convertUtf8OffsetToUtf16(l[c++]);p[u]={start:g,end:_,length:_-g}}return{index:h,captureIndices:p}}}function gb(n){return typeof n.instantiator=="function"}function _b(n){return typeof n.default=="function"}function mb(n){return typeof n.data<"u"}function xb(n){return typeof Response<"u"&&n instanceof Response}function yb(n){var t;return typeof ArrayBuffer<"u"&&(n instanceof ArrayBuffer||ArrayBuffer.isView(n))||typeof Buffer<"u"&&((t=Buffer.isBuffer)==null?void 0:t.call(Buffer,n))||typeof SharedArrayBuffer<"u"&&n instanceof SharedArrayBuffer||typeof Uint32Array<"u"&&n instanceof Uint32Array}let wo;function vb(n){if(wo)return wo;async function t(){$e=await hb(async e=>{let s=n;return s=await s,typeof s=="function"&&(s=await s(e)),typeof s=="function"&&(s=await s(e)),gb(s)?s=await s.instantiator(e):_b(s)?s=await s.default(e):(mb(s)&&(s=s.data),xb(s)?typeof WebAssembly.instantiateStreaming=="function"?s=await wb(s)(e):s=await bb(s)(e):yb(s)?s=await Ec(s)(e):s instanceof WebAssembly.Module?s=await Ec(s)(e):"default"in s&&s.default instanceof WebAssembly.Module&&(s=await Ec(s.default)(e))),"instance"in s&&(s=s.instance),"exports"in s&&(s=s.exports),s})}return wo=t(),wo}function Ec(n){return t=>WebAssembly.instantiate(n,t)}function wb(n){return t=>WebAssembly.instantiateStreaming(n,t)}function bb(n){return async t=>{const e=await n.arrayBuffer();return WebAssembly.instantiate(e,t)}}async function kb(n){return n&&await vb(n),{createScanner(t){return new fb(t.map(e=>typeof e=="string"?e:e.source))},createString(t){return new Yg(t)}}}let Cc=null;const tE=()=>{const[n,t]=at.useState(null),[e,s]=at.useState(!0);return at.useEffect(()=>{(async()=>{Cc||(Cc=await ob({themes:[ri(()=>import("./github-dark-DHJKELXO.js"),[]),ri(()=>import("./github-light-DAi9KRSo.js"),[]),ri(()=>import("./vitesse-light-CVO1_9PV.js"),[])],langs:[ri(()=>import("./tsx-COt5Ahok.js"),[])],engine:kb(ri(()=>import("./wasm-CG6Dc4jp.js"),[]))})),t(Cc),s(!1)})()},[]),{highlighter:n,isLoading:e}},hf=()=>{const n=new URLSearchParams(window.location.search),t={};for(const[e,s]of n.entries())t[e]=s;return t},Sb=()=>{const[n,t]=at.useState(hf());return at.useEffect(()=>{const e=()=>{t(hf())};return e(),window.addEventListener("popstate",e),()=>{window.removeEventListener("popstate",e)}},[]),n},Pb=(n,t)=>{const e=JSON.stringify(n,null,2),s=new Blob([e],{type:"application/json"});tt.saveAs(s,t)},Tb=(n,t)=>{const e=$x({circuitJson:n,minTraceWidth:.1}),s=new Blob([JSON.stringify(e,null,2)],{type:"application/json"});tt.saveAs(s,t+"_routes.json")};function Xg(n){if(!n)return"";if("resistance"in n)return n.resistance>=1e3?`${n.resistance/1e3}k`:`${n.resistance}`;if("capacitance"in n){const t=n.capacitance*1e6;return t>=1?`${t}uF`:`${t.toFixed(3)}uF`}return""}function qg(n,t){if(!n||!t)return"";const e=t.width.toFixed(4),s=t.height.toFixed(4);return`${n.ftype}:${e}x${s}_mm`}function ai({shape:n,width:t,height:e,holeDiameter:s,outerDiameter:r,layer:i="top"}){const a={top:"T",bottom:"B",all:"A"}[i]??"T";switch(n){case"circle":return`Round[${a}]Pad_${s}_${r}_um`;case"oval":return`Oval[${a}]Pad_${t}x${e}_um`;case"pill":return`Oval[${a}]Pad_${t}x${e}_um`;case"rect":return`RoundRect[${a}]Pad_${t}x${e}_um`;default:return"default_pad"}}function Eb(n,t,e){return{name:n,shapes:[{shapeType:"circle",layer:"F.Cu",diameter:t},{shapeType:"circle",layer:"B.Cu",diameter:t}],hole:{shape:"circle",diameter:e},attach:"off"}}function Cb(n,t,e,s,r){const i=Math.abs(t-e)/2,a=t>e;return{name:n,shapes:[{shapeType:"path",layer:"F.Cu",width:a?e:t,coordinates:a?[-i,0,i,0]:[0,-i,0,i]},{shapeType:"path",layer:"B.Cu",width:a?e:t,coordinates:a?[-i,0,i,0]:[0,-i,0,i]}],hole:{shape:"oval",width:s,height:r},attach:"off"}}function Nb(n,t,e,s){const r=t/2,i=e/2;return{name:n,shapes:[{shapeType:"polygon",layer:s==="bottom"?"B.Cu":"F.Cu",width:0,coordinates:[-r,i,r,i,r,-i,-r,-i,-r,i]}],attach:"off"}}var $b=pr(1e3);function Ab(n,t,e){var i;const s=new Set,r=new Map;for(const a of n){const{pcb_component_id:l,pcb_smtpads:c}=a;if(c.length===0)continue;const h=ct(t).pcb_component.list().find(_=>_.pcb_component_id===l),d=ct(t).source_component.list().find(_=>_.source_component_id===(h==null?void 0:h.source_component_id)),p=qg(d,h),u=(d==null?void 0:d.name)||"Unknown",g=B($b,h.center);r.has(p)||r.set(p,[]),(i=r.get(p))==null||i.push({componentName:u,coordinates:g,rotation:(h==null?void 0:h.rotation)||0,value:Xg(d),sourceComponent:d})}for(const[a,l]of r){const c=l[0],h=n.find(u=>{const g=t.find(_=>{var x;return _.type==="pcb_component"&&_.source_component_id===((x=c.sourceComponent)==null?void 0:x.source_component_id)});return g&&u.pcb_component_id===g.pcb_component_id});if(!h)continue;for(const u of h.pcb_smtpads)if(u.shape==="rect"){const g=ai({shape:"rect",width:u.width*1e3,height:u.height*1e3,layer:u.layer});if(!s.has(g)){const _=Math.round(u.width*1e3),x=Math.round(u.height*1e3),v=Nb(g,_,x,u.layer);e.library.padstacks.push(v),s.add(g)}}const d={name:a,outlines:[],pins:h.pcb_smtpads.map(u=>{var _;const g=t.find(x=>{var v;return x.type==="pcb_component"&&x.source_component_id===((v=c.sourceComponent)==null?void 0:v.source_component_id)});if(u.shape==="rect"){const x=ct(t).pcb_port.list().find(m=>m.pcb_port_id===u.pcb_port_id),v=ct(t).source_port.list().find(m=>m.source_port_id===(x==null?void 0:x.source_port_id));return{padstack_name:ai({shape:"rect",width:u.width*1e3,height:u.height*1e3,layer:u.layer}),pin_number:((_=v==null?void 0:v.port_hints)==null?void 0:_.find(m=>!Number.isNaN(Number(m))))||1,x:(u.x-g.center.x)*1e3,y:(u.y-g.center.y)*1e3}}}).filter(u=>u!==void 0)};e.library.images.push(d);const p={name:a,places:l.map(u=>{var g;return{refdes:`${u.componentName}_${(g=u.sourceComponent)==null?void 0:g.source_component_id}`,x:u.coordinates.x,y:u.coordinates.y,side:"front",rotation:u.rotation%90,PN:u.value}})};e.placement.components.push(p)}}function Ib(n,t){var a,l,c;const e=new Map;for(const h of n)h.type==="source_component"&&e.set(h.source_component_id,h.name);const s=new Map;for(const h of n)if((h.type==="pcb_smtpad"||h.type==="pcb_plated_hole")&&h.pcb_port_id){const d=ct(n).pcb_port.list().find(p=>p.pcb_port_id===h.pcb_port_id);if(d&&"source_port_id"in d){const p=ct(n).source_port.list().find(u=>u.source_port_id===d.source_port_id);if(p&&"source_component_id"in p){const u=e.get(p.source_component_id)||"",g=(a=p.port_hints)==null?void 0:a.find(_=>!Number.isNaN(Number(_)));s.set(p.source_port_id,{componentName:`${u}_${p.source_component_id}`,pinNumber:g,sourcePortId:p.source_port_id})}}}const r=new Map;for(const h of n)if(h.type==="source_trace"&&h.connected_source_port_ids){const d=h.connected_source_port_ids;if(d.length>=2){const p=s.get(d[0]);if(p){const u=`Net-(${p.componentName}-Pad${p.pinNumber})`;r.has(u)||r.set(u,new Set);for(const g of d){const _=s.get(g);_&&((l=r.get(u))==null||l.add(`${_.componentName}-${_.pinNumber}`))}}}}for(const[h,d]of s){let p=!1;const u=`${d.componentName}-${d.pinNumber.replace("pin","")}`;for(const[_,x]of r.entries())if(Array.from(x).some(v=>(v==null?void 0:v.toString())===u||(v==null?void 0:v.toString())===`${d.componentName}-${d.pinNumber}`)){p=!0;break}let g=!1;for(const _ of n)if(_.type==="source_net"&&n.filter(v=>{var m,y;return v.type==="source_trace"&&((m=v.connected_source_net_ids)==null?void 0:m.includes(_.source_net_id))&&((y=v.connected_source_port_ids)==null?void 0:y.includes(h))}).length>0){g=!0;break}if(!p&&!g){const _=`unconnected-(${d.componentName}-Pad${d.pinNumber.replace("pin","")})`;r.set(_,new Set([`${d.componentName}-${d.pinNumber}`]))}}for(const h of n)if(h.type==="source_net"){const d=`${h.name}_${h.source_net_id}`;r.has(d)||r.set(d,new Set);const p=n.filter(u=>{var g;return u.type==="source_trace"&&((g=u.connected_source_net_ids)==null?void 0:g.includes(h.source_net_id))});for(const u of p)for(const g of u.connected_source_port_ids||[]){const _=s.get(g);_&&((c=r.get(d))==null||c.add(`${_.componentName}-${_.pinNumber}`))}}const i=Array.from(r.keys()).sort((h,d)=>h==="GND"?-1:d==="GND"?1:h==="VCC"?-1:d==="VCC"?1:h.startsWith("Net-")&&!d.startsWith("Net-")?-1:!h.startsWith("Net-")&&d.startsWith("Net-")?1:h.localeCompare(d));for(const h of i)t.network.nets.push({name:h,pins:Array.from(r.get(h)||[]).map(d=>d.replace("pin",""))});t.network.classes[0].net_names=i}function df(n,t,e){const s=`Via[0-1]_${t}:${e}_um`,r=n.getLibrary();if(r.padstacks.find(l=>l.name===s))return s;const a={name:s,attach:"off",shapes:[{shapeType:"circle",layer:"F.Cu",diameter:t},{shapeType:"circle",layer:"B.Cu",diameter:t}],hole:{shape:"circle",diameter:e}};return r.padstacks.push(a),s}var Lb=n=>({getNextNetId:()=>`Net-${n.network.nets.length+1}`,addWire:t=>{n.wiring.wires.push(t)},getStructure:()=>n.structure,getLibrary:()=>n.library});function Mb(n,t){var s;const e=[];for(const r of t){const i=n.find(h=>h.type==="source_port"&&h.source_port_id===r);if(!i)continue;const a=n.find(h=>h.type==="source_component"&&h.source_component_id===i.source_component_id);if(!a)continue;const l=a.name||a.source_component_id,c=i.name||((s=i.pin_number)==null?void 0:s.toString())||r;e.push({displayName:`Pad${c.replace("pin","")}_${l}_${i.source_component_id}`})}return e.map(r=>r.displayName).join("--")}var ki=Mt("dsn-converter:processPcbTraces"),bo=600,uf=300;function Rb(n){return{path:{layer:n.layer==="top"?"F.Cu":"B.Cu",width:n.widthMm*1e3,coordinates:[]},net:n.netName,type:"route"}}function Ob(n,t){var r,i;const e=Lb(t),s=1e3;for(const a of n)if(a.type==="pcb_trace"){const l=a,c=ct(n).source_trace.getWhere({source_trace_id:l.source_trace_id}),h=c&&ct(n).source_net.list().find(_=>c.connected_source_net_ids.includes(_.source_net_id));ki(`PCB TRACE
|
|
33
|
+
----------
|
|
34
|
+
`,l);const d=Mb(n,(c==null?void 0:c.connected_source_port_ids)||[]),p=(h==null?void 0:h.name)||`${l.source_trace_id}--${d}`||e.getNextNetId();let u="",g=null;for(let _=0;_<l.route.length;_++){const x=l.route[_];if(ki(`POINT
|
|
35
|
+
------
|
|
36
|
+
`,x),x.route_type==="wire"){const v=u&&x.layer!==u;if(!g&&(g=Rb({layer:x.layer,widthMm:x.width,netName:p}),e.addWire(g),u=x.layer),g&&!v){g.path.coordinates.push(x.x*s),g.path.coordinates.push(x.y*s);continue}if(v){const y=l.route[_-1],w=df(e,bo,uf);e.getStructure()&&!((r=e.getStructure())!=null&&r.via)&&(e.getStructure().via=w),e.addWire({path:{layer:u==="top"?"F.Cu":"B.Cu",width:bo,coordinates:[y.x*s,y.y*s]},net:p,type:"via"})}continue}if(x.route_type==="via"){ki(`VIA
|
|
37
|
+
----
|
|
38
|
+
`,x),g&&(g.path.coordinates.push(x.x*s),g.path.coordinates.push(x.y*s),g=null);const v=df(e,bo,uf);ki("VIA PADSTACK NAME:",v),e.getStructure()&&!((i=e.getStructure())!=null&&i.via)&&(e.getStructure().via=v),e.addWire({path:{layer:x.from_layer==="top"?"F.Cu":"B.Cu",width:bo,coordinates:[x.x*s,x.y*s]},net:p,type:"via"}),u=x.to_layer,g=null}}}ki("PCB WIRING/NETWORK_OUT AT END",JSON.stringify(t.wiring,null,2))}var Fb=pr(1e3);function zb(n,t,e){var i;const s=new Set,r=new Map;for(const a of n){const{pcb_component_id:l,pcb_plated_holes:c,pcb_smtpads:h}=a;if(c.length===0)continue;const d=ct(t).pcb_component.list().find(m=>m.pcb_component_id===l),p=d&&ct(t).source_component.list().find(m=>m.source_component_id===d.source_component_id);if(!d)continue;const u=qg(p,d),g=p.name||"Unknown",_=B(Fb,d.center);h.length===0&&(r.has(u)||r.set(u,[]),(i=r.get(u))==null||i.push({componentName:g,coordinates:_,rotation:(d==null?void 0:d.rotation)||0,value:Xg(p),sourceComponent:p}));for(const m of c)if(m.shape==="circle"){const y=ai({shape:"circle",holeDiameter:m.hole_diameter*1e3,outerDiameter:m.outer_diameter*1e3,layer:"all"});if(!s.has(y)){const w=Math.round(m.outer_diameter*1e3);e.library.padstacks.push(Eb(y,w,w)),s.add(y)}}else if(m.shape==="oval"||m.shape==="pill"){const y=ai({shape:m.shape,width:m.hole_width*1e3,height:m.hole_height*1e3,layer:"all"});if(!s.has(y)){const w=Math.round(m.hole_width*1e3),b=Math.round(m.hole_height*1e3),k=Math.round(m.outer_width*1e3),C=Math.round(m.outer_height*1e3);e.library.padstacks.push(Cb(y,k,C,w,b)),s.add(y)}}let x=e.library.images.find(m=>m.name===u);x||(x={name:u,outlines:[],pins:[]},e.library.images.push(x));const v=c.map(m=>{var b,k;const y=ct(t).pcb_port.list().find(C=>C.pcb_port_id===m.pcb_port_id),w=y&&ct(t).source_port.list().find(C=>C.source_port_id===y.source_port_id);if(m.shape==="circle"){const C={padstack_name:ai({shape:"circle",holeDiameter:m.hole_diameter*1e3,outerDiameter:m.outer_diameter*1e3,layer:"all"}),pin_number:((b=w==null?void 0:w.port_hints)==null?void 0:b.find(E=>!Number.isNaN(Number(E))))||1,x:(Number(m.x.toFixed(3))-d.center.x)*1e3,y:(Number(m.y.toFixed(3))-d.center.y)*1e3};return x.pins.some(E=>{const N=E.pin_number===C.pin_number,I=E.x===C.x&&E.y===C.y&&E.padstack_name===C.padstack_name;return N||I})?void 0:C}else if(m.shape==="oval"||m.shape==="pill"){const C={padstack_name:ai({shape:m.shape,width:m.hole_width*1e3,height:m.hole_height*1e3,layer:"all"}),pin_number:((k=w==null?void 0:w.port_hints)==null?void 0:k.find(E=>!Number.isNaN(Number(E))))||1,x:(Number(m.x.toFixed(3))-d.center.x)*1e3,y:(Number(m.y.toFixed(3))-d.center.y)*1e3};return x.pins.some(E=>E.x===C.x&&E.y===C.y&&E.padstack_name===C.padstack_name)?void 0:C}}).filter(m=>m!==void 0);x.pins.push(...v)}for(const[a,l]of r){const c={name:a,places:l.map(h=>{var d;return{refdes:`${h.componentName}_${(d=h.sourceComponent)==null?void 0:d.source_component_id}`,x:h.coordinates.x,y:h.coordinates.y,side:"front",rotation:h.rotation%90,PN:h.value}})};e.placement.components.push(c)}}function Ub(n){const t=n.find(r=>r.type==="pcb_board"),e={is_dsn_pcb:!0,filename:"",parser:{string_quote:"",host_version:"",space_in_quoted_tokens:"",host_cad:""},resolution:{unit:"um",value:10},unit:"um",structure:{layers:[{name:"F.Cu",type:"signal",property:{index:0}},{name:"B.Cu",type:"signal",property:{index:1}}],boundary:{path:{layer:"pcb",width:0,coordinates:jb(t)}},via:"Via[0-1]_600:300_um",rule:{clearances:[{value:200},{value:200,type:"default_smd"},{value:50,type:"smd_smd"}],width:200}},placement:{components:[]},library:{images:[],padstacks:[{name:"Via[0-1]_600:300_um",shapes:[{shapeType:"circle",layer:"F.Cu",diameter:600},{shapeType:"circle",layer:"B.Cu",diameter:600}],attach:"off"}]},network:{nets:[],classes:[{name:"kicad_default",description:"",net_names:[],circuit:{use_via:"Via[0-1]_600:300_um"},rule:{clearances:[{value:200,type:""}],width:100}}]},wiring:{wires:[]}},s=Bb(n);return Ab(s,n,e),zb(s,n,e),Ib(n,e),Ob(n,e),e}function jb(n){var h,d;const t=(n==null?void 0:n.width)??100,e=(n==null?void 0:n.height)??100,s=((h=n==null?void 0:n.center)==null?void 0:h.x)??0,r=((d=n==null?void 0:n.center)==null?void 0:d.y)??0,i=t*1e3/2,a=e*1e3/2,l=s*1e3,c=r*1e3;return[l-i,c-a,l+i,c-a,l+i,c+a,l-i,c+a,l-i,c-a]}function Bb(n){var e,s;const t=new Map;for(const r of n)if(r.type==="pcb_smtpad"||r.type==="pcb_plated_hole"){const i=r.pcb_component_id??"";t.has(i)||t.set(i,{pcb_component_id:i,pcb_smtpads:[],pcb_plated_holes:[]}),r.type==="pcb_smtpad"?(e=t.get(i))==null||e.pcb_smtpads.push(r):r.type==="pcb_plated_hole"&&((s=t.get(i))==null||s.pcb_plated_holes.push(r))}return Array.from(t.values())}Mt("dsn-converter:mergeDsnSessionIntoDsnPcb");var Db=n=>{var a;let e="";const s=l=>l==null?'""':typeof l=="string"?`"${l}"`:l.toString(),r=l=>l.join(" "),i=(l,c)=>`${" ".repeat(c)}(path ${l.layer} ${l.width} ${r(l.coordinates)})`;return e+=`(pcb ./converted_dsn.dsn
|
|
39
|
+
`,e+=` (parser
|
|
40
|
+
`,e+=` (string_quote ")
|
|
41
|
+
`,e+=` (space_in_quoted_tokens on)
|
|
42
|
+
`,e+=` (host_cad "KiCad's Pcbnew")
|
|
43
|
+
`,e+=` (host_version "${n.parser.host_version}")
|
|
44
|
+
`,e+=` )
|
|
45
|
+
`,e+=` (resolution ${n.resolution.unit} ${n.resolution.value})
|
|
46
|
+
`,e+=` (unit ${n.unit})
|
|
47
|
+
`,e+=` (structure
|
|
48
|
+
`,n.structure.layers.forEach(l=>{e+=` (layer ${l.name}
|
|
49
|
+
`,e+=` (type ${l.type})
|
|
50
|
+
`,e+=` (property
|
|
51
|
+
`,e+=` (index ${l.property.index})
|
|
52
|
+
`,e+=` )
|
|
53
|
+
`,e+=` )
|
|
54
|
+
`}),n.structure.boundary&&(e+=` (boundary
|
|
55
|
+
`,e+=` ${i(n.structure.boundary.path,0)}
|
|
56
|
+
`,e+=` )
|
|
57
|
+
`),e+=` (via ${s(n.structure.via)})
|
|
58
|
+
`,e+=` (rule
|
|
59
|
+
`,e+=` (width ${n.structure.rule.width})
|
|
60
|
+
`,n.structure.rule.clearances.forEach(l=>{e+=` (clearance ${l.value}${l.type?` (type ${l.type})`:""})
|
|
61
|
+
`}),e+=` )
|
|
62
|
+
`,e+=` )
|
|
63
|
+
`,e+=` (placement
|
|
64
|
+
`,n.placement.components.forEach(l=>{e+=` (component ${s(l.name)}
|
|
65
|
+
`,l.places&&l.places.forEach(c=>{e+=` (place ${c.refdes} ${c.x} ${c.y} ${c.side} ${c.rotation}${c.PN?` (PN ${s(c.PN)})`:""})
|
|
66
|
+
`}),e+=` )
|
|
67
|
+
`}),e+=` )
|
|
68
|
+
`,e+=` (library
|
|
69
|
+
`,n.library.images.forEach(l=>{e+=` (image ${s(l.name)}
|
|
70
|
+
`,l.outlines.forEach(c=>{e+=` (outline ${i(c.path,4)})
|
|
71
|
+
`}),l.pins.forEach(c=>{e+=` (pin ${c.padstack_name} ${c.pin_number} ${c.x} ${c.y})
|
|
72
|
+
`}),e+=` )
|
|
73
|
+
`}),n.library.padstacks.forEach(l=>{e+=` (padstack ${s(l.name)}
|
|
74
|
+
`,l.shapes.forEach(c=>{c.shapeType==="polygon"?e+=` (shape (polygon ${c.layer} ${c.width} ${r(c.coordinates)}))
|
|
75
|
+
`:c.shapeType==="circle"?e+=` (shape (circle ${c.layer} ${c.diameter}))
|
|
76
|
+
`:c.shapeType==="path"&&(e+=` (shape (path ${c.layer} ${c.width} ${r(c.coordinates)}))
|
|
77
|
+
`)}),e+=` (attach ${l.attach})
|
|
78
|
+
`,e+=` )
|
|
79
|
+
`}),e+=` )
|
|
80
|
+
`,e+=` (network
|
|
81
|
+
`,n.network.nets.forEach(l=>{e+=` (net ${s(l.name)}
|
|
82
|
+
`,l.pins.length>0&&(e+=` (pins ${l.pins.join(" ")})
|
|
83
|
+
`),e+=` )
|
|
84
|
+
`}),n.network.classes.forEach(l=>{e+=` (class ${s(l.name)} ${s(l.description)}${l.net_names.map(c=>` ${s(c)}`).join("")}
|
|
85
|
+
`,e+=` (circuit
|
|
86
|
+
`,e+=` (use_via ${s(l.circuit.use_via)})
|
|
87
|
+
`,e+=` )
|
|
88
|
+
`,l.rule&&(e+=` (rule
|
|
89
|
+
`,e+=` (width ${l.rule.width})
|
|
90
|
+
`,l.rule.clearances.forEach(c=>{e+=` (clearance ${c.value}${c.type?` (type ${c.type})`:""})
|
|
91
|
+
`}),e+=` )
|
|
92
|
+
`),e+=` )
|
|
93
|
+
`}),e+=` )
|
|
94
|
+
`,e+=` (wiring
|
|
95
|
+
`,(((a=n.wiring)==null?void 0:a.wires)??[]).forEach(l=>{l.type==="via"?e+=` (via ${i(l.path,3)}(net ${s(l.net)}))
|
|
96
|
+
`:e+=` (wire ${i(l.path,3)}(net ${s(l.net)})(type ${l.type}))
|
|
97
|
+
`}),e+=` )
|
|
98
|
+
`,e+=`)
|
|
99
|
+
`,e},Wb=n=>{const t=Ub(n);return Db(t)};Mt("dsn-converter:convertPadstacksToSmtpads");Mt("dsn-converter:convertWiringPathToPcbTraces");Mt("dsn-converter:convertWiringViaToPcbVias");Mt("dsn-converter:convertWiresToPcbTraces");Mt("dsn-converter");Mt("dsn-converter:getPinNum");Mt("dsn-converter:getViaCoords");Mt("dsn-converter:parse-dsn-to-dsn-json");const Gb=(n,t)=>{const e=Wb(n),s=new Blob([e],{type:"text/plain"});tt.saveAs(s,t+".dsn")},Vb=async({circuitJson:n,snippetUnscopedName:t})=>{const e=new ig,s=Ax(n,{flip_y_axis:!1}),r=Ix(s);for(const[p,u]of Object.entries(r))e.file(`gerber/${p}.gbr`,u);const i=Lx({circuitJson:n,is_plated:!0,flip_y_axis:!1}),a=Mx(i);e.file("gerber/drill.drl",a);const l=await Rx({circuitJson:n}),c=await Ox(l);e.file("bom.csv",c);const h=await Fx(n);e.file("pick_and_place.csv",h);const d=await e.generateAsync({type:"blob"});tt.saveAs(d,`${t}_fabrication_files.zip`)},Hb=(n,t)=>{const e=og(n),s=new Blob([e],{type:"image/svg"});tt.saveAs(s,t+".svg")};var Yb={MISO:1.2,MOSI:1.2,SCLK:1.2,SDA:1.2,SCL:1.2,RX:1.15,TX:1.15,GPIO:1.1,cathode:.5,anode:.5,GND:1.1,VDD:1.1,AGND:1.1,V5:1.1,V3:1.1,V1:1.1,neg:.9,pos:.9,pin:.5,left:.3,right:.3},Xb=Object.entries(Yb).sort((n,t)=>t[1]-n[1]),Kg=n=>{if(n.match(/\d+/))return .5;for(const[t,e]of Xb)if(n.includes(t))return e;return 1},pf=({circuitJson:n,source_port_id:t})=>{var p,u;const e=Ge(n).source_port.list(),s=Ge(n).source_component.list(),r=e.find(g=>g.source_port_id===t);if(!r)return"";const i=s.find(g=>g.source_component_id===r.source_component_id);if(!i)return"";const a=(p=r.port_hints)==null?void 0:p.some(g=>["anode","pos","positive"].includes(g.toLowerCase())),l=(u=r.port_hints)==null?void 0:u.some(g=>["cathode","neg","negative"].includes(g.toLowerCase())),c=r.name?r.name:`Pin${r.pin_number}`,h=[];a&&i.ftype!=="simple_resistor"?h.push("+"):l&&i.ftype!=="simple_resistor"&&h.push("-");for(const g of r.port_hints??[]){if(g===c)continue;Kg(g)>1&&h.push(g)}const d=i.display_value?` (${i.display_value})`:"";return`${i.name} ${c}${h.length>0?` (${h.join(",")})`:""}${d}`},qb=n=>!("ftype"in n)||n.ftype==="simple_resistor"?0:n.ftype==="simple_capacitor"?1:2,ff=({circuitJson:n,connectedIds:t})=>{const e=Ge(n).source_component.list(),s=new Map;for(const _ of e)s.set(_.source_component_id,qb(_));e.sort((_,x)=>s.get(x.source_component_id)-s.get(_.source_component_id));const r=Ge(n).source_port.list().sort((_,x)=>s.get(x.source_component_id)-s.get(_.source_component_id)),i=Ge(n).source_net.list(),a=Ge(n).source_trace.list(),l=r.filter(_=>t.includes(_.source_port_id)),c=i.filter(_=>t.includes(_.source_net_id));a.filter(_=>t.includes(_.source_trace_id));const p=l.flatMap(_=>Array.from(new Set([..._.name?[_.name]:[],..._.port_hints??[]]))).concat(c.map(_=>_.name)).map(_=>({name:_,score:Kg(_)})).sort((_,x)=>x.score-_.score)[0].name,u=l.find(_=>{var x;return _.name===p||((x=_.port_hints)==null?void 0:x.includes(p))}),g=e.find(_=>_.source_component_id===(u==null?void 0:u.source_component_id));return[g==null?void 0:g.name,p].filter(Boolean).join("_")},Kb=n=>{const e=ag(n.filter(h=>h.type.startsWith("source_"))).netMap,s=Ge(n).source_port.list(),r=Ge(n).source_component.list(),i=Ge(n).source_net.list();Ge(n).source_trace.list();const a=[];a.push("COMPONENTS:");for(const h of r){let d="";const p=Ge(n).cad_component.getWhere({source_component_id:h.source_component_id}),u=p==null?void 0:p.footprinter_string;h.ftype==="simple_resistor"?d=`${h.display_resistance}${u?` ${u}`:""} resistor`:h.ftype==="simple_capacitor"?d=`${h.display_capacitance}${u?` ${u}`:""} capacitor`:h.ftype==="simple_chip"?d=[h.manufacturer_part_number,u].filter(Boolean).join(", "):d=[h.name,h.type].filter(Boolean).join(", "),a.push(` - ${h.name}: ${d}`)}a.push("");for(const[h,d]of Object.entries(e)){const p=i.find(_=>d.includes(_.source_net_id));let u=p==null?void 0:p.name;if(u||(u=ff({circuitJson:n,connectedIds:d})),!(d.filter(_=>_.startsWith("source_port")).length<=1)){a.push(`NET: ${u}`);for(const _ of d){const x=pf({circuitJson:n,source_port_id:_});x&&a.push(` - ${x}`)}a.push("")}}let l=!1;for(const[h,d]of Object.entries(e))if(d.filter(u=>u.startsWith("source_port")).length===1){l||(a.push(""),a.push("EMPTY NET PINS:"),l=!0);const u=e[h].find(_=>_.startsWith("source_port")),g=pf({circuitJson:n,source_port_id:u});g&&a.push(` - ${g}`)}const c={};for(const[h,d]of Object.entries(e)){const p=d.filter(_=>_.startsWith("source_port"));if(p.length===0)continue;const u=i.find(_=>d.includes(_.source_net_id));let g=u==null?void 0:u.name;g||(g=ff({circuitJson:n,connectedIds:d}));for(const _ of p)c[_]||(c[_]=[]),c[_].push(g)}if(r.length>0){a.push(""),a.push("COMPONENT_PINS:");for(const h of r){const d=Ge(n).cad_component.getWhere({source_component_id:h.source_component_id}),p=d==null?void 0:d.footprinter_string;let u=h.name;h.ftype==="simple_resistor"?u=`${h.name} (${h.display_resistance} ${p})`:h.ftype==="simple_capacitor"?u=`${h.name} (${h.display_capacitance} ${p})`:h.manufacturer_part_number&&(u=`${h.name} (${h.manufacturer_part_number})`),a.push(u);const g=s.filter(_=>_.source_component_id===h.source_component_id).sort((_,x)=>(_.pin_number??0)-(x.pin_number??0));for(const _ of g){const x=_.pin_number!==void 0?`pin${_.pin_number}`:_.name,v=[];_.name&&_.name!==x&&v.push(_.name);for(const b of _.port_hints??[])b!==String(_.pin_number)&&b!==x&&b!==_.name&&v.push(b);const m=v.length>0?`(${Array.from(new Set(v)).join(", ")})`:"",y=c[_.source_port_id]??[],w=y.length>0?`NETS(${y.join(", ")})`:"NOT_CONNECTED";a.push(`- ${x}${m}: ${w}`)}a.push("")}}return a.join(`
|
|
100
|
+
`)};const Jb=(n,t)=>{const e=Kb(n),s=new Blob([e],{type:"text/plain"});tt.saveAs(s,t+".txt")};var Zb=n=>{const t=[];t.push(n.title);for(const e of n.components)t.push(e.toSpiceString());return t.push(".END"),t.join(`
|
|
101
|
+
`)},Qb=class{constructor(n="Circuit Netlist"){o(this,"title");o(this,"components");o(this,"nodes");this.title=n,this.components=[],this.nodes=new Set}addComponent(n){this.components.push(n);for(const t of n.nodes)this.nodes.add(t)}toSpiceString(){return Zb(this)}},gf=class{constructor(n,t,e){o(this,"name");o(this,"command");o(this,"nodes");this.name=n,this.command=t,this.nodes=e}toSpiceString(){return this.command.toSpiceString()}},ek=class{constructor(n){o(this,"commandName","resistor");o(this,"props");this.props=n}toSpiceString(){const{name:n,positiveNode:t,negativeNode:e,model:s,value:r}=this.props;let i=`R${n} ${t} ${e}`;return s&&(i+=` ${s}`),i+=` ${r}`,i}},tk=class{constructor(n){o(this,"commandName","capacitor");o(this,"props");this.props=n}toSpiceString(){const{name:n,positiveNode:t,negativeNode:e,modelName:s,value:r,initialCondition:i}=this.props;let a=`C${n} ${t} ${e}`;return s&&(a+=` ${s}`),a+=` ${r}`,i&&(a+=` IC=${i}`),a}};function sk(n){const t=new Qb("Circuit JSON to SPICE Netlist"),e=n.filter(l=>l.type==="source_component"),s=n.filter(l=>l.type==="source_port"),r=n.filter(l=>l.type==="source_trace"),i=new Map;let a=1;for(const l of r)if(l.type==="source_trace"){const c=l.connected_source_port_ids||[];if(c.length>0){const h=`N${a++}`;for(const d of c)i.set(d,h)}}for(const l of e){if(l.type!=="source_component")continue;const h=s.filter(d=>d.type==="source_port"&&d.source_component_id===l.source_component_id).map(d=>i.get(d.source_port_id)||`N${a++}`);if("ftype"in l){let d=null;switch(l.ftype){case"simple_resistor":{if("resistance"in l&&"name"in l){const p=new ek({name:l.name,positiveNode:h[0]||"0",negativeNode:h[1]||"0",value:nk(l.resistance)});d=new gf(l.name,p,h)}break}case"simple_capacitor":{if("capacitance"in l&&"name"in l){const p=new tk({name:l.name,positiveNode:h[0]||"0",negativeNode:h[1]||"0",value:rk(l.capacitance)});d=new gf(l.name,p,h)}break}}d&&t.addComponent(d)}}return t}function nk(n){return n>=1e6?`${n/1e6}MEG`:n>=1e3?`${n/1e3}K`:n.toString()}function rk(n){return n>=.001?`${n*1e3}M`:n>=1e-6?`${n*1e6}U`:n>=1e-9?`${n*1e9}N`:n>=1e-12?`${n*1e12}P`:n.toString()}const ik=(n,t)=>{const s=sk(n).toSpiceString(),r=new Blob([s],{type:"text/plain"});tt.saveAs(r,t+".cir")},ok=(n,t)=>{const e=cg(n),s=new Blob([e],{type:"image/svg"});tt.saveAs(s,t+".svg")},Sa=at.forwardRef(({className:n,...t},e)=>P.jsx(lg,{ref:e,className:zp("peer h-4 w-4 shrink-0 rounded-sm border border-slate-200 border-slate-900 shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-slate-950 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-slate-900 data-[state=checked]:text-slate-50 dark:border-slate-800 dark:border-slate-50 dark:focus-visible:ring-slate-300 dark:data-[state=checked]:bg-slate-50 dark:data-[state=checked]:text-slate-900",n),...t,children:P.jsx(zx,{className:zp("flex items-center justify-center text-current"),children:P.jsx(Ux,{className:"h-4 w-4"})})}));Sa.displayName=lg.displayName;const ak=(n,t,e={})=>{const s={};e.layer&&e.layer!=="all"&&(s.layer=e.layer),e.matchAspectRatio&&(s.matchBoardAspectRatio=!0),typeof e.drawPaddingOutsideBoard=="boolean"&&(s.drawPaddingOutsideBoard=e.drawPaddingOutsideBoard),e.backgroundColor&&(s.backgroundColor=e.backgroundColor);const r=np(n,s),i=new Blob([r],{type:"image/svg+xml"});tt.saveAs(i,t+".svg")},ck=({open:n,onOpenChange:t,circuitJson:e,fileName:s})=>{const[r,i]=at.useState("all"),[a,l]=at.useState(!0),[c,h]=at.useState(!1),[d,p]=at.useState(!1),u=()=>{ak(e,s,{layer:r,drawPaddingOutsideBoard:a,backgroundColor:c?"transparent":"#000",matchAspectRatio:d}),t(!1)};return P.jsx(jx,{open:n,onOpenChange:t,children:P.jsxs(Bx,{children:[P.jsx(Dx,{children:P.jsx(Wx,{children:"Download PCB SVG"})}),P.jsxs("div",{className:"space-y-4 py-2",children:[P.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[P.jsx(mo,{htmlFor:"layer",className:"text-right",children:"Layer"}),P.jsxs(cy,{value:r,onValueChange:g=>i(g),children:[P.jsx(ly,{id:"layer",className:"col-span-3",children:P.jsx(hy,{placeholder:"Layer"})}),P.jsxs(dy,{className:"!z-[999]",children:[P.jsx(yc,{value:"all",children:"All"}),P.jsx(yc,{value:"top",children:"Top"}),P.jsx(yc,{value:"bottom",children:"Bottom"})]})]})]}),P.jsxs("div",{className:"flex items-center space-x-2",children:[P.jsx(Sa,{id:"padding",checked:a,onCheckedChange:g=>l(!!g)}),P.jsx(mo,{htmlFor:"padding",children:"Draw Padding and Board Outline"})]}),P.jsxs("div",{className:"flex items-center space-x-2",children:[P.jsx(Sa,{id:"transparentBg",checked:c,onCheckedChange:g=>h(!!g)}),P.jsx(mo,{htmlFor:"transparentBg",children:"Transparent Background"})]}),P.jsxs("div",{className:"flex items-center space-x-2",children:[P.jsx(Sa,{id:"matchAspectRatio",checked:d,onCheckedChange:g=>p(!!g)}),P.jsx(mo,{htmlFor:"matchAspectRatio",children:"Match Aspect Ratio"})]})]}),P.jsxs(Gx,{children:[P.jsx(Aa,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),P.jsx(Aa,{onClick:u,children:"Download"})]})]})})},lk=ny(ck);function hk(n){const t=[];let e=0;const s=l=>/\s/.test(l),r=l=>/[^\s()"]/u.test(l),i=()=>e<n.length?n[e]:void 0,a=()=>{if(e>=n.length)throw new SyntaxError("Unexpected end of input");return n[e++]};for(;e<n.length;){const l=i();if(l===void 0)break;const c=l;if(s(c)){e++;continue}if(c===";"){for(;e<n.length&&n[e]!==`
|
|
102
|
+
`;)e++;continue}if(c==="("){t.push({type:"lparen"}),e++;continue}if(c===")"){t.push({type:"rparen"}),e++;continue}if(c==='"'){e++;let h="";for(;e<n.length;){const d=a();if(d==='"')break;if(d==="\\"){if(e>=n.length)throw new SyntaxError("Unterminated escape in string");const p=a();switch(p){case"n":h+=`
|
|
103
|
+
`;break;case"r":h+="\r";break;case"t":h+=" ";break;case'"':h+='"';break;case"\\":h+="\\";break;default:h+=p;break}}else h+=d}if(n[e-1]!=='"')throw new SyntaxError("Unterminated string literal");t.push({type:"string",value:h});continue}if(r(c)||c==="-"||c==="+"||c==="."){let h=e;for(;e<n.length;){const p=n[e];if(s(p)||p==="("||p===")"||p==='"')break;e++}const d=n.slice(h,e);if(d==="#t"){t.push({type:"boolean",value:!0});continue}if(d==="#f"){t.push({type:"boolean",value:!1});continue}if(d==="nil"){t.push({type:"nil"});continue}/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/u.test(d)?t.push({type:"number",value:Number(d)}):t.push({type:"symbol",value:d});continue}throw new SyntaxError(`Unexpected character: ${JSON.stringify(l)} at ${e}`)}return t}function dk(n){const t=hk(n);let e=0;const s=()=>e<t.length?t[e]:void 0,r=()=>{if(e>=t.length)throw new SyntaxError("Unexpected end of input");return t[e++]};function i(){const l=r();switch(l.type){case"lparen":{const c=[];for(;;){const h=s();if(!h)throw new SyntaxError("Unmatched '('");if(h.type==="rparen")break;c.push(i())}return r(),c}case"rparen":throw new SyntaxError("Unmatched ')'");case"number":return l.value;case"string":return l.value;case"boolean":return l.value;case"nil":return null;case"symbol":return l.value}}const a=[];for(;s();)a.push(i());return a}function Ie(n){if(n===null)return"nil";if(typeof n=="boolean")return n?"#t":"#f";if(typeof n=="number")return Number.isFinite(n)?String(n):"nan";if(typeof n=="string")return/^[^\s()"]+$/u.test(n)&&n!=="nil"&&n!=="#t"&&n!=="#f"?n:`"${n.replace(/["\\\n\r\t]/g,t=>t==='"'?'\\"':t==="\\"?"\\\\":t===`
|
|
104
|
+
`?"\\n":t==="\r"?"\\r":"\\t")}"`;if(Array.isArray(n))return`(${n.map(Ie).join(" ")})`;throw new Error(`Unsupported S-expression value: ${JSON.stringify(n)}`)}var Nc="__default__",qe,f=(qe=class{constructor(){o(this,"isSxClass",!0)}getChildren(){return Object.keys(this).filter(t=>t.startsWith("_sx")).map(t=>this[t]).filter(t=>t&&typeof t=="object"&&t.isSxClass)}getStringIndented(){return this.getString().split(`
|
|
105
|
+
`).map(t=>` ${t}`).join(`
|
|
106
|
+
`)}getString(){const t=this.getChildren();if(t.length===0)return`(${this.token})`;const e=[`(${this.token}`];for(const s of t)e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
107
|
+
`)}get[Symbol.toStringTag](){return this.getString()}[Symbol.for("nodejs.util.inspect.custom")](){return this.getString()}static register(t){if(!t.token)throw new Error("Class must have a static override token");const e=t.parentToken??Nc,s=qe.classes[t.token]??{};s[e]=t,qe.classes[t.token]=s}static parse(t){const e=dk(t);return qe.parsePrimitiveSexpr(e)}static fromSexprPrimitives(t){throw new Error(`"${this.name}" class has not implemented fromSexprPrimitives`)}static parsePrimitiveSexpr(t,e={}){const s=e.parentToken;if(Array.isArray(t)&&t.length>=1&&typeof t[0]=="string"){const r=t[0],i=qe.classes[r];if(!i)throw new Error(`Class "${r}" not registered via SxClass.register`);const l=i[s??Nc]??i[Nc];if(!l)throw new Error(`Class "${r}" not registered for parent "${s??"<root>"}"`);const c=t.slice(1);if(!("fromSexprPrimitives"in l))throw new Error(`Class "${r}" does not have a fromSexprPrimitives method`);return l.fromSexprPrimitives(c)}if(Array.isArray(t))return t.map(r=>qe.parsePrimitiveSexpr(r,e));if(typeof t=="number"||typeof t=="string"||typeof t=="boolean"||t===null)return t;throw new Error(`Couldn't parse primitive S-expression: ${JSON.stringify(t)}`)}static parsePrimitivesToClassProperties(t,e){var i;const s={},r={};for(const a of t){const l=qe.parsePrimitiveSexpr(a,{parentToken:e});l.isSxClass&&(s[l.token]=l,r[i=l.token]??(r[i]=[]),r[l.token].push(l))}return{propertyMap:s,arrayPropertyMap:r}}},o(qe,"token"),o(qe,"parentToken"),o(qe,"classes",{}),qe),oe=class extends f{constructor(t){super();o(this,"value");this.value=t}set(t){this.value=t}static fromSexprPrimitives(t){return new this(t[0])}getString(){return`(${this.token} ${this.value})`}},Vc,de=(Vc=class extends oe{constructor(){super(...arguments);o(this,"token","width")}},o(Vc,"token","width"),Vc);f.register(de);var Jt,Jg=(Jt=class extends f{constructor(e){super();o(this,"token","type");o(this,"type");this.type=e}static fromSexprPrimitives(e){return new Jt(e[0])}getString(){return`(type ${this.type})`}},o(Jt,"token","type"),o(Jt,"parentToken","stroke"),Jt);f.register(Jg);var kr,fp=(kr=class extends f{constructor(e){super();o(this,"token","color");o(this,"color");this.color={r:e[0],g:e[1],b:e[2],a:e[3]}}static fromSexprPrimitives(e){return new kr(e)}getString(){return`(color ${this.color.r} ${this.color.g} ${this.color.b} ${this.color.a})`}},o(kr,"token","color"),kr);f.register(fp);var Sr,gp=(Sr=class extends f{constructor(){super(...arguments);o(this,"token","stroke");o(this,"_sxWidth");o(this,"_sxType");o(this,"_sxColor")}static fromSexprPrimitives(e){const s=new Sr,{propertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);return s._sxWidth=r.width,s._sxType=r.type,s._sxColor=r.color,s}get width(){var e;return(e=this._sxWidth)==null?void 0:e.value}get type(){var e;return(e=this._sxType)==null?void 0:e.type}get color(){var e;return(e=this._sxColor)==null?void 0:e.color}set width(e){this._sxWidth=new de(e)}set type(e){this._sxType=new Jg(e)}set color(e){this._sxColor=new fp([e.r,e.g,e.b,e.a])}},o(Sr,"token","stroke"),Sr);f.register(gp);var uk=["inches","mils","millimeters","automatic"],Pr,pk=(Pr=class extends f{constructor(e){super();o(this,"token","unit");o(this,"value");typeof e=="number"?this.value=uk[e]:this.value=e}static fromSexprPrimitives(e){const[s]=e;return new Pr(s)}},o(Pr,"token","unit"),Pr);f.register(pk);var fe=class extends f{constructor(t){super();o(this,"value");this.value=t}set(t){this.value=t}static fromSexprPrimitives(t){const[e]=t;let s;return typeof e=="boolean"?s=e:typeof e=="string"?s=e==="true"||e==="yes":s=!1,new this(s)}getString(){return`(${this.token} ${this.value?"yes":"no"})`}},Hc,_p=(Hc=class extends fe{constructor(){super(...arguments);o(this,"token","in_bom")}},o(Hc,"token","in_bom"),Hc);f.register(_p);var Yc,mp=(Yc=class extends fe{constructor(){super(...arguments);o(this,"token","on_board")}},o(Yc,"token","on_board"),Yc);f.register(mp);var O=n=>{if(n!==void 0){if(typeof n=="number")return n;if(typeof n=="string"){const t=Number(n);return Number.isNaN(t)?void 0:t}}},Tr,et=(Tr=class extends f{constructor(e,s){super();o(this,"token","xy");o(this,"x");o(this,"y");this.x=e,this.y=s}static fromSexprPrimitives(e){const[s,r]=e,i=O(s)??0,a=O(r)??0;return new Tr(i,a)}getChildren(){return[]}getString(){return`(xy ${this.x} ${this.y})`}},o(Tr,"token","xy"),Tr);f.register(et);var Er,Gt=(Er=class extends f{constructor(e=[]){super();o(this,"token","pts");o(this,"points");this.points=e}static fromSexprPrimitives(e){const s=[];for(const r of e){if(!Array.isArray(r)||r.length===0)throw new Error(`Unexpected primitive inside pts: ${Ie(r)}`);const i=f.parsePrimitiveSexpr(r,{parentToken:this.token});if(i instanceof et){s.push(i);continue}throw i instanceof f?new Error(`Unsupported child "${i.token}" inside pts expression`):new Error(`Unable to parse child inside pts: ${Ie(r)}`)}return new Er(s)}getChildren(){return[...this.points]}getString(){const e=["(pts"];for(const s of this.points){const i=s.getString().split(`
|
|
108
|
+
`);for(const a of i)e.push(` ${a}`)}return e.push(")"),e.join(`
|
|
109
|
+
`)}},o(Er,"token","pts"),Er);f.register(Gt);var Lt,he=(Lt=class extends f{constructor(e,s={}){super();o(this,"token","at");o(this,"x");o(this,"y");o(this,"angle");this.x=e[0],this.y=e[1],this.angle=e[2],this.angle&&s.isTextSymbol&&(this.angle*=10)}static from(e,s={}){return e instanceof Lt?e:Array.isArray(e)?new Lt(e,s):new Lt([e.x,e.y,e.angle],s)}static fromSexprPrimitives(e){const[s,r,i]=e;return new Lt([s,r,i])}getString(){const e=[this.x,this.y];return this.angle!==void 0&&e.push(this.angle),`(at ${e.join(" ")})`}},o(Lt,"token","at"),Lt);f.register(he);var Rt=class extends f{constructor(t){super();o(this,"value");this.value=t}set(t){this.value=t}static fromSexprPrimitives(t){return new this(t[0])}getString(){return`(${this.token} ${this.value})`}},D=n=>`"${n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}"`,F=n=>{if(n!==void 0){if(typeof n=="string")return n;if(typeof n=="number"||typeof n=="boolean")return String(n)}},Cr,Yt=(Cr=class extends f{constructor(e={}){super();o(this,"token","effects");o(this,"_sxFont");o(this,"_sxJustify");o(this,"_hiddenText",!1);e.font!==void 0&&(this.font=e.font),e.justify!==void 0&&(this.justify=e.justify),e.hiddenText!==void 0&&(this.hiddenText=e.hiddenText)}get font(){return this._sxFont||(this._sxFont=new Xt),this._sxFont}set font(e){this._sxFont=e}get justify(){return this._sxJustify}set justify(e){this._sxJustify=e}get hiddenText(){return this._hiddenText}set hiddenText(e){this._hiddenText=e}static fromSexprPrimitives(e){const s=new Cr,{propertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);s._sxFont=r.font,s._sxJustify=r.justify;const i=r.hide;i&&(s._hiddenText=i.value);for(const a of e){if(typeof a=="string"){if(a==="hide"){s._hiddenText=!0;continue}throw new Error(`Unknown text effects token: ${a}`)}if(!Array.isArray(a))throw new Error(`Unsupported text effects primitive: ${JSON.stringify(a)}`)}return s}getChildren(){const e=[];return this._sxFont&&e.push(this._sxFont),this._sxJustify&&e.push(this._sxJustify),this._hiddenText&&e.push(new sd(!0)),e}getString(){const e=["(effects"];return this._sxFont&&e.push(this._sxFont.getStringIndented()),this._sxJustify&&e.push(this._sxJustify.getStringIndented()),this._hiddenText&&e.push(new sd(!0).getStringIndented()),e.push(")"),e.join(`
|
|
110
|
+
`)}},o(Cr,"token","effects"),Cr);f.register(Yt);var Zt,Xt=(Zt=class extends f{constructor(){super(...arguments);o(this,"token","font");o(this,"_sxFace");o(this,"_sxSize");o(this,"_sxThickness");o(this,"_sxLineSpacing");o(this,"_bold",!1);o(this,"_italic",!1)}get face(){var e;return(e=this._sxFace)==null?void 0:e.value}set face(e){this._sxFace=e===void 0?void 0:new Zg(e)}get size(){if(this._sxSize)return{height:this._sxSize.height,width:this._sxSize.width}}set size(e){if(e===void 0){this._sxSize=void 0;return}if(e instanceof td){this._sxSize=e;return}this._sxSize=new td(e.height,e.width)}get thickness(){var e;return(e=this._sxThickness)==null?void 0:e.value}set thickness(e){this._sxThickness=e===void 0?void 0:new Qg(e)}get lineSpacing(){var e;return(e=this._sxLineSpacing)==null?void 0:e.value}set lineSpacing(e){this._sxLineSpacing=e===void 0?void 0:new e_(e)}get bold(){return this._bold}set bold(e){this._bold=e}get italic(){return this._italic}set italic(e){this._italic=e}static fromSexprPrimitives(e){const s=new Zt,{propertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);s._sxFace=r.face,s._sxSize=r.size,s._sxThickness=r.thickness,s._sxLineSpacing=r.line_spacing;for(const i of e){if(typeof i=="string"){if(i==="bold"){s._bold=!0;continue}if(i==="italic"){s._italic=!0;continue}throw new Error(`Unknown font token: ${i}`)}if(!Array.isArray(i))throw new Error(`Unsupported font primitive: ${JSON.stringify(i)}`)}return s}getChildren(){const e=[];return this._sxFace&&e.push(this._sxFace),this._sxSize&&e.push(this._sxSize),this._sxThickness&&e.push(this._sxThickness),this._sxLineSpacing&&e.push(this._sxLineSpacing),e}getString(){const e=["(font"];return this._sxFace&&e.push(this._sxFace.getStringIndented()),this._sxSize&&e.push(this._sxSize.getStringIndented()),this._sxThickness&&e.push(this._sxThickness.getStringIndented()),this._bold&&e.push(" bold"),this._italic&&e.push(" italic"),this._sxLineSpacing&&e.push(this._sxLineSpacing.getStringIndented()),e.push(")"),e.join(`
|
|
111
|
+
`)}},o(Zt,"token","font"),o(Zt,"parentToken","effects"),Zt);f.register(Xt);var To,Zg=(To=class extends Rt{constructor(){super(...arguments);o(this,"token","face")}getString(){return`(face ${D(this.value)})`}},o(To,"token","face"),o(To,"parentToken","font"),To);f.register(Zg);var Qt,td=(Qt=class extends f{constructor(e=0,s=0){super();o(this,"token","size");o(this,"_height",0);o(this,"_width",0);this._height=e,this._width=s}static fromSexprPrimitives(e){const s=O(e[0])??0,r=O(e[1])??0;return new Qt(s,r)}get height(){return this._height}set height(e){this._height=e}get width(){return this._width}set width(e){this._width=e}getString(){return`(size ${this._height} ${this._width})`}},o(Qt,"token","size"),o(Qt,"parentToken","font"),Qt);f.register(td);var Eo,Qg=(Eo=class extends oe{constructor(){super(...arguments);o(this,"token","thickness")}},o(Eo,"token","thickness"),o(Eo,"parentToken","font"),Eo);f.register(Qg);var Co,sd=(Co=class extends fe{constructor(t){super(t??!0);o(this,"token","hide")}getString(){return this.value?"(hide yes)":"(hide no)"}},o(Co,"token","hide"),o(Co,"parentToken","effects"),Co);f.register(sd);var No,e_=(No=class extends oe{constructor(){super(...arguments);o(this,"token","line_spacing")}},o(No,"token","line_spacing"),o(No,"parentToken","font"),No);f.register(e_);var es,ac=(es=class extends f{constructor(e={}){super();o(this,"token","justify");o(this,"_horizontal");o(this,"_vertical");o(this,"_mirror",!1);this._horizontal=e.horizontal,this._vertical=e.vertical,this._mirror=e.mirror??!1}static fromSexprPrimitives(e){const s=new es;for(const r of e){const i=F(r);if(i===void 0)throw new Error(`Unsupported justify primitive: ${JSON.stringify(r)}`);if(i==="left"||i==="right"){s._horizontal=i;continue}if(i==="top"||i==="bottom"){s._vertical=i;continue}if(i==="mirror"){s._mirror=!0;continue}throw new Error(`Unknown justify token: ${i}`)}return s}get horizontal(){return this._horizontal}set horizontal(e){this._horizontal=e}get vertical(){return this._vertical}set vertical(e){this._vertical=e}get mirror(){return this._mirror}set mirror(e){this._mirror=e}getString(){const e=["(justify"];return this._horizontal&&e.push(` ${this._horizontal}`),this._vertical&&e.push(` ${this._vertical}`),this._mirror&&e.push(" mirror"),e.push(")"),e.join("")}},o(es,"token","justify"),o(es,"parentToken","effects"),es);f.register(ac);var Xc,W=(Xc=class extends Rt{constructor(){super(...arguments);o(this,"token","uuid")}},o(Xc,"token","uuid"),Xc);f.register(W);function uo(n){if(n===void 0)return"";const t=F(n);return t!==void 0?t:Ie(n)}var Nr,t_=(Nr=class extends f{constructor(e={}){super();o(this,"token","title_block");o(this,"_sxTitle");o(this,"_sxDate");o(this,"_sxRev");o(this,"_sxCompany");o(this,"comments",[]);e.title!==void 0&&(this.title=e.title),e.date!==void 0&&(this.date=e.date),e.rev!==void 0&&(this.rev=e.rev),e.company!==void 0&&(this.company=e.company),e.comments!==void 0&&(this.comments=e.comments)}static fromSexprPrimitives(e){const s=new Nr;for(const r of e){if(!Array.isArray(r)||r.length===0)throw new Error(`Unexpected primitive inside title_block: ${Ie(r)}`);const i=f.parsePrimitiveSexpr(r,{parentToken:this.token});if(!(i instanceof f))throw new Error(`Unable to parse child node inside title_block: ${Ie(r)}`);if(i instanceof nd){s._sxTitle=i;continue}if(i instanceof rd){s._sxDate=i;continue}if(i instanceof id){s._sxRev=i;continue}if(i instanceof od){s._sxCompany=i;continue}if(i instanceof ad){s.comments.push(i);continue}throw new Error(`Unsupported child "${i.token}" inside title_block expression`)}return s}get title(){var e;return(e=this._sxTitle)==null?void 0:e.value}set title(e){this._sxTitle=e===void 0?void 0:new nd(e)}get date(){var e;return(e=this._sxDate)==null?void 0:e.value}set date(e){this._sxDate=e===void 0?void 0:new rd(e)}get rev(){var e;return(e=this._sxRev)==null?void 0:e.value}set rev(e){this._sxRev=e===void 0?void 0:new id(e)}get company(){var e;return(e=this._sxCompany)==null?void 0:e.value}set company(e){this._sxCompany=e===void 0?void 0:new od(e)}getComment(e){var s;return(s=this.comments.find(r=>r.index===e))==null?void 0:s.value}setComment(e,s){const r=this.comments.find(i=>i.index===e);if(r){r.value=s;return}this.comments.push(new ad(e,s))}removeComment(e){this.comments=this.comments.filter(s=>s.index!==e)}getChildren(){const e=[];this._sxTitle&&e.push(this._sxTitle),this._sxDate&&e.push(this._sxDate),this._sxRev&&e.push(this._sxRev),this._sxCompany&&e.push(this._sxCompany);const s=[...this.comments].sort((r,i)=>r.index-i.index);return e.push(...s),e}getString(){const e=["(title_block"];for(const s of this.getChildren())e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
112
|
+
`)}},o(Nr,"token","title_block"),Nr);f.register(t_);var cc=class extends f{constructor(t){super();o(this,"value");this.value=t}getChildren(){return[]}},ts,nd=(ts=class extends cc{constructor(){super(...arguments);o(this,"token","title")}static fromSexprPrimitives(e){const[s]=e;return new ts(uo(s))}getString(){return`(title ${D(this.value)})`}},o(ts,"token","title"),o(ts,"parentToken","title_block"),ts);f.register(nd);var ss,rd=(ss=class extends cc{constructor(){super(...arguments);o(this,"token","date")}static fromSexprPrimitives(e){const[s]=e;return new ss(uo(s))}getString(){return`(date ${D(this.value)})`}},o(ss,"token","date"),o(ss,"parentToken","title_block"),ss);f.register(rd);var ns,id=(ns=class extends cc{constructor(){super(...arguments);o(this,"token","rev")}static fromSexprPrimitives(e){const[s]=e;return new ns(uo(s))}getString(){return`(rev ${D(this.value)})`}},o(ns,"token","rev"),o(ns,"parentToken","title_block"),ns);f.register(id);var rs,od=(rs=class extends cc{constructor(){super(...arguments);o(this,"token","company")}static fromSexprPrimitives(e){const[s]=e;return new rs(uo(s))}getString(){return`(company ${D(this.value)})`}},o(rs,"token","company"),o(rs,"parentToken","title_block"),rs);f.register(od);var is,ad=(is=class extends f{constructor(e,s){super();o(this,"token","comment");o(this,"index");o(this,"value");o(this,"_sxAt");o(this,"_sxEffects");o(this,"_sxUuid");this.index=e,this.value=s}static fromSexprPrimitives(e){const[s,r,...i]=e,a=O(s);if(a===void 0)throw new Error("title_block comment requires a numeric index");const l=uo(r),c=new is(a,l);for(const h of i){if(!Array.isArray(h)||h.length===0)throw new Error(`Unexpected primitive inside title_block comment: ${Ie(h)}`);const d=f.parsePrimitiveSexpr(h,{parentToken:this.token});if(!(d instanceof f))throw new Error(`Unable to parse child node inside title_block comment: ${Ie(h)}`);if(d instanceof he){c._sxAt=d;continue}if(d instanceof Yt){c._sxEffects=d;continue}if(d instanceof W){c._sxUuid=d;continue}throw new Error(`Unsupported child "${d.token}" inside title_block comment`)}return c}get at(){return this._sxAt}set at(e){this._sxAt=e}get effects(){return this._sxEffects}set effects(e){this._sxEffects=e}get uuid(){return this._sxUuid}set uuid(e){this._sxUuid=e}getChildren(){const e=[];return this._sxAt&&e.push(this._sxAt),this._sxEffects&&e.push(this._sxEffects),this._sxUuid&&e.push(this._sxUuid),e}getString(){const e=this.getChildren();if(e.length===0)return`(comment ${this.index} ${D(this.value)})`;const s=[`(comment ${this.index} ${D(this.value)}`];for(const r of e)s.push(r.getStringIndented());return s.push(")"),s.join(`
|
|
113
|
+
`)}},o(is,"token","comment"),o(is,"parentToken","title_block"),is);f.register(ad);var $r,lc=($r=class extends f{constructor(){super(...arguments);o(this,"token","paper");o(this,"_size");o(this,"_width");o(this,"_height");o(this,"_portrait",!1)}static fromSexprPrimitives(e){const s=new $r,r=[];for(const i of e){if(typeof i=="number"){r.push(i);continue}if(typeof i=="string"){if(i==="portrait"){s._portrait=!0;continue}s._size===void 0&&r.length===0&&(s._size=i)}}return r.length>=2?(s._width=r[0],s._height=r[1]):r.length===1&&(s._width=r[0]),s}get size(){return this._size}set size(e){this._size=e,e!==void 0&&(this._width=void 0,this._height=void 0)}get customSize(){if(typeof this._width=="number"&&typeof this._height=="number")return{width:this._width,height:this._height}}set customSize(e){if(!e){this._width=void 0,this._height=void 0;return}this._width=e.width,this._height=e.height,this._size=void 0}get isPortrait(){return this._portrait}set isPortrait(e){this._portrait=e}getString(){const e=["(paper"];return this._size?e.push(` ${this._size}`):typeof this._width=="number"&&typeof this._height=="number"&&e.push(` ${this._width} ${this._height}`),this._portrait&&e.push(" portrait"),e.push(")"),e.join(`
|
|
114
|
+
`)}},o($r,"token","paper"),$r);f.register(lc);var Ar,ce=(Ar=class extends f{constructor(e=[]){super();o(this,"token","layer");o(this,"_names",[]);this.names=e.map(s=>String(s))}static fromSexprPrimitives(e){const s=e.map(r=>typeof r=="string"||typeof r=="number"?String(r):Ie(r));return new Ar(s)}get names(){return[...this._names]}set names(e){this._names=e.map(s=>String(s))}addName(e){this._names.push(String(e))}getString(){return`(layer ${this._names.map(s=>/^[^\s()"]+$/u.test(s)&&!["nil","#t","#f"].includes(s)?s:D(s)).join(" ")})`}},o(Ar,"token","layer"),Ar);f.register(ce);var _f=new Set(["at","xy","scale","layer","uuid","data"]),fk=new Set,Ir,s_=(Ir=class extends f{constructor(e={}){super();o(this,"token","image");o(this,"_sxPosition");o(this,"_sxScale");o(this,"_sxLayer");o(this,"_sxUuid");o(this,"_sxData");e.position!==void 0&&(this.position=e.position),e.scale!==void 0&&(this.scale=e.scale),e.layer!==void 0&&(this.layer=e.layer),e.uuid!==void 0&&(this.uuid=e.uuid),e.data!==void 0&&(this.data=e.data)}static fromSexprPrimitives(e){const s=new Ir,r=[];for(const h of e){if(!Array.isArray(h)||h.length===0)throw new Error(`image encountered invalid child expression: ${JSON.stringify(h)}`);r.push(h)}const{propertyMap:i,arrayPropertyMap:a}=f.parsePrimitivesToClassProperties(r,this.token);for(const h of Object.keys(i))if(!_f.has(h))throw new Error(`image encountered unsupported child token "${h}"`);for(const[h,d]of Object.entries(a)){if(!_f.has(h))throw new Error(`image encountered unsupported child token "${h}"`);if(!fk.has(h)&&d.length>1)throw new Error(`image does not support repeated child token "${h}"`)}const l=i.at,c=i.xy;if(l&&c)throw new Error("image cannot include both at and xy child tokens");return s._sxPosition=l??c,s._sxScale=i.scale,s._sxLayer=i.layer,s._sxUuid=i.uuid,s._sxData=i.data,s}get position(){return this._sxPosition}set position(e){if(e===void 0){this._sxPosition=void 0;return}if(e instanceof et){this._sxPosition=e;return}this._sxPosition=he.from(e)}get scale(){return this._sxScale}set scale(e){if(e===void 0){this._sxScale=void 0;return}this._sxScale=e instanceof cd?e:new cd(e)}get layer(){return this._sxLayer}set layer(e){if(e===void 0){this._sxLayer=void 0;return}if(e instanceof ce)this._sxLayer=e;else{const s=Array.isArray(e)?e:[e];this._sxLayer=new ce(s)}}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}get data(){return this._sxData}set data(e){if(e===void 0){this._sxData=void 0;return}e instanceof Pa?this._sxData=e:Array.isArray(e)?this._sxData=Pa.fromStrings(e):this._sxData=Pa.fromStrings([e])}getChildren(){const e=[];return this._sxPosition&&e.push(this._sxPosition),this._sxScale&&e.push(this._sxScale),this._sxLayer&&e.push(this._sxLayer),this._sxUuid&&e.push(this._sxUuid),this._sxData&&e.push(this._sxData),e}},o(Ir,"token","image"),Ir);f.register(s_);var os,cd=(os=class extends f{constructor(e){super();o(this,"token","scale");o(this,"value");this.value=e}static fromSexprPrimitives(e){const[s]=e,r=O(s);return new os(r??1)}getChildren(){return[]}getString(){return`(scale ${this.value})`}},o(os,"token","scale"),o(os,"parentToken","image"),os);f.register(cd);var Ut,Pa=(Ut=class extends f{constructor(e=[]){super();o(this,"token","data");o(this,"_chunks");this._chunks=e}static fromSexprPrimitives(e){const s=e.map(r=>gk(r));return new Ut(s)}static fromStrings(e){return new Ut(e)}get chunks(){return[...this._chunks]}set chunks(e){this._chunks=[...e]}get value(){return this._chunks.join("")}set value(e){this._chunks=[e]}getChildren(){return[]}getString(){return this._chunks.length===0?"(data)":`(data ${this._chunks.map(s=>D(s)).join(" ")})`}},o(Ut,"token","data"),o(Ut,"parentToken","image"),Ut);f.register(Pa);function gk(n){const t=F(n);return t!==void 0?t:Ie(n)}var Lr,_k=(Lr=class extends f{constructor(e=""){super();o(this,"token","render_cache");o(this,"_text");o(this,"_angle");o(this,"_offsetX");o(this,"_offsetY");o(this,"_elements",[]);this._text=e}static fromSexprPrimitives(e){if(e.length===0)throw new Error("render_cache requires a text argument");const[s,...r]=e,i=F(s);if(i===void 0)throw new Error(`render_cache text must be a string value, received ${JSON.stringify(s)}`);const a=new Lr(i),l=[];for(const c of r){if(Array.isArray(c)){const d=f.parsePrimitiveSexpr(c,{parentToken:this.token});if(!(d instanceof f))throw new Error(`render_cache child did not resolve to an SxClass: ${JSON.stringify(c)}`);if(!(d instanceof n_))throw new Error(`render_cache encountered unsupported child token "${d.token}"`);a._elements.push(d);continue}const h=O(c);if(h===void 0)throw new Error(`render_cache encountered non-numeric parameter ${JSON.stringify(c)}`);l.push(h)}if(l.length>0&&(a._angle=l[0]),l.length>1&&(a._offsetX=l[1]),l.length>2&&(a._offsetY=l[2]),l.length>3)throw new Error("render_cache supports at most three numeric parameters");return a}get text(){return this._text}set text(e){this._text=e}get angle(){return this._angle}set angle(e){this._angle=e}get offsetX(){return this._offsetX}set offsetX(e){this._offsetX=e}get offsetY(){return this._offsetY}set offsetY(e){this._offsetY=e}get elements(){return[...this._elements]}set elements(e){this._elements=[...e]}addElement(e){this._elements.push(e)}getChildren(){return[...this._elements]}getString(){const e=[D(this._text)];if(this._angle!==void 0&&e.push(String(this._angle)),this._offsetX!==void 0&&e.push(String(this._offsetX)),this._offsetY!==void 0&&e.push(String(this._offsetY)),this._elements.length===0)return`(render_cache ${e.join(" ")})`;const s=[`(render_cache ${e.join(" ")}`];for(const r of this._elements)s.push(r.getStringIndented());return s.push(")"),s.join(`
|
|
115
|
+
`)}},o(Lr,"token","render_cache"),Lr);f.register(_k);var as,n_=(as=class extends f{constructor(){super(...arguments);o(this,"token","polygon");o(this,"_contours",[])}static fromSexprPrimitives(e){const s=new as;for(const r of e){if(!Array.isArray(r)||r.length===0)throw new Error(`render_cache polygon encountered invalid child: ${JSON.stringify(r)}`);const i=f.parsePrimitiveSexpr(r,{parentToken:this.token});if(!(i instanceof f))throw new Error(`render_cache polygon child did not resolve to an SxClass: ${JSON.stringify(r)}`);if(!(i instanceof Gt))throw new Error(`render_cache polygon encountered unsupported token "${i.token}"`);s._contours.push(i)}if(s._contours.length===0)throw new Error("render_cache polygon requires at least one pts child");return s}get contours(){return[...this._contours]}set contours(e){this._contours=[...e]}getChildren(){return[...this._contours]}},o(as,"token","polygon"),o(as,"parentToken","render_cache"),as);f.register(n_);var mk=n=>/^[A-Za-z0-9._-]+$/.test(n),cs,ld=(cs=class extends Rt{constructor(){super(...arguments);o(this,"token","generator")}static fromSexprPrimitives(e){const[s]=e,r=F(s);if(r===void 0)throw new Error("generator expects a string argument");return new cs(r)}getString(){return`(generator ${mk(this.value)?this.value:D(this.value)})`}},o(cs,"token","generator"),o(cs,"parentToken","kicad_sch"),cs);f.register(ld);var ls,hd=(ls=class extends oe{constructor(){super(...arguments);o(this,"token","version")}static fromSexprPrimitives(e){const[s]=e,r=O(s);if(r===void 0)throw new Error("version expects a numeric argument");return new ls(r)}},o(ls,"token","version"),o(ls,"parentToken","kicad_sch"),ls);f.register(hd);var hs,dd=(hs=class extends Rt{constructor(){super(...arguments);o(this,"token","generator_version")}static fromSexprPrimitives(e){const[s]=e,r=F(s);if(r===void 0)throw new Error("generator_version expects a string argument");return new hs(r)}getString(){return`(generator_version ${/^[^\s()\"]+$/.test(this.value)?this.value:D(this.value)})`}},o(hs,"token","generator_version"),o(hs,"parentToken","kicad_sch"),hs);f.register(dd);var qt=(n,t=" ")=>n.split(`
|
|
116
|
+
`).map(e=>`${t}${e}`),qc,xp=(qc=class extends fe{constructor(){super(...arguments);o(this,"token","dnp")}},o(qc,"token","dnp"),qc);f.register(xp);var ft,yp=(ft=class extends f{constructor(e=!1){super();o(this,"token","embedded_fonts");o(this,"_enabled",!1);this._enabled=e}static fromSexprPrimitives(e){if(e.length===0)return new ft(!1);if(e.length>1)throw new Error("embedded_fonts accepts at most a single value");const[s]=e;if(s===void 0)return new ft(!1);if(typeof s=="boolean")return new ft(s);if(typeof s=="string"){const r=s.toLowerCase();if(r==="yes")return new ft(!0);if(r==="no")return new ft(!1);throw new Error(`embedded_fonts expects "yes" or "no", received "${s}"`)}throw new Error(`embedded_fonts encountered unsupported value ${JSON.stringify(s)}`)}get enabled(){return this._enabled}set enabled(e){this._enabled=e}getChildren(){return[]}getString(){return`(embedded_fonts ${this._enabled?"yes":"no"})`}},o(ft,"token","embedded_fonts"),ft);f.register(yp);var Kc,hc=(Kc=class extends fe{constructor(){super(...arguments);o(this,"token","exclude_from_sim")}},o(Kc,"token","exclude_from_sim"),Kc);f.register(hc);var Jc,ti=(Jc=class extends fe{constructor(){super(...arguments);o(this,"token","fields_autoplaced")}},o(Jc,"token","fields_autoplaced"),Jc);f.register(ti);var jt,r_=(jt=class extends oe{constructor(){super(...arguments);o(this,"token","unit")}static from(e){return e instanceof jt?e:new jt(e)}},o(jt,"token","unit"),o(jt,"parentToken","symbol"),jt);f.register(r_);var ds,vp=(ds=class extends f{constructor(e){super();o(this,"token","lib_id");o(this,"value");this.value=e}static fromSexprPrimitives(e){const[s]=e,r=F(s);if(r===void 0)throw new Error("lib_id expects a string value");return new ds(r)}getChildren(){return[]}getString(){return`(lib_id ${D(this.value)})`}},o(ds,"token","lib_id"),o(ds,"parentToken","symbol"),ds);f.register(vp);var $o,i_=($o=class extends fe{constructor(){super(...arguments);o(this,"token","duplicate_pin_numbers_are_jumpers")}},o($o,"token","duplicate_pin_numbers_are_jumpers"),o($o,"parentToken","symbol"),$o);f.register(i_);var us,o_=(us=class extends f{constructor(){super(...arguments);o(this,"token","pin_numbers");o(this,"_sxHide")}static fromSexprPrimitives(e){const s=new us,r=[],i=[];for(const l of e){if(typeof l=="string"){r.push(l);continue}i.push(l)}const{propertyMap:a}=f.parsePrimitivesToClassProperties(i,this.token);s._sxHide=a.hide;for(const l of r){if(l==="hide"){s._sxHide=new ud(!0,{inline:!0});continue}throw new Error(`symbol pin_numbers encountered unsupported flag "${l}"`)}return s}get hide(){var e;return((e=this._sxHide)==null?void 0:e.value)??!1}set hide(e){this._sxHide=new ud(e)}getChildren(){return this._sxHide?[this._sxHide]:[]}},o(us,"token","pin_numbers"),o(us,"parentToken","symbol"),us);f.register(o_);var Ao,ud=(Ao=class extends fe{constructor(t,e={}){super(t??!0);o(this,"token","hide");o(this,"inline",!1);this.inline=e.inline??!1}getString(){return this.inline?this.value?"hide":"(hide no)":super.getString()}},o(Ao,"token","hide"),o(Ao,"parentToken","pin_numbers"),Ao);f.register(ud);var ps,a_=(ps=class extends f{constructor(){super(...arguments);o(this,"token","pin_names");o(this,"_sxOffset");o(this,"_sxHide")}static fromSexprPrimitives(e){const s=new ps,{propertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);return s._sxOffset=r.offset,s._sxHide=r.hide,s}get offset(){var e;return(e=this._sxOffset)==null?void 0:e.value}set offset(e){if(e===void 0){this._sxOffset=void 0;return}this._sxOffset=new c_(e)}get hide(){var e;return((e=this._sxHide)==null?void 0:e.value)??!1}set hide(e){this._sxHide=new l_(e)}getChildren(){const e=[];return this._sxOffset&&e.push(this._sxOffset),this._sxHide&&e.push(this._sxHide),e}},o(ps,"token","pin_names"),o(ps,"parentToken","symbol"),ps);f.register(a_);var fs,c_=(fs=class extends f{constructor(e){super();o(this,"token","offset");o(this,"value");this.value=e}static fromSexprPrimitives(e){const[s]=e,r=O(s);if(r===void 0)throw new Error("pin_names offset expects a numeric value");return new fs(r)}getChildren(){return[]}getString(){return`(offset ${this.value})`}},o(fs,"token","offset"),o(fs,"parentToken","pin_names"),fs);f.register(c_);var Io,l_=(Io=class extends fe{constructor(){super(...arguments);o(this,"token","hide")}},o(Io,"token","hide"),o(Io,"parentToken","pin_names"),Io);f.register(l_);var vi=class extends f{constructor(t,e){super();o(this,"_x");o(this,"_y");this._x=t,this._y=e}static fromSexprPrimitives(t){const[e,s]=t,r=O(e),i=O(s);if(r===void 0||i===void 0)throw new Error(`${this.name} expects two numeric arguments`);const a=this;return new a(r,i)}get x(){return this._x}set x(t){this._x=t}get y(){return this._y}set y(t){this._y=t}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(${this.token} ${this._x} ${this._y})`}},Lo,xk=(Lo=class extends vi{constructor(){super(...arguments);o(this,"token","start")}},o(Lo,"token","start"),o(Lo,"parentToken","rectangle"),Lo);f.register(xk);var Mo,yk=(Mo=class extends vi{constructor(){super(...arguments);o(this,"token","end")}},o(Mo,"token","end"),o(Mo,"parentToken","rectangle"),Mo);f.register(yk);var Ro,vk=(Ro=class extends vi{constructor(){super(...arguments);o(this,"token","start")}},o(Ro,"token","start"),o(Ro,"parentToken","arc"),Ro);f.register(vk);var Oo,wk=(Oo=class extends vi{constructor(){super(...arguments);o(this,"token","mid")}},o(Oo,"token","mid"),o(Oo,"parentToken","arc"),Oo);f.register(wk);var Fo,bk=(Fo=class extends vi{constructor(){super(...arguments);o(this,"token","end")}},o(Fo,"token","end"),o(Fo,"parentToken","arc"),Fo);f.register(bk);var zo,kk=(zo=class extends vi{constructor(){super(...arguments);o(this,"token","center")}},o(zo,"token","center"),o(zo,"parentToken","circle"),zo);f.register(kk);var Uo,Sk=(Uo=class extends oe{constructor(){super(...arguments);o(this,"token","radius")}},o(Uo,"token","radius"),o(Uo,"parentToken","circle"),Uo);f.register(Sk);var dc=class extends f{constructor(){super(...arguments);o(this,"_sxType")}static fromSexprPrimitives(t){const e=new this,{propertyMap:s}=f.parsePrimitivesToClassProperties(t,"fill");return e._sxType=s.type,e}get type(){var t;return(t=this._sxType)==null?void 0:t.value}set type(t){if(t===void 0){this._sxType=void 0;return}this._sxType=new d_(t)}getChildren(){return this._sxType?[this._sxType]:[]}},jo,h_=(jo=class extends dc{constructor(){super(...arguments);o(this,"token","fill")}},o(jo,"token","fill"),o(jo,"parentToken","polyline"),jo);f.register(h_);var Bo,Pk=(Bo=class extends dc{constructor(){super(...arguments);o(this,"token","fill")}},o(Bo,"token","fill"),o(Bo,"parentToken","rectangle"),Bo);f.register(Pk);var Do,Tk=(Do=class extends dc{constructor(){super(...arguments);o(this,"token","fill")}},o(Do,"token","fill"),o(Do,"parentToken","circle"),Do);f.register(Tk);var Wo,Ek=(Wo=class extends dc{constructor(){super(...arguments);o(this,"token","fill")}},o(Wo,"token","fill"),o(Wo,"parentToken","arc"),Wo);f.register(Ek);var gs,d_=(gs=class extends f{constructor(e){super();o(this,"token","type");o(this,"value");this.value=e}static fromSexprPrimitives(e){const[s]=e,r=F(s);if(r===void 0)throw new Error("fill type expects a string value");return new gs(r)}getChildren(){return[]}getString(){return`(type ${this.value})`}},o(gs,"token","type"),o(gs,"parentToken","fill"),gs);f.register(d_);var _s,u_=(_s=class extends f{constructor(){super(...arguments);o(this,"token","polyline");o(this,"_sxPts");o(this,"_sxStroke");o(this,"_sxFill")}static fromSexprPrimitives(e){const s=new _s,{propertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);return s._sxPts=r.pts,s._sxStroke=r.stroke,s._sxFill=r.fill,s}get points(){return this._sxPts}set points(e){this._sxPts=e}get stroke(){return this._sxStroke}set stroke(e){this._sxStroke=e}get fill(){return this._sxFill}set fill(e){this._sxFill=e}getChildren(){const e=[];return this._sxPts&&e.push(this._sxPts),this._sxStroke&&e.push(this._sxStroke),this._sxFill&&e.push(this._sxFill),e}},o(_s,"token","polyline"),o(_s,"parentToken","symbol"),_s);f.register(u_);var ms,Ck=(ms=class extends f{constructor(){super(...arguments);o(this,"token","rectangle");o(this,"_sxStart");o(this,"_sxEnd");o(this,"_sxStroke");o(this,"_sxFill")}static fromSexprPrimitives(e){const s=new ms,{propertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);return s._sxStart=r.start,s._sxEnd=r.end,s._sxStroke=r.stroke,s._sxFill=r.fill,s}getChildren(){const e=[];return this._sxStart&&e.push(this._sxStart),this._sxEnd&&e.push(this._sxEnd),this._sxStroke&&e.push(this._sxStroke),this._sxFill&&e.push(this._sxFill),e}},o(ms,"token","rectangle"),o(ms,"parentToken","symbol"),ms);f.register(Ck);var xs,Nk=(xs=class extends f{constructor(){super(...arguments);o(this,"token","circle");o(this,"_sxCenter");o(this,"_sxRadius");o(this,"_sxStroke");o(this,"_sxFill")}static fromSexprPrimitives(e){const s=new xs,{propertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);return s._sxCenter=r.center,s._sxRadius=r.radius,s._sxStroke=r.stroke,s._sxFill=r.fill,s}getChildren(){const e=[];return this._sxCenter&&e.push(this._sxCenter),this._sxRadius&&e.push(this._sxRadius),this._sxStroke&&e.push(this._sxStroke),this._sxFill&&e.push(this._sxFill),e}},o(xs,"token","circle"),o(xs,"parentToken","symbol"),xs);f.register(Nk);var ys,$k=(ys=class extends f{constructor(){super(...arguments);o(this,"token","arc");o(this,"_sxStart");o(this,"_sxMid");o(this,"_sxEnd");o(this,"_sxStroke");o(this,"_sxFill")}static fromSexprPrimitives(e){const s=new ys,{propertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);return s._sxStart=r.start,s._sxMid=r.mid,s._sxEnd=r.end,s._sxStroke=r.stroke,s._sxFill=r.fill,s}getChildren(){const e=[];return this._sxStart&&e.push(this._sxStart),this._sxMid&&e.push(this._sxMid),this._sxEnd&&e.push(this._sxEnd),this._sxStroke&&e.push(this._sxStroke),this._sxFill&&e.push(this._sxFill),e}},o(ys,"token","arc"),o(ys,"parentToken","symbol"),ys);f.register($k);var vs,Ak=(vs=class extends f{constructor(){super(...arguments);o(this,"token","text");o(this,"_value","");o(this,"_sxAt");o(this,"_sxEffects")}static fromSexprPrimitives(e){const[s,...r]=e,i=F(s);if(i===void 0)throw new Error("text expects a string value");const a=new vs;a._value=i;const{propertyMap:l}=f.parsePrimitivesToClassProperties(r,this.token);return a._sxAt=l.at,a._sxEffects=l.effects,a}get value(){return this._value}set value(e){this._value=e}get at(){return this._sxAt}set at(e){this._sxAt=e!==void 0?he.from(e):void 0}get effects(){return this._sxEffects}set effects(e){this._sxEffects=e}getChildren(){const e=[];return this._sxAt&&e.push(this._sxAt),this._sxEffects&&e.push(this._sxEffects),e}getString(){const e=[`(text ${D(this._value)}`];for(const s of this.getChildren())e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
117
|
+
`)}},o(vs,"token","text"),o(vs,"parentToken","symbol"),vs);f.register(Ak);var ws,Ik=(ws=class extends f{constructor(){super(...arguments);o(this,"token","power")}static fromSexprPrimitives(){return new ws}getChildren(){return[]}getString(){return"(power)"}},o(ws,"token","power"),o(ws,"parentToken","symbol"),ws);f.register(Ik);var Mr,hi=(Mr=class extends f{constructor(e={}){super();o(this,"token","symbol");o(this,"_sxLibId");o(this,"_sxAt");o(this,"_sxUnit");o(this,"_sxPinNumbers");o(this,"_sxPinNames");o(this,"_sxExcludeFromSim");o(this,"_sxInBom");o(this,"_sxOnBoard");o(this,"_sxDnp");o(this,"_sxUuid");o(this,"_sxDuplicatePinNumbersAreJumpers");o(this,"_sxFieldsAutoplaced");o(this,"properties",[]);o(this,"pins",[]);o(this,"subSymbols",[]);o(this,"polylines",[]);o(this,"rectangles",[]);o(this,"circles",[]);o(this,"arcs",[]);o(this,"texts",[]);o(this,"_sxPower");o(this,"_sxEmbeddedFonts");o(this,"_sxInstances");o(this,"_inlineLibId");e.libraryId!==void 0&&(this.libraryId=e.libraryId),e.at!==void 0&&(this.at=e.at),e.unit!==void 0&&(this.unit=typeof e.unit=="number"?e.unit:e.unit.value),e.pinNumbers!==void 0&&(this.pinNumbers=e.pinNumbers),e.pinNames!==void 0&&(this.pinNames=e.pinNames),e.excludeFromSim!==void 0&&(this.excludeFromSim=e.excludeFromSim),e.inBom!==void 0&&(this.inBom=e.inBom),e.onBoard!==void 0&&(this.onBoard=e.onBoard),e.dnp!==void 0&&(this.dnp=e.dnp),e.uuid!==void 0&&(this.uuid=e.uuid),e.duplicatePinNumbersAreJumpers!==void 0&&(this.duplicatePinNumbersAreJumpers=e.duplicatePinNumbersAreJumpers),e.fieldsAutoplaced!==void 0&&(this.fieldsAutoplaced=e.fieldsAutoplaced),e.properties!==void 0&&(this.properties=e.properties),e.pins!==void 0&&(this.pins=e.pins),e.subSymbols!==void 0&&(this.subSymbols=e.subSymbols),e.polylines!==void 0&&(this.polylines=e.polylines),e.rectangles!==void 0&&(this.rectangles=e.rectangles),e.circles!==void 0&&(this.circles=e.circles),e.arcs!==void 0&&(this.arcs=e.arcs),e.texts!==void 0&&(this.texts=e.texts),e.embeddedFonts!==void 0&&(this._sxEmbeddedFonts=e.embeddedFonts),e.instances!==void 0&&(this.instances=e.instances)}get libraryId(){var e;return((e=this._sxLibId)==null?void 0:e.value)??this._inlineLibId}set libraryId(e){if(e&&typeof e=="object"){this._sxLibId=e,this._inlineLibId=void 0;return}if(e===void 0||e===""){this._inlineLibId=void 0,this._sxLibId&&(this._sxLibId=void 0);return}this._inlineLibId=e,this._sxLibId=void 0}get at(){return this._sxAt}set at(e){this._sxAt=e!==void 0?he.from(e):void 0}get unit(){var e;return(e=this._sxUnit)==null?void 0:e.value}set unit(e){this._sxUnit=e===void 0?void 0:r_.from(e)}get pinNumbers(){return this._sxPinNumbers}set pinNumbers(e){this._sxPinNumbers=e}get pinNames(){return this._sxPinNames}set pinNames(e){this._sxPinNames=e}get inBom(){var e;return(e=this._sxInBom)==null?void 0:e.value}set inBom(e){this._sxInBom=e===void 0?void 0:new _p(e)}get excludeFromSim(){var e;return((e=this._sxExcludeFromSim)==null?void 0:e.value)??!1}set excludeFromSim(e){this._sxExcludeFromSim=new hc(e)}get onBoard(){var e;return(e=this._sxOnBoard)==null?void 0:e.value}set onBoard(e){this._sxOnBoard=e===void 0?void 0:new mp(e)}get dnp(){var e;return((e=this._sxDnp)==null?void 0:e.value)??!1}set dnp(e){this._sxDnp=new xp(e)}get fieldsAutoplaced(){var e;return((e=this._sxFieldsAutoplaced)==null?void 0:e.value)??!1}set fieldsAutoplaced(e){this._sxFieldsAutoplaced=new ti(e)}get uuid(){var e;return(e=this._sxUuid)==null?void 0:e.value}set uuid(e){this._sxUuid=e===void 0?void 0:new W(e)}get duplicatePinNumbersAreJumpers(){var e;return((e=this._sxDuplicatePinNumbersAreJumpers)==null?void 0:e.value)??!1}set duplicatePinNumbersAreJumpers(e){if(e===void 0){this._sxDuplicatePinNumbersAreJumpers=void 0;return}this._sxDuplicatePinNumbersAreJumpers=new i_(e)}get instances(){return this._sxInstances}set instances(e){this._sxInstances=e}static fromSexprPrimitives(e){const s=new Mr;let r=e,i;if(r.length>0){const h=r[0];i=F(h),i!==void 0&&(s._inlineLibId=i,r=r.slice(1))}const{propertyMap:a,arrayPropertyMap:l}=f.parsePrimitivesToClassProperties(r,this.token),c=a.lib_id;return c?s._sxLibId=c:i!==void 0&&(s._inlineLibId=i),s._sxAt=a.at,s._sxUnit=a.unit,s._sxPinNumbers=a.pin_numbers,s._sxPinNames=a.pin_names,s._sxExcludeFromSim=a.exclude_from_sim,s._sxInBom=a.in_bom,s._sxOnBoard=a.on_board,s._sxDnp=a.dnp,s._sxUuid=a.uuid,s._sxDuplicatePinNumbersAreJumpers=a.duplicate_pin_numbers_are_jumpers,s._sxFieldsAutoplaced=a.fields_autoplaced,s._sxPower=a.power,s._sxEmbeddedFonts=a.embedded_fonts,s.properties=l.property??[],s.pins=l.pin??[],s.subSymbols=l.symbol??[],s.polylines=l.polyline??[],s.rectangles=l.rectangle??[],s.circles=l.circle??[],s.arcs=l.arc??[],s.texts=l.text??[],s._sxInstances=a.instances,s}getChildren(){const e=[];return this._sxLibId&&e.push(this._sxLibId),this._sxAt&&e.push(this._sxAt),this._sxUnit&&e.push(this._sxUnit),this._sxPinNumbers&&e.push(this._sxPinNumbers),this._sxPinNames&&e.push(this._sxPinNames),this._sxExcludeFromSim&&e.push(this._sxExcludeFromSim),this._sxInBom&&e.push(this._sxInBom),this._sxOnBoard&&e.push(this._sxOnBoard),this._sxDnp&&e.push(this._sxDnp),this._sxUuid&&e.push(this._sxUuid),this._sxDuplicatePinNumbersAreJumpers&&e.push(this._sxDuplicatePinNumbersAreJumpers),this._sxFieldsAutoplaced&&e.push(this._sxFieldsAutoplaced),e.push(...this.properties),e.push(...this.pins),e.push(...this.subSymbols),e.push(...this.polylines),e.push(...this.rectangles),e.push(...this.circles),e.push(...this.arcs),e.push(...this.texts),this._sxPower&&e.push(this._sxPower),this._sxEmbeddedFonts&&e.push(this._sxEmbeddedFonts),this._sxInstances&&e.push(this._sxInstances),e}getString(){const e=this._sxLibId?void 0:this.libraryId,s=e!==void 0&&e!==""?[`(symbol ${D(e)}`]:["(symbol"];for(const r of this.getChildren())s.push(r.getStringIndented());return s.push(")"),s.join(`
|
|
118
|
+
`)}},o(Mr,"token","symbol"),Mr);f.register(hi);var Bt,Oi=(Bt=class extends oe{constructor(){super(...arguments);o(this,"token","id")}static from(e){return e instanceof Bt?e:new Bt(e)}},o(Bt,"token","id"),o(Bt,"parentToken","property"),Bt);f.register(Oi);var bs,ot=(bs=class extends f{constructor(e){super();o(this,"token","property");o(this,"key");o(this,"value");o(this,"_sxId");o(this,"_sxAt");o(this,"_sxEffects");this.key=e.key,this.value=e.value,this._sxId=e.id!==void 0?Oi.from(e.id):void 0,this._sxAt=e.at!==void 0?he.from(e.at):void 0,this._sxEffects=e.effects}static fromSexprPrimitives(e){const[s,r,...i]=e,a=F(s)??"",l=F(r)??"",{propertyMap:c}=f.parsePrimitivesToClassProperties(i,this.token);return new bs({key:a,value:l,id:c.id,at:c.at,effects:c.effects})}get id(){var e;return(e=this._sxId)==null?void 0:e.value}set id(e){this._sxId=e===void 0?void 0:Oi.from(e)}get at(){return this._sxAt}set at(e){this._sxAt=e!==void 0?he.from(e):void 0}get effects(){return this._sxEffects}set effects(e){this._sxEffects=e}getChildren(){const e=[];return this._sxId&&e.push(this._sxId),this._sxAt&&e.push(this._sxAt),this._sxEffects&&e.push(this._sxEffects),e}getString(){const e=[`(property ${D(this.key)} ${D(this.value)}`];return this._sxId&&e.push(...qt(this._sxId.getString())),this._sxAt&&e.push(...qt(this._sxAt.getString())),this._sxEffects&&e.push(...qt(this._sxEffects.getString())),e.push(")"),e.join(`
|
|
119
|
+
`)}},o(bs,"token","property"),o(bs,"parentToken","symbol"),bs);f.register(ot);var Lk=new Set(["input","output","bidirectional","tri_state","passive","free","unspecified","power_in","power_out","open_collector","open_emitter","no_connect"]),Mk=new Set(["line","inverted","clock","inverted_clock","input_low","clock_low","output_low","edge_clock_high","non_logic"]),Go,p_=(Go=class extends oe{constructor(){super(...arguments);o(this,"token","length")}},o(Go,"token","length"),o(Go,"parentToken","pin"),Go);f.register(p_);var ks,wp=(ks=class extends f{constructor(e){super();o(this,"token","name");o(this,"value");o(this,"_sxEffects");this.value=e.value,this._sxEffects=e.effects}static fromSexprPrimitives(e){const[s,...r]=e,i=F(s)??"",{propertyMap:a}=f.parsePrimitivesToClassProperties(r,this.token);return new ks({value:i,effects:a.effects})}get effects(){return this._sxEffects}set effects(e){this._sxEffects=e}getChildren(){return this._sxEffects?[this._sxEffects]:[]}getString(){const e=[`(name ${D(this.value)}`];return this._sxEffects&&e.push(...qt(this._sxEffects.getString())),e.push(")"),e.join(`
|
|
120
|
+
`)}},o(ks,"token","name"),o(ks,"parentToken","pin"),ks);f.register(wp);var Ss,f_=(Ss=class extends f{constructor(e){super();o(this,"token","number");o(this,"value");o(this,"_sxEffects");this.value=e.value,this._sxEffects=e.effects}static fromSexprPrimitives(e){const[s,...r]=e,i=F(s)??"",{propertyMap:a}=f.parsePrimitivesToClassProperties(r,this.token);return new Ss({value:i,effects:a.effects})}get effects(){return this._sxEffects}set effects(e){this._sxEffects=e}getChildren(){return this._sxEffects?[this._sxEffects]:[]}getString(){const e=[`(number ${D(this.value)}`];return this._sxEffects&&e.push(...qt(this._sxEffects.getString())),e.push(")"),e.join(`
|
|
121
|
+
`)}},o(Ss,"token","number"),o(Ss,"parentToken","pin"),Ss);f.register(f_);var Ps,uc=(Ps=class extends f{constructor(){super(...arguments);o(this,"token","pin");o(this,"pinElectricalType");o(this,"pinGraphicStyle");o(this,"_sxAt");o(this,"_sxLength");o(this,"_sxName");o(this,"_sxNumber");o(this,"_sxUuid");o(this,"inlineNumber");o(this,"_sxHide")}static fromSexprPrimitives(e){const s=new Ps;let r=0;const i=e[0],a=F(i);if(a&&Lk.has(a)){s.pinElectricalType=a,r=1;const p=e[1],u=F(p);u&&Mk.has(u)&&(s.pinGraphicStyle=u,r=2)}else a!==void 0&&!Array.isArray(i)&&(s.inlineNumber=a,r=1);const l=e.slice(r),c=[],h=[];for(const p of l){if(typeof p=="string"){c.push(p);continue}h.push(p)}const{propertyMap:d}=f.parsePrimitivesToClassProperties(h,this.token);s._sxAt=d.at,s._sxLength=d.length,s._sxName=d.name,s._sxNumber=d.number,s._sxUuid=d.uuid,s._sxHide=d.hide;for(const p of c){if(p==="hide"){s._sxHide=new pd(!0,{inline:!0});continue}throw new Error(`symbol pin encountered unsupported flag "${p}"`)}return s}get at(){return this._sxAt}set at(e){this._sxAt=e!==void 0?he.from(e):void 0}get length(){var e;return(e=this._sxLength)==null?void 0:e.value}set length(e){this._sxLength=e===void 0?void 0:new p_(e)}get name(){var e;return(e=this._sxName)==null?void 0:e.value}set name(e){if(e===void 0){this._sxName=void 0;return}this._sxName=new wp({value:e})}get numberString(){var e;return((e=this._sxNumber)==null?void 0:e.value)??this.inlineNumber}set numberString(e){if(e===void 0){this._sxNumber=void 0,this.inlineNumber=void 0;return}this.inlineNumber=e,this._sxNumber=void 0}get uuid(){var e;return(e=this._sxUuid)==null?void 0:e.value}set uuid(e){this._sxUuid=e===void 0?void 0:new W(e)}get hidden(){var e;return((e=this._sxHide)==null?void 0:e.value)??!1}set hidden(e){this._sxHide=e?new pd(e):void 0}getChildren(){const e=[];return this._sxAt&&e.push(this._sxAt),this._sxLength&&e.push(this._sxLength),this._sxName&&e.push(this._sxName),this._sxNumber&&e.push(this._sxNumber),this._sxUuid&&e.push(this._sxUuid),this._sxHide&&e.push(this._sxHide),e}getString(){if(this.pinElectricalType){const r=["(pin",this.pinElectricalType];this.pinGraphicStyle&&r.push(this.pinGraphicStyle);const i=[r.join(" ")];for(const a of this.getChildren())i.push(...qt(a.getString()));return i.push(")"),i.join(`
|
|
122
|
+
`)}const e=this.numberString??"",s=[`(pin ${D(e)}`];return this._sxUuid&&s.push(...qt(this._sxUuid.getString())),s.push(")"),s.join(`
|
|
123
|
+
`)}},o(Ps,"token","pin"),o(Ps,"parentToken","symbol"),Ps);f.register(uc);var Ts,bp=(Ts=class extends f{constructor(){super(...arguments);o(this,"token","instances");o(this,"projects",[])}static fromSexprPrimitives(e){const s=new Ts,{arrayPropertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);return s.projects=r.project??[],s}getChildren(){return[...this.projects]}getString(){const e=["(instances"];for(const s of this.projects)e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
124
|
+
`)}},o(Ts,"token","instances"),o(Ts,"parentToken","symbol"),Ts);f.register(bp);var Vo,pd=(Vo=class extends fe{constructor(t,e={}){super(t??!0);o(this,"token","hide");o(this,"inline",!1);this.inline=e.inline??!1}getString(){return this.inline?this.value?"hide":"(hide no)":this.value?"(hide yes)":"(hide no)"}},o(Vo,"token","hide"),o(Vo,"parentToken","pin"),Vo);f.register(pd);var Es,kp=(Es=class extends f{constructor(e){super();o(this,"token","project");o(this,"name");o(this,"paths",[]);this.name=e}static fromSexprPrimitives(e){const[s,...r]=e,i=F(s)??"",a=new Es(i),{arrayPropertyMap:l}=f.parsePrimitivesToClassProperties(r,this.token);return a.paths=l.path??[],a}getChildren(){return[...this.paths]}getString(){const e=[`(project ${D(this.name)}`];for(const s of this.paths)e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
125
|
+
`)}},o(Es,"token","project"),o(Es,"parentToken","instances"),Es);f.register(kp);var Cs,Sp=(Cs=class extends f{constructor(e){super();o(this,"token","path");o(this,"value");o(this,"_sxReference");o(this,"_sxUnit");this.value=e}static fromSexprPrimitives(e){const[s,...r]=e,i=F(s)??"",a=new Cs(i),{propertyMap:l}=f.parsePrimitivesToClassProperties(r,this.token);return a._sxReference=l.reference,a._sxUnit=l.unit,a}get reference(){var e;return(e=this._sxReference)==null?void 0:e.value}set reference(e){this._sxReference=e===void 0?void 0:new g_(e)}get unit(){var e;return(e=this._sxUnit)==null?void 0:e.value}set unit(e){this._sxUnit=e===void 0?void 0:new __(e)}getChildren(){const e=[];return this._sxReference&&e.push(this._sxReference),this._sxUnit&&e.push(this._sxUnit),e}getString(){const e=[`(path ${D(this.value)}`];for(const s of this.getChildren())e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
126
|
+
`)}},o(Cs,"token","path"),o(Cs,"parentToken","project"),Cs);f.register(Sp);var Ns,g_=(Ns=class extends f{constructor(e){super();o(this,"token","reference");o(this,"value");this.value=e}static fromSexprPrimitives(e){const[s]=e;return new Ns(F(s)??"")}getString(){return`(reference ${D(this.value)})`}},o(Ns,"token","reference"),o(Ns,"parentToken","path"),Ns);f.register(g_);var Ho,__=(Ho=class extends oe{constructor(){super(...arguments);o(this,"token","unit")}},o(Ho,"token","unit"),o(Ho,"parentToken","path"),Ho);f.register(__);var mf=new Set(["symbol"]),$s,m_=($s=class extends f{constructor(){super(...arguments);o(this,"token","lib_symbols");o(this,"_symbols",[])}static fromSexprPrimitives(e){const s=new $s,{propertyMap:r,arrayPropertyMap:i}=f.parsePrimitivesToClassProperties(e,this.token),a=Object.keys(r).filter(h=>!mf.has(h));if(a.length>0)throw new Error(`Unsupported child tokens inside lib_symbols expression: ${a.join(", ")}`);const l=Object.keys(i).filter(h=>!mf.has(h));if(l.length>0)throw new Error(`Unsupported repeated child tokens inside lib_symbols expression: ${l.join(", ")}`);const c=i.symbol??[];return!c.length&&r.symbol&&c.push(r.symbol),s._symbols=c,s}get symbols(){return[...this._symbols]}set symbols(e){this._symbols=[...e]}getChildren(){return[...this._symbols]}},o($s,"token","lib_symbols"),o($s,"parentToken","kicad_sch"),$s);f.register(m_);var xf=new Set(["pts","stroke","uuid"]),As,x_=(As=class extends f{constructor(e={}){super();o(this,"token","wire");o(this,"_sxPts");o(this,"_sxStroke");o(this,"_sxUuid");e.points!==void 0&&(this.points=e.points),e.stroke!==void 0&&(this.stroke=e.stroke),e.uuid!==void 0&&(this.uuid=e.uuid)}static fromSexprPrimitives(e){var l;const s=new As,{propertyMap:r,arrayPropertyMap:i}=f.parsePrimitivesToClassProperties(e,this.token);for(const[c,h]of Object.entries(i)){if(!xf.has(c))throw new Error(`Unsupported child tokens inside wire expression: ${c}`);if(h.length>1)throw new Error(`wire does not support repeated child tokens: ${c}`)}const a=Object.keys(r).filter(c=>!xf.has(c));if(a.length>0)throw new Error(`Unsupported child tokens inside wire expression: ${a.join(", ")}`);return s._sxPts=((l=i.pts)==null?void 0:l[0])??r.pts,s._sxStroke=r.stroke,s._sxUuid=r.uuid,s}get points(){return this._sxPts}set points(e){this._sxPts=e}get stroke(){return this._sxStroke}set stroke(e){this._sxStroke=e}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}getChildren(){const e=[];return this._sxPts&&e.push(this._sxPts),this._sxStroke&&e.push(this._sxStroke),this._sxUuid&&e.push(this._sxUuid),e}},o(As,"token","wire"),o(As,"parentToken","kicad_sch"),As);f.register(x_);var Rk=new Set(["pts","stroke","uuid"]),Is,Ok=(Is=class extends f{constructor(e={}){super();o(this,"token","bus");o(this,"_sxPts");o(this,"_sxStroke");o(this,"_sxUuid");e.points!==void 0&&(this.points=e.points),e.stroke!==void 0&&(this.stroke=e.stroke),e.uuid!==void 0&&(this.uuid=e.uuid)}static fromSexprPrimitives(e){const s=new Is,{propertyMap:r,arrayPropertyMap:i}=f.parsePrimitivesToClassProperties(e,this.token);if(Object.keys(i).length>0){const l=Object.keys(i).join(", ");throw new Error(`bus does not support repeated child tokens: ${l}`)}const a=Object.keys(r).filter(l=>!Rk.has(l));if(a.length>0)throw new Error(`Unsupported child tokens inside bus expression: ${a.join(", ")}`);return s._sxPts=r.pts,s._sxStroke=r.stroke,s._sxUuid=r.uuid,s}get points(){return this._sxPts}set points(e){this._sxPts=e}get stroke(){return this._sxStroke}set stroke(e){this._sxStroke=e}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}getChildren(){const e=[];return this._sxPts&&e.push(this._sxPts),this._sxStroke&&e.push(this._sxStroke),this._sxUuid&&e.push(this._sxUuid),e}},o(Is,"token","bus"),o(Is,"parentToken","kicad_sch"),Is);f.register(Ok);var Ls,y_=(Ls=class extends f{constructor(e={}){super();o(this,"token","junction");o(this,"_sxAt");o(this,"_sxDiameter");o(this,"_sxColor");o(this,"_sxUuid");e.at!==void 0&&(this.at=e.at),e.diameter!==void 0&&(e.diameter instanceof Ta?this._sxDiameter=e.diameter:this.diameter=e.diameter),e.color!==void 0&&(this.color=e.color),e.uuid!==void 0&&(this.uuid=e.uuid)}static fromSexprPrimitives(e){const s=new Ls;for(const r of e){if(!Array.isArray(r)||r.length===0)throw new Error(`junction encountered invalid child expression: ${JSON.stringify(r)}`);const i=f.parsePrimitiveSexpr(r,{parentToken:this.token});if(!(i instanceof f))throw new Error(`junction child did not resolve to an SxClass: ${JSON.stringify(r)}`);if(i instanceof he){if(s._sxAt)throw new Error("junction encountered duplicate at tokens");s._sxAt=i;continue}if(i instanceof Ta){if(s._sxDiameter)throw new Error("junction encountered duplicate diameter tokens");s._sxDiameter=i;continue}if(i instanceof fp){if(s._sxColor)throw new Error("junction encountered duplicate color tokens");s._sxColor=i;continue}if(i instanceof W){if(s._sxUuid)throw new Error("junction encountered duplicate uuid tokens");s._sxUuid=i;continue}throw new Error(`Unsupported child tokens inside junction expression: ${i.token}`)}return s}get at(){return this._sxAt}set at(e){this._sxAt=e!==void 0?he.from(e):void 0}get diameter(){var e;return(e=this._sxDiameter)==null?void 0:e.value}set diameter(e){this._sxDiameter=e===void 0?void 0:new Ta(e)}get color(){return this._sxColor}set color(e){this._sxColor=e}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}getChildren(){const e=[];return this._sxAt&&e.push(this._sxAt),this._sxDiameter&&e.push(this._sxDiameter),this._sxColor&&e.push(this._sxColor),this._sxUuid&&e.push(this._sxUuid),e}},o(Ls,"token","junction"),o(Ls,"parentToken","kicad_sch"),Ls);f.register(y_);var Yo,Ta=(Yo=class extends oe{constructor(){super(...arguments);o(this,"token","diameter")}},o(Yo,"token","diameter"),o(Yo,"parentToken","junction"),Yo);f.register(Ta);var Fk=new Set(["at","uuid"]),Ms,zk=(Ms=class extends f{constructor(e={}){super();o(this,"token","no_connect");o(this,"_sxAt");o(this,"_sxUuid");e.at!==void 0&&(this.at=e.at),e.uuid!==void 0&&(this.uuid=e.uuid)}static fromSexprPrimitives(e){const s=new Ms,{propertyMap:r,arrayPropertyMap:i}=f.parsePrimitivesToClassProperties(e,this.token);if(Object.keys(i).length>0){const l=Object.keys(i).join(", ");throw new Error(`no_connect does not support repeated child tokens: ${l}`)}const a=Object.keys(r).filter(l=>!Fk.has(l));if(a.length>0)throw new Error(`Unsupported child tokens inside no_connect expression: ${a.join(", ")}`);return s._sxAt=r.at,s._sxUuid=r.uuid,s}get at(){return this._sxAt}set at(e){this._sxAt=e!==void 0?he.from(e):void 0}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}getChildren(){const e=[];return this._sxAt&&e.push(this._sxAt),this._sxUuid&&e.push(this._sxUuid),e}},o(Ms,"token","no_connect"),o(Ms,"parentToken","kicad_sch"),Ms);f.register(zk);var Uk=new Set(["at","size","stroke","uuid"]),Rs,jk=(Rs=class extends f{constructor(e={}){super();o(this,"token","bus_entry");o(this,"_sxAt");o(this,"_sxSize");o(this,"_sxStroke");o(this,"_sxUuid");e.at!==void 0&&(this.at=e.at),e.size!==void 0&&(this.size=e.size),e.stroke!==void 0&&(this.stroke=e.stroke),e.uuid!==void 0&&(this.uuid=e.uuid)}static fromSexprPrimitives(e){const s=new Rs,{propertyMap:r,arrayPropertyMap:i}=f.parsePrimitivesToClassProperties(e,this.token);if(Object.keys(i).length>0){const l=Object.keys(i).join(", ");throw new Error(`bus_entry does not support repeated child tokens: ${l}`)}const a=Object.keys(r).filter(l=>!Uk.has(l));if(a.length>0)throw new Error(`Unsupported child tokens inside bus_entry expression: ${a.join(", ")}`);return s._sxAt=r.at,s._sxSize=r.size,s._sxStroke=r.stroke,s._sxUuid=r.uuid,s}get at(){return this._sxAt}set at(e){this._sxAt=e!==void 0?he.from(e):void 0}get size(){var e;return(e=this._sxSize)==null?void 0:e.toObject()}set size(e){if(e===void 0){this._sxSize=void 0;return}if(e instanceof fd){this._sxSize=e;return}this._sxSize=new fd(e.x,e.y)}get stroke(){return this._sxStroke}set stroke(e){this._sxStroke=e}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}getChildren(){const e=[];return this._sxAt&&e.push(this._sxAt),this._sxSize&&e.push(this._sxSize),this._sxStroke&&e.push(this._sxStroke),this._sxUuid&&e.push(this._sxUuid),e}},o(Rs,"token","bus_entry"),o(Rs,"parentToken","kicad_sch"),Rs);f.register(jk);var Os,fd=(Os=class extends f{constructor(e,s){super();o(this,"token","size");o(this,"_x");o(this,"_y");this._x=e,this._y=s}static fromSexprPrimitives(e){const[s,r]=e;if(typeof s!="number"||typeof r!="number")throw new Error("bus_entry size expects two numeric arguments");return new Os(s,r)}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(size ${this._x} ${this._y})`}},o(Os,"token","size"),o(Os,"parentToken","bus_entry"),Os);f.register(fd);var yf=new Set(["at","effects","uuid","fields_autoplaced"]),Fs,Bk=(Fs=class extends f{constructor(e={}){super();o(this,"token","label");o(this,"_value","");o(this,"_sxAt");o(this,"_sxEffects");o(this,"_sxUuid");o(this,"_sxFieldsAutoplaced");e.value!==void 0&&(this.value=e.value),e.at!==void 0&&(this.at=e.at),e.effects!==void 0&&(this.effects=e.effects),e.uuid!==void 0&&(this.uuid=e.uuid),e.fieldsAutoplaced!==void 0&&(e.fieldsAutoplaced instanceof ti?this._sxFieldsAutoplaced=e.fieldsAutoplaced:this.fieldsAutoplaced=e.fieldsAutoplaced)}static fromSexprPrimitives(e){var d,p,u,g;const[s,...r]=e,i=F(s);if(i===void 0)throw new Error("label expects a string value");const a=new Fs;a._value=i;const{propertyMap:l,arrayPropertyMap:c}=f.parsePrimitivesToClassProperties(r,this.token),h=Object.keys(l).filter(_=>!yf.has(_));if(h.length>0)throw new Error(`Unsupported child tokens inside label expression: ${h.join(", ")}`);for(const[_,x]of Object.entries(c)){if(!yf.has(_))throw new Error(`Unsupported child tokens inside label expression: ${_}`);if(x.length>1)throw new Error(`label does not support repeated child tokens: ${_}`)}return a._sxAt=((d=c.at)==null?void 0:d[0])??l.at,a._sxEffects=((p=c.effects)==null?void 0:p[0])??l.effects,a._sxUuid=((u=c.uuid)==null?void 0:u[0])??l.uuid,a._sxFieldsAutoplaced=((g=c.fields_autoplaced)==null?void 0:g[0])??l.fields_autoplaced,a}get value(){return this._value}set value(e){this._value=e}get at(){return this._sxAt}set at(e){this._sxAt=e!==void 0?he.from(e):void 0}get effects(){return this._sxEffects}set effects(e){this._sxEffects=e}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}get fieldsAutoplaced(){var e;return((e=this._sxFieldsAutoplaced)==null?void 0:e.value)??!1}set fieldsAutoplaced(e){this._sxFieldsAutoplaced=new ti(e)}getChildren(){const e=[];return this._sxAt&&e.push(this._sxAt),this._sxEffects&&e.push(this._sxEffects),this._sxUuid&&e.push(this._sxUuid),this._sxFieldsAutoplaced&&e.push(this._sxFieldsAutoplaced),e}getString(){const e=[`(label ${D(this._value)}`];for(const s of this.getChildren())e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
127
|
+
`)}},o(Fs,"token","label"),o(Fs,"parentToken","kicad_sch"),Fs);f.register(Bk);var Xo,gd=(Xo=class extends fe{constructor(){super(...arguments);o(this,"token","hide")}},o(Xo,"token","hide"),o(Xo,"parentToken","property"),Xo);f.register(gd);var qo,_d=(qo=class extends fe{constructor(){super(...arguments);o(this,"token","unlocked")}},o(qo,"token","unlocked"),o(qo,"parentToken","property"),qo);f.register(_d);var vf=new Set(["at","xy","layer","uuid","effects","unlocked","hide"]),Dk=(n,t)=>{const e=n[t];if(e&&e.length>1)throw new Error(`property does not support repeated "${t}" children`)},wf=n=>{if(n===void 0)return;const t=F(n);return t!==void 0?t:Ie(n)},Rr,v_=(Rr=class extends f{constructor(e={},s=""){super();o(this,"token","property");o(this,"_key","");o(this,"_value","");o(this,"_sxAt");o(this,"_sxXy");o(this,"_sxLayer");o(this,"_sxUuid");o(this,"_sxEffects");o(this,"_sxUnlocked");o(this,"_sxHide");if(typeof e=="string")this._key=e,this._value=s;else{const r=e;r.key!==void 0&&(this._key=r.key),r.value!==void 0&&(this._value=r.value),r.position!==void 0&&(this.position=r.position),r.layer!==void 0&&(this.layer=r.layer),r.uuid!==void 0&&(this.uuid=r.uuid),r.effects!==void 0&&(this.effects=r.effects),r.unlocked!==void 0&&(r.unlocked instanceof _d?this._sxUnlocked=r.unlocked:this.unlocked=r.unlocked),r.hidden!==void 0&&(r.hidden instanceof gd?this._sxHide=r.hidden:this.hidden=r.hidden)}}static fromSexprPrimitives(e){if(e.length<2)throw new Error("property requires key and value arguments");const[s,r,...i]=e,a=wf(s),l=wf(r);if(a===void 0)throw new Error("property key must be a printable value");if(l===void 0)throw new Error("property value must be a printable value");for(const g of i){if(!Array.isArray(g))throw new Error(`property encountered unexpected primitive child: ${JSON.stringify(g)}`);if(g.length===0||typeof g[0]!="string")throw new Error(`property encountered invalid child expression: ${JSON.stringify(g)}`)}const c=new Rr(a,l),{propertyMap:h,arrayPropertyMap:d}=f.parsePrimitivesToClassProperties(i,this.token);for(const g of Object.keys(h))if(!vf.has(g))throw new Error(`property encountered unsupported child token "${g}"`);for(const g of Object.keys(d)){if(!vf.has(g))throw new Error(`property encountered unsupported child token "${g}"`);Dk(d,g)}const p=h.at,u=h.xy;if(p&&u)throw new Error("property can't include both at and xy children");return c._sxAt=p,c._sxXy=u,c._sxLayer=h.layer,c._sxUuid=h.uuid,c._sxEffects=h.effects,c._sxUnlocked=h.unlocked,c._sxHide=h.hide,c}get key(){return this._key}set key(e){this._key=e}get value(){return this._value}set value(e){this._value=e}get position(){return this._sxAt??this._sxXy}set position(e){if(e===void 0){this._sxAt=void 0,this._sxXy=void 0;return}if(e instanceof et){this._sxXy=e,this._sxAt=void 0;return}this._sxAt=he.from(e),this._sxXy=void 0}get layer(){return this._sxLayer}set layer(e){if(e===void 0){this._sxLayer=void 0;return}if(e instanceof ce){this._sxLayer=e;return}const s=Array.isArray(e)?e:[e];this._sxLayer=new ce(s)}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}get effects(){return this._sxEffects}set effects(e){this._sxEffects=e}get unlocked(){var e;return((e=this._sxUnlocked)==null?void 0:e.value)??!1}set unlocked(e){this._sxUnlocked=new _d(e)}get hidden(){var e;return((e=this._sxHide)==null?void 0:e.value)??!1}set hidden(e){this._sxHide=new gd(e)}getChildren(){const e=[];return this._sxAt&&e.push(this._sxAt),this._sxXy&&e.push(this._sxXy),this._sxUnlocked&&e.push(this._sxUnlocked),this._sxLayer&&e.push(this._sxLayer),this._sxHide&&e.push(this._sxHide),this._sxUuid&&e.push(this._sxUuid),this._sxEffects&&e.push(this._sxEffects),e}getString(){const e=[`(property ${D(this._key)} ${D(this._value)}`];for(const s of this.getChildren())e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
128
|
+
`)}},o(Rr,"token","property"),Rr);f.register(v_);var bf=new Set(["shape","at","effects","uuid","fields_autoplaced","property"]),zs,w_=(zs=class extends f{constructor(e={}){super();o(this,"token","global_label");o(this,"_value","");o(this,"_shape","input");o(this,"_sxAt");o(this,"_sxEffects");o(this,"_sxUuid");o(this,"_sxFieldsAutoplaced");o(this,"_properties",[]);e.value!==void 0&&(this.value=e.value),e.shape!==void 0&&(this.shape=e.shape),e.at!==void 0&&(this.at=e.at),e.effects!==void 0&&(this.effects=e.effects),e.uuid!==void 0&&(this.uuid=e.uuid),e.fieldsAutoplaced!==void 0&&(e.fieldsAutoplaced instanceof ti?this._sxFieldsAutoplaced=e.fieldsAutoplaced:this.fieldsAutoplaced=e.fieldsAutoplaced),e.properties!==void 0&&(this.properties=e.properties)}static fromSexprPrimitives(e){var u,g,_,x;const[s,...r]=e,i=F(s);if(i===void 0)throw new Error("global_label expects a string value");const a=new zs;a._value=i;let l=-1;for(let v=0;v<r.length;v++){const m=r[v];if(Array.isArray(m)&&m[0]==="shape"&&m.length===2){l=v;const y=F(m[1]);y&&(a._shape=y);break}}const c=l>=0?r.filter((v,m)=>m!==l):r,{propertyMap:h,arrayPropertyMap:d}=f.parsePrimitivesToClassProperties(c,this.token),p=Object.keys(h).filter(v=>!bf.has(v));if(p.length>0)throw new Error(`Unsupported child tokens inside global_label expression: ${p.join(", ")}`);for(const[v,m]of Object.entries(d)){if(!bf.has(v))throw new Error(`Unsupported child tokens inside global_label expression: ${v}`);if(v!=="property"&&m.length>1)throw new Error(`global_label does not support repeated child tokens: ${v}`)}return a._sxAt=((u=d.at)==null?void 0:u[0])??h.at,a._sxEffects=((g=d.effects)==null?void 0:g[0])??h.effects,a._sxUuid=((_=d.uuid)==null?void 0:_[0])??h.uuid,a._sxFieldsAutoplaced=((x=d.fields_autoplaced)==null?void 0:x[0])??h.fields_autoplaced,a._properties=d.property??[],a}get value(){return this._value}set value(e){this._value=e}get shape(){return this._shape}set shape(e){this._shape=e}get at(){return this._sxAt}set at(e){this._sxAt=e!==void 0?he.from(e):void 0}get effects(){return this._sxEffects}set effects(e){this._sxEffects=e}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}get fieldsAutoplaced(){var e;return((e=this._sxFieldsAutoplaced)==null?void 0:e.value)??!1}set fieldsAutoplaced(e){this._sxFieldsAutoplaced=new ti(e)}get properties(){return[...this._properties]}set properties(e){this._properties=[...e]}getChildren(){const e=[];return this._sxAt&&e.push(this._sxAt),this._sxEffects&&e.push(this._sxEffects),this._sxUuid&&e.push(this._sxUuid),e.push(...this._properties),this._sxFieldsAutoplaced&&e.push(this._sxFieldsAutoplaced),e}getString(){const e=[`(global_label ${D(this._value)}`];e.push(` (shape ${this._shape})`);for(const s of this.getChildren())e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
129
|
+
`)}},o(zs,"token","global_label"),o(zs,"parentToken","kicad_sch"),zs);f.register(w_);var kf=new Set(["exclude_from_sim","at","effects","uuid"]),Us,Wk=(Us=class extends f{constructor(e={}){super();o(this,"token","text");o(this,"_value","");o(this,"_sxExcludeFromSim");o(this,"_sxAt");o(this,"_sxEffects");o(this,"_sxUuid");e.value!==void 0&&(this.value=e.value),e.excludeFromSim!==void 0&&(this.excludeFromSim=typeof e.excludeFromSim=="boolean"?e.excludeFromSim:e.excludeFromSim.value),e.at!==void 0&&(this.at=e.at),e.effects!==void 0&&(this.effects=e.effects),e.uuid!==void 0&&(this.uuid=e.uuid)}static fromSexprPrimitives(e){var d,p,u,g;const[s,...r]=e,i=F(s);if(i===void 0)throw new Error("text expects a string value");const a=new Us;a._value=i;const{propertyMap:l,arrayPropertyMap:c}=f.parsePrimitivesToClassProperties(r,this.token),h=Object.keys(l).filter(_=>!kf.has(_));if(h.length>0)throw new Error(`Unsupported child tokens inside text expression: ${h.join(", ")}`);for(const[_,x]of Object.entries(c)){if(!kf.has(_))throw new Error(`Unsupported child tokens inside text expression: ${_}`);if(x.length>1)throw new Error(`text does not support repeated child tokens: ${_}`)}return a._sxExcludeFromSim=((d=c.exclude_from_sim)==null?void 0:d[0])??l.exclude_from_sim,a._sxAt=((p=c.at)==null?void 0:p[0])??l.at,a._sxEffects=((u=c.effects)==null?void 0:u[0])??l.effects,a._sxUuid=((g=c.uuid)==null?void 0:g[0])??l.uuid,a}get value(){return this._value}set value(e){this._value=e}get excludeFromSim(){var e;return((e=this._sxExcludeFromSim)==null?void 0:e.value)??!1}set excludeFromSim(e){this._sxExcludeFromSim=e?new hc(!0):void 0}get at(){return this._sxAt}set at(e){this._sxAt=e!==void 0?he.from(e):void 0}get effects(){return this._sxEffects}set effects(e){this._sxEffects=e}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}getChildren(){const e=[];return this._sxExcludeFromSim&&e.push(this._sxExcludeFromSim),this._sxAt&&e.push(this._sxAt),this._sxEffects&&e.push(this._sxEffects),this._sxUuid&&e.push(this._sxUuid),e}getString(){const e=[`(text ${D(this._value)}`];for(const s of this.getChildren())e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
130
|
+
`)}},o(Us,"token","text"),o(Us,"parentToken","kicad_sch"),Us);f.register(Wk);var Sf=new Set(["page"]),Or,Gk=(Or=class extends f{constructor(){super(...arguments);o(this,"token","sheet_instances");o(this,"_paths",[])}static fromSexprPrimitives(e){const s=new Or,{propertyMap:r,arrayPropertyMap:i}=f.parsePrimitivesToClassProperties(e,this.token),a=Object.keys(r).filter(h=>h!=="path");if(a.length>0)throw new Error(`Unsupported singular child tokens inside sheet_instances expression: ${a.join(", ")}`);const l=Object.keys(i).filter(h=>h!=="path");if(l.length>0)throw new Error(`Unsupported repeated child tokens inside sheet_instances expression: ${l.join(", ")}`);const c=i.path??[];return!c.length&&r.path&&c.push(r.path),s._paths=c,s}get paths(){return[...this._paths]}set paths(e){this._paths=[...e]}getChildren(){return[...this._paths]}},o(Or,"token","sheet_instances"),Or);f.register(Gk);var js,b_=(js=class extends f{constructor(){super(...arguments);o(this,"token","path");o(this,"_value","");o(this,"_pages",[])}static fromSexprPrimitives(e){const[s,...r]=e,i=F(s);if(i===void 0)throw new Error("sheet_instances path requires a string identifier");const a=new js;a._value=i;const{propertyMap:l,arrayPropertyMap:c}=f.parsePrimitivesToClassProperties(r,"sheet_instances_path"),h=Object.keys(l).filter(u=>!Sf.has(u));if(h.length>0)throw new Error(`Unsupported singular child tokens inside sheet_instances path expression: ${h.join(", ")}`);const d=Object.keys(c).filter(u=>!Sf.has(u));if(d.length>0)throw new Error(`Unsupported repeated child tokens inside sheet_instances path expression: ${d.join(", ")}`);const p=c.page??[];return!p.length&&l.page&&p.push(l.page),a._pages=p,a}get value(){return this._value}set value(e){this._value=e}get pages(){return[...this._pages]}set pages(e){this._pages=[...e]}getChildren(){return[...this._pages]}getString(){const e=[`(path ${D(this._value)}`];for(const s of this._pages)e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
131
|
+
`)}},o(js,"token","path"),o(js,"parentToken","sheet_instances"),js);f.register(b_);var Bs,k_=(Bs=class extends Rt{constructor(){super(...arguments);o(this,"token","page")}static fromSexprPrimitives(e){const[s]=e,r=F(s);if(r===void 0)throw new Error("sheet_instances page expects a string value");return new Bs(r)}getString(){return`(page ${D(this.value)})`}},o(Bs,"token","page"),o(Bs,"parentToken","sheet_instances_path"),Bs);f.register(k_);var Pf=new Set(["project","path"]),S_=n=>{const{propertyMap:t,arrayPropertyMap:e}=f.parsePrimitivesToClassProperties(n,"sheet_instances"),s=Object.keys(t).filter(l=>!Pf.has(l));if(s.length>0)throw new Error(`sheet_instances encountered unsupported child token${s.length>1?"s":""} ${s.map(l=>`"${l}"`).join(", ")}`);const r=Object.keys(e).filter(l=>!Pf.has(l));if(r.length>0)throw new Error(`sheet_instances encountered unsupported repeated child token${r.length>1?"s":""} ${r.map(l=>`"${l}"`).join(", ")}`);const i=e.project??[];!i.length&&t.project&&i.push(t.project);const a=e.path??[];return!a.length&&t.path&&a.push(t.path),{projects:i,paths:a}},Ds,Pp=(Ds=class extends f{constructor(){super(...arguments);o(this,"token","sheet_instances");o(this,"_projects",[]);o(this,"_paths",[])}static fromSexprPrimitives(e){const s=new Ds,{projects:r,paths:i}=S_(e);return s.projects=r,s.paths=i,s}get projects(){return[...this._projects]}set projects(e){this._projects=[...e]}get paths(){return[...this._paths]}set paths(e){this._paths=[...e]}getChildren(){return[...this._projects,...this._paths]}getString(){const e=this.getChildren();if(e.length===0)return`(${this.token})`;const s=[`(${this.token}`];for(const r of e)s.push(r.getStringIndented());return s.push(")"),s.join(`
|
|
132
|
+
`)}},o(Ds,"token","sheet_instances"),o(Ds,"parentToken","kicad_sch"),Ds);f.register(Pp);var Ws,Vk=(Ws=class extends Pp{constructor(){super(...arguments);o(this,"token","instances")}static fromSexprPrimitives(e){const s=new Ws,{projects:r,paths:i}=S_(e);return s.projects=r,s.paths=i,s}},o(Ws,"token","instances"),o(Ws,"parentToken","sheet"),Ws);f.register(Vk);var Gs,Hk=(Gs=class extends f{constructor(e){super();o(this,"token","project");o(this,"name");o(this,"paths",[]);this.name=e}static fromSexprPrimitives(e){const[s,...r]=e,i=F(s);if(i===void 0)throw new Error("sheet project instances require a project name");const a=new Gs(i),{arrayPropertyMap:l}=f.parsePrimitivesToClassProperties(r,"sheet_project");return a.paths=l.path??[],a}getChildren(){return[...this.paths]}getString(){const e=[`(project ${D(this.name)}`];for(const s of this.paths)e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
133
|
+
`)}},o(Gs,"token","project"),o(Gs,"parentToken","sheet_instances"),Gs);f.register(Hk);var Vs,Yk=(Vs=class extends f{constructor(e){super();o(this,"token","path");o(this,"value");o(this,"pages",[]);this.value=e}static fromSexprPrimitives(e){const[s,...r]=e,i=F(s);if(i===void 0)throw new Error("sheet instance path value must be a string");const a=new Vs(i),{arrayPropertyMap:l}=f.parsePrimitivesToClassProperties(r,"sheet_path");return a.pages=l.page??[],a}getChildren(){return[...this.pages]}getString(){const e=[`(path ${D(this.value)}`];for(const s of this.pages)e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
134
|
+
`)}},o(Vs,"token","path"),o(Vs,"parentToken","sheet_project"),Vs);f.register(Yk);var Hs,Xk=(Hs=class extends f{constructor(e){super();o(this,"token","page");o(this,"value");this.value=e}static fromSexprPrimitives(e){const[s]=e,r=F(s);if(r===void 0)throw new Error("sheet instance page value must be a string");return new Hs(r)}getString(){return`(page ${D(this.value)})`}},o(Hs,"token","page"),o(Hs,"parentToken","sheet_path"),Hs);f.register(Xk);var Tf=new Set(["input","output","bidirectional","tri_state","passive"]),Ys,qk=(Ys=class extends f{constructor(){super(...arguments);o(this,"token","pin");o(this,"name","");o(this,"electricalType","input");o(this,"_sxAt");o(this,"_sxEffects");o(this,"_sxUuid")}static fromSexprPrimitives(e){if(e.length<2)throw new Error("sheet pin requires a name and electrical type");const[s,r,...i]=e,a=F(s);if(a===void 0)throw new Error("sheet pin name must be a string");const l=F(r);if(!l||!Tf.has(l))throw new Error(`sheet pin electrical type must be one of: ${Array.from(Tf).join(", ")}`);const c=new Ys;c.name=a,c.electricalType=l;const{propertyMap:h}=f.parsePrimitivesToClassProperties(i,this.token);return c._sxAt=h.at,c._sxEffects=h.effects,c._sxUuid=h.uuid,c}get position(){return this._sxAt}set position(e){this._sxAt=e}get effects(){return this._sxEffects}set effects(e){this._sxEffects=e}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}getChildren(){const e=[];return this._sxAt&&e.push(this._sxAt),this._sxEffects&&e.push(this._sxEffects),this._sxUuid&&e.push(this._sxUuid),e}getString(){const e=`(pin ${D(this.name)} ${this.electricalType}`,s=this.getChildren().flatMap(r=>qt(r.getString()));return s.length===0?`${e})`:[e,...s,")"].join(`
|
|
135
|
+
`)}},o(Ys,"token","pin"),o(Ys,"parentToken","sheet"),Ys);f.register(qk);var Xs,Kk=(Xs=class extends f{constructor(){super(...arguments);o(this,"token","fill");o(this,"_sxColor")}static fromSexprPrimitives(e){const s=new Xs,{propertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);return s._sxColor=r.color,s}get color(){return this._sxColor}set color(e){this._sxColor=e}getChildren(){return this._sxColor?[this._sxColor]:[]}},o(Xs,"token","fill"),o(Xs,"parentToken","sheet"),Xs);f.register(Kk);var qs,md=(qs=class extends f{constructor(e,s){super();o(this,"token","size");o(this,"width");o(this,"height");this.width=e,this.height=s}static fromSexprPrimitives(e){const s=O(e[0]),r=O(e[1]);if(s===void 0||r===void 0)throw new Error("sheet size requires numeric width and height");return new qs(s,r)}toObject(){return{width:this.width,height:this.height}}getString(){return`(size ${this.width} ${this.height})`}},o(qs,"token","size"),o(qs,"parentToken","sheet"),qs);f.register(md);var Ks,Jk=(Ks=class extends f{constructor(e){super();o(this,"token","property");o(this,"key");o(this,"value");o(this,"_sxId");o(this,"_sxAt");o(this,"_sxEffects");this.key=e.key,this.value=e.value,this.id=e.id,this.at=e.at,this.effects=e.effects}static fromSexprPrimitives(e){const[s,r,...i]=e,a=F(s),l=F(r);if(a===void 0||l===void 0)throw new Error("sheet property requires string key and value");const{propertyMap:c}=f.parsePrimitivesToClassProperties(i,this.token);return new Ks({key:a,value:l,id:c.id,at:c.at,effects:c.effects})}get id(){var e;return(e=this._sxId)==null?void 0:e.value}set id(e){if(e===void 0){this._sxId=void 0;return}this._sxId=e instanceof Oi?e:new Oi(e)}get idClass(){return this._sxId}get at(){return this._sxAt}set at(e){this._sxAt=e}get effects(){return this._sxEffects}set effects(e){this._sxEffects=e}getChildren(){const e=[];return this._sxId&&e.push(this._sxId),this._sxAt&&e.push(this._sxAt),this._sxEffects&&e.push(this._sxEffects),e}getString(){const e=`(property ${D(this.key)} ${D(this.value)}`,s=this.getChildren().flatMap(r=>qt(r.getString()));return s.length===0?`${e})`:[e,...s,")"].join(`
|
|
136
|
+
`)}},o(Ks,"token","property"),o(Ks,"parentToken","sheet"),Ks);f.register(Jk);var Fr,Zk=(Fr=class extends f{constructor(e={}){super();o(this,"token","sheet");o(this,"_sxAt");o(this,"_sxSize");o(this,"_sxExcludeFromSim");o(this,"_sxInBom");o(this,"_sxOnBoard");o(this,"_sxDnp");o(this,"_sxFieldsAutoplaced");o(this,"_sxStroke");o(this,"_sxFill");o(this,"_sxUuid");o(this,"_properties",[]);o(this,"_pins",[]);o(this,"_sxInstances");e.position!==void 0&&(this.position=e.position),e.size!==void 0&&(this.size=e.size),e.excludeFromSim!==void 0&&(this.excludeFromSim=typeof e.excludeFromSim=="boolean"?e.excludeFromSim:e.excludeFromSim.value),e.inBom!==void 0&&(this.inBom=typeof e.inBom=="boolean"?e.inBom:e.inBom.value),e.onBoard!==void 0&&(this.onBoard=typeof e.onBoard=="boolean"?e.onBoard:e.onBoard.value),e.dnp!==void 0&&(this.dnp=typeof e.dnp=="boolean"?e.dnp:e.dnp.value),e.fieldsAutoplaced!==void 0&&(this.fieldsAutoplaced=typeof e.fieldsAutoplaced=="boolean"?e.fieldsAutoplaced:e.fieldsAutoplaced.value),e.stroke!==void 0&&(this.stroke=e.stroke),e.fill!==void 0&&(this.fill=e.fill),e.uuid!==void 0&&(this.uuid=e.uuid),e.properties!==void 0&&(this.properties=e.properties),e.pins!==void 0&&(this.pins=e.pins),e.instances!==void 0&&(this.instances=e.instances)}static fromSexprPrimitives(e){const s=new Fr,{propertyMap:r,arrayPropertyMap:i}=f.parsePrimitivesToClassProperties(e,this.token);return s._sxAt=r.at,s._sxSize=r.size,s._sxExcludeFromSim=r.exclude_from_sim,s._sxInBom=r.in_bom,s._sxOnBoard=r.on_board,s._sxDnp=r.dnp,s._sxFieldsAutoplaced=r.fields_autoplaced,s._sxStroke=r.stroke,s._sxFill=r.fill,s._sxUuid=r.uuid,s._properties=i.property??[],s._pins=i.pin??[],s._sxInstances=r.instances,s}get position(){return this._sxAt}set position(e){this._sxAt=e!==void 0?he.from(e):void 0}get size(){var e;return(e=this._sxSize)==null?void 0:e.toObject()}set size(e){if(e===void 0){this._sxSize=void 0;return}if(e instanceof md){this._sxSize=e;return}this._sxSize=new md(e.width,e.height)}get excludeFromSim(){var e;return((e=this._sxExcludeFromSim)==null?void 0:e.value)??!1}set excludeFromSim(e){this._sxExcludeFromSim=new hc(e)}get inBom(){var e;return((e=this._sxInBom)==null?void 0:e.value)??!1}set inBom(e){this._sxInBom=new _p(e)}get onBoard(){var e;return((e=this._sxOnBoard)==null?void 0:e.value)??!1}set onBoard(e){this._sxOnBoard=new mp(e)}get dnp(){var e;return((e=this._sxDnp)==null?void 0:e.value)??!1}set dnp(e){this._sxDnp=new xp(e)}get fieldsAutoplaced(){var e;return((e=this._sxFieldsAutoplaced)==null?void 0:e.value)??!1}set fieldsAutoplaced(e){this._sxFieldsAutoplaced=new ti(e)}get stroke(){return this._sxStroke}set stroke(e){this._sxStroke=e}get fill(){return this._sxFill}set fill(e){this._sxFill=e}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}get properties(){return this._properties}set properties(e){this._properties=e}get pins(){return this._pins}set pins(e){this._pins=e}get instances(){return this._sxInstances}set instances(e){this._sxInstances=e}getChildren(){const e=[];return this._sxAt&&e.push(this._sxAt),this._sxSize&&e.push(this._sxSize),this._sxExcludeFromSim&&e.push(this._sxExcludeFromSim),this._sxInBom&&e.push(this._sxInBom),this._sxOnBoard&&e.push(this._sxOnBoard),this._sxDnp&&e.push(this._sxDnp),this._sxFieldsAutoplaced&&e.push(this._sxFieldsAutoplaced),this._sxStroke&&e.push(this._sxStroke),this._sxFill&&e.push(this._sxFill),this._sxUuid&&e.push(this._sxUuid),e.push(...this._properties),e.push(...this._pins),this._sxInstances&&e.push(this._sxInstances),e}},o(Fr,"token","sheet"),Fr);f.register(Zk);var Qk=new Set(["version","generator","generator_version","uuid","paper","title_block","lib_symbols","embedded_fonts"]),P_=new Set(["property","image","sheet","symbol","text","label","global_label","junction","wire","sheet_instances"]),Ef=new Set([...Qk,...P_]),zr,T_=(zr=class extends f{constructor(e={}){super();o(this,"token","kicad_sch");o(this,"_sxVersion");o(this,"_sxGenerator");o(this,"_sxGeneratorVersion");o(this,"_sxUuid");o(this,"_sxPaper");o(this,"_sxTitleBlock");o(this,"_sxLibSymbols");o(this,"_sheetInstances",[]);o(this,"_sxEmbeddedFonts");o(this,"_properties",[]);o(this,"_images",[]);o(this,"_sheets",[]);o(this,"_symbols",[]);o(this,"_texts",[]);o(this,"_labels",[]);o(this,"_globalLabels",[]);o(this,"_wires",[]);o(this,"_junctions",[]);e.version instanceof hd?this._sxVersion=e.version:e.version!==void 0&&(this.version=e.version),e.generator instanceof ld?this._sxGenerator=e.generator:e.generator!==void 0&&(this.generator=e.generator),e.generatorVersion instanceof dd?this._sxGeneratorVersion=e.generatorVersion:e.generatorVersion!==void 0&&(this.generatorVersion=e.generatorVersion),e.uuid!==void 0&&(this.uuid=e.uuid),e.paper!==void 0&&(this.paper=e.paper),e.titleBlock!==void 0&&(this.titleBlock=e.titleBlock),e.libSymbols!==void 0&&(this.libSymbols=e.libSymbols),e.sheetInstances!==void 0&&(this.sheetInstances=e.sheetInstances),e.embeddedFonts!==void 0&&(this.embeddedFonts=e.embeddedFonts),e.properties!==void 0&&(this.properties=e.properties),e.images!==void 0&&(this.images=e.images),e.sheets!==void 0&&(this.sheets=e.sheets),e.symbols!==void 0&&(this.symbols=e.symbols),e.texts!==void 0&&(this.texts=e.texts),e.labels!==void 0&&(this.labels=e.labels),e.globalLabels!==void 0&&(this.globalLabels=e.globalLabels),e.wires!==void 0&&(this.wires=e.wires),e.junctions!==void 0&&(this.junctions=e.junctions)}static fromSexprPrimitives(e){for(const i of e){if(!Array.isArray(i))throw new Error(`kicad_sch encountered unexpected primitive child: ${JSON.stringify(i)}`);if(i.length===0||typeof i[0]!="string")throw new Error(`kicad_sch encountered invalid child expression: ${JSON.stringify(i)}`)}const{propertyMap:s,arrayPropertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);for(const i of Object.keys(s))if(!Ef.has(i))throw new Error(`kicad_sch encountered unsupported child token "${i}"`);for(const[i,a]of Object.entries(r)){if(!Ef.has(i))throw new Error(`kicad_sch encountered unsupported child token "${i}"`);if(!P_.has(i)&&a.length>1)throw new Error(`kicad_sch does not support repeated child token "${i}"`)}return new zr({version:s.version,generator:s.generator,generatorVersion:s.generator_version,uuid:s.uuid,paper:s.paper,titleBlock:s.title_block,libSymbols:s.lib_symbols,sheetInstances:r.sheet_instances,embeddedFonts:s.embedded_fonts,properties:r.property??[],images:r.image??[],sheets:r.sheet??[],symbols:r.symbol??[],texts:r.text??[],labels:r.label??[],globalLabels:r.global_label??[],junctions:r.junction??[],wires:r.wire??[]})}get version(){var e;return(e=this._sxVersion)==null?void 0:e.value}set version(e){this._sxVersion=e===void 0?void 0:new hd(e)}get generator(){var e;return(e=this._sxGenerator)==null?void 0:e.value}set generator(e){this._sxGenerator=e===void 0?void 0:new ld(e)}get generatorVersion(){var e;return(e=this._sxGeneratorVersion)==null?void 0:e.value}set generatorVersion(e){this._sxGeneratorVersion=e===void 0?void 0:new dd(e)}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}get paper(){return this._sxPaper}set paper(e){this._sxPaper=e}get titleBlock(){return this._sxTitleBlock}set titleBlock(e){this._sxTitleBlock=e}get libSymbols(){return this._sxLibSymbols}set libSymbols(e){this._sxLibSymbols=e}get sheetInstances(){return[...this._sheetInstances]}set sheetInstances(e){if(e===void 0){this._sheetInstances=[];return}this._sheetInstances=Array.isArray(e)?[...e]:[e]}get embeddedFonts(){return this._sxEmbeddedFonts}set embeddedFonts(e){this._sxEmbeddedFonts=e}get properties(){return[...this._properties]}set properties(e){this._properties=[...e]}get images(){return[...this._images]}set images(e){this._images=[...e]}get sheets(){return[...this._sheets]}set sheets(e){this._sheets=[...e]}get symbols(){return[...this._symbols]}set symbols(e){this._symbols=[...e]}get texts(){return[...this._texts]}set texts(e){this._texts=[...e]}get labels(){return[...this._labels]}set labels(e){this._labels=[...e]}get globalLabels(){return[...this._globalLabels]}set globalLabels(e){this._globalLabels=[...e]}get junctions(){return[...this._junctions]}set junctions(e){this._junctions=[...e]}get wires(){return[...this._wires]}set wires(e){this._wires=[...e]}getChildren(){const e=[];return this._sxVersion&&e.push(this._sxVersion),this._sxGenerator&&e.push(this._sxGenerator),this._sxGeneratorVersion&&e.push(this._sxGeneratorVersion),this._sxUuid&&e.push(this._sxUuid),this._sxPaper&&e.push(this._sxPaper),this._sxTitleBlock&&e.push(this._sxTitleBlock),this._sxLibSymbols&&e.push(this._sxLibSymbols),e.push(...this._sheetInstances),this._sxEmbeddedFonts&&e.push(this._sxEmbeddedFonts),e.push(...this._properties),e.push(...this._images),e.push(...this._sheets),e.push(...this._symbols),e.push(...this._texts),e.push(...this._labels),e.push(...this._globalLabels),e.push(...this._junctions),e.push(...this._wires),e}},o(zr,"token","kicad_sch"),zr);f.register(T_);var e0=new Set(["board_only","exclude_from_pos_files","exclude_from_bom"]),Js,t0=(Js=class extends f{constructor(){super(...arguments);o(this,"token","attr");o(this,"_type");o(this,"_boardOnly",!1);o(this,"_excludeFromPosFiles",!1);o(this,"_excludeFromBom",!1)}static fromSexprPrimitives(e){const s=new Js;for(const r of e){if(typeof r!="string")throw new Error(`attr encountered unsupported child: ${JSON.stringify(r)}`);if(e0.has(r)){s.applyFlag(r);continue}if(s._type===void 0){s._type=r;continue}throw new Error(`attr encountered duplicate or unknown token "${r}"`)}return s}applyFlag(e){switch(e){case"board_only":this._boardOnly=!0;break;case"exclude_from_pos_files":this._excludeFromPosFiles=!0;break;case"exclude_from_bom":this._excludeFromBom=!0;break}}get type(){return this._type}set type(e){this._type=e}get boardOnly(){return this._boardOnly}set boardOnly(e){this._boardOnly=e}get excludeFromPosFiles(){return this._excludeFromPosFiles}set excludeFromPosFiles(e){this._excludeFromPosFiles=e}get excludeFromBom(){return this._excludeFromBom}set excludeFromBom(e){this._excludeFromBom=e}getChildren(){return[]}getString(){const e=["attr"];return this._type&&e.push(this._type),this._boardOnly&&e.push("board_only"),this._excludeFromPosFiles&&e.push("exclude_from_pos_files"),this._excludeFromBom&&e.push("exclude_from_bom"),`(${e.join(" ")})`}},o(Js,"token","attr"),o(Js,"parentToken","footprint"),Js);f.register(t0);var Ko,xd=(Ko=class extends oe{constructor(){super(...arguments);o(this,"token","autoplace_cost180")}},o(Ko,"token","autoplace_cost180"),o(Ko,"parentToken","footprint"),Ko);f.register(xd);var Jo,yd=(Jo=class extends oe{constructor(){super(...arguments);o(this,"token","autoplace_cost90")}},o(Jo,"token","autoplace_cost90"),o(Jo,"parentToken","footprint"),Jo);f.register(yd);var Zo,vd=(Zo=class extends oe{constructor(){super(...arguments);o(this,"token","clearance")}},o(Zo,"token","clearance"),o(Zo,"parentToken","footprint"),Zo);f.register(vd);var Zs,wd=(Zs=class extends f{constructor(e){super();o(this,"token","descr");o(this,"_value");this._value=e}static fromSexprPrimitives(e){const s=F(e[0]);if(s===void 0)throw new Error("descr expects a string value");return new Zs(s)}get value(){return this._value}set value(e){this._value=e}getChildren(){return[]}getString(){return`(descr ${D(this._value)})`}},o(Zs,"token","descr"),o(Zs,"parentToken","footprint"),Zs);f.register(wd);var Qs,bd=(Qs=class extends f{constructor(e){super();o(this,"token","net_tie_pad_groups");o(this,"_groups",[]);this.groups=e}static fromSexprPrimitives(e){const s=e.map(r=>{const i=F(r);if(i===void 0)throw new Error(`net_tie_pad_groups expects string group entries, received ${JSON.stringify(r)}`);return i});return new Qs(s)}get groups(){return[...this._groups]}set groups(e){this._groups=e.map(s=>String(s))}getChildren(){return[]}getString(){return`(net_tie_pad_groups ${this._groups.map(s=>D(s)).join(" ")})`}},o(Qs,"token","net_tie_pad_groups"),o(Qs,"parentToken","footprint"),Qs);f.register(bd);var en,kd=(en=class extends f{constructor(e){super();o(this,"token","path");o(this,"_value");this._value=e}static fromSexprPrimitives(e){const s=F(e[0]);if(s===void 0)throw new Error("path expects a string value");return new en(s)}get value(){return this._value}set value(e){this._value=e}getChildren(){return[]}getString(){return`(path ${D(this._value)})`}},o(en,"token","path"),o(en,"parentToken","footprint"),en);f.register(kd);var tn,Sd=(tn=class extends f{constructor(e){super();o(this,"token","private_layers");o(this,"_layers",[]);this.layers=e}static fromSexprPrimitives(e){const s=e.map(r=>{const i=F(r);if(i===void 0)throw new Error(`private_layers expects string layer names, received ${JSON.stringify(r)}`);return i});return new tn(s)}get layers(){return[...this._layers]}set layers(e){this._layers=e.map(s=>String(s))}getChildren(){return[]}getString(){return`(private_layers ${this._layers.map(s=>/^[^\s()"]+$/u.test(s)&&!["nil","#t","#f"].includes(s)?s:D(s)).join(" ")})`}},o(tn,"token","private_layers"),o(tn,"parentToken","footprint"),tn);f.register(Sd);var Qo,Pd=(Qo=class extends oe{constructor(){super(...arguments);o(this,"token","solder_mask_margin")}},o(Qo,"token","solder_mask_margin"),o(Qo,"parentToken","footprint"),Qo);f.register(Pd);var ea,Td=(ea=class extends oe{constructor(){super(...arguments);o(this,"token","solder_paste_margin")}},o(ea,"token","solder_paste_margin"),o(ea,"parentToken","footprint"),ea);f.register(Td);var ta,Ed=(ta=class extends oe{constructor(){super(...arguments);o(this,"token","solder_paste_ratio")}},o(ta,"token","solder_paste_ratio"),o(ta,"parentToken","footprint"),ta);f.register(Ed);var sn,Cd=(sn=class extends f{constructor(e){super();o(this,"token","tags");o(this,"_value");this._value=e}static fromSexprPrimitives(e){const s=F(e[0]);if(s===void 0)throw new Error("tags expects a string value");return new sn(s)}get value(){return this._value}set value(e){this._value=e}getChildren(){return[]}getString(){return`(tags ${D(this._value)})`}},o(sn,"token","tags"),o(sn,"parentToken","footprint"),sn);f.register(Cd);var nn,Nd=(nn=class extends Rt{constructor(){super(...arguments);o(this,"token","tedit")}static fromSexprPrimitives(e){const s=F(e[0]);if(s===void 0)throw new Error("tedit expects a string value");return new nn(s)}},o(nn,"token","tedit"),o(nn,"parentToken","footprint"),nn);f.register(Nd);var sa,$d=(sa=class extends oe{constructor(){super(...arguments);o(this,"token","thermal_gap")}},o(sa,"token","thermal_gap"),o(sa,"parentToken","footprint"),sa);f.register($d);var na,Ad=(na=class extends oe{constructor(){super(...arguments);o(this,"token","thermal_width")}},o(na,"token","thermal_width"),o(na,"parentToken","footprint"),na);f.register(Ad);var ra,Id=(ra=class extends oe{constructor(){super(...arguments);o(this,"token","zone_connect")}},o(ra,"token","zone_connect"),o(ra,"parentToken","footprint"),ra);f.register(Id);var rn,s0=(rn=class extends f{constructor(e){super();o(this,"token","chamfer");o(this,"_corners",[]);this.corners=e}static fromSexprPrimitives(e){const s=e.map(r=>{const i=F(r);return i===void 0?Ie(r):i});return new rn(s)}get corners(){return[...this._corners]}set corners(e){this._corners=e.map(s=>String(s))}getChildren(){return[]}getString(){return this._corners.length===0?"(chamfer)":`(chamfer ${this._corners.join(" ")})`}},o(rn,"token","chamfer"),o(rn,"parentToken","pad"),rn);f.register(s0);var ia,E_=(ia=class extends oe{constructor(){super(...arguments);o(this,"token","chamfer_ratio")}},o(ia,"token","chamfer_ratio"),o(ia,"parentToken","pad"),ia);f.register(E_);var oa,C_=(oa=class extends oe{constructor(){super(...arguments);o(this,"token","clearance")}},o(oa,"token","clearance"),o(oa,"parentToken","pad"),oa);f.register(C_);var aa,N_=(aa=class extends oe{constructor(){super(...arguments);o(this,"token","die_length")}},o(aa,"token","die_length"),o(aa,"parentToken","pad"),aa);f.register(N_);var on,ii=(on=class extends f{constructor(e,s){super();o(this,"token","offset");o(this,"_x");o(this,"_y");this._x=e,this._y=s}static fromSexprPrimitives(e){const s=O(e[0]),r=O(e[1]);if(s===void 0||r===void 0)throw new Error("drill offset requires x and y numeric values");return new on(s,r)}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`(offset ${this._x} ${this._y})`}},o(on,"token","offset"),o(on,"parentToken","drill"),on);f.register(ii);var an,Ct=(an=class extends f{constructor({oval:e=!1,diameter:s,width:r,offset:i}){super();o(this,"token","drill");o(this,"_oval",!1);o(this,"_diameter");o(this,"_width");o(this,"_sxOffset");this._oval=e,this._diameter=s,this._width=r,i instanceof ii?this._sxOffset=i:i&&(this._sxOffset=new ii(i.x,i.y))}static fromSexprPrimitives(e){const s=[...e];let r=!1;s[0]==="oval"&&(r=!0,s.shift());const i=O(s.shift());if(i===void 0)throw new Error("drill requires a diameter value");let a;const l=O(s[0]);l!==void 0&&(a=l,s.shift());const c=new an({oval:r,diameter:i,width:a});for(const h of s){if(!Array.isArray(h))throw new Error(`drill encountered unexpected primitive child: ${JSON.stringify(h)}`);const d=f.parsePrimitiveSexpr(h,{parentToken:this.token});if(!(d instanceof ii))throw new Error(`drill encountered unsupported child token: ${Ie(h)}`);if(c._sxOffset)throw new Error("drill does not support multiple offset children");c._sxOffset=d}return c}get oval(){return this._oval}set oval(e){this._oval=e}get diameter(){return this._diameter}set diameter(e){this._diameter=e}get width(){return this._width}set width(e){this._width=e}get offset(){return this._sxOffset}set offset(e){if(e===void 0){this._sxOffset=void 0;return}this._sxOffset=e instanceof ii?e:new ii(e.x,e.y)}getChildren(){return this._sxOffset?[this._sxOffset]:[]}getString(){const e=[];if(this._oval&&e.push("oval"),e.push(String(this._diameter)),this._width!==void 0&&e.push(String(this._width)),!this._sxOffset)return`(drill ${e.join(" ")})`;const s=[`(drill ${e.join(" ")}`];return s.push(this._sxOffset.getStringIndented()),s.push(")"),s.join(`
|
|
137
|
+
`)}},o(an,"token","drill"),o(an,"parentToken","pad"),an);f.register(Ct);var $t,$_=($t=class extends f{constructor(e){super();o(this,"token","layers");o(this,"_layers",[]);this.layers=e}static from(e){return e instanceof $t?e:new $t(e)}static fromSexprPrimitives(e){const s=e.map(r=>{const i=F(r);return i===void 0?Ie(r):i});return new $t(s)}get layers(){return[...this._layers]}set layers(e){this._layers=e.map(s=>String(s))}getChildren(){return[]}getString(){return this._layers.length===0?"(layers)":`(layers ${this._layers.map(s=>/^[^\s()"]+$/u.test(s)&&!["nil","#t","#f"].includes(s)?s:D(s)).join(" ")})`}},o($t,"token","layers"),o($t,"parentToken","pad"),$t);f.register($_);var cn,n0=(cn=class extends f{constructor(e,s){super();o(this,"token","net");o(this,"_id");o(this,"_name");this._id=e,this._name=s}static fromSexprPrimitives(e){const s=O(e[0]),r=F(e[1]);if(s===void 0||r===void 0)throw new Error("pad net requires numeric id and string name");return new cn(s,r)}get id(){return this._id}set id(e){this._id=e}get name(){return this._name}set name(e){this._name=e}getChildren(){return[]}getString(){return`(net ${this._id} ${D(this._name)})`}},o(cn,"token","net"),o(cn,"parentToken","pad"),cn);f.register(n0);var Cf=["outline","convexhull"],Nf=["rect","circle"],ln,r0=(ln=class extends f{constructor(){super(...arguments);o(this,"token","options");o(this,"_sxClearance");o(this,"_sxAnchor")}static fromSexprPrimitives(e){const s=new ln;for(const r of e){if(!Array.isArray(r)||r.length===0)throw new Error(`pad options encountered invalid child expression: ${JSON.stringify(r)}`);const i=f.parsePrimitiveSexpr(r,{parentToken:this.token});if(!(i instanceof f))throw new Error(`pad options child did not resolve to an SxClass: ${JSON.stringify(r)}`);if(i instanceof Ld){if(s._sxClearance)throw new Error("pad options encountered duplicate clearance tokens");s._sxClearance=i;continue}if(i instanceof Md){if(s._sxAnchor)throw new Error("pad options encountered duplicate anchor tokens");s._sxAnchor=i;continue}throw new Error(`pad options encountered unsupported token "${i.token}"`)}return s}get clearance(){var e;return(e=this._sxClearance)==null?void 0:e.type}set clearance(e){this._sxClearance=e?new Ld(e):void 0}get anchor(){var e;return(e=this._sxAnchor)==null?void 0:e.shape}set anchor(e){this._sxAnchor=e?new Md(e):void 0}getChildren(){const e=[];return this._sxClearance&&e.push(this._sxClearance),this._sxAnchor&&e.push(this._sxAnchor),e}},o(ln,"token","options"),o(ln,"parentToken","pad"),ln);f.register(r0);var hn,Ld=(hn=class extends f{constructor(e){super();o(this,"token","clearance");o(this,"_type");this._type=e}static fromSexprPrimitives(e){const[s]=e,r=F(s);if(r===void 0)throw new Error("pad options clearance requires a string value");if(!Cf.includes(r))throw new Error(`pad options clearance must be one of ${Cf.join(", ")}`);return new hn(r)}get type(){return this._type}set type(e){this._type=e}getChildren(){return[]}getString(){return`(clearance ${this._type})`}},o(hn,"token","clearance"),o(hn,"parentToken","options"),hn);f.register(Ld);var dn,Md=(dn=class extends f{constructor(e){super();o(this,"token","anchor");o(this,"_shape");this._shape=e}static fromSexprPrimitives(e){const[s]=e,r=F(s);if(r===void 0)throw new Error("pad options anchor requires a string value");if(!Nf.includes(r))throw new Error(`pad options anchor must be one of ${Nf.join(", ")}`);return new dn(r)}get shape(){return this._shape}set shape(e){this._shape=e}getChildren(){return[]}getString(){return`(anchor ${this._shape})`}},o(dn,"token","anchor"),o(dn,"parentToken","options"),dn);f.register(Md);var ca,A_=(ca=class extends Rt{constructor(){super(...arguments);o(this,"token","pinfunction")}},o(ca,"token","pinfunction"),o(ca,"parentToken","pad"),ca);f.register(A_);var la,I_=(la=class extends Rt{constructor(){super(...arguments);o(this,"token","pintype")}},o(la,"token","pintype"),o(la,"parentToken","pad"),la);f.register(I_);var un,Fi=(un=class extends f{constructor(e,s){super();o(this,"token","end");o(this,"_x");o(this,"_y");this._x=e,this._y=s}static fromSexprPrimitives(e){const[s,r]=e,i=O(s),a=O(r);if(i===void 0||a===void 0)throw new Error("gr_line end expects two numeric arguments");return new un(i,a)}get x(){return this._x}set x(e){this._x=e}get y(){return this._y}set y(e){this._y=e}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(end ${this._x} ${this._y})`}},o(un,"token","end"),o(un,"parentToken","gr_line"),un);f.register(Fi);var pn,zi=(pn=class extends f{constructor(e,s){super();o(this,"token","start");o(this,"_x");o(this,"_y");this._x=e,this._y=s}static fromSexprPrimitives(e){const[s,r]=e,i=O(s),a=O(r);if(i===void 0||a===void 0)throw new Error("gr_line start expects two numeric arguments");return new pn(i,a)}get x(){return this._x}set x(e){this._x=e}get y(){return this._y}set y(e){this._y=e}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(start ${this._x} ${this._y})`}},o(pn,"token","start"),o(pn,"parentToken","gr_line"),pn);f.register(zi);var $f=new Set(["start","end","width"]),fn,L_=(fn=class extends f{constructor(){super(...arguments);o(this,"token","gr_line");o(this,"_sxStart");o(this,"_sxEnd");o(this,"_sxWidth")}static fromSexprPrimitives(e){const s=new fn,{propertyMap:r,arrayPropertyMap:i}=f.parsePrimitivesToClassProperties(e,this.token);for(const a of Object.keys(r))if(!$f.has(a))throw new Error(`pad primitive gr_line encountered unsupported child token "${a}"`);for(const[a,l]of Object.entries(i)){if(!$f.has(a))throw new Error(`pad primitive gr_line encountered unsupported child token "${a}"`);if(l.length>1)throw new Error(`pad primitive gr_line does not support repeated "${a}" tokens`)}if(s._sxStart=r.start,s._sxEnd=r.end,s._sxWidth=r.width,!s._sxStart)throw new Error("pad primitive gr_line requires a start child token");if(!s._sxEnd)throw new Error("pad primitive gr_line requires an end child token");return s}get start(){return this._sxStart}set start(e){if(e===void 0){this._sxStart=void 0;return}if(e instanceof zi){this._sxStart=e;return}this._sxStart=new zi(e.x,e.y)}get end(){return this._sxEnd}set end(e){if(e===void 0){this._sxEnd=void 0;return}if(e instanceof Fi){this._sxEnd=e;return}this._sxEnd=new Fi(e.x,e.y)}get width(){var e;return(e=this._sxWidth)==null?void 0:e.value}set width(e){if(e===void 0){this._sxWidth=void 0;return}this._sxWidth=e instanceof de?e:new de(e)}get widthClass(){return this._sxWidth}getChildren(){const e=[];return this._sxStart&&e.push(this._sxStart),this._sxEnd&&e.push(this._sxEnd),this._sxWidth&&e.push(this._sxWidth),e}getString(){const e=["(gr_line"];return this._sxStart&&e.push(this._sxStart.getStringIndented()),this._sxEnd&&e.push(this._sxEnd.getStringIndented()),this._sxWidth&&e.push(this._sxWidth.getStringIndented()),e.push(")"),e.join(`
|
|
138
|
+
`)}},o(fn,"token","gr_line"),o(fn,"parentToken","primitives"),fn);f.register(L_);var Af=new Set(["start","mid","end","width"]),gn,M_=(gn=class extends f{constructor(e={}){super();o(this,"token","gr_arc");o(this,"_sxStart");o(this,"_sxMid");o(this,"_sxEnd");o(this,"_sxWidth");e.start!==void 0&&(this.start=e.start),e.mid!==void 0&&(this.mid=e.mid),e.end!==void 0&&(this.end=e.end),e.width!==void 0&&(this.width=e.width)}static fromSexprPrimitives(e){const s=new gn,{propertyMap:r,arrayPropertyMap:i}=f.parsePrimitivesToClassProperties(e,this.token);for(const a of Object.keys(r))if(!Af.has(a))throw new Error(`pad primitive gr_arc encountered unsupported child token "${a}"`);for(const[a,l]of Object.entries(i)){if(!Af.has(a))throw new Error(`pad primitive gr_arc encountered unsupported child token "${a}"`);if(l.length>1)throw new Error(`pad primitive gr_arc does not support repeated "${a}" tokens`)}if(s._sxStart=r.start,s._sxMid=r.mid,s._sxEnd=r.end,s._sxWidth=r.width,!s._sxStart)throw new Error("pad primitive gr_arc requires a start child token");if(!s._sxMid)throw new Error("pad primitive gr_arc requires a mid child token");if(!s._sxEnd)throw new Error("pad primitive gr_arc requires an end child token");return s}get start(){return this._sxStart}set start(e){this._sxStart=$c(e,R_)}get mid(){return this._sxMid}set mid(e){this._sxMid=$c(e,O_)}get end(){return this._sxEnd}set end(e){this._sxEnd=$c(e,F_)}get width(){var e;return(e=this._sxWidth)==null?void 0:e.value}set width(e){if(e===void 0){this._sxWidth=void 0;return}this._sxWidth=e instanceof de?e:new de(e)}get widthClass(){return this._sxWidth}getChildren(){const e=[];return this._sxStart&&e.push(this._sxStart),this._sxMid&&e.push(this._sxMid),this._sxEnd&&e.push(this._sxEnd),this._sxWidth&&e.push(this._sxWidth),e}getString(){const e=["(gr_arc"];return this._sxStart&&e.push(this._sxStart.getStringIndented()),this._sxMid&&e.push(this._sxMid.getStringIndented()),this._sxEnd&&e.push(this._sxEnd.getStringIndented()),this._sxWidth&&e.push(this._sxWidth.getStringIndented()),e.push(")"),e.join(`
|
|
139
|
+
`)}},o(gn,"token","gr_arc"),o(gn,"parentToken","primitives"),gn);f.register(M_);var $c=(n,t)=>{if(n!==void 0)return n instanceof t?n:new t(n.x,n.y)},Tp=class extends f{constructor(t,e){super();o(this,"_x");o(this,"_y");this._x=t,this._y=e}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})`}},_n,R_=(_n=class extends Tp{constructor(e,s){super(e,s);o(this,"token","start")}static fromSexprPrimitives(e){const[s,r]=e,i=O(s),a=O(r);if(i===void 0||a===void 0)throw new Error("pad primitive gr_arc start expects two numeric arguments");return new _n(i,a)}},o(_n,"token","start"),o(_n,"parentToken","gr_arc"),_n);f.register(R_);var mn,O_=(mn=class extends Tp{constructor(e,s){super(e,s);o(this,"token","mid")}static fromSexprPrimitives(e){const[s,r]=e,i=O(s),a=O(r);if(i===void 0||a===void 0)throw new Error("pad primitive gr_arc mid expects two numeric arguments");return new mn(i,a)}},o(mn,"token","mid"),o(mn,"parentToken","gr_arc"),mn);f.register(O_);var xn,F_=(xn=class extends Tp{constructor(e,s){super(e,s);o(this,"token","end")}static fromSexprPrimitives(e){const[s,r]=e,i=O(s),a=O(r);if(i===void 0||a===void 0)throw new Error("pad primitive gr_arc end expects two numeric arguments");return new xn(i,a)}},o(xn,"token","end"),o(xn,"parentToken","gr_arc"),xn);f.register(F_);var If=new Set(["center","end","width","fill"]),yn,z_=(yn=class extends f{constructor(e={}){super();o(this,"token","gr_circle");o(this,"_sxCenter");o(this,"_sxEnd");o(this,"_sxWidth");o(this,"_sxFill");e.center!==void 0&&(this.center=e.center),e.end!==void 0&&(this.end=e.end),e.width!==void 0&&(this.width=e.width),e.fill!==void 0&&(this.fill=e.fill)}static fromSexprPrimitives(e){const s=new yn,{propertyMap:r,arrayPropertyMap:i}=f.parsePrimitivesToClassProperties(e,this.token);for(const a of Object.keys(r))if(!If.has(a))throw new Error(`pad primitive gr_circle encountered unsupported child token "${a}"`);for(const[a,l]of Object.entries(i)){if(!If.has(a))throw new Error(`pad primitive gr_circle encountered unsupported child token "${a}"`);if(l.length>1)throw new Error(`pad primitive gr_circle does not support repeated "${a}" tokens`)}if(s._sxCenter=r.center,s._sxEnd=r.end,s._sxWidth=r.width,s._sxFill=r.fill,!s._sxCenter)throw new Error("pad primitive gr_circle requires a center child token");if(!s._sxEnd)throw new Error("pad primitive gr_circle requires an end child token");return s}get center(){return this._sxCenter}set center(e){this._sxCenter=Lf(e,j_)}get end(){return this._sxEnd}set end(e){this._sxEnd=Lf(e,B_)}get width(){var e;return(e=this._sxWidth)==null?void 0:e.value}set width(e){if(e===void 0){this._sxWidth=void 0;return}this._sxWidth=e instanceof de?e:new de(e)}get widthClass(){return this._sxWidth}get fill(){var e;return(e=this._sxFill)==null?void 0:e.value}set fill(e){if(e===void 0){this._sxFill=void 0;return}this._sxFill=e instanceof Rd?e:new Rd(e)}get fillClass(){return this._sxFill}getChildren(){const e=[];return this._sxCenter&&e.push(this._sxCenter),this._sxEnd&&e.push(this._sxEnd),this._sxWidth&&e.push(this._sxWidth),this._sxFill&&e.push(this._sxFill),e}getString(){const e=["(gr_circle"];return this._sxCenter&&e.push(this._sxCenter.getStringIndented()),this._sxEnd&&e.push(this._sxEnd.getStringIndented()),this._sxWidth&&e.push(this._sxWidth.getStringIndented()),this._sxFill&&e.push(this._sxFill.getStringIndented()),e.push(")"),e.join(`
|
|
140
|
+
`)}},o(yn,"token","gr_circle"),o(yn,"parentToken","primitives"),yn);f.register(z_);var Lf=(n,t)=>{if(n!==void 0)return n instanceof t?n:new t(n.x,n.y)},U_=class extends f{constructor(t,e){super();o(this,"_x");o(this,"_y");this._x=t,this._y=e}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})`}},vn,j_=(vn=class extends U_{constructor(e,s){super(e,s);o(this,"token","center")}static fromSexprPrimitives(e){const[s,r]=e,i=O(s),a=O(r);if(i===void 0||a===void 0)throw new Error("pad primitive gr_circle center expects two numeric arguments");return new vn(i,a)}},o(vn,"token","center"),o(vn,"parentToken","gr_circle"),vn);f.register(j_);var wn,B_=(wn=class extends U_{constructor(e,s){super(e,s);o(this,"token","end")}static fromSexprPrimitives(e){const[s,r]=e,i=O(s),a=O(r);if(i===void 0||a===void 0)throw new Error("pad primitive gr_circle end expects two numeric arguments");return new wn(i,a)}},o(wn,"token","end"),o(wn,"parentToken","gr_circle"),wn);f.register(B_);var gt,Rd=(gt=class extends fe{constructor(e){super(e??!1);o(this,"token","fill")}static fromSexprPrimitives(e){const[s]=e;if(s===void 0)return new gt(!1);if(typeof s=="boolean")return new gt(s);if(typeof s=="string"){const r=s.toLowerCase();if(r==="yes"||r==="true")return new gt(!0);if(r==="no"||r==="false")return new gt(!1)}throw new Error(`pad primitive gr_circle fill expects yes/no or boolean, received ${JSON.stringify(s)}`)}},o(gt,"token","fill"),o(gt,"parentToken","gr_circle"),gt);f.register(Rd);var bn,i0=(bn=class extends f{constructor(){super(...arguments);o(this,"token","primitives");o(this,"_graphics",[]);o(this,"_sxWidth");o(this,"_sxFill")}static fromSexprPrimitives(e){const s=new bn;for(const r of e){if(!Array.isArray(r)||r.length===0)throw new Error(`pad primitives encountered invalid child expression: ${JSON.stringify(r)}`);const i=f.parsePrimitiveSexpr(r,{parentToken:this.token});if(!(i instanceof f))throw new Error(`pad primitives child did not resolve to an SxClass: ${JSON.stringify(r)}`);if(i instanceof de){if(s._sxWidth)throw new Error("pad primitives encountered duplicate width tokens");s._sxWidth=i;continue}if(i instanceof Od){if(s._sxFill)throw new Error("pad primitives encountered duplicate fill tokens");s._sxFill=i;continue}if(i instanceof D_){s._graphics.push(i);continue}if(i instanceof L_){s._graphics.push(i);continue}if(i instanceof M_){s._graphics.push(i);continue}if(i instanceof z_){s._graphics.push(i);continue}throw new Error(`pad primitives encountered unsupported token "${i.token}"`)}return s}get graphics(){return[...this._graphics]}set graphics(e){this._graphics=[...e]}addGraphic(e){this._graphics.push(e)}get width(){var e;return(e=this._sxWidth)==null?void 0:e.value}set width(e){this._sxWidth=e===void 0?void 0:new de(e)}get fill(){var e;return(e=this._sxFill)==null?void 0:e.value}set fill(e){this._sxFill=e===void 0?void 0:new Od({value:e})}getChildren(){const e=[];return e.push(...this._graphics),this._sxWidth&&e.push(this._sxWidth),this._sxFill&&e.push(this._sxFill),e}},o(bn,"token","primitives"),o(bn,"parentToken","pad"),bn);f.register(i0);var _t,Od=(_t=class extends fe{constructor(e={}){super(e.value??!1);o(this,"token","fill")}static fromSexprPrimitives(e){const[s]=e,r=typeof s=="string"?s.toLowerCase():s;if(r===void 0)return new _t({value:!1});if(r==="yes")return new _t({value:!0});if(r==="no")return new _t({value:!1});if(typeof r=="boolean")return new _t({value:r});throw new Error(`pad primitives fill expects yes/no or boolean, received ${JSON.stringify(s)}`)}},o(_t,"token","fill"),o(_t,"parentToken","primitives"),_t);f.register(Od);var kn,D_=(kn=class extends f{constructor(){super(...arguments);o(this,"token","gr_poly");o(this,"_contours",[]);o(this,"_sxWidth");o(this,"_sxFill")}static fromSexprPrimitives(e){const s=new kn;for(const r of e){if(!Array.isArray(r)||r.length===0)throw new Error(`gr_poly primitive encountered invalid child: ${JSON.stringify(r)}`);const i=f.parsePrimitiveSexpr(r,{parentToken:this.token});if(!(i instanceof f))throw new Error(`gr_poly primitive child did not resolve to an SxClass: ${JSON.stringify(r)}`);if(i instanceof Gt){s._contours.push(i);continue}if(i instanceof de){if(s._sxWidth)throw new Error("gr_poly encountered duplicate width tokens");s._sxWidth=i;continue}if(i instanceof Fd){if(s._sxFill)throw new Error("gr_poly encountered duplicate fill tokens");s._sxFill=i;continue}throw new Error(`gr_poly encountered unsupported token "${i.token}"`)}if(s._contours.length===0)throw new Error("gr_poly requires at least one pts child");return s}get contours(){return[...this._contours]}set contours(e){this._contours=[...e]}get width(){var e;return(e=this._sxWidth)==null?void 0:e.value}set width(e){this._sxWidth=e===void 0?void 0:new de(e)}get filled(){var e;return(e=this._sxFill)==null?void 0:e.value}set filled(e){this._sxFill=e===void 0?void 0:new Fd({value:e})}getChildren(){const e=[];return e.push(...this._contours),this._sxWidth&&e.push(this._sxWidth),this._sxFill&&e.push(this._sxFill),e}},o(kn,"token","gr_poly"),o(kn,"parentToken","primitives"),kn);f.register(D_);var At,Fd=(At=class extends fe{constructor(e={}){super(e.value??!1);o(this,"token","fill")}static fromSexprPrimitives(e){const[s]=e;if(s===void 0)return new At({value:!1});if(typeof s=="boolean")return new At({value:s});if(typeof s=="string")return new At({value:s.toLowerCase()==="yes"});throw new Error(`gr_poly fill expects yes/no or boolean, received ${JSON.stringify(s)}`)}getString(){return`(fill ${this.value?"yes":"no"})`}},o(At,"token","fill"),o(At,"parentToken","gr_poly"),At);f.register(Fd);var ha,W_=(ha=class extends oe{constructor(){super(...arguments);o(this,"token","roundrect_rratio")}},o(ha,"token","roundrect_rratio"),o(ha,"parentToken","pad"),ha);f.register(W_);var mt,G_=(mt=class extends f{constructor(e,s){super();o(this,"token","size");o(this,"_width");o(this,"_height");this._width=e,this._height=s}static from(e){return e instanceof mt?e:Array.isArray(e)?new mt(e[0],e[1]):new mt(e.width,e.height)}static fromSexprPrimitives(e){const s=O(e[0]),r=O(e[1]);if(s===void 0||r===void 0)throw new Error("size requires width and height numeric values");return new mt(s,r)}get width(){return this._width}set width(e){this._width=e}get height(){return this._height}set height(e){this._height=e}getChildren(){return[]}getString(){return`(size ${this._width} ${this._height})`}},o(mt,"token","size"),o(mt,"parentToken","pad"),mt);f.register(G_);var da,V_=(da=class extends oe{constructor(){super(...arguments);o(this,"token","solder_mask_margin")}},o(da,"token","solder_mask_margin"),o(da,"parentToken","pad"),da);f.register(V_);var ua,H_=(ua=class extends oe{constructor(){super(...arguments);o(this,"token","solder_paste_margin")}},o(ua,"token","solder_paste_margin"),o(ua,"parentToken","pad"),ua);f.register(H_);var pa,Y_=(pa=class extends oe{constructor(){super(...arguments);o(this,"token","solder_paste_margin_ratio")}},o(pa,"token","solder_paste_margin_ratio"),o(pa,"parentToken","pad"),pa);f.register(Y_);var fa,X_=(fa=class extends oe{constructor(){super(...arguments);o(this,"token","thermal_gap")}},o(fa,"token","thermal_gap"),o(fa,"parentToken","pad"),fa);f.register(X_);var ga,q_=(ga=class extends oe{constructor(){super(...arguments);o(this,"token","thermal_width")}},o(ga,"token","thermal_width"),o(ga,"parentToken","pad"),ga);f.register(q_);var _a,K_=(_a=class extends oe{constructor(){super(...arguments);o(this,"token","thermal_bridge_angle")}},o(_a,"token","thermal_bridge_angle"),o(_a,"parentToken","pad"),_a);f.register(K_);var ma,J_=(ma=class extends oe{constructor(){super(...arguments);o(this,"token","zone_connect")}},o(ma,"token","zone_connect"),o(ma,"parentToken","pad"),ma);f.register(J_);var Ep=n=>{const t=F(n);if(t){if(t==="yes"||t==="true")return!0;if(t==="no"||t==="false")return!1}},Mf=new Map([["best_length_ratio","bestLengthRatio"],["max_length","maxLength"],["best_width_ratio","bestWidthRatio"],["max_width","maxWidth"],["filter_ratio","filterRatio"]]),Rf=new Map([["curved_edges","curvedEdges"],["enabled","enabled"],["allow_two_segments","allowTwoSegments"],["prefer_zone_connections","preferZoneConnections"]]),Sn,Z_=(Sn=class extends f{constructor(){super(...arguments);o(this,"token","teardrops");o(this,"_bestLengthRatio");o(this,"_maxLength");o(this,"_bestWidthRatio");o(this,"_maxWidth");o(this,"_filterRatio");o(this,"_curvedEdges");o(this,"_enabled");o(this,"_allowTwoSegments");o(this,"_preferZoneConnections")}static fromSexprPrimitives(e){const s=new Sn;for(const r of e){if(!Array.isArray(r)||r.length===0)throw new Error(`teardrops encountered invalid child expression: ${JSON.stringify(r)}`);const[i,a]=r;if(typeof i!="string")throw new Error(`teardrops encountered non-string token: ${JSON.stringify(i)}`);if(Mf.has(i)){const l=Mf.get(i),c=O(a);if(c===void 0)throw new Error(`teardrops ${i} expects a numeric value, received ${JSON.stringify(a)}`);s[l]=c;continue}if(Rf.has(i)){const l=Rf.get(i),c=Ep(a);if(c===void 0)throw new Error(`teardrops ${i} expects yes/no, received ${JSON.stringify(a)}`);s[l]=c;continue}throw new Error(`teardrops encountered unsupported token "${i}"`)}return s}get bestLengthRatio(){return this._bestLengthRatio}set bestLengthRatio(e){this._bestLengthRatio=e}get maxLength(){return this._maxLength}set maxLength(e){this._maxLength=e}get bestWidthRatio(){return this._bestWidthRatio}set bestWidthRatio(e){this._bestWidthRatio=e}get maxWidth(){return this._maxWidth}set maxWidth(e){this._maxWidth=e}get filterRatio(){return this._filterRatio}set filterRatio(e){this._filterRatio=e}get curvedEdges(){return this._curvedEdges}set curvedEdges(e){this._curvedEdges=e}get enabled(){return this._enabled}set enabled(e){this._enabled=e}get allowTwoSegments(){return this._allowTwoSegments}set allowTwoSegments(e){this._allowTwoSegments=e}get preferZoneConnections(){return this._preferZoneConnections}set preferZoneConnections(e){this._preferZoneConnections=e}getChildren(){return[]}getString(){const e=["(teardrops"];return this._bestLengthRatio!==void 0&&e.push(` (best_length_ratio ${this._bestLengthRatio})`),this._maxLength!==void 0&&e.push(` (max_length ${this._maxLength})`),this._bestWidthRatio!==void 0&&e.push(` (best_width_ratio ${this._bestWidthRatio})`),this._maxWidth!==void 0&&e.push(` (max_width ${this._maxWidth})`),this._curvedEdges!==void 0&&e.push(` (curved_edges ${this._curvedEdges?"yes":"no"})`),this._filterRatio!==void 0&&e.push(` (filter_ratio ${this._filterRatio})`),this._enabled!==void 0&&e.push(` (enabled ${this._enabled?"yes":"no"})`),this._allowTwoSegments!==void 0&&e.push(` (allow_two_segments ${this._allowTwoSegments?"yes":"no"})`),this._preferZoneConnections!==void 0&&e.push(` (prefer_zone_connections ${this._preferZoneConnections?"yes":"no"})`),e.push(")"),e.join(`
|
|
141
|
+
`)}},o(Sn,"token","teardrops"),o(Sn,"parentToken","pad"),Sn);f.register(Z_);var Pn,zd=(Pn=class extends f{constructor(e=0,s=0){super();o(this,"token","rect_delta");o(this,"_x");o(this,"_y");this._x=e,this._y=s}static fromSexprPrimitives(e){const[s,r]=e,i=O(s),a=O(r);if(i===void 0||a===void 0)throw new Error("pad rect_delta expects two numeric arguments");return new Pn(i,a)}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`(rect_delta ${this._x} ${this._y})`}},o(Pn,"token","rect_delta"),o(Pn,"parentToken","pad"),Pn);f.register(zd);var o0=new Set(["at","size","drill","layers","width","stroke","rect_delta","roundrect_rratio","chamfer_ratio","chamfer","net","uuid","pinfunction","pintype","die_length","solder_mask_margin","solder_paste_margin","solder_paste_margin_ratio","clearance","zone_connect","thermal_width","thermal_gap","thermal_bridge_angle","options","primitives","remove_unused_layers","keep_end_layers","teardrops"]),Q_=new Set(["property"]),Of=new Set([...o0,...Q_]),pe=(n,t)=>{const e=n[t];if(e&&e.length>1)throw new Error(`pad does not support repeated "${t}" children`)},Ur,pc=(Ur=class extends f{constructor(e,s,r){super();o(this,"token","pad");o(this,"_number","");o(this,"_padType","");o(this,"_shape","");o(this,"_locked",!1);o(this,"_sxRemoveUnusedLayers");o(this,"_sxKeepEndLayers");o(this,"_sxAt");o(this,"_sxSize");o(this,"_sxDrill");o(this,"_sxLayers");o(this,"_sxWidth");o(this,"_sxStroke");o(this,"_properties",[]);o(this,"_sxRoundrectRatio");o(this,"_sxChamferRatio");o(this,"_sxChamfer");o(this,"_sxRectDelta");o(this,"_sxNet");o(this,"_sxUuid");o(this,"_sxPinFunction");o(this,"_sxPinType");o(this,"_sxDieLength");o(this,"_sxSolderMaskMargin");o(this,"_sxSolderPasteMargin");o(this,"_sxSolderPasteMarginRatio");o(this,"_sxClearance");o(this,"_sxZoneConnect");o(this,"_sxThermalWidth");o(this,"_sxThermalGap");o(this,"_sxThermalBridgeAngle");o(this,"_sxOptions");o(this,"_sxPrimitives");o(this,"_sxTeardrops");if(typeof e=="string"){this._number=e,this._padType=s||"",this._shape=r||"";return}const i=e||{};i.number!==void 0&&(this.number=i.number),i.padType!==void 0&&(this.padType=i.padType),i.shape!==void 0&&(this.shape=i.shape),i.locked!==void 0&&(this.locked=i.locked),i.removeUnusedLayers!==void 0&&(this.removeUnusedLayer=i.removeUnusedLayers),i.keepEndLayers!==void 0&&(this.keepEndLayers=i.keepEndLayers),i.at!==void 0&&(this.at=i.at),i.size!==void 0&&(this.size=i.size),i.drill!==void 0&&(this.drill=i.drill),i.layers!==void 0&&(this.layers=i.layers),i.width!==void 0&&(this.width=i.width),i.stroke!==void 0&&(this.stroke=i.stroke),i.properties!==void 0&&(this.properties=i.properties),i.roundrectRatio!==void 0&&(this.roundrectRatio=i.roundrectRatio),i.chamferRatio!==void 0&&(this.chamferRatio=i.chamferRatio),i.chamfer!==void 0&&(this.chamfer=i.chamfer),i.rectDelta!==void 0&&(this.rectDelta=i.rectDelta),i.net!==void 0&&(this.net=i.net),i.uuid!==void 0&&(this.uuid=i.uuid),i.pinFunction!==void 0&&(this.pinfunction=i.pinFunction),i.pinType!==void 0&&(this.pintype=i.pinType),i.dieLength!==void 0&&(this.dieLength=i.dieLength),i.solderMaskMargin!==void 0&&(this.solderMaskMargin=i.solderMaskMargin),i.solderPasteMargin!==void 0&&(this.solderPasteMargin=i.solderPasteMargin),i.solderPasteMarginRatio!==void 0&&(this.solderPasteMarginRatio=i.solderPasteMarginRatio),i.clearance!==void 0&&(this.clearance=i.clearance),i.zoneConnect!==void 0&&(this.zoneConnect=i.zoneConnect),i.thermalWidth!==void 0&&(this.thermalWidth=i.thermalWidth),i.thermalGap!==void 0&&(this.thermalGap=i.thermalGap),i.thermalBridgeAngle!==void 0&&(this.thermalBridgeAngle=i.thermalBridgeAngle),i.options!==void 0&&(this.options=i.options),i.primitives!==void 0&&(this.primitives=i.primitives),i.teardrops!==void 0&&(this.teardrops=i.teardrops)}static fromSexprPrimitives(e){var x,v,m;if(e.length<3)throw new Error("pad requires number, type, and shape arguments");const[s,r,i,...a]=e,l=F(s),c=F(r),h=F(i);if(l===void 0||c===void 0||h===void 0)throw new Error("pad header tokens must be strings");const d=new Ur(l,c,h),p=[],u=[];for(const y of a)if(typeof y=="string")p.push(y);else if(Array.isArray(y))u.push(y);else throw new Error(`pad encountered unexpected primitive child: ${JSON.stringify(y)}`);for(const y of p)switch(y){case"locked":d._locked=!0;break;case"remove_unused_layer":d._sxRemoveUnusedLayers=new Ud({value:!0,bareToken:"remove_unused_layer"});break;case"keep_end_layers":d._sxKeepEndLayers=new jd({value:!0,bare:!0});break;default:throw new Error(`pad encountered unsupported flag "${y}"`)}const{propertyMap:g,arrayPropertyMap:_}=f.parsePrimitivesToClassProperties(u,this.token);for(const y of Object.keys(g))if(!Of.has(y))throw new Error(`pad encountered unsupported child token "${y}"`);for(const[y,w]of Object.entries(_)){if(!Of.has(y))throw new Error(`pad encountered unsupported child token "${y}"`);if(!Q_.has(y)&&w.length>1)throw new Error(`pad does not support repeated child "${y}"`)}return pe(_,"at"),pe(_,"size"),pe(_,"drill"),pe(_,"layers"),pe(_,"width"),pe(_,"stroke"),pe(_,"rect_delta"),pe(_,"roundrect_rratio"),pe(_,"chamfer_ratio"),pe(_,"chamfer"),pe(_,"net"),pe(_,"uuid"),pe(_,"pinfunction"),pe(_,"pintype"),pe(_,"die_length"),pe(_,"solder_mask_margin"),pe(_,"solder_paste_margin"),pe(_,"solder_paste_margin_ratio"),pe(_,"clearance"),pe(_,"zone_connect"),pe(_,"thermal_width"),pe(_,"thermal_gap"),pe(_,"thermal_bridge_angle"),pe(_,"options"),pe(_,"primitives"),d._sxAt=g.at,d._sxSize=g.size,d._sxDrill=g.drill,d._sxLayers=g.layers,d._sxWidth=g.width,d._sxStroke=g.stroke,d._sxRectDelta=g.rect_delta,d._properties=_.property??[],d._sxRoundrectRatio=g.roundrect_rratio,d._sxChamferRatio=g.chamfer_ratio,d._sxChamfer=g.chamfer,d._sxNet=g.net,d._sxUuid=g.uuid,d._sxPinFunction=g.pinfunction,d._sxPinType=g.pintype,d._sxDieLength=g.die_length,d._sxSolderMaskMargin=g.solder_mask_margin,d._sxSolderPasteMargin=g.solder_paste_margin,d._sxSolderPasteMarginRatio=g.solder_paste_margin_ratio,d._sxClearance=g.clearance,d._sxZoneConnect=g.zone_connect,d._sxThermalWidth=g.thermal_width,d._sxThermalGap=g.thermal_gap,d._sxThermalBridgeAngle=g.thermal_bridge_angle,d._sxOptions=g.options,d._sxPrimitives=g.primitives,d._sxRemoveUnusedLayers=((x=_.remove_unused_layers)==null?void 0:x[0])??d._sxRemoveUnusedLayers,d._sxKeepEndLayers=((v=_.keep_end_layers)==null?void 0:v[0])??d._sxKeepEndLayers,d._sxTeardrops=((m=_.teardrops)==null?void 0:m[0])??void 0,d}get number(){return this._number}set number(e){this._number=e}get padType(){return this._padType}set padType(e){this._padType=e}get shape(){return this._shape}set shape(e){this._shape=e}get locked(){return this._locked}set locked(e){this._locked=e}get removeUnusedLayer(){var e;return((e=this._sxRemoveUnusedLayers)==null?void 0:e.value)??!1}set removeUnusedLayer(e){this._sxRemoveUnusedLayers=e?new Ud({value:e}):void 0}get keepEndLayers(){var e;return((e=this._sxKeepEndLayers)==null?void 0:e.value)??!1}set keepEndLayers(e){this._sxKeepEndLayers=e?new jd({value:e}):void 0}get at(){return this._sxAt}set at(e){this._sxAt=e!==void 0?he.from(e):void 0}get size(){return this._sxSize}set size(e){this._sxSize=e!==void 0?G_.from(e):void 0}get drill(){return this._sxDrill}set drill(e){this._sxDrill=e}get layers(){return this._sxLayers}set layers(e){this._sxLayers=e!==void 0?$_.from(e):void 0}get width(){return this._sxWidth}set width(e){if(e===void 0){this._sxWidth=void 0;return}this._sxWidth=typeof e=="number"?new de(e):e}get stroke(){return this._sxStroke}set stroke(e){this._sxStroke=e}get properties(){return[...this._properties]}set properties(e){this._properties=[...e]}get roundrectRatio(){var e;return(e=this._sxRoundrectRatio)==null?void 0:e.value}set roundrectRatio(e){if(e===void 0){this._sxRoundrectRatio=void 0;return}this._sxRoundrectRatio=typeof e=="number"?new W_(e):e}get chamferRatio(){var e;return(e=this._sxChamferRatio)==null?void 0:e.value}set chamferRatio(e){if(e===void 0){this._sxChamferRatio=void 0;return}this._sxChamferRatio=typeof e=="number"?new E_(e):e}get chamfer(){return this._sxChamfer}set chamfer(e){this._sxChamfer=e}get chamferCorners(){var e;return(e=this._sxChamfer)==null?void 0:e.corners}get rectDelta(){return this._sxRectDelta}set rectDelta(e){if(e===void 0){this._sxRectDelta=void 0;return}if(e instanceof zd){this._sxRectDelta=e;return}this._sxRectDelta=new zd(e.x,e.y)}get net(){return this._sxNet}set net(e){this._sxNet=e}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}get pinfunction(){var e;return(e=this._sxPinFunction)==null?void 0:e.value}set pinfunction(e){if(e===void 0){this._sxPinFunction=void 0;return}this._sxPinFunction=typeof e=="string"?new A_(e):e}get pintype(){var e;return(e=this._sxPinType)==null?void 0:e.value}set pintype(e){if(e===void 0){this._sxPinType=void 0;return}this._sxPinType=typeof e=="string"?new I_(e):e}get dieLength(){var e;return(e=this._sxDieLength)==null?void 0:e.value}set dieLength(e){if(e===void 0){this._sxDieLength=void 0;return}this._sxDieLength=typeof e=="number"?new N_(e):e}get solderMaskMargin(){var e;return(e=this._sxSolderMaskMargin)==null?void 0:e.value}set solderMaskMargin(e){if(e===void 0){this._sxSolderMaskMargin=void 0;return}this._sxSolderMaskMargin=typeof e=="number"?new V_(e):e}get solderPasteMargin(){var e;return(e=this._sxSolderPasteMargin)==null?void 0:e.value}set solderPasteMargin(e){if(e===void 0){this._sxSolderPasteMargin=void 0;return}this._sxSolderPasteMargin=typeof e=="number"?new H_(e):e}get solderPasteMarginRatio(){var e;return(e=this._sxSolderPasteMarginRatio)==null?void 0:e.value}set solderPasteMarginRatio(e){if(e===void 0){this._sxSolderPasteMarginRatio=void 0;return}this._sxSolderPasteMarginRatio=typeof e=="number"?new Y_(e):e}get clearance(){var e;return(e=this._sxClearance)==null?void 0:e.value}set clearance(e){if(e===void 0){this._sxClearance=void 0;return}this._sxClearance=typeof e=="number"?new C_(e):e}get zoneConnect(){var e;return(e=this._sxZoneConnect)==null?void 0:e.value}set zoneConnect(e){if(e===void 0){this._sxZoneConnect=void 0;return}this._sxZoneConnect=typeof e=="number"?new J_(e):e}get thermalWidth(){var e;return(e=this._sxThermalWidth)==null?void 0:e.value}set thermalWidth(e){if(e===void 0){this._sxThermalWidth=void 0;return}this._sxThermalWidth=typeof e=="number"?new q_(e):e}get thermalGap(){var e;return(e=this._sxThermalGap)==null?void 0:e.value}set thermalGap(e){if(e===void 0){this._sxThermalGap=void 0;return}this._sxThermalGap=typeof e=="number"?new X_(e):e}get thermalBridgeAngle(){var e;return(e=this._sxThermalBridgeAngle)==null?void 0:e.value}set thermalBridgeAngle(e){if(e===void 0){this._sxThermalBridgeAngle=void 0;return}this._sxThermalBridgeAngle=typeof e=="number"?new K_(e):e}get options(){return this._sxOptions}set options(e){this._sxOptions=e}get primitives(){return this._sxPrimitives}set primitives(e){this._sxPrimitives=e}get teardrops(){return this._sxTeardrops}set teardrops(e){this._sxTeardrops=e}getChildren(){const e=[];return this._sxAt&&e.push(this._sxAt),this._sxSize&&e.push(this._sxSize),this._sxDrill&&e.push(this._sxDrill),this._sxLayers&&e.push(this._sxLayers),this._sxWidth&&e.push(this._sxWidth),this._sxStroke&&e.push(this._sxStroke),e.push(...this._properties),this._sxRoundrectRatio&&e.push(this._sxRoundrectRatio),this._sxChamferRatio&&e.push(this._sxChamferRatio),this._sxChamfer&&e.push(this._sxChamfer),this._sxRectDelta&&e.push(this._sxRectDelta),this._sxNet&&e.push(this._sxNet),this._sxPinFunction&&e.push(this._sxPinFunction),this._sxPinType&&e.push(this._sxPinType),this._sxDieLength&&e.push(this._sxDieLength),this._sxSolderMaskMargin&&e.push(this._sxSolderMaskMargin),this._sxSolderPasteMargin&&e.push(this._sxSolderPasteMargin),this._sxSolderPasteMarginRatio&&e.push(this._sxSolderPasteMarginRatio),this._sxClearance&&e.push(this._sxClearance),this._sxZoneConnect&&e.push(this._sxZoneConnect),this._sxThermalWidth&&e.push(this._sxThermalWidth),this._sxThermalGap&&e.push(this._sxThermalGap),this._sxThermalBridgeAngle&&e.push(this._sxThermalBridgeAngle),this._sxUuid&&e.push(this._sxUuid),this._sxRemoveUnusedLayers&&e.push(this._sxRemoveUnusedLayers),this._sxKeepEndLayers&&e.push(this._sxKeepEndLayers),this._sxTeardrops&&e.push(this._sxTeardrops),this._sxOptions&&e.push(this._sxOptions),this._sxPrimitives&&e.push(this._sxPrimitives),e}getString(){const e=[`(pad ${D(this._number)} ${this._padType} ${this._shape}`];for(const s of this.getChildren())e.push(s.getStringIndented());return this._locked&&e.push(" locked"),e.push(")"),e.join(`
|
|
142
|
+
`)}},o(Ur,"token","pad"),Ur);f.register(pc);var xt,Ud=(xt=class extends fe{constructor(e={}){super(e.value??!1);o(this,"token","remove_unused_layers");o(this,"bareToken");this.bareToken=e.bareToken}static fromSexprPrimitives(e){const[s]=e;if(s===void 0)return new xt({value:!1});if(typeof s=="boolean")return new xt({value:s});if(typeof s=="string"){const r=s.toLowerCase();if(r==="yes"||r==="true")return new xt({value:!0});if(r==="no"||r==="false")return new xt({value:!1})}throw new Error(`remove_unused_layers expects yes/no or boolean, received ${JSON.stringify(s)}`)}getString(){return this.bareToken?this.bareToken:`(remove_unused_layers ${this.value?"yes":"no"})`}},o(xt,"token","remove_unused_layers"),o(xt,"parentToken","pad"),xt);f.register(Ud);var yt,jd=(yt=class extends fe{constructor(e={}){super(e.value??!1);o(this,"token","keep_end_layers");o(this,"renderBare");this.renderBare=e.bare??!1}static fromSexprPrimitives(e){const[s]=e;if(s===void 0)return new yt({value:!1});if(typeof s=="boolean")return new yt({value:s});if(typeof s=="string"){const r=s.toLowerCase();if(r==="yes"||r==="true")return new yt({value:!0});if(r==="no"||r==="false")return new yt({value:!1})}throw new Error(`keep_end_layers expects yes/no or boolean, received ${JSON.stringify(s)}`)}getString(){return this.renderBare?"keep_end_layers":`(keep_end_layers ${this.value?"yes":"no"})`}},o(yt,"token","keep_end_layers"),o(yt,"parentToken","pad"),yt);f.register(jd);var Ff=new Set(["at","xy","layer","effects","uuid","unlocked","hide"]),a0=new Set,jr,em=(jr=class extends f{constructor(e={}){super();o(this,"token","fp_text");o(this,"_type");o(this,"_text","");o(this,"_sxPosition");o(this,"_sxUnlocked");o(this,"_sxHide");o(this,"_sxLayer");o(this,"_sxEffects");o(this,"_sxUuid");e.type!==void 0&&(this.type=e.type),e.text!==void 0&&(this.text=e.text),e.position!==void 0&&(this.position=e.position),e.unlocked!==void 0&&(this.unlocked=e.unlocked),e.hidden!==void 0&&(this.hidden=e.hidden),e.layer!==void 0&&(this.layer=e.layer),e.effects!==void 0&&(this.effects=e.effects),e.uuid!==void 0&&(this.uuid=e.uuid)}static fromSexprPrimitives(e){if(e.length<2)throw new Error("fp_text requires a type and text value");const[s,r,...i]=e,a=new jr;if(typeof s!="string")throw new Error(`fp_text type must be a string token, received ${JSON.stringify(s)}`);a._type=s,a._text=c0(r);const l=[];let c=!1,h=!1;for(const v of i){if(typeof v=="string"){if(v==="unlocked"){if(c)throw new Error("fp_text encountered duplicate bare unlocked tokens");c=!0;continue}if(v==="hide"){if(h)throw new Error("fp_text encountered duplicate bare hide tokens");h=!0;continue}throw new Error(`fp_text encountered unsupported flag "${v}"`)}if(!Array.isArray(v)||v.length===0)throw new Error(`fp_text encountered invalid child expression: ${JSON.stringify(v)}`);l.push(v)}const{propertyMap:d,arrayPropertyMap:p}=f.parsePrimitivesToClassProperties(l,this.token);for(const v of Object.keys(d))if(!Ff.has(v))throw new Error(`fp_text encountered unsupported child token "${v}"`);for(const[v,m]of Object.entries(p)){if(!Ff.has(v))throw new Error(`fp_text encountered unsupported child token "${v}"`);if(!a0.has(v)&&m.length>1)throw new Error(`fp_text does not support repeated child token "${v}"`)}const u=d.at,g=d.xy;if(u&&g)throw new Error("fp_text cannot include both at and xy child tokens");a._sxPosition=u??g,a._sxLayer=d.layer,a._sxEffects=d.effects,a._sxUuid=d.uuid;const _=d.unlocked,x=d.hide;if(_&&c)throw new Error("fp_text encountered both bare and structured unlocked tokens");if(x&&h)throw new Error("fp_text encountered both bare and structured hide tokens");return a._sxUnlocked=_,a._sxHide=x,c&&(a._sxUnlocked=new Bd({value:!0,bare:!0})),h&&(a._sxHide=new Dd({value:!0,bare:!0})),a}get type(){return this._type}set type(e){this._type=e}get text(){return this._text}set text(e){this._text=e}get position(){return this._sxPosition}set position(e){if(e===void 0){this._sxPosition=void 0;return}if(e instanceof et){this._sxPosition=e;return}this._sxPosition=he.from(e)}get unlocked(){var e;return((e=this._sxUnlocked)==null?void 0:e.value)??!1}set unlocked(e){this._sxUnlocked=e?new Bd({value:!0,bare:!0}):void 0}get hidden(){var e;return((e=this._sxHide)==null?void 0:e.value)??!1}set hidden(e){this._sxHide=e?new Dd({value:!0,bare:!0}):void 0}get layer(){return this._sxLayer}set layer(e){if(e===void 0){this._sxLayer=void 0;return}if(e instanceof ce)this._sxLayer=e;else{const s=Array.isArray(e)?e:[e];this._sxLayer=new ce(s)}}get effects(){return this._sxEffects}set effects(e){this._sxEffects=e}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}getChildren(){const e=[];return this._sxPosition&&e.push(this._sxPosition),this._sxUnlocked&&e.push(this._sxUnlocked),this._sxLayer&&e.push(this._sxLayer),this._sxHide&&e.push(this._sxHide),this._sxEffects&&e.push(this._sxEffects),this._sxUuid&&e.push(this._sxUuid),e}getString(){const e=["(fp_text"];this._type!==void 0&&e.push(` ${this._type}`),e.push(` ${D(this._text)}`);for(const s of this.getChildren())e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
143
|
+
`)}},o(jr,"token","fp_text"),jr);f.register(em);function c0(n){if(n===void 0)return"";const t=F(n);return t!==void 0?t:Ie(n)}var Tn,Bd=(Tn=class extends f{constructor(e={}){super();o(this,"token","unlocked");o(this,"value");o(this,"renderBare");this.value=e.value??!0,this.renderBare=e.bare??!1}static fromSexprPrimitives(e){const[s]=e,r=F(s),i=r===void 0?!0:!/^(no|false)$/iu.test(r);return new Tn({value:i,bare:!1})}getChildren(){return[]}getString(){return this.renderBare?"unlocked":`(unlocked ${this.value?"yes":"no"})`}},o(Tn,"token","unlocked"),o(Tn,"parentToken","fp_text"),Tn);f.register(Bd);var En,Dd=(En=class extends f{constructor(e={}){super();o(this,"token","hide");o(this,"value");o(this,"renderBare");this.value=e.value??!0,this.renderBare=e.bare??!1}static fromSexprPrimitives(e){const[s]=e,r=F(s),i=r===void 0?!0:!/^(no|false)$/iu.test(r);return new En({value:i,bare:!1})}getChildren(){return[]}getString(){return this.renderBare?"hide":`(hide ${this.value?"yes":"no"})`}},o(En,"token","hide"),o(En,"parentToken","fp_text"),En);f.register(Dd);function l0(n){if(n===void 0)return"";const t=F(n);return t!==void 0?t:Ie(n)}var zf=new Set(["start","end","pts","angle","layer","uuid","effects","stroke","render_cache"]),h0=new Set,Br,d0=(Br=class extends f{constructor(e={}){super();o(this,"token","fp_text_box");o(this,"_sxLocked");o(this,"_text","");o(this,"_sxStart");o(this,"_sxEnd");o(this,"_sxPts");o(this,"_sxAngle");o(this,"_sxLayer");o(this,"_sxUuid");o(this,"_sxEffects");o(this,"_sxStroke");o(this,"_sxRenderCache");e.locked!==void 0&&(this.locked=e.locked),e.text!==void 0&&(this.text=e.text),e.start!==void 0&&(this.start=e.start),e.end!==void 0&&(this.end=e.end),e.pts!==void 0&&(this.pts=e.pts),e.angle!==void 0&&(this.angle=e.angle),e.layer!==void 0&&(this.layer=e.layer),e.uuid!==void 0&&(this.uuid=e.uuid),e.effects!==void 0&&(this.effects=e.effects),e.stroke!==void 0&&(this.stroke=e.stroke),e.renderCache!==void 0&&(this.renderCache=e.renderCache)}static fromSexprPrimitives(e){const s=new Br;if(e.length===0)throw new Error("fp_text_box requires a text value");let r=!1,i=!1;const a=[];for(const h of e){if(typeof h=="string"){if(h==="locked"){if(i)throw new Error("fp_text_box encountered duplicate locked flags");i=!0;continue}if(!r){s._text=h,r=!0;continue}throw new Error(`fp_text_box encountered unsupported flag "${h}"`)}if(!r){s._text=l0(h),r=!0;continue}if(!Array.isArray(h)||h.length===0)throw new Error(`fp_text_box encountered invalid child expression: ${JSON.stringify(h)}`);a.push(h)}if(!r)throw new Error("fp_text_box did not include a text value");i&&(s._sxLocked=new Hd);const{propertyMap:l,arrayPropertyMap:c}=f.parsePrimitivesToClassProperties(a,this.token);for(const h of Object.keys(l))if(!zf.has(h))throw new Error(`fp_text_box encountered unsupported child token "${h}"`);for(const[h,d]of Object.entries(c)){if(!zf.has(h))throw new Error(`fp_text_box encountered unsupported child token "${h}"`);if(!h0.has(h)&&d.length>1)throw new Error(`fp_text_box does not support repeated child token "${h}"`)}return s._sxStart=l.start,s._sxEnd=l.end,s._sxPts=l.pts,s._sxAngle=l.angle,s._sxLayer=l.layer,s._sxUuid=l.uuid,s._sxEffects=l.effects,s._sxStroke=l.stroke,s._sxRenderCache=l.render_cache,s}get locked(){return this._sxLocked!==void 0}set locked(e){this._sxLocked=e?new Hd:void 0}get text(){return this._text}set text(e){this._text=e}get start(){return this._sxStart}set start(e){if(e===void 0){this._sxStart=void 0;return}this._sxStart=e instanceof Wd?e:new Wd([e.x,e.y])}get end(){return this._sxEnd}set end(e){if(e===void 0){this._sxEnd=void 0;return}this._sxEnd=e instanceof Gd?e:new Gd([e.x,e.y])}get pts(){return this._sxPts}set pts(e){this._sxPts=e}get angle(){return this._sxAngle}set angle(e){if(e===void 0){this._sxAngle=void 0;return}this._sxAngle=e instanceof Vd?e:new Vd([e])}get layer(){return this._sxLayer}set layer(e){if(e===void 0){this._sxLayer=void 0;return}if(e instanceof ce)this._sxLayer=e;else{const s=Array.isArray(e)?e:[e];this._sxLayer=new ce(s)}}get effects(){return this._sxEffects}set effects(e){this._sxEffects=e}get stroke(){return this._sxStroke}set stroke(e){this._sxStroke=e}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}get renderCache(){return this._sxRenderCache}set renderCache(e){this._sxRenderCache=e}getChildren(){const e=[];return this._sxLocked&&e.push(this._sxLocked),this._sxStart&&e.push(this._sxStart),this._sxEnd&&e.push(this._sxEnd),this._sxPts&&e.push(this._sxPts),this._sxAngle&&e.push(this._sxAngle),this._sxLayer&&e.push(this._sxLayer),this._sxEffects&&e.push(this._sxEffects),this._sxStroke&&e.push(this._sxStroke),this._sxUuid&&e.push(this._sxUuid),this._sxRenderCache&&e.push(this._sxRenderCache),e}getString(){const e=["(fp_text_box"];this._sxLocked&&e.push(this._sxLocked.getStringIndented()),e.push(` ${D(this._text)}`);for(const s of this.getChildren())s!==this._sxLocked&&e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
144
|
+
`)}},o(Br,"token","fp_text_box"),Br);f.register(d0);var Cn,Wd=(Cn=class extends f{constructor(e){super();o(this,"token","start");o(this,"x");o(this,"y");this.x=e[0],this.y=e[1]}static fromSexprPrimitives(e){const[s,r]=e,i=Number(s),a=Number(r);return new Cn([Number.isFinite(i)?i:0,Number.isFinite(a)?a:0])}getChildren(){return[]}getString(){return`(start ${this.x} ${this.y})`}},o(Cn,"token","start"),o(Cn,"parentToken","fp_text_box"),Cn);f.register(Wd);var Nn,Gd=(Nn=class extends f{constructor(e){super();o(this,"token","end");o(this,"x");o(this,"y");this.x=e[0],this.y=e[1]}static fromSexprPrimitives(e){const[s,r]=e,i=Number(s),a=Number(r);return new Nn([Number.isFinite(i)?i:0,Number.isFinite(a)?a:0])}getChildren(){return[]}getString(){return`(end ${this.x} ${this.y})`}},o(Nn,"token","end"),o(Nn,"parentToken","fp_text_box"),Nn);f.register(Gd);var $n,Vd=($n=class extends f{constructor(e){super();o(this,"token","angle");o(this,"value");this.value=e[0]}static fromSexprPrimitives(e){const[s]=e,r=typeof s=="number"?s:O(s)??0;return new $n([r])}getChildren(){return[]}getString(){return`(angle ${this.value})`}},o($n,"token","angle"),o($n,"parentToken","fp_text_box"),$n);f.register(Vd);var An,Hd=(An=class extends f{constructor(){super(...arguments);o(this,"token","locked")}static fromSexprPrimitives(){return new An}getChildren(){return[]}getString(){return"locked"}},o(An,"token","locked"),o(An,"parentToken","fp_text_box"),An);f.register(Hd);var Dr,u0=(Dr=class extends f{constructor(e={}){super();o(this,"token","fp_rect");o(this,"_sxStart");o(this,"_sxEnd");o(this,"_sxLayer");o(this,"_sxWidth");o(this,"_sxStroke");o(this,"_sxFill");o(this,"_sxUuid");o(this,"_locked",!1);e.start!==void 0&&(this.start=e.start),e.end!==void 0&&(this.end=e.end),e.layer!==void 0&&(this.layer=e.layer),e.width!==void 0&&(this.width=e.width),e.stroke!==void 0&&(this.stroke=e.stroke),e.fill!==void 0&&(this.fill=e.fill),e.uuid!==void 0&&(this.uuid=e.uuid),e.locked!==void 0&&(this.locked=e.locked)}static fromSexprPrimitives(e){const s=new Dr,{propertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);s._sxStart=r.start,s._sxEnd=r.end,s._sxLayer=r.layer,s._sxWidth=r.width,s._sxStroke=r.stroke,s._sxFill=r.fill,s._sxUuid=r.uuid;for(const i of e)i==="locked"&&(s._locked=!0);return s}get start(){return this._sxStart}set start(e){if(e===void 0){this._sxStart=void 0;return}if(e instanceof Yd){this._sxStart=e;return}this._sxStart=new Yd(e.x,e.y)}get end(){return this._sxEnd}set end(e){if(e===void 0){this._sxEnd=void 0;return}if(e instanceof Xd){this._sxEnd=e;return}this._sxEnd=new Xd(e.x,e.y)}get layer(){return this._sxLayer}set layer(e){if(e===void 0){this._sxLayer=void 0;return}if(e instanceof ce){this._sxLayer=e;return}const s=Array.isArray(e)?e:[e];this._sxLayer=new ce(s)}get stroke(){return this._sxStroke}set stroke(e){this._sxStroke=e}get width(){var e;return(e=this._sxWidth)==null?void 0:e.value}set width(e){if(e===void 0){this._sxWidth=void 0;return}if(e instanceof de){this._sxWidth=e;return}this._sxWidth=new de(e)}get widthClass(){return this._sxWidth}get fill(){var e;return(e=this._sxFill)==null?void 0:e.filled}set fill(e){if(e===void 0){this._sxFill=void 0;return}if(e instanceof qd){this._sxFill=e;return}this._sxFill=new qd(e)}get fillClass(){return this._sxFill}get uuid(){var e;return(e=this._sxUuid)==null?void 0:e.value}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}if(e instanceof W){this._sxUuid=e;return}this._sxUuid=new W(e)}get uuidClass(){return this._sxUuid}get locked(){return this._locked}set locked(e){this._locked=e}getChildren(){const e=[];return this._sxStart&&e.push(this._sxStart),this._sxEnd&&e.push(this._sxEnd),this._sxLayer&&e.push(this._sxLayer),this._sxWidth&&e.push(this._sxWidth),this._sxStroke&&e.push(this._sxStroke),this._sxFill&&e.push(this._sxFill),this._sxUuid&&e.push(this._sxUuid),e}getString(){const e=["(fp_rect"],s=r=>{r&&e.push(r.getStringIndented())};return s(this._sxStart),s(this._sxEnd),s(this._sxLayer),s(this._sxWidth),s(this._sxStroke),s(this._sxFill),s(this._sxUuid),this._locked&&e.push(" locked"),e.push(")"),e.join(`
|
|
145
|
+
`)}},o(Dr,"token","fp_rect"),Dr);f.register(u0);var In,Yd=(In=class extends f{constructor(e,s){super();o(this,"token","start");o(this,"x");o(this,"y");this.x=e,this.y=s}static fromSexprPrimitives(e){const s=O(e[0])??0,r=O(e[1])??0;return new In(s,r)}getString(){return`(start ${this.x} ${this.y})`}},o(In,"token","start"),o(In,"parentToken","fp_rect"),In);f.register(Yd);var Ln,Xd=(Ln=class extends f{constructor(e,s){super();o(this,"token","end");o(this,"x");o(this,"y");this.x=e,this.y=s}static fromSexprPrimitives(e){const s=O(e[0])??0,r=O(e[1])??0;return new Ln(s,r)}getString(){return`(end ${this.x} ${this.y})`}},o(Ln,"token","end"),o(Ln,"parentToken","fp_rect"),Ln);f.register(Xd);var Mn,qd=(Mn=class extends f{constructor(e){super();o(this,"token","fill");o(this,"filled");this.filled=e}static fromSexprPrimitives(e){const s=F(e[0]);return new Mn(s==="yes")}getString(){return`(fill ${this.filled?"yes":"no"})`}},o(Mn,"token","fill"),o(Mn,"parentToken","fp_rect"),Mn);f.register(qd);var Wr,p0=(Wr=class extends f{constructor(e={}){super();o(this,"token","fp_circle");o(this,"_sxCenter");o(this,"_sxEnd");o(this,"_sxLayer");o(this,"_sxWidth");o(this,"_sxStroke");o(this,"_sxFill");o(this,"_sxUuid");o(this,"_locked",!1);e.center!==void 0&&(this.center=e.center),e.end!==void 0&&(this.end=e.end),e.layer!==void 0&&(this.layer=e.layer),e.width!==void 0&&(this.width=e.width),e.stroke!==void 0&&(this.stroke=e.stroke),e.fill!==void 0&&(this.fill=e.fill),e.uuid!==void 0&&(this.uuid=e.uuid),e.locked!==void 0&&(this.locked=e.locked)}static fromSexprPrimitives(e){const s=new Wr,{propertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);s._sxCenter=r.center,s._sxEnd=r.end,s._sxLayer=r.layer,s._sxWidth=r.width,s._sxStroke=r.stroke,s._sxFill=r.fill,s._sxUuid=r.uuid;for(const i of e)i==="locked"&&(s._locked=!0);return s}get center(){return this._sxCenter}set center(e){if(e===void 0){this._sxCenter=void 0;return}if(e instanceof Kd){this._sxCenter=e;return}this._sxCenter=new Kd(e.x,e.y)}get end(){return this._sxEnd}set end(e){if(e===void 0){this._sxEnd=void 0;return}if(e instanceof Jd){this._sxEnd=e;return}this._sxEnd=new Jd(e.x,e.y)}get layer(){return this._sxLayer}set layer(e){if(e===void 0){this._sxLayer=void 0;return}if(e instanceof ce){this._sxLayer=e;return}const s=Array.isArray(e)?e:[e];this._sxLayer=new ce(s)}get width(){var e;return(e=this._sxWidth)==null?void 0:e.value}set width(e){if(e===void 0){this._sxWidth=void 0;return}if(e instanceof de){this._sxWidth=e;return}this._sxWidth=new de(e)}get widthClass(){return this._sxWidth}get stroke(){return this._sxStroke}set stroke(e){this._sxStroke=e}get fill(){var e;return(e=this._sxFill)==null?void 0:e.filled}set fill(e){if(e===void 0){this._sxFill=void 0;return}if(e instanceof Zd){this._sxFill=e;return}this._sxFill=new Zd(e)}get fillClass(){return this._sxFill}get uuid(){var e;return(e=this._sxUuid)==null?void 0:e.value}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}if(e instanceof W){this._sxUuid=e;return}this._sxUuid=new W(e)}get uuidClass(){return this._sxUuid}get locked(){return this._locked}set locked(e){this._locked=e}getChildren(){const e=[];return this._sxCenter&&e.push(this._sxCenter),this._sxEnd&&e.push(this._sxEnd),this._sxLayer&&e.push(this._sxLayer),this._sxWidth&&e.push(this._sxWidth),this._sxStroke&&e.push(this._sxStroke),this._sxFill&&e.push(this._sxFill),this._sxUuid&&e.push(this._sxUuid),e}getString(){const e=["(fp_circle"],s=r=>{r&&e.push(r.getStringIndented())};return s(this._sxCenter),s(this._sxEnd),s(this._sxLayer),s(this._sxWidth),s(this._sxStroke),s(this._sxFill),s(this._sxUuid),this._locked&&e.push(" locked"),e.push(")"),e.join(`
|
|
146
|
+
`)}},o(Wr,"token","fp_circle"),Wr);f.register(p0);var Rn,Kd=(Rn=class extends f{constructor(e,s){super();o(this,"token","center");o(this,"x");o(this,"y");this.x=e,this.y=s}static fromSexprPrimitives(e){const s=O(e[0])??0,r=O(e[1])??0;return new Rn(s,r)}getString(){return`(center ${this.x} ${this.y})`}},o(Rn,"token","center"),o(Rn,"parentToken","fp_circle"),Rn);f.register(Kd);var On,Jd=(On=class extends f{constructor(e,s){super();o(this,"token","end");o(this,"x");o(this,"y");this.x=e,this.y=s}static fromSexprPrimitives(e){const s=O(e[0])??0,r=O(e[1])??0;return new On(s,r)}getString(){return`(end ${this.x} ${this.y})`}},o(On,"token","end"),o(On,"parentToken","fp_circle"),On);f.register(Jd);var Fn,Zd=(Fn=class extends f{constructor(e){super();o(this,"token","fill");o(this,"filled");this.filled=e}static fromSexprPrimitives(e){const s=F(e[0]);return new Fn(s==="yes")}getString(){return`(fill ${this.filled?"yes":"no"})`}},o(Fn,"token","fill"),o(Fn,"parentToken","fp_circle"),Fn);f.register(Zd);var Gr,f0=(Gr=class extends f{constructor(e={}){super();o(this,"token","fp_arc");o(this,"_sxStart");o(this,"_sxMid");o(this,"_sxEnd");o(this,"_sxLayer");o(this,"_sxWidth");o(this,"_sxStroke");o(this,"_sxUuid");o(this,"_locked",!1);e.start!==void 0&&(this.start=e.start),e.mid!==void 0&&(this.mid=e.mid),e.end!==void 0&&(this.end=e.end),e.layer!==void 0&&(this.layer=e.layer),e.width!==void 0&&(this.width=e.width),e.stroke!==void 0&&(this.stroke=e.stroke),e.uuid!==void 0&&(this.uuid=e.uuid),e.locked!==void 0&&(this.locked=e.locked)}static fromSexprPrimitives(e){const s=new Gr,{propertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);s._sxStart=r.start,s._sxMid=r.mid,s._sxEnd=r.end,s._sxLayer=r.layer,s._sxWidth=r.width,s._sxStroke=r.stroke,s._sxUuid=r.uuid;for(const i of e)i==="locked"&&(s._locked=!0);return s}get start(){return this._sxStart}set start(e){if(e===void 0){this._sxStart=void 0;return}if(e instanceof Qd){this._sxStart=e;return}this._sxStart=new Qd(e.x,e.y)}get mid(){return this._sxMid}set mid(e){if(e===void 0){this._sxMid=void 0;return}if(e instanceof eu){this._sxMid=e;return}this._sxMid=new eu(e.x,e.y)}get end(){return this._sxEnd}set end(e){if(e===void 0){this._sxEnd=void 0;return}if(e instanceof tu){this._sxEnd=e;return}this._sxEnd=new tu(e.x,e.y)}get layer(){return this._sxLayer}set layer(e){if(e===void 0){this._sxLayer=void 0;return}if(e instanceof ce){this._sxLayer=e;return}const s=Array.isArray(e)?e:[e];this._sxLayer=new ce(s)}get width(){var e;return(e=this._sxWidth)==null?void 0:e.value}set width(e){if(e===void 0){this._sxWidth=void 0;return}if(e instanceof de){this._sxWidth=e;return}this._sxWidth=new de(e)}get widthClass(){return this._sxWidth}get stroke(){return this._sxStroke}set stroke(e){this._sxStroke=e}get uuid(){var e;return(e=this._sxUuid)==null?void 0:e.value}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}if(e instanceof W){this._sxUuid=e;return}this._sxUuid=new W(e)}get uuidClass(){return this._sxUuid}get locked(){return this._locked}set locked(e){this._locked=e}getChildren(){const e=[];return this._sxStart&&e.push(this._sxStart),this._sxMid&&e.push(this._sxMid),this._sxEnd&&e.push(this._sxEnd),this._sxLayer&&e.push(this._sxLayer),this._sxWidth&&e.push(this._sxWidth),this._sxStroke&&e.push(this._sxStroke),this._sxUuid&&e.push(this._sxUuid),e}getString(){const e=["(fp_arc"],s=r=>{r&&e.push(r.getStringIndented())};return s(this._sxStart),s(this._sxMid),s(this._sxEnd),s(this._sxLayer),s(this._sxWidth),s(this._sxStroke),s(this._sxUuid),this._locked&&e.push(" locked"),e.push(")"),e.join(`
|
|
147
|
+
`)}},o(Gr,"token","fp_arc"),Gr);f.register(f0);var zn,Qd=(zn=class extends f{constructor(e,s){super();o(this,"token","start");o(this,"x");o(this,"y");this.x=e,this.y=s}static fromSexprPrimitives(e){const s=O(e[0])??0,r=O(e[1])??0;return new zn(s,r)}getString(){return`(start ${this.x} ${this.y})`}},o(zn,"token","start"),o(zn,"parentToken","fp_arc"),zn);f.register(Qd);var Un,eu=(Un=class extends f{constructor(e,s){super();o(this,"token","mid");o(this,"x");o(this,"y");this.x=e,this.y=s}static fromSexprPrimitives(e){const s=O(e[0])??0,r=O(e[1])??0;return new Un(s,r)}getString(){return`(mid ${this.x} ${this.y})`}},o(Un,"token","mid"),o(Un,"parentToken","fp_arc"),Un);f.register(eu);var jn,tu=(jn=class extends f{constructor(e,s){super();o(this,"token","end");o(this,"x");o(this,"y");this.x=e,this.y=s}static fromSexprPrimitives(e){const s=O(e[0])??0,r=O(e[1])??0;return new jn(s,r)}getString(){return`(end ${this.x} ${this.y})`}},o(jn,"token","end"),o(jn,"parentToken","fp_arc"),jn);f.register(tu);var g0=new Set(["yes","true","1"]),vt,su=(vt=class extends fe{constructor(e){super(e);o(this,"token","fill")}static fromSexprPrimitives(e){const[s]=e;return s===void 0?new vt(!1):typeof s=="boolean"?new vt(s):typeof s=="string"?new vt(g0.has(s.toLowerCase())):new vt(!1)}get filled(){return this.value}set filled(e){this.value=e}getString(){return`(fill ${this.value?"yes":"no"})`}},o(vt,"token","fill"),o(vt,"parentToken","fp_poly"),vt);f.register(su);var _0=new Set(["yes","true","1"]),wt,Ea=(wt=class extends fe{constructor(e){super(e);o(this,"token","locked")}static fromSexprPrimitives(e){const[s]=e;return s===void 0?new wt(!0):typeof s=="boolean"?new wt(s):typeof s=="string"?new wt(_0.has(s.toLowerCase())):new wt(!1)}getString(){return`(locked ${this.value?"yes":"no"})`}},o(wt,"token","locked"),o(wt,"parentToken","fp_poly"),wt);f.register(Ea);var Ac=new Set(["pts","xy","layer","width","stroke","fill","locked","uuid"]),Vr,m0=(Vr=class extends f{constructor(e={}){super();o(this,"token","fp_poly");o(this,"_sxPts");o(this,"_sxLayer");o(this,"_sxWidth");o(this,"_sxStroke");o(this,"_sxFill");o(this,"_sxLocked");o(this,"_sxUuid");e.points!==void 0&&(this.points=e.points),e.layer!==void 0&&(this.layer=e.layer),e.width!==void 0&&(this.width=e.width),e.stroke!==void 0&&(this.stroke=e.stroke),e.fill!==void 0&&(this.fill=e.fill),e.locked!==void 0&&(this.locked=e.locked),e.uuid!==void 0&&(this.uuid=e.uuid)}static fromSexprPrimitives(e){const s=new Vr,{propertyMap:r,arrayPropertyMap:i}=f.parsePrimitivesToClassProperties(e,this.token),a=new Set;for(const p of Object.keys(r))Ac.has(p)||a.add(p);for(const p of Object.keys(i))Ac.has(p)||a.add(p),p!=="xy"&&i[p].length>1&&a.add(p);if(a.size>0)throw new Error(`Unsupported child tokens inside fp_poly expression: ${[...a].join(", ")}`);const l=i.pts;if(l&&l.length>1)throw new Error("fp_poly does not support repeated pts tokens");const c=i.xy;let h=r.pts;if(h&&c&&c.length>0)throw new Error("fp_poly cannot mix pts and xy child tokens");!h&&(l!=null&&l.length)&&(h=l[0]),!h&&c&&c.length>0&&(h=new Gt(c)),s._sxPts=h,s._sxLayer=r.layer,s._sxWidth=r.width,s._sxStroke=r.stroke,s._sxFill=r.fill;const d=r.locked;s._sxLocked=d&&d.value?d:void 0,s._sxUuid=r.uuid;for(const p of e){if(p==="locked"){s._sxLocked||(s._sxLocked=new Ea(!0));continue}if(!Array.isArray(p)||p.length===0)throw new Error(`fp_poly encountered unexpected primitive child: ${JSON.stringify(p)}`);const[u,...g]=p;if(typeof u!="string")throw new Error(`fp_poly child token must be a string, received: ${JSON.stringify(u)}`);if(!Ac.has(u))throw new Error(`Unsupported child token inside fp_poly expression: ${u}`);u==="locked"&&!s._sxLocked&&(s._sxLocked=Ea.fromSexprPrimitives(g),s._sxLocked.value||(s._sxLocked=void 0))}if(!s._sxPts)throw new Error("fp_poly requires pts or xy child tokens");if(!s._sxLayer)throw new Error("fp_poly requires a layer child token");if(!s._sxUuid)throw new Error("fp_poly requires a uuid child token");return s}get points(){return this._sxPts}set points(e){if(e===void 0){this._sxPts=void 0;return}if(e instanceof Gt){this._sxPts=e;return}if(Array.isArray(e)&&e.every(s=>s instanceof et)){this._sxPts=new Gt(e);return}if(Array.isArray(e)){this._sxPts=new Gt(e.map(({x:s,y:r})=>new et(s,r)));return}throw new Error("Unsupported points value provided to fp_poly")}get layer(){return this._sxLayer}set layer(e){if(e===void 0){this._sxLayer=void 0;return}if(e instanceof ce){this._sxLayer=e;return}const s=Array.isArray(e)?e:[e];this._sxLayer=new ce(s)}get width(){var e;return(e=this._sxWidth)==null?void 0:e.value}set width(e){if(e===void 0){this._sxWidth=void 0;return}this._sxWidth=e instanceof de?e:new de(e)}get widthClass(){return this._sxWidth}set widthClass(e){this._sxWidth=e}get stroke(){return this._sxStroke}set stroke(e){this._sxStroke=e}get fill(){return this._sxFill}set fill(e){if(e===void 0){this._sxFill=void 0;return}if(e instanceof su){this._sxFill=e;return}this._sxFill=new su(e)}get locked(){var e;return((e=this._sxLocked)==null?void 0:e.value)??!1}set locked(e){this._sxLocked=e?new Ea(!0):void 0}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}getChildren(){const e=[];return this._sxPts&&e.push(this._sxPts),this._sxLayer&&e.push(this._sxLayer),this._sxWidth&&e.push(this._sxWidth),this._sxStroke&&e.push(this._sxStroke),this._sxFill&&e.push(this._sxFill),this._sxLocked&&e.push(this._sxLocked),this._sxUuid&&e.push(this._sxUuid),e}},o(Vr,"token","fp_poly"),Vr);f.register(m0);var Bn,nu=(Bn=class extends f{constructor(e){super();o(this,"token","sheetname");o(this,"_value");this._value=e}static fromSexprPrimitives(e){const s=F(e[0]);if(s===void 0)throw new Error("sheetname expects a string value");return new Bn(s)}get value(){return this._value}set value(e){this._value=e}getChildren(){return[]}getString(){return`(sheetname ${D(this._value)})`}},o(Bn,"token","sheetname"),o(Bn,"parentToken","footprint"),Bn);f.register(nu);var Dn,ru=(Dn=class extends f{constructor(e){super();o(this,"token","sheetfile");o(this,"_value");this._value=e}static fromSexprPrimitives(e){const s=F(e[0]);if(s===void 0)throw new Error("sheetfile expects a string value");return new Dn(s)}get value(){return this._value}set value(e){this._value=e}getChildren(){return[]}getString(){return`(sheetfile ${D(this._value)})`}},o(Dn,"token","sheetfile"),o(Dn,"parentToken","footprint"),Dn);f.register(ru);var Uf=new Set(["start","end","layer","width","stroke","uuid"]),Wn,x0=(Wn=class extends f{constructor(e={}){super();o(this,"token","fp_line");o(this,"_sxStart");o(this,"_sxEnd");o(this,"_sxLayer");o(this,"_sxWidth");o(this,"_sxStroke");o(this,"_sxUuid");o(this,"_locked",!1);e.start!==void 0&&(this.start=e.start),e.end!==void 0&&(this.end=e.end),e.layer!==void 0&&(this.layer=e.layer),e.width!==void 0&&(this.width=e.width),e.stroke!==void 0&&(this.stroke=e.stroke),e.uuid!==void 0&&(this.uuid=e.uuid),e.locked!==void 0&&(this.locked=e.locked)}static fromSexprPrimitives(e){var l,c,h,d,p,u;const s=new Wn,r=[];for(const g of e){if(typeof g=="string"){if(g==="locked"){if(s._locked)throw new Error("fp_line encountered duplicate locked flags");s._locked=!0;continue}throw new Error(`fp_line encountered unsupported flag "${g}"`)}if(!Array.isArray(g)||g.length===0)throw new Error(`fp_line encountered invalid child expression: ${JSON.stringify(g)}`);r.push(g)}const{propertyMap:i,arrayPropertyMap:a}=f.parsePrimitivesToClassProperties(r,this.token);for(const g of Object.keys(i))if(!Uf.has(g))throw new Error(`fp_line encountered unsupported child token "${g}"`);for(const[g,_]of Object.entries(a)){if(!Uf.has(g))throw new Error(`fp_line encountered unsupported child token "${g}"`);if(_.length>1)throw new Error(`fp_line does not support repeated child token "${g}"`)}if(s._sxStart=((l=a.start)==null?void 0:l[0])??i.start,s._sxEnd=((c=a.end)==null?void 0:c[0])??i.end,s._sxLayer=((h=a.layer)==null?void 0:h[0])??i.layer,s._sxWidth=((d=a.width)==null?void 0:d[0])??i.width,s._sxStroke=((p=a.stroke)==null?void 0:p[0])??i.stroke,s._sxUuid=((u=a.uuid)==null?void 0:u[0])??i.uuid,!s._sxStart)throw new Error("fp_line requires a start child token");if(!s._sxEnd)throw new Error("fp_line requires an end child token");if(!s._sxLayer)throw new Error("fp_line requires a layer child token");return s}get start(){return this._sxStart}set start(e){if(e===void 0){this._sxStart=void 0;return}this._sxStart=e instanceof iu?e:new iu(e.x,e.y)}get end(){return this._sxEnd}set end(e){if(e===void 0){this._sxEnd=void 0;return}this._sxEnd=e instanceof ou?e:new ou(e.x,e.y)}get layer(){return this._sxLayer}set layer(e){if(e===void 0){this._sxLayer=void 0;return}if(e instanceof ce){this._sxLayer=e;return}const s=Array.isArray(e)?e:[e];this._sxLayer=new ce(s)}get width(){var e;return(e=this._sxWidth)==null?void 0:e.value}set width(e){this._sxWidth=e===void 0?void 0:new de(e)}get stroke(){return this._sxStroke}set stroke(e){this._sxStroke=e}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}get locked(){return this._locked}set locked(e){this._locked=e}getChildren(){const e=[];return this._sxStart&&e.push(this._sxStart),this._sxEnd&&e.push(this._sxEnd),this._sxStroke?e.push(this._sxStroke):this._sxWidth&&e.push(this._sxWidth),this._sxLayer&&e.push(this._sxLayer),this._sxUuid&&e.push(this._sxUuid),this._locked&&e.push(new tm),e}},o(Wn,"token","fp_line"),o(Wn,"parentToken","footprint"),Wn);f.register(x0);var Gn,iu=(Gn=class extends f{constructor(e,s){super();o(this,"token","start");this.x=e,this.y=s}static fromSexprPrimitives(e){const[s,r]=e,i=Number(s),a=Number(r);if(!Number.isFinite(i)||!Number.isFinite(a))throw new Error("fp_line start expects numeric coordinates");return new Gn(i,a)}getChildren(){return[]}getString(){return`(start ${this.x} ${this.y})`}},o(Gn,"token","start"),o(Gn,"parentToken","fp_line"),Gn);f.register(iu);var Vn,ou=(Vn=class extends f{constructor(e,s){super();o(this,"token","end");this.x=e,this.y=s}static fromSexprPrimitives(e){const[s,r]=e,i=Number(s),a=Number(r);if(!Number.isFinite(i)||!Number.isFinite(a))throw new Error("fp_line end expects numeric coordinates");return new Vn(i,a)}getChildren(){return[]}getString(){return`(end ${this.x} ${this.y})`}},o(Vn,"token","end"),o(Vn,"parentToken","fp_line"),Vn);f.register(ou);var Hn,tm=(Hn=class extends f{constructor(){super(...arguments);o(this,"token","locked")}static fromSexprPrimitives(){return new Hn}getChildren(){return[]}getString(){return"locked"}},o(Hn,"token","locked"),o(Hn,"parentToken","fp_line"),Hn);f.register(tm);var Ic={x:0,y:0,z:0},Yn,y0=(Yn=class extends f{constructor(e){super();o(this,"token","model");o(this,"_path");o(this,"_offset");o(this,"_scale");o(this,"_rotate");this._path=e}static fromSexprPrimitives(e){if(e.length===0)throw new Error("model requires a path argument");const[s,...r]=e,i=F(s);if(i===void 0)throw new Error("model path must be a string value");const a=new Yn(i);for(const l of r){if(!Array.isArray(l)||l.length===0)throw new Error(`model encountered invalid child expression: ${JSON.stringify(l)}`);const[c,...h]=l;if(c==="offset"){a._offset=Lc(h,"offset");continue}if(c==="scale"){a._scale=Lc(h,"scale");continue}if(c==="rotate"){a._rotate=Lc(h,"rotate");continue}throw new Error(`model encountered unsupported child token "${c}"`)}return a}get path(){return this._path}set path(e){this._path=e}get offset(){return this._offset?{...this._offset}:void 0}set offset(e){this._offset=e?{...e}:void 0}get scale(){return this._scale?{...this._scale}:void 0}set scale(e){this._scale=e?{...e}:void 0}get rotate(){return this._rotate?{...this._rotate}:void 0}set rotate(e){this._rotate=e?{...e}:void 0}getChildren(){return[]}getString(){const e=[`(model ${D(this._path)}`];return this._offset&&e.push(Mc("offset",this._offset)),this._scale&&e.push(Mc("scale",this._scale)),this._rotate&&e.push(Mc("rotate",this._rotate)),e.push(")"),e.join(`
|
|
148
|
+
`)}},o(Yn,"token","model"),o(Yn,"parentToken","footprint"),Yn);f.register(y0);function Lc(n,t){if(n.length!==1)throw new Error(`model ${t} expects a single xyz child`);const[e]=n;if(!Array.isArray(e)||e.length!==4||e[0]!=="xyz")throw new Error(`model ${t} expects (xyz x y z), received ${JSON.stringify(e)}`);const[,s,r,i]=e,a=O(s)??Ic.x,l=O(r)??Ic.y,c=O(i)??Ic.z;return{x:a,y:l,z:c}}function Mc(n,t){return` (${n}
|
|
149
|
+
(xyz ${t.x} ${t.y} ${t.z})
|
|
150
|
+
)`}var Dt,Ca=(Dt=class extends fe{constructor(e=!0){super(e);o(this,"token","locked")}static fromSexprPrimitives(e){if(e.length===0)return new Dt(!0);const s=Ep(e[0]);if(s===void 0)throw new Error(`locked expects yes/no, received ${JSON.stringify(e[0])}`);return new Dt(s)}},o(Dt,"token","locked"),o(Dt,"parentToken","footprint"),Dt);f.register(Ca);var Wt,Na=(Wt=class extends fe{constructor(e=!0){super(e);o(this,"token","placed")}static fromSexprPrimitives(e){if(e.length===0)return new Wt(!0);const s=Ep(e[0]);if(s===void 0)throw new Error(`placed expects yes/no, received ${JSON.stringify(e[0])}`);return new Wt(s)}},o(Wt,"token","placed"),o(Wt,"parentToken","footprint"),Wt);f.register(Na);var v0=new Set(["layer","locked","placed","tedit","uuid","at","xy","descr","tags","path","autoplace_cost90","autoplace_cost180","solder_mask_margin","solder_paste_margin","solder_paste_ratio","clearance","zone_connect","thermal_width","thermal_gap","attr","private_layers","net_tie_pad_groups","sheetname","sheetfile","embedded_fonts"]),sm=new Set(["property","fp_text","fp_text_box","fp_line","fp_rect","fp_circle","fp_arc","fp_poly","pad","model"]),jf=new Set([...v0,...sm]),Hr,Cp=(Hr=class extends f{constructor(e={}){super();o(this,"token","footprint");o(this,"_libraryLink");o(this,"_sxLocked");o(this,"_sxPlaced");o(this,"_sxLayer");o(this,"_sxTedit");o(this,"_sxUuid");o(this,"_sxAt");o(this,"_sxXy");o(this,"_sxDescr");o(this,"_sxTags");o(this,"_sxPath");o(this,"_sxAutoplaceCost90");o(this,"_sxAutoplaceCost180");o(this,"_sxSolderMaskMargin");o(this,"_sxSolderPasteMargin");o(this,"_sxSolderPasteRatio");o(this,"_sxClearance");o(this,"_sxZoneConnect");o(this,"_sxThermalWidth");o(this,"_sxThermalGap");o(this,"_sxAttr");o(this,"_sxPrivateLayers");o(this,"_sxNetTiePadGroups");o(this,"_sxSheetname");o(this,"_sxSheetfile");o(this,"_sxEmbeddedFonts");o(this,"_properties",[]);o(this,"_fpTexts",[]);o(this,"_fpTextBoxes",[]);o(this,"_fpLines",[]);o(this,"_fpRects",[]);o(this,"_fpCircles",[]);o(this,"_fpArcs",[]);o(this,"_fpPolys",[]);o(this,"_fpPads",[]);o(this,"_models",[]);e.libraryLink!==void 0&&(this.libraryLink=e.libraryLink),e.locked!==void 0&&(this.locked=e.locked),e.placed!==void 0&&(this.placed=e.placed),e.layer!==void 0&&(this.layer=e.layer),e.uuid!==void 0&&(this.uuid=e.uuid),e.at!==void 0&&(this.position=e.at),e.descr!==void 0&&(this.descr=e.descr),e.tags!==void 0&&(this.tags=e.tags),e.path!==void 0&&(this.path=e.path),e.autoplaceCost90!==void 0&&(this.autoplaceCost90=e.autoplaceCost90),e.autoplaceCost180!==void 0&&(this.autoplaceCost180=e.autoplaceCost180),e.solderMaskMargin!==void 0&&(this.solderMaskMargin=e.solderMaskMargin),e.solderPasteMargin!==void 0&&(this.solderPasteMargin=e.solderPasteMargin),e.solderPasteRatio!==void 0&&(this.solderPasteRatio=e.solderPasteRatio),e.clearance!==void 0&&(this.clearance=e.clearance),e.zoneConnect!==void 0&&(this.zoneConnect=e.zoneConnect),e.thermalWidth!==void 0&&(this.thermalWidth=e.thermalWidth),e.thermalGap!==void 0&&(this.thermalGap=e.thermalGap),e.attr!==void 0&&(this.attr=e.attr),e.privateLayers!==void 0&&(this.privateLayers=e.privateLayers),e.netTiePadGroups!==void 0&&(this.netTiePadGroups=e.netTiePadGroups),e.sheetname!==void 0&&(this.sheetname=e.sheetname),e.sheetfile!==void 0&&(this.sheetfile=e.sheetfile),e.embeddedFonts!==void 0&&(this.embeddedFonts=e.embeddedFonts),e.properties!==void 0&&(this.properties=e.properties),e.fpTexts!==void 0&&(this.fpTexts=e.fpTexts),e.fpTextBoxes!==void 0&&(this.fpTextBoxes=e.fpTextBoxes),e.fpLines!==void 0&&(this.fpLines=e.fpLines),e.fpRects!==void 0&&(this.fpRects=e.fpRects),e.fpCircles!==void 0&&(this.fpCircles=e.fpCircles),e.fpArcs!==void 0&&(this.fpArcs=e.fpArcs),e.fpPolys!==void 0&&(this.fpPolys=e.fpPolys),e.pads!==void 0&&(this.fpPads=e.pads),e.models!==void 0&&(this.models=e.models)}static fromSexprPrimitives(e){const s=new Hr,r=[],i=[];for(const h of e){if(typeof h=="string"){r.push(h);continue}if(Array.isArray(h)){i.push(h);continue}throw new Error(`footprint encountered unsupported primitive child: ${JSON.stringify(h)}`)}let a=[];r.length>0&&(s._libraryLink=r[0],a=r.slice(1));const{propertyMap:l,arrayPropertyMap:c}=f.parsePrimitivesToClassProperties(i,this.token);for(const h of Object.keys(l))if(!jf.has(h))throw new Error(`footprint encountered unsupported child token "${h}"`);for(const[h,d]of Object.entries(c)){if(!jf.has(h))throw new Error(`footprint encountered unsupported child token "${h}"`);if(!sm.has(h)&&d.length>1)throw new Error(`footprint does not support repeated child token "${h}"`)}if(s._sxLocked=l.locked,s._sxLocked&&!s._sxLocked.value&&(s._sxLocked=void 0),s._sxPlaced=l.placed,s._sxPlaced&&!s._sxPlaced.value&&(s._sxPlaced=void 0),s._sxLayer=l.layer,s._sxTedit=l.tedit,s._sxUuid=l.uuid,s._sxAt=l.at,s._sxXy=l.xy,s._sxAt&&s._sxXy)throw new Error("footprint cannot include both at and xy children");s._sxDescr=l.descr,s._sxTags=l.tags,s._sxPath=l.path,s._sxAutoplaceCost90=l.autoplace_cost90,s._sxAutoplaceCost180=l.autoplace_cost180,s._sxSolderMaskMargin=l.solder_mask_margin,s._sxSolderPasteMargin=l.solder_paste_margin,s._sxSolderPasteRatio=l.solder_paste_ratio,s._sxClearance=l.clearance,s._sxZoneConnect=l.zone_connect,s._sxThermalWidth=l.thermal_width,s._sxThermalGap=l.thermal_gap,s._sxAttr=l.attr,s._sxPrivateLayers=l.private_layers,s._sxNetTiePadGroups=l.net_tie_pad_groups,s._sxSheetname=l.sheetname,s._sxSheetfile=l.sheetfile,s._sxEmbeddedFonts=l.embedded_fonts,s._properties=c.property??[],s._fpTexts=c.fp_text??[],s._fpTextBoxes=c.fp_text_box??[],s._fpLines=c.fp_line??[],s._fpRects=c.fp_rect??[],s._fpCircles=c.fp_circle??[],s._fpArcs=c.fp_arc??[],s._fpPolys=c.fp_poly??[],s._fpPads=c.pad??[],s._models=c.model??[];for(const h of a){if(h==="locked"){if(s._sxLocked)throw new Error("footprint encountered duplicate locked tokens");s._sxLocked=new Ca(!0);continue}if(h==="placed"){if(s._sxPlaced)throw new Error("footprint encountered duplicate placed tokens");s._sxPlaced=new Na(!0);continue}throw new Error(`footprint encountered unsupported flag "${h}"`)}return s}get libraryLink(){return this._libraryLink}set libraryLink(e){this._libraryLink=e}get locked(){var e;return((e=this._sxLocked)==null?void 0:e.value)??!1}set locked(e){if(e===void 0){this._sxLocked=void 0;return}if(e instanceof Ca){this._sxLocked=e.value?e:void 0;return}this._sxLocked=e?new Ca(!0):void 0}get placed(){var e;return((e=this._sxPlaced)==null?void 0:e.value)??!1}set placed(e){if(e===void 0){this._sxPlaced=void 0;return}if(e instanceof Na){this._sxPlaced=e.value?e:void 0;return}this._sxPlaced=e?new Na(!0):void 0}get layer(){return this._sxLayer}set layer(e){if(e===void 0){this._sxLayer=void 0;return}if(e instanceof ce)this._sxLayer=e;else{const s=Array.isArray(e)?e:[e];this._sxLayer=new ce(s)}}get tedit(){return this._sxTedit}set tedit(e){if(e===void 0){this._sxTedit=void 0;return}this._sxTedit=e instanceof Nd?e:new Nd(e)}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}get position(){return this._sxAt??this._sxXy}set position(e){if(e===void 0){this._sxAt=void 0,this._sxXy=void 0;return}if(e instanceof et){this._sxXy=e,this._sxAt=void 0;return}this._sxAt=he.from(e),this._sxXy=void 0}get descr(){return this._sxDescr}set descr(e){if(e===void 0){this._sxDescr=void 0;return}this._sxDescr=e instanceof wd?e:new wd(e)}get tags(){return this._sxTags}set tags(e){if(e===void 0){this._sxTags=void 0;return}if(e instanceof Cd){this._sxTags=e;return}const s=Array.isArray(e)?e.join(" "):e;this._sxTags=new Cd(s)}get path(){return this._sxPath}set path(e){if(e===void 0){this._sxPath=void 0;return}this._sxPath=e instanceof kd?e:new kd(e)}get autoplaceCost90(){return this._sxAutoplaceCost90}set autoplaceCost90(e){if(e===void 0){this._sxAutoplaceCost90=void 0;return}this._sxAutoplaceCost90=e instanceof yd?e:new yd(e)}get autoplaceCost180(){return this._sxAutoplaceCost180}set autoplaceCost180(e){if(e===void 0){this._sxAutoplaceCost180=void 0;return}this._sxAutoplaceCost180=e instanceof xd?e:new xd(e)}get solderMaskMargin(){return this._sxSolderMaskMargin}set solderMaskMargin(e){if(e===void 0){this._sxSolderMaskMargin=void 0;return}this._sxSolderMaskMargin=e instanceof Pd?e:new Pd(e)}get solderPasteMargin(){return this._sxSolderPasteMargin}set solderPasteMargin(e){if(e===void 0){this._sxSolderPasteMargin=void 0;return}this._sxSolderPasteMargin=e instanceof Td?e:new Td(e)}get solderPasteRatio(){return this._sxSolderPasteRatio}set solderPasteRatio(e){if(e===void 0){this._sxSolderPasteRatio=void 0;return}this._sxSolderPasteRatio=e instanceof Ed?e:new Ed(e)}get clearance(){return this._sxClearance}set clearance(e){if(e===void 0){this._sxClearance=void 0;return}this._sxClearance=e instanceof vd?e:new vd(e)}get zoneConnect(){return this._sxZoneConnect}set zoneConnect(e){if(e===void 0){this._sxZoneConnect=void 0;return}this._sxZoneConnect=e instanceof Id?e:new Id(e)}get thermalWidth(){return this._sxThermalWidth}set thermalWidth(e){if(e===void 0){this._sxThermalWidth=void 0;return}this._sxThermalWidth=e instanceof Ad?e:new Ad(e)}get thermalGap(){return this._sxThermalGap}set thermalGap(e){if(e===void 0){this._sxThermalGap=void 0;return}this._sxThermalGap=e instanceof $d?e:new $d(e)}get attr(){return this._sxAttr}set attr(e){this._sxAttr=e}get privateLayers(){return this._sxPrivateLayers}set privateLayers(e){if(e===void 0){this._sxPrivateLayers=void 0;return}this._sxPrivateLayers=e instanceof Sd?e:new Sd(e)}get netTiePadGroups(){return this._sxNetTiePadGroups}set netTiePadGroups(e){if(e===void 0){this._sxNetTiePadGroups=void 0;return}this._sxNetTiePadGroups=e instanceof bd?e:new bd(e)}get sheetname(){var e;return(e=this._sxSheetname)==null?void 0:e.value}set sheetname(e){if(e===void 0){this._sxSheetname=void 0;return}this._sxSheetname=e instanceof nu?e:new nu(e)}get sheetfile(){var e;return(e=this._sxSheetfile)==null?void 0:e.value}set sheetfile(e){if(e===void 0){this._sxSheetfile=void 0;return}this._sxSheetfile=e instanceof ru?e:new ru(e)}get embeddedFonts(){return this._sxEmbeddedFonts}set embeddedFonts(e){this._sxEmbeddedFonts=e}get properties(){return[...this._properties]}set properties(e){this._properties=[...e]}get fpTexts(){return[...this._fpTexts]}set fpTexts(e){this._fpTexts=[...e]}get fpTextBoxes(){return[...this._fpTextBoxes]}set fpTextBoxes(e){this._fpTextBoxes=[...e]}get fpLines(){return[...this._fpLines]}set fpLines(e){this._fpLines=[...e]}get fpRects(){return[...this._fpRects]}set fpRects(e){this._fpRects=[...e]}get fpCircles(){return[...this._fpCircles]}set fpCircles(e){this._fpCircles=[...e]}get fpArcs(){return[...this._fpArcs]}set fpArcs(e){this._fpArcs=[...e]}get fpPolys(){return[...this._fpPolys]}set fpPolys(e){this._fpPolys=[...e]}get fpPads(){return[...this._fpPads]}set fpPads(e){this._fpPads=[...e]}get models(){return[...this._models]}set models(e){this._models=[...e]}getChildren(){const e=[];return this._sxLocked&&e.push(this._sxLocked),this._sxPlaced&&e.push(this._sxPlaced),this._sxLayer&&e.push(this._sxLayer),this._sxTedit&&e.push(this._sxTedit),this._sxUuid&&e.push(this._sxUuid),this._sxAt&&e.push(this._sxAt),this._sxXy&&e.push(this._sxXy),this._sxDescr&&e.push(this._sxDescr),this._sxTags&&e.push(this._sxTags),this._sxPath&&e.push(this._sxPath),this._sxAutoplaceCost90&&e.push(this._sxAutoplaceCost90),this._sxAutoplaceCost180&&e.push(this._sxAutoplaceCost180),this._sxSolderMaskMargin&&e.push(this._sxSolderMaskMargin),this._sxSolderPasteMargin&&e.push(this._sxSolderPasteMargin),this._sxSolderPasteRatio&&e.push(this._sxSolderPasteRatio),this._sxClearance&&e.push(this._sxClearance),this._sxZoneConnect&&e.push(this._sxZoneConnect),this._sxThermalWidth&&e.push(this._sxThermalWidth),this._sxThermalGap&&e.push(this._sxThermalGap),this._sxAttr&&e.push(this._sxAttr),this._sxPrivateLayers&&e.push(this._sxPrivateLayers),this._sxNetTiePadGroups&&e.push(this._sxNetTiePadGroups),this._sxSheetname&&e.push(this._sxSheetname),this._sxSheetfile&&e.push(this._sxSheetfile),this._sxEmbeddedFonts&&e.push(this._sxEmbeddedFonts),e.push(...this._properties),e.push(...this._fpTexts),e.push(...this._fpTextBoxes),e.push(...this._fpLines),e.push(...this._fpRects),e.push(...this._fpCircles),e.push(...this._fpArcs),e.push(...this._fpPolys),e.push(...this._fpPads),e.push(...this._models),e}getString(){const e=["(footprint"];this._libraryLink!==void 0&&e.push(` ${D(this._libraryLink)}`);for(const s of this.getChildren())e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
151
|
+
`)}},o(Hr,"token","footprint"),Hr);f.register(Cp);var Xn,nm=(Xn=class extends oe{constructor(e){super(e);o(this,"token","angle")}static fromSexprPrimitives(e){const[s]=e,r=O(s);if(r===void 0)throw new Error("gr_line angle expects a numeric value");return new Xn(r)}getString(){return`(angle ${this.value})`}},o(Xn,"token","angle"),o(Xn,"parentToken","gr_line"),Xn);f.register(nm);var w0=new Set(["true","yes","1"]),bt,rm=(bt=class extends fe{constructor(e){super(e);o(this,"token","locked")}static fromSexprPrimitives(e){const[s]=e;return s===void 0?new bt(!0):typeof s=="boolean"?new bt(s):typeof s=="string"?new bt(w0.has(s.toLowerCase())):new bt(!1)}getString(){return`(locked ${this.value?"yes":"no"})`}},o(bt,"token","locked"),o(bt,"parentToken","gr_line"),bt);f.register(rm);var Bf=new Set(["start","end","angle","layer","width","stroke","uuid","locked"]),Yr,Wa=(Yr=class extends f{constructor(e={}){super();o(this,"token","gr_line");o(this,"_sxStart");o(this,"_sxEnd");o(this,"_sxAngle");o(this,"_sxLayer");o(this,"_sxWidth");o(this,"_sxStroke");o(this,"_sxUuid");o(this,"_sxLocked");e.start!==void 0&&(this.start=e.start),e.end!==void 0&&(this.end=e.end),e.angle!==void 0&&(this.angle=e.angle),e.layer!==void 0&&(this.layer=e.layer),e.width!==void 0&&(this.width=e.width),e.stroke!==void 0&&(this.stroke=e.stroke),e.uuid!==void 0&&(this.uuid=e.uuid),e.locked!==void 0&&(this.locked=e.locked)}static fromSexprPrimitives(e){const s=new Yr,{propertyMap:r,arrayPropertyMap:i}=f.parsePrimitivesToClassProperties(e,this.token),a=new Set;for(const c of Object.keys(r))Bf.has(c)||a.add(c);for(const c of Object.keys(i)){if(!Bf.has(c)){a.add(c);continue}if(i[c].length>1)throw new Error(`gr_line does not support repeated child tokens: ${c}`)}if(a.size>0)throw new Error(`Unsupported child tokens inside gr_line expression: ${[...a].join(", ")}`);for(const c of e)if(!Array.isArray(c))throw new Error(`gr_line encountered unexpected primitive child: ${JSON.stringify(c)}`);s._sxStart=r.start,s._sxEnd=r.end,s._sxAngle=r.angle,s._sxLayer=r.layer,s._sxWidth=r.width,s._sxStroke=r.stroke;const l=r.locked;if(s._sxLocked=l&&l.value?l:void 0,s._sxUuid=r.uuid,!s._sxStart)throw new Error("gr_line requires a start child token");if(!s._sxEnd)throw new Error("gr_line requires an end child token");if(!s._sxLayer)throw new Error("gr_line requires a layer child token");return s}get start(){return this._sxStart}set start(e){this._sxStart=this.normalizeStart(e)}get end(){return this._sxEnd}set end(e){this._sxEnd=this.normalizeEnd(e)}get startPoint(){var e;return(e=this._sxStart)==null?void 0:e.toObject()}get endPoint(){var e;return(e=this._sxEnd)==null?void 0:e.toObject()}get angle(){var e;return(e=this._sxAngle)==null?void 0:e.value}set angle(e){if(e===void 0){this._sxAngle=void 0;return}this._sxAngle=new nm(e)}get layer(){return this._sxLayer}set layer(e){if(e===void 0){this._sxLayer=void 0;return}if(e instanceof ce){this._sxLayer=e;return}const s=Array.isArray(e)?e:[e];this._sxLayer=new ce(s)}get width(){var e;return(e=this._sxWidth)==null?void 0:e.value}set width(e){if(e===void 0){this._sxWidth=void 0;return}this._sxWidth=e instanceof de?e:new de(e)}get widthClass(){return this._sxWidth}set widthClass(e){this._sxWidth=e}get stroke(){return this._sxStroke}set stroke(e){this._sxStroke=e}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}get locked(){var e;return((e=this._sxLocked)==null?void 0:e.value)??!1}set locked(e){this._sxLocked=e?new rm(!0):void 0}getChildren(){const e=[];return this._sxStart&&e.push(this._sxStart),this._sxEnd&&e.push(this._sxEnd),this._sxAngle&&e.push(this._sxAngle),this._sxStroke&&e.push(this._sxStroke),this._sxWidth&&e.push(this._sxWidth),this._sxLocked&&e.push(this._sxLocked),this._sxLayer&&e.push(this._sxLayer),this._sxUuid&&e.push(this._sxUuid),e}normalizeStart(e){if(e!==void 0)return e instanceof zi?e:new zi(e.x,e.y)}normalizeEnd(e){if(e!==void 0)return e instanceof Fi?e:new Fi(e.x,e.y)}},o(Yr,"token","gr_line"),Yr);f.register(Wa);var Df=new Set(["at","xy","layer","uuid","effects"]),Xr,Np=(Xr=class extends f{constructor(e={}){super();o(this,"token","gr_text");o(this,"_text","");o(this,"_sxPosition");o(this,"_sxLayer");o(this,"_sxUuid");o(this,"_sxEffects");typeof e=="string"?this.text=e:(e.text!==void 0&&(this.text=e.text),e.position!==void 0&&(this.position=e.position),e.layer!==void 0&&(this.layer=e.layer),e.uuid!==void 0&&(this.uuid=e.uuid),e.effects!==void 0&&(this.effects=e.effects))}static fromSexprPrimitives(e){if(e.length===0)throw new Error("gr_text requires a text argument");const[s,...r]=e,i=F(s);if(i===void 0)throw new Error("gr_text text must be a string value");const a=new Xr(i),{propertyMap:l,arrayPropertyMap:c}=f.parsePrimitivesToClassProperties(r,this.token),h=new Set;for(const u of Object.keys(l))Df.has(u)||h.add(u);for(const u of Object.keys(c)){if(!Df.has(u)){h.add(u);continue}if(c[u].length>1)throw new Error(`gr_text does not support repeated child tokens: ${u}`)}if(h.size>0)throw new Error(`Unsupported child tokens inside gr_text expression: ${[...h].join(", ")}`);for(const u of r)if(!Array.isArray(u))throw new Error(`gr_text encountered unexpected primitive child: ${JSON.stringify(u)}`);const d=l.at,p=l.xy;if(d&&p)throw new Error("gr_text cannot include both at and xy tokens");if(a._sxPosition=d??p,a._sxLayer=l.layer,a._sxUuid=l.uuid,a._sxEffects=l.effects,!a._sxPosition)throw new Error("gr_text requires a position child token");if(!a._sxLayer)throw new Error("gr_text requires a layer child token");if(!a._sxUuid)throw new Error("gr_text requires a uuid child token");if(!a._sxEffects)throw new Error("gr_text requires an effects child token");return a}get text(){return this._text}set text(e){this._text=e}get position(){return this._sxPosition}set position(e){if(e===void 0){this._sxPosition=void 0;return}if(e instanceof et){this._sxPosition=e;return}if(typeof e=="object"&&"x"in e&&"y"in e&&!Array.isArray(e)&&!(e instanceof he)){const{x:s,y:r,angle:i}=e;i!==void 0?this._sxPosition=new he([s,r,i]):this._sxPosition=new et(s,r);return}this._sxPosition=he.from(e)}get layer(){return this._sxLayer}set layer(e){if(e===void 0){this._sxLayer=void 0;return}if(e instanceof ce){this._sxLayer=e;return}const s=Array.isArray(e)?e:[e];this._sxLayer=new ce(s)}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}get effects(){return this._sxEffects}set effects(e){this._sxEffects=e}getChildren(){const e=[];return this._sxPosition&&e.push(this._sxPosition),this._sxLayer&&e.push(this._sxLayer),this._sxUuid&&e.push(this._sxUuid),this._sxEffects&&e.push(this._sxEffects),e}getString(){const e=["(gr_text",` ${D(this._text)}`];for(const s of this.getChildren())e.push(s.getStringIndented());return e.push(")"),e.join(`
|
|
152
|
+
`)}},o(Xr,"token","gr_text"),Xr);f.register(Np);var qn,au=(qn=class extends f{constructor(e,s){super();o(this,"token","end");o(this,"_x");o(this,"_y");this._x=e,this._y=s}static fromSexprPrimitives(e){const[s,r]=e,i=O(s),a=O(r);if(i===void 0||a===void 0)throw new Error("end expects two numeric arguments");return new qn(i,a)}get x(){return this._x}set x(e){this._x=e}get y(){return this._y}set y(e){this._y=e}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(end ${this._x} ${this._y})`}},o(qn,"token","end"),o(qn,"parentToken","segment"),qn);f.register(au);var b0=new Set(["true","yes","1"]),It,im=(It=class extends fe{constructor(e){super(e);o(this,"token","locked")}static fromSexprPrimitives(e){const[s]=e;return typeof s=="boolean"?new It(s):typeof s=="string"?new It(b0.has(s.toLowerCase())):new It(!1)}getString(){return`(locked ${this.value?"yes":"no"})`}},o(It,"token","locked"),o(It,"parentToken","segment"),It);f.register(im);var Kn,Ga=(Kn=class extends f{constructor(e,s){super();o(this,"token","net");o(this,"_id");o(this,"_name");this._id=e,this._name=s}static fromSexprPrimitives(e){const[s,r]=e,i=O(s);if(i===void 0)throw new Error("net expects a numeric identifier");const a=r===void 0?void 0:F(r);return new Kn(i,a??void 0)}get id(){return this._id}set id(e){this._id=e}get name(){return this._name}set name(e){this._name=e===""?void 0:e}toObject(){return this._name===void 0?{id:this._id}:{id:this._id,name:this._name}}getChildren(){return[]}getString(){const e=this._name?` ${D(this._name)}`:"";return`(net ${this._id}${e})`}},o(Kn,"token","net"),o(Kn,"parentToken","segment"),Kn);f.register(Ga);var Jn,cu=(Jn=class extends f{constructor(e,s){super();o(this,"token","start");o(this,"_x");o(this,"_y");this._x=e,this._y=s}static fromSexprPrimitives(e){const[s,r]=e,i=O(s),a=O(r);if(i===void 0||a===void 0)throw new Error("start expects two numeric arguments");return new Jn(i,a)}get x(){return this._x}set x(e){this._x=e}get y(){return this._y}set y(e){this._y=e}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(start ${this._x} ${this._y})`}},o(Jn,"token","start"),o(Jn,"parentToken","segment"),Jn);f.register(cu);var Wf=new Set(["start","end","width","layer","net","uuid","locked"]),qr,$p=(qr=class extends f{constructor(e={}){super();o(this,"token","segment");o(this,"_sxStart");o(this,"_sxEnd");o(this,"_sxWidth");o(this,"_sxLayer");o(this,"_sxNet");o(this,"_sxUuid");o(this,"_sxLocked");e.start!==void 0&&(this.start=e.start),e.end!==void 0&&(this.end=e.end),e.width!==void 0&&(this.width=e.width),e.layer!==void 0&&(this.layer=e.layer),e.net!==void 0&&(this.net=e.net),e.uuid!==void 0&&(this.uuid=e.uuid),e.locked!==void 0&&(this.locked=e.locked)}static fromSexprPrimitives(e){var c,h,d,p,u,g,_;const s=new qr,{propertyMap:r,arrayPropertyMap:i}=f.parsePrimitivesToClassProperties(e,this.token),a=Object.keys(r).filter(x=>!Wf.has(x));if(a.length>0)throw new Error(`Unsupported child tokens inside segment expression: ${a.join(", ")}`);for(const[x,v]of Object.entries(i)){if(!Wf.has(x))throw new Error(`Unsupported child tokens inside segment expression: ${x}`);if(v.length>1)throw new Error(`Segment does not support repeated child tokens: ${x}`)}s._sxStart=((c=i.start)==null?void 0:c[0])??r.start,s._sxEnd=((h=i.end)==null?void 0:h[0])??r.end,s._sxWidth=((d=i.width)==null?void 0:d[0])??r.width,s._sxLayer=((p=i.layer)==null?void 0:p[0])??r.layer,s._sxNet=((u=i.net)==null?void 0:u[0])??r.net;const l=((g=i.locked)==null?void 0:g[0])??r.locked;return s._sxLocked=l&&l.value?l:void 0,s._sxUuid=((_=i.uuid)==null?void 0:_[0])??r.uuid,s}get start(){return this._sxStart}set start(e){this._sxStart=this.normalizeStart(e)}get end(){return this._sxEnd}set end(e){this._sxEnd=this.normalizeEnd(e)}get startPoint(){var e;return(e=this._sxStart)==null?void 0:e.toObject()}get endPoint(){var e;return(e=this._sxEnd)==null?void 0:e.toObject()}get width(){var e;return(e=this._sxWidth)==null?void 0:e.value}set width(e){if(e===void 0){this._sxWidth=void 0;return}this._sxWidth=e instanceof de?e:new de(e)}get widthClass(){return this._sxWidth}set widthClass(e){this._sxWidth=e}get layer(){return this._sxLayer}set layer(e){if(e===void 0){this._sxLayer=void 0;return}if(e instanceof ce){this._sxLayer=e;return}const s=Array.isArray(e)?e:[e];this._sxLayer=new ce(s)}get net(){return this._sxNet}set net(e){if(e===void 0){this._sxNet=void 0;return}if(e instanceof Ga){this._sxNet=e;return}this._sxNet=new Ga(e.id,e.name)}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}get locked(){var e;return((e=this._sxLocked)==null?void 0:e.value)??!1}set locked(e){this._sxLocked=e?new im(!0):void 0}getChildren(){const e=[];return this._sxStart&&e.push(this._sxStart),this._sxEnd&&e.push(this._sxEnd),this._sxWidth&&e.push(this._sxWidth),this._sxLayer&&e.push(this._sxLayer),this._sxNet&&e.push(this._sxNet),this._sxLocked&&e.push(this._sxLocked),this._sxUuid&&e.push(this._sxUuid),e}normalizeStart(e){if(e!==void 0)return e instanceof cu?e:new cu(e.x,e.y)}normalizeEnd(e){if(e!==void 0)return e instanceof au?e:new au(e.x,e.y)}},o(qr,"token","segment"),qr);f.register($p);var Kr,om=(Kr=class extends f{constructor(){super(...arguments);o(this,"token","zone");o(this,"_rawChildren",[])}static fromSexprPrimitives(e){const s=new Kr;return s._rawChildren=[...e],s}get rawChildren(){return[...this._rawChildren]}set rawChildren(e){this._rawChildren=[...e]}getChildren(){return[]}getString(){const e=["(zone"];for(const s of this._rawChildren)e.push(` ${Ie(s)}`);return e.push(")"),e.join(`
|
|
153
|
+
`)}},o(Kr,"token","zone"),Kr);f.register(om);var Jr,$a=(Jr=class extends f{constructor(e=[]){super();o(this,"token","layers");o(this,"_names",[]);this.names=e}static fromSexprPrimitives(e){const s=e.map(r=>typeof r=="string"||typeof r=="number"?String(r):Ie(r));return new Jr(s)}get names(){return[...this._names]}set names(e){this._names=e.map(s=>String(s))}getString(){return`(layers ${this._names.map(s=>/^[^\s()"]+$/u.test(s)&&!["nil","#t","#f"].includes(s)?s:D(s)).join(" ")})`}},o(Jr,"token","layers"),Jr);f.register($a);var po=class extends f{constructor(t){super();o(this,"_value");o(this,"quoteStringValue",!1);this._value=t}static fromSexprPrimitives(t){const[e]=t,s=this.parsePrimitiveValue(e),r=this;return new r(s)}static parsePrimitiveValue(t){const e=F(t);if(e===void 0)throw new Error(`${this.name} expects a primitive value`);return e}get value(){return this._value}set value(t){this._value=t}getChildren(){return[]}formatValue(){return typeof this._value=="string"?this.quoteStringValue?D(this._value):this._value:`${this._value}`}getString(){return`(${this.token} ${this.formatValue()})`}},k0=class extends f{constructor(t){super();o(this,"_values");this._values=t}static fromSexprPrimitives(t){const e=t.map(r=>{const i=O(r);if(i===void 0)throw new Error(`${this.name} expects numeric primitives but received ${r}`);return i}),s=this;return new s(e)}get values(){return[...this._values]}set values(t){this._values=[...t]}getChildren(){return[]}getString(){return`(${this.token} ${this._values.join(" ")})`}},S0=class extends f{constructor(t,e){super();o(this,"_x");o(this,"_y");this._x=t,this._y=e}static fromSexprPrimitives(t){const[e,s]=t,r=O(e),i=O(s);if(r===void 0||i===void 0)throw new Error(`${this.name} expects two numeric values`);const a=this;return new a(r,i)}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})`}},Zc,se=(Zc=class extends po{},o(Zc,"parentToken","pcbplotparams"),Zc),ht=class extends se{static parsePrimitiveValue(n){const t=O(n);if(t===void 0)throw new Error(`pcbplotparams ${this.token} expects a numeric value`);return t}},Qc,am=(Qc=class extends se{constructor(){super(...arguments);o(this,"token","layerselection")}},o(Qc,"token","layerselection"),Qc);f.register(am);var el,cm=(el=class extends se{constructor(){super(...arguments);o(this,"token","plot_on_all_layers_selection")}},o(el,"token","plot_on_all_layers_selection"),el);f.register(cm);var tl,lm=(tl=class extends ht{constructor(){super(...arguments);o(this,"token","dashed_line_dash_ratio")}},o(tl,"token","dashed_line_dash_ratio"),tl);f.register(lm);var sl,hm=(sl=class extends ht{constructor(){super(...arguments);o(this,"token","dashed_line_gap_ratio")}},o(sl,"token","dashed_line_gap_ratio"),sl);f.register(hm);var nl,dm=(nl=class extends ht{constructor(){super(...arguments);o(this,"token","svgprecision")}},o(nl,"token","svgprecision"),nl);f.register(dm);var rl,um=(rl=class extends ht{constructor(){super(...arguments);o(this,"token","linewidth")}},o(rl,"token","linewidth"),rl);f.register(um);var il,pm=(il=class extends ht{constructor(){super(...arguments);o(this,"token","mode")}},o(il,"token","mode"),il);f.register(pm);var ol,fm=(ol=class extends ht{constructor(){super(...arguments);o(this,"token","hpglpennumber")}},o(ol,"token","hpglpennumber"),ol);f.register(fm);var al,gm=(al=class extends ht{constructor(){super(...arguments);o(this,"token","hpglpenspeed")}},o(al,"token","hpglpenspeed"),al);f.register(gm);var cl,_m=(cl=class extends ht{constructor(){super(...arguments);o(this,"token","hpglpendiameter")}},o(cl,"token","hpglpendiameter"),cl);f.register(_m);var ll,mm=(ll=class extends ht{constructor(){super(...arguments);o(this,"token","hpglpenoverlay")}},o(ll,"token","hpglpenoverlay"),ll);f.register(mm);var hl,xm=(hl=class extends ht{constructor(){super(...arguments);o(this,"token","outputformat")}},o(hl,"token","outputformat"),hl);f.register(xm);var dl,ym=(dl=class extends ht{constructor(){super(...arguments);o(this,"token","drillshape")}},o(dl,"token","drillshape"),dl);f.register(ym);var ul,vm=(ul=class extends ht{constructor(){super(...arguments);o(this,"token","scaleselection")}},o(ul,"token","scaleselection"),ul);f.register(vm);var pl,wm=(pl=class extends se{constructor(){super(...arguments);o(this,"token","disableapertmacros")}},o(pl,"token","disableapertmacros"),pl);f.register(wm);var fl,bm=(fl=class extends se{constructor(){super(...arguments);o(this,"token","usegerberextensions")}},o(fl,"token","usegerberextensions"),fl);f.register(bm);var gl,km=(gl=class extends se{constructor(){super(...arguments);o(this,"token","usegerberattributes")}},o(gl,"token","usegerberattributes"),gl);f.register(km);var _l,Sm=(_l=class extends se{constructor(){super(...arguments);o(this,"token","usegerberadvancedattributes")}},o(_l,"token","usegerberadvancedattributes"),_l);f.register(Sm);var ml,Pm=(ml=class extends se{constructor(){super(...arguments);o(this,"token","creategerberjobfile")}},o(ml,"token","creategerberjobfile"),ml);f.register(Pm);var xl,Tm=(xl=class extends se{constructor(){super(...arguments);o(this,"token","excludeedgelayer")}},o(xl,"token","excludeedgelayer"),xl);f.register(Tm);var yl,Em=(yl=class extends se{constructor(){super(...arguments);o(this,"token","plotframeref")}},o(yl,"token","plotframeref"),yl);f.register(Em);var vl,Cm=(vl=class extends se{constructor(){super(...arguments);o(this,"token","viasonmask")}},o(vl,"token","viasonmask"),vl);f.register(Cm);var wl,Nm=(wl=class extends se{constructor(){super(...arguments);o(this,"token","useauxorigin")}},o(wl,"token","useauxorigin"),wl);f.register(Nm);var bl,$m=(bl=class extends se{constructor(){super(...arguments);o(this,"token","pdf_front_fp_property_popups")}},o(bl,"token","pdf_front_fp_property_popups"),bl);f.register($m);var kl,Am=(kl=class extends se{constructor(){super(...arguments);o(this,"token","pdf_back_fp_property_popups")}},o(kl,"token","pdf_back_fp_property_popups"),kl);f.register(Am);var Sl,Im=(Sl=class extends se{constructor(){super(...arguments);o(this,"token","pdf_metadata")}},o(Sl,"token","pdf_metadata"),Sl);f.register(Im);var Pl,Lm=(Pl=class extends se{constructor(){super(...arguments);o(this,"token","pdf_single_document")}},o(Pl,"token","pdf_single_document"),Pl);f.register(Lm);var Tl,Mm=(Tl=class extends se{constructor(){super(...arguments);o(this,"token","dxfpolygonmode")}},o(Tl,"token","dxfpolygonmode"),Tl);f.register(Mm);var El,Rm=(El=class extends se{constructor(){super(...arguments);o(this,"token","dxfimperialunits")}},o(El,"token","dxfimperialunits"),El);f.register(Rm);var Cl,Om=(Cl=class extends se{constructor(){super(...arguments);o(this,"token","dxfusepcbnewfont")}},o(Cl,"token","dxfusepcbnewfont"),Cl);f.register(Om);var Nl,Fm=(Nl=class extends se{constructor(){super(...arguments);o(this,"token","psnegative")}},o(Nl,"token","psnegative"),Nl);f.register(Fm);var $l,zm=($l=class extends se{constructor(){super(...arguments);o(this,"token","psa4output")}},o($l,"token","psa4output"),$l);f.register(zm);var Al,Um=(Al=class extends se{constructor(){super(...arguments);o(this,"token","plotreference")}},o(Al,"token","plotreference"),Al);f.register(Um);var Il,jm=(Il=class extends se{constructor(){super(...arguments);o(this,"token","plotvalue")}},o(Il,"token","plotvalue"),Il);f.register(jm);var Ll,Bm=(Ll=class extends se{constructor(){super(...arguments);o(this,"token","plotothertext")}},o(Ll,"token","plotothertext"),Ll);f.register(Bm);var Ml,Dm=(Ml=class extends se{constructor(){super(...arguments);o(this,"token","plotinvisibletext")}},o(Ml,"token","plotinvisibletext"),Ml);f.register(Dm);var Rl,Wm=(Rl=class extends se{constructor(){super(...arguments);o(this,"token","padsonsilk")}},o(Rl,"token","padsonsilk"),Rl);f.register(Wm);var Ol,Gm=(Ol=class extends se{constructor(){super(...arguments);o(this,"token","sketchpadsonfab")}},o(Ol,"token","sketchpadsonfab"),Ol);f.register(Gm);var Fl,Vm=(Fl=class extends se{constructor(){super(...arguments);o(this,"token","plotpadnumbers")}},o(Fl,"token","plotpadnumbers"),Fl);f.register(Vm);var zl,Hm=(zl=class extends se{constructor(){super(...arguments);o(this,"token","hidednponfab")}},o(zl,"token","hidednponfab"),zl);f.register(Hm);var Ul,Ym=(Ul=class extends se{constructor(){super(...arguments);o(this,"token","sketchdnponfab")}},o(Ul,"token","sketchdnponfab"),Ul);f.register(Ym);var jl,Xm=(jl=class extends se{constructor(){super(...arguments);o(this,"token","crossoutdnponfab")}},o(jl,"token","crossoutdnponfab"),jl);f.register(Xm);var Bl,qm=(Bl=class extends se{constructor(){super(...arguments);o(this,"token","subtractmaskfromsilk")}},o(Bl,"token","subtractmaskfromsilk"),Bl);f.register(qm);var Dl,Km=(Dl=class extends se{constructor(){super(...arguments);o(this,"token","plot_black_and_white")}},o(Dl,"token","plot_black_and_white"),Dl);f.register(Km);var Wl,Jm=(Wl=class extends se{constructor(){super(...arguments);o(this,"token","mirror")}},o(Wl,"token","mirror"),Wl);f.register(Jm);var Gl,Zm=(Gl=class extends se{constructor(){super(...arguments);o(this,"token","outputdirectory");o(this,"quoteStringValue",!0)}},o(Gl,"token","outputdirectory"),Gl);f.register(Zm);var Vl,Qm=(Vl=class extends se{constructor(){super(...arguments);o(this,"token","plot_on_all_layers")}},o(Vl,"token","plot_on_all_layers"),Vl);f.register(Qm);var Hl,ex=(Hl=class extends se{constructor(){super(...arguments);o(this,"token","plotinvisible")}},o(Hl,"token","plotinvisible"),Hl);f.register(ex);var P0={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"},T0=["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"],Zn,lu=(Zn=class extends f{constructor(){super(...arguments);o(this,"token","pcbplotparams");o(this,"_properties",{})}static fromSexprPrimitives(e){const s=new Zn,{propertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);for(const[i,a]of Object.entries(r)){const l=P0[i];if(!l)throw new Error(`Unsupported pcbplotparams token: ${i}`);s._properties[l]=a}return s}getChildren(){const e=[];for(const s of T0){const r=this._properties[s];r&&e.push(r)}return e}clearProperty(e){delete this._properties[e]}setStringProperty(e,s,r){if(s===void 0){this.clearProperty(e);return}this._properties[e]=new r(s)}setNumberProperty(e,s,r){if(s===void 0){this.clearProperty(e);return}this._properties[e]=new r(s)}setStringOrNumberProperty(e,s,r){if(s===void 0){this.clearProperty(e);return}this._properties[e]=new r(s)}get layerselection(){var e;return(e=this._properties.layerselection)==null?void 0:e.value}set layerselection(e){this.setStringOrNumberProperty("layerselection",e,am)}get plot_on_all_layers_selection(){var e;return(e=this._properties.plot_on_all_layers_selection)==null?void 0:e.value}set plot_on_all_layers_selection(e){this.setStringOrNumberProperty("plot_on_all_layers_selection",e,cm)}get disableapertmacros(){var e;return(e=this._properties.disableapertmacros)==null?void 0:e.value}set disableapertmacros(e){this.setStringProperty("disableapertmacros",e,wm)}get usegerberextensions(){var e;return(e=this._properties.usegerberextensions)==null?void 0:e.value}set usegerberextensions(e){this.setStringProperty("usegerberextensions",e,bm)}get usegerberattributes(){var e;return(e=this._properties.usegerberattributes)==null?void 0:e.value}set usegerberattributes(e){this.setStringProperty("usegerberattributes",e,km)}get usegerberadvancedattributes(){var e;return(e=this._properties.usegerberadvancedattributes)==null?void 0:e.value}set usegerberadvancedattributes(e){this.setStringProperty("usegerberadvancedattributes",e,Sm)}get creategerberjobfile(){var e;return(e=this._properties.creategerberjobfile)==null?void 0:e.value}set creategerberjobfile(e){this.setStringProperty("creategerberjobfile",e,Pm)}get excludeedgelayer(){var e;return(e=this._properties.excludeedgelayer)==null?void 0:e.value}set excludeedgelayer(e){this.setStringProperty("excludeedgelayer",e,Tm)}get dashed_line_dash_ratio(){var e;return(e=this._properties.dashed_line_dash_ratio)==null?void 0:e.value}set dashed_line_dash_ratio(e){this.setNumberProperty("dashed_line_dash_ratio",e,lm)}get dashed_line_gap_ratio(){var e;return(e=this._properties.dashed_line_gap_ratio)==null?void 0:e.value}set dashed_line_gap_ratio(e){this.setNumberProperty("dashed_line_gap_ratio",e,hm)}get svgprecision(){var e;return(e=this._properties.svgprecision)==null?void 0:e.value}set svgprecision(e){this.setNumberProperty("svgprecision",e,dm)}get linewidth(){var e;return(e=this._properties.linewidth)==null?void 0:e.value}set linewidth(e){this.setNumberProperty("linewidth",e,um)}get plotframeref(){var e;return(e=this._properties.plotframeref)==null?void 0:e.value}set plotframeref(e){this.setStringProperty("plotframeref",e,Em)}get plotreference(){var e;return(e=this._properties.plotreference)==null?void 0:e.value}set plotreference(e){this.setStringProperty("plotreference",e,Um)}get plotvalue(){var e;return(e=this._properties.plotvalue)==null?void 0:e.value}set plotvalue(e){this.setStringProperty("plotvalue",e,jm)}get plotothertext(){var e;return(e=this._properties.plotothertext)==null?void 0:e.value}set plotothertext(e){this.setStringProperty("plotothertext",e,Bm)}get plotinvisibletext(){var e;return(e=this._properties.plotinvisibletext)==null?void 0:e.value}set plotinvisibletext(e){this.setStringProperty("plotinvisibletext",e,Dm)}get padsonsilk(){var e;return(e=this._properties.padsonsilk)==null?void 0:e.value}set padsonsilk(e){this.setStringProperty("padsonsilk",e,Wm)}get plotpadnumbers(){var e;return(e=this._properties.plotpadnumbers)==null?void 0:e.value}set plotpadnumbers(e){this.setStringProperty("plotpadnumbers",e,Vm)}get sketchpadsonfab(){var e;return(e=this._properties.sketchpadsonfab)==null?void 0:e.value}set sketchpadsonfab(e){this.setStringProperty("sketchpadsonfab",e,Gm)}get hidednponfab(){var e;return(e=this._properties.hidednponfab)==null?void 0:e.value}set hidednponfab(e){this.setStringProperty("hidednponfab",e,Hm)}get sketchdnponfab(){var e;return(e=this._properties.sketchdnponfab)==null?void 0:e.value}set sketchdnponfab(e){this.setStringProperty("sketchdnponfab",e,Ym)}get crossoutdnponfab(){var e;return(e=this._properties.crossoutdnponfab)==null?void 0:e.value}set crossoutdnponfab(e){this.setStringProperty("crossoutdnponfab",e,Xm)}get subtractmaskfromsilk(){var e;return(e=this._properties.subtractmaskfromsilk)==null?void 0:e.value}set subtractmaskfromsilk(e){this.setStringProperty("subtractmaskfromsilk",e,qm)}get plot_black_and_white(){var e;return(e=this._properties.plot_black_and_white)==null?void 0:e.value}set plot_black_and_white(e){this.setStringProperty("plot_black_and_white",e,Km)}get plot_on_all_layers(){var e;return(e=this._properties.plot_on_all_layers)==null?void 0:e.value}set plot_on_all_layers(e){this.setStringProperty("plot_on_all_layers",e,Qm)}get plotinvisible(){var e;return(e=this._properties.plotinvisible)==null?void 0:e.value}set plotinvisible(e){this.setStringProperty("plotinvisible",e,ex)}get mode(){var e;return(e=this._properties.mode)==null?void 0:e.value}set mode(e){this.setNumberProperty("mode",e,pm)}get useauxorigin(){var e;return(e=this._properties.useauxorigin)==null?void 0:e.value}set useauxorigin(e){this.setStringProperty("useauxorigin",e,Nm)}get viasonmask(){var e;return(e=this._properties.viasonmask)==null?void 0:e.value}set viasonmask(e){this.setStringProperty("viasonmask",e,Cm)}get hpglpennumber(){var e;return(e=this._properties.hpglpennumber)==null?void 0:e.value}set hpglpennumber(e){this.setNumberProperty("hpglpennumber",e,fm)}get hpglpenspeed(){var e;return(e=this._properties.hpglpenspeed)==null?void 0:e.value}set hpglpenspeed(e){this.setNumberProperty("hpglpenspeed",e,gm)}get hpglpendiameter(){var e;return(e=this._properties.hpglpendiameter)==null?void 0:e.value}set hpglpendiameter(e){this.setNumberProperty("hpglpendiameter",e,_m)}get hpglpenoverlay(){var e;return(e=this._properties.hpglpenoverlay)==null?void 0:e.value}set hpglpenoverlay(e){this.setNumberProperty("hpglpenoverlay",e,mm)}get pdf_front_fp_property_popups(){var e;return(e=this._properties.pdf_front_fp_property_popups)==null?void 0:e.value}set pdf_front_fp_property_popups(e){this.setStringProperty("pdf_front_fp_property_popups",e,$m)}get pdf_back_fp_property_popups(){var e;return(e=this._properties.pdf_back_fp_property_popups)==null?void 0:e.value}set pdf_back_fp_property_popups(e){this.setStringProperty("pdf_back_fp_property_popups",e,Am)}get pdf_metadata(){var e;return(e=this._properties.pdf_metadata)==null?void 0:e.value}set pdf_metadata(e){this.setStringProperty("pdf_metadata",e,Im)}get pdf_single_document(){var e;return(e=this._properties.pdf_single_document)==null?void 0:e.value}set pdf_single_document(e){this.setStringProperty("pdf_single_document",e,Lm)}get dxfpolygonmode(){var e;return(e=this._properties.dxfpolygonmode)==null?void 0:e.value}set dxfpolygonmode(e){this.setStringProperty("dxfpolygonmode",e,Mm)}get dxfimperialunits(){var e;return(e=this._properties.dxfimperialunits)==null?void 0:e.value}set dxfimperialunits(e){this.setStringProperty("dxfimperialunits",e,Rm)}get dxfusepcbnewfont(){var e;return(e=this._properties.dxfusepcbnewfont)==null?void 0:e.value}set dxfusepcbnewfont(e){this.setStringProperty("dxfusepcbnewfont",e,Om)}get psnegative(){var e;return(e=this._properties.psnegative)==null?void 0:e.value}set psnegative(e){this.setStringProperty("psnegative",e,Fm)}get psa4output(){var e;return(e=this._properties.psa4output)==null?void 0:e.value}set psa4output(e){this.setStringProperty("psa4output",e,zm)}get mirror(){var e;return(e=this._properties.mirror)==null?void 0:e.value}set mirror(e){this.setStringProperty("mirror",e,Jm)}get outputformat(){var e;return(e=this._properties.outputformat)==null?void 0:e.value}set outputformat(e){this.setNumberProperty("outputformat",e,xm)}get drillshape(){var e;return(e=this._properties.drillshape)==null?void 0:e.value}set drillshape(e){this.setNumberProperty("drillshape",e,ym)}get scaleselection(){var e;return(e=this._properties.scaleselection)==null?void 0:e.value}set scaleselection(e){this.setNumberProperty("scaleselection",e,vm)}get outputdirectory(){var e;return(e=this._properties.outputdirectory)==null?void 0:e.value}set outputdirectory(e){this.setStringProperty("outputdirectory",e,Zm)}},o(Zn,"token","pcbplotparams"),o(Zn,"parentToken","setup"),Zn);f.register(lu);var Yl,fc=(Yl=class extends po{},o(Yl,"parentToken","setup"),Yl),Xl,hu=(Xl=class extends fc{constructor(){super(...arguments);o(this,"token","zone_45_only")}},o(Xl,"token","zone_45_only"),Xl);f.register(hu);var ql,du=(ql=class extends fc{constructor(){super(...arguments);o(this,"token","allow_soldermask_bridges_in_footprints")}},o(ql,"token","allow_soldermask_bridges_in_footprints"),ql);f.register(du);var Kl,uu=(Kl=class extends fc{constructor(){super(...arguments);o(this,"token","visible_elements")}},o(Kl,"token","visible_elements"),Kl);f.register(uu);var Jl,pu=(Jl=class extends fc{constructor(){super(...arguments);o(this,"token","uvias_allowed")}},o(Jl,"token","uvias_allowed"),Jl);f.register(pu);var Qn,fu=(Qn=class extends f{constructor(e=[]){super();o(this,"token","tenting");o(this,"_sides",[]);this.sides=e}static fromSexprPrimitives(e){const s=e.map(r=>F(r)).filter(r=>r!==void 0);return new Qn(s)}get sides(){return[...this._sides]}set sides(e){this._sides=e.map(s=>String(s))}getChildren(){return[]}getString(){return this._sides.length===0?"(tenting)":`(tenting ${this._sides.join(" ")})`}},o(Qn,"token","tenting"),o(Qn,"parentToken","setup"),Qn);f.register(fu);var Zl,fo=(Zl=class extends k0{},o(Zl,"parentToken","setup"),Zl),Ql,tx=(Ql=class extends S0{},o(Ql,"parentToken","setup"),Ql),eh,gu=(eh=class extends fo{constructor(){super(...arguments);o(this,"token","pcb_text_size")}},o(eh,"token","pcb_text_size"),eh);f.register(gu);var th,_u=(th=class extends fo{constructor(){super(...arguments);o(this,"token","mod_text_size")}},o(th,"token","mod_text_size"),th);f.register(_u);var sh,mu=(sh=class extends fo{constructor(){super(...arguments);o(this,"token","pad_size")}},o(sh,"token","pad_size"),sh);f.register(mu);var nh,xu=(nh=class extends fo{constructor(){super(...arguments);o(this,"token","pad_to_paste_clearance_values")}},o(nh,"token","pad_to_paste_clearance_values"),nh);f.register(xu);var rh,yu=(rh=class extends fo{constructor(){super(...arguments);o(this,"token","trace_width")}},o(rh,"token","trace_width"),rh);f.register(yu);var ih,vu=(ih=class extends tx{constructor(){super(...arguments);o(this,"token","aux_axis_origin")}},o(ih,"token","aux_axis_origin"),ih);f.register(vu);var oh,wu=(oh=class extends tx{constructor(){super(...arguments);o(this,"token","grid_origin")}},o(oh,"token","grid_origin"),oh);f.register(wu);var ah,me=(ah=class extends po{static parsePrimitiveValue(n){const t=O(n);if(t===void 0)throw new Error(`${this.name} expects a numeric value`);return t}},o(ah,"parentToken","setup"),ah),ch,bu=(ch=class extends me{constructor(){super(...arguments);o(this,"token","pad_to_mask_clearance")}},o(ch,"token","pad_to_mask_clearance"),ch);f.register(bu);var lh,ku=(lh=class extends me{constructor(){super(...arguments);o(this,"token","solder_mask_min_width")}},o(lh,"token","solder_mask_min_width"),lh);f.register(ku);var hh,Su=(hh=class extends me{constructor(){super(...arguments);o(this,"token","pad_to_paste_clearance")}},o(hh,"token","pad_to_paste_clearance"),hh);f.register(Su);var dh,Pu=(dh=class extends me{constructor(){super(...arguments);o(this,"token","pad_to_paste_clearance_ratio")}},o(dh,"token","pad_to_paste_clearance_ratio"),dh);f.register(Pu);var uh,Tu=(uh=class extends me{constructor(){super(...arguments);o(this,"token","last_trace_width")}},o(uh,"token","last_trace_width"),uh);f.register(Tu);var ph,Eu=(ph=class extends me{constructor(){super(...arguments);o(this,"token","trace_clearance")}},o(ph,"token","trace_clearance"),ph);f.register(Eu);var fh,Cu=(fh=class extends me{constructor(){super(...arguments);o(this,"token","zone_clearance")}},o(fh,"token","zone_clearance"),fh);f.register(Cu);var gh,Nu=(gh=class extends me{constructor(){super(...arguments);o(this,"token","trace_min")}},o(gh,"token","trace_min"),gh);f.register(Nu);var _h,$u=(_h=class extends me{constructor(){super(...arguments);o(this,"token","segment_width")}},o(_h,"token","segment_width"),_h);f.register($u);var mh,Au=(mh=class extends me{constructor(){super(...arguments);o(this,"token","edge_width")}},o(mh,"token","edge_width"),mh);f.register(Au);var xh,Iu=(xh=class extends me{constructor(){super(...arguments);o(this,"token","via_size")}},o(xh,"token","via_size"),xh);f.register(Iu);var yh,Lu=(yh=class extends me{constructor(){super(...arguments);o(this,"token","via_drill")}},o(yh,"token","via_drill"),yh);f.register(Lu);var vh,Mu=(vh=class extends me{constructor(){super(...arguments);o(this,"token","via_min_size")}},o(vh,"token","via_min_size"),vh);f.register(Mu);var wh,Ru=(wh=class extends me{constructor(){super(...arguments);o(this,"token","via_min_drill")}},o(wh,"token","via_min_drill"),wh);f.register(Ru);var bh,Ou=(bh=class extends me{constructor(){super(...arguments);o(this,"token","uvia_size")}},o(bh,"token","uvia_size"),bh);f.register(Ou);var kh,Fu=(kh=class extends me{constructor(){super(...arguments);o(this,"token","uvia_drill")}},o(kh,"token","uvia_drill"),kh);f.register(Fu);var Sh,zu=(Sh=class extends me{constructor(){super(...arguments);o(this,"token","uvia_min_size")}},o(Sh,"token","uvia_min_size"),Sh);f.register(zu);var Ph,Uu=(Ph=class extends me{constructor(){super(...arguments);o(this,"token","uvia_min_drill")}},o(Ph,"token","uvia_min_drill"),Ph);f.register(Uu);var Th,ju=(Th=class extends me{constructor(){super(...arguments);o(this,"token","pcb_text_width")}},o(Th,"token","pcb_text_width"),Th);f.register(ju);var Eh,Bu=(Eh=class extends me{constructor(){super(...arguments);o(this,"token","mod_edge_width")}},o(Eh,"token","mod_edge_width"),Eh);f.register(Bu);var Ch,Du=(Ch=class extends me{constructor(){super(...arguments);o(this,"token","mod_text_width")}},o(Ch,"token","mod_text_width"),Ch);f.register(Du);var Nh,Wu=(Nh=class extends me{constructor(){super(...arguments);o(this,"token","pad_drill")}},o(Nh,"token","pad_drill"),Nh);f.register(Wu);var $h,go=($h=class extends po{},o($h,"parentToken","stackup"),$h),Ah,sx=(Ah=class extends go{constructor(){super(...arguments);o(this,"token","copper_finish");o(this,"quoteStringValue",!0)}},o(Ah,"token","copper_finish"),Ah);f.register(sx);var Ih,nx=(Ih=class extends go{constructor(){super(...arguments);o(this,"token","dielectric_constraints")}},o(Ih,"token","dielectric_constraints"),Ih);f.register(nx);var Lh,rx=(Lh=class extends go{constructor(){super(...arguments);o(this,"token","edge_connector")}},o(Lh,"token","edge_connector"),Lh);f.register(rx);var Mh,ix=(Mh=class extends go{constructor(){super(...arguments);o(this,"token","castellated_pads")}},o(Mh,"token","castellated_pads"),Mh);f.register(ix);var Rh,ox=(Rh=class extends go{constructor(){super(...arguments);o(this,"token","edge_plating")}},o(Rh,"token","edge_plating"),Rh);f.register(ox);var Oh,wi=(Oh=class extends po{},o(Oh,"parentToken","layer"),Oh),Fh,Gu=(Fh=class extends wi{constructor(){super(...arguments);o(this,"token","type");o(this,"quoteStringValue",!0)}},o(Fh,"token","type"),Fh);f.register(Gu);var zh,Vu=(zh=class extends wi{constructor(){super(...arguments);o(this,"token","color");o(this,"quoteStringValue",!0)}},o(zh,"token","color"),zh);f.register(Vu);var Uh,Hu=(Uh=class extends wi{constructor(){super(...arguments);o(this,"token","thickness")}static parsePrimitiveValue(t){const e=O(t);if(e===void 0)throw new Error("Stackup layer thickness expects a numeric value");return e}},o(Uh,"token","thickness"),Uh);f.register(Hu);var jh,Yu=(jh=class extends wi{constructor(){super(...arguments);o(this,"token","material");o(this,"quoteStringValue",!0)}},o(jh,"token","material"),jh);f.register(Yu);var Bh,Xu=(Bh=class extends wi{constructor(){super(...arguments);o(this,"token","epsilon_r")}static parsePrimitiveValue(t){const e=O(t);if(e===void 0)throw new Error("Stackup layer epsilon_r expects a numeric value");return e}},o(Bh,"token","epsilon_r"),Bh);f.register(Xu);var Dh,qu=(Dh=class extends wi{constructor(){super(...arguments);o(this,"token","loss_tangent")}static parsePrimitiveValue(t){const e=O(t);if(e===void 0)throw new Error("Stackup layer loss_tangent expects a numeric value");return e}},o(Dh,"token","loss_tangent"),Dh);f.register(qu);var er,ax=(er=class extends f{constructor(e,s={}){super();o(this,"token","layer");o(this,"_name");o(this,"_number");o(this,"_sxType");o(this,"_sxColor");o(this,"_sxThickness");o(this,"_sxMaterial");o(this,"_sxEpsilonR");o(this,"_sxLossTangent");this._name=e,this._number=s.number,this._sxType=s.type,this._sxColor=s.color,this._sxThickness=s.thickness,this._sxMaterial=s.material,this._sxEpsilonR=s.epsilonR,this._sxLossTangent=s.lossTangent}static fromSexprPrimitives(e){if(e.length===0)throw new Error("Stackup layer requires at least a name");const s=F(e[0]);if(s===void 0)throw new Error("Stackup layer name must be a string");let r=1,i;const a=e[r],l=O(a);l!==void 0&&(i=l,r+=1);const c=e.slice(r),{propertyMap:h}=f.parsePrimitivesToClassProperties(c,this.token);return new er(s,{number:i,type:h.type,color:h.color,thickness:h.thickness,material:h.material,epsilonR:h.epsilon_r,lossTangent:h.loss_tangent})}get name(){return this._name}set name(e){const s=F(e);if(s===void 0)throw new Error("Stackup layer name must be a string");this._name=s}get number(){return this._number}set number(e){if(e===void 0){this._number=void 0;return}const s=O(e);if(s===void 0)throw new Error("Stackup layer number must be numeric");this._number=s}get type(){var e;return(e=this._sxType)==null?void 0:e.value}set type(e){if(e===void 0){this._sxType=void 0;return}this._sxType=e instanceof Gu?e:new Gu(e)}get color(){var e;return(e=this._sxColor)==null?void 0:e.value}set color(e){if(e===void 0){this._sxColor=void 0;return}this._sxColor=e instanceof Vu?e:new Vu(e)}get thickness(){var e;return(e=this._sxThickness)==null?void 0:e.value}set thickness(e){if(e===void 0){this._sxThickness=void 0;return}this._sxThickness=e instanceof Hu?e:new Hu(e)}get material(){var e;return(e=this._sxMaterial)==null?void 0:e.value}set material(e){if(e===void 0){this._sxMaterial=void 0;return}this._sxMaterial=e instanceof Yu?e:new Yu(e)}get epsilonR(){var e;return(e=this._sxEpsilonR)==null?void 0:e.value}set epsilonR(e){if(e===void 0){this._sxEpsilonR=void 0;return}this._sxEpsilonR=e instanceof Xu?e:new Xu(e)}get lossTangent(){var e;return(e=this._sxLossTangent)==null?void 0:e.value}set lossTangent(e){if(e===void 0){this._sxLossTangent=void 0;return}this._sxLossTangent=e instanceof qu?e:new qu(e)}getChildren(){const e=[];return this._sxType&&e.push(this._sxType),this._sxColor&&e.push(this._sxColor),this._sxThickness&&e.push(this._sxThickness),this._sxMaterial&&e.push(this._sxMaterial),this._sxEpsilonR&&e.push(this._sxEpsilonR),this._sxLossTangent&&e.push(this._sxLossTangent),e}getString(){const e=`(layer ${D(this._name)}${this._number!==void 0?` ${this._number}`:""}`,s=this.getChildren();if(s.length===0)return`${e})`;const r=[e];for(const i of s)r.push(i.getStringIndented());return r.push(")"),r.join(`
|
|
154
|
+
`)}},o(er,"token","layer"),o(er,"parentToken","stackup"),er);f.register(ax);var tr,Ku=(tr=class extends f{constructor(e={}){super();o(this,"token","stackup");o(this,"_layers",[]);o(this,"_sxCopperFinish");o(this,"_sxDielectricConstraints");o(this,"_sxEdgeConnector");o(this,"_sxCastellatedPads");o(this,"_sxEdgePlating");this.layers=e.layers??[],this._sxCopperFinish=e.copperFinish,this._sxDielectricConstraints=e.dielectricConstraints,this._sxEdgeConnector=e.edgeConnector,this._sxCastellatedPads=e.castellatedPads,this._sxEdgePlating=e.edgePlating}static fromSexprPrimitives(e){const{propertyMap:s,arrayPropertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);return new tr({layers:r.layer??[],copperFinish:s.copper_finish,dielectricConstraints:s.dielectric_constraints,edgeConnector:s.edge_connector,castellatedPads:s.castellated_pads,edgePlating:s.edge_plating})}get layers(){return[...this._layers]}set layers(e){this._layers=e.map(s=>{if(!(s instanceof ax))throw new Error("Stackup layers must be StackupLayer instances");return s})}get copperFinish(){var e;return(e=this._sxCopperFinish)==null?void 0:e.value}set copperFinish(e){this._sxCopperFinish=e?new sx(e):void 0}get dielectricConstraints(){var e;return(e=this._sxDielectricConstraints)==null?void 0:e.value}set dielectricConstraints(e){this._sxDielectricConstraints=e?new nx(e):void 0}get edgeConnector(){var e;return(e=this._sxEdgeConnector)==null?void 0:e.value}set edgeConnector(e){this._sxEdgeConnector=e?new rx(e):void 0}get castellatedPads(){var e;return(e=this._sxCastellatedPads)==null?void 0:e.value}set castellatedPads(e){this._sxCastellatedPads=e?new ix(e):void 0}get edgePlating(){var e;return(e=this._sxEdgePlating)==null?void 0:e.value}set edgePlating(e){this._sxEdgePlating=e?new ox(e):void 0}getChildren(){const e=[...this._layers],s=[this._sxCopperFinish,this._sxDielectricConstraints,this._sxEdgeConnector,this._sxCastellatedPads,this._sxEdgePlating];for(const r of s)r&&e.push(r);return e}},o(tr,"token","stackup"),o(tr,"parentToken","setup"),tr);f.register(Ku);var E0={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"},C0=["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"],Zr,Ap=(Zr=class extends f{constructor(){super(...arguments);o(this,"token","setup");o(this,"_properties",{})}static fromSexprPrimitives(e){const s=new Zr,{propertyMap:r}=f.parsePrimitivesToClassProperties(e,this.token);for(const[i,a]of Object.entries(r)){const l=E0[i];if(!l)throw new Error(`Unsupported setup property token: ${i}`);s._properties[l]=a}return s}getChildren(){const e=[];for(const s of C0){const r=this._properties[s];r&&e.push(r)}return e}setProperty(e,s){if(s){this._properties[e]=s;return}delete this._properties[e]}setNumberProperty(e,s,r){if(s===void 0){delete this._properties[e];return}this._properties[e]=new r(s)}getPropertyInstance(e,s){const r=this._properties[e];return r instanceof s?r:void 0}get stackup(){return this.getPropertyInstance("stackup",Ku)}set stackup(e){if(e!==void 0&&!(e instanceof Ku))throw new Error("stackup must be a Stackup instance");this.setProperty("stackup",e)}get pcbPlotParams(){return this.getPropertyInstance("pcbPlotParams",lu)}set pcbPlotParams(e){if(e!==void 0&&!(e instanceof lu))throw new Error("pcbPlotParams must be a PcbPlotParams instance");this.setProperty("pcbPlotParams",e)}get padToMaskClearance(){var e;return(e=this.getPropertyInstance("padToMaskClearance",bu))==null?void 0:e.value}set padToMaskClearance(e){this.setNumberProperty("padToMaskClearance",e,bu)}get solderMaskMinWidth(){var e;return(e=this.getPropertyInstance("solderMaskMinWidth",ku))==null?void 0:e.value}set solderMaskMinWidth(e){this.setNumberProperty("solderMaskMinWidth",e,ku)}get padToPasteClearance(){var e;return(e=this.getPropertyInstance("padToPasteClearance",Su))==null?void 0:e.value}set padToPasteClearance(e){this.setNumberProperty("padToPasteClearance",e,Su)}get padToPasteClearanceRatio(){var e;return(e=this.getPropertyInstance("padToPasteClearanceRatio",Pu))==null?void 0:e.value}set padToPasteClearanceRatio(e){this.setNumberProperty("padToPasteClearanceRatio",e,Pu)}get lastTraceWidth(){var e;return(e=this.getPropertyInstance("lastTraceWidth",Tu))==null?void 0:e.value}set lastTraceWidth(e){this.setNumberProperty("lastTraceWidth",e,Tu)}get traceClearance(){var e;return(e=this.getPropertyInstance("traceClearance",Eu))==null?void 0:e.value}set traceClearance(e){this.setNumberProperty("traceClearance",e,Eu)}get zoneClearance(){var e;return(e=this.getPropertyInstance("zoneClearance",Cu))==null?void 0:e.value}set zoneClearance(e){this.setNumberProperty("zoneClearance",e,Cu)}get zone45Only(){var e;return(e=this.getPropertyInstance("zone45Only",hu))==null?void 0:e.value}set zone45Only(e){this.setProperty("zone45Only",e===void 0?void 0:new hu(e))}get traceMin(){var e;return(e=this.getPropertyInstance("traceMin",Nu))==null?void 0:e.value}set traceMin(e){this.setNumberProperty("traceMin",e,Nu)}get segmentWidth(){var e;return(e=this.getPropertyInstance("segmentWidth",$u))==null?void 0:e.value}set segmentWidth(e){this.setNumberProperty("segmentWidth",e,$u)}get edgeWidth(){var e;return(e=this.getPropertyInstance("edgeWidth",Au))==null?void 0:e.value}set edgeWidth(e){this.setNumberProperty("edgeWidth",e,Au)}get viaSize(){var e;return(e=this.getPropertyInstance("viaSize",Iu))==null?void 0:e.value}set viaSize(e){this.setNumberProperty("viaSize",e,Iu)}get viaDrill(){var e;return(e=this.getPropertyInstance("viaDrill",Lu))==null?void 0:e.value}set viaDrill(e){this.setNumberProperty("viaDrill",e,Lu)}get viaMinSize(){var e;return(e=this.getPropertyInstance("viaMinSize",Mu))==null?void 0:e.value}set viaMinSize(e){this.setNumberProperty("viaMinSize",e,Mu)}get viaMinDrill(){var e;return(e=this.getPropertyInstance("viaMinDrill",Ru))==null?void 0:e.value}set viaMinDrill(e){this.setNumberProperty("viaMinDrill",e,Ru)}get uviasAllowed(){var e;return(e=this.getPropertyInstance("uviasAllowed",pu))==null?void 0:e.value}set uviasAllowed(e){this.setProperty("uviasAllowed",e===void 0?void 0:new pu(e))}get uviaSize(){var e;return(e=this.getPropertyInstance("uviaSize",Ou))==null?void 0:e.value}set uviaSize(e){this.setNumberProperty("uviaSize",e,Ou)}get uviaDrill(){var e;return(e=this.getPropertyInstance("uviaDrill",Fu))==null?void 0:e.value}set uviaDrill(e){this.setNumberProperty("uviaDrill",e,Fu)}get uviaMinSize(){var e;return(e=this.getPropertyInstance("uviaMinSize",zu))==null?void 0:e.value}set uviaMinSize(e){this.setNumberProperty("uviaMinSize",e,zu)}get uviaMinDrill(){var e;return(e=this.getPropertyInstance("uviaMinDrill",Uu))==null?void 0:e.value}set uviaMinDrill(e){this.setNumberProperty("uviaMinDrill",e,Uu)}get pcbTextWidth(){var e;return(e=this.getPropertyInstance("pcbTextWidth",ju))==null?void 0:e.value}set pcbTextWidth(e){this.setNumberProperty("pcbTextWidth",e,ju)}get pcbTextSize(){var e;return(e=this.getPropertyInstance("pcbTextSize",gu))==null?void 0:e.values}set pcbTextSize(e){if(e===void 0){delete this._properties.pcbTextSize;return}this.setProperty("pcbTextSize",new gu(e))}get modEdgeWidth(){var e;return(e=this.getPropertyInstance("modEdgeWidth",Bu))==null?void 0:e.value}set modEdgeWidth(e){this.setNumberProperty("modEdgeWidth",e,Bu)}get modTextSize(){var e;return(e=this.getPropertyInstance("modTextSize",_u))==null?void 0:e.values}set modTextSize(e){if(e===void 0){delete this._properties.modTextSize;return}this.setProperty("modTextSize",new _u(e))}get modTextWidth(){var e;return(e=this.getPropertyInstance("modTextWidth",Du))==null?void 0:e.value}set modTextWidth(e){this.setNumberProperty("modTextWidth",e,Du)}get padSize(){var e;return(e=this.getPropertyInstance("padSize",mu))==null?void 0:e.values}set padSize(e){if(e===void 0){delete this._properties.padSize;return}this.setProperty("padSize",new mu(e))}get padDrill(){var e;return(e=this.getPropertyInstance("padDrill",Wu))==null?void 0:e.value}set padDrill(e){this.setNumberProperty("padDrill",e,Wu)}get allowSoldermaskBridgesInFootprints(){var e;return(e=this.getPropertyInstance("allowSoldermaskBridgesInFootprints",du))==null?void 0:e.value}set allowSoldermaskBridgesInFootprints(e){this.setProperty("allowSoldermaskBridgesInFootprints",e===void 0?void 0:new du(e))}get tenting(){var e;return(e=this.getPropertyInstance("tenting",fu))==null?void 0:e.sides}set tenting(e){if(e===void 0){delete this._properties.tenting;return}this.setProperty("tenting",new fu(e))}get auxAxisOrigin(){const e=this.getPropertyInstance("auxAxisOrigin",vu);if(e)return{x:e.x,y:e.y}}set auxAxisOrigin(e){if(!e){delete this._properties.auxAxisOrigin;return}this.setProperty("auxAxisOrigin",new vu(e.x,e.y))}get gridOrigin(){const e=this.getPropertyInstance("gridOrigin",wu);if(e)return{x:e.x,y:e.y}}set gridOrigin(e){if(!e){delete this._properties.gridOrigin;return}this.setProperty("gridOrigin",new wu(e.x,e.y))}get visibleElements(){var e;return(e=this.getPropertyInstance("visibleElements",uu))==null?void 0:e.value}set visibleElements(e){this.setProperty("visibleElements",e===void 0?void 0:new uu(e))}get padToPasteClearanceValues(){var e;return(e=this.getPropertyInstance("padToPasteClearanceValues",xu))==null?void 0:e.values}set padToPasteClearanceValues(e){if(e===void 0){delete this._properties.padToPasteClearanceValues;return}this.setProperty("padToPasteClearanceValues",new xu(e))}get traceWidth(){var e;return(e=this.getPropertyInstance("traceWidth",yu))==null?void 0:e.values}set traceWidth(e){if(e===void 0){delete this._properties.traceWidth;return}this.setProperty("traceWidth",new yu(e))}},o(Zr,"token","setup"),Zr);f.register(Ap);var xa,cx=(xa=class extends oe{constructor(){super(...arguments);o(this,"token","thickness")}},o(xa,"token","thickness"),o(xa,"parentToken","general"),xa);f.register(cx);var sr,lx=(sr=class extends f{constructor(e){super();o(this,"token","legacy_teardrops");o(this,"_enabled");this._enabled=e}static fromSexprPrimitives(e){const s=F(e[0]);if(s===void 0)throw new Error("legacy_teardrops expects a string value");const r=/^(yes|true)$/iu.test(s);return new sr(r)}get enabled(){return this._enabled}set enabled(e){this._enabled=e}getChildren(){return[]}getString(){return`(legacy_teardrops ${this._enabled?"yes":"no"})`}},o(sr,"token","legacy_teardrops"),o(sr,"parentToken","general"),sr);f.register(lx);var Gf=new Set(["thickness","legacy_teardrops"]),nr,Ip=(nr=class extends f{constructor(){super(...arguments);o(this,"token","general");o(this,"_sxThickness");o(this,"_sxLegacyTeardrops")}static fromSexprPrimitives(e){var a,l;const s=new nr,{propertyMap:r,arrayPropertyMap:i}=f.parsePrimitivesToClassProperties(e,this.token);for(const c of Object.keys(r))if(!Gf.has(c))throw new Error(`general encountered unsupported child token "${c}"`);for(const[c,h]of Object.entries(i)){if(!Gf.has(c))throw new Error(`general encountered unsupported child token "${c}"`);if(h.length>1)throw new Error(`general encountered repeated child token "${c}"`)}return s._sxThickness=((a=i.thickness)==null?void 0:a[0])??r.thickness,s._sxLegacyTeardrops=((l=i.legacy_teardrops)==null?void 0:l[0])??r.legacy_teardrops,s}get thickness(){var e;return(e=this._sxThickness)==null?void 0:e.value}set thickness(e){this._sxThickness=e===void 0?void 0:new cx(e)}get legacyTeardrops(){var e;return(e=this._sxLegacyTeardrops)==null?void 0:e.enabled}set legacyTeardrops(e){if(e===void 0){this._sxLegacyTeardrops=void 0;return}this._sxLegacyTeardrops=new lx(e)}getChildren(){const e=[];return this._sxThickness&&e.push(this._sxThickness),this._sxLegacyTeardrops&&e.push(this._sxLegacyTeardrops),e}},o(nr,"token","general"),o(nr,"parentToken","kicad_pcb"),nr);f.register(Ip);var rr,ge=(rr=class extends f{constructor(e){super();o(this,"token","__pcb_layer_definition__");o(this,"_index");o(this,"_name");o(this,"_type");o(this,"_userName");this._index=e.index,this._name=e.name,this._type=e.type,this._userName=e.userName}static fromPrimitive(e){if(!Array.isArray(e)||e.length<3)throw new Error(`layers entry must be an array with at least index, name, and type: ${JSON.stringify(e)}`);const[s,r,i,a]=e,l=O(s),c=F(r),h=F(i),d=a===void 0?void 0:F(a);if(l===void 0||c===void 0||h===void 0)throw new Error(`layers entry is missing required values: ${JSON.stringify(e)}`);return new rr({index:l,name:c,type:h,userName:d})}get index(){return this._index}set index(e){this._index=e}get name(){return this._name}set name(e){this._name=e}get type(){return this._type}set type(e){this._type=e}get userName(){return this._userName}set userName(e){this._userName=e}getChildren(){return[]}getString(){if(this._index===void 0||this._name===void 0||this._type===void 0)return"()";const e=[String(this._index),D(this._name),this._type];return this._userName!==void 0&&e.push(D(this._userName)),`(${e.join(" ")})`}},o(rr,"token","__pcb_layer_definition__"),o(rr,"parentToken","layers"),rr);f.register(ge);var ir,Lp=(ir=class extends f{constructor(){super(...arguments);o(this,"token","layers");o(this,"_definitions",[])}static fromSexprPrimitives(e){const s=new ir;return s._definitions=e.map(r=>ge.fromPrimitive(r)),s}get definitions(){return[...this._definitions]}set definitions(e){this._definitions=[...e]}getChildren(){return[...this._definitions]}},o(ir,"token","layers"),o(ir,"parentToken","kicad_pcb"),ir);f.register(Lp);var or,Mp=(or=class extends f{constructor(e,s){super();o(this,"token","net");o(this,"_id");o(this,"_name");this._id=e,this._name=s}static fromSexprPrimitives(e){const s=O(e[0]),r=F(e[1]);if(s===void 0||r===void 0)throw new Error("net requires numeric id and string name");return new or(s,r)}get id(){return this._id}set id(e){this._id=e}get name(){return this._name}set name(e){this._name=e}getChildren(){return[]}getString(){return`(net ${this._id} ${D(this._name)})`}},o(or,"token","net"),o(or,"parentToken","kicad_pcb"),or);f.register(Mp);var ya,Ju=(ya=class extends oe{constructor(){super(...arguments);o(this,"token","version")}},o(ya,"token","version"),o(ya,"parentToken","kicad_pcb"),ya);f.register(Ju);var N0=n=>/^[A-Za-z0-9._-]+$/.test(n),va,Zu=(va=class extends Rt{constructor(){super(...arguments);o(this,"token","generator")}getString(){return`(generator ${N0(this.value)?this.value:D(this.value)})`}},o(va,"token","generator"),o(va,"parentToken","kicad_pcb"),va);f.register(Zu);var $0=n=>/^[A-Za-z0-9._-]+$/.test(n),wa,Qu=(wa=class extends Rt{constructor(){super(...arguments);o(this,"token","generator_version")}getString(){return`(generator_version ${$0(this.value)?this.value:D(this.value)})`}},o(wa,"token","generator_version"),o(wa,"parentToken","kicad_pcb"),wa);f.register(Qu);var ar,Rp=(ar=class extends f{constructor(e,s){super();o(this,"token","net");o(this,"_id");o(this,"_name");this._id=e,this._name=s}static fromSexprPrimitives(e){const s=O(e[0]);if(s===void 0)throw new Error("via net requires a numeric id");const r=e.length>1?F(e[1]):void 0;return new ar(s,r)}get id(){return this._id}set id(e){this._id=e}get name(){return this._name}set name(e){this._name=e}getChildren(){return[]}getString(){return this._name!==void 0?`(net ${this._id} ${D(this._name)})`:`(net ${this._id})`}},o(ar,"token","net"),o(ar,"parentToken","via"),ar);f.register(Rp);var A0=new Set(["locked","free","remove_unused_layers","keep_end_layers"]),Qr,Op=(Qr=class extends f{constructor(e={}){super();o(this,"token","via");o(this,"_type");o(this,"_locked",!1);o(this,"_free",!1);o(this,"_removeUnusedLayers",!1);o(this,"_keepEndLayers",!1);o(this,"_sxAt");o(this,"_size");o(this,"_drill");o(this,"_sxLayers");o(this,"_sxNet");o(this,"_sxUuid");o(this,"_tstamp");o(this,"_sxTeardrops");e.type!==void 0&&(this.type=e.type),e.locked!==void 0&&(this.locked=e.locked),e.free!==void 0&&(this.free=e.free),e.removeUnusedLayers!==void 0&&(this.removeUnusedLayers=e.removeUnusedLayers),e.keepEndLayers!==void 0&&(this.keepEndLayers=e.keepEndLayers),e.at!==void 0&&(this.at=e.at),e.size!==void 0&&(this.size=e.size),e.drill!==void 0&&(this.drill=e.drill),e.layers!==void 0&&(this.layers=e.layers),e.net!==void 0&&(this.net=e.net),e.uuid!==void 0&&(this.uuid=e.uuid),e.tstamp!==void 0&&(this.tstamp=e.tstamp),e.teardrops!==void 0&&(this.teardrops=e.teardrops)}static fromSexprPrimitives(e){const s=new Qr;for(const r of e){if(typeof r=="string"){s.consumeBareToken(r);continue}if(!Array.isArray(r)||r.length===0)throw new Error(`via encountered unsupported primitive child: ${JSON.stringify(r)}`);const[i,...a]=r;if(typeof i!="string")throw new Error(`via encountered child with non-string token: ${JSON.stringify(r)}`);s.consumeNode(i,a)}return s}consumeBareToken(e){if(e==="blind"||e==="micro"){this._type=e;return}if(!A0.has(e))throw new Error(`via encountered unsupported flag "${e}"`);switch(e){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(e,s){switch(e){case"type":{const r=F(s[0]);if(r===void 0)throw new Error("via type expects a string value");this._type=r;return}case"locked":this._locked=this.parseYesNo(s);return;case"free":this._free=this.parseYesNo(s);return;case"remove_unused_layers":this._removeUnusedLayers=this.parseYesNo(s);return;case"keep_end_layers":this._keepEndLayers=this.parseYesNo(s);return;case"at":{const r=f.parsePrimitiveSexpr(["at",...s],{parentToken:this.token});if(!(r instanceof he))throw new Error("via failed to parse at child");this._sxAt=r;return}case"size":{const r=O(s[0]);if(r===void 0)throw new Error("via size expects a numeric value");this._size=r;return}case"drill":{const r=O(s[0]);if(r===void 0)throw new Error("via drill expects a numeric value");this._drill=r;return}case"layers":{this._sxLayers=$a.fromSexprPrimitives(s);return}case"net":{this._sxNet=Rp.fromSexprPrimitives(s);return}case"teardrops":{this._sxTeardrops=Z_.fromSexprPrimitives(s);return}case"uuid":{const r=F(s[0]);if(r===void 0)throw new Error("via uuid expects a string value");this._sxUuid=new W(r);return}case"tstamp":{const r=F(s[0]);if(r===void 0)throw new Error("via tstamp expects a string value");this._tstamp=r;return}default:throw new Error(`via encountered unsupported child token "${e}"`)}}parseYesNo(e){if(e.length===0)return!0;const s=F(e[0]);if(s===void 0)throw new Error("Expected string when parsing via boolean child");return/^(yes|true)$/iu.test(s)}get type(){return this._type}set type(e){this._type=e}get locked(){return this._locked}set locked(e){this._locked=e}get free(){return this._free}set free(e){this._free=e}get removeUnusedLayers(){return this._removeUnusedLayers}set removeUnusedLayers(e){this._removeUnusedLayers=e}get keepEndLayers(){return this._keepEndLayers}set keepEndLayers(e){this._keepEndLayers=e}get at(){return this._sxAt}set at(e){this._sxAt=e!==void 0?he.from(e):void 0}get size(){return this._size}set size(e){this._size=e}get drill(){return this._drill}set drill(e){this._drill=e}get layers(){return this._sxLayers}set layers(e){if(e===void 0){this._sxLayers=void 0;return}this._sxLayers=e instanceof $a?e:new $a(e)}get net(){return this._sxNet}set net(e){this._sxNet=e}get uuid(){return this._sxUuid}set uuid(e){if(e===void 0){this._sxUuid=void 0;return}this._sxUuid=e instanceof W?e:new W(e)}get teardrops(){return this._sxTeardrops}set teardrops(e){this._sxTeardrops=e}get tstamp(){return this._tstamp}set tstamp(e){this._tstamp=e}getChildren(){const e=[];return this._sxAt&&e.push(this._sxAt),this._sxLayers&&e.push(this._sxLayers),this._sxNet&&e.push(this._sxNet),this._sxUuid&&e.push(this._sxUuid),this._sxTeardrops&&e.push(this._sxTeardrops),e}getString(){const e=["(via"];return this._type!==void 0&&e.push(` (type ${this._type})`),this._locked&&e.push(" locked"),this._free&&e.push(" free"),this._removeUnusedLayers&&e.push(" remove_unused_layers"),this._keepEndLayers&&e.push(" keep_end_layers"),this._sxAt&&e.push(this._sxAt.getStringIndented()),this._size!==void 0&&e.push(` (size ${this._size})`),this._drill!==void 0&&e.push(` (drill ${this._drill})`),this._sxLayers&&e.push(this._sxLayers.getStringIndented()),this._sxNet&&e.push(this._sxNet.getStringIndented()),this._sxUuid&&e.push(this._sxUuid.getStringIndented()),this._tstamp!==void 0&&e.push(` (tstamp ${D(this._tstamp)})`),this._sxTeardrops&&e.push(this._sxTeardrops.getStringIndented()),e.push(")"),e.join(`
|
|
155
|
+
`)}},o(Qr,"token","via"),Qr);f.register(Op);var ei,hx=(ei=class extends f{constructor(e={}){super();o(this,"token","kicad_pcb");o(this,"_sxVersion");o(this,"_sxGenerator");o(this,"_sxGeneratorVersion");o(this,"_sxGeneral");o(this,"_sxPaper");o(this,"_sxTitleBlock");o(this,"_sxLayers");o(this,"_sxSetup");o(this,"_properties",[]);o(this,"_nets",[]);o(this,"_footprints",[]);o(this,"_images",[]);o(this,"_segments",[]);o(this,"_grLines",[]);o(this,"_grTexts",[]);o(this,"_vias",[]);o(this,"_zones",[]);o(this,"_otherChildren",[]);e.version!==void 0&&(this.version=e.version),e.generator!==void 0&&(this.generator=e.generator),e.generatorVersion!==void 0&&(this.generatorVersion=e.generatorVersion),e.general!==void 0&&(this.general=e.general),e.paper!==void 0&&(this.paper=e.paper),e.titleBlock!==void 0&&(this.titleBlock=e.titleBlock),e.layers!==void 0&&(this.layers=e.layers),e.setup!==void 0&&(this.setup=e.setup),e.properties!==void 0&&(this.properties=e.properties),e.nets!==void 0&&(this.nets=e.nets),e.footprints!==void 0&&(this.footprints=e.footprints),e.images!==void 0&&(this.images=e.images),e.segments!==void 0&&(this.segments=e.segments),e.graphicLines!==void 0&&(this.graphicLines=e.graphicLines),e.graphicTexts!==void 0&&(this.graphicTexts=e.graphicTexts),e.vias!==void 0&&(this.vias=e.vias),e.zones!==void 0&&(this.zones=e.zones),e.otherChildren!==void 0&&(this.otherChildren=e.otherChildren)}static fromSexprPrimitives(e){const s=new ei;for(const r of e){if(!Array.isArray(r)||r.length===0)throw new Error(`kicad_pcb encountered unsupported primitive child: ${JSON.stringify(r)}`);const i=f.parsePrimitiveSexpr(r,{parentToken:this.token});if(!(i instanceof f))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(r)}`);s.consumeChild(i)}return s}consumeChild(e){if(e instanceof Ju){this._sxVersion=e;return}if(e instanceof Zu){this._sxGenerator=e;return}if(e instanceof Qu){this._sxGeneratorVersion=e;return}if(e instanceof Ip){this._sxGeneral=e;return}if(e instanceof lc){this._sxPaper=e;return}if(e instanceof t_){this._sxTitleBlock=e;return}if(e instanceof Lp){this._sxLayers=e;return}if(e instanceof Ap){this._sxSetup=e;return}if(e instanceof v_){this._properties.push(e);return}if(e instanceof Mp){this._nets.push(e);return}if(e instanceof Cp){this._footprints.push(e);return}if(e instanceof s_){this._images.push(e);return}if(e instanceof $p){this._segments.push(e);return}if(e instanceof Wa){this._grLines.push(e);return}if(e instanceof Np){this._grTexts.push(e);return}if(e instanceof Op){this._vias.push(e);return}if(e instanceof om){this._zones.push(e);return}this._otherChildren.push(e)}get version(){var e;return(e=this._sxVersion)==null?void 0:e.value}set version(e){this._sxVersion=e===void 0?void 0:new Ju(e)}get generator(){var e;return(e=this._sxGenerator)==null?void 0:e.value}set generator(e){this._sxGenerator=e===void 0?void 0:new Zu(e)}get generatorVersion(){var e;return(e=this._sxGeneratorVersion)==null?void 0:e.value}set generatorVersion(e){this._sxGeneratorVersion=e===void 0?void 0:new Qu(e)}get general(){return this._sxGeneral}set general(e){this._sxGeneral=e}get paper(){return this._sxPaper}set paper(e){this._sxPaper=e}get titleBlock(){return this._sxTitleBlock}set titleBlock(e){this._sxTitleBlock=e}get layers(){return this._sxLayers}set layers(e){this._sxLayers=e}get setup(){return this._sxSetup}set setup(e){this._sxSetup=e}get properties(){return[...this._properties]}set properties(e){this._properties=[...e]}get nets(){return[...this._nets]}set nets(e){this._nets=[...e]}get footprints(){return[...this._footprints]}set footprints(e){this._footprints=[...e]}get images(){return[...this._images]}set images(e){this._images=[...e]}get segments(){return[...this._segments]}set segments(e){this._segments=[...e]}get graphicLines(){return[...this._grLines]}set graphicLines(e){this._grLines=[...e]}get graphicTexts(){return[...this._grTexts]}set graphicTexts(e){this._grTexts=[...e]}get vias(){return[...this._vias]}set vias(e){this._vias=[...e]}get zones(){return[...this._zones]}set zones(e){this._zones=[...e]}get otherChildren(){return[...this._otherChildren]}set otherChildren(e){this._otherChildren=[...e]}getChildren(){const e=[];return this._sxVersion&&e.push(this._sxVersion),this._sxGenerator&&e.push(this._sxGenerator),this._sxGeneratorVersion&&e.push(this._sxGeneratorVersion),this._sxGeneral&&e.push(this._sxGeneral),this._sxPaper&&e.push(this._sxPaper),this._sxTitleBlock&&e.push(this._sxTitleBlock),this._sxLayers&&e.push(this._sxLayers),this._sxSetup&&e.push(this._sxSetup),e.push(...this._properties),e.push(...this._nets),e.push(...this._footprints),e.push(...this._images),e.push(...this._segments),e.push(...this._grLines),e.push(...this._grTexts),e.push(...this._vias),e.push(...this._zones),e.push(...this._otherChildren),e}},o(ei,"token","kicad_pcb"),ei);f.register(hx);var dt=class{constructor(n,t){o(this,"MAX_ITERATIONS",1e3);o(this,"iteration",0);o(this,"finished",!1);o(this,"input");o(this,"ctx");this.input=n,this.ctx=t}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")}},I0=class extends dt{_step(){const{kicadSch:n}=this.ctx;if(!n)throw new Error("KicadSch instance not initialized in context");n.version=20250114;const t=new lc;t.size="A4",n.paper=t,n.uuid=new W(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function dx(n,t){return n.type!=="source_component"?t.symbol_name?`Custom:${t.symbol_name}`:"Device:Component":n.ftype==="simple_resistor"?`Device:R_${n.source_component_id}`:n.ftype==="simple_capacitor"?`Device:C_${n.source_component_id}`:n.ftype==="simple_inductor"?`Device:L_${n.source_component_id}`:n.ftype==="simple_diode"?`Device:D_${n.source_component_id}`:n.ftype==="simple_chip"?`Device:U_${n.source_component_id}`:t.symbol_name?`Custom:${t.symbol_name}`:`Device:Component_${n.source_component_id}`}var L0=class extends dt{_step(){var a,l,c,h;const{kicadSch:n,db:t}=this.ctx,e=new m_,s=[],r=t.schematic_component.list();for(const d of r){const p=this.createLibrarySymbolForComponent(d);p&&s.push(p)}const i=((l=(a=t.schematic_net_label)==null?void 0:a.list)==null?void 0:l.call(a))||[];for(const d of i)if(d.symbol_name){const p=d.source_net_id?(c=t.source_net.get(d.source_net_id))==null?void 0:c.is_power:!1,u=d.source_net_id?(h=t.source_net.get(d.source_net_id))==null?void 0:h.is_ground:!1;if(p||u){const _=this.createLibrarySymbolForNetLabel({netLabel:d,isPower:p??!1,isGround:u??!1});_&&s.push(_)}}e.symbols=s,n&&(n.libSymbols=e),this.finished=!0}createLibrarySymbolForComponent(n){const{db:t}=this.ctx,e=n.source_component_id?t.source_component.get(n.source_component_id):null;if(!e)return null;const s=n.symbol_name||(e.ftype==="simple_chip"?`generic_chip_${n.source_component_id}`:null);if(!s)return null;const r=this.getSymbolData(s,n);if(!r)return null;const i=dx(e,n),a=e.ftype==="simple_chip";return this.createLibrarySymbol({libId:i,symbolData:r,isChip:a,schematicComponent:n,description:this.getDescription(e),keywords:this.getKeywords(e),fpFilters:this.getFpFilters(e)})}createLibrarySymbolForNetLabel({netLabel:n,isPower:t,isGround:e}){const s=n.symbol_name;if(!s)return null;const r=Wh[s];if(!r)return null;const i=`Custom:${s}`;return this.createLibrarySymbol({libId:i,symbolData:r,isChip:!1,schematicComponent:void 0,description:t?"Power net label":e?"Ground net label":"Net symbol",keywords:t?"power net":e?"ground net":"net",fpFilters:""})}getSymbolData(n,t){return n.startsWith("generic_chip_")?this.createGenericChipSymbolData(t,this.ctx.db):Wh[n]||null}createGenericChipSymbolData(n,t){var l,c;const e=t.schematic_port.list().filter(h=>h.schematic_component_id===n.schematic_component_id).sort((h,d)=>(h.pin_number||0)-(d.pin_number||0)),s=((l=n.size)==null?void 0:l.width)||1.5,r=((c=n.size)==null?void 0:c.height)||1,i={type:"path",points:[{x:-s/2,y:-r/2},{x:s/2,y:-r/2},{x:s/2,y:r/2},{x:-s/2,y:r/2},{x:-s/2,y:-r/2}]},a=e.map(h=>{const d=h.center.x-n.center.x,p=h.center.y-n.center.y;return{x:d,y:p,labels:[h.display_pin_label||`${h.pin_number||1}`],pinNumber:h.pin_number||1}});return{center:{x:0,y:0},primitives:[i],ports:a,size:{width:s,height:r}}}createLibrarySymbol({libId:n,symbolData:t,isChip:e,schematicComponent:s,description:r,keywords:i,fpFilters:a}){const l=new hi({libraryId:n,excludeFromSim:!1,inBom:!0,onBoard:!0}),c=new o_;c.hide=!e,l._sxPinNumbers=c;const h=new a_;h.offset=e?1.27:0,l._sxPinNames=h,this.addSymbolProperties({symbol:l,libId:n,description:r,keywords:i,fpFilters:a});const d=this.createDrawingSubsymbol({libId:n,symbolData:t,isChip:e});l.subSymbols.push(d);const p=this.createPinSubsymbol({libId:n,symbolData:t,isChip:e,schematicComponent:s});return l.subSymbols.push(p),l._sxEmbeddedFonts=new yp(!1),l}addSymbolProperties({symbol:n,libId:t,description:e,keywords:s,fpFilters:r}){var l;const i=((l=t.split(":")[1])==null?void 0:l[0])||"U",a=[{key:"Reference",value:i,id:0,at:[2.032,0,90],hide:!1},{key:"Value",value:i,id:1,at:[0,0,90],hide:!1},{key:"Footprint",value:"",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:s,id:5,at:[0,0,0],hide:!0},{key:"ki_fp_filters",value:r,id:6,at:[0,0,0],hide:!0}];for(const c of a)n.properties.push(new ot({key:c.key,value:c.value,id:c.id,at:c.at,effects:this.createTextEffects(1.27,c.hide)}))}getDescription(n){return(n==null?void 0:n.ftype)==="simple_resistor"?"Resistor":(n==null?void 0:n.ftype)==="simple_capacitor"?"Capacitor":(n==null?void 0:n.ftype)==="simple_chip"?"Integrated Circuit":"Component"}getKeywords(n){return(n==null?void 0:n.ftype)==="simple_resistor"?"R res resistor":(n==null?void 0:n.ftype)==="simple_capacitor"?"C cap capacitor":(n==null?void 0:n.ftype)==="simple_chip"?"U IC chip":""}getFpFilters(n){return(n==null?void 0:n.ftype)==="simple_resistor"?"R_*":(n==null?void 0:n.ftype)==="simple_capacitor"?"C_*":((n==null?void 0:n.ftype)==="simple_chip","*")}createDrawingSubsymbol({libId:n,symbolData:t,isChip:e}){var i;const s=new hi({libraryId:`${n.split(":")[1]}_0_1`}),r=((i=this.ctx.c2kMatSch)==null?void 0:i.a)||15;for(const a of t.primitives||[])if(a.type==="path"&&a.points){const l=e?"background":"none",c=this.createPolylineFromPoints({points:a.points,scale:r,center:t.center,fillType:l});s.polylines.push(c)}return s}createPolylineFromPoints({points:n,scale:t,center:e,fillType:s}){const r=new u_,i=(e==null?void 0:e.x)??0,a=(e==null?void 0:e.y)??0,l=pr(t,t),c=n.map(u=>{const g=B(l,{x:u.x-i,y:u.y-a});return new et(g.x,g.y)}),h=new Gt(c);r.points=h;const d=new gp;d.width=.254,d.type="default",r.stroke=d;const p=new h_;return p.type=s,r.fill=p,r}createPinSubsymbol({libId:n,symbolData:t,isChip:e,schematicComponent:s}){var i,a,l;const r=new hi({libraryId:`${n.split(":")[1]}_1_1`});for(let c=0;c<(((i=t.ports)==null?void 0:i.length)||0);c++){const h=t.ports[c],d=new uc;d.pinElectricalType="passive",d.pinGraphicStyle="line";const{x:p,y:u,angle:g}=this.calculatePinPosition(h,t.center,t.size,e,c,s);d.at=[p,u,g],d.length=e?6:1.27;const _=new Xt;_.size={height:1.27,width:1.27};const x=new Yt({font:_}),v=((a=h.labels)==null?void 0:a[0])||"~";d._sxName=new wp({value:v,effects:x});const m=new Xt;m.size={height:1.27,width:1.27};const y=new Yt({font:m}),w=((l=h.pinNumber)==null?void 0:l.toString())||`${c+1}`;d._sxNumber=new f_({value:w,effects:y}),r.pins.push(d)}return r}calculatePinPosition(n,t,e,s,r,i){var w;const a=((w=this.ctx.c2kMatSch)==null?void 0:w.a)||15;let l=n.x??0,c=n.y??0,h=!1;if(r!==void 0&&i){const b=this.ctx.db.schematic_port.list().filter(k=>k.schematic_component_id===i.schematic_component_id).sort((k,C)=>(k.pin_number||0)-(C.pin_number||0));if(b[r]){const k=b[r];l=k.center.x-i.center.x,c=k.center.y-i.center.y,h=!0}}let d,p;if(h)d=l,p=c;else{const b=(t==null?void 0:t.x)??0,k=(t==null?void 0:t.y)??0;d=l-b,p=c-k}const u=pr(a,a),g=B(u,{x:d,y:p});let _;if(s&&e){const b=e.width/2,k=e.height/2,C=Math.abs(d)/b,E=Math.abs(p)/k;_=C>E}else _=Math.abs(d)>Math.abs(p);let x=g.x,v=g.y;const m=6;if(s&&e){const b=e.width/2*a,k=e.height/2*a;_?(x=d>0?b:-b,v=p*a):(x=d*a,v=p>0?k:-k)}let y=0;return _?d>0?s?(y=180,x=x+m):y=0:s?(y=0,x=x-m):y=180:p>0?s?(y=270,v=v+m):y=90:s?(y=90,v=v-m):y=270,{x,y:v,angle:y}}createTextEffects(n,t){const e=new Xt;return e.size={height:n,width:n},new Yt({font:e,hiddenText:t})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},M0=class extends dt{_step(){var r;const{kicadSch:n,db:t}=this.ctx,e=t.schematic_component.list();if(e.length===0){this.finished=!0;return}const s=[];for(const i of e){const a=i.source_component_id?t.source_component.get(i.source_component_id):null;if(!a||!this.ctx.c2kMatSch)continue;const{x:l,y:c}=B(this.ctx.c2kMatSch,{x:i.center.x,y:i.center.y}),h=crypto.randomUUID(),d=new hi({at:[l,c,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:h,fieldsAutoplaced:!0}),p=dx(a,i),u=new vp(p);d._sxLibId=u;const{reference:g,value:_,description:x}=this.getComponentMetadata(a),{refTextPos:v,valTextPos:m}=this.getTextPositions(i,{x:l,y:c}),y=new ot({key:"Reference",value:g,id:0,at:[v.x,v.y,0],effects:this.createTextEffects(1.27,!1)}),w=a.ftype==="simple_chip",b=new ot({key:"Value",value:_,id:1,at:[m.x,m.y,0],effects:this.createTextEffects(1.27,w)}),k=new ot({key:"Footprint",value:"",id:2,at:[l-1.778,c,90],effects:this.createTextEffects(1.27,!0)}),C=new ot({key:"Datasheet",value:"~",id:3,at:[l,c,0],effects:this.createTextEffects(1.27,!0)}),E=new ot({key:"Description",value:x,id:4,at:[l,c,0],effects:this.createTextEffects(1.27,!0)});d.properties.push(y,b,k,C,E);const N=t.schematic_port.list().filter(L=>L.schematic_component_id===i.schematic_component_id).sort((L,R)=>(L.pin_number||0)-(R.pin_number||0));for(const L of N){const R=new uc;R.numberString=`${L.pin_number||1}`,R.uuid=crypto.randomUUID(),d.pins.push(R)}const I=new bp,M=new kp(""),S=new Sp(`/${((r=n==null?void 0:n.uuid)==null?void 0:r.value)||""}`);S.reference=g,S.unit=1,M.paths.push(S),I.projects.push(M),d._sxInstances=I,s.push(d)}n&&(n.symbols=s),this.finished=!0}getTextPositions(n,t){var g,_,x;const s=(((x=(_=(g=this.ctx.db.schematic_text)==null?void 0:g.list)==null?void 0:_.call(g))==null?void 0:x.filter(v=>v.schematic_component_id===n.schematic_component_id))||[]).find(v=>v.text&&v.text.length>0);if(s&&this.ctx.c2kMatSch){const v=B(this.ctx.c2kMatSch,{x:s.position.x,y:s.position.y}),m={x:t.x,y:t.y+6};return{refTextPos:v,valTextPos:m}}const r=n.symbol_name,i=Wh[r];if(!i)return{refTextPos:{x:t.x,y:t.y-6},valTextPos:{x:t.x,y:t.y+6}};let a=null,l=null;for(const v of i.primitives)v.type==="text"&&(v.text==="{REF}"?a=v:v.text==="{VAL}"&&(l=v));const c=i.center||{x:0,y:0},d=r.includes("_down")||r.includes("_up")?.15:0,p=a&&this.ctx.c2kMatSch?B(this.ctx.c2kMatSch,{x:n.center.x+(a.x-c.x)+d,y:n.center.y+(a.y-c.y)}):{x:t.x,y:t.y-6},u=l&&this.ctx.c2kMatSch?B(this.ctx.c2kMatSch,{x:n.center.x+(l.x-c.x)+d,y:n.center.y+(l.y-c.y)}):{x:t.x,y:t.y+6};return{refTextPos:p,valTextPos:u}}getComponentMetadata(n){const t=n.name||"?";return n.ftype==="simple_resistor"?{reference:t,value:n.display_resistance||"R",description:"Resistor"}:n.ftype==="simple_capacitor"?{reference:t,value:n.display_capacitance||"C",description:"Capacitor"}:n.ftype==="simple_inductor"?{reference:t,value:n.display_inductance||"L",description:"Inductor"}:n.ftype==="simple_diode"?{reference:t,value:"D",description:"Diode"}:n.ftype==="simple_chip"?{reference:t,value:t,description:"Integrated Circuit"}:{reference:t,value:t,description:"Component"}}createTextEffects(n,t=!1,e){const s=new Xt;s.size={height:n,width:n};const r=e?new ac({horizontal:e}):void 0;return new Yt({font:s,hiddenText:t,justify:r})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},R0=class extends dt{_step(){var i,a;const{kicadSch:n,db:t}=this.ctx,e=((a=(i=t.schematic_net_label)==null?void 0:i.list)==null?void 0:a.call(i))||[];if(e.length===0){this.finished=!0;return}if(!this.ctx.c2kMatSch){this.finished=!0;return}const s=[],r=[];for(const l of e){const c=l.text||"",h=l.symbol_name;if(h){const d=this.createSymbolFromNetLabel(l,c,h);d&&s.push(d)}else{const d=this.createGlobalLabel(l,c);d&&r.push(d)}}if(n&&s.length>0){const l=n.symbols||[];n.symbols=[...l,...s]}n&&r.length>0&&(n.globalLabels=[...n.globalLabels||[],...r]),this.finished=!0}createSymbolFromNetLabel(n,t,e){var C,E,N,I,M;if(!this.ctx.c2kMatSch)return null;const{x:s,y:r}=B(this.ctx.c2kMatSch,{x:((C=n.anchor_position)==null?void 0:C.x)??((E=n.center)==null?void 0:E.x)??0,y:((N=n.anchor_position)==null?void 0:N.y)??((I=n.center)==null?void 0:I.y)??0}),i=crypto.randomUUID(),a=new hi({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:i,fieldsAutoplaced:!0}),l=`Custom:${e}`,c=new vp(l);a._sxLibId=c;const h=e.includes("_up")||e.toLowerCase().includes("vcc"),d=h?-4:4,p=h?-6:6,u=new ot({key:"Reference",value:t,id:0,at:[s,r+d,0],effects:this.createTextEffects(1.27,!1)}),g=new ot({key:"Value",value:t,id:1,at:[s,r+p,0],effects:this.createTextEffects(1.27,!0)}),_=new ot({key:"Footprint",value:"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,!0)}),x=new ot({key:"Datasheet",value:"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,!0)}),v=new ot({key:"Description",value:`Power/Net symbol: ${t}`,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,!0)});a.properties.push(u,g,_,x,v);const m=new uc;m.numberString="1",m.uuid=crypto.randomUUID(),a.pins.push(m);const{kicadSch:y}=this.ctx,w=new bp,b=new kp(""),k=new Sp(`/${((M=y==null?void 0:y.uuid)==null?void 0:M.value)||""}`);return k.reference=t,k.unit=1,b.paths.push(k),w.projects.push(b),a._sxInstances=w,a}createGlobalLabel(n,t){var p,u,g,_;if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:e,y:s}=B(this.ctx.c2kMatSch,{x:((p=n.anchor_position)==null?void 0:p.x)??((u=n.center)==null?void 0:u.x)??0,y:((g=n.anchor_position)==null?void 0:g.y)??((_=n.center)==null?void 0:_.y)??0}),r=n.anchor_side||"left",a={left:0,right:180,top:270,bottom:90}[r]||0,c={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[r]||{},h=this.createTextEffects(1.27,!1);return Object.keys(c).length>0&&(h.justify=new ac(c)),new w_({value:t,at:[e,s,a],effects:h,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(n,t=!1){const e=new Xt;return e.size={height:n,width:n},new Yt({font:e,hiddenText:t})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},O0=class extends dt{_step(){const{kicadSch:n,db:t}=this.ctx;if(!n)throw new Error("KicadSch instance not initialized in context");const e=t.schematic_trace.list();if(e.length===0){this.finished=!0;return}const s=[],r=[];for(const i of e){for(const a of i.edges){const l=this.createWireFromEdge(a);s.push(l)}for(const a of i.junctions){const l=this.createJunction(a);r.push(l)}}n.wires=s,n.junctions=r,this.finished=!0}createWireFromEdge(n){const t=new x_;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const e=B(this.ctx.c2kMatSch,{x:n.from.x,y:n.from.y}),s=B(this.ctx.c2kMatSch,{x:n.to.x,y:n.to.y}),r=e.x,i=e.y,a=s.x,l=s.y,c=new Gt([new et(r,i),new et(a,l)]);t.points=c;const h=new gp;return h.width=0,h.type="default",t.stroke=h,t.uuid=crypto.randomUUID(),t}createJunction(n){if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const{x:t,y:e}=B(this.ctx.c2kMatSch,{x:n.x,y:n.y}),s=new y_({at:[t,e],diameter:0});return s.uuid=crypto.randomUUID(),s}getOutput(){return this.ctx.kicadSch}},F0=class extends dt{_step(){const{kicadSch:n}=this.ctx;if(!n)throw new Error("KicadSch instance not initialized in context");const t=new Pp,e=new b_;e.value="/";const s=new k_("1");e.pages=[s],t.paths=[e],n.sheetInstances=t,n.embeddedFonts=new yp(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function z0(n){var h,d;const t=n.schematic_component.list(),e=n.schematic_trace.list();let s=1/0,r=1/0,i=-1/0,a=-1/0;for(const p of t){const u=((h=p.size)==null?void 0:h.width)??0,g=((d=p.size)==null?void 0:d.height)??0;s=Math.min(s,p.center.x-u/2),r=Math.min(r,p.center.y-g/2),i=Math.max(i,p.center.x+u/2),a=Math.max(a,p.center.y+g/2)}for(const p of e)for(const u of p.edges)s=Math.min(s,u.from.x,u.to.x),r=Math.min(r,u.from.y,u.to.y),i=Math.max(i,u.from.x,u.to.x),a=Math.max(a,u.from.y,u.to.y);s===1/0&&(s=0,r=0,i=0,a=0);const l=(s+i)/2,c=(r+a)/2;return{center:{x:l,y:c},bounds:{minX:s,minY:r,maxX:i,maxY:a}}}var U0=class{constructor(n){o(this,"ctx");o(this,"pipeline");o(this,"currentStageIndex",0);o(this,"finished",!1);const r=co(n),{center:i}=z0(r);this.ctx={db:r,circuitJson:n,kicadSch:new T_({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatSch:si(fr(148.5,105),pr(15,-15),fr(-i.x,-i.y))},this.pipeline=[new I0(n,this.ctx),new L0(n,this.ctx),new M0(n,this.ctx),new R0(n,this.ctx),new O0(n,this.ctx),new F0(n,this.ctx)]}get currentStage(){return this.pipeline[this.currentStageIndex]}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()}},j0=class extends dt{_step(){const{kicadPcb:n}=this.ctx;if(!n)throw new Error("KicadPcb instance not initialized in context");n.version=20241229;const t=new lc;t.size="A4",n.paper=t;const e=new Ip;e.thickness=1.6,n.general=e;const s=new Ap;s.padToMaskClearance=0,n.setup=s;const r=new Lp,i=[new ge({index:0,name:"F.Cu",type:"signal"}),new ge({index:2,name:"B.Cu",type:"signal"}),new ge({index:9,name:"F.Adhes",type:"user"}),new ge({index:11,name:"B.Adhes",type:"user"}),new ge({index:13,name:"F.Paste",type:"user"}),new ge({index:15,name:"B.Paste",type:"user"}),new ge({index:5,name:"F.SilkS",type:"user"}),new ge({index:7,name:"B.SilkS",type:"user"}),new ge({index:1,name:"F.Mask",type:"user"}),new ge({index:3,name:"B.Mask",type:"user"}),new ge({index:20,name:"Dwgs.User",type:"user"}),new ge({index:21,name:"Cmts.User",type:"user"}),new ge({index:22,name:"Eco1.User",type:"user"}),new ge({index:23,name:"Eco2.User",type:"user"}),new ge({index:24,name:"Edge.Cuts",type:"user"}),new ge({index:25,name:"Margin",type:"user"}),new ge({index:17,name:"B.CrtYd",type:"user"}),new ge({index:16,name:"F.CrtYd",type:"user"}),new ge({index:19,name:"B.Fab",type:"user"}),new ge({index:18,name:"F.Fab",type:"user"})];r.definitions=i,n.layers=r,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},B0=class extends dt{_step(){const{kicadPcb:n}=this.ctx;if(!n)throw new Error("KicadPcb instance not initialized in context");this.ctx.pcbNetMap||(this.ctx.pcbNetMap=new Map);const t=this.ctx.db.pcb_trace.list(),e=new Set;e.add("GND");for(const r of t)if(r.route&&r.route.length>0){const i=`Net-${r.pcb_trace_id}`;e.add(i)}let s=0;for(const r of Array.from(e).sort()){const i=new Mp(s,r),a=n.nets;a.push(i),n.nets=a,this.ctx.pcbNetMap.set(r,s),s++}this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function D0({pcbPad:n,componentCenter:t,padNumber:e,componentRotation:s=0}){if(!("x"in n&&"y"in n))throw new Error("no support for polygon pads (or any pads w/o X/Y) yet");const r=n.x-t.x,i=-(n.y-t.y),a=s!==0?gr(s*Math.PI/180):tc(),l=B(a,{x:r,y:i}),h={top:"F.Cu",bottom:"B.Cu"}[n.layer]||"F.Cu",d=n.shape==="circle"?"circle":"rect",p=n.shape==="circle"?["radius"in n?n.radius*2:.5,"radius"in n?n.radius*2:.5]:["width"in n?n.width:.5,"height"in n?n.height:.5];return new pc({number:String(e),padType:"smd",shape:d,at:[l.x,l.y,0],size:p,layers:[`${h}`,`${h==="F.Cu"?"F":"B"}.Paste`,`${h==="F.Cu"?"F":"B"}.Mask`],uuid:crypto.randomUUID()})}function W0({platedHole:n,componentCenter:t,padNumber:e,componentRotation:s=0}){if(!("x"in n&&"y"in n))return null;const r=n.x-t.x,i=-(n.y-t.y),a=s!==0?gr(s*Math.PI/180):tc(),l=B(a,{x:r,y:i});let c="circle",h,d,p=0;return n.shape==="circle"?(c="circle",h=[n.outer_diameter,n.outer_diameter],d=new Ct({diameter:n.hole_diameter})):n.shape==="pill"||n.shape==="oval"?(c="oval",h=[n.outer_width,n.outer_height],d=new Ct({oval:!0,diameter:n.hole_width,width:n.hole_height})):n.shape==="pill_hole_with_rect_pad"?(c="rect",h=[n.rect_pad_width,n.rect_pad_height],d=new Ct({oval:!0,diameter:n.hole_width,width:n.hole_height})):n.shape==="circular_hole_with_rect_pad"?(c="rect",h=[n.rect_pad_width,n.rect_pad_height],d=new Ct({diameter:n.hole_diameter})):n.shape==="rotated_pill_hole_with_rect_pad"?(c="rect",h=[n.rect_pad_width,n.rect_pad_height],d=new Ct({oval:!0,diameter:n.hole_width,width:n.hole_height}),p=n.rect_ccw_rotation||0):(c="circle",h=[1.6,1.6],d=new Ct({diameter:.8})),new pc({number:String(e),padType:"thru_hole",shape:c,at:[l.x,l.y,p],size:h,drill:d,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:crypto.randomUUID()})}function G0({pcbHole:n,componentCenter:t,componentRotation:e=0}){if(!("x"in n&&"y"in n))return null;const s=n.x-t.x,r=-(n.y-t.y),i=e!==0?gr(e*Math.PI/180):tc(),a=B(i,{x:s,y:r});let l="circle",c,h;if(n.hole_shape==="circle"){l="circle";const d=n.hole_diameter;c=[d,d],h=new Ct({diameter:d})}else if(n.hole_shape==="oval"){l="oval";const d=n.hole_width,p=n.hole_height;c=[d,p],h=new Ct({oval:!0,diameter:d,width:p})}else{l="circle";const d=n.hole_diameter||1;c=[d,d],h=new Ct({diameter:d})}return new pc({number:"",padType:"np_thru_hole",shape:l,at:[a.x,a.y,0],size:c,drill:h,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:crypto.randomUUID()})}function V0({textElement:n,componentCenter:t,componentRotation:e=0}){if(!n.text||!n.anchor_position)return null;const s=n.anchor_position.x-t.x,r=-(n.anchor_position.y-t.y),i=e!==0?gr(e*Math.PI/180):tc(),a=B(i,{x:s,y:r}),l={x:a.x,y:a.y},h={top:"F.SilkS",bottom:"B.SilkS"}[n.layer]||n.layer||"F.SilkS",d=(n.font_size||1)/1.5,p=new Xt;p.size={width:d,height:d};const u=new Yt({font:p}),g=n.ccw_rotation||0;return new em({type:"user",text:n.text,position:{x:l.x,y:l.y,angle:g},layer:h,effects:u})}var H0=class extends dt{constructor(t,e){super(t,e);o(this,"componentsProcessed",0);o(this,"pcbComponents",[]);this.pcbComponents=this.ctx.db.pcb_component.list()}_step(){var v,m,y,w;const{kicadPcb:t,c2kMatPcb:e}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!e)throw new Error("PCB transformation matrix not initialized in context");if(this.componentsProcessed>=this.pcbComponents.length){this.finished=!0;return}const s=this.pcbComponents[this.componentsProcessed],r=s.source_component_id?this.ctx.db.source_component.get(s.source_component_id):null,i=(r==null?void 0:r.ftype)||"Unknown",a=B(e,{x:s.center.x,y:s.center.y}),l=new Cp({libraryLink:`tscircuit:${i}`,layer:"F.Cu",at:[a.x,a.y,s.rotation||0],uuid:crypto.randomUUID()}),c=l.fpTexts,h=((v=this.ctx.db.pcb_silkscreen_text)==null?void 0:v.list().filter(b=>b.pcb_component_id===s.pcb_component_id))||[];for(const b of h){const k=V0({textElement:b,componentCenter:s.center,componentRotation:s.rotation||0});k&&c.push(k)}l.fpTexts=c;const d=((m=this.ctx.db.pcb_smtpad)==null?void 0:m.list().filter(b=>b.pcb_component_id===s.pcb_component_id))||[],p=l.fpPads;let u=1;for(const b of d){const k=D0({pcbPad:b,componentCenter:s.center,padNumber:u,componentRotation:s.rotation||0});p.push(k),u++}const g=((y=this.ctx.db.pcb_plated_hole)==null?void 0:y.list().filter(b=>b.pcb_component_id===s.pcb_component_id))||[];for(const b of g){const k=W0({platedHole:b,componentCenter:s.center,padNumber:u,componentRotation:s.rotation||0});k&&(p.push(k),u++)}const _=((w=this.ctx.db.pcb_hole)==null?void 0:w.list().filter(b=>b.subcircuit_id===s.subcircuit_id))||[];for(const b of _){const k=G0({pcbHole:b,componentCenter:s.center,componentRotation:s.rotation||0});k&&p.push(k)}l.fpPads=p;const x=t.footprints;x.push(l),t.footprints=x,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},Y0=class extends dt{constructor(t,e){super(t,e);o(this,"tracesProcessed",0);o(this,"pcbTraces",[]);this.pcbTraces=this.ctx.db.pcb_trace.list()}_step(){const{kicadPcb:t,c2kMatPcb:e,pcbNetMap:s}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!e)throw new Error("PCB transformation matrix not initialized in context");if(this.tracesProcessed>=this.pcbTraces.length){this.finished=!0;return}const r=this.pcbTraces[this.tracesProcessed];if(!r.route||r.route.length<2){this.tracesProcessed++;return}for(let i=0;i<r.route.length-1;i++){const a=r.route[i],l=r.route[i+1],c=B(e,{x:a.x,y:a.y}),h=B(e,{x:l.x,y:l.y});let d=0;if(s){const x=`Net-${r.pcb_trace_id}`;d=s.get(x)??0}const u={top:"F.Cu",bottom:"B.Cu"}[a.layer]||a.layer||"F.Cu",g=new $p({start:{x:c.x,y:c.y},end:{x:h.x,y:h.y},layer:u,width:r.width||.25,net:new Ga(d)}),_=t.segments;_.push(g),t.segments=_}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},X0=class extends dt{constructor(t,e){var s;super(t,e);o(this,"viasProcessed",0);o(this,"pcbVias",[]);this.pcbVias=((s=this.ctx.db.pcb_via)==null?void 0:s.list())||[]}_step(){const{kicadPcb:t,c2kMatPcb:e,pcbNetMap:s}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!e)throw new Error("PCB transformation matrix not initialized in context");if(this.viasProcessed>=this.pcbVias.length){this.finished=!0;return}const r=this.pcbVias[this.viasProcessed],i=B(e,{x:r.x,y:r.y});let a=0;s&&r.net_name&&(a=s.get(r.net_name)??0);const l=new Op({at:[i.x,i.y],size:r.outer_diameter||.8,drill:r.hole_diameter||.4,layers:["F.Cu","B.Cu"],net:new Rp(a)}),c=t.vias;c.push(l),t.vias=c,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}};function q0({textElement:n,c2kMatPcb:t}){if(!n.text||!n.anchor_position)return null;const e=B(t,{x:n.anchor_position.x,y:n.anchor_position.y}),r={top:"F.SilkS",bottom:"B.SilkS"}[n.layer]||n.layer||"F.SilkS",i=(n.font_size||1)/1.5,a=new Xt;a.size={width:i,height:i};const l=new ac,c=n.anchor_alignment||"center";switch(c){case"top_left":l.horizontal="left",l.vertical="top";break;case"top_right":l.horizontal="right",l.vertical="top";break;case"bottom_left":l.horizontal="left",l.vertical="bottom";break;case"bottom_right":l.horizontal="right",l.vertical="bottom";break}const h=new Yt({font:a});c!=="center"&&(h.justify=l);const d=n.ccw_rotation||0,p=new he([e.x,e.y,d]),u=new Np({text:n.text,layer:r,effects:h});return u.position=p,u}var K0=class extends dt{_step(){var i,a,l;const{kicadPcb:n,c2kMatPcb:t}=this.ctx;if(!n)throw new Error("KicadPcb instance not initialized in context");if(!t)throw new Error("PCB transformation matrix not initialized in context");const e=((i=this.ctx.db.pcb_silkscreen_path)==null?void 0:i.list())||[];for(const c of e)if(!(!c.route||c.route.length<2))for(let h=0;h<c.route.length-1;h++){const d=c.route[h],p=c.route[h+1];if(!d||!p)continue;const u=B(t,{x:d.x,y:d.y}),g=B(t,{x:p.x,y:p.y}),x={top:"F.SilkS",bottom:"B.SilkS"}[c.layer]||c.layer||"F.SilkS",v=new Wa({start:{x:u.x,y:u.y},end:{x:g.x,y:g.y},layer:x,width:c.stroke_width||.15}),m=n.graphicLines;m.push(v),n.graphicLines=m}const s=((a=this.ctx.db.pcb_silkscreen_text)==null?void 0:a.list().filter(c=>!c.pcb_component_id))||[];for(const c of s){const h=q0({textElement:c,c2kMatPcb:t});if(h){const d=n.graphicTexts;d.push(h),n.graphicTexts=d}}const r=((l=this.ctx.db.pcb_board)==null?void 0:l.list())||[];if(r.length>0){const c=r[0];if(!c){this.finished=!0;return}let h;if(c.outline&&c.outline.length>0)h=c.outline;else{const p=c.width/2,u=c.height/2;h=[{x:c.center.x-p,y:c.center.y-u},{x:c.center.x+p,y:c.center.y-u},{x:c.center.x+p,y:c.center.y+u},{x:c.center.x-p,y:c.center.y+u}]}const d=h.map(p=>B(t,p));for(let p=0;p<d.length;p++){const u=d[p],g=d[(p+1)%d.length];if(!u||!g)continue;const _=new Wa({start:{x:u.x,y:u.y},end:{x:g.x,y:g.y},layer:"Edge.Cuts",width:.1}),x=n.graphicLines;x.push(_),n.graphicLines=x}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},J0=class{constructor(n){o(this,"ctx");o(this,"pipeline");o(this,"currentStageIndex",0);o(this,"finished",!1);this.ctx={db:co(n),circuitJson:n,kicadPcb:new hx({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:si(fr(100,100),pr(1,-1))},this.pipeline=[new j0(n,this.ctx),new B0(n,this.ctx),new H0(n,this.ctx),new Y0(n,this.ctx),new X0(n,this.ctx),new K0(n,this.ctx)]}get currentStage(){return this.pipeline[this.currentStageIndex]}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()}},Z0=class{constructor(n,t={}){o(this,"ctx");o(this,"project");var a;const e=t.projectName??((a=n==null?void 0:n.project)==null?void 0:a.name)??"circuit-json-project",s=t.schematicFilename??`${e}.kicad_sch`,r=t.pcbFilename??`${e}.kicad_pcb`,i=new Date().toISOString();this.ctx={db:co(n),circuitJson:n},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:e,created:i,modified:i},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:[s]},board:{meta:{version:1},last_opened_board:r},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
|
|
156
|
+
`}};const Q0=(n,t)=>{const e=new J0(n);e.runUntilFinished();const s=e.getOutputString(),r=new U0(n);r.runUntilFinished();const i=r.getOutputString(),a=new Z0(n,{projectName:t,schematicFilename:`${t}.kicad_sch`,pcbFilename:`${t}.kicad_pcb`});a.runUntilFinished();const l=a.getOutputString(),c=new ig;c.file(`${t}.kicad_pcb`,s),c.file(`${t}.kicad_sch`,i),c.file(`${t}.kicad_pro`,l),c.generateAsync({type:"blob"}).then(h=>{tt.saveAs(h,`${t}_kicad.zip`)})},Vf=async(n,t,e)=>{const s=await Vx(n,e);let r,i=(e==null?void 0:e.format)==="glb"?".glb":".gltf";if(s instanceof ArrayBuffer)r=new Blob([s],{type:"model/gltf-binary"}),i=e!=null&&e.format?e.format==="glb"?".glb":".gltf":".glb";else if(typeof ArrayBuffer<"u"&&s&&typeof s.buffer=="object"&&s.byteLength!==void 0){const a=s;r=new Blob([a],{type:"model/gltf-binary"}),i=e!=null&&e.format?e.format==="glb"?".glb":".gltf":".glb"}else typeof s=="string"?r=new Blob([s],{type:"model/gltf+json"}):r=new Blob([JSON.stringify(s)],{type:"model/gltf+json"});tt.saveAs(r,t+i)},ux=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",eS=ux+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040",tS="["+ux+"]["+eS+"]*",sS=new RegExp("^"+tS+"$");function px(n,t){const e=[];let s=t.exec(n);for(;s;){const r=[];r.startIndex=t.lastIndex-s[0].length;const i=s.length;for(let a=0;a<i;a++)r.push(s[a]);e.push(r),s=t.exec(n)}return e}const gc=function(n){const t=sS.exec(n);return!(t===null||typeof t>"u")};function nS(n){return typeof n<"u"}const rS={allowBooleanAttributes:!1,unpairedTags:[]};function iS(n,t){t=Object.assign({},rS,t);const e=[];let s=!1,r=!1;n[0]==="\uFEFF"&&(n=n.substr(1));for(let i=0;i<n.length;i++)if(n[i]==="<"&&n[i+1]==="?"){if(i+=2,i=Yf(n,i),i.err)return i}else if(n[i]==="<"){let a=i;if(i++,n[i]==="!"){i=Xf(n,i);continue}else{let l=!1;n[i]==="/"&&(l=!0,i++);let c="";for(;i<n.length&&n[i]!==">"&&n[i]!==" "&&n[i]!==" "&&n[i]!==`
|
|
157
|
+
`&&n[i]!=="\r";i++)c+=n[i];if(c=c.trim(),c[c.length-1]==="/"&&(c=c.substring(0,c.length-1),i--),!pS(c)){let p;return c.trim().length===0?p="Invalid space after '<'.":p="Tag '"+c+"' is an invalid name.",xe("InvalidTag",p,De(n,i))}const h=cS(n,i);if(h===!1)return xe("InvalidAttr","Attributes for '"+c+"' have open quote.",De(n,i));let d=h.value;if(i=h.index,d[d.length-1]==="/"){const p=i-d.length;d=d.substring(0,d.length-1);const u=qf(d,t);if(u===!0)s=!0;else return xe(u.err.code,u.err.msg,De(n,p+u.err.line))}else if(l)if(h.tagClosed){if(d.trim().length>0)return xe("InvalidTag","Closing tag '"+c+"' can't have attributes or invalid starting.",De(n,a));if(e.length===0)return xe("InvalidTag","Closing tag '"+c+"' has not been opened.",De(n,a));{const p=e.pop();if(c!==p.tagName){let u=De(n,p.tagStartPos);return xe("InvalidTag","Expected closing tag '"+p.tagName+"' (opened in line "+u.line+", col "+u.col+") instead of closing tag '"+c+"'.",De(n,a))}e.length==0&&(r=!0)}}else return xe("InvalidTag","Closing tag '"+c+"' doesn't have proper closing.",De(n,i));else{const p=qf(d,t);if(p!==!0)return xe(p.err.code,p.err.msg,De(n,i-d.length+p.err.line));if(r===!0)return xe("InvalidXml","Multiple possible root nodes found.",De(n,i));t.unpairedTags.indexOf(c)!==-1||e.push({tagName:c,tagStartPos:a}),s=!0}for(i++;i<n.length;i++)if(n[i]==="<")if(n[i+1]==="!"){i++,i=Xf(n,i);continue}else if(n[i+1]==="?"){if(i=Yf(n,++i),i.err)return i}else break;else if(n[i]==="&"){const p=dS(n,i);if(p==-1)return xe("InvalidChar","char '&' is not expected.",De(n,i));i=p}else if(r===!0&&!Hf(n[i]))return xe("InvalidXml","Extra text at the end",De(n,i));n[i]==="<"&&i--}}else{if(Hf(n[i]))continue;return xe("InvalidChar","char '"+n[i]+"' is not expected.",De(n,i))}if(s){if(e.length==1)return xe("InvalidTag","Unclosed tag '"+e[0].tagName+"'.",De(n,e[0].tagStartPos));if(e.length>0)return xe("InvalidXml","Invalid '"+JSON.stringify(e.map(i=>i.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1})}else return xe("InvalidXml","Start tag expected.",1);return!0}function Hf(n){return n===" "||n===" "||n===`
|
|
158
|
+
`||n==="\r"}function Yf(n,t){const e=t;for(;t<n.length;t++)if(n[t]=="?"||n[t]==" "){const s=n.substr(e,t-e);if(t>5&&s==="xml")return xe("InvalidXml","XML declaration allowed only at the start of the document.",De(n,t));if(n[t]=="?"&&n[t+1]==">"){t++;break}else continue}return t}function Xf(n,t){if(n.length>t+5&&n[t+1]==="-"&&n[t+2]==="-"){for(t+=3;t<n.length;t++)if(n[t]==="-"&&n[t+1]==="-"&&n[t+2]===">"){t+=2;break}}else if(n.length>t+8&&n[t+1]==="D"&&n[t+2]==="O"&&n[t+3]==="C"&&n[t+4]==="T"&&n[t+5]==="Y"&&n[t+6]==="P"&&n[t+7]==="E"){let e=1;for(t+=8;t<n.length;t++)if(n[t]==="<")e++;else if(n[t]===">"&&(e--,e===0))break}else if(n.length>t+9&&n[t+1]==="["&&n[t+2]==="C"&&n[t+3]==="D"&&n[t+4]==="A"&&n[t+5]==="T"&&n[t+6]==="A"&&n[t+7]==="["){for(t+=8;t<n.length;t++)if(n[t]==="]"&&n[t+1]==="]"&&n[t+2]===">"){t+=2;break}}return t}const oS='"',aS="'";function cS(n,t){let e="",s="",r=!1;for(;t<n.length;t++){if(n[t]===oS||n[t]===aS)s===""?s=n[t]:s!==n[t]||(s="");else if(n[t]===">"&&s===""){r=!0;break}e+=n[t]}return s!==""?!1:{value:e,index:t,tagClosed:r}}const lS=new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,"g");function qf(n,t){const e=px(n,lS),s={};for(let r=0;r<e.length;r++){if(e[r][1].length===0)return xe("InvalidAttr","Attribute '"+e[r][2]+"' has no space in starting.",Si(e[r]));if(e[r][3]!==void 0&&e[r][4]===void 0)return xe("InvalidAttr","Attribute '"+e[r][2]+"' is without value.",Si(e[r]));if(e[r][3]===void 0&&!t.allowBooleanAttributes)return xe("InvalidAttr","boolean attribute '"+e[r][2]+"' is not allowed.",Si(e[r]));const i=e[r][2];if(!uS(i))return xe("InvalidAttr","Attribute '"+i+"' is an invalid name.",Si(e[r]));if(!s.hasOwnProperty(i))s[i]=1;else return xe("InvalidAttr","Attribute '"+i+"' is repeated.",Si(e[r]))}return!0}function hS(n,t){let e=/\d/;for(n[t]==="x"&&(t++,e=/[\da-fA-F]/);t<n.length;t++){if(n[t]===";")return t;if(!n[t].match(e))break}return-1}function dS(n,t){if(t++,n[t]===";")return-1;if(n[t]==="#")return t++,hS(n,t);let e=0;for(;t<n.length;t++,e++)if(!(n[t].match(/\w/)&&e<20)){if(n[t]===";")break;return-1}return t}function xe(n,t,e){return{err:{code:n,msg:t,line:e.line||e,col:e.col}}}function uS(n){return gc(n)}function pS(n){return gc(n)}function De(n,t){const e=n.substring(0,t).split(/\r?\n/);return{line:e.length,col:e[e.length-1].length+1}}function Si(n){return n.startIndex+n[1].length}const fS={preserveOrder:!1,attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(n,t){return t},attributeValueProcessor:function(n,t){return t},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(n,t,e){return n},captureMetaData:!1},gS=function(n){return Object.assign({},fS,n)};let Va;typeof Symbol!="function"?Va="@@xmlMetadata":Va=Symbol("XML Node Metadata");class yr{constructor(t){this.tagname=t,this.child=[],this[":@"]={}}add(t,e){t==="__proto__"&&(t="#__proto__"),this.child.push({[t]:e})}addChild(t,e){t.tagname==="__proto__"&&(t.tagname="#__proto__"),t[":@"]&&Object.keys(t[":@"]).length>0?this.child.push({[t.tagname]:t.child,":@":t[":@"]}):this.child.push({[t.tagname]:t.child}),e!==void 0&&(this.child[this.child.length-1][Va]={startIndex:e})}static getMetaDataSymbol(){return Va}}class _S{constructor(t){this.suppressValidationErr=!t}readDocType(t,e){const s={};if(t[e+3]==="O"&&t[e+4]==="C"&&t[e+5]==="T"&&t[e+6]==="Y"&&t[e+7]==="P"&&t[e+8]==="E"){e=e+9;let r=1,i=!1,a=!1,l="";for(;e<t.length;e++)if(t[e]==="<"&&!a){if(i&&xr(t,"!ENTITY",e)){e+=7;let c,h;[c,h,e]=this.readEntityExp(t,e+1,this.suppressValidationErr),h.indexOf("&")===-1&&(s[c]={regx:RegExp(`&${c};`,"g"),val:h})}else if(i&&xr(t,"!ELEMENT",e)){e+=8;const{index:c}=this.readElementExp(t,e+1);e=c}else if(i&&xr(t,"!ATTLIST",e))e+=8;else if(i&&xr(t,"!NOTATION",e)){e+=9;const{index:c}=this.readNotationExp(t,e+1,this.suppressValidationErr);e=c}else if(xr(t,"!--",e))a=!0;else throw new Error("Invalid DOCTYPE");r++,l=""}else if(t[e]===">"){if(a?t[e-1]==="-"&&t[e-2]==="-"&&(a=!1,r--):r--,r===0)break}else t[e]==="["?i=!0:l+=t[e];if(r!==0)throw new Error("Unclosed DOCTYPE")}else throw new Error("Invalid Tag instead of DOCTYPE");return{entities:s,i:e}}readEntityExp(t,e){e=He(t,e);let s="";for(;e<t.length&&!/\s/.test(t[e])&&t[e]!=='"'&&t[e]!=="'";)s+=t[e],e++;if(Pi(s),e=He(t,e),!this.suppressValidationErr){if(t.substring(e,e+6).toUpperCase()==="SYSTEM")throw new Error("External entities are not supported");if(t[e]==="%")throw new Error("Parameter entities are not supported")}let r="";return[e,r]=this.readIdentifierVal(t,e,"entity"),e--,[s,r,e]}readNotationExp(t,e){e=He(t,e);let s="";for(;e<t.length&&!/\s/.test(t[e]);)s+=t[e],e++;!this.suppressValidationErr&&Pi(s),e=He(t,e);const r=t.substring(e,e+6).toUpperCase();if(!this.suppressValidationErr&&r!=="SYSTEM"&&r!=="PUBLIC")throw new Error(`Expected SYSTEM or PUBLIC, found "${r}"`);e+=r.length,e=He(t,e);let i=null,a=null;if(r==="PUBLIC")[e,i]=this.readIdentifierVal(t,e,"publicIdentifier"),e=He(t,e),(t[e]==='"'||t[e]==="'")&&([e,a]=this.readIdentifierVal(t,e,"systemIdentifier"));else if(r==="SYSTEM"&&([e,a]=this.readIdentifierVal(t,e,"systemIdentifier"),!this.suppressValidationErr&&!a))throw new Error("Missing mandatory system identifier for SYSTEM notation");return{notationName:s,publicIdentifier:i,systemIdentifier:a,index:--e}}readIdentifierVal(t,e,s){let r="";const i=t[e];if(i!=='"'&&i!=="'")throw new Error(`Expected quoted string, found "${i}"`);for(e++;e<t.length&&t[e]!==i;)r+=t[e],e++;if(t[e]!==i)throw new Error(`Unterminated ${s} value`);return e++,[e,r]}readElementExp(t,e){e=He(t,e);let s="";for(;e<t.length&&!/\s/.test(t[e]);)s+=t[e],e++;if(!this.suppressValidationErr&&!gc(s))throw new Error(`Invalid element name: "${s}"`);e=He(t,e);let r="";if(t[e]==="E"&&xr(t,"MPTY",e))e+=4;else if(t[e]==="A"&&xr(t,"NY",e))e+=2;else if(t[e]==="("){for(e++;e<t.length&&t[e]!==")";)r+=t[e],e++;if(t[e]!==")")throw new Error("Unterminated content model")}else if(!this.suppressValidationErr)throw new Error(`Invalid Element Expression, found "${t[e]}"`);return{elementName:s,contentModel:r.trim(),index:e}}readAttlistExp(t,e){e=He(t,e);let s="";for(;e<t.length&&!/\s/.test(t[e]);)s+=t[e],e++;Pi(s),e=He(t,e);let r="";for(;e<t.length&&!/\s/.test(t[e]);)r+=t[e],e++;if(!Pi(r))throw new Error(`Invalid attribute name: "${r}"`);e=He(t,e);let i="";if(t.substring(e,e+8).toUpperCase()==="NOTATION"){if(i="NOTATION",e+=8,e=He(t,e),t[e]!=="(")throw new Error(`Expected '(', found "${t[e]}"`);e++;let l=[];for(;e<t.length&&t[e]!==")";){let c="";for(;e<t.length&&t[e]!=="|"&&t[e]!==")";)c+=t[e],e++;if(c=c.trim(),!Pi(c))throw new Error(`Invalid notation name: "${c}"`);l.push(c),t[e]==="|"&&(e++,e=He(t,e))}if(t[e]!==")")throw new Error("Unterminated list of notations");e++,i+=" ("+l.join("|")+")"}else{for(;e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;const l=["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"];if(!this.suppressValidationErr&&!l.includes(i.toUpperCase()))throw new Error(`Invalid attribute type: "${i}"`)}e=He(t,e);let a="";return t.substring(e,e+8).toUpperCase()==="#REQUIRED"?(a="#REQUIRED",e+=8):t.substring(e,e+7).toUpperCase()==="#IMPLIED"?(a="#IMPLIED",e+=7):[e,a]=this.readIdentifierVal(t,e,"ATTLIST"),{elementName:s,attributeName:r,attributeType:i,defaultValue:a,index:e}}}const He=(n,t)=>{for(;t<n.length&&/\s/.test(n[t]);)t++;return t};function xr(n,t,e){for(let s=0;s<t.length;s++)if(t[s]!==n[e+s+1])return!1;return!0}function Pi(n){if(gc(n))return n;throw new Error(`Invalid entity name ${n}`)}const mS=/^[-+]?0x[a-fA-F0-9]+$/,xS=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,yS={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};function vS(n,t={}){if(t=Object.assign({},yS,t),!n||typeof n!="string")return n;let e=n.trim();if(t.skipLike!==void 0&&t.skipLike.test(e))return n;if(n==="0")return 0;if(t.hex&&mS.test(e))return SS(e,16);if(e.search(/.+[eE].+/)!==-1)return bS(n,e,t);{const s=xS.exec(e);if(s){const r=s[1]||"",i=s[2];let a=kS(s[3]);const l=r?n[i.length+1]===".":n[i.length]===".";if(!t.leadingZeros&&(i.length>1||i.length===1&&!l))return n;{const c=Number(e),h=String(c);if(c===0)return c;if(h.search(/[eE]/)!==-1)return t.eNotation?c:n;if(e.indexOf(".")!==-1)return h==="0"||h===a||h===`${r}${a}`?c:n;let d=i?a:e;return i?d===h||r+d===h?c:n:d===h||d===r+h?c:n}}else return n}}const wS=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;function bS(n,t,e){if(!e.eNotation)return n;const s=t.match(wS);if(s){let r=s[1]||"";const i=s[3].indexOf("e")===-1?"E":"e",a=s[2],l=r?n[a.length+1]===i:n[a.length]===i;return a.length>1&&l?n:a.length===1&&(s[3].startsWith(`.${i}`)||s[3][0]===i)?Number(t):e.leadingZeros&&!l?(t=(s[1]||"")+s[3],Number(t)):n}else return n}function kS(n){return n&&n.indexOf(".")!==-1&&(n=n.replace(/0+$/,""),n==="."?n="0":n[0]==="."?n="0"+n:n[n.length-1]==="."&&(n=n.substring(0,n.length-1))),n}function SS(n,t){if(parseInt)return parseInt(n,t);if(Number.parseInt)return Number.parseInt(n,t);if(window&&window.parseInt)return window.parseInt(n,t);throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")}function PS(n){return typeof n=="function"?n:Array.isArray(n)?t=>{for(const e of n)if(typeof e=="string"&&t===e||e instanceof RegExp&&e.test(t))return!0}:()=>!1}class TS{constructor(t){this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"¢"},pound:{regex:/&(pound|#163);/g,val:"£"},yen:{regex:/&(yen|#165);/g,val:"¥"},euro:{regex:/&(euro|#8364);/g,val:"€"},copyright:{regex:/&(copy|#169);/g,val:"©"},reg:{regex:/&(reg|#174);/g,val:"®"},inr:{regex:/&(inr|#8377);/g,val:"₹"},num_dec:{regex:/&#([0-9]{1,7});/g,val:(e,s)=>String.fromCodePoint(Number.parseInt(s,10))},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(e,s)=>String.fromCodePoint(Number.parseInt(s,16))}},this.addExternalEntities=ES,this.parseXml=IS,this.parseTextData=CS,this.resolveNameSpace=NS,this.buildAttributesMap=AS,this.isItStopNode=OS,this.replaceEntitiesValue=MS,this.readStopNodeData=zS,this.saveTextToParentTag=RS,this.addChild=LS,this.ignoreAttributesFn=PS(this.options.ignoreAttributes)}}function ES(n){const t=Object.keys(n);for(let e=0;e<t.length;e++){const s=t[e];this.lastEntities[s]={regex:new RegExp("&"+s+";","g"),val:n[s]}}}function CS(n,t,e,s,r,i,a){if(n!==void 0&&(this.options.trimValues&&!s&&(n=n.trim()),n.length>0)){a||(n=this.replaceEntitiesValue(n));const l=this.options.tagValueProcessor(t,n,e,r,i);return l==null?n:typeof l!=typeof n||l!==n?l:this.options.trimValues?tp(n,this.options.parseTagValue,this.options.numberParseOptions):n.trim()===n?tp(n,this.options.parseTagValue,this.options.numberParseOptions):n}}function NS(n){if(this.options.removeNSPrefix){const t=n.split(":"),e=n.charAt(0)==="/"?"/":"";if(t[0]==="xmlns")return"";t.length===2&&(n=e+t[1])}return n}const $S=new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`,"gm");function AS(n,t,e){if(this.options.ignoreAttributes!==!0&&typeof n=="string"){const s=px(n,$S),r=s.length,i={};for(let a=0;a<r;a++){const l=this.resolveNameSpace(s[a][1]);if(this.ignoreAttributesFn(l,t))continue;let c=s[a][4],h=this.options.attributeNamePrefix+l;if(l.length)if(this.options.transformAttributeName&&(h=this.options.transformAttributeName(h)),h==="__proto__"&&(h="#__proto__"),c!==void 0){this.options.trimValues&&(c=c.trim()),c=this.replaceEntitiesValue(c);const d=this.options.attributeValueProcessor(l,c,t);d==null?i[h]=c:typeof d!=typeof c||d!==c?i[h]=d:i[h]=tp(c,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(i[h]=!0)}if(!Object.keys(i).length)return;if(this.options.attributesGroupName){const a={};return a[this.options.attributesGroupName]=i,a}return i}}const IS=function(n){n=n.replace(/\r\n?/g,`
|
|
159
|
+
`);const t=new yr("!xml");let e=t,s="",r="";const i=new _S(this.options.processEntities);for(let a=0;a<n.length;a++)if(n[a]==="<")if(n[a+1]==="/"){const c=br(n,">",a,"Closing Tag is not closed.");let h=n.substring(a+2,c).trim();if(this.options.removeNSPrefix){const u=h.indexOf(":");u!==-1&&(h=h.substr(u+1))}this.options.transformTagName&&(h=this.options.transformTagName(h)),e&&(s=this.saveTextToParentTag(s,e,r));const d=r.substring(r.lastIndexOf(".")+1);if(h&&this.options.unpairedTags.indexOf(h)!==-1)throw new Error(`Unpaired tag can not be used as closing tag: </${h}>`);let p=0;d&&this.options.unpairedTags.indexOf(d)!==-1?(p=r.lastIndexOf(".",r.lastIndexOf(".")-1),this.tagsNodeStack.pop()):p=r.lastIndexOf("."),r=r.substring(0,p),e=this.tagsNodeStack.pop(),s="",a=c}else if(n[a+1]==="?"){let c=ep(n,a,!1,"?>");if(!c)throw new Error("Pi Tag is not closed.");if(s=this.saveTextToParentTag(s,e,r),!(this.options.ignoreDeclaration&&c.tagName==="?xml"||this.options.ignorePiTags)){const h=new yr(c.tagName);h.add(this.options.textNodeName,""),c.tagName!==c.tagExp&&c.attrExpPresent&&(h[":@"]=this.buildAttributesMap(c.tagExp,r,c.tagName)),this.addChild(e,h,r,a)}a=c.closeIndex+1}else if(n.substr(a+1,3)==="!--"){const c=br(n,"-->",a+4,"Comment is not closed.");if(this.options.commentPropName){const h=n.substring(a+4,c-2);s=this.saveTextToParentTag(s,e,r),e.add(this.options.commentPropName,[{[this.options.textNodeName]:h}])}a=c}else if(n.substr(a+1,2)==="!D"){const c=i.readDocType(n,a);this.docTypeEntities=c.entities,a=c.i}else if(n.substr(a+1,2)==="!["){const c=br(n,"]]>",a,"CDATA is not closed.")-2,h=n.substring(a+9,c);s=this.saveTextToParentTag(s,e,r);let d=this.parseTextData(h,e.tagname,r,!0,!1,!0,!0);d==null&&(d=""),this.options.cdataPropName?e.add(this.options.cdataPropName,[{[this.options.textNodeName]:h}]):e.add(this.options.textNodeName,d),a=c+2}else{let c=ep(n,a,this.options.removeNSPrefix),h=c.tagName;const d=c.rawTagName;let p=c.tagExp,u=c.attrExpPresent,g=c.closeIndex;this.options.transformTagName&&(h=this.options.transformTagName(h)),e&&s&&e.tagname!=="!xml"&&(s=this.saveTextToParentTag(s,e,r,!1));const _=e;_&&this.options.unpairedTags.indexOf(_.tagname)!==-1&&(e=this.tagsNodeStack.pop(),r=r.substring(0,r.lastIndexOf("."))),h!==t.tagname&&(r+=r?"."+h:h);const x=a;if(this.isItStopNode(this.options.stopNodes,r,h)){let v="";if(p.length>0&&p.lastIndexOf("/")===p.length-1)h[h.length-1]==="/"?(h=h.substr(0,h.length-1),r=r.substr(0,r.length-1),p=h):p=p.substr(0,p.length-1),a=c.closeIndex;else if(this.options.unpairedTags.indexOf(h)!==-1)a=c.closeIndex;else{const y=this.readStopNodeData(n,d,g+1);if(!y)throw new Error(`Unexpected end of ${d}`);a=y.i,v=y.tagContent}const m=new yr(h);h!==p&&u&&(m[":@"]=this.buildAttributesMap(p,r,h)),v&&(v=this.parseTextData(v,h,r,!0,u,!0,!0)),r=r.substr(0,r.lastIndexOf(".")),m.add(this.options.textNodeName,v),this.addChild(e,m,r,x)}else{if(p.length>0&&p.lastIndexOf("/")===p.length-1){h[h.length-1]==="/"?(h=h.substr(0,h.length-1),r=r.substr(0,r.length-1),p=h):p=p.substr(0,p.length-1),this.options.transformTagName&&(h=this.options.transformTagName(h));const v=new yr(h);h!==p&&u&&(v[":@"]=this.buildAttributesMap(p,r,h)),this.addChild(e,v,r,x),r=r.substr(0,r.lastIndexOf("."))}else{const v=new yr(h);this.tagsNodeStack.push(e),h!==p&&u&&(v[":@"]=this.buildAttributesMap(p,r,h)),this.addChild(e,v,r,x),e=v}s="",a=g}}else s+=n[a];return t.child};function LS(n,t,e,s){this.options.captureMetaData||(s=void 0);const r=this.options.updateTag(t.tagname,e,t[":@"]);r===!1||(typeof r=="string"&&(t.tagname=r),n.addChild(t,s))}const MS=function(n){if(this.options.processEntities){for(let t in this.docTypeEntities){const e=this.docTypeEntities[t];n=n.replace(e.regx,e.val)}for(let t in this.lastEntities){const e=this.lastEntities[t];n=n.replace(e.regex,e.val)}if(this.options.htmlEntities)for(let t in this.htmlEntities){const e=this.htmlEntities[t];n=n.replace(e.regex,e.val)}n=n.replace(this.ampEntity.regex,this.ampEntity.val)}return n};function RS(n,t,e,s){return n&&(s===void 0&&(s=t.child.length===0),n=this.parseTextData(n,t.tagname,e,!1,t[":@"]?Object.keys(t[":@"]).length!==0:!1,s),n!==void 0&&n!==""&&t.add(this.options.textNodeName,n),n=""),n}function OS(n,t,e){const s="*."+e;for(const r in n){const i=n[r];if(s===i||t===i)return!0}return!1}function FS(n,t,e=">"){let s,r="";for(let i=t;i<n.length;i++){let a=n[i];if(s)a===s&&(s="");else if(a==='"'||a==="'")s=a;else if(a===e[0])if(e[1]){if(n[i+1]===e[1])return{data:r,index:i}}else return{data:r,index:i};else a===" "&&(a=" ");r+=a}}function br(n,t,e,s){const r=n.indexOf(t,e);if(r===-1)throw new Error(s);return r+t.length-1}function ep(n,t,e,s=">"){const r=FS(n,t+1,s);if(!r)return;let i=r.data;const a=r.index,l=i.search(/\s/);let c=i,h=!0;l!==-1&&(c=i.substring(0,l),i=i.substring(l+1).trimStart());const d=c;if(e){const p=c.indexOf(":");p!==-1&&(c=c.substr(p+1),h=c!==r.data.substr(p+1))}return{tagName:c,tagExp:i,closeIndex:a,attrExpPresent:h,rawTagName:d}}function zS(n,t,e){const s=e;let r=1;for(;e<n.length;e++)if(n[e]==="<")if(n[e+1]==="/"){const i=br(n,">",e,`${t} is not closed`);if(n.substring(e+2,i).trim()===t&&(r--,r===0))return{tagContent:n.substring(s,e),i};e=i}else if(n[e+1]==="?")e=br(n,"?>",e+1,"StopNode is not closed.");else if(n.substr(e+1,3)==="!--")e=br(n,"-->",e+3,"StopNode is not closed.");else if(n.substr(e+1,2)==="![")e=br(n,"]]>",e,"StopNode is not closed.")-2;else{const i=ep(n,e,">");i&&((i&&i.tagName)===t&&i.tagExp[i.tagExp.length-1]!=="/"&&r++,e=i.closeIndex)}}function tp(n,t,e){if(t&&typeof n=="string"){const s=n.trim();return s==="true"?!0:s==="false"?!1:vS(n,e)}else return nS(n)?n:""}const Rc=yr.getMetaDataSymbol();function US(n,t){return fx(n,t)}function fx(n,t,e){let s;const r={};for(let i=0;i<n.length;i++){const a=n[i],l=jS(a);let c="";if(e===void 0?c=l:c=e+"."+l,l===t.textNodeName)s===void 0?s=a[l]:s+=""+a[l];else{if(l===void 0)continue;if(a[l]){let h=fx(a[l],t,c);const d=DS(h,t);a[Rc]!==void 0&&(h[Rc]=a[Rc]),a[":@"]?BS(h,a[":@"],c,t):Object.keys(h).length===1&&h[t.textNodeName]!==void 0&&!t.alwaysCreateTextNode?h=h[t.textNodeName]:Object.keys(h).length===0&&(t.alwaysCreateTextNode?h[t.textNodeName]="":h=""),r[l]!==void 0&&r.hasOwnProperty(l)?(Array.isArray(r[l])||(r[l]=[r[l]]),r[l].push(h)):t.isArray(l,c,d)?r[l]=[h]:r[l]=h}}}return typeof s=="string"?s.length>0&&(r[t.textNodeName]=s):s!==void 0&&(r[t.textNodeName]=s),r}function jS(n){const t=Object.keys(n);for(let e=0;e<t.length;e++){const s=t[e];if(s!==":@")return s}}function BS(n,t,e,s){if(t){const r=Object.keys(t),i=r.length;for(let a=0;a<i;a++){const l=r[a];s.isArray(l,e+"."+l,!0,!0)?n[l]=[t[l]]:n[l]=t[l]}}}function DS(n,t){const{textNodeName:e}=t,s=Object.keys(n).length;return!!(s===0||s===1&&(n[e]||typeof n[e]=="boolean"||n[e]===0))}class WS{constructor(t){this.externalEntities={},this.options=gS(t)}parse(t,e){if(typeof t!="string"&&t.toString)t=t.toString();else if(typeof t!="string")throw new Error("XML data is accepted in String or Bytes[] form.");if(e){e===!0&&(e={});const i=iS(t,e);if(i!==!0)throw Error(`${i.err.msg}:${i.err.line}:${i.err.col}`)}const s=new TS(this.options);s.addExternalEntities(this.externalEntities);const r=s.parseXml(t);return this.options.preserveOrder||r===void 0?r:US(r,this.options)}addEntity(t,e){if(e.indexOf("&")!==-1)throw new Error("Entity value can't have '&'");if(t.indexOf("&")!==-1||t.indexOf(";")!==-1)throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'");if(e==="&")throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=e}static getMetaDataSymbol(){return yr.getMetaDataSymbol()}}function Et(n,t){return{x:n.x+t.x,y:n.y+t.y,z:n.z+t.z}}function Pe(n,t){return{x:n.x-t.x,y:n.y-t.y,z:n.z-t.z}}function lt(n,t){return n.x*t.x+n.y*t.y+n.z*t.z}function cr(n,t){return{x:n.y*t.z-n.z*t.y,y:n.z*t.x-n.x*t.z,z:n.x*t.y-n.y*t.x}}function dr(n,t){return{x:n.x*t,y:n.y*t,z:n.z*t}}function Ui(n){return Math.sqrt(lt(n,n))}function ji(n){const t=Ui(n)||1;return dr(n,1/t)}function $i(n,t={x:0,y:0,z:0}){let{x:e,y:s,z:r}=n;if(t.x){const i=Math.cos(t.x),a=Math.sin(t.x),l=s*i-r*a;r=s*a+r*i,s=l}if(t.y){const i=Math.cos(t.y),a=Math.sin(t.y),l=e*i+r*a;r=-e*a+r*i,e=l}if(t.z){const i=Math.cos(t.z),a=Math.sin(t.z),l=e*i-s*a;s=e*a+s*i,e=l}return{x:e,y:s,z:r}}var GS={black:[0,0,0],silver:[192,192,192],gray:[128,128,128],grey:[128,128,128],white:[255,255,255],maroon:[128,0,0],red:[255,0,0],purple:[128,0,128],fuchsia:[255,0,255],green:[0,128,0],lime:[0,255,0],olive:[128,128,0],yellow:[255,255,0],navy:[0,0,128],blue:[0,0,255],teal:[0,128,128],aqua:[0,255,255],orange:[255,165,0]};function Bi(n){if(typeof n=="string")return n;const[t,e,s,r]=n;return`rgba(${Math.round(t)},${Math.round(e)},${Math.round(s)},${r})`}function gx(n){if(Array.isArray(n))return n;const t=n.trim().toLowerCase();if(t.startsWith("#")){const r=t.slice(1);if(r.length===3){const i=parseInt(r.charAt(0)+r.charAt(0),16),a=parseInt(r.charAt(1)+r.charAt(1),16),l=parseInt(r.charAt(2)+r.charAt(2),16);return[i,a,l,1]}if(r.length===6){const i=parseInt(r.slice(0,2),16),a=parseInt(r.slice(2,4),16),l=parseInt(r.slice(4,6),16);return[i,a,l,1]}}const e=t.match(/^rgba?\(([^)]+)\)$/);if(e){const i=e[1].split(/\s*,\s*/).map(Number),[a=0,l=0,c=0,h=1]=i;return[a,l,c,h]}const s=GS[t];return s?[s[0],s[1],s[2],1]:[0,0,0,1]}function VS(n,t){const[e,s,r,i]=gx(n);return[e+(255-e)*t,s+(255-s)*t,r+(255-r)*t,i]}function HS(n,t){const[e,s,r,i]=gx(n);return[e*(1-t),s*(1-t),r*(1-t),i]}function Oc(n,t){const e=ji(t);return e.z>=0?Bi(VS(n,e.z*.4)):Bi(HS(n,-e.z*.4))}var Fc=new Map;async function YS(n){if(Fc.has(n))return Fc.get(n);const e=await(await fetch(n)).arrayBuffer(),s=XS(e);return Fc.set(n,s),s}function XS(n){const t=new DataView(n);return new TextDecoder().decode(n.slice(0,5)).toLowerCase()==="solid"?qS(n):KS(t)}function qS(n){const e=new TextDecoder().decode(n).split(`
|
|
160
|
+
`).map(a=>a.trim()),s=[];let r=0;for(;r<e.length;){const a=e[r];if(a&&a.startsWith("facet normal")){const l=a.match(/facet normal\s+([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)\s+([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)\s+([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)/),c=l?{x:parseFloat(l[1]),y:parseFloat(l[2]),z:parseFloat(l[3])}:{x:0,y:0,z:1};r++;const h=[];for(;r<e.length&&e[r]&&!e[r].startsWith("endfacet");){const d=e[r];if(d.startsWith("vertex")){const p=d.match(/vertex\s+([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)\s+([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)\s+([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)/);p&&h.push({x:parseFloat(p[1]),y:parseFloat(p[2]),z:parseFloat(p[3])})}r++}h.length===3&&s.push({vertices:[h[0],h[1],h[2]],normal:c})}r++}const i=s.map(a=>({...a,vertices:a.vertices.map(l=>({x:l.x,y:-l.z,z:l.y})),normal:{x:a.normal.x,y:-a.normal.z,z:a.normal.y}}));return{triangles:i,boundingBox:_x(i)}}function KS(n){let t=80;const e=n.getUint32(t,!0);t+=4;const s=[];for(let i=0;i<e;i++){const a={x:n.getFloat32(t,!0),y:n.getFloat32(t+4,!0),z:n.getFloat32(t+8,!0)};t+=12;const l=[{x:n.getFloat32(t,!0),y:n.getFloat32(t+4,!0),z:n.getFloat32(t+8,!0)},{x:n.getFloat32(t+12,!0),y:n.getFloat32(t+16,!0),z:n.getFloat32(t+20,!0)},{x:n.getFloat32(t+24,!0),y:n.getFloat32(t+28,!0),z:n.getFloat32(t+32,!0)}];t+=36,t+=2,s.push({vertices:l,normal:a})}const r=s.map(i=>({...i,vertices:i.vertices.map(a=>({x:a.x,y:-a.z,z:a.y})),normal:{x:i.normal.x,y:-i.normal.z,z:i.normal.y}}));return{triangles:r,boundingBox:_x(r)}}function _x(n){if(n.length===0)return{min:{x:0,y:0,z:0},max:{x:0,y:0,z:0}};let t=1/0,e=1/0,s=1/0,r=-1/0,i=-1/0,a=-1/0;for(const l of n)for(const c of l.vertices)t=Math.min(t,c.x),e=Math.min(e,c.y),s=Math.min(s,c.z),r=Math.max(r,c.x),i=Math.max(i,c.y),a=Math.max(a,c.z);return{min:{x:t,y:e,z:s},max:{x:r,y:i,z:a}}}var zc=new Map;async function JS(n){if(zc.has(n))return zc.get(n);const e=await(await fetch(n)).text(),s=ZS(e);return zc.set(n,s),s}function ZS(n){const t=n.split(/\r?\n/),e=[],s=[],r=[],i=[],a={};let l;for(const c of t){const h=c.trim();if(h.startsWith("v ")){const d=h.split(/\s+/),p=d[1],u=d[2],g=d[3];if(e.push({x:parseFloat(p),y:parseFloat(u),z:-parseFloat(g)}),d.length>=7){const[_,x,v]=d.slice(4,7);let m=Number(_),y=Number(x),w=Number(v);m<=1&&y<=1&&w<=1&&(m*=255,y*=255,w*=255),s.push([m,y,w,1])}else s.push(void 0)}else if(h.startsWith("vn ")){const d=h.split(/\s+/),p=d[1],u=d[2],g=d[3];r.push({x:parseFloat(p),y:parseFloat(u),z:-parseFloat(g)})}else if(h.startsWith("newmtl "))l=h.split(/\s+/)[1];else if(h.startsWith("Kd ")&&l){const d=h.split(/\s+/),p=d[1],u=d[2],g=d[3];let _=parseFloat(p),x=parseFloat(u),v=parseFloat(g);_<=1&&x<=1&&v<=1&&(_*=255,x*=255,v*=255),a[l]=[_,x,v,1]}else if(h.startsWith("usemtl "))l=h.split(/\s+/)[1];else if(h.startsWith("f ")){const p=h.slice(2).trim().split(/\s+/).map(u=>{const[g,,_]=u.split("/");return{v:parseInt(g)-1,n:_?parseInt(_)-1:void 0}});for(let u=1;u<p.length-1;u++){const g=p[0],_=p[u],x=p[u+1],v=e[g.v],m=e[_.v],y=e[x.v];let w;if(g.n!==void 0&&r[g.n])w=r[g.n];else if(_.n!==void 0&&r[_.n])w=r[_.n];else if(x.n!==void 0&&r[x.n])w=r[x.n];else{const k={x:m.x-v.x,y:m.y-v.y,z:m.z-v.z},C={x:y.x-v.x,y:y.y-v.y,z:y.z-v.z};w={x:k.y*C.z-k.z*C.y,y:k.z*C.x-k.x*C.z,z:-(k.x*C.y-k.y*C.x)}}let b;l&&a[l]?b=a[l]:b=s[g.v]??s[_.v]??s[x.v],i.push({vertices:[v,m,y],normal:w,color:b})}}}return{triangles:i,boundingBox:QS(i)}}function QS(n){if(n.length===0)return{min:{x:0,y:0,z:0},max:{x:0,y:0,z:0}};let t=1/0,e=1/0,s=1/0,r=-1/0,i=-1/0,a=-1/0;for(const l of n)for(const c of l.vertices)c.x<t&&(t=c.x),c.y<e&&(e=c.y),c.z<s&&(s=c.z),c.x>r&&(r=c.x),c.y>i&&(i=c.y),c.z>a&&(a=c.z);return{min:{x:t,y:e,z:s},max:{x:r,y:i,z:a}}}var Uc=new Map;async function eP(n){if(Uc.has(n))return Uc.get(n);const e=await(await fetch(n)).arrayBuffer(),r=Hx(new Uint8Array(e))["3D/3dmodel.model"];if(!r)throw new Error("3MF model file not found");const i=new TextDecoder().decode(r),a=tP(i);return Uc.set(n,a),a}function tP(n){var u,g,_,x,v,m,y,w,b,k,C,E;const e=new WS({ignoreAttributes:!1}).parse(n),s=((v=(x=(_=(g=(u=e==null?void 0:e.model)==null?void 0:u.resources)==null?void 0:g.object)==null?void 0:_.mesh)==null?void 0:x.vertices)==null?void 0:v.vertex)??[],i=(Array.isArray(s)?s:[s]).map(N=>({x:parseFloat(N["@_x"]),y:parseFloat(N["@_y"]),z:parseFloat(N["@_z"])})),a=(y=(m=e==null?void 0:e.model)==null?void 0:m.resources)==null?void 0:y.basematerials,l={};if(a){const N=Array.isArray(a)?a:[a];for(const I of N){const M=I["@_id"],S=I.base??[],L=Array.isArray(S)?S:[S];l[M]=L.map(R=>sP(R["@_displaycolor"]))}}const c=((E=(C=(k=(b=(w=e==null?void 0:e.model)==null?void 0:w.resources)==null?void 0:b.object)==null?void 0:k.mesh)==null?void 0:C.triangles)==null?void 0:E.triangle)??[],p=(Array.isArray(c)?c:[c]).map(N=>{const I=i[parseInt(N["@_v1"])],M=i[parseInt(N["@_v2"])],S=i[parseInt(N["@_v3"])],L={x:M.x-I.x,y:M.y-I.y,z:M.z-I.z},R={x:S.x-I.x,y:S.y-I.y,z:S.z-I.z},U={x:L.y*R.z-L.z*R.y,y:L.z*R.x-L.x*R.z,z:-(L.x*R.y-L.y*R.x)};let j;const V=N["@_pid"];if(V&&l[V]){const G=parseInt(N["@_p1"]??N["@_p2"]??N["@_p3"]??"0");j=l[V][G]}return j?{vertices:[I,M,S],normal:U,color:j}:{vertices:[I,M,S],normal:U}}).map(N=>({...N,vertices:N.vertices.map(I=>({x:I.x,y:-I.z,z:I.y})),normal:{x:N.normal.x,y:-N.normal.z,z:N.normal.y}}));return{triangles:p,boundingBox:nP(p)}}function sP(n){if(n!=null&&n.startsWith("#")){const t=n.slice(1);if(t.length===8){const e=parseInt(t.slice(0,2),16),s=parseInt(t.slice(2,4),16),r=parseInt(t.slice(4,6),16),i=parseInt(t.slice(6,8),16)/255;return[e,s,r,i]}if(t.length===6){const e=parseInt(t.slice(0,2),16),s=parseInt(t.slice(2,4),16),r=parseInt(t.slice(4,6),16);return[e,s,r,1]}}return[0,0,0,1]}function nP(n){if(n.length===0)return{min:{x:0,y:0,z:0},max:{x:0,y:0,z:0}};let t=1/0,e=1/0,s=1/0,r=-1/0,i=-1/0,a=-1/0;for(const l of n)for(const c of l.vertices)c.x<t&&(t=c.x),c.y<e&&(e=c.y),c.z<s&&(s=c.z),c.x>r&&(r=c.x),c.y>i&&(i=c.y),c.z>a&&(a=c.z);return{min:{x:t,y:e,z:s},max:{x:r,y:i,z:a}}}function jc(n,t,e,s){const{boundingBox:r}=n,i=dr(Et(r.min,r.max),.5),a=t.centerModel!==!1,l=[];for(const p of n.triangles)for(const u of p.vertices){let g=Pe(u,i);s==="stl"&&t.stlRotation&&(g=$i(g,t.stlRotation)),s==="obj"&&t.objRotation&&(g=$i(g,t.objRotation)),s==="3mf"&&t.threeMfRotation&&(g=$i(g,t.threeMfRotation)),a||(g=Et(g,i)),l.push(g)}let c=1,h={x:0,y:0,z:0};if(e){let p={x:1/0,y:1/0,z:1/0},u={x:-1/0,y:-1/0,z:-1/0};for(const y of l)y.x<p.x&&(p.x=y.x),y.y<p.y&&(p.y=y.y),y.z<p.z&&(p.z=y.z),y.x>u.x&&(u.x=y.x),y.y>u.y&&(u.y=y.y),y.z>u.z&&(u.z=y.z);const g=Pe(u,p),_=t.size,x=_.x/g.x,v=_.y/g.y,m=_.z/g.z;c=Math.min(x,v,m),h=dr(Et(p,u),.5)}const d=[];for(const p of l){let u=p;e&&(u=Pe(u,h),u=dr(u,c),a||(u=Et(u,h))),t.stlPosition&&(u=Et(u,t.stlPosition)),t.objPosition&&(u=Et(u,t.objPosition)),t.threeMfPosition&&(u=Et(u,t.threeMfPosition)),t.rotation&&(u=$i(u,t.rotation)),u=Et(u,t.center),d.push(u)}return d}var rP=[[0,1,2,3],[4,7,6,5],[0,1,5,4],[3,2,6,7],[1,2,6,5],[0,3,7,4]],iP=[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]],ko=[3,2,6,7];function Kf(n){const{size:{x:t,y:e,z:s},center:r,rotation:i}=n;return[{x:-t/2,y:-e/2,z:-s/2},{x:t/2,y:-e/2,z:-s/2},{x:t/2,y:e/2,z:-s/2},{x:-t/2,y:e/2,z:-s/2},{x:-t/2,y:-e/2,z:s/2},{x:t/2,y:-e/2,z:s/2},{x:t/2,y:e/2,z:s/2},{x:-t/2,y:e/2,z:s/2}].map(l=>Et(r,$i(l,i)))}function oP(n){const t=n[0][0],e=n[0][1],s=n[0][2],r=n[1][0],i=n[1][1],a=n[1][2],l=n[2][0],c=n[2][1],h=n[2][2],d=i*h-c*a,p=-(e*h-c*s),u=e*a-i*s,g=-(r*h-l*a),_=t*h-l*s,x=-(t*a-r*s),v=r*c-l*i,m=-(t*c-l*e),y=t*i-r*e,w=t*d+e*g+s*v,b=w?1/w:0;return[[d*b,p*b,u*b],[g*b,_*b,x*b],[v*b,m*b,y*b]]}function aP(n,t){const e=[[0,0,0],[0,0,0],[0,0,0]];for(let s=0;s<3;s++)for(let r=0;r<3;r++)e[s][r]=n[s][0]*t[0][r]+n[s][1]*t[1][r]+n[s][2]*t[2][r];return e}function Jf(n,t){const e=[[n[0].x,n[1].x,n[2].x],[n[0].y,n[1].y,n[2].y],[1,1,1]],s=[[t[0].x,t[1].x,t[2].x],[t[0].y,t[1].y,t[2].y],[1,1,1]],r=aP(s,oP(e));return`matrix(${r[0][0]} ${r[1][0]} ${r[0][1]} ${r[1][1]} ${r[0][2]} ${r[1][2]})`}function nt(n){return(Math.round(n*100)/100).toString()}var cP=400,lP=400,hP=2;function dP(n){const t=ji(Pe(n.lookAt,n.position));let s=ji(cr(t,{x:0,y:1,z:0}));Ui(s)||(s={x:1,y:0,z:0});const r=cr(s,t);return{r:s,u:r,f:t}}function Be(n,t){const{r:e,u:s,f:r}=dP(t),i=Pe(n,t.position);return{x:lt(i,e),y:lt(i,s),z:lt(i,r)}}function Oe(n,t,e,s){if(n.z<=0)return null;const r=s/n.z;return{x:n.x*r*t/2,y:-n.y*r*e/2,z:n.z}}async function uP(n,t={}){var y;const e=t.width??cP,s=t.height??lP,r=n.camera.focalLength??hP,i=[],a=[],l=new Map,c=[],h=[];let d=0;const p=new Map,u=new Map,g=new Map,_=new Map;for(const w of n.boxes){if(w.stlUrl&&!u.has(w.stlUrl))try{const b=await YS(w.stlUrl);u.set(w.stlUrl,b)}catch(b){console.warn(`Failed to load STL from ${w.stlUrl}:`,b)}if(w.objUrl&&!g.has(w.objUrl))try{const b=await JS(w.objUrl);g.set(w.objUrl,b)}catch(b){console.warn(`Failed to load OBJ from ${w.objUrl}:`,b)}if(w.threeMfUrl&&!_.has(w.threeMfUrl))try{const b=await eP(w.threeMfUrl);_.set(w.threeMfUrl,b)}catch(b){console.warn(`Failed to load 3MF from ${w.threeMfUrl}:`,b)}}for(const w of n.boxes){const k=Kf(w).map(E=>Be(E,n.camera)),C=k.map(E=>Oe(E,e,s,r));if(w.drawBoundingBox)for(const[E,N]of iP){const I=C[E],M=C[N];if(I&&M){const S=Math.max(k[E].z,k[N].z);h.push({pts:[I,M],depth:S,color:"rgba(0,0,0,0.5)"})}}if(w.stlUrl&&u.has(w.stlUrl)){const E=u.get(w.stlUrl),N=jc(E,w,w.scaleStlToBox??!1,"stl");for(let I=0;I<E.triangles.length;I++){E.triangles[I];const M=I*3,S=N[M],L=N[M+1],R=N[M+2],U=Be(S,n.camera),j=Be(L,n.camera),V=Be(R,n.camera),G=Oe(U,e,s,r),ne=Oe(j,e,s,r),J=Oe(V,e,s,r);if(G&&ne&&J){const re=Pe(j,U),ee=Pe(V,U),X=cr(re,ee),Y=w.color??"gray";i.push({pts:[G,ne,J],cam:[U,j,V],fill:Oc(Y,X),stroke:!1})}}}else if(w.objUrl&&g.has(w.objUrl)){const E=g.get(w.objUrl),N=jc(E,w,w.scaleObjToBox??!1,"obj");for(let I=0;I<E.triangles.length;I++){const M=I*3,S=E.triangles[I],L=N[M],R=N[M+1],U=N[M+2],j=Be(L,n.camera),V=Be(R,n.camera),G=Be(U,n.camera),ne=Oe(j,e,s,r),J=Oe(V,e,s,r),re=Oe(G,e,s,r);if(ne&&J&&re){const ee=Pe(V,j),X=Pe(G,j),Y=cr(ee,X);i.push({pts:[ne,J,re],cam:[j,V,G],fill:Oc(w.color??S.color??"gray",Y),stroke:!1})}}}else if(w.threeMfUrl&&_.has(w.threeMfUrl)){const E=_.get(w.threeMfUrl),N=jc(E,w,w.scaleThreeMfToBox??!1,"3mf");for(let I=0;I<E.triangles.length;I++){const M=I*3,S=E.triangles[I],L=N[M],R=N[M+1],U=N[M+2],j=Be(L,n.camera),V=Be(R,n.camera),G=Be(U,n.camera),ne=Oe(j,e,s,r),J=Oe(V,e,s,r),re=Oe(G,e,s,r);if(ne&&J&&re){const ee=Pe(V,j),X=Pe(G,j),Y=cr(ee,X);i.push({pts:[ne,J,re],cam:[j,V,G],fill:Oc(w.color??S.color??"gray",Y),stroke:!1})}}}else{const E=Kf(w),N=E.map(M=>Be(M,n.camera)),I=N.map(M=>Oe(M,e,s,r));for(const M of rP){const S=[];let L=!1;for(const U of M){const j=I[U];if(!j){L=!0;break}S.push(j)}if(L)continue;const R=M.map(U=>N[U]);i.push({pts:S,cam:R,fill:Bi(w.color??"gray"),stroke:!0})}if((y=w.faceImages)!=null&&y.top){const M=ko.map(S=>E[S]);if(M.every(Boolean)){const S=M,L=Math.max(...ko.map(G=>N[G].z)),R=w.faceImages.top;p.has(R)||p.set(R,`tex${p.size}`);const U=p.get(R),V=w.projectionSubdivision??2;for(let G=0;G<V;G++)for(let ne=0;ne<V;ne++){const J=ne/V,re=(ne+1)/V,ee=G/V,X=(G+1)/V,Y=($,Q,te)=>({x:$.x*(1-te)+Q.x*te,y:$.y*(1-te)+Q.y*te,z:$.z*(1-te)+Q.z*te}),Re=Be(Y(Y(S[0],S[1],J),Y(S[3],S[2],J),ee),n.camera),Ce=Be(Y(Y(S[0],S[1],re),Y(S[3],S[2],re),ee),n.camera),be=Be(Y(Y(S[0],S[1],J),Y(S[3],S[2],J),X),n.camera),Ue=Be(Y(Y(S[0],S[1],re),Y(S[3],S[2],re),X),n.camera),Je=Oe(Re,e,s,r),ut=Oe(Ce,e,s,r),St=Oe(be,e,s,r),st=Oe(Ue,e,s,r),je=Jf([{x:J,y:ee},{x:re,y:ee},{x:re,y:X}],[Je,ut,st]),Ve=`clip${d++}`;a.push({matrix:je,depth:L,href:R,clip:Ve,points:`${nt(J)},${nt(ee)} ${nt(re)},${nt(ee)} ${nt(re)},${nt(X)}`,sym:U});const ye={pts:[Je,ut,st],cam:[Re,Ce,Ue],fill:"none",stroke:!1};i.push(ye),l.set(ye,a[a.length-1]);const T=Jf([{x:J,y:ee},{x:re,y:X},{x:J,y:X}],[Je,st,St]),z=`clip${d++}`;a.push({matrix:T,depth:L,href:R,clip:z,points:`${nt(J)},${nt(ee)} ${nt(re)},${nt(X)} ${nt(J)},${nt(X)}`,sym:U});const ae={pts:[Je,st,St],cam:[Re,Ue,be],fill:"none",stroke:!1};i.push(ae),l.set(ae,a[a.length-1])}}}if(w.topLabel){const M=ko.map(S=>I[S]);if(M.every(Boolean)){const S=M[0],L=M[1],R=M[3],U=Pe(L,S),j=Pe(R,S),V=Ui(U),G=Ui(j);if(V&&G){const ne=dr(U,1/V),J=dr(j,1/G),re=M.reduce((Ce,be)=>Ce+be.x,0)/4,ee=M.reduce((Ce,be)=>Ce+be.y,0)/4,X=Math.max(...ko.map(Ce=>N[Ce].z)),Y=`matrix(${ne.x} ${ne.y} ${J.x} ${J.y} ${re} ${ee})`,Re=w.topLabelColor??[0,0,0,1];c.push({matrix:Y,depth:X,text:w.topLabel,fill:Bi(Re)})}}}}}function x(w,b,k,C){function N(L){if(!L.length)return null;const R=L[0],U=R.cam[0],j=R.cam[1],V=R.cam[2],G=cr(Pe(j,U),Pe(V,U)),ne=[],J=[];for(let re=1;re<L.length;re++){const ee=L[re];let X=0,Y=0;const Re=[];for(const Ce of ee.cam){const be=lt(G,Pe(Ce,U));Re.push(be),be>1e-6?X++:be<-1e-6&&Y++}if(!X&&!Y)ne.push(ee);else if(!X)J.push(ee);else if(!Y)ne.push(ee);else{const Ce=[],be=[],Ue=[],Je=[];for(let je=0;je<ee.cam.length;je++){const Ve=(je+1)%ee.cam.length,ye=ee.cam[je],T=ee.cam[Ve],z=ee.pts[je];ee.pts[Ve];const ae=Re[je],$=Re[Ve],Q=(te,ie,ue,Le)=>{te.push(ue),ie.push(Le)};if(ae>=-1e-6&&Q(Ce,Ue,ye,z),ae<=1e-6&&Q(be,Je,ye,z),ae>0&&$<0||ae<0&&$>0){const te=ae/(ae-$),ie={x:ye.x+(T.x-ye.x)*te,y:ye.y+(T.y-ye.y)*te,z:ye.z+(T.z-ye.z)*te},ue=Oe(ie,b,k,C);Q(Ce,Ue,ie,ue),Q(be,Je,ie,ue)}}const ut=(je,Ve)=>{if(je.length<3)return null;const ye={cam:je,pts:Ve,fill:ee.fill,stroke:!1},T=l.get(ee);return T&&l.set(ye,T),ye},St=ut(Ce,Ue),st=ut(be,Je);St&&ne.push(St),st&&J.push(st)}}return{face:R,normal:G,point:U,front:N(ne),back:N(J)}}function I(L,R){if(!L)return;lt(L.normal,dr(L.point,-1))>=0?(I(L.back,R),R.push(L.face),I(L.front,R)):(I(L.front,R),R.push(L.face),I(L.back,R))}const M=N(w),S=[];return I(M,S),S}const v=x(i,e,s,r),m=[];for(const w of v){const b=l.get(w);b?m.push({type:"image",data:b}):m.push({type:"face",data:w})}return m.push(...c.map(w=>({type:"label",data:w})),...h.sort((w,b)=>w.depth-b.depth).map(w=>({type:"edge",data:w}))),{width:e,height:s,backgroundColor:t.backgroundColor,elements:m,images:a,texId:p}}function _e(n){return Math.round(n)+""}async function pP(n,t={}){var d,p;const{width:e,height:s,backgroundColor:r,elements:i,images:a,texId:l}=await uP(n,{width:t.width,height:t.height,backgroundColor:t.backgroundColor}),c=[];if(c.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${s}" viewBox="${-e/2} ${-s/2} ${e} ${s}">`),r&&c.push(` <rect x="${-e/2}" y="${-s/2}" width="${e}" height="${s}" fill="${Bi(r)}" />
|
|
161
|
+
`),a.length){c.push(` <defs>
|
|
162
|
+
`);for(const[u,g]of l)c.push(` <image id="${g}" href="${u}" width="1" height="1" preserveAspectRatio="none" style="image-rendering:pixelated"/>
|
|
163
|
+
`);for(const u of a)c.push(` <clipPath id="${u.clip}" clipPathUnits="objectBoundingBox"><polygon points="${u.points}" /></clipPath>
|
|
164
|
+
`);c.push(` </defs>
|
|
165
|
+
`)}t.showGrid&&c.push(gP(n,e,s,((d=t.grid)==null?void 0:d.cellSize)??1,((p=t.grid)==null?void 0:p.plane)??"xz"));let h=!1;for(const u of i)if(u.type==="face"||u.type==="image")if(h||(c.push(` <g stroke="#000" stroke-width="1" stroke-linecap="round" stroke-linejoin="round">
|
|
166
|
+
`),h=!0),u.type==="face"){const g=u.data,_=g.stroke?"":' stroke="none"';c.push(` <polygon fill="${g.fill}"${_} points="${g.pts.map(x=>`${_e(x.x)},${_e(x.y)}`).join(" ")}" />
|
|
167
|
+
`)}else{const g=u.data;c.push(` <g transform="${g.matrix}" clip-path="url(#${g.clip})"><use href="#${g.sym}"/></g>
|
|
168
|
+
`)}else if(u.type==="label"){h&&(c.push(` </g>
|
|
169
|
+
`),h=!1);const g=u.data;c.push(` <g font-family="sans-serif" font-size="14" text-anchor="middle" dominant-baseline="central" transform="${g.matrix}"><text x="0" y="0" fill="${g.fill}">${g.text}</text></g>
|
|
170
|
+
`)}else if(u.type==="edge"){h&&(c.push(` </g>
|
|
171
|
+
`),h=!1);const g=u.data;c.push(` <polyline fill="none" stroke="${g.color}" points="${g.pts.map(_=>`${_.x},${_.y}`).join(" ")}" />
|
|
172
|
+
`)}return h&&c.push(` </g>
|
|
173
|
+
`),t.showOrigin&&c.push(_P(n.camera,e,s)),t.showAxes&&c.push(fP(n.camera,e,s)),c.push("</svg>"),c.join("")}function fP(n,t,e){const s=n.focalLength??2,r=3,i=Math.min(t,e)*.08,a=r*.16/s,l=Ha({x:0,y:0,z:r},t,e,s);if(!l)return"";const c=-t/2+i-l.x,h=e/2-i-l.y;function d(m){const y=Ha(m,t,e,s);return y?{x:y.x+c,y:y.y+h}:{x:0,y:0}}const{r:p,u,f:g}=Fp(n),_=d({x:0,y:0,z:r}),x=[{w:{x:1,y:0,z:0},color:"red",label:"X"},{w:{x:0,y:1,z:0},color:"green",label:"Y"},{w:{x:0,y:0,z:1},color:"blue",label:"Z"}].map(({w:m,color:y,label:w})=>({dir:{x:m.x*p.x+m.y*p.y+m.z*p.z,y:m.x*u.x+m.y*u.y+m.z*u.z,z:m.x*g.x+m.y*g.y+m.z*g.z},color:y,label:w})),v=[];for(const{dir:m,color:y,label:w}of x){const b=d({x:m.x*a,y:m.y*a,z:r+m.z*a}),k=b.x-_.x,C=b.y-_.y,E=Math.sqrt(k*k+C*C)||1,N=k/E,I=C/E,M=b.x-N*8,S=b.y-I*8,L=M+-I*4,R=S+N*4,U=M- -I*4,j=S-N*4,V=b.x+N*10,G=b.y+I*10;v.push(` <line x1="${_e(_.x)}" y1="${_e(_.y)}" x2="${_e(M)}" y2="${_e(S)}" stroke="${y}" />`),v.push(` <polygon fill="${y}" points="${_e(b.x)},${_e(b.y)} ${_e(L)},${_e(R)} ${_e(U)},${_e(j)}" />`),v.push(` <text x="${_e(V)}" y="${_e(G)}" fill="${y}" font-size="12" font-family="sans-serif" text-anchor="middle" dominant-baseline="central">${w}</text>`)}return` <g stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
174
|
+
${v.join(`
|
|
175
|
+
`)}
|
|
176
|
+
</g>
|
|
177
|
+
`}function gP(n,t,e,s,r){const i=n.camera,a=i.focalLength??2,{r:l,u:c,f:h}=Fp(i),d=_=>{const x=Pe(_,i.position);return{x:lt(x,l),y:lt(x,c),z:lt(x,h)}},p=_=>Ha(d(_),t,e,a),u=s*10,g=[];for(let _=-u;_<=u;_+=s){const x=(v,m)=>{const y=p(v),w=p(m);y&&w&&g.push(` <line x1="${_e(y.x)}" y1="${_e(y.y)}" x2="${_e(w.x)}" y2="${_e(w.y)}" />`)};switch(r){case"xz":x({x:_,y:0,z:-u},{x:_,y:0,z:u}),x({x:-u,y:0,z:_},{x:u,y:0,z:_});break;case"xy":x({x:_,y:-u,z:0},{x:_,y:u,z:0}),x({x:-u,y:_,z:0},{x:u,y:_,z:0});break;case"yz":x({x:0,y:_,z:-u},{x:0,y:_,z:u}),x({x:0,y:-u,z:_},{x:0,y:u,z:_});break}}return g.length?` <g stroke="#ccc" stroke-width="0.5">
|
|
178
|
+
${g.join(`
|
|
179
|
+
`)}
|
|
180
|
+
</g>
|
|
181
|
+
`:""}function _P(n,t,e){const s=n.focalLength??2,{r,u:i,f:a}=Fp(n),l=_=>{const x=Pe(_,n.position);return{x:lt(x,r),y:lt(x,i),z:lt(x,a)}},c=_=>Ha(_,t,e,s),h=[{dir:{x:1,y:0,z:0},color:"red"},{dir:{x:0,y:1,z:0},color:"green"},{dir:{x:0,y:0,z:1},color:"blue"}],d=Math.max(t,e)*Math.SQRT2,p=[],u={x:0,y:0,z:0},g=[];return h.forEach(({dir:_,color:x},v)=>{const y=Et(u,dr(_,1)),w=l(u),b=l(y),k=c(w),C=c(b),E=C.x-k.x,N=C.y-k.y,I=Math.sqrt(E*E+N*N),M={x:k.x+E*d/I,y:k.y+N*d/I};if(k&&C){const S=`axis-grad-${v}`,L=_e(k.x),R=_e(k.y),U=_e(M.x),j=_e(M.y);g.push(` <linearGradient id="${S}" x1="${L}" y1="${R}" x2="${U}" y2="${j}" gradientUnits="userSpaceOnUse"> <stop offset="0%" stop-color="${x}"/> <stop offset="${Math.min(I/d*1e3,100)}%" stop-color="rgba(255,255,255,0)"/> <stop offset="100%" stop-color="rgba(255,255,255,0)"/> </linearGradient>`),p.push(` <line x1="${L}" y1="${R}" x2="${U}" y2="${j}" stroke="url(#${S})" />`)}}),g.length&&p.unshift(` <defs>
|
|
182
|
+
${g.join(`
|
|
183
|
+
`)}
|
|
184
|
+
</defs>`),p.length?` <g stroke-width="1">
|
|
185
|
+
${p.join(`
|
|
186
|
+
`)}
|
|
187
|
+
</g>
|
|
188
|
+
`:""}function Fp(n){const t=ji(Pe(n.lookAt,n.position));let s=ji(cr(t,{x:0,y:1,z:0}));Ui(s)||(s={x:1,y:0,z:0});const r=cr(s,t);return{r:s,u:r,f:t}}function Ha(n,t,e,s){if(n.z<=0)return null;const r=s/n.z;return{x:n.x*r*t/2,y:-n.y*r*e/2}}function mP(n,t="angle1",e){var g,_;const s=n.width,r=n.height,i=((g=n.center)==null?void 0:g.x)||0,a=((_=n.center)==null?void 0:_.y)||0;let c=Math.max(s,r)*1.5,h;e!==void 0&&e>0&&(h=e,c=c/h);const d=c;let p;if(t==="angle1")p={x:i-d,y:d,z:a-d};else if(t==="angle2")p={x:i+d,y:d,z:a-d};else if(t==="left")p={x:i-d,y:0,z:a};else if(t==="right")p={x:i+d,y:0,z:a};else if(t==="left-raised")p={x:i-d,y:d,z:a};else if(t==="right-raised")p={x:i+d,y:d,z:a};else throw new Error(`Unknown angle preset: ${t}`);const u=h?Math.max(1,2*h):2;return{position:p,lookAt:{x:i,y:0,z:a},focalLength:u}}var xP=n=>{try{return hg(n),!0}catch{return!1}};function yP(n){if(!n)return"white";if(n.color){if(n.opacity!==void 0)try{const t=hg(n.color),e=Math.max(0,Math.min(1,n.opacity));return t.alpha(e).string()}catch{return"white"}return xP(n.color)?n.color:"white"}return"white"}var vP=n=>({x:n.x*Math.PI/180-Math.PI/2,y:n.y*Math.PI/180,z:n.z*Math.PI/180});async function wP(n,t={}){var d,p;const e=co(n),s=[],r=e.pcb_board.list()[0];if(!r)throw new Error("No pcb_board, can't render to 3d");const i=2,a=((p=(d=e.cad_component)==null?void 0:d.list)==null?void 0:p.call(d))??[],l=new Set;for(const u of a){const{model_stl_url:g,model_obj_url:_}=u;if(!g&&!_)continue;l.add(u.pcb_component_id);const x=e.pcb_component.get(u.pcb_component_id),v=2,m=u.size??(x?{x:x.width,y:i,z:x.height}:{x:v,y:v,z:v}),y=u.position?{x:u.position.x,y:u.position.z,z:u.position.y}:{x:(x==null?void 0:x.center.x)??0,y:r.thickness/2+m.y/2,z:(x==null?void 0:x.center.y)??0};s.push({center:y,size:m,color:_||g?void 0:"rgba(128,128,128,0.5)",...g?{stlUrl:g,scaleStlToBox:!1,centerModel:!0,drawBoundingBox:t.showBoundingBoxes??!1}:{},..._?{objUrl:_,scaleObjToBox:!1,centerModel:!0,drawBoundingBox:t.showBoundingBoxes??!1}:{},...u.rotation?{objRotation:vP(u.rotation)}:{}})}const c=np(n,{layer:"top",matchBoardAspectRatio:!0,backgroundColor:"transparent",drawPaddingOutsideBoard:!1,colorOverrides:{copper:{top:"#ffe066",bottom:"#ffe066"},drill:"rgba(0,0,0,0.5)"}}).replace("<svg","<svg transform='scale(1, -1)'"),h=t.camera??mP(r,t.anglePreset??"angle1",t.defaultZoomMultiplier);h.focalLength||(h.focalLength=1),s.push({center:{x:r.center.x,y:0,z:r.center.y},size:{x:r.width,y:r.thickness,z:r.height},faceImages:{top:`data:image/svg+xml;base64,${btoa(c)}`},projectionSubdivision:10,color:"rgba(0,140,0,0.8)"});for(const u of e.pcb_component.list()){if(l.has(u.pcb_component_id))continue;const g=e.source_component.get(u.source_component_id),_=Math.min(Math.min(u.width,u.height),i);s.push({center:{x:u.center.x,y:r.thickness/2+_/2,z:u.center.y},size:{x:u.width,y:_,z:u.height},color:"rgba(128,128,128,0.5)",topLabel:(g==null?void 0:g.name)??"?",topLabelColor:"white"})}return{boxes:s,camera:h}}async function bP(n,t={}){const s={backgroundColor:yP(t.background),showGrid:t.showGrid??!1,showOrigin:t.showOrigin??!1,showAxes:t.showAxes??!1};t.width&&(s.width=t.width),t.height&&(s.height=t.height);const r=await wP(n,t);return await pP(r,{...s})}const kP=async n=>new Promise((t,e)=>{const s=document.createElement("canvas"),r=s.getContext("2d");if(!r){e(new Error("Failed to get canvas context"));return}const i=new Image;i.onload=()=>{s.width=i.width||800,s.height=i.height||600,r.fillStyle="white",r.fillRect(0,0,s.width,s.height),r.drawImage(i,0,0),s.toBlob(c=>{c?t(c):e(new Error("Failed to convert canvas to blob"))},"image/png")},i.onerror=()=>{e(new Error("Failed to load SVG image"))};const a=new Blob([n],{type:"image/svg+xml"}),l=URL.createObjectURL(a);i.src=l,setTimeout(()=>URL.revokeObjectURL(l),1e4)}),SP=async(n,t,e={format:"pcb"})=>{try{let s,r;const i={};switch(e.width&&(i.width=e.width),e.height&&(i.height=e.height),e.format.toLowerCase()){case"schematic":r=og(n,i);break;case"pcb":r=np(n,i);break;case"assembly":r=cg(n,i);break;default:r=await bP(n,{background:{color:"#fff",opacity:0},defaultZoomMultiplier:1.1})}s=await kP(r);const a=`${t}_${e.format}.png`;tt.saveAs(s,a)}catch(s){throw console.error(s),new Error(`Failed to download ${e.format} PNG: ${s}`)}},Ti=async({circuitJson:n,unscopedName:t,format:e})=>{try{if(!n)throw new Error("Circuit JSON not available");await SP(n,t||"circuit",{format:e})}catch(s){Ci({title:`Error Downloading ${e.charAt(0).toUpperCase()+e.slice(1)} PNG`,description:s.toString(),variant:"destructive"})}},PP=n=>{const t=dg();return Yx(["package",n],async()=>{if(!n)return;const{data:e}=await t.get("/packages/get",{params:{package_id:n}});return e.package},{retry:!1,enabled:!!n,refetchOnWindowFocus:!1})},TP=()=>{const t=Sb().package_id??null,{author:e,packageName:s}=Xx(),r=e&&s?`${e}/${s}`:null,i=PP(t),a=uy(r),l=i.data??a.data,c=i.isLoading||a.isLoading,h=i.error??a.error??null,d=t?i.refetch:a.refetch;return{packageInfo:l,isLoading:c,error:h,refetch:d}},EP=()=>{const{packageInfo:n,isLoading:t,error:e}=TP();return{packageId:(n==null?void 0:n.package_id)??null,isLoading:t,error:e}};class q{static parse(t,e){throw new Error("not implemented")}}const CP=n=>n;class NP{constructor(t){this.id=t}resolve(t){const e=t.get(this.id);if(!e)throw new Error(`Unresolved #${this.id}`);return e}toString(){return`#${this.id}`}}const H=n=>`'${n.replace(/'/g,"''")}'`,kt=n=>Number.isInteger(n)?`${n}.`:`${n}`;class $P{constructor(){this.map=new Map,this.order=[],this.schema="AP214",this.units={length:"MM",angle:"RAD",solidAngle:"SR"}}set(t,e){this.map.has(t)||this.order.push(t),this.map.set(t,e)}add(t){const e=CP(this.order.length?Math.max(...this.order)+1:1);return this.set(e,t),new NP(e)}get(t){return this.map.get(t)}entries(){return this.order.map(t=>[t,this.map.get(t)])}toPartFile(t){const e=new Date().toISOString().slice(0,10).replace(/-/g,"-"),s=["ISO-10303-21;","HEADER;",`FILE_DESCRIPTION((${H(t.name)}),'2;1');`,`FILE_NAME(${H(t.name)},${H(e)},(${H(t.author??"tscircuit")}),(${H(t.org??"tscircuit")}),${H("generator")},${H("")},${H("")});`,`FILE_SCHEMA(('${this.schema==="AP214"?"AUTOMOTIVE_DESIGN { 1 0 10303 214 1 1 1 1 }":"AP242_MANAGED_MODEL_BASED_3D_ENGINEERING"}'));`,"ENDSEC;","DATA;"],r=this.entries().map(([a,l])=>`#${a} = ${l.toStep(this)};`),i=["ENDSEC;","END-ISO-10303-21;"];return[...s,...r,...i].join(`
|
|
189
|
+
`)}}const AP=new Map;function K(n,t){AP.set(n,t)}class Qe extends q{constructor(t,e,s,r){super(),this.name=t,this.location=e,this.axis=s,this.refDirection=r,this.type="AXIS2_PLACEMENT_3D"}static parse(t,e){const s=e.parseString(t[0]),r=e.parseRef(t[1]),i=t[2]!=="$"?e.parseRef(t[2]):void 0,a=t[3]!=="$"?e.parseRef(t[3]):void 0;return new Qe(s,r,i,a)}toStep(){const t=this.axis?this.axis.toString():"$",e=this.refDirection?this.refDirection.toString():"$";return`AXIS2_PLACEMENT_3D(${H(this.name)},${this.location},${t},${e})`}}K("AXIS2_PLACEMENT_3D",Qe.parse.bind(Qe));class we extends q{constructor(t,e,s,r){super(),this.name=t,this.x=e,this.y=s,this.z=r,this.type="CARTESIAN_POINT"}static parse(t,e){const s=e.parseString(t[0]),r=t[1].replace(/^\(|\)$/g,"").split(",").map(e.parseNumber);return new we(s,r[0],r[1],r[2]??0)}toStep(){return`CARTESIAN_POINT(${H(this.name)},(${kt(this.x)},${kt(this.y)},${kt(this.z)}))`}}K("CARTESIAN_POINT",we.parse.bind(we));class lr extends q{constructor(t,e,s){super(),this.name=t,this.placement=e,this.radius=s,this.type="CIRCLE"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=e.parseRef(t[1]),i=e.parseNumber(t[2]);return new lr(s,r,i)}toStep(){return`CIRCLE(${this.name?`'${this.name}'`:"''"},${this.placement},${kt(this.radius)})`}}K("CIRCLE",lr.parse.bind(lr));class Di extends q{constructor(t,e,s){super(),this.name=t,this.position=e,this.radius=s,this.type="CYLINDRICAL_SURFACE"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=e.parseRef(t[1]),i=e.parseNumber(t[2]);return new Di(s,r,i)}toStep(){return`CYLINDRICAL_SURFACE(${H(this.name)},${this.position},${kt(this.radius)})`}}K("CYLINDRICAL_SURFACE",Di.parse.bind(Di));class We extends q{constructor(t,e,s,r){super(),this.name=t,this.dx=e,this.dy=s,this.dz=r,this.type="DIRECTION"}static parse(t,e){const s=e.parseString(t[0]),r=t[1].replace(/^\(|\)$/g,"").split(",").map(e.parseNumber);return new We(s,r[0],r[1],r[2]??0)}toStep(){return`DIRECTION(${H(this.name)},(${kt(this.dx)},${kt(this.dy)},${kt(this.dz)}))`}}K("DIRECTION",We.parse.bind(We));class pi extends q{constructor(t,e,s){super(),this.name=t,this.pnt=e,this.dir=s,this.type="LINE"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=e.parseRef(t[1]),i=t[2];if(i.startsWith("VECTOR("))throw new Error("Inline VECTOR in LINE is not supported - VECTOR should be a separate entity");const a=e.parseRef(i);return new pi(s,r,a)}toStep(){return`LINE(${this.name?`'${this.name}'`:"''"},${this.pnt},${this.dir})`}}K("LINE",pi.parse.bind(pi));class ur extends q{constructor(t,e){super(),this.name=t,this.placement=e,this.type="PLANE"}static parse(t,e){return new ur(e.parseString(t[0]),e.parseRef(t[1]))}toStep(){return`PLANE(${H(this.name)},${this.placement})`}}K("PLANE",ur.parse.bind(ur));class Ya extends q{constructor(t,e,s,r){super(),this.name=t,this.position=e,this.majorRadius=s,this.minorRadius=r,this.type="TOROIDAL_SURFACE"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=e.parseRef(t[1]),i=e.parseNumber(t[2]),a=e.parseNumber(t[3]);return new Ya(s,r,i,a)}toStep(){return`TOROIDAL_SURFACE(${H(this.name)},${this.position},${kt(this.majorRadius)},${kt(this.minorRadius)})`}}K("TOROIDAL_SURFACE",Ya.parse.bind(Ya));class fi extends q{constructor(t,e,s){super(),this.name=t,this.orientation=e,this.magnitude=s,this.type="VECTOR"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=e.parseRef(t[1]),i=e.parseNumber(t[2]);return new fi(s,r,i)}toStep(){return`VECTOR(${H(this.name)},${this.orientation},${kt(this.magnitude)})`}}K("VECTOR",fi.parse.bind(fi));class Wi extends q{constructor(t,e,s,r){super(),this.name=t,this.r=e,this.g=s,this.b=r,this.type="COLOUR_RGB"}static parse(t,e){return new Wi(e.parseString(t[0]),e.parseNumber(t[1]),e.parseNumber(t[2]),e.parseNumber(t[3]))}toStep(){return`COLOUR_RGB(${H(this.name)},${this.r},${this.g},${this.b})`}}K("COLOUR_RGB",Wi.parse.bind(Wi));class Gi extends q{constructor(t,e){super(),this.name=t,this.items=e,this.type="FILL_AREA_STYLE"}static parse(t,e){const s=t[1].replace(/^\(|\)$/g,"").split(",").filter(Boolean).map(r=>e.parseRef(r));return new Gi(t[0]==="$"?"":e.parseString(t[0]),s)}toStep(){return`FILL_AREA_STYLE(${H(this.name)},(${this.items.join(",")}))`}}K("FILL_AREA_STYLE",Gi.parse.bind(Gi));class Vi extends q{constructor(t,e){super(),this.name=t,this.colour=e,this.type="FILL_AREA_STYLE_COLOUR"}static parse(t,e){return new Vi(e.parseString(t[0]),e.parseRef(t[1]))}toStep(){return`FILL_AREA_STYLE_COLOUR(${H(this.name)},${this.colour})`}}K("FILL_AREA_STYLE_COLOUR",Vi.parse.bind(Vi));class Hi extends q{constructor(t,e,s){super(),this.name=t,this.items=e,this.contextOfItems=s,this.type="MECHANICAL_DESIGN_GEOMETRIC_PRESENTATION_REPRESENTATION"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=t[1].replace(/^\(|\)$/g,"").split(",").filter(Boolean).map(a=>e.parseRef(a)),i=e.parseRef(t[2]);return new Hi(s,r,i)}toStep(){return`MECHANICAL_DESIGN_GEOMETRIC_PRESENTATION_REPRESENTATION(${H(this.name)},(${this.items.join(",")}),${this.contextOfItems})`}}K("MECHANICAL_DESIGN_GEOMETRIC_PRESENTATION_REPRESENTATION",Hi.parse.bind(Hi));class Yi extends q{constructor(t){super(),this.items=t,this.type="PRESENTATION_STYLE_ASSIGNMENT"}static parse(t,e){const s=t[0].replace(/^\(|\)$/g,"").split(",").filter(Boolean).map(r=>e.parseRef(r));return new Yi(s)}toStep(){return`PRESENTATION_STYLE_ASSIGNMENT((${this.items.join(",")}))`}}K("PRESENTATION_STYLE_ASSIGNMENT",Yi.parse.bind(Yi));class Xi extends q{constructor(t,e,s){super(),this.name=t,this.styles=e,this.item=s,this.type="STYLED_ITEM"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=t[1].replace(/^\(|\)$/g,"").split(",").filter(Boolean).map(a=>e.parseRef(a)),i=e.parseRef(t[2]);return new Xi(s,r,i)}toStep(){return`STYLED_ITEM(${H(this.name)},(${this.styles.join(",")}),${this.item})`}}K("STYLED_ITEM",Xi.parse.bind(Xi));class qi extends q{constructor(t,e){super(),this.name=t,this.styles=e,this.type="SURFACE_SIDE_STYLE"}static parse(t,e){const s=t[1].replace(/^\(|\)$/g,"").split(",").filter(Boolean).map(r=>e.parseRef(r));return new qi(t[0]==="$"?"":e.parseString(t[0]),s)}toStep(){return`SURFACE_SIDE_STYLE(${H(this.name)},(${this.styles.join(",")}))`}}K("SURFACE_SIDE_STYLE",qi.parse.bind(qi));class Ki extends q{constructor(t){super(),this.style=t,this.type="SURFACE_STYLE_FILL_AREA"}static parse(t,e){return new Ki(e.parseRef(t[0]))}toStep(){return`SURFACE_STYLE_FILL_AREA(${this.style})`}}K("SURFACE_STYLE_FILL_AREA",Ki.parse.bind(Ki));class Ji extends q{constructor(t,e){super(),this.side=t,this.style=e,this.type="SURFACE_STYLE_USAGE"}static parse(t,e){return new Ji(t[0].trim(),e.parseRef(t[1]))}toStep(){return`SURFACE_STYLE_USAGE(${this.side},${this.style})`}}K("SURFACE_STYLE_USAGE",Ji.parse.bind(Ji));class Zi extends q{constructor(t,e,s){super(),this.name=t,this.items=e,this.context=s,this.type="ADVANCED_BREP_SHAPE_REPRESENTATION"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=t[1].replace(/^\(|\)$/g,"").split(",").filter(Boolean).map(a=>e.parseRef(a)),i=e.parseRef(t[2]);return new Zi(s,r,i)}toStep(){return`ADVANCED_BREP_SHAPE_REPRESENTATION(${H(this.name)},(${this.items.join(",")}),${this.context})`}}K("ADVANCED_BREP_SHAPE_REPRESENTATION",Zi.parse.bind(Zi));class Qi extends q{constructor(t){super(),this.application=t,this.type="APPLICATION_CONTEXT"}static parse(t,e){const s=e.parseString(t[0]);return new Qi(s)}toStep(){return`APPLICATION_CONTEXT(${H(this.application)})`}}K("APPLICATION_CONTEXT",Qi.parse.bind(Qi));class eo extends q{constructor(t,e,s,r){super(),this.status=t,this.applicationInterpretedModelSchemaName=e,this.applicationProtocolYear=s,this.application=r,this.type="APPLICATION_PROTOCOL_DEFINITION"}static parse(t,e){const s=e.parseString(t[0]),r=e.parseString(t[1]),i=e.parseNumber(t[2]),a=e.parseRef(t[3]);return new eo(s,r,i,a)}toStep(){return`APPLICATION_PROTOCOL_DEFINITION(${H(this.status)},${H(this.applicationInterpretedModelSchemaName)},${this.applicationProtocolYear},${this.application})`}}K("APPLICATION_PROTOCOL_DEFINITION",eo.parse.bind(eo));class Xa extends q{constructor(t,e){super(),this.representationRelation=t,this.representedProductRelation=e,this.type="CONTEXT_DEPENDENT_SHAPE_REPRESENTATION"}static parse(t,e){const s=e.parseRef(t[0]),r=e.parseRef(t[1]);return new Xa(s,r)}toStep(){return`CONTEXT_DEPENDENT_SHAPE_REPRESENTATION(${this.representationRelation},${this.representedProductRelation})`}}K("CONTEXT_DEPENDENT_SHAPE_REPRESENTATION",Xa.parse.bind(Xa));class qa extends q{constructor(t,e,s,r){super(),this.name=t,this.description=e,this.transformItem1=s,this.transformItem2=r,this.type="ITEM_DEFINED_TRANSFORMATION"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=t[1]==="$"?"":e.parseString(t[1]),i=e.parseRef(t[2]),a=e.parseRef(t[3]);return new qa(s,r,i,a)}toStep(){return`ITEM_DEFINED_TRANSFORMATION(${H(this.name)},${H(this.description)},${this.transformItem1},${this.transformItem2})`}}K("ITEM_DEFINED_TRANSFORMATION",qa.parse.bind(qa));class Ka extends q{constructor(t,e,s,r,i,a){super(),this.id=t,this.name=e,this.description=s,this.relatingProductDefinition=r,this.relatedProductDefinition=i,this.referenceDesignator=a,this.type="NEXT_ASSEMBLY_USAGE_OCCURRENCE"}static parse(t,e){const s=e.parseString(t[0]),r=e.parseString(t[1]),i=t[2]==="$"?"":e.parseString(t[2]),a=e.parseRef(t[3]),l=e.parseRef(t[4]),c=t[5]==="$"?"":e.parseString(t[5]);return new Ka(s,r,i,a,l,c)}toStep(){return`NEXT_ASSEMBLY_USAGE_OCCURRENCE(${H(this.id)},${H(this.name)},${this.description?H(this.description):"$"},${this.relatingProductDefinition},${this.relatedProductDefinition},${this.referenceDesignator?H(this.referenceDesignator):"$"})`}}K("NEXT_ASSEMBLY_USAGE_OCCURRENCE",Ka.parse.bind(Ka));class to extends q{constructor(t,e,s,r){super(),this.name=t,this.id=e,this.description=s,this.frameOfReference=r,this.type="PRODUCT"}static parse(t,e){const s=e.parseString(t[0]),r=e.parseString(t[1]),i=e.parseString(t[2]),a=t[3].replace(/^\(|\)$/g,"").split(",").filter(Boolean).map(l=>e.parseRef(l.trim()));return new to(s,r,i,a)}toStep(){return`PRODUCT(${H(this.name)},${H(this.id)},${H(this.description)},(${this.frameOfReference.join(",")}))`}}K("PRODUCT",to.parse.bind(to));class so extends q{constructor(t,e,s){super(),this.name=t,this.frameOfReference=e,this.disciplineType=s,this.type="PRODUCT_CONTEXT"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=e.parseRef(t[1]),i=e.parseString(t[2]);return new so(s,r,i)}toStep(){return`PRODUCT_CONTEXT(${H(this.name)},${this.frameOfReference},${H(this.disciplineType)})`}}K("PRODUCT_CONTEXT",so.parse.bind(so));class no extends q{constructor(t,e,s,r){super(),this.id=t,this.description=e,this.formation=s,this.frameOfReference=r,this.type="PRODUCT_DEFINITION"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=t[1]==="$"?"":e.parseString(t[1]),i=e.parseRef(t[2]),a=e.parseRef(t[3]);return new no(s,r,i,a)}toStep(){return`PRODUCT_DEFINITION(${H(this.id)},${H(this.description)},${this.formation},${this.frameOfReference})`}}K("PRODUCT_DEFINITION",no.parse.bind(no));class ro extends q{constructor(t,e,s){super(),this.name=t,this.frameOfReference=e,this.lifecycleStage=s,this.type="PRODUCT_DEFINITION_CONTEXT"}static parse(t,e){const s=e.parseString(t[0]),r=e.parseRef(t[1]),i=e.parseString(t[2]);return new ro(s,r,i)}toStep(){return`PRODUCT_DEFINITION_CONTEXT(${H(this.name)},${this.frameOfReference},${H(this.lifecycleStage)})`}}K("PRODUCT_DEFINITION_CONTEXT",ro.parse.bind(ro));class io extends q{constructor(t,e,s){super(),this.id=t,this.description=e,this.ofProduct=s,this.type="PRODUCT_DEFINITION_FORMATION"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=t[1]==="$"?"":e.parseString(t[1]),i=e.parseRef(t[2]);return new io(s,r,i)}toStep(){return`PRODUCT_DEFINITION_FORMATION(${H(this.id)},${H(this.description)},${this.ofProduct})`}}K("PRODUCT_DEFINITION_FORMATION",io.parse.bind(io));class oo extends q{constructor(t,e,s){super(),this.name=t,this.description=e,this.definition=s,this.type="PRODUCT_DEFINITION_SHAPE"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=t[1]==="$"?"":e.parseString(t[1]),i=e.parseRef(t[2]);return new oo(s,r,i)}toStep(){return`PRODUCT_DEFINITION_SHAPE(${H(this.name)},${H(this.description)},${this.definition})`}}K("PRODUCT_DEFINITION_SHAPE",oo.parse.bind(oo));class Ja extends q{constructor(t,e,s){super(),this.name=t,this.description=e,this.products=s,this.type="PRODUCT_RELATED_PRODUCT_CATEGORY"}static parse(t,e){const s=e.parseString(t[0]),r=t[1]==="$"?"":e.parseString(t[1]),i=t[2].replace(/^\(|\)$/g,"").split(",").filter(Boolean).map(a=>e.parseRef(a));return new Ja(s,r,i)}toStep(){return`PRODUCT_RELATED_PRODUCT_CATEGORY(${H(this.name)},${this.description?H(this.description):"$"},(${this.products.join(",")}))`}}K("PRODUCT_RELATED_PRODUCT_CATEGORY",Ja.parse.bind(Ja));class ao extends q{constructor(t,e){super(),this.definition=t,this.usedRepresentation=e,this.type="SHAPE_DEFINITION_REPRESENTATION"}static parse(t,e){const s=e.parseRef(t[0]),r=e.parseRef(t[1]);return new ao(s,r)}toStep(){return`SHAPE_DEFINITION_REPRESENTATION(${this.definition},${this.usedRepresentation})`}}K("SHAPE_DEFINITION_REPRESENTATION",ao.parse.bind(ao));class Za extends q{constructor(t,e,s){super(),this.name=t,this.items=e,this.contextOfItems=s,this.type="SHAPE_REPRESENTATION"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=t[1].replace(/^\(|\)$/g,"").split(",").filter(Boolean).map(a=>e.parseRef(a)),i=e.parseRef(t[2]);return new Za(s,r,i)}toStep(){return`SHAPE_REPRESENTATION(${H(this.name)},(${this.items.join(",")}),${this.contextOfItems})`}}K("SHAPE_REPRESENTATION",Za.parse.bind(Za));class Vt extends q{constructor(t,e,s,r){super(),this.name=t,this.bounds=e,this.surface=s,this.sameSense=r,this.type="ADVANCED_FACE"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=t[1].replace(/^\(|\)$/g,"").split(",").filter(Boolean).map(l=>e.parseRef(l.trim())),i=e.parseRef(t[2]),a=t[3].trim()===".T.";return new Vt(s,r,i,a)}toStep(){return`ADVANCED_FACE(${this.name?`'${this.name}'`:"''"},(${this.bounds.join(",")}),${this.surface},${this.sameSense?".T.":".F."})`}}K("ADVANCED_FACE",Vt.parse.bind(Vt));class gi extends q{constructor(t,e){super(),this.name=t,this.faces=e,this.type="CLOSED_SHELL"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=t[1].replace(/^\(|\)$/g,"").split(",").filter(Boolean).map(i=>e.parseRef(i.trim()));return new gi(s,r)}toStep(){return`CLOSED_SHELL(${this.name?`'${this.name}'`:"''"},(${this.faces.join(",")}))`}}K("CLOSED_SHELL",gi.parse.bind(gi));class Nt extends q{constructor(t,e,s,r,i){super(),this.name=t,this.start=e,this.end=s,this.curve=r,this.sameSense=i,this.type="EDGE_CURVE"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=e.parseRef(t[1]),i=e.parseRef(t[2]),a=e.parseRef(t[3]),l=t[4].trim()===".T.";return new Nt(s,r,i,a,l)}toStep(){return`EDGE_CURVE(${this.name?`'${this.name}'`:"''"},${this.start},${this.end},${this.curve},${this.sameSense?".T.":".F."})`}}K("EDGE_CURVE",Nt.parse.bind(Nt));class pt extends q{constructor(t,e){super(),this.name=t,this.edges=e,this.type="EDGE_LOOP"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]),r=t[1].replace(/^\(|\)$/g,"").split(",").filter(Boolean).map(i=>e.parseRef(i));return new pt(s,r)}toStep(){return`EDGE_LOOP(${H(this.name)},(${this.edges.join(",")}))`}}K("EDGE_LOOP",pt.parse.bind(pt));class _i extends q{constructor(t,e,s){super(),this.name=t,this.bound=e,this.sameSense=s,this.type="FACE_BOUND"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]);return new _i(s,e.parseRef(t[1]),t[2].trim()===".T.")}toStep(){return`FACE_BOUND(${H(this.name)},${this.bound},${this.sameSense?".T.":".F."})`}}K("FACE_BOUND",_i.parse.bind(_i));class Ht extends q{constructor(t,e,s){super(),this.name=t,this.bound=e,this.sameSense=s,this.type="FACE_OUTER_BOUND"}static parse(t,e){return new Ht(e.parseString(t[0]),e.parseRef(t[1]),t[2].trim()===".T.")}toStep(){return`FACE_OUTER_BOUND('${this.name}',${this.bound},${this.sameSense?".T.":".F."})`}}K("FACE_OUTER_BOUND",Ht.parse.bind(Ht));class mi extends q{constructor(t,e){super(),this.name=t,this.outer=e,this.type="MANIFOLD_SOLID_BREP"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]);return new mi(s,e.parseRef(t[1]))}toStep(){return`MANIFOLD_SOLID_BREP(${H(this.name)},${this.outer})`}}K("MANIFOLD_SOLID_BREP",mi.parse.bind(mi));class Me extends q{constructor(t,e,s){super(),this.name=t,this.edge=e,this.orientation=s,this.type="ORIENTED_EDGE"}static parse(t,e){var a,l,c,h;const s=t[0]==="$"?"":e.parseString(t[0]),r=e.parseRef(t[3]),i=((l=(a=t[4])==null?void 0:a.trim)==null?void 0:l.call(a))===".T."||((h=(c=t[2])==null?void 0:c.trim)==null?void 0:h.call(c))===".T.";return new Me(s,r,i)}toStep(){return`ORIENTED_EDGE(${H(this.name)},*,*,${this.edge},${this.orientation?".T.":".F."})`}}K("ORIENTED_EDGE",Me.parse.bind(Me));class Xe extends q{constructor(t,e){super(),this.name=t,this.pnt=e,this.type="VERTEX_POINT"}static parse(t,e){const s=t[0]==="$"?"":e.parseString(t[0]);return new Xe(s,e.parseRef(t[1]))}toStep(){return`VERTEX_POINT(${this.name?`'${this.name}'`:"''"},${this.pnt})`}}K("VERTEX_POINT",Xe.parse.bind(Xe));class Ei extends q{constructor(t,e){super(),this.type=t,this.args=e}toStep(){return this.args.length===1&&this.args[0].startsWith("( ")?`(
|
|
190
|
+
${this.args[0].slice(2,-2).trim().split(/\s+(?=[A-Z_])/g).join(`
|
|
191
|
+
`)}
|
|
192
|
+
)`:`${this.type}(${this.args.join(",")})`}}function IP(n,t,e){var u;const{transform:s,shouldDrawErrors:r}=e;if(!r)return[];const{pcb_port_ids:i}=n,a=t.find(g=>g.type==="pcb_port"&&g.pcb_port_id===(i==null?void 0:i[0])),l=t.find(g=>g.type==="pcb_port"&&g.pcb_port_id===(i==null?void 0:i[1]));if(!a||!l){const g=(u=n.message)==null?void 0:u.match(/pcb_via\[#?(pcb_via_\d+)\]/),_=g==null?void 0:g[1],x=t.find(v=>v.type==="pcb_via"&&v.pcb_via_id===_);if(x&&x.type==="pcb_via")return LP(n,x,e);if(n.center){const v=B(s,{x:n.center.x,y:n.center.y});return[{name:"rect",type:"element",attributes:{x:(v.x-5).toString(),y:(v.y-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${v.x} ${v.y})`},children:[],value:""},{name:"text",type:"element",attributes:{x:v.x.toString(),y:(v.y-15).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",value:n.message||"Pcb Trace Error",name:"",attributes:{},children:[]}],value:""}]}else return[]}const c=B(s,{x:a.x,y:a.y}),h=B(s,{x:l.x,y:l.y}),d={x:(c.x+h.x)/2,y:(c.y+h.y)/2};return isNaN(c.x)||isNaN(c.y)||isNaN(h.x)||isNaN(h.y)||isNaN(d.x)||isNaN(d.y)?[]:[{name:"line",type:"element",attributes:{x1:c.x.toString(),y1:c.y.toString(),x2:d.x.toString(),y2:d.y.toString(),stroke:"red","stroke-width":"1.5","stroke-dasharray":"2,2"},children:[],value:""},{name:"line",type:"element",attributes:{x1:d.x.toString(),y1:d.y.toString(),x2:h.x.toString(),y2:h.y.toString(),stroke:"red","stroke-width":"1.5","stroke-dasharray":"2,2"},children:[],value:""},{name:"rect",type:"element",attributes:{x:(d.x-5).toString(),y:(d.y-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${d.x} ${d.y})`},children:[],value:""},{name:"text",type:"element",attributes:{x:d.x.toString(),y:(d.y-15).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",value:n.message||"Pcb Trace Error",name:"",attributes:{},children:[]}],value:""}]}function LP(n,t,e){const{transform:s}=e;if(n.center&&t){const r=B(s,{x:n.center.x,y:n.center.y}),i=B(s,{x:t.x,y:t.y}),a=i.x-r.x,l=i.y-r.y,c=Math.sqrt(a*a+l*l),h=Math.atan2(l,a)*180/Math.PI,p=c+10*2,u=20,g=(r.x+i.x)/2,_=(r.y+i.y)/2;return[{name:"rect",type:"element",attributes:{x:(g-p/2).toString(),y:(_-u/2).toString(),width:p.toString(),height:u.toString(),fill:"none",stroke:"red","stroke-width":"1","stroke-dasharray":"3,2",transform:`rotate(${h} ${g} ${_})`},children:[],value:""},{name:"rect",type:"element",attributes:{x:(g-5).toString(),y:(_-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${g} ${_})`},children:[],value:""},{name:"text",type:"element",attributes:{x:g.toString(),y:(_-u/2-5).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",value:n.message||"Pcb Trace Error",name:"",attributes:{},children:[]}],value:""}]}return[]}function MP(n,t){const{transform:e,layer:s}=t;if(!n.route||!Array.isArray(n.route))return[];const r=n.route[0],i=n.route[n.route.length-1],a=r.x===i.x&&r.y===i.y,l=n.route.slice(0,a?-1:void 0).map((c,h)=>{const[d,p]=B(e,[c.x,c.y]);return h===0?`M ${d} ${p}`:`L ${d} ${p}`}).join(" ")+(a?" Z":"");return[{name:"path",type:"element",attributes:{class:"pcb-fabrication-note-path",stroke:n.color||"rgba(255,255,255,0.5)",fill:"none",d:l,"stroke-width":(n.stroke_width*Math.abs(e.a)).toString(),"data-pcb-component-id":n.pcb_component_id,"data-pcb-fabrication-note-path-id":n.pcb_fabrication_note_path_id},value:"",children:[]}]}function RP(n,t){const{transform:e,layer:s}=t,{anchor_position:r,anchor_alignment:i,text:a,font_size:l=1,layer:c="top",color:h}=n;if(s&&c!==s)return[];if(!r||typeof r.x!="number"||typeof r.y!="number")return console.error("Invalid anchor_position:",r),[];const[d,p]=B(e,[r.x,r.y]),u=l*Math.abs(e.a),g=si(fr(d,p),gr(Math.PI/180));return[{name:"text",type:"element",attributes:{x:"0",y:"0","font-family":"Arial, sans-serif","font-size":u.toString(),"text-anchor":"middle","dominant-baseline":"central",transform:sc(g),class:"pcb-fabrication-note-text",fill:h||"rgba(255,255,255,0.5)"},children:[{type:"text",value:a,name:"",attributes:{},children:[]}],value:""}]}function OP(n,t){const{transform:e,colorMap:s}=t,[r,i]=B(e,[n.x,n.y]);if(n.shape==="pill"){const a=n.outer_width*Math.abs(e.a),l=n.outer_height*Math.abs(e.a),c=n.hole_width*Math.abs(e.a),h=n.hole_height*Math.abs(e.a),d=a/2,p=c/2,u=l-a,g=n.ccw_rotation||0,_=g?`translate(${r} ${i}) rotate(${-g})`:`translate(${r} ${i})`,x=g?`translate(${r} ${i}) rotate(${-g})`:`translate(${r} ${i})`;return[{name:"g",type:"element",children:[{name:"path",type:"element",attributes:{class:"pcb-hole-outer",fill:s.copper.top,d:`M${-d},${-u/2} v${u} a${d},${d} 0 0 0 ${a},0 v-${u} a${d},${d} 0 0 0 -${a},0 z`,transform:_},value:"",children:[]},{name:"path",type:"element",attributes:{class:"pcb-hole-inner",fill:s.drill,d:`M${-p},${-(h-c)/2} v${h-c} a${p},${p} 0 0 0 ${c},0 v-${h-c} a${p},${p} 0 0 0 -${c},0 z`,transform:x},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="circle"){const a=n.outer_diameter*Math.abs(e.a),l=n.outer_diameter*Math.abs(e.a),c=n.hole_diameter*Math.abs(e.a),h=n.hole_diameter*Math.abs(e.a),d=Math.min(a,l)/2,p=Math.min(c,h)/2;return[{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"pcb-hole-outer",fill:s.copper.top,cx:r.toString(),cy:i.toString(),r:d.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",fill:s.drill,cx:r.toString(),cy:i.toString(),r:p.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="circular_hole_with_rect_pad"){const a=n,l=n.hole_diameter*Math.abs(e.a),c=n.rect_pad_width*Math.abs(e.a),h=n.rect_pad_height*Math.abs(e.a),d=(n.rect_border_radius??0)*Math.abs(e.a),p=l/2,[u,g]=B(e,[a.x+(a.hole_offset_x??0),a.y+(a.hole_offset_y??0)]);return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-pad",fill:s.copper.top,x:(r-c/2).toString(),y:(i-h/2).toString(),width:c.toString(),height:h.toString(),...d?{rx:d.toString(),ry:d.toString()}:{}},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",fill:s.drill,cx:u.toString(),cy:g.toString(),r:p.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="pill_hole_with_rect_pad"){const a=n,l=a.rect_pad_width*Math.abs(e.a),c=a.rect_pad_height*Math.abs(e.a),h=(a.rect_border_radius??0)*Math.abs(e.a),d=a.hole_height*Math.abs(e.a),p=a.hole_width*Math.abs(e.a),u=a,g=u.hole_offset_x??0,_=u.hole_offset_y??0,[x,v]=B(e,[a.x+g,a.y+_]),m=Math.min(d,p)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-pad",fill:s.copper.top,x:(r-l/2).toString(),y:(i-c/2).toString(),width:l.toString(),height:c.toString(),...h?{rx:h.toString(),ry:h.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pcb-hole-inner",fill:s.drill,x:(x-p/2).toString(),y:(v-d/2).toString(),width:p.toString(),height:d.toString(),rx:m.toString(),ry:m.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="rotated_pill_hole_with_rect_pad"){const a=n,l=a.rect_pad_width*Math.abs(e.a),c=a.rect_pad_height*Math.abs(e.a),h=(a.rect_border_radius??0)*Math.abs(e.a),d=a.hole_height*Math.abs(e.a),p=a.hole_width*Math.abs(e.a),u=a,g=u.hole_offset_x??0,_=u.hole_offset_y??0,[x,v]=B(e,[a.x+g,a.y+_]),m=Math.min(d,p)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-pad",fill:s.copper.top,x:(-l/2).toString(),y:(-c/2).toString(),width:l.toString(),height:c.toString(),transform:`translate(${r} ${i}) rotate(${-a.rect_ccw_rotation})`,...h?{rx:h.toString(),ry:h.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pcb-hole-inner",fill:s.drill,x:(-p/2).toString(),y:(-d/2).toString(),width:p.toString(),height:d.toString(),rx:m.toString(),ry:m.toString(),transform:`translate(${x} ${v}) rotate(${-a.hole_ccw_rotation})`},value:"",children:[]}],value:"",attributes:{}}]}return[]}function FP(n,t){const{transform:e,layer:s,colorMap:r}=t;if(!n.route||!Array.isArray(n.route))return[];let i=n.route.map((d,p)=>{const[u,g]=B(e,[d.x,d.y]);return p===0?`M ${u} ${g}`:`L ${u} ${g}`}).join(" ");const a=n.route[0],l=n.route[n.route.length-1];a&&l&&a.x===l.x&&a.y===l.y&&(i+=" Z");const c=n.layer||"top";if(s&&c!==s)return[];const h=c==="bottom"?r.silkscreen.bottom:r.silkscreen.top;return[{name:"path",type:"element",attributes:{class:`pcb-silkscreen pcb-silkscreen-${c}`,d:i,fill:"none",stroke:h,"stroke-width":(n.stroke_width*Math.abs(e.a)).toString(),"stroke-linecap":"round","stroke-linejoin":"round","data-pcb-component-id":n.pcb_component_id,"data-pcb-silkscreen-path-id":n.pcb_silkscreen_path_id},value:"",children:[]}]}function zP(n,t){const{transform:e,layer:s,colorMap:r}=t,{anchor_position:i,text:a,font_size:l=1,layer:c="top",ccw_rotation:h=0,anchor_alignment:d="center"}=n;if(s&&c!==s)return[];if(!i||typeof i.x!="number"||typeof i.y!="number")return console.error("Invalid anchor_position:",i),[];const[p,u]=B(e,[i.x,i.y]),g=l*Math.abs(e.a);let _="middle",x="central";const v=0,m=0;switch(d){case"top_left":_="start",x="text-before-edge";break;case"top_center":_="middle",x="text-before-edge";break;case"top_right":_="end",x="text-before-edge";break;case"center_left":_="start",x="central";break;case"center_right":_="end",x="central";break;case"bottom_left":_="start",x="text-after-edge";break;case"bottom_center":_="middle",x="text-after-edge";break;case"bottom_right":_="end",x="text-after-edge";break;case"center":default:_="middle",x="central";break}const y=si(fr(p,u),gr(-h*Math.PI/180),...c==="bottom"?[pr(-1,1)]:[]),w=c==="bottom"?r.silkscreen.bottom:r.silkscreen.top,b=a.split(`
|
|
193
|
+
`),k=b.length===1?[{type:"text",value:a,name:"",attributes:{},children:[]}]:b.map((E,N)=>({type:"element",name:"tspan",value:"",attributes:{x:"0",...N>0?{dy:g.toString()}:{}},children:[{type:"text",value:E,name:"",attributes:{},children:[]}]}));return[{name:"text",type:"element",attributes:{x:"0",y:"0",dx:v.toString(),dy:m.toString(),fill:w,"font-family":"Arial, sans-serif","font-size":g.toString(),"text-anchor":_,"dominant-baseline":x,transform:sc(y),class:`pcb-silkscreen-text pcb-silkscreen-${c}`,"data-pcb-silkscreen-text-id":n.pcb_component_id,stroke:"none"},children:k,value:""}]}function UP(n,t){const{transform:e,layer:s,colorMap:r}=t,{center:i,width:a,height:l,layer:c="top",pcb_silkscreen_rect_id:h,stroke_width:d,is_filled:p,has_stroke:u,is_stroke_dashed:g}=n;if(s&&c!==s)return[];if(!i||typeof i.x!="number"||typeof i.y!="number"||typeof a!="number"||typeof l!="number")return console.error("Invalid rectangle data:",{center:i,width:a,height:l}),[];const[_,x]=B(e,[i.x,i.y]),v=a*Math.abs(e.a),m=l*Math.abs(e.d),y=d*Math.abs(e.a),w=c==="bottom"?r.silkscreen.bottom:r.silkscreen.top,b={x:(_-v/2).toString(),y:(x-m/2).toString(),width:v.toString(),height:m.toString(),class:`pcb-silkscreen-rect pcb-silkscreen-${c}`,"data-pcb-silkscreen-rect-id":h};b.fill=p?w:"none";let k;if(u===void 0?k=y>0:k=u,k){if(b.stroke=w,b["stroke-width"]=y.toString(),g){const E=.1*Math.abs(e.a),N=.05*Math.abs(e.a);b["stroke-dasharray"]=`${E} ${N}`}}else b.stroke="none";return[{name:"rect",type:"element",attributes:b,value:"",children:[]}]}function jP(n,t){const{transform:e,layer:s,colorMap:r}=t,{center:i,radius:a,layer:l="top",pcb_silkscreen_circle_id:c,stroke_width:h=1}=n;if(s&&l!==s)return[];if(!i||typeof i.x!="number"||typeof i.y!="number"||typeof a!="number")return console.error("Invalid PCB Silkscreen Circle data:",{center:i,radius:a}),[];const[d,p]=B(e,[i.x,i.y]),u=a*Math.abs(e.a),g=h*Math.abs(e.a),_=l==="bottom"?r.silkscreen.bottom:r.silkscreen.top;return[{name:"circle",type:"element",attributes:{cx:d.toString(),cy:p.toString(),r:u.toString(),class:`pcb-silkscreen-circle pcb-silkscreen-${l}`,stroke:_,"stroke-width":g.toString(),"data-pcb-silkscreen-circle-id":c},value:"",children:[]}]}function BP(n,t){const{transform:e,layer:s,colorMap:r}=t,{x1:i,y1:a,x2:l,y2:c,stroke_width:h,layer:d="top",pcb_silkscreen_line_id:p}=n;if(s&&d!==s)return[];if(typeof i!="number"||typeof a!="number"||typeof l!="number"||typeof c!="number")return console.error("Invalid coordinates:",{x1:i,y1:a,x2:l,y2:c}),[];const[u,g]=B(e,[i,a]),[_,x]=B(e,[l,c]),v=h*Math.abs(e.a),m=d==="bottom"?r.silkscreen.bottom:r.silkscreen.top;return[{name:"line",type:"element",attributes:{x1:u.toString(),y1:g.toString(),x2:_.toString(),y2:x.toString(),stroke:m,"stroke-width":v.toString(),class:`pcb-silkscreen-line pcb-silkscreen-${d}`,"data-pcb-silkscreen-line-id":p},value:"",children:[]}]}function DP(n){const t=[];for(let e=0;e<n.length-1;e++)t.push([n[e],n[e+1]]);return t}var Ye={copper:{top:"rgb(200, 52, 52)",inner1:"rgb(255, 140, 0)",inner2:"rgb(255, 215, 0)",inner3:"rgb(50, 205, 50)",inner4:"rgb(64, 224, 208)",inner5:"rgb(138, 43, 226)",inner6:"rgb(255, 105, 180)",bottom:"rgb(77, 127, 196)"},soldermask:{top:"rgb(200, 52, 52)",bottom:"rgb(77, 127, 196)"},drill:"#FF26E2",silkscreen:{top:"#f2eda1",bottom:"#5da9e9"},boardOutline:"rgba(255, 255, 255, 0.5)",debugComponent:{fill:null,stroke:null}};Ye.drill;Ye.silkscreen.top;Ye.silkscreen.bottom;({...Ye.copper});function vr(n,t=Ye){return t.copper[n]??"white"}function WP(n,t){const{transform:e,layer:s,colorMap:r,renderSolderMask:i}=t;if(!n.route||!Array.isArray(n.route)||n.route.length<2)return[];const a=DP(n.route),l=[];for(const[c,h]of a){const d=B(e,[c.x,c.y]),p=B(e,[h.x,h.y]),u="layer"in c?c.layer:"layer"in h?h.layer:null;if(!u||s&&u!==s)continue;const g=vr(u,r),_=r.soldermask[u]??g,x="width"in c?c.width:"width"in h?h.width:null,v=x?(x*Math.abs(e.a)).toString():"0.3";if(i){const m={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-trace",stroke:g,fill:"none",d:`M ${d[0]} ${d[1]} L ${p[0]} ${p[1]}`,"stroke-width":v,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-layer":u}},y={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask",stroke:_,fill:"none",d:`M ${d[0]} ${d[1]} L ${p[0]} ${p[1]}`,"stroke-width":v,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-layer":u}};l.push(y,m)}else{const m={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-trace",stroke:_,fill:"none",d:`M ${d[0]} ${d[1]} L ${p[0]} ${p[1]}`,"stroke-width":v,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-layer":u}};l.push(m)}}return l.sort((c,h)=>{const d=c.attributes["data-layer"],p=h.attributes["data-layer"];return d==="bottom"&&p!=="bottom"?-1:d==="top"&&p!=="top"?1:0}),l}function GP(n,t){const{transform:e,layer:s,colorMap:r,renderSolderMask:i}=t;if(s&&n.layer!==s)return[];const a=!!(n!=null&&n.is_covered_with_solder_mask),l=i&&a,c=r.soldermask[n.layer]??r.soldermask.top;if(n.shape==="rect"||n.shape==="rotated_rect"){const h=n.width*Math.abs(e.a),d=n.height*Math.abs(e.d),[p,u]=B(e,[n.x,n.y]),g=(n.rect_border_radius??0)*Math.abs(e.a);if(n.shape==="rotated_rect"&&n.ccw_rotation){const v={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:vr(n.layer,r),x:(-h/2).toString(),y:(-d/2).toString(),width:h.toString(),height:d.toString(),transform:`translate(${p} ${u}) rotate(${-n.ccw_rotation})`,"data-layer":n.layer,...g?{rx:g.toString(),ry:g.toString()}:{}}};if(!l)return[v];const m={name:v.name,type:v.type,value:"",children:[],attributes:{...v.attributes,class:"pcb-solder-mask",fill:c}};return[v,m]}const _={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:vr(n.layer,r),x:(p-h/2).toString(),y:(u-d/2).toString(),width:h.toString(),height:d.toString(),"data-layer":n.layer,...g?{rx:g.toString(),ry:g.toString()}:{}}};if(!l)return[_];const x={name:_.name,type:_.type,value:"",children:[],attributes:{..._.attributes,class:"pcb-solder-mask",fill:c}};return[_,x]}if(n.shape==="pill"){const h=n.width*Math.abs(e.a),d=n.height*Math.abs(e.d),p=n.radius*Math.abs(e.a),[u,g]=B(e,[n.x,n.y]),_={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:vr(n.layer,r),x:(u-h/2).toString(),y:(g-d/2).toString(),width:h.toString(),height:d.toString(),rx:p.toString(),ry:p.toString(),"data-layer":n.layer}};if(!l)return[_];const x={name:_.name,type:_.type,value:"",children:[],attributes:{..._.attributes,class:"pcb-solder-mask",fill:c}};return[_,x]}if(n.shape==="circle"){const h=n.radius*Math.abs(e.a),[d,p]=B(e,[n.x,n.y]),u={name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:vr(n.layer,r),cx:d.toString(),cy:p.toString(),r:h.toString(),"data-layer":n.layer}};if(!l)return[u];const g={name:u.name,type:u.type,value:"",children:[],attributes:{...u.attributes,class:"pcb-solder-mask",fill:c}};return[u,g]}if(n.shape==="polygon"){const h=(n.points??[]).map(u=>B(e,[u.x,u.y])),d={name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:vr(n.layer,r),points:h.map(u=>u.join(",")).join(" "),"data-layer":n.layer}};if(!l)return[d];const p={name:d.name,type:d.type,value:"",children:[],attributes:{...d.attributes,class:"pcb-solder-mask",fill:c}};return[d,p]}return[]}function VP(n,t){const{transform:e,colorMap:s}=t,{width:r,height:i,center:a,outline:l}=n;let c;if(l&&Array.isArray(l)&&l.length>=3)c=l.map((h,d)=>{const[p,u]=B(e,[h.x,h.y]);return d===0?`M ${p} ${u}`:`L ${p} ${u}`}).join(" ");else{const h=r/2,d=i/2,p=B(e,[a.x-h,a.y-d]),u=B(e,[a.x+h,a.y-d]),g=B(e,[a.x+h,a.y+d]),_=B(e,[a.x-h,a.y+d]);c=`M ${p[0]} ${p[1]} L ${u[0]} ${u[1]} L ${g[0]} ${g[1]} L ${_[0]} ${_[1]}`}return c+=" Z",[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board",d:c,fill:"none",stroke:s.boardOutline,"stroke-width":(.1*Math.abs(e.a)).toString()}}]}function HP(n,t){const{transform:e,colorMap:s}=t,[r,i]=B(e,[n.x,n.y]),a=n.outer_diameter*Math.abs(e.a),l=n.outer_diameter*Math.abs(e.a),c=n.hole_diameter*Math.abs(e.a),h=n.hole_diameter*Math.abs(e.a),d=Math.min(a,l)/2,p=Math.min(c,h)/2;return{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"pcb-hole-outer",fill:s.copper.top,cx:r.toString(),cy:i.toString(),r:d.toString()}},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",fill:s.drill,cx:r.toString(),cy:i.toString(),r:p.toString()}}]}}function YP(n,t){const{transform:e,colorMap:s}=t,[r,i]=B(e,[n.x,n.y]);if(n.hole_shape==="circle"||n.hole_shape==="square"){const a=n.hole_diameter*Math.abs(e.a),l=a/2;return n.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"pcb-hole",cx:r.toString(),cy:i.toString(),r:l.toString(),fill:s.drill},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"pcb-hole",x:(r-l).toString(),y:(i-l).toString(),width:a.toString(),height:a.toString(),fill:s.drill},children:[],value:""}]}if(n.hole_shape==="oval"){const a=n.hole_width*Math.abs(e.a),l=n.hole_height*Math.abs(e.a),c=a/2,h=l/2;return[{name:"ellipse",type:"element",attributes:{class:"pcb-hole",cx:r.toString(),cy:i.toString(),rx:c.toString(),ry:h.toString(),fill:s.drill},children:[],value:""}]}return[]}var XP=(n,t)=>{const e=Ge(t).pcb_smtpad.get(n);if(e&&"x"in e&&"y"in e)return{x:e.x,y:e.y};const s=Ge(t).pcb_plated_hole.get(n);return s&&"x"in s&&"y"in s?{x:s.x,y:s.y}:null},qP=(n,t,e,s)=>{const r=e.getIdsConnectedToNet(t);let i=null,a=1/0;for(const l of r){const c=XP(l,s);if(c){const h=n.x-c.x,d=n.y-c.y,p=Math.sqrt(h*h+d*d);p>0&&p<a&&(a=p,i=c)}}return i};function KP(n,t){const{transform:e}=t,s=ag(n),r=n.filter(c=>c.type==="pcb_port"),i=n.filter(c=>c.type==="source_trace"),a=[];r.forEach((c,h)=>{const d=c.pcb_port_id;if(!d)return;const p=s.getNetConnectedToId(d);if(!p)return;let u=!1;const g=Ge(n).source_port.getWhere({pcb_port_id:d});if(g&&g.source_port_id){const v=g.source_port_id;for(const m of i)if(Array.isArray(m.connected_source_port_ids)&&m.connected_source_port_ids.includes(v)&&Array.isArray(m.connected_source_net_ids)&&m.connected_source_net_ids.length>0){u=!0;break}}const _={x:c.x,y:c.y},x=qP(_,p,s,n);x&&a.push({key:`${d}-${h}`,startPoint:_,endPoint:x,isInNet:u})});const l=[];for(const c of a){const h=B(e,[c.startPoint.x,c.startPoint.y]),d=B(e,[c.endPoint.x,c.endPoint.y]),p={x1:h[0].toString(),y1:h[1].toString(),x2:d[0].toString(),y2:d[1].toString(),stroke:"white","stroke-width":"1","stroke-dasharray":"6,6"};l.push({name:"line",type:"element",attributes:p,value:"",children:[]})}return l}function JP(n,t){const{transform:e,colorMap:s}=t;if(n.shape==="rect"){const r=n,[i,a]=B(e,[r.center.x,r.center.y]),l=r.width*Math.abs(e.a),c=r.height*Math.abs(e.d),h=-(r.rotation??0);return[{name:"rect",type:"element",attributes:{class:"pcb-cutout pcb-cutout-rect",x:(-l/2).toString(),y:(-c/2).toString(),width:l.toString(),height:c.toString(),fill:s.drill,transform:sc(si(fr(i,a),gr(h*Math.PI/180)))},children:[],value:""}]}if(n.shape==="circle"){const r=n,[i,a]=B(e,[r.center.x,r.center.y]),l=r.radius*Math.abs(e.a);return[{name:"circle",type:"element",attributes:{class:"pcb-cutout pcb-cutout-circle",cx:i.toString(),cy:a.toString(),r:l.toString(),fill:s.drill},children:[],value:""}]}if(n.shape==="polygon"){const r=n;return!r.points||r.points.length===0?[]:[{name:"polygon",type:"element",attributes:{class:"pcb-cutout pcb-cutout-polygon",points:r.points.map(l=>B(e,[l.x,l.y])).map(l=>`${l[0]},${l[1]}`).join(" "),fill:s.drill},children:[],value:""}]}return[]}function Zf(n,t){if(n.length===0)return"";const e=n.map(r=>{const[i,a]=B(t,[r.x,r.y]);return{...r,x:i,y:a}});let s=`M ${e[0].x} ${e[0].y}`;for(let r=0;r<e.length;r++){const i=e[r],a=e[(r+1)%e.length];if(i.bulge){if(Math.hypot(a.x-i.x,a.y-i.y)<1e-9)continue;const l=i.bulge,c=a.x-i.x,h=a.y-i.y,d=Math.hypot(c,h),p=Math.abs(d/4/l*(l*l+1)),u=l<0?1:0,g=Math.abs(l)>1?1:0;s+=` A ${p} ${p} 0 ${g} ${u} ${a.x} ${a.y}`}else s+=` L ${a.x} ${a.y}`}return s+=" Z",s}function ZP(n,t){const{transform:e,layer:s,colorMap:r}=t,{layer:i}=n;if(s&&i!==s)return[];const a=vr(i,r),l="0.5";if(n.shape==="rect"){const[c,h]=B(e,[n.center.x,n.center.y]),d=n.width*Math.abs(e.a),p=n.height*Math.abs(e.d),u=-(n.rotation??0);return[{name:"rect",type:"element",attributes:{class:"pcb-copper-pour pcb-copper-pour-rect",x:(-d/2).toString(),y:(-p/2).toString(),width:d.toString(),height:p.toString(),fill:a,"fill-opacity":l,transform:sc(si(fr(c,h),gr(u*Math.PI/180))),"data-layer":i},children:[],value:""}]}if(n.shape==="polygon")return!n.points||n.points.length===0?[]:[{name:"polygon",type:"element",attributes:{class:"pcb-copper-pour pcb-copper-pour-polygon",points:n.points.map(d=>B(e,[d.x,d.y])).map(d=>`${d[0]},${d[1]}`).join(" "),fill:a,"fill-opacity":l,"data-layer":i},children:[],value:""}];if(n.shape==="brep"){const{brep_shape:c}=n;let h=Zf(c.outer_ring.vertices,e);for(const d of c.inner_rings??[])h+=` ${Zf(d.vertices,e)}`;return[{name:"path",type:"element",attributes:{class:"pcb-copper-pour pcb-copper-pour-brep",d:h,fill:a,"fill-rule":"evenodd","fill-opacity":l,"data-layer":i},children:[],value:""}]}return[]}function QP(n,t){var u,g;const{transform:e}=t,{center:s,width:r,height:i,rotation:a=0}=n,[l,c]=B(e,[s.x,s.y]),h=r*Math.abs(e.a),d=i*Math.abs(e.d),p=`translate(${l}, ${c}) rotate(${-a}) scale(1, -1)`;return!((u=t.colorMap.debugComponent)!=null&&u.fill)&&!((g=t.colorMap.debugComponent)!=null&&g.stroke)?[]:[{name:"g",type:"element",attributes:{transform:p},children:[{name:"rect",type:"element",attributes:{class:"pcb-component",x:(-h/2).toString(),y:(-d/2).toString(),width:h.toString(),height:d.toString(),fill:t.colorMap.debugComponent.fill??"transparent",stroke:t.colorMap.debugComponent.stroke??"transparent"}}],value:""}]}function eT(n){const t=n.find(e=>e.type==="project_software_metadata"||e.type==="source_project_metadata");return t==null?void 0:t.software_used_string}var tT={version:"0.0.225"},sT=tT.version,Qf=["pcb_trace_error","pcb_plated_hole","pcb_fabrication_note_text","pcb_fabrication_note_path","pcb_silkscreen_text","pcb_silkscreen_path","pcb_via","pcb_cutout","pcb_copper_pour","pcb_smtpad","pcb_trace","pcb_component","pcb_board"];function nT(n,t){var ut,St,st,je,Ve,ye;const e=(t==null?void 0:t.drawPaddingOutsideBoard)??!0,s=t==null?void 0:t.layer,r=t==null?void 0:t.colorOverrides,i={...Ye.copper};if(r!=null&&r.copper)for(const[T,z]of Object.entries(r.copper))z!==void 0&&(i[T]=z);const a={copper:i,drill:(r==null?void 0:r.drill)??Ye.drill,silkscreen:{top:((ut=r==null?void 0:r.silkscreen)==null?void 0:ut.top)??Ye.silkscreen.top,bottom:((St=r==null?void 0:r.silkscreen)==null?void 0:St.bottom)??Ye.silkscreen.bottom},boardOutline:(r==null?void 0:r.boardOutline)??Ye.boardOutline,soldermask:{top:((st=r==null?void 0:r.soldermask)==null?void 0:st.top)??Ye.soldermask.top,bottom:((je=r==null?void 0:r.soldermask)==null?void 0:je.bottom)??Ye.soldermask.bottom},debugComponent:{fill:((Ve=r==null?void 0:r.debugComponent)==null?void 0:Ve.fill)??Ye.debugComponent.fill,stroke:((ye=r==null?void 0:r.debugComponent)==null?void 0:ye.stroke)??Ye.debugComponent.stroke}};let l=Number.POSITIVE_INFINITY,c=Number.POSITIVE_INFINITY,h=Number.NEGATIVE_INFINITY,d=Number.NEGATIVE_INFINITY,p=Number.POSITIVE_INFINITY,u=Number.POSITIVE_INFINITY,g=Number.NEGATIVE_INFINITY,_=Number.NEGATIVE_INFINITY;for(const T of n)if(T.type==="pcb_board")T.outline&&Array.isArray(T.outline)&&T.outline.length>=3?(Ce(T.outline),be(T.outline)):"center"in T&&"width"in T&&"height"in T&&(Y(T.center,T.width,T.height),Re(T.center,T.width,T.height));else if("x"in T&&"y"in T)Y({x:T.x,y:T.y},0,0);else if(T.type==="pcb_smtpad"){const z=T;z.shape==="rect"||z.shape==="rotated_rect"||z.shape==="pill"?Y({x:z.x,y:z.y},z.width,z.height):z.shape==="circle"?Y({x:z.x,y:z.y},z.radius*2,z.radius*2):z.shape==="polygon"&&Ue(z.points)}else"route"in T?Ue(T.route):T.type==="pcb_silkscreen_text"||T.type==="pcb_silkscreen_rect"||T.type==="pcb_silkscreen_circle"||T.type==="pcb_silkscreen_line"?Je(T):T.type==="pcb_copper_pour"&&(T.shape==="rect"?Y(T.center,T.width,T.height):T.shape==="polygon"&&Ue(T.points));const x=e?1:0,v=e||!Number.isFinite(p)?l:p,m=e||!Number.isFinite(u)?c:u,y=e||!Number.isFinite(g)?h:g,w=e||!Number.isFinite(_)?d:_,b=y-v+2*x,k=w-m+2*x;let C=(t==null?void 0:t.width)??800,E=(t==null?void 0:t.height)??600;if(t!=null&&t.matchBoardAspectRatio){const T=g-p,z=_-u;if(T>0&&z>0){const ae=T/z;t!=null&&t.width&&!(t!=null&&t.height)?E=t.width/ae:t!=null&&t.height&&!(t!=null&&t.width)?C=t.height*ae:E=C/ae}}const N=[];for(const T of n)"route"in T&&T.route!==void 0&&N.push(T.route);const I=C/b,M=E/k,S=Math.min(I,M),L=(C-b*S)/2,R=(E-k*S)/2,U=si(fr(L-v*S+x*S,E-R+m*S-x*S),pr(S,-S)),j={transform:U,layer:s,shouldDrawErrors:t==null?void 0:t.shouldDrawErrors,drawPaddingOutsideBoard:e,colorMap:a,renderSolderMask:t==null?void 0:t.renderSolderMask};function V(T){if(T.type==="pcb_smtpad")return T.layer==="top"||T.layer==="bottom"?T.layer:void 0;if(T.type==="pcb_trace")for(const z of T.route??[]){const ae="layer"in z&&z.layer||"from_layer"in z&&z.from_layer||"to_layer"in z&&z.to_layer||void 0;if(ae==="top"||ae==="bottom")return ae}}function G(T){return T.type==="pcb_trace"||T.type==="pcb_smtpad"}let ne=n.sort((T,z)=>{const ae=V(T),$=V(z);if(G(T)&&G(z)&&ae!==$){if(ae==="top")return 1;if($==="top"||ae==="bottom")return-1;if($==="bottom")return 1}return(Qf.indexOf(z.type)??9999)-(Qf.indexOf(T.type)??9999)}).flatMap(T=>rT({elm:T,circuitJson:n,ctx:j}));for(const T of n)if("stroke_width"in T){String(S*T.stroke_width);break}if(t!=null&&t.shouldDrawRatsNest){const T=KP(n,j);ne=ne.concat(T)}const J=[{name:"style",type:"element",value:"",attributes:{},children:[{type:"text",value:"",name:"",attributes:{},children:[]}]},{name:"rect",type:"element",value:"",attributes:{class:"boundary",x:"0",y:"0",fill:(t==null?void 0:t.backgroundColor)??"#000",width:C.toString(),height:E.toString()},children:[]}];e&&J.push(iT(U,l,c,h,d)),J.push(...ne);const re=eT(n),ee=sT,X={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:C.toString(),height:E.toString(),...re&&{"data-software-used-string":re},...(t==null?void 0:t.includeVersion)&&{"data-circuit-to-svg-version":ee}},value:"",children:J.filter(T=>T!==null)};try{return qx(X)}catch(T){throw console.error("Error stringifying SVG object:",T),T}function Y(T,z,ae){const $=z/2,Q=ae/2;l=Math.min(l,T.x-$),c=Math.min(c,T.y-Q),h=Math.max(h,T.x+$),d=Math.max(d,T.y+Q)}function Re(T,z,ae){const $=z/2,Q=ae/2;p=Math.min(p,T.x-$),u=Math.min(u,T.y-Q),g=Math.max(g,T.x+$),_=Math.max(_,T.y+Q)}function Ce(T){for(const z of T)l=Math.min(l,z.x),c=Math.min(c,z.y),h=Math.max(h,z.x),d=Math.max(d,z.y)}function be(T){for(const z of T)p=Math.min(p,z.x),u=Math.min(u,z.y),g=Math.max(g,z.x),_=Math.max(_,z.y)}function Ue(T){for(const z of T)l=Math.min(l,z.x),c=Math.min(c,z.y),h=Math.max(h,z.x),d=Math.max(d,z.y)}function Je(T){if(T.type==="pcb_silkscreen_text")Y(T.anchor_position,0,0);else if(T.type==="pcb_silkscreen_path")Ue(T.route);else if(T.type==="pcb_silkscreen_rect")Y(T.center,T.width,T.height);else if(T.type==="pcb_silkscreen_circle")Y(T.center,T.radius*2,T.radius*2);else if(T.type==="pcb_silkscreen_line")Y({x:T.x1,y:T.y1},0,0),Y({x:T.x2,y:T.y2},0,0);else if(T.type==="pcb_cutout"){const z=T;z.shape==="rect"?Y(z.center,z.width,z.height):z.shape==="circle"?Y(z.center,z.radius*2,z.radius*2):z.shape==="polygon"&&Ue(z.points)}}}function rT({elm:n,circuitJson:t,ctx:e}){switch(n.type){case"pcb_trace_error":return IP(n,t,e).filter(Boolean);case"pcb_component":return QP(n,e).filter(Boolean);case"pcb_trace":return WP(n,e);case"pcb_copper_pour":return ZP(n,e);case"pcb_plated_hole":return OP(n,e).filter(Boolean);case"pcb_hole":return YP(n,e);case"pcb_smtpad":return GP(n,e);case"pcb_silkscreen_text":return zP(n,e);case"pcb_silkscreen_rect":return UP(n,e);case"pcb_silkscreen_circle":return jP(n,e);case"pcb_silkscreen_line":return BP(n,e);case"pcb_fabrication_note_path":return MP(n,e);case"pcb_fabrication_note_text":return RP(n,e);case"pcb_silkscreen_path":return FP(n,e);case"pcb_board":return e.drawPaddingOutsideBoard?VP(n,e):[];case"pcb_via":return HP(n,e);case"pcb_cutout":return JP(n,e);default:return[]}}function iT(n,t,e,s,r){const[i,a]=B(n,[t,e]),[l,c]=B(n,[s,r]),h=Math.abs(l-i),d=Math.abs(c-a),p=Math.min(i,l),u=Math.min(a,c);return{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-boundary",fill:"none",stroke:"#fff","stroke-width":"0.3",x:p.toString(),y:u.toString(),width:h.toString(),height:d.toString()}}}var sp=Kx(),Qa=Jx(),di=Zx(),oT=Qx(),mx=ey(),aT=sy();const cT=ty(aT);function eg(n,t){let{x:e,y:s,z:r}=n;if(t.axisMapping){const i={x:e,y:s,z:r};t.axisMapping.x&&(e=Bc(i,t.axisMapping.x)),t.axisMapping.y&&(s=Bc(i,t.axisMapping.y)),t.axisMapping.z&&(r=Bc(i,t.axisMapping.z))}if(e*=t.flipX??1,s*=t.flipY??1,r*=t.flipZ??1,t.rotation){if(t.rotation.x){const i=t.rotation.x*Math.PI/180,a=Math.cos(i),l=Math.sin(i),c=s*a-r*l,h=s*l+r*a;s=c,r=h}if(t.rotation.y){const i=t.rotation.y*Math.PI/180,a=Math.cos(i),l=Math.sin(i),c=e*a+r*l,h=-e*l+r*a;e=c,r=h}if(t.rotation.z){const i=t.rotation.z*Math.PI/180,a=Math.cos(i),l=Math.sin(i),c=e*a-s*l,h=e*l+s*a;e=c,s=h}}return{x:e,y:s,z:r}}function Bc(n,t){switch(t){case"x":return n.x;case"y":return n.y;case"z":return n.z;case"-x":return-n.x;case"-y":return-n.y;case"-z":return-n.z;default:return 0}}function _c(n,t){return n.map(e=>({...e,vertices:e.vertices.map(s=>eg(s,t)),normal:eg(e.normal,t)}))}var mc={Z_UP_TO_Y_UP:{axisMapping:{x:"x",y:"-z",z:"y"}},Z_UP_TO_Y_UP_USB_FIX:{axisMapping:{x:"x",y:"-z",z:"y"},flipZ:-1},IDENTITY:{}},Dc=new Map;async function lT(n,t){const e=`${n}:${JSON.stringify(t??{})}`;if(Dc.has(e))return Dc.get(e);const r=await(await fetch(n)).arrayBuffer(),i=hT(r,t);return Dc.set(e,i),i}function hT(n,t){const e=new DataView(n);return new TextDecoder().decode(n.slice(0,5)).toLowerCase()==="solid"?dT(n,t):uT(e,t)}function dT(n,t){const s=new TextDecoder().decode(n).split(`
|
|
194
|
+
`).map(c=>c.trim()),r=[];let i=0;for(;i<s.length;){const c=s[i];if(c&&c.startsWith("facet normal")){const h=c.match(/facet normal\s+([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)\s+([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)\s+([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)/),d=h?{x:parseFloat(h[1]),y:parseFloat(h[2]),z:parseFloat(h[3])}:{x:0,y:0,z:1};i++;const p=[];for(;i<s.length&&s[i]&&!s[i].startsWith("endfacet");){const u=s[i];if(u.startsWith("vertex")){const g=u.match(/vertex\s+([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)\s+([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)\s+([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)/);g&&p.push({x:parseFloat(g[1]),y:parseFloat(g[2]),z:parseFloat(g[3])})}i++}p.length===3&&r.push({vertices:[p[0],p[1],p[2]],normal:d})}i++}const a=t??mc.Z_UP_TO_Y_UP,l=_c(r,a);return{triangles:l,boundingBox:xx(l)}}function uT(n,t){let e=80;const s=n.getUint32(e,!0);e+=4;const r=[];for(let l=0;l<s;l++){const c={x:n.getFloat32(e,!0),y:n.getFloat32(e+4,!0),z:n.getFloat32(e+8,!0)};e+=12;const h=[{x:n.getFloat32(e,!0),y:n.getFloat32(e+4,!0),z:n.getFloat32(e+8,!0)},{x:n.getFloat32(e+12,!0),y:n.getFloat32(e+16,!0),z:n.getFloat32(e+20,!0)},{x:n.getFloat32(e+24,!0),y:n.getFloat32(e+28,!0),z:n.getFloat32(e+32,!0)}];e+=36,e+=2,r.push({vertices:h,normal:c})}const i=t??mc.Z_UP_TO_Y_UP,a=_c(r,i);return{triangles:a,boundingBox:xx(a)}}function xx(n){if(n.length===0)return{min:{x:0,y:0,z:0},max:{x:0,y:0,z:0}};let t=1/0,e=1/0,s=1/0,r=-1/0,i=-1/0,a=-1/0;for(const l of n)for(const c of l.vertices)t=Math.min(t,c.x),e=Math.min(e,c.y),s=Math.min(s,c.z),r=Math.max(r,c.x),i=Math.max(i,c.y),a=Math.max(a,c.z);return{min:{x:t,y:e,z:s},max:{x:r,y:i,z:a}}}var Wc=new Map;async function pT(n,t){const e=`${n}:${JSON.stringify(t??{})}`;if(Wc.has(e))return Wc.get(e);const r=await(await fetch(n)).text(),i=fT(r,t);return Wc.set(e,i),i}function fT(n,t){const e=n.split(/\r?\n/),s=[],r=[],i=[],a=[],l=new Map;let c,h=0;const d=new Map;for(const g of e){const _=g.trim();if(_.startsWith("v ")){const x=_.split(/\s+/),v=x[1],m=x[2],y=x[3];if(s.push({x:parseFloat(v),y:parseFloat(m),z:parseFloat(y)}),x.length>=7){const[w,b,k]=x.slice(4,7);let C=Number(w),E=Number(b),N=Number(k);C<=1&&E<=1&&N<=1&&(C*=255,E*=255,N*=255),r.push([C,E,N,1])}else r.push(void 0)}else if(_.startsWith("vn ")){const x=_.split(/\s+/),v=x[1],m=x[2],y=x[3];i.push({x:parseFloat(v),y:parseFloat(m),z:parseFloat(y)})}else if(_.startsWith("newmtl ")){const x=_.split(/\s+/)[1];l.set(x,{name:x}),d.set(x,h++),c=x}else if(_.startsWith("Kd ")&&c){const x=_.split(/\s+/),v=x[1],m=x[2],y=x[3];let w=parseFloat(v),b=parseFloat(m),k=parseFloat(y);w<=1&&b<=1&&k<=1&&(w*=255,b*=255,k*=255);const C=l.get(c);C.color=[w,b,k,1]}else if(_.startsWith("Ka ")&&c){const x=_.split(/\s+/),v=x[1],m=x[2],y=x[3];let w=parseFloat(v),b=parseFloat(m),k=parseFloat(y);w<=1&&b<=1&&k<=1&&(w*=255,b*=255,k*=255);const C=l.get(c);C.ambient=[w,b,k,1]}else if(_.startsWith("Ks ")&&c){const x=_.split(/\s+/),v=x[1],m=x[2],y=x[3];let w=parseFloat(v),b=parseFloat(m),k=parseFloat(y);w<=1&&b<=1&&k<=1&&(w*=255,b*=255,k*=255);const C=l.get(c);C.specular=[w,b,k,1]}else if(_.startsWith("Ns ")&&c){const x=parseFloat(_.split(/\s+/)[1]),v=l.get(c);v.shininess=x}else if(_.startsWith("d ")&&c){const x=parseFloat(_.split(/\s+/)[1]),v=l.get(c);v.dissolve=x}else if(_==="endmtl")c=void 0;else if(_.startsWith("usemtl "))c=_.split(/\s+/)[1];else if(_.startsWith("f ")){const v=_.slice(2).trim().split(/\s+/).map(m=>{const[y,w,b]=m.split("/");return{v:parseInt(y)-1,n:b?parseInt(b)-1:void 0}});for(let m=1;m<v.length-1;m++){const y=v[0],w=v[m],b=v[m+1],k=s[y.v],C=s[w.v],E=s[b.v];let N;if(y.n!==void 0&&i[y.n])N=i[y.n];else if(w.n!==void 0&&i[w.n])N=i[w.n];else if(b.n!==void 0&&i[b.n])N=i[b.n];else{const S={x:C.x-k.x,y:C.y-k.y,z:C.z-k.z},L={x:E.x-k.x,y:E.y-k.y,z:E.z-k.z};N={x:S.y*L.z-S.z*L.y,y:S.z*L.x-S.x*L.z,z:S.x*L.y-S.y*L.x}}const I={vertices:[k,C,E],normal:N};c&&d.has(c)&&(I.materialIndex=d.get(c));const M=r[y.v]??r[w.v]??r[b.v];M&&(I.color=M),a.push(I)}}}const p=t??mc.IDENTITY,u=_c(a,p);return{triangles:u,boundingBox:gT(u),materials:l.size>0?l:void 0,materialIndexMap:l.size>0?d:void 0}}function gT(n){if(n.length===0)return{min:{x:0,y:0,z:0},max:{x:0,y:0,z:0}};let t=1/0,e=1/0,s=1/0,r=-1/0,i=-1/0,a=-1/0;for(const l of n)for(const c of l.vertices)c.x<t&&(t=c.x),c.y<e&&(e=c.y),c.z<s&&(s=c.z),c.x>r&&(r=c.x),c.y>i&&(i=c.y),c.z>a&&(a=c.z);return{min:{x:t,y:e,z:s},max:{x:r,y:i,z:a}}}var Gc=new Map;async function _T(n,t){const e=`${n}:${JSON.stringify(t??{})}`;if(Gc.has(e))return Gc.get(e);const r=await(await fetch(n)).arrayBuffer(),i=yx(r,t);return Gc.set(e,i),i}function yx(n,t){const e=new DataView(n);let s=0;const r=e.getUint32(s,!0);if(s+=4,r!==1179937895)throw new Error("Invalid GLB file: incorrect magic number");const i=e.getUint32(s,!0);if(s+=4,i!==2)throw new Error(`Unsupported GLB version: ${i}`);const a=e.getUint32(s,!0);s+=4;const l=e.getUint32(s,!0);s+=4;const c=e.getUint32(s,!0);if(s+=4,c!==1313821514)throw new Error("Expected JSON chunk");const h=new Uint8Array(n,s,l),d=new TextDecoder().decode(h),p=JSON.parse(d);s+=l;let u;if(s<a){const m=e.getUint32(s,!0);s+=4;const y=e.getUint32(s,!0);s+=4,y===5130562&&(u=n.slice(s,s+m))}const g=xT(p,u),x=_c(g,t??{axisMapping:{x:"x",y:"z",z:"y"}});return x.some(m=>m.color!==void 0)?mT(x):{triangles:x,boundingBox:vx(x)}}function mT(n){const t=new Map;for(const a of n){const l=a.color?JSON.stringify(a.color):"default";t.has(l)||t.set(l,[]),t.get(l).push(a)}const e=new Map,s=new Map;let r=0;const i=[];for(const[a,l]of t){const c=`Material_${r}`;if(s.set(c,r),a==="default")e.set(c,{name:c,color:[179,179,179,1]});else{const h=JSON.parse(a);e.set(c,{name:c,color:h})}for(const h of l)i.push({...h,materialIndex:r});r++}return{triangles:i,boundingBox:vx(i),materials:e,materialIndexMap:s}}function xT(n,t){var s;const e=[];if(!n.meshes||!n.accessors||!n.bufferViews)return e;for(const r of n.meshes)for(const i of r.primitives){if((i.mode??4)!==4)continue;const l=i.attributes.POSITION;if(l===void 0)continue;const c=n.accessors[l],h=So(c,n.bufferViews,t);let d;const p=i.attributes.NORMAL;if(p!==void 0){const m=n.accessors[p];d=So(m,n.bufferViews,t)}let u;const g=i.attributes.COLOR_0;if(g!==void 0){const m=n.accessors[g];u=So(m,n.bufferViews,t)}let _;if(!u&&i.material!==void 0&&n.materials){const m=n.materials[i.material];if((s=m==null?void 0:m.pbrMetallicRoughness)!=null&&s.baseColorFactor){const y=m.pbrMetallicRoughness.baseColorFactor;_=[Math.round(y[0]*255),Math.round(y[1]*255),Math.round(y[2]*255),y[3]]}}let x;if(i.indices!==void 0){const m=n.accessors[i.indices],y=So(m,n.bufferViews,t);x=m.componentType===5123?new Uint16Array(y.buffer,y.byteOffset,y.length):new Uint32Array(y.buffer,y.byteOffset,y.length)}const v=h.length/3;if(x)for(let m=0;m<x.length;m+=3){const y=x[m],w=x[m+1],b=x[m+2],k={x:h[y*3],y:h[y*3+1],z:h[y*3+2]},C={x:h[w*3],y:h[w*3+1],z:h[w*3+2]},E={x:h[b*3],y:h[b*3+1],z:h[b*3+2]};let N;d?N={x:(d[y*3]+d[w*3]+d[b*3])/3,y:(d[y*3+1]+d[w*3+1]+d[b*3+1])/3,z:(d[y*3+2]+d[w*3+2]+d[b*3+2])/3}:N=tg(k,C,E);let I;if(u){const M=u.length/v;M===3?I=[Math.round((u[y*3]+u[w*3]+u[b*3])/3*255),Math.round((u[y*3+1]+u[w*3+1]+u[b*3+1])/3*255),Math.round((u[y*3+2]+u[w*3+2]+u[b*3+2])/3*255),1]:M===4&&(I=[Math.round((u[y*4]+u[w*4]+u[b*4])/3*255),Math.round((u[y*4+1]+u[w*4+1]+u[b*4+1])/3*255),Math.round((u[y*4+2]+u[w*4+2]+u[b*4+2])/3*255),(u[y*4+3]+u[w*4+3]+u[b*4+3])/3])}else I=_;e.push({vertices:[k,C,E],normal:N,color:I})}else for(let m=0;m<v;m+=3){const y={x:h[m*3],y:h[m*3+1],z:h[m*3+2]},w={x:h[(m+1)*3],y:h[(m+1)*3+1],z:h[(m+1)*3+2]},b={x:h[(m+2)*3],y:h[(m+2)*3+1],z:h[(m+2)*3+2]};let k;d?k={x:(d[m*3]+d[(m+1)*3]+d[(m+2)*3])/3,y:(d[m*3+1]+d[(m+1)*3+1]+d[(m+2)*3+1])/3,z:(d[m*3+2]+d[(m+1)*3+2]+d[(m+2)*3+2])/3}:k=tg(y,w,b);let C;if(u){const E=u.length/v;E===3?C=[Math.round((u[m*3]+u[(m+1)*3]+u[(m+2)*3])/3*255),Math.round((u[m*3+1]+u[(m+1)*3+1]+u[(m+2)*3+1])/3*255),Math.round((u[m*3+2]+u[(m+1)*3+2]+u[(m+2)*3+2])/3*255),1]:E===4&&(C=[Math.round((u[m*4]+u[(m+1)*4]+u[(m+2)*4])/3*255),Math.round((u[m*4+1]+u[(m+1)*4+1]+u[(m+2)*4+1])/3*255),Math.round((u[m*4+2]+u[(m+1)*4+2]+u[(m+2)*4+2])/3*255),(u[m*4+3]+u[(m+1)*4+3]+u[(m+2)*4+3])/3])}else C=_;e.push({vertices:[y,w,b],normal:k,color:C})}}return e}function So(n,t,e){const s=t[n.bufferView];if(!s||!e)throw new Error("Missing buffer data");const r=(s.byteOffset??0)+(n.byteOffset??0),i=n.componentType,a=n.count,l=n.type,h=a*(l==="SCALAR"?1:l==="VEC2"?2:l==="VEC3"?3:l==="VEC4"?4:1);if(i===5126)return new Float32Array(e,r,h);if(i===5123){const d=new Uint16Array(e,r,h);return new Float32Array(d)}else if(i===5125){const d=new Uint32Array(e,r,h);return new Float32Array(d)}else if(i===5122){const d=new Int16Array(e,r,h);return new Float32Array(d)}else if(i===5124){const d=new Int32Array(e,r,h);return new Float32Array(d)}else if(i===5121){const d=new Uint8Array(e,r,h);return new Float32Array(d)}else if(i===5120){const d=new Int8Array(e,r,h);return new Float32Array(d)}throw new Error(`Unsupported component type: ${i}`)}function tg(n,t,e){const s={x:t.x-n.x,y:t.y-n.y,z:t.z-n.z},r={x:e.x-n.x,y:e.y-n.y,z:e.z-n.z};return{x:s.y*r.z-s.z*r.y,y:s.z*r.x-s.x*r.z,z:s.x*r.y-s.y*r.x}}function vx(n){if(n.length===0)return{min:{x:0,y:0,z:0},max:{x:0,y:0,z:0}};let t=1/0,e=1/0,s=1/0,r=-1/0,i=-1/0,a=-1/0;for(const l of n)for(const c of l.vertices)t=Math.min(t,c.x),e=Math.min(e,c.y),s=Math.min(s,c.z),r=Math.max(r,c.x),i=Math.max(i,c.y),a=Math.max(a,c.z);return{min:{x:t,y:e,z:s},max:{x:r,y:i,z:a}}}async function yT(n){const t=await fetch(n);if(!t.ok)throw new Error(`Failed to fetch ${n}: ${t.statusText}`);return t.arrayBuffer()}function vT(n){const t=n.split(","),e=atob(t[1]),s=new ArrayBuffer(e.length),r=new Uint8Array(s);for(let i=0;i<e.length;i++)r[i]=e.charCodeAt(i);return s}async function wT(n){const t=await fetch(n);if(!t.ok)throw new Error(`Failed to fetch glTF file: ${t.statusText}`);const e=await t.json(),s=[];if(e.buffers){for(const _ of e.buffers)if(_.uri)if(_.uri.startsWith("data:"))s.push(Promise.resolve(vT(_.uri)));else{const x=new URL(_.uri,n).toString();s.push(yT(x))}}const r=await Promise.all(s);let i=new ArrayBuffer(0);r.length>0&&r[0]&&(i=r[0]),e.buffers&&e.buffers.length>0&&(delete e.buffers[0].uri,e.buffers[0].byteLength=i.byteLength);const a=JSON.stringify(e),l=new TextEncoder().encode(a),c=(4-l.length%4)%4,h=(4-i.byteLength%4)%4,d=12+(8+l.length+c)+(i.byteLength>0?8+i.byteLength+h:0),p=new ArrayBuffer(d),u=new DataView(p);let g=0;u.setUint32(g,1179937895,!0),g+=4,u.setUint32(g,2,!0),g+=4,u.setUint32(g,d,!0),g+=4,u.setUint32(g,l.length+c,!0),g+=4,u.setUint32(g,1313821514,!0),g+=4,new Uint8Array(p,g).set(l),g+=l.length;for(let _=0;_<c;_++)u.setUint8(g++,32);if(i.byteLength>0){u.setUint32(g,i.byteLength+h,!0),g+=4,u.setUint32(g,5130562,!0),g+=4,new Uint8Array(p,g).set(new Uint8Array(i)),g+=i.byteLength;for(let _=0;_<h;_++)u.setUint8(g++,0)}return p}async function bT(n,t){const e=await wT(n);return yx(e,t)}async function sg(n,t){const{layer:e,resolution:s=1024,backgroundColor:r="transparent",copperColor:i="#ffe066",silkscreenColor:a="#ffffff",drillColor:l="rgba(0,0,0,0.5)"}=t,h=nT(n,{layer:e,matchBoardAspectRatio:!0,backgroundColor:r,drawPaddingOutsideBoard:!1,colorOverrides:{soldermask:{top:"#4CAF50",bottom:"#4CAF50"},copper:{top:i,bottom:i},silkscreen:{top:a,bottom:a},drill:l}});return await kT(h,s,r)}async function kT(n,t,e){if(typeof window<"u"&&typeof document<"u")return ng(n,t,e);try{const{svgToPngDataUrl:s}=await ri(async()=>{const{svgToPngDataUrl:r}=await import("./svg-to-png-BX4YEHCP-pNo9Afg8.js");return{svgToPngDataUrl:r}},[]);return await s(n,{width:t,background:e})}catch(s){return console.warn("Failed to load native svg-to-png, falling back to browser method:",s),ng(n,t,e)}}async function ng(n,t,e){return new Promise((s,r)=>{const i=document.createElement("canvas");i.width=t,i.height=t;const a=i.getContext("2d");a.fillStyle=e,a.fillRect(0,0,t,t);const l=`data:image/svg+xml;base64,${btoa(n)}`,c=new Image;c.onload=()=>{try{a.drawImage(c,0,0,t,t),s(i.toDataURL("image/png"))}catch(h){r(h)}},c.onerror=h=>{console.error("Failed to load SVG image:",h),r(h)},c.src=l})}async function ST(n,t=1024){console.log("Generating PCB texture...");const[e,s]=await Promise.all([sg(n,{layer:"top",resolution:t,backgroundColor:"#008C00"}),sg(n,{layer:"bottom",resolution:t,backgroundColor:"#006600"})]);return console.log("PCB texture generated:",{topLength:e.length,bottomLength:s.length}),{top:e,bottom:s}}var wx=64,PT=1e-4,TT=(n,t)=>[n.x-t.x,n.y-t.y],ET=n=>{let t=0;for(let s=0;s<n.length;s++){const r=(s+1)%n.length;t+=n[s][0]*n[r][1],t-=n[r][0]*n[s][1]}return t/2<=0},Kt=(n,t)=>{const e=n[t];return typeof e=="number"?e:void 0},CT=(n,t,e)=>{if(n.outline&&n.outline.length>=3){let i=n.outline.map(c=>TT(c,t));ET(i)&&(i=i.slice().reverse());const a=Qa.polygon({points:i});let l=sp.extrudeLinear({height:e},a);return l=di.translate([0,0,-e/2],l),l}const s=Qa.rectangle({size:[n.width,n.height]});let r=sp.extrudeLinear({height:e},s);return r=di.translate([0,0,-e/2],r),r},rg=(n,t,e,s)=>Qa.cylinder({center:[n,t,0],height:s+1,radius:e,segments:wx}),NT=(n,t,e,s,r,i)=>{const a=Math.min(e,s),l=Math.max(0,a/2-PT),c=l<=0?0:Math.min(s/2,l),h=Qa.roundedRectangle({size:[e,s],roundRadius:c,segments:wx});let d=sp.extrudeLinear({height:r+1},h);return d=di.translate([0,0,-(r+1)/2],d),i&&(d=di.rotateZ(Math.PI/2,d)),di.translate([n,t,0],d)},$T=(n,t,e=[],s=[])=>{const r=[];for(const i of e){const a=i,l=Kt(a,"hole_diameter")??Kt(a,"diameter");if(!l)continue;const c=l/2,h=i.x-n.x,d=-(i.y-n.y);r.push(rg(h,d,c,t))}for(const i of s){const a=i.x-n.x,l=-(i.y-n.y),c=i;if(i.shape==="pill"||i.shape==="pill_hole_with_rect_pad"){const d=Kt(c,"hole_width")??Kt(c,"outer_diameter")??0,p=Kt(c,"hole_height")??Kt(c,"hole_diameter")??0;if(!d||!p)continue;const u=p>d,g=u?p:d,_=u?d:p;r.push(NT(a,l,g,_,t,u));continue}const h=Kt(c,"hole_diameter")??Kt(c,"outer_diameter");h&&r.push(rg(a,l,h/2,t))}return r},AT=(n,t)=>{const e=t??mx.toPolygons(n),s=[];for(const r of e){if(!r||r.vertices.length<3)continue;const i=r.vertices[0],a=r.vertices[1],l=r.vertices[2],c=[a[0]-i[0],a[1]-i[1],a[2]-i[2]],h=[l[0]-i[0],l[1]-i[1],l[2]-i[2]],d=[c[1]*h[2]-c[2]*h[1],c[2]*h[0]-c[0]*h[2],c[0]*h[1]-c[1]*h[0]],p=Math.sqrt(d[0]**2+d[1]**2+d[2]**2)||1,u={x:d[0]/p,y:d[1]/p,z:d[2]/p};for(let g=1;g<r.vertices.length-1;g++){const _=r.vertices[g],x=r.vertices[g+1],v={vertices:[{x:i[0],y:i[1],z:i[2]},{x:_[0],y:_[1],z:_[2]},{x:x[0],y:x[1],z:x[2]}],normal:u};s.push(v)}}return s},IT=n=>{const[t,e]=n;return{min:{x:t[0],y:t[1],z:t[2]},max:{x:e[0],y:e[1],z:e[2]}}},LT=(n,t)=>{const{thickness:e,holes:s=[],platedHoles:r=[]}=t,i=n.center??{x:0,y:0};let a=CT(n,i,e);const l=$T(i,e,s,r);l.length>0&&(a=oT.subtract(a,...l)),a=di.rotateX(-Math.PI/2,a);const c=mx.toPolygons(a),h=AT(a,c),d=cT(a),p=IT(d);return{triangles:h,boundingBox:p}},MT=1.6,RT=2;function Po(n){return{x:n.x*Math.PI/180,y:n.y*Math.PI/180,z:n.z*Math.PI/180}}async function OT(n,t={}){var m,y,w,b,k,C,E,N,I,M;const{pcbColor:e="rgba(0,140,0,0.8)",componentColor:s="rgba(128,128,128,0.5)",boardThickness:r=MT,defaultComponentHeight:i=RT,renderBoardTextures:a=!0,textureResolution:l=1024,coordinateTransform:c}=t,h=co(n),d=[],p=(y=(m=h.pcb_board)==null?void 0:m.list)==null?void 0:y.call(m)[0],u=(p==null?void 0:p.thickness)??r;if(p){const S=((b=(w=h.pcb_hole)==null?void 0:w.list)==null?void 0:b.call(w))??[],L=((C=(k=h.pcb_plated_hole)==null?void 0:k.list)==null?void 0:C.call(k))??[],R=LT(p,{thickness:u,holes:S,platedHoles:L}),U=R.boundingBox.max.x-R.boundingBox.min.x,j=R.boundingBox.max.z-R.boundingBox.min.z,V={center:{x:p.center.x,y:0,z:p.center.y},size:{x:Number.isFinite(U)?U:p.width,y:u,z:Number.isFinite(j)?j:p.height},mesh:R,color:e};if(a&&l>0)try{const G=await ST(n,l);V.texture={top:G.top,bottom:G.bottom}}catch(G){console.warn("Failed to render board textures:",G),V.color=e}else V.color=e;d.push(V)}const g=((N=(E=h.cad_component)==null?void 0:E.list)==null?void 0:N.call(E))??[],_=new Set;for(const S of g){let{model_stl_url:L,model_obj_url:R,model_glb_url:U,model_gltf_url:j}=S,V=!!(L||R||U||j);if(!V&&S.footprinter_string&&(U=`https://modelcdn.tscircuit.com/jscad_models/${S.footprinter_string}.glb`,V=!0),!V)continue;_.add(S.pcb_component_id);const G=h.pcb_component.get(S.pcb_component_id),ne=(G==null?void 0:G.layer)==="bottom",J=S.size??{x:(G==null?void 0:G.width)??2,y:i,z:(G==null?void 0:G.height)??2},X={center:S.position?{x:S.position.x,y:ne?-Math.abs(S.position.z):S.position.z,z:S.position.y}:{x:(G==null?void 0:G.center.x)??0,y:ne?-(u/2+J.y/2):u/2+J.y/2,z:(G==null?void 0:G.center.y)??0},size:J,meshUrl:L||R||U||j,meshType:L?"stl":R?"obj":j?"gltf":"glb"};S.rotation?U||j?X.rotation=Po({x:ne?S.rotation.x+180:S.rotation.x,y:S.rotation.z,z:S.rotation.y}):X.rotation=Po({x:ne?S.rotation.x+180:S.rotation.x,y:S.rotation.y,z:S.rotation.z}):ne&&(U||j?X.rotation=Po({x:180,y:0,z:0}):X.rotation=Po({x:180,y:0,z:0}));const Y=c??(U||j?void 0:mc.Z_UP_TO_Y_UP_USB_FIX);L?X.mesh=await lT(L,Y):R?X.mesh=await pT(R,Y):U?X.mesh=await _T(U,Y):j&&(X.mesh=await bT(j,Y)),X.mesh||(X.color=s),d.push(X)}for(const S of h.pcb_component.list()){if(_.has(S.pcb_component_id))continue;const L=h.source_component.get(S.source_component_id),R=Math.min(Math.min(S.width,S.height),i),U=S.layer==="bottom";d.push({center:{x:S.center.x,y:U?-(u/2+R/2):u/2+R/2,z:S.center.y},size:{x:S.width,y:R,z:S.height},color:s,label:(L==null?void 0:L.name)??"?",labelColor:"white"})}let x;if(p){const L=Math.sqrt(p.width*p.width+p.height*p.height)*1.5;x={position:{x:p.center.x+L*.5,y:L*.7,z:p.center.y+L*.5},target:{x:p.center.x,y:0,z:p.center.y},up:{x:0,y:1,z:0},fov:50,near:.1,far:L*4}}else if(d.length>0){let L=1/0,R=1/0,U=-1/0,j=-1/0;for(const X of d){const Y=(((I=X.size)==null?void 0:I.x)??0)/2,Re=(((M=X.size)==null?void 0:M.z)??0)/2;L=Math.min(L,X.center.x-Y),U=Math.max(U,X.center.x+Y),R=Math.min(R,X.center.z-Re),j=Math.max(j,X.center.z+Re)}const V=Math.max(U-L,1),G=Math.max(j-R,1),J=Math.sqrt(V*V+G*G)*1.5,re=(L+U)/2,ee=(R+j)/2;x={position:{x:re+J*.5,y:J*.7,z:ee+J*.5},target:{x:re,y:0,z:ee},up:{x:0,y:1,z:0},fov:50,near:.1,far:J*4}}else x={position:{x:30,y:30,z:25},target:{x:0,y:0,z:0},up:{x:0,y:1,z:0},fov:50,near:.1,far:120};return{boxes:d,camera:x,lights:[{type:"ambient",color:"white",intensity:.5},{type:"directional",color:"white",intensity:.5,direction:{x:-1,y:-1,z:-1}}]}}function FT(n){const{center:t,size:e}=n,s=e.x/2,r=e.y/2,i=e.z/2,a=[{x:-s,y:-r,z:-i},{x:s,y:-r,z:-i},{x:s,y:r,z:-i},{x:-s,y:r,z:-i},{x:-s,y:-r,z:i},{x:s,y:-r,z:i},{x:s,y:r,z:i},{x:-s,y:r,z:i}].map(c=>({x:c.x+t.x,y:c.y+t.y,z:c.z+t.z}));return[{vertices:[a[0],a[1],a[2]],normal:{x:0,y:0,z:-1}},{vertices:[a[0],a[2],a[3]],normal:{x:0,y:0,z:-1}},{vertices:[a[4],a[6],a[5]],normal:{x:0,y:0,z:1}},{vertices:[a[4],a[7],a[6]],normal:{x:0,y:0,z:1}},{vertices:[a[0],a[5],a[1]],normal:{x:0,y:-1,z:0}},{vertices:[a[0],a[4],a[5]],normal:{x:0,y:-1,z:0}},{vertices:[a[2],a[6],a[7]],normal:{x:0,y:1,z:0}},{vertices:[a[2],a[7],a[3]],normal:{x:0,y:1,z:0}},{vertices:[a[0],a[3],a[7]],normal:{x:-1,y:0,z:0}},{vertices:[a[0],a[7],a[4]],normal:{x:-1,y:0,z:0}},{vertices:[a[1],a[6],a[2]],normal:{x:1,y:0,z:0}},{vertices:[a[1],a[5],a[6]],normal:{x:1,y:0,z:0}}]}function zT(n,t){const e=[];for(const s of t){const r=n.add(new Xe("",n.add(new we("",s.vertices[0].x,s.vertices[0].y,s.vertices[0].z)))),i=n.add(new Xe("",n.add(new we("",s.vertices[1].x,s.vertices[1].y,s.vertices[1].z)))),a=n.add(new Xe("",n.add(new we("",s.vertices[2].x,s.vertices[2].y,s.vertices[2].z)))),l=r.resolve(n).pnt.resolve(n),c=i.resolve(n).pnt.resolve(n),h=(C,E)=>{const N=C.resolve(n).pnt.resolve(n),I=E.resolve(n).pnt.resolve(n),M=n.add(new We("",I.x-N.x,I.y-N.y,I.z-N.z)),S=n.add(new fi("",M,1)),L=n.add(new pi("",C.resolve(n).pnt,S));return n.add(new Nt("",C,E,L,!0))},d=h(r,i),p=h(i,a),u=h(a,r),g=n.add(new pt("",[n.add(new Me("",d,!0)),n.add(new Me("",p,!0)),n.add(new Me("",u,!0))])),_=n.add(new We("",s.normal.x,s.normal.y,s.normal.z)),x=c.x-l.x,v=c.y-l.y,m=c.z-l.z,y=n.add(new We("",x,v,m)),w=n.add(new Qe("",r.resolve(n).pnt,_,y)),b=n.add(new ur("",w)),k=n.add(new Vt("",[n.add(new Ht("",g,!0))],b,!0));e.push(k)}return e}async function UT(n){const{repo:t,circuitJson:e,boardThickness:s,includeExternalMeshes:r=!1}=n,i=[];try{const a=e.filter(h=>h.type!=="pcb_board").map(h=>!r&&h.type==="cad_component"?{...h,model_3mf_url:void 0,model_obj_url:void 0,model_stl_url:void 0,model_glb_url:void 0,model_gltf_url:void 0}:h),l=await OT(a,{boardThickness:s,renderBoardTextures:!1}),c=[];for(const h of l.boxes)if(h.mesh&&"triangles"in h.mesh)c.push(...h.mesh.triangles);else{const d=FT(h);c.push(...d)}if(c.length>0){const h=c.map(g=>({vertices:g.vertices.map(_=>({x:_.x,y:_.z,z:_.y})),normal:{x:g.normal.x,y:g.normal.z,z:g.normal.y}})),d=zT(t,h),p=t.add(new gi("",d)),u=t.add(new mi("Components",p));i.push(u)}}catch(a){console.warn("Failed to generate component mesh:",a)}return i}async function jT(n,t={}){var z,ae;const e=new $P,s=n.find($=>$.type==="pcb_board"),r=n.filter($=>$.type==="pcb_hole"||$.type==="pcb_plated_hole"),i=t.boardWidth??(s==null?void 0:s.width),a=t.boardHeight??(s==null?void 0:s.height),l=t.boardThickness??(s==null?void 0:s.thickness)??1.6,c=t.productName??"PCB",h=((z=s==null?void 0:s.center)==null?void 0:z.x)??0,d=((ae=s==null?void 0:s.center)==null?void 0:ae.y)??0;if(!i||!a)throw new Error("Board dimensions not found. Either provide boardWidth and boardHeight in options, or include a pcb_board in the circuit JSON with width and height properties.");const p=e.add(new Qi("core data for automotive mechanical design processes"));e.add(new eo("international standard","automotive_design",2010,p));const u=e.add(new so("",p,"mechanical")),g=e.add(new to(c,c,"",[u])),_=e.add(new ro("part definition",p,"design")),x=e.add(new io("","",g)),v=e.add(new no("","",x,_)),m=e.add(new oo("","",v)),y=e.add(new Ei("",["( LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(.MILLI.,.METRE.) )"])),w=e.add(new Ei("",["( NAMED_UNIT(*) PLANE_ANGLE_UNIT() SI_UNIT($,.RADIAN.) )"])),b=e.add(new Ei("",["( NAMED_UNIT(*) SI_UNIT($,.STERADIAN.) SOLID_ANGLE_UNIT() )"])),k=e.add(new Ei("UNCERTAINTY_MEASURE_WITH_UNIT",["LENGTH_MEASURE(1.E-07)",`${y}`,"'distance_accuracy_value'","'Maximum Tolerance'"])),C=e.add(new Ei("",[`( GEOMETRIC_REPRESENTATION_CONTEXT(3) GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((${k})) GLOBAL_UNIT_ASSIGNED_CONTEXT((${y},${w},${b})) REPRESENTATION_CONTEXT('${c}','3D') )`])),E=s==null?void 0:s.outline;let N,I;if(E&&Array.isArray(E)&&E.length>=3)N=E.map($=>e.add(new Xe("",e.add(new we("",$.x,$.y,0))))),I=E.map($=>e.add(new Xe("",e.add(new we("",$.x,$.y,l)))));else{const $=i/2,Q=a/2,ie=[[h-$,d-Q,0],[h+$,d-Q,0],[h+$,d+Q,0],[h-$,d+Q,0],[h-$,d-Q,l],[h+$,d-Q,l],[h+$,d+Q,l],[h-$,d+Q,l]].map(([ue,Le,ke])=>e.add(new Xe("",e.add(new we("",ue,Le,ke)))));N=[ie[0],ie[1],ie[2],ie[3]],I=[ie[4],ie[5],ie[6],ie[7]]}function M($,Q){const te=$.resolve(e).pnt.resolve(e),ie=Q.resolve(e).pnt.resolve(e),ue=e.add(new We("",ie.x-te.x,ie.y-te.y,ie.z-te.z)),Le=e.add(new fi("",ue,1)),ke=e.add(new pi("",$.resolve(e).pnt,Le));return e.add(new Nt("",$,Q,ke,!0))}const S=[],L=[],R=[];for(let $=0;$<N.length;$++){const Q=N[$],te=N[($+1)%N.length];S.push(M(Q,te))}for(let $=0;$<I.length;$++){const Q=I[$],te=I[($+1)%I.length];L.push(M(Q,te))}for(let $=0;$<N.length;$++)R.push(M(N[$],I[$]));const U=e.add(new we("",0,0,0)),j=e.add(new We("",1,0,0)),V=e.add(new We("",0,0,1)),G=e.add(new Qe("",U,e.add(new We("",0,0,-1)),j)),ne=e.add(new ur("",G)),J=e.add(new pt("",S.map($=>e.add(new Me("",$,!0))))),re=[];for(const $ of r)if(($.hole_shape||$.shape)==="circle"){const te=typeof $.x=="number"?$.x:$.x.value,ie=typeof $.y=="number"?$.y:$.y.value,ue=$.hole_diameter/2,Le=e.add(new we("",te,ie,0)),ke=e.add(new Xe("",e.add(new we("",te+ue,ie,0)))),Ot=e.add(new Qe("",Le,e.add(new We("",0,0,-1)),j)),Ft=e.add(new lr("",Ot,ue)),_r=e.add(new Nt("",ke,ke,Ft,!0)),mr=e.add(new pt("",[e.add(new Me("",_r,!1))]));re.push(e.add(new _i("",mr,!0)))}const ee=e.add(new Vt("",[e.add(new Ht("",J,!0)),...re],ne,!0)),X=e.add(new we("",0,0,l)),Y=e.add(new Qe("",X,V,j)),Re=e.add(new ur("",Y)),Ce=e.add(new pt("",L.map($=>e.add(new Me("",$,!1))))),be=[];for(const $ of r)if(($.hole_shape||$.shape)==="circle"){const te=typeof $.x=="number"?$.x:$.x.value,ie=typeof $.y=="number"?$.y:$.y.value,ue=$.hole_diameter/2,Le=e.add(new we("",te,ie,l)),ke=e.add(new Xe("",e.add(new we("",te+ue,ie,l)))),Ot=e.add(new Qe("",Le,V,j)),Ft=e.add(new lr("",Ot,ue)),_r=e.add(new Nt("",ke,ke,Ft,!0)),mr=e.add(new pt("",[e.add(new Me("",_r,!0))]));be.push(e.add(new _i("",mr,!0)))}const Ue=e.add(new Vt("",[e.add(new Ht("",Ce,!0)),...be],Re,!0)),Je=[];for(let $=0;$<S.length;$++){const Q=($+1)%S.length,te=N[$].resolve(e).pnt,ie=N[Q].resolve(e).pnt,ue=te.resolve(e),Le=ie.resolve(e),ke={x:Le.x-ue.x,y:Le.y-ue.y},Ot=e.add(new We("",ke.y,-ke.x,0)),Ft=e.add(new We("",ke.x,ke.y,0)),_r=e.add(new Qe("",te,Ot,Ft)),mr=e.add(new ur("",_r)),_o=e.add(new pt("",[e.add(new Me("",S[$],!0)),e.add(new Me("",R[Q],!0)),e.add(new Me("",L[$],!1)),e.add(new Me("",R[$],!1))])),xc=e.add(new Vt("",[e.add(new Ht("",_o,!0))],mr,!0));Je.push(xc)}const ut=[];for(const $ of r)if(($.hole_shape||$.shape)==="circle"){const te=typeof $.x=="number"?$.x:$.x.value,ie=typeof $.y=="number"?$.y:$.y.value,ue=$.hole_diameter/2,Le=e.add(new we("",te,ie,0)),ke=e.add(new Xe("",e.add(new we("",te+ue,ie,0)))),Ot=e.add(new Qe("",Le,e.add(new We("",0,0,-1)),j)),Ft=e.add(new lr("",Ot,ue)),_r=e.add(new Nt("",ke,ke,Ft,!0)),mr=e.add(new we("",te,ie,l)),_o=e.add(new Xe("",e.add(new we("",te+ue,ie,l)))),xc=e.add(new Qe("",mr,V,j)),bx=e.add(new lr("",xc,ue)),kx=e.add(new Nt("",_o,_o,bx,!0)),Sx=e.add(new pt("",[e.add(new Me("",_r,!0)),e.add(new Me("",kx,!1))])),Px=e.add(new Qe("",Le,V,j)),Tx=e.add(new Di("",Px,ue)),Ex=e.add(new Vt("",[e.add(new Ht("",Sx,!0))],Tx,!1));ut.push(Ex)}const St=[ee,Ue,...Je,...ut],st=e.add(new gi("",St)),Ve=[e.add(new mi(c,st))];if(t.includeComponents){const $=await UT({repo:e,circuitJson:n,boardThickness:l,includeExternalMeshes:t.includeExternalMeshes});Ve.push(...$)}const ye=[];for(const $ of Ve){const Q=e.add(new Wi("",.2,.6,.2)),te=e.add(new Vi("",Q)),ie=e.add(new Gi("",[te])),ue=e.add(new Ki(ie)),Le=e.add(new qi("",[ue])),ke=e.add(new Ji(".BOTH.",Le)),Ot=e.add(new Yi([ke])),Ft=e.add(new Xi("",[Ot],$));ye.push(Ft)}e.add(new Hi("",ye,C));const T=e.add(new Zi(c,Ve,C));return e.add(new ao(m,T)),e.toPartFile({name:c})}const BT=async(n,t)=>{const e=await jT(n),s=new Blob([e],{type:"text/plain"});tt.saveAs(s,t+".step")};function sE({className:n,unscopedName:t,author:e,desiredImageType:s="pcb",hasCircuitJson:r,offerMultipleImageFormats:i=!1,circuitJson:a}){const l=ry(),{Dialog:c,openDialog:h}=lk(),d=dg(),{packageId:p}=EP(),[u,g]=at.useState(null),[_,x]=at.useState(!1),v=!!(r||a&&a.length),m=async()=>{var y,w;if(a&&a.length)return a;if(u&&u.length)return u;x(!0);try{const{data:b}=await d.get("/package_files/get",{params:{package_id:p,file_path:"dist/circuit.json"}}),k=(y=b==null?void 0:b.package_file)==null?void 0:y.content_text;if(!k)throw new Error("Circuit JSON not found");const C=JSON.parse(k);return g(C),C}catch(b){throw Ci({title:"Failed to fetch Circuit JSON",description:(b==null?void 0:b.message)||((w=b==null?void 0:b.toString)==null?void 0:w.call(b))||"Unknown error",variant:"destructive"}),b}finally{x(!1)}};return v?P.jsxs("div",{className:n,children:[P.jsxs(iy,{children:[P.jsx(oy,{asChild:!0,children:P.jsxs(Aa,{size:"sm",className:"bg-white shadow-none text-gray-900 hover:bg-gray-100 border border-gray-300 px-1 pl-2 select-none",children:[P.jsx(Ne,{className:"w-4 h-4 mr-2"}),"Download",P.jsx(jp,{className:"w-4 h-4 ml-1"})]})}),P.jsxs(ay,{className:"!z-[101]",children:[P.jsxs(Se,{className:"text-xs",onSelect:async()=>{const y=await m();Pb(y,t||"circuit.json")},children:[P.jsx(Ne,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"Circuit JSON"}),P.jsx("span",{className:"text-[0.6rem] opacity-80 bg-blue-500 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"json"})]}),P.jsxs(Se,{className:"text-xs",onClick:async()=>{try{const y=await m();await Vf(y,t||"circuit",{format:"glb",boardTextureResolution:2048})}catch(y){Ci({title:"Error Downloading 3D Model",description:y.toString(),variant:"destructive"})}},children:[P.jsx(Up,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"3D Model"}),P.jsx("span",{className:"text-[0.6rem] bg-green-500 opacity-80 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"glb"})]}),P.jsxs(Se,{className:"text-xs",onClick:async()=>{try{const y=await m();await Vf(y,t||"circuit",{format:"gltf",boardTextureResolution:2048})}catch(y){Ci({title:"Error Downloading 3D Model (GLTF)",description:y.toString(),variant:"destructive"})}},children:[P.jsx(Up,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"3D Model"}),P.jsx("span",{className:"text-[0.6rem] bg-green-500 opacity-80 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"gltf"})]}),P.jsxs(Se,{className:"text-xs",onClick:async()=>{const y=await m();await Vb({circuitJson:y,snippetUnscopedName:t||"snippet"}).catch(w=>{console.error(w),console.log(w,w.stack),Ci({title:"Error Downloading Fabrication Files",description:w.toString(),variant:"destructive"})})},children:[P.jsx(_y,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"Fabrication Files"}),P.jsx("span",{className:"text-[0.6rem] bg-purple-500 opacity-80 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"gerber/pnp/bom/csv"})]}),P.jsxs(Se,{className:"text-xs",onClick:()=>l("kicad footprint download"),children:[P.jsx(Ne,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"KiCad Footprint"}),P.jsx("span",{className:"text-[0.6rem] bg-orange-500 opacity-80 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"kicad_mod"})]}),P.jsxs(Se,{className:"text-xs",onSelect:async()=>{const y=await m();Q0(y,t||"kicad_project")},children:[P.jsx(Ne,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"KiCad Project"}),P.jsx("span",{className:"text-[0.6rem] bg-orange-500 opacity-80 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"kicad_*.zip"})]}),P.jsxs(Se,{className:"text-xs",onSelect:async()=>{const y=await m();BT(y,t||"step_file")},children:[P.jsx(Ne,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"Step Format"}),P.jsx("span",{className:"text-[0.6rem] bg-emerald-500 opacity-80 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"STEP"})]}),P.jsxs(Se,{className:"text-xs",onSelect:async()=>{const y=await m();Hb(y,t||"circuit")},children:[P.jsx(Ne,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"Schematic SVG"}),P.jsx("span",{className:"text-[0.6rem] opacity-80 bg-blue-500 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"svg"})]}),P.jsxs(Se,{className:"text-xs",onSelect:async()=>{const y=await m();ok(y,t||"circuit")},children:[P.jsx(Ne,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"Assembly SVG"}),P.jsx("span",{className:"text-[0.6rem] opacity-80 bg-blue-500 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"svg"})]}),P.jsxs(Se,{className:"text-xs",onSelect:async()=>{const y=await m();g(y),h()},children:[P.jsx(Ne,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"PCB SVG"}),P.jsx("span",{className:"text-[0.6rem] opacity-80 bg-blue-500 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"svg"})]}),P.jsxs(Se,{className:"text-xs",onSelect:async()=>{const y=await m();Gb(y,t||"circuit")},children:[P.jsx(Ne,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"Specctra DSN"}),P.jsx("span",{className:"text-[0.6rem] opacity-80 bg-blue-500 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"dsn"})]}),P.jsxs(Se,{className:"text-xs",onClick:async()=>{const y=await m();Jb(y,t||"circuit")},children:[P.jsx(Ne,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"Readable Netlist"}),P.jsx("span",{className:"text-[0.6rem] opacity-80 bg-blue-500 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"txt"})]}),P.jsxs(Se,{className:"text-xs",onSelect:async()=>{const y=await m();ik(y,t||"circuit")},children:[P.jsx(Ne,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"SPICE Netlist"}),P.jsx("span",{className:"text-[0.6rem] opacity-80 bg-blue-500 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"spice"})]}),P.jsxs(Se,{className:"text-xs",onSelect:async()=>{const y=await m();Tb(y,t||"circuit")},children:[P.jsx(Ne,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"Simple Route JSON"}),P.jsx("span",{className:"text-[0.6rem] opacity-80 bg-blue-500 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"json"})]}),!i&&P.jsxs(Se,{className:"text-xs",onClick:async()=>{const y=["pcb","schematic","assembly","3d"].includes(s)?s:"pcb",w=await m();Ti({circuitJson:w,unscopedName:t,format:y})},children:[P.jsx(Ne,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"Image PNG"}),P.jsx("span",{className:"text-[0.6rem] opacity-80 bg-teal-600 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"png"})]}),i&&P.jsxs(P.Fragment,{children:[P.jsxs(Se,{className:"text-xs",onClick:async()=>Ti({circuitJson:await m(),unscopedName:t,format:"schematic"}),children:[P.jsx(Ne,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"Schematic PNG"}),P.jsx("span",{className:"text-[0.6rem] opacity-80 bg-teal-600 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"png"})]}),P.jsxs(Se,{className:"text-xs",onClick:async()=>Ti({circuitJson:await m(),unscopedName:t,format:"pcb"}),children:[P.jsx(Ne,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"PCB PNG"}),P.jsx("span",{className:"text-[0.6rem] opacity-80 bg-teal-600 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"png"})]}),P.jsxs(Se,{className:"text-xs",onClick:async()=>Ti({circuitJson:await m(),unscopedName:t,format:"assembly"}),children:[P.jsx(Ne,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"Assembly PNG"}),P.jsx("span",{className:"text-[0.6rem] opacity-80 bg-teal-600 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"png"})]}),P.jsxs(Se,{className:"text-xs",onClick:async()=>Ti({circuitJson:await m(),unscopedName:t,format:"3d"}),children:[P.jsx(Ne,{className:"mr-1 h-3 w-3"}),P.jsx("span",{className:"flex-grow mr-6",children:"3D PNG"}),P.jsx("span",{className:"text-[0.6rem] opacity-80 bg-teal-600 text-white font-mono rounded-md px-1 text-center py-0.5 mr-1",children:"png"})]})]})]})]}),P.jsx(c,{circuitJson:u||a||[],fileName:t||"circuit"})]}):P.jsx("div",{className:n,children:P.jsxs(Aa,{disabled:!0,size:"sm",className:"shadow-none bg-muted text-muted-foreground border border-input cursor-not-allowed",children:[P.jsx(Ne,{className:"h-4 w-4 mr-2"}),"Download",P.jsx(jp,{className:"h-4 w-4 ml-1"})]})})}export{qT as C,sE as D,KT as G,JT as T,EP as a,Sb as b,tE as c,Ov as d,Fv as e,hv as f,Qp as g,pv as h,PP as i,Mg as s,TP as u,op as w};
|