From 61eb1e1c49dd6b9deb29241a4aed965499ac4cd1 Mon Sep 17 00:00:00 2001 From: Thierry Bela Date: Sat, 27 Feb 2021 12:50:49 -0500 Subject: [PATCH 1/5] #125 generate onesignal javascript --- BUILD.md | 41 ++++++++++++++++++++++ config/terser/terser.config.js | 57 ++++++++++++++++++++---------- gzip.xml | 4 +-- package.json | 2 +- terser.config.js | 59 ++++++++++++++++++++++---------- worker/dist/onesignal.js | 38 ++++++++++++++++++++ worker/dist/onesignal.min.js | 1 + worker/dist/serviceworker.min.js | 2 +- 8 files changed, 164 insertions(+), 40 deletions(-) create mode 100644 BUILD.md create mode 100644 worker/dist/onesignal.js create mode 100644 worker/dist/onesignal.min.js diff --git a/BUILD.md b/BUILD.md new file mode 100644 index 0000000..9e02f65 --- /dev/null +++ b/BUILD.md @@ -0,0 +1,41 @@ +# How to build scripts + +Build all javascript files + +```bash +./build.sh +``` + +## Service Worker Scripts + +Definitions are located in ./config/rollup/rollup.config.js. After you update the definitions, +you need to update the build script with + +```bash +npm run rollup-config +``` + +The updated script will be located in ./rollup.config.js + +### Run the build script + +```bash +node ./rollup.config.js +``` + +## Other javascript files + +Definitions are located in ./config/terser/terser.config.js. After you update the definitions, +you need to update the build script with + +```bash +npm run terser-config +``` + +The updated script will be located in ./terser.config.js + +### Run the build script + +```bash +node ./terser.config.js +``` \ No newline at end of file diff --git a/config/terser/terser.config.js b/config/terser/terser.config.js index f64cb03..cadecb4 100644 --- a/config/terser/terser.config.js +++ b/config/terser/terser.config.js @@ -11,9 +11,10 @@ */ const preamble = "/* do not edit this file! */"; +const ECMA_VERSION = 5; const compress = { - // ecma: 5, + // ecma: ECMA_VERSION, // keep_fnames: true, passes: 3, toplevel: true, @@ -29,7 +30,7 @@ const output = { // output options preamble, beautify: true, - // ecma: 5, // specify one of: 5, 6, 7 or 8 + // ecma: ECMA_VERSION, // specify one of: 5, 6, 7 or 8 comments: true }; @@ -44,7 +45,7 @@ const minify = { ...output, preamble: '', beautify: false, - // ecma: 5, // specify one of: 5, 6, 7 or 8 + // ecma: ECMA_VERSION, // specify one of: 5, 6, 7 or 8 comments: false } }; @@ -63,7 +64,7 @@ export const imageLoader = { output: "./imagesloader.js", config: { // ie8: true, - ecma: 5, + ecma: ECMA_VERSION, output, warnings: true } @@ -74,7 +75,7 @@ export const bgStyles = { output: "./bgstyles.js", config: { // ie8: true, - ecma: 5, + ecma: ECMA_VERSION, output, warnings: true } @@ -85,7 +86,18 @@ export const intersectionObserver = { output: "./js/dist/intersection-observer.js", config: { // ie8: true, - ecma: 5, + ecma: ECMA_VERSION, + output, + warnings: true + } +}; + +export const oneSignal = { + input: "./worker/src/onesignal/onesignal.js", + output: "./worker/dist/onesignal.js", + config: { + // ie8: true, + ecma: ECMA_VERSION, output, warnings: true } @@ -97,7 +109,7 @@ export const imageLoaderMin = { config: { ...minify, // ie8: true, - ecma: 5 // specify one of: 5, 6, 7 or 8 + ecma: ECMA_VERSION // specify one of: 5, 6, 7 or 8 } }; @@ -107,7 +119,7 @@ export const bgStylesMin = { config: { ...minify, // ie8: true, - ecma: 5 // specify one of: 5, 6, 7 or 8 + ecma: ECMA_VERSION // specify one of: 5, 6, 7 or 8 } }; @@ -117,7 +129,7 @@ export const loaderMin = { config: { ...minify, // ie8: true, - ecma: 5 // specify one of: 5, 6, 7 or 8 + ecma: ECMA_VERSION // specify one of: 5, 6, 7 or 8 } }; @@ -127,7 +139,7 @@ export const libReadyMin = { config: { ...minify, ...imagesOverride, - ecma: 5 + ecma: ECMA_VERSION } }; @@ -137,7 +149,7 @@ export const libImageMin = { config: { ...minify, ...imagesOverride, - ecma: 5 + ecma: ECMA_VERSION } }; @@ -146,7 +158,16 @@ export const intersectionObserverMin = { output: "./js/dist/intersection-observer.min.js", config: { ...minify, - ecma: 5 + ecma: ECMA_VERSION + } +}; + +export const oneSignalMin = { + input: "./worker/dist/onesignal.js", + output: "./worker/dist/onesignal.min.js", + config: { + ...minify, + ecma: ECMA_VERSION } }; @@ -155,7 +176,7 @@ export const syncMin = { output: "./worker/dist/sync.fallback.min.js", config: { ...minify, - ecma: 5 + ecma: ECMA_VERSION } }; @@ -164,7 +185,7 @@ export const browserPrefetchMin = { output: "./worker/dist/browser.prefetch.min.js", config: { ...minify, - ecma: 5 + ecma: ECMA_VERSION } }; @@ -191,7 +212,7 @@ export const browserMin = { output: "./worker/dist/browser.min.js", config: { ...minify, - ecma: 5 + ecma: ECMA_VERSION } }; @@ -200,7 +221,7 @@ export const browserAdminMin = { output: "./worker/dist/browser.administrator.min.js", config: { ...minify, - ecma: 5 + ecma: ECMA_VERSION } }; @@ -209,7 +230,7 @@ export const browserSyncMin = { output: "./worker/dist/browser.sync.min.js", config: { ...minify, - ecma: 5 + ecma: ECMA_VERSION } }; @@ -218,6 +239,6 @@ export const browserUninstallMin = { output: "./worker/dist/browser.uninstall.min.js", config: { ...minify, - ecma: 5 + ecma: ECMA_VERSION } }; diff --git a/gzip.xml b/gzip.xml index f0bc376..37a6f72 100644 --- a/gzip.xml +++ b/gzip.xml @@ -3,11 +3,11 @@ plg_system_gzip Thierry Bela August 2016 - Copyright (C) 2005 - 2016 Thierry Bela. + Copyright (C) 2005 - 2021 Thierry Bela. Released under dual license LGPL v3 | MIT contact@tbela.net https://tbela.net - 2.9.2 + 2.9.3 PLG_SYSTEM_GZIP_XML_DESCRIPTION docs diff --git a/package.json b/package.json index 4b50a21..88f0b39 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gzip", - "version": "2.9.2", + "version": "2.9.3", "scripts": { "build": "./build.sh", "rollup-config": "./node_modules/rollup/dist/bin/rollup ./config/rollup/rollup.js -f iife --name=rollupConfig > ./rollup.config.js", diff --git a/terser.config.js b/terser.config.js index c0484b4..7bfc65c 100644 --- a/terser.config.js +++ b/terser.config.js @@ -14,9 +14,10 @@ */ const preamble = "/* do not edit this file! */"; + const ECMA_VERSION = 5; const compress = { - // ecma: 5, + // ecma: ECMA_VERSION, // keep_fnames: true, passes: 3, toplevel: true, @@ -32,7 +33,7 @@ // output options preamble, beautify: true, - // ecma: 5, // specify one of: 5, 6, 7 or 8 + // ecma: ECMA_VERSION, // specify one of: 5, 6, 7 or 8 comments: true }; @@ -47,7 +48,7 @@ ...output, preamble: '', beautify: false, - // ecma: 5, // specify one of: 5, 6, 7 or 8 + // ecma: ECMA_VERSION, // specify one of: 5, 6, 7 or 8 comments: false } }; @@ -66,7 +67,7 @@ output: "./imagesloader.js", config: { // ie8: true, - ecma: 5, + ecma: ECMA_VERSION, output, warnings: true } @@ -77,7 +78,7 @@ output: "./bgstyles.js", config: { // ie8: true, - ecma: 5, + ecma: ECMA_VERSION, output, warnings: true } @@ -88,7 +89,18 @@ output: "./js/dist/intersection-observer.js", config: { // ie8: true, - ecma: 5, + ecma: ECMA_VERSION, + output, + warnings: true + } + }; + + const oneSignal = { + input: "./worker/src/onesignal/onesignal.js", + output: "./worker/dist/onesignal.js", + config: { + // ie8: true, + ecma: ECMA_VERSION, output, warnings: true } @@ -100,7 +112,7 @@ config: { ...minify, // ie8: true, - ecma: 5 // specify one of: 5, 6, 7 or 8 + ecma: ECMA_VERSION // specify one of: 5, 6, 7 or 8 } }; @@ -110,7 +122,7 @@ config: { ...minify, // ie8: true, - ecma: 5 // specify one of: 5, 6, 7 or 8 + ecma: ECMA_VERSION // specify one of: 5, 6, 7 or 8 } }; @@ -120,7 +132,7 @@ config: { ...minify, // ie8: true, - ecma: 5 // specify one of: 5, 6, 7 or 8 + ecma: ECMA_VERSION // specify one of: 5, 6, 7 or 8 } }; @@ -130,7 +142,7 @@ config: { ...minify, ...imagesOverride, - ecma: 5 + ecma: ECMA_VERSION } }; @@ -140,7 +152,7 @@ config: { ...minify, ...imagesOverride, - ecma: 5 + ecma: ECMA_VERSION } }; @@ -149,7 +161,16 @@ output: "./js/dist/intersection-observer.min.js", config: { ...minify, - ecma: 5 + ecma: ECMA_VERSION + } + }; + + const oneSignalMin = { + input: "./worker/dist/onesignal.js", + output: "./worker/dist/onesignal.min.js", + config: { + ...minify, + ecma: ECMA_VERSION } }; @@ -158,7 +179,7 @@ output: "./worker/dist/sync.fallback.min.js", config: { ...minify, - ecma: 5 + ecma: ECMA_VERSION } }; @@ -167,7 +188,7 @@ output: "./worker/dist/browser.prefetch.min.js", config: { ...minify, - ecma: 5 + ecma: ECMA_VERSION } }; @@ -194,7 +215,7 @@ output: "./worker/dist/browser.min.js", config: { ...minify, - ecma: 5 + ecma: ECMA_VERSION } }; @@ -203,7 +224,7 @@ output: "./worker/dist/browser.administrator.min.js", config: { ...minify, - ecma: 5 + ecma: ECMA_VERSION } }; @@ -212,7 +233,7 @@ output: "./worker/dist/browser.sync.min.js", config: { ...minify, - ecma: 5 + ecma: ECMA_VERSION } }; @@ -221,7 +242,7 @@ output: "./worker/dist/browser.uninstall.min.js", config: { ...minify, - ecma: 5 + ecma: ECMA_VERSION } }; @@ -230,12 +251,14 @@ imageLoader: imageLoader, bgStyles: bgStyles, intersectionObserver: intersectionObserver, + oneSignal: oneSignal, imageLoaderMin: imageLoaderMin, bgStylesMin: bgStylesMin, loaderMin: loaderMin, libReadyMin: libReadyMin, libImageMin: libImageMin, intersectionObserverMin: intersectionObserverMin, + oneSignalMin: oneSignalMin, syncMin: syncMin, browserPrefetchMin: browserPrefetchMin, serviceWorkerMin: serviceWorkerMin, diff --git a/worker/dist/onesignal.js b/worker/dist/onesignal.js new file mode 100644 index 0000000..caca78b --- /dev/null +++ b/worker/dist/onesignal.js @@ -0,0 +1,38 @@ +/* do not edit this file! */ +/** + * + * @package GZip Plugin + * @copyright Copyright (C) 2005 - 2018 Thierry Bela. + * + * dual licensed + * + * @license LGPL v3 + * @license MIT License + */ +// @ts-check +/* wrap-iife: 0 */ +!function(n, e) { + n.src = "https://cdn.onesignal.com/sdks/OneSignalSDK.js", n.defer = !0, n.async = !0, + n.onload = function() { + const n = window.OneSignal = window.OneSignal || []; + n.push((function() { + n.init({ + appId: "{APP_ID}" + }); + } + /*, + // get user ID + function() { + OneSignal.on("subscriptionChange", function(isSubscribed) { + if (isSubscribed) { + // The user is subscribed + // Either the user subscribed for the first time + // Or the user was subscribed -> unsubscribed -> subscribed + OneSignal.getUserId(function(userId) { + // Make a POST call to your server with the user ID + }); + } + }); + } */)); + }, e.removeChild(e.appendChild(n)); +}(document.createElement("script"), document.body); \ No newline at end of file diff --git a/worker/dist/onesignal.min.js b/worker/dist/onesignal.min.js new file mode 100644 index 0000000..8e7b6bc --- /dev/null +++ b/worker/dist/onesignal.min.js @@ -0,0 +1 @@ +var n,e;n=document.createElement("script"),e=document.body,n.src="https://cdn.onesignal.com/sdks/OneSignalSDK.js",n.defer=!0,n.async=!0,n.onload=function(){const d=window.OneSignal=window.OneSignal||[];d.push((function(){d.init({appId:"{APP_ID}"})}))},e.removeChild(e.appendChild(n)); \ No newline at end of file diff --git a/worker/dist/serviceworker.min.js b/worker/dist/serviceworker.min.js index eff39de..a92f006 100644 --- a/worker/dist/serviceworker.min.js +++ b/worker/dist/serviceworker.min.js @@ -1 +1 @@ -!function(){"use strict";async function DB(e,t="id",r=[]){return new Promise((n,s)=>{const a=indexedDB.open(e,1),o=`${e}_store`;let i;const _query=(e,t,r=null,n=null)=>new Promise((s,a)=>{const c=t?"readonly":"readwrite";if(i.objectStoreNames.contains(o)){const t=i.transaction(o,c),l=t.objectStore(o);let u;"put"===e&&r&&void 0!==r.length?(u=t,r.forEach(e=>{l.put(e)})):(n&&l.index(n),u=l[e](r)),u.oncomplete=e=>{s(e.target.result)},u.onsuccess=e=>{s(e.target.result)},u.onerror=e=>{a(e)}}else a(new Error("Store not found"))}),c={count:async()=>{const e=i.transaction(o,"readonly").objectStore(o).count();return new Promise((function(t,r){e.onsuccess=function(e){t(e.target.result)},e.onerror=function(e){r(e)}}))},get:(e,t)=>_query("get",!0,e,t),getAll:(e,t)=>_query("getAll",!0,e,t),put:e=>_query("put",!1,e),delete:e=>_query("delete",!1,e),clear:()=>_query("clear",!1),deleteDatabase:()=>new Promise((function(e,t){const r=indexedDB.deleteDatabase;r.onerror=t,r.onsuccess=e}))};a.onupgradeneeded=(()=>{i=a.result;const e=i.createObjectStore(o,{keyPath:t});let n;for(n of r)e.createIndex(n.name,n.key,n.options)}).bind(this),a.onsuccess=(()=>{i=a.result,n(c)}).bind(this),a.onerror=(e=>{s(new Error(e.originalTarget&&e.originalTarget.error||e))}).bind(this)})}const e={implement(e){const t=e.prototype,r=[].slice.call(arguments,1);let n,s,a;function makefunc(e,t,r){return function(){const n=this,s="previous"in n,a="parent"in n,o=n.previous,i=n.parent;n.previous=t,n.parent=r;const c=e.apply(n,arguments);return s&&(n.previous=o),a&&(n.parent=i),c}}for(n=0;nfunction(t){if("object"==typeof t){const r=[].slice.call(arguments,1);let n;for(n in t)e.apply(this,[n,t[n]].concat(r))}else e.apply(this,arguments);return this}};function merge(e){const t=[].slice.call(arguments,1);let r,n,s,a,o="boolean"==typeof e;for(!0===o&&(o=e,e=t.shift()),r=0;r1?[].slice.call(arguments,1):[];return Promise.all((t.$events[e]||[]).concat().map(e=>new Promise(n=>{n(e.cb.apply(t,r))})))},addPseudo(e,t){return this.$pseudo[e]=t,this}};function normalize(e="GET"){return Array.isArray(e)||(e=[e]),e.forEach(e=>e==i||"HEAD"==e?"GET":e.toUpperCase()),e}r.addPseudo("once",(function(e){return e.cb=function(){const t=this,r=e.fn.apply(t,arguments);return t.off(e.name,e.fn),r},this}));class n{constructor(){this.routers=Object.create(i),this.defaultRouter=Object.create(i)}getRouter(e){const t=e!=i&&e.request.method||"GET",r=this.routers[t]||[],n=r.length;let s,a=0;for(;a{t in this.routers||(this.routers[t]=[]),this.routers[t].push(e)}),this}unregisterRoute(e,t){return normalize(t).forEach(t=>{const r=this.routers[t]||[],n=r.indexOf(e);-1!=n&&r.splice(n,1)}),this}setDefaultRouter(e,t){normalize(t).forEach(t=>this.defaultRouter[t]=e)}getDefaultRouter(){for(let e in this.defaultRouter)return this.defaultRouter[e];return i}}e.merge(!0,n.prototype,r);class s{constructor(e,t,r=null){const n=this;n.plugins=[],n.options=Object.assign(Object.create(i),{mime:[]},r||{}),n.path=e,n.strategy=t.name,n.handler={handle:async e=>{let r,s;for(r of n.plugins)try{if(s=await r.precheck(e),s instanceof Response)return s}catch(e){console.error({error:e})}if(s=await t.handle(e),s instanceof Response)for(r of n.plugins)try{await r.postcheck(e,s)}catch(e){console.error(e.message)}return s}}}addPlugin(e){return this.plugins.includes(e)||this.plugins.push(e),this}match(e,t){return!0}}e.merge(!0,s.prototype,r);class a extends s{match(e,t){const r=e.request.url;return/^https?:/.test(r)&&this.path.test(r)||this.options.mime.includes(e.request.headers.get("Content-Type"))||t!=i&&this.options.mime.includes(t.headers.get("Content-Type"))}}class o extends s{constructor(e,t,r=null){super(e,t,r),this.url=new URL(e,self.origin)}match(e,t){const r=e.request.url,n=new URL(r);return/^https?:/.test(r)&&n.origin==this.url.origin&&0==n.pathname.indexOf(this.url.pathname)||this.options.mime.includes(e.request.headers.get("Content-Type"))||t!=i&&this.options.mime.includes(t.headers.get("Content-Type"))}}const i=null,c=Object.create(i);function hashCode(e){var t,r=0;if(0===e.length)return r;for(t=0;ta+=t+":"+getObjectHash(e)+","),","==a[a.length-1]&&(a=a.substr(0,a.length-2)),a+="}";else{for(n of(a+="[",r))a+=getObjectHash(n)+",";","==a[a.length-1]&&(a=a.substr(0,a.length-2)),a+="]"}else a+="{"+getObjectHash(r)+"}";else a+=""+r;else a+=JSON.stringify(r);a+=","}","==a[a.length-1]&&(a=a.substr(0,a.length-2)),Array.isArray(e)?a="["+a+"]":"object"==typeof e&&(a="{"+a+"}")}return a}function num2FileSize(e,t){if(0==e)return 0;const r=Math.floor(Math.log(e)/Math.log(1024));return(e/Math.pow(1024,Math.floor(r))).toFixed(2)+" "+(t&&t[r]?t[r]:["b","Kb","Mb","Gb","Tb","Pb"][r])}function sprintf(e){let t,r=-1;const n=[].slice.apply(arguments).slice(1);return e.replace(/%([s%])/g,(function(e,s){if("%"==s)return s;switch(t=n[++r],s){case"s":return null==t?"":t}}))}function ellipsis(e,t=30,r=15,n="..."){return e.length>t?e.slice(0,t-r-n.length+1)+n+e.slice(e.length-r+1):e}let l;e.merge(!0,c,r),Object.defineProperties(c,{app:{value:Object.create(i)},routes:{value:new n}}),Object.defineProperties(c.app,{name:{value:"gzip",enumerable:!0},scope:{value:"{scope}",enumerable:!0},route:{value:"{ROUTE}",enumerable:!0},cacheName:{value:"{CACHE_NAME}",enumerable:!0},codeName:{value:"Joomla Website Optimizer Plugin",enumerable:!0},build:{value:"{VERSION}",enumerable:!0},buildid:{value:"build-id",enumerable:!0},builddate:{value:"build-date",enumerable:!0},urls:{value:"{CDN_HOSTS}",enumerable:!0},backgroundSync:{value:"{BACKGROUND_SYNC}",enumerable:!0},offline:{value:"{pwa_offline_page}"},network:{value:"{pwa_cache_settings}"},customNetwork:{value:"{pwa_custom_cache_settings}"},precache:{value:"{preloaded_urls}".map(e=>new URL(e,self.origin).href),enumerable:!0},homepage:{value:"https://github.com/tbela99/gzip",enumerable:!0}}),caches.open(c.app.cacheName).then(e=>l=e);class u{constructor(e){this.setOptions(e)}getRouteTag(e){const t=c.app.route;let r;for(r of c.app.urls)if(new RegExp("^https?://"+r+c.app.scope+t+"/").test(e))return t;return i}async setOptions(e){const t=new Date,r=+t;this.maxAge=0,this.limit=+e.limit||0,this.maxFileSize=+e.maxFileSize||0;const n=e.maxAge.match(/([+-]?\d+)(.*)$/);if(null!=n)switch(n[2]){case"months":case"minutes":case"hours":let e=(s=n[2])[0].toUpperCase()+s.slice(1);"Months"==e&&(e="Month"),t["set"+e](+n[1]+t["get"+e]()),this.maxAge=t-r}var s;this.db=await DB(e.cacheName!=i?e.cacheName:"gzip_sw_worker_expiration_cache_private","url",[{name:"url",key:"url"},{name:"version",key:"version"},{name:"route",key:"route"}])}async precheck(e){try{if(this.db==i||0==this.maxAge)return!0;const t=hashCode(getObjectHash(e.request)),r=await this.db.get(e.request.url,"url");return r!=i&&(r.version!=t||r.timestamp0&&t.body!=i){const e=await t.clone().blob();if(e.size>this.maxFileSize)throw sprintf("cache limit exceeded. Deleting item [%s]",ellipsis(t.url)),await this.db.delete(t.url),await l.delete(t),new Error(sprintf("[%s][cache failed] cache size limit exceeded %s of %s",ellipsis(t.url,42),num2FileSize(e.size),num2FileSize(this.maxFileSize)))}try{const t=e.request.url,r=await this.db.get(t,"url"),n=hashCode(getObjectHash(e.request));return r==i||r.version!=n||r.timestampt instanceof Response&&("cors"==t.type||new URL(e.url,self.origin).origin==self.origin)&&"GET"==e.method&&t.ok&&["default","cors","basic","navigate"].includes(t.type)&&!t.bodyUsed,h=new Map,f={add:(e,t,r)=>h.set(e,{key:e,name:r==i?e:r,handle:async e=>await t(e)}),keys:()=>h.keys(),values:()=>h.values(),entries:()=>h.entries(),get:e=>h.get(e),has:e=>h.has(e),delete:e=>h.delete(e),isCacheableRequest:isCacheableRequest};f[Symbol.iterator]=()=>h[Symbol.iterator](),Object.defineProperty(f,"size",{get:()=>h.size});const p=c.app.cacheName,d=c.app.cacheName,m=c.app.cacheName,g=c.app.cacheName;f.add("cf",(async function(e){let t=await caches.match(e.request,{cacheName:p});if(null!=t)return t;if(t=await fetch(e.request),f.isCacheableRequest(e.request,t)){const r=t.clone();caches.open(p).then(t=>t.put(e.request,r))}return t}),"Cache fallback to Network"),f.add("cn",(async function(e){const t=await caches.match(e.request,{cacheName:d}),r=fetch(e.request).then(t=>{if(f.isCacheableRequest(e.request,t)){const r=t.clone();caches.open(d).then(t=>t.put(e.request,r))}return t}).catch(()=>{});return t||r}),"Cache and Network Update"),f.add("co",(async function(e){return await caches.match(e.request,{cacheName:m})}),"Cache Only"),f.add("nf",(async function(e){try{const t=await fetch(e.request);if(null==t)throw new Error("Network error");if(f.isCacheableRequest(e.request,t)){const r=t.clone();caches.open(g).then(t=>t.put(e.request,r))}return t}catch(e){}return caches.match(e.request,{cacheName:g})}),"Network fallback to Cache"),f.add("no",(async function(e){return fetch(e.request)}),"Network Only"),self.addEventListener("activate",e=>{e.waitUntil((async()=>{try{await c.resolve("activate",e)}catch(e){console.error("😭",e)}return self.clients.claim()})())}),self.addEventListener("fetch",e=>{e.respondWith(!e.url||"only-if-cached"===e.request.cache&&"same-origin"!==e.request.mode?fetch(e.request):async function(){let t;const r=c.routes.getRouter(e);if(r!=i)try{if(t=await r.handler.handle(e),t instanceof Response)return t;for(t of await c.routes.resolve("fail",e,t))if(t instanceof Response)return t}catch(e){console.error("😭",e)}return fetch(e.request)}())}),self.addEventListener("install",e=>{e.waitUntil((async()=>{try{await c.resolve("install",e)}catch(e){console.error("😭",e)}return self.skipWaiting()})())});const y=["method","referrer","referrerPolicy","mode","credentials","cache","redirect","integrity","keepalive"];class w{async push(e){const t=await this.cloneRequestData(e),r=await this.getDB();return await r.put({id:hashCode(e.url+y.map(async e=>{let r=t[e];return r==i?"":"headers"==e?r instanceof Headers?[...r.values()].filter(e=>e!=i).join(""):Object.values(r).map(r=>t[e][r]!=i?t[e][r]:"").join(""):"body"==e?await r.text():r}).join("")),lastRetry:Date.now()+864e5,url:e.url,request:t}),this}async cloneRequestData(e){const t={headers:{}};"GET"!==e.method&&(t.body=await e.clone().arrayBuffer());for(const[r,n]of e.headers.entries())t.headers[r]=n;for(const r of y)void 0!==e[r]&&(t[r]=e[r]);return"navigate"===t.mode&&(t.mode="same-origin"),t}async getDB(){return this.db==i&&(this.db=await DB("gzip_sw_worker_sync_requests","id")),this.db}async replay(e){if("{SYNC_API_TAG}"!=e)return;const t=await this.getDB(),r=await t.getAll();r.length;const n=await caches.open("{CACHE_NAME}");for(const e of r){let r=!1;try{e.request.method,e.url;const t=new Request(e.url,e.request);let s=await n.match(t);r=s!=i,r||(s=await fetch(t.clone()),r=s!=i&&s.ok,r&&isCacheableRequest(t,s)&&await n.put(t,s))}catch(e){}(r||e.lastRetry<=Date.now())&&await t.delete(e.id)}}}if(c.app.backgroundSync.enabled){const e=new w;c.on({async install(){for(const e of["gzip_sw_worker_sync_requests","gzip_sw_worker_sync_tasks"]){const t=await DB(e,"id");null!=t&&await t.clear()}}}),c.routes.on({fail(t,r){const n=c.app.backgroundSync;if(0==n.length||-1!=n.method.indexOf(t.method)){const r=t.url.replace(self.origin,"");if(0==n.pattern.length||n.pattern.some(e=>0==r.indexOf(e)))return e.push(t)}}}),self.addEventListener("sync",(function(t){t.tag,t.waitUntil(e.replay(t.tag).catch(e=>console.error({error:e})))}))}c.app.network.limit>0&&self.addEventListener("sync",async e=>{const t=await async function(){let e=await caches.open("{CACHE_NAME}");const t="{preloaded_urls}".map(e=>new URL(e,self.origin).href),r="{pwa_cache_max_file_count}",n=await DB("gzip_sw_worker_expiration_cache_private","url",[{name:"url",key:"url"},{name:"version",key:"version"},{name:"route",key:"route"}]);return async function(){let s=await n.count();if(s>r){sprintf("cleaning up [%s] items present. [%s] items allowed",s,r);for(let a of await n.getAll())if(t.includes(a.url))sprintf("skipped preloaded resource [%s]",a.url);else if(sprintf("removing [%s]",a.url),await e.delete(a.url),await n.delete(a.url),--s<=r)break;sprintf("cleaned up [%s] items present. [%s] items allowed",s,r)}}}();e.waitUntil(t())}),c.app.offline.enabled&&c.routes.on("fail",async e=>{if("navigate"==e.request.mode&&c.app.offline.methods.includes(e.request.method)){if("response"==c.app.offline.type)return new Response(c.app.offline.body,{headers:new Headers({"Content-Type":'text/html; charset="{offline_charset}"'})});if(""!=c.app.offline.url)return caches.match(c.app.offline.url)}});const b=c.routes,v=c.app.scope,k=c.app.network,O=k.caching;let _,R,x,q,j,A,E;({limit:j,maxAge:x,cacheName:A,strategy:E,maxFileSize:q}=k);const N={limit:j,maxAge:x,strategy:E,maxFileSize:q};for(_ of"{exclude_urls}")b.registerRoute(new a(new RegExp(_),f.get("no")));for(_ of k.settings)R=new a(new RegExp("("+_.ext.join(")|(")+")","i"),f.get(_.strategy),_),O&&(({limit:j,maxAge:x,maxFileSize:q}=_),R.addPlugin(new u({limit:j,maxAge:x,maxFileSize:q}))),b.registerRoute(R);for(_ of f)R=new o(v+"{ROUTE}/media/z/"+_[0]+"/",_[1]),O&&R.addPlugin(new u(N)),b.registerRoute(R),c.app.customNetwork.forEach(e=>{let t=v+"{ROUTE}/"+_[0]+"/"+e.prefix+"/";delete e.prefix;let r=new o(t,e);r.addPlugin(new u(e)),b.registerRoute(r)});R=new o(v,f.get(k.strategy)),O&&R.addPlugin(new u(N)),b.setDefaultRouter(R),A=c.app.cacheName,c.on({error(e,t){console.error({error:e,event:t})},async install(){await caches.open(A).then(async e=>await e.addAll(c.app.precache))},async activate(){const e=await DB("gzip_sw_worker_config_cache_private","name"),t=await e.get("gzip");if(t!=i&&"{ROUTE}"!=t.route){let e,t;for(e of"{STORES}")t=await DB(e,"url",[{name:"url",key:"url"},{name:"version",key:"version"},{name:"route",key:"route"}]),t!=i&&t.clear()}await e.put(c.app);const r=await caches.keys(),n=A.split(/_/,2),s=2==n.length&&n[0]+"_";0!=s&&await Promise.all(r.map(e=>0==e.indexOf(s)&&e!=A&&caches.delete(e)))}})}(); \ No newline at end of file +!function(){"use strict";async function DB(e,t="id",r=[]){return new Promise((n,s)=>{const a=indexedDB.open(e,1),o=`${e}_store`;let i;const _query=(e,t,r=null,n=null)=>new Promise((s,a)=>{const c=t?"readonly":"readwrite";if(i.objectStoreNames.contains(o)){const t=i.transaction(o,c),l=t.objectStore(o);let u;"put"===e&&r&&void 0!==r.length?(u=t,r.forEach(e=>{l.put(e)})):(n&&l.index(n),u=l[e](r)),u.oncomplete=e=>{s(e.target.result)},u.onsuccess=e=>{s(e.target.result)},u.onerror=e=>{a(e)}}else a(new Error("Store not found"))}),c={count:async()=>{const e=i.transaction(o,"readonly").objectStore(o).count();return new Promise((function(t,r){e.onsuccess=function(e){t(e.target.result)},e.onerror=function(e){r(e)}}))},get:(e,t)=>_query("get",!0,e,t),getAll:(e,t)=>_query("getAll",!0,e,t),put:e=>_query("put",!1,e),delete:e=>_query("delete",!1,e),clear:()=>_query("clear",!1),deleteDatabase:()=>new Promise((function(e,t){const r=indexedDB.deleteDatabase;r.onerror=t,r.onsuccess=e}))};a.onupgradeneeded=(()=>{i=a.result;const e=i.createObjectStore(o,{keyPath:t});let n;for(n of r)e.createIndex(n.name,n.key,n.options)}).bind(this),a.onsuccess=(()=>{i=a.result,n(c)}).bind(this),a.onerror=(e=>{s(new Error(e.originalTarget&&e.originalTarget.error||e))}).bind(this)})}const e={implement(e){const t=e.prototype,r=[].slice.call(arguments,1);let n,s,a;function makefunc(e,t,r){return function(){const n=this,s="previous"in n,a="parent"in n,o=n.previous,i=n.parent;n.previous=t,n.parent=r;const c=e.apply(n,arguments);return s&&(n.previous=o),a&&(n.parent=i),c}}for(n=0;nfunction(t){if("object"==typeof t){const r=[].slice.call(arguments,1);let n;for(n in t)e.apply(this,[n,t[n]].concat(r))}else e.apply(this,arguments);return this}};function merge(e){const t=[].slice.call(arguments,1);let r,n,s,a,o="boolean"==typeof e;for(!0===o&&(o=e,e=t.shift()),r=0;r1?[].slice.call(arguments,1):[];return Promise.all((t.$events[e]||[]).concat().map(e=>new Promise(n=>{n(e.cb.apply(t,r))})))},addPseudo(e,t){return this.$pseudo[e]=t,this}};function normalize(e="GET"){return Array.isArray(e)||(e=[e]),e.forEach(e=>e==i||"HEAD"==e?"GET":e.toUpperCase()),e}r.addPseudo("once",(function(e){return e.cb=function(){const t=this,r=e.fn.apply(t,arguments);return t.off(e.name,e.fn),r},this}));class n{constructor(){this.routers=Object.create(i),this.defaultRouter=Object.create(i)}getRouter(e){const t=e!=i&&e.request.method||"GET",r=this.routers[t]||[],n=r.length;let s,a=0;for(;a{t in this.routers||(this.routers[t]=[]),this.routers[t].push(e)}),this}unregisterRoute(e,t){return normalize(t).forEach(t=>{const r=this.routers[t]||[],n=r.indexOf(e);-1!=n&&r.splice(n,1)}),this}setDefaultRouter(e,t){normalize(t).forEach(t=>this.defaultRouter[t]=e)}getDefaultRouter(){for(let e in this.defaultRouter)return this.defaultRouter[e];return i}}e.merge(!0,n.prototype,r);class s{constructor(e,t,r=null){const n=this;n.plugins=[],n.options=Object.assign(Object.create(i),{mime:[]},r||{}),n.path=e,n.strategy=t.name,n.handler={handle:async e=>{let r,s;for(r of n.plugins)try{if(s=await r.precheck(e),s instanceof Response)return s}catch(e){console.error({error:e})}if(s=await t.handle(e),s instanceof Response)for(r of n.plugins)try{await r.postcheck(e,s)}catch(e){console.error(e.message)}return s}}}addPlugin(e){return this.plugins.includes(e)||this.plugins.push(e),this}match(e,t){return!0}}e.merge(!0,s.prototype,r);class a extends s{match(e,t){const r=e.request.url;return/^https?:/.test(r)&&this.path.test(r)||this.options.mime.includes(e.request.headers.get("Content-Type"))||t!=i&&this.options.mime.includes(t.headers.get("Content-Type"))}}class o extends s{constructor(e,t,r=null){super(e,t,r),this.url=new URL(e,self.origin)}match(e,t){const r=e.request.url,n=new URL(r);return/^https?:/.test(r)&&n.origin==this.url.origin&&0==n.pathname.indexOf(this.url.pathname)||this.options.mime.includes(e.request.headers.get("Content-Type"))||t!=i&&this.options.mime.includes(t.headers.get("Content-Type"))}}const i=null,c=Object.create(i);function hashCode(e){var t,r=0;if(0===e.length)return r;for(t=0;ta+=t+":"+getObjectHash(e)+","),","==a[a.length-1]&&(a=a.substr(0,a.length-2)),a+="}";else{for(n of(a+="[",r))a+=getObjectHash(n)+",";","==a[a.length-1]&&(a=a.substr(0,a.length-2)),a+="]"}else a+="{"+getObjectHash(r)+"}";else a+=""+r;else a+=JSON.stringify(r);a+=","}","==a[a.length-1]&&(a=a.substr(0,a.length-2)),Array.isArray(e)?a="["+a+"]":"object"==typeof e&&(a="{"+a+"}")}return a}function num2FileSize(e,t){if(0==e)return 0;const r=Math.floor(Math.log(e)/Math.log(1024));return(e/Math.pow(1024,Math.floor(r))).toFixed(2)+" "+(t&&t[r]?t[r]:["b","Kb","Mb","Gb","Tb","Pb"][r])}function sprintf(e){let t,r=-1;const n=[].slice.apply(arguments).slice(1);return e.replace(/%([s%])/g,(function(e,s){if("%"==s)return s;switch(t=n[++r],s){case"s":return null==t?"":t}}))}function ellipsis(e,t=30,r=15,n="..."){return e.length>t?e.slice(0,t-r-n.length+1)+n+e.slice(e.length-r+1):e}let l;e.merge(!0,c,r),Object.defineProperties(c,{app:{value:Object.create(i)},routes:{value:new n}}),Object.defineProperties(c.app,{name:{value:"gzip",enumerable:!0},scope:{value:"{scope}",enumerable:!0},route:{value:"{ROUTE}",enumerable:!0},cacheName:{value:"{CACHE_NAME}",enumerable:!0},codeName:{value:"Joomla Website Optimizer Plugin",enumerable:!0},build:{value:"{VERSION}",enumerable:!0},buildid:{value:"ac3d844",enumerable:!0},builddate:{value:"2021-02-07 11:00:41-05:00",enumerable:!0},urls:{value:"{CDN_HOSTS}",enumerable:!0},backgroundSync:{value:"{BACKGROUND_SYNC}",enumerable:!0},offline:{value:"{pwa_offline_page}"},network:{value:"{pwa_cache_settings}"},customNetwork:{value:"{pwa_custom_cache_settings}"},precache:{value:"{preloaded_urls}".map(e=>new URL(e,self.origin).href),enumerable:!0},homepage:{value:"https://github.com/tbela99/gzip",enumerable:!0}}),caches.open(c.app.cacheName).then(e=>l=e);class u{constructor(e){this.setOptions(e)}getRouteTag(e){const t=c.app.route;let r;for(r of c.app.urls)if(new RegExp("^https?://"+r+c.app.scope+t+"/").test(e))return t;return i}async setOptions(e){const t=new Date,r=+t;this.maxAge=0,this.limit=+e.limit||0,this.maxFileSize=+e.maxFileSize||0;const n=e.maxAge.match(/([+-]?\d+)(.*)$/);if(null!=n)switch(n[2]){case"months":case"minutes":case"hours":let e=(s=n[2])[0].toUpperCase()+s.slice(1);"Months"==e&&(e="Month"),t["set"+e](+n[1]+t["get"+e]()),this.maxAge=t-r}var s;this.db=await DB(e.cacheName!=i?e.cacheName:"gzip_sw_worker_expiration_cache_private","url",[{name:"url",key:"url"},{name:"version",key:"version"},{name:"route",key:"route"}])}async precheck(e){try{if(this.db==i||0==this.maxAge)return!0;const t=hashCode(getObjectHash(e.request)),r=await this.db.get(e.request.url,"url");return r!=i&&(r.version!=t||r.timestamp0&&t.body!=i){const e=await t.clone().blob();if(e.size>this.maxFileSize)throw sprintf("cache limit exceeded. Deleting item [%s]",ellipsis(t.url)),await this.db.delete(t.url),await l.delete(t),new Error(sprintf("[%s][cache failed] cache size limit exceeded %s of %s",ellipsis(t.url,42),num2FileSize(e.size),num2FileSize(this.maxFileSize)))}try{const t=e.request.url,r=await this.db.get(t,"url"),n=hashCode(getObjectHash(e.request));return r==i||r.version!=n||r.timestampt instanceof Response&&("cors"==t.type||new URL(e.url,self.origin).origin==self.origin)&&"GET"==e.method&&t.ok&&["default","cors","basic","navigate"].includes(t.type)&&!t.bodyUsed,h=new Map,f={add:(e,t,r)=>h.set(e,{key:e,name:r==i?e:r,handle:async e=>await t(e)}),keys:()=>h.keys(),values:()=>h.values(),entries:()=>h.entries(),get:e=>h.get(e),has:e=>h.has(e),delete:e=>h.delete(e),isCacheableRequest:isCacheableRequest};f[Symbol.iterator]=()=>h[Symbol.iterator](),Object.defineProperty(f,"size",{get:()=>h.size});const p=c.app.cacheName,d=c.app.cacheName,m=c.app.cacheName,g=c.app.cacheName;f.add("cf",(async function(e){let t=await caches.match(e.request,{cacheName:p});if(null!=t)return t;if(t=await fetch(e.request),f.isCacheableRequest(e.request,t)){const r=t.clone();caches.open(p).then(t=>t.put(e.request,r))}return t}),"Cache fallback to Network"),f.add("cn",(async function(e){const t=await caches.match(e.request,{cacheName:d}),r=fetch(e.request).then(t=>{if(f.isCacheableRequest(e.request,t)){const r=t.clone();caches.open(d).then(t=>t.put(e.request,r))}return t}).catch(()=>{});return t||r}),"Cache and Network Update"),f.add("co",(async function(e){return await caches.match(e.request,{cacheName:m})}),"Cache Only"),f.add("nf",(async function(e){try{const t=await fetch(e.request);if(null==t)throw new Error("Network error");if(f.isCacheableRequest(e.request,t)){const r=t.clone();caches.open(g).then(t=>t.put(e.request,r))}return t}catch(e){}return caches.match(e.request,{cacheName:g})}),"Network fallback to Cache"),f.add("no",(async function(e){return fetch(e.request)}),"Network Only"),self.addEventListener("activate",e=>{e.waitUntil((async()=>{try{await c.resolve("activate",e)}catch(e){console.error("😭",e)}return self.clients.claim()})())}),self.addEventListener("fetch",e=>{e.respondWith(!e.url||"only-if-cached"===e.request.cache&&"same-origin"!==e.request.mode?fetch(e.request):async function(){let t;const r=c.routes.getRouter(e);if(r!=i)try{if(t=await r.handler.handle(e),t instanceof Response)return t;for(t of await c.routes.resolve("fail",e,t))if(t instanceof Response)return t}catch(e){console.error("😭",e)}return fetch(e.request)}())}),self.addEventListener("install",e=>{e.waitUntil((async()=>{try{await c.resolve("install",e)}catch(e){console.error("😭",e)}return self.skipWaiting()})())});const y=["method","referrer","referrerPolicy","mode","credentials","cache","redirect","integrity","keepalive"];class w{async push(e){const t=await this.cloneRequestData(e),r=await this.getDB();return await r.put({id:hashCode(e.url+y.map(async e=>{let r=t[e];return r==i?"":"headers"==e?r instanceof Headers?[...r.values()].filter(e=>e!=i).join(""):Object.values(r).map(r=>t[e][r]!=i?t[e][r]:"").join(""):"body"==e?await r.text():r}).join("")),lastRetry:Date.now()+864e5,url:e.url,request:t}),this}async cloneRequestData(e){const t={headers:{}};"GET"!==e.method&&(t.body=await e.clone().arrayBuffer());for(const[r,n]of e.headers.entries())t.headers[r]=n;for(const r of y)void 0!==e[r]&&(t[r]=e[r]);return"navigate"===t.mode&&(t.mode="same-origin"),t}async getDB(){return this.db==i&&(this.db=await DB("gzip_sw_worker_sync_requests","id")),this.db}async replay(e){if("{SYNC_API_TAG}"!=e)return;const t=await this.getDB(),r=await t.getAll();r.length;const n=await caches.open("{CACHE_NAME}");for(const e of r){let r=!1;try{e.request.method,e.url;const t=new Request(e.url,e.request);let s=await n.match(t);r=s!=i,r||(s=await fetch(t.clone()),r=s!=i&&s.ok,r&&isCacheableRequest(t,s)&&await n.put(t,s))}catch(e){}(r||e.lastRetry<=Date.now())&&await t.delete(e.id)}}}if(c.app.backgroundSync.enabled){const e=new w;c.on({async install(){for(const e of["gzip_sw_worker_sync_requests","gzip_sw_worker_sync_tasks"]){const t=await DB(e,"id");null!=t&&await t.clear()}}}),c.routes.on({fail(t,r){const n=c.app.backgroundSync;if(0==n.length||-1!=n.method.indexOf(t.method)){const r=t.url.replace(self.origin,"");if(0==n.pattern.length||n.pattern.some(e=>0==r.indexOf(e)))return e.push(t)}}}),self.addEventListener("sync",(function(t){t.tag,t.waitUntil(e.replay(t.tag).catch(e=>console.error({error:e})))}))}c.app.network.limit>0&&self.addEventListener("sync",async e=>{const t=await async function(){let e=await caches.open("{CACHE_NAME}");const t="{preloaded_urls}".map(e=>new URL(e,self.origin).href),r="{pwa_cache_max_file_count}",n=await DB("gzip_sw_worker_expiration_cache_private","url",[{name:"url",key:"url"},{name:"version",key:"version"},{name:"route",key:"route"}]);return async function(){let s=await n.count();if(s>r){sprintf("cleaning up [%s] items present. [%s] items allowed",s,r);for(let a of await n.getAll())if(t.includes(a.url))sprintf("skipped preloaded resource [%s]",a.url);else if(sprintf("removing [%s]",a.url),await e.delete(a.url),await n.delete(a.url),--s<=r)break;sprintf("cleaned up [%s] items present. [%s] items allowed",s,r)}}}();e.waitUntil(t())}),c.app.offline.enabled&&c.routes.on("fail",async e=>{if("navigate"==e.request.mode&&c.app.offline.methods.includes(e.request.method)){if("response"==c.app.offline.type)return new Response(c.app.offline.body,{headers:new Headers({"Content-Type":'text/html; charset="{offline_charset}"'})});if(""!=c.app.offline.url)return caches.match(c.app.offline.url)}});const b=c.routes,v=c.app.scope,k=c.app.network,O=k.caching;let _,R,x,q,j,A,E;({limit:j,maxAge:x,cacheName:A,strategy:E,maxFileSize:q}=k);const N={limit:j,maxAge:x,strategy:E,maxFileSize:q};for(_ of"{exclude_urls}")b.registerRoute(new a(new RegExp(_),f.get("no")));for(_ of k.settings)R=new a(new RegExp("("+_.ext.join(")|(")+")","i"),f.get(_.strategy),_),O&&(({limit:j,maxAge:x,maxFileSize:q}=_),R.addPlugin(new u({limit:j,maxAge:x,maxFileSize:q}))),b.registerRoute(R);for(_ of f)R=new o(v+"{ROUTE}/media/z/"+_[0]+"/",_[1]),O&&R.addPlugin(new u(N)),b.registerRoute(R),c.app.customNetwork.forEach(e=>{let t=v+"{ROUTE}/"+_[0]+"/"+e.prefix+"/";delete e.prefix;let r=new o(t,e);r.addPlugin(new u(e)),b.registerRoute(r)});R=new o(v,f.get(k.strategy)),O&&R.addPlugin(new u(N)),b.setDefaultRouter(R),A=c.app.cacheName,c.on({error(e,t){console.error({error:e,event:t})},async install(){await caches.open(A).then(async e=>await e.addAll(c.app.precache))},async activate(){const e=await DB("gzip_sw_worker_config_cache_private","name"),t=await e.get("gzip");if(t!=i&&"{ROUTE}"!=t.route){let e,t;for(e of"{STORES}")t=await DB(e,"url",[{name:"url",key:"url"},{name:"version",key:"version"},{name:"route",key:"route"}]),t!=i&&t.clear()}await e.put(c.app);const r=await caches.keys(),n=A.split(/_/,2),s=2==n.length&&n[0]+"_";0!=s&&await Promise.all(r.map(e=>0==e.indexOf(s)&&e!=A&&caches.delete(e)))}})}(); \ No newline at end of file From 8096811dc700e073c17a0c839ca001b72b8ba8a0 Mon Sep 17 00:00:00 2001 From: Thierry Bela Date: Sat, 27 Feb 2021 17:53:59 -0500 Subject: [PATCH 2/5] #124 update the version number, #105 fix notice error, #125 use rollup to build OneSignal script --- config/rollup/rollup.config.js | 8 +++ config/terser/terser.config.js | 11 ---- helpers/CSS.php | 1 + rollup.config.js | 9 +++ terser.config.js | 12 ---- worker/dist/browser.administrator.js | 2 +- worker/dist/browser.js | 2 +- worker/dist/browser.prefetch.js | 17 ----- worker/dist/browser.prefetch.min.js | 2 +- worker/dist/browser.uninstall.js | 2 +- worker/dist/onesignal.js | 94 +++++++++++++++++----------- worker/dist/onesignal.min.js | 2 +- worker/dist/serviceworker.js | 4 +- worker/dist/serviceworker.min.js | 2 +- worker/src/onesignal/onesignal.js | 13 +++- worker/src/utils/ready.js | 17 ----- worker_version | 2 +- 17 files changed, 93 insertions(+), 107 deletions(-) diff --git a/config/rollup/rollup.config.js b/config/rollup/rollup.config.js index ffd34da..25b26dc 100644 --- a/config/rollup/rollup.config.js +++ b/config/rollup/rollup.config.js @@ -36,6 +36,14 @@ export const serviceworker = { } }; +export const oneSignal = { + input: "./worker/src/onesignal/onesignal.js", + output: { + file: "./worker/dist/onesignal.js", + format: "iife" + } +}; + export const serviceworkerAdmin = { input: "worker/src/administrator/index.js", output: { diff --git a/config/terser/terser.config.js b/config/terser/terser.config.js index cadecb4..d69a7f5 100644 --- a/config/terser/terser.config.js +++ b/config/terser/terser.config.js @@ -92,17 +92,6 @@ export const intersectionObserver = { } }; -export const oneSignal = { - input: "./worker/src/onesignal/onesignal.js", - output: "./worker/dist/onesignal.js", - config: { - // ie8: true, - ecma: ECMA_VERSION, - output, - warnings: true - } -}; - export const imageLoaderMin = { input: "./imagesloader.js", output: "./imagesloader.min.js", diff --git a/helpers/CSS.php b/helpers/CSS.php index 965aa67..7dff116 100644 --- a/helpers/CSS.php +++ b/helpers/CSS.php @@ -170,6 +170,7 @@ public function processHTML($html, array $options = []) // parsing css can be expansive // let do it only when needed if (!empty($options['parseinlinecss']) && + !empty($attributes['style']) && strpos($attributes['style'], 'background') !== false && strpos($attributes['style'], 'url(') !== false && !empty($attributes['style'])) { diff --git a/rollup.config.js b/rollup.config.js index 8a8996d..d894123 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -39,6 +39,14 @@ } }; + const oneSignal = { + input: "./worker/src/onesignal/onesignal.js", + output: { + file: "./worker/dist/onesignal.js", + format: "iife" + } + }; + const serviceworkerAdmin = { input: "worker/src/administrator/index.js", output: { @@ -69,6 +77,7 @@ libReady: libReady, libImages: libImages, serviceworker: serviceworker, + oneSignal: oneSignal, serviceworkerAdmin: serviceworkerAdmin, browserPrefetch: browserPrefetch, sync: sync diff --git a/terser.config.js b/terser.config.js index 7bfc65c..95e0d20 100644 --- a/terser.config.js +++ b/terser.config.js @@ -95,17 +95,6 @@ } }; - const oneSignal = { - input: "./worker/src/onesignal/onesignal.js", - output: "./worker/dist/onesignal.js", - config: { - // ie8: true, - ecma: ECMA_VERSION, - output, - warnings: true - } - }; - const imageLoaderMin = { input: "./imagesloader.js", output: "./imagesloader.min.js", @@ -251,7 +240,6 @@ imageLoader: imageLoader, bgStyles: bgStyles, intersectionObserver: intersectionObserver, - oneSignal: oneSignal, imageLoaderMin: imageLoaderMin, bgStylesMin: bgStylesMin, loaderMin: loaderMin, diff --git a/worker/dist/browser.administrator.js b/worker/dist/browser.administrator.js index fcf9bae..e8a8538 100644 --- a/worker/dist/browser.administrator.js +++ b/worker/dist/browser.administrator.js @@ -11,7 +11,7 @@ // @ts-check -// build ac3d844 2021-02-07 11:00:41-05:00 +// build 61eb1e1 2021-02-27 17:46:22-05:00 if ("serviceWorker" in navigator) { navigator.serviceWorker. diff --git a/worker/dist/browser.js b/worker/dist/browser.js index f4df288..793724a 100644 --- a/worker/dist/browser.js +++ b/worker/dist/browser.js @@ -11,7 +11,7 @@ // @ts-check -// build ac3d844 2021-02-07 11:00:41-05:00 +// build 61eb1e1 2021-02-27 17:46:22-05:00 if ("serviceWorker" in navigator) { navigator.serviceWorker. diff --git a/worker/dist/browser.prefetch.js b/worker/dist/browser.prefetch.js index 3db8edc..e511a95 100644 --- a/worker/dist/browser.prefetch.js +++ b/worker/dist/browser.prefetch.js @@ -9,7 +9,6 @@ var prefetch = (function (exports) { function domReady() { document.removeEventListener('DOMContentLoaded', domReady); - document.removeEventListener('readystatechange', readystatechange); fired = true; while (queue.length > 0) { @@ -18,23 +17,7 @@ var prefetch = (function (exports) { } } - function readystatechange() { - - switch (document.readyState) { - - case 'loading': - break; - - case 'interactive': - default: - - domReady(); - break; - } - } - document.addEventListener('DOMContentLoaded', domReady); - document.addEventListener('readystatechange', readystatechange); function ready(cb) { diff --git a/worker/dist/browser.prefetch.min.js b/worker/dist/browser.prefetch.min.js index cacb0e1..e17230f 100644 --- a/worker/dist/browser.prefetch.min.js +++ b/worker/dist/browser.prefetch.min.js @@ -1 +1 @@ -!function(e){"use strict";const t=[];let n,o="loading"!=document.readyState;function domReady(){for(document.removeEventListener("DOMContentLoaded",domReady),document.removeEventListener("readystatechange",readystatechange),o=!0;t.length>0;)requestAnimationFrame(t.shift())}function readystatechange(){switch(document.readyState){case"loading":break;case"interactive":default:domReady()}}document.addEventListener("DOMContentLoaded",domReady),document.addEventListener("readystatechange",readystatechange);const a=document.createElement("link"),r="instantAllowQueryString"in document.body.dataset,s="instantAllowExternalLinks"in document.body.dataset,d=document.body.dataset.instantFilterType,i=JSON.parse(document.body.dataset.instantFilters),c=new Set;function isPreloadable(e){if(!e||!e.href||n==e.href||c.has(e.href)||!s&&e.origin!=location.origin||!["http:","https:"].includes(e.protocol)||e.protocol!=location.protocol||!r&&e.search&&!("instant"in e.dataset))return!1;if(i.length>0){const t=i.some((function(t){return-1!=e.pathname.indexOf(t)}));if(1==d&&!t||2==d&&t)return!1}return!0}function preload(e){c.has(e)||(a.href=e),c.add(e)}function stopPreloading(){a.removeAttribute("href")}c.add(""+window.location),function(e){if(o){for(;t.length>0;)requestAnimationFrame(t.shift());e()}else t.push(e)}((function(){let e,t;const o=a.relList&&a.relList.supports&&a.relList.supports("prefetch"),r=navigator.connection&&navigator.connection.saveData;let s=+document.body.dataset.instantIntensity||65,d=document.body.dataset.instantTrigger;function touchendAndTouchcancelListener(){n=void 0,stopPreloading()}function mouseoutListener(t){t.relatedTarget&&t.target.closest("a")===t.relatedTarget.closest("a")||(e&&(clearTimeout(e),e=void 0),n=void 0,stopPreloading())}o&&!r&&(a.rel="prefetch",document.head.appendChild(a),!("mousedown"in document.documentElement)&&"ontouchstart"in document.documentElement&&(d="touchstart"),document.addEventListener(d,"touchstart"===d?function(e){t=performance.now();const o=e.target.closest("a");isPreloadable(o)&&(o.addEventListener("touchcancel",touchendAndTouchcancelListener,{passive:!0}),o.addEventListener("touchend",touchendAndTouchcancelListener,{passive:!0}),n=o.href,preload(o.href))}:"mousedown"===d?function(e){const t=e.target.closest("a");isPreloadable(t)&&(t.addEventListener("mouseout",mouseoutListener,{passive:!0}),n=t.href,preload(t.href))}:function(o){if(performance.now()-t<1100)return;const a=o.target.closest("a");isPreloadable(a)&&(a.addEventListener("mouseout",mouseoutListener,{passive:!0}),n=a.href,e=setTimeout(()=>{preload(a.href),e=void 0},s))},{capture:!0,passive:!0}))})),e.isPreloadable=isPreloadable,e.preload=preload,e.stopPreloading=stopPreloading}({}); \ No newline at end of file +!function(e){"use strict";const t=[];let n,o="loading"!=document.readyState;document.addEventListener("DOMContentLoaded",(function domReady(){for(document.removeEventListener("DOMContentLoaded",domReady),o=!0;t.length>0;)requestAnimationFrame(t.shift())}));const a=document.createElement("link"),r="instantAllowQueryString"in document.body.dataset,s="instantAllowExternalLinks"in document.body.dataset,i=document.body.dataset.instantFilterType,d=JSON.parse(document.body.dataset.instantFilters),c=new Set;function isPreloadable(e){if(!e||!e.href||n==e.href||c.has(e.href)||!s&&e.origin!=location.origin||!["http:","https:"].includes(e.protocol)||e.protocol!=location.protocol||!r&&e.search&&!("instant"in e.dataset))return!1;if(d.length>0){const t=d.some((function(t){return-1!=e.pathname.indexOf(t)}));if(1==i&&!t||2==i&&t)return!1}return!0}function preload(e){c.has(e)||(a.href=e),c.add(e)}function stopPreloading(){a.removeAttribute("href")}c.add(""+window.location),function(e){if(o){for(;t.length>0;)requestAnimationFrame(t.shift());e()}else t.push(e)}((function(){let e,t;const o=a.relList&&a.relList.supports&&a.relList.supports("prefetch"),r=navigator.connection&&navigator.connection.saveData;let s=+document.body.dataset.instantIntensity||65,i=document.body.dataset.instantTrigger;function touchendAndTouchcancelListener(){n=void 0,stopPreloading()}function mouseoutListener(t){t.relatedTarget&&t.target.closest("a")===t.relatedTarget.closest("a")||(e&&(clearTimeout(e),e=void 0),n=void 0,stopPreloading())}o&&!r&&(a.rel="prefetch",document.head.appendChild(a),!("mousedown"in document.documentElement)&&"ontouchstart"in document.documentElement&&(i="touchstart"),document.addEventListener(i,"touchstart"===i?function(e){t=performance.now();const o=e.target.closest("a");isPreloadable(o)&&(o.addEventListener("touchcancel",touchendAndTouchcancelListener,{passive:!0}),o.addEventListener("touchend",touchendAndTouchcancelListener,{passive:!0}),n=o.href,preload(o.href))}:"mousedown"===i?function(e){const t=e.target.closest("a");isPreloadable(t)&&(t.addEventListener("mouseout",mouseoutListener,{passive:!0}),n=t.href,preload(t.href))}:function(o){if(performance.now()-t<1100)return;const a=o.target.closest("a");isPreloadable(a)&&(a.addEventListener("mouseout",mouseoutListener,{passive:!0}),n=a.href,e=setTimeout(()=>{preload(a.href),e=void 0},s))},{capture:!0,passive:!0}))})),e.isPreloadable=isPreloadable,e.preload=preload,e.stopPreloading=stopPreloading}({}); \ No newline at end of file diff --git a/worker/dist/browser.uninstall.js b/worker/dist/browser.uninstall.js index 35b82e3..0b88766 100644 --- a/worker/dist/browser.uninstall.js +++ b/worker/dist/browser.uninstall.js @@ -10,7 +10,7 @@ */ // @ts-check -// build ac3d844 2021-02-07 11:00:41-05:00 +// build 61eb1e1 2021-02-27 17:46:22-05:00 if ("serviceWorker" in navigator && navigator.serviceWorker.controller) { navigator.serviceWorker.getRegistration().then(function (registration) { diff --git a/worker/dist/onesignal.js b/worker/dist/onesignal.js index caca78b..36ca7e3 100644 --- a/worker/dist/onesignal.js +++ b/worker/dist/onesignal.js @@ -1,38 +1,56 @@ -/* do not edit this file! */ -/** - * - * @package GZip Plugin - * @copyright Copyright (C) 2005 - 2018 Thierry Bela. - * - * dual licensed - * - * @license LGPL v3 - * @license MIT License - */ -// @ts-check -/* wrap-iife: 0 */ -!function(n, e) { - n.src = "https://cdn.onesignal.com/sdks/OneSignalSDK.js", n.defer = !0, n.async = !0, - n.onload = function() { - const n = window.OneSignal = window.OneSignal || []; - n.push((function() { - n.init({ - appId: "{APP_ID}" - }); - } - /*, - // get user ID - function() { - OneSignal.on("subscriptionChange", function(isSubscribed) { - if (isSubscribed) { - // The user is subscribed - // Either the user subscribed for the first time - // Or the user was subscribed -> unsubscribed -> subscribed - OneSignal.getUserId(function(userId) { - // Make a POST call to your server with the user ID - }); - } - }); - } */)); - }, e.removeChild(e.appendChild(n)); -}(document.createElement("script"), document.body); \ No newline at end of file +(function () { + 'use strict'; + + /** + * + * @package GZip Plugin + * @copyright Copyright (C) 2005 - 2018 Thierry Bela. + * + * dual licensed + * + * @license LGPL v3 + * @license MIT License + */ + + // @ts-check + /* wrap-iife: 0 */ + + !(function(script, window) { + script.src = "https://cdn.onesignal.com/sdks/OneSignalSDK.js"; + script.defer = true; + script.async = true; + + script.onload = function() { + const OneSignal = (window.OneSignal = window.OneSignal || []); + + OneSignal.push( + function() { + OneSignal.init({ appId: "{APP_ID}" }); + } /*, + // get user ID + function() { + OneSignal.on("subscriptionChange", function(isSubscribed) { + if (isSubscribed) { + // The user is subscribed + // Either the user subscribed for the first time + // Or the user was subscribed -> unsubscribed -> subscribed + OneSignal.getUserId(function(userId) { + // Make a POST call to your server with the user ID + }); + } + }); + } */ + ); + }; + + window.addEventListener('DOMContentLoaded', function l() { + + let body = document.body; + + body.removeChild(body.appendChild(script)); + window.removeEventListener('DOMContentLoaded', l); + }); + + }(document.createElement("script"), window)); + +}()); diff --git a/worker/dist/onesignal.min.js b/worker/dist/onesignal.min.js index 8e7b6bc..1981ae7 100644 --- a/worker/dist/onesignal.min.js +++ b/worker/dist/onesignal.min.js @@ -1 +1 @@ -var n,e;n=document.createElement("script"),e=document.body,n.src="https://cdn.onesignal.com/sdks/OneSignalSDK.js",n.defer=!0,n.async=!0,n.onload=function(){const d=window.OneSignal=window.OneSignal||[];d.push((function(){d.init({appId:"{APP_ID}"})}))},e.removeChild(e.appendChild(n)); \ No newline at end of file +!function(){"use strict";!function(n,e){n.src="https://cdn.onesignal.com/sdks/OneSignalSDK.js",n.defer=!0,n.async=!0,n.onload=function(){const n=e.OneSignal=e.OneSignal||[];n.push((function(){n.init({appId:"{APP_ID}"})}))},e.addEventListener("DOMContentLoaded",(function l(){let t=document.body;t.removeChild(t.appendChild(n)),e.removeEventListener("DOMContentLoaded",l)}))}(document.createElement("script"),window)}(); \ No newline at end of file diff --git a/worker/dist/serviceworker.js b/worker/dist/serviceworker.js index 03ada82..46e9aa1 100644 --- a/worker/dist/serviceworker.js +++ b/worker/dist/serviceworker.js @@ -881,14 +881,14 @@ * service worker build id */ buildid: { - value: "ac3d844", + value: "61eb1e1", enumerable: true }, /** * service worker buid date */ builddate: { - value: "2021-02-07 11:00:41-05:00", + value: "2021-02-27 17:46:22-05:00", enumerable: true }, /** diff --git a/worker/dist/serviceworker.min.js b/worker/dist/serviceworker.min.js index a92f006..eff39de 100644 --- a/worker/dist/serviceworker.min.js +++ b/worker/dist/serviceworker.min.js @@ -1 +1 @@ -!function(){"use strict";async function DB(e,t="id",r=[]){return new Promise((n,s)=>{const a=indexedDB.open(e,1),o=`${e}_store`;let i;const _query=(e,t,r=null,n=null)=>new Promise((s,a)=>{const c=t?"readonly":"readwrite";if(i.objectStoreNames.contains(o)){const t=i.transaction(o,c),l=t.objectStore(o);let u;"put"===e&&r&&void 0!==r.length?(u=t,r.forEach(e=>{l.put(e)})):(n&&l.index(n),u=l[e](r)),u.oncomplete=e=>{s(e.target.result)},u.onsuccess=e=>{s(e.target.result)},u.onerror=e=>{a(e)}}else a(new Error("Store not found"))}),c={count:async()=>{const e=i.transaction(o,"readonly").objectStore(o).count();return new Promise((function(t,r){e.onsuccess=function(e){t(e.target.result)},e.onerror=function(e){r(e)}}))},get:(e,t)=>_query("get",!0,e,t),getAll:(e,t)=>_query("getAll",!0,e,t),put:e=>_query("put",!1,e),delete:e=>_query("delete",!1,e),clear:()=>_query("clear",!1),deleteDatabase:()=>new Promise((function(e,t){const r=indexedDB.deleteDatabase;r.onerror=t,r.onsuccess=e}))};a.onupgradeneeded=(()=>{i=a.result;const e=i.createObjectStore(o,{keyPath:t});let n;for(n of r)e.createIndex(n.name,n.key,n.options)}).bind(this),a.onsuccess=(()=>{i=a.result,n(c)}).bind(this),a.onerror=(e=>{s(new Error(e.originalTarget&&e.originalTarget.error||e))}).bind(this)})}const e={implement(e){const t=e.prototype,r=[].slice.call(arguments,1);let n,s,a;function makefunc(e,t,r){return function(){const n=this,s="previous"in n,a="parent"in n,o=n.previous,i=n.parent;n.previous=t,n.parent=r;const c=e.apply(n,arguments);return s&&(n.previous=o),a&&(n.parent=i),c}}for(n=0;nfunction(t){if("object"==typeof t){const r=[].slice.call(arguments,1);let n;for(n in t)e.apply(this,[n,t[n]].concat(r))}else e.apply(this,arguments);return this}};function merge(e){const t=[].slice.call(arguments,1);let r,n,s,a,o="boolean"==typeof e;for(!0===o&&(o=e,e=t.shift()),r=0;r1?[].slice.call(arguments,1):[];return Promise.all((t.$events[e]||[]).concat().map(e=>new Promise(n=>{n(e.cb.apply(t,r))})))},addPseudo(e,t){return this.$pseudo[e]=t,this}};function normalize(e="GET"){return Array.isArray(e)||(e=[e]),e.forEach(e=>e==i||"HEAD"==e?"GET":e.toUpperCase()),e}r.addPseudo("once",(function(e){return e.cb=function(){const t=this,r=e.fn.apply(t,arguments);return t.off(e.name,e.fn),r},this}));class n{constructor(){this.routers=Object.create(i),this.defaultRouter=Object.create(i)}getRouter(e){const t=e!=i&&e.request.method||"GET",r=this.routers[t]||[],n=r.length;let s,a=0;for(;a{t in this.routers||(this.routers[t]=[]),this.routers[t].push(e)}),this}unregisterRoute(e,t){return normalize(t).forEach(t=>{const r=this.routers[t]||[],n=r.indexOf(e);-1!=n&&r.splice(n,1)}),this}setDefaultRouter(e,t){normalize(t).forEach(t=>this.defaultRouter[t]=e)}getDefaultRouter(){for(let e in this.defaultRouter)return this.defaultRouter[e];return i}}e.merge(!0,n.prototype,r);class s{constructor(e,t,r=null){const n=this;n.plugins=[],n.options=Object.assign(Object.create(i),{mime:[]},r||{}),n.path=e,n.strategy=t.name,n.handler={handle:async e=>{let r,s;for(r of n.plugins)try{if(s=await r.precheck(e),s instanceof Response)return s}catch(e){console.error({error:e})}if(s=await t.handle(e),s instanceof Response)for(r of n.plugins)try{await r.postcheck(e,s)}catch(e){console.error(e.message)}return s}}}addPlugin(e){return this.plugins.includes(e)||this.plugins.push(e),this}match(e,t){return!0}}e.merge(!0,s.prototype,r);class a extends s{match(e,t){const r=e.request.url;return/^https?:/.test(r)&&this.path.test(r)||this.options.mime.includes(e.request.headers.get("Content-Type"))||t!=i&&this.options.mime.includes(t.headers.get("Content-Type"))}}class o extends s{constructor(e,t,r=null){super(e,t,r),this.url=new URL(e,self.origin)}match(e,t){const r=e.request.url,n=new URL(r);return/^https?:/.test(r)&&n.origin==this.url.origin&&0==n.pathname.indexOf(this.url.pathname)||this.options.mime.includes(e.request.headers.get("Content-Type"))||t!=i&&this.options.mime.includes(t.headers.get("Content-Type"))}}const i=null,c=Object.create(i);function hashCode(e){var t,r=0;if(0===e.length)return r;for(t=0;ta+=t+":"+getObjectHash(e)+","),","==a[a.length-1]&&(a=a.substr(0,a.length-2)),a+="}";else{for(n of(a+="[",r))a+=getObjectHash(n)+",";","==a[a.length-1]&&(a=a.substr(0,a.length-2)),a+="]"}else a+="{"+getObjectHash(r)+"}";else a+=""+r;else a+=JSON.stringify(r);a+=","}","==a[a.length-1]&&(a=a.substr(0,a.length-2)),Array.isArray(e)?a="["+a+"]":"object"==typeof e&&(a="{"+a+"}")}return a}function num2FileSize(e,t){if(0==e)return 0;const r=Math.floor(Math.log(e)/Math.log(1024));return(e/Math.pow(1024,Math.floor(r))).toFixed(2)+" "+(t&&t[r]?t[r]:["b","Kb","Mb","Gb","Tb","Pb"][r])}function sprintf(e){let t,r=-1;const n=[].slice.apply(arguments).slice(1);return e.replace(/%([s%])/g,(function(e,s){if("%"==s)return s;switch(t=n[++r],s){case"s":return null==t?"":t}}))}function ellipsis(e,t=30,r=15,n="..."){return e.length>t?e.slice(0,t-r-n.length+1)+n+e.slice(e.length-r+1):e}let l;e.merge(!0,c,r),Object.defineProperties(c,{app:{value:Object.create(i)},routes:{value:new n}}),Object.defineProperties(c.app,{name:{value:"gzip",enumerable:!0},scope:{value:"{scope}",enumerable:!0},route:{value:"{ROUTE}",enumerable:!0},cacheName:{value:"{CACHE_NAME}",enumerable:!0},codeName:{value:"Joomla Website Optimizer Plugin",enumerable:!0},build:{value:"{VERSION}",enumerable:!0},buildid:{value:"ac3d844",enumerable:!0},builddate:{value:"2021-02-07 11:00:41-05:00",enumerable:!0},urls:{value:"{CDN_HOSTS}",enumerable:!0},backgroundSync:{value:"{BACKGROUND_SYNC}",enumerable:!0},offline:{value:"{pwa_offline_page}"},network:{value:"{pwa_cache_settings}"},customNetwork:{value:"{pwa_custom_cache_settings}"},precache:{value:"{preloaded_urls}".map(e=>new URL(e,self.origin).href),enumerable:!0},homepage:{value:"https://github.com/tbela99/gzip",enumerable:!0}}),caches.open(c.app.cacheName).then(e=>l=e);class u{constructor(e){this.setOptions(e)}getRouteTag(e){const t=c.app.route;let r;for(r of c.app.urls)if(new RegExp("^https?://"+r+c.app.scope+t+"/").test(e))return t;return i}async setOptions(e){const t=new Date,r=+t;this.maxAge=0,this.limit=+e.limit||0,this.maxFileSize=+e.maxFileSize||0;const n=e.maxAge.match(/([+-]?\d+)(.*)$/);if(null!=n)switch(n[2]){case"months":case"minutes":case"hours":let e=(s=n[2])[0].toUpperCase()+s.slice(1);"Months"==e&&(e="Month"),t["set"+e](+n[1]+t["get"+e]()),this.maxAge=t-r}var s;this.db=await DB(e.cacheName!=i?e.cacheName:"gzip_sw_worker_expiration_cache_private","url",[{name:"url",key:"url"},{name:"version",key:"version"},{name:"route",key:"route"}])}async precheck(e){try{if(this.db==i||0==this.maxAge)return!0;const t=hashCode(getObjectHash(e.request)),r=await this.db.get(e.request.url,"url");return r!=i&&(r.version!=t||r.timestamp0&&t.body!=i){const e=await t.clone().blob();if(e.size>this.maxFileSize)throw sprintf("cache limit exceeded. Deleting item [%s]",ellipsis(t.url)),await this.db.delete(t.url),await l.delete(t),new Error(sprintf("[%s][cache failed] cache size limit exceeded %s of %s",ellipsis(t.url,42),num2FileSize(e.size),num2FileSize(this.maxFileSize)))}try{const t=e.request.url,r=await this.db.get(t,"url"),n=hashCode(getObjectHash(e.request));return r==i||r.version!=n||r.timestampt instanceof Response&&("cors"==t.type||new URL(e.url,self.origin).origin==self.origin)&&"GET"==e.method&&t.ok&&["default","cors","basic","navigate"].includes(t.type)&&!t.bodyUsed,h=new Map,f={add:(e,t,r)=>h.set(e,{key:e,name:r==i?e:r,handle:async e=>await t(e)}),keys:()=>h.keys(),values:()=>h.values(),entries:()=>h.entries(),get:e=>h.get(e),has:e=>h.has(e),delete:e=>h.delete(e),isCacheableRequest:isCacheableRequest};f[Symbol.iterator]=()=>h[Symbol.iterator](),Object.defineProperty(f,"size",{get:()=>h.size});const p=c.app.cacheName,d=c.app.cacheName,m=c.app.cacheName,g=c.app.cacheName;f.add("cf",(async function(e){let t=await caches.match(e.request,{cacheName:p});if(null!=t)return t;if(t=await fetch(e.request),f.isCacheableRequest(e.request,t)){const r=t.clone();caches.open(p).then(t=>t.put(e.request,r))}return t}),"Cache fallback to Network"),f.add("cn",(async function(e){const t=await caches.match(e.request,{cacheName:d}),r=fetch(e.request).then(t=>{if(f.isCacheableRequest(e.request,t)){const r=t.clone();caches.open(d).then(t=>t.put(e.request,r))}return t}).catch(()=>{});return t||r}),"Cache and Network Update"),f.add("co",(async function(e){return await caches.match(e.request,{cacheName:m})}),"Cache Only"),f.add("nf",(async function(e){try{const t=await fetch(e.request);if(null==t)throw new Error("Network error");if(f.isCacheableRequest(e.request,t)){const r=t.clone();caches.open(g).then(t=>t.put(e.request,r))}return t}catch(e){}return caches.match(e.request,{cacheName:g})}),"Network fallback to Cache"),f.add("no",(async function(e){return fetch(e.request)}),"Network Only"),self.addEventListener("activate",e=>{e.waitUntil((async()=>{try{await c.resolve("activate",e)}catch(e){console.error("😭",e)}return self.clients.claim()})())}),self.addEventListener("fetch",e=>{e.respondWith(!e.url||"only-if-cached"===e.request.cache&&"same-origin"!==e.request.mode?fetch(e.request):async function(){let t;const r=c.routes.getRouter(e);if(r!=i)try{if(t=await r.handler.handle(e),t instanceof Response)return t;for(t of await c.routes.resolve("fail",e,t))if(t instanceof Response)return t}catch(e){console.error("😭",e)}return fetch(e.request)}())}),self.addEventListener("install",e=>{e.waitUntil((async()=>{try{await c.resolve("install",e)}catch(e){console.error("😭",e)}return self.skipWaiting()})())});const y=["method","referrer","referrerPolicy","mode","credentials","cache","redirect","integrity","keepalive"];class w{async push(e){const t=await this.cloneRequestData(e),r=await this.getDB();return await r.put({id:hashCode(e.url+y.map(async e=>{let r=t[e];return r==i?"":"headers"==e?r instanceof Headers?[...r.values()].filter(e=>e!=i).join(""):Object.values(r).map(r=>t[e][r]!=i?t[e][r]:"").join(""):"body"==e?await r.text():r}).join("")),lastRetry:Date.now()+864e5,url:e.url,request:t}),this}async cloneRequestData(e){const t={headers:{}};"GET"!==e.method&&(t.body=await e.clone().arrayBuffer());for(const[r,n]of e.headers.entries())t.headers[r]=n;for(const r of y)void 0!==e[r]&&(t[r]=e[r]);return"navigate"===t.mode&&(t.mode="same-origin"),t}async getDB(){return this.db==i&&(this.db=await DB("gzip_sw_worker_sync_requests","id")),this.db}async replay(e){if("{SYNC_API_TAG}"!=e)return;const t=await this.getDB(),r=await t.getAll();r.length;const n=await caches.open("{CACHE_NAME}");for(const e of r){let r=!1;try{e.request.method,e.url;const t=new Request(e.url,e.request);let s=await n.match(t);r=s!=i,r||(s=await fetch(t.clone()),r=s!=i&&s.ok,r&&isCacheableRequest(t,s)&&await n.put(t,s))}catch(e){}(r||e.lastRetry<=Date.now())&&await t.delete(e.id)}}}if(c.app.backgroundSync.enabled){const e=new w;c.on({async install(){for(const e of["gzip_sw_worker_sync_requests","gzip_sw_worker_sync_tasks"]){const t=await DB(e,"id");null!=t&&await t.clear()}}}),c.routes.on({fail(t,r){const n=c.app.backgroundSync;if(0==n.length||-1!=n.method.indexOf(t.method)){const r=t.url.replace(self.origin,"");if(0==n.pattern.length||n.pattern.some(e=>0==r.indexOf(e)))return e.push(t)}}}),self.addEventListener("sync",(function(t){t.tag,t.waitUntil(e.replay(t.tag).catch(e=>console.error({error:e})))}))}c.app.network.limit>0&&self.addEventListener("sync",async e=>{const t=await async function(){let e=await caches.open("{CACHE_NAME}");const t="{preloaded_urls}".map(e=>new URL(e,self.origin).href),r="{pwa_cache_max_file_count}",n=await DB("gzip_sw_worker_expiration_cache_private","url",[{name:"url",key:"url"},{name:"version",key:"version"},{name:"route",key:"route"}]);return async function(){let s=await n.count();if(s>r){sprintf("cleaning up [%s] items present. [%s] items allowed",s,r);for(let a of await n.getAll())if(t.includes(a.url))sprintf("skipped preloaded resource [%s]",a.url);else if(sprintf("removing [%s]",a.url),await e.delete(a.url),await n.delete(a.url),--s<=r)break;sprintf("cleaned up [%s] items present. [%s] items allowed",s,r)}}}();e.waitUntil(t())}),c.app.offline.enabled&&c.routes.on("fail",async e=>{if("navigate"==e.request.mode&&c.app.offline.methods.includes(e.request.method)){if("response"==c.app.offline.type)return new Response(c.app.offline.body,{headers:new Headers({"Content-Type":'text/html; charset="{offline_charset}"'})});if(""!=c.app.offline.url)return caches.match(c.app.offline.url)}});const b=c.routes,v=c.app.scope,k=c.app.network,O=k.caching;let _,R,x,q,j,A,E;({limit:j,maxAge:x,cacheName:A,strategy:E,maxFileSize:q}=k);const N={limit:j,maxAge:x,strategy:E,maxFileSize:q};for(_ of"{exclude_urls}")b.registerRoute(new a(new RegExp(_),f.get("no")));for(_ of k.settings)R=new a(new RegExp("("+_.ext.join(")|(")+")","i"),f.get(_.strategy),_),O&&(({limit:j,maxAge:x,maxFileSize:q}=_),R.addPlugin(new u({limit:j,maxAge:x,maxFileSize:q}))),b.registerRoute(R);for(_ of f)R=new o(v+"{ROUTE}/media/z/"+_[0]+"/",_[1]),O&&R.addPlugin(new u(N)),b.registerRoute(R),c.app.customNetwork.forEach(e=>{let t=v+"{ROUTE}/"+_[0]+"/"+e.prefix+"/";delete e.prefix;let r=new o(t,e);r.addPlugin(new u(e)),b.registerRoute(r)});R=new o(v,f.get(k.strategy)),O&&R.addPlugin(new u(N)),b.setDefaultRouter(R),A=c.app.cacheName,c.on({error(e,t){console.error({error:e,event:t})},async install(){await caches.open(A).then(async e=>await e.addAll(c.app.precache))},async activate(){const e=await DB("gzip_sw_worker_config_cache_private","name"),t=await e.get("gzip");if(t!=i&&"{ROUTE}"!=t.route){let e,t;for(e of"{STORES}")t=await DB(e,"url",[{name:"url",key:"url"},{name:"version",key:"version"},{name:"route",key:"route"}]),t!=i&&t.clear()}await e.put(c.app);const r=await caches.keys(),n=A.split(/_/,2),s=2==n.length&&n[0]+"_";0!=s&&await Promise.all(r.map(e=>0==e.indexOf(s)&&e!=A&&caches.delete(e)))}})}(); \ No newline at end of file +!function(){"use strict";async function DB(e,t="id",r=[]){return new Promise((n,s)=>{const a=indexedDB.open(e,1),o=`${e}_store`;let i;const _query=(e,t,r=null,n=null)=>new Promise((s,a)=>{const c=t?"readonly":"readwrite";if(i.objectStoreNames.contains(o)){const t=i.transaction(o,c),l=t.objectStore(o);let u;"put"===e&&r&&void 0!==r.length?(u=t,r.forEach(e=>{l.put(e)})):(n&&l.index(n),u=l[e](r)),u.oncomplete=e=>{s(e.target.result)},u.onsuccess=e=>{s(e.target.result)},u.onerror=e=>{a(e)}}else a(new Error("Store not found"))}),c={count:async()=>{const e=i.transaction(o,"readonly").objectStore(o).count();return new Promise((function(t,r){e.onsuccess=function(e){t(e.target.result)},e.onerror=function(e){r(e)}}))},get:(e,t)=>_query("get",!0,e,t),getAll:(e,t)=>_query("getAll",!0,e,t),put:e=>_query("put",!1,e),delete:e=>_query("delete",!1,e),clear:()=>_query("clear",!1),deleteDatabase:()=>new Promise((function(e,t){const r=indexedDB.deleteDatabase;r.onerror=t,r.onsuccess=e}))};a.onupgradeneeded=(()=>{i=a.result;const e=i.createObjectStore(o,{keyPath:t});let n;for(n of r)e.createIndex(n.name,n.key,n.options)}).bind(this),a.onsuccess=(()=>{i=a.result,n(c)}).bind(this),a.onerror=(e=>{s(new Error(e.originalTarget&&e.originalTarget.error||e))}).bind(this)})}const e={implement(e){const t=e.prototype,r=[].slice.call(arguments,1);let n,s,a;function makefunc(e,t,r){return function(){const n=this,s="previous"in n,a="parent"in n,o=n.previous,i=n.parent;n.previous=t,n.parent=r;const c=e.apply(n,arguments);return s&&(n.previous=o),a&&(n.parent=i),c}}for(n=0;nfunction(t){if("object"==typeof t){const r=[].slice.call(arguments,1);let n;for(n in t)e.apply(this,[n,t[n]].concat(r))}else e.apply(this,arguments);return this}};function merge(e){const t=[].slice.call(arguments,1);let r,n,s,a,o="boolean"==typeof e;for(!0===o&&(o=e,e=t.shift()),r=0;r1?[].slice.call(arguments,1):[];return Promise.all((t.$events[e]||[]).concat().map(e=>new Promise(n=>{n(e.cb.apply(t,r))})))},addPseudo(e,t){return this.$pseudo[e]=t,this}};function normalize(e="GET"){return Array.isArray(e)||(e=[e]),e.forEach(e=>e==i||"HEAD"==e?"GET":e.toUpperCase()),e}r.addPseudo("once",(function(e){return e.cb=function(){const t=this,r=e.fn.apply(t,arguments);return t.off(e.name,e.fn),r},this}));class n{constructor(){this.routers=Object.create(i),this.defaultRouter=Object.create(i)}getRouter(e){const t=e!=i&&e.request.method||"GET",r=this.routers[t]||[],n=r.length;let s,a=0;for(;a{t in this.routers||(this.routers[t]=[]),this.routers[t].push(e)}),this}unregisterRoute(e,t){return normalize(t).forEach(t=>{const r=this.routers[t]||[],n=r.indexOf(e);-1!=n&&r.splice(n,1)}),this}setDefaultRouter(e,t){normalize(t).forEach(t=>this.defaultRouter[t]=e)}getDefaultRouter(){for(let e in this.defaultRouter)return this.defaultRouter[e];return i}}e.merge(!0,n.prototype,r);class s{constructor(e,t,r=null){const n=this;n.plugins=[],n.options=Object.assign(Object.create(i),{mime:[]},r||{}),n.path=e,n.strategy=t.name,n.handler={handle:async e=>{let r,s;for(r of n.plugins)try{if(s=await r.precheck(e),s instanceof Response)return s}catch(e){console.error({error:e})}if(s=await t.handle(e),s instanceof Response)for(r of n.plugins)try{await r.postcheck(e,s)}catch(e){console.error(e.message)}return s}}}addPlugin(e){return this.plugins.includes(e)||this.plugins.push(e),this}match(e,t){return!0}}e.merge(!0,s.prototype,r);class a extends s{match(e,t){const r=e.request.url;return/^https?:/.test(r)&&this.path.test(r)||this.options.mime.includes(e.request.headers.get("Content-Type"))||t!=i&&this.options.mime.includes(t.headers.get("Content-Type"))}}class o extends s{constructor(e,t,r=null){super(e,t,r),this.url=new URL(e,self.origin)}match(e,t){const r=e.request.url,n=new URL(r);return/^https?:/.test(r)&&n.origin==this.url.origin&&0==n.pathname.indexOf(this.url.pathname)||this.options.mime.includes(e.request.headers.get("Content-Type"))||t!=i&&this.options.mime.includes(t.headers.get("Content-Type"))}}const i=null,c=Object.create(i);function hashCode(e){var t,r=0;if(0===e.length)return r;for(t=0;ta+=t+":"+getObjectHash(e)+","),","==a[a.length-1]&&(a=a.substr(0,a.length-2)),a+="}";else{for(n of(a+="[",r))a+=getObjectHash(n)+",";","==a[a.length-1]&&(a=a.substr(0,a.length-2)),a+="]"}else a+="{"+getObjectHash(r)+"}";else a+=""+r;else a+=JSON.stringify(r);a+=","}","==a[a.length-1]&&(a=a.substr(0,a.length-2)),Array.isArray(e)?a="["+a+"]":"object"==typeof e&&(a="{"+a+"}")}return a}function num2FileSize(e,t){if(0==e)return 0;const r=Math.floor(Math.log(e)/Math.log(1024));return(e/Math.pow(1024,Math.floor(r))).toFixed(2)+" "+(t&&t[r]?t[r]:["b","Kb","Mb","Gb","Tb","Pb"][r])}function sprintf(e){let t,r=-1;const n=[].slice.apply(arguments).slice(1);return e.replace(/%([s%])/g,(function(e,s){if("%"==s)return s;switch(t=n[++r],s){case"s":return null==t?"":t}}))}function ellipsis(e,t=30,r=15,n="..."){return e.length>t?e.slice(0,t-r-n.length+1)+n+e.slice(e.length-r+1):e}let l;e.merge(!0,c,r),Object.defineProperties(c,{app:{value:Object.create(i)},routes:{value:new n}}),Object.defineProperties(c.app,{name:{value:"gzip",enumerable:!0},scope:{value:"{scope}",enumerable:!0},route:{value:"{ROUTE}",enumerable:!0},cacheName:{value:"{CACHE_NAME}",enumerable:!0},codeName:{value:"Joomla Website Optimizer Plugin",enumerable:!0},build:{value:"{VERSION}",enumerable:!0},buildid:{value:"build-id",enumerable:!0},builddate:{value:"build-date",enumerable:!0},urls:{value:"{CDN_HOSTS}",enumerable:!0},backgroundSync:{value:"{BACKGROUND_SYNC}",enumerable:!0},offline:{value:"{pwa_offline_page}"},network:{value:"{pwa_cache_settings}"},customNetwork:{value:"{pwa_custom_cache_settings}"},precache:{value:"{preloaded_urls}".map(e=>new URL(e,self.origin).href),enumerable:!0},homepage:{value:"https://github.com/tbela99/gzip",enumerable:!0}}),caches.open(c.app.cacheName).then(e=>l=e);class u{constructor(e){this.setOptions(e)}getRouteTag(e){const t=c.app.route;let r;for(r of c.app.urls)if(new RegExp("^https?://"+r+c.app.scope+t+"/").test(e))return t;return i}async setOptions(e){const t=new Date,r=+t;this.maxAge=0,this.limit=+e.limit||0,this.maxFileSize=+e.maxFileSize||0;const n=e.maxAge.match(/([+-]?\d+)(.*)$/);if(null!=n)switch(n[2]){case"months":case"minutes":case"hours":let e=(s=n[2])[0].toUpperCase()+s.slice(1);"Months"==e&&(e="Month"),t["set"+e](+n[1]+t["get"+e]()),this.maxAge=t-r}var s;this.db=await DB(e.cacheName!=i?e.cacheName:"gzip_sw_worker_expiration_cache_private","url",[{name:"url",key:"url"},{name:"version",key:"version"},{name:"route",key:"route"}])}async precheck(e){try{if(this.db==i||0==this.maxAge)return!0;const t=hashCode(getObjectHash(e.request)),r=await this.db.get(e.request.url,"url");return r!=i&&(r.version!=t||r.timestamp0&&t.body!=i){const e=await t.clone().blob();if(e.size>this.maxFileSize)throw sprintf("cache limit exceeded. Deleting item [%s]",ellipsis(t.url)),await this.db.delete(t.url),await l.delete(t),new Error(sprintf("[%s][cache failed] cache size limit exceeded %s of %s",ellipsis(t.url,42),num2FileSize(e.size),num2FileSize(this.maxFileSize)))}try{const t=e.request.url,r=await this.db.get(t,"url"),n=hashCode(getObjectHash(e.request));return r==i||r.version!=n||r.timestampt instanceof Response&&("cors"==t.type||new URL(e.url,self.origin).origin==self.origin)&&"GET"==e.method&&t.ok&&["default","cors","basic","navigate"].includes(t.type)&&!t.bodyUsed,h=new Map,f={add:(e,t,r)=>h.set(e,{key:e,name:r==i?e:r,handle:async e=>await t(e)}),keys:()=>h.keys(),values:()=>h.values(),entries:()=>h.entries(),get:e=>h.get(e),has:e=>h.has(e),delete:e=>h.delete(e),isCacheableRequest:isCacheableRequest};f[Symbol.iterator]=()=>h[Symbol.iterator](),Object.defineProperty(f,"size",{get:()=>h.size});const p=c.app.cacheName,d=c.app.cacheName,m=c.app.cacheName,g=c.app.cacheName;f.add("cf",(async function(e){let t=await caches.match(e.request,{cacheName:p});if(null!=t)return t;if(t=await fetch(e.request),f.isCacheableRequest(e.request,t)){const r=t.clone();caches.open(p).then(t=>t.put(e.request,r))}return t}),"Cache fallback to Network"),f.add("cn",(async function(e){const t=await caches.match(e.request,{cacheName:d}),r=fetch(e.request).then(t=>{if(f.isCacheableRequest(e.request,t)){const r=t.clone();caches.open(d).then(t=>t.put(e.request,r))}return t}).catch(()=>{});return t||r}),"Cache and Network Update"),f.add("co",(async function(e){return await caches.match(e.request,{cacheName:m})}),"Cache Only"),f.add("nf",(async function(e){try{const t=await fetch(e.request);if(null==t)throw new Error("Network error");if(f.isCacheableRequest(e.request,t)){const r=t.clone();caches.open(g).then(t=>t.put(e.request,r))}return t}catch(e){}return caches.match(e.request,{cacheName:g})}),"Network fallback to Cache"),f.add("no",(async function(e){return fetch(e.request)}),"Network Only"),self.addEventListener("activate",e=>{e.waitUntil((async()=>{try{await c.resolve("activate",e)}catch(e){console.error("😭",e)}return self.clients.claim()})())}),self.addEventListener("fetch",e=>{e.respondWith(!e.url||"only-if-cached"===e.request.cache&&"same-origin"!==e.request.mode?fetch(e.request):async function(){let t;const r=c.routes.getRouter(e);if(r!=i)try{if(t=await r.handler.handle(e),t instanceof Response)return t;for(t of await c.routes.resolve("fail",e,t))if(t instanceof Response)return t}catch(e){console.error("😭",e)}return fetch(e.request)}())}),self.addEventListener("install",e=>{e.waitUntil((async()=>{try{await c.resolve("install",e)}catch(e){console.error("😭",e)}return self.skipWaiting()})())});const y=["method","referrer","referrerPolicy","mode","credentials","cache","redirect","integrity","keepalive"];class w{async push(e){const t=await this.cloneRequestData(e),r=await this.getDB();return await r.put({id:hashCode(e.url+y.map(async e=>{let r=t[e];return r==i?"":"headers"==e?r instanceof Headers?[...r.values()].filter(e=>e!=i).join(""):Object.values(r).map(r=>t[e][r]!=i?t[e][r]:"").join(""):"body"==e?await r.text():r}).join("")),lastRetry:Date.now()+864e5,url:e.url,request:t}),this}async cloneRequestData(e){const t={headers:{}};"GET"!==e.method&&(t.body=await e.clone().arrayBuffer());for(const[r,n]of e.headers.entries())t.headers[r]=n;for(const r of y)void 0!==e[r]&&(t[r]=e[r]);return"navigate"===t.mode&&(t.mode="same-origin"),t}async getDB(){return this.db==i&&(this.db=await DB("gzip_sw_worker_sync_requests","id")),this.db}async replay(e){if("{SYNC_API_TAG}"!=e)return;const t=await this.getDB(),r=await t.getAll();r.length;const n=await caches.open("{CACHE_NAME}");for(const e of r){let r=!1;try{e.request.method,e.url;const t=new Request(e.url,e.request);let s=await n.match(t);r=s!=i,r||(s=await fetch(t.clone()),r=s!=i&&s.ok,r&&isCacheableRequest(t,s)&&await n.put(t,s))}catch(e){}(r||e.lastRetry<=Date.now())&&await t.delete(e.id)}}}if(c.app.backgroundSync.enabled){const e=new w;c.on({async install(){for(const e of["gzip_sw_worker_sync_requests","gzip_sw_worker_sync_tasks"]){const t=await DB(e,"id");null!=t&&await t.clear()}}}),c.routes.on({fail(t,r){const n=c.app.backgroundSync;if(0==n.length||-1!=n.method.indexOf(t.method)){const r=t.url.replace(self.origin,"");if(0==n.pattern.length||n.pattern.some(e=>0==r.indexOf(e)))return e.push(t)}}}),self.addEventListener("sync",(function(t){t.tag,t.waitUntil(e.replay(t.tag).catch(e=>console.error({error:e})))}))}c.app.network.limit>0&&self.addEventListener("sync",async e=>{const t=await async function(){let e=await caches.open("{CACHE_NAME}");const t="{preloaded_urls}".map(e=>new URL(e,self.origin).href),r="{pwa_cache_max_file_count}",n=await DB("gzip_sw_worker_expiration_cache_private","url",[{name:"url",key:"url"},{name:"version",key:"version"},{name:"route",key:"route"}]);return async function(){let s=await n.count();if(s>r){sprintf("cleaning up [%s] items present. [%s] items allowed",s,r);for(let a of await n.getAll())if(t.includes(a.url))sprintf("skipped preloaded resource [%s]",a.url);else if(sprintf("removing [%s]",a.url),await e.delete(a.url),await n.delete(a.url),--s<=r)break;sprintf("cleaned up [%s] items present. [%s] items allowed",s,r)}}}();e.waitUntil(t())}),c.app.offline.enabled&&c.routes.on("fail",async e=>{if("navigate"==e.request.mode&&c.app.offline.methods.includes(e.request.method)){if("response"==c.app.offline.type)return new Response(c.app.offline.body,{headers:new Headers({"Content-Type":'text/html; charset="{offline_charset}"'})});if(""!=c.app.offline.url)return caches.match(c.app.offline.url)}});const b=c.routes,v=c.app.scope,k=c.app.network,O=k.caching;let _,R,x,q,j,A,E;({limit:j,maxAge:x,cacheName:A,strategy:E,maxFileSize:q}=k);const N={limit:j,maxAge:x,strategy:E,maxFileSize:q};for(_ of"{exclude_urls}")b.registerRoute(new a(new RegExp(_),f.get("no")));for(_ of k.settings)R=new a(new RegExp("("+_.ext.join(")|(")+")","i"),f.get(_.strategy),_),O&&(({limit:j,maxAge:x,maxFileSize:q}=_),R.addPlugin(new u({limit:j,maxAge:x,maxFileSize:q}))),b.registerRoute(R);for(_ of f)R=new o(v+"{ROUTE}/media/z/"+_[0]+"/",_[1]),O&&R.addPlugin(new u(N)),b.registerRoute(R),c.app.customNetwork.forEach(e=>{let t=v+"{ROUTE}/"+_[0]+"/"+e.prefix+"/";delete e.prefix;let r=new o(t,e);r.addPlugin(new u(e)),b.registerRoute(r)});R=new o(v,f.get(k.strategy)),O&&R.addPlugin(new u(N)),b.setDefaultRouter(R),A=c.app.cacheName,c.on({error(e,t){console.error({error:e,event:t})},async install(){await caches.open(A).then(async e=>await e.addAll(c.app.precache))},async activate(){const e=await DB("gzip_sw_worker_config_cache_private","name"),t=await e.get("gzip");if(t!=i&&"{ROUTE}"!=t.route){let e,t;for(e of"{STORES}")t=await DB(e,"url",[{name:"url",key:"url"},{name:"version",key:"version"},{name:"route",key:"route"}]),t!=i&&t.clear()}await e.put(c.app);const r=await caches.keys(),n=A.split(/_/,2),s=2==n.length&&n[0]+"_";0!=s&&await Promise.all(r.map(e=>0==e.indexOf(s)&&e!=A&&caches.delete(e)))}})}(); \ No newline at end of file diff --git a/worker/src/onesignal/onesignal.js b/worker/src/onesignal/onesignal.js index 82cb634..ad54206 100644 --- a/worker/src/onesignal/onesignal.js +++ b/worker/src/onesignal/onesignal.js @@ -12,7 +12,7 @@ // @ts-check /* wrap-iife: 0 */ -!(function(script, body) { +!(function(script, window) { script.src = "https://cdn.onesignal.com/sdks/OneSignalSDK.js"; script.defer = true; script.async = true; @@ -40,5 +40,12 @@ ); }; - body.removeChild(body.appendChild(script)); -}(document.createElement("script"), document.body)); + window.addEventListener('DOMContentLoaded', function l() { + + let body = document.body; + + body.removeChild(body.appendChild(script)); + window.removeEventListener('DOMContentLoaded', l); + }); + +}(document.createElement("script"), window)); diff --git a/worker/src/utils/ready.js b/worker/src/utils/ready.js index 28cc1db..5ac9c86 100644 --- a/worker/src/utils/ready.js +++ b/worker/src/utils/ready.js @@ -22,7 +22,6 @@ let fired = document.readyState != 'loading'; function domReady() { document.removeEventListener('DOMContentLoaded', domReady); - document.removeEventListener('readystatechange', readystatechange); fired = true; while (queue.length > 0) { @@ -31,23 +30,7 @@ function domReady() { } } -function readystatechange() { - - switch (document.readyState) { - - case 'loading': - break; - - case 'interactive': - default: - - domReady(); - break; - } -} - document.addEventListener('DOMContentLoaded', domReady); -document.addEventListener('readystatechange', readystatechange); export function ready(cb) { diff --git a/worker_version b/worker_version index b537717..d3d2f18 100644 --- a/worker_version +++ b/worker_version @@ -1 +1 @@ -fcb6d2563285fd1a88d25ad15f3130a87c17e327 +9e76f58a1620ddb3b4f28386277c8ae7e9ff1908 From 2d334399802a186a4849acee8ab2ce803f1e2667 Mon Sep 17 00:00:00 2001 From: Thierry Bela Date: Sat, 27 Feb 2021 19:57:10 -0500 Subject: [PATCH 3/5] #124 change the date --- gzip.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gzip.xml b/gzip.xml index 37a6f72..33021ae 100644 --- a/gzip.xml +++ b/gzip.xml @@ -2,7 +2,7 @@ plg_system_gzip Thierry Bela - August 2016 + Feb 2021 Copyright (C) 2005 - 2021 Thierry Bela. Released under dual license LGPL v3 | MIT contact@tbela.net From a5d296992c059c3e1350666a13ccc8f254237d44 Mon Sep 17 00:00:00 2001 From: Thierry Bela Date: Sun, 28 Feb 2021 02:45:15 -0500 Subject: [PATCH 4/5] #126 do not remove quotes when somme characters are present --- helpers/HTML.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers/HTML.php b/helpers/HTML.php index e8ff559..8cfa572 100644 --- a/helpers/HTML.php +++ b/helpers/HTML.php @@ -217,7 +217,7 @@ public function postProcessHTML ($html, array $options = []) { $root = $options['webroot']; //remove quotes from HTML attributes that does not contain spaces; keep quotes around URLs! - $html = preg_replace_callback('~([\r\n\t ])?([a-zA-Z0-9:]+)=(["\'])([^\s\3]*)\3([\r\n\t ])?~', function ($matches) use ($options, $root) { + $html = preg_replace_callback('~([\r\n\t ])?([a-zA-Z0-9:]+)=(["\'])([^\s="\'`]*)\3([\r\n\t ])?~', function ($matches) use ($options, $root) { if ($matches[2] == 'style') { From d043738a542878a1ae194c21696e2fff6d733f71 Mon Sep 17 00:00:00 2001 From: Thierry Bela Date: Sun, 28 Feb 2021 02:59:37 -0500 Subject: [PATCH 5/5] update change log --- CHANGELOG.md | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b1c82b..6398e81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,20 +1,23 @@ # Change History -## 2.9.0 - -- New [CSS parser](https://github.com/tbela99/css) and minifier #67 -- Resize background images in inline css #116 -- Preserve background transparency when resizing #117 -- \[bug\] Fix an issue with responsive images #95 -- \[bug\] PWA start_url missing from preloaded urls #113 -- \[bug\] Cannot download sourcemap file #112 -- \[bug\] fix an error in the service worker #104 -- Convert CSS inline images to webp #93 -- Parse and minify inline CSS attribute #105 +## 2.9.3 + +- Do not remove quotes when some characters are present #126 +- Fix notice when parse inline CSS is enabled #105 +- Update version number #124 +- Add missing onesignal javascript #125 + +## 2.9.2 + +fix bug that prevent installation + +## 2.9.1 + +fix bug that prevent installation ## 2.8.1 -- fix empty service worker files #102 +- Fix empty service worker files #102 ## 2.8.0