{"version":3,"sources":["../../src/sections/table-of-contents.ts"],"sourcesContent":["import { DocumentSection } from './section.js';\nimport { heading } from '../elements/heading.js';\n\nexport interface TableOfContents {\n  title?: string;\n  sections: ReadonlyArray<DocumentSection>;\n}\n\nexport class TableOfContentsSection extends DocumentSection {\n  constructor(private options: TableOfContents) {\n    super({ title: 'Table of Contents' });\n  }\n\n  private generateTableOfContents(\n    sections: ReadonlyArray<DocumentSection>,\n    indent: number = 0,\n  ): Array<string> {\n    const tableOfContents: Array<string> = [];\n\n    const indentation = ' '.repeat(indent);\n\n    for (const section of sections) {\n      tableOfContents.push(\n        `${indentation}- [${section.title}](#${section.title\n          .toLowerCase()\n          .replace(/ /g, '-')\n          .replace(/\\\\/g, '')})`,\n      );\n\n      tableOfContents.push(\n        ...this.generateTableOfContents(section.subSections, indent + 2),\n      );\n    }\n\n    return tableOfContents;\n  }\n\n  protected synthesizeContent(): Array<string> {\n    return [\n      heading(2, this.title),\n      '',\n      ...this.generateTableOfContents(this.options.sections),\n    ];\n  }\n}\n\nexport function tableOfContentsSection(options: TableOfContents) {\n  return new TableOfContentsSection(options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAgC;AAChC,qBAAwB;AAOjB,MAAM,+BAA+B,+BAAgB;AAAA,EAC1D,YAAoB,SAA0B;AAC5C,UAAM,EAAE,OAAO,oBAAoB,CAAC;AADlB;AAAA,EAEpB;AAAA,EAEQ,wBACN,UACA,SAAiB,GACF;AACf,UAAM,kBAAiC,CAAC;AAExC,UAAM,cAAc,IAAI,OAAO,MAAM;AAErC,eAAW,WAAW,UAAU;AAC9B,sBAAgB;AAAA,QACd,GAAG,WAAW,MAAM,QAAQ,KAAK,MAAM,QAAQ,MAC5C,YAAY,EACZ,QAAQ,MAAM,GAAG,EACjB,QAAQ,OAAO,EAAE,CAAC;AAAA,MACvB;AAEA,sBAAgB;AAAA,QACd,GAAG,KAAK,wBAAwB,QAAQ,aAAa,SAAS,CAAC;AAAA,MACjE;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEU,oBAAmC;AAC3C,WAAO;AAAA,UACL,wBAAQ,GAAG,KAAK,KAAK;AAAA,MACrB;AAAA,MACA,GAAG,KAAK,wBAAwB,KAAK,QAAQ,QAAQ;AAAA,IACvD;AAAA,EACF;AACF;AAEO,SAAS,uBAAuB,SAA0B;AAC/D,SAAO,IAAI,uBAAuB,OAAO;AAC3C;","names":[]}