{"version":3,"file":"bootkit-ng1-components-document.mjs","sources":["../../../projects/ng1/components/document/document.service.ts","../../../projects/ng1/components/document/document.component.ts","../../../projects/ng1/components/document/document.component.html","../../../projects/ng1/components/document/document-section/document-section.component.ts","../../../projects/ng1/components/document/document-section/document-section.component.html","../../../projects/ng1/components/document/table-of-content/table-of-content.component.ts","../../../projects/ng1/components/document/table-of-content/table-of-content.component.html","../../../projects/ng1/components/document/document.module.ts","../../../projects/ng1/components/document/bootkit-ng1-components-document.ts"],"sourcesContent":["import { Injectable, signal } from '@angular/core';\nimport type { DocumentComponent } from './document.component';\n\n/**\n * Service for managing the current document being displayed. \n */\n@Injectable({\n  providedIn: 'root'\n})\nexport class DocumentService {\n  /**\n   * The current document being displayed. This can be undefined if no document is currently loaded.\n   */\n  public readonly document = signal<DocumentComponent | undefined>(undefined);\n}\n","import { ChangeDetectionStrategy, Component, inject, input, OnDestroy, signal } from '@angular/core';\nimport { DocumentService } from './document.service';\nimport { DocumentSectionComponent } from './document-section/document-section.component';\n\n/**\n * Component representing a document. \n * A document can contain multiple sections, which are represented by DocumentContentComponent instances.\n */\n@Component({\n  selector: 'ng1-document, ng1-doc',\n  templateUrl: './document.component.html',\n  standalone: true,\n  changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class DocumentComponent implements OnDestroy {\n  private readonly _documentService = inject(DocumentService);\n  public readonly sections = signal<DocumentSectionComponent[]>([]);\n\n  constructor() {\n    if (this._documentService.document()) {\n      throw new Error(\"Only one Document is allowed per page.\");\n    } else {\n      this._documentService.document.set(this);\n    }\n  }\n\n  ngOnDestroy(): void {\n    this._documentService.document.set(undefined);\n  }\n}\n","<ng-content></ng-content>\n\n<style>\n    :host {\n        display: block;\n    }\n</style>\n","import { ChangeDetectionStrategy, Component, computed, inject, input, OnDestroy, signal } from '@angular/core';\nimport { DocumentComponent } from '../document.component';\n\n/**\n * Component representing a section of a document. \n * A section can be nested inside another section, allowing for a hierarchical structure of the document. \n * Each section can have a header and an optional header ID, which can be used for linking to specific sections of the document.\n */\n@Component({\n  selector: 'ng1-document-section, ng1-doc-section',\n  templateUrl: './document-section.component.html',\n  standalone: true,\n  changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class DocumentSectionComponent implements OnDestroy {\n  /**\n   * The child sections of this section. This allows for nested sections within a document.\n   */\n  public readonly sections = signal<DocumentSectionComponent[]>([]);\n\n  /**\n   * The DocumentComponent instance that this section belongs to. \n   */\n  public readonly document = inject(DocumentComponent, { optional: true, skipSelf: true });\n\n  /**\n   * The parent DocumentSectionComponent instance that this section belongs to, if any. \n   * This allows for nested sections within a document.\n   */\n  public readonly parent = inject(DocumentSectionComponent, { optional: true, skipSelf: true });\n\n\n  /**\n   * The header of the section, which can be used as a title for the section.\n   */\n  public readonly header = input<string>();\n\n  /**\n   * An optional ID for the section header, which can be used for linking to specific sections of the document.\n   */\n  public readonly headerId = input<string>();\n\n  /**\n   * A computed property that generates a header ID based on the header text if the header ID is not explicitly provided.\n   * It converts the header text to lowercase, replaces non-alphanumeric characters with underscores, and trims leading/trailing underscores.\n   * If neither the header ID nor the header text is provided, it returns undefined.\n   */\n  public readonly computedHeaderId = computed(() => {\n    if (this.headerId()) {\n      return this.headerId();\n    }\n    if (this.header()) {\n      return this.header()!\n        .toLowerCase()\n        .replace(/[^a-z0-9]+/g, \"_\")  // replace non-english letters/numbers with _\n        .replace(/^_+|_+$/g, \"\");     // trim leading/trailing _\n    }\n\n    return undefined;\n  });\n\n  constructor() {\n    if (this.parent) {\n      let contents = this.parent.sections();\n      contents.push(this);\n      this.parent.sections.set([...contents]);\n    } else if (this.document) {\n      let contents = this.document.sections();\n      contents.push(this);\n      this.document.sections.set([...contents]);\n    } else {\n      throw Error('Use DocumentSectionComponent inside a DocumentComponent');\n    }\n  }\n\n  ngOnDestroy(): void {\n    if (this.parent) {\n      let contents = this.parent.sections();\n      contents.splice(contents.indexOf(this), 1);\n      this.parent.sections.set([...contents]);\n    } else {\n      let contents = this.document!.sections();\n      contents.splice(contents.indexOf(this), 1);\n      this.document?.sections.set([...contents]);\n    }\n  }\n}\n","@if (header()) {\n    <h4 [attr.id]=\"computedHeaderId()\">\n        {{ header() }}\n    </h4>\n}\n\n<ng-content></ng-content>\n\n<style>\n    :host {\n        display: block;\n        margin: 2rem 0;\n    }\n</style>\n","import { ChangeDetectionStrategy, Component, inject } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { DocumentService } from '../document.service';\nimport { Router } from '@angular/router';\n\n/**\n * Component representing the table of contents of a document. \n * The table of contents is generated based on the sections of the document, and allows for easy navigation to different sections of the document.\n */\n@Component({\n  selector: 'ng1-document-table-of-content,ng1-document-toc',\n  templateUrl: './table-of-content.component.html',\n  // styleUrl: './table-of-content.component.scss',\n  standalone: true,\n  changeDetection: ChangeDetectionStrategy.OnPush,\n  imports: [CommonModule]\n})\nexport class DocumentTableOfContentComponent {\n  protected readonly _router = inject(Router);\n  protected readonly _documentService = inject(DocumentService);\n}\n","@let doc = _documentService.document();\n\n<p class=\"text-muted border-bottom pb-2\" style=\"border-color: gray;\">On this page:</p>\n\n@if (doc) {\n    <ul class=\"list-unstyled\">\n        @for (item of doc.sections(); track $index) {\n            <li>\n                <a\n                    class=\"text-decoration-none\"\n                    [attr.href]=\"_router.url + '#' + item.computedHeaderId()\">\n                    {{item.header()}}\n                </a>\n            </li>\n        }\n    </ul>\n}\n\n<style></style>\n","import { NgModule } from '@angular/core';\nimport { DocumentComponent } from './document.component';\nimport { DocumentSectionComponent } from './document-section/document-section.component';\nimport { DocumentTableOfContentComponent } from './table-of-content/table-of-content.component';\n\nconst declares = [\n        DocumentComponent,\n        DocumentSectionComponent,\n        DocumentTableOfContentComponent\n];\n\n@NgModule({\n    imports: declares,\n    exports: declares\n})\nexport class DocumentModule {\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAGA;;AAEG;MAIU,eAAe,CAAA;AAC1B;;AAEG;AACa,IAAA,QAAQ,GAAG,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