bug-widget-library 0.1.0 → 0.2.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,2 +1,8 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("react");c=s(c,1);let l=require("html2canvas");l=s(l,1);let u=require("lucide-react"),d=require("react/jsx-runtime"),f=require("react-konva");function p(e){try{return new URL(e).hostname}catch{return`project`}}var m=({projectUrl:e,isOpen:t,onClose:n,uiSettings:r={},screenshots:i,onTriggerScreenshot:a,onEditScreenshot:o,onDeleteScreenshot:s,onSubmitReport:l})=>{let{position:f=`bottom-right`,primaryColor:m=`#2563eb`,title:h=`Report a Bug`,subtitle:g=`Found an issue? Let us know with details and screenshots.`,placeholderTitle:_=`e.g. Broken checkout button on cart page`,placeholderDescription:v=`Describe what happened, steps to reproduce, and expected result...`}=r,y=(e=>e===`bottom-left`||e===`top-left`||e===`left`)(f),[b,x]=(0,c.useState)(``),[S,C]=(0,c.useState)(``),[w,T]=(0,c.useState)(!1),[E,D]=(0,c.useState)(!1),[O,k]=(0,c.useState)(null),[A,j]=(0,c.useState)({}),[M,N]=(0,c.useState)(null),P=p(e),F=()=>{let e={};return b.trim()||(e.title=`Title / bug name is required.`),S.trim()||(e.description=`Description is required.`),j(e),Object.keys(e).length===0};return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`div`,{"data-bugdrop-widget":`true`,onClick:n,className:`fixed inset-0 z-[99990] bg-slate-900/40 backdrop-blur-sm transition-opacity duration-300 ${t?`opacity-100 pointer-events-auto`:`opacity-0 pointer-events-none`}`}),(0,d.jsxs)(`aside`,{"data-bugdrop-widget":`true`,className:`fixed top-0 z-[99995] flex h-full w-full max-w-md flex-col bg-white shadow-2xl transition-all duration-300 ease-out sm:max-w-lg ${y?`left-0 border-r border-slate-200`:`right-0 border-l border-slate-200`} ${y?t?`translate-x-0 opacity-100 pointer-events-auto`:`-translate-x-full opacity-0 pointer-events-none`:t?`translate-x-0 opacity-100 pointer-events-auto`:`translate-x-full opacity-0 pointer-events-none`}`,role:`dialog`,"aria-modal":`true`,"aria-label":h,children:[(0,d.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b border-slate-100 px-6 py-5`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,d.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl text-white shadow-md font-bold`,style:{backgroundColor:m},children:(0,d.jsx)(u.Sparkles,{className:`h-5 w-5`})}),(0,d.jsxs)(`div`,{children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,d.jsx)(`h2`,{className:`text-lg font-bold text-slate-800`,children:h}),(0,d.jsx)(`span`,{className:`rounded-md bg-slate-100 px-2 py-0.5 text-[11px] font-semibold tracking-wider text-slate-500`,title:e,children:P})]}),(0,d.jsx)(`p`,{className:`mt-0.5 text-xs text-slate-500`,children:g})]})]}),(0,d.jsx)(`button`,{type:`button`,onClick:n,className:`flex h-8 w-8 items-center justify-center rounded-lg text-slate-400 transition hover:bg-slate-100 hover:text-slate-600`,children:(0,d.jsx)(u.X,{className:`h-5 w-5`})})]}),(0,d.jsx)(`div`,{className:`flex-1 overflow-y-auto px-6 py-5`,children:E?(0,d.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center text-center py-10 animate-fadeIn`,children:[(0,d.jsx)(`div`,{className:`flex h-16 w-16 items-center justify-center rounded-full text-white shadow-lg mb-4`,style:{backgroundColor:m},children:(0,d.jsx)(u.CheckCircle2,{className:`h-9 w-9`})}),(0,d.jsx)(`h3`,{className:`text-xl font-bold text-slate-800`,children:`Bug Report Submitted!`}),(0,d.jsxs)(`p`,{className:`mt-2 text-sm text-slate-500 max-w-xs`,children:[`Thank you! Your bug report with `,i.length,` screenshot`,i.length===1?``:`s`,` has been captured and logged.`]}),(0,d.jsxs)(`div`,{className:`mt-8 flex flex-col sm:flex-row gap-3 w-full`,children:[(0,d.jsx)(`button`,{type:`button`,onClick:()=>{x(``),C(``),j({}),k(null),D(!1)},className:`flex-1 rounded-xl border border-slate-200 bg-white py-2.5 text-sm font-semibold text-slate-700 shadow-sm transition hover:bg-slate-50`,children:`Report Another Bug`}),(0,d.jsx)(`button`,{type:`button`,onClick:n,style:{backgroundColor:m},className:`flex-1 rounded-xl py-2.5 text-sm font-semibold text-white shadow-md transition hover:brightness-110`,children:`Close`})]})]}):(0,d.jsxs)(`form`,{onSubmit:async t=>{if(t.preventDefault(),F()){T(!0),k(null);try{await l({projectUrl:e,title:b.trim(),description:S.trim(),screenshots:i,timestamp:new Date().toISOString(),meta:{url:window.location.href,userAgent:navigator.userAgent,timestamp:new Date().toISOString(),screenSize:{width:window.innerWidth,height:window.innerHeight}}}),D(!0)}catch(e){console.error(`Failed to submit bug report:`,e),k(e instanceof Error?e.message:`Failed to submit bug report. Please try again.`)}finally{T(!1)}}},className:`space-y-5`,children:[(0,d.jsxs)(`div`,{children:[(0,d.jsxs)(`label`,{className:`block text-xs font-bold tracking-wide uppercase text-slate-700`,children:[`Bug Title / Name `,(0,d.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,d.jsx)(`input`,{type:`text`,value:b,onChange:e=>{x(e.target.value),A.title&&j(e=>({...e,title:void 0}))},placeholder:_,className:`mt-1.5 w-full rounded-xl border px-3.5 py-2.5 text-sm transition focus:outline-none focus:ring-2 ${A.title?`border-red-300 bg-red-50/50 text-red-900 focus:ring-red-400`:`border-slate-200 bg-white text-slate-800 focus:border-transparent focus:ring-blue-500`}`}),A.title&&(0,d.jsxs)(`p`,{className:`mt-1.5 flex items-center gap-1 text-xs text-red-600`,children:[(0,d.jsx)(u.AlertCircle,{className:`h-3.5 w-3.5`}),(0,d.jsx)(`span`,{children:A.title})]})]}),(0,d.jsxs)(`div`,{children:[(0,d.jsxs)(`label`,{className:`block text-xs font-bold tracking-wide uppercase text-slate-700`,children:[`Description `,(0,d.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,d.jsx)(`textarea`,{rows:4,value:S,onChange:e=>{C(e.target.value),A.description&&j(e=>({...e,description:void 0}))},placeholder:v,className:`mt-1.5 w-full rounded-xl border px-3.5 py-2.5 text-sm transition focus:outline-none focus:ring-2 ${A.description?`border-red-300 bg-red-50/50 text-red-900 focus:ring-red-400`:`border-slate-200 bg-white text-slate-800 focus:border-transparent focus:ring-blue-500`}`}),A.description&&(0,d.jsxs)(`p`,{className:`mt-1.5 flex items-center gap-1 text-xs text-red-600`,children:[(0,d.jsx)(u.AlertCircle,{className:`h-3.5 w-3.5`}),(0,d.jsx)(`span`,{children:A.description})]})]}),(0,d.jsxs)(`div`,{children:[(0,d.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,d.jsxs)(`label`,{className:`block text-xs font-bold tracking-wide uppercase text-slate-700`,children:[`Screenshots `,(0,d.jsx)(`span`,{className:`text-slate-400 font-normal lowercase`,children:`(optional)`})]}),(0,d.jsxs)(`span`,{className:`rounded-full bg-slate-100 px-2 py-0.5 text-xs font-semibold text-slate-600`,children:[i.length,` / 3`]})]}),(0,d.jsx)(`p`,{className:`mt-1 text-xs text-slate-500`,children:`Capture your screen and annotate with pencil, shapes, or arrows.`}),i.length>0&&(0,d.jsx)(`div`,{className:`mt-3 grid grid-cols-3 gap-2.5`,children:i.map((e,t)=>(0,d.jsxs)(`div`,{className:`group relative aspect-video overflow-hidden rounded-lg border border-slate-200 bg-slate-100 shadow-sm`,children:[(0,d.jsx)(`img`,{src:e.dataUrl,alt:`Screenshot ${t+1}`,className:`h-full w-full object-cover transition duration-200 group-hover:scale-105`}),(0,d.jsxs)(`span`,{className:`absolute top-1 left-1 rounded bg-black/60 px-1 py-0.2 text-[10px] font-semibold text-white`,children:[`#`,t+1]}),(0,d.jsxs)(`div`,{className:`absolute inset-0 flex items-center justify-center gap-1.5 bg-black/50 opacity-0 backdrop-blur-[1px] transition-opacity duration-200 group-hover:opacity-100`,children:[(0,d.jsx)(`button`,{type:`button`,onClick:()=>N(e.dataUrl),title:`Preview screenshot`,className:`flex h-7 w-7 items-center justify-center rounded-md bg-white/90 text-slate-700 shadow transition hover:bg-white hover:text-blue-600`,children:(0,d.jsx)(u.Eye,{className:`h-3.5 w-3.5`})}),(0,d.jsx)(`button`,{type:`button`,onClick:()=>o(e),title:`Re-edit / annotate`,className:`flex h-7 w-7 items-center justify-center rounded-md bg-white/90 text-slate-700 shadow transition hover:bg-white hover:text-blue-600`,children:(0,d.jsx)(u.Edit3,{className:`h-3.5 w-3.5`})}),(0,d.jsx)(`button`,{type:`button`,onClick:()=>s(e.id),title:`Delete screenshot`,className:`flex h-7 w-7 items-center justify-center rounded-md bg-red-600 text-white shadow transition hover:bg-red-700`,children:(0,d.jsx)(u.Trash2,{className:`h-3.5 w-3.5`})})]})]},e.id))}),(0,d.jsx)(`div`,{className:`mt-3`,children:i.length<3?(0,d.jsxs)(`button`,{type:`button`,onClick:a,className:`flex w-full items-center justify-center gap-2 rounded-xl border-2 border-dashed border-slate-300 bg-slate-50/70 py-3 text-xs font-semibold text-slate-600 transition hover:border-blue-400 hover:bg-blue-50/50 hover:text-blue-600`,children:[(0,d.jsx)(u.Camera,{className:`h-4 w-4 text-slate-500`}),(0,d.jsx)(`span`,{children:i.length===0?`Capture Screen & Annotate`:`Capture Another Screenshot (${3-i.length} left)`})]}):(0,d.jsx)(`div`,{className:`rounded-lg bg-amber-50 p-2.5 text-center text-xs text-amber-700 border border-amber-200`,children:`Maximum 3 screenshots attached. Delete one to take a new one.`})})]}),O&&(0,d.jsxs)(`div`,{className:`rounded-xl border border-red-200 bg-red-50 px-3.5 py-2.5 text-xs text-red-700 flex items-start gap-2`,children:[(0,d.jsx)(u.AlertCircle,{className:`h-4 w-4 shrink-0 mt-0.5`}),(0,d.jsx)(`span`,{children:O})]}),(0,d.jsxs)(`div`,{className:`pt-4 border-t border-slate-100 flex items-center justify-end gap-3`,children:[(0,d.jsx)(`button`,{type:`button`,onClick:n,className:`rounded-xl border border-slate-200 bg-white px-4 py-2.5 text-sm font-semibold text-slate-600 transition hover:bg-slate-50`,children:`Cancel`}),(0,d.jsx)(`button`,{type:`submit`,disabled:w,style:{backgroundColor:m},className:`flex items-center gap-2 rounded-xl px-5 py-2.5 text-sm font-semibold text-white shadow-md transition hover:brightness-110 active:scale-95 disabled:opacity-60`,children:w?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(u.Loader2,{className:`h-4 w-4 animate-spin`}),(0,d.jsx)(`span`,{children:`Submitting...`})]}):(0,d.jsx)(`span`,{children:`Submit Bug Report`})})]})]})})]}),M&&(0,d.jsx)(`div`,{"data-bugdrop-widget":`true`,onClick:()=>N(null),className:`fixed inset-0 z-[100001] flex items-center justify-center bg-black/80 p-4 backdrop-blur-sm animate-fadeIn`,children:(0,d.jsxs)(`div`,{className:`relative max-h-[90vh] max-w-[90vw] overflow-hidden rounded-xl bg-slate-900 shadow-2xl`,onClick:e=>e.stopPropagation(),children:[(0,d.jsx)(`img`,{src:M,alt:`Screenshot Preview`,className:`max-h-[85vh] w-auto rounded-xl object-contain`}),(0,d.jsx)(`button`,{type:`button`,onClick:()=>N(null),className:`absolute top-3 right-3 flex h-8 w-8 items-center justify-center rounded-full bg-black/60 text-white shadow hover:bg-black/90`,children:(0,d.jsx)(u.X,{className:`h-4 w-4`})})]})})]})},h=[`#ef4444`,`#f97316`,`#eab308`,`#10b981`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#000000`,`#ffffff`],g=[{label:`S`,value:3},{label:`M`,value:6},{label:`L`,value:10},{label:`XL`,value:16}],_=({imageSrc:e,onSave:t,onCancel:n,primaryColor:r=`#2563eb`})=>{let i=(0,c.useRef)(null),a=(0,c.useRef)(null),o=(0,c.useRef)(null),[s,l]=(0,c.useState)(null),[p,m]=(0,c.useState)(1),[_,v]=(0,c.useState)({width:800,height:600}),[y,b]=(0,c.useState)(`pencil`),[x,S]=(0,c.useState)(`#ef4444`),[C,w]=(0,c.useState)(6),[T,E]=(0,c.useState)(null),[D,O]=(0,c.useState)([]),[k,A]=(0,c.useState)(null),[j,M]=(0,c.useState)(!1),[N,P]=(0,c.useState)(null),[F,I]=(0,c.useState)([[]]),[L,R]=(0,c.useState)(0);(0,c.useEffect)(()=>{let t=new window.Image;t.crossOrigin=`anonymous`,t.src=e,t.onload=()=>{l(t)}},[e]);let z=(0,c.useCallback)(()=>{if(!i.current||!s)return;let e=Math.max(300,i.current.clientWidth-48),t=Math.max(300,i.current.clientHeight-120),n=Math.min(e/s.naturalWidth,t/s.naturalHeight,1);m(n),v({width:Math.round(s.naturalWidth*n),height:Math.round(s.naturalHeight*n)})},[s]);(0,c.useEffect)(()=>(z(),window.addEventListener(`resize`,z),()=>window.removeEventListener(`resize`,z)),[z]),(0,c.useEffect)(()=>{if(o.current&&a.current){if(T){let e=a.current.findOne(`#`+T);if(e){o.current.nodes([e]),o.current.getLayer()?.batchDraw();return}}o.current.nodes([]),o.current.getLayer()?.batchDraw()}},[T,D]);let B=(0,c.useCallback)(e=>{I(t=>{let n=t.slice(0,L+1);return n.push(e),n}),R(e=>e+1)},[L]),V=(0,c.useCallback)(()=>{if(L>0){let e=L-1;R(e),O(F[e]),E(null)}},[L,F]),H=(0,c.useCallback)(()=>{if(L<F.length-1){let e=L+1;R(e),O(F[e]),E(null)}},[L,F]),U=()=>{if(D.length===0)return;let e=[];O(e),B(e),E(null)},W=(0,c.useCallback)(()=>{if(!T)return;let e=D.filter(e=>e.id!==T);O(e),B(e),E(null)},[T,D,B]);(0,c.useEffect)(()=>{let e=e=>{e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement||((e.ctrlKey||e.metaKey)&&e.key===`z`?(e.shiftKey?H():V(),e.preventDefault()):(e.ctrlKey||e.metaKey)&&e.key===`y`?(H(),e.preventDefault()):e.key===`Delete`||e.key===`Backspace`?T&&(W(),e.preventDefault()):e.key===`Escape`&&(E(null),e.preventDefault()))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[W,H,V,T]);let G=e=>{let t=a.current;if(!t||!s)return;let n=t.getPointerPosition();if(!n)return;let r=n.x/p,i=n.y/p;if(y===`select`){(e.target===t||e.target.hasName(`bg-image`))&&E(null);return}if(y===`eraser`){let n=e.target;if(n!==t&&!n.hasName(`bg-image`)){let e=n.id();if(e){let t=D.filter(t=>t.id!==e);O(t),B(t),E(null);return}}}E(null),M(!0),P({x:r,y:i});let o=`shape_${Date.now()}_${Math.random().toString(36).substring(2,7)}`;if(y===`pencil`||y===`eraser`){let e={id:o,type:`line`,tool:y,points:[r,i],stroke:y===`eraser`?`#ffffff`:x,strokeWidth:y===`eraser`?C*2.5:C};A(e)}else y===`rectangle`?A({id:o,type:`rectangle`,x:r,y:i,width:0,height:0,stroke:x,strokeWidth:C}):y===`circle`?A({id:o,type:`circle`,x:r,y:i,radius:0,stroke:x,strokeWidth:C}):y===`arrow`&&A({id:o,type:`arrow`,points:[r,i,r,i],stroke:x,fill:x,strokeWidth:C})},K=()=>{if(!j||!k||!N||!a.current)return;let e=a.current.getPointerPosition();if(!e)return;let t=e.x/p,n=e.y/p;if(k.type===`line`)A({...k,points:[...k.points,t,n]});else if(k.type===`rectangle`){let e=Math.min(N.x,t),r=Math.min(N.y,n),i=Math.abs(t-N.x),a=Math.abs(n-N.y);A({...k,x:e,y:r,width:i,height:a})}else if(k.type===`circle`){let e=Math.hypot(t-N.x,n-N.y);A({...k,radius:e})}else k.type===`arrow`&&A({...k,points:[N.x,N.y,t,n]})},q=()=>{if(!j||(M(!1),!k))return;let e=!1;if(k.type===`line`&&k.points.length>=2)e=!0;else if(k.type===`rectangle`&&k.width>6&&k.height>6)e=!0;else if(k.type===`circle`&&k.radius>5)e=!0;else if(k.type===`arrow`){let[t,n,r,i]=k.points;Math.hypot(r-t,i-n)>10&&(e=!0)}if(e){let e=[...D,k];O(e),B(e),(k.type===`rectangle`||k.type===`circle`||k.type===`arrow`)&&(E(k.id),b(`select`))}A(null),P(null)},J=(e,t)=>{let n=e.target,r=D.find(e=>e.id===t);if(r){if(r.type===`rectangle`){let e=n.scaleX(),i=n.scaleY();n.scaleX(1),n.scaleY(1);let a={...r,x:n.x(),y:n.y(),width:Math.max(10,n.width()*e),height:Math.max(10,n.height()*i),rotation:n.rotation()},o=D.map(e=>e.id===t?a:e);O(o),B(o)}else if(r.type===`circle`){let e=n.scaleX();n.scaleX(1),n.scaleY(1);let i={...r,x:n.x(),y:n.y(),radius:Math.max(6,r.radius*e),rotation:n.rotation()},a=D.map(e=>e.id===t?i:e);O(a),B(a)}else if(r.type===`arrow`){let e=n.scaleX(),i=n.scaleY();n.scaleX(1),n.scaleY(1);let[a,o,s,c]=r.points,l={...r,x:n.x(),y:n.y(),points:[a,o,a+(s-a)*e,o+(c-o)*i],rotation:n.rotation()},u=D.map(e=>e.id===t?l:e);O(u),B(u)}}},Y=(e,t)=>{let n=e.target;if(!D.find(e=>e.id===t))return;let r=D.map(e=>e.id===t?{...e,x:n.x(),y:n.y()}:e);O(r),B(r)};return(0,d.jsxs)(`div`,{ref:i,className:`fixed inset-0 z-[100000] flex flex-col bg-slate-950/90 backdrop-blur-md select-none text-white overflow-hidden animate-fadeIn`,style:{touchAction:`none`},children:[(0,d.jsxs)(`div`,{className:`flex h-16 shrink-0 items-center justify-between border-b border-slate-800 bg-slate-900/90 px-4 sm:px-6`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,d.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded-lg text-white font-bold text-sm shadow`,style:{backgroundColor:r},children:`BD`}),(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`h1`,{className:`text-sm sm:text-base font-semibold leading-tight text-slate-100`,children:`Screenshot Editor`}),(0,d.jsx)(`p`,{className:`text-xs text-slate-400 hidden sm:block`,children:`Highlight issues with pencil, arrows, circles, and boxes`})]})]}),(0,d.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[(0,d.jsx)(`button`,{type:`button`,onClick:V,disabled:L<=0,title:`Undo (Ctrl+Z)`,className:`flex h-9 w-9 items-center justify-center rounded-lg border border-slate-700 bg-slate-800 text-slate-200 transition hover:bg-slate-700 hover:text-white disabled:opacity-40 disabled:pointer-events-none`,children:(0,d.jsx)(u.Undo2,{className:`h-4 w-4`})}),(0,d.jsx)(`button`,{type:`button`,onClick:H,disabled:L>=F.length-1,title:`Redo (Ctrl+Y)`,className:`flex h-9 w-9 items-center justify-center rounded-lg border border-slate-700 bg-slate-800 text-slate-200 transition hover:bg-slate-700 hover:text-white disabled:opacity-40 disabled:pointer-events-none`,children:(0,d.jsx)(u.Redo2,{className:`h-4 w-4`})}),(0,d.jsxs)(`button`,{type:`button`,onClick:U,disabled:D.length===0,title:`Clear all annotations`,className:`flex h-9 items-center gap-1.5 rounded-lg border border-slate-700 bg-slate-800 px-2.5 text-xs font-medium text-slate-300 transition hover:bg-slate-700 hover:text-white disabled:opacity-40 disabled:pointer-events-none`,children:[(0,d.jsx)(u.Trash2,{className:`h-3.5 w-3.5`}),(0,d.jsx)(`span`,{className:`hidden md:inline`,children:`Clear All`})]}),(0,d.jsx)(`div`,{className:`h-5 w-px bg-slate-700 mx-1`}),(0,d.jsxs)(`button`,{type:`button`,onClick:n,className:`flex h-9 items-center gap-1.5 rounded-lg border border-slate-700 bg-slate-800 px-3 text-xs sm:text-sm font-medium text-slate-200 transition hover:bg-slate-700 hover:text-white`,children:[(0,d.jsx)(u.X,{className:`h-4 w-4`}),(0,d.jsx)(`span`,{children:`Cancel`})]}),(0,d.jsxs)(`button`,{type:`button`,onClick:()=>{a.current&&(E(null),setTimeout(()=>{a.current&&t(a.current.toDataURL({pixelRatio:1/p,mimeType:`image/png`}))},60))},style:{backgroundColor:r},className:`flex h-9 items-center gap-1.5 rounded-lg px-4 text-xs sm:text-sm font-semibold text-white shadow-md transition hover:brightness-110 active:scale-95`,children:[(0,d.jsx)(u.Check,{className:`h-4 w-4`}),(0,d.jsx)(`span`,{children:`Add to Report`})]})]})]}),(0,d.jsxs)(`div`,{className:`absolute top-20 left-1/2 -translate-x-1/2 z-20 flex flex-wrap items-center justify-center gap-2 rounded-2xl border border-slate-700/80 bg-slate-900/95 p-2 shadow-2xl backdrop-blur-md`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,d.jsx)(`button`,{type:`button`,onClick:()=>b(`select`),title:`Select & Move / Resize`,className:`flex h-9 w-9 items-center justify-center rounded-xl transition ${y===`select`?`bg-blue-600 text-white shadow-inner`:`text-slate-300 hover:bg-slate-800 hover:text-white`}`,children:(0,d.jsx)(u.MousePointer,{className:`h-4 w-4`})}),(0,d.jsx)(`button`,{type:`button`,onClick:()=>{b(`pencil`),E(null)},title:`Pencil / Draw`,className:`flex h-9 w-9 items-center justify-center rounded-xl transition ${y===`pencil`?`bg-blue-600 text-white shadow-inner`:`text-slate-300 hover:bg-slate-800 hover:text-white`}`,children:(0,d.jsx)(u.Pencil,{className:`h-4 w-4`})}),(0,d.jsx)(`button`,{type:`button`,onClick:()=>{b(`eraser`),E(null)},title:`Eraser (click or drag to erase)`,className:`flex h-9 w-9 items-center justify-center rounded-xl transition ${y===`eraser`?`bg-blue-600 text-white shadow-inner`:`text-slate-300 hover:bg-slate-800 hover:text-white`}`,children:(0,d.jsx)(u.Eraser,{className:`h-4 w-4`})}),(0,d.jsx)(`button`,{type:`button`,onClick:()=>{b(`rectangle`),E(null)},title:`Rectangle (Resizable)`,className:`flex h-9 w-9 items-center justify-center rounded-xl transition ${y===`rectangle`?`bg-blue-600 text-white shadow-inner`:`text-slate-300 hover:bg-slate-800 hover:text-white`}`,children:(0,d.jsx)(u.Square,{className:`h-4 w-4`})}),(0,d.jsx)(`button`,{type:`button`,onClick:()=>{b(`circle`),E(null)},title:`Circle (Resizable)`,className:`flex h-9 w-9 items-center justify-center rounded-xl transition ${y===`circle`?`bg-blue-600 text-white shadow-inner`:`text-slate-300 hover:bg-slate-800 hover:text-white`}`,children:(0,d.jsx)(u.Circle,{className:`h-4 w-4`})}),(0,d.jsx)(`button`,{type:`button`,onClick:()=>{b(`arrow`),E(null)},title:`Arrow (Resizable)`,className:`flex h-9 w-9 items-center justify-center rounded-xl transition ${y===`arrow`?`bg-blue-600 text-white shadow-inner`:`text-slate-300 hover:bg-slate-800 hover:text-white`}`,children:(0,d.jsx)(u.ArrowUpRight,{className:`h-4 w-4`})})]}),(0,d.jsx)(`div`,{className:`h-5 w-px bg-slate-700`}),(0,d.jsxs)(`div`,{className:`flex items-center gap-1.5 px-1`,children:[h.map(e=>(0,d.jsx)(`button`,{type:`button`,onClick:()=>S(e),title:e,style:{backgroundColor:e},className:`h-5 w-5 rounded-full border border-slate-700 transition-transform ${x===e?`scale-125 ring-2 ring-white ring-offset-1 ring-offset-slate-900`:`hover:scale-110`}`},e)),(0,d.jsxs)(`label`,{title:`Custom Color`,className:`relative flex h-6 w-6 cursor-pointer items-center justify-center rounded-full border border-slate-600 bg-slate-800 text-slate-300 hover:text-white transition`,children:[(0,d.jsx)(u.Palette,{className:`h-3.5 w-3.5`}),(0,d.jsx)(`input`,{type:`color`,value:x,onChange:e=>S(e.target.value),className:`absolute inset-0 opacity-0 cursor-pointer`})]})]}),(0,d.jsx)(`div`,{className:`h-5 w-px bg-slate-700`}),(0,d.jsx)(`div`,{className:`flex items-center gap-1`,children:g.map(e=>(0,d.jsx)(`button`,{type:`button`,onClick:()=>w(e.value),className:`flex h-7 w-7 items-center justify-center rounded-lg text-xs font-semibold transition ${C===e.value?`bg-slate-700 text-white ring-1 ring-slate-400`:`text-slate-400 hover:bg-slate-800 hover:text-white`}`,children:e.label},e.value))}),T&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`div`,{className:`h-5 w-px bg-slate-700`}),(0,d.jsxs)(`button`,{type:`button`,onClick:W,title:`Delete Selected Shape (Del / Backspace)`,className:`flex h-8 items-center gap-1.5 rounded-xl bg-red-600/90 px-3 text-xs font-semibold text-white shadow hover:bg-red-600`,children:[(0,d.jsx)(u.Trash2,{className:`h-3.5 w-3.5`}),(0,d.jsx)(`span`,{children:`Delete`})]})]})]}),(0,d.jsx)(`div`,{className:`relative flex flex-1 items-center justify-center p-4 overflow-hidden`,children:s?(0,d.jsx)(`div`,{className:`relative shadow-2xl rounded-md overflow-hidden border border-slate-700 bg-slate-900`,style:{width:_.width,height:_.height,cursor:y===`select`?`default`:y===`eraser`?`cell`:`crosshair`},children:(0,d.jsxs)(f.Stage,{ref:a,width:_.width,height:_.height,scaleX:p,scaleY:p,onMouseDown:G,onMouseMove:K,onMouseUp:q,onTouchStart:G,onTouchMove:K,onTouchEnd:q,children:[(0,d.jsx)(f.Layer,{listening:!1,children:(0,d.jsx)(f.Image,{name:`bg-image`,image:s,width:s.naturalWidth,height:s.naturalHeight})}),(0,d.jsxs)(f.Layer,{children:[D.map(e=>{let t=y===`select`;return e.type===`line`?(0,d.jsx)(f.Line,{id:e.id,points:e.points,stroke:e.stroke,strokeWidth:e.strokeWidth,tension:.5,lineCap:`round`,lineJoin:`round`,globalCompositeOperation:e.tool===`eraser`?`destination-out`:`source-over`,draggable:t&&e.tool!==`eraser`,onClick:()=>{if(t&&E(e.id),y===`eraser`){let t=D.filter(t=>t.id!==e.id);O(t),B(t)}},onTap:()=>{t&&E(e.id)},onDragEnd:t=>Y(t,e.id)},e.id):e.type===`rectangle`?(0,d.jsx)(f.Rect,{id:e.id,x:e.x,y:e.y,width:e.width,height:e.height,stroke:e.stroke,strokeWidth:e.strokeWidth,rotation:e.rotation||0,draggable:t,onClick:()=>{if(t&&E(e.id),y===`eraser`){let t=D.filter(t=>t.id!==e.id);O(t),B(t)}},onTap:()=>{t&&E(e.id)},onTransformEnd:t=>J(t,e.id),onDragEnd:t=>Y(t,e.id)},e.id):e.type===`circle`?(0,d.jsx)(f.Circle,{id:e.id,x:e.x,y:e.y,radius:e.radius,stroke:e.stroke,strokeWidth:e.strokeWidth,rotation:e.rotation||0,draggable:t,onClick:()=>{if(t&&E(e.id),y===`eraser`){let t=D.filter(t=>t.id!==e.id);O(t),B(t)}},onTap:()=>{t&&E(e.id)},onTransformEnd:t=>J(t,e.id),onDragEnd:t=>Y(t,e.id)},e.id):e.type===`arrow`?(0,d.jsx)(f.Arrow,{id:e.id,points:e.points,pointerLength:14,pointerWidth:14,stroke:e.stroke,fill:e.fill,strokeWidth:e.strokeWidth,rotation:e.rotation||0,draggable:t,onClick:()=>{if(t&&E(e.id),y===`eraser`){let t=D.filter(t=>t.id!==e.id);O(t),B(t)}},onTap:()=>{t&&E(e.id)},onTransformEnd:t=>J(t,e.id),onDragEnd:t=>Y(t,e.id)},e.id):null}),k&&(0,d.jsxs)(d.Fragment,{children:[k.type===`line`&&(0,d.jsx)(f.Line,{points:k.points,stroke:k.stroke,strokeWidth:k.strokeWidth,tension:.5,lineCap:`round`,lineJoin:`round`,globalCompositeOperation:k.tool===`eraser`?`destination-out`:`source-over`}),k.type===`rectangle`&&(0,d.jsx)(f.Rect,{x:k.x,y:k.y,width:k.width,height:k.height,stroke:k.stroke,strokeWidth:k.strokeWidth,dash:[6,4]}),k.type===`circle`&&(0,d.jsx)(f.Circle,{x:k.x,y:k.y,radius:k.radius,stroke:k.stroke,strokeWidth:k.strokeWidth,dash:[6,4]}),k.type===`arrow`&&(0,d.jsx)(f.Arrow,{points:k.points,pointerLength:14,pointerWidth:14,stroke:k.stroke,fill:k.fill,strokeWidth:k.strokeWidth,dash:[6,4]})]}),(0,d.jsx)(f.Transformer,{ref:o,rotateEnabled:!0,enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`,`middle-left`,`middle-right`,`top-center`,`bottom-center`],borderStroke:`#3b82f6`,borderDash:[4,4],anchorFill:`#ffffff`,anchorStroke:`#3b82f6`,anchorSize:9,anchorCornerRadius:2,boundBoxFunc:(e,t)=>t.width<10||t.height<10?e:t})]})]})}):(0,d.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-slate-400`,children:[(0,d.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-2 border-blue-500 border-t-transparent`}),(0,d.jsx)(`p`,{className:`text-sm`,children:`Loading screenshot...`})]})}),(0,d.jsxs)(`div`,{className:`flex h-10 shrink-0 items-center justify-between border-t border-slate-800 bg-slate-900/80 px-4 text-xs text-slate-400`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,d.jsxs)(`span`,{children:[`Active tool: `,(0,d.jsx)(`strong`,{className:`text-slate-200 capitalize`,children:y})]}),(0,d.jsxs)(`span`,{className:`hidden sm:inline`,children:[`Use `,(0,d.jsx)(`kbd`,{className:`rounded bg-slate-800 px-1 py-0.5 text-slate-300`,children:`Ctrl+Z`}),` to undo, `,(0,d.jsx)(`kbd`,{className:`rounded bg-slate-800 px-1 py-0.5 text-slate-300`,children:`Del`}),` to remove selected shape`]})]}),(0,d.jsx)(`div`,{children:s&&(0,d.jsxs)(`span`,{children:[`Original Resolution: `,s.naturalWidth,` x `,s.naturalHeight,`px`]})})]})]})},v=({projectUrl:e,onSubmit:t,uiSettings:n={},onSuccess:r,onError:i,isOpen:a,onToggle:o,className:s=``})=>{let{position:f=`bottom-right`,primaryColor:p=`#2563eb`,buttonSize:h=`md`,buttonText:g,buttonIcon:v,zIndex:y=99990}=n,[b,x]=(0,c.useState)(!1),S=a===void 0?b:a,C=e=>{a===void 0&&x(e),o?.(e)},[w,T]=(0,c.useState)([]),[E,D]=(0,c.useState)(!1),[O,k]=(0,c.useState)(!1),[A,j]=(0,c.useState)(null),M=e=>{switch(e){case`bottom-left`:return`bottom-6 left-6`;case`top-left`:return`top-6 left-6`;case`top-right`:return`top-6 right-6`;case`left`:return`top-1/2 -translate-y-1/2 left-4`;case`right`:return`top-1/2 -translate-y-1/2 right-4`;default:return`bottom-6 right-6`}},N=(e=>{switch(e){case`sm`:return{button:`h-10 px-3.5 gap-2 text-xs font-semibold rounded-full shadow-md`,icon:`h-4 w-4`};case`lg`:return{button:`h-14 px-5 gap-3 text-base font-bold rounded-full shadow-xl`,icon:`h-6 w-6`};default:return{button:`h-12 px-4 gap-2.5 text-sm font-semibold rounded-full shadow-lg`,icon:`h-5 w-5`}}})(h);return E?null:(0,d.jsxs)(d.Fragment,{children:[!O&&(0,d.jsx)(`div`,{"data-bugdrop-widget":`true`,className:`fixed ${M(f)} ${s}`,style:{zIndex:y},children:(0,d.jsxs)(`button`,{type:`button`,onClick:()=>C(!S),style:{backgroundColor:p},className:`group flex items-center justify-center text-white transition-all duration-200 hover:brightness-110 active:scale-95 ${N.button}`,"aria-label":S?`Close bug report form`:`Open bug report form`,title:S?`Close Bug Report`:`Report a Bug`,children:[S?(0,d.jsx)(u.X,{className:N.icon}):v||(0,d.jsx)(u.Bug,{className:N.icon}),g&&(0,d.jsx)(`span`,{children:g}),w.length>0&&!S&&(0,d.jsx)(`span`,{className:`flex h-5 w-5 items-center justify-center rounded-full bg-white text-[11px] font-bold text-slate-900 shadow`,children:w.length})]})}),!O&&(0,d.jsx)(m,{projectUrl:e,isOpen:S,onClose:()=>C(!1),uiSettings:n,screenshots:w,onTriggerScreenshot:async()=>{D(!0);try{await new Promise(e=>setTimeout(e,180));let e=(await(0,l.default)(document.documentElement,{useCORS:!0,allowTaint:!0,logging:!1,scrollX:0,scrollY:-window.scrollY,windowWidth:document.documentElement.offsetWidth,windowHeight:document.documentElement.offsetHeight,ignoreElements:e=>e.getAttribute(`data-bugdrop-widget`)===`true`||e.classList.contains(`bugdrop-ignore`)})).toDataURL(`image/png`);j({dataUrl:e,isNew:!0}),k(!0)}catch(e){console.error(`Error taking screenshot:`,e),alert(`Could not capture screenshot. Please try again.`)}finally{D(!1)}},onEditScreenshot:e=>{j({id:e.id,dataUrl:e.dataUrl,isNew:!1}),k(!0)},onDeleteScreenshot:e=>{T(t=>t.filter(t=>t.id!==e))},onSubmitReport:async e=>{try{await t(e),r?.(e)}catch(e){let t=e instanceof Error?e:Error(`Failed to submit bug report`);throw i?.(t),t}}}),O&&A&&(0,d.jsx)(_,{imageSrc:A.dataUrl,onSave:e=>{if(A?.isNew){if(w.length<3){let t={id:`ss_${Date.now()}_${Math.random().toString(36).substring(2,6)}`,dataUrl:e,createdAt:Date.now()};T(e=>[...e,t])}}else A?.id&&T(t=>t.map(t=>t.id===A.id?{...t,dataUrl:e}:t));k(!1),j(null),C(!0)},onCancel:()=>{k(!1),j(null),C(!0)},primaryColor:p})]})};exports.Widget=v;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("react");c=s(c,1);let l=require("lucide-react"),u=require("react/jsx-runtime");var d=class e{window;cspNonce;cache;constructor(e={}){let t=e.window||(typeof window<`u`?window:void 0);if(!t)throw Error(`Window object is required but not available`);this.window=t,this.cspNonce=e.cspNonce,this.cache=e.cache}static fromElement(t,n={}){let r=t.ownerDocument;if(!r)throw Error(`Element is not attached to a document`);let i=r.defaultView;if(!i)throw Error(`Document is not attached to a window`);return new e({window:i,...n})}clone(t={}){return new e({window:t.window||this.window,cspNonce:t.cspNonce??this.cspNonce,cache:t.cache??this.cache})}},f=class{config;constructor(e={}){this.config={maxImageTimeout:3e5,allowDataUrls:!0,...e}}validateUrl(e,t=`general`){if(!e||typeof e!=`string`)return{valid:!1,error:`URL must be a non-empty string`};if(e.startsWith(`data:`))return this.config.allowDataUrls?{valid:!0,sanitized:e}:{valid:!1,error:`Data URLs are not allowed`};if(e.startsWith(`blob:`))return{valid:!0,sanitized:e};try{let n=new URL(e);if(![`http:`,`https:`].includes(n.protocol))return{valid:!1,error:`Protocol ${n.protocol} is not allowed. Only http and https are permitted.`};if(t===`proxy`&&this.config.allowedProxyDomains&&this.config.allowedProxyDomains.length>0){let e=n.hostname.toLowerCase();if(!this.config.allowedProxyDomains.some(t=>{let n=t.toLowerCase();return e===n||e.endsWith(`.`+n)}))return{valid:!1,error:`Proxy domain ${n.hostname} is not in the allowed list`}}if(t===`proxy`){if(!this.config.allowLocalhostProxy){let e=n.hostname.toLowerCase();if(e===`localhost`||e===`127.0.0.1`||e===`::1`)return{valid:!1,error:`Localhost is not allowed for proxy URLs`};if(this.isPrivateIP(e))return{valid:!1,error:`Private IP addresses are not allowed for proxy URLs`};if(e.startsWith(`169.254.`)||e.startsWith(`fe80:`))return{valid:!1,error:`Link-local addresses are not allowed for proxy URLs`}}return{valid:!0,sanitized:e}}return{valid:!0,sanitized:e}}catch(e){return{valid:!1,error:`Invalid URL format: ${e instanceof Error?e.message:`Unknown error`}`}}}isPrivateIP(e){return[/^0\./,/^10\./,/^100\.(6[4-9]|[7-9][0-9]|1[0-1][0-9]|12[0-7])\./,/^127\./,/^169\.254\./,/^172\.(1[6-9]|2[0-9]|3[0-1])\./,/^192\.0\.0\./,/^192\.0\.2\./,/^192\.168\./,/^198\.(1[8-9])\./,/^198\.51\.100\./,/^203\.0\.113\./,/^2(2[4-9]|3[0-9])\./,/^24[0-9]\./,/^255\.255\.255\.255$/].some(t=>t.test(e))?!0:e.includes(`:`)?this.isPrivateIPv6(e):!1}isPrivateIPv6(e){let t=e.toLowerCase().trim().replace(/^\[|\]$/g,``),n=t.split(`%`)[0]??t;if(/^(0:){7}1$/.test(n)||n===`::1`||/^(0:){7}0$/.test(n)||n===`::`)return!0;let r=this.expandIPv6(n);if(!r)return this.isPrivateIPv6Prefix(n);let i=parseInt(r.substring(0,2),16);if(i>=252&&i<=253)return!0;if(i===254){let e=parseInt(r.substring(2,4),16);if(e>=128&&e<=191)return!0}return i===255}expandIPv6(e){try{if(e.includes(`::`)){let t=e.split(`::`);if(t.length>2)return null;let n=t[0]?t[0].split(`:`):[],r=t[1]?t[1].split(`:`):[],i=8-n.length-r.length;if(i<0)return null;let a=Array(i).fill(`0000`);return[...n,...a,...r].map(e=>e.padStart(4,`0`)).join(`:`)}{let t=e.split(`:`);return t.length===8?t.map(e=>e.padStart(4,`0`)).join(`:`):null}}catch{return null}}isPrivateIPv6Prefix(e){return!!(/^fc[0-9a-f]{0,2}:?/i.test(e)||/^fd[0-9a-f]{0,2}:?/i.test(e)||/^fe[89ab][0-9a-f]:?/i.test(e)||/^ff[0-9a-f]{0,2}:?/i.test(e))}validateCspNonce(e){return!e||typeof e!=`string`?{valid:!1,error:`CSP nonce must be a non-empty string`}:e.length<16?{valid:!1,error:`CSP nonce is too short (minimum 16 characters recommended)`}:/^[A-Za-z0-9+/=_-]+$/.test(e)?{valid:!0,sanitized:e}:{valid:!1,error:`CSP nonce contains invalid characters`}}validateImageTimeout(e){return typeof e!=`number`||isNaN(e)?{valid:!1,error:`Image timeout must be a number`}:e<0?{valid:!1,error:`Image timeout cannot be negative`}:this.config.maxImageTimeout&&e>this.config.maxImageTimeout?{valid:!1,error:`Image timeout ${e}ms exceeds maximum allowed ${this.config.maxImageTimeout}ms`}:{valid:!0,sanitized:e}}validateDimensions(e,t){if(typeof e!=`number`||typeof t!=`number`)return{valid:!1,error:`Dimensions must be numbers`};if(isNaN(e)||isNaN(t))return{valid:!1,error:`Dimensions cannot be NaN`};if(e<=0||t<=0)return{valid:!1,error:`Dimensions must be positive`};let n=32767;return e>n||t>n?{valid:!1,error:`Dimensions exceed maximum allowed (${n}px)`}:{valid:!0,sanitized:{width:e,height:t}}}validateScale(e){return typeof e!=`number`||isNaN(e)?{valid:!1,error:`Scale must be a number`}:e<=0?{valid:!1,error:`Scale must be positive`}:e>10?{valid:!1,error:`Scale factor too large (maximum 10x)`}:{valid:!0,sanitized:e}}validateElement(e){if(!e)return{valid:!1,error:`Element is required`};if(typeof e!=`object`)return{valid:!1,error:`Element must be an object`};let t=e;return typeof HTMLElement<`u`&&e instanceof HTMLElement?e.ownerDocument?{valid:!0}:{valid:!1,error:`Element must be attached to a document`}:t.ownerDocument?t.ownerDocument.defaultView?{valid:!0}:{valid:!1,error:`Document must be attached to a window (ownerDocument.defaultView required)`}:{valid:!1,error:`Element must be attached to a document (ownerDocument required)`}}validateOptions(e){let t=[],n=e.proxy;if(n!=null&&typeof n==`string`&&n.length>0){let e=this.validateUrl(n,`proxy`);e.valid||t.push(`Proxy: ${e.error}`)}if(e.imageTimeout!==void 0){let n=this.validateImageTimeout(e.imageTimeout);n.valid||t.push(`Image timeout: ${n.error}`)}if(e.width!==void 0||e.height!==void 0){let n=e.width??800,r=e.height??600,i=this.validateDimensions(n,r);i.valid||t.push(`Dimensions: ${i.error}`)}if(e.scale!==void 0){let n=this.validateScale(e.scale);n.valid||t.push(`Scale: ${n.error}`)}if(e.cspNonce!==void 0){let n=this.validateCspNonce(e.cspNonce);n.valid||t.push(`CSP nonce: ${n.error}`)}if(this.config.customValidator){let n=this.config.customValidator(e,`options`);n.valid||t.push(`Custom validation: ${n.error}`)}return t.length>0?{valid:!1,error:t.join(`; `)}:{valid:!0}}};function p(e={}){return new f({allowDataUrls:!0,maxImageTimeout:3e5,...e})}var m=class{context;activeMetrics=new Map;completedMetrics=[];enabled;getTime;constructor(e,t=!0){this.context=e,this.enabled=t,this.getTime=typeof performance<`u`&&typeof performance.now==`function`?()=>performance.now():()=>Date.now()}start(e,t){this.enabled&&(this.activeMetrics.has(e)&&this.context?.logger.warn(`Performance metric '${e}' already started. Overwriting.`),this.activeMetrics.set(e,{name:e,startTime:this.getTime(),metadata:t}))}end(e){if(!this.enabled)return;let t=this.activeMetrics.get(e);if(!t)this.context?.logger.warn(`Performance metric '${e}' not found. Was start() called?`);else return t.endTime=this.getTime(),t.duration=t.endTime-t.startTime,this.completedMetrics.push(t),this.activeMetrics.delete(e),this.context?.logger.debug(`⏱️ ${e}: ${t.duration.toFixed(2)}ms`,t.metadata),t}measure(e,t,n){this.start(e,n);try{let n=t();return this.end(e),n}catch(t){throw this.end(e),t}}async measureAsync(e,t,n){this.start(e,n);try{let n=await t();return this.end(e),n}catch(t){throw this.end(e),t}}getMetrics(){return[...this.completedMetrics]}getMetric(e){return this.completedMetrics.find(t=>t.name===e)}getSummary(){let e=this.completedMetrics.reduce((e,t)=>e+(t.duration||0),0),t=this.completedMetrics.map(t=>({name:t.name,duration:t.duration||0,percentage:e>0?((t.duration||0)/e*100).toFixed(1)+`%`:`0%`}));return{totalDuration:e,metrics:this.getMetrics(),breakdown:t}}logSummary(){if(!this.enabled||this.completedMetrics.length===0||!this.context)return;let e=this.getSummary();this.context.logger.info(`\n📊 Performance Summary (Total: ${e.totalDuration.toFixed(2)}ms):`),e.breakdown.sort((e,t)=>t.duration-e.duration).forEach(e=>{this.context.logger.info(` ${e.name.padEnd(20)} ${e.duration.toFixed(2).padStart(8)}ms ${e.percentage.padStart(6)}`)})}clear(){this.activeMetrics.clear(),this.completedMetrics.splice(0)}isEnabled(){return this.enabled}getActiveMetrics(){return Array.from(this.activeMetrics.keys())}},h=class e{left;top;width;height;constructor(e,t,n,r){this.left=e,this.top=t,this.width=n,this.height=r}add(t,n,r,i){return new e(this.left+t,this.top+n,this.width+r,this.height+i)}static fromClientRect(t,n){return new e(n.left+t.windowBounds.left,n.top+t.windowBounds.top,n.width,n.height)}static fromDOMRectList(t,n){let r=Array.from(n),i=r.find(e=>e.width!==0);return i||=r.find(e=>e.height!==0),!i&&r.length>0&&(i=r[0]),i?new e(i.left+t.windowBounds.left,i.top+t.windowBounds.top,i.width,i.height):e.EMPTY}static EMPTY=new e(0,0,0,0)},g=(e,t)=>h.fromClientRect(e,t.getBoundingClientRect()),_=e=>{let t=e.body,n=e.documentElement;if(!t||!n)throw Error(`Unable to get document size`);return new h(0,0,Math.max(Math.max(t.scrollWidth,n.scrollWidth),Math.max(t.offsetWidth,n.offsetWidth),Math.max(t.clientWidth,n.clientWidth)),Math.max(Math.max(t.scrollHeight,n.scrollHeight),Math.max(t.offsetHeight,n.offsetHeight),Math.max(t.clientHeight,n.clientHeight)))},v=(e,t)=>{let n=e[t];if(n===void 0)throw Error(`Missing element at index ${t}`);return n},y=65533,b=e=>e>=48&&e<=57,x=e=>e>=55296&&e<=57343,S=e=>b(e)||e>=65&&e<=70||e>=97&&e<=102,C=e=>e>=97&&e<=122,w=e=>e>=65&&e<=90,T=e=>C(e)||w(e),ee=e=>e>=128,E=e=>e===10||e===9||e===32,D=e=>T(e)||ee(e)||e===95,O=e=>D(e)||b(e)||e===45,te=e=>e>=0&&e<=8||e===11||e>=14&&e<=31||e===127,k=(e,t)=>e===92&&t!==10,A=(e,t,n)=>e===45?D(t)||k(t,n):!!(D(e)||e===92&&k(e,t)),j=(e,t,n)=>e===43||e===45?b(t)?!0:t===46&&b(n):b(e===46?t:e),ne=e=>{let t=0,n=1;(e[t]===43||e[t]===45)&&(e[t]===45&&(n=-1),t++);let r=[];for(;b(e[t]??NaN);)r.push(v(e,t)),t++;let i=r.length?parseInt(String.fromCodePoint(...r),10):0;e[t]===46&&t++;let a=[];for(;b(e[t]??NaN);)a.push(v(e,t)),t++;let o=a.length,s=o?parseInt(String.fromCodePoint(...a),10):0;(e[t]===69||e[t]===101)&&t++;let c=1;(e[t]===43||e[t]===45)&&(e[t]===45&&(c=-1),t++);let l=[];for(;b(e[t]??NaN);)l.push(v(e,t)),t++;let u=l.length?parseInt(String.fromCodePoint(...l),10):0;return n*(i+s*10**-o)*10**(c*u)},re={type:2},ie={type:3},ae={type:4},oe={type:13},se={type:8},ce={type:21},le={type:9},ue={type:10},de={type:11},fe={type:12},pe={type:14},me={type:23},he={type:1},ge={type:25},_e={type:24},ve={type:26},ye={type:27},be={type:28},xe={type:29},Se={type:31},Ce={type:32},we=class e{static _pool=[];static MAX_POOL_SIZE=40;static get(){return e._pool.pop()||new e}static release(t){e._pool.length<e.MAX_POOL_SIZE&&(t._reset(),e._pool.push(t))}_value;_cursor;constructor(){this._value=[],this._cursor=0}_reset(){this._value=[],this._cursor=0}write(e){this._cursor>0&&(this._value=this._value.slice(this._cursor),this._cursor=0),this._value=this._value.concat([...e].map(e=>e.codePointAt(0)))}read(){let e=[],t=this.consumeToken();for(;t!==Ce;)e.push(t),t=this.consumeToken();return e}consumeToken(){let e=this.consumeCodePoint();switch(e){case 34:return this.consumeStringToken(34);case 35:{let e=this.peekCodePoint(0),t=this.peekCodePoint(1),n=this.peekCodePoint(2);if(O(e)||k(t,n)){let r=A(e,t,n)?2:1;return{type:5,value:this.consumeName(),flags:r}}break}case 36:if(this.peekCodePoint(0)===61)return this.consumeCodePoint(),oe;break;case 39:return this.consumeStringToken(39);case 40:return re;case 41:return ie;case 42:if(this.peekCodePoint(0)===61)return this.consumeCodePoint(),pe;break;case 43:if(j(e,this.peekCodePoint(0),this.peekCodePoint(1)))return this.reconsumeCodePoint(e),this.consumeNumericToken();break;case 44:return ae;case 45:{let t=e,n=this.peekCodePoint(0),r=this.peekCodePoint(1);if(j(t,n,r))return this.reconsumeCodePoint(e),this.consumeNumericToken();if(A(t,n,r))return this.reconsumeCodePoint(e),this.consumeIdentLikeToken();if(n===45&&r===62)return this.consumeCodePoint(),this.consumeCodePoint(),_e;break}case 46:if(j(e,this.peekCodePoint(0),this.peekCodePoint(1)))return this.reconsumeCodePoint(e),this.consumeNumericToken();break;case 47:if(this.peekCodePoint(0)===42)for(this.consumeCodePoint();;){let e=this.consumeCodePoint();if(e===42&&(e=this.consumeCodePoint(),e===47)||e===-1)return this.consumeToken()}break;case 58:return ve;case 59:return ye;case 60:if(this.peekCodePoint(0)===33&&this.peekCodePoint(1)===45&&this.peekCodePoint(2)===45)return this.consumeCodePoint(),this.consumeCodePoint(),this.consumeCodePoint(),ge;break;case 64:if(A(this.peekCodePoint(0),this.peekCodePoint(1),this.peekCodePoint(2)))return{type:7,value:this.consumeName()};break;case 91:return be;case 92:if(k(e,this.peekCodePoint(0)))return this.reconsumeCodePoint(e),this.consumeIdentLikeToken();break;case 93:return xe;case 94:if(this.peekCodePoint(0)===61)return this.consumeCodePoint(),se;break;case 123:return de;case 125:return fe;case 117:case 85:{let t=this.peekCodePoint(0),n=this.peekCodePoint(1);return t===43&&(S(n)||n===63)?(this.consumeCodePoint(),this.consumeUnicodeRangeToken()):(this.reconsumeCodePoint(e),this.consumeIdentLikeToken())}case 124:if(this.peekCodePoint(0)===61)return this.consumeCodePoint(),le;if(this.peekCodePoint(0)===124)return this.consumeCodePoint(),ce;break;case 126:if(this.peekCodePoint(0)===61)return this.consumeCodePoint(),ue;break;case-1:return Ce}return E(e)?(this.consumeWhiteSpace(),Se):b(e)?(this.reconsumeCodePoint(e),this.consumeNumericToken()):D(e)?(this.reconsumeCodePoint(e),this.consumeIdentLikeToken()):{type:6,value:String.fromCodePoint(e)}}consumeCodePoint(){let e=this._value[this._cursor];return e===void 0?-1:(this._cursor++,e)}reconsumeCodePoint(e){this._cursor>0&&this._value[this._cursor-1]===e?this._cursor--:this._value.splice(this._cursor,0,e)}peekCodePoint(e){let t=this._value[this._cursor+e];return t===void 0?-1:t}consumeUnicodeRangeToken(){let e=[],t=this.consumeCodePoint();for(;S(t)&&e.length<6;)e.push(t),t=this.consumeCodePoint();let n=!1;for(;t===63&&e.length<6;)e.push(t),t=this.consumeCodePoint(),n=!0;if(n)return{type:30,start:parseInt(String.fromCodePoint(...e.map(e=>e===63?48:e)),16),end:parseInt(String.fromCodePoint(...e.map(e=>e===63?70:e)),16)};let r=parseInt(String.fromCodePoint(...e),16);if(t===45&&S(this.peekCodePoint(0))){t=this.consumeCodePoint();let e=[];for(;S(t)&&e.length<6;)e.push(t),t=this.consumeCodePoint();return{type:30,start:r,end:parseInt(String.fromCodePoint(...e),16)}}return{type:30,start:r,end:r}}consumeIdentLikeToken(){let e=this.consumeName();return e.toLowerCase()===`url`&&this.peekCodePoint(0)===40?(this.consumeCodePoint(),this.consumeUrlToken()):this.peekCodePoint(0)===40?(this.consumeCodePoint(),{type:19,value:e}):{type:20,value:e}}consumeUrlToken(){let e=[];if(this.consumeWhiteSpace(),this.peekCodePoint(0)===-1)return{type:22,value:``};let t=this.peekCodePoint(0);if(t===39||t===34){let e=this.consumeStringToken(this.consumeCodePoint());return e.type===0&&(this.consumeWhiteSpace(),this.peekCodePoint(0)===-1||this.peekCodePoint(0)===41)?(this.consumeCodePoint(),{type:22,value:e.value}):(this.consumeBadUrlRemnants(),me)}for(;;){let t=this.consumeCodePoint();if(t===-1||t===41)return{type:22,value:String.fromCodePoint(...e)};if(E(t))return this.consumeWhiteSpace(),this.peekCodePoint(0)===-1||this.peekCodePoint(0)===41?(this.consumeCodePoint(),{type:22,value:String.fromCodePoint(...e)}):(this.consumeBadUrlRemnants(),me);if(t===34||t===39||t===40||te(t))return this.consumeBadUrlRemnants(),me;if(t===92){if(k(t,this.peekCodePoint(0)))e.push(this.consumeEscapedCodePoint());else return this.consumeBadUrlRemnants(),me}else e.push(t)}}consumeWhiteSpace(){for(;E(this.peekCodePoint(0));)this.consumeCodePoint()}consumeBadUrlRemnants(){for(;;){let e=this.consumeCodePoint();if(e===41||e===-1)return;k(e,this.peekCodePoint(0))&&this.consumeEscapedCodePoint()}}consumeStringSlice(e){let t=``,n=this._cursor+e,r=this._cursor;for(;r<n;){let e=Math.min(n,r+5e4);t+=String.fromCodePoint(...this._value.slice(r,e)),r=e}return this._cursor=n+1,t}consumeStringToken(e){let t=``,n=0;do{let r=this._value[this._cursor+n];if(r===-1||r===void 0||r===e)return t+=this.consumeStringSlice(n),{type:0,value:t};if(r===10)return this._cursor+=n,he;if(r===92){let e=this._value[this._cursor+n+1];e!==-1&&e!==void 0&&(e===10?(t+=this.consumeStringSlice(n),n=-1,this._cursor++):k(r,e)&&(t+=this.consumeStringSlice(n),t+=String.fromCodePoint(this.consumeEscapedCodePoint()),n=-1))}n++}while(1)}consumeNumber(){let e=[],t=4,n=this.peekCodePoint(0);for((n===43||n===45)&&e.push(this.consumeCodePoint());b(this.peekCodePoint(0));)e.push(this.consumeCodePoint());n=this.peekCodePoint(0);let r=this.peekCodePoint(1);if(n===46&&b(r))for(e.push(this.consumeCodePoint(),this.consumeCodePoint()),t=8;b(this.peekCodePoint(0));)e.push(this.consumeCodePoint());n=this.peekCodePoint(0),r=this.peekCodePoint(1);let i=this.peekCodePoint(2);if((n===69||n===101)&&((r===43||r===45)&&b(i)||b(r)))for(e.push(this.consumeCodePoint(),this.consumeCodePoint()),t=8;b(this.peekCodePoint(0));)e.push(this.consumeCodePoint());return[ne(e),t]}consumeNumericToken(){let[e,t]=this.consumeNumber(),n=this.peekCodePoint(0);return A(n,this.peekCodePoint(1),this.peekCodePoint(2))?{type:15,number:e,flags:t,unit:this.consumeName()}:n===37?(this.consumeCodePoint(),{type:16,number:e,flags:t}):{type:17,number:e,flags:t}}consumeEscapedCodePoint(){let e=this.consumeCodePoint();if(S(e)){let t=String.fromCodePoint(e);for(;S(this.peekCodePoint(0))&&t.length<6;)t+=String.fromCodePoint(this.consumeCodePoint());E(this.peekCodePoint(0))&&this.consumeCodePoint();let n=parseInt(t,16);return n===0||x(n)||n>1114111?y:n}return e===-1?y:e}consumeName(){let e=``;for(;;){let t=this.consumeCodePoint();if(O(t))e+=String.fromCodePoint(t);else if(k(t,this.peekCodePoint(0)))e+=String.fromCodePoint(this.consumeEscapedCodePoint());else return this.reconsumeCodePoint(t),e}}},Te=class e{_tokens;constructor(e){this._tokens=e}static create(t){let n=new we;return n.write(t),new e(n.read())}static parseValue(t){return e.create(t).parseComponentValue()}static parseValues(t){return e.create(t).parseComponentValues()}parseComponentValue(){let e=this.consumeToken();for(;e.type===31;)e=this.consumeToken();if(e.type===32)throw SyntaxError(`Error parsing CSS component value, unexpected EOF`);this.reconsumeToken(e);let t=this.consumeComponentValue();do e=this.consumeToken();while(e.type===31);if(e.type===32)return t;throw SyntaxError(`Error parsing CSS component value, multiple values found when expecting only one`)}parseComponentValues(){let e=[];for(;;){let t=this.consumeComponentValue();if(t.type===32)return e;e.push(t)}}consumeComponentValue(){let e=this.consumeToken();switch(e.type){case 11:case 28:case 2:return this.consumeSimpleBlock(e.type);case 19:return this.consumeFunction(e)}return e}consumeSimpleBlock(e){let t={type:e,values:[]},n=this.consumeToken();for(;;){if(n.type===32||Ae(n,e))return t;this.reconsumeToken(n),t.values.push(this.consumeComponentValue()),n=this.consumeToken()}}consumeFunction(e){let t={name:e.value,values:[],type:18};for(;;){let e=this.consumeToken();if(e.type===32||e.type===3)return t;this.reconsumeToken(e),t.values.push(this.consumeComponentValue())}}consumeToken(){let e=this._tokens.shift();return e===void 0?Ce:e}reconsumeToken(e){this._tokens.unshift(e)}},M=e=>e.type===15,N=e=>e.type===17,P=e=>e.type===20,Ee=e=>e.type===0,De=(e,t)=>P(e)&&e.value===t,Oe=e=>e.type!==31,F=e=>e.type!==31&&e.type!==4,ke=e=>{let t=[],n=[];return e.forEach(e=>{e.type===4?n.length&&(t.push(n),n=[]):e.type!==31&&n.push(e)}),n.length&&t.push(n),t},Ae=(e,t)=>t===11&&e.type===12||t===28&&e.type===29||t===2&&e.type===3,je=/(\d+(?:\.\d+)?|[+\-*/()])/g,Me=e=>{let t=e.match(je);if(!t)return NaN;let n=[],r=[],i={"+":1,"-":1,"*":2,"/":2};for(let e of t)if(/^\d+(?:\.\d+)?$/.test(e))n.push(parseFloat(e));else if(e===`(`)r.push(e);else if(e===`)`){for(;r.length&&r[r.length-1]!==`(`;)n.push(r.pop());if(!r.length)return NaN;r.pop()}else{for(;r.length&&(i[v(r,r.length-1)]??0)>=(i[e]??0);)n.push(r.pop());r.push(e)}for(;r.length;){let e=r.pop();if(e===`(`)return NaN;n.push(e)}let a=[];for(let e of n)if(typeof e==`number`)a.push(e);else{let t=a.pop(),n=a.pop();if(n===void 0||t===void 0)return NaN;switch(e){case`+`:a.push(n+t);break;case`-`:a.push(n-t);break;case`*`:a.push(n*t);break;case`/`:a.push(t===0?NaN:n/t);break;default:return NaN}}return a.length===1?a[0]??NaN:NaN},I=(e,t,n)=>Math.min(Math.max(e,t),n),L=(e,t)=>[e[0]*t[0]+e[1]*t[1]+e[2]*t[2],e[3]*t[0]+e[4]*t[1]+e[5]*t[2],e[6]*t[0]+e[7]*t[1]+e[8]*t[2]],Ne=e=>L([3.2409699419045226,-1.537383177570094,-.4986107602930034,-.9692436362808796,1.8759675015077202,.04155505740717559,.05563007969699366,-.20397695888897652,1.0569715142428786],e),Pe=e=>L([.41239079926595934,.357584339383878,.1804807884018343,.21263900587151027,.715168678767756,.07219231536073371,.01933081871559182,.11919477979462598,.9505321522496607],e),Fe=e=>{let[t,n,r]=e,i=e=>{let t=e<0?-1:1,n=Math.abs(e);return n>.0031308?t*(1.055*n**(1/2.4)-.055):12.92*e};return[i(t),i(n),i(r)]},Ie=e=>{let[t,n,r]=e,i=e=>{let t=e<0?-1:1,n=Math.abs(e);return n<=.04045?e/12.92:t*((n+.055)/1.055)**2.4};return[i(t),i(n),i(r)]},Le=e=>{let[t,n,r]=Fe(Ne([e[0],e[1],e[2]]));return[t,n,r,e[3]]},Re=e=>{let[t,n,r]=Ne([e[0],e[1],e[2]]);return[I(Math.round(t*255),0,255),I(Math.round(n*255),0,255),I(Math.round(r*255),0,255),e[3]]},ze=e=>e.type===17||e.type===15,R=e=>e.type===16||ze(e)||Be(e),Be=e=>e.type===17&&e._calcPercentage!==void 0,Ve=e=>e.type===18&&e.name===`calc`,He=e=>{let t=We(e,0);if(!t)return null;let n=We(e,100);if(!n)return null;let r=t.number,i=n.number-r;return i===0?t:{type:17,number:r,flags:4,_calcPercentage:i,_calcPixelOffset:r}},Ue=e=>Ve(e)?He(e):R(e)?e:null,We=(e,t=0)=>{let n=e=>{let r=``;for(let i of e)if(i.type!==31){if(i.type===18){if(i.name===`calc`){let e=n(i.values);if(e===null)return null;r+=`(${e})`}else return null}else if(i.type===17)r+=i.number.toString();else if(i.type===15)i.unit===`px`?r+=i.number.toString():i.unit===`rem`||i.unit===`em`?r+=(i.number*16).toString():r+=i.number.toString();else if(i.type===16)r+=(i.number/100*t).toString();else if(i.type===6){let e=i.value;e===`+`||e===`-`||e===`*`||e===`/`?r+=` ${e} `:e===`(`?r+=`(`:e===`)`&&(r+=`)`)}}return r};try{let t=n(e.values);if(t===null||t.trim()===``)return null;let r=Me(t);if(typeof r==`number`&&!isNaN(r))return{type:17,number:r,flags:4}}catch{return null}return null},Ge=e=>e.length>1?[v(e,0),v(e,1)]:[v(e,0)],z={type:17,number:0,flags:4},B={type:16,number:50,flags:4},V={type:16,number:100,flags:4},Ke=(e,t,n)=>{let[r,i]=e;return[H(r,t),H(i===void 0?r:i,n)]},H=(e,t)=>{if(Be(e))return e._calcPercentage/100*t+e._calcPixelOffset;if(e.type===16)return e.number/100*t;if(M(e))switch(e.unit){case`rem`:case`em`:return 16*e.number;default:return e.number}return e.number},qe=`deg`,Je=`grad`,Ye=`rad`,Xe=`turn`,Ze={name:`angle`,parse:(e,t)=>{if(t.type===15)switch(t.unit){case qe:return Math.PI*t.number/180;case Je:return Math.PI/200*t.number;case Ye:return t.number;case Xe:return Math.PI*2*t.number}throw Error(`Unsupported angle type`)}},Qe=e=>!(e.type!==15||e.unit!==qe&&e.unit!==Je&&e.unit!==Ye&&e.unit!==Xe),$e=e=>{switch(e.filter(P).map(e=>e.value).join(` `)){case`to bottom right`:case`to right bottom`:case`left top`:case`top left`:return[z,z];case`to top`:case`bottom`:return et(0);case`to bottom left`:case`to left bottom`:case`right top`:case`top right`:return[z,V];case`to right`:case`left`:return et(90);case`to top left`:case`to left top`:case`right bottom`:case`bottom right`:return[V,V];case`to bottom`:case`top`:return et(180);case`to top right`:case`to right top`:case`left bottom`:case`bottom left`:return[V,z];case`to left`:case`right`:return et(270)}return 0},et=e=>Math.PI*e/180,tt=e=>!(255&e),U=e=>{let t=255&e,n=255&e>>8,r=255&e>>16,i=255&e>>24;return t<255?`rgba(${i},${r},${n},${t/255})`:`rgb(${i},${r},${n})`},nt=(e,t,n,r)=>(e<<24|t<<16|n<<8|Math.round(r*255))>>>0,rt=(e,t)=>{if(e.type===17)return e.number;if(e.type===16){let n=t===3?1:255;return t===3?e.number/100*n:Math.round(e.number/100*n)}return 0},it=e=>{let t=e[0];return(t&&t.type===20?t.value:`unknown`)===`from`},at=e=>nt(I(Math.round(e[0]*255),0,255),I(Math.round(e[1]*255),0,255),I(Math.round(e[2]*255),0,255),I(e[3],0,1)),ot=e=>{let[t,n,r,i]=e,a=Fe([t,n,r]);return nt(I(Math.round(a[0]*255),0,255),I(Math.round(a[1]*255),0,255),I(Math.round(a[2]*255),0,255),i)},st=e=>{let t=Ne([e[0],e[1],e[2]]);return ot([t[0],t[1],t[2],e[3]])},ct=(e,t)=>{if(it(t.filter(F)))throw Error(`Relative color not supported for lab()`);let[n,r,i,a]=gt(t),o=Fe(Ne(wt([lt(t)?n*100:n,r,i])));return nt(I(Math.round(o[0]*255),0,255),I(Math.round(o[1]*255),0,255),I(Math.round(o[2]*255),0,255),a)},lt=e=>{let t=e.filter(F)[0];return t!==void 0&&t.type===16},ut=(e,t)=>{if(it(t.filter(F)))throw Error(`Relative color not supported for oklab()`);let[n,r,i,a]=gt(t),o=Fe(Ne(Ct([n,r,i])));return nt(I(Math.round(o[0]*255),0,255),I(Math.round(o[1]*255),0,255),I(Math.round(o[2]*255),0,255),a)},dt=(e,t)=>{if(it(t.filter(F)))throw Error(`Relative color not supported for oklch()`);let[n,r,i,a]=_t(t),o=Fe(Ne(Ct(St([n,r,i]))));return nt(I(Math.round(o[0]*255),0,255),I(Math.round(o[1]*255),0,255),I(Math.round(o[2]*255),0,255),a)},ft=(e,t)=>{if(it(t.filter(F)))throw Error(`Relative color not supported for lch()`);let[n,r,i,a]=ht(t),o=Fe(Ne(wt(St([n,r,i]))));return nt(I(Math.round(o[0]*255),0,255),I(Math.round(o[1]*255),0,255),I(Math.round(o[2]*255),0,255),a)},pt=(e,t)=>{let n=t.filter(F),r=n[0],i=n[1],a=n[2],o=n[3],s=o!==void 0&&o.type===6&&o.value===`/`?n[4]:n[3];return[r?(r.type===17?et(r.number):Ze.parse(e,r))/(Math.PI*2):0,i!==void 0&&R(i)?i.number/100:0,a!==void 0&&R(a)?a.number/100:0,s!==void 0&&R(s)?H(s,1):1]},mt=(e,t)=>{if(it(t))throw Error(`Relative color not supported for hsl()`);let[n,r,i,a]=pt(e,t),o=xt([n,r,i]);return nt(o[0]*255,o[1]*255,o[2]*255,a)},ht=e=>{let t=e.filter(F),n=t[0],r=t[1],i=t[2],a=t[4];return[n!==void 0&&R(n)?n.number:0,r!==void 0&&R(r)?r.number:0,i!==void 0&&(N(i)||M(i))?i.number:0,a!==void 0&&R(a)?H(a,1):1]},gt=e=>{let t=e.filter(F),n=t[0],r=t[1],i=t[2],a=t[4];return[n===void 0?0:n.type===16?n.number/100:N(n)?n.number:0,r===void 0?0:r.type===16?r.number/100:N(r)?r.number:0,i!==void 0&&(N(i)||M(i))?i.number:0,a!==void 0&&R(a)?H(a,1):1]},_t=e=>{let t=e.filter(F),n=t[0],r=t[1],i=t[2],a=t[4];return[n===void 0?0:n.type===16?n.number/100:N(n)?n.number:0,r===void 0?0:r.type===16?r.number/100:N(r)?r.number:0,i!==void 0&&(N(i)||M(i))?i.number:0,a!==void 0&&R(a)?H(a,1):1]},vt=e=>L([1.0479297925449969,.022946870601609652,-.05019226628920524,.02962780877005599,.9904344267538799,-.017073799063418826,-.009243040646204504,.015055191490298152,.7518742814281371],e),yt=e=>L([.955473421488075,-.02309845494876471,.06325924320057072,-.0283697093338637,1.0099953980813041,.021041441191917323,.012314014864481998,-.020507649298898964,1.330365926242124],e),bt=(e,t,n)=>(n<0&&(n+=1),n>=1&&--n,n<1/6?(t-e)*n*6+e:n<1/2?t:n<2/3?(t-e)*6*(2/3-n)+e:e),xt=([e,t,n])=>{if(t===0)return[n,n,n];let r=n<=.5?n*(t+1):n+t-n*t,i=n*2-r;return[bt(i,r,e+1/3),bt(i,r,e),bt(i,r,e-1/3)]},St=([e,t,n])=>(t<0&&(t=0),isNaN(n)&&(n=0),[e,t*Math.cos(n*Math.PI/180),t*Math.sin(n*Math.PI/180)]),Ct=e=>{let t=L([1,.3963377773761749,.2158037573099136,1,-.1055613458156586,-.0638541728258133,1,-.0894841775298119,-1.2914855480194092],e);return L([1.2268798758459243,-.5578149944602171,.2813910456659647,-.0405757452148008,1.112286803280317,-.0717110580655164,-.0763729366746601,-.4214933324022432,1.5869240198367816],[t[0]**3,t[1]**3,t[2]**3])},wt=e=>{let t=(e[0]+16)/116,n=e[1]/500+t,r=t-e[2]/200,i=24389/27,a=24/116,o=[(n>a?n**3:(116*n-16)/i)*.3457/.3585,e[0]>8?t**3:e[0]/i,(r>a?r**3:(116*r-16)/i)*.2958/.3585];return yt([o[0],o[1],o[2]])},Tt=(e,t)=>{let n=t.filter(F);if(n.length===3||n.length===4){let e=rt(v(n,0),0),t=rt(v(n,1),1),r=rt(v(n,2),2),i=n.length===4?rt(v(n,3),3):1,a=Ie([e/255,t/255,r/255]),[o,s,c]=Pe([a[0],a[1],a[2]]);return[o,s,c,i]}return[0,0,0,1]},Et=(e,t)=>{let[n,r,i,a]=pt(e,t),o=Ie(xt([n,r,i])),[s,c,l]=Pe([o[0],o[1],o[2]]);return[s,c,l,a]},Dt=(e,t)=>{let[n,r,i,a]=gt(t),[o,s,c]=wt([n,r,i]);return[o,s,c,a]},Ot=(e,t)=>{let[n,r,i,a]=ht(t),[o,s,c]=wt(St([n,r,i]));return[o,s,c,a]},kt=(e,t)=>{let[n,r,i,a]=_t(t),[o,s,c]=Ct(St([n,r,i]));return[o,s,c,a]},At=(e,t)=>{let[n,r,i,a]=gt(t),[o,s,c]=Ct([n,r,i]);return[o,s,c,a]},jt=e=>yt([e[0],e[1],e[2]]),Mt=e=>e,Nt=e=>{let[t,n,r]=vt([e[0],e[2],e[3]]);return[t,n,r,e[3]]},Pt=e=>st([e[0],e[1],e[2],e[3]]),Ft=e=>{let t=jt([e[0],e[1],e[2]]);return st([t[0],t[1],t[2],e[3]])},It=e=>L([.4865709486482162,.26566769316909306,.1982172852343625,.2289745640697488,.6917385218365064,.079286914093745,0,.04511338185890264,1.043944368900976],e),Lt=e=>L([2.493496911941425,-.9313836179191239,-.40271078445071684,-.8294889695615747,1.7626640603183463,.023624685841943577,.03584583024378447,-.07617238926804182,.9568845240076872],e),Rt=e=>{let t=e=>{let t=e<0?-1:1;return e*t<=.04045?e/12.92:t*((e+.055)/1.055)**2.4||0};return[t(e[0]),t(e[1]),t(e[2])]},zt=e=>Fe(e),Bt=e=>{let t=Rt([e[0],e[1],e[2]]);return It([t[0],t[1],t[2]])},Vt=e=>{let[t,n,r]=zt(Lt([e[0],e[1],e[2]]));return[t,n,r,e[3]]},Ht=e=>{let t=Bt([e[0],e[1],e[2]]);return st([t[0],t[1],t[2],e[3]])},Ut=e=>L([2.0415879038107465,-.5650069742788596,-.34473135077832956,-.9692436362808795,1.8759675015077202,.04155505740717557,.013444280632031142,-.11836239223101838,1.0151749943912054],e),Wt=e=>L([.5766690429101305,.1855582379065463,.1882286462349947,.29734497525053605,.6273635662554661,.0752914584939978,.02703136138641234,.07068885253582723,.9913375368376388],e),Gt=e=>{let t=e.map(e=>(e<0?-1:1)*Math.abs(e)**(563/256));return[t[0]??0,t[1]??0,t[2]??0]},Kt=e=>{let t=e.map(e=>(e<0?-1:1)*Math.abs(e)**(256/563));return[t[0]??0,t[1]??0,t[2]??0]},qt=e=>{let[t,n,r]=Kt(Ut([e[0],e[1],e[2]]));return[t,n,r,e[3]]},Jt=e=>{let t=Ne(Wt(Gt([e[0],e[1],e[2]])));return ot([t[0],t[1],t[2],e[3]])},Yt=e=>L([.7977666449006423,.13518129740053308,.0313477341283922,.2880748288194013,.711835234241873,8993693872564e-17,0,0,.8251046025104602],e),Xt=e=>L([1.3457868816471583,-.25557208737979464,-.05110186497554526,-.5446307051249019,1.5082477428451468,.02052744743642139,0,0,1.2119675456389452],e),Zt=e=>{let[t,n,r]=e,i=e=>e<16/512?e/16:e**1.8;return[i(t),i(n),i(r)]},Qt=e=>{let[t,n,r]=e,i=e=>e>1/512?e**(1/1.8):e*16;return[i(t),i(n),i(r)]},$t=e=>{let t=Zt([e[0],e[1],e[2]]);return yt(Yt([t[0],t[1],t[2]]))},en=e=>{let[t,n,r]=Qt(Xt(vt([e[0],e[1],e[2]])));return[t,n,r,e[3]]},tn=e=>{let t=$t([e[0],e[1],e[2]]);return st([t[0],t[1],t[2],e[3]])},nn=1.09929682680944,rn=.018053968510807,an=e=>{let t=e=>e<rn*4.5?e/4.5:((e+nn-1)/nn)**(1/.45);return[t(e[0]),t(e[1]),t(e[2])]},on=e=>{let t=e=>e>=rn?nn*e**.45-.09929682680944008:4.5*e;return[t(e[0]),t(e[1]),t(e[2])]},sn=e=>L([.6369580483012914,.14461690358620832,.1688809751641721,.2627002120112671,.6779980715188708,.05930171646986196,0,.028072693049087428,1.060985057710791],e),cn=e=>L([1.716651187971268,-.355670783776392,-.25336628137366,-.666684351832489,1.616481236634939,.0157685458139111,.017639857445311,-.042770613257809,.942103121235474],e),ln=e=>{let t=an([e[0],e[1],e[2]]);return sn([t[0],t[1],t[2]])},un=e=>{let[t,n,r]=on(cn([e[0],e[1],e[2]]));return[t,n,r,e[3]]},dn=e=>{let t=ln([e[0],e[1],e[2]]);return st([t[0],t[1],t[2],e[3]])},fn={lch:2,oklch:2,hsl:0},pn=[1.2268798758459243,-.5578149944602171,.2813910456659647,-.0405757452148008,1.112286803280317,-.0717110580655164,-.0763729366746601,-.4214933324022432,1.5869240198367816],mn=[1,.3963377773761749,.2158037573099136,1,-.1055613458156586,-.0638541728258133,1,-.0894841775298119,-1.2914855480194092],hn=e=>{let t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],o=e[5],s=e[6],c=e[7],l=e[8],u=t*(a*l-o*c)-n*(i*l-o*s)+r*(i*c-a*s);return[(a*l-o*c)/u,(r*c-n*l)/u,(n*o-r*a)/u,(o*s-i*l)/u,(t*l-r*s)/u,(r*i-t*o)/u,(i*c-a*s)/u,(n*s-t*c)/u,(t*a-n*i)/u]},gn=hn(pn),_n=hn(mn),vn=24389/27,yn=24/116,bn=yn*yn*yn,xn=.3457/.3585,Sn=.2958/.3585,Cn=e=>[(255&e>>24)/255,(255&e>>16)/255,(255&e>>8)/255],wn=e=>{let[t,n,r]=vt([e[0],e[1],e[2]]),i=t/xn,a=n,o=r/Sn,s=i>bn?Math.cbrt(i):(vn*i+16)/116,c=a>bn?Math.cbrt(a):(vn*a+16)/116,l=o>bn?Math.cbrt(o):(vn*o+16)/116;return[116*c-16,500*(s-c),200*(c-l)]},Tn=e=>{let t=L(gn,e);return L(_n,[Math.cbrt(t[0]),Math.cbrt(t[1]),Math.cbrt(t[2])])},En=e=>{let t=Math.hypot(e[1],e[2]),n=Math.atan2(e[2],e[1])*180/Math.PI;return[e[0],t,(n+360)%360]},Dn=e=>{let t=e[0],n=e[1],r=e[2],i=Math.max(t,n,r),a=Math.min(t,n,r),o=(i+a)/2;if(i===a)return[0,0,o];let s=i-a,c=o>.5?s/(2-i-a):s/(i+a),l;return l=i===t?((n-r)/s+(n<r?6:0))/6:i===n?((r-t)/s+2)/6:((t-n)/s+4)/6,[l,c,o]},On=(e,t)=>{let n=(255&e)/255,r=Cn(e),i=Ie(r),a=Pe(i),o;switch(t){case`srgb`:o=r;break;case`srgb-linear`:o=i;break;case`xyz`:case`xyz-d65`:o=a;break;case`xyz-d50`:o=vt(a);break;case`lab`:o=wn(a);break;case`oklab`:o=Tn(a);break;case`lch`:o=En(wn(a));break;case`oklch`:o=En(Tn(a));break;case`hsl`:o=[Dn(r)[0]*360,Dn(r)[1],Dn(r)[2]]}return[o[0],o[1],o[2],n]},kn=(e,t)=>{let n=e[0],r=e[1],i=e[2],a=e[3];switch(t){case`srgb`:return at([n,r,i,a]);case`srgb-linear`:return ot([n,r,i,a]);case`xyz`:case`xyz-d65`:return st([n,r,i,a]);case`xyz-d50`:return st([...yt([n,r,i]),a]);case`lab`:return An(wt([n,r,i]),a);case`oklab`:return An(Ct([n,r,i]),a);case`lch`:return An(wt(St([n,r,i])),a);case`oklch`:return An(Ct(St([n,r,i])),a);case`hsl`:{let e=xt([n/360,r,i]);return at([e[0],e[1],e[2],a])}}},An=(e,t)=>{let n=Fe(Ne(e));return at([n[0],n[1],n[2],t])},jn=(e,t,n,r,i=`shorter`)=>{let a=n+r;if(a===0)return e;let o=((t-e)%360+360)%360;switch(i){case`shorter`:o>180&&(o-=360);break;case`longer`:o<180&&(o-=360);break;case`increasing`:break;case`decreasing`:o>0&&(o-=360)}return e+r/a*o},Mn=(e,t)=>{let n,r=null;for(let e of t)if(e.type!==31&&e.type!==4){if(e.type===16)r=e.number;else if(P(e)&&e.value===`none`)r===null&&(r=0);else if(n===void 0)n=e;else throw Error(`Unexpected token in color-mix() component`)}if(n===void 0)throw Error(`color-mix() component is missing a color`);let i=n;return{color:W.parse(e,i),percentage:r}},Nn=[`srgb`,`srgb-linear`,`lab`,`oklab`,`lch`,`oklch`,`hsl`,`xyz`,`xyz-d50`,`xyz-d65`],Pn=(e,t,n,r,i,a)=>{let o=fn[i],s=[e[0]*e[3],e[1]*e[3],e[2]*e[3],e[3]],c=[t[0]*t[3],t[1]*t[3],t[2]*t[3],t[3]],l=n*s[3]+r*c[3];if(l<=0)return[0,0,0,0];let u=[0,0,0,l];for(let e=0;e<3;e++)e!==o&&(u[e]=(n*v(s,e)+r*v(c,e))/l);if(o!==void 0){let i=v(e,o),s=v(t,o);e[1]===0&&(i=s),t[1]===0&&(s=i),u[o]=jn(i,s,n,r,a)}return u},Fn=(e,t)=>{let n=[[]];for(let e of t)e.type===4?n.push([]):n[n.length-1].push(e);let r=n.map(e=>e.filter(e=>e.type!==31));if(r.length!==3)throw Error(`color-mix() requires exactly two color components`);let i=r[0],a=i?i[0]:void 0,o=a!==void 0&&P(a)&&a.value===`in`;if(!i||i.length<2||!o)throw Error("color-mix() requires an interpolation space after `in`");let s=i[1];if(!s||!P(s))throw Error(`color-mix() space must be an identifier`);let c=s.value;if(Nn.indexOf(c)===-1)throw Error(`Unsupported color-mix() interpolation space "${c}"`);let l=`shorter`,u=i.slice(2);if(u.length>0){let e=u[0],t=u[1];if(!e||!t||!P(e)||!P(t)||t.value!==`hue`)throw Error(`Unsupported color-mix() hue method syntax`);if([`shorter`,`longer`,`increasing`,`decreasing`].indexOf(e.value)===-1)throw Error(`Unsupported color-mix() hue method "${e.value}"`);l=e.value}let d=r[1],f=r[2];if(!d||!f)throw Error(`color-mix() requires exactly two color components`);let p=Mn(e,d),m=Mn(e,f),h=p.percentage,g=m.percentage;if(h===null&&g===null)h=50,g=50;else if(h===null)h=100-(g??0);else if(g===null)g=100-h;else{let e=h+g;e>0&&(h=h/e*100,g=g/e*100)}let _=(h??0)/100,v=(g??0)/100;return kn(Pn(On(p.color,c),On(m.color,c),_,v,c,l),c)},In=(e,t)=>{try{return Fn(e,t)}catch(t){return e.logger.warn(`Unsupported color-mix() value: ${t instanceof Error?t.message:t}`),0}},W={name:`color`,parse:(e,t)=>{if(t.type===18){let n=Un[t.name];if(n===void 0)throw Error(`Attempting to parse an unsupported color function "${t.name}"`);return n(e,t.values)}if(t.type===5){let[e,n,r,i]=Ln(t);return nt(e,n,r,i)}if(t.type===20){let e=Gn[t.value.toUpperCase()];if(e!==void 0)return e}return 0}},Ln=e=>{if(e.value.length===3){let t=e.value.substring(0,1),n=e.value.substring(1,2),r=e.value.substring(2,3);return[parseInt(t+t,16),parseInt(n+n,16),parseInt(r+r,16),1]}if(e.value.length===4){let t=e.value.substring(0,1),n=e.value.substring(1,2),r=e.value.substring(2,3),i=e.value.substring(3,4);return[parseInt(t+t,16),parseInt(n+n,16),parseInt(r+r,16),parseInt(i+i,16)/255]}if(e.value.length===6){let t=e.value.substring(0,2),n=e.value.substring(2,4),r=e.value.substring(4,6);return[parseInt(t,16),parseInt(n,16),parseInt(r,16),1]}if(e.value.length===8){let t=e.value.substring(0,2),n=e.value.substring(2,4),r=e.value.substring(4,6),i=e.value.substring(6,8);return[parseInt(t,16),parseInt(n,16),parseInt(r,16),parseInt(i,16)/255]}return[0,0,0,1]},Rn=(e,t)=>{let n=t.filter(F);if(it(n))throw Error(`Relative color not supported for rgb()`);if(n.length===3||n.length===4)return nt(rt(v(n,0),0),rt(v(n,1),1),rt(v(n,2),2),n.length===4?rt(v(n,3),3):1);if(n.length===5){let e=v(n,3);if(e.type===6&&e.value===`/`)return nt(rt(v(n,0),0),rt(v(n,1),1),rt(v(n,2),2),rt(v(n,4),3))}return 0},zn=(e,t)=>{let n=t.filter(F),r=n[0],i=r&&r.type===20?r.value:`unknown`;if(it(n)){let t=(e,t)=>{if(N(t))return t.number;let n=e=>e===`r`||e===`x`?0:e===`g`||e===`y`?1:2;if(P(t))return v(e,n(t.value));let r=e=>{let t=e.filter(F),n=`(`;for(let e of t)n+=e.type===18&&e.name===`calc`?r(e.values):N(e)?e.number:e.type===6||P(e)?e.value:``;return n+=`)`,n};if(t.type===18){let n=t.values.filter(F);if(t.name===`calc`)return Me(r(n).replace(/r|x/,e[0].toString()).replace(/g|y/,e[1].toString()).replace(/b|z/,e[2].toString()))}return null},r=v(n,1),i=r.type===18?r.name:P(r)||r.type===5?`rgb`:`unknown`,a=v(n,2),o=P(a)?a.value:`unknown`,s=r.type===18?r.values:P(r)?[r]:[];if(P(r)){if(Gn[r.value.toUpperCase()]===void 0)throw Error(`Attempting to use unknown color in relative color 'from'`);{let t=Wn(e,r.value),n=255&t,i=255&t>>8,a=255&t>>16;s=[{type:17,number:255&t>>24,flags:1},{type:17,number:a,flags:1},{type:17,number:i,flags:1},{type:17,number:n>1?n/255:n,flags:1}]}}else if(r.type===5){let[e,t,n,i]=Ln(r);s=[{type:17,number:e,flags:1},{type:17,number:t,flags:1},{type:17,number:n,flags:1},{type:17,number:i>1?i/255:i,flags:1}]}if(s.length===0)throw Error(`Attempting to use unknown color in relative color 'from'`);if(o===`unknown`)throw Error(`Attempting to use unknown colorspace in relative color 'to'`);let c=Vn[i],l=Hn[o],u=Bn[o];if(c===void 0)throw Error(`Attempting to parse an unsupported color space "${i}" for color() function`);if(l===void 0)throw Error(`Attempting to parse an unsupported color space "${o}" for color() function`);let d=l(c(e,s)),f=t(d,v(n,3)),p=t(d,v(n,4)),m=t(d,v(n,5)),h=n[6],g=n[7],_=h!==void 0&&h.type===6&&h.value===`/`&&g!==void 0&&N(g)?g.number:1;if(f===null||p===null||m===null)throw Error(`Invalid relative color in color() function`);if(u===void 0)throw Error(`Attempting to parse an unsupported color space "${o}" for color() function`);return u([f,p,m,_])}{let e=i,t=Bn[e];if(t===void 0)throw Error(`Attempting to parse an unsupported color space "${e}" for color() function`);let r=v(n,1),a=v(n,2),o=v(n,3),s=n[4],c=n[5];return t([N(r)?r.number:0,N(a)?a.number:0,N(o)?o.number:0,s!==void 0&&s.type===6&&s.value===`/`&&c!==void 0&&N(c)?c.number:1])}},Bn={srgb:at,"srgb-linear":ot,"display-p3":Ht,"a98-rgb":Jt,"prophoto-rgb":tn,xyz:Pt,"xyz-d50":Ft,"xyz-d65":Pt,rec2020:dn},Vn={rgb:Tt,hsl:Et,lab:Dt,lch:Ot,oklab:At,oklch:kt},Hn={srgb:Le,"srgb-linear":Re,"display-p3":Vt,"a98-rgb":qt,"prophoto-rgb":en,xyz:Mt,"xyz-d50":Nt,"xyz-d65":Mt,rec2020:un},Un={hsl:mt,hsla:mt,rgb:Rn,rgba:Rn,lch:ft,oklch:dt,oklab:ut,lab:ct,color:zn,"color-mix":In},Wn=(e,t)=>W.parse(e,Te.create(t).parseComponentValue()),Gn={ALICEBLUE:4042850303,ANTIQUEWHITE:4209760255,AQUA:16777215,AQUAMARINE:2147472639,AZURE:4043309055,BEIGE:4126530815,BISQUE:4293182719,BLACK:255,BLANCHEDALMOND:4293643775,BLUE:65535,BLUEVIOLET:2318131967,BROWN:2771004159,BURLYWOOD:3736635391,CADETBLUE:1604231423,CHARTREUSE:2147418367,CHOCOLATE:3530104575,CORAL:4286533887,CORNFLOWERBLUE:1687547391,CORNSILK:4294499583,CRIMSON:3692313855,CYAN:16777215,DARKBLUE:35839,DARKCYAN:9145343,DARKGOLDENROD:3095837695,DARKGRAY:2846468607,DARKGREEN:6553855,DARKGREY:2846468607,DARKKHAKI:3182914559,DARKMAGENTA:2332068863,DARKOLIVEGREEN:1433087999,DARKORANGE:4287365375,DARKORCHID:2570243327,DARKRED:2332033279,DARKSALMON:3918953215,DARKSEAGREEN:2411499519,DARKSLATEBLUE:1211993087,DARKSLATEGRAY:793726975,DARKSLATEGREY:793726975,DARKTURQUOISE:13554175,DARKVIOLET:2483082239,DEEPPINK:4279538687,DEEPSKYBLUE:12582911,DIMGRAY:1768516095,DIMGREY:1768516095,DODGERBLUE:512819199,FIREBRICK:2988581631,FLORALWHITE:4294635775,FORESTGREEN:579543807,FUCHSIA:4278255615,GAINSBORO:3705462015,GHOSTWHITE:4177068031,GOLD:4292280575,GOLDENROD:3668254975,GRAY:2155905279,GREEN:8388863,GREENYELLOW:2919182335,GREY:2155905279,HONEYDEW:4043305215,HOTPINK:4285117695,INDIANRED:3445382399,INDIGO:1258324735,IVORY:4294963455,KHAKI:4041641215,LAVENDER:3873897215,LAVENDERBLUSH:4293981695,LAWNGREEN:2096890111,LEMONCHIFFON:4294626815,LIGHTBLUE:2916673279,LIGHTCORAL:4034953471,LIGHTCYAN:3774873599,LIGHTGOLDENRODYELLOW:4210742015,LIGHTGRAY:3553874943,LIGHTGREEN:2431553791,LIGHTGREY:3553874943,LIGHTPINK:4290167295,LIGHTSALMON:4288707327,LIGHTSEAGREEN:548580095,LIGHTSKYBLUE:2278488831,LIGHTSLATEGRAY:2005441023,LIGHTSLATEGREY:2005441023,LIGHTSTEELBLUE:2965692159,LIGHTYELLOW:4294959359,LIME:16711935,LIMEGREEN:852308735,LINEN:4210091775,MAGENTA:4278255615,MAROON:2147483903,MEDIUMAQUAMARINE:1724754687,MEDIUMBLUE:52735,MEDIUMORCHID:3126187007,MEDIUMPURPLE:2473647103,MEDIUMSEAGREEN:1018393087,MEDIUMSLATEBLUE:2070474495,MEDIUMSPRINGGREEN:16423679,MEDIUMTURQUOISE:1221709055,MEDIUMVIOLETRED:3340076543,MIDNIGHTBLUE:421097727,MINTCREAM:4127193855,MISTYROSE:4293190143,MOCCASIN:4293178879,NAVAJOWHITE:4292783615,NAVY:33023,OLDLACE:4260751103,OLIVE:2155872511,OLIVEDRAB:1804477439,ORANGE:4289003775,ORANGERED:4282712319,ORCHID:3664828159,PALEGOLDENROD:4008225535,PALEGREEN:2566625535,PALETURQUOISE:2951671551,PALEVIOLETRED:3681588223,PAPAYAWHIP:4293907967,PEACHPUFF:4292524543,PERU:3448061951,PINK:4290825215,PLUM:3718307327,POWDERBLUE:2967529215,PURPLE:2147516671,REBECCAPURPLE:1714657791,RED:4278190335,ROSYBROWN:3163525119,ROYALBLUE:1097458175,SADDLEBROWN:2336560127,SALMON:4202722047,SANDYBROWN:4104413439,SEAGREEN:780883967,SEASHELL:4294307583,SIENNA:2689740287,SILVER:3233857791,SKYBLUE:2278484991,SLATEBLUE:1784335871,SLATEGRAY:1887473919,SLATEGREY:1887473919,SNOW:4294638335,SPRINGGREEN:16744447,STEELBLUE:1182971135,TAN:3535047935,TEAL:8421631,THISTLE:3636451583,TOMATO:4284696575,TRANSPARENT:0,TURQUOISE:1088475391,VIOLET:4001558271,WHEAT:4125012991,WHITE:4294967295,WHITESMOKE:4126537215,YELLOW:4294902015,YELLOWGREEN:2597139199},Kn=e=>e.nodeType===Node.ELEMENT_NODE,qn=e=>e.nodeType===Node.TEXT_NODE,Jn=e=>typeof e.className==`object`,Yn=e=>Kn(e)&&e.style!==void 0&&!Jn(e),Xn=e=>e.tagName===`INPUT`,Zn=e=>e.tagName===`HTML`,Qn=e=>e.tagName===`svg`,$n=e=>e.tagName===`BODY`,er=e=>e.tagName===`CANVAS`,tr=e=>e.tagName===`VIDEO`,nr=e=>e.tagName===`IMG`,rr=e=>e.tagName===`IFRAME`,ir=e=>e.tagName===`STYLE`,ar=e=>e.tagName===`SCRIPT`,or=e=>e.tagName===`TEXTAREA`,sr=e=>e.tagName===`SELECT`,cr=e=>e.tagName===`SLOT`,lr=e=>e.tagName===`LI`,ur=e=>e.tagName===`OL`,dr=e=>!Jn(e)&&e.tagName.indexOf(`-`)>0,fr=new Set([`IMG`,`VIDEO`,`AUDIO`,`CANVAS`,`IFRAME`,`INPUT`,`TEXTAREA`,`SELECT`,`BR`,`HR`,`META`,`LINK`,`BASE`,`COL`,`SOURCE`,`TRACK`,`WBR`,`AREA`,`PARAM`,`EMBED`,`OBJECT`]),pr=e=>!Jn(e)&&!fr.has(e.tagName),mr={name:`list-style-type`,initialValue:`none`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`disc`:return 0;case`circle`:return 1;case`square`:return 2;case`decimal`:return 3;case`cjk-decimal`:return 4;case`decimal-leading-zero`:return 5;case`lower-roman`:return 6;case`upper-roman`:return 7;case`lower-greek`:return 8;case`lower-alpha`:return 9;case`upper-alpha`:return 10;case`arabic-indic`:return 11;case`armenian`:return 12;case`bengali`:return 13;case`cambodian`:return 14;case`cjk-earthly-branch`:return 15;case`cjk-heavenly-stem`:return 16;case`cjk-ideographic`:return 17;case`devanagari`:return 18;case`ethiopic-numeric`:return 19;case`georgian`:return 20;case`gujarati`:return 21;case`gurmukhi`:return 22;case`hebrew`:return 52;case`hiragana`:return 23;case`hiragana-iroha`:return 24;case`japanese-formal`:return 25;case`japanese-informal`:return 26;case`kannada`:return 27;case`katakana`:return 28;case`katakana-iroha`:return 29;case`khmer`:return 30;case`korean-hangul-formal`:return 31;case`korean-hanja-formal`:return 32;case`korean-hanja-informal`:return 33;case`lao`:return 34;case`lower-armenian`:return 35;case`malayalam`:return 36;case`mongolian`:return 37;case`myanmar`:return 38;case`oriya`:return 39;case`persian`:return 40;case`simp-chinese-formal`:return 41;case`simp-chinese-informal`:return 42;case`tamil`:return 43;case`telugu`:return 44;case`thai`:return 45;case`tibetan`:return 46;case`trad-chinese-formal`:return 47;case`trad-chinese-informal`:return 48;case`upper-armenian`:return 49;case`disclosure-open`:return 50;case`disclosure-closed`:return 51;default:return-1}}},G=(e,t)=>(e&t)!==0,hr=class{counters={};getCounterValue(e){let t=this.counters[e];return t&&t.length?v(t,t.length-1):1}getCounterValues(e){return this.counters[e]||[]}pop(e){e.forEach(e=>this.counters[e]?.pop())}parse(e){let t=e.counterIncrement,n=e.counterReset,r=!0;t!==null&&t.forEach(e=>{let t=this.counters[e.counter];if(t&&e.increment!==0){r=!1,t.length||t.push(1);let n=Math.max(0,t.length-1);t[n]=(t[n]??0)+e.increment}});let i=[];return r&&n.forEach(e=>{let t=this.counters[e.counter];i.push(e.counter),t||=this.counters[e.counter]=[],t.push(e.reset)}),i}},gr={integers:[1e3,900,500,400,100,90,50,40,10,9,5,4,1],values:[`M`,`CM`,`D`,`CD`,`C`,`XC`,`L`,`XL`,`X`,`IX`,`V`,`IV`,`I`]},_r={integers:[9e3,8e3,7e3,6e3,5e3,4e3,3e3,2e3,1e3,900,800,700,600,500,400,300,200,100,90,80,70,60,50,40,30,20,10,9,8,7,6,5,4,3,2,1],values:`Ք.Փ.Ւ.Ց.Ր.Տ.Վ.Ս.Ռ.Ջ.Պ.Չ.Ո.Շ.Ն.Յ.Մ.Ճ.Ղ.Ձ.Հ.Կ.Ծ.Խ.Լ.Ի.Ժ.Թ.Ը.Է.Զ.Ե.Դ.Գ.Բ.Ա`.split(`.`)},vr={integers:[1e4,9e3,8e3,7e3,6e3,5e3,4e3,3e3,2e3,1e3,400,300,200,100,90,80,70,60,50,40,30,20,19,18,17,16,15,10,9,8,7,6,5,4,3,2,1],values:`י׳.ט׳.ח׳.ז׳.ו׳.ה׳.ד׳.ג׳.ב׳.א׳.ת.ש.ר.ק.צ.פ.ע.ס.נ.מ.ל.כ.יט.יח.יז.טז.טו.י.ט.ח.ז.ו.ה.ד.ג.ב.א`.split(`.`)},yr={integers:[1e4,9e3,8e3,7e3,6e3,5e3,4e3,3e3,2e3,1e3,900,800,700,600,500,400,300,200,100,90,80,70,60,50,40,30,20,10,9,8,7,6,5,4,3,2,1],values:`ჵ.ჰ.ჯ.ჴ.ხ.ჭ.წ.ძ.ც.ჩ.შ.ყ.ღ.ქ.ფ.ჳ.ტ.ს.რ.ჟ.პ.ო.ჲ.ნ.მ.ლ.კ.ი.თ.ჱ.ზ.ვ.ე.დ.გ.ბ.ა`.split(`.`)},br=(e,t,n,r,i,a)=>e<t||e>n?Mr(e,i,a.length>0):r.integers.reduce((t,n,i)=>{for(;e>=n;)e-=n,t+=r.values[i];return t},``)+a,xr=(e,t,n,r)=>{let i=``;do n||e--,i=r(e)+i,e/=t;while(e*t>=t);return i},K=(e,t,n,r,i)=>{let a=n-t+1;return(e<0?`-`:``)+(xr(Math.abs(e),a,r,e=>String.fromCodePoint(Math.floor(e%a)+t))+i)},Sr=(e,t,n=`. `)=>{let r=t.length;return xr(Math.abs(e),r,!1,e=>String(t[Math.floor(e%r)]))+n},Cr=1,wr=2,Tr=4,Er=8,Dr=(e,t,n,r,i,a)=>{if(e<-9999||e>9999)return Mr(e,4,i.length>0);let o=Math.abs(e),s=i;if(o===0)return t[0]+s;for(let r=0;o>0&&r<=4;r++){let i=o%10;i===0&&G(a,Cr)&&s!==``?s=t[i]+s:i>1||i===1&&r===0||i===1&&r===1&&G(a,wr)||i===1&&r===1&&G(a,Tr)&&e>100||i===1&&r>1&&G(a,Er)?s=(t[i]??``)+(r>0?n[r-1]??``:``)+s:i===1&&r>0&&(s=(n[r-1]??``)+s),o=Math.floor(o/10)}return(e<0?r:``)+s},Or=`十百千萬`,kr=`拾佰仟萬`,Ar=`マイナス`,jr=`마이너스`,Mr=(e,t,n)=>{let r=n?`. `:``,i=n?`、`:``,a=n?`, `:``,o=n?` `:``;switch(t){case 0:return`•`+o;case 1:return`◦`+o;case 2:return`◾`+o;case 5:let t=K(e,48,57,!0,r);return t.length<4?`0${t}`:t;case 4:return Sr(e,`〇一二三四五六七八九`,i);case 6:return br(e,1,3999,gr,3,r).toLowerCase();case 7:return br(e,1,3999,gr,3,r);case 8:return K(e,945,969,!1,r);case 9:return K(e,97,122,!1,r);case 10:return K(e,65,90,!1,r);case 11:return K(e,1632,1641,!0,r);case 12:case 49:return br(e,1,9999,_r,3,r);case 35:return br(e,1,9999,_r,3,r).toLowerCase();case 13:return K(e,2534,2543,!0,r);case 14:case 30:return K(e,6112,6121,!0,r);case 15:return Sr(e,`子丑寅卯辰巳午未申酉戌亥`,i);case 16:return Sr(e,`甲乙丙丁戊己庚辛壬癸`,i);case 17:case 48:return Dr(e,`零一二三四五六七八九`,Or,`負`,i,14);case 47:return Dr(e,`零壹貳參肆伍陸柒捌玖`,kr,`負`,i,15);case 42:return Dr(e,`零一二三四五六七八九`,Or,`负`,i,14);case 41:return Dr(e,`零壹贰叁肆伍陆柒捌玖`,kr,`负`,i,15);case 26:return Dr(e,`〇一二三四五六七八九`,`十百千万`,Ar,i,0);case 25:return Dr(e,`零壱弐参四伍六七八九`,`拾百千万`,Ar,i,7);case 31:return Dr(e,`영일이삼사오육칠팔구`,`십백천만`,jr,a,7);case 33:return Dr(e,`零一二三四五六七八九`,`十百千萬`,jr,a,0);case 32:return Dr(e,`零壹貳參四五六七八九`,`拾百千`,jr,a,7);case 18:return K(e,2406,2415,!0,r);case 20:return br(e,1,19999,yr,3,r);case 21:return K(e,2790,2799,!0,r);case 22:return K(e,2662,2671,!0,r);case 52:return br(e,1,10999,vr,3,r);case 23:return Sr(e,`あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわゐゑをん`);case 24:return Sr(e,`いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせす`);case 27:return K(e,3302,3311,!0,r);case 28:return Sr(e,`アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヰヱヲン`,i);case 29:return Sr(e,`イロハニホヘトチリヌルヲワカヨタレソツネナラムウヰノオクヤマケフコエテアサキユメミシヱヒモセス`,i);case 34:return K(e,3792,3801,!0,r);case 37:return K(e,6160,6169,!0,r);case 38:return K(e,4160,4169,!0,r);case 39:return K(e,2918,2927,!0,r);case 40:return K(e,1776,1785,!0,r);case 43:return K(e,3046,3055,!0,r);case 44:return K(e,3174,3183,!0,r);case 45:return K(e,3664,3673,!0,r);case 46:return K(e,3872,3881,!0,r);default:return K(e,48,57,!0,r)}},Nr={name:`display`,initialValue:`inline-block`,prefix:!1,type:1,parse:(e,t)=>t.filter(P).reduce((e,t)=>e|Pr(t.value),0)},Pr=e=>{switch(e){case`block`:case`-webkit-box`:return 2;case`inline`:return 4;case`run-in`:return 8;case`flow`:return 16;case`flow-root`:return 32;case`table`:return 64;case`flex`:case`-webkit-flex`:return 128;case`grid`:case`-ms-grid`:return 256;case`ruby`:return 512;case`subgrid`:return 1024;case`list-item`:return 2048;case`table-row-group`:return 4096;case`table-header-group`:return 8192;case`table-footer-group`:return 16384;case`table-row`:return 32768;case`table-cell`:return 65536;case`table-column-group`:return 131072;case`table-column`:return 262144;case`table-caption`:return 524288;case`ruby-base`:return 1048576;case`ruby-text`:return 2097152;case`ruby-base-container`:return 4194304;case`ruby-text-container`:return 8388608;case`contents`:return 16777216;case`inline-block`:return 33554432;case`inline-list-item`:return 67108864;case`inline-table`:return 134217728;case`inline-flex`:return 268435456;case`inline-grid`:return 536870912}return 0},Fr={name:`float`,initialValue:`none`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`left`:return 1;case`right`:return 2;case`inline-start`:return 3;case`inline-end`:return 4}return 0}},Ir={name:`overflow`,initialValue:`visible`,prefix:!1,type:1,parse:(e,t)=>t.filter(P).map(e=>{switch(e.value){case`hidden`:return 1;case`scroll`:return 2;case`clip`:return 3;case`auto`:return 4;default:return 0}})},Lr={name:`text-decoration-color`,initialValue:`transparent`,prefix:!1,type:3,format:`color`},Rr={name:`text-decoration-line`,initialValue:`none`,prefix:!1,type:1,parse:(e,t)=>t.filter(P).map(e=>{switch(e.value){case`underline`:return 1;case`overline`:return 2;case`line-through`:return 3;case`none`:return 4}return 0}).filter(e=>e!==0)},zr={name:`content`,initialValue:`none`,type:1,prefix:!1,parse:(e,t)=>{if(t.length===0)return[];let n=t[0];return n&&n.type===20&&n.value===`none`?[]:t}},Br={name:`quotes`,initialValue:`none`,prefix:!0,type:1,parse:(e,t)=>{if(t.length===0)return null;let n=t[0];if(n&&n.type===20&&n.value===`none`)return null;let r=[],i=t.filter(Ee);if(i.length%2!=0)return null;for(let e=0;e<i.length;e+=2){let t=v(i,e).value,n=v(i,e+1).value;r.push({open:t,close:n})}return r}},Vr=(e,t,n)=>{if(!e)return``;let r=e[Math.min(t,e.length-1)];return r?n?r.open:r.close:``},Hr=(e,t)=>{let n=[],r=e.filter(Oe);for(let e=0;e<r.length;e++){let i=r[e],a=r[e+1];if(i&&i.type===20){let e=a&&N(a)?a.number:t;n.push([i.value,e])}}return n},Ur={name:`counter-increment`,initialValue:`none`,prefix:!0,type:1,parse:(e,t)=>{if(t.length===0)return null;let n=t[0];return n&&n.type===20&&n.value===`none`?null:Hr(t,1).map(([e,t])=>({counter:e,increment:t}))}},Wr={name:`counter-reset`,initialValue:`none`,prefix:!0,type:1,parse:(e,t)=>t.length===0?[]:Hr(t,0).filter(([e])=>e!==`none`).map(([e,t])=>({counter:e,reset:t}))},Gr={name:`background-clip`,initialValue:`border-box`,prefix:!1,type:1,parse:(e,t)=>t.map(e=>{if(P(e))switch(e.value){case`padding-box`:return 1;case`content-box`:return 2;case`text`:return 3}return 0})},Kr={name:`background-color`,initialValue:`transparent`,prefix:!1,type:3,format:`color`},qr=(e,t)=>{let n=W.parse(e,v(t,0)),r=t[1];return r&&R(r)?{color:n,stop:r}:{color:n,stop:null}},Jr=(e,t)=>{let n=e.map(e=>({color:e.color,stop:e.stop})),r=v(n,0),i=v(n,n.length-1);r.stop===null&&(r.stop=z),i.stop===null&&(i.stop=V);let a=[],o=0;for(let e=0;e<n.length;e++){let r=v(n,e).stop;if(r!==null){let e=H(r,t);e>o?a.push(e):a.push(o),o=e}else a.push(null)}let s=null;for(let e=0;e<a.length;e++){let t=v(a,e);if(t===null)s===null&&(s=e);else if(s!==null){let n=e-s,r=(t-a[s-1])/(n+1);for(let e=1;e<=n;e++)a[s+e-1]=r*e;s=null}}return n.map(({color:e},n)=>({color:e,stop:Math.max(Math.min(1,a[n]/t),0)}))},Yr=(e,t,n)=>{let r=t/2,i=n/2,a=H(e[0],t)-r,o=i-H(e[1],n);return(Math.atan2(o,a)+Math.PI*2)%(Math.PI*2)},Xr=(e,t,n)=>{let r=typeof e==`number`?e:Yr(e,t,n),i=Math.abs(t*Math.sin(r))+Math.abs(n*Math.cos(r)),a=t/2,o=n/2,s=i/2,c=Math.sin(r-Math.PI/2)*s,l=Math.cos(r-Math.PI/2)*s;return[i,a-l,a+l,o-c,o+c]},Zr=(e,t)=>Math.sqrt(e*e+t*t),Qr=(e,t,n,r,i)=>[[0,0],[0,t],[e,0],[e,t]].reduce((e,t)=>{let[a,o]=t,s=Zr(n-a,r-o);return(i?s<e.optimumDistance:s>e.optimumDistance)?{optimumCorner:t,optimumDistance:s}:e},{optimumDistance:i?1/0:-1/0,optimumCorner:null}).optimumCorner,$r=(e,t,n,r,i)=>{let a=0,o=0;switch(e.size){case 0:e.shape===0?a=o=Math.min(Math.abs(t),Math.abs(t-r),Math.abs(n),Math.abs(n-i)):e.shape===1&&(a=Math.min(Math.abs(t),Math.abs(t-r)),o=Math.min(Math.abs(n),Math.abs(n-i)));break;case 2:if(e.shape===0)a=o=Math.min(Zr(t,n),Zr(t,n-i),Zr(t-r,n),Zr(t-r,n-i));else if(e.shape===1){let e=Math.min(Math.abs(n),Math.abs(n-i))/Math.min(Math.abs(t),Math.abs(t-r)),[s,c]=Qr(r,i,t,n,!0);a=Zr(s-t,(c-n)/e),o=e*a}break;case 1:e.shape===0?a=o=Math.max(Math.abs(t),Math.abs(t-r),Math.abs(n),Math.abs(n-i)):e.shape===1&&(a=Math.max(Math.abs(t),Math.abs(t-r)),o=Math.max(Math.abs(n),Math.abs(n-i)));break;case 3:if(e.shape===0)a=o=Math.max(Zr(t,n),Zr(t,n-i),Zr(t-r,n),Zr(t-r,n-i));else if(e.shape===1){let e=Math.max(Math.abs(n),Math.abs(n-i))/Math.max(Math.abs(t),Math.abs(t-r)),[s,c]=Qr(r,i,t,n,!1);a=Zr(s-t,(c-n)/e),o=e*a}}if(Array.isArray(e.size)){let t=e.size;a=H(v(t,0),r),o=t.length===2?H(v(t,1),i):a}return[a,o]},ei=(e,t)=>{let n=et(180),r=[];return ke(t).forEach((t,i)=>{if(i===0){let r=t[0];if(r&&r.type===20&&r.value===`to`){n=$e(t);return}if(r&&Qe(r)){n=Ze.parse(e,r);return}}let a=qr(e,t);r.push(a)}),{angle:n,stops:r,type:1}},ti=(e,t)=>{let n=et(180),r=[];return ke(t).forEach((t,i)=>{if(i===0){let r=t[0];if(r&&r.type===20&&[`top`,`left`,`right`,`bottom`].indexOf(r.value)!==-1){n=$e(t);return}if(r&&Qe(r)){n=(Ze.parse(e,r)+et(270))%et(360);return}}let a=qr(e,t);r.push(a)}),{angle:n,stops:r,type:1}},ni=(e,t)=>{let n=et(180),r=[],i=1;return ke(t).forEach((t,n)=>{let a=t[0];if(a){if(n===0){if(P(a)&&a.value===`linear`){i=1;return}if(P(a)&&a.value===`radial`){i=2;return}}if(a.type===18){if(a.name===`from`){let t=W.parse(e,v(a.values,0));r.push({stop:z,color:t})}else if(a.name===`to`){let t=W.parse(e,v(a.values,0));r.push({stop:V,color:t})}else if(a.name===`color-stop`){let t=a.values.filter(F);if(t.length===2){let n=W.parse(e,v(t,1)),i=v(t,0);N(i)&&r.push({stop:{type:16,number:i.number*100,flags:i.flags},color:n})}}}}}),i===1?{angle:(n+et(180))%et(360),stops:r,type:i}:{size:3,shape:0,stops:r,position:[],type:i}},ri=`closest-side`,ii=`farthest-side`,ai=`closest-corner`,oi=`farthest-corner`,si=`circle`,ci=`ellipse`,li=`cover`,ui=`contain`,di=(e,t)=>{let n=1,r=3,i=[],a=[];return ke(t).forEach((t,o)=>{let s=!0;if(o===0){let e=!1;s=t.reduce((t,i)=>{if(e){if(P(i))switch(i.value){case`center`:return a.push(B),t;case`top`:case`left`:return a.push(z),t;case`right`:case`bottom`:return a.push(V),t}else(R(i)||ze(i))&&a.push(i)}else if(P(i))switch(i.value){case si:return n=0,!1;case ci:return n=1,!1;case`at`:return e=!0,!1;case ri:return r=0,!1;case li:case ii:return r=1,!1;case ui:case ai:return r=2,!1;case oi:return r=3,!1}else if(ze(i)||R(i))return Array.isArray(r)||(r=[]),r.push(i),!1;return t},s)}if(s){let n=qr(e,t);i.push(n)}}),{size:r,shape:n,stops:i,position:a,type:2}},fi=(e,t)=>{let n=1,r=3,i=[],a=[];return ke(t).forEach((t,o)=>{let s=!0;if(o===0?s=t.reduce((e,t)=>{if(P(t))switch(t.value){case`center`:return a.push(B),!1;case`top`:case`left`:return a.push(z),!1;case`right`:case`bottom`:return a.push(V),!1}else if(R(t)||ze(t))return a.push(t),!1;return e},s):o===1&&(s=t.reduce((e,t)=>{if(P(t))switch(t.value){case si:return n=0,!1;case ci:return n=1,!1;case ui:case ri:return r=0,!1;case ii:return r=1,!1;case ai:return r=2,!1;case li:case oi:return r=3,!1}else if(ze(t)||R(t))return Array.isArray(r)||(r=[]),r.push(t),!1;return e},s)),s){let n=qr(e,t);i.push(n)}}),{size:r,shape:n,stops:i,position:a,type:2}},pi=(e,t)=>({...ei(e,t),type:3}),mi=(e,t)=>({...di(e,t),type:4}),hi=(e,t)=>{let n=0,r=[],i=[];return ke(t).forEach((t,a)=>{let o=!0;if(a===0){let i=!1,a=!1;o=t.reduce((t,o)=>{if(P(o))switch(o.value){case`from`:return i=!0,a=!1,!1;case`at`:return i=!1,a=!0,!1;case`center`:return r.push(B),t;case`top`:case`left`:return r.push(z),t;case`right`:case`bottom`:return r.push(V),t}return i?(n=Ze.parse(e,o),!1):(a&&R(o)&&r.push(o),t)},!0)}o&&t.length>0&&i.push(qr(e,t))}),{type:5,angle:n,position:r,stops:i}},gi=(e,t)=>({...hi(e,t),type:6}),_i=e=>e&&(M(e)&&(e.unit===`dppx`||e.unit===`x`)||N(e))?e.number:1,vi=(e,t)=>{let n=ke(t),r=e.config.window.devicePixelRatio||1,i=[];for(let e of n){let t=e.find(e=>e.type===22||e.type===18);if(!t)continue;let n=e.find(e=>M(e)||N(e));i.push({imageToken:t,resolution:_i(n)})}if(i.length===0)throw Error(`image-set() requires at least one image candidate`);let a=i.filter(e=>e.resolution>=r).sort((e,t)=>e.resolution-t.resolution),o=v(a.length>0?a:i.slice().sort((e,t)=>t.resolution-e.resolution),0);return Ti.parse(e,o.imageToken)},yi=e=>e.type===1,bi=e=>e.type===2,xi=e=>e.type===3,Si=e=>e.type===4,Ci=e=>e.type===5,wi=e=>e.type===6,Ti={name:`image`,parse:(e,t)=>{if(t.type===22){let n={url:t.value,type:0};return e.cache.addImage(t.value),n}if(t.type===18){let n=Di[t.name];if(n===void 0)throw Error(`Attempting to parse an unsupported image function "${t.name}"`);return n(e,t.values)}throw Error(`Unsupported image type ${t.type}`)}};function Ei(e){return(e.type!==20||e.value!==`none`)&&(e.type!==18||!!Di[e.name])}var Di={"linear-gradient":ei,"-moz-linear-gradient":ti,"-ms-linear-gradient":ti,"-o-linear-gradient":ti,"-webkit-linear-gradient":ti,"radial-gradient":di,"-moz-radial-gradient":fi,"-ms-radial-gradient":fi,"-o-radial-gradient":fi,"-webkit-radial-gradient":fi,"-webkit-gradient":ni,"repeating-linear-gradient":pi,"-webkit-repeating-linear-gradient":pi,"-moz-repeating-linear-gradient":pi,"-ms-repeating-linear-gradient":pi,"-o-repeating-linear-gradient":pi,"repeating-radial-gradient":mi,"-webkit-repeating-radial-gradient":mi,"-moz-repeating-radial-gradient":mi,"conic-gradient":hi,"-webkit-conic-gradient":hi,"-moz-conic-gradient":hi,"repeating-conic-gradient":gi,"-webkit-repeating-conic-gradient":gi,"-moz-repeating-conic-gradient":gi,"image-set":vi,"-webkit-image-set":vi},Oi={name:`background-image`,initialValue:`none`,type:1,prefix:!1,skipCache:!0,parse:(e,t)=>{if(t.length===0)return[];let n=t[0];return n&&n.type===20&&n.value===`none`?[]:t.filter(e=>F(e)&&Ei(e)).map(t=>Ti.parse(e,t))}},ki={name:`background-origin`,initialValue:`border-box`,prefix:!1,type:1,parse:(e,t)=>t.map(e=>{if(P(e))switch(e.value){case`padding-box`:return 1;case`content-box`:return 2}return 0})},Ai={name:`background-position`,initialValue:`0% 0%`,type:1,prefix:!1,parse:(e,t)=>ke(t).map(e=>e.map(Ue).filter(e=>e!==null)).map(Ge)},ji={name:`background-repeat`,initialValue:`repeat`,prefix:!1,type:1,parse:(e,t)=>ke(t).map(e=>e.filter(P).map(e=>e.value).join(` `)).map(Mi)},Mi=e=>{switch(e){case`no-repeat`:return 1;case`repeat-x`:case`repeat no-repeat`:return 2;case`repeat-y`:case`no-repeat repeat`:return 3;default:return 0}},Ni={name:`background-size`,initialValue:`0`,prefix:!1,type:1,parse:(e,t)=>ke(t).map(e=>e.map(e=>Pi(e)?e:Ue(e)).filter(e=>e!==null))},Pi=e=>P(e)||R(e),Fi=e=>({name:`border-${e}-color`,initialValue:`transparent`,prefix:!1,type:3,format:`color`}),Ii=Fi(`top`),Li=Fi(`right`),Ri=Fi(`bottom`),zi=Fi(`left`),Bi=e=>({name:`border-${e}-radius`,initialValue:`0 0`,prefix:!1,type:1,parse:(e,t)=>Ge(t.filter(R))}),Vi=Bi(`top-left`),Hi=Bi(`top-right`),Ui=Bi(`bottom-right`),Wi=Bi(`bottom-left`),Gi=e=>({name:`border-${e}-style`,initialValue:`solid`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`none`:return 0;case`dashed`:return 2;case`dotted`:return 3;case`double`:return 4}return 1}}),Ki=Gi(`top`),qi=Gi(`right`),Ji=Gi(`bottom`),Yi=Gi(`left`),Xi=e=>({name:`border-${e}-width`,initialValue:`0`,type:0,prefix:!1,parse:(e,t)=>M(t)?t.number:0}),Zi=Xi(`top`),Qi=Xi(`right`),$i=Xi(`bottom`),ea=Xi(`left`),ta={type:0},na=e=>{let[t]=e;return t?P(t)?t.value===`farthest-side`?`farthest-side`:`closest-side`:R(t)?t:`closest-side`:`closest-side`},ra=e=>{let t=null,n=null;for(let r of e)if(P(r))switch(r.value){case`left`:t=z;break;case`right`:t=V;break;case`top`:n=z;break;case`bottom`:n=V;break;case`center`:t===null?t=B:n===null&&(n=B)}else R(r)&&(t===null?t=r:n===null&&(n=r));return{cx:t??B,cy:n??B}},ia=e=>{let t=[];for(let n of e)if(n.type!==31){if(P(n)&&n.value===`round`)break;R(n)&&t.push(n)}let n=t[0]??z,r=t[1]??n;return{type:1,top:n,right:r,bottom:t[2]??n,left:t[3]??r}},aa=e=>{let t=e.filter(Oe),n=t.findIndex(e=>De(e,`at`)),r=n===-1?t:t.slice(0,n),i=n===-1?[]:t.slice(n+1);return{type:2,radius:na(r),...ra(i)}},oa=e=>{let t=e.filter(Oe),n=t.findIndex(e=>De(e,`at`)),r=n===-1?t:t.slice(0,n),i=n===-1?[]:t.slice(n+1);return{type:3,rx:na(r.slice(0,1)),ry:na(r.slice(1,2)),...ra(i)}},sa=e=>{let t=ke(e),n=[];for(let e of t){if(e.length===1&&e[0]&&P(e[0]))continue;let t=e.filter(R);t.length>=2&&n.push([v(t,0),v(t,1)])}return{type:4,points:n}},ca=e=>{let t=e.find(e=>e.type===0);return t?{type:5,d:t.value}:ta},la=e=>{let t=[];for(let n of e)if(n.type!==31){if(P(n)&&n.value===`round`)break;R(n)&&t.push(n)}return t.length<4?ta:{type:6,x:v(t,0),y:v(t,1),width:v(t,2),height:v(t,3)}},ua=e=>{let t=[];for(let n of e)if(n.type!==31){if(P(n)){if(n.value===`round`)break;if(n.value===`auto`){t.push(`auto`);continue}return ta}R(n)&&t.push(n)}if(t.length!==4)return ta;let n=(e,t)=>e===`auto`?t===`top`||t===`left`?z:V:e;return{type:1,top:n(v(t,0),`top`),right:n(v(t,1),`right`),bottom:n(v(t,2),`bottom`),left:n(v(t,3),`left`)}},da={name:`clip-path`,initialValue:`none`,prefix:!1,type:0,parse:(e,t)=>{if(P(t)&&t.value===`none`)return ta;if(t.type===18)switch(t.name){case`inset`:return ia(t.values);case`circle`:return aa(t.values);case`ellipse`:return oa(t.values);case`polygon`:return sa(t.values);case`path`:return ca(t.values);case`xywh`:return la(t.values);case`rect`:return ua(t.values)}return ta}},fa={name:`color`,initialValue:`transparent`,prefix:!1,type:3,format:`color`},pa={name:`direction`,initialValue:`ltr`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`rtl`:return 1;default:return 0}}},ma={name:`font-family`,initialValue:``,prefix:!1,type:1,parse:(e,t)=>{let n=[],r=[],i=[],a=!1;return t.forEach(e=>{switch(e.type){case 20:n.push(e.value);break;case 0:a=!0,n.push(e.value);break;case 17:n.push(e.number.toString());break;case 4:r.push(n.join(` `)),i.push(a),a=!1,n.length=0}}),n.length&&(r.push(n.join(` `)),i.push(a)),r.map((e,t)=>i[t]||e.indexOf(` `)!==-1?`'${e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`).replace(/\n/g,`\\a `).replace(/\r/g,`\\d `).replace(/\f/g,`\\c `)}'`:e)}},ha={name:`font-size`,initialValue:`0`,prefix:!1,type:3,format:`length`},ga={name:`letter-spacing`,initialValue:`0`,prefix:!1,type:0,parse:(e,t)=>t.type===20&&t.value===`normal`?0:t.type===17||t.type===15?t.number:0},_a={name:`line-break`,initialValue:`normal`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`strict`:return`strict`;default:return`normal`}}},va={name:`line-height`,initialValue:`normal`,prefix:!1,type:4},ya=(e,t)=>P(e)&&e.value===`normal`?1.2*t:e.type===17?t*e.number:R(e)?H(e,t):t,ba={name:`list-style-image`,initialValue:`none`,type:0,prefix:!1,skipCache:!0,parse:(e,t)=>t.type===20&&t.value===`none`||!Ei(t)?null:Ti.parse(e,t)},xa={name:`list-style-position`,initialValue:`outside`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`inside`:return 0;default:return 1}}},Sa=e=>({name:`margin-${e}`,initialValue:`0`,prefix:!1,type:4}),Ca=Sa(`top`),wa=Sa(`right`),Ta=Sa(`bottom`),Ea=Sa(`left`),Da={name:`overflow-wrap`,initialValue:`normal`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`break-word`:return`break-word`;default:return`normal`}}},Oa=e=>({name:`padding-${e}`,initialValue:`0`,prefix:!1,type:3,format:`length-percentage`}),ka=Oa(`top`),Aa=Oa(`right`),ja=Oa(`bottom`),Ma=Oa(`left`),Na={name:`text-align`,initialValue:`left`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`right`:return 2;case`center`:case`justify`:return 1;default:return 0}}},Pa={name:`position`,initialValue:`static`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`relative`:return 1;case`absolute`:return 2;case`fixed`:return 3;case`sticky`:return 4}return 0}},Fa={name:`text-shadow`,initialValue:`none`,type:1,prefix:!1,parse:(e,t)=>t.length===1&&De(v(t,0),`none`)?[]:ke(t).map(t=>{let n={color:0,offsetX:z,offsetY:z,blur:z},r=0;for(let i=0;i<t.length;i++){let a=t[i];a&&(ze(a)?(r===0?n.offsetX=a:r===1?n.offsetY=a:n.blur=a,r++):n.color=W.parse(e,a))}return n})},Ia={name:`text-transform`,initialValue:`none`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`uppercase`:return 2;case`lowercase`:return 1;case`capitalize`:return 3}return 0}},La={name:`transform`,initialValue:`none`,prefix:!0,type:0,parse:(e,t)=>{if(t.type===20&&t.value===`none`)return null;if(t.type===18){let n=Ra[t.name];if(n===void 0)throw Error(`Attempting to parse an unsupported transform function "${t.name}"`);return n(e,t.values)}return null}},Ra={matrix:(e,t)=>{let n=t.filter(e=>e.type===17).map(e=>e.number);return n.length===6?n:null},matrix3d:(e,t)=>{let n=t.filter(e=>e.type===17).map(e=>e.number);return n.length===16?[v(n,0),v(n,1),v(n,4),v(n,5),v(n,12),v(n,13)]:null},rotate:(e,t)=>{if(t.length!==1)return null;let n=v(t,0),r=0;if(n.type===17&&n.number===0)r=0;else if(n.type===15)r=Ze.parse(e,n);else return null;let i=Math.cos(r),a=Math.sin(r);return[i,a,-a,i,0,0]}},za={type:16,number:50,flags:4},Ba=[za,za],Va={name:`transform-origin`,initialValue:`50% 50%`,prefix:!0,type:1,parse:(e,t)=>{let n=t.filter(R);return n.length===2?[v(n,0),v(n,1)]:Ba}},Ha={name:`rotate`,initialValue:`none`,prefix:!1,type:0,parse:(e,t)=>t.type===20&&t.value===`none`?null:t.type===17&&t.number===0?0:t.type===15?Ze.parse(e,t)*180/Math.PI:null},Ua={name:`visibility`,initialValue:`none`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`hidden`:return 1;case`collapse`:return 2;default:return 0}}},Wa={name:`word-break`,initialValue:`normal`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`break-all`:return`break-all`;case`keep-all`:return`keep-all`;default:return`normal`}}},Ga={name:`white-space`,initialValue:`normal`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`pre`:return`pre`;case`nowrap`:return`nowrap`;case`pre-wrap`:return`pre-wrap`;case`pre-line`:return`pre-line`;default:return`normal`}}},Ka=e=>e!==0,qa=e=>e===3||e===4,Ja={name:`writing-mode`,initialValue:`horizontal-tb`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`vertical-rl`:return 1;case`vertical-lr`:return 2;case`sideways-rl`:return 3;case`sideways-lr`:return 4;default:return 0}}},Ya={name:`z-index`,initialValue:`auto`,prefix:!1,type:0,parse:(e,t)=>{if(t.type===20)return{auto:!0,order:0};if(N(t))return{auto:!1,order:t.number};throw Error(`Invalid z-index number parsed`)}},Xa={name:`time`,parse:(e,t)=>{if(t.type===15)switch(t.unit.toLowerCase()){case`s`:return 1e3*t.number;case`ms`:return t.number}throw Error(`Unsupported time type`)}},Za={name:`opacity`,initialValue:`1`,type:0,prefix:!1,parse:(e,t)=>N(t)?t.number:1},Qa={name:`text-decoration-style`,initialValue:`solid`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`double`:return 1;case`dotted`:return 2;case`dashed`:return 3;case`wavy`:return 4;default:return 0}}},$a={name:`text-decoration-thickness`,initialValue:`auto`,prefix:!1,type:0,parse:(e,t)=>{if(P(t))switch(t.value){case`auto`:return`auto`;case`from-font`:return`from-font`}return M(t)?t.number:`auto`}},eo={name:`text-underline-offset`,initialValue:`auto`,prefix:!1,type:0,parse:(e,t)=>P(t)&&t.value===`auto`?`auto`:M(t)?t.number:`auto`},to={name:`font-weight`,initialValue:`normal`,type:0,prefix:!1,parse:(e,t)=>{if(N(t))return t.number;if(P(t))switch(t.value){case`bold`:return 700;default:return 400}return 400}},no={name:`font-variant`,initialValue:`none`,type:1,prefix:!1,parse:(e,t)=>t.filter(P).map(e=>e.value)},ro={name:`font-style`,initialValue:`normal`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`oblique`:return`oblique`;case`italic`:return`italic`;default:return`normal`}}},io={name:`duration`,initialValue:`0s`,prefix:!1,type:1,parse:(e,t)=>t.filter(M).map(t=>Xa.parse(e,t))},ao={name:`box-shadow`,initialValue:`none`,type:1,prefix:!1,parse:(e,t)=>t.length===1&&De(v(t,0),`none`)?[]:ke(t).map(t=>{let n={color:255,offsetX:z,offsetY:z,blur:z,spread:z,inset:!1},r=0;for(let i=0;i<t.length;i++){let a=t[i];a&&(De(a,`inset`)?n.inset=!0:ze(a)?(r===0?n.offsetX=a:r===1?n.offsetY=a:r===2?n.blur=a:n.spread=a,r++):n.color=W.parse(e,a))}return n})},oo={name:`paint-order`,initialValue:`normal`,prefix:!1,type:1,parse:(e,t)=>{let n=[0,1,2],r=[];return t.filter(P).forEach(e=>{switch(e.value){case`stroke`:r.push(1);break;case`fill`:r.push(0);break;case`markers`:r.push(2)}}),n.forEach(e=>{r.indexOf(e)===-1&&r.push(e)}),r}},so={name:`-webkit-text-stroke-color`,initialValue:`currentcolor`,prefix:!1,type:3,format:`color`},co={name:`-webkit-text-stroke-width`,initialValue:`0`,type:0,prefix:!1,parse:(e,t)=>M(t)?t.number:0},lo={name:`-webkit-line-clamp`,initialValue:`none`,prefix:!0,type:0,parse:(e,t)=>t.type===20&&t.value===`none`?0:t.type===17?Math.max(0,Math.floor(t.number)):0},uo={name:`object-fit`,initialValue:`fill`,prefix:!1,type:1,parse:(e,t)=>t.filter(P).reduce((e,t)=>e|fo(t.value),0)},fo=e=>{switch(e){case`contain`:return 2;case`cover`:return 4;case`none`:return 8;case`scale-down`:return 16}return 0},po={name:`text-overflow`,initialValue:`clip`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`ellipsis`:return 1;default:return 0}}},mo={name:`image-rendering`,initialValue:`auto`,prefix:!1,type:2,parse:(e,t)=>{switch(t.toLowerCase()){case`crisp-edges`:case`-webkit-crisp-edges`:case`-moz-crisp-edges`:return 1;case`pixelated`:case`-webkit-optimize-contrast`:return 2;case`smooth`:case`high-quality`:return 3;default:return 0}}},q={NORMAL:`normal`,MULTIPLY:`multiply`,SCREEN:`screen`,OVERLAY:`overlay`,DARKEN:`darken`,LIGHTEN:`lighten`,COLOR_DODGE:`color-dodge`,COLOR_BURN:`color-burn`,HARD_LIGHT:`hard-light`,SOFT_LIGHT:`soft-light`,DIFFERENCE:`difference`,EXCLUSION:`exclusion`,HUE:`hue`,SATURATION:`saturation`,COLOR:`color`,LUMINOSITY:`luminosity`},ho=new Set(Object.values(q)),go={name:`mix-blend-mode`,initialValue:`normal`,type:2,prefix:!1,parse:(e,t)=>ho.has(t)?t:q.NORMAL},_o={name:`filter`,initialValue:`none`,prefix:!1,type:1,parse:(e,t)=>{if(t.length===1){let e=v(t,0);if(e.type===20&&e.value===`none`)return null}let n=[];for(let e of t)if(e.type===22)n.push(`url("${e.value}")`);else if(e.type===18){let t=e,r=vo(t.values);switch(t.name){case`blur`:n.push(`blur(${r})`);break;case`brightness`:case`contrast`:case`invert`:case`opacity`:case`saturate`:case`sepia`:n.push(`${t.name}(${r})`);break;case`grayscale`:n.push(`grayscale(${r})`);break;case`hue-rotate`:n.push(`hue-rotate(${r})`);break;case`drop-shadow`:n.push(`drop-shadow(${r})`);break;default:n.push(`${t.name}(${r})`)}}return n.length>0?n.join(` `):null}},vo=e=>{let t=[];for(let n of e)n.type===31?t.push(` `):n.type===18?t.push(`${n.name}(${vo(n.values)})`):n.type===4?t.push(`,`):n.type===6?t.push(n.value):n.type===15?t.push(`${n.number}${n.unit}`):n.type===17?t.push(`${n.number}`):n.type===16?t.push(`${n.number}%`):n.type===20?t.push(n.value):n.type===5&&t.push(`#${n.value}`);return t.join(``).trim()},yo={name:`font-variant-ligatures`,initialValue:`normal`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`none`:return 1;case`common-ligatures`:return 2;case`no-common-ligatures`:return 3;case`discretionary-ligatures`:return 4;case`no-discretionary-ligatures`:return 5;case`historical-ligatures`:return 6;case`no-historical-ligatures`:return 7;case`contextual`:return 8;case`no-contextual`:return 9;default:return 0}}},bo={name:`zoom`,initialValue:`1`,type:0,prefix:!1,parse:(e,t)=>t.type===16?Math.max(0,t.number/100):t.type===17?Math.max(0,t.number):1},xo={name:`object-position`,initialValue:`50% 50%`,prefix:!1,type:1,parse:(e,t)=>{let n=[],r=0;for(;r<t.length&&n.length<2;){let e=t[r];if(!e)break;if(P(e))switch(e.value){case`left`:case`top`:n.push(z);break;case`center`:n.push(B);break;case`right`:case`bottom`:n.push(V)}else R(e)&&n.push(e);r++}for(;n.length<2;)n.push(B);return[v(n,0),v(n,1)]}},So=new Set(Object.values({NORMAL:`normal`,MULTIPLY:`multiply`,SCREEN:`screen`,OVERLAY:`overlay`,DARKEN:`darken`,LIGHTEN:`lighten`,COLOR_DODGE:`color-dodge`,COLOR_BURN:`color-burn`,HARD_LIGHT:`hard-light`,SOFT_LIGHT:`soft-light`,DIFFERENCE:`difference`,EXCLUSION:`exclusion`,HUE:`hue`,SATURATION:`saturation`,COLOR:`color`,LUMINOSITY:`luminosity`})),Co={name:`background-blend-mode`,initialValue:`normal`,prefix:!1,type:1,parse:(e,t)=>{let n=[],r=t.filter(F);for(let e of r)P(e)&&So.has(e.value)&&n.push(e.value);return n.length>0?n:[`normal`]}},wo={name:`border-image-source`,initialValue:`none`,prefix:!1,type:1,skipCache:!0,parse:(e,t)=>{if(t.length===0)return null;let n=t.filter(e=>F(e)&&Ei(e));return n.length===0?null:Ti.parse(e,v(n,0))}},To=e=>{let t=[...e];if(t.length===1){let e=v(t,0);t.push(e,e,e)}else t.length===2?t.push(v(t,0),v(t,1)):t.length===3&&t.push(v(t,1));return[v(t,0),v(t,1),v(t,2),v(t,3)]},Eo={name:`border-image-slice`,initialValue:`100%`,prefix:!1,type:1,parse:(e,t)=>{let n=t.filter(Oe),r=[],i=!1,a=`percent`;for(let e of n)P(e)&&e.value===`fill`?i=!0:e.type===17?(r.push(e.number),a=`number`):e.type===16&&(r.push(e.number),a=`percent`);let[o,s,c,l]=To(r.length>0?r:[100]);return{top:o,right:s,bottom:c,left:l,fill:i,unit:a}}},Do=e=>{switch(e){case`repeat`:return 1;case`round`:return 2;case`space`:return 3;default:return 0}},Oo={name:`border-image-repeat`,initialValue:`stretch`,prefix:!1,type:1,parse:(e,t)=>{let n=t.filter(Oe),r=[];for(let e of n)P(e)&&r.push(Do(e.value));let i=r[0]??0;return{horizontal:i,vertical:r[1]??i}}},ko={name:`box-decoration-break`,initialValue:`slice`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`clone`:return 1;default:return 0}}},Ao={name:`accent-color`,initialValue:`auto`,prefix:!1,type:0,parse:(e,t)=>P(t)&&t.value===`auto`?null:W.parse(e,t)},jo={name:`-webkit-text-fill-color`,initialValue:`currentcolor`,prefix:!0,type:0,parse:(e,t)=>P(t)&&t.value===`currentcolor`?null:W.parse(e,t)},Mo={name:`isolation`,initialValue:`auto`,prefix:!1,type:2,parse:(e,t)=>+(t===`isolate`)},No={name:`outline-style`,initialValue:`none`,prefix:!1,type:2,parse:(e,t)=>{switch(t){case`solid`:return 2;case`dashed`:return 3;case`dotted`:return 4;case`double`:return 5;case`auto`:return 1;default:return 0}}},Po={name:`outline-color`,initialValue:`currentcolor`,prefix:!1,type:0,parse:(e,t)=>P(t)&&(t.value===`currentcolor`||t.value===`invert`)?null:W.parse(e,t)},Fo={name:`outline-width`,initialValue:`medium`,prefix:!1,type:0,parse:Zi.parse},Io={name:`outline-offset`,initialValue:`0px`,prefix:!1,type:0,parse:(e,t)=>M(t)||N(t)?t.number:0},Lo={name:`backdrop-filter`,initialValue:`none`,prefix:!1,type:1,parse:(e,t)=>_o.parse(e,t)},Ro={name:`mask-image`,initialValue:`none`,prefix:!1,type:1,skipCache:!0,parse:Oi.parse},zo={name:`mask-position`,initialValue:`0%`,prefix:!1,type:1,parse:Ai.parse},Bo={name:`mask-repeat`,initialValue:`repeat`,prefix:!1,type:1,parse:ji.parse},Vo={name:`mask-size`,initialValue:`auto`,prefix:!1,type:1,parse:Ni.parse},Ho=[`dot`,`circle`,`double-circle`,`triangle`,`sesame`],Uo={name:`text-emphasis-style`,initialValue:`none`,prefix:!1,type:1,parse:(e,t)=>{let n=t.filter(Oe);if(n.length===0)return null;let r=v(n,0);if(r.type===0)return r.value;if(P(r)){if(r.value===`none`)return null;if(r.value!==`filled`&&r.value!==`open`&&Ho.indexOf(r.value)===-1)return r.value}let i=!0,a=`circle`;for(let e of n)P(e)&&(e.value===`filled`?i=!0:e.value===`open`?i=!1:Ho.indexOf(e.value)!==-1&&(a=e.value));return{fill:i,shape:a}}},Wo={name:`text-emphasis-color`,initialValue:`currentcolor`,prefix:!1,type:0,parse:(e,t)=>P(t)&&t.value===`currentcolor`?null:W.parse(e,t)},Go={name:`text-emphasis-position`,initialValue:`over right`,prefix:!1,type:1,parse:(e,t)=>{let n=!0,r=!0;for(let e of t)if(P(e))switch(e.value){case`over`:n=!0;break;case`under`:n=!1;break;case`right`:r=!0;break;case`left`:r=!1}return{over:n,right:r}}},Ko=e=>{let t=[...e];if(t.length===1){let e=v(t,0);t.push(e,e,e)}else t.length===2?t.push(v(t,0),v(t,1)):t.length===3&&t.push(v(t,1));return[v(t,0),v(t,1),v(t,2),v(t,3)]},qo=e=>P(e)&&e.value===`auto`?{kind:`auto`}:e.type===17?{kind:`number`,value:e.number}:e.type===15&&e.unit===`px`?{kind:`length`,value:e.number}:e.type===16?{kind:`percentage`,value:e.number}:null,Jo=e=>{let t=[];for(let n of e){if(n.type===31)continue;let e=qo(n);if(!e)return null;t.push(e)}return t.length===0||t.length>4?null:Ko(t)},Yo={name:`border-image-width`,initialValue:`auto`,prefix:!1,type:1,parse:(e,t)=>{let n=Jo(t),r={kind:`auto`};return n?{top:n[0],right:n[1],bottom:n[2],left:n[3]}:{top:r,right:r,bottom:r,left:r}}},Xo={name:`border-image-outset`,initialValue:`0px`,prefix:!1,type:1,parse:(e,t)=>{let n=Jo(t),r={kind:`length`,value:0};return n?{top:n[0],right:n[1],bottom:n[2],left:n[3]}:{top:r,right:r,bottom:r,left:r}}},Zo={name:`-webkit-box-reflect`,initialValue:`none`,prefix:!0,type:1,skipCache:!0,parse:(e,t)=>{let n=null,r=0,i=null;for(let a of t)if(a.type!==31){if(n===null&&P(a)){if(a.value===`below`||a.value===`above`||a.value===`left`||a.value===`right`){n=a.value;continue}if(a.value===`none`)return null}r===0&&M(a)&&a.unit===`px`?r=a.number:i===null&&Ei(a)&&(i=Ti.parse(e,a))}return n===null?null:{direction:n,offset:r,mask:i}}},Qo={name:`translate`,initialValue:`none`,prefix:!1,type:1,parse:(e,t)=>{let n=[];for(let e of t)R(e)&&n.push(e);return n.length===0?null:[v(n,0),n.length>1?v(n,1):z]}},$o={name:`scale`,initialValue:`none`,prefix:!1,type:1,parse:(e,t)=>{let n=[];for(let e of t)N(e)&&n.push(e.number);return n.length===0?null:[v(n,0),n.length>1?v(n,1):v(n,0)]}},es=1e4,ts=3e4,ns=6e4,rs=[[`animationDuration`,io,`animationDuration`],[`backgroundClip`,Gr,`backgroundClip`],[`backgroundColor`,Kr,`backgroundColor`],[`backgroundImage`,Oi,`backgroundImage`],[`backgroundOrigin`,ki,`backgroundOrigin`],[`backgroundPosition`,Ai,`backgroundPosition`],[`backgroundRepeat`,ji,`backgroundRepeat`],[`backgroundSize`,Ni,`backgroundSize`],[`borderTopColor`,Ii,`borderTopColor`],[`borderRightColor`,Li,`borderRightColor`],[`borderBottomColor`,Ri,`borderBottomColor`],[`borderLeftColor`,zi,`borderLeftColor`],[`borderTopLeftRadius`,Vi,`borderTopLeftRadius`],[`borderTopRightRadius`,Hi,`borderTopRightRadius`],[`borderBottomRightRadius`,Ui,`borderBottomRightRadius`],[`borderBottomLeftRadius`,Wi,`borderBottomLeftRadius`],[`borderTopStyle`,Ki,`borderTopStyle`],[`borderRightStyle`,qi,`borderRightStyle`],[`borderBottomStyle`,Ji,`borderBottomStyle`],[`borderLeftStyle`,Yi,`borderLeftStyle`],[`borderTopWidth`,Zi,`borderTopWidth`],[`borderRightWidth`,Qi,`borderRightWidth`],[`borderBottomWidth`,$i,`borderBottomWidth`],[`borderLeftWidth`,ea,`borderLeftWidth`],[`boxShadow`,ao,`boxShadow`],[`clipPath`,da,`clipPath`],[`color`,fa,`color`],[`direction`,pa,`direction`],[`display`,Nr,`display`],[`fontFamily`,ma,`fontFamily`],[`fontSize`,ha,`fontSize`],[`fontStyle`,ro,`fontStyle`],[`fontVariant`,no,`fontVariant`],[`fontWeight`,to,`fontWeight`],[`letterSpacing`,ga,`letterSpacing`],[`lineBreak`,_a,`lineBreak`],[`lineHeight`,va,`lineHeight`],[`listStyleImage`,ba,`listStyleImage`],[`listStylePosition`,xa,`listStylePosition`],[`listStyleType`,mr,`listStyleType`],[`marginTop`,Ca,`marginTop`],[`marginRight`,wa,`marginRight`],[`marginBottom`,Ta,`marginBottom`],[`marginLeft`,Ea,`marginLeft`],[`opacity`,Za,`opacity`],[`overflowWrap`,Da,`overflowWrap`],[`paddingTop`,ka,`paddingTop`],[`paddingRight`,Aa,`paddingRight`],[`paddingBottom`,ja,`paddingBottom`],[`paddingLeft`,Ma,`paddingLeft`],[`paintOrder`,oo,`paintOrder`],[`position`,Pa,`position`],[`textAlign`,Na,`textAlign`],[`textDecorationStyle`,Qa,`textDecorationStyle`],[`textDecorationThickness`,$a,`textDecorationThickness`],[`textUnderlineOffset`,eo,`textUnderlineOffset`],[`textShadow`,Fa,`textShadow`],[`textTransform`,Ia,`textTransform`],[`textOverflow`,po,`textOverflow`],[`transform`,La,`transform`],[`transformOrigin`,Va,`transformOrigin`],[`rotate`,Ha,`rotate`],[`translate`,Qo,`translate`],[`scale`,$o,`scale`],[`visibility`,Ua,`visibility`],[`webkitTextStrokeColor`,so,`webkitTextStrokeColor`],[`webkitTextStrokeWidth`,co,`webkitTextStrokeWidth`],[`webkitLineClamp`,lo,`webkitLineClamp`],[`wordBreak`,Wa,`wordBreak`],[`whiteSpace`,Ga,`whiteSpace`],[`writingMode`,Ja,`writingMode`],[`zIndex`,Ya,`zIndex`],[`objectFit`,uo,`objectFit`],[`imageRendering`,mo,`imageRendering`],[`mixBlendMode`,go,`mixBlendMode`],[`filter`,_o,`filter`],[`fontVariantLigatures`,yo,`fontVariantLigatures`],[`zoom`,bo,`zoom`],[`objectPosition`,xo,`objectPosition`],[`backgroundBlendMode`,Co,`backgroundBlendMode`],[`borderImageSource`,wo,`borderImageSource`],[`borderImageSlice`,Eo,`borderImageSlice`],[`borderImageRepeat`,Oo,`borderImageRepeat`],[`boxDecorationBreak`,ko,`boxDecorationBreak`],[`accentColor`,Ao,`accentColor`],[`webkitTextFillColor`,jo,`webkitTextFillColor`],[`isolation`,Mo,`isolation`],[`outlineColor`,Po,`outlineColor`],[`outlineStyle`,No,`outlineStyle`],[`outlineWidth`,Fo,`outlineWidth`],[`outlineOffset`,Io,`outlineOffset`],[`backdropFilter`,Lo,`backdropFilter`],[`maskImage`,Ro,`maskImage`],[`maskPosition`,zo,`maskPosition`],[`maskRepeat`,Bo,`maskRepeat`],[`maskSize`,Vo,`maskSize`],[`textEmphasisStyle`,Uo,`textEmphasisStyle`],[`textEmphasisColor`,Wo,`textEmphasisColor`],[`textEmphasisPosition`,Go,`textEmphasisPosition`],[`borderImageWidth`,Yo,`borderImageWidth`],[`borderImageOutset`,Xo,`borderImageOutset`],[`webkitBoxReflect`,Zo,`webkitBoxReflect`]],is=new Map,as=(e,t,n)=>{let r=n==null?t.initialValue:n.toString();r.trim()===``&&(r=t.initialValue);let i=is.get(t);if(i){let e=i.get(r);if(e!==void 0)return i.delete(r),i.set(r,e),e}let a=we.get();a.write(r);let o=new Te(a.read());we.release(a);let s=(()=>{switch(t.type){case 2:{let n=o.parseComponentValue();return t.parse(e,P(n)?n.value:t.initialValue)}case 0:return t.parse(e,o.parseComponentValue());case 1:return t.parse(e,o.parseComponentValues());case 4:return o.parseComponentValue();case 3:switch(t.format){case`angle`:return Ze.parse(e,o.parseComponentValue());case`color`:return W.parse(e,o.parseComponentValue());case`image`:return Ti.parse(e,o.parseComponentValue());case`length`:{let e=o.parseComponentValue();return ze(e)?e:z}case`length-percentage`:{let e=o.parseComponentValue();return R(e)?e:z}case`time`:return Xa.parse(e,o.parseComponentValue())}}})();if(i||(i=new Map,is.set(t,i)),!(t.skipCache||t.type===3&&t.format===`image`)){if(i.size>=200){let e=i.keys().next().value;e!==void 0&&i.delete(e)}i.set(r,s)}return s},os=class{styles;constructor(e){this.styles=e}get topColor(){return this.styles.borderTopColor}get rightColor(){return this.styles.borderRightColor}get bottomColor(){return this.styles.borderBottomColor}get leftColor(){return this.styles.borderLeftColor}get topStyle(){return this.styles.borderTopStyle}get rightStyle(){return this.styles.borderRightStyle}get bottomStyle(){return this.styles.borderBottomStyle}get leftStyle(){return this.styles.borderLeftStyle}get topWidth(){return this.styles.borderTopWidth}get rightWidth(){return this.styles.borderRightWidth}get bottomWidth(){return this.styles.borderBottomWidth}get leftWidth(){return this.styles.borderLeftWidth}get topLeftRadius(){return this.styles.borderTopLeftRadius}get topRightRadius(){return this.styles.borderTopRightRadius}get bottomRightRadius(){return this.styles.borderBottomRightRadius}get bottomLeftRadius(){return this.styles.borderBottomLeftRadius}get imageSource(){return this.styles.borderImageSource}get imageSlice(){return this.styles.borderImageSlice}get imageRepeat(){return this.styles.borderImageRepeat}get boxShadow(){return this.styles.boxShadow}},ss=class{styles;constructor(e){this.styles=e}get color(){return this.styles.backgroundColor}get image(){return this.styles.backgroundImage}get clip(){return this.styles.backgroundClip}get origin(){return this.styles.backgroundOrigin}get position(){return this.styles.backgroundPosition}get repeat(){return this.styles.backgroundRepeat}get size(){return this.styles.backgroundSize}get blendMode(){return this.styles.backgroundBlendMode}},cs=class{styles;constructor(e){this.styles=e}get family(){return this.styles.fontFamily}get size(){return this.styles.fontSize}get style(){return this.styles.fontStyle}get variant(){return this.styles.fontVariant}get weight(){return this.styles.fontWeight}get ligatures(){return this.styles.fontVariantLigatures}get color(){return this.styles.color}get letterSpacing(){return this.styles.letterSpacing}get lineHeight(){return this.styles.lineHeight}get textAlign(){return this.styles.textAlign}get textTransform(){return this.styles.textTransform}get textOverflow(){return this.styles.textOverflow}get textShadow(){return this.styles.textShadow}get textDecorationColor(){return this.styles.textDecorationColor}get textDecorationLine(){return this.styles.textDecorationLine}get textDecorationStyle(){return this.styles.textDecorationStyle}get textDecorationThickness(){return this.styles.textDecorationThickness}get textUnderlineOffset(){return this.styles.textUnderlineOffset}get wordBreak(){return this.styles.wordBreak}get lineBreak(){return this.styles.lineBreak}get overflowWrap(){return this.styles.overflowWrap}get writingMode(){return this.styles.writingMode}get direction(){return this.styles.direction}get webkitTextStrokeColor(){return this.styles.webkitTextStrokeColor}get webkitTextStrokeWidth(){return this.styles.webkitTextStrokeWidth}get webkitLineClamp(){return this.styles.webkitLineClamp}get paintOrder(){return this.styles.paintOrder}},ls=class{styles;constructor(e){this.styles=e}get display(){return this.styles.display}get position(){return this.styles.position}get float(){return this.styles.float}get zIndex(){return this.styles.zIndex}get marginTop(){return this.styles.marginTop}get marginRight(){return this.styles.marginRight}get marginBottom(){return this.styles.marginBottom}get marginLeft(){return this.styles.marginLeft}get paddingTop(){return this.styles.paddingTop}get paddingRight(){return this.styles.paddingRight}get paddingBottom(){return this.styles.paddingBottom}get paddingLeft(){return this.styles.paddingLeft}get overflowX(){return this.styles.overflowX}get overflowY(){return this.styles.overflowY}get opacity(){return this.styles.opacity}get visibility(){return this.styles.visibility}get transform(){return this.styles.transform}get transformOrigin(){return this.styles.transformOrigin}get rotate(){return this.styles.rotate}get zoom(){return this.styles.zoom}get clipPath(){return this.styles.clipPath}get mixBlendMode(){return this.styles.mixBlendMode}get filter(){return this.styles.filter}get imageRendering(){return this.styles.imageRendering}get objectFit(){return this.styles.objectFit}get objectPosition(){return this.styles.objectPosition}get boxDecorationBreak(){return this.styles.boxDecorationBreak}get listStyleImage(){return this.styles.listStyleImage}get listStylePosition(){return this.styles.listStylePosition}get listStyleType(){return this.styles.listStyleType}get animationDuration(){return this.styles.animationDuration}isVisible(){return this.styles.isVisible()}isTransparent(){return this.styles.isTransparent()}isTransformed(){return this.styles.isTransformed()}isPositioned(){return this.styles.isPositioned()}isPositionedWithZIndex(){return this.styles.isPositionedWithZIndex()}isFloating(){return this.styles.isFloating()}isInlineLevel(){return this.styles.isInlineLevel()}},us=class{animationDuration;backgroundClip;backgroundColor;backgroundImage;backgroundOrigin;backgroundPosition;backgroundRepeat;backgroundSize;borderTopColor;borderRightColor;borderBottomColor;borderLeftColor;borderTopLeftRadius;borderTopRightRadius;borderBottomRightRadius;borderBottomLeftRadius;borderTopStyle;borderRightStyle;borderBottomStyle;borderLeftStyle;borderTopWidth;borderRightWidth;borderBottomWidth;borderLeftWidth;boxShadow;clipPath;color;direction;display;float;fontFamily;fontSize;fontStyle;fontVariant;fontWeight;letterSpacing;lineBreak;lineHeight;listStyleImage;listStylePosition;listStyleType;marginTop;marginRight;marginBottom;marginLeft;opacity;overflowX;overflowY;overflowWrap;paddingTop;paddingRight;paddingBottom;paddingLeft;paintOrder;position;textAlign;textDecorationColor;textDecorationLine;textDecorationStyle;textDecorationThickness;textUnderlineOffset;textShadow;textTransform;textOverflow;transform;transformOrigin;rotate;translate;scale;visibility;webkitTextStrokeColor;webkitTextStrokeWidth;webkitLineClamp;wordBreak;whiteSpace;writingMode;zIndex;objectFit;imageRendering;mixBlendMode;filter;fontVariantLigatures;zoom;objectPosition;backgroundBlendMode;borderImageSource;borderImageSlice;borderImageRepeat;boxDecorationBreak;accentColor;webkitTextFillColor;isolation;outlineColor;outlineStyle;outlineWidth;outlineOffset;backdropFilter;maskImage;maskPosition;maskRepeat;maskSize;textEmphasisStyle;textEmphasisColor;textEmphasisPosition;borderImageWidth;borderImageOutset;webkitBoxReflect;_border;_background;_font;_layout;get border(){return this._border??=new os(this)}get background(){return this._background??=new ss(this)}get font(){return this._font??=new cs(this)}get layout(){return this._layout??=new ls(this)}constructor(e,t){if(t.display===`none`){this.display=0;for(let[t,n]of rs)t!==`display`&&(this[t]=as(e,n,void 0));Object.assign(this,ds(e,null))}else{for(let[n,r,i]of rs)this[n]=as(e,r,t[i]);Object.assign(this,ds(e,t))}}isVisible(){return this.display>0&&this.opacity>0&&this.visibility===0}isTransparent(){return tt(this.backgroundColor)}isTransformed(){return this.transform!==null||this.rotate!==null||this.translate!==null||this.scale!==null}isPositioned(){return this.position!==0}isPositionedWithZIndex(){return this.isPositioned()&&!this.zIndex.auto}isFloating(){return this.float!==0}isInlineLevel(){return G(this.display,4)||G(this.display,33554432)||G(this.display,268435456)||G(this.display,536870912)||G(this.display,67108864)||G(this.display,134217728)}},ds=(e,t)=>{let n=(e,n)=>{if(t)return t[e]??n},r=as(e,Ir,n(`overflow`));return{float:as(e,Fr,n(`cssFloat`)),textDecorationColor:as(e,Lr,n(`textDecorationColor`,n(`color`))),textDecorationLine:as(e,Rr,n(`textDecorationLine`,n(`textDecoration`))),overflowX:r[0],overflowY:r[+(r.length>1)]}},fs=class{content;quotes;constructor(e,t){this.content=as(e,zr,t.content),this.quotes=as(e,Br,t.quotes)}},ps=class{counterIncrement;counterReset;constructor(e,t){this.counterIncrement=as(e,Ur,t.counterIncrement),this.counterReset=as(e,Wr,t.counterReset)}},ms=`data-html2canvas-debug`,hs=e=>{if(typeof e.getAttribute!=`function`)return 0;switch(e.getAttribute(ms)){case`all`:return 1;case`clone`:return 2;case`parse`:return 3;case`render`:return 4;default:return 0}},gs=(e,t)=>{let n=hs(e);return n===1||t===n},_s=e=>{let t=``;for(let n of e)try{let e=n.cssRules;for(let n=0;n<e.length;n++){let r=e[n];r&&typeof r.cssText==`string`&&(t+=r.cssText)}}catch{}return t},vs=(e,t,n)=>{let r=_s(t);if(!r)return null;let i=e.createElement(`style`);return i.textContent=r,n&&(i.nonce=n),i},ys=`data-html2canvas-ignore`,bs=class{cloneNodeFn;options;context;constructor(e,t,n){this.cloneNodeFn=e,this.options=t,this.context=n}appendChildNode(e,t,n){this.safeAppendClonedChild(e,t,n)}cloneChildNodes(e,t,n){e.shadowRoot&&t.shadowRoot?(this.cloneShadowDOMChildren(e.shadowRoot,t.shadowRoot,n),this.cloneLightDOMChildren(e,t,n)):e.shadowRoot&&!t.shadowRoot?this.cloneShadowDOMAsLightDOM(e.shadowRoot,t,n):this.cloneLightDOMChildren(e,t,n)}shouldCloneChild(e){return!Kn(e)||!ar(e)&&!e.hasAttribute(`data-html2canvas-ignore`)&&(typeof this.options.ignoreElements!=`function`||!this.options.ignoreElements(e))}shouldCloneStyleElement(e){return!this.options.copyStyles||!Kn(e)||!ir(e)}safeAppendClonedChild(e,t,n){this.shouldCloneChild(t)&&this.shouldCloneStyleElement(t)&&e.appendChild(this.cloneNodeFn(t,n))}cloneAssignedNodes(e,t,n){e.forEach(e=>{this.safeAppendClonedChild(t,e,n)})}cloneSlotFallbackContent(e,t,n){for(let r=e.firstChild;r;r=r.nextSibling)this.safeAppendClonedChild(t,r,n)}cloneSlotElement(e,t,n){if(!cr(e))return;let r=e;if(typeof r.assignedNodes!=`function`){this.context.logger.warn(`HTMLSlotElement.assignedNodes is not available`,e),this.cloneSlotFallbackContent(e,t,n);return}let i=r.assignedNodes();!i||!Array.isArray(i)?(this.context.logger.warn(`assignedNodes() did not return a valid array`,e),this.cloneSlotFallbackContent(e,t,n)):i.length>0?this.cloneAssignedNodes(i,t,n):this.cloneSlotFallbackContent(e,t,n)}cloneShadowDOMChildren(e,t,n){for(let r=e.firstChild;r;r=r.nextSibling)Kn(r)&&cr(r)?this.cloneSlotElement(r,t,n):this.safeAppendClonedChild(t,r,n);this.appendAdoptedStyleSheets(e,t,n)}cloneLightDOMChildren(e,t,n){for(let r=e.firstChild;r;r=r.nextSibling)this.appendChildNode(t,r,n)}cloneSlotElementAsLightDOM(e,t,n){if(!cr(e))return;let r=e;if(typeof r.assignedNodes!=`function`){for(let r=e.firstChild;r;r=r.nextSibling)this.appendChildNode(t,r,n);return}let i=r.assignedNodes();if(i&&Array.isArray(i)&&i.length>0)i.forEach(e=>this.appendChildNode(t,e,n));else for(let r=e.firstChild;r;r=r.nextSibling)this.appendChildNode(t,r,n)}cloneShadowDOMAsLightDOM(e,t,n){for(let r=e.firstChild;r;r=r.nextSibling)Kn(r)&&cr(r)?this.cloneSlotElementAsLightDOM(r,t,n):this.appendChildNode(t,r,n);this.appendAdoptedStyleSheets(e,t,n)}appendAdoptedStyleSheets(e,t,n){if(n)return;let r=e.adoptedStyleSheets;if(!r||r.length===0)return;let i=`host`in t?t.host.ownerDocument:t.ownerDocument;if(!i)return;let a=vs(i,r,this.options.cspNonce);a&&t.appendChild(a)}},xs=[`all`,`d`,`content`],Ss=(e,t)=>{let n=[];for(let t=e.length-1;t>=0;t--){let r=e.item(t);if(xs.indexOf(r)===-1&&!r.startsWith(`--`)){let t=e.getPropertyValue(r);if(t){let i=e.getPropertyPriority(r);n.push(i?`${r}:${t} !${i}`:`${r}:${t}`)}}}return n.length>0&&(t.style.cssText=n.join(`;`)+`;`),t},Cs=`:before`,ws=`:after`,Ts=`___html2canvas___pseudoelement_before`,Es=`___html2canvas___pseudoelement_after`,Ds=`{
2
+ content: "" !important;
3
+ display: none !important;
4
+ }`,Os=(e,t)=>{ks(e,`.${Ts}${Cs}${Ds}
5
+ .${Es}${ws}${Ds}`,t)},ks=(e,t,n)=>{let r=e.ownerDocument;if(r){let i=r.createElement(`style`);i.textContent=t,n&&(i.nonce=n),e.appendChild(i)}},As=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 ps(this.context,n));let o=new fs(this.context,n),s=a.createElement(`html2canvaspseudoelement`);Ss(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(P);n.length&&n[0]&&s.appendChild(a.createTextNode(e.getAttribute(n[0].value)||``))}else if(t.name===`counter`){let[e,n]=t.values.filter(F);if(e&&P(e)){let t=this.counters.getCounterValue(e.value),r=n&&P(n)?mr.parse(this.context,n.value):3;s.appendChild(a.createTextNode(Mr(t,r,!1)))}}else if(t.name===`counters`){let[e,n,r]=t.values.filter(F);if(e&&P(e)){let t=this.counters.getCounterValues(e.value),i=r&&P(r)?mr.parse(this.context,r.value):3,o=n&&n.type===0?n.value:``,c=t.map(e=>Mr(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(Vr(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(Vr(o.quotes,this.quoteDepth,!1)));break}default:s.appendChild(a.createTextNode(t.value))}}),s.className=`${Ts} ${Es}`;let c=r===0?` ${Ts}`:` ${Es}`;return Jn(t)?t.className.baseValue+=c:t.className+=c,s}},J=e=>{if(e?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`)},js=new WeakMap,Ms=e=>{let t=e&&e.trustedTypes;if(!t)return null;if(js.has(t))return js.get(t)??null;let n=null;try{n=t.getPolicy?.(`html2canvas-pro`)??t.createPolicy(`html2canvas-pro`,{createHTML:e=>e})}catch{n=null}return js.set(t,n),n},Ns=(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(ys,`true`),(n||e.body).appendChild(r),r},Ps=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(Ps)),Is=(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(Error(`Cloned iframe did not fire its load event within ${ns}ms`))},ns),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=Math.ceil(ts/50),u=0;s=setInterval(()=>{u++,n?.aborted?l():o.body.childNodes.length>0&&o.readyState===`complete`?(clearInterval(s),s=void 0,clearTimeout(c),r(e)):u>=i&&(clearInterval(s),s=void 0,t?.warn(`Cloned iframe did not become ready within ${ts/1e3} seconds; continuing with a possibly incomplete document`),r(e))},50)},n&&(n.aborted?l():n.addEventListener(`abort`,l,{once:!0}))}),Ls=e=>{let t=``;return e&&(t+=`<!DOCTYPE `,e.name&&(t+=e.name),e.internalSubset&&(t+=` `+e.internalSubset.replace(/"/g,`&quot;`).replace(/>/g,`&gt;`)),e.publicId?(t+=` PUBLIC "`+e.publicId.replace(/"/g,`&quot;`)+`"`,e.systemId&&(t+=` "`+e.systemId.replace(/"/g,`&quot;`)+`"`)):e.systemId&&(t+=` SYSTEM "`+e.systemId.replace(/"/g,`&quot;`)+`"`),t+=`>`),t},Rs=(e,t,n)=>{e&&e.defaultView&&(t!==e.defaultView.pageXOffset||n!==e.defaultView.pageYOffset)&&e.defaultView.scrollTo(t,n)},zs=([e,t,n])=>{e.scrollLeft=t,e.scrollTop=n},Bs=(e,t)=>{let n=e.ownerDocument.createElement(`base`);n.href=t;let r=e.getElementsByTagName(`head`).item(0);r?.insertBefore(n,r?.firstChild??null)},Vs=(e,t,n,r)=>{let i=Ns(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=Is(i,e.logger,r.signal).then(async()=>{r.scrolledElements.forEach(zs),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 J(r.signal),c.fonts&&c.fonts.ready&&await c.fonts.ready,J(r.signal),/(AppleWebKit)/g.test(navigator.userAgent)&&(await Fs(c),J(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=Ls(t.doctype)+`<html></html>`;try{let e=Ms(t.defaultView),n=e?e.createHTML(d):d;c.write(n)}catch{c.write(d)}Rs(t,a,o),c.close();let f=c.adoptNode(r.documentElement);return Bs(f,u),c.replaceChild(f,c.documentElement),l},Hs=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},Us=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 hr,this.pseudoContents=new As(e,this.counters),this.slotCloner=new bs((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=Hs(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=vs(this.documentElement.ownerDocument??e,t,this.options.cspNonce);r&&n.appendChild(r)}toIFrame(e,t){return Vs(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(gs(e,2))debugger;if(er(e))return this.createCanvasClone(e);if(tr(e))return this.createVideoClone(e);if(ir(e))return this.createStyleClone(e);let t=e.cloneNode(!1);return nr(t)&&(nr(e)&&e.currentSrc&&e.currentSrc!==e.src&&(t.src=e.currentSrc,t.srcset=``),t.loading===`lazy`&&(t.loading=`eager`)),dr(t)&&!Jn(t)?this.createCustomElementClone(e,t):t}createCustomElementClone(e,t){let n=document.createElement(`div`);n.className=t.className,Ss(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(qn(e))return(e.ownerDocument??document).createTextNode(e.data);if(!e.ownerDocument)return e.cloneNode(!1);let n=e.ownerDocument.defaultView;if(n&&Kn(e)&&(Yn(e)||Jn(e))){let r=this.createElementClone(e);r.style.transitionProperty=`none`;let i=n.getComputedStyle(e),a=pr(e);this.referenceElement===e&&Yn(r)&&(this.clonedReferenceElement=r),$n(r)&&Os(r,this.options.cspNonce);let o=this.counters.parse(new ps(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(dr(e)&&(t=!0),tr(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||Jn(e))&&!rr(e)||t)&&Ss(i,r),(e.scrollTop!==0||e.scrollLeft!==0)&&this.scrolledElements.push([r,e.scrollLeft,e.scrollTop]),(or(e)||sr(e))&&(or(r)||sr(r))&&(r.value=e.value),r}return e.cloneNode(!1)}static destroy(e){return e.parentNode?(e.parentNode.removeChild(e),!0):!1}},Ws=class{static normalizeElement(e,t){let n={};if(!Yn(e)&&!Jn(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){(Yn(e)||Jn(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))}},Gs=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,gs(t,3))debugger;if(this.styles=new us(e,e.config.window.getComputedStyle(t,null)),n.normalizeDom!==!1&&(Yn(t)||Jn(t))&&(this.originalStyles=Ws.normalizeElement(t,this.styles),this.originalElement=t),this.bounds=g(this.context,t),t.tagName===`FIELDSET`){let e=t.querySelector(`:scope > legend`);if(e){let t=g(this.context,e);this.legendBounds=t;let n=t.top+t.height/2-this.styles.borderTopWidth/2;this.bounds=new h(this.bounds.left,n,this.bounds.width,this.bounds.height-(n-this.bounds.top))}}gs(t,4)&&(this.debugRender=!0)}restore(){this.originalStyles&&this.originalElement&&(Ws.restoreElement(this.originalElement,this.originalStyles),this.originalStyles=void 0,this.originalElement=void 0)}restoreTree(){this.restore();for(let e of this.elements)e.restoreTree()}},Ks=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},qs=()=>new Image().crossOrigin!==void 0,Js=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},Ys=(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},Xs=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))}`}),Zs={get SUPPORT_RANGE_BOUNDS(){"use strict";let e=Ks(document);return Object.defineProperty(Zs,"SUPPORT_RANGE_BOUNDS",{value:e}),e},get SUPPORT_SVG_DRAWING(){"use strict";let e=Js(document);return Object.defineProperty(Zs,"SUPPORT_SVG_DRAWING",{value:e}),e},get SUPPORT_CORS_IMAGES(){"use strict";let e=qs();return Object.defineProperty(Zs,"SUPPORT_CORS_IMAGES",{value:e}),e}},Qs=class{text;bounds;constructor(e,t){this.text=e,this.bounds=t}},$s=(e,t,n,r)=>{let i=oc(t,n),a=[],o=0;return i.forEach(t=>{if(n.textDecorationLine.length||t.trim().length>0){if(Zs.SUPPORT_RANGE_BOUNDS){let n=tc(r,o,t.length).getClientRects();if(n.length>1){let n=ic(t),i=0;n.forEach(t=>{a.push(new Qs(t,h.fromDOMRectList(e,tc(r,i+o,t.length).getClientRects()))),i+=t.length})}else a.push(new Qs(t,h.fromDOMRectList(e,n)))}else{let n=r.splitText(t.length);a.push(new Qs(t,ec(e,r))),r=n}}else Zs.SUPPORT_RANGE_BOUNDS||(r=r.splitText(t.length));o+=t.length}),a},ec=(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=g(e,r);return r.firstChild&&i.replaceChild(r.firstChild,r),n}}return h.EMPTY},tc=(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},nc=new Map,rc=e=>{let t=nc.get(e);return t||(t=new Intl.Segmenter(void 0,{granularity:e}),nc.set(e,t)),t},ic=e=>Array.from(rc(`grapheme`).segment(e),e=>e.segment),ac=e=>Array.from(rc(`word`).segment(e),e=>e.segment),oc=(e,t)=>Ka(t.writingMode)?ic(e):t.letterSpacing===0?ac(e):ic(e),sc=class{text;textBounds;constructor(e,t,n){this.text=cc(t.data,n.textTransform),this.text.length!==t.data.length&&(t.data=this.text),this.textBounds=$s(e,this.text,n,t)}},cc=(e,t)=>{switch(t){case 1:return e.toLowerCase();case 3:return e.replace(lc,uc);case 2:return e.toUpperCase();default:return e}},lc=/(^|\s|:|-|\(|\))([a-z])/g,uc=(e,t,n)=>e.length>0?t+n.toUpperCase():e,dc=class extends Gs{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)}},fc=class extends Gs{canvas;intrinsicWidth;intrinsicHeight;constructor(e,t,n={}){super(e,t,n),this.canvas=t,this.intrinsicWidth=t.width,this.intrinsicHeight=t.height}},pc=[`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`],mc=(e,t)=>{let n=t.getAttribute(`style`);pc.forEach(e=>t.style.removeProperty(e));let r=e.serializeToString(t);return n===null?t.removeAttribute(`style`):t.setAttribute(`style`,n),r},hc=class extends Gs{svg;intrinsicWidth;intrinsicHeight;constructor(e,t,n={}){super(e,t,n);let r=new XMLSerializer,i=g(e,t);t.setAttribute(`width`,`${i.width}px`),t.setAttribute(`height`,`${i.height}px`),this.svg=`data:image/svg+xml,${encodeURIComponent(mc(r,t))}`,this.intrinsicWidth=t.width.baseVal.value,this.intrinsicHeight=t.height.baseVal.value,this.context.cache.addImage(this.svg)}},gc=class extends Gs{value;constructor(e,t,n={}){super(e,t,n),this.value=t.value}},_c=class extends Gs{start;reversed;constructor(e,t,n={}){super(e,t,n),this.start=t.start,this.reversed=typeof t.reversed==`boolean`&&t.reversed===!0}},vc=[{type:15,flags:0,unit:`px`,number:3}],yc=[{type:16,flags:0,number:50}],bc=e=>e.width>e.height?new h(e.left+(e.width-e.height)/2,e.top,e.height,e.height):e.width<e.height?new h(e.left,e.top+(e.height-e.width)/2,e.width,e.width):e,xc=e=>{let t=e.type===`password`?Array(e.value.length+1).join(`•`):e.value;return t.length===0?e.placeholder||``:t},Sc=e=>e.value.length===0&&!!e.placeholder,Cc=`checkbox`,wc=`radio`,Tc=1970632191,Ec=class extends Gs{type;checked;value;isPlaceholder;constructor(e,t,n={}){switch(super(e,t,n),this.type=t.type.toLowerCase(),this.checked=t.checked,this.value=xc(t),this.isPlaceholder=Sc(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=bc(this.bounds)),this.type){case Cc:this.styles.borderTopRightRadius=this.styles.borderTopLeftRadius=this.styles.borderBottomRightRadius=this.styles.borderBottomLeftRadius=vc;break;case wc:this.styles.borderTopRightRadius=this.styles.borderTopLeftRadius=this.styles.borderBottomRightRadius=this.styles.borderBottomLeftRadius=yc}}},Dc=class extends Gs{value;constructor(e,t,n={}){super(e,t,n);let r=t.options[t.selectedIndex||0];this.value=r&&r.text||``}},Oc=class extends Gs{value;constructor(e,t,n={}){super(e,t,n),this.value=t.value}},kc=class extends Gs{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=Wn(e,n.getComputedStyle(r.documentElement).backgroundColor),i=r.body?Wn(e,n.getComputedStyle(r.body).backgroundColor):0;this.backgroundColor=tt(t)?tt(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)}}},Ac=[`OL`,`UL`,`MENU`],jc=(e,t,n,r,i=1,a={})=>{for(let o=t.firstChild,s;o;o=s)s=o.nextSibling,Mc(e,o,n,r,i,a)},Mc=(e,t,n,r,i=1,a={})=>{if(qn(t)&&t.data.length>0){let r=new sc(e,t,n.styles);if(i!==1){let e=n.bounds.left,t=n.bounds.top;r.textBounds=r.textBounds.map(n=>new Qs(n.text,new h(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(Kn(t)){if(cr(t)&&t.assignedNodes)t.assignedNodes().forEach(t=>Mc(e,t,n,r,i,a));else{let o=Nc(e,t,a),s=o.styles.zoom||1;if(s!==1&&(o.bounds=new h(o.bounds.left,o.bounds.top,o.bounds.width/s,o.bounds.height/s)),o.styles.isVisible()){Fc(t,o,r)?o.createsRealStackingContext=!0:Ic(o.styles)&&(o.createsStackingContext=!0),Ac.indexOf(t.tagName)!==-1&&(o.isListOwner=!0),n.elements.push(o);let s=i*(o.styles.zoom||1);t.shadowRoot?jc(e,t.shadowRoot,o,r,s,a):!or(t)&&!Qn(t)&&!sr(t)&&jc(e,t,o,r,s,a)}}}},Nc=(e,t,n={})=>nr(t)?new dc(e,t,n):er(t)?new fc(e,t,n):Qn(t)?new hc(e,t,n):lr(t)?new gc(e,t,n):ur(t)?new _c(e,t,n):Xn(t)?new Ec(e,t,n):sr(t)?new Dc(e,t,n):or(t)?new Oc(e,t,n):rr(t)?new kc(e,t,(e,t)=>Pc(e,t,n),n):new Gs(e,t,n),Pc=(e,t,n={})=>{let r=Nc(e,t,n);return r.createsRealStackingContext=!0,jc(e,t,r,r,1,n),r},Fc=(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()||$n(e)&&n.styles.isTransparent(),Ic=e=>e.isPositioned()||e.isFloating()||e.mixBlendMode!==q.NORMAL?!0:G(e.display,268435456)||G(e.display,33554432)||G(e.display,536870912)||G(e.display,134217728),Lc=(e,t)=>e.length===t.length&&e.some((e,n)=>e===t[n]),Rc=(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}),Y=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)}},zc=(e,t,n)=>new Y(e.x+(t.x-e.x)*n,e.y+(t.y-e.y)*n),Bc=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=zc(this.start,this.startControl,t),i=zc(this.startControl,this.endControl,t),a=zc(this.endControl,this.end,t),o=zc(r,i,t),s=zc(i,a,t),c=zc(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)}},X=e=>e.type===1,Vc=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]=Ke(t.borderTopLeftRadius,n.width,n.height),[a,o]=Ke(t.borderTopRightRadius,n.width,n.height),[s,c]=Ke(t.borderBottomRightRadius,n.width,n.height),[l,u]=Ke(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=H(t.paddingTop,e.bounds.width),S=H(t.paddingRight,e.bounds.width),C=H(t.paddingBottom,e.bounds.width),w=H(t.paddingLeft,e.bounds.width);this.topLeftBorderDoubleOuterBox=r>0||i>0?Z(n.left+b/3,n.top+_/3,r-b/3,i-_/3,0):new Y(n.left+b/3,n.top+_/3),this.topRightBorderDoubleOuterBox=a>0||o>0?Z(n.left+p,n.top+_/3,a-v/3,o-_/3,1):new Y(n.left+n.width-v/3,n.top+_/3),this.bottomRightBorderDoubleOuterBox=s>0||c>0?Z(n.left+h,n.top+m,s-v/3,c-y/3,2):new Y(n.left+n.width-v/3,n.top+n.height-y/3),this.bottomLeftBorderDoubleOuterBox=l>0||u>0?Z(n.left+b/3,n.top+g,l-b/3,u-y/3,3):new Y(n.left+b/3,n.top+n.height-y/3),this.topLeftBorderDoubleInnerBox=r>0||i>0?Z(n.left+b*2/3,n.top+_*2/3,r-b*2/3,i-_*2/3,0):new Y(n.left+b*2/3,n.top+_*2/3),this.topRightBorderDoubleInnerBox=a>0||o>0?Z(n.left+p,n.top+_*2/3,a-v*2/3,o-_*2/3,1):new Y(n.left+n.width-v*2/3,n.top+_*2/3),this.bottomRightBorderDoubleInnerBox=s>0||c>0?Z(n.left+h,n.top+m,s-v*2/3,c-y*2/3,2):new Y(n.left+n.width-v*2/3,n.top+n.height-y*2/3),this.bottomLeftBorderDoubleInnerBox=l>0||u>0?Z(n.left+b*2/3,n.top+g,l-b*2/3,u-y*2/3,3):new Y(n.left+b*2/3,n.top+n.height-y*2/3),this.topLeftBorderStroke=r>0||i>0?Z(n.left+b/2,n.top+_/2,r-b/2,i-_/2,0):new Y(n.left+b/2,n.top+_/2),this.topRightBorderStroke=a>0||o>0?Z(n.left+p,n.top+_/2,a-v/2,o-_/2,1):new Y(n.left+n.width-v/2,n.top+_/2),this.bottomRightBorderStroke=s>0||c>0?Z(n.left+h,n.top+m,s-v/2,c-y/2,2):new Y(n.left+n.width-v/2,n.top+n.height-y/2),this.bottomLeftBorderStroke=l>0||u>0?Z(n.left+b/2,n.top+g,l-b/2,u-y/2,3):new Y(n.left+b/2,n.top+n.height-y/2),this.topLeftBorderBox=r>0||i>0?Z(n.left,n.top,r,i,0):new Y(n.left,n.top),this.topRightBorderBox=a>0||o>0?Z(n.left+p,n.top,a,o,1):new Y(n.left+n.width,n.top),this.bottomRightBorderBox=s>0||c>0?Z(n.left+h,n.top+m,s,c,2):new Y(n.left+n.width,n.top+n.height),this.bottomLeftBorderBox=l>0||u>0?Z(n.left,n.top+g,l,u,3):new Y(n.left,n.top+n.height),this.topLeftPaddingBox=r>0||i>0?Z(n.left+b,n.top+_,Math.max(0,r-b),Math.max(0,i-_),0):new Y(n.left+b,n.top+_),this.topRightPaddingBox=a>0||o>0?Z(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 Y(n.left+n.width-v,n.top+_),this.bottomRightPaddingBox=s>0||c>0?Z(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 Y(n.left+n.width-v,n.top+n.height-y),this.bottomLeftPaddingBox=l>0||u>0?Z(n.left+b,n.top+Math.min(g,n.height-y),Math.max(0,l-b),Math.max(0,u-y),3):new Y(n.left+b,n.top+n.height-y),this.topLeftContentBox=r>0||i>0?Z(n.left+b+w,n.top+_+x,Math.max(0,r-(b+w)),Math.max(0,i-(_+x)),0):new Y(n.left+b+w,n.top+_+x),this.topRightContentBox=a>0||o>0?Z(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 Y(n.left+n.width-(v+S),n.top+_+x),this.bottomRightContentBox=s>0||c>0?Z(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 Y(n.left+n.width-(v+S),n.top+n.height-(y+C)),this.bottomLeftContentBox=l>0||u>0?Z(n.left+b+w,n.top+g,Math.max(0,l-(b+w)),u-(y+C),3):new Y(n.left+b+w,n.top+n.height-(y+C))}},Z=(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 Bc(new Y(e,l),new Y(e,l-s),new Y(c-o,t),new Y(c,t));case 1:return new Bc(new Y(e,t),new Y(e+o,t),new Y(c,l-s),new Y(c,l));case 2:return new Bc(new Y(c,t),new Y(c,t+s),new Y(e+o,l),new Y(e,l));default:return new Bc(new Y(c,l),new Y(c-o,l),new Y(e,t+s),new Y(e,t))}},Hc=e=>[e.topLeftBorderBox,e.topRightBorderBox,e.bottomRightBorderBox,e.bottomLeftBorderBox],Uc=e=>[e.topLeftContentBox,e.topRightContentBox,e.bottomRightContentBox,e.bottomLeftContentBox],Wc=e=>[e.topLeftPaddingBox,e.topRightPaddingBox,e.bottomRightPaddingBox,e.bottomLeftPaddingBox],Gc=class{offsetX;offsetY;matrix;type=0;target=6;constructor(e,t,n){this.offsetX=e,this.offsetY=t,this.matrix=n}},Kc=class{path;target;type=1;constructor(e,t){this.path=e,this.target=t}},qc=class{opacity;type=2;target=6;constructor(e){this.opacity=e}},Jc=class{applyClip;type=3;target=6;constructor(e){this.applyClip=e}},Yc={[q.NORMAL]:`source-over`,[q.MULTIPLY]:`multiply`,[q.SCREEN]:`screen`,[q.OVERLAY]:`overlay`,[q.DARKEN]:`darken`,[q.LIGHTEN]:`lighten`,[q.COLOR_DODGE]:`color-dodge`,[q.COLOR_BURN]:`color-burn`,[q.HARD_LIGHT]:`hard-light`,[q.SOFT_LIGHT]:`soft-light`,[q.DIFFERENCE]:`difference`,[q.EXCLUSION]:`exclusion`,[q.HUE]:`hue`,[q.SATURATION]:`saturation`,[q.COLOR]:`color`,[q.LUMINOSITY]:`luminosity`},Xc=class{mixBlendMode;type=4;target=6;compositeOperation;constructor(e){this.mixBlendMode=e,this.compositeOperation=Yc[e]}},Zc=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(v(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:v(r,0),offsetY:v(r,1),blur:r.length>2?v(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)}},Qc=e=>e.type===0,$c=e=>e.type===1,el=e=>e.type===2,tl=e=>e.type===3,nl=e=>e.type===4,rl=e=>e.type===5,il=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=[]}},al=class{container;parent;effects=[];curves;listValue;plainEffectsCache=null;constructor(e,t){if(this.container=e,this.parent=t,this.curves=new Vc(this.container),this.container.styles.opacity<1&&this.effects.push(new qc(this.container.styles.opacity)),this.container.styles.translate!==null){let e=this.container.styles.transformOrigin,t=this.container.bounds.left+H(e[0],this.container.bounds.width),n=this.container.bounds.top+H(e[1],this.container.bounds.height),[r,i]=this.container.styles.translate,a=H(r,this.container.bounds.width),o=H(i,this.container.bounds.height);this.effects.push(new Gc(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+H(e[0],this.container.bounds.width),n=this.container.bounds.top+H(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 Gc(t,n,o))}if(this.container.styles.scale!==null){let e=this.container.styles.transformOrigin,t=this.container.bounds.left+H(e[0],this.container.bounds.width),n=this.container.bounds.top+H(e[1],this.container.bounds.height),[r,i]=this.container.styles.scale;this.effects.push(new Gc(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+H(e[0],this.container.bounds.width),n=this.container.bounds.top+H(e[1],this.container.bounds.height),r=this.container.styles.transform;this.effects.push(new Gc(t,n,r))}if(ol(this.container.styles)){let e=Hc(this.curves),t=Wc(this.curves);Lc(e,t)?this.effects.push(new Kc(e,6)):(this.effects.push(new Kc(e,2)),this.effects.push(new Kc(t,4)))}if(this.container.styles.clipPath.type!==0){let e=cl(this.container.styles.clipPath,this.container.bounds);e&&this.effects.push(e)}if(this.container.styles.mixBlendMode!==q.NORMAL&&this.effects.push(new Xc(this.container.styles.mixBlendMode)),this.container.styles.filter!==null&&this.effects.push(new Zc(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 Gc(e,t,r))}}getEffects(e,t){if(!t){let t=this.plainEffectsCache;t||(t=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||!rl(n)&&!el(n)&&!nl(n)),a=i(this);for(;r;){let e=i(r).filter(e=>!$c(e));if(n||r.container.styles.position!==0||!r.parent){if(n=[2,3].indexOf(r.container.styles.position)===-1,ol(r.container.styles)){let e=Hc(r.curves),t=Wc(r.curves);Lc(e,t)||a.unshift(new Kc(t,6))}a.unshift(...e)}else a.unshift(...e);r=r===t?null:r.parent}return a.filter(t=>G(t.target,e))}},ol=e=>e.overflowX!==0||e.overflowY!==0,sl=(e,t,n,r,i)=>e===`closest-side`?Math.min(t-n,r-t):e===`farthest-side`?Math.max(t-n,r-t):H(e,i),cl=(e,t)=>{let{left:n,top:r,width:i,height:a}=t;switch(e.type){case 1:{let t=H(e.left,i),o=H(e.top,a),s=n+t,c=r+o,l=Math.max(0,i-t-H(e.right,i)),u=Math.max(0,a-o-H(e.bottom,a));return new Jc(e=>{e.beginPath(),e.rect(s,c,l,u),e.clip()})}case 2:{let t=n+H(e.cx,i),o=r+H(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):H(e.radius,Math.sqrt(i*i+a*a)/Math.SQRT2),new Jc(e=>{e.beginPath(),e.arc(t,o,Math.max(0,s),0,Math.PI*2),e.clip()})}case 3:{let t=n+H(e.cx,i),o=r+H(e.cy,a),s=sl(e.rx,t,n,n+i,i),c=sl(e.ry,o,r,r+a,a);return new Jc(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+H(e,i),r+H(t,a)]);return new Jc(e=>{if(e.beginPath(),t.length>0){e.moveTo(v(v(t,0),0),v(v(t,0),1));for(let n=1;n<t.length;n++)e.lineTo(v(v(t,n),0),v(v(t,n),1));e.closePath()}e.clip()})}case 5:{let{d:t}=e,i=null;return new Jc(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+H(e.x,i),o=r+H(e.y,a),s=Math.max(0,H(e.width,i)),c=Math.max(0,H(e.height,a));return new Jc(e=>{e.beginPath(),e.rect(t,o,s,c),e.clip()})}case 0:return null;default:return null}},ll=(e,t,n,r)=>{e.container.elements.forEach(i=>{let a=i.createsRealStackingContext,o=i.createsStackingContext,s=new al(i,e);G(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 il(s);if(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);ll(s,r,a?r:n,c)}else i.styles.isInlineLevel()?t.inlineLevel.push(s):t.nonInlineLevel.push(s),ll(s,t,n,c);i.isListOwner&&ul(i,c)})},ul=(e,t)=>{let n=e instanceof _c?e.start:1,r=e instanceof _c&&e.reversed;for(let e=0;e<t.length;e++){let i=v(t,e);i.container instanceof gc&&typeof i.container.value==`number`&&i.container.value!==0&&(n=i.container.value),i.listValue=Mr(n,i.container.styles.listStyleType,!0),n+=r?-1:1}},dl=e=>{let t=new al(e,null),n=new il(t),r=[];return ll(t,n,n,r),ul(t.container,r),n},fl=e=>Math.min(1,Math.max(0,e)),pl=e=>{let t=v(e,0),n=v(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:U(a.color)})}let o=i[i.length-1];return(!o||o.stop<1)&&i.push({stop:1,color:U(n.color)}),i},ml=e=>e.map(e=>({stop:fl(e.stop),color:U(e.color)})),hl=(e,t,n,r,i=!1)=>{let a=Jr(r,t),o=U(v(a,a.length-1).color),s=e.createElement(`canvas`);s.width=Math.max(1,Math.ceil(t*2)),s.height=Math.max(1,Math.ceil(n*2));let c=s.getContext(`2d`);if(!c)return null;let l;if(i){let e=pl(a);if(!e)return c.fillStyle=o,c.fillRect(0,0,s.width,s.height),{canvas:s,lastColor:o,rx:t,ry:n};l=e}else l=ml(a);let u=c.createRadialGradient(t,t,0,t,t,t);return l.forEach(e=>u.addColorStop(fl(e.stop),e.color)),c.fillStyle=u,t!==n&&c.scale(1,n/t),c.fillRect(0,0,t*2,t*2),{canvas:s,lastColor:o,rx:t,ry:n}},gl=e=>{let t=e.bounds,n=e.styles;return t.add(n.borderLeftWidth,n.borderTopWidth,-(n.borderRightWidth+n.borderLeftWidth),-(n.borderTopWidth+n.borderBottomWidth))},_l=e=>{let t=e.styles,n=e.bounds,r=H(t.paddingLeft,n.width),i=H(t.paddingRight,n.width),a=H(t.paddingTop,n.width),o=H(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))},vl=(e,t)=>e===0?t.bounds:e===2?_l(t):gl(t),yl=(e,t)=>e===0?t.bounds:e===2?_l(t):gl(t),bl=(e,t,n)=>{let r=vl(wl(e.styles.backgroundOrigin,t),e),i=yl(wl(e.styles.backgroundClip,t),e),a=Cl(wl(e.styles.backgroundSize,t),n,r),[o,s]=a,c=Ke(wl(e.styles.backgroundPosition,t),r.width-o,r.height-s),l=Tl(wl(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]},xl=e=>P(e)&&e.value===`auto`,Sl=e=>typeof e==`number`,Cl=(e,[t,n,r],i)=>{let[a,o]=e;if(!a)return[0,0];if(R(a)&&o&&R(o))return[H(a,i.width),H(o,i.height)];let s=Sl(r);if(P(a)&&(a.value===`contain`||a.value===`cover`))return Sl(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=Sl(t),l=Sl(n),u=c||l;if(xl(a)&&(!o||xl(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 R(a)?e=H(a,i.width):o&&R(o)&&(t=H(o,i.height)),xl(a)?e=t*r:(!o||xl(o))&&(t=e/r),[e,t]}let d=null,f=null;if(R(a)?d=H(a,i.width):o&&R(o)&&(f=H(o,i.height)),d!==null&&(!o||xl(o))&&(f=c&&l?d/t*n:i.height),f!==null&&xl(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`)},wl=(e,t)=>{let n=e[t];return n===void 0?v(e,0):n},Tl=(e,[t,n],[r,i],a,o)=>{switch(e){case 2:return[new Y(Math.round(a.left),Math.round(a.top+n)),new Y(Math.round(a.left+a.width),Math.round(a.top+n)),new Y(Math.round(a.left+a.width),Math.round(i+a.top+n)),new Y(Math.round(a.left),Math.round(i+a.top+n))];case 3:return[new Y(Math.round(a.left+t),Math.round(a.top)),new Y(Math.round(a.left+t+r),Math.round(a.top)),new Y(Math.round(a.left+t+r),Math.round(a.height+a.top)),new Y(Math.round(a.left+t),Math.round(a.height+a.top))];case 1:return[new Y(Math.round(a.left+t),Math.round(a.top+n)),new Y(Math.round(a.left+t+r),Math.round(a.top+n)),new Y(Math.round(a.left+t+r),Math.round(a.top+n+i)),new Y(Math.round(a.left+t),Math.round(a.top+n+i))];default:return[new Y(Math.round(o.left),Math.round(o.top)),new Y(Math.round(o.left+o.width),Math.round(o.top)),new Y(Math.round(o.left+o.width),Math.round(o.height+o.top)),new Y(Math.round(o.left),Math.round(o.height+o.top))]}},Q=class extends Error{},$=e=>{e.width=e.height=0},El=[`brightness`,`contrast`,`grayscale`,`hue-rotate`,`invert`,`opacity`,`saturate`,`sepia`],Dl=256,Ol=new Map,kl={functions:[]};function Al(e){if(!e||e===`none`)return kl;let t=Ol.get(e);if(t!==void 0)return Ol.delete(e),Ol.set(e,t),t;let n=jl(e);if(Ol.size>=Dl){let e=Ol.keys().next().value;e!==void 0&&Ol.delete(e)}return Ol.set(e,n),n}var jl=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r===` `||r===`
6
+ `||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=Ml(e,i);if(o===-1)return null;let s=Pl(a,e.slice(i+1,o).trim());if(!s)return null;t.push(s),n=o+1}return{functions:t}},Ml=(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},Nl=/^-?\d+(?:\.\d+)?px$/,Pl=(e,t)=>{if(e===`blur`){if(t===`0`)return{kind:`blur`,value:0};if(!Nl.test(t))return null;let e=Number.parseFloat(t);return e<0?null:{kind:`blur`,value:e}}if(e===`drop-shadow`)return Il(t);if(El.indexOf(e)!==-1){let n=e;if(n===`hue-rotate`){let e=Ll(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},Fl=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},Il=e=>{let t=Fl(e),n=t.filter(e=>Nl.test(e)).map(e=>Number.parseFloat(e));if(n.length<2||n.length>3)return null;let r=t.filter(e=>!Nl.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},Ll=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},Rl=(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 zl(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 Bl(e){let t=(e.ownerDocument??document).createElement(`canvas`);return t.width=e.width,t.height=e.height,t}var Vl=(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 Q(`Filter surface image decode timed out`)),1e4);t?.addEventListener(`abort`,a,{once:!0}),t?.aborted?a():e.decode().then(()=>i(),()=>i(new Q(`Filter surface image decode failed`)))}),Hl=new WeakMap;function Ul(e=document){let t=Hl.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{$(n),$(r)}return Hl.set(e,i),i}function Wl(e,t,n,r,i){let a,o,s=!1;try{J(i),a=Bl(e);let c=a.getContext(`2d`);if(!c||!(`filter`in c)||(c.filter=Rl(t,r),c.filter===`none`||c.filter===``))return null;c.drawImage(e,0,0),J(i),o=Bl(e);let l=o.getContext(`2d`);return l?(l.globalAlpha=n,l.drawImage(a,0,0),J(i),s=!0,o):null}catch{return J(i),null}finally{a&&$(a),o&&!s&&$(o)}}var Gl=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 Kl(e,t,n,r,i){if(J(i),t.functions.length>0&&Ul(e.ownerDocument??document)){let a=Wl(e,t,n,r,i);if(a)return a}if(!Gl(t))throw new Q(`Filter chain requires native canvas filters`);return ql(e,t,n,r,i)}async function ql(e,t,n,r,i){J(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=Bl(e),r=t.getContext(`2d`);if(!r)throw $(t),new Q(`Filter surface canvas is unavailable`);r.globalAlpha=n;try{return r.drawImage(e,0,0),t}catch{throw $(t),new Q(`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 Q(`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 Vl(g,i),J(i),_=Bl(e);let t=_.getContext(`2d`);if(!t)throw new Q(`Filter surface canvas is unavailable`);return t.globalAlpha=n,t.drawImage(g,0,0),_}catch(e){throw _&&$(_),i?.aborted&&J(i),e instanceof Q?e:new Q(`Filter surface image cannot be drawn`)}finally{g.removeAttribute(`src`)}}function Jl(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)}var Yl=(e,t)=>e.add(-t,-t,t*2,t*2),Xl=(e,t)=>new h(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 Zl(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=Xl(n,Yl(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=Yl(i.bounds,2*H(t.fontSize,e.bounds.height)+t.webkitTextStrokeWidth);n=Xl(n,r);for(let e of t.textShadow)n=Xl(n,Yl(r.add(e.offsetX.number,e.offsetY.number,0,0),3*e.blur.number))}for(let t of e.elements)t.styles.isVisible()&&(n=Xl(n,Zl(t)));let r=Al(t.filter);return Yl(n,r?zl(r):0)}function Ql(e,t,n,r){let i=Yl(t,n),a=Math.floor(Math.max(e.left,i.left)*r)/r,o=Math.floor(Math.max(e.top,i.top)*r)/r,s=Math.ceil(Math.min(e.left+e.width,i.left+i.width)*r)/r,c=Math.ceil(Math.min(e.top+e.height,i.top+i.height)*r)/r;return new h(a,o,Math.max(0,s-a),Math.max(0,c-o))}var $l=class{ctx;constructor(e){this.ctx=e}render(e,t){this.ctx.fillStyle=U(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()}},eu=`Mg`,tu=e=>e!==void 0&&!Number.isNaN(e),nu=(e,t)=>{let n=e.measureText(eu),r=n;return{baseline:tu(r.fontBoundingBoxAscent)?r.fontBoundingBoxAscent:tu(n.actualBoundingBoxAscent)?n.actualBoundingBoxAscent:t,height:tu(r.fontBoundingBoxAscent)&&tu(r.fontBoundingBoxDescent)?r.fontBoundingBoxAscent+r.fontBoundingBoxDescent:tu(n.actualBoundingBoxAscent)&&tu(n.actualBoundingBoxDescent)?n.actualBoundingBoxAscent+n.actualBoundingBoxDescent:t}},ru=(e,t)=>nu(e,t).baseline,iu=1,au=/[\u2E80-\u2FFF\u3000-\u30FF\u3400-\u4DBF\u4E00-\u9FFF\uAC00-\uD7AF\uF900-\uFAFF\uFF01-\uFFEF]/,ou=e=>au.test(e),su=()=>typeof navigator>`u`?!1:navigator.userAgentData!==void 0||(typeof window<`u`?window:void 0)?.chrome!==void 0,cu=()=>su()?`miter`:`round`,lu=class{ctx;options;decorationRenderer;baselineCache=new Map;glyphWidthCache=null;constructor(e){this.ctx=e.ctx,this.options=e.options,this.decorationRenderer=new $l(e.ctx)}cachedMeasureText(e,t){let n=this.glyphWidthCache;n||(n=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=ic(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=ic(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(!(qa(r)||!ou(u)&&u.trim().length>0)){let r=this.ctx.textBaseline;ou(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(!qa(r)&&!ou(e)&&e.trim().length===0)break;if(qa(r)||!ou(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=U(t.webkitTextStrokeColor),this.ctx.lineWidth=t.webkitTextStrokeWidth,this.ctx.lineJoin=cu(),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=U(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=ic(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=M(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 U(e.webkitTextFillColor??e.color)}renderLineClampedText(e,t,n,r,i){let a=ya(t.lineHeight,t.fontSize.number),o=[],s=[],c=v(e.textBounds,0).bounds.top;e.textBounds.forEach(e=>{Math.abs(e.bounds.top-c)>=a*.5?(s.length>0&&o.push(s),s=[e],c=e.bounds.top):s.push(e)}),s.length>0&&o.push(s);let l=t.webkitLineClamp;if(o.length<=l)return!1;for(let e=0;e<l-1;e++)v(o,e).forEach(e=>this.renderTextBoundWithPaintOrder(e,t,n,r));let u=o[l-1];if(u?.length&&i){let e=u.map(e=>e.text).join(``),a=v(u,0),o=i.width-(a.bounds.left-i.left),s=new Qs(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=ya(t.lineHeight,t.fontSize.number),o=v(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+iu)return!1;let c=new Qs(this.truncateTextWithEllipsis(s,i.width,t.letterSpacing),v(e.textBounds,0).bounds);for(let e of n)e===0?this.renderTextFillWithShadows(c,t,r):e===1&&this.renderTextStrokeWithStyle(c,t,r);return!0}measureBaselineCached(e,t){let n=this.baselineCache.get(e);return n===void 0&&(n=ru(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=U(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 ic(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}}}},uu=(e,t)=>{t.forEach((t,n)=>{let r=X(t)?t.start:t;n===0?e.moveTo(r.x,r.y):e.lineTo(r.x,r.y),X(t)&&e.bezierCurveTo(t.startControl.x,t.startControl.y,t.endControl.x,t.endControl.y,t.end.x,t.end.y)})},du=(e,t)=>{e.beginPath(),uu(e,t),e.closePath()},fu=class{maxSize;_map;constructor(e){this.maxSize=e,this._map=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()}},pu=class{ctx;context;canvas;patternCache=new fu(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):yi(i)?this.renderLinearGradient(e,i,t):xi(i)?this.renderRepeatingLinearGradient(e,i,t):bi(i)?this.renderRadialGradient(e,i,t):Si(i)?this.renderRepeatingRadialGradient(e,i,t):Ci(i)?this.renderConicGradient(e,i,t):wi(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]=bl(e,n,[t,a,t/a]),d=wl(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]=bl(e,n,[null,null,null]),[c,l,u,d,f]=Xr(t.angle,o,s),p=i+l,m=i+u,h=a+d,g=a+f,_=Jr(t.stops,c||1),y=pl(_),b=this.ctx.createLinearGradient(p,h,m,g);if(y)y.forEach(e=>b.addColorStop(Math.min(1,Math.max(0,e.stop)),e.color));else{let e=U(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]=bl(e,n,[null,null,null]),[c,l,u,d,f]=Xr(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);Jr(t.stops,c||1).forEach(e=>r.addColorStop(e.stop,U(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]=bl(e,n,[null,null,null]),c=t.position.length===0?[B]:t.position,l=H(v(c,0),o),u=H(v(c,c.length-1),s),[d,f]=$r(t,l,u,o,s);if((d===0||f===0)&&(d=Math.max(d,.01),f=Math.max(f,.01)),d>0&&f>0){let e=`rg|${Math.round(l)}x${Math.round(u)}|${Math.round(d)}x${Math.round(f)}|${JSON.stringify(t.stops)}`,n=Jr(t.stops,d),o=U(v(n,n.length-1).color),s=this.patternCache.get(e);if(!s){let n=hl(this.canvas.ownerDocument??document,d,f,t.stops,!1);if(!n)return;s=this.ctx.createPattern(n.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+l-d,a+u-f),this.ctx.fillStyle=s,this.ctx.fillRect(0,0,d*2,f*2),this.ctx.restore()}}renderRepeatingRadialGradient(e,t,n){let[r,i,a,o,s]=bl(e,n,[null,null,null]),c=t.position.length===0?[B]:t.position,l=H(v(c,0),o),u=H(v(c,c.length-1),s),[d,f]=$r(t,l,u,o,s);if((d===0||f===0)&&(d=Math.max(d,.01),f=Math.max(f,.01)),!(d>0&&f>0))return;let p=`rrg|${Math.round(l)}x${Math.round(u)}|${Math.round(d)}x${Math.round(f)}|${JSON.stringify(t.stops)}`,m=this.patternCache.get(p);if(!m){let e=hl(this.canvas.ownerDocument??document,d,f,t.stops,!0);if(!e)return;m=this.ctx.createPattern(e.canvas,`no-repeat`),this.patternCache.set(p,m)}m&&(this.path(r),this.ctx.save(),this.ctx.clip(),this.ctx.translate(i+l-d,a+u-f),this.ctx.fillStyle=m,this.ctx.fillRect(0,0,d*2,f*2),this.ctx.restore())}renderConicGradient(e,t,n){let[r,i,a,o,s]=bl(e,n,[null,null,null]),c=t.position.length===0?[B]:t.position,l=i+H(v(c,0),o),u=a+H(v(c,c.length-1),s),d=this.ctx.createConicGradient(t.angle-Math.PI/2,l,u);Jr(t.stops,1).forEach(e=>{d.addColorStop(Math.min(1,Math.max(0,e.stop)),U(e.color))}),this.path(r),this.ctx.save(),this.ctx.clip(),this.ctx.fillStyle=d,this.ctx.fill(),this.ctx.restore()}renderRepeatingConicGradient(e,t,n){let[r,i,a,o,s]=bl(e,n,[null,null,null]),c=t.position.length===0?[B]:t.position,l=i+H(v(c,0),o),u=a+H(v(c,c.length-1),s),d=Jr(t.stops,1),f=v(d,0),p=v(d,d.length-1),m=Math.max(p.stop-f.stop,.01);if(p.stop-f.stop<1e-6){let e=this.ctx.createConicGradient(t.angle-Math.PI/2,l,u);e.addColorStop(0,U(p.color)),e.addColorStop(1,U(p.color)),this.path(r),this.ctx.save(),this.ctx.clip(),this.ctx.fillStyle=e,this.ctx.fill(),this.ctx.restore();return}let h=[],g=Math.ceil(1/m);for(let e=0;e<g;e++)for(let t of d){let n=e*m+(t.stop-f.stop);if(n>1)break;h.push({stop:n,color:U(t.color)})}let _=v(h,h.length-1);_&&_.stop<1&&h.push({stop:1,color:_.color});let y=this.ctx.createConicGradient(t.angle-Math.PI/2,l,u);h.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){du(this.ctx,e)}},mu=(e,t)=>{switch(t){case 0:return yu(e.topLeftBorderBox,e.topLeftPaddingBox,e.topRightBorderBox,e.topRightPaddingBox);case 1:return yu(e.topRightBorderBox,e.topRightPaddingBox,e.bottomRightBorderBox,e.bottomRightPaddingBox);case 2:return yu(e.bottomRightBorderBox,e.bottomRightPaddingBox,e.bottomLeftBorderBox,e.bottomLeftPaddingBox);default:return yu(e.bottomLeftBorderBox,e.bottomLeftPaddingBox,e.topLeftBorderBox,e.topLeftPaddingBox)}},hu=(e,t)=>{switch(t){case 0:return yu(e.topLeftBorderBox,e.topLeftBorderDoubleOuterBox,e.topRightBorderBox,e.topRightBorderDoubleOuterBox);case 1:return yu(e.topRightBorderBox,e.topRightBorderDoubleOuterBox,e.bottomRightBorderBox,e.bottomRightBorderDoubleOuterBox);case 2:return yu(e.bottomRightBorderBox,e.bottomRightBorderDoubleOuterBox,e.bottomLeftBorderBox,e.bottomLeftBorderDoubleOuterBox);default:return yu(e.bottomLeftBorderBox,e.bottomLeftBorderDoubleOuterBox,e.topLeftBorderBox,e.topLeftBorderDoubleOuterBox)}},gu=(e,t)=>{switch(t){case 0:return yu(e.topLeftBorderDoubleInnerBox,e.topLeftPaddingBox,e.topRightBorderDoubleInnerBox,e.topRightPaddingBox);case 1:return yu(e.topRightBorderDoubleInnerBox,e.topRightPaddingBox,e.bottomRightBorderDoubleInnerBox,e.bottomRightPaddingBox);case 2:return yu(e.bottomRightBorderDoubleInnerBox,e.bottomRightPaddingBox,e.bottomLeftBorderDoubleInnerBox,e.bottomLeftPaddingBox);default:return yu(e.bottomLeftBorderDoubleInnerBox,e.bottomLeftPaddingBox,e.topLeftBorderDoubleInnerBox,e.topLeftPaddingBox)}},_u=(e,t)=>{switch(t){case 0:return vu(e.topLeftBorderStroke,e.topRightBorderStroke);case 1:return vu(e.topRightBorderStroke,e.bottomRightBorderStroke);case 2:return vu(e.bottomRightBorderStroke,e.bottomLeftBorderStroke);default:return vu(e.bottomLeftBorderStroke,e.topLeftBorderStroke)}},vu=(e,t)=>{let n=[];return X(e)?n.push(e.subdivide(.5,!1)):n.push(e),X(t)?n.push(t.subdivide(.5,!0)):n.push(t),n},yu=(e,t,n,r)=>{let i=[];return X(e)?i.push(e.subdivide(.5,!1)):i.push(e),X(n)?i.push(n.subdivide(.5,!0)):i.push(n),X(r)?i.push(r.subdivide(.5,!0).reverse()):i.push(r),X(t)?i.push(t.subdivide(.5,!1).reverse()):i.push(t),i},bu=class{ctx;pathCallbacks;constructor(e,t){this.ctx=e.ctx,this.pathCallbacks=t}async renderSolidBorder(e,t,n){this.pathCallbacks.path(mu(n,t)),this.ctx.fillStyle=U(e),this.ctx.fill()}async renderDoubleBorder(e,t,n,r){if(t<3){await this.renderSolidBorder(e,n,r);return}let i=hu(r,n);this.pathCallbacks.path(i),this.ctx.fillStyle=U(e),this.ctx.fill();let a=gu(r,n);this.pathCallbacks.path(a),this.ctx.fill()}async renderDashedDottedBorder(e,t,n,r,i){this.ctx.save();let a=_u(r,n),o=mu(r,n);i===2&&(this.pathCallbacks.path(o),this.ctx.clip());let s,c,l,u;X(v(o,0))?(s=v(o,0).start.x,c=v(o,0).start.y):(s=v(o,0).x,c=v(o,0).y),X(v(o,1))?(l=v(o,1).end.x,u=v(o,1).end.y):(l=v(o,1).x,u=v(o,1).y);let d;d=Math.abs(n===0||n===2?s-l:c-u),this.ctx.beginPath(),i===3?this.pathCallbacks.formatPath(a):this.pathCallbacks.formatPath(o.slice(0,2));let f=t<3?t*3:t*2,p=t<3?t*2:t;i===3&&(f=t,p=t);let m=!0;if(d<=f*2)m=!1;else if(d<=f*2+p){let e=d/(2*f+p);f*=e,p*=e}else{let e=Math.floor((d+p)/(f+p)),t=(d-e*f)/(e-1),n=(d-(e+1)*f)/e;p=n<=0||Math.abs(p-t)<Math.abs(p-n)?t:n}if(m&&(i===3?this.ctx.setLineDash([0,f+p]):this.ctx.setLineDash([f,p])),i===3?(this.ctx.lineCap=`round`,this.ctx.lineWidth=t):this.ctx.lineWidth=t*2+1.1,this.ctx.strokeStyle=U(e),this.ctx.stroke(),this.ctx.setLineDash([]),i===2){if(X(v(o,0))){let e=v(o,3),t=v(o,0);this.ctx.beginPath(),this.pathCallbacks.formatPath([new Y(e.end.x,e.end.y),new Y(t.start.x,t.start.y)]),this.ctx.stroke()}if(X(v(o,1))){let e=v(o,1),t=v(o,2);this.ctx.beginPath(),this.pathCallbacks.formatPath([new Y(e.end.x,e.end.y),new Y(t.start.x,t.start.y)]),this.ctx.stroke()}}this.ctx.restore()}},xu=(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)})},Su=(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)}},Cu=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()}},wu=/blur\((\d+(?:\.\d+)?)px\)/gi,Tu=(e,t)=>t===1?e:e.replace(wu,(e,n)=>`blur(${parseFloat(n)*t}px)`),Eu=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=>Qc(e)||$c(e)||tl(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=v(e,r);t(i)&&(this.didSave||=(this.ctx.save(),!0),r===n&&(this.saveAtDepth=this.activeEffects.length)),this.applyEffect(i)}}applyEffect(e){Qc(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)):$c(e)?(this.pathCallback.path(e.path),this.ctx.clip()):tl(e)?e.applyClip(this.ctx):el(e)?this.ctx.globalAlpha*=e.opacity:nl(e)?this.ctx.globalCompositeOperation=e.compositeOperation:rl(e)&&(this.ctx.filter=Tu(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}},Du=(e,t)=>e.length===0?void 0:e[t%e.length]??e[0],Ou=(e,t,n,r)=>{let i=e?e[0]:void 0,a=e&&e.length>1?v(e,1):void 0,o=e=>e!==void 0&&P(e)?e.value:null,s=(e,t,n)=>e===void 0||P(e)?null:R(e)?H(e,t):n,c=o(i);if(c===`contain`||c===`cover`){let e=c===`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 l=s(i,t.width,n),u=s(a,t.height,r);return l===null&&u===null?(l=n,u=r):l===null?l=n/r*u:u===null&&(u=r/n*l),{width:l,height:u}},ku=(e,t,n,r,i)=>{let a=t.naturalWidth||t.width||i.width,o=t.naturalHeight||t.height||i.height,{width:s,height:c}=Ou(Du(n.maskSize,r),i,a,o),l=Du(n.maskPosition,r)??[],u=i.left+H(v(l,0),i.width-s),d=i.top+H(v(l,l.length-1),i.height-c),f=Du(n.maskRepeat,r)??0,p=f===0||f===2,m=f===0||f===3,h=p?Math.ceil((u-i.left)/s):0,g=m?Math.ceil((d-i.top)/c):0,_=p?Math.ceil((i.left+i.width-u)/s):0,y=m?Math.ceil((i.top+i.height-d)/c):0;for(let n=-g;n<=y;n++)for(let r=-h;r<=_;r++)e.drawImage(t,u+r*s,d+n*c,s,c)},Au=(e,t,n)=>{let{width:r,height:i}=n,a=t.position.length===0?[B]:t.position,o=H(v(a,0),r),s=H(v(a,a.length-1),i),[c,l]=$r(t,o,s,r,i);c=Math.max(c,.01),l=Math.max(l,.01);let u=hl(e.canvas.ownerDocument??document,c,l,t.stops,Si(t));u&&(e.fillStyle=u.lastColor,e.fillRect(n.left,n.top,n.width,n.height),e.drawImage(u.canvas,n.left+o-c,n.top+s-l,c*2,l*2))},ju=(e,t,n)=>{let{width:r,height:i}=n;if(r<=0||i<=0)return;if(bi(t)||Si(t)){Au(e,t,n);return}let a=null;if(t.type===1||t.type===3){let o=t,[s,c,l,u,d]=Xr(o.angle||0,r,i),f=Jr(o.stops,s||1);if(t.type===3){let t=pl(f);if(!t){e.fillStyle=U(v(f,f.length-1).color),e.fillRect(n.left,n.top,r,i);return}a=e.createLinearGradient(n.left+c,n.top+u,n.left+l,n.top+d),t.forEach(e=>a.addColorStop(Math.min(1,Math.max(0,e.stop)),e.color))}else a=e.createLinearGradient(n.left+c,n.top+u,n.left+l,n.top+d),ml(f).forEach(e=>a.addColorStop(e.stop,e.color))}else if(t.type===5||t.type===6){let o=t,s=Jr(o.stops,1),c=t.type===6;if(c&&!pl(s)){e.fillStyle=U(v(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),((c?pl(s):null)??ml(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))},Mu=async(e,t,n,r,i)=>{for(let a=0;a<t.length;a++){let o=v(t,a);if(o.type===0){let t=await i(o.url);t&&ku(e,t,n,a,r)}else ju(e,o,r)}},Nu=(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?H(i[0],1):.5,g=i?H(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 Pu(e,t,n,r,i,a,o,s){if(i instanceof dc)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 fc&&s(i,a,i.canvas),i instanceof hc)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 kc&&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 Fu(e,t,n,r,i){if(r instanceof Ec){let t=Math.min(r.bounds.width,r.bounds.height);r.type===`checkbox`&&r.checked?(e.save(),n([new Y(r.bounds.left+t*.39363,r.bounds.top+t*.79),new Y(r.bounds.left+t*.16,r.bounds.top+t*.5549),new Y(r.bounds.left+t*.27347,r.bounds.top+t*.44071),new Y(r.bounds.left+t*.39694,r.bounds.top+t*.5649),new Y(r.bounds.left+t*.72983,r.bounds.top+t*.23),new Y(r.bounds.left+t*.84,r.bounds.top+t*.34085),new Y(r.bounds.left+t*.39363,r.bounds.top+t*.79)]),e.fillStyle=U(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=U(r.styles.accentColor??7733247),e.fill(),e.restore())}if(zu(r)&&r.value.length){let[a]=t.createFontStyle(i);e.font=a??``;let o=H(i.fontSize,0),{baseline:s,height:c}=nu(e,o);e.fillStyle=r instanceof Ec&&r.isPlaceholder?U(Tc):U(i.color),e.textBaseline=`alphabetic`,e.textAlign=Bu(r.styles.textAlign);let l=_l(r),u=r instanceof Ec?Iu(l,gl(r),c):l,d=0;switch(r.styles.textAlign){case 1:d+=l.width/2;break;case 2:d+=l.width}let f=0;r instanceof Ec&&(f=(l.height-c)/2);let p=l.add(d,f,0,0);e.save(),n([new Y(u.left,u.top),new Y(u.left+u.width,u.top),new Y(u.left+u.width,u.top+u.height),new Y(u.left,u.top+u.height)]),e.clip();let m=Lu(e,r.value,l.width,i.whiteSpace===`pre`||i.whiteSpace===`nowrap`),g=ya(i.lineHeight,o);m.forEach((n,r)=>{let a=p.left,o=e.measureText(n).width;switch(i.textAlign){case 1:a+=(l.width-o)/2;break;case 2:a+=l.width-o}let c=new h(a,p.top+r*g,0,0);t.renderTextWithLetterSpacing(new Qs(n,c),i.letterSpacing,s,i.writingMode)}),e.restore(),e.textBaseline=`alphabetic`,e.textAlign=`left`}}var Iu=(e,t,n)=>e.height<n?new h(e.left,t.top,e.width,t.height):e,Lu=(e,t,n,r)=>{let i=[],a=t.split(`
7
+ `);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 Ru(e,t,n,r,i,a){if(G(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),o=H(a.fontSize,0),s=n?.naturalWidth||n.width,c=n?.naturalHeight||n.height;if(s<=0||c<=0)return;let l=Math.min(o/s,o/c),u=s*l,d=c*l,f=i.bounds.top+H(i.styles.paddingTop,i.bounds.width)+ya(a.lineHeight,a.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=a.fontSize.number*.45,r=i.bounds.left-n*.9,o=i.bounds.top+H(i.styles.paddingTop,i.bounds.width)+ya(a.lineHeight,a.fontSize.number)/2;e.save(),e.fillStyle=U(a.color),e.beginPath(),t===2?e.rect(r-n/2,o-n/2,n,n):(e.arc(r,o,n/2,0,Math.PI*2),t===1&&(e.strokeStyle=U(a.color),e.lineWidth=n*.18)),t===1?e.stroke():e.fill(),e.restore()}else{let[t]=n.createFontStyle(a);e.font=t??``,e.fillStyle=U(a.color),e.textBaseline=`middle`,e.textAlign=`right`;let o=new h(i.bounds.left,i.bounds.top+H(i.styles.paddingTop,i.bounds.width),i.bounds.width,ya(a.lineHeight,a.fontSize.number)/2+1);n.renderTextWithLetterSpacing(new Qs(r.listValue,o),a.letterSpacing,ya(a.lineHeight,a.fontSize.number)/2+2,a.writingMode),e.textBaseline=`bottom`,e.textAlign=`left`}}}}var zu=e=>e instanceof Oc||e instanceof Dc||e instanceof Ec&&e.type!==`radio`&&e.type!==`checkbox`,Bu=e=>{switch(e){case 1:return`center`;case 2:return`right`;default:return`left`}},Vu=(e,t)=>{let n=t>e?t*(1+(e/t-1)**3):t;return Math.max(0,e+n)},Hu=(e,t)=>{if(t===0)return e;let n=e.map((e,t)=>X(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=v(n,1).x-v(n,0).x+2*t,i=v(n,3).y-v(n,0).y+2*t;if(r<=0||i<=0)return[];let a=n.map(e=>({x:Vu(e.rx,t),y:Vu(e.ry,t)})),o=(e,t)=>t>0?e/t:1,s=Math.min(1,o(r,v(a,0).x+v(a,1).x),o(r,v(a,3).x+v(a,2).x),o(i,v(a,0).y+v(a,3).y),o(i,v(a,1).y+v(a,2).y));return e.map((e,r)=>{let i=v(n,r),o=i.x+(r===1||r===2?t:-t),c=i.y+(r>=2?t:-t);if(!X(e))return new Y(o,c);let l=v(a,r).x*s,u=v(a,r).y*s;if(!l||!u)return new Y(o,c);let d=l/i.rx,f=u/i.ry,p=e=>new Y(o+(e.x-i.x)*d,c+(e.y-i.y)*f);return new Bc(p(e.start),p(e.startControl),p(e.endControl),p(e.end))})},Uu=(e,t,n)=>{let{a:r,b:i,c:a,d:o,e:s,f:c}=e;if(![r,i,a,o,s,c,t,n].every(Number.isFinite))return null;let l=r*o-i*a;if(!Number.isFinite(l)||l===0)return null;let u=(e,t)=>({x:(o*(e-s)-a*(t-c))/l,y:(-i*(e-s)+r*(t-c))/l}),d=[u(0,0),u(t,0),u(t,n),u(0,n)];if(!d.every(e=>Number.isFinite(e.x)&&Number.isFinite(e.y)))return null;let f=Math.min(...d.map(e=>e.x)),p=Math.min(...d.map(e=>e.y)),m=Math.max(...d.map(e=>e.x)),g=Math.max(...d.map(e=>e.y)),_=r*r+i*i,v=a*a+o*o,y=r*a+i*o,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 h(f,p,m-f,g-p),scale:b,uniform:Math.abs(_-v)<=x&&Math.abs(y)<=x}},Wu=(e,t,n)=>{e.beginPath(),e.rect(t.left,t.top,t.width,t.height),n.length&&(uu(e,n),e.closePath())},Gu=(e,t)=>{let n=t.spread.number,r=gl(e.container);return r.width-2*n<=0||r.height-2*n<=0?[]:Hu(Wc(e.curves),-n)},Ku=async(e,t,n,r,i,a)=>{let o=gl(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=Jl(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=Rc(n.inset?Gu(t,n):Hu(Hc(t.curves),l),n.offsetX.number,n.offsetY.number,0,0);n.inset?Wu(i,u,o):du(i,o),i.fillStyle=U(n.color),i.fill(n.inset?`evenodd`:`nonzero`),h=await Kl(m,{functions:[{kind:`blur`,value:s}]},1,a.scale,r.signal),e.save();try{n.inset?(du(e,Wc(t.curves)),e.clip()):(Wu(e,a.viewport,Hc(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 Q))throw e;return!1}finally{h&&h!==m&&$(h),m&&$(m),i.pixels-=p}},qu=async(e,t,n,r,i)=>{if(r.signal?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);if(tt(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=Uu(s,e.canvas.width,e.canvas.height);if(!c)return;let{viewport:l}=c;if(n.blur.number>0&&(n.inset||!c.uniform)&&await Ku(e,t,n,r,i,c))return;let u=gl(t.container);e.save();try{if(n.inset&&n.blur.number===0){du(e,Wc(t.curves)),e.clip(),Wu(e,u,Rc(Gu(t,n),n.offsetX.number,n.offsetY.number,0,0)),e.fillStyle=U(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(es,y+r*c.scale+2);n.inset?(du(e,Wc(t.curves)),e.clip()):(Wu(e,l,Hc(t.curves)),e.clip(`evenodd`)),o?e.setTransform(d,f,p,m,h-b,g):e.translate(-b/d,0),n.inset?Wu(e,i,Gu(t,n)):du(e,Hu(Hc(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=U(n.color),e.fillStyle=`rgb(0, 0, 0)`,e.fill(n.inset?`evenodd`:`nonzero`)}finally{e.restore()}},Ju=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=ru(u.ctx,n.fontSize.number),g=new pu({ctx:u.ctx,context:this.context,canvas:u.canvas,options:{width:o,height:s,scale:1}});tt(n.backgroundColor)||(u.ctx.fillStyle=U(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=U(n.webkitTextStrokeColor),d.ctx.lineWidth=n.webkitTextStrokeWidth,d.ctx.lineJoin=cu());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{$(u.canvas),d&&$(d.canvas),f&&$(f.canvas),p&&p.forEach($)}}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 ic(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 c=[];for(let a=s.length-1;a>=0;a--){let l=v(s,a),u=this.createGlyphLayer(t,n,r,i);if(u){u.ctx.shadowColor=U(l.color),u.ctx.shadowOffsetX=l.offsetX.number*this.scale,u.ctx.shadowOffsetY=l.offsetY.number*this.scale,u.ctx.shadowBlur=l.blur.number*this.scale,u.ctx.fillStyle=U(l.color);for(let t of e.container.textNodes)for(let e of t.textBounds)this.drawGlyphs(u,e,o,(e,t,n,r)=>{e.fillText(t,n,r)});c.push(u.canvas)}}return c.length?c:null}},Yu=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||$(this.canvas),n?new Q(`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 pu({ctx:this.ctx,context:this.context,canvas:this.canvas,options:{width:t.width,height:t.height,scale:t.scale}}),this.borderRenderer=new bu({ctx:this.ctx},{path:e=>this.path(e),formatPath:e=>this.formatPath(e)}),this.borderImageRenderer=new Cu(this.ctx),this.effectsRenderer=new Eu({ctx:this.ctx,scale:t.scale},{path:e=>this.path(e)}),this.textRenderer=new lu({ctx:this.ctx,options:{scale:t.scale}}),this.textClipRenderer=new Ju({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=Al(t.filter),r=n!==null&&n.functions.length>0,i=t.maskImage.length>0,a=t.webkitBoxReflect,o=t.mixBlendMode!==q.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&&!G(t.display,2048)&&Al(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,a=!1){let o=this.options.signal;if(o?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);let s=Ql(Zl(t.element.container),new h(this.options.x,this.options.y,this.options.width,this.options.height),n?zl(n):0,this.options.scale);if(!s.width||!s.height)return!0;let c=Jl(this.surfaceBudget,Math.ceil(s.width*this.options.scale),Math.ceil(s.height*this.options.scale));if(!c)return this.context.logger.info(`Filter surface budget exceeded; using the existing renderer`),!1;let l={...this.options,canvas:void 0,backgroundColor:null,x:s.left,y:s.top,width:s.width,height:s.height},u,d;try{u=new e(this.context,l,t.element,this.surfaceBudget),await u.renderStackContent(t),u.effectsRenderer.applyEffects([]),n&&(d=await Kl(u.canvas,n,t.element.container.styles.opacity,l.scale,o));let c=d??u.canvas;if(r&&await this.applyMask(c,t.element.container.styles,s),o?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);let f=t.element.effects,p=t.element.getEffects(4,this.surfaceRoot).filter(e=>!f.includes(e)||!rl(e)&&!el(e)&&!nl(e)&&!$c(e));return this.effectsRenderer.applyEffects(p),a?(this.ctx.save(),this.ctx.globalCompositeOperation=t.element.container.styles.mixBlendMode,this.ctx.drawImage(c,l.x,l.y,c.width/l.scale,c.height/l.scale),this.ctx.restore()):this.ctx.drawImage(c,l.x,l.y,c.width/l.scale,c.height/l.scale),i&&await this.drawReflection(c,t.element.container.bounds,s,i),!0}catch(e){if(!(e instanceof Q))throw e;return this.context.logger.info(`${e.message}; using the existing renderer`),!1}finally{u&&$(u.canvas),d&&$(d),this.surfaceBudget.pixels-=c}}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){a.scale(this.options.scale,this.options.scale),a.translate(-n.left,-n.top);try{await Mu(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}`);return}r.save();try{r.setTransform(1,0,0,1,0,0),r.globalCompositeOperation=`destination-in`,r.drawImage(i,0,0)}finally{r.restore()}}}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=Jl(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 Mu(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&&$(c),l&&$(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=_l(e),o=Wc(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}=Nu(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=_l(n);for(let e of n.textNodes)await this.textRenderer.renderTextNode(e,i,a);await Pu(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)),Fu(this.ctx,this.textRenderer,this.path.bind(this),n,i),await Ru(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){du(this.ctx,e)}formatPath(e){uu(this.ctx,e)}async renderSurfaceBoxShadow(e,t){let n=t.spread.number,r=t.blur.number/2,i=Math.ceil(3*r)+1,a=e.container.bounds.add(-n,-n,2*n,2*n);if(a.width<=0||a.height<=0)return;let o=this.options.scale,s=Ql(a.add(-i,-i,2*i,2*i),new h(this.options.x-t.offsetX.number,this.options.y-t.offsetY.number,this.options.width,this.options.height),i,o);if(!s.width||!s.height)return;let c=Math.ceil(s.width*o),l=Math.ceil(s.height*o),u=Jl(this.surfaceBudget,c,l);if(!u)throw new Q(`Box shadow surface budget exceeded`);let d,f;try{d=this.context.resourceDocument.createElement(`canvas`),d.width=c,d.height=l;let i=d.getContext(`2d`);if(!i)throw new Q(`Box shadow surface canvas is unavailable`);i.scale(o,o),i.translate(-s.left,-s.top),du(i,Rc(Hc(e.curves),-n,-n,2*n,2*n)),i.fillStyle=U(t.color),i.fill(),f=await Kl(d,{functions:[{kind:`blur`,value:r}]},1,o,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),uu(this.ctx,Hc(e.curves)),this.ctx.closePath(),this.ctx.clip(`evenodd`),this.ctx.drawImage(f,s.left+t.offsetX.number,s.top+t.offsetY.number,f.width/o,f.height/o)}finally{this.ctx.restore()}}finally{d&&$(d),f&&$(f),this.surfaceBudget.pixels-=u}}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=!tt(t.backgroundColor)||t.backgroundImage.length,r=Zu(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=Xu(wl(t.backgroundClip,0),e.curves);if(n||t.boxShadow.length){r&&e.container.textNodes.length>0?await this.textClipRenderer.render(e):(this.ctx.save(),this.path(a),this.ctx.clip(),tt(t.backgroundColor)||(this.ctx.fillStyle=U(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 qu(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=Su(t.borderImageOutset,i),n=r.add(-e.left,-e.top,e.left+e.right,e.top+e.bottom),o=xu(t.borderImageWidth,i,n);this.borderImageRenderer.renderBorderImage(r,a,t.borderImageSlice,t.borderImageRepeat,o[0],o[1],o[2],o[3],e)}return}let o=0;for(let t of i){if(t.style!==0&&!tt(t.color)&&t.width>0){let n=async()=>{t.style===2?await this.borderRenderer.renderDashedDottedBorder(t.color,t.width,o,e.curves,2):t.style===3?await this.borderRenderer.renderDashedDottedBorder(t.color,t.width,o,e.curves,3):t.style===4?await this.borderRenderer.renderDoubleBorder(t.color,t.width,o,e.curves):await this.borderRenderer.renderSolidBorder(t.color,o,e.curves)},r=e.container.legendBounds;if(o===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()}o++}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(tt(r))return;let i=Math.max(0,t.outlineOffset)+n/2,a=Rc(Hc(e.curves),-i,-i,2*i,2*i);this.ctx.save();try{this.ctx.strokeStyle=U(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,c,l,u]=Xr(t.angle,n,r),d=Jr(t.stops,o||n),f=e.type===3,p=f?pl(d):null,m=a.createLinearGradient(s,c,l,u);if(p)p.forEach(e=>{m.addColorStop(Math.min(1,Math.max(0,e.stop)),e.color)});else if(f){let e=U(v(d,d.length-1).color);m.addColorStop(0,e),m.addColorStop(1,e)}else ml(d).forEach(e=>{m.addColorStop(e.stop,e.color)});return a.fillStyle=m,a.fillRect(0,0,n,r),i}if(e.type===2||e.type===4){let t=e,o=t.position.length===0?[B]:t.position,s=H(v(o,0),n),c=H(v(o,o.length-1),r),[l,u]=$r(t,s,c,n,r);if(l<=0||u<=0)return null;let d=hl(this.ctx.canvas.ownerDocument??document,l,u,t.stops,e.type===4);return d?(a.fillStyle=d.lastColor,a.fillRect(0,0,n,r),a.drawImage(d.canvas,s-l,c-u,l*2,u*2),i):null}if(e.type===5||e.type===6){let t=e,o=H(v(t.position,0),n),s=H(v(t.position,1),r),c=a.createConicGradient(t.angle-Math.PI/2,o,s),l;if(e.type===6){let e=Jr(t.stops,1),n=v(e,0),r=v(e,e.length-1),i=Math.max(r.stop-n.stop,.01);l=[];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;l.push({stop:e,color:U(r.color)})}let o=v(l,l.length-1);o&&o.stop<1&&l.push({stop:1,color:o.color})}else l=Jr(t.stops,Math.max(n,r)).map(e=>({stop:e.stop,color:U(e.color)}));return l.forEach(e=>{c.addColorStop(Math.min(1,Math.max(0,e.stop)),e.color)}),a.fillStyle=c,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=Al(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=Jl(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 Kl(s,t,1,r,this.options.signal)}catch(e){if(e instanceof Q){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&&$(s),c&&$(c),this.surfaceBudget.pixels-=o}}async render(e){try{this.options.backgroundColor&&(this.ctx.fillStyle=U(this.options.backgroundColor),this.ctx.fillRect(this.options.x,this.options.y,this.options.width,this.options.height));let t=dl(e);return await this.renderStack(t),this.effectsRenderer.applyEffects([]),this.canvas}catch(e){throw this.options.canvas||$(this.canvas),e}}},Xu=(e,t)=>{switch(e){case 0:return Hc(t);case 2:return Uc(t);default:return Wc(t)}},Zu=e=>e.backgroundClip.some(e=>e===3),Qu=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=ed(e),n=Xs(Ys(this.options.width,this.options.height,0,0,e));t();let r=await n;if(this.options.signal?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);return this.options.backgroundColor&&(this.ctx.fillStyle=U(this.options.backgroundColor),this.ctx.fillRect(this.options.x,this.options.y,this.options.width,this.options.height)),this.ctx.drawImage(r,this.options.x,this.options.y,this.options.width,this.options.height),this.canvas}},$u=[`marginTop`,`marginRight`,`marginBottom`,`marginLeft`,`top`,`right`,`bottom`,`left`],ed=e=>{let t=e.style,n=$u.map(e=>[e,t[e]]);for(let e of $u)t[e]=e.startsWith(`margin`)?`0px`:`auto`;return()=>{for(let[e,r]of n)t[e]=r}},td=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))}},nd=class{context;_options;_cache=new Map;maxSize;_pendingOperations=new Map;_deferMode=!1;_collectedUrls=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){J(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)&&(ld(e)||od(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 ld(e)||od(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&&!sd(e)&&!ld(e)&&typeof this._options.proxy!=`string`,a=!sd(e)&&(this._options.useCORS===!0||i)&&Zs.SUPPORT_CORS_IMAGES&&!r,o=!sd(e)&&!r&&!ld(e)&&typeof this._options.proxy==`string`&&!a;if(!r&&this._options.allowTaint===!1&&!sd(e)&&!ld(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,(cd(s)||a)&&(n.crossOrigin=`anonymous`),n.src=s,n.complete===!0&&(typeof n.decode==`function`?n.decode().then(()=>e(n),()=>t(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()})}},rd=/^data:image\/svg\+xml/i,id=/^data:image\/.*;base64,/i,ad=/^data:image\/.*/i,od=e=>Zs.SUPPORT_SVG_DRAWING||!ud(e),sd=e=>ad.test(e),cd=e=>id.test(e),ld=e=>e.substring(0,4)===`blob`,ud=e=>e.slice(-3).toLowerCase()===`svg`||rd.test(e),dd=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}},fd=class e{static instanceCount=1;instanceName=`#${e.instanceCount++}`;logger;cache;originChecker;config;onError;_windowBounds;constructor(e,t,n){this.config=n,this.logger=new td({id:this.instanceName,enabled:e.logging}),this.originChecker=new dd(n.window),this.cache=e.cache??n.cache??new nd(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)}},pd=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)}})},md=e=>({allowTaint:e.allowTaint??!1,imageTimeout:e.imageTimeout??15e3,proxy:e.proxy,useCORS:e.useCORS??!1,customIsSameOrigin:e.customIsSameOrigin,maxCacheSize:e.maxCacheSize}),hd=(e,t,n)=>({logging:e.logging??!0,cache:e.cache??t.cache,...n}),gd=800,_d=600,vd=0,yd=(e,t)=>{let n=t;return{windowWidth:e.windowWidth??n.innerWidth??gd,windowHeight:e.windowHeight??n.innerHeight??_d,scrollX:e.scrollX??n.pageXOffset??vd,scrollY:e.scrollY??n.pageYOffset??vd}},bd=(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}),xd=(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}),Sd=(e,t,n)=>{let r=t.ownerDocument,i=r.documentElement?Wn(e,getComputedStyle(r.documentElement).backgroundColor):0,a=r.body?Wn(e,getComputedStyle(r.body).backgroundColor):0,o=typeof n==`string`?Wn(e,n):n===null?0:4294967295;return t===r.documentElement?tt(i)?tt(a)?o:a:i:o},Cd=(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)}`)}},wd=async(e,t,n)=>{if(pd(t),!t.skipValidation){let n=t.validator||p(),r=n.validateElement(e);if(!r.valid)throw Error(r.error);let i=n.validateOptions(t);if(!i.valid)throw Error(`Invalid options: ${i.error}`)}if(!e||typeof e!=`object`)throw Error(`Invalid element provided as first argument`);let r=e.ownerDocument;if(!r)throw Error(`Element is not attached to a Document`);let i=r.defaultView;if(!i)throw Error(`Document is not attached to a Window`);let a=hd(t,n,md(t)),o=yd(t,i),s=new h(o.scrollX,o.scrollY,o.windowWidth,o.windowHeight),c=new fd(a,s,n),l=t.enablePerformanceMonitoring??t.logging??!1,u=new m(c,l);u.start(`total`,{width:o.windowWidth,height:o.windowHeight});let d=t.signal;J(d);let f=t.foreignObjectRendering??!1,v=bd(t,n,f);c.logger.debug(`Starting document clone with size ${s.width}x${s.height} scrolled to ${-s.left},${-s.top}`),Cd(t.onProgress,c,`clone`,10),u.start(`clone`);let y=new Us(c,e,v),b=y.clonedReferenceElement;if(!b)throw Error(`Unable to find element in cloned iframe`);let x=await y.toIFrame(r,s);u.end(`clone`),Cd(t.onProgress,c,`clone`,30),d?.aborted&&((t.removeContainer??!0)&&Us.destroy(x),J(d));let{width:S,height:C,left:w,top:T}=$n(b)||Zn(b)?_(b.ownerDocument):g(c,b),ee=Sd(c,b,t.backgroundColor),E=xd(t,ee,w,T,S,C,i.devicePixelRatio??1),D,O;try{f?(c.logger.debug(`Document cloned, using foreign object rendering`),u.start(`render-foreignobject`),D=await new Qu(c,E).render(b),u.end(`render-foreignobject`)):(c.logger.debug(`Document cloned, element located at ${w},${T} with size ${S}x${C} using computed rendering`),c.logger.debug(`Starting DOM parsing`),u.start(`parse`),J(d),c.cache.startDefer(),O=Pc(c,b,{normalizeDom:t.normalizeDom}),u.end(`parse`),Cd(t.onProgress,c,`parse`,50),u.start(`preload`),await c.cache.preloadAll(10,(e,n)=>{Cd(t.onProgress,c,`preload`,50+Math.round(e/n*10))},d),u.end(`preload`),Cd(t.onProgress,c,`layout`,60),ee===O.styles.backgroundColor&&(O.styles.backgroundColor=0),c.logger.debug(`Starting renderer for element at ${E.x},${E.y} with size ${E.width}x${E.height}`),u.start(`render`),J(d),D=await new Yu(c,E).render(O),u.end(`render`)),Cd(t.onProgress,c,`render`,90)}finally{u.start(`cleanup`);try{O&&O.restoreTree()}finally{(t.removeContainer??!0)&&Us.destroy(x),u.end(`cleanup`)}}return u.end(`total`),c.logger.debug(`Finished rendering`),l&&u.logSummary(),Cd(t.onProgress,c,`render`,100),D},Td=(e,t={},n)=>wd(e,t,n||d.fromElement(e,{cspNonce:t.cspNonce,cache:t.cache}));function Ed(e){try{return new URL(e).hostname}catch{return`project`}}var Dd=({projectUrl:e,isOpen:t,onClose:n,uiSettings:r={},screenshots:i,onTriggerScreenshot:a,onEditScreenshot:o,onDeleteScreenshot:s,onSubmitReport:d})=>{let{position:f=`bottom-right`,primaryColor:p=`#2563eb`,title:m=`Report a Bug`,subtitle:h=`Found an issue? Let us know with details and screenshots.`,placeholderTitle:g=`e.g. Broken checkout button on cart page`,placeholderDescription:_=`Describe what happened, steps to reproduce, and expected result...`}=r,v=(e=>e===`bottom-left`||e===`top-left`||e===`left`)(f),[y,b]=(0,c.useState)(``),[x,S]=(0,c.useState)(``),[C,w]=(0,c.useState)(!1),[T,ee]=(0,c.useState)(!1),[E,D]=(0,c.useState)(null),[O,te]=(0,c.useState)({}),[k,A]=(0,c.useState)(null),j=Ed(e),ne=()=>{let e={};return y.trim()||(e.title=`Title / bug name is required.`),x.trim()||(e.description=`Description is required.`),te(e),Object.keys(e).length===0};return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`div`,{"data-bugdrop-widget":`true`,onClick:n,className:`fixed inset-0 z-[99990] bg-slate-900/40 backdrop-blur-sm transition-opacity duration-300 ${t?`opacity-100 pointer-events-auto`:`opacity-0 pointer-events-none`}`}),(0,u.jsxs)(`aside`,{"data-bugdrop-widget":`true`,className:`fixed top-0 z-[99995] flex h-full w-full max-w-md flex-col bg-white shadow-2xl transition-all duration-300 ease-out sm:max-w-lg ${v?`left-0 border-r border-slate-200`:`right-0 border-l border-slate-200`} ${v?t?`translate-x-0 opacity-100 pointer-events-auto`:`-translate-x-full opacity-0 pointer-events-none`:t?`translate-x-0 opacity-100 pointer-events-auto`:`translate-x-full opacity-0 pointer-events-none`}`,role:`dialog`,"aria-modal":`true`,"aria-label":m,children:[(0,u.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b border-slate-100 px-6 py-5`,children:[(0,u.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,u.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl text-white shadow-md font-bold`,style:{backgroundColor:p},children:(0,u.jsx)(l.Sparkles,{className:`h-5 w-5`})}),(0,u.jsxs)(`div`,{children:[(0,u.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,u.jsx)(`h2`,{className:`text-lg font-bold text-slate-800`,children:m}),(0,u.jsx)(`span`,{className:`rounded-md bg-slate-100 px-2 py-0.5 text-[11px] font-semibold tracking-wider text-slate-500`,title:e,children:j})]}),(0,u.jsx)(`p`,{className:`mt-0.5 text-xs text-slate-500`,children:h})]})]}),(0,u.jsx)(`button`,{type:`button`,onClick:n,className:`flex h-8 w-8 items-center justify-center rounded-lg text-slate-400 transition hover:bg-slate-100 hover:text-slate-600`,children:(0,u.jsx)(l.X,{className:`h-5 w-5`})})]}),(0,u.jsx)(`div`,{className:`flex-1 overflow-y-auto px-6 py-5`,children:T?(0,u.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center text-center py-10 animate-fadeIn`,children:[(0,u.jsx)(`div`,{className:`flex h-16 w-16 items-center justify-center rounded-full text-white shadow-lg mb-4`,style:{backgroundColor:p},children:(0,u.jsx)(l.CheckCircle2,{className:`h-9 w-9`})}),(0,u.jsx)(`h3`,{className:`text-xl font-bold text-slate-800`,children:`Bug Report Submitted!`}),(0,u.jsxs)(`p`,{className:`mt-2 text-sm text-slate-500 max-w-xs`,children:[`Thank you! Your bug report with `,i.length,` screenshot`,i.length===1?``:`s`,` has been captured and logged.`]}),(0,u.jsxs)(`div`,{className:`mt-8 flex flex-col sm:flex-row gap-3 w-full`,children:[(0,u.jsx)(`button`,{type:`button`,onClick:()=>{b(``),S(``),te({}),D(null),ee(!1)},className:`flex-1 rounded-xl border border-slate-200 bg-white py-2.5 text-sm font-semibold text-slate-700 shadow-sm transition hover:bg-slate-50`,children:`Report Another Bug`}),(0,u.jsx)(`button`,{type:`button`,onClick:n,style:{backgroundColor:p},className:`flex-1 rounded-xl py-2.5 text-sm font-semibold text-white shadow-md transition hover:brightness-110`,children:`Close`})]})]}):(0,u.jsxs)(`form`,{onSubmit:async t=>{if(t.preventDefault(),ne()){w(!0),D(null);try{await d({projectUrl:e,title:y.trim(),description:x.trim(),screenshots:i,timestamp:new Date().toISOString(),meta:{url:window.location.href,userAgent:navigator.userAgent,timestamp:new Date().toISOString(),screenSize:{width:window.innerWidth,height:window.innerHeight}}}),ee(!0)}catch(e){console.error(`Failed to submit bug report:`,e),D(e instanceof Error?e.message:`Failed to submit bug report. Please try again.`)}finally{w(!1)}}},className:`space-y-5`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsxs)(`label`,{className:`block text-xs font-bold tracking-wide uppercase text-slate-700`,children:[`Bug Title / Name `,(0,u.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,u.jsx)(`input`,{type:`text`,value:y,onChange:e=>{b(e.target.value),O.title&&te(e=>({...e,title:void 0}))},placeholder:g,className:`mt-1.5 w-full rounded-xl border px-3.5 py-2.5 text-sm transition focus:outline-none focus:ring-2 ${O.title?`border-red-300 bg-red-50/50 text-red-900 focus:ring-red-400`:`border-slate-200 bg-white text-slate-800 focus:border-transparent focus:ring-blue-500`}`}),O.title&&(0,u.jsxs)(`p`,{className:`mt-1.5 flex items-center gap-1 text-xs text-red-600`,children:[(0,u.jsx)(l.AlertCircle,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{children:O.title})]})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsxs)(`label`,{className:`block text-xs font-bold tracking-wide uppercase text-slate-700`,children:[`Description `,(0,u.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,u.jsx)(`textarea`,{rows:4,value:x,onChange:e=>{S(e.target.value),O.description&&te(e=>({...e,description:void 0}))},placeholder:_,className:`mt-1.5 w-full rounded-xl border px-3.5 py-2.5 text-sm transition focus:outline-none focus:ring-2 ${O.description?`border-red-300 bg-red-50/50 text-red-900 focus:ring-red-400`:`border-slate-200 bg-white text-slate-800 focus:border-transparent focus:ring-blue-500`}`}),O.description&&(0,u.jsxs)(`p`,{className:`mt-1.5 flex items-center gap-1 text-xs text-red-600`,children:[(0,u.jsx)(l.AlertCircle,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{children:O.description})]})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsxs)(`label`,{className:`block text-xs font-bold tracking-wide uppercase text-slate-700`,children:[`Screenshots `,(0,u.jsx)(`span`,{className:`text-slate-400 font-normal lowercase`,children:`(optional)`})]}),(0,u.jsxs)(`span`,{className:`rounded-full bg-slate-100 px-2 py-0.5 text-xs font-semibold text-slate-600`,children:[i.length,` / 3`]})]}),(0,u.jsx)(`p`,{className:`mt-1 text-xs text-slate-500`,children:`Capture your screen and annotate with pencil, shapes, or arrows.`}),i.length>0&&(0,u.jsx)(`div`,{className:`mt-3 grid grid-cols-3 gap-2.5`,children:i.map((e,t)=>(0,u.jsxs)(`div`,{className:`group relative aspect-video overflow-hidden rounded-lg border border-slate-200 bg-slate-100 shadow-sm`,children:[(0,u.jsx)(`img`,{src:e.dataUrl,alt:`Screenshot ${t+1}`,className:`h-full w-full object-cover transition duration-200 group-hover:scale-105`}),(0,u.jsxs)(`span`,{className:`absolute top-1 left-1 rounded bg-black/60 px-1 py-0.2 text-[10px] font-semibold text-white`,children:[`#`,t+1]}),(0,u.jsxs)(`div`,{className:`absolute inset-0 flex items-center justify-center gap-1.5 bg-black/50 opacity-0 backdrop-blur-[1px] transition-opacity duration-200 group-hover:opacity-100`,children:[(0,u.jsx)(`button`,{type:`button`,onClick:()=>A(e.dataUrl),title:`Preview screenshot`,className:`flex h-7 w-7 items-center justify-center rounded-md bg-white/90 text-slate-700 shadow transition hover:bg-white hover:text-blue-600`,children:(0,u.jsx)(l.Eye,{className:`h-3.5 w-3.5`})}),(0,u.jsx)(`button`,{type:`button`,onClick:()=>o(e),title:`Re-edit / annotate`,className:`flex h-7 w-7 items-center justify-center rounded-md bg-white/90 text-slate-700 shadow transition hover:bg-white hover:text-blue-600`,children:(0,u.jsx)(l.Edit3,{className:`h-3.5 w-3.5`})}),(0,u.jsx)(`button`,{type:`button`,onClick:()=>s(e.id),title:`Delete screenshot`,className:`flex h-7 w-7 items-center justify-center rounded-md bg-red-600 text-white shadow transition hover:bg-red-700`,children:(0,u.jsx)(l.Trash2,{className:`h-3.5 w-3.5`})})]})]},e.id))}),(0,u.jsx)(`div`,{className:`mt-3`,children:i.length<3?(0,u.jsxs)(`button`,{type:`button`,onClick:a,className:`flex w-full items-center justify-center gap-2 rounded-xl border-2 border-dashed border-slate-300 bg-slate-50/70 py-3 text-xs font-semibold text-slate-600 transition hover:border-blue-400 hover:bg-blue-50/50 hover:text-blue-600`,children:[(0,u.jsx)(l.Camera,{className:`h-4 w-4 text-slate-500`}),(0,u.jsx)(`span`,{children:i.length===0?`Capture Screen & Annotate`:`Capture Another Screenshot (${3-i.length} left)`})]}):(0,u.jsx)(`div`,{className:`rounded-lg bg-amber-50 p-2.5 text-center text-xs text-amber-700 border border-amber-200`,children:`Maximum 3 screenshots attached. Delete one to take a new one.`})})]}),E&&(0,u.jsxs)(`div`,{className:`rounded-xl border border-red-200 bg-red-50 px-3.5 py-2.5 text-xs text-red-700 flex items-start gap-2`,children:[(0,u.jsx)(l.AlertCircle,{className:`h-4 w-4 shrink-0 mt-0.5`}),(0,u.jsx)(`span`,{children:E})]}),(0,u.jsxs)(`div`,{className:`pt-4 border-t border-slate-100 flex items-center justify-end gap-3`,children:[(0,u.jsx)(`button`,{type:`button`,onClick:n,className:`rounded-xl border border-slate-200 bg-white px-4 py-2.5 text-sm font-semibold text-slate-600 transition hover:bg-slate-50`,children:`Cancel`}),(0,u.jsx)(`button`,{type:`submit`,disabled:C,style:{backgroundColor:p},className:`flex items-center gap-2 rounded-xl px-5 py-2.5 text-sm font-semibold text-white shadow-md transition hover:brightness-110 active:scale-95 disabled:opacity-60`,children:C?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(l.Loader2,{className:`h-4 w-4 animate-spin`}),(0,u.jsx)(`span`,{children:`Submitting...`})]}):(0,u.jsx)(`span`,{children:`Submit Bug Report`})})]})]})})]}),k&&(0,u.jsx)(`div`,{"data-bugdrop-widget":`true`,onClick:()=>A(null),className:`fixed inset-0 z-[100001] flex items-center justify-center bg-black/80 p-4 backdrop-blur-sm animate-fadeIn`,children:(0,u.jsxs)(`div`,{className:`relative max-h-[90vh] max-w-[90vw] overflow-hidden rounded-xl bg-slate-900 shadow-2xl`,onClick:e=>e.stopPropagation(),children:[(0,u.jsx)(`img`,{src:k,alt:`Screenshot Preview`,className:`max-h-[85vh] w-auto rounded-xl object-contain`}),(0,u.jsx)(`button`,{type:`button`,onClick:()=>A(null),className:`absolute top-3 right-3 flex h-8 w-8 items-center justify-center rounded-full bg-black/60 text-white shadow hover:bg-black/90`,children:(0,u.jsx)(l.X,{className:`h-4 w-4`})})]})})]})},Od=null;function kd(){return Od||=import(`konva`).then(e=>{let t=e;return t.default??t}).catch(e=>{throw Od=null,e}),Od}var Ad=typeof window<`u`?c.useLayoutEffect:c.useEffect;function jd(e){let t=e,n={stroke:e.stroke,strokeWidth:e.strokeWidth,rotation:t.rotation??0};switch(e.type){case`line`:return{...n,x:t.x??0,y:t.y??0,points:e.points,tension:.5,lineCap:`round`,lineJoin:`round`,globalCompositeOperation:e.tool===`eraser`?`destination-out`:`source-over`};case`rectangle`:return{...n,x:e.x,y:e.y,width:e.width,height:e.height};case`circle`:return{...n,x:e.x,y:e.y,radius:e.radius};case`arrow`:return{...n,x:t.x??0,y:t.y??0,points:e.points,fill:e.fill,pointerLength:14,pointerWidth:14};default:return n}}function Md(e,t,n){let r={...jd(t),...n};switch(t.type){case`line`:return new e.Line(r);case`rectangle`:return new e.Rect(r);case`circle`:return new e.Circle(r);case`arrow`:return new e.Arrow(r);default:return null}}var Nd=[`#ef4444`,`#f97316`,`#eab308`,`#10b981`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#000000`,`#ffffff`],Pd=[{label:`S`,value:3},{label:`M`,value:6},{label:`L`,value:10},{label:`XL`,value:16}],Fd=[{id:`select`,title:`Select & Move / Resize`,Icon:l.MousePointer},{id:`pencil`,title:`Pencil / Draw`,Icon:l.Pencil},{id:`eraser`,title:`Eraser (click or drag to erase)`,Icon:l.Eraser},{id:`rectangle`,title:`Rectangle (Resizable)`,Icon:l.Square},{id:`circle`,title:`Circle (Resizable)`,Icon:l.Circle},{id:`arrow`,title:`Arrow (Resizable)`,Icon:l.ArrowUpRight}],Id=[`top-left`,`top-right`,`bottom-left`,`bottom-right`,`middle-left`,`middle-right`,`top-center`,`bottom-center`],Ld=({imageSrc:e,onSave:t,onCancel:n,primaryColor:r=`#2563eb`})=>{let i=(0,c.useRef)(null),a=(0,c.useRef)(null),o=(0,c.useRef)(null),s=(0,c.useRef)(null),d=(0,c.useRef)(null),f=(0,c.useRef)(null),p=(0,c.useRef)(null),m=(0,c.useRef)(null),[h,g]=(0,c.useState)(null),[_,v]=(0,c.useState)(null),[y,b]=(0,c.useState)(null),[x,S]=(0,c.useState)(1),[C,w]=(0,c.useState)({width:800,height:600}),[T,ee]=(0,c.useState)(`pencil`),[E,D]=(0,c.useState)(`#ef4444`),[O,te]=(0,c.useState)(6),[k,A]=(0,c.useState)(null),[j,ne]=(0,c.useState)([]),[re,ie]=(0,c.useState)([[]]),[ae,oe]=(0,c.useState)(0);(0,c.useEffect)(()=>{let e=!1;return kd().then(t=>{e||g(()=>t)}).catch(()=>{e||v(`The annotation editor could not load. Check your connection and try again.`)}),()=>{e=!0}},[]),(0,c.useEffect)(()=>{let t=new window.Image;return t.crossOrigin=`anonymous`,t.onload=()=>b(t),t.src=e,()=>{t.onload=null}},[e]);let se=(0,c.useCallback)(()=>{if(!i.current||!y)return;let e=Math.max(300,i.current.clientWidth-48),t=Math.max(300,i.current.clientHeight-120),n=Math.min(e/y.naturalWidth,t/y.naturalHeight,1);S(n),w({width:Math.round(y.naturalWidth*n),height:Math.round(y.naturalHeight*n)})},[y]);(0,c.useEffect)(()=>(se(),window.addEventListener(`resize`,se),()=>window.removeEventListener(`resize`,se)),[se]),(0,c.useEffect)(()=>{let e=a.current;if(!h||!y||!e)return;let t=h,n=new t.Stage({container:e,width:1,height:1}),r=new t.Layer({listening:!1});r.add(new t.Image({name:`bg-image`,image:y,width:y.naturalWidth,height:y.naturalHeight}));let i=new t.Layer,c=new t.Transformer({rotateEnabled:!0,enabledAnchors:Id,borderStroke:`#3b82f6`,borderDash:[4,4],anchorFill:`#ffffff`,anchorStroke:`#3b82f6`,anchorSize:9,anchorCornerRadius:2,boundBoxFunc:(e,t)=>Math.abs(t.width)<10||Math.abs(t.height)<10?e:t});i.add(c),n.add(r),n.add(i),n.on(`pointerdown`,e=>m.current?.pointerDown(e)),n.on(`pointermove`,()=>m.current?.pointerMove()),n.on(`pointerup`,()=>m.current?.pointerUp());let l=()=>m.current?.pointerUp();return window.addEventListener(`pointerup`,l),window.addEventListener(`pointercancel`,l),o.current=n,s.current=i,d.current=c,()=>{window.removeEventListener(`pointerup`,l),window.removeEventListener(`pointercancel`,l),p.current=null,f.current=null,n.destroy(),o.current=null,s.current=null,d.current=null}},[h,y]),(0,c.useEffect)(()=>{let e=o.current;e&&(e.size(C),e.scale({x,y:x}))},[h,y,x,C]),(0,c.useEffect)(()=>{let e=h,t=s.current,n=d.current;if(!e||!t||!n)return;n.nodes([]),t.find(`.annotation`).forEach(e=>e.destroy());let r=T===`select`;j.forEach(n=>{let i=n.type===`line`&&n.tool===`eraser`,a=Md(e,n,{id:n.id,name:`annotation`,draggable:r&&!i,hitStrokeWidth:Math.max(n.strokeWidth,12)});a&&(a.on(`dragend`,()=>m.current?.dragEnd(a,n.id)),a.on(`transformend`,()=>m.current?.transformEnd(a,n.id)),t.add(a))}),n.moveToTop()},[h,y,j,T]),(0,c.useEffect)(()=>{let e=s.current,t=d.current;if(!e||!t)return;let n=k?e.findOne(`#`+k):void 0;if(!n){t.nodes([]);return}let r=n.getClassName()===`Line`;t.resizeEnabled(!r),t.rotateEnabled(!r),t.nodes([n])},[h,y,j,T,k]);let ce=e=>{ne(e),ie([...re.slice(0,ae+1),e]),oe(ae+1)},le=()=>{if(ae<=0)return;let e=ae-1;oe(e),ne(re[e]),A(null)},ue=()=>{if(ae>=re.length-1)return;let e=ae+1;oe(e),ne(re[e]),A(null)},de=()=>{j.length!==0&&(ce([]),A(null))},fe=()=>{k&&(ce(j.filter(e=>e.id!==k)),A(null))},pe=()=>{let e=o.current?.getPointerPosition();return e?{x:e.x/x,y:e.y/x}:null},me=e=>{let t=o.current,n=s.current,r=h;if(!t||!n||!r||p.current)return;let i=pe();if(!i)return;let{x:a,y:c}=i,l=e.target,u=l===t?``:l.id(),d=u?j.find(e=>e.id===u):void 0;if(T===`select`){d?(d.type!==`line`||d.tool!==`eraser`)&&A(d.id):(l===t||l.hasName(`bg-image`))&&A(null);return}if(T===`eraser`&&d){ce(j.filter(e=>e.id!==d.id)),A(null);return}A(null);let m=`shape_${Date.now()}_${Math.random().toString(36).substring(2,7)}`,g;g=T===`pencil`||T===`eraser`?{id:m,type:`line`,tool:T,points:[a,c],stroke:T===`eraser`?`#ffffff`:E,strokeWidth:T===`eraser`?O*2.5:O}:T===`rectangle`?{id:m,type:`rectangle`,x:a,y:c,width:0,height:0,stroke:E,strokeWidth:O}:T===`circle`?{id:m,type:`circle`,x:a,y:c,radius:0,stroke:E,strokeWidth:O}:{id:m,type:`arrow`,points:[a,c,a,c],stroke:E,fill:E,strokeWidth:O};let _=Md(r,g,{listening:!1,dash:g.type===`line`?void 0:[6,4]});_&&(n.add(_),f.current=_,p.current={start:{x:a,y:c},data:g})},he=()=>{let e=p.current;if(!e)return;let t=pe();if(!t)return;let{x:n,y:r}=t,{start:i,data:a}=e,o=a;a.type===`line`?o={...a,points:[...a.points,n,r]}:a.type===`rectangle`?o={...a,x:Math.min(i.x,n),y:Math.min(i.y,r),width:Math.abs(n-i.x),height:Math.abs(r-i.y)}:a.type===`circle`?o={...a,radius:Math.hypot(n-i.x,r-i.y)}:a.type===`arrow`&&(o={...a,points:[i.x,i.y,n,r]}),e.data=o,f.current?.setAttrs(jd(o))},ge=()=>{let e=p.current;if(!e)return;p.current=null,f.current?.destroy(),f.current=null;let t=e.data,n=!1;if(t.type===`line`)n=t.points.length>=2;else if(t.type===`rectangle`)n=t.width>6&&t.height>6;else if(t.type===`circle`)n=t.radius>5;else if(t.type===`arrow`){let[e,r,i,a]=t.points;n=Math.hypot(i-e,a-r)>10}n&&(ce([...j,t]),(t.type===`rectangle`||t.type===`circle`||t.type===`arrow`)&&(A(t.id),ee(`select`)))},_e=(e,t)=>{j.some(e=>e.id===t)&&ce(j.map(n=>n.id===t?{...n,x:e.x(),y:e.y()}:n))},ve=(e,t)=>{let n=j.find(e=>e.id===t);if(!n)return;let r=e.scaleX(),i=e.scaleY();e.scaleX(1),e.scaleY(1);let a=null;if(n.type===`rectangle`)a={...n,x:e.x(),y:e.y(),width:Math.max(10,e.width()*r),height:Math.max(10,e.height()*i),rotation:e.rotation()};else if(n.type===`circle`)a={...n,x:e.x(),y:e.y(),radius:Math.max(6,n.radius*r),rotation:e.rotation()};else if(n.type===`arrow`){let[t,o,s,c]=n.points;a={...n,x:e.x(),y:e.y(),points:[t,o,t+(s-t)*r,o+(c-o)*i],rotation:e.rotation()}}if(!a)return;let o=a;ce(j.map(e=>e.id===t?o:e))};Ad(()=>{m.current={pointerDown:me,pointerMove:he,pointerUp:ge,dragEnd:_e,transformEnd:ve,undo:le,redo:ue,deleteSelected:fe,hasSelection:()=>k!==null,clearSelection:()=>A(null)}}),(0,c.useEffect)(()=>{let e=e=>{let t=m.current;if(!t||e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement)return;let n=e.ctrlKey||e.metaKey,r=e.key.toLowerCase();n&&r===`z`?(e.shiftKey?t.redo():t.undo(),e.preventDefault()):n&&r===`y`?(t.redo(),e.preventDefault()):(e.key===`Delete`||e.key===`Backspace`)&&t.hasSelection()?(t.deleteSelected(),e.preventDefault()):e.key===`Escape`&&(t.clearSelection(),e.preventDefault())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let ye=()=>{let e=o.current;e&&(d.current?.nodes([]),A(null),t(e.toDataURL({pixelRatio:1/x,mimeType:`image/png`})))},be=e=>{ee(e),e!==`select`&&A(null)},xe=!!(y&&h);return(0,u.jsxs)(`div`,{ref:i,className:`fixed inset-0 z-[100000] flex flex-col bg-slate-950/90 backdrop-blur-md select-none text-white overflow-hidden animate-fadeIn`,style:{touchAction:`none`},children:[(0,u.jsxs)(`div`,{className:`flex h-16 shrink-0 items-center justify-between border-b border-slate-800 bg-slate-900/90 px-4 sm:px-6`,children:[(0,u.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,u.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded-lg text-white font-bold text-sm shadow`,style:{backgroundColor:r},children:`BD`}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h1`,{className:`text-sm sm:text-base font-semibold leading-tight text-slate-100`,children:`Screenshot Editor`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-400 hidden sm:block`,children:`Highlight issues with pencil, arrows, circles, and boxes`})]})]}),(0,u.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[(0,u.jsx)(`button`,{type:`button`,onClick:le,disabled:ae<=0,title:`Undo (Ctrl+Z)`,className:`flex h-9 w-9 items-center justify-center rounded-lg border border-slate-700 bg-slate-800 text-slate-200 transition hover:bg-slate-700 hover:text-white disabled:opacity-40 disabled:pointer-events-none`,children:(0,u.jsx)(l.Undo2,{className:`h-4 w-4`})}),(0,u.jsx)(`button`,{type:`button`,onClick:ue,disabled:ae>=re.length-1,title:`Redo (Ctrl+Y)`,className:`flex h-9 w-9 items-center justify-center rounded-lg border border-slate-700 bg-slate-800 text-slate-200 transition hover:bg-slate-700 hover:text-white disabled:opacity-40 disabled:pointer-events-none`,children:(0,u.jsx)(l.Redo2,{className:`h-4 w-4`})}),(0,u.jsxs)(`button`,{type:`button`,onClick:de,disabled:j.length===0,title:`Clear all annotations`,className:`flex h-9 items-center gap-1.5 rounded-lg border border-slate-700 bg-slate-800 px-2.5 text-xs font-medium text-slate-300 transition hover:bg-slate-700 hover:text-white disabled:opacity-40 disabled:pointer-events-none`,children:[(0,u.jsx)(l.Trash2,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{className:`hidden md:inline`,children:`Clear All`})]}),(0,u.jsx)(`div`,{className:`h-5 w-px bg-slate-700 mx-1`}),(0,u.jsxs)(`button`,{type:`button`,onClick:n,className:`flex h-9 items-center gap-1.5 rounded-lg border border-slate-700 bg-slate-800 px-3 text-xs sm:text-sm font-medium text-slate-200 transition hover:bg-slate-700 hover:text-white`,children:[(0,u.jsx)(l.X,{className:`h-4 w-4`}),(0,u.jsx)(`span`,{children:`Cancel`})]}),(0,u.jsxs)(`button`,{type:`button`,onClick:ye,disabled:!xe,style:{backgroundColor:r},className:`flex h-9 items-center gap-1.5 rounded-lg px-4 text-xs sm:text-sm font-semibold text-white shadow-md transition hover:brightness-110 active:scale-95 disabled:opacity-50 disabled:pointer-events-none`,children:[(0,u.jsx)(l.Check,{className:`h-4 w-4`}),(0,u.jsx)(`span`,{children:`Add to Report`})]})]})]}),(0,u.jsxs)(`div`,{className:`absolute top-20 left-1/2 -translate-x-1/2 z-20 flex flex-wrap items-center justify-center gap-2 rounded-2xl border border-slate-700/80 bg-slate-900/95 p-2 shadow-2xl backdrop-blur-md`,children:[(0,u.jsx)(`div`,{className:`flex items-center gap-1`,children:Fd.map(({id:e,title:t,Icon:n})=>(0,u.jsx)(`button`,{type:`button`,onClick:()=>be(e),title:t,"aria-pressed":T===e,className:`flex h-9 w-9 items-center justify-center rounded-xl transition ${T===e?`bg-blue-600 text-white shadow-inner`:`text-slate-300 hover:bg-slate-800 hover:text-white`}`,children:(0,u.jsx)(n,{className:`h-4 w-4`})},e))}),(0,u.jsx)(`div`,{className:`h-5 w-px bg-slate-700`}),(0,u.jsxs)(`div`,{className:`flex items-center gap-1.5 px-1`,children:[Nd.map(e=>(0,u.jsx)(`button`,{type:`button`,onClick:()=>D(e),title:e,"aria-label":`Color ${e}`,style:{backgroundColor:e},className:`h-5 w-5 rounded-full border border-slate-700 transition-transform ${E===e?`scale-125 ring-2 ring-white ring-offset-1 ring-offset-slate-900`:`hover:scale-110`}`},e)),(0,u.jsxs)(`label`,{title:`Custom Color`,className:`relative flex h-6 w-6 cursor-pointer items-center justify-center rounded-full border border-slate-600 bg-slate-800 text-slate-300 hover:text-white transition`,children:[(0,u.jsx)(l.Palette,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`input`,{type:`color`,value:E,onChange:e=>D(e.target.value),className:`absolute inset-0 opacity-0 cursor-pointer`})]})]}),(0,u.jsx)(`div`,{className:`h-5 w-px bg-slate-700`}),(0,u.jsx)(`div`,{className:`flex items-center gap-1`,children:Pd.map(e=>(0,u.jsx)(`button`,{type:`button`,onClick:()=>te(e.value),className:`flex h-7 w-7 items-center justify-center rounded-lg text-xs font-semibold transition ${O===e.value?`bg-slate-700 text-white ring-1 ring-slate-400`:`text-slate-400 hover:bg-slate-800 hover:text-white`}`,children:e.label},e.value))}),k&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`div`,{className:`h-5 w-px bg-slate-700`}),(0,u.jsxs)(`button`,{type:`button`,onClick:fe,title:`Delete Selected Shape (Del / Backspace)`,className:`flex h-8 items-center gap-1.5 rounded-xl bg-red-600/90 px-3 text-xs font-semibold text-white shadow hover:bg-red-600`,children:[(0,u.jsx)(l.Trash2,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{children:`Delete`})]})]})]}),(0,u.jsx)(`div`,{className:`relative flex flex-1 items-center justify-center p-4 overflow-hidden`,children:_?(0,u.jsx)(`p`,{className:`text-sm text-red-300`,children:_}):xe?(0,u.jsx)(`div`,{className:`relative shadow-2xl rounded-md overflow-hidden border border-slate-700 bg-slate-900`,style:{width:C.width,height:C.height,cursor:T===`select`?`default`:T===`eraser`?`cell`:`crosshair`},children:(0,u.jsx)(`div`,{ref:a})}):(0,u.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-slate-400`,children:[(0,u.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-2 border-blue-500 border-t-transparent`}),(0,u.jsx)(`p`,{className:`text-sm`,children:`Loading screenshot...`})]})}),(0,u.jsxs)(`div`,{className:`flex h-10 shrink-0 items-center justify-between border-t border-slate-800 bg-slate-900/80 px-4 text-xs text-slate-400`,children:[(0,u.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,u.jsxs)(`span`,{children:[`Active tool: `,(0,u.jsx)(`strong`,{className:`text-slate-200 capitalize`,children:T})]}),(0,u.jsxs)(`span`,{className:`hidden sm:inline`,children:[`Use `,(0,u.jsx)(`kbd`,{className:`rounded bg-slate-800 px-1 py-0.5 text-slate-300`,children:`Ctrl+Z`}),` to undo,`,` `,(0,u.jsx)(`kbd`,{className:`rounded bg-slate-800 px-1 py-0.5 text-slate-300`,children:`Del`}),` to remove selected shape`]})]}),(0,u.jsx)(`div`,{children:y&&(0,u.jsxs)(`span`,{children:[`Original Resolution: `,y.naturalWidth,` x `,y.naturalHeight,`px`]})})]})]})},Rd=({projectUrl:e,onSubmit:t,uiSettings:n={},onSuccess:r,onError:i,isOpen:a,onToggle:o,className:s=``})=>{let{position:d=`bottom-right`,primaryColor:f=`#2563eb`,buttonSize:p=`md`,buttonText:m,buttonIcon:h,zIndex:g=99990}=n,[_,v]=(0,c.useState)(!1),y=a===void 0?_:a,b=e=>{a===void 0&&v(e),o?.(e)},[x,S]=(0,c.useState)([]),[C,w]=(0,c.useState)(!1),[T,ee]=(0,c.useState)(!1),[E,D]=(0,c.useState)(null),O=e=>{switch(e){case`bottom-left`:return`bottom-6 left-6`;case`top-left`:return`top-6 left-6`;case`top-right`:return`top-6 right-6`;case`left`:return`top-1/2 -translate-y-1/2 left-4`;case`right`:return`top-1/2 -translate-y-1/2 right-4`;default:return`bottom-6 right-6`}},te=(e=>{switch(e){case`sm`:return{button:`h-10 px-3.5 gap-2 text-xs font-semibold rounded-full shadow-md`,icon:`h-4 w-4`};case`lg`:return{button:`h-14 px-5 gap-3 text-base font-bold rounded-full shadow-xl`,icon:`h-6 w-6`};default:return{button:`h-12 px-4 gap-2.5 text-sm font-semibold rounded-full shadow-lg`,icon:`h-5 w-5`}}})(p);return C?null:(0,u.jsxs)(u.Fragment,{children:[!T&&(0,u.jsx)(`div`,{"data-bugdrop-widget":`true`,className:`fixed ${O(d)} ${s}`,style:{zIndex:g},children:(0,u.jsxs)(`button`,{type:`button`,onClick:()=>b(!y),style:{backgroundColor:f},className:`group flex items-center justify-center text-white transition-all duration-200 hover:brightness-110 active:scale-95 ${te.button}`,"aria-label":y?`Close bug report form`:`Open bug report form`,title:y?`Close Bug Report`:`Report a Bug`,children:[y?(0,u.jsx)(l.X,{className:te.icon}):h||(0,u.jsx)(l.Bug,{className:te.icon}),m&&(0,u.jsx)(`span`,{children:m}),x.length>0&&!y&&(0,u.jsx)(`span`,{className:`flex h-5 w-5 items-center justify-center rounded-full bg-white text-[11px] font-bold text-slate-900 shadow`,children:x.length})]})}),!T&&(0,u.jsx)(Dd,{projectUrl:e,isOpen:y,onClose:()=>b(!1),uiSettings:n,screenshots:x,onTriggerScreenshot:async()=>{w(!0);try{await new Promise(e=>setTimeout(e,180));let e=(await Td(document.documentElement,{useCORS:!0,allowTaint:!0,logging:!1,scrollX:0,scrollY:-window.scrollY,windowWidth:document.documentElement.offsetWidth,windowHeight:document.documentElement.offsetHeight,ignoreElements:e=>e.getAttribute(`data-bugdrop-widget`)===`true`||e.classList.contains(`bugdrop-ignore`)})).toDataURL(`image/png`);D({dataUrl:e,isNew:!0}),ee(!0)}catch(e){console.error(`Error taking screenshot:`,e),alert(`Could not capture screenshot. Please try again.`)}finally{w(!1)}},onEditScreenshot:e=>{D({id:e.id,dataUrl:e.dataUrl,isNew:!1}),ee(!0)},onDeleteScreenshot:e=>{S(t=>t.filter(t=>t.id!==e))},onSubmitReport:async e=>{try{await t(e),r?.(e)}catch(e){let t=e instanceof Error?e:Error(`Failed to submit bug report`);throw i?.(t),t}}}),T&&E&&(0,u.jsx)(Ld,{imageSrc:E.dataUrl,onSave:e=>{if(E?.isNew){if(x.length<3){let t={id:`ss_${Date.now()}_${Math.random().toString(36).substring(2,6)}`,dataUrl:e,createdAt:Date.now()};S(e=>[...e,t])}}else E?.id&&S(t=>t.map(t=>t.id===E.id?{...t,dataUrl:e}:t));ee(!1),D(null),b(!0)},onCancel:()=>{ee(!1),D(null),b(!0)},primaryColor:f})]})};exports.Widget=Rd;
2
8
  //# sourceMappingURL=bug-widget-library.cjs.map