/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { coerceArray } from '@angular/cdk/coercion'; import { Injectable, NgZone } from '@angular/core'; import { combineLatest, concat, Observable, Subject } from 'rxjs'; import { debounceTime, map, skip, startWith, take, takeUntil } from 'rxjs/operators'; import { MediaMatcher } from './media-matcher'; import * as i0 from "@angular/core"; import * as i1 from "./media-matcher"; /** Utility for checking the matching state of @media queries. */ export class BreakpointObserver { constructor(_mediaMatcher, _zone) { this._mediaMatcher = _mediaMatcher; this._zone = _zone; /** A map of all media queries currently being listened for. */ this._queries = new Map(); /** A subject for all other observables to takeUntil based on. */ this._destroySubject = new Subject(); } /** Completes the active subject, signalling to all other observables to complete. */ ngOnDestroy() { this._destroySubject.next(); this._destroySubject.complete(); } /** * Whether one or more media queries match the current viewport size. * @param value One or more media queries to check. * @returns Whether any of the media queries match. */ isMatched(value) { const queries = splitQueries(coerceArray(value)); return queries.some(mediaQuery => this._registerQuery(mediaQuery).mql.matches); } /** * Gets an observable of results for the given queries that will emit new results for any changes * in matching of the given queries. * @param value One or more media queries to check. * @returns A stream of matches for the given queries. */ observe(value) { const queries = splitQueries(coerceArray(value)); const observables = queries.map(query => this._registerQuery(query).observable); let stateObservable = combineLatest(observables); // Emit the first state immediately, and then debounce the subsequent emissions. stateObservable = concat(stateObservable.pipe(take(1)), stateObservable.pipe(skip(1), debounceTime(0))); return stateObservable.pipe(map(breakpointStates => { const response = { matches: false, breakpoints: {}, }; breakpointStates.forEach(({ matches, query }) => { response.matches = response.matches || matches; response.breakpoints[query] = matches; }); return response; })); } /** Registers a specific query to be listened for. */ _registerQuery(query) { // Only set up a new MediaQueryList if it is not already being listened for. if (this._queries.has(query)) { return this._queries.get(query); } const mql = this._mediaMatcher.matchMedia(query); // Create callback for match changes and add it is as a listener. const queryObservable = new Observable((observer) => { // Listener callback methods are wrapped to be placed back in ngZone. Callbacks must be placed // back into the zone because matchMedia is only included in Zone.js by loading the // webapis-media-query.js file alongside the zone.js file. Additionally, some browsers do not // have MediaQueryList inherit from EventTarget, which causes inconsistencies in how Zone.js // patches it. const handler = (e) => this._zone.run(() => observer.next(e)); mql.addListener(handler); return () => { mql.removeListener(handler); }; }).pipe(startWith(mql), map(({ matches }) => ({ query, matches })), takeUntil(this._destroySubject)); // Add the MediaQueryList to the set of queries. const output = { observable: queryObservable, mql }; this._queries.set(query, output); return output; } } BreakpointObserver.ɵprov = i0.ɵɵdefineInjectable({ factory: function BreakpointObserver_Factory() { return new BreakpointObserver(i0.ɵɵinject(i1.MediaMatcher), i0.ɵɵinject(i0.NgZone)); }, token: BreakpointObserver, providedIn: "root" }); BreakpointObserver.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; BreakpointObserver.ctorParameters = () => [ { type: MediaMatcher }, { type: NgZone } ]; /** * Split each query string into separate query strings if two queries are provided as comma * separated. */ function splitQueries(queries) { return queries.map(query => query.split(',')) .reduce((a1, a2) => a1.concat(a2)) .map(query => query.trim()); } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnJlYWtwb2ludHMtb2JzZXJ2ZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvY2RrL2xheW91dC9icmVha3BvaW50cy1vYnNlcnZlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMsV0FBVyxFQUFDLE1BQU0sdUJBQXVCLENBQUM7QUFDbEQsT0FBTyxFQUFDLFVBQVUsRUFBRSxNQUFNLEVBQVksTUFBTSxlQUFlLENBQUM7QUFDNUQsT0FBTyxFQUFDLGFBQWEsRUFBRSxNQUFNLEVBQUUsVUFBVSxFQUFZLE9BQU8sRUFBQyxNQUFNLE1BQU0sQ0FBQztBQUMxRSxPQUFPLEVBQUMsWUFBWSxFQUFFLEdBQUcsRU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