@nypl/web-reader 0.1.4 → 0.2.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ServiceWorker/sw.js +2 -0
- package/dist/cjs/ServiceWorker/sw.js.map +7 -0
- package/dist/cjs/index.js +683 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/esm/ServiceWorker/sw.js +1263 -0
- package/dist/esm/ServiceWorker/sw.js.map +7 -0
- package/dist/esm/index.js +88803 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/html-styles.css +2 -0
- package/dist/html-styles.css.map +7 -0
- package/dist/pdf-styles.css +2 -0
- package/dist/pdf-styles.css.map +7 -0
- package/dist/{HtmlReader → types/HtmlReader}/HtmlReaderContent.d.ts +3 -3
- package/dist/{HtmlReader → types/HtmlReader}/index.d.ts +22 -22
- package/dist/{HtmlReader → types/HtmlReader}/injectables.d.ts +30 -30
- package/dist/{PdfReader → types/PdfReader}/index.d.ts +11 -12
- package/dist/{PdfReader → types/PdfReader}/useMeasure.d.ts +7 -4
- package/dist/{ServiceWorker → types/ServiceWorker}/client.d.ts +9 -9
- package/dist/{ServiceWorker → types/ServiceWorker}/constants.d.ts +3 -3
- package/{src/ServiceWorker/index.ts → dist/types/ServiceWorker/index.d.ts} +0 -0
- package/dist/{ServiceWorker → types/ServiceWorker}/sw.d.ts +7 -7
- package/dist/{ServiceWorker → types/ServiceWorker}/types.d.ts +3 -3
- package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/ConformsTo.d.ts +3 -3
- package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/Contributor.d.ts +17 -17
- package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/EpubExtension.d.ts +47 -47
- package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/LanguageMap.d.ts +3 -3
- package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/Metadata.d.ts +46 -46
- package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/OPDSLink.d.ts +63 -63
- package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/PresentationHints.d.ts +53 -53
- package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/ReadiumLink.d.ts +58 -58
- package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/Subject.d.ts +16 -16
- package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/WebpubManifest.d.ts +14 -14
- package/dist/{constants.d.ts → types/constants.d.ts} +2 -2
- package/dist/{index.d.ts → types/index.d.ts} +7 -7
- package/dist/{types.d.ts → types/types.d.ts} +66 -66
- package/dist/{ui → types/ui}/Button.d.ts +9 -7
- package/dist/{ui → types/ui}/Header.d.ts +6 -6
- package/dist/{ui → types/ui}/HtmlSettings.d.ts +9 -9
- package/dist/{ui → types/ui}/PageButton.d.ts +7 -7
- package/dist/{ui → types/ui}/PdfSettings.d.ts +9 -9
- package/dist/{ui → types/ui}/SettingsButton.d.ts +5 -5
- package/dist/{ui → types/ui}/TableOfContent.d.ts +7 -7
- package/dist/{ui → types/ui}/ToggleButton.d.ts +10 -10
- package/dist/{ui → types/ui}/ToggleGroup.d.ts +8 -8
- package/dist/{ui → types/ui}/constants.d.ts +1 -1
- package/dist/{ui → types/ui}/hooks/useColorModeValue.d.ts +7 -7
- package/dist/{ui → types/ui}/hooks/useContainerWidth.d.ts +6 -6
- package/dist/{ui → types/ui}/hooks/useEventListener.d.ts +8 -8
- package/dist/{ui → types/ui}/manager.d.ts +9 -9
- package/dist/{ui → types/ui}/nypl-base-theme/components/button.d.ts +94 -94
- package/dist/{ui → types/ui}/nypl-base-theme/components/checkbox.d.ts +41 -41
- package/dist/{ui → types/ui}/nypl-base-theme/components/form-error.d.ts +14 -14
- package/dist/{ui → types/ui}/nypl-base-theme/components/form-label.d.ts +14 -14
- package/dist/{ui → types/ui}/nypl-base-theme/components/form.d.ts +15 -15
- package/dist/{ui → types/ui}/nypl-base-theme/components/input.d.ts +107 -107
- package/dist/{ui → types/ui}/nypl-base-theme/components/text-area.d.ts +34 -34
- package/dist/{ui → types/ui}/nypl-base-theme/foundations/breakpoints.d.ts +8 -8
- package/dist/{ui → types/ui}/nypl-base-theme/foundations/colors.d.ts +3 -3
- package/dist/{ui → types/ui}/nypl-base-theme/foundations/global.d.ts +13 -13
- package/dist/{ui → types/ui}/nypl-base-theme/foundations/radii.d.ts +12 -12
- package/dist/{ui → types/ui}/nypl-base-theme/foundations/spacing.d.ts +49 -49
- package/dist/{ui → types/ui}/nypl-base-theme/foundations/typography.d.ts +10 -10
- package/dist/{ui → types/ui}/nypl-base-theme/index.d.ts +6 -6
- package/dist/{ui → types/ui}/nypl-base-theme/types.d.ts +1 -1
- package/dist/{ui → types/ui}/theme/components/button.d.ts +78 -78
- package/dist/{ui → types/ui}/theme/components/text.d.ts +20 -20
- package/dist/{ui → types/ui}/theme/foundations/colors.d.ts +3 -3
- package/dist/{ui → types/ui}/theme/index.d.ts +11 -11
- package/dist/{ui → types/ui}/theme/types.d.ts +1 -1
- package/dist/{useWebReader.d.ts → types/useWebReader.d.ts} +7 -7
- package/dist/{utils → types/utils}/decryptAxisNow.d.ts +0 -0
- package/dist/{utils → types/utils}/fetch.d.ts +4 -4
- package/dist/{utils → types/utils}/getColor.d.ts +2 -2
- package/dist/{utils → types/utils}/toggleFullScreen.d.ts +5 -5
- package/package.json +21 -33
- package/dist/ServiceWorker/index.d.ts +0 -1
- package/dist/index.js +0 -8
- package/dist/web-reader.cjs.development.js +0 -3363
- package/dist/web-reader.cjs.development.js.map +0 -1
- package/dist/web-reader.cjs.production.min.js +0 -2
- package/dist/web-reader.cjs.production.min.js.map +0 -1
- package/dist/web-reader.esm.js +0 -3356
- package/dist/web-reader.esm.js.map +0 -1
- package/src/HtmlReader/HtmlReaderContent.tsx +0 -19
- package/src/HtmlReader/index.tsx +0 -262
- package/src/HtmlReader/injectables.ts +0 -26
- package/src/PdfReader/index.tsx +0 -492
- package/src/PdfReader/useMeasure.tsx +0 -68
- package/src/ServiceWorker/client.ts +0 -106
- package/src/ServiceWorker/constants.ts +0 -4
- package/src/ServiceWorker/sw.ts +0 -84
- package/src/ServiceWorker/types.ts +0 -3
- package/src/WebpubManifestTypes/ConformsTo.ts +0 -9
- package/src/WebpubManifestTypes/Contributor.ts +0 -24
- package/src/WebpubManifestTypes/EpubExtension.ts +0 -48
- package/src/WebpubManifestTypes/LanguageMap.ts +0 -5
- package/src/WebpubManifestTypes/Metadata.ts +0 -48
- package/src/WebpubManifestTypes/OPDSLink.ts +0 -251
- package/src/WebpubManifestTypes/PresentationHints.ts +0 -54
- package/src/WebpubManifestTypes/ReadiumLink.ts +0 -61
- package/src/WebpubManifestTypes/Subject.ts +0 -20
- package/src/WebpubManifestTypes/WebpubManifest.ts +0 -15
- package/src/constants.ts +0 -3
- package/src/index.tsx +0 -25
- package/src/types.ts +0 -94
- package/src/ui/Button.tsx +0 -12
- package/src/ui/Header.tsx +0 -89
- package/src/ui/HtmlSettings.tsx +0 -97
- package/src/ui/PageButton.tsx +0 -39
- package/src/ui/PdfSettings.tsx +0 -85
- package/src/ui/SettingsButton.tsx +0 -71
- package/src/ui/TableOfContent.tsx +0 -144
- package/src/ui/ToggleButton.tsx +0 -60
- package/src/ui/ToggleGroup.tsx +0 -41
- package/src/ui/constants.ts +0 -2
- package/src/ui/hooks/useColorModeValue.tsx +0 -19
- package/src/ui/hooks/useContainerWidth.ts +0 -24
- package/src/ui/hooks/useEventListener.ts +0 -26
- package/src/ui/manager.tsx +0 -73
- package/src/ui/nypl-base-theme/components/button.ts +0 -117
- package/src/ui/nypl-base-theme/components/checkbox.ts +0 -45
- package/src/ui/nypl-base-theme/components/form-error.ts +0 -15
- package/src/ui/nypl-base-theme/components/form-label.ts +0 -15
- package/src/ui/nypl-base-theme/components/form.ts +0 -16
- package/src/ui/nypl-base-theme/components/input.ts +0 -101
- package/src/ui/nypl-base-theme/components/text-area.ts +0 -17
- package/src/ui/nypl-base-theme/foundations/breakpoints.ts +0 -10
- package/src/ui/nypl-base-theme/foundations/colors.ts +0 -136
- package/src/ui/nypl-base-theme/foundations/global.ts +0 -16
- package/src/ui/nypl-base-theme/foundations/radii.ts +0 -13
- package/src/ui/nypl-base-theme/foundations/spacing.ts +0 -58
- package/src/ui/nypl-base-theme/foundations/typography.ts +0 -43
- package/src/ui/nypl-base-theme/index.ts +0 -42
- package/src/ui/nypl-base-theme/types.ts +0 -1
- package/src/ui/theme/components/button.ts +0 -85
- package/src/ui/theme/components/text.ts +0 -24
- package/src/ui/theme/foundations/colors.ts +0 -10
- package/src/ui/theme/index.ts +0 -34
- package/src/ui/theme/types.ts +0 -1
- package/src/useWebReader.tsx +0 -105
- package/src/utils/decryptAxisNow.ts +0 -45
- package/src/utils/fetch.ts +0 -13
- package/src/utils/getColor.ts +0 -14
- package/src/utils/toggleFullScreen.ts +0 -71
|
@@ -0,0 +1,1263 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __require = typeof require !== "undefined" ? require : (x) => {
|
|
21
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
22
|
+
};
|
|
23
|
+
var __async = (__this, __arguments, generator) => {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
var fulfilled = (value) => {
|
|
26
|
+
try {
|
|
27
|
+
step(generator.next(value));
|
|
28
|
+
} catch (e) {
|
|
29
|
+
reject(e);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var rejected = (value) => {
|
|
33
|
+
try {
|
|
34
|
+
step(generator.throw(value));
|
|
35
|
+
} catch (e) {
|
|
36
|
+
reject(e);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
40
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// node_modules/workbox-core/_version.js
|
|
45
|
+
"use strict";
|
|
46
|
+
try {
|
|
47
|
+
self["workbox:core:6.2.4"] && _();
|
|
48
|
+
} catch (e) {
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// node_modules/workbox-core/_private/logger.js
|
|
52
|
+
var logger = true ? null : (() => {
|
|
53
|
+
if (!("__WB_DISABLE_DEV_LOGS" in self)) {
|
|
54
|
+
self.__WB_DISABLE_DEV_LOGS = false;
|
|
55
|
+
}
|
|
56
|
+
let inGroup = false;
|
|
57
|
+
const methodToColorMap = {
|
|
58
|
+
debug: `#7f8c8d`,
|
|
59
|
+
log: `#2ecc71`,
|
|
60
|
+
warn: `#f39c12`,
|
|
61
|
+
error: `#c0392b`,
|
|
62
|
+
groupCollapsed: `#3498db`,
|
|
63
|
+
groupEnd: null
|
|
64
|
+
};
|
|
65
|
+
const print = function(method, args) {
|
|
66
|
+
if (self.__WB_DISABLE_DEV_LOGS) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (method === "groupCollapsed") {
|
|
70
|
+
if (/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
|
|
71
|
+
console[method](...args);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const styles = [
|
|
76
|
+
`background: ${methodToColorMap[method]}`,
|
|
77
|
+
`border-radius: 0.5em`,
|
|
78
|
+
`color: white`,
|
|
79
|
+
`font-weight: bold`,
|
|
80
|
+
`padding: 2px 0.5em`
|
|
81
|
+
];
|
|
82
|
+
const logPrefix = inGroup ? [] : ["%cworkbox", styles.join(";")];
|
|
83
|
+
console[method](...logPrefix, ...args);
|
|
84
|
+
if (method === "groupCollapsed") {
|
|
85
|
+
inGroup = true;
|
|
86
|
+
}
|
|
87
|
+
if (method === "groupEnd") {
|
|
88
|
+
inGroup = false;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const api = {};
|
|
92
|
+
const loggerMethods = Object.keys(methodToColorMap);
|
|
93
|
+
for (const key of loggerMethods) {
|
|
94
|
+
const method = key;
|
|
95
|
+
api[method] = (...args) => {
|
|
96
|
+
print(method, args);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return api;
|
|
100
|
+
})();
|
|
101
|
+
|
|
102
|
+
// node_modules/workbox-core/models/messages/messageGenerator.js
|
|
103
|
+
var fallback = (code, ...args) => {
|
|
104
|
+
let msg = code;
|
|
105
|
+
if (args.length > 0) {
|
|
106
|
+
msg += ` :: ${JSON.stringify(args)}`;
|
|
107
|
+
}
|
|
108
|
+
return msg;
|
|
109
|
+
};
|
|
110
|
+
var messageGenerator = true ? fallback : generatorFunction;
|
|
111
|
+
|
|
112
|
+
// node_modules/workbox-core/_private/WorkboxError.js
|
|
113
|
+
var WorkboxError = class extends Error {
|
|
114
|
+
constructor(errorCode, details) {
|
|
115
|
+
const message = messageGenerator(errorCode, details);
|
|
116
|
+
super(message);
|
|
117
|
+
this.name = errorCode;
|
|
118
|
+
this.details = details;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// node_modules/workbox-core/models/quotaErrorCallbacks.js
|
|
123
|
+
var quotaErrorCallbacks = new Set();
|
|
124
|
+
|
|
125
|
+
// node_modules/workbox-core/registerQuotaErrorCallback.js
|
|
126
|
+
function registerQuotaErrorCallback(callback) {
|
|
127
|
+
if (false) {
|
|
128
|
+
finalAssertExports.isType(callback, "function", {
|
|
129
|
+
moduleName: "workbox-core",
|
|
130
|
+
funcName: "register",
|
|
131
|
+
paramName: "callback"
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
quotaErrorCallbacks.add(callback);
|
|
135
|
+
if (false) {
|
|
136
|
+
logger.log("Registered a callback to respond to quota errors.", callback);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// node_modules/workbox-core/_private/cacheNames.js
|
|
141
|
+
var _cacheNameDetails = {
|
|
142
|
+
googleAnalytics: "googleAnalytics",
|
|
143
|
+
precache: "precache-v2",
|
|
144
|
+
prefix: "workbox",
|
|
145
|
+
runtime: "runtime",
|
|
146
|
+
suffix: typeof registration !== "undefined" ? registration.scope : ""
|
|
147
|
+
};
|
|
148
|
+
var _createCacheName = (cacheName) => {
|
|
149
|
+
return [_cacheNameDetails.prefix, cacheName, _cacheNameDetails.suffix].filter((value) => value && value.length > 0).join("-");
|
|
150
|
+
};
|
|
151
|
+
var eachCacheNameDetail = (fn) => {
|
|
152
|
+
for (const key of Object.keys(_cacheNameDetails)) {
|
|
153
|
+
fn(key);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
var cacheNames = {
|
|
157
|
+
updateDetails: (details) => {
|
|
158
|
+
eachCacheNameDetail((key) => {
|
|
159
|
+
if (typeof details[key] === "string") {
|
|
160
|
+
_cacheNameDetails[key] = details[key];
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
getGoogleAnalyticsName: (userCacheName) => {
|
|
165
|
+
return userCacheName || _createCacheName(_cacheNameDetails.googleAnalytics);
|
|
166
|
+
},
|
|
167
|
+
getPrecacheName: (userCacheName) => {
|
|
168
|
+
return userCacheName || _createCacheName(_cacheNameDetails.precache);
|
|
169
|
+
},
|
|
170
|
+
getPrefix: () => {
|
|
171
|
+
return _cacheNameDetails.prefix;
|
|
172
|
+
},
|
|
173
|
+
getRuntimeName: (userCacheName) => {
|
|
174
|
+
return userCacheName || _createCacheName(_cacheNameDetails.runtime);
|
|
175
|
+
},
|
|
176
|
+
getSuffix: () => {
|
|
177
|
+
return _cacheNameDetails.suffix;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// node_modules/workbox-core/_private/cacheMatchIgnoreParams.js
|
|
182
|
+
function stripParams(fullURL, ignoreParams) {
|
|
183
|
+
const strippedURL = new URL(fullURL);
|
|
184
|
+
for (const param of ignoreParams) {
|
|
185
|
+
strippedURL.searchParams.delete(param);
|
|
186
|
+
}
|
|
187
|
+
return strippedURL.href;
|
|
188
|
+
}
|
|
189
|
+
function cacheMatchIgnoreParams(cache, request, ignoreParams, matchOptions) {
|
|
190
|
+
return __async(this, null, function* () {
|
|
191
|
+
const strippedRequestURL = stripParams(request.url, ignoreParams);
|
|
192
|
+
if (request.url === strippedRequestURL) {
|
|
193
|
+
return cache.match(request, matchOptions);
|
|
194
|
+
}
|
|
195
|
+
const keysOptions = Object.assign(Object.assign({}, matchOptions), { ignoreSearch: true });
|
|
196
|
+
const cacheKeys = yield cache.keys(request, keysOptions);
|
|
197
|
+
for (const cacheKey of cacheKeys) {
|
|
198
|
+
const strippedCacheKeyURL = stripParams(cacheKey.url, ignoreParams);
|
|
199
|
+
if (strippedRequestURL === strippedCacheKeyURL) {
|
|
200
|
+
return cache.match(cacheKey, matchOptions);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return;
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// node_modules/workbox-core/_private/dontWaitFor.js
|
|
208
|
+
function dontWaitFor(promise) {
|
|
209
|
+
void promise.then(() => {
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// node_modules/workbox-core/_private/Deferred.js
|
|
214
|
+
var Deferred = class {
|
|
215
|
+
constructor() {
|
|
216
|
+
this.promise = new Promise((resolve, reject) => {
|
|
217
|
+
this.resolve = resolve;
|
|
218
|
+
this.reject = reject;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// node_modules/workbox-core/_private/executeQuotaErrorCallbacks.js
|
|
224
|
+
function executeQuotaErrorCallbacks() {
|
|
225
|
+
return __async(this, null, function* () {
|
|
226
|
+
if (false) {
|
|
227
|
+
logger.log(`About to run ${quotaErrorCallbacks.size} callbacks to clean up caches.`);
|
|
228
|
+
}
|
|
229
|
+
for (const callback of quotaErrorCallbacks) {
|
|
230
|
+
yield callback();
|
|
231
|
+
if (false) {
|
|
232
|
+
logger.log(callback, "is complete.");
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (false) {
|
|
236
|
+
logger.log("Finished running callbacks.");
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// node_modules/workbox-core/_private/getFriendlyURL.js
|
|
242
|
+
var getFriendlyURL = (url) => {
|
|
243
|
+
const urlObj = new URL(String(url), location.href);
|
|
244
|
+
return urlObj.href.replace(new RegExp(`^${location.origin}`), "");
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// node_modules/workbox-core/_private/timeout.js
|
|
248
|
+
function timeout(ms) {
|
|
249
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// node_modules/workbox-core/clientsClaim.js
|
|
253
|
+
function clientsClaim() {
|
|
254
|
+
self.addEventListener("activate", () => self.clients.claim());
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// node_modules/idb/build/esm/wrap-idb-value.js
|
|
258
|
+
var instanceOfAny = (object, constructors) => constructors.some((c) => object instanceof c);
|
|
259
|
+
var idbProxyableTypes;
|
|
260
|
+
var cursorAdvanceMethods;
|
|
261
|
+
function getIdbProxyableTypes() {
|
|
262
|
+
return idbProxyableTypes || (idbProxyableTypes = [
|
|
263
|
+
IDBDatabase,
|
|
264
|
+
IDBObjectStore,
|
|
265
|
+
IDBIndex,
|
|
266
|
+
IDBCursor,
|
|
267
|
+
IDBTransaction
|
|
268
|
+
]);
|
|
269
|
+
}
|
|
270
|
+
function getCursorAdvanceMethods() {
|
|
271
|
+
return cursorAdvanceMethods || (cursorAdvanceMethods = [
|
|
272
|
+
IDBCursor.prototype.advance,
|
|
273
|
+
IDBCursor.prototype.continue,
|
|
274
|
+
IDBCursor.prototype.continuePrimaryKey
|
|
275
|
+
]);
|
|
276
|
+
}
|
|
277
|
+
var cursorRequestMap = new WeakMap();
|
|
278
|
+
var transactionDoneMap = new WeakMap();
|
|
279
|
+
var transactionStoreNamesMap = new WeakMap();
|
|
280
|
+
var transformCache = new WeakMap();
|
|
281
|
+
var reverseTransformCache = new WeakMap();
|
|
282
|
+
function promisifyRequest(request) {
|
|
283
|
+
const promise = new Promise((resolve, reject) => {
|
|
284
|
+
const unlisten = () => {
|
|
285
|
+
request.removeEventListener("success", success);
|
|
286
|
+
request.removeEventListener("error", error);
|
|
287
|
+
};
|
|
288
|
+
const success = () => {
|
|
289
|
+
resolve(wrap(request.result));
|
|
290
|
+
unlisten();
|
|
291
|
+
};
|
|
292
|
+
const error = () => {
|
|
293
|
+
reject(request.error);
|
|
294
|
+
unlisten();
|
|
295
|
+
};
|
|
296
|
+
request.addEventListener("success", success);
|
|
297
|
+
request.addEventListener("error", error);
|
|
298
|
+
});
|
|
299
|
+
promise.then((value) => {
|
|
300
|
+
if (value instanceof IDBCursor) {
|
|
301
|
+
cursorRequestMap.set(value, request);
|
|
302
|
+
}
|
|
303
|
+
}).catch(() => {
|
|
304
|
+
});
|
|
305
|
+
reverseTransformCache.set(promise, request);
|
|
306
|
+
return promise;
|
|
307
|
+
}
|
|
308
|
+
function cacheDonePromiseForTransaction(tx) {
|
|
309
|
+
if (transactionDoneMap.has(tx))
|
|
310
|
+
return;
|
|
311
|
+
const done = new Promise((resolve, reject) => {
|
|
312
|
+
const unlisten = () => {
|
|
313
|
+
tx.removeEventListener("complete", complete);
|
|
314
|
+
tx.removeEventListener("error", error);
|
|
315
|
+
tx.removeEventListener("abort", error);
|
|
316
|
+
};
|
|
317
|
+
const complete = () => {
|
|
318
|
+
resolve();
|
|
319
|
+
unlisten();
|
|
320
|
+
};
|
|
321
|
+
const error = () => {
|
|
322
|
+
reject(tx.error || new DOMException("AbortError", "AbortError"));
|
|
323
|
+
unlisten();
|
|
324
|
+
};
|
|
325
|
+
tx.addEventListener("complete", complete);
|
|
326
|
+
tx.addEventListener("error", error);
|
|
327
|
+
tx.addEventListener("abort", error);
|
|
328
|
+
});
|
|
329
|
+
transactionDoneMap.set(tx, done);
|
|
330
|
+
}
|
|
331
|
+
var idbProxyTraps = {
|
|
332
|
+
get(target, prop, receiver) {
|
|
333
|
+
if (target instanceof IDBTransaction) {
|
|
334
|
+
if (prop === "done")
|
|
335
|
+
return transactionDoneMap.get(target);
|
|
336
|
+
if (prop === "objectStoreNames") {
|
|
337
|
+
return target.objectStoreNames || transactionStoreNamesMap.get(target);
|
|
338
|
+
}
|
|
339
|
+
if (prop === "store") {
|
|
340
|
+
return receiver.objectStoreNames[1] ? void 0 : receiver.objectStore(receiver.objectStoreNames[0]);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return wrap(target[prop]);
|
|
344
|
+
},
|
|
345
|
+
set(target, prop, value) {
|
|
346
|
+
target[prop] = value;
|
|
347
|
+
return true;
|
|
348
|
+
},
|
|
349
|
+
has(target, prop) {
|
|
350
|
+
if (target instanceof IDBTransaction && (prop === "done" || prop === "store")) {
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
353
|
+
return prop in target;
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
function replaceTraps(callback) {
|
|
357
|
+
idbProxyTraps = callback(idbProxyTraps);
|
|
358
|
+
}
|
|
359
|
+
function wrapFunction(func) {
|
|
360
|
+
if (func === IDBDatabase.prototype.transaction && !("objectStoreNames" in IDBTransaction.prototype)) {
|
|
361
|
+
return function(storeNames, ...args) {
|
|
362
|
+
const tx = func.call(unwrap(this), storeNames, ...args);
|
|
363
|
+
transactionStoreNamesMap.set(tx, storeNames.sort ? storeNames.sort() : [storeNames]);
|
|
364
|
+
return wrap(tx);
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
if (getCursorAdvanceMethods().includes(func)) {
|
|
368
|
+
return function(...args) {
|
|
369
|
+
func.apply(unwrap(this), args);
|
|
370
|
+
return wrap(cursorRequestMap.get(this));
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
return function(...args) {
|
|
374
|
+
return wrap(func.apply(unwrap(this), args));
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
function transformCachableValue(value) {
|
|
378
|
+
if (typeof value === "function")
|
|
379
|
+
return wrapFunction(value);
|
|
380
|
+
if (value instanceof IDBTransaction)
|
|
381
|
+
cacheDonePromiseForTransaction(value);
|
|
382
|
+
if (instanceOfAny(value, getIdbProxyableTypes()))
|
|
383
|
+
return new Proxy(value, idbProxyTraps);
|
|
384
|
+
return value;
|
|
385
|
+
}
|
|
386
|
+
function wrap(value) {
|
|
387
|
+
if (value instanceof IDBRequest)
|
|
388
|
+
return promisifyRequest(value);
|
|
389
|
+
if (transformCache.has(value))
|
|
390
|
+
return transformCache.get(value);
|
|
391
|
+
const newValue = transformCachableValue(value);
|
|
392
|
+
if (newValue !== value) {
|
|
393
|
+
transformCache.set(value, newValue);
|
|
394
|
+
reverseTransformCache.set(newValue, value);
|
|
395
|
+
}
|
|
396
|
+
return newValue;
|
|
397
|
+
}
|
|
398
|
+
var unwrap = (value) => reverseTransformCache.get(value);
|
|
399
|
+
|
|
400
|
+
// node_modules/idb/build/esm/index.js
|
|
401
|
+
function openDB(name, version, { blocked, upgrade, blocking, terminated } = {}) {
|
|
402
|
+
const request = indexedDB.open(name, version);
|
|
403
|
+
const openPromise = wrap(request);
|
|
404
|
+
if (upgrade) {
|
|
405
|
+
request.addEventListener("upgradeneeded", (event) => {
|
|
406
|
+
upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction));
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
if (blocked)
|
|
410
|
+
request.addEventListener("blocked", () => blocked());
|
|
411
|
+
openPromise.then((db) => {
|
|
412
|
+
if (terminated)
|
|
413
|
+
db.addEventListener("close", () => terminated());
|
|
414
|
+
if (blocking)
|
|
415
|
+
db.addEventListener("versionchange", () => blocking());
|
|
416
|
+
}).catch(() => {
|
|
417
|
+
});
|
|
418
|
+
return openPromise;
|
|
419
|
+
}
|
|
420
|
+
function deleteDB(name, { blocked } = {}) {
|
|
421
|
+
const request = indexedDB.deleteDatabase(name);
|
|
422
|
+
if (blocked)
|
|
423
|
+
request.addEventListener("blocked", () => blocked());
|
|
424
|
+
return wrap(request).then(() => void 0);
|
|
425
|
+
}
|
|
426
|
+
var readMethods = ["get", "getKey", "getAll", "getAllKeys", "count"];
|
|
427
|
+
var writeMethods = ["put", "add", "delete", "clear"];
|
|
428
|
+
var cachedMethods = new Map();
|
|
429
|
+
function getMethod(target, prop) {
|
|
430
|
+
if (!(target instanceof IDBDatabase && !(prop in target) && typeof prop === "string")) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
if (cachedMethods.get(prop))
|
|
434
|
+
return cachedMethods.get(prop);
|
|
435
|
+
const targetFuncName = prop.replace(/FromIndex$/, "");
|
|
436
|
+
const useIndex = prop !== targetFuncName;
|
|
437
|
+
const isWrite = writeMethods.includes(targetFuncName);
|
|
438
|
+
if (!(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) || !(isWrite || readMethods.includes(targetFuncName))) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
const method = function(storeName, ...args) {
|
|
442
|
+
return __async(this, null, function* () {
|
|
443
|
+
const tx = this.transaction(storeName, isWrite ? "readwrite" : "readonly");
|
|
444
|
+
let target2 = tx.store;
|
|
445
|
+
if (useIndex)
|
|
446
|
+
target2 = target2.index(args.shift());
|
|
447
|
+
return (yield Promise.all([
|
|
448
|
+
target2[targetFuncName](...args),
|
|
449
|
+
isWrite && tx.done
|
|
450
|
+
]))[0];
|
|
451
|
+
});
|
|
452
|
+
};
|
|
453
|
+
cachedMethods.set(prop, method);
|
|
454
|
+
return method;
|
|
455
|
+
}
|
|
456
|
+
replaceTraps((oldTraps) => __spreadProps(__spreadValues({}, oldTraps), {
|
|
457
|
+
get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
|
|
458
|
+
has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop)
|
|
459
|
+
}));
|
|
460
|
+
|
|
461
|
+
// node_modules/workbox-expiration/_version.js
|
|
462
|
+
"use strict";
|
|
463
|
+
try {
|
|
464
|
+
self["workbox:expiration:6.2.4"] && _();
|
|
465
|
+
} catch (e) {
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// node_modules/workbox-expiration/models/CacheTimestampsModel.js
|
|
469
|
+
var DB_NAME = "workbox-expiration";
|
|
470
|
+
var CACHE_OBJECT_STORE = "cache-entries";
|
|
471
|
+
var normalizeURL = (unNormalizedUrl) => {
|
|
472
|
+
const url = new URL(unNormalizedUrl, location.href);
|
|
473
|
+
url.hash = "";
|
|
474
|
+
return url.href;
|
|
475
|
+
};
|
|
476
|
+
var CacheTimestampsModel = class {
|
|
477
|
+
constructor(cacheName) {
|
|
478
|
+
this._db = null;
|
|
479
|
+
this._cacheName = cacheName;
|
|
480
|
+
}
|
|
481
|
+
_upgradeDb(db) {
|
|
482
|
+
const objStore = db.createObjectStore(CACHE_OBJECT_STORE, { keyPath: "id" });
|
|
483
|
+
objStore.createIndex("cacheName", "cacheName", { unique: false });
|
|
484
|
+
objStore.createIndex("timestamp", "timestamp", { unique: false });
|
|
485
|
+
}
|
|
486
|
+
_upgradeDbAndDeleteOldDbs(db) {
|
|
487
|
+
this._upgradeDb(db);
|
|
488
|
+
if (this._cacheName) {
|
|
489
|
+
void deleteDB(this._cacheName);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
setTimestamp(url, timestamp) {
|
|
493
|
+
return __async(this, null, function* () {
|
|
494
|
+
url = normalizeURL(url);
|
|
495
|
+
const entry = {
|
|
496
|
+
url,
|
|
497
|
+
timestamp,
|
|
498
|
+
cacheName: this._cacheName,
|
|
499
|
+
id: this._getId(url)
|
|
500
|
+
};
|
|
501
|
+
const db = yield this.getDb();
|
|
502
|
+
const tx = db.transaction(CACHE_OBJECT_STORE, "readwrite", { durability: "relaxed" });
|
|
503
|
+
yield tx.store.put(entry);
|
|
504
|
+
yield tx.done;
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
getTimestamp(url) {
|
|
508
|
+
return __async(this, null, function* () {
|
|
509
|
+
const db = yield this.getDb();
|
|
510
|
+
const entry = yield db.get(CACHE_OBJECT_STORE, this._getId(url));
|
|
511
|
+
return entry === null || entry === void 0 ? void 0 : entry.timestamp;
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
expireEntries(minTimestamp, maxCount) {
|
|
515
|
+
return __async(this, null, function* () {
|
|
516
|
+
const db = yield this.getDb();
|
|
517
|
+
let cursor = yield db.transaction(CACHE_OBJECT_STORE).store.index("timestamp").openCursor(null, "prev");
|
|
518
|
+
const entriesToDelete = [];
|
|
519
|
+
let entriesNotDeletedCount = 0;
|
|
520
|
+
while (cursor) {
|
|
521
|
+
const result = cursor.value;
|
|
522
|
+
if (result.cacheName === this._cacheName) {
|
|
523
|
+
if (minTimestamp && result.timestamp < minTimestamp || maxCount && entriesNotDeletedCount >= maxCount) {
|
|
524
|
+
entriesToDelete.push(cursor.value);
|
|
525
|
+
} else {
|
|
526
|
+
entriesNotDeletedCount++;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
cursor = yield cursor.continue();
|
|
530
|
+
}
|
|
531
|
+
const urlsDeleted = [];
|
|
532
|
+
for (const entry of entriesToDelete) {
|
|
533
|
+
yield db.delete(CACHE_OBJECT_STORE, entry.id);
|
|
534
|
+
urlsDeleted.push(entry.url);
|
|
535
|
+
}
|
|
536
|
+
return urlsDeleted;
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
_getId(url) {
|
|
540
|
+
return this._cacheName + "|" + normalizeURL(url);
|
|
541
|
+
}
|
|
542
|
+
getDb() {
|
|
543
|
+
return __async(this, null, function* () {
|
|
544
|
+
if (!this._db) {
|
|
545
|
+
this._db = yield openDB(DB_NAME, 1, {
|
|
546
|
+
upgrade: this._upgradeDbAndDeleteOldDbs.bind(this)
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
return this._db;
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
// node_modules/workbox-expiration/CacheExpiration.js
|
|
555
|
+
var CacheExpiration = class {
|
|
556
|
+
constructor(cacheName, config = {}) {
|
|
557
|
+
this._isRunning = false;
|
|
558
|
+
this._rerunRequested = false;
|
|
559
|
+
if (false) {
|
|
560
|
+
finalAssertExports.isType(cacheName, "string", {
|
|
561
|
+
moduleName: "workbox-expiration",
|
|
562
|
+
className: "CacheExpiration",
|
|
563
|
+
funcName: "constructor",
|
|
564
|
+
paramName: "cacheName"
|
|
565
|
+
});
|
|
566
|
+
if (!(config.maxEntries || config.maxAgeSeconds)) {
|
|
567
|
+
throw new WorkboxError("max-entries-or-age-required", {
|
|
568
|
+
moduleName: "workbox-expiration",
|
|
569
|
+
className: "CacheExpiration",
|
|
570
|
+
funcName: "constructor"
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
if (config.maxEntries) {
|
|
574
|
+
finalAssertExports.isType(config.maxEntries, "number", {
|
|
575
|
+
moduleName: "workbox-expiration",
|
|
576
|
+
className: "CacheExpiration",
|
|
577
|
+
funcName: "constructor",
|
|
578
|
+
paramName: "config.maxEntries"
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
if (config.maxAgeSeconds) {
|
|
582
|
+
finalAssertExports.isType(config.maxAgeSeconds, "number", {
|
|
583
|
+
moduleName: "workbox-expiration",
|
|
584
|
+
className: "CacheExpiration",
|
|
585
|
+
funcName: "constructor",
|
|
586
|
+
paramName: "config.maxAgeSeconds"
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
this._maxEntries = config.maxEntries;
|
|
591
|
+
this._maxAgeSeconds = config.maxAgeSeconds;
|
|
592
|
+
this._matchOptions = config.matchOptions;
|
|
593
|
+
this._cacheName = cacheName;
|
|
594
|
+
this._timestampModel = new CacheTimestampsModel(cacheName);
|
|
595
|
+
}
|
|
596
|
+
expireEntries() {
|
|
597
|
+
return __async(this, null, function* () {
|
|
598
|
+
if (this._isRunning) {
|
|
599
|
+
this._rerunRequested = true;
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
this._isRunning = true;
|
|
603
|
+
const minTimestamp = this._maxAgeSeconds ? Date.now() - this._maxAgeSeconds * 1e3 : 0;
|
|
604
|
+
const urlsExpired = yield this._timestampModel.expireEntries(minTimestamp, this._maxEntries);
|
|
605
|
+
const cache = yield self.caches.open(this._cacheName);
|
|
606
|
+
for (const url of urlsExpired) {
|
|
607
|
+
yield cache.delete(url, this._matchOptions);
|
|
608
|
+
}
|
|
609
|
+
if (false) {
|
|
610
|
+
if (urlsExpired.length > 0) {
|
|
611
|
+
logger.groupCollapsed(`Expired ${urlsExpired.length} ${urlsExpired.length === 1 ? "entry" : "entries"} and removed ${urlsExpired.length === 1 ? "it" : "them"} from the '${this._cacheName}' cache.`);
|
|
612
|
+
logger.log(`Expired the following ${urlsExpired.length === 1 ? "URL" : "URLs"}:`);
|
|
613
|
+
urlsExpired.forEach((url) => logger.log(` ${url}`));
|
|
614
|
+
logger.groupEnd();
|
|
615
|
+
} else {
|
|
616
|
+
logger.debug(`Cache expiration ran and found no entries to remove.`);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
this._isRunning = false;
|
|
620
|
+
if (this._rerunRequested) {
|
|
621
|
+
this._rerunRequested = false;
|
|
622
|
+
dontWaitFor(this.expireEntries());
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
updateTimestamp(url) {
|
|
627
|
+
return __async(this, null, function* () {
|
|
628
|
+
if (false) {
|
|
629
|
+
finalAssertExports.isType(url, "string", {
|
|
630
|
+
moduleName: "workbox-expiration",
|
|
631
|
+
className: "CacheExpiration",
|
|
632
|
+
funcName: "updateTimestamp",
|
|
633
|
+
paramName: "url"
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
yield this._timestampModel.setTimestamp(url, Date.now());
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
isURLExpired(url) {
|
|
640
|
+
return __async(this, null, function* () {
|
|
641
|
+
if (!this._maxAgeSeconds) {
|
|
642
|
+
if (false) {
|
|
643
|
+
throw new WorkboxError(`expired-test-without-max-age`, {
|
|
644
|
+
methodName: "isURLExpired",
|
|
645
|
+
paramName: "maxAgeSeconds"
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
return false;
|
|
649
|
+
} else {
|
|
650
|
+
const timestamp = yield this._timestampModel.getTimestamp(url);
|
|
651
|
+
const expireOlderThan = Date.now() - this._maxAgeSeconds * 1e3;
|
|
652
|
+
return timestamp !== void 0 ? timestamp < expireOlderThan : true;
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
delete() {
|
|
657
|
+
return __async(this, null, function* () {
|
|
658
|
+
this._rerunRequested = false;
|
|
659
|
+
yield this._timestampModel.expireEntries(Infinity);
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
|
|
664
|
+
// node_modules/workbox-expiration/ExpirationPlugin.js
|
|
665
|
+
var ExpirationPlugin = class {
|
|
666
|
+
constructor(config = {}) {
|
|
667
|
+
this.cachedResponseWillBeUsed = (_0) => __async(this, [_0], function* ({ event, request, cacheName, cachedResponse }) {
|
|
668
|
+
if (!cachedResponse) {
|
|
669
|
+
return null;
|
|
670
|
+
}
|
|
671
|
+
const isFresh = this._isResponseDateFresh(cachedResponse);
|
|
672
|
+
const cacheExpiration = this._getCacheExpiration(cacheName);
|
|
673
|
+
dontWaitFor(cacheExpiration.expireEntries());
|
|
674
|
+
const updateTimestampDone = cacheExpiration.updateTimestamp(request.url);
|
|
675
|
+
if (event) {
|
|
676
|
+
try {
|
|
677
|
+
event.waitUntil(updateTimestampDone);
|
|
678
|
+
} catch (error) {
|
|
679
|
+
if (false) {
|
|
680
|
+
if ("request" in event) {
|
|
681
|
+
logger.warn(`Unable to ensure service worker stays alive when updating cache entry for '${getFriendlyURL(event.request.url)}'.`);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
return isFresh ? cachedResponse : null;
|
|
687
|
+
});
|
|
688
|
+
this.cacheDidUpdate = (_0) => __async(this, [_0], function* ({ cacheName, request }) {
|
|
689
|
+
if (false) {
|
|
690
|
+
finalAssertExports.isType(cacheName, "string", {
|
|
691
|
+
moduleName: "workbox-expiration",
|
|
692
|
+
className: "Plugin",
|
|
693
|
+
funcName: "cacheDidUpdate",
|
|
694
|
+
paramName: "cacheName"
|
|
695
|
+
});
|
|
696
|
+
finalAssertExports.isInstance(request, Request, {
|
|
697
|
+
moduleName: "workbox-expiration",
|
|
698
|
+
className: "Plugin",
|
|
699
|
+
funcName: "cacheDidUpdate",
|
|
700
|
+
paramName: "request"
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
const cacheExpiration = this._getCacheExpiration(cacheName);
|
|
704
|
+
yield cacheExpiration.updateTimestamp(request.url);
|
|
705
|
+
yield cacheExpiration.expireEntries();
|
|
706
|
+
});
|
|
707
|
+
if (false) {
|
|
708
|
+
if (!(config.maxEntries || config.maxAgeSeconds)) {
|
|
709
|
+
throw new WorkboxError("max-entries-or-age-required", {
|
|
710
|
+
moduleName: "workbox-expiration",
|
|
711
|
+
className: "Plugin",
|
|
712
|
+
funcName: "constructor"
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
if (config.maxEntries) {
|
|
716
|
+
finalAssertExports.isType(config.maxEntries, "number", {
|
|
717
|
+
moduleName: "workbox-expiration",
|
|
718
|
+
className: "Plugin",
|
|
719
|
+
funcName: "constructor",
|
|
720
|
+
paramName: "config.maxEntries"
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
if (config.maxAgeSeconds) {
|
|
724
|
+
finalAssertExports.isType(config.maxAgeSeconds, "number", {
|
|
725
|
+
moduleName: "workbox-expiration",
|
|
726
|
+
className: "Plugin",
|
|
727
|
+
funcName: "constructor",
|
|
728
|
+
paramName: "config.maxAgeSeconds"
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
this._config = config;
|
|
733
|
+
this._maxAgeSeconds = config.maxAgeSeconds;
|
|
734
|
+
this._cacheExpirations = new Map();
|
|
735
|
+
if (config.purgeOnQuotaError) {
|
|
736
|
+
registerQuotaErrorCallback(() => this.deleteCacheAndMetadata());
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
_getCacheExpiration(cacheName) {
|
|
740
|
+
if (cacheName === cacheNames.getRuntimeName()) {
|
|
741
|
+
throw new WorkboxError("expire-custom-caches-only");
|
|
742
|
+
}
|
|
743
|
+
let cacheExpiration = this._cacheExpirations.get(cacheName);
|
|
744
|
+
if (!cacheExpiration) {
|
|
745
|
+
cacheExpiration = new CacheExpiration(cacheName, this._config);
|
|
746
|
+
this._cacheExpirations.set(cacheName, cacheExpiration);
|
|
747
|
+
}
|
|
748
|
+
return cacheExpiration;
|
|
749
|
+
}
|
|
750
|
+
_isResponseDateFresh(cachedResponse) {
|
|
751
|
+
if (!this._maxAgeSeconds) {
|
|
752
|
+
return true;
|
|
753
|
+
}
|
|
754
|
+
const dateHeaderTimestamp = this._getDateHeaderTimestamp(cachedResponse);
|
|
755
|
+
if (dateHeaderTimestamp === null) {
|
|
756
|
+
return true;
|
|
757
|
+
}
|
|
758
|
+
const now = Date.now();
|
|
759
|
+
return dateHeaderTimestamp >= now - this._maxAgeSeconds * 1e3;
|
|
760
|
+
}
|
|
761
|
+
_getDateHeaderTimestamp(cachedResponse) {
|
|
762
|
+
if (!cachedResponse.headers.has("date")) {
|
|
763
|
+
return null;
|
|
764
|
+
}
|
|
765
|
+
const dateHeader = cachedResponse.headers.get("date");
|
|
766
|
+
const parsedDate = new Date(dateHeader);
|
|
767
|
+
const headerTime = parsedDate.getTime();
|
|
768
|
+
if (isNaN(headerTime)) {
|
|
769
|
+
return null;
|
|
770
|
+
}
|
|
771
|
+
return headerTime;
|
|
772
|
+
}
|
|
773
|
+
deleteCacheAndMetadata() {
|
|
774
|
+
return __async(this, null, function* () {
|
|
775
|
+
for (const [cacheName, cacheExpiration] of this._cacheExpirations) {
|
|
776
|
+
yield self.caches.delete(cacheName);
|
|
777
|
+
yield cacheExpiration.delete();
|
|
778
|
+
}
|
|
779
|
+
this._cacheExpirations = new Map();
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
// node_modules/workbox-strategies/_version.js
|
|
785
|
+
"use strict";
|
|
786
|
+
try {
|
|
787
|
+
self["workbox:strategies:6.2.4"] && _();
|
|
788
|
+
} catch (e) {
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
// node_modules/workbox-strategies/StrategyHandler.js
|
|
792
|
+
function toRequest(input) {
|
|
793
|
+
return typeof input === "string" ? new Request(input) : input;
|
|
794
|
+
}
|
|
795
|
+
var StrategyHandler = class {
|
|
796
|
+
constructor(strategy, options) {
|
|
797
|
+
this._cacheKeys = {};
|
|
798
|
+
if (false) {
|
|
799
|
+
finalAssertExports.isInstance(options.event, ExtendableEvent, {
|
|
800
|
+
moduleName: "workbox-strategies",
|
|
801
|
+
className: "StrategyHandler",
|
|
802
|
+
funcName: "constructor",
|
|
803
|
+
paramName: "options.event"
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
Object.assign(this, options);
|
|
807
|
+
this.event = options.event;
|
|
808
|
+
this._strategy = strategy;
|
|
809
|
+
this._handlerDeferred = new Deferred();
|
|
810
|
+
this._extendLifetimePromises = [];
|
|
811
|
+
this._plugins = [...strategy.plugins];
|
|
812
|
+
this._pluginStateMap = new Map();
|
|
813
|
+
for (const plugin of this._plugins) {
|
|
814
|
+
this._pluginStateMap.set(plugin, {});
|
|
815
|
+
}
|
|
816
|
+
this.event.waitUntil(this._handlerDeferred.promise);
|
|
817
|
+
}
|
|
818
|
+
fetch(input) {
|
|
819
|
+
return __async(this, null, function* () {
|
|
820
|
+
const { event } = this;
|
|
821
|
+
let request = toRequest(input);
|
|
822
|
+
if (request.mode === "navigate" && event instanceof FetchEvent && event.preloadResponse) {
|
|
823
|
+
const possiblePreloadResponse = yield event.preloadResponse;
|
|
824
|
+
if (possiblePreloadResponse) {
|
|
825
|
+
if (false) {
|
|
826
|
+
logger.log(`Using a preloaded navigation response for '${getFriendlyURL(request.url)}'`);
|
|
827
|
+
}
|
|
828
|
+
return possiblePreloadResponse;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
const originalRequest = this.hasCallback("fetchDidFail") ? request.clone() : null;
|
|
832
|
+
try {
|
|
833
|
+
for (const cb of this.iterateCallbacks("requestWillFetch")) {
|
|
834
|
+
request = yield cb({ request: request.clone(), event });
|
|
835
|
+
}
|
|
836
|
+
} catch (err) {
|
|
837
|
+
if (err instanceof Error) {
|
|
838
|
+
throw new WorkboxError("plugin-error-request-will-fetch", { thrownErrorMessage: err.message });
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
const pluginFilteredRequest = request.clone();
|
|
842
|
+
try {
|
|
843
|
+
let fetchResponse;
|
|
844
|
+
fetchResponse = yield fetch(request, request.mode === "navigate" ? void 0 : this._strategy.fetchOptions);
|
|
845
|
+
if (false) {
|
|
846
|
+
logger.debug(`Network request for '${getFriendlyURL(request.url)}' returned a response with status '${fetchResponse.status}'.`);
|
|
847
|
+
}
|
|
848
|
+
for (const callback of this.iterateCallbacks("fetchDidSucceed")) {
|
|
849
|
+
fetchResponse = yield callback({
|
|
850
|
+
event,
|
|
851
|
+
request: pluginFilteredRequest,
|
|
852
|
+
response: fetchResponse
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
return fetchResponse;
|
|
856
|
+
} catch (error) {
|
|
857
|
+
if (false) {
|
|
858
|
+
logger.log(`Network request for '${getFriendlyURL(request.url)}' threw an error.`, error);
|
|
859
|
+
}
|
|
860
|
+
if (originalRequest) {
|
|
861
|
+
yield this.runCallbacks("fetchDidFail", {
|
|
862
|
+
error,
|
|
863
|
+
event,
|
|
864
|
+
originalRequest: originalRequest.clone(),
|
|
865
|
+
request: pluginFilteredRequest.clone()
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
throw error;
|
|
869
|
+
}
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
fetchAndCachePut(input) {
|
|
873
|
+
return __async(this, null, function* () {
|
|
874
|
+
const response = yield this.fetch(input);
|
|
875
|
+
const responseClone = response.clone();
|
|
876
|
+
void this.waitUntil(this.cachePut(input, responseClone));
|
|
877
|
+
return response;
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
cacheMatch(key) {
|
|
881
|
+
return __async(this, null, function* () {
|
|
882
|
+
const request = toRequest(key);
|
|
883
|
+
let cachedResponse;
|
|
884
|
+
const { cacheName, matchOptions } = this._strategy;
|
|
885
|
+
const effectiveRequest = yield this.getCacheKey(request, "read");
|
|
886
|
+
const multiMatchOptions = Object.assign(Object.assign({}, matchOptions), { cacheName });
|
|
887
|
+
cachedResponse = yield caches.match(effectiveRequest, multiMatchOptions);
|
|
888
|
+
if (false) {
|
|
889
|
+
if (cachedResponse) {
|
|
890
|
+
logger.debug(`Found a cached response in '${cacheName}'.`);
|
|
891
|
+
} else {
|
|
892
|
+
logger.debug(`No cached response found in '${cacheName}'.`);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
for (const callback of this.iterateCallbacks("cachedResponseWillBeUsed")) {
|
|
896
|
+
cachedResponse = (yield callback({
|
|
897
|
+
cacheName,
|
|
898
|
+
matchOptions,
|
|
899
|
+
cachedResponse,
|
|
900
|
+
request: effectiveRequest,
|
|
901
|
+
event: this.event
|
|
902
|
+
})) || void 0;
|
|
903
|
+
}
|
|
904
|
+
return cachedResponse;
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
cachePut(key, response) {
|
|
908
|
+
return __async(this, null, function* () {
|
|
909
|
+
const request = toRequest(key);
|
|
910
|
+
yield timeout(0);
|
|
911
|
+
const effectiveRequest = yield this.getCacheKey(request, "write");
|
|
912
|
+
if (false) {
|
|
913
|
+
if (effectiveRequest.method && effectiveRequest.method !== "GET") {
|
|
914
|
+
throw new WorkboxError("attempt-to-cache-non-get-request", {
|
|
915
|
+
url: getFriendlyURL(effectiveRequest.url),
|
|
916
|
+
method: effectiveRequest.method
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
const vary = response.headers.get("Vary");
|
|
920
|
+
if (vary) {
|
|
921
|
+
logger.debug(`The response for ${getFriendlyURL(effectiveRequest.url)} has a 'Vary: ${vary}' header. Consider setting the {ignoreVary: true} option on your strategy to ensure cache matching and deletion works as expected.`);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
if (!response) {
|
|
925
|
+
if (false) {
|
|
926
|
+
logger.error(`Cannot cache non-existent response for '${getFriendlyURL(effectiveRequest.url)}'.`);
|
|
927
|
+
}
|
|
928
|
+
throw new WorkboxError("cache-put-with-no-response", {
|
|
929
|
+
url: getFriendlyURL(effectiveRequest.url)
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
const responseToCache = yield this._ensureResponseSafeToCache(response);
|
|
933
|
+
if (!responseToCache) {
|
|
934
|
+
if (false) {
|
|
935
|
+
logger.debug(`Response '${getFriendlyURL(effectiveRequest.url)}' will not be cached.`, responseToCache);
|
|
936
|
+
}
|
|
937
|
+
return false;
|
|
938
|
+
}
|
|
939
|
+
const { cacheName, matchOptions } = this._strategy;
|
|
940
|
+
const cache = yield self.caches.open(cacheName);
|
|
941
|
+
const hasCacheUpdateCallback = this.hasCallback("cacheDidUpdate");
|
|
942
|
+
const oldResponse = hasCacheUpdateCallback ? yield cacheMatchIgnoreParams(cache, effectiveRequest.clone(), ["__WB_REVISION__"], matchOptions) : null;
|
|
943
|
+
if (false) {
|
|
944
|
+
logger.debug(`Updating the '${cacheName}' cache with a new Response for ${getFriendlyURL(effectiveRequest.url)}.`);
|
|
945
|
+
}
|
|
946
|
+
try {
|
|
947
|
+
yield cache.put(effectiveRequest, hasCacheUpdateCallback ? responseToCache.clone() : responseToCache);
|
|
948
|
+
} catch (error) {
|
|
949
|
+
if (error instanceof Error) {
|
|
950
|
+
if (error.name === "QuotaExceededError") {
|
|
951
|
+
yield executeQuotaErrorCallbacks();
|
|
952
|
+
}
|
|
953
|
+
throw error;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
for (const callback of this.iterateCallbacks("cacheDidUpdate")) {
|
|
957
|
+
yield callback({
|
|
958
|
+
cacheName,
|
|
959
|
+
oldResponse,
|
|
960
|
+
newResponse: responseToCache.clone(),
|
|
961
|
+
request: effectiveRequest,
|
|
962
|
+
event: this.event
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
return true;
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
getCacheKey(request, mode) {
|
|
969
|
+
return __async(this, null, function* () {
|
|
970
|
+
if (!this._cacheKeys[mode]) {
|
|
971
|
+
let effectiveRequest = request;
|
|
972
|
+
for (const callback of this.iterateCallbacks("cacheKeyWillBeUsed")) {
|
|
973
|
+
effectiveRequest = toRequest(yield callback({
|
|
974
|
+
mode,
|
|
975
|
+
request: effectiveRequest,
|
|
976
|
+
event: this.event,
|
|
977
|
+
params: this.params
|
|
978
|
+
}));
|
|
979
|
+
}
|
|
980
|
+
this._cacheKeys[mode] = effectiveRequest;
|
|
981
|
+
}
|
|
982
|
+
return this._cacheKeys[mode];
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
hasCallback(name) {
|
|
986
|
+
for (const plugin of this._strategy.plugins) {
|
|
987
|
+
if (name in plugin) {
|
|
988
|
+
return true;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
return false;
|
|
992
|
+
}
|
|
993
|
+
runCallbacks(name, param) {
|
|
994
|
+
return __async(this, null, function* () {
|
|
995
|
+
for (const callback of this.iterateCallbacks(name)) {
|
|
996
|
+
yield callback(param);
|
|
997
|
+
}
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
*iterateCallbacks(name) {
|
|
1001
|
+
for (const plugin of this._strategy.plugins) {
|
|
1002
|
+
if (typeof plugin[name] === "function") {
|
|
1003
|
+
const state = this._pluginStateMap.get(plugin);
|
|
1004
|
+
const statefulCallback = (param) => {
|
|
1005
|
+
const statefulParam = Object.assign(Object.assign({}, param), { state });
|
|
1006
|
+
return plugin[name](statefulParam);
|
|
1007
|
+
};
|
|
1008
|
+
yield statefulCallback;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
waitUntil(promise) {
|
|
1013
|
+
this._extendLifetimePromises.push(promise);
|
|
1014
|
+
return promise;
|
|
1015
|
+
}
|
|
1016
|
+
doneWaiting() {
|
|
1017
|
+
return __async(this, null, function* () {
|
|
1018
|
+
let promise;
|
|
1019
|
+
while (promise = this._extendLifetimePromises.shift()) {
|
|
1020
|
+
yield promise;
|
|
1021
|
+
}
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
destroy() {
|
|
1025
|
+
this._handlerDeferred.resolve(null);
|
|
1026
|
+
}
|
|
1027
|
+
_ensureResponseSafeToCache(response) {
|
|
1028
|
+
return __async(this, null, function* () {
|
|
1029
|
+
let responseToCache = response;
|
|
1030
|
+
let pluginsUsed = false;
|
|
1031
|
+
for (const callback of this.iterateCallbacks("cacheWillUpdate")) {
|
|
1032
|
+
responseToCache = (yield callback({
|
|
1033
|
+
request: this.request,
|
|
1034
|
+
response: responseToCache,
|
|
1035
|
+
event: this.event
|
|
1036
|
+
})) || void 0;
|
|
1037
|
+
pluginsUsed = true;
|
|
1038
|
+
if (!responseToCache) {
|
|
1039
|
+
break;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
if (!pluginsUsed) {
|
|
1043
|
+
if (responseToCache && responseToCache.status !== 200) {
|
|
1044
|
+
responseToCache = void 0;
|
|
1045
|
+
}
|
|
1046
|
+
if (false) {
|
|
1047
|
+
if (responseToCache) {
|
|
1048
|
+
if (responseToCache.status !== 200) {
|
|
1049
|
+
if (responseToCache.status === 0) {
|
|
1050
|
+
logger.warn(`The response for '${this.request.url}' is an opaque response. The caching strategy that you're using will not cache opaque responses by default.`);
|
|
1051
|
+
} else {
|
|
1052
|
+
logger.debug(`The response for '${this.request.url}' returned a status code of '${response.status}' and won't be cached as a result.`);
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
return responseToCache;
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
|
|
1063
|
+
// node_modules/workbox-strategies/Strategy.js
|
|
1064
|
+
var Strategy = class {
|
|
1065
|
+
constructor(options = {}) {
|
|
1066
|
+
this.cacheName = cacheNames.getRuntimeName(options.cacheName);
|
|
1067
|
+
this.plugins = options.plugins || [];
|
|
1068
|
+
this.fetchOptions = options.fetchOptions;
|
|
1069
|
+
this.matchOptions = options.matchOptions;
|
|
1070
|
+
}
|
|
1071
|
+
handle(options) {
|
|
1072
|
+
const [responseDone] = this.handleAll(options);
|
|
1073
|
+
return responseDone;
|
|
1074
|
+
}
|
|
1075
|
+
handleAll(options) {
|
|
1076
|
+
if (options instanceof FetchEvent) {
|
|
1077
|
+
options = {
|
|
1078
|
+
event: options,
|
|
1079
|
+
request: options.request
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
const event = options.event;
|
|
1083
|
+
const request = typeof options.request === "string" ? new Request(options.request) : options.request;
|
|
1084
|
+
const params = "params" in options ? options.params : void 0;
|
|
1085
|
+
const handler = new StrategyHandler(this, { event, request, params });
|
|
1086
|
+
const responseDone = this._getResponse(handler, request, event);
|
|
1087
|
+
const handlerDone = this._awaitComplete(responseDone, handler, request, event);
|
|
1088
|
+
return [responseDone, handlerDone];
|
|
1089
|
+
}
|
|
1090
|
+
_getResponse(handler, request, event) {
|
|
1091
|
+
return __async(this, null, function* () {
|
|
1092
|
+
yield handler.runCallbacks("handlerWillStart", { event, request });
|
|
1093
|
+
let response = void 0;
|
|
1094
|
+
try {
|
|
1095
|
+
response = yield this._handle(request, handler);
|
|
1096
|
+
if (!response || response.type === "error") {
|
|
1097
|
+
throw new WorkboxError("no-response", { url: request.url });
|
|
1098
|
+
}
|
|
1099
|
+
} catch (error) {
|
|
1100
|
+
if (error instanceof Error) {
|
|
1101
|
+
for (const callback of handler.iterateCallbacks("handlerDidError")) {
|
|
1102
|
+
response = yield callback({ error, event, request });
|
|
1103
|
+
if (response) {
|
|
1104
|
+
break;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
if (!response) {
|
|
1109
|
+
throw error;
|
|
1110
|
+
} else if (false) {
|
|
1111
|
+
logger.log(`While responding to '${getFriendlyURL(request.url)}', an ${error instanceof Error ? error.toString() : ""} error occurred. Using a fallback response provided by a handlerDidError plugin.`);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
for (const callback of handler.iterateCallbacks("handlerWillRespond")) {
|
|
1115
|
+
response = yield callback({ event, request, response });
|
|
1116
|
+
}
|
|
1117
|
+
return response;
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
_awaitComplete(responseDone, handler, request, event) {
|
|
1121
|
+
return __async(this, null, function* () {
|
|
1122
|
+
let response;
|
|
1123
|
+
let error;
|
|
1124
|
+
try {
|
|
1125
|
+
response = yield responseDone;
|
|
1126
|
+
} catch (error2) {
|
|
1127
|
+
}
|
|
1128
|
+
try {
|
|
1129
|
+
yield handler.runCallbacks("handlerDidRespond", {
|
|
1130
|
+
event,
|
|
1131
|
+
request,
|
|
1132
|
+
response
|
|
1133
|
+
});
|
|
1134
|
+
yield handler.doneWaiting();
|
|
1135
|
+
} catch (waitUntilError) {
|
|
1136
|
+
if (waitUntilError instanceof Error) {
|
|
1137
|
+
error = waitUntilError;
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
yield handler.runCallbacks("handlerDidComplete", {
|
|
1141
|
+
event,
|
|
1142
|
+
request,
|
|
1143
|
+
response,
|
|
1144
|
+
error
|
|
1145
|
+
});
|
|
1146
|
+
handler.destroy();
|
|
1147
|
+
if (error) {
|
|
1148
|
+
throw error;
|
|
1149
|
+
}
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
|
|
1154
|
+
// node_modules/workbox-strategies/CacheFirst.js
|
|
1155
|
+
var CacheFirst = class extends Strategy {
|
|
1156
|
+
_handle(request, handler) {
|
|
1157
|
+
return __async(this, null, function* () {
|
|
1158
|
+
const logs = [];
|
|
1159
|
+
if (false) {
|
|
1160
|
+
finalAssertExports.isInstance(request, Request, {
|
|
1161
|
+
moduleName: "workbox-strategies",
|
|
1162
|
+
className: this.constructor.name,
|
|
1163
|
+
funcName: "makeRequest",
|
|
1164
|
+
paramName: "request"
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
let response = yield handler.cacheMatch(request);
|
|
1168
|
+
let error = void 0;
|
|
1169
|
+
if (!response) {
|
|
1170
|
+
if (false) {
|
|
1171
|
+
logs.push(`No response found in the '${this.cacheName}' cache. Will respond with a network request.`);
|
|
1172
|
+
}
|
|
1173
|
+
try {
|
|
1174
|
+
response = yield handler.fetchAndCachePut(request);
|
|
1175
|
+
} catch (err) {
|
|
1176
|
+
if (err instanceof Error) {
|
|
1177
|
+
error = err;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
if (false) {
|
|
1181
|
+
if (response) {
|
|
1182
|
+
logs.push(`Got response from network.`);
|
|
1183
|
+
} else {
|
|
1184
|
+
logs.push(`Unable to get a response from the network.`);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
} else {
|
|
1188
|
+
if (false) {
|
|
1189
|
+
logs.push(`Found a cached response in the '${this.cacheName}' cache.`);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
if (false) {
|
|
1193
|
+
logger.groupCollapsed(messages2.strategyStart(this.constructor.name, request));
|
|
1194
|
+
for (const log2 of logs) {
|
|
1195
|
+
logger.log(log2);
|
|
1196
|
+
}
|
|
1197
|
+
messages2.printFinalResponse(response);
|
|
1198
|
+
logger.groupEnd();
|
|
1199
|
+
}
|
|
1200
|
+
if (!response) {
|
|
1201
|
+
throw new WorkboxError("no-response", { url: request.url, error });
|
|
1202
|
+
}
|
|
1203
|
+
return response;
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
|
|
1208
|
+
// src/constants.ts
|
|
1209
|
+
var IS_DEV = false;
|
|
1210
|
+
|
|
1211
|
+
// src/ServiceWorker/constants.ts
|
|
1212
|
+
var WEBPUB_CACHE_NAME = "webpub-cache";
|
|
1213
|
+
var CACHE_EXPIRATION_SECONDS = 7 * 24 * 60 * 60;
|
|
1214
|
+
|
|
1215
|
+
// src/ServiceWorker/sw.ts
|
|
1216
|
+
var VERSION = "v1";
|
|
1217
|
+
clientsClaim();
|
|
1218
|
+
function initWebReaderSW({
|
|
1219
|
+
cacheExpirationSeconds = CACHE_EXPIRATION_SECONDS
|
|
1220
|
+
} = {}) {
|
|
1221
|
+
log("INITIALIZING");
|
|
1222
|
+
self.addEventListener("install", (event) => {
|
|
1223
|
+
log("INSTALLING ");
|
|
1224
|
+
function installSW() {
|
|
1225
|
+
return __async(this, null, function* () {
|
|
1226
|
+
self.skipWaiting();
|
|
1227
|
+
log("INSTALLED");
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
event.waitUntil(installSW);
|
|
1231
|
+
});
|
|
1232
|
+
self.addEventListener("fetch", (event) => {
|
|
1233
|
+
if (event.request.method !== "GET") {
|
|
1234
|
+
return;
|
|
1235
|
+
}
|
|
1236
|
+
function matchOrFetch() {
|
|
1237
|
+
return __async(this, null, function* () {
|
|
1238
|
+
const pubCache = yield caches.open(WEBPUB_CACHE_NAME);
|
|
1239
|
+
const match = yield pubCache.match(event.request);
|
|
1240
|
+
if (match) {
|
|
1241
|
+
return new CacheFirst({
|
|
1242
|
+
cacheName: WEBPUB_CACHE_NAME,
|
|
1243
|
+
plugins: [
|
|
1244
|
+
new ExpirationPlugin({
|
|
1245
|
+
maxAgeSeconds: cacheExpirationSeconds
|
|
1246
|
+
})
|
|
1247
|
+
]
|
|
1248
|
+
}).handle(event);
|
|
1249
|
+
}
|
|
1250
|
+
return fetch(event.request);
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
event.respondWith(matchOrFetch());
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
function log(message) {
|
|
1257
|
+
if (IS_DEV)
|
|
1258
|
+
console.log(`SW (${VERSION}) -`, message);
|
|
1259
|
+
}
|
|
1260
|
+
export {
|
|
1261
|
+
initWebReaderSW as default
|
|
1262
|
+
};
|
|
1263
|
+
//# sourceMappingURL=sw.js.map
|