!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).singlefile={})}(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",i="single-file-block-cookies-start",a="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",u="single-file-load-image",m="single-file-image-loaded",h="_singleFile_fontFaces",g=globalThis.CustomEvent,p=globalThis.document,f=globalThis.Document,b=globalThis.JSON,E=globalThis.MutationObserver;let T;function y(){p instanceof f&&(p.addEventListener("single-file-new-font-face",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,T.set(b.stringify(s),t)})),p.addEventListener("single-file-delete-font",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,T.delete(b.stringify(s))})),p.addEventListener("single-file-clear-fonts",(()=>T=new Map)))}T=window[h]?window[h]:window[h]=new Map,y(),new E(y).observe(p,{childList:!0});const w="[\\x20\\t\\r\\n\\f]",I=new RegExp("\\\\([\\da-f]{1,6}"+w+"?|("+w+")|.)","ig");const v="single-file-",A="__frameTree__::",S=v+"on-before-capture",R=v+"on-after-capture",_=v+"request-get-adopted-stylesheets",M=v+"response-get-adopted-stylesheets",P=v+"unregister-request-get-adopted-stylesheets",N="data-"+v+"removed-content",C="data-"+v+"hidden-content",L="data-"+v+"kept-content",F="data-"+v+"hidden-frame",x="data-"+v+"preserved-space-element",q="data-"+v+"shadow-root-element",k="data-"+v+"win-id",U="data-"+v+"image",D="data-"+v+"poster",O="data-"+v+"video",V="data-"+v+"canvas",W="data-"+v+"movable-style",H="data-"+v+"input-value",z="data-"+v+"lazy-loaded-src",B="data-"+v+"stylesheet",j="data-"+v+"disabled-noscript",Y="data-"+v+"invalid-element",G="data-"+v+"async-script",Z="*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)",J=["NOSCRIPT","DISABLED-NOSCRIPT","META","LINK","STYLE","TITLE","TEMPLATE","SOURCE","OBJECT","SCRIPT","HEAD","BODY"],K=["SCRIPT","NOSCRIPT","META","LINK","TEMPLATE"],$=/^'(.*?)'$/,X=/^"(.*?)"$/,Q={regular:"400",normal:"400",bold:"700",bolder:"700",lighter:"100"},ee="single-file-ui-element",te="single-file-infobar",se="data:,",oe=globalThis.JSON,ne=globalThis.CustomEvent;function ie(e,t,s,o,n={usedFonts:new Map,canvases:[],images:[],posters:[],videos:[],shadowRoots:[],markedElements:[]},i){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 a,r,l;if(!o.autoSaveExternalSave&&(o.removeHiddenElements||o.removeUnusedFonts||o.compressHTML)&&(l=he(e,s),(s instanceof e.HTMLElement||s instanceof globalThis.HTMLElement)&&o.removeHiddenElements&&(r=(i||s.closest("html > head"))&&J.includes(s.tagName.toUpperCase())||s.closest("details"),r||(a=i||ce(s,l),a&&!K.includes(s.tagName.toUpperCase())&&(s.setAttribute(C,""),n.markedElements.push(s)))),!a)){if(o.compressHTML&&l){const e=l.getPropertyValue("white-space");e&&e.startsWith("pre")&&(s.setAttribute(x,""),n.markedElements.push(s))}o.removeUnusedFonts&&(re(l,o,n.usedFonts),re(he(e,s,":first-letter"),o,n.usedFonts),re(he(e,s,":before"),o,n.usedFonts),re(he(e,s,":after"),o,n.usedFonts))}!function(e,t,s,o,n,i,a){const r=s.tagName&&s.tagName.toUpperCase();if("CANVAS"==r)try{n.canvases.push({dataURI:s.toDataURL("image/png",""),backgroundColor:a.getPropertyValue("background-color")}),s.setAttribute(V,n.canvases.length-1),n.markedElements.push(s)}catch(e){}if("IMG"==r){const t={currentSrc:i?se:o.loadDeferredImages&&s.getAttribute(z)||s.currentSrc};if(n.images.push(t),s.setAttribute(U,n.images.length-1),n.markedElements.push(s),s.removeAttribute(z),a=a||he(e,s)){t.size=function(e,t,s){let o=t.naturalWidth,n=t.naturalHeight;if(!o&&!n){const i=null==t.getAttribute("style");if(s=s||he(e,t)){let e,a,r,l,d,c,u,m,h=!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"),h=t.clientWidth!=o,e?t.style.setProperty("box-sizing",e,s):t.style.removeProperty("box-sizing")}e=me("padding-left",s),a=me("padding-right",s),r=me("padding-top",s),l=me("padding-bottom",s),h?(d=me("border-left-width",s),c=me("border-right-width",s),u=me("border-top-width",s),m=me("border-bottom-width",s)):d=c=u=m=0,o=Math.max(0,t.clientWidth-e-a-d-c),n=Math.max(0,t.clientHeight-r-l-u-m),i&&t.removeAttribute("style")}}return{pxWidth:o,pxHeight:n}}(e,s,a);const o=a.getPropertyValue("box-shadow"),n=a.getPropertyValue("background-image");o&&"none"!=o||n&&"none"!=n||!(t.size.pxWidth>1||t.size.pxHeight>1)||(t.replaceable=!0,t.backgroundColor=a.getPropertyValue("background-color"),t.objectFit=a.getPropertyValue("object-fit"),t.boxSizing=a.getPropertyValue("box-sizing"),t.objectPosition=a.getPropertyValue("object-position"))}}if("VIDEO"==r){const o=s.currentSrc;if(o&&!o.startsWith("blob:")&&!o.startsWith("data:")){const t=he(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(O,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(D,n.posters.length-1),n.markedElements.push(s)}catch(e){}}}"IFRAME"==r&&i&&o.removeHiddenElements&&(s.setAttribute(F,""),n.markedElements.push(s));"INPUT"==r&&("password"!=s.type&&(s.setAttribute(H,s.value),n.markedElements.push(s)),"radio"!=s.type&&"checkbox"!=s.type||(s.setAttribute(H,s.checked),n.markedElements.push(s)));"TEXTAREA"==r&&(s.setAttribute(H,s.value),n.markedElements.push(s));"SELECT"==r&&s.querySelectorAll("option").forEach((e=>{e.selected&&(e.setAttribute(H,""),n.markedElements.push(e))}));"SCRIPT"==r&&(s.async&&""!=s.getAttribute("async")&&"async"!=s.getAttribute("async")&&(s.setAttribute(G,""),n.markedElements.push(s)),s.textContent=s.textContent.replace(/<\/script>/gi,"<\\/script>"))}(e,t,s,o,n,a,l);const d=!(s instanceof e.SVGElement||s instanceof globalThis.SVGElement)&&le(s);if(d&&!s.classList.contains(ee)&&s.tagName.toLowerCase()!=te){const i={};s.setAttribute(q,n.shadowRoots.length),n.markedElements.push(s),n.shadowRoots.push(i);try{if(d.adoptedStyleSheets)if(d.adoptedStyleSheets.length)i.adoptedStyleSheets=ae(d.adoptedStyleSheets);else if(void 0===d.adoptedStyleSheets.length){const e=e=>i.adoptedStyleSheets=e.detail.adoptedStyleSheets;d.addEventListener(M,e),d.dispatchEvent(new ne(_,{bubbles:!0})),i.adoptedStyleSheets||s.dispatchEvent(new ne(_,{bubbles:!0})),d.removeEventListener(M,e)}}catch(e){}ie(e,t,d,o,n,a),i.content=d.innerHTML,i.mode=d.mode;try{d.adoptedStyleSheets&&void 0===d.adoptedStyleSheets.length&&d.dispatchEvent(new ne(P,{bubbles:!0}))}catch(e){}}ie(e,t,s,o,n,a),!o.autoSaveExternalSave&&o.removeHiddenElements&&i&&(r||""==s.getAttribute(L)?s.parentElement&&(s.parentElement.setAttribute(L,""),n.markedElements.push(s.parentElement)):a&&(s.setAttribute(N,""),n.markedElements.push(s)))}))}return n}function ae(e){return e?Array.from(e).map((e=>Array.from(e.cssRules).map((e=>e.cssText)).join("\n"))):[]}function re(e,t,s){if(e){const o=e.getPropertyValue("font-style")||"normal";e.getPropertyValue("font-family").split(",").forEach((n=>{if(n=de(n),!t.loadedFonts||t.loadedFonts.find((e=>de(e.family)==n&&e.style==o))){const t=(i=e.getPropertyValue("font-weight"),Q[i.toLowerCase().trim()]||i),a=e.getPropertyValue("font-variant")||"normal",r=[n,t,o,a];s.set(oe.stringify(r),[n,t,o,a])}var i}))}}function le(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 de(e=""){return function(e){e=e.match($)?e.replace($,"$1"):e.replace(X,"$1");return e.trim()}((t=e.trim(),t.replace(I,((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 ce(e,t){let s=!1;if(t){const o=t.getPropertyValue("display"),n=t.getPropertyValue("opacity"),i=t.getPropertyValue("visibility");if(s="none"==o,!s&&("0"==n||"hidden"==i)&&e.getBoundingClientRect){const t=e.getBoundingClientRect();s=!t.width&&!t.height}}return Boolean(s)}function ue(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 i=n.sheet;n.remove();const a=Array.from(i.cssRules).map((e=>e.cssText)).join("\n"),r=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n");i&&a==r||(s.setAttribute(B,o),t[o]=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n"))}}catch(e){}})),t}}function me(e,t){if(t.getPropertyValue(e).endsWith("px"))return parseFloat(t.getPropertyValue(e))}function he(e,t,s){try{return e.getComputedStyle(t,s)}catch(e){}}const ge={LAZY_SRC_ATTRIBUTE_NAME:z,SINGLE_FILE_UI_ELEMENT_CLASS:ee},pe=10,fe="attributes",be=globalThis.browser,Ee=globalThis.document,Te=globalThis.MutationObserver,ye=new Map;let we;async function Ie(e){if(Ee.documentElement){ye.clear();const s=Ee.body?Math.max(Ee.body.scrollHeight,Ee.documentElement.scrollHeight):Ee.documentElement.scrollHeight,n=Ee.body?Math.max(Ee.body.scrollWidth,Ee.documentElement.scrollWidth):Ee.documentElement.scrollWidth;if(s>globalThis.innerHeight||n>globalThis.innerWidth){const a=Math.max(s-1.5*globalThis.innerHeight,0),l=Math.max(n-1.5*globalThis.innerWidth,0);if(globalThis.scrollY{let n;const a=new Set,l=new Te((async t=>{if((t=t.filter((e=>e.type==fe))).length){t.filter((e=>{if("src"==e.attributeName&&(e.target.setAttribute(ge.LAZY_SRC_ATTRIBUTE_NAME,e.target.src),e.target.addEventListener("load",h)),"src"==e.attributeName||"srcset"==e.attributeName||e.target.tagName&&"SOURCE"==e.target.tagName.toUpperCase())return!e.target.classList||!e.target.classList.contains(ge.SINGLE_FILE_UI_ELEMENT_CLASS)})).length&&(n=!0,await Ae(l,e,E),a.size||await ve(l,e,E))}}));async function c(t){await Re("idleTimeout",(async()=>{n?weSe(e,t,s)),t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function Ae(e,t,s){await Re("maxTimeout",(async()=>{await Me("loadTimeout"),await Se(e,t,s)}),10*t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function Se(e,t,o){await Me("idleTimeout"),function(e){e.loadDeferredImagesBlockCookies&&p.dispatchEvent(new g(a)),e.loadDeferredImagesBlockStorage&&p.dispatchEvent(new g(c)),e.loadDeferredImagesDispatchScrollEvent&&p.dispatchEvent(new g(l)),e.loadDeferredImagesKeepZoomLevel?p.dispatchEvent(new g(n)):p.dispatchEvent(new g(s))}(t),await Re("endTimeout",(async()=>{await Me("maxTimeout"),o()}),t.loadDeferredImagesMaxIdleTime/2,t.loadDeferredImagesNativeTimeout),e.disconnect()}async function Re(e,t,s,o){if(be&&be.runtime&&be.runtime.sendMessage&&!o){if(!ye.get(e)||!ye.get(e).pending){const o={callback:t,pending:!0};ye.set(e,o);try{await be.runtime.sendMessage({method:"singlefile.lazyTimeout.setTimeout",type:e,delay:s})}catch(o){_e(e,t,s)}o.pending=!1}}else _e(e,t,s)}function _e(e,t,s){const o=ye.get(e);o&&globalThis.clearTimeout(o),ye.set(e,t),globalThis.setTimeout(t,s)}async function Me(e){if(be&&be.runtime&&be.runtime.sendMessage)try{await be.runtime.sendMessage({method:"singlefile.lazyTimeout.clearTimeout",type:e})}catch(t){Pe(e)}else Pe(e)}function Pe(e){const t=ye.get(e);ye.delete(e),t&&globalThis.clearTimeout(t)}be&&be.runtime&&be.runtime.onMessage&&be.runtime.onMessage.addListener&&be.runtime.onMessage.addListener((e=>{if("singlefile.lazyTimeout.onTimeout"==e.method){const t=ye.get(e.type);if(t){ye.delete(e.type);try{t.callback()}catch(t){Pe(e.type)}}}}));const Ne={ON_BEFORE_CAPTURE_EVENT_NAME:S,ON_AFTER_CAPTURE_EVENT_NAME:R,WIN_ID_ATTRIBUTE_NAME:k,WAIT_FOR_USERSCRIPT_PROPERTY_NAME:"_singleFile_waitForUserScript",preProcessDoc:function(e,t,s){e.querySelectorAll("noscript:not(["+j+"])").forEach((e=>{e.setAttribute(j,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(Z).forEach((e=>e.hidden=!0)),e.querySelectorAll("svg foreignObject").forEach((e=>{const t=e.querySelectorAll("html > head > "+Z+", html > body > "+Z);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(Y,""),s.content.appendChild(t.cloneNode(!0)),o.set(t,s),t.replaceWith(s)})),n=ie(t,e,e.documentElement,s),s.moveStylesInHead&&e.querySelectorAll("body style, body ~ style").forEach((e=>{const s=he(t,e);s&&ce(e,s)&&(e.setAttribute(W,""),n.markedElements.push(e))}))):n={canvases:[],images:[],posters:[],videos:[],usedFonts:[],shadowRoots:[],markedElements:[]},{canvases:n.canvases,fonts:Array.from(T.values()),stylesheets:ue(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:ae(e.adoptedStyleSheets)}},serialize:function(e){const t=e.doctype;let s="";return t&&(s=" "),s+e.documentElement.outerHTML},postProcessDoc:function(e,t,s){if(e.querySelectorAll("["+j+"]").forEach((e=>{e.textContent=e.getAttribute(j),e.removeAttribute(j)})),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=[N,F,C,x,U,D,O,V,H,q,B,G];t=e.querySelectorAll(s.map((e=>"["+e+"]")).join(","))}t.forEach((e=>{e.removeAttribute(N),e.removeAttribute(C),e.removeAttribute(L),e.removeAttribute(F),e.removeAttribute(x),e.removeAttribute(U),e.removeAttribute(D),e.removeAttribute(O),e.removeAttribute(V),e.removeAttribute(H),e.removeAttribute(q),e.removeAttribute(B),e.removeAttribute(G),e.removeAttribute(W)})),s&&s.forEach(((e,t)=>e.replaceWith(t)))},getShadowRoot:le},Ce='iframe, frame, object[type="text/html"][data]',Le="*",Fe="singlefile.frameTree.initRequest",xe="singlefile.frameTree.ackInitRequest",qe="singlefile.frameTree.cleanupRequest",ke="singlefile.frameTree.initResponse",Ue="*",De=5e3,Oe=1e4,Ve=".",We=globalThis.window==globalThis.top,He=globalThis.browser,ze=globalThis.top,Be=globalThis.MessageChannel,je=globalThis.document,Ye=globalThis.JSON,Ge=globalThis.MutationObserver;let Ze,Je=globalThis.sessions;function Ke(){globalThis.addEventListener("message",(async e=>{if("string"==typeof e.data&&e.data.startsWith(A)){e.preventDefault(),e.stopPropagation();const t=Ye.parse(e.data.substring(A.length));if(t.method==Fe)e.source&&at(e.source,{method:xe,windowId:t.windowId,sessionId:t.sessionId}),We||(globalThis.stop(),t.options.loadDeferredImages&&Ie(t.options),await Xe(t));else if(t.method==xe)st("requestTimeouts",t.sessionId,t.windowId),ot(t.sessionId,t.windowId);else if(t.method==qe)Qe(t);else if(t.method==ke&&Je.get(t.sessionId)){e.ports[0].onmessage=e=>et(e.data)}}}),!0)}function $e(){return globalThis.crypto.getRandomValues(new Uint32Array(32)).join("")}async function Xe(e){const t=e.sessionId,s=globalThis[Ne.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,We||(Ze=globalThis.frameId=e.windowId),tt(je,e.options,Ze,t),We||(e.options.userScriptEnabled&&s&&await s(Ne.ON_BEFORE_CAPTURE_EVENT_NAME),it({frames:[rt(je,globalThis,Ze,e.options,e.scrolling)],sessionId:t,requestedFrameId:je.documentElement.dataset.requestedFrameId&&Ze}),e.options.userScriptEnabled&&s&&await s(Ne.ON_AFTER_CAPTURE_EVENT_NAME),delete je.documentElement.dataset.requestedFrameId)}function Qe(e){if(!globalThis._singleFile_cleaningUp){globalThis._singleFile_cleaningUp=!0;const t=e.sessionId;nt(lt(je),e.windowId,t)}}function et(e){e.frames.forEach((t=>st("responseTimeouts",e.sessionId,t.windowId)));const t=Je.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.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(Ve).length-e.windowId.split(Ve).length)),t.resolve&&(t.requestedFrameId&&t.frames.forEach((e=>{e.windowId==t.requestedFrameId&&(e.requestedFrame=!0)})),t.resolve(t.frames)))}}function tt(e,t,s,o){const n=lt(e);!function(e,t,s,o,n){const i=[];let a;Je.get(n)?a=Je.get(n).requestTimeouts:(a={},Je.set(n,{requestTimeouts:a}));t.forEach(((e,t)=>{const s=o+Ve+t;e.setAttribute(Ne.WIN_ID_ATTRIBUTE_NAME,s),i.push({windowId:s})})),it({frames:i,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),t.forEach(((e,t)=>{const i=o+Ve+t;try{at(e.contentWindow,{method:Fe,windowId:i,sessionId:n,options:s,scrolling:e.scrolling})}catch(e){}a[i]=globalThis.setTimeout((()=>it({frames:[{windowId:i,processed:!0}],sessionId:n})),De)})),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o),n.length&&function(e,t,s,o,n){const i=[];t.forEach(((e,t)=>{const a=o+Ve+t;let r;try{r=e.contentDocument}catch(e){}if(r)try{const t=e.contentWindow;t.stop(),st("requestTimeouts",n,a),tt(r,s,a,n),i.push(rt(r,t,a,s,e.scrolling))}catch(e){i.push({windowId:a,processed:!0})}})),it({frames:i,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o)}function st(e,t,s){const o=Je.get(t);if(o&&o[e]){const t=o[e][s];t&&(globalThis.clearTimeout(t),delete o[e][s])}}function ot(e,t){const s=Je.get(e);s&&s.responseTimeouts&&(s.responseTimeouts[t]=globalThis.setTimeout((()=>it({frames:[{windowId:t,processed:!0}],sessionId:e})),Oe))}function nt(e,t,s){e.forEach(((e,o)=>{const n=t+Ve+o;e.removeAttribute(Ne.WIN_ID_ATTRIBUTE_NAME);try{at(e.contentWindow,{method:qe,windowId:n,sessionId:s})}catch(e){}})),e.forEach(((e,o)=>{const n=t+Ve+o;let i;try{i=e.contentDocument}catch(e){}if(i)try{nt(lt(i),n,s)}catch(e){}}))}function it(e){e.method=ke;try{ze.singlefile.processors.frameTree.initResponse(e)}catch(t){at(ze,e,!0)}}function at(e,t,s){if(e==ze&&He&&He.runtime&&He.runtime.sendMessage)He.runtime.sendMessage(t);else if(s){const s=new Be;e.postMessage(A+Ye.stringify({method:t.method,sessionId:t.sessionId}),Ue,[s.port2]),s.port1.postMessage(t)}else e.postMessage(A+Ye.stringify(t),Ue)}function rt(e,t,s,o,n){const i=Ne.preProcessDoc(e,t,o),a=Ne.serialize(e);Ne.postProcessDoc(e,i.markedElements,i.invalidElements);return{windowId:s,content:a,baseURI:e.baseURI.split("#")[0],url:e.documentURI,title:e.title,canvases:i.canvases,fonts:i.fonts,stylesheets:i.stylesheets,images:i.images,posters:i.posters,videos:i.videos,usedFonts:i.usedFonts,shadowRoots:i.shadowRoots,scrollPosition:i.scrollPosition,scrolling:n,adoptedStyleSheets:i.adoptedStyleSheets,processed:!0}}function lt(e){let t=Array.from(e.querySelectorAll(Ce));return e.querySelectorAll(Le).forEach((e=>{const s=Ne.getShadowRoot(e);s&&(t=t.concat(...s.querySelectorAll(Ce)))})),t}Je||(Je=globalThis.sessions=new Map),We&&(Ze="0",He&&He.runtime&&He.runtime.onMessage&&He.runtime.onMessage.addListener&&He.runtime.onMessage.addListener((e=>e.method==ke?(et(e),Promise.resolve({})):e.method==xe?(st("requestTimeouts",e.sessionId,e.windowId),ot(e.sessionId,e.windowId),Promise.resolve({})):void 0))),Ke(),new Ge(Ke).observe(je,{childList:!0}),e.TIMEOUT_INIT_REQUEST_MESSAGE=De,e.cleanup=function(e){Je.delete(e),Qe({windowId:Ze,sessionId:e,options:{sessionId:e}})},e.getAsync=function(e){const t=$e();return e=Ye.parse(Ye.stringify(e)),new Promise((s=>{Je.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{},resolve:e=>{e.sessionId=t,s(e)}}),Xe({windowId:Ze,sessionId:t,options:e})}))},e.getSync=function(e){const t=$e();e=Ye.parse(Ye.stringify(e)),Je.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{}}),function(e){const t=e.sessionId,s=globalThis[Ne.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,We||(Ze=globalThis.frameId=e.windowId);tt(je,e.options,Ze,t),We||(e.options.userScriptEnabled&&s&&s(Ne.ON_BEFORE_CAPTURE_EVENT_NAME),it({frames:[rt(je,globalThis,Ze,e.options,e.scrolling)],sessionId:t,requestedFrameId:je.documentElement.dataset.requestedFrameId&&Ze}),e.options.userScriptEnabled&&s&&s(Ne.ON_AFTER_CAPTURE_EVENT_NAME),delete je.documentElement.dataset.requestedFrameId)}({windowId:Ze,sessionId:t,options:e});const s=Je.get(t).frames;return s.sessionId=t,s},e.initResponse=et,Object.defineProperty(e,"__esModule",{value:!0})}));