source: trip-planner-front/node_modules/@angular/cdk/esm2015/layout/media-matcher.js@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 9.8 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { Injectable } from '@angular/core';
9import { Platform } from '@angular/cdk/platform';
10import * as i0 from "@angular/core";
11import * as i1 from "@angular/cdk/platform";
12/** Global registry for all dynamically-created, injected media queries. */
13const mediaQueriesForWebkitCompatibility = new Set();
14/** Style tag that holds all of the dynamically-created media queries. */
15let mediaQueryStyleNode;
16/** A utility for calling matchMedia queries. */
17export class MediaMatcher {
18 constructor(_platform) {
19 this._platform = _platform;
20 this._matchMedia = this._platform.isBrowser && window.matchMedia ?
21 // matchMedia is bound to the window scope intentionally as it is an illegal invocation to
22 // call it from a different scope.
23 window.matchMedia.bind(window) :
24 noopMatchMedia;
25 }
26 /**
27 * Evaluates the given media query and returns the native MediaQueryList from which results
28 * can be retrieved.
29 * Confirms the layout engine will trigger for the selector query provided and returns the
30 * MediaQueryList for the query provided.
31 */
32 matchMedia(query) {
33 if (this._platform.WEBKIT || this._platform.BLINK) {
34 createEmptyStyleRule(query);
35 }
36 return this._matchMedia(query);
37 }
38}
39MediaMatcher.ɵprov = i0.ɵɵdefineInjectable({ factory: function MediaMatcher_Factory() { return new MediaMatcher(i0.ɵɵinject(i1.Platform)); }, token: MediaMatcher, providedIn: "root" });
40MediaMatcher.decorators = [
41 { type: Injectable, args: [{ providedIn: 'root' },] }
42];
43MediaMatcher.ctorParameters = () => [
44 { type: Platform }
45];
46/**
47 * Creates an empty stylesheet that is used to work around browser inconsistencies related to
48 * `matchMedia`. At the time of writing, it handles the following cases:
49 * 1. On WebKit browsers, a media query has to have at least one rule in order for `matchMedia`
50 * to fire. We work around it by declaring a dummy stylesheet with a `@media` declaration.
51 * 2. In some cases Blink browsers will stop firing the `matchMedia` listener if none of the rules
52 * inside the `@media` match existing elements on the page. We work around it by having one rule
53 * targeting the `body`. See https://github.com/angular/components/issues/23546.
54 */
55function createEmptyStyleRule(query) {
56 if (mediaQueriesForWebkitCompatibility.has(query)) {
57 return;
58 }
59 try {
60 if (!mediaQueryStyleNode) {
61 mediaQueryStyleNode = document.createElement('style');
62 mediaQueryStyleNode.setAttribute('type', 'text/css');
63 document.head.appendChild(mediaQueryStyleNode);
64 }
65 if (mediaQueryStyleNode.sheet) {
66 mediaQueryStyleNode.sheet.insertRule(`@media ${query} {body{ }}`, 0);
67 mediaQueriesForWebkitCompatibility.add(query);
68 }
69 }
70 catch (e) {
71 console.error(e);
72 }
73}
74/** No-op matchMedia replacement for non-browser platforms. */
75function noopMatchMedia(query) {
76 // Use `as any` here to avoid adding additional necessary properties for
77 // the noop matcher.
78 return {
79 matches: query === 'all' || query === '',
80 media: query,
81 addListener: () => { },
82 removeListener: () => { }
83 };
84}
85//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVkaWEtbWF0Y2hlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy9jZGsvbGF5b3V0L21lZGlhLW1hdGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBQ0gsT0FBTyxFQUFDLFVBQVUsRUFBQyxNQUFNLGVBQWUsQ0FBQztBQUN6QyxPQUFPLEVBQUMsUUFBUSxFQUFDLE1BQU0sdUJBQXVCLENBQUM7OztBQUUvQywyRUFBMkU7QUFDM0UsTUFBTSxrQ0FBa0MsR0FBZ0IsSUFBSSxHQUFHLEVBQVUsQ0FBQztBQUUxRSx5RUFBeUU7QUFDekUsSUFBSSxtQkFBaUQsQ0FBQztBQUV0RCxnREFBZ0Q7QUFFaEQsTUFBTSxPQUFPLFlBQV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