; (self.AMP=self.AMP||[]).push({m:1,v:"2310061803000",n:"amp-install-serviceworker",ev:"0.1",l:!0,f:function(t,r){(()=>{var{isArray:r}=Array,{hasOwnProperty:e,toString:n}=Object.prototype;function i(t,r){void 0===r&&(r=t.hasAttribute("hidden")),r?t.removeAttribute("hidden"):t.setAttribute("hidden","")}self.__AMP_LOG=self.__AMP_LOG||{user:null,dev:null,userForEmbed:null};var s=self.__AMP_LOG;function o(t){return s.user||(s.user=c()),function(t,r){return r&&r.ownerDocument.defaultView!=t}(s.user.win,t)?s.userForEmbed||(s.userForEmbed=c()):s.user}function c(t){return function(t,r){throw new Error("failed to call initLogConstructor")}()}function a(t,r,e,n,i,s,o,c,a,l,h){return t}function l(t,r,e,n,i,s,c,a,l,h,u){return o().assert(t,r,e,n,i,s,c,a,l,h,u)}function h(t,r){return d(t=function(t){return t.__AMP_TOP||(t.__AMP_TOP=t)}(t),r)}function u(t){return t.nodeType?(e=t,r=(e.ownerDocument||e).defaultView,h(r,"ampdoc")).getAmpDoc(t):t;var r,e}function f(t){const r=u(t);return r.isSingleDoc()?r.win:r}function d(t,r){a(m(t,r));const e=function(t){let r=t.__AMP_SERVICES;return r||(r=t.__AMP_SERVICES={}),r}(t)[r];return e.obj||(a(e.ctor),a(e.context),e.obj=new e.ctor(e.context),a(e.obj),e.context=null,e.resolve&&e.resolve(e.obj)),e.obj}function m(t,r){const e=t.__AMP_SERVICES&&t.__AMP_SERVICES[r];return!(!e||!e.ctor)}var p,v=t=>function(t,r){const e=f(u(t));return m(e,"url")?d(e,"url"):null}(t);function w(t){const r=t.indexOf("#");return-1==r?t:t.substring(0,r)}var _=(()=>self.AMP.config.urls)(),A="amp-install-serviceworker",P=class extends t.BaseElement{constructor(t){var r;super(t),this.ov=null,this.cv=null,this.av=(r=this.win,h(r,"platform")).isSafari()}buildCallback(){const{win:t}=this;if(!("serviceWorker"in t.navigator))return void this.lv();const r=this.hv(),e=this.element.getAttribute("src");if(r.assertHttpsUrl(e,this.element),!r.isProxyOrigin(e)&&!r.isProxyOrigin(t.location.href)||this.av)r.parse(t.location.href).origin==r.parse(e).origin?this.uv().then((()=>function(t,r,e){const n={};return e.hasAttribute("data-scope")&&(n.scope=e.getAttribute("data-scope")),t.navigator.serviceWorker.register(r,n).then((function(r){const n=r.installing;return n?n.addEventListener("statechange",(n=>{"activated"===n.target.state&&b(r,t,e)})):r.active&&b(r,t,e),r}),(function(t){o().error(A,"ServiceWorker registration failed:",t)}))}(this.win,e,this.element))):this.user().error(A,"Did not install ServiceWorker because it does not match the current origin: "+e);else{const t=this.element.getAttribute("data-iframe-src");if(t){r.assertHttpsUrl(t,this.element);const{origin:e}=r.parse(t),n=function(t,r){return d(f(u(t)),"documentInfo")}(this.element).get(),i=r.parse(n.sourceUrl),s=r.parse(n.canonicalUrl);l(e==i.origin||e==s.origin,"data-iframe-src (%s) should be a URL on the same origin as the source (%s) or canonical URL (%s) of the AMP-document.",e,i.origin,s.origin),this.ov=t,this.uv().then((()=>this.fv()))}}(r.isProxyOrigin(e)||r.isProxyOrigin(t.location.href))&&this.av&&this.user().error(A,"Did not install ServiceWorker because of safari double keyring caching as it will not have any effect")}uv(){return Promise.all([this.loadPromise(this.win),this.getAmpDoc().whenFirstVisible()])}fv(){return this.mutateElement((()=>{i(this.element,!1);const t=this.win.document.createElement("iframe");t.setAttribute("sandbox","allow-same-origin allow-scripts"),t.src=this.ov,this.element.appendChild(t)}))}lv(){if(!this.getAmpDoc().isSingleDoc())return;const t=this.getAmpDoc(),{win:r}=this,e=this.hv(),n=e.parse(r.location.href),i=this.element.getAttribute("data-no-service-worker-fallback-url-match");let s,c=this.element.getAttribute("data-no-service-worker-fallback-shell-url");if(i||c){l(i&&c,'Both, "%s" and "%s" must be specified for url-rewrite',"data-no-service-worker-fallback-url-match","data-no-service-worker-fallback-shell-url"),c=w(c);try{s=new RegExp(i)}catch(t){throw o().createError('Invalid "data-no-service-worker-fallback-url-match" expression',t)}l(e.getSourceOrigin(n)==e.parse(c).origin,'Shell source origin "%s" must be the same as source origin "%s"',c,n.href),this.cv=new k(t,s,c,this.element),e.isSecure(c)&&this.dv(c)}}dv(t){return this.uv().then((()=>{this.mutateElement((()=>this.mv(t)))}))}mv(t){const{win:r}=this,e=r.document.createElement("iframe");e.id="i-amphtml-shell-preload",e.setAttribute("src",t+"#preload"),i(e,!1),e.setAttribute("sandbox","allow-scripts allow-same-origin"),this.loadPromise(e).then((()=>{var t,r;null===(r=(t=e).parentElement)||void 0===r||r.removeChild(t)})),this.element.appendChild(e)}hv(){return v(this.element)}},k=class{constructor(t,r,e,n){this.win=t.win,this.pv=r,this.vv=e,this.wv=v(n),this._v=this.wv.parse(e),function(t,r,e,n){!function(t,r,e,n){let i=t,s=e;const o=function(){if(void 0!==p)return p;p=!1;try{const t={get capture(){return p=!0,!1}};self.addEventListener("test-options",null,t),self.removeEventListener("test-options",null,t)}catch(t){}return p}();i.addEventListener("click",(t=>{try{return s(t)}catch(t){var r,e;throw null===(r=(e=self).__AMP_REPORT_ERROR)||void 0===r||r.call(e,t),t}}),!!o&&n)}(t,0,e,void 0)}(t.getRootNode(),0,this.dc.bind(this))}dc(t){if(t.defaultPrevented)return;const r=t.target.closest("A");if(!r||!r.href)return;const e=this.wv.parse(r.href);if(e.origin!=this._v.origin||e.pathname==this._v.pathname||!this.pv.test(e.href))return;if(r.getAttribute("i-amphtml-orig-href"))return;const{win:n}=this;w(e.href)!=w(n.location.href)&&(r.setAttribute("i-amphtml-orig-href",r.href),r.href=this.vv+"#href="+encodeURIComponent(`${e.pathname}${e.search}${e.hash}`))}};function b(t,r,e){!function(t,r){if("performance"in t){const e=t.performance.getEntriesByType("resource").filter((t=>"script"===t.initiatorType&&t.name.startsWith(_.cdn))).map((t=>t.name)),n=r.active;n.postMessage&&n.postMessage(JSON.stringify({"type":"AMP__FIRST-VISIT-CACHING","payload":e}))}}(r,t),e.hasAttribute("data-prefetch")&&function(t,r){const{document:e}=r,n=[].map.call(e.querySelectorAll("a[data-rel=prefetch]"),(t=>t.href));if(function(t){const r=t.createElement("link");return!(!r.relList||!r.relList.supports)&&r.relList.supports("prefetch")}(e))n.forEach((t=>{const r=e.createElement("link");r.setAttribute("rel","prefetch"),r.setAttribute("href",t),e.head.appendChild(r)}));else{const r=t.active;r.postMessage&&r.postMessage(JSON.stringify({"type":"AMP__LINK-PREFETCH","payload":n}))}}(t,r)}t.registerElement(A,P)})(); /*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */}}); //# sourceMappingURL=amp-install-serviceworker-0.1.mjs.map