pkgroll
Version:
Zero-config rollup bundler
32 lines • 59.2 kB
JavaScript
var Qe=Object.defineProperty;var c=(n,e)=>Qe(n,"name",{value:e,configurable:!0});import{createRequire as Ye}from"node:module";const Ze=Ye(import.meta.url);import*as T from"node:path";import i from"typescript";import{createRequire as et}from"node:module";import X from"magic-string";import le from"node:fs/promises";import{g as tt}from"./cli-DrYwvddJ.mjs";import"node:fs";import"tty";import"rollup";import"rollup-plugin-import-trace";import"yaml";import"node:path/posix";import"@rollup/plugin-node-resolve";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-alias";import"@rollup/plugin-dynamic-import-vars";import"esbuild";import"fs";import"os";import"path";import"rollup-pluginutils";import"node:url";import"cjs-module-lexer";var ue=44,nt=59,pe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fe=new Uint8Array(64),me=new Uint8Array(128);for(let n=0;n<pe.length;n++){const e=pe.charCodeAt(n);fe[n]=e,me[e]=n}function K(n,e){let t=0,r=0,s=0;do{const a=n.next();s=me[a],t|=(s&31)<<r,r+=5}while(s&32);const o=t&1;return t>>>=1,o&&(t=-2147483648|-t),e+t}c(K,"decodeInteger");function z(n,e,t){let r=e-t;r=r<0?-r<<1|1:r<<1;do{let s=r&31;r>>>=5,r>0&&(s|=32),n.write(fe[s])}while(r>0);return e}c(z,"encodeInteger");function de(n,e){return n.pos>=e?!1:n.peek()!==ue}c(de,"hasMoreVlq");var he=1024*16,ge=typeof TextDecoder<"u"?new TextDecoder:typeof Buffer<"u"?{decode(n){return Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString()}}:{decode(n){let e="";for(let t=0;t<n.length;t++)e+=String.fromCharCode(n[t]);return e}},rt=class{static{c(this,"StringWriter")}constructor(){this.pos=0,this.out="",this.buffer=new Uint8Array(he)}write(n){const{buffer:e}=this;e[this.pos++]=n,this.pos===he&&(this.out+=ge.decode(e),this.pos=0)}flush(){const{buffer:n,out:e,pos:t}=this;return t>0?e+ge.decode(n.subarray(0,t)):e}},st=class{static{c(this,"StringReader")}constructor(n){this.pos=0,this.buffer=n}next(){return this.buffer.charCodeAt(this.pos++)}peek(){return this.buffer.charCodeAt(this.pos)}indexOf(n){const{buffer:e,pos:t}=this,r=e.indexOf(n,t);return r===-1?e.length:r}};function Q(n){const{length:e}=n,t=new st(n),r=[];let s=0,o=0,a=0,u=0,m=0;do{const p=t.indexOf(";"),d=[];let h=!0,l=0;for(s=0;t.pos<p;){let g;s=K(t,s),s<l&&(h=!1),l=s,de(t,p)?(o=K(t,o),a=K(t,a),u=K(t,u),de(t,p)?(m=K(t,m),g=[s,o,a,u,m]):g=[s,o,a,u]):g=[s],d.push(g),t.pos++}h||it(d),r.push(d),t.pos=p+1}while(t.pos<=e);return r}c(Q,"decode");function it(n){n.sort(ot)}c(it,"sort");function ot(n,e){return n[0]-e[0]}c(ot,"sortComparator$1");function ye(n){const e=new rt;let t=0,r=0,s=0,o=0;for(let a=0;a<n.length;a++){const u=n[a];if(a>0&&e.write(nt),u.length===0)continue;let m=0;for(let p=0;p<u.length;p++){const d=u[p];p>0&&e.write(ue),m=z(e,d[0],m),d.length!==1&&(t=z(e,d[1],t),r=z(e,d[2],r),s=z(e,d[3],s),d.length!==4&&(o=z(e,d[4],o)))}}return e.flush()}c(ye,"encode");const at=/^[\w+.-]+:\/\//,ct=/^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/,lt=/^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;function ut(n){return at.test(n)}c(ut,"isAbsoluteUrl");function pt(n){return n.startsWith("//")}c(pt,"isSchemeRelativeUrl");function xe(n){return n.startsWith("/")}c(xe,"isAbsolutePath");function ft(n){return n.startsWith("file:")}c(ft,"isFileUrl");function Se(n){return/^[.?#]/.test(n)}c(Se,"isRelative");function q(n){const e=ct.exec(n);return ve(e[1],e[2]||"",e[3],e[4]||"",e[5]||"/",e[6]||"",e[7]||"")}c(q,"parseAbsoluteUrl");function mt(n){const e=lt.exec(n),t=e[2];return ve("file:","",e[1]||"","",xe(t)?t:"/"+t,e[3]||"",e[4]||"")}c(mt,"parseFileUrl");function ve(n,e,t,r,s,o,a){return{scheme:n,user:e,host:t,port:r,path:s,query:o,hash:a,type:7}}c(ve,"makeUrl");function Ee(n){if(pt(n)){const t=q("http:"+n);return t.scheme="",t.type=6,t}if(xe(n)){const t=q("http://foo.com"+n);return t.scheme="",t.host="",t.type=5,t}if(ft(n))return mt(n);if(ut(n))return q(n);const e=q("http://foo.com/"+n);return e.scheme="",e.host="",e.type=n?n.startsWith("?")?3:n.startsWith("#")?2:4:1,e}c(Ee,"parseUrl");function dt(n){if(n.endsWith("/.."))return n;const e=n.lastIndexOf("/");return n.slice(0,e+1)}c(dt,"stripPathFilename");function ht(n,e){Te(e,e.type),n.path==="/"?n.path=e.path:n.path=dt(e.path)+n.path}c(ht,"mergePaths");function Te(n,e){const t=e<=4,r=n.path.split("/");let s=1,o=0,a=!1;for(let m=1;m<r.length;m++){const p=r[m];if(!p){a=!0;continue}if(a=!1,p!=="."){if(p===".."){o?(a=!0,o--,s--):t&&(r[s++]=p);continue}r[s++]=p,o++}}let u="";for(let m=1;m<s;m++)u+="/"+r[m];(!u||a&&!u.endsWith("/.."))&&(u+="/"),n.path=u}c(Te,"normalizePath");function gt(n,e){if(!n&&!e)return"";const t=Ee(n);let r=t.type;if(e&&r!==7){const o=Ee(e),a=o.type;switch(r){case 1:t.hash=o.hash;case 2:t.query=o.query;case 3:case 4:ht(t,o);case 5:t.user=o.user,t.host=o.host,t.port=o.port;case 6:t.scheme=o.scheme}a>r&&(r=a)}Te(t,r);const s=t.query+t.hash;switch(r){case 2:case 3:return s;case 4:{const o=t.path.slice(1);return o?Se(e||n)&&!Se(o)?"./"+o+s:o+s:s||"."}case 5:return t.path+s;default:return t.scheme+"//"+t.user+t.host+t.port+t.path+s}}c(gt,"resolve");function yt(n){if(!n)return"";const e=n.lastIndexOf("/");return n.slice(0,e+1)}c(yt,"stripFilename");function xt(n,e){const t=yt(n),r=e?e+"/":"";return s=>gt(r+(s||""),t)}c(xt,"resolver");var k=0;function St(n,e){const t=Ne(n,0);if(t===n.length)return n;e||(n=n.slice());for(let r=t;r<n.length;r=Ne(n,r+1))n[r]=Et(n[r],e);return n}c(St,"maybeSort");function Ne(n,e){for(let t=e;t<n.length;t++)if(!vt(n[t]))return t;return n.length}c(Ne,"nextUnsortedSegmentLine");function vt(n){for(let e=1;e<n.length;e++)if(n[e][k]<n[e-1][k])return!1;return!0}c(vt,"isSorted");function Et(n,e){return e||(n=n.slice()),n.sort(Tt)}c(Et,"sortSegments");function Tt(n,e){return n[k]-e[k]}c(Tt,"sortComparator");var H=!1;function Nt(n,e,t,r){for(;t<=r;){const s=t+(r-t>>1),o=n[s][k]-e;if(o===0)return H=!0,s;o<0?t=s+1:r=s-1}return H=!1,t-1}c(Nt,"binarySearch");function Ct(n,e,t){for(let r=t-1;r>=0&&n[r][k]===e;t=r--);return t}c(Ct,"lowerBound");function wt(){return{lastKey:-1,lastNeedle:-1,lastIndex:-1}}c(wt,"memoizedState");function Dt(n,e,t,r){const{lastKey:s,lastNeedle:o,lastIndex:a}=t;let u=0,m=n.length-1;if(r===s){if(e===o)return H=a!==-1&&n[a][k]===e,a;e>=o?u=a===-1?0:a:m=a}return t.lastKey=r,t.lastNeedle=e,t.lastIndex=Nt(n,e,u,m)}c(Dt,"memoizedBinarySearch");function bt(n){return typeof n=="string"?JSON.parse(n):n}c(bt,"parse$1");var Ce=class{static{c(this,"TraceMap")}constructor(n,e){const t=typeof n=="string";if(!t&&n._decodedMemo)return n;const r=bt(n),{version:s,file:o,names:a,sourceRoot:u,sources:m,sourcesContent:p}=r;this.version=s,this.file=o,this.names=a||[],this.sourceRoot=u,this.sources=m,this.sourcesContent=p,this.ignoreList=r.ignoreList||r.x_google_ignoreList||void 0;const d=xt(e,u);this.resolvedSources=m.map(d);const{mappings:h}=r;if(typeof h=="string")this._encoded=h,this._decoded=void 0;else if(Array.isArray(h))this._encoded=void 0,this._decoded=St(h,t);else throw r.sections?new Error("TraceMap passed sectioned source map, please use FlattenMap export instead"):new Error(`invalid source map: ${JSON.stringify(r)}`);this._decodedMemo=wt(),this._bySources=void 0,this._bySourceMemos=void 0}};function er(n){return n}c(er,"cast$1");function we(n){var e;return(e=n)._decoded||(e._decoded=Q(n._encoded))}c(we,"decodedMappings");function It(n,e,t){const r=we(n);if(e>=r.length)return null;const s=r[e],o=Mt(s,n._decodedMemo,e,t);return o===-1?null:s[o]}c(It,"traceSegment");function Mt(n,e,t,r,s){let o=Dt(n,r,e,t);return H&&(o=Ct(n,r,o)),o===-1||o===n.length?-1:o}c(Mt,"traceSegmentInternal");var Y=class{static{c(this,"SetArray")}constructor(){this._indexes={__proto__:null},this.array=[]}};function tr(n){return n}c(tr,"cast");function De(n,e){return n._indexes[e]}c(De,"get");function V(n,e){const t=De(n,e);if(t!==void 0)return t;const{array:r,_indexes:s}=n,o=r.push(e);return s[e]=o-1}c(V,"put");function Ft(n,e){const t=De(n,e);if(t===void 0)return;const{array:r,_indexes:s}=n;for(let o=t+1;o<r.length;o++){const a=r[o];r[o-1]=a,s[a]--}s[e]=void 0,r.pop()}c(Ft,"remove");var Rt=0,Ot=1,At=2,Lt=3,Pt=4,be=-1,_t=class{static{c(this,"GenMapping")}constructor({file:n,sourceRoot:e}={}){this._names=new Y,this._sources=new Y,this._sourcesContent=[],this._mappings=[],this.file=n,this.sourceRoot=e,this._ignoreList=new Y}};function nr(n){return n}c(nr,"cast2");var $t=c((n,e,t,r,s,o,a,u)=>Ut(!0,n,e,t,r,s,o,a),"maybeAddSegment");function Bt(n,e,t){const{_sources:r,_sourcesContent:s}=n,o=V(r,e);s[o]=t}c(Bt,"setSourceContent");function kt(n,e,t=!0){const{_sources:r,_sourcesContent:s,_ignoreList:o}=n,a=V(r,e);a===s.length&&(s[a]=null),t?V(o,a):Ft(o,a)}c(kt,"setIgnore");function Ie(n){const{_mappings:e,_sources:t,_sourcesContent:r,_names:s,_ignoreList:o}=n;return Vt(e),{version:3,file:n.file||void 0,names:s.array,sourceRoot:n.sourceRoot||void 0,sources:t.array,sourcesContent:r,mappings:e,ignoreList:o.array}}c(Ie,"toDecodedMap");function jt(n){const e=Ie(n);return Object.assign({},e,{mappings:ye(e.mappings)})}c(jt,"toEncodedMap");function Ut(n,e,t,r,s,o,a,u,m){const{_mappings:p,_sources:d,_sourcesContent:h,_names:l}=e,g=Kt(p,t),x=zt(g,r);if(!s)return Jt(g,x)?void 0:Me(g,x,[r]);const S=V(d,s),E=u?V(l,u):be;if(S===h.length&&(h[S]=null),!Wt(g,x,S,o,a,E))return Me(g,x,u?[r,S,o,a,E]:[r,S,o,a])}c(Ut,"addSegmentInternal");function Kt(n,e){for(let t=n.length;t<=e;t++)n[t]=[];return n[e]}c(Kt,"getIndex");function zt(n,e){let t=n.length;for(let r=t-1;r>=0;t=r--){const s=n[r];if(e>=s[Rt])break}return t}c(zt,"getColumnIndex");function Me(n,e,t){for(let r=n.length;r>e;r--)n[r]=n[r-1];n[e]=t}c(Me,"insert");function Vt(n){const{length:e}=n;let t=e;for(let r=t-1;r>=0&&!(n[r].length>0);t=r,r--);t<e&&(n.length=t)}c(Vt,"removeEmptyFinalLines");function Jt(n,e){return e===0?!0:n[e-1].length===1}c(Jt,"skipSourceless");function Wt(n,e,t,r,s,o){if(e===0)return!1;const a=n[e-1];return a.length===1?!1:t===a[Ot]&&r===a[At]&&s===a[Lt]&&o===(a.length===5?a[Pt]:be)}c(Wt,"skipSource");var Fe=Re("",-1,-1,"",null,!1),Gt=[];function Re(n,e,t,r,s,o){return{source:n,line:e,column:t,name:r,content:s,ignore:o}}c(Re,"SegmentObject");function Oe(n,e,t,r,s){return{map:n,sources:e,source:t,content:r,ignore:s}}c(Oe,"Source");function Ae(n,e){return Oe(n,e,"",null,!1)}c(Ae,"MapSource");function qt(n,e,t){return Oe(null,Gt,n,e,t)}c(qt,"OriginalSource");function Ht(n){const e=new _t({file:n.map.file}),{sources:t,map:r}=n,s=r.names,o=we(r);for(let a=0;a<o.length;a++){const u=o[a];for(let m=0;m<u.length;m++){const p=u[m],d=p[0];let h=Fe;if(p.length!==1){const D=t[p[1]];if(h=Le(D,p[2],p[3],p.length===5?s[p[4]]:""),h==null)continue}const{column:l,line:g,name:x,content:S,source:E,ignore:N}=h;$t(e,a,d,E,g,l,x),E&&S!=null&&Bt(e,E,S),N&&kt(e,E,!0)}}return e}c(Ht,"traceMappings");function Le(n,e,t,r){if(!n.map)return Re(n.source,e,t,r,n.content,n.ignore);const s=It(n.map,e,t);return s==null?null:s.length===1?Fe:Le(n.sources[s[1]],s[2],s[3],s.length===5?n.map.names[s[4]]:r)}c(Le,"originalPositionFor");function Xt(n){return Array.isArray(n)?n:[n]}c(Xt,"asArray");function Qt(n,e){const t=Xt(n).map(o=>new Ce(o,"")),r=t.pop();for(let o=0;o<t.length;o++)if(t[o].sources.length>1)throw new Error(`Transformation map ${o} must have exactly one source file.
Did you specify these with the most recent transformation maps first?`);let s=Pe(r,e,"",0);for(let o=t.length-1;o>=0;o--)s=Ae(t[o],[s]);return s}c(Qt,"buildSourceMapTree");function Pe(n,e,t,r){const{resolvedSources:s,sourcesContent:o,ignoreList:a}=n,u=r+1,m=s.map((p,d)=>{const h={importer:t,depth:u,source:p||"",content:void 0,ignore:void 0},l=e(h.source,h),{source:g}=h;if(l)return Pe(new Ce(l,g),e,g,u);const x=o?o[d]:null,S=a?a.includes(d):!1;return qt(g,x,S)});return Ae(n,m)}c(Pe,"build");var Yt=class{static{c(this,"SourceMap")}constructor(n,e){const t=e.decodedMappings?Ie(n):jt(n);this.version=t.version,this.file=t.file,this.mappings=t.mappings,this.names=t.names,this.ignoreList=t.ignoreList,this.sourceRoot=t.sourceRoot,this.sources=t.sources,e.excludeContent||(this.sourcesContent=t.sourcesContent)}toString(){return JSON.stringify(this)}};function Zt(n,e,t){const r={excludeContent:!1,decodedMappings:!1},s=Qt(n,e);return new Yt(Ht(s),r)}c(Zt,"remapping");var Z={},_e;function en(){return _e||(_e=1,(function(n){Object.defineProperty(n,"commentRegex",{get:c(function(){return/^\s*?\/[\/\*][@#]\s+?sourceMappingURL=data:(((?:application|text)\/json)(?:;charset=([^;,]+?)?)?)?(?:;(base64))?,(.*?)$/mg},"getCommentRegex")}),Object.defineProperty(n,"mapFileCommentRegex",{get:c(function(){return/(?:\/\/[@#][ \t]+?sourceMappingURL=([^\s'"`]+?)[ \t]*?$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^*]+?)[ \t]*?(?:\*\/){1}[ \t]*?$)/mg},"getMapFileCommentRegex")});var e;typeof Buffer<"u"?typeof Buffer.from=="function"?e=t:e=r:e=s;function t(l){return Buffer.from(l,"base64").toString()}c(t,"decodeBase64WithBufferFrom");function r(l){if(typeof value=="number")throw new TypeError("The value to decode must not be of type number.");return new Buffer(l,"base64").toString()}c(r,"decodeBase64WithNewBuffer");function s(l){return decodeURIComponent(escape(atob(l)))}c(s,"decodeBase64WithAtob");function o(l){return l.split(",").pop()}c(o,"stripComment");function a(l,g){var x=n.mapFileCommentRegex.exec(l),S=x[1]||x[2];try{var l=g(S);return l!=null&&typeof l.catch=="function"?l.catch(E):l}catch(N){E(N)}function E(N){throw new Error("An error occurred while trying to read the map file at "+S+`
`+N.stack)}c(E,"throwError")}c(a,"readFromFileMap");function u(l,g){g=g||{},g.hasComment&&(l=o(l)),g.encoding==="base64"?l=e(l):g.encoding==="uri"&&(l=decodeURIComponent(l)),(g.isJSON||g.encoding)&&(l=JSON.parse(l)),this.sourcemap=l}c(u,"Converter"),u.prototype.toJSON=function(l){return JSON.stringify(this.sourcemap,null,l)},typeof Buffer<"u"?typeof Buffer.from=="function"?u.prototype.toBase64=m:u.prototype.toBase64=p:u.prototype.toBase64=d;function m(){var l=this.toJSON();return Buffer.from(l,"utf8").toString("base64")}c(m,"encodeBase64WithBufferFrom");function p(){var l=this.toJSON();if(typeof l=="number")throw new TypeError("The json to encode must not be of type number.");return new Buffer(l,"utf8").toString("base64")}c(p,"encodeBase64WithNewBuffer");function d(){var l=this.toJSON();return btoa(unescape(encodeURIComponent(l)))}c(d,"encodeBase64WithBtoa"),u.prototype.toURI=function(){var l=this.toJSON();return encodeURIComponent(l)},u.prototype.toComment=function(l){var g,x,S;return l!=null&&l.encoding==="uri"?(g="",x=this.toURI()):(g=";base64",x=this.toBase64()),S="sourceMappingURL=data:application/json;charset=utf-8"+g+","+x,l!=null&&l.multiline?"/*# "+S+" */":"//# "+S},u.prototype.toObject=function(){return JSON.parse(this.toJSON())},u.prototype.addProperty=function(l,g){if(this.sourcemap.hasOwnProperty(l))throw new Error('property "'+l+'" already exists on the sourcemap, use set property instead');return this.setProperty(l,g)},u.prototype.setProperty=function(l,g){return this.sourcemap[l]=g,this},u.prototype.getProperty=function(l){return this.sourcemap[l]},n.fromObject=function(l){return new u(l)},n.fromJSON=function(l){return new u(l,{isJSON:!0})},n.fromURI=function(l){return new u(l,{encoding:"uri"})},n.fromBase64=function(l){return new u(l,{encoding:"base64"})},n.fromComment=function(l){var g,x;return l=l.replace(/^\/\*/g,"//").replace(/\*\/$/g,""),g=n.commentRegex.exec(l),x=g&&g[4]||"uri",new u(l,{encoding:x,hasComment:!0})};function h(l){return new u(l,{isJSON:!0})}c(h,"makeConverter"),n.fromMapFileComment=function(l,g){if(typeof g=="string")throw new Error("String directory paths are no longer supported with `fromMapFileComment`\nPlease review the Upgrading documentation at https://github.com/thlorenz/convert-source-map#upgrading");var x=a(l,g);return x!=null&&typeof x.then=="function"?x.then(h):h(x)},n.fromSource=function(l){var g=l.match(n.commentRegex);return g?n.fromComment(g.pop()):null},n.fromMapFileSource=function(l,g){if(typeof g=="string")throw new Error("String directory paths are no longer supported with `fromMapFileSource`\nPlease review the Upgrading documentation at https://github.com/thlorenz/convert-source-map#upgrading");var x=l.match(n.mapFileCommentRegex);return x?n.fromMapFileComment(x.pop(),g):null},n.removeComments=function(l){return l.replace(n.commentRegex,"")},n.removeMapFileComments=function(l){return l.replace(n.mapFileCommentRegex,"")},n.generateMapFileComment=function(l,g){var x="sourceMappingURL="+l;return g&&g.multiline?"/*# "+x+" */":"//# "+x}})(Z)),Z}c(en,"requireConvertSourceMap");var tn=en(),$e=tt(tn);function nn(n){return{...n,compilerOptions:n.compilerOptions??{},respectExternal:n.respectExternal??!1,includeExternal:n.includeExternal??[],sourcemap:n.sourcemap??!1}}c(nn,"resolveDefaultOptions");const j=/\.d\.(c|m)?tsx?$/,ee=/\.json$/,Be=/((\.d)?\.(c|m)?(t|j)sx?|\.json)$/;function te(n){return n.replace(Be,"")}c(te,"trimExtension");function ke(n){return n.replace(Be,".d.ts")}c(ke,"getDeclarationId");function J(n,e){return i.createSourceFile(n,e,i.ScriptTarget.Latest,!0)}c(J,"parse");const ne={getCurrentDirectory:c(()=>i.sys.getCurrentDirectory(),"getCurrentDirectory"),getNewLine:c(()=>i.sys.newLine,"getNewLine"),getCanonicalFileName:i.sys.useCaseSensitiveFileNames?n=>n:n=>n.toLowerCase()},rn={declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!0,target:i.ScriptTarget.ESNext,resolveJsonModule:!0},W=new Map,U=c((...n)=>process.env.DTS_LOG_CACHE?console.log("[cache]",...n):null,"logCache");function je([n,e],t){for(U(n),W.set(n,t);n!==e&&n!==T.dirname(n);){if(n=T.dirname(n),U("up",n),W.has(n))return U("has",n);W.set(n,t)}}c(je,"cacheConfig");function re(n,e,t,r){const s={...rn,...e,...r===!0&&{declarationMap:!0}};let o=T.dirname(n),a=[];const u=t||o;if(W.has(u))U("HIT",u);else{U("miss",u);const h=t?T.resolve(process.cwd(),t):i.findConfigFile(o,i.sys.fileExists);if(!h)return{dtsFiles:a,dirName:o,compilerOptions:s};const l=o;o=T.dirname(h);const{config:g,error:x}=i.readConfigFile(h,i.sys.readFile);if(x)return console.error(i.formatDiagnostic(x,ne)),{dtsFiles:a,dirName:o,compilerOptions:s};U("tsconfig",g);const S=i.parseJsonConfigFileContent(g,i.sys,o);je(t?[t,t]:[l,o],S)}const{fileNames:m,options:p,errors:d}=W.get(u);return a=m.filter(h=>j.test(h)),d.length?(console.error(i.formatDiagnostics(d,ne)),{dtsFiles:a,dirName:o,compilerOptions:s}):{dtsFiles:a,dirName:o,compilerOptions:{...p,...s}}}c(re,"getCompilerOptions");function sn(n,e,t,r){const{dtsFiles:s,compilerOptions:o}=re(n,e,t,r);return i.createProgram([n].concat(Array.from(s)),o,i.createCompilerHost(o,!0))}c(sn,"createProgram$1");function on(n,e,t,r){const s=[],o=new Set;let a=[],u="",m={};for(let p of n){if(j.test(p))continue;p=T.resolve(p);const d=re(p,e,t,r);if(d.dtsFiles.forEach(o.add,o),!a.length){a.push(p),{dirName:u,compilerOptions:m}=d;continue}if(d.dirName===u)a.push(p);else{const h=i.createCompilerHost(m,!0),l=i.createProgram(a.concat(Array.from(o)),m,h);s.push(l),a=[p],{dirName:u,compilerOptions:m}=d}}if(a.length){const p=i.createCompilerHost(m,!0),d=i.createProgram(a.concat(Array.from(o)),m,p);s.push(d)}return s}c(on,"createPrograms");function an(){let n;try{return{codeFrameColumns:n}=Ze("@babel/code-frame"),n}catch{try{return{codeFrameColumns:n}=et(import.meta.url)("@babel/code-frame"),n}catch{}}}c(an,"getCodeFrame");function cn(n){const e=n.getSourceFile(),t=e.getLineAndCharacterOfPosition(n.getStart()),r=e.getLineAndCharacterOfPosition(n.getEnd());return{start:{line:t.line+1,column:t.character+1},end:{line:r.line+1,column:r.character+1}}}c(cn,"getLocation");function ln(n){const e=an(),r=n.getSourceFile().getFullText(),s=cn(n);return e?`
`+e(r,s,{highlightCode:!0}):`
${s.start.line}:${s.start.column}: \`${n.getFullText().trim()}\``}c(ln,"frameNode");class w extends Error{static{c(this,"UnsupportedSyntaxError")}constructor(e,t="Syntax not yet supported"){super(`${t}
${ln(e)}`)}}class un{static{c(this,"NamespaceFixer")}constructor(e){this.sourceFile=e}findNamespaces(){const e=[],t={};for(const r of this.sourceFile.statements){const s={start:r.getStart(),end:r.getEnd()};if(i.isEmptyStatement(r)){e.unshift({name:"",exports:[],location:s});continue}if((i.isImportDeclaration(r)||i.isExportDeclaration(r))&&r.moduleSpecifier&&i.isStringLiteral(r.moduleSpecifier)){const{text:d}=r.moduleSpecifier;if(d.startsWith(".")&&(d.endsWith(".d.ts")||d.endsWith(".d.cts")||d.endsWith(".d.mts"))){const h=r.moduleSpecifier.getStart()+1,l=r.moduleSpecifier.getEnd()-1;e.unshift({name:"",exports:[],location:{start:h,end:l},textBeforeCodeAfter:d.replace(/\.d\.ts$/,".js").replace(/\.d\.cts$/,".cjs").replace(/\.d\.mts$/,".mjs")})}}if(i.isModuleDeclaration(r)&&r.body){let d=r.body;for(;i.isModuleDeclaration(d)&&d.body;)d=d.body;if(!i.isModuleBlock(d))continue;for(const h of d.statements)if(i.isExportDeclaration(h)&&h.exportClause){if(i.isNamespaceExport(h.exportClause))continue;for(const l of h.exportClause.elements)l.propertyName&&l.propertyName.getText()==l.name.getText()&&e.unshift({name:"",exports:[],location:{start:l.propertyName.getEnd(),end:l.name.getEnd()}})}}if(i.isClassDeclaration(r)?t[r.name.getText()]={type:"class",generics:r.typeParameters}:i.isFunctionDeclaration(r)?t[r.name.getText()]={type:"function"}:i.isInterfaceDeclaration(r)?t[r.name.getText()]={type:"interface",generics:r.typeParameters}:i.isTypeAliasDeclaration(r)?t[r.name.getText()]={type:"type",generics:r.typeParameters}:i.isModuleDeclaration(r)&&i.isIdentifier(r.name)?t[r.name.getText()]={type:"namespace"}:i.isEnumDeclaration(r)&&(t[r.name.getText()]={type:"enum"}),!i.isVariableStatement(r))continue;const{declarations:o}=r.declarationList;if(o.length!==1)continue;const a=o[0],u=a.name.getText();if(!a.initializer||!i.isCallExpression(a.initializer)){t[u]={type:"var"};continue}const m=a.initializer.arguments[0];if(!a.initializer.expression.getFullText().includes("/*#__PURE__*/Object.freeze")||!i.isObjectLiteralExpression(m))continue;const p=[];for(const d of m.properties){if(!i.isPropertyAssignment(d)||!(i.isIdentifier(d.name)||i.isStringLiteral(d.name))||d.name.text!=="__proto__"&&!i.isIdentifier(d.initializer))throw new w(d,"Expected a property assignment");d.name.text!=="__proto__"&&p.push({exportedName:d.name.text,localName:d.initializer.getText()})}e.unshift({name:u,exports:p,location:s})}return{namespaces:e,itemTypes:t}}fix(){let e=this.sourceFile.getFullText();const{namespaces:t,itemTypes:r}=this.findNamespaces();for(const s of t){const o=e.slice(s.location.end);e=e.slice(0,s.location.start);for(const{exportedName:a,localName:u}of s.exports)if(a===u){const{type:m,generics:p}=r[u]||{};if(m==="interface"||m==="type"){const d=Ue(p);e+=`type ${s.name}_${a}${d.in} = ${u}${d.out};
`}else if(m==="enum"||m==="class"){const d=Ue(p);e+=`type ${s.name}_${a}${d.in} = ${u}${d.out};
`,e+=`declare const ${s.name}_${a}: typeof ${u};
`}else m==="namespace"?e+=`import ${s.name}_${a} = ${u};
`:e+=`declare const ${s.name}_${a}: typeof ${u};
`}if(s.name){e+=`declare namespace ${s.name} {
`,e+=` export {
`;for(const{exportedName:a,localName:u}of s.exports)a===u?e+=` ${s.name}_${a} as ${a},
`:e+=` ${u} as ${a},
`;e+=` };
`,e+="}"}e+=s.textBeforeCodeAfter??"",e+=o}return e}}function Ue(n){return!n||!n.length?{in:"",out:""}:{in:`<${n.map(e=>e.getText()).join(", ")}>`,out:`<${n.map(e=>e.name.getText()).join(", ")}>`}}c(Ue,"renderTypeParams");let Ke=1;function pn(n){return I({type:"Program",sourceType:"module",body:[]},{start:n.getFullStart(),end:n.getEnd()})}c(pn,"createProgram");function fn(n){const e={type:"Identifier",name:String(Ke++)};return{ident:e,expr:{type:"AssignmentPattern",left:e,right:n}}}c(fn,"createReference");function M(n){return I({type:"Identifier",name:n.getText()},n)}c(M,"createIdentifier");function mn(n){const e=I({type:"FunctionExpression",id:null,params:[],body:{type:"BlockStatement",body:[]}},n),t=I({type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:String(Ke++)},arguments:[e],optional:!1}},n);return{fn:e,iife:t}}c(mn,"createIIFE");function dn(){const n={type:"ArrayExpression",elements:[]};return{expr:n,stmt:{type:"ReturnStatement",argument:n}}}c(dn,"createReturn");function hn(n,e){return I({type:"FunctionDeclaration",id:I({type:"Identifier",name:i.idText(n)},n),params:[],body:{type:"BlockStatement",body:[]}},e)}c(hn,"createDeclaration");function A(n){if(i.isLiteralExpression(n))return{type:"Literal",value:n.text};if(i.isPropertyAccessExpression(n)){if(i.isPrivateIdentifier(n.name))throw new w(n.name);return I({type:"MemberExpression",computed:!1,optional:!1,object:A(n.expression),property:A(n.name)},{start:n.expression.getStart(),end:n.name.getEnd()})}if(i.isObjectLiteralExpression(n))return I({type:"ObjectExpression",properties:n.properties.map(e=>{if(i.isPropertyAssignment(e))return I({type:"Property",key:i.isIdentifier(e.name)?M(e.name):A(e.name),value:A(e.initializer),kind:"init",method:!1,shorthand:!1,computed:i.isComputedPropertyName(e.name)},e);if(i.isShorthandPropertyAssignment(e))return I({type:"Property",key:M(e.name),value:M(e.name),kind:"init",method:!1,shorthand:!0,computed:!1},e);throw new w(e,"Unsupported property type in object literal")})},n);if(i.isArrayLiteralExpression(n))return I({type:"ArrayExpression",elements:n.elements.map(e=>{if(i.isExpression(e))return A(e);throw new w(e,"Unsupported element type in array literal")})},n);if(i.isIdentifier(n))return M(n);if(n.kind==i.SyntaxKind.NullKeyword)return{type:"Literal",value:null};throw new w(n)}c(A,"convertExpression");function I(n,e){const t="start"in e?e:{start:e.getStart(),end:e.getEnd()};return Object.assign(n,t)}c(I,"withStartEnd");function G(n,e){return(i.getCombinedModifierFlags(n)&e)===e}c(G,"matchesModifier");class gn{static{c(this,"LanguageService")}constructor(e){this.fileName="index.d.ts";const t={getCompilationSettings:c(()=>({noEmit:!0,noResolve:!0,skipLibCheck:!0,declaration:!1,checkJs:!1,declarationMap:!1,target:i.ScriptTarget.ESNext}),"getCompilationSettings"),getScriptFileNames:c(()=>[this.fileName],"getScriptFileNames"),getScriptVersion:c(()=>"1","getScriptVersion"),getScriptSnapshot:c(r=>r===this.fileName?i.ScriptSnapshot.fromString(e):void 0,"getScriptSnapshot"),getCurrentDirectory:c(()=>"","getCurrentDirectory"),getDefaultLibFileName:c(()=>"","getDefaultLibFileName"),fileExists:c(r=>r===this.fileName,"fileExists"),readFile:c(r=>r===this.fileName?e:void 0,"readFile")};this.service=i.createLanguageService(t,i.createDocumentRegistry(void 0,""),i.LanguageServiceMode.PartialSemantic)}findReferenceCount(e){const t=this.service.findReferences(this.fileName,e.getStart());return t?.length?t.reduce((r,s)=>r+s.references.length,0):0}}class yn{static{c(this,"TypeOnlyFixer")}constructor(e,t){this.DEBUG=!!process.env.DTS_EXPORTS_FIXER_DEBUG,this.types=new Set,this.values=new Set,this.typeHints=new Map,this.reExportTypeHints=new Map,this.importNodes=[],this.exportNodes=[],this.rawCode=t,this.source=J(e,t),this.code=new X(t)}fix(){return this.analyze(this.source.statements),(this.typeHints.size||this.reExportTypeHints.size)&&(this.service=new gn(this.rawCode),this.importNodes.forEach(e=>this.fixTypeOnlyImport(e))),this.types.size&&this.exportNodes.forEach(e=>this.fixTypeOnlyExport(e)),this.types.size?{magicCode:this.code}:{code:this.rawCode,map:null}}fixTypeOnlyImport(e){let t=!1;const r=[],s=[],o=e.moduleSpecifier.getText(),a=e.importClause.name,u=e.importClause.namedBindings;if(a){const m=a.text;this.isTypeOnly(m)?this.isUselessImport(a)?t=!0:r.push(`import type ${m} from ${o};`):s.push(`import ${m} from ${o};`)}if(u&&i.isNamespaceImport(u)){const m=u.name.text;this.isTypeOnly(m)?this.isUselessImport(u.name)?t=!0:r.push(`import type * as ${m} from ${o};`):s.push(`import * as ${m} from ${o};`)}if(u&&i.isNamedImports(u)){const m=[],p=[];for(const d of u.elements)this.isTypeOnly(d.name.text)?this.isUselessImport(d.name)?t=!0:m.push(d.getText()):p.push(d.getText());m.length&&r.push(`import type { ${m.join(", ")} } from ${o};`),p.length&&s.push(`import { ${p.join(", ")} } from ${o};`)}(r.length||t)&&this.code.overwrite(e.getStart(),e.getEnd(),[...s,...r].join(`
${ze(e)}`))}fixTypeOnlyExport(e){const t=[],r=[],s=e.moduleSpecifier?.getText();if(i.isNamespaceExport(e.exportClause)){const o=e.exportClause.name.text;this.isReExportTypeOnly(o)?t.push(`export type * as ${o} from ${s};`):r.push(`export * as ${o} from ${s};`)}if(i.isNamedExports(e.exportClause)){const o=[],a=[];for(const u of e.exportClause.elements){const m=u.propertyName?.text||u.name.text;(e.moduleSpecifier?this.isReExportTypeOnly(u.name.text):this.isTypeOnly(m))?o.push(u.getText()):a.push(u.getText())}o.length&&t.push(`export type { ${o.join(", ")} }${s?` from ${s}`:""};`),a.length&&r.push(`export { ${a.join(", ")} }${s?` from ${s}`:""};`)}t.length&&this.code.overwrite(e.getStart(),e.getEnd(),[...r,...t].join(`
${ze(e)}`))}analyze(e){for(const t of e){if(this.DEBUG&&console.log(t.getText(),t.kind),i.isImportDeclaration(t)&&t.importClause){this.importNodes.push(t);continue}if(i.isExportDeclaration(t)&&t.exportClause){this.exportNodes.push(t);continue}if(i.isInterfaceDeclaration(t)){this.DEBUG&&console.log(`${t.name.getFullText()} is a type`),this.types.add(t.name.text);continue}if(i.isTypeAliasDeclaration(t)){const r=t.name.text;this.DEBUG&&console.log(`${t.name.getFullText()} is a type`),this.types.add(r);continue}if(i.isEnumDeclaration(t)||i.isFunctionDeclaration(t)||i.isClassDeclaration(t)||i.isVariableStatement(t)){if(i.isVariableStatement(t))for(const r of t.declarationList.declarations)i.isIdentifier(r.name)&&(this.DEBUG&&console.log(`${r.name.getFullText()} is a value (from var statement)`),this.values.add(r.name.text));else t.name&&(this.DEBUG&&console.log(`${t.name.getFullText()} is a value (from declaration)`),this.values.add(t.name.text));continue}if(i.isModuleBlock(t)){this.analyze(t.statements);continue}if(i.isModuleDeclaration(t)){t.name&&i.isIdentifier(t.name)&&(this.DEBUG&&console.log(`${t.name.getFullText()} is a value (from module declaration)`),this.values.add(t.name.text)),this.analyze(t.getChildren());continue}this.DEBUG&&console.log("unhandled statement",t.getFullText(),t.kind)}}isUselessImport(e){const t=this.service.findReferenceCount(e),r=this.typeHints.get(e.text);return r&&r+1>=t}isTypeOnly(e){return this.typeHints.has(e)||this.types.has(e)&&!this.values.has(e)}isReExportTypeOnly(e){return this.reExportTypeHints.has(e)}}function ze(n){const e=n.getFullText().match(/^(?:\n*)([ ]*)/);return" ".repeat(e?.[1]?.length||0)}c(ze,"getNodeIndent");function se(n,e,t){if(i.isModuleDeclaration(n)){n.body&&(i.isModuleBlock(n.body)||i.isModuleDeclaration(n.body))&&se(n.body,e);return}for(const r of n.statements)ie(e,r),i.isModuleDeclaration(r)&&r.body&&(i.isModuleBlock(r.body)||i.isModuleDeclaration(r.body))&&se(r.body,e)}c(se,"preProcessNamespaceBody");function xn({sourceFile:n,isEntry:e,isJSON:t}){const r=new X(n.getFullText()),s=!e&&Sn(n),o=new Set,a=new Set;let u="";const m=new Map,p=new Map;for(const f of n.statements){if(i.isEmptyStatement(f)){r.remove(f.getStart(),f.getEnd());continue}if(i.isImportDeclaration(f)){if(!f.importClause)continue;f.importClause.name&&o.add(f.importClause.name.text),f.importClause.namedBindings&&(i.isNamespaceImport(f.importClause.namedBindings)?o.add(f.importClause.namedBindings.name.text):f.importClause.namedBindings.elements.forEach(y=>o.add(y.name.text)))}else if(i.isEnumDeclaration(f)||i.isFunctionDeclaration(f)||i.isInterfaceDeclaration(f)||i.isClassDeclaration(f)||i.isTypeAliasDeclaration(f)||i.isModuleDeclaration(f)){if(f.name){const y=f.name.getText();o.add(y),f.flags&i.NodeFlags.GlobalAugmentation||(G(f,i.ModifierFlags.ExportDefault)?u=y:(s&&i.isIdentifier(f.name)||G(f,i.ModifierFlags.Export))&&a.add(y)),f.flags&i.NodeFlags.GlobalAugmentation||L(y,[oe(f),Je(f)])}i.isModuleDeclaration(f)&&(f.body&&(i.isModuleBlock(f.body)||i.isModuleDeclaration(f.body))&&se(f.body,r),Ve(r,f)),ie(r,f)}else if(i.isVariableStatement(f)){const{declarations:y}=f.declarationList,v=G(f,i.ModifierFlags.Export);for(const F of f.declarationList.declarations)if(i.isIdentifier(F.name)){const O=F.name.getText();o.add(O),(s||v)&&a.add(O)}if(ie(r,f),y.length===1){const F=y[0];i.isIdentifier(F.name)&&L(F.name.getText(),[oe(f),Je(f)])}else{const F=y.slice(),O=F.shift();L(O.name.getText(),[oe(f),O.getEnd()]);for(const B of F)i.isIdentifier(B.name)&&L(B.name.getText(),[B.getFullStart(),B.getEnd()])}const{flags:C}=f.declarationList,P=`declare ${C&i.NodeFlags.Let?"let":C&i.NodeFlags.Const?"const":"var"} `,$=f.declarationList.getChildren().find(F=>F.kind===i.SyntaxKind.SyntaxList).getChildren();let _=0;for(const F of $)if(F.kind===i.SyntaxKind.CommaToken)_=F.getStart(),r.remove(_,F.getEnd());else if(_){r.appendLeft(_,`;
`);const O=F.getFullStart(),B=r.slice(O,F.getStart()),ce=B.length-B.trimStart().length;ce?r.overwrite(O,O+ce,P):r.appendLeft(O,P)}}}for(const f of n.statements){if(N(f),i.isExportAssignment(f)&&!f.isExportEquals&&(i.isObjectLiteralExpression(f.expression)||i.isArrayLiteralExpression(f.expression))){u||(u=b("export_default")),r.overwrite(f.getStart(),f.expression.getStart(),`declare var ${u} = `);continue}if(G(f,i.ModifierFlags.ExportDefault)&&(i.isFunctionDeclaration(f)||i.isClassDeclaration(f))){if(f.name)continue;u||(u=b("export_default"));const y=f.getChildren(),v=y.findIndex($=>$.kind===i.SyntaxKind.ClassKeyword||$.kind===i.SyntaxKind.FunctionKeyword),C=y[v],R=y[v+1];if(R.kind>=i.SyntaxKind.FirstPunctuation&&R.kind<=i.SyntaxKind.LastPunctuation){const $=r.slice(C.getEnd(),R.getStart())!=" ";r.appendLeft(R.getStart(),`${$?" ":""}${u}`)}else r.appendRight(C.getEnd(),` ${u}`)}}for(const f of p.values()){const v=f.pop()[0];for(const C of f)r.move(C[0],C[1],v)}u&&r.append(`
export default ${u};
`),a.size&&r.append(`
export { ${[...a].join(", ")} };
`),t&&a.size&&(u=b("export_default"),r.append([`
declare const ${u}: {`,[...a].map(f=>` ${f}: typeof ${f};`).join(`
`),"};",`export default ${u};
`].join(`
`)));for(const[f,y]of m.entries())r.prepend(`import * as ${y} from "${f}";
`);const d=n.getLineStarts(),h=new Set;for(const f of n.typeReferenceDirectives){h.add(f.fileName);const{line:y}=n.getLineAndCharacterOfPosition(f.pos),v=d[y];let C=n.getLineEndOfPosition(f.pos);r.slice(C,C+1)===`
`&&(C+=1),r.remove(v,C)}const l=new Set;for(const f of n.referencedFiles){l.add(f.fileName);const{line:y}=n.getLineAndCharacterOfPosition(f.pos),v=d[y];let C=n.getLineEndOfPosition(f.pos);r.slice(C,C+1)===`
`&&(C+=1),r.remove(v,C)}const g=n.getFullText(),x=i.getLeadingCommentRanges(g,n.endOfFileToken.getFullStart()),S=n.statements[n.statements.length-1],E=S?i.getTrailingCommentRanges(g,S.getEnd()):void 0;for(const f of[...x??[],...E??[]]){if(f.kind!==i.SyntaxKind.SingleLineCommentTrivia)continue;const y=g.slice(f.pos,f.end);if(!/\/\/[#@]\s*sourceMappingURL=/.test(y))continue;let v=f.pos;v>0&&g[v-1]===`
`&&(v-=1),r.remove(v,f.end);break}return{code:r,typeReferences:h,fileReferences:l};function N(f){if(i.forEachChild(f,N),i.isImportTypeNode(f)){if(!i.isLiteralTypeNode(f.argument)||!i.isStringLiteral(f.argument.literal))throw new w(f,"inline imports should have a literal argument");const y=f.argument.literal.text,v=f.getChildren(),C=v.find(_=>_.kind===i.SyntaxKind.ImportKeyword).getStart();let R=f.getEnd();const P=v.find(_=>_.kind===i.SyntaxKind.DotToken||_.kind===i.SyntaxKind.LessThanToken);P&&(R=P.getStart());const $=D(y);r.overwrite(C,R,$)}}function D(f){let y=m.get(f);return y||(y=b(vn(f)),m.set(f,y)),y}function b(f){let y=f;for(;o.has(y);)y=`_${y}`;return o.add(y),y}function L(f,y){let v=p.get(f);if(!v)v=[y],p.set(f,v);else{const C=v[v.length-1];C[1]===y[0]?C[1]=y[1]:v.push(y)}}}c(xn,"preProcess");function Sn(n){let e=!1;for(const t of n.statements){if(i.isExportDeclaration(t)||i.isExportAssignment(t))return!1;(e||i.isImportDeclaration(t)||G(t,i.ModifierFlags.Export))&&(e=!0)}return e}c(Sn,"isGlobalModule");function ie(n,e){if(!i.canHaveModifiers(e))return;if(e.parent.kind===i.SyntaxKind.SourceFile){let r=!1;const s=i.isEnumDeclaration(e)||i.isClassDeclaration(e)||i.isFunctionDeclaration(e)||i.isModuleDeclaration(e)||i.isVariableStatement(e);for(const o of e.modifiers??[])switch(o.kind){case i.SyntaxKind.ExportKeyword:case i.SyntaxKind.DefaultKeyword:n.remove(o.getStart(),o.getEnd()+1);break;case i.SyntaxKind.DeclareKeyword:r=!0}s&&!r&&n.appendRight(e.getStart(),"declare ")}}c(ie,"fixModifiers");function Ve(n,e){if(e.body){if(i.isModuleDeclaration(e.body)){Ve(n,e.body);return}if(i.isModuleBlock(e.body)){for(const t of e.body.statements)if(i.isExportDeclaration(t)&&t.exportClause){if(i.isNamespaceExport(t.exportClause))continue;for(const r of t.exportClause.elements)r.propertyName||n.appendLeft(r.name.getEnd(),` as ${r.name.getText()}`)}}}}c(Ve,"duplicateExports");function vn(n){return n.replace(/[^a-zA-Z0-9_$]/g,()=>"_")}c(vn,"getSafeName");function oe(n){const e=n.getFullStart();return e+(We(n,e)?1:0)}c(oe,"getStart");function Je(n){const e=n.getEnd();return e+(We(n,e)?1:0)}c(Je,"getEnd");function We(n,e){return n.getSourceFile().getFullText()[e]===`
`}c(We,"newlineAt");const En=new Set([i.SyntaxKind.LiteralType,i.SyntaxKind.VoidKeyword,i.SyntaxKind.UnknownKeyword,i.SyntaxKind.AnyKeyword,i.SyntaxKind.BooleanKeyword,i.SyntaxKind.NumberKeyword,i.SyntaxKind.StringKeyword,i.SyntaxKind.ObjectKeyword,i.SyntaxKind.NullKeyword,i.SyntaxKind.UndefinedKeyword,i.SyntaxKind.SymbolKeyword,i.SyntaxKind.NeverKeyword,i.SyntaxKind.ThisKeyword,i.SyntaxKind.ThisType,i.SyntaxKind.BigIntKeyword]);class Ge{static{c(this,"DeclarationScope")}constructor({id:e,range:t}){if(this.scopes=[],e)this.declaration=hn(e,t);else{const{iife:s,fn:o}=mn(t);this.iife=s,this.declaration=o}const r=dn();this.declaration.body.body.push(r.stmt),this.returnExpr=r.expr}pushScope(){this.scopes.push(new Set)}popScope(e=1){for(let t=0;t<e;t++)this.scopes.pop()}pushTypeVariable(e){const t=e.getText();this.scopes[this.scopes.length-1]?.add(t)}pushReference(e){let t;if(e.type==="Identifier"?t=e.name:e.type==="MemberExpression"&&e.object.type==="Identifier"&&(t=e.object.name),t){for(const o of this.scopes)if(o.has(t))return}if(t==="this")return;const{ident:r,expr:s}=fn(e);this.declaration.params.push(s),this.returnExpr.elements.push(r)}pushIdentifierReference(e){this.pushReference(M(e))}convertEntityName(e){return i.isIdentifier(e)?M(e):I({type:"MemberExpression",computed:!1,optional:!1,object:this.convertEntityName(e.left),property:M(e.right)},e)}convertPropertyAccess(e){if(!i.isIdentifier(e.expression)&&!i.isPropertyAccessExpression(e.expression))throw new w(e.expression);if(i.isPrivateIdentifier(e.name))throw new w(e.name);const t=i.isIdentifier(e.expression)?M(e.expression):this.convertPropertyAccess(e.expression);return I({type:"MemberExpression",computed:!1,optional:!1,object:t,property:M(e.name)},e)}convertComputedPropertyName(e){if(!e.name||!i.isComputedPropertyName(e.name))return;const{expression:t}=e.name;if(!(i.isLiteralExpression(t)||i.isPrefixUnaryExpression(t))){if(i.isIdentifier(t))return this.pushReference(M(t));if(i.isPropertyAccessExpression(t))return this.pushReference(this.convertPropertyAccess(t));throw new w(t)}}convertParametersAndType(e){this.convertComputedPropertyName(e);const t=this.convertTypeParameters(e.typeParameters);for(const r of e.parameters)this.convertTypeNode(r.type);this.convertTypeNode(e.type),this.popScope(t)}convertHeritageClauses(e){for(const t of e.heritageClauses||[])for(const r of t.types)this.pushReference(A(r.expression)),this.convertTypeArguments(r)}convertTypeArguments(e){if(e.typeArguments)for(const t of e.typeArguments)this.convertTypeNode(t)}convertMembers(e){for(const t of e){if(i.isPropertyDeclaration(t)||i.isPropertySignature(t)||i.isIndexSignatureDeclaration(t)){i.isPropertyDeclaration(t)&&t.initializer&&i.isPropertyAccessExpression(t.initializer)&&this.pushReference(this.convertPropertyAccess(t.initializer)),this.convertComputedPropertyName(t),this.convertTypeNode(t.type);continue}if(i.isMethodDeclaration(t)||i.isMethodSignature(t)||i.isConstructorDeclaration(t)||i.isConstructSignatureDeclaration(t)||i.isCallSignatureDeclaration(t)||i.isGetAccessorDeclaration(t)||i.isSetAccessorDeclaration(t))this.convertParametersAndType(t);else throw new w(t)}}convertTypeParameters(e){if(!e)return 0;for(const t of e)this.convertTypeNode(t.constraint),this.convertTypeNode(t.default),this.pushScope(),this.pushTypeVariable(t.name);return e.length}convertTypeNode(e){if(e&&!En.has(e.kind)){if(i.isTypeReferenceNode(e)){this.pushReference(this.convertEntityName(e.typeName)),this.convertTypeArguments(e);return}if(i.isTypeLiteralNode(e)){this.convertMembers(e.members);return}if(i.isArrayTypeNode(e)){this.convertTypeNode(e.elementType);return}if(i.isTupleTypeNode(e)){for(const t of e.elements)this.convertTypeNode(t);return}if(i.isNamedTupleMember(e)||i.isParenthesizedTypeNode(e)||i.isTypeOperatorNode(e)||i.isTypePredicateNode(e)){this.convertTypeNode(e.type);return}if(i.isUnionTypeNode(e)||i.isIntersectionTypeNode(e)){for(const t of e.types)this.convertTypeNode(t);return}if(i.isMappedTypeNode(e)){const{typeParameter:t,type:r,nameType:s}=e;this.convertTypeNode(t.constraint),this.pushScope(),this.pushTypeVariable(t.name),this.convertTypeNode(r),s&&this.convertTypeNode(s),this.popScope();return}if(i.isConditionalTypeNode(e)){this.convertTypeNode(e.checkType),this.pushScope(),this.convertTypeNode(e.extendsType),this.convertTypeNode(e.trueType),this.convertTypeNode(e.falseType),this.popScope();return}if(i.isIndexedAccessTypeNode(e)){this.convertTypeNode(e.objectType),this.convertTypeNode(e.indexType);return}if(i.isFunctionOrConstructorTypeNode(e)){this.convertParametersAndType(e);return}if(i.isTypeQueryNode(e)){const t=this.convertEntityName(e.exprName);this.pushReference(t),this.convertTypeArguments(e);return}if(i.isRestTypeNode(e)){this.convertTypeNode(e.type);return}if(i.isOptionalTypeNode(e)){this.convertTypeNode(e.type);return}if(i.isTemplateLiteralTypeNode(e)){for(const t of e.templateSpans)this.convertTypeNode(t.type);return}if(i.isInferTypeNode(e)){const{typeParameter:t}=e;this.convertTypeNode(t.constraint),this.pushTypeVariable(t.name);return}else throw new w(e)}}convertNamespace(e,t=!1){if(this.pushScope(),t&&e.body&&i.isModuleDeclaration(e.body)){this.convertNamespace(e.body,!0);return}if(!e.body||!i.isModuleBlock(e.body))throw new w(e,'namespace must have a "ModuleBlock" body.');const{statements:r}=e.body;for(const s of r){if(i.isEnumDeclaration(s)||i.isFunctionDeclaration(s)||i.isClassDeclaration(s)||i.isInterfaceDeclaration(s)||i.isTypeAliasDeclaration(s)||i.isModuleDeclaration(s)){if(s.name&&i.isIdentifier(s.name))this.pushTypeVariable(s.name);else throw new w(s,"non-Identifier name not supported");continue}if(i.isVariableStatement(s)){for(const o of s.declarationList.declarations)if(i.isIdentifier(o.name))this.pushTypeVariable(o.name);else throw new w(o,"non-Identifier name not supported");continue}if(i.isImportDeclaration(s)){if(s.importClause&&(s.importClause.name&&this.pushTypeVariable(s.importClause.name),s.importClause.namedBindings))if(i.isNamespaceImport(s.importClause.namedBindings))this.pushTypeVariable(s.importClause.namedBindings.name);else for(const o of s.importClause.namedBindings.elements)this.pushTypeVariable(o.name);continue}if(i.isImportEqualsDeclaration(s)){this.pushTypeVariable(s.name);continue}if(!i.isExportDeclaration(s))throw new w(s,"namespace child (hoisting) not supported yet")}for(const s of r){if(i.isVariableStatement(s)){for(const o of s.declarationList.declarations)o.type&&this.convertTypeNode(o.type);continue}if(i.isFunctionDeclaration(s)){this.convertParametersAndType(s);continue}if(i.isInterfaceDeclaration(s)||i.isClassDeclaration(s)){const o=this.convertTypeParameters(s.typeParameters);this.convertHeritageClauses(s),this.convertMembers(s.members),this.popScope(o);continue}if(i.isTypeAliasDeclaration(s)){const o=this.convertTypeParameters(s.typeParameters);this.convertTypeNode(s.type),this.popScope(o);continue}if(i.isModuleDeclaration(s)){this.convertNamespace(s,t);continue}if(!i.isEnumDeclaration(s)&&!i.isImportDeclaration(s)){if(i.isImportEqualsDeclaration(s)){i.isEntityName(s.moduleReference)&&this.pushReference(this.convertEntityName(s.moduleReference));continue}if(i.isExportDeclaration(s)){if(s.exportClause){if(i.isNamespaceExport(s.exportClause))throw new w(s.exportClause);for(const o of s.exportClause.elements){const a=o.propertyName||o.name;this.pushIdentifierReference(a)}}}else throw new w(s,"namespace child (walking) not supported yet")}}this.popScope()}}function Tn({sourceFile:n}){return new Nn(n).transform()}c(Tn,"convert");class Nn{static{c(this,"Transformer")}constructor(e){this.sourceFile=e,this.declarations=new Map,this.ast=pn(e);for(const t of e.statements)this.convertStatement(t)}transform(){return{ast:this.ast}}pushStatement(e){this.ast.body.push(e)}createDeclaration(e,t){const r={start:e.getFullStart(),end:e.getEnd()};if(!t){const u=new Ge({range:r});return this.pushStatement(u.iife),u}const s=t.getText(),o=new Ge({id:t,range:r}),a=this.declarations.get(s);if(a){a.pushIdentifierReference(t),a.declaration.end=r.end;const u=this.ast.body.findIndex(m=>m==a.declaration);for(let m=u+1;m<this.ast.body.length;m++){const p=this.ast.body[m];p.start=p.end=r.end}}else this.pushStatement(o.declaration),this.declarations.set(s,o);return a||o}convertStatement(e){if(i.isEnumDeclaration(e))return this.convertEnumDeclaration(e);if(i.isFunctionDeclaration(e))return this.convertFunctionDeclaration(e);if(i.isInterfaceDeclaration(e)||i.isClassDeclaration(e))return this.convertClassOrInterfaceDeclaration(e);if(i.isTypeAliasDeclaration(e))return this.convertTypeAliasDeclaration(e);if(i.isVariableStatement(e))return this.convertVariableStatement(e);if(i.isExportDeclaration(e)||i.isExportAssignment(e))return this.convertExportDeclaration(e);if(i.isModuleDeclaration(e))return this.convertNamespaceDeclaration(e);if(e.kind===i.SyntaxKind.NamespaceExportDeclaration)return this.removeStatement(e);if(i.isImportDeclaration(e)||i.isImportEqualsDeclaration(e))return this.convertImportDeclaration(e);throw new w(e)}removeStatement(e){this.pushStatement(I({type:"ExpressionStatement",expression:{type:"Literal",value:"pls remove me"}},e))}convertNamespaceDeclaration(e){if(e.flags&i.NodeFlags.GlobalAugmentation||!i.isIdentifier(e.name)){this.createDeclaration(e).convertNamespace(e,!0);return}const r=this.createDeclaration(e,e.name);r.pushIdentifierReference(e.name),r.convertNamespace(e,!0)}convertEnumDeclaration(e){this.createDeclaration(e,e.name).pushIdentifierReference(e.name)}convertFunctionDeclaration(e){if(!e.name)throw new w(e,"FunctionDeclaration should have a name");const t=this.createDeclaration(e,e.name);t.pushIdentifierReference(e.name),t.convertParametersAndType(e)}convertClassOrInterfaceDeclaration(e){if(!e.name)throw new w(e,"ClassDeclaration / InterfaceDeclaration should have a name");const t=this.createDeclaration(e,e.name),r=t.convertTypeParameters(e.typeParameters);t.convertHeritageClauses(e),t.convertMembers(e.members),t.popScope(r)}convertTypeAliasDeclaration(e){const t=this.createDeclaration(e,e.name),r=t.convertTypeParameters(e.typeParameters);t.convertTypeNode(e.type),t.popScope(r)}convertVariableStatement(e){const{declarations:t}=e.declarationList;if(t.length!==1)throw new w(e,"VariableStatement with more than one declaration not yet supported");for(const r of t){if(!i.isIdentifier(r.name))throw new w(e,"VariableDeclaration must have a name");const s=this.createDeclaration(e,r.name);s.convertTypeNode(r.type),r.initializer&&this.trackExpressionReferences(r.initializer,s)}}trackExpressionReferences(e,t){if(i.isIdentifier(e))t.pushIdentifierReference(e);else if(i.isObjectLiteralExpression(e))for(const r of e.properties)i.isShorthandPropertyAssignment(r)?t.pushIdentifierReference(r.name):i.isPropertyAssignment(r)&&this.trackExpressionReferences(r.initializer,t);else if(i.isArrayLiteralExpression(e))for(const r of e.elements)i.isExpression(r)&&this.trackExpressionReferences(r,t);else i.isPropertyAccessExpression(e)&&this.trackExpressionReferences(e.expression,t)}convertExportDeclaration(e){if(i.isExportAssignment(e)){this.pushStatement(I({type:"ExportDefaultDeclaration",declaration:A(e.expression)},e));return}const t=e.moduleSpecifier?A(e.moduleSpecifier):void 0;if(!e.exportClause)this.pushStatement(I({type:"ExportAllDeclaration",source:t,exported:null,attributes:[]},e));else if(i.isNamespaceExport(e.exportClause))this.pushStatement(I({type:"ExportAllDeclaration",source:t,exported:M(e.exportClause.name),attributes:[]},e));else{const r=[];for(const s of e.exportClause.elements)r.push(this.convertExportSpecifier(s));this.pushStatement(I({type:"ExportNamedDeclaration",declaration:null,specifiers:r,source:t,attributes:[]},e))}}convertImportDeclaration(e){if(i.isImportEqualsDeclaration(e)){if(i.isEntityName(e.moduleReference)){const s=this.createDeclaration(e,e.name);s.pushReference(s.convertEntityName(e.moduleReference));return}if(!i.isExternalModuleReference(e.moduleReference))throw new w(e,"ImportEquals should have a literal source.");this.pushStatement(I({type:"ImportDeclaration",specifiers:[{type:"ImportDefaultSpecifier",local:M(e.name)}],source:A(e.moduleReference.expression),attributes:[]},e));return}const t=A(e.moduleSpecifier),r=e.importClause&&e.importClause.namedBindings?this.convertNamedImportBindings(e.importClause.namedBindings):[];e.importClause&&e.importClause.name&&r.push({type:"ImportDefaultSpecifier",local:M(e.importClause.name)}),this.pushStatement(I({type:"ImportDeclaration",specifiers:r,source:t,attributes:[]},e))}convertNamedImportBindings(e){return i.isNamedImports(e)?e.elements.map(t=>{const r=M(t.name),s=t.propertyName?M(t.propertyName):r;return{type:"ImportSpecifier",local:r,imported:s}}):[{type:"ImportNamespaceSpecifier",local:M(e.name)}]}convertExportSpecifier(e){const t=M(e.name);return{type:"ExportSpecifier",exported:t,local:e.propertyName?M(e.propert