{ "version": 3, "sources": ["src/app/core/services/device.service.ts"], "sourcesContent": ["import { isPlatformBrowser } from '@angular/common';\nimport { Inject, Injectable, PLATFORM_ID } from '@angular/core';\nimport { fromEvent, Observable, of, ReplaySubject } from 'rxjs';\nimport {\n debounceTime,\n distinctUntilChanged,\n map,\n shareReplay,\n} from 'rxjs/operators';\nimport { WINDOW } from './window.service';\n\nexport interface WindowSize {\n innerHeight: number;\n innerWidth: number;\n ratio: number;\n isDesktop: boolean;\n}\n\n@Injectable({\n providedIn: 'root',\n})\nexport class DeviceService {\n private resize: Observable;\n windowSize: ReplaySubject;\n breakPointSwitch: Observable;\n breakPoint = 768;\n isDesktop: Observable;\n\n constructor(\n @Inject(WINDOW) private window: Window,\n @Inject(PLATFORM_ID) private platformId: Object\n ) {\n if (isPlatformBrowser(platformId)) {\n this.resize = fromEvent(this.window, 'resize');\n } else {\n this.resize = of(null);\n }\n this.windowSize = new ReplaySubject(1);\n this.windowSize.next(this.calculateWindowSizes());\n this.resize\n .pipe(\n debounceTime(100),\n map(event => this.calculateWindowSizes())\n )\n .subscribe(this.windowSize);\n this.breakPointSwitch = this.windowSize.pipe(\n distinctUntilChanged(\n (x: WindowSize, y: WindowSize) => x.isDesktop === y.isDesktop\n )\n );\n\n this.isDesktop = this.windowSize.pipe(\n map(size => size.isDesktop),\n distinctUntilChanged(),\n shareReplay(1)\n );\n }\n\n calculateWindowSizes(): WindowSize {\n if (isPlatformBrowser(this.platformId)) {\n return this.calculateWindowParams(\n this.window.innerWidth,\n this.window.innerHeight\n );\n } else {\n //smallest supported screen\n return this.calculateWindowParams(375, 559);\n }\n }\n calculateWindowParams(width: number, height: number): WindowSize {\n return {\n innerHeight: height,\n innerWidth: width,\n ratio: width / height,\n isDesktop: width >= this.breakPoint,\n };\n }\n}\n"], "mappings": "2JAqBA,IAAaA,GAAa,IAAA,CAApB,MAAOA,CAAa,CAOtBC,YAC4BC,EACKC,EAAkB,CADvB,KAAAD,OAAAA,EACK,KAAAC,WAAAA,EALjC,KAAAC,WAAa,IAOLC,EAAkBF,CAAU,EAC5B,KAAKG,OAASC,EAAU,KAAKL,OAAQ,QAAQ,EAE7C,KAAKI,OAASE,EAAG,IAAI,EAEzB,KAAKC,WAAa,IAAIC,EAAc,CAAC,EACrC,KAAKD,WAAWE,KAAK,KAAKC,qBAAoB,CAAE,EAChD,KAAKN,OACAO,KACGC,EAAa,GAAG,EAChBC,EAAIC,GAAS,KAAKJ,qBAAoB,CAAE,CAAC,EAE5CK,UAAU,KAAKR,UAAU,EAC9B,KAAKS,iBAAmB,KAAKT,WAAWI,KACpCM,EACI,CAACC,EAAeC,IAAkBD,EAAEE,YAAcD,EAAEC,SAAS,CAChE,EAGL,KAAKA,UAAY,KAAKb,WAAWI,KAC7BE,EAAIQ,GAAQA,EAAKD,SAAS,EAC1BH,EAAoB,EACpBK,EAAY,CAAC,CAAC,CAEtB,CAEAZ,sBAAoB,CAChB,OAAIP,EAAkB,KAAKF,UAAU,EAC1B,KAAKsB,sBACR,KAAKvB,OAAOwB,WACZ,KAAKxB,OAAOyB,WAAW,EAIpB,KAAKF,sBAAsB,IAAK,GAAG,CAElD,CACAA,sBAAsBG,EAAeC,EAAc,CAC/C,MAAO,CACHF,YAAaE,EACbH,WAAYE,EACZE,MAAOF,EAAQC,EACfP,UAAWM,GAAS,KAAKxB,WAEjC,iDAvDSJ,GAAa+B,EAQVC,CAAM,EAAAD,EACNE,CAAW,CAAA,CAAA,CAAA,iCATdjC,EAAakC,QAAblC,EAAamC,UAAAC,WAFV,MAAM,CAAA,CAAA,SAETpC,CAAa,GAAA", "names": ["DeviceService", "constructor", "window", "platformId", "breakPoint", "isPlatformBrowser", "resize", "fromEvent", "of", "windowSize", "ReplaySubject", "next", "calculateWindowSizes", "pipe", "debounceTime", "map", "event", "subscribe", "breakPointSwitch", "distinctUntilChanged", "x", "y", "isDesktop", "size", "shareReplay", "calculateWindowParams", "innerWidth", "innerHeight", "width", "height", "ratio", "\u0275\u0275inject", "WINDOW", "PLATFORM_ID", "factory", "\u0275fac", "providedIn"] }