// @bun
import{ec as K}from"./chunk-b0bkjk0p.js";import{Vc as _}from"./chunk-57agx6g8.js";import{existsSync as j,mkdirSync as w,readFileSync as b,writeFileSync as V}from"fs";import{basename as H,join as R}from"path";function N(q){let z={description:"",params:[],examples:[],tags:{},see:[],throws:[]};if(!q||q.length===0)return z;for(let A of q){let G=A.replace(/^\/\*\*/,"").replace(/\*\/$/,"").split(`
`).map((X)=>X.replace(/^\s*\*\s?/,"")).join(`
`).trim(),Q=G.search(/@\w+/);if(Q===-1){z.description=G;continue}else if(Q>0)z.description=G.slice(0,Q).trim(),G=G.slice(Q);let U=/@(\w+)(?:\s+\{([^}]+)\})?\s*([^\n@]*(?:\n(?!@)[^\n@]*)*)/g,W;while((W=U.exec(G))!==null){let[,X,Y,Z]=W,$=Z.trim();switch(X){case"param":{let v=$.match(/^(\[)?(\w+)\]?\s*(?:-\s*)?(.*)/);if(v)z.params.push({name:v[2],type:Y,description:v[3].trim(),optional:!!v[1]});break}case"returns":case"return":z.returns={type:Y,description:$};break;case"example":z.examples.push($);break;case"deprecated":z.deprecated=$||"Deprecated";break;case"since":z.since=$;break;case"see":z.see.push($);break;case"throws":case"throw":z.throws.push({type:Y,description:$});break;case"category":z.category=$;break;default:if(!z.tags[X])z.tags[X]=[];z.tags[X].push($)}}}return z}function M(q,z){let A=N(q.leadingComments),G="";switch(q.kind){case"function":G=h(q);break;case"variable":G=T(q);break;case"interface":G=F(q);break;case"type":G=S(q);break;case"class":G=k(q);break;case"enum":G=x(q);break;default:G=q.text||q.name}let Q={name:q.name,kind:q.kind,signature:G,jsdoc:A,isExported:q.isExported,isDefault:q.isDefault,sourceFile:z};if(q.members&&q.members.length>0)Q.members=q.members.map((U)=>M(U,z));return Q}function h(q){let z=[];if(q.isExported)z.push("export");if(q.isDefault)z.push("default");if(z.push("function"),z.push(q.name),q.generics)z.push(q.generics);if(q.parameters){let A=q.parameters.map((G)=>{let Q="";if(G.rest)Q+="...";if(Q+=G.name,G.optional)Q+="?";if(G.type)Q+=`: ${G.type}`;return Q}).join(", ");z.push(`(${A})`)}else z.push("()");if(q.returnType)z.push(`: ${q.returnType}`);return z.join(" ").replace(/\s+/g," ")}function T(q){let z=[];if(q.isExported)z.push("export");if(z.push("const"),z.push(q.name),q.typeAnnotation)z.push(`: ${q.typeAnnotation}`);return z.join(" ")}function F(q){let z=[];if(q.isExported)z.push("export");if(z.push("interface"),z.push(q.name),q.generics)z.push(q.generics);if(q.extends)z.push(`extends ${q.extends}`);return z.join(" ")}function S(q){let z=[];if(q.isExported)z.push("export");if(z.push("type"),z.push(q.name),q.generics)z.push(q.generics);if(z.push("="),q.typeAnnotation)z.push(q.typeAnnotation);return z.join(" ")}function k(q){let z=[];if(q.isExported)z.push("export");if(q.isDefault)z.push("default");if(z.push("class"),z.push(q.name),q.generics)z.push(q.generics);if(q.extends)z.push(`extends ${q.extends}`);if(q.implements&&q.implements.length>0)z.push(`implements ${q.implements.join(", ")}`);return z.join(" ")}function x(q){let z=[];if(q.isExported)z.push("export");return z.push("enum"),z.push(q.name),z.join(" ")}async function P(q,z={}){let A=[],G=new Map;for(let Q of q){if(!j(Q)){_.warn(`File not found: ${Q}`);continue}let U=b(Q,"utf-8"),W=K(U,Q,!0);for(let X of W){if(X.kind==="import")continue;if(!z.includePrivate&&X.name.startsWith("_"))continue;if(!z.includeInternal&&X.leadingComments?.some((Z)=>Z.includes("@internal")))continue;let Y=M(X,Q);if(A.push(Y),z.groupByCategory&&Y.jsdoc.category){let Z=Y.jsdoc.category;if(!G.has(Z))G.set(Z,[]);G.get(Z).push(Y)}}}return{title:z.title||"API Documentation",description:z.description,entries:A,categories:G,generatedAt:new Date}}function B(q,z={}){let A=[];if(A.push(`# ${q.title}`),A.push(""),q.description)A.push(q.description),A.push("");if(A.push(`> Generated on ${q.generatedAt.toISOString()}`),A.push(""),A.push("## Table of Contents"),A.push(""),z.groupByCategory&&q.categories.size>0)for(let G of q.categories.keys())A.push(`- [${G}](#${E(G)})`);else{let G=I(q.entries);for(let[Q,U]of G)if(U.length>0)A.push(`- [${O(Q)}](#${E(O(Q))})`)}if(A.push(""),z.groupByCategory&&q.categories.size>0)for(let[G,Q]of q.categories){A.push(`## ${G}`),A.push("");for(let U of Q)A.push(...L(U,z))}else{let G=I(q.entries);for(let[Q,U]of G)if(U.length>0){A.push(`## ${O(Q)}`),A.push("");for(let W of U)A.push(...L(W,z))}}return A.join(`
`)}function L(q,z){let A=[];if(A.push(`### ${q.name}`),A.push(""),q.jsdoc.deprecated)A.push(`> **Deprecated:** ${q.jsdoc.deprecated}`),A.push("");if(A.push("```typescript"),A.push(q.signature),A.push("```"),A.push(""),q.jsdoc.description)A.push(q.jsdoc.description),A.push("");if(q.jsdoc.params.length>0){A.push("**Parameters:**"),A.push(""),A.push("| Name | Type | Description |"),A.push("|------|------|-------------|");for(let G of q.jsdoc.params){let Q=G.optional?" (optional)":"",U=G.type||"any";A.push(`| \`${G.name}\`${Q} | \`${U}\` | ${G.description} |`)}A.push("")}if(q.jsdoc.returns){A.push("**Returns:**"),A.push("");let G=q.jsdoc.returns.type?`\`${q.jsdoc.returns.type}\``:"";A.push(`${G} ${q.jsdoc.returns.description}`),A.push("")}if(q.jsdoc.throws.length>0){A.push("**Throws:**"),A.push("");for(let G of q.jsdoc.throws){let Q=G.type?`\`${G.type}\``:"";A.push(`- ${Q} ${G.description}`)}A.push("")}if(q.jsdoc.examples.length>0){A.push("**Examples:**"),A.push("");for(let G of q.jsdoc.examples)A.push("```typescript"),A.push(G),A.push("```"),A.push("")}if(q.jsdoc.see.length>0){A.push("**See also:**"),A.push("");for(let G of q.jsdoc.see)A.push(`- ${G}`);A.push("")}if(q.jsdoc.since)A.push(`*Since: ${q.jsdoc.since}*`),A.push("");if(z.includeSourceLinks&&q.sourceFile){let G=q.sourceFile;if(z.sourceBaseUrl)A.push(`[Source](${z.sourceBaseUrl}/${G})`);else A.push(`*Source: ${G}*`);A.push("")}if(q.members&&q.members.length>0){A.push("**Members:**"),A.push("");for(let G of q.members)if(A.push(`#### ${G.name}`),A.push(""),A.push("```typescript"),A.push(G.signature),A.push("```"),A.push(""),G.jsdoc.description)A.push(G.jsdoc.description),A.push("")}return A.push("---"),A.push(""),A}function C(q,z={}){let A=B(q,z);return`<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>${f(q.title)}</title>
  <style>
    :root {
      --bg: #ffffff;
      --text: #1a1a1a;
      --code-bg: #f4f4f4;
      --border: #e0e0e0;
      --link: #0066cc;
    }
    @media (prefers-color-scheme: dark) {
      :root {
        --bg: #1a1a1a;
        --text: #e0e0e0;
        --code-bg: #2d2d2d;
        --border: #404040;
        --link: #66b3ff;
      }
    }
    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
      line-height: 1.6;
      max-width: 900px;
      margin: 0 auto;
      padding: 2rem;
      background: var(--bg);
      color: var(--text);
    }
    h1, h2, h3, h4 { margin-top: 2rem; }
    code {
      background: var(--code-bg);
      padding: 0.2em 0.4em;
      border-radius: 3px;
      font-family: 'Monaco', 'Menlo', monospace;
      font-size: 0.9em;
    }
    pre {
      background: var(--code-bg);
      padding: 1rem;
      border-radius: 6px;
      overflow-x: auto;
    }
    pre code {
      padding: 0;
      background: none;
    }
    table {
      border-collapse: collapse;
      width: 100%;
      margin: 1rem 0;
    }
    th, td {
      border: 1px solid var(--border);
      padding: 0.5rem;
      text-align: left;
    }
    th { background: var(--code-bg); }
    a { color: var(--link); }
    blockquote {
      border-left: 4px solid var(--border);
      margin: 1rem 0;
      padding-left: 1rem;
      color: #666;
    }
    hr {
      border: none;
      border-top: 1px solid var(--border);
      margin: 2rem 0;
    }
    .deprecated {
      background: #fff3cd;
      border-left: 4px solid #ffc107;
      padding: 0.5rem 1rem;
      margin: 1rem 0;
    }
    @media (prefers-color-scheme: dark) {
      .deprecated {
        background: #3d3000;
        border-left-color: #ffc107;
      }
    }
  </style>
</head>
<body>
  <article id="content"></article>
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
  <script>
    const markdown = ${JSON.stringify(A)};
    document.getElementById('content').innerHTML = marked.parse(markdown);
  </script>
</body>
</html>`}function D(q,z={}){let A={title:q.title,description:q.description,generatedAt:q.generatedAt.toISOString(),version:"1.0.0",entries:q.entries.map((G)=>({name:G.name,kind:G.kind,signature:G.signature,description:G.jsdoc.description,isExported:G.isExported,isDefault:G.isDefault,deprecated:G.jsdoc.deprecated,since:G.jsdoc.since,category:G.jsdoc.category,params:G.jsdoc.params,returns:G.jsdoc.returns,examples:G.jsdoc.examples,throws:G.jsdoc.throws,see:G.jsdoc.see,tags:G.jsdoc.tags,sourceFile:G.sourceFile,sourceLine:G.sourceLine,members:G.members?.map((Q)=>({name:Q.name,kind:Q.kind,signature:Q.signature,description:Q.jsdoc.description,deprecated:Q.jsdoc.deprecated,params:Q.jsdoc.params,returns:Q.jsdoc.returns}))})),categories:z.groupByCategory?Object.fromEntries(Array.from(q.categories.entries()).map(([G,Q])=>[G,Q.map((U)=>U.name)])):void 0};return JSON.stringify(A,null,2)}function u(q){let z={id:0,name:q.title,kind:1,kindString:"Project",flags:{},children:q.entries.map((A,G)=>({id:G+1,name:A.name,kind:J(A.kind),kindString:A.kind,flags:{isExported:A.isExported,isDefault:A.isDefault},comment:A.jsdoc.description?{summary:[{kind:"text",text:A.jsdoc.description}],blockTags:A.jsdoc.deprecated?[{tag:"@deprecated",content:[{kind:"text",text:A.jsdoc.deprecated}]}]:void 0}:void 0,sources:A.sourceFile?[{fileName:A.sourceFile,line:A.sourceLine||1,character:0}]:void 0,signatures:A.kind==="function"?[{id:G+1000,name:A.name,kind:4096,kindString:"Call signature",parameters:A.jsdoc.params.map((Q,U)=>({id:G+2000+U,name:Q.name,kind:32768,kindString:"Parameter",flags:{isOptional:Q.optional},type:Q.type?{type:"intrinsic",name:Q.type}:void 0,comment:Q.description?{summary:[{kind:"text",text:Q.description}]}:void 0})),type:A.jsdoc.returns?.type?{type:"intrinsic",name:A.jsdoc.returns.type}:void 0}]:void 0,children:A.members?.map((Q,U)=>({id:G+3000+U,name:Q.name,kind:J(Q.kind),kindString:Q.kind,comment:Q.jsdoc.description?{summary:[{kind:"text",text:Q.jsdoc.description}]}:void 0}))}))};return JSON.stringify(z,null,2)}async function d(q,z){_.info("Extracting documentation...");let A=await P(q,z);if(_.info(`Found ${A.entries.length} documented entries`),!j(z.outdir))w(z.outdir,{recursive:!0});if(z.format==="markdown")if(z.splitByModule){let G=m(A.entries);for(let[U,W]of G){let X={title:H(U,".ts"),description:`Documentation for ${U}`,entries:W,categories:new Map,generatedAt:A.generatedAt},Y=B(X,z),Z=R(z.outdir,`${H(U,".ts")}.md`);V(Z,Y),_.info(`Generated: ${Z}`)}let Q=[`# ${A.title}`,"",A.description||"","","## Modules",""];for(let[U]of G){let W=H(U,".ts");Q.push(`- [${W}](./${W}.md)`)}V(R(z.outdir,"README.md"),Q.join(`
`)),_.info(`Generated: ${R(z.outdir,"README.md")}`)}else{let G=B(A,z),Q=R(z.outdir,"API.md");V(Q,G),_.info(`Generated: ${Q}`)}else if(z.format==="json"){let G=D(A,z),Q=R(z.outdir,"api.json");V(Q,G),_.info(`Generated: ${Q}`);let U=u(A),W=R(z.outdir,"typedoc.json");V(W,U),_.info(`Generated: ${W}`)}else{let G=C(A,z),Q=R(z.outdir,"index.html");V(Q,G),_.info(`Generated: ${Q}`)}}function E(q){return q.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function O(q){return{function:"Functions",variable:"Variables",interface:"Interfaces",type:"Type Aliases",class:"Classes",enum:"Enums",export:"Exports",module:"Modules"}[q]||q}function I(q){let z=new Map,A=["function","class","interface","type","enum","variable"];for(let G of A)z.set(G,[]);for(let G of q){let Q=G.kind;if(!z.has(Q))z.set(Q,[]);z.get(Q).push(G)}return z}function f(q){return q.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function m(q){let z=new Map;for(let A of q){let G=A.sourceFile||"unknown";if(!z.has(G))z.set(G,[]);z.get(G).push(A)}return z}function J(q){return{function:64,variable:32,interface:256,type:4194304,class:128,enum:8,property:1024,method:2048,module:2,namespace:4}[q]||0}function l(q={}){return{extract:(z)=>P(z,q),generateMarkdown:(z)=>B(z,q),generateHTML:(z)=>C(z,q),generateJSON:(z)=>D(z,q),parseJSDoc:N}}
export{N as d,P as e,B as f,C as g,D as h,u as i,d as j,l as k};
