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