/** * @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 { Injectable } from '@angular/core'; import { Platform } from '@angular/cdk/platform'; import * as i0 from "@angular/core"; import * as i1 from "@angular/cdk/platform"; /** Global registry for all dynamically-created, injected media queries. */ const mediaQueriesForWebkitCompatibility = new Set(); /** Style tag that holds all of the dynamically-created media queries. */ let mediaQueryStyleNode; /** A utility for calling matchMedia queries. */ export class MediaMatcher { constructor(_platform) { this._platform = _platform; this._matchMedia = this._platform.isBrowser && window.matchMedia ? // matchMedia is bound to the window scope intentionally as it is an illegal invocation to // call it from a different scope. window.matchMedia.bind(window) : noopMatchMedia; } /** * Evaluates the given media query and returns the native MediaQueryList from which results * can be retrieved. * Confirms the layout engine will trigger for the selector query provided and returns the * MediaQueryList for the query provided. */ matchMedia(query) { if (this._platform.WEBKIT || this._platform.BLINK) { createEmptyStyleRule(query); } return this._matchMedia(query); } } MediaMatcher.ɵprov = i0.ɵɵdefineInjectable({ factory: function MediaMatcher_Factory() { return new MediaMatcher(i0.ɵɵinject(i1.Platform)); }, token: MediaMatcher, providedIn: "root" }); MediaMatcher.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; MediaMatcher.ctorParameters = () => [ { type: Platform } ]; /** * Creates an empty stylesheet that is used to work around browser inconsistencies related to * `matchMedia`. At the time of writing, it handles the following cases: * 1. On WebKit browsers, a media query has to have at least one rule in order for `matchMedia` * to fire. We work around it by declaring a dummy stylesheet with a `@media` declaration. * 2. In some cases Blink browsers will stop firing the `matchMedia` listener if none of the rules * inside the `@media` match existing elements on the page. We work around it by having one rule * targeting the `body`. See https://github.com/angular/components/issues/23546. */ function createEmptyStyleRule(query) { if (mediaQueriesForWebkitCompatibility.has(query)) { return; } try { if (!mediaQueryStyleNode) { mediaQueryStyleNode = document.createElement('style'); mediaQueryStyleNode.setAttribute('type', 'text/css'); document.head.appendChild(mediaQueryStyleNode); } if (mediaQueryStyleNode.sheet) { mediaQueryStyleNode.sheet.insertRule(`@media ${query} {body{ }}`, 0); mediaQueriesForWebkitCompatibility.add(query); } } catch (e) { console.error(e); } } /** No-op matchMedia replacement for non-browser platforms. */ function noopMatchMedia(query) { // Use `as any` here to avoid adding additional necessary properties for // the noop matcher. return { matches: query === 'all' || query === '', media: query, addListener: () => { }, removeListener: () => { } }; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVkaWEtbWF0Y2hlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy9jZGsvbGF5b3V0L21lZGlhLW1hdGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBQ0gsT0FBTyxFQUFDLFVBQVUsRUFBQyxNQUFNLGVBQWUsQ0FBQztBQUN6QyxPQUFPLEVBQUMsUUFBUSxFQUFDLE1BQU0sdUJBQXVCLENBQUM7OztBQUUvQywyRUFBMkU7QUFDM0UsTUFBTSxrQ0FBa0MsR0FBZ0IsSUFBSSxHQUFHLEVBQVUsQ0FBQztBQUUxRSx5RUFBeUU7QUFDekUsSUFBSSxtQkFBaUQsQ0FBQztBQUV0RCxnREFBZ0Q7QUFFaEQsTUFBTSxPQUFPLFlBQVk7SUFJdkIsWUFBb0IsU0FBbUI7UUFBbkIsY0FBUyxHQUFULFNBQVMsQ0FBVTtRQUNyQyxJQUFJLENBQUMsV0FBVyxHQUFHLElBQUksQ0FBQyxTQUFTLENBQUMsU0FBUyxJQUFJLE1BQU0sQ0FBQyxVQUFVLENBQUMsQ0FBQztZQUNoRSwwRkFBMEY7WUFDMUYsa0NBQWtDO1lBQ2xDLE1BQU0sQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUM7WUFDaEMsY0FBYyxDQUFDO0lBQ25CLENBQUM7SUFFRDs7Ozs7T0FLRztJQ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