jekyll-pwa-workbox 0.0.7 → 0.0.8

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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-pwa-workbox.rb +1 -1
  3. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-background-sync.dev.js +818 -818
  4. data/lib/vendor/workbox-v5.1.1/workbox-background-sync.dev.js.map +1 -0
  5. data/lib/vendor/workbox-v5.1.1/workbox-background-sync.prod.js +2 -0
  6. data/lib/vendor/workbox-v5.1.1/workbox-background-sync.prod.js.map +1 -0
  7. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-broadcast-update.dev.js +288 -288
  8. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-broadcast-update.dev.js.map +1 -1
  9. data/lib/vendor/workbox-v5.1.1/workbox-broadcast-update.prod.js +2 -0
  10. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-broadcast-update.prod.js.map +1 -1
  11. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-cacheable-response.dev.js +191 -191
  12. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-cacheable-response.dev.js.map +1 -1
  13. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-cacheable-response.prod.js +2 -2
  14. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-cacheable-response.prod.js.map +1 -1
  15. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-core.dev.js +1880 -1882
  16. data/lib/vendor/workbox-v5.1.1/workbox-core.dev.js.map +1 -0
  17. data/lib/vendor/workbox-v5.1.1/workbox-core.prod.js +2 -0
  18. data/lib/vendor/workbox-v5.1.1/workbox-core.prod.js.map +1 -0
  19. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-expiration.dev.js +649 -651
  20. data/lib/vendor/workbox-v5.1.1/workbox-expiration.dev.js.map +1 -0
  21. data/lib/vendor/workbox-v5.1.1/workbox-expiration.prod.js +2 -0
  22. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-expiration.prod.js.map +1 -1
  23. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-navigation-preload.dev.js +102 -102
  24. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-navigation-preload.dev.js.map +1 -1
  25. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-navigation-preload.prod.js +2 -2
  26. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-navigation-preload.prod.js.map +1 -1
  27. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-offline-ga.dev.js +235 -235
  28. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-offline-ga.dev.js.map +1 -1
  29. data/lib/vendor/workbox-v5.1.1/workbox-offline-ga.prod.js +2 -0
  30. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-offline-ga.prod.js.map +1 -1
  31. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-precaching.dev.js +1222 -1222
  32. data/lib/vendor/workbox-v5.1.1/workbox-precaching.dev.js.map +1 -0
  33. data/lib/vendor/workbox-v5.1.1/workbox-precaching.prod.js +2 -0
  34. data/lib/vendor/workbox-v5.1.1/workbox-precaching.prod.js.map +1 -0
  35. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-range-requests.dev.js +262 -262
  36. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-range-requests.dev.js.map +1 -1
  37. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-range-requests.prod.js +2 -2
  38. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-range-requests.prod.js.map +1 -1
  39. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-routing.dev.js +923 -923
  40. data/lib/vendor/workbox-v5.1.1/workbox-routing.dev.js.map +1 -0
  41. data/lib/vendor/workbox-v5.1.1/workbox-routing.prod.js +2 -0
  42. data/lib/vendor/workbox-v5.1.1/workbox-routing.prod.js.map +1 -0
  43. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-strategies.dev.js +923 -923
  44. data/lib/vendor/workbox-v5.1.1/workbox-strategies.dev.js.map +1 -0
  45. data/lib/vendor/workbox-v5.1.1/workbox-strategies.prod.js +2 -0
  46. data/lib/vendor/workbox-v5.1.1/workbox-strategies.prod.js.map +1 -0
  47. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-streams.dev.js +318 -318
  48. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-streams.dev.js.map +1 -1
  49. data/lib/vendor/workbox-v5.1.1/workbox-streams.prod.js +2 -0
  50. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-streams.prod.js.map +1 -1
  51. data/lib/vendor/workbox-v5.1.1/workbox-sw.js +2 -0
  52. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-sw.js.map +1 -1
  53. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-window.dev.es5.mjs +1094 -1075
  54. data/lib/vendor/workbox-v5.1.1/workbox-window.dev.es5.mjs.map +1 -0
  55. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-window.dev.mjs +943 -943
  56. data/lib/vendor/workbox-v5.1.1/workbox-window.dev.mjs.map +1 -0
  57. data/lib/vendor/{workbox-v5.0.0 → workbox-v5.1.1}/workbox-window.dev.umd.js +1105 -1086
  58. data/lib/vendor/workbox-v5.1.1/workbox-window.dev.umd.js.map +1 -0
  59. data/lib/vendor/workbox-v5.1.1/workbox-window.prod.es5.mjs +2 -0
  60. data/lib/vendor/workbox-v5.1.1/workbox-window.prod.es5.mjs.map +1 -0
  61. data/lib/vendor/workbox-v5.1.1/workbox-window.prod.mjs +2 -0
  62. data/lib/vendor/workbox-v5.1.1/workbox-window.prod.mjs.map +1 -0
  63. data/lib/vendor/workbox-v5.1.1/workbox-window.prod.umd.js +2 -0
  64. data/lib/vendor/workbox-v5.1.1/workbox-window.prod.umd.js.map +1 -0
  65. metadata +65 -65
  66. data/lib/vendor/workbox-v5.0.0/workbox-background-sync.dev.js.map +0 -1
  67. data/lib/vendor/workbox-v5.0.0/workbox-background-sync.prod.js +0 -2
  68. data/lib/vendor/workbox-v5.0.0/workbox-background-sync.prod.js.map +0 -1
  69. data/lib/vendor/workbox-v5.0.0/workbox-broadcast-update.prod.js +0 -2
  70. data/lib/vendor/workbox-v5.0.0/workbox-core.dev.js.map +0 -1
  71. data/lib/vendor/workbox-v5.0.0/workbox-core.prod.js +0 -2
  72. data/lib/vendor/workbox-v5.0.0/workbox-core.prod.js.map +0 -1
  73. data/lib/vendor/workbox-v5.0.0/workbox-expiration.dev.js.map +0 -1
  74. data/lib/vendor/workbox-v5.0.0/workbox-expiration.prod.js +0 -2
  75. data/lib/vendor/workbox-v5.0.0/workbox-offline-ga.prod.js +0 -2
  76. data/lib/vendor/workbox-v5.0.0/workbox-precaching.dev.js.map +0 -1
  77. data/lib/vendor/workbox-v5.0.0/workbox-precaching.prod.js +0 -2
  78. data/lib/vendor/workbox-v5.0.0/workbox-precaching.prod.js.map +0 -1
  79. data/lib/vendor/workbox-v5.0.0/workbox-routing.dev.js.map +0 -1
  80. data/lib/vendor/workbox-v5.0.0/workbox-routing.prod.js +0 -2
  81. data/lib/vendor/workbox-v5.0.0/workbox-routing.prod.js.map +0 -1
  82. data/lib/vendor/workbox-v5.0.0/workbox-strategies.dev.js.map +0 -1
  83. data/lib/vendor/workbox-v5.0.0/workbox-strategies.prod.js +0 -2
  84. data/lib/vendor/workbox-v5.0.0/workbox-strategies.prod.js.map +0 -1
  85. data/lib/vendor/workbox-v5.0.0/workbox-streams.prod.js +0 -2
  86. data/lib/vendor/workbox-v5.0.0/workbox-sw.js +0 -2
  87. data/lib/vendor/workbox-v5.0.0/workbox-window.dev.es5.mjs.map +0 -1
  88. data/lib/vendor/workbox-v5.0.0/workbox-window.dev.mjs.map +0 -1
  89. data/lib/vendor/workbox-v5.0.0/workbox-window.dev.umd.js.map +0 -1
  90. data/lib/vendor/workbox-v5.0.0/workbox-window.prod.es5.mjs +0 -2
  91. data/lib/vendor/workbox-v5.0.0/workbox-window.prod.es5.mjs.map +0 -1
  92. data/lib/vendor/workbox-v5.0.0/workbox-window.prod.mjs +0 -2
  93. data/lib/vendor/workbox-v5.0.0/workbox-window.prod.mjs.map +0 -1
  94. data/lib/vendor/workbox-v5.0.0/workbox-window.prod.umd.js +0 -2
  95. data/lib/vendor/workbox-v5.0.0/workbox-window.prod.umd.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"workbox-range-requests.dev.js","sources":["../_version.js","../utils/calculateEffectiveBoundaries.js","../utils/parseRangeHeader.js","../createPartialResponse.js","../RangeRequestsPlugin.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:range-requests:5.0.0'] && _();\n}\ncatch (e) { }\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { assert } from 'workbox-core/_private/assert.js';\nimport '../_version.js';\n/**\n * @param {Blob} blob A source blob.\n * @param {number} [start] The offset to use as the start of the\n * slice.\n * @param {number} [end] The offset to use as the end of the slice.\n * @return {Object} An object with `start` and `end` properties, reflecting\n * the effective boundaries to use given the size of the blob.\n *\n * @private\n */\nfunction calculateEffectiveBoundaries(blob, start, end) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(blob, Blob, {\n moduleName: 'workbox-range-requests',\n funcName: 'calculateEffectiveBoundaries',\n paramName: 'blob',\n });\n }\n const blobSize = blob.size;\n if ((end && end > blobSize) || (start && start < 0)) {\n throw new WorkboxError('range-not-satisfiable', {\n size: blobSize,\n end,\n start,\n });\n }\n let effectiveStart;\n let effectiveEnd;\n if (start !== undefined && end !== undefined) {\n effectiveStart = start;\n // Range values are inclusive, so add 1 to the value.\n effectiveEnd = end + 1;\n }\n else if (start !== undefined && end === undefined) {\n effectiveStart = start;\n effectiveEnd = blobSize;\n }\n else if (end !== undefined && start === undefined) {\n effectiveStart = blobSize - end;\n effectiveEnd = blobSize;\n }\n return {\n start: effectiveStart,\n end: effectiveEnd,\n };\n}\nexport { calculateEffectiveBoundaries };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { assert } from 'workbox-core/_private/assert.js';\nimport '../_version.js';\n/**\n * @param {string} rangeHeader A Range: header value.\n * @return {Object} An object with `start` and `end` properties, reflecting\n * the parsed value of the Range: header. If either the `start` or `end` are\n * omitted, then `null` will be returned.\n *\n * @private\n */\nfunction parseRangeHeader(rangeHeader) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(rangeHeader, 'string', {\n moduleName: 'workbox-range-requests',\n funcName: 'parseRangeHeader',\n paramName: 'rangeHeader',\n });\n }\n const normalizedRangeHeader = rangeHeader.trim().toLowerCase();\n if (!normalizedRangeHeader.startsWith('bytes=')) {\n throw new WorkboxError('unit-must-be-bytes', { normalizedRangeHeader });\n }\n // Specifying multiple ranges separate by commas is valid syntax, but this\n // library only attempts to handle a single, contiguous sequence of bytes.\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range#Syntax\n if (normalizedRangeHeader.includes(',')) {\n throw new WorkboxError('single-range-only', { normalizedRangeHeader });\n }\n const rangeParts = /(\\d*)-(\\d*)/.exec(normalizedRangeHeader);\n // We need either at least one of the start or end values.\n if (!rangeParts || !(rangeParts[1] || rangeParts[2])) {\n throw new WorkboxError('invalid-range-values', { normalizedRangeHeader });\n }\n return {\n start: rangeParts[1] === '' ? undefined : Number(rangeParts[1]),\n end: rangeParts[2] === '' ? undefined : Number(rangeParts[2]),\n };\n}\nexport { parseRangeHeader };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { calculateEffectiveBoundaries } from './utils/calculateEffectiveBoundaries.js';\nimport { parseRangeHeader } from './utils/parseRangeHeader.js';\nimport './_version.js';\n/**\n * Given a `Request` and `Response` objects as input, this will return a\n * promise for a new `Response`.\n *\n * If the original `Response` already contains partial content (i.e. it has\n * a status of 206), then this assumes it already fulfills the `Range:`\n * requirements, and will return it as-is.\n *\n * @param {Request} request A request, which should contain a Range:\n * header.\n * @param {Response} originalResponse A response.\n * @return {Promise<Response>} Either a `206 Partial Content` response, with\n * the response body set to the slice of content specified by the request's\n * `Range:` header, or a `416 Range Not Satisfiable` response if the\n * conditions of the `Range:` header can't be met.\n *\n * @memberof module:workbox-range-requests\n */\nasync function createPartialResponse(request, originalResponse) {\n try {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(request, Request, {\n moduleName: 'workbox-range-requests',\n funcName: 'createPartialResponse',\n paramName: 'request',\n });\n assert.isInstance(originalResponse, Response, {\n moduleName: 'workbox-range-requests',\n funcName: 'createPartialResponse',\n paramName: 'originalResponse',\n });\n }\n if (originalResponse.status === 206) {\n // If we already have a 206, then just pass it through as-is;\n // see https://github.com/GoogleChrome/workbox/issues/1720\n return originalResponse;\n }\n const rangeHeader = request.headers.get('range');\n if (!rangeHeader) {\n throw new WorkboxError('no-range-header');\n }\n const boundaries = parseRangeHeader(rangeHeader);\n const originalBlob = await originalResponse.blob();\n const effectiveBoundaries = calculateEffectiveBoundaries(originalBlob, boundaries.start, boundaries.end);\n const slicedBlob = originalBlob.slice(effectiveBoundaries.start, effectiveBoundaries.end);\n const slicedBlobSize = slicedBlob.size;\n const slicedResponse = new Response(slicedBlob, {\n // Status code 206 is for a Partial Content response.\n // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/206\n status: 206,\n statusText: 'Partial Content',\n headers: originalResponse.headers,\n });\n slicedResponse.headers.set('Content-Length', String(slicedBlobSize));\n slicedResponse.headers.set('Content-Range', `bytes ${effectiveBoundaries.start}-${effectiveBoundaries.end - 1}/` +\n originalBlob.size);\n return slicedResponse;\n }\n catch (error) {\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(`Unable to construct a partial response; returning a ` +\n `416 Range Not Satisfiable response instead.`);\n logger.groupCollapsed(`View details here.`);\n logger.log(error);\n logger.log(request);\n logger.log(originalResponse);\n logger.groupEnd();\n }\n return new Response('', {\n status: 416,\n statusText: 'Range Not Satisfiable',\n });\n }\n}\nexport { createPartialResponse };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { createPartialResponse } from './createPartialResponse.js';\nimport './_version.js';\n/**\n * The range request plugin makes it easy for a request with a 'Range' header to\n * be fulfilled by a cached response.\n *\n * It does this by intercepting the `cachedResponseWillBeUsed` plugin callback\n * and returning the appropriate subset of the cached response body.\n *\n * @memberof module:workbox-range-requests\n */\nclass RangeRequestsPlugin {\n constructor() {\n /**\n * @param {Object} options\n * @param {Request} options.request The original request, which may or may not\n * contain a Range: header.\n * @param {Response} options.cachedResponse The complete cached response.\n * @return {Promise<Response>} If request contains a 'Range' header, then a\n * new response with status 206 whose body is a subset of `cachedResponse` is\n * returned. Otherwise, `cachedResponse` is returned as-is.\n *\n * @private\n */\n this.cachedResponseWillBeUsed = async ({ request, cachedResponse }) => {\n // Only return a sliced response if there's something valid in the cache,\n // and there's a Range: header in the request.\n if (cachedResponse && request.headers.has('range')) {\n return await createPartialResponse(request, cachedResponse);\n }\n // If there was no Range: header, or if cachedResponse wasn't valid, just\n // pass it through as-is.\n return cachedResponse;\n };\n }\n}\nexport { RangeRequestsPlugin };\n"],"names":["self","_","e","calculateEffectiveBoundaries","blob","start","end","assert","isInstance","Blob","moduleName","funcName","paramName","blobSize","size","WorkboxError","effectiveStart","effectiveEnd","undefined","parseRangeHeader","rangeHeader","isType","normalizedRangeHeader","trim","toLowerCase","startsWith","includes","rangeParts","exec","Number","createPartialResponse","request","originalResponse","process","Request","Response","status","headers","get","boundaries","originalBlob","effectiveBoundaries","slicedBlob","slice","slicedBlobSize","slicedResponse","statusText","set","String","error","logger","warn","groupCollapsed","log","groupEnd","RangeRequestsPlugin","constructor","cachedResponseWillBeUsed","cachedResponse","has"],"mappings":";;;;IAEA,IAAI;IACAA,EAAAA,IAAI,CAAC,8BAAD,CAAJ,IAAwCC,CAAC,EAAzC;IACH,CAFD,CAGA,OAAOC,CAAP,EAAU;;ICLV;;;;;;;AAOA,IAGA;;;;;;;;;;;IAUA,SAASC,4BAAT,CAAsCC,IAAtC,EAA4CC,KAA5C,EAAmDC,GAAnD,EAAwD;IACpD,EAA2C;IACvCC,IAAAA,gBAAM,CAACC,UAAP,CAAkBJ,IAAlB,EAAwBK,IAAxB,EAA8B;IAC1BC,MAAAA,UAAU,EAAE,wBADc;IAE1BC,MAAAA,QAAQ,EAAE,8BAFgB;IAG1BC,MAAAA,SAAS,EAAE;IAHe,KAA9B;IAKH;;IACD,QAAMC,QAAQ,GAAGT,IAAI,CAACU,IAAtB;;IACA,MAAKR,GAAG,IAAIA,GAAG,GAAGO,QAAd,IAA4BR,KAAK,IAAIA,KAAK,GAAG,CAAjD,EAAqD;IACjD,UAAM,IAAIU,4BAAJ,CAAiB,uBAAjB,EAA0C;IAC5CD,MAAAA,IAAI,EAAED,QADsC;IAE5CP,MAAAA,GAF4C;IAG5CD,MAAAA;IAH4C,KAA1C,CAAN;IAKH;;IACD,MAAIW,c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AAuB,oBAAvB;IACAF,MAAAA,gBAAM,CAACG,GAAP,CAAWJ,KAAX;IACAC,MAAAA,gBAAM,CAACG,GAAP,CAAWtB,OAAX;IACAmB,MAAAA,gBAAM,CAACG,GAAP,CAAWrB,gBAAX;IACAkB,MAAAA,gBAAM,CAACI,QAAP;IACH;;IACD,WAAO,IAAInB,QAAJ,CAAa,EAAb,EAAiB;IACpBC,MAAAA,MAAM,EAAE,GADY;IAEpBU,MAAAA,UAAU,EAAE;IAFQ,KAAjB,CAAP;IAIH;IACJ;;ICtFD;;;;;;;AAOA,IAEA;;;;;;;;;;IASA,MAAMS,mBAAN,CAA0B;IACtBC,EAAAA,WAAW,GAAG;IACV;;;;;;;;;;;IAWA,SAAKC,wBAAL,GAAgC,OAAO;IAAE1B,MAAAA,OAAF;IAAW2B,MAAAA;IAAX,KAAP,KAAuC;IACnE;IACA;IACA,UAAIA,cAAc,IAAI3B,OAAO,CAACM,OAAR,CAAgBsB,GAAhB,CAAoB,OAApB,CAAtB,EAAoD;IAChD,eAAO,MAAM7B,qBAAqB,CAACC,OAAD,EAAU2B,cAAV,CAAlC;IACH,OALkE;IAOnE;;;IACA,aAAOA,cAAP;IACH,KATD;IAUH;;IAvBqB;;;;;;;;;;;"}
