{"version":3,"sources":["../../src/sections/examples.ts"],"sourcesContent":["import { DocumentSection, DocumentSectionOptions } from './section.js';\nimport type { Optional } from '../@types/optional.js';\nimport { codeBlock } from '../elements/code-block.js';\nimport { HeadingLevel, heading } from '../elements/heading.js';\n\ninterface CodeBlock {\n  language:\n    | 'apache'\n    | 'armasm'\n    | 'bash'\n    | 'c'\n    | 'coffeescript'\n    | 'cpp'\n    | 'csharp'\n    | 'css'\n    | 'd'\n    | 'diff'\n    | 'go'\n    | 'handlebars'\n    | 'haskell'\n    | 'http'\n    | 'ini'\n    | 'java'\n    | 'javascript'\n    | 'json'\n    | 'julia'\n    | 'kotlin'\n    | 'less'\n    | 'lua'\n    | 'makefile'\n    | 'markdown'\n    | 'nginx'\n    | 'objectivec'\n    | 'perl'\n    | 'php'\n    | 'plaintext'\n    | 'properties'\n    | 'python'\n    | 'r'\n    | 'ruby'\n    | 'rust'\n    | 'scala'\n    | 'scss'\n    | 'shell'\n    | 'sql'\n    | 'swift'\n    | 'typescript'\n    | 'x86asm'\n    | 'xml'\n    | 'yaml';\n  code: string;\n}\n\nexport interface Example {\n  title: string;\n  description?: string;\n  codeblock: CodeBlock;\n  group?: string;\n}\n\nexport interface ExamplesOptions\n  extends Optional<DocumentSectionOptions, 'title'> {\n  items?: Array<Example>;\n}\nexport class Examples extends DocumentSection {\n  protected items = new Map<string, Array<Example>>();\n\n  constructor(options?: ExamplesOptions) {\n    super({ title: options?.title ?? 'Examples', ...options });\n    options?.items?.forEach((item) => this.add(item));\n  }\n\n  public add(item: Example) {\n    const group = this.items.get(item.group ?? 'ungrouped');\n\n    if (group) {\n      group.push(item);\n    } else {\n      this.items.set(item.group ?? 'ungrouped', [item]);\n    }\n\n    return this;\n  }\n\n  protected itemMapper(item: Example, headingLevel: HeadingLevel): string {\n    const { code, language } = item.codeblock;\n\n    return [\n      heading(headingLevel, item.title),\n      ...(item.description ? ['', item.description, ''] : ['']),\n      // `\\`\\`\\`${item.codeblock.language}`,\n      // item.codeblock.code.replace(/\\n$/, ''),\n      codeBlock({ code, language }),\n      // item.codeblock.code.replace(/\\n$/, ''),\n      // '```',\n      '',\n    ].join('\\n');\n  }\n\n  protected synthesizeContent(): Array<string> {\n    const content = [heading(this.headingLevel, this.title)];\n\n    let headingLevel = this.headingLevel + 1;\n    for (const [group, examples] of this.items) {\n      content.push('');\n      if (group !== 'ungrouped') {\n        content.push(heading(headingLevel as HeadingLevel, group), '');\n        headingLevel++;\n      }\n      content.push(\n        ...examples.map((item) =>\n          this.itemMapper(item, headingLevel as HeadingLevel),\n        ),\n      );\n    }\n\n    return content;\n  }\n}\n\nexport function examplesSection(options?: ExamplesOptions) {\n  return new Examples(options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwD;AAExD,wBAA0B;AAC1B,qBAAsC;AA6D/B,MAAM,iBAAiB,+BAAgB;AAAA,EAClC,QAAQ,oBAAI,IAA4B;AAAA,EAElD,YAAY,SAA2B;AACrC,UAAM,EAAE,OAAO,SAAS,SAAS,YAAY,GAAG,QAAQ,CAAC;AACzD,aAAS,OAAO,QAAQ,CAAC,SAAS,KAAK,IAAI,IAAI,CAAC;AAAA,EAClD;AAAA,EAEO,IAAI,MAAe;AACxB,UAAM,QAAQ,KAAK,MAAM,IAAI,KAAK,SAAS,WAAW;AAEtD,QAAI,OAAO;AACT,YAAM,KAAK,IAAI;AAAA,IACjB,OAAO;AACL,WAAK,MAAM,IAAI,KAAK,SAAS,aAAa,CAAC,IAAI,CAAC;AAAA,IAClD;AAEA,WAAO;AAAA,EACT;AAAA,EAEU,WAAW,MAAe,cAAoC;AACtE,UAAM,EAAE,MAAM,SAAS,IAAI,KAAK;AAEhC,WAAO;AAAA,UACL,wBAAQ,cAAc,KAAK,KAAK;AAAA,MAChC,GAAI,KAAK,cAAc,CAAC,IAAI,KAAK,aAAa,EAAE,IAAI,CAAC,EAAE;AAAA;AAAA;AAAA,UAGvD,6BAAU,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