{"version":3,"file":"ng-aos.mjs","sources":["../../src/lib/cssAnimation.ts","../../src/lib/aos.ts","../../src/ng-aos.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport type { Styles, Easing } from '../types/Inputs';\n\n@Injectable({ providedIn: 'root' })\nexport class CssAnimationService {\n  private _styleElement: HTMLStyleElement | null = null;\n  private _cache = new Map<string, string>(); // hash -> className\n\n  constructor() {\n    if (typeof document !== 'undefined') {\n      this._styleElement = document.createElement('style');\n      this._styleElement.setAttribute('data-css-animation', '');\n      document.head.appendChild(this._styleElement);\n    }\n  }\n\n  /**\n   * Generate a random CSS class with animation\n   * and append to document head\n   */\n  createRandomAnimationClass(\n    hideStyles: Styles = { opacity: '0' },\n    showStyles: Styles = { opacity: '1' },\n    duration: number = 500,\n    delay: number = 0,\n    easing: Easing = ''\n  ): string {\n    if (!this._styleElement) {\n      throw new Error(\n        '<style data-css-animation> not appended to document <head>'\n      );\n    }\n\n    const hash = this._generateHash({\n      hideStyles,\n      showStyles,\n      duration,\n      delay,\n      easing,\n    });\n\n    const existingClass = this._cache.get(hash);\n    if (existingClass) {\n      return existingClass;\n    }\n\n    const className = `anim_${Math.random().toString(36).substring(2, 9)}`;\n    const keyframesName = `kf_${Math.random().toString(36).substring(2, 9)}`;\n\n    const hideCss = this._objToString(hideStyles);\n    const showCss = this._objToString(showStyles);\n\n    const css = `\n      @keyframes ${keyframesName} {\n        0% { ${hideCss} }\n        100% { ${showCss} }\n      }\n\n      .${className} {\n        animation-name: ${keyframesName};\n        animation-duration: ${duration}ms;\n        animation-delay: ${delay}ms;\n        animation-timing-function: ${easing || 'linear'};\n        animation-fill-mode: forwards;\n      }\n    `;\n\n    this._styleElement.appendChild(document.createTextNode(css));\n    this._cache.set(hash, className);\n\n    return className;\n  }\n\n  /**\n   * Transform Object to string\n   */\n  private _objToString(styles: Styles): string {\n    return Object.entries(styles)\n      .map(([k, v]) => `${k}: ${v};`)\n      .join(' ');\n  }\n\n  /**\n   * Stringify but sorted\n   * Will produce same string no matter the order of keys in obj\n   */\n  private _sortedStringify(obj: Object): string {\n    if (obj === null || typeof obj !== 'object') return String(obj);\n    if (Array.isArray(obj))\n      return `[${obj.map((v) => this._sortedStringify(v)).join(',')}]`;\n\n    const keys = Object.keys(obj).sort();\n    return `{${keys\n      .map((k) => `${k}:${this._sortedStringify(obj[k as keyof Object])}`)\n      .join(',')}}`;\n  }\n\n  /**\n   * Hash generator\n   */\n  private _generateHash(obj: Object): string {\n    const str = this._sortedStringify(obj);\n    let hash = 0;\n    for (let i = 0; i < str.length; i++) {\n      hash = (hash << 5) - hash + str.charCodeAt(i);\n      hash |= 0;\n    }\n    return `h${Math.abs(hash).toString(36)}`;\n  }\n}\n","import {\n  Directive,\n  ElementRef,\n  EventEmitter,\n  Inject,\n  Input,\n  OnDestroy,\n  OnInit,\n  Output,\n  Renderer2,\n  PLATFORM_ID,\n} from '@angular/core';\n\nimport { isPlatformBrowser } from '@angular/common';\n\nimport type { Styles, Threshold, Easing } from '../types/Inputs';\n\nimport { CssAnimationService } from './cssAnimation';\n\n/**\n * Animate element when user scrolls it into view\n */\n@Directive({\n  selector: '[ng-aos]',\n  standalone: true,\n})\nexport class NgAos implements OnDestroy, OnInit {\n  /**\n   * Styles to apply when the element is hidden.\n   */\n  @Input('hide') hideStyles: Styles = {};\n\n  /**\n   * Styles to apply when the element becomes visible.\n   */\n  @Input('show') showStyles: Styles = {};\n\n  /**\n   * Duration of the show animation in milliseconds.\n   */\n  @Input() duration: number = 500;\n\n  /**\n   * Delay before the show animation starts, in milliseconds.\n   */\n  @Input() delay: number = 0;\n\n  /**\n   * CSS easing function for the show animation.\n   * Controls the acceleration curve of the transition.\n   */\n  @Input() easing: Easing = '';\n\n  /**\n   * Percentage of the element that must be visible before triggering the animation.\n   */\n  @Input() threshold: Threshold = 0.6;\n\n  /**\n   * Margin around the root element used by IntersectionObserver.\n   * Example usage:\n   *  - '0px'    → triggers exactly when the element enters the viewport\n   *  - '100px'  → triggers 100px before the element enters\n   *  - '-50px'  → triggers after the element is 50px inside the viewport\n   */\n  @Input() rootMargin: `${number}px` = '0px';\n\n  /**\n   * Optional CSS class that handles animation.\n   * If set, then the CSS is responsible for hiding/showing the element,\n   * not the directive\n   */\n  @Input() aosClass: string = '';\n\n  /**\n   * Emits an event when the element enters the viewport.\n   */\n  @Output() intersection = new EventEmitter<ElementRef>();\n\n  // Indicates whether the code is running in the browser (used for SSR safety)\n  private _isBrowser: boolean;\n  // Css class used to animate element\n  private _animationClass: string = '';\n  // Intersection observer instance\n  private _observer!: IntersectionObserver;\n\n  constructor(\n    private _element: ElementRef,\n    private _renderer: Renderer2,\n    private _css: CssAnimationService,\n    @Inject(PLATFORM_ID) private _platformId: Object\n  ) {\n    this._isBrowser = isPlatformBrowser(this._platformId);\n  }\n\n  ngOnInit() {\n    if (this._isBrowser) {\n      this._animationClass =\n        this.aosClass ||\n        this._css.createRandomAnimationClass(\n          this.hideStyles,\n          this.showStyles,\n          this.duration,\n          this.delay,\n          this.easing\n        );\n\n      this._setHideStyles();\n      this._createObserver();\n      this._startObserving();\n    }\n  }\n\n  private _setHideStyles() {\n    if (this.aosClass) {\n      return;\n    }\n    for (const style of Object.keys(this.hideStyles)) {\n      this._renderer.setStyle(\n        this._element.nativeElement,\n        style,\n        this.hideStyles[style as keyof CSSStyleDeclaration]\n      );\n    }\n  }\n\n  private _createObserver() {\n    const options = {\n      root: null,\n      rootMargin: this.rootMargin,\n      threshold: this.threshold,\n    };\n\n    this._observer = new IntersectionObserver((entries, observer) => {\n      entries.forEach((entry) => {\n        if (entry.isIntersecting && entry.intersectionRatio >= this.threshold) {\n          this._handleIntersection();\n        }\n      });\n    }, options);\n  }\n\n  private _startObserving() {\n    this._observer?.observe(this._element.nativeElement);\n  }\n\n  private _handleIntersection() {\n    const target = this._element.nativeElement;\n    this._renderer.addClass(target, this._animationClass);\n    this.intersection.emit(this._element.nativeElement);\n    this._observer?.unobserve(target);\n  }\n\n  ngOnDestroy() {\n    if (this._observer) {\n      this._observer.disconnect();\n    }\n  }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;MAIa,mBAAmB,CAAA;IACtB,aAAa,GAA4B,IAAI;AAC7C,IAAA,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;AAE3C,IAAA,WAAA,GAAA;AACE,QAAA,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;YACnC,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC;YACpD,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,oBAAoB,EAAE,EAAE,CAAC;YACzD,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC;QAC/C;IACF;AAEA;;;AAGG;IACH,0BAA0B,CACxB,aAAqB,EAAE,OAAO,EAAE,GAAG,EAAE,EACrC,UAAA,GAAqB,EAAE,OAAO,EAAE,GAAG,EAAE,EACrC,QAAA,GAAmB,GAAG,EACtB,KAAA,GAAgB,CAAC,EACjB,MAAA,GAAiB,EAAE,EAAA;AAEnB,QAAA,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;AACvB,YAAA,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D;QACH;AAEA,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC;YAC9B,UAAU;YACV,UAAU;YACV,QAAQ;YACR,KAAK;YACL,MAAM;AACP,SAAA,CAAC;QAEF,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;QAC3C,IAAI,aAAa,EAAE;AACjB,YAAA,OAAO,aAAa;QACtB;QAEA,MAAM,SAAS,GAAG,CAAA,KAAA,EAAQ,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;QACtE,MAAM,aAAa,GAAG,CAAA,GAAA,EAAM,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