{"version":3,"file":"odx-angular-components-loading-spinner.mjs","sources":["../../../../libs/angular/components/loading-spinner/src/lib/loading-spinner.component.ts","../../../../libs/angular/components/loading-spinner/src/lib/loading-spinner.component.html","../../../../libs/angular/components/loading-spinner/src/lib/loading-spinner.directive.ts","../../../../libs/angular/components/loading-spinner/src/lib/loading-spinner.module.ts","../../../../libs/angular/components/loading-spinner/src/odx-angular-components-loading-spinner.ts"],"sourcesContent":["import { ChangeDetectionStrategy, Component, Input, OnInit, ViewEncapsulation, inject } from '@angular/core';\nimport { WindowRef } from '@odx/angular';\nimport { CircularProgressComponent } from '@odx/angular/components/circular-progress';\nimport { CSSComponent, CSSModifier } from '@odx/angular/internal';\nimport { injectElement } from '@odx/angular/utils';\n\nconst BROWSER_TRANSPARENT_COLOR = 'rgba(0, 0, 0, 0)';\n\n/**\n * Represents a loading spinner component.\n */\n@CSSComponent('loading-spinner')\n@Component({\n  standalone: true,\n  selector: 'odx-loading-spinner',\n  templateUrl: './loading-spinner.component.html',\n  imports: [CircularProgressComponent],\n  encapsulation: ViewEncapsulation.None,\n  changeDetection: ChangeDetectionStrategy.OnPush,\n  host: {\n    class: 'odx-animate-fade-in',\n  },\n})\nexport class LoadingSpinnerComponent implements OnInit {\n  private readonly windowRef = inject(WindowRef);\n\n  protected backgroundColor: string | null = null;\n\n  public readonly element = injectElement();\n\n  /**\n   * Indicates whether the color of the loading spinner should be automatically determined.\n   * If set to true, the color will be based on the theme of the parent container.\n   * If set to false, the color will be the default color specified in the component's styles.\n   *\n   * @type {boolean}\n   * @default false\n   */\n  @CSSModifier()\n  @Input()\n  public autoColor = false;\n\n  public ngOnInit(): void {\n    this.backgroundColor = this.resolveBackgroundColor(this.element.nativeElement);\n  }\n\n  private resolveBackgroundColor(element: HTMLElement): string | null {\n    const { backgroundColor } = this.windowRef.nativeWindow.getComputedStyle(element);\n    if (backgroundColor !== BROWSER_TRANSPARENT_COLOR) {\n      return backgroundColor;\n    }\n    if (element.parentElement) {\n      return this.resolveBackgroundColor(element.parentElement);\n    }\n    return null;\n  }\n}\n","<odx-circular-progress size=\"auto\" value=\"-1\" />\n<div class=\"odx-loading-spinner__backdrop\" [style.backgroundColor]=\"backgroundColor\"></div>\n","import { booleanAttribute, Directive, inject, Injector, Input, numberAttribute, Renderer2 } from '@angular/core';\nimport { WindowRef } from '@odx/angular';\nimport { DynamicViewRef, DynamicViewService } from '@odx/angular/cdk/dynamic-view';\nimport { deferFn, injectElement, px, waitForAnimations } from '@odx/angular/utils';\nimport { LoadingSpinnerComponent } from './loading-spinner.component';\n\nconst LOADING_SPINNER_PARENT_CLASS = 'odx-loading-spinner-parent';\n\n/**\n * A directive that controls the display of a loading spinner overlay on the host element.\n * This directive can dynamically create or remove a loading spinner based on the `isLoading` state.\n * It modifies the host element's styles to ensure the spinner is displayed correctly, and optionally,\n * it can set a minimum height to prevent layout shifts.\n */\n@Directive({\n  standalone: true,\n  selector: '[odxLoadingSpinner]',\n  // providers: [DisabledController.connect()],\n})\nexport class LoadingSpinnerDirective {\n  // private readonly disabledController = DisabledController.inject();\n  // private readonly hasDisabledControllerOnHost = !!inject(DisabledController, { optional: true });\n  private readonly dynamicViewService = inject(DynamicViewService);\n  private readonly hostElement = injectElement();\n  private readonly renderer = inject(Renderer2);\n  private readonly injector = inject(Injector);\n  private readonly windowRef = inject(WindowRef);\n\n  private parentMinHeight?: number;\n  private viewRef: DynamicViewRef<typeof LoadingSpinnerComponent> | null = null;\n\n  /**\n   * Whether the spinner should automatically adjust its color based on the background.\n   * Allows the user to specify if the spinner should use automatic color adjustment.\n   *\n   * @type {boolean}\n   * @default false\n   */\n  @Input({ alias: 'odxLoadingSpinnerAutoColor', transform: booleanAttribute })\n  public autoColor = false;\n\n  /**\n   * Controls whether the spinner is visible or not.\n   * Manages the loading state, showing or hiding the spinner accordingly.\n   *\n   * @type {boolean}\n   */\n  @Input({ alias: 'odxLoadingSpinner', transform: booleanAttribute })\n  public set isLoading(value: boolean) {\n    if (value) {\n      this.createSpinner();\n    } else {\n      this.removeSpinner();\n    }\n  }\n  public get isLoading(): boolean {\n    return this.viewRef !== null;\n  }\n\n  /**\n   * Sets the minimum height for the host element when the spinner is active, to avoid layout shifts.\n   * Specifies the minimum height for the spinner's parent element.\n   *\n   * @type {number}\n   */\n  @Input({ alias: 'odxLoadingSpinnerMinHeight', transform: numberAttribute })\n  public set minHeight(value: number) {\n    this.parentMinHeight = value;\n    this.isLoading && this.setParentHeight();\n  }\n\n  /**\n   * Resets styles applied to the parent element when the spinner is removed.\n   * Removes the class, minHeight, and position styles.\n   */\n  public resetParentStyles(): void {\n    this.renderer.removeClass(this.hostElement.nativeElement, LOADING_SPINNER_PARENT_CLASS);\n    this.renderer.removeStyle(this.hostElement.nativeElement, 'minHeight');\n    this.renderer.removeStyle(this.hostElement.nativeElement, 'position');\n  }\n\n  private setParentHeight(): void {\n    this.renderer.setStyle(this.hostElement.nativeElement, 'minHeight', this.parentMinHeight ? px(this.parentMinHeight) : 'inherit');\n  }\n\n  private createSpinner(): void {\n    this.renderer.addClass(this.hostElement.nativeElement, LOADING_SPINNER_PARENT_CLASS);\n    this.setParentHeight();\n    if (this.hasStaticPosition()) {\n      this.renderer.setStyle(this.hostElement.nativeElement, 'position', 'relative');\n    }\n    this.viewRef = this.dynamicViewService.createView(LoadingSpinnerComponent, {\n      injector: this.injector,\n      context: { autoColor: this.autoColor },\n      host: this.hostElement.nativeElement,\n    });\n    deferFn(() => (this.hostElement.nativeElement.scrollTop = 0));\n  }\n\n  private removeSpinner(): void {\n    const viewRef = this.viewRef;\n    this.viewRef = null;\n    if (!viewRef) return;\n\n    const element = viewRef.getElement();\n    this.renderer.addClass(element, 'odx-animate-fade-out');\n    waitForAnimations(element).then(() => {\n      viewRef.destroy();\n      this.resetParentStyles();\n    });\n  }\n\n  private hasStaticPosition(): boolean {\n    return this.windowRef.nativeWindow.getComputedStyle(this.hostElement.nativeElement).position === 'static';\n  }\n}\n","import { NgModule } from '@angular/core';\nimport { CoreModule } from '@odx/angular';\nimport { LoadingSpinnerComponent } from './loading-spinner.component';\nimport { LoadingSpinnerDirective } from './loading-spinner.directive';\n\nconst modules = [LoadingSpinnerComponent, LoadingSpinnerDirective];\n\n@NgModule({\n  imports: modules,\n  exports: [CoreModule, ...modules],\n})\nexport class LoadingSpinnerModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;AAMA,MAAM,yBAAyB,GAAG,kBAAkB;AAEpD;;AAEG;AAaI,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB,CAAA;AAA7B,IAAA,WAAA,GAAA;AACY,QAAA,IAAA,CAAA,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAEpC,IAAA,CAAA,eAAe,GAAkB,IAAI;QAE/B,IAAA,CAAA,OAAO,GAAG,aAAa,EAAE;AAEzC;;;;;;;AAOG;QAGI,IAAA,CAAA,SAAS,GAAG,KAAK;AAgBzB,IAAA;IAdQ,QAAQ,GAAA;AACb,QAAA,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC;IAChF;AAEQ,IAAA,sBAAsB,CAAC,OAAoB,EAAA;AACjD,QAAA,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,gBAAgB,CAAC,OAAO,CAAC;AACjF,QAAA,IAAI,eAAe,KAAK,yBAAyB,EAAE;AACjD,YAAA,OAAO,eAAe;QACxB;AACA,QAAA,IAAI,OAAO,CAAC,aAAa,EAAE;YACzB,OAAO,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,aAAa,CAAC;QAC3D;AACA,QAAA,OAAO,IAAI;IACb;+GAhCW,uBAAuB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA,CAAA;mGAAvB,uBAAuB,EAAA,YAAA,EAAA,IAAA,EAAA,QA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