/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/readem@0.2.15/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import*as fs from"fs";import*as path from"path";import walker from"at-at";import mkdirp from"mkdirp";import jsdocTypeParse from"jsdoctypeparser";import{Eventful}from"@lume/eventful";export class FileScanner extends(Eventful()){async scanFile(e,t="utf8"){let n=await fs.promises.readFile(path.resolve(e),{encoding:t});"string"!=typeof n&&(n=n.toString());const r=[],o=doubleStarCommentBlockRegex;let s;for(;s=o.exec(n);){const e={source:s[0],content:[]},t=s[1].replace(leadingStarsRegex,""),n=jsDocTagRegex;let o;for(;o=n.exec(t);){let t;try{t=o[2]&&jsdocTypeParse(o[2]),t.source=o[2]}catch(e){t=o[2]}e.content.push({source:o[0],tag:o[1],type:t||void 0,name:o[3],description:o[4]&&o[4].trim()||void 0})}r.push(e),this.emit("comment",e)}return r}}export class FolderScanner extends FileScanner{async scanFolder(e){const t=await new Promise((t=>{walker.walk(e,(async e=>{const n=[],r=[];for(const t of e)r.push(fs.promises.stat(path.resolve(t)).then((e=>{e.isDirectory()||n.push(t)})));await Promise.all(r),t(n.sort())}))})),n=[];for(const e of t)n.push(this.scanFile(e).then((t=>{const n={file:e,comments:t};return this.emit("fileScanned",n),n})));return Promise.all(n)}}const doubleStarCommentBlockRegex=/\/\*\*((?:\s|\S)*?)\*\//g,leadingStarsRegex=/^[^\S\r\n]*\*[^\S\r\n]?/gm,jsDocTagRegex=/(?<=^[^\S\r\n]*)(?:(?:@([a-zA-Z]+))(?:[^\S\r\n]*(?:{(.*)}))?(?:[^\S\r\n]*((?:[^@\s-]|@@)+))?(?:[^\S\r\n]*(?:-[^\S\r\n]*)?((?:[^@]|@@)*))?)/gm;export class CommentAnalyzer{scanner=new FolderScanner;classes=new Map;functions=new Map;async analyze(e,t){e=e.endsWith("/")?e:e+"/";const n=await this.scanner.scanFolder(e);for(const e of n){if(t&&!t(e.file))continue;let n;for(const t of e.comments){let r,o,s,a,i,c,m,p=[],d=[],l=!1,h="public",u=!1,f=[],g=!1;for(const e of t.content)if("string"==typeof e);else switch(e.tag){case"class":if(p.push(e.tag),r){duplicateTagWarning(e,t);break}r=e.name,n=e.name,o=e.description;break;case"inherits":case"extends":e.name&&!d.includes(e.name)&&d.push(e.name);break;case"abstract":l=!0;break;case"public":case"protected":case"private":if(u){duplicateTagWarning(e,t);break}h=e.tag,u=!0;break;case"constructor":if(p.push(e.tag),g){duplicateTagWarning(e,t);break}g=!0,s="constructor",o=e.description;break;case"method":if(p.push(e.tag),s){duplicateTagWarning(e,t);break}e.type&&warningForComment(t,"The {type} field of a @method tag is ignored. Use @param and @return to define the method shape."),s=e.name,o=e.description;break;case"function":if(p.push(e.tag),a){duplicateTagWarning(e,t);break}e.type&&warningForComment(t,"The {type} field of a @function tag is ignored. Use @param and @return to define the function shape."),a=e.name,o=e.description;break;case"param":if(f.some((t=>t.name===e.name))){warningForComment(t,"Duplicate parameters found for an @method or @function comment. Only the first will be used.");break}if(!e.name){warningForComment(t,"A @parameter tag in the comment had no name field. Skipping.");break}f.push({name:e.name,description:e.description,type:e.type});break;case"return":case"returns":if(i){duplicateTagWarning(e,t);break}e.name&&warningForComment(t,"The name field of a @return (or @returns) tag is ignored."),e.type||warningForComment(t,"A @return tag did not have a {type} field, skipping. Specify a return type, f.e. @return {number}."),i=e.type;break;case"property":if(p.push(e.tag),c){duplicateTagWarning(e,t);break}c=e.name,o=e.description,m=e.type;break;case"typedef":o=e.description}p.length>2&&multiplePrimaryTagsWarning(t,p),r&&this.trackClass(r,{name:r,description:o,file:e.file,extends:d,abstract:l}),s&&(n?this.trackMethod(n,s,{name:s,description:o,access:h,params:f,returns:i},t):orphanPropertyOrMethodWarning("method",t,s)),c&&(n?this.trackProperty(n,c,{name:c,description:o,access:h,type:m},t):orphanPropertyOrMethodWarning("property",t,c)),a&&this.functions.set(a,{file:e.file,name:a,description:o,params:f,returns:i}),p=[],r=void 0,o=void 0,d=[],l=!1,h="public",u=!1,s=void 0,a=void 0,f=[],i=void 0,g=!1,c=void 0,m=void 0}n=""}return{sourceFolder:e,classes:this.classes,functions:this.functions}}trackClass(e,t){const n=Object.assign({name:"",description:"",file:"",extends:[],abstract:!1,methods:{},properties:{}},t);let r=this.classes.get(e);r?(r.extends.push(...n.extends),r.abstract=n.abstract,r.methods={...r.methods,...n.methods},r.properties={...r.properties,...n.properties}):this.classes.set(e,r=n)}trackMethod(e,t,n,r){const o=this.classes.get(e);o?o.methods.hasOwnProperty(t)?propertyOrMethodAlreadyExistsWarning("method",r,e,t):o.methods[t]=n:warningForComment(r,`Not in context of a class for method "${t}"`)}trackProperty(e,t,n,r){const o=this.classes.get(e);o?o.methods.hasOwnProperty(t)?propertyOrMethodAlreadyExistsWarning("property",r,e,t):o.properties[t]=n:warningForComment(r,`Not in context of a class for property "${t}"`)}}function duplicateTagWarning(e,t){warningForComment(t,`\n            More than one @${e.tag} primary tag was found in a comment.\n            Only the first accurrence will be used.\n        `)}function multiplePrimaryTagsWarning(e,t){warningForComment(e,`\n            Found more than one primary tag in a single comment. Unexpected\n            behavior may occurr with documentation output.\n\n            The following tags should not be in the same comment:\n\n            ${t.map((e=>"@"+e)).join("\n")}\n        `)}function orphanPropertyOrMethodWarning(e,t,n){warningForComment(t,`\n            Encountered an @${e} tag named "${n}" outside of the\n            context of a class. This most likely means that the ${e}\n            definition did not come after an @class comment in the source\n            code order.\n\n            For now, @${e} comments must follow an @class comment in\n            order for the methods to be associated with the class. In the\n            future, an @memberOf tag will help alleviate the source-order\n            requirement.\n        `)}function propertyOrMethodAlreadyExistsWarning(e,t,n,r){warningForComment(t,`\n            A ${e} called '${n}' is already defined for the\n            class '${r}'. This means you probably have two or\n            more comments with an @${e} tag defining the same\n            ${e} name. Only the first definition will be used.\n\n            ${"method"===e?"\n\t\t\t\tIf you meant to define an overloaded method, prefer to\n\t\t\t\tuse type unions in the type definitions of your method\n\t\t\t\tparameters, all within a single @method comment.\n\t\t\t":""}\n        `)}function warningForComment(e,t){console.warn(messageWithComment(t,e))}function messageWithComment(e,t){return trim(e)+"\nThe comment was:\n\n"+reIndentComment(t.source)}function trim(e){return e.split("\n").map((e=>e.trim())).join("\n")}function reIndentComment(e){return e.split("\n").map(((e,t)=>0===t?e.trim():" "+e.trim())).join("\n")}async function promise(e,...t){return new Promise(((n,r)=>{e(...t,((e,t)=>{e&&r(e),n(t)}))}))}export class MarkdownRenderer{async render(e,t){t=this.resolveDestination(t);const n=[];await promise(mkdirp,t);for(const[r,o]of e.classes){const s=path.dirname(o.file).replace(e.sourceFolder,""),a=path.join(t,s),i=path.join(a,r+".md");n.push(promise(mkdirp,a).then((()=>fs.promises.writeFile(i,c))));const c=this.renderClass(r,o,e)}await Promise.all(n)}resolveDestination(e){return e=e.replace("/",path.sep),path.isAbsolute(e)||(e=path.resolve(process.cwd(),e)),e}renderNav(e,t){let n="";const r={};for(const[,t]of e.classes){const n=path.relative(e.sourceFolder,t.file).split(path.sep)[0];r[n]||(r[n]=[]),r[n].push(t)}const o=t&&t.linePadStart||"",s=t&&t.basePath||"";let a="";for(const t in r){n+=`${o}- ${t}/\n`;for(const i of r[t])a=path.relative(e.sourceFolder,i.file.replace(/\.ts$/,".md")),n+=`${o}  - [${i.name}](${path.join(s,a)})\n`}return n}renderClass(e,t,n){const r=t.extends.map((e=>{const r=n.classes.get(e);if(!r)return e;return`[${e}](${path.relative(path.dirname(t.file),r.file.replace(/\.ts$/,".md"))})`})).join(", "),o=Object.entries(t.properties),s=Object.entries(t.methods);return`\n# <code>class <b>${e}</b>${r?" extends "+r:""}</code> :id=${e}\n\n${t.description?t.description:""}\n\n${o.length?"## Properties":""}\n\n${r?`Inherits properties from ${r}.`:""}\n\n${o.map((([e,t])=>this.renderProperty(e,t,n))).join("\n\n")}\n\n${s.length?"## Methods":""}\n\n${r?`Inherits methods from ${r}.`:""}\n\n${s.map((([e,t])=>this.renderMethod(e,t,n))).join("\n\n")}\n        `}renderProperty(e,t,n){const r=t.type?t.type.source:"";return`\n### <code>.<b>${e}</b>${r?`: ${r}`:""}</code> :id=${e}\n\n${t.description}\n        `}renderMethod(e,t,n){return`\n### <code>.<b>${e}</b>(): ${t.returns?t.returns.source:"void"}</code> :id=${e}\n\n${t.description}\n        `}}export const version="0.2.15";
//# sourceMappingURL=/sm/62cc810fa54ee83719be0e24c023e2cc590765d4933df34cd02ecfdcde29acb6.map