single-file-cli 1.0.8 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/args.js CHANGED
@@ -81,7 +81,6 @@ const args = require("yargs")
81
81
  "remove-unused-styles": true,
82
82
  "remove-unused-fonts": true,
83
83
  "remove-frames": false,
84
- "remove-imports": true,
85
84
  "block-scripts": true,
86
85
  "block-audios": true,
87
86
  "block-videos": true,
@@ -213,8 +212,6 @@ const args = require("yargs")
213
212
  .boolean("remove-unused-styles")
214
213
  .options("remove-unused-fonts", { description: "Remove unused CSS font rules" })
215
214
  .boolean("remove-unused-fonts")
216
- .options("remove-imports", { description: "Remove HTML imports" })
217
- .boolean("remove-imports")
218
215
  .options("block-scripts", { description: "Block scripts" })
219
216
  .boolean("block-scripts")
220
217
  .options("block-audios", { description: "Block audio elements" })
@@ -1 +1 @@
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};if(o.images.push(t),s.setAttribute(y,o.images.length-1),o.markedElements.push(s),s.removeAttribute(S),i=i||e.getComputedStyle(s)){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,"&amp;").replace(/\u00a0/g,"&nbsp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}(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,"&amp;").replace(/\u00a0/g,"&nbsp;"),i.includes('"')&&(i.includes("'")||!s?i=i.replace(/"/g,"&quot;"):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})}));
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",f="data-single-file-hidden-content",p="data-single-file-kept-content",h="data-single-file-hidden-frame",b="data-single-file-preserved-space-element",y="data-single-file-shadow-root-element",E="data-single-file-image",T="data-single-file-poster",w="data-single-file-video",I="data-single-file-canvas",A="data-single-file-movable-style",v="data-single-file-input-value",N="data-single-file-lazy-loaded-src",S="data-single-file-stylesheet",R="data-single-file-disabled-noscript",F="data-single-file-async-script",C="*: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"],P=/^'(.*?)'$/,x=/^"(.*?)"$/,M={regular:"400",normal:"400",bold:"700",bolder:"700",lighter:"100"},O="single-file-ui-element",D="data:,",L=(e,t,s)=>globalThis.addEventListener(e,t,s);function k(e,t,s){e.querySelectorAll("noscript:not([data-single-file-disabled-noscript])").forEach((e=>{e.setAttribute(R,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(C).forEach((e=>e.hidden=!0)),e.querySelectorAll("svg foreignObject").forEach((e=>{const t=e.querySelectorAll("html > head > "+C+", html > body > "+C);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=q(t,e,e.documentElement,s),s.moveStylesInHead&&e.querySelectorAll("body style, body ~ style").forEach((e=>{const s=t.getComputedStyle(e);s&&B(e,s)&&(e.setAttribute(A,""),o.markedElements.push(e))}))):o={canvases:[],images:[],posters:[],videos:[],usedFonts:[],shadowRoots:[],markedElements:[]},{canvases:o.canvases,fonts:Array.from(d.values()),stylesheets:W(e),images:o.images,posters:o.posters,videos:o.videos,usedFonts:Array.from(o.usedFonts.values()),shadowRoots:o.shadowRoots,referrer:e.referrer,markedElements:o.markedElements,invalidElements:n}}function q(e,t,s,n,o={usedFonts:new Map,canvases:[],images:[],posters:[],videos:[],shadowRoots:[],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"))&&_.includes(s.tagName)||s.closest("details"),r||(i=a||B(s,l),i&&(s.setAttribute(f,""),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&&(U(l,n,o.usedFonts),U(e.getComputedStyle(s,":first-letter"),n,o.usedFonts),U(e.getComputedStyle(s,":before"),n,o.usedFonts),U(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?D:n.loadDeferredImages&&s.getAttribute(N)||s.currentSrc};o.images.push(t),s.setAttribute(E,o.images.length-1),o.markedElements.push(s),s.removeAttribute(N);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,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"),n=t.clientWidth;t.style.setProperty("box-sizing","border-box","important"),f=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),f?(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));"INPUT"==s.tagName&&("password"!=s.type&&(s.setAttribute(v,s.value),o.markedElements.push(s)),"radio"!=s.type&&"checkbox"!=s.type||(s.setAttribute(v,s.checked),o.markedElements.push(s)));"TEXTAREA"==s.tagName&&(s.setAttribute(v,s.value),o.markedElements.push(s));"SELECT"==s.tagName&&s.querySelectorAll("option").forEach((e=>{e.selected&&(e.setAttribute(v,""),o.markedElements.push(e))}));"SCRIPT"==s.tagName&&(s.async&&""!=s.getAttribute("async")&&"async"!=s.getAttribute("async")&&(s.setAttribute(F,""),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)&&H(s);if(d&&!s.classList.contains(O)){const a={};s.setAttribute(y,o.shadowRoots.length),o.markedElements.push(s),o.shadowRoots.push(a),q(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){}}q(e,t,s,n,o,i),!n.autoSaveExternalSave&&n.removeHiddenElements&&a&&(r||""==s.getAttribute(p)?s.parentElement&&(s.parentElement.setAttribute(p,""),o.markedElements.push(s.parentElement)):i&&(s.setAttribute(g,""),o.markedElements.push(s)))})),o}function U(e,t,s){if(e){const n=e.getPropertyValue("font-style")||"normal";e.getPropertyValue("font-family").split(",").forEach((o=>{if(o=V(o),!t.loadedFonts||t.loadedFonts.find((e=>V(e.family)==o&&e.style==n))){const t=(a=e.getPropertyValue("font-weight"),M[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 H(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 V(e=""){return function(e){e=e.match(P)?e.replace(P,"$1"):e.replace(x,"$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 B(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 z(e,t,s){if(e.querySelectorAll("[data-single-file-disabled-noscript]").forEach((e=>{e.textContent=e.getAttribute(R),e.removeAttribute(R)})),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,f,b,E,T,w,I,v,y,S,F];t=e.querySelectorAll(s.map((e=>"["+e+"]")).join(","))}t.forEach((e=>{e.removeAttribute(g),e.removeAttribute(f),e.removeAttribute(p),e.removeAttribute(h),e.removeAttribute(b),e.removeAttribute(E),e.removeAttribute(T),e.removeAttribute(w),e.removeAttribute(I),e.removeAttribute(v),e.removeAttribute(y),e.removeAttribute(S),e.removeAttribute(F),e.removeAttribute(A)})),s&&Array.from(s.entries()).forEach((([e,t])=>t.replaceWith(e)))}function W(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(S,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))}const J=N,G=O,Y="attributes",$=globalThis.browser,K=globalThis.document,X=globalThis.MutationObserver,Q=(e,t,s)=>globalThis.addEventListener(e,t,s),Z=(e,t,s)=>globalThis.removeEventListener(e,t,s),ee=new Map;let te;async function se(e){if(K.documentElement){ee.clear();const n=Math.max(K.documentElement.scrollHeight-1.5*K.documentElement.clientHeight,0),o=Math.max(K.documentElement.scrollWidth-1.5*K.documentElement.clientWidth,0);if(globalThis.scrollY<=n&&globalThis.scrollX<=o)return function(e){return te=0,new Promise((async n=>{let o;const r=new Set,l=new X((async t=>{if((t=t.filter((e=>e.type==Y))).length){t.filter((e=>{if("src"==e.attributeName&&(e.target.setAttribute(J,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(G)})).length&&(o=!0,await oe(l,e,g),r.size||await ne(l,e,g))}}));async function d(t){await ie("idleTimeout",(async()=>{o?te<10&&(te++,le("idleTimeout"),await d(Math.max(500,t/2))):(le("loadTimeout"),le("maxTimeout"),ae(l,e,g))}),t)}function c(e){const t=e.target;t.removeAttribute(J),t.removeEventListener("load",c)}async function m(t){o=!0,await oe(l,e,g),await ne(l,e,g),t.detail&&r.add(t.detail)}async function u(t){await oe(l,e,g),await ne(l,e,g),r.delete(t.detail),r.size||await ne(l,e,g)}function g(e){l.disconnect(),Z(t,m),Z(s,u),n(e)}await d(2*e.loadDeferredImagesMaxIdleTime),await oe(l,e,g),l.observe(K,{subtree:!0,childList:!0,attributes:!0}),Q(t,m),Q(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 ne(e,t,s){await ie("loadTimeout",(()=>ae(e,t,s)),t.loadDeferredImagesMaxIdleTime)}async function oe(e,t,s){await ie("maxTimeout",(async()=>{await le("loadTimeout"),await ae(e,t,s)}),10*t.loadDeferredImagesMaxIdleTime)}async function ae(e,t,s){await le("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 ie("endTimeout",(async()=>{await le("maxTimeout"),s()}),t.loadDeferredImagesMaxIdleTime/2),e.disconnect()}async function ie(e,t,s){if($&&$.runtime&&$.runtime.sendMessage){if(!ee.get(e)||!ee.get(e).pending){const n={callback:t,pending:!0};ee.set(e,n);try{await $.runtime.sendMessage({method:"singlefile.lazyTimeout.setTimeout",type:e,delay:s})}catch(n){re(e,t,s)}n.pending=!1}}else re(e,t,s)}function re(e,t,s){const n=ee.get(e);n&&globalThis.clearTimeout(n),ee.set(e,t),globalThis.setTimeout(t,s)}async function le(e){if($&&$.runtime&&$.runtime.sendMessage)try{await $.runtime.sendMessage({method:"singlefile.lazyTimeout.clearTimeout",type:e})}catch(t){de(e)}else de(e)}function de(e){const t=ee.get(e);ee.delete(e),t&&globalThis.clearTimeout(t)}$&&$.runtime&&$.runtime.onMessage&&$.runtime.onMessage.addListener&&$.runtime.onMessage.addListener((e=>{if("singlefile.lazyTimeout.onTimeout"==e.method){const t=ee.get(e.type);if(t){ee.delete(e.type);try{t.callback()}catch(t){de(e.type)}}}}));const ce={ON_BEFORE_CAPTURE_EVENT_NAME:m,ON_AFTER_CAPTURE_EVENT_NAME:u,WIN_ID_ATTRIBUTE_NAME:"data-single-file-win-id",preProcessDoc:k,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:z,getShadowRoot:H},me="__frameTree__::",ue='iframe, frame, object[type="text/html"][data]',ge="singlefile.frameTree.initRequest",fe="singlefile.frameTree.ackInitRequest",pe="singlefile.frameTree.cleanupRequest",he="singlefile.frameTree.initResponse",be=5e3,ye=".",Ee=globalThis.window==globalThis.top,Te=globalThis.browser,we=globalThis.top,Ie=globalThis.MessageChannel,Ae=globalThis.document;let ve,Ne=globalThis.sessions;var Se,Re,Fe;function Ce(){return globalThis.crypto.getRandomValues(new Uint32Array(32)).join("")}async function _e(e){const t=e.sessionId,s=globalThis._singleFile_waitForUserScript;delete globalThis._singleFile_cleaningUp,Ee||(ve=globalThis.frameId=e.windowId),Me(Ae,e.options,ve,t),Ee||(e.options.userScriptEnabled&&s&&await s(ce.ON_BEFORE_CAPTURE_EVENT_NAME),ke({frames:[Ue(Ae,globalThis,ve,e.options)],sessionId:t,requestedFrameId:Ae.documentElement.dataset.requestedFrameId&&ve}),e.options.userScriptEnabled&&s&&await s(ce.ON_AFTER_CAPTURE_EVENT_NAME),delete Ae.documentElement.dataset.requestedFrameId)}function Pe(e){if(!globalThis._singleFile_cleaningUp){globalThis._singleFile_cleaningUp=!0;const t=e.sessionId;Le(He(Ae),e.windowId,t)}}function xe(e){e.frames.forEach((t=>Oe("responseTimeouts",e.sessionId,t.windowId)));const t=Ne.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.processed=e.processed)}));t.frames.filter((e=>!e.processed)).length||(t.frames=t.frames.sort(((e,t)=>t.windowId.split(ye).length-e.windowId.split(ye).length)),t.resolve&&(t.requestedFrameId&&t.frames.forEach((e=>{e.windowId==t.requestedFrameId&&(e.requestedFrame=!0)})),t.resolve(t.frames)))}}function Me(e,t,s,n){const o=He(e);!function(e,t,s,n,o){const a=[];let i;Ne.get(o)?i=Ne.get(o).requestTimeouts:(i={},Ne.set(o,{requestTimeouts:i}));t.forEach(((e,t)=>{const s=n+ye+t;e.setAttribute(ce.WIN_ID_ATTRIBUTE_NAME,s),a.push({windowId:s})})),ke({frames:a,sessionId:o,requestedFrameId:e.documentElement.dataset.requestedFrameId&&n}),t.forEach(((e,t)=>{const a=n+ye+t;try{qe(e.contentWindow,{method:ge,windowId:a,sessionId:o,options:s})}catch(e){}i[a]=globalThis.setTimeout((()=>ke({frames:[{windowId:a,processed:!0}],sessionId:o})),be)})),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+ye+t;let r;try{r=e.contentDocument}catch(e){}if(r)try{const t=e.contentWindow;t.stop(),Oe("requestTimeouts",o,i),Me(r,s,i,o),a.push(Ue(r,t,i,s))}catch(e){a.push({windowId:i,processed:!0})}})),ke({frames:a,sessionId:o,requestedFrameId:e.documentElement.dataset.requestedFrameId&&n}),delete e.documentElement.dataset.requestedFrameId}(e,o,t,s,n)}function Oe(e,t,s){const n=Ne.get(t);if(n&&n[e]){const t=n[e][s];t&&(globalThis.clearTimeout(t),delete n[e][s])}}function De(e,t){const s=Ne.get(e);s&&s.responseTimeouts&&(s.responseTimeouts[t]=globalThis.setTimeout((()=>ke({frames:[{windowId:t,processed:!0}],sessionId:e})),1e4))}function Le(e,t,s){e.forEach(((e,n)=>{const o=t+ye+n;e.removeAttribute(ce.WIN_ID_ATTRIBUTE_NAME);try{qe(e.contentWindow,{method:pe,windowId:o,sessionId:s})}catch(e){}})),e.forEach(((e,n)=>{const o=t+ye+n;let a;try{a=e.contentDocument}catch(e){}if(a)try{Le(He(a),o,s)}catch(e){}}))}function ke(e){e.method=he;try{we.singlefile.processors.frameTree.initResponse(e)}catch(t){qe(we,e,!0)}}function qe(e,t,s){if(e==we&&Te&&Te.runtime&&Te.runtime.sendMessage)Te.runtime.sendMessage(t);else if(s){const s=new Ie;e.postMessage(me+JSON.stringify({method:t.method,sessionId:t.sessionId}),"*",[s.port2]),s.port1.postMessage(t)}else e.postMessage(me+JSON.stringify(t),"*")}function Ue(e,t,s,n){const o=ce.preProcessDoc(e,t,n),a=ce.serialize(e);ce.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,processed:!0}}function He(e){let t=Array.from(e.querySelectorAll(ue));return e.querySelectorAll("*").forEach((e=>{const s=ce.getShadowRoot(e);s&&(t=t.concat(...s.querySelectorAll(ue)))})),t}Ne||(Ne=globalThis.sessions=new Map),Ee&&(ve="0",Te&&Te.runtime&&Te.runtime.onMessage&&Te.runtime.onMessage.addListener&&Te.runtime.onMessage.addListener((e=>e.method==he?(xe(e),Promise.resolve({})):e.method==fe?(Oe("requestTimeouts",e.sessionId,e.windowId),De(e.sessionId,e.windowId),Promise.resolve({})):void 0))),Se="message",Re=async e=>{if("string"==typeof e.data&&e.data.startsWith(me)){e.preventDefault(),e.stopPropagation();const t=JSON.parse(e.data.substring(me.length));t.method==ge?(e.source&&qe(e.source,{method:fe,windowId:t.windowId,sessionId:t.sessionId}),Ee||(globalThis.stop(),t.options.loadDeferredImages&&se(t.options),await _e(t))):t.method==fe?(Oe("requestTimeouts",t.sessionId,t.windowId),De(t.sessionId,t.windowId)):t.method==pe?Pe(t):t.method==he&&Ne.get(t.sessionId)&&(e.ports[0].onmessage=e=>xe(e.data))}},Fe=!0,globalThis.addEventListener(Se,Re,Fe);var Ve=Object.freeze({__proto__:null,getAsync:function(e){const t=Ce();return e=JSON.parse(JSON.stringify(e)),new Promise((s=>{Ne.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{},resolve:e=>{e.sessionId=t,s(e)}}),_e({windowId:ve,sessionId:t,options:e})}))},getSync:function(e){const t=Ce();e=JSON.parse(JSON.stringify(e)),Ne.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{}}),function(e){const t=e.sessionId,s=globalThis._singleFile_waitForUserScript;delete globalThis._singleFile_cleaningUp,Ee||(ve=globalThis.frameId=e.windowId);Me(Ae,e.options,ve,t),Ee||(e.options.userScriptEnabled&&s&&s(ce.ON_BEFORE_CAPTURE_EVENT_NAME),ke({frames:[Ue(Ae,globalThis,ve,e.options)],sessionId:t,requestedFrameId:Ae.documentElement.dataset.requestedFrameId&&ve}),e.options.userScriptEnabled&&s&&s(ce.ON_AFTER_CAPTURE_EVENT_NAME),delete Ae.documentElement.dataset.requestedFrameId)}({windowId:ve,sessionId:t,options:e});const s=Ne.get(t).frames;return s.sessionId=t,s},cleanup:function(e){Ne.delete(e),Pe({windowId:ve,sessionId:e,options:{sessionId:e}})},initResponse:xe,TIMEOUT_INIT_REQUEST_MESSAGE:be});const Be=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],ze=[{tagName:"head",accept:e=>!e.childNodes.length||1==e.childNodes[0].nodeType},{tagName:"body",accept:e=>!e.childNodes.length}],We=[{tagName:"html",accept:e=>!e||8!=e.nodeType},{tagName:"head",accept:e=>!e||8!=e.nodeType&&(3!=e.nodeType||!Ge(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||!Ge(e.textContent))},{tagName:"caption",accept:e=>!e||8!=e.nodeType&&(3!=e.nodeType||!Ge(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)}],je=["style","script","xmp","iframe","noembed","noframes","plaintext","noscript"];function Je(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||je.includes(s)?"script"==s?e.textContent.replace(/<\//gi,"<\\/").replace(/\/>/gi,"\\/>"):e.textContent:e.textContent.replace(/&/g,"&amp;").replace(/\u00a0/g,"&nbsp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}(e):8==e.nodeType?"\x3c!--"+e.textContent+"--\x3e":1==e.nodeType?function(e,t,s){const n=e.tagName.toLowerCase(),o=t&&ze.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,"&amp;").replace(/\u00a0/g,"&nbsp;"),i.includes('"')&&(i.includes("'")||!s?i=i.replace(/"/g,"&quot;"):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+=Je(e,t,s||"svg"==n))):a+=e.innerHTML;const i=t&&We.find((t=>n==t.tagName&&t.accept(e.nextSibling,e)));(s||!i&&!Be.includes(n))&&(a+="</"+n+">");return a}(e,t,s):void 0}function Ge(e){return Boolean(e.match(/^[ \t\n\f\r]/))}const Ye={frameTree:Ve},$e={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:k,postProcessDoc:z,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+Je(e.documentElement,t)}(e,t),getShadowRoot:H};L("single-file-user-script-init",(()=>globalThis._singleFile_waitForUserScript=async e=>{const t=new CustomEvent(e+"-request",{cancelable:!0}),s=new Promise((t=>L(e+"-response",t)));(e=>{try{globalThis.dispatchEvent(e)}catch(e){}})(t),t.defaultPrevented&&await s})),e.helper=$e,e.processors=Ye,Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -1 +1 @@
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};if(n.images.push(t),s.setAttribute(b,n.images.length-1),n.markedElements.push(s),s.removeAttribute(A),a=a||e.getComputedStyle(s)){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})}));
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),u(...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 u(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 u(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 u="data-single-file-removed-content",m="data-single-file-hidden-content",f="data-single-file-kept-content",g="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-movable-style",I="data-single-file-input-value",v="data-single-file-lazy-loaded-src",A="data-single-file-stylesheet",S="data-single-file-disabled-noscript",F="data-single-file-async-script",R="*: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"],N=/^'(.*?)'$/,C=/^"(.*?)"$/,M={regular:"400",normal:"400",bold:"700",bolder:"700",lighter:"100"},q="single-file-ui-element",x="data:,";function P(e,t,s,o,n={usedFonts:new Map,canvases:[],images:[],posters:[],videos:[],shadowRoots:[],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||D(s,l),a&&(s.setAttribute(m,""),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&&(k(l,o,n.usedFonts),k(e.getComputedStyle(s,":first-letter"),o,n.usedFonts),k(e.getComputedStyle(s,":before"),o,n.usedFonts),k(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?x:o.loadDeferredImages&&s.getAttribute(v)||s.currentSrc};n.images.push(t),s.setAttribute(b,n.images.length-1),n.markedElements.push(s),s.removeAttribute(v);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,u,m,f,g=!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"),g=t.clientWidth!=o,e?t.style.setProperty("box-sizing",e,s):t.style.removeProperty("box-sizing")}a=V("padding-left",s),r=V("padding-right",s),l=V("padding-top",s),d=V("padding-bottom",s),g?(c=V("border-left-width",s),u=V("border-right-width",s),m=V("border-top-width",s),f=V("border-bottom-width",s)):c=u=m=f=0,o=Math.max(0,t.clientWidth-a-r-c-u),n=Math.max(0,t.clientHeight-l-d-m-f),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(g,""),n.markedElements.push(s));"INPUT"==s.tagName&&("password"!=s.type&&(s.setAttribute(I,s.value),n.markedElements.push(s)),"radio"!=s.type&&"checkbox"!=s.type||(s.setAttribute(I,s.checked),n.markedElements.push(s)));"TEXTAREA"==s.tagName&&(s.setAttribute(I,s.value),n.markedElements.push(s));"SELECT"==s.tagName&&s.querySelectorAll("option").forEach((e=>{e.selected&&(e.setAttribute(I,""),n.markedElements.push(e))}));"SCRIPT"==s.tagName&&(s.async&&""!=s.getAttribute("async")&&"async"!=s.getAttribute("async")&&(s.setAttribute(F,""),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)&&L(s);if(d&&!s.classList.contains(q)){const i={};s.setAttribute(p,n.shadowRoots.length),n.markedElements.push(s),n.shadowRoots.push(i),P(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){}}P(e,t,s,o,n,a),!o.autoSaveExternalSave&&o.removeHiddenElements&&i&&(r||""==s.getAttribute(f)?s.parentElement&&(s.parentElement.setAttribute(f,""),n.markedElements.push(s.parentElement)):a&&(s.setAttribute(u,""),n.markedElements.push(s)))})),n}function k(e,t,s){if(e){const o=e.getPropertyValue("font-style")||"normal";e.getPropertyValue("font-family").split(",").forEach((n=>{if(n=O(n),!t.loadedFonts||t.loadedFonts.find((e=>O(e.family)==n&&e.style==o))){const t=(i=e.getPropertyValue("font-weight"),M[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 L(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 O(e=""){return function(e){e=e.match(N)?e.replace(N,"$1"):e.replace(C,"$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 D(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 U(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(A,o),t[o]=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n"))}catch(e){}})),t}}function V(e,t){if(t.getPropertyValue(e).endsWith("px"))return parseFloat(t.getPropertyValue(e))}const W=v,z=q,H="attributes",B=globalThis.browser,j=globalThis.document,J=globalThis.MutationObserver,G=(e,t,s)=>globalThis.addEventListener(e,t,s),Y=(e,t,s)=>globalThis.removeEventListener(e,t,s),$=new Map;let K;async function X(e){if(j.documentElement){$.clear();const o=Math.max(j.documentElement.scrollHeight-1.5*j.documentElement.clientHeight,0),n=Math.max(j.documentElement.scrollWidth-1.5*j.documentElement.clientWidth,0);if(globalThis.scrollY<=o&&globalThis.scrollX<=n)return function(e){return K=0,new Promise((async o=>{let n;const r=new Set,l=new J((async t=>{if((t=t.filter((e=>e.type==H))).length){t.filter((e=>{if("src"==e.attributeName&&(e.target.setAttribute(W,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(z)})).length&&(n=!0,await Q(l,e,f),r.size||await Z(l,e,f))}}));async function d(t){await te("idleTimeout",(async()=>{n?K<10&&(K++,oe("idleTimeout"),await d(Math.max(500,t/2))):(oe("loadTimeout"),oe("maxTimeout"),ee(l,e,f))}),t)}function c(e){const t=e.target;t.removeAttribute(W),t.removeEventListener("load",c)}async function u(t){n=!0,await Q(l,e,f),await Z(l,e,f),t.detail&&r.add(t.detail)}async function m(t){await Q(l,e,f),await Z(l,e,f),r.delete(t.detail),r.size||await Z(l,e,f)}function f(e){l.disconnect(),Y(t,u),Y(s,m),o(e)}await d(2*e.loadDeferredImagesMaxIdleTime),await Q(l,e,f),l.observe(j,{subtree:!0,childList:!0,attributes:!0}),G(t,u),G(s,m),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 Z(e,t,s){await te("loadTimeout",(()=>ee(e,t,s)),t.loadDeferredImagesMaxIdleTime)}async function Q(e,t,s){await te("maxTimeout",(async()=>{await oe("loadTimeout"),await ee(e,t,s)}),10*t.loadDeferredImagesMaxIdleTime)}async function ee(e,t,s){await oe("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 te("endTimeout",(async()=>{await oe("maxTimeout"),s()}),t.loadDeferredImagesMaxIdleTime/2),e.disconnect()}async function te(e,t,s){if(B&&B.runtime&&B.runtime.sendMessage){if(!$.get(e)||!$.get(e).pending){const o={callback:t,pending:!0};$.set(e,o);try{await B.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=$.get(e);o&&globalThis.clearTimeout(o),$.set(e,t),globalThis.setTimeout(t,s)}async function oe(e){if(B&&B.runtime&&B.runtime.sendMessage)try{await B.runtime.sendMessage({method:"singlefile.lazyTimeout.clearTimeout",type:e})}catch(t){ne(e)}else ne(e)}function ne(e){const t=$.get(e);$.delete(e),t&&globalThis.clearTimeout(t)}B&&B.runtime&&B.runtime.onMessage&&B.runtime.onMessage.addListener&&B.runtime.onMessage.addListener((e=>{if("singlefile.lazyTimeout.onTimeout"==e.method){const t=$.get(e.type);if(t){$.delete(e.type);try{t.callback()}catch(t){ne(e.type)}}}}));const ie={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(S,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(R).forEach((e=>e.hidden=!0)),e.querySelectorAll("svg foreignObject").forEach((e=>{const t=e.querySelectorAll("html > head > "+R+", html > body > "+R);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=P(t,e,e.documentElement,s),s.moveStylesInHead&&e.querySelectorAll("body style, body ~ style").forEach((e=>{const s=t.getComputedStyle(e);s&&D(e,s)&&(e.setAttribute(T,""),n.markedElements.push(e))}))):n={canvases:[],images:[],posters:[],videos:[],usedFonts:[],shadowRoots:[],markedElements:[]},{canvases:n.canvases,fonts:Array.from(d.values()),stylesheets:U(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}},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("[data-single-file-disabled-noscript]").forEach((e=>{e.textContent=e.getAttribute(S),e.removeAttribute(S)})),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=[u,g,m,h,b,y,w,E,I,p,A,F];t=e.querySelectorAll(s.map((e=>"["+e+"]")).join(","))}t.forEach((e=>{e.removeAttribute(u),e.removeAttribute(m),e.removeAttribute(f),e.removeAttribute(g),e.removeAttribute(h),e.removeAttribute(b),e.removeAttribute(y),e.removeAttribute(w),e.removeAttribute(E),e.removeAttribute(I),e.removeAttribute(p),e.removeAttribute(A),e.removeAttribute(F),e.removeAttribute(T)})),s&&Array.from(s.entries()).forEach((([e,t])=>t.replaceWith(e)))},getShadowRoot:L},ae="__frameTree__::",re='iframe, frame, object[type="text/html"][data]',le="singlefile.frameTree.initRequest",de="singlefile.frameTree.ackInitRequest",ce="singlefile.frameTree.cleanupRequest",ue="singlefile.frameTree.initResponse",me=5e3,fe=".",ge=globalThis.window==globalThis.top,he=globalThis.browser,pe=globalThis.top,be=globalThis.MessageChannel,ye=globalThis.document;let we,Ee=globalThis.sessions;var Te,Ie,ve;function Ae(){return globalThis.crypto.getRandomValues(new Uint32Array(32)).join("")}async function Se(e){const t=e.sessionId,s=globalThis._singleFile_waitForUserScript;delete globalThis._singleFile_cleaningUp,ge||(we=globalThis.frameId=e.windowId),_e(ye,e.options,we,t),ge||(e.options.userScriptEnabled&&s&&await s(ie.ON_BEFORE_CAPTURE_EVENT_NAME),qe({frames:[Pe(ye,globalThis,we,e.options)],sessionId:t,requestedFrameId:ye.documentElement.dataset.requestedFrameId&&we}),e.options.userScriptEnabled&&s&&await s(ie.ON_AFTER_CAPTURE_EVENT_NAME),delete ye.documentElement.dataset.requestedFrameId)}function Fe(e){if(!globalThis._singleFile_cleaningUp){globalThis._singleFile_cleaningUp=!0;const t=e.sessionId;Me(ke(ye),e.windowId,t)}}function Re(e){e.frames.forEach((t=>Ne("responseTimeouts",e.sessionId,t.windowId)));const t=Ee.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.processed=e.processed)}));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 _e(e,t,s,o){const n=ke(e);!function(e,t,s,o,n){const i=[];let a;Ee.get(n)?a=Ee.get(n).requestTimeouts:(a={},Ee.set(n,{requestTimeouts:a}));t.forEach(((e,t)=>{const s=o+fe+t;e.setAttribute(ie.WIN_ID_ATTRIBUTE_NAME,s),i.push({windowId:s})})),qe({frames:i,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),t.forEach(((e,t)=>{const i=o+fe+t;try{xe(e.contentWindow,{method:le,windowId:i,sessionId:n,options:s})}catch(e){}a[i]=globalThis.setTimeout((()=>qe({frames:[{windowId:i,processed:!0}],sessionId:n})),me)})),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+fe+t;let r;try{r=e.contentDocument}catch(e){}if(r)try{const t=e.contentWindow;t.stop(),Ne("requestTimeouts",n,a),_e(r,s,a,n),i.push(Pe(r,t,a,s))}catch(e){i.push({windowId:a,processed:!0})}})),qe({frames:i,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o)}function Ne(e,t,s){const o=Ee.get(t);if(o&&o[e]){const t=o[e][s];t&&(globalThis.clearTimeout(t),delete o[e][s])}}function Ce(e,t){const s=Ee.get(e);s&&s.responseTimeouts&&(s.responseTimeouts[t]=globalThis.setTimeout((()=>qe({frames:[{windowId:t,processed:!0}],sessionId:e})),1e4))}function Me(e,t,s){e.forEach(((e,o)=>{const n=t+fe+o;e.removeAttribute(ie.WIN_ID_ATTRIBUTE_NAME);try{xe(e.contentWindow,{method:ce,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{Me(ke(i),n,s)}catch(e){}}))}function qe(e){e.method=ue;try{pe.singlefile.processors.frameTree.initResponse(e)}catch(t){xe(pe,e,!0)}}function xe(e,t,s){if(e==pe&&he&&he.runtime&&he.runtime.sendMessage)he.runtime.sendMessage(t);else if(s){const s=new be;e.postMessage(ae+JSON.stringify({method:t.method,sessionId:t.sessionId}),"*",[s.port2]),s.port1.postMessage(t)}else e.postMessage(ae+JSON.stringify(t),"*")}function Pe(e,t,s,o){const n=ie.preProcessDoc(e,t,o),i=ie.serialize(e);ie.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,processed:!0}}function ke(e){let t=Array.from(e.querySelectorAll(re));return e.querySelectorAll("*").forEach((e=>{const s=ie.getShadowRoot(e);s&&(t=t.concat(...s.querySelectorAll(re)))})),t}Ee||(Ee=globalThis.sessions=new Map),ge&&(we="0",he&&he.runtime&&he.runtime.onMessage&&he.runtime.onMessage.addListener&&he.runtime.onMessage.addListener((e=>e.method==ue?(Re(e),Promise.resolve({})):e.method==de?(Ne("requestTimeouts",e.sessionId,e.windowId),Ce(e.sessionId,e.windowId),Promise.resolve({})):void 0))),Te="message",Ie=async e=>{if("string"==typeof e.data&&e.data.startsWith(ae)){e.preventDefault(),e.stopPropagation();const t=JSON.parse(e.data.substring(ae.length));t.method==le?(e.source&&xe(e.source,{method:de,windowId:t.windowId,sessionId:t.sessionId}),ge||(globalThis.stop(),t.options.loadDeferredImages&&X(t.options),await Se(t))):t.method==de?(Ne("requestTimeouts",t.sessionId,t.windowId),Ce(t.sessionId,t.windowId)):t.method==ce?Fe(t):t.method==ue&&Ee.get(t.sessionId)&&(e.ports[0].onmessage=e=>Re(e.data))}},ve=!0,globalThis.addEventListener(Te,Ie,ve),e.TIMEOUT_INIT_REQUEST_MESSAGE=me,e.cleanup=function(e){Ee.delete(e),Fe({windowId:we,sessionId:e,options:{sessionId:e}})},e.getAsync=function(e){const t=Ae();return e=JSON.parse(JSON.stringify(e)),new Promise((s=>{Ee.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{},resolve:e=>{e.sessionId=t,s(e)}}),Se({windowId:we,sessionId:t,options:e})}))},e.getSync=function(e){const t=Ae();e=JSON.parse(JSON.stringify(e)),Ee.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{}}),function(e){const t=e.sessionId,s=globalThis._singleFile_waitForUserScript;delete globalThis._singleFile_cleaningUp,ge||(we=globalThis.frameId=e.windowId);_e(ye,e.options,we,t),ge||(e.options.userScriptEnabled&&s&&s(ie.ON_BEFORE_CAPTURE_EVENT_NAME),qe({frames:[Pe(ye,globalThis,we,e.options)],sessionId:t,requestedFrameId:ye.documentElement.dataset.requestedFrameId&&we}),e.options.userScriptEnabled&&s&&s(ie.ON_AFTER_CAPTURE_EVENT_NAME),delete ye.documentElement.dataset.requestedFrameId)}({windowId:we,sessionId:t,options:e});const s=Ee.get(t).frames;return s.sessionId=t,s},e.initResponse=Re,Object.defineProperty(e,"__esModule",{value:!0})}));