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