html2canvas-pro 2.6.0 → 2.6.1

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * html2canvas-pro 2.6.0 <https://yorickshan.github.io/html2canvas-pro/>
2
+ * html2canvas-pro 2.6.1 <https://yorickshan.github.io/html2canvas-pro/>
3
3
  * Copyright (c) 2024-present yorickshan and html2canvas-pro contributors
4
4
  * Released under MIT License
5
5
  */
@@ -7,6 +7,6 @@
7
7
  content: "" !important;
8
8
  display: none !important;
9
9
  }`,as=(e,t)=>{os(e,`.${ns}:before${is}
10
- .${rs}:after${is}`,t)},os=(e,t,n)=>{let r=e.ownerDocument;if(r){let i=r.createElement(`style`);i.textContent=t,n&&(i.nonce=n),e.appendChild(i)}};var ss=class{context;counters;quoteDepth=0;constructor(e,t){this.context=e,this.counters=t}resolvePseudoContent(e,t,n,r){if(!n)return;let i=n.content,a=t.ownerDocument;if(!a||!i||i===`none`||i===`-moz-alt-content`||n.display===`none`)return;this.counters.parse(new Jo(this.context,n));let o=new qo(this.context,n),s=a.createElement(`html2canvaspseudoelement`);ts(n,s),o.content.forEach(t=>{if(t.type===0)s.appendChild(a.createTextNode(t.value));else if(t.type===22){let e=a.createElement(`img`);e.src=t.value,e.style.opacity=`1`,s.appendChild(e)}else if(t.type===18){if(t.name===`attr`){let n=t.values.filter(D);n.length&&n[0]&&s.appendChild(a.createTextNode(e.getAttribute(n[0].value)||``))}else if(t.name===`counter`){let[e,n]=t.values.filter(O);if(e&&D(e)){let t=this.counters.getCounterValue(e.value),r=n&&D(n)?rr.parse(this.context,n.value):3;s.appendChild(a.createTextNode(_r(t,r,!1)))}}else if(t.name===`counters`){let[e,n,r]=t.values.filter(O);if(e&&D(e)){let t=this.counters.getCounterValues(e.value),i=r&&D(r)?rr.parse(this.context,r.value):3,o=n&&n.type===0?n.value:``,c=t.map(e=>_r(e,i,!1)).join(o);s.appendChild(a.createTextNode(c))}}}else if(t.type===20)switch(t.value){case`open-quote`:s.appendChild(a.createTextNode(Er(o.quotes,this.quoteDepth++,!0)));break;case`close-quote`:{let e=this.quoteDepth>0;this.quoteDepth=Math.max(0,this.quoteDepth-1),e&&s.appendChild(a.createTextNode(Er(o.quotes,this.quoteDepth,!1)));break}default:s.appendChild(a.createTextNode(t.value))}}),s.className=`${ns} ${rs}`;let c=r===0?` ${ns}`:` ${rs}`;return Ln(t)?t.className.baseValue+=c:t.className+=c,s}};let q=e=>{if(e?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`)},cs=/* @__PURE__ */ new WeakMap,ls=e=>{let t=e&&e.trustedTypes;if(!t)return null;if(cs.has(t))return cs.get(t)??null;let n=null;try{n=t.getPolicy?.(`html2canvas-pro`)??t.createPolicy(`html2canvas-pro`,{createHTML:e=>e})}catch{n=null}return cs.set(t,n),n},us=(e,t,n)=>{let r=e.createElement(`iframe`);return r.className=`html2canvas-container`,r.style.visibility=`hidden`,r.style.position=`fixed`,r.style.left=`-10000px`,r.style.top=`0px`,r.style.border=`0`,r.width=t.width.toString(),r.height=t.height.toString(),r.scrolling=`no`,r.setAttribute(`data-html2canvas-ignore`,`true`),(n||e.body).appendChild(r),r},ds=e=>new Promise(t=>{e.complete?t():e.src?(e.onload=t,e.onerror=t):t()}),fs=e=>Promise.all([].slice.call(e.images,0).map(ds)),ps=(e,t=0)=>{if(!e||t>ms)return!0;let n;try{n=e.cssRules}catch{return!0}if(!n)return!0;for(let e=0;e<n.length;e++){let r=n[e];if(!r||!(`styleSheet`in r))continue;let i=r.styleSheet;if(!i||!ps(i,t+1))return!1}return!0},ms=32,hs=(e,t)=>{let n=e.querySelectorAll(`link`);for(let e=0;e<n.length;e++){let r=n[e];r&&t.push(r)}let r=(e.ownerDocument??e).createTreeWalker(e,NodeFilter.SHOW_ELEMENT),i=r.nextNode();for(;i;){let e=i.shadowRoot;e&&hs(e,t),i=r.nextNode()}},gs=(e,t,n,r=1e4)=>{if(n?.aborted)return Promise.resolve();let i=[],a=[];hs(e,a);for(let e of a){if(e.sheet)continue;let a=(e.getAttribute(`rel`)??``).trim().toLowerCase().split(/\s+/);a.includes(`stylesheet`)&&!a.includes(`alternate`)&&!e.disabled&&e.getAttribute(`href`)&&i.push(new Promise(i=>{let a=e.href,o=()=>{e.removeEventListener(`load`,o),e.removeEventListener(`error`,o),n?.removeEventListener(`abort`,s),clearInterval(l),i()},s=()=>o();if(e.sheet){i();return}e.addEventListener(`load`,o),e.addEventListener(`error`,o),n?.addEventListener(`abort`,s,{once:!0});let c=0,l=setInterval(()=>{c+=50,e.sheet?o():c>=r&&(t?.warn(`Stylesheet ${a} did not finish loading within ${r/1e3}s; continuing with a possibly unstyled clone`),o())},50)}))}let o=e.getElementsByTagName(`style`);for(let e=0;e<o.length;e++){let n=o[e],a=n?.sheet;a&&n?.textContent?.includes(`@import`)&&(ps(a)||i.push(new Promise(e=>{let i=0,a=setInterval(()=>{i+=50;let o=n.sheet;(o&&ps(o)||i>=r)&&(i>=r&&!ps(o??null)&&t?.warn(`@import chain in an inline <style> did not finish loading within ${r/1e3}s; continuing with a possibly unstyled clone`),clearInterval(a),e())},50)})))}return i.length===0?Promise.resolve():Promise.all(i).then(()=>void 0)},_s=(e,t,n)=>new Promise((r,i)=>{let a=e.contentWindow;if(!a)return i(`No window assigned for iframe`);let o=a.document,s,c=setTimeout(()=>{s&&clearInterval(s),i(/* @__PURE__ */ Error(`Cloned iframe did not fire its load event within ${Lo}ms`))},Lo),l=()=>{s&&clearInterval(s),clearTimeout(c),i(new DOMException(`The operation was aborted.`,`AbortError`))};a.onload=e.onload=()=>{a.onload=e.onload=null;let i=0;s=setInterval(()=>{i++,n?.aborted?l():o.body.childNodes.length>0&&o.readyState===`complete`?(clearInterval(s),s=void 0,clearTimeout(c),r(e)):i>=600&&(clearInterval(s),s=void 0,t?.warn(`Cloned iframe did not become ready within 30 seconds; continuing with a possibly incomplete document`),r(e))},50)},n&&(n.aborted?l():n.addEventListener(`abort`,l,{once:!0}))}),vs=e=>e.replace(/[<>&"'`\\]|[\u0000-\u001f\u007f]/g,``),ys=e=>{let t=``;return e&&(t+=`<!DOCTYPE `,e.name&&(t+=vs(e.name)),e.internalSubset&&(t+=` `+vs(e.internalSubset)),e.publicId?(t+=` PUBLIC "`+vs(e.publicId)+`"`,e.systemId&&(t+=` "`+vs(e.systemId)+`"`)):e.systemId&&(t+=` SYSTEM "`+vs(e.systemId)+`"`),t+=`>`),t},bs=(e,t,n)=>{e&&e.defaultView&&(t!==e.defaultView.pageXOffset||n!==e.defaultView.pageYOffset)&&e.defaultView.scrollTo(t,n)},xs=([e,t,n])=>{e.scrollLeft=t,e.scrollTop=n},Ss=(e,t)=>{let n=e.ownerDocument.createElement(`base`);n.href=t;let r=e.getElementsByTagName(`head`).item(0);r?.insertBefore(n,r?.firstChild??null)},Cs=(e,t,n,r)=>{let i=us(t,n,r.container);if(!i.contentWindow)throw Error(`Unable to find iframe window`);let a=t.defaultView.pageXOffset,o=t.defaultView.pageYOffset,s=i.contentWindow,c=s.document,l=_s(i,e.logger,r.signal).then(async()=>{r.scrolledElements.forEach(xs),s&&s.scrollTo(n.left,n.top);let t=r.onclone,a=r.clonedReferenceElement;if(a===void 0)throw Error(`Error finding the ${r.referenceElementName} in the cloned document`);return q(r.signal),await p,q(r.signal),c.fonts&&c.fonts.ready&&await c.fonts.ready,q(r.signal),/(AppleWebKit)/g.test(navigator.userAgent)&&(await fs(c),q(r.signal)),typeof t==`function`&&await Promise.resolve().then(()=>t(c,a)),s.scrollTo(n.left,n.top),/AppleWebKit/g.test(navigator.userAgent)&&(s.scrollY!==n.top||s.scrollX!==n.left)&&(e.logger.warn(`Unable to restore scroll position for cloned document`),e.adjustWindowBounds(s.scrollX-n.left,s.scrollY-n.top)),i}),u=t.baseURI;c.open();let d=ys(t.doctype)+`<html></html>`;try{let e=ls(t.defaultView),n=e?e.createHTML(d):d;c.write(n)}catch{c.write(d)}bs(t,a,o),c.close();let f=c.adoptNode(r.documentElement);Ss(f,u),c.replaceChild(f,c.documentElement);let p=gs(c,e.logger,r.signal);return l.catch(e=>{throw i.parentNode?.removeChild(i),e})},ws=e=>{let t=e;for(;t;){if(t.parentNode&&t.parentNode.host)return t.parentNode;let e=t.getRootNode();if(e&&e!==t.ownerDocument&&e.host)return e;t=t.parentNode}return null};var Ts=class{context;options;scrolledElements;referenceElement;clonedReferenceElement;documentElement;counters;pseudoContents;slotCloner;constructor(e,t,n){if(this.context=e,this.options=n,this.scrolledElements=[],this.referenceElement=t,this.counters=new ir,this.pseudoContents=new ss(e,this.counters),this.slotCloner=new $o((e,t)=>this.cloneNode(e,t),{ignoreElements:n.ignoreElements,copyStyles:n.copyStyles??!0,cspNonce:n.cspNonce},e),!t.ownerDocument)throw Error(`Cloned element does not have an owner document`);if(!this.options.iframeContainer){let e=ws(t);e&&(this.options.iframeContainer=e)}this.documentElement=this.cloneNode(t.ownerDocument.documentElement,!1),this.appendDocumentAdoptedStyles(t.ownerDocument)}appendDocumentAdoptedStyles(e){if(this.options.copyStyles)return;let t=e.adoptedStyleSheets;if(!t||t.length===0)return;let n=this.documentElement.getElementsByTagName(`head`).item(0);if(!n)return;let r=Qo(this.documentElement.ownerDocument??e,t,this.options.cspNonce);r&&n.appendChild(r)}toIFrame(e,t){return Cs(this.context,e,t,{documentElement:this.documentElement,clonedReferenceElement:this.clonedReferenceElement,referenceElementName:this.referenceElement.nodeName,scrolledElements:this.scrolledElements,onclone:this.options.onclone,container:this.options.iframeContainer,signal:this.options.signal})}createElementClone(e){if(Xo(e,2))debugger;if(Un(e))return this.createCanvasClone(e);if(Wn(e))return this.createVideoClone(e);if(qn(e))return this.createStyleClone(e);let t=e.cloneNode(!1);return Gn(t)&&(Gn(e)&&e.currentSrc&&e.currentSrc!==e.src&&(t.src=e.currentSrc,t.srcset=``),t.loading===`lazy`&&(t.loading=`eager`)),er(t)&&!Ln(t)?this.createCustomElementClone(e,t):t}createCustomElementClone(e,t){let n=document.createElement(`div`);n.className=t.className,ts(t.style,n);let r=t.attributes;for(let e=0;e<r.length;e++){let t=r.item(e);t&&t.name!==`class`&&t.name!==`style`&&n.setAttribute(t.name,t.value)}if(e.shadowRoot)try{n.attachShadow({mode:`open`})}catch(e){this.context.logger.error(`Failed to attach shadow root to custom element clone:`,e)}return n}createStyleClone(e){try{let t=e.sheet;if(t&&t.cssRules){let n=[].slice.call(t.cssRules,0).reduce((e,t)=>t&&typeof t.cssText==`string`?e+t.cssText:e,``),r=e.cloneNode(!1);return r.textContent=n,this.options.cspNonce&&(r.nonce=this.options.cspNonce),r}}catch(e){if(this.context.logger.error(`Unable to access cssRules property`,e),e.name!==`SecurityError`)throw e}let t=e.cloneNode(!1);return this.options.cspNonce&&(t.nonce=this.options.cspNonce),t}createCanvasClone(e){if(this.options.inlineImages&&e.ownerDocument){let t=e.ownerDocument.createElement(`img`);try{return t.src=e.toDataURL(),t}catch{this.context.logger.info(`Unable to inline canvas contents, canvas is tainted`,e)}}let t=e.cloneNode(!1);try{t.width=e.width,t.height=e.height;let n=e.getContext(`2d`),r=t.getContext(`2d`,{willReadFrequently:!0});if(r){if(!this.options.allowTaint&&n)r.putImageData(n.getImageData(0,0,e.width,e.height),0,0);else{let t=e.getContext(`webgl2`)??e.getContext(`webgl`);t&&t.getContextAttributes()?.preserveDrawingBuffer===!1&&this.context.logger.warn(`Unable to clone WebGL context as it has preserveDrawingBuffer=false`,e),r.drawImage(e,0,0)}}return t}catch{this.context.logger.info(`Unable to clone canvas as it is tainted`,e)}return t}createVideoClone(e){let t=e.ownerDocument.createElement(`canvas`);t.width=e.offsetWidth,t.height=e.offsetHeight;let n=t.getContext(`2d`);try{return n&&(n.drawImage(e,0,0,t.width,t.height),this.options.allowTaint||n.getImageData(0,0,t.width,t.height)),t}catch{this.context.logger.info(`Unable to clone video as it is tainted`,e)}let r=e.ownerDocument.createElement(`canvas`);return r.width=e.offsetWidth,r.height=e.offsetHeight,r}appendChildNode(e,t,n){this.slotCloner.appendChildNode(e,t,n)}cloneChildNodes(e,t,n){this.slotCloner.cloneChildNodes(e,t,n)}cloneNode(e,t){if(In(e))return(e.ownerDocument??document).createTextNode(e.data);if(!e.ownerDocument)return e.cloneNode(!1);let n=e.ownerDocument.defaultView;if(n&&Fn(e)&&(Rn(e)||Ln(e))){let r=this.createElementClone(e);r.style.transitionProperty=`none`;let i=n.getComputedStyle(e),a=nr(e);this.referenceElement===e&&Rn(r)&&(this.clonedReferenceElement=r),Hn(r)&&as(r,this.options.cspNonce);let o=this.counters.parse(new Jo(this.context,i));if(a){let t=n.getComputedStyle(e,`:before`),i=this.pseudoContents.resolvePseudoContent(e,r,t,0);i&&r.insertBefore(i,r.firstChild)}if(er(e)&&(t=!0),Wn(e)||this.cloneChildNodes(e,r,t),a){let t=n.getComputedStyle(e,`:after`),i=this.pseudoContents.resolvePseudoContent(e,r,t,1);i&&r.appendChild(i)}return this.counters.pop(o),(i&&(this.options.copyStyles||Ln(e))&&!Kn(e)||t)&&ts(i,r),(e.scrollTop!==0||e.scrollLeft!==0)&&this.scrolledElements.push([r,e.scrollLeft,e.scrollTop]),(Yn(e)||Xn(e))&&(Yn(r)||Xn(r))&&(r.value=e.value),r}return e.cloneNode(!1)}static destroy(e){return e.parentNode?(e.parentNode.removeChild(e),!0):!1}},Es=class{static normalizeElement(e,t){let n={};if(!Rn(e)&&!Ln(e))return n;t.animationDuration.some(e=>e>0)&&(n.animationDuration=e.style.animationDuration,e.style.animationDuration=`0s`),t.transform!==null&&(n.transform=e.style.transform,e.style.transform=`translate(0, 0)`);let r=!1;return t.rotate!==null&&(n.rotate=e.style.rotate,e.style.rotate=`0deg`,r=!0),t.translate!==null&&(n.translate=e.style.translate,e.style.translate=`0px`,r=!0),t.scale!==null&&(n.scale=e.style.scale,e.style.scale=`1`,r=!0),r&&n.transform===void 0&&(n.transform=e.style.transform,e.style.transform=`translate(0, 0)`),n}static restoreElement(e,t){(Rn(e)||Ln(e))&&(t.animationDuration!==void 0&&(e.style.animationDuration=t.animationDuration),t.transform!==void 0&&(e.style.transform=t.transform),t.rotate!==void 0&&(e.style.rotate=t.rotate),t.translate!==void 0&&(e.style.translate=t.translate),t.scale!==void 0&&(e.style.scale=t.scale))}},Ds=class{context;styles;textNodes=[];elements=[];bounds;legendBounds;createsStackingContext=!1;createsRealStackingContext=!1;isListOwner=!1;debugRender=!1;originalStyles;originalElement;constructor(e,t,n={}){if(this.context=e,Xo(t,3))debugger;if(this.styles=new Go(e,e.config.window.getComputedStyle(t,null)),n.normalizeDom!==!1&&(Rn(t)||Ln(t))&&(this.originalStyles=Es.normalizeElement(t,this.styles),this.originalElement=t),this.bounds=o(this.context,t),t.tagName===`FIELDSET`){let e=t.querySelector(`:scope > legend`);if(e){let t=o(this.context,e);this.legendBounds=t;let n=t.top+t.height/2-this.styles.borderTopWidth/2;this.bounds=new a(this.bounds.left,n,this.bounds.width,this.bounds.height-(n-this.bounds.top))}}Xo(t,4)&&(this.debugRender=!0)}restore(){this.originalStyles&&this.originalElement&&(Es.restoreElement(this.originalElement,this.originalStyles),this.originalStyles=void 0,this.originalElement=void 0)}restoreTree(){this.restore();for(let e of this.elements)e.restoreTree()}};let Os=e=>{if(e.createRange){let t=e.createRange();if(t.getBoundingClientRect){let n=e.createElement(`boundtest`);n.style.height=`123px`,n.style.display=`block`,e.body.appendChild(n),t.selectNode(n);let r=t.getBoundingClientRect(),i=Math.round(r.height);if(e.body.removeChild(n),i===123)return!0}}return!1},ks=()=>new Image().crossOrigin!==void 0,As=e=>{let t=new Image,n=e.createElement(`canvas`),r=n.getContext(`2d`);if(!r)return!1;t.src=`data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'></svg>`;try{r.drawImage(t,0,0),n.toDataURL()}catch{return!1}return!0},js=(e,t,n,r,i)=>{let a=`http://www.w3.org/2000/svg`,o=document.createElementNS(a,`svg`),s=document.createElementNS(a,`foreignObject`);return o.setAttributeNS(null,`width`,e.toString()),o.setAttributeNS(null,`height`,t.toString()),s.setAttributeNS(null,`width`,`100%`),s.setAttributeNS(null,`height`,`100%`),s.setAttributeNS(null,`x`,n.toString()),s.setAttributeNS(null,`y`,r.toString()),s.setAttributeNS(null,`externalResourcesRequired`,`true`),o.appendChild(s),s.appendChild(i),o},Ms=e=>new Promise((t,n)=>{let r=new Image;r.onload=()=>t(r),r.onerror=n,r.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(new XMLSerializer().serializeToString(e))}`}),Ns={get SUPPORT_RANGE_BOUNDS(){"use strict";let e=Os(document);return Object.defineProperty(Ns,"SUPPORT_RANGE_BOUNDS",{value:e}),e},get SUPPORT_SVG_DRAWING(){"use strict";let e=As(document);return Object.defineProperty(Ns,"SUPPORT_SVG_DRAWING",{value:e}),e},get SUPPORT_CORS_IMAGES(){"use strict";let e=ks();return Object.defineProperty(Ns,"SUPPORT_CORS_IMAGES",{value:e}),e}};var Ps=class{text;bounds;constructor(e,t){this.text=e,this.bounds=t}};let Fs=(e,t,n,r)=>{let i=Hs(t,n),o=[],s=0;return i.forEach(t=>{if(n.textDecorationLine.length||t.trim().length>0){if(Ns.SUPPORT_RANGE_BOUNDS){let n=Ls(r,s,t.length).getClientRects();if(n.length>1){let n=Bs(t),i=0;n.forEach(t=>{o.push(new Ps(t,a.fromDOMRectList(e,Ls(r,i+s,t.length).getClientRects()))),i+=t.length})}else o.push(new Ps(t,a.fromDOMRectList(e,n)))}else{let n=r.splitText(t.length);o.push(new Ps(t,Is(e,r))),r=n}}else Ns.SUPPORT_RANGE_BOUNDS||(r=r.splitText(t.length));s+=t.length}),o},Is=(e,t)=>{let n=t.ownerDocument;if(n){let r=n.createElement(`html2canvaswrapper`);r.appendChild(t.cloneNode(!0));let i=t.parentNode;if(i){i.replaceChild(r,t);let n=o(e,r);return r.firstChild&&i.replaceChild(r.firstChild,r),n}}return a.EMPTY},Ls=(e,t,n)=>{let r=e.ownerDocument;if(!r)throw Error(`Node has no owner document`);let i=r.createRange();return i.setStart(e,t),i.setEnd(e,t+n),i},Rs=/* @__PURE__ */ new Map,zs=e=>{let t=Rs.get(e);return t||(t=new Intl.Segmenter(void 0,{granularity:e}),Rs.set(e,t)),t},Bs=e=>Array.from(zs(`grapheme`).segment(e),e=>e.segment),Vs=e=>Array.from(zs(`word`).segment(e),e=>e.segment),Hs=(e,t)=>ka(t.writingMode)?Bs(e):t.letterSpacing===0?Vs(e):Bs(e);var Us=class{text;textBounds;constructor(e,t,n){this.text=Ws(t.data,n.textTransform),this.text.length!==t.data.length&&(t.data=this.text),this.textBounds=Fs(e,this.text,n,t)}};let Ws=(e,t)=>{switch(t){case 1:return e.toLowerCase();case 3:return e.replace(Gs,Ks);case 2:return e.toUpperCase();default:return e}},Gs=/(^|\s|:|-|\(|\))([a-z])/g,Ks=(e,t,n)=>e.length>0?t+n.toUpperCase():e;var qs=class extends Ds{src;intrinsicWidth;intrinsicHeight;constructor(e,t,n={}){super(e,t,n),this.src=t.currentSrc||t.src,this.intrinsicWidth=t.naturalWidth,this.intrinsicHeight=t.naturalHeight,this.context.cache.addImage(this.src)}},Js=class extends Ds{canvas;intrinsicWidth;intrinsicHeight;constructor(e,t,n={}){super(e,t,n),this.canvas=t,this.intrinsicWidth=t.width,this.intrinsicHeight=t.height}};let Ys=[`position`,`inset`,`top`,`right`,`bottom`,`left`,`inset-inline`,`inset-inline-start`,`inset-inline-end`,`inset-block`,`inset-block-start`,`inset-block-end`,`margin`,`margin-top`,`margin-right`,`margin-bottom`,`margin-left`,`margin-inline`,`margin-inline-start`,`margin-inline-end`,`margin-block`,`margin-block-start`,`margin-block-end`],Xs=(e,t)=>{let n=t.getAttribute(`style`);Ys.forEach(e=>t.style.removeProperty(e));let r=e.serializeToString(t);return n===null?t.removeAttribute(`style`):t.setAttribute(`style`,n),r};var Zs=class extends Ds{svg;intrinsicWidth;intrinsicHeight;constructor(e,t,n={}){super(e,t,n);let r=new XMLSerializer,i=o(e,t);t.setAttribute(`width`,`${i.width}px`),t.setAttribute(`height`,`${i.height}px`),this.svg=`data:image/svg+xml,${encodeURIComponent(Xs(r,t))}`,this.intrinsicWidth=t.width.baseVal.value,this.intrinsicHeight=t.height.baseVal.value,this.context.cache.addImage(this.svg)}},Qs=class extends Ds{value;constructor(e,t,n={}){super(e,t,n),this.value=t.value}},$s=class extends Ds{start;reversed;constructor(e,t,n={}){super(e,t,n),this.start=t.start,this.reversed=typeof t.reversed==`boolean`&&t.reversed===!0}};let ec=[{type:15,flags:0,unit:`px`,number:3}],tc=[{type:16,flags:0,number:50}],nc=e=>e.width>e.height?new a(e.left+(e.width-e.height)/2,e.top,e.height,e.height):e.width<e.height?new a(e.left,e.top+(e.height-e.width)/2,e.width,e.width):e,rc=e=>{let t=e.type===`password`?Array(e.value.length+1).join(`•`):e.value;return t.length===0?e.placeholder||``:t},ic=e=>e.value.length===0&&!!e.placeholder;var ac=class extends Ds{type;checked;value;isPlaceholder;constructor(e,t,n={}){switch(super(e,t,n),this.type=t.type.toLowerCase(),this.checked=t.checked,this.value=rc(t),this.isPlaceholder=ic(t),(this.type===`checkbox`||this.type===`radio`)&&(this.styles.backgroundColor=3739148031,this.styles.borderTopColor=this.styles.borderRightColor=this.styles.borderBottomColor=this.styles.borderLeftColor=2779096575,this.styles.borderTopWidth=this.styles.borderRightWidth=this.styles.borderBottomWidth=this.styles.borderLeftWidth=1,this.styles.borderTopStyle=this.styles.borderRightStyle=this.styles.borderBottomStyle=this.styles.borderLeftStyle=1,this.styles.backgroundClip=[0],this.styles.backgroundOrigin=[0],this.bounds=nc(this.bounds)),this.type){case`checkbox`:this.styles.borderTopRightRadius=this.styles.borderTopLeftRadius=this.styles.borderBottomRightRadius=this.styles.borderBottomLeftRadius=ec;break;case`radio`:this.styles.borderTopRightRadius=this.styles.borderTopLeftRadius=this.styles.borderBottomRightRadius=this.styles.borderBottomLeftRadius=tc}}},oc=class extends Ds{value;constructor(e,t,n={}){super(e,t,n);let r=t.options[t.selectedIndex||0];this.value=r&&r.text||``}},sc=class extends Ds{value;constructor(e,t,n={}){super(e,t,n),this.value=t.value}},cc=class extends Ds{src;width;height;tree;backgroundColor;parseTreeFn;constructor(e,t,n,r={}){super(e,t,r),this.src=t.src,this.width=parseInt(t.width,10)||0,this.height=parseInt(t.height,10)||0,this.backgroundColor=this.styles.backgroundColor,this.parseTreeFn=n;try{let n=t.contentWindow,r=n?.document;if(n&&r&&r.documentElement&&this.parseTreeFn){this.tree=this.parseTreeFn(e,r.documentElement);let t=Nn(e,n.getComputedStyle(r.documentElement).backgroundColor),i=r.body?Nn(e,n.getComputedStyle(r.body).backgroundColor):0;this.backgroundColor=R(t)?R(i)?this.styles.backgroundColor:i:t}}catch(e){let t=e instanceof Error?e:Error(String(e));this.context.logger.warn(`Unable to render iframe content${this.src?` from ${this.src}`:``}: ${t.message}`),this.context.onError?.(t)}}};let lc=[`OL`,`UL`,`MENU`],uc=(e,t,n,r,i=1,a={})=>{for(let o=t.firstChild,s;o;o=s)s=o.nextSibling,dc(e,o,n,r,i,a)},dc=(e,t,n,r,i=1,o={})=>{if(In(t)&&t.data.length>0){let r=new Us(e,t,n.styles);if(i!==1){let e=n.bounds.left,t=n.bounds.top;r.textBounds=r.textBounds.map(n=>new Ps(n.text,new a(e+(n.bounds.left-e)/i,t+(n.bounds.top-t)/i,n.bounds.width/i,n.bounds.height/i)))}n.textNodes.push(r)}else if(Fn(t)){if(Zn(t)&&t.assignedNodes)t.assignedNodes().forEach(t=>dc(e,t,n,r,i,o));else{let s=fc(e,t,o),c=s.styles.zoom||1;if(c!==1&&(s.bounds=new a(s.bounds.left,s.bounds.top,s.bounds.width/c,s.bounds.height/c)),s.styles.isVisible()){mc(t,s,r)?s.createsRealStackingContext=!0:hc(s.styles)&&(s.createsStackingContext=!0),lc.indexOf(t.tagName)!==-1&&(s.isListOwner=!0),n.elements.push(s);let a=i*(s.styles.zoom||1);t.shadowRoot?uc(e,t.shadowRoot,s,r,a,o):!Yn(t)&&!Vn(t)&&!Xn(t)&&uc(e,t,s,r,a,o)}}}},fc=(e,t,n={})=>Gn(t)?new qs(e,t,n):Un(t)?new Js(e,t,n):Vn(t)?new Zs(e,t,n):Qn(t)?new Qs(e,t,n):$n(t)?new $s(e,t,n):zn(t)?new ac(e,t,n):Xn(t)?new oc(e,t,n):Yn(t)?new sc(e,t,n):Kn(t)?new cc(e,t,(e,t)=>pc(e,t,n),n):new Ds(e,t,n),pc=(e,t,n={})=>{let r=fc(e,t,n);return r.createsRealStackingContext=!0,uc(e,t,r,r,1,n),r},mc=(e,t,n)=>t.styles.isPositionedWithZIndex()||t.styles.opacity<1||!!t.styles.filter||!!t.styles.backdropFilter||t.styles.maskImage.length>0||!!t.styles.webkitBoxReflect||t.styles.isolation===1||t.styles.isTransformed()||Hn(e)&&n.styles.isTransparent(),hc=e=>e.isPositioned()||e.isFloating()||e.mixBlendMode!==K.NORMAL?!0:H(e.display,268435456)||H(e.display,33554432)||H(e.display,536870912)||H(e.display,134217728),gc=(e,t)=>e.length===t.length&&e.some((e,n)=>e===t[n]),_c=(e,t,n,r,i)=>e.map((e,a)=>{switch(a){case 0:return e.add(t,n);case 1:return e.add(t+r,n);case 2:return e.add(t+r,n+i);case 3:return e.add(t,n+i)}return e});var J=class e{type;x;y;constructor(e,t){this.type=0,this.x=e,this.y=t}add(t,n){return new e(this.x+t,this.y+n)}};let vc=(e,t,n)=>new J(e.x+(t.x-e.x)*n,e.y+(t.y-e.y)*n);var yc=class e{type;start;startControl;endControl;end;constructor(e,t,n,r){this.type=1,this.start=e,this.startControl=t,this.endControl=n,this.end=r}subdivide(t,n){let r=vc(this.start,this.startControl,t),i=vc(this.startControl,this.endControl,t),a=vc(this.endControl,this.end,t),o=vc(r,i,t),s=vc(i,a,t),c=vc(o,s,t);return n?new e(this.start,r,o,c):new e(c,s,a,this.end)}add(t,n){return new e(this.start.add(t,n),this.startControl.add(t,n),this.endControl.add(t,n),this.end.add(t,n))}reverse(){return new e(this.end,this.endControl,this.startControl,this.start)}};let Y=e=>e.type===1;var bc=class{topLeftBorderDoubleOuterBox;topRightBorderDoubleOuterBox;bottomRightBorderDoubleOuterBox;bottomLeftBorderDoubleOuterBox;topLeftBorderDoubleInnerBox;topRightBorderDoubleInnerBox;bottomRightBorderDoubleInnerBox;bottomLeftBorderDoubleInnerBox;topLeftBorderStroke;topRightBorderStroke;bottomRightBorderStroke;bottomLeftBorderStroke;topLeftBorderBox;topRightBorderBox;bottomRightBorderBox;bottomLeftBorderBox;topLeftPaddingBox;topRightPaddingBox;bottomRightPaddingBox;bottomLeftPaddingBox;topLeftContentBox;topRightContentBox;bottomRightContentBox;bottomLeftContentBox;constructor(e){let t=e.styles,n=e.bounds,[r,i]=He(t.borderTopLeftRadius,n.width,n.height),[a,o]=He(t.borderTopRightRadius,n.width,n.height),[s,c]=He(t.borderBottomRightRadius,n.width,n.height),[l,u]=He(t.borderBottomLeftRadius,n.width,n.height),d=[];d.push((r+a)/n.width),d.push((l+s)/n.width),d.push((i+u)/n.height),d.push((o+c)/n.height);let f=Math.max(...d);f>1&&(r/=f,i/=f,a/=f,o/=f,s/=f,c/=f,l/=f,u/=f);let p=n.width-a,m=n.height-c,h=n.width-s,g=n.height-u,_=t.borderTopWidth,v=t.borderRightWidth,y=t.borderBottomWidth,b=t.borderLeftWidth,x=I(t.paddingTop,e.bounds.width),S=I(t.paddingRight,e.bounds.width),C=I(t.paddingBottom,e.bounds.width),w=I(t.paddingLeft,e.bounds.width);this.topLeftBorderDoubleOuterBox=r>0||i>0?X(n.left+b/3,n.top+_/3,r-b/3,i-_/3,0):new J(n.left+b/3,n.top+_/3),this.topRightBorderDoubleOuterBox=a>0||o>0?X(n.left+p,n.top+_/3,a-v/3,o-_/3,1):new J(n.left+n.width-v/3,n.top+_/3),this.bottomRightBorderDoubleOuterBox=s>0||c>0?X(n.left+h,n.top+m,s-v/3,c-y/3,2):new J(n.left+n.width-v/3,n.top+n.height-y/3),this.bottomLeftBorderDoubleOuterBox=l>0||u>0?X(n.left+b/3,n.top+g,l-b/3,u-y/3,3):new J(n.left+b/3,n.top+n.height-y/3),this.topLeftBorderDoubleInnerBox=r>0||i>0?X(n.left+b*2/3,n.top+_*2/3,r-b*2/3,i-_*2/3,0):new J(n.left+b*2/3,n.top+_*2/3),this.topRightBorderDoubleInnerBox=a>0||o>0?X(n.left+p,n.top+_*2/3,a-v*2/3,o-_*2/3,1):new J(n.left+n.width-v*2/3,n.top+_*2/3),this.bottomRightBorderDoubleInnerBox=s>0||c>0?X(n.left+h,n.top+m,s-v*2/3,c-y*2/3,2):new J(n.left+n.width-v*2/3,n.top+n.height-y*2/3),this.bottomLeftBorderDoubleInnerBox=l>0||u>0?X(n.left+b*2/3,n.top+g,l-b*2/3,u-y*2/3,3):new J(n.left+b*2/3,n.top+n.height-y*2/3),this.topLeftBorderStroke=r>0||i>0?X(n.left+b/2,n.top+_/2,r-b/2,i-_/2,0):new J(n.left+b/2,n.top+_/2),this.topRightBorderStroke=a>0||o>0?X(n.left+p,n.top+_/2,a-v/2,o-_/2,1):new J(n.left+n.width-v/2,n.top+_/2),this.bottomRightBorderStroke=s>0||c>0?X(n.left+h,n.top+m,s-v/2,c-y/2,2):new J(n.left+n.width-v/2,n.top+n.height-y/2),this.bottomLeftBorderStroke=l>0||u>0?X(n.left+b/2,n.top+g,l-b/2,u-y/2,3):new J(n.left+b/2,n.top+n.height-y/2),this.topLeftBorderBox=r>0||i>0?X(n.left,n.top,r,i,0):new J(n.left,n.top),this.topRightBorderBox=a>0||o>0?X(n.left+p,n.top,a,o,1):new J(n.left+n.width,n.top),this.bottomRightBorderBox=s>0||c>0?X(n.left+h,n.top+m,s,c,2):new J(n.left+n.width,n.top+n.height),this.bottomLeftBorderBox=l>0||u>0?X(n.left,n.top+g,l,u,3):new J(n.left,n.top+n.height),this.topLeftPaddingBox=r>0||i>0?X(n.left+b,n.top+_,Math.max(0,r-b),Math.max(0,i-_),0):new J(n.left+b,n.top+_),this.topRightPaddingBox=a>0||o>0?X(n.left+Math.min(p,n.width-v),n.top+_,p>n.width+v?0:Math.max(0,a-v),Math.max(0,o-_),1):new J(n.left+n.width-v,n.top+_),this.bottomRightPaddingBox=s>0||c>0?X(n.left+Math.min(h,n.width-b),n.top+Math.min(m,n.height-y),Math.max(0,s-v),Math.max(0,c-y),2):new J(n.left+n.width-v,n.top+n.height-y),this.bottomLeftPaddingBox=l>0||u>0?X(n.left+b,n.top+Math.min(g,n.height-y),Math.max(0,l-b),Math.max(0,u-y),3):new J(n.left+b,n.top+n.height-y),this.topLeftContentBox=r>0||i>0?X(n.left+b+w,n.top+_+x,Math.max(0,r-(b+w)),Math.max(0,i-(_+x)),0):new J(n.left+b+w,n.top+_+x),this.topRightContentBox=a>0||o>0?X(n.left+Math.min(p,n.width+b+w),n.top+_+x,p>n.width+b+w?0:a-b+w,o-(_+x),1):new J(n.left+n.width-(v+S),n.top+_+x),this.bottomRightContentBox=s>0||c>0?X(n.left+Math.min(h,n.width-(b+w)),n.top+Math.min(m,n.height+_+x),Math.max(0,s-(v+S)),c-(y+C),2):new J(n.left+n.width-(v+S),n.top+n.height-(y+C)),this.bottomLeftContentBox=l>0||u>0?X(n.left+b+w,n.top+g,Math.max(0,l-(b+w)),u-(y+C),3):new J(n.left+b+w,n.top+n.height-(y+C))}};let X=(e,t,n,r,i)=>{let a=4*((Math.sqrt(2)-1)/3),o=n*a,s=r*a,c=e+n,l=t+r;switch(i){case 0:return new yc(new J(e,l),new J(e,l-s),new J(c-o,t),new J(c,t));case 1:return new yc(new J(e,t),new J(e+o,t),new J(c,l-s),new J(c,l));case 2:return new yc(new J(c,t),new J(c,t+s),new J(e+o,l),new J(e,l));default:return new yc(new J(c,l),new J(c-o,l),new J(e,t+s),new J(e,t))}},xc=e=>[e.topLeftBorderBox,e.topRightBorderBox,e.bottomRightBorderBox,e.bottomLeftBorderBox],Sc=e=>[e.topLeftContentBox,e.topRightContentBox,e.bottomRightContentBox,e.bottomLeftContentBox],Cc=e=>[e.topLeftPaddingBox,e.topRightPaddingBox,e.bottomRightPaddingBox,e.bottomLeftPaddingBox];var wc=class{offsetX;offsetY;matrix;type=0;target=6;constructor(e,t,n){this.offsetX=e,this.offsetY=t,this.matrix=n}},Tc=class{path;target;type=1;constructor(e,t){this.path=e,this.target=t}},Ec=class{opacity;type=2;target=6;constructor(e){this.opacity=e}},Dc=class{applyClip;type=3;target=6;constructor(e){this.applyClip=e}};let Oc={[K.NORMAL]:`source-over`,[K.MULTIPLY]:`multiply`,[K.SCREEN]:`screen`,[K.OVERLAY]:`overlay`,[K.DARKEN]:`darken`,[K.LIGHTEN]:`lighten`,[K.COLOR_DODGE]:`color-dodge`,[K.COLOR_BURN]:`color-burn`,[K.HARD_LIGHT]:`hard-light`,[K.SOFT_LIGHT]:`soft-light`,[K.DIFFERENCE]:`difference`,[K.EXCLUSION]:`exclusion`,[K.HUE]:`hue`,[K.SATURATION]:`saturation`,[K.COLOR]:`color`,[K.LUMINOSITY]:`luminosity`};var kc=class{mixBlendMode;type=4;target=6;compositeOperation;constructor(e){this.mixBlendMode=e,this.compositeOperation=Oc[e]}},Ac=class e{type=5;target=6;safeFilterString;shadow;constructor(t){let n=e.parseDropShadow(t);this.shadow=n.shadow,this.safeFilterString=n.safeFilterString}static parseDropShadow(t){if(!t)return{safeFilterString:``};let n=e.findDropShadows(t);if(n.length===0)return{safeFilterString:t};let r=e.parseDropShadowBody(c(n,0).body),i=``,a=0;for(let e of n)i+=t.slice(a,e.start),a=e.end;return i+=t.slice(a),{shadow:r,safeFilterString:i.replace(/\s+/g,` `).trim()}}static findDropShadows(e){let t=[],n=/drop-shadow\(/gi,r;for(;(r=n.exec(e))!==null;){let n=r.index+12-1,i=r.index,a=1,o=n+1;for(;o<e.length&&a>0;){let t=e[o]??``;t===`(`?a++:t===`)`&&a--,o++}if(a!==0)break;let s=e.slice(n+1,o-1);t.push({body:s,start:i,end:o})}return t}static parseDropShadowBody(t){let n=e.tokenizeFilterArgs(t.trim()),r=[],i;for(let t of n)e.isCSSLength(t)?r.push(parseFloat(t)):t&&(i=t);if(!(r.length<2||r.length>3))return{offsetX:c(r,0),offsetY:c(r,1),blur:r.length>2?c(r,2):0,color:i??`rgba(0,0,0,1)`}}static tokenizeFilterArgs(e){let t=[],n=``,r=0;for(let i=0;i<e.length;i++){let a=e[i]??``;a===`(`?(r++,n+=a):a===`)`?(r--,n+=a):/\s/.test(a)?r>0?n+=a:n&&=(t.push(n),``):n+=a}return n&&t.push(n),t}static isCSSLength(e){return/^-?[\d.]+(px|em|rem|pt|cm|mm|in|pc|ex|ch|vw|vh|vmin|vmax|%)?$/i.test(e)}};let jc=e=>e.type===0,Mc=e=>e.type===1,Nc=e=>e.type===2,Pc=e=>e.type===3,Fc=e=>e.type===4,Ic=e=>e.type===5;var Lc=class{element;negativeZIndex;zeroOrAutoZIndexOrTransformedOrOpacity;positiveZIndex;nonPositionedFloats;nonPositionedInlineLevel;inlineLevel;nonInlineLevel;constructor(e){this.element=e,this.inlineLevel=[],this.nonInlineLevel=[],this.negativeZIndex=[],this.zeroOrAutoZIndexOrTransformedOrOpacity=[],this.positiveZIndex=[],this.nonPositionedFloats=[],this.nonPositionedInlineLevel=[]}},Rc=class{container;parent;effects=[];curves;listValue;plainEffectsCache=null;constructor(e,t){if(this.container=e,this.parent=t,this.curves=new bc(this.container),this.container.styles.opacity<1&&this.effects.push(new Ec(this.container.styles.opacity)),this.container.styles.translate!==null){let e=this.container.styles.transformOrigin,t=this.container.bounds.left+I(e[0],this.container.bounds.width),n=this.container.bounds.top+I(e[1],this.container.bounds.height),[r,i]=this.container.styles.translate,a=I(r,this.container.bounds.width),o=I(i,this.container.bounds.height);this.effects.push(new wc(t,n,[1,0,0,1,a,o]))}if(this.container.styles.rotate!==null){let e=this.container.styles.transformOrigin,t=this.container.bounds.left+I(e[0],this.container.bounds.width),n=this.container.bounds.top+I(e[1],this.container.bounds.height),r=this.container.styles.rotate*Math.PI/180,i=Math.cos(r),a=Math.sin(r),o=[i,a,-a,i,0,0];this.effects.push(new wc(t,n,o))}if(this.container.styles.scale!==null){let e=this.container.styles.transformOrigin,t=this.container.bounds.left+I(e[0],this.container.bounds.width),n=this.container.bounds.top+I(e[1],this.container.bounds.height),[r,i]=this.container.styles.scale;this.effects.push(new wc(t,n,[r,0,0,i,0,0]))}if(this.container.styles.transform!==null){let e=this.container.styles.transformOrigin,t=this.container.bounds.left+I(e[0],this.container.bounds.width),n=this.container.bounds.top+I(e[1],this.container.bounds.height),r=this.container.styles.transform;this.effects.push(new wc(t,n,r))}if(zc(this.container.styles)){let e=xc(this.curves),t=Cc(this.curves);gc(e,t)?this.effects.push(new Tc(e,6)):(this.effects.push(new Tc(e,2)),this.effects.push(new Tc(t,4)))}if(this.container.styles.clipPath.type!==0){let e=Vc(this.container.styles.clipPath,this.container.bounds);e&&this.effects.push(e)}if(this.container.styles.mixBlendMode!==K.NORMAL&&this.effects.push(new kc(this.container.styles.mixBlendMode)),this.container.styles.filter!==null&&this.effects.push(new Ac(this.container.styles.filter)),this.container.styles.zoom!==1){let e=this.container.bounds.left,t=this.container.bounds.top,n=this.container.styles.zoom,r=[n,0,0,n,0,0];this.effects.push(new wc(e,t,r))}}getEffects(e,t){if(!t){let t=this.plainEffectsCache;t||(t=/* @__PURE__ */ new Map,this.plainEffectsCache=t);let n=t.get(e);return n||(n=this.computeEffects(e),t.set(e,n)),n}return this.computeEffects(e,t)}computeEffects(e,t){let n=[2,3].indexOf(this.container.styles.position)===-1,r=this===t?null:this.parent,i=e=>e.effects.filter(n=>e!==t||!Ic(n)&&!Nc(n)&&!Fc(n)),a=i(this);for(;r;){let e=i(r).filter(e=>!Mc(e));if(n||r.container.styles.position!==0||!r.parent){if(n=[2,3].indexOf(r.container.styles.position)===-1,zc(r.container.styles)){let e=xc(r.curves),t=Cc(r.curves);gc(e,t)||a.unshift(new Tc(t,6))}a.unshift(...e)}else a.unshift(...e);r=r===t?null:r.parent}return a.filter(t=>H(t.target,e))}};let zc=e=>e.overflowX!==0||e.overflowY!==0,Bc=(e,t,n,r,i)=>e===`closest-side`?Math.min(t-n,r-t):e===`farthest-side`?Math.max(t-n,r-t):I(e,i),Vc=(e,t)=>{let{left:n,top:r,width:i,height:a}=t;switch(e.type){case 1:{let t=I(e.left,i),o=I(e.top,a),s=n+t,c=r+o,l=Math.max(0,i-t-I(e.right,i)),u=Math.max(0,a-o-I(e.bottom,a));return new Dc(e=>{e.beginPath(),e.rect(s,c,l,u),e.clip()})}case 2:{let t=n+I(e.cx,i),o=r+I(e.cy,a),s;return s=e.radius===`closest-side`?Math.min(t-n,o-r,n+i-t,r+a-o):e.radius===`farthest-side`?Math.max(t-n,o-r,n+i-t,r+a-o):I(e.radius,Math.sqrt(i*i+a*a)/Math.SQRT2),new Dc(e=>{e.beginPath(),e.arc(t,o,Math.max(0,s),0,Math.PI*2),e.clip()})}case 3:{let t=n+I(e.cx,i),o=r+I(e.cy,a),s=Bc(e.rx,t,n,n+i,i),c=Bc(e.ry,o,r,r+a,a);return new Dc(e=>{e.beginPath(),e.ellipse(t,o,Math.max(0,s),Math.max(0,c),0,0,Math.PI*2),e.clip()})}case 4:{let t=e.points.map(([e,t])=>[n+I(e,i),r+I(t,a)]);return new Dc(e=>{if(e.beginPath(),t.length>0){e.moveTo(c(c(t,0),0),c(c(t,0),1));for(let n=1;n<t.length;n++)e.lineTo(c(c(t,n),0),c(c(t,n),1));e.closePath()}e.clip()})}case 5:{let{d:t}=e,i=null;return new Dc(e=>{try{i||=new Path2D(t);let a=e.getTransform();e.translate(n,r),e.clip(i),e.setTransform(a)}catch{}})}case 6:{let t=n+I(e.x,i),o=r+I(e.y,a),s=Math.max(0,I(e.width,i)),c=Math.max(0,I(e.height,a));return new Dc(e=>{e.beginPath(),e.rect(t,o,s,c),e.clip()})}case 0:return null;default:return null}},Hc=(e,t,n,r)=>{e.container.elements.forEach(i=>{let a=i.createsRealStackingContext,o=i.createsStackingContext,s=new Rc(i,e);H(i.styles.display,2048)&&r.push(s);let c=i.isListOwner?[]:r;if(a||o){let e=a||i.styles.isPositioned()?n:t,r=new Lc(s);if(a||i.styles.isPositioned()||i.styles.opacity<1||i.styles.isTransformed()){let t=i.styles.zIndex.order;if(t<0){let n=0;e.negativeZIndex.some((e,r)=>t>=e.element.container.styles.zIndex.order?(n=r+1,!1):n>0),e.negativeZIndex.splice(n,0,r)}else if(t>0){let n=0;e.positiveZIndex.some((e,r)=>t>=e.element.container.styles.zIndex.order?(n=r+1,!1):n>0),e.positiveZIndex.splice(n,0,r)}else e.zeroOrAutoZIndexOrTransformedOrOpacity.push(r)}else i.styles.isFloating()?e.nonPositionedFloats.push(r):e.nonPositionedInlineLevel.push(r);Hc(s,r,a?r:n,c)}else i.styles.isInlineLevel()?t.inlineLevel.push(s):t.nonInlineLevel.push(s),Hc(s,t,n,c);i.isListOwner&&Uc(i,c)})},Uc=(e,t)=>{let n=e instanceof $s?e.start:1,r=e instanceof $s&&e.reversed;for(let e=0;e<t.length;e++){let i=c(t,e);i.container instanceof Qs&&typeof i.container.value==`number`&&i.container.value!==0&&(n=i.container.value),i.listValue=_r(n,i.container.styles.listStyleType,!0),n+=r?-1:1}},Wc=e=>{let t=new Rc(e,null),n=new Lc(t),r=[];return Hc(t,n,n,r),Uc(t.container,r),n},Gc=e=>Math.min(1,Math.max(0,e)),Kc=e=>{let t=c(e,0),n=c(e,e.length-1);if(n.stop-t.stop<1e-6)return null;let r=Math.max(n.stop-t.stop,.01),i=[],a=Math.ceil(1/r);for(let n=0;n<a;n++)for(let a of e){let e=n*r+(a.stop-t.stop);if(e>1)break;i.push({stop:e,color:z(a.color)})}let o=i[i.length-1];return(!o||o.stop<1)&&i.push({stop:1,color:z(n.color)}),i},qc=e=>e.map(e=>({stop:Gc(e.stop),color:z(e.color)})),Jc=(e,t,n,r,i=!1)=>{let a=W(r,t),o=c(a,a.length-1),s=z(o.color),l=e.createElement(`canvas`);l.width=Math.max(1,Math.ceil(t*2)),l.height=Math.max(1,Math.ceil(n*2));let u=l.getContext(`2d`);if(!u)return null;let d;if(i){let e=Kc(a);if(!e)return u.fillStyle=s,u.fillRect(0,0,l.width,l.height),{canvas:l,lastColor:s,rx:t,ry:n};d=e}else d=qc(a);let f=u.createRadialGradient(t,t,0,t,t,t);return d.forEach(e=>f.addColorStop(Gc(e.stop),e.color)),u.fillStyle=f,t!==n&&u.scale(1,n/t),u.fillRect(0,0,t*2,t*2),{canvas:l,lastColor:s,rx:t,ry:n}},Yc=e=>{let t=e.bounds,n=e.styles;return t.add(n.borderLeftWidth,n.borderTopWidth,-(n.borderRightWidth+n.borderLeftWidth),-(n.borderTopWidth+n.borderBottomWidth))},Xc=e=>{let t=e.styles,n=e.bounds,r=I(t.paddingLeft,n.width),i=I(t.paddingRight,n.width),a=I(t.paddingTop,n.width),o=I(t.paddingBottom,n.width);return n.add(r+t.borderLeftWidth,a+t.borderTopWidth,-(t.borderRightWidth+t.borderLeftWidth+r+i),-(t.borderTopWidth+t.borderBottomWidth+a+o))},Zc=(e,t)=>e===0?t.bounds:e===2?Xc(t):Yc(t),Qc=(e,t)=>e===0?t.bounds:e===2?Xc(t):Yc(t),$c=(e,t,n)=>{let r=Zc(rl(e.styles.backgroundOrigin,t),e),i=Qc(rl(e.styles.backgroundClip,t),e),a=nl(rl(e.styles.backgroundSize,t),n,r),[o,s]=a,c=He(rl(e.styles.backgroundPosition,t),r.width-o,r.height-s),l=il(rl(e.styles.backgroundRepeat,t),c,a,r,i),u=Math.round(r.left+c[0]),d=Math.round(r.top+c[1]);return o=Math.max(1,o),s=Math.max(1,s),[l,u,d,o,s]},el=e=>D(e)&&e.value===`auto`,tl=e=>typeof e==`number`,nl=(e,[t,n,r],i)=>{let[a,o]=e;if(!a)return[0,0];if(M(a)&&o&&M(o))return[I(a,i.width),I(o,i.height)];let s=tl(r);if(D(a)&&(a.value===`contain`||a.value===`cover`))return tl(r)?i.width/i.height<r==(a.value===`cover`)?[i.height*r,i.height]:[i.width,i.width/r]:[i.width,i.height];let c=tl(t),l=tl(n),u=c||l;if(el(a)&&(!o||el(o)))return c&&l?[t,n]:!s&&!u?[i.width,i.height]:u&&s?[c?t:n*r,l?n:t/r]:[c?t:i.width,l?n:i.height];if(s){let e=0,t=0;return M(a)?e=I(a,i.width):o&&M(o)&&(t=I(o,i.height)),el(a)?e=t*r:(!o||el(o))&&(t=e/r),[e,t]}let d=null,f=null;if(M(a)?d=I(a,i.width):o&&M(o)&&(f=I(o,i.height)),d!==null&&(!o||el(o))&&(f=c&&l?d/t*n:i.height),f!==null&&el(a)&&(d=c&&l?f/n*t:i.width),d!==null&&f!==null)return[d,f];throw Error(`Unable to calculate background-size for element`)},rl=(e,t)=>{let n=e[t];return n===void 0?c(e,0):n},il=(e,[t,n],[r,i],a,o)=>{switch(e){case 2:return[new J(Math.round(a.left),Math.round(a.top+n)),new J(Math.round(a.left+a.width),Math.round(a.top+n)),new J(Math.round(a.left+a.width),Math.round(i+a.top+n)),new J(Math.round(a.left),Math.round(i+a.top+n))];case 3:return[new J(Math.round(a.left+t),Math.round(a.top)),new J(Math.round(a.left+t+r),Math.round(a.top)),new J(Math.round(a.left+t+r),Math.round(a.height+a.top)),new J(Math.round(a.left+t),Math.round(a.height+a.top))];case 1:return[new J(Math.round(a.left+t),Math.round(a.top+n)),new J(Math.round(a.left+t+r),Math.round(a.top+n)),new J(Math.round(a.left+t+r),Math.round(a.top+n+i)),new J(Math.round(a.left+t),Math.round(a.top+n+i))];default:return[new J(Math.round(o.left),Math.round(o.top)),new J(Math.round(o.left+o.width),Math.round(o.top)),new J(Math.round(o.left+o.width),Math.round(o.height+o.top)),new J(Math.round(o.left),Math.round(o.height+o.top))]}};var Z=class extends Error{};let Q=e=>{e.width=e.height=0},al=[`brightness`,`contrast`,`grayscale`,`hue-rotate`,`invert`,`opacity`,`saturate`,`sepia`],ol=/* @__PURE__ */ new Map,sl={functions:[]};function cl(e){if(!e||e===`none`)return sl;let t=ol.get(e);if(t!==void 0)return ol.delete(e),ol.set(e,t),t;let n=ll(e);if(ol.size>=256){let e=ol.keys().next().value;e!==void 0&&ol.delete(e)}return ol.set(e,n),n}let ll=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r===` `||r===`
11
- `||r===` `){n++;continue}let i=e.indexOf(`(`,n);if(i===-1)return null;let a=e.slice(n,i).trim();if(!/^[a-zA-Z-]+$/.test(a))return null;let o=ul(e,i);if(o===-1)return null;let s=fl(a,e.slice(i+1,o).trim());if(!s)return null;t.push(s),n=o+1}return{functions:t}},ul=(e,t)=>{let n=1;for(let r=t+1;r<e.length;r++){let t=e[r];if(t===`(`)n++;else if(t===`)`&&(n--,n===0))return r}return-1},dl=/^-?\d+(?:\.\d+)?px$/,fl=(e,t)=>{if(e===`blur`){if(t===`0`)return{kind:`blur`,value:0};if(!dl.test(t))return null;let e=Number.parseFloat(t);return e<0?null:{kind:`blur`,value:e}}if(e===`drop-shadow`)return ml(t);if(al.indexOf(e)!==-1){let n=e;if(n===`hue-rotate`){let e=hl(t);return e===null?null:{kind:`unitless`,name:n,value:e}}let r=t.trim(),i=r.endsWith(`%`),a=i?r.slice(0,-1):r;return/^-?\d+(?:\.\d+)?$/.test(a)?{kind:`unitless`,name:n,value:Number.parseFloat(a)*(i?1/100:1)}:null}return null},pl=e=>{let t=[],n=0,r=``;for(let i of e)i===`(`?n++:i===`)`&&n--,i===` `&&n===0?(r&&t.push(r),r=``):r+=i;return r&&t.push(r),t},ml=e=>{let t=pl(e),n=t.filter(e=>dl.test(e)).map(e=>Number.parseFloat(e));if(n.length<2||n.length>3)return null;let r=t.filter(e=>!dl.test(e));return t.length-r.length===n.length?{kind:`drop-shadow`,x:n[0],y:n[1],blur:n[2]??0,color:r.join(` `)||`rgba(0, 0, 0, 0)`}:null},hl=e=>{let t=e.trim();if(t===`0`)return 0;let n=Number.parseFloat(t);return Number.isNaN(n)?null:t.endsWith(`deg`)?n:t.endsWith(`grad`)?n*.9:t.endsWith(`rad`)?n*180/Math.PI:t.endsWith(`turn`)?n*360:null},gl=(e,t)=>e.functions.map(e=>{switch(e.kind){case`blur`:return`blur(${e.value*t}px)`;case`drop-shadow`:return`drop-shadow(${e.x*t}px ${e.y*t}px ${e.blur*t}px ${e.color})`;case`unitless`:return e.name===`hue-rotate`?`hue-rotate(${e.value}deg)`:`${e.name}(${e.value})`}}).join(` `);function _l(e){let t=0,n=0;for(let r of e.functions)r.kind===`blur`?t+=r.value:r.kind===`drop-shadow`&&(t+=r.blur,n=Math.max(n,Math.abs(r.x),Math.abs(r.y)));return Math.ceil(3*t+n)}function vl(e){let t=(e.ownerDocument??document).createElement(`canvas`);return t.width=e.width,t.height=e.height,t}let yl=(e,t)=>new Promise((n,r)=>{let i=e=>{clearTimeout(o),t?.removeEventListener(`abort`,a),e?r(e):n()},a=()=>i(new DOMException(`The operation was aborted.`,`AbortError`)),o=setTimeout(()=>i(new Z(`Filter surface image decode timed out`)),1e4);t?.addEventListener(`abort`,a,{once:!0}),t?.aborted?a():e.decode().then(()=>i(),()=>i(new Z(`Filter surface image decode failed`)))}),bl=/* @__PURE__ */ new WeakMap;function xl(e=document){let t=bl.get(e);if(t!==void 0)return t;let n=e.createElement(`canvas`),r=e.createElement(`canvas`),i=!1;try{n.width=n.height=r.width=r.height=32;let e=n.getContext(`2d`),t=r.getContext(`2d`);if(e&&t&&`filter`in t){e.fillStyle=`#fff`,e.fillRect(8,8,8,8),t.filter=`blur(2px)`,t.drawImage(n,0,0);let r=(t.getImageData(6,12,1,1).data[3]??0)>0;t.clearRect(0,0,32,32),t.filter=`drop-shadow(12px 0px 0px rgba(255, 0, 0, 0.5))`,t.drawImage(n,0,0);let a=t.getImageData(24,12,1,1).data;i=r&&(a[0]??0)>240&&(a[1]??0)<10&&(a[3]??0)>=126&&(a[3]??0)<=129}}catch{}finally{Q(n),Q(r)}return bl.set(e,i),i}function Sl(e,t,n,r,i){let a,o,s=!1;try{q(i),a=vl(e);let c=a.getContext(`2d`);if(!c||!(`filter`in c)||(c.filter=gl(t,r),c.filter===`none`||c.filter===``))return null;c.drawImage(e,0,0),q(i),o=vl(e);let l=o.getContext(`2d`);return l?(l.globalAlpha=n,l.drawImage(a,0,0),q(i),s=!0,o):null}catch{return q(i),null}finally{a&&Q(a),o&&!s&&Q(o)}}let Cl=e=>{let t=0,n=0;for(let r of e.functions)if(r.kind===`blur`)t++;else if(r.kind===`drop-shadow`)n++;else return!1;return t>1||n>1?!1:t>0&&n>0?e.functions.findIndex(e=>e.kind===`blur`)<e.functions.findIndex(e=>e.kind===`drop-shadow`):!0};async function wl(e,t,n,r,i){if(q(i),t.functions.length>0&&xl(e.ownerDocument??document)){let a=Sl(e,t,n,r,i);if(a)return a}if(!Cl(t))throw new Z(`Filter chain requires native canvas filters`);return Tl(e,t,n,r,i)}async function Tl(e,t,n,r,i){q(i);let a=t.functions.find(e=>e.kind===`blur`),o=t.functions.find(e=>e.kind===`drop-shadow`),s=a&&a.kind===`blur`?a.value:0,c=o&&o.kind===`drop-shadow`?{x:o.x,y:o.y,blur:o.blur,color:o.color}:void 0;if(!s&&!c){let t=vl(e),r=t.getContext(`2d`);if(!r)throw Q(t),new Z(`Filter surface canvas is unavailable`);r.globalAlpha=n;try{return r.drawImage(e,0,0),t}catch{throw Q(t),new Z(`Filter surface image cannot be drawn`)}}let l=e.ownerDocument??document,u=(e,t={})=>{let n=l.createElementNS(`http://www.w3.org/2000/svg`,e);return Object.entries(t).forEach(([e,t])=>n.setAttribute(e,String(t))),n},d=u(`svg`,{width:e.width,height:e.height,viewBox:`0 0 ${e.width} ${e.height}`}),f=u(`defs`),p=u(`filter`,{id:`composited-filter`,filterUnits:`userSpaceOnUse`,x:0,y:0,width:e.width,height:e.height,"color-interpolation-filters":`sRGB`});if(s&&p.appendChild(u(`feGaussianBlur`,{stdDeviation:s*r,result:`blurred-source`})),c){p.appendChild(u(`feGaussianBlur`,{in:s?`blurred-source`:`SourceAlpha`,stdDeviation:c.blur*r})),p.appendChild(u(`feOffset`,{dx:c.x*r,dy:c.y*r,result:`offset-shadow`})),p.appendChild(u(`feFlood`,{"flood-color":c.color})),p.appendChild(u(`feComposite`,{in2:`offset-shadow`,operator:`in`}));let e=u(`feMerge`);e.appendChild(u(`feMergeNode`)),e.appendChild(u(`feMergeNode`,{in:s?`blurred-source`:`SourceGraphic`})),p.appendChild(e)}f.appendChild(p),d.appendChild(f);let m;try{if(m=e.toDataURL(`image/png`),m===`data:,`)throw Error(`Canvas size is unsupported`)}catch{throw new Z(`Filter surface pixels cannot be serialized`)}d.appendChild(u(`image`,{width:e.width,height:e.height,href:m,filter:`url(#composited-filter)`}));let h=l.defaultView,g=h?.Image?new h.Image:new Image,_;try{g.src=`data:image/svg+xml,${encodeURIComponent(new XMLSerializer().serializeToString(d))}`,await yl(g,i),q(i),_=vl(e);let t=_.getContext(`2d`);if(!t)throw new Z(`Filter surface canvas is unavailable`);return t.globalAlpha=n,t.drawImage(g,0,0),_}catch(e){throw _&&Q(_),i?.aborted&&q(i),e instanceof Z?e:new Z(`Filter surface image cannot be drawn`)}finally{g.removeAttribute(`src`)}}function El(e,t,n){let r=t*n*4;return!Number.isFinite(r)||t<=0||n<=0||t>8192||n>8192||e.pixels+r>16777216?0:(e.pixels+=r,r)}let Dl=(e,t)=>e.add(-t,-t,t*2,t*2),Ol=(e,t)=>new a(Math.min(e.left,t.left),Math.min(e.top,t.top),Math.max(e.left+e.width,t.left+t.width)-Math.min(e.left,t.left),Math.max(e.top+e.height,t.top+t.height)-Math.min(e.top,t.top));function kl(e){let t=e.styles,n=e.bounds;for(let r of t.boxShadow)if(!r.inset){let t=Math.max(0,r.spread.number)+3*r.blur.number;n=Ol(n,Dl(e.bounds.add(r.offsetX.number,r.offsetY.number,0,0),t))}for(let r of e.textNodes)for(let i of r.textBounds){let r=Dl(i.bounds,2*I(t.fontSize,e.bounds.height)+t.webkitTextStrokeWidth);n=Ol(n,r);for(let e of t.textShadow)n=Ol(n,Dl(r.add(e.offsetX.number,e.offsetY.number,0,0),3*e.blur.number))}for(let t of e.elements)t.styles.isVisible()&&(n=Ol(n,kl(t)));let r=cl(t.filter);return Dl(n,r?_l(r):0)}function Al(e,t,n,r){let i=Dl(t,n),o=Math.floor(Math.max(e.left,i.left)*r)/r,s=Math.floor(Math.max(e.top,i.top)*r)/r,c=Math.ceil(Math.min(e.left+e.width,i.left+i.width)*r)/r,l=Math.ceil(Math.min(e.top+e.height,i.top+i.height)*r)/r;return new a(o,s,Math.max(0,c-o),Math.max(0,l-s))}var jl=class{ctx;constructor(e){this.ctx=e}render(e,t){this.ctx.fillStyle=z(t.textDecorationColor??t.color);let n=1;typeof t.textDecorationThickness==`number`?n=t.textDecorationThickness:t.textDecorationThickness===`from-font`&&(n=Math.max(1,Math.floor(t.fontSize.number*.05)));let r=0;typeof t.textUnderlineOffset==`number`&&(r=t.textUnderlineOffset);let i=t.textDecorationStyle;t.textDecorationLine.forEach(t=>{let a=0;switch(t){case 1:a=e.top+e.height-n+r;break;case 2:a=e.top;break;case 3:a=e.top+(e.height/2-n/2);break;default:return}this.draw(e.left,a,e.width,n,i)})}draw(e,t,n,r,i){switch(i){case 0:this.ctx.fillRect(e,t,n,r);break;case 1:{let i=Math.max(1,r);this.ctx.fillRect(e,t,n,r),this.ctx.fillRect(e,t+r+i,n,r);break}case 2:this.drawPattern(e,t,n,r,[r,r*2]);break;case 3:this.drawPattern(e,t,n,r,[r*3,r*2]);break;case 4:this.drawWavy(e,t,n,r);break;default:this.ctx.fillRect(e,t,n,r)}}drawPattern(e,t,n,r,i){this.ctx.save(),this.ctx.beginPath(),this.ctx.setLineDash(i),this.ctx.lineWidth=r,this.ctx.strokeStyle=this.ctx.fillStyle,this.ctx.moveTo(e,t+r/2),this.ctx.lineTo(e+n,t+r/2),this.ctx.stroke(),this.ctx.restore()}drawWavy(e,t,n,r){this.ctx.save(),this.ctx.beginPath(),this.ctx.lineWidth=r,this.ctx.strokeStyle=this.ctx.fillStyle;let i=r*2,a=r*4,o=e;for(this.ctx.moveTo(o,t+r/2);o<e+n;){let s=Math.min(o+a/2,e+n);if(this.ctx.quadraticCurveTo(o+a/4,t+r/2-i,s,t+r/2),o=s,o<e+n){let s=Math.min(o+a/2,e+n);this.ctx.quadraticCurveTo(o+a/4,t+r/2+i,s,t+r/2),o=s}}this.ctx.stroke(),this.ctx.restore()}};let Ml=e=>e!==void 0&&!Number.isNaN(e),Nl=(e,t)=>{let n=e.measureText(`Mg`),r=n;return{baseline:Ml(r.fontBoundingBoxAscent)?r.fontBoundingBoxAscent:Ml(n.actualBoundingBoxAscent)?n.actualBoundingBoxAscent:t,height:Ml(r.fontBoundingBoxAscent)&&Ml(r.fontBoundingBoxDescent)?r.fontBoundingBoxAscent+r.fontBoundingBoxDescent:Ml(n.actualBoundingBoxAscent)&&Ml(n.actualBoundingBoxDescent)?n.actualBoundingBoxAscent+n.actualBoundingBoxDescent:t}},Pl=(e,t)=>Nl(e,t).baseline,Fl=/[\u2E80-\u2FFF\u3000-\u30FF\u3400-\u4DBF\u4E00-\u9FFF\uAC00-\uD7AF\uF900-\uFAFF\uFF01-\uFFEF]/,Il=e=>Fl.test(e),Ll=()=>typeof navigator>`u`?!1:navigator.userAgentData!==void 0||(typeof window<`u`?window:void 0)?.chrome!==void 0,Rl=()=>Ll()?`miter`:`round`;var zl=class{ctx;options;decorationRenderer;baselineCache=/* @__PURE__ */ new Map;glyphWidthCache=null;constructor(e){this.ctx=e.ctx,this.options=e.options,this.decorationRenderer=new jl(e.ctx)}cachedMeasureText(e,t){let n=this.glyphWidthCache;n||(n=/* @__PURE__ */ new Map,this.glyphWidthCache=n);let r=e+t,i=n.get(r);return i===void 0&&(i=this.ctx.measureText(e).width,n.set(r,i)),i}iterateLettersWithLetterSpacing(e,t,n,r,i){if(ka(r)){this.iterateVerticalGlyphs(e,t,n,r,i);return}let a=Bs(e.text),o=e.bounds.top+n,s=this.ctx.font,c=e.bounds.left;for(let e of a)i(e,c,o),c+=this.cachedMeasureText(e,s)+t}iterateVerticalGlyphs(e,t,n,r,i){let a=Bs(e.text),o=this.ctx.font,s=r===4?-Math.PI/2:Math.PI/2,c=e.bounds.top;for(let l=0;l<a.length;){let u=a[l];if(!(Aa(r)||!Il(u)&&u.trim().length>0)){let r=this.ctx.textBaseline;Il(u)&&(this.ctx.textBaseline=`ideographic`),i(u,e.bounds.left,c+n),this.ctx.textBaseline=r,c+=this.cachedMeasureText(u,o)+t,l++;continue}let d=l;for(;l<a.length;){let e=a[l];if(!Aa(r)&&!Il(e)&&e.trim().length===0)break;if(Aa(r)||!Il(e)&&e.trim().length>0)l++;else break}this.ctx.save(),this.ctx.translate(e.bounds.left+n,c),this.ctx.rotate(s);let f=0;for(let e=d;e<l;e++){let n=a[e];i(n,0,f),f+=this.cachedMeasureText(n,o)+t}this.ctx.restore(),c+=f}}renderTextWithLetterSpacing(e,t,n,r=0){this.renderFillText(e,t,n,r)}canRenderWholeText(e,t){return e===0&&!ka(t)}renderFillText(e,t,n,r){this.canRenderWholeText(t,r)?this.ctx.fillText(e.text,e.bounds.left,e.bounds.top+n):this.iterateLettersWithLetterSpacing(e,t,n,r,(e,t,n)=>{this.ctx.fillText(e,t,n)})}renderStrokeText(e,t,n,r){this.canRenderWholeText(t,r)?this.ctx.strokeText(e.text,e.bounds.left,e.bounds.top+n):this.iterateLettersWithLetterSpacing(e,t,n,r,(e,t,n)=>{this.ctx.strokeText(e,t,n)})}renderTextStrokeWithStyle(e,t,n){t.webkitTextStrokeWidth&&e.text.trim().length&&(this.ctx.strokeStyle=z(t.webkitTextStrokeColor),this.ctx.lineWidth=t.webkitTextStrokeWidth,this.ctx.lineJoin=Rl(),this.renderStrokeText(e,t.letterSpacing,n,t.writingMode),this.ctx.strokeStyle=``,this.ctx.lineWidth=0,this.ctx.lineJoin=`miter`)}renderTextFillWithShadows(e,t,n){this.ctx.fillStyle=this.resolveFillColor(t),this.renderTextWithLetterSpacing(e,t.letterSpacing,n,t.writingMode);let r=t.textShadow;r.length&&e.text.trim().length&&(r.slice(0).reverse().forEach(r=>{this.ctx.shadowColor=z(r.color),this.ctx.shadowOffsetX=r.offsetX.number*this.options.scale,this.ctx.shadowOffsetY=r.offsetY.number*this.options.scale,this.ctx.shadowBlur=r.blur.number*this.options.scale,this.renderTextWithLetterSpacing(e,t.letterSpacing,n,t.writingMode)}),this.ctx.shadowColor=``,this.ctx.shadowOffsetX=0,this.ctx.shadowOffsetY=0,this.ctx.shadowBlur=0)}renderTextBoundWithPaintOrder(e,t,n,r){n.forEach(n=>{switch(n){case 0:this.ctx.fillStyle=this.resolveFillColor(t),this.renderTextWithLetterSpacing(e,t.letterSpacing,r,t.writingMode);break;case 1:this.renderTextStrokeWithStyle(e,t,r)}})}renderTextDecoration(e,t){this.decorationRenderer.render(e,t)}truncateTextWithEllipsis(e,t,n){let r=this.ctx.measureText(`…`).width,i=Bs(e);if(n===0){let e=e=>this.ctx.measureText(i.slice(0,e).join(``)).width+r<=t,n=0,a=i.length;for(;n<a;){let t=n+a+1>>1;e(t)?n=t:a=t-1}return i.slice(0,n).join(``)+`…`}{let e=this.ctx.font,a=r,o=[];for(let r of i){let i=this.cachedMeasureText(r,e);if(a+i>t)break;o.push(r),a+=i+n}return o.join(``)+`…`}}createFontStyle(e){let t=e.fontVariant.filter(e=>e===`normal`||e===`small-caps`).join(``),n=e.fontFamily.join(`, `),r=T(e.fontSize)?`${e.fontSize.number}${e.fontSize.unit}`:`${e.fontSize.number}px`;return[[e.fontStyle,t,e.fontWeight,r,n].join(` `),n,r]}resolveFillColor(e){return z(e.webkitTextFillColor??e.color)}renderLineClampedText(e,t,n,r,i){let a=na(t.lineHeight,t.fontSize.number),o=[],s=[],l=c(e.textBounds,0).bounds.top;e.textBounds.forEach(e=>{Math.abs(e.bounds.top-l)>=a*.5?(s.length>0&&o.push(s),s=[e],l=e.bounds.top):s.push(e)}),s.length>0&&o.push(s);let u=t.webkitLineClamp;if(o.length<=u)return!1;for(let e=0;e<u-1;e++)c(o,e).forEach(e=>this.renderTextBoundWithPaintOrder(e,t,n,r));let d=o[u-1];if(d?.length&&i){let e=d.map(e=>e.text).join(``),a=c(d,0),o=i.width-(a.bounds.left-i.left),s=new Ps(this.truncateTextWithEllipsis(e,o,t.letterSpacing),a.bounds);for(let e of n)e===0?(this.ctx.fillStyle=this.resolveFillColor(t),this.renderTextWithLetterSpacing(s,t.letterSpacing,r,t.writingMode)):e===1&&this.renderTextStrokeWithStyle(s,t,r)}return!0}renderEllipsisText(e,t,n,r,i){let a=na(t.lineHeight,t.fontSize.number),o=c(e.textBounds,0).bounds.top;if(!e.textBounds.every(e=>Math.abs(e.bounds.top-o)<a*.5))return!1;let s=e.textBounds.map(e=>e.text).join(``).replace(/\s+/g,` `).trim();if(this.ctx.measureText(s).width<=i.width+1)return!1;let l=new Ps(this.truncateTextWithEllipsis(s,i.width,t.letterSpacing),c(e.textBounds,0).bounds);for(let e of n)e===0?this.renderTextFillWithShadows(l,t,r):e===1&&this.renderTextStrokeWithStyle(l,t,r);return!0}measureBaselineCached(e,t){let n=this.baselineCache.get(e);return n===void 0&&(n=Pl(this.ctx,t),this.baselineCache.size>=64&&this.baselineCache.clear(),this.baselineCache.set(e,n)),n}async renderTextNode(e,t,n){this.glyphWidthCache=null;let[r]=this.createFontStyle(t);this.ctx.font=r??``,this.ctx.direction=t.direction===1?`rtl`:`ltr`,this.ctx.textAlign=`left`,this.ctx.textBaseline=`alphabetic`;let i=t.paintOrder,a=this.measureBaselineCached(r??``,t.fontSize.number);t.webkitLineClamp>0&&t.display&34&&t.overflowY===1&&e.textBounds.length>0&&this.renderLineClampedText(e,t,i,a,n)||t.textOverflow===1&&n&&t.overflowX===1&&e.textBounds.length>0&&this.renderEllipsisText(e,t,i,a,n)||(e.textBounds.forEach(e=>{i.forEach(n=>{n===0?(this.renderTextFillWithShadows(e,t,a),t.textDecorationLine.length&&this.renderTextDecoration(e.bounds,t)):n===1&&this.renderTextStrokeWithStyle(e,t,a)})}),t.textEmphasisStyle&&this.renderTextEmphasis(e,t,a))}renderTextEmphasis(e,t,n){if(ka(t.writingMode))return;let r=t.textEmphasisStyle;if(!r)return;let i=t.fontSize.number,a=i*.5,o=z(t.textEmphasisColor??t.color),s=t.textEmphasisPosition,c=(e,t)=>{if(typeof r==`string`){let n=this.ctx.font;this.ctx.font=n.replace(/^\S+/,`${a}px`),this.ctx.textAlign=`center`,this.ctx.fillText(r,e,t+a/3),this.ctx.font=n,this.ctx.textAlign=`left`;return}let{fill:n,shape:i}=r,o=a*(i===`dot`?.3:i===`sesame`?.26:.34);this.ctx.beginPath(),i===`sesame`?this.ctx.ellipse(e,t,o*1.3,o*.8,Math.PI/4,0,Math.PI*2):i===`triangle`?(this.ctx.moveTo(e,t-o),this.ctx.lineTo(e+o*1.1,t+o*.8),this.ctx.lineTo(e-o*1.1,t+o*.8),this.ctx.closePath()):this.ctx.arc(e,t,o,0,Math.PI*2),n?i===`double-circle`?(this.ctx.lineWidth=o*.7,this.ctx.stroke(),this.ctx.beginPath(),this.ctx.arc(e,t,o*.4,0,Math.PI*2),this.ctx.lineWidth=o*.35,this.ctx.stroke()):this.ctx.fill():(this.ctx.lineWidth=Math.max(1,o*.35),this.ctx.stroke(),i===`double-circle`&&(this.ctx.beginPath(),this.ctx.arc(e,t,o*.5,0,Math.PI*2),this.ctx.stroke()))},l=this.ctx.font;for(let r of e.textBounds){let e=r.bounds.top+n,u=s.over?e-i-a*.4:e+a*.9,d=r.bounds.left;for(let e of Bs(r.text)){let n=this.cachedMeasureText(e,l);this.ctx.save();try{this.ctx.fillStyle=o,this.ctx.strokeStyle=o,this.ctx.lineWidth=1,c(d+n/2+t.letterSpacing/2,u)}finally{this.ctx.restore()}d+=n+t.letterSpacing}}}};let Bl=(e,t)=>{t.forEach((t,n)=>{let r=Y(t)?t.start:t;n===0?e.moveTo(r.x,r.y):e.lineTo(r.x,r.y),Y(t)&&e.bezierCurveTo(t.startControl.x,t.startControl.y,t.endControl.x,t.endControl.y,t.end.x,t.end.y)})},Vl=(e,t)=>{e.beginPath(),Bl(e,t),e.closePath()};var Hl=class{maxSize;_map;constructor(e){this.maxSize=e,this._map=/* @__PURE__ */ new Map}get(e){if(!this._map.has(e))return;let t=this._map.get(e);return this._map.delete(e),this._map.set(e,t),t}set(e,t){if(this._map.has(e))this._map.delete(e);else if(this._map.size>=this.maxSize){let e=this._map.keys().next().value;e!==void 0&&this._map.delete(e)}this._map.set(e,t)}get size(){return this._map.size}clear(){this._map.clear()}},Ul=class{ctx;context;canvas;patternCache=new Hl(50);constructor(e){this.ctx=e.ctx,this.context=e.context,this.canvas=e.canvas}async renderBackgroundImage(e){let t=e.styles.backgroundImage.length-1,n=e.styles.backgroundBlendMode,r=0;for(let i of e.styles.backgroundImage.slice(0).reverse()){if(r>0){let e=n[r]??n[0]??`normal`;e!==`normal`&&(this.ctx.save(),this.ctx.globalCompositeOperation=e)}i.type===0?await this.renderBackgroundURLImage(e,i,t):ni(i)?this.renderLinearGradient(e,i,t):ii(i)?this.renderRepeatingLinearGradient(e,i,t):ri(i)?this.renderRadialGradient(e,i,t):ai(i)?this.renderRepeatingRadialGradient(e,i,t):oi(i)?this.renderConicGradient(e,i,t):si(i)&&this.renderRepeatingConicGradient(e,i,t),r>0&&(n[r]??n[0]??`normal`)!==`normal`&&this.ctx.restore(),t--,r++}}async renderBackgroundURLImage(e,t,n){let r,i=t.url;try{r=await this.context.cache.match(i)}catch{this.context.logger.error(`Error loading background-image ${i}`)}if(r){let t=isNaN(r.width)||r.width===0?1:r.width,a=isNaN(r.height)||r.height===0?1:r.height,[o,s,c,l,u]=$c(e,n,[t,a,t/a]),d=rl(e.styles.backgroundRepeat,n),f=d===1?`no-repeat`:d===2?`repeat-x`:d===3?`repeat-y`:`repeat`,p=`${i}|${Math.round(l)}x${Math.round(u)}|${e.styles.imageRendering}|${f}`,m=this.patternCache.get(p);if(!m){let t=this.resizeImage(r,l,u,e.styles.imageRendering);m=this.ctx.createPattern(t,f),this.patternCache.set(p,m)}this.renderRepeat(o,m,s,c)}}renderRepeatingLinearGradient(e,t,n){let[r,i,a,o,s]=$c(e,n,[null,null,null]),[l,u,d,f,p]=Pr(t.angle,o,s),m=i+u,h=i+d,g=a+f,_=a+p,v=W(t.stops,l||1),y=Kc(v),b=this.ctx.createLinearGradient(m,g,h,_);if(y)y.forEach(e=>b.addColorStop(Math.min(1,Math.max(0,e.stop)),e.color));else{let e=z(c(v,v.length-1).color);b.addColorStop(0,e),b.addColorStop(1,e)}this.path(r),this.ctx.fillStyle=b,this.ctx.fill()}renderLinearGradient(e,t,n){let[r,i,a,o,s]=$c(e,n,[null,null,null]),[c,l,u,d,f]=Pr(t.angle,o,s),p=`lg|${t.angle}|${Math.round(o)}x${Math.round(s)}|${JSON.stringify(t.stops)}`,m=this.patternCache.get(p);if(!m){let e=(this.canvas.ownerDocument??document).createElement(`canvas`);e.width=o,e.height=s;let n=e.getContext(`2d`);if(!n)return;let r=n.createLinearGradient(l,d,u,f);W(t.stops,c||1).forEach(e=>r.addColorStop(e.stop,z(e.color))),n.fillStyle=r,n.fillRect(0,0,o,s),o>0&&s>0&&(m=this.ctx.createPattern(e,`repeat`),this.patternCache.set(p,m))}m&&this.renderRepeat(r,m,i,a)}renderRadialGradient(e,t,n){let[r,i,a,o,s]=$c(e,n,[null,null,null]),l=t.position.length===0?[P]:t.position,u=I(c(l,0),o),d=I(c(l,l.length-1),s),[f,p]=Ir(t,u,d,o,s);if((f===0||p===0)&&(f=Math.max(f,.01),p=Math.max(p,.01)),f>0&&p>0){let e=`rg|${Math.round(u)}x${Math.round(d)}|${Math.round(f)}x${Math.round(p)}|${JSON.stringify(t.stops)}`,n=W(t.stops,f),o=z(c(n,n.length-1).color),s=this.patternCache.get(e);if(!s){let n=this.canvas.ownerDocument??document,r=Jc(n,f,p,t.stops,!1);if(!r)return;s=this.ctx.createPattern(r.canvas,`no-repeat`),this.patternCache.set(e,s)}this.path(r),this.ctx.save(),this.ctx.clip(),this.ctx.fillStyle=o,this.ctx.fill(),this.ctx.translate(i+u-f,a+d-p),this.ctx.fillStyle=s,this.ctx.fillRect(0,0,f*2,p*2),this.ctx.restore()}}renderRepeatingRadialGradient(e,t,n){let[r,i,a,o,s]=$c(e,n,[null,null,null]),l=t.position.length===0?[P]:t.position,u=I(c(l,0),o),d=I(c(l,l.length-1),s),[f,p]=Ir(t,u,d,o,s);if((f===0||p===0)&&(f=Math.max(f,.01),p=Math.max(p,.01)),!(f>0&&p>0))return;let m=`rrg|${Math.round(u)}x${Math.round(d)}|${Math.round(f)}x${Math.round(p)}|${JSON.stringify(t.stops)}`,h=this.patternCache.get(m);if(!h){let e=this.canvas.ownerDocument??document,n=Jc(e,f,p,t.stops,!0);if(!n)return;h=this.ctx.createPattern(n.canvas,`no-repeat`),this.patternCache.set(m,h)}h&&(this.path(r),this.ctx.save(),this.ctx.clip(),this.ctx.translate(i+u-f,a+d-p),this.ctx.fillStyle=h,this.ctx.fillRect(0,0,f*2,p*2),this.ctx.restore())}renderConicGradient(e,t,n){let[r,i,a,o,s]=$c(e,n,[null,null,null]),l=t.position.length===0?[P]:t.position,u=i+I(c(l,0),o),d=a+I(c(l,l.length-1),s),f=this.ctx.createConicGradient(t.angle-Math.PI/2,u,d);W(t.stops,1).forEach(e=>{f.addColorStop(Math.min(1,Math.max(0,e.stop)),z(e.color))}),this.path(r),this.ctx.save(),this.ctx.clip(),this.ctx.fillStyle=f,this.ctx.fill(),this.ctx.restore()}renderRepeatingConicGradient(e,t,n){let[r,i,a,o,s]=$c(e,n,[null,null,null]),l=t.position.length===0?[P]:t.position,u=i+I(c(l,0),o),d=a+I(c(l,l.length-1),s),f=W(t.stops,1),p=c(f,0),m=c(f,f.length-1),h=Math.max(m.stop-p.stop,.01);if(m.stop-p.stop<1e-6){let e=this.ctx.createConicGradient(t.angle-Math.PI/2,u,d);e.addColorStop(0,z(m.color)),e.addColorStop(1,z(m.color)),this.path(r),this.ctx.save(),this.ctx.clip(),this.ctx.fillStyle=e,this.ctx.fill(),this.ctx.restore();return}let g=[],_=Math.ceil(1/h);for(let e=0;e<_;e++)for(let t of f){let n=e*h+(t.stop-p.stop);if(n>1)break;g.push({stop:n,color:z(t.color)})}let v=c(g,g.length-1);v&&v.stop<1&&g.push({stop:1,color:v.color});let y=this.ctx.createConicGradient(t.angle-Math.PI/2,u,d);g.forEach(e=>{y.addColorStop(Math.min(1,Math.max(0,e.stop)),e.color)}),this.path(r),this.ctx.save(),this.ctx.clip(),this.ctx.fillStyle=y,this.ctx.fill(),this.ctx.restore()}renderRepeat(e,t,n,r){this.path(e),this.ctx.fillStyle=t,this.ctx.translate(n,r),this.ctx.fill(),this.ctx.translate(-n,-r)}resizeImage(e,t,n,r){let i=(this.canvas.ownerDocument??document).createElement(`canvas`);i.width=Math.max(1,t),i.height=Math.max(1,n);let a=i.getContext(`2d`);return a?(r===2||r===1?(this.context.logger.debug(`Disabling image smoothing for background image due to CSS image-rendering`),a.imageSmoothingEnabled=!1):r===3?(this.context.logger.debug(`Enabling image smoothing for background image due to CSS image-rendering: smooth`),a.imageSmoothingEnabled=!0):a.imageSmoothingEnabled=this.ctx.imageSmoothingEnabled,this.ctx.imageSmoothingQuality&&(a.imageSmoothingQuality=this.ctx.imageSmoothingQuality),a.drawImage(e,0,0,e.width,e.height,0,0,t,n),i):e}path(e){Vl(this.ctx,e)}};let Wl=(e,t)=>{switch(t){case 0:return $(e.topLeftBorderBox,e.topLeftPaddingBox,e.topRightBorderBox,e.topRightPaddingBox);case 1:return $(e.topRightBorderBox,e.topRightPaddingBox,e.bottomRightBorderBox,e.bottomRightPaddingBox);case 2:return $(e.bottomRightBorderBox,e.bottomRightPaddingBox,e.bottomLeftBorderBox,e.bottomLeftPaddingBox);default:return $(e.bottomLeftBorderBox,e.bottomLeftPaddingBox,e.topLeftBorderBox,e.topLeftPaddingBox)}},Gl=(e,t)=>{switch(t){case 0:return $(e.topLeftBorderBox,e.topLeftBorderDoubleOuterBox,e.topRightBorderBox,e.topRightBorderDoubleOuterBox);case 1:return $(e.topRightBorderBox,e.topRightBorderDoubleOuterBox,e.bottomRightBorderBox,e.bottomRightBorderDoubleOuterBox);case 2:return $(e.bottomRightBorderBox,e.bottomRightBorderDoubleOuterBox,e.bottomLeftBorderBox,e.bottomLeftBorderDoubleOuterBox);default:return $(e.bottomLeftBorderBox,e.bottomLeftBorderDoubleOuterBox,e.topLeftBorderBox,e.topLeftBorderDoubleOuterBox)}},Kl=(e,t)=>{switch(t){case 0:return $(e.topLeftBorderDoubleInnerBox,e.topLeftPaddingBox,e.topRightBorderDoubleInnerBox,e.topRightPaddingBox);case 1:return $(e.topRightBorderDoubleInnerBox,e.topRightPaddingBox,e.bottomRightBorderDoubleInnerBox,e.bottomRightPaddingBox);case 2:return $(e.bottomRightBorderDoubleInnerBox,e.bottomRightPaddingBox,e.bottomLeftBorderDoubleInnerBox,e.bottomLeftPaddingBox);default:return $(e.bottomLeftBorderDoubleInnerBox,e.bottomLeftPaddingBox,e.topLeftBorderDoubleInnerBox,e.topLeftPaddingBox)}},ql=(e,t)=>{switch(t){case 0:return Jl(e.topLeftBorderStroke,e.topRightBorderStroke);case 1:return Jl(e.topRightBorderStroke,e.bottomRightBorderStroke);case 2:return Jl(e.bottomRightBorderStroke,e.bottomLeftBorderStroke);default:return Jl(e.bottomLeftBorderStroke,e.topLeftBorderStroke)}},Jl=(e,t)=>{let n=[];return Y(e)?n.push(e.subdivide(.5,!1)):n.push(e),Y(t)?n.push(t.subdivide(.5,!0)):n.push(t),n},$=(e,t,n,r)=>{let i=[];return Y(e)?i.push(e.subdivide(.5,!1)):i.push(e),Y(n)?i.push(n.subdivide(.5,!0)):i.push(n),Y(r)?i.push(r.subdivide(.5,!0).reverse()):i.push(r),Y(t)?i.push(t.subdivide(.5,!1).reverse()):i.push(t),i};var Yl=class{ctx;pathCallbacks;constructor(e,t){this.ctx=e.ctx,this.pathCallbacks=t}async renderSolidBorder(e,t,n){this.pathCallbacks.path(Wl(n,t)),this.ctx.fillStyle=z(e),this.ctx.fill()}async renderDoubleBorder(e,t,n,r){if(t<3){await this.renderSolidBorder(e,n,r);return}let i=Gl(r,n);this.pathCallbacks.path(i),this.ctx.fillStyle=z(e),this.ctx.fill();let a=Kl(r,n);this.pathCallbacks.path(a),this.ctx.fill()}async renderDashedDottedBorder(e,t,n,r,i){this.ctx.save();let a=ql(r,n),o=Wl(r,n);i===2&&(this.pathCallbacks.path(o),this.ctx.clip());let s,l,u,d;Y(c(o,0))?(s=c(o,0).start.x,l=c(o,0).start.y):(s=c(o,0).x,l=c(o,0).y),Y(c(o,1))?(u=c(o,1).end.x,d=c(o,1).end.y):(u=c(o,1).x,d=c(o,1).y);let f;f=Math.abs(n===0||n===2?s-u:l-d),this.ctx.beginPath(),i===3?this.pathCallbacks.formatPath(a):this.pathCallbacks.formatPath(o.slice(0,2));let p=t<3?t*3:t*2,m=t<3?t*2:t;i===3&&(p=t,m=t);let h=!0;if(f<=p*2)h=!1;else if(f<=p*2+m){let e=f/(2*p+m);p*=e,m*=e}else{let e=Math.floor((f+m)/(p+m)),t=(f-e*p)/(e-1),n=(f-(e+1)*p)/e;m=n<=0||Math.abs(m-t)<Math.abs(m-n)?t:n}if(h&&(i===3?this.ctx.setLineDash([0,p+m]):this.ctx.setLineDash([p,m])),i===3?(this.ctx.lineCap=`round`,this.ctx.lineWidth=t):this.ctx.lineWidth=t*2+1.1,this.ctx.strokeStyle=z(e),this.ctx.stroke(),this.ctx.setLineDash([]),i===2){if(Y(c(o,0))){let e=c(o,3),t=c(o,0);this.ctx.beginPath(),this.pathCallbacks.formatPath([new J(e.end.x,e.end.y),new J(t.start.x,t.start.y)]),this.ctx.stroke()}if(Y(c(o,1))){let e=c(o,1),t=c(o,2);this.ctx.beginPath(),this.pathCallbacks.formatPath([new J(e.end.x,e.end.y),new J(t.start.x,t.start.y)]),this.ctx.stroke()}}this.ctx.restore()}};let Xl=(e,t,n)=>{let r=e?[e.top,e.right,e.bottom,e.left]:null;return[0,1,2,3].map(e=>{let i=r?r[e]:null,a=t[e]??0;return!i||i.kind===`auto`?a:i.kind===`number`?a*(i.value??1):i.kind===`length`?i.value??0:(i.value??0)/100*(e===0||e===2?n.height:n.width)})},Zl=(e,t)=>{let n=e?[e.top,e.right,e.bottom,e.left]:null,r=e=>{let r=n?n[e]:null;return r?r.kind===`number`?(t[e]??0)*(r.value??0):r.value??0:0};return{top:r(0),right:r(1),bottom:r(2),left:r(3)}};var Ql=class{ctx;constructor(e){this.ctx=e}renderBorderImage(e,t,n,r,i,a,o,s,c={top:0,right:0,bottom:0,left:0}){e=e.add(-c.left,-c.top,c.left+c.right,c.top+c.bottom);let l=t.naturalWidth||t.width,u=t.naturalHeight||t.height;if(l<=0||u<=0)return;let d=Math.min(n.unit===`percent`?n.top/100*u:Math.min(n.top,u),u),f=Math.min(n.unit===`percent`?n.right/100*l:Math.min(n.right,l),l),p=Math.min(n.unit===`percent`?n.bottom/100*u:Math.min(n.bottom,u),u),m=Math.min(n.unit===`percent`?n.left/100*l:Math.min(n.left,l),l),{left:h,top:g,width:_,height:v}=e;if(_<=0||v<=0)return;let y=Math.min(i,v),b=Math.min(a,_),x=Math.min(o,v-y),S=Math.min(s,_-b);this.drawRegion(t,0,0,m,d,h,g,S,y),this.drawRegion(t,l-f,0,f,d,h+_-b,g,b,y),this.drawRegion(t,l-f,u-p,f,p,h+_-b,g+v-x,b,x),this.drawRegion(t,0,u-p,m,p,h,g+v-x,S,x);let C=[{sx:m,sy:0,sw:l-m-f,sh:d,dx:h+S,dy:g,dw:_-S-b,dh:y,repeat:r.horizontal,horizontal:!0},{sx:l-f,sy:d,sw:f,sh:u-d-p,dx:h+_-b,dy:g+y,dw:b,dh:v-y-x,repeat:r.vertical,horizontal:!1},{sx:m,sy:u-p,sw:l-m-f,sh:p,dx:h+S,dy:g+v-x,dw:_-S-b,dh:x,repeat:r.horizontal,horizontal:!0},{sx:0,sy:d,sw:m,sh:u-d-p,dx:h,dy:g+y,dw:S,dh:v-y-x,repeat:r.vertical,horizontal:!1}];for(let e of C)e.sw<=0||e.sh<=0||e.dw<=0||e.dh<=0||(e.repeat===0?this.ctx.drawImage(t,e.sx,e.sy,e.sw,e.sh,e.dx,e.dy,e.dw,e.dh):(e.repeat===1||e.repeat===2)&&this.drawRepeatedEdge(t,e,e.horizontal,e.repeat===2));n.fill&&this.drawCenterRegion(t,{sx:m,sy:d,sw:l-m-f,sh:u-d-p},{dx:h+S,dy:g+y,dw:_-S-b,dh:v-y-x},r)}drawRegion(e,t,n,r,i,a,o,s,c){r>0&&i>0&&s>0&&c>0&&this.ctx.drawImage(e,t,n,r,i,a,o,s,c)}drawRepeatedEdge(e,t,n,r){let i=n?t.sw:t.sh,a=n?t.dw:t.dh;if(i<=0||a<=0)return;let o,s;r?(s=Math.max(1,Math.round(a/i)),o=a/s):(o=i,s=Math.ceil(a/o)),this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(t.dx,t.dy,t.dw,t.dh),this.ctx.clip();for(let r=0;r<s;r++){let i=r*o;n?this.ctx.drawImage(e,t.sx,t.sy,t.sw,t.sh,t.dx+i,t.dy,o,t.dh):this.ctx.drawImage(e,t.sx,t.sy,t.sw,t.sh,t.dx,t.dy+i,t.dw,o)}this.ctx.restore()}drawCenterRegion(e,t,n,r){if(t.sw<=0||t.sh<=0||n.dw<=0||n.dh<=0)return;let i=(e,t,n)=>{if(e===0)return{size:n,count:1};if(e===2){let e=Math.max(1,Math.round(n/t));return{size:n/e,count:e}}return{size:t,count:Math.max(1,Math.ceil(n/t))}},a=i(r.horizontal,t.sw,n.dw),o=i(r.vertical,t.sh,n.dh);this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(n.dx,n.dy,n.dw,n.dh),this.ctx.clip();for(let r=0;r<o.count;r++)for(let i=0;i<a.count;i++)this.ctx.drawImage(e,t.sx,t.sy,t.sw,t.sh,n.dx+i*a.size,n.dy+r*o.size,a.size,o.size);this.ctx.restore()}};let $l=/blur\((\d+(?:\.\d+)?)px\)/gi,eu=(e,t)=>t===1?e:e.replace($l,(e,n)=>`blur(${parseFloat(n)*t}px)`);var tu=class{ctx;pathCallback;scale;activeEffects=[];didSave=!1;saveAtDepth=-1;constructor(e,t){this.ctx=e.ctx,this.pathCallback=t,this.scale=e.scale??1}applyEffects(e){for(;this.activeEffects.length;)this.popEffect();this.didSave=!1,this.saveAtDepth=-1;let t=e=>jc(e)||Mc(e)||Pc(e),n=e.reduceRight((e,n,r)=>e===-1?t(n)?r:-1:e,-1);for(let r=0;r<e.length;r++){let i=c(e,r);t(i)&&(this.didSave||=(this.ctx.save(),!0),r===n&&(this.saveAtDepth=this.activeEffects.length)),this.applyEffect(i)}}applyEffect(e){jc(e)?(this.ctx.translate(e.offsetX,e.offsetY),this.ctx.transform(e.matrix[0],e.matrix[1],e.matrix[2],e.matrix[3],e.matrix[4],e.matrix[5]),this.ctx.translate(-e.offsetX,-e.offsetY)):Mc(e)?(this.pathCallback.path(e.path),this.ctx.clip()):Pc(e)?e.applyClip(this.ctx):Nc(e)?this.ctx.globalAlpha*=e.opacity:Fc(e)?this.ctx.globalCompositeOperation=e.compositeOperation:Ic(e)&&(this.ctx.filter=eu(e.safeFilterString,this.scale)||`none`,e.shadow&&(this.ctx.shadowOffsetX=e.shadow.offsetX*this.scale,this.ctx.shadowOffsetY=e.shadow.offsetY*this.scale,this.ctx.shadowBlur=e.shadow.blur*this.scale,this.ctx.shadowColor=e.shadow.color)),this.activeEffects.push(e)}popEffect(){this.activeEffects.length!==0&&(this.didSave&&this.activeEffects.length-1===this.saveAtDepth&&(this.ctx.restore(),this.didSave=!1,this.saveAtDepth=-1),this.activeEffects.pop(),!this.didSave&&this.activeEffects.length===0&&(this.ctx.globalAlpha=1,this.ctx.globalCompositeOperation=`source-over`,this.ctx.filter=`none`,this.ctx.shadowOffsetX=0,this.ctx.shadowOffsetY=0,this.ctx.shadowBlur=0,this.ctx.shadowColor=`rgba(0, 0, 0, 0)`))}getActiveEffectCount(){return this.activeEffects.length}hasActiveEffects(){return this.activeEffects.length>0}};let nu=(e,t)=>e.length===0?void 0:e[t%e.length]??e[0],ru=(e,t,n,r)=>{let i=e?e[0]:void 0,a=e&&e.length>1?c(e,1):void 0,o=e=>e!==void 0&&D(e)?e.value:null,s=(e,t,n)=>e===void 0||D(e)?null:M(e)?I(e,t):n,l=o(i);if(l===`contain`||l===`cover`){let e=l===`contain`?Math.min(t.width/n,t.height/r):Math.max(t.width/n,t.height/r);return{width:n*e,height:r*e}}let u=s(i,t.width,n),d=s(a,t.height,r);return u===null&&d===null?(u=n,d=r):u===null?u=n/r*d:d===null&&(d=r/n*u),{width:u,height:d}},iu=(e,t,n,r,i)=>{let a=t.naturalWidth||t.width||i.width,o=t.naturalHeight||t.height||i.height,{width:s,height:l}=ru(nu(n.maskSize,r),i,a,o),u=nu(n.maskPosition,r)??[],d=i.left+I(c(u,0),i.width-s),f=i.top+I(c(u,u.length-1),i.height-l),p=nu(n.maskRepeat,r)??0,m=p===0||p===2,h=p===0||p===3,g=m?Math.ceil((d-i.left)/s):0,_=h?Math.ceil((f-i.top)/l):0,v=m?Math.ceil((i.left+i.width-d)/s):0,y=h?Math.ceil((i.top+i.height-f)/l):0;for(let n=-_;n<=y;n++)for(let r=-g;r<=v;r++)e.drawImage(t,d+r*s,f+n*l,s,l)},au=(e,t,n)=>{let{width:r,height:i}=n,a=t.position.length===0?[P]:t.position,o=I(c(a,0),r),s=I(c(a,a.length-1),i),[l,u]=Ir(t,o,s,r,i);l=Math.max(l,.01),u=Math.max(u,.01);let d=e.canvas.ownerDocument??document,f=Jc(d,l,u,t.stops,ai(t));f&&(e.fillStyle=f.lastColor,e.fillRect(n.left,n.top,n.width,n.height),e.drawImage(f.canvas,n.left+o-l,n.top+s-u,l*2,u*2),Q(f.canvas))},ou=(e,t,n)=>{let{width:r,height:i}=n;if(r<=0||i<=0)return;if(ri(t)||ai(t)){au(e,t,n);return}let a=null;if(t.type===1||t.type===3){let o=t,[s,l,u,d,f]=Pr(o.angle||0,r,i),p=W(o.stops,s||1);if(t.type===3){let t=Kc(p);if(!t){e.fillStyle=z(c(p,p.length-1).color),e.fillRect(n.left,n.top,r,i);return}a=e.createLinearGradient(n.left+l,n.top+d,n.left+u,n.top+f),t.forEach(e=>a.addColorStop(Math.min(1,Math.max(0,e.stop)),e.color))}else a=e.createLinearGradient(n.left+l,n.top+d,n.left+u,n.top+f),qc(p).forEach(e=>a.addColorStop(e.stop,e.color))}else if(t.type===5||t.type===6){let o=t,s=W(o.stops,1),l=t.type===6;if(l&&!Kc(s)){e.fillStyle=z(c(s,s.length-1).color),e.fillRect(n.left,n.top,r,i);return}a=e.createConicGradient(o.angle-Math.PI/2,n.left+r/2,n.top+i/2),((l?Kc(s):null)??qc(s)).forEach(e=>a.addColorStop(Math.min(1,Math.max(0,e.stop)),e.color))}a&&(e.fillStyle=a,e.fillRect(n.left,n.top,r,i))},su=async(e,t,n,r,i)=>{for(let a=0;a<t.length;a++){let o=c(t,a);if(o.type===0){let t=await i(o.url);t&&iu(e,t,n,a,r)}else ou(e,o,r)}},cu=(e,t,n,r,i)=>{let a=0,o=0,s=e,c=t,l=n.left,u=n.top,d=n.width,f=n.height,p=d/f,m=s/c,h=i?I(i[0],1):.5,g=i?I(i[1],1):.5;if(r===2)m>p?(f=d/m,u+=(n.height-f)*g):(d=f*m,l+=(n.width-d)*h);else if(r===4)m>p?(s=c*p,a+=(e-s)*h):(c=s/p,o+=(t-c)*g);else if(r===8)s>d?(a+=(s-d)*h,s=d):(l+=(d-s)*h,d=s),c>f?(o+=(c-f)*g,c=f):(u+=(f-c)*g,f=c);else if(r===16){let e=m>p?d:f*m,t=m>p?d/m:f,r=Math.min(s,d),i=Math.min(c,f);e*t<r*i?m>p?(f=d/m,u+=(n.height-f)*g):(d=f*m,l+=(n.width-d)*h):(s>d?(a+=(s-d)*h,s=d):(l+=(d-s)*h,d=s),c>f?(o+=(c-f)*g,c=f):(u+=(f-c)*g,f=c))}return{sx:a,sy:o,sw:s,sh:c,dx:l,dy:u,dw:d,dh:f}};async function lu(e,t,n,r,i,a,o,s){if(i instanceof qs)try{let n=await t.cache.match(i.src),r=e.imageSmoothingEnabled;o.imageRendering===2||o.imageRendering===1?e.imageSmoothingEnabled=!1:o.imageRendering===3&&(e.imageSmoothingEnabled=!0),s(i,a,n),e.imageSmoothingEnabled=r}catch{t.logger.error(`Error loading image ${i.src}`)}if(i instanceof Js&&s(i,a,i.canvas),i instanceof Zs)try{s(i,a,await t.cache.match(i.svg))}catch{t.logger.error(`Error loading svg ${i.svg.substring(0,255)}`)}if(i instanceof cc&&i.tree){let a=await r(t,{scale:n.scale,backgroundColor:i.backgroundColor,x:0,y:0,width:i.width,height:i.height}).render(i.tree);i.width&&i.height&&e.drawImage(a,0,0,i.width,i.height,i.bounds.left,i.bounds.top,i.bounds.width,i.bounds.height)}}function uu(e,t,n,r,i){if(r instanceof ac){let t=Math.min(r.bounds.width,r.bounds.height);r.type===`checkbox`&&r.checked?(e.save(),n([new J(r.bounds.left+t*.39363,r.bounds.top+t*.79),new J(r.bounds.left+t*.16,r.bounds.top+t*.5549),new J(r.bounds.left+t*.27347,r.bounds.top+t*.44071),new J(r.bounds.left+t*.39694,r.bounds.top+t*.5649),new J(r.bounds.left+t*.72983,r.bounds.top+t*.23),new J(r.bounds.left+t*.84,r.bounds.top+t*.34085),new J(r.bounds.left+t*.39363,r.bounds.top+t*.79)]),e.fillStyle=z(r.styles.accentColor??7733247),e.fill(),e.restore()):r.type===`radio`&&r.checked&&(e.save(),e.beginPath(),e.arc(r.bounds.left+t/2,r.bounds.top+t/2,t/4,0,Math.PI*2,!0),e.fillStyle=z(r.styles.accentColor??7733247),e.fill(),e.restore())}if(mu(r)&&r.value.length){let[o]=t.createFontStyle(i);e.font=o??``;let s=I(i.fontSize,0),{baseline:c,height:l}=Nl(e,s);e.fillStyle=r instanceof ac&&r.isPlaceholder?z(1970632191):z(i.color),e.textBaseline=`alphabetic`,e.textAlign=hu(r.styles.textAlign);let u=Xc(r),d=r instanceof ac?du(u,Yc(r),l):u,f=0;switch(r.styles.textAlign){case 1:f+=u.width/2;break;case 2:f+=u.width}let p=0;r instanceof ac&&(p=(u.height-l)/2);let m=u.add(f,p,0,0);e.save(),n([new J(d.left,d.top),new J(d.left+d.width,d.top),new J(d.left+d.width,d.top+d.height),new J(d.left,d.top+d.height)]),e.clip();let h=fu(e,r.value,u.width,i.whiteSpace===`pre`||i.whiteSpace===`nowrap`),g=na(i.lineHeight,s);h.forEach((n,r)=>{let o=m.left,s=e.measureText(n).width;switch(i.textAlign){case 1:o+=(u.width-s)/2;break;case 2:o+=u.width-s}let l=new a(o,m.top+r*g,0,0);t.renderTextWithLetterSpacing(new Ps(n,l),i.letterSpacing,c,i.writingMode)}),e.restore(),e.textBaseline=`alphabetic`,e.textAlign=`left`}}let du=(e,t,n)=>e.height<n?new a(e.left,t.top,e.width,t.height):e,fu=(e,t,n,r)=>{let i=[],a=t.split(`
12
- `);for(let t of a){if(r){i.push(t);continue}let a=t.split(/(\s+)/),o=``;for(let t of a){let r=o+t;e.measureText(r).width<=n||o===``?o=r:(i.push(o),o=t)}i.push(o)}return i};async function pu(e,t,n,r,i,o){if(H(i.styles.display,2048)){if(i.styles.listStyleImage!==null){let n=i.styles.listStyleImage;if(n.type===0){let r=n.url;try{let n=await t.cache.match(r),a=I(o.fontSize,0),s=n?.naturalWidth||n.width,c=n?.naturalHeight||n.height;if(s<=0||c<=0)return;let l=Math.min(a/s,a/c),u=s*l,d=c*l,f=i.bounds.top+I(i.styles.paddingTop,i.bounds.width)+na(o.lineHeight,o.fontSize.number)/2;e.drawImage(n,i.bounds.left-(u+10),f-d/2,u,d)}catch{t.logger.error(`Error loading list-style-image ${r}`)}}}else if(r.listValue&&i.styles.listStyleType!==-1){let t=i.styles.listStyleType;if(t===0||t===1||t===2){let n=o.fontSize.number*.45,r=i.bounds.left-n*.9,a=i.bounds.top+I(i.styles.paddingTop,i.bounds.width)+na(o.lineHeight,o.fontSize.number)/2;e.save(),e.fillStyle=z(o.color),e.beginPath(),t===2?e.rect(r-n/2,a-n/2,n,n):(e.arc(r,a,n/2,0,Math.PI*2),t===1&&(e.strokeStyle=z(o.color),e.lineWidth=n*.18)),t===1?e.stroke():e.fill(),e.restore()}else{let[t]=n.createFontStyle(o);e.font=t??``,e.fillStyle=z(o.color),e.textBaseline=`middle`,e.textAlign=`right`;let s=new a(i.bounds.left,i.bounds.top+I(i.styles.paddingTop,i.bounds.width),i.bounds.width,na(o.lineHeight,o.fontSize.number)/2+1);n.renderTextWithLetterSpacing(new Ps(r.listValue,s),o.letterSpacing,na(o.lineHeight,o.fontSize.number)/2+2,o.writingMode),e.textBaseline=`bottom`,e.textAlign=`left`}}}}let mu=e=>e instanceof sc||e instanceof oc||e instanceof ac&&e.type!==`radio`&&e.type!==`checkbox`,hu=e=>{switch(e){case 1:return`center`;case 2:return`right`;default:return`left`}},gu=(e,t)=>{let n=t>e?t*(1+(e/t-1)**3):t;return Math.max(0,e+n)},_u=(e,t)=>{if(t===0)return e;let n=e.map((e,t)=>Y(e)?{x:t%2==0?e.start.x:e.end.x,y:t%2==0?e.end.y:e.start.y,rx:Math.abs(e.end.x-e.start.x),ry:Math.abs(e.end.y-e.start.y)}:{x:e.x,y:e.y,rx:0,ry:0}),r=c(n,1).x-c(n,0).x+2*t,i=c(n,3).y-c(n,0).y+2*t;if(r<=0||i<=0)return[];let a=n.map(e=>({x:gu(e.rx,t),y:gu(e.ry,t)})),o=(e,t)=>t>0?e/t:1,s=Math.min(1,o(r,c(a,0).x+c(a,1).x),o(r,c(a,3).x+c(a,2).x),o(i,c(a,0).y+c(a,3).y),o(i,c(a,1).y+c(a,2).y));return e.map((e,r)=>{let i=c(n,r),o=i.x+(r===1||r===2?t:-t),l=i.y+(r>=2?t:-t);if(!Y(e))return new J(o,l);let u=c(a,r).x*s,d=c(a,r).y*s;if(!u||!d)return new J(o,l);let f=u/i.rx,p=d/i.ry,m=e=>new J(o+(e.x-i.x)*f,l+(e.y-i.y)*p);return new yc(m(e.start),m(e.startControl),m(e.endControl),m(e.end))})},vu=(e,t,n)=>{let{a:r,b:i,c:o,d:s,e:c,f:l}=e;if(![r,i,o,s,c,l,t,n].every(Number.isFinite))return null;let u=r*s-i*o;if(!Number.isFinite(u)||u===0)return null;let d=(e,t)=>({x:(s*(e-c)-o*(t-l))/u,y:(-i*(e-c)+r*(t-l))/u}),f=[d(0,0),d(t,0),d(t,n),d(0,n)];if(!f.every(e=>Number.isFinite(e.x)&&Number.isFinite(e.y)))return null;let p=Math.min(...f.map(e=>e.x)),m=Math.min(...f.map(e=>e.y)),h=Math.max(...f.map(e=>e.x)),g=Math.max(...f.map(e=>e.y)),_=r*r+i*i,v=o*o+s*s,y=r*o+i*s,b=Math.sqrt((_+v+Math.hypot(_-v,2*y))/2);if(!Number.isFinite(b)||b<=0)return null;let x=1e-10*Math.max(_,v);return{matrix:e,viewport:new a(p,m,h-p,g-m),scale:b,uniform:Math.abs(_-v)<=x&&Math.abs(y)<=x}},yu=(e,t,n)=>{e.beginPath(),e.rect(t.left,t.top,t.width,t.height),n.length&&(Bl(e,n),e.closePath())},bu=(e,t)=>{let n=t.spread.number,r=Yc(e.container);return r.width-2*n<=0||r.height-2*n<=0?[]:_u(Cc(e.curves),-n)},xu=async(e,t,n,r,i,a)=>{let o=Yc(t.container),s=n.blur.number/2,c=Math.ceil(3*s)+2,l=n.spread.number,u=Al((n.inset?o:t.container.bounds.add(n.offsetX.number-l,n.offsetY.number-l,2*l,2*l)).add(-c,-c,2*c,2*c),a.viewport,c,a.scale);if(!u.width||!u.height)return!0;let d=Math.ceil(u.width*a.scale),f=Math.ceil(u.height*a.scale),p=El(i,d,f);if(!p)return!1;let m,h;try{m=e.canvas.ownerDocument.createElement(`canvas`),m.width=d,m.height=f;let i=m.getContext(`2d`);if(!i)return!1;i.scale(a.scale,a.scale),i.translate(-u.left,-u.top);let o=n.inset?bu(t,n):_u(xc(t.curves),l),c=_c(o,n.offsetX.number,n.offsetY.number,0,0);n.inset?yu(i,u,c):Vl(i,c),i.fillStyle=z(n.color),i.fill(n.inset?`evenodd`:`nonzero`),h=await wl(m,{functions:[{kind:`blur`,value:s}]},1,a.scale,r.signal),e.save();try{n.inset?(Vl(e,Cc(t.curves)),e.clip()):(yu(e,a.viewport,xc(t.curves)),e.clip(`evenodd`)),e.drawImage(h,u.left,u.top,h.width/a.scale,h.height/a.scale)}finally{e.restore()}return!0}catch(e){if(!(e instanceof Z))throw e;return!1}finally{h&&h!==m&&Q(h),m&&Q(m),i.pixels-=p}},Su=async(e,t,n,r,i)=>{if(r.signal?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);if(R(n.color))return;let a=n.spread.number;if(!n.inset&&(t.container.bounds.width+2*a<=0||t.container.bounds.height+2*a<=0))return;let o=typeof e.getTransform==`function`,s=o?e.getTransform():{a:r.scale,b:0,c:0,d:r.scale,e:-r.x*r.scale,f:-r.y*r.scale},c=vu(s,e.canvas.width,e.canvas.height);if(!c)return;let{viewport:l}=c;if(n.blur.number>0&&(n.inset||!c.uniform)&&await xu(e,t,n,r,i,c))return;let u=Yc(t.container);e.save();try{if(n.inset&&n.blur.number===0){Vl(e,Cc(t.curves)),e.clip(),yu(e,u,_c(bu(t,n),n.offsetX.number,n.offsetY.number,0,0)),e.fillStyle=z(n.color),e.fill(`evenodd`);return}let r=Math.ceil(n.blur.number*2+Math.abs(a)+Math.abs(n.offsetX.number)+Math.abs(n.offsetY.number))+2,i=n.inset?u.add(-r,-r,2*r,2*r):t.container.bounds.add(-a,-a,2*a,2*a),{a:d,b:f,c:p,d:m,e:h,f:g}=s,_=i.left+i.width,v=i.top+i.height,y=Math.max(d*i.left+p*i.top+h,d*_+p*i.top+h,d*_+p*v+h,d*i.left+p*v+h),b=Math.max(1e4,y+r*c.scale+2);n.inset?(Vl(e,Cc(t.curves)),e.clip()):(yu(e,l,xc(t.curves)),e.clip(`evenodd`)),o?e.setTransform(d,f,p,m,h-b,g):e.translate(-b/d,0),n.inset?yu(e,i,bu(t,n)):Vl(e,_u(xc(t.curves),a)),o?e.setTransform(d,f,p,m,h,g):e.translate(b/d,0),e.shadowOffsetX=b+d*n.offsetX.number+p*n.offsetY.number,e.shadowOffsetY=f*n.offsetX.number+m*n.offsetY.number,e.shadowBlur=n.blur.number*c.scale,e.shadowColor=z(n.color),e.fillStyle=`rgb(0, 0, 0)`,e.fill(n.inset?`evenodd`:`nonzero`)}finally{e.restore()}};var Cu=class{ctx;context;scale;createFontStyle;constructor(e){this.ctx=e.ctx,this.context=e.context,this.scale=e.scale,this.createFontStyle=e.createFontStyle}async render(e){let t=e.container,n=t.styles,r=t.bounds,i=this.scale;if(r.width<=0||r.height<=0)return;let a=this.ctx.canvas.ownerDocument??document,o=Math.ceil(r.width),s=Math.ceil(r.height),c=Math.ceil(r.width*i),l=Math.ceil(r.height*i),u=this.createLayer(a,c,l);if(!u)return;let d=null,f=null,p=null;try{u.ctx.scale(i,i);let[m]=this.createFontStyle(n);u.ctx.font=m??``,u.ctx.textBaseline=`alphabetic`,u.ctx.textAlign=`left`,u.ctx.direction=n.direction===1?`rtl`:`ltr`;let h=Pl(u.ctx,n.fontSize.number),g=new Ul({ctx:u.ctx,context:this.context,canvas:u.canvas,options:{width:o,height:s,scale:1}});R(n.backgroundColor)||(u.ctx.fillStyle=z(n.backgroundColor),u.ctx.fillRect(0,0,o,s)),u.ctx.save(),u.ctx.translate(-r.left,-r.top),await g.renderBackgroundImage(t),u.ctx.restore();let _={bounds:r,baseline:h,letterSpacing:n.letterSpacing,writingMode:n.writingMode};if(d=this.createGlyphLayer(a,c,l,u.ctx),!d)return;let v=!!n.webkitTextStrokeWidth;v&&(d.ctx.strokeStyle=z(n.webkitTextStrokeColor),d.ctx.lineWidth=n.webkitTextStrokeWidth,d.ctx.lineJoin=Rl());for(let e of t.textNodes)for(let t of e.textBounds)this.drawGlyphs(d,t,_,(e,t,n,r)=>{e.fillText(t,n,r),v&&e.strokeText(t,n,r)});if(u.ctx.globalCompositeOperation=`destination-in`,u.ctx.drawImage(d.canvas,0,0,o,s),p=this.renderShadowSilhouettes(e,a,c,l,u.ctx,n,_),p){if(f=this.createLayer(a,c,l),!f)return;for(let e of p)f.ctx.drawImage(e,0,0);f.ctx.drawImage(u.canvas,0,0),this.ctx.drawImage(f.canvas,r.left,r.top,r.width,r.height)}else this.ctx.drawImage(u.canvas,r.left,r.top,r.width,r.height)}finally{Q(u.canvas),d&&Q(d.canvas),f&&Q(f.canvas),p&&p.forEach(Q)}}createLayer(e,t,n){let r=e.createElement(`canvas`);r.width=t,r.height=n;let i=r.getContext(`2d`);return i?{canvas:r,ctx:i}:null}createGlyphLayer(e,t,n,r){let i=this.createLayer(e,t,n);return i?(i.ctx.scale(this.scale,this.scale),i.ctx.font=r.font,i.ctx.textBaseline=r.textBaseline,i.ctx.textAlign=r.textAlign,i.ctx.direction=r.direction,i.ctx.fillStyle=`#000`,i):null}drawGlyphs(e,t,n,r){let i=t.bounds.left-n.bounds.left,a=t.bounds.top-n.bounds.top+n.baseline,{letterSpacing:o,writingMode:s}=n;if(o<=0||ka(s)){r(e.ctx,t.text,i,a);return}let c=i;for(let n of Bs(t.text))r(e.ctx,n,c,a),c+=e.ctx.measureText(n).width+o}renderShadowSilhouettes(e,t,n,r,i,a,o){let s=a.textShadow;if(!s.length)return null;let l=[];for(let a=s.length-1;a>=0;a--){let u=c(s,a),d=this.createGlyphLayer(t,n,r,i);if(d){d.ctx.shadowColor=z(u.color),d.ctx.shadowOffsetX=u.offsetX.number*this.scale,d.ctx.shadowOffsetY=u.offsetY.number*this.scale,d.ctx.shadowBlur=u.blur.number*this.scale,d.ctx.fillStyle=z(u.color);for(let t of e.container.textNodes)for(let e of t.textBounds)this.drawGlyphs(d,e,o,(e,t,n,r)=>{e.fillText(t,n,r)});l.push(d.canvas)}}return l.length?l:null}},wu=class e{surfaceRoot;surfaceBudget;canvas;ctx;context;options;backgroundRenderer;borderRenderer;borderImageRenderer;effectsRenderer;textRenderer;textClipRenderer;legacySubtree=!1;constructor(e,t,n,r={pixels:0}){this.surfaceRoot=n,this.surfaceBudget=r,this.context=e,this.options=t,this.canvas=t.canvas?t.canvas:e.resourceDocument.createElement(`canvas`);let i=this.canvas.getContext(`2d`);if(!i)throw t.canvas||Q(this.canvas),n?new Z(`Filter surface canvas is unavailable`):Error(`Failed to get 2D rendering context from canvas`);this.ctx=i,t.canvas||(this.canvas.width=Math.floor(t.width*t.scale),this.canvas.height=Math.floor(t.height*t.scale),this.canvas.style.width=`${t.width}px`,this.canvas.style.height=`${t.height}px`),this.ctx.scale(this.options.scale,this.options.scale),this.ctx.translate(-t.x,-t.y),this.ctx.textBaseline=`bottom`,t.imageSmoothing!==void 0&&(this.ctx.imageSmoothingEnabled=t.imageSmoothing),t.imageSmoothingQuality&&(this.ctx.imageSmoothingQuality=t.imageSmoothingQuality),this.backgroundRenderer=new Ul({ctx:this.ctx,context:this.context,canvas:this.canvas,options:{width:t.width,height:t.height,scale:t.scale}}),this.borderRenderer=new Yl({ctx:this.ctx},{path:e=>this.path(e),formatPath:e=>this.formatPath(e)}),this.borderImageRenderer=new Ql(this.ctx),this.effectsRenderer=new tu({ctx:this.ctx,scale:t.scale},{path:e=>this.path(e)}),this.textRenderer=new zl({ctx:this.ctx,options:{scale:t.scale}}),this.textClipRenderer=new Cu({ctx:this.ctx,context:this.context,scale:t.scale,createFontStyle:e=>this.textRenderer.createFontStyle(e)}),this.context.logger.debug(`Canvas renderer initialized (${t.width}x${t.height}) with scale ${t.scale}`)}async renderStack(e){let t=e.element.container.styles;if(t.isVisible()){let n=cl(t.filter),r=n!==null&&n.functions.length>0,i=t.maskImage.length>0,a=t.webkitBoxReflect,o=t.mixBlendMode!==K.NORMAL;if(e.element!==this.surfaceRoot&&!this.legacySubtree&&(i||a||o||n!==null&&(r||t.opacity<1))&&this.canComposite(e.element)){if(!await this.renderCompositedStack(e,n,i,a,o)){this.legacySubtree=!0;try{await this.renderStackContent(e)}finally{this.legacySubtree=!1}}return}await this.renderStackContent(e)}}canComposite(e){let t=e=>{let t=e.styles;return!t.isTransformed()&&t.zoom===1&&t.clipPath.type===0&&!H(t.display,2048)&&cl(t.filter)!==null},n=e=>t(e)&&e.elements.every(n),r=e.parent;for(;r&&r!==this.surfaceRoot;){if(!t(r.container))return!1;r=r.parent}return n(e.container)}async renderCompositedStack(t,n,r,i,o=!1){let s=this.options.signal;if(s?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);let c=Al(kl(t.element.container),new a(this.options.x,this.options.y,this.options.width,this.options.height),n?_l(n):0,this.options.scale);if(!c.width||!c.height)return!0;let l=El(this.surfaceBudget,Math.ceil(c.width*this.options.scale),Math.ceil(c.height*this.options.scale));if(!l)return this.context.logger.info(`Filter surface budget exceeded; using the existing renderer`),!1;let u={...this.options,canvas:void 0,backgroundColor:null,x:c.left,y:c.top,width:c.width,height:c.height},d,f;try{d=new e(this.context,u,t.element,this.surfaceBudget),await d.renderStackContent(t),d.effectsRenderer.applyEffects([]),n&&(f=await wl(d.canvas,n,t.element.container.styles.opacity,u.scale,s));let a=f??d.canvas;if(r&&await this.applyMask(a,t.element.container.styles,c),s?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);let l=t.element.effects,p=t.element.getEffects(4,this.surfaceRoot).filter(e=>!l.includes(e)||!Ic(e)&&!Nc(e)&&!Fc(e)&&!Mc(e));return this.effectsRenderer.applyEffects(p),o?(this.ctx.save(),this.ctx.globalCompositeOperation=t.element.container.styles.mixBlendMode,this.ctx.drawImage(a,u.x,u.y,a.width/u.scale,a.height/u.scale),this.ctx.restore()):this.ctx.drawImage(a,u.x,u.y,a.width/u.scale,a.height/u.scale),i&&await this.drawReflection(a,t.element.container.bounds,c,i),!0}catch(e){if(!(e instanceof Z))throw e;return this.context.logger.info(`${e.message}; using the existing renderer`),!1}finally{d&&Q(d.canvas),f&&Q(f),this.surfaceBudget.pixels-=l}}async applyMask(e,t,n){let r=e.getContext(`2d`);if(!r)return;let i=this.context.resourceDocument.createElement(`canvas`);i.width=e.width,i.height=e.height;let a=i.getContext(`2d`);if(!a)Q(i);else{a.scale(this.options.scale,this.options.scale),a.translate(-n.left,-n.top);try{await su(a,t.maskImage,t,{left:n.left,top:n.top,width:n.width,height:n.height},async e=>await this.context.cache.match(e))}catch(e){this.context.logger.error(`Error rendering mask-image: ${e instanceof Error?e.message:e}`),Q(i);return}r.save();try{r.setTransform(1,0,0,1,0,0),r.globalCompositeOperation=`destination-in`,r.drawImage(i,0,0)}finally{r.restore(),Q(i)}}}async drawReflection(e,t,n,r){let i=this.options.scale,a=Math.ceil(t.width*i),o=Math.ceil(t.height*i);if(a<=0||o<=0)return;let s=El(this.surfaceBudget,a,o);if(!s)return;let c,l;try{c=this.context.resourceDocument.createElement(`canvas`),c.width=a,c.height=o;let s=c.getContext(`2d`);if(!s)return;let u=Math.round((t.left-n.left)*i),d=Math.round((t.top-n.top)*i),f=r.direction===`left`||r.direction===`right`;s.save();try{f?(s.translate(a,0),s.scale(-1,1)):(s.translate(0,o),s.scale(1,-1)),s.drawImage(e,-u,-d)}finally{s.restore()}if(r.mask){l=this.context.resourceDocument.createElement(`canvas`),l.width=a,l.height=o;let e=l.getContext(`2d`);if(e){e.scale(i,i),await su(e,[r.mask],{maskPosition:[],maskRepeat:[],maskSize:[]},{left:0,top:0,width:t.width,height:t.height},async e=>await this.context.cache.match(e)),s.save();try{f?(s.translate(a,0),s.scale(-1,1)):(s.translate(0,o),s.scale(1,-1)),s.globalCompositeOperation=`destination-in`,s.drawImage(l,0,0,a,o)}finally{s.restore()}}}let p=r.offset,m=t.left,h=t.top;r.direction===`below`?h=t.top+t.height+p:r.direction===`above`?h=t.top-t.height-p:m=r.direction===`right`?t.left+t.width+p:t.left-t.width-p,this.ctx.save();try{this.ctx.filter=`none`,this.ctx.drawImage(c,m,h,t.width,t.height)}finally{this.ctx.restore()}}finally{c&&Q(c),l&&Q(l),this.surfaceBudget.pixels-=s}}async renderNode(e){if(e.container.debugRender)debugger;e.container.styles.isVisible()&&(await this.renderNodeBackgroundAndBorders(e),await this.renderNodeContent(e))}renderReplacedElement(e,t,n){let r=n.naturalWidth||e.intrinsicWidth,i=n.naturalHeight||e.intrinsicHeight;if(n&&r>0&&i>0){let a=Xc(e),o=Cc(t);this.path(o),this.ctx.save(),this.ctx.clip();let{sx:s,sy:c,sw:l,sh:u,dx:d,dy:f,dw:p,dh:m}=cu(r,i,a,e.styles.objectFit,e.styles.objectPosition);this.ctx.drawImage(n,s,c,l,u,d,f,p,m),this.ctx.restore()}}async renderNodeContent(t){this.effectsRenderer.applyEffects(t.getEffects(4,this.surfaceRoot));let n=t.container,r=t.curves,i=n.styles,a=Xc(n);for(let e of n.textNodes)await this.textRenderer.renderTextNode(e,i,a);await lu(this.ctx,this.context,{scale:this.options.scale,backgroundColor:this.options.backgroundColor,x:this.options.x,y:this.options.y,width:this.options.width,height:this.options.height},(t,n)=>new e(t,n),n,r,i,(e,t,n)=>this.renderReplacedElement(e,t,n)),uu(this.ctx,this.textRenderer,this.path.bind(this),n,i),await pu(this.ctx,this.context,this.textRenderer,t,n,i)}async renderStackContent(e){if(e.element.container.debugRender)debugger;let t=this.options.signal;await this.renderNodeBackgroundAndBorders(e.element);for(let n of e.negativeZIndex){if(t?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);await this.renderStack(n)}if(t?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);await this.renderNodeContent(e.element);for(let t of e.nonInlineLevel)await this.renderNode(t);for(let n of e.nonPositionedFloats){if(t?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);await this.renderStack(n)}for(let n of e.nonPositionedInlineLevel){if(t?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);await this.renderStack(n)}for(let t of e.inlineLevel)await this.renderNode(t);for(let n of e.zeroOrAutoZIndexOrTransformedOrOpacity){if(t?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);await this.renderStack(n)}for(let n of e.positiveZIndex){if(t?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);await this.renderStack(n)}}path(e){Vl(this.ctx,e)}formatPath(e){Bl(this.ctx,e)}async renderSurfaceBoxShadow(e,t){let n=t.spread.number,r=t.blur.number/2,i=Math.ceil(3*r)+1,o=e.container.bounds.add(-n,-n,2*n,2*n);if(o.width<=0||o.height<=0)return;let s=this.options.scale,c=Al(o.add(-i,-i,2*i,2*i),new a(this.options.x-t.offsetX.number,this.options.y-t.offsetY.number,this.options.width,this.options.height),i,s);if(!c.width||!c.height)return;let l=Math.ceil(c.width*s),u=Math.ceil(c.height*s),d=El(this.surfaceBudget,l,u);if(!d)throw new Z(`Box shadow surface budget exceeded`);let f,p;try{f=this.context.resourceDocument.createElement(`canvas`),f.width=l,f.height=u;let i=f.getContext(`2d`);if(!i)throw new Z(`Box shadow surface canvas is unavailable`);i.scale(s,s),i.translate(-c.left,-c.top),Vl(i,_c(xc(e.curves),-n,-n,2*n,2*n)),i.fillStyle=z(t.color),i.fill(),p=await wl(f,{functions:[{kind:`blur`,value:r}]},1,s,this.options.signal),this.ctx.save();try{this.ctx.beginPath(),this.ctx.rect(this.options.x,this.options.y,this.options.width,this.options.height),Bl(this.ctx,xc(e.curves)),this.ctx.closePath(),this.ctx.clip(`evenodd`),this.ctx.drawImage(p,c.left+t.offsetX.number,c.top+t.offsetY.number,p.width/s,p.height/s)}finally{this.ctx.restore()}}finally{f&&Q(f),p&&Q(p),this.surfaceBudget.pixels-=d}}async renderNodeBackgroundAndBorders(e){this.effectsRenderer.applyEffects(e.getEffects(2,this.surfaceRoot)),!this.surfaceRoot&&e.container.styles.backdropFilter&&await this.renderBackdropFilter(e);let t=e.container.styles,n=!R(t.backgroundColor)||t.backgroundImage.length,r=Eu(t),i=[{style:t.borderTopStyle,color:t.borderTopColor,width:t.borderTopWidth},{style:t.borderRightStyle,color:t.borderRightColor,width:t.borderRightWidth},{style:t.borderBottomStyle,color:t.borderBottomColor,width:t.borderBottomWidth},{style:t.borderLeftStyle,color:t.borderLeftColor,width:t.borderLeftWidth}],a=rl(t.backgroundClip,0),o=Tu(a,e.curves);if(n||t.boxShadow.length){r&&e.container.textNodes.length>0?await this.textClipRenderer.render(e):(this.ctx.save(),this.path(o),this.ctx.clip(),R(t.backgroundColor)||(this.ctx.fillStyle=z(t.backgroundColor),this.ctx.fill()),await this.backgroundRenderer.renderBackgroundImage(e.container),this.ctx.restore());for(let n of t.boxShadow.slice(0).reverse())this.surfaceRoot&&!n.inset?await this.renderSurfaceBoxShadow(e,n):await Su(this.ctx,e,n,this.options,this.surfaceBudget)}if(t.borderImageSource){let n=t.borderImageSource,r=e.container.bounds,i=[Math.max(0,t.borderTopWidth),Math.max(0,t.borderRightWidth),Math.max(0,t.borderBottomWidth),Math.max(0,t.borderLeftWidth)],a=null;if(n.type===0){let e=n.url;try{a=await this.context.cache.match(e)??null}catch{this.context.logger.error(`Error loading border-image ${e}`)}}else a=this.rasterizeGradientSource(n,r);if(a){let e=Zl(t.borderImageOutset,i),n=r.add(-e.left,-e.top,e.left+e.right,e.top+e.bottom),o=Xl(t.borderImageWidth,i,n);this.borderImageRenderer.renderBorderImage(r,a,t.borderImageSlice,t.borderImageRepeat,o[0],o[1],o[2],o[3],e)}return}let s=0;for(let t of i){if(t.style!==0&&!R(t.color)&&t.width>0){let n=async()=>{t.style===2?await this.borderRenderer.renderDashedDottedBorder(t.color,t.width,s,e.curves,2):t.style===3?await this.borderRenderer.renderDashedDottedBorder(t.color,t.width,s,e.curves,3):t.style===4?await this.borderRenderer.renderDoubleBorder(t.color,t.width,s,e.curves):await this.borderRenderer.renderSolidBorder(t.color,s,e.curves)},r=e.container.legendBounds;if(s===0&&r){let t=e.container.bounds,i=r.left-t.left,a=r.left+r.width-t.left;i>0&&(this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(t.left,t.top,i,t.height),this.ctx.clip(),await n(),this.ctx.restore());let o=t.left+a,s=t.width-a;s>0&&(this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(o,t.top,s,t.height),this.ctx.clip(),await n(),this.ctx.restore())}else await n()}s++}this.renderOutline(e)}renderOutline(e){let t=e.container.styles;if(t.outlineStyle===0||t.outlineStyle===1)return;let n=Math.max(0,t.outlineWidth);if(n<=0)return;let r=t.outlineColor??t.color;if(R(r))return;let i=Math.max(0,t.outlineOffset)+n/2,a=_c(xc(e.curves),-i,-i,2*i,2*i);this.ctx.save();try{this.ctx.strokeStyle=z(r),this.ctx.lineWidth=n,t.outlineStyle===3?this.ctx.setLineDash([n*3,n*3]):t.outlineStyle===4&&this.ctx.setLineDash([n,n*2]),this.path(a),this.ctx.stroke()}finally{this.ctx.restore()}}rasterizeGradientSource(e,t){let n=Math.max(1,Math.ceil(t.width)),r=Math.max(1,Math.ceil(t.height)),i=(this.ctx.canvas.ownerDocument??document).createElement(`canvas`);i.width=n,i.height=r;let a=i.getContext(`2d`);if(!a)return null;if(e.type===1||e.type===3){let t=e,[o,s,l,u,d]=Pr(t.angle,n,r),f=W(t.stops,o||n),p=e.type===3,m=p?Kc(f):null,h=a.createLinearGradient(s,l,u,d);if(m)m.forEach(e=>{h.addColorStop(Math.min(1,Math.max(0,e.stop)),e.color)});else if(p){let e=z(c(f,f.length-1).color);h.addColorStop(0,e),h.addColorStop(1,e)}else qc(f).forEach(e=>{h.addColorStop(e.stop,e.color)});return a.fillStyle=h,a.fillRect(0,0,n,r),i}if(e.type===2||e.type===4){let t=e,o=t.position.length===0?[P]:t.position,s=I(c(o,0),n),l=I(c(o,o.length-1),r),[u,d]=Ir(t,s,l,n,r);if(u<=0||d<=0)return null;let f=this.ctx.canvas.ownerDocument??document,p=Jc(f,u,d,t.stops,e.type===4);return p?(a.fillStyle=p.lastColor,a.fillRect(0,0,n,r),a.drawImage(p.canvas,s-u,l-d,u*2,d*2),Q(p.canvas),i):null}if(e.type===5||e.type===6){let t=e,o=I(c(t.position,0),n),s=I(c(t.position,1),r),l=a.createConicGradient(t.angle-Math.PI/2,o,s),u;if(e.type===6){let e=W(t.stops,1),n=c(e,0),r=c(e,e.length-1),i=Math.max(r.stop-n.stop,.01);u=[];let a=Math.ceil(1/i);for(let t=0;t<a;t++)for(let r of e){let e=t*i+(r.stop-n.stop);if(e>1)break;u.push({stop:e,color:z(r.color)})}let o=c(u,u.length-1);o&&o.stop<1&&u.push({stop:1,color:o.color})}else u=W(t.stops,Math.max(n,r)).map(e=>({stop:e.stop,color:z(e.color)}));return u.forEach(e=>{l.addColorStop(Math.min(1,Math.max(0,e.stop)),e.color)}),a.fillStyle=l,a.fillRect(0,0,n,r),i}return this.context.logger.warn(`Unsupported border-image source; only URL and gradient images are supported`),null}async renderBackdropFilter(e){let t=cl(e.container.styles.backdropFilter);if(!t||t.functions.length===0)return;let n=e.container.bounds;if(n.width<=0||n.height<=0)return;let r=this.options.scale,i=Math.ceil(n.width*r),a=Math.ceil(n.height*r);if(i<=0||a<=0)return;let o=El(this.surfaceBudget,i,a);if(!o)return;let s,c;try{s=this.context.resourceDocument.createElement(`canvas`),s.width=i,s.height=a;let e=s.getContext(`2d`);if(!e)return;let o=Math.round((n.left-this.options.x)*r),l=Math.round((n.top-this.options.y)*r);e.drawImage(this.canvas,o,l,i,a,0,0,i,a);try{c=await wl(s,t,1,r,this.options.signal)}catch(e){if(e instanceof Z){this.context.logger.info(`${e.message}; rendering without the backdrop effect`);return}throw e}if(this.options.signal?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);this.ctx.save();try{this.ctx.filter=`none`,this.ctx.drawImage(c,n.left,n.top,n.width,n.height)}finally{this.ctx.restore()}}finally{s&&Q(s),c&&Q(c),this.surfaceBudget.pixels-=o}}async render(e){try{this.options.backgroundColor&&(this.ctx.fillStyle=z(this.options.backgroundColor),this.ctx.fillRect(this.options.x,this.options.y,this.options.width,this.options.height));let t=Wc(e);return await this.renderStack(t),this.effectsRenderer.applyEffects([]),this.canvas}catch(e){throw this.options.canvas||Q(this.canvas),e}}};let Tu=(e,t)=>{switch(e){case 0:return xc(t);case 2:return Sc(t);default:return Cc(t)}},Eu=e=>e.backgroundClip.some(e=>e===3);var Du=class{canvas;ctx;options;context;constructor(e,t){this.context=e,this.options=t,this.canvas=t.canvas?t.canvas:e.resourceDocument.createElement(`canvas`);let n=this.canvas.getContext(`2d`);if(!n)throw Error(`Failed to get 2D rendering context from canvas`);this.ctx=n,this.canvas.width=Math.floor(t.width*t.scale),this.canvas.height=Math.floor(t.height*t.scale),this.canvas.style.width=`${t.width}px`,this.canvas.style.height=`${t.height}px`,this.ctx.scale(this.options.scale,this.options.scale),this.ctx.translate(-t.x,-t.y),this.context.logger.debug(`EXPERIMENTAL ForeignObject renderer initialized (${t.width}x${t.height} at ${t.x},${t.y}) with scale ${t.scale}`)}async render(e){if(this.options.signal?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);let t=ku(e),n=js(this.options.width,this.options.height,0,0,e),r=Ms(n);t();try{let e=await r;if(this.options.signal?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);return this.options.backgroundColor&&(this.ctx.fillStyle=z(this.options.backgroundColor),this.ctx.fillRect(this.options.x,this.options.y,this.options.width,this.options.height)),this.ctx.drawImage(e,this.options.x,this.options.y,this.options.width,this.options.height),this.canvas}catch(e){throw this.options.canvas||Q(this.canvas),e}}};let Ou=[`marginTop`,`marginRight`,`marginBottom`,`marginLeft`,`top`,`right`,`bottom`,`left`],ku=e=>{let t=e.style,n=Ou.map(e=>[e,t[e]]);for(let e of Ou)t[e]=e.startsWith(`margin`)?`0px`:`auto`;return()=>{for(let[e,r]of n)t[e]=r}};var Au=class{id;enabled;start;constructor({id:e,enabled:t}){this.id=e,this.enabled=t,this.start=Date.now()}debug(...e){this.enabled&&(typeof window<`u`&&window.console&&typeof console.debug==`function`?console.debug(this.id,`${this.getTime()}ms`,...e):this.info(...e))}getTime(){return Date.now()-this.start}info(...e){this.enabled&&typeof window<`u`&&window.console&&typeof console.info==`function`&&console.info(this.id,`${this.getTime()}ms`,...e)}warn(...e){this.enabled&&(typeof window<`u`&&window.console&&typeof console.warn==`function`?console.warn(this.id,`${this.getTime()}ms`,...e):this.info(...e))}error(...e){this.enabled&&(typeof window<`u`&&window.console&&typeof console.error==`function`?console.error(this.id,`${this.getTime()}ms`,...e):this.info(...e))}},ju=class{context;_options;_cache=/* @__PURE__ */ new Map;maxSize;_pendingOperations=/* @__PURE__ */ new Map;_deferMode=!1;_collectedUrls=/* @__PURE__ */ new Set;_evictionSuspendCount=0;get _evictionEnabled(){return this._evictionSuspendCount===0}constructor(e,t){if(this.context=e,this._options=t,this.maxSize=t.maxCacheSize??100,this.maxSize<1)throw Error(`Cache maxSize must be at least 1`);this.maxSize>1e4&&this.context.logger.warn(`Cache maxSize ${this.maxSize} is very large and may cause memory issues. Consider using a smaller value (recommended: 100-1000).`)}startDefer(){this._deferMode=!0,this._evictionSuspendCount++}async preloadAll(e=10,t,n){this._deferMode=!1;let r=Array.from(this._collectedUrls);this._collectedUrls.clear();try{if(r.length===0)return;let i=Math.max(1,Math.min(e,100));this.context.logger.debug(`Preloading ${r.length} image(s) with concurrency ${i}`);let a=0,o=n?new Promise((e,t)=>{let r=()=>t(new DOMException(`The operation was aborted.`,`AbortError`));n.aborted?r():n.addEventListener(`abort`,r,{once:!0})}):null;o?.catch(()=>void 0),t?.(0,r.length);for(let e=0;e<r.length;e+=i){q(n);let s=r.slice(e,e+i);s.map(e=>this._addImageWithPending(e));let c=Promise.allSettled(s.map(e=>this._cache.get(e)?.value??Promise.resolve()));await(o?Promise.race([c,o]):c),a+=s.length,t?.(a,r.length)}}finally{this._evictionSuspendCount=Math.max(0,this._evictionSuspendCount-1)}}addImage(e){if(this._deferMode)return!this.has(e)&&(Ru(e)||Fu(e))&&this._collectedUrls.add(e),Promise.resolve();let t=this._pendingOperations.get(e);if(t)return t;if(this.has(e)){let t=this._cache.get(e);return this._cache.delete(e),this._cache.set(e,t),Promise.resolve()}return Ru(e)||Fu(e)?this._addImageWithPending(e):Promise.resolve()}_addImageWithPending(e){let t=this._pendingOperations.get(e);if(t)return t;let n=this._addImageInternal(e);return this._pendingOperations.set(e,n),n.finally(()=>{this._pendingOperations.delete(e)}),n}async _addImageInternal(e){let t=this._options.imageTimeout??15e3,n=this.withTimeout(this.loadImage(e),t,`Timed out (${t}ms) loading image`);n.catch(t=>{let n=t instanceof Error?t.message:String(t),r=`Failed to load image ${e.substring(0,256)}: ${n}`;this.context.logger.error(r),this.context.onError?.(Error(r))}),this.set(e,n)}withTimeout(e,t,n){if(t<=0)return e;let r,i=new Promise((e,i)=>{r=setTimeout(()=>i(Error(n)),t)});return Promise.race([e,i]).finally(()=>{r!==void 0&&clearTimeout(r)})}match(e){let t=this._cache.get(e);if(t)return this._cache.delete(e),this._cache.set(e,t),t.value}set(e,t){if(this._cache.has(e))this._cache.delete(e);else if(this._evictionEnabled&&this._cache.size>=this.maxSize){let e=this._cache.keys().next().value;e!==void 0&&(this._cache.delete(e),this.context.logger.debug(`Cache: Evicted LRU entry: ${e}`))}this._cache.set(e,{value:t})}size(){return this._cache.size}getMaxSize(){return this.maxSize}clear(){this._cache.clear()}async loadImage(e){let t=this.context.originChecker,n=e=>t.isSameOrigin(e),r=typeof this._options.customIsSameOrigin==`function`?await this._options.customIsSameOrigin(e,n):n(e),i=!r&&this._options.allowTaint===!1&&!Iu(e)&&!Ru(e)&&typeof this._options.proxy!=`string`,a=!Iu(e)&&(this._options.useCORS===!0||i)&&Ns.SUPPORT_CORS_IMAGES&&!r,o=!Iu(e)&&!r&&!Ru(e)&&typeof this._options.proxy==`string`&&!a;if(!r&&this._options.allowTaint===!1&&!Iu(e)&&!Ru(e)&&!o&&!a)return;let s=e;o&&(s=await this.proxy(s)),this.context.logger.debug(`Added image ${e.substring(0,256)}`);let c=this.context.config.window.Image??Image;return await new Promise((e,t)=>{let n=new c;n.onload=()=>e(n),n.onerror=t,(Lu(s)||a)&&(n.crossOrigin=`anonymous`),n.src=s,n.complete===!0&&(typeof n.decode==`function`?n.decode().then(()=>e(n),()=>t(/* @__PURE__ */ Error(`Failed to decode image ${s.substring(0,256)}`))):setTimeout(()=>e(n),500))})}has(e){return this._cache.has(e)}keys(){return Promise.resolve(Array.from(this._cache.keys()))}proxy(e){let t=this._options.proxy;if(!t)throw Error(`No proxy defined`);let n=e.substring(0,256);return new Promise((r,i)=>{let a=new XMLHttpRequest;a.onload=()=>{if(a.status===200){let e=new FileReader;e.addEventListener(`load`,()=>r(e.result),!1),e.addEventListener(`error`,e=>i(e),!1),e.readAsDataURL(a.response)}else i(`Failed to proxy resource ${n} with status code ${a.status}`)},a.onerror=i;let o=t.indexOf(`?`)>-1?`&`:`?`;if(a.open(`GET`,`${t}${o}url=${encodeURIComponent(e)}&responseType=blob`),a.responseType=`blob`,this._options.imageTimeout){let e=this._options.imageTimeout;a.timeout=e,a.ontimeout=()=>i(`Timed out (${e}ms) proxying ${n}`)}a.send()})}};let Mu=/^data:image\/svg\+xml/i,Nu=/^data:image\/.*;base64,/i,Pu=/^data:image\/.*/i,Fu=e=>Ns.SUPPORT_SVG_DRAWING||!zu(e),Iu=e=>Pu.test(e),Lu=e=>Nu.test(e),Ru=e=>e.substring(0,4)===`blob`,zu=e=>e.slice(-3).toLowerCase()===`svg`||Mu.test(e);var Bu=class{baseUri;origin;constructor(e){if(!e||!e.document)throw Error(`Valid window object required for OriginChecker`);if(!e.location||!e.location.href)throw Error(`Window object must have valid location`);this.baseUri=e.location.href,this.origin=this.getOrigin(e.location.href)}getOrigin(e){try{return new URL(e,this.baseUri).origin}catch{return``}}isSameOrigin(e){return this.getOrigin(e)===this.origin}getContextOrigin(){return this.origin}},Vu=class e{static instanceCount=1;instanceName=`#${e.instanceCount++}`;logger;cache;originChecker;config;onError;_windowBounds;constructor(e,t,n){this.config=n,this.logger=new Au({id:this.instanceName,enabled:e.logging}),this.originChecker=new Bu(n.window),this.cache=e.cache??n.cache??new ju(this,e),this.onError=e.onError,this._windowBounds=t}get windowBounds(){return this._windowBounds}get resourceDocument(){return this.config.window.document||(typeof document<`u`?document:void 0)}adjustWindowBounds(e,t){this._windowBounds=this._windowBounds.add(e,t,0,0)}};let Hu=e=>{[`scale`,`width`,`height`,`imageTimeout`,`x`,`y`,`windowWidth`,`windowHeight`,`scrollX`,`scrollY`].forEach(t=>{let n=e[t];if(n!=null&&typeof n!=`number`){let r=Number(n);Number.isNaN(r)||(e[t]=r)}})},Uu=e=>({allowTaint:e.allowTaint??!1,imageTimeout:e.imageTimeout??15e3,proxy:e.proxy,useCORS:e.useCORS??!1,customIsSameOrigin:e.customIsSameOrigin,maxCacheSize:e.maxCacheSize}),Wu=(e,t,n)=>({logging:e.logging??!0,cache:e.cache??t.cache,...n}),Gu=(e,t)=>{let n=t;return{windowWidth:e.windowWidth??n.innerWidth??800,windowHeight:e.windowHeight??n.innerHeight??600,scrollX:e.scrollX??n.pageXOffset??0,scrollY:e.scrollY??n.pageYOffset??0}},Ku=(e,t,n)=>({allowTaint:e.allowTaint??!1,onclone:e.onclone,ignoreElements:e.ignoreElements,iframeContainer:e.iframeContainer,inlineImages:n,copyStyles:n,cspNonce:e.cspNonce??t.cspNonce,signal:e.signal}),qu=(e,t,n,r,i,a,o)=>({canvas:e.canvas,backgroundColor:t,signal:e.signal,scale:e.scale??o??1,x:(e.x??0)+n,y:(e.y??0)+r,width:e.width??Math.ceil(i),height:e.height??Math.ceil(a),imageSmoothing:e.imageSmoothing,imageSmoothingQuality:e.imageSmoothingQuality}),Ju=(e,t,n)=>{let r=t.ownerDocument,i=r.documentElement?Nn(e,getComputedStyle(r.documentElement).backgroundColor):0,a=r.body?Nn(e,getComputedStyle(r.body).backgroundColor):0,o=typeof n==`string`?Nn(e,n):n===null?0:4294967295;return t===r.documentElement?R(i)?R(a)?o:a:i:o},Yu=(e,t,n,r)=>{if(e)try{e(n,r)}catch(e){t.logger.error(`onProgress callback failed: ${e instanceof Error?e.message:String(e)}`)}},Xu=async(e,t,n)=>{if(Hu(t),!t.skipValidation){let n=t.validator||r(),i=n.validateElement(e);if(!i.valid)throw Error(i.error);let a=n.validateOptions(t);if(!a.valid)throw Error(`Invalid options: ${a.error}`)}if(!e||typeof e!=`object`)throw Error(`Invalid element provided as first argument`);let c=e.ownerDocument;if(!c)throw Error(`Element is not attached to a Document`);let l=c.defaultView;if(!l)throw Error(`Document is not attached to a Window`);let u=Uu(t),d=Wu(t,n,u),f=Gu(t,l),p=new a(f.scrollX,f.scrollY,f.windowWidth,f.windowHeight),m=new Vu(d,p,n),h=t.enablePerformanceMonitoring??t.logging??!1,g=new i(m,h);g.start(`total`,{width:f.windowWidth,height:f.windowHeight});let _=t.signal;q(_);let v=t.foreignObjectRendering??!1,y=Ku(t,n,v);m.logger.debug(`Starting document clone with size ${p.width}x${p.height} scrolled to ${-p.left},${-p.top}`),Yu(t.onProgress,m,`clone`,10),g.start(`clone`);let b=new Ts(m,e,y),x=b.clonedReferenceElement;if(!x)throw Error(`Unable to find element in cloned iframe`);let S,C,w;try{S=await b.toIFrame(c,p),g.end(`clone`),Yu(t.onProgress,m,`clone`,30),q(_);let{width:e,height:n,left:r,top:i}=Hn(x)||Bn(x)?s(x.ownerDocument):o(m,x),a=Ju(m,x,t.backgroundColor),u=qu(t,a,r,i,e,n,l.devicePixelRatio??1);v?(m.logger.debug(`Document cloned, using foreign object rendering`),g.start(`render-foreignobject`),C=await new Du(m,u).render(x),g.end(`render-foreignobject`)):(m.logger.debug(`Document cloned, element located at ${r},${i} with size ${e}x${n} using computed rendering`),m.logger.debug(`Starting DOM parsing`),g.start(`parse`),q(_),m.cache.startDefer(),w=pc(m,x,{normalizeDom:t.normalizeDom}),g.end(`parse`),Yu(t.onProgress,m,`parse`,50),g.start(`preload`),await m.cache.preloadAll(10,(e,n)=>{Yu(t.onProgress,m,`preload`,50+Math.round(e/n*10))},_),g.end(`preload`),Yu(t.onProgress,m,`layout`,60),a===w.styles.backgroundColor&&(w.styles.backgroundColor=0),m.logger.debug(`Starting renderer for element at ${u.x},${u.y} with size ${u.width}x${u.height}`),g.start(`render`),q(_),C=await new wu(m,u).render(w),g.end(`render`)),Yu(t.onProgress,m,`render`,90)}finally{g.start(`cleanup`);try{w&&w.restoreTree()}finally{S&&(t.removeContainer??!0)&&Ts.destroy(S),g.end(`cleanup`)}}return g.end(`total`),m.logger.debug(`Finished rendering`),h&&g.logSummary(),Yu(t.onProgress,m,`render`,100),C},Zu=(e,n={},r)=>{let i=r||t.fromElement(e,{cspNonce:n.cspNonce,cache:n.cache});return Xu(e,n,i)};e.Html2CanvasConfig=t,e.PerformanceMonitor=i,e.Validator=n,e.createDefaultValidator=r,e.default=Zu,e.html2canvas=Zu}),typeof window<`u`&&window.html2canvas&&window.html2canvas.default&&(window.html2canvasExports=window.html2canvas,window.html2canvas=window.html2canvas.default);
10
+ .${rs}:after${is}`,t)},os=(e,t,n)=>{let r=e.ownerDocument;if(r){let i=r.createElement(`style`);i.textContent=t,n&&(i.nonce=n),e.appendChild(i)}};var ss=class{context;counters;quoteDepth=0;constructor(e,t){this.context=e,this.counters=t}resolvePseudoContent(e,t,n,r){if(!n)return;let i=n.content,a=t.ownerDocument;if(!a||!i||i===`none`||i===`-moz-alt-content`||n.display===`none`)return;this.counters.parse(new Jo(this.context,n));let o=new qo(this.context,n),s=a.createElement(`html2canvaspseudoelement`);ts(n,s),o.content.forEach(t=>{if(t.type===0)s.appendChild(a.createTextNode(t.value));else if(t.type===22){let e=a.createElement(`img`);e.src=t.value,e.style.opacity=`1`,s.appendChild(e)}else if(t.type===18){if(t.name===`attr`){let n=t.values.filter(D);n.length&&n[0]&&s.appendChild(a.createTextNode(e.getAttribute(n[0].value)||``))}else if(t.name===`counter`){let[e,n]=t.values.filter(O);if(e&&D(e)){let t=this.counters.getCounterValue(e.value),r=n&&D(n)?rr.parse(this.context,n.value):3;s.appendChild(a.createTextNode(_r(t,r,!1)))}}else if(t.name===`counters`){let[e,n,r]=t.values.filter(O);if(e&&D(e)){let t=this.counters.getCounterValues(e.value),i=r&&D(r)?rr.parse(this.context,r.value):3,o=n&&n.type===0?n.value:``,c=t.map(e=>_r(e,i,!1)).join(o);s.appendChild(a.createTextNode(c))}}}else if(t.type===20)switch(t.value){case`open-quote`:s.appendChild(a.createTextNode(Er(o.quotes,this.quoteDepth++,!0)));break;case`close-quote`:{let e=this.quoteDepth>0;this.quoteDepth=Math.max(0,this.quoteDepth-1),e&&s.appendChild(a.createTextNode(Er(o.quotes,this.quoteDepth,!1)));break}default:s.appendChild(a.createTextNode(t.value))}}),s.className=`${ns} ${rs}`;let c=r===0?` ${ns}`:` ${rs}`;return Ln(t)?t.className.baseValue+=c:t.className+=c,s}};let q=e=>{if(e?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`)},cs=/* @__PURE__ */ new WeakMap,ls=e=>{let t=e&&e.trustedTypes;if(!t)return null;if(cs.has(t))return cs.get(t)??null;let n=null;try{n=t.getPolicy?.(`html2canvas-pro`)??t.createPolicy(`html2canvas-pro`,{createHTML:e=>e})}catch{n=null}return cs.set(t,n),n},us=(e,t,n)=>{let r=e.createElement(`iframe`);r.className=`html2canvas-container`,r.style.visibility=`hidden`,r.style.position=`fixed`,r.style.left=`-10000px`,r.style.top=`0px`,r.width=t.width.toString(),r.height=t.height.toString();let i=[[`width`,`${t.width}px`],[`height`,`${t.height}px`],[`min-width`,`0px`],[`max-width`,`none`],[`min-height`,`0px`],[`max-height`,`none`],[`box-sizing`,`content-box`],[`padding`,`0px`],[`border`,`0`]];for(let[e,t]of i)r.style.setProperty(e,t,`important`);return r.scrolling=`no`,r.setAttribute(`data-html2canvas-ignore`,`true`),(n||e.body).appendChild(r),r},ds=e=>new Promise(t=>{e.complete?t():e.src?(e.onload=t,e.onerror=t):t()}),fs=e=>Promise.all([].slice.call(e.images,0).map(ds)),ps=(e,t=0)=>{if(!e||t>ms)return!0;let n;try{n=e.cssRules}catch{return!0}if(!n)return!0;for(let e=0;e<n.length;e++){let r=n[e];if(!r||!(`styleSheet`in r))continue;let i=r.styleSheet;if(!i||!ps(i,t+1))return!1}return!0},ms=32,hs=(e,t)=>{let n=e.querySelectorAll(`link`);for(let e=0;e<n.length;e++){let r=n[e];r&&t.push(r)}let r=(e.ownerDocument??e).createTreeWalker(e,NodeFilter.SHOW_ELEMENT),i=r.nextNode();for(;i;){let e=i.shadowRoot;e&&hs(e,t),i=r.nextNode()}},gs=(e,t,n,r=1e4)=>{if(n?.aborted)return Promise.resolve();let i=[],a=[];hs(e,a);for(let e of a){if(e.sheet)continue;let a=(e.getAttribute(`rel`)??``).trim().toLowerCase().split(/\s+/);a.includes(`stylesheet`)&&!a.includes(`alternate`)&&!e.disabled&&e.getAttribute(`href`)&&i.push(new Promise(i=>{let a=e.href,o=()=>{e.removeEventListener(`load`,o),e.removeEventListener(`error`,o),n?.removeEventListener(`abort`,s),clearInterval(l),i()},s=()=>o();if(e.sheet){i();return}e.addEventListener(`load`,o),e.addEventListener(`error`,o),n?.addEventListener(`abort`,s,{once:!0});let c=0,l=setInterval(()=>{c+=50,e.sheet?o():c>=r&&(t?.warn(`Stylesheet ${a} did not finish loading within ${r/1e3}s; continuing with a possibly unstyled clone`),o())},50)}))}let o=e.getElementsByTagName(`style`);for(let e=0;e<o.length;e++){let n=o[e],a=n?.sheet;a&&n?.textContent?.includes(`@import`)&&(ps(a)||i.push(new Promise(e=>{let i=0,a=setInterval(()=>{i+=50;let o=n.sheet;(o&&ps(o)||i>=r)&&(i>=r&&!ps(o??null)&&t?.warn(`@import chain in an inline <style> did not finish loading within ${r/1e3}s; continuing with a possibly unstyled clone`),clearInterval(a),e())},50)})))}return i.length===0?Promise.resolve():Promise.all(i).then(()=>void 0)},_s=(e,t,n)=>new Promise((r,i)=>{let a=e.contentWindow;if(!a)return i(`No window assigned for iframe`);let o=a.document,s,c=setTimeout(()=>{s&&clearInterval(s),i(/* @__PURE__ */ Error(`Cloned iframe did not fire its load event within ${Lo}ms`))},Lo),l=()=>{s&&clearInterval(s),clearTimeout(c),i(new DOMException(`The operation was aborted.`,`AbortError`))};a.onload=e.onload=()=>{a.onload=e.onload=null;let i=0;s=setInterval(()=>{i++,n?.aborted?l():o.body.childNodes.length>0&&o.readyState===`complete`?(clearInterval(s),s=void 0,clearTimeout(c),r(e)):i>=600&&(clearInterval(s),s=void 0,t?.warn(`Cloned iframe did not become ready within 30 seconds; continuing with a possibly incomplete document`),r(e))},50)},n&&(n.aborted?l():n.addEventListener(`abort`,l,{once:!0}))}),vs=e=>e.replace(/[<>&"'`\\]|[\u0000-\u001f\u007f]/g,``),ys=e=>{let t=``;return e&&(t+=`<!DOCTYPE `,e.name&&(t+=vs(e.name)),e.internalSubset&&(t+=` `+vs(e.internalSubset)),e.publicId?(t+=` PUBLIC "`+vs(e.publicId)+`"`,e.systemId&&(t+=` "`+vs(e.systemId)+`"`)):e.systemId&&(t+=` SYSTEM "`+vs(e.systemId)+`"`),t+=`>`),t},bs=(e,t,n)=>{e&&e.defaultView&&(t!==e.defaultView.pageXOffset||n!==e.defaultView.pageYOffset)&&e.defaultView.scrollTo(t,n)},xs=([e,t,n])=>{e.scrollLeft=t,e.scrollTop=n},Ss=(e,t)=>{let n=e.ownerDocument.createElement(`base`);n.href=t;let r=e.getElementsByTagName(`head`).item(0);r?.insertBefore(n,r?.firstChild??null)},Cs=(e,t,n,r)=>{let i=us(t,n,r.container);if(!i.contentWindow)throw Error(`Unable to find iframe window`);let a=t.defaultView.pageXOffset,o=t.defaultView.pageYOffset,s=i.contentWindow,c=s.document,l=_s(i,e.logger,r.signal).then(async()=>{r.scrolledElements.forEach(xs),s&&s.scrollTo(n.left,n.top);let t=r.onclone,a=r.clonedReferenceElement;if(a===void 0)throw Error(`Error finding the ${r.referenceElementName} in the cloned document`);return q(r.signal),await p,q(r.signal),c.fonts&&c.fonts.ready&&await c.fonts.ready,q(r.signal),/(AppleWebKit)/g.test(navigator.userAgent)&&(await fs(c),q(r.signal)),typeof t==`function`&&await Promise.resolve().then(()=>t(c,a)),s.scrollTo(n.left,n.top),/AppleWebKit/g.test(navigator.userAgent)&&(s.scrollY!==n.top||s.scrollX!==n.left)&&(e.logger.warn(`Unable to restore scroll position for cloned document`),e.adjustWindowBounds(s.scrollX-n.left,s.scrollY-n.top)),i}),u=t.baseURI;c.open();let d=ys(t.doctype)+`<html></html>`;try{let e=ls(t.defaultView),n=e?e.createHTML(d):d;c.write(n)}catch{c.write(d)}bs(t,a,o),c.close();let f=c.adoptNode(r.documentElement);Ss(f,u),c.replaceChild(f,c.documentElement);let p=gs(c,e.logger,r.signal);return l.catch(e=>{throw i.parentNode?.removeChild(i),e})},ws=e=>{let t=e;for(;t;){if(t.parentNode&&t.parentNode.host)return t.parentNode;let e=t.getRootNode();if(e&&e!==t.ownerDocument&&e.host)return e;t=t.parentNode}return null};var Ts=class{context;options;scrolledElements;referenceElement;clonedReferenceElement;documentElement;counters;pseudoContents;slotCloner;constructor(e,t,n){if(this.context=e,this.options=n,this.scrolledElements=[],this.referenceElement=t,this.counters=new ir,this.pseudoContents=new ss(e,this.counters),this.slotCloner=new $o((e,t)=>this.cloneNode(e,t),{ignoreElements:n.ignoreElements,copyStyles:n.copyStyles??!0,cspNonce:n.cspNonce},e),!t.ownerDocument)throw Error(`Cloned element does not have an owner document`);if(!this.options.iframeContainer){let e=ws(t);e&&(this.options.iframeContainer=e)}this.documentElement=this.cloneNode(t.ownerDocument.documentElement,!1),this.appendDocumentAdoptedStyles(t.ownerDocument),this.appendPseudoHideStyles()}appendDocumentAdoptedStyles(e){if(this.options.copyStyles)return;let t=e.adoptedStyleSheets;if(!t||t.length===0)return;let n=this.documentElement.getElementsByTagName(`head`).item(0);if(!n)return;let r=Qo(this.documentElement.ownerDocument??e,t,this.options.cspNonce);r&&n.appendChild(r)}appendPseudoHideStyles(){let e=this.documentElement.getElementsByTagName(`head`).item(0);as(e??this.documentElement,this.options.cspNonce)}toIFrame(e,t){return Cs(this.context,e,t,{documentElement:this.documentElement,clonedReferenceElement:this.clonedReferenceElement,referenceElementName:this.referenceElement.nodeName,scrolledElements:this.scrolledElements,onclone:this.options.onclone,container:this.options.iframeContainer,signal:this.options.signal})}createElementClone(e){if(Xo(e,2))debugger;if(Un(e))return this.createCanvasClone(e);if(Wn(e))return this.createVideoClone(e);if(qn(e))return this.createStyleClone(e);let t=e.cloneNode(!1);return Gn(t)&&(Gn(e)&&e.currentSrc&&e.currentSrc!==e.src&&(t.src=e.currentSrc,t.srcset=``),t.loading===`lazy`&&(t.loading=`eager`)),er(t)&&!Ln(t)?this.createCustomElementClone(e,t):t}createCustomElementClone(e,t){let n=document.createElement(`div`);n.className=t.className,ts(t.style,n);let r=t.attributes;for(let e=0;e<r.length;e++){let t=r.item(e);t&&t.name!==`class`&&t.name!==`style`&&n.setAttribute(t.name,t.value)}if(e.shadowRoot)try{n.attachShadow({mode:`open`})}catch(e){this.context.logger.error(`Failed to attach shadow root to custom element clone:`,e)}return n}createStyleClone(e){try{let t=e.sheet;if(t&&t.cssRules){let n=[].slice.call(t.cssRules,0).reduce((e,t)=>t&&typeof t.cssText==`string`?e+t.cssText:e,``),r=e.cloneNode(!1);return r.textContent=n,this.options.cspNonce&&(r.nonce=this.options.cspNonce),r}}catch(e){if(this.context.logger.error(`Unable to access cssRules property`,e),e.name!==`SecurityError`)throw e}let t=e.cloneNode(!1);return this.options.cspNonce&&(t.nonce=this.options.cspNonce),t}createCanvasClone(e){if(this.options.inlineImages&&e.ownerDocument){let t=e.ownerDocument.createElement(`img`);try{return t.src=e.toDataURL(),t}catch{this.context.logger.info(`Unable to inline canvas contents, canvas is tainted`,e)}}let t=e.cloneNode(!1);try{t.width=e.width,t.height=e.height;let n=e.getContext(`2d`),r=t.getContext(`2d`,{willReadFrequently:!0});if(r){if(!this.options.allowTaint&&n)r.putImageData(n.getImageData(0,0,e.width,e.height),0,0);else{let t=e.getContext(`webgl2`)??e.getContext(`webgl`);t&&t.getContextAttributes()?.preserveDrawingBuffer===!1&&this.context.logger.warn(`Unable to clone WebGL context as it has preserveDrawingBuffer=false`,e),r.drawImage(e,0,0)}}return t}catch{this.context.logger.info(`Unable to clone canvas as it is tainted`,e)}return t}createVideoClone(e){let t=e.ownerDocument.createElement(`canvas`);t.width=e.offsetWidth,t.height=e.offsetHeight;let n=t.getContext(`2d`);try{return n&&(n.drawImage(e,0,0,t.width,t.height),this.options.allowTaint||n.getImageData(0,0,t.width,t.height)),t}catch{this.context.logger.info(`Unable to clone video as it is tainted`,e)}let r=e.ownerDocument.createElement(`canvas`);return r.width=e.offsetWidth,r.height=e.offsetHeight,r}appendChildNode(e,t,n){this.slotCloner.appendChildNode(e,t,n)}cloneChildNodes(e,t,n){this.slotCloner.cloneChildNodes(e,t,n)}cloneNode(e,t){if(In(e))return(e.ownerDocument??document).createTextNode(e.data);if(!e.ownerDocument)return e.cloneNode(!1);let n=e.ownerDocument.defaultView;if(n&&Fn(e)&&(Rn(e)||Ln(e))){let r=this.createElementClone(e);r.style.transitionProperty=`none`;let i=n.getComputedStyle(e),a=nr(e);this.referenceElement===e&&Rn(r)&&(this.clonedReferenceElement=r);let o=this.counters.parse(new Jo(this.context,i));if(a){let t=n.getComputedStyle(e,`:before`),i=this.pseudoContents.resolvePseudoContent(e,r,t,0);i&&r.insertBefore(i,r.firstChild)}if(er(e)&&(t=!0),Wn(e)||this.cloneChildNodes(e,r,t),a){let t=n.getComputedStyle(e,`:after`),i=this.pseudoContents.resolvePseudoContent(e,r,t,1);i&&r.appendChild(i)}return this.counters.pop(o),(i&&(this.options.copyStyles||Ln(e))&&!Kn(e)||t)&&ts(i,r),(e.scrollTop!==0||e.scrollLeft!==0)&&this.scrolledElements.push([r,e.scrollLeft,e.scrollTop]),(Yn(e)||Xn(e))&&(Yn(r)||Xn(r))&&(r.value=e.value),r}return e.cloneNode(!1)}static destroy(e){return e.parentNode?(e.parentNode.removeChild(e),!0):!1}},Es=class{static normalizeElement(e,t){let n={};if(!Rn(e)&&!Ln(e))return n;t.animationDuration.some(e=>e>0)&&(n.animationDuration=e.style.animationDuration,e.style.animationDuration=`0s`),t.transform!==null&&(n.transform=e.style.transform,e.style.transform=`translate(0, 0)`);let r=!1;return t.rotate!==null&&(n.rotate=e.style.rotate,e.style.rotate=`0deg`,r=!0),t.translate!==null&&(n.translate=e.style.translate,e.style.translate=`0px`,r=!0),t.scale!==null&&(n.scale=e.style.scale,e.style.scale=`1`,r=!0),r&&n.transform===void 0&&(n.transform=e.style.transform,e.style.transform=`translate(0, 0)`),n}static restoreElement(e,t){(Rn(e)||Ln(e))&&(t.animationDuration!==void 0&&(e.style.animationDuration=t.animationDuration),t.transform!==void 0&&(e.style.transform=t.transform),t.rotate!==void 0&&(e.style.rotate=t.rotate),t.translate!==void 0&&(e.style.translate=t.translate),t.scale!==void 0&&(e.style.scale=t.scale))}};let Ds={x:`-10%`,y:`-10%`,width:`120%`,height:`120%`},Os=[`color-interpolation-filters`,`flood-color`,`flood-opacity`,`lighting-color`],ks=/^(["']?)(#[^"'\s()]+)\1$/,As=/url\(\s*([^)]*?)\s*\)/g,js=e=>{let t=ks.exec(e.trim());return t?t[2]:null};function Ms(e,t,n){if(!t||t.indexOf(`url(`)===-1)return;let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Set;for(let a of t.matchAll(As)){let t=js(a[1]);if(!t||i.has(t))continue;i.add(t);let o=Ns(e.ownerDocument,t,n);o&&r.set(t,o)}return r}function Ns(e,t,n){let r=e.getElementById(t.slice(1));if(!r||r.namespaceURI!==`http://www.w3.org/2000/svg`||r.localName!==`filter`||!Fs(r))return null;let i=Is(r,n);if(!i)return null;let a=r.cloneNode(!0);Ls(r,a),a.removeAttribute(`id`),a.setAttribute(`filterUnits`,`userSpaceOnUse`),Object.keys(i).forEach(e=>a.setAttribute(e,String(i[e])));let o=Math.max(0,-i.x,-i.y,i.x+i.width-n.width,i.y+i.height-n.height);return{element:a,region:i,outset:Math.ceil(o)}}let Ps=e=>e.hasAttribute(`href`)||e.hasAttributeNS(`http://www.w3.org/1999/xlink`,`href`);function Fs(e){if(e.getAttribute(`primitiveUnits`)===`objectBoundingBox`||Ps(e))return!1;for(let t of Array.from(e.querySelectorAll(`*`))){if(t.localName===`feImage`||Ps(t))return!1;for(let e of[`x`,`y`,`width`,`height`])if((t.getAttribute(e)??``).indexOf(`%`)!==-1)return!1}return!0}function Is(e,t){let n=e.getAttribute(`filterUnits`)!==`userSpaceOnUse`,r=(t,r)=>{let i=(e.getAttribute(t)??(n?Ds[t]:``)).trim();if(i===``)return null;let a=i.endsWith(`%`),o=Number(a?i.slice(0,-1):i.replace(/px$/,``));return Number.isFinite(o)?n?(a?o/100:o)*r:a?null:o:null},i=r(`x`,t.width),a=r(`y`,t.height),o=r(`width`,t.width),s=r(`height`,t.height);return i===null||a===null||o===null||s===null||o<=0||s<=0?null:{x:i,y:a,width:o,height:s}}function Ls(e,t){let n=e.ownerDocument.defaultView;if(!n)return;let r=[e,...Array.from(e.querySelectorAll(`*`))],i=[t,...Array.from(t.querySelectorAll(`*`))];r.forEach((e,t)=>{let r=n.getComputedStyle(e);for(let e of Os){let n=r.getPropertyValue(e);n&&i[t]?.setAttribute(e,n)}})}var Rs=class{context;styles;textNodes=[];elements=[];bounds;legendBounds;filterReferences;createsStackingContext=!1;createsRealStackingContext=!1;isListOwner=!1;debugRender=!1;originalStyles;originalElement;constructor(e,t,n={}){if(this.context=e,Xo(t,3))debugger;if(this.styles=new Go(e,e.config.window.getComputedStyle(t,null)),n.normalizeDom!==!1&&(Rn(t)||Ln(t))&&(this.originalStyles=Es.normalizeElement(t,this.styles),this.originalElement=t),this.bounds=o(this.context,t),t.tagName===`FIELDSET`){let e=t.querySelector(`:scope > legend`);if(e){let t=o(this.context,e);this.legendBounds=t;let n=t.top+t.height/2-this.styles.borderTopWidth/2;this.bounds=new a(this.bounds.left,n,this.bounds.width,this.bounds.height-(n-this.bounds.top))}}this.filterReferences=Ms(t,this.styles.filter,this.bounds),Xo(t,4)&&(this.debugRender=!0)}restore(){this.originalStyles&&this.originalElement&&(Es.restoreElement(this.originalElement,this.originalStyles),this.originalStyles=void 0,this.originalElement=void 0)}restoreTree(){this.restore();for(let e of this.elements)e.restoreTree()}};let zs=e=>{if(e.createRange){let t=e.createRange();if(t.getBoundingClientRect){let n=e.createElement(`boundtest`);n.style.height=`123px`,n.style.display=`block`,e.body.appendChild(n),t.selectNode(n);let r=t.getBoundingClientRect(),i=Math.round(r.height);if(e.body.removeChild(n),i===123)return!0}}return!1},Bs=()=>new Image().crossOrigin!==void 0,Vs=e=>{let t=new Image,n=e.createElement(`canvas`),r=n.getContext(`2d`);if(!r)return!1;t.src=`data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'></svg>`;try{r.drawImage(t,0,0),n.toDataURL()}catch{return!1}return!0},Hs=(e,t,n,r,i)=>{let a=`http://www.w3.org/2000/svg`,o=document.createElementNS(a,`svg`),s=document.createElementNS(a,`foreignObject`);return o.setAttributeNS(null,`width`,e.toString()),o.setAttributeNS(null,`height`,t.toString()),s.setAttributeNS(null,`width`,`100%`),s.setAttributeNS(null,`height`,`100%`),s.setAttributeNS(null,`x`,n.toString()),s.setAttributeNS(null,`y`,r.toString()),s.setAttributeNS(null,`externalResourcesRequired`,`true`),o.appendChild(s),s.appendChild(i),o},Us=e=>new Promise((t,n)=>{let r=new Image;r.onload=()=>t(r),r.onerror=n,r.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(new XMLSerializer().serializeToString(e))}`}),Ws={get SUPPORT_RANGE_BOUNDS(){"use strict";let e=zs(document);return Object.defineProperty(Ws,"SUPPORT_RANGE_BOUNDS",{value:e}),e},get SUPPORT_SVG_DRAWING(){"use strict";let e=Vs(document);return Object.defineProperty(Ws,"SUPPORT_SVG_DRAWING",{value:e}),e},get SUPPORT_CORS_IMAGES(){"use strict";let e=Bs();return Object.defineProperty(Ws,"SUPPORT_CORS_IMAGES",{value:e}),e}};var Gs=class{text;bounds;constructor(e,t){this.text=e,this.bounds=t}};let Ks=(e,t,n,r)=>{let i=$s(t,n),o=[],s=0;return i.forEach(t=>{if(n.textDecorationLine.length||t.trim().length>0){if(Ws.SUPPORT_RANGE_BOUNDS){let n=Js(r,s,t.length).getClientRects();if(n.length>1){let n=Zs(t),i=0;n.forEach(t=>{o.push(new Gs(t,a.fromDOMRectList(e,Js(r,i+s,t.length).getClientRects()))),i+=t.length})}else o.push(new Gs(t,a.fromDOMRectList(e,n)))}else{let n=r.splitText(t.length);o.push(new Gs(t,qs(e,r))),r=n}}else Ws.SUPPORT_RANGE_BOUNDS||(r=r.splitText(t.length));s+=t.length}),o},qs=(e,t)=>{let n=t.ownerDocument;if(n){let r=n.createElement(`html2canvaswrapper`);r.appendChild(t.cloneNode(!0));let i=t.parentNode;if(i){i.replaceChild(r,t);let n=o(e,r);return r.firstChild&&i.replaceChild(r.firstChild,r),n}}return a.EMPTY},Js=(e,t,n)=>{let r=e.ownerDocument;if(!r)throw Error(`Node has no owner document`);let i=r.createRange();return i.setStart(e,t),i.setEnd(e,t+n),i},Ys=/* @__PURE__ */ new Map,Xs=e=>{let t=Ys.get(e);return t||(t=new Intl.Segmenter(void 0,{granularity:e}),Ys.set(e,t)),t},Zs=e=>Array.from(Xs(`grapheme`).segment(e),e=>e.segment),Qs=e=>Array.from(Xs(`word`).segment(e),e=>e.segment),$s=(e,t)=>ka(t.writingMode)?Zs(e):t.letterSpacing===0?Qs(e):Zs(e);var ec=class{text;textBounds;constructor(e,t,n){this.text=tc(t.data,n.textTransform),this.text.length!==t.data.length&&(t.data=this.text),this.textBounds=Ks(e,this.text,n,t)}};let tc=(e,t)=>{switch(t){case 1:return e.toLowerCase();case 3:return e.replace(nc,rc);case 2:return e.toUpperCase();default:return e}},nc=/(^|\s|:|-|\(|\))([a-z])/g,rc=(e,t,n)=>e.length>0?t+n.toUpperCase():e;var ic=class extends Rs{src;intrinsicWidth;intrinsicHeight;constructor(e,t,n={}){super(e,t,n),this.src=t.currentSrc||t.src,this.intrinsicWidth=t.naturalWidth,this.intrinsicHeight=t.naturalHeight,this.context.cache.addImage(this.src)}},ac=class extends Rs{canvas;intrinsicWidth;intrinsicHeight;constructor(e,t,n={}){super(e,t,n),this.canvas=t,this.intrinsicWidth=t.width,this.intrinsicHeight=t.height}};let oc=[`position`,`inset`,`top`,`right`,`bottom`,`left`,`inset-inline`,`inset-inline-start`,`inset-inline-end`,`inset-block`,`inset-block-start`,`inset-block-end`,`margin`,`margin-top`,`margin-right`,`margin-bottom`,`margin-left`,`margin-inline`,`margin-inline-start`,`margin-inline-end`,`margin-block`,`margin-block-start`,`margin-block-end`],sc=(e,t)=>{let n=t.getAttribute(`style`);oc.forEach(e=>t.style.removeProperty(e));let r=e.serializeToString(t);return n===null?t.removeAttribute(`style`):t.setAttribute(`style`,n),r};var cc=class extends Rs{svg;intrinsicWidth;intrinsicHeight;constructor(e,t,n={}){super(e,t,n);let r=new XMLSerializer,i=o(e,t);t.setAttribute(`width`,`${i.width}px`),t.setAttribute(`height`,`${i.height}px`),this.svg=`data:image/svg+xml,${encodeURIComponent(sc(r,t))}`,this.intrinsicWidth=t.width.baseVal.value,this.intrinsicHeight=t.height.baseVal.value,this.context.cache.addImage(this.svg)}},lc=class extends Rs{value;constructor(e,t,n={}){super(e,t,n),this.value=t.value}},uc=class extends Rs{start;reversed;constructor(e,t,n={}){super(e,t,n),this.start=t.start,this.reversed=typeof t.reversed==`boolean`&&t.reversed===!0}};let dc=[{type:15,flags:0,unit:`px`,number:3}],fc=[{type:16,flags:0,number:50}],pc=e=>e.width>e.height?new a(e.left+(e.width-e.height)/2,e.top,e.height,e.height):e.width<e.height?new a(e.left,e.top+(e.height-e.width)/2,e.width,e.width):e,mc=e=>{let t=e.type===`password`?Array(e.value.length+1).join(`•`):e.value;return t.length===0?e.placeholder||``:t},hc=e=>e.value.length===0&&!!e.placeholder;var gc=class extends Rs{type;checked;value;isPlaceholder;constructor(e,t,n={}){switch(super(e,t,n),this.type=t.type.toLowerCase(),this.checked=t.checked,this.value=mc(t),this.isPlaceholder=hc(t),(this.type===`checkbox`||this.type===`radio`)&&(this.styles.backgroundColor=3739148031,this.styles.borderTopColor=this.styles.borderRightColor=this.styles.borderBottomColor=this.styles.borderLeftColor=2779096575,this.styles.borderTopWidth=this.styles.borderRightWidth=this.styles.borderBottomWidth=this.styles.borderLeftWidth=1,this.styles.borderTopStyle=this.styles.borderRightStyle=this.styles.borderBottomStyle=this.styles.borderLeftStyle=1,this.styles.backgroundClip=[0],this.styles.backgroundOrigin=[0],this.bounds=pc(this.bounds)),this.type){case`checkbox`:this.styles.borderTopRightRadius=this.styles.borderTopLeftRadius=this.styles.borderBottomRightRadius=this.styles.borderBottomLeftRadius=dc;break;case`radio`:this.styles.borderTopRightRadius=this.styles.borderTopLeftRadius=this.styles.borderBottomRightRadius=this.styles.borderBottomLeftRadius=fc}}},_c=class extends Rs{value;constructor(e,t,n={}){super(e,t,n);let r=t.options[t.selectedIndex||0];this.value=r&&r.text||``}},vc=class extends Rs{value;constructor(e,t,n={}){super(e,t,n),this.value=t.value}},yc=class extends Rs{src;width;height;tree;backgroundColor;parseTreeFn;constructor(e,t,n,r={}){super(e,t,r),this.src=t.src,this.width=parseInt(t.width,10)||0,this.height=parseInt(t.height,10)||0,this.backgroundColor=this.styles.backgroundColor,this.parseTreeFn=n;try{let n=t.contentWindow,r=n?.document;if(n&&r&&r.documentElement&&this.parseTreeFn){this.tree=this.parseTreeFn(e,r.documentElement);let t=Nn(e,n.getComputedStyle(r.documentElement).backgroundColor),i=r.body?Nn(e,n.getComputedStyle(r.body).backgroundColor):0;this.backgroundColor=R(t)?R(i)?this.styles.backgroundColor:i:t}}catch(e){let t=e instanceof Error?e:Error(String(e));this.context.logger.warn(`Unable to render iframe content${this.src?` from ${this.src}`:``}: ${t.message}`),this.context.onError?.(t)}}};let bc=[`OL`,`UL`,`MENU`],xc=(e,t,n,r,i=1,a={})=>{for(let o=t.firstChild,s;o;o=s)s=o.nextSibling,Sc(e,o,n,r,i,a)},Sc=(e,t,n,r,i=1,o={})=>{if(In(t)&&t.data.length>0){let r=new ec(e,t,n.styles);if(i!==1){let e=n.bounds.left,t=n.bounds.top;r.textBounds=r.textBounds.map(n=>new Gs(n.text,new a(e+(n.bounds.left-e)/i,t+(n.bounds.top-t)/i,n.bounds.width/i,n.bounds.height/i)))}n.textNodes.push(r)}else if(Fn(t)){if(Zn(t)&&t.assignedNodes)t.assignedNodes().forEach(t=>Sc(e,t,n,r,i,o));else{let s=Cc(e,t,o),c=s.styles.zoom||1;if(c!==1&&(s.bounds=new a(s.bounds.left,s.bounds.top,s.bounds.width/c,s.bounds.height/c)),s.styles.isVisible()){Tc(t,s,r)?s.createsRealStackingContext=!0:Ec(s.styles)&&(s.createsStackingContext=!0),bc.indexOf(t.tagName)!==-1&&(s.isListOwner=!0),n.elements.push(s);let a=i*(s.styles.zoom||1);t.shadowRoot?xc(e,t.shadowRoot,s,r,a,o):!Yn(t)&&!Vn(t)&&!Xn(t)&&xc(e,t,s,r,a,o)}}}},Cc=(e,t,n={})=>Gn(t)?new ic(e,t,n):Un(t)?new ac(e,t,n):Vn(t)?new cc(e,t,n):Qn(t)?new lc(e,t,n):$n(t)?new uc(e,t,n):zn(t)?new gc(e,t,n):Xn(t)?new _c(e,t,n):Yn(t)?new vc(e,t,n):Kn(t)?new yc(e,t,(e,t)=>wc(e,t,n),n):new Rs(e,t,n),wc=(e,t,n={})=>{let r=Cc(e,t,n);return r.createsRealStackingContext=!0,xc(e,t,r,r,1,n),r},Tc=(e,t,n)=>t.styles.isPositionedWithZIndex()||t.styles.opacity<1||!!t.styles.filter||!!t.styles.backdropFilter||t.styles.maskImage.length>0||!!t.styles.webkitBoxReflect||t.styles.isolation===1||t.styles.isTransformed()||Hn(e)&&n.styles.isTransparent(),Ec=e=>e.isPositioned()||e.isFloating()||e.mixBlendMode!==K.NORMAL?!0:H(e.display,268435456)||H(e.display,33554432)||H(e.display,536870912)||H(e.display,134217728),Dc=(e,t)=>e.length===t.length&&e.some((e,n)=>e===t[n]),Oc=(e,t,n,r,i)=>e.map((e,a)=>{switch(a){case 0:return e.add(t,n);case 1:return e.add(t+r,n);case 2:return e.add(t+r,n+i);case 3:return e.add(t,n+i)}return e});var J=class e{type;x;y;constructor(e,t){this.type=0,this.x=e,this.y=t}add(t,n){return new e(this.x+t,this.y+n)}};let kc=(e,t,n)=>new J(e.x+(t.x-e.x)*n,e.y+(t.y-e.y)*n);var Ac=class e{type;start;startControl;endControl;end;constructor(e,t,n,r){this.type=1,this.start=e,this.startControl=t,this.endControl=n,this.end=r}subdivide(t,n){let r=kc(this.start,this.startControl,t),i=kc(this.startControl,this.endControl,t),a=kc(this.endControl,this.end,t),o=kc(r,i,t),s=kc(i,a,t),c=kc(o,s,t);return n?new e(this.start,r,o,c):new e(c,s,a,this.end)}add(t,n){return new e(this.start.add(t,n),this.startControl.add(t,n),this.endControl.add(t,n),this.end.add(t,n))}reverse(){return new e(this.end,this.endControl,this.startControl,this.start)}};let Y=e=>e.type===1;var jc=class{topLeftBorderDoubleOuterBox;topRightBorderDoubleOuterBox;bottomRightBorderDoubleOuterBox;bottomLeftBorderDoubleOuterBox;topLeftBorderDoubleInnerBox;topRightBorderDoubleInnerBox;bottomRightBorderDoubleInnerBox;bottomLeftBorderDoubleInnerBox;topLeftBorderStroke;topRightBorderStroke;bottomRightBorderStroke;bottomLeftBorderStroke;topLeftBorderBox;topRightBorderBox;bottomRightBorderBox;bottomLeftBorderBox;topLeftPaddingBox;topRightPaddingBox;bottomRightPaddingBox;bottomLeftPaddingBox;topLeftContentBox;topRightContentBox;bottomRightContentBox;bottomLeftContentBox;constructor(e){let t=e.styles,n=e.bounds,[r,i]=He(t.borderTopLeftRadius,n.width,n.height),[a,o]=He(t.borderTopRightRadius,n.width,n.height),[s,c]=He(t.borderBottomRightRadius,n.width,n.height),[l,u]=He(t.borderBottomLeftRadius,n.width,n.height),d=[];d.push((r+a)/n.width),d.push((l+s)/n.width),d.push((i+u)/n.height),d.push((o+c)/n.height);let f=Math.max(...d);f>1&&(r/=f,i/=f,a/=f,o/=f,s/=f,c/=f,l/=f,u/=f);let p=n.width-a,m=n.height-c,h=n.width-s,g=n.height-u,_=t.borderTopWidth,v=t.borderRightWidth,y=t.borderBottomWidth,b=t.borderLeftWidth,x=I(t.paddingTop,e.bounds.width),S=I(t.paddingRight,e.bounds.width),C=I(t.paddingBottom,e.bounds.width),w=I(t.paddingLeft,e.bounds.width);this.topLeftBorderDoubleOuterBox=r>0||i>0?X(n.left+b/3,n.top+_/3,r-b/3,i-_/3,0):new J(n.left+b/3,n.top+_/3),this.topRightBorderDoubleOuterBox=a>0||o>0?X(n.left+p,n.top+_/3,a-v/3,o-_/3,1):new J(n.left+n.width-v/3,n.top+_/3),this.bottomRightBorderDoubleOuterBox=s>0||c>0?X(n.left+h,n.top+m,s-v/3,c-y/3,2):new J(n.left+n.width-v/3,n.top+n.height-y/3),this.bottomLeftBorderDoubleOuterBox=l>0||u>0?X(n.left+b/3,n.top+g,l-b/3,u-y/3,3):new J(n.left+b/3,n.top+n.height-y/3),this.topLeftBorderDoubleInnerBox=r>0||i>0?X(n.left+b*2/3,n.top+_*2/3,r-b*2/3,i-_*2/3,0):new J(n.left+b*2/3,n.top+_*2/3),this.topRightBorderDoubleInnerBox=a>0||o>0?X(n.left+p,n.top+_*2/3,a-v*2/3,o-_*2/3,1):new J(n.left+n.width-v*2/3,n.top+_*2/3),this.bottomRightBorderDoubleInnerBox=s>0||c>0?X(n.left+h,n.top+m,s-v*2/3,c-y*2/3,2):new J(n.left+n.width-v*2/3,n.top+n.height-y*2/3),this.bottomLeftBorderDoubleInnerBox=l>0||u>0?X(n.left+b*2/3,n.top+g,l-b*2/3,u-y*2/3,3):new J(n.left+b*2/3,n.top+n.height-y*2/3),this.topLeftBorderStroke=r>0||i>0?X(n.left+b/2,n.top+_/2,r-b/2,i-_/2,0):new J(n.left+b/2,n.top+_/2),this.topRightBorderStroke=a>0||o>0?X(n.left+p,n.top+_/2,a-v/2,o-_/2,1):new J(n.left+n.width-v/2,n.top+_/2),this.bottomRightBorderStroke=s>0||c>0?X(n.left+h,n.top+m,s-v/2,c-y/2,2):new J(n.left+n.width-v/2,n.top+n.height-y/2),this.bottomLeftBorderStroke=l>0||u>0?X(n.left+b/2,n.top+g,l-b/2,u-y/2,3):new J(n.left+b/2,n.top+n.height-y/2),this.topLeftBorderBox=r>0||i>0?X(n.left,n.top,r,i,0):new J(n.left,n.top),this.topRightBorderBox=a>0||o>0?X(n.left+p,n.top,a,o,1):new J(n.left+n.width,n.top),this.bottomRightBorderBox=s>0||c>0?X(n.left+h,n.top+m,s,c,2):new J(n.left+n.width,n.top+n.height),this.bottomLeftBorderBox=l>0||u>0?X(n.left,n.top+g,l,u,3):new J(n.left,n.top+n.height),this.topLeftPaddingBox=r>0||i>0?X(n.left+b,n.top+_,Math.max(0,r-b),Math.max(0,i-_),0):new J(n.left+b,n.top+_),this.topRightPaddingBox=a>0||o>0?X(n.left+Math.min(p,n.width-v),n.top+_,p>n.width+v?0:Math.max(0,a-v),Math.max(0,o-_),1):new J(n.left+n.width-v,n.top+_),this.bottomRightPaddingBox=s>0||c>0?X(n.left+Math.min(h,n.width-b),n.top+Math.min(m,n.height-y),Math.max(0,s-v),Math.max(0,c-y),2):new J(n.left+n.width-v,n.top+n.height-y),this.bottomLeftPaddingBox=l>0||u>0?X(n.left+b,n.top+Math.min(g,n.height-y),Math.max(0,l-b),Math.max(0,u-y),3):new J(n.left+b,n.top+n.height-y),this.topLeftContentBox=r>0||i>0?X(n.left+b+w,n.top+_+x,Math.max(0,r-(b+w)),Math.max(0,i-(_+x)),0):new J(n.left+b+w,n.top+_+x),this.topRightContentBox=a>0||o>0?X(n.left+Math.min(p,n.width+b+w),n.top+_+x,p>n.width+b+w?0:a-b+w,o-(_+x),1):new J(n.left+n.width-(v+S),n.top+_+x),this.bottomRightContentBox=s>0||c>0?X(n.left+Math.min(h,n.width-(b+w)),n.top+Math.min(m,n.height+_+x),Math.max(0,s-(v+S)),c-(y+C),2):new J(n.left+n.width-(v+S),n.top+n.height-(y+C)),this.bottomLeftContentBox=l>0||u>0?X(n.left+b+w,n.top+g,Math.max(0,l-(b+w)),u-(y+C),3):new J(n.left+b+w,n.top+n.height-(y+C))}};let X=(e,t,n,r,i)=>{let a=4*((Math.sqrt(2)-1)/3),o=n*a,s=r*a,c=e+n,l=t+r;switch(i){case 0:return new Ac(new J(e,l),new J(e,l-s),new J(c-o,t),new J(c,t));case 1:return new Ac(new J(e,t),new J(e+o,t),new J(c,l-s),new J(c,l));case 2:return new Ac(new J(c,t),new J(c,t+s),new J(e+o,l),new J(e,l));default:return new Ac(new J(c,l),new J(c-o,l),new J(e,t+s),new J(e,t))}},Mc=e=>[e.topLeftBorderBox,e.topRightBorderBox,e.bottomRightBorderBox,e.bottomLeftBorderBox],Nc=e=>[e.topLeftContentBox,e.topRightContentBox,e.bottomRightContentBox,e.bottomLeftContentBox],Pc=e=>[e.topLeftPaddingBox,e.topRightPaddingBox,e.bottomRightPaddingBox,e.bottomLeftPaddingBox];var Fc=class{offsetX;offsetY;matrix;type=0;target=6;constructor(e,t,n){this.offsetX=e,this.offsetY=t,this.matrix=n}},Ic=class{path;target;type=1;constructor(e,t){this.path=e,this.target=t}},Lc=class{opacity;type=2;target=6;constructor(e){this.opacity=e}},Rc=class{applyClip;type=3;target=6;constructor(e){this.applyClip=e}};let zc={[K.NORMAL]:`source-over`,[K.MULTIPLY]:`multiply`,[K.SCREEN]:`screen`,[K.OVERLAY]:`overlay`,[K.DARKEN]:`darken`,[K.LIGHTEN]:`lighten`,[K.COLOR_DODGE]:`color-dodge`,[K.COLOR_BURN]:`color-burn`,[K.HARD_LIGHT]:`hard-light`,[K.SOFT_LIGHT]:`soft-light`,[K.DIFFERENCE]:`difference`,[K.EXCLUSION]:`exclusion`,[K.HUE]:`hue`,[K.SATURATION]:`saturation`,[K.COLOR]:`color`,[K.LUMINOSITY]:`luminosity`};var Bc=class{mixBlendMode;type=4;target=6;compositeOperation;constructor(e){this.mixBlendMode=e,this.compositeOperation=zc[e]}},Vc=class e{type=5;target=6;safeFilterString;shadow;constructor(t){let n=e.parseDropShadow(t);this.shadow=n.shadow,this.safeFilterString=n.safeFilterString}static parseDropShadow(t){if(!t)return{safeFilterString:``};let n=e.findDropShadows(t);if(n.length===0)return{safeFilterString:t};let r=e.parseDropShadowBody(c(n,0).body),i=``,a=0;for(let e of n)i+=t.slice(a,e.start),a=e.end;return i+=t.slice(a),{shadow:r,safeFilterString:i.replace(/\s+/g,` `).trim()}}static findDropShadows(e){let t=[],n=/drop-shadow\(/gi,r;for(;(r=n.exec(e))!==null;){let n=r.index+12-1,i=r.index,a=1,o=n+1;for(;o<e.length&&a>0;){let t=e[o]??``;t===`(`?a++:t===`)`&&a--,o++}if(a!==0)break;let s=e.slice(n+1,o-1);t.push({body:s,start:i,end:o})}return t}static parseDropShadowBody(t){let n=e.tokenizeFilterArgs(t.trim()),r=[],i;for(let t of n)e.isCSSLength(t)?r.push(parseFloat(t)):t&&(i=t);if(!(r.length<2||r.length>3))return{offsetX:c(r,0),offsetY:c(r,1),blur:r.length>2?c(r,2):0,color:i??`rgba(0,0,0,1)`}}static tokenizeFilterArgs(e){let t=[],n=``,r=0;for(let i=0;i<e.length;i++){let a=e[i]??``;a===`(`?(r++,n+=a):a===`)`?(r--,n+=a):/\s/.test(a)?r>0?n+=a:n&&=(t.push(n),``):n+=a}return n&&t.push(n),t}static isCSSLength(e){return/^-?[\d.]+(px|em|rem|pt|cm|mm|in|pc|ex|ch|vw|vh|vmin|vmax|%)?$/i.test(e)}};let Hc=e=>e.type===0,Uc=e=>e.type===1,Wc=e=>e.type===2,Gc=e=>e.type===3,Kc=e=>e.type===4,qc=e=>e.type===5;var Jc=class{element;negativeZIndex;zeroOrAutoZIndexOrTransformedOrOpacity;positiveZIndex;nonPositionedFloats;nonPositionedInlineLevel;inlineLevel;nonInlineLevel;constructor(e){this.element=e,this.inlineLevel=[],this.nonInlineLevel=[],this.negativeZIndex=[],this.zeroOrAutoZIndexOrTransformedOrOpacity=[],this.positiveZIndex=[],this.nonPositionedFloats=[],this.nonPositionedInlineLevel=[]}},Yc=class{container;parent;effects=[];curves;listValue;plainEffectsCache=null;constructor(e,t){if(this.container=e,this.parent=t,this.curves=new jc(this.container),this.container.styles.opacity<1&&this.effects.push(new Lc(this.container.styles.opacity)),this.container.styles.translate!==null){let e=this.container.styles.transformOrigin,t=this.container.bounds.left+I(e[0],this.container.bounds.width),n=this.container.bounds.top+I(e[1],this.container.bounds.height),[r,i]=this.container.styles.translate,a=I(r,this.container.bounds.width),o=I(i,this.container.bounds.height);this.effects.push(new Fc(t,n,[1,0,0,1,a,o]))}if(this.container.styles.rotate!==null){let e=this.container.styles.transformOrigin,t=this.container.bounds.left+I(e[0],this.container.bounds.width),n=this.container.bounds.top+I(e[1],this.container.bounds.height),r=this.container.styles.rotate*Math.PI/180,i=Math.cos(r),a=Math.sin(r),o=[i,a,-a,i,0,0];this.effects.push(new Fc(t,n,o))}if(this.container.styles.scale!==null){let e=this.container.styles.transformOrigin,t=this.container.bounds.left+I(e[0],this.container.bounds.width),n=this.container.bounds.top+I(e[1],this.container.bounds.height),[r,i]=this.container.styles.scale;this.effects.push(new Fc(t,n,[r,0,0,i,0,0]))}if(this.container.styles.transform!==null){let e=this.container.styles.transformOrigin,t=this.container.bounds.left+I(e[0],this.container.bounds.width),n=this.container.bounds.top+I(e[1],this.container.bounds.height),r=this.container.styles.transform;this.effects.push(new Fc(t,n,r))}if(Xc(this.container.styles)){let e=Mc(this.curves),t=Pc(this.curves);Dc(e,t)?this.effects.push(new Ic(e,6)):(this.effects.push(new Ic(e,2)),this.effects.push(new Ic(t,4)))}if(this.container.styles.clipPath.type!==0){let e=Qc(this.container.styles.clipPath,this.container.bounds);e&&this.effects.push(e)}if(this.container.styles.mixBlendMode!==K.NORMAL&&this.effects.push(new Bc(this.container.styles.mixBlendMode)),this.container.styles.filter!==null&&this.effects.push(new Vc(this.container.styles.filter)),this.container.styles.zoom!==1){let e=this.container.bounds.left,t=this.container.bounds.top,n=this.container.styles.zoom,r=[n,0,0,n,0,0];this.effects.push(new Fc(e,t,r))}}getEffects(e,t){if(!t){let t=this.plainEffectsCache;t||(t=/* @__PURE__ */ new Map,this.plainEffectsCache=t);let n=t.get(e);return n||(n=this.computeEffects(e),t.set(e,n)),n}return this.computeEffects(e,t)}computeEffects(e,t){let n=[2,3].indexOf(this.container.styles.position)===-1,r=this===t?null:this.parent,i=e=>e.effects.filter(n=>e!==t||!qc(n)&&!Wc(n)&&!Kc(n)),a=i(this);for(;r;){let e=i(r).filter(e=>!Uc(e));if(n||r.container.styles.position!==0||!r.parent){if(n=[2,3].indexOf(r.container.styles.position)===-1,Xc(r.container.styles)){let e=Mc(r.curves),t=Pc(r.curves);Dc(e,t)||a.unshift(new Ic(t,6))}a.unshift(...e)}else a.unshift(...e);r=r===t?null:r.parent}return a.filter(t=>H(t.target,e))}};let Xc=e=>e.overflowX!==0||e.overflowY!==0,Zc=(e,t,n,r,i)=>e===`closest-side`?Math.min(t-n,r-t):e===`farthest-side`?Math.max(t-n,r-t):I(e,i),Qc=(e,t)=>{let{left:n,top:r,width:i,height:a}=t;switch(e.type){case 1:{let t=I(e.left,i),o=I(e.top,a),s=n+t,c=r+o,l=Math.max(0,i-t-I(e.right,i)),u=Math.max(0,a-o-I(e.bottom,a));return new Rc(e=>{e.beginPath(),e.rect(s,c,l,u),e.clip()})}case 2:{let t=n+I(e.cx,i),o=r+I(e.cy,a),s;return s=e.radius===`closest-side`?Math.min(t-n,o-r,n+i-t,r+a-o):e.radius===`farthest-side`?Math.max(t-n,o-r,n+i-t,r+a-o):I(e.radius,Math.sqrt(i*i+a*a)/Math.SQRT2),new Rc(e=>{e.beginPath(),e.arc(t,o,Math.max(0,s),0,Math.PI*2),e.clip()})}case 3:{let t=n+I(e.cx,i),o=r+I(e.cy,a),s=Zc(e.rx,t,n,n+i,i),c=Zc(e.ry,o,r,r+a,a);return new Rc(e=>{e.beginPath(),e.ellipse(t,o,Math.max(0,s),Math.max(0,c),0,0,Math.PI*2),e.clip()})}case 4:{let t=e.points.map(([e,t])=>[n+I(e,i),r+I(t,a)]);return new Rc(e=>{if(e.beginPath(),t.length>0){e.moveTo(c(c(t,0),0),c(c(t,0),1));for(let n=1;n<t.length;n++)e.lineTo(c(c(t,n),0),c(c(t,n),1));e.closePath()}e.clip()})}case 5:{let{d:t}=e,i=null;return new Rc(e=>{try{i||=new Path2D(t);let a=e.getTransform();e.translate(n,r),e.clip(i),e.setTransform(a)}catch{}})}case 6:{let t=n+I(e.x,i),o=r+I(e.y,a),s=Math.max(0,I(e.width,i)),c=Math.max(0,I(e.height,a));return new Rc(e=>{e.beginPath(),e.rect(t,o,s,c),e.clip()})}case 0:return null;default:return null}},$c=(e,t,n,r)=>{e.container.elements.forEach(i=>{let a=i.createsRealStackingContext,o=i.createsStackingContext,s=new Yc(i,e);H(i.styles.display,2048)&&r.push(s);let c=i.isListOwner?[]:r;if(a||o){let e=a||i.styles.isPositioned()?n:t,r=new Jc(s);if(a||i.styles.isPositioned()||i.styles.opacity<1||i.styles.isTransformed()){let t=i.styles.zIndex.order;if(t<0){let n=0;e.negativeZIndex.some((e,r)=>t>=e.element.container.styles.zIndex.order?(n=r+1,!1):n>0),e.negativeZIndex.splice(n,0,r)}else if(t>0){let n=0;e.positiveZIndex.some((e,r)=>t>=e.element.container.styles.zIndex.order?(n=r+1,!1):n>0),e.positiveZIndex.splice(n,0,r)}else e.zeroOrAutoZIndexOrTransformedOrOpacity.push(r)}else i.styles.isFloating()?e.nonPositionedFloats.push(r):e.nonPositionedInlineLevel.push(r);$c(s,r,a?r:n,c)}else i.styles.isInlineLevel()?t.inlineLevel.push(s):t.nonInlineLevel.push(s),$c(s,t,n,c);i.isListOwner&&el(i,c)})},el=(e,t)=>{let n=e instanceof uc?e.start:1,r=e instanceof uc&&e.reversed;for(let e=0;e<t.length;e++){let i=c(t,e);i.container instanceof lc&&typeof i.container.value==`number`&&i.container.value!==0&&(n=i.container.value),i.listValue=_r(n,i.container.styles.listStyleType,!0),n+=r?-1:1}},tl=e=>{let t=new Yc(e,null),n=new Jc(t),r=[];return $c(t,n,n,r),el(t.container,r),n},nl=e=>Math.min(1,Math.max(0,e)),rl=e=>{let t=c(e,0),n=c(e,e.length-1);if(n.stop-t.stop<1e-6)return null;let r=Math.max(n.stop-t.stop,.01),i=[],a=Math.ceil(1/r);for(let n=0;n<a;n++)for(let a of e){let e=n*r+(a.stop-t.stop);if(e>1)break;i.push({stop:e,color:z(a.color)})}let o=i[i.length-1];return(!o||o.stop<1)&&i.push({stop:1,color:z(n.color)}),i},il=e=>e.map(e=>({stop:nl(e.stop),color:z(e.color)})),al=(e,t,n,r,i=!1)=>{let a=W(r,t),o=c(a,a.length-1),s=z(o.color),l=e.createElement(`canvas`);l.width=Math.max(1,Math.ceil(t*2)),l.height=Math.max(1,Math.ceil(n*2));let u=l.getContext(`2d`);if(!u)return null;let d;if(i){let e=rl(a);if(!e)return u.fillStyle=s,u.fillRect(0,0,l.width,l.height),{canvas:l,lastColor:s,rx:t,ry:n};d=e}else d=il(a);let f=u.createRadialGradient(t,t,0,t,t,t);return d.forEach(e=>f.addColorStop(nl(e.stop),e.color)),u.fillStyle=f,t!==n&&u.scale(1,n/t),u.fillRect(0,0,t*2,t*2),{canvas:l,lastColor:s,rx:t,ry:n}},ol=e=>{let t=e.bounds,n=e.styles;return t.add(n.borderLeftWidth,n.borderTopWidth,-(n.borderRightWidth+n.borderLeftWidth),-(n.borderTopWidth+n.borderBottomWidth))},sl=e=>{let t=e.styles,n=e.bounds,r=I(t.paddingLeft,n.width),i=I(t.paddingRight,n.width),a=I(t.paddingTop,n.width),o=I(t.paddingBottom,n.width);return n.add(r+t.borderLeftWidth,a+t.borderTopWidth,-(t.borderRightWidth+t.borderLeftWidth+r+i),-(t.borderTopWidth+t.borderBottomWidth+a+o))},cl=(e,t)=>e===0?t.bounds:e===2?sl(t):ol(t),ll=(e,t)=>e===0?t.bounds:e===2?sl(t):ol(t),ul=(e,t,n)=>{let r=cl(ml(e.styles.backgroundOrigin,t),e),i=ll(ml(e.styles.backgroundClip,t),e),a=pl(ml(e.styles.backgroundSize,t),n,r),[o,s]=a,c=He(ml(e.styles.backgroundPosition,t),r.width-o,r.height-s),l=hl(ml(e.styles.backgroundRepeat,t),c,a,r,i),u=Math.round(r.left+c[0]),d=Math.round(r.top+c[1]);return o=Math.max(1,o),s=Math.max(1,s),[l,u,d,o,s]},dl=e=>D(e)&&e.value===`auto`,fl=e=>typeof e==`number`,pl=(e,[t,n,r],i)=>{let[a,o]=e;if(!a)return[0,0];if(M(a)&&o&&M(o))return[I(a,i.width),I(o,i.height)];let s=fl(r);if(D(a)&&(a.value===`contain`||a.value===`cover`))return fl(r)?i.width/i.height<r==(a.value===`cover`)?[i.height*r,i.height]:[i.width,i.width/r]:[i.width,i.height];let c=fl(t),l=fl(n),u=c||l;if(dl(a)&&(!o||dl(o)))return c&&l?[t,n]:!s&&!u?[i.width,i.height]:u&&s?[c?t:n*r,l?n:t/r]:[c?t:i.width,l?n:i.height];if(s){let e=0,t=0;return M(a)?e=I(a,i.width):o&&M(o)&&(t=I(o,i.height)),dl(a)?e=t*r:(!o||dl(o))&&(t=e/r),[e,t]}let d=null,f=null;if(M(a)?d=I(a,i.width):o&&M(o)&&(f=I(o,i.height)),d!==null&&(!o||dl(o))&&(f=c&&l?d/t*n:i.height),f!==null&&dl(a)&&(d=c&&l?f/n*t:i.width),d!==null&&f!==null)return[d,f];throw Error(`Unable to calculate background-size for element`)},ml=(e,t)=>{let n=e[t];return n===void 0?c(e,0):n},hl=(e,[t,n],[r,i],a,o)=>{switch(e){case 2:return[new J(Math.round(a.left),Math.round(a.top+n)),new J(Math.round(a.left+a.width),Math.round(a.top+n)),new J(Math.round(a.left+a.width),Math.round(i+a.top+n)),new J(Math.round(a.left),Math.round(i+a.top+n))];case 3:return[new J(Math.round(a.left+t),Math.round(a.top)),new J(Math.round(a.left+t+r),Math.round(a.top)),new J(Math.round(a.left+t+r),Math.round(a.height+a.top)),new J(Math.round(a.left+t),Math.round(a.height+a.top))];case 1:return[new J(Math.round(a.left+t),Math.round(a.top+n)),new J(Math.round(a.left+t+r),Math.round(a.top+n)),new J(Math.round(a.left+t+r),Math.round(a.top+n+i)),new J(Math.round(a.left+t),Math.round(a.top+n+i))];default:return[new J(Math.round(o.left),Math.round(o.top)),new J(Math.round(o.left+o.width),Math.round(o.top)),new J(Math.round(o.left+o.width),Math.round(o.height+o.top)),new J(Math.round(o.left),Math.round(o.height+o.top))]}};var Z=class extends Error{};let Q=e=>{e.width=e.height=0},gl=[`brightness`,`contrast`,`grayscale`,`hue-rotate`,`invert`,`opacity`,`saturate`,`sepia`],_l=/* @__PURE__ */ new Map,vl={functions:[]};function yl(e){if(!e||e===`none`)return vl;let t=_l.get(e);if(t!==void 0)return _l.delete(e),_l.set(e,t),t;let n=bl(e);if(_l.size>=256){let e=_l.keys().next().value;e!==void 0&&_l.delete(e)}return _l.set(e,n),n}let bl=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r===` `||r===`
11
+ `||r===` `){n++;continue}let i=e.indexOf(`(`,n);if(i===-1)return null;let a=e.slice(n,i).trim();if(!/^[a-zA-Z-]+$/.test(a))return null;let o=xl(e,i);if(o===-1)return null;let s=Cl(a,e.slice(i+1,o).trim());if(!s)return null;t.push(s),n=o+1}return{functions:t}},xl=(e,t)=>{let n=1;for(let r=t+1;r<e.length;r++){let t=e[r];if(t===`(`)n++;else if(t===`)`&&(n--,n===0))return r}return-1},Sl=/^-?\d+(?:\.\d+)?px$/,Cl=(e,t)=>{if(e===`blur`){if(t===`0`)return{kind:`blur`,value:0};if(!Sl.test(t))return null;let e=Number.parseFloat(t);return e<0?null:{kind:`blur`,value:e}}if(e===`drop-shadow`)return Tl(t);if(gl.indexOf(e)!==-1){let n=e;if(n===`hue-rotate`){let e=El(t);return e===null?null:{kind:`unitless`,name:n,value:e}}let r=t.trim(),i=r.endsWith(`%`),a=i?r.slice(0,-1):r;return/^-?\d+(?:\.\d+)?$/.test(a)?{kind:`unitless`,name:n,value:Number.parseFloat(a)*(i?1/100:1)}:null}if(e===`url`){let e=js(t);return e?{kind:`url`,ref:e}:null}return null},wl=e=>{let t=[],n=0,r=``;for(let i of e)i===`(`?n++:i===`)`&&n--,i===` `&&n===0?(r&&t.push(r),r=``):r+=i;return r&&t.push(r),t},Tl=e=>{let t=wl(e),n=t.filter(e=>Sl.test(e)).map(e=>Number.parseFloat(e));if(n.length<2||n.length>3)return null;let r=t.filter(e=>!Sl.test(e));return t.length-r.length===n.length?{kind:`drop-shadow`,x:n[0],y:n[1],blur:n[2]??0,color:r.join(` `)||`rgba(0, 0, 0, 0)`}:null},El=e=>{let t=e.trim();if(t===`0`)return 0;let n=Number.parseFloat(t);return Number.isNaN(n)?null:t.endsWith(`deg`)?n:t.endsWith(`grad`)?n*.9:t.endsWith(`rad`)?n*180/Math.PI:t.endsWith(`turn`)?n*360:null},Dl=(e,t)=>e.functions.map(e=>{switch(e.kind){case`blur`:return`blur(${e.value*t}px)`;case`drop-shadow`:return`drop-shadow(${e.x*t}px ${e.y*t}px ${e.blur*t}px ${e.color})`;case`unitless`:return e.name===`hue-rotate`?`hue-rotate(${e.value}deg)`:`${e.name}(${e.value})`;case`url`:return`url("${e.ref}")`}}).join(` `);function Ol(e,t){let n=0,r=0,i=0;for(let a of e.functions)a.kind===`blur`?n+=a.value:a.kind===`drop-shadow`?(n+=a.blur,r=Math.max(r,Math.abs(a.x),Math.abs(a.y))):a.kind===`url`&&(i+=t?.get(a.ref)?.outset??0);return Math.ceil(3*n+r+i)}function kl(e){let t=(e.ownerDocument??document).createElement(`canvas`);return t.width=e.width,t.height=e.height,t}let Al=(e,t)=>new Promise((n,r)=>{let i=e=>{clearTimeout(o),t?.removeEventListener(`abort`,a),e?r(e):n()},a=()=>i(new DOMException(`The operation was aborted.`,`AbortError`)),o=setTimeout(()=>i(new Z(`Filter surface image decode timed out`)),1e4);t?.addEventListener(`abort`,a,{once:!0}),t?.aborted?a():e.decode().then(()=>i(),()=>i(new Z(`Filter surface image decode failed`)))}),jl=/* @__PURE__ */ new WeakMap;function Ml(e=document){let t=jl.get(e);if(t!==void 0)return t;let n=e.createElement(`canvas`),r=e.createElement(`canvas`),i=!1;try{n.width=n.height=r.width=r.height=32;let e=n.getContext(`2d`),t=r.getContext(`2d`);if(e&&t&&`filter`in t){e.fillStyle=`#fff`,e.fillRect(8,8,8,8),t.filter=`blur(2px)`,t.drawImage(n,0,0);let r=(t.getImageData(6,12,1,1).data[3]??0)>0;t.clearRect(0,0,32,32),t.filter=`drop-shadow(12px 0px 0px rgba(255, 0, 0, 0.5))`,t.drawImage(n,0,0);let a=t.getImageData(24,12,1,1).data;i=r&&(a[0]??0)>240&&(a[1]??0)<10&&(a[3]??0)>=126&&(a[3]??0)<=129}}catch{}finally{Q(n),Q(r)}return jl.set(e,i),i}function Nl(e,t,n,r,i){let a,o,s=!1;try{q(i),a=kl(e);let c=a.getContext(`2d`);if(!c||!(`filter`in c)||(c.filter=Dl(t,r),c.filter===`none`||c.filter===``))return null;c.drawImage(e,0,0),q(i),o=kl(e);let l=o.getContext(`2d`);return l?(l.globalAlpha=n,l.drawImage(a,0,0),q(i),s=!0,o):null}catch{return q(i),null}finally{a&&Q(a),o&&!s&&Q(o)}}let Pl=e=>{let t=0,n=0;for(let r of e.functions)if(r.kind===`blur`)t++;else if(r.kind===`drop-shadow`)n++;else return!1;return t>1||n>1?!1:t>0&&n>0?e.functions.findIndex(e=>e.kind===`blur`)<e.functions.findIndex(e=>e.kind===`drop-shadow`):!0};async function Fl(e,t,n,r,i,a){if(q(i),t.functions.some(e=>e.kind===`url`))return Il(e,t,n,r,i,a);if(t.functions.length>0&&Ml(e.ownerDocument??document)){let a=Nl(e,t,n,r,i);if(a)return a}if(!Pl(t))throw new Z(`Filter chain requires native canvas filters`);return Hl(e,t,n,r,i)}async function Il(e,t,n,r,i,a){let o=[];for(let e of t.functions){if(e.kind===`url`){let t=a?.references?.get(e.ref);if(!t)throw new Z(`Filter reference ${e.ref} cannot be resolved`);o.push(t);continue}let t=o[o.length-1];Array.isArray(t)?t.push(e):o.push([e])}let s=a?.origin??{x:0,y:0},c=o[o.length-1],l=Array.isArray(c),u=e;try{for(let t of o){let a=Array.isArray(t)?await Fl(u,{functions:t},t===c?n:1,r,i):await Vl(u,t,s,r,i);u!==e&&Q(u),u=a}if(l||n===1){let t=u;return u=e,t}return Ll(u,n)}finally{u!==e&&Q(u)}}function Ll(e,t){let n=kl(e),r=n.getContext(`2d`);if(!r)throw Q(n),new Z(`Filter surface canvas is unavailable`);r.globalAlpha=t;try{return r.drawImage(e,0,0),n}catch{throw Q(n),new Z(`Filter surface image cannot be drawn`)}}function Rl(e,t,n={}){let r=e.createElementNS(`http://www.w3.org/2000/svg`,t);return Object.entries(n).forEach(([e,t])=>r.setAttribute(e,String(t))),r}function zl(e){try{let t=e.toDataURL(`image/png`);if(t===`data:,`)throw Error(`Canvas size is unsupported`);return t}catch{throw new Z(`Filter surface pixels cannot be serialized`)}}async function Bl(e,t,n,r){let i=(t.ownerDocument??document).defaultView,a=i?.Image?new i.Image:new Image,o;try{a.src=`data:image/svg+xml,${encodeURIComponent(new XMLSerializer().serializeToString(e))}`,await Al(a,r),q(r),o=kl(t);let i=o.getContext(`2d`);if(!i)throw new Z(`Filter surface canvas is unavailable`);return i.globalAlpha=n,i.drawImage(a,0,0),o}catch(e){throw o&&Q(o),r?.aborted&&q(r),e instanceof Z?e:new Z(`Filter surface image cannot be drawn`)}finally{a.removeAttribute(`src`)}}async function Vl(e,t,n,r,i){q(i);let a=e.ownerDocument??document,o=e.width/r,s=e.height/r,c=Rl(a,`svg`,{width:e.width,height:e.height,viewBox:`0 0 ${o} ${s}`}),l=Rl(a,`defs`),u=a.importNode(t.element,!0);u.setAttribute(`id`,`composited-reference`),l.appendChild(u),c.appendChild(l);let d=Rl(a,`g`,{transform:`translate(${n.x} ${n.y})`});return d.appendChild(Rl(a,`image`,{x:-n.x,y:-n.y,width:o,height:s,href:zl(e),filter:`url(#composited-reference)`})),c.appendChild(d),Bl(c,e,1,i)}async function Hl(e,t,n,r,i){q(i);let a=t.functions.find(e=>e.kind===`blur`),o=t.functions.find(e=>e.kind===`drop-shadow`),s=a&&a.kind===`blur`?a.value:0,c=o&&o.kind===`drop-shadow`?{x:o.x,y:o.y,blur:o.blur,color:o.color}:void 0;if(!s&&!c)return Ll(e,n);let l=e.ownerDocument??document,u=(e,t={})=>Rl(l,e,t),d=u(`svg`,{width:e.width,height:e.height,viewBox:`0 0 ${e.width} ${e.height}`}),f=u(`defs`),p=u(`filter`,{id:`composited-filter`,filterUnits:`userSpaceOnUse`,x:0,y:0,width:e.width,height:e.height,"color-interpolation-filters":`sRGB`});if(s&&p.appendChild(u(`feGaussianBlur`,{stdDeviation:s*r,result:`blurred-source`})),c){p.appendChild(u(`feGaussianBlur`,{in:s?`blurred-source`:`SourceAlpha`,stdDeviation:c.blur*r})),p.appendChild(u(`feOffset`,{dx:c.x*r,dy:c.y*r,result:`offset-shadow`})),p.appendChild(u(`feFlood`,{"flood-color":c.color})),p.appendChild(u(`feComposite`,{in2:`offset-shadow`,operator:`in`}));let e=u(`feMerge`);e.appendChild(u(`feMergeNode`)),e.appendChild(u(`feMergeNode`,{in:s?`blurred-source`:`SourceGraphic`})),p.appendChild(e)}return f.appendChild(p),d.appendChild(f),d.appendChild(u(`image`,{width:e.width,height:e.height,href:zl(e),filter:`url(#composited-filter)`})),Bl(d,e,n,i)}function Ul(e,t,n){let r=t*n*4;return!Number.isFinite(r)||t<=0||n<=0||t>8192||n>8192||e.pixels+r>16777216?0:(e.pixels+=r,r)}let Wl=(e,t)=>e.add(-t,-t,t*2,t*2),Gl=(e,t)=>new a(Math.min(e.left,t.left),Math.min(e.top,t.top),Math.max(e.left+e.width,t.left+t.width)-Math.min(e.left,t.left),Math.max(e.top+e.height,t.top+t.height)-Math.min(e.top,t.top));function Kl(e){let t=e.styles,n=e.bounds;for(let r of t.boxShadow)if(!r.inset){let t=Math.max(0,r.spread.number)+3*r.blur.number;n=Gl(n,Wl(e.bounds.add(r.offsetX.number,r.offsetY.number,0,0),t))}for(let r of e.textNodes)for(let i of r.textBounds){let r=Wl(i.bounds,2*I(t.fontSize,e.bounds.height)+t.webkitTextStrokeWidth);n=Gl(n,r);for(let e of t.textShadow)n=Gl(n,Wl(r.add(e.offsetX.number,e.offsetY.number,0,0),3*e.blur.number))}for(let t of e.elements)t.styles.isVisible()&&(n=Gl(n,Kl(t)));let r=yl(t.filter);return Wl(n,r?Ol(r,e.filterReferences):0)}function ql(e,t,n,r){let i=Wl(t,n),o=Math.floor(Math.max(e.left,i.left)*r)/r,s=Math.floor(Math.max(e.top,i.top)*r)/r,c=Math.ceil(Math.min(e.left+e.width,i.left+i.width)*r)/r,l=Math.ceil(Math.min(e.top+e.height,i.top+i.height)*r)/r;return new a(o,s,Math.max(0,c-o),Math.max(0,l-s))}var Jl=class{ctx;constructor(e){this.ctx=e}render(e,t){this.ctx.fillStyle=z(t.textDecorationColor??t.color);let n=1;typeof t.textDecorationThickness==`number`?n=t.textDecorationThickness:t.textDecorationThickness===`from-font`&&(n=Math.max(1,Math.floor(t.fontSize.number*.05)));let r=0;typeof t.textUnderlineOffset==`number`&&(r=t.textUnderlineOffset);let i=t.textDecorationStyle;t.textDecorationLine.forEach(t=>{let a=0;switch(t){case 1:a=e.top+e.height-n+r;break;case 2:a=e.top;break;case 3:a=e.top+(e.height/2-n/2);break;default:return}this.draw(e.left,a,e.width,n,i)})}draw(e,t,n,r,i){switch(i){case 0:this.ctx.fillRect(e,t,n,r);break;case 1:{let i=Math.max(1,r);this.ctx.fillRect(e,t,n,r),this.ctx.fillRect(e,t+r+i,n,r);break}case 2:this.drawPattern(e,t,n,r,[r,r*2]);break;case 3:this.drawPattern(e,t,n,r,[r*3,r*2]);break;case 4:this.drawWavy(e,t,n,r);break;default:this.ctx.fillRect(e,t,n,r)}}drawPattern(e,t,n,r,i){this.ctx.save(),this.ctx.beginPath(),this.ctx.setLineDash(i),this.ctx.lineWidth=r,this.ctx.strokeStyle=this.ctx.fillStyle,this.ctx.moveTo(e,t+r/2),this.ctx.lineTo(e+n,t+r/2),this.ctx.stroke(),this.ctx.restore()}drawWavy(e,t,n,r){this.ctx.save(),this.ctx.beginPath(),this.ctx.lineWidth=r,this.ctx.strokeStyle=this.ctx.fillStyle;let i=r*2,a=r*4,o=e;for(this.ctx.moveTo(o,t+r/2);o<e+n;){let s=Math.min(o+a/2,e+n);if(this.ctx.quadraticCurveTo(o+a/4,t+r/2-i,s,t+r/2),o=s,o<e+n){let s=Math.min(o+a/2,e+n);this.ctx.quadraticCurveTo(o+a/4,t+r/2+i,s,t+r/2),o=s}}this.ctx.stroke(),this.ctx.restore()}};let Yl=e=>e!==void 0&&!Number.isNaN(e),Xl=(e,t)=>{let n=e.measureText(`Mg`),r=n;return{baseline:Yl(r.fontBoundingBoxAscent)?r.fontBoundingBoxAscent:Yl(n.actualBoundingBoxAscent)?n.actualBoundingBoxAscent:t,height:Yl(r.fontBoundingBoxAscent)&&Yl(r.fontBoundingBoxDescent)?r.fontBoundingBoxAscent+r.fontBoundingBoxDescent:Yl(n.actualBoundingBoxAscent)&&Yl(n.actualBoundingBoxDescent)?n.actualBoundingBoxAscent+n.actualBoundingBoxDescent:t}},Zl=(e,t)=>Xl(e,t).baseline,Ql=/[\u2E80-\u2FFF\u3000-\u30FF\u3400-\u4DBF\u4E00-\u9FFF\uAC00-\uD7AF\uF900-\uFAFF\uFF01-\uFFEF]/,$l=e=>Ql.test(e),eu=()=>typeof navigator>`u`?!1:navigator.userAgentData!==void 0||(typeof window<`u`?window:void 0)?.chrome!==void 0,tu=()=>eu()?`miter`:`round`;var nu=class{ctx;options;decorationRenderer;baselineCache=/* @__PURE__ */ new Map;glyphWidthCache=null;constructor(e){this.ctx=e.ctx,this.options=e.options,this.decorationRenderer=new Jl(e.ctx)}cachedMeasureText(e,t){let n=this.glyphWidthCache;n||(n=/* @__PURE__ */ new Map,this.glyphWidthCache=n);let r=e+t,i=n.get(r);return i===void 0&&(i=this.ctx.measureText(e).width,n.set(r,i)),i}iterateLettersWithLetterSpacing(e,t,n,r,i){if(ka(r)){this.iterateVerticalGlyphs(e,t,n,r,i);return}let a=Zs(e.text),o=e.bounds.top+n,s=this.ctx.font,c=e.bounds.left;for(let e of a)i(e,c,o),c+=this.cachedMeasureText(e,s)+t}iterateVerticalGlyphs(e,t,n,r,i){let a=Zs(e.text),o=this.ctx.font,s=r===4?-Math.PI/2:Math.PI/2,c=e.bounds.top;for(let l=0;l<a.length;){let u=a[l];if(!(Aa(r)||!$l(u)&&u.trim().length>0)){let r=this.ctx.textBaseline;$l(u)&&(this.ctx.textBaseline=`ideographic`),i(u,e.bounds.left,c+n),this.ctx.textBaseline=r,c+=this.cachedMeasureText(u,o)+t,l++;continue}let d=l;for(;l<a.length;){let e=a[l];if(!Aa(r)&&!$l(e)&&e.trim().length===0)break;if(Aa(r)||!$l(e)&&e.trim().length>0)l++;else break}this.ctx.save(),this.ctx.translate(e.bounds.left+n,c),this.ctx.rotate(s);let f=0;for(let e=d;e<l;e++){let n=a[e];i(n,0,f),f+=this.cachedMeasureText(n,o)+t}this.ctx.restore(),c+=f}}renderTextWithLetterSpacing(e,t,n,r=0){this.renderFillText(e,t,n,r)}canRenderWholeText(e,t){return e===0&&!ka(t)}renderFillText(e,t,n,r){this.canRenderWholeText(t,r)?this.ctx.fillText(e.text,e.bounds.left,e.bounds.top+n):this.iterateLettersWithLetterSpacing(e,t,n,r,(e,t,n)=>{this.ctx.fillText(e,t,n)})}renderStrokeText(e,t,n,r){this.canRenderWholeText(t,r)?this.ctx.strokeText(e.text,e.bounds.left,e.bounds.top+n):this.iterateLettersWithLetterSpacing(e,t,n,r,(e,t,n)=>{this.ctx.strokeText(e,t,n)})}renderTextStrokeWithStyle(e,t,n){t.webkitTextStrokeWidth&&e.text.trim().length&&(this.ctx.strokeStyle=z(t.webkitTextStrokeColor),this.ctx.lineWidth=t.webkitTextStrokeWidth,this.ctx.lineJoin=tu(),this.renderStrokeText(e,t.letterSpacing,n,t.writingMode),this.ctx.strokeStyle=``,this.ctx.lineWidth=0,this.ctx.lineJoin=`miter`)}renderTextFillWithShadows(e,t,n){this.ctx.fillStyle=this.resolveFillColor(t),this.renderTextWithLetterSpacing(e,t.letterSpacing,n,t.writingMode);let r=t.textShadow;r.length&&e.text.trim().length&&(r.slice(0).reverse().forEach(r=>{this.ctx.shadowColor=z(r.color),this.ctx.shadowOffsetX=r.offsetX.number*this.options.scale,this.ctx.shadowOffsetY=r.offsetY.number*this.options.scale,this.ctx.shadowBlur=r.blur.number*this.options.scale,this.renderTextWithLetterSpacing(e,t.letterSpacing,n,t.writingMode)}),this.ctx.shadowColor=``,this.ctx.shadowOffsetX=0,this.ctx.shadowOffsetY=0,this.ctx.shadowBlur=0)}renderTextBoundWithPaintOrder(e,t,n,r){n.forEach(n=>{switch(n){case 0:this.ctx.fillStyle=this.resolveFillColor(t),this.renderTextWithLetterSpacing(e,t.letterSpacing,r,t.writingMode);break;case 1:this.renderTextStrokeWithStyle(e,t,r)}})}renderTextDecoration(e,t){this.decorationRenderer.render(e,t)}truncateTextWithEllipsis(e,t,n){let r=this.ctx.measureText(`…`).width,i=Zs(e);if(n===0){let e=e=>this.ctx.measureText(i.slice(0,e).join(``)).width+r<=t,n=0,a=i.length;for(;n<a;){let t=n+a+1>>1;e(t)?n=t:a=t-1}return i.slice(0,n).join(``)+`…`}{let e=this.ctx.font,a=r,o=[];for(let r of i){let i=this.cachedMeasureText(r,e);if(a+i>t)break;o.push(r),a+=i+n}return o.join(``)+`…`}}createFontStyle(e){let t=e.fontVariant.filter(e=>e===`normal`||e===`small-caps`).join(``),n=e.fontFamily.join(`, `),r=T(e.fontSize)?`${e.fontSize.number}${e.fontSize.unit}`:`${e.fontSize.number}px`;return[[e.fontStyle,t,e.fontWeight,r,n].join(` `),n,r]}resolveFillColor(e){return z(e.webkitTextFillColor??e.color)}renderLineClampedText(e,t,n,r,i){let a=na(t.lineHeight,t.fontSize.number),o=[],s=[],l=c(e.textBounds,0).bounds.top;e.textBounds.forEach(e=>{Math.abs(e.bounds.top-l)>=a*.5?(s.length>0&&o.push(s),s=[e],l=e.bounds.top):s.push(e)}),s.length>0&&o.push(s);let u=t.webkitLineClamp;if(o.length<=u)return!1;for(let e=0;e<u-1;e++)c(o,e).forEach(e=>this.renderTextBoundWithPaintOrder(e,t,n,r));let d=o[u-1];if(d?.length&&i){let e=d.map(e=>e.text).join(``),a=c(d,0),o=i.width-(a.bounds.left-i.left),s=new Gs(this.truncateTextWithEllipsis(e,o,t.letterSpacing),a.bounds);for(let e of n)e===0?(this.ctx.fillStyle=this.resolveFillColor(t),this.renderTextWithLetterSpacing(s,t.letterSpacing,r,t.writingMode)):e===1&&this.renderTextStrokeWithStyle(s,t,r)}return!0}renderEllipsisText(e,t,n,r,i){let a=na(t.lineHeight,t.fontSize.number),o=c(e.textBounds,0).bounds.top;if(!e.textBounds.every(e=>Math.abs(e.bounds.top-o)<a*.5))return!1;let s=e.textBounds.map(e=>e.text).join(``).replace(/\s+/g,` `).trim();if(this.ctx.measureText(s).width<=i.width+1)return!1;let l=new Gs(this.truncateTextWithEllipsis(s,i.width,t.letterSpacing),c(e.textBounds,0).bounds);for(let e of n)e===0?this.renderTextFillWithShadows(l,t,r):e===1&&this.renderTextStrokeWithStyle(l,t,r);return!0}measureBaselineCached(e,t){let n=this.baselineCache.get(e);return n===void 0&&(n=Zl(this.ctx,t),this.baselineCache.size>=64&&this.baselineCache.clear(),this.baselineCache.set(e,n)),n}async renderTextNode(e,t,n){this.glyphWidthCache=null;let[r]=this.createFontStyle(t);this.ctx.font=r??``,this.ctx.direction=t.direction===1?`rtl`:`ltr`,this.ctx.textAlign=`left`,this.ctx.textBaseline=`alphabetic`;let i=t.paintOrder,a=this.measureBaselineCached(r??``,t.fontSize.number);t.webkitLineClamp>0&&t.display&34&&t.overflowY===1&&e.textBounds.length>0&&this.renderLineClampedText(e,t,i,a,n)||t.textOverflow===1&&n&&t.overflowX===1&&e.textBounds.length>0&&this.renderEllipsisText(e,t,i,a,n)||(e.textBounds.forEach(e=>{i.forEach(n=>{n===0?(this.renderTextFillWithShadows(e,t,a),t.textDecorationLine.length&&this.renderTextDecoration(e.bounds,t)):n===1&&this.renderTextStrokeWithStyle(e,t,a)})}),t.textEmphasisStyle&&this.renderTextEmphasis(e,t,a))}renderTextEmphasis(e,t,n){if(ka(t.writingMode))return;let r=t.textEmphasisStyle;if(!r)return;let i=t.fontSize.number,a=i*.5,o=z(t.textEmphasisColor??t.color),s=t.textEmphasisPosition,c=(e,t)=>{if(typeof r==`string`){let n=this.ctx.font;this.ctx.font=n.replace(/^\S+/,`${a}px`),this.ctx.textAlign=`center`,this.ctx.fillText(r,e,t+a/3),this.ctx.font=n,this.ctx.textAlign=`left`;return}let{fill:n,shape:i}=r,o=a*(i===`dot`?.3:i===`sesame`?.26:.34);this.ctx.beginPath(),i===`sesame`?this.ctx.ellipse(e,t,o*1.3,o*.8,Math.PI/4,0,Math.PI*2):i===`triangle`?(this.ctx.moveTo(e,t-o),this.ctx.lineTo(e+o*1.1,t+o*.8),this.ctx.lineTo(e-o*1.1,t+o*.8),this.ctx.closePath()):this.ctx.arc(e,t,o,0,Math.PI*2),n?i===`double-circle`?(this.ctx.lineWidth=o*.7,this.ctx.stroke(),this.ctx.beginPath(),this.ctx.arc(e,t,o*.4,0,Math.PI*2),this.ctx.lineWidth=o*.35,this.ctx.stroke()):this.ctx.fill():(this.ctx.lineWidth=Math.max(1,o*.35),this.ctx.stroke(),i===`double-circle`&&(this.ctx.beginPath(),this.ctx.arc(e,t,o*.5,0,Math.PI*2),this.ctx.stroke()))},l=this.ctx.font;for(let r of e.textBounds){let e=r.bounds.top+n,u=s.over?e-i-a*.4:e+a*.9,d=r.bounds.left;for(let e of Zs(r.text)){let n=this.cachedMeasureText(e,l);this.ctx.save();try{this.ctx.fillStyle=o,this.ctx.strokeStyle=o,this.ctx.lineWidth=1,c(d+n/2+t.letterSpacing/2,u)}finally{this.ctx.restore()}d+=n+t.letterSpacing}}}};let ru=(e,t)=>{t.forEach((t,n)=>{let r=Y(t)?t.start:t;n===0?e.moveTo(r.x,r.y):e.lineTo(r.x,r.y),Y(t)&&e.bezierCurveTo(t.startControl.x,t.startControl.y,t.endControl.x,t.endControl.y,t.end.x,t.end.y)})},iu=(e,t)=>{e.beginPath(),ru(e,t),e.closePath()};var au=class{maxSize;_map;constructor(e){this.maxSize=e,this._map=/* @__PURE__ */ new Map}get(e){if(!this._map.has(e))return;let t=this._map.get(e);return this._map.delete(e),this._map.set(e,t),t}set(e,t){if(this._map.has(e))this._map.delete(e);else if(this._map.size>=this.maxSize){let e=this._map.keys().next().value;e!==void 0&&this._map.delete(e)}this._map.set(e,t)}get size(){return this._map.size}clear(){this._map.clear()}},ou=class{ctx;context;canvas;patternCache=new au(50);constructor(e){this.ctx=e.ctx,this.context=e.context,this.canvas=e.canvas}async renderBackgroundImage(e){let t=e.styles.backgroundImage.length-1,n=e.styles.backgroundBlendMode,r=0;for(let i of e.styles.backgroundImage.slice(0).reverse()){if(r>0){let e=n[r]??n[0]??`normal`;e!==`normal`&&(this.ctx.save(),this.ctx.globalCompositeOperation=e)}i.type===0?await this.renderBackgroundURLImage(e,i,t):ni(i)?this.renderLinearGradient(e,i,t):ii(i)?this.renderRepeatingLinearGradient(e,i,t):ri(i)?this.renderRadialGradient(e,i,t):ai(i)?this.renderRepeatingRadialGradient(e,i,t):oi(i)?this.renderConicGradient(e,i,t):si(i)&&this.renderRepeatingConicGradient(e,i,t),r>0&&(n[r]??n[0]??`normal`)!==`normal`&&this.ctx.restore(),t--,r++}}async renderBackgroundURLImage(e,t,n){let r,i=t.url;try{r=await this.context.cache.match(i)}catch{this.context.logger.error(`Error loading background-image ${i}`)}if(r){let t=isNaN(r.width)||r.width===0?1:r.width,a=isNaN(r.height)||r.height===0?1:r.height,[o,s,c,l,u]=ul(e,n,[t,a,t/a]),d=ml(e.styles.backgroundRepeat,n),f=d===1?`no-repeat`:d===2?`repeat-x`:d===3?`repeat-y`:`repeat`,p=`${i}|${Math.round(l)}x${Math.round(u)}|${e.styles.imageRendering}|${f}`,m=this.patternCache.get(p);if(!m){let t=this.resizeImage(r,l,u,e.styles.imageRendering);m=this.ctx.createPattern(t,f),this.patternCache.set(p,m)}this.renderRepeat(o,m,s,c)}}renderRepeatingLinearGradient(e,t,n){let[r,i,a,o,s]=ul(e,n,[null,null,null]),[l,u,d,f,p]=Pr(t.angle,o,s),m=i+u,h=i+d,g=a+f,_=a+p,v=W(t.stops,l||1),y=rl(v),b=this.ctx.createLinearGradient(m,g,h,_);if(y)y.forEach(e=>b.addColorStop(Math.min(1,Math.max(0,e.stop)),e.color));else{let e=z(c(v,v.length-1).color);b.addColorStop(0,e),b.addColorStop(1,e)}this.path(r),this.ctx.fillStyle=b,this.ctx.fill()}renderLinearGradient(e,t,n){let[r,i,a,o,s]=ul(e,n,[null,null,null]),[c,l,u,d,f]=Pr(t.angle,o,s),p=`lg|${t.angle}|${Math.round(o)}x${Math.round(s)}|${JSON.stringify(t.stops)}`,m=this.patternCache.get(p);if(!m){let e=(this.canvas.ownerDocument??document).createElement(`canvas`);e.width=o,e.height=s;let n=e.getContext(`2d`);if(!n)return;let r=n.createLinearGradient(l,d,u,f);W(t.stops,c||1).forEach(e=>r.addColorStop(e.stop,z(e.color))),n.fillStyle=r,n.fillRect(0,0,o,s),o>0&&s>0&&(m=this.ctx.createPattern(e,`repeat`),this.patternCache.set(p,m))}m&&this.renderRepeat(r,m,i,a)}renderRadialGradient(e,t,n){let[r,i,a,o,s]=ul(e,n,[null,null,null]),l=t.position.length===0?[P]:t.position,u=I(c(l,0),o),d=I(c(l,l.length-1),s),[f,p]=Ir(t,u,d,o,s);if((f===0||p===0)&&(f=Math.max(f,.01),p=Math.max(p,.01)),f>0&&p>0){let e=`rg|${Math.round(u)}x${Math.round(d)}|${Math.round(f)}x${Math.round(p)}|${JSON.stringify(t.stops)}`,n=W(t.stops,f),o=z(c(n,n.length-1).color),s=this.patternCache.get(e);if(!s){let n=this.canvas.ownerDocument??document,r=al(n,f,p,t.stops,!1);if(!r)return;s=this.ctx.createPattern(r.canvas,`no-repeat`),this.patternCache.set(e,s)}this.path(r),this.ctx.save(),this.ctx.clip(),this.ctx.fillStyle=o,this.ctx.fill(),this.ctx.translate(i+u-f,a+d-p),this.ctx.fillStyle=s,this.ctx.fillRect(0,0,f*2,p*2),this.ctx.restore()}}renderRepeatingRadialGradient(e,t,n){let[r,i,a,o,s]=ul(e,n,[null,null,null]),l=t.position.length===0?[P]:t.position,u=I(c(l,0),o),d=I(c(l,l.length-1),s),[f,p]=Ir(t,u,d,o,s);if((f===0||p===0)&&(f=Math.max(f,.01),p=Math.max(p,.01)),!(f>0&&p>0))return;let m=`rrg|${Math.round(u)}x${Math.round(d)}|${Math.round(f)}x${Math.round(p)}|${JSON.stringify(t.stops)}`,h=this.patternCache.get(m);if(!h){let e=this.canvas.ownerDocument??document,n=al(e,f,p,t.stops,!0);if(!n)return;h=this.ctx.createPattern(n.canvas,`no-repeat`),this.patternCache.set(m,h)}h&&(this.path(r),this.ctx.save(),this.ctx.clip(),this.ctx.translate(i+u-f,a+d-p),this.ctx.fillStyle=h,this.ctx.fillRect(0,0,f*2,p*2),this.ctx.restore())}renderConicGradient(e,t,n){let[r,i,a,o,s]=ul(e,n,[null,null,null]),l=t.position.length===0?[P]:t.position,u=i+I(c(l,0),o),d=a+I(c(l,l.length-1),s),f=this.ctx.createConicGradient(t.angle-Math.PI/2,u,d);W(t.stops,1).forEach(e=>{f.addColorStop(Math.min(1,Math.max(0,e.stop)),z(e.color))}),this.path(r),this.ctx.save(),this.ctx.clip(),this.ctx.fillStyle=f,this.ctx.fill(),this.ctx.restore()}renderRepeatingConicGradient(e,t,n){let[r,i,a,o,s]=ul(e,n,[null,null,null]),l=t.position.length===0?[P]:t.position,u=i+I(c(l,0),o),d=a+I(c(l,l.length-1),s),f=W(t.stops,1),p=c(f,0),m=c(f,f.length-1),h=Math.max(m.stop-p.stop,.01);if(m.stop-p.stop<1e-6){let e=this.ctx.createConicGradient(t.angle-Math.PI/2,u,d);e.addColorStop(0,z(m.color)),e.addColorStop(1,z(m.color)),this.path(r),this.ctx.save(),this.ctx.clip(),this.ctx.fillStyle=e,this.ctx.fill(),this.ctx.restore();return}let g=[],_=Math.ceil(1/h);for(let e=0;e<_;e++)for(let t of f){let n=e*h+(t.stop-p.stop);if(n>1)break;g.push({stop:n,color:z(t.color)})}let v=c(g,g.length-1);v&&v.stop<1&&g.push({stop:1,color:v.color});let y=this.ctx.createConicGradient(t.angle-Math.PI/2,u,d);g.forEach(e=>{y.addColorStop(Math.min(1,Math.max(0,e.stop)),e.color)}),this.path(r),this.ctx.save(),this.ctx.clip(),this.ctx.fillStyle=y,this.ctx.fill(),this.ctx.restore()}renderRepeat(e,t,n,r){this.path(e),this.ctx.fillStyle=t,this.ctx.translate(n,r),this.ctx.fill(),this.ctx.translate(-n,-r)}resizeImage(e,t,n,r){let i=(this.canvas.ownerDocument??document).createElement(`canvas`);i.width=Math.max(1,t),i.height=Math.max(1,n);let a=i.getContext(`2d`);return a?(r===2||r===1?(this.context.logger.debug(`Disabling image smoothing for background image due to CSS image-rendering`),a.imageSmoothingEnabled=!1):r===3?(this.context.logger.debug(`Enabling image smoothing for background image due to CSS image-rendering: smooth`),a.imageSmoothingEnabled=!0):a.imageSmoothingEnabled=this.ctx.imageSmoothingEnabled,this.ctx.imageSmoothingQuality&&(a.imageSmoothingQuality=this.ctx.imageSmoothingQuality),a.drawImage(e,0,0,e.width,e.height,0,0,t,n),i):e}path(e){iu(this.ctx,e)}};let su=(e,t)=>{switch(t){case 0:return $(e.topLeftBorderBox,e.topLeftPaddingBox,e.topRightBorderBox,e.topRightPaddingBox);case 1:return $(e.topRightBorderBox,e.topRightPaddingBox,e.bottomRightBorderBox,e.bottomRightPaddingBox);case 2:return $(e.bottomRightBorderBox,e.bottomRightPaddingBox,e.bottomLeftBorderBox,e.bottomLeftPaddingBox);default:return $(e.bottomLeftBorderBox,e.bottomLeftPaddingBox,e.topLeftBorderBox,e.topLeftPaddingBox)}},cu=(e,t)=>{switch(t){case 0:return $(e.topLeftBorderBox,e.topLeftBorderDoubleOuterBox,e.topRightBorderBox,e.topRightBorderDoubleOuterBox);case 1:return $(e.topRightBorderBox,e.topRightBorderDoubleOuterBox,e.bottomRightBorderBox,e.bottomRightBorderDoubleOuterBox);case 2:return $(e.bottomRightBorderBox,e.bottomRightBorderDoubleOuterBox,e.bottomLeftBorderBox,e.bottomLeftBorderDoubleOuterBox);default:return $(e.bottomLeftBorderBox,e.bottomLeftBorderDoubleOuterBox,e.topLeftBorderBox,e.topLeftBorderDoubleOuterBox)}},lu=(e,t)=>{switch(t){case 0:return $(e.topLeftBorderDoubleInnerBox,e.topLeftPaddingBox,e.topRightBorderDoubleInnerBox,e.topRightPaddingBox);case 1:return $(e.topRightBorderDoubleInnerBox,e.topRightPaddingBox,e.bottomRightBorderDoubleInnerBox,e.bottomRightPaddingBox);case 2:return $(e.bottomRightBorderDoubleInnerBox,e.bottomRightPaddingBox,e.bottomLeftBorderDoubleInnerBox,e.bottomLeftPaddingBox);default:return $(e.bottomLeftBorderDoubleInnerBox,e.bottomLeftPaddingBox,e.topLeftBorderDoubleInnerBox,e.topLeftPaddingBox)}},uu=(e,t)=>{switch(t){case 0:return du(e.topLeftBorderStroke,e.topRightBorderStroke);case 1:return du(e.topRightBorderStroke,e.bottomRightBorderStroke);case 2:return du(e.bottomRightBorderStroke,e.bottomLeftBorderStroke);default:return du(e.bottomLeftBorderStroke,e.topLeftBorderStroke)}},du=(e,t)=>{let n=[];return Y(e)?n.push(e.subdivide(.5,!1)):n.push(e),Y(t)?n.push(t.subdivide(.5,!0)):n.push(t),n},$=(e,t,n,r)=>{let i=[];return Y(e)?i.push(e.subdivide(.5,!1)):i.push(e),Y(n)?i.push(n.subdivide(.5,!0)):i.push(n),Y(r)?i.push(r.subdivide(.5,!0).reverse()):i.push(r),Y(t)?i.push(t.subdivide(.5,!1).reverse()):i.push(t),i};var fu=class{ctx;pathCallbacks;constructor(e,t){this.ctx=e.ctx,this.pathCallbacks=t}async renderSolidBorder(e,t,n){this.pathCallbacks.path(su(n,t)),this.ctx.fillStyle=z(e),this.ctx.fill()}async renderDoubleBorder(e,t,n,r){if(t<3){await this.renderSolidBorder(e,n,r);return}let i=cu(r,n);this.pathCallbacks.path(i),this.ctx.fillStyle=z(e),this.ctx.fill();let a=lu(r,n);this.pathCallbacks.path(a),this.ctx.fill()}async renderDashedDottedBorder(e,t,n,r,i){this.ctx.save();let a=uu(r,n),o=su(r,n);i===2&&(this.pathCallbacks.path(o),this.ctx.clip());let s,l,u,d;Y(c(o,0))?(s=c(o,0).start.x,l=c(o,0).start.y):(s=c(o,0).x,l=c(o,0).y),Y(c(o,1))?(u=c(o,1).end.x,d=c(o,1).end.y):(u=c(o,1).x,d=c(o,1).y);let f;f=Math.abs(n===0||n===2?s-u:l-d),this.ctx.beginPath(),i===3?this.pathCallbacks.formatPath(a):this.pathCallbacks.formatPath(o.slice(0,2));let p=t<3?t*3:t*2,m=t<3?t*2:t;i===3&&(p=t,m=t);let h=!0;if(f<=p*2)h=!1;else if(f<=p*2+m){let e=f/(2*p+m);p*=e,m*=e}else{let e=Math.floor((f+m)/(p+m)),t=(f-e*p)/(e-1),n=(f-(e+1)*p)/e;m=n<=0||Math.abs(m-t)<Math.abs(m-n)?t:n}if(h&&(i===3?this.ctx.setLineDash([0,p+m]):this.ctx.setLineDash([p,m])),i===3?(this.ctx.lineCap=`round`,this.ctx.lineWidth=t):this.ctx.lineWidth=t*2+1.1,this.ctx.strokeStyle=z(e),this.ctx.stroke(),this.ctx.setLineDash([]),i===2){if(Y(c(o,0))){let e=c(o,3),t=c(o,0);this.ctx.beginPath(),this.pathCallbacks.formatPath([new J(e.end.x,e.end.y),new J(t.start.x,t.start.y)]),this.ctx.stroke()}if(Y(c(o,1))){let e=c(o,1),t=c(o,2);this.ctx.beginPath(),this.pathCallbacks.formatPath([new J(e.end.x,e.end.y),new J(t.start.x,t.start.y)]),this.ctx.stroke()}}this.ctx.restore()}};let pu=(e,t,n)=>{let r=e?[e.top,e.right,e.bottom,e.left]:null;return[0,1,2,3].map(e=>{let i=r?r[e]:null,a=t[e]??0;return!i||i.kind===`auto`?a:i.kind===`number`?a*(i.value??1):i.kind===`length`?i.value??0:(i.value??0)/100*(e===0||e===2?n.height:n.width)})},mu=(e,t)=>{let n=e?[e.top,e.right,e.bottom,e.left]:null,r=e=>{let r=n?n[e]:null;return r?r.kind===`number`?(t[e]??0)*(r.value??0):r.value??0:0};return{top:r(0),right:r(1),bottom:r(2),left:r(3)}};var hu=class{ctx;constructor(e){this.ctx=e}renderBorderImage(e,t,n,r,i,a,o,s,c={top:0,right:0,bottom:0,left:0}){e=e.add(-c.left,-c.top,c.left+c.right,c.top+c.bottom);let l=t.naturalWidth||t.width,u=t.naturalHeight||t.height;if(l<=0||u<=0)return;let d=Math.min(n.unit===`percent`?n.top/100*u:Math.min(n.top,u),u),f=Math.min(n.unit===`percent`?n.right/100*l:Math.min(n.right,l),l),p=Math.min(n.unit===`percent`?n.bottom/100*u:Math.min(n.bottom,u),u),m=Math.min(n.unit===`percent`?n.left/100*l:Math.min(n.left,l),l),{left:h,top:g,width:_,height:v}=e;if(_<=0||v<=0)return;let y=Math.min(i,v),b=Math.min(a,_),x=Math.min(o,v-y),S=Math.min(s,_-b);this.drawRegion(t,0,0,m,d,h,g,S,y),this.drawRegion(t,l-f,0,f,d,h+_-b,g,b,y),this.drawRegion(t,l-f,u-p,f,p,h+_-b,g+v-x,b,x),this.drawRegion(t,0,u-p,m,p,h,g+v-x,S,x);let C=[{sx:m,sy:0,sw:l-m-f,sh:d,dx:h+S,dy:g,dw:_-S-b,dh:y,repeat:r.horizontal,horizontal:!0},{sx:l-f,sy:d,sw:f,sh:u-d-p,dx:h+_-b,dy:g+y,dw:b,dh:v-y-x,repeat:r.vertical,horizontal:!1},{sx:m,sy:u-p,sw:l-m-f,sh:p,dx:h+S,dy:g+v-x,dw:_-S-b,dh:x,repeat:r.horizontal,horizontal:!0},{sx:0,sy:d,sw:m,sh:u-d-p,dx:h,dy:g+y,dw:S,dh:v-y-x,repeat:r.vertical,horizontal:!1}];for(let e of C)e.sw<=0||e.sh<=0||e.dw<=0||e.dh<=0||(e.repeat===0?this.ctx.drawImage(t,e.sx,e.sy,e.sw,e.sh,e.dx,e.dy,e.dw,e.dh):(e.repeat===1||e.repeat===2)&&this.drawRepeatedEdge(t,e,e.horizontal,e.repeat===2));n.fill&&this.drawCenterRegion(t,{sx:m,sy:d,sw:l-m-f,sh:u-d-p},{dx:h+S,dy:g+y,dw:_-S-b,dh:v-y-x},r)}drawRegion(e,t,n,r,i,a,o,s,c){r>0&&i>0&&s>0&&c>0&&this.ctx.drawImage(e,t,n,r,i,a,o,s,c)}drawRepeatedEdge(e,t,n,r){let i=n?t.sw:t.sh,a=n?t.dw:t.dh;if(i<=0||a<=0)return;let o,s;r?(s=Math.max(1,Math.round(a/i)),o=a/s):(o=i,s=Math.ceil(a/o)),this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(t.dx,t.dy,t.dw,t.dh),this.ctx.clip();for(let r=0;r<s;r++){let i=r*o;n?this.ctx.drawImage(e,t.sx,t.sy,t.sw,t.sh,t.dx+i,t.dy,o,t.dh):this.ctx.drawImage(e,t.sx,t.sy,t.sw,t.sh,t.dx,t.dy+i,t.dw,o)}this.ctx.restore()}drawCenterRegion(e,t,n,r){if(t.sw<=0||t.sh<=0||n.dw<=0||n.dh<=0)return;let i=(e,t,n)=>{if(e===0)return{size:n,count:1};if(e===2){let e=Math.max(1,Math.round(n/t));return{size:n/e,count:e}}return{size:t,count:Math.max(1,Math.ceil(n/t))}},a=i(r.horizontal,t.sw,n.dw),o=i(r.vertical,t.sh,n.dh);this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(n.dx,n.dy,n.dw,n.dh),this.ctx.clip();for(let r=0;r<o.count;r++)for(let i=0;i<a.count;i++)this.ctx.drawImage(e,t.sx,t.sy,t.sw,t.sh,n.dx+i*a.size,n.dy+r*o.size,a.size,o.size);this.ctx.restore()}};let gu=/blur\((\d+(?:\.\d+)?)px\)/gi,_u=(e,t)=>t===1?e:e.replace(gu,(e,n)=>`blur(${parseFloat(n)*t}px)`);var vu=class{ctx;pathCallback;scale;activeEffects=[];didSave=!1;saveAtDepth=-1;constructor(e,t){this.ctx=e.ctx,this.pathCallback=t,this.scale=e.scale??1}applyEffects(e){for(;this.activeEffects.length;)this.popEffect();this.didSave=!1,this.saveAtDepth=-1;let t=e=>Hc(e)||Uc(e)||Gc(e),n=e.reduceRight((e,n,r)=>e===-1?t(n)?r:-1:e,-1);for(let r=0;r<e.length;r++){let i=c(e,r);t(i)&&(this.didSave||=(this.ctx.save(),!0),r===n&&(this.saveAtDepth=this.activeEffects.length)),this.applyEffect(i)}}applyEffect(e){Hc(e)?(this.ctx.translate(e.offsetX,e.offsetY),this.ctx.transform(e.matrix[0],e.matrix[1],e.matrix[2],e.matrix[3],e.matrix[4],e.matrix[5]),this.ctx.translate(-e.offsetX,-e.offsetY)):Uc(e)?(this.pathCallback.path(e.path),this.ctx.clip()):Gc(e)?e.applyClip(this.ctx):Wc(e)?this.ctx.globalAlpha*=e.opacity:Kc(e)?this.ctx.globalCompositeOperation=e.compositeOperation:qc(e)&&(this.ctx.filter=_u(e.safeFilterString,this.scale)||`none`,e.shadow&&(this.ctx.shadowOffsetX=e.shadow.offsetX*this.scale,this.ctx.shadowOffsetY=e.shadow.offsetY*this.scale,this.ctx.shadowBlur=e.shadow.blur*this.scale,this.ctx.shadowColor=e.shadow.color)),this.activeEffects.push(e)}popEffect(){this.activeEffects.length!==0&&(this.didSave&&this.activeEffects.length-1===this.saveAtDepth&&(this.ctx.restore(),this.didSave=!1,this.saveAtDepth=-1),this.activeEffects.pop(),!this.didSave&&this.activeEffects.length===0&&(this.ctx.globalAlpha=1,this.ctx.globalCompositeOperation=`source-over`,this.ctx.filter=`none`,this.ctx.shadowOffsetX=0,this.ctx.shadowOffsetY=0,this.ctx.shadowBlur=0,this.ctx.shadowColor=`rgba(0, 0, 0, 0)`))}getActiveEffectCount(){return this.activeEffects.length}hasActiveEffects(){return this.activeEffects.length>0}};let yu=(e,t)=>e.length===0?void 0:e[t%e.length]??e[0],bu=(e,t,n,r)=>{let i=e?e[0]:void 0,a=e&&e.length>1?c(e,1):void 0,o=e=>e!==void 0&&D(e)?e.value:null,s=(e,t,n)=>e===void 0||D(e)?null:M(e)?I(e,t):n,l=o(i);if(l===`contain`||l===`cover`){let e=l===`contain`?Math.min(t.width/n,t.height/r):Math.max(t.width/n,t.height/r);return{width:n*e,height:r*e}}let u=s(i,t.width,n),d=s(a,t.height,r);return u===null&&d===null?(u=n,d=r):u===null?u=n/r*d:d===null&&(d=r/n*u),{width:u,height:d}},xu=(e,t,n,r,i)=>{let a=t.naturalWidth||t.width||i.width,o=t.naturalHeight||t.height||i.height,{width:s,height:l}=bu(yu(n.maskSize,r),i,a,o),u=yu(n.maskPosition,r)??[],d=i.left+I(c(u,0),i.width-s),f=i.top+I(c(u,u.length-1),i.height-l),p=yu(n.maskRepeat,r)??0,m=p===0||p===2,h=p===0||p===3,g=m?Math.ceil((d-i.left)/s):0,_=h?Math.ceil((f-i.top)/l):0,v=m?Math.ceil((i.left+i.width-d)/s):0,y=h?Math.ceil((i.top+i.height-f)/l):0;for(let n=-_;n<=y;n++)for(let r=-g;r<=v;r++)e.drawImage(t,d+r*s,f+n*l,s,l)},Su=(e,t,n)=>{let{width:r,height:i}=n,a=t.position.length===0?[P]:t.position,o=I(c(a,0),r),s=I(c(a,a.length-1),i),[l,u]=Ir(t,o,s,r,i);l=Math.max(l,.01),u=Math.max(u,.01);let d=e.canvas.ownerDocument??document,f=al(d,l,u,t.stops,ai(t));f&&(e.fillStyle=f.lastColor,e.fillRect(n.left,n.top,n.width,n.height),e.drawImage(f.canvas,n.left+o-l,n.top+s-u,l*2,u*2),Q(f.canvas))},Cu=(e,t,n)=>{let{width:r,height:i}=n;if(r<=0||i<=0)return;if(ri(t)||ai(t)){Su(e,t,n);return}let a=null;if(t.type===1||t.type===3){let o=t,[s,l,u,d,f]=Pr(o.angle||0,r,i),p=W(o.stops,s||1);if(t.type===3){let t=rl(p);if(!t){e.fillStyle=z(c(p,p.length-1).color),e.fillRect(n.left,n.top,r,i);return}a=e.createLinearGradient(n.left+l,n.top+d,n.left+u,n.top+f),t.forEach(e=>a.addColorStop(Math.min(1,Math.max(0,e.stop)),e.color))}else a=e.createLinearGradient(n.left+l,n.top+d,n.left+u,n.top+f),il(p).forEach(e=>a.addColorStop(e.stop,e.color))}else if(t.type===5||t.type===6){let o=t,s=W(o.stops,1),l=t.type===6;if(l&&!rl(s)){e.fillStyle=z(c(s,s.length-1).color),e.fillRect(n.left,n.top,r,i);return}a=e.createConicGradient(o.angle-Math.PI/2,n.left+r/2,n.top+i/2),((l?rl(s):null)??il(s)).forEach(e=>a.addColorStop(Math.min(1,Math.max(0,e.stop)),e.color))}a&&(e.fillStyle=a,e.fillRect(n.left,n.top,r,i))},wu=async(e,t,n,r,i)=>{for(let a=0;a<t.length;a++){let o=c(t,a);if(o.type===0){let t=await i(o.url);t&&xu(e,t,n,a,r)}else Cu(e,o,r)}},Tu=(e,t,n,r,i)=>{let a=0,o=0,s=e,c=t,l=n.left,u=n.top,d=n.width,f=n.height,p=d/f,m=s/c,h=i?I(i[0],1):.5,g=i?I(i[1],1):.5;if(r===2)m>p?(f=d/m,u+=(n.height-f)*g):(d=f*m,l+=(n.width-d)*h);else if(r===4)m>p?(s=c*p,a+=(e-s)*h):(c=s/p,o+=(t-c)*g);else if(r===8)s>d?(a+=(s-d)*h,s=d):(l+=(d-s)*h,d=s),c>f?(o+=(c-f)*g,c=f):(u+=(f-c)*g,f=c);else if(r===16){let e=m>p?d:f*m,t=m>p?d/m:f,r=Math.min(s,d),i=Math.min(c,f);e*t<r*i?m>p?(f=d/m,u+=(n.height-f)*g):(d=f*m,l+=(n.width-d)*h):(s>d?(a+=(s-d)*h,s=d):(l+=(d-s)*h,d=s),c>f?(o+=(c-f)*g,c=f):(u+=(f-c)*g,f=c))}return{sx:a,sy:o,sw:s,sh:c,dx:l,dy:u,dw:d,dh:f}};async function Eu(e,t,n,r,i,a,o,s){if(i instanceof ic)try{let n=await t.cache.match(i.src),r=e.imageSmoothingEnabled;o.imageRendering===2||o.imageRendering===1?e.imageSmoothingEnabled=!1:o.imageRendering===3&&(e.imageSmoothingEnabled=!0),s(i,a,n),e.imageSmoothingEnabled=r}catch{t.logger.error(`Error loading image ${i.src}`)}if(i instanceof ac&&s(i,a,i.canvas),i instanceof cc)try{s(i,a,await t.cache.match(i.svg))}catch{t.logger.error(`Error loading svg ${i.svg.substring(0,255)}`)}if(i instanceof yc&&i.tree){let a=await r(t,{scale:n.scale,backgroundColor:i.backgroundColor,x:0,y:0,width:i.width,height:i.height}).render(i.tree);i.width&&i.height&&e.drawImage(a,0,0,i.width,i.height,i.bounds.left,i.bounds.top,i.bounds.width,i.bounds.height)}}function Du(e,t,n,r,i){if(r instanceof gc){let t=Math.min(r.bounds.width,r.bounds.height);r.type===`checkbox`&&r.checked?(e.save(),n([new J(r.bounds.left+t*.39363,r.bounds.top+t*.79),new J(r.bounds.left+t*.16,r.bounds.top+t*.5549),new J(r.bounds.left+t*.27347,r.bounds.top+t*.44071),new J(r.bounds.left+t*.39694,r.bounds.top+t*.5649),new J(r.bounds.left+t*.72983,r.bounds.top+t*.23),new J(r.bounds.left+t*.84,r.bounds.top+t*.34085),new J(r.bounds.left+t*.39363,r.bounds.top+t*.79)]),e.fillStyle=z(r.styles.accentColor??7733247),e.fill(),e.restore()):r.type===`radio`&&r.checked&&(e.save(),e.beginPath(),e.arc(r.bounds.left+t/2,r.bounds.top+t/2,t/4,0,Math.PI*2,!0),e.fillStyle=z(r.styles.accentColor??7733247),e.fill(),e.restore())}if(ju(r)&&r.value.length){let[o]=t.createFontStyle(i);e.font=o??``;let s=I(i.fontSize,0),{baseline:c,height:l}=Xl(e,s);e.fillStyle=r instanceof gc&&r.isPlaceholder?z(1970632191):z(i.color),e.textBaseline=`alphabetic`,e.textAlign=Mu(r.styles.textAlign);let u=sl(r),d=r instanceof gc?Ou(u,ol(r),l):u,f=0;switch(r.styles.textAlign){case 1:f+=u.width/2;break;case 2:f+=u.width}let p=0;r instanceof gc&&(p=(u.height-l)/2);let m=u.add(f,p,0,0);e.save(),n([new J(d.left,d.top),new J(d.left+d.width,d.top),new J(d.left+d.width,d.top+d.height),new J(d.left,d.top+d.height)]),e.clip();let h=ku(e,r.value,u.width,i.whiteSpace===`pre`||i.whiteSpace===`nowrap`),g=na(i.lineHeight,s);h.forEach((n,r)=>{let o=m.left,s=e.measureText(n).width;switch(i.textAlign){case 1:o+=(u.width-s)/2;break;case 2:o+=u.width-s}let l=new a(o,m.top+r*g,0,0);t.renderTextWithLetterSpacing(new Gs(n,l),i.letterSpacing,c,i.writingMode)}),e.restore(),e.textBaseline=`alphabetic`,e.textAlign=`left`}}let Ou=(e,t,n)=>e.height<n?new a(e.left,t.top,e.width,t.height):e,ku=(e,t,n,r)=>{let i=[],a=t.split(`
12
+ `);for(let t of a){if(r){i.push(t);continue}let a=t.split(/(\s+)/),o=``;for(let t of a){let r=o+t;e.measureText(r).width<=n||o===``?o=r:(i.push(o),o=t)}i.push(o)}return i};async function Au(e,t,n,r,i,o){if(H(i.styles.display,2048)){if(i.styles.listStyleImage!==null){let n=i.styles.listStyleImage;if(n.type===0){let r=n.url;try{let n=await t.cache.match(r),a=I(o.fontSize,0),s=n?.naturalWidth||n.width,c=n?.naturalHeight||n.height;if(s<=0||c<=0)return;let l=Math.min(a/s,a/c),u=s*l,d=c*l,f=i.bounds.top+I(i.styles.paddingTop,i.bounds.width)+na(o.lineHeight,o.fontSize.number)/2;e.drawImage(n,i.bounds.left-(u+10),f-d/2,u,d)}catch{t.logger.error(`Error loading list-style-image ${r}`)}}}else if(r.listValue&&i.styles.listStyleType!==-1){let t=i.styles.listStyleType;if(t===0||t===1||t===2){let n=o.fontSize.number*.45,r=i.bounds.left-n*.9,a=i.bounds.top+I(i.styles.paddingTop,i.bounds.width)+na(o.lineHeight,o.fontSize.number)/2;e.save(),e.fillStyle=z(o.color),e.beginPath(),t===2?e.rect(r-n/2,a-n/2,n,n):(e.arc(r,a,n/2,0,Math.PI*2),t===1&&(e.strokeStyle=z(o.color),e.lineWidth=n*.18)),t===1?e.stroke():e.fill(),e.restore()}else{let[t]=n.createFontStyle(o);e.font=t??``,e.fillStyle=z(o.color),e.textBaseline=`middle`,e.textAlign=`right`;let s=new a(i.bounds.left,i.bounds.top+I(i.styles.paddingTop,i.bounds.width),i.bounds.width,na(o.lineHeight,o.fontSize.number)/2+1);n.renderTextWithLetterSpacing(new Gs(r.listValue,s),o.letterSpacing,na(o.lineHeight,o.fontSize.number)/2+2,o.writingMode),e.textBaseline=`bottom`,e.textAlign=`left`}}}}let ju=e=>e instanceof vc||e instanceof _c||e instanceof gc&&e.type!==`radio`&&e.type!==`checkbox`,Mu=e=>{switch(e){case 1:return`center`;case 2:return`right`;default:return`left`}},Nu=(e,t)=>{let n=t>e?t*(1+(e/t-1)**3):t;return Math.max(0,e+n)},Pu=(e,t)=>{if(t===0)return e;let n=e.map((e,t)=>Y(e)?{x:t%2==0?e.start.x:e.end.x,y:t%2==0?e.end.y:e.start.y,rx:Math.abs(e.end.x-e.start.x),ry:Math.abs(e.end.y-e.start.y)}:{x:e.x,y:e.y,rx:0,ry:0}),r=c(n,1).x-c(n,0).x+2*t,i=c(n,3).y-c(n,0).y+2*t;if(r<=0||i<=0)return[];let a=n.map(e=>({x:Nu(e.rx,t),y:Nu(e.ry,t)})),o=(e,t)=>t>0?e/t:1,s=Math.min(1,o(r,c(a,0).x+c(a,1).x),o(r,c(a,3).x+c(a,2).x),o(i,c(a,0).y+c(a,3).y),o(i,c(a,1).y+c(a,2).y));return e.map((e,r)=>{let i=c(n,r),o=i.x+(r===1||r===2?t:-t),l=i.y+(r>=2?t:-t);if(!Y(e))return new J(o,l);let u=c(a,r).x*s,d=c(a,r).y*s;if(!u||!d)return new J(o,l);let f=u/i.rx,p=d/i.ry,m=e=>new J(o+(e.x-i.x)*f,l+(e.y-i.y)*p);return new Ac(m(e.start),m(e.startControl),m(e.endControl),m(e.end))})},Fu=(e,t,n)=>{let{a:r,b:i,c:o,d:s,e:c,f:l}=e;if(![r,i,o,s,c,l,t,n].every(Number.isFinite))return null;let u=r*s-i*o;if(!Number.isFinite(u)||u===0)return null;let d=(e,t)=>({x:(s*(e-c)-o*(t-l))/u,y:(-i*(e-c)+r*(t-l))/u}),f=[d(0,0),d(t,0),d(t,n),d(0,n)];if(!f.every(e=>Number.isFinite(e.x)&&Number.isFinite(e.y)))return null;let p=Math.min(...f.map(e=>e.x)),m=Math.min(...f.map(e=>e.y)),h=Math.max(...f.map(e=>e.x)),g=Math.max(...f.map(e=>e.y)),_=r*r+i*i,v=o*o+s*s,y=r*o+i*s,b=Math.sqrt((_+v+Math.hypot(_-v,2*y))/2);if(!Number.isFinite(b)||b<=0)return null;let x=1e-10*Math.max(_,v);return{matrix:e,viewport:new a(p,m,h-p,g-m),scale:b,uniform:Math.abs(_-v)<=x&&Math.abs(y)<=x}},Iu=(e,t,n)=>{e.beginPath(),e.rect(t.left,t.top,t.width,t.height),n.length&&(ru(e,n),e.closePath())},Lu=(e,t)=>{let n=t.spread.number,r=ol(e.container);return r.width-2*n<=0||r.height-2*n<=0?[]:Pu(Pc(e.curves),-n)},Ru=async(e,t,n,r,i,a)=>{let o=ol(t.container),s=n.blur.number/2,c=Math.ceil(3*s)+2,l=n.spread.number,u=ql((n.inset?o:t.container.bounds.add(n.offsetX.number-l,n.offsetY.number-l,2*l,2*l)).add(-c,-c,2*c,2*c),a.viewport,c,a.scale);if(!u.width||!u.height)return!0;let d=Math.ceil(u.width*a.scale),f=Math.ceil(u.height*a.scale),p=Ul(i,d,f);if(!p)return!1;let m,h;try{m=e.canvas.ownerDocument.createElement(`canvas`),m.width=d,m.height=f;let i=m.getContext(`2d`);if(!i)return!1;i.scale(a.scale,a.scale),i.translate(-u.left,-u.top);let o=n.inset?Lu(t,n):Pu(Mc(t.curves),l),c=Oc(o,n.offsetX.number,n.offsetY.number,0,0);n.inset?Iu(i,u,c):iu(i,c),i.fillStyle=z(n.color),i.fill(n.inset?`evenodd`:`nonzero`),h=await Fl(m,{functions:[{kind:`blur`,value:s}]},1,a.scale,r.signal),e.save();try{n.inset?(iu(e,Pc(t.curves)),e.clip()):(Iu(e,a.viewport,Mc(t.curves)),e.clip(`evenodd`)),e.drawImage(h,u.left,u.top,h.width/a.scale,h.height/a.scale)}finally{e.restore()}return!0}catch(e){if(!(e instanceof Z))throw e;return!1}finally{h&&h!==m&&Q(h),m&&Q(m),i.pixels-=p}},zu=async(e,t,n,r,i)=>{if(r.signal?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);if(R(n.color))return;let a=n.spread.number;if(!n.inset&&(t.container.bounds.width+2*a<=0||t.container.bounds.height+2*a<=0))return;let o=typeof e.getTransform==`function`,s=o?e.getTransform():{a:r.scale,b:0,c:0,d:r.scale,e:-r.x*r.scale,f:-r.y*r.scale},c=Fu(s,e.canvas.width,e.canvas.height);if(!c)return;let{viewport:l}=c;if(n.blur.number>0&&(n.inset||!c.uniform)&&await Ru(e,t,n,r,i,c))return;let u=ol(t.container);e.save();try{if(n.inset&&n.blur.number===0){iu(e,Pc(t.curves)),e.clip(),Iu(e,u,Oc(Lu(t,n),n.offsetX.number,n.offsetY.number,0,0)),e.fillStyle=z(n.color),e.fill(`evenodd`);return}let r=Math.ceil(n.blur.number*2+Math.abs(a)+Math.abs(n.offsetX.number)+Math.abs(n.offsetY.number))+2,i=n.inset?u.add(-r,-r,2*r,2*r):t.container.bounds.add(-a,-a,2*a,2*a),{a:d,b:f,c:p,d:m,e:h,f:g}=s,_=i.left+i.width,v=i.top+i.height,y=Math.max(d*i.left+p*i.top+h,d*_+p*i.top+h,d*_+p*v+h,d*i.left+p*v+h),b=Math.max(1e4,y+r*c.scale+2);n.inset?(iu(e,Pc(t.curves)),e.clip()):(Iu(e,l,Mc(t.curves)),e.clip(`evenodd`)),o?e.setTransform(d,f,p,m,h-b,g):e.translate(-b/d,0),n.inset?Iu(e,i,Lu(t,n)):iu(e,Pu(Mc(t.curves),a)),o?e.setTransform(d,f,p,m,h,g):e.translate(b/d,0),e.shadowOffsetX=b+d*n.offsetX.number+p*n.offsetY.number,e.shadowOffsetY=f*n.offsetX.number+m*n.offsetY.number,e.shadowBlur=n.blur.number*c.scale,e.shadowColor=z(n.color),e.fillStyle=`rgb(0, 0, 0)`,e.fill(n.inset?`evenodd`:`nonzero`)}finally{e.restore()}};var Bu=class{ctx;context;scale;createFontStyle;constructor(e){this.ctx=e.ctx,this.context=e.context,this.scale=e.scale,this.createFontStyle=e.createFontStyle}async render(e){let t=e.container,n=t.styles,r=t.bounds,i=this.scale;if(r.width<=0||r.height<=0)return;let a=this.ctx.canvas.ownerDocument??document,o=Math.ceil(r.width),s=Math.ceil(r.height),c=Math.ceil(r.width*i),l=Math.ceil(r.height*i),u=this.createLayer(a,c,l);if(!u)return;let d=null,f=null,p=null;try{u.ctx.scale(i,i);let[m]=this.createFontStyle(n);u.ctx.font=m??``,u.ctx.textBaseline=`alphabetic`,u.ctx.textAlign=`left`,u.ctx.direction=n.direction===1?`rtl`:`ltr`;let h=Zl(u.ctx,n.fontSize.number),g=new ou({ctx:u.ctx,context:this.context,canvas:u.canvas,options:{width:o,height:s,scale:1}});R(n.backgroundColor)||(u.ctx.fillStyle=z(n.backgroundColor),u.ctx.fillRect(0,0,o,s)),u.ctx.save(),u.ctx.translate(-r.left,-r.top),await g.renderBackgroundImage(t),u.ctx.restore();let _={bounds:r,baseline:h,letterSpacing:n.letterSpacing,writingMode:n.writingMode};if(d=this.createGlyphLayer(a,c,l,u.ctx),!d)return;let v=!!n.webkitTextStrokeWidth;v&&(d.ctx.strokeStyle=z(n.webkitTextStrokeColor),d.ctx.lineWidth=n.webkitTextStrokeWidth,d.ctx.lineJoin=tu());for(let e of t.textNodes)for(let t of e.textBounds)this.drawGlyphs(d,t,_,(e,t,n,r)=>{e.fillText(t,n,r),v&&e.strokeText(t,n,r)});if(u.ctx.globalCompositeOperation=`destination-in`,u.ctx.drawImage(d.canvas,0,0,o,s),p=this.renderShadowSilhouettes(e,a,c,l,u.ctx,n,_),p){if(f=this.createLayer(a,c,l),!f)return;for(let e of p)f.ctx.drawImage(e,0,0);f.ctx.drawImage(u.canvas,0,0),this.ctx.drawImage(f.canvas,r.left,r.top,r.width,r.height)}else this.ctx.drawImage(u.canvas,r.left,r.top,r.width,r.height)}finally{Q(u.canvas),d&&Q(d.canvas),f&&Q(f.canvas),p&&p.forEach(Q)}}createLayer(e,t,n){let r=e.createElement(`canvas`);r.width=t,r.height=n;let i=r.getContext(`2d`);return i?{canvas:r,ctx:i}:null}createGlyphLayer(e,t,n,r){let i=this.createLayer(e,t,n);return i?(i.ctx.scale(this.scale,this.scale),i.ctx.font=r.font,i.ctx.textBaseline=r.textBaseline,i.ctx.textAlign=r.textAlign,i.ctx.direction=r.direction,i.ctx.fillStyle=`#000`,i):null}drawGlyphs(e,t,n,r){let i=t.bounds.left-n.bounds.left,a=t.bounds.top-n.bounds.top+n.baseline,{letterSpacing:o,writingMode:s}=n;if(o<=0||ka(s)){r(e.ctx,t.text,i,a);return}let c=i;for(let n of Zs(t.text))r(e.ctx,n,c,a),c+=e.ctx.measureText(n).width+o}renderShadowSilhouettes(e,t,n,r,i,a,o){let s=a.textShadow;if(!s.length)return null;let l=[];for(let a=s.length-1;a>=0;a--){let u=c(s,a),d=this.createGlyphLayer(t,n,r,i);if(d){d.ctx.shadowColor=z(u.color),d.ctx.shadowOffsetX=u.offsetX.number*this.scale,d.ctx.shadowOffsetY=u.offsetY.number*this.scale,d.ctx.shadowBlur=u.blur.number*this.scale,d.ctx.fillStyle=z(u.color);for(let t of e.container.textNodes)for(let e of t.textBounds)this.drawGlyphs(d,e,o,(e,t,n,r)=>{e.fillText(t,n,r)});l.push(d.canvas)}}return l.length?l:null}},Vu=class e{surfaceRoot;surfaceBudget;canvas;ctx;context;options;backgroundRenderer;borderRenderer;borderImageRenderer;effectsRenderer;textRenderer;textClipRenderer;legacySubtree=!1;constructor(e,t,n,r={pixels:0}){this.surfaceRoot=n,this.surfaceBudget=r,this.context=e,this.options=t,this.canvas=t.canvas?t.canvas:e.resourceDocument.createElement(`canvas`);let i=this.canvas.getContext(`2d`);if(!i)throw t.canvas||Q(this.canvas),n?new Z(`Filter surface canvas is unavailable`):Error(`Failed to get 2D rendering context from canvas`);this.ctx=i,t.canvas||(this.canvas.width=Math.floor(t.width*t.scale),this.canvas.height=Math.floor(t.height*t.scale),this.canvas.style.width=`${t.width}px`,this.canvas.style.height=`${t.height}px`),this.ctx.scale(this.options.scale,this.options.scale),this.ctx.translate(-t.x,-t.y),this.ctx.textBaseline=`bottom`,t.imageSmoothing!==void 0&&(this.ctx.imageSmoothingEnabled=t.imageSmoothing),t.imageSmoothingQuality&&(this.ctx.imageSmoothingQuality=t.imageSmoothingQuality),this.backgroundRenderer=new ou({ctx:this.ctx,context:this.context,canvas:this.canvas,options:{width:t.width,height:t.height,scale:t.scale}}),this.borderRenderer=new fu({ctx:this.ctx},{path:e=>this.path(e),formatPath:e=>this.formatPath(e)}),this.borderImageRenderer=new hu(this.ctx),this.effectsRenderer=new vu({ctx:this.ctx,scale:t.scale},{path:e=>this.path(e)}),this.textRenderer=new nu({ctx:this.ctx,options:{scale:t.scale}}),this.textClipRenderer=new Bu({ctx:this.ctx,context:this.context,scale:t.scale,createFontStyle:e=>this.textRenderer.createFontStyle(e)}),this.context.logger.debug(`Canvas renderer initialized (${t.width}x${t.height}) with scale ${t.scale}`)}async renderStack(e){let t=e.element.container.styles;if(t.isVisible()){let n=yl(t.filter),r=n!==null&&n.functions.length>0,i=t.maskImage.length>0,a=t.webkitBoxReflect,o=t.mixBlendMode!==K.NORMAL;if(e.element!==this.surfaceRoot&&!this.legacySubtree&&(i||a||o||n!==null&&(r||t.opacity<1))&&this.canComposite(e.element)){if(!await this.renderCompositedStack(e,n,i,a,o)){this.legacySubtree=!0;try{await this.renderStackContent(e)}finally{this.legacySubtree=!1}}return}await this.renderStackContent(e)}}canComposite(e){let t=e=>{let t=e.styles;return!t.isTransformed()&&t.zoom===1&&t.clipPath.type===0&&!H(t.display,2048)&&yl(t.filter)!==null},n=e=>t(e)&&e.elements.every(n),r=e.parent;for(;r&&r!==this.surfaceRoot;){if(!t(r.container))return!1;r=r.parent}return n(e.container)}async renderCompositedStack(t,n,r,i,o=!1){let s=this.options.signal;if(s?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);let c=t.element.container,l=ql(Kl(c),new a(this.options.x,this.options.y,this.options.width,this.options.height),n?Ol(n,c.filterReferences):0,this.options.scale);if(!l.width||!l.height)return!0;let u=Ul(this.surfaceBudget,Math.ceil(l.width*this.options.scale),Math.ceil(l.height*this.options.scale));if(!u)return this.context.logger.info(`Filter surface budget exceeded; using the existing renderer`),!1;let d={...this.options,canvas:void 0,backgroundColor:null,x:l.left,y:l.top,width:l.width,height:l.height},f,p;try{f=new e(this.context,d,t.element,this.surfaceBudget),await f.renderStackContent(t),f.effectsRenderer.applyEffects([]),n&&(p=await Fl(f.canvas,n,c.styles.opacity,d.scale,s,{references:c.filterReferences,origin:{x:c.bounds.left-l.left,y:c.bounds.top-l.top}}));let a=p??f.canvas;if(r&&await this.applyMask(a,t.element.container.styles,l),s?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);let u=t.element.effects,m=t.element.getEffects(4,this.surfaceRoot).filter(e=>!u.includes(e)||!qc(e)&&!Wc(e)&&!Kc(e)&&!Uc(e));return this.effectsRenderer.applyEffects(m),o?(this.ctx.save(),this.ctx.globalCompositeOperation=t.element.container.styles.mixBlendMode,this.ctx.drawImage(a,d.x,d.y,a.width/d.scale,a.height/d.scale),this.ctx.restore()):this.ctx.drawImage(a,d.x,d.y,a.width/d.scale,a.height/d.scale),i&&await this.drawReflection(a,t.element.container.bounds,l,i),!0}catch(e){if(!(e instanceof Z))throw e;return this.context.logger.info(`${e.message}; using the existing renderer`),!1}finally{f&&Q(f.canvas),p&&Q(p),this.surfaceBudget.pixels-=u}}async applyMask(e,t,n){let r=e.getContext(`2d`);if(!r)return;let i=this.context.resourceDocument.createElement(`canvas`);i.width=e.width,i.height=e.height;let a=i.getContext(`2d`);if(!a)Q(i);else{a.scale(this.options.scale,this.options.scale),a.translate(-n.left,-n.top);try{await wu(a,t.maskImage,t,{left:n.left,top:n.top,width:n.width,height:n.height},async e=>await this.context.cache.match(e))}catch(e){this.context.logger.error(`Error rendering mask-image: ${e instanceof Error?e.message:e}`),Q(i);return}r.save();try{r.setTransform(1,0,0,1,0,0),r.globalCompositeOperation=`destination-in`,r.drawImage(i,0,0)}finally{r.restore(),Q(i)}}}async drawReflection(e,t,n,r){let i=this.options.scale,a=Math.ceil(t.width*i),o=Math.ceil(t.height*i);if(a<=0||o<=0)return;let s=Ul(this.surfaceBudget,a,o);if(!s)return;let c,l;try{c=this.context.resourceDocument.createElement(`canvas`),c.width=a,c.height=o;let s=c.getContext(`2d`);if(!s)return;let u=Math.round((t.left-n.left)*i),d=Math.round((t.top-n.top)*i),f=r.direction===`left`||r.direction===`right`;s.save();try{f?(s.translate(a,0),s.scale(-1,1)):(s.translate(0,o),s.scale(1,-1)),s.drawImage(e,-u,-d)}finally{s.restore()}if(r.mask){l=this.context.resourceDocument.createElement(`canvas`),l.width=a,l.height=o;let e=l.getContext(`2d`);if(e){e.scale(i,i),await wu(e,[r.mask],{maskPosition:[],maskRepeat:[],maskSize:[]},{left:0,top:0,width:t.width,height:t.height},async e=>await this.context.cache.match(e)),s.save();try{f?(s.translate(a,0),s.scale(-1,1)):(s.translate(0,o),s.scale(1,-1)),s.globalCompositeOperation=`destination-in`,s.drawImage(l,0,0,a,o)}finally{s.restore()}}}let p=r.offset,m=t.left,h=t.top;r.direction===`below`?h=t.top+t.height+p:r.direction===`above`?h=t.top-t.height-p:m=r.direction===`right`?t.left+t.width+p:t.left-t.width-p,this.ctx.save();try{this.ctx.filter=`none`,this.ctx.drawImage(c,m,h,t.width,t.height)}finally{this.ctx.restore()}}finally{c&&Q(c),l&&Q(l),this.surfaceBudget.pixels-=s}}async renderNode(e){if(e.container.debugRender)debugger;e.container.styles.isVisible()&&(await this.renderNodeBackgroundAndBorders(e),await this.renderNodeContent(e))}renderReplacedElement(e,t,n){let r=n.naturalWidth||e.intrinsicWidth,i=n.naturalHeight||e.intrinsicHeight;if(n&&r>0&&i>0){let a=sl(e),o=Pc(t);this.path(o),this.ctx.save(),this.ctx.clip();let{sx:s,sy:c,sw:l,sh:u,dx:d,dy:f,dw:p,dh:m}=Tu(r,i,a,e.styles.objectFit,e.styles.objectPosition);this.ctx.drawImage(n,s,c,l,u,d,f,p,m),this.ctx.restore()}}async renderNodeContent(t){this.effectsRenderer.applyEffects(t.getEffects(4,this.surfaceRoot));let n=t.container,r=t.curves,i=n.styles,a=sl(n);for(let e of n.textNodes)await this.textRenderer.renderTextNode(e,i,a);await Eu(this.ctx,this.context,{scale:this.options.scale,backgroundColor:this.options.backgroundColor,x:this.options.x,y:this.options.y,width:this.options.width,height:this.options.height},(t,n)=>new e(t,n),n,r,i,(e,t,n)=>this.renderReplacedElement(e,t,n)),Du(this.ctx,this.textRenderer,this.path.bind(this),n,i),await Au(this.ctx,this.context,this.textRenderer,t,n,i)}async renderStackContent(e){if(e.element.container.debugRender)debugger;let t=this.options.signal;await this.renderNodeBackgroundAndBorders(e.element);for(let n of e.negativeZIndex){if(t?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);await this.renderStack(n)}if(t?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);await this.renderNodeContent(e.element);for(let t of e.nonInlineLevel)await this.renderNode(t);for(let n of e.nonPositionedFloats){if(t?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);await this.renderStack(n)}for(let n of e.nonPositionedInlineLevel){if(t?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);await this.renderStack(n)}for(let t of e.inlineLevel)await this.renderNode(t);for(let n of e.zeroOrAutoZIndexOrTransformedOrOpacity){if(t?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);await this.renderStack(n)}for(let n of e.positiveZIndex){if(t?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);await this.renderStack(n)}}path(e){iu(this.ctx,e)}formatPath(e){ru(this.ctx,e)}async renderSurfaceBoxShadow(e,t){let n=t.spread.number,r=t.blur.number/2,i=Math.ceil(3*r)+1,o=e.container.bounds.add(-n,-n,2*n,2*n);if(o.width<=0||o.height<=0)return;let s=this.options.scale,c=ql(o.add(-i,-i,2*i,2*i),new a(this.options.x-t.offsetX.number,this.options.y-t.offsetY.number,this.options.width,this.options.height),i,s);if(!c.width||!c.height)return;let l=Math.ceil(c.width*s),u=Math.ceil(c.height*s),d=Ul(this.surfaceBudget,l,u);if(!d)throw new Z(`Box shadow surface budget exceeded`);let f,p;try{f=this.context.resourceDocument.createElement(`canvas`),f.width=l,f.height=u;let i=f.getContext(`2d`);if(!i)throw new Z(`Box shadow surface canvas is unavailable`);i.scale(s,s),i.translate(-c.left,-c.top),iu(i,Oc(Mc(e.curves),-n,-n,2*n,2*n)),i.fillStyle=z(t.color),i.fill(),p=await Fl(f,{functions:[{kind:`blur`,value:r}]},1,s,this.options.signal),this.ctx.save();try{this.ctx.beginPath(),this.ctx.rect(this.options.x,this.options.y,this.options.width,this.options.height),ru(this.ctx,Mc(e.curves)),this.ctx.closePath(),this.ctx.clip(`evenodd`),this.ctx.drawImage(p,c.left+t.offsetX.number,c.top+t.offsetY.number,p.width/s,p.height/s)}finally{this.ctx.restore()}}finally{f&&Q(f),p&&Q(p),this.surfaceBudget.pixels-=d}}async renderNodeBackgroundAndBorders(e){this.effectsRenderer.applyEffects(e.getEffects(2,this.surfaceRoot)),!this.surfaceRoot&&e.container.styles.backdropFilter&&await this.renderBackdropFilter(e);let t=e.container.styles,n=!R(t.backgroundColor)||t.backgroundImage.length,r=Uu(t),i=[{style:t.borderTopStyle,color:t.borderTopColor,width:t.borderTopWidth},{style:t.borderRightStyle,color:t.borderRightColor,width:t.borderRightWidth},{style:t.borderBottomStyle,color:t.borderBottomColor,width:t.borderBottomWidth},{style:t.borderLeftStyle,color:t.borderLeftColor,width:t.borderLeftWidth}],a=ml(t.backgroundClip,0),o=Hu(a,e.curves);if(n||t.boxShadow.length){r&&e.container.textNodes.length>0?await this.textClipRenderer.render(e):(this.ctx.save(),this.path(o),this.ctx.clip(),R(t.backgroundColor)||(this.ctx.fillStyle=z(t.backgroundColor),this.ctx.fill()),await this.backgroundRenderer.renderBackgroundImage(e.container),this.ctx.restore());for(let n of t.boxShadow.slice(0).reverse())this.surfaceRoot&&!n.inset?await this.renderSurfaceBoxShadow(e,n):await zu(this.ctx,e,n,this.options,this.surfaceBudget)}if(t.borderImageSource){let n=t.borderImageSource,r=e.container.bounds,i=[Math.max(0,t.borderTopWidth),Math.max(0,t.borderRightWidth),Math.max(0,t.borderBottomWidth),Math.max(0,t.borderLeftWidth)],a=null;if(n.type===0){let e=n.url;try{a=await this.context.cache.match(e)??null}catch{this.context.logger.error(`Error loading border-image ${e}`)}}else a=this.rasterizeGradientSource(n,r);if(a){let e=mu(t.borderImageOutset,i),n=r.add(-e.left,-e.top,e.left+e.right,e.top+e.bottom),o=pu(t.borderImageWidth,i,n);this.borderImageRenderer.renderBorderImage(r,a,t.borderImageSlice,t.borderImageRepeat,o[0],o[1],o[2],o[3],e)}return}let s=0;for(let t of i){if(t.style!==0&&!R(t.color)&&t.width>0){let n=async()=>{t.style===2?await this.borderRenderer.renderDashedDottedBorder(t.color,t.width,s,e.curves,2):t.style===3?await this.borderRenderer.renderDashedDottedBorder(t.color,t.width,s,e.curves,3):t.style===4?await this.borderRenderer.renderDoubleBorder(t.color,t.width,s,e.curves):await this.borderRenderer.renderSolidBorder(t.color,s,e.curves)},r=e.container.legendBounds;if(s===0&&r){let t=e.container.bounds,i=r.left-t.left,a=r.left+r.width-t.left;i>0&&(this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(t.left,t.top,i,t.height),this.ctx.clip(),await n(),this.ctx.restore());let o=t.left+a,s=t.width-a;s>0&&(this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(o,t.top,s,t.height),this.ctx.clip(),await n(),this.ctx.restore())}else await n()}s++}this.renderOutline(e)}renderOutline(e){let t=e.container.styles;if(t.outlineStyle===0||t.outlineStyle===1)return;let n=Math.max(0,t.outlineWidth);if(n<=0)return;let r=t.outlineColor??t.color;if(R(r))return;let i=Math.max(0,t.outlineOffset)+n/2,a=Oc(Mc(e.curves),-i,-i,2*i,2*i);this.ctx.save();try{this.ctx.strokeStyle=z(r),this.ctx.lineWidth=n,t.outlineStyle===3?this.ctx.setLineDash([n*3,n*3]):t.outlineStyle===4&&this.ctx.setLineDash([n,n*2]),this.path(a),this.ctx.stroke()}finally{this.ctx.restore()}}rasterizeGradientSource(e,t){let n=Math.max(1,Math.ceil(t.width)),r=Math.max(1,Math.ceil(t.height)),i=(this.ctx.canvas.ownerDocument??document).createElement(`canvas`);i.width=n,i.height=r;let a=i.getContext(`2d`);if(!a)return null;if(e.type===1||e.type===3){let t=e,[o,s,l,u,d]=Pr(t.angle,n,r),f=W(t.stops,o||n),p=e.type===3,m=p?rl(f):null,h=a.createLinearGradient(s,l,u,d);if(m)m.forEach(e=>{h.addColorStop(Math.min(1,Math.max(0,e.stop)),e.color)});else if(p){let e=z(c(f,f.length-1).color);h.addColorStop(0,e),h.addColorStop(1,e)}else il(f).forEach(e=>{h.addColorStop(e.stop,e.color)});return a.fillStyle=h,a.fillRect(0,0,n,r),i}if(e.type===2||e.type===4){let t=e,o=t.position.length===0?[P]:t.position,s=I(c(o,0),n),l=I(c(o,o.length-1),r),[u,d]=Ir(t,s,l,n,r);if(u<=0||d<=0)return null;let f=this.ctx.canvas.ownerDocument??document,p=al(f,u,d,t.stops,e.type===4);return p?(a.fillStyle=p.lastColor,a.fillRect(0,0,n,r),a.drawImage(p.canvas,s-u,l-d,u*2,d*2),Q(p.canvas),i):null}if(e.type===5||e.type===6){let t=e,o=I(c(t.position,0),n),s=I(c(t.position,1),r),l=a.createConicGradient(t.angle-Math.PI/2,o,s),u;if(e.type===6){let e=W(t.stops,1),n=c(e,0),r=c(e,e.length-1),i=Math.max(r.stop-n.stop,.01);u=[];let a=Math.ceil(1/i);for(let t=0;t<a;t++)for(let r of e){let e=t*i+(r.stop-n.stop);if(e>1)break;u.push({stop:e,color:z(r.color)})}let o=c(u,u.length-1);o&&o.stop<1&&u.push({stop:1,color:o.color})}else u=W(t.stops,Math.max(n,r)).map(e=>({stop:e.stop,color:z(e.color)}));return u.forEach(e=>{l.addColorStop(Math.min(1,Math.max(0,e.stop)),e.color)}),a.fillStyle=l,a.fillRect(0,0,n,r),i}return this.context.logger.warn(`Unsupported border-image source; only URL and gradient images are supported`),null}async renderBackdropFilter(e){let t=yl(e.container.styles.backdropFilter);if(!t||t.functions.length===0)return;let n=e.container.bounds;if(n.width<=0||n.height<=0)return;let r=this.options.scale,i=Math.ceil(n.width*r),a=Math.ceil(n.height*r);if(i<=0||a<=0)return;let o=Ul(this.surfaceBudget,i,a);if(!o)return;let s,c;try{s=this.context.resourceDocument.createElement(`canvas`),s.width=i,s.height=a;let e=s.getContext(`2d`);if(!e)return;let o=Math.round((n.left-this.options.x)*r),l=Math.round((n.top-this.options.y)*r);e.drawImage(this.canvas,o,l,i,a,0,0,i,a);try{c=await Fl(s,t,1,r,this.options.signal)}catch(e){if(e instanceof Z){this.context.logger.info(`${e.message}; rendering without the backdrop effect`);return}throw e}if(this.options.signal?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);this.ctx.save();try{this.ctx.filter=`none`,this.ctx.drawImage(c,n.left,n.top,n.width,n.height)}finally{this.ctx.restore()}}finally{s&&Q(s),c&&Q(c),this.surfaceBudget.pixels-=o}}async render(e){try{this.options.backgroundColor&&(this.ctx.fillStyle=z(this.options.backgroundColor),this.ctx.fillRect(this.options.x,this.options.y,this.options.width,this.options.height));let t=tl(e);return await this.renderStack(t),this.effectsRenderer.applyEffects([]),this.canvas}catch(e){throw this.options.canvas||Q(this.canvas),e}}};let Hu=(e,t)=>{switch(e){case 0:return Mc(t);case 2:return Nc(t);default:return Pc(t)}},Uu=e=>e.backgroundClip.some(e=>e===3);var Wu=class{canvas;ctx;options;context;constructor(e,t){this.context=e,this.options=t,this.canvas=t.canvas?t.canvas:e.resourceDocument.createElement(`canvas`);let n=this.canvas.getContext(`2d`);if(!n)throw Error(`Failed to get 2D rendering context from canvas`);this.ctx=n,this.canvas.width=Math.floor(t.width*t.scale),this.canvas.height=Math.floor(t.height*t.scale),this.canvas.style.width=`${t.width}px`,this.canvas.style.height=`${t.height}px`,this.ctx.scale(this.options.scale,this.options.scale),this.ctx.translate(-t.x,-t.y),this.context.logger.debug(`EXPERIMENTAL ForeignObject renderer initialized (${t.width}x${t.height} at ${t.x},${t.y}) with scale ${t.scale}`)}async render(e){if(this.options.signal?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);let t=Ku(e),n=Hs(this.options.width,this.options.height,0,0,e),r=Us(n);t();try{let e=await r;if(this.options.signal?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);return this.options.backgroundColor&&(this.ctx.fillStyle=z(this.options.backgroundColor),this.ctx.fillRect(this.options.x,this.options.y,this.options.width,this.options.height)),this.ctx.drawImage(e,this.options.x,this.options.y,this.options.width,this.options.height),this.canvas}catch(e){throw this.options.canvas||Q(this.canvas),e}}};let Gu=[`marginTop`,`marginRight`,`marginBottom`,`marginLeft`,`top`,`right`,`bottom`,`left`],Ku=e=>{let t=e.style,n=Gu.map(e=>[e,t[e]]);for(let e of Gu)t[e]=e.startsWith(`margin`)?`0px`:`auto`;return()=>{for(let[e,r]of n)t[e]=r}};var qu=class{id;enabled;start;constructor({id:e,enabled:t}){this.id=e,this.enabled=t,this.start=Date.now()}debug(...e){this.enabled&&(typeof window<`u`&&window.console&&typeof console.debug==`function`?console.debug(this.id,`${this.getTime()}ms`,...e):this.info(...e))}getTime(){return Date.now()-this.start}info(...e){this.enabled&&typeof window<`u`&&window.console&&typeof console.info==`function`&&console.info(this.id,`${this.getTime()}ms`,...e)}warn(...e){this.enabled&&(typeof window<`u`&&window.console&&typeof console.warn==`function`?console.warn(this.id,`${this.getTime()}ms`,...e):this.info(...e))}error(...e){this.enabled&&(typeof window<`u`&&window.console&&typeof console.error==`function`?console.error(this.id,`${this.getTime()}ms`,...e):this.info(...e))}},Ju=class{context;_options;_cache=/* @__PURE__ */ new Map;maxSize;_pendingOperations=/* @__PURE__ */ new Map;_deferMode=!1;_collectedUrls=/* @__PURE__ */ new Set;_evictionSuspendCount=0;get _evictionEnabled(){return this._evictionSuspendCount===0}constructor(e,t){if(this.context=e,this._options=t,this.maxSize=t.maxCacheSize??100,this.maxSize<1)throw Error(`Cache maxSize must be at least 1`);this.maxSize>1e4&&this.context.logger.warn(`Cache maxSize ${this.maxSize} is very large and may cause memory issues. Consider using a smaller value (recommended: 100-1000).`)}startDefer(){this._deferMode=!0,this._evictionSuspendCount++}async preloadAll(e=10,t,n){this._deferMode=!1;let r=Array.from(this._collectedUrls);this._collectedUrls.clear();try{if(r.length===0)return;let i=Math.max(1,Math.min(e,100));this.context.logger.debug(`Preloading ${r.length} image(s) with concurrency ${i}`);let a=0,o=n?new Promise((e,t)=>{let r=()=>t(new DOMException(`The operation was aborted.`,`AbortError`));n.aborted?r():n.addEventListener(`abort`,r,{once:!0})}):null;o?.catch(()=>void 0),t?.(0,r.length);for(let e=0;e<r.length;e+=i){q(n);let s=r.slice(e,e+i);s.map(e=>this._addImageWithPending(e));let c=Promise.allSettled(s.map(e=>this._cache.get(e)?.value??Promise.resolve()));await(o?Promise.race([c,o]):c),a+=s.length,t?.(a,r.length)}}finally{this._evictionSuspendCount=Math.max(0,this._evictionSuspendCount-1)}}addImage(e){if(this._deferMode)return!this.has(e)&&(td(e)||Qu(e))&&this._collectedUrls.add(e),Promise.resolve();let t=this._pendingOperations.get(e);if(t)return t;if(this.has(e)){let t=this._cache.get(e);return this._cache.delete(e),this._cache.set(e,t),Promise.resolve()}return td(e)||Qu(e)?this._addImageWithPending(e):Promise.resolve()}_addImageWithPending(e){let t=this._pendingOperations.get(e);if(t)return t;let n=this._addImageInternal(e);return this._pendingOperations.set(e,n),n.finally(()=>{this._pendingOperations.delete(e)}),n}async _addImageInternal(e){let t=this._options.imageTimeout??15e3,n=this.withTimeout(this.loadImage(e),t,`Timed out (${t}ms) loading image`);n.catch(t=>{let n=t instanceof Error?t.message:String(t),r=`Failed to load image ${e.substring(0,256)}: ${n}`;this.context.logger.error(r),this.context.onError?.(Error(r))}),this.set(e,n)}withTimeout(e,t,n){if(t<=0)return e;let r,i=new Promise((e,i)=>{r=setTimeout(()=>i(Error(n)),t)});return Promise.race([e,i]).finally(()=>{r!==void 0&&clearTimeout(r)})}match(e){let t=this._cache.get(e);if(t)return this._cache.delete(e),this._cache.set(e,t),t.value}set(e,t){if(this._cache.has(e))this._cache.delete(e);else if(this._evictionEnabled&&this._cache.size>=this.maxSize){let e=this._cache.keys().next().value;e!==void 0&&(this._cache.delete(e),this.context.logger.debug(`Cache: Evicted LRU entry: ${e}`))}this._cache.set(e,{value:t})}size(){return this._cache.size}getMaxSize(){return this.maxSize}clear(){this._cache.clear()}async loadImage(e){let t=this.context.originChecker,n=e=>t.isSameOrigin(e),r=typeof this._options.customIsSameOrigin==`function`?await this._options.customIsSameOrigin(e,n):n(e),i=!r&&this._options.allowTaint===!1&&!$u(e)&&!td(e)&&typeof this._options.proxy!=`string`,a=!$u(e)&&(this._options.useCORS===!0||i)&&Ws.SUPPORT_CORS_IMAGES&&!r,o=!$u(e)&&!r&&!td(e)&&typeof this._options.proxy==`string`&&!a;if(!r&&this._options.allowTaint===!1&&!$u(e)&&!td(e)&&!o&&!a)return;let s=e;o&&(s=await this.proxy(s)),this.context.logger.debug(`Added image ${e.substring(0,256)}`);let c=this.context.config.window.Image??Image;return await new Promise((e,t)=>{let n=new c;n.onload=()=>e(n),n.onerror=t,(ed(s)||a)&&(n.crossOrigin=`anonymous`),n.src=s,n.complete===!0&&(typeof n.decode==`function`?n.decode().then(()=>e(n),()=>t(/* @__PURE__ */ Error(`Failed to decode image ${s.substring(0,256)}`))):setTimeout(()=>e(n),500))})}has(e){return this._cache.has(e)}keys(){return Promise.resolve(Array.from(this._cache.keys()))}proxy(e){let t=this._options.proxy;if(!t)throw Error(`No proxy defined`);let n=e.substring(0,256);return new Promise((r,i)=>{let a=new XMLHttpRequest;a.onload=()=>{if(a.status===200){let e=new FileReader;e.addEventListener(`load`,()=>r(e.result),!1),e.addEventListener(`error`,e=>i(e),!1),e.readAsDataURL(a.response)}else i(`Failed to proxy resource ${n} with status code ${a.status}`)},a.onerror=i;let o=t.indexOf(`?`)>-1?`&`:`?`;if(a.open(`GET`,`${t}${o}url=${encodeURIComponent(e)}&responseType=blob`),a.responseType=`blob`,this._options.imageTimeout){let e=this._options.imageTimeout;a.timeout=e,a.ontimeout=()=>i(`Timed out (${e}ms) proxying ${n}`)}a.send()})}};let Yu=/^data:image\/svg\+xml/i,Xu=/^data:image\/.*;base64,/i,Zu=/^data:image\/.*/i,Qu=e=>Ws.SUPPORT_SVG_DRAWING||!nd(e),$u=e=>Zu.test(e),ed=e=>Xu.test(e),td=e=>e.substring(0,4)===`blob`,nd=e=>e.slice(-3).toLowerCase()===`svg`||Yu.test(e);var rd=class{baseUri;origin;constructor(e){if(!e||!e.document)throw Error(`Valid window object required for OriginChecker`);if(!e.location||!e.location.href)throw Error(`Window object must have valid location`);this.baseUri=e.location.href,this.origin=this.getOrigin(e.location.href)}getOrigin(e){try{return new URL(e,this.baseUri).origin}catch{return``}}isSameOrigin(e){return this.getOrigin(e)===this.origin}getContextOrigin(){return this.origin}},id=class e{static instanceCount=1;instanceName=`#${e.instanceCount++}`;logger;cache;originChecker;config;onError;_windowBounds;constructor(e,t,n){this.config=n,this.logger=new qu({id:this.instanceName,enabled:e.logging}),this.originChecker=new rd(n.window),this.cache=e.cache??n.cache??new Ju(this,e),this.onError=e.onError,this._windowBounds=t}get windowBounds(){return this._windowBounds}get resourceDocument(){return this.config.window.document||(typeof document<`u`?document:void 0)}adjustWindowBounds(e,t){this._windowBounds=this._windowBounds.add(e,t,0,0)}};let ad=e=>{[`scale`,`width`,`height`,`imageTimeout`,`x`,`y`,`windowWidth`,`windowHeight`,`scrollX`,`scrollY`].forEach(t=>{let n=e[t];if(n!=null&&typeof n!=`number`){let r=Number(n);Number.isNaN(r)||(e[t]=r)}})},od=e=>({allowTaint:e.allowTaint??!1,imageTimeout:e.imageTimeout??15e3,proxy:e.proxy,useCORS:e.useCORS??!1,customIsSameOrigin:e.customIsSameOrigin,maxCacheSize:e.maxCacheSize}),sd=(e,t,n)=>({logging:e.logging??!0,cache:e.cache??t.cache,...n}),cd=(e,t)=>{let n=t;return{windowWidth:e.windowWidth??n.innerWidth??800,windowHeight:e.windowHeight??n.innerHeight??600,scrollX:e.scrollX??n.pageXOffset??0,scrollY:e.scrollY??n.pageYOffset??0}},ld=(e,t,n)=>({allowTaint:e.allowTaint??!1,onclone:e.onclone,ignoreElements:e.ignoreElements,iframeContainer:e.iframeContainer,inlineImages:n,copyStyles:n,cspNonce:e.cspNonce??t.cspNonce,signal:e.signal}),ud=(e,t,n,r,i,a,o)=>({canvas:e.canvas,backgroundColor:t,signal:e.signal,scale:e.scale??o??1,x:(e.x??0)+n,y:(e.y??0)+r,width:e.width??Math.ceil(i),height:e.height??Math.ceil(a),imageSmoothing:e.imageSmoothing,imageSmoothingQuality:e.imageSmoothingQuality}),dd=(e,t,n)=>{let r=t.ownerDocument,i=r.documentElement?Nn(e,getComputedStyle(r.documentElement).backgroundColor):0,a=r.body?Nn(e,getComputedStyle(r.body).backgroundColor):0,o=typeof n==`string`?Nn(e,n):n===null?0:4294967295;return t===r.documentElement?R(i)?R(a)?o:a:i:o},fd=(e,t,n,r)=>{if(e)try{e(n,r)}catch(e){t.logger.error(`onProgress callback failed: ${e instanceof Error?e.message:String(e)}`)}},pd=async(e,t,n)=>{if(ad(t),!t.skipValidation){let n=t.validator||r(),i=n.validateElement(e);if(!i.valid)throw Error(i.error);let a=n.validateOptions(t);if(!a.valid)throw Error(`Invalid options: ${a.error}`)}if(!e||typeof e!=`object`)throw Error(`Invalid element provided as first argument`);let c=e.ownerDocument;if(!c)throw Error(`Element is not attached to a Document`);let l=c.defaultView;if(!l)throw Error(`Document is not attached to a Window`);let u=od(t),d=sd(t,n,u),f=cd(t,l),p=new a(f.scrollX,f.scrollY,f.windowWidth,f.windowHeight),m=new id(d,p,n),h=t.enablePerformanceMonitoring??t.logging??!1,g=new i(m,h);g.start(`total`,{width:f.windowWidth,height:f.windowHeight});let _=t.signal;q(_);let v=t.foreignObjectRendering??!1,y=ld(t,n,v);m.logger.debug(`Starting document clone with size ${p.width}x${p.height} scrolled to ${-p.left},${-p.top}`),fd(t.onProgress,m,`clone`,10),g.start(`clone`);let b=new Ts(m,e,y),x=b.clonedReferenceElement;if(!x)throw Error(`Unable to find element in cloned iframe`);let S,C,w;try{S=await b.toIFrame(c,p),g.end(`clone`),fd(t.onProgress,m,`clone`,30),q(_);let{width:e,height:n,left:r,top:i}=Hn(x)||Bn(x)?s(x.ownerDocument):o(m,x),a=dd(m,x,t.backgroundColor),u=ud(t,a,r,i,e,n,l.devicePixelRatio??1);v?(m.logger.debug(`Document cloned, using foreign object rendering`),g.start(`render-foreignobject`),C=await new Wu(m,u).render(x),g.end(`render-foreignobject`)):(m.logger.debug(`Document cloned, element located at ${r},${i} with size ${e}x${n} using computed rendering`),m.logger.debug(`Starting DOM parsing`),g.start(`parse`),q(_),m.cache.startDefer(),w=wc(m,x,{normalizeDom:t.normalizeDom}),g.end(`parse`),fd(t.onProgress,m,`parse`,50),g.start(`preload`),await m.cache.preloadAll(10,(e,n)=>{fd(t.onProgress,m,`preload`,50+Math.round(e/n*10))},_),g.end(`preload`),fd(t.onProgress,m,`layout`,60),a===w.styles.backgroundColor&&(w.styles.backgroundColor=0),m.logger.debug(`Starting renderer for element at ${u.x},${u.y} with size ${u.width}x${u.height}`),g.start(`render`),q(_),C=await new Vu(m,u).render(w),g.end(`render`)),fd(t.onProgress,m,`render`,90)}finally{g.start(`cleanup`);try{w&&w.restoreTree()}finally{S&&(t.removeContainer??!0)&&Ts.destroy(S),g.end(`cleanup`)}}return g.end(`total`),m.logger.debug(`Finished rendering`),h&&g.logSummary(),fd(t.onProgress,m,`render`,100),C},md=(e,n={},r)=>{let i=r||t.fromElement(e,{cspNonce:n.cspNonce,cache:n.cache});return pd(e,n,i)};e.Html2CanvasConfig=t,e.PerformanceMonitor=i,e.Validator=n,e.createDefaultValidator=r,e.default=md,e.html2canvas=md}),typeof window<`u`&&window.html2canvas&&window.html2canvas.default&&(window.html2canvasExports=window.html2canvas,window.html2canvas=window.html2canvas.default);
@@ -42,6 +42,13 @@ export declare class DocumentCloner {
42
42
  * the other stylesheet-cloning paths.
43
43
  */
44
44
  private appendDocumentAdoptedStyles;
45
+ /**
46
+ * Add the rules that hide the source ::before / ::after (the clone draws
47
+ * them as surrogate elements) to the clone's <head>. Inside <body> the
48
+ * <style> would be one of its children, and `body > :first-child`,
49
+ * `:nth-child()` and sibling selectors would match the wrong elements.
50
+ */
51
+ private appendPseudoHideStyles;
45
52
  toIFrame(ownerDocument: Document, windowSize: Bounds): Promise<HTMLIFrameElement>;
46
53
  createElementClone<T extends HTMLElement | SVGElement>(node: T): HTMLElement | SVGElement;
47
54
  createCustomElementClone(originalNode: HTMLElement, clonedNode: HTMLElement): HTMLElement;