!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",g="_singleFile_fontFaces",p=(e,t,s)=>globalThis.addEventListener(e,t,s),h=e=>{try{globalThis.dispatchEvent(e)}catch(e){}},f=globalThis.CustomEvent,T=globalThis.document,E=globalThis.Document,b=globalThis.JSON;let y;y=window[g]?window[g]:window[g]=new Map,T instanceof E&&(p("single-file-new-font-face",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,y.set(b.stringify(s),t)})),p("single-file-delete-font",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,y.delete(b.stringify(s))})),p("single-file-clear-fonts",(()=>y=new Map)));const I="[\\x20\\t\\r\\n\\f]",w=new RegExp("\\\\([\\da-f]{1,6}"+I+"?|("+I+")|.)","ig");const A="single-file-",S="_singleFile_waitForUserScript",v="__frameTree__::",R=A+"on-before-capture",N=A+"on-after-capture",P=A+"request-get-adopted-stylesheets",_=A+"response-get-adopted-stylesheets",C=A+"unregister-request-get-adopted-stylesheets",M=A+"user-script-init",O="data-"+A+"removed-content",L="data-"+A+"hidden-content",D="data-"+A+"kept-content",x="data-"+A+"hidden-frame",F="data-"+A+"preserved-space-element",U="data-"+A+"shadow-root-element",q="data-"+A+"win-id",k="data-"+A+"image",H="data-"+A+"poster",V="data-"+A+"video",B="data-"+A+"canvas",W="data-"+A+"movable-style",z="data-"+A+"input-value",Y="data-"+A+"lazy-loaded-src",j="data-"+A+"stylesheet",G="data-"+A+"disabled-noscript",K="data-"+A+"invalid-element",X="data-"+A+"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"],$=["SCRIPT","NOSCRIPT","META","LINK","TEMPLATE"],Q=/^'(.*?)'$/,ee=/^"(.*?)"$/,te={regular:"400",normal:"400",bold:"700",bolder:"700",lighter:"100"},se="single-file-ui-element",oe="single-file-infobar",ne="data:,",ae=(e,t,s)=>globalThis.addEventListener(e,t,s),ie=globalThis.JSON,re=globalThis.CustomEvent;function le(e,t,s){e.querySelectorAll("noscript:not(["+G+"])").forEach((e=>{e.setAttribute(G,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(K,""),s.content.appendChild(t.cloneNode(!0)),o.set(t,s),t.replaceWith(s)})),n=de(t,e,e.documentElement,s),s.moveStylesInHead&&e.querySelectorAll("body style, body ~ style").forEach((e=>{const s=Ee(t,e);s&&pe(e,s)&&(e.setAttribute(W,""),n.markedElements.push(e))}))):n={canvases:[],images:[],posters:[],videos:[],usedFonts:[],shadowRoots:[],markedElements:[]},{canvases:n.canvases,fonts:Array.from(y.values()),stylesheets:fe(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:ce(e.adoptedStyleSheets)}}function de(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=Ee(e,s),(s instanceof e.HTMLElement||s instanceof globalThis.HTMLElement)&&o.removeHiddenElements&&(r=(a||s.closest("html > head"))&&J.includes(s.tagName.toUpperCase())||s.closest("details"),r||(i=a||pe(s,l),i&&!$.includes(s.tagName.toUpperCase())&&(s.setAttribute(L,""),n.markedElements.push(s)))),!i)){if(o.compressHTML&&l){const e=l.getPropertyValue("white-space");e&&e.startsWith("pre")&&(s.setAttribute(F,""),n.markedElements.push(s))}o.removeUnusedFonts&&(me(l,o,n.usedFonts),me(Ee(e,s,":first-letter"),o,n.usedFonts),me(Ee(e,s,":before"),o,n.usedFonts),me(Ee(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(B,n.canvases.length-1),n.markedElements.push(s)}catch(e){}if("IMG"==r){const t={currentSrc:a?ne:o.loadDeferredImages&&s.getAttribute(Y)||s.currentSrc};if(n.images.push(t),s.setAttribute(k,n.images.length-1),n.markedElements.push(s),s.removeAttribute(Y),i=i||Ee(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||Ee(e,t)){let e,i,r,l,d,c,m,u,g=!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"),g=t.clientWidth!=o,e?t.style.setProperty("box-sizing",e,s):t.style.removeProperty("box-sizing")}e=Te("padding-left",s),i=Te("padding-right",s),r=Te("padding-top",s),l=Te("padding-bottom",s),g?(d=Te("border-left-width",s),c=Te("border-right-width",s),m=Te("border-top-width",s),u=Te("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=Ee(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(V,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(H,n.posters.length-1),n.markedElements.push(s)}catch(e){}}}"IFRAME"==r&&a&&o.removeHiddenElements&&(s.setAttribute(x,""),n.markedElements.push(s));"INPUT"==r&&("password"!=s.type&&(s.setAttribute(z,s.value),n.markedElements.push(s)),"radio"!=s.type&&"checkbox"!=s.type||(s.setAttribute(z,s.checked),n.markedElements.push(s)));"TEXTAREA"==r&&(s.setAttribute(z,s.value),n.markedElements.push(s));"SELECT"==r&&s.querySelectorAll("option").forEach((e=>{e.selected&&(e.setAttribute(z,""),n.markedElements.push(e))}));"SCRIPT"==r&&(s.async&&""!=s.getAttribute("async")&&"async"!=s.getAttribute("async")&&(s.setAttribute(X,""),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)&&ue(s);if(d&&!s.classList.contains(se)&&s.tagName.toLowerCase()!=oe){const a={};s.setAttribute(U,n.shadowRoots.length),n.markedElements.push(s),n.shadowRoots.push(a);try{if(d.adoptedStyleSheets)if(d.adoptedStyleSheets.length)a.adoptedStyleSheets=ce(d.adoptedStyleSheets);else if(void 0===d.adoptedStyleSheets.length){const e=e=>a.adoptedStyleSheets=e.detail.adoptedStyleSheets;d.addEventListener(_,e),d.dispatchEvent(new re(P,{bubbles:!0})),a.adoptedStyleSheets||s.dispatchEvent(new re(P,{bubbles:!0})),d.removeEventListener(_,e)}}catch(e){}de(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 re(C,{bubbles:!0}))}catch(e){}}de(e,t,s,o,n,i),!o.autoSaveExternalSave&&o.removeHiddenElements&&a&&(r||""==s.getAttribute(D)?s.parentElement&&(s.parentElement.setAttribute(D,""),n.markedElements.push(s.parentElement)):i&&(s.setAttribute(O,""),n.markedElements.push(s)))}))}return n}function ce(e){return e?Array.from(e).map((e=>Array.from(e.cssRules).map((e=>e.cssText)).join("\n"))):[]}function me(e,t,s){if(e){const o=e.getPropertyValue("font-style")||"normal";e.getPropertyValue("font-family").split(",").forEach((n=>{if(n=ge(n),!t.loadedFonts||t.loadedFonts.find((e=>ge(e.family)==n&&e.style==o))){const t=(a=e.getPropertyValue("font-weight"),te[a.toLowerCase().trim()]||a),i=e.getPropertyValue("font-variant")||"normal",r=[n,t,o,i];s.set(ie.stringify(r),[n,t,o,i])}var a}))}}function ue(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 ge(e=""){return function(e){e=e.match(Q)?e.replace(Q,"$1"):e.replace(ee,"$1");return e.trim()}((t=e.trim(),t.replace(w,((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 pe(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 he(e,t,s){if(e.querySelectorAll("["+G+"]").forEach((e=>{e.textContent=e.getAttribute(G),e.removeAttribute(G)})),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=[O,x,L,F,k,H,V,B,z,U,j,X];t=e.querySelectorAll(s.map((e=>"["+e+"]")).join(","))}t.forEach((e=>{e.removeAttribute(O),e.removeAttribute(L),e.removeAttribute(D),e.removeAttribute(x),e.removeAttribute(F),e.removeAttribute(k),e.removeAttribute(H),e.removeAttribute(V),e.removeAttribute(B),e.removeAttribute(z),e.removeAttribute(U),e.removeAttribute(j),e.removeAttribute(X),e.removeAttribute(W)})),s&&s.forEach(((e,t)=>e.replaceWith(t)))}function fe(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(j,o),t[o]=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n"))}}catch(e){}})),t}}function Te(e,t){if(t.getPropertyValue(e).endsWith("px"))return parseFloat(t.getPropertyValue(e))}function Ee(e,t,s){try{return e.getComputedStyle(t,s)}catch(e){}}const be={LAZY_SRC_ATTRIBUTE_NAME:Y,SINGLE_FILE_UI_ELEMENT_CLASS:se},ye=10,Ie="attributes",we=globalThis.browser,Ae=globalThis.document,Se=globalThis.MutationObserver,ve=(e,t,s)=>globalThis.addEventListener(e,t,s),Re=(e,t,s)=>globalThis.removeEventListener(e,t,s),Ne=new Map;let Pe;async function _e(e){if(Ae.documentElement){Ne.clear();const s=Ae.body?Math.max(Ae.body.scrollHeight,Ae.documentElement.scrollHeight):Ae.documentElement.scrollHeight,n=Ae.body?Math.max(Ae.body.scrollWidth,Ae.documentElement.scrollWidth):Ae.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 Se((async t=>{if((t=t.filter((e=>e.type==Ie))).length){t.filter((e=>{if("src"==e.attributeName&&(e.target.setAttribute(be.LAZY_SRC_ATTRIBUTE_NAME,e.target.src),e.target.addEventListener("load",g)),"src"==e.attributeName||"srcset"==e.attributeName||e.target.tagName&&"SOURCE"==e.target.tagName.toUpperCase())return!e.target.classList||!e.target.classList.contains(be.SINGLE_FILE_UI_ELEMENT_CLASS)})).length&&(n=!0,await Me(l,e,E),i.size||await Ce(l,e,E))}}));async function c(t){await Le("idleTimeout",(async()=>{n?PeOe(e,t,s)),t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function Me(e,t,s){await Le("maxTimeout",(async()=>{await xe("loadTimeout"),await Oe(e,t,s)}),10*t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function Oe(e,t,o){await xe("idleTimeout"),function(e){e.loadDeferredImagesBlockCookies&&h(new f(i)),e.loadDeferredImagesBlockStorage&&h(new f(c)),e.loadDeferredImagesDispatchScrollEvent&&h(new f(l)),e.loadDeferredImagesKeepZoomLevel?h(new f(n)):h(new f(s))}(t),await Le("endTimeout",(async()=>{await xe("maxTimeout"),o()}),t.loadDeferredImagesMaxIdleTime/2,t.loadDeferredImagesNativeTimeout),e.disconnect()}async function Le(e,t,s,o){if(we&&we.runtime&&we.runtime.sendMessage&&!o){if(!Ne.get(e)||!Ne.get(e).pending){const o={callback:t,pending:!0};Ne.set(e,o);try{await we.runtime.sendMessage({method:"singlefile.lazyTimeout.setTimeout",type:e,delay:s})}catch(o){De(e,t,s)}o.pending=!1}}else De(e,t,s)}function De(e,t,s){const o=Ne.get(e);o&&globalThis.clearTimeout(o),Ne.set(e,t),globalThis.setTimeout(t,s)}async function xe(e){if(we&&we.runtime&&we.runtime.sendMessage)try{await we.runtime.sendMessage({method:"singlefile.lazyTimeout.clearTimeout",type:e})}catch(t){Fe(e)}else Fe(e)}function Fe(e){const t=Ne.get(e);Ne.delete(e),t&&globalThis.clearTimeout(t)}we&&we.runtime&&we.runtime.onMessage&&we.runtime.onMessage.addListener&&we.runtime.onMessage.addListener((e=>{if("singlefile.lazyTimeout.onTimeout"==e.method){const t=Ne.get(e.type);if(t){Ne.delete(e.type);try{t.callback()}catch(t){Fe(e.type)}}}}));const Ue={ON_BEFORE_CAPTURE_EVENT_NAME:R,ON_AFTER_CAPTURE_EVENT_NAME:N,WIN_ID_ATTRIBUTE_NAME:q,WAIT_FOR_USERSCRIPT_PROPERTY_NAME:S,preProcessDoc:le,serialize:function(e){const t=e.doctype;let s="";return t&&(s=" "),s+e.documentElement.outerHTML},postProcessDoc:he,getShadowRoot:ue},qe='iframe, frame, object[type="text/html"][data]',ke="*",He="singlefile.frameTree.initRequest",Ve="singlefile.frameTree.ackInitRequest",Be="singlefile.frameTree.cleanupRequest",We="singlefile.frameTree.initResponse",ze="*",Ye=5e3,je=".",Ge=globalThis.window==globalThis.top,Ke=globalThis.browser,Xe=globalThis.top,Ze=globalThis.MessageChannel,Je=globalThis.document,$e=globalThis.JSON;let Qe,et=globalThis.sessions;var tt,st,ot;function nt(){return globalThis.crypto.getRandomValues(new Uint32Array(32)).join("")}async function at(e){const t=e.sessionId,s=globalThis[Ue.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,Ge||(Qe=globalThis.frameId=e.windowId),lt(Je,e.options,Qe,t),Ge||(e.options.userScriptEnabled&&s&&await s(Ue.ON_BEFORE_CAPTURE_EVENT_NAME),ut({frames:[pt(Je,globalThis,Qe,e.options,e.scrolling)],sessionId:t,requestedFrameId:Je.documentElement.dataset.requestedFrameId&&Qe}),e.options.userScriptEnabled&&s&&await s(Ue.ON_AFTER_CAPTURE_EVENT_NAME),delete Je.documentElement.dataset.requestedFrameId)}function it(e){if(!globalThis._singleFile_cleaningUp){globalThis._singleFile_cleaningUp=!0;const t=e.sessionId;mt(ht(Je),e.windowId,t)}}function rt(e){e.frames.forEach((t=>dt("responseTimeouts",e.sessionId,t.windowId)));const t=et.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(je).length-e.windowId.split(je).length)),t.resolve&&(t.requestedFrameId&&t.frames.forEach((e=>{e.windowId==t.requestedFrameId&&(e.requestedFrame=!0)})),t.resolve(t.frames)))}}function lt(e,t,s,o){const n=ht(e);!function(e,t,s,o,n){const a=[];let i;et.get(n)?i=et.get(n).requestTimeouts:(i={},et.set(n,{requestTimeouts:i}));t.forEach(((e,t)=>{const s=o+je+t;e.setAttribute(Ue.WIN_ID_ATTRIBUTE_NAME,s),a.push({windowId:s})})),ut({frames:a,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),t.forEach(((e,t)=>{const a=o+je+t;try{gt(e.contentWindow,{method:He,windowId:a,sessionId:n,options:s,scrolling:e.scrolling})}catch(e){}i[a]=globalThis.setTimeout((()=>ut({frames:[{windowId:a,processed:!0}],sessionId:n})),Ye)})),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+je+t;let r;try{r=e.contentDocument}catch(e){}if(r)try{const t=e.contentWindow;t.stop(),dt("requestTimeouts",n,i),lt(r,s,i,n),a.push(pt(r,t,i,s,e.scrolling))}catch(e){a.push({windowId:i,processed:!0})}})),ut({frames:a,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o)}function dt(e,t,s){const o=et.get(t);if(o&&o[e]){const t=o[e][s];t&&(globalThis.clearTimeout(t),delete o[e][s])}}function ct(e,t){const s=et.get(e);s&&s.responseTimeouts&&(s.responseTimeouts[t]=globalThis.setTimeout((()=>ut({frames:[{windowId:t,processed:!0}],sessionId:e})),1e4))}function mt(e,t,s){e.forEach(((e,o)=>{const n=t+je+o;e.removeAttribute(Ue.WIN_ID_ATTRIBUTE_NAME);try{gt(e.contentWindow,{method:Be,windowId:n,sessionId:s})}catch(e){}})),e.forEach(((e,o)=>{const n=t+je+o;let a;try{a=e.contentDocument}catch(e){}if(a)try{mt(ht(a),n,s)}catch(e){}}))}function ut(e){e.method=We;try{Xe.singlefile.processors.frameTree.initResponse(e)}catch(t){gt(Xe,e,!0)}}function gt(e,t,s){if(e==Xe&&Ke&&Ke.runtime&&Ke.runtime.sendMessage)Ke.runtime.sendMessage(t);else if(s){const s=new Ze;e.postMessage(v+$e.stringify({method:t.method,sessionId:t.sessionId}),ze,[s.port2]),s.port1.postMessage(t)}else e.postMessage(v+$e.stringify(t),ze)}function pt(e,t,s,o,n){const a=Ue.preProcessDoc(e,t,o),i=Ue.serialize(e);Ue.postProcessDoc(e,a.markedElements,a.invalidElements);return{windowId:s,content:i,baseURI:e.baseURI.split("#")[0],url:e.location.href,title:e.title,canvases:a.canvases,fonts:a.fonts,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 ht(e){let t=Array.from(e.querySelectorAll(qe));return e.querySelectorAll(ke).forEach((e=>{const s=Ue.getShadowRoot(e);s&&(t=t.concat(...s.querySelectorAll(qe)))})),t}et||(et=globalThis.sessions=new Map),Ge&&(Qe="0",Ke&&Ke.runtime&&Ke.runtime.onMessage&&Ke.runtime.onMessage.addListener&&Ke.runtime.onMessage.addListener((e=>e.method==We?(rt(e),Promise.resolve({})):e.method==Ve?(dt("requestTimeouts",e.sessionId,e.windowId),ct(e.sessionId,e.windowId),Promise.resolve({})):void 0))),tt="message",st=async e=>{if("string"==typeof e.data&&e.data.startsWith(v)){e.preventDefault(),e.stopPropagation();const t=$e.parse(e.data.substring(v.length));t.method==He?(e.source&>(e.source,{method:Ve,windowId:t.windowId,sessionId:t.sessionId}),Ge||(globalThis.stop(),t.options.loadDeferredImages&&_e(t.options),await at(t))):t.method==Ve?(dt("requestTimeouts",t.sessionId,t.windowId),ct(t.sessionId,t.windowId)):t.method==Be?it(t):t.method==We&&et.get(t.sessionId)&&(e.ports[0].onmessage=e=>rt(e.data))}},ot=!0,globalThis.addEventListener(tt,st,ot);var ft=Object.freeze({__proto__:null,getAsync:function(e){const t=nt();return e=$e.parse($e.stringify(e)),new Promise((s=>{et.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{},resolve:e=>{e.sessionId=t,s(e)}}),at({windowId:Qe,sessionId:t,options:e})}))},getSync:function(e){const t=nt();e=$e.parse($e.stringify(e)),et.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{}}),function(e){const t=e.sessionId,s=globalThis[Ue.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,Ge||(Qe=globalThis.frameId=e.windowId);lt(Je,e.options,Qe,t),Ge||(e.options.userScriptEnabled&&s&&s(Ue.ON_BEFORE_CAPTURE_EVENT_NAME),ut({frames:[pt(Je,globalThis,Qe,e.options,e.scrolling)],sessionId:t,requestedFrameId:Je.documentElement.dataset.requestedFrameId&&Qe}),e.options.userScriptEnabled&&s&&s(Ue.ON_AFTER_CAPTURE_EVENT_NAME),delete Je.documentElement.dataset.requestedFrameId)}({windowId:Qe,sessionId:t,options:e});const s=et.get(t).frames;return s.sessionId=t,s},cleanup:function(e){et.delete(e),it({windowId:Qe,sessionId:e,options:{sessionId:e}})},initResponse:rt,TIMEOUT_INIT_REQUEST_MESSAGE:Ye});const Tt=["AREA","BASE","BR","COL","COMMAND","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"],Et=1,bt=3,yt=8,It=[{tagName:"HEAD",accept:e=>!e.childNodes.length||e.childNodes[0].nodeType==Et},{tagName:"BODY",accept:e=>!e.childNodes.length}],wt=[{tagName:"HTML",accept:e=>!e||e.nodeType!=yt},{tagName:"HEAD",accept:e=>!e||e.nodeType!=yt&&(e.nodeType!=bt||!vt(e.textContent))},{tagName:"BODY",accept:e=>!e||e.nodeType!=yt},{tagName:"LI",accept:(e,t)=>!e&&t.parentElement&&("UL"==Rt(t.parentElement)||"OL"==Rt(t.parentElement))||e&&["LI"].includes(Rt(e))},{tagName:"DT",accept:e=>!e||["DT","DD"].includes(Rt(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(Rt(e))},{tagName:"DD",accept:e=>!e||["DT","DD"].includes(Rt(e))},{tagName:"RT",accept:e=>!e||["RT","RP"].includes(Rt(e))},{tagName:"RP",accept:e=>!e||["RT","RP"].includes(Rt(e))},{tagName:"OPTGROUP",accept:e=>!e||["OPTGROUP"].includes(Rt(e))},{tagName:"OPTION",accept:e=>!e||["OPTION","OPTGROUP"].includes(Rt(e))},{tagName:"COLGROUP",accept:e=>!e||e.nodeType!=yt&&(e.nodeType!=bt||!vt(e.textContent))},{tagName:"CAPTION",accept:e=>!e||e.nodeType!=yt&&(e.nodeType!=bt||!vt(e.textContent))},{tagName:"THEAD",accept:e=>!e||["TBODY","TFOOT"].includes(Rt(e))},{tagName:"TBODY",accept:e=>!e||["TBODY","TFOOT"].includes(Rt(e))},{tagName:"TFOOT",accept:e=>!e},{tagName:"TR",accept:e=>!e||["TR"].includes(Rt(e))},{tagName:"TD",accept:e=>!e||["TD","TH"].includes(Rt(e))},{tagName:"TH",accept:e=>!e||["TD","TH"].includes(Rt(e))}],At=["STYLE","SCRIPT","XMP","IFRAME","NOEMBED","NOFRAMES","PLAINTEXT","NOSCRIPT"];function St(e,t,s){return e.nodeType==bt?function(e){const t=e.parentNode;let s;t&&t.nodeType==Et&&(s=Rt(t));return!s||At.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==yt?"\x3c!--"+e.textContent+"--\x3e":e.nodeType==Et?function(e,t,s){const o=Rt(e),n=t&&It.find((t=>o==Rt(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&&wt.find((t=>o==Rt(t)&&t.accept(e.nextSibling,e)));(s||!i&&!Tt.includes(o))&&(a+="");return a}(e,t,s):void 0}function vt(e){return Boolean(e.match(/^[ \t\n\f\r]/))}function Rt(e){return e.tagName&&e.tagName.toUpperCase()}const Nt={frameTree:ft},Pt={COMMENT_HEADER:"Page saved with SingleFile",COMMENT_HEADER_LEGACY:"Archive processed by SingleFile",ON_BEFORE_CAPTURE_EVENT_NAME:R,ON_AFTER_CAPTURE_EVENT_NAME:N,WAIT_FOR_USERSCRIPT_PROPERTY_NAME:S,preProcessDoc:le,postProcessDoc:he,serialize:(e,t)=>function(e,t){const s=e.doctype;let o="";return s&&(o=" "),o+St(e.documentElement,t)}(e,t),getShadowRoot:ue};ae(M,(()=>globalThis[S]=async e=>{const t=new re(e+"-request",{cancelable:!0}),s=new Promise((t=>ae(e+"-response",t)));(e=>{try{globalThis.dispatchEvent(e)}catch(e){}})(t),t.defaultPrevented&&await s})),e.helper=Pt,e.processors=Nt,Object.defineProperty(e,"__esModule",{value:!0})}));