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