Files
sm-bm-plugin/public/assets/index-S6sqpC1H.js
2026-11-06 15:05:55 +01:00

15 lines
24 KiB
JavaScript

function ge(e,t){return e[13]=1,e[14]=t>>8,e[15]=t&255,e[16]=t>>8,e[17]=t&255,e}const J=112,K=72,Q=89,Z=115;let L;function he(){const e=new Int32Array(256);for(let t=0;t<256;t++){let r=t;for(let n=0;n<8;n++)r=r&1?3988292384^r>>>1:r>>>1;e[t]=r}return e}function pe(e){let t=-1;L||(L=he());for(let r=0;r<e.length;r++)t=L[(t^e[r])&255]^t>>>8;return t^-1}function we(e){const t=e.length-1;for(let r=t;r>=4;r--)if(e[r-4]===9&&e[r-3]===J&&e[r-2]===K&&e[r-1]===Q&&e[r]===Z)return r-3;return 0}function ye(e,t,r=!1){const n=new Uint8Array(13);t*=39.3701,n[0]=J,n[1]=K,n[2]=Q,n[3]=Z,n[4]=t>>>24,n[5]=t>>>16,n[6]=t>>>8,n[7]=t&255,n[8]=n[4],n[9]=n[5],n[10]=n[6],n[11]=n[7],n[12]=1;const a=pe(n),s=new Uint8Array(4);if(s[0]=a>>>24,s[1]=a>>>16,s[2]=a>>>8,s[3]=a&255,r){const i=we(e);return e.set(n,i),e.set(s,i+13),e}else{const i=new Uint8Array(4);i[0]=0,i[1]=0,i[2]=0,i[3]=9;const o=new Uint8Array(54);return o.set(e,0),o.set(i,33),o.set(n,37),o.set(s,50),o}}const be="AAlwSFlz",Se="AAAJcEhZ",Ee="AAAACXBI";function Ce(e){let t=e.indexOf(be);return t===-1&&(t=e.indexOf(Se)),t===-1&&(t=e.indexOf(Ee)),t}const ee="[modern-screenshot]",N=typeof window<"u",ve=N&&"Worker"in window,Ne=N&&"atob"in window,Te=N&&"btoa"in window,B=N?window.navigator?.userAgent:"",te=B.includes("Chrome"),_=B.includes("AppleWebKit")&&!te,W=B.includes("Firefox"),Ae=e=>e&&"__CONTEXT__"in e,Re=e=>e.constructor.name==="CSSFontFaceRule",De=e=>e.constructor.name==="CSSImportRule",ke=e=>e.constructor.name==="CSSLayerBlockRule",E=e=>e.nodeType===1,F=e=>typeof e.className=="object",re=e=>e.tagName==="image",Fe=e=>e.tagName==="use",R=e=>E(e)&&typeof e.style<"u"&&!F(e),Ie=e=>e.nodeType===8,_e=e=>e.nodeType===3,A=e=>e.tagName==="IMG",P=e=>e.tagName==="VIDEO",Pe=e=>e.tagName==="CANVAS",xe=e=>e.tagName==="TEXTAREA",Ue=e=>e.tagName==="INPUT",$e=e=>e.tagName==="STYLE",Le=e=>e.tagName==="SCRIPT",Oe=e=>e.tagName==="SELECT",Me=e=>e.tagName==="SLOT",Be=e=>e.tagName==="IFRAME",We=(...e)=>console.warn(ee,...e);function qe(e){const t=e?.createElement?.("canvas");return t&&(t.height=t.width=1),!!t&&"toDataURL"in t&&!!t.toDataURL("image/webp").includes("image/webp")}const O=e=>e.startsWith("data:");function ne(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(N&&e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i)||!N)return e;const r=x().implementation.createHTMLDocument(),n=r.createElement("base"),a=r.createElement("a");return r.head.appendChild(n),r.body.appendChild(a),t&&(n.href=t),a.href=e,a.href}function x(e){return(e&&E(e)?e?.ownerDocument:e)??window.document}const U="http://www.w3.org/2000/svg";function je(e,t,r){const n=x(r).createElementNS(U,"svg");return n.setAttributeNS(null,"width",e.toString()),n.setAttributeNS(null,"height",t.toString()),n.setAttributeNS(null,"viewBox",`0 0 ${e} ${t}`),n}function He(e,t){let r=new XMLSerializer().serializeToString(e);return t&&(r=r.replace(/[\u0000-\u0008\v\f\u000E-\u001F\uD800-\uDFFF\uFFFE\uFFFF]/gu,"")),`data:image/svg+xml;charset=utf-8,${encodeURIComponent(r)}`}function Ve(e,t){return new Promise((r,n)=>{const a=new FileReader;a.onload=()=>r(a.result),a.onerror=()=>n(a.error),a.onabort=()=>n(new Error(`Failed read blob to ${t}`)),a.readAsDataURL(e)})}const ze=e=>Ve(e,"dataUrl");function T(e,t){const r=x(t).createElement("img");return r.decoding="sync",r.loading="eager",r.src=e,r}function D(e,t){return new Promise(r=>{const{timeout:n,ownerDocument:a,onError:s,onWarn:i}=t??{},o=typeof e=="string"?T(e,x(a)):e;let f=null,u=null;function l(){r(o),f&&clearTimeout(f),u?.()}if(n&&(f=setTimeout(l,n)),P(o)){const m=o.currentSrc||o.src;if(!m)return o.poster?D(o.poster,t).then(r):l();if(o.readyState>=2)return l();const d=l,g=h=>{i?.("Failed video load",m,h),s?.(h),l()};u=()=>{o.removeEventListener("loadeddata",d),o.removeEventListener("error",g)},o.addEventListener("loadeddata",d,{once:!0}),o.addEventListener("error",g,{once:!0})}else{const m=re(o)?o.href.baseVal:o.currentSrc||o.src;if(!m)return l();const d=async()=>{if(A(o)&&"decode"in o)try{await o.decode()}catch(h){i?.("Failed to decode image, trying to render anyway",o.dataset.originalSrc||m,h)}l()},g=h=>{i?.("Failed image load",o.dataset.originalSrc||m,h),l()};if(A(o)&&o.complete)return d();u=()=>{o.removeEventListener("load",d),o.removeEventListener("error",g)},o.addEventListener("load",d,{once:!0}),o.addEventListener("error",g,{once:!0})}})}async function Xe(e,t){R(e)&&(A(e)||P(e)?await D(e,t):await Promise.all(["img","video"].flatMap(r=>Array.from(e.querySelectorAll(r)).map(n=>D(n,t)))))}const oe=(function(){let t=0;const r=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(t+=1,`u${r()}${t}`)})();function se(e){return e?.split(",").map(t=>t.trim().replace(/"|'/g,"").toLowerCase()).filter(Boolean)}let H=0;function Ge(e){const t=`${ee}[#${H}]`;return H++,{time:r=>e&&console.time(`${t} ${r}`),timeEnd:r=>e&&console.timeEnd(`${t} ${r}`),warn:(...r)=>e&&We(...r)}}function Ye(e){return{cache:e?"no-cache":"force-cache"}}async function $(e,t){return Ae(e)?e:Je(e,{...t,autoDestruct:!0})}async function Je(e,t){const{scale:r=1,workerUrl:n,workerNumber:a=1}=t||{},s=!!t?.debug,i=t?.features??!0,o=e.ownerDocument??(N?window.document:void 0),f=e.ownerDocument?.defaultView??(N?window:void 0),u=new Map,l={width:0,height:0,quality:1,type:"image/png",scale:r,backgroundColor:null,style:null,filter:null,maximumCanvasSize:0,timeout:3e4,progress:null,debug:s,fetch:{requestInit:Ye(t?.fetch?.bypassingCache),placeholderImage:"data:image/png;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",bypassingCache:!1,...t?.fetch},fetchFn:null,font:{},drawImageInterval:100,workerUrl:null,workerNumber:a,onCloneEachNode:null,onCloneNode:null,onEmbedNode:null,onCreateForeignObjectSvg:null,includeStyleProperties:null,autoDestruct:!1,...t,__CONTEXT__:!0,log:Ge(s),node:e,ownerDocument:o,ownerWindow:f,dpi:r===1?null:96*r,svgStyleElement:ae(o),svgDefsElement:o?.createElementNS(U,"defs"),svgStyles:new Map,defaultComputedStyles:new Map,workers:[...Array.from({length:ve&&n&&a?a:0})].map(()=>{try{const g=new Worker(n);return g.onmessage=async h=>{const{url:c,result:p}=h.data;p?u.get(c)?.resolve?.(p):u.get(c)?.reject?.(new Error(`Error receiving message from worker: ${c}`))},g.onmessageerror=h=>{const{url:c}=h.data;u.get(c)?.reject?.(new Error(`Error receiving message from worker: ${c}`))},g}catch(g){return l.log.warn("Failed to new Worker",g),null}}).filter(Boolean),fontFamilies:new Map,fontCssTexts:new Map,acceptOfImage:`${[qe(o)&&"image/webp","image/svg+xml","image/*","*/*"].filter(Boolean).join(",")};q=0.8`,requests:u,drawImageCount:0,tasks:[],features:i,isEnable:g=>g==="restoreScrollPosition"?typeof i=="boolean"?!1:i[g]??!1:typeof i=="boolean"?i:i[g]??!0,shadowRoots:[]};l.log.time("wait until load"),await Xe(e,{timeout:l.timeout,onWarn:l.log.warn}),l.log.timeEnd("wait until load");const{width:m,height:d}=Ke(e,l);return l.width=m,l.height=d,l}function ae(e){if(!e)return;const t=e.createElement("style"),r=t.ownerDocument.createTextNode(`
.______background-clip--text {
background-clip: text;
-webkit-background-clip: text;
}
`);return t.appendChild(r),t}function Ke(e,t){let{width:r,height:n}=t;if(E(e)&&(!r||!n)){const a=e.getBoundingClientRect();r=r||a.width||Number(e.getAttribute("width"))||0,n=n||a.height||Number(e.getAttribute("height"))||0}return{width:r,height:n}}async function Qe(e,t){const{log:r,timeout:n,drawImageCount:a,drawImageInterval:s}=t;r.time("image to canvas");const i=await D(e,{timeout:n,onWarn:t.log.warn}),{canvas:o,context2d:f}=Ze(e.ownerDocument,t),u=()=>{try{f?.drawImage(i,0,0,o.width,o.height)}catch(l){t.log.warn("Failed to drawImage",l)}};if(u(),t.isEnable("fixSvgXmlDecode"))for(let l=0;l<a;l++)await new Promise(m=>{setTimeout(()=>{f?.clearRect(0,0,o.width,o.height),u(),m()},l+s)});return t.drawImageCount=0,r.timeEnd("image to canvas"),o}function Ze(e,t){const{width:r,height:n,scale:a,backgroundColor:s,maximumCanvasSize:i}=t,o=e.createElement("canvas");o.width=Math.floor(r*a),o.height=Math.floor(n*a),o.style.width=`${r}px`,o.style.height=`${n}px`,i&&(o.width>i||o.height>i)&&(o.width>i&&o.height>i?o.width>o.height?(o.height*=i/o.width,o.width=i):(o.width*=i/o.height,o.height=i):o.width>i?(o.height*=i/o.width,o.width=i):(o.width*=i/o.height,o.height=i));const f=o.getContext("2d");return f&&s&&(f.fillStyle=s,f.fillRect(0,0,o.width,o.height)),{canvas:o,context2d:f}}function ie(e,t){if(e.ownerDocument)try{const s=e.toDataURL();if(s!=="data:,")return T(s,e.ownerDocument)}catch(s){t.log.warn("Failed to clone canvas",s)}const r=e.cloneNode(!1),n=e.getContext("2d"),a=r.getContext("2d");try{return n&&a&&a.putImageData(n.getImageData(0,0,e.width,e.height),0,0),r}catch(s){t.log.warn("Failed to clone canvas",s)}return r}function et(e,t){try{if(e?.contentDocument?.documentElement)return q(e.contentDocument.documentElement,t)}catch(r){t.log.warn("Failed to clone iframe",r)}return e.cloneNode(!1)}function tt(e){const t=e.cloneNode(!1);return e.currentSrc&&e.currentSrc!==e.src&&(t.src=e.currentSrc,t.srcset=""),t.loading==="lazy"&&(t.loading="eager"),t}async function rt(e,t){if(e.ownerDocument&&!e.currentSrc&&e.poster)return T(e.poster,e.ownerDocument);const r=e.cloneNode(!1);r.crossOrigin="anonymous",e.currentSrc&&e.currentSrc!==e.src&&(r.src=e.currentSrc);const n=r.ownerDocument;if(n){let a=!0;if(await D(r,{onError:()=>a=!1,onWarn:t.log.warn}),!a)return e.poster?T(e.poster,e.ownerDocument):r;r.currentTime=e.currentTime,await new Promise(i=>{r.addEventListener("seeked",i,{once:!0})});const s=n.createElement("canvas");s.width=e.offsetWidth,s.height=e.offsetHeight;try{const i=s.getContext("2d");i&&i.drawImage(r,0,0,s.width,s.height)}catch(i){return t.log.warn("Failed to clone video",i),e.poster?T(e.poster,e.ownerDocument):r}return ie(s,t)}return r}function nt(e,t){return Pe(e)?ie(e,t):Be(e)?et(e,t):A(e)?tt(e):P(e)?rt(e,t):e.cloneNode(!1)}function ot(e){let t=e.sandbox;if(!t){const{ownerDocument:r}=e;try{r&&(t=r.createElement("iframe"),t.id=`__SANDBOX__${oe()}`,t.width="0",t.height="0",t.style.visibility="hidden",t.style.position="fixed",r.body.appendChild(t),t.srcdoc='<!DOCTYPE html><meta charset="UTF-8"><title></title><body>',e.sandbox=t)}catch(n){e.log.warn("Failed to getSandBox",n)}}return t}const st=["width","height","-webkit-text-fill-color"],at=["stroke","fill"];function le(e,t,r){const{defaultComputedStyles:n}=r,a=e.nodeName.toLowerCase(),s=F(e)&&a!=="svg",i=s?at.map(c=>[c,e.getAttribute(c)]).filter(([,c])=>c!==null):[],o=[s&&"svg",a,i.map((c,p)=>`${c}=${p}`).join(","),t].filter(Boolean).join(":");if(n.has(o))return n.get(o);const u=ot(r)?.contentWindow;if(!u)return new Map;const l=u?.document;let m,d;s?(m=l.createElementNS(U,"svg"),d=m.ownerDocument.createElementNS(m.namespaceURI,a),i.forEach(([c,p])=>{d.setAttributeNS(null,c,p)}),m.appendChild(d)):m=d=l.createElement(a),d.textContent=" ",l.body.appendChild(m);const g=u.getComputedStyle(d,t),h=new Map;for(let c=g.length,p=0;p<c;p++){const w=g.item(p);st.includes(w)||h.set(w,g.getPropertyValue(w))}return l.body.removeChild(m),n.set(o,h),h}function ce(e,t,r){const n=new Map,a=[],s=new Map;if(r)for(const o of r)i(o);else for(let o=e.length,f=0;f<o;f++){const u=e.item(f);i(u)}for(let o=a.length,f=0;f<o;f++)s.get(a[f])?.forEach((u,l)=>n.set(l,u));function i(o){const f=e.getPropertyValue(o),u=e.getPropertyPriority(o),l=o.lastIndexOf("-"),m=l>-1?o.substring(0,l):void 0;if(m){let d=s.get(m);d||(d=new Map,s.set(m,d)),d.set(o,[f,u])}t.get(o)===f&&!u||(m?a.push(m):n.set(o,[f,u]))}return n}function it(e,t,r,n){const{ownerWindow:a,includeStyleProperties:s,currentParentNodeStyle:i}=n,o=t.style,f=a.getComputedStyle(e),u=le(e,null,n);i?.forEach((m,d)=>{u.delete(d)});const l=ce(f,u,s);l.delete("transition-property"),l.delete("all"),l.delete("d"),l.delete("content"),r&&(l.delete("position"),l.delete("margin-top"),l.delete("margin-right"),l.delete("margin-bottom"),l.delete("margin-left"),l.delete("margin-block-start"),l.delete("margin-block-end"),l.delete("margin-inline-start"),l.delete("margin-inline-end"),l.set("box-sizing",["border-box",""])),l.get("background-clip")?.[0]==="text"&&t.classList.add("______background-clip--text"),te&&(l.has("font-kerning")||l.set("font-kerning",["normal",""]),(l.get("overflow-x")?.[0]==="hidden"||l.get("overflow-y")?.[0]==="hidden")&&l.get("text-overflow")?.[0]==="ellipsis"&&e.scrollWidth===e.clientWidth&&l.set("text-overflow",["clip",""]));for(let m=o.length,d=0;d<m;d++)o.removeProperty(o.item(d));return l.forEach(([m,d],g)=>{o.setProperty(g,m,d)}),l}function lt(e,t){(xe(e)||Ue(e)||Oe(e))&&t.setAttribute("value",e.value)}const ct=["::before","::after"],ut=["::-webkit-scrollbar","::-webkit-scrollbar-button","::-webkit-scrollbar-thumb","::-webkit-scrollbar-track","::-webkit-scrollbar-track-piece","::-webkit-scrollbar-corner","::-webkit-resizer"];function ft(e,t,r,n,a){const{ownerWindow:s,svgStyleElement:i,svgStyles:o,currentNodeStyle:f}=n;if(!i||!s)return;function u(l){const m=s.getComputedStyle(e,l);let d=m.getPropertyValue("content");if(!d||d==="none")return;a?.(d),d=d.replace(/(')|(")|(counter\(.+\))/g,"");const g=[oe()],h=le(e,l,n);f?.forEach((y,S)=>{h.delete(S)});const c=ce(m,h,n.includeStyleProperties);c.delete("content"),c.delete("-webkit-locale"),c.get("background-clip")?.[0]==="text"&&t.classList.add("______background-clip--text");const p=[`content: '${d}';`];if(c.forEach(([y,S],v)=>{p.push(`${v}: ${y}${S?" !important":""};`)}),p.length===1)return;try{t.className=[t.className,...g].join(" ")}catch(y){n.log.warn("Failed to copyPseudoClass",y);return}const w=p.join(`
`);let b=o.get(w);b||(b=[],o.set(w,b)),b.push(`.${g[0]}${l}`)}ct.forEach(u),r&&ut.forEach(u)}const V=new Set(["symbol"]);async function z(e,t,r,n,a){if(E(r)&&($e(r)||Le(r))||n.filter&&!n.filter(r))return;V.has(t.nodeName)||V.has(r.nodeName)?n.currentParentNodeStyle=void 0:n.currentParentNodeStyle=n.currentNodeStyle;const s=await q(r,n,!1,a);n.isEnable("restoreScrollPosition")&&dt(e,s),t.appendChild(s)}async function X(e,t,r,n){let a=e.firstChild;E(e)&&e.shadowRoot&&(a=e.shadowRoot?.firstChild,r.shadowRoots.push(e.shadowRoot));for(let s=a;s;s=s.nextSibling)if(!Ie(s))if(E(s)&&Me(s)&&typeof s.assignedNodes=="function"){const i=s.assignedNodes();for(let o=0;o<i.length;o++)await z(e,t,i[o],r,n)}else await z(e,t,s,r,n)}function dt(e,t){if(!R(e)||!R(t))return;const{scrollTop:r,scrollLeft:n}=e;if(!r&&!n)return;const{transform:a}=t.style,s=new DOMMatrix(a),{a:i,b:o,c:f,d:u}=s;s.a=1,s.b=0,s.c=0,s.d=1,s.translateSelf(-n,-r),s.a=i,s.b=o,s.c=f,s.d=u,t.style.transform=s.toString()}function mt(e,t){const{backgroundColor:r,width:n,height:a,style:s}=t,i=e.style;if(r&&i.setProperty("background-color",r,"important"),n&&i.setProperty("width",`${n}px`,"important"),a&&i.setProperty("height",`${a}px`,"important"),s)for(const o in s)i[o]=s[o]}const gt=/^[\w-:]+$/;async function q(e,t,r=!1,n){const{ownerDocument:a,ownerWindow:s,fontFamilies:i,onCloneEachNode:o}=t;if(a&&_e(e))return n&&/\S/.test(e.data)&&n(e.data),a.createTextNode(e.data);if(a&&s&&E(e)&&(R(e)||F(e))){const u=await nt(e,t);if(t.isEnable("removeAbnormalAttributes")){const c=u.getAttributeNames();for(let p=c.length,w=0;w<p;w++){const b=c[w];gt.test(b)||u.removeAttribute(b)}}const l=t.currentNodeStyle=it(e,u,r,t);r&&mt(u,t);let m=!1;if(t.isEnable("copyScrollbar")){const c=[l.get("overflow-x")?.[0],l.get("overflow-y")?.[0]];m=c.includes("scroll")||(c.includes("auto")||c.includes("overlay"))&&(e.scrollHeight>e.clientHeight||e.scrollWidth>e.clientWidth)}const d=l.get("text-transform")?.[0],g=se(l.get("font-family")?.[0]),h=g?c=>{d==="uppercase"?c=c.toUpperCase():d==="lowercase"?c=c.toLowerCase():d==="capitalize"&&(c=c[0].toUpperCase()+c.substring(1)),g.forEach(p=>{let w=i.get(p);w||i.set(p,w=new Set),c.split("").forEach(b=>w.add(b))})}:void 0;return ft(e,u,m,t,h),lt(e,u),P(e)||await X(e,u,t,h),await o?.(u),u}const f=e.cloneNode(!1);return await X(e,f,t),await o?.(f),f}function ht(e){if(e.ownerDocument=void 0,e.ownerWindow=void 0,e.svgStyleElement=void 0,e.svgDefsElement=void 0,e.svgStyles.clear(),e.defaultComputedStyles.clear(),e.sandbox){try{e.sandbox.remove()}catch(t){e.log.warn("Failed to destroyContext",t)}e.sandbox=void 0}e.workers=[],e.fontFamilies.clear(),e.fontCssTexts.clear(),e.requests.clear(),e.tasks=[],e.shadowRoots=[]}function pt(e){const{url:t,timeout:r,responseType:n,...a}=e,s=new AbortController,i=r?setTimeout(()=>s.abort(),r):void 0;return fetch(t,{signal:s.signal,...a}).then(o=>{if(!o.ok)throw new Error("Failed fetch, not 2xx response",{cause:o});switch(n){case"arrayBuffer":return o.arrayBuffer();case"dataUrl":return o.blob().then(ze);default:return o.text()}}).finally(()=>clearTimeout(i))}function k(e,t){const{url:r,requestType:n="text",responseType:a="text",imageDom:s}=t;let i=r;const{timeout:o,acceptOfImage:f,requests:u,fetchFn:l,fetch:{requestInit:m,bypassingCache:d,placeholderImage:g},font:h,workers:c,fontFamilies:p}=e;n==="image"&&(_||W)&&e.drawImageCount++;let w=u.get(r);if(!w){d&&d instanceof RegExp&&d.test(i)&&(i+=(/\?/.test(i)?"&":"?")+new Date().getTime());const b=n.startsWith("font")&&h&&h.minify,y=new Set;b&&n.split(";")[1].split(",").forEach(I=>{p.has(I)&&p.get(I).forEach(j=>y.add(j))});const S=b&&y.size,v={url:i,timeout:o,responseType:S?"arrayBuffer":a,headers:n==="image"?{accept:f}:void 0,...m};w={type:n,resolve:void 0,reject:void 0,response:null},w.response=(async()=>{if(l&&n==="image"){const C=await l(r);if(C)return C}return!_&&r.startsWith("http")&&c.length?new Promise((C,I)=>{c[u.size&c.length-1].postMessage({rawUrl:r,...v}),w.resolve=C,w.reject=I}):pt(v)})().catch(C=>{if(u.delete(r),n==="image"&&g)return e.log.warn("Failed to fetch image base64, trying to use placeholder image",i),typeof g=="string"?g:g(s);throw C}),u.set(r,w)}return w.response}async function ue(e,t,r,n){if(!fe(e))return e;for(const[a,s]of wt(e,t))try{const i=await k(r,{url:s,requestType:n?"image":"text",responseType:"dataUrl"});e=e.replace(yt(a),`$1${i}$3`)}catch(i){r.log.warn("Failed to fetch css data url",a,i)}return e}function fe(e){return/url\((['"]?)([^'"]+?)\1\)/.test(e)}const de=/url\((['"]?)([^'"]+?)\1\)/g;function wt(e,t){const r=[];return e.replace(de,(n,a,s)=>(r.push([s,ne(s,t)]),n)),r.filter(([n])=>!O(n))}function yt(e){const t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,"g")}const bt=["background-image","border-image-source","-webkit-border-image","-webkit-mask-image","list-style-image"];function St(e,t){return bt.map(r=>{const n=e.getPropertyValue(r);return!n||n==="none"?null:((_||W)&&t.drawImageCount++,ue(n,null,t,!0).then(a=>{!a||n===a||e.setProperty(r,a,e.getPropertyPriority(r))}))}).filter(Boolean)}function Et(e,t){if(A(e)){const r=e.currentSrc||e.src;if(!O(r))return[k(t,{url:r,imageDom:e,requestType:"image",responseType:"dataUrl"}).then(n=>{n&&(e.srcset="",e.dataset.originalSrc=r,e.src=n||"")})];(_||W)&&t.drawImageCount++}else if(F(e)&&!O(e.href.baseVal)){const r=e.href.baseVal;return[k(t,{url:r,imageDom:e,requestType:"image",responseType:"dataUrl"}).then(n=>{n&&(e.dataset.originalSrc=r,e.href.baseVal=n||"")})]}return[]}function Ct(e,t){const{ownerDocument:r,svgDefsElement:n}=t,a=e.getAttribute("href")??e.getAttribute("xlink:href");if(!a)return[];const[s,i]=a.split("#");if(i){const o=`#${i}`,f=t.shadowRoots.reduce((u,l)=>u??l.querySelector(`svg ${o}`),r?.querySelector(`svg ${o}`));if(s&&e.setAttribute("href",o),n?.querySelector(o))return[];if(f)return n?.appendChild(f.cloneNode(!0)),[];if(s)return[k(t,{url:s,responseType:"text"}).then(u=>{n?.insertAdjacentHTML("beforeend",u)})]}return[]}function me(e,t){const{tasks:r}=t;E(e)&&((A(e)||re(e))&&r.push(...Et(e,t)),Fe(e)&&r.push(...Ct(e,t))),R(e)&&r.push(...St(e.style,t)),e.childNodes.forEach(n=>{me(n,t)})}async function vt(e,t){const{ownerDocument:r,svgStyleElement:n,fontFamilies:a,fontCssTexts:s,tasks:i,font:o}=t;if(!(!r||!n||!a.size))if(o&&o.cssText){const f=Y(o.cssText,t);n.appendChild(r.createTextNode(`${f}
`))}else{const f=Array.from(r.styleSheets).filter(g=>{try{return"cssRules"in g&&!!g.cssRules.length}catch(h){return t.log.warn(`Error while reading CSS rules from ${g.href}`,h),!1}}),u=r.implementation.createHTMLDocument(""),l=u.createElement("style");u.head.appendChild(l);const m=l.sheet;await Promise.all(f.flatMap(g=>Array.from(g.cssRules).map(async h=>{if(De(h)){const c=h.href;let p="";try{p=await k(t,{url:c,requestType:"text",responseType:"text"})}catch(b){t.log.warn(`Error fetch remote css import from ${c}`,b)}const w=p.replace(de,(b,y,S)=>b.replace(S,ne(S,c)));for(const b of Tt(w))try{m.insertRule(b,m.cssRules.length)}catch(y){t.log.warn("Error inserting rule from remote css import",{rule:b,error:y})}}}))),m.cssRules.length&&f.push(m);const d=[];f.forEach(g=>{M(g.cssRules,d)}),d.filter(g=>Re(g)&&fe(g.style.getPropertyValue("src"))&&se(g.style.getPropertyValue("font-family"))?.some(h=>a.has(h))).forEach(g=>{const h=g,c=s.get(h.cssText);c?n.appendChild(r.createTextNode(`${c}
`)):i.push(ue(h.cssText,h.parentStyleSheet?h.parentStyleSheet.href:null,t).then(p=>{p=Y(p,t),s.set(h.cssText,p),n.appendChild(r.createTextNode(`${p}
`))}))})}}const Nt=/(\/\*[\s\S]*?\*\/)/g,G=/((@.*?keyframes [\s\S]*?){([\s\S]*?}\s*?)})/gi;function Tt(e){if(e==null)return[];const t=[];let r=e.replace(Nt,"");for(;;){const s=G.exec(r);if(!s)break;t.push(s[0])}r=r.replace(G,"");const n=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,a=new RegExp("((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})","gi");for(;;){let s=n.exec(r);if(s)a.lastIndex=n.lastIndex;else if(s=a.exec(r),s)n.lastIndex=a.lastIndex;else break;t.push(s[0])}return t}const At=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,Rt=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function Y(e,t){const{font:r}=t,n=r?r?.preferredFormat:void 0;return n?e.replace(Rt,a=>{for(;;){const[s,,i]=At.exec(a)||[];if(!i)return"";if(i===n)return`src: ${s};`}}):e}function M(e,t=[]){for(const r of Array.from(e))ke(r)?t.push(...M(r.cssRules)):"cssRules"in r?M(r.cssRules,t):t.push(r);return t}const Dt=/\bx?link:?href\s*=\s*["'](?!data:)[^"']+["']/i;function kt(e){return Dt.test(e.innerHTML)}async function Ft(e,t){const r=await $(e,t);if(E(r.node)&&F(r.node)&&!kt(r.node))return r.node;const{ownerDocument:n,log:a,tasks:s,svgStyleElement:i,svgDefsElement:o,svgStyles:f,font:u,progress:l,autoDestruct:m,onCloneNode:d,onEmbedNode:g,onCreateForeignObjectSvg:h}=r;a.time("clone node");const c=await q(r.node,r,!0);if(i&&n){let S="";f.forEach((v,C)=>{S+=`${v.join(`,
`)} {
${C}
}
`}),i.appendChild(n.createTextNode(S))}a.timeEnd("clone node"),await d?.(c),u!==!1&&E(c)&&(a.time("embed web font"),await vt(c,r),a.timeEnd("embed web font")),a.time("embed node"),me(c,r);const p=s.length;let w=0;const b=async()=>{for(;;){const S=s.pop();if(!S)break;try{await S}catch(v){r.log.warn("Failed to run task",v)}l?.(++w,p)}};l?.(w,p),await Promise.all([...Array.from({length:4})].map(b)),a.timeEnd("embed node"),await g?.(c);const y=It(c,r);return o&&y.insertBefore(o,y.children[0]),i&&y.insertBefore(i,y.children[0]),m&&ht(r),await h?.(y),y}function It(e,t){const{width:r,height:n}=t,a=je(r,n,e.ownerDocument),s=a.ownerDocument.createElementNS(a.namespaceURI,"foreignObject");return s.setAttributeNS(null,"x","0%"),s.setAttributeNS(null,"y","0%"),s.setAttributeNS(null,"width","100%"),s.setAttributeNS(null,"height","100%"),s.append(e),a.appendChild(s),a}async function _t(e,t){const r=await $(e,t),n=await Ft(r),a=He(n,r.isEnable("removeControlCharacter"));r.autoDestruct||(r.svgStyleElement=ae(r.ownerDocument),r.svgDefsElement=r.ownerDocument?.createElementNS(U,"defs"),r.svgStyles.clear());const s=T(a,n.ownerDocument);return await Qe(s,r)}async function Pt(e,t){const r=await $(e,t),{log:n,quality:a,type:s,dpi:i}=r,o=await _t(r);n.time("canvas to data url");let f=o.toDataURL(s,a);if(["image/png","image/jpeg"].includes(s)&&i&&Ne&&Te){const[u,l]=f.split(",");let m=0,d=!1;if(s==="image/png"){const y=Ce(l);y>=0?(m=Math.ceil((y+28)/3)*4,d=!0):m=33/3*4}else s==="image/jpeg"&&(m=18/3*4);const g=l.substring(0,m),h=l.substring(m),c=window.atob(g),p=new Uint8Array(c.length);for(let y=0;y<p.length;y++)p[y]=c.charCodeAt(y);const w=s==="image/png"?ye(p,i,d):ge(p,i),b=window.btoa(String.fromCharCode(...w));f=[u,",",b,h].join("")}return n.timeEnd("canvas to data url"),f}async function xt(e,t){return Pt(await $(e,{...t,type:"image/jpeg"}))}export{Je as createContext,ht as destroyContext,_t as domToCanvas,Pt as domToDataUrl,Ft as domToForeignObjectSvg,xt as domToJpeg,D as loadMedia,Xe as waitUntilLoad};