{"version":3,"file":"bravobit-bb-foundation-utils.mjs","sources":["../../../projects/bb-foundation/utils/src/lib/directives/template.directive.ts","../../../projects/bb-foundation/utils/src/lib/directives/autosize.directive.ts","../../../projects/bb-foundation/utils/src/lib/directives/focus.directive.ts","../../../projects/bb-foundation/utils/src/lib/directives/focus-trap.directive.ts","../../../projects/bb-foundation/utils/src/lib/utils.module.ts","../../../projects/bb-foundation/utils/src/bravobit-bb-foundation-utils.ts"],"sourcesContent":["import {Directive, inject, Input, TemplateRef, ViewContainerRef} from '@angular/core';\n\n@Directive({\n    selector: '[bbTemplate]'\n})\nexport class BbTemplate {\n\n    // Dependencies.\n    private readonly _templateRef: TemplateRef<any> = inject(TemplateRef);\n    private readonly _viewContainerRef: ViewContainerRef = inject(ViewContainerRef);\n\n    @Input() set bbTemplate(content: string | TemplateRef<any>) {\n        // Get the template.\n        const template = content instanceof TemplateRef\n            ? content\n            : this._templateRef;\n\n        // Clear the view container ref and create the view.\n        this._viewContainerRef.clear();\n        this._viewContainerRef.createEmbeddedView(template);\n    }\n\n    // Required so that the template type checker can infer the type of the coerced inputs.\n    static ngAcceptInputType_bbTemplate: string | TemplateRef<any>;\n\n}\n","import {AfterViewInit, Directive, ElementRef, HostBinding, HostListener, inject, Input, numberAttribute, Renderer2} from '@angular/core';\n\n@Directive({\n    selector: 'textarea[bbAutosize]'\n})\nexport class BbAutosize implements AfterViewInit {\n\n    // Dependencies.\n    private readonly _renderer: Renderer2 = inject(Renderer2);\n    private readonly _elementRef: ElementRef = inject(ElementRef);\n\n    // Min/max heights for the textarea.\n    @Input() @HostBinding('style.min-height') minHeight: string | null = null;\n    @Input() @HostBinding('style.max-height') maxHeight: string | null = null;\n    @Input({transform: numberAttribute}) @HostBinding('rows') rows: number = 1;\n\n    get element() {\n        return this._elementRef?.nativeElement as HTMLTextAreaElement;\n    }\n\n    ngAfterViewInit() {\n        // Update the styles after the DOM has loaded.\n        this.updateStylesInitial();\n    }\n\n    @HostListener('window:resize')\n    onWindowResize() {\n        // Update the styles when the window is resized.\n        this.updateStyles();\n    }\n\n    @HostListener('input')\n    onInputReceived() {\n        // Update the styles after the textarea received input.\n        this.updateStyles();\n    }\n\n    private updateStyles() {\n        // Validate the element exists.\n        if (!this.element) {\n            return;\n        }\n\n        // Calculate border height which is not included in the scroll height.\n        const borderHeight = this.element?.offsetHeight - this.element?.clientHeight;\n\n        // Reset textarea height to auto that correctly calculate the new height.\n        this.setHeight('auto');\n\n        // Set new height.\n        this.setHeight(`${this.element?.scrollHeight + borderHeight}px`);\n    }\n\n    private setHeight(value: string) {\n        this._renderer.setStyle(this.element, 'height', value);\n    }\n\n    private updateStylesInitial() {\n        if (setTimeout === null || setTimeout === undefined) {\n            return this.updateStyles();\n        }\n\n        return setTimeout(() => this.updateStyles(), 0);\n    }\n\n}\n","import {AfterViewInit, Directive, ElementRef, inject, Input, NgZone} from '@angular/core';\nimport {GLOBAL_FOCUS_MODE, FocusMode} from '@bravobit/bb-foundation';\nimport {Platform} from '@angular/cdk/platform';\n\n@Directive({\n    selector: '[bbFocus]'\n})\nexport class BbFocus implements AfterViewInit {\n\n    // Dependencies.\n    private readonly _zone: NgZone = inject(NgZone);\n    private readonly _platform: Platform = inject(Platform);\n    private readonly _elementRef: ElementRef = inject(ElementRef);\n    private readonly _globalFocusMode: FocusMode = inject(GLOBAL_FOCUS_MODE);\n\n    // Inputs.\n    @Input() bbFocusMode: FocusMode | null = null;\n\n    private get nativeElement() {\n        return this._elementRef.nativeElement;\n    }\n\n    ngAfterViewInit() {\n        // Run the method outside the Angular zone.\n        this._zone.runOutsideAngular(() => this.focus());\n    }\n\n    private isMobile() {\n        return this._platform.IOS || this._platform.ANDROID;\n    }\n\n    private focus() {\n        const focusMode = this.bbFocusMode ?? this._globalFocusMode;\n        if (focusMode === 'only-desktop' && this.isMobile()) {\n            return;\n        }\n\n        // Check if set timeout exists and the user is\n        // using the site on desktop devices.\n        if (!setTimeout) {\n            return;\n        }\n\n        // Check if the element and the focus method exist, if so focus the element.\n        if (!this.nativeElement || !this.nativeElement.focus) {\n            return;\n        }\n\n        // Execute the focus method in a timeout.\n        setTimeout(() => this.nativeElement.focus(), 0);\n    }\n\n}\n","import {Directive, ElementRef, HostListener, inject} from '@angular/core';\nimport {Platform} from '@angular/cdk/platform';\n\n@Directive({\n    selector: '[bbFocusTrap]'\n})\nexport class BbFocusTrap {\n\n    // Dependencies.\n    private readonly _platform: Platform = inject(Platform);\n    private readonly _elementRef: ElementRef = inject(ElementRef);\n\n    private readonly _focusableElements = [\n        'a[href]',\n        'area[href]',\n        'input:not([disabled]):not([type=\"hidden\"]):not([aria-hidden])',\n        'select:not([disabled]):not([aria-hidden])',\n        'textarea:not([disabled]):not([aria-hidden])',\n        'button:not([disabled]):not([aria-hidden])',\n        'iframe',\n        'object',\n        'embed',\n        '[contenteditable]',\n        '[tabindex]:not([tabindex^=\"-\"])'\n    ];\n\n    @HostListener('keydown', ['$event'])\n    onKeydown(event: KeyboardEvent) {\n        // Validate it is a tab event.\n        if (!this.isTabEvent(event)) {\n            return;\n        }\n\n        // Trap the focus inside the element.\n        return this.trapFocus(event);\n    }\n\n    trapFocus(event: KeyboardEvent) {\n        // Validate that the DOM is available.\n        if (!this._platform.isBrowser) {\n            return;\n        }\n\n        // Get all focusable nodes.\n        const focusableNodes = this.getFocusableNodes();\n\n        // Focus the first available element if the focus\n        // is not in the modal.\n        if (!this.element.contains(document.activeElement)) {\n            return this.focus(focusableNodes[0]);\n        }\n\n        const focusedItemIndex = focusableNodes.indexOf(document.activeElement);\n\n        if (event.shiftKey && focusedItemIndex === 0) {\n            this.focus(focusableNodes[focusableNodes.length - 1]);\n            return event.preventDefault();\n        }\n\n        if (!event.shiftKey && focusedItemIndex === focusableNodes.length - 1) {\n            this.focus(focusableNodes[0]);\n            return event.preventDefault();\n        }\n    }\n\n    private get element() {\n        return this._elementRef.nativeElement;\n    }\n\n    private getFocusableNodes() {\n        const nodes = this.element.querySelectorAll(this._focusableElements);\n        return Array(...nodes);\n    }\n\n    private focus = (element: HTMLElement) => {\n        return element && element.focus && element.focus();\n    };\n\n    private isTabEvent = (event: KeyboardEvent) => {\n        return event?.key === 'Tab' || event?.keyCode === 9;\n    };\n\n}\n","import {BbFocusTrap} from './directives/focus-trap.directive';\nimport {BbTemplate} from './directives/template.directive';\nimport {BbAutosize} from './directives/autosize.directive';\nimport {BbFocus} from './directives/focus.directive';\nimport {NgModule} from '@angular/core';\n\n@NgModule({\n    imports: [\n        BbTemplate,\n        BbAutosize,\n        BbFocus,\n        BbFocusTrap\n    ],\n    exports: [\n        BbTemplate,\n        BbAutosize,\n        BbFocus,\n        BbFocusTrap\n    ]\n})\nexport class UtilsModule {\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;MAKa,UAAU,CAAA;;AAGF,IAAA,YAAY,GAAqB,MAAM,CAAC,WAAW,CAAC;AACpD,IAAA,iBAAiB,GAAqB,MAAM,CAAC,gBAAgB,CAAC;IAE/E,IAAa,UAAU,CAAC,OAAkC,EAAA;;AAEtD,QAAA,MAAM,QAAQ,GAAG,OAAO,YAAY;AAChC,cAAE;AACF,cAAE,IAAI,CAAC,YAAY;;AAGvB,QAAA,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE;AAC9B,QAAA,IAAI,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,QAAQ,CAAC;IACvD;;IAGA,OAAO,4BAA4B;wGAlB1B,UAAU,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;4FAAV,UAAU,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,cAAA,EAAA,MAAA,EAAA,EAAA,UAAA,EAAA,YAAA,EAAA,EAAA,QAAA,EAAA,EAAA,EAAA,CAAA;;4FAAV,UAAU,EAAA,UAAA,EAAA,CAAA;kBAHtB,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACP,oBAAA,QA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