{"version":3,"file":"odx-angular-cdk-active-indicator.mjs","sources":["../../../../libs/angular/cdk/active-indicator/src/lib/models/active-indicator-direction.ts","../../../../libs/angular/cdk/active-indicator/src/lib/models/active-indicator-position.ts","../../../../libs/angular/cdk/active-indicator/src/lib/active-indicator.directive.ts","../../../../libs/angular/cdk/active-indicator/src/odx-angular-cdk-active-indicator.ts"],"sourcesContent":["export type ActiveIndicatorDirection = typeof ActiveIndicatorDirection[keyof typeof ActiveIndicatorDirection];\n\nexport const ActiveIndicatorDirection = {\n  HORIZONTAL: 'horizontal',\n  VERTICAL: 'vertical',\n} as const;\n","export type ActiveIndicatorPosition = typeof ActiveIndicatorPosition[keyof typeof ActiveIndicatorPosition];\n\nexport const ActiveIndicatorPosition = {\n  START: 'start',\n  CENTER: 'center',\n  END: 'end',\n} as const;\n","import { AfterViewInit, Directive, Input, OnChanges } from '@angular/core';\nimport { CSSComponent, CSSModifier } from '@odx/angular/internal';\nimport { fromElementResize$ } from '@odx/angular/rxjs';\nimport { NgChanges, applyStyles, disableCSSTransitions, hasChanged, injectElement, isPresent, px, untilDestroyed } from '@odx/angular/utils';\nimport { BehaviorSubject, EMPTY, distinctUntilChanged, switchMap } from 'rxjs';\nimport { ActiveIndicatorPosition } from './models';\nimport { ActiveIndicatorDirection } from './models/active-indicator-direction';\n\n/**\n * `ActiveIndicatorDirective` is designed to adjust an indicator's position and size dynamically to highlight\n * the active element within a container. It's useful for tabs, menus, or any list where an active state is visually represented.\n * The directive can be customized to align the indicator based on the active element's position and supports\n * both horizontal and vertical orientations.\n *\n * To use this directive, apply it to the element you want to use as an active indicator.\n * Then, bind the active element using the `odxActiveIndicator` input. Optionally, specify\n * the container element with `odxActiveIndicatorParent` if the container is not the immediate parent of the indicator.\n *\n * @example\n * ```html\n * <div class=\"tabs-container\" #tabsContainer>\n *   @for(tab of tabs; track tab.id) {\n *   <div class=\"tab\" [class.active]=\"tab.isActive\" #tabElement>{{ tab.label }}</div>\n *   }\n *   <div class=\"indicator\" [odxActiveIndicator]=\"activeTabElement\" [odxActiveIndicatorParent]=\"tabsContainer\"></div>\n * </div>\n * ```\n *\n * ```ts\n * @Component({\n *   selector: 'app-tabs',\n *   templateUrl: './tabs.component.html',\n *   imports: [ActiveIndicatorDirective, NgForOf],\n * })\n * export class TabsComponent {\n *   tabs = [{ label: 'Tab 1', isActive: true }, { label: 'Tab 2', isActive: false }];\n *   @ViewChildren('tabElement') tabElements?: QueryList<ElementRef>;\n *   @ViewChild('tabsContainer') tabsContainer!: ElementRef;\n *\n *   get activeTabElement(): HTMLElement {\n *     const activeTab = this.tabElements?.find((tab) => tab.nativeElement.classList.contains('active'));\n *     return activeTab ? activeTab.nativeElement : null;\n *   }\n * }\n * ```\n */\n@CSSComponent('cdk-active-indicator')\n@Directive({\n  standalone: true,\n  selector: '[odxActiveIndicator]',\n})\nexport class ActiveIndicatorDirective implements OnChanges, AfterViewInit {\n  private readonly takeUntilDestroyed = untilDestroyed();\n  private readonly parentElement$$ = new BehaviorSubject<HTMLElement | null>(null);\n  private readonly onResize$ = this.parentElement$$.pipe(\n    distinctUntilChanged(),\n    switchMap((parentElement) => {\n      return parentElement ? fromElementResize$(parentElement) : EMPTY;\n    }),\n  );\n\n  public readonly element = injectElement();\n\n  /**\n   * Indicates whether the element is active or not.\n   *\n   * @type {boolean}\n   */\n  @CSSModifier()\n  public isActive = false;\n\n  /**\n   * The currently active element to which the indicator should align.\n   * It dynamically updates the indicator's position and size based on this element.\n   *\n   * @type {HTMLElement | null}\n   */\n  @Input('odxActiveIndicator')\n  public activeElement?: HTMLElement | null = null;\n\n  /**\n   * The parent container element of the active elements.\n   * If not set, the indicator's immediate parent element is used.\n   *\n   * @type {HTMLElement | null}\n   */\n  @Input('odxActiveIndicatorParent')\n  public set parent(value: HTMLElement | null) {\n    this.parentElement$$.next(value);\n  }\n  public get parent(): HTMLElement | null {\n    return this.parentElement$$.getValue();\n  }\n\n  /**\n   * The direction in which the indicator should move.\n   *\n   * @type {ActiveIndicatorDirection}\n   */\n  @CSSModifier()\n  @Input('odxActiveIndicatorDirection')\n  public direction: ActiveIndicatorDirection = ActiveIndicatorDirection.HORIZONTAL;\n\n  /**\n   * The position of the indicator relative to the active element.\n   *\n   * @type {ActiveIndicatorPosition}\n   */\n  @Input('odxActiveIndicatorPosition')\n  public position: ActiveIndicatorPosition = ActiveIndicatorPosition.CENTER;\n\n  public ngAfterViewInit(): void {\n    this.onResize$.pipe(this.takeUntilDestroyed()).subscribe(() => this.updateStyles());\n    this.parent ??= this.element.nativeElement.parentElement;\n  }\n\n  public ngOnChanges(changes: NgChanges<ActiveIndicatorDirective>): void {\n    if (hasChanged(changes, 'activeElement', false)) {\n      this.isActive = !!this.activeElement;\n    }\n    if (hasChanged(changes, ['activeElement', 'direction', 'position'])) {\n      this.updateStyles(!isPresent(changes.activeElement?.previousValue));\n    }\n  }\n\n  private updateStyles(disableTransition = false): void {\n    if (!this.activeElement) return;\n    const isHorizontal = this.direction === ActiveIndicatorDirection.HORIZONTAL;\n    const isVertical = this.direction === ActiveIndicatorDirection.VERTICAL;\n    const relativeOffset = this.getIndicatorRelativeOffset();\n\n    let transform = null;\n    if (isHorizontal) {\n      const positionX = this.getIndicatorPositionX(this.activeElement);\n      transform = `translateX(${px(positionX)}) translateX(${relativeOffset}%)`;\n    }\n    if (isVertical) {\n      const positionY = this.getIndicatorPositionY(this.activeElement);\n      transform = `translateY(${px(positionY)}) translateY(${relativeOffset}%)`;\n    }\n\n    disableTransition && disableCSSTransitions(this.element.nativeElement, true);\n    applyStyles(this.element.nativeElement, {\n      transform,\n      width: isHorizontal ? px(this.activeElement.offsetWidth) : null,\n      height: isVertical ? px(this.activeElement.offsetHeight) : null,\n    });\n    disableTransition && disableCSSTransitions(this.element.nativeElement, false);\n  }\n\n  private getIndicatorPositionX(activeElement: HTMLElement): number {\n    switch (this.position) {\n      case ActiveIndicatorPosition.START:\n        return activeElement.offsetLeft;\n      case ActiveIndicatorPosition.CENTER:\n        return activeElement.offsetLeft + activeElement.offsetWidth / 2;\n      case ActiveIndicatorPosition.END:\n        return activeElement.offsetLeft + activeElement.offsetWidth;\n    }\n  }\n\n  private getIndicatorPositionY(activeElement: HTMLElement): number {\n    switch (this.position) {\n      case ActiveIndicatorPosition.START:\n        return activeElement.offsetTop;\n      case ActiveIndicatorPosition.CENTER:\n        return activeElement.offsetTop + activeElement.offsetHeight / 2;\n      case ActiveIndicatorPosition.END:\n        return activeElement.offsetTop + activeElement.offsetHeight;\n    }\n  }\n\n  private getIndicatorRelativeOffset(): number {\n    switch (this.position) {\n      case ActiveIndicatorPosition.START:\n        return 0;\n      case ActiveIndicatorPosition.CENTER:\n        return -50;\n      case ActiveIndicatorPosition.END:\n        return -100;\n    }\n  }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;AAEO,MAAM,wBAAwB,GAAG;AACtC,IAAA,UAAU,EAAE,YAAY;AACxB,IAAA,QAAQ,EAAE,UAAU;;;ACFf,MAAM,uBAAuB,GAAG;AACrC,IAAA,KAAK,EAAE,OAAO;AACd,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,GAAG,EAAE,KAAK;;;ACGZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCG;AAMI,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB,CAAA;AAA9B,IAAA,WAAA,GAAA;QACY,IAAA,CAAA,kBAAkB,GAAG,cAAc,EAAE;AACrC,QAAA,IAAA,CAAA,eAAe,GAAG,IAAI,eAAe,CAAqB,IAAI,CAAC;AAC/D,QAAA,IAAA,CAAA,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CACpD,oBAAoB,EAAE,EACtB,SAAS,CAAC,CAAC,aAAa,KAAI;AAC1B,YAAA,OAAO,aAAa,GAAG,kBAAkB,CAAC,aAAa,CAAC,GAAG,KAAK;QAClE,CAAC,CAAC,CACH;QAEe,IAAA,CAAA,OAAO,GAAG,aAAa,EAA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