{"version":3,"sources":["../../src/sections/section.ts"],"sourcesContent":["import { HeadingLevel } from '../elements/heading.js';\n\nexport interface DocumentSectionOptions {\n  title: string;\n  parent?: DocumentSection;\n  subSections?: Array<DocumentSection>;\n}\n\n/**\n * Represents a markdown document section.\n */\nexport abstract class DocumentSection {\n  private _subSections: Array<DocumentSection> = [];\n\n  title: string;\n\n  parent: DocumentSection | undefined;\n\n  constructor(options: DocumentSectionOptions) {\n    this.title = options.title;\n    this.parent = options.parent;\n    this.parent?._subSections.push(this);\n    options.subSections?.forEach((section) => this.addSubSection(section));\n  }\n\n  get subSections(): ReadonlyArray<DocumentSection> {\n    return this._subSections;\n  }\n\n  get headingLevel(): HeadingLevel {\n    const rootHeadingLevel = 2;\n    const maxHeadingLevel = 6;\n    const level = this.parent ? this.parent.headingLevel + 1 : rootHeadingLevel;\n    return (level > maxHeadingLevel ? maxHeadingLevel : level) as HeadingLevel;\n  }\n\n  addSubSection(section: DocumentSection) {\n    section.parent = this;\n    this._subSections.push(section);\n    return this;\n  }\n\n  /**\n   * Transform the section data into an array of strings\n   */\n  protected abstract synthesizeContent(): Array<string>;\n\n  /**\n   * Synthesize the section data so it can be written to the readme\n   */\n  public synthesize() {\n    return this.synthesizeContent().join('\\n');\n  }\n}\n\nexport function tryFindSection<S extends DocumentSection>(\n  sections: ReadonlyArray<S>,\n  path: Array<string>,\n): S | undefined {\n  for (const section of sections) {\n    if (section.title === path[0] && path.length === 1) {\n      return section;\n    }\n\n    return tryFindSection(section.subSections, path.slice(1)) as S;\n  }\n\n  return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWO,MAAe,gBAAgB;AAAA,EAC5B,eAAuC,CAAC;AAAA,EAEhD;AAAA,EAEA;AAAA,EAEA,YAAY,SAAiC;AAC3C,SAAK,QAAQ,QAAQ;AACrB,SAAK,SAAS,QAAQ;AACtB,SAAK,QAAQ,aAAa,KAAK,IAAI;AACnC,YAAQ,aAAa,QAAQ,CAAC,YAAY,KAAK,cAAc,OAAO,CAAC;AAAA,EACvE;AAAA,EAEA,IAAI,cAA8C;AAChD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,eAA6B;AAC/B,UAAM,mBAAmB;AACzB,UAAM,kBAAkB;AACxB,UAAM,QAAQ,KAAK,SAAS,KAAK,OAAO,eAAe,IAAI;AAC3D,WAAQ,QAAQ,kBAAkB,kBAAkB;AAAA,EACtD;AAAA,EAEA,cAAc,SAA0B;AACtC,YAAQ,SAAS;AACjB,SAAK,aAAa,KAAK,OAAO;AAC9B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAUO,aAAa;AAClB,WAAO,KAAK,kBAAkB,EAAE,KAAK,IAAI;AAAA,EAC3C;AACF;AAEO,SAAS,eACd,UACA,MACe;AACf,aAAW,WAAW,UAAU;AAC9B,QAAI,QAAQ,UAAU,KAAK,CAAC,KAAK,KAAK,WAAW,GAAG;AAClD,aAAO;AAAA,IACT;AAEA,WAAO,eAAe,QAAQ,aAAa,KAAK,MAAM,CAAC,CAAC;AAAA,EAC1D;AAEA,SAAO;AACT;","names":[]}