1
+ {"version":3,"file":"workbox-range-requests.dev.js","sources":["../_version.js","../utils/calculateEffectiveBoundaries.js","../utils/parseRangeHeader.js","../createPartialResponse.js","../RangeRequestsPlugin.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:range-requests:5.1.1'] && _();\n}\ncatch (e) { }\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { assert } from 'workbox-core/_private/assert.js';\nimport '../_version.js';\n/**\n * @param {Blob} blob A source blob.\n * @param {number} [start] The offset to use as the start of the\n * slice.\n * @param {number} [end] The offset to use as the end of the slice.\n * @return {Object} An object with `start` and `end` properties, reflecting\n * the effective boundaries to use given the size of the blob.\n *\n * @private\n */\nfunction calculateEffectiveBoundaries(blob, start, end) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(blob, Blob, {\n moduleName: 'workbox-range-requests',\n funcName: 'calculateEffectiveBoundaries',\n paramName: 'blob',\n });\n }\n const blobSize = blob.size;\n if ((end && end > blobSize) || (start && start < 0)) {\n throw new WorkboxError('range-not-satisfiable', {\n size: blobSize,\n end,\n start,\n });\n }\n let effectiveStart;\n let effectiveEnd;\n if (start !== undefined && end !== undefined) {\n effectiveStart = start;\n // Range values are inclusive, so add 1 to the value.\n effectiveEnd = end + 1;\n }\n else if (start !== undefined && end === undefined) {\n effectiveStart = start;\n effectiveEnd = blobSize;\n }\n else if (end !== undefined && start === undefined) {\n effectiveStart = blobSize - end;\n effectiveEnd = blobSize;\n }\n return {\n start: effectiveStart,\n end: effectiveEnd,\n };\n}\nexport { calculateEffectiveBoundaries };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { assert } from 'workbox-core/_private/assert.js';\nimport '../_version.js';\n/**\n * @param {string} rangeHeader A Range: header value.\n * @return {Object} An object with `start` and `end` properties, reflecting\n * the parsed value of the Range: header. If either the `start` or `end` are\n * omitted, then `null` will be returned.\n *\n * @private\n */\nfunction parseRangeHeader(rangeHeader) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(rangeHeader, 'string', {\n moduleName: 'workbox-range-requests',\n funcName: 'parseRangeHeader',\n paramName: 'rangeHeader',\n });\n }\n const normalizedRangeHeader = rangeHeader.trim().toLowerCase();\n if (!normalizedRangeHeader.startsWith('bytes=')) {\n throw new WorkboxError('unit-must-be-bytes', { normalizedRangeHeader });\n }\n // Specifying multiple ranges separate by commas is valid syntax, but this\n // library only attempts to handle a single, contiguous sequence of bytes.\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range#Syntax\n if (normalizedRangeHeader.includes(',')) {\n throw new WorkboxError('single-range-only', { normalizedRangeHeader });\n }\n const rangeParts = /(\\d*)-(\\d*)/.exec(normalizedRangeHeader);\n // We need either at least one of the start or end values.\n if (!rangeParts || !(rangeParts[1] || rangeParts[2])) {\n throw new WorkboxError('invalid-range-values', { normalizedRangeHeader });\n }\n return {\n start: rangeParts[1] === '' ? undefined : Number(rangeParts[1]),\n end: rangeParts[2] === '' ? undefined : Number(rangeParts[2]),\n };\n}\nexport { parseRangeHeader };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { calculateEffectiveBoundaries } from './utils/calculateEffectiveBoundaries.js';\nimport { parseRangeHeader } from './utils/parseRangeHeader.js';\nimport './_version.js';\n/**\n * Given a `Request` and `Response` objects as input, this will return a\n * promise for a new `Response`.\n *\n * If the original `Response` already contains partial content (i.e. it has\n * a status of 206), then this assumes it already fulfills the `Range:`\n * requirements, and will return it as-is.\n *\n * @param {Request} request A request, which should contain a Range:\n * header.\n * @param {Response} originalResponse A response.\n * @return {Promise<Response>} Either a `206 Partial Content` response, with\n * the response body set to the slice of content specified by the request's\n * `Range:` header, or a `416 Range Not Satisfiable` response if the\n * conditions of the `Range:` header can't be met.\n *\n * @memberof module:workbox-range-requests\n */\nasync function createPartialResponse(request, originalResponse) {\n try {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(request, Request, {\n moduleName: 'workbox-range-requests',\n funcName: 'createPartialResponse',\n paramName: 'request',\n });\n assert.isInstance(originalResponse, Response, {\n moduleName: 'workbox-range-requests',\n funcName: 'createPartialResponse',\n paramName: 'originalResponse',\n });\n }\n if (originalResponse.status === 206) {\n // If we already have a 206, then just pass it through as-is;\n // see https://github.com/GoogleChrome/workbox/issues/1720\n return originalResponse;\n }\n const rangeHeader = request.headers.get('range');\n if (!rangeHeader) {\n throw new WorkboxError('no-range-header');\n }\n const boundaries = parseRangeHeader(rangeHeader);\n const originalBlob = await originalResponse.blob();\n const effectiveBoundaries = calculateEffectiveBoundaries(originalBlob, boundaries.start, boundaries.end);\n const slicedBlob = originalBlob.slice(effectiveBoundaries.start, effectiveBoundaries.end);\n const slicedBlobSize = slicedBlob.size;\n const slicedResponse = new Response(slicedBlob, {\n // Status code 206 is for a Partial Content response.\n // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/206\n status: 206,\n statusText: 'Partial Content',\n headers: originalResponse.headers,\n });\n slicedResponse.headers.set('Content-Length', String(slicedBlobSize));\n slicedResponse.headers.set('Content-Range', `bytes ${effectiveBoundaries.start}-${effectiveBoundaries.end - 1}/` +\n originalBlob.size);\n return slicedResponse;\n }\n catch (error) {\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(`Unable to construct a partial response; returning a ` +\n `416 Range Not Satisfiable response instead.`);\n logger.groupCollapsed(`View details here.`);\n logger.log(error);\n logger.log(request);\n logger.log(originalResponse);\n logger.groupEnd();\n }\n return new Response('', {\n status: 416,\n statusText: 'Range Not Satisfiable',\n });\n }\n}\nexport { createPartialResponse };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { createPartialResponse } from './createPartialResponse.js';\nimport './_version.js';\n/**\n * The range request plugin makes it easy for a request with a 'Range' header to\n * be fulfilled by a cached response.\n *\n * It does this by intercepting the `cachedResponseWillBeUsed` plugin callback\n * and returning the appropriate subset of the cached response body.\n *\n * @memberof module:workbox-range-requests\n */\nclass RangeRequestsPlugin {\n constructor() {\n /**\n * @param {Object} options\n * @param {Request} options.request The original request, which may or may not\n * contain a Range: header.\n * @param {Response} options.cachedResponse The complete cached response.\n * @return {Promise<Response>} If request contains a 'Range' header, then a\n * new response with status 206 whose body is a subset of `cachedResponse` is\n * returned. Otherwise, `cachedResponse` is returned as-is.\n *\n * @private\n */\n this.cachedResponseWillBeUsed = async ({ request, cachedResponse }) => {\n // Only return a sliced response if there's something valid in the cache,\n // and there's a Range: header in the request.\n if (cachedResponse && request.headers.has('range')) {\n return await createPartialResponse(request, cachedResponse);\n }\n // If there was no Range: header, or if cachedResponse wasn't valid, just\n // pass it through as-is.\n return cachedResponse;\n };\n }\n}\nexport { RangeRequestsPlugin };\n"],"names":["self","_","e","calculateEffectiveBoundaries","blob","start","end","assert","isInstance","Blob","moduleName","funcName","paramName","blobSize","size","WorkboxError","effectiveStart","effectiveEnd","undefined","parseRangeHeader","rangeHeader","isType","normalizedRangeHeader","trim","toLowerCase","startsWith","includes","rangeParts","exec","Number","createPartialResponse","request","originalResponse","process","Request","Response","status","headers","get","boundaries","originalBlob","effectiveBoundaries","slicedBlob","slice","slicedBlobSize","slicedResponse","statusText","set","String","error","logger","warn","groupCollapsed","log","groupEnd","RangeRequestsPlugin","constructor","cachedResponseWillBeUsed","cachedResponse","has"],"mappings":";;;;IAEA,IAAI;IACAA,EAAAA,IAAI,CAAC,8BAAD,CAAJ,IAAwCC,CAAC,EAAzC;IACH,CAFD,CAGA,OAAOC,CAAP,EAAU;;ICLV;;;;;;;AAOA,IAGA;;;;;;;;;;;IAUA,SAASC,4BAAT,CAAsCC,IAAtC,EAA4CC,KAA5C,EAAmDC,GAAnD,EAAwD;IACpD,EAA2C;IACvCC,IAAAA,gBAAM,CAACC,UAAP,CAAkBJ,IAAlB,EAAwBK,IAAxB,EAA8B;IAC1BC,MAAAA,UAAU,EAAE,wBADc;IAE1BC,MAAAA,QAAQ,EAAE,8BAFgB;IAG1BC,MAAAA,SAAS,EAAE;IAHe,KAA9B;IAKH;;IACD,QAAMC,QAAQ,GAAGT,IAAI,CAACU,IAAtB;;IACA,MAAKR,GAAG,IAAIA,GA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B,CAACnC,GAApB,GAA0B,CAAE,GAAlE,GACxCkC,YAAY,CAAC1B,IADjB;IAEA,WAAO+B,cAAP;IACH,GAtCD,CAuCA,OAAOI,KAAP,EAAc;IACV,IAA2C;IACvCC,MAAAA,gBAAM,CAACC,IAAP,CAAa,sDAAD,GACP,6CADL;IAEAD,MAAAA,gBAAM,CAACE,cAAP,CAAuB,oBAAvB;IACAF,MAAAA,gBAAM,CAACG,GAAP,CAAWJ,KAAX;IACAC,MAAAA,gBAAM,CAACG,GAAP,CAAWtB,OAAX;IACAmB,MAAAA,gBAAM,CAACG,GAAP,CAAWrB,gBAAX;IACAkB,MAAAA,gBAAM,CAACI,QAAP;IACH;;IACD,WAAO,IAAInB,QAAJ,CAAa,EAAb,EAAiB;IACpBC,MAAAA,MAAM,EAAE,GADY;IAEpBU,MAAAA,UAAU,EAAE;IAFQ,KAAjB,CAAP;IAIH;IACJ;;ICtFD;;;;;;;AAOA,IAEA;;;;;;;;;;IASA,MAAMS,mBAAN,CAA0B;IACtBC,EAAAA,WAAW,GAAG;IACV;;;;;;;;;;;IAWA,SAAKC,wBAAL,GAAgC,OAAO;IAAE1B,MAAAA,OAAF;IAAW2B,MAAAA;IAAX,KAAP,KAAuC;IACnE;IACA;IACA,UAAIA,cAAc,IAAI3B,OAAO,CAACM,OAAR,CAAgBsB,GAAhB,CAAoB,OAApB,CAAtB,EAAoD;IAChD,eAAO,MAAM7B,qBAAqB,CAACC,OAAD,EAAU2B,cAAV,CAAlC;IACH,OALkE;IAOnE;;;IACA,aAAOA,cAAP;IACH,KATD;IAUH;;IAvBqB;;;;;;;;;;;"}
@@ -1,2 +1,2 @@
1
- this.workbox=this.workbox||{},this.workbox.rangeRequests=function(t,e,n){"use strict";try{self["workbox:range-requests:5.0.0"]&&_()}catch(t){}async function r(t,n){try{if(206===n.status)return n;const r=t.headers.get("range");if(!r)throw new e.WorkboxError("no-range-header");const s=function(t){const n=t.trim().toLowerCase();if(!n.startsWith("bytes="))throw new e.WorkboxError("unit-must-be-bytes",{normalizedRangeHeader:n});if(n.includes(","))throw new e.WorkboxError("single-range-only",{normalizedRangeHeader:n});const r=/(\d*)-(\d*)/.exec(n);if(!r||!r[1]&&!r[2])throw new e.WorkboxError("invalid-range-values",{normalizedRangeHeader:n});return{start:""===r[1]?void 0:Number(r[1]),end:""===r[2]?void 0:Number(r[2])}}(r),a=await n.blob(),o=function(t,n,r){const s=t.size;if(r&&r>s||n&&n<0)throw new e.WorkboxError("range-not-satisfiable",{size:s,end:r,start:n});let a,o;return void 0!==n&&void 0!==r?(a=n,o=r+1):void 0!==n&&void 0===r?(a=n,o=s):void 0!==r&&void 0===n&&(a=s-r,o=s),{start:a,end:o}}(a,s.start,s.end),i=a.slice(o.start,o.end),d=i.size,u=new Response(i,{status:206,statusText:"Partial Content",headers:n.headers});return u.headers.set("Content-Length",String(d)),u.headers.set("Content-Range",`bytes ${o.start}-${o.end-1}/`+a.size),u}catch(t){return new Response("",{status:416,statusText:"Range Not Satisfiable"})}}return t.RangeRequestsPlugin=class{constructor(){this.cachedResponseWillBeUsed=(async({request:t,cachedResponse:e})=>e&&t.headers.has("range")?await r(t,e):e)}},t.createPartialResponse=r,t}({},workbox.core._private,workbox.core._private);
2
- //# sourceMappingURL=workbox-range-requests.prod.js.map
1
+ this.workbox=this.workbox||{},this.workbox.rangeRequests=function(t,e,n){"use strict";try{self["workbox:range-requests:5.1.1"]&&_()}catch(t){}async function r(t,n){try{if(206===n.status)return n;const r=t.headers.get("range");if(!r)throw new e.WorkboxError("no-range-header");const s=function(t){const n=t.trim().toLowerCase();if(!n.startsWith("bytes="))throw new e.WorkboxError("unit-must-be-bytes",{normalizedRangeHeader:n});if(n.includes(","))throw new e.WorkboxError("single-range-only",{normalizedRangeHeader:n});const r=/(\d*)-(\d*)/.exec(n);if(!r||!r[1]&&!r[2])throw new e.WorkboxError("invalid-range-values",{normalizedRangeHeader:n});return{start:""===r[1]?void 0:Number(r[1]),end:""===r[2]?void 0:Number(r[2])}}(r),a=await n.blob(),o=function(t,n,r){const s=t.size;if(r&&r>s||n&&n<0)throw new e.WorkboxError("range-not-satisfiable",{size:s,end:r,start:n});let a,o;return void 0!==n&&void 0!==r?(a=n,o=r+1):void 0!==n&&void 0===r?(a=n,o=s):void 0!==r&&void 0===n&&(a=s-r,o=s),{start:a,end:o}}(a,s.start,s.end),i=a.slice(o.start,o.end),d=i.size,u=new Response(i,{status:206,statusText:"Partial Content",headers:n.headers});return u.headers.set("Content-Length",String(d)),u.headers.set("Content-Range",`bytes ${o.start}-${o.end-1}/`+a.size),u}catch(t){return new Response("",{status:416,statusText:"Range Not Satisfiable"})}}return t.RangeRequestsPlugin=class{constructor(){this.cachedResponseWillBeUsed=async({request:t,cachedResponse:e})=>e&&t.headers.has("range")?await r(t,e):e}},t.createPartialResponse=r,t}({},workbox.core._private,workbox.core._private);
2
+ //# sourceMappingURL=workbox-range-requests.prod.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"workbox-range-requests.prod.js","sources":["../_version.js","../createPartialResponse.js","../utils/parseRangeHeader.js","../utils/calculateEffectiveBoundaries.js","../RangeRequestsPlugin.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:range-requests:5.0.0'] && _();\n}\ncatch (e) { }\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { calculateEffectiveBoundaries } from './utils/calculateEffectiveBoundaries.js';\nimport { parseRangeHeader } from './utils/parseRangeHeader.js';\nimport './_version.js';\n/**\n * Given a `Request` and `Response` objects as input, this will return a\n * promise for a new `Response`.\n *\n * If the original `Response` already contains partial content (i.e. it has\n * a status of 206), then this assumes it already fulfills the `Range:`\n * requirements, and will return it as-is.\n *\n * @param {Request} request A request, which should contain a Range:\n * header.\n * @param {Response} originalResponse A response.\n * @return {Promise<Response>} Either a `206 Partial Content` response, with\n * the response body set to the slice of content specified by the request's\n * `Range:` header, or a `416 Range Not Satisfiable` response if the\n * conditions of the `Range:` header can't be met.\n *\n * @memberof module:workbox-range-requests\n */\nasync function createPartialResponse(request, originalResponse) {\n try {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(request, Request, {\n moduleName: 'workbox-range-requests',\n funcName: 'createPartialResponse',\n paramName: 'request',\n });\n assert.isInstance(originalResponse, Response, {\n moduleName: 'workbox-range-requests',\n funcName: 'createPartialResponse',\n paramName: 'originalResponse',\n });\n }\n if (originalResponse.status === 206) {\n // If we already have a 206, then just pass it through as-is;\n // see https://github.com/GoogleChrome/workbox/issues/1720\n return originalResponse;\n }\n const rangeHeader = request.headers.get('range');\n if (!rangeHeader) {\n throw new WorkboxError('no-range-header');\n }\n const boundaries = parseRangeHeader(rangeHeader);\n const originalBlob = await originalResponse.blob();\n const effectiveBoundaries = calculateEffectiveBoundaries(originalBlob, boundaries.start, boundaries.end);\n const slicedBlob = originalBlob.slice(effectiveBoundaries.start, effectiveBoundaries.end);\n const slicedBlobSize = slicedBlob.size;\n const slicedResponse = new Response(slicedBlob, {\n // Status code 206 is for a Partial Content response.\n // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/206\n status: 206,\n statusText: 'Partial Content',\n headers: originalResponse.headers,\n });\n slicedResponse.headers.set('Content-Length', String(slicedBlobSize));\n slicedResponse.headers.set('Content-Range', `bytes ${effectiveBoundaries.start}-${effectiveBoundaries.end - 1}/` +\n originalBlob.size);\n return slicedResponse;\n }\n catch (error) {\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(`Unable to construct a partial response; returning a ` +\n `416 Range Not Satisfiable response instead.`);\n logger.groupCollapsed(`View details here.`);\n logger.log(error);\n logger.log(request);\n logger.log(originalResponse);\n logger.groupEnd();\n }\n return new Response('', {\n status: 416,\n statusText: 'Range Not Satisfiable',\n });\n }\n}\nexport { createPartialResponse };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { assert } from 'workbox-core/_private/assert.js';\nimport '../_version.js';\n/**\n * @param {string} rangeHeader A Range: header value.\n * @return {Object} An object with `start` and `end` properties, reflecting\n * the parsed value of the Range: header. If either the `start` or `end` are\n * omitted, then `null` will be returned.\n *\n * @private\n */\nfunction parseRangeHeader(rangeHeader) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(rangeHeader, 'string', {\n moduleName: 'workbox-range-requests',\n funcName: 'parseRangeHeader',\n paramName: 'rangeHeader',\n });\n }\n const normalizedRangeHeader = rangeHeader.trim().toLowerCase();\n if (!normalizedRangeHeader.startsWith('bytes=')) {\n throw new WorkboxError('unit-must-be-bytes', { normalizedRangeHeader });\n }\n // Specifying multiple ranges separate by commas is valid syntax, but this\n // library only attempts to handle a single, contiguous sequence of bytes.\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range#Syntax\n if (normalizedRangeHeader.includes(',')) {\n throw new WorkboxError('single-range-only', { normalizedRangeHeader });\n }\n const rangeParts = /(\\d*)-(\\d*)/.exec(normalizedRangeHeader);\n // We need either at least one of the start or end values.\n if (!rangeParts || !(rangeParts[1] || rangeParts[2])) {\n throw new WorkboxError('invalid-range-values', { normalizedRangeHeader });\n }\n return {\n start: rangeParts[1] === '' ? undefined : Number(rangeParts[1]),\n end: rangeParts[2] === '' ? undefined : Number(rangeParts[2]),\n };\n}\nexport { parseRangeHeader };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { assert } from 'workbox-core/_private/assert.js';\nimport '../_version.js';\n/**\n * @param {Blob} blob A source blob.\n * @param {number} [start] The offset to use as the start of the\n * slice.\n * @param {number} [end] The offset to use as the end of the slice.\n * @return {Object} An object with `start` and `end` properties, reflecting\n * the effective boundaries to use given the size of the blob.\n *\n * @private\n */\nfunction calculateEffectiveBoundaries(blob, start, end) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(blob, Blob, {\n moduleName: 'workbox-range-requests',\n funcName: 'calculateEffectiveBoundaries',\n paramName: 'blob',\n });\n }\n const blobSize = blob.size;\n if ((end && end > blobSize) || (start && start < 0)) {\n throw new WorkboxError('range-not-satisfiable', {\n size: blobSize,\n end,\n start,\n });\n }\n let effectiveStart;\n let effectiveEnd;\n if (start !== undefined && end !== undefined) {\n effectiveStart = start;\n // Range values are inclusive, so add 1 to the value.\n effectiveEnd = end + 1;\n }\n else if (start !== undefined && end === undefined) {\n effectiveStart = start;\n effectiveEnd = blobSize;\n }\n else if (end !== undefined && start === undefined) {\n effectiveStart = blobSize - end;\n effectiveEnd = blobSize;\n }\n return {\n start: effectiveStart,\n end: effectiveEnd,\n };\n}\nexport { calculateEffectiveBoundaries };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { createPartialResponse } from './createPartialResponse.js';\nimport './_version.js';\n/**\n * The range request plugin makes it easy for a request with a 'Range' header to\n * be fulfilled by a cached response.\n *\n * It does this by intercepting the `cachedResponseWillBeUsed` plugin callback\n * and returning the appropriate subset of the cached response body.\n *\n * @memberof module:workbox-range-requests\n */\nclass RangeRequestsPlugin {\n constructor() {\n /**\n * @param {Object} options\n * @param {Request} options.request The original request, which may or may not\n * contain a Range: header.\n * @param {Response} options.cachedResponse The complete cached response.\n * @return {Promise<Response>} If request contains a 'Range' header, then a\n * new response with status 206 whose body is a subset of `cachedResponse` is\n * returned. Otherwise, `cachedResponse` is returned as-is.\n *\n * @private\n */\n this.cachedResponseWillBeUsed = async ({ request, cachedResponse }) => {\n // Only return a sliced response if there's something valid in the cache,\n // and there's a Range: header in the request.\n if (cachedResponse && request.headers.has('range')) {\n return await createPartialResponse(request, cachedResponse);\n }\n // If there was no Range: header, or if cachedResponse wasn't valid, just\n // pass it through as-is.\n return cachedResponse;\n };\n }\n}\nexport { RangeRequestsPlugin };\n"],"names":["self","_","e","async","createPartialResponse","request","originalResponse","status","rangeHeader","headers","get","WorkboxError","boundaries","normalizedRangeHeader","trim","toLowerCase","startsWith","includes","rangeParts","exec","start","undefined","Number","end","parseRangeHeader","originalBlob","blob","effectiveBoundaries","blobSize","size","effectiveStart","effectiveEnd","calculateEffectiveBoundaries","slicedBlob","slice","slicedBlobSize","slicedResponse","Response","statusText","set","String","error","constructor","cachedResponseWillBeUsed","cachedResponse","has"],"mappings":"sFAEA,IACIA,KAAK,iCAAmCC,IAE5C,MAAOC,IC0BPC,eAAeC,EAAsBC,EAASC,UAcN,MAA5BA,EAAiBC,cAGVD,QAELE,EAAcH,EAAQI,QAAQC,IAAI,aACnCF,QACK,IAAIG,eAAa,yBAErBC,ECpCd,SAA0BJ,SAQhBK,EAAwBL,EAAYM,OAAOC,kBAC5CF,EAAsBG,WAAW,gBAC5B,IAAIL,eAAa,qBAAsB,CAAEE,sBAAAA,OAK/CA,EAAsBI,SAAS,WACzB,IAAIN,eAAa,oBAAqB,CAAEE,sBAAAA,UAE5CK,EAAa,cAAcC,KAAKN,OAEjCK,IAAgBA,EAAW,KAAMA,EAAW,SACvC,IAAIP,eAAa,uBAAwB,CAAEE,sBAAAA,UAE9C,CACHO,MAAyB,KAAlBF,EAAW,QAAYG,EAAYC,OAAOJ,EAAW,IAC5DK,IAAuB,KAAlBL,EAAW,QAAYG,EAAYC,OAAOJ,EAAW,KDWvCM,CAAiBhB,GAC9BiB,QAAqBnB,EAAiBoB,OACtCC,EEpCd,SAAsCD,EAAMN,EAAOG,SAQzCK,EAAWF,EAAKG,QACjBN,GAAOA,EAAMK,GAAcR,GAASA,EAAQ,QACvC,IAAIT,eAAa,wBAAyB,CAC5CkB,KAAMD,EACNL,IAAAA,EACAH,MAAAA,QAGJU,EACAC,cACUV,IAAVD,QAA+BC,IAARE,GACvBO,EAAiBV,EAEjBW,EAAeR,EAAM,QAENF,IAAVD,QAA+BC,IAARE,GAC5BO,EAAiBV,EACjBW,EAAeH,QAEFP,IAARE,QAA+BF,IAAVD,IAC1BU,EAAiBF,EAAWL,EAC5BQ,EAAeH,GAEZ,CACHR,MAAOU,EACPP,IAAKQ,GFGuBC,CAA6BP,EAAcb,EAAWQ,MAAOR,EAAWW,KAC9FU,EAAaR,EAAaS,MAAMP,EAAoBP,MAAOO,EAAoBJ,KAC/EY,EAAiBF,EAAWJ,KAC5BO,EAAiB,IAAIC,SAASJ,EAAY,CAG5C1B,OAAQ,IACR+B,WAAY,kBACZ7B,QAASH,EAAiBG,iBAE9B2B,EAAe3B,QAAQ8B,IAAI,iBAAkBC,OAAOL,IACpDC,EAAe3B,QAAQ8B,IAAI,yBAA0BZ,EAAoBP,SAASO,EAAoBJ,IAAM,KACxGE,EAAaI,MACVO,EAEX,MAAOK,UAUI,IAAIJ,SAAS,GAAI,CACpB9B,OAAQ,IACR+B,WAAY,wDGjExB,MACII,mBAYSC,yBAA2BxC,QAASE,QAAAA,EAASuC,eAAAA,KAG1CA,GAAkBvC,EAAQI,QAAQoC,IAAI,eACzBzC,EAAsBC,EAASuC,GAIzCA"}
1
+ {"version":3,"file":"workbox-range-requests.prod.js","sources":["../_version.js","../createPartialResponse.js","../utils/parseRangeHeader.js","../utils/calculateEffectiveBoundaries.js","../RangeRequestsPlugin.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:range-requests:5.1.1'] && _();\n}\ncatch (e) { }\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { calculateEffectiveBoundaries } from './utils/calculateEffectiveBoundaries.js';\nimport { parseRangeHeader } from './utils/parseRangeHeader.js';\nimport './_version.js';\n/**\n * Given a `Request` and `Response` objects as input, this will return a\n * promise for a new `Response`.\n *\n * If the original `Response` already contains partial content (i.e. it has\n * a status of 206), then this assumes it already fulfills the `Range:`\n * requirements, and will return it as-is.\n *\n * @param {Request} request A request, which should contain a Range:\n * header.\n * @param {Response} originalResponse A response.\n * @return {Promise<Response>} Either a `206 Partial Content` response, with\n * the response body set to the slice of content specified by the request's\n * `Range:` header, or a `416 Range Not Satisfiable` response if the\n * conditions of the `Range:` header can't be met.\n *\n * @memberof module:workbox-range-requests\n */\nasync function createPartialResponse(request, originalResponse) {\n try {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(request, Request, {\n moduleName: 'workbox-range-requests',\n funcName: 'createPartialResponse',\n paramName: 'request',\n });\n assert.isInstance(originalResponse, Response, {\n moduleName: 'workbox-range-requests',\n funcName: 'createPartialResponse',\n paramName: 'originalResponse',\n });\n }\n if (originalResponse.status === 206) {\n // If we already have a 206, then just pass it through as-is;\n // see https://github.com/GoogleChrome/workbox/issues/1720\n return originalResponse;\n }\n const rangeHeader = request.headers.get('range');\n if (!rangeHeader) {\n throw new WorkboxError('no-range-header');\n }\n const boundaries = parseRangeHeader(rangeHeader);\n const originalBlob = await originalResponse.blob();\n const effectiveBoundaries = calculateEffectiveBoundaries(originalBlob, boundaries.start, boundaries.end);\n const slicedBlob = originalBlob.slice(effectiveBoundaries.start, effectiveBoundaries.end);\n const slicedBlobSize = slicedBlob.size;\n const slicedResponse = new Response(slicedBlob, {\n // Status code 206 is for a Partial Content response.\n // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/206\n status: 206,\n statusText: 'Partial Content',\n headers: originalResponse.headers,\n });\n slicedResponse.headers.set('Content-Length', String(slicedBlobSize));\n slicedResponse.headers.set('Content-Range', `bytes ${effectiveBoundaries.start}-${effectiveBoundaries.end - 1}/` +\n originalBlob.size);\n return slicedResponse;\n }\n catch (error) {\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(`Unable to construct a partial response; returning a ` +\n `416 Range Not Satisfiable response instead.`);\n logger.groupCollapsed(`View details here.`);\n logger.log(error);\n logger.log(request);\n logger.log(originalResponse);\n logger.groupEnd();\n }\n return new Response('', {\n status: 416,\n statusText: 'Range Not Satisfiable',\n });\n }\n}\nexport { createPartialResponse };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { assert } from 'workbox-core/_private/assert.js';\nimport '../_version.js';\n/**\n * @param {string} rangeHeader A Range: header value.\n * @return {Object} An object with `start` and `end` properties, reflecting\n * the parsed value of the Range: header. If either the `start` or `end` are\n * omitted, then `null` will be returned.\n *\n * @private\n */\nfunction parseRangeHeader(rangeHeader) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(rangeHeader, 'string', {\n moduleName: 'workbox-range-requests',\n funcName: 'parseRangeHeader',\n paramName: 'rangeHeader',\n });\n }\n const normalizedRangeHeader = rangeHeader.trim().toLowerCase();\n if (!normalizedRangeHeader.startsWith('bytes=')) {\n throw new WorkboxError('unit-must-be-bytes', { normalizedRangeHeader });\n }\n // Specifying multiple ranges separate by commas is valid syntax, but this\n // library only attempts to handle a single, contiguous sequence of bytes.\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range#Syntax\n if (normalizedRangeHeader.includes(',')) {\n throw new WorkboxError('single-range-only', { normalizedRangeHeader });\n }\n const rangeParts = /(\\d*)-(\\d*)/.exec(normalizedRangeHeader);\n // We need either at least one of the start or end values.\n if (!rangeParts || !(rangeParts[1] || rangeParts[2])) {\n throw new WorkboxError('invalid-range-values', { normalizedRangeHeader });\n }\n return {\n start: rangeParts[1] === '' ? undefined : Number(rangeParts[1]),\n end: rangeParts[2] === '' ? undefined : Number(rangeParts[2]),\n };\n}\nexport { parseRangeHeader };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { assert } from 'workbox-core/_private/assert.js';\nimport '../_version.js';\n/**\n * @param {Blob} blob A source blob.\n * @param {number} [start] The offset to use as the start of the\n * slice.\n * @param {number} [end] The offset to use as the end of the slice.\n * @return {Object} An object with `start` and `end` properties, reflecting\n * the effective boundaries to use given the size of the blob.\n *\n * @private\n */\nfunction calculateEffectiveBoundaries(blob, start, end) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(blob, Blob, {\n moduleName: 'workbox-range-requests',\n funcName: 'calculateEffectiveBoundaries',\n paramName: 'blob',\n });\n }\n const blobSize = blob.size;\n if ((end && end > blobSize) || (start && start < 0)) {\n throw new WorkboxError('range-not-satisfiable', {\n size: blobSize,\n end,\n start,\n });\n }\n let effectiveStart;\n let effectiveEnd;\n if (start !== undefined && end !== undefined) {\n effectiveStart = start;\n // Range values are inclusive, so add 1 to the value.\n effectiveEnd = end + 1;\n }\n else if (start !== undefined && end === undefined) {\n effectiveStart = start;\n effectiveEnd = blobSize;\n }\n else if (end !== undefined && start === undefined) {\n effectiveStart = blobSize - end;\n effectiveEnd = blobSize;\n }\n return {\n start: effectiveStart,\n end: effectiveEnd,\n };\n}\nexport { calculateEffectiveBoundaries };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { createPartialResponse } from './createPartialResponse.js';\nimport './_version.js';\n/**\n * The range request plugin makes it easy for a request with a 'Range' header to\n * be fulfilled by a cached response.\n *\n * It does this by intercepting the `cachedResponseWillBeUsed` plugin callback\n * and returning the appropriate subset of the cached response body.\n *\n * @memberof module:workbox-range-requests\n */\nclass RangeRequestsPlugin {\n constructor() {\n /**\n * @param {Object} options\n * @param {Request} options.request The original request, which may or may not\n * contain a Range: header.\n * @param {Response} options.cachedResponse The complete cached response.\n * @return {Promise<Response>} If request contains a 'Range' header, then a\n * new response with status 206 whose body is a subset of `cachedResponse` is\n * returned. Otherwise, `cachedResponse` is returned as-is.\n *\n * @private\n */\n this.cachedResponseWillBeUsed = async ({ request, cachedResponse }) => {\n // Only return a sliced response if there's something valid in the cache,\n // and there's a Range: header in the request.\n if (cachedResponse && request.headers.has('range')) {\n return await createPartialResponse(request, cachedResponse);\n }\n // If there was no Range: header, or if cachedResponse wasn't valid, just\n // pass it through as-is.\n return cachedResponse;\n };\n }\n}\nexport { RangeRequestsPlugin };\n"],"names":["self","_","e","async","createPartialResponse","request","originalResponse","status","rangeHeader","headers","get","WorkboxError","boundaries","normalizedRangeHeader","trim","toLowerCase","startsWith","includes","rangeParts","exec","start","undefined","Number","end","parseRangeHeader","originalBlob","blob","effectiveBoundaries","blobSize","size","effectiveStart","effectiveEnd","calculateEffectiveBoundaries","slicedBlob","slice","slicedBlobSize","slicedResponse","Response","statusText","set","String","error","constructor","cachedResponseWillBeUsed","cachedResponse","has"],"mappings":"sFAEA,IACIA,KAAK,iCAAmCC,IAE5C,MAAOC,IC0BPC,eAAeC,EAAsBC,EAASC,UAcN,MAA5BA,EAAiBC,cAGVD,QAELE,EAAcH,EAAQI,QAAQC,IAAI,aACnCF,QACK,IAAIG,eAAa,yBAErBC,ECpCd,SAA0BJ,SAQhBK,EAAwBL,EAAYM,OAAOC,kBAC5CF,EAAsBG,WAAW,gBAC5B,IAAIL,eAAa,qBAAsB,CAAEE,sBAAAA,OAK/CA,EAAsBI,SAAS,WACzB,IAAIN,eAAa,oBAAqB,CAAEE,sBAAAA,UAE5CK,EAAa,cAAcC,KAAKN,OAEjCK,IAAgBA,EAAW,KAAMA,EAAW,SACvC,IAAIP,eAAa,uBAAwB,CAAEE,sBAAAA,UAE9C,CACHO,MAAyB,KAAlBF,EAAW,QAAYG,EAAYC,OAAOJ,EAAW,IAC5DK,IAAuB,KAAlBL,EAAW,QAAYG,EAAYC,OAAOJ,EAAW,KDWvCM,CAAiBhB,GAC9BiB,QAAqBnB,EAAiBoB,OACtCC,EEpCd,SAAsCD,EAAMN,EAAOG,SAQzCK,EAAWF,EAAKG,QACjBN,GAAOA,EAAMK,GAAcR,GAASA,EAAQ,QACvC,IAAIT,eAAa,wBAAyB,CAC5CkB,KAAMD,EACNL,IAAAA,EACAH,MAAAA,QAGJU,EACAC,cACUV,IAAVD,QAA+BC,IAARE,GACvBO,EAAiBV,EAEjBW,EAAeR,EAAM,QAENF,IAAVD,QAA+BC,IAARE,GAC5BO,EAAiBV,EACjBW,EAAeH,QAEFP,IAARE,QAA+BF,IAAVD,IAC1BU,EAAiBF,EAAWL,EAC5BQ,EAAeH,GAEZ,CACHR,MAAOU,EACPP,IAAKQ,GFGuBC,CAA6BP,EAAcb,EAAWQ,MAAOR,EAAWW,KAC9FU,EAAaR,EAAaS,MAAMP,EAAoBP,MAAOO,EAAoBJ,KAC/EY,EAAiBF,EAAWJ,KAC5BO,EAAiB,IAAIC,SAASJ,EAAY,CAG5C1B,OAAQ,IACR+B,WAAY,kBACZ7B,QAASH,EAAiBG,iBAE9B2B,EAAe3B,QAAQ8B,IAAI,iBAAkBC,OAAOL,IACpDC,EAAe3B,QAAQ8B,IAAI,gBAAkB,SAAQZ,EAAoBP,SAASO,EAAoBJ,IAAM,KACxGE,EAAaI,MACVO,EAEX,MAAOK,UAUI,IAAIJ,SAAS,GAAI,CACpB9B,OAAQ,IACR+B,WAAY,wDGjExB,MACII,mBAYSC,yBAA2BxC,OAASE,QAAAA,EAASuC,eAAAA,KAG1CA,GAAkBvC,EAAQI,QAAQoC,IAAI,eACzBzC,EAAsBC,EAASuC,GAIzCA"}
@@ -1,923 +1,923 @@
1
- this.workbox = this.workbox || {};
2
- this.workbox.routing = (function (exports, assert_js, logger_js, WorkboxError_js, getFriendlyURL_js) {
3
- 'use strict';
4
-
5
- try {
6
- self['workbox:routing:5.0.0'] && _();
7
- } catch (e) {}
8
-
9
- /*
10
- Copyright 2018 Google LLC
11
-
12
- Use of this source code is governed by an MIT-style
13
- license that can be found in the LICENSE file or at
14
- https://opensource.org/licenses/MIT.
15
- */
16
- /**
17
- * The default HTTP method, 'GET', used when there's no specific method
18
- * configured for a route.
19
- *
20
- * @type {string}
21
- *
22
- * @private
23
- */
24
-
25
- const defaultMethod = 'GET';
26
- /**
27
- * The list of valid HTTP methods associated with requests that could be routed.
28
- *
29
- * @type {Array<string>}
30
- *
31
- * @private
32
- */
33
-
34
- const validMethods = ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT'];
35
-
36
- /*
37
- Copyright 2018 Google LLC
38
-
39
- Use of this source code is governed by an MIT-style
40
- license that can be found in the LICENSE file or at
41
- https://opensource.org/licenses/MIT.
42
- */
43
- /**
44
- * @param {function()|Object} handler Either a function, or an object with a
45
- * 'handle' method.
46
- * @return {Object} An object with a handle method.
47
- *
48
- * @private
49
- */
50
-
51
- const normalizeHandler = handler => {
52
- if (handler && typeof handler === 'object') {
53
- {
54
- assert_js.assert.hasMethod(handler, 'handle', {
55
- moduleName: 'workbox-routing',
56
- className: 'Route',
57
- funcName: 'constructor',
58
- paramName: 'handler'
59
- });
60
- }
61
-
62
- return handler;
63
- } else {
64
- {
65
- assert_js.assert.isType(handler, 'function', {
66
- moduleName: 'workbox-routing',
67
- className: 'Route',
68
- funcName: 'constructor',
69
- paramName: 'handler'
70
- });
71
- }
72
-
73
- return {
74
- handle: handler
75
- };
76
- }
77
- };
78
-
79
- /*
80
- Copyright 2018 Google LLC
81
-
82
- Use of this source code is governed by an MIT-style
83
- license that can be found in the LICENSE file or at
84
- https://opensource.org/licenses/MIT.
85
- */
86
- /**
87
- * A `Route` consists of a pair of callback functions, "match" and "handler".
88
- * The "match" callback determine if a route should be used to "handle" a
89
- * request by returning a non-falsy value if it can. The "handler" callback
90
- * is called when there is a match and should return a Promise that resolves
91
- * to a `Response`.
92
- *
93
- * @memberof module:workbox-routing
94
- */
95
-
96
- class Route {
97
- /**
98
- * Constructor for Route class.
99
- *
100
- * @param {module:workbox-routing~matchCallback} match
101
- * A callback function that determines whether the route matches a given
102
- * `fetch` event by returning a non-falsy value.
103
- * @param {module:workbox-routing~handlerCallback} handler A callback
104
- * function that returns a Promise resolving to a Response.
105
- * @param {string} [method='GET'] The HTTP method to match the Route
106
- * against.
107
- */
108
- constructor(match, handler, method = defaultMethod) {
109
- {
110
- assert_js.assert.isType(match, 'function', {
111
- moduleName: 'workbox-routing',
112
- className: 'Route',
113
- funcName: 'constructor',
114
- paramName: 'match'
115
- });
116
-
117
- if (method) {
118
- assert_js.assert.isOneOf(method, validMethods, {
119
- paramName: 'method'
120
- });
121
- }
122
- } // These values are referenced directly by Router so cannot be
123
- // altered by minificaton.
124
-
125
-
126
- this.handler = normalizeHandler(handler);
127
- this.match = match;
128
- this.method = method;
129
- }
130
-
131
- }
132
-
133
- /*
134
- Copyright 2018 Google LLC
135
-
136
- Use of this source code is governed by an MIT-style
137
- license that can be found in the LICENSE file or at
138
- https://opensource.org/licenses/MIT.
139
- */
140
- /**
141
- * NavigationRoute makes it easy to create a
142
- * [Route]{@link module:workbox-routing.Route} that matches for browser
143
- * [navigation requests]{@link https://developers.google.com/web/fundamentals/primers/service-workers/high-performance-loading#first_what_are_navigation_requests}.
144
- *
145
- * It will only match incoming Requests whose
146
- * [`mode`]{@link https://fetch.spec.whatwg.org/#concept-request-mode}
147
- * is set to `navigate`.
148
- *
149
- * You can optionally only apply this route to a subset of navigation requests
150
- * by using one or both of the `denylist` and `allowlist` parameters.
151
- *
152
- * @memberof module:workbox-routing
153
- * @extends module:workbox-routing.Route
154
- */
155
-
156
- class NavigationRoute extends Route {
157
- /**
158
- * If both `denylist` and `allowlist` are provided, the `denylist` will
159
- * take precedence and the request will not match this route.
160
- *
161
- * The regular expressions in `allowlist` and `denylist`
162
- * are matched against the concatenated
163
- * [`pathname`]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/pathname}
164
- * and [`search`]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/search}
165
- * portions of the requested URL.
166
- *
167
- * @param {module:workbox-routing~handlerCallback} handler A callback
168
- * function that returns a Promise resulting in a Response.
169
- * @param {Object} options
170
- * @param {Array<RegExp>} [options.denylist] If any of these patterns match,
171
- * the route will not handle the request (even if a allowlist RegExp matches).
172
- * @param {Array<RegExp>} [options.allowlist=[/./]] If any of these patterns
173
- * match the URL's pathname and search parameter, the route will handle the
174
- * request (assuming the denylist doesn't match).
175
- */
176
- constructor(handler, {
177
- allowlist = [/./],
178
- denylist = []
179
- } = {}) {
180
- {
181
- assert_js.assert.isArrayOfClass(allowlist, RegExp, {
182
- moduleName: 'workbox-routing',
183
- className: 'NavigationRoute',
184
- funcName: 'constructor',
185
- paramName: 'options.allowlist'
186
- });
187
- assert_js.assert.isArrayOfClass(denylist, RegExp, {
188
- moduleName: 'workbox-routing',
189
- className: 'NavigationRoute',
190
- funcName: 'constructor',
191
- paramName: 'options.denylist'
192
- });
193
- }
194
-
195
- super(options => this._match(options), handler);
196
- this._allowlist = allowlist;
197
- this._denylist = denylist;
198
- }
199
- /**
200
- * Routes match handler.
201
- *
202
- * @param {Object} options
203
- * @param {URL} options.url
204
- * @param {Request} options.request
205
- * @return {boolean}
206
- *
207
- * @private
208
- */
209
-
210
-
211
- _match({
212
- url,
213
- request
214
- }) {
215
- if (request && request.mode !== 'navigate') {
216
- return false;
217
- }
218
-
219
- const pathnameAndSearch = url.pathname + url.search;
220
-
221
- for (const regExp of this._denylist) {
222
- if (regExp.test(pathnameAndSearch)) {
223
- {
224
- logger_js.logger.log(`The navigation route ${pathnameAndSearch} is not ` + `being used, since the URL matches this denylist pattern: ` + `${regExp}`);
225
- }
226
-
227
- return false;
228
- }
229
- }
230
-
231
- if (this._allowlist.some(regExp => regExp.test(pathnameAndSearch))) {
232
- {
233
- logger_js.logger.debug(`The navigation route ${pathnameAndSearch} ` + `is being used.`);
234
- }
235
-
236
- return true;
237
- }
238
-
239
- {
240
- logger_js.logger.log(`The navigation route ${pathnameAndSearch} is not ` + `being used, since the URL being navigated to doesn't ` + `match the allowlist.`);
241
- }
242
-
243
- return false;
244
- }
245
-
246
- }
247
-
248
- /*
249
- Copyright 2018 Google LLC
250
-
251
- Use of this source code is governed by an MIT-style
252
- license that can be found in the LICENSE file or at
253
- https://opensource.org/licenses/MIT.
254
- */
255
- /**
256
- * RegExpRoute makes it easy to create a regular expression based
257
- * [Route]{@link module:workbox-routing.Route}.
258
- *
259
- * For same-origin requests the RegExp only needs to match part of the URL. For
260
- * requests against third-party servers, you must define a RegExp that matches
261
- * the start of the URL.
262
- *
263
- * [See the module docs for info.]{@link https://developers.google.com/web/tools/workbox/modules/workbox-routing}
264
- *
265
- * @memberof module:workbox-routing
266
- * @extends module:workbox-routing.Route
267
- */
268
-
269
- class RegExpRoute extends Route {
270
- /**
271
- * If the regular expression contains
272
- * [capture groups]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#grouping-back-references},
273
- * the captured values will be passed to the
274
- * [handler's]{@link module:workbox-routing~handlerCallback} `params`
275
- * argument.
276
- *
277
- * @param {RegExp} regExp The regular expression to match against URLs.
278
- * @param {module:workbox-routing~handlerCallback} handler A callback
279
- * function that returns a Promise resulting in a Response.
280
- * @param {string} [method='GET'] The HTTP method to match the Route
281
- * against.
282
- */
283
- constructor(regExp, handler, method) {
284
- {
285
- assert_js.assert.isInstance(regExp, RegExp, {
286
- moduleName: 'workbox-routing',
287
- className: 'RegExpRoute',
288
- funcName: 'constructor',
289
- paramName: 'pattern'
290
- });
291
- }
292
-
293
- const match = ({
294
- url
295
- }) => {
296
- const result = regExp.exec(url.href); // Return immediately if there's no match.
297
-
298
- if (!result) {
299
- return;
300
- } // Require that the match start at the first character in the URL string
301
- // if it's a cross-origin request.
302
- // See https://github.com/GoogleChrome/workbox/issues/281 for the context
303
- // behind this behavior.
304
-
305
-
306
- if (url.origin !== location.origin && result.index !== 0) {
307
- {
308
- logger_js.logger.debug(`The regular expression '${regExp}' only partially matched ` + `against the cross-origin URL '${url}'. RegExpRoute's will only ` + `handle cross-origin requests if they match the entire URL.`);
309
- }
310
-
311
- return;
312
- } // If the route matches, but there aren't any capture groups defined, then
313
- // this will return [], which is truthy and therefore sufficient to
314
- // indicate a match.
315
- // If there are capture groups, then it will return their values.
316
-
317
-
318
- return result.slice(1);
319
- };
320
-
321
- super(match, handler, method);
322
- }
323
-
324
- }
325
-
326
- /*
327
- Copyright 2018 Google LLC
328
-
329
- Use of this source code is governed by an MIT-style
330
- license that can be found in the LICENSE file or at
331
- https://opensource.org/licenses/MIT.
332
- */
333
- /**
334
- * The Router can be used to process a FetchEvent through one or more
335
- * [Routes]{@link module:workbox-routing.Route} responding with a Request if
336
- * a matching route exists.
337
- *
338
- * If no route matches a given a request, the Router will use a "default"
339
- * handler if one is defined.
340
- *
341
- * Should the matching Route throw an error, the Router will use a "catch"
342
- * handler if one is defined to gracefully deal with issues and respond with a
343
- * Request.
344
- *
345
- * If a request matches multiple routes, the **earliest** registered route will
346
- * be used to respond to the request.
347
- *
348
- * @memberof module:workbox-routing
349
- */
350
-
351
- class Router {
352
- /**
353
- * Initializes a new Router.
354
- */
355
- constructor() {
356
- this._routes = new Map();
357
- }
358
- /**
359
- * @return {Map<string, Array<module:workbox-routing.Route>>} routes A `Map` of HTTP
360
- * method name ('GET', etc.) to an array of all the corresponding `Route`
361
- * instances that are registered.
362
- */
363
-
364
-
365
- get routes() {
366
- return this._routes;
367
- }
368
- /**
369
- * Adds a fetch event listener to respond to events when a route matches
370
- * the event's request.
371
- */
372
-
373
-
374
- addFetchListener() {
375
- // See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705
376
- self.addEventListener('fetch', event => {
377
- const {
378
- request
379
- } = event;
380
- const responsePromise = this.handleRequest({
381
- request,
382
- event
383
- });
384
-
385
- if (responsePromise) {
386
- event.respondWith(responsePromise);
387
- }
388
- });
389
- }
390
- /**
391
- * Adds a message event listener for URLs to cache from the window.
392
- * This is useful to cache resources loaded on the page prior to when the
393
- * service worker started controlling it.
394
- *
395
- * The format of the message data sent from the window should be as follows.
396
- * Where the `urlsToCache` array may consist of URL strings or an array of
397
- * URL string + `requestInit` object (the same as you'd pass to `fetch()`).
398
- *
399
- * ```
400
- * {
401
- * type: 'CACHE_URLS',
402
- * payload: {
403
- * urlsToCache: [
404
- * './script1.js',
405
- * './script2.js',
406
- * ['./script3.js', {mode: 'no-cors'}],
407
- * ],
408
- * },
409
- * }
410
- * ```
411
- */
412
-
413
-
414
- addCacheListener() {
415
- // See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705
416
- self.addEventListener('message', event => {
417
- if (event.data && event.data.type === 'CACHE_URLS') {
418
- const {
419
- payload
420
- } = event.data;
421
-
422
- {
423
- logger_js.logger.debug(`Caching URLs from the window`, payload.urlsToCache);
424
- }
425
-
426
- const requestPromises = Promise.all(payload.urlsToCache.map(entry => {
427
- if (typeof entry === 'string') {
428
- entry = [entry];
429
- }
430
-
431
- const request = new Request(...entry);
432
- return this.handleRequest({
433
- request
434
- }); // TODO(philipwalton): TypeScript errors without this typecast for
435
- // some reason (probably a bug). The real type here should work but
436
- // doesn't: `Array<Promise<Response> | undefined>`.
437
- })); // TypeScript
438
-
439
- event.waitUntil(requestPromises); // If a MessageChannel was used, reply to the message on success.
440
-
441
- if (event.ports && event.ports[0]) {
442
- requestPromises.then(() => event.ports[0].postMessage(true));
443
- }
444
- }
445
- });
446
- }
447
- /**
448
- * Apply the routing rules to a FetchEvent object to get a Response from an
449
- * appropriate Route's handler.
450
- *
451
- * @param {Object} options
452
- * @param {Request} options.request The request to handle (this is usually
453
- * from a fetch event, but it does not have to be).
454
- * @param {FetchEvent} [options.event] The event that triggered the request,
455
- * if applicable.
456
- * @return {Promise<Response>|undefined} A promise is returned if a
457
- * registered route can handle the request. If there is no matching
458
- * route and there's no `defaultHandler`, `undefined` is returned.
459
- */
460
-
461
-
462
- handleRequest({
463
- request,
464
- event
465
- }) {
466
- {
467
- assert_js.assert.isInstance(request, Request, {
468
- moduleName: 'workbox-routing',
469
- className: 'Router',
470
- funcName: 'handleRequest',
471
- paramName: 'options.request'
472
- });
473
- }
474
-
475
- const url = new URL(request.url, location.href);
476
-
477
- if (!url.protocol.startsWith('http')) {
478
- {
479
- logger_js.logger.debug(`Workbox Router only supports URLs that start with 'http'.`);
480
- }
481
-
482
- return;
483
- }
484
-
485
- let {
486
- params,
487
- route
488
- } = this.findMatchingRoute({
489
- url,
490
- request,
491
- event
492
- });
493
- let handler = route && route.handler;
494
- let debugMessages = [];
495
-
496
- {
497
- if (handler) {
498
- debugMessages.push([`Found a route to handle this request:`, route]);
499
-
500
- if (params) {
501
- debugMessages.push([`Passing the following params to the route's handler:`, params]);
502
- }
503
- }
504
- } // If we don't have a handler because there was no matching route, then
505
- // fall back to defaultHandler if that's defined.
506
-
507
-
508
- if (!handler && this._defaultHandler) {
509
- {
510
- debugMessages.push(`Failed to find a matching route. Falling ` + `back to the default handler.`);
511
- }
512
-
513
- handler = this._defaultHandler;
514
- }
515
-
516
- if (!handler) {
517
- {
518
- // No handler so Workbox will do nothing. If logs is set of debug
519
- // i.e. verbose, we should print out this information.
520
- logger_js.logger.debug(`No route found for: ${getFriendlyURL_js.getFriendlyURL(url)}`);
521
- }
522
-
523
- return;
524
- }
525
-
526
- {
527
- // We have a handler, meaning Workbox is going to handle the route.
528
- // print the routing details to the console.
529
- logger_js.logger.groupCollapsed(`Router is responding to: ${getFriendlyURL_js.getFriendlyURL(url)}`);
530
- debugMessages.forEach(msg => {
531
- if (Array.isArray(msg)) {
532
- logger_js.logger.log(...msg);
533
- } else {
534
- logger_js.logger.log(msg);
535
- }
536
- });
537
- logger_js.logger.groupEnd();
538
- } // Wrap in try and catch in case the handle method throws a synchronous
539
- // error. It should still callback to the catch handler.
540
-
541
-
542
- let responsePromise;
543
-
544
- try {
545
- responsePromise = handler.handle({
546
- url,
547
- request,
548
- event,
549
- params
550
- });
551
- } catch (err) {
552
- responsePromise = Promise.reject(err);
553
- }
554
-
555
- if (responsePromise instanceof Promise && this._catchHandler) {
556
- responsePromise = responsePromise.catch(err => {
557
- {
558
- // Still include URL here as it will be async from the console group
559
- // and may not make sense without the URL
560
- logger_js.logger.groupCollapsed(`Error thrown when responding to: ` + ` ${getFriendlyURL_js.getFriendlyURL(url)}. Falling back to Catch Handler.`);
561
- logger_js.logger.error(`Error thrown by:`, route);
562
- logger_js.logger.error(err);
563
- logger_js.logger.groupEnd();
564
- }
565
-
566
- return this._catchHandler.handle({
567
- url,
568
- request,
569
- event
570
- });
571
- });
572
- }
573
-
574
- return responsePromise;
575
- }
576
- /**
577
- * Checks a request and URL (and optionally an event) against the list of
578
- * registered routes, and if there's a match, returns the corresponding
579
- * route along with any params generated by the match.
580
- *
581
- * @param {Object} options
582
- * @param {URL} options.url
583
- * @param {Request} options.request The request to match.
584
- * @param {Event} [options.event] The corresponding event (unless N/A).
585
- * @return {Object} An object with `route` and `params` properties.
586
- * They are populated if a matching route was found or `undefined`
587
- * otherwise.
588
- */
589
-
590
-
591
- findMatchingRoute({
592
- url,
593
- request,
594
- event
595
- }) {
596
- {
597
- assert_js.assert.isInstance(url, URL, {
598
- moduleName: 'workbox-routing',
599
- className: 'Router',
600
- funcName: 'findMatchingRoute',
601
- paramName: 'options.url'
602
- });
603
- assert_js.assert.isInstance(request, Request, {
604
- moduleName: 'workbox-routing',
605
- className: 'Router',
606
- funcName: 'findMatchingRoute',
607
- paramName: 'options.request'
608
- });
609
- }
610
-
611
- const routes = this._routes.get(request.method) || [];
612
-
613
- for (const route of routes) {
614
- let params;
615
- let matchResult = route.match({
616
- url,
617
- request,
618
- event
619
- });
620
-
621
- if (matchResult) {
622
- // See https://github.com/GoogleChrome/workbox/issues/2079
623
- params = matchResult;
624
-
625
- if (Array.isArray(matchResult) && matchResult.length === 0) {
626
- // Instead of passing an empty array in as params, use undefined.
627
- params = undefined;
628
- } else if (matchResult.constructor === Object && Object.keys(matchResult).length === 0) {
629
- // Instead of passing an empty object in as params, use undefined.
630
- params = undefined;
631
- } else if (typeof matchResult === 'boolean') {
632
- // For the boolean value true (rather than just something truth-y),
633
- // don't set params.
634
- // See https://github.com/GoogleChrome/workbox/pull/2134#issuecomment-513924353
635
- params = undefined;
636
- } // Return early if have a match.
637
-
638
-
639
- return {
640
- route,
641
- params
642
- };
643
- }
644
- } // If no match was found above, return and empty object.
645
-
646
-
647
- return {};
648
- }
649
- /**
650
- * Define a default `handler` that's called when no routes explicitly
651
- * match the incoming request.
652
- *
653
- * Without a default handler, unmatched requests will go against the
654
- * network as if there were no service worker present.
655
- *
656
- * @param {module:workbox-routing~handlerCallback} handler A callback
657
- * function that returns a Promise resulting in a Response.
658
- */
659
-
660
-
661
- setDefaultHandler(handler) {
662
- this._defaultHandler = normalizeHandler(handler);
663
- }
664
- /**
665
- * If a Route throws an error while handling a request, this `handler`
666
- * will be called and given a chance to provide a response.
667
- *
668
- * @param {module:workbox-routing~handlerCallback} handler A callback
669
- * function that returns a Promise resulting in a Response.
670
- */
671
-
672
-
673
- setCatchHandler(handler) {
674
- this._catchHandler = normalizeHandler(handler);
675
- }
676
- /**
677
- * Registers a route with the router.
678
- *
679
- * @param {module:workbox-routing.Route} route The route to register.
680
- */
681
-
682
-
683
- registerRoute(route) {
684
- {
685
- assert_js.assert.isType(route, 'object', {
686
- moduleName: 'workbox-routing',
687
- className: 'Router',
688
- funcName: 'registerRoute',
689
- paramName: 'route'
690
- });
691
- assert_js.assert.hasMethod(route, 'match', {
692
- moduleName: 'workbox-routing',
693
- className: 'Router',
694
- funcName: 'registerRoute',
695
- paramName: 'route'
696
- });
697
- assert_js.assert.isType(route.handler, 'object', {
698
- moduleName: 'workbox-routing',
699
- className: 'Router',
700
- funcName: 'registerRoute',
701
- paramName: 'route'
702
- });
703
- assert_js.assert.hasMethod(route.handler, 'handle', {
704
- moduleName: 'workbox-routing',
705
- className: 'Router',
706
- funcName: 'registerRoute',
707
- paramName: 'route.handler'
708
- });
709
- assert_js.assert.isType(route.method, 'string', {
710
- moduleName: 'workbox-routing',
711
- className: 'Router',
712
- funcName: 'registerRoute',
713
- paramName: 'route.method'
714
- });
715
- }
716
-
717
- if (!this._routes.has(route.method)) {
718
- this._routes.set(route.method, []);
719
- } // Give precedence to all of the earlier routes by adding this additional
720
- // route to the end of the array.
721
-
722
-
723
- this._routes.get(route.method).push(route);
724
- }
725
- /**
726
- * Unregisters a route with the router.
727
- *
728
- * @param {module:workbox-routing.Route} route The route to unregister.
729
- */
730
-
731
-
732
- unregisterRoute(route) {
733
- if (!this._routes.has(route.method)) {
734
- throw new WorkboxError_js.WorkboxError('unregister-route-but-not-found-with-method', {
735
- method: route.method
736
- });
737
- }
738
-
739
- const routeIndex = this._routes.get(route.method).indexOf(route);
740
-
741
- if (routeIndex > -1) {
742
- this._routes.get(route.method).splice(routeIndex, 1);
743
- } else {
744
- throw new WorkboxError_js.WorkboxError('unregister-route-route-not-registered');
745
- }
746
- }
747
-
748
- }
749
-
750
- /*
751
- Copyright 2019 Google LLC
752
-
753
- Use of this source code is governed by an MIT-style
754
- license that can be found in the LICENSE file or at
755
- https://opensource.org/licenses/MIT.
756
- */
757
- let defaultRouter;
758
- /**
759
- * Creates a new, singleton Router instance if one does not exist. If one
760
- * does already exist, that instance is returned.
761
- *
762
- * @private
763
- * @return {Router}
764
- */
765
-
766
- const getOrCreateDefaultRouter = () => {
767
- if (!defaultRouter) {
768
- defaultRouter = new Router(); // The helpers that use the default Router assume these listeners exist.
769
-
770
- defaultRouter.addFetchListener();
771
- defaultRouter.addCacheListener();
772
- }
773
-
774
- return defaultRouter;
775
- };
776
-
777
- /*
778
- Copyright 2019 Google LLC
779
-
780
- Use of this source code is governed by an MIT-style
781
- license that can be found in the LICENSE file or at
782
- https://opensource.org/licenses/MIT.
783
- */
784
- /**
785
- * Easily register a RegExp, string, or function with a caching
786
- * strategy to a singleton Router instance.
787
- *
788
- * This method will generate a Route for you if needed and
789
- * call [registerRoute()]{@link module:workbox-routing.Router#registerRoute}.
790
- *
791
- * @param {RegExp|string|module:workbox-routing.Route~matchCallback|module:workbox-routing.Route} capture
792
- * If the capture param is a `Route`, all other arguments will be ignored.
793
- * @param {module:workbox-routing~handlerCallback} [handler] A callback
794
- * function that returns a Promise resulting in a Response. This parameter
795
- * is required if `capture` is not a `Route` object.
796
- * @param {string} [method='GET'] The HTTP method to match the Route
797
- * against.
798
- * @return {module:workbox-routing.Route} The generated `Route`(Useful for
799
- * unregistering).
800
- *
801
- * @memberof module:workbox-routing
802
- */
803
-
804
- function registerRoute(capture, handler, method) {
805
- let route;
806
-
807
- if (typeof capture === 'string') {
808
- const captureUrl = new URL(capture, location.href);
809
-
810
- {
811
- if (!(capture.startsWith('/') || capture.startsWith('http'))) {
812
- throw new WorkboxError_js.WorkboxError('invalid-string', {
813
- moduleName: 'workbox-routing',
814
- funcName: 'registerRoute',
815
- paramName: 'capture'
816
- });
817
- } // We want to check if Express-style wildcards are in the pathname only.
818
- // TODO: Remove this log message in v4.
819
-
820
-
821
- const valueToCheck = capture.startsWith('http') ? captureUrl.pathname : capture; // See https://github.com/pillarjs/path-to-regexp#parameters
822
-
823
- const wildcards = '[*:?+]';
824
-
825
- if (valueToCheck.match(new RegExp(`${wildcards}`))) {
826
- logger_js.logger.debug(`The '$capture' parameter contains an Express-style wildcard ` + `character (${wildcards}). Strings are now always interpreted as ` + `exact matches; use a RegExp for partial or wildcard matches.`);
827
- }
828
- }
829
-
830
- const matchCallback = ({
831
- url
832
- }) => {
833
- {
834
- if (url.pathname === captureUrl.pathname && url.origin !== captureUrl.origin) {
835
- logger_js.logger.debug(`${capture} only partially matches the cross-origin URL ` + `${url}. This route will only handle cross-origin requests ` + `if they match the entire URL.`);
836
- }
837
- }
838
-
839
- return url.href === captureUrl.href;
840
- }; // If `capture` is a string then `handler` and `method` must be present.
841
-
842
-
843
- route = new Route(matchCallback, handler, method);
844
- } else if (capture instanceof RegExp) {
845
- // If `capture` is a `RegExp` then `handler` and `method` must be present.
846
- route = new RegExpRoute(capture, handler, method);
847
- } else if (typeof capture === 'function') {
848
- // If `capture` is a function then `handler` and `method` must be present.
849
- route = new Route(capture, handler, method);
850
- } else if (capture instanceof Route) {
851
- route = capture;
852
- } else {
853
- throw new WorkboxError_js.WorkboxError('unsupported-route-type', {
854
- moduleName: 'workbox-routing',
855
- funcName: 'registerRoute',
856
- paramName: 'capture'
857
- });
858
- }
859
-
860
- const defaultRouter = getOrCreateDefaultRouter();
861
- defaultRouter.registerRoute(route);
862
- return route;
863
- }
864
-
865
- /*
866
- Copyright 2019 Google LLC
867
-
868
- Use of this source code is governed by an MIT-style
869
- license that can be found in the LICENSE file or at
870
- https://opensource.org/licenses/MIT.
871
- */
872
- /**
873
- * If a Route throws an error while handling a request, this `handler`
874
- * will be called and given a chance to provide a response.
875
- *
876
- * @param {module:workbox-routing~handlerCallback} handler A callback
877
- * function that returns a Promise resulting in a Response.
878
- *
879
- * @memberof module:workbox-routing
880
- */
881
-
882
- function setCatchHandler(handler) {
883
- const defaultRouter = getOrCreateDefaultRouter();
884
- defaultRouter.setCatchHandler(handler);
885
- }
886
-
887
- /*
888
- Copyright 2019 Google LLC
889
-
890
- Use of this source code is governed by an MIT-style
891
- license that can be found in the LICENSE file or at
892
- https://opensource.org/licenses/MIT.
893
- */
894
- /**
895
- * Define a default `handler` that's called when no routes explicitly
896
- * match the incoming request.
897
- *
898
- * Without a default handler, unmatched requests will go against the
899
- * network as if there were no service worker present.
900
- *
901
- * @param {module:workbox-routing~handlerCallback} handler A callback
902
- * function that returns a Promise resulting in a Response.
903
- *
904
- * @memberof module:workbox-routing
905
- */
906
-
907
- function setDefaultHandler(handler) {
908
- const defaultRouter = getOrCreateDefaultRouter();
909
- defaultRouter.setDefaultHandler(handler);
910
- }
911
-
912
- exports.NavigationRoute = NavigationRoute;
913
- exports.RegExpRoute = RegExpRoute;
914
- exports.Route = Route;
915
- exports.Router = Router;
916
- exports.registerRoute = registerRoute;
917
- exports.setCatchHandler = setCatchHandler;
918
- exports.setDefaultHandler = setDefaultHandler;
919
-
920
- return exports;
921
-
922
- }({}, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private));
923
- //# sourceMappingURL=workbox-routing.dev.js.map
1
+ this.workbox = this.workbox || {};
2
+ this.workbox.routing = (function (exports, assert_js, logger_js, WorkboxError_js, getFriendlyURL_js) {
3
+ 'use strict';
4
+
5
+ try {
6
+ self['workbox:routing:5.1.1'] && _();
7
+ } catch (e) {}
8
+
9
+ /*
10
+ Copyright 2018 Google LLC
11
+
12
+ Use of this source code is governed by an MIT-style
13
+ license that can be found in the LICENSE file or at
14
+ https://opensource.org/licenses/MIT.
15
+ */
16
+ /**
17
+ * The default HTTP method, 'GET', used when there's no specific method
18
+ * configured for a route.
19
+ *
20
+ * @type {string}
21
+ *
22
+ * @private
23
+ */
24
+
25
+ const defaultMethod = 'GET';
26
+ /**
27
+ * The list of valid HTTP methods associated with requests that could be routed.
28
+ *
29
+ * @type {Array<string>}
30
+ *
31
+ * @private
32
+ */
33
+
34
+ const validMethods = ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT'];
35
+
36
+ /*
37
+ Copyright 2018 Google LLC
38
+
39
+ Use of this source code is governed by an MIT-style
40
+ license that can be found in the LICENSE file or at
41
+ https://opensource.org/licenses/MIT.
42
+ */
43
+ /**
44
+ * @param {function()|Object} handler Either a function, or an object with a
45
+ * 'handle' method.
46
+ * @return {Object} An object with a handle method.
47
+ *
48
+ * @private
49
+ */
50
+
51
+ const normalizeHandler = handler => {
52
+ if (handler && typeof handler === 'object') {
53
+ {
54
+ assert_js.assert.hasMethod(handler, 'handle', {
55
+ moduleName: 'workbox-routing',
56
+ className: 'Route',
57
+ funcName: 'constructor',
58
+ paramName: 'handler'
59
+ });
60
+ }
61
+
62
+ return handler;
63
+ } else {
64
+ {
65
+ assert_js.assert.isType(handler, 'function', {
66
+ moduleName: 'workbox-routing',
67
+ className: 'Route',
68
+ funcName: 'constructor',
69
+ paramName: 'handler'
70
+ });
71
+ }
72
+
73
+ return {
74
+ handle: handler
75
+ };
76
+ }
77
+ };
78
+
79
+ /*
80
+ Copyright 2018 Google LLC
81
+
82
+ Use of this source code is governed by an MIT-style
83
+ license that can be found in the LICENSE file or at
84
+ https://opensource.org/licenses/MIT.
85
+ */
86
+ /**
87
+ * A `Route` consists of a pair of callback functions, "match" and "handler".
88
+ * The "match" callback determine if a route should be used to "handle" a
89
+ * request by returning a non-falsy value if it can. The "handler" callback
90
+ * is called when there is a match and should return a Promise that resolves
91
+ * to a `Response`.
92
+ *
93
+ * @memberof module:workbox-routing
94
+ */
95
+
96
+ class Route {
97
+ /**
98
+ * Constructor for Route class.
99
+ *
100
+ * @param {module:workbox-routing~matchCallback} match
101
+ * A callback function that determines whether the route matches a given
102
+ * `fetch` event by returning a non-falsy value.
103
+ * @param {module:workbox-routing~handlerCallback} handler A callback
104
+ * function that returns a Promise resolving to a Response.
105
+ * @param {string} [method='GET'] The HTTP method to match the Route
106
+ * against.
107
+ */
108
+ constructor(match, handler, method = defaultMethod) {
109
+ {
110
+ assert_js.assert.isType(match, 'function', {
111
+ moduleName: 'workbox-routing',
112
+ className: 'Route',
113
+ funcName: 'constructor',
114
+ paramName: 'match'
115
+ });
116
+
117
+ if (method) {
118
+ assert_js.assert.isOneOf(method, validMethods, {
119
+ paramName: 'method'
120
+ });
121
+ }
122
+ } // These values are referenced directly by Router so cannot be
123
+ // altered by minificaton.
124
+
125
+
126
+ this.handler = normalizeHandler(handler);
127
+ this.match = match;
128
+ this.method = method;
129
+ }
130
+
131
+ }
132
+
133
+ /*
134
+ Copyright 2018 Google LLC
135
+
136
+ Use of this source code is governed by an MIT-style
137
+ license that can be found in the LICENSE file or at
138
+ https://opensource.org/licenses/MIT.
139
+ */
140
+ /**
141
+ * NavigationRoute makes it easy to create a
142
+ * [Route]{@link module:workbox-routing.Route} that matches for browser
143
+ * [navigation requests]{@link https://developers.google.com/web/fundamentals/primers/service-workers/high-performance-loading#first_what_are_navigation_requests}.
144
+ *
145
+ * It will only match incoming Requests whose
146
+ * [`mode`]{@link https://fetch.spec.whatwg.org/#concept-request-mode}
147
+ * is set to `navigate`.
148
+ *
149
+ * You can optionally only apply this route to a subset of navigation requests
150
+ * by using one or both of the `denylist` and `allowlist` parameters.
151
+ *
152
+ * @memberof module:workbox-routing
153
+ * @extends module:workbox-routing.Route
154
+ */
155
+
156
+ class NavigationRoute extends Route {
157
+ /**
158
+ * If both `denylist` and `allowlist` are provided, the `denylist` will
159
+ * take precedence and the request will not match this route.
160
+ *
161
+ * The regular expressions in `allowlist` and `denylist`
162
+ * are matched against the concatenated
163
+ * [`pathname`]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/pathname}
164
+ * and [`search`]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/search}
165
+ * portions of the requested URL.
166
+ *
167
+ * @param {module:workbox-routing~handlerCallback} handler A callback
168
+ * function that returns a Promise resulting in a Response.
169
+ * @param {Object} options
170
+ * @param {Array<RegExp>} [options.denylist] If any of these patterns match,
171
+ * the route will not handle the request (even if a allowlist RegExp matches).
172
+ * @param {Array<RegExp>} [options.allowlist=[/./]] If any of these patterns
173
+ * match the URL's pathname and search parameter, the route will handle the
174
+ * request (assuming the denylist doesn't match).
175
+ */
176
+ constructor(handler, {
177
+ allowlist = [/./],
178
+ denylist = []
179
+ } = {}) {
180
+ {
181
+ assert_js.assert.isArrayOfClass(allowlist, RegExp, {
182
+ moduleName: 'workbox-routing',
183
+ className: 'NavigationRoute',
184
+ funcName: 'constructor',
185
+ paramName: 'options.allowlist'
186
+ });
187
+ assert_js.assert.isArrayOfClass(denylist, RegExp, {
188
+ moduleName: 'workbox-routing',
189
+ className: 'NavigationRoute',
190
+ funcName: 'constructor',
191
+ paramName: 'options.denylist'
192
+ });
193
+ }
194
+
195
+ super(options => this._match(options), handler);
196
+ this._allowlist = allowlist;
197
+ this._denylist = denylist;
198
+ }
199
+ /**
200
+ * Routes match handler.
201
+ *
202
+ * @param {Object} options
203
+ * @param {URL} options.url
204
+ * @param {Request} options.request
205
+ * @return {boolean}
206
+ *
207
+ * @private
208
+ */
209
+
210
+
211
+ _match({
212
+ url,
213
+ request
214
+ }) {
215
+ if (request && request.mode !== 'navigate') {
216
+ return false;
217
+ }
218
+
219
+ const pathnameAndSearch = url.pathname + url.search;
220
+
221
+ for (const regExp of this._denylist) {
222
+ if (regExp.test(pathnameAndSearch)) {
223
+ {
224
+ logger_js.logger.log(`The navigation route ${pathnameAndSearch} is not ` + `being used, since the URL matches this denylist pattern: ` + `${regExp}`);
225
+ }
226
+
227
+ return false;
228
+ }
229
+ }
230
+
231
+ if (this._allowlist.some(regExp => regExp.test(pathnameAndSearch))) {
232
+ {
233
+ logger_js.logger.debug(`The navigation route ${pathnameAndSearch} ` + `is being used.`);
234
+ }
235
+
236
+ return true;
237
+ }
238
+
239
+ {
240
+ logger_js.logger.log(`The navigation route ${pathnameAndSearch} is not ` + `being used, since the URL being navigated to doesn't ` + `match the allowlist.`);
241
+ }
242
+
243
+ return false;
244
+ }
245
+
246
+ }
247
+
248
+ /*
249
+ Copyright 2018 Google LLC
250
+
251
+ Use of this source code is governed by an MIT-style
252
+ license that can be found in the LICENSE file or at
253
+ https://opensource.org/licenses/MIT.
254
+ */
255
+ /**
256
+ * RegExpRoute makes it easy to create a regular expression based
257
+ * [Route]{@link module:workbox-routing.Route}.
258
+ *
259
+ * For same-origin requests the RegExp only needs to match part of the URL. For
260
+ * requests against third-party servers, you must define a RegExp that matches
261
+ * the start of the URL.
262
+ *
263
+ * [See the module docs for info.]{@link https://developers.google.com/web/tools/workbox/modules/workbox-routing}
264
+ *
265
+ * @memberof module:workbox-routing
266
+ * @extends module:workbox-routing.Route
267
+ */
268
+
269
+ class RegExpRoute extends Route {
270
+ /**
271
+ * If the regular expression contains
272
+ * [capture groups]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#grouping-back-references},
273
+ * the captured values will be passed to the
274
+ * [handler's]{@link module:workbox-routing~handlerCallback} `params`
275
+ * argument.
276
+ *
277
+ * @param {RegExp} regExp The regular expression to match against URLs.
278
+ * @param {module:workbox-routing~handlerCallback} handler A callback
279
+ * function that returns a Promise resulting in a Response.
280
+ * @param {string} [method='GET'] The HTTP method to match the Route
281
+ * against.
282
+ */
283
+ constructor(regExp, handler, method) {
284
+ {
285
+ assert_js.assert.isInstance(regExp, RegExp, {
286
+ moduleName: 'workbox-routing',
287
+ className: 'RegExpRoute',
288
+ funcName: 'constructor',
289
+ paramName: 'pattern'
290
+ });
291
+ }
292
+
293
+ const match = ({
294
+ url
295
+ }) => {
296
+ const result = regExp.exec(url.href); // Return immediately if there's no match.
297
+
298
+ if (!result) {
299
+ return;
300
+ } // Require that the match start at the first character in the URL string
301
+ // if it's a cross-origin request.
302
+ // See https://github.com/GoogleChrome/workbox/issues/281 for the context
303
+ // behind this behavior.
304
+
305
+
306
+ if (url.origin !== location.origin && result.index !== 0) {
307
+ {
308
+ logger_js.logger.debug(`The regular expression '${regExp}' only partially matched ` + `against the cross-origin URL '${url}'. RegExpRoute's will only ` + `handle cross-origin requests if they match the entire URL.`);
309
+ }
310
+
311
+ return;
312
+ } // If the route matches, but there aren't any capture groups defined, then
313
+ // this will return [], which is truthy and therefore sufficient to
314
+ // indicate a match.
315
+ // If there are capture groups, then it will return their values.
316
+
317
+
318
+ return result.slice(1);
319
+ };
320
+
321
+ super(match, handler, method);
322
+ }
323
+
324
+ }
325
+
326
+ /*
327
+ Copyright 2018 Google LLC
328
+
329
+ Use of this source code is governed by an MIT-style
330
+ license that can be found in the LICENSE file or at
331
+ https://opensource.org/licenses/MIT.
332
+ */
333
+ /**
334
+ * The Router can be used to process a FetchEvent through one or more
335
+ * [Routes]{@link module:workbox-routing.Route} responding with a Request if
336
+ * a matching route exists.
337
+ *
338
+ * If no route matches a given a request, the Router will use a "default"
339
+ * handler if one is defined.
340
+ *
341
+ * Should the matching Route throw an error, the Router will use a "catch"
342
+ * handler if one is defined to gracefully deal with issues and respond with a
343
+ * Request.
344
+ *
345
+ * If a request matches multiple routes, the **earliest** registered route will
346
+ * be used to respond to the request.
347
+ *
348
+ * @memberof module:workbox-routing
349
+ */
350
+
351
+ class Router {
352
+ /**
353
+ * Initializes a new Router.
354
+ */
355
+ constructor() {
356
+ this._routes = new Map();
357
+ }
358
+ /**
359
+ * @return {Map<string, Array<module:workbox-routing.Route>>} routes A `Map` of HTTP
360
+ * method name ('GET', etc.) to an array of all the corresponding `Route`
361
+ * instances that are registered.
362
+ */
363
+
364
+
365
+ get routes() {
366
+ return this._routes;
367
+ }
368
+ /**
369
+ * Adds a fetch event listener to respond to events when a route matches
370
+ * the event's request.
371
+ */
372
+
373
+
374
+ addFetchListener() {
375
+ // See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705
376
+ self.addEventListener('fetch', event => {
377
+ const {
378
+ request
379
+ } = event;
380
+ const responsePromise = this.handleRequest({
381
+ request,
382
+ event
383
+ });
384
+
385
+ if (responsePromise) {
386
+ event.respondWith(responsePromise);
387
+ }
388
+ });
389
+ }
390
+ /**
391
+ * Adds a message event listener for URLs to cache from the window.
392
+ * This is useful to cache resources loaded on the page prior to when the
393
+ * service worker started controlling it.
394
+ *
395
+ * The format of the message data sent from the window should be as follows.
396
+ * Where the `urlsToCache` array may consist of URL strings or an array of
397
+ * URL string + `requestInit` object (the same as you'd pass to `fetch()`).
398
+ *
399
+ * ```
400
+ * {
401
+ * type: 'CACHE_URLS',
402
+ * payload: {
403
+ * urlsToCache: [
404
+ * './script1.js',
405
+ * './script2.js',
406
+ * ['./script3.js', {mode: 'no-cors'}],
407
+ * ],
408
+ * },
409
+ * }
410
+ * ```
411
+ */
412
+
413
+
414
+ addCacheListener() {
415
+ // See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705
416
+ self.addEventListener('message', event => {
417
+ if (event.data && event.data.type === 'CACHE_URLS') {
418
+ const {
419
+ payload
420
+ } = event.data;
421
+
422
+ {
423
+ logger_js.logger.debug(`Caching URLs from the window`, payload.urlsToCache);
424
+ }
425
+
426
+ const requestPromises = Promise.all(payload.urlsToCache.map(entry => {
427
+ if (typeof entry === 'string') {
428
+ entry = [entry];
429
+ }
430
+
431
+ const request = new Request(...entry);
432
+ return this.handleRequest({
433
+ request
434
+ }); // TODO(philipwalton): TypeScript errors without this typecast for
435
+ // some reason (probably a bug). The real type here should work but
436
+ // doesn't: `Array<Promise<Response> | undefined>`.
437
+ })); // TypeScript
438
+
439
+ event.waitUntil(requestPromises); // If a MessageChannel was used, reply to the message on success.
440
+
441
+ if (event.ports && event.ports[0]) {
442
+ requestPromises.then(() => event.ports[0].postMessage(true));
443
+ }
444
+ }
445
+ });
446
+ }
447
+ /**
448
+ * Apply the routing rules to a FetchEvent object to get a Response from an
449
+ * appropriate Route's handler.
450
+ *
451
+ * @param {Object} options
452
+ * @param {Request} options.request The request to handle (this is usually
453
+ * from a fetch event, but it does not have to be).
454
+ * @param {FetchEvent} [options.event] The event that triggered the request,
455
+ * if applicable.
456
+ * @return {Promise<Response>|undefined} A promise is returned if a
457
+ * registered route can handle the request. If there is no matching
458
+ * route and there's no `defaultHandler`, `undefined` is returned.
459
+ */
460
+
461
+
462
+ handleRequest({
463
+ request,
464
+ event
465
+ }) {
466
+ {
467
+ assert_js.assert.isInstance(request, Request, {
468
+ moduleName: 'workbox-routing',
469
+ className: 'Router',
470
+ funcName: 'handleRequest',
471
+ paramName: 'options.request'
472
+ });
473
+ }
474
+
475
+ const url = new URL(request.url, location.href);
476
+
477
+ if (!url.protocol.startsWith('http')) {
478
+ {
479
+ logger_js.logger.debug(`Workbox Router only supports URLs that start with 'http'.`);
480
+ }
481
+
482
+ return;
483
+ }
484
+
485
+ const {
486
+ params,
487
+ route
488
+ } = this.findMatchingRoute({
489
+ url,
490
+ request,
491
+ event
492
+ });
493
+ let handler = route && route.handler;
494
+ const debugMessages = [];
495
+
496
+ {
497
+ if (handler) {
498
+ debugMessages.push([`Found a route to handle this request:`, route]);
499
+
500
+ if (params) {
501
+ debugMessages.push([`Passing the following params to the route's handler:`, params]);
502
+ }
503
+ }
504
+ } // If we don't have a handler because there was no matching route, then
505
+ // fall back to defaultHandler if that's defined.
506
+
507
+
508
+ if (!handler && this._defaultHandler) {
509
+ {
510
+ debugMessages.push(`Failed to find a matching route. Falling ` + `back to the default handler.`);
511
+ }
512
+
513
+ handler = this._defaultHandler;
514
+ }
515
+
516
+ if (!handler) {
517
+ {
518
+ // No handler so Workbox will do nothing. If logs is set of debug
519
+ // i.e. verbose, we should print out this information.
520
+ logger_js.logger.debug(`No route found for: ${getFriendlyURL_js.getFriendlyURL(url)}`);
521
+ }
522
+
523
+ return;
524
+ }
525
+
526
+ {
527
+ // We have a handler, meaning Workbox is going to handle the route.
528
+ // print the routing details to the console.
529
+ logger_js.logger.groupCollapsed(`Router is responding to: ${getFriendlyURL_js.getFriendlyURL(url)}`);
530
+ debugMessages.forEach(msg => {
531
+ if (Array.isArray(msg)) {
532
+ logger_js.logger.log(...msg);
533
+ } else {
534
+ logger_js.logger.log(msg);
535
+ }
536
+ });
537
+ logger_js.logger.groupEnd();
538
+ } // Wrap in try and catch in case the handle method throws a synchronous
539
+ // error. It should still callback to the catch handler.
540
+
541
+
542
+ let responsePromise;
543
+
544
+ try {
545
+ responsePromise = handler.handle({
546
+ url,
547
+ request,
548
+ event,
549
+ params
550
+ });
551
+ } catch (err) {
552
+ responsePromise = Promise.reject(err);
553
+ }
554
+
555
+ if (responsePromise instanceof Promise && this._catchHandler) {
556
+ responsePromise = responsePromise.catch(err => {
557
+ {
558
+ // Still include URL here as it will be async from the console group
559
+ // and may not make sense without the URL
560
+ logger_js.logger.groupCollapsed(`Error thrown when responding to: ` + ` ${getFriendlyURL_js.getFriendlyURL(url)}. Falling back to Catch Handler.`);
561
+ logger_js.logger.error(`Error thrown by:`, route);
562
+ logger_js.logger.error(err);
563
+ logger_js.logger.groupEnd();
564
+ }
565
+
566
+ return this._catchHandler.handle({
567
+ url,
568
+ request,
569
+ event
570
+ });
571
+ });
572
+ }
573
+
574
+ return responsePromise;
575
+ }
576
+ /**
577
+ * Checks a request and URL (and optionally an event) against the list of
578
+ * registered routes, and if there's a match, returns the corresponding
579
+ * route along with any params generated by the match.
580
+ *
581
+ * @param {Object} options
582
+ * @param {URL} options.url
583
+ * @param {Request} options.request The request to match.
584
+ * @param {Event} [options.event] The corresponding event (unless N/A).
585
+ * @return {Object} An object with `route` and `params` properties.
586
+ * They are populated if a matching route was found or `undefined`
587
+ * otherwise.
588
+ */
589
+
590
+
591
+ findMatchingRoute({
592
+ url,
593
+ request,
594
+ event
595
+ }) {
596
+ {
597
+ assert_js.assert.isInstance(url, URL, {
598
+ moduleName: 'workbox-routing',
599
+ className: 'Router',
600
+ funcName: 'findMatchingRoute',
601
+ paramName: 'options.url'
602
+ });
603
+ assert_js.assert.isInstance(request, Request, {
604
+ moduleName: 'workbox-routing',
605
+ className: 'Router',
606
+ funcName: 'findMatchingRoute',
607
+ paramName: 'options.request'
608
+ });
609
+ }
610
+
611
+ const routes = this._routes.get(request.method) || [];
612
+
613
+ for (const route of routes) {
614
+ let params;
615
+ const matchResult = route.match({
616
+ url,
617
+ request,
618
+ event
619
+ });
620
+
621
+ if (matchResult) {
622
+ // See https://github.com/GoogleChrome/workbox/issues/2079
623
+ params = matchResult;
624
+
625
+ if (Array.isArray(matchResult) && matchResult.length === 0) {
626
+ // Instead of passing an empty array in as params, use undefined.
627
+ params = undefined;
628
+ } else if (matchResult.constructor === Object && Object.keys(matchResult).length === 0) {
629
+ // Instead of passing an empty object in as params, use undefined.
630
+ params = undefined;
631
+ } else if (typeof matchResult === 'boolean') {
632
+ // For the boolean value true (rather than just something truth-y),
633
+ // don't set params.
634
+ // See https://github.com/GoogleChrome/workbox/pull/2134#issuecomment-513924353
635
+ params = undefined;
636
+ } // Return early if have a match.
637
+
638
+
639
+ return {
640
+ route,
641
+ params
642
+ };
643
+ }
644
+ } // If no match was found above, return and empty object.
645
+
646
+
647
+ return {};
648
+ }
649
+ /**
650
+ * Define a default `handler` that's called when no routes explicitly
651
+ * match the incoming request.
652
+ *
653
+ * Without a default handler, unmatched requests will go against the
654
+ * network as if there were no service worker present.
655
+ *
656
+ * @param {module:workbox-routing~handlerCallback} handler A callback
657
+ * function that returns a Promise resulting in a Response.
658
+ */
659
+
660
+
661
+ setDefaultHandler(handler) {
662
+ this._defaultHandler = normalizeHandler(handler);
663
+ }
664
+ /**
665
+ * If a Route throws an error while handling a request, this `handler`
666
+ * will be called and given a chance to provide a response.
667
+ *
668
+ * @param {module:workbox-routing~handlerCallback} handler A callback
669
+ * function that returns a Promise resulting in a Response.
670
+ */
671
+
672
+
673
+ setCatchHandler(handler) {
674
+ this._catchHandler = normalizeHandler(handler);
675
+ }
676
+ /**
677
+ * Registers a route with the router.
678
+ *
679
+ * @param {module:workbox-routing.Route} route The route to register.
680
+ */
681
+
682
+
683
+ registerRoute(route) {
684
+ {
685
+ assert_js.assert.isType(route, 'object', {
686
+ moduleName: 'workbox-routing',
687
+ className: 'Router',
688
+ funcName: 'registerRoute',
689
+ paramName: 'route'
690
+ });
691
+ assert_js.assert.hasMethod(route, 'match', {
692
+ moduleName: 'workbox-routing',
693
+ className: 'Router',
694
+ funcName: 'registerRoute',
695
+ paramName: 'route'
696
+ });
697
+ assert_js.assert.isType(route.handler, 'object', {
698
+ moduleName: 'workbox-routing',
699
+ className: 'Router',
700
+ funcName: 'registerRoute',
701
+ paramName: 'route'
702
+ });
703
+ assert_js.assert.hasMethod(route.handler, 'handle', {
704
+ moduleName: 'workbox-routing',
705
+ className: 'Router',
706
+ funcName: 'registerRoute',
707
+ paramName: 'route.handler'
708
+ });
709
+ assert_js.assert.isType(route.method, 'string', {
710
+ moduleName: 'workbox-routing',
711
+ className: 'Router',
712
+ funcName: 'registerRoute',
713
+ paramName: 'route.method'
714
+ });
715
+ }
716
+
717
+ if (!this._routes.has(route.method)) {
718
+ this._routes.set(route.method, []);
719
+ } // Give precedence to all of the earlier routes by adding this additional
720
+ // route to the end of the array.
721
+
722
+
723
+ this._routes.get(route.method).push(route);
724
+ }
725
+ /**
726
+ * Unregisters a route with the router.
727
+ *
728
+ * @param {module:workbox-routing.Route} route The route to unregister.
729
+ */
730
+
731
+
732
+ unregisterRoute(route) {
733
+ if (!this._routes.has(route.method)) {
734
+ throw new WorkboxError_js.WorkboxError('unregister-route-but-not-found-with-method', {
735
+ method: route.method
736
+ });
737
+ }
738
+
739
+ const routeIndex = this._routes.get(route.method).indexOf(route);
740
+
741
+ if (routeIndex > -1) {
742
+ this._routes.get(route.method).splice(routeIndex, 1);
743
+ } else {
744
+ throw new WorkboxError_js.WorkboxError('unregister-route-route-not-registered');
745
+ }
746
+ }
747
+
748
+ }
749
+
750
+ /*
751
+ Copyright 2019 Google LLC
752
+
753
+ Use of this source code is governed by an MIT-style
754
+ license that can be found in the LICENSE file or at
755
+ https://opensource.org/licenses/MIT.
756
+ */
757
+ let defaultRouter;
758
+ /**
759
+ * Creates a new, singleton Router instance if one does not exist. If one
760
+ * does already exist, that instance is returned.
761
+ *
762
+ * @private
763
+ * @return {Router}
764
+ */
765
+
766
+ const getOrCreateDefaultRouter = () => {
767
+ if (!defaultRouter) {
768
+ defaultRouter = new Router(); // The helpers that use the default Router assume these listeners exist.
769
+
770
+ defaultRouter.addFetchListener();
771
+ defaultRouter.addCacheListener();
772
+ }
773
+
774
+ return defaultRouter;
775
+ };
776
+
777
+ /*
778
+ Copyright 2019 Google LLC
779
+
780
+ Use of this source code is governed by an MIT-style
781
+ license that can be found in the LICENSE file or at
782
+ https://opensource.org/licenses/MIT.
783
+ */
784
+ /**
785
+ * Easily register a RegExp, string, or function with a caching
786
+ * strategy to a singleton Router instance.
787
+ *
788
+ * This method will generate a Route for you if needed and
789
+ * call [registerRoute()]{@link module:workbox-routing.Router#registerRoute}.
790
+ *
791
+ * @param {RegExp|string|module:workbox-routing.Route~matchCallback|module:workbox-routing.Route} capture
792
+ * If the capture param is a `Route`, all other arguments will be ignored.
793
+ * @param {module:workbox-routing~handlerCallback} [handler] A callback
794
+ * function that returns a Promise resulting in a Response. This parameter
795
+ * is required if `capture` is not a `Route` object.
796
+ * @param {string} [method='GET'] The HTTP method to match the Route
797
+ * against.
798
+ * @return {module:workbox-routing.Route} The generated `Route`(Useful for
799
+ * unregistering).
800
+ *
801
+ * @memberof module:workbox-routing
802
+ */
803
+
804
+ function registerRoute(capture, handler, method) {
805
+ let route;
806
+
807
+ if (typeof capture === 'string') {
808
+ const captureUrl = new URL(capture, location.href);
809
+
810
+ {
811
+ if (!(capture.startsWith('/') || capture.startsWith('http'))) {
812
+ throw new WorkboxError_js.WorkboxError('invalid-string', {
813
+ moduleName: 'workbox-routing',
814
+ funcName: 'registerRoute',
815
+ paramName: 'capture'
816
+ });
817
+ } // We want to check if Express-style wildcards are in the pathname only.
818
+ // TODO: Remove this log message in v4.
819
+
820
+
821
+ const valueToCheck = capture.startsWith('http') ? captureUrl.pathname : capture; // See https://github.com/pillarjs/path-to-regexp#parameters
822
+
823
+ const wildcards = '[*:?+]';
824
+
825
+ if (new RegExp(`${wildcards}`).exec(valueToCheck)) {
826
+ logger_js.logger.debug(`The '$capture' parameter contains an Express-style wildcard ` + `character (${wildcards}). Strings are now always interpreted as ` + `exact matches; use a RegExp for partial or wildcard matches.`);
827
+ }
828
+ }
829
+
830
+ const matchCallback = ({
831
+ url
832
+ }) => {
833
+ {
834
+ if (url.pathname === captureUrl.pathname && url.origin !== captureUrl.origin) {
835
+ logger_js.logger.debug(`${capture} only partially matches the cross-origin URL ` + `${url}. This route will only handle cross-origin requests ` + `if they match the entire URL.`);
836
+ }
837
+ }
838
+
839
+ return url.href === captureUrl.href;
840
+ }; // If `capture` is a string then `handler` and `method` must be present.
841
+
842
+
843
+ route = new Route(matchCallback, handler, method);
844
+ } else if (capture instanceof RegExp) {
845
+ // If `capture` is a `RegExp` then `handler` and `method` must be present.
846
+ route = new RegExpRoute(capture, handler, method);
847
+ } else if (typeof capture === 'function') {
848
+ // If `capture` is a function then `handler` and `method` must be present.
849
+ route = new Route(capture, handler, method);
850
+ } else if (capture instanceof Route) {
851
+ route = capture;
852
+ } else {
853
+ throw new WorkboxError_js.WorkboxError('unsupported-route-type', {
854
+ moduleName: 'workbox-routing',
855
+ funcName: 'registerRoute',
856
+ paramName: 'capture'
857
+ });
858
+ }
859
+
860
+ const defaultRouter = getOrCreateDefaultRouter();
861
+ defaultRouter.registerRoute(route);
862
+ return route;
863
+ }
864
+
865
+ /*
866
+ Copyright 2019 Google LLC
867
+
868
+ Use of this source code is governed by an MIT-style
869
+ license that can be found in the LICENSE file or at
870
+ https://opensource.org/licenses/MIT.
871
+ */
872
+ /**
873
+ * If a Route throws an error while handling a request, this `handler`
874
+ * will be called and given a chance to provide a response.
875
+ *
876
+ * @param {module:workbox-routing~handlerCallback} handler A callback
877
+ * function that returns a Promise resulting in a Response.
878
+ *
879
+ * @memberof module:workbox-routing
880
+ */
881
+
882
+ function setCatchHandler(handler) {
883
+ const defaultRouter = getOrCreateDefaultRouter();
884
+ defaultRouter.setCatchHandler(handler);
885
+ }
886
+
887
+ /*
888
+ Copyright 2019 Google LLC
889
+
890
+ Use of this source code is governed by an MIT-style
891
+ license that can be found in the LICENSE file or at
892
+ https://opensource.org/licenses/MIT.
893
+ */
894
+ /**
895
+ * Define a default `handler` that's called when no routes explicitly
896
+ * match the incoming request.
897
+ *
898
+ * Without a default handler, unmatched requests will go against the
899
+ * network as if there were no service worker present.
900
+ *
901
+ * @param {module:workbox-routing~handlerCallback} handler A callback
902
+ * function that returns a Promise resulting in a Response.
903
+ *
904
+ * @memberof module:workbox-routing
905
+ */
906
+
907
+ function setDefaultHandler(handler) {
908
+ const defaultRouter = getOrCreateDefaultRouter();
909
+ defaultRouter.setDefaultHandler(handler);
910
+ }
911
+
912
+ exports.NavigationRoute = NavigationRoute;
913
+ exports.RegExpRoute = RegExpRoute;
914
+ exports.Route = Route;
915
+ exports.Router = Router;
916
+ exports.registerRoute = registerRoute;
917
+ exports.setCatchHandler = setCatchHandler;
918
+ exports.setDefaultHandler = setDefaultHandler;
919
+
920
+ return exports;
921
+
922
+ }({}, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private));
923
+ //# sourceMappingURL=workbox-routing.dev.js.map