UNPKG

@igo2/core

Version:
101 lines (96 loc) 3.62 kB
import * as i1 from '@angular/cdk/layout'; import { Breakpoints } from '@angular/cdk/layout'; import * as i0 from '@angular/core'; import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs'; var Media; (function (Media) { Media["Mobile"] = "mobile"; Media["Tablet"] = "tablet"; Media["Desktop"] = "desktop"; })(Media || (Media = {})); var MediaOrientation; (function (MediaOrientation) { MediaOrientation["Portrait"] = "portrait"; MediaOrientation["Landscape"] = "landscape"; })(MediaOrientation || (MediaOrientation = {})); class MediaService { media$ = new BehaviorSubject(undefined); orientation$ = new BehaviorSubject(undefined); constructor(breakpointObserver) { breakpointObserver .observe([Breakpoints.HandsetLandscape]) .subscribe((res) => { if (res.matches) { this.media$.next(Media.Mobile); this.orientation$.next(MediaOrientation.Landscape); } }); breakpointObserver .observe([Breakpoints.HandsetPortrait]) .subscribe((res) => { if (res.matches) { this.media$.next(Media.Mobile); this.orientation$.next(MediaOrientation.Portrait); } }); breakpointObserver .observe([Breakpoints.TabletLandscape]) .subscribe((res) => { if (res.matches) { this.media$.next(Media.Tablet); this.orientation$.next(MediaOrientation.Landscape); } }); breakpointObserver .observe([Breakpoints.TabletPortrait]) .subscribe((res) => { if (res.matches) { this.media$.next(Media.Tablet); this.orientation$.next(MediaOrientation.Portrait); } }); breakpointObserver.observe([Breakpoints.WebLandscape]).subscribe((res) => { if (res.matches) { this.media$.next(Media.Desktop); this.orientation$.next(MediaOrientation.Landscape); } }); breakpointObserver.observe([Breakpoints.WebPortrait]).subscribe((res) => { if (res.matches) { this.media$.next(Media.Desktop); this.orientation$.next(MediaOrientation.Portrait); } }); } getMedia() { return this.media$.value; } getOrientation() { return this.orientation$.value; } isTouchScreen() { return 'ontouchstart' in document.documentElement ? true : false; } isMobile() { const media = this.getMedia(); return media === 'mobile'; } isDesktop() { const media = this.getMedia(); return media === 'desktop'; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: MediaService, deps: [{ token: i1.BreakpointObserver }], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: MediaService, providedIn: 'root' }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: MediaService, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: () => [{ type: i1.BreakpointObserver }] }); /** * Generated bundle index. Do not edit. */ export { Media, MediaOrientation, MediaService }; //# sourceMappingURL=igo2-core-media.mjs.map