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CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;YACvC,uBAAuB,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;SACtC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,uBAAuB,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;IACtF,uBAAuB,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;AAC7D,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 Basic router that calls a callback whenever the location is updated.\n\n Example:\n\n import { installRouter } from 'pwa-helpers/router.js';\n\n installRouter((location) => handleNavigation(location));\n\n For example, if you're using this router in a Redux-connected component,\n you could dispatch an action in the callback:\n\n import { installRouter } from 'pwa-helpers/router.js';\n import { navigate } from '../actions/app.js';\n\n installRouter((location) => store.dispatch(navigate(location)))\n\n If you need to force a navigation to a new location programmatically, you can\n do so by pushing a new state using the History API, and then manually\n calling the callback with the new location:\n\n window.history.pushState({}, '', '/new-route');\n handleNavigation(window.location);\n\n Optionally, you can use the second argument to read the event that caused the\n navigation. For example, you may want to scroll to top only after a link click.\n\n installRouter((location, event) => {\n // Only scroll to top on link clicks, not popstate events.\n if (event && event.type === 'click') {\n window.scrollTo(0, 0);\n }\n handleNavigation(location);\n });\n*/\nexport const installRouter = (locationUpdatedCallback: (location:Location, event: Event|null) => void) => {\n document.body.addEventListener('click', e => {\n if (e.defaultPrevented || e.button !== 0 ||\n e.metaKey || e.ctrlKey || e.shiftKey) return;\n\n const anchor = e.composedPath().filter(\n n => (n as HTMLElement).tagName === 'A'\n )[0] as HTMLAnchorElement | undefined;\n if (!anchor || anchor.target ||\n anchor.hasAttribute('download') ||\n anchor.getAttribute('rel') === 'external') return;\n\n const href = anchor.href;\n if (!href || href.indexOf('mailto:') !== -1) return;\n\n const location = window.location;\n const origin = location.origin || location.protocol + '//' + location.host;\n if (href.indexOf(origin) !== 0) return;\n\n e.preventDefault();\n if (href !== location.href) {\n window.history.pushState({}, '', href);\n locationUpdatedCallback(location, e);\n }\n });\n\n window.addEventListener('popstate', e => locationUpdatedCallback(window.location, e));\n locationUpdatedCallback(window.location, null /* event */);\n};\n"]} |