{"version":3,"file":"gravitee-ui-particles-angular-gio-asciidoctor.mjs","sources":["../../../projects/ui-particles-angular/gio-asciidoctor/gio-asciidoctor.service.ts","../../../projects/ui-particles-angular/gio-asciidoctor/gio-asciidoctor.component.ts","../../../projects/ui-particles-angular/gio-asciidoctor/gio-asciidoctor.module.ts","../../../projects/ui-particles-angular/gio-asciidoctor/public-api.ts","../../../projects/ui-particles-angular/gio-asciidoctor/gravitee-ui-particles-angular-gio-asciidoctor.ts"],"sourcesContent":["/*\n * Copyright (C) 2023 The Gravitee team (http://gravitee.io)\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *         http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Injectable } from '@angular/core';\nimport { from, Observable, of } from 'rxjs';\nimport { shareReplay } from 'rxjs/operators';\nimport asciidoctor, { Asciidoctor } from '@asciidoctor/core';\n\ndeclare global {\n  interface Window {\n    _gioAsciidoctor: Asciidoctor;\n  }\n}\n\n@Injectable({\n  providedIn: 'root',\n})\nexport class GioAsciidoctorService {\n  public load(): Observable<Asciidoctor> {\n    return this.loadAsciidoctor().pipe(\n      // If already loaded, we don't want to load it again\n      shareReplay(1),\n    );\n  }\n\n  private loadAsciidoctor(): Observable<Asciidoctor> {\n    if (!window._gioAsciidoctor) {\n      const loadAsciidoctor = async () => {\n        window._gioAsciidoctor = asciidoctor();\n        return window._gioAsciidoctor;\n      };\n\n      return from(loadAsciidoctor());\n    } else {\n      return of(window._gioAsciidoctor);\n    }\n  }\n}\n","/*\n * Copyright (C) 2015 The Gravitee team (http://gravitee.io)\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *         http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { APP_ID, Component, ElementRef, Inject, Input, OnChanges, OnDestroy, SecurityContext, SimpleChanges } from '@angular/core';\nimport { takeUntil } from 'rxjs/operators';\nimport { ReplaySubject, Subject, forkJoin } from 'rxjs';\nimport { HttpClient } from '@angular/common/http';\nimport { DomSanitizer } from '@angular/platform-browser';\nimport { Asciidoctor, Options } from '@asciidoctor/core';\nimport { GioPrismJsService } from '@gravitee/ui-particles-angular';\n\nimport { GioAsciidoctorService } from './gio-asciidoctor.service';\n\n@Component({\n  selector: 'gio-asciidoctor',\n  template: '',\n  styleUrls: ['./gio-asciidoctor.component.scss'],\n  standalone: false,\n})\nexport class GioAsciidoctorComponent implements OnChanges, OnDestroy {\n  @Input()\n  public content?: string;\n\n  @Input()\n  public src?: string;\n\n  private options: Options = {\n    header_footer: false,\n    attributes: {\n      showtitle: true,\n    },\n    safe: 'secure',\n  };\n\n  private asciidoctor$ = new ReplaySubject<Asciidoctor>(1);\n  private unsubscribe$ = new Subject<void>();\n\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n  private _uniqueId: string = (this.constructor as any)['ɵcmp'].id;\n\n  constructor(\n    private readonly gioAsciidoctorService: GioAsciidoctorService,\n    private readonly gioPrismJsService: GioPrismJsService,\n    private readonly sanitizer: DomSanitizer,\n    private readonly elementRef: ElementRef,\n    private readonly httpClient: HttpClient,\n    @Inject(APP_ID) private readonly appId: string,\n  ) {\n    // Asynchronously load asciidoctor.js and prism.js\n    forkJoin([this.gioAsciidoctorService.load(), this.gioPrismJsService.loadPrismJs()])\n      .pipe(takeUntil(this.unsubscribe$))\n      .subscribe(([asciidoctor]) => {\n        this.asciidoctor$.next(asciidoctor);\n      });\n  }\n\n  public ngOnChanges(changes: SimpleChanges): void {\n    if (changes.content && this.content) {\n      this.render(this.content);\n    }\n    if (changes.src && this.src) {\n      this.httpClient\n        .get(this.src, { responseType: 'text' })\n        .pipe(takeUntil(this.unsubscribe$))\n        .subscribe(content => {\n          this.render(content);\n        });\n    }\n  }\n\n  public ngOnDestroy(): void {\n    this.unsubscribe$.next();\n    this.unsubscribe$.complete();\n  }\n\n  private render(content?: string): void {\n    if (!content) {\n      return;\n    }\n\n    // When asciidoctor is not loaded yet, wait for it\n    this.asciidoctor$.pipe(takeUntil(this.unsubscribe$)).subscribe(asciidoctor => {\n      const html = asciidoctor.convert(content, this.options);\n      this.elementRef.nativeElement.innerHTML = this.sanitizer.sanitize(SecurityContext.HTML, html);\n\n      // Highlight all code blocks with PrismJs\n      const highlights = this.elementRef.nativeElement.querySelectorAll('pre.highlight');\n      for (const element of highlights) {\n        element.setAttribute('class', 'prismjs highlight');\n        if (window.Prism) {\n          window.Prism.highlightAllUnder(element, false);\n        }\n      }\n\n      // Manually add Angular encapsulation attribute to all elements at the end\n      const descandants = this.elementRef.nativeElement.querySelectorAll('*');\n      for (const element of descandants) {\n        element.setAttribute(`_ngcontent-${this.appId}-${this._uniqueId}`, '');\n      }\n    });\n  }\n}\n","/*\n * Copyright (C) 2015 The Gravitee team (http://gravitee.io)\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *         http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { CommonModule } from '@angular/common';\nimport { NgModule } from '@angular/core';\n\nimport { GioAsciidoctorComponent } from './gio-asciidoctor.component';\n\n@NgModule({\n  imports: [CommonModule],\n  declarations: [GioAsciidoctorComponent],\n  exports: [GioAsciidoctorComponent],\n})\nexport class GioAsciidoctorModule {}\n","/*\n * Copyright (C) 2024 The Gravitee team (http://gravitee.io)\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *         http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport * from './gio-asciidoctor.module';\nexport * from './gio-asciidoctor.component';\nexport * from './gio-asciidoctor.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;;AAAA;;;;;;;;;;;;;;AAcG;MAeU,qBAAqB,CAAA;IACzB,IAAI,GAAA;AACT,QAAA,OAAO,IAAI,CAAC,eAAe,EAAE,CAAC,IAAI;;AAEhC,QAAA,WAAW,CAAC,CAAC,CAAC,CACf;IACH;IAEQ,eAAe,GAAA;AACrB,QAAA,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE;AAC3B,YAAA,MAAM,eAAe,GAAG,YAAW;AACjC,gBAAA,MAAM,CAAC,eAAe,GAAG,WAAW,EAAE;gBACtC,OAAO,MAAM,CAAC,eAAe;AAC/B,YAAA,CAAC;AAED,YAAA,OAAO,IAAI,CAAC,eAAe,EAAE,CAAC;QAChC;aAAO;AACL,YAAA,OAAO,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC;QACnC;IACF;8GAnBW,qBAAqB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;AAArB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAA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