|
| 1 | +/** |
| 2 | + * Copyright 2018 Google Inc. All Rights Reserved. |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * Unless required by applicable law or agreed to in writing, software |
| 8 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | + * See the License for the specific language governing permissions and |
| 11 | + * limitations under the License. |
| 12 | + */ |
| 13 | + |
| 14 | +// If the loader is already loaded, just stop. |
| 15 | +if (!self.define) { |
| 16 | + const registry = {}; |
| 17 | + |
| 18 | + // Used for `eval` and `importScripts` where we can't get script URL by other means. |
| 19 | + // In both cases, it's safe to use a global var because those functions are synchronous. |
| 20 | + let nextDefineUri; |
| 21 | + |
| 22 | + const singleRequire = (uri, parentUri) => { |
| 23 | + uri = new URL(uri + ".js", parentUri).href; |
| 24 | + return ( |
| 25 | + registry[uri] || |
| 26 | + new Promise((resolve) => { |
| 27 | + if ("document" in self) { |
| 28 | + const script = document.createElement("script"); |
| 29 | + script.src = uri; |
| 30 | + script.onload = resolve; |
| 31 | + document.head.appendChild(script); |
| 32 | + } else { |
| 33 | + nextDefineUri = uri; |
| 34 | + importScripts(uri); |
| 35 | + resolve(); |
| 36 | + } |
| 37 | + }).then(() => { |
| 38 | + const promise = registry[uri]; |
| 39 | + if (!promise) { |
| 40 | + throw new Error(`Module ${uri} didn’t register its module`); |
| 41 | + } |
| 42 | + return promise; |
| 43 | + }) |
| 44 | + ); |
| 45 | + }; |
| 46 | + |
| 47 | + self.define = (depsNames, factory) => { |
| 48 | + const uri = |
| 49 | + nextDefineUri || |
| 50 | + ("document" in self ? document.currentScript.src : "") || |
| 51 | + location.href; |
| 52 | + if (registry[uri]) { |
| 53 | + // Module is already loading or loaded. |
| 54 | + return; |
| 55 | + } |
| 56 | + const exports = {}; |
| 57 | + const require = (depUri) => singleRequire(depUri, uri); |
| 58 | + const specialDeps = { |
| 59 | + module: { uri }, |
| 60 | + exports, |
| 61 | + require, |
| 62 | + }; |
| 63 | + registry[uri] = Promise.all( |
| 64 | + depsNames.map((depName) => specialDeps[depName] || require(depName)), |
| 65 | + ).then((deps) => { |
| 66 | + factory(...deps); |
| 67 | + return exports; |
| 68 | + }); |
| 69 | + }; |
| 70 | +} |
| 71 | +define(["./workbox-c676b6d3"], (workbox) => { |
| 72 | + self.skipWaiting(); |
| 73 | + workbox.clientsClaim(); |
| 74 | + |
| 75 | + /** |
| 76 | + * The precacheAndRoute() method efficiently caches and responds to |
| 77 | + * requests for URLs in the manifest. |
| 78 | + * See https://goo.gl/S9QRab |
| 79 | + */ |
| 80 | + workbox.precacheAndRoute( |
| 81 | + [ |
| 82 | + { |
| 83 | + url: "registerSW.js", |
| 84 | + revision: "711bd134fba5e3500fbfc72b61696bf7", |
| 85 | + }, |
| 86 | + { |
| 87 | + url: "index.html", |
| 88 | + revision: "0.gg92c0fmgi", |
| 89 | + }, |
| 90 | + ], |
| 91 | + {}, |
| 92 | + ); |
| 93 | + workbox.cleanupOutdatedCaches(); |
| 94 | + workbox.registerRoute( |
| 95 | + new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), { |
| 96 | + allowlist: [/^\/$/], |
| 97 | + }), |
| 98 | + ); |
| 99 | +}); |
0 commit comments