@angular/service-worker
Version:
Angular - service worker tooling!
41 lines • 7.14 kB
JavaScript
/**
* @license Angular v7.0.2
* (c) 2010-2018 Google, Inc. https://angular.io/
* License: MIT
*/
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define("@angular/service-worker/config",["exports"],r):r((e.ng=e.ng||{},e.ng.serviceWorker=e.ng.serviceWorker||{},e.ng.serviceWorker.config={}))}(this,function(e){"use strict";function r(e,r,t,n){return new(t||(t=Promise))(function(o,i){function s(e){try{u(n.next(e))}catch(e){i(e)}}function a(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){e.done?o(e.value):new t(function(r){r(e.value)}).then(s,a)}u((n=n.apply(e,r||[])).next())})}function t(e,r){var t,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function u(i){if(t)throw new TypeError("Generator is already executing.");for(;s;)try{if(t=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=r.call(e,s)}catch(e){i=[6,e],n=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function n(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,o,i=t.call(e),s=[];try{for(;(void 0===r||r-- >0)&&!(n=i.next()).done;)s.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(t=i.return)&&t.call(i)}finally{if(o)throw o.error}}return s}function o(){for(var e=[],r=0;r<arguments.length;r++)e=e.concat(n(arguments[r]));return e}
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/var i=/([0-9]+[^0-9]+)/g,s=/^([0-9]+)([dhmsu]+)$/;function a(e){for(var r,t=[];null!==(r=i.exec(e));)t.push(r[0]);return t.map(function(e){var r=s.exec(e);if(null===r)throw new Error("Not a valid duration: "+e);var t=0;switch(r[2]){case"d":t=864e5;break;case"h":t=36e5;break;case"m":t=6e4;break;case"s":t=1e3;break;case"u":t=1;break;default:throw new Error("Not a valid duration unit: "+r[2])}return parseInt(r[1])*t}).reduce(function(e,r){return e+r},0)}
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/var u="(?:.+\\/)?",c=[{replace:/\./g,with:"\\."},{replace:/\+/g,with:"\\+"},{replace:/\*/g,with:"[^/]*"}],f=o(c,[{replace:/\?/g,with:"[^/]"}]),l=o(c,[{replace:/\?/g,with:"\\?"}]);function p(e,r){void 0===r&&(r=!1);for(var t=r?l:f,n=e.split("/").reverse(),o="";n.length>0;){var i=n.pop();"**"===i?o+=n.length>0?u:".*":(o+=t.reduce(function(e,r){return e.replace(r.replace,r.with)},i),n.length>0&&(o+="\\/"))}return o}
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/var h=["/**","!/**/*.*","!/**/*__*","!/**/*__*/**"],d=function(){function e(e,r){this.fs=e,this.baseHref=r}return e.prototype.process=function(e){return r(this,void 0,void 0,function(){var r,n;return t(this,function(t){switch(t.label){case 0:return[4,this.processAssetGroups(e,r={})];case 1:return n=t.sent(),[2,{configVersion:1,appData:e.appData,index:b(this.baseHref,e.index),assetGroups:n,dataGroups:this.processDataGroups(e),hashTable:function o(e){var r={};return Object.keys(e).sort().forEach(function(t){return r[t]=e[t]}),r}
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/(r),navigationUrls:function i(e,r){return void 0===r&&(r=h),r.map(function(r){var t=!r.startsWith("!");return{positive:t,regex:"^"+g(r=t?r:r.substr(1),e)+"$"}})}(this.baseHref,e.navigationUrls)}]}})})},e.prototype.processAssetGroups=function(e,n){return r(this,void 0,void 0,function(){var i,s=this;return t(this,function(a){return i=new Set,[2,Promise.all((e.assetGroups||[]).map(function(e){return r(s,void 0,void 0,function(){var s,a,u,c,f,l,p=this;return t(this,function(h){switch(h.label){case 0:return e.resources.versionedFiles&&console.warn("Asset-group '"+e.name+"' in 'ngsw-config.json' uses the 'versionedFiles' option.\nAs of v6 'versionedFiles' and 'files' options have the same behavior. Use 'files' instead."),s=v(e.resources.files||[]),a=v(e.resources.versionedFiles||[]),[4,this.fs.list("/")];case 1:return u=h.sent(),(c=u.filter(s).filter(function(e){return!i.has(e)})).forEach(function(e){return i.add(e)}),(f=u.filter(a).filter(function(e){return!i.has(e)})).forEach(function(e){return i.add(e)}),[4,(l=o(c,f).sort()).reduce(function(e,o){return r(p,void 0,void 0,function(){var r;return t(this,function(t){switch(t.label){case 0:return[4,e];case 1:return t.sent(),[4,this.fs.hash(o)];case 2:return r=t.sent(),n[b(this.baseHref,o)]=r,[2]}})})},Promise.resolve())];case 2:return h.sent(),[2,{name:e.name,installMode:e.installMode||"prefetch",updateMode:e.updateMode||e.installMode||"prefetch",urls:l.map(function(e){return b(p.baseHref,e)}),patterns:(e.resources.urls||[]).map(function(e){return g(e,p.baseHref,!0)})}]}})})}))]})})},e.prototype.processDataGroups=function(e){var r=this;return(e.dataGroups||[]).map(function(e){return{name:e.name,patterns:e.urls.map(function(e){return g(e,r.baseHref,!0)}),strategy:e.cacheConfig.strategy||"performance",maxSize:e.cacheConfig.maxSize,maxAge:a(e.cacheConfig.maxAge),timeoutMs:e.cacheConfig.timeout&&a(e.cacheConfig.timeout),version:void 0!==e.version?e.version:1}})},e}();function v(e){var r=e.map(function(e){return e.startsWith("!")?{positive:!1,regex:new RegExp("^"+p(e.substr(1))+"$")}:{positive:!0,regex:new RegExp("^"+p(e)+"$")}});return function(e){return function t(e,r){return r.reduce(function(r,t){return t.positive?r||t.regex.test(e):r&&!t.regex.test(e)},!1)}(e,r)}}function g(e,r,t){return e.startsWith("/")||-1!==e.indexOf("://")||(e=b(r,e)),p(e,t)}function b(e,r){return e.endsWith("/")&&r.startsWith("/")?e+r.substr(1):e.endsWith("/")||r.startsWith("/")?e+r:e+"/"+r}e.Generator=d,Object.defineProperty(e,"__esModule",{value:!0})});