!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).singlefileBootstrap={})}(this,(function(e){"use strict";const t="single-file-load-deferred-images-start",s="single-file-load-deferred-images-end",o="single-file-load-deferred-images-keep-zoom-level-start",n="single-file-load-deferred-images-keep-zoom-level-end",a="single-file-block-cookies-start",i="single-file-block-cookies-end",r="single-file-dispatch-scroll-event-start",l="single-file-dispatch-scroll-event-end",d="single-file-block-storage-start",c="single-file-block-storage-end",m="single-file-load-image",u="single-file-image-loaded",p="_singleFile_fontFaces",g="_singleFile_worklets",h=globalThis.CustomEvent,f=globalThis.document,E=globalThis.Document,T=globalThis.JSON,b=globalThis.MutationObserver;let y,w;function I(){f instanceof E&&(f.addEventListener("single-file-new-font-face",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,y.set(T.stringify(s),t)})),f.addEventListener("single-file-delete-font",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,y.delete(T.stringify(s))})),f.addEventListener("single-file-clear-fonts",(()=>y=new Map)),f.addEventListener("single-file-new-worklet",(e=>{const t=e.detail;w.set(t.moduleURL,t)})))}y=window[p]?window[p]:window[p]=new Map,w=window[g]?window[g]:window[g]=new Map,I(),new b(I).observe(f,{childList:!0});const A="[\\x20\\t\\r\\n\\f]",v=new RegExp("\\\\([\\da-f]{1,6}"+A+"?|("+A+")|.)","ig");const S="single-file-",R="_singleFile_waitForUserScript",N="__frameTree__::",P=S+"on-before-capture",_=S+"on-after-capture",M=S+"request-get-adopted-stylesheets",C=S+"response-get-adopted-stylesheets",O=S+"unregister-request-get-adopted-stylesheets",L=S+"user-script-init",D="data-"+S+"removed-content",F="data-"+S+"hidden-content",x="data-"+S+"kept-content",U="data-"+S+"hidden-frame",k="data-"+S+"preserved-space-element",q="data-"+S+"shadow-root-element",H="data-"+S+"win-id",V="data-"+S+"image",B="data-"+S+"poster",W="data-"+S+"video",z="data-"+S+"canvas",Y="data-"+S+"movable-style",j="data-"+S+"input-value",G="data-"+S+"lazy-loaded-src",K="data-"+S+"stylesheet",X="data-"+S+"disabled-noscript",Z="data-"+S+"invalid-element",J="data-"+S+"async-script",$="*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)",Q=["NOSCRIPT","DISABLED-NOSCRIPT","META","LINK","STYLE","TITLE","TEMPLATE","SOURCE","OBJECT","SCRIPT","HEAD","BODY"],ee=["SCRIPT","NOSCRIPT","META","LINK","TEMPLATE"],te=/^'(.*?)'$/,se=/^"(.*?)"$/,oe={regular:"400",normal:"400",bold:"700",bolder:"700",lighter:"100"},ne="single-file-ui-element",ae="single-file-infobar",ie="data:,",re=(e,t,s)=>globalThis.addEventListener(e,t,s),le=globalThis.JSON,de=globalThis.CustomEvent,ce=globalThis.MutationObserver;function me(e,t,s){e.querySelectorAll("noscript:not(["+X+"])").forEach((e=>{e.setAttribute(X,e.textContent),e.textContent=""})),function(e){e.querySelectorAll("meta[http-equiv=refresh]").forEach((e=>{e.removeAttribute("http-equiv"),e.setAttribute("disabled-http-equiv","refresh")}))}(e),e.head&&e.head.querySelectorAll($).forEach((e=>e.hidden=!0)),e.querySelectorAll("svg foreignObject").forEach((e=>{const t=e.querySelectorAll("html > head > "+$+", html > body > "+$);t.length&&(Array.from(e.childNodes).forEach((e=>e.remove())),t.forEach((t=>e.appendChild(t))))}));const o=new Map;let n;return t&&e.documentElement?(e.querySelectorAll("button button, a a").forEach((t=>{const s=e.createElement("template");s.setAttribute(Z,""),s.content.appendChild(t.cloneNode(!0)),o.set(t,s),t.replaceWith(s)})),n=ue(t,e,e.documentElement,s),s.moveStylesInHead&&e.querySelectorAll("body style, body ~ style").forEach((e=>{const s=we(t,e);s&&Ee(e,s)&&(e.setAttribute(Y,""),n.markedElements.push(e))}))):n={canvases:[],images:[],posters:[],videos:[],usedFonts:[],shadowRoots:[],markedElements:[]},{canvases:n.canvases,fonts:Array.from(y.values()),worklets:Array.from(w.values()),stylesheets:be(e),images:n.images,posters:n.posters,videos:n.videos,usedFonts:Array.from(n.usedFonts.values()),shadowRoots:n.shadowRoots,referrer:e.referrer,markedElements:n.markedElements,invalidElements:o,scrollPosition:{x:t.scrollX,y:t.scrollY},adoptedStyleSheets:pe(e.adoptedStyleSheets)}}function ue(e,t,s,o,n={usedFonts:new Map,canvases:[],images:[],posters:[],videos:[],shadowRoots:[],markedElements:[]},a){if(s.childNodes){Array.from(s.childNodes).filter((t=>t instanceof e.HTMLElement||t instanceof e.SVGElement||t instanceof globalThis.HTMLElement||t instanceof globalThis.SVGElement)).forEach((s=>{let i,r,l;if(!o.autoSaveExternalSave&&(o.removeHiddenElements||o.removeUnusedFonts||o.compressHTML)&&(l=we(e,s),(s instanceof e.HTMLElement||s instanceof globalThis.HTMLElement)&&o.removeHiddenElements&&(r=(a||s.closest("html > head"))&&Q.includes(s.tagName.toUpperCase())||s.closest("details"),r||(i=a||Ee(s,l),i&&!ee.includes(s.tagName.toUpperCase())&&(s.setAttribute(F,""),n.markedElements.push(s)))),!i)){if(o.compressHTML&&l){const e=l.getPropertyValue("white-space");e&&e.startsWith("pre")&&(s.setAttribute(k,""),n.markedElements.push(s))}o.removeUnusedFonts&&(ge(l,o,n.usedFonts),ge(we(e,s,":first-letter"),o,n.usedFonts),ge(we(e,s,":before"),o,n.usedFonts),ge(we(e,s,":after"),o,n.usedFonts))}!function(e,t,s,o,n,a,i){const r=s.tagName&&s.tagName.toUpperCase();if("CANVAS"==r)try{n.canvases.push({dataURI:s.toDataURL("image/png",""),backgroundColor:i.getPropertyValue("background-color")}),s.setAttribute(z,n.canvases.length-1),n.markedElements.push(s)}catch(e){}if("IMG"==r){const t={currentSrc:a?ie:o.loadDeferredImages&&s.getAttribute(G)||s.currentSrc};if(n.images.push(t),s.setAttribute(V,n.images.length-1),n.markedElements.push(s),s.removeAttribute(G),i=i||we(e,s)){t.size=function(e,t,s){let o=t.naturalWidth,n=t.naturalHeight;if(!o&&!n){const a=null==t.getAttribute("style");if(s=s||we(e,t)){let e,i,r,l,d,c,m,u,p=!1;if("content-box"==s.getPropertyValue("box-sizing")){const e=t.style.getPropertyValue("box-sizing"),s=t.style.getPropertyPriority("box-sizing"),o=t.clientWidth;t.style.setProperty("box-sizing","border-box","important"),p=t.clientWidth!=o,e?t.style.setProperty("box-sizing",e,s):t.style.removeProperty("box-sizing")}e=ye("padding-left",s),i=ye("padding-right",s),r=ye("padding-top",s),l=ye("padding-bottom",s),p?(d=ye("border-left-width",s),c=ye("border-right-width",s),m=ye("border-top-width",s),u=ye("border-bottom-width",s)):d=c=m=u=0,o=Math.max(0,t.clientWidth-e-i-d-c),n=Math.max(0,t.clientHeight-r-l-m-u),a&&t.removeAttribute("style")}}return{pxWidth:o,pxHeight:n}}(e,s,i);const o=i.getPropertyValue("box-shadow"),n=i.getPropertyValue("background-image");o&&"none"!=o||n&&"none"!=n||!(t.size.pxWidth>1||t.size.pxHeight>1)||(t.replaceable=!0,t.backgroundColor=i.getPropertyValue("background-color"),t.objectFit=i.getPropertyValue("object-fit"),t.boxSizing=i.getPropertyValue("box-sizing"),t.objectPosition=i.getPropertyValue("object-position"))}}if("VIDEO"==r){const o=s.currentSrc;if(o&&!o.startsWith("blob:")&&!o.startsWith("data:")){const t=we(e,s.parentNode);n.videos.push({positionParent:t&&t.getPropertyValue("position"),src:o,size:{pxWidth:s.clientWidth,pxHeight:s.clientHeight},currentTime:s.currentTime}),s.setAttribute(W,n.videos.length-1)}if(!s.getAttribute("poster")){const e=t.createElement("canvas"),o=e.getContext("2d");e.width=s.clientWidth,e.height=s.clientHeight;try{o.drawImage(s,0,0,e.width,e.height),n.posters.push(e.toDataURL("image/png","")),s.setAttribute(B,n.posters.length-1),n.markedElements.push(s)}catch(e){}}}"IFRAME"==r&&a&&o.removeHiddenElements&&(s.setAttribute(U,""),n.markedElements.push(s));"INPUT"==r&&("password"!=s.type&&(s.setAttribute(j,s.value),n.markedElements.push(s)),"radio"!=s.type&&"checkbox"!=s.type||(s.setAttribute(j,s.checked),n.markedElements.push(s)));"TEXTAREA"==r&&(s.setAttribute(j,s.value),n.markedElements.push(s));"SELECT"==r&&s.querySelectorAll("option").forEach((e=>{e.selected&&(e.setAttribute(j,""),n.markedElements.push(e))}));"SCRIPT"==r&&(s.async&&""!=s.getAttribute("async")&&"async"!=s.getAttribute("async")&&(s.setAttribute(J,""),n.markedElements.push(s)),s.textContent=s.textContent.replace(/<\/script>/gi,"<\\/script>"))}(e,t,s,o,n,i,l);const d=!(s instanceof e.SVGElement||s instanceof globalThis.SVGElement)&&he(s);if(d&&!s.classList.contains(ne)&&s.tagName.toLowerCase()!=ae){const a={};s.setAttribute(q,n.shadowRoots.length),n.markedElements.push(s),n.shadowRoots.push(a);try{if(d.adoptedStyleSheets)if(d.adoptedStyleSheets.length)a.adoptedStyleSheets=pe(d.adoptedStyleSheets);else if(void 0===d.adoptedStyleSheets.length){const e=e=>a.adoptedStyleSheets=e.detail.adoptedStyleSheets;d.addEventListener(C,e),d.dispatchEvent(new de(M,{bubbles:!0})),a.adoptedStyleSheets||s.dispatchEvent(new de(M,{bubbles:!0})),d.removeEventListener(C,e)}}catch(e){}ue(e,t,d,o,n,i),a.content=d.innerHTML,a.mode=d.mode;try{d.adoptedStyleSheets&&void 0===d.adoptedStyleSheets.length&&d.dispatchEvent(new de(O,{bubbles:!0}))}catch(e){}}ue(e,t,s,o,n,i),!o.autoSaveExternalSave&&o.removeHiddenElements&&a&&(r||""==s.getAttribute(x)?s.parentElement&&(s.parentElement.setAttribute(x,""),n.markedElements.push(s.parentElement)):i&&(s.setAttribute(D,""),n.markedElements.push(s)))}))}return n}function pe(e){return e?Array.from(e).map((e=>Array.from(e.cssRules).map((e=>e.cssText)).join("\n"))):[]}function ge(e,t,s){if(e){const o=e.getPropertyValue("font-style")||"normal";e.getPropertyValue("font-family").split(",").forEach((n=>{if(n=fe(n),!t.loadedFonts||t.loadedFonts.find((e=>fe(e.family)==n&&e.style==o))){const t=(a=e.getPropertyValue("font-weight"),oe[a.toLowerCase().trim()]||a),i=e.getPropertyValue("font-variant")||"normal",r=[n,t,o,i];s.set(le.stringify(r),[n,t,o,i])}var a}))}}function he(e){const t=globalThis.chrome;if(e.openOrClosedShadowRoot)return e.openOrClosedShadowRoot;if(!(t&&t.dom&&t.dom.openOrClosedShadowRoot))return e.shadowRoot;try{return t.dom.openOrClosedShadowRoot(e)}catch(t){return e.shadowRoot}}function fe(e=""){return function(e){e=e.match(te)?e.replace(te,"$1"):e.replace(se,"$1");return e.trim()}((t=e.trim(),t.replace(v,((e,t,s)=>{const o="0x"+t-65536;return o!=o||s?t:o<0?String.fromCharCode(o+65536):String.fromCharCode(o>>10|55296,1023&o|56320)})))).toLowerCase();var t}function Ee(e,t){let s=!1;if(t){const o=t.getPropertyValue("display"),n=t.getPropertyValue("opacity"),a=t.getPropertyValue("visibility");if(s="none"==o,!s&&("0"==n||"hidden"==a)&&e.getBoundingClientRect){const t=e.getBoundingClientRect();s=!t.width&&!t.height}}return Boolean(s)}function Te(e,t,s){if(e.querySelectorAll("["+X+"]").forEach((e=>{e.textContent=e.getAttribute(X),e.removeAttribute(X)})),e.querySelectorAll("meta[disabled-http-equiv]").forEach((e=>{e.setAttribute("http-equiv",e.getAttribute("disabled-http-equiv")),e.removeAttribute("disabled-http-equiv")})),e.head&&e.head.querySelectorAll("*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)").forEach((e=>e.removeAttribute("hidden"))),!t){const s=[D,U,F,k,V,B,W,z,j,q,K,J];t=e.querySelectorAll(s.map((e=>"["+e+"]")).join(","))}t.forEach((e=>{e.removeAttribute(D),e.removeAttribute(F),e.removeAttribute(x),e.removeAttribute(U),e.removeAttribute(k),e.removeAttribute(V),e.removeAttribute(B),e.removeAttribute(W),e.removeAttribute(z),e.removeAttribute(j),e.removeAttribute(q),e.removeAttribute(K),e.removeAttribute(J),e.removeAttribute(Y)})),s&&s.forEach(((e,t)=>e.replaceWith(t)))}function be(e){if(e){const t=[];return e.querySelectorAll("style").forEach(((s,o)=>{try{if(!s.sheet.disabled){const n=e.createElement("style");n.textContent=s.textContent,e.body.appendChild(n);const a=n.sheet;n.remove();const i=Array.from(a.cssRules).map((e=>e.cssText)).join("\n"),r=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n");a&&i==r||(s.setAttribute(K,o),t[o]=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n"))}}catch(e){}})),t}}function ye(e,t){if(t.getPropertyValue(e).endsWith("px"))return parseFloat(t.getPropertyValue(e))}function we(e,t,s){try{return e.getComputedStyle(t,s)}catch(e){}}const Ie={LAZY_SRC_ATTRIBUTE_NAME:G,SINGLE_FILE_UI_ELEMENT_CLASS:ne},Ae=10,ve="attributes",Se=globalThis.browser,Re=globalThis.document,Ne=globalThis.MutationObserver,Pe=new Map;let _e;async function Me(e){if(Re.documentElement){Pe.clear();const s=Re.body?Math.max(Re.body.scrollHeight,Re.documentElement.scrollHeight):Re.documentElement.scrollHeight,n=Re.body?Math.max(Re.body.scrollWidth,Re.documentElement.scrollWidth):Re.documentElement.scrollWidth;if(s>globalThis.innerHeight||n>globalThis.innerWidth){const i=Math.max(s-1.5*globalThis.innerHeight,0),l=Math.max(n-1.5*globalThis.innerWidth,0);if(globalThis.scrollY{let n;const i=new Set,l=new Ne((async t=>{if((t=t.filter((e=>e.type==ve))).length){t.filter((e=>{if("src"==e.attributeName&&(e.target.setAttribute(Ie.LAZY_SRC_ATTRIBUTE_NAME,e.target.src),e.target.addEventListener("load",p)),"src"==e.attributeName||"srcset"==e.attributeName||e.target.tagName&&"SOURCE"==e.target.tagName.toUpperCase())return!e.target.classList||!e.target.classList.contains(Ie.SINGLE_FILE_UI_ELEMENT_CLASS)})).length&&(n=!0,await Oe(l,e,T),i.size||await Ce(l,e,T))}}));async function c(t){await De("idleTimeout",(async()=>{n?_eLe(e,t,s)),t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function Oe(e,t,s){await De("maxTimeout",(async()=>{await xe("loadTimeout"),await Le(e,t,s)}),10*t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function Le(e,t,o){await xe("idleTimeout"),function(e){e.loadDeferredImagesBlockCookies&&f.dispatchEvent(new h(i)),e.loadDeferredImagesBlockStorage&&f.dispatchEvent(new h(c)),e.loadDeferredImagesDispatchScrollEvent&&f.dispatchEvent(new h(l)),e.loadDeferredImagesKeepZoomLevel?f.dispatchEvent(new h(n)):f.dispatchEvent(new h(s))}(t),await De("endTimeout",(async()=>{await xe("maxTimeout"),o()}),t.loadDeferredImagesMaxIdleTime/2,t.loadDeferredImagesNativeTimeout),e.disconnect()}async function De(e,t,s,o){if(Se&&Se.runtime&&Se.runtime.sendMessage&&!o){if(!Pe.get(e)||!Pe.get(e).pending){const o={callback:t,pending:!0};Pe.set(e,o);try{await Se.runtime.sendMessage({method:"singlefile.lazyTimeout.setTimeout",type:e,delay:s})}catch(o){Fe(e,t,s)}o.pending=!1}}else Fe(e,t,s)}function Fe(e,t,s){const o=Pe.get(e);o&&globalThis.clearTimeout(o),Pe.set(e,t),globalThis.setTimeout(t,s)}async function xe(e){if(Se&&Se.runtime&&Se.runtime.sendMessage)try{await Se.runtime.sendMessage({method:"singlefile.lazyTimeout.clearTimeout",type:e})}catch(t){Ue(e)}else Ue(e)}function Ue(e){const t=Pe.get(e);Pe.delete(e),t&&globalThis.clearTimeout(t)}Se&&Se.runtime&&Se.runtime.onMessage&&Se.runtime.onMessage.addListener&&Se.runtime.onMessage.addListener((e=>{if("singlefile.lazyTimeout.onTimeout"==e.method){const t=Pe.get(e.type);if(t){Pe.delete(e.type);try{t.callback()}catch(t){Ue(e.type)}}}}));const ke={ON_BEFORE_CAPTURE_EVENT_NAME:P,ON_AFTER_CAPTURE_EVENT_NAME:_,WIN_ID_ATTRIBUTE_NAME:H,WAIT_FOR_USERSCRIPT_PROPERTY_NAME:R,preProcessDoc:me,serialize:function(e){const t=e.doctype;let s="";return t&&(s=" "),s+e.documentElement.outerHTML},postProcessDoc:Te,getShadowRoot:he},qe='iframe, frame, object[type="text/html"][data]',He="*",Ve="singlefile.frameTree.initRequest",Be="singlefile.frameTree.ackInitRequest",We="singlefile.frameTree.cleanupRequest",ze="singlefile.frameTree.initResponse",Ye="*",je=5e3,Ge=1e4,Ke=".",Xe=globalThis.window==globalThis.top,Ze=globalThis.browser,Je=globalThis.top,$e=globalThis.MessageChannel,Qe=globalThis.document,et=globalThis.JSON,tt=globalThis.MutationObserver,st=globalThis.DOMParser;let ot,nt=globalThis.sessions;function at(){globalThis.addEventListener("message",(async e=>{if("string"==typeof e.data&&e.data.startsWith(N)){e.preventDefault(),e.stopPropagation();const t=et.parse(e.data.substring(N.length));if(t.method==Ve)e.source&&ht(e.source,{method:Be,windowId:t.windowId,sessionId:t.sessionId}),Xe||(globalThis.stop(),t.options.loadDeferredImages&&Me(t.options),await rt(t));else if(t.method==Be)mt("requestTimeouts",t.sessionId,t.windowId),ut(t.sessionId,t.windowId);else if(t.method==We)lt(t);else if(t.method==ze&&nt.get(t.sessionId)){e.ports[0].onmessage=e=>dt(e.data)}}}),!0)}function it(){return globalThis.crypto.getRandomValues(new Uint32Array(32)).join("")}async function rt(e){const t=e.sessionId,s=globalThis[ke.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,Xe||(ot=globalThis.frameId=e.windowId),ct(Qe,e.options,ot,t),Xe||(e.options.userScriptEnabled&&s&&await s(ke.ON_BEFORE_CAPTURE_EVENT_NAME),gt({frames:[ft(Qe,globalThis,ot,e.options,e.scrolling)],sessionId:t,requestedFrameId:Qe.documentElement.dataset.requestedFrameId&&ot}),e.options.userScriptEnabled&&s&&await s(ke.ON_AFTER_CAPTURE_EVENT_NAME),delete Qe.documentElement.dataset.requestedFrameId)}function lt(e){if(!globalThis._singleFile_cleaningUp){globalThis._singleFile_cleaningUp=!0;const t=e.sessionId;pt(Et(Qe),e.windowId,t)}}function dt(e){e.frames.forEach((t=>mt("responseTimeouts",e.sessionId,t.windowId)));const t=nt.get(e.sessionId);if(t){e.requestedFrameId&&(t.requestedFrameId=e.requestedFrameId),e.frames.forEach((e=>{let s=t.frames.find((t=>e.windowId==t.windowId));s||(s={windowId:e.windowId},t.frames.push(s)),s.processed||(s.content=e.content,s.baseURI=e.baseURI,s.title=e.title,s.url=e.url,s.canvases=e.canvases,s.fonts=e.fonts,s.worklets=e.worklets,s.stylesheets=e.stylesheets,s.images=e.images,s.posters=e.posters,s.videos=e.videos,s.usedFonts=e.usedFonts,s.shadowRoots=e.shadowRoots,s.processed=e.processed,s.scrollPosition=e.scrollPosition,s.scrolling=e.scrolling,s.adoptedStyleSheets=e.adoptedStyleSheets)}));t.frames.filter((e=>!e.processed)).length||(t.frames=t.frames.sort(((e,t)=>t.windowId.split(Ke).length-e.windowId.split(Ke).length)),t.resolve&&(t.requestedFrameId&&t.frames.forEach((e=>{e.windowId==t.requestedFrameId&&(e.requestedFrame=!0)})),t.resolve(t.frames)))}}function ct(e,t,s,o){const n=Et(e);!function(e,t,s,o,n){const a=[];let i;nt.get(n)?i=nt.get(n).requestTimeouts:(i={},nt.set(n,{requestTimeouts:i}));t.forEach(((e,t)=>{const s=o+Ke+t;e.setAttribute(ke.WIN_ID_ATTRIBUTE_NAME,s),a.push({windowId:s})})),gt({frames:a,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),t.forEach(((e,t)=>{const a=o+Ke+t;try{ht(e.contentWindow,{method:Ve,windowId:a,sessionId:n,options:s,scrolling:e.scrolling})}catch(e){}i[a]=globalThis.setTimeout((()=>gt({frames:[{windowId:a,processed:!0}],sessionId:n})),je)})),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o),n.length&&function(e,t,s,o,n){const a=[];t.forEach(((e,t)=>{const i=o+Ke+t;let r,l;try{r=e.contentDocument,l=e.contentWindow,l.stop()}catch(e){}const d=e.getAttribute("srcdoc");if(!r&&d){r=(new st).parseFromString(d,"text/html"),l=globalThis}if(r)try{mt("requestTimeouts",n,i),ct(r,s,i,n),a.push(ft(r,l,i,s,e.scrolling))}catch(e){a.push({windowId:i,processed:!0})}})),gt({frames:a,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o)}function mt(e,t,s){const o=nt.get(t);if(o&&o[e]){const t=o[e][s];t&&(globalThis.clearTimeout(t),delete o[e][s])}}function ut(e,t){const s=nt.get(e);s&&s.responseTimeouts&&(s.responseTimeouts[t]=globalThis.setTimeout((()=>gt({frames:[{windowId:t,processed:!0}],sessionId:e})),Ge))}function pt(e,t,s){e.forEach(((e,o)=>{const n=t+Ke+o;e.removeAttribute(ke.WIN_ID_ATTRIBUTE_NAME);try{ht(e.contentWindow,{method:We,windowId:n,sessionId:s})}catch(e){}})),e.forEach(((e,o)=>{const n=t+Ke+o;let a;try{a=e.contentDocument}catch(e){}if(a)try{pt(Et(a),n,s)}catch(e){}}))}function gt(e){e.method=ze;try{Je.singlefile.processors.frameTree.initResponse(e)}catch(t){ht(Je,e,!0)}}function ht(e,t,s){if(e==Je&&Ze&&Ze.runtime&&Ze.runtime.sendMessage)Ze.runtime.sendMessage(t);else if(s){const s=new $e;e.postMessage(N+et.stringify({method:t.method,sessionId:t.sessionId}),Ye,[s.port2]),s.port1.postMessage(t)}else e.postMessage(N+et.stringify(t),Ye)}function ft(e,t,s,o,n){const a=ke.preProcessDoc(e,t,o),i=ke.serialize(e);ke.postProcessDoc(e,a.markedElements,a.invalidElements);return{windowId:s,content:i,baseURI:e.baseURI.split("#")[0],url:e.documentURI,title:e.title,canvases:a.canvases,fonts:a.fonts,worklets:a.worklets,stylesheets:a.stylesheets,images:a.images,posters:a.posters,videos:a.videos,usedFonts:a.usedFonts,shadowRoots:a.shadowRoots,scrollPosition:a.scrollPosition,scrolling:n,adoptedStyleSheets:a.adoptedStyleSheets,processed:!0}}function Et(e){let t=Array.from(e.querySelectorAll(qe));return e.querySelectorAll(He).forEach((e=>{const s=ke.getShadowRoot(e);s&&(t=t.concat(...s.querySelectorAll(qe)))})),t}nt||(nt=globalThis.sessions=new Map),Xe&&(ot="0",Ze&&Ze.runtime&&Ze.runtime.onMessage&&Ze.runtime.onMessage.addListener&&Ze.runtime.onMessage.addListener((e=>e.method==ze?(dt(e),Promise.resolve({})):e.method==Be?(mt("requestTimeouts",e.sessionId,e.windowId),ut(e.sessionId,e.windowId),Promise.resolve({})):void 0))),at(),new tt(at).observe(Qe,{childList:!0});const Tt=["AREA","BASE","BR","COL","COMMAND","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"],bt=1,yt=3,wt=8,It=[{tagName:"HEAD",accept:e=>!e.childNodes.length||e.childNodes[0].nodeType==bt},{tagName:"BODY",accept:e=>!e.childNodes.length}],At=[{tagName:"HTML",accept:e=>!e||e.nodeType!=wt},{tagName:"HEAD",accept:e=>!e||e.nodeType!=wt&&(e.nodeType!=yt||!Rt(e.textContent))},{tagName:"BODY",accept:e=>!e||e.nodeType!=wt},{tagName:"LI",accept:(e,t)=>!e&&t.parentElement&&("UL"==Nt(t.parentElement)||"OL"==Nt(t.parentElement))||e&&["LI"].includes(Nt(e))},{tagName:"DT",accept:e=>!e||["DT","DD"].includes(Nt(e))},{tagName:"P",accept:e=>e&&["ADDRESS","ARTICLE","ASIDE","BLOCKQUOTE","DETAILS","DIV","DL","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","H1","H2","H3","H4","H5","H6","HEADER","HR","MAIN","NAV","OL","P","PRE","SECTION","TABLE","UL"].includes(Nt(e))},{tagName:"DD",accept:e=>!e||["DT","DD"].includes(Nt(e))},{tagName:"RT",accept:e=>!e||["RT","RP"].includes(Nt(e))},{tagName:"RP",accept:e=>!e||["RT","RP"].includes(Nt(e))},{tagName:"OPTGROUP",accept:e=>!e||["OPTGROUP"].includes(Nt(e))},{tagName:"OPTION",accept:e=>!e||["OPTION","OPTGROUP"].includes(Nt(e))},{tagName:"COLGROUP",accept:e=>!e||e.nodeType!=wt&&(e.nodeType!=yt||!Rt(e.textContent))},{tagName:"CAPTION",accept:e=>!e||e.nodeType!=wt&&(e.nodeType!=yt||!Rt(e.textContent))},{tagName:"THEAD",accept:e=>!e||["TBODY","TFOOT"].includes(Nt(e))},{tagName:"TBODY",accept:e=>!e||["TBODY","TFOOT"].includes(Nt(e))},{tagName:"TFOOT",accept:e=>!e},{tagName:"TR",accept:e=>!e||["TR"].includes(Nt(e))},{tagName:"TD",accept:e=>!e||["TD","TH"].includes(Nt(e))},{tagName:"TH",accept:e=>!e||["TD","TH"].includes(Nt(e))}],vt=["STYLE","SCRIPT","XMP","IFRAME","NOEMBED","NOFRAMES","PLAINTEXT","NOSCRIPT"];function St(e,t,s){return e.nodeType==yt?function(e){const t=e.parentNode;let s;t&&t.nodeType==bt&&(s=Nt(t));return!s||vt.includes(s)?"SCRIPT"==s||"STYLE"==s?e.textContent.replace(/<\//gi,"<\\/").replace(/\/>/gi,"\\/>"):e.textContent:e.textContent.replace(/&/g,"&").replace(/\u00a0/g," ").replace(//g,">")}(e):e.nodeType==wt?"\x3c!--"+e.textContent+"--\x3e":e.nodeType==bt?function(e,t,s){const o=Nt(e),n=t&&It.find((t=>o==Nt(t)&&t.accept(e)));let a="";n&&!e.attributes.length||(a="<"+o.toLowerCase(),Array.from(e.attributes).forEach((s=>a+=function(e,t,s){const o=e.name;let n="";if(!o.match(/["'>/=]/)){let a,i=e.value;s&&"class"==o&&(i=Array.from(t.classList).map((e=>e.trim())).join(" ")),i=i.replace(/&/g,"&").replace(/\u00a0/g," "),i.includes('"')&&(i.includes("'")||!s?i=i.replace(/"/g,"""):a=!0);const r=!s||i.match(/[ \t\n\f\r'"`=<>]/);n+=" ",e.namespace?"http://www.w3.org/XML/1998/namespace"==e.namespaceURI?n+="xml:"+o:"http://www.w3.org/2000/xmlns/"==e.namespaceURI?("xmlns"!==o&&(n+="xmlns:"),n+=o):"http://www.w3.org/1999/xlink"==e.namespaceURI?n+="xlink:"+o:n+=o:n+=o,""!=i&&(n+="=",r&&(n+=a?"'":'"'),n+=i,r&&(n+=a?"'":'"'))}return n}(s,e,t))),a+=">");"TEMPLATE"!=o||e.childNodes.length?Array.from(e.childNodes).forEach((e=>a+=St(e,t,s||"svg"==o))):a+=e.innerHTML;const i=t&&At.find((t=>o==Nt(t)&&t.accept(e.nextSibling,e)));(s||!i&&!Tt.includes(o))&&(a+="");return a}(e,t,s):void 0}function Rt(e){return Boolean(e.match(/^[ \t\n\f\r]/))}function Nt(e){return e.tagName&&e.tagName.toUpperCase()}const Pt={frameTree:Object.freeze({__proto__:null,getAsync:function(e){const t=it();return e=et.parse(et.stringify(e)),new Promise((s=>{nt.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{},resolve:e=>{e.sessionId=t,s(e)}}),rt({windowId:ot,sessionId:t,options:e})}))},getSync:function(e){const t=it();e=et.parse(et.stringify(e)),nt.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{}}),function(e){const t=e.sessionId,s=globalThis[ke.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,Xe||(ot=globalThis.frameId=e.windowId);ct(Qe,e.options,ot,t),Xe||(e.options.userScriptEnabled&&s&&s(ke.ON_BEFORE_CAPTURE_EVENT_NAME),gt({frames:[ft(Qe,globalThis,ot,e.options,e.scrolling)],sessionId:t,requestedFrameId:Qe.documentElement.dataset.requestedFrameId&&ot}),e.options.userScriptEnabled&&s&&s(ke.ON_AFTER_CAPTURE_EVENT_NAME),delete Qe.documentElement.dataset.requestedFrameId)}({windowId:ot,sessionId:t,options:e});const s=nt.get(t).frames;return s.sessionId=t,s},cleanup:function(e){nt.delete(e),lt({windowId:ot,sessionId:e,options:{sessionId:e}})},initResponse:dt,TIMEOUT_INIT_REQUEST_MESSAGE:je})},_t={COMMENT_HEADER:"Page saved with SingleFile",COMMENT_HEADER_LEGACY:"Archive processed by SingleFile",ON_BEFORE_CAPTURE_EVENT_NAME:P,ON_AFTER_CAPTURE_EVENT_NAME:_,WAIT_FOR_USERSCRIPT_PROPERTY_NAME:R,preProcessDoc:me,postProcessDoc:Te,serialize:(e,t)=>function(e,t){const s=e.doctype;let o="";return s&&(o=" "),o+St(e.documentElement,t)}(e,t),getShadowRoot:he};!function e(){re(L,(()=>globalThis[R]=async e=>{const t=new de(e+"-request",{cancelable:!0}),s=new Promise((t=>re(e+"-response",t)));(e=>{try{globalThis.dispatchEvent(e)}catch(e){}})(t),t.defaultPrevented&&await s})),new ce(e).observe(globalThis.document,{childList:!0})}(),e.helper=_t,e.processors=Pt,Object.defineProperty(e,"__esModule",{value:!0})}));