!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-image",s="single-file-image-loaded",n=globalThis.browser,o=(e,t,s)=>globalThis.addEventListener(e,t,s),a=e=>globalThis.dispatchEvent(e),i=globalThis.CustomEvent,r=globalThis.document,l=globalThis.Document;let d;if(d=window._singleFile_fontFaces?window._singleFile_fontFaces:window._singleFile_fontFaces=new Map,r instanceof l&&n&&n.runtime&&n.runtime.getURL){o("single-file-new-font-face",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,d.set(JSON.stringify(s),t)})),o("single-file-delete-font",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,d.delete(JSON.stringify(s))})),o("single-file-clear-fonts",(()=>d=new Map));let e=r.createElement("script");e.src="data:,("+function(){"undefined"==typeof globalThis&&(window.globalThis=window);const e=globalThis.document,t=globalThis.console,s=e=>globalThis.dispatchEvent(e),n=globalThis.CustomEvent,o=globalThis.FileReader,a=globalThis.Blob,i=t&&t.warn&&((...e)=>t.warn(...e))||(()=>{}),r="single-file-new-font-face",l="single-file-delete-font",d="single-file-clear-fonts",c={family:"font-family",style:"font-style",weight:"font-weight",stretch:"font-stretch",unicodeRange:"unicode-range",variant:"font-variant",featureSettings:"font-feature-settings"};if(globalThis.FontFace){const t=globalThis.FontFace;let o;globalThis.FontFace=function(){return o||(i("SingleFile is hooking the FontFace constructor, document.fonts.delete and document.fonts.clear to handle dynamically loaded fonts."),o=!0),m(...arguments).then((e=>s(new n(r,{detail:e})))),new t(...arguments)},globalThis.FontFace.toString=function(){return"function FontFace() { [native code] }"};const a=e.fonts.delete;e.fonts.delete=function(t){return m(t.family).then((e=>s(new n(l,{detail:e})))),a.call(e.fonts,t)},e.fonts.delete.toString=function(){return"function delete() { [native code] }"};const c=e.fonts.clear;e.fonts.clear=function(){return s(new n(d)),c.call(e.fonts)},e.fonts.clear.toString=function(){return"function clear() { [native code] }"}}async function m(e,t,s){const n={};return n["font-family"]=e,n.src=t,s&&Object.keys(s).forEach((e=>{c[e]&&(n[c[e]]=s[e])})),new Promise((e=>{if(n.src instanceof ArrayBuffer){const t=new o;t.readAsDataURL(new a([n.src])),t.addEventListener("load",(()=>{n.src="url("+t.result+")",e(n)}))}else e(n)}))}}.toString()+")()",(r.documentElement||r).appendChild(e),e.remove(),e=r.createElement("script"),e.src=n.runtime.getURL("/lib/web/hooks/hooks-frames-web.js"),e.async=!1,(r.documentElement||r).appendChild(e),e.remove()}const c=new RegExp("\\\\([\\da-f]{1,6}[\\x20\\t\\r\\n\\f]?|([\\x20\\t\\r\\n\\f])|.)","ig");const m="single-file-on-before-capture",u="single-file-on-after-capture",g="data-single-file-removed-content",p="data-single-file-hidden-content",f="data-single-file-kept-content",h="data-single-file-hidden-frame",b="data-single-file-preserved-space-element",E="data-single-file-shadow-root-element",T="data-single-file-image",y="data-single-file-poster",w="data-single-file-video",A="data-single-file-canvas",I="data-single-file-import",v="data-single-file-movable-style",N="data-single-file-input-value",S="data-single-file-lazy-loaded-src",R="data-single-file-stylesheet",F="data-single-file-disabled-noscript",C="data-single-file-async-script",_="*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)",P=["NOSCRIPT","DISABLED-NOSCRIPT","META","LINK","STYLE","TITLE","TEMPLATE","SOURCE","OBJECT","SCRIPT","HEAD"],x=/^'(.*?)'$/,O=/^"(.*?)"$/,M={regular:"400",normal:"400",bold:"700",bolder:"700",lighter:"100"},L="single-file-ui-element",k=(e,t,s)=>globalThis.addEventListener(e,t,s);function D(e,t,s){let n;return e.querySelectorAll("noscript:not([data-single-file-disabled-noscript])").forEach((e=>{e.setAttribute(F,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))))})),t&&e.documentElement?(n=q(t,e,e.documentElement,s),s.moveStylesInHead&&e.querySelectorAll("body style, body ~ style").forEach((e=>{const s=t.getComputedStyle(e);s&&B(e,s)&&(e.setAttribute(v,""),n.markedElements.push(e))}))):n={canvases:[],images:[],posters:[],videos:[],usedFonts:[],shadowRoots:[],imports:[],markedElements:[]},{canvases:n.canvases,fonts:Array.from(d.values()),stylesheets:j(e),images:n.images,posters:n.posters,videos:n.videos,usedFonts:Array.from(n.usedFonts.values()),shadowRoots:n.shadowRoots,imports:n.imports,referrer:e.referrer,markedElements:n.markedElements}}function q(e,t,s,n,o={usedFonts:new Map,canvases:[],images:[],posters:[],videos:[],shadowRoots:[],imports:[],markedElements:[]},a){return Array.from(s.childNodes).filter((t=>t instanceof e.HTMLElement||t instanceof e.SVGElement)).forEach((s=>{let i,r,l;if(!n.autoSaveExternalSave&&(n.removeHiddenElements||n.removeUnusedFonts||n.compressHTML)&&(l=e.getComputedStyle(s),s instanceof e.HTMLElement&&n.removeHiddenElements&&(r=(a||s.closest("html > head"))&&P.includes(s.tagName)||s.closest("details"),r||(i=a||B(s,l),i&&(s.setAttribute(p,""),o.markedElements.push(s)))),!i)){if(n.compressHTML&&l){const e=l.getPropertyValue("white-space");e&&e.startsWith("pre")&&(s.setAttribute(b,""),o.markedElements.push(s))}n.removeUnusedFonts&&(U(l,n,o.usedFonts),U(e.getComputedStyle(s,":first-letter"),n,o.usedFonts),U(e.getComputedStyle(s,":before"),n,o.usedFonts),U(e.getComputedStyle(s,":after"),n,o.usedFonts))}!function(e,t,s,n,o,a,i){if("CANVAS"==s.tagName)try{o.canvases.push({dataURI:s.toDataURL("image/png","")}),s.setAttribute(A,o.canvases.length-1),o.markedElements.push(s)}catch(e){}if("IMG"==s.tagName){const t={currentSrc:a?"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==":n.loadDeferredImages&&s.getAttribute(S)||s.currentSrc};if(o.images.push(t),s.setAttribute(T,o.images.length-1),o.markedElements.push(s),s.removeAttribute(S),i=i||e.getComputedStyle(s)){t.size=function(e,t,s){let n=t.naturalWidth,o=t.naturalHeight;if(!n&&!o){const a=null==t.getAttribute("style");let i,r,l,d,c,m,u,g,p=!1;if("content-box"==(s=s||e.getComputedStyle(t)).getPropertyValue("box-sizing")){const e=t.style.getPropertyValue("box-sizing"),s=t.style.getPropertyPriority("box-sizing"),n=t.clientWidth;t.style.setProperty("box-sizing","border-box","important"),p=t.clientWidth!=n,e?t.style.setProperty("box-sizing",e,s):t.style.removeProperty("box-sizing")}i=W("padding-left",s),r=W("padding-right",s),l=W("padding-top",s),d=W("padding-bottom",s),p?(c=W("border-left-width",s),m=W("border-right-width",s),u=W("border-top-width",s),g=W("border-bottom-width",s)):c=m=u=g=0,n=Math.max(0,t.clientWidth-i-r-c-m),o=Math.max(0,t.clientHeight-l-d-u-g),a&&t.removeAttribute("style")}return{pxWidth:n,pxHeight:o}}(e,s,i);const n=i.getPropertyValue("box-shadow"),o=i.getPropertyValue("background-image");n&&"none"!=n||o&&"none"!=o||!(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"==s.tagName&&(s.currentSrc&&(o.videos.push(s.currentSrc),s.setAttribute(w,o.videos.length-1)),!s.poster)){const e=t.createElement("canvas"),n=e.getContext("2d");e.width=s.clientWidth,e.height=s.clientHeight;try{n.drawImage(s,0,0,e.width,e.height),o.posters.push(e.toDataURL("image/png","")),s.setAttribute(y,o.posters.length-1),o.markedElements.push(s)}catch(e){}}"IFRAME"==s.tagName&&a&&n.removeHiddenElements&&(s.setAttribute(h,""),o.markedElements.push(s));"LINK"==s.tagName&&s.import&&s.import.documentElement&&(o.imports.push({content:J(s.import)}),s.setAttribute(I,o.imports.length-1),o.markedElements.push(s));"INPUT"==s.tagName&&("password"!=s.type&&(s.setAttribute(N,s.value),o.markedElements.push(s)),"radio"!=s.type&&"checkbox"!=s.type||(s.setAttribute(N,s.checked),o.markedElements.push(s)));"TEXTAREA"==s.tagName&&(s.setAttribute(N,s.value),o.markedElements.push(s));"SELECT"==s.tagName&&s.querySelectorAll("option").forEach((e=>{e.selected&&(e.setAttribute(N,""),o.markedElements.push(e))}));"SCRIPT"==s.tagName&&(s.async&&""!=s.getAttribute("async")&&"async"!=s.getAttribute("async")&&(s.setAttribute(C,""),o.markedElements.push(s)),s.textContent=s.textContent.replace(/<\/script>/gi,"<\\/script>"))}(e,t,s,n,o,i,l);const d=!(s instanceof e.SVGElement)&&H(s);if(d&&!s.classList.contains(L)){const a={};s.setAttribute(E,o.shadowRoots.length),o.markedElements.push(s),o.shadowRoots.push(a),q(e,t,d,n,o,i),a.content=d.innerHTML,a.delegatesFocus=d.delegatesFocus,a.mode=d.mode,d.adoptedStyleSheets&&d.adoptedStyleSheets.length&&(a.adoptedStyleSheets=Array.from(d.adoptedStyleSheets).map((e=>Array.from(e.cssRules).map((e=>e.cssText)).join("\n"))))}q(e,t,s,n,o,i),!n.autoSaveExternalSave&&n.removeHiddenElements&&a&&(r||""==s.getAttribute(f)?s.parentElement&&(s.parentElement.setAttribute(f,""),o.markedElements.push(s.parentElement)):i&&(s.setAttribute(g,""),o.markedElements.push(s)))})),o}function U(e,t,s){if(e){const n=e.getPropertyValue("font-style")||"normal";e.getPropertyValue("font-family").split(",").forEach((o=>{if(o=V(o),!t.loadedFonts||t.loadedFonts.find((e=>V(e.family)==o&&e.style==n))){const t=(a=e.getPropertyValue("font-weight"),M[a.toLowerCase().trim()]||a),i=e.getPropertyValue("font-variant")||"normal",r=[o,t,n,i];s.set(JSON.stringify(r),[o,t,n,i])}var a}))}}function H(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 V(e=""){return function(e){e=e.match(x)?e.replace(x,"$1"):e.replace(O,"$1");return e.trim()}((t=e.trim(),t.replace(c,((e,t,s)=>{const n="0x"+t-65536;return n!=n||s?t:n<0?String.fromCharCode(n+65536):String.fromCharCode(n>>10|55296,1023&n|56320)})))).toLowerCase();var t}function B(e,t){let s=!1;if(t){const n=t.getPropertyValue("display"),o=t.getPropertyValue("opacity"),a=t.getPropertyValue("visibility");if(s="none"==n,!s&&("0"==o||"hidden"==a)&&e.getBoundingClientRect){const t=e.getBoundingClientRect();s=!t.width&&!t.height}}return Boolean(s)}function z(e,t){if(e.querySelectorAll("[data-single-file-disabled-noscript]").forEach((e=>{e.textContent=e.getAttribute(F),e.removeAttribute(F)})),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=[g,h,p,b,T,y,w,A,N,E,I,R,C];t=e.querySelectorAll(s.map((e=>"["+e+"]")).join(","))}t.forEach((e=>{e.removeAttribute(g),e.removeAttribute(p),e.removeAttribute(f),e.removeAttribute(h),e.removeAttribute(b),e.removeAttribute(T),e.removeAttribute(y),e.removeAttribute(w),e.removeAttribute(A),e.removeAttribute(N),e.removeAttribute(E),e.removeAttribute(I),e.removeAttribute(R),e.removeAttribute(C),e.removeAttribute(v)}))}function j(e){if(e){const t=[];return e.querySelectorAll("style").forEach(((s,n)=>{try{const o=e.createElement("style");o.textContent=s.textContent,e.body.appendChild(o);const a=o.sheet;o.remove(),a&&a.cssRules.length==s.sheet.cssRules.length||(s.setAttribute(R,n),t[n]=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n"))}catch(e){}})),t}}function W(e,t){if(t.getPropertyValue(e).endsWith("px"))return parseFloat(t.getPropertyValue(e))}function J(e){const t=e.doctype;let s="";return t&&(s=" "),s+e.documentElement.outerHTML}const G=S,Y=L,K="attributes",$=globalThis.browser,Q=globalThis.document,X=globalThis.MutationObserver,Z=(e,t,s)=>globalThis.addEventListener(e,t,s),ee=(e,t,s)=>globalThis.removeEventListener(e,t,s),te=new Map;let se;async function ne(e){if(Q.documentElement){te.clear();const n=Math.max(Q.documentElement.scrollHeight-1.5*Q.documentElement.clientHeight,0),o=Math.max(Q.documentElement.scrollWidth-1.5*Q.documentElement.clientWidth,0);if(globalThis.scrollY<=n&&globalThis.scrollX<=o)return function(e){return se=0,new Promise((async n=>{let o;const r=new Set,l=new X((async t=>{if((t=t.filter((e=>e.type==K))).length){t.filter((e=>{if("src"==e.attributeName&&(e.target.setAttribute(G,e.target.src),e.target.addEventListener("load",c)),"src"==e.attributeName||"srcset"==e.attributeName||"SOURCE"==e.target.tagName)return!e.target.classList||!e.target.classList.contains(Y)})).length&&(o=!0,await ae(l,e,g),r.size||await oe(l,e,g))}}));async function d(t){await re("idleTimeout",(async()=>{o?se<10&&(se++,de("idleTimeout"),await d(Math.max(500,t/2))):(de("loadTimeout"),de("maxTimeout"),ie(l,e,g))}),t)}function c(e){const t=e.target;t.removeAttribute(G),t.removeEventListener("load",c)}async function m(t){o=!0,await ae(l,e,g),await oe(l,e,g),t.detail&&r.add(t.detail)}async function u(t){await ae(l,e,g),await oe(l,e,g),r.delete(t.detail),r.size||await oe(l,e,g)}function g(e){l.disconnect(),ee(t,m),ee(s,u),n(e)}await d(2*e.loadDeferredImagesMaxIdleTime),await ae(l,e,g),l.observe(Q,{subtree:!0,childList:!0,attributes:!0}),Z(t,m),Z(s,u),function(e){e.loadDeferredImagesBlockCookies&&a(new i("single-file-block-cookies-start")),e.loadDeferredImagesBlockStorage&&a(new i("single-file-block-storage-start")),e.loadDeferredImagesKeepZoomLevel?a(new i("single-file-load-deferred-images-keep-zoom-level-start")):a(new i("single-file-load-deferred-images-start"))}(e)}))}(e)}}async function oe(e,t,s){await re("loadTimeout",(()=>ie(e,t,s)),t.loadDeferredImagesMaxIdleTime)}async function ae(e,t,s){await re("maxTimeout",(async()=>{await de("loadTimeout"),await ie(e,t,s)}),10*t.loadDeferredImagesMaxIdleTime)}async function ie(e,t,s){await de("idleTimeout"),function(e){e.loadDeferredImagesBlockCookies&&a(new i("single-file-block-cookies-end")),e.loadDeferredImagesBlockStorage&&a(new i("single-file-block-storage-end")),e.loadDeferredImagesKeepZoomLevel?a(new i("single-file-load-deferred-images-keep-zoom-level-end")):a(new i("single-file-load-deferred-images-end"))}(t),await re("endTimeout",(async()=>{await de("maxTimeout"),s()}),t.loadDeferredImagesMaxIdleTime/2),e.disconnect()}async function re(e,t,s){if($&&$.runtime&&$.runtime.sendMessage){if(!te.get(e)||!te.get(e).pending){const n={callback:t,pending:!0};te.set(e,n);try{await $.runtime.sendMessage({method:"singlefile.lazyTimeout.setTimeout",type:e,delay:s})}catch(n){le(e,t,s)}n.pending=!1}}else le(e,t,s)}function le(e,t,s){const n=te.get(e);n&&globalThis.clearTimeout(n),te.set(e,t),globalThis.setTimeout(t,s)}async function de(e){if($&&$.runtime&&$.runtime.sendMessage)try{await $.runtime.sendMessage({method:"singlefile.lazyTimeout.clearTimeout",type:e})}catch(t){ce(e)}else ce(e)}function ce(e){const t=te.get(e);te.delete(e),t&&globalThis.clearTimeout(t)}$&&$.runtime&&$.runtime.onMessage&&$.runtime.onMessage.addListener&&$.runtime.onMessage.addListener((e=>{if("singlefile.lazyTimeout.onTimeout"==e.method){const t=te.get(e.type);if(t){te.delete(e.type);try{t.callback()}catch(t){ce(e.type)}}}}));const me={ON_BEFORE_CAPTURE_EVENT_NAME:m,ON_AFTER_CAPTURE_EVENT_NAME:u,WIN_ID_ATTRIBUTE_NAME:"data-single-file-win-id",preProcessDoc:D,serialize:J,postProcessDoc:z,getShadowRoot:H},ue="__frameTree__::",ge='iframe, frame, object[type="text/html"][data]',pe="singlefile.frameTree.initRequest",fe="singlefile.frameTree.ackInitRequest",he="singlefile.frameTree.cleanupRequest",be="singlefile.frameTree.initResponse",Ee=5e3,Te=".",ye=globalThis.window==globalThis.top,we=globalThis.browser,Ae=globalThis.top,Ie=globalThis.MessageChannel,ve=globalThis.document,Ne=new Map;let Se;var Re,Fe,Ce;function _e(){return globalThis.crypto.getRandomValues(new Uint32Array(32)).join("")}async function Pe(e){const t=e.sessionId,s=globalThis._singleFile_waitForUserScript;delete globalThis._singleFile_cleaningUp,ye||(Se=globalThis.frameId=e.windowId),Me(ve,e.options,Se,t),ye||(e.options.userScriptEnabled&&s&&await s(me.ON_BEFORE_CAPTURE_EVENT_NAME),qe({frames:[He(ve,globalThis,Se,e.options)],sessionId:t,requestedFrameId:ve.documentElement.dataset.requestedFrameId&&Se}),e.options.userScriptEnabled&&s&&await s(me.ON_AFTER_CAPTURE_EVENT_NAME),delete ve.documentElement.dataset.requestedFrameId)}function xe(e){if(!globalThis._singleFile_cleaningUp){globalThis._singleFile_cleaningUp=!0;const t=e.sessionId;De(Ve(ve),e.windowId,t)}}function Oe(e){e.frames.forEach((t=>Le("responseTimeouts",e.sessionId,t.windowId)));const t=Ne.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.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.imports=e.imports,s.processed=e.processed)}));t.frames.filter((e=>!e.processed)).length||(t.frames=t.frames.sort(((e,t)=>t.windowId.split(Te).length-e.windowId.split(Te).length)),t.resolve&&(t.requestedFrameId&&t.frames.forEach((e=>{e.windowId==t.requestedFrameId&&(e.requestedFrame=!0)})),t.resolve(t.frames)))}}function Me(e,t,s,n){const o=Ve(e);!function(e,t,s,n,o){const a=[];let i;Ne.get(o)?i=Ne.get(o).requestTimeouts:(i={},Ne.set(o,{requestTimeouts:i}));t.forEach(((e,t)=>{const s=n+Te+t;e.setAttribute(me.WIN_ID_ATTRIBUTE_NAME,s),a.push({windowId:s})})),qe({frames:a,sessionId:o,requestedFrameId:e.documentElement.dataset.requestedFrameId&&n}),t.forEach(((e,t)=>{const a=n+Te+t;try{Ue(e.contentWindow,{method:pe,windowId:a,sessionId:o,options:s})}catch(e){}i[a]=globalThis.setTimeout((()=>qe({frames:[{windowId:a,processed:!0}],sessionId:o})),Ee)})),delete e.documentElement.dataset.requestedFrameId}(e,o,t,s,n),o.length&&function(e,t,s,n,o){const a=[];t.forEach(((e,t)=>{const i=n+Te+t;let r;try{r=e.contentDocument}catch(e){}if(r)try{const t=e.contentWindow;t.stop(),Le("requestTimeouts",o,i),Me(r,s,i,o),a.push(He(r,t,i,s))}catch(e){a.push({windowId:i,processed:!0})}})),qe({frames:a,sessionId:o,requestedFrameId:e.documentElement.dataset.requestedFrameId&&n}),delete e.documentElement.dataset.requestedFrameId}(e,o,t,s,n)}function Le(e,t,s){const n=Ne.get(t);if(n&&n[e]){const t=n[e][s];t&&(globalThis.clearTimeout(t),delete n[e][s])}}function ke(e,t){const s=Ne.get(e);s&&s.responseTimeouts&&(s.responseTimeouts[t]=globalThis.setTimeout((()=>qe({frames:[{windowId:t,processed:!0}],sessionId:e})),1e4))}function De(e,t,s){e.forEach(((e,n)=>{const o=t+Te+n;e.removeAttribute(me.WIN_ID_ATTRIBUTE_NAME);try{Ue(e.contentWindow,{method:he,windowId:o,sessionId:s})}catch(e){}})),e.forEach(((e,n)=>{const o=t+Te+n;let a;try{a=e.contentDocument}catch(e){}if(a)try{De(Ve(a),o,s)}catch(e){}}))}function qe(e){e.method=be;try{Ae.singlefile.processors.frameTree.initResponse(e)}catch(t){Ue(Ae,e,!0)}}function Ue(e,t,s){if(e==Ae&&we&&we.runtime&&we.runtime.sendMessage)we.runtime.sendMessage(t);else if(s){const s=new Ie;e.postMessage(ue+JSON.stringify({method:t.method,sessionId:t.sessionId}),"*",[s.port2]),s.port1.postMessage(t)}else e.postMessage(ue+JSON.stringify(t),"*")}function He(e,t,s,n){const o=me.preProcessDoc(e,t,n),a=me.serialize(e);me.postProcessDoc(e,o.markedElements);return{windowId:s,content:a,baseURI:e.baseURI.split("#")[0],title:e.title,canvases:o.canvases,fonts:o.fonts,stylesheets:o.stylesheets,images:o.images,posters:o.posters,videos:o.videos,usedFonts:o.usedFonts,shadowRoots:o.shadowRoots,imports:o.imports,processed:!0}}function Ve(e){let t=Array.from(e.querySelectorAll(ge));return e.querySelectorAll("*").forEach((e=>{const s=me.getShadowRoot(e);s&&(t=t.concat(...s.querySelectorAll(ge)))})),t}ye&&(Se="0",we&&we.runtime&&we.runtime.onMessage&&we.runtime.onMessage.addListener&&we.runtime.onMessage.addListener((e=>e.method==be?(Oe(e),Promise.resolve({})):e.method==fe?(Le("requestTimeouts",e.sessionId,e.windowId),ke(e.sessionId,e.windowId),Promise.resolve({})):void 0))),Re="message",Fe=async e=>{if("string"==typeof e.data&&e.data.startsWith(ue)){e.preventDefault(),e.stopPropagation();const t=JSON.parse(e.data.substring(ue.length));t.method==pe?(e.source&&Ue(e.source,{method:fe,windowId:t.windowId,sessionId:t.sessionId}),ye||(globalThis.stop(),t.options.loadDeferredImages&&ne(t.options),await Pe(t))):t.method==fe?(Le("requestTimeouts",t.sessionId,t.windowId),ke(t.sessionId,t.windowId)):t.method==he?xe(t):t.method==be&&Ne.get(t.sessionId)&&(e.ports[0].onmessage=e=>Oe(e.data))}},Ce=!0,globalThis.addEventListener(Re,Fe,Ce);var Be=Object.freeze({__proto__:null,getAsync:function(e){const t=_e();return e=JSON.parse(JSON.stringify(e)),new Promise((s=>{Ne.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{},resolve:e=>{e.sessionId=t,s(e)}}),Pe({windowId:Se,sessionId:t,options:e})}))},getSync:function(e){const t=_e();e=JSON.parse(JSON.stringify(e)),Ne.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{}}),function(e){const t=e.sessionId,s=globalThis._singleFile_waitForUserScript;delete globalThis._singleFile_cleaningUp,ye||(Se=globalThis.frameId=e.windowId);Me(ve,e.options,Se,t),ye||(e.options.userScriptEnabled&&s&&s(me.ON_BEFORE_CAPTURE_EVENT_NAME),qe({frames:[He(ve,globalThis,Se,e.options)],sessionId:t,requestedFrameId:ve.documentElement.dataset.requestedFrameId&&Se}),e.options.userScriptEnabled&&s&&s(me.ON_AFTER_CAPTURE_EVENT_NAME),delete ve.documentElement.dataset.requestedFrameId)}({windowId:Se,sessionId:t,options:e});const s=Ne.get(t).frames;return s.sessionId=t,s},cleanup:function(e){Ne.delete(e),xe({windowId:Se,sessionId:e,options:{sessionId:e}})},initResponse:Oe,TIMEOUT_INIT_REQUEST_MESSAGE:Ee});const ze=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],je=[{tagName:"head",accept:e=>!e.childNodes.length||1==e.childNodes[0].nodeType},{tagName:"body",accept:e=>!e.childNodes.length}],We=[{tagName:"html",accept:e=>!e||8!=e.nodeType},{tagName:"head",accept:e=>!e||8!=e.nodeType&&(3!=e.nodeType||!Ye(e.textContent))},{tagName:"body",accept:e=>!e||8!=e.nodeType},{tagName:"li",accept:(e,t)=>!e&&t.parentElement&&("UL"==t.parentElement.tagName||"OL"==t.parentElement.tagName)||e&&["LI"].includes(e.tagName)},{tagName:"dt",accept:e=>!e||["DT","DD"].includes(e.tagName)},{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(e.tagName)},{tagName:"dd",accept:e=>!e||["DT","DD"].includes(e.tagName)},{tagName:"rt",accept:e=>!e||["RT","RP"].includes(e.tagName)},{tagName:"rp",accept:e=>!e||["RT","RP"].includes(e.tagName)},{tagName:"optgroup",accept:e=>!e||["OPTGROUP"].includes(e.tagName)},{tagName:"option",accept:e=>!e||["OPTION","OPTGROUP"].includes(e.tagName)},{tagName:"colgroup",accept:e=>!e||8!=e.nodeType&&(3!=e.nodeType||!Ye(e.textContent))},{tagName:"caption",accept:e=>!e||8!=e.nodeType&&(3!=e.nodeType||!Ye(e.textContent))},{tagName:"thead",accept:e=>!e||["TBODY","TFOOT"].includes(e.tagName)},{tagName:"tbody",accept:e=>!e||["TBODY","TFOOT"].includes(e.tagName)},{tagName:"tfoot",accept:e=>!e},{tagName:"tr",accept:e=>!e||["TR"].includes(e.tagName)},{tagName:"td",accept:e=>!e||["TD","TH"].includes(e.tagName)},{tagName:"th",accept:e=>!e||["TD","TH"].includes(e.tagName)}],Je=["style","script","xmp","iframe","noembed","noframes","plaintext","noscript"];function Ge(e,t,s){return 3==e.nodeType?function(e){const t=e.parentNode;let s;t&&1==t.nodeType&&(s=t.tagName.toLowerCase());return!s||Je.includes(s)?"script"==s?e.textContent.replace(/<\//gi,"<\\/").replace(/\/>/gi,"\\/>"):e.textContent:e.textContent.replace(/&/g,"&").replace(/\u00a0/g," ").replace(//g,">")}(e):8==e.nodeType?"\x3c!--"+e.textContent+"--\x3e":1==e.nodeType?function(e,t,s){const n=e.tagName.toLowerCase(),o=t&&je.find((t=>n==t.tagName&&t.accept(e)));let a="";o&&!e.attributes.length||(a="<"+n,Array.from(e.attributes).forEach((s=>a+=function(e,t,s){const n=e.name;let o="";if(!n.match(/["'>/=]/)){let a,i=e.value;s&&"class"==n&&(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'"`=<>]+$/);o+=" ",e.namespace?"http://www.w3.org/XML/1998/namespace"==e.namespaceURI?o+="xml:"+n:"http://www.w3.org/2000/xmlns/"==e.namespaceURI?("xmlns"!==n&&(o+="xmlns:"),o+=n):"http://www.w3.org/1999/xlink"==e.namespaceURI?o+="xlink:"+n:o+=n:o+=n,""!=i&&(o+="=",r&&(o+=a?"'":'"'),o+=i,r&&(o+=a?"'":'"'))}return o}(s,e,t))),a+=">");"TEMPLATE"!=e.tagName||e.childNodes.length?Array.from(e.childNodes).forEach((e=>a+=Ge(e,t,s||"svg"==n))):a+=e.innerHTML;const i=t&&We.find((t=>n==t.tagName&&t.accept(e.nextSibling,e)));(s||!i&&!ze.includes(n))&&(a+="");return a}(e,t,s):void 0}function Ye(e){return Boolean(e.match(/^[ \t\n\f\r]/))}const Ke={frameTree:Be},$e={COMMENT_HEADER:"Page saved with SingleFile",COMMENT_HEADER_LEGACY:"Archive processed by SingleFile",ON_BEFORE_CAPTURE_EVENT_NAME:m,ON_AFTER_CAPTURE_EVENT_NAME:u,preProcessDoc:D,postProcessDoc:z,serialize:(e,t)=>function(e,t){const s=e.doctype;let n="";return s&&(n=" "),n+Ge(e.documentElement,t)}(e,t),getShadowRoot:H};k("single-file-user-script-init",(()=>globalThis._singleFile_waitForUserScript=async e=>{const t=new CustomEvent(e+"-request",{cancelable:!0}),s=new Promise((t=>k(e+"-response",t)));(e=>{globalThis.dispatchEvent(e)})(t),t.defaultPrevented&&await s})),e.helper=$e,e.processors=Ke,Object.defineProperty(e,"__esModule",{value:!0})}));