@dtsx/dtsx 0.0.0-stage → 0.11.38
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/LICENSE.md +21 -0
- package/README.md +442 -2
- package/dist/bin/cli.d.ts +1 -0
- package/dist/bin/cli.js +12 -0
- package/dist/chunk-082w7zvy.js +4 -0
- package/dist/chunk-0k0fhq13.js +19 -0
- package/dist/chunk-0rmbc5zp.js +3 -0
- package/dist/chunk-0yg5mcrf.js +3 -0
- package/dist/chunk-0zfzhn19.js +31 -0
- package/dist/chunk-189nn4fc.js +3 -0
- package/dist/chunk-1j6092xz.js +7 -0
- package/dist/chunk-1qtghb2x.js +3 -0
- package/dist/chunk-2436cnmb.js +3 -0
- package/dist/chunk-2qd3axyx.js +5 -0
- package/dist/chunk-32qexm3w.js +3 -0
- package/dist/chunk-3fbt79hx.js +3 -0
- package/dist/chunk-3t57mzvf.js +3 -0
- package/dist/chunk-42j9cfte.js +3 -0
- package/dist/chunk-4fygcxtb.js +4 -0
- package/dist/chunk-50h54rax.js +177 -0
- package/dist/chunk-5hyv43ps.js +12 -0
- package/dist/chunk-6yvk3q1e.js +3 -0
- package/dist/chunk-73dzve1s.js +3 -0
- package/dist/chunk-7tremqhs.js +14 -0
- package/dist/chunk-83qnrx0m.js +7 -0
- package/dist/chunk-88gwzbew.js +4 -0
- package/dist/chunk-8d3sdkv4.js +24 -0
- package/dist/chunk-8tzd98q8.js +22 -0
- package/dist/chunk-96atbsd3.js +3 -0
- package/dist/chunk-9gts9ymh.js +3 -0
- package/dist/chunk-9menejdz.js +3 -0
- package/dist/chunk-a7nvyxpg.js +6 -0
- package/dist/chunk-ag1b6d30.js +3 -0
- package/dist/chunk-asws39qs.js +31 -0
- package/dist/chunk-bnry23ve.js +4 -0
- package/dist/chunk-bxc2herz.js +9 -0
- package/dist/chunk-cpmqa8kd.js +4 -0
- package/dist/chunk-cv29b4zb.js +7 -0
- package/dist/chunk-cyr45de1.js +8 -0
- package/dist/chunk-d0bazr3p.js +3 -0
- package/dist/chunk-danfamyx.js +3 -0
- package/dist/chunk-davy89dj.js +8 -0
- package/dist/chunk-e29rp5xj.js +7 -0
- package/dist/chunk-eba562w8.js +9 -0
- package/dist/chunk-ebjafajx.js +62 -0
- package/dist/chunk-ft2zk7jx.js +3 -0
- package/dist/chunk-g2120ysy.js +3 -0
- package/dist/chunk-ghfd34r7.js +3 -0
- package/dist/chunk-gspsxc9d.js +34 -0
- package/dist/chunk-h3n6256r.js +3 -0
- package/dist/chunk-hnqm1zb3.js +5 -0
- package/dist/chunk-htgy94y3.js +2 -0
- package/dist/chunk-hv8bx8xx.js +102 -0
- package/dist/chunk-hzn9kmq7.js +3 -0
- package/dist/chunk-ja7bp731.js +3 -0
- package/dist/chunk-jcckwgb9.js +3 -0
- package/dist/chunk-kfk554fj.js +3 -0
- package/dist/chunk-kkshxyex.js +18 -0
- package/dist/chunk-kpbz61yy.js +4 -0
- package/dist/chunk-mkakbjvs.js +3 -0
- package/dist/chunk-mwyjxjqa.js +3 -0
- package/dist/chunk-p023fhce.js +8 -0
- package/dist/chunk-p9vfxn8g.js +3 -0
- package/dist/chunk-pga5m4wm.js +3 -0
- package/dist/chunk-pjqzkgzk.js +6 -0
- package/dist/chunk-qzjzw9p2.js +3 -0
- package/dist/chunk-rbx6q1r0.js +18 -0
- package/dist/chunk-rkstz4w1.js +6 -0
- package/dist/chunk-rz060wxt.js +6 -0
- package/dist/chunk-sd8bywh9.js +21 -0
- package/dist/chunk-sv8h007a.js +3 -0
- package/dist/chunk-t4va49p3.js +10 -0
- package/dist/chunk-tka2m4af.js +7 -0
- package/dist/chunk-v6fwy63g.js +3 -0
- package/dist/chunk-v93389xm.js +3 -0
- package/dist/chunk-vf3ybe5r.js +3 -0
- package/dist/chunk-vkahj2ab.js +10 -0
- package/dist/chunk-wnqg6hem.js +27 -0
- package/dist/chunk-xa6rsd4b.js +29 -0
- package/dist/chunk-xfjfhe9d.js +3 -0
- package/dist/chunk-xwpn40p0.js +6 -0
- package/dist/chunk-y1g6v96c.js +10 -0
- package/dist/chunk-y5k0szq6.js +3 -0
- package/dist/chunk-yay68832.js +3 -0
- package/dist/chunk-yrv6z221.js +3 -0
- package/dist/chunk-yx1jy7fx.js +37 -0
- package/dist/chunk-zgcdx773.js +4 -0
- package/dist/chunk-zk3w5sqv.js +4 -0
- package/dist/chunk-zq93f8ca.js +5 -0
- package/dist/src/augmentation-graph.d.ts +11 -0
- package/dist/src/augmentation-graph.js +2 -0
- package/dist/src/binding-patterns.d.ts +18 -0
- package/dist/src/binding-patterns.js +2 -0
- package/dist/src/branded-types.d.ts +159 -0
- package/dist/src/branded-types.js +2 -0
- package/dist/src/bundle-linker.d.ts +38 -0
- package/dist/src/bundle-linker.js +2 -0
- package/dist/src/bundler.d.ts +55 -0
- package/dist/src/bundler.js +2 -0
- package/dist/src/cache.d.ts +53 -0
- package/dist/src/cache.js +2 -0
- package/dist/src/call-signatures.d.ts +1 -0
- package/dist/src/call-signatures.js +2 -0
- package/dist/src/checker.d.ts +107 -0
- package/dist/src/circular.d.ts +82 -0
- package/dist/src/circular.js +2 -0
- package/dist/src/compat.d.ts +114 -0
- package/dist/src/compat.js +2 -0
- package/dist/src/computed-keys.d.ts +12 -0
- package/dist/src/computed-keys.js +2 -0
- package/dist/src/concurrency.d.ts +4 -0
- package/dist/src/concurrency.js +2 -0
- package/dist/src/config.d.ts +35 -0
- package/dist/src/config.js +2 -0
- package/dist/src/dangling-refs.d.ts +11 -0
- package/dist/src/dangling-refs.js +2 -0
- package/dist/src/declaration-project.d.ts +33 -0
- package/dist/src/declaration-project.js +2 -0
- package/dist/src/declaration-publication.d.ts +15 -0
- package/dist/src/declaration-publication.js +2 -0
- package/dist/src/declaration-references.d.ts +19 -0
- package/dist/src/declaration-references.js +2 -0
- package/dist/src/diff.d.ts +82 -0
- package/dist/src/diff.js +2 -0
- package/dist/src/docs.d.ts +97 -0
- package/dist/src/docs.js +2 -0
- package/dist/src/enum-declarations.d.ts +6 -0
- package/dist/src/enum-declarations.js +2 -0
- package/dist/src/errors.d.ts +113 -0
- package/dist/src/errors.js +2 -0
- package/dist/src/extractor/directives.d.ts +5 -0
- package/dist/src/extractor/directives.js +2 -0
- package/dist/src/extractor/extract.d.ts +10 -0
- package/dist/src/extractor/extract.js +2 -0
- package/dist/src/extractor/hash.d.ts +1 -0
- package/dist/src/extractor/hash.js +2 -0
- package/dist/src/extractor/scanner.d.ts +32 -0
- package/dist/src/extractor/scanner.js +2 -0
- package/dist/src/extractor.d.ts +5 -0
- package/dist/src/extractor.js +2 -0
- package/dist/src/formats.d.ts +50 -0
- package/dist/src/formats.js +2 -0
- package/dist/src/formatter.d.ts +61 -0
- package/dist/src/formatter.js +2 -0
- package/dist/src/function-properties.d.ts +3 -0
- package/dist/src/function-properties.js +2 -0
- package/dist/src/generator.d.ts +18 -0
- package/dist/src/generator.js +2 -0
- package/dist/src/global-types.d.ts +17 -0
- package/dist/src/global-types.js +2 -0
- package/dist/src/import-sorter.d.ts +99 -0
- package/dist/src/import-sorter.js +2 -0
- package/dist/src/incremental.d.ts +103 -0
- package/dist/src/incremental.js +2 -0
- package/dist/src/index.d.ts +62 -0
- package/dist/src/index.js +2 -0
- package/dist/src/inferred-imports.d.ts +4 -0
- package/dist/src/inferred-imports.js +2 -0
- package/dist/src/json-config.d.ts +2 -0
- package/dist/src/json-config.js +2 -0
- package/dist/src/lexical.d.ts +6 -0
- package/dist/src/lexical.js +2 -0
- package/dist/src/logger.d.ts +57 -0
- package/dist/src/logger.js +2 -0
- package/dist/src/lsp.d.ts +333 -0
- package/dist/src/lsp.js +2 -0
- package/dist/src/memory.d.ts +127 -0
- package/dist/src/memory.js +2 -0
- package/dist/src/merger.d.ts +38 -0
- package/dist/src/merger.js +2 -0
- package/dist/src/module-graph.d.ts +70 -0
- package/dist/src/module-graph.js +2 -0
- package/dist/src/module-references.d.ts +30 -0
- package/dist/src/module-references.js +2 -0
- package/dist/src/native-checker.d.ts +55 -0
- package/dist/src/native-checker.js +2 -0
- package/dist/src/native-engine.d.ts +16 -0
- package/dist/src/native-engine.js +2 -0
- package/dist/src/native-extractor.d.ts +9 -0
- package/dist/src/native-extractor.js +2 -0
- package/dist/src/native-generation.d.ts +20 -0
- package/dist/src/native-generation.js +2 -0
- package/dist/src/native-project.d.ts +35 -0
- package/dist/src/native-project.js +2 -0
- package/dist/src/optimizer.d.ts +56 -0
- package/dist/src/optimizer.js +2 -0
- package/dist/src/output-normalizer.d.ts +123 -0
- package/dist/src/output-normalizer.js +2 -0
- package/dist/src/parallel-processor.d.ts +63 -0
- package/dist/src/parallel-processor.js +2 -0
- package/dist/src/parameters.d.ts +5 -0
- package/dist/src/parameters.js +2 -0
- package/dist/src/parser.d.ts +68 -0
- package/dist/src/parser.js +2 -0
- package/dist/src/plugins/bun.d.ts +58 -0
- package/dist/src/plugins/bun.js +2 -0
- package/dist/src/plugins/esbuild.d.ts +63 -0
- package/dist/src/plugins/esbuild.js +2 -0
- package/dist/src/plugins/index.d.ts +16 -0
- package/dist/src/plugins/index.js +2 -0
- package/dist/src/plugins/tsdown.d.ts +30 -0
- package/dist/src/plugins/tsdown.js +2 -0
- package/dist/src/plugins/tsup.d.ts +53 -0
- package/dist/src/plugins/tsup.js +2 -0
- package/dist/src/plugins/vite.d.ts +49 -0
- package/dist/src/plugins/vite.js +2 -0
- package/dist/src/plugins/webpack.d.ts +69 -0
- package/dist/src/plugins/webpack.js +2 -0
- package/dist/src/plugins.d.ts +88 -0
- package/dist/src/plugins.js +2 -0
- package/dist/src/process-source.d.ts +28 -0
- package/dist/src/process-source.js +2 -0
- package/dist/src/processor/cache.d.ts +18 -0
- package/dist/src/processor/cache.js +2 -0
- package/dist/src/processor/comments.d.ts +9 -0
- package/dist/src/processor/comments.js +2 -0
- package/dist/src/processor/declarations.d.ts +37 -0
- package/dist/src/processor/declarations.js +2 -0
- package/dist/src/processor/import-usage.d.ts +6 -0
- package/dist/src/processor/import-usage.js +2 -0
- package/dist/src/processor/imports.d.ts +68 -0
- package/dist/src/processor/imports.js +2 -0
- package/dist/src/processor/index.d.ts +33 -0
- package/dist/src/processor/index.js +2 -0
- package/dist/src/processor/type-inference.d.ts +116 -0
- package/dist/src/processor/type-inference.js +2 -0
- package/dist/src/processor.d.ts +5 -0
- package/dist/src/processor.js +2 -0
- package/dist/src/profiling.d.ts +114 -0
- package/dist/src/profiling.js +2 -0
- package/dist/src/return-type-scope.d.ts +3 -0
- package/dist/src/return-type-scope.js +2 -0
- package/dist/src/security.d.ts +100 -0
- package/dist/src/security.js +2 -0
- package/dist/src/source-cache.d.ts +16 -0
- package/dist/src/source-cache.js +2 -0
- package/dist/src/sourcemap.d.ts +137 -0
- package/dist/src/sourcemap.js +2 -0
- package/dist/src/stx.d.ts +20 -0
- package/dist/src/stx.js +2 -0
- package/dist/src/syntax-validator.d.ts +7 -0
- package/dist/src/syntax-validator.js +2 -0
- package/dist/src/tracking.d.ts +95 -0
- package/dist/src/tracking.js +2 -0
- package/dist/src/transformers.d.ts +188 -0
- package/dist/src/transformers.js +2 -0
- package/dist/src/tree-shaker.d.ts +69 -0
- package/dist/src/tree-shaker.js +2 -0
- package/dist/src/tsconfig.d.ts +8 -0
- package/dist/src/tsconfig.js +2 -0
- package/dist/src/type-mappings.d.ts +145 -0
- package/dist/src/type-mappings.js +2 -0
- package/dist/src/types.d.ts +230 -0
- package/dist/src/types.js +1 -0
- package/dist/src/utils.d.ts +63 -0
- package/dist/src/utils.js +2 -0
- package/dist/src/value-inference.d.ts +6 -0
- package/dist/src/value-inference.js +2 -0
- package/dist/src/vue.d.ts +108 -0
- package/dist/src/vue.js +2 -0
- package/dist/src/watcher.d.ts +64 -0
- package/dist/src/watcher.js +2 -0
- package/dist/src/worker-thread.d.ts +1 -0
- package/dist/src/worker-thread.js +2 -0
- package/dist/src/worker.d.ts +98 -0
- package/dist/src/worker.js +2 -0
- package/dist/src/workspace.d.ts +62 -0
- package/dist/src/workspace.js +2 -0
- package/native/README.md +6 -0
- package/native/darwin-arm64/libzig-dtsx.dylib +0 -0
- package/native/darwin-x64/libzig-dtsx.dylib +0 -0
- package/native/freebsd-x64/libzig-dtsx.so +0 -0
- package/native/linux-arm64/libzig-dtsx.so +0 -0
- package/native/linux-x64/libzig-dtsx.so +0 -0
- package/native/windows-x64/zig-dtsx.dll +0 -0
- package/package.json +120 -4
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
class Ft{config;memorySamples=[];cpuSamples=[];ioOperations=[];startTime=0;memoryInterval=null;cpuInterval=null;lastCpuUsage=null;isRunning=!1;constructor(e={}){this.config={memory:e.memory??!1,memoryLimit:e.memoryLimit??1024,cpu:e.cpu??!1,samplingInterval:e.samplingInterval??100,io:e.io??!1,trackOperations:e.trackOperations??["read","write"],outputFile:e.outputFile??""}}start(){if(this.isRunning)return;if(this.isRunning=!0,this.startTime=Date.now(),this.memorySamples=[],this.cpuSamples=[],this.ioOperations=[],this.lastCpuUsage=null,this.config.memory)this.sampleMemory(),this.memoryInterval=setInterval(()=>this.sampleMemory(),this.config.samplingInterval);if(this.config.cpu)this.sampleCpu(),this.cpuInterval=setInterval(()=>this.sampleCpu(),this.config.samplingInterval)}stop(){if(!this.isRunning)return;if(this.isRunning=!1,this.memoryInterval)clearInterval(this.memoryInterval),this.memoryInterval=null;if(this.cpuInterval)clearInterval(this.cpuInterval),this.cpuInterval=null}sampleMemory(){let e=y();this.memorySamples.push(e)}sampleCpu(){let e=d();if(this.lastCpuUsage){let t={timestamp:Date.now(),user:e.user-this.lastCpuUsage.user,system:e.system-this.lastCpuUsage.system,total:e.user-this.lastCpuUsage.user+(e.system-this.lastCpuUsage.system)};this.cpuSamples.push(t)}this.lastCpuUsage=e}recordIo(e,t,s,r){if(!this.config.io)return;if(!this.config.trackOperations.includes(e))return;this.ioOperations.push({timestamp:Date.now(),operation:e,path:t,size:s,durationMs:r})}getResults(){let e=Date.now(),t=[],s=this.memorySamples[0]||y(),r=0;for(let a of this.memorySamples){if(r+=a.heapUsed,a.heapUsed>s.heapUsed)s=a;let g=a.heapUsed/1048576;if(g>this.config.memoryLimit)t.push(`Memory limit exceeded at ${new Date(a.timestamp).toISOString()}: ${g.toFixed(2)}MB > ${this.config.memoryLimit}MB`)}let i=this.memorySamples.length>0?r/this.memorySamples.length:0,o=0,m=0;for(let a of this.cpuSamples)o+=a.user,m+=a.system;let u=0,l=0,p=0,h=0,c=0,f=0;for(let a of this.ioOperations)if(a.operation==="read")u++,p+=a.size,c+=a.durationMs;else l++,h+=a.size,f+=a.durationMs;return{startTime:this.startTime,endTime:e,durationMs:e-this.startTime,memory:{samples:this.memorySamples,peak:s,average:{timestamp:0,heapUsed:i,heapTotal:0,external:0,arrayBuffers:0,rss:0},warnings:t},cpu:{samples:this.cpuSamples,totalUser:o,totalSystem:m},io:{operations:this.ioOperations,totalReads:u,totalWrites:l,totalReadBytes:p,totalWriteBytes:h,totalReadMs:c,totalWriteMs:f}}}formatResults(){let e=this.getResults(),t=["=== Profiling Results ===",""];if(t.push(`Duration: ${e.durationMs}ms`),t.push(""),this.config.memory){if(t.push("Memory:"),t.push(` Samples: ${e.memory.samples.length}`),t.push(` Peak heap: ${n(e.memory.peak.heapUsed)}`),t.push(` Average heap: ${n(e.memory.average.heapUsed)}`),e.memory.warnings.length>0){t.push(" Warnings:");for(let s of e.memory.warnings)t.push(` - ${s}`)}t.push("")}if(this.config.cpu)t.push("CPU:"),t.push(` Samples: ${e.cpu.samples.length}`),t.push(` Total user time: ${(e.cpu.totalUser/1000).toFixed(2)}ms`),t.push(` Total system time: ${(e.cpu.totalSystem/1000).toFixed(2)}ms`),t.push("");if(this.config.io)t.push("I/O:"),t.push(` Total reads: ${e.io.totalReads}`),t.push(` Total writes: ${e.io.totalWrites}`),t.push(` Total read: ${n(e.io.totalReadBytes)} in ${e.io.totalReadMs.toFixed(2)}ms`),t.push(` Total write: ${n(e.io.totalWriteBytes)} in ${e.io.totalWriteMs.toFixed(2)}ms`),t.push("");return t.join(`
|
|
3
|
+
`)}async writeResults(){if(!this.config.outputFile)return;let e=this.getResults(),t=JSON.stringify(e,null,2);try{let s=await import("fs/promises");await s.writeFile(this.config.outputFile,t,"utf-8")}catch{await Bun.write(this.config.outputFile,t)}}}function y(){if(typeof process<"u"&&process.memoryUsage){let e=process.memoryUsage();return{timestamp:Date.now(),heapUsed:e.heapUsed,heapTotal:e.heapTotal,external:e.external,arrayBuffers:e.arrayBuffers||0,rss:e.rss}}return{timestamp:Date.now(),heapUsed:0,heapTotal:0,external:0,arrayBuffers:0,rss:0}}function d(){if(typeof process<"u"&&process.cpuUsage){let e=process.cpuUsage();return{user:e.user,system:e.system}}return{user:0,system:0}}function n(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],s=1024,r=Math.floor(Math.log(e)/Math.log(s));return`${Number.parseFloat((e/s**r).toFixed(2))} ${t[r]}`}function cr(e){return new Ft(e)}async function zi(e,t){let s=cr({memory:!0,cpu:!0,...t});s.start();try{return{result:await e(),profile:s.getResults()}}finally{s.stop()}}function Hi(e){return{async read(t,s){let r=Date.now();try{let i=await s(),o=typeof i==="string"?i.length:0;return e.recordIo("read",t,o,Date.now()-r),i}catch(i){throw e.recordIo("read",t,0,Date.now()-r),i}},async write(t,s,r){let i=Date.now();try{await s(),e.recordIo("write",t,r,Date.now()-i)}catch(o){throw e.recordIo("write",t,0,Date.now()-i),o}}}}class Lt{marks=new Map;durations=new Map;mark(e){this.marks.set(e,performance.now())}measure(e,t){let s=this.marks.get(t);if(s===void 0)throw Error(`Mark "${t}" not found`);let r=performance.now()-s,i=this.durations.get(e)||[];return i.push(r),this.durations.set(e,i),r}getDurations(e){return this.durations.get(e)||[]}getAverage(e){let t=this.getDurations(e);if(t.length===0)return 0;return t.reduce((s,r)=>s+r,0)/t.length}getSummary(){let e=new Map;for(let[t,s]of this.durations)e.set(t,{count:s.length,total:s.reduce((r,i)=>r+i,0),average:s.reduce((r,i)=>r+i,0)/s.length,min:Math.min(...s),max:Math.max(...s)});return e}clear(){this.marks.clear(),this.durations.clear()}}function Ki(){return new Lt}
|
|
4
|
+
export{Ft,cr,zi,Hi,Lt,Ki};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{t}from"./chunk-1j6092xz.js";import{Un,zn,Hn}from"./chunk-32qexm3w.js";import{De}from"./chunk-0rmbc5zp.js";import{Pe}from"./chunk-cv29b4zb.js";var Q=20,Y=!1,E=null;function _(e){return Ct(e).replace(/\n[ \t]*(?=\n)/g,"")}function Ct(e){if(e.indexOf("/*")===-1)return e.trim();let r=[],s=0,i=0,l=e.length;while(i<l)if(e.charCodeAt(i)===47&&i+1<l&&e.charCodeAt(i+1)===42){if(i>s)r.push(e.substring(s,i));i+=2;while(i<l-1){if(e.charCodeAt(i)===42&&e.charCodeAt(i+1)===47){i+=2;break}i++}s=i}else i++;if(s<l)r.push(e.substring(s));return r.join("").trim()}function Rt(){Y=!0,E=null}function Mt(){Y=!1;let e=E;return E=null,e}function ot(e){let c=e.length;if(c===0)return!1;let r=0;if(e.charCodeAt(r)===45)r++;if(r>=c)return!1;let s=r;while(r<c&&e.charCodeAt(r)>=48&&e.charCodeAt(r)<=57)r++;if(r===s)return!1;if(r<c&&e.charCodeAt(r)===46){r++;let i=r;while(r<c&&e.charCodeAt(r)>=48&&e.charCodeAt(r)<=57)r++;if(r===i)return!1}return r===c}function bt(e){for(let c=0,r=e.length-1;c<r;c++){let s=e.charCodeAt(c);if(s<48||s>57)return!1}return!0}function Z(e,c){let r=0,s=0;while((s=e.indexOf(c,s))!==-1)r++,s+=c.length;return r}function at(e){return e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||e===36||e===95||e===46||e===58||e===45}function z(e){let c=e.trim();if(c.length<3||c.charCodeAt(0)!==60)return!1;if(c.startsWith("<>"))return c.endsWith("</>");let r=c.charCodeAt(1);if(!(r>=65&&r<=90||r>=97&&r<=122||r===36||r===95))return!1;let i=2;while(i<c.length&&at(c.charCodeAt(i)))i++;let l=c.slice(1,i),f=c.charCodeAt(i);if(f>32&&f!==62&&f!==47)return!1;if(c.endsWith("/>"))return!0;let u=c.lastIndexOf("</");if(u===-1)return!1;let a=u+2;while(a<c.length&&at(c.charCodeAt(a)))a++;return c.slice(u+2,a)===l&&c.charCodeAt(a)===62&&a===c.length-1}function X(e){let c=e.length,r=!1;for(let f=1;f<c;f++)if(e.charCodeAt(f)<=32&&e.charCodeAt(f-1)<=32){r=!0;break}if(!r)for(let f=0;f<c;f++){let u=e.charCodeAt(f);if(u===10||u===13||u===9){r=!0;break}}if(!r)return e;let s=[],i=-1,l=!1;for(let f=0;f<c;f++)if(e.charCodeAt(f)<=32){if(!l){if(i>=0)s.push(e.substring(i,f));s.push(" "),l=!0,i=-1}}else{if(l||i<0)i=f;l=!1}if(i>=0)s.push(e.substring(i));return s.join("")}function n(e,c=!1,r=!1,s=0,i){if(!e||typeof e!=="string")return"unknown";if(s>=Q)return"unknown";let l=e.trim();if(z(l))return"JSX.Element";if(l.startsWith("BigInt("))return"bigint";if(l.startsWith("Symbol.for("))return"symbol";if(l.includes(".raw`")||l.includes("String.raw`"))return"string";if(l.startsWith("`")&&l.endsWith("`")){if(!c||l.includes("${")||l.includes(`
|
|
3
|
+
`)||l.includes("\r"))return"string";return l}if(l.charCodeAt(0)===39||l.charCodeAt(0)===34){let u=Tt(l);if(u!==null){if(u==="string"||!c)return"string";return u}}if(ot(l)){if(!c)return"number";return l}if(l==="true"||l==="false"){if(!c)return"boolean";return l}if(l==="null")return"null";if(l==="undefined")return"undefined";if(l.startsWith("[")&&l.endsWith("]"))return ke(l,c,s+1,i);if(l.startsWith("{")&&l.endsWith("}"))return et(l,c,s+1,i);if(l.startsWith("class ")||l.startsWith("class{"))return Ft(l);if(l.startsWith("new "))return Lt(l);if(l.endsWith("as const")){let u=l.slice(0,-8).trim();if(u.startsWith("[")&&u.endsWith("]")){let a=u.slice(1,-1).trim();if(!a)return"readonly []";let h=oe(a),p=[];for(let y=0;y<h.length;y++){let A=h[y].trim();if(A.startsWith("...")){let m=A.slice(3).trim();if(F(m))p.push(`...typeof ${m}`);else{let g=n(m,!0,!1,s+1,i);p.push(g.startsWith("readonly [")||g.endsWith("[]")?`...${g}`:"...unknown[]")}}else p.push(n(A,!0,!1,s+1,i))}return`readonly [${p.join(", ")}]`}return n(u,!0,r,s+1,i)}if(q(l)!==-1||l.startsWith("function")||l.startsWith("async"))return tt(l,r,s,c);if(l.startsWith("`")&&l.endsWith("`"))return Kt(l,c);if(l.startsWith("Promise."))return Wt(l,c,s,i);if(l.startsWith("await "))return"unknown";if(l.startsWith("typeof ")&&U(l.slice(7)))return"string";if(l.startsWith("void ")&&U(l.slice(5)))return"undefined";if(l.startsWith("delete ")&&U(l.slice(7)))return"boolean";if(l.charCodeAt(l.length-1)===110&&l.length>1&&bt(l)){if(c)return l;return"bigint"}if(l.startsWith("Symbol(")||l==="Symbol.for")return"symbol";let f=Te(l);if(f!==null)return f;if(At(l))return"boolean";if(It(l))return"number";return"unknown"}function ut(e){let c=e.charCodeAt(0);if(c!==39&&c!==34)return!1;return B(e,0,c)===e.length}function Tt(e){if(ut(e))return e;let c=kt(e);if(c.length<2)return null;let r=!1,s=!0,i="";for(let l of c){let f=l.trim();if(ut(f))r=!0,i+=St(f);else s=!1}if(s)return Pt(i);if(r)return"string";return null}function kt(e){let c=[],r=0,s=0,i=0;while(i<e.length){let l=e.charCodeAt(i);if(l===39||l===34||l===96){i=B(e,i,l);continue}if(l===40||l===91||l===123)r++;else if(l===41||l===93||l===125)r--;else if(l===43&&r===0)c.push(e.slice(s,i)),s=i+1;i++}return c.push(e.slice(s)),c}function St(e){return e.slice(1,-1).replace(/\\(.)/g,(r,s)=>{if(s==="n")return`
|
|
4
|
+
`;if(s==="t")return"\t";if(s==="r")return"\r";if(s==="0")return"\x00";return s})}function Pt(e){return`'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}'`}function It(e){if(e==="")return!1;let c=!1,r=!1;for(let s=0;s<e.length;s++){let i=e.charCodeAt(s);if(i>=48&&i<=57){c=!0;continue}if(i===43||i===45||i===42||i===47||i===37){r=!0;continue}if(i===46||i===40||i===41||i<=32)continue;return!1}return c&&r}function At(e){let c=0;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);if(s===34||s===39||s===96){r=B(e,r,s)-1;continue}if(s===40||s===91||s===123){c++;continue}if(s===41||s===93||s===125){c--;continue}if(c!==0)continue;if(e.startsWith("===",r)||e.startsWith("!==",r)||e.startsWith("==",r)||e.startsWith("!=",r)||e.startsWith(">=",r)||e.startsWith("<=",r))return!0;if((s===62||s===60)&&e.charCodeAt(r-1)!==61&&e.charCodeAt(r+1)!==61)return!0}return!1}function Ot(e,c=!1,r=0,s){return n(e,c,!0,r,s)}function I(e,c=!1,r="",s,i){let l=v(r,s),f=[],u=!1,a=0;while(a<e.length){let p=e.charCodeAt(a);if(p===34||p===39||p===96){a=B(e,a,p);continue}if(p===47&&e.charCodeAt(a+1)===47){a+=2;while(a<e.length&&e.charCodeAt(a)!==10&&e.charCodeAt(a)!==13)a++;continue}if(p===47&&e.charCodeAt(a+1)===42){let A=e.indexOf("*/",a+2);a=A===-1?e.length:A+2;continue}if(e.startsWith("function",a)&&G(e,a,8)||e.startsWith("class",a)&&G(e,a,5)){let A=Bt(e,a);if(A!==-1){a=H(e,A);continue}}if(p===61&&e.charCodeAt(a+1)===62){let A=wt(e,a+2);if(e.charCodeAt(A)===123){a=H(e,A);continue}}if(e.startsWith("return",a)&&(a===0||!R(e.charCodeAt(a-1)))&&!R(e.charCodeAt(a+6))){a+=6;let A=!1;while(a<e.length&&e.charCodeAt(a)<=32){let W=e.charCodeAt(a);if(W===10||W===13)A=!0;a++}if(A||a>=e.length||e.charCodeAt(a)===59||e.charCodeAt(a)===125){u=!0;continue}let m=a,g=0,C=0,d=0;while(a<e.length){let W=e.charCodeAt(a);if(W===34||W===39||W===96){a=B(e,a,W);continue}if(W===47&&e.charCodeAt(a+1)===47){if(g===0&&C===0&&d===0)break;while(a<e.length&&e.charCodeAt(a)!==10&&e.charCodeAt(a)!==13)a++;continue}if(W===47&&e.charCodeAt(a+1)===42){let b=e.indexOf("*/",a+2);a=b===-1?e.length:b+2;continue}if(W===40)g++;else if(W===41)g--;else if(W===91)C++;else if(W===93)C--;else if(W===123)d++;else if(W===125){if(d===0&&g===0&&C===0)break;d--}else if(W===59&&g===0&&C===0&&d===0)break;else if((W===10||W===13)&&g===0&&C===0&&d===0){let b=a+1;while(b<e.length&&e.charCodeAt(b)<=32)b++;if(e.startsWith("return",b)&&!R(e.charCodeAt(b+6)))break}a++}let w=e.slice(m,a).trim(),x=_(K(w,l,s,i,m));if(!f.includes(x))f.push(x);continue}a++}if(u&&!f.includes("undefined"))f.push("undefined");let h=f.includes("unknown")?"unknown":f.length===0?"void":yt(f);return c&&!h.startsWith("Promise<")?`Promise<${h}>`:h}function v(e,c){let r=new Map,s=e.startsWith("(")&&e.endsWith(")")?e.slice(1,-1):e,i=t(s),l=0,f=0,u=[];for(let a of i){let h=s.slice(a.start,a.end);if(h===","&&f===0)u.push(s.slice(l,a.start)),l=a.end;if(["(","[","{","<"].includes(h))f++;else if([")","]","}"].includes(h)||h===">"&&s[a.start-1]!=="=")f--}u.push(s.slice(l));for(let a of u){let h=t(a),p=-1,y=-1,A=0;for(let C of h){let d=a.slice(C.start,C.end);if(A===0&&d===":"&&p===-1)p=C.start;if(A===0&&d==="="&&a[C.end]!==">"){y=C.start;break}if(["(","[","{","<"].includes(d))A++;else if([")","]","}"].includes(d)||d===">"&&a[C.start-1]!=="=")A--}let m=a.slice(0,p!==-1?p:y!==-1?y:void 0).trim().replace(/^\.\.\./,"").replace(/\?$/,"");if(!J(m))continue;let g=p!==-1?a.slice(p+1,y!==-1?y:void 0).trim():"";if(!g&&y!==-1){let C=a.slice(y+1).trim();g=c?.(C)??n(C,!1)}if(g){if(y===-1&&a.slice(0,p).trim().endsWith("?"))g=`(${g}) | undefined`;r.set(m,g)}}return r}function Et(e,c){if(e=e.trim(),!e.startsWith("{")||!e.endsWith("}"))return;let r=e.slice(1,-1),s=t(r),i=0,l=0;for(let f=0;f<=s.length;f++){let u=s[f],a=u?r.slice(u.start,u.end):";";if(l===0&&(a===";"||a===",")){let h=r.slice(i,u?.start).trim(),p=h.indexOf(":");if(p!==-1&&h.slice(0,p).trim()===c)return h.slice(p+1).trim();i=u?.end??r.length}if(["(","[","{","<"].includes(a))l++;else if([")","]","}"].includes(a)||a===">"&&u&&r[u.start-1]!=="=")l--}return}function K(e,c,r,s,i=0,l=0){if(l>=Q)return"unknown";let f=e.trim();while(ct(f))f=f.slice(1,-1).trim();let u=r?.(f);if(u)return u;if(z(f))return"JSX.Element";if(f.startsWith("await ")){let d=K(f.slice(6),c,r,s,i,l+1);return d.startsWith("Promise<")&&d.endsWith(">")?d.slice(8,-1):d}if(c.has(f))return c.get(f);let a=/^([\w$]+)\.([\w$]+)$/.exec(f);if(a){let d=c.get(a[1]),w=d&&Et(d,a[2]);if(w)return w}if(f.startsWith("!"))return"boolean";if(f.startsWith("fetch("))return"Promise<Response>";if(Dt(f))return n(f,!1);let h=Nt(f);if(h){let d=K(h.whenTrue,c,r,s,i,l+1),w=K(h.whenFalse,c,r,s,i,l+1);return d===w?d:yt([d,w])}let p=jt(f);if(p&&s)return s(p,i);if(At(f))return"boolean";let y=0;for(let d=f.length-1;d>=0;d--){let w=f.charCodeAt(d);if(w===41||w===93||w===125)y++;else if(w===40||w===91||w===123)y--;else if(y===0&&(w===43||w===45||w===42||w===47||w===37)){let x=K(f.slice(0,d),c,r,s,i,l+1),W=K(f.slice(d+1),c,r,s,i,l+1);if(w===43&&(x==="string"||W==="string"))return"string";if(x==="number"&&W==="number")return"number";break}}let A=f.startsWith("{")&&f.endsWith("}")?et(f,!1,l+1,void 0,(d)=>K(d,c,r,s,i,l+1)):n(f,!1),m=t(A),g="",C=0;for(let d=0;d<m.length;d++){let w=m[d];if(w.kind!=="word"||A.slice(w.start,w.end)!=="typeof")continue;let x=m[d+1];if(!x||x.kind!=="word")continue;let W=c.get(A.slice(x.start,x.end)),b=!W,T=w.start,k=x.end,O=d;d++;while(m[d+1]&&A.slice(m[d+1].start,m[d+1].end)==="."&&m[d+2]?.kind==="word"){let L=m[d+2];if(!b)W=`(${W})["${A.slice(L.start,L.end)}"]`;k=L.end,d+=2}if(b&&O>=2&&A.slice(m[O-2].start,m[O-2].end)==="ReturnType"&&A.slice(m[O-1].start,m[O-1].end)==="<"&&m[d+1]&&A.slice(m[d+1].start,m[d+1].end)===">")T=m[O-2].start,k=m[++d].end;g+=A.slice(C,T)+(W??"unknown"),C=k}return g+A.slice(C)}function jt(e){let c=t(e),r=0,s=-1;for(let l=0;l<c.length;l++){let f=c[l],u=e.slice(f.start,f.end);if(f.kind!=="punctuation"&&f.kind!=="word")continue;if(["(","[","{"].includes(u))r++;else if([")","]","}"].includes(u))r--;else if(!r&&u==="as"&&l>0&&e.slice(c[l-1].start,c[l-1].end)!==".")s=l}if(s===-1||s+1===c.length)return;let i=e.slice(c[s].end).trim();if(i==="const")return;r=0;for(let l of c.slice(s+1)){if(l.kind!=="punctuation")continue;let f=e.slice(l.start,l.end);if(["(","[","{","<"].includes(f))r++;else if([")","]","}",">"].includes(f))r--;else if(!r&&["+","-","*","/","%","=","!",";"].includes(f))return}return i}function yt(e){return e.map((c)=>e.length>1&&q(c)!==-1?`(${c})`:c).join(" | ")}function ht(e){let c=0;while(c<e.length){let i=e.charCodeAt(c);if(i<=32)c++;else if(i===47&&e.charCodeAt(c+1)===47){c+=2;while(c<e.length&&e.charCodeAt(c)!==10&&e.charCodeAt(c)!==13)c++}else if(i===47&&e.charCodeAt(c+1)===42){let l=e.indexOf("*/",c+2);c=l===-1?e.length:l+2}else break}let r=c,s=c;while(s<e.length){let i=e.charCodeAt(s);if(i===34||i===39||i===96){s=B(e,s,i),r=s;continue}if(i===92){s=Math.min(s+2,e.length),r=s;continue}if(i===47&&e.charCodeAt(s+1)===47){while(s<e.length&&e.charCodeAt(s)!==10&&e.charCodeAt(s)!==13)s++;continue}if(i===47&&e.charCodeAt(s+1)===42){let l=e.indexOf("*/",s+2);s=l===-1?e.length:l+2;continue}if(s++,i>32)r=s}return e.slice(c,r)}function U(e){let c=0;for(let r=0;r<e.length;r++){let s=e[r];if(s==="'"||s==='"'||s==="`"){let i=r+1;while(i<e.length&&e[i]!==s){if(e[i]==="\\")i++;i++}r=i;continue}if(s==="("||s==="["||s==="{")c++;else if(s===")"||s==="]"||s==="}")c--;else if(c!==0)continue;else if(s==="?"){if(e[r+1]!==".")return!1}else if("=!<>&|+-*/%,:".includes(s))return!1;else if(s===" "||s==="\t"||s===`
|
|
5
|
+
`||s==="\r"){let i=e.slice(r).trimStart();if(i&&i[0]!=="."&&i[0]!=="?"&&i[0]!=="("&&i[0]!=="[")return!1}}return!0}function Dt(e){if(e.startsWith("function")&&G(e,0,8))return!0;let c=q(e);if(c===-1)return!1;let r=e.slice(0,c).trim();if(r.startsWith("async")&&G(r,0,5))r=r.slice(5).trim();if(r.startsWith("<")){let i=o(r,0,"<",">");if(i===-1)return!1;r=r.slice(i+1).trim()}if(r.startsWith("(")){let i=o(r,0,"(",")");if(i===-1)return!1;let l=r.slice(i+1).trim();if(l&&!l.startsWith(":"))return!1}let s=st(r);return ct(s.params)||J(s.params)}function ct(e){if(!e.startsWith("(")||!e.endsWith(")"))return!1;let c=0;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);if(s===40)c++;else if(s===41&&--c===0)return r===e.length-1}return!1}function Nt(e){let c=0,r=-1;for(let s=0;s<e.length;s++){let i=e.charCodeAt(s);if(i===34||i===39||i===96){s=B(e,s,i)-1;continue}if(i===47&&(e.charCodeAt(s+1)===47||e.charCodeAt(s+1)===42)){if(e.charCodeAt(s+1)===47)while(s+1<e.length&&e.charCodeAt(s+1)!==10&&e.charCodeAt(s+1)!==13)s++;else{let l=e.indexOf("*/",s+2);s=l===-1?e.length:l+1}continue}if(i===40||i===91||i===123)c++;else if(i===41||i===93||i===125)c--;else if(i===63&&c===0&&e.charCodeAt(s+1)!==63)r=s;else if(i===58&&c===0&&r!==-1)return{whenTrue:ht(e.slice(r+1,s)),whenFalse:ht(e.slice(s+1))}}return null}function G(e,c,r){return(c===0||!R(e.charCodeAt(c-1)))&&!R(e.charCodeAt(c+r))}function wt(e,c){let r=c;while(r<e.length){if(e.charCodeAt(r)<=32){r++;continue}if(e.startsWith("//",r)){while(r<e.length&&e.charCodeAt(r)!==10&&e.charCodeAt(r)!==13)r++;continue}if(e.startsWith("/*",r)){let s=e.indexOf("*/",r+2);r=s<0?e.length:s+2;continue}break}return r}function Bt(e,c){let r=0,s=0,i=0,l=!1,f=!1;for(let u=c;u<e.length;u++){if(u=wt(e,u),u>=e.length)break;let a=e.charCodeAt(u);if(a===34||a===39||a===96){u=B(e,u,a)-1,f=!1;continue}if(R(a)||a>=128){let h=u;while(u+1<e.length&&(R(e.charCodeAt(u+1))||e.charCodeAt(u+1)>=128))u++;f=l&&["keyof","typeof","readonly","unique","new","abstract","infer","extends"].includes(e.slice(h,u+1));continue}if(a===61&&e.charCodeAt(u+1)===62){u++,f=l;continue}if(a===40)r++;else if(a===41)r--,f=!1;else if(a===91)s++;else if(a===93)s--,f=!1;else if(a===60&&r===0&&s===0)i++;else if(a===62&&i>0&&r===0&&s===0)i--,f=!1;else if(a===123)if(r||s||i||l&&f)u=H(e,u)-1,f=!1;else return u;else if(r===0&&s===0&&i===0){if(a===58)l=!0,f=!0;else if(l&&[124,38,63].includes(a))f=!0;else if(a===59)return-1}}return-1}function H(e,c){let r=1,s=c+1;while(s<e.length&&r>0){let i=e.charCodeAt(s);if(i===34||i===39||i===96){s=B(e,s,i);continue}if(i===47&&e.charCodeAt(s+1)===47){s+=2;while(s<e.length&&e.charCodeAt(s)!==10&&e.charCodeAt(s)!==13)s++;continue}if(i===47&&e.charCodeAt(s+1)===42){let l=e.indexOf("*/",s+2);s=l===-1?e.length:l+2;continue}if(i===123)r++;else if(i===125)r--;s++}return s}function B(e,c,r){let s=c+1;while(s<e.length){let i=e.charCodeAt(s);if(i===92){s+=2;continue}if(r===96&&i===36&&e.charCodeAt(s+1)===123){s=H(e,s+1);continue}if(s++,i===r)break}return s}function Kt(e,c){if(e.includes(".raw`")||e.includes("String.raw`"))return"string";if(!c||e.includes("${")||e.includes(`
|
|
6
|
+
`)||e.includes("\r"))return"string";return e}function Lt(e){let c=4;while(c<e.length&&e.charCodeAt(c)<=32)c++;let r=c,s=e.charCodeAt(c);if(s<65||s>90)return"unknown";while(c<e.length&&(R(e.charCodeAt(c))||e.charCodeAt(c)===46))c++;if(c===r)return"unknown";let i=e.slice(r,c);{let l=e.slice(c),f=l;if(l.startsWith("<")){let a=0,h=-1;for(let p=0;p<l.length;p++)if(l[p]==="<")a++;else if(l[p]===">"){if(a--,a===0){h=p;break}}if(h!==-1){let p=l.slice(0,h+1);f=l.slice(h+1);let y=f.indexOf("(");if(y!==-1){let A=0,m=-1;for(let g=y;g<f.length;g++)if(f[g]==="(")A++;else if(f[g]===")"){if(A--,A===0){m=g;break}}if(m!==-1){if(f.slice(m+1).trimStart().startsWith("."))return"unknown"}}return`${i}${p}`}}let u=f.indexOf("(");if(u!==-1){let a=0,h=-1;for(let p=u;p<f.length;p++)if(f[p]==="(")a++;else if(f[p]===")"){if(a--,a===0){h=p;break}}if(h!==-1){if(f.slice(h+1).trimStart().startsWith("."))return"unknown"}}switch(i){case"Date":return"Date";case"Map":return"Map<any, any>";case"Set":return"Set<any>";case"WeakMap":return"WeakMap<any, any>";case"WeakSet":return"WeakSet<any>";case"RegExp":return"RegExp";case"Error":return"Error";case"Array":return"any[]";case"Object":return"object";case"Function":return"Function";case"Promise":return"Promise<any>";default:return i}}return"unknown"}function Ft(e){return"{ new (...args: any[]): any }"}function Wt(e,c,r=0,s){if(e.startsWith("Promise.resolve(")){let l=e.indexOf(")",16);if(l!==-1){let f=e.slice(16,l).trim();if(f)return`Promise<${n(f,c,!1,r+1,s)}>`}return"Promise<unknown>"}if(e.startsWith("Promise.reject("))return"Promise<never>";if(e.startsWith("Promise.all(")){let i=e.indexOf("[",12),l=e.lastIndexOf("]");if(i!==-1&&l>i){let f=e.slice(i+1,l).trim(),u=oe(f),a=[];for(let h=0;h<u.length;h++){let p=u[h].trim();if(p.startsWith("Promise.resolve(")){let y=Wt(p,c,r+1,s),A=y.indexOf("<"),m=y.lastIndexOf(">");a.push(A!==-1&&m>A?y.slice(A+1,m):"unknown")}else a.push(n(p,c,!1,r+1,s))}return`Promise<[${a.join(", ")}]>`}return"Promise<unknown[]>"}return"Promise<unknown>"}function ke(e,c,r=0,s){let i=e.slice(1,-1).trim();if(!i)return"never[]";if(r>=Q)return"unknown[]";let l=oe(i),f=!1;for(let m=0;m<l.length;m++){let g=l[m],C=g.length;while(C>0&&g.charCodeAt(C-1)<=32)C--;if(C>=8&&g.slice(C-8,C)==="as const"){f=!0;break}}if(f){let m=[];for(let g=0;g<l.length;g++){let C=l[g].trim();if(C.endsWith("as const")){let d=C.slice(0,-8).trim();if(d.startsWith("[")&&d.endsWith("]")){let w=d.slice(1,-1).trim(),x=oe(w),W=[];for(let b=0;b<x.length;b++)W.push(n(x[b].trim(),!0,!1,r+1,s));m.push(`readonly [${W.join(", ")}]`)}else m.push(n(d,!0,!1,r+1,s))}else if(C.startsWith("[")&&C.endsWith("]"))m.push(ke(C,!0,r+1,s));else m.push(n(C,!0,!1,r+1,s))}return`readonly [
|
|
7
|
+
${m.join(` |
|
|
8
|
+
`)}
|
|
9
|
+
]`}let u=Y&&!c,a=[],h=[];for(let m of l){let g=m.trim(),C=E;if(E=null,g.startsWith("...")){let d=g.slice(3).trim(),w=n(d,!1,!1,r+1,s);if(w.endsWith("[]"))a.push(w.slice(0,-2));else if(w.startsWith("readonly [")&&w.endsWith("]"))a.push(w.slice(10,-1));else if(F(d))a.push(`(typeof ${d})[number]`);else a.push("unknown")}else if(g.startsWith("[")&&g.endsWith("]"))a.push(ke(g,c,r+1,s));else a.push(Ot(g,c,r+1,s));if(u)h.push(E);E=C}if(u)if(rt(e))E=X(e);else{let m=[];for(let g=0;g<l.length;g++){let C=l[g].trim();if(C.endsWith("as const"))continue;if(nt(C)||C==="null"||C==="undefined")m.push(C);else if(C.startsWith("[")&&rt(C))m.push(X(C));else if(C.startsWith("{")){if(h[g])m.push(h[g])}else{let d=n(C,!1,!1,0,s);if(d!=="unknown")m.push(d)}}if(m.length>0)E=`[${m.join(", ")}]`}if(c)return`readonly [${a.join(", ")}]`;let p=new Set,y=[],A=!0;for(let m of a){if(!p.has(m))p.add(m),y.push(m);if(A){if(!(ot(m)||m==="true"||m==="false"||m.charCodeAt(0)===34&&m.charCodeAt(m.length-1)===34||m.charCodeAt(0)===39&&m.charCodeAt(m.length-1)===39))A=!1}}if(A&&a.length<=10)return`readonly [${a.join(", ")}]`;if(y.length===1)return`${y[0]}[]`;return`(${y.join(" | ")})[]`}function oe(e){let c=[],r=0,s=!1,i=0,l=-1,f=0;for(let u=0;u<e.length;u++){let a=e.charCodeAt(u);if(s){if(a===92)u++;else if(a===i)s=!1;f=u+1;continue}if(a===47&&e.charCodeAt(u+1)===47){let h=e.indexOf(`
|
|
10
|
+
`,u+2);u=(h===-1?e.length:h)-1;continue}if(a===47&&e.charCodeAt(u+1)===42){let h=e.indexOf("*/",u+2);u=(h===-1?e.length:h+2)-1;continue}if(a===32||a===9||a===10||a===13)continue;if(a===44&&r===0){if(l!==-1)c.push(e.slice(l,f));l=-1;continue}if(a===34||a===39||a===96)s=!0,i=a;else if(a===91||a===123||a===40)r++;else if(a===93||a===125||a===41)r--;if(l===-1)l=u;f=u+1}if(l!==-1)c.push(e.slice(l,f));return c}function nt(e){if(ot(e))return!0;if(e==="true"||e==="false")return!0;if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return!0;return!1}function qt(e){return e==="number"||e==="string"||e==="boolean"}function rt(e){let c=!1,r=0,s=e.length;for(let i=0;i<s;i++){let l=e.charCodeAt(i);if(c){if(l===92){i++;continue}if(l===r)c=!1;continue}if(l===34||l===39||l===96){c=!0,r=l;continue}if(l===61&&i+1<s&&e.charCodeAt(i+1)===62)return!1;if(l===47&&(e.charCodeAt(i+1)===47||e.charCodeAt(i+1)===42))return!1;if(l>=97&&l<=122){let f=i;while(i<s&&(e.charCodeAt(i)>=97&&e.charCodeAt(i)<=122||e.charCodeAt(i)>=65&&e.charCodeAt(i)<=90||e.charCodeAt(i)>=48&&e.charCodeAt(i)<=57||e.charCodeAt(i)===95||e.charCodeAt(i)===36))i++;let u=e.slice(f,i);if(u==="new"||u==="async"||u==="await"||u==="function"||u==="yield"||u==="console"||u==="process")return!1;let a=i;while(a<s&&e.charCodeAt(a)<=32)a++;if(a<s&&e.charCodeAt(a)===40)return!1;i--}}return!0}function et(e,c,r=0,s,i){let l=e.slice(1,-1).trim();if(!l)return"{}";if(r>=Q)return"Record<string, unknown>";let f=zt(l),u=new Set(f.flatMap(([d])=>{let w=mt(it(d).key);return w?.kind==="get"?[w.name]:[]})),a=[],h=[],p=[],y=!1,A=Y&&!c,m=[];for(let[d,w]of f){let{comments:x,key:W}=it(d),b=x?`${x}
|
|
11
|
+
`:"",T=mt(W);if(T&&Hn(T.name))continue;let k=W,O=!1;if(W==="..."){let P=w.trim(),N=F(P)?`typeof ${P}`:n(P,c,!1,r+1,s);if(N!=="unknown")h.push(N);if(A&&(F(P)||P.startsWith("{")))m.push(`...${X(P)}`);continue}let L=E;E=null;let S,D=w.trim();if(D===W&&J(D))S=(c?void 0:s?.mutableBindingTypes?.get(D))??`typeof ${D}`;else if(Qt(D)){O=!0;let P=Yt(W);if(P){k=P.name;let N="";if(D.startsWith("async "))N="async ";if(D.charCodeAt(N.length)===42)N+="*";S=pt(P.name,N+P.typeParams+D.slice(N.length))}else S=pt(W,D)}else{if(S=i?.(w)??n(w,c,!1,r+1,s),S==="unknown"&&F(D))S=(c?void 0:s?.mutableBindingTypes?.get(D))??`typeof ${D}`;if(S.includes("=>")||S.includes("function")||S.includes("async"))S=dt(S)}let ft=E;E=L;let $t=k,M=w.trim(),V=Un(k,s);if(!zn(T?.name??k,s)&&!(T?.kind==="set"&&u.has(T.name)))p.push(T?Ht(T.kind,S):S);if(V&&"index"in V)y=!0;else{if(V&&"name"in V)k=V.name;if(T){let P=Xt(T.kind,T.name,S);if(P){a.push(`${b}${P}`);continue}}if(!c&&qt(S)&&nt(M))a.push(`${b}/** @defaultValue ${Pe(M)} */
|
|
12
|
+
${k}: ${S}`);else a.push(`${b}${c?"readonly ":""}${k}: ${S}`)}if(A){let P=Ct($t);if(M.endsWith("as const"));else if(nt(M))m.push(`${P}: ${M}`);else if(M.startsWith("[")&&rt(M))m.push(`${P}: ${X(M)}`);else if(M.startsWith("{")){if(ft)m.push(`${P}: ${ft}`)}else if(O)m.push(`${P}: ${_(dt(S))}`);else if(!M.startsWith("[")&&(M.includes("=>")||M.startsWith("function")||M.startsWith("async"))){let N=tt(M,!1,0,!0);m.push(`${P}: ${_(N)}`)}}}if(A&&m.length>0){let d=r>0?(r-1)/2:0,w=`{ ${m.join(", ")} }`;if(w.length<=80)E=w;else{let x=" ".repeat((d+1)*2),W=" ".repeat(d*2);E=`{
|
|
13
|
+
${x}${m.join(`,
|
|
14
|
+
${x}`)}
|
|
15
|
+
${W}}`}}if(y&&h.length===0){let d=[...new Set(p)].map((w)=>w.includes("=>")||w.includes(" & ")?`(${w})`:w);a.unshift(`${c?"readonly ":""}[x: string]: ${d.join(" | ")}`)}let g=a.length>0?`{
|
|
16
|
+
${a.join(`;
|
|
17
|
+
`)}
|
|
18
|
+
}`:"{}";if(h.length===0)return g;let C=h[0];for(let d=1;d<h.length;d++)C=`Omit<${C}, keyof ${h[d]}> & ${h[d]}`;return a.length>0?`Omit<${C}, keyof ${g}> & ${g}`:C}function J(e){if(!e)return!1;let c=e.charCodeAt(0);if(!(c>=65&&c<=90||c>=97&&c<=122||c===95||c===36||c>127))return!1;for(let r=1;r<e.length;r++)if(!R(e.charCodeAt(r)))return!1;return!0}function F(e){let c=e.split(".");return c.length>0&&c.every(J)}function Vt(e){let c=!1,r="";for(let s=0;s<e.length;s++){let i=e[s];if(c){if(i==="\\")s++;else if(i===r)c=!1;continue}if(i==='"'||i==="'"||i==="`"){c=!0,r=i;continue}if(i==="(")return s;if(i==="<"){let l=o(e,s,"<",">");if(l!==-1)s=l}}return-1}function Te(e){if(e.length<3||!e.endsWith(")"))return null;let c=Vt(e);if(c===-1||o(e,c,"(",")")!==e.length-1)return null;let r=e.slice(0,c).trim(),s=!1;if(r.endsWith("?."))s=!0,r=r.slice(0,-2).trim();let i=r,l=!1,f=r.indexOf("<");if(f!==-1){if(o(r,f,"<",">")!==r.length-1)return null;i=r.slice(0,f).trim(),l=!0}if(!F(i))return null;let u=e.slice(c+1,-1).trim(),a=q(u)!==-1||u.startsWith("function")||u.startsWith("async function"),h=F(u),p=!a&&u.endsWith(")")&&Te(u)!==null,y=i.indexOf(".");if(y!==-1){if(i.indexOf(".",y+1)!==-1)return null}else if(!l&&!s&&!a&&!h&&!p)return null;let A=`ReturnType<typeof ${r}>`;return s?`${A} | undefined`:A}function dt(e){let r=e.split(`
|
|
19
|
+
`).map((p)=>xt(p)).join(`
|
|
20
|
+
`),s=r.indexOf("async");if(s!==-1){let p=s>0?r.charCodeAt(s-1):32,y=s+5<r.length?r.charCodeAt(s+5):32;if(!R(p)&&!R(y))r=(r.slice(0,s)+r.slice(s+5)).trim()}let i=r.indexOf("(");if(i!==-1){let p=o(r,i,"(",")");if(p!==-1){let y=r.slice(i,p+1),A=ae(y);r=r.slice(0,i)+A+r.slice(p+1)}}let l=r.length,f="",u=[],a=!1,h=!1;for(let p=0;p<l;p++){let y=r.charCodeAt(p);if(y===123||y===40)u.push(y);else if(y===125||y===41)u.pop();if(y<=32){if(a=!0,y===10||y===13)h=!0;continue}if(a&&f.length>0){let m=(u.length>0?u[u.length-1]:0)===123;if(h&&m){let g=f.charCodeAt(f.length-1),C=g===59||g===44||g===123||y===125,d=f.length>=2&&f.charCodeAt(f.length-1)===47&&f.charCodeAt(f.length-2)===42;if(!C&&!d)f+="; ";else f+=" "}else f+=" "}a=!1,h=!1,f+=r[p]}return f.trim()}function R(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95||e===36}function ae(e){let c=e.trim(),r,s=!1;if(c.startsWith("(")&&c.endsWith(")"))r=c.slice(1,-1),s=!0;else r=c;let i=r.trim();if(!i)return s?"()":"";let l=!1;{let g=0;for(let C=0;C<i.length;C++){let d=i.charCodeAt(C);if(d===40||d===60||d===91||d===123)g++;else if(d===41||d===93||d===125||d===62&&i.charCodeAt(C-1)!==61)g--;else if(g===0&&d===61){let w=C>0?i.charCodeAt(C-1):0,x=C+1<i.length?i.charCodeAt(C+1):0;if(w!==61&&w!==33&&w!==60&&w!==62&&x!==61&&x!==62){l=!0;break}}}}if(!l)return c;let f=[],u=[],a=0,h=0,p=!1,y=0;for(let g=0;g<=i.length;g++){if(g===i.length){f.push(i.slice(a));break}let C=i.charCodeAt(g);if(p){if(C===92){g++;continue}if(C===y)p=!1;continue}if(C===47&&g+1<i.length){let d=i.charCodeAt(g+1);if(d===42){g+=2;while(g+1<i.length&&!(i.charCodeAt(g)===42&&i.charCodeAt(g+1)===47))g++;g++;continue}if(d===47){while(g<i.length&&i.charCodeAt(g)!==10)g++;continue}}if(C===39||C===34||C===96){p=!0,y=C;continue}if(C===40||C===60||C===91||C===123)h++;else if(C===41||C===93||C===125||C===62&&i.charCodeAt(g-1)!==61)h--;else if(C===44&&h===0){f.push(i.slice(a,g));let d=",",w=g+1;while(w<i.length&&i.charCodeAt(w)<=32)d+=i[w],w++;u.push(d),a=w}}let A=[];for(let g of f){let C=g.trim();if(!C){A.push(g);continue}if(C.startsWith("//"))continue;let d=xt(C),w=g.slice(0,g.length-g.trimStart().length);A.push(w+Gt(d))}let m=A[0]||"";for(let g=1;g<A.length;g++)m+=(u[g-1]||", ")+A[g];return De(s?`(${m})`:m)}function xt(e){let c=!1,r=0;for(let s=0;s<e.length-1;s++){let i=e.charCodeAt(s);if(c){if(i===92){s++;continue}if(i===r)c=!1;continue}if(i===39||i===34||i===96){c=!0,r=i;continue}if(i===47&&e.charCodeAt(s+1)===47)return e.slice(0,s).trimEnd()}return e}function Gt(e){if(e.startsWith("..."))return e;let c=-1,r=-1,s=0,i=!1,l=0;for(let u=0;u<e.length;u++){let a=e.charCodeAt(u);if(i){if(a===92){u++;continue}if(a===l)i=!1;continue}if(a===47&&u+1<e.length){let h=e.charCodeAt(u+1);if(h===42){u+=2;while(u+1<e.length&&!(e.charCodeAt(u)===42&&e.charCodeAt(u+1)===47))u++;u++;continue}if(h===47){while(u<e.length&&e.charCodeAt(u)!==10)u++;continue}}if(a===39||a===34||a===96){i=!0,l=a;continue}if(a===40||a===60||a===91||a===123)s++;else if(a===41||a===93||a===125||a===62&&e.charCodeAt(u-1)!==61)s--;else if(s===0){if(a===58&&c===-1)c=u;else if(a===61&&r===-1&&(u===0||e.charCodeAt(u-1)!==61)&&(u+1>=e.length||e.charCodeAt(u+1)!==61&&e.charCodeAt(u+1)!==62))r=u}}let f=r!==-1;if(c!==-1&&(r===-1||c<r)){let u=e.slice(0,c).trim(),a=r!==-1?e.slice(c+1,r).trim():e.slice(c+1).trim(),h=f&&!u.endsWith("?")?"?":"";return`${u}${h}: ${a}`}else if(r!==-1){let u=e.slice(0,r).trim(),a=!u.endsWith("?")?"?":"",h=e.slice(r+1).trim(),p="unknown";if(h==="true"||h==="false")p="boolean";else if(/^-?\d+(\.\d+)?$/.test(h))p="number";else if(h.startsWith("'")&&h.endsWith("'")||h.startsWith('"')&&h.endsWith('"'))p="string";else if(h.startsWith("["))p="unknown[]";else if(h.startsWith("{"))p="Record<string, unknown>";return`${u}${a}: ${p}`}return e}function Jt(e){let c=0,r=e.length;while(c<r){while(c<r&&(e.charCodeAt(c)===32||e.charCodeAt(c)===9||e.charCodeAt(c)===10||e.charCodeAt(c)===13))c++;if(c+1<r&&e.charCodeAt(c)===47&&e.charCodeAt(c+1)===42){c+=2;while(c+1<r&&!(e.charCodeAt(c)===42&&e.charCodeAt(c+1)===47))c++;c+=2;continue}break}return c}function it(e){let c=[],r=0,s=e.length;while(r<s){while(r<s&&e.charCodeAt(r)<=32)r++;if(r+1>=s||e.charCodeAt(r)!==47||e.charCodeAt(r+1)!==42)break;let i=r;r+=2;while(r+1<s&&!(e.charCodeAt(r)===42&&e.charCodeAt(r+1)===47))r++;r=Math.min(r+2,s),c.push(e.slice(i,r).trim())}return{comments:c.join(`
|
|
21
|
+
`),key:e.slice(r).trim()}}function zt(e){let c=[],r="",s="",i=0,l=!1,f="",u=!0,a=!1,h=0,p=!1,y=!1,A=0,m=!1,g=!1;for(let C=0;C<e.length;C++){let d=e.charCodeAt(C),w=C>0?e.charCodeAt(C-1):0,x=C<e.length-1?e.charCodeAt(C+1):0;if(!l&&!a&&d===47&&x===47){r=r.replace(/[ \t]+$/,""),C+=2;while(C<e.length&&e.charCodeAt(C)!==10)C++;C--;continue}if(!l&&!a&&d===47&&x===42){a=!0,h=1,r+="/*",C++;continue}else if(a&&d===42&&x===47){if(h--,r+="*/",C++,h===0)a=!1;continue}else if(a&&d===47&&x===42){h++,r+="/*",C++;continue}let W=e[C];if(!l&&!a&&(d===34||d===39||d===96))l=!0,f=W,r+=W;else if(l&&W===f&&w!==92)l=!1,r+=W;else if(!l&&!a)if(d===40&&i===0&&u&&A===0){s=r.trim();let b=Jt(s),T=b>0?s.slice(0,b):"",k=s.slice(b),O="";if(k.startsWith("async ")||k.startsWith("async\t")||k.startsWith(`async
|
|
22
|
+
`))k=k.slice(6).trimStart(),O="async ";if(k.startsWith("*"))k=k.slice(1).trimStart(),O+="*";s=T+k,r=O+W,u=!1,m=!0,g=!1,i=1}else if(d===123||d===91||d===40){if(i++,r+=W,g&&d===123)g=!1}else if(d===125||d===93||d===41){if(i--,r+=W,d===41&&i===0&&!u&&!m)p=!0;if(m){if(d===41&&i===0&&!g)g=!0;else if(d===125&&i===0)m=!1,g=!1}}else if(d===58&&i===0&&u&&A===0)s=r.trim(),r="",u=!1;else if(d===58&&i===0&&p)y=!0,r+=W;else if(d===60&&y)A++,r+=W;else if(d===60&&u&&i===0)A++,r+=W;else if(d===62&&A>0&&w!==61)A--,r+=W;else if(d===61&&x===62&&y&&A===0)y=!1,p=!1,r+=W;else if(d===44&&i===0&&A===0&&!g){if(s&&r.trim()){let b=r.trim();c.push([s,b])}else if(u&&r.trim())gt(c,r.trim());r="",s="",u=!0,p=!1,y=!1,A=0}else r+=W;else r+=W}if(s&&r.trim()){let C=r.trim();c.push([s,C])}else if(u&&r.trim())gt(c,r.trim());return c}function gt(e,c){let{comments:r,key:s}=it(c);if(J(s))e.push([r?`${r}
|
|
23
|
+
${s}`:s,s]);else if(s.startsWith("...")&&s.length>3)e.push(["...",s.slice(3).trim()])}function mt(e){let c=e.trim();if(c.startsWith("get ")&&c.length>4){let r=c.slice(4).trim();if(r)return{kind:"get",name:r}}if(c.startsWith("set ")&&c.length>4){let r=c.slice(4).trim();if(r)return{kind:"set",name:r}}return null}function Xt(e,c,r){let s=r.trim();if(s.charCodeAt(0)!==40)return null;let i=o(s,0,"(",")");if(i===-1)return null;let l=s.slice(1,i).trim(),f=s.slice(i+1).trimStart();if(!f.startsWith("=>"))return null;let u=f.slice(2).trim();if(e==="get")return`get ${c}(): ${u||"unknown"}`;return`set ${c}(${l})`}function Ht(e,c){let r=c.trim(),s=o(r,0,"(",")");if(!r.startsWith("(")||s===-1)return"unknown";if(e==="get"){let u=r.slice(s+1).trim();return u.startsWith("=>")?u.slice(2).trim():"unknown"}let i=r.slice(1,s).trim(),l=i.startsWith("{")?o(i,0,"{","}"):i.startsWith("[")?o(i,0,"[","]"):0,f=i.indexOf(":",Math.max(0,l));return f===-1?"unknown":i.slice(f+1).trim()}function Qt(e){let c=e;if(c.startsWith("async ")||c.startsWith("async\t"))c=c.slice(5).trimStart();if(c.startsWith("*"))c=c.slice(1).trimStart();if(!c.startsWith("("))return!1;let r=0;for(let s=0;s<c.length;s++){let i=c.charCodeAt(s);if(i===40)r++;else if(i===41){if(r--,r===0){let l=c.slice(s+1).trimStart();if(l.startsWith("{"))return!0;if(l.startsWith(":")){let f=lt(l,1);if(f?.kind==="arrow")return!1;if(f?.kind==="body")return!0}return!1}}}return!1}function Yt(e){let c=e.trimEnd();if(!c.endsWith(">"))return null;let r=0,s=-1;for(let l=c.length-1;l>=0;l--){let f=c.charCodeAt(l);if(f===62){if(l>0&&c.charCodeAt(l-1)===61)continue;r++}else if(f===60){if(r--,r===0){s=l;break}}}if(s===-1)return null;let i=c.slice(0,s).trimEnd();if(!i)return null;return{name:i,typeParams:c.slice(s)}}function pt(e,c){let r=c.trimStart(),s=!1,i=!1;if(r.startsWith("async ")||r.startsWith("async\t"))s=!0,r=r.slice(5).trimStart();if(r.startsWith("*"))i=!0,r=r.slice(1).trimStart();let l="";if(r.charCodeAt(0)===60){let A=0,m=-1;for(let g=0;g<r.length;g++)if(r.charCodeAt(g)===60)A++;else if(r.charCodeAt(g)===62&&!(g>0&&r.charCodeAt(g-1)===61)){if(A--,A===0){m=g;break}}if(m!==-1)l=r.slice(0,m+1),r=r.slice(m+1).trimStart()}let f=r.indexOf("("),u=o(r,f,"(",")");if(f===-1||u===-1)return"() => unknown";let a=r.slice(f,u+1),h="unknown",p=r.slice(u+1).trimStart();if(p.charCodeAt(0)===58){let A=p.slice(1),m=lt(A,0);if(m)h=A.slice(0,m.index).trim();else h=A.trim()}if(h==="unknown"&&!i&&p.charCodeAt(0)===123){let A=o(p,0,"{","}");if(A!==-1){let m=I(p.slice(1,A),s,a);if(m!=="unknown"&&m!=="Promise<unknown>")h=s&&m.startsWith("Promise<")?m.slice(8,-1):m;else if(s)h="Promise<unknown>"}}if(h==="unknown"){if(s&&i)h="AsyncGenerator<unknown, void, unknown>";else if(i)h="Generator<unknown, void, unknown>";else if(s)h="Promise<void>"}else if(s&&!h.startsWith("Promise<")&&!h.startsWith("AsyncGenerator<"))h=`Promise<${h}>`;let y=ae(a);return`${l}${y} => ${h}`}function lt(e,c){let r=0,s=0,i=0,l=0,f=!1,u=0;for(let a=c;a<e.length;a++){let h=e.charCodeAt(a);if(f){if(h===92)a++;else if(h===u)f=!1;continue}if(h===34||h===39||h===96){f=!0,u=h;continue}if(h===40)r++;else if(h===41&&r>0)r--;else if(h===91)s++;else if(h===93&&s>0)s--;else if(h===60)i++;else if(h===62&&i>0&&e.charCodeAt(a-1)!==61)i--;else if(h===125&&l>0)l--;else if(h===123){let p=r>0||s>0||i>0||l>0,y=e.slice(c,a).trimEnd(),A=y.charCodeAt(y.length-1),m=y.length===0||A===38||A===124||A===40||A===44||A===58||A===61||A===91;if(p||m)l++;else return{index:a,kind:"body"}}else if(h===61&&a+1<e.length&&e.charCodeAt(a+1)===62&&r===0&&s===0&&i===0&&l===0)return{index:a,kind:"arrow"}}return null}function o(e,c,r,s){let i=0;for(let l=c;l<e.length;l++)if(e[l]===r)i++;else if(e[l]===s){if(s===">"&&l>0&&e[l-1]==="=")continue;if(i--,i===0)return l}return-1}function q(e){let c=0,r=0,s=!1,i="";for(let l=0;l<e.length-1;l++){let f=e[l],u=e[l+1],a=l>0?e[l-1]:"";if(!s&&(f==='"'||f==="'"||f==="`"))s=!0,i=f;else if(s&&f===i&&a!=="\\")s=!1;if(!s){if(f==="<"){let h=o(e,l,"<",">");if(h!==-1){l=h;continue}}if(f==="(")c++;else if(f===")")c--;else if(f==="[")r++;else if(f==="]")r--;if(f==="="&&u===">"&&c===0&&r===0)return l}}return-1}function tt(e,c=!1,r=0,s=!0){let i=e.trim();if(i.length>200&&Z(i,"=>")>2&&Z(i,"<")>5&&!i.startsWith("function"))return c?"((...args: any[]) => any)":"(...args: any[]) => any";if(i.startsWith("async ")&&i.includes("=>")){let f=i.slice(5).trim(),u=q(f);if(u===-1)return c?"(() => Promise<unknown>)":"() => Promise<unknown>";let a=f.substring(0,u).trim(),h=f.substring(u+2).trim(),p=st(a),{params:y,returnType:A}=p;if(y=ae(y),y==="()"||y==="")y="()";else if(!y.startsWith("("))y=`(${y})`;let m=A;if(m);else if(h.startsWith("{"))m=I(h.slice(1,h.endsWith("}")?-1:void 0),!0,p.params);else m=K(h,v(p.params));let g=`${y} => ${A||m.startsWith("Promise<")?m:`Promise<${m}>`}`;return c?`(${g})`:g}if(i.includes("=>")){let f="",u=i;if(i.startsWith("<")){let d=o(i,0,"<",">");if(d!==-1)f=i.substring(0,d+1),u=i.substring(d+1).trim()}let a=q(u);if(a===-1)return c?"(() => unknown)":"() => unknown";let h=u.substring(0,a).trim(),p=u.substring(a+2).trim(),y=st(h),{params:A,returnType:m}=y;if(A=ae(A),A==="()"||A==="")A="()";else if(!A.startsWith("("))A=`(${A})`;let g="unknown";if(m)g=m;else if(p.startsWith("{"))g=I(p.slice(1,p.endsWith("}")?-1:void 0),!1,y.params);else if(z(p)||ct(p)&&z(p.slice(1,-1).trim()))g="JSX.Element";else if(p.includes("=>")){let d=p.trimStart(),w=d.indexOf("("),x=w!==-1?o(d,w,"(",")"):-1,W=x!==-1?d.indexOf("=>",x):-1;if(w===0&&x!==-1&&W!==-1){let b=d.substring(w+1,x).trim(),T=ae(b);if(f.includes("T")&&T.includes("T"))g=`(${T}) => T`;else g=`(${T}) => any`}else g="any"}else g=K(p,v(y.params));let C=`${f}${A} => ${g}`;return c?`(${C})`:C}if(i.startsWith("function")){let f=8,u=i.length;while(f<u&&i.charCodeAt(f)<=32)f++;let a=!1;if(f<u&&i.charCodeAt(f)===42){a=!0,f++;while(f<u&&i.charCodeAt(f)<=32)f++}let h="";if(f<u&&i.charCodeAt(f)===60){let A=f,m=1;f++;while(f<u&&m>0){let g=i.charCodeAt(f);if(g===60)m++;else if(g===62&&i.charCodeAt(f-1)!==61)m--;f++}h=i.substring(A,f);while(f<u&&i.charCodeAt(f)<=32)f++}let p=i.indexOf("(",f);if(p!==-1){let A=1,m=p+1;while(m<u&&A>0){let W=i.charCodeAt(m);if(W===40)A++;else if(W===41)A--;m++}let g=i.substring(p+1,m-1).trim(),C=g?ae(`(${g})`):"()";if(a){let W=i.substring(m).trim(),b=W.indexOf("Generator<");if(b!==-1){let k=b+10,O=W.indexOf(">",k);if(O!==-1){let L=W.substring(k,O),S=`${h}${C} => Generator<${L}>`;return c?`(${S})`:S}}let T=`${h}${C} => Generator<any, any, any>`;return c?`(${T})`:T}let d="unknown",w=i.substring(m).trimStart();if(w.charCodeAt(0)===58){let W=w.slice(1),b=lt(W,0),T=(b?W.slice(0,b.index):W).trim();if(T)d=T}let x=`${h}${C} => ${d}`;return c?`(${x})`:x}let y="(...args: any[]) => unknown";return c?`(${y})`:y}if(i.includes("=>")&&i.includes("(")&&i.includes(")")){if(i.length>100||Z(i,"=>")>2){let f="";if(i.charCodeAt(0)===60){let y=o(i,0,"<",">");if(y!==-1)f=i.substring(0,y+1)}let u=i.indexOf("("),a=u!==-1?o(i,u,"(",")"):-1,h=u!==-1&&a!==-1?i.substring(u,a+1):"(...args: any[])";h=ae(h);let p=`${f}${h} => any`;return c?`(${p})`:p}return c?`(${i})`:i}let l="() => unknown";return c?`(${l})`:l}function st(e){let c=e.trim();if(!c.startsWith("("))return{params:c,returnType:""};let r=o(c,0,"(",")");if(r===-1)return{params:c,returnType:""};let s=c.slice(r+1).trim();return{params:c.slice(0,r+1),returnType:s.startsWith(":")?s.slice(1).trim():""}}function Ae(e){let c=e.trim();if(c==="any"||c==="object"||c==="unknown")return!0;if(c.startsWith("Record<")&&c.endsWith(">"))return!0;if(c.startsWith("Array<")&&c.endsWith(">"))return!0;if(/^\{\s*\[[^\]]*\]:\s*(any|string|number|unknown)\s*\}$/.test(c))return!0;return!1}function j(e){let c=-1,r=0;for(let i=0;i<e.length;i++){let l=e.charCodeAt(i);if(l===34||l===39||l===96){i=B(e,i,l)-1;continue}if(l===47&&e.charCodeAt(i+1)===47){while(i<e.length&&e.charCodeAt(i)!==10)i++;continue}if(l===47&&e.charCodeAt(i+1)===42){let f=e.indexOf("*/",i+2);i=f===-1?e.length:f+1;continue}if(l===47){let f=i-1;while(f>=0&&e.charCodeAt(f)<=32)f--;if(f<0||"([{:;,=!?&|+*-~>".includes(e[f])){let u=!1;for(i++;i<e.length;i++){let a=e.charCodeAt(i);if(a===92)i++;else if(a===91)u=!0;else if(a===93)u=!1;else if(a===47&&!u)break}continue}}if(l===40||l===91||l===123)r++;else if(l===41||l===93||l===125)r--;else if(r===0&&e.startsWith("satisfies",i)&&G(e,i,9)&&e[i-1]!==".")c=i}if(c===-1)return null;let s=e.slice(c+9).trim();if(s.endsWith(";"))s=s.slice(0,-1).trim();return s||null}function Ta(e){let c=e.trim(),r=c.match(/^\{\s*\[(\w+)\s+in\s+(.+?)\](\?)?\s*:\s*(.+)\s*\}$/);if(r){let[,l,f,u,a]=r;return`{ [${l} in ${f}]${u?"?":""}: ${a} }`}let s=c.match(/^\{\s*readonly\s+\[(\w+)\s+in\s+(.+?)\](\?)?\s*:\s*(.+)\s*\}$/);if(s){let[,l,f,u,a]=s;return`{ readonly [${l} in ${f}]${u?"?":""}: ${a} }`}let i=c.match(/^\{\s*(-?readonly\s+)?\[(\w+)\s+in\s+(.+?)\](-?\?)?\s*:\s*(.+)\s*\}$/);if(i){let[,l,f,u,a,h]=i;return`{ ${l?`${l.trim()} `:""}[${f} in ${u}]${a||""}: ${h} }`}return null}function Aa(e){let c=e.trim(),r=c.indexOf(" extends ");if(r===-1)return null;let s=c.slice(r+9),i=Zt(s);if(i===-1)return null;let l=Ut(s,i);if(l===-1)return null;let f=c.slice(0,r).trim(),u=s.slice(0,i).trim(),a=s.slice(i+1,l).trim(),h=s.slice(l+1).trim();return`${f} extends ${u} ? ${a} : ${h}`}function Zt(e){let c=0,r=!1,s="";for(let i=0;i<e.length;i++){let l=e[i],f=i>0?e[i-1]:"";if(!r&&(l==='"'||l==="'"||l==="`"))r=!0,s=l;else if(r&&l===s&&f!=="\\")r=!1;if(!r){if(l==="<"||l==="("||l==="["||l==="{")c++;if(l===">"||l===")"||l==="]"||l==="}")c--;if(l==="?"&&c===0)return i}}return-1}function Ut(e,c){let r=0,s=!1,i="";for(let l=c+1;l<e.length;l++){let f=e[l],u=l>0?e[l-1]:"";if(!s&&(f==='"'||f==="'"||f==="`"))s=!0,i=f;else if(s&&f===i&&u!=="\\")s=!1;if(!s){if(f==="<"||f==="("||f==="["||f==="{")r++;if(f===">"||f===")"||f==="]"||f==="}")r--;if(f==="?"&&r===0)r++;if(f===":"&&r===0)return l;if(f===":"&&r>0)r--}}return-1}function Pa(e){let c=e.trim();if(!c.startsWith("`")||!c.endsWith("`"))return null;let r=c.slice(1,-1);if(!r.includes("${"))return c;let s=[],i="",l=0;while(l<r.length)if(r[l]==="$"&&r[l+1]==="{"){if(i)s.push(`"${i}"`),i="";let f=1,u="";l+=2;while(l<r.length&&f>0){if(r[l]==="{")f++;if(r[l]==="}")f--;if(f>0)u+=r[l];l++}s.push(u.trim())}else i+=r[l],l++;if(i)s.push(`"${i}"`);return c}function Da(e){let c=[],r=/infer\s+(\w+)/g,s;while((s=r.exec(e))!==null)c.push(s[1]);return c}function Ra(e){let r=e.trim(),s=r.indexOf("[");if(s!==-1){if(r.indexOf(" in ",s)!==-1)return!0}let i=r.indexOf(" extends ");if(i!==-1){let f=r.indexOf(" ? ",i);if(f!==-1&&r.indexOf(" : ",f)!==-1)return!0}if(r.charCodeAt(0)===96&&r.charCodeAt(r.length-1)===96){if(r.indexOf("${")!==-1)return!0}let l=r.indexOf("infer ");if(l!==-1){if(l===0||!R(r.charCodeAt(l-1)))return!0}return!1}function Ma(e,c=3){let r=e.trim(),s=0,i=0;for(let l of r){if(l==="<"||l==="("||l==="["||l==="{")s++,i=Math.max(i,s);if(l===">"||l===")"||l==="]"||l==="}")s--}if(i>c){let l=r.match(/^(\w+)</);if(l)return`${l[1]}<any>`;return"unknown"}return r}function Oa(e){let r=e.trim().match(/^(\w+)<(.+)>$/);if(!r)return null;let s=r[1],i=r[2],l=ca(i);if(["Partial","Required","Readonly","Pick","Omit","Record","Exclude","Extract","NonNullable","ReturnType","Parameters","ConstructorParameters","InstanceType","ThisParameterType","OmitThisParameter","ThisType","Uppercase","Lowercase","Capitalize","Uncapitalize","Awaited","NoInfer"].includes(s))return{name:s,params:l};return null}function ca(e){let c=[],r="",s=0,i=!1,l="";for(let f=0;f<e.length;f++){let u=e[f],a=f>0?e[f-1]:"";if(!i&&(u==='"'||u==="'"||u==="`"))i=!0,l=u;else if(i&&u===l&&a!=="\\")i=!1;if(!i){if(u==="<"||u==="("||u==="["||u==="{")s++;if(u===">"||u===")"||u==="]"||u==="}")s--;if(u===","&&s===0){c.push(r.trim()),r="";continue}}r+=u}if(r.trim())c.push(r.trim());return c}function Ia(e){let c=e.trim();if(c.startsWith("keyof "))return c;return null}function Fa(e){let c=e.trim();if(c.startsWith("typeof "))return c;return null}function La(e){let c=e.trim();if(c.length===0||c.charCodeAt(0)===91)return!1;if(c.charCodeAt(c.length-1)!==93)return!1;let r=c.indexOf("[");if(r<=0)return!1;for(let s=0;s<r;s++){let i=c.charCodeAt(s);if(!R(i)&&i!==46)return!1}return!0}
|
|
24
|
+
export{Rt,Mt,n,Ot,I,ke,oe,et,Te,ae,o,tt,Ae,j,Ta,Aa,Pa,Da,Ra,Ma,Oa,ca,Ia,Fa,La};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{r}from"./chunk-jcckwgb9.js";import{l}from"./chunk-y1g6v96c.js";import{existsSync as P,readFileSync as b,unwatchFile as w}from"fs";var Dr;((o)=>{o[o.Error=1]="Error";o[o.Warning=2]="Warning";o[o.Information=3]="Information";o[o.Hint=4]="Hint"})(Dr||={});var Rr;((s)=>{s[s.File=1]="File";s[s.Module=2]="Module";s[s.Namespace=3]="Namespace";s[s.Package=4]="Package";s[s.Class=5]="Class";s[s.Method=6]="Method";s[s.Property=7]="Property";s[s.Field=8]="Field";s[s.Constructor=9]="Constructor";s[s.Enum=10]="Enum";s[s.Interface=11]="Interface";s[s.Function=12]="Function";s[s.Variable=13]="Variable";s[s.Constant=14]="Constant";s[s.String=15]="String";s[s.Number=16]="Number";s[s.Boolean=17]="Boolean";s[s.Array=18]="Array";s[s.Object=19]="Object";s[s.Key=20]="Key";s[s.Null=21]="Null";s[s.EnumMember=22]="EnumMember";s[s.Struct=23]="Struct";s[s.Event=24]="Event";s[s.Operator=25]="Operator";s[s.TypeParameter=26]="TypeParameter"})(Rr||={});var Mr;((c)=>{c[c.Text=1]="Text";c[c.Method=2]="Method";c[c.Function=3]="Function";c[c.Constructor=4]="Constructor";c[c.Field=5]="Field";c[c.Variable=6]="Variable";c[c.Class=7]="Class";c[c.Interface=8]="Interface";c[c.Module=9]="Module";c[c.Property=10]="Property";c[c.Unit=11]="Unit";c[c.Value=12]="Value";c[c.Enum=13]="Enum";c[c.Keyword=14]="Keyword";c[c.Snippet=15]="Snippet";c[c.Color=16]="Color";c[c.File=17]="File";c[c.Reference=18]="Reference";c[c.Folder=19]="Folder";c[c.EnumMember=20]="EnumMember";c[c.Constant=21]="Constant";c[c.Struct=22]="Struct";c[c.Event=23]="Event";c[c.Operator=24]="Operator";c[c.TypeParameter=25]="TypeParameter"})(Mr||={});var Or;((n)=>{n[n.Text=1]="Text";n[n.Read=2]="Read";n[n.Write=3]="Write"})(Or||={});class Yt{documents=new Map;rootUri=null;config={};messageId=0;watchers=new Map;initialize(t){return this.rootUri=t.rootUri,{capabilities:{textDocumentSync:1,hoverProvider:!0,completionProvider:{triggerCharacters:[".",":","<",'"',"'","/"],resolveProvider:!0},definitionProvider:!0,referencesProvider:!0,renameProvider:{prepareProvider:!0},documentSymbolProvider:!0,workspaceSymbolProvider:!0,codeActionProvider:{codeActionKinds:["quickfix","refactor","source"]},signatureHelpProvider:{triggerCharacters:["(",","],retriggerCharacters:[","]},documentHighlightProvider:!0,documentFormattingProvider:!0,diagnosticProvider:{interFileDependencies:!0,workspaceDiagnostics:!0}}}}didOpen(t){let{uri:e,text:i,version:n}=t.textDocument;this.updateDocument(e,i,n)}didChange(t){let{uri:e,version:i}=t.textDocument,n=t.contentChanges[0]?.text||"";this.updateDocument(e,n,i)}didClose(t){let e=t.textDocument.uri;if(this.documents.delete(e),this.watchers.get(e))w(this.uriToPath(e)),this.watchers.delete(e)}updateDocument(t,e,i){let n=this.uriToPath(t),o=r(e,n,!0);this.documents.set(t,{content:e,version:i,declarations:o})}getDiagnostics(t){let e=this.documents.get(t);if(!e)return[];let i=[];for(let n of e.declarations){if(n.isExported&&n.kind==="variable"&&!n.typeAnnotation)i.push({range:this.getDeclarationRange(n,e.content),severity:2,code:"missing-type",source:"dtsx",message:`Exported variable '${n.name}' should have an explicit type annotation for better declaration generation`});if(n.typeAnnotation==="any"||n.returnType==="any")i.push({range:this.getDeclarationRange(n,e.content),severity:3,code:"any-type",source:"dtsx",message:"Consider using a more specific type instead of 'any'"});if(n.kind==="function"&&n.isExported&&!n.returnType)i.push({range:this.getDeclarationRange(n,e.content),severity:3,code:"missing-return-type",source:"dtsx",message:`Function '${n.name}' should have an explicit return type for better declaration generation`})}return i}hover(t){let e=this.documents.get(t.textDocument.uri);if(!e)return null;let{line:i,character:n}=t.position,a=e.content.split(`
|
|
3
|
+
`)[i]||"",u=a.slice(0,n).match(/[\w$]+$/),d=a.slice(n).match(/^[\w$]+/);if(!u&&!d)return null;let g=(u?.[0]||"")+(d?.[0]||""),f=e.declarations.find((x)=>x.name===g);if(!f)return null;let m=`\`\`\`typescript
|
|
4
|
+
${this.buildSignature(f)}
|
|
5
|
+
\`\`\``;if(f.leadingComments&&f.leadingComments.length>0){let v=f.leadingComments.join(`
|
|
6
|
+
`).match(/\*\s*([^@*][^*]*)/);if(v)m+=`
|
|
7
|
+
|
|
8
|
+
${v[1].trim()}`}return{contents:{kind:"markdown",value:m}}}completion(t){let e=this.documents.get(t.textDocument.uri);if(!e)return[];let i=[];for(let n of e.declarations){if(!n.isExported)continue;let o=6;switch(n.kind){case"function":o=3;break;case"class":o=7;break;case"interface":o=8;break;case"type":o=8;break;case"enum":o=13;break}i.push({label:n.name,kind:o,detail:this.buildSignature(n)})}return i}definition(t){let e=this.documents.get(t.textDocument.uri);if(!e)return null;let{line:i,character:n}=t.position,a=e.content.split(`
|
|
9
|
+
`)[i]||"",u=a.slice(0,n).match(/[\w$]+$/),d=a.slice(n).match(/^[\w$]+/);if(!u&&!d)return null;let g=(u?.[0]||"")+(d?.[0]||""),f=e.declarations.find((p)=>p.name===g);if(!f)return null;return{uri:t.textDocument.uri,range:this.getDeclarationRange(f,e.content)}}references(t){let e=[],i=this.getWordAtPosition(t.textDocument.uri,t.position);if(!i)return e;for(let[n,o]of this.documents){let a=o.content.split(`
|
|
10
|
+
`);for(let u=0;u<a.length;u++){let d=a[u],g=0;while(g<d.length){let f=d.indexOf(i,g);if(f===-1)break;let p=f>0?d[f-1]:" ",m=f+i.length<d.length?d[f+i.length]:" ";if(!/[\w$]/.test(p)&&!/[\w$]/.test(m))e.push({uri:n,range:{start:{line:u,character:f},end:{line:u,character:f+i.length}}});g=f+1}}}return e}prepareRename(t){let e=this.getWordAtPosition(t.textDocument.uri,t.position);if(!e)return null;let i=this.documents.get(t.textDocument.uri);if(!i)return null;let n=i.declarations.find((a)=>a.name===e);if(!n)return null;return{range:this.getDeclarationRange(n,i.content),placeholder:e}}rename(t){if(!this.getWordAtPosition(t.textDocument.uri,t.position))return null;let i=this.references({textDocument:t.textDocument,position:t.position,context:{includeDeclaration:!0}});if(i.length===0)return null;let n={};for(let o of i){if(!n[o.uri])n[o.uri]=[];n[o.uri].push({range:o.range,newText:t.newName})}return{changes:n}}documentSymbols(t){let e=this.documents.get(t.textDocument.uri);if(!e)return[];let i=[];for(let n of e.declarations){let o=this.getDeclarationRange(n,e.content),a=this.declarationKindToSymbolKind(n.kind),u={name:n.name,detail:this.buildSignature(n),kind:a,range:o,selectionRange:o};if(n.members&&n.members.length>0)u.children=n.members.map((d)=>({name:d.name,kind:this.declarationKindToSymbolKind(d.kind),range:this.getDeclarationRange(d,e.content),selectionRange:this.getDeclarationRange(d,e.content)}));i.push(u)}return i}workspaceSymbols(t){let e=[],i=t.query.toLowerCase();for(let[n,o]of this.documents)for(let a of o.declarations){if(!a.isExported)continue;if(i&&!a.name.toLowerCase().includes(i))continue;e.push({name:a.name,kind:this.declarationKindToSymbolKind(a.kind),location:{uri:n,range:this.getDeclarationRange(a,o.content)}})}return e}codeActions(t){let e=[];if(!this.documents.get(t.textDocument.uri))return e;for(let o of t.context.diagnostics){if(o.code==="missing-type"){let a=this.getWordAtRange(t.textDocument.uri,o.range);if(a)e.push({title:`Add type annotation to '${a}'`,kind:"quickfix",diagnostics:[o],edit:{changes:{[t.textDocument.uri]:[{range:{start:o.range.end,end:o.range.end},newText:": unknown"}]}}})}if(o.code==="any-type")e.push({title:"Replace 'any' with 'unknown'",kind:"quickfix",diagnostics:[o],isPreferred:!0,edit:{changes:{[t.textDocument.uri]:[{range:o.range,newText:"unknown"}]}}});if(o.code==="missing-return-type"){let a=this.getWordAtRange(t.textDocument.uri,o.range);if(a)e.push({title:`Add return type to '${a}'`,kind:"quickfix",diagnostics:[o]})}}let n=this.getDeclarationAtPosition(t.textDocument.uri,t.range.start);if(n){if(n.kind==="function")e.push({title:"Extract function signature to type",kind:"refactor.extract"});if(n.kind==="interface"||n.kind==="type")e.push({title:"Generate runtime validator",kind:"source"})}return e}signatureHelp(t){let e=this.documents.get(t.textDocument.uri);if(!e)return null;let{line:i,character:n}=t.position,a=e.content.split(`
|
|
11
|
+
`)[i]||"",u=0,d=-1,g=0;for(let h=n-1;h>=0;h--){let D=a[h];if(D===")")u++;else if(D==="("){if(u===0){d=h;break}u--}else if(D===","&&u===0)g++}if(d===-1)return null;let p=a.slice(0,d).trimEnd().match(/[\w$]+$/);if(!p)return null;let m=p[0],x=e.declarations.find((h)=>h.name===m&&h.kind==="function");if(!x||!x.parameters)return null;let v=x.parameters.map((h)=>{let D="";if(h.rest)D+="...";if(D+=h.name,h.optional)D+="?";if(h.type)D+=`: ${h.type}`;return D});return{signatures:[{label:`${m}(${v.join(", ")}): ${x.returnType||"void"}`,parameters:x.parameters.map((h)=>({label:h.name,documentation:h.type?`Type: ${h.type}`:void 0}))}],activeSignature:0,activeParameter:Math.min(g,x.parameters.length-1)}}documentHighlight(t){let e=[],i=this.getWordAtPosition(t.textDocument.uri,t.position);if(!i)return e;let n=this.documents.get(t.textDocument.uri);if(!n)return e;let o=n.content.split(`
|
|
12
|
+
`);for(let a=0;a<o.length;a++){let u=o[a],d=0;while(d<u.length){let g=u.indexOf(i,d);if(g===-1)break;let f=g>0?u[g-1]:" ",p=g+i.length<u.length?u[g+i.length]:" ";if(!/[\w$]/.test(f)&&!/[\w$]/.test(p)){let m=/^\s*[=:]/.test(u.slice(g+i.length))||/^(const|let|var|function|class|interface|type|enum)\s+$/.test(u.slice(0,g));e.push({range:{start:{line:a,character:g},end:{line:a,character:g+i.length}},kind:m?3:2})}d=g+1}}return e}async formatting(t){let e=this.documents.get(t.textDocument.uri);if(!e)return[];let i=this.generateDts(t.textDocument.uri);if(!i)return[];let n=e.content.split(`
|
|
13
|
+
`);return[{range:{start:{line:0,character:0},end:{line:n.length-1,character:n[n.length-1].length}},newText:i}]}getWordAtPosition(t,e){let i=this.documents.get(t);if(!i)return null;let o=i.content.split(`
|
|
14
|
+
`)[e.line]||"",a=o.slice(0,e.character).match(/[\w$]+$/),u=o.slice(e.character).match(/^[\w$]+/);if(!a&&!u)return null;return(a?.[0]||"")+(u?.[0]||"")}getWordAtRange(t,e){let i=this.documents.get(t);if(!i)return null;let n=i.content.split(`
|
|
15
|
+
`);if(e.start.line===e.end.line)return n[e.start.line]?.slice(e.start.character,e.end.character)||null;return null}getDeclarationAtPosition(t,e){let i=this.documents.get(t);if(!i)return null;for(let n of i.declarations){let o=this.getDeclarationRange(n,i.content);if(this.positionInRange(e,o))return n}return null}positionInRange(t,e){if(t.line<e.start.line||t.line>e.end.line)return!1;if(t.line===e.start.line&&t.character<e.start.character)return!1;if(t.line===e.end.line&&t.character>e.end.character)return!1;return!0}declarationKindToSymbolKind(t){switch(t){case"function":return 12;case"class":return 5;case"interface":return 11;case"type":return 11;case"enum":return 10;case"variable":return 13;case"const":return 14;case"property":return 7;case"method":return 6;case"module":return 2;case"namespace":return 3;default:return 13}}generateDts(t){let e=this.documents.get(t);if(!e)return null;let i={filePath:this.uriToPath(t),sourceCode:e.content,declarations:e.declarations};return l(e.declarations,i,!0,this.config.importOrder)}buildSignature(t){switch(t.kind){case"function":{let e=t.parameters?.map((o)=>{let a="";if(o.rest)a+="...";if(a+=o.name,o.optional)a+="?";if(o.type)a+=`: ${o.type}`;return a}).join(", ")||"",i=t.generics||"",n=t.returnType?`: ${t.returnType}`:"";return`function ${t.name}${i}(${e})${n}`}case"variable":return`const ${t.name}: ${t.typeAnnotation||"unknown"}`;case"interface":return`interface ${t.name}${t.generics||""}${t.extends?` extends ${t.extends}`:""}`;case"type":return`type ${t.name}${t.generics||""} = ${t.typeAnnotation||"unknown"}`;case"class":return`class ${t.name}${t.generics||""}${t.extends?` extends ${t.extends}`:""}`;case"enum":return`enum ${t.name}`;default:return t.name}}getDeclarationRange(t,e){if(t.start!==void 0&&t.end!==void 0)return{start:this.offsetToPosition(t.start,e),end:this.offsetToPosition(t.end,e)};let i=e.split(`
|
|
16
|
+
`);for(let n=0;n<i.length;n++){let o=i[n].indexOf(t.name);if(o!==-1)return{start:{line:n,character:o},end:{line:n,character:o+t.name.length}}}return{start:{line:0,character:0},end:{line:0,character:0}}}offsetToPosition(t,e){let i=0,n=0;for(let o=0;o<t&&o<e.length;o++)if(e[o]===`
|
|
17
|
+
`)i++,n=0;else n++;return{line:i,character:n}}uriToPath(t){if(t.startsWith("file://"))return decodeURIComponent(t.slice(7));return t}pathToUri(t){return`file://${encodeURIComponent(t).replace(/%2F/g,"/")}`}handleMessage(t){if(t.method==="initialize")return{jsonrpc:"2.0",id:t.id,result:this.initialize(t.params)};if(t.method==="initialized")return null;if(t.method==="shutdown")return{jsonrpc:"2.0",id:t.id,result:null};if(t.method==="exit")process.exit(0);let e=t.params;if(t.method==="textDocument/didOpen")return this.didOpen(e),null;if(t.method==="textDocument/didChange")return this.didChange(e),null;if(t.method==="textDocument/didClose")return this.didClose(e),null;if(t.method==="textDocument/hover")return{jsonrpc:"2.0",id:t.id,result:this.hover(e)};if(t.method==="textDocument/completion")return{jsonrpc:"2.0",id:t.id,result:this.completion(e)};if(t.method==="textDocument/definition")return{jsonrpc:"2.0",id:t.id,result:this.definition(e)};if(t.method==="textDocument/references")return{jsonrpc:"2.0",id:t.id,result:this.references(e)};if(t.method==="textDocument/prepareRename")return{jsonrpc:"2.0",id:t.id,result:this.prepareRename(e)};if(t.method==="textDocument/rename")return{jsonrpc:"2.0",id:t.id,result:this.rename(e)};if(t.method==="textDocument/documentSymbol")return{jsonrpc:"2.0",id:t.id,result:this.documentSymbols(e)};if(t.method==="workspace/symbol")return{jsonrpc:"2.0",id:t.id,result:this.workspaceSymbols(e)};if(t.method==="textDocument/codeAction")return{jsonrpc:"2.0",id:t.id,result:this.codeActions(e)};if(t.method==="textDocument/signatureHelp")return{jsonrpc:"2.0",id:t.id,result:this.signatureHelp(e)};if(t.method==="textDocument/documentHighlight")return{jsonrpc:"2.0",id:t.id,result:this.documentHighlight(e)};if(t.method==="textDocument/formatting")return{jsonrpc:"2.0",id:t.id,result:this.formatting(e)};if(t.method==="textDocument/diagnostic"){let i=e?.textDocument?.uri;return{jsonrpc:"2.0",id:t.id,result:{kind:"full",items:i?this.getDiagnostics(i):[]}}}if(t.id!==void 0)return{jsonrpc:"2.0",id:t.id,error:{code:-32601,message:`Method not found: ${t.method}`}};return null}}function As(){let t=new Yt,e="";process.stdin.setEncoding("utf8"),process.stdin.on("data",(i)=>{e+=i;while(!0){let n=e.indexOf(`\r
|
|
18
|
+
\r
|
|
19
|
+
`);if(n===-1)break;let a=e.slice(0,n).match(/Content-Length:\s*(\d+)/i);if(!a){e=e.slice(n+4);continue}let u=Number.parseInt(a[1],10),d=n+4,g=d+u;if(e.length<g)break;let f=e.slice(d,g);e=e.slice(g);try{let p=JSON.parse(f),m=t.handleMessage(p);if(m){let x=JSON.stringify(m),v=Buffer.byteLength(x,"utf8");process.stdout.write(`Content-Length: ${v}\r
|
|
20
|
+
\r
|
|
21
|
+
${x}`)}}catch(p){console.error("Error parsing LSP message:",p)}}})}function Ps(t,e){return(i)=>{if(!P(i))return;let n=b(i,"utf-8"),o=`file://${i}`;t.didOpen({textDocument:{uri:o,languageId:"typescript",version:1,text:n}});let a=t.getDiagnostics(o);e(o,a)}}
|
|
22
|
+
export{Dr,Rr,Mr,Or,Yt,As,Ps};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{N}from"./chunk-ebjafajx.js";import{k}from"./chunk-p9vfxn8g.js";import{ye,be}from"./chunk-davy89dj.js";import{createHash as x}from"crypto";import{readFile as d}from"fs/promises";import{resolve as m}from"path";async function vn(g){let e={...N,...g},n=e.moduleSpecifierMode??"preserve";if(n!=="node"&&n!=="preserve")throw Error("moduleSpecifierMode must be preserve or node");if(e.plugins?.length)throw Error("Native project planning does not support generation plugins");let o=await ye(e),l=[];for(let r of o.files){let s=await d(r),a=s.toString("utf8");if(!Buffer.from(a,"utf8").equals(s))throw Error(`Native declaration source must be valid UTF-8: ${r}`);let u=o.outputBySource.get(r),v=be(r,e,o.resolver),i=[],S=new Set(k(a,{includeImports:!0}).map((t)=>t.specifier));for(let t of S){let p=v(t);if(p.kind!=="local")continue;let{resolvedSource:h,declarationOutput:w,emittedSpecifier:y}=p;i.push({specifier:t,resolvedSource:h,declarationOutput:w,emittedSpecifier:y})}let c={version:1,moduleSpecifierMode:n,sourceFile:r,outputFile:u,sourceHash:x("sha256").update(s).digest("hex"),rewrites:i};if(!e.isolatedDeclarations&&i.length)c.inferenceSources=await Promise.all(i.map(async(t)=>({specifier:t.specifier,source:await d(t.resolvedSource,"utf8")})));let f=o.augmentationImports.get(r);if(f?.size)c.augmentationImports=[...f];l.push(Object.freeze({sourceFile:r,outputFile:u,source:a,context:c}))}return Object.freeze({version:1,rootPath:m(e.cwd,e.root),outdirPath:m(e.cwd,e.outdir),files:Object.freeze(l)})}
|
|
3
|
+
export{vn};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{basename as e,dirname as n,isAbsolute as i,join as o,relative as a,resolve as s}from"path";function $i(t){if(!t||typeof t!=="string")throw Error("Invalid file path: must be a non-empty string");return t}function Ei(t){if(!t||typeof t!=="string")throw Error("Invalid directory path: must be a non-empty string");return t}function ki(t){if(!t||typeof t!=="string")throw Error("Invalid glob pattern: must be a non-empty string");return t}function Ti(t){if(typeof t!=="string")throw TypeError("Invalid source code: must be a string");return t}function Ai(t){if(typeof t!=="string")throw TypeError("Invalid DTS content: must be a string");return t}function Pi(t){if(!t||typeof t!=="string")throw Error("Invalid module specifier: must be a non-empty string");return t}function Di(t){if(!t||typeof t!=="string")throw Error("Invalid type name: must be a non-empty string");if(!["string","number","boolean","symbol","bigint","undefined","null","void","never","any","unknown","object"].includes(t)&&!/^[A-Z_$]/.test(t));return t}function Ri(t){if(!t||typeof t!=="string")throw Error("Invalid declaration name: must be a non-empty string");return t}function Mi(t){if(!t||typeof t!=="string")throw Error("Invalid absolute path: must be a non-empty string");if(!t.startsWith("/")&&!/^[A-Z]:/i.test(t))throw Error("Invalid absolute path: must start with / or drive letter");return t}function Oi(t){if(!t||typeof t!=="string")throw Error("Invalid relative path: must be a non-empty string");if(t.startsWith("/")||/^[A-Z]:/i.test(t))throw Error("Invalid relative path: must not be absolute");return t}function Ii(t){if(typeof t!=="string")throw TypeError("Invalid JSON string: must be a string");try{JSON.parse(t)}catch{throw Error("Invalid JSON string: must be valid JSON")}return t}function Fi(t,r){return typeof t==="string"||typeof t==="number"}function Li(t){return t}var Ni={join(t,...r){return o(t,...r)},dirname(t){return n(t)},basename(t){return e(t)},resolve(...t){return s(...t)},isAbsolute(t){return i(t)},relative(t,r){return a(t,r)}};
|
|
3
|
+
export{$i,Ei,ki,Ti,Ai,Pi,Di,Ri,Mi,Oi,Ii,Fi,Li,Ni};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{s}from"./chunk-0zfzhn19.js";function le(d={}){let{onBuildStart:u=!1,onBuildEnd:f=!0,onGenerated:l,onError:i,...c}=d,o,r,e=async()=>{let t={...c};if(!t.outdir&&o)t.outdir=o;if(!t.entrypoints&&r)t.entrypoints=r;try{let n=await s(t);l?.(n)}catch(n){let a=n instanceof Error?n:Error(String(n));if(i?.(a),!i)console.error("[dtsx] Generation failed:",a.message)}};return{name:"dtsx",esbuildOptions(t){if(t.outdir&&typeof t.outdir==="string")o=t.outdir;if(t.entryPoints){if(Array.isArray(t.entryPoints))r=t.entryPoints;else if(typeof t.entryPoints==="object")r=Object.values(t.entryPoints)}},async buildStart(){if(u)await e()},async buildEnd(t){if(f)await e()}}}var ha=le,Yn=le,ya=le;
|
|
3
|
+
export{le,ha,Yn,ya};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{r}from"./chunk-jcckwgb9.js";import{me}from"./chunk-danfamyx.js";import{readFileSync as u}from"fs";import{readFile as p}from"fs/promises";import{resolve as g}from"path";function m(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/^\s*\/\/.*$/gm,"").replace(/,\s*([}\]])/g,"$1")}function hs(t,e){try{return{...JSON.parse(m(u(t,"utf8"))).compilerOptions,...e}}catch(s){throw Error(`Error reading tsconfig.json: ${s instanceof Error?s.message:String(s)}`)}}function f(t,e){let s=e.declarationsOnly?t.filter((o)=>o.endsWith(".d.ts")):t;if(e.include?.length){let o=e.include.map((n)=>new RegExp(n.replace(/\*/g,".*")));s=s.filter((n)=>o.some((i)=>i.test(n)))}if(e.exclude?.length){let o=e.exclude.map((n)=>new RegExp(n.replace(/\*/g,".*")));s=s.filter((n)=>!o.some((i)=>i.test(n)))}return s}async function at(t,e={}){let s=performance.now(),o=f(t,e),n=[];for(let a of o)try{let c=await p(a,"utf8");for(let l of me(c))n.push({file:a,line:l.line,column:l.column,message:l.message,code:Number(l.code.slice(4)),severity:"error",category:"Error"})}catch(c){n.push({file:a,line:0,column:0,message:c instanceof Error?c.message:String(c),code:1000,severity:"error",category:"Error"})}let i=e.maxErrors?n.slice(0,e.maxErrors):n;return{success:i.length===0,diagnostics:i,errorCount:i.length,warningCount:0,infoCount:0,filesChecked:o,durationMs:performance.now()-s}}function xr(t,e={}){return at(t,{...e,declarationsOnly:!0})}async function ys(t){let e=new Map;for(let s of t){let o=await p(s,"utf8").catch(()=>""),n=[];for(let i of r(o,s,!1,!0))if(i.isExported&&i.kind==="function"&&!i.returnType)n.push({line:1,column:1,message:"Exported function requires an explicit return type",declarationName:i.name,missingAnnotation:"return"});e.set(s,{compatible:n.length===0,issues:n})}return e}function d(t,e,s){let o=t.split(`
|
|
3
|
+
`);if(e<1||e>o.length||s<1||s>o[e-1].length+1)return null;let n=s-1;for(let i=0;i<e-1;i++)n+=o[i].length+1;return n}function Cr(t,e,s){try{let o=u(t,"utf8"),n=d(o,e,s);if(n===null)return null;let i=r(o,t,!1).find((a)=>n>=(a.start??0)&&n<=(a.end??o.length));return i?.typeAnnotation??i?.returnType??i?.text??null}catch{return null}}function bs(t,e,s){let o=Cr(t,e,s);return o?{type:o}:null}function ws(t){if(t.success)return`\u2713 Type check passed (${t.filesChecked.length} files checked in ${t.durationMs}ms)`;return["\u2717 Type check failed",` ${t.errorCount} error(s), ${t.warningCount} warning(s)`,...t.diagnostics.map((e)=>`\u2717 ${e.file}:${e.line}:${e.column}
|
|
4
|
+
${e.message}`)].join(`
|
|
5
|
+
`)}function xs(t){return at(t.entrypoints.map((e)=>g(t.cwd,e)),{tsconfigPath:t.tsconfigPath,rootDir:t.root})}async function Cs(t,e){let o=(await Promise.all([at(t),xr(e)])).flatMap((n)=>n.diagnostics).map((n)=>({sourceName:n.file,sourceType:n.message,dtsType:"<invalid>"}));return{valid:o.length===0,mismatches:o}}
|
|
6
|
+
export{hs,at,xr,ys,Cr,bs,ws,xs,Cs};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{t,F}from"./chunk-1j6092xz.js";import{Kn}from"./chunk-42j9cfte.js";function Qe(o){let f=t(o);if(f.length!==1||f[0].kind!=="word")return;let l=o.slice(f[0].start,f[0].end);return["true","false","null","undefined","this","super"].includes(l)?void 0:l}function Dt(o){let f=t(o);if(f.length===0)return!0;let l=f[f.length-1],s=o.slice(l.start,l.end);if(l.kind==="word"&&(s==="is"||s==="extends"))return!0;if(s==="|"||s==="&")return!0;let n=f[f.length-2];return s===">"&&n!==void 0&&o.slice(n.start,n.end)==="="}function W(o){return w(o,F(o))}function jn(o){for(let f=1024;f<o.length;f*=8){let l=o.slice(0,f),s=v(l,t(l),f);if(s!==void 0)return s}return w(o,t(o))}function w(o,f){return v(o,f,1/0)??!1}function v(o,f,l){let s=0;for(let n=0;n<f.length;n++){let a=f[n];if(a.end>=l)return;if(a.kind==="punctuation"){let d=o.charCodeAt(a.start);if(d===123||d===40||d===91)s++;else if(d===125||d===41||d===93)s--;continue}if(s!==0||a.kind!=="word"||a.end-a.start!==6)continue;let c=o.slice(a.start,a.end);if(c==="export")return!0;if(c==="import"){let d=f[n+1];if(d===void 0?l!==1/0:d.end>=l)return;let x=d?o.slice(d.start,d.end):"";if(x!=="("&&x!==".")return!0}}return l===1/0?!1:void 0}function _n(o){if(o.isExported)return!1;if(["function","variable","interface","type","class","enum","namespace"].includes(o.kind))return!0;return o.kind==="module"&&(o.moduleForm==="namespace"||o.moduleForm==="identifier")}function Gn(o,f){let l=o.text,s=t(l),n=(i)=>s[i]?l.slice(s[i].start,s[i].end):"",a=(i)=>s[i]?.kind==="word",c=new Map,d=[];for(let i=0;i<s.length;i++){let e=n(i);if(e==="("||e==="["||e==="{"||e==="<")d.push(i);else if(e===")"||e==="]"||e==="}"||e===">"&&n(i-1)!=="="){let r=d.at(-1);if(r!==void 0&&(n(r)==="("&&e===")"||n(r)==="["&&e==="]"||n(r)==="{"&&e==="}"||n(r)==="<"&&e===">"))d.pop(),c.set(r,i)}}let x=[];for(let i=0;i<s.length;i++){if(n(i)!=="(")continue;let e=c.get(i);if(e===void 0||!(n(e+1)===":"||n(e+1)==="="&&n(e+2)===">"))continue;let r=new Set,u=i+1;while(u<e){let m=u;while(m<e&&n(m)!==","){let b=c.get(m);if(b!==void 0)m=b+1;else m++}let g=u;while(g<m&&n(g)!==":"&&n(g)!=="="){let b=c.get(g);if(b!==void 0)g=b+1;else g++}let h=u;while([".","public","private","protected","readonly","override"].includes(n(h)))h++;if(n(h)==="{"||n(h)==="[")for(let b of Kn(l.slice(s[h].start,s[g-1].end)))r.add(b);else if(a(h))r.add(n(h));u=m+1}let p=e+(n(e+1)===":"?2:3);while(p<s.length){if([";",",",")","]","}"].includes(n(p))||n(p)===">"&&n(p-1)!=="=")break;let m=c.get(p);if(m!==void 0)p=m+1;else p++}x.push({start:i,end:p,names:r})}let y=(i)=>{if(!a(i))return;let e=n(i);if(!x.some((r)=>i>=r.start&&i<r.end&&r.names.has(e)))f.add(e)},k=(i,e)=>{for(let r=i;r<e;r++){if(n(r)==="<"&&c.has(r)){r=c.get(r);continue}if(!a(r)||n(r-1)==="."||n(r+1)===":")continue;if(["true","false","null","undefined","new","this","super","as","satisfies","typeof","void","keyof"].includes(n(r)))continue;y(r)}};for(let i=0;i<s.length;i++){if(n(i)==="typeof")y(i+1);if(n(i)==="export"){let e=i+1;if(n(e)==="default"){if(!["function","class","abstract"].includes(n(e+1)))k(e+1,s.length);continue}if(n(e)==="type")e++;if(n(e)==="{"){let r=c.get(e);if(r===void 0||n(r+1)==="from")continue;for(let u=e+1;u<r;){if(n(u)==="type"&&a(u+1)&&n(u+1)!=="as")u++;y(u);while(u<r&&n(u)!==",")u++;u++}}}if(n(i)==="["){let e=c.get(i);if(e!==void 0&&[":","?","("].includes(n(e+1))&&n(i+2)!==":"&&n(i+2)!=="in")k(i+1,e)}}if(o.kind==="class"){let i=-1;for(let e=0;e<s.length&&n(e)!=="{";e++)if(n(e)==="<"&&c.has(e))e=c.get(e);else if(n(e)==="extends"){i=e;break}if(i!==-1){let e=i+1;while(e<s.length&&n(e)!=="{"&&n(e)!=="implements"){let r=c.get(e);if(r!==void 0)e=r+1;else e++}k(i+1,e)}}}
|
|
3
|
+
export{Qe,Dt,W,jn,_n,Gn};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{EventEmitter as J}from"events";import w from"process";import D from"process";import N from"process";import B from"process";import S from"process";import H from"tty";import De,{stdin as it,stdout as nt}from"process";import{existsSync as Ue}from"fs";import V from"fs/promises";import U from"os";import A from"path";import b from"process";function M(e){return e.replace(/[<[].+/,"").trim()}function Q(e){let t=/<([^>]+)>/g,s=/\[([^\]]+)\]/g,i=[],o=(c)=>{let r=!1,n=c[1];if(n.startsWith("..."))n=n.slice(3),r=!0;else if(n.endsWith("..."))n=n.slice(0,-3),r=!0;return{required:c[0].startsWith("<"),value:n.trim(),variadic:r}},a;while(a=t.exec(e))i.push(o(a));let h;while(h=s.exec(e))i.push(o(h));return i}function X(e){let t={alias:{},boolean:[]};for(let[s,i]of e.entries()){if(i.names.length>1)t.alias[i.names[0]]=i.names.slice(1);if(i.isBoolean)if(i.negated){if(!e.some((a,h)=>h!==s&&a.names.some((c)=>i.names.includes(c))&&typeof a.required==="boolean"))t.boolean.push(i.names[0])}else t.boolean.push(i.names[0])}return t}function W(e){return e.reduce((t,s)=>t.length>=s.length?t:s,"")}function k(e,t){return e.length>=t?e:`${e}${" ".repeat(t-e.length)}`}function E(e){return e.replace(/([a-z])-([a-z])/g,(t,s,i)=>s+i.toUpperCase())}function Z(e,t,s){let i=0,o=t.length,a=e,h;for(;i<o;++i)h=a[t[i]],a=a[t[i]]=i===o-1?s:h!=null?h:!!~t[i+1].indexOf(".")||!(+t[i+1]>-1)?{}:[]}function ee(e,t){for(let s of Object.keys(t)){let i=t[s];if(e[s]===void 0)continue;if(i.shouldTransform){if(e[s]=Array.prototype.concat.call([],e[s]),typeof i.transformFunction==="function")e[s]=e[s].map(i.transformFunction)}}}function te(e){let t=/([^\\/]+)$/.exec(e);return t?t[1]:""}function _(e){return e.split(".").map((t,s)=>s===0?E(t):t).join(".")}class I extends Error{exitCode=2;isUsageError=!0;usage;constructor(e,t){super(e);if(this.name=this.constructor.name,t!==void 0)this.usage=t;if(typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,this.constructor);else this.stack=Error(e).stack}format(e=!1){if(e&&this.stack)return`${this.message}
|
|
3
|
+
|
|
4
|
+
Stack trace:
|
|
5
|
+
${this.stack}`;return this.message}}function se(e){if(e instanceof I)return!0;return!!e&&typeof e==="object"&&e.name==="ClappError"&&typeof e.message==="string"}function ie(){let{env:e}=D,{TERM:t,TERM_PROGRAM:s}=e;if(D.platform!=="win32")return t!=="linux";return Boolean(e.WT_SESSION)||Boolean(e.TERMINUS_SUBLIME)||e.ConEmuTask==="{cmd::Cmder}"||s==="Terminus-Sublime"||s==="vscode"||t==="xterm-256color"||t==="alacritty"||t==="rxvt-unicode"||t==="rxvt-unicode-256color"||e.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var T="\x1B",g=`${T}[`;var P={to(e,t){if(!t)return`${g}${e+1}G`;return`${g}${t+1};${e+1}H`},move(e,t){let s="";if(e<0)s+=`${g}${-e}D`;else if(e>0)s+=`${g}${e}C`;if(t<0)s+=`${g}${-t}A`;else if(t>0)s+=`${g}${t}B`;return s},up:(e=1)=>`${g}${e}A`,down:(e=1)=>`${g}${e}B`,forward:(e=1)=>`${g}${e}C`,backward:(e=1)=>`${g}${e}D`,nextLine:(e=1)=>`${g}E`.repeat(e),prevLine:(e=1)=>`${g}F`.repeat(e),left:`${g}G`,hide:`${g}?25l`,show:`${g}?25h`,save:`${T}7`,restore:`${T}8`};var ze={screen:`${g}2J`,up:(e=1)=>`${g}1J`.repeat(e),down:(e=1)=>`${g}J`.repeat(e),line:`${g}2K`,lineEnd:`${g}K`,lineStart:`${g}1K`,lines(e){let t="";for(let s=0;s<e;s++)t+=this.line+(s<e-1?P.up():"");if(e)t+=P.left;return t}},Ye={screen:`${T}c`};function ne(e,t){let s=[];for(let i=0;i<=t.length;i++)s[i]=[i];for(let i=0;i<=e.length;i++)s[0][i]=i;for(let i=1;i<=t.length;i++)for(let o=1;o<=e.length;o++)if(t.charAt(i-1)===e.charAt(o-1))s[i][o]=s[i-1][o-1];else s[i][o]=Math.min(s[i-1][o-1]+1,s[i][o-1]+1,s[i-1][o]+1);return s[t.length][e.length]}function G(e,t,s=2,i=3){return t.map((o)=>({cmd:o,distance:ne(e,o)})).filter(({distance:o})=>o<=s).sort((o,a)=>o.distance-a.distance).slice(0,i).map(({cmd:o})=>o)}function re(e,t={}){let s={_:[]},i=t.alias||{},o=new Set(t.boolean||[]),a={};for(let r of Object.keys(i))for(let n of i[r])a[n]=r;for(let r of o)if(i[r])for(let n of i[r])o.add(n);function h(r,n){if(r===void 0)return n;if(typeof n==="boolean")return n;return Array.isArray(r)?[...r,n]:[r,n]}function c(r,n){let u=a[r]||r,m=h(s[u],n);if(s[u]=m,i[u])for(let l of i[u])s[l]=m;if(a[r]&&i[a[r]])for(let l of i[a[r]])s[l]=m;s[r]=m}for(let r=0;r<e.length;r++){let n=e[r];if(n==="--"){s._.push(...e.slice(r+1));break}if(n.startsWith("--")){let u=n.indexOf("=");if(u!==-1){let m=E(n.slice(2,u)),l=n.slice(u+1);c(m,l)}else{let m=n.slice(2);if(m.startsWith("no-")){let f=E(m.slice(3));c(f,!1);continue}let l=E(m),v=a[l]||l;if(o.has(v)||o.has(l))c(l,!0);else{let f=e[r+1];if(f!==void 0&&!f.startsWith("-"))c(l,f),r++;else c(l,!0)}}}else if(n.startsWith("-")&&n.length>1){let u=n.slice(1);for(let m=0;m<u.length;m++){let l=u[m],v=a[l]||l;if(m===u.length-1&&!o.has(v)&&!o.has(l)){let f=e[r+1];if(f!==void 0&&!f.startsWith("-"))c(l,f),r++;else c(l,!0)}else c(l,!0)}}else s._.push(n)}return s}class K{rawName;description;name;names;isBoolean;required;config;negated;variadic;constructor(e,t,s){if(this.rawName=e,this.description=t,this.config=Object.assign({},s),e=e.replace(/\.\*/g,""),this.negated=!1,this.variadic=/[<[](?:\.\.\.[^\]>]+|[^\]>]+\.\.\.)[\]>]/.test(e),this.names=M(e).split(",").map((i)=>{let o=i.trim().replace(/^-{1,2}/,"");if(o.startsWith("no-"))this.negated=!0,o=o.replace(/^no-/,"");return _(o)}).sort((i,o)=>i.length>o.length?1:-1),this.name=this.names[this.names.length-1],this.negated&&this.config.default==null)this.config.default=!0;if(e.includes("<"))this.required=!0;else if(e.includes("["))this.required=!1;else this.isBoolean=!0}}var Qe=N.argv,oe=`${N.platform}-${N.arch} bun-v${typeof Bun<"u"?Bun.version:"unknown"}`,F=B.argv,ae=`${B.platform}-${B.arch} node-${B.version}`;class R{rawName;description;config;cli;options;aliasNames;name;namespace;args;commandAction;usageText;versionNumber;examples;helpCallback;globalCommand;beforeHooks;afterHooks;middleware;constructor(e,t,s,i){this.rawName=e,this.description=t,this.config=s,this.cli=i,this.options=[],this.aliasNames=[],this.name=M(e);let o=M(e),a=o.indexOf(":");if(a>0)this.namespace=o.substring(0,a),this.name=o.substring(a+1);if(this.args=Q(e),this.examples=[],this.beforeHooks=[],this.afterHooks=[],this.middleware=[],!s)this.config={}}usage(e){return this.usageText=e,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(e,t="-v, --version"){return this.versionNumber=e,this.option(t,"Display version number"),this}example(e){return this.examples.push(e),this}option(e,t,s){let i=new K(e,t,s);return this.options.push(i),this}alias(e){return this.aliasNames.push(e),this}action(e){return this.commandAction=e,this}before(e){return this.beforeHooks.push(e),this}after(e){return this.afterHooks.push(e),this}use(e){return this.middleware.push(e),this}isMatched(e){if(this.aliasNames.includes(e))return!0;if(this.namespace)return`${this.namespace}:${this.name}`===e;return this.name===e}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof j}get displayName(){return this.namespace?`${this.namespace}:${this.name}`:this.name}hasOption(e){let t=_(e.split(".")[0]);return!!this.options.find((s)=>s.names.some((i)=>_(i)===t))}outputHelp(){let{name:e,commands:t}=this.cli,{versionNumber:s,options:i,helpCallback:o}=this.cli.globalCommand,a=[{body:`${e}${s?`/${s}`:""}`}];if(a.push({title:"Usage",body:` $ ${e} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&t.length>0){let n=W(t.map((f)=>f.rawName)),u=new Map,m=[];for(let f of t)if(f.namespace){if(!u.has(f.namespace))u.set(f.namespace,[]);u.get(f.namespace).push(f)}else m.push(f);let l="";if(m.sort((f,O)=>f.rawName<O.rawName?-1:f.rawName>O.rawName?1:0),m.length>0)l+=m.map((f)=>` ${k(f.rawName,n.length)} ${f.description}`).join(`
|
|
6
|
+
`);let v=Array.from(u.keys()).sort();for(let f of v){let O=u.get(f);if(l.length>0)l+=`
|
|
7
|
+
|
|
8
|
+
`;l+=` ${f}:
|
|
9
|
+
`,l+=O.map((L)=>` ${k(L.rawName,n.length-2)} ${L.description}`).join(`
|
|
10
|
+
`)}a.push({title:"Commands",body:l}),a.push({body:`Run \`${e} <command> --help\` for command details.`})}let c=new Set(this.options.flatMap((n)=>n.names)),r=this.isGlobalCommand?i:[...this.options,...(i||[]).filter((n)=>!n.names.some((u)=>c.has(u)))];if(!this.isGlobalCommand&&!this.isDefaultCommand)r=r.filter((n)=>n.name!=="version");if(r.length>0){let n=W(r.map((u)=>u.rawName));a.push({title:"Options",body:r.map((u)=>` ${k(u.rawName,n.length)} ${u.description} ${u.config.default===void 0?"":`(default: ${u.config.default})`}`).join(`
|
|
11
|
+
`)})}if(this.examples.length>0)a.push({title:"Examples",body:this.examples.map((n)=>{if(typeof n==="function")return n(e);return n}).join(`
|
|
12
|
+
`)});if(o)a=o(a)||a;console.log(a.map((n)=>n.title?`${n.title}:
|
|
13
|
+
${n.body}`:n.body).join(`
|
|
14
|
+
|
|
15
|
+
`))}outputVersion(){let{name:e}=this.cli,{versionNumber:t}=this.cli.globalCommand;if(t)console.log(`${e}/${t} ${typeof Bun<"u"?oe:ae}`)}get usageLine(){return`$ ${this.cli.name} ${this.usageText||this.rawName}`}checkRequiredArgs(){let e=this.args.filter((t)=>t.required).length;if(this.cli.args.length<e){let s=this.args.filter((o)=>o.required).slice(this.cli.args.length),i=s.map((o)=>`<${o.value}>`).join(" ");throw new I(`Missing required argument${s.length>1?"s":""}: ${i}
|
|
16
|
+
|
|
17
|
+
Run \`${this.cli.name} ${this.rawName} --help\` for usage information.`,this.usageLine)}}checkUnknownOptions(){let{options:e,globalCommand:t}=this.cli;if(!this.config.allowUnknownOptions){for(let s of Object.keys(e))if(s!=="--"&&!this.hasOption(s)&&!t.hasOption(s)){let o=[...t.options,...this.options].flatMap((n)=>n.names),a=_(s.split(".")[0]),h=s.length>1?`--${s}`:`-${s}`,c=G(a,o),r=`Unknown option \`${h}\``;if(c.length>0)r+=`
|
|
18
|
+
|
|
19
|
+
Did you mean one of these?`,c.forEach((n)=>{let u=n.length>1?`--${n}`:`-${n}`;r+=`
|
|
20
|
+
\u2022 ${u}`});throw r+=`
|
|
21
|
+
|
|
22
|
+
Run \`${this.cli.name} ${this.rawName} --help\` to see available options.`,new I(r,this.usageLine)}}}checkOptionValue(){let{options:e,globalCommand:t}=this.cli,s=[...t.options,...this.options];for(let i of s){let o=e[i.name.split(".")[0]];if(i.required){let a=s.some((h)=>h.negated&&h.names.includes(i.name));if(o===!0||o===!1&&!a)throw new I(`Option \`${i.rawName}\` requires a value.
|
|
23
|
+
|
|
24
|
+
Example: ${this.cli.name} ${this.rawName} ${i.rawName} <value>`,this.usageLine)}}}}class j extends R{constructor(e){super("@@global@@","",{},e)}}var le=R,y={red:["\x1B[31m","\x1B[39m"],green:["\x1B[32m","\x1B[39m"],blue:["\x1B[34m","\x1B[39m"],yellow:["\x1B[33m","\x1B[39m"],cyan:["\x1B[36m","\x1B[39m"],magenta:["\x1B[35m","\x1B[39m"],white:["\x1B[37m","\x1B[39m"],gray:["\x1B[90m","\x1B[39m"],bgRed:["\x1B[41m","\x1B[49m"],bgGreen:["\x1B[42m","\x1B[49m"],bgBlue:["\x1B[44m","\x1B[49m"],bgYellow:["\x1B[43m","\x1B[49m"],bgCyan:["\x1B[46m","\x1B[49m"],bgMagenta:["\x1B[45m","\x1B[49m"],bold:["\x1B[1m","\x1B[22m"],italic:["\x1B[3m","\x1B[23m"],underline:["\x1B[4m","\x1B[24m"],dim:["\x1B[2m","\x1B[22m"],inverse:["\x1B[7m","\x1B[27m"],hidden:["\x1B[8m","\x1B[28m"],strikethrough:["\x1B[9m","\x1B[29m"]};var x={primary:"blue",secondary:"cyan",success:"green",warning:"yellow",error:"red",info:"magenta",muted:"gray"};function ue(){return!0}function ce(){let e={};e.supportsColor=ue();function t(i,o=[]){let a=i===""?[]:[...o,i],h=function(r){if(!e.supportsColor)return r;let n="",u="";for(let m of a)if(m in x&&x[m]in y){let l=x[m];n+=y[l][0],u=y[l][1]+u}else if(m in y)n+=y[m][0],u=y[m][1]+u;return n+r+u},c=[...Object.keys(y),...Object.keys(x)];for(let r of c)if(!(r in h))Object.defineProperty(h,r,{get(){return t(r,a)}});return h}let s=[...Object.keys(y),...Object.keys(x)];for(let i of s)if(!(i in e))Object.defineProperty(e,i,{get(){return t(i)}});return e}var C=ce();class he extends J{name;commands;globalCommand;matchedCommand;matchedCommandName;rawArgs;args;options;showHelpOnExit;showVersionOnExit;enableDidYouMean=!0;signalHandlersSet=!1;isVerbose=!1;isQuiet=!1;isDebug=!1;isNoInteraction=!1;environment;isDryRun=!1;isForce=!1;useEmoji=!0;theme;isNoCache=!1;constructor(e=""){super();this.name=e,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new j(this),this.globalCommand.usage("<command> [options]")}handleSignals(e){if(this.signalHandlersSet)return this;let t=async(s)=>{if(console.log(`
|
|
25
|
+
|
|
26
|
+
Received ${s}, cleaning up...`),e)try{await e()}catch(i){console.error("Error during cleanup:",i)}w.exit(0)};return w.on("SIGINT",()=>t("SIGINT")),w.on("SIGTERM",()=>t("SIGTERM")),this.signalHandlersSet=!0,this}didYouMean(e=!0){return this.enableDidYouMean=e,this}verbose(){return this.globalCommand.option("-v, --verbose","Enable verbose output"),this}quiet(){return this.globalCommand.option("-q, --quiet","Suppress non-essential output"),this}debug(){return this.globalCommand.option("--debug","Enable debug mode with detailed error information"),this}noInteraction(){return this.globalCommand.option("-n, --no-interaction","Do not ask any interactive questions (for CI/CD)"),this}env(){return this.globalCommand.option("--env <environment>","Target environment (e.g., production, staging, local)"),this}dryRun(){return this.globalCommand.option("--dry-run","Preview actions without executing them"),this}force(){return this.globalCommand.option("-f, --force","Skip confirmation prompts"),this}emoji(){return this.globalCommand.option("--no-emoji","Disable emoji in output"),this}themes(){return this.globalCommand.option("--theme <theme>","Color theme (default, dracula, nord, solarized, monokai)"),this}cache(){return this.globalCommand.option("--no-cache","Disable caching"),this}usage(e){return this.globalCommand.usage(e),this}command(e,t,s){if(!s)s={};let i=new le(e,t||"",s,this);return i.globalCommand=this.globalCommand,this.commands.push(i),i}option(e,t,s){return this.globalCommand.option(e,t,s),this}help(e){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=e,this.showHelpOnExit=!0,this}version(e,t="-v, --version"){return this.globalCommand.version(e,t),this.showVersionOnExit=!0,this}example(e){return this.globalCommand.example(e),this}outputHelp(){if(this.matchedCommand)this.matchedCommand.outputHelp();else this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:e,options:t},s,i){if(this.args=e,this.options=t,s)this.matchedCommand=s;if(i)this.matchedCommandName=i;return this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}showCommandNotFound(e){if(console.log(C.red(`
|
|
27
|
+
\u2717 Command "${e}" not found.
|
|
28
|
+
`)),this.enableDidYouMean){let t=[];for(let i of this.commands){if(i.displayName)t.push(i.displayName);if(i.aliasNames)t.push(...i.aliasNames)}let s=G(e,t);if(s.length>0)console.log(C.yellow("Did you mean one of these?")),s.forEach((i)=>console.log(` ${C.dim("\u2022")} ${this.name} ${i}`)),console.log("")}console.log(C.dim("Run"),`${this.name} --help`,C.dim("to see all available commands")),w.exit(1)}async parse(e=F,t={}){let{run:s=!0,exitOnError:i=!1}=t;if(i)try{return await this.parse(e,{run:s})}catch(r){throw this.handleUsageError(r),r}if(this.rawArgs=e,!this.name)this.name=e[1]?te(e[1]):"cli";let o=!0,a=e.slice(2),h=a[0];if(h&&!h.startsWith("-")){for(let r of this.commands)if(r.isMatched(h)){let n=this.mri(a,r);o=!1;let u={...n,args:n.args.slice(1)};this.setParsedInfo(u,r,h),this.emit(`command:${h}`,r);break}if(o){let r=a[1];if(r&&!r.startsWith("-")){let n=`${h}:${r}`;for(let u of this.commands)if(u.isMatched(n)){let m=this.mri(a,u);o=!1;let l={...m,args:m.args.slice(2)};this.setParsedInfo(l,u,n),this.emit(`command:${n}`,u);break}}}}if(o){for(let r of this.commands)if(r.name===""){o=!1;let n=this.mri(a,r);this.setParsedInfo(n,r),this.emit("command:!",r);break}}if(o){let r=this.mri(e.slice(2));this.setParsedInfo(r)}if(this.options.verbose)this.isVerbose=!0;if(this.options.quiet)this.isQuiet=!0;if(this.options.debug)this.isDebug=!0;if(this.options.noInteraction||this.options.interaction===!1)this.isNoInteraction=!0;if(this.options.env)this.environment=String(this.options.env);if(this.options.dryRun)this.isDryRun=!0;if(this.options.force)this.isForce=!0;if(this.options.noEmoji||this.options.emoji===!1)this.useEmoji=!1;if(this.options.theme)this.theme=String(this.options.theme);if(this.options.noCache||this.options.cache===!1)this.isNoCache=!0;if(this.options.help&&this.showHelpOnExit)this.outputHelp(),s=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),s=!1,this.unsetMatchedCommand();let c={args:this.args,options:this.options};if(s)await this.runMatchedCommand();if(!this.matchedCommand&&this.args[0]){if(this.emit("command:*"),!(this.listenerCount("command:*")>0))this.showCommandNotFound(this.args[0])}return c}mri(e,t){let s=[...this.globalCommand.options,...t?t.options:[]],i=X(s),o=[],a=e.indexOf("--");if(a>-1)o=e.slice(a+1),e=e.slice(0,a);let h=re(e,i),c={_:h._};for(let l of Object.keys(h))if(l!=="_")c[_(l)]=h[l];let r=c._,n={"--":o},u=t&&t.config.ignoreOptionDefaultValue?t.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,m=Object.create(null);for(let l of s){if(!u&&l.config.default!==void 0)for(let v of l.names)n[v]=l.config.default;if(Array.isArray(l.config.type)){if(m[l.name]===void 0)m[l.name]={shouldTransform:!0,transformFunction:l.config.type[0]}}}for(let l of Object.keys(c))if(l!=="_"){let v=l.split(".");Z(n,v,c[l]),ee(n,m)}for(let l of s){if(!l.variadic)continue;for(let v of l.names){let f=n[v];if(f===void 0||Array.isArray(f))continue;if(l.config.default!==void 0&&f===l.config.default)continue;n[v]=[f]}}return{args:r,options:n}}async run(e=F){return this.parse(e,{run:!0,exitOnError:!0})}handleUsageError(e){if(!se(e)||e.isUsageError===!1)return;let t=e.message||"command-line error",s=this.name?`${this.name}: `:"",i=/--help/.test(t)?"":e.usage?`
|
|
29
|
+
Usage: ${e.usage}`:`
|
|
30
|
+
Run \`${this.name??"cli"} --help\` for usage.`;w.stderr.write(`${s}${t}${i}
|
|
31
|
+
`),w.exit(e.exitCode??2)}async runMatchedCommand(){let{args:e,options:t,matchedCommand:s}=this;if(!s||!s.commandAction)return;s.checkUnknownOptions(),s.checkOptionValue(),s.checkRequiredArgs();let i=[];s.args.forEach((c,r)=>{if(c.variadic)i.push(e.slice(r));else i.push(e[r])}),i.push(t);let o={command:s,args:i,options:t};for(let c of s.beforeHooks)await c(o);let a,h=async()=>{let c=s.commandAction.apply(this,i);if(c instanceof Promise)a=await c;else a=c;return a};if(s.middleware.length>0){let c=0,r=async()=>{if(c<s.middleware.length){let n=s.middleware[c++];await n({...o,next:r})}else await h()};await r()}else await h();for(let c of s.afterHooks)await c(o);return a}removeSignalHandlers(){if(!this.signalHandlersSet)return this;return w.removeAllListeners("SIGINT"),w.removeAllListeners("SIGTERM"),this.signalHandlersSet=!1,this}destroy(){this.removeSignalHandlers(),this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.matchedCommand=void 0,this.matchedCommandName=void 0,this.removeAllListeners()}}class q{cache;enabled;cleanupInterval=null;hits=0;misses=0;constructor(){this.cache=new Map,this.enabled=!0,this.startCleanupInterval()}startCleanupInterval(){if(this.cleanupInterval)return;this.cleanupInterval=setInterval(()=>{this.cleanup()},30000),this.cleanupInterval.unref()}stopCleanup(){if(this.cleanupInterval)clearInterval(this.cleanupInterval),this.cleanupInterval=null}isEnabled(){return this.enabled}get(e){if(!this.enabled){this.misses++;return}let t=this.cache.get(e);if(!t){this.misses++;return}if(Date.now()-t.timestamp>t.ttl){this.cache.delete(e),this.misses++;return}return this.hits++,t.value}set(e,t,s=5000){if(!this.enabled)return;this.cache.set(e,{value:t,timestamp:Date.now(),ttl:s})}has(e){if(!this.enabled)return!1;let t=this.cache.get(e);if(!t)return!1;if(Date.now()-t.timestamp>t.ttl)return this.cache.delete(e),!1;return!0}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}disable(){this.enabled=!1,this.clear()}enable(){this.enabled=!0}stats(){return{size:this.cache.size,enabled:this.enabled,hits:this.hits,misses:this.misses}}resetStats(){this.hits=0,this.misses=0}keys(){return Array.from(this.cache.keys())}cleanup(){let e=Date.now();for(let[t,s]of this.cache.entries())if(e-s.timestamp>s.ttl)this.cache.delete(t)}destroy(){this.stopCleanup(),this.clear(),this.resetStats()}}var Ze=new q;function me(){if("FORCE_COLOR"in S.env)return S.env.FORCE_COLOR!=="0";if("NO_COLOR"in S.env||S.env.TERM==="dumb")return!1;if(S.platform==="win32")return!0;return H.isatty(1)&&H.isatty(2)}var z=me();function p(e,t){if(!z)return(s)=>s;return(s)=>e+s+t}var fe=p("\x1B[0m","\x1B[0m"),de=p("\x1B[31m","\x1B[39m"),pe=p("\x1B[32m","\x1B[39m"),ge=p("\x1B[33m","\x1B[39m"),$e=p("\x1B[34m","\x1B[39m"),ve=p("\x1B[35m","\x1B[39m"),we=p("\x1B[36m","\x1B[39m"),ye=p("\x1B[37m","\x1B[39m"),be=p("\x1B[90m","\x1B[39m"),xe=p("\x1B[1m","\x1B[22m"),Ce=p("\x1B[3m","\x1B[23m"),Se=p("\x1B[4m","\x1B[24m"),_e=p("\x1B[2m","\x1B[22m"),Ie=p("\x1B[7m","\x1B[27m"),Oe=p("\x1B[8m","\x1B[28m"),Ee=p("\x1B[9m","\x1B[29m"),Be=p("\x1B[41m","\x1B[49m"),Te=p("\x1B[42m","\x1B[49m"),ke=p("\x1B[43m","\x1B[49m"),Ve=p("\x1B[44m","\x1B[49m"),Ae=p("\x1B[45m","\x1B[49m"),Me=p("\x1B[46m","\x1B[49m"),Ne=p("\x1B[47m","\x1B[49m"),Re=z,je={reset:fe,red:de,green:pe,yellow:ge,blue:$e,magenta:ve,cyan:we,white:ye,gray:be,bold:xe,italic:Ce,underline:Se,dim:_e,inverse:Ie,hidden:Oe,strikethrough:Ee,bgRed:Be,bgGreen:Te,bgYellow:ke,bgBlue:Ve,bgMagenta:Ae,bgCyan:Me,bgWhite:Ne,isColorSupported:Re},Le=je,We=["up","down","left","right","space","enter","cancel"],rt={actions:new Set(We),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"}};var ot=De.platform.startsWith("win"),at=Symbol("clapp:cancel");var Pe=ie();var d=(e,t)=>Pe?e:t,lt=d("\u25C6","*"),ut=d("\u25A0","x"),ct=d("\u25B2","x"),ht=d("\u25C7","o"),mt=d("\u250C","T"),Fe=d("\u2502","|"),ft=d("\u2514","\u2014"),dt=d("\u25CF",">"),pt=d("\u25CB"," "),gt=d("\u25FB","[\u2022]"),$t=d("\u25FC","[+]"),vt=d("\u25FB","[ ]"),wt=d("\u25AA","\u2022"),yt=d("\u2500","-"),bt=d("\u256E","+"),xt=d("\u251C","+"),Ct=d("\u256F","+"),St=d("\u25CF","\u2022"),_t=d("\u25C6","*"),It=d("\u25B2","!"),Ot=d("\u25A0","x");var Et={light:d("\u2500","-"),heavy:d("\u2501","="),block:d("\u2588","#")};function He(){return`${Le.gray(Fe)} `}var Bt=He();class Y{configPath;config=null;events=[];retryCount=0;maxRetries=3;retryDelayMs=1000;constructor(){let e=U.homedir(),t=A.join(e,".config","clapp");this.configPath=A.join(t,"telemetry.json")}async isEnabled(){if(b.env.DO_NOT_TRACK==="1"||b.env.DO_NOT_TRACK==="true")return!1;if(b.env.NO_TELEMETRY==="1"||b.env.NO_TELEMETRY==="true")return!1;return(await this.loadConfig()).enabled}async enable(){let e=await this.loadConfig();if(e.enabled=!0,!e.userId)e.userId=this.generateUserId();await this.saveConfig(e)}async disable(){let e=await this.loadConfig();e.enabled=!1,await this.saveConfig(e)}async track(e,t){if(!await this.isEnabled())return;let i={event:e,...t,timestamp:Date.now(),platform:U.platform(),nodeVersion:b.version};if(this.events.push(i),this.events.length>=10)await this.send()}async trackCommand(e,t){await this.track("command",{command:e,duration:t})}async trackError(e,t){await this.track("error",{error:e,command:t})}async send(){if(!await this.isEnabled()||this.events.length===0)return!0;try{this.events=[],this.retryCount=0;let t=await this.loadConfig();return t.lastSent=Date.now(),await this.saveConfig(t),!0}catch{if(this.retryCount<this.maxRetries){this.retryCount++;let t=this.retryDelayMs*2**(this.retryCount-1);return await this.sleep(t),this.send()}return this.events=[],this.retryCount=0,!1}}async flush(){if(this.events.length===0)return!0;return this.send()}sleep(e){return new Promise((t)=>setTimeout(t,e))}async status(){let e=await this.loadConfig();return{enabled:e.enabled,doNotTrack:b.env.DO_NOT_TRACK==="1"||b.env.DO_NOT_TRACK==="true",eventsQueued:this.events.length,lastSent:e.lastSent}}async loadConfig(){if(this.config)return this.config;try{if(Ue(this.configPath)){let e=await V.readFile(this.configPath,"utf-8");return this.config=JSON.parse(e),this.config}}catch{}return this.config={enabled:!1},this.config}async saveConfig(e){this.config=e;try{let t=A.dirname(this.configPath);await V.mkdir(t,{recursive:!0}),await V.writeFile(this.configPath,JSON.stringify(e,null,2),"utf-8")}catch{}}generateUserId(){let e=Math.random().toString(36).substring(2,15),t=Date.now().toString(36);return`${e}-${t}`}}var Nt=new Y;export{he as CLI};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{r}from"./chunk-jcckwgb9.js";import{existsSync as g,readFileSync as h,writeFileSync as b}from"fs";function d(t){let e=[],s=/\b([A-Z][a-zA-Z0-9]*)\b/g,o;while((o=s.exec(t))!==null){let i=o[1];if(!D(i))e.push(i)}return[...new Set(e)]}function D(t){return new Set(["Array","Object","String","Number","Boolean","Symbol","BigInt","Function","Promise","Map","Set","WeakMap","WeakSet","Date","RegExp","Error","TypeError","RangeError","SyntaxError","Partial","Required","Readonly","Pick","Omit","Record","Exclude","Extract","NonNullable","ReturnType","Parameters","ConstructorParameters","InstanceType","ThisType","Uppercase","Lowercase","Capitalize","Uncapitalize","Awaited","NoInfer","Generator","AsyncGenerator","IterableIterator","AsyncIterableIterator","PropertyKey","Iterable","AsyncIterable","ArrayLike","PromiseLike","ArrayBuffer","SharedArrayBuffer","DataView","Int8Array","Uint8Array","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"]).has(t)}function x(t){if(t.kind!=="type")return!1;let e=t.typeAnnotation||"";if(t.generics)return!1;if(e.includes("{")||e.includes("(")||e.includes("<"))return!1;return/^[\w\s|&]+$/.test(e)}function v(t){if(t.kind!=="interface")return!1;if(!t.members||t.members.length===0){if(!t.extends)return!0}return!1}function I(t,e){let s={...t,members:[...t.members||[],...e.members||[]],leadingComments:[...t.leadingComments||[],...e.leadingComments||[]]};if(t.extends&&e.extends){let o=t.extends.split(",").map((n)=>n.trim()),i=e.extends.split(",").map((n)=>n.trim());s.extends=[...new Set([...o,...i])].join(", ")}else s.extends=t.extends||e.extends;return s}function A(t){let e={import:0,interface:1,type:2,class:3,enum:4,function:5,variable:6,export:7};return[...t].sort((s,o)=>{let i=e[s.kind]??99,n=e[o.kind]??99;if(i!==n)return i-n;return s.name.localeCompare(o.name)})}function T(t){let e=[],s=[];for(let i=0;i<t.length;i++){let n=t[i];if(n.kind==="import")e.push(n);else s.push(n)}return[...[...e].sort((i,n)=>{let a=i.source||"",c=n.source||"",p=a.startsWith("node:")||a==="bun",m=c.startsWith("node:")||c==="bun";if(p&&!m)return-1;if(!p&&m)return 1;let l=!a.startsWith("."),u=!c.startsWith(".");if(l&&!u)return-1;if(!l&&u)return 1;return a.localeCompare(c)}),...s]}function S(t){let e=new Set;for(let i of t){if(i.kind==="import")continue;let n=i.text||"",a=i.typeAnnotation||"",c=i.returnType||"",p=i.extends||"",m=i.implements?.join(" ")||"",l=`${n} ${a} ${c} ${p} ${m}`;for(let u of d(l))e.add(u);if(i.members)for(let u of i.members){let f=`${u.typeAnnotation||""} ${u.returnType||""}`;for(let y of d(f))e.add(y)}if(i.parameters){for(let u of i.parameters)if(u.type)for(let f of d(u.type))e.add(f)}}let s=0;return{declarations:t.map((i)=>{if(i.kind!=="import"||!i.specifiers)return i;let n=i.specifiers.filter((a)=>{let c=a.alias||a.name;return e.has(c)});if(n.length===0){if(!i.isSideEffect)return s++,null}if(n.length<(i.specifiers?.length||0))return s+=(i.specifiers?.length||0)-n.length,{...i,specifiers:n};return i}).filter((i)=>i!==null),removed:s}}function k(t){let e=new Map,s=0;for(let o of t){if(o.kind==="import"){let n=`import:${o.source}`;if(e.has(n)){let a=e.get(n),c=[...a.specifiers||[],...o.specifiers||[]],p=Array.from(new Map(c.map((m)=>[m.alias||m.name,m])).values());e.set(n,{...a,specifiers:p}),s++}else e.set(n,o);continue}let i=`${o.kind}:${o.name}`;if(e.has(i))s++;else e.set(i,o)}return{declarations:Array.from(e.values()),removed:s}}function z(t){let e=new Map,s=[];for(let n of t)if(n.kind==="interface"){let a=n.name;if(!e.has(a))e.set(a,[]);e.get(a).push(n)}else s.push(n);let o=0,i=[];for(let[n,a]of e)if(a.length>1){let c=a[0];for(let p=1;p<a.length;p++)c=I(c,a[p]),o++;i.push(c)}else i.push(a[0]);return{declarations:[...s,...i],merged:o}}function w(t){let e=new Map,s=new Set;for(let n of t)if(x(n))e.set(n.name,n.typeAnnotation||""),s.add(n.name);if(e.size===0)return{declarations:t,inlined:0};function o(n){let a=n;for(let[c,p]of e){let m=new RegExp(`\\b${c}\\b`,"g");a=a.replace(m,p)}return a}return{declarations:t.filter((n)=>n.kind!=="type"||!s.has(n.name)).map((n)=>{if(n.typeAnnotation)n={...n,typeAnnotation:o(n.typeAnnotation)};if(n.returnType)n={...n,returnType:o(n.returnType)};if(n.extends)n={...n,extends:o(n.extends)};return n}),inlined:e.size}}function R(t){let e=t.length,s=t.filter((o)=>!v(o));return{declarations:s,removed:e-s.length}}function Qn(t,e={}){let s=[...t],o={originalSize:0,optimizedSize:0,savings:0,savingsPercent:0,removedImports:0,removedDeclarations:0,mergedInterfaces:0,inlinedTypes:0};if(e.removeUnusedImports){let{declarations:i,removed:n}=S(s);s=i,o.removedImports=n}if(e.deduplicateDeclarations){let{declarations:i,removed:n}=k(s);s=i,o.removedDeclarations+=n}if(e.mergeInterfaces){let{declarations:i,merged:n}=z(s);s=i,o.mergedInterfaces=n}if(e.removeEmptyInterfaces){let{declarations:i,removed:n}=R(s);s=i,o.removedDeclarations+=n}if(e.inlineSimpleTypes){let{declarations:i,inlined:n}=w(s);s=i,o.inlinedTypes=n}if(e.sortImports)s=T(s);if(e.sortDeclarations)s=A(s);return{declarations:s,result:o}}async function vi(t,e={}){if(!g(t))throw Error(`File not found: ${t}`);let s=h(t,"utf-8"),o=Buffer.byteLength(s,"utf-8"),i=r(s,t,!e.removeComments),{declarations:n,result:a}=Qn(i,e),c=C(n,e);if(e.minify)c=er(c);let p=Buffer.byteLength(c,"utf-8");return a.originalSize=o,a.optimizedSize=p,a.savings=o-p,a.savingsPercent=Math.round(a.savings/o*100),b(t,c),a}function C(t,e){let s=[];for(let o of t){if(!e.removeComments&&o.leadingComments)for(let i of o.leadingComments)s.push(i);if(o.text)s.push(o.text);else s.push(E(o));s.push("")}return s.join(`
|
|
3
|
+
`)}function E(t){let e=[];if(t.isExported)e.push("export");if(t.isDefault)e.push("default");switch(t.kind){case"import":if(t.isTypeOnly)e.push("import type");else e.push("import");if(t.specifiers&&t.specifiers.length>0){let s=t.specifiers.map((o)=>{let i=o.isType?"type ":"";return o.alias?`${i}${o.name} as ${o.alias}`:`${i}${o.name}`}).join(", ");e.push(`{ ${s} }`)}e.push("from"),e.push(`'${t.source}'`);break;case"function":if(e.push("declare function"),e.push(t.name),t.generics)e.push(t.generics);if(e.push(`(${B(t.parameters)})`),t.returnType)e.push(`: ${t.returnType}`);break;case"variable":if(e.push("declare const"),e.push(t.name),t.typeAnnotation)e.push(`: ${t.typeAnnotation}`);break;case"interface":if(e.push("interface"),e.push(t.name),t.generics)e.push(t.generics);if(t.extends)e.push(`extends ${t.extends}`);if(e.push("{"),t.members)for(let s of t.members)e.push(` ${s.name}${s.typeAnnotation?`: ${s.typeAnnotation}`:""}`);e.push("}");break;case"type":if(e.push("type"),e.push(t.name),t.generics)e.push(t.generics);e.push("="),e.push(t.typeAnnotation||"unknown");break;case"class":if(e.push("declare class"),e.push(t.name),t.generics)e.push(t.generics);if(t.extends)e.push(`extends ${t.extends}`);if(t.implements?.length)e.push(`implements ${t.implements.join(", ")}`);e.push("{ }");break;case"enum":e.push("declare enum"),e.push(t.name),e.push("{ }");break;default:return t.text||""}return e.join(" ")}function B(t){if(!t)return"";return t.map((e)=>{let s="";if(e.rest)s+="...";if(s+=e.name,e.optional)s+="?";if(e.type)s+=`: ${e.type}`;return s}).join(", ")}function er(t){return t.replace(/(?<!\/\*\*)\/\/[^\n]*/g,"").replace(/^\s*[\r\n]/gm,"").replace(/ {2,}/g," ").replace(/\s*([{}[\]();,:])\s*/g,"$1").replace(/(\w)(\{)/g,"$1 $2").replace(/(\})([a-z])/gi,"$1 $2").replace(/(export|import|type|interface|class|function|const|let|var|extends|implements|declare)\s*/g,"$1 ").trim()}
|
|
4
|
+
export{Qn,vi,er};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
class he{plugins=[];config=null;register(t){if(this.plugins.some((n)=>n.name===t.name))throw Error(`Plugin "${t.name}" is already registered`);this.plugins.push(t)}hasDeclarationHooks(){return this.plugins.some((t)=>t.onDeclarations!==void 0)}unregister(t){let n=this.plugins.findIndex((r)=>r.name===t);if(n>=0)return this.plugins.splice(n,1),!0;return!1}getPlugins(){return this.plugins}createLogger(t){return{debug:(n)=>console.debug(`[${t}] ${n}`),info:(n)=>console.info(`[${t}] ${n}`),warn:(n)=>console.warn(`[${t}] ${n}`),error:(n)=>console.error(`[${t}] ${n}`)}}async runOnStart(t){let n=t;for(let r of this.plugins)if(r.onStart){let e=await r.onStart(n);if(e)n=e}return this.config=n,n}async runOnBeforeFile(t,n){let r=n;for(let e of this.plugins)if(e.onBeforeFile){let i={filePath:t,sourceCode:n,content:r,config:this.config,log:this.createLogger(e.name)},o=await e.onBeforeFile(i);if(typeof o==="string")r=o}return r}async runOnDeclarations(t,n,r){let e=r;for(let i of this.plugins)if(i.onDeclarations){let o={filePath:t,sourceCode:n,declarations:e,config:this.config,log:this.createLogger(i.name)},s=await i.onDeclarations(o);if(s)e=s}return e}async runOnAfterFile(t,n,r){let e=r;for(let i of this.plugins)if(i.onAfterFile){let o={filePath:t,sourceCode:n,content:e,config:this.config,log:this.createLogger(i.name)},s=await i.onAfterFile(o);if(typeof s==="string")e=s}return e}async runOnEnd(t){for(let n of this.plugins)if(n.onEnd)await n.onEnd(t)}async runOnError(t,n,r){for(let e of this.plugins)if(e.onError){let i={filePath:n,sourceCode:r,config:this.config,log:this.createLogger(e.name)};await e.onError(t,i)}}}var Wo=new he;function q(t){return t}var jo=q({name:"strip-internal",version:"1.0.0",description:"Removes declarations marked with @internal",onDeclarations:(t)=>t.declarations.filter((n)=>{if(n.leadingComments){if(n.leadingComments.some((e)=>e.includes("@internal")))return t.log.debug(`Stripping internal declaration: ${n.name}`),!1}return!0})});function _o(t){return q({name:"banner",version:"1.0.0",description:"Adds a banner comment to generated files",onAfterFile:(n)=>`/**
|
|
3
|
+
* ${t.split(`
|
|
4
|
+
`).join(`
|
|
5
|
+
* `)}
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
`+n.content})}function Go(t){return q({name:"filter",version:"1.0.0",description:"Filters declarations by name",onDeclarations:(n)=>n.declarations.filter((r)=>{if(r.kind==="import")return!0;return t(r.name)})})}
|
|
9
|
+
export{he,Wo,q,jo,_o,Go};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
function ve(h){let a="",i=0,e=0;while(i<h.length){let r=h.charCodeAt(i);if(e){if(a+=h[i],r===92&&i+1<h.length){a+=h[i+1],i+=2;continue}if(r===e)e=0;i++;continue}if(r===34){e=r,a+=h[i++];continue}if(r===47&&h.charCodeAt(i+1)===47){i+=2;while(i<h.length&&h.charCodeAt(i)!==10&&h.charCodeAt(i)!==13)i++;continue}if(r===47&&h.charCodeAt(i+1)===42){i+=2;while(i+1<h.length&&!(h.charCodeAt(i)===42&&h.charCodeAt(i+1)===47)){if(h.charCodeAt(i)===10)a+=`
|
|
3
|
+
`;i++}i=Math.min(i+2,h.length);continue}if(r===44){let c=i+1;while(c<h.length){while(c<h.length&&h.charCodeAt(c)<=32)c++;if(h.charCodeAt(c)===47&&h.charCodeAt(c+1)===47){c+=2;while(c<h.length&&h.charCodeAt(c)!==10&&h.charCodeAt(c)!==13)c++;continue}if(h.charCodeAt(c)===47&&h.charCodeAt(c+1)===42){c+=2;while(c+1<h.length&&!(h.charCodeAt(c)===42&&h.charCodeAt(c+1)===47))c++;c=Math.min(c+2,h.length);continue}break}let t=h.charCodeAt(c);if(t===93||t===125){i++;continue}}a+=h[i++]}return a}
|
|
4
|
+
export{ve};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
function f(r,e=!0){if(!e||!r||r.length===0)return"";if(r.length===1){let t=r[0];if(t.length>0&&t.charCodeAt(0)>32&&t.charCodeAt(t.length-1)>32)return`${t}
|
|
3
|
+
`;return`${t.trim()}
|
|
4
|
+
`}let n="";for(let t=0;t<r.length;t++){if(t>0)n+=`
|
|
5
|
+
`;n+=r[t].trim()}return`${n}
|
|
6
|
+
`}function Pe(r){return r.replaceAll("*/","*\\/")}
|
|
7
|
+
export{f,Pe};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{t,F}from"./chunk-1j6092xz.js";import{n}from"./chunk-8d3sdkv4.js";function Rn(p,y,D,k){let r=new Map,i=new Map;for(let e of[...y,...D.values(),...[...k.values()].flat()])if(r.set(e.name,e),e.kind==="function"&&!i.has(e.name))i.set(e.name,e);for(let[e,o]of k)if(o.length)i.set(e,o[0]);if(!i.size)return;let u=new Set;for(let[e,o]of k)if(o.length>1)u.add(e);let a=new Map;for(let e of y)if(e.kind==="function"){let o=(a.get(e.name)??0)+1;if(a.set(e.name,o),o>1)u.add(e.name)}let s=F(p),d=(e)=>s[e]?p.slice(s[e].start,s[e].end):"",g=new Map,h=0;for(let e=0;e<s.length;e++){let o=s[e];if(o.kind==="punctuation"){let l=p.charCodeAt(o.start);if(l===40||l===91||l===123)h++;else if(l===41||l===93||l===125)h--;continue}if(h||s[e+2]?.kind!=="word"||d(e+1)!=="."||d(e+3)!=="=")continue;let c=d(e);if(!i.has(c))continue;let b=d(e+2),x=e+4,f=x,m=0;for(;f<s.length;f++){let l=d(f);if(!m&&l===";")break;if(!m&&f>x&&/[\r\n]/.test(p.slice(s[f-1].end,s[f].start))&&(["export","const","let","var","function","class"].includes(l)||i.has(l)&&d(f+1)==="."))break;if(["(","[","{"].includes(l))m++;else if([")","]","}"].includes(l))m--}if(f===x)continue;let w=A(p.slice(s[x].start,s[f-1].end),r,u),M=g.get(c);if(!M)g.set(c,M=new Map);let v=M.get(b);if(!v)M.set(b,v=[]);if(!v.includes(w))v.push(w);e=f-1}for(let[e,o]of g){let c=i.get(e),b=[...o].map(([f,m])=>` let ${f}: ${m.map((w)=>w.includes("=>")&&m.length>1?`(${w})`:w).join(" | ")};`).join(`
|
|
3
|
+
`),x=c.isExported&&!c.isDefault?"export ":"";if(c.isDefault)c.text=c.text.replace("export default function ","declare function ");if(c.text+=`
|
|
4
|
+
${x}declare namespace ${e} {
|
|
5
|
+
${b}
|
|
6
|
+
}`,c.isDefault)c.text+=`
|
|
7
|
+
export default ${e};`}}function A(p,y,D,k=0){let r=p.trim(),i=y.get(r);if(i?.kind==="variable"&&k<64){if(i.typeAnnotation)return i.typeAnnotation==="unique symbol"?`typeof ${r}`:i.typeAnnotation;if(typeof i.value==="string")return A(i.value,y,D,k+1)}let u=n(r,!1);if(u!=="unknown")return u;let a=t(r);if(a[0]?.kind==="word"&&a[1]&&r.slice(a[1].start,a[1].end)==="("&&r.endsWith(")")){let s=0,d=-1;for(let e=1;e<a.length;e++){let o=r.slice(a[e].start,a[e].end);if(o==="(")s++;else if(o===")"&&--s===0){d=e;break}}if(d!==a.length-1)return u;let g=r.slice(a[0].start,a[0].end),h=y.get(g);if(h?.kind==="function"&&!h.generics&&!D.has(g))return`ReturnType<typeof ${g}>`}if(/^[$A-Z_a-z][$\w]*(?:\.[$A-Z_a-z][$\w]*)*$/.test(r))return`typeof ${r}`;return u}
|
|
8
|
+
export{Rn};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{s}from"./chunk-0zfzhn19.js";function ue(a={}){let{onStart:d=!1,onEnd:l=!0,onGenerated:u,onError:i,...n}=a,e=async()=>{try{let r=await s(n);u?.(r)}catch(r){let t=r instanceof Error?r:Error(String(r));if(i?.(t),!i)console.error("[dtsx] Generation failed:",t.message)}};return{name:"dtsx",setup(r){let t=r.initialOptions;if(!n.entrypoints&&t.entryPoints)if(Array.isArray(t.entryPoints))n.entrypoints=t.entryPoints;else n.entrypoints=Object.values(t.entryPoints);if(!n.outdir){if(t.outdir)n.outdir=t.outdir;else if(t.outfile){let o=t.outfile.lastIndexOf("/");if(o!==-1)n.outdir=t.outfile.substring(0,o)}}if(d)r.onStart(async()=>{await e()});if(l)r.onEnd(async(o)=>{if(o.errors.length===0)await e()})}}}var wa=ue,Zn=ue,xa=ue;
|
|
3
|
+
export{ue,wa,Zn,xa};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
function d(n,c){let o=1,l=1;for(let i=0;i<c;i++)if(n.charCodeAt(i)===10)o++,l=1;else l++;return{line:o,column:l}}function me(n){let c=[],o=[],l=[],i={")":"(","]":"[","}":"{"},r=0,m=0,f=-1;for(let e=0;e<n.length;e++){let t=n.charCodeAt(e),s=n.charCodeAt(e+1);if(f!==-1){if(t===42&&s===47)o.push({start:f,end:e+2}),f=-1,e++;continue}if(r){if(t===92)e++;else if(t===r)o.push({start:m,end:e+1}),r=0;continue}if(t===47&&s===42){f=e,e++;continue}if(t===47&&s===47){let u=e;while(e<n.length&&n.charCodeAt(e)!==10)e++;o.push({start:u,end:e});continue}if(t===39||t===34||t===96){r=t,m=e;continue}let a=n[e];if(a==="("||a==="["||a==="{")l.push({char:a,offset:e});else if(i[a]){let u=l.pop();if(!u||u.char!==i[a])c.push({...d(n,e),message:`Unexpected closing delimiter ${a}`,code:"DTSX1004"})}}if(r)c.push({...d(n,m),message:"Unterminated string literal",code:"DTSX1002"});if(f!==-1)c.push({...d(n,f),message:"Unterminated block comment",code:"DTSX1003"});for(let e of l)c.push({...d(n,e.offset),message:`Unclosed delimiter ${e.char}`,code:"DTSX1001"});let p=[[/\b(?:interface|class|enum)\s*(?=[{=])/g,"Declaration name expected"],[/\bfunction\s*(?=\()/g,"Function name expected"],[/\(\s*:/g,"Parameter name expected"]];for(let[e,t]of p)for(let s of n.matchAll(e)){if(o.some((a)=>s.index>=a.start&&s.index<a.end))continue;c.push({...d(n,s.index),message:t,code:"DTSX1005"})}for(let e of n.matchAll(/\btype\s*(?=[{=])/g)){if(o.some((s)=>e.index>=s.start&&e.index<s.end))continue;let t=n.slice(0,e.index).trimEnd();if(t.endsWith("import")||t.endsWith("export"))continue;c.push({...d(n,e.index),message:"Declaration name expected",code:"DTSX1005"})}return c.push(...g(n,o)),c.sort((e,t)=>e.line-t.line||e.column-t.column)}var h=String.raw`(?:[\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*|'[^']*'|"[^"]*")`,x=new RegExp(`^(?:type\\s+)?${h}(?:\\s+as\\s+${h})?$`,"u");function g(n,c){let o=[],l=(i)=>c.some((r)=>i>=r.start&&i<r.end);for(let i of n.matchAll(/\b(import|export)\s+(?:type\s+)?\{/g)){let r=i.index;if(l(r))continue;let m=r+i[0].length-1,f=-1;for(let t=m+1;t<n.length;t++){if(l(t))continue;let s=n[t];if(s==="{"){f=-2;break}if(s==="}"){f=t;break}}if(f<0)continue;let p=n.slice(m+1,f);if(!p.trim())continue;let e=m+1;for(let t of p.split(",")){let s=t.trim();if(s){let a=e+t.indexOf(s);if(s.includes(";"))o.push({...d(n,a),message:`Unexpected ';' in ${i[1]} clause \u2014 specifiers are separated by ','`,code:"DTSX1006"});else if(!x.test(s))o.push({...d(n,a),message:`Invalid ${i[1]} specifier '${s}'`,code:"DTSX1006"})}e+=t.length+1}}return o}
|
|
3
|
+
export{me};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{we}from"./chunk-g2120ysy.js";import{e}from"./chunk-yay68832.js";import{Ce,V}from"./chunk-p9vfxn8g.js";import{existsSync as x}from"fs";import{basename as D,dirname as M,extname as R,isAbsolute as v,relative as p,resolve as m}from"path";var{Glob:j}=globalThis.Bun;async function ye(r,o){let s=await N(r);F(r,s);let n=s.slice(),a=await(o?o():Ce(r)),t=null;if(r.autoIncludeReExports!==!1&&n.length>0){t=await V(n,{includeImports:!0,resolveSpecifier:a});let l=m(r.cwd,r.root),u=r.exclude||[],f=[];for(let c of t.reachable){if(n.includes(c))continue;if(!b(c))continue;if(c.endsWith(".d.ts"))continue;if(c.includes("node_modules"))continue;let E=r.outputStructure==="flat"&&s.some((O)=>a.isPackageLocal?.(O,c));if(!S(c,l)&&!E){e.warn(`Skipping auto-included source outside root: ${p(r.cwd,c)}`);continue}if(J(c,u,l))continue;f.push(c)}if(f.length>0)n=[...n,...f],e.debug(`Auto-included ${f.length} file(s) reached via relative re-exports`)}let i=A(n,r),d=t??await V(n,{includeImports:!0,resolveSpecifier:a}),g=await we([...d.sources.keys()],a,r.isolatedDeclarations??!1,d.sources),h=new Set(n);for(let[l,u]of g){if(!h.has(l))continue;for(let f of u){let c=a(f,l).resolved;if(c&&!h.has(c))throw Error(`Module augmentation import ${JSON.stringify(f)} from ${l} requires a source not emitted by this package build: ${c}`)}}let y=[...g].map(([l,u])=>[l,[...u].sort()]).sort(([l],[u])=>l.localeCompare(u));return Object.freeze({entryFiles:Object.freeze(s),files:Object.freeze(n),outputBySource:i,resolver:a,reachability:t,augmentationImports:g,getResolutionFingerprint:()=>JSON.stringify({resolution:a.cacheKey?.(n),augmentations:y})})}var P=50,w=new Map;function k(r){let o=w.get(r);if(!o){if(o=new j(r),w.set(r,o),w.size>P){let s=w.keys().next().value;if(s!==void 0)w.delete(s)}}return o}function J(r,o,s){if(!o||o.length===0)return!1;let n=p(s,r);for(let a of o){let t=k(a);if(t.match(n)||t.match(r))return!0}return!1}var C=/[*?[\]{}!]/;function F(r,o){let s=m(r.cwd,r.root),n=` root: ${s}
|
|
3
|
+
entrypoints: ${r.entrypoints.map((t)=>JSON.stringify(t)).join(", ")||"(none)"}
|
|
4
|
+
`+(r.exclude?.length?` exclude: ${r.exclude.map((t)=>JSON.stringify(t)).join(", ")}
|
|
5
|
+
`:"")+"Entrypoints are resolved relative to --root. Pass several by repeating --entrypoints or separating them with commas.";if(o.length===0){if(r.entrypoints.filter((i)=>v(i)&&x(i)&&!S(i,s)).length===r.entrypoints.length)return;throw Error(`No source files matched. Nothing was generated.
|
|
6
|
+
${n}`)}let a=r.entrypoints.filter((t)=>{if(C.test(t))return!1;return!x(v(t)?t:m(s,t))});if(a.length>0)throw Error(`Entrypoint${a.length>1?"s":""} not found: ${a.map((t)=>JSON.stringify(t)).join(", ")}
|
|
7
|
+
${n}`)}async function N(r){let o=[],s=m(r.cwd,r.root),n=r.exclude||[],a=[...r.entrypoints,...r.include??[]];for(let t of a)if(v(t)&&b(t)){if(!t.includes("node_modules")){if(!S(t,s)&&r.outputStructure!=="flat")e.warn(`Skipping entrypoint outside root: ${p(r.cwd,t)}`);else if(!J(t,n,s))o.push(t)}}else{let i=new j(t);for await(let d of i.scan({cwd:s,absolute:!0,onlyFiles:!0}))if(b(d)&&!d.includes("node_modules")){if(!J(d,n,s))o.push(d)}}return[...new Set(o.map((t)=>m(t)))].sort()}function S(r,o){let s=p(o,r);return s!==".."&&!s.startsWith(`..${process.platform==="win32"?"\\":"/"}`)&&!v(s)}function A(r,o){let s=new Map,n=new Map;for(let a of r){let t=G(a,o),i=s.get(t);if(i&&i!==a)throw Error(`Output path collision: ${p(o.cwd,i)} and ${p(o.cwd,a)} both emit ${p(o.cwd,t)}`);s.set(t,a),n.set(a,t)}return n}function b(r){return/\.(m?tsx?|cts|jsx?|mjs|cjs|vue|stx)$/.test(r)&&!/\.d\.(?:ts|mts|cts)$/.test(r)}function G(r,o){let s=m(o.cwd,o.root),n=p(s,r),a=/\.d\.(?:ts|mts|cts)$/.test(n)?n:n.replace(/\.(m?tsx?|cts|jsx?|mjs|cjs|vue|stx)$/,(t)=>{if(t===".mts"||t===".mjs")return".d.mts";if(t===".cts"||t===".cjs")return".d.cts";return".d.ts"});if(o.outputStructure==="mirror")return m(o.cwd,o.outdir,a);else{let t=D(a);return m(o.cwd,o.outdir,t)}}function Vo(r,o,s=""){let n=p(M(r),o).replace(/\\/g,"/");if(n=n.replace(/\.d\.mts$/,"").replace(/\.d\.cts$/,"").replace(/\.d\.ts$/,""),s)n+=s;if(!n.startsWith("."))n=`./${n}`;return n}function be(r,o,s,n){let a=G(r,o);return(t)=>{let i=s(t,r);if(!i.isRelative||!i.resolved)return{kind:"unchanged",reason:i.isRelative?"unresolved":"external",specifier:t,emittedSpecifier:t};if(/\.d\.(?:ts|mts|cts)$/.test(i.resolved)){if(o.moduleSpecifierMode!=="node")return{kind:"unchanged",reason:"preserved-declaration",specifier:t,emittedSpecifier:t};if(n&&!n.has(i.resolved))throw Error(`Local declaration ${JSON.stringify(t)} from ${r} targets an authored declaration not emitted by this package build: ${i.resolved}. Declaration-only dependencies must be delivered with the package before this importer can be emitted.`)}if(i.isAlias&&n&&!n.has(i.resolved))throw Error(`Local alias ${JSON.stringify(t)} from ${r} targets a declaration excluded from this package build: ${i.resolved}`);if(n&&!n.has(i.resolved)&&J(i.resolved,o.exclude??[],m(o.cwd,o.root)))throw Error(`Local reference ${JSON.stringify(t)} from ${r} targets a source excluded from this package build: ${i.resolved}`);let d=i.isAlias?i.suffix??"":t.match(/[?#].*$/)?.[0]??"",g=d?t.slice(0,-d.length):t,h=R(g),y=/^(?:\.js|\.jsx|\.mjs|\.cjs)$/.test(h)?h:"";if(!y&&o.moduleSpecifierMode==="node"){let u=R(i.resolved);y=u===".mts"||u===".mjs"?".mjs":u===".cts"||u===".cjs"?".cjs":".js"}let l=G(i.resolved,o);return{kind:"local",specifier:t,resolvedSource:i.resolved,declarationOutput:l,emittedSpecifier:Vo(a,l,y)+d}}}
|
|
8
|
+
export{ye,J,S,G,Vo,be};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{Z}from"./chunk-73dzve1s.js";function M(n,t){let e=n.length,i=t.length,o=Array.from({length:e+1},()=>Array(i+1).fill(0));for(let s=1;s<=e;s++)for(let r=1;r<=i;r++)if(n[s-1]===t[r-1])o[s][r]=o[s-1][r-1]+1;else o[s][r]=Math.max(o[s-1][r],o[s][r-1]);return o}function S(n,t,e,i,o){let s=[];while(i>0||o>0)if(i>0&&o>0&&t[i-1]===e[o-1])s.unshift({op:"equal",oldIdx:i-1,newIdx:o-1,line:t[i-1]}),i--,o--;else if(o>0&&(i===0||n[i][o-1]>=n[i-1][o]))s.unshift({op:"add",newIdx:o-1,line:e[o-1]}),o--;else if(i>0)s.unshift({op:"remove",oldIdx:i-1,line:t[i-1]}),i--;return s}function k(n,t){let e=n;if(t.ignoreWhitespace)e=e.replace(/\s+/g," ").trim();return e}function ot(n,t,e,i={}){let{context:o=3,ignoreWhitespace:s=!1,ignoreBlankLines:r=!1}=i,f=n.split(`
|
|
3
|
+
`),p=t.split(`
|
|
4
|
+
`);if(f[f.length-1]==="")f.pop();if(p[p.length-1]==="")p.pop();let d=f.map((l)=>k(l,{ignoreWhitespace:s})),a=p.map((l)=>k(l,{ignoreWhitespace:s})),c=d,g=a,w=f.map((l,x)=>x),m=p.map((l,x)=>x);if(r)c=[],g=[],w=[],m=[],d.forEach((l,x)=>{if(l.trim())c.push(l),w.push(x)}),a.forEach((l,x)=>{if(l.trim())g.push(l),m.push(x)});let F=M(c,g),b=S(F,c,g,c.length,g.length),B=b.every((l)=>l.op==="equal"),D=0,u=0,h=0;for(let l of b)if(l.op==="add")D++;else if(l.op==="remove")u++;else h++;let y=C(b,f,p,w,m,o);return{filePath:e,identical:B,hunks:y,stats:{additions:D,deletions:u,unchanged:h},oldContent:n,newContent:t}}function C(n,t,e,i,o,s){let r=[],f=[];if(n.forEach((a,c)=>{if(a.op!=="equal")f.push(c)}),f.length===0)return r;let p=[],d=[f[0]];for(let a=1;a<f.length;a++)if(f[a]-f[a-1]<=s*2+1)d.push(f[a]);else p.push(d),d=[f[a]];p.push(d);for(let a of p){let c=Math.max(0,a[0]-s),g=Math.min(n.length-1,a[a.length-1]+s),w=n.slice(c,g+1),m=[],F=1,b=1,B=0,D=0;for(let u=0;u<c;u++){let h=n[u];if(h.op==="equal"||h.op==="remove")F++;if(h.op==="equal"||h.op==="add")b++}for(let u of w)if(u.op==="equal")m.push(` ${u.line}`),B++,D++;else if(u.op==="remove")m.push(`-${u.line}`),B++;else if(u.op==="add")m.push(`+${u.line}`),D++;r.push({operation:"equal",lines:m,oldStart:F,oldCount:B,newStart:b,newCount:D})}return r}function _i(n){if(n.identical)return"";let t=[];t.push(`--- a/${n.filePath}`),t.push(`+++ b/${n.filePath}`);for(let e of n.hunks)t.push(`@@ -${e.oldStart},${e.oldCount} +${e.newStart},${e.newCount} @@`),t.push(...e.lines);return t.join(`
|
|
5
|
+
`)}function ir(n){if(n.identical)return`\x1B[32m\u2713 ${n.filePath} (unchanged)\x1B[0m`;let t=[],e=`+${n.stats.additions} -${n.stats.deletions}`;t.push(`\x1B[1m${n.filePath}\x1B[0m \x1B[90m(${e})\x1B[0m`),t.push("");for(let i of n.hunks){t.push(`\x1B[36m@@ -${i.oldStart},${i.oldCount} +${i.newStart},${i.newCount} @@\x1B[0m`);for(let o of i.lines)if(o.startsWith("+"))t.push(`\x1B[32m${o}\x1B[0m`);else if(o.startsWith("-"))t.push(`\x1B[31m${o}\x1B[0m`);else t.push(`\x1B[90m${o}\x1B[0m`);t.push("")}return t.join(`
|
|
6
|
+
`)}function Gi(n){if(n.identical)return`${n.filePath}: unchanged`;return`${n.filePath}: +${n.stats.additions} -${n.stats.deletions} lines`}async function sr(n,t,e={}){let i="";try{let o=Z(n);if(await o.exists())i=await o.text();else if(!e.treatMissingAsEmpty)return ot("",t,n,e)}catch{if(!e.treatMissingAsEmpty)return ot("",t,n,e)}return ot(i,t,n,e)}async function Vi(n,t={}){let e=new Map;for(let[i,o]of n){let s=await sr(i,o,t);e.set(i,s)}return e}function or(n){let t=0,e=0,i=0,o=0,s=0;for(let r of n.values())if(r.identical)e++;else if(t++,i+=r.stats.additions,o+=r.stats.deletions,!r.oldContent)s++;return{totalFiles:n.size,changedFiles:t,unchangedFiles:e,totalAdditions:i,totalDeletions:o,newFiles:s}}function ar(n){console.log(ir(n))}function Ui(n,t=!1){for(let i of n.values()){if(i.identical&&!t)continue;ar(i)}let e=or(n);if(console.log(""),console.log(`\x1B[1mSummary:\x1B[0m ${e.totalFiles} files, ${e.changedFiles} changed, ${e.unchangedFiles} unchanged`),e.changedFiles>0)console.log(` \x1B[32m+${e.totalAdditions}\x1B[0m \x1B[31m-${e.totalDeletions}\x1B[0m lines`);if(e.newFiles>0)console.log(` ${e.newFiles} new files`)}
|
|
7
|
+
export{ot,_i,ir,Gi,sr,Vi,or,ar,Ui};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
function rt(e,r={}){let{entryPoints:n,keepExported:s=!0,keep:t=[],remove:l=[],shakableKinds:c=["type","interface"],debug:m=!1}=r,p=m?console.log.bind(console,"[tree-shake]"):()=>{},x=new Map;for(let a of e)x.set(a.name,a);let i=it(e);p("Dependency graph:",Object.fromEntries(Array.from(i.entries()).map(([a,d])=>[a,Array.from(d)])));let o=new Set;if(n&&n.length>0){for(let a of n)if(x.has(a))o.add(a)}else{let a=new Set(c);for(let d of e){if(s&&d.isExported){o.add(d.name);continue}if(k(d.name,t)){o.add(d.name);continue}if(!a.has(d.kind))o.add(d.name)}}if(n&&n.length>0&&t.length>0){for(let a of e)if(k(a.name,t))o.add(a.name)}p("Entry points:",Array.from(o));let f=T(o,i);p("Reachable:",Array.from(f));let u=new Set,g=[];for(let a of e){let d=a.name;if(f.has(d)){u.add(d);continue}if(k(d,l)){g.push(d);continue}if(!c.includes(a.kind)){u.add(d);continue}g.push(d)}p("Keeping:",Array.from(u)),p("Removing:",g);let b=e.filter((a)=>u.has(a.name)),y={totalBefore:e.length,totalAfter:b.length,removedCount:g.length,reductionPercent:e.length>0?Math.round(g.length/e.length*100):0};return{declarations:b,removed:g,dependencyGraph:i,stats:y}}function it(e){let r=new Map,n=new Set;for(let s=0;s<e.length;s++)n.add(e[s].name);for(let s of e){let t=new Set,l=st(s);for(let c of l)if(n.has(c)&&c!==s.name)t.add(c);r.set(s.name,t)}return r}function st(e){let r=new Set;if(e.typeAnnotation)h(e.typeAnnotation,r);if(e.extends)h(e.extends,r);if(e.text)R(e.text,r);if(e.members)for(let n of e.members){let s=st(n);for(let t of s)r.add(t)}if(e.parameters){for(let n of e.parameters)if(n.type)h(n.type,r)}if(e.returnType)h(e.returnType,r);return r}var E=new Set(["string","number","boolean","object","any","unknown","never","void","null","undefined","symbol","bigint","true","false","Array","Object","String","Number","Boolean","Function","Symbol","Promise","Map","Set","WeakMap","WeakSet","Record","Partial","Required","Readonly","Pick","Omit","Exclude","Extract","NonNullable","Parameters","ReturnType","InstanceType","ConstructorParameters","ThisParameterType","OmitThisParameter","ThisType","Uppercase","Lowercase","Capitalize","Uncapitalize","Awaited","keyof","typeof","infer","extends","readonly","const","new"]),S=/\b([A-Z]\w*)\b/g,D=/\btypeof\s+([$A-Z_a-z][$\w]*)/g;function h(e,r){S.lastIndex=0;let n;while((n=S.exec(e))!==null){let s=n[1];if(!E.has(s))r.add(s)}D.lastIndex=0;while((n=D.exec(e))!==null)r.add(n[1])}function R(e,r){h(e,r)}function T(e,r){let n=new Set,s=Array.from(e);while(s.length>0){let t=s.pop();if(n.has(t))continue;n.add(t);let l=r.get(t);if(l){for(let c of l)if(!n.has(c))s.push(c)}}return n}function k(e,r){for(let n of r)if(typeof n==="string"){if(n.includes("*")){if(new RegExp(`^${n.replace(/\*/g,".*").replace(/\?/g,".")}$`).test(e))return!0}else if(e===n)return!0}else if(n.test(e))return!0;return!1}function tr(e,r={}){let n=e.split(`
|
|
3
|
+
`),s=[],t=null;for(let i=0;i<n.length;i++){let o=n[i],f=o.trim();if(!t&&(f===""||f.startsWith("//")))continue;if(!t){let u=f.match(/^(export\s+)?(declare\s+)?(interface|type|enum|class|function|const|let|var)\s+(\w+)/);if(u){let[,g,,b,y]=u;if(t={name:y,kind:b,isExported:!!g,start:i,lines:[o],braceCount:0},t.braceCount+=(o.match(/\{/g)||[]).length,t.braceCount-=(o.match(/\}/g)||[]).length,t.braceCount===0&&(f.endsWith(";")||!f.includes("{")))s.push({name:t.name,kind:t.kind,isExported:t.isExported,start:t.start,end:i,text:t.lines.join(`
|
|
4
|
+
`)}),t=null;continue}}if(t){if(t.lines.push(o),t.braceCount+=(o.match(/\{/g)||[]).length,t.braceCount-=(o.match(/\}/g)||[]).length,t.braceCount<=0&&(f.endsWith("}")||f.endsWith(";")))s.push({name:t.name,kind:t.kind,isExported:t.isExported,start:t.start,end:i,text:t.lines.join(`
|
|
5
|
+
`)}),t=null}}if(s.length===0)return{content:e,removed:[]};let l=s.map((i)=>({name:i.name,kind:i.kind,isExported:i.isExported,text:i.text})),c=rt(l,r),m=new Set(c.declarations.map((i)=>i.name)),p=new Set;for(let i of s)if(!m.has(i.name))for(let o=i.start;o<=i.end;o++)p.add(o);return{content:n.filter((i,o)=>!p.has(o)).join(`
|
|
6
|
+
`).replace(/\n{3,}/g,`
|
|
7
|
+
|
|
8
|
+
`),removed:c.removed}}function nr(e,r={}){return rt(e,{...r,debug:!1}).removed}function rr(e,r){let n=it(r),s=n.get(e)||new Set,t=T(new Set([e]),n);t.delete(e);let l=[];for(let[c,m]of n)if(c!==e&&m.has(e))l.push(c);return{directDependencies:Array.from(s),transitiveDependencies:Array.from(t),dependents:l}}function ji(e={}){return{shake:(r)=>rt(r,e),shakeContent:(r)=>tr(r,e),findUnused:(r)=>nr(r,e),analyzeDependencies:(r,n)=>rr(r,n),buildGraph:it,extractRefs:st}}
|
|
9
|
+
export{rt,it,st,tr,nr,rr,ji};
|