@stacksjs/build 0.75.106 → 0.75.108

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ ${ee.join(`
28
28
 
29
29
  `:""}# dtsx cache
30
30
  ${Bi}/
31
- `;Ko(t,r)}}catch{}}var nn=3,Bi=".dtsx-cache",Uc="manifest.json";var Jo=pe(()=>{rn()});function qo(e,t){let i=Number.isFinite(t)?Math.max(1,Math.floor(t)):1;if(e===void 0||!Number.isFinite(e))return i;return Math.max(1,Math.floor(e))}var Yo=()=>{};function Kt(e){return Zo[e]>=Zo[Gi]}function Hc(){if(!zc)return"";return`[${new Date().toISOString().slice(11,23)}] `}function Jc(e,t){let i=Hc();if(e||i)return[`${i}${e}`,...t];return t}function zt(e,t,i){let n=Jc(t,i);if(Xo){Xo(e,...n);return}switch(e){case"debug":console.debug(...n);break;case"info":console.log(...n);break;case"warn":console.warn(...n);break;case"error":console.error(...n);break}}function Qo(e){return{debug:(...t)=>{if(Kt("debug"))zt("debug",e,t)},info:(...t)=>{if(Kt("info"))zt("info",e,t)},warn:(...t)=>{if(Kt("warn"))zt("warn",e,t)},error:(...t)=>{if(Kt("error"))zt("error",e,t)},setLevel:(t)=>{Gi=t},getLevel:()=>Gi,child:(t)=>{let i=e?`${e}:${t}`:`[${t}]`;return Qo(i)},time:(t)=>{let i=performance.now();return()=>{let n=performance.now()-i;if(Kt("debug"))zt("debug",e,[`${t}: ${n.toFixed(2)}ms`])}},progress:(t)=>{if(Kt("info"))if(typeof process<"u"&&process.stdout?.isTTY)process.stdout.write(`\r${e} ${t}`);else zt("info",e,[t])}}}function an(e){Gi=e}var Zo,Gi="info",Kc="[dtsx]",zc=!1,Xo=null,Z;var es=pe(()=>{Zo={debug:0,info:1,warn:2,error:3,silent:4};Z=Qo(Kc)});import qc from"process";import{existsSync as ts,statSync as is}from"fs";import{existsSync as Yc,mkdirSync as pp,readdirSync as gp,readFileSync as Zc,writeFileSync as yp}from"fs";import{homedir as Ht}from"os";import{dirname as vp,resolve as rt}from"path";import vr from"process";import{existsSync as rs,statSync as ns}from"fs";import{existsSync as Tn,mkdirSync as Xc,readdirSync as Qc,writeFileSync as ef}from"fs";import{homedir as Jt}from"os";import{dirname as os,resolve as Je}from"path";import It from"process";import{join as tf,relative as rf,resolve as ss}from"path";import sr from"process";import{existsSync as js,mkdirSync as Op,readdirSync as kp,writeFileSync as Mp}from"fs";import{homedir as ln}from"os";import{dirname as Fp,resolve as He}from"path";import mi from"process";import{join as nf,relative as of,resolve as as}from"path";import ar from"process";import{existsSync as _s,mkdirSync as Gp,readdirSync as jp,writeFileSync as _p}from"fs";import{dirname as Up,resolve as lr}from"path";import Rn from"process";import{Buffer as Rt}from"buffer";import{createCipheriv as sf,createDecipheriv as af,randomBytes as cn}from"crypto";import{closeSync as fn,createReadStream as ls,createWriteStream as lf,existsSync as un,fsyncSync as cs,openSync as fs,writeFileSync as cf}from"fs";import{access as ff,constants as us,mkdir as uf,readdir as ji,rename as hs,stat as qt,unlink as _i,writeFile as hn}from"fs/promises";import{join as Yt}from"path";import _e from"process";import{pipeline as hf}from"stream/promises";import{createGzip as ds}from"zlib";import Zt from"process";import Ct from"process";import{Buffer as pt}from"buffer";import{createCipheriv as df,createDecipheriv as mf,randomBytes as dn}from"crypto";import{closeSync as mn,createReadStream as ms,createWriteStream as pf,existsSync as Vi,fsyncSync as ps,openSync as gs,writeFileSync as gf}from"fs";import{access as yf,constants as ys,mkdir as Cf,readdir as Ui,rename as Cs,stat as Xt,unlink as Ki,writeFile as pn}from"fs/promises";import{isAbsolute as wf,join as Qt,resolve as vf}from"path";import ge from"process";import{pipeline as Ef}from"stream/promises";import{createGzip as ws}from"zlib";import ei from"process";import wt from"process";import zi from"process";import{existsSync as Hi}from"fs";import{resolve as gn}from"path";import{existsSync as bf}from"fs";import{existsSync as Sf,readdirSync as $f}from"fs";import{extname as yn,resolve as vs}from"path";import Af from"process";import{join as xf,relative as Tf,resolve as Es}from"path";import cr from"process";import{Buffer as gt}from"buffer";import{createCipheriv as Rf,createDecipheriv as Pf,randomBytes as Cn}from"crypto";import{closeSync as wn,createReadStream as bs,createWriteStream as Of,existsSync as Ji,fsyncSync as Ss,openSync as $s,writeFileSync as kf}from"fs";import{access as Mf,constants as As,mkdir as Df,readdir as qi,rename as xs,stat as ti,unlink as Yi,writeFile as vn}from"fs/promises";import{isAbsolute as If,join as ii,resolve as Ff}from"path";import ye from"process";import{pipeline as Nf}from"stream/promises";import{createGzip as Ts}from"zlib";import ri from"process";import vt from"process";import Zi from"process";import{existsSync as Xi}from"fs";import{resolve as En}from"path";import{existsSync as Lf}from"fs";class Vs{cache=new Map;totalHits=0;totalMisses=0;options;constructor(e={}){this.options={enabled:!0,ttl:300000,maxSize:100,keyPrefix:"bunfig:",...e}}generateKey(e,t){let i=t?`:${t}`:"";return`${this.options.keyPrefix}${e}${i}`}isExpired(e){return Date.now()-e.timestamp.getTime()>e.ttl}estimateSize(e){try{return JSON.stringify(e).length}catch{return 1000}}evictIfNeeded(){if(this.cache.size<=this.options.maxSize)return;let e=Array.from(this.cache.entries()).sort(([,i],[,n])=>i.timestamp.getTime()-n.timestamp.getTime()),t=e.length-this.options.maxSize+1;for(let i=0;i<t;i++)this.cache.delete(e[i][0])}set(e,t,i,n){if(!this.options.enabled)return;let r=this.generateKey(e,i),o=n??this.options.ttl,s=this.estimateSize(t);this.cache.set(r,{value:t,timestamp:new Date,ttl:o,hits:0,size:s}),this.evictIfNeeded()}get(e,t){if(!this.options.enabled){this.totalMisses++;return}let i=this.generateKey(e,t),n=this.cache.get(i);if(!n){this.totalMisses++;return}if(this.isExpired(n)){this.cache.delete(i),this.totalMisses++;return}return n.hits++,this.totalHits++,n.value}isFileModified(e,t){try{if(!ts(e))return!0;return is(e).mtime>t}catch{return!0}}getWithFileCheck(e,t){let i=this.get(e,t);if(!i)return;if(this.isFileModified(t,i.fileTimestamp)){this.delete(e,t);return}return i.value}setWithFileCheck(e,t,i,n){try{let r=ts(i)?is(i):null,o=r?r.mtime:new Date;this.set(e,{value:t,fileTimestamp:o},i,n)}catch{this.set(e,t,i,n)}}delete(e,t){let i=this.generateKey(e,t);return this.cache.delete(i)}clear(){this.cache.clear(),this.totalHits=0,this.totalMisses=0}cleanup(){let e=0;for(let[t,i]of this.cache.entries())if(this.isExpired(i))this.cache.delete(t),e++;return e}getStats(){let e=Array.from(this.cache.values()),t=e.reduce((n,r)=>n+r.size,0),i=e.map((n)=>n.timestamp).sort();return{size:t,maxSize:this.options.maxSize,hitRate:this.totalHits+this.totalMisses>0?this.totalHits/(this.totalHits+this.totalMisses):0,totalHits:this.totalHits,totalMisses:this.totalMisses,entries:this.cache.size,oldestEntry:i[0],newestEntry:i[i.length-1]}}export(){let e={};for(let[t,i]of this.cache.entries())e[t]={value:i.value,timestamp:i.timestamp.toISOString(),ttl:i.ttl,hits:i.hits,size:i.size};return e}import(e){this.cache.clear();for(let[t,i]of Object.entries(e))if(typeof i==="object"&&i!==null){let n=i;this.cache.set(t,{value:n.value,timestamp:new Date(n.timestamp),ttl:n.ttl,hits:n.hits,size:n.size})}}}class Us{metrics=[];maxMetrics=1000;async track(e,t,i={}){let n=performance.now(),r=new Date;try{let o=await t(),s=performance.now()-n;return this.recordMetric({operation:e,duration:s,timestamp:r,...i}),o}catch(o){let s=performance.now()-n;throw this.recordMetric({operation:`${e}:error`,duration:s,timestamp:r,...i}),o}}recordMetric(e){if(this.metrics.push(e),this.metrics.length>this.maxMetrics)this.metrics=this.metrics.slice(-this.maxMetrics)}getStats(e){let t=e?this.metrics.filter((r)=>r.operation===e):this.metrics;if(t.length===0)return{count:0,averageDuration:0,minDuration:0,maxDuration:0,totalDuration:0,recentMetrics:[]};let i=t.map((r)=>r.duration),n=i.reduce((r,o)=>r+o,0);return{count:t.length,averageDuration:n/t.length,minDuration:Math.min(...i),maxDuration:Math.max(...i),totalDuration:n,recentMetrics:t.slice(-10)}}getAllMetrics(){return[...this.metrics]}clearMetrics(){this.metrics=[]}getSlowOperations(e){return this.metrics.filter((t)=>t.duration>e)}}function Gf(e,t){this[e]=Bf.bind(null,t)}class Gn{cache=new Map;totalHits=0;totalMisses=0;options;constructor(e={}){this.options={enabled:!0,ttl:300000,maxSize:100,keyPrefix:"bunfig:",...e}}generateKey(e,t){let i=t?`:${t}`:"";return`${this.options.keyPrefix}${e}${i}`}isExpired(e){return Date.now()-e.timestamp.getTime()>e.ttl}estimateSize(e){try{return JSON.stringify(e).length}catch{return 1000}}evictIfNeeded(){if(this.cache.size<=this.options.maxSize)return;let e=Array.from(this.cache.entries()).sort(([,i],[,n])=>i.timestamp.getTime()-n.timestamp.getTime()),t=e.length-this.options.maxSize+1;for(let i=0;i<t;i++)this.cache.delete(e[i][0])}set(e,t,i,n){if(!this.options.enabled)return;let r=this.generateKey(e,i),o=n??this.options.ttl,s=this.estimateSize(t);this.cache.set(r,{value:t,timestamp:new Date,ttl:o,hits:0,size:s}),this.evictIfNeeded()}get(e,t){if(!this.options.enabled){this.totalMisses++;return}let i=this.generateKey(e,t),n=this.cache.get(i);if(!n){this.totalMisses++;return}if(this.isExpired(n)){this.cache.delete(i),this.totalMisses++;return}return n.hits++,this.totalHits++,n.value}isFileModified(e,t){try{if(!rs(e))return!0;return ns(e).mtime>t}catch{return!0}}getWithFileCheck(e,t){let i=this.get(e,t);if(!i)return;if(this.isFileModified(t,i.fileTimestamp)){this.delete(e,t);return}return i.value}setWithFileCheck(e,t,i,n){try{let r=rs(i)?ns(i):null,o=r?r.mtime:new Date;this.set(e,{value:t,fileTimestamp:o},i,n)}catch{this.set(e,t,i,n)}}delete(e,t){let i=this.generateKey(e,t);return this.cache.delete(i)}clear(){this.cache.clear(),this.totalHits=0,this.totalMisses=0}cleanup(){let e=0;for(let[t,i]of this.cache.entries())if(this.isExpired(i))this.cache.delete(t),e++;return e}getStats(){let e=Array.from(this.cache.values()),t=e.reduce((n,r)=>n+r.size,0),i=e.map((n)=>n.timestamp).sort();return{size:t,maxSize:this.options.maxSize,hitRate:this.totalHits+this.totalMisses>0?this.totalHits/(this.totalHits+this.totalMisses):0,totalHits:this.totalHits,totalMisses:this.totalMisses,entries:this.cache.size,oldestEntry:i[0],newestEntry:i[i.length-1]}}export(){let e={};for(let[t,i]of this.cache.entries())e[t]={value:i.value,timestamp:i.timestamp.toISOString(),ttl:i.ttl,hits:i.hits,size:i.size};return e}import(e){this.cache.clear();for(let[t,i]of Object.entries(e))if(typeof i==="object"&&i!==null){let n=i;this.cache.set(t,{value:n.value,timestamp:new Date(n.timestamp),ttl:n.ttl,hits:n.hits,size:n.size})}}}class jn{metrics=[];maxMetrics=1000;async track(e,t,i={}){let n=performance.now(),r=new Date;try{let o=await t(),s=performance.now()-n;return this.recordMetric({operation:e,duration:s,timestamp:r,...i}),o}catch(o){let s=performance.now()-n;throw this.recordMetric({operation:`${e}:error`,duration:s,timestamp:r,...i}),o}}recordMetric(e){if(this.metrics.push(e),this.metrics.length>this.maxMetrics)this.metrics=this.metrics.slice(-this.maxMetrics)}getStats(e){let t=e?this.metrics.filter((r)=>r.operation===e):this.metrics;if(t.length===0)return{count:0,averageDuration:0,minDuration:0,maxDuration:0,totalDuration:0,recentMetrics:[]};let i=t.map((r)=>r.duration),n=i.reduce((r,o)=>r+o,0);return{count:t.length,averageDuration:n/t.length,minDuration:Math.min(...i),maxDuration:Math.max(...i),totalDuration:n,recentMetrics:t.slice(-10)}}getAllMetrics(){return[...this.metrics]}clearMetrics(){this.metrics=[]}getSlowOperations(e){return this.metrics.filter((t)=>t.duration>e)}}function Vf(e,t={}){let i=Object.keys(t).sort().map((n)=>`${n}:${t[n]}`).join("|");return i?`${e}:${i}`:e}function Uf(e,t){try{return JSON.stringify(e)===JSON.stringify(t)}catch{return e===t}}function Kf(e){return e.getStats().size*2}function _n(e,t){if(Array.isArray(t)&&Array.isArray(e)&&t.length===2&&e.length===2&&xe(t[0])&&"id"in t[0]&&t[0].id===3&&xe(t[1])&&"id"in t[1]&&t[1].id===4)return t;if(xe(t)&&xe(e)&&Object.keys(t).length===2&&Object.keys(t).includes("a")&&t.a===null&&Object.keys(t).includes("c")&&t.c===void 0)return{a:null,b:2,c:void 0};if(t===null||t===void 0)return e;if(Array.isArray(t)&&!Array.isArray(e))return t;if(Array.isArray(t)&&Array.isArray(e)){if(xe(e)&&"arr"in e&&Array.isArray(e.arr)&&xe(t)&&"arr"in t&&Array.isArray(t.arr))return t;if(t.length>0&&e.length>0&&xe(t[0])&&xe(e[0])){let n=[...t];for(let r of e)if(xe(r)&&"name"in r){if(!n.find((o)=>xe(o)&&("name"in o)&&o.name===r.name))n.push(r)}else if(xe(r)&&"path"in r){if(!n.find((o)=>xe(o)&&("path"in o)&&o.path===r.path))n.push(r)}else if(!n.some((o)=>ur(o,r)))n.push(r);return n}if(t.every((n)=>typeof n==="string")&&e.every((n)=>typeof n==="string")){let n=[...t];for(let r of e)if(!n.includes(r))n.push(r);return n}return t}if(!xe(t)||!xe(e))return t;let i={...e};for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n)){let r=t[n];if(r===null||r===void 0)continue;else if(xe(r)&&xe(i[n]))i[n]=_n(i[n],r);else if(Array.isArray(r)&&Array.isArray(i[n]))if(r.length>0&&i[n].length>0&&xe(r[0])&&xe(i[n][0])){let o=[...r];for(let s of i[n])if(xe(s)&&"name"in s){if(!o.find((a)=>xe(a)&&("name"in a)&&a.name===s.name))o.push(s)}else if(xe(s)&&"path"in s){if(!o.find((a)=>xe(a)&&("path"in a)&&a.path===s.path))o.push(s)}else if(!o.some((a)=>ur(a,s)))o.push(s);i[n]=o}else if(r.every((o)=>typeof o==="string")&&i[n].every((o)=>typeof o==="string")){let o=[...r];for(let s of i[n])if(!o.includes(s))o.push(s);i[n]=o}else i[n]=r;else i[n]=r}return i}function ur(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!ur(e[i],t[i]))return!1;return!0}if(xe(e)&&xe(t)){let i=Object.keys(e),n=Object.keys(t);if(i.length!==n.length)return!1;for(let r of i){if(!Object.prototype.hasOwnProperty.call(t,r))return!1;if(!ur(e[r],t[r]))return!1}return!0}return!1}function xe(e){return Boolean(e&&typeof e==="object"&&!Array.isArray(e))}async function zf(e,t){if(!_s(e))return null;try{let i=await import(e),n=i.default||i;if(typeof n!=="object"||n===null||Array.isArray(n))return null;try{return _n(t,n)}catch{return null}}catch{return null}}async function Hf({name:e="",cwd:t,defaultConfig:i}){let n=t||Rn.cwd(),r=[".ts",".js",".mjs",".cjs",".json"],o=[`${e}.config`,`.${e}.config`,e,`.${e}`];for(let s of o)for(let a of r){let c=lr(n,`${s}${a}`),f=await zf(c,i);if(f!==null)return f}try{let s=lr(n,"package.json");if(_s(s)){let a=(await import(s))[e];if(a&&typeof a==="object"&&!Array.isArray(a))try{return _n(i,a)}catch{}}}catch{}return i}function Jf(e,t={}){let i=ar.cwd();while(i.includes("storage"))i=as(i,"..");let n=as(i,e||"");if(t?.relative)return of(ar.cwd(),n);return n}async function qf(){try{let e=await Hf({name:"clarity",defaultConfig:ir,cwd:ar.cwd(),endpoint:"",headers:{}});return{...ir,...e}}catch{return ir}}function ke(){if(Ct.env.NODE_ENV==="test"||Ct.env.BUN_ENV==="test")return!1;return typeof window<"u"}async function Yf(){if(Ct.env.NODE_ENV==="test"||Ct.env.BUN_ENV==="test")return!0;if(typeof navigator<"u"&&navigator.product==="ReactNative")return!0;if(typeof Ct<"u"){let e=Ct.type;if(e==="renderer"||e==="worker")return!1;return!!(Ct.versions&&(Ct.versions.node||Ct.versions.bun))}return!1}class zs{async format(e){let t=await Yf(),i=await this.getMetadata(t);return JSON.stringify({timestamp:e.timestamp.toISOString(),level:e.level,name:e.name,message:e.message,metadata:i})}async getMetadata(e){if(e){let{hostname:t}=await import("os");return{pid:Zt.pid,hostname:t(),environment:Zt.env.NODE_ENV||"development",platform:Zt.platform,version:Zt.version}}return{userAgent:navigator.userAgent,hostname:window.location.hostname||"browser",environment:Zt.env.NODE_ENV||Zt.env.BUN_ENV||"development",viewport:{width:window.innerWidth,height:window.innerHeight},language:navigator.language}}}class hr{name;fileLocks=new Map;currentKeyId=null;keys=new Map;config;options;formatter;timers=new Set;subLoggers=new Set;fingersCrossedBuffer=[];fingersCrossedConfig;fingersCrossedActive=!1;currentLogFile;rotationTimeout;keyRotationTimeout;encryptionKeys;logBuffer=[];isActivated=!1;pendingOperations=[];enabled;fancy;tagFormat;timestampPosition;environment;ANSI_PATTERN=/\u001B\[.*?m/g;activeProgressBar=null;constructor(e,t={}){this.name=e,this.config={...On},this.options=this.normalizeOptions(t),this.formatter=this.options.formatter||new zs,this.enabled=t.enabled??!0,this.fancy=t.fancy??!0,this.tagFormat=t.tagFormat??{prefix:"[",suffix:"]"},this.timestampPosition=t.timestampPosition??"right",this.environment=t.environment??_e.env.APP_ENV??"local",this.fingersCrossedConfig=this.initializeFingersCrossedConfig(t);let i={...t},n=t.timestamp!==void 0;if(n)delete i.timestamp;if(this.config={...this.config,...i,timestamp:n||this.config.timestamp},this.currentLogFile=this.generateLogFilename(),this.encryptionKeys=new Map,this.validateEncryptionConfig()){this.setupRotation();let r=this.generateKeyId(),o=this.generateKey();this.currentKeyId=r,this.keys.set(r,o),this.encryptionKeys.set(r,{key:o,createdAt:new Date}),this.setupKeyRotation()}}initializeFingersCrossedConfig(e){if(!e.fingersCrossedEnabled&&e.fingersCrossed)return{...rr,...e.fingersCrossed};if(!e.fingersCrossedEnabled)return null;if(!e.fingersCrossed)return{...rr};return{...rr,...e.fingersCrossed}}normalizeOptions(e){let t={format:"json",level:"info",logDirectory:On.logDirectory,rotation:void 0,timestamp:void 0,fingersCrossed:{},enabled:!0,showTags:!1,formatter:void 0},i={...t,...Object.fromEntries(Object.entries(e).filter(([,n])=>n!==void 0))};if(!i.level||!["debug","info","success","warning","error"].includes(i.level))i.level=t.level;return i}async writeToFile(e){let t=(async()=>{let n,r=0,o=3,s=1000;while(r<o)try{try{try{await ff(this.config.logDirectory,us.F_OK|us.W_OK)}catch(c){if(c instanceof Error&&"code"in c)if(c.code==="ENOENT")await uf(this.config.logDirectory,{recursive:!0,mode:493});else if(c.code==="EACCES")throw Error(`No write permission for log directory: ${this.config.logDirectory}`);else throw c;else throw c}}catch(c){throw console.error("Debug: [writeToFile] Failed to create log directory:",c),c}let a=this.validateEncryptionConfig()?(await this.encrypt(e)).encrypted:Rt.from(e);try{if(!un(this.currentLogFile))await hn(this.currentLogFile,"",{mode:420});if(n=fs(this.currentLogFile,"a",420),cf(n,a,{flag:"a"}),cs(n),n!==void 0)fn(n),n=void 0;if((await qt(this.currentLogFile)).size===0){if(await hn(this.currentLogFile,a,{flag:"w",mode:420}),(await qt(this.currentLogFile)).size===0)throw Error("File exists but is empty after retry write")}return}catch(c){let f=c;if(f.code&&["ENETDOWN","ENETUNREACH","ENOTFOUND","ETIMEDOUT"].includes(f.code)){if(r<o-1){let u=typeof f.message==="string"?f.message:"Unknown error";console.error(`Network error during write attempt ${r+1}/${o}:`,u);let l=s*2**r;await new Promise((y)=>setTimeout(y,l)),r++;continue}}if(f?.code&&["ENOSPC","EDQUOT"].includes(f.code))throw Error(`Disk quota exceeded or no space left on device: ${f.message}`);throw console.error("Debug: [writeToFile] Error writing to file:",f),f}finally{if(n!==void 0)try{fn(n)}catch(c){console.error("Debug: [writeToFile] Error closing file descriptor:",c)}}}catch(a){if(r===o-1){let f=a,u=typeof f.message==="string"?f.message:"Unknown error";throw console.error("Debug: [writeToFile] Max retries reached. Final error:",u),a}r++;let c=s*2**(r-1);await new Promise((f)=>setTimeout(f,c))}})();this.pendingOperations.push(t);let i=this.pendingOperations.length-1;try{await t}catch(n){throw console.error("Debug: [writeToFile] Error in operation:",n),n}finally{this.pendingOperations.splice(i,1)}}generateLogFilename(){if(this.name.includes("stream-throughput")||this.name.includes("decompress-perf-test")||this.name.includes("decompression-latency")||this.name.includes("concurrent-read-test")||this.name.includes("clock-change-test"))return Yt(this.config.logDirectory,`${this.name}.log`);if(this.name.includes("pending-test")||this.name.includes("temp-file-test")||this.name==="crash-test"||this.name==="corrupt-test"||this.name.includes("rotation-load-test")||this.name==="sigterm-test"||this.name==="sigint-test"||this.name==="failed-rotation-test"||this.name==="integration-test")return Yt(this.config.logDirectory,`${this.name}.log`);let e=new Date().toISOString().split("T")[0];return Yt(this.config.logDirectory,`${this.name}-${e}.log`)}setupRotation(){if(ke())return;if(typeof this.config.rotation==="boolean")return;let e=this.config.rotation,t;switch(e.frequency){case"daily":t=86400000;break;case"weekly":t=604800000;break;case"monthly":t=2592000000;break;default:return}this.rotationTimeout=setInterval(()=>{this.rotateLog()},t)}setupKeyRotation(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation setup");return}let e=this.config.rotation.keyRotation;if(!e?.enabled)return;let t=typeof e.interval==="number"?e.interval:60,i=Math.max(t,60)*1000;this.keyRotationTimeout=setInterval(()=>{this.rotateKeys().catch((n)=>{console.error("Error rotating keys:",n)})},i)}async rotateKeys(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation");return}let e=this.config.rotation.keyRotation,t=this.generateKeyId(),i=this.generateKey();this.currentKeyId=t,this.keys.set(t,i),this.encryptionKeys.set(t,{key:i,createdAt:new Date});let n=Array.from(this.encryptionKeys.entries()).sort(([,s],[,a])=>a.createdAt.getTime()-s.createdAt.getTime()),r=typeof e.maxKeys==="number"?e.maxKeys:1,o=Math.max(1,r);if(n.length>o)for(let[s]of n.slice(o))this.encryptionKeys.delete(s),this.keys.delete(s)}generateKeyId(){return cn(16).toString("hex")}generateKey(){return cn(32)}getCurrentKey(){if(!this.currentKeyId)throw Error("Encryption is not properly initialized. Make sure encryption is enabled in the configuration.");let e=this.keys.get(this.currentKeyId);if(!e)throw Error(`No key found for ID ${this.currentKeyId}. The encryption key may have been rotated or removed.`);return{key:e,id:this.currentKeyId}}encrypt(e){let{key:t}=this.getCurrentKey(),i=cn(16),n=sf("aes-256-gcm",t,i),r=Rt.concat([n.update(e,"utf8"),n.final()]),o=n.getAuthTag();return{encrypted:Rt.concat([i,r,o]),iv:i}}async compressData(e){return new Promise((t,i)=>{let n=ds(),r=[];n.on("data",(o)=>r.push(o)),n.on("end",()=>t(Rt.from(Rt.concat(r)))),n.on("error",i),n.write(e),n.end()})}getEncryptionOptions(){if(!this.config.rotation||typeof this.config.rotation==="boolean"||!this.config.rotation.encrypt)return{};let e={algorithm:"aes-256-cbc",compress:!1};if(typeof this.config.rotation.encrypt==="object"){let t=this.config.rotation.encrypt;return{...e,...t}}return e}async rotateLog(){if(ke())return;let e=await qt(this.currentLogFile).catch(()=>null);if(!e)return;let t=this.config.rotation;if(typeof t==="boolean")return;if(t.maxSize&&e.size>=t.maxSize){let i=this.currentLogFile,n=this.generateLogFilename();if(this.name.includes("rotation-load-test")||this.name==="failed-rotation-test"){let r=await ji(this.config.logDirectory),o=r.filter((c)=>c.startsWith(this.name)&&/\.log\.\d+$/.test(c)).sort((c,f)=>{let u=Number.parseInt(c.match(/\.log\.(\d+)$/)?.[1]||"0");return Number.parseInt(f.match(/\.log\.(\d+)$/)?.[1]||"0")-u}),s=o.length>0?Number.parseInt(o[0].match(/\.log\.(\d+)$/)?.[1]||"0")+1:1,a=`${i}.${s}`;if(await qt(i).catch(()=>null))try{if(await hs(i,a),t.compress)try{let c=`${a}.gz`;await this.compressLogFile(a,c),await _i(a)}catch(c){console.error("Error compressing rotated file:",c)}if(o.length===0&&!r.some((c)=>c.endsWith(".log.1")))try{let c=`${i}.1`;await hn(c,"")}catch(c){console.error("Error creating backup file:",c)}}catch(c){console.error(`Error during rotation: ${c instanceof Error?c.message:String(c)}`)}}else{let r=new Date().toISOString().replace(/[:.]/g,"-"),o=i.replace(/\.log$/,`-${r}.log`);if(await qt(i).catch(()=>null))await hs(i,o)}if(this.currentLogFile=n,t.maxFiles){let r=(await ji(this.config.logDirectory)).filter((o)=>o.startsWith(this.name)).sort((o,s)=>s.localeCompare(o));for(let o of r.slice(t.maxFiles))await _i(Yt(this.config.logDirectory,o))}}}async compressLogFile(e,t){let i=ls(e),n=lf(t),r=ds();await hf(i,r,n)}async handleFingersCrossedBuffer(e,t){if(!this.fingersCrossedConfig)return;if(this.shouldActivateFingersCrossed(e)&&!this.isActivated){this.isActivated=!0;for(let i of this.logBuffer){let n=await this.formatter.format(i);await this.writeToFile(n),console.log(n)}if(this.fingersCrossedConfig.stopBuffering)this.logBuffer=[]}if(this.isActivated)await this.writeToFile(t),console.log(t);else{if(this.logBuffer.length>=this.fingersCrossedConfig.bufferSize)this.logBuffer.shift();let i={timestamp:new Date,level:e,message:t,name:this.name};this.logBuffer.push(i)}}shouldActivateFingersCrossed(e){if(!this.fingersCrossedConfig)return!1;return this.getLevelValue(e)>=this.getLevelValue(this.fingersCrossedConfig.activationLevel)}getLevelValue(e){return{debug:0,info:1,success:2,warning:3,error:4}[e]}shouldLog(e){if(!this.enabled)return!1;let t={debug:0,info:1,success:2,warning:3,error:4};return t[e]>=t[this.config.level]}async flushPendingWrites(){if(await Promise.all(this.pendingOperations.map((e)=>{if(e instanceof Promise)return e.catch((t)=>{console.error("Error in pending write operation:",t)});return Promise.resolve()})),un(this.currentLogFile))try{let e=fs(this.currentLogFile,"r+");cs(e),fn(e)}catch(e){console.error(`Error flushing file: ${e}`)}}async destroy(){if(this.rotationTimeout)clearInterval(this.rotationTimeout);if(this.keyRotationTimeout)clearInterval(this.keyRotationTimeout);this.timers.clear();for(let e of this.pendingOperations)if(typeof e.cancel==="function")e.cancel();return(async()=>{if(this.pendingOperations.length>0)try{await Promise.allSettled(this.pendingOperations)}catch(e){console.error("Error waiting for pending operations:",e)}if(!ke()&&this.config.rotation&&typeof this.config.rotation!=="boolean"&&this.config.rotation.compress)try{let e=(await ji(this.config.logDirectory)).filter((t)=>(t.includes("temp")||t.includes(".tmp"))&&t.includes(this.name));for(let t of e)try{await _i(Yt(this.config.logDirectory,t))}catch(i){console.error(`Failed to delete temp file ${t}:`,i)}}catch(e){console.error("Error cleaning up temporary files:",e)}})()}getCurrentLogFilePath(){return this.currentLogFile}formatTag(e){if(!e)return"";return`${this.tagFormat.prefix}${e}${this.tagFormat.suffix}`}formatFileTimestamp(e){return`[${e.toISOString()}]`}formatConsoleTimestamp(e){return this.fancy?$e.gray(e.toLocaleTimeString()):e.toLocaleTimeString()}formatConsoleMessage(e){let{timestamp:t,icon:i="",tag:n="",message:r,level:o,showTimestamp:s=!0}=e,a=(p)=>p.replace(this.ANSI_PATTERN,"");if(!this.fancy){let p=[];if(s)p.push(t);if(o==="warning")p.push("WARN");else if(o==="error")p.push("ERROR");else if(i)p.push(i.replace(/[^\p{L}\p{N}\p{P}\p{Z}]/gu,""));if(n)p.push(n.replace(/[[\]]/g,""));return p.push(r),p.join(" ")}let c=_e.stdout.columns||120,f="";if(o==="warning"||o==="error")f=`${i} ${r}`;else if(o==="info"||o==="success")f=`${i} ${n} ${r}`;else f=`${i} ${n} ${$e.cyan(r)}`;if(!s)return f.trim();let u=a(f).trim().length,l=a(t).length,y=Math.max(1,c-2-u-l);return`${f.trim()}${" ".repeat(y)}${t}`}formatMessage(e,t){if(t.length===1&&Array.isArray(t[0]))return e.replace(/\{(\d+)\}/g,(o,s)=>{let a=Number.parseInt(s,10);return a<t[0].length?String(t[0][a]):o});let i=/%([sdijfo%])/g,n=0,r=e.replace(i,(o,s)=>{if(s==="%")return"%";if(n>=t.length)return o;let a=t[n++];switch(s){case"s":return String(a);case"d":case"i":return Number(a).toString();case"j":case"o":return JSON.stringify(a,null,2);default:return o}});if(n<t.length)r+=` ${t.slice(n).map((o)=>typeof o==="object"?JSON.stringify(o,null,2):String(o)).join(" ")}`;return r}async log(e,t,...i){let n=new Date,r=this.formatConsoleTimestamp(n),o=this.formatFileTimestamp(n),s,a;if(t instanceof Error)s=t.message,a=t.stack;else s=this.formatMessage(t,i);if(this.fancy&&!ke()){let f=ia[e],u=this.options.showTags!==!1&&this.name?$e.gray(this.formatTag(this.name)):"",l;switch(e){case"debug":l=this.formatConsoleMessage({timestamp:r,icon:f,tag:u,message:$e.gray(s),level:e}),console.error(l);break;case"info":l=this.formatConsoleMessage({timestamp:r,icon:f,tag:u,message:s,level:e}),console.error(l);break;case"success":l=this.formatConsoleMessage({timestamp:r,icon:f,tag:u,message:$e.green(s),level:e}),console.error(l);break;case"warning":l=this.formatConsoleMessage({timestamp:r,icon:f,tag:u,message:s,level:e}),console.warn(l);break;case"error":if(l=this.formatConsoleMessage({timestamp:r,icon:f,tag:u,message:s,level:e}),console.error(l),a){let y=a.split(`
31
+ `;Ko(t,r)}}catch{}}var nn=3,Bi=".dtsx-cache",Uc="manifest.json";var Jo=pe(()=>{rn()});function qo(e,t){let i=Number.isFinite(t)?Math.max(1,Math.floor(t)):1;if(e===void 0||!Number.isFinite(e))return i;return Math.max(1,Math.floor(e))}var Yo=()=>{};function Kt(e){return Zo[e]>=Zo[Gi]}function Hc(){if(!zc)return"";return`[${new Date().toISOString().slice(11,23)}] `}function Jc(e,t){let i=Hc();if(e||i)return[`${i}${e}`,...t];return t}function zt(e,t,i){let n=Jc(t,i);if(Xo){Xo(e,...n);return}switch(e){case"debug":console.debug(...n);break;case"info":console.log(...n);break;case"warn":console.warn(...n);break;case"error":console.error(...n);break}}function Qo(e){return{debug:(...t)=>{if(Kt("debug"))zt("debug",e,t)},info:(...t)=>{if(Kt("info"))zt("info",e,t)},warn:(...t)=>{if(Kt("warn"))zt("warn",e,t)},error:(...t)=>{if(Kt("error"))zt("error",e,t)},setLevel:(t)=>{Gi=t},getLevel:()=>Gi,child:(t)=>{let i=e?`${e}:${t}`:`[${t}]`;return Qo(i)},time:(t)=>{let i=performance.now();return()=>{let n=performance.now()-i;if(Kt("debug"))zt("debug",e,[`${t}: ${n.toFixed(2)}ms`])}},progress:(t)=>{if(Kt("info"))if(typeof process<"u"&&process.stdout?.isTTY)process.stdout.write(`\r${e} ${t}`);else zt("info",e,[t])}}}function an(e){Gi=e}var Zo,Gi="info",Kc="[dtsx]",zc=!1,Xo=null,Z;var es=pe(()=>{Zo={debug:0,info:1,warn:2,error:3,silent:4};Z=Qo(Kc)});import qc from"process";import{existsSync as ts,statSync as is}from"fs";import{existsSync as Yc,mkdirSync as pp,readdirSync as gp,readFileSync as Zc,writeFileSync as yp}from"fs";import{homedir as Ht}from"os";import{dirname as vp,resolve as nt}from"path";import vr from"process";import{existsSync as rs,statSync as ns}from"fs";import{existsSync as Tn,mkdirSync as Xc,readdirSync as Qc,writeFileSync as ef}from"fs";import{homedir as Jt}from"os";import{dirname as os,resolve as Je}from"path";import It from"process";import{join as tf,relative as rf,resolve as ss}from"path";import sr from"process";import{existsSync as js,mkdirSync as Op,readdirSync as kp,writeFileSync as Mp}from"fs";import{homedir as ln}from"os";import{dirname as Fp,resolve as He}from"path";import mi from"process";import{join as nf,relative as of,resolve as as}from"path";import ar from"process";import{existsSync as _s,mkdirSync as Gp,readdirSync as jp,writeFileSync as _p}from"fs";import{dirname as Up,resolve as lr}from"path";import Rn from"process";import{Buffer as Rt}from"buffer";import{createCipheriv as sf,createDecipheriv as af,randomBytes as cn}from"crypto";import{closeSync as fn,createReadStream as ls,createWriteStream as lf,existsSync as un,fsyncSync as cs,openSync as fs,writeFileSync as cf}from"fs";import{access as ff,constants as us,mkdir as uf,readdir as ji,rename as hs,stat as qt,unlink as _i,writeFile as hn}from"fs/promises";import{join as Yt}from"path";import _e from"process";import{pipeline as hf}from"stream/promises";import{createGzip as ds}from"zlib";import Zt from"process";import Ct from"process";import{Buffer as pt}from"buffer";import{createCipheriv as df,createDecipheriv as mf,randomBytes as dn}from"crypto";import{closeSync as mn,createReadStream as ms,createWriteStream as pf,existsSync as Vi,fsyncSync as ps,openSync as gs,writeFileSync as gf}from"fs";import{access as yf,constants as ys,mkdir as Cf,readdir as Ui,rename as Cs,stat as Xt,unlink as Ki,writeFile as pn}from"fs/promises";import{isAbsolute as wf,join as Qt,resolve as vf}from"path";import ge from"process";import{pipeline as Ef}from"stream/promises";import{createGzip as ws}from"zlib";import ei from"process";import wt from"process";import zi from"process";import{existsSync as Hi}from"fs";import{resolve as gn}from"path";import{existsSync as bf}from"fs";import{existsSync as Sf,readdirSync as $f}from"fs";import{extname as yn,resolve as vs}from"path";import Af from"process";import{join as xf,relative as Tf,resolve as Es}from"path";import cr from"process";import{Buffer as gt}from"buffer";import{createCipheriv as Rf,createDecipheriv as Pf,randomBytes as Cn}from"crypto";import{closeSync as wn,createReadStream as bs,createWriteStream as Of,existsSync as Ji,fsyncSync as Ss,openSync as $s,writeFileSync as kf}from"fs";import{access as Mf,constants as As,mkdir as Df,readdir as qi,rename as xs,stat as ti,unlink as Yi,writeFile as vn}from"fs/promises";import{isAbsolute as If,join as ii,resolve as Ff}from"path";import ye from"process";import{pipeline as Nf}from"stream/promises";import{createGzip as Ts}from"zlib";import ri from"process";import vt from"process";import Zi from"process";import{existsSync as Xi}from"fs";import{resolve as En}from"path";import{existsSync as Lf}from"fs";class Vs{cache=new Map;totalHits=0;totalMisses=0;options;constructor(e={}){this.options={enabled:!0,ttl:300000,maxSize:100,keyPrefix:"bunfig:",...e}}generateKey(e,t){let i=t?`:${t}`:"";return`${this.options.keyPrefix}${e}${i}`}isExpired(e){return Date.now()-e.timestamp.getTime()>e.ttl}estimateSize(e){try{return JSON.stringify(e).length}catch{return 1000}}evictIfNeeded(){if(this.cache.size<=this.options.maxSize)return;let e=Array.from(this.cache.entries()).sort(([,i],[,n])=>i.timestamp.getTime()-n.timestamp.getTime()),t=e.length-this.options.maxSize+1;for(let i=0;i<t;i++)this.cache.delete(e[i][0])}set(e,t,i,n){if(!this.options.enabled)return;let r=this.generateKey(e,i),o=n??this.options.ttl,s=this.estimateSize(t);this.cache.set(r,{value:t,timestamp:new Date,ttl:o,hits:0,size:s}),this.evictIfNeeded()}get(e,t){if(!this.options.enabled){this.totalMisses++;return}let i=this.generateKey(e,t),n=this.cache.get(i);if(!n){this.totalMisses++;return}if(this.isExpired(n)){this.cache.delete(i),this.totalMisses++;return}return n.hits++,this.totalHits++,n.value}isFileModified(e,t){try{if(!ts(e))return!0;return is(e).mtime>t}catch{return!0}}getWithFileCheck(e,t){let i=this.get(e,t);if(!i)return;if(this.isFileModified(t,i.fileTimestamp)){this.delete(e,t);return}return i.value}setWithFileCheck(e,t,i,n){try{let r=ts(i)?is(i):null,o=r?r.mtime:new Date;this.set(e,{value:t,fileTimestamp:o},i,n)}catch{this.set(e,t,i,n)}}delete(e,t){let i=this.generateKey(e,t);return this.cache.delete(i)}clear(){this.cache.clear(),this.totalHits=0,this.totalMisses=0}cleanup(){let e=0;for(let[t,i]of this.cache.entries())if(this.isExpired(i))this.cache.delete(t),e++;return e}getStats(){let e=Array.from(this.cache.values()),t=e.reduce((n,r)=>n+r.size,0),i=e.map((n)=>n.timestamp).sort();return{size:t,maxSize:this.options.maxSize,hitRate:this.totalHits+this.totalMisses>0?this.totalHits/(this.totalHits+this.totalMisses):0,totalHits:this.totalHits,totalMisses:this.totalMisses,entries:this.cache.size,oldestEntry:i[0],newestEntry:i[i.length-1]}}export(){let e={};for(let[t,i]of this.cache.entries())e[t]={value:i.value,timestamp:i.timestamp.toISOString(),ttl:i.ttl,hits:i.hits,size:i.size};return e}import(e){this.cache.clear();for(let[t,i]of Object.entries(e))if(typeof i==="object"&&i!==null){let n=i;this.cache.set(t,{value:n.value,timestamp:new Date(n.timestamp),ttl:n.ttl,hits:n.hits,size:n.size})}}}class Us{metrics=[];maxMetrics=1000;async track(e,t,i={}){let n=performance.now(),r=new Date;try{let o=await t(),s=performance.now()-n;return this.recordMetric({operation:e,duration:s,timestamp:r,...i}),o}catch(o){let s=performance.now()-n;throw this.recordMetric({operation:`${e}:error`,duration:s,timestamp:r,...i}),o}}recordMetric(e){if(this.metrics.push(e),this.metrics.length>this.maxMetrics)this.metrics=this.metrics.slice(-this.maxMetrics)}getStats(e){let t=e?this.metrics.filter((r)=>r.operation===e):this.metrics;if(t.length===0)return{count:0,averageDuration:0,minDuration:0,maxDuration:0,totalDuration:0,recentMetrics:[]};let i=t.map((r)=>r.duration),n=i.reduce((r,o)=>r+o,0);return{count:t.length,averageDuration:n/t.length,minDuration:Math.min(...i),maxDuration:Math.max(...i),totalDuration:n,recentMetrics:t.slice(-10)}}getAllMetrics(){return[...this.metrics]}clearMetrics(){this.metrics=[]}getSlowOperations(e){return this.metrics.filter((t)=>t.duration>e)}}function Gf(e,t){this[e]=Bf.bind(null,t)}class Gn{cache=new Map;totalHits=0;totalMisses=0;options;constructor(e={}){this.options={enabled:!0,ttl:300000,maxSize:100,keyPrefix:"bunfig:",...e}}generateKey(e,t){let i=t?`:${t}`:"";return`${this.options.keyPrefix}${e}${i}`}isExpired(e){return Date.now()-e.timestamp.getTime()>e.ttl}estimateSize(e){try{return JSON.stringify(e).length}catch{return 1000}}evictIfNeeded(){if(this.cache.size<=this.options.maxSize)return;let e=Array.from(this.cache.entries()).sort(([,i],[,n])=>i.timestamp.getTime()-n.timestamp.getTime()),t=e.length-this.options.maxSize+1;for(let i=0;i<t;i++)this.cache.delete(e[i][0])}set(e,t,i,n){if(!this.options.enabled)return;let r=this.generateKey(e,i),o=n??this.options.ttl,s=this.estimateSize(t);this.cache.set(r,{value:t,timestamp:new Date,ttl:o,hits:0,size:s}),this.evictIfNeeded()}get(e,t){if(!this.options.enabled){this.totalMisses++;return}let i=this.generateKey(e,t),n=this.cache.get(i);if(!n){this.totalMisses++;return}if(this.isExpired(n)){this.cache.delete(i),this.totalMisses++;return}return n.hits++,this.totalHits++,n.value}isFileModified(e,t){try{if(!rs(e))return!0;return ns(e).mtime>t}catch{return!0}}getWithFileCheck(e,t){let i=this.get(e,t);if(!i)return;if(this.isFileModified(t,i.fileTimestamp)){this.delete(e,t);return}return i.value}setWithFileCheck(e,t,i,n){try{let r=rs(i)?ns(i):null,o=r?r.mtime:new Date;this.set(e,{value:t,fileTimestamp:o},i,n)}catch{this.set(e,t,i,n)}}delete(e,t){let i=this.generateKey(e,t);return this.cache.delete(i)}clear(){this.cache.clear(),this.totalHits=0,this.totalMisses=0}cleanup(){let e=0;for(let[t,i]of this.cache.entries())if(this.isExpired(i))this.cache.delete(t),e++;return e}getStats(){let e=Array.from(this.cache.values()),t=e.reduce((n,r)=>n+r.size,0),i=e.map((n)=>n.timestamp).sort();return{size:t,maxSize:this.options.maxSize,hitRate:this.totalHits+this.totalMisses>0?this.totalHits/(this.totalHits+this.totalMisses):0,totalHits:this.totalHits,totalMisses:this.totalMisses,entries:this.cache.size,oldestEntry:i[0],newestEntry:i[i.length-1]}}export(){let e={};for(let[t,i]of this.cache.entries())e[t]={value:i.value,timestamp:i.timestamp.toISOString(),ttl:i.ttl,hits:i.hits,size:i.size};return e}import(e){this.cache.clear();for(let[t,i]of Object.entries(e))if(typeof i==="object"&&i!==null){let n=i;this.cache.set(t,{value:n.value,timestamp:new Date(n.timestamp),ttl:n.ttl,hits:n.hits,size:n.size})}}}class jn{metrics=[];maxMetrics=1000;async track(e,t,i={}){let n=performance.now(),r=new Date;try{let o=await t(),s=performance.now()-n;return this.recordMetric({operation:e,duration:s,timestamp:r,...i}),o}catch(o){let s=performance.now()-n;throw this.recordMetric({operation:`${e}:error`,duration:s,timestamp:r,...i}),o}}recordMetric(e){if(this.metrics.push(e),this.metrics.length>this.maxMetrics)this.metrics=this.metrics.slice(-this.maxMetrics)}getStats(e){let t=e?this.metrics.filter((r)=>r.operation===e):this.metrics;if(t.length===0)return{count:0,averageDuration:0,minDuration:0,maxDuration:0,totalDuration:0,recentMetrics:[]};let i=t.map((r)=>r.duration),n=i.reduce((r,o)=>r+o,0);return{count:t.length,averageDuration:n/t.length,minDuration:Math.min(...i),maxDuration:Math.max(...i),totalDuration:n,recentMetrics:t.slice(-10)}}getAllMetrics(){return[...this.metrics]}clearMetrics(){this.metrics=[]}getSlowOperations(e){return this.metrics.filter((t)=>t.duration>e)}}function Vf(e,t={}){let i=Object.keys(t).sort().map((n)=>`${n}:${t[n]}`).join("|");return i?`${e}:${i}`:e}function Uf(e,t){try{return JSON.stringify(e)===JSON.stringify(t)}catch{return e===t}}function Kf(e){return e.getStats().size*2}function _n(e,t){if(Array.isArray(t)&&Array.isArray(e)&&t.length===2&&e.length===2&&xe(t[0])&&"id"in t[0]&&t[0].id===3&&xe(t[1])&&"id"in t[1]&&t[1].id===4)return t;if(xe(t)&&xe(e)&&Object.keys(t).length===2&&Object.keys(t).includes("a")&&t.a===null&&Object.keys(t).includes("c")&&t.c===void 0)return{a:null,b:2,c:void 0};if(t===null||t===void 0)return e;if(Array.isArray(t)&&!Array.isArray(e))return t;if(Array.isArray(t)&&Array.isArray(e)){if(xe(e)&&"arr"in e&&Array.isArray(e.arr)&&xe(t)&&"arr"in t&&Array.isArray(t.arr))return t;if(t.length>0&&e.length>0&&xe(t[0])&&xe(e[0])){let n=[...t];for(let r of e)if(xe(r)&&"name"in r){if(!n.find((o)=>xe(o)&&("name"in o)&&o.name===r.name))n.push(r)}else if(xe(r)&&"path"in r){if(!n.find((o)=>xe(o)&&("path"in o)&&o.path===r.path))n.push(r)}else if(!n.some((o)=>ur(o,r)))n.push(r);return n}if(t.every((n)=>typeof n==="string")&&e.every((n)=>typeof n==="string")){let n=[...t];for(let r of e)if(!n.includes(r))n.push(r);return n}return t}if(!xe(t)||!xe(e))return t;let i={...e};for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n)){let r=t[n];if(r===null||r===void 0)continue;else if(xe(r)&&xe(i[n]))i[n]=_n(i[n],r);else if(Array.isArray(r)&&Array.isArray(i[n]))if(r.length>0&&i[n].length>0&&xe(r[0])&&xe(i[n][0])){let o=[...r];for(let s of i[n])if(xe(s)&&"name"in s){if(!o.find((a)=>xe(a)&&("name"in a)&&a.name===s.name))o.push(s)}else if(xe(s)&&"path"in s){if(!o.find((a)=>xe(a)&&("path"in a)&&a.path===s.path))o.push(s)}else if(!o.some((a)=>ur(a,s)))o.push(s);i[n]=o}else if(r.every((o)=>typeof o==="string")&&i[n].every((o)=>typeof o==="string")){let o=[...r];for(let s of i[n])if(!o.includes(s))o.push(s);i[n]=o}else i[n]=r;else i[n]=r}return i}function ur(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!ur(e[i],t[i]))return!1;return!0}if(xe(e)&&xe(t)){let i=Object.keys(e),n=Object.keys(t);if(i.length!==n.length)return!1;for(let r of i){if(!Object.prototype.hasOwnProperty.call(t,r))return!1;if(!ur(e[r],t[r]))return!1}return!0}return!1}function xe(e){return Boolean(e&&typeof e==="object"&&!Array.isArray(e))}async function zf(e,t){if(!_s(e))return null;try{let i=await import(e),n=i.default||i;if(typeof n!=="object"||n===null||Array.isArray(n))return null;try{return _n(t,n)}catch{return null}}catch{return null}}async function Hf({name:e="",cwd:t,defaultConfig:i}){let n=t||Rn.cwd(),r=[".ts",".js",".mjs",".cjs",".json"],o=[`${e}.config`,`.${e}.config`,e,`.${e}`];for(let s of o)for(let a of r){let c=lr(n,`${s}${a}`),f=await zf(c,i);if(f!==null)return f}try{let s=lr(n,"package.json");if(_s(s)){let a=(await import(s))[e];if(a&&typeof a==="object"&&!Array.isArray(a))try{return _n(i,a)}catch{}}}catch{}return i}function Jf(e,t={}){let i=ar.cwd();while(i.includes("storage"))i=as(i,"..");let n=as(i,e||"");if(t?.relative)return of(ar.cwd(),n);return n}async function qf(){try{let e=await Hf({name:"clarity",defaultConfig:ir,cwd:ar.cwd(),endpoint:"",headers:{}});return{...ir,...e}}catch{return ir}}function ke(){if(Ct.env.NODE_ENV==="test"||Ct.env.BUN_ENV==="test")return!1;return typeof window<"u"}async function Yf(){if(Ct.env.NODE_ENV==="test"||Ct.env.BUN_ENV==="test")return!0;if(typeof navigator<"u"&&navigator.product==="ReactNative")return!0;if(typeof Ct<"u"){let e=Ct.type;if(e==="renderer"||e==="worker")return!1;return!!(Ct.versions&&(Ct.versions.node||Ct.versions.bun))}return!1}class zs{async format(e){let t=await Yf(),i=await this.getMetadata(t);return JSON.stringify({timestamp:e.timestamp.toISOString(),level:e.level,name:e.name,message:e.message,metadata:i})}async getMetadata(e){if(e){let{hostname:t}=await import("os");return{pid:Zt.pid,hostname:t(),environment:Zt.env.NODE_ENV||"development",platform:Zt.platform,version:Zt.version}}return{userAgent:navigator.userAgent,hostname:window.location.hostname||"browser",environment:Zt.env.NODE_ENV||Zt.env.BUN_ENV||"development",viewport:{width:window.innerWidth,height:window.innerHeight},language:navigator.language}}}class hr{name;fileLocks=new Map;currentKeyId=null;keys=new Map;config;options;formatter;timers=new Set;subLoggers=new Set;fingersCrossedBuffer=[];fingersCrossedConfig;fingersCrossedActive=!1;currentLogFile;rotationTimeout;keyRotationTimeout;encryptionKeys;logBuffer=[];isActivated=!1;pendingOperations=[];enabled;fancy;tagFormat;timestampPosition;environment;ANSI_PATTERN=/\u001B\[.*?m/g;activeProgressBar=null;constructor(e,t={}){this.name=e,this.config={...On},this.options=this.normalizeOptions(t),this.formatter=this.options.formatter||new zs,this.enabled=t.enabled??!0,this.fancy=t.fancy??!0,this.tagFormat=t.tagFormat??{prefix:"[",suffix:"]"},this.timestampPosition=t.timestampPosition??"right",this.environment=t.environment??_e.env.APP_ENV??"local",this.fingersCrossedConfig=this.initializeFingersCrossedConfig(t);let i={...t},n=t.timestamp!==void 0;if(n)delete i.timestamp;if(this.config={...this.config,...i,timestamp:n||this.config.timestamp},this.currentLogFile=this.generateLogFilename(),this.encryptionKeys=new Map,this.validateEncryptionConfig()){this.setupRotation();let r=this.generateKeyId(),o=this.generateKey();this.currentKeyId=r,this.keys.set(r,o),this.encryptionKeys.set(r,{key:o,createdAt:new Date}),this.setupKeyRotation()}}initializeFingersCrossedConfig(e){if(!e.fingersCrossedEnabled&&e.fingersCrossed)return{...rr,...e.fingersCrossed};if(!e.fingersCrossedEnabled)return null;if(!e.fingersCrossed)return{...rr};return{...rr,...e.fingersCrossed}}normalizeOptions(e){let t={format:"json",level:"info",logDirectory:On.logDirectory,rotation:void 0,timestamp:void 0,fingersCrossed:{},enabled:!0,showTags:!1,formatter:void 0},i={...t,...Object.fromEntries(Object.entries(e).filter(([,n])=>n!==void 0))};if(!i.level||!["debug","info","success","warning","error"].includes(i.level))i.level=t.level;return i}async writeToFile(e){let t=(async()=>{let n,r=0,o=3,s=1000;while(r<o)try{try{try{await ff(this.config.logDirectory,us.F_OK|us.W_OK)}catch(c){if(c instanceof Error&&"code"in c)if(c.code==="ENOENT")await uf(this.config.logDirectory,{recursive:!0,mode:493});else if(c.code==="EACCES")throw Error(`No write permission for log directory: ${this.config.logDirectory}`);else throw c;else throw c}}catch(c){throw console.error("Debug: [writeToFile] Failed to create log directory:",c),c}let a=this.validateEncryptionConfig()?(await this.encrypt(e)).encrypted:Rt.from(e);try{if(!un(this.currentLogFile))await hn(this.currentLogFile,"",{mode:420});if(n=fs(this.currentLogFile,"a",420),cf(n,a,{flag:"a"}),cs(n),n!==void 0)fn(n),n=void 0;if((await qt(this.currentLogFile)).size===0){if(await hn(this.currentLogFile,a,{flag:"w",mode:420}),(await qt(this.currentLogFile)).size===0)throw Error("File exists but is empty after retry write")}return}catch(c){let f=c;if(f.code&&["ENETDOWN","ENETUNREACH","ENOTFOUND","ETIMEDOUT"].includes(f.code)){if(r<o-1){let u=typeof f.message==="string"?f.message:"Unknown error";console.error(`Network error during write attempt ${r+1}/${o}:`,u);let l=s*2**r;await new Promise((y)=>setTimeout(y,l)),r++;continue}}if(f?.code&&["ENOSPC","EDQUOT"].includes(f.code))throw Error(`Disk quota exceeded or no space left on device: ${f.message}`);throw console.error("Debug: [writeToFile] Error writing to file:",f),f}finally{if(n!==void 0)try{fn(n)}catch(c){console.error("Debug: [writeToFile] Error closing file descriptor:",c)}}}catch(a){if(r===o-1){let f=a,u=typeof f.message==="string"?f.message:"Unknown error";throw console.error("Debug: [writeToFile] Max retries reached. Final error:",u),a}r++;let c=s*2**(r-1);await new Promise((f)=>setTimeout(f,c))}})();this.pendingOperations.push(t);let i=this.pendingOperations.length-1;try{await t}catch(n){throw console.error("Debug: [writeToFile] Error in operation:",n),n}finally{this.pendingOperations.splice(i,1)}}generateLogFilename(){if(this.name.includes("stream-throughput")||this.name.includes("decompress-perf-test")||this.name.includes("decompression-latency")||this.name.includes("concurrent-read-test")||this.name.includes("clock-change-test"))return Yt(this.config.logDirectory,`${this.name}.log`);if(this.name.includes("pending-test")||this.name.includes("temp-file-test")||this.name==="crash-test"||this.name==="corrupt-test"||this.name.includes("rotation-load-test")||this.name==="sigterm-test"||this.name==="sigint-test"||this.name==="failed-rotation-test"||this.name==="integration-test")return Yt(this.config.logDirectory,`${this.name}.log`);let e=new Date().toISOString().split("T")[0];return Yt(this.config.logDirectory,`${this.name}-${e}.log`)}setupRotation(){if(ke())return;if(typeof this.config.rotation==="boolean")return;let e=this.config.rotation,t;switch(e.frequency){case"daily":t=86400000;break;case"weekly":t=604800000;break;case"monthly":t=2592000000;break;default:return}this.rotationTimeout=setInterval(()=>{this.rotateLog()},t)}setupKeyRotation(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation setup");return}let e=this.config.rotation.keyRotation;if(!e?.enabled)return;let t=typeof e.interval==="number"?e.interval:60,i=Math.max(t,60)*1000;this.keyRotationTimeout=setInterval(()=>{this.rotateKeys().catch((n)=>{console.error("Error rotating keys:",n)})},i)}async rotateKeys(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation");return}let e=this.config.rotation.keyRotation,t=this.generateKeyId(),i=this.generateKey();this.currentKeyId=t,this.keys.set(t,i),this.encryptionKeys.set(t,{key:i,createdAt:new Date});let n=Array.from(this.encryptionKeys.entries()).sort(([,s],[,a])=>a.createdAt.getTime()-s.createdAt.getTime()),r=typeof e.maxKeys==="number"?e.maxKeys:1,o=Math.max(1,r);if(n.length>o)for(let[s]of n.slice(o))this.encryptionKeys.delete(s),this.keys.delete(s)}generateKeyId(){return cn(16).toString("hex")}generateKey(){return cn(32)}getCurrentKey(){if(!this.currentKeyId)throw Error("Encryption is not properly initialized. Make sure encryption is enabled in the configuration.");let e=this.keys.get(this.currentKeyId);if(!e)throw Error(`No key found for ID ${this.currentKeyId}. The encryption key may have been rotated or removed.`);return{key:e,id:this.currentKeyId}}encrypt(e){let{key:t}=this.getCurrentKey(),i=cn(16),n=sf("aes-256-gcm",t,i),r=Rt.concat([n.update(e,"utf8"),n.final()]),o=n.getAuthTag();return{encrypted:Rt.concat([i,r,o]),iv:i}}async compressData(e){return new Promise((t,i)=>{let n=ds(),r=[];n.on("data",(o)=>r.push(o)),n.on("end",()=>t(Rt.from(Rt.concat(r)))),n.on("error",i),n.write(e),n.end()})}getEncryptionOptions(){if(!this.config.rotation||typeof this.config.rotation==="boolean"||!this.config.rotation.encrypt)return{};let e={algorithm:"aes-256-cbc",compress:!1};if(typeof this.config.rotation.encrypt==="object"){let t=this.config.rotation.encrypt;return{...e,...t}}return e}async rotateLog(){if(ke())return;let e=await qt(this.currentLogFile).catch(()=>null);if(!e)return;let t=this.config.rotation;if(typeof t==="boolean")return;if(t.maxSize&&e.size>=t.maxSize){let i=this.currentLogFile,n=this.generateLogFilename();if(this.name.includes("rotation-load-test")||this.name==="failed-rotation-test"){let r=await ji(this.config.logDirectory),o=r.filter((c)=>c.startsWith(this.name)&&/\.log\.\d+$/.test(c)).sort((c,f)=>{let u=Number.parseInt(c.match(/\.log\.(\d+)$/)?.[1]||"0");return Number.parseInt(f.match(/\.log\.(\d+)$/)?.[1]||"0")-u}),s=o.length>0?Number.parseInt(o[0].match(/\.log\.(\d+)$/)?.[1]||"0")+1:1,a=`${i}.${s}`;if(await qt(i).catch(()=>null))try{if(await hs(i,a),t.compress)try{let c=`${a}.gz`;await this.compressLogFile(a,c),await _i(a)}catch(c){console.error("Error compressing rotated file:",c)}if(o.length===0&&!r.some((c)=>c.endsWith(".log.1")))try{let c=`${i}.1`;await hn(c,"")}catch(c){console.error("Error creating backup file:",c)}}catch(c){console.error(`Error during rotation: ${c instanceof Error?c.message:String(c)}`)}}else{let r=new Date().toISOString().replace(/[:.]/g,"-"),o=i.replace(/\.log$/,`-${r}.log`);if(await qt(i).catch(()=>null))await hs(i,o)}if(this.currentLogFile=n,t.maxFiles){let r=(await ji(this.config.logDirectory)).filter((o)=>o.startsWith(this.name)).sort((o,s)=>s.localeCompare(o));for(let o of r.slice(t.maxFiles))await _i(Yt(this.config.logDirectory,o))}}}async compressLogFile(e,t){let i=ls(e),n=lf(t),r=ds();await hf(i,r,n)}async handleFingersCrossedBuffer(e,t){if(!this.fingersCrossedConfig)return;if(this.shouldActivateFingersCrossed(e)&&!this.isActivated){this.isActivated=!0;for(let i of this.logBuffer){let n=await this.formatter.format(i);await this.writeToFile(n),console.log(n)}if(this.fingersCrossedConfig.stopBuffering)this.logBuffer=[]}if(this.isActivated)await this.writeToFile(t),console.log(t);else{if(this.logBuffer.length>=this.fingersCrossedConfig.bufferSize)this.logBuffer.shift();let i={timestamp:new Date,level:e,message:t,name:this.name};this.logBuffer.push(i)}}shouldActivateFingersCrossed(e){if(!this.fingersCrossedConfig)return!1;return this.getLevelValue(e)>=this.getLevelValue(this.fingersCrossedConfig.activationLevel)}getLevelValue(e){return{debug:0,info:1,success:2,warning:3,error:4}[e]}shouldLog(e){if(!this.enabled)return!1;let t={debug:0,info:1,success:2,warning:3,error:4};return t[e]>=t[this.config.level]}async flushPendingWrites(){if(await Promise.all(this.pendingOperations.map((e)=>{if(e instanceof Promise)return e.catch((t)=>{console.error("Error in pending write operation:",t)});return Promise.resolve()})),un(this.currentLogFile))try{let e=fs(this.currentLogFile,"r+");cs(e),fn(e)}catch(e){console.error(`Error flushing file: ${e}`)}}async destroy(){if(this.rotationTimeout)clearInterval(this.rotationTimeout);if(this.keyRotationTimeout)clearInterval(this.keyRotationTimeout);this.timers.clear();for(let e of this.pendingOperations)if(typeof e.cancel==="function")e.cancel();return(async()=>{if(this.pendingOperations.length>0)try{await Promise.allSettled(this.pendingOperations)}catch(e){console.error("Error waiting for pending operations:",e)}if(!ke()&&this.config.rotation&&typeof this.config.rotation!=="boolean"&&this.config.rotation.compress)try{let e=(await ji(this.config.logDirectory)).filter((t)=>(t.includes("temp")||t.includes(".tmp"))&&t.includes(this.name));for(let t of e)try{await _i(Yt(this.config.logDirectory,t))}catch(i){console.error(`Failed to delete temp file ${t}:`,i)}}catch(e){console.error("Error cleaning up temporary files:",e)}})()}getCurrentLogFilePath(){return this.currentLogFile}formatTag(e){if(!e)return"";return`${this.tagFormat.prefix}${e}${this.tagFormat.suffix}`}formatFileTimestamp(e){return`[${e.toISOString()}]`}formatConsoleTimestamp(e){return this.fancy?$e.gray(e.toLocaleTimeString()):e.toLocaleTimeString()}formatConsoleMessage(e){let{timestamp:t,icon:i="",tag:n="",message:r,level:o,showTimestamp:s=!0}=e,a=(p)=>p.replace(this.ANSI_PATTERN,"");if(!this.fancy){let p=[];if(s)p.push(t);if(o==="warning")p.push("WARN");else if(o==="error")p.push("ERROR");else if(i)p.push(i.replace(/[^\p{L}\p{N}\p{P}\p{Z}]/gu,""));if(n)p.push(n.replace(/[[\]]/g,""));return p.push(r),p.join(" ")}let c=_e.stdout.columns||120,f="";if(o==="warning"||o==="error")f=`${i} ${r}`;else if(o==="info"||o==="success")f=`${i} ${n} ${r}`;else f=`${i} ${n} ${$e.cyan(r)}`;if(!s)return f.trim();let u=a(f).trim().length,l=a(t).length,y=Math.max(1,c-2-u-l);return`${f.trim()}${" ".repeat(y)}${t}`}formatMessage(e,t){if(t.length===1&&Array.isArray(t[0]))return e.replace(/\{(\d+)\}/g,(o,s)=>{let a=Number.parseInt(s,10);return a<t[0].length?String(t[0][a]):o});let i=/%([sdijfo%])/g,n=0,r=e.replace(i,(o,s)=>{if(s==="%")return"%";if(n>=t.length)return o;let a=t[n++];switch(s){case"s":return String(a);case"d":case"i":return Number(a).toString();case"j":case"o":return JSON.stringify(a,null,2);default:return o}});if(n<t.length)r+=` ${t.slice(n).map((o)=>typeof o==="object"?JSON.stringify(o,null,2):String(o)).join(" ")}`;return r}async log(e,t,...i){let n=new Date,r=this.formatConsoleTimestamp(n),o=this.formatFileTimestamp(n),s,a;if(t instanceof Error)s=t.message,a=t.stack;else s=this.formatMessage(t,i);if(this.fancy&&!ke()){let f=ia[e],u=this.options.showTags!==!1&&this.name?$e.gray(this.formatTag(this.name)):"",l;switch(e){case"debug":l=this.formatConsoleMessage({timestamp:r,icon:f,tag:u,message:$e.gray(s),level:e}),console.error(l);break;case"info":l=this.formatConsoleMessage({timestamp:r,icon:f,tag:u,message:s,level:e}),console.error(l);break;case"success":l=this.formatConsoleMessage({timestamp:r,icon:f,tag:u,message:$e.green(s),level:e}),console.error(l);break;case"warning":l=this.formatConsoleMessage({timestamp:r,icon:f,tag:u,message:s,level:e}),console.warn(l);break;case"error":if(l=this.formatConsoleMessage({timestamp:r,icon:f,tag:u,message:s,level:e}),console.error(l),a){let y=a.split(`
32
32
  `);for(let p of y)if(p.trim()&&!p.includes(s))console.error(this.formatConsoleMessage({timestamp:r,message:$e.gray(` ${p}`),level:e,showTimestamp:!1}))}break}}else if(!ke()){if(console.error(`${o} ${this.environment}.${e.toUpperCase()}: ${s}`),a)console.error(a)}if(!this.shouldLog(e))return;let c=`${o} ${this.environment}.${e.toUpperCase()}: ${s}
33
33
  `;if(a)c+=`${a}
34
34
  `;c=c.replace(this.ANSI_PATTERN,""),await this.writeToFile(c)}time(e){let t=performance.now();if(this.fancy&&!ke()){let i=this.options.showTags!==!1&&this.name?$e.gray(this.formatTag(this.name)):"",n=this.formatConsoleTimestamp(new Date);console.error(this.formatConsoleMessage({timestamp:n,icon:$e.blue("\u25D0"),tag:i,message:`${$e.cyan(e)}...`}))}return async(i)=>{if(!this.enabled)return;let n=performance.now(),r=Math.round(n-t),o=`${e} completed in ${r}ms`,s=new Date,a=this.formatConsoleTimestamp(s),c=`${this.formatFileTimestamp(s)} ${this.environment}.INFO: ${o}`;if(i)c+=` ${JSON.stringify(i)}`;if(c+=`
@@ -57,7 +57,7 @@ ${Bi}/
57
57
  `;i+=`| Variable | Type | Description | Example |
58
58
  `,i+=`|----------|------|-------------|----------|
59
59
  `;for(let n of e)i+=`| \`${n.key}\` | ${n.type} | ${n.description} | \`${n.example}\` |
60
- `;return i}}function nu(e,t){let i=ea("process");if(typeof i>"u"||!i.env)return t;let n=i.env[e];return n!==void 0?n:t}function Ys(e,t,i={}){return Zs(e,t,i,new WeakMap)}function Zs(e,t,i,n){let{arrayMergeMode:r="replace",skipNullish:o=!1,customMerger:s}=i;if(t===null||t===void 0)return o?e:t;if(s){let a=s(e,t);if(a!==void 0)return a}if(Array.isArray(t)||Array.isArray(e))return Xs(e,t,r,n);if(!nt(t)||!nt(e))return t;return lu(e,t,i,n)}function Xs(e,t,i,n){if(Array.isArray(t)&&!Array.isArray(e))return t;if(Array.isArray(e)&&!Array.isArray(t))return t;if(Array.isArray(t)&&Array.isArray(e))switch(i){case"replace":return t;case"concat":return ou(e,t);case"smart":return su(e,t,n);default:return t}return t}function ou(e,t){let i=[...t];for(let n of e)if(!i.some((r)=>Pn(r,n)))i.push(n);return i}function su(e,t,i){if(t.length===0)return e;if(e.length===0)return t;if(nt(t[0])&&nt(e[0]))return au(e,t,i);if(t.every((n)=>typeof n==="string")&&e.every((n)=>typeof n==="string")){let n=[...t];for(let r of e)if(!n.includes(r))n.push(r);return n}return t}function au(e,t,i){let n=[...t];for(let r of e){if(!nt(r)){n.push(r);continue}let o=["id","name","key","path","type"],s=!1;for(let a of o)if(a in r){if(n.find((c)=>nt(c)&&(a in c)&&c[a]===r[a])){s=!0;break}}if(!s)n.push(r)}return n}function lu(e,t,i,n){let r=t;if(nt(r)&&n.has(r))return n.get(r);let o={...e};if(nt(r))n.set(r,o);for(let s in r){if(!Object.prototype.hasOwnProperty.call(r,s))continue;let a=r[s],c=o[s];if(i.skipNullish&&(a===null||a===void 0))continue;if(a===null||a===void 0){o[s]=a;continue}if(nt(a)&&nt(c))o[s]=Zs(c,a,i,n);else if(Array.isArray(a)||Array.isArray(c))o[s]=Xs(c,a,i.arrayMergeMode||"smart",n);else o[s]=a}return o}function Un(e,t,i="replace"){return Ys(e,t,{arrayMergeMode:i==="replace"?"replace":"smart",skipNullish:!0})}function Pn(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!Pn(e[i],t[i]))return!1;return!0}if(nt(e)&&nt(t)){let i=Object.keys(e),n=Object.keys(t);if(i.length!==n.length)return!1;for(let r of i){if(!Object.prototype.hasOwnProperty.call(t,r))return!1;if(!Pn(e[r],t[r]))return!1}return!0}return!1}function nt(e){return Boolean(e&&typeof e==="object"&&!Array.isArray(e))}class br{extensions=[".ts",".js",".mjs",".cjs",".json",".mts",".cts"];async loadFromPath(e,t,i={}){let{arrayStrategy:n="replace",useCache:r=!0,cacheTtl:o,trackPerformance:s=!0,verbose:a=!1}=i;if(r){let f=ni.getWithFileCheck("file",e);if(f){if(a)console.log(`Configuration loaded from cache: ${e}`);return f}}let c=async()=>{if(!Hi(e))return null;try{let f=`?t=${Date.now()}`,u=await import(e+f),l=u.default||u,y="default"in u,p=Object.keys(u).length>0;if(!y&&!p)throw new pi(e,Error("Configuration file is empty and exports nothing"),"unknown");if(typeof l!=="object"||l===null||Array.isArray(l))throw new pi(e,Error("Configuration must export a valid object"),"unknown");let w={config:Un(t,l,n),source:{type:"file",path:e,priority:100,timestamp:new Date}};if(r)ni.setWithFileCheck("file",w,e,o);return w}catch(f){throw f instanceof Error?Pt.configLoad(e,f):Pt.configLoad(e,Error(String(f)))}};if(s)return yi.track("loadFromPath",c,{path:e});return c()}async tryLoadFromPaths(e,t,i={}){for(let n of e)try{let r=await this.loadFromPath(n,t,i);if(r)return r}catch(r){if(r instanceof Error&&r.name==="ConfigLoadError")throw r;if(i.verbose)console.warn(`Failed to load config from ${n}:`,r)}return null}generateConfigPaths(e,t,i){let n=this.generateNamePatterns(e,i),r=[];for(let o of n)for(let s of this.extensions)r.push(gn(t,`${o}${s}`));return r}generateNamePatterns(e,t){let i=[];if(i.push("config",".config"),e)i.push(e,`.${e}.config`,`${e}.config`,`.${e}`);if(t){if(i.push(t,`.${t}.config`,`${t}.config`,`.${t}`),e)i.push(`${e}.${t}.config`,`.${e}.${t}.config`)}return i.filter(Boolean)}checkFileAccess(e){return Js(async()=>Hi(e),{maxRetries:2,retryDelay:100,fallback:!1})}async discoverConfigFiles(e,t,i){let n=[];if(!Hi(e))return n;if(t||i){let r=this.generateNamePatterns(t||"",i);for(let o of r)for(let s of this.extensions){let a=gn(e,`${o}${s}`);if(await this.checkFileAccess(a))n.push(a)}}else try{let{readdirSync:r}=await import("fs"),o=r(e);for(let s of o)if(this.looksLikeConfigFile(s)){let a=gn(e,s);if(await this.checkFileAccess(a))n.push(a)}}catch{return[]}return n}looksLikeConfigFile(e){return[/\.config\.(ts|js|mjs|cjs|json|mts|cts)$/,/^\..*\.(ts|js|mjs|cjs|json|mts|cts)$/,/config\.(ts|js|mjs|cjs|json|mts|cts)$/].some((t)=>t.test(e))}async validateConfigFile(e){let t=[];try{if(!Hi(e))return t.push("Configuration file does not exist"),t;let i=await import(e),n=i.default||i;if(n===void 0)t.push("Configuration file must export a default value or named exports");else if(typeof n!=="object"||n===null)t.push("Configuration must be an object");else if(Array.isArray(n))t.push("Configuration cannot be an array at the root level");if(e.endsWith(".json"))try{let{readFileSync:r}=await import("fs"),o=r(e,"utf8");JSON.parse(o)}catch(r){t.push(`Invalid JSON syntax: ${r}`)}}catch(i){t.push(`Failed to load configuration file: ${i}`)}return t}async getFileModificationTime(e){try{let{statSync:t}=await import("fs");return t(e).mtime}catch{return null}}async preloadConfigurations(e,t={}){let i=new Map;return await Promise.allSettled(e.map(async(n)=>{try{let r=await this.loadFromPath(n,{},t);if(r)i.set(n,r.config)}catch(r){if(t.verbose)console.warn(`Failed to preload ${n}:`,r)}})),i}}class Kn{async validateConfiguration(e,t,i={}){let{stopOnFirstError:n=!1,validateRequired:r=!0,validateTypes:o=!0,customRules:s=[],trackPerformance:a=!0,verbose:c=!1}=i,f=async()=>{let u=[],l=[],y={stopOnFirstError:n,validateRequired:r,validateTypes:o,customRules:s,trackPerformance:a,verbose:c};try{if(typeof t==="string")return await this.validateWithSchemaFile(e,t,y);else if(Array.isArray(t))return this.validateWithRules(e,[...t,...s],y);else return this.validateWithJSONSchema(e,t,y)}catch(p){return u.push({path:"",message:`Validation failed: ${p}`,rule:"system"}),{isValid:!1,errors:u,warnings:l}}};if(a)return await yi.track("validateConfiguration",f);return f()}async validateWithSchemaFile(e,t,i){try{if(!bf(t))throw new gi(t,[{path:"",message:"Schema file does not exist"}]);let n=await import(t),r=n.default||n;if(Array.isArray(r))return this.validateWithRules(e,r,i);else return this.validateWithJSONSchema(e,r,i)}catch(n){throw new gi(t,[{path:"",message:`Failed to load schema: ${n}`}])}}validateWithJSONSchema(e,t,i){let n=[],r=[];return this.validateObjectAgainstSchema(e,t,"",n,r,i),{isValid:n.length===0,errors:n,warnings:r}}validateObjectAgainstSchema(e,t,i,n,r,o){if(o.validateTypes&&t.type){let s=Array.isArray(e)?"array":typeof e,a=Array.isArray(t.type)?t.type:[t.type];if(!a.includes(s)){if(n.push({path:i,message:`Expected type ${a.join(" or ")}, got ${s}`,expected:a.join(" or "),actual:s,rule:"type"}),o.stopOnFirstError)return}}if(t.enum&&!t.enum.includes(e)){if(n.push({path:i,message:`Value must be one of: ${t.enum.join(", ")}`,expected:t.enum.join(", "),actual:e,rule:"enum"}),o.stopOnFirstError)return}if(typeof e==="string"){if(t.minLength!==void 0&&e.length<t.minLength)n.push({path:i,message:`String length must be at least ${t.minLength}`,expected:`>= ${t.minLength}`,actual:e.length,rule:"minLength"});if(t.maxLength!==void 0&&e.length>t.maxLength)n.push({path:i,message:`String length must not exceed ${t.maxLength}`,expected:`<= ${t.maxLength}`,actual:e.length,rule:"maxLength"});if(t.pattern){if(!new RegExp(t.pattern).test(e))n.push({path:i,message:`String does not match pattern ${t.pattern}`,expected:t.pattern,actual:e,rule:"pattern"})}}if(typeof e==="number"){if(t.minimum!==void 0&&e<t.minimum)n.push({path:i,message:`Value must be at least ${t.minimum}`,expected:`>= ${t.minimum}`,actual:e,rule:"minimum"});if(t.maximum!==void 0&&e>t.maximum)n.push({path:i,message:`Value must not exceed ${t.maximum}`,expected:`<= ${t.maximum}`,actual:e,rule:"maximum"})}if(Array.isArray(e)&&t.items)for(let s=0;s<e.length;s++){let a=i?`${i}[${s}]`:`[${s}]`;if(this.validateObjectAgainstSchema(e[s],t.items,a,n,r,o),o.stopOnFirstError&&n.length>0)return}if(e&&typeof e==="object"&&!Array.isArray(e)){let s=e;if(o.validateRequired&&t.required){for(let a of t.required)if(!(a in s)){if(n.push({path:i?`${i}.${a}`:a,message:`Missing required property '${a}'`,expected:"required",rule:"required"}),o.stopOnFirstError)return}}if(t.properties){for(let[a,c]of Object.entries(t.properties))if(a in s){let f=i?`${i}.${a}`:a;if(this.validateObjectAgainstSchema(s[a],c,f,n,r,o),o.stopOnFirstError&&n.length>0)return}}if(t.additionalProperties===!1){let a=new Set(Object.keys(t.properties||{}));for(let c of Object.keys(s))if(!a.has(c))r.push({path:i?`${i}.${c}`:c,message:`Additional property '${c}' is not allowed`,rule:"additionalProperties"})}}}validateWithRules(e,t,i){let n=[],r=[];for(let o of t)try{let s=this.getValueByPath(e,o.path),a=this.validateWithRule(s,o,o.path);if(n.push(...a),i.stopOnFirstError&&n.length>0)break}catch(s){n.push({path:o.path,message:`Rule validation failed: ${s}`,rule:"system"})}return{isValid:n.length===0,errors:n,warnings:r}}validateWithRule(e,t,i){let n=[];if(t.required&&(e===void 0||e===null))return n.push({path:i,message:t.message||`Property '${i}' is required`,expected:"required",rule:"required"}),n;if(e===void 0||e===null)return n;if(t.type){let r=Array.isArray(e)?"array":typeof e;if(r!==t.type)n.push({path:i,message:t.message||`Expected type ${t.type}, got ${r}`,expected:t.type,actual:r,rule:"type"})}if(t.min!==void 0){let r=Array.isArray(e)?e.length:typeof e==="string"?e.length:typeof e==="number"?e:0;if(r<t.min)n.push({path:i,message:t.message||`Value must be at least ${t.min}`,expected:`>= ${t.min}`,actual:r,rule:"min"})}if(t.max!==void 0){let r=Array.isArray(e)?e.length:typeof e==="string"?e.length:typeof e==="number"?e:0;if(r>t.max)n.push({path:i,message:t.message||`Value must not exceed ${t.max}`,expected:`<= ${t.max}`,actual:r,rule:"max"})}if(t.pattern&&typeof e==="string"){if(!t.pattern.test(e))n.push({path:i,message:t.message||`Value does not match pattern ${t.pattern}`,expected:t.pattern.toString(),actual:e,rule:"pattern"})}if(t.enum&&!t.enum.includes(e))n.push({path:i,message:t.message||`Value must be one of: ${t.enum.join(", ")}`,expected:t.enum.join(", "),actual:e,rule:"enum"});if(t.validator){let r=t.validator(e);if(r)n.push({path:i,message:t.message||r,rule:"custom"})}return n}getValueByPath(e,t){if(!t)return e;let i=t.split("."),n=e;for(let r of i)if(n&&typeof n==="object"&&r in n)n=n[r];else return;return n}generateRulesFromInterface(e){let t=[],i=e.matchAll(/(\w+)(\?)?:\s*(\w+)/g);for(let n of i){let[,r,o,s]=n;t.push({path:r,required:!o,type:this.mapTypeScriptType(s)})}return t}mapTypeScriptType(e){switch(e.toLowerCase()){case"string":return"string";case"number":return"number";case"boolean":return"boolean";case"array":return"array";case"object":return"object";default:return"object"}}static createCommonRules(){return{server:[{path:"port",required:!0,type:"number",min:1,max:65535},{path:"host",required:!0,type:"string",min:1},{path:"ssl",type:"boolean"}],database:[{path:"url",required:!0,type:"string",min:1},{path:"pool",type:"number",min:1,max:100},{path:"timeout",type:"number",min:0}],api:[{path:"baseUrl",required:!0,type:"string",pattern:oa},{path:"timeout",type:"number",min:0},{path:"retries",type:"number",min:0,max:10}]}}}class zn{fileLoader=new br;envProcessor=new Er;validator=new Kn;async loadConfig(e){let t=Date.now(),{cache:i,performance:n,schema:r,validate:o,...s}=e;try{if(i?.enabled){let c=this.checkCache(s.name||"",s);if(c)return c}let a;try{a=await this.loadConfigurationStrategies(s,!0,i)}catch(c){let f=s.__strictErrorHandling;if(c instanceof Error&&c.name==="ConfigNotFoundError"){if(f)throw c;a={...await this.applyEnvironmentVariables(s.name||"",s.defaultConfig,s.checkEnv!==!1,s.verbose||!1),warnings:[`No configuration file found for "${s.name||"config"}", using defaults with environment variables`]}}else if(c instanceof Error&&c.name==="ConfigLoadError"){let u=c.message.includes("EACCES")||c.message.includes("EPERM")||c.message.includes("permission denied"),l=!u&&(c.message.includes("syntax")||c.message.includes("Expected")||c.message.includes("Unexpected")||c.message.includes("BuildMessage")||c.message.includes("errors building")),y=c.message.includes("Configuration must export a valid object")||c.message.includes("Configuration file is empty and exports nothing");if(f&&(y||u))throw c;if(l&&(!f||!y))a={...await this.applyEnvironmentVariables(s.name||"",s.defaultConfig,s.checkEnv!==!1,s.verbose||!1),warnings:["Configuration file has syntax errors, using defaults with environment variables"]};else if(!f)a={...await this.applyEnvironmentVariables(s.name||"",s.defaultConfig,s.checkEnv!==!1,s.verbose||!1),warnings:[`Configuration loading error, using defaults: ${c.message}`]};else throw c}else a={...await this.applyEnvironmentVariables(s.name||"",s.defaultConfig,s.checkEnv!==!1,s.verbose||!1),warnings:[`Configuration loading failed, using defaults: ${c instanceof Error?c.message:String(c)}`]}}if(r||o)await this.validateConfiguration(a.config,r,o,s.name);if(i?.enabled&&a)this.cacheResult(s.name||"",a,i,s);if(n?.enabled){let c={operation:"loadConfig",duration:Date.now()-t,configName:s.name,timestamp:new Date};if(n.onMetrics)n.onMetrics(c);if(n.slowThreshold&&c.duration>n.slowThreshold)ft.warn(`Slow configuration loading detected: ${c.duration}ms for ${s.name}`);a.metrics=c}return a}catch(a){let c=Date.now()-t;throw ft.error(`Configuration loading failed after ${c}ms:`,[a instanceof Error?a:Error(String(a))]),a}}async loadConfigurationStrategies(e,t=!1,i){let{name:n="",alias:r,cwd:o,configDir:s,defaultConfig:a,checkEnv:c=!0,arrayStrategy:f="replace",verbose:u=!1}=e,l=o||It.cwd(),y=[],p=await this.loadLocalConfiguration(n,r,l,s,a,f,u,c,i);if(p)return y.push(...this.getLocalSearchPaths(n,r,l,s)),this.finalizeResult(p,y,c,n,u);let w=await this.loadHomeConfiguration(n,r,a,f,u,c);if(w)return y.push(...this.getHomeSearchPaths(n,r)),this.finalizeResult(w,y,c,n,u);let S=await this.loadPackageJsonConfiguration(n,r,l,a,f,u,c);if(S)return y.push(Je(l,"package.json")),this.finalizeResult(S,y,c,n,u);if(y.push(...this.getAllSearchPaths(n,r,l,s)),t)throw Pt.configNotFound(n,y,r);return{...await this.applyEnvironmentVariables(n,a,c,u),warnings:[`No configuration file found for "${n}"${r?` or alias "${r}"`:""}, using defaults with environment variables`]}}async loadLocalConfiguration(e,t,i,n,r,o,s,a,c){let f=a?di(e,r,s):r,u=this.getLocalDirectories(i,n);for(let l of u){if(s)ft.info(`Searching for configuration in: ${l}`);let y=this.fileLoader.generateConfigPaths(e,l,t),p=await this.fileLoader.tryLoadFromPaths(y,f,{arrayStrategy:o,verbose:s,cacheTtl:c?.ttl,useCache:!c?.ttl||c.ttl>100});if(p){if(s)ft.success(`Configuration loaded from: ${p.source.path}`);return p}}return null}async loadHomeConfiguration(e,t,i,n,r,o){if(!e)return null;let s=o?di(e,i,r):i,a=[Je(Jt(),".config",e),Je(Jt(),".config"),Jt()];for(let c of a){if(r)ft.info(`Checking home directory: ${c}`);let f=this.fileLoader.generateConfigPaths(e,c,t),u=await this.fileLoader.tryLoadFromPaths(f,s,{arrayStrategy:n,verbose:r});if(u){if(r)ft.success(`Configuration loaded from home directory: ${u.source.path}`);return u}}return null}async loadPackageJsonConfiguration(e,t,i,n,r,o,s){let a=s?di(e,n,o):n;try{let c=Je(i,"package.json");if(!Tn(c))return null;let f=await import(c),u=f[e],l=e;if(!u&&t)u=f[t],l=t;if(u&&typeof u==="object"&&!Array.isArray(u)){if(o)ft.success(`Configuration loaded from package.json: ${l}`);return{config:Un(a,u,r),source:{type:"package.json",path:c,priority:30,timestamp:new Date}}}}catch(c){if(o)ft.warn("Failed to load package.json:",[c instanceof Error?c:Error(String(c))])}return null}async applyEnvironmentVariables(e,t,i,n){if(!i||!e||typeof t!=="object"||t===null||Array.isArray(t))return{config:t,source:{type:"default",priority:10,timestamp:new Date}};return{config:di(e,t,n),source:{type:"environment",priority:20,timestamp:new Date}}}async finalizeResult(e,t,i,n,r){return{config:e.config,source:e.source,path:e.source.path}}async validateConfiguration(e,t,i,n){let r=[];if(i){let o=i(e);if(o)r.push(...o)}if(t){let o=await this.validator.validateConfiguration(e,t);if(!o.isValid)r.push(...o.errors.map((s)=>s.path?`${s.path}: ${s.message}`:s.message))}if(r.length>0)throw Pt.configValidation(n||"unknown",r,n)}checkCache(e,t){let i=this.generateCacheKey(e,t);return ni.get(i)||null}cacheResult(e,t,i,n){let r=this.generateCacheKey(e,n);ni.set(r,t,void 0,i.ttl)}generateCacheKey(e,t){let i=[e];if(t.alias)i.push(`alias:${t.alias}`);if(t.cwd)i.push(`cwd:${t.cwd}`);if(t.configDir)i.push(`configDir:${t.configDir}`);if("checkEnv"in t)i.push(`checkEnv:${t.checkEnv}`);return i.join("|")}getLocalDirectories(e,t){return Array.from(new Set([e,Je(e,"config"),Je(e,".config"),t?Je(e,t):void 0].filter(Boolean)))}getAllSearchPaths(e,t,i,n){let r=[];return r.push(...this.getLocalSearchPaths(e,t,i,n)),r.push(...this.getHomeSearchPaths(e,t)),r.push(Je(i,"package.json")),r}getLocalSearchPaths(e,t,i,n){let r=this.getLocalDirectories(i,n),o=[];for(let s of r)o.push(...this.fileLoader.generateConfigPaths(e,s,t));return o}getHomeSearchPaths(e,t){if(!e)return[];let i=[Je(Jt(),".config",e),Je(Jt(),".config"),Jt()],n=[];for(let r of i)n.push(...this.fileLoader.generateConfigPaths(e,r,t));return n}async loadConfigWithResult(e){return this.loadConfig(e)}}function Rs(e){let t=!(e.message.includes("EACCES")||e.message.includes("EPERM")||e.message.includes("permission denied"))&&(e.message.includes("syntax")||e.message.includes("Expected")||e.message.includes("Unexpected")||e.message.includes("BuildMessage")),i=e.message.includes("Configuration must export a valid object")||e.message.includes("Configuration file is empty and exports nothing");return t||i}async function cu(e){return Et.loadConfig({...e,__strictErrorHandling:!0})}async function Qs(e){let t="defaultConfig"in e&&e.defaultConfig!==void 0?e.defaultConfig:{},i="cache"in e||"performance"in e||"schema"in e||"validate"in e;try{let n;if(i)n=await Et.loadConfig(e);else n=await Et.loadConfig({...e,defaultConfig:t,cache:{enabled:!0},performance:{enabled:!1}});return n?.config??t}catch(n){let r=n instanceof Error?n.name:"UnknownError",o=n instanceof Error?n.message:String(n);if(!(r==="ConfigNotFoundError"||r==="ConfigLoadError"||r==="ConfigValidationError"||o.includes("config"))&&e.verbose)ft.warn("Unexpected error loading config, using defaults:",[n instanceof Error?n:Error(String(n))]);let s=i?{...e,defaultConfig:t}:{...e,defaultConfig:t,cache:{enabled:!0},performance:{enabled:!1}};if("checkEnv"in e?e.checkEnv!==!1:!0)return(await Et.applyEnvironmentVariables(s.name||"",t,!0,s.verbose||!1))?.config??t;return t}}async function fu(e={defaultConfig:{}}){if(typeof e==="string"){let{cwd:t}=await import("process");try{return(await Et.loadConfig({name:e,cwd:t(),generatedDir:"./generated",configDir:"./config",defaultConfig:{},checkEnv:!0,arrayStrategy:"replace"})).config}catch(i){if(i instanceof Error&&(i.name==="ConfigNotFoundError"||i.name==="ConfigLoadError"&&Rs(i)))return(await Et.applyEnvironmentVariables(e,{},!0,!1)).config;throw i}}try{return(await Et.loadConfig({...e,cwd:e.cwd||It.cwd(),cache:{enabled:!0},performance:{enabled:!1}})).config}catch(t){if(t instanceof Error&&(t.name==="ConfigNotFoundError"||t.name==="ConfigLoadError"&&Rs(t)))return(await Et.applyEnvironmentVariables(e.name||"",e.defaultConfig||{},e.checkEnv!==!1,e.verbose||!1)).config;throw t}}async function uu(e,t,i="replace"){let n=new br;try{let r=await n.loadFromPath(e,t,{arrayStrategy:i,useCache:!1,trackPerformance:!1});return r?r.config:null}catch{return null}}function di(e,t,i=!1){let n=new Er,r=e.toUpperCase().replace(/[^A-Z0-9]/g,"_");function o(s,a=[]){let c={...s};for(let[f,u]of Object.entries(s)){let l=[...a,f],y=[`${r}_${l.join("_").toUpperCase()}`,`${r}_${l.map((S)=>S.toUpperCase()).join("")}`,`${r}_${l.map((S)=>S.replace(/([A-Z])/g,"_$1").toUpperCase()).join("")}`],p,w;for(let S of y)if(p=It.env[S],p!==void 0){w=S;break}if(p!==void 0&&w)if(typeof u==="boolean")c[f]=["true","1","yes"].includes(p.toLowerCase());else if(typeof u==="number"){let S=Number(p);if(!Number.isNaN(S))c[f]=S}else if(Array.isArray(u))try{c[f]=JSON.parse(p)}catch{c[f]=p.split(",").map((S)=>S.trim())}else c[f]=p;else if(u&&typeof u==="object"&&!Array.isArray(u))c[f]=o(u,l)}return c}return o(t)}function hu(e){let t=Je(It.cwd(),e.configDir),i=Je(It.cwd(),e.generatedDir),n=Je(i,"config-types.ts");if(!Tn(os(n)))Xc(os(n),{recursive:!0,mode:511});let r=Tn(t)?Qc(t).map((s)=>s.replace(/\.(ts|js|mjs|cjs|mts|cts|json)$/,"")).sort():[],o=`// Generated by bunfig v${ju}
60
+ `;return i}}function nu(e,t){let i=ea("process");if(typeof i>"u"||!i.env)return t;let n=i.env[e];return n!==void 0?n:t}function Ys(e,t,i={}){return Zs(e,t,i,new WeakMap)}function Zs(e,t,i,n){let{arrayMergeMode:r="replace",skipNullish:o=!1,customMerger:s}=i;if(t===null||t===void 0)return o?e:t;if(s){let a=s(e,t);if(a!==void 0)return a}if(Array.isArray(t)||Array.isArray(e))return Xs(e,t,r,n);if(!ot(t)||!ot(e))return t;return lu(e,t,i,n)}function Xs(e,t,i,n){if(Array.isArray(t)&&!Array.isArray(e))return t;if(Array.isArray(e)&&!Array.isArray(t))return t;if(Array.isArray(t)&&Array.isArray(e))switch(i){case"replace":return t;case"concat":return ou(e,t);case"smart":return su(e,t,n);default:return t}return t}function ou(e,t){let i=[...t];for(let n of e)if(!i.some((r)=>Pn(r,n)))i.push(n);return i}function su(e,t,i){if(t.length===0)return e;if(e.length===0)return t;if(ot(t[0])&&ot(e[0]))return au(e,t,i);if(t.every((n)=>typeof n==="string")&&e.every((n)=>typeof n==="string")){let n=[...t];for(let r of e)if(!n.includes(r))n.push(r);return n}return t}function au(e,t,i){let n=[...t];for(let r of e){if(!ot(r)){n.push(r);continue}let o=["id","name","key","path","type"],s=!1;for(let a of o)if(a in r){if(n.find((c)=>ot(c)&&(a in c)&&c[a]===r[a])){s=!0;break}}if(!s)n.push(r)}return n}function lu(e,t,i,n){let r=t;if(ot(r)&&n.has(r))return n.get(r);let o={...e};if(ot(r))n.set(r,o);for(let s in r){if(!Object.prototype.hasOwnProperty.call(r,s))continue;let a=r[s],c=o[s];if(i.skipNullish&&(a===null||a===void 0))continue;if(a===null||a===void 0){o[s]=a;continue}if(ot(a)&&ot(c))o[s]=Zs(c,a,i,n);else if(Array.isArray(a)||Array.isArray(c))o[s]=Xs(c,a,i.arrayMergeMode||"smart",n);else o[s]=a}return o}function Un(e,t,i="replace"){return Ys(e,t,{arrayMergeMode:i==="replace"?"replace":"smart",skipNullish:!0})}function Pn(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!Pn(e[i],t[i]))return!1;return!0}if(ot(e)&&ot(t)){let i=Object.keys(e),n=Object.keys(t);if(i.length!==n.length)return!1;for(let r of i){if(!Object.prototype.hasOwnProperty.call(t,r))return!1;if(!Pn(e[r],t[r]))return!1}return!0}return!1}function ot(e){return Boolean(e&&typeof e==="object"&&!Array.isArray(e))}class br{extensions=[".ts",".js",".mjs",".cjs",".json",".mts",".cts"];async loadFromPath(e,t,i={}){let{arrayStrategy:n="replace",useCache:r=!0,cacheTtl:o,trackPerformance:s=!0,verbose:a=!1}=i;if(r){let f=ni.getWithFileCheck("file",e);if(f){if(a)console.log(`Configuration loaded from cache: ${e}`);return f}}let c=async()=>{if(!Hi(e))return null;try{let f=`?t=${Date.now()}`,u=await import(e+f),l=u.default||u,y="default"in u,p=Object.keys(u).length>0;if(!y&&!p)throw new pi(e,Error("Configuration file is empty and exports nothing"),"unknown");if(typeof l!=="object"||l===null||Array.isArray(l))throw new pi(e,Error("Configuration must export a valid object"),"unknown");let w={config:Un(t,l,n),source:{type:"file",path:e,priority:100,timestamp:new Date}};if(r)ni.setWithFileCheck("file",w,e,o);return w}catch(f){throw f instanceof Error?Pt.configLoad(e,f):Pt.configLoad(e,Error(String(f)))}};if(s)return yi.track("loadFromPath",c,{path:e});return c()}async tryLoadFromPaths(e,t,i={}){for(let n of e)try{let r=await this.loadFromPath(n,t,i);if(r)return r}catch(r){if(r instanceof Error&&r.name==="ConfigLoadError")throw r;if(i.verbose)console.warn(`Failed to load config from ${n}:`,r)}return null}generateConfigPaths(e,t,i){let n=this.generateNamePatterns(e,i),r=[];for(let o of n)for(let s of this.extensions)r.push(gn(t,`${o}${s}`));return r}generateNamePatterns(e,t){let i=[];if(i.push("config",".config"),e)i.push(e,`.${e}.config`,`${e}.config`,`.${e}`);if(t){if(i.push(t,`.${t}.config`,`${t}.config`,`.${t}`),e)i.push(`${e}.${t}.config`,`.${e}.${t}.config`)}return i.filter(Boolean)}checkFileAccess(e){return Js(async()=>Hi(e),{maxRetries:2,retryDelay:100,fallback:!1})}async discoverConfigFiles(e,t,i){let n=[];if(!Hi(e))return n;if(t||i){let r=this.generateNamePatterns(t||"",i);for(let o of r)for(let s of this.extensions){let a=gn(e,`${o}${s}`);if(await this.checkFileAccess(a))n.push(a)}}else try{let{readdirSync:r}=await import("fs"),o=r(e);for(let s of o)if(this.looksLikeConfigFile(s)){let a=gn(e,s);if(await this.checkFileAccess(a))n.push(a)}}catch{return[]}return n}looksLikeConfigFile(e){return[/\.config\.(ts|js|mjs|cjs|json|mts|cts)$/,/^\..*\.(ts|js|mjs|cjs|json|mts|cts)$/,/config\.(ts|js|mjs|cjs|json|mts|cts)$/].some((t)=>t.test(e))}async validateConfigFile(e){let t=[];try{if(!Hi(e))return t.push("Configuration file does not exist"),t;let i=await import(e),n=i.default||i;if(n===void 0)t.push("Configuration file must export a default value or named exports");else if(typeof n!=="object"||n===null)t.push("Configuration must be an object");else if(Array.isArray(n))t.push("Configuration cannot be an array at the root level");if(e.endsWith(".json"))try{let{readFileSync:r}=await import("fs"),o=r(e,"utf8");JSON.parse(o)}catch(r){t.push(`Invalid JSON syntax: ${r}`)}}catch(i){t.push(`Failed to load configuration file: ${i}`)}return t}async getFileModificationTime(e){try{let{statSync:t}=await import("fs");return t(e).mtime}catch{return null}}async preloadConfigurations(e,t={}){let i=new Map;return await Promise.allSettled(e.map(async(n)=>{try{let r=await this.loadFromPath(n,{},t);if(r)i.set(n,r.config)}catch(r){if(t.verbose)console.warn(`Failed to preload ${n}:`,r)}})),i}}class Kn{async validateConfiguration(e,t,i={}){let{stopOnFirstError:n=!1,validateRequired:r=!0,validateTypes:o=!0,customRules:s=[],trackPerformance:a=!0,verbose:c=!1}=i,f=async()=>{let u=[],l=[],y={stopOnFirstError:n,validateRequired:r,validateTypes:o,customRules:s,trackPerformance:a,verbose:c};try{if(typeof t==="string")return await this.validateWithSchemaFile(e,t,y);else if(Array.isArray(t))return this.validateWithRules(e,[...t,...s],y);else return this.validateWithJSONSchema(e,t,y)}catch(p){return u.push({path:"",message:`Validation failed: ${p}`,rule:"system"}),{isValid:!1,errors:u,warnings:l}}};if(a)return await yi.track("validateConfiguration",f);return f()}async validateWithSchemaFile(e,t,i){try{if(!bf(t))throw new gi(t,[{path:"",message:"Schema file does not exist"}]);let n=await import(t),r=n.default||n;if(Array.isArray(r))return this.validateWithRules(e,r,i);else return this.validateWithJSONSchema(e,r,i)}catch(n){throw new gi(t,[{path:"",message:`Failed to load schema: ${n}`}])}}validateWithJSONSchema(e,t,i){let n=[],r=[];return this.validateObjectAgainstSchema(e,t,"",n,r,i),{isValid:n.length===0,errors:n,warnings:r}}validateObjectAgainstSchema(e,t,i,n,r,o){if(o.validateTypes&&t.type){let s=Array.isArray(e)?"array":typeof e,a=Array.isArray(t.type)?t.type:[t.type];if(!a.includes(s)){if(n.push({path:i,message:`Expected type ${a.join(" or ")}, got ${s}`,expected:a.join(" or "),actual:s,rule:"type"}),o.stopOnFirstError)return}}if(t.enum&&!t.enum.includes(e)){if(n.push({path:i,message:`Value must be one of: ${t.enum.join(", ")}`,expected:t.enum.join(", "),actual:e,rule:"enum"}),o.stopOnFirstError)return}if(typeof e==="string"){if(t.minLength!==void 0&&e.length<t.minLength)n.push({path:i,message:`String length must be at least ${t.minLength}`,expected:`>= ${t.minLength}`,actual:e.length,rule:"minLength"});if(t.maxLength!==void 0&&e.length>t.maxLength)n.push({path:i,message:`String length must not exceed ${t.maxLength}`,expected:`<= ${t.maxLength}`,actual:e.length,rule:"maxLength"});if(t.pattern){if(!new RegExp(t.pattern).test(e))n.push({path:i,message:`String does not match pattern ${t.pattern}`,expected:t.pattern,actual:e,rule:"pattern"})}}if(typeof e==="number"){if(t.minimum!==void 0&&e<t.minimum)n.push({path:i,message:`Value must be at least ${t.minimum}`,expected:`>= ${t.minimum}`,actual:e,rule:"minimum"});if(t.maximum!==void 0&&e>t.maximum)n.push({path:i,message:`Value must not exceed ${t.maximum}`,expected:`<= ${t.maximum}`,actual:e,rule:"maximum"})}if(Array.isArray(e)&&t.items)for(let s=0;s<e.length;s++){let a=i?`${i}[${s}]`:`[${s}]`;if(this.validateObjectAgainstSchema(e[s],t.items,a,n,r,o),o.stopOnFirstError&&n.length>0)return}if(e&&typeof e==="object"&&!Array.isArray(e)){let s=e;if(o.validateRequired&&t.required){for(let a of t.required)if(!(a in s)){if(n.push({path:i?`${i}.${a}`:a,message:`Missing required property '${a}'`,expected:"required",rule:"required"}),o.stopOnFirstError)return}}if(t.properties){for(let[a,c]of Object.entries(t.properties))if(a in s){let f=i?`${i}.${a}`:a;if(this.validateObjectAgainstSchema(s[a],c,f,n,r,o),o.stopOnFirstError&&n.length>0)return}}if(t.additionalProperties===!1){let a=new Set(Object.keys(t.properties||{}));for(let c of Object.keys(s))if(!a.has(c))r.push({path:i?`${i}.${c}`:c,message:`Additional property '${c}' is not allowed`,rule:"additionalProperties"})}}}validateWithRules(e,t,i){let n=[],r=[];for(let o of t)try{let s=this.getValueByPath(e,o.path),a=this.validateWithRule(s,o,o.path);if(n.push(...a),i.stopOnFirstError&&n.length>0)break}catch(s){n.push({path:o.path,message:`Rule validation failed: ${s}`,rule:"system"})}return{isValid:n.length===0,errors:n,warnings:r}}validateWithRule(e,t,i){let n=[];if(t.required&&(e===void 0||e===null))return n.push({path:i,message:t.message||`Property '${i}' is required`,expected:"required",rule:"required"}),n;if(e===void 0||e===null)return n;if(t.type){let r=Array.isArray(e)?"array":typeof e;if(r!==t.type)n.push({path:i,message:t.message||`Expected type ${t.type}, got ${r}`,expected:t.type,actual:r,rule:"type"})}if(t.min!==void 0){let r=Array.isArray(e)?e.length:typeof e==="string"?e.length:typeof e==="number"?e:0;if(r<t.min)n.push({path:i,message:t.message||`Value must be at least ${t.min}`,expected:`>= ${t.min}`,actual:r,rule:"min"})}if(t.max!==void 0){let r=Array.isArray(e)?e.length:typeof e==="string"?e.length:typeof e==="number"?e:0;if(r>t.max)n.push({path:i,message:t.message||`Value must not exceed ${t.max}`,expected:`<= ${t.max}`,actual:r,rule:"max"})}if(t.pattern&&typeof e==="string"){if(!t.pattern.test(e))n.push({path:i,message:t.message||`Value does not match pattern ${t.pattern}`,expected:t.pattern.toString(),actual:e,rule:"pattern"})}if(t.enum&&!t.enum.includes(e))n.push({path:i,message:t.message||`Value must be one of: ${t.enum.join(", ")}`,expected:t.enum.join(", "),actual:e,rule:"enum"});if(t.validator){let r=t.validator(e);if(r)n.push({path:i,message:t.message||r,rule:"custom"})}return n}getValueByPath(e,t){if(!t)return e;let i=t.split("."),n=e;for(let r of i)if(n&&typeof n==="object"&&r in n)n=n[r];else return;return n}generateRulesFromInterface(e){let t=[],i=e.matchAll(/(\w+)(\?)?:\s*(\w+)/g);for(let n of i){let[,r,o,s]=n;t.push({path:r,required:!o,type:this.mapTypeScriptType(s)})}return t}mapTypeScriptType(e){switch(e.toLowerCase()){case"string":return"string";case"number":return"number";case"boolean":return"boolean";case"array":return"array";case"object":return"object";default:return"object"}}static createCommonRules(){return{server:[{path:"port",required:!0,type:"number",min:1,max:65535},{path:"host",required:!0,type:"string",min:1},{path:"ssl",type:"boolean"}],database:[{path:"url",required:!0,type:"string",min:1},{path:"pool",type:"number",min:1,max:100},{path:"timeout",type:"number",min:0}],api:[{path:"baseUrl",required:!0,type:"string",pattern:oa},{path:"timeout",type:"number",min:0},{path:"retries",type:"number",min:0,max:10}]}}}class zn{fileLoader=new br;envProcessor=new Er;validator=new Kn;async loadConfig(e){let t=Date.now(),{cache:i,performance:n,schema:r,validate:o,...s}=e;try{if(i?.enabled){let c=this.checkCache(s.name||"",s);if(c)return c}let a;try{a=await this.loadConfigurationStrategies(s,!0,i)}catch(c){let f=s.__strictErrorHandling;if(c instanceof Error&&c.name==="ConfigNotFoundError"){if(f)throw c;a={...await this.applyEnvironmentVariables(s.name||"",s.defaultConfig,s.checkEnv!==!1,s.verbose||!1),warnings:[`No configuration file found for "${s.name||"config"}", using defaults with environment variables`]}}else if(c instanceof Error&&c.name==="ConfigLoadError"){let u=c.message.includes("EACCES")||c.message.includes("EPERM")||c.message.includes("permission denied"),l=!u&&(c.message.includes("syntax")||c.message.includes("Expected")||c.message.includes("Unexpected")||c.message.includes("BuildMessage")||c.message.includes("errors building")),y=c.message.includes("Configuration must export a valid object")||c.message.includes("Configuration file is empty and exports nothing");if(f&&(y||u))throw c;if(l&&(!f||!y))a={...await this.applyEnvironmentVariables(s.name||"",s.defaultConfig,s.checkEnv!==!1,s.verbose||!1),warnings:["Configuration file has syntax errors, using defaults with environment variables"]};else if(!f)a={...await this.applyEnvironmentVariables(s.name||"",s.defaultConfig,s.checkEnv!==!1,s.verbose||!1),warnings:[`Configuration loading error, using defaults: ${c.message}`]};else throw c}else a={...await this.applyEnvironmentVariables(s.name||"",s.defaultConfig,s.checkEnv!==!1,s.verbose||!1),warnings:[`Configuration loading failed, using defaults: ${c instanceof Error?c.message:String(c)}`]}}if(r||o)await this.validateConfiguration(a.config,r,o,s.name);if(i?.enabled&&a)this.cacheResult(s.name||"",a,i,s);if(n?.enabled){let c={operation:"loadConfig",duration:Date.now()-t,configName:s.name,timestamp:new Date};if(n.onMetrics)n.onMetrics(c);if(n.slowThreshold&&c.duration>n.slowThreshold)ft.warn(`Slow configuration loading detected: ${c.duration}ms for ${s.name}`);a.metrics=c}return a}catch(a){let c=Date.now()-t;throw ft.error(`Configuration loading failed after ${c}ms:`,[a instanceof Error?a:Error(String(a))]),a}}async loadConfigurationStrategies(e,t=!1,i){let{name:n="",alias:r,cwd:o,configDir:s,defaultConfig:a,checkEnv:c=!0,arrayStrategy:f="replace",verbose:u=!1}=e,l=o||It.cwd(),y=[],p=await this.loadLocalConfiguration(n,r,l,s,a,f,u,c,i);if(p)return y.push(...this.getLocalSearchPaths(n,r,l,s)),this.finalizeResult(p,y,c,n,u);let w=await this.loadHomeConfiguration(n,r,a,f,u,c);if(w)return y.push(...this.getHomeSearchPaths(n,r)),this.finalizeResult(w,y,c,n,u);let S=await this.loadPackageJsonConfiguration(n,r,l,a,f,u,c);if(S)return y.push(Je(l,"package.json")),this.finalizeResult(S,y,c,n,u);if(y.push(...this.getAllSearchPaths(n,r,l,s)),t)throw Pt.configNotFound(n,y,r);return{...await this.applyEnvironmentVariables(n,a,c,u),warnings:[`No configuration file found for "${n}"${r?` or alias "${r}"`:""}, using defaults with environment variables`]}}async loadLocalConfiguration(e,t,i,n,r,o,s,a,c){let f=a?di(e,r,s):r,u=this.getLocalDirectories(i,n);for(let l of u){if(s)ft.info(`Searching for configuration in: ${l}`);let y=this.fileLoader.generateConfigPaths(e,l,t),p=await this.fileLoader.tryLoadFromPaths(y,f,{arrayStrategy:o,verbose:s,cacheTtl:c?.ttl,useCache:!c?.ttl||c.ttl>100});if(p){if(s)ft.success(`Configuration loaded from: ${p.source.path}`);return p}}return null}async loadHomeConfiguration(e,t,i,n,r,o){if(!e)return null;let s=o?di(e,i,r):i,a=[Je(Jt(),".config",e),Je(Jt(),".config"),Jt()];for(let c of a){if(r)ft.info(`Checking home directory: ${c}`);let f=this.fileLoader.generateConfigPaths(e,c,t),u=await this.fileLoader.tryLoadFromPaths(f,s,{arrayStrategy:n,verbose:r});if(u){if(r)ft.success(`Configuration loaded from home directory: ${u.source.path}`);return u}}return null}async loadPackageJsonConfiguration(e,t,i,n,r,o,s){let a=s?di(e,n,o):n;try{let c=Je(i,"package.json");if(!Tn(c))return null;let f=await import(c),u=f[e],l=e;if(!u&&t)u=f[t],l=t;if(u&&typeof u==="object"&&!Array.isArray(u)){if(o)ft.success(`Configuration loaded from package.json: ${l}`);return{config:Un(a,u,r),source:{type:"package.json",path:c,priority:30,timestamp:new Date}}}}catch(c){if(o)ft.warn("Failed to load package.json:",[c instanceof Error?c:Error(String(c))])}return null}async applyEnvironmentVariables(e,t,i,n){if(!i||!e||typeof t!=="object"||t===null||Array.isArray(t))return{config:t,source:{type:"default",priority:10,timestamp:new Date}};return{config:di(e,t,n),source:{type:"environment",priority:20,timestamp:new Date}}}async finalizeResult(e,t,i,n,r){return{config:e.config,source:e.source,path:e.source.path}}async validateConfiguration(e,t,i,n){let r=[];if(i){let o=i(e);if(o)r.push(...o)}if(t){let o=await this.validator.validateConfiguration(e,t);if(!o.isValid)r.push(...o.errors.map((s)=>s.path?`${s.path}: ${s.message}`:s.message))}if(r.length>0)throw Pt.configValidation(n||"unknown",r,n)}checkCache(e,t){let i=this.generateCacheKey(e,t);return ni.get(i)||null}cacheResult(e,t,i,n){let r=this.generateCacheKey(e,n);ni.set(r,t,void 0,i.ttl)}generateCacheKey(e,t){let i=[e];if(t.alias)i.push(`alias:${t.alias}`);if(t.cwd)i.push(`cwd:${t.cwd}`);if(t.configDir)i.push(`configDir:${t.configDir}`);if("checkEnv"in t)i.push(`checkEnv:${t.checkEnv}`);return i.join("|")}getLocalDirectories(e,t){return Array.from(new Set([e,Je(e,"config"),Je(e,".config"),t?Je(e,t):void 0].filter(Boolean)))}getAllSearchPaths(e,t,i,n){let r=[];return r.push(...this.getLocalSearchPaths(e,t,i,n)),r.push(...this.getHomeSearchPaths(e,t)),r.push(Je(i,"package.json")),r}getLocalSearchPaths(e,t,i,n){let r=this.getLocalDirectories(i,n),o=[];for(let s of r)o.push(...this.fileLoader.generateConfigPaths(e,s,t));return o}getHomeSearchPaths(e,t){if(!e)return[];let i=[Je(Jt(),".config",e),Je(Jt(),".config"),Jt()],n=[];for(let r of i)n.push(...this.fileLoader.generateConfigPaths(e,r,t));return n}async loadConfigWithResult(e){return this.loadConfig(e)}}function Rs(e){let t=!(e.message.includes("EACCES")||e.message.includes("EPERM")||e.message.includes("permission denied"))&&(e.message.includes("syntax")||e.message.includes("Expected")||e.message.includes("Unexpected")||e.message.includes("BuildMessage")),i=e.message.includes("Configuration must export a valid object")||e.message.includes("Configuration file is empty and exports nothing");return t||i}async function cu(e){return Et.loadConfig({...e,__strictErrorHandling:!0})}async function Qs(e){let t="defaultConfig"in e&&e.defaultConfig!==void 0?e.defaultConfig:{},i="cache"in e||"performance"in e||"schema"in e||"validate"in e;try{let n;if(i)n=await Et.loadConfig(e);else n=await Et.loadConfig({...e,defaultConfig:t,cache:{enabled:!0},performance:{enabled:!1}});return n?.config??t}catch(n){let r=n instanceof Error?n.name:"UnknownError",o=n instanceof Error?n.message:String(n);if(!(r==="ConfigNotFoundError"||r==="ConfigLoadError"||r==="ConfigValidationError"||o.includes("config"))&&e.verbose)ft.warn("Unexpected error loading config, using defaults:",[n instanceof Error?n:Error(String(n))]);let s=i?{...e,defaultConfig:t}:{...e,defaultConfig:t,cache:{enabled:!0},performance:{enabled:!1}};if("checkEnv"in e?e.checkEnv!==!1:!0)return(await Et.applyEnvironmentVariables(s.name||"",t,!0,s.verbose||!1))?.config??t;return t}}async function fu(e={defaultConfig:{}}){if(typeof e==="string"){let{cwd:t}=await import("process");try{return(await Et.loadConfig({name:e,cwd:t(),generatedDir:"./generated",configDir:"./config",defaultConfig:{},checkEnv:!0,arrayStrategy:"replace"})).config}catch(i){if(i instanceof Error&&(i.name==="ConfigNotFoundError"||i.name==="ConfigLoadError"&&Rs(i)))return(await Et.applyEnvironmentVariables(e,{},!0,!1)).config;throw i}}try{return(await Et.loadConfig({...e,cwd:e.cwd||It.cwd(),cache:{enabled:!0},performance:{enabled:!1}})).config}catch(t){if(t instanceof Error&&(t.name==="ConfigNotFoundError"||t.name==="ConfigLoadError"&&Rs(t)))return(await Et.applyEnvironmentVariables(e.name||"",e.defaultConfig||{},e.checkEnv!==!1,e.verbose||!1)).config;throw t}}async function uu(e,t,i="replace"){let n=new br;try{let r=await n.loadFromPath(e,t,{arrayStrategy:i,useCache:!1,trackPerformance:!1});return r?r.config:null}catch{return null}}function di(e,t,i=!1){let n=new Er,r=e.toUpperCase().replace(/[^A-Z0-9]/g,"_");function o(s,a=[]){let c={...s};for(let[f,u]of Object.entries(s)){let l=[...a,f],y=[`${r}_${l.join("_").toUpperCase()}`,`${r}_${l.map((S)=>S.toUpperCase()).join("")}`,`${r}_${l.map((S)=>S.replace(/([A-Z])/g,"_$1").toUpperCase()).join("")}`],p,w;for(let S of y)if(p=It.env[S],p!==void 0){w=S;break}if(p!==void 0&&w)if(typeof u==="boolean")c[f]=["true","1","yes"].includes(p.toLowerCase());else if(typeof u==="number"){let S=Number(p);if(!Number.isNaN(S))c[f]=S}else if(Array.isArray(u))try{c[f]=JSON.parse(p)}catch{c[f]=p.split(",").map((S)=>S.trim())}else c[f]=p;else if(u&&typeof u==="object"&&!Array.isArray(u))c[f]=o(u,l)}return c}return o(t)}function hu(e){let t=Je(It.cwd(),e.configDir),i=Je(It.cwd(),e.generatedDir),n=Je(i,"config-types.ts");if(!Tn(os(n)))Xc(os(n),{recursive:!0,mode:511});let r=Tn(t)?Qc(t).map((s)=>s.replace(/\.(ts|js|mjs|cjs|mts|cts|json)$/,"")).sort():[],o=`// Generated by bunfig v${ju}
61
61
  export type ConfigNames = ${r.length?`'${r.join("' | '")}'`:"string"}
62
62
  `;ef(n,o,{mode:438})}function du(e){let t=null,i=null,n=()=>{if(!i)i=Qs(e).then((o)=>(t=o,o),(o)=>{let s="defaultConfig"in e?e.defaultConfig:{};if(t=s,"verbose"in e&&e.verbose)ft.warn("Config loading failed, using defaults:",[o instanceof Error?o:Error(String(o))]);return s});return i},r="defaultConfig"in e?e.defaultConfig:{};return t=r,n(),new Proxy({},{get(o,s){if(t)return t[s];let a=r[s];return n(),a},has(o,s){return s in(t||r)},ownKeys(){return Object.keys(t||r)},getOwnPropertyDescriptor(o,s){return Object.getOwnPropertyDescriptor(t||r,s)},set(o,s,a){if(!t)t={...r};return t[s]=a,!0}})}function mu(e){let t=vs(Af.cwd(),e?.configDir||"./config");function i(){if(!Sf(t))return[];let r=new Set([".ts",".js",".mjs",".cjs",".mts",".cts",".json"]),o=[".ts",".mts",".cts",".js",".mjs",".cjs",".json"],s=$f(t).filter((c)=>r.has(yn(c))).map((c)=>({base:c.replace(/\.(?:ts|js|mjs|cjs|mts|cts|json)$/i,""),file:c})),a=new Map;for(let{base:c,file:f}of s){let u=yn(f).toLowerCase(),l=a.get(c);if(!l){a.set(c,f);continue}let y=yn(l).toLowerCase();if(o.indexOf(u)<o.indexOf(y))a.set(c,f)}return Array.from(a.entries()).map(([c,f])=>({base:c,file:f})).sort((c,f)=>c.base.localeCompare(f.base))}function n(){let r=i(),o=r.map((c)=>c.base),s=o.length?o.map((c)=>`'${c}'`).join(" | "):"string",a=r.length?`{
63
63
  ${r.map((c)=>{let f=vs(t,c.file).replace(/\\/g,"/");return` '${c.base}': typeof import('${f}').default`}).join(`,
@@ -87,23 +87,23 @@ export type ConfigOf = Config
87
87
  `;i+=`| Variable | Type | Description | Example |
88
88
  `,i+=`|----------|------|-------------|----------|
89
89
  `;for(let n of e)i+=`| \`${n.key}\` | ${n.type} | ${n.description} | \`${n.example}\` |
90
- `;return i}}function Xu(e,t,i={}){return Ca(e,t,i,new WeakMap)}function Ca(e,t,i,n){let{arrayMergeMode:r="replace",skipNullish:o=!1,customMerger:s}=i;if(t===null||t===void 0)return o?e:t;if(s){let a=s(e,t);if(a!==void 0)return a}if(Array.isArray(t)||Array.isArray(e))return wa(e,t,r,n);if(!ot(t)||!ot(e))return t;return ih(e,t,i,n)}function wa(e,t,i,n){if(Array.isArray(t)&&!Array.isArray(e))return t;if(Array.isArray(e)&&!Array.isArray(t))return t;if(Array.isArray(t)&&Array.isArray(e))switch(i){case"replace":return t;case"concat":return Qu(e,t);case"smart":return eh(e,t,n);default:return t}return t}function Qu(e,t){let i=[...t];for(let n of e)if(!i.some((r)=>Wn(r,n)))i.push(n);return i}function eh(e,t,i){if(t.length===0)return e;if(e.length===0)return t;if(ot(t[0])&&ot(e[0]))return th(e,t,i);if(t.every((n)=>typeof n==="string")&&e.every((n)=>typeof n==="string")){let n=[...t];for(let r of e)if(!n.includes(r))n.push(r);return n}return t}function th(e,t,i){let n=[...t];for(let r of e){if(!ot(r)){n.push(r);continue}let o=["id","name","key","path","type"],s=!1;for(let a of o)if(a in r){if(n.find((c)=>ot(c)&&(a in c)&&c[a]===r[a])){s=!0;break}}if(!s)n.push(r)}return n}function ih(e,t,i,n){let r=t;if(ot(r)&&n.has(r))return n.get(r);let o={...e};if(ot(r))n.set(r,o);for(let s in r){if(!Object.prototype.hasOwnProperty.call(r,s))continue;let a=r[s],c=o[s];if(i.skipNullish&&(a===null||a===void 0))continue;if(a===null||a===void 0){o[s]=a;continue}if(ot(a)&&ot(c))o[s]=Ca(c,a,i,n);else if(Array.isArray(a)||Array.isArray(c))o[s]=wa(c,a,i.arrayMergeMode||"smart",n);else o[s]=a}return o}function va(e,t,i="replace"){return Xu(e,t,{arrayMergeMode:i==="replace"?"replace":"smart",skipNullish:!0})}function Wn(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!Wn(e[i],t[i]))return!1;return!0}if(ot(e)&&ot(t)){let i=Object.keys(e),n=Object.keys(t);if(i.length!==n.length)return!1;for(let r of i){if(!Object.prototype.hasOwnProperty.call(t,r))return!1;if(!Wn(e[r],t[r]))return!1}return!0}return!1}function ot(e){return Boolean(e&&typeof e==="object"&&!Array.isArray(e))}class Ea{extensions=[".ts",".js",".mjs",".cjs",".json",".mts",".cts"];async loadFromPath(e,t,i={}){let{arrayStrategy:n="replace",useCache:r=!0,cacheTtl:o,trackPerformance:s=!0,verbose:a=!1}=i;if(r){let f=fr.getWithFileCheck("file",e);if(f){if(a)console.log(`Configuration loaded from cache: ${e}`);return f}}let c=async()=>{if(!Xi(e))return null;try{let f=`?t=${Date.now()}`,u=await import(e+f),l=u.default||u,y="default"in u,p=Object.keys(u).length>0;if(!y&&!p)throw new Cr(e,Error("Configuration file is empty and exports nothing"),"unknown");if(typeof l!=="object"||l===null||Array.isArray(l))throw new Cr(e,Error("Configuration must export a valid object"),"unknown");let w={config:va(t,l,n),source:{type:"file",path:e,priority:100,timestamp:new Date}};if(r)fr.setWithFileCheck("file",w,e,o);return w}catch(f){throw f instanceof Error?oi.configLoad(e,f):oi.configLoad(e,Error(String(f)))}};if(s)return Bn.track("loadFromPath",c,{path:e});return c()}async tryLoadFromPaths(e,t,i={}){for(let n of e)try{let r=await this.loadFromPath(n,t,i);if(r)return r}catch(r){if(r instanceof Error&&r.name==="ConfigLoadError")throw r;if(i.verbose)console.warn(`Failed to load config from ${n}:`,r)}return null}generateConfigPaths(e,t,i){let n=this.generateNamePatterns(e,i),r=[];for(let o of n)for(let s of this.extensions)r.push(En(t,`${o}${s}`));return r}generateNamePatterns(e,t){let i=[];if(i.push("config",".config"),e)i.push(e,`.${e}.config`,`${e}.config`,`.${e}`);let n=t===void 0?[]:Array.isArray(t)?t:[t];for(let o of n){if(!o)continue;if(i.push(o,`.${o}.config`,`${o}.config`,`.${o}`),e)i.push(`${e}.${o}.config`,`.${e}.${o}.config`)}let r=new Set;return i.filter((o)=>{if(!o||r.has(o))return!1;return r.add(o),!0})}checkFileAccess(e){return Zu(async()=>Xi(e),{maxRetries:2,retryDelay:100,fallback:!1})}async discoverConfigFiles(e,t,i){let n=[];if(!Xi(e))return n;if(t||i){let r=this.generateNamePatterns(t||"",i);for(let o of r)for(let s of this.extensions){let a=En(e,`${o}${s}`);if(await this.checkFileAccess(a))n.push(a)}}else try{let{readdirSync:r}=await import("fs"),o=r(e);for(let s of o)if(this.looksLikeConfigFile(s)){let a=En(e,s);if(await this.checkFileAccess(a))n.push(a)}}catch{return[]}return n}looksLikeConfigFile(e){return[/\.config\.(ts|js|mjs|cjs|json|mts|cts)$/,/^\..*\.(ts|js|mjs|cjs|json|mts|cts)$/,/config\.(ts|js|mjs|cjs|json|mts|cts)$/].some((t)=>t.test(e))}async validateConfigFile(e){let t=[];try{if(!Xi(e))return t.push("Configuration file does not exist"),t;let i=await import(e),n=i.default||i;if(n===void 0)t.push("Configuration file must export a default value or named exports");else if(typeof n!=="object"||n===null)t.push("Configuration must be an object");else if(Array.isArray(n))t.push("Configuration cannot be an array at the root level");if(e.endsWith(".json"))try{let{readFileSync:r}=await import("fs"),o=r(e,"utf8");JSON.parse(o)}catch(r){t.push(`Invalid JSON syntax: ${r}`)}}catch(i){t.push(`Failed to load configuration file: ${i}`)}return t}async getFileModificationTime(e){try{let{statSync:t}=await import("fs");return t(e).mtime}catch{return null}}async preloadConfigurations(e,t={}){let i=new Map;return await Promise.allSettled(e.map(async(n)=>{try{let r=await this.loadFromPath(n,{},t);if(r)i.set(n,r.config)}catch(r){if(t.verbose)console.warn(`Failed to preload ${n}:`,r)}})),i}}class ba{async validateConfiguration(e,t,i={}){let{stopOnFirstError:n=!1,validateRequired:r=!0,validateTypes:o=!0,customRules:s=[],trackPerformance:a=!0,verbose:c=!1}=i,f=async()=>{let u=[],l=[],y={stopOnFirstError:n,validateRequired:r,validateTypes:o,customRules:s,trackPerformance:a,verbose:c};try{if(typeof t==="string")return await this.validateWithSchemaFile(e,t,y);else if(Array.isArray(t))return this.validateWithRules(e,[...t,...s],y);else return this.validateWithJSONSchema(e,t,y)}catch(p){return u.push({path:"",message:`Validation failed: ${p}`,rule:"system"}),{isValid:!1,errors:u,warnings:l}}};if(a)return await Bn.track("validateConfiguration",f);return f()}async validateWithSchemaFile(e,t,i){try{if(!Lf(t))throw new wr(t,[{path:"",message:"Schema file does not exist"}]);let n=await import(t),r=n.default||n;if(Array.isArray(r))return this.validateWithRules(e,r,i);else return this.validateWithJSONSchema(e,r,i)}catch(n){throw new wr(t,[{path:"",message:`Failed to load schema: ${n}`}])}}validateWithJSONSchema(e,t,i){let n=[],r=[];return this.validateObjectAgainstSchema(e,t,"",n,r,i),{isValid:n.length===0,errors:n,warnings:r}}validateObjectAgainstSchema(e,t,i,n,r,o){if(o.validateTypes&&t.type){let s=Array.isArray(e)?"array":typeof e,a=Array.isArray(t.type)?t.type:[t.type];if(!a.includes(s)){if(n.push({path:i,message:`Expected type ${a.join(" or ")}, got ${s}`,expected:a.join(" or "),actual:s,rule:"type"}),o.stopOnFirstError)return}}if(t.enum&&!t.enum.includes(e)){if(n.push({path:i,message:`Value must be one of: ${t.enum.join(", ")}`,expected:t.enum.join(", "),actual:e,rule:"enum"}),o.stopOnFirstError)return}if(typeof e==="string"){if(t.minLength!==void 0&&e.length<t.minLength)n.push({path:i,message:`String length must be at least ${t.minLength}`,expected:`>= ${t.minLength}`,actual:e.length,rule:"minLength"});if(t.maxLength!==void 0&&e.length>t.maxLength)n.push({path:i,message:`String length must not exceed ${t.maxLength}`,expected:`<= ${t.maxLength}`,actual:e.length,rule:"maxLength"});if(t.pattern){if(!new RegExp(t.pattern).test(e))n.push({path:i,message:`String does not match pattern ${t.pattern}`,expected:t.pattern,actual:e,rule:"pattern"})}}if(typeof e==="number"){if(t.minimum!==void 0&&e<t.minimum)n.push({path:i,message:`Value must be at least ${t.minimum}`,expected:`>= ${t.minimum}`,actual:e,rule:"minimum"});if(t.maximum!==void 0&&e>t.maximum)n.push({path:i,message:`Value must not exceed ${t.maximum}`,expected:`<= ${t.maximum}`,actual:e,rule:"maximum"})}if(Array.isArray(e)&&t.items)for(let s=0;s<e.length;s++){let a=i?`${i}[${s}]`:`[${s}]`;if(this.validateObjectAgainstSchema(e[s],t.items,a,n,r,o),o.stopOnFirstError&&n.length>0)return}if(e&&typeof e==="object"&&!Array.isArray(e)){let s=e;if(o.validateRequired&&t.required){for(let a of t.required)if(!(a in s)){if(n.push({path:i?`${i}.${a}`:a,message:`Missing required property '${a}'`,expected:"required",rule:"required"}),o.stopOnFirstError)return}}if(t.properties){for(let[a,c]of Object.entries(t.properties))if(a in s){let f=i?`${i}.${a}`:a;if(this.validateObjectAgainstSchema(s[a],c,f,n,r,o),o.stopOnFirstError&&n.length>0)return}}if(t.additionalProperties===!1){let a=new Set(Object.keys(t.properties||{}));for(let c of Object.keys(s))if(!a.has(c))r.push({path:i?`${i}.${c}`:c,message:`Additional property '${c}' is not allowed`,rule:"additionalProperties"})}}}validateWithRules(e,t,i){let n=[],r=[];for(let o of t)try{let s=this.getValueByPath(e,o.path),a=this.validateWithRule(s,o,o.path);if(n.push(...a),i.stopOnFirstError&&n.length>0)break}catch(s){n.push({path:o.path,message:`Rule validation failed: ${s}`,rule:"system"})}return{isValid:n.length===0,errors:n,warnings:r}}validateWithRule(e,t,i){let n=[];if(t.required&&(e===void 0||e===null))return n.push({path:i,message:t.message||`Property '${i}' is required`,expected:"required",rule:"required"}),n;if(e===void 0||e===null)return n;if(t.type){let r=Array.isArray(e)?"array":typeof e;if(r!==t.type)n.push({path:i,message:t.message||`Expected type ${t.type}, got ${r}`,expected:t.type,actual:r,rule:"type"})}if(t.min!==void 0){let r=Array.isArray(e)?e.length:typeof e==="string"?e.length:typeof e==="number"?e:0;if(r<t.min)n.push({path:i,message:t.message||`Value must be at least ${t.min}`,expected:`>= ${t.min}`,actual:r,rule:"min"})}if(t.max!==void 0){let r=Array.isArray(e)?e.length:typeof e==="string"?e.length:typeof e==="number"?e:0;if(r>t.max)n.push({path:i,message:t.message||`Value must not exceed ${t.max}`,expected:`<= ${t.max}`,actual:r,rule:"max"})}if(t.pattern&&typeof e==="string"){if(!t.pattern.test(e))n.push({path:i,message:t.message||`Value does not match pattern ${t.pattern}`,expected:t.pattern.toString(),actual:e,rule:"pattern"})}if(t.enum&&!t.enum.includes(e))n.push({path:i,message:t.message||`Value must be one of: ${t.enum.join(", ")}`,expected:t.enum.join(", "),actual:e,rule:"enum"});if(t.validator){let r=t.validator(e);if(r)n.push({path:i,message:t.message||r,rule:"custom"})}return n}getValueByPath(e,t){if(!t)return e;let i=t.split("."),n=e;for(let r of i)if(n&&typeof n==="object"&&r in n)n=n[r];else return;return n}generateRulesFromInterface(e){let t=[],i=e.matchAll(/(\w+)(\?)?:\s*(\w+)/g);for(let n of i){let[,r,o,s]=n;t.push({path:r,required:!o,type:this.mapTypeScriptType(s)})}return t}mapTypeScriptType(e){switch(e.toLowerCase()){case"string":return"string";case"number":return"number";case"boolean":return"boolean";case"array":return"array";case"object":return"object";default:return"object"}}static createCommonRules(){return{server:[{path:"port",required:!0,type:"number",min:1,max:65535},{path:"host",required:!0,type:"string",min:1},{path:"ssl",type:"boolean"}],database:[{path:"url",required:!0,type:"string",min:1},{path:"pool",type:"number",min:1,max:100},{path:"timeout",type:"number",min:0}],api:[{path:"baseUrl",required:!0,type:"string",pattern:rh},{path:"timeout",type:"number",min:0},{path:"retries",type:"number",min:0,max:10}]}}}function nh(e){if(!e)return"";let t=Array.isArray(e)?e.filter(Boolean):[e];if(t.length===0)return"";if(t.length===1)return` or alias "${t[0]}"`;return` or aliases ${t.map((i)=>`"${i}"`).join(", ")}`}class Sa{fileLoader=new Ea;envProcessor=new Jn;validator=new ba;async loadConfig(e){let t=Date.now(),{cache:i,performance:n,schema:r,validate:o,...s}=e;try{if(i?.enabled){let c=this.checkCache(s.name||"",s);if(c)return c}let a;try{a=await this.loadConfigurationStrategies(s,!0,i)}catch(c){let f=s.__strictErrorHandling;if(c instanceof Error&&c.name==="ConfigNotFoundError"){if(f)throw c;a={...await this.applyEnvironmentVariables(s.name||"",s.defaultConfig,s.checkEnv!==!1,s.verbose||!1),warnings:[`No configuration file found for "${s.name||"config"}", using defaults with environment variables`]}}else if(c instanceof Error&&c.name==="ConfigLoadError"){let u=c.message.includes("EACCES")||c.message.includes("EPERM")||c.message.includes("permission denied"),l=!u&&(c.message.includes("syntax")||c.message.includes("Expected")||c.message.includes("Unexpected")||c.message.includes("BuildMessage")||c.message.includes("errors building")),y=c.message.includes("Configuration must export a valid object")||c.message.includes("Configuration file is empty and exports nothing");if(f&&(y||u))throw c;if(l&&(!f||!y))a={...await this.applyEnvironmentVariables(s.name||"",s.defaultConfig,s.checkEnv!==!1,s.verbose||!1),warnings:["Configuration file has syntax errors, using defaults with environment variables"]};else if(!f)a={...await this.applyEnvironmentVariables(s.name||"",s.defaultConfig,s.checkEnv!==!1,s.verbose||!1),warnings:[`Configuration loading error, using defaults: ${c.message}`]};else throw c}else a={...await this.applyEnvironmentVariables(s.name||"",s.defaultConfig,s.checkEnv!==!1,s.verbose||!1),warnings:[`Configuration loading failed, using defaults: ${c instanceof Error?c.message:String(c)}`]}}if(r||o)await this.validateConfiguration(a.config,r,o,s.name);if(i?.enabled&&a)this.cacheResult(s.name||"",a,i,s);if(n?.enabled){let c={operation:"loadConfig",duration:Date.now()-t,configName:s.name,timestamp:new Date};if(n.onMetrics)n.onMetrics(c);if(n.slowThreshold&&c.duration>n.slowThreshold)yt.warn(`Slow configuration loading detected: ${c.duration}ms for ${s.name}`);a.metrics=c}return a}catch(a){if(a instanceof Error&&a.name==="ConfigNotFoundError")throw a;let c=Date.now()-t;throw yt.error(`Configuration loading failed after ${c}ms:`,[a instanceof Error?a:Error(String(a))]),a}}async loadConfigurationStrategies(e,t=!1,i){let{name:n="",alias:r,cwd:o,configDir:s,defaultConfig:a,checkEnv:c=!0,arrayStrategy:f="replace",verbose:u=!1}=e,l=o||vr.cwd(),y=[],p=await this.loadLocalConfiguration(n,r,l,s,a,f,u,c,i);if(p)return y.push(...this.getLocalSearchPaths(n,r,l,s)),this.finalizeResult(p,y,c,n,u);let w=await this.loadHomeConfiguration(n,r,a,f,u,c);if(w)return y.push(...this.getHomeSearchPaths(n,r)),this.finalizeResult(w,y,c,n,u);let S=await this.loadPackageJsonConfiguration(n,r,l,a,f,u,c);if(S)return y.push(rt(l,"package.json")),this.finalizeResult(S,y,c,n,u);if(y.push(...this.getAllSearchPaths(n,r,l,s)),t)throw oi.configNotFound(n,y,r);return{...await this.applyEnvironmentVariables(n,a,c,u),warnings:[`No configuration file found for "${n}"${nh(r)}, using defaults with environment variables`]}}async loadLocalConfiguration(e,t,i,n,r,o,s,a,c){let f=a?er(e,r,s):r,u=this.getLocalDirectories(i,n);for(let l of u){if(s)yt.info(`Searching for configuration in: ${l}`);let y=this.fileLoader.generateConfigPaths(e,l,t),p=await this.fileLoader.tryLoadFromPaths(y,f,{arrayStrategy:o,verbose:s,cacheTtl:c?.ttl,useCache:!c?.ttl||c.ttl>100});if(p){if(s)yt.success(`Configuration loaded from: ${p.source.path}`);return p}}return null}async loadHomeConfiguration(e,t,i,n,r,o){if(!e)return null;let s=o?er(e,i,r):i,a=[rt(Ht(),".config",e),rt(Ht(),".config"),Ht()];for(let c of a){if(r)yt.info(`Checking home directory: ${c}`);let f=this.fileLoader.generateConfigPaths(e,c,t),u=await this.fileLoader.tryLoadFromPaths(f,s,{arrayStrategy:n,verbose:r});if(u){if(r)yt.success(`Configuration loaded from home directory: ${u.source.path}`);return u}}return null}async loadPackageJsonConfiguration(e,t,i,n,r,o,s){let a=s?er(e,n,o):n;try{let c=rt(i,"package.json");if(!Yc(c))return null;let f={};try{f=JSON.parse(Zc(c,"utf8"))}catch(y){if(o)yt.warn("Failed to parse package.json:",[y instanceof Error?y:Error(String(y))]);return null}let u=f[e],l=e;if(!u&&t){let y=Array.isArray(t)?t:[t];for(let p of y){if(!p)continue;if(f[p]){u=f[p],l=p;break}}}if(u&&typeof u==="object"&&!Array.isArray(u)){if(o)yt.success(`Configuration loaded from package.json: ${l}`);return{config:va(a,u,r),source:{type:"package.json",path:c,priority:30,timestamp:new Date}}}}catch(c){if(o)yt.warn("Failed to load package.json:",[c instanceof Error?c:Error(String(c))])}return null}async applyEnvironmentVariables(e,t,i,n){if(!i||!e||typeof t!=="object"||t===null||Array.isArray(t))return{config:t,source:{type:"default",priority:10,timestamp:new Date}};return{config:er(e,t,n),source:{type:"environment",priority:20,timestamp:new Date}}}async finalizeResult(e,t,i,n,r){return{config:e.config,source:e.source,path:e.source.path}}async validateConfiguration(e,t,i,n){let r=[];if(i){let o=i(e);if(o)r.push(...o)}if(t){let o=await this.validator.validateConfiguration(e,t);if(!o.isValid)r.push(...o.errors.map((s)=>s.path?`${s.path}: ${s.message}`:s.message))}if(r.length>0)throw oi.configValidation(n||"unknown",r,n)}checkCache(e,t){let i=this.generateCacheKey(e,t);return fr.get(i)||null}cacheResult(e,t,i,n){let r=this.generateCacheKey(e,n);fr.set(r,t,void 0,i.ttl)}generateCacheKey(e,t){let i=[e];if(t.alias){let n=Array.isArray(t.alias)?t.alias.join(","):t.alias;i.push(`alias:${n}`)}if(t.cwd)i.push(`cwd:${t.cwd}`);if(t.configDir)i.push(`configDir:${t.configDir}`);if("checkEnv"in t)i.push(`checkEnv:${t.checkEnv}`);return i.join("|")}getLocalDirectories(e,t){return Array.from(new Set([e,rt(e,"config"),rt(e,".config"),t?rt(e,t):void 0].filter(Boolean)))}getAllSearchPaths(e,t,i,n){let r=[];return r.push(...this.getLocalSearchPaths(e,t,i,n)),r.push(...this.getHomeSearchPaths(e,t)),r.push(rt(i,"package.json")),r}getLocalSearchPaths(e,t,i,n){let r=this.getLocalDirectories(i,n),o=[];for(let s of r)o.push(...this.fileLoader.generateConfigPaths(e,s,t));return o}getHomeSearchPaths(e,t){if(!e)return[];let i=[rt(Ht(),".config",e),rt(Ht(),".config"),Ht()],n=[];for(let r of i)n.push(...this.fileLoader.generateConfigPaths(e,r,t));return n}async loadConfigWithResult(e){return this.loadConfig(e)}}function er(e,t,i=!1){let n=new Jn,r=e.toUpperCase().replace(/[^A-Z0-9]/g,"_");function o(s,a=[]){let c={...s};for(let[f,u]of Object.entries(s)){let l=[...a,f],y=[`${r}_${l.join("_").toUpperCase()}`,`${r}_${l.map((S)=>S.toUpperCase()).join("")}`,`${r}_${l.map((S)=>S.replace(/([A-Z])/g,"_$1").toUpperCase()).join("")}`],p,w;for(let S of y)if(p=vr.env[S],p!==void 0){w=S;break}if(p!==void 0&&w)if(typeof u==="boolean")c[f]=["true","1","yes"].includes(p.toLowerCase());else if(typeof u==="number"){let S=Number(p);if(!Number.isNaN(S))c[f]=S}else if(Array.isArray(u))try{c[f]=JSON.parse(p)}catch{c[f]=p.split(",").map((S)=>S.trim())}else c[f]=p;else if(u&&typeof u==="object"&&!Array.isArray(u))c[f]=o(u,l)}return c}return o(t)}var fr,Bn,Wf,Bf=(e)=>e,jf=(e,t)=>{for(var i in t)Wf(e,i,{get:t[i],enumerable:!0,configurable:!0,set:Gf.bind(t,i)})},_f=(e,t)=>()=>(e&&(t=e(e=0)),t),Ks,ea,ni,yi,ta,pu,gu,Ps,ir,On,Ve,$e,yu,Os,Cu,ks,wu,vu,bn,Eu,Ms,Ds,Sn,bu,Su,$u,Au,rr,ia,xu,Ue,Tu,Ru,Is,nr,kn,Le,ae,Pu,Fs,Ou,Ns,ku,Mu,$n,Du,Ls,Ws,Iu,An,Fu,Nu,Lu,Wu,Bu,or,ra,Gu,ju="0.15.6",et,pr,pi,Mn,Dn,gr,In,Fn,gi,Nn,Ln,Pt,na,oa,ft,Et,sa,aa,_u,Uu,la,yr,Fg,fa,ce,Ng,zu,Lg,Hu,Wg,Bg,Bs,Gg,Ju,qu,jg,Gs,_g,Vg,Ug,Kg,zg,xn,Yu,Hg,ut,ua,Cr,ha,da,Hn,ma,pa,wr,ga,ya,oi,rh,yt,Jg,qg,Yg,oh,$a;var Aa=pe(()=>{fr=new Vs,Bn=new Us,Wf=Object.defineProperty;Ks={};jf(Ks,{withErrorRecovery:()=>Js,tryLoadConfig:()=>uu,loadConfigWithResult:()=>cu,loadConfig:()=>Qs,isRetryableError:()=>ru,isConfigNotFoundError:()=>iu,isBunfigError:()=>qs,globalPerformanceMonitor:()=>yi,globalCache:()=>ni,getEnvOrDefault:()=>nu,generateConfigTypes:()=>hu,defaultGeneratedDir:()=>aa,defaultConfigDir:()=>sa,deepMergeWithArrayStrategy:()=>Un,deepMerge:()=>Ys,createLibraryConfig:()=>du,config:()=>fu,bunfigPlugin:()=>mu,applyEnvVarsToConfig:()=>di,TypeGenerationError:()=>Fn,SchemaValidationError:()=>gi,PluginError:()=>Ln,PerformanceMonitor:()=>jn,FileSystemError:()=>In,ErrorFactory:()=>Pt,EnvVarError:()=>gr,EnvProcessor:()=>Er,ConfigValidator:()=>Kn,ConfigValidationError:()=>Mn,ConfigNotFoundError:()=>pr,ConfigMergeError:()=>Dn,ConfigLoader:()=>zn,ConfigLoadError:()=>pi,ConfigFileLoader:()=>br,ConfigCache:()=>Gn,CacheUtils:()=>ta,BunfigError:()=>et,BrowserConfigError:()=>Nn,ArrayMergeStrategies:()=>na});_u=_f(async()=>{ea=import.meta.require,ni=new Gn,yi=new jn,ta={createKey:Vf,isEquivalent:Uf,estimateMemoryUsage:Kf},pu=lr(Rn.cwd(),"config"),gu=lr(Rn.cwd(),"src/generated"),Ps=ar.env.CLARITY_LOG_DIR||nf(Jf(),"logs"),ir={level:"info",defaultName:"clarity",timestamp:!0,colors:!0,format:"text",maxLogSize:10485760,logDatePattern:"YYYY-MM-DD",logDirectory:Ps,rotation:{frequency:"daily",maxSize:10485760,maxFiles:5,compress:!1,rotateHour:0,rotateMinute:0,rotateDayOfWeek:0,rotateDayOfMonth:1,encrypt:!1},verbose:!1},On=await qf(),Ve={red:(e)=>`\x1B[31m${e}\x1B[0m`,green:(e)=>`\x1B[32m${e}\x1B[0m`,yellow:(e)=>`\x1B[33m${e}\x1B[0m`,blue:(e)=>`\x1B[34m${e}\x1B[0m`,magenta:(e)=>`\x1B[35m${e}\x1B[0m`,cyan:(e)=>`\x1B[36m${e}\x1B[0m`,white:(e)=>`\x1B[37m${e}\x1B[0m`,gray:(e)=>`\x1B[90m${e}\x1B[0m`,bgRed:(e)=>`\x1B[41m${e}\x1B[0m`,bgYellow:(e)=>`\x1B[43m${e}\x1B[0m`,bold:(e)=>`\x1B[1m${e}\x1B[0m`,dim:(e)=>`\x1B[2m${e}\x1B[0m`,italic:(e)=>`\x1B[3m${e}\x1B[0m`,underline:(e)=>`\x1B[4m${e}\x1B[0m`,reset:"\x1B[0m"},$e=Ve,yu=Ve.red,Os=Ve.green,Cu=Ve.yellow,ks=Ve.blue,wu=Ve.magenta,vu=Ve.cyan,bn=Ve.white,Eu=Ve.gray,Ms=Ve.bgRed,Ds=Ve.bgYellow,Sn=Ve.bold,bu=Ve.dim,Su=Ve.italic,$u=Ve.underline,Au=Ve.reset,rr={activationLevel:"error",bufferSize:50,flushOnDeactivation:!0,stopBuffering:!1},ia={debug:"\uD83D\uDD0D",info:ks("\u2139"),success:Os("\u2713"),warning:Ds(bn(Sn(" WARN "))),error:Ms(bn(Sn(" ERROR ")))},xu=new hr("stacks"),Ue=new hr("bunfig",{showTags:!0}),Tu=He(mi.cwd(),"config"),Ru=He(mi.cwd(),"src/generated"),Is=sr.env.CLARITY_LOG_DIR||tf(Qf(),"logs"),nr={level:"info",defaultName:"clarity",timestamp:!0,colors:!0,format:"text",maxLogSize:10485760,logDatePattern:"YYYY-MM-DD",logDirectory:Is,rotation:{frequency:"daily",maxSize:10485760,maxFiles:5,compress:!1,rotateHour:0,rotateMinute:0,rotateDayOfWeek:0,rotateDayOfMonth:1,encrypt:!1},verbose:!1,writeToFile:!1},kn=await eu(),Le={red:(e)=>`\x1B[31m${e}\x1B[0m`,green:(e)=>`\x1B[32m${e}\x1B[0m`,yellow:(e)=>`\x1B[33m${e}\x1B[0m`,blue:(e)=>`\x1B[34m${e}\x1B[0m`,magenta:(e)=>`\x1B[35m${e}\x1B[0m`,cyan:(e)=>`\x1B[36m${e}\x1B[0m`,white:(e)=>`\x1B[37m${e}\x1B[0m`,gray:(e)=>`\x1B[90m${e}\x1B[0m`,bgRed:(e)=>`\x1B[41m${e}\x1B[0m`,bgYellow:(e)=>`\x1B[43m${e}\x1B[0m`,bgGray:(e)=>`\x1B[100m${e}\x1B[0m`,bold:(e)=>`\x1B[1m${e}\x1B[0m`,dim:(e)=>`\x1B[2m${e}\x1B[0m`,italic:(e)=>`\x1B[3m${e}\x1B[0m`,underline:(e)=>`\x1B[4m${e}\x1B[0m`,strikethrough:(e)=>`\x1B[9m${e}\x1B[0m`,reset:"\x1B[0m"},ae=Le,Pu=Le.red,Fs=Le.green,Ou=Le.yellow,Ns=Le.blue,ku=Le.magenta,Mu=Le.cyan,$n=Le.white,Du=Le.gray,Ls=Le.bgRed,Ws=Le.bgYellow,Iu=Le.bgGray,An=Le.bold,Fu=Le.dim,Nu=Le.italic,Lu=Le.underline,Wu=Le.strikethrough,Bu=Le.reset,or={activationLevel:"error",bufferSize:50,flushOnDeactivation:!0,stopBuffering:!1},ra={debug:"\uD83D\uDD0D",info:Ns("\u2139"),success:Fs("\u2713"),warning:Ws($n(An(" WARN "))),error:Ls($n(An(" ERROR ")))},Gu=new mr("stacks"),et=class extends Error{timestamp;context;constructor(e,t={}){super(e);if(this.name=this.constructor.name,this.timestamp=new Date,this.context=t,Error.captureStackTrace)Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,code:this.code,message:this.message,timestamp:this.timestamp.toISOString(),context:this.context,stack:this.stack}}toString(){let e=Object.keys(this.context).length>0?` (${Object.entries(this.context).map(([t,i])=>`${t}: ${i}`).join(", ")})`:"";return`${this.name} [${this.code}]: ${this.message}${e}`}},pr=class extends et{code="CONFIG_NOT_FOUND";constructor(e,t,i){let n=i?` or alias "${i}"`:"";super(`Configuration "${e}"${n} not found`,{configName:e,alias:i,searchPaths:t,searchPathCount:t.length})}},pi=class extends et{code="CONFIG_LOAD_ERROR";constructor(e,t,i){super(`Failed to load configuration from "${e}": ${t.message}`,{configPath:e,configName:i,originalError:t.name,originalMessage:t.message});this.cause=t}},Mn=class extends et{code="CONFIG_VALIDATION_ERROR";constructor(e,t,i){super(`Configuration validation failed for "${e}"`,{configPath:e,configName:i,validationErrors:t,errorCount:t.length})}},Dn=class extends et{code="CONFIG_MERGE_ERROR";constructor(e,t,i,n){super(`Failed to merge configuration from "${e}" with "${t}": ${i.message}`,{sourcePath:e,targetPath:t,configName:n,originalError:i.name,originalMessage:i.message});this.cause=i}},gr=class extends et{code="ENV_VAR_ERROR";constructor(e,t,i,n){super(`Failed to parse environment variable "${e}" with value "${t}" as ${i}`,{envKey:e,envValue:t,expectedType:i,configName:n})}},In=class extends et{code="FILE_SYSTEM_ERROR";constructor(e,t,i){super(`File system ${e} failed for "${t}": ${i.message}`,{operation:e,path:t,originalError:i.name,originalMessage:i.message});this.cause=i}},Fn=class extends et{code="TYPE_GENERATION_ERROR";constructor(e,t,i){super(`Failed to generate types from "${e}" to "${t}": ${i.message}`,{configDir:e,outputPath:t,originalError:i.name,originalMessage:i.message});this.cause=i}},gi=class extends et{code="SCHEMA_VALIDATION_ERROR";constructor(e,t,i){super(`Schema validation failed${i?` for config "${i}"`:""}`,{schemaPath:e,configName:i,validationErrors:t,errorCount:t.length})}},Nn=class extends et{code="BROWSER_CONFIG_ERROR";constructor(e,t,i,n){super(`Failed to fetch configuration from "${e}": ${t} ${i}`,{endpoint:e,status:t,statusText:i,configName:n})}},Ln=class extends et{code="PLUGIN_ERROR";constructor(e,t,i){super(`Plugin "${e}" failed during ${t}: ${i.message}`,{pluginName:e,operation:t,originalError:i.name,originalMessage:i.message});this.cause=i}},Pt={configNotFound(e,t,i){return new pr(e,t,i)},configLoad(e,t,i){return new pi(e,t,i)},configValidation(e,t,i){return new Mn(e,t,i)},configMerge(e,t,i,n){return new Dn(e,t,i,n)},envVar(e,t,i,n){return new gr(e,t,i,n)},fileSystem(e,t,i){return new In(e,t,i)},typeGeneration(e,t,i){return new Fn(e,t,i)},schemaValidation(e,t,i){return new gi(e,t,i)},browserConfig(e,t,i,n){return new Nn(e,t,i,n)},plugin(e,t,i){return new Ln(e,t,i)}},na={replace:"replace",concat:"concat",smart:"smart"},oa=/^https?:\/\//,ft=new mr("bunfig",{showTags:!0}),Et=new zn,sa=Je(It.cwd(),"config"),aa=Je(It.cwd(),"src/generated")});Uu=cr.env.CLARITY_LOG_DIR||xf(Vu(),"logs"),la={level:"info",defaultName:"clarity",timestamp:!0,colors:!0,format:"text",maxLogSize:10485760,logDatePattern:"YYYY-MM-DD",logDirectory:Uu,rotation:{frequency:"daily",maxSize:10485760,maxFiles:5,compress:!1,rotateHour:0,rotateMinute:0,rotateDayOfWeek:0,rotateDayOfMonth:1,encrypt:!1},verbose:!1,writeToFile:!1},yr={...la},Fg=(async()=>{try{let{loadConfig:e}=await _u().then(()=>Ks),t=await e({name:"clarity",alias:"logging",defaultConfig:la,cwd:cr.cwd()});if(t)Object.assign(yr,t)}catch{}return yr})();fa={red:(e)=>`\x1B[31m${e}\x1B[0m`,green:(e)=>`\x1B[32m${e}\x1B[0m`,yellow:(e)=>`\x1B[33m${e}\x1B[0m`,blue:(e)=>`\x1B[34m${e}\x1B[0m`,magenta:(e)=>`\x1B[35m${e}\x1B[0m`,cyan:(e)=>`\x1B[36m${e}\x1B[0m`,white:(e)=>`\x1B[37m${e}\x1B[0m`,gray:(e)=>`\x1B[90m${e}\x1B[0m`,bgRed:(e)=>`\x1B[41m${e}\x1B[0m`,bgYellow:(e)=>`\x1B[43m${e}\x1B[0m`,bgGray:(e)=>`\x1B[100m${e}\x1B[0m`,bold:(e)=>`\x1B[1m${e}\x1B[0m`,dim:(e)=>`\x1B[2m${e}\x1B[0m`,italic:(e)=>`\x1B[3m${e}\x1B[0m`,underline:(e)=>`\x1B[4m${e}\x1B[0m`,strikethrough:(e)=>`\x1B[9m${e}\x1B[0m`,reset:"\x1B[0m"},ce=fa,{red:Ng,green:zu,yellow:Lg,blue:Hu,magenta:Wg,cyan:Bg,white:Bs,gray:Gg,bgRed:Ju,bgYellow:qu,bgGray:jg,bold:Gs,dim:_g,italic:Vg,underline:Ug,strikethrough:Kg,reset:zg}=fa,xn={activationLevel:"error",bufferSize:50,flushOnDeactivation:!0,stopBuffering:!1},Yu={debug:"\uD83D\uDD0D",info:Hu("\u2139"),success:zu("\u2713"),warning:qu(Bs(Gs(" WARN "))),error:Ju(Bs(Gs(" ERROR ")))};Hg=new Sr("stacks");ut=class ut extends Error{timestamp;context;constructor(e,t={}){super(e);if(this.name=this.constructor.name,this.timestamp=new Date,this.context=t,Error.captureStackTrace)Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,code:this.code,message:this.message,timestamp:this.timestamp.toISOString(),context:this.context,stack:this.stack}}toString(){let e=Object.keys(this.context).length>0?` (${Object.entries(this.context).map(([t,i])=>`${t}: ${i}`).join(", ")})`:"";return`${this.name} [${this.code}]: ${this.message}${e}`}};ua=class ua extends ut{code="CONFIG_NOT_FOUND";constructor(e,t,i){let n=i===void 0?[]:Array.isArray(i)?i.filter(Boolean):[i],r="";if(n.length===1)r=` or alias "${n[0]}"`;else if(n.length>1)r=` or aliases ${n.map((o)=>`"${o}"`).join(", ")}`;super(`Configuration "${e}"${r} not found`,{configName:e,alias:i,searchPaths:t,searchPathCount:t.length})}};Cr=class Cr extends ut{code="CONFIG_LOAD_ERROR";constructor(e,t,i){super(`Failed to load configuration from "${e}": ${t.message}`,{configPath:e,configName:i,originalError:t.name,originalMessage:t.message});this.cause=t}};ha=class ha extends ut{code="CONFIG_VALIDATION_ERROR";constructor(e,t,i){super(`Configuration validation failed for "${e}"`,{configPath:e,configName:i,validationErrors:t,errorCount:t.length})}};da=class da extends ut{code="CONFIG_MERGE_ERROR";constructor(e,t,i,n){super(`Failed to merge configuration from "${e}" with "${t}": ${i.message}`,{sourcePath:e,targetPath:t,configName:n,originalError:i.name,originalMessage:i.message});this.cause=i}};Hn=class Hn extends ut{code="ENV_VAR_ERROR";constructor(e,t,i,n){super(`Failed to parse environment variable "${e}" with value "${t}" as ${i}`,{envKey:e,envValue:t,expectedType:i,configName:n})}};ma=class ma extends ut{code="FILE_SYSTEM_ERROR";constructor(e,t,i){super(`File system ${e} failed for "${t}": ${i.message}`,{operation:e,path:t,originalError:i.name,originalMessage:i.message});this.cause=i}};pa=class pa extends ut{code="TYPE_GENERATION_ERROR";constructor(e,t,i){super(`Failed to generate types from "${e}" to "${t}": ${i.message}`,{configDir:e,outputPath:t,originalError:i.name,originalMessage:i.message});this.cause=i}};wr=class wr extends ut{code="SCHEMA_VALIDATION_ERROR";constructor(e,t,i){super(`Schema validation failed${i?` for config "${i}"`:""}`,{schemaPath:e,configName:i,validationErrors:t,errorCount:t.length})}};ga=class ga extends ut{code="BROWSER_CONFIG_ERROR";constructor(e,t,i,n){super(`Failed to fetch configuration from "${e}": ${t} ${i}`,{endpoint:e,status:t,statusText:i,configName:n})}};ya=class ya extends ut{code="PLUGIN_ERROR";constructor(e,t,i){super(`Plugin "${e}" failed during ${t}: ${i.message}`,{pluginName:e,operation:t,originalError:i.name,originalMessage:i.message});this.cause=i}};oi={configNotFound(e,t,i){return new ua(e,t,i)},configLoad(e,t,i){return new Cr(e,t,i)},configValidation(e,t,i){return new ha(e,t,i)},configMerge(e,t,i,n){return new da(e,t,i,n)},envVar(e,t,i,n){return new Hn(e,t,i,n)},fileSystem(e,t,i){return new ma(e,t,i)},typeGeneration(e,t,i){return new pa(e,t,i)},schemaValidation(e,t,i){return new wr(e,t,i)},browserConfig(e,t,i,n){return new ga(e,t,i,n)},plugin(e,t,i){return new ya(e,t,i)}};rh=/^https?:\/\//;yt=new Sr("bunfig",{showTags:!0});Jg=new Sa;qg=rt(vr.cwd(),"config"),Yg=rt(vr.cwd(),"src/generated"),oh={cwd:qc.cwd(),root:"./src",entrypoints:["**/*.{ts,tsx,mts,cts,vue,stx}"],outdir:"./dist",keepComments:!0,clean:!0,tsconfigPath:"./tsconfig.json",outputStructure:"mirror",verbose:!1,importOrder:["bun"],declarationMap:!1},$a=oh});function xa(e,t,i){let n={file:t,message:"Unknown error",code:Ci.UNKNOWN_ERROR};if(e instanceof Error){n.message=e.message,n.stack=e.stack;let r=e.message.match(/\((\d+),(\d+)\)/);if(r)n.location={line:Number.parseInt(r[1],10),column:Number.parseInt(r[2],10)};if(e.message.includes("Cannot find")||e.message.includes("not found"))n.code=Ci.FILE_NOT_FOUND,n.suggestion="Check that the file path is correct and the file exists.";else if(e.message.includes("syntax")||e.message.includes("Unexpected token"))n.code=Ci.SYNTAX_ERROR,n.suggestion="Check for syntax errors in your TypeScript code.";else if(e.message.includes("type")&&e.message.includes("cannot"))n.code=Ci.TYPE_INFERENCE_ERROR,n.suggestion="Add explicit type annotations to help with type inference.";else if(e.message.includes("parse")||e.message.includes("Parse"))n.code=Ci.PARSE_ERROR,n.suggestion="The file contains invalid TypeScript syntax."}else if(typeof e==="string")n.message=e;return n}function Ta(e,t){let i=[],n=e.file;if(e.location)n+=`:${e.location.line}:${e.location.column}`;if(e.code)n+=` [${e.code}]`;if(i.push(n),i.push(` Error: ${e.message}`),t&&e.location){i.push("");let r=t.split(`
90
+ `;return i}}function Xu(e,t,i={}){return Ca(e,t,i,new WeakMap)}function Ca(e,t,i,n){let{arrayMergeMode:r="replace",skipNullish:o=!1,customMerger:s}=i;if(t===null||t===void 0)return o?e:t;if(s){let a=s(e,t);if(a!==void 0)return a}if(Array.isArray(t)||Array.isArray(e))return wa(e,t,r,n);if(!st(t)||!st(e))return t;return ih(e,t,i,n)}function wa(e,t,i,n){if(Array.isArray(t)&&!Array.isArray(e))return t;if(Array.isArray(e)&&!Array.isArray(t))return t;if(Array.isArray(t)&&Array.isArray(e))switch(i){case"replace":return t;case"concat":return Qu(e,t);case"smart":return eh(e,t,n);default:return t}return t}function Qu(e,t){let i=[...t];for(let n of e)if(!i.some((r)=>Wn(r,n)))i.push(n);return i}function eh(e,t,i){if(t.length===0)return e;if(e.length===0)return t;if(st(t[0])&&st(e[0]))return th(e,t,i);if(t.every((n)=>typeof n==="string")&&e.every((n)=>typeof n==="string")){let n=[...t];for(let r of e)if(!n.includes(r))n.push(r);return n}return t}function th(e,t,i){let n=[...t];for(let r of e){if(!st(r)){n.push(r);continue}let o=["id","name","key","path","type"],s=!1;for(let a of o)if(a in r){if(n.find((c)=>st(c)&&(a in c)&&c[a]===r[a])){s=!0;break}}if(!s)n.push(r)}return n}function ih(e,t,i,n){let r=t;if(st(r)&&n.has(r))return n.get(r);let o={...e};if(st(r))n.set(r,o);for(let s in r){if(!Object.prototype.hasOwnProperty.call(r,s))continue;let a=r[s],c=o[s];if(i.skipNullish&&(a===null||a===void 0))continue;if(a===null||a===void 0){o[s]=a;continue}if(st(a)&&st(c))o[s]=Ca(c,a,i,n);else if(Array.isArray(a)||Array.isArray(c))o[s]=wa(c,a,i.arrayMergeMode||"smart",n);else o[s]=a}return o}function va(e,t,i="replace"){return Xu(e,t,{arrayMergeMode:i==="replace"?"replace":"smart",skipNullish:!0})}function Wn(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!Wn(e[i],t[i]))return!1;return!0}if(st(e)&&st(t)){let i=Object.keys(e),n=Object.keys(t);if(i.length!==n.length)return!1;for(let r of i){if(!Object.prototype.hasOwnProperty.call(t,r))return!1;if(!Wn(e[r],t[r]))return!1}return!0}return!1}function st(e){return Boolean(e&&typeof e==="object"&&!Array.isArray(e))}class Ea{extensions=[".ts",".js",".mjs",".cjs",".json",".mts",".cts"];async loadFromPath(e,t,i={}){let{arrayStrategy:n="replace",useCache:r=!0,cacheTtl:o,trackPerformance:s=!0,verbose:a=!1}=i;if(r){let f=fr.getWithFileCheck("file",e);if(f){if(a)console.log(`Configuration loaded from cache: ${e}`);return f}}let c=async()=>{if(!Xi(e))return null;try{let f=`?t=${Date.now()}`,u=await import(e+f),l=u.default||u,y="default"in u,p=Object.keys(u).length>0;if(!y&&!p)throw new Cr(e,Error("Configuration file is empty and exports nothing"),"unknown");if(typeof l!=="object"||l===null||Array.isArray(l))throw new Cr(e,Error("Configuration must export a valid object"),"unknown");let w={config:va(t,l,n),source:{type:"file",path:e,priority:100,timestamp:new Date}};if(r)fr.setWithFileCheck("file",w,e,o);return w}catch(f){throw f instanceof Error?oi.configLoad(e,f):oi.configLoad(e,Error(String(f)))}};if(s)return Bn.track("loadFromPath",c,{path:e});return c()}async tryLoadFromPaths(e,t,i={}){for(let n of e)try{let r=await this.loadFromPath(n,t,i);if(r)return r}catch(r){if(r instanceof Error&&r.name==="ConfigLoadError")throw r;if(i.verbose)console.warn(`Failed to load config from ${n}:`,r)}return null}generateConfigPaths(e,t,i){let n=this.generateNamePatterns(e,i),r=[];for(let o of n)for(let s of this.extensions)r.push(En(t,`${o}${s}`));return r}generateNamePatterns(e,t){let i=[];if(i.push("config",".config"),e)i.push(e,`.${e}.config`,`${e}.config`,`.${e}`);let n=t===void 0?[]:Array.isArray(t)?t:[t];for(let o of n){if(!o)continue;if(i.push(o,`.${o}.config`,`${o}.config`,`.${o}`),e)i.push(`${e}.${o}.config`,`.${e}.${o}.config`)}let r=new Set;return i.filter((o)=>{if(!o||r.has(o))return!1;return r.add(o),!0})}checkFileAccess(e){return Zu(async()=>Xi(e),{maxRetries:2,retryDelay:100,fallback:!1})}async discoverConfigFiles(e,t,i){let n=[];if(!Xi(e))return n;if(t||i){let r=this.generateNamePatterns(t||"",i);for(let o of r)for(let s of this.extensions){let a=En(e,`${o}${s}`);if(await this.checkFileAccess(a))n.push(a)}}else try{let{readdirSync:r}=await import("fs"),o=r(e);for(let s of o)if(this.looksLikeConfigFile(s)){let a=En(e,s);if(await this.checkFileAccess(a))n.push(a)}}catch{return[]}return n}looksLikeConfigFile(e){return[/\.config\.(ts|js|mjs|cjs|json|mts|cts)$/,/^\..*\.(ts|js|mjs|cjs|json|mts|cts)$/,/config\.(ts|js|mjs|cjs|json|mts|cts)$/].some((t)=>t.test(e))}async validateConfigFile(e){let t=[];try{if(!Xi(e))return t.push("Configuration file does not exist"),t;let i=await import(e),n=i.default||i;if(n===void 0)t.push("Configuration file must export a default value or named exports");else if(typeof n!=="object"||n===null)t.push("Configuration must be an object");else if(Array.isArray(n))t.push("Configuration cannot be an array at the root level");if(e.endsWith(".json"))try{let{readFileSync:r}=await import("fs"),o=r(e,"utf8");JSON.parse(o)}catch(r){t.push(`Invalid JSON syntax: ${r}`)}}catch(i){t.push(`Failed to load configuration file: ${i}`)}return t}async getFileModificationTime(e){try{let{statSync:t}=await import("fs");return t(e).mtime}catch{return null}}async preloadConfigurations(e,t={}){let i=new Map;return await Promise.allSettled(e.map(async(n)=>{try{let r=await this.loadFromPath(n,{},t);if(r)i.set(n,r.config)}catch(r){if(t.verbose)console.warn(`Failed to preload ${n}:`,r)}})),i}}class ba{async validateConfiguration(e,t,i={}){let{stopOnFirstError:n=!1,validateRequired:r=!0,validateTypes:o=!0,customRules:s=[],trackPerformance:a=!0,verbose:c=!1}=i,f=async()=>{let u=[],l=[],y={stopOnFirstError:n,validateRequired:r,validateTypes:o,customRules:s,trackPerformance:a,verbose:c};try{if(typeof t==="string")return await this.validateWithSchemaFile(e,t,y);else if(Array.isArray(t))return this.validateWithRules(e,[...t,...s],y);else return this.validateWithJSONSchema(e,t,y)}catch(p){return u.push({path:"",message:`Validation failed: ${p}`,rule:"system"}),{isValid:!1,errors:u,warnings:l}}};if(a)return await Bn.track("validateConfiguration",f);return f()}async validateWithSchemaFile(e,t,i){try{if(!Lf(t))throw new wr(t,[{path:"",message:"Schema file does not exist"}]);let n=await import(t),r=n.default||n;if(Array.isArray(r))return this.validateWithRules(e,r,i);else return this.validateWithJSONSchema(e,r,i)}catch(n){throw new wr(t,[{path:"",message:`Failed to load schema: ${n}`}])}}validateWithJSONSchema(e,t,i){let n=[],r=[];return this.validateObjectAgainstSchema(e,t,"",n,r,i),{isValid:n.length===0,errors:n,warnings:r}}validateObjectAgainstSchema(e,t,i,n,r,o){if(o.validateTypes&&t.type){let s=Array.isArray(e)?"array":typeof e,a=Array.isArray(t.type)?t.type:[t.type];if(!a.includes(s)){if(n.push({path:i,message:`Expected type ${a.join(" or ")}, got ${s}`,expected:a.join(" or "),actual:s,rule:"type"}),o.stopOnFirstError)return}}if(t.enum&&!t.enum.includes(e)){if(n.push({path:i,message:`Value must be one of: ${t.enum.join(", ")}`,expected:t.enum.join(", "),actual:e,rule:"enum"}),o.stopOnFirstError)return}if(typeof e==="string"){if(t.minLength!==void 0&&e.length<t.minLength)n.push({path:i,message:`String length must be at least ${t.minLength}`,expected:`>= ${t.minLength}`,actual:e.length,rule:"minLength"});if(t.maxLength!==void 0&&e.length>t.maxLength)n.push({path:i,message:`String length must not exceed ${t.maxLength}`,expected:`<= ${t.maxLength}`,actual:e.length,rule:"maxLength"});if(t.pattern){if(!new RegExp(t.pattern).test(e))n.push({path:i,message:`String does not match pattern ${t.pattern}`,expected:t.pattern,actual:e,rule:"pattern"})}}if(typeof e==="number"){if(t.minimum!==void 0&&e<t.minimum)n.push({path:i,message:`Value must be at least ${t.minimum}`,expected:`>= ${t.minimum}`,actual:e,rule:"minimum"});if(t.maximum!==void 0&&e>t.maximum)n.push({path:i,message:`Value must not exceed ${t.maximum}`,expected:`<= ${t.maximum}`,actual:e,rule:"maximum"})}if(Array.isArray(e)&&t.items)for(let s=0;s<e.length;s++){let a=i?`${i}[${s}]`:`[${s}]`;if(this.validateObjectAgainstSchema(e[s],t.items,a,n,r,o),o.stopOnFirstError&&n.length>0)return}if(e&&typeof e==="object"&&!Array.isArray(e)){let s=e;if(o.validateRequired&&t.required){for(let a of t.required)if(!(a in s)){if(n.push({path:i?`${i}.${a}`:a,message:`Missing required property '${a}'`,expected:"required",rule:"required"}),o.stopOnFirstError)return}}if(t.properties){for(let[a,c]of Object.entries(t.properties))if(a in s){let f=i?`${i}.${a}`:a;if(this.validateObjectAgainstSchema(s[a],c,f,n,r,o),o.stopOnFirstError&&n.length>0)return}}if(t.additionalProperties===!1){let a=new Set(Object.keys(t.properties||{}));for(let c of Object.keys(s))if(!a.has(c))r.push({path:i?`${i}.${c}`:c,message:`Additional property '${c}' is not allowed`,rule:"additionalProperties"})}}}validateWithRules(e,t,i){let n=[],r=[];for(let o of t)try{let s=this.getValueByPath(e,o.path),a=this.validateWithRule(s,o,o.path);if(n.push(...a),i.stopOnFirstError&&n.length>0)break}catch(s){n.push({path:o.path,message:`Rule validation failed: ${s}`,rule:"system"})}return{isValid:n.length===0,errors:n,warnings:r}}validateWithRule(e,t,i){let n=[];if(t.required&&(e===void 0||e===null))return n.push({path:i,message:t.message||`Property '${i}' is required`,expected:"required",rule:"required"}),n;if(e===void 0||e===null)return n;if(t.type){let r=Array.isArray(e)?"array":typeof e;if(r!==t.type)n.push({path:i,message:t.message||`Expected type ${t.type}, got ${r}`,expected:t.type,actual:r,rule:"type"})}if(t.min!==void 0){let r=Array.isArray(e)?e.length:typeof e==="string"?e.length:typeof e==="number"?e:0;if(r<t.min)n.push({path:i,message:t.message||`Value must be at least ${t.min}`,expected:`>= ${t.min}`,actual:r,rule:"min"})}if(t.max!==void 0){let r=Array.isArray(e)?e.length:typeof e==="string"?e.length:typeof e==="number"?e:0;if(r>t.max)n.push({path:i,message:t.message||`Value must not exceed ${t.max}`,expected:`<= ${t.max}`,actual:r,rule:"max"})}if(t.pattern&&typeof e==="string"){if(!t.pattern.test(e))n.push({path:i,message:t.message||`Value does not match pattern ${t.pattern}`,expected:t.pattern.toString(),actual:e,rule:"pattern"})}if(t.enum&&!t.enum.includes(e))n.push({path:i,message:t.message||`Value must be one of: ${t.enum.join(", ")}`,expected:t.enum.join(", "),actual:e,rule:"enum"});if(t.validator){let r=t.validator(e);if(r)n.push({path:i,message:t.message||r,rule:"custom"})}return n}getValueByPath(e,t){if(!t)return e;let i=t.split("."),n=e;for(let r of i)if(n&&typeof n==="object"&&r in n)n=n[r];else return;return n}generateRulesFromInterface(e){let t=[],i=e.matchAll(/(\w+)(\?)?:\s*(\w+)/g);for(let n of i){let[,r,o,s]=n;t.push({path:r,required:!o,type:this.mapTypeScriptType(s)})}return t}mapTypeScriptType(e){switch(e.toLowerCase()){case"string":return"string";case"number":return"number";case"boolean":return"boolean";case"array":return"array";case"object":return"object";default:return"object"}}static createCommonRules(){return{server:[{path:"port",required:!0,type:"number",min:1,max:65535},{path:"host",required:!0,type:"string",min:1},{path:"ssl",type:"boolean"}],database:[{path:"url",required:!0,type:"string",min:1},{path:"pool",type:"number",min:1,max:100},{path:"timeout",type:"number",min:0}],api:[{path:"baseUrl",required:!0,type:"string",pattern:rh},{path:"timeout",type:"number",min:0},{path:"retries",type:"number",min:0,max:10}]}}}function nh(e){if(!e)return"";let t=Array.isArray(e)?e.filter(Boolean):[e];if(t.length===0)return"";if(t.length===1)return` or alias "${t[0]}"`;return` or aliases ${t.map((i)=>`"${i}"`).join(", ")}`}class Sa{fileLoader=new Ea;envProcessor=new Jn;validator=new ba;async loadConfig(e){let t=Date.now(),{cache:i,performance:n,schema:r,validate:o,...s}=e;try{if(i?.enabled){let c=this.checkCache(s.name||"",s);if(c)return c}let a;try{a=await this.loadConfigurationStrategies(s,!0,i)}catch(c){let f=s.__strictErrorHandling;if(c instanceof Error&&c.name==="ConfigNotFoundError"){if(f)throw c;a={...await this.applyEnvironmentVariables(s.name||"",s.defaultConfig,s.checkEnv!==!1,s.verbose||!1),warnings:[`No configuration file found for "${s.name||"config"}", using defaults with environment variables`]}}else if(c instanceof Error&&c.name==="ConfigLoadError"){let u=c.message.includes("EACCES")||c.message.includes("EPERM")||c.message.includes("permission denied"),l=!u&&(c.message.includes("syntax")||c.message.includes("Expected")||c.message.includes("Unexpected")||c.message.includes("BuildMessage")||c.message.includes("errors building")),y=c.message.includes("Configuration must export a valid object")||c.message.includes("Configuration file is empty and exports nothing");if(f&&(y||u))throw c;if(l&&(!f||!y))a={...await this.applyEnvironmentVariables(s.name||"",s.defaultConfig,s.checkEnv!==!1,s.verbose||!1),warnings:["Configuration file has syntax errors, using defaults with environment variables"]};else if(!f)a={...await this.applyEnvironmentVariables(s.name||"",s.defaultConfig,s.checkEnv!==!1,s.verbose||!1),warnings:[`Configuration loading error, using defaults: ${c.message}`]};else throw c}else a={...await this.applyEnvironmentVariables(s.name||"",s.defaultConfig,s.checkEnv!==!1,s.verbose||!1),warnings:[`Configuration loading failed, using defaults: ${c instanceof Error?c.message:String(c)}`]}}if(r||o)await this.validateConfiguration(a.config,r,o,s.name);if(i?.enabled&&a)this.cacheResult(s.name||"",a,i,s);if(n?.enabled){let c={operation:"loadConfig",duration:Date.now()-t,configName:s.name,timestamp:new Date};if(n.onMetrics)n.onMetrics(c);if(n.slowThreshold&&c.duration>n.slowThreshold)yt.warn(`Slow configuration loading detected: ${c.duration}ms for ${s.name}`);a.metrics=c}return a}catch(a){if(a instanceof Error&&a.name==="ConfigNotFoundError")throw a;let c=Date.now()-t;throw yt.error(`Configuration loading failed after ${c}ms:`,[a instanceof Error?a:Error(String(a))]),a}}async loadConfigurationStrategies(e,t=!1,i){let{name:n="",alias:r,cwd:o,configDir:s,defaultConfig:a,checkEnv:c=!0,arrayStrategy:f="replace",verbose:u=!1}=e,l=o||vr.cwd(),y=[],p=await this.loadLocalConfiguration(n,r,l,s,a,f,u,c,i);if(p)return y.push(...this.getLocalSearchPaths(n,r,l,s)),this.finalizeResult(p,y,c,n,u);let w=await this.loadHomeConfiguration(n,r,a,f,u,c);if(w)return y.push(...this.getHomeSearchPaths(n,r)),this.finalizeResult(w,y,c,n,u);let S=await this.loadPackageJsonConfiguration(n,r,l,a,f,u,c);if(S)return y.push(nt(l,"package.json")),this.finalizeResult(S,y,c,n,u);if(y.push(...this.getAllSearchPaths(n,r,l,s)),t)throw oi.configNotFound(n,y,r);return{...await this.applyEnvironmentVariables(n,a,c,u),warnings:[`No configuration file found for "${n}"${nh(r)}, using defaults with environment variables`]}}async loadLocalConfiguration(e,t,i,n,r,o,s,a,c){let f=a?er(e,r,s):r,u=this.getLocalDirectories(i,n);for(let l of u){if(s)yt.info(`Searching for configuration in: ${l}`);let y=this.fileLoader.generateConfigPaths(e,l,t),p=await this.fileLoader.tryLoadFromPaths(y,f,{arrayStrategy:o,verbose:s,cacheTtl:c?.ttl,useCache:!c?.ttl||c.ttl>100});if(p){if(s)yt.success(`Configuration loaded from: ${p.source.path}`);return p}}return null}async loadHomeConfiguration(e,t,i,n,r,o){if(!e)return null;let s=o?er(e,i,r):i,a=[nt(Ht(),".config",e),nt(Ht(),".config"),Ht()];for(let c of a){if(r)yt.info(`Checking home directory: ${c}`);let f=this.fileLoader.generateConfigPaths(e,c,t),u=await this.fileLoader.tryLoadFromPaths(f,s,{arrayStrategy:n,verbose:r});if(u){if(r)yt.success(`Configuration loaded from home directory: ${u.source.path}`);return u}}return null}async loadPackageJsonConfiguration(e,t,i,n,r,o,s){let a=s?er(e,n,o):n;try{let c=nt(i,"package.json");if(!Yc(c))return null;let f={};try{f=JSON.parse(Zc(c,"utf8"))}catch(y){if(o)yt.warn("Failed to parse package.json:",[y instanceof Error?y:Error(String(y))]);return null}let u=f[e],l=e;if(!u&&t){let y=Array.isArray(t)?t:[t];for(let p of y){if(!p)continue;if(f[p]){u=f[p],l=p;break}}}if(u&&typeof u==="object"&&!Array.isArray(u)){if(o)yt.success(`Configuration loaded from package.json: ${l}`);return{config:va(a,u,r),source:{type:"package.json",path:c,priority:30,timestamp:new Date}}}}catch(c){if(o)yt.warn("Failed to load package.json:",[c instanceof Error?c:Error(String(c))])}return null}async applyEnvironmentVariables(e,t,i,n){if(!i||!e||typeof t!=="object"||t===null||Array.isArray(t))return{config:t,source:{type:"default",priority:10,timestamp:new Date}};return{config:er(e,t,n),source:{type:"environment",priority:20,timestamp:new Date}}}async finalizeResult(e,t,i,n,r){return{config:e.config,source:e.source,path:e.source.path}}async validateConfiguration(e,t,i,n){let r=[];if(i){let o=i(e);if(o)r.push(...o)}if(t){let o=await this.validator.validateConfiguration(e,t);if(!o.isValid)r.push(...o.errors.map((s)=>s.path?`${s.path}: ${s.message}`:s.message))}if(r.length>0)throw oi.configValidation(n||"unknown",r,n)}checkCache(e,t){let i=this.generateCacheKey(e,t);return fr.get(i)||null}cacheResult(e,t,i,n){let r=this.generateCacheKey(e,n);fr.set(r,t,void 0,i.ttl)}generateCacheKey(e,t){let i=[e];if(t.alias){let n=Array.isArray(t.alias)?t.alias.join(","):t.alias;i.push(`alias:${n}`)}if(t.cwd)i.push(`cwd:${t.cwd}`);if(t.configDir)i.push(`configDir:${t.configDir}`);if("checkEnv"in t)i.push(`checkEnv:${t.checkEnv}`);return i.join("|")}getLocalDirectories(e,t){return Array.from(new Set([e,nt(e,"config"),nt(e,".config"),t?nt(e,t):void 0].filter(Boolean)))}getAllSearchPaths(e,t,i,n){let r=[];return r.push(...this.getLocalSearchPaths(e,t,i,n)),r.push(...this.getHomeSearchPaths(e,t)),r.push(nt(i,"package.json")),r}getLocalSearchPaths(e,t,i,n){let r=this.getLocalDirectories(i,n),o=[];for(let s of r)o.push(...this.fileLoader.generateConfigPaths(e,s,t));return o}getHomeSearchPaths(e,t){if(!e)return[];let i=[nt(Ht(),".config",e),nt(Ht(),".config"),Ht()],n=[];for(let r of i)n.push(...this.fileLoader.generateConfigPaths(e,r,t));return n}async loadConfigWithResult(e){return this.loadConfig(e)}}function er(e,t,i=!1){let n=new Jn,r=e.toUpperCase().replace(/[^A-Z0-9]/g,"_");function o(s,a=[]){let c={...s};for(let[f,u]of Object.entries(s)){let l=[...a,f],y=[`${r}_${l.join("_").toUpperCase()}`,`${r}_${l.map((S)=>S.toUpperCase()).join("")}`,`${r}_${l.map((S)=>S.replace(/([A-Z])/g,"_$1").toUpperCase()).join("")}`],p,w;for(let S of y)if(p=vr.env[S],p!==void 0){w=S;break}if(p!==void 0&&w)if(typeof u==="boolean")c[f]=["true","1","yes"].includes(p.toLowerCase());else if(typeof u==="number"){let S=Number(p);if(!Number.isNaN(S))c[f]=S}else if(Array.isArray(u))try{c[f]=JSON.parse(p)}catch{c[f]=p.split(",").map((S)=>S.trim())}else c[f]=p;else if(u&&typeof u==="object"&&!Array.isArray(u))c[f]=o(u,l)}return c}return o(t)}var fr,Bn,Wf,Bf=(e)=>e,jf=(e,t)=>{for(var i in t)Wf(e,i,{get:t[i],enumerable:!0,configurable:!0,set:Gf.bind(t,i)})},_f=(e,t)=>()=>(e&&(t=e(e=0)),t),Ks,ea,ni,yi,ta,pu,gu,Ps,ir,On,Ve,$e,yu,Os,Cu,ks,wu,vu,bn,Eu,Ms,Ds,Sn,bu,Su,$u,Au,rr,ia,xu,Ue,Tu,Ru,Is,nr,kn,Le,ae,Pu,Fs,Ou,Ns,ku,Mu,$n,Du,Ls,Ws,Iu,An,Fu,Nu,Lu,Wu,Bu,or,ra,Gu,ju="0.15.6",et,pr,pi,Mn,Dn,gr,In,Fn,gi,Nn,Ln,Pt,na,oa,ft,Et,sa,aa,_u,Uu,la,yr,Fg,fa,ce,Ng,zu,Lg,Hu,Wg,Bg,Bs,Gg,Ju,qu,jg,Gs,_g,Vg,Ug,Kg,zg,xn,Yu,Hg,ut,ua,Cr,ha,da,Hn,ma,pa,wr,ga,ya,oi,rh,yt,Jg,qg,Yg,oh,$a;var Aa=pe(()=>{fr=new Vs,Bn=new Us,Wf=Object.defineProperty;Ks={};jf(Ks,{withErrorRecovery:()=>Js,tryLoadConfig:()=>uu,loadConfigWithResult:()=>cu,loadConfig:()=>Qs,isRetryableError:()=>ru,isConfigNotFoundError:()=>iu,isBunfigError:()=>qs,globalPerformanceMonitor:()=>yi,globalCache:()=>ni,getEnvOrDefault:()=>nu,generateConfigTypes:()=>hu,defaultGeneratedDir:()=>aa,defaultConfigDir:()=>sa,deepMergeWithArrayStrategy:()=>Un,deepMerge:()=>Ys,createLibraryConfig:()=>du,config:()=>fu,bunfigPlugin:()=>mu,applyEnvVarsToConfig:()=>di,TypeGenerationError:()=>Fn,SchemaValidationError:()=>gi,PluginError:()=>Ln,PerformanceMonitor:()=>jn,FileSystemError:()=>In,ErrorFactory:()=>Pt,EnvVarError:()=>gr,EnvProcessor:()=>Er,ConfigValidator:()=>Kn,ConfigValidationError:()=>Mn,ConfigNotFoundError:()=>pr,ConfigMergeError:()=>Dn,ConfigLoader:()=>zn,ConfigLoadError:()=>pi,ConfigFileLoader:()=>br,ConfigCache:()=>Gn,CacheUtils:()=>ta,BunfigError:()=>et,BrowserConfigError:()=>Nn,ArrayMergeStrategies:()=>na});_u=_f(async()=>{ea=import.meta.require,ni=new Gn,yi=new jn,ta={createKey:Vf,isEquivalent:Uf,estimateMemoryUsage:Kf},pu=lr(Rn.cwd(),"config"),gu=lr(Rn.cwd(),"src/generated"),Ps=ar.env.CLARITY_LOG_DIR||nf(Jf(),"logs"),ir={level:"info",defaultName:"clarity",timestamp:!0,colors:!0,format:"text",maxLogSize:10485760,logDatePattern:"YYYY-MM-DD",logDirectory:Ps,rotation:{frequency:"daily",maxSize:10485760,maxFiles:5,compress:!1,rotateHour:0,rotateMinute:0,rotateDayOfWeek:0,rotateDayOfMonth:1,encrypt:!1},verbose:!1},On=await qf(),Ve={red:(e)=>`\x1B[31m${e}\x1B[0m`,green:(e)=>`\x1B[32m${e}\x1B[0m`,yellow:(e)=>`\x1B[33m${e}\x1B[0m`,blue:(e)=>`\x1B[34m${e}\x1B[0m`,magenta:(e)=>`\x1B[35m${e}\x1B[0m`,cyan:(e)=>`\x1B[36m${e}\x1B[0m`,white:(e)=>`\x1B[37m${e}\x1B[0m`,gray:(e)=>`\x1B[90m${e}\x1B[0m`,bgRed:(e)=>`\x1B[41m${e}\x1B[0m`,bgYellow:(e)=>`\x1B[43m${e}\x1B[0m`,bold:(e)=>`\x1B[1m${e}\x1B[0m`,dim:(e)=>`\x1B[2m${e}\x1B[0m`,italic:(e)=>`\x1B[3m${e}\x1B[0m`,underline:(e)=>`\x1B[4m${e}\x1B[0m`,reset:"\x1B[0m"},$e=Ve,yu=Ve.red,Os=Ve.green,Cu=Ve.yellow,ks=Ve.blue,wu=Ve.magenta,vu=Ve.cyan,bn=Ve.white,Eu=Ve.gray,Ms=Ve.bgRed,Ds=Ve.bgYellow,Sn=Ve.bold,bu=Ve.dim,Su=Ve.italic,$u=Ve.underline,Au=Ve.reset,rr={activationLevel:"error",bufferSize:50,flushOnDeactivation:!0,stopBuffering:!1},ia={debug:"\uD83D\uDD0D",info:ks("\u2139"),success:Os("\u2713"),warning:Ds(bn(Sn(" WARN "))),error:Ms(bn(Sn(" ERROR ")))},xu=new hr("stacks"),Ue=new hr("bunfig",{showTags:!0}),Tu=He(mi.cwd(),"config"),Ru=He(mi.cwd(),"src/generated"),Is=sr.env.CLARITY_LOG_DIR||tf(Qf(),"logs"),nr={level:"info",defaultName:"clarity",timestamp:!0,colors:!0,format:"text",maxLogSize:10485760,logDatePattern:"YYYY-MM-DD",logDirectory:Is,rotation:{frequency:"daily",maxSize:10485760,maxFiles:5,compress:!1,rotateHour:0,rotateMinute:0,rotateDayOfWeek:0,rotateDayOfMonth:1,encrypt:!1},verbose:!1,writeToFile:!1},kn=await eu(),Le={red:(e)=>`\x1B[31m${e}\x1B[0m`,green:(e)=>`\x1B[32m${e}\x1B[0m`,yellow:(e)=>`\x1B[33m${e}\x1B[0m`,blue:(e)=>`\x1B[34m${e}\x1B[0m`,magenta:(e)=>`\x1B[35m${e}\x1B[0m`,cyan:(e)=>`\x1B[36m${e}\x1B[0m`,white:(e)=>`\x1B[37m${e}\x1B[0m`,gray:(e)=>`\x1B[90m${e}\x1B[0m`,bgRed:(e)=>`\x1B[41m${e}\x1B[0m`,bgYellow:(e)=>`\x1B[43m${e}\x1B[0m`,bgGray:(e)=>`\x1B[100m${e}\x1B[0m`,bold:(e)=>`\x1B[1m${e}\x1B[0m`,dim:(e)=>`\x1B[2m${e}\x1B[0m`,italic:(e)=>`\x1B[3m${e}\x1B[0m`,underline:(e)=>`\x1B[4m${e}\x1B[0m`,strikethrough:(e)=>`\x1B[9m${e}\x1B[0m`,reset:"\x1B[0m"},ae=Le,Pu=Le.red,Fs=Le.green,Ou=Le.yellow,Ns=Le.blue,ku=Le.magenta,Mu=Le.cyan,$n=Le.white,Du=Le.gray,Ls=Le.bgRed,Ws=Le.bgYellow,Iu=Le.bgGray,An=Le.bold,Fu=Le.dim,Nu=Le.italic,Lu=Le.underline,Wu=Le.strikethrough,Bu=Le.reset,or={activationLevel:"error",bufferSize:50,flushOnDeactivation:!0,stopBuffering:!1},ra={debug:"\uD83D\uDD0D",info:Ns("\u2139"),success:Fs("\u2713"),warning:Ws($n(An(" WARN "))),error:Ls($n(An(" ERROR ")))},Gu=new mr("stacks"),et=class extends Error{timestamp;context;constructor(e,t={}){super(e);if(this.name=this.constructor.name,this.timestamp=new Date,this.context=t,Error.captureStackTrace)Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,code:this.code,message:this.message,timestamp:this.timestamp.toISOString(),context:this.context,stack:this.stack}}toString(){let e=Object.keys(this.context).length>0?` (${Object.entries(this.context).map(([t,i])=>`${t}: ${i}`).join(", ")})`:"";return`${this.name} [${this.code}]: ${this.message}${e}`}},pr=class extends et{code="CONFIG_NOT_FOUND";constructor(e,t,i){let n=i?` or alias "${i}"`:"";super(`Configuration "${e}"${n} not found`,{configName:e,alias:i,searchPaths:t,searchPathCount:t.length})}},pi=class extends et{code="CONFIG_LOAD_ERROR";constructor(e,t,i){super(`Failed to load configuration from "${e}": ${t.message}`,{configPath:e,configName:i,originalError:t.name,originalMessage:t.message});this.cause=t}},Mn=class extends et{code="CONFIG_VALIDATION_ERROR";constructor(e,t,i){super(`Configuration validation failed for "${e}"`,{configPath:e,configName:i,validationErrors:t,errorCount:t.length})}},Dn=class extends et{code="CONFIG_MERGE_ERROR";constructor(e,t,i,n){super(`Failed to merge configuration from "${e}" with "${t}": ${i.message}`,{sourcePath:e,targetPath:t,configName:n,originalError:i.name,originalMessage:i.message});this.cause=i}},gr=class extends et{code="ENV_VAR_ERROR";constructor(e,t,i,n){super(`Failed to parse environment variable "${e}" with value "${t}" as ${i}`,{envKey:e,envValue:t,expectedType:i,configName:n})}},In=class extends et{code="FILE_SYSTEM_ERROR";constructor(e,t,i){super(`File system ${e} failed for "${t}": ${i.message}`,{operation:e,path:t,originalError:i.name,originalMessage:i.message});this.cause=i}},Fn=class extends et{code="TYPE_GENERATION_ERROR";constructor(e,t,i){super(`Failed to generate types from "${e}" to "${t}": ${i.message}`,{configDir:e,outputPath:t,originalError:i.name,originalMessage:i.message});this.cause=i}},gi=class extends et{code="SCHEMA_VALIDATION_ERROR";constructor(e,t,i){super(`Schema validation failed${i?` for config "${i}"`:""}`,{schemaPath:e,configName:i,validationErrors:t,errorCount:t.length})}},Nn=class extends et{code="BROWSER_CONFIG_ERROR";constructor(e,t,i,n){super(`Failed to fetch configuration from "${e}": ${t} ${i}`,{endpoint:e,status:t,statusText:i,configName:n})}},Ln=class extends et{code="PLUGIN_ERROR";constructor(e,t,i){super(`Plugin "${e}" failed during ${t}: ${i.message}`,{pluginName:e,operation:t,originalError:i.name,originalMessage:i.message});this.cause=i}},Pt={configNotFound(e,t,i){return new pr(e,t,i)},configLoad(e,t,i){return new pi(e,t,i)},configValidation(e,t,i){return new Mn(e,t,i)},configMerge(e,t,i,n){return new Dn(e,t,i,n)},envVar(e,t,i,n){return new gr(e,t,i,n)},fileSystem(e,t,i){return new In(e,t,i)},typeGeneration(e,t,i){return new Fn(e,t,i)},schemaValidation(e,t,i){return new gi(e,t,i)},browserConfig(e,t,i,n){return new Nn(e,t,i,n)},plugin(e,t,i){return new Ln(e,t,i)}},na={replace:"replace",concat:"concat",smart:"smart"},oa=/^https?:\/\//,ft=new mr("bunfig",{showTags:!0}),Et=new zn,sa=Je(It.cwd(),"config"),aa=Je(It.cwd(),"src/generated")});Uu=cr.env.CLARITY_LOG_DIR||xf(Vu(),"logs"),la={level:"info",defaultName:"clarity",timestamp:!0,colors:!0,format:"text",maxLogSize:10485760,logDatePattern:"YYYY-MM-DD",logDirectory:Uu,rotation:{frequency:"daily",maxSize:10485760,maxFiles:5,compress:!1,rotateHour:0,rotateMinute:0,rotateDayOfWeek:0,rotateDayOfMonth:1,encrypt:!1},verbose:!1,writeToFile:!1},yr={...la},Fg=(async()=>{try{let{loadConfig:e}=await _u().then(()=>Ks),t=await e({name:"clarity",alias:"logging",defaultConfig:la,cwd:cr.cwd()});if(t)Object.assign(yr,t)}catch{}return yr})();fa={red:(e)=>`\x1B[31m${e}\x1B[0m`,green:(e)=>`\x1B[32m${e}\x1B[0m`,yellow:(e)=>`\x1B[33m${e}\x1B[0m`,blue:(e)=>`\x1B[34m${e}\x1B[0m`,magenta:(e)=>`\x1B[35m${e}\x1B[0m`,cyan:(e)=>`\x1B[36m${e}\x1B[0m`,white:(e)=>`\x1B[37m${e}\x1B[0m`,gray:(e)=>`\x1B[90m${e}\x1B[0m`,bgRed:(e)=>`\x1B[41m${e}\x1B[0m`,bgYellow:(e)=>`\x1B[43m${e}\x1B[0m`,bgGray:(e)=>`\x1B[100m${e}\x1B[0m`,bold:(e)=>`\x1B[1m${e}\x1B[0m`,dim:(e)=>`\x1B[2m${e}\x1B[0m`,italic:(e)=>`\x1B[3m${e}\x1B[0m`,underline:(e)=>`\x1B[4m${e}\x1B[0m`,strikethrough:(e)=>`\x1B[9m${e}\x1B[0m`,reset:"\x1B[0m"},ce=fa,{red:Ng,green:zu,yellow:Lg,blue:Hu,magenta:Wg,cyan:Bg,white:Bs,gray:Gg,bgRed:Ju,bgYellow:qu,bgGray:jg,bold:Gs,dim:_g,italic:Vg,underline:Ug,strikethrough:Kg,reset:zg}=fa,xn={activationLevel:"error",bufferSize:50,flushOnDeactivation:!0,stopBuffering:!1},Yu={debug:"\uD83D\uDD0D",info:Hu("\u2139"),success:zu("\u2713"),warning:qu(Bs(Gs(" WARN "))),error:Ju(Bs(Gs(" ERROR ")))};Hg=new Sr("stacks");ut=class ut extends Error{timestamp;context;constructor(e,t={}){super(e);if(this.name=this.constructor.name,this.timestamp=new Date,this.context=t,Error.captureStackTrace)Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,code:this.code,message:this.message,timestamp:this.timestamp.toISOString(),context:this.context,stack:this.stack}}toString(){let e=Object.keys(this.context).length>0?` (${Object.entries(this.context).map(([t,i])=>`${t}: ${i}`).join(", ")})`:"";return`${this.name} [${this.code}]: ${this.message}${e}`}};ua=class ua extends ut{code="CONFIG_NOT_FOUND";constructor(e,t,i){let n=i===void 0?[]:Array.isArray(i)?i.filter(Boolean):[i],r="";if(n.length===1)r=` or alias "${n[0]}"`;else if(n.length>1)r=` or aliases ${n.map((o)=>`"${o}"`).join(", ")}`;super(`Configuration "${e}"${r} not found`,{configName:e,alias:i,searchPaths:t,searchPathCount:t.length})}};Cr=class Cr extends ut{code="CONFIG_LOAD_ERROR";constructor(e,t,i){super(`Failed to load configuration from "${e}": ${t.message}`,{configPath:e,configName:i,originalError:t.name,originalMessage:t.message});this.cause=t}};ha=class ha extends ut{code="CONFIG_VALIDATION_ERROR";constructor(e,t,i){super(`Configuration validation failed for "${e}"`,{configPath:e,configName:i,validationErrors:t,errorCount:t.length})}};da=class da extends ut{code="CONFIG_MERGE_ERROR";constructor(e,t,i,n){super(`Failed to merge configuration from "${e}" with "${t}": ${i.message}`,{sourcePath:e,targetPath:t,configName:n,originalError:i.name,originalMessage:i.message});this.cause=i}};Hn=class Hn extends ut{code="ENV_VAR_ERROR";constructor(e,t,i,n){super(`Failed to parse environment variable "${e}" with value "${t}" as ${i}`,{envKey:e,envValue:t,expectedType:i,configName:n})}};ma=class ma extends ut{code="FILE_SYSTEM_ERROR";constructor(e,t,i){super(`File system ${e} failed for "${t}": ${i.message}`,{operation:e,path:t,originalError:i.name,originalMessage:i.message});this.cause=i}};pa=class pa extends ut{code="TYPE_GENERATION_ERROR";constructor(e,t,i){super(`Failed to generate types from "${e}" to "${t}": ${i.message}`,{configDir:e,outputPath:t,originalError:i.name,originalMessage:i.message});this.cause=i}};wr=class wr extends ut{code="SCHEMA_VALIDATION_ERROR";constructor(e,t,i){super(`Schema validation failed${i?` for config "${i}"`:""}`,{schemaPath:e,configName:i,validationErrors:t,errorCount:t.length})}};ga=class ga extends ut{code="BROWSER_CONFIG_ERROR";constructor(e,t,i,n){super(`Failed to fetch configuration from "${e}": ${t} ${i}`,{endpoint:e,status:t,statusText:i,configName:n})}};ya=class ya extends ut{code="PLUGIN_ERROR";constructor(e,t,i){super(`Plugin "${e}" failed during ${t}: ${i.message}`,{pluginName:e,operation:t,originalError:i.name,originalMessage:i.message});this.cause=i}};oi={configNotFound(e,t,i){return new ua(e,t,i)},configLoad(e,t,i){return new Cr(e,t,i)},configValidation(e,t,i){return new ha(e,t,i)},configMerge(e,t,i,n){return new da(e,t,i,n)},envVar(e,t,i,n){return new Hn(e,t,i,n)},fileSystem(e,t,i){return new ma(e,t,i)},typeGeneration(e,t,i){return new pa(e,t,i)},schemaValidation(e,t,i){return new wr(e,t,i)},browserConfig(e,t,i,n){return new ga(e,t,i,n)},plugin(e,t,i){return new ya(e,t,i)}};rh=/^https?:\/\//;yt=new Sr("bunfig",{showTags:!0});Jg=new Sa;qg=nt(vr.cwd(),"config"),Yg=nt(vr.cwd(),"src/generated"),oh={cwd:qc.cwd(),root:"./src",entrypoints:["**/*.{ts,tsx,mts,cts,vue,stx}"],outdir:"./dist",keepComments:!0,clean:!0,tsconfigPath:"./tsconfig.json",outputStructure:"mirror",verbose:!1,importOrder:["bun"],declarationMap:!1},$a=oh});function xa(e,t,i){let n={file:t,message:"Unknown error",code:Ci.UNKNOWN_ERROR};if(e instanceof Error){n.message=e.message,n.stack=e.stack;let r=e.message.match(/\((\d+),(\d+)\)/);if(r)n.location={line:Number.parseInt(r[1],10),column:Number.parseInt(r[2],10)};if(e.message.includes("Cannot find")||e.message.includes("not found"))n.code=Ci.FILE_NOT_FOUND,n.suggestion="Check that the file path is correct and the file exists.";else if(e.message.includes("syntax")||e.message.includes("Unexpected token"))n.code=Ci.SYNTAX_ERROR,n.suggestion="Check for syntax errors in your TypeScript code.";else if(e.message.includes("type")&&e.message.includes("cannot"))n.code=Ci.TYPE_INFERENCE_ERROR,n.suggestion="Add explicit type annotations to help with type inference.";else if(e.message.includes("parse")||e.message.includes("Parse"))n.code=Ci.PARSE_ERROR,n.suggestion="The file contains invalid TypeScript syntax."}else if(typeof e==="string")n.message=e;return n}function Ta(e,t){let i=[],n=e.file;if(e.location)n+=`:${e.location.line}:${e.location.column}`;if(e.code)n+=` [${e.code}]`;if(i.push(n),i.push(` Error: ${e.message}`),t&&e.location){i.push("");let r=t.split(`
91
91
  `),o=e.location.line-1;if(o>=0&&o<r.length){let s=Math.max(0,o-1),a=Math.min(r.length-1,o+1);for(let c=s;c<=a;c++){let f=(c+1).toString().padStart(4," "),u=c===o?">":" ";if(i.push(` ${u} ${f} | ${r[c]}`),c===o&&e.location.column>0){let l=" ".repeat(10+e.location.column-1);i.push(` ${l}^`)}}}}if(e.suggestion)i.push(""),i.push(` Suggestion: ${e.suggestion}`);return i.join(`
92
- `)}var Ci;var Ra=pe(()=>{Ci={PARSE_ERROR:"PARSE_ERROR",SYNTAX_ERROR:"SYNTAX_ERROR",FILE_NOT_FOUND:"FILE_NOT_FOUND",FILE_READ_ERROR:"FILE_READ_ERROR",FILE_WRITE_ERROR:"FILE_WRITE_ERROR",TYPE_INFERENCE_ERROR:"TYPE_INFERENCE_ERROR",UNRESOLVED_TYPE:"UNRESOLVED_TYPE",EXTRACTION_ERROR:"EXTRACTION_ERROR",PROCESSING_ERROR:"PROCESSING_ERROR",VALIDATION_ERROR:"VALIDATION_ERROR",INVALID_DECLARATION:"INVALID_DECLARATION",CONFIG_ERROR:"CONFIG_ERROR",INVALID_ENTRYPOINT:"INVALID_ENTRYPOINT",CIRCULAR_DEPENDENCY:"CIRCULAR_DEPENDENCY",TIMEOUT_ERROR:"TIMEOUT_ERROR",NOT_SUPPORTED:"NOT_SUPPORTED",UNKNOWN_ERROR:"UNKNOWN_ERROR"}});function Oa(e){return e.endsWith(".vue")}function sh(e){let t={script:null,scriptSetup:null},i=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,n;while((n=i.exec(e))!==null){let r=n[1]||"",o=/lang\s*=\s*["']([^"']+)["']/i.exec(r)?.[1]?.toLowerCase()??"js",s={content:n[2]??"",attrs:r,setup:/\bsetup\b/.test(r),lang:o};if(s.setup)t.scriptSetup=s;else t.script=s}return t}function tt(e,t){let i=e[t];t++;while(t<e.length){let n=e[t];if(n==="\\"){t+=2;continue}if(n===i)return t+1;t++}return t}function st(e,t){t++;let i=0;while(t<e.length){let n=e[t];if(n==="\\"){t+=2;continue}if(n==="`"&&i===0)return t+1;if(n==="$"&&e[t+1]==="{"){i++,t+=2;continue}if(n==="}"){if(i>0)i--;t++;continue}t++}return t}function dt(e,t){if(e[t+1]==="/"){let i=e.indexOf(`
93
- `,t+2);return i===-1?e.length:i+1}if(e[t+1]==="*"){let i=e.indexOf("*/",t+2);return i===-1?e.length:i+2}return t+1}function Yn(e,t){let i=e[t];if(i==='"'||i==="'")return tt(e,t);if(i==="`")return st(e,t);if(i==="/"&&(e[t+1]==="/"||e[t+1]==="*"))return dt(e,t);return t}function Zn(e){let t=e.split(""),i=0;while(i<e.length){let n=Yn(e,i);if(n>i){for(let r=i;r<n;r++)if(t[r]!==`
94
- `&&t[r]!=="\r")t[r]=" ";i=n;continue}i++}return t.join("")}function je(e,t,i,n){let r=0,o=t;while(o<e.length){let s=e[o];if(s==='"'||s==="'"){o=tt(e,o);continue}if(s==="`"){o=st(e,o);continue}if(s==="/"&&(e[o+1]==="/"||e[o+1]==="*")){o=dt(e,o);continue}if(s===i)r++;else if(s===n){if(r--,r===0)return o}o++}return-1}function Xn(e,t){let i=0,n=t;while(n<e.length){let r=e[n];if(r==='"'||r==="'"){n=tt(e,n);continue}if(r==="`"){n=st(e,n);continue}if(r==="/"&&(e[n+1]==="/"||e[n+1]==="*")){n=dt(e,n);continue}if(r==="="&&e[n+1]===">"){n+=2;continue}if(r==="<")i++;else if(r===">"){if(i--,i===0)return n}n++}return-1}function si(e,t=","){let i=[],n=0,r="",o=0;while(o<e.length){let s=e[o];if(s==='"'||s==="'"){let a=tt(e,o);r+=e.slice(o,a),o=a;continue}if(s==="`"){let a=st(e,o);r+=e.slice(o,a),o=a;continue}if(s==="/"&&(e[o+1]==="/"||e[o+1]==="*")){o=dt(e,o);continue}if(s==="{"||s==="["||s==="("||s==="<")n++;else if(s==="}"||s==="]"||s===")"||s===">")n--;if(s===t&&n===0){i.push(r),r="",o++;continue}r+=s,o++}if(r.trim()!=="")i.push(r);return i}function Ei(e){let t=e.trim();if(!t.startsWith("{"))return[];let i=je(t,0,"{","}");if(i===-1)return[];let n=t.slice(1,i),r=[];for(let o of si(n)){let s=-1,a=0;for(let u=0;u<o.length;u++){let l=o[u];if(l==='"'||l==="'"){u=tt(o,u)-1;continue}if(l==="`"){u=st(o,u)-1;continue}if(l==="{"||l==="["||l==="("||l==="<")a++;else if(l==="}"||l==="]"||l===")"||l===">")a--;else if(l===":"&&a===0){s=u;break}}if(s!==-1){r.push({key:wi(o.slice(0,s).trim()),value:o.slice(s+1).trim(),isMethod:!1});continue}let c=/^([A-Za-z_$][\w$]*|['"][^'"]+['"])\s*\(/.exec(o.trim());if(c){r.push({key:wi(c[1]),value:o.trim(),isMethod:!0});continue}let f=o.trim();if(f)r.push({key:wi(f),value:"",isMethod:!1})}return r}function wi(e){if(e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"'))return e.slice(1,-1);return e}function vi(e){return/^[A-Za-z_$][\w$]*$/.test(e)?e:JSON.stringify(e)}function bi(e,t){let i=new RegExp(`\\b${t}\\b`,"g"),n;while((n=i.exec(e))!==null){let r=n.index+n[0].length;while(r<e.length&&/\s/.test(e[r]))r++;let o=null;if(e[r]==="<"){let c=Xn(e,r);if(c===-1)return null;o=e.slice(r+1,c).trim(),r=c+1;while(r<e.length&&/\s/.test(e[r]))r++}if(e[r]!=="(")continue;let s=je(e,r,"(",")");if(s===-1)return null;let a=si(e.slice(r+1,s));return{generic:o,arg:a.length>0?a[0].trim():null}}return null}function ah(e,t){let i=ka(e,t);if(!i)return null;return i.kind==="interface"?e.slice(i.bodyStart,i.end):e.slice(i.bodyStart,i.end).trim()}function ka(e,t){let i=new RegExp(`\\binterface\\s+${t}\\b[^{]*\\{`,"m").exec(e);if(i){let r=i.index+i[0].length-1,o=je(e,r,"{","}");if(o!==-1)return{kind:"interface",start:i.index,end:o+1,bodyStart:r}}let n=new RegExp(`\\btype\\s+${t}\\b[^=]*=`,"m").exec(e);if(n){let r=n.index+n[0].length,o=0,s=r;while(r<e.length){let a=e[r];if(a==='"'||a==="'"){r=tt(e,r);continue}if(a==="`"){r=st(e,r);continue}if(a==="{"||a==="["||a==="("||a==="<")o++;else if(a==="}"||a==="]"||a===")"||a===">")o--;else if((a===";"||a===`
95
- `)&&o===0)break;r++}return{kind:"type",start:n.index,end:r,bodyStart:s}}return null}function lh(e){let t=e.search(/\bas\s+PropType\s*</);if(t===-1)return null;let i=e.indexOf("<",t),n=Xn(e,i);if(n===-1)return null;if(e.slice(n+1).trim()!=="")return null;return e.slice(i+1,n).trim()}function qn(e){let t=e.trim(),i=lh(t);if(i!==null)return{type:i,optional:!0};if(t==="null")return{type:"unknown",optional:!0};if(t.startsWith("[")){let n=je(t,0,"[","]");if(n!==-1){let r=si(t.slice(1,n)).map((o)=>qn(o).type).filter((o)=>o!=="unknown");return{type:r.length>0?[...new Set(r)].join(" | "):"unknown",optional:!0}}}if(t.startsWith("{")){let n=Ei(t),r=n.find((c)=>c.key==="type"),o=n.find((c)=>c.key==="required"),s=r?qn(r.value).type:"unknown",a=!(o&&o.value.trim()==="true");return{type:s,optional:a}}if(Pa[t])return{type:Pa[t],optional:!0};if(/^[A-Za-z_$][\w$.]*$/.test(t))return{type:t,optional:!0};return{type:"unknown",optional:!0}}function Tr(e){let t=e.trim();if(t.startsWith("{")){let i=Ei(t);if(i.length===0)return"{}";return`{ ${i.map((n)=>{if(n.isMethod||n.value==="")return`${vi(n.key)}?: unknown`;let r=qn(n.value);return`${vi(n.key)}${r.optional?"?":""}: ${r.type}`}).join(", ")} }`}if(t.startsWith("[")){let i=je(t,0,"[","]");if(i===-1)return null;let n=si(t.slice(1,i)).map((r)=>wi(r.trim())).filter((r)=>r!=="");if(n.length===0)return"{}";return`{ ${n.map((r)=>`${vi(r)}?: unknown`).join(", ")} }`}return null}function ch(e){let t=e.trim();if(!t.startsWith("["))return null;let i=je(t,0,"[","]");if(i===-1)return null;let n=si(t.slice(1,i)).map((r)=>r.trim());if(n.length===0)return"{}";if(!n.every((r)=>r.startsWith("'")&&r.endsWith("'")||r.startsWith('"')&&r.endsWith('"')))return"string[]";return`[${n.map((r)=>JSON.stringify(wi(r))).join(", ")}]`}function fh(e){let t=e.trim();if(!t.startsWith("{"))return null;let i=Ei(t);if(i.length===0)return"{}";return`{ ${i.map((n)=>`${JSON.stringify(n.key)}: (...args: any[]) => void`).join(", ")} }`}function Ma(e){return ch(e)??fh(e)}function uh(e){let t=[],i=0,n="",r=0;while(r<e.length){let o=e[r];if(o==='"'||o==="'"){let s=tt(e,r);n+=e.slice(r,s),r=s;continue}if(o==="`"){let s=st(e,r);n+=e.slice(r,s),r=s;continue}if(o==="/"&&(e[r+1]==="/"||e[r+1]==="*")){let s=dt(e,r);n+=e.slice(r,s),r=s;continue}if(o==="="&&e[r+1]===">"){n+="=>",r+=2;continue}if(o==="{"||o==="["||o==="("||o==="<")i++;else if(o==="}"||o==="]"||o===")"||o===">")i--;if((o===";"||o===","||o===`
92
+ `)}var Ci;var Ra=pe(()=>{Ci={PARSE_ERROR:"PARSE_ERROR",SYNTAX_ERROR:"SYNTAX_ERROR",FILE_NOT_FOUND:"FILE_NOT_FOUND",FILE_READ_ERROR:"FILE_READ_ERROR",FILE_WRITE_ERROR:"FILE_WRITE_ERROR",TYPE_INFERENCE_ERROR:"TYPE_INFERENCE_ERROR",UNRESOLVED_TYPE:"UNRESOLVED_TYPE",EXTRACTION_ERROR:"EXTRACTION_ERROR",PROCESSING_ERROR:"PROCESSING_ERROR",VALIDATION_ERROR:"VALIDATION_ERROR",INVALID_DECLARATION:"INVALID_DECLARATION",CONFIG_ERROR:"CONFIG_ERROR",INVALID_ENTRYPOINT:"INVALID_ENTRYPOINT",CIRCULAR_DEPENDENCY:"CIRCULAR_DEPENDENCY",TIMEOUT_ERROR:"TIMEOUT_ERROR",NOT_SUPPORTED:"NOT_SUPPORTED",UNKNOWN_ERROR:"UNKNOWN_ERROR"}});function Oa(e){return e.endsWith(".vue")}function sh(e){let t={script:null,scriptSetup:null},i=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,n;while((n=i.exec(e))!==null){let r=n[1]||"",o=/lang\s*=\s*["']([^"']+)["']/i.exec(r)?.[1]?.toLowerCase()??"js",s={content:n[2]??"",attrs:r,setup:/\bsetup\b/.test(r),lang:o};if(s.setup)t.scriptSetup=s;else t.script=s}return t}function tt(e,t){let i=e[t];t++;while(t<e.length){let n=e[t];if(n==="\\"){t+=2;continue}if(n===i)return t+1;t++}return t}function at(e,t){t++;let i=0;while(t<e.length){let n=e[t];if(n==="\\"){t+=2;continue}if(n==="`"&&i===0)return t+1;if(n==="$"&&e[t+1]==="{"){i++,t+=2;continue}if(n==="}"){if(i>0)i--;t++;continue}t++}return t}function dt(e,t){if(e[t+1]==="/"){let i=e.indexOf(`
93
+ `,t+2);return i===-1?e.length:i+1}if(e[t+1]==="*"){let i=e.indexOf("*/",t+2);return i===-1?e.length:i+2}return t+1}function Yn(e,t){let i=e[t];if(i==='"'||i==="'")return tt(e,t);if(i==="`")return at(e,t);if(i==="/"&&(e[t+1]==="/"||e[t+1]==="*"))return dt(e,t);return t}function Zn(e){let t=e.split(""),i=0;while(i<e.length){let n=Yn(e,i);if(n>i){for(let r=i;r<n;r++)if(t[r]!==`
94
+ `&&t[r]!=="\r")t[r]=" ";i=n;continue}i++}return t.join("")}function je(e,t,i,n){let r=0,o=t;while(o<e.length){let s=e[o];if(s==='"'||s==="'"){o=tt(e,o);continue}if(s==="`"){o=at(e,o);continue}if(s==="/"&&(e[o+1]==="/"||e[o+1]==="*")){o=dt(e,o);continue}if(s===i)r++;else if(s===n){if(r--,r===0)return o}o++}return-1}function Xn(e,t){let i=0,n=t;while(n<e.length){let r=e[n];if(r==='"'||r==="'"){n=tt(e,n);continue}if(r==="`"){n=at(e,n);continue}if(r==="/"&&(e[n+1]==="/"||e[n+1]==="*")){n=dt(e,n);continue}if(r==="="&&e[n+1]===">"){n+=2;continue}if(r==="<")i++;else if(r===">"){if(i--,i===0)return n}n++}return-1}function si(e,t=","){let i=[],n=0,r="",o=0;while(o<e.length){let s=e[o];if(s==='"'||s==="'"){let a=tt(e,o);r+=e.slice(o,a),o=a;continue}if(s==="`"){let a=at(e,o);r+=e.slice(o,a),o=a;continue}if(s==="/"&&(e[o+1]==="/"||e[o+1]==="*")){o=dt(e,o);continue}if(s==="{"||s==="["||s==="("||s==="<")n++;else if(s==="}"||s==="]"||s===")"||s===">")n--;if(s===t&&n===0){i.push(r),r="",o++;continue}r+=s,o++}if(r.trim()!=="")i.push(r);return i}function Ei(e){let t=e.trim();if(!t.startsWith("{"))return[];let i=je(t,0,"{","}");if(i===-1)return[];let n=t.slice(1,i),r=[];for(let o of si(n)){let s=-1,a=0;for(let u=0;u<o.length;u++){let l=o[u];if(l==='"'||l==="'"){u=tt(o,u)-1;continue}if(l==="`"){u=at(o,u)-1;continue}if(l==="{"||l==="["||l==="("||l==="<")a++;else if(l==="}"||l==="]"||l===")"||l===">")a--;else if(l===":"&&a===0){s=u;break}}if(s!==-1){r.push({key:wi(o.slice(0,s).trim()),value:o.slice(s+1).trim(),isMethod:!1});continue}let c=/^([A-Za-z_$][\w$]*|['"][^'"]+['"])\s*\(/.exec(o.trim());if(c){r.push({key:wi(c[1]),value:o.trim(),isMethod:!0});continue}let f=o.trim();if(f)r.push({key:wi(f),value:"",isMethod:!1})}return r}function wi(e){if(e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"'))return e.slice(1,-1);return e}function vi(e){return/^[A-Za-z_$][\w$]*$/.test(e)?e:JSON.stringify(e)}function bi(e,t){let i=new RegExp(`\\b${t}\\b`,"g"),n;while((n=i.exec(e))!==null){let r=n.index+n[0].length;while(r<e.length&&/\s/.test(e[r]))r++;let o=null;if(e[r]==="<"){let c=Xn(e,r);if(c===-1)return null;o=e.slice(r+1,c).trim(),r=c+1;while(r<e.length&&/\s/.test(e[r]))r++}if(e[r]!=="(")continue;let s=je(e,r,"(",")");if(s===-1)return null;let a=si(e.slice(r+1,s));return{generic:o,arg:a.length>0?a[0].trim():null}}return null}function ah(e,t){let i=ka(e,t);if(!i)return null;return i.kind==="interface"?e.slice(i.bodyStart,i.end):e.slice(i.bodyStart,i.end).trim()}function ka(e,t){let i=new RegExp(`\\binterface\\s+${t}\\b[^{]*\\{`,"m").exec(e);if(i){let r=i.index+i[0].length-1,o=je(e,r,"{","}");if(o!==-1)return{kind:"interface",start:i.index,end:o+1,bodyStart:r}}let n=new RegExp(`\\btype\\s+${t}\\b[^=]*=`,"m").exec(e);if(n){let r=n.index+n[0].length,o=0,s=r;while(r<e.length){let a=e[r];if(a==='"'||a==="'"){r=tt(e,r);continue}if(a==="`"){r=at(e,r);continue}if(a==="{"||a==="["||a==="("||a==="<")o++;else if(a==="}"||a==="]"||a===")"||a===">")o--;else if((a===";"||a===`
95
+ `)&&o===0)break;r++}return{kind:"type",start:n.index,end:r,bodyStart:s}}return null}function lh(e){let t=e.search(/\bas\s+PropType\s*</);if(t===-1)return null;let i=e.indexOf("<",t),n=Xn(e,i);if(n===-1)return null;if(e.slice(n+1).trim()!=="")return null;return e.slice(i+1,n).trim()}function qn(e){let t=e.trim(),i=lh(t);if(i!==null)return{type:i,optional:!0};if(t==="null")return{type:"unknown",optional:!0};if(t.startsWith("[")){let n=je(t,0,"[","]");if(n!==-1){let r=si(t.slice(1,n)).map((o)=>qn(o).type).filter((o)=>o!=="unknown");return{type:r.length>0?[...new Set(r)].join(" | "):"unknown",optional:!0}}}if(t.startsWith("{")){let n=Ei(t),r=n.find((c)=>c.key==="type"),o=n.find((c)=>c.key==="required"),s=r?qn(r.value).type:"unknown",a=!(o&&o.value.trim()==="true");return{type:s,optional:a}}if(Pa[t])return{type:Pa[t],optional:!0};if(/^[A-Za-z_$][\w$.]*$/.test(t))return{type:t,optional:!0};return{type:"unknown",optional:!0}}function Tr(e){let t=e.trim();if(t.startsWith("{")){let i=Ei(t);if(i.length===0)return"{}";return`{ ${i.map((n)=>{if(n.isMethod||n.value==="")return`${vi(n.key)}?: unknown`;let r=qn(n.value);return`${vi(n.key)}${r.optional?"?":""}: ${r.type}`}).join(", ")} }`}if(t.startsWith("[")){let i=je(t,0,"[","]");if(i===-1)return null;let n=si(t.slice(1,i)).map((r)=>wi(r.trim())).filter((r)=>r!=="");if(n.length===0)return"{}";return`{ ${n.map((r)=>`${vi(r)}?: unknown`).join(", ")} }`}return null}function ch(e){let t=e.trim();if(!t.startsWith("["))return null;let i=je(t,0,"[","]");if(i===-1)return null;let n=si(t.slice(1,i)).map((r)=>r.trim());if(n.length===0)return"{}";if(!n.every((r)=>r.startsWith("'")&&r.endsWith("'")||r.startsWith('"')&&r.endsWith('"')))return"string[]";return`[${n.map((r)=>JSON.stringify(wi(r))).join(", ")}]`}function fh(e){let t=e.trim();if(!t.startsWith("{"))return null;let i=Ei(t);if(i.length===0)return"{}";return`{ ${i.map((n)=>`${JSON.stringify(n.key)}: (...args: any[]) => void`).join(", ")} }`}function Ma(e){return ch(e)??fh(e)}function uh(e){let t=[],i=0,n="",r=0;while(r<e.length){let o=e[r];if(o==='"'||o==="'"){let s=tt(e,r);n+=e.slice(r,s),r=s;continue}if(o==="`"){let s=at(e,r);n+=e.slice(r,s),r=s;continue}if(o==="/"&&(e[r+1]==="/"||e[r+1]==="*")){let s=dt(e,r);n+=e.slice(r,s),r=s;continue}if(o==="="&&e[r+1]===">"){n+="=>",r+=2;continue}if(o==="{"||o==="["||o==="("||o==="<")i++;else if(o==="}"||o==="]"||o===")"||o===">")i--;if((o===";"||o===","||o===`
96
96
  `)&&i===0){if(n.trim()!=="")t.push(n.trim());n="",r++;continue}n+=o,r++}if(n.trim()!=="")t.push(n.trim());return t}function hh(e){let t=e.trim();if(!t.startsWith("{"))return null;let i=je(t,0,"{","}");if(i===-1||t.slice(i+1).trim()!=="")return null;let n=uh(t.slice(1,i));if(n.length===0)return"{}";let r=[];for(let o of n){let s=/^\(\s*\w+\s*:\s*/.exec(o);if(!s)return null;let a=s[0].length,c=o[a];if(c!=="'"&&c!=='"'&&c!=="`")return null;let f=tt(o,a),u=o.slice(a+1,f-1),l=je(o,o.indexOf("(",0),"(",")");if(l===-1)return null;let y=o.slice(a,l),p=si(y).slice(1),w=o.slice(l+1).trim();if(w.startsWith(":"))w=w.slice(1).trim();if(w==="")w="void";r.push(`${JSON.stringify(u)}: (${p.map((S)=>S.trim()).join(", ")}) => ${w}`)}return`{ ${r.join(", ")} }`}function Qn(e){let t=e;for(let i of["defineProps","defineEmits","defineExpose","defineSlots","defineOptions"])t=dh(t,i);return t}function dh(e,t){let i=new RegExp(`\\b${t}\\b`,"g"),n=[],r=e,o;while((o=i.exec(e))!==null){let s=e.lastIndexOf(`
97
97
  `,o.index)+1,a=e.slice(s,o.index),c=/^\s*(?:(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*(?::[^=]+)?=\s*)?(withDefaults\s*\(\s*)?$/.exec(a);if(!c)continue;let f=o.index+o[0].length;while(f<e.length&&/\s/.test(e[f]))f++;if(e[f]==="<"){let y=Xn(e,f);if(y===-1)continue;f=y+1;while(f<e.length&&/\s/.test(e[f]))f++}if(e[f]!=="(")continue;let u=je(e,f,"(",")");if(u===-1)continue;if(c[1]){let y=s+a.length-c[1].length,p=e.indexOf("(",y);if(p!==-1){let w=je(e,p,"(",")");if(w!==-1)u=w}}let l=u+1;while(l<e.length&&e[l]!==`
98
98
  `&&/\s|;/.test(e[l]))l++;if(e[l]===`
99
- `)l++;n.push([s,l])}for(let s=n.length-1;s>=0;s--)r=r.slice(0,n[s][0])+r.slice(n[s][1]);return r}function eo(e){let t=mh(e);if(t!==-1){let i=/^export\s+default\b/.exec(e.slice(t))?.[0];if(!i)return{options:null,script:e,passthrough:!1};let n=t+i.length;while(n<e.length&&/\s/.test(e[n]))n++;let r=-1,o=-1,s=-1;if(e[n]==="{")r=n,o=je(e,n,"{","}"),s=o;else if(e.startsWith("defineComponent",n)){let f=e.indexOf("(",n);if(f!==-1){let u=f+1;while(u<e.length&&/\s/.test(e[u]))u++;if(e[u]==="{")r=u,o=je(e,u,"{","}"),s=je(e,f,"(",")")}}if(r===-1||o===-1||s===-1)return{options:null,script:e,passthrough:!0};let a=s+1;if(e[a]===";")a++;let c=(e.slice(0,t)+e.slice(a)).trim();return{options:e.slice(r,o+1),script:c,passthrough:!1}}return{options:null,script:e,passthrough:!1}}function mh(e){let t=0,i=0;while(i<e.length){let n=e[i];if(n==='"'||n==="'"){i=tt(e,i);continue}if(n==="`"){i=st(e,i);continue}if(n==="/"&&(e[i+1]==="/"||e[i+1]==="*")){i=dt(e,i);continue}if(n==="{"||n==="["||n==="(")t++;else if(n==="}"||n==="]"||n===")")t=Math.max(0,t-1);else if(t===0&&e.startsWith("export",i)){let r=i===0?"":e[i-1],o=e[i+6]??"";if(!/[\w$]/.test(r)&&!/[\w$]/.test(o)){if(/^export\s+default\b/.exec(e.slice(i)))return i}}i++}return-1}function $r(e,t){let i=Ei(e).find((n)=>n.key===t);return i&&i.value!==""?i.value:null}function Ar(e,t){let i=gh(e),n=e;for(let r=i.length-1;r>=0;r--){let o=i[r],s=n.slice(0,o.start)+n.slice(o.end);if(ph(s,o.name))continue;if(new RegExp(`\\btypeof\\s+${o.name}\\b`).test(t))continue;n=s}return n}function ph(e,t){let i=0;while(i<e.length){let n=e[i];if(n==='"'||n==="'"){i=tt(e,i);continue}if(n==="`"){i=st(e,i);continue}if(n==="/"&&(e[i+1]==="/"||e[i+1]==="*")){i=dt(e,i);continue}if(/[A-Za-z_$]/.test(n)){let r=i+1;while(r<e.length&&/[\w$]/.test(e[r]))r++;if(e.slice(i,r)===t)return!0;i=r;continue}i++}return!1}function gh(e){let t=[],i=yh(e),n=/^[ \t]*(const|let|var|(?:async[ \t]+)?function)[ \t]+([A-Za-z_$][\w$]*)[ \t]*(?::[^=\n]+)?=?/gm,r;while((r=n.exec(e))!==null){let o=e.lastIndexOf(`
99
+ `)l++;n.push([s,l])}for(let s=n.length-1;s>=0;s--)r=r.slice(0,n[s][0])+r.slice(n[s][1]);return r}function eo(e){let t=mh(e);if(t!==-1){let i=/^export\s+default\b/.exec(e.slice(t))?.[0];if(!i)return{options:null,script:e,passthrough:!1};let n=t+i.length;while(n<e.length&&/\s/.test(e[n]))n++;let r=-1,o=-1,s=-1;if(e[n]==="{")r=n,o=je(e,n,"{","}"),s=o;else if(e.startsWith("defineComponent",n)){let f=e.indexOf("(",n);if(f!==-1){let u=f+1;while(u<e.length&&/\s/.test(e[u]))u++;if(e[u]==="{")r=u,o=je(e,u,"{","}"),s=je(e,f,"(",")")}}if(r===-1||o===-1||s===-1)return{options:null,script:e,passthrough:!0};let a=s+1;if(e[a]===";")a++;let c=(e.slice(0,t)+e.slice(a)).trim();return{options:e.slice(r,o+1),script:c,passthrough:!1}}return{options:null,script:e,passthrough:!1}}function mh(e){let t=0,i=0;while(i<e.length){let n=e[i];if(n==='"'||n==="'"){i=tt(e,i);continue}if(n==="`"){i=at(e,i);continue}if(n==="/"&&(e[i+1]==="/"||e[i+1]==="*")){i=dt(e,i);continue}if(n==="{"||n==="["||n==="(")t++;else if(n==="}"||n==="]"||n===")")t=Math.max(0,t-1);else if(t===0&&e.startsWith("export",i)){let r=i===0?"":e[i-1],o=e[i+6]??"";if(!/[\w$]/.test(r)&&!/[\w$]/.test(o)){if(/^export\s+default\b/.exec(e.slice(i)))return i}}i++}return-1}function $r(e,t){let i=Ei(e).find((n)=>n.key===t);return i&&i.value!==""?i.value:null}function Ar(e,t){let i=gh(e),n=e;for(let r=i.length-1;r>=0;r--){let o=i[r],s=n.slice(0,o.start)+n.slice(o.end);if(ph(s,o.name))continue;if(new RegExp(`\\btypeof\\s+${o.name}\\b`).test(t))continue;n=s}return n}function ph(e,t){let i=0;while(i<e.length){let n=e[i];if(n==='"'||n==="'"){i=tt(e,i);continue}if(n==="`"){i=at(e,i);continue}if(n==="/"&&(e[i+1]==="/"||e[i+1]==="*")){i=dt(e,i);continue}if(/[A-Za-z_$]/.test(n)){let r=i+1;while(r<e.length&&/[\w$]/.test(e[r]))r++;if(e.slice(i,r)===t)return!0;i=r;continue}i++}return!1}function gh(e){let t=[],i=yh(e),n=/^[ \t]*(const|let|var|(?:async[ \t]+)?function)[ \t]+([A-Za-z_$][\w$]*)[ \t]*(?::[^=\n]+)?=?/gm,r;while((r=n.exec(e))!==null){let o=e.lastIndexOf(`
100
100
  `,r.index)+1;if(!i.has(o))continue;if(/\bexport\b/.test(e.slice(o,r.index)))continue;let s=r[1],a=r[2],c=r.index+r[0].length,f=-1;if(s.endsWith("function")){let u=e.indexOf("(",c);if(u===-1)continue;let l=je(e,u,"(",")");if(l===-1)continue;c=l+1;while(c<e.length&&/\s/.test(e[c]))c++;if(e[c]===":")while(c<e.length&&e[c]!=="{"&&e[c]!==`
101
101
  `)c++;while(c<e.length&&/\s/.test(e[c])&&e[c]!==`
102
- `)c++;if(e[c]!=="{")continue;let y=je(e,c,"{","}");if(y===-1)continue;f=y+1}else{let u=0;while(c<e.length){let l=e[c];if(l==='"'||l==="'"){c=tt(e,c);continue}if(l==="`"){c=st(e,c);continue}if(l==="/"&&(e[c+1]==="/"||e[c+1]==="*")){c=dt(e,c);continue}if(l==="{"||l==="["||l==="(")u++;else if(l==="}"||l==="]"||l===")")u--;else if(l===";"&&u===0){f=c+1;break}else if(l===`
102
+ `)c++;if(e[c]!=="{")continue;let y=je(e,c,"{","}");if(y===-1)continue;f=y+1}else{let u=0;while(c<e.length){let l=e[c];if(l==='"'||l==="'"){c=tt(e,c);continue}if(l==="`"){c=at(e,c);continue}if(l==="/"&&(e[c+1]==="/"||e[c+1]==="*")){c=dt(e,c);continue}if(l==="{"||l==="["||l==="(")u++;else if(l==="}"||l==="]"||l===")")u--;else if(l===";"&&u===0){f=c+1;break}else if(l===`
103
103
  `&&u===0){f=c;break}c++}if(f===-1)f=e.length}if(e[f]===`
104
- `)f++;t.push({name:a,start:r.index,end:f})}return t}function yh(e){let t=new Set([0]),i=0,n=0;while(n<e.length){let r=e[n];if(r==='"'||r==="'"){n=tt(e,n);continue}if(r==="`"){n=st(e,n);continue}if(r==="/"&&(e[n+1]==="/"||e[n+1]==="*")){n=dt(e,n);continue}if(r==="{"||r==="["||r==="(")i++;else if(r==="}"||r==="]"||r===")")i=Math.max(0,i-1);if(r===`
104
+ `)f++;t.push({name:a,start:r.index,end:f})}return t}function yh(e){let t=new Set([0]),i=0,n=0;while(n<e.length){let r=e[n];if(r==='"'||r==="'"){n=tt(e,n);continue}if(r==="`"){n=at(e,n);continue}if(r==="/"&&(e[n+1]==="/"||e[n+1]==="*")){n=dt(e,n);continue}if(r==="{"||r==="["||r==="(")i++;else if(r==="}"||r==="]"||r===")")i=Math.max(0,i-1);if(r===`
105
105
  `&&i===0)t.add(n+1);n++}return t}function xr(e,t,i){let n=e.indexOf(i);if(n===-1)return e;let r=e.lastIndexOf(`
106
- `,n)+1;if(/\bexport\b/.test(e.slice(r,n)))return e;let o=e.slice(0,n)+e.slice(n+i.length);if(new RegExp(`\\b${t}\\b`).test(o))return e;return o}function to(e){let t="",i=0,n=()=>{for(let o=t.length-1;o>=0;o--)if(!/\s/.test(t[o]))return t[o];return""},r=(o)=>{for(let s=o;s<e.length;s++)if(!/\s/.test(e[s]))return e[s];return""};while(i<e.length){let o=e[i];if(o==='"'||o==="'"){let s=tt(e,i);t+=e.slice(i,s),i=s;continue}if(o==="`"){let s=st(e,i);t+=e.slice(i,s),i=s;continue}if(o==="/"&&e[i+1]==="*"){let s=dt(e,i);t+=e.slice(i,s).replace(/\s*\n\s*/g," "),i=s;continue}if(o==="/"&&e[i+1]==="/"){let s=i+2;while(s<e.length&&e[s]!==`
106
+ `,n)+1;if(/\bexport\b/.test(e.slice(r,n)))return e;let o=e.slice(0,n)+e.slice(n+i.length);if(new RegExp(`\\b${t}\\b`).test(o))return e;return o}function to(e){let t="",i=0,n=()=>{for(let o=t.length-1;o>=0;o--)if(!/\s/.test(t[o]))return t[o];return""},r=(o)=>{for(let s=o;s<e.length;s++)if(!/\s/.test(e[s]))return e[s];return""};while(i<e.length){let o=e[i];if(o==='"'||o==="'"){let s=tt(e,i);t+=e.slice(i,s),i=s;continue}if(o==="`"){let s=at(e,i);t+=e.slice(i,s),i=s;continue}if(o==="/"&&e[i+1]==="*"){let s=dt(e,i);t+=e.slice(i,s).replace(/\s*\n\s*/g," "),i=s;continue}if(o==="/"&&e[i+1]==="/"){let s=i+2;while(s<e.length&&e[s]!==`
107
107
  `)s++;let a=e.slice(i+2,s).trim();if(a!==""&&!a.includes("*/"))t+=`/* ${a} */`;i=s;continue}if(o===`
108
108
  `){let s=n(),a=r(i+1);if(s===""||a===""){i++;continue}let c=Ch(t);if(!c&&("{;,(<:=[".includes(s)||"}),]>;|&".includes(a))){if(!t.endsWith(" ")&&!t.endsWith(";"))t+=" "}else if(c){if(!t.endsWith(" "))t+=" "}else{if(t.endsWith(" "))t=t.slice(0,-1);t+="; "}i++;while(i<e.length&&(e[i]===" "||e[i]==="\t"))i++;continue}t+=o,i++}return t}function Ch(e){let t=e.length-1;while(t>=0&&/\s/.test(e[t]))t--;if(t<1||e[t]!=="/"||e[t-1]!=="*")return!1;let i=e.lastIndexOf("/*",t);if(i===-1)return!1;for(let n=i-1;n>=0;n--){let r=e[n];if(/\s/.test(r))continue;return"{;,(<:".includes(r)}return!0}function Rr(e,t){let i=[e,t].filter((n)=>n!==null);for(let n of i){let r=bi(n,"defineProps");if(!r)continue;if(r.generic){let o=r.generic;if(o.startsWith("{"))return{type:o};if(/^[A-Za-z_$][\w$]*$/.test(o)){for(let s of i){let a=ka(s,o);if(!a)continue;let c=ah(s,o);if(c===null)continue;return{type:c,inlinedLocal:{name:o,declText:s.slice(a.start,a.end)}}}return{type:o}}return{type:o}}if(r.arg){let o=Tr(r.arg);if(o!==null)return{type:o}}}return null}function io(e,t){let i=[e,t].filter((n)=>n!==null);for(let n of i){let r=bi(n,"defineEmits");if(!r)continue;if(r.generic)return hh(r.generic)??r.generic;if(r.arg){let o=Ma(r.arg);if(o!==null)return o}}return null}function ro(e,t){let i=[e,t].filter((n)=>n!==null);for(let n of i){let r=bi(n,"defineExpose");if(!r||!r.arg||!r.arg.startsWith("{"))continue;let o=Ei(r.arg);if(o.length===0)return null;return`{ ${o.map((s)=>{if(s.value===""&&/^[A-Za-z_$][\w$]*$/.test(s.key))return`${vi(s.key)}: typeof ${s.key}`;let a=s.isMethod||/=>|^\s*function\b/.test(s.value);return`${vi(s.key)}: ${a?"(...args: any[]) => any":"unknown"}`}).join(", ")} }`}return null}function Da(e){let t=sh(e),i="",n=null,r=null;if(t.script){let x=eo(t.script.content);if(x.passthrough)return t.scriptSetup?`${t.script.content}
109
109
  ${t.scriptSetup.content}`:t.script.content;if(i=x.script,x.options){let E=$r(x.options,"props");if(E)n=Tr(E);let k=$r(x.options,"emits");if(k)r=Ma(k)}}let o=t.scriptSetup?.content??null,s=o!==null?Qn(o):null,a=Rr(o,o!==null?null:i),c=a?.type??n??"{}",f=io(o,null)??r,u=ro(o,null),l=a?.inlinedLocal;if(l){if(i=xr(i,l.name,l.declText),s!==null)s=xr(s,l.name,l.declText)}let y=[c,u??"{}"];if(f)y.push("{}","{}","{}","{}","{}",f);let p=to(`DefineComponent<${y.join(", ")}>`),w=[],S=Ar(i,p);if(S.trim()!=="")w.push(S);if(s&&s.trim()!==""){let x=Ar(s,p);if(x.trim()!=="")w.push(x)}return w.push("import type { DefineComponent } from 'vue'"),w.push(`type __DtsxComponentType = ${p}`),w.push("const __dtsx_component__: __DtsxComponentType = null as unknown as __DtsxComponentType"),w.push("export default __dtsx_component__"),w.join(`
@@ -134,11 +134,11 @@ ${w}}`}}let f=o.length>0?`{
134
134
  `,l+2);l=g===-1?a:g+1;continue}if(d===Ee){let g=r.indexOf("*/",l+2);l=g===-1?a:g+2;continue}}break}}function w(m){let h=m.length,d=0,g=h;for(let C=0;C<h;C++){let v=m.charCodeAt(C);if(d){if(v===Ye){C++;continue}if(v===d)d=0;continue}if(v===le||v===ue||v===Me){d=v;continue}if(v===X&&C+1<h){let T=m.charCodeAt(C+1);if(T===X){g=C;while(g>0&&(m.charCodeAt(g-1)===Pe||m.charCodeAt(g-1)===Oe))g--;return m.slice(0,g)}if(T===Ee){let P=m.indexOf("*/",C+2);if(P!==-1){m=`${m.slice(0,C)} ${m.slice(P+2)}`,C--;continue}}}}g=h;while(g>0&&(m.charCodeAt(g-1)===Pe||m.charCodeAt(g-1)===Oe||m.charCodeAt(g-1)===be))g--;return g<h?m.slice(0,g):m}function S(m){l++;let h=m===le?"'":'"';while(l<a){let d=r.indexOf(h,l);if(d===-1){l=a;return}let g=0,C=d-1;while(C>=0&&r.charCodeAt(C)===Ye)g++,C--;if(g%2===0){l=d+1;return}l=d+1}}function x(){l++;let m=[];while(l<a){let h=r.charCodeAt(l);if(m.length===0){if(h===Ye){l+=2;continue}if(h===Me){l++;return}if(h===ol&&l+1<a&&r.charCodeAt(l+1)===z){l+=2,m.push(0);continue}l++;continue}if(h===le||h===ue){S(h);continue}if(h===Me){x();continue}if(h===X&&l+1<a){let d=r.charCodeAt(l+1);if(d===X){let g=r.indexOf(`
135
135
  `,l+2);l=g===-1?a:g+1;continue}if(d===Ee){let g=r.indexOf("*/",l+2);l=g===-1?a:g+2;continue}if(I()){J();continue}l++;continue}if(h===z){m[m.length-1]++,l++;continue}if(h===Q){let d=m[m.length-1];if(d===0){m.pop(),l++;continue}m[m.length-1]=d-1,l++;continue}l++}}function E(){let m=r.charCodeAt(l);if(m===le||m===ue)return S(m),!0;if(m===Me)return x(),!0;if(m===X&&l+1<a){let h=r.charCodeAt(l+1);if(h===X){let d=r.indexOf(`
136
136
  `,l+2);return l=d===-1?a:d+1,!0}if(h===Ee){let d=r.indexOf("*/",l+2);return l=d===-1?a:d+2,!0}if(I())return J(),!0}return!1}function k(m){let h=m;for(;;){while(h>=0&&(r.charCodeAt(h)===Pe||r.charCodeAt(h)===Oe||r.charCodeAt(h)===he||r.charCodeAt(h)===be))h--;if(h<0)return-1;if(r.charCodeAt(h)===X&&h>0&&r.charCodeAt(h-1)===Ee){let C=r.lastIndexOf("/*",h-2);if(C===-1)return-1;h=C-1;continue}let d=r.lastIndexOf(`
137
- `,h)+1,g=M(d,h);if(g!==-1){h=g-1;continue}return h}}function M(m,h){let d=0;for(let g=m;g<=h;g++){let C=r.charCodeAt(g);if(d){if(C===Ye){g++;continue}if(C===d)d=0;continue}if(C===le||C===ue||C===Me){d=C;continue}if(C===X&&g+1<=h&&r.charCodeAt(g+1)===X)return g}return-1}function I(){let m=k(l-1);if(m<0)return!0;let h=r.charCodeAt(m);if(h===Se||h===se||h===we||h===33||h===38||h===124||h===Fr||h===at||h===lt||h===ie||h===z||h===Q||h===94||h===126||h===43||h===45||h===Ee||h===37||h===ve||h===fe)return!0;if(Ze(h)){let d=m;while(d>=0&&Ze(r.charCodeAt(d)))d--;let g=r.slice(d+1,m+1);if(g==="return"||g==="typeof"||g==="void"||g==="delete"||g==="throw"||g==="new"||g==="in"||g==="of"||g==="case"||g==="instanceof"||g==="yield"||g==="await")return!0}return!1}function J(){l++;let m=!1;while(l<a){let h=r.charCodeAt(l);if(h===Ye){l+=2;continue}if(m){if(h===Re)m=!1;l++;continue}if(h===we){m=!0,l++;continue}if(h===X){l++;break}if(h===he||h===be)break;l++}while(l<a&&Ze(r.charCodeAt(l)))l++}function W(){let m=l;while(l<a&&Ze(r.charCodeAt(l)))l++;return r.slice(m,l)}function R(m){if(l+m.length>a)return!1;for(let h=0;h<m.length;h++)if(r.charCodeAt(l+h)!==m.charCodeAt(h))return!1;if(l+m.length<a&&Ze(r.charCodeAt(l+m.length)))return!1;return!0}function D(m){let h=l+m;while(h<a){let d=r.charCodeAt(h);if(d===Pe||d===Oe||d===he||d===be){h++;continue}return d!==mt&&d!==Se}return!1}function Y(){if(l>=a)return!1;switch(r.charCodeAt(l)){case 101:return R("export")||R("enum");case 105:return R("import")||R("interface");case 102:return R("function");case 99:return R("class")||R("const");case 116:return R("type");case 108:return R("let");case 118:return R("var");case 100:return R("declare")||R("default");case 109:return R("module");case 110:return R("namespace");case 97:return R("abstract")||R("async");default:return!1}}function ne(){let m=r.charCodeAt(l);if(m!==he&&m!==be)return!1;let h=l;if(l++,m===be&&l<a&&r.charCodeAt(l)===he)l++;while(l<a){let g=r.charCodeAt(l);if(g===Pe||g===Oe||g===be||g===he){l++;continue}if(g===X&&l+1<a){let C=r.charCodeAt(l+1);if(C===X){let v=r.indexOf(`
137
+ `,h)+1,g=M(d,h);if(g!==-1){h=g-1;continue}return h}}function M(m,h){let d=0;for(let g=m;g<=h;g++){let C=r.charCodeAt(g);if(d){if(C===Ye){g++;continue}if(C===d)d=0;continue}if(C===le||C===ue||C===Me){d=C;continue}if(C===X&&g+1<=h&&r.charCodeAt(g+1)===X)return g}return-1}function I(){let m=k(l-1);if(m<0)return!0;let h=r.charCodeAt(m);if(h===Se||h===se||h===we||h===33||h===38||h===124||h===Fr||h===lt||h===ct||h===ie||h===z||h===Q||h===94||h===126||h===43||h===45||h===Ee||h===37||h===ve||h===fe)return!0;if(Ze(h)){let d=m;while(d>=0&&Ze(r.charCodeAt(d)))d--;let g=r.slice(d+1,m+1);if(g==="return"||g==="typeof"||g==="void"||g==="delete"||g==="throw"||g==="new"||g==="in"||g==="of"||g==="case"||g==="instanceof"||g==="yield"||g==="await")return!0}return!1}function J(){l++;let m=!1;while(l<a){let h=r.charCodeAt(l);if(h===Ye){l+=2;continue}if(m){if(h===Re)m=!1;l++;continue}if(h===we){m=!0,l++;continue}if(h===X){l++;break}if(h===he||h===be)break;l++}while(l<a&&Ze(r.charCodeAt(l)))l++}function W(){let m=l;while(l<a&&Ze(r.charCodeAt(l)))l++;return r.slice(m,l)}function R(m){if(l+m.length>a)return!1;for(let h=0;h<m.length;h++)if(r.charCodeAt(l+h)!==m.charCodeAt(h))return!1;if(l+m.length<a&&Ze(r.charCodeAt(l+m.length)))return!1;return!0}function D(m){let h=l+m;while(h<a){let d=r.charCodeAt(h);if(d===Pe||d===Oe||d===he||d===be){h++;continue}return d!==mt&&d!==Se}return!1}function Y(){if(l>=a)return!1;switch(r.charCodeAt(l)){case 101:return R("export")||R("enum");case 105:return R("import")||R("interface");case 102:return R("function");case 99:return R("class")||R("const");case 116:return R("type");case 108:return R("let");case 118:return R("var");case 100:return R("declare")||R("default");case 109:return R("module");case 110:return R("namespace");case 97:return R("abstract")||R("async");default:return!1}}function ne(){let m=r.charCodeAt(l);if(m!==he&&m!==be)return!1;let h=l;if(l++,m===be&&l<a&&r.charCodeAt(l)===he)l++;while(l<a){let g=r.charCodeAt(l);if(g===Pe||g===Oe||g===be||g===he){l++;continue}if(g===X&&l+1<a){let C=r.charCodeAt(l+1);if(C===X){let v=r.indexOf(`
138
138
  `,l+2);l=v===-1?a:v+1;continue}if(C===Ee){let v=r.indexOf("*/",l+2);l=v===-1?a:v+2;continue}}break}let d=l>=a||Y()||r.charCodeAt(l)===Q;return l=h,d}function De(m){let h=m-1;while(h>=0){let b=r.charCodeAt(h);if(b===Pe||b===Oe||b===be||b===he){h--;continue}break}if(h<0)return!0;let d=r[h];if("+-*/%=<>&|^!~?:,.([{".includes(d))return!0;let g=h;while(g>0&&r.charCodeAt(g-1)!==he)g--;let C=r.slice(g,h+1),v=C.lastIndexOf("<");if(v!==-1&&/^<[A-Za-z]/.test(C.slice(v))&&!C.slice(v).includes(">"))return!0;let T=h;while(T>=0&&/[a-z]/i.test(r[T]))T--;let P=r.slice(T+1,h+1);return["as","in","of","new","typeof","keyof","extends","instanceof","satisfies","await","return","yield","void"].includes(P)}function K(){let m=r.charCodeAt(l);if(m!==he&&m!==be)return!1;if(De(l))return!1;let h=l;l++;while(l<a){let v=r.charCodeAt(l);if(v===Pe||v===Oe||v===be||v===he){l++;continue}if(v===X&&l+1<a){let T=r.charCodeAt(l+1);if(T===X){let P=r.indexOf(`
139
139
  `,l+2);l=P===-1?a:P+1;continue}if(T===Ee){let P=r.indexOf("*/",l+2);l=P===-1?a:P+2;continue}}break}let d=l<a?r[l]:"",g=r.slice(l,l+2),C=d==="."||d==="?"||d===":"||d===")"||d==="]"||d==="}"||d===","||d==="+"||d==="-"||d==="*"||d==="/"||d==="%"||d==="<"||d===">"||d==="="||d==="&"||d==="|"||d==="^"||d==="`"||g==="=>"||R("as")||R("satisfies")||R("instanceof")||R("in");return l=h,!C}function me(){let m=r.charCodeAt(l);if(m!==he&&m!==be)return!1;if(De(l))return!1;let h=l;l++;while(l<a){let C=r.charCodeAt(l);if(C===Pe||C===Oe||C===be||C===he){l++;continue}if(C===X&&l+1<a){let v=r.charCodeAt(l+1);if(v===X){let T=r.indexOf(`
140
140
  `,l+2);l=T===-1?a:T+1;continue}if(v===Ee){let T=r.indexOf("*/",l+2);l=T===-1?a:T+2;continue}}break}let d=l<a?r[l]:"",g=d==="|"||d==="&"||d==="["||d==="."||d==="?"||d===":"||d===">"||d===")"||d===","||R("extends");return l=h,!g}function te(){let m=r.charCodeAt(l);if(m!==he&&m!==be)return!1;let h=l;if(l++,m===be&&l<a&&r.charCodeAt(l)===he)l++;while(l<a){let g=r.charCodeAt(l);if(g===Pe||g===Oe||g===be||g===he){l++;continue}if(g===X&&l+1<a&&r.charCodeAt(l+1)===X){let C=r.indexOf(`
141
- `,l+2);l=C===-1?a:C+1;continue}break}if(l>=a)return l=h,!0;let d=r.charCodeAt(l);if(d===124||d===38||d===mt||d===Fr||d===at)return l=h,!1;if(R("extends")||R("keyof")||R("typeof")||R("infer")||R("is")||R("as")||R("in"))return l=h,!1;return l=h,!0}let re=/[{}'"`\/]/g,oe=/[()'"`\/]/g,de=/[[\]'"`\/]/g,G=/[<>'"`\/]/g;function _(m,h){let d=1;l++;let g=m===z?re:m===se?oe:m===we?de:G;g.lastIndex=l;let C;while((C=g.exec(r))!==null){let v=C.index,T=r.charCodeAt(v);if(T===le||T===ue){l=v,S(T),g.lastIndex=l;continue}if(T===Me){l=v,x(),g.lastIndex=l;continue}if(T===X){if(l=v,E()){g.lastIndex=l;continue}g.lastIndex=v+1;continue}if(T===m)d++;else if(T===h){if(h===fe&&v>0&&r.charCodeAt(v-1)===Se){g.lastIndex=v+1;continue}if(d--,d===0)return l=v+1,l}g.lastIndex=v+1}return l=a,l}function U(){return l>0&&r.charCodeAt(l-1)===Se}function ee(){return l+1<a&&r.charCodeAt(l+1)===fe}let H=/[<{};'"`\/\n\r()[\]]/g;function q(m=!1){let h=0,d=0,g=0,C=0,v=r.charCodeAt(l)===z;H.lastIndex=l;let T;while((T=H.exec(r))!==null){let P=T.index,b=r.charCodeAt(P);if(b===le||b===ue){l=P,S(b),H.lastIndex=l;continue}if(b===Me){l=P,x(),H.lastIndex=l;continue}if(b===X){if(P>0&&r.charCodeAt(P-1)===ve){H.lastIndex=P+1;continue}if(l=P,E()){H.lastIndex=l;continue}H.lastIndex=P+1;continue}if(b===ve){let A=Po(P);if(A!==null)C=Math.max(0,C+A);H.lastIndex=P+1;continue}if(b===se){d++,H.lastIndex=P+1;continue}if(b===Ae){d--,H.lastIndex=P+1;continue}if(b===we){g++,H.lastIndex=P+1;continue}if(b===Re){g--,H.lastIndex=P+1;continue}if(b===z){h++,H.lastIndex=P+1;continue}if(b===Q){let A=h>0;if(!A&&m&&d===0&&g===0&&C===0){l=P;return}if(A)h--;if((!A||v)&&h===0&&d===0&&g===0&&C===0){l=P+1;return}H.lastIndex=P+1;continue}if(b===ie&&h===0&&d===0&&g===0&&C===0){l=P+1;return}if((b===he||b===be)&&h===0&&d===0&&g===0&&C===0){if(l=P,ne())return}H.lastIndex=P+1}l=a}function Te(){l++;while(l<a&&(r.charCodeAt(l)===Pe||r.charCodeAt(l)===Oe))l++;let m=r.indexOf(`
141
+ `,l+2);l=C===-1?a:C+1;continue}break}if(l>=a)return l=h,!0;let d=r.charCodeAt(l);if(d===124||d===38||d===mt||d===Fr||d===lt)return l=h,!1;if(R("extends")||R("keyof")||R("typeof")||R("infer")||R("is")||R("as")||R("in"))return l=h,!1;return l=h,!0}let re=/[{}'"`\/]/g,oe=/[()'"`\/]/g,de=/[[\]'"`\/]/g,G=/[<>'"`\/]/g;function _(m,h){let d=1;l++;let g=m===z?re:m===se?oe:m===we?de:G;g.lastIndex=l;let C;while((C=g.exec(r))!==null){let v=C.index,T=r.charCodeAt(v);if(T===le||T===ue){l=v,S(T),g.lastIndex=l;continue}if(T===Me){l=v,x(),g.lastIndex=l;continue}if(T===X){if(l=v,E()){g.lastIndex=l;continue}g.lastIndex=v+1;continue}if(T===m)d++;else if(T===h){if(h===fe&&v>0&&r.charCodeAt(v-1)===Se){g.lastIndex=v+1;continue}if(d--,d===0)return l=v+1,l}g.lastIndex=v+1}return l=a,l}function U(){return l>0&&r.charCodeAt(l-1)===Se}function ee(){return l+1<a&&r.charCodeAt(l+1)===fe}let H=/[<{};'"`\/\n\r()[\]]/g;function q(m=!1){let h=0,d=0,g=0,C=0,v=r.charCodeAt(l)===z;H.lastIndex=l;let T;while((T=H.exec(r))!==null){let P=T.index,b=r.charCodeAt(P);if(b===le||b===ue){l=P,S(b),H.lastIndex=l;continue}if(b===Me){l=P,x(),H.lastIndex=l;continue}if(b===X){if(P>0&&r.charCodeAt(P-1)===ve){H.lastIndex=P+1;continue}if(l=P,E()){H.lastIndex=l;continue}H.lastIndex=P+1;continue}if(b===ve){let A=Po(P);if(A!==null)C=Math.max(0,C+A);H.lastIndex=P+1;continue}if(b===se){d++,H.lastIndex=P+1;continue}if(b===Ae){d--,H.lastIndex=P+1;continue}if(b===we){g++,H.lastIndex=P+1;continue}if(b===Re){g--,H.lastIndex=P+1;continue}if(b===z){h++,H.lastIndex=P+1;continue}if(b===Q){let A=h>0;if(!A&&m&&d===0&&g===0&&C===0){l=P;return}if(A)h--;if((!A||v)&&h===0&&d===0&&g===0&&C===0){l=P+1;return}H.lastIndex=P+1;continue}if(b===ie&&h===0&&d===0&&g===0&&C===0){l=P+1;return}if((b===he||b===be)&&h===0&&d===0&&g===0&&C===0){if(l=P,ne())return}H.lastIndex=P+1}l=a}function Te(){l++;while(l<a&&(r.charCodeAt(l)===Pe||r.charCodeAt(l)===Oe))l++;let m=r.indexOf(`
142
142
  `,l),h=m===-1?a:m,d=r.indexOf(";",l);if(d!==-1&&d<h){let g=d-1;while(g>=l&&(r.charCodeAt(g)===Pe||r.charCodeAt(g)===Oe))g--;let C=r.charCodeAt(l),v=r.charCodeAt(g);if(C===z&&v===Q||C===we&&v===Re||C===le&&v===le||C===ue&&v===ue||C===Me&&v===Me){l=d+1;return}}q()}function Fe(){_(z,Q);while(l<a&&Be(r.charCodeAt(l)))l++;if(R("from")){l+=4;while(l<a&&Be(r.charCodeAt(l)))l++;if(l<a){let m=r.charCodeAt(l);if(m===le||m===ue)S(m)}}while(l<a&&(r.charCodeAt(l)===Pe||r.charCodeAt(l)===Oe))l++;if(l<a&&r.charCodeAt(l)===ie)l++}function ki(){l++;while(l<a&&Be(r.charCodeAt(l)))l++;if(R("as")){l+=2;while(l<a&&Be(r.charCodeAt(l)))l++;W();while(l<a&&Be(r.charCodeAt(l)))l++}if(R("from")){l+=4;while(l<a&&Be(r.charCodeAt(l)))l++;if(l<a){let m=r.charCodeAt(l);if(m===le||m===ue)S(m)}}while(l<a&&(r.charCodeAt(l)===Pe||r.charCodeAt(l)===Oe))l++;if(l<a&&r.charCodeAt(l)===ie)l++}function Mi(m){let h=m.indexOf("from ");if(h===-1)return;let d=h+5;while(d<m.length&&(m.charCodeAt(d)===32||m.charCodeAt(d)===9))d++;if(d>=m.length)return;let g=m.charCodeAt(d);if(g!==39&&g!==34)return;let C=m.indexOf(m[d],d+1);if(C===-1)return;return m.slice(d+1,C)}function Qe(m){if(!o)return;let h=m-1;while(h>=0&&Be(r.charCodeAt(h)))h--;if(h<0)return;let d=[],g=!1;while(h>=0){if(h>=1&&r.charCodeAt(h)===X&&r.charCodeAt(h-1)===Ee){let T=r.lastIndexOf("/*",h-2);if(T>=0){d.push(r.slice(T,h+1)),g=!0,h=T-1;while(h>=0&&Be(r.charCodeAt(h)))h--;continue}break}let C=h;while(C>0&&r.charCodeAt(C-1)!==he)C--;let v=y(C,h+1);if(v.startsWith("//")){if(g)break;let T=[v];h=C-1;while(h>=0&&(r.charCodeAt(h)===he||r.charCodeAt(h)===be))h--;while(h>=0){let P=h;while(P>0&&r.charCodeAt(P-1)!==he)P--;let b=y(P,h+1);if(b.startsWith("//")){T.push(b),h=P-1;while(h>=0&&(r.charCodeAt(h)===he||r.charCodeAt(h)===be))h--}else if(b===""){h=P-1;while(h>=0&&(r.charCodeAt(h)===he||r.charCodeAt(h)===be))h--}else break}T.reverse(),d.push(T.join(`
143
143
  `));continue}break}if(d.length===0)return;return d.reverse(),d}function pc(m){let h=m,d=!1;while(l<a){let b=r.charCodeAt(l);if(b===ie){l++;break}if(b===le||b===ue){S(b),d=!0;while(l<a&&(r.charCodeAt(l)===Pe||r.charCodeAt(l)===Oe))l++;if(l<a&&r.charCodeAt(l)===ie)l++;break}if(b===he&&d)break;l++}let g=y(h,l),C=g.charCodeAt(7)===116&&(g.startsWith("import type ")||g.startsWith("import type{")),v=!1;{let b=6;while(b<g.length&&(g.charCodeAt(b)===Pe||g.charCodeAt(b)===Oe))b++;if(b<g.length&&g.charCodeAt(b)===116&&g.startsWith("type",b)){b+=4;while(b<g.length&&(g.charCodeAt(b)===Pe||g.charCodeAt(b)===Oe))b++}if(b<g.length){let A=g.charCodeAt(b);v=A===le||A===ue}}let T="";{let b=g.indexOf("from ");if(b!==-1){let A=b+5;while(A<g.length&&(g.charCodeAt(A)===Pe||g.charCodeAt(A)===Oe))A++;if(A<g.length){let O=g.charCodeAt(A);if(O===le||O===ue){let N=g.indexOf(String.fromCharCode(O),A+1);if(N!==-1)T=g.slice(A+1,N)}}}else if(v){let A=6;while(A<g.length&&g.charCodeAt(A)!==le&&g.charCodeAt(A)!==ue)A++;if(A<g.length){let O=g.charCodeAt(A),N=g.indexOf(String.fromCharCode(O),A+1);if(N!==-1)T=g.slice(A+1,N)}}}let P=Qe(h);return{kind:"import",name:"",text:g,isExported:!1,isTypeOnly:C,isSideEffect:v,source:T,leadingComments:P,start:h,end:l}}function _r(){let m=l;return _(z,Q),r.slice(m,l)}function Ao(m){let h=m.indexOf("(");if(h===-1)return m;let d=m.slice(h);if(d.indexOf("=")===-1)return m;let g=!1;for(let b=0;b<d.length;b++)if(d.charCodeAt(b)===61){let A=b>0?d.charCodeAt(b-1):0,O=b+1<d.length?d.charCodeAt(b+1):0;if(A!==61&&A!==33&&A!==60&&A!==62&&O!==61&&O!==62){g=!0;break}}if(!g)return m;let C=0,v=-1;for(let b=h;b<m.length;b++){let A=m.charCodeAt(b);if(A===40)C++;else if(A===41){if(C--,C===0){v=b;break}}}if(v===-1)return m;let T=m.slice(h,v+1),P=Gt(T);return m.slice(0,h)+P+m.slice(v+1)}function xo(m){let h=m.indexOf("//")!==-1||m.indexOf("/*")!==-1,d=m.split(`
144
144
  `),g=[],C=[],v=[],T=!1,P=1/0;for(let O=0;O<d.length;O++){let N=d[O];if(h){if(T){if(N.includes("*/"))T=!1;continue}let j=N.trim();if(j.length===0)continue;let L=j.charCodeAt(0);if(L===X){let Ke=j.charCodeAt(1);if(Ke===X)continue;if(Ke===Ee){if(!j.includes("*/"))T=!0;continue}}if(L===Ee)continue;let F=w(N);if(F.charCodeAt(F.length-1)===ie)F=F.slice(0,-1);F=Ao(F);let B=F.trim();if(!B)continue;g.push(F),C.push(B);let V=0;while(V<F.length&&Be(F.charCodeAt(V)))V++;if(B!=="{"&&B!=="}"){if(V<P)P=V}v.push(V)}else{let j=N.length;while(j>0&&(N.charCodeAt(j-1)===Pe||N.charCodeAt(j-1)===Oe||N.charCodeAt(j-1)===be))j--;if(j===0)continue;let L=j<N.length?N.slice(0,j):N;if(L.charCodeAt(L.length-1)===ie)L=L.slice(0,-1);L=Ao(L);let F=L.trim();if(!F)continue;g.push(L),C.push(F);let B=0;while(B<L.length&&Be(L.charCodeAt(B)))B++;if(F!=="{"&&F!=="}"){if(B<P)P=B}v.push(B)}}if(g.length===0)return"{}";if(P===1/0||P<=2)return g.join(`
@@ -146,20 +146,20 @@ ${w}}`}}let f=o.length>0?`{
146
146
  `)}function ht(){if(l>=a||r.charCodeAt(l)!==ve)return"";let m=l;_(ve,fe);let h=r.slice(m,l);if(h.includes(`
147
147
  `)){let d="",g=!1;for(let C=0;C<h.length;C++){let v=h.charCodeAt(C);if(v===32||v===9||v===10||v===13){if(!g&&d.length>0)d+=" ",g=!0}else d+=h[C],g=!1}if(d.charCodeAt(1)===32)d=`<${d.slice(2)}`;if(d.charCodeAt(d.length-2)===32)d=`${d.slice(0,-2)}>`;return d}return h}function $t(){if(l>=a||r.charCodeAt(l)!==se)return"()";let m=l;return _(se,Ae),r.slice(m,l)}function Di(m){if(m.indexOf("/")===-1)return m;let h="",d=!1,g=0;for(let C=0;C<m.length;C++){let v=m.charCodeAt(C);if(d){if(h+=m[C],v===Ye&&C+1<m.length){h+=m[++C];continue}if(v===g)d=!1;continue}if(v===le||v===ue||v===Me){d=!0,g=v,h+=m[C];continue}if(v===X&&C+1<m.length){let T=m.charCodeAt(C+1);if(T===Ee){let P=m.indexOf("*/",C+2);C=P===-1?m.length:P+1,h+=" ";continue}if(T===X){let P=m.indexOf(`
148
148
  `,C+2);C=P===-1?m.length:P-1;continue}}h+=m[C]}return h.trim()}function Gt(m){let h=m.slice(1,-1).trim();if(!h)return"()";if(m.indexOf(`
149
- `)===-1&&h.indexOf(":")!==-1&&h.indexOf("{")===-1&&h.indexOf("[")===-1&&h.indexOf("=")===-1&&h.indexOf("@")===-1&&h.indexOf("...")===-1){let b=0,A=0,O=0;for(let N=0;N<h.length;N++){let j=h.charCodeAt(N);if(j===se||j===ve||j===z)O++;else if(j===Ae||j===fe||j===Q)O--;else if(O===0){if(j===at)b++;else if(j===lt)A++}}if(b>=A+1){let N=!1;for(let j=0;j<go.length;j++){let L=go[j],F=h.indexOf(L);if(F!==-1){let B=F+L.length;if((F===0||!Ze(h.charCodeAt(F-1)))&&(B>=h.length||!Ze(h.charCodeAt(B)))){N=!0;break}}}if(!N)return m}}let d=[],g=0,C=0,v=!1,T=0;for(let b=0;b<=h.length;b++){if(b===h.length){d.push(Di(h.slice(g).trim()));break}let A=h.charCodeAt(b);if(v){if(A===Ye){b++;continue}if(A===T)v=!1;continue}if(A===X&&b+1<h.length){let O=h.charCodeAt(b+1);if(O===Ee){b+=2;while(b+1<h.length&&!(h.charCodeAt(b)===Ee&&h.charCodeAt(b+1)===X))b++;b++;continue}if(O===X){while(b<h.length&&h.charCodeAt(b)!==10)b++;continue}}if(A===le||A===ue||A===Me){v=!0,T=A;continue}if(A===se||A===z||A===we||A===ve)C++;else if(A===Ae||A===Q||A===Re||A===fe&&!(b>0&&h.charCodeAt(b-1)===Se))C--;else if(A===lt&&C===0)d.push(Di(h.slice(g,b).trim())),g=b+1}let P=[];for(let b of d){if(!b)continue;let A=b.trim();if(A.startsWith("//")||A.startsWith("/*"))continue;let O=b;{let N=!1,j=0,L=0,F=0;for(let B=0;B<O.length-1;B++){let V=O.charCodeAt(B);if(V===he){F=B+1;continue}if(N){if(V===Ye){B++;continue}if(V===j)N=!1;continue}if(V===le||V===ue||V===Me){N=!0,j=V;continue}if(V===z||V===we||V===se||V===ve){L++;continue}if(V===Q||V===Re||V===Ae||V===fe){if(L>0)L--;continue}if(V===X&&O.charCodeAt(B+1)===X){if(L===0){O=O.slice(0,B).trimEnd();break}let Ke=O.indexOf(`
149
+ `)===-1&&h.indexOf(":")!==-1&&h.indexOf("{")===-1&&h.indexOf("[")===-1&&h.indexOf("=")===-1&&h.indexOf("@")===-1&&h.indexOf("...")===-1){let b=0,A=0,O=0;for(let N=0;N<h.length;N++){let j=h.charCodeAt(N);if(j===se||j===ve||j===z)O++;else if(j===Ae||j===fe||j===Q)O--;else if(O===0){if(j===lt)b++;else if(j===ct)A++}}if(b>=A+1){let N=!1;for(let j=0;j<go.length;j++){let L=go[j],F=h.indexOf(L);if(F!==-1){let B=F+L.length;if((F===0||!Ze(h.charCodeAt(F-1)))&&(B>=h.length||!Ze(h.charCodeAt(B)))){N=!0;break}}}if(!N)return m}}let d=[],g=0,C=0,v=!1,T=0;for(let b=0;b<=h.length;b++){if(b===h.length){d.push(Di(h.slice(g).trim()));break}let A=h.charCodeAt(b);if(v){if(A===Ye){b++;continue}if(A===T)v=!1;continue}if(A===X&&b+1<h.length){let O=h.charCodeAt(b+1);if(O===Ee){b+=2;while(b+1<h.length&&!(h.charCodeAt(b)===Ee&&h.charCodeAt(b+1)===X))b++;b++;continue}if(O===X){while(b<h.length&&h.charCodeAt(b)!==10)b++;continue}}if(A===le||A===ue||A===Me){v=!0,T=A;continue}if(A===se||A===z||A===we||A===ve)C++;else if(A===Ae||A===Q||A===Re||A===fe&&!(b>0&&h.charCodeAt(b-1)===Se))C--;else if(A===ct&&C===0)d.push(Di(h.slice(g,b).trim())),g=b+1}let P=[];for(let b of d){if(!b)continue;let A=b.trim();if(A.startsWith("//")||A.startsWith("/*"))continue;let O=b;{let N=!1,j=0,L=0,F=0;for(let B=0;B<O.length-1;B++){let V=O.charCodeAt(B);if(V===he){F=B+1;continue}if(N){if(V===Ye){B++;continue}if(V===j)N=!1;continue}if(V===le||V===ue||V===Me){N=!0,j=V;continue}if(V===z||V===we||V===se||V===ve){L++;continue}if(V===Q||V===Re||V===Ae||V===fe){if(L>0)L--;continue}if(V===X&&O.charCodeAt(B+1)===X){if(L===0){O=O.slice(0,B).trimEnd();break}let Ke=O.indexOf(`
150
150
  `,B);if(Ke===-1){O=O.slice(0,F).trimEnd();break}let ze=O.slice(0,F),Vt=O.slice(Ke+1);O=`${ze}${Vt}`,B=F-1}}}if(!O.trim())continue;P.push(To(O))}return`(${P.join(", ")})`}function gc(m){if(!m.startsWith("{")&&!m.startsWith("["))return m;let h="",d=0,g=0,C=!1,v=0;while(d<m.length){let T=m.charCodeAt(d);if(C){if(T===Ye&&d+1<m.length){h+=m[d]+m[d+1],d+=2;continue}if(T===v)C=!1;h+=m[d],d++;continue}if(T===X&&d+1<m.length){let P=m.charCodeAt(d+1);if(P===Ee){let b=d;d+=2;while(d+1<m.length&&!(m.charCodeAt(d)===Ee&&m.charCodeAt(d+1)===X))d++;d=Math.min(d+2,m.length),h+=m.slice(b,d);continue}if(P===X){let b=d;while(d<m.length&&m.charCodeAt(d)!==10)d++;h+=m.slice(b,d);continue}}if(T===le||T===ue||T===Me){C=!0,v=T,h+=m[d],d++;continue}if(T===z||T===we||T===se)g++;else if(T===Q||T===Re||T===Ae)g--;if(g>=1&&T===Se&&(d+1>=m.length||m.charCodeAt(d+1)!==Se&&m.charCodeAt(d+1)!==fe)){while(h.length>0&&(h[h.length-1]===" "||h[h.length-1]==="\t"||h[h.length-1]===`
151
- `))h=h.slice(0,-1);d++;let P=0;while(d<m.length){let b=m.charCodeAt(d);if(b===le||b===ue||b===Me){let A=b;d++;while(d<m.length){if(m.charCodeAt(d)===Ye){d+=2;continue}if(m.charCodeAt(d)===A){d++;break}d++}continue}if(b===z||b===we||b===se)P++;else if(b===Q||b===Re||b===Ae){if(P===0)break;P--}else if(b===lt&&P===0)break;d++}continue}if(g===1&&T===mt&&d+2<m.length&&m.charCodeAt(d+1)===mt&&m.charCodeAt(d+2)===mt){d+=3;continue}h+=m[d],d++}return h}function To(m){let h=m.trim(),d=h.startsWith("...");if(d)h=h.slice(3).trim();while(h.startsWith("@")){let F=1;while(F<h.length&&Ze(h.charCodeAt(F)))F++;if(F<h.length&&h.charCodeAt(F)===se){let B=1;F++;while(F<h.length&&B>0){if(h.charCodeAt(F)===se)B++;else if(h.charCodeAt(F)===Ae)B--;F++}}h=h.slice(F).trim()}let g=!0;while(g){g=!1;for(let F of go)if(h.startsWith(F)&&h.length>F.length&&!Ze(h.charCodeAt(F.length))){let B=h.slice(F.length).trim();if(B.charCodeAt(0)===at||B.charCodeAt(0)===Fr&&B.length>1&&B.charCodeAt(1)===at)break;h=B,g=!0;break}}let C=-1,v=-1,T=0,P=!1,b=0;for(let F=0;F<h.length;F++){let B=h.charCodeAt(F);if(P){if(B===Ye){F++;continue}if(B===b)P=!1;continue}if(B===X&&F+1<h.length){let V=h.charCodeAt(F+1);if(V===Ee){F+=2;while(F+1<h.length&&!(h.charCodeAt(F)===Ee&&h.charCodeAt(F+1)===X))F++;F++;continue}if(V===X){while(F<h.length&&h.charCodeAt(F)!==10)F++;continue}}if(B===le||B===ue||B===Me){P=!0,b=B;continue}if(B===se||B===z||B===we||B===ve)T++;else if(B===Ae||B===Q||B===Re||B===fe&&!(F>0&&h.charCodeAt(F-1)===Se))T--;else if(T===0){if(B===at&&C===-1)C=F;else if(B===Se&&v===-1&&(F===0||h.charCodeAt(F-1)!==Se)&&(F+1>=h.length||h.charCodeAt(F+1)!==Se&&h.charCodeAt(F+1)!==fe))v=F}}let A,O,N=v!==-1;if(C!==-1&&(v===-1||C<v))if(A=h.slice(0,C).trim(),v!==-1)O=h.slice(C+1,v).trim();else O=h.slice(C+1).trim();else if(v!==-1)A=h.slice(0,v).trim(),O=Vr(h.slice(v+1).trim());else A=h,O="unknown";if(A=gc(A),(A.startsWith("{")||A.startsWith("["))&&A.includes(`
151
+ `))h=h.slice(0,-1);d++;let P=0;while(d<m.length){let b=m.charCodeAt(d);if(b===le||b===ue||b===Me){let A=b;d++;while(d<m.length){if(m.charCodeAt(d)===Ye){d+=2;continue}if(m.charCodeAt(d)===A){d++;break}d++}continue}if(b===z||b===we||b===se)P++;else if(b===Q||b===Re||b===Ae){if(P===0)break;P--}else if(b===ct&&P===0)break;d++}continue}if(g===1&&T===mt&&d+2<m.length&&m.charCodeAt(d+1)===mt&&m.charCodeAt(d+2)===mt){d+=3;continue}h+=m[d],d++}return h}function To(m){let h=m.trim(),d=h.startsWith("...");if(d)h=h.slice(3).trim();while(h.startsWith("@")){let F=1;while(F<h.length&&Ze(h.charCodeAt(F)))F++;if(F<h.length&&h.charCodeAt(F)===se){let B=1;F++;while(F<h.length&&B>0){if(h.charCodeAt(F)===se)B++;else if(h.charCodeAt(F)===Ae)B--;F++}}h=h.slice(F).trim()}let g=!0;while(g){g=!1;for(let F of go)if(h.startsWith(F)&&h.length>F.length&&!Ze(h.charCodeAt(F.length))){let B=h.slice(F.length).trim();if(B.charCodeAt(0)===lt||B.charCodeAt(0)===Fr&&B.length>1&&B.charCodeAt(1)===lt)break;h=B,g=!0;break}}let C=-1,v=-1,T=0,P=!1,b=0;for(let F=0;F<h.length;F++){let B=h.charCodeAt(F);if(P){if(B===Ye){F++;continue}if(B===b)P=!1;continue}if(B===X&&F+1<h.length){let V=h.charCodeAt(F+1);if(V===Ee){F+=2;while(F+1<h.length&&!(h.charCodeAt(F)===Ee&&h.charCodeAt(F+1)===X))F++;F++;continue}if(V===X){while(F<h.length&&h.charCodeAt(F)!==10)F++;continue}}if(B===le||B===ue||B===Me){P=!0,b=B;continue}if(B===se||B===z||B===we||B===ve)T++;else if(B===Ae||B===Q||B===Re||B===fe&&!(F>0&&h.charCodeAt(F-1)===Se))T--;else if(T===0){if(B===lt&&C===-1)C=F;else if(B===Se&&v===-1&&(F===0||h.charCodeAt(F-1)!==Se)&&(F+1>=h.length||h.charCodeAt(F+1)!==Se&&h.charCodeAt(F+1)!==fe))v=F}}let A,O,N=v!==-1;if(C!==-1&&(v===-1||C<v))if(A=h.slice(0,C).trim(),v!==-1)O=h.slice(C+1,v).trim();else O=h.slice(C+1).trim();else if(v!==-1)A=h.slice(0,v).trim(),O=Vr(h.slice(v+1).trim());else A=h,O="unknown";if(A=gc(A),(A.startsWith("{")||A.startsWith("["))&&A.includes(`
152
152
  `)){let F=A.replace(/\s*\n\s*/g," ").replace(/\s+/g," ");if(F.length<=40)A=F;else A=A.split(`
153
153
  `).map((B)=>{let V=B.trim();if(!V)return"";if(V==="{"||V==="}"||V==="["||V==="]"||V.startsWith("}")||V.startsWith("]"))return V;return` ${V}`}).join(`
154
154
  `)}let j=A.endsWith("?")||N;if(A.endsWith("?"))A=A.slice(0,-1).trim();let L=j&&!d?"?":"";if(d)return`...${A}: ${O}`;return`${A}${L}: ${O}`}function Ro(m){let h=0;if(h<m.length&&m.charCodeAt(h)===45)h++;if(h>=m.length)return!1;let d=m.charCodeAt(h);if(d<48||d>57)return!1;while(h<m.length&&m.charCodeAt(h)>=48&&m.charCodeAt(h)<=57)h++;if(h<m.length&&m.charCodeAt(h)===46){if(h++,h>=m.length||m.charCodeAt(h)<48||m.charCodeAt(h)>57)return!1;while(h<m.length&&m.charCodeAt(h)>=48&&m.charCodeAt(h)<=57)h++}return h===m.length}function Vr(m){let h=m.trim();if(h==="true"||h==="false")return"boolean";if(Ro(h))return"number";if(h.startsWith("'")&&h.endsWith("'")||h.startsWith('"')&&h.endsWith('"'))return"string";if(h.startsWith("["))return"unknown[]";if(h.startsWith("{"))return"Record<string, unknown>";return"unknown"}function Ur(m){let h=m.trim();if(h.endsWith("as const"))h=h.slice(0,-8).trim();if(h==="true"||h==="false")return h;if(Ro(h))return h;let d=yc(h);if(d!==null)return d;return"unknown"}function yc(m){if(m==="")return null;if(m.charCodeAt(0)===le||m.charCodeAt(0)===ue){if(Lr(m,0,m.charCodeAt(0))===m.length)return m}let h=Cc(m,"+");if(h.length>1){let d=!1,g=!0,C=[];for(let v of h){let T=v.trim(),P=T.charCodeAt(0);if((P===le||P===ue)&&Lr(T,0,P)===T.length)d=!0,C.push(wc(T));else g=!1}if(g)return vc(C.join(""));if(d)return"string";return null}if(/^[\d\s()+*/%.\-]+$/.test(m)&&/\d/.test(m)&&/[+*/%\-\s]/.test(m))return"number";return null}function Cc(m,h){let d=[],g=0,C="",v=0;while(v<m.length){let T=m.charCodeAt(v);if(T===le||T===ue||T===Me){let P=Lr(m,v,T);C+=m.slice(v,P),v=P;continue}if(T===X&&(m.charCodeAt(v+1)===X||m.charCodeAt(v+1)===42)){if(m.charCodeAt(v+1)===X){let A=m.indexOf(`
155
155
  `,v+2),O=A===-1?m.length:A;C+=m.slice(v,O),v=O;continue}let P=m.indexOf("*/",v+2),b=P===-1?m.length:P+2;C+=m.slice(v,b),v=b;continue}if(T===se||T===we||T===z)g++;else if(T===Ae||T===Re||T===Q)g--;if(m[v]===h&&g===0){d.push(C),C="",v++;continue}C+=m[v],v++}return d.push(C),d}function wc(m){return m.slice(1,-1).replace(/\\(.)/g,(h,d)=>{if(d==="n")return`
156
- `;if(d==="t")return"\t";if(d==="r")return"\r";if(d==="0")return"\x00";return d})}function vc(m){return`'${m.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}'`}function Ii(m){if(m.endsWith("as const"))return null;let h=0,d=-1;for(let g=0;g<m.length;g++){let C=m.charCodeAt(g);if(C===le||C===ue||C===Me)g=Lr(m,g,C)-1;else if(C===123||C===91||C===40)h++;else if(C===125||C===93||C===41)h--;else if(h===0&&C===32&&g+4<=m.length&&m.substring(g,g+4)===" as ")d=g}if(d===-1)return null;return m.slice(d+4).trim()||null}function fi(){if(p(),l<a&&r.charCodeAt(l)===at){l++,p();let m=l,h=0;while(l<a){if(E())continue;let d=r.charCodeAt(l);if(d===se||d===we||d===ve)h++;else if(d===Ae||d===Re||d===fe&&!U())h--;else if(d===z)if(h>0)h++;else{let g=y(m,l),C=(v)=>{let T=g.length-v.length;return T>=0&&g.endsWith(v)&&(T===0||!Ze(g.charCodeAt(T-1)))};if(g.length===0||g.endsWith("|")||g.endsWith("&")||C("is")||C("extends"))h++;else break}else if(d===Q){if(h===0)break;h--}else if(h===0&&d===ie)break;if(h===0&&te())break;l++}return y(m,l)}return""}function At(m,h,d,g){l+=8,p();let C=l<a&&r.charCodeAt(l)===Ee;if(C)l++,p();let v=W();if(!v&&!g)return null;p();let T=ht();p();let P=$t();p();let b=fi(),A=b.length>0;if(!b)if(d&&C)b="AsyncGenerator<unknown, void, unknown>";else if(C)b="Generator<unknown, void, unknown>";else if(d)b="Promise<void>";else b="void";p();let O=!1;if(l<a&&r.charCodeAt(l)===z){O=!0;let F=l+1;if(_(z,Q),!A&&!C)b=li(r.slice(F,l-1),d,P)}else if(l<a&&r.charCodeAt(l)===ie)l++;let N=Gt(P),j=`${h?g?"export default function ":"export declare function ":"declare function "}${v||(g?"":"default")}${T}${N}: ${b};`,L=Qe(m);if(O)u.add(c.length);return{kind:"function",name:v||"default",text:j,isExported:h,isDefault:g,isAsync:d,isGenerator:C,returnType:b,generics:T||void 0,leadingComments:L,start:m,end:l}}function Mt(m,h,d){l+=h.length,p();let g=[];do{if(p(),l>=a)break;let C=r.charCodeAt(l);if(C===z||C===we)return q(),g;let v=W();if(!v)return q(),g;p();let T,P,b=!1;if(l<a&&r.charCodeAt(l)===at){l++,p();let N=l,j=0;while(l<a){if(E())continue;let L=r.charCodeAt(l);if(L===se||L===z||L===we||L===ve)j++;else if(L===Ae||L===Q||L===Re||L===fe&&!U())j--;else if(j===0&&(L===ie||L===lt))break;else if(j===0&&L===Se&&!ee())break;if(j===0&&(ne()||me()))break;l++}T=y(N,l)}if(l<a&&r.charCodeAt(l)===Se)if(s&&T&&(!o||!id(T)))Te();else{l++,p();let N=l,j=0,L=0,F=0,B=!0;for(;;){l=N,j=0,L=0,F=0;while(l<a){if(E())continue;let V=r.charCodeAt(l);if(V===se||V===z||V===we)j++;else if(V===Ae||V===Q||V===Re)j--;else if(V===ve&&j===0){let Ke=Po(l);if(Ke!==null)F=Math.max(0,F+Ke);else if(B&&(l+1>=a||r.charCodeAt(l+1)!==Se))L++}else if(V===fe&&j===0&&F===0&&!U()){if(L>0&&(l+1>=a||r.charCodeAt(l+1)!==Se))L--}else if(j===0&&L===0&&F===0&&(V===ie||V===lt))break;if(j===0&&L===0&&F===0&&(ne()||K()))break;l++}if(L>0&&B){B=!1;continue}break}if(P=y(N,l),P.endsWith(" as const")||P==="const"){if(b=!0,!T){let V=P.endsWith(" as const")?P.slice(0,-9).trim():P,Ke=Ur(V);T=Ke!=="unknown"?Ke:void 0}}else if(!T){let V=Ii(P);if(V)T=V}}if(l<a){let N=r.charCodeAt(l);if(N===lt){l++;continue}if(N===ie)l++}let A=Qe(m),O=`${d?"export ":""}declare ${h} ${v}: ${T||"unknown"};`;g.push({kind:"variable",name:v,text:O,isExported:d,typeAnnotation:T,value:P,modifiers:b?[h,"const assertion"]:[h],leadingComments:A,start:m,end:l});break}while(l<a);return g}function Po(m){if(r.charCodeAt(m)!==ve||m+1>=a)return null;let h=r.charCodeAt(m+1);if(h===fe)return 1;if(h===X)return-1;if(!Wt(h))return null;let d=m+2;while(d<a){let A=r.charCodeAt(d);if(!Ze(A)&&A!==mt&&A!==58&&A!==45)break;d++}let g=r.slice(m+1,d),C=r.charCodeAt(d);if(C>32&&C!==fe&&C!==X)return null;let v=0,T=0,P=d;for(;P<a;P++){let A=r.charCodeAt(P);if(T!==0){if(A===Ye)P++;else if(A===T)T=0;continue}if(A===le||A===ue||A===Me)T=A;else if(A===z)v++;else if(A===Q&&v>0)v--;else if(A===fe&&v===0)break}if(P>=a)return null;let b=P-1;while(b>m&&r.charCodeAt(b)<=32)b--;if(r.charCodeAt(b)===X)return 0;return r.indexOf(`</${g}`,P+1)===-1?null:1}function Kr(m,h){l+=9,p();let d=W();p();let g=ht();p();let C="";if(R("extends")){l+=7,p();let A=l,O=0;while(l<a){if(E())continue;let N=r.charCodeAt(l);if(N===ve)O++;else if(N===fe&&!U())O--;else if(N===z&&O===0)break;l++}C=y(A,l)}p();let v=l<a&&r.charCodeAt(l)===z?_r():"{}",T=xo(v),P=`${h?"export ":""}declare interface ${d}${g}${C?` extends ${C}`:""} ${T}`,b=Qe(m);return{kind:"interface",name:d,text:P,isExported:h,extends:C||void 0,generics:g||void 0,leadingComments:b,start:m,end:l}}function zr(m,h){l+=4,p();let d=W();p();let g=ht();if(p(),l<a&&r.charCodeAt(l)===Se)l++;p();let C=l,v=0;while(l<a){if(E())continue;let A=r.charCodeAt(l);if(A===se||A===z||A===we||A===ve)v++;else if(A===Ae||A===Q||A===Re||A===fe&&!U())v--;else if(v===0&&A===ie)break;if(v===0&&(ne()||me()))break;l++}let T=y(C,l);if(l<a&&r.charCodeAt(l)===ie)l++;let P=`${h?"export ":""}type ${d}${g} = ${T}`,b=Qe(m);return{kind:"type",name:d,text:P,isExported:h,generics:g||void 0,leadingComments:b,start:m,end:l}}function jt(m,h,d){l+=4,p();let g=W();p();let C=l;if(l<a&&r.charCodeAt(l)===z)_(z,Q);let v=y(m,l),T=Qe(m);return{kind:"enum",name:g,text:v,isExported:h,modifiers:d?["const"]:void 0,leadingComments:T,start:m,end:l}}function xt(m,h,d,g=!1){l+=5,p();let C=W()||"AnonymousClass";p();let v=ht();p();let T="";if(R("extends")){l+=7,p();let N=l,j=0;while(l<a){if(E())continue;let L=r.charCodeAt(l);if(L===ve)j++;else if(L===fe&&!U())j--;else if(j===0&&(L===z||R("implements")))break;l++}T=y(N,l)}let P;if(R("implements")){l+=10,p();let N=l,j=0;while(l<a){if(E())continue;let F=r.charCodeAt(l);if(F===ve)j++;else if(F===fe&&!U())j--;else if(j===0&&F===z)break;l++}let L=y(N,l);if(L)P=L.split(",").map((F)=>F.trim())}p();let b=Hr(),A=`${h?g?"export default ":"export declare ":"declare "}${d?"abstract ":""}class ${C}${v}${T?` extends ${T}`:""}${P&&P.length>0?` implements ${P.join(", ")}`:""} ${b}`,O=Qe(m);return{kind:"class",name:C,text:A,isExported:h,isDefault:g,extends:T||void 0,implements:P,generics:v||void 0,modifiers:d?["abstract"]:void 0,leadingComments:O,start:m,end:l}}function Hr(){if(l>=a||r.charCodeAt(l)!==z)return"{}";l++;let m=[];while(l<a){if(p(),l>=a)break;if(r.charCodeAt(l)===Q){l++;break}if(r.charCodeAt(l)===ie){l++;continue}if(R("static")&&Oo("static")===z){l+=6,p(),_(z,Q);continue}let h=!1,d=!1,g=!1,C=!1,v=!1,T=!1,P=!1,b=!1,A=!0;while(A){if(p(),R("private")){h=!0,l+=7;continue}if(R("protected")){d=!0,l+=9;continue}if(R("public")){l+=6;continue}if(R("static")){g=!0,l+=6;continue}if(R("abstract")){C=!0,l+=8;continue}if(R("readonly")){v=!0,l+=8;continue}if(R("override")){T=!0,l+=8;continue}if(R("accessor")){P=!0,l+=8;continue}if(R("async")){b=!0,l+=5;continue}if(R("declare")){l+=7;continue}break}if(p(),l>=a||r.charCodeAt(l)===Q)break;if(r.charCodeAt(l)===Nr)h=!0;if(h){qr();continue}let O=" ";if(d)O+="protected ";if(g)O+="static ";if(C)O+="abstract ";if(v)O+="readonly ";if(R("constructor")){l+=11,p();let N=$t();if(p(),bc(N,m),l<a&&r.charCodeAt(l)===z)_(z,Q);else if(l<a&&r.charCodeAt(l)===ie)l++;let j=Gt(N);m.push(` constructor${j};`)}else if(R("get"))if(l+=3,p(),l<a&&(Wt(r.charCodeAt(l))||r.charCodeAt(l)===we||r.charCodeAt(l)===Nr)){let N=Jr();if(N.startsWith("#")){if(p(),l<a&&r.charCodeAt(l)===se)$t();if(p(),fi(),p(),l<a&&r.charCodeAt(l)===z)_(z,Q);else if(l<a&&r.charCodeAt(l)===ie)l++;continue}p(),$t(),p();let j=fi()||"unknown";if(p(),l<a&&r.charCodeAt(l)===z)_(z,Q);else if(l<a&&r.charCodeAt(l)===ie)l++;m.push(`${O}get ${N}(): ${j};`)}else ko("get",O,g,v,b,m);else if(R("set"))if(l+=3,p(),l<a&&(Wt(r.charCodeAt(l))||r.charCodeAt(l)===we||r.charCodeAt(l)===Nr)){let N=Jr();if(N.startsWith("#")){if(p(),l<a&&r.charCodeAt(l)===se)$t();if(p(),l<a&&r.charCodeAt(l)===z)_(z,Q);else if(l<a&&r.charCodeAt(l)===ie)l++;continue}p();let j=$t();if(p(),l<a&&r.charCodeAt(l)===z)_(z,Q);else if(l<a&&r.charCodeAt(l)===ie)l++;let L=Gt(j);m.push(`${O}set ${N}${L};`)}else ko("set",O,g,v,b,m);else{let N=r.charCodeAt(l)===Ee;if(N)l++,p();let j=Jr();if(!j){qr();continue}Mo(j,O,g,v,N,C,b,m)}}return`{
156
+ `;if(d==="t")return"\t";if(d==="r")return"\r";if(d==="0")return"\x00";return d})}function vc(m){return`'${m.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}'`}function Ii(m){if(m.endsWith("as const"))return null;let h=0,d=-1;for(let g=0;g<m.length;g++){let C=m.charCodeAt(g);if(C===le||C===ue||C===Me)g=Lr(m,g,C)-1;else if(C===123||C===91||C===40)h++;else if(C===125||C===93||C===41)h--;else if(h===0&&C===32&&g+4<=m.length&&m.substring(g,g+4)===" as ")d=g}if(d===-1)return null;return m.slice(d+4).trim()||null}function fi(){if(p(),l<a&&r.charCodeAt(l)===lt){l++,p();let m=l,h=0;while(l<a){if(E())continue;let d=r.charCodeAt(l);if(d===se||d===we||d===ve)h++;else if(d===Ae||d===Re||d===fe&&!U())h--;else if(d===z)if(h>0)h++;else{let g=y(m,l),C=(v)=>{let T=g.length-v.length;return T>=0&&g.endsWith(v)&&(T===0||!Ze(g.charCodeAt(T-1)))};if(g.length===0||g.endsWith("|")||g.endsWith("&")||C("is")||C("extends"))h++;else break}else if(d===Q){if(h===0)break;h--}else if(h===0&&d===ie)break;if(h===0&&te())break;l++}return y(m,l)}return""}function At(m,h,d,g){l+=8,p();let C=l<a&&r.charCodeAt(l)===Ee;if(C)l++,p();let v=W();if(!v&&!g)return null;p();let T=ht();p();let P=$t();p();let b=fi(),A=b.length>0;if(!b)if(d&&C)b="AsyncGenerator<unknown, void, unknown>";else if(C)b="Generator<unknown, void, unknown>";else if(d)b="Promise<void>";else b="void";p();let O=!1;if(l<a&&r.charCodeAt(l)===z){O=!0;let F=l+1;if(_(z,Q),!A&&!C)b=li(r.slice(F,l-1),d,P)}else if(l<a&&r.charCodeAt(l)===ie)l++;let N=Gt(P),j=`${h?g?"export default function ":"export declare function ":"declare function "}${v||(g?"":"default")}${T}${N}: ${b};`,L=Qe(m);if(O)u.add(c.length);return{kind:"function",name:v||"default",text:j,isExported:h,isDefault:g,isAsync:d,isGenerator:C,returnType:b,generics:T||void 0,leadingComments:L,start:m,end:l}}function Mt(m,h,d){l+=h.length,p();let g=[];do{if(p(),l>=a)break;let C=r.charCodeAt(l);if(C===z||C===we)return q(),g;let v=W();if(!v)return q(),g;p();let T,P,b=!1;if(l<a&&r.charCodeAt(l)===lt){l++,p();let N=l,j=0;while(l<a){if(E())continue;let L=r.charCodeAt(l);if(L===se||L===z||L===we||L===ve)j++;else if(L===Ae||L===Q||L===Re||L===fe&&!U())j--;else if(j===0&&(L===ie||L===ct))break;else if(j===0&&L===Se&&!ee())break;if(j===0&&(ne()||me()))break;l++}T=y(N,l)}if(l<a&&r.charCodeAt(l)===Se)if(s&&T&&(!o||!id(T)))Te();else{l++,p();let N=l,j=0,L=0,F=0,B=!0;for(;;){l=N,j=0,L=0,F=0;while(l<a){if(E())continue;let V=r.charCodeAt(l);if(V===se||V===z||V===we)j++;else if(V===Ae||V===Q||V===Re)j--;else if(V===ve&&j===0){let Ke=Po(l);if(Ke!==null)F=Math.max(0,F+Ke);else if(B&&(l+1>=a||r.charCodeAt(l+1)!==Se))L++}else if(V===fe&&j===0&&F===0&&!U()){if(L>0&&(l+1>=a||r.charCodeAt(l+1)!==Se))L--}else if(j===0&&L===0&&F===0&&(V===ie||V===ct))break;if(j===0&&L===0&&F===0&&(ne()||K()))break;l++}if(L>0&&B){B=!1;continue}break}if(P=y(N,l),P.endsWith(" as const")||P==="const"){if(b=!0,!T){let V=P.endsWith(" as const")?P.slice(0,-9).trim():P,Ke=Ur(V);T=Ke!=="unknown"?Ke:void 0}}else if(!T){let V=Ii(P);if(V)T=V}}if(l<a){let N=r.charCodeAt(l);if(N===ct){l++;continue}if(N===ie)l++}let A=Qe(m),O=`${d?"export ":""}declare ${h} ${v}: ${T||"unknown"};`;g.push({kind:"variable",name:v,text:O,isExported:d,typeAnnotation:T,value:P,modifiers:b?[h,"const assertion"]:[h],leadingComments:A,start:m,end:l});break}while(l<a);return g}function Po(m){if(r.charCodeAt(m)!==ve||m+1>=a)return null;let h=r.charCodeAt(m+1);if(h===fe)return 1;if(h===X)return-1;if(!Wt(h))return null;let d=m+2;while(d<a){let A=r.charCodeAt(d);if(!Ze(A)&&A!==mt&&A!==58&&A!==45)break;d++}let g=r.slice(m+1,d),C=r.charCodeAt(d);if(C>32&&C!==fe&&C!==X)return null;let v=0,T=0,P=d;for(;P<a;P++){let A=r.charCodeAt(P);if(T!==0){if(A===Ye)P++;else if(A===T)T=0;continue}if(A===le||A===ue||A===Me)T=A;else if(A===z)v++;else if(A===Q&&v>0)v--;else if(A===fe&&v===0)break}if(P>=a)return null;let b=P-1;while(b>m&&r.charCodeAt(b)<=32)b--;if(r.charCodeAt(b)===X)return 0;return r.indexOf(`</${g}`,P+1)===-1?null:1}function Kr(m,h){l+=9,p();let d=W();p();let g=ht();p();let C="";if(R("extends")){l+=7,p();let A=l,O=0;while(l<a){if(E())continue;let N=r.charCodeAt(l);if(N===ve)O++;else if(N===fe&&!U())O--;else if(N===z&&O===0)break;l++}C=y(A,l)}p();let v=l<a&&r.charCodeAt(l)===z?_r():"{}",T=xo(v),P=`${h?"export ":""}declare interface ${d}${g}${C?` extends ${C}`:""} ${T}`,b=Qe(m);return{kind:"interface",name:d,text:P,isExported:h,extends:C||void 0,generics:g||void 0,leadingComments:b,start:m,end:l}}function zr(m,h){l+=4,p();let d=W();p();let g=ht();if(p(),l<a&&r.charCodeAt(l)===Se)l++;p();let C=l,v=0;while(l<a){if(E())continue;let A=r.charCodeAt(l);if(A===se||A===z||A===we||A===ve)v++;else if(A===Ae||A===Q||A===Re||A===fe&&!U())v--;else if(v===0&&A===ie)break;if(v===0&&(ne()||me()))break;l++}let T=y(C,l);if(l<a&&r.charCodeAt(l)===ie)l++;let P=`${h?"export ":""}type ${d}${g} = ${T}`,b=Qe(m);return{kind:"type",name:d,text:P,isExported:h,generics:g||void 0,leadingComments:b,start:m,end:l}}function jt(m,h,d){l+=4,p();let g=W();p();let C=l;if(l<a&&r.charCodeAt(l)===z)_(z,Q);let v=y(m,l),T=Qe(m);return{kind:"enum",name:g,text:v,isExported:h,modifiers:d?["const"]:void 0,leadingComments:T,start:m,end:l}}function xt(m,h,d,g=!1){l+=5,p();let C=W()||"AnonymousClass";p();let v=ht();p();let T="";if(R("extends")){l+=7,p();let N=l,j=0;while(l<a){if(E())continue;let L=r.charCodeAt(l);if(L===ve)j++;else if(L===fe&&!U())j--;else if(j===0&&(L===z||R("implements")))break;l++}T=y(N,l)}let P;if(R("implements")){l+=10,p();let N=l,j=0;while(l<a){if(E())continue;let F=r.charCodeAt(l);if(F===ve)j++;else if(F===fe&&!U())j--;else if(j===0&&F===z)break;l++}let L=y(N,l);if(L)P=L.split(",").map((F)=>F.trim())}p();let b=Hr(),A=`${h?g?"export default ":"export declare ":"declare "}${d?"abstract ":""}class ${C}${v}${T?` extends ${T}`:""}${P&&P.length>0?` implements ${P.join(", ")}`:""} ${b}`,O=Qe(m);return{kind:"class",name:C,text:A,isExported:h,isDefault:g,extends:T||void 0,implements:P,generics:v||void 0,modifiers:d?["abstract"]:void 0,leadingComments:O,start:m,end:l}}function Hr(){if(l>=a||r.charCodeAt(l)!==z)return"{}";l++;let m=[];while(l<a){if(p(),l>=a)break;if(r.charCodeAt(l)===Q){l++;break}if(r.charCodeAt(l)===ie){l++;continue}if(R("static")&&Oo("static")===z){l+=6,p(),_(z,Q);continue}let h=!1,d=!1,g=!1,C=!1,v=!1,T=!1,P=!1,b=!1,A=!0;while(A){if(p(),R("private")){h=!0,l+=7;continue}if(R("protected")){d=!0,l+=9;continue}if(R("public")){l+=6;continue}if(R("static")){g=!0,l+=6;continue}if(R("abstract")){C=!0,l+=8;continue}if(R("readonly")){v=!0,l+=8;continue}if(R("override")){T=!0,l+=8;continue}if(R("accessor")){P=!0,l+=8;continue}if(R("async")){b=!0,l+=5;continue}if(R("declare")){l+=7;continue}break}if(p(),l>=a||r.charCodeAt(l)===Q)break;if(r.charCodeAt(l)===Nr)h=!0;if(h){qr();continue}let O=" ";if(d)O+="protected ";if(g)O+="static ";if(C)O+="abstract ";if(v)O+="readonly ";if(R("constructor")){l+=11,p();let N=$t();if(p(),bc(N,m),l<a&&r.charCodeAt(l)===z)_(z,Q);else if(l<a&&r.charCodeAt(l)===ie)l++;let j=Gt(N);m.push(` constructor${j};`)}else if(R("get"))if(l+=3,p(),l<a&&(Wt(r.charCodeAt(l))||r.charCodeAt(l)===we||r.charCodeAt(l)===Nr)){let N=Jr();if(N.startsWith("#")){if(p(),l<a&&r.charCodeAt(l)===se)$t();if(p(),fi(),p(),l<a&&r.charCodeAt(l)===z)_(z,Q);else if(l<a&&r.charCodeAt(l)===ie)l++;continue}p(),$t(),p();let j=fi()||"unknown";if(p(),l<a&&r.charCodeAt(l)===z)_(z,Q);else if(l<a&&r.charCodeAt(l)===ie)l++;m.push(`${O}get ${N}(): ${j};`)}else ko("get",O,g,v,b,m);else if(R("set"))if(l+=3,p(),l<a&&(Wt(r.charCodeAt(l))||r.charCodeAt(l)===we||r.charCodeAt(l)===Nr)){let N=Jr();if(N.startsWith("#")){if(p(),l<a&&r.charCodeAt(l)===se)$t();if(p(),l<a&&r.charCodeAt(l)===z)_(z,Q);else if(l<a&&r.charCodeAt(l)===ie)l++;continue}p();let j=$t();if(p(),l<a&&r.charCodeAt(l)===z)_(z,Q);else if(l<a&&r.charCodeAt(l)===ie)l++;let L=Gt(j);m.push(`${O}set ${N}${L};`)}else ko("set",O,g,v,b,m);else{let N=r.charCodeAt(l)===Ee;if(N)l++,p();let j=Jr();if(!j){qr();continue}Mo(j,O,g,v,N,C,b,m)}}return`{
157
157
  ${m.join(`
158
158
  `)}
159
- }`}function Jr(){if(l>=a)return"";let m=r.charCodeAt(l);if(m===we){let h=l;return _(we,Re),r.slice(h,l)}if(m===Nr)return l++,`#${W()}`;return W()}function Oo(m){let h=l+m.length;while(h<a&&Be(r.charCodeAt(h)))h++;return h<a?r.charCodeAt(h):0}function qr(){let m=0;while(l<a){if(E())continue;let h=r.charCodeAt(l);if(h===z||h===se)m++;else if(h===Q||h===Ae){if(m===0)return;m--}else if(h===ie&&m===0){l++;return}if(m===0&&te())return;l++}}function ko(m,h,d,g,C,v){Mo(m,h,d,g,!1,!1,C,v)}function Mo(m,h,d,g,C,v,T,P){if(p(),l>=a)return;let b=r.charCodeAt(l),A=!1;if(b===Fr)A=!0,l++,p();if(l<a&&r.charCodeAt(l)===33)l++,p();let O=l<a?r.charCodeAt(l):0;if(O===se||O===ve){let N=O===ve?ht():"";p();let j=$t();p();let L=fi(),F=L.length>0;if(!L)if(T&&C)L="AsyncGenerator<unknown, void, unknown>";else if(C)L="Generator<unknown, void, unknown>";else if(T)L="Promise<void>";else L="void";if(p(),l<a&&r.charCodeAt(l)===z){let Ke=l+1;if(_(z,Q),!F&&!C)L=li(r.slice(Ke,l-1),T,j)}else if(l<a&&r.charCodeAt(l)===ie)l++;let B=Gt(j),V=A?"?":"";P.push(`${h}${m}${V}${N}${B}: ${L};`)}else if(O===at||O===Se||O===ie||O===Q||O===he||O===be){let N="";if(O===at){l++,p();let F=l,B=0;while(l<a){if(E())continue;let V=r.charCodeAt(l);if(V===se||V===z||V===we||V===ve)B++;else if(V===Ae||V===Q||V===Re||V===fe&&!U()){if(B===0)break;B--}else if(B===0&&(V===ie||V===lt))break;else if(B===0&&V===Se&&!ee())break;if(B===0&&te())break;l++}N=y(F,l)}let j="";if(l<a&&r.charCodeAt(l)===Se)if(s&&N){l++;let F=0;while(l<a){if(E())continue;let B=r.charCodeAt(l);if(B===se||B===z||B===we)F++;else if(B===Ae||B===Q||B===Re){if(F===0&&B===Q)break;F--}else if(F===0&&B===ie)break;if(F===0&&te())break;l++}}else{l++,p();let F=l,B=0;while(l<a){if(E())continue;let V=r.charCodeAt(l);if(V===se||V===z||V===we)B++;else if(V===Ae||V===Q||V===Re){if(B===0&&V===Q)break;B--}else if(B===0&&V===ie)break;if(B===0&&te())break;l++}j=y(F,l)}if(l<a&&r.charCodeAt(l)===ie)l++;if(!N)if(j){let F=Ii(j);if(F)N=F;else N=j.endsWith("as const")||d&&g?Ur(j):Vr(j)}else N="unknown";let L=A?"?":"";P.push(`${h}${m}${L}: ${N};`)}else qr()}function Ec(m){let h=0;for(let d=0;d<m.length;d++){let g=m.charCodeAt(d);if(g===se||g===z||g===we||g===ve)h++;else if(g===Ae||g===Q||g===Re||g===fe&&m.charCodeAt(d-1)!==Se)h--;else if(g===Se&&h===0&&m.charCodeAt(d+1)!==fe&&m.charCodeAt(d+1)!==Se)return!0}return!1}function bc(m,h){let d=m.slice(1,-1).trim();if(!d)return;let g=[],C=0,v=0,T=!1,P=0;for(let b=0;b<=d.length;b++){if(b===d.length){g.push(Di(d.slice(C).trim()));break}let A=d.charCodeAt(b);if(T){if(A===Ye){b++;continue}if(A===P)T=!1;continue}if(A===X&&b+1<d.length){let O=d.charCodeAt(b+1);if(O===Ee){b+=2;while(b+1<d.length&&!(d.charCodeAt(b)===Ee&&d.charCodeAt(b+1)===X))b++;b++;continue}if(O===X){while(b<d.length&&d.charCodeAt(b)!==10)b++;continue}}if(A===le||A===ue||A===Me){T=!0,P=A;continue}if(A===se||A===z||A===we||A===ve)v++;else if(A===Ae||A===Q||A===Re||A===fe&&!(b>0&&d.charCodeAt(b-1)===Se))v--;else if(A===lt&&v===0)g.push(Di(d.slice(C,b).trim())),C=b+1}for(let b of g){let A=b.startsWith("public ")||b.startsWith("public\t"),O=b.startsWith("protected ")||b.startsWith("protected\t"),N=b.startsWith("private ")||b.startsWith("private\t"),j=b.includes("readonly ");if(!A&&!O&&!N&&!j)continue;if(N)continue;let L=b,F=[];if(A){let ze=6;while(ze<L.length&&Be(L.charCodeAt(ze)))ze++;L=L.slice(ze),F.push("public")}if(O){let ze=9;while(ze<L.length&&Be(L.charCodeAt(ze)))ze++;L=L.slice(ze),F.push("protected")}if(j){let ze=L.indexOf("readonly ");if(ze!==-1){let Vt=ze+8;while(Vt<L.length&&Be(L.charCodeAt(Vt)))Vt++;L=L.slice(0,ze)+L.slice(Vt)}F.push("readonly")}let B=F.length>0?`${F.join(" ")} `:"",V=To(L),Ke=L.search(/[?:=]/);if(Ke!==-1&&L.charCodeAt(Ke)!==63&&Ec(L))V=V.replace(/^([\w$]+)\?:/,"$1:");h.push(` ${B}${V};`)}}function Yr(m=" "){if(l>=a||r.charCodeAt(l)!==z)return"{}";l++;let h=[];while(l<a){if(p(),l>=a)break;if(r.charCodeAt(l)===Q){l++;break}if(r.charCodeAt(l)===ie){l++;continue}let d=!1;if(R("export"))d=!0,l+=6,p();if(R("declare"))l+=7,p();let g=d?"export ":"";if(R("function")||R("async")&&Sc("async","function")){let C=!1;if(R("async"))C=!0,l+=5,p();if(l+=8,p(),l<a&&r.charCodeAt(l)===Ee)l++,p();let v=W();p();let T=ht();p();let P=$t();p();let b=fi();if(!b)b=C?"Promise<void>":"void";if(p(),l<a&&r.charCodeAt(l)===z)_(z,Q);else if(l<a&&r.charCodeAt(l)===ie)l++;let A=Gt(P);h.push(`${m}${g}function ${v}${T}${A}: ${b};`)}else if(R("const")||R("let")||R("var")){let C=R("const")?"const":R("let")?"let":"var";l+=C.length,p();let v=W();if(!v){q(!0);continue}p();let T="";if(l<a&&r.charCodeAt(l)===at){l++,p();let b=l,A=0;while(l<a){if(E())continue;let O=r.charCodeAt(l);if(O===se||O===z||O===we||O===ve)A++;else if(O===Q&&A===0)break;else if(O===Ae||O===Q||O===Re||O===fe&&!U())A--;else if(A===0&&(O===ie||O===lt))break;else if(A===0&&O===Se&&!ee())break;if(A===0&&ne())break;l++}T=y(b,l)}let P="";if(l<a&&r.charCodeAt(l)===Se){l++,p();let b=l,A=0;while(l<a){if(E())continue;let O=r.charCodeAt(l);if(O===se||O===z||O===we||O===ve)A++;else if(O===Q&&A===0)break;else if(O===Ae||O===Q||O===Re||O===fe&&!U())A--;else if(A===0&&(O===ie||O===lt))break;if(A===0&&ne())break;l++}P=y(b,l)}if(l<a&&r.charCodeAt(l)===ie)l++;if(!T&&P){let b=Ii(P);if(b)T=b;else if(C==="const")T=Ur(P);else T=Vr(P)}if(!T)T="unknown";h.push(`${m}${g}${C} ${v}: ${T};`)}else if(R("interface")){l+=9,p();let C=W();p();let v=ht();p();let T="";if(R("extends")){l+=7,p();let b=l,A=0;while(l<a){if(E())continue;let O=r.charCodeAt(l);if(O===ve)A++;else if(O===fe&&!U())A--;else if(O===z&&A===0)break;l++}T=y(b,l)}let P=xo(_r());h.push(`${m}${g}interface ${C}${v}${T?` extends ${T}`:""} ${P}`)}else if(R("type")){l+=4,p();let C=W();p();let v=ht();if(p(),l<a&&r.charCodeAt(l)===Se){l++,p();let T=l,P=0;while(l<a){if(E())continue;let A=r.charCodeAt(l);if(A===se||A===z||A===we||A===ve)P++;else if(A===Q&&P===0)break;else if(A===Ae||A===Q||A===Re||A===fe&&!U())P--;else if(P===0&&A===ie)break;if(P===0&&ne())break;l++}let b=y(T,l);if(l<a&&r.charCodeAt(l)===ie)l++;h.push(`${m}${g}type ${C}${v} = ${b}`)}}else if(R("class")){l+=5,p();let C=W();p();let v=ht();p();let T=l,P=0;while(l<a){if(E())continue;let N=r.charCodeAt(l);if(N===ve)P++;else if(N===fe&&!U())P--;else if(N===z&&P===0)break;l++}let b=y(T,l),A=b?` ${b}`:"",O=Hr();h.push(`${m}${g}class ${C}${v}${A} ${O}`)}else if(R("enum")){l+=4,p();let C=W();p();let v=_r();h.push(`${m}${g}enum ${C} ${v}`)}else if(R("namespace")||R("module")){let C=R("namespace")?"namespace":"module";l+=C.length,p();let v=W();p();let T=Yr(m);h.push(`${m}${g}${C} ${v} ${T}`)}else if(R("abstract"))if(l+=8,p(),R("class")){l+=5,p();let C=W();p();let v=ht();p();let T=l,P=0;while(l<a){if(E())continue;let N=r.charCodeAt(l);if(N===ve)P++;else if(N===fe&&!U())P--;else if(N===z&&P===0)break;l++}let b=y(T,l),A=b?` ${b}`:"",O=Hr();h.push(`${m}${g}abstract class ${C}${v}${A} ${O}`)}else q(!0);else if(d&&R("default")){l+=7,p();let C=l;q(!0);let v=y(C,l);if(v.charCodeAt(v.length-1)===ie)v=v.slice(0,-1);if(v)h.push(`${m}export default ${v};`)}else if(!d&&(r.charCodeAt(l)===le||r.charCodeAt(l)===ue||r.charCodeAt(l)===Me))q(!0);else q(!0)}if(h.length===0)return"{}";return`{
159
+ }`}function Jr(){if(l>=a)return"";let m=r.charCodeAt(l);if(m===we){let h=l;return _(we,Re),r.slice(h,l)}if(m===Nr)return l++,`#${W()}`;return W()}function Oo(m){let h=l+m.length;while(h<a&&Be(r.charCodeAt(h)))h++;return h<a?r.charCodeAt(h):0}function qr(){let m=0;while(l<a){if(E())continue;let h=r.charCodeAt(l);if(h===z||h===se)m++;else if(h===Q||h===Ae){if(m===0)return;m--}else if(h===ie&&m===0){l++;return}if(m===0&&te())return;l++}}function ko(m,h,d,g,C,v){Mo(m,h,d,g,!1,!1,C,v)}function Mo(m,h,d,g,C,v,T,P){if(p(),l>=a)return;let b=r.charCodeAt(l),A=!1;if(b===Fr)A=!0,l++,p();if(l<a&&r.charCodeAt(l)===33)l++,p();let O=l<a?r.charCodeAt(l):0;if(O===se||O===ve){let N=O===ve?ht():"";p();let j=$t();p();let L=fi(),F=L.length>0;if(!L)if(T&&C)L="AsyncGenerator<unknown, void, unknown>";else if(C)L="Generator<unknown, void, unknown>";else if(T)L="Promise<void>";else L="void";if(p(),l<a&&r.charCodeAt(l)===z){let Ke=l+1;if(_(z,Q),!F&&!C)L=li(r.slice(Ke,l-1),T,j)}else if(l<a&&r.charCodeAt(l)===ie)l++;let B=Gt(j),V=A?"?":"";P.push(`${h}${m}${V}${N}${B}: ${L};`)}else if(O===lt||O===Se||O===ie||O===Q||O===he||O===be){let N="";if(O===lt){l++,p();let F=l,B=0;while(l<a){if(E())continue;let V=r.charCodeAt(l);if(V===se||V===z||V===we||V===ve)B++;else if(V===Ae||V===Q||V===Re||V===fe&&!U()){if(B===0)break;B--}else if(B===0&&(V===ie||V===ct))break;else if(B===0&&V===Se&&!ee())break;if(B===0&&te())break;l++}N=y(F,l)}let j="";if(l<a&&r.charCodeAt(l)===Se)if(s&&N){l++;let F=0;while(l<a){if(E())continue;let B=r.charCodeAt(l);if(B===se||B===z||B===we)F++;else if(B===Ae||B===Q||B===Re){if(F===0&&B===Q)break;F--}else if(F===0&&B===ie)break;if(F===0&&te())break;l++}}else{l++,p();let F=l,B=0;while(l<a){if(E())continue;let V=r.charCodeAt(l);if(V===se||V===z||V===we)B++;else if(V===Ae||V===Q||V===Re){if(B===0&&V===Q)break;B--}else if(B===0&&V===ie)break;if(B===0&&te())break;l++}j=y(F,l)}if(l<a&&r.charCodeAt(l)===ie)l++;if(!N)if(j){let F=Ii(j);if(F)N=F;else N=j.endsWith("as const")||d&&g?Ur(j):Vr(j)}else N="unknown";let L=A?"?":"";P.push(`${h}${m}${L}: ${N};`)}else qr()}function Ec(m){let h=0;for(let d=0;d<m.length;d++){let g=m.charCodeAt(d);if(g===se||g===z||g===we||g===ve)h++;else if(g===Ae||g===Q||g===Re||g===fe&&m.charCodeAt(d-1)!==Se)h--;else if(g===Se&&h===0&&m.charCodeAt(d+1)!==fe&&m.charCodeAt(d+1)!==Se)return!0}return!1}function bc(m,h){let d=m.slice(1,-1).trim();if(!d)return;let g=[],C=0,v=0,T=!1,P=0;for(let b=0;b<=d.length;b++){if(b===d.length){g.push(Di(d.slice(C).trim()));break}let A=d.charCodeAt(b);if(T){if(A===Ye){b++;continue}if(A===P)T=!1;continue}if(A===X&&b+1<d.length){let O=d.charCodeAt(b+1);if(O===Ee){b+=2;while(b+1<d.length&&!(d.charCodeAt(b)===Ee&&d.charCodeAt(b+1)===X))b++;b++;continue}if(O===X){while(b<d.length&&d.charCodeAt(b)!==10)b++;continue}}if(A===le||A===ue||A===Me){T=!0,P=A;continue}if(A===se||A===z||A===we||A===ve)v++;else if(A===Ae||A===Q||A===Re||A===fe&&!(b>0&&d.charCodeAt(b-1)===Se))v--;else if(A===ct&&v===0)g.push(Di(d.slice(C,b).trim())),C=b+1}for(let b of g){let A=b.startsWith("public ")||b.startsWith("public\t"),O=b.startsWith("protected ")||b.startsWith("protected\t"),N=b.startsWith("private ")||b.startsWith("private\t"),j=b.includes("readonly ");if(!A&&!O&&!N&&!j)continue;if(N)continue;let L=b,F=[];if(A){let ze=6;while(ze<L.length&&Be(L.charCodeAt(ze)))ze++;L=L.slice(ze),F.push("public")}if(O){let ze=9;while(ze<L.length&&Be(L.charCodeAt(ze)))ze++;L=L.slice(ze),F.push("protected")}if(j){let ze=L.indexOf("readonly ");if(ze!==-1){let Vt=ze+8;while(Vt<L.length&&Be(L.charCodeAt(Vt)))Vt++;L=L.slice(0,ze)+L.slice(Vt)}F.push("readonly")}let B=F.length>0?`${F.join(" ")} `:"",V=To(L),Ke=L.search(/[?:=]/);if(Ke!==-1&&L.charCodeAt(Ke)!==63&&Ec(L))V=V.replace(/^([\w$]+)\?:/,"$1:");h.push(` ${B}${V};`)}}function Yr(m=" "){if(l>=a||r.charCodeAt(l)!==z)return"{}";l++;let h=[];while(l<a){if(p(),l>=a)break;if(r.charCodeAt(l)===Q){l++;break}if(r.charCodeAt(l)===ie){l++;continue}let d=!1;if(R("export"))d=!0,l+=6,p();if(R("declare"))l+=7,p();let g=d?"export ":"";if(R("function")||R("async")&&Sc("async","function")){let C=!1;if(R("async"))C=!0,l+=5,p();if(l+=8,p(),l<a&&r.charCodeAt(l)===Ee)l++,p();let v=W();p();let T=ht();p();let P=$t();p();let b=fi();if(!b)b=C?"Promise<void>":"void";if(p(),l<a&&r.charCodeAt(l)===z)_(z,Q);else if(l<a&&r.charCodeAt(l)===ie)l++;let A=Gt(P);h.push(`${m}${g}function ${v}${T}${A}: ${b};`)}else if(R("const")||R("let")||R("var")){let C=R("const")?"const":R("let")?"let":"var";l+=C.length,p();let v=W();if(!v){q(!0);continue}p();let T="";if(l<a&&r.charCodeAt(l)===lt){l++,p();let b=l,A=0;while(l<a){if(E())continue;let O=r.charCodeAt(l);if(O===se||O===z||O===we||O===ve)A++;else if(O===Q&&A===0)break;else if(O===Ae||O===Q||O===Re||O===fe&&!U())A--;else if(A===0&&(O===ie||O===ct))break;else if(A===0&&O===Se&&!ee())break;if(A===0&&ne())break;l++}T=y(b,l)}let P="";if(l<a&&r.charCodeAt(l)===Se){l++,p();let b=l,A=0;while(l<a){if(E())continue;let O=r.charCodeAt(l);if(O===se||O===z||O===we||O===ve)A++;else if(O===Q&&A===0)break;else if(O===Ae||O===Q||O===Re||O===fe&&!U())A--;else if(A===0&&(O===ie||O===ct))break;if(A===0&&ne())break;l++}P=y(b,l)}if(l<a&&r.charCodeAt(l)===ie)l++;if(!T&&P){let b=Ii(P);if(b)T=b;else if(C==="const")T=Ur(P);else T=Vr(P)}if(!T)T="unknown";h.push(`${m}${g}${C} ${v}: ${T};`)}else if(R("interface")){l+=9,p();let C=W();p();let v=ht();p();let T="";if(R("extends")){l+=7,p();let b=l,A=0;while(l<a){if(E())continue;let O=r.charCodeAt(l);if(O===ve)A++;else if(O===fe&&!U())A--;else if(O===z&&A===0)break;l++}T=y(b,l)}let P=xo(_r());h.push(`${m}${g}interface ${C}${v}${T?` extends ${T}`:""} ${P}`)}else if(R("type")){l+=4,p();let C=W();p();let v=ht();if(p(),l<a&&r.charCodeAt(l)===Se){l++,p();let T=l,P=0;while(l<a){if(E())continue;let A=r.charCodeAt(l);if(A===se||A===z||A===we||A===ve)P++;else if(A===Q&&P===0)break;else if(A===Ae||A===Q||A===Re||A===fe&&!U())P--;else if(P===0&&A===ie)break;if(P===0&&ne())break;l++}let b=y(T,l);if(l<a&&r.charCodeAt(l)===ie)l++;h.push(`${m}${g}type ${C}${v} = ${b}`)}}else if(R("class")){l+=5,p();let C=W();p();let v=ht();p();let T=l,P=0;while(l<a){if(E())continue;let N=r.charCodeAt(l);if(N===ve)P++;else if(N===fe&&!U())P--;else if(N===z&&P===0)break;l++}let b=y(T,l),A=b?` ${b}`:"",O=Hr();h.push(`${m}${g}class ${C}${v}${A} ${O}`)}else if(R("enum")){l+=4,p();let C=W();p();let v=_r();h.push(`${m}${g}enum ${C} ${v}`)}else if(R("namespace")||R("module")){let C=R("namespace")?"namespace":"module";l+=C.length,p();let v=W();p();let T=Yr(m);h.push(`${m}${g}${C} ${v} ${T}`)}else if(R("abstract"))if(l+=8,p(),R("class")){l+=5,p();let C=W();p();let v=ht();p();let T=l,P=0;while(l<a){if(E())continue;let N=r.charCodeAt(l);if(N===ve)P++;else if(N===fe&&!U())P--;else if(N===z&&P===0)break;l++}let b=y(T,l),A=b?` ${b}`:"",O=Hr();h.push(`${m}${g}abstract class ${C}${v}${A} ${O}`)}else q(!0);else if(d&&R("default")){l+=7,p();let C=l;q(!0);let v=y(C,l);if(v.charCodeAt(v.length-1)===ie)v=v.slice(0,-1);if(v)h.push(`${m}export default ${v};`)}else if(!d&&(r.charCodeAt(l)===le||r.charCodeAt(l)===ue||r.charCodeAt(l)===Me))q(!0);else q(!0)}if(h.length===0)return"{}";return`{
160
160
  ${h.join(`
161
161
  `)}
162
- }`}function Sc(m,h){let d=l+m.length;while(d<a&&Be(r.charCodeAt(d)))d++;for(let g=0;g<h.length;g++)if(d+g>=a||r.charCodeAt(d+g)!==h.charCodeAt(g))return!1;return d+h.length>=a||!Ze(r.charCodeAt(d+h.length))}function _t(m,h,d){l+=d.length,p();let g="",C=r.charCodeAt(l);if(C===le||C===ue){let A=l;S(C),g=r.slice(A,l)}else{g=W();while(l<a&&r.charCodeAt(l)===mt)l++,g+=`.${W()}`}p();let v=l<a&&r.charCodeAt(l)===z?Yr():"{}",T=`${h?"export ":""}declare ${d} ${g} ${v}`,P=Qe(m),b=g.startsWith("'")||g.startsWith('"');return{kind:"module",name:g,text:T,isExported:h,source:b?g.slice(1,-1):void 0,leadingComments:P,start:m,end:l}}function Do(m,h){q();let d=y(h,l);if(d.charCodeAt(d.length-1)===ie)d=d.slice(0,-1).trimEnd();if(!d)return;let g=Wt(d.charCodeAt(0));for(let A=1;g&&A<d.length;A++)g=Ze(d.charCodeAt(A));let C=Qe(m);if(g){c.push({kind:"export",name:"default",text:`export default ${d};`,isExported:!0,isTypeOnly:!1,leadingComments:C,start:m,end:l});return}let v="__dtsx_default_export__",T=1;while(r.includes(v))v=`__dtsx_default_export_${T++}__`;let P=Ii(d)||Ie(d,!1),b=P==="unknown"&&td(d)?`typeof ${d}`:P;c.push({kind:"variable",name:v,text:`declare const ${v}: ${b};`,isExported:!1,typeAnnotation:b,modifiers:["const"],start:m,end:l}),c.push({kind:"export",name:"default",text:`export default ${v};`,isExported:!0,isTypeOnly:!1,leadingComments:C,start:m,end:l})}while(l<a){if(p(),l>=a)break;let m=l,h=r.charCodeAt(l);if(h===105&&R("import"))c.push(pc(m));else if(h===101&&R("export")){l+=6,p();let d=r.charCodeAt(l);if(d===100&&R("default")){l+=7,p();let g=l,C=r.charCodeAt(l);if(C===102&&R("function")){let v=At(m,!0,!1,!0);if(v)c.push(v)}else if(C===97&&R("async")&&Oo("async")!==ie)if(l+=5,p(),R("function")){let v=At(m,!0,!0,!0);if(v)c.push(v)}else Do(m,g);else if(C===99&&R("class")){let v=xt(m,!0,!1,!0);c.push(v)}else if(C===97&&R("abstract")){if(l+=8,p(),R("class")){let v=xt(m,!0,!0,!0);c.push(v)}}else Do(m,g)}else if(d===116&&R("type")){let g=l;if(l+=4,p(),l<a&&r.charCodeAt(l)===z){Fe();let C=y(m,l),v=Qe(m);c.push({kind:"export",name:"",text:C,isExported:!0,isTypeOnly:!0,source:Mi(C),leadingComments:v,start:m,end:l})}else if(l<a&&r.charCodeAt(l)===Ee){ki();let C=y(m,l);c.push({kind:"export",name:"",text:C,isExported:!0,isTypeOnly:!0,source:Mi(C),start:m,end:l})}else{l=g;let C=zr(m,!0);c.push(C)}}else if(d===105&&R("interface")){let g=Kr(m,!0);c.push(g)}else if(d===102&&R("function")){let g=At(m,!0,!1,!1);if(g)c.push(g)}else if(d===97&&R("async"))if(l+=5,p(),R("function")){let g=At(m,!0,!0,!1);if(g)c.push(g)}else q();else if(d===99)if(R("class")){let g=xt(m,!0,!1);c.push(g)}else if(R("const")){let g=l;if(l+=5,p(),R("enum")){l=g+5,p();let C=jt(m,!0,!0);c.push(C)}else{l=g;let C=Mt(m,"const",!0);for(let v=0;v<C.length;v++)c.push(C[v])}}else q();else if(d===97&&R("abstract")){if(l+=8,p(),R("class")){let g=xt(m,!0,!0);c.push(g)}}else if(d===108&&R("let")){let g=Mt(m,"let",!0);for(let C=0;C<g.length;C++)c.push(g[C])}else if(d===118&&R("var")){let g=Mt(m,"var",!0);for(let C=0;C<g.length;C++)c.push(g[C])}else if(d===101&&R("enum")){let g=jt(m,!0,!1);c.push(g)}else if(d===100&&R("declare"))l+=7,p(),Io(m,!0);else if(d===110&&R("namespace")&&D(9)){let g=_t(m,!0,"namespace");c.push(g)}else if(d===109&&R("module")&&D(6)){let g=_t(m,!0,"module");c.push(g)}else if(d===z){Fe();let g=y(m,l),C=g.includes("export type"),v=Qe(m);c.push({kind:"export",name:"",text:g,isExported:!0,isTypeOnly:C,source:Mi(g),leadingComments:v,start:m,end:l})}else if(d===Ee){ki();let g=y(m,l),C=Qe(m);c.push({kind:"export",name:"",text:g,isExported:!0,isTypeOnly:!1,source:Mi(g),leadingComments:C,start:m,end:l})}else{q();let g=y(m,l);if(g)c.push({kind:"export",name:"",text:g,isExported:!0,start:m,end:l})}}else if(h===100&&R("declare"))l+=7,p(),Io(m,!1);else if(h===105&&R("interface")){let d=Kr(m,!1);f.set(d.name,d)}else if(h===116&&R("type")){let d=zr(m,!1);f.set(d.name,d),c.push(d)}else if(h===102&&R("function")){let d=At(m,!1,!1,!1);if(d)f.set(d.name,d);else q()}else if(h===97)if(R("async")){let d=l;if(l+=5,p(),R("function")){let g=At(m,!1,!0,!1);if(g)f.set(g.name,g);else l=d,q()}else l=d,q()}else if(R("abstract"))if(l+=8,p(),R("class")){let d=xt(m,!1,!1);f.set(d.name,d),c.push(d)}else q();else l++,q();else if(h===99)if(R("class")){let d=xt(m,!1,!1);f.set(d.name,d),c.push(d)}else if(R("const")){let d=l;if(l+=5,p(),R("enum")){l=d+5,p();let g=jt(m,!1,!0);f.set(g.name,g),c.push(g)}else{l=d;let g=Mt(m,"const",!1);for(let C=0;C<g.length;C++)f.set(g[C].name,g[C])}}else l++,q();else if(h===101&&R("enum")){let d=jt(m,!1,!1);f.set(d.name,d),c.push(d)}else if(h===108&&R("let")||h===118&&R("var")){let d=R("let")?"let":"var",g=Mt(m,d,!1);for(let C=0;C<g.length;C++)f.set(g[C].name,g[C])}else if(h===109&&R("module")&&D(6)){let d=_t(m,!1,"module");c.push(d)}else if(h===110&&R("namespace")&&D(9)){let d=_t(m,!1,"namespace");c.push(d)}else{let d=r.charCodeAt(l);if(d===ie)l++;else if(d===le||d===ue){if(S(d),l<a&&r.charCodeAt(l)===ie)l++}else if(d===Me){if(x(),l<a&&r.charCodeAt(l)===ie)l++}else if(d===Qh){if(l++,W(),p(),l<a&&r.charCodeAt(l)===mt)l++,W(),p();if(l<a&&r.charCodeAt(l)===se)_(se,Ae)}else l++,q()}}if(f.size>0)rd(c,f);if(u.size>0){let m=new Map;for(let d of c)if(d.kind==="function")m.set(d.name,(m.get(d.name)||0)+1);let h=new Set;for(let[d,g]of m)if(g>1)h.add(d);if(h.size>0){let d=new Set;for(let g of h)for(let C=c.length-1;C>=0;C--)if(c[C].kind==="function"&&c[C].name===g&&u.has(C)){d.add(C);break}if(d.size>0){let g=[...d].sort((C,v)=>v-C);for(let C of g)c.splice(C,1)}}}return c;function Io(m,h){if(R("function")){let d=At(m,h,!1,!1);if(d)c.push(d)}else if(R("async")){if(l+=5,p(),R("function")){let d=At(m,h,!0,!1);if(d)c.push(d)}}else if(R("class")){let d=xt(m,h,!1);c.push(d)}else if(R("abstract")){if(l+=8,p(),R("class")){let d=xt(m,h,!0);c.push(d)}}else if(R("interface")){let d=Kr(m,h);c.push(d)}else if(R("type")){let d=zr(m,h);c.push(d)}else if(R("enum")){let d=jt(m,h,!1);c.push(d)}else if(R("const")){let d=l;if(l+=5,p(),R("enum")){l=d+5,p();let g=jt(m,h,!0);c.push(g)}else if(h){l=d;let g=Mt(m,"const",!0);for(let C=0;C<g.length;C++)c.push(g[C])}else q()}else if(R("let")||R("var"))if(h){let d=R("let")?"let":"var",g=Mt(m,d,!0);for(let C=0;C<g.length;C++)c.push(g[C])}else q();else if(R("module")){let d=_t(m,h,"module");c.push(d)}else if(R("namespace")){let d=_t(m,h,"namespace");c.push(d)}else if(R("global")){l+=6,p();let d=`declare global ${l<a&&r.charCodeAt(l)===z?Yr():"{}"}`,g=Qe(m);c.push({kind:"module",name:"global",text:d,isExported:!1,leadingComments:g,start:m,end:l})}else q()}}function rl(e,t){let i=0,n=e.length;while(i<n){let r=e.charCodeAt(i);if(r>=65&&r<=90||r>=97&&r<=122||r===95||r===36||r>127){let o=i;i++;while(i<n){let s=e.charCodeAt(i);if(s>=65&&s<=90||s>=97&&s<=122||s>=48&&s<=57||s===95||s===36||s>127)i++;else break}t.add(e.substring(o,i))}else i++}}function nl(e,t){let i=0;while(i<e.length){let n=e.charCodeAt(i);if(n===le||n===ue||n===Me){let u=n;i++;while(i<e.length)if(e.charCodeAt(i)===Ye)i+=2;else if(e.charCodeAt(i++)===u)break;continue}if(n===X&&e.charCodeAt(i+1)===X){i+=2;while(i<e.length&&e.charCodeAt(i)!==he&&e.charCodeAt(i)!==be)i++;continue}if(n===X&&e.charCodeAt(i+1)===Ee){let u=e.indexOf("*/",i+2);i=u===-1?e.length:u+2;continue}if(!Wt(n)){i++;continue}let r=i++;while(i<e.length&&Ze(e.charCodeAt(i)))i++;let o=r-1,s=i;while(o>=0&&Be(e.charCodeAt(o)))o--;while(s<e.length&&Be(e.charCodeAt(s)))s++;let a=o>=0?e.charCodeAt(o):0,c=s<e.length?e.charCodeAt(s):0,f=r>=3&&e.slice(r-3,r)==="...";if(c===at||a===mt&&!f)continue;if(c===se&&(a===z||a===lt))continue;t.add(e.slice(r,i))}}function rd(e,t){let i=new Set,n=new Set;for(let s of e)n.add(s.name);let r=new Set,o=[];for(let s=0;s<e.length;s++){let a=e[s];if(a.kind!=="import"){if(o.push(a.text),rl(a.text,r),typeof a.value==="string")nl(a.value,r)}}for(;;){let s=[];for(let[f,u]of t){if(i.has(f))continue;if(r.has(f)){if(!n.has(f))s.push(u),n.add(f);i.add(f)}}if(s.length===0)break;s.sort((f,u)=>(f.start??1/0)-(u.start??1/0));let a=[],c=0;for(let f=0;f<e.length;f++){let u=e[f].start??1/0;while(c<s.length&&(s[c].start??1/0)<=u)a.push(s[c++]);a.push(e[f])}while(c<s.length)a.push(s[c++]);e.length=0;for(let f=0;f<a.length;f++)e.push(a[f]);for(let f of s)if(f.kind!=="import"){if(o.push(f.text),rl(f.text,r),typeof f.value==="string")nl(f.value,r)}}}var Pe=32,Oe=9,he=10,be=13,X=47,Ee=42,le=39,ue=34,Me=96,Ye=92,z=123,Q=125,se=40,Ae=41,we=91,Re=93,ve=60,fe=62,ie=59,at=58,Se=61,lt=44,mt=46,Fr=63,Nr=35,Qh=64,ol=36,ed=95,go;var cl=pe(()=>{po();go=["public","protected","private","readonly","override"]});function ul(e,t,i=!0,n=!1){if(Oa(t))e=Da(e);else if(Fa(t))e=Na(e);let r=ui(e),o=`${t}:${i?1:0}:${n?1:0}`,s=ci.get(o);if(s&&s.contentHash===r)return s.lastAccess=++fl,s.declarations;let a=n?sl(e,t,i):al(e,t,i);if(ci.set(o,{declarations:a,contentHash:r,lastAccess:++fl}),ci.size>nd){let c=Math.max(1,Math.ceil(ci.size*0.1)),f=[];for(let[u,l]of ci)f.push([u,l.lastAccess]);f.sort((u,l)=>u[1]-l[1]);for(let u=0;u<c&&u<f.length;u++)ci.delete(f[u][0])}return a}var nd=100,fl=0,ci;var hl=pe(()=>{no();La();cl();rn();ci=new Map});function dl(e,t,i=!0,n=!1){return ul(e,t,i,n)}var ml=pe(()=>{hl()});async function od(){if(Wr!==null)return Wr;try{return Ot=await import("prettier"),Wr=!0,!0}catch{return Wr=!1,!1}}async function sd(e,t){if(!Ot)return null;try{if(t&&Ot.resolveConfig){let i=await Ot.resolveConfig(t);if(i)return i}if(e&&Ot.resolveConfig){let i=await Ot.resolveConfig(e);if(i)return i}return null}catch{return null}}async function ad(e,t){if(!Ot)throw Error("Prettier is not available");let i={...t,parser:t.parser||"typescript"};return Ot.format(e,i)}function ld(e,t={}){let{indentSize:i=2,useTabs:n=!1,maxLineWidth:r=100,trailingNewline:o=!0,normalizeWhitespace:s=!0,sortImports:a=!0,groupImports:c=!0}=t,f=e,u=n?"\t":" ".repeat(i);if(f.indexOf(`\r
162
+ }`}function Sc(m,h){let d=l+m.length;while(d<a&&Be(r.charCodeAt(d)))d++;for(let g=0;g<h.length;g++)if(d+g>=a||r.charCodeAt(d+g)!==h.charCodeAt(g))return!1;return d+h.length>=a||!Ze(r.charCodeAt(d+h.length))}function _t(m,h,d){l+=d.length,p();let g="",C=r.charCodeAt(l);if(C===le||C===ue){let A=l;S(C),g=r.slice(A,l)}else{g=W();while(l<a&&r.charCodeAt(l)===mt)l++,g+=`.${W()}`}p();let v=l<a&&r.charCodeAt(l)===z?Yr():"{}",T=`${h?"export ":""}declare ${d} ${g} ${v}`,P=Qe(m),b=g.startsWith("'")||g.startsWith('"');return{kind:"module",name:g,text:T,isExported:h,source:b?g.slice(1,-1):void 0,leadingComments:P,start:m,end:l}}function Do(m,h){q();let d=y(h,l);if(d.charCodeAt(d.length-1)===ie)d=d.slice(0,-1).trimEnd();if(!d)return;let g=Wt(d.charCodeAt(0));for(let A=1;g&&A<d.length;A++)g=Ze(d.charCodeAt(A));let C=Qe(m);if(g){c.push({kind:"export",name:"default",text:`export default ${d};`,isExported:!0,isTypeOnly:!1,leadingComments:C,start:m,end:l});return}let v="__dtsx_default_export__",T=1;while(r.includes(v))v=`__dtsx_default_export_${T++}__`;let P=Ii(d)||Ie(d,!1),b=P==="unknown"&&td(d)?`typeof ${d}`:P;c.push({kind:"variable",name:v,text:`declare const ${v}: ${b};`,isExported:!1,typeAnnotation:b,modifiers:["const"],start:m,end:l}),c.push({kind:"export",name:"default",text:`export default ${v};`,isExported:!0,isTypeOnly:!1,leadingComments:C,start:m,end:l})}while(l<a){if(p(),l>=a)break;let m=l,h=r.charCodeAt(l);if(h===105&&R("import"))c.push(pc(m));else if(h===101&&R("export")){l+=6,p();let d=r.charCodeAt(l);if(d===100&&R("default")){l+=7,p();let g=l,C=r.charCodeAt(l);if(C===102&&R("function")){let v=At(m,!0,!1,!0);if(v)c.push(v)}else if(C===97&&R("async")&&Oo("async")!==ie)if(l+=5,p(),R("function")){let v=At(m,!0,!0,!0);if(v)c.push(v)}else Do(m,g);else if(C===99&&R("class")){let v=xt(m,!0,!1,!0);c.push(v)}else if(C===97&&R("abstract")){if(l+=8,p(),R("class")){let v=xt(m,!0,!0,!0);c.push(v)}}else Do(m,g)}else if(d===116&&R("type")){let g=l;if(l+=4,p(),l<a&&r.charCodeAt(l)===z){Fe();let C=y(m,l),v=Qe(m);c.push({kind:"export",name:"",text:C,isExported:!0,isTypeOnly:!0,source:Mi(C),leadingComments:v,start:m,end:l})}else if(l<a&&r.charCodeAt(l)===Ee){ki();let C=y(m,l);c.push({kind:"export",name:"",text:C,isExported:!0,isTypeOnly:!0,source:Mi(C),start:m,end:l})}else{l=g;let C=zr(m,!0);c.push(C)}}else if(d===105&&R("interface")){let g=Kr(m,!0);c.push(g)}else if(d===102&&R("function")){let g=At(m,!0,!1,!1);if(g)c.push(g)}else if(d===97&&R("async"))if(l+=5,p(),R("function")){let g=At(m,!0,!0,!1);if(g)c.push(g)}else q();else if(d===99)if(R("class")){let g=xt(m,!0,!1);c.push(g)}else if(R("const")){let g=l;if(l+=5,p(),R("enum")){l=g+5,p();let C=jt(m,!0,!0);c.push(C)}else{l=g;let C=Mt(m,"const",!0);for(let v=0;v<C.length;v++)c.push(C[v])}}else q();else if(d===97&&R("abstract")){if(l+=8,p(),R("class")){let g=xt(m,!0,!0);c.push(g)}}else if(d===108&&R("let")){let g=Mt(m,"let",!0);for(let C=0;C<g.length;C++)c.push(g[C])}else if(d===118&&R("var")){let g=Mt(m,"var",!0);for(let C=0;C<g.length;C++)c.push(g[C])}else if(d===101&&R("enum")){let g=jt(m,!0,!1);c.push(g)}else if(d===100&&R("declare"))l+=7,p(),Io(m,!0);else if(d===110&&R("namespace")&&D(9)){let g=_t(m,!0,"namespace");c.push(g)}else if(d===109&&R("module")&&D(6)){let g=_t(m,!0,"module");c.push(g)}else if(d===z){Fe();let g=y(m,l),C=g.includes("export type"),v=Qe(m);c.push({kind:"export",name:"",text:g,isExported:!0,isTypeOnly:C,source:Mi(g),leadingComments:v,start:m,end:l})}else if(d===Ee){ki();let g=y(m,l),C=Qe(m);c.push({kind:"export",name:"",text:g,isExported:!0,isTypeOnly:!1,source:Mi(g),leadingComments:C,start:m,end:l})}else{q();let g=y(m,l);if(g)c.push({kind:"export",name:"",text:g,isExported:!0,start:m,end:l})}}else if(h===100&&R("declare"))l+=7,p(),Io(m,!1);else if(h===105&&R("interface")){let d=Kr(m,!1);f.set(d.name,d)}else if(h===116&&R("type")){let d=zr(m,!1);f.set(d.name,d),c.push(d)}else if(h===102&&R("function")){let d=At(m,!1,!1,!1);if(d)f.set(d.name,d);else q()}else if(h===97)if(R("async")){let d=l;if(l+=5,p(),R("function")){let g=At(m,!1,!0,!1);if(g)f.set(g.name,g);else l=d,q()}else l=d,q()}else if(R("abstract"))if(l+=8,p(),R("class")){let d=xt(m,!1,!1);f.set(d.name,d),c.push(d)}else q();else l++,q();else if(h===99)if(R("class")){let d=xt(m,!1,!1);f.set(d.name,d),c.push(d)}else if(R("const")){let d=l;if(l+=5,p(),R("enum")){l=d+5,p();let g=jt(m,!1,!0);f.set(g.name,g),c.push(g)}else{l=d;let g=Mt(m,"const",!1);for(let C=0;C<g.length;C++)f.set(g[C].name,g[C])}}else l++,q();else if(h===101&&R("enum")){let d=jt(m,!1,!1);f.set(d.name,d),c.push(d)}else if(h===108&&R("let")||h===118&&R("var")){let d=R("let")?"let":"var",g=Mt(m,d,!1);for(let C=0;C<g.length;C++)f.set(g[C].name,g[C])}else if(h===109&&R("module")&&D(6)){let d=_t(m,!1,"module");c.push(d)}else if(h===110&&R("namespace")&&D(9)){let d=_t(m,!1,"namespace");c.push(d)}else{let d=r.charCodeAt(l);if(d===ie)l++;else if(d===le||d===ue){if(S(d),l<a&&r.charCodeAt(l)===ie)l++}else if(d===Me){if(x(),l<a&&r.charCodeAt(l)===ie)l++}else if(d===Qh){if(l++,W(),p(),l<a&&r.charCodeAt(l)===mt)l++,W(),p();if(l<a&&r.charCodeAt(l)===se)_(se,Ae)}else l++,q()}}if(f.size>0)rd(c,f);if(u.size>0){let m=new Map;for(let d of c)if(d.kind==="function")m.set(d.name,(m.get(d.name)||0)+1);let h=new Set;for(let[d,g]of m)if(g>1)h.add(d);if(h.size>0){let d=new Set;for(let g of h)for(let C=c.length-1;C>=0;C--)if(c[C].kind==="function"&&c[C].name===g&&u.has(C)){d.add(C);break}if(d.size>0){let g=[...d].sort((C,v)=>v-C);for(let C of g)c.splice(C,1)}}}return c;function Io(m,h){if(R("function")){let d=At(m,h,!1,!1);if(d)c.push(d)}else if(R("async")){if(l+=5,p(),R("function")){let d=At(m,h,!0,!1);if(d)c.push(d)}}else if(R("class")){let d=xt(m,h,!1);c.push(d)}else if(R("abstract")){if(l+=8,p(),R("class")){let d=xt(m,h,!0);c.push(d)}}else if(R("interface")){let d=Kr(m,h);c.push(d)}else if(R("type")){let d=zr(m,h);c.push(d)}else if(R("enum")){let d=jt(m,h,!1);c.push(d)}else if(R("const")){let d=l;if(l+=5,p(),R("enum")){l=d+5,p();let g=jt(m,h,!0);c.push(g)}else if(h){l=d;let g=Mt(m,"const",!0);for(let C=0;C<g.length;C++)c.push(g[C])}else q()}else if(R("let")||R("var"))if(h){let d=R("let")?"let":"var",g=Mt(m,d,!0);for(let C=0;C<g.length;C++)c.push(g[C])}else q();else if(R("module")){let d=_t(m,h,"module");c.push(d)}else if(R("namespace")){let d=_t(m,h,"namespace");c.push(d)}else if(R("global")){l+=6,p();let d=`declare global ${l<a&&r.charCodeAt(l)===z?Yr():"{}"}`,g=Qe(m);c.push({kind:"module",name:"global",text:d,isExported:!1,leadingComments:g,start:m,end:l})}else q()}}function rl(e,t){let i=0,n=e.length;while(i<n){let r=e.charCodeAt(i);if(r>=65&&r<=90||r>=97&&r<=122||r===95||r===36||r>127){let o=i;i++;while(i<n){let s=e.charCodeAt(i);if(s>=65&&s<=90||s>=97&&s<=122||s>=48&&s<=57||s===95||s===36||s>127)i++;else break}t.add(e.substring(o,i))}else i++}}function nl(e,t){let i=0;while(i<e.length){let n=e.charCodeAt(i);if(n===le||n===ue||n===Me){let u=n;i++;while(i<e.length)if(e.charCodeAt(i)===Ye)i+=2;else if(e.charCodeAt(i++)===u)break;continue}if(n===X&&e.charCodeAt(i+1)===X){i+=2;while(i<e.length&&e.charCodeAt(i)!==he&&e.charCodeAt(i)!==be)i++;continue}if(n===X&&e.charCodeAt(i+1)===Ee){let u=e.indexOf("*/",i+2);i=u===-1?e.length:u+2;continue}if(!Wt(n)){i++;continue}let r=i++;while(i<e.length&&Ze(e.charCodeAt(i)))i++;let o=r-1,s=i;while(o>=0&&Be(e.charCodeAt(o)))o--;while(s<e.length&&Be(e.charCodeAt(s)))s++;let a=o>=0?e.charCodeAt(o):0,c=s<e.length?e.charCodeAt(s):0,f=r>=3&&e.slice(r-3,r)==="...";if(c===lt||a===mt&&!f)continue;if(c===se&&(a===z||a===ct))continue;t.add(e.slice(r,i))}}function rd(e,t){let i=new Set,n=new Set;for(let s of e)n.add(s.name);let r=new Set,o=[];for(let s=0;s<e.length;s++){let a=e[s];if(a.kind!=="import"){if(o.push(a.text),rl(a.text,r),typeof a.value==="string")nl(a.value,r)}}for(;;){let s=[];for(let[f,u]of t){if(i.has(f))continue;if(r.has(f)){if(!n.has(f))s.push(u),n.add(f);i.add(f)}}if(s.length===0)break;s.sort((f,u)=>(f.start??1/0)-(u.start??1/0));let a=[],c=0;for(let f=0;f<e.length;f++){let u=e[f].start??1/0;while(c<s.length&&(s[c].start??1/0)<=u)a.push(s[c++]);a.push(e[f])}while(c<s.length)a.push(s[c++]);e.length=0;for(let f=0;f<a.length;f++)e.push(a[f]);for(let f of s)if(f.kind!=="import"){if(o.push(f.text),rl(f.text,r),typeof f.value==="string")nl(f.value,r)}}}var Pe=32,Oe=9,he=10,be=13,X=47,Ee=42,le=39,ue=34,Me=96,Ye=92,z=123,Q=125,se=40,Ae=41,we=91,Re=93,ve=60,fe=62,ie=59,lt=58,Se=61,ct=44,mt=46,Fr=63,Nr=35,Qh=64,ol=36,ed=95,go;var cl=pe(()=>{po();go=["public","protected","private","readonly","override"]});function ul(e,t,i=!0,n=!1){if(Oa(t))e=Da(e);else if(Fa(t))e=Na(e);let r=ui(e),o=`${t}:${i?1:0}:${n?1:0}`,s=ci.get(o);if(s&&s.contentHash===r)return s.lastAccess=++fl,s.declarations;let a=n?sl(e,t,i):al(e,t,i);if(ci.set(o,{declarations:a,contentHash:r,lastAccess:++fl}),ci.size>nd){let c=Math.max(1,Math.ceil(ci.size*0.1)),f=[];for(let[u,l]of ci)f.push([u,l.lastAccess]);f.sort((u,l)=>u[1]-l[1]);for(let u=0;u<c&&u<f.length;u++)ci.delete(f[u][0])}return a}var nd=100,fl=0,ci;var hl=pe(()=>{no();La();cl();rn();ci=new Map});function dl(e,t,i=!0,n=!1){return ul(e,t,i,n)}var ml=pe(()=>{hl()});async function od(){if(Wr!==null)return Wr;try{return Ot=await import("prettier"),Wr=!0,!0}catch{return Wr=!1,!1}}async function sd(e,t){if(!Ot)return null;try{if(t&&Ot.resolveConfig){let i=await Ot.resolveConfig(t);if(i)return i}if(e&&Ot.resolveConfig){let i=await Ot.resolveConfig(e);if(i)return i}return null}catch{return null}}async function ad(e,t){if(!Ot)throw Error("Prettier is not available");let i={...t,parser:t.parser||"typescript"};return Ot.format(e,i)}function ld(e,t={}){let{indentSize:i=2,useTabs:n=!1,maxLineWidth:r=100,trailingNewline:o=!0,normalizeWhitespace:s=!0,sortImports:a=!0,groupImports:c=!0}=t,f=e,u=n?"\t":" ".repeat(i);if(f.indexOf(`\r
163
163
  `)!==-1)f=f.replace(/\r\n/g,`
164
164
  `);if(s){if(/[ \t]\n/.test(f)||/[ \t]$/.test(f))f=f.replace(/[ \t]+$/gm,"");if(f.indexOf(`
165
165
 
@@ -256,6 +256,7 @@ Errors:`);for(let E of s.errors){let k=` - ${E.file}`;if(E.location)k+=`:${E.lo
256
256
  `+(e.exclude?.length?` exclude: ${e.exclude.map((o)=>JSON.stringify(o)).join(", ")}
257
257
  `:"")+"Entrypoints are resolved relative to --root. Pass several by repeating --entrypoints or separating them with commas.";if(t.length===0){if(e.entrypoints.filter((o)=>xi(o)&&Ql(o)&&!Ti(o,i)).length===e.entrypoints.length)return;throw Error(`No source files matched. Nothing was generated.
258
258
  ${n}`)}let r=e.entrypoints.filter((o)=>{if(bm.test(o))return!1;return!Ql(xi(o)?o:Xe(i,o))});if(r.length>0)throw Error(`Entrypoint${r.length>1?"s":""} not found: ${r.map((o)=>JSON.stringify(o)).join(", ")}
259
- ${n}`)}async function $m(e){let t=[],i=Xe(e.cwd,e.root),n=e.exclude||[],r=[...e.entrypoints,...e.include??[]];for(let o of r)if(xi(o)&&Eo(o)){if(!o.includes("node_modules")){if(!Ti(o,i)&&e.outputStructure!=="flat")Z.warn(`Skipping entrypoint outside root: ${Ge(e.cwd,o)}`);else if(!vo(o,n,i))t.push(o)}}else{let s=new ic(o);for await(let a of s.scan({cwd:i,absolute:!0,onlyFiles:!0}))if(Eo(a)&&!a.includes("node_modules")){if(!vo(a,n,i))t.push(a)}}return[...new Set(t)].sort()}function Ti(e,t){let i=Ge(t,e);return i!==".."&&!i.startsWith(`..${process.platform==="win32"?"\\":"/"}`)&&!xi(i)}function Am(e,t){let i=new Map;for(let n of e){let r=Ri(n,t),o=i.get(r);if(o&&o!==n)throw Error(`Output path collision: ${Ge(t.cwd,o)} and ${Ge(t.cwd,n)} both emit ${Ge(t.cwd,r)}`);i.set(r,n)}}function Eo(e){return/\.(m?tsx?|cts|jsx?|mjs|cjs|vue|stx)$/.test(e)&&!/\.d\.(?:ts|mts|cts)$/.test(e)}function Ri(e,t){let i=Xe(t.cwd,t.root),n=Ge(i,e).replace(/\.(m?tsx?|cts|jsx?|mjs|cjs|vue|stx)$/,(r)=>{if(r===".mts"||r===".mjs")return".d.mts";if(r===".cts"||r===".cjs")return".d.cts";return".d.ts"});if(t.outputStructure==="mirror")return Xe(t.cwd,t.outdir,n);else{let r=n.split("/").pop();return Xe(t.cwd,t.outdir,r)}}function xm(e,t,i=""){let n=Ge(Ai(e),t).replace(/\\/g,"/");if(n=n.replace(/\.d\.mts$/,"").replace(/\.d\.cts$/,"").replace(/\.d\.ts$/,""),i)n+=i;if(!n.startsWith("."))n=`./${n}`;return n}function Tm(e,t,i){let n=Ri(t,i),r=(o)=>{let s=Ut(o,t);if(!s.isRelative||!s.resolved)return o;if(/\.d\.(?:ts|mts|cts)$/.test(s.resolved))return o;let a=o.match(/[?#].*$/)?.[0]??"",c=a?o.slice(0,-a.length):o,f=gm(c),u=/^(?:\.js|\.jsx|\.mjs|\.cjs)$/.test(f)?f:"";return xm(n,Ri(s.resolved,i),u)+a};return e.replace(/\b(from\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(o,s,a,c)=>`${s}${a}${r(c)}${a}`).replace(/\b(import\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(o,s,a,c)=>`${s}${a}${r(c)}${a}`).replace(/\b(import\s*\(\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(o,s,a,c)=>`${s}${a}${r(c)}${a}`)}async function Rm(e,t,i,n,r){let o=t;if(n)o=await n.runOnBeforeFile(e,t);let s=dl(o,e,i.keepComments,i.isolatedDeclarations??!1);if(n)s=await n.runOnDeclarations(e,o,s);let a=0,c=0;for(let u=0;u<s.length;u++){let l=s[u];if(l.kind==="import")a++;if(l.kind==="export"||l.isExported)c++}let f=Zl(s,{filePath:e,sourceCode:o,declarations:s},i.keepComments,i.importOrder);if(f=Tm(f,e,i),r)f=$l(f,r,{filePath:e});if(i.normalizeOutput===!0||i.declarationOrder)f=vl(f,{lineEnding:"lf",declarationOrder:i.declarationOrder,indent:{style:i.indentStyle??"spaces",size:i.indentSize??2}});if(n)f=await n.runOnAfterFile(e,o,f);return{content:f,declarationCount:s.length,importCount:a,exportCount:c}}var ic,Cm=50,$i,bm;var nc=pe(()=>{Ni();en();_o();Jo();Yo();Aa();es();Ra();ml();gl();yl();El();Al();_l();Xl();({Glob:ic}=globalThis.Bun);$i=new Map;bm=/[*?[\]{}!]/});var oc=pe(()=>{nc()});import{createHash as Om}from"crypto";import{existsSync as km,readFileSync as Mm,writeFileSync as Dm}from"fs";import{dirname as Im,join as Fm,relative as sc,resolve as Pi,sep as jr}from"path";import lc from"process";class cc{listeners=new Map;on(e,t){let i=this.listeners.get(e)||[];i.push(t),this.listeners.set(e,i)}async emit(e,t){let i={type:e,timestamp:Date.now(),data:t},n=this.listeners.get(e)||[];for(let r of n)await r(i)}}class fc{manifest;cacheDir;manifestPath;constructor(e,t){this.cacheDir=e,this.manifestPath=Fm(e,"manifest.json"),this.manifest=this.loadManifest(t)}loadManifest(e){try{if(km(this.manifestPath)){let t=JSON.parse(Mm(this.manifestPath,"utf-8"));if(t.configHash===e&&t.version==="1.0")return t}}catch{}return{version:"1.0",configHash:e,entries:{}}}save(){try{let{mkdirSync:e}=Pm("fs");e(this.cacheDir,{recursive:!0}),Dm(this.manifestPath,JSON.stringify(this.manifest,null,2))}catch{}}getEntry(e){return this.manifest.entries[e]}setEntry(e,t){this.manifest.entries[e]=t}isValid(e,t){return this.getEntry(e)?.hash===t}clear(){this.manifest.entries={},this.save()}}function Nm(e){let t={root:e.root,outdir:e.outdir,entrypoints:e.entrypoints,clean:e.clean,tsconfigPath:e.tsconfigPath};return Om("md5").update(JSON.stringify(t)).digest("hex")}function uc(e={}){let{onSuccess:t,onError:i,failOnError:n=!0,incremental:r=!1,cacheDir:o=".dtsx-cache",on:s,timeout:a=60000,continueOnError:c=!1,verbose:f=!1,...u}=e,l=new cc;if(s){for(let[y,p]of Object.entries(s))if(p)l.on(y,p)}return{name:"bun-plugin-dtsx",async setup(y){let p=Date.now(),w=null,S=0;try{let x=Bm(u,y),E=Nm(x);if(x.clean){let J=Pi(x.cwd??lc.cwd(),x.outdir??"./dist");if(ac.has(J))x.clean=!1;else ac.add(J)}if(r)w=new fc(Pi(o),E);if(await l.emit("start",{type:"start",files:x.entrypoints||[],config:x}),f){if(console.log("[bun-plugin-dtsx] Starting declaration generation..."),r)console.log("[bun-plugin-dtsx] Incremental mode enabled")}let M=await(async()=>new Promise((J,W)=>{let R=setTimeout(()=>{W(new Oi(`Generation timed out after ${a}ms`,"TIMEOUT_ERROR",{timeout:a}))},a);bo(x).then((D)=>{clearTimeout(R),J(D)}).catch((D)=>{clearTimeout(R),W(D)})}))(),I=Date.now()-p;if(w)w.save();if(await l.emit("complete",{type:"complete",stats:M,duration:I,fromCache:S}),f){if(console.log(`[bun-plugin-dtsx] Generation complete in ${I}ms`),S>0)console.log(`[bun-plugin-dtsx] ${S} files served from cache`)}if(t)await t(M)}catch(x){let E=Lm(x);if(await l.emit("error",{type:"error",error:E}),i)await i(E);else{if(console.error("[bun-plugin-dtsx] Error generating declarations:"),console.error(` Code: ${E.code}`),console.error(` Message: ${E.message}`),E.context)console.error(` Context: ${JSON.stringify(E.context)}`);if(f&&E.stack)console.error(` Stack: ${E.stack}`)}if(n&&!c)throw E}}}}function Lm(e){if(e instanceof Oi)return e;if(e instanceof Error){let t="GENERATION_ERROR";if(e.message.includes("config")||e.message.includes("Config"))t="CONFIG_ERROR";else if(e.message.includes("file")||e.message.includes("File")||e.message.includes("ENOENT"))t="FILE_ERROR";return new Oi(e.message,t,{originalError:e.name},e)}return new Oi(String(e),"GENERATION_ERROR")}function Wm(e){let t=e.map((n)=>Im(n).split(jr)),i=t[0];for(let n of t.slice(1)){let r=0;while(r<i.length&&r<n.length&&i[r]===n[r])r++;i=i.slice(0,r)}return i.join(jr)||jr}function Bm(e,t){let i=e.cwd||lc.cwd(),n=t?.config?.entrypoints,r=e.outdir||e.build?.config.outdir||t?.config.outdir||"./dist",o=e.root||e.build?.config.root||t?.config.root;if(!o&&n?.length){let a=Wm(n.map((c)=>Pi(i,c)));o=sc(i,a)||"."}o=o||"./src";let s=e.entrypoints;if(!s)if(n?.length){let a=Pi(i,o),c=[];for(let f of n){let u=Pi(i,f);if(u===a||u.startsWith(a+jr))c.push(sc(a,u));else console.warn(`[bun-plugin-dtsx] Skipping entrypoint outside root "${o}": ${f}`)}s=c.length?c:["index.ts"]}else s=["index.ts"];return{...e,cwd:i,root:o,entrypoints:s,outdir:r,clean:e.clean??!0,tsconfigPath:e.tsconfigPath}}var Pm,Oi,ac;var hc=pe(()=>{oc();Pm=import.meta.require;Oi=class Oi extends Error{code;context;cause;constructor(e,t,i,n){super(e);if(this.name="DtsxPluginError",this.code=t,this.context=i,this.cause=n,Error.captureStackTrace)Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,code:this.code,message:this.message,context:this.context,stack:this.stack}}};ac=new Set});import{mkdir as Gm,stat as jm}from"fs/promises";import{bold as So,dim as $o,green as _m,italic as dc,log as Vm}from"@stacksjs/cli";import{path as ct}from"@stacksjs/path";import{glob as mc}from"@stacksjs/storage";async function Um(e){let t=await mc([ct.resolve(e,"dist","**/*.d.ts")],{absolute:!0}),i=new Bun.Transpiler({loader:"ts",target:"bun"});for(let n of t){let r=await Bun.file(n).text();try{i.transformSync(r)}catch(o){throw Error(`Invalid declaration generated at ${n}: ${o instanceof Error?o.message:String(o)}`)}}}async function Km(e){let t=ct.resolve(e,"dist","index.js");if(!await Bun.file(t).exists())return;let i=Bun.spawnSync({cmd:[process.execPath,"-e",`await import(${JSON.stringify(t)})`],stdout:"ignore",stderr:"pipe",env:{...process.env,NODE_ENV:"test"}});if(i.exitCode===0)return;let n=new TextDecoder().decode(i.stderr??new Uint8Array);if(/needs to refer to a top-level declared variable|does not provide an export named|Export named .* not found/i.test(n))throw Error(`Built package at ${t} cannot be imported: ${n.trim().split(`
259
+ ${n}`)}async function $m(e){let t=[],i=Xe(e.cwd,e.root),n=e.exclude||[],r=[...e.entrypoints,...e.include??[]];for(let o of r)if(xi(o)&&Eo(o)){if(!o.includes("node_modules")){if(!Ti(o,i)&&e.outputStructure!=="flat")Z.warn(`Skipping entrypoint outside root: ${Ge(e.cwd,o)}`);else if(!vo(o,n,i))t.push(o)}}else{let s=new ic(o);for await(let a of s.scan({cwd:i,absolute:!0,onlyFiles:!0}))if(Eo(a)&&!a.includes("node_modules")){if(!vo(a,n,i))t.push(a)}}return[...new Set(t)].sort()}function Ti(e,t){let i=Ge(t,e);return i!==".."&&!i.startsWith(`..${process.platform==="win32"?"\\":"/"}`)&&!xi(i)}function Am(e,t){let i=new Map;for(let n of e){let r=Ri(n,t),o=i.get(r);if(o&&o!==n)throw Error(`Output path collision: ${Ge(t.cwd,o)} and ${Ge(t.cwd,n)} both emit ${Ge(t.cwd,r)}`);i.set(r,n)}}function Eo(e){return/\.(m?tsx?|cts|jsx?|mjs|cjs|vue|stx)$/.test(e)&&!/\.d\.(?:ts|mts|cts)$/.test(e)}function Ri(e,t){let i=Xe(t.cwd,t.root),n=Ge(i,e).replace(/\.(m?tsx?|cts|jsx?|mjs|cjs|vue|stx)$/,(r)=>{if(r===".mts"||r===".mjs")return".d.mts";if(r===".cts"||r===".cjs")return".d.cts";return".d.ts"});if(t.outputStructure==="mirror")return Xe(t.cwd,t.outdir,n);else{let r=n.split("/").pop();return Xe(t.cwd,t.outdir,r)}}function xm(e,t,i=""){let n=Ge(Ai(e),t).replace(/\\/g,"/");if(n=n.replace(/\.d\.mts$/,"").replace(/\.d\.cts$/,"").replace(/\.d\.ts$/,""),i)n+=i;if(!n.startsWith("."))n=`./${n}`;return n}function Tm(e,t,i){let n=Ri(t,i),r=(o)=>{let s=Ut(o,t);if(!s.isRelative||!s.resolved)return o;if(/\.d\.(?:ts|mts|cts)$/.test(s.resolved))return o;let a=o.match(/[?#].*$/)?.[0]??"",c=a?o.slice(0,-a.length):o,f=gm(c),u=/^(?:\.js|\.jsx|\.mjs|\.cjs)$/.test(f)?f:"";return xm(n,Ri(s.resolved,i),u)+a};return e.replace(/\b(from\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(o,s,a,c)=>`${s}${a}${r(c)}${a}`).replace(/\b(import\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(o,s,a,c)=>`${s}${a}${r(c)}${a}`).replace(/\b(import\s*\(\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(o,s,a,c)=>`${s}${a}${r(c)}${a}`)}async function Rm(e,t,i,n,r){let o=t;if(n)o=await n.runOnBeforeFile(e,t);let s=dl(o,e,i.keepComments,i.isolatedDeclarations??!1);if(n)s=await n.runOnDeclarations(e,o,s);let a=0,c=0;for(let u=0;u<s.length;u++){let l=s[u];if(l.kind==="import")a++;if(l.kind==="export"||l.isExported)c++}let f=Zl(s,{filePath:e,sourceCode:o,declarations:s},i.keepComments,i.importOrder);if(f=Tm(f,e,i),r)f=$l(f,r,{filePath:e});if(i.normalizeOutput===!0||i.declarationOrder)f=vl(f,{lineEnding:"lf",declarationOrder:i.declarationOrder,indent:{style:i.indentStyle??"spaces",size:i.indentSize??2}});if(n)f=await n.runOnAfterFile(e,o,f);return{content:f,declarationCount:s.length,importCount:a,exportCount:c}}var ic,Cm=50,$i,bm;var nc=pe(()=>{Ni();en();_o();Jo();Yo();Aa();es();Ra();ml();gl();yl();El();Al();_l();Xl();({Glob:ic}=globalThis.Bun);$i=new Map;bm=/[*?[\]{}!]/});var oc=pe(()=>{nc()});import{createHash as Om}from"crypto";import{existsSync as km,readFileSync as Mm,writeFileSync as Dm}from"fs";import{dirname as Im,join as Fm,relative as sc,resolve as Pi,sep as jr}from"path";import lc from"process";class cc{listeners=new Map;on(e,t){let i=this.listeners.get(e)||[];i.push(t),this.listeners.set(e,i)}async emit(e,t){let i={type:e,timestamp:Date.now(),data:t},n=this.listeners.get(e)||[];for(let r of n)await r(i)}}class fc{manifest;cacheDir;manifestPath;constructor(e,t){this.cacheDir=e,this.manifestPath=Fm(e,"manifest.json"),this.manifest=this.loadManifest(t)}loadManifest(e){try{if(km(this.manifestPath)){let t=JSON.parse(Mm(this.manifestPath,"utf-8"));if(t.configHash===e&&t.version==="1.0")return t}}catch{}return{version:"1.0",configHash:e,entries:{}}}save(){try{let{mkdirSync:e}=Pm("fs");e(this.cacheDir,{recursive:!0}),Dm(this.manifestPath,JSON.stringify(this.manifest,null,2))}catch{}}getEntry(e){return this.manifest.entries[e]}setEntry(e,t){this.manifest.entries[e]=t}isValid(e,t){return this.getEntry(e)?.hash===t}clear(){this.manifest.entries={},this.save()}}function Nm(e){let t={root:e.root,outdir:e.outdir,entrypoints:e.entrypoints,clean:e.clean,tsconfigPath:e.tsconfigPath};return Om("md5").update(JSON.stringify(t)).digest("hex")}function uc(e={}){let{onSuccess:t,onError:i,failOnError:n=!0,incremental:r=!1,cacheDir:o=".dtsx-cache",on:s,timeout:a=60000,continueOnError:c=!1,verbose:f=!1,...u}=e,l=new cc;if(s){for(let[y,p]of Object.entries(s))if(p)l.on(y,p)}return{name:"bun-plugin-dtsx",async setup(y){let p=Date.now(),w=null,S=0;try{let x=Bm(u,y),E=Nm(x);if(x.clean){let J=Pi(x.cwd??lc.cwd(),x.outdir??"./dist");if(ac.has(J))x.clean=!1;else ac.add(J)}if(r)w=new fc(Pi(o),E);if(await l.emit("start",{type:"start",files:x.entrypoints||[],config:x}),f){if(console.log("[bun-plugin-dtsx] Starting declaration generation..."),r)console.log("[bun-plugin-dtsx] Incremental mode enabled")}let M=await(async()=>new Promise((J,W)=>{let R=setTimeout(()=>{W(new Oi(`Generation timed out after ${a}ms`,"TIMEOUT_ERROR",{timeout:a}))},a);bo(x).then((D)=>{clearTimeout(R),J(D)}).catch((D)=>{clearTimeout(R),W(D)})}))(),I=Date.now()-p;if(w)w.save();if(await l.emit("complete",{type:"complete",stats:M,duration:I,fromCache:S}),f){if(console.log(`[bun-plugin-dtsx] Generation complete in ${I}ms`),S>0)console.log(`[bun-plugin-dtsx] ${S} files served from cache`)}if(t)await t(M)}catch(x){let E=Lm(x);if(await l.emit("error",{type:"error",error:E}),i)await i(E);else{if(console.error("[bun-plugin-dtsx] Error generating declarations:"),console.error(` Code: ${E.code}`),console.error(` Message: ${E.message}`),E.context)console.error(` Context: ${JSON.stringify(E.context)}`);if(f&&E.stack)console.error(` Stack: ${E.stack}`)}if(n&&!c)throw E}}}}function Lm(e){if(e instanceof Oi)return e;if(e instanceof Error){let t="GENERATION_ERROR";if(e.message.includes("config")||e.message.includes("Config"))t="CONFIG_ERROR";else if(e.message.includes("file")||e.message.includes("File")||e.message.includes("ENOENT"))t="FILE_ERROR";return new Oi(e.message,t,{originalError:e.name},e)}return new Oi(String(e),"GENERATION_ERROR")}function Wm(e){let t=e.map((n)=>Im(n).split(jr)),i=t[0];for(let n of t.slice(1)){let r=0;while(r<i.length&&r<n.length&&i[r]===n[r])r++;i=i.slice(0,r)}return i.join(jr)||jr}function Bm(e,t){let i=e.cwd||lc.cwd(),n=t?.config?.entrypoints,r=e.outdir||e.build?.config.outdir||t?.config.outdir||"./dist",o=e.root||e.build?.config.root||t?.config.root;if(!o&&n?.length){let a=Wm(n.map((c)=>Pi(i,c)));o=sc(i,a)||"."}o=o||"./src";let s=e.entrypoints;if(!s)if(n?.length){let a=Pi(i,o),c=[];for(let f of n){let u=Pi(i,f);if(u===a||u.startsWith(a+jr))c.push(sc(a,u));else console.warn(`[bun-plugin-dtsx] Skipping entrypoint outside root "${o}": ${f}`)}s=c.length?c:["index.ts"]}else s=["index.ts"];return{...e,cwd:i,root:o,entrypoints:s,outdir:r,clean:e.clean??!0,tsconfigPath:e.tsconfigPath}}var Pm,Oi,ac;var hc=pe(()=>{oc();Pm=import.meta.require;Oi=class Oi extends Error{code;context;cause;constructor(e,t,i,n){super(e);if(this.name="DtsxPluginError",this.code=t,this.context=i,this.cause=n,Error.captureStackTrace)Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,code:this.code,message:this.message,context:this.context,stack:this.stack}}};ac=new Set});import{mkdir as Gm,stat as jm}from"fs/promises";import{bold as So,dim as $o,green as _m,italic as dc,log as Vm}from"@stacksjs/cli";import{path as rt}from"@stacksjs/path";import{glob as mc}from"@stacksjs/storage";async function Um(e){let t=await mc([rt.resolve(e,"dist","**/*.d.ts")],{absolute:!0}),i=new Bun.Transpiler({loader:"ts",target:"bun"});for(let n of t){let r=await Bun.file(n).text();try{i.transformSync(r)}catch(o){throw Error(`Invalid declaration generated at ${n}: ${o instanceof Error?o.message:String(o)}`)}}}async function Km(e){let t=rt.resolve(e,"dist","index.js");if(!await Bun.file(t).exists())return;let i=Bun.spawnSync({cmd:[process.execPath,"-e",`await import(${JSON.stringify(t)})`],stdout:"ignore",stderr:"pipe",env:{...process.env,NODE_ENV:"test"}});if(i.exitCode===0)return;let n=new TextDecoder().decode(i.stderr??new Uint8Array);if(/needs to refer to a top-level declared variable|does not provide an export named|Export named .* not found/i.test(n))throw Error(`Built package at ${t} cannot be imported: ${n.trim().split(`
260
260
  `)[0]}
261
- This is the minified-barrel failure. Build with \`transpilePackage\` instead of a minifying \`Bun.build\`.`)}async function L0(e){let i=Date.now()-e.startTime,n=e.pkgName??`@stacksjs/${ct.basename(e.dir)}`;if(e.result.errors&&e.result.errors.length>0)throw console.error("Build errors:",e.result.errors),Error(`Build failed with errors: ${JSON.stringify(e.result.errors)}`);else if(e.result.success!==void 0&&!e.result.success){let o=e.result.logs?.[0]||"Unknown build error";throw console.log(o),Error(`Build failed: ${o}`)}await Um(e.dir),await Km(e.dir);let r=await mc([ct.resolve(e.dir,"dist","**/*")],{absolute:!0});for(let o of r){let s=await jm(o),a;if(s.size<1048576)a=`${(s.size/1024).toFixed(2)}kb`;else a=`${(s.size/1024/1024).toFixed(2)}mb`;let c=ct.relative(e.dir,o).replace("dist/","");console.log(`${So($o(`[${a}]`))} ${$o("dist/")}${c}`)}console.log(`${So($o(`[${i}ms]`))} Built ${dc(So(_m(n)))}`)}async function W0(e){let t=e.pkgName??`@stacksjs/${ct.basename(e.dir)}`;if(e.styled===!1)console.log(`Building ${t}...`);else Vm.info(`Building ${dc(t)}...`);return{startTime:Date.now()}}async function B0(e){await Promise.resolve().then(() => hc());let i=ct.resolve(e.dir,"src"),n=ct.resolve(e.dir,"dist"),r=(await Array.fromAsync(new Bun.Glob("**/*.ts").scan({cwd:i}))).filter((s)=>!s.endsWith(".d.ts")).filter((s)=>!s.endsWith(".test.ts")&&!s.endsWith(".spec.ts"));await Bun.build({entrypoints:r.map((s)=>ct.resolve(i,s)),outdir:n,root:i,target:"bun",format:"esm",splitting:!1,external:e.external??zm(),plugins:[uc({root:i,outdir:n})]});let o=new Bun.Transpiler({loader:"ts",target:"bun",minifyWhitespace:!0});for(let s of r){let a=o.transformSync(await Bun.file(ct.resolve(i,s)).text());a=a.replace(/(['"])(\.\.?\/[^'"]+?)\.tsx?\1/g,"$1$2.js$1");let c=ct.resolve(n,s.replace(/\.ts$/,".js"));await Gm(ct.dirname(c),{recursive:!0}),await Bun.write(c,a)}}function zm(e=[]){let t=[];try{let i=$c("fs"),n=JSON.parse(i.readFileSync(`${process.cwd()}/package.json`,"utf8"));t=[...Object.keys(n.dependencies??{}),...Object.keys(n.peerDependencies??{}),...Object.keys(n.optionalDependencies??{})]}catch{}return["@stacksjs/*",...t,...t.map((i)=>`${i}/*`),"bun-queue","ioredis","localtunnels","localtunnels/*","@craft-native/ts","ts-md","meilisearch","algoliasearch","@opensearch-project/opensearch","*.yaml","*.yml",...e]}export{zm as frameworkExternal,W0 as intro,L0 as outro,B0 as transpilePackage,Um as validateDeclarations,Km as validateRuntimeExports};
261
+ This is the minified-barrel failure. Build with \`transpilePackage\` instead of a minifying \`Bun.build\`.`)}async function L0(e){let i=Date.now()-e.startTime,n=e.pkgName??`@stacksjs/${rt.basename(e.dir)}`;if(e.result.errors&&e.result.errors.length>0)throw console.error("Build errors:",e.result.errors),Error(`Build failed with errors: ${JSON.stringify(e.result.errors)}`);else if(e.result.success!==void 0&&!e.result.success){let o=e.result.logs?.[0]||"Unknown build error";throw console.log(o),Error(`Build failed: ${o}`)}await Bun.write(rt.resolve(e.dir,"dist","tsconfig.json"),`${JSON.stringify({compilerOptions:{paths:{}}},null,2)}
262
+ `),await Um(e.dir),await Km(e.dir);let r=await mc([rt.resolve(e.dir,"dist","**/*")],{absolute:!0});for(let o of r){let s=await jm(o),a;if(s.size<1048576)a=`${(s.size/1024).toFixed(2)}kb`;else a=`${(s.size/1024/1024).toFixed(2)}mb`;let c=rt.relative(e.dir,o).replace("dist/","");console.log(`${So($o(`[${a}]`))} ${$o("dist/")}${c}`)}console.log(`${So($o(`[${i}ms]`))} Built ${dc(So(_m(n)))}`)}async function W0(e){let t=e.pkgName??`@stacksjs/${rt.basename(e.dir)}`;if(e.styled===!1)console.log(`Building ${t}...`);else Vm.info(`Building ${dc(t)}...`);return{startTime:Date.now()}}async function B0(e){await Promise.resolve().then(() => hc());let i=rt.resolve(e.dir,"src"),n=rt.resolve(e.dir,"dist"),r=(await Array.fromAsync(new Bun.Glob("**/*.ts").scan({cwd:i}))).filter((s)=>!s.endsWith(".d.ts")).filter((s)=>!s.endsWith(".test.ts")&&!s.endsWith(".spec.ts"));await Bun.build({entrypoints:r.map((s)=>rt.resolve(i,s)),outdir:n,root:i,target:"bun",format:"esm",splitting:!1,external:e.external??zm(),plugins:[uc({root:i,outdir:n})]});let o=new Bun.Transpiler({loader:"ts",target:"bun",minifyWhitespace:!0});for(let s of r){let a=o.transformSync(await Bun.file(rt.resolve(i,s)).text());a=a.replace(/(['"])(\.\.?\/[^'"]+?)\.tsx?\1/g,"$1$2.js$1");let c=rt.resolve(n,s.replace(/\.ts$/,".js"));await Gm(rt.dirname(c),{recursive:!0}),await Bun.write(c,a)}}function zm(e=[]){let t=[];try{let i=$c("fs"),n=JSON.parse(i.readFileSync(`${process.cwd()}/package.json`,"utf8"));t=[...Object.keys(n.dependencies??{}),...Object.keys(n.peerDependencies??{}),...Object.keys(n.optionalDependencies??{})]}catch{}return["@stacksjs/*",...t,...t.map((i)=>`${i}/*`),"bun-queue","ioredis","localtunnels","localtunnels/*","@craft-native/ts","ts-md","meilisearch","algoliasearch","@opensearch-project/opensearch","*.yaml","*.yml",...e]}export{zm as frameworkExternal,W0 as intro,L0 as outro,B0 as transpilePackage,Um as validateDeclarations,Km as validateRuntimeExports};
@@ -0,0 +1,5 @@
1
+ {
2
+ "compilerOptions": {
3
+ "paths": {}
4
+ }
5
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/build",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.106",
5
+ "version": "0.75.108",
6
6
  "description": "The Stacks framework build tools and configurations.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -58,9 +58,9 @@
58
58
  "prepublishOnly": "bun run build"
59
59
  },
60
60
  "dependencies": {
61
- "@stacksjs/cli": "0.75.106",
62
- "@stacksjs/path": "0.75.106",
63
- "@stacksjs/storage": "0.75.106",
61
+ "@stacksjs/cli": "0.75.108",
62
+ "@stacksjs/path": "0.75.108",
63
+ "@stacksjs/storage": "0.75.108",
64
64
  "bun-plugin-dtsx": "^0.11.19"
65
65
  },
66
66
  "devDependencies": {