// @bun
import{Cc as Kz,Dc as Uz,Ec as P,Lc as u,Mc as p,Nc as jz}from"./chunk-sv136qag.js";function _(z,X=!0){if(!X||!z||z.length===0)return"";if(z.length===1)return z[0].trim()+`
`;let K="";for(let Z=0;Z<z.length;Z++){if(Z>0)K+=`
`;K+=z[Z].trim()}return`${K}
`}function Jz(z){if(z.includes(`
`))return`/**
 * ${z}
 */
`;return`/** ${z} */
`}function Xz(z){let X=z.indexOf("{");if(X===-1)return-1;let K=z.indexOf("<");if(K===-1||K>X)return X;let Z=0,H=!1,j="";for(let Y=0;Y<z.length;Y++){let J=z[Y],G=Y>0?z[Y-1]:"";if(!H&&(J==='"'||J==="'"||J==="`"))H=!0,j=J;else if(H&&J===j&&G!=="\\")H=!1;if(!H){if(J==="<")Z++;else if(J===">")Z--;else if(J==="{"&&Z===0)return Y}}return-1}function n(z,X=!0){return _(z.leadingComments,X)+z.text}function c(z,X=!0){let K=_(z.leadingComments,X);if(z.typeAnnotation&&!z.value)return K+z.text;let Z="";if(z.isExported)Z+="export ";Z+="declare ";let H=z.modifiers?.[0]||"const";Z+=`${H} `,Z+=z.name;let{typeAnnotation:j,value:Y}=z;if(Y&&Y.includes(" satisfies ")){let G=p(Y);if(G)j=G}else if(Y&&Y.trim().endsWith("as const"))j=P(Y,!0);else if(!j&&Y&&H==="const"){let G=Y.trim(),W=G.startsWith("{")||G.startsWith("[");if(W)Kz();j=P(Y,!W)}else if(j&&Y&&H==="const"&&u(j)){let G=P(Y,!0);if(G!=="unknown")j=G}else if(!j&&Y)j=P(Y,H==="const");if(!j)j="unknown";let J="";if(Y&&!z.typeAnnotation&&!Y.trim().endsWith("as const")){let G=Y.trim();if(H!=="const"){if((j==="string"||j==="number"||j==="boolean")&&G.length>0)J=`@defaultValue ${G}`}else if(G.startsWith("{")||G.startsWith("[")){let W=Uz();if(W)if(W.includes(`
`))J=`@defaultValue
 * \`\`\`ts
${W.split(`
`).map((R)=>` * ${R}`).join(`
`)}
 * \`\`\``;else J=`@defaultValue \`${W}\``}}if(Z+=`: ${j};`,J&&K&&K.includes("@defaultValue"))J="";if(J&&K){let G=K.trimEnd(),W=G.lastIndexOf("*/");if(W!==-1){let R=G.slice(0,W).trimEnd();if(R.startsWith("/** ")&&!R.includes(`
`))R=`/**
 * ${R.slice(4)}`;return`${R}
 * ${J}
 */
`+Z}return`/**
 * ${G.replace(/^\/\/\s*/,"")}
 * ${J}
 */
${Z}`}if(J)return`${Jz(J)}${Z}`;return K+Z}function d(z,X=!0){let K=_(z.leadingComments,X),Z=z.text;if(Z.startsWith("export declare interface")||Z.startsWith("declare interface"))return K+Z;let H="";if(z.isExported)H+="export ";if(H+="declare interface ",H+=z.name,z.generics)H+=z.generics;if(z.extends)H+=` extends ${z.extends}`;let j=Xz(z.text);if(j!==-1)H+=` ${z.text.slice(j)}`;else H+=" {}";return K+H}function l(z,X=!0){let K=_(z.leadingComments,X);if(z.text.includes("{")&&z.text.includes("}")&&z.text.includes("from"))return K+z.text;let Z="";if(z.isExported)Z+="export ";if(!z.isExported&&!z.text.includes(" from "))Z+="declare ";let H=z.text.indexOf("type ");if(H!==-1){let Y=z.text.slice(H),J=Y.length;while(J>0&&(Y.charCodeAt(J-1)===59||Y.charCodeAt(J-1)===32||Y.charCodeAt(J-1)===10||Y.charCodeAt(J-1)===13))J--;if(J<Y.length)Y=Y.slice(0,J);Z+=Y}else{if(Z+=`type ${z.name}`,z.generics)Z+=z.generics;Z+=" = any"}let j=Z.trimEnd();if(!j.endsWith(";")&&!j.endsWith("}"))Z+=";";return K+Z}function i(z,X=!0){return _(z.leadingComments,X)+z.text}function o(z,X=!0){let K=_(z.leadingComments,X),Z="";if(z.isExported)Z+="export ";if(Z+="declare ",z.modifiers?.includes("const"))Z+="const ";Z+="enum ",Z+=z.name;let H=z.text.indexOf("{");if(H!==-1)Z+=` ${z.text.slice(H)}`;else Z+=" {}";return K+Z}function Lz(z){let X=z.text.trim(),K=X.length;while(K>0&&X.charCodeAt(K-1)===59)K--;if(K<X.length)X=X.slice(0,K);return X+=";",X}function Gz(z,X=!0){return _(z.leadingComments,X)+z.text.trim()}function s(z,X=!0){let K=_(z.leadingComments,X);if(z.text.startsWith("declare global"))return K+z.text;if(z.source||(z.name.startsWith('"')||z.name.startsWith("'")||z.name.startsWith("`"))){let Y="declare module ";Y+=z.name;let J=z.text.indexOf("{");if(J!==-1)Y+=` ${z.text.slice(J)}`;else Y+=" {}";return K+Y}let H="";if(z.isExported)H+="export ";if(!z.modifiers?.includes("declare"))H+="declare ";H+="namespace ",H+=z.name;let j=z.text.indexOf("{");if(j!==-1)H+=` ${z.text.slice(j)}`;else H+=" {}";return K+H}var Rz=new Map,T=new Map;function Yz(z){return T.get(z)??null}function m(z,X){if(T.set(z,X),T.size>200){let K=0;for(let Z of T.keys()){if(K++>=20)break;T.delete(Z)}}}function Wz(){Rz.clear(),T.clear()}function a(z){let X=z.indexOf(" from ");if(X===-1)return null;let K=z.slice(X+6).trim(),Z=K[0];if(Z!=='"'&&Z!=="'")return null;let H=K.indexOf(Z,1);if(H===-1)return null;let j=K.slice(1,H),Y=z.slice(0,X).trim(),J=Y.startsWith("import type ");if(Y.startsWith("import "))Y=Y.slice(7).trim();if(Y.startsWith("type "))Y=Y.slice(5).trim();let G=null,W=[],Q=Y.indexOf("{"),R=Y.lastIndexOf("}");if(Q!==-1&&R!==-1){let D=Y.slice(0,Q).trim();if(D.endsWith(","))G=D.slice(0,-1).trim()||null;let w=Y.slice(Q+1,R),b=0;for(let S=0;S<=w.length;S++)if(S===w.length||w.charCodeAt(S)===44){let F=b,O=S;while(F<O&&(w.charCodeAt(F)===32||w.charCodeAt(F)===9||w.charCodeAt(F)===10))F++;while(O>F&&(w.charCodeAt(O-1)===32||w.charCodeAt(O-1)===9||w.charCodeAt(O-1)===10))O--;if(F<O)W.push(w.slice(F,O));b=S+1}}else G=Y.trim()||null;return{defaultName:G,namedItems:W,source:j,isTypeOnly:J}}function r(z){let X=Yz(z);if(X)return X;let K=[],Z=z.indexOf(" from ");if(Z===-1)return m(z,K),K;let H=z.slice(0,Z).trim();if(H.startsWith("import "))H=H.slice(7).trim();if(H.startsWith("type "))H=H.slice(5).trim();let j=H.indexOf("{"),Y=H.lastIndexOf("}");if(j!==-1&&Y!==-1){let J=H.slice(0,j).trim();if(J.endsWith(",")){let Q=J.slice(0,-1).trim();if(Q)K.push(Q)}else if(J&&!J.includes(","))K.push(J);let W=H.slice(j+1,Y).split(",");for(let Q=0;Q<W.length;Q++){let R=W[Q].trim();if(!R)continue;if(R.startsWith("type "))R=R.slice(5).trim();let D=R.indexOf(" as ");if(D!==-1)R=R.slice(D+4).trim();if(R)K.push(R)}}else{let J=H.trim();if(J)K.push(J)}return m(z,K),K}function Zz(z,X){throw Error(X||`Unexpected value: ${z}`)}function Vz(z){return z>=65&&z<=90||z>=97&&z<=122||z>=48&&z<=57||z===95||z===36||z>127}function $z(z){let X=new Set,K=0,Z=z.length;while(K<Z){let H=z.charCodeAt(K);if(H>=65&&H<=90||H>=97&&H<=122||H===95||H===36||H>127){let j=K;K++;while(K<Z&&Vz(z.charCodeAt(K)))K++;X.add(z.substring(j,K))}else K++}return X}var Qz=/export\s+(?:type\s+)?\{\s*([^}]+)\s*\}/;function Tz(z,X,K=!0,Z=["bun"]){let H="",j=X.sourceCode;if(j){let U=0;while(U<j.length&&(j.charCodeAt(U)===32||j.charCodeAt(U)===9||j.charCodeAt(U)===10||j.charCodeAt(U)===13))U++;if(U<j.length-2&&j.charCodeAt(U)===47&&j.charCodeAt(U+1)===47&&j.charCodeAt(U+2)===47){let L=jz(j);if(L.length>0)for(let V=0;V<L.length;V++){if(H)H+=`
`;H+=L[V]}}}let Y=[],J=[],G=[],W=[],Q=[],R=[],D=[],w=[],b=[];for(let U of z){let L=U.kind;switch(L){case"import":Y.push(U);break;case"function":J.push(U);break;case"variable":G.push(U);break;case"interface":W.push(U);break;case"type":Q.push(U);break;case"class":R.push(U);break;case"enum":D.push(U);break;case"module":w.push(U);break;case"export":b.push(U);break;case"namespace":w.push(U);break;case"unknown":break;default:Zz(L,`Unhandled declaration kind: ${L}`)}}let S=new Set,F=[],O=[],x=[],t=new Set;for(let U of b){let L=_(U.leadingComments,K);if(U.text.startsWith("export default")){let V=U.text.endsWith(";")?U.text:`${U.text};`;x.push(L+V)}else{let V=U.text.trim();if(!V.endsWith(";"))V+=";";let M=V.match(Qz);if(M){let q=M[1].split(",").map((B)=>B.trim());for(let B of q)S.add(B)}let $=L+V;if(!t.has($))if(t.add($),$.includes("export type"))F.push($);else O.push($)}}let y=new Map;if(Y.length>0)for(let U of Y){let L=r(U.text);for(let V of L)y.set(V,U)}let e=new Set;if(W.length>0){let U=[];for(let L of J)if(L.isExported)U.push(L.text);for(let L of R)U.push(L.text);for(let L of Q)U.push(L.text);if(U.length>0){let L=$z(U.join(`
`));for(let V of W)if(L.has(V.name))e.add(V.name)}}let N=[];if(Y.length>0){let U=new Set,L=[];for(let $ of J)if($.isExported)L.push($.text);for(let $ of G)if($.isExported){if(L.push($.text),$.typeAnnotation)L.push($.typeAnnotation)}for(let $ of W)if($.isExported||e.has($.name))L.push($.text);for(let $ of Q)L.push($.text);for(let $ of R)L.push($.text);for(let $ of D)L.push($.text);for(let $ of w)L.push($.text);for(let $ of b)L.push($.text);let V=L.join(`
`);if(V&&y.size>0){let $=$z(V);for(let q of y.keys())if($.has(q))U.add(q)}for(let $ of S)if(y.has($))U.add($);for(let $ of Y){if($.isSideEffect){let E=$.text.trim(),g=E.endsWith(";")?E:`${E};`;N.push(g);continue}let q=a($.text);if(!q)continue;let{defaultName:B,namedItems:A,source:v,isTypeOnly:k}=q,h=B?U.has(B):!1,I="",C=0;for(let E=0;E<A.length;E++){let g=A[E],f=g.charCodeAt(0)===116&&g.startsWith("type ")?g.slice(5).trim():g.trim(),Hz=f.indexOf(" as ");if(Hz!==-1)f=f.slice(Hz+4).trim();if(U.has(f)){if(C>0)I+=", ";I+=g,C++}}if(h||C>0){let E=k?"import type ":"import ";if(h&&B)E+=C>0?`${B}, { ${I} }`:B;else if(C>0)E+=`{ ${I} }`;E+=` from '${v}';`,N.push(E)}}let M=Z.length;if(N.length>1){let $=Z.map((A)=>`from '${A}`),q=Z.map((A)=>`from "${A}`),B=new Map;for(let A of N){let v=M;for(let k=0;k<Z.length;k++)if(A.includes($[k])||A.includes(q[k])){v=k;break}B.set(A,v)}N.sort((A,v)=>{let k=B.get(A),h=B.get(v);return k!==h?k-h:A.localeCompare(v)})}}for(let U=0;U<N.length;U++){if(H)H+=`
`;H+=N[U]}for(let U=0;U<F.length;U++){if(H)H+=`
`;H+=F[U]}let zz=[J,G,W,Q,R,D,w];for(let U=0;U<zz.length;U++){let L=zz[U];for(let V=0;V<L.length;V++){let M=L[V],$="",q=M.kind;switch(q){case"function":$=n(M,K);break;case"variable":$=c(M,K);break;case"interface":$=d(M,K);break;case"type":$=l(M,K);break;case"class":$=i(M,K);break;case"enum":$=o(M,K);break;case"module":case"namespace":$=s(M,K);break;case"import":case"export":case"unknown":break;default:Zz(q,`Unhandled declaration kind in processor: ${q}`)}if($){if(H)H+=`
`;H+=$}}}for(let U=0;U<O.length;U++){if(H)H+=`
`;H+=O[U]}for(let U=0;U<x.length;U++){if(H)H+=`
`;H+=x[U]}return H}export{_ as oc,n as pc,c as qc,d as rc,l as sc,i as tc,o as uc,Lz as vc,Gz as wc,s as xc,Wz as yc,a as zc,r as Ac,Tz as Bc};
