blob: 6efdc9123056fa51bef8800bbfb6a2a31c27db49 [file] [log] [blame]
{"version":3,"file":"cdk-layout.umd.min.js","sources":["../../src/cdk/layout/media-matcher.ts","../../src/cdk/layout/breakpoints-observer.ts","../../src/cdk/layout/layout-module.ts","../../src/cdk/layout/breakpoints.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\nimport {Injectable} from '@angular/core';\nimport {Platform} from '@angular/cdk/platform';\n\n/** Global registry for all dynamically-created, injected media queries. */\nconst mediaQueriesForWebkitCompatibility: Set<string> = new Set<string>();\n\n/** Style tag that holds all of the dynamically-created media queries. */\nlet mediaQueryStyleNode: HTMLStyleElement | undefined;\n\n/** A utility for calling matchMedia queries. */\n@Injectable({providedIn: 'root'})\nexport class MediaMatcher {\n /** The internal matchMedia method to return back a MediaQueryList like object. */\n private _matchMedia: (query: string) => MediaQueryList;\n\n constructor(private _platform: Platform) {\n this._matchMedia = this._platform.isBrowser && window.matchMedia ?\n // matchMedia is bound to the window scope intentionally as it is an illegal invocation to\n // call it from a different scope.\n window.matchMedia.bind(window) :\n noopMatchMedia;\n }\n\n /**\n * Evaluates the given media query and returns the native MediaQueryList from which results\n * can be retrieved.\n * Confirms the layout engine will trigger for the selector query provided and returns the\n * MediaQueryList for the query provided.\n */\n matchMedia(query: string): MediaQueryList {\n if (this._platform.WEBKIT) {\n createEmptyStyleRule(query);\n }\n return this._matchMedia(query);\n }\n}\n\n/**\n * For Webkit engines that only trigger the MediaQueryListListener when\n * there is at least one CSS selector for the respective media query.\n */\nfunction createEmptyStyleRule(query: string) {\n if (mediaQueriesForWebkitCompatibility.has(query)) {\n return;\n }\n\n try {\n if (!mediaQueryStyleNode) {\n mediaQueryStyleNode = document.createElement('style');\n mediaQueryStyleNode.setAttribute('type', 'text/css');\n document.head!.appendChild(mediaQueryStyleNode);\n }\n\n if (mediaQueryStyleNode.sheet) {\n (mediaQueryStyleNode.sheet as CSSStyleSheet)\n .insertRule(`@media ${query} {.fx-query-test{ }}`, 0);\n mediaQueriesForWebkitCompatibility.add(query);\n }\n } catch (e) {\n console.error(e);\n }\n}\n\n/** No-op matchMedia replacement for non-browser platforms. */\nfunction noopMatchMedia(query: string): MediaQueryList {\n // Use `as any` here to avoid adding additional necessary properties for\n // the noop matcher.\n return {\n matches: query === 'all' || query === '',\n media: query,\n addListener: () => {},\n removeListener: () => {}\n } as any;\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {Injectable, NgZone, OnDestroy} from '@angular/core';\nimport {MediaMatcher} from './media-matcher';\nimport {combineLatest, concat, Observable, Subject, Observer} from 'rxjs';\nimport {debounceTime, map, skip, startWith, take, takeUntil} from 'rxjs/operators';\nimport {coerceArray} from '@angular/cdk/coercion';\n\n\n/** The current state of a layout breakpoint. */\nexport interface BreakpointState {\n /** Whether the breakpoint is currently matching. */\n matches: boolean;\n /**\n * A key boolean pair for each query provided to the observe method,\n * with its current matched state.\n */\n breakpoints: {\n [key: string]: boolean;\n };\n}\n\n/** The current state of a layout breakpoint. */\ninterface InternalBreakpointState {\n /** Whether the breakpoint is currently matching. */\n matches: boolean;\n /** The media query being to be matched */\n query: string;\n}\n\ninterface Query {\n observable: Observable<InternalBreakpointState>;\n mql: MediaQueryList;\n}\n\n/** Utility for checking the matching state of @media queries. */\n@Injectable({providedIn: 'root'})\nexport class BreakpointObserver implements OnDestroy {\n /** A map of all media queries currently being listened for. */\n private _queries = new Map<string, Query>();\n /** A subject for all other observables to takeUntil based on. */\n private _destroySubject = new Subject<void>();\n\n constructor(private _mediaMatcher: MediaMatcher, private _zone: NgZone) {}\n\n /** Completes the active subject, signalling to all other observables to complete. */\n ngOnDestroy() {\n this._destroySubject.next();\n this._destroySubject.complete();\n }\n\n /**\n * Whether one or more media queries match the current viewport size.\n * @param value One or more media queries to check.\n * @returns Whether any of the media queries match.\n */\n isMatched(value: string | string[]): boolean {\n const queries = splitQueries(coerceArray(value));\n return queries.some(mediaQuery => this._registerQuery(mediaQuery).mql.matches);\n }\n\n /**\n * Gets an observable of results for the given queries that will emit new results for any changes\n * in matching of the given queries.\n * @param value One or more media queries to check.\n * @returns A stream of matches for the given queries.\n */\n observe(value: string | string[]): Observable<BreakpointState> {\n const queries = splitQueries(coerceArray(value));\n const observables = queries.map(query => this._registerQuery(query).observable);\n\n let stateObservable = combineLatest(observables);\n // Emit the first state immediately, and then debounce the subsequent emissions.\n stateObservable = concat(\n stateObservable.pipe(take(1)),\n stateObservable.pipe(skip(1), debounceTime(0)));\n return stateObservable.pipe(map((breakpointStates: InternalBreakpointState[]) => {\n const response: BreakpointState = {\n matches: false,\n breakpoints: {},\n };\n breakpointStates.forEach((state: InternalBreakpointState) => {\n response.matches = response.matches || state.matches;\n response.breakpoints[state.query] = state.matches;\n });\n return response;\n }));\n }\n\n /** Registers a specific query to be listened for. */\n private _registerQuery(query: string): Query {\n // Only set up a new MediaQueryList if it is not already being listened for.\n if (this._queries.has(query)) {\n return this._queries.get(query)!;\n }\n\n const mql: MediaQueryList = this._mediaMatcher.matchMedia(query);\n\n // Create callback for match changes and add it is as a listener.\n const queryObservable = new Observable<MediaQueryList>((observer: Observer<MediaQueryList>) => {\n // Listener callback methods are wrapped to be placed back in ngZone. Callbacks must be placed\n // back into the zone because matchMedia is only included in Zone.js by loading the\n // webapis-media-query.js file alongside the zone.js file. Additionally, some browsers do not\n // have MediaQueryList inherit from EventTarget, which causes inconsistencies in how Zone.js\n // patches it.\n const handler = (e: any) => this._zone.run(() => observer.next(e));\n mql.addListener(handler);\n\n return () => {\n mql.removeListener(handler);\n };\n }).pipe(\n startWith(mql),\n map((nextMql: MediaQueryList) => ({query, matches: nextMql.matches})),\n takeUntil(this._destroySubject)\n );\n\n // Add the MediaQueryList to the set of queries.\n const output = {observable: queryObservable, mql};\n this._queries.set(query, output);\n return output;\n }\n}\n\n/**\n * Split each query string into separate query strings if two queries are provided as comma\n * separated.\n */\nfunction splitQueries(queries: string[]): string[] {\n return queries.map((query: string) => query.split(','))\n .reduce((a1: string[], a2: string[]) => a1.concat(a2))\n .map(query => query.trim());\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\nimport {NgModule} from '@angular/core';\n\n\n@NgModule({})\nexport class LayoutModule {}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n// PascalCase is being used as Breakpoints is used like an enum.\n// tslint:disable-next-line:variable-name\nexport const Breakpoints = {\n XSmall: '(max-width: 599.99px)',\n Small: '(min-width: 600px) and (max-width: 959.99px)',\n Medium: '(min-width: 960px) and (max-width: 1279.99px)',\n Large: '(min-width: 1280px) and (max-width: 1919.99px)',\n XLarge: '(min-width: 1920px)',\n\n Handset: '(max-width: 599.99px) and (orientation: portrait), ' +\n '(max-width: 959.99px) and (orientation: landscape)',\n Tablet: '(min-width: 600px) and (max-width: 839.99px) and (orientation: portrait), ' +\n '(min-width: 960px) and (max-width: 1279.99px) and (orientation: landscape)',\n Web: '(min-width: 840px) and (orientation: portrait), ' +\n '(min-width: 1280px) and (orientation: landscape)',\n\n HandsetPortrait: '(max-width: 599.99px) and (orientation: portrait)',\n TabletPortrait: '(min-width: 600px) and (max-width: 839.99px) and (orientation: portrait)',\n WebPortrait: '(min-width: 840px) and (orientation: portrait)',\n\n HandsetLandscape: '(max-width: 959.99px) and (orientation: landscape)',\n TabletLandscape: '(min-width: 960px) and (max-width: 1279.99px) and (orientation: landscape)',\n WebLandscape: '(min-width: 1280px) and (orientation: landscape)',\n};\n"],"names":["createEmptyStyleRule","query","mediaQueriesForWebkitCompatibility","has","mediaQueryStyleNode","document","createElement","setAttribute","appendChild","sheet","insertRule","add","e","console","error","noopMatchMedia","matches","media","addListener","removeListener","splitQueries","queries","map","split","reduce","a1","a2","concat","trim","LayoutModule","type","NgModule","args","Set","MediaMatcher","_platform","this","_matchMedia","isBrowser","window","matchMedia","bind","prototype","WEBKIT","Injectable","providedIn","Platform","BreakpointObserver","_mediaMatcher","_zone","_queries","Map","_destroySubject","Subject","ngOnDestroy","next","complete","isMatched","value","_this","coerceArray","some","mediaQuery","_registerQuery","mql","observe","observables","observable","stateObservable","combineLatest","pipe","take","skip","debounceTime","breakpointStates","response","breakpoints","forEach","state","get","queryObservable","Observable","observer","handler","run","startWith","nextMql","takeUntil","output","set","NgZone","Breakpoints","XSmall","Small","Medium","Large","XLarge","Handset","Tablet","Web","HandsetPortrait","TabletPortrait","WebPortrait","HandsetLandscape","TabletLandscape","WebLandscape"],"mappings":";;;;;;;wiBAgDA,SAASA,GAAqBC,GAC5B,IAAIC,EAAmCC,IAAIF,GAI3C,IACOG,IACHA,EAAsBC,SAASC,cAAc,SAC7CF,EAAoBG,aAAa,OAAQ,YACzCF,SAAa,KAAEG,YAAYJ,IAGzBA,EAAoBK,QACrBL,EAAyB,MACrBM,WAAW,UAAUT,EAAhC,uBAA6D,GACvDC,EAAmCS,IAAIV,IAEzC,MAAOW,GACPC,QAAQC,MAAMF,IAKlB,QAASG,GAAed,GAGtB,OACEe,QAAmB,QAAVf,GAA6B,KAAVA,EAC5BgB,MAAOhB,EACPiB,YAAW,aACXC,eAAc,cCwDlB,QAASC,GAAaC,GACpB,MAAOA,GAAQC,IAAG,SAAErB,GAAkB,MAAAA,GAAMsB,MAAM,OACnCC,OAAM,SAAEC,EAAcC,GAAiB,MAAAD,GAAGE,OAAOD,KACjDJ,IAAG,SAACrB,GAAS,MAAAA,GAAM2B,SC/HpC,GFIIxB,GEJJyB,EAAA,WAAA,QAAAA,MAC2B,sBAD3BC,KAACC,EAAAA,SAADC,YACAH,KFAM3B,EAAkD,GAAI+B,KAM5DC,EAAA,WAKE,QAAFA,GAAsBC,GAAAC,KAAt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