UNPKG

1.71 kBSource Map (JSON)View Raw
1{"version":3,"file":"media-query.js","sourceRoot":"","sources":["src/media-query.ts"],"names":[],"mappings":"AAAA;;;;;;;;EAQE;AAEF;;;;;;;;;;;;EAYE;AACF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,UAAkB,EAAE,qBAA2D,EAAE,EAAE;IAC1H,IAAI,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IACxC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,qBAAqB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACzD,qBAAqB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC,CAAC","sourcesContent":["/**\n@license\nCopyright (c) 2018 The Polymer Project Authors. All rights reserved.\nThis code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt\nThe complete set of authors may be found at http://polymer.github.io/AUTHORS.txt\nThe complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt\nCode distributed by Google as part of the polymer project is also\nsubject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt\n*/\n\n/**\n Utility method that calls a callback whenever a media-query matches in response\n to the viewport size changing. The callback should take a boolean parameter\n (with `true` meaning the media query is matched).\n\n Example:\n\n import { installMediaQueryWatcher } from 'pwa-helpers/media-query.js';\n\n installMediaQueryWatcher(`(min-width: 600px)`, (matches) => {\n console.log(matches ? 'wide screen' : 'narrow sreen');\n });\n*/\nexport const installMediaQueryWatcher = (mediaQuery: string, layoutChangedCallback: (mediaQueryMatches: boolean) => void) => {\n let mql = window.matchMedia(mediaQuery);\n mql.addListener((e) => layoutChangedCallback(e.matches));\n layoutChangedCallback(mql.matches);\n};\n"]}
\No newline at end of file