{"version":3,"file":"ngx-fixed-footer.mjs","sources":["../../../projects/ngx-fixed-footer/src/lib/ngx-fixed-footer.constants.ts","../../../projects/ngx-fixed-footer/src/lib/ngx-fixed-footer.provider.ts","../../../projects/ngx-fixed-footer/src/lib/ngx-fixed-footer.directive.ts","../../../projects/ngx-fixed-footer/src/public-api.ts","../../../projects/ngx-fixed-footer/src/ngx-fixed-footer.ts"],"sourcesContent":["import { NgxFixedFooterOptions } from './ngx-fixed-footer.interface';\n\nexport const DEFAULT_CSS_ATTRIBUTE = 'padding';\nexport const DEFAULT_CONTAINER_SELECTOR = '[role=\"main\"]';\nexport const DEFAULT_FIXED_FOOTER_OPTIONS: NgxFixedFooterOptions = {\n  containerSelector: DEFAULT_CONTAINER_SELECTOR,\n  cssAttribute: DEFAULT_CSS_ATTRIBUTE\n};\n","import { InjectionToken, Provider } from '@angular/core';\nimport { DEFAULT_CONTAINER_SELECTOR, DEFAULT_CSS_ATTRIBUTE } from './ngx-fixed-footer.constants';\nimport { NgxFixedFooterOptions } from './ngx-fixed-footer.interface';\n\nexport const APP_FIXED_FOOTER_OPTIONS_TOKEN = new InjectionToken<NgxFixedFooterOptions>('[ngxFixedFooter] Options');\n\nexport const provideFixedFooter = (options: Partial<NgxFixedFooterOptions>): Provider => {\n  return {\n    provide: APP_FIXED_FOOTER_OPTIONS_TOKEN,\n    useValue: {\n      cssAttribute: options.cssAttribute || DEFAULT_CSS_ATTRIBUTE,\n      containerSelector: options.containerSelector || DEFAULT_CONTAINER_SELECTOR\n    }\n  };\n};\n","import {\n  DOCUMENT,\n  Directive,\n  ElementRef,\n  OnDestroy,\n  OnInit,\n  Renderer2,\n  computed,\n  effect,\n  inject,\n  input,\n  signal\n} from '@angular/core';\nimport { DEFAULT_FIXED_FOOTER_OPTIONS } from './ngx-fixed-footer.constants';\nimport { NgxFixedFooterCssAttribute, NgxFixedFooterOptions } from './ngx-fixed-footer.interface';\nimport { APP_FIXED_FOOTER_OPTIONS_TOKEN } from './ngx-fixed-footer.provider';\n\n@Directive({\n  selector: '[ngxFixedFooter]'\n})\nexport class NgxFixedFooterDirective implements OnDestroy, OnInit {\n  private readonly document = inject(DOCUMENT);\n  private readonly el = inject(ElementRef);\n  private readonly render = inject(Renderer2);\n  private options: NgxFixedFooterOptions =\n    inject(APP_FIXED_FOOTER_OPTIONS_TOKEN, { optional: true }) || DEFAULT_FIXED_FOOTER_OPTIONS;\n  private readonly hasResizeObserver = typeof ResizeObserver !== 'undefined';\n  private resizeObserver?: ResizeObserver;\n\n  private offsetHeight = signal<number | undefined>(undefined);\n  private prevContainerSelector = signal<string | undefined>(undefined);\n\n  public containerSelector = input<string>(this.options.containerSelector);\n  public cssAttribute = input<NgxFixedFooterCssAttribute>(this.options.cssAttribute);\n\n  private container = computed(() => {\n    const selector = this.containerSelector() || this.options.containerSelector;\n    return this.document.body.querySelector<HTMLElement>(selector);\n  });\n\n  constructor() {\n    // swap selector\n    effect(() => {\n      if (!this.hasResizeObserver || !this.document) return;\n      const containerSelector = this.containerSelector();\n      const offsetHeight = this.offsetHeight();\n      if (!containerSelector || typeof offsetHeight !== 'number') return;\n      const cssAttribute = this.cssAttribute();\n      const prevContainerSelector = this.prevContainerSelector();\n      if (prevContainerSelector && prevContainerSelector !== containerSelector) {\n        const prevContainer = this.document.body.querySelector<HTMLElement>(prevContainerSelector);\n        if (prevContainer) {\n          this.removeStyle(prevContainer, cssAttribute);\n        }\n      }\n      const container = this.document.body.querySelector<HTMLElement>(containerSelector);\n      if (container) {\n        this.setStyle(container, cssAttribute, offsetHeight);\n        this.prevContainerSelector.set(containerSelector);\n      }\n    });\n\n    // swap css attribute\n    effect(() => {\n      if (!this.hasResizeObserver || !this.document) return;\n      const container = this.container();\n      const offsetHeight = this.offsetHeight();\n      if (!container || typeof offsetHeight !== 'number') return;\n      const cssAttribute = this.cssAttribute();\n      this.removeStyle(container, cssAttribute === 'padding' ? 'margin' : 'padding');\n      this.setStyle(container, cssAttribute, offsetHeight);\n    });\n  }\n\n  public ngOnInit(): void {\n    if (this.hasResizeObserver && this.document) {\n      this.resizeObserver = new ResizeObserver(() => this.checkHeight());\n      this.resizeObserver.observe(this.html);\n    }\n  }\n\n  public ngOnDestroy(): void {\n    const container = this.container();\n    if (this.resizeObserver && this.document && container) {\n      this.removeStyle(container, this.cssAttribute());\n      this.resizeObserver.unobserve(this.html);\n    }\n  }\n\n  private checkHeight(): void {\n    const height = this.html.offsetHeight;\n    const container = this.container();\n    if (this.offsetHeight() !== height && container) {\n      this.setStyle(container, this.cssAttribute(), height);\n      this.offsetHeight.set(height);\n    }\n  }\n\n  private removeStyle(container: HTMLElement, cssAttribute: NgxFixedFooterCssAttribute): void {\n    if (!container) {\n      throw new Error(`Cannot removeStyle to undefined container`);\n    }\n    this.render.setStyle(container, `${cssAttribute}-bottom`, '');\n  }\n\n  private setStyle(container: HTMLElement, cssAttribute: NgxFixedFooterCssAttribute, height: number): void {\n    if (!container) {\n      throw new Error(`Cannot setStyle to undefined container`);\n    }\n    this.render.setStyle(container, `${cssAttribute}-bottom`, height === 0 ? '' : `${height}px`);\n  }\n\n  private get html(): HTMLElement {\n    return this.el.nativeElement;\n  }\n}\n","/*\n * Public API Surface of ngx-fixed-footer\n */\n\nexport * from './lib/ngx-fixed-footer.constants';\nexport * from './lib/ngx-fixed-footer.directive';\nexport * from './lib/ngx-fixed-footer.interface';\nexport * from './lib/ngx-fixed-footer.provider';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;AAEO,MAAM,qBAAqB,GAAG;AAC9B,MAAM,0BAA0B,GAAG;AAC7B,MAAA,4BAA4B,GAA0B;AACjE,IAAA,iBAAiB,EAAE,0BAA0B;AAC7C,IAAA,YAAY,EAAE;;;MCFH,8BAA8B,GAAG,IAAI,cAAc,CAAwB,0BAA0B;AAErG,MAAA,kBAAkB,GAAG,CAAC,OAAuC,KAAc;IACtF,OAAO;AACL,QAAA,OAAO,EAAE,8BAA8B;AACvC,QAAA,QA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