{"version":3,"file":"pepperi-addons-ngx-lib-size-detector.mjs","sources":["../../../projects/ngx-lib/size-detector/size-detector.component.ts","../../../projects/ngx-lib/size-detector/size-detector.component.html","../../../projects/ngx-lib/size-detector/size-detector.module.ts","../../../projects/ngx-lib/size-detector/public-api.ts","../../../projects/ngx-lib/size-detector/pepperi-addons-ngx-lib-size-detector.ts"],"sourcesContent":["import {\n    Component,\n    OnInit,\n    AfterViewInit,\n    HostListener,\n    ElementRef,\n    Input,\n    Output,\n    EventEmitter,\n} from '@angular/core';\nimport { PepLayoutService, PepScreenSizeType } from '@pepperi-addons/ngx-lib';\n\ninterface IPepSizeDetectorItem {\n    id: PepScreenSizeType;\n    name: string;\n    css: string;\n}\n\n@Component({\n    selector: 'pep-size-detector',\n    templateUrl: './size-detector.component.html',\n})\nexport class PepSizeDetectorComponent implements AfterViewInit {\n    @Input() showScreenSize = false;\n\n    private _useAsWebComponent = false;\n    @Input()\n    set useAsWebComponent(value: boolean) {\n        if (value) {\n            this.exportFunctionsOnHostElement();\n        }\n    }\n    get useAsWebComponent(): boolean {\n        return this._useAsWebComponent;\n    }\n\n    @Output()\n    sizeChange: EventEmitter<IPepSizeDetectorItem> = new EventEmitter<IPepSizeDetectorItem>();\n\n    prefix = 'is-';\n    sizes: Array<IPepSizeDetectorItem> = [\n        {\n            id: PepScreenSizeType.XS,\n            name: 'xs',\n            css: `d-block d-sm-none`,\n        },\n        {\n            id: PepScreenSizeType.SM,\n            name: 'sm',\n            css: `d-none d-sm-block d-md-none`,\n        },\n        {\n            id: PepScreenSizeType.MD,\n            name: 'md',\n            css: `d-none d-md-block d-lg-none`,\n        },\n        {\n            id: PepScreenSizeType.LG,\n            name: 'lg',\n            css: `d-none d-lg-block d-xl-none`,\n        },\n        {\n            id: PepScreenSizeType.XL,\n            name: 'xl',\n            css: `d-none d-xl-block`,\n        },\n    ];\n\n    private currentSize: IPepSizeDetectorItem;\n\n    constructor(\n        private hostElement: ElementRef,\n        private layoutService: PepLayoutService\n    ) {\n        this.layoutService.onResize$.subscribe((size: PepScreenSizeType) => {\n            this.currentSize = this.sizes.find((s) => s.id === size);\n            this.sizeChange.emit(this.currentSize);\n        });\n    }\n\n    @HostListener('window:resize', ['$event'])\n    onResize(event): void {\n        this.detectScreenSize();\n    }\n\n    ngAfterViewInit(): void {\n        this.detectScreenSize();\n    }\n\n    private detectScreenSize(): void {\n        this.currentSize = this.sizes.find((x) => {\n            const el = this.hostElement.nativeElement.querySelector(\n                `.${this.prefix}${x.id}`\n            );\n            const isVisible = getComputedStyle(el).display !== 'none';\n\n            return isVisible;\n        });\n\n        this.layoutService.onResize(this.currentSize.id);\n    }\n\n    private exportFunctionsOnHostElement() {\n        // This is for web component usage for use those functions.\n        this.hostElement.nativeElement.getCurrentSize = this.getCurrentSize.bind(\n            this\n        );\n    }\n\n    getCurrentSize(): IPepSizeDetectorItem {\n        return this.currentSize;\n    }\n}\n","<!-- Bootstrap -->\n<!-- <div *ngFor=\"let s of sizes\" class=\"{{s.css + ' ' + (prefix + s.id) }}\">{{s.name}}</div> -->\n\n<!-- Angular flex-layout -->\n<div *ngFor=\"let s of sizes\" fxShow.xs=\"{{s.name == 'xs'}}\" fxShow.sm=\"{{s.name == 'sm'}}\"\n  fxShow.md=\"{{s.name == 'md'}}\" fxShow.lg=\"{{s.name == 'lg'}}\" fxShow.xl=\"{{s.name == 'xl'}}\"\n  class=\"{{s.css + ' ' + (prefix + s.id) }}\">\n  <ng-container *ngIf=\"showScreenSize\"> The current screen size is - {{s.name}}</ng-container>\n</div>","import { NgModule } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { ReactiveFormsModule } from '@angular/forms';\nimport { FlexLayoutModule } from '@angular/flex-layout';\n\nimport { PepNgxLibModule } from '@pepperi-addons/ngx-lib';\n\nimport { PepSizeDetectorComponent } from './size-detector.component';\n\n@NgModule({\n    imports: [\n        CommonModule,\n        ReactiveFormsModule,\n        FlexLayoutModule,\n        // ngx-lib modules\n        PepNgxLibModule,\n    ],\n    exports: [PepSizeDetectorComponent],\n    declarations: [PepSizeDetectorComponent],\n})\nexport class PepSizeDetectorModule {}\n","/*\n * Public API Surface of ngx-lib/size-detector\n */\nexport * from './size-detector.module';\nexport * from './size-detector.component';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;;MAsBa,wBAAwB,CAAA;IAgDjC,WACY,CAAA,WAAuB,EACvB,aAA+B,EAAA;AAD/B,QAAA,IAAW,CAAA,WAAA,GAAX,WAAW,CAAY;AACvB,QAAA,IAAa,CAAA,aAAA,GAAb,aAAa,CAAkB;AAjDlC,QAAA,IAAc,CAAA,cAAA,GAAG,KAAK,CAAC;AAExB,QAAA,IAAkB,CAAA,kBAAA,GAAG,KAAK,CAAC;AAYnC,QAAA,IAAA,CAAA,UAAU,GAAuC,IAAI,YAAY,EAAwB,CAAC;AAE1F,QAAA,IAAM,CAAA,MAAA,GAAG,KAAK,CAAC;QACf,IAAA,CAAA,KAAK,GAAgC;AACjC,YAAA;gBACI,EAAE,EAAE,iBAAiB,CAAC,EAAE;AACxB,gBAAA,IAAI,EAAE,IAAI;AACV,gBAAA,GAAG,EAAE,CAAmB,iBAAA,CAAA;AAC3B,aAAA;AACD,YAAA;gBACI,EAAE,EAAE,iBAAiB,CAAC,EAAE;AACxB,gBAAA,IAAI,EAAE,IAAI;AACV,gBAAA,GAAG,EAAE,CAA6B,2BAAA,CAAA;AACrC,aAAA;AACD,YAAA;gBACI,EAAE,EAAE,iBAAiB,CAAC,EAAE;AACxB,gBAAA,IAAI,EAAE,IAAI;AACV,gBAAA,GAAG,EAAE,CAA6B,2BAAA,CAAA;AACrC,aAAA;AACD,YAAA;gBACI,EAAE,EAAE,iBAAiB,CAAC,EAAE;AACxB,gBAAA,IAAI,EAAE,IAAI;AACV,gBAAA,GAAG,EAAE,CAA6B,2BAAA,CAAA;AACrC,aAAA;AACD,YAAA;gBACI,EAAE,EAAE,iBAAiB,CAAC,EAAE;AACx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