(self.AMP=self.AMP||[]).push({n:"amp-install-serviceworker",ev:"0.1",l:true,v:"2107030008001",m:1,f:function(AMP,_){function h(a){return a||{}}let k=self.AMP_CONFIG||{},m=("string"==typeof k.cdnProxyRegex?new RegExp(k.cdnProxyRegex):k.cdnProxyRegex)||/^https:\/\/([a-zA-Z0-9_-]+\.)?cdn\.ampproject\.org$/;function n(a){if(!self.document||!self.document.head||self.location&&m.test(self.location.origin))return null;let b=self.document.head.querySelector(`meta[name="${a}"]`);return b&&b.getAttribute("content")||null}let p={thirdParty:k.thirdPartyUrl||"https://3p.ampproject.net",thirdPartyFrameHost:k.thirdPartyFrameHost||"ampproject.net",thirdPartyFrameRegex:("string"==typeof k.thirdPartyFrameRegex?new RegExp(k.thirdPartyFrameRegex):k.thirdPartyFrameRegex)||/^d-\d+\.ampproject\.net$/,cdn:k.cdnUrl||n("runtime-host")||"https://cdn.ampproject.org",cdnProxyRegex:m,localhostRegex:/^https?:\/\/localhost(:\d+)?$/,errorReporting:k.errorReportingUrl||"https://us-central1-amp-error-reporting.cloudfunctions.net/r",betaErrorReporting:k.betaErrorReportingUrl||"https://us-central1-amp-error-reporting.cloudfunctions.net/r-beta",localDev:k.localDev||!1,trustedViewerHosts:[/(^|\.)google\.(com?|[a-z]{2}|com?\.[a-z]{2}|cat)$/,/(^|\.)gmail\.(com|dev)$/],geoApi:k.geoApiUrl||n("amp-geo-api")};self.__AMP_LOG=self.__AMP_LOG||{user:null,dev:null,userForEmbed:null};let q=self.__AMP_LOG;function r(){if(!q.user)throw Error("failed to call initLogConstructor");return q.user}function t(a,b,c,e,d){r().assert(a,b,c,e,d,void 0,void 0,void 0,void 0,void 0,void 0)}function u(a,b){a=a.__AMP_TOP||(a.__AMP_TOP=a);return v(a,b)}function w(a){var b=x(a);b=y(b);return v(b,"documentInfo")}function z(a){a=x(a);a=y(a);return A(a,"url")?v(a,"url"):null}function x(a){return a.nodeType?u((a.ownerDocument||a).defaultView,"ampdoc").getAmpDoc(a):a}function y(a){a=x(a);return a.isSingleDoc()?a.win:a}function v(a,b){A(a,b);let c=a.__AMP_SERVICES;c||(c=a.__AMP_SERVICES={});a=c[b];a.obj||(a.obj=new a.ctor(a.context),a.context=null,a.resolve&&a.resolve(a.obj));return a.obj}function A(a,b){a=a.__AMP_SERVICES&&a.__AMP_SERVICES[b];return!(!a||!a.ctor)} /* https://mths.be/cssescape v1.5.1 by @mathias | MIT license */ function B(a,b){for(;a&&void 0!==a;a=a.parentElement)if(b(a))return a;return null}function C(a){return a.closest?a.closest("A"):B(a,(b=>{let c=b.matches||b.webkitMatchesSelector||b.mozMatchesSelector||b.msMatchesSelector||b.oMatchesSelector;return c?c.call(b,"A"):!1}))}let D;function E(a,b){let c=F();a.addEventListener("click",(e=>{try{return b(e)}catch(f){var d,g;null===(d=(g=self).__AMP_REPORT_ERROR)||void 0===d?void 0:d.call(g,f);throw f}}),c?void 0:!1)}function F(){if(void 0!==D)return D;D=!1;try{let a={get capture(){D=!0}};self.addEventListener("test-options",null,a);self.removeEventListener("test-options",null,a)}catch(a){}return D}new Set(["c","v","a","ad"]);function G(a){let b=a.indexOf("#");return-1==b?a:a.substring(0,b)}function H(a){var b=!1;void 0===b&&(b=a.hasAttribute("hidden"));b?a.removeAttribute("hidden"):a.setAttribute("hidden","")}function I(a){return Promise.all([a.loadPromise(a.win),a.getAmpDoc().whenFirstVisible()])}function J(a){return a.mutateElement((()=>{H(a.element);let b=a.win.document.createElement("iframe");b.setAttribute("sandbox","allow-same-origin allow-scripts");b.src=a.h;a.element.appendChild(b)}))}function K(a){if(a.getAmpDoc().isSingleDoc()){var b=a.getAmpDoc(),c=a.win,e=z(a.element),d=e.parse(c.location.href),g=a.element.getAttribute("data-no-service-worker-fallback-url-match"),f=a.element.getAttribute("data-no-service-worker-fallback-shell-url");if(g||f){t(g&&f,'Both, "%s" and "%s" must be specified for url-rewrite',"data-no-service-worker-fallback-url-match","data-no-service-worker-fallback-shell-url");f=G(f);try{var l=new RegExp(g)}catch(M){throw r().createError('Invalid "data-no-service-worker-fallback-url-match" expression',M)}t(e.getSourceOrigin(d)==e.parse(f).origin,'Shell source origin "%s" must be the same as source origin "%s"',f,d.href);a.F=new L(b,l,f,a.element);e.isSecure(f)&&N(a,f)}}}function N(a,b){I(a).then((()=>{a.mutateElement((()=>O(a,b)))}))}function O(a,b){let c=a.win.document.createElement("iframe");c.id="i-amphtml-shell-preload";c.setAttribute("src",b+"#preload");H(c);c.setAttribute("sandbox","allow-scripts allow-same-origin");a.loadPromise(c).then((()=>{var e;null===(e=c.parentElement)||void 0===e?void 0:e.removeChild(c)}));a.element.appendChild(c)}class P extends AMP.BaseElement{constructor(a){super(a);this.F=this.h=null;this.j=u(this.win,"platform").isSafari()}buildCallback(){let a=this.win;if("serviceWorker"in a.navigator){var b=z(this.element),c=this.element.getAttribute("src");b.assertHttpsUrl(c,this.element);if(!b.isProxyOrigin(c)&&!b.isProxyOrigin(a.location.href)||this.j)b.parse(a.location.href).origin==b.parse(c).origin?I(this).then((()=>Q(this.win,c,this.element))):this.user().error("amp-install-serviceworker","Did not install ServiceWorker because it does not match the current origin: "+c);else{let e=this.element.getAttribute("data-iframe-src");if(e){b.assertHttpsUrl(e,this.element);let{origin:d}=b.parse(e),g=w(this.element).get(),f=b.parse(g.sourceUrl),l=b.parse(g.canonicalUrl);t(d==f.origin||d==l.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.",d,f.origin,l.origin);this.h=e;I(this).then((()=>J(this)))}}(b.isProxyOrigin(c)||b.isProxyOrigin(a.location.href))&&this.j&&this.user().error("amp-install-serviceworker","Did not install ServiceWorker because of safari double keyring caching as it will not have any effect")}else K(this)}}class L{constructor(a,b,c,e){this.win=a.win;this.D=b;this.C=c;this.A=z(e);this.o=this.A.parse(c);a=a.getRootNode();b=this.B.bind(this);E(a,b)}B(a){if(!a.defaultPrevented&&(a=C(a.target))&&a.href){var b=this.A.parse(a.href);if(b.origin==this.o.origin&&b.pathname!=this.o.pathname&&this.D.test(b.href)&&!a.getAttribute("i-amphtml-orig-href")){var c=this.win;G(b.href)!=G(c.location.href)&&(a.setAttribute("i-amphtml-orig-href",a.href),a.href=this.C+"#href="+encodeURIComponent(`${b.pathname}${b.search}${b.hash}`))}}}}function Q(a,b,c){let e={};c.hasAttribute("data-scope")&&(e.scope=c.getAttribute("data-scope"));return a.navigator.serviceWorker.register(b,e).then((function(d){let g=d.installing;g?g.addEventListener("statechange",(f=>{"activated"===f.target.state&&R(d,a,c)})):d.active&&R(d,a,c);return d}),(function(d){r().error("amp-install-serviceworker","ServiceWorker registration failed:",d)}))}function R(a,b,c){S(b,a);c.hasAttribute("data-prefetch")&&T(a,b)}function S(a,b){if("performance"in a){let c=a.performance.getEntriesByType("resource").filter((d=>"script"===d.initiatorType&&d.name.startsWith(p.cdn))).map((d=>d.name)),e=b.active;e.postMessage&&e.postMessage(JSON.stringify(h({type:"AMP__FIRST-VISIT-CACHING",payload:c})))}}function T(a,b){let c=b.document,e=[].map.call(c.querySelectorAll("a[data-rel=prefetch]"),(d=>d.href));U(c)?e.forEach((d=>{let g=c.createElement("link");g.setAttribute("rel","prefetch");g.setAttribute("href",d);c.head.appendChild(g)})):(a=a.active,a.postMessage&&a.postMessage(JSON.stringify(h({type:"AMP__LINK-PREFETCH",payload:e}))))}function U(a){let b=a.createElement("link");return b.relList&&b.relList.supports?b.relList.supports("prefetch"):!1}(a=>{a.registerElement("amp-install-serviceworker",P)})(self.AMP)}});//# sourceMappingURL=amp-install-serviceworker-0.1.mjs.map