{"version":3,"file":"bootkit-ng1-components-code.mjs","sources":["../../../projects/ng1/components/code/types.ts","../../../projects/ng1/components/code/code.component.ts","../../../projects/ng1/components/code/code.component.html","../../../projects/ng1/components/code/code.module.ts","../../../projects/ng1/components/code/highligh-js.ts","../../../projects/ng1/components/code/bootkit-ng1-components-code.ts"],"sourcesContent":["import { InjectionToken } from \"@angular/core\";\n\nexport type CodeFormatterFunc = (code: string) => string;\n\nexport class CodeFormatter {\n    constructor(public readonly name: string, public readonly format: CodeFormatterFunc) {\n    }\n}\n\nexport const CODE_FORMATTER = new InjectionToken<CodeFormatter>('Code Formatter');","import { ChangeDetectionStrategy, Component, computed, inject, input, model } from '@angular/core';\nimport { DomSanitizer } from '@angular/platform-browser';\nimport { CODE_FORMATTER, CodeFormatter } from './types';\n\n/**\n * CodeComponent is responsible for displaying formatted code snippets.\n * It takes raw code as input and uses registered CodeFormatters to format the code based on the specified formatter name. \n */\n@Component({\n  selector: 'ng1-code',\n  exportAs: 'ng1Code',\n  styleUrls: ['./code.component.scss'],\n  templateUrl: './code.component.html',\n  standalone: true,\n  changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class CodeComponent {\n  private readonly _domSanitizer = inject(DomSanitizer);\n  private readonly _formatters = inject<CodeFormatter[] | undefined>(CODE_FORMATTER, { optional: true });\n\n  /** \n   * The name of the formatter to be used for syntax highlighting (e.g., 'typescript', 'html').\n   */\n  public readonly formatter = input<string | undefined>(undefined);\n\n  /** \n   * The actual code string to be displayed.\n   */\n  public readonly code = model<string| undefined>(undefined);\n\n  constructor() {\n  }\n\n  protected _safeHtml = computed(() => {\n    let code = this.code() || ''; // track\n    let formatterName = this.formatter(); // track\n    let foramtter = this._formatters?.find(x => x.name == formatterName);\n    let formattedCode: string;\n\n    if (foramtter) {\n      formattedCode = foramtter.format(code);\n    } else {\n      console.warn(`Code formatter \"${formatterName}\" not found.`);\n      formattedCode = code;\n    }\n\n    return this._domSanitizer.bypassSecurityTrustHtml(formattedCode);\n  });\n}\n","<pre class=\"language-{{formatter()}} formatter-{{formatter()}}\">\n<code class=\"language-{{formatter()}} formatter-{{formatter()}}\"  [innerHtml]=\"_safeHtml()\"></code>\n</pre>","import { NgModule } from '@angular/core';\nimport { CodeComponent } from './code.component';\n\nconst DECLARES = [\n    CodeComponent\n];\n\n@NgModule({\n    imports: DECLARES,\n    exports: DECLARES\n})\nexport class CodeModule {\n}\n","import { CodeFormatter, CodeFormatterFunc } from \"./types\";\n\n/**\n * Creates a CodeFormatter using highlight.js library\n * @param name The name of the registered language in highlight.js (e.g., 'html', 'css', 'javascript')\n * @param hljs The highlight.js instance\n * @returns A CodeFormatter instance that uses highlight.js to format code of the specified language\n */\nexport function createHighlightJsFormatter(name: string, hljs: any): CodeFormatter {\n    let f: CodeFormatterFunc = (code: string) => hljs.highlight(code, { language: name }).value;\n\n    return new CodeFormatter(name, f);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAIa,aAAa,CAAA;AACM,IAAA,IAAA;AAA8B,IAAA,MAAA;IAA1D,WAAA,CAA4B,IAAY,EAAkB,MAAyB,EAAA;QAAvD,IAAA,CAAA,IAAI,GAAJ,IAAI;QAA0B,IAAA,CAAA,MAAM,GAAN,MAAM;IAChE;AACH;MAEY,cAAc,GAAG,IAAI,cAAc,CAAgB,gBAAgB;;ACLhF;;;AAGG;MASU,aAAa,CAAA;AACP,IAAA,aAAa,GAAG,MAAM,CAAC,YAAY,CAAC;IACpC,WAAW,GAAG,MAAM,CAA8B,cAAc,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AAEtG;;AAEG;AACa,IAAA,SAAS,GAAG,KAAK,CAAqB,SAAS,qDAAC;AAEhE;;AAEG;AACa,IAAA,IAAI,GAAG,KAAK,CAAoB,SAAS,gDAAC;AAE1D,IAAA,WAAA,GAAA;IACA;AAEU,IAAA,SAAS,GAAG,QAAQ,CAAC,MAAK;QAClC,IAAI,IAAI,GAAG,IA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