var $e=Object.defineProperty;var i=(e,s)=>$e(e,"name",{value:s,configurable:!0});import T from"node:module";import{MessageChannel as We}from"node:worker_threads";import{i as j,b as Je,e as z,m as be}from"./node-features-B9BBLzwu.mjs";import{l as re,t as oe,g as Oe,a as Ne,d as b,b as d,e as V,f as S,h as L,j as K,k as Ae,m as g,n as Me,w as ne,o as ae,p as O,q as ce,s as N,u as Be}from"./register-BnTWPeIB.mjs";import{pathToFileURL as h,fileURLToPath as Y}from"node:url";import{readFileSync as qe}from"node:fs";import{readFile as Qe}from"node:fs/promises";import{p as He,i as ie,t as me,a as A,b as le,c as Ge,r as Xe}from"./index-XurvG3JN.mjs";import{p as de}from"./client-D_mPDF5S.mjs";import U from"node:path";const I={active:!0,parsedTsconfig:void 0},ue=i(e=>{const s={active:!0,namespace:e?.namespace,onImport:e?.onImport,parsedTsconfig:void 0,port:e?.port,tsconfig:e?.tsconfig};return e?.tsconfig!==!1&&(s.parsedTsconfig=re(e?.tsconfig??process.env.TSX_TSCONFIG_PATH)),s},"createData"),ze=i(async e=>{if(!e)throw new Error(`tsx must be loaded with --import instead of --loader The --loader flag was deprecated in Node v20.6.0 and v18.19.0`);Object.assign(I,ue(e)),e.port&&e.port.on("message",s=>{s==="deactivate"&&(I.active=!1,e.port.postMessage({type:"deactivated"}))})},"initialize"),Ve=i(()=>(I.parsedTsconfig=re(process.env.TSX_TSCONFIG_PATH),"process.setSourceMapsEnabled(true);"),"globalPreload"),Ke=i(e=>{const{pathname:s}=new URL(e),t=U.extname(s);if(t===".mts"||t===".mjs")return"module";if(t===".cts"||t===".cjs")return"commonjs";if(t===".js"||oe.includes(t))return Oe(e)},"getFormatFromFileUrl"),Ye=i(e=>{const{pathname:s}=new URL(e),t=U.extname(s);if(t===".mts"||t===".mjs")return"module";if(t===".cts"||t===".cjs")return"commonjs";if(t===".js"||oe.includes(t))return Ne(e)},"getFormatFromFileUrlSync"),R="tsx-namespace=",M="tsx-commonjs-export-preparse",fe=`${M}=1`,F="tsx-commonjs-virtual-query",C=new Map,Z=i((e,s)=>e.slice(1).split("&").filter(t=>t&&s.every(r=>!t.startsWith(r))).join("&"),"getQueryWithoutParameters"),B=i((e,s)=>{const t=Z(e,s);return t?`?${t}`:""},"getSearchWithoutParameters"),Ze=i(e=>e.replaceAll(/\/\*[\s\S]*?\*\/|\/\/[^\n\r]*/g,""),"stripComments"),De=i(e=>{const s=Ze(e);if(/^\s*export\s*\*/.test(s))return"named";if(/^\s*import\s*\*\s*as\s+[\w$]+/.test(s))return"namespace";const t=s.match(/\{([^}]*)\}/)?.[1];if(t)return t.split(",").some(r=>{const o=r.trim().split(/\s+as\s+/)[0];return!!(o&&o!=="default")})?"named":void 0},"getCommonJsImportBinding"),ke=i((e,s,t)=>{const r=C.get(e);if(!r)return!1;try{const[o]=He(r);return o.some(n=>{if(n.d!==-1||n.n!==s)return!1;const m=De(r.slice(n.ss,n.s));return m==="named"||t&&m==="namespace"})}catch{return!1}},"parentImportsCommonJsExports"),v=i(e=>{const s=e.indexOf(R);if(s===-1)return;const t=e[s-1];if(t!=="?"&&t!=="&")return;const r=s+R.length,o=e.indexOf("&",r);return o===-1?e.slice(r):e.slice(r,o)},"getNamespace"),pe=j(Je)?"importAttributes":"importAssertions",he=i(e=>e==="commonjs"||e==="commonjs-typescript","isCommonJsFormat"),ge=i(e=>e==="module-typescript"||e==="typescript","isModuleTypeScriptFormat"),xe=j(z),et=[`${F}=`],q=[`${M}=`,`${F}=`],w=i((e,s)=>s.parsedTsconfig&&Ae(s.parsedTsconfig,e)?s.parsedTsconfig.config:void 0,"getTsconfigRaw"),tt=i(e=>{if(!e.searchParams.has(F))return;const{pathname:s}=e,t=s.toLowerCase().lastIndexOf("%3f");if(t===-1)return;const r=new URL(e);return r.pathname=s.slice(0,t),r.search="",Y(r)},"getFilePathFromVirtualQuery"),D=i(e=>{const s=e.startsWith(g)?new URL(e):void 0,t=s?Y(s):e,r=s&&tt(s),o=r||t,n=s&&r?h(o).toString()+B(s.search,et):e;return{fileUrl:s,filePath:o,loadUrl:n}},"getFileLoadContext"),ye=i((e,s)=>{if(!s?.search)return e;const t=B(s.search,q);return t?h(e).toString()+t:e},"getTransformPath"),Pe=i((e,s,t)=>{const r=[...s?Z(s.search,[R,...q]).split("&").filter(Boolean):[],...t?[`namespace=${encodeURIComponent(t)}`]:[]].join("&");return r?`${e}?${r}`:e},"getFilePathWithQuery"),st=new TextDecoder,Se=i(e=>typeof e=="string"?e:st.decode(e),"decodeSource"),rt=i((e,s)=>{const t=new URL(s),r=s.startsWith(g)?D(s).filePath:void 0;t.searchParams.delete("tsx-namespace"),t.searchParams.delete(M),t.searchParams.delete(F),r&&(t.pathname=new URL(h(r)).pathname);const o=t.toString();return e.port&&e.port.postMessage({type:"load",url:o}),e.onImport?.(o),o},"notifyLoad"),Re=i((e,s)=>{if(!e.active)return!1;const t=v(s);if(e.namespace&&e.namespace!==t)return!1;const r=rt(e,s);return de.send&&de.send({type:"dependency",path:r}),!0},"prepareLoad"),Ue=i((e,s)=>{if(!Me.test(e))return s;const t=s[pe];return t?.type?s:{...s,[pe]:{...t,type:"json"}}},"prepareJsonAttributes"),k=i(({conditions:e})=>e?.includes("require")===!0&&!e.includes("import"),"isCommonJsRequireContext$1"),ot=i(e=>{const s=i(async(t,r,o)=>{if(!Re(e,t))return o(t,r);const n=v(t),{fileUrl:m,filePath:c,loadUrl:a}=D(t),u=Ue(a,r),l=await o(a,u);d(3,"loaded by next loader",{url:t,loadUrl:a,loaded:l});const y=m?.searchParams.has(M)===!0,P=l.format,E=m?new URL(h(c)):void 0;if(E&&m&&(E.search=B(m.search,q)),he(P)&&m&&l.responseURL?.startsWith("file:")&&!c.endsWith(".cjs")){const f=await Qe(h(c),"utf8"),W=ie(f);if(P==="commonjs-typescript"||!c.endsWith(".js")||W){if(!xe){if(y&&W&&V.test(c)){const J=await me(f,c,{define:{"import.meta.url":JSON.stringify(E.toString())},tsconfigRaw:w(c,e)});return C.set(t,J.code),{format:"module",source:S(J)}}return l}if(!n&&!y&&!c.endsWith(".cts"))return l;const te=!!(n||y||B(m.search,q)),se=A(f,ye(c,m),{cjsBanner:te?`require = require("node:module").createRequire(${JSON.stringify(h(c).toString())});`:void 0,tsconfigRaw:w(c,e)});if(l.format="commonjs",l.source=S(se),te){const J=Pe(c,m,n);l.responseURL=`data:text/javascript,${encodeURIComponent(se.code)}?filePath=${encodeURIComponent(J)}`}return d(3,"returning CJS export annotation",l),l}}if(!l.source)return l;const p=Se(l.source),$=P==="json"&&!k(r);if(P==="commonjs-typescript"){const f=A(p,c,{tsconfigRaw:w(c,e)});return{...l,format:"commonjs",source:S(f)}}if($||ge(P)||L.test(t)){const f=await me(p,c,{tsconfigRaw:w(c,e)});return C.set(t,f.code),{format:"module",source:S(f)}}if(l.format==="module"){const f=le(c,p);f?(l.source=S(f),C.set(t,f.code)):C.set(t,p)}return l},"load2");return b?async(t,r,o)=>{d(2,"load",{url:t,context:r});const n=await s(t,r,o);return d(1,"loaded",{url:t,result:n}),n}:s},"createLoad"),nt=i(e=>{const s=i((t,r,o)=>{if(k(r)&&K()||!Re(e,t))return o(t,r);const n=v(t),{fileUrl:m,filePath:c,loadUrl:a}=D(t),u=Ue(a,r),l=o(a,u);d(3,"loaded by next loader",{url:t,loadUrl:a,loaded:l});const y=l.format;if(he(y)&&j(z)&&l.responseURL?.startsWith("file:")&&!c.endsWith(".cjs")){const p=qe(h(c),"utf8");if(y==="commonjs-typescript"||!c.endsWith(".js")||ie(p)){const $=A(p,ye(c,m),{tsconfigRaw:w(c,e)}),f=!n&&K(),W=Pe(c,m,n);return l.format="commonjs",l.shouldBeReloadedByCJSLoader=f,l.source=S($),f||(l.responseURL=`data:text/javascript,${encodeURIComponent($.code)}?filePath=${encodeURIComponent(W)}`),d(3,"returning CJS export annotation",l),l}}if(!l.source)return l;const P=Se(l.source),E=y==="json"&&!k(r);if(y==="commonjs-typescript"){const p=A(P,c,{tsconfigRaw:w(c,e)});return{...l,format:"commonjs",shouldBeReloadedByCJSLoader:!1,source:S(p)}}if(E||ge(y)||L.test(t)){const p=Ge(P,c,{tsconfigRaw:w(c,e)});return{format:"module",source:S(p)}}if(l.format==="module"){const p=le(c,P);p&&(l.source=S(p))}return l},"load2");return b?(t,r,o)=>{d(2,"loadSync",{url:t,context:r});const n=s(t,r,o);return d(1,"loadedSync",{url:t,result:n}),n}:s},"createLoadSync"),at=ot(I),ct=j(z),it=/^(?:[a-z][\d+.a-z-]*:\/\/|data:|file:|node:)/i,ve=i(e=>!ae(e)&&!it.test(e),"isTsconfigPathAliasSpecifier"),Q=i(e=>{if(e.url)return e.url;const s=e.message.match(/^Cannot find module '([^']+)'/);if(s){const[,r]=s;return r}const t=e.message.match(/^Cannot find package '([^']+)'/);if(t){const[,r]=t;if(!U.isAbsolute(r))return;const o=h(r);if(o.pathname.endsWith("/")&&(o.pathname+="package.json"),o.pathname.endsWith("/package.json")){const n=Xe(o);if(n?.main)return new URL(n.main,o).toString()}else return o.toString()}},"getMissingPathFromNotFound"),H=i(e=>e==="ERR_MODULE_NOT_FOUND"||e==="MODULE_NOT_FOUND","isModuleNotFound"),we=i(e=>e.conditions.includes("require")&&!e.conditions.includes("import"),"isCommonJsRequireContext"),G=i(async(e,s,t,r)=>{const o=ce(e);if(d(3,"resolveExtensions",{url:e,context:s,throwError:r,tryPaths:o}),!o)return;let n;for(const m of o)try{return await t(m,s)}catch(c){const{code:a}=c;if(!H(a)&&a!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw c;n=c}if(r)throw n},"resolveExtensions"),_=i((e,s,t,r)=>{const o=ce(e);if(d(3,"resolveExtensionsSync",{url:e,context:s,throwError:r,tryPaths:o}),!o)return;let n;for(const m of o)try{return t(m,s)}catch(c){const{code:a}=c;if(!H(a)&&a!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw c;n=c}if(r)throw n},"resolveExtensionsSync"),mt=i(async(e,s,t,r)=>{const o=r.parsedTsconfig?.config.compilerOptions?.allowJs??!1;if(d(3,"resolveBase",{specifier:e,context:s,specifierStartsWithFileUrl:e.startsWith(g),isRelativePath:N(e),tsExtensionsPattern:L.test(s.parentURL),allowJs:o}),(e.startsWith(g)||N(e))&&(L.test(s.parentURL)||o)){const n=await G(e,s,t);if(d(3,"resolveBase resolved",{specifier:e,context:s,resolved:n}),n)return n}try{return await t(e,s)}catch(n){if(d(3,"resolveBase error",{specifier:e,context:s,error:n}),n instanceof Error){const m=n;if(H(m.code)){const c=Q(m);if(c){const a=await G(c,s,t);if(a)return a}}}throw n}},"resolveBase"),x=i((e,s,t,r)=>{const o=r.parsedTsconfig?.config.compilerOptions?.allowJs??!1;if(d(3,"resolveBaseSync",{specifier:e,context:s,specifierStartsWithFileUrl:e.startsWith(g),isRelativePath:N(e),tsExtensionsPattern:L.test(s.parentURL),allowJs:o}),(e.startsWith(g)||N(e))&&(L.test(s.parentURL)||o)){const n=_(e,s,t);if(d(3,"resolveBaseSync resolved",{specifier:e,context:s,resolved:n}),n)return n}try{return t(e,s)}catch(n){if(d(3,"resolveBaseSync error",{specifier:e,context:s,error:n}),n instanceof Error){const m=n;if(H(m.code)){const c=Q(m);if(c){const a=_(c,s,t);if(a)return a}}}throw n}},"resolveBaseSync"),Te=i(async(e,s,t,r)=>{if(d(3,"resolveDirectory",{specifier:e,context:s,isDirectory:O.test(e)}),(e==="."||e===".."||e.endsWith("/.."))&&(e+="/"),O.test(e)){const o=new URL(e,s.parentURL);return o.pathname=U.join(o.pathname,"index"),await G(o.toString(),s,t,!0)}try{return await mt(e,s,t,r)}catch(o){if(o instanceof Error){d(3,"resolveDirectory error",{specifier:e,context:s,error:o});const n=o;if(n.code==="ERR_UNSUPPORTED_DIR_IMPORT"){const m=Q(n);if(m)try{return await G(`${m}/index`,s,t,!0)}catch(c){const a=c,{message:u}=a;throw a.message=a.message.replace(`${"/index".replace("/",U.sep)}'`,"'"),a.stack=a.stack.replace(u,a.message),a}}}throw o}},"resolveDirectory"),Le=i((e,s,t,r)=>{if(d(3,"resolveDirectorySync",{specifier:e,context:s,isDirectory:O.test(e)}),(e==="."||e===".."||e.endsWith("/.."))&&(e+="/"),O.test(e)){const o=we(s);if(o&&!ae(e))return x(e,s,t,r);const n=new URL(e,s.parentURL);return n.pathname=U.join(n.pathname,"index"),o?_(Y(n),s,t,!1)??x(e,s,t,r):_(n.toString(),s,t,!0)}try{return x(e,s,t,r)}catch(o){if(o instanceof Error){d(3,"resolveDirectorySync error",{specifier:e,context:s,error:o});const n=o;if(n.code==="ERR_UNSUPPORTED_DIR_IMPORT"){const m=Q(n);if(m)try{return _(`${m}/index`,s,t,!0)}catch(c){const a=c,{message:u}=a;throw a.message=a.message.replace(`${"/index".replace("/",U.sep)}'`,"'"),a.stack=a.stack.replace(u,a.message),a}}}throw o}},"resolveDirectorySync"),lt=i(async(e,s,t,r)=>{const o=ve(e);if(d(3,"resolveTsPaths",{specifier:e,context:s,tsconfigPathAliasSpecifier:o,tsconfig:r.parsedTsconfig,fromNodeModules:s.parentURL?.includes("/node_modules/")}),o&&r.parsedTsconfig&&!s.parentURL?.includes("/node_modules/")){const n=ne(r.parsedTsconfig,e);d(3,"resolveTsPaths",{possiblePaths:n});for(const m of n)try{return await Te(h(m).toString(),s,t,r)}catch{}}return Te(e,s,t,r)},"resolveTsPaths"),dt=i((e,s,t,r)=>{const o=ve(e);if(d(3,"resolveTsPathsSync",{specifier:e,context:s,tsconfigPathAliasSpecifier:o,tsconfig:r.parsedTsconfig,fromNodeModules:s.parentURL?.includes("/node_modules/")}),o&&r.parsedTsconfig&&!s.parentURL?.includes("/node_modules/")){const n=ne(r.parsedTsconfig,e);d(3,"resolveTsPathsSync",{possiblePaths:n});for(const m of n)try{return Le(h(m).toString(),s,t,r)}catch{}}return Le(e,s,t,r)},"resolveTsPathsSync"),X="tsx://",ee=i((e,s)=>`${e}${e.includes("?")?"&":"?"}${s}`,"addQuery"),Ee=i((e,s,t)=>{if(s!=="commonjs"||!e.startsWith(g)||!V.test(e))return e;const r=new URL(e),o=[Z(r.search,[R]),...t?[`namespace=${encodeURIComponent(t)}`]:[]].filter(Boolean).join("&");return o?(r.pathname+=`%3F${o}`,r.searchParams.set(F,"1"),r.toString()):e},"preserveCommonJsQueryIdentity"),ut=i(e=>{const s=i(async(t,r,o)=>{if(!e.active||t.startsWith("node:"))return o(t,r);let n=v(t)??(r.parentURL&&v(r.parentURL));if(e.namespace){let l;if(t.startsWith(X)){try{l=JSON.parse(t.slice(X.length))}catch{}l?.namespace&&(n=l.namespace)}if(e.namespace!==n)return o(t,r);l&&(t=l.specifier,r.parentURL=l.parentURL)}const[m,c]=t.split("?"),a=await lt(m,r,o,e);if(d(2,"nextResolve",{resolved:a}),a.format==="builtin")return a;(!a.format||a.format==="commonjs-typescript"||a.format==="module-typescript")&&a.url.startsWith(g)&&(a.format=await Ke(a.url),d(2,"getFormatFromFileUrl",{resolved:a,format:a.format})),c&&(a.url+=`?${c}`);const u=r.parentURL&&a.format==="commonjs"&&V.test(a.url)&&(r.parentURL.includes(fe)||ke(r.parentURL,t,ct));return n&&!a.url.includes(R)&&(a.url=ee(a.url,`${R}${n}`)),u&&(a.url=ee(a.url,fe)),(n||u)&&(a.url=Ee(a.url,a.format,n)),a},"resolve2");return b?async(t,r,o)=>{d(2,"resolve",{specifier:t,context:r});const n=await s(t,r,o);return d(1,"resolved",{specifier:t,context:r,result:n}),n}:s},"createResolve"),ft=i(e=>{const s=i((t,r,o)=>{if(!e.active||t.startsWith("node:")||we(r)&&K())return o(t,r);let n=v(t)??(r.parentURL&&v(r.parentURL));if(e.namespace){let u;if(t.startsWith(X)){try{u=JSON.parse(t.slice(X.length))}catch{}u?.namespace&&(n=u.namespace)}if(e.namespace!==n)return o(t,r);u&&(t=u.specifier,r.parentURL=u.parentURL)}const[m,c]=t.split("?"),a=dt(m,r,o,e);return d(2,"nextResolve",{resolved:a}),a.format==="builtin"||((!a.format||a.format==="commonjs-typescript"||a.format==="module-typescript")&&a.url.startsWith(g)&&(a.format=Ye(a.url),d(2,"getFormatFromFileUrlSync",{resolved:a,format:a.format})),c&&(a.url+=`?${c}`),n&&!a.url.includes(R)&&(a.url=ee(a.url,`${R}${n}`)),a.url=Ee(a.url,a.format,n)),a},"resolve2");return b?(t,r,o)=>{d(2,"resolveSync",{specifier:t,context:r});const n=s(t,r,o);return d(1,"resolvedSync",{specifier:t,context:r,result:n}),n}:s},"createResolveSync"),pt=ut(I),je=i(e=>(s,t)=>{if(!t)throw new Error("The current file path (import.meta.url) must be provided in the second argument of tsImport()");const r=t.startsWith(g)?t:h(t).toString();return import(`tsx://${JSON.stringify({specifier:s,parentURL:r,namespace:e})}`)},"createScopedImport");let Ie=!1;const ht=i(e=>{const s=[];for(let t=0;t[...(process.env.NODE_OPTIONS??"").matchAll(/(?:^|\s)--import(?:=|\s+)(\S+)/g)].map(([,e])=>e),"collectNodeOptionsImportSpecifiers"),Fe=[new URL("loader.mjs",import.meta.url).toString(),new URL("esm/index.mjs",import.meta.url).toString()],yt=new Set(["tsx","tsx/esm",...Fe,...Fe.map(e=>decodeURI(new URL(e).pathname))]),Pt=i(e=>yt.has(e),"isTsxImport"),Ce=i(e=>/\.(?:[cm]?ts|tsx)(?:[?#].*)?$/.test(e),"isTypeScriptImport"),St=i(()=>{const e=ht(process.execArgv),s=e.findIndex(Pt);return s>0&&e.slice(0,s).some(Ce)},"hasCliTypeScriptPreload"),Rt=gt().some(Ce)||St(),_e=typeof T.registerHooks=="function"&&j(be)&&!Rt,Ut=i(e=>{if(!T.register&&!_e)throw new Error(`This version of Node.js (${process.version}) does not support module.register(). Please upgrade to Node v18.19 or v20.6 and above.`);if(!Ie){const{_resolveFilename:c}=T;T._resolveFilename=(a,...u)=>c(Be(a),...u),Ie=!0}const{sourceMapsEnabled:s}=process;if(process.setSourceMapsEnabled(!0),_e){const c=ue({namespace:e?.namespace,onImport:e?.onImport,tsconfig:e?.tsconfig}),a=T.registerHooks({load:nt(c),resolve:ft(c)}),u=i(async()=>{c.active=!1,a.deregister(),s===!1&&process.setSourceMapsEnabled(!1)},"unregister2");return e?.namespace&&(u.import=je(e.namespace),u.unregister=u),u}const{port1:t,port2:r}=new We;T.register(`./esm/index.mjs?${Date.now()}`,{parentURL:import.meta.url,data:{port:r,namespace:e?.namespace,tsconfig:e?.tsconfig},transferList:[r]});const o=e?.onImport,n=o&&(c=>{c.type==="load"&&o(c.url)});n&&(t.on("message",n),t.unref());const m=i(()=>(s===!1&&process.setSourceMapsEnabled(!1),n&&t.off("message",n),t.postMessage("deactivate"),new Promise(c=>{const a=i(u=>{u.type==="deactivated"&&(c(),t.off("message",a))},"onDeactivated");t.on("message",a)})),"unregister");return e?.namespace&&(m.import=je(e.namespace),m.unregister=m),m},"register");export{Ut as a,Ve as g,ze as i,at as l,pt as r};