{"version":3,"file":"siemens-element-ng-markdown-extensions-katex.mjs","sources":["../../../../projects/element-ng/markdown/extensions/katex/si-markdown-katex.component.ts","../../../../projects/element-ng/markdown/extensions/katex/si-markdown-katex.extension.ts","../../../../projects/element-ng/markdown/extensions/katex/index.ts","../../../../projects/element-ng/markdown/extensions/katex/siemens-element-ng-markdown-extensions-katex.ts"],"sourcesContent":["/**\n * Copyright (c) Siemens 2016 - 2026\n * SPDX-License-Identifier: MIT\n */\nimport {\n  Component,\n  computed,\n  effect,\n  ElementRef,\n  inject,\n  input,\n  ViewEncapsulation\n} from '@angular/core';\nimport { type SiMarkdownExtensionComponent } from '@siemens/element-ng/markdown';\nimport { type KatexOptions, render } from 'katex';\nimport { Literal, type Node, type Parent } from 'mdast';\n\n@Component({\n  selector: 'si-markdown-katex',\n  template: '',\n  styleUrl: 'si-markdown-katex.component.scss',\n  // this is necessary for the styles to work correctly\n  // eslint-disable-next-line @angular-eslint/use-component-view-encapsulation\n  encapsulation: ViewEncapsulation.None,\n  host: {\n    class: 'katex-container',\n    '[attr.data-line]': 'node().position?.start?.line',\n    '[class.d-block]': 'displayMode()'\n  }\n})\nexport class SiMarkdownKatexComponent implements SiMarkdownExtensionComponent {\n  private readonly elementRef = inject(ElementRef);\n\n  readonly node = input.required<Node>();\n  readonly parent = input.required<Parent>();\n  readonly options = input<KatexOptions>();\n\n  protected readonly displayMode = computed(() => this.node().type === 'math');\n  private readonly expr = computed(() => (this.node() as Literal).value);\n\n  constructor() {\n    effect(() => this.render());\n  }\n\n  private render(): void {\n    const expr = this.expr();\n    const options = this.options() ?? {};\n    render(expr, this.elementRef.nativeElement, {\n      ...options,\n      displayMode: this.displayMode(),\n      throwOnError: false\n    });\n  }\n}\n","/**\n * Copyright (c) Siemens 2016 - 2026\n * SPDX-License-Identifier: MIT\n */\nimport { type SiMarkdownExtension } from '@siemens/element-ng/markdown';\n/**\n * Copyright (c) Siemens 2016 - 2026\n * SPDX-License-Identifier: MIT\n */\nimport { type KatexOptions } from 'katex';\nimport remarkMath, { type Options } from 'remark-math';\n\nimport { SiMarkdownKatexComponent } from './si-markdown-katex.component';\n\n/**\n * An extension to render LaTeX math expressions using KaTeX. Uses `remark-math` to parse\n * the expressions inside the markdown document.\n * @param parseOptions - options passed to `remark-math`\n * @param katexOptions - options passed to `katex`. Keep the default `trust: false` for untrusted\n * expressions. Do not set `trust: true` unless all expressions rendered with that configuration\n * come from sources you fully trust. For untrusted expressions that require specific commands,\n * use a narrowly scoped `trust` callback that validates commands and their arguments, including URLs.\n * @returns extension for `SiMarkdownOption.installExtension()`\n */\nexport const siMarkdownMathKaTeX = (\n  parseOptions?: Options,\n  katexOptions?: KatexOptions\n): SiMarkdownExtension => {\n  katexOptions ??= {\n    output: 'html'\n  };\n\n  return {\n    plugins: [{ plugin: remarkMath, options: parseOptions }],\n    types: [\n      { type: 'math', component: SiMarkdownKatexComponent, options: katexOptions },\n      { type: 'inlineMath', component: SiMarkdownKatexComponent, options: katexOptions }\n    ]\n  };\n};\n","/**\n * Copyright (c) Siemens 2016 - 2026\n * SPDX-License-Identifier: MIT\n */\nexport * from './si-markdown-katex.extension';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAAA;;;AAGG;MA2BU,wBAAwB,CAAA;AAClB,IAAA,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IAEvC,IAAI,GAAG,KAAK,CAAC,QAAQ;6EAAQ;IAC7B,MAAM,GAAG,KAAK,CAAC,QAAQ;+EAAU;AACjC,IAAA,OAAO,GAAG,KAAK;2FAAgB;AAErB,IAAA,WAAW,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,KAAK,MAAM;oFAAC;IAC3D,IAAI,GAAG,QAAQ,CAAC,MAAO,IAAI,CAAC,IAAI,EAAc,CAAC,KAAK;6EAAC;AAEtE,IAAA,WAAA,GAAA;QACE,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,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