{"version":3,"file":"talenra-ngx-base-layout-service.mjs","sources":["../../../projects/ngx-base/layout-service/src/layout-service/layout-service.types.ts","../../../projects/ngx-base/layout-service/src/layout-service/layout-service.service.ts","../../../projects/ngx-base/layout-service/talenra-ngx-base-layout-service.ts"],"sourcesContent":["/**\n * Represents an appearance scheme (light-mode, dark-mode)\n *\n * ### Import\n *\n * ```typescript\n * import { AppearanceScheme } from '@talenra/ngx-base/layout-service';\n * ```\n */\nexport enum AppearanceScheme {\n  Light = 'LIGHT',\n  Dark = 'DARK',\n}\n\n/**\n * Represents a color theme (petrol, denim)\n *\n * ### Import\n *\n * ```typescript\n * import { Theme } from '@talenra/ngx-base/layout-service';\n * ```\n */\nexport enum Theme {\n  Petrol = 'PETROL',\n  Denim = 'DENIM',\n  Coshare = 'COSHARE',\n}\n","import { Injectable, Renderer2, RendererFactory2, inject } from '@angular/core';\nimport { BehaviorSubject } from 'rxjs';\nimport { AppearanceScheme, Theme } from './layout-service.types';\n\n/**\n * Provides control and state of the global layout.\n *\n * ### Import\n *\n * ```typescript\n * import { LayoutService } from '@talenra/ngx-base/layout-service';\n * ```\n */\n@Injectable({\n  providedIn: 'root',\n})\nexport class LayoutService {\n  private renderer: Renderer2;\n\n  private renderFactory = inject(RendererFactory2);\n\n  /** @internal */\n  constructor() {\n    const renderFactory = this.renderFactory;\n    this.renderer = renderFactory.createRenderer(null, null);\n    // Setup: Apply the classes for appearance and theme to the body element\n    this.renderer.addClass(document.body, `appearance--${this.appearanceScheme$.value.toLowerCase()}`);\n    this.renderer.addClass(document.body, `theme--${this.theme$.value.toLowerCase()}`);\n  }\n\n  /**\n   * Update the class name reflecting the current appearance scheme and color theme.\n   * @param prefix {String} - Prefix of the class to be applied, e.g. \"theme\"\n   * @param value {String} - Value of the class to be applied, e.g. \"petrol\"\n   */\n  private updatePrefixedClass(prefix: string, value: string): void {\n    const classList: DOMTokenList = document.body?.classList || [];\n    // TODO: Proper way to convert the DOMTokenList to an array in typescript?\n    // WORKAROUND: Disable typescript for the next line.\n    // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n    // @ts-ignore\n    const classNames: string[] = [...classList];\n    const length: number = classNames.length;\n    let i = 0;\n    // Make sure the given prefix is used only once. Remove all class-names using the prefix.\n    while (i < length) {\n      const className: string = classNames[i];\n      className.startsWith(`${prefix}--`) && classList.remove(className);\n      i++;\n    }\n    this.renderer.addClass(document.body, `${(prefix + '--' + value).toLowerCase()}`);\n  }\n\n  // --- Appearance scheme (light/dark mode)\n\n  /**\n   * Provides the current appearance scheme.\n   *\n   * see {@link AppearanceScheme}\n   */\n  public readonly appearanceScheme$ = new BehaviorSubject<AppearanceScheme>(AppearanceScheme.Light);\n\n  /**\n   * Applies the given appearance scheme.\n   */\n  public setAppearance(scheme: AppearanceScheme): void {\n    this.appearanceScheme$.next(scheme);\n    this.updatePrefixedClass('appearance', scheme);\n  }\n\n  // --- Color theme\n\n  /**\n   * Provides the current color theme.\n   *\n   * see {@link Theme}\n   */\n  public readonly theme$ = new BehaviorSubject<Theme>(Theme.Petrol);\n\n  /**\n   * Applies the given color theme.\n   */\n  public setTheme(theme: Theme): void {\n    this.theme$.next(theme);\n    this.updatePrefixedClass('theme', theme);\n  }\n\n  // --- Overlay layout (used for small viewports)\n\n  /**\n   * Returns whether to use \"overlay layout\" for side-navigation and sidepanels.\n   * Overlay layout means that elements like side-navigation and sidepanels are\n   * displayes on top of the content. It is used for small viewports.\n   *\n   * Note: Has nothing to do with OverlayService or OverlayLayout and will probably\n   * be renamed.\n   */\n  public useOverlayLayout(): boolean {\n    return window.matchMedia('(max-width: 1199.9px)').matches;\n  }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAAA;;;;;;;;AAQG;IACS;AAAZ,CAAA,UAAY,gBAAgB,EAAA;AAC1B,IAAA,gBAAA,CAAA,OAAA,CAAA,GAAA,OAAe;AACf,IAAA,gBAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACf,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