| 1 |
- !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-image",s="single-file-image-loaded",o=globalThis.browser,n=(e,t,s)=>globalThis.addEventListener(e,t,s),i=e=>{try{globalThis.dispatchEvent(e)}catch(e){}},a=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("single-file-new-font-face",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,d.set(JSON.stringify(s),t)})),n("single-file-delete-font",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,d.delete(JSON.stringify(s))})),n("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),o=globalThis.CustomEvent,n=globalThis.FileReader,i=globalThis.Blob,a=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 n;globalThis.FontFace=function(){return n||(a("SingleFile is hooking the FontFace constructor, document.fonts.delete and document.fonts.clear to handle dynamically loaded fonts."),n=!0),m(...arguments).then((e=>s(new o(r,{detail:e})))),new t(...arguments)},globalThis.FontFace.toString=function(){return"function FontFace() { [native code] }"};const i=e.fonts.delete;e.fonts.delete=function(t){return m(t.family).then((e=>s(new o(l,{detail:e})))),i.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 o(d)),c.call(e.fonts)},e.fonts.clear.toString=function(){return"function clear() { [native code] }"}}async function m(e,t,s){const o={};return o["font-family"]=e,o.src=t,s&&Object.keys(s).forEach((e=>{c[e]&&(o[c[e]]=s[e])})),new Promise((e=>{if(o.src instanceof ArrayBuffer){const t=new n;t.readAsDataURL(new i([o.src])),t.addEventListener("load",(()=>{o.src="url("+t.result+")",e(o)}))}else e(o)}))}}.toString()+")()",(r.documentElement||r).appendChild(e),e.remove(),o&&o.runtime&&o.runtime.getURL&&(e=r.createElement("script"),e.src=o.runtime.getURL("/lib/single-file-hooks-frames.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="data-single-file-removed-content",u="data-single-file-hidden-content",g="data-single-file-kept-content",f="data-single-file-hidden-frame",h="data-single-file-preserved-space-element",p="data-single-file-shadow-root-element",b="data-single-file-image",y="data-single-file-poster",w="data-single-file-video",E="data-single-file-canvas",T="data-single-file-import",I="data-single-file-movable-style",v="data-single-file-input-value",A="data-single-file-lazy-loaded-src",S="data-single-file-stylesheet",F="data-single-file-disabled-noscript",R="data-single-file-async-script",N="*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)",_=["NOSCRIPT","DISABLED-NOSCRIPT","META","LINK","STYLE","TITLE","TEMPLATE","SOURCE","OBJECT","SCRIPT","HEAD"],C=/^'(.*?)'$/,M=/^"(.*?)"$/,q={regular:"400",normal:"400",bold:"700",bolder:"700",lighter:"100"},x="single-file-ui-element",P="data:,";function k(e,t,s,o,n={usedFonts:new Map,canvases:[],images:[],posters:[],videos:[],shadowRoots:[],imports:[],markedElements:[]},i){return Array.from(s.childNodes).filter((t=>t instanceof e.HTMLElement||t instanceof e.SVGElement)).forEach((s=>{let a,r,l;if(!o.autoSaveExternalSave&&(o.removeHiddenElements||o.removeUnusedFonts||o.compressHTML)&&(l=e.getComputedStyle(s),s instanceof e.HTMLElement&&o.removeHiddenElements&&(r=(i||s.closest("html > head"))&&_.includes(s.tagName)||s.closest("details"),r||(a=i||U(s,l),a&&(s.setAttribute(u,""),n.markedElements.push(s)))),!a)){if(o.compressHTML&&l){const e=l.getPropertyValue("white-space");e&&e.startsWith("pre")&&(s.setAttribute(h,""),n.markedElements.push(s))}o.removeUnusedFonts&&(L(l,o,n.usedFonts),L(e.getComputedStyle(s,":first-letter"),o,n.usedFonts),L(e.getComputedStyle(s,":before"),o,n.usedFonts),L(e.getComputedStyle(s,":after"),o,n.usedFonts))}!function(e,t,s,o,n,i,a){if("CANVAS"==s.tagName)try{n.canvases.push({dataURI:s.toDataURL("image/png","")}),s.setAttribute(E,n.canvases.length-1),n.markedElements.push(s)}catch(e){}if("IMG"==s.tagName){const t={currentSrc:i?P:o.loadDeferredImages&&s.getAttribute(A)||s.currentSrc};n.images.push(t),s.setAttribute(b,n.images.length-1),n.markedElements.push(s),s.removeAttribute(A);try{a=a||e.getComputedStyle(s)}catch(e){}if(a){t.size=function(e,t,s){let o=t.naturalWidth,n=t.naturalHeight;if(!o&&!n){const i=null==t.getAttribute("style");let a,r,l,d,c,m,u,g,f=!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"),o=t.clientWidth;t.style.setProperty("box-sizing","border-box","important"),f=t.clientWidth!=o,e?t.style.setProperty("box-sizing",e,s):t.style.removeProperty("box-sizing")}a=W("padding-left",s),r=W("padding-right",s),l=W("padding-top",s),d=W("padding-bottom",s),f?(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,o=Math.max(0,t.clientWidth-a-r-c-m),n=Math.max(0,t.clientHeight-l-d-u-g),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"==s.tagName){const o=s.currentSrc;if(o&&!o.startsWith("blob:")&&!o.startsWith("data:")){const t=e.getComputedStyle(s.parentNode).getPropertyValue("position");n.videos.push({positionParent:t,src:o,size:{pxWidth:s.clientWidth,pxHeight:s.clientHeight},currentTime:s.currentTime}),s.setAttribute(w,n.videos.length-1)}if(!s.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(y,n.posters.length-1),n.markedElements.push(s)}catch(e){}}}"IFRAME"==s.tagName&&i&&o.removeHiddenElements&&(s.setAttribute(f,""),n.markedElements.push(s));"LINK"==s.tagName&&s.import&&s.import.documentElement&&(n.imports.push({content:z(s.import)}),s.setAttribute(T,n.imports.length-1),n.markedElements.push(s));"INPUT"==s.tagName&&("password"!=s.type&&(s.setAttribute(v,s.value),n.markedElements.push(s)),"radio"!=s.type&&"checkbox"!=s.type||(s.setAttribute(v,s.checked),n.markedElements.push(s)));"TEXTAREA"==s.tagName&&(s.setAttribute(v,s.value),n.markedElements.push(s));"SELECT"==s.tagName&&s.querySelectorAll("option").forEach((e=>{e.selected&&(e.setAttribute(v,""),n.markedElements.push(e))}));"SCRIPT"==s.tagName&&(s.async&&""!=s.getAttribute("async")&&"async"!=s.getAttribute("async")&&(s.setAttribute(R,""),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)&&O(s);if(d&&!s.classList.contains(x)){const i={};s.setAttribute(p,n.shadowRoots.length),n.markedElements.push(s),n.shadowRoots.push(i),k(e,t,d,o,n,a),i.content=d.innerHTML,i.mode=d.mode;try{d.adoptedStyleSheets&&d.adoptedStyleSheets.length&&(i.adoptedStyleSheets=Array.from(d.adoptedStyleSheets).map((e=>Array.from(e.cssRules).map((e=>e.cssText)).join("\n"))))}catch(e){}}k(e,t,s,o,n,a),!o.autoSaveExternalSave&&o.removeHiddenElements&&i&&(r||""==s.getAttribute(g)?s.parentElement&&(s.parentElement.setAttribute(g,""),n.markedElements.push(s.parentElement)):a&&(s.setAttribute(m,""),n.markedElements.push(s)))})),n}function L(e,t,s){if(e){const o=e.getPropertyValue("font-style")||"normal";e.getPropertyValue("font-family").split(",").forEach((n=>{if(n=D(n),!t.loadedFonts||t.loadedFonts.find((e=>D(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(JSON.stringify(r),[n,t,o,a])}var i}))}}function O(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 D(e=""){return function(e){e=e.match(C)?e.replace(C,"$1"):e.replace(M,"$1");return e.trim()}((t=e.trim(),t.replace(c,((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 U(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 V(e){if(e){const t=[];return e.querySelectorAll("style").forEach(((s,o)=>{try{const n=e.createElement("style");n.textContent=s.textContent,e.body.appendChild(n);const i=n.sheet;n.remove(),i&&i.cssRules.length==s.sheet.cssRules.length||(s.setAttribute(S,o),t[o]=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 z(e){const t=e.doctype;let s="";return t&&(s="<!DOCTYPE "+t.nodeName,t.publicId?(s+=' PUBLIC "'+t.publicId+'"',t.systemId&&(s+=' "'+t.systemId+'"')):t.systemId&&(s+=' SYSTEM "'+t.systemId+'"'),t.internalSubset&&(s+=" ["+t.internalSubset+"]"),s+="> "),s+e.documentElement.outerHTML}const H=A,B=x,j="attributes",J=globalThis.browser,G=globalThis.document,K=globalThis.MutationObserver,Y=(e,t,s)=>globalThis.addEventListener(e,t,s),$=(e,t,s)=>globalThis.removeEventListener(e,t,s),X=new Map;let Z;async function Q(e){if(G.documentElement){X.clear();const o=Math.max(G.documentElement.scrollHeight-1.5*G.documentElement.clientHeight,0),n=Math.max(G.documentElement.scrollWidth-1.5*G.documentElement.clientWidth,0);if(globalThis.scrollY<=o&&globalThis.scrollX<=n)return function(e){return Z=0,new Promise((async o=>{let n;const r=new Set,l=new K((async t=>{if((t=t.filter((e=>e.type==j))).length){t.filter((e=>{if("src"==e.attributeName&&(e.target.setAttribute(H,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(B)})).length&&(n=!0,await te(l,e,g),r.size||await ee(l,e,g))}}));async function d(t){await oe("idleTimeout",(async()=>{n?Z<10&&(Z++,ie("idleTimeout"),await d(Math.max(500,t/2))):(ie("loadTimeout"),ie("maxTimeout"),se(l,e,g))}),t)}function c(e){const t=e.target;t.removeAttribute(H),t.removeEventListener("load",c)}async function m(t){n=!0,await te(l,e,g),await ee(l,e,g),t.detail&&r.add(t.detail)}async function u(t){await te(l,e,g),await ee(l,e,g),r.delete(t.detail),r.size||await ee(l,e,g)}function g(e){l.disconnect(),$(t,m),$(s,u),o(e)}await d(2*e.loadDeferredImagesMaxIdleTime),await te(l,e,g),l.observe(G,{subtree:!0,childList:!0,attributes:!0}),Y(t,m),Y(s,u),function(e){e.loadDeferredImagesBlockCookies&&i(new a("single-file-block-cookies-start")),e.loadDeferredImagesBlockStorage&&i(new a("single-file-block-storage-start")),e.loadDeferredImagesDispatchScrollEvent&&i(new a("single-file-dispatch-scroll-event-start")),e.loadDeferredImagesKeepZoomLevel?i(new a("single-file-load-deferred-images-keep-zoom-level-start")):i(new a("single-file-load-deferred-images-start"))}(e)}))}(e)}}async function ee(e,t,s){await oe("loadTimeout",(()=>se(e,t,s)),t.loadDeferredImagesMaxIdleTime)}async function te(e,t,s){await oe("maxTimeout",(async()=>{await ie("loadTimeout"),await se(e,t,s)}),10*t.loadDeferredImagesMaxIdleTime)}async function se(e,t,s){await ie("idleTimeout"),function(e){e.loadDeferredImagesBlockCookies&&i(new a("single-file-block-cookies-end")),e.loadDeferredImagesBlockStorage&&i(new a("single-file-block-storage-end")),e.loadDeferredImagesDispatchScrollEvent&&i(new a("single-file-dispatch-scroll-event-end")),e.loadDeferredImagesKeepZoomLevel?i(new a("single-file-load-deferred-images-keep-zoom-level-end")):i(new a("single-file-load-deferred-images-end"))}(t),await oe("endTimeout",(async()=>{await ie("maxTimeout"),s()}),t.loadDeferredImagesMaxIdleTime/2),e.disconnect()}async function oe(e,t,s){if(J&&J.runtime&&J.runtime.sendMessage){if(!X.get(e)||!X.get(e).pending){const o={callback:t,pending:!0};X.set(e,o);try{await J.runtime.sendMessage({method:"singlefile.lazyTimeout.setTimeout",type:e,delay:s})}catch(o){ne(e,t,s)}o.pending=!1}}else ne(e,t,s)}function ne(e,t,s){const o=X.get(e);o&&globalThis.clearTimeout(o),X.set(e,t),globalThis.setTimeout(t,s)}async function ie(e){if(J&&J.runtime&&J.runtime.sendMessage)try{await J.runtime.sendMessage({method:"singlefile.lazyTimeout.clearTimeout",type:e})}catch(t){ae(e)}else ae(e)}function ae(e){const t=X.get(e);X.delete(e),t&&globalThis.clearTimeout(t)}J&&J.runtime&&J.runtime.onMessage&&J.runtime.onMessage.addListener&&J.runtime.onMessage.addListener((e=>{if("singlefile.lazyTimeout.onTimeout"==e.method){const t=X.get(e.type);if(t){X.delete(e.type);try{t.callback()}catch(t){ae(e.type)}}}}));const re={ON_BEFORE_CAPTURE_EVENT_NAME:"single-file-on-before-capture",ON_AFTER_CAPTURE_EVENT_NAME:"single-file-on-after-capture",WIN_ID_ATTRIBUTE_NAME:"data-single-file-win-id",preProcessDoc:function(e,t,s){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(N).forEach((e=>e.hidden=!0)),e.querySelectorAll("svg foreignObject").forEach((e=>{const t=e.querySelectorAll("html > head > "+N+", html > body > "+N);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, p div").forEach((t=>{const s=e.createElement("template");s.setAttribute("data-single-file-invalid-element",""),s.content.appendChild(t.cloneNode(!0)),o.set(t,s),t.replaceWith(s)})),n=k(t,e,e.documentElement,s),s.moveStylesInHead&&e.querySelectorAll("body style, body ~ style").forEach((e=>{const s=t.getComputedStyle(e);s&&U(e,s)&&(e.setAttribute(I,""),n.markedElements.push(e))}))):n={canvases:[],images:[],posters:[],videos:[],usedFonts:[],shadowRoots:[],imports:[],markedElements:[]},{canvases:n.canvases,fonts:Array.from(d.values()),stylesheets:V(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,invalidElements:o}},serialize:z,postProcessDoc:function(e,t,s){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=[m,f,u,h,b,y,w,E,v,p,T,S,R];t=e.querySelectorAll(s.map((e=>"["+e+"]")).join(","))}t.forEach((e=>{e.removeAttribute(m),e.removeAttribute(u),e.removeAttribute(g),e.removeAttribute(f),e.removeAttribute(h),e.removeAttribute(b),e.removeAttribute(y),e.removeAttribute(w),e.removeAttribute(E),e.removeAttribute(v),e.removeAttribute(p),e.removeAttribute(T),e.removeAttribute(S),e.removeAttribute(R),e.removeAttribute(I)})),s&&Array.from(s.entries()).forEach((([e,t])=>t.replaceWith(e)))},getShadowRoot:O},le="__frameTree__::",de='iframe, frame, object[type="text/html"][data]',ce="singlefile.frameTree.initRequest",me="singlefile.frameTree.ackInitRequest",ue="singlefile.frameTree.cleanupRequest",ge="singlefile.frameTree.initResponse",fe=5e3,he=".",pe=globalThis.window==globalThis.top,be=globalThis.browser,ye=globalThis.top,we=globalThis.MessageChannel,Ee=globalThis.document;let Te,Ie=globalThis.sessions;var ve,Ae,Se;function Fe(){return globalThis.crypto.getRandomValues(new Uint32Array(32)).join("")}async function Re(e){const t=e.sessionId,s=globalThis._singleFile_waitForUserScript;delete globalThis._singleFile_cleaningUp,pe||(Te=globalThis.frameId=e.windowId),Ce(Ee,e.options,Te,t),pe||(e.options.userScriptEnabled&&s&&await s(re.ON_BEFORE_CAPTURE_EVENT_NAME),Pe({frames:[Le(Ee,globalThis,Te,e.options)],sessionId:t,requestedFrameId:Ee.documentElement.dataset.requestedFrameId&&Te}),e.options.userScriptEnabled&&s&&await s(re.ON_AFTER_CAPTURE_EVENT_NAME),delete Ee.documentElement.dataset.requestedFrameId)}function Ne(e){if(!globalThis._singleFile_cleaningUp){globalThis._singleFile_cleaningUp=!0;const t=e.sessionId;xe(Oe(Ee),e.windowId,t)}}function _e(e){e.frames.forEach((t=>Me("responseTimeouts",e.sessionId,t.windowId)));const t=Ie.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(he).length-e.windowId.split(he).length)),t.resolve&&(t.requestedFrameId&&t.frames.forEach((e=>{e.windowId==t.requestedFrameId&&(e.requestedFrame=!0)})),t.resolve(t.frames)))}}function Ce(e,t,s,o){const n=Oe(e);!function(e,t,s,o,n){const i=[];let a;Ie.get(n)?a=Ie.get(n).requestTimeouts:(a={},Ie.set(n,{requestTimeouts:a}));t.forEach(((e,t)=>{const s=o+he+t;e.setAttribute(re.WIN_ID_ATTRIBUTE_NAME,s),i.push({windowId:s})})),Pe({frames:i,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),t.forEach(((e,t)=>{const i=o+he+t;try{ke(e.contentWindow,{method:ce,windowId:i,sessionId:n,options:s})}catch(e){}a[i]=globalThis.setTimeout((()=>Pe({frames:[{windowId:i,processed:!0}],sessionId:n})),fe)})),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+he+t;let r;try{r=e.contentDocument}catch(e){}if(r)try{const t=e.contentWindow;t.stop(),Me("requestTimeouts",n,a),Ce(r,s,a,n),i.push(Le(r,t,a,s))}catch(e){i.push({windowId:a,processed:!0})}})),Pe({frames:i,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o)}function Me(e,t,s){const o=Ie.get(t);if(o&&o[e]){const t=o[e][s];t&&(globalThis.clearTimeout(t),delete o[e][s])}}function qe(e,t){const s=Ie.get(e);s&&s.responseTimeouts&&(s.responseTimeouts[t]=globalThis.setTimeout((()=>Pe({frames:[{windowId:t,processed:!0}],sessionId:e})),1e4))}function xe(e,t,s){e.forEach(((e,o)=>{const n=t+he+o;e.removeAttribute(re.WIN_ID_ATTRIBUTE_NAME);try{ke(e.contentWindow,{method:ue,windowId:n,sessionId:s})}catch(e){}})),e.forEach(((e,o)=>{const n=t+he+o;let i;try{i=e.contentDocument}catch(e){}if(i)try{xe(Oe(i),n,s)}catch(e){}}))}function Pe(e){e.method=ge;try{ye.singlefile.processors.frameTree.initResponse(e)}catch(t){ke(ye,e,!0)}}function ke(e,t,s){if(e==ye&&be&&be.runtime&&be.runtime.sendMessage)be.runtime.sendMessage(t);else if(s){const s=new we;e.postMessage(le+JSON.stringify({method:t.method,sessionId:t.sessionId}),"*",[s.port2]),s.port1.postMessage(t)}else e.postMessage(le+JSON.stringify(t),"*")}function Le(e,t,s,o){const n=re.preProcessDoc(e,t,o),i=re.serialize(e);re.postProcessDoc(e,n.markedElements,n.invalidElements);return{windowId:s,content:i,baseURI:e.baseURI.split("#")[0],title:e.title,canvases:n.canvases,fonts:n.fonts,stylesheets:n.stylesheets,images:n.images,posters:n.posters,videos:n.videos,usedFonts:n.usedFonts,shadowRoots:n.shadowRoots,imports:n.imports,processed:!0}}function Oe(e){let t=Array.from(e.querySelectorAll(de));return e.querySelectorAll("*").forEach((e=>{const s=re.getShadowRoot(e);s&&(t=t.concat(...s.querySelectorAll(de)))})),t}Ie||(Ie=globalThis.sessions=new Map),pe&&(Te="0",be&&be.runtime&&be.runtime.onMessage&&be.runtime.onMessage.addListener&&be.runtime.onMessage.addListener((e=>e.method==ge?(_e(e),Promise.resolve({})):e.method==me?(Me("requestTimeouts",e.sessionId,e.windowId),qe(e.sessionId,e.windowId),Promise.resolve({})):void 0))),ve="message",Ae=async e=>{if("string"==typeof e.data&&e.data.startsWith(le)){e.preventDefault(),e.stopPropagation();const t=JSON.parse(e.data.substring(le.length));t.method==ce?(e.source&&ke(e.source,{method:me,windowId:t.windowId,sessionId:t.sessionId}),pe||(globalThis.stop(),t.options.loadDeferredImages&&Q(t.options),await Re(t))):t.method==me?(Me("requestTimeouts",t.sessionId,t.windowId),qe(t.sessionId,t.windowId)):t.method==ue?Ne(t):t.method==ge&&Ie.get(t.sessionId)&&(e.ports[0].onmessage=e=>_e(e.data))}},Se=!0,globalThis.addEventListener(ve,Ae,Se),e.TIMEOUT_INIT_REQUEST_MESSAGE=fe,e.cleanup=function(e){Ie.delete(e),Ne({windowId:Te,sessionId:e,options:{sessionId:e}})},e.getAsync=function(e){const t=Fe();return e=JSON.parse(JSON.stringify(e)),new Promise((s=>{Ie.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{},resolve:e=>{e.sessionId=t,s(e)}}),Re({windowId:Te,sessionId:t,options:e})}))},e.getSync=function(e){const t=Fe();e=JSON.parse(JSON.stringify(e)),Ie.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{}}),function(e){const t=e.sessionId,s=globalThis._singleFile_waitForUserScript;delete globalThis._singleFile_cleaningUp,pe||(Te=globalThis.frameId=e.windowId);Ce(Ee,e.options,Te,t),pe||(e.options.userScriptEnabled&&s&&s(re.ON_BEFORE_CAPTURE_EVENT_NAME),Pe({frames:[Le(Ee,globalThis,Te,e.options)],sessionId:t,requestedFrameId:Ee.documentElement.dataset.requestedFrameId&&Te}),e.options.userScriptEnabled&&s&&s(re.ON_AFTER_CAPTURE_EVENT_NAME),delete Ee.documentElement.dataset.requestedFrameId)}({windowId:Te,sessionId:t,options:e});const s=Ie.get(t).frames;return s.sessionId=t,s},e.initResponse=_e,Object.defineProperty(e,"__esModule",{value:!0})}));
|