tldraw/public/sw.js

133 lines
3.5 KiB
JavaScript
Raw Normal View History

2021-06-11 12:37:09 +00:00
/**
* Copyright 2018 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// If the loader is already loaded, just stop.
if (!self.define) {
2021-06-11 22:06:09 +00:00
const singleRequire = (name) => {
2021-06-11 12:37:09 +00:00
if (name !== 'require') {
2021-06-11 22:06:09 +00:00
name = name + '.js'
2021-06-11 12:37:09 +00:00
}
2021-06-11 22:06:09 +00:00
let promise = Promise.resolve()
2021-06-11 12:37:09 +00:00
if (!registry[name]) {
2021-06-11 22:06:09 +00:00
promise = new Promise(async (resolve) => {
if ('document' in self) {
const script = document.createElement('script')
script.src = name
document.head.appendChild(script)
script.onload = resolve
} else {
importScripts(name)
resolve()
}
})
2021-06-11 12:37:09 +00:00
}
return promise.then(() => {
if (!registry[name]) {
2021-06-11 22:06:09 +00:00
throw new Error(`Module ${name} didnt register its module`)
2021-06-11 12:37:09 +00:00
}
2021-06-11 22:06:09 +00:00
return registry[name]
})
}
2021-06-11 12:37:09 +00:00
const require = (names, resolve) => {
2021-06-11 22:06:09 +00:00
Promise.all(names.map(singleRequire)).then((modules) =>
resolve(modules.length === 1 ? modules[0] : modules)
)
}
2021-06-11 12:37:09 +00:00
const registry = {
2021-06-11 22:06:09 +00:00
require: Promise.resolve(require),
}
2021-06-11 12:37:09 +00:00
self.define = (moduleName, depsNames, factory) => {
if (registry[moduleName]) {
// Module is already loading or loaded.
2021-06-11 22:06:09 +00:00
return
2021-06-11 12:37:09 +00:00
}
registry[moduleName] = Promise.resolve().then(() => {
2021-06-11 22:06:09 +00:00
let exports = {}
2021-06-11 12:37:09 +00:00
const module = {
2021-06-11 22:06:09 +00:00
uri: location.origin + moduleName.slice(1),
}
2021-06-11 12:37:09 +00:00
return Promise.all(
2021-06-11 22:06:09 +00:00
depsNames.map((depName) => {
switch (depName) {
case 'exports':
return exports
case 'module':
return module
2021-06-11 12:37:09 +00:00
default:
2021-06-11 22:06:09 +00:00
return singleRequire(depName)
2021-06-11 12:37:09 +00:00
}
})
2021-06-11 22:06:09 +00:00
).then((deps) => {
const facValue = factory(...deps)
if (!exports.default) {
exports.default = facValue
2021-06-11 12:37:09 +00:00
}
2021-06-11 22:06:09 +00:00
return exports
})
})
}
2021-06-11 12:37:09 +00:00
}
2021-06-11 22:06:09 +00:00
define('./sw.js', ['./workbox-6b19f60b'], function (workbox) {
'use strict'
2021-06-11 12:37:09 +00:00
/**
2021-06-11 22:06:09 +00:00
* Welcome to your Workbox-powered service worker!
*
* You'll need to register this file in your web app.
* See https://goo.gl/nhQhGp
*
* The rest of the code is auto-generated. Please don't update this file
* directly; instead, make changes to your Workbox build configuration
* and re-run your build process.
* See https://goo.gl/2aRDsh
*/
2021-06-11 12:37:09 +00:00
2021-06-11 22:06:09 +00:00
importScripts()
self.skipWaiting()
workbox.clientsClaim()
workbox.registerRoute(
'/',
new workbox.NetworkFirst({
cacheName: 'start-url',
plugins: [
{
cacheWillUpdate: async ({ request, response, event, state }) => {
if (response && response.type === 'opaqueredirect') {
return new Response(response.body, {
status: 200,
statusText: 'OK',
headers: response.headers,
})
}
2021-06-11 12:37:09 +00:00
2021-06-11 22:06:09 +00:00
return response
},
},
],
}),
'GET'
)
workbox.registerRoute(
/.*/i,
new workbox.NetworkOnly({
cacheName: 'dev',
plugins: [],
}),
'GET'
)
})
2021-06-11 12:37:09 +00:00
//# sourceMappingURL=sw.js.